[erlang-questions] dets:info/2

Tim <>
Sun Jun 30 21:25:29 CEST 2013


On 01/07/2013, at 3:39 AM, Garrett Smith <> wrote:

> 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.

Heh.  I'd already slipped into using a lot of the ++ and the iolist approach will make my code much cleaner.  Thanks for that!



More information about the erlang-questions mailing list