[erlang-questions] dets:info/2

Garrett Smith g@REDACTED
Sun Jun 30 20:09:48 CEST 2013

Hi Tim,

On Sun, Jun 30, 2013 at 12:50 PM, Tim <erlang@REDACTED> wrote:
> Ooookaaaay.  I see I'm going to have to unlearn a lot of assumptions to get my brain into the Erlang groove.  :)

If you can avoid it, don't make assumptions when you're sorting this
stuff out :)

To reiterate Joseph's point, the Erlang shell is where you want to go
first for info. It's usually pretty easy to experiment with APIs in
the shell, which will give you a hands on experience that's sometimes
hard to get from online docs and books.

A lesser know pattern, related to your problem, is to avoid creating
flattened strings when you're generating content for file-like IO
(file system, sockets. etc.).

Rather than this:

   Name = "Joe",
   "My name is " ++ Name

Do this:

   Name = "Joe",
   ["My name is ", Name]

This is an example of an "iolist", which is an arbitrarily nested list
containing strings (lists of integers) and binaries. It's a powerful
abstraction has it lets you efficiently build string/binary content
without pointlessly flattening them.

> Thanks for sorting that out - it does now work as expected.
> One parting question though:  If integers and strings (lists of integers) are _not_ interchangeable, why doesn't this line generate an error?
> {html, MyInfo}.

My guess is the server is treating the integer as a character and it's
getting rolled into an iolist (see previous comment).


More information about the erlang-questions mailing list