Generic-user-small Paul Tracey 2 posts

Hi all,

I can’t seem to get this code example to work, as no-one else seems to have mentioned this in the errata or such I would think it might be symptomatic of a misconfiguration on my part. In any case here is what I have entered and the associated error message:

_ Erlang (BEAM) emulator version 5.6.3 smp:2

Eshell V5.6.3 (abort with ^G)
1> for(Max, Max,F) -> [F(Max)];
1> for(I, Max, F) -> [F(I)|for(I+1), Max, F)].
  • 1: syntax error before: ‘->‘
    1>_

(Other code examples have worked up until this point in the book).
probably something dense on my part but any assistance would be appreciated.

Thanks in advance
Paul

 
Alain_o_dea_small Alain O'Dea 35 posts

I ran into this exact same problem.

That function definition syntax is only valid at in a module file which you would compile and load.

The book has a warning there about that, but it is unfortunately two pages later under the heading “Common Errors”.

Erlang expressions written in EShell have the same syntax rules as those within the body of a function within a module file. As a result you cannot define functions this way in EShell.

I hope this helps. Thank you for posting your question.

 
Generic-user-small Paul Tracey 2 posts

Thanks for the help Alain, all sorted.

3 posts, 2 voices