<div dir="ltr"><div><div>Another question from a newbie based on your code above. In this line:<br><br>[Time,_|Dishes] = string:tokens(User_Entry, ","),<br><br></div>The way I understand it, Time will point to the first token, the second will be dropped (as it maps to _) and Dishes will be the rest of the list. Am I correct?<br>
<br>If yes, did you include _ to reflect the original code where lists:nthtail(AllTokens, 2) would have resulted in Dishes starting at the 3rd token effectively ignoring the 2nd token? I'm not sure that's what was intended based on the description. Also, would it be sensible to add space as a separator to avoid having them included in tokens?<br>
<br></div>In which case, that line may be a bit closer to what Boris intended.<br><div><br>[Time|Dishes] = string:tokens(User_Entry, ", "),<br><br></div><div>Please correct me if I misunderstood something, I'm learning Erlang too :-)<br>
<br></div><div>Cheers,<br><br></div><div>Bruno<br></div><div><br></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On 9 May 2013 02:10, Richard A. O'Keefe <span dir="ltr"><<a href="mailto:ok@cs.otago.ac.nz" target="_blank">ok@cs.otago.ac.nz</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I wonder if the original poster would have been so puzzled had<br>
the error message been<br>
<br>
"A function cannot begin with 'case'."<br>
<br>
which would have hinted that the compiler thought this was<br>
the beginning of a (new) function.<br>
<br>
The last parser I wrote, I switched from Yacc to plain old<br>
recursive descent and found it much easier to generate<br>
error messages that I found helpful.<br>
<br>
The original poster should also note that<br>
itIsNotConsideredGoodErlangStyleToUseWordsRunTogetherLikeThis.<br>
Multi-word identifiers in Erlang are normally separated by<br>
spaces unless they have to be compatible with something else.<br>
Itisalsonotgoodtorunwordstogetherwithnoindication.<br>
<br>
There is a problem with the calls to nthtail/2 (just because<br>
it's in the Erlang standard library doesn't mean it's a good<br>
name):  the arguments are in the wrong order.  In any case,<br>
you don't need it.<br>
<br>
-module(practicum).<br>
-export([place_order/1]).<br>
<br>
place_order(User_Entry) -><br>
    [Time,_|Dishes] = string:tokens(User_Entry, ","),<br>
    case Time<br>
      of "morning" -> process_morning(Dishes)<br>
       ; "night"   -> process_evening(Dishes)<br>
       ; _         -> io:fwrite("error\n")<br>
    end.<br>
<br>
process_morning(Dishes) -><br>
    Dishes.<br>
<br>
process_evening(Dishes) -><br>
    Dishes.<br>
<br>
You might prefer to eliminate the '_ -> io:fwrite(...)' case;<br>
if there's no match the 'case' will crash, and that's just what<br>
we want.  Unless this is an assignment, in which case do what<br>
the assignment says.<br>
<div class="HOEnZb"><div class="h5"><br>
<br>
_______________________________________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>
<a href="http://erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br>
</div></div></blockquote></div><br><br clear="all"><br>-- <br>Bruno<br>Visit my weblog: <a href="http://brunogirin.blogspot.com">http://brunogirin.blogspot.com</a>
</div>