[erlang-questions] unexpected result of term_to_binary

Joe Armstrong <>
Mon Jan 21 22:00:40 CET 2013


On Mon, Jan 21, 2013 at 9:24 PM, Steve Davis <
> wrote:

> Even better solution is to send "lists of integers" as tuples:
> 2> term_to_binary({1,2,3,4}).
> <<131,104,4,97,1,97,2,97,3,97,4>>
>
> :-)
>

While we're on the subject - shouldn't we rename lists.

stacks is a much better name - Erlang has no lists only stacks.

think of explaining reverse

reverse(L) -> reverse(L, []).

reverse([H|T], L) -> reverse(T, [H|L]);
reverse([], L) -> L.

easy to explain using the "two stacks of plates" model.

Lists is a stupid name :-)

/Joe






> /s
>
>
> On Jan 21, 2013, at 2:15 PM, Steve Davis <>
> wrote:
>
> > Hi Dmitry,
> >
> > Unfortunately, Bert-js suffers from the same ambiguity client side.
> >
> > I have in fact found a reasonable hack which only costs an extra byte
> and is to prepend NIL_EXT to the list:
> > 1> term_to_binary([[],1,2,3,4]).
> > <<131,108,0,0,0,5,106,97,1,97,2,97,3,97,4,106>>
> >
> > Best,
> > Steve
> >
> > On Jan 21, 2013, at 2:13 PM, Dmitry Kolesnikov <>
> wrote:
> >
> >> Hi Steve,
> >>
> >> There is a well document External Term Format protocol. I am not here
> to judge that protocol but it is implementable on other languages as well (
> https://github.com/rustyio/BERT-JS). Yes, it make sense in scopes of that
> protocol specification.
> >>
> >> Long time ago, I've been trying to use it for WebApp development and …
> switched to JSON. :-)
> >> But I strongly believe that External Term Format make sense for other
> use-case...
> >>
> >>
> >> Best Regards,
> >> Dmitry
> >>
> >>
> >> On Jan 21, 2013, at 10:00 PM, Steve Davis <
> > wrote:
> >>
> >>> Hi Dmitry,
> >>>
> >>> It "makes sense" only if the "binary_to_term" decode is done in erlang.
> >>>
> >>> br,
> >>> /s
> >>>
> >>> On Jan 21, 2013, at 1:53 PM, Dmitry Kolesnikov <>
> wrote:
> >>>
> >>>> Hello,
> >>>>
> >>>> This make sense to me!
> >>>>
> >>>> term_to_binary/1 returns a binary data object which is the result of
> encoding Term according to the Erlang external term format. See
> http://erlang.org/doc/apps/erts/erl_ext_dist.html
> >>>>
> >>>> Use list_to_binary or unicode:character_to_binary depends on your
> use-case.
> >>>>
> >>>> - Dmitry
> >>>>
> >>>> On Jan 21, 2013, at 9:38 PM, Steve Davis <
> > wrote:
> >>>>
> >>>>> The following appears to encode lists of integers as strings (?!?):
> >>>>>
> >>>>> Eshell V5.9.3  (abort with ^G)
> >>>>> 1> term_to_binary([1,2,3,4]).
> >>>>> <<131,107,0,4,1,2,3,4>>
> >>>>>
> >>>>> Is there a reason for this that I'm missing?
> >>>>>
> >>>>> regs,
> >>>>> /s
> >>>>>
> >>>>> _______________________________________________
> >>>>> erlang-questions mailing list
> >>>>> 
> >>>>> http://erlang.org/mailman/listinfo/erlang-questions
> >>>>
> >>>
> >>
> >
>
> _______________________________________________
> erlang-questions mailing list
> 
> http://erlang.org/mailman/listinfo/erlang-questions
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20130121/a51f21b3/attachment.html>


More information about the erlang-questions mailing list