[erlang-questions] Pattern matching in function calls

Jachym Holecek freza@REDACTED
Fri Apr 15 22:44:18 CEST 2011


[I didn't read the rest of the thread, so hopefully I'm not terribly offtopic.
Also, I got rid of top-posting and unlimited context quoting as both are seen
as bad taste where I come from.]

# Robert Raschke 2011-04-15:
>> On Thu, Apr 14, 2011 at 11:48 AM, Dave Challis <dsc@REDACTED> wrote:
>> Yup, I agree completely :)
>> My question was mostly prompted by a blog post (http://ppolv.wordpress.com/2008/02/25/
>> parsing-csv-in-erlang/) on parsing CSV in erlang.
>> The do_parse function there has a dozen items which search binaries and check state, which made
>> me wonder whether swapping the argument order round would make any difference at all.
>> That code makes me wonder if it could be rewritten using gen_fsm. Never used gen_fsm myself, so I'm
>> not really sure.

I don't think so; gen_fsm is brilliant for purely event-driven automata but
would be very ugly for a task like this. What the CSV guy needs to do is:

  1) Get rid of #ecsv{} record, that's overkill for such a trivial purpose.

  2) Break the parser into a bunch of tiny functions, pass all necessary
     data in arguments.

IIRC LFE's scanner/parser code is a neat example of how to get it right.

	-- Jachym

More information about the erlang-questions mailing list