[erlang-questions] Pattern matching in function calls

Mike Oxford moxford@REDACTED
Fri Apr 15 22:59:52 CEST 2011


Just to be obnoxious....
Why not split on ',' and check last chars?  If you find an escape char then
build a single term out of it.

Hello Foo\, it's me\, Mike,Hi Mike\, good to meet you!

lists returns
[Hello Foo\, it's me\, Mike,Hi Mike\, good to meet you!]

You then check for '\' (and optionally, \\) and concat as needed, replacing
'\' with ',' when not itself escaped.

You'll have to iterate "N" terms a complete second time which may be a
killer for performance but with smaller data sets
it would work, and would lend itself to parallelization via distributed
Map->Reduce on pairs of terms for really big sets.

-mox


On Fri, Apr 15, 2011 at 1:44 PM, Jachym Holecek <freza@REDACTED>wrote:

> Hi,
>
> [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.
>
> Regards,
>        -- Jachym
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20110415/a1386f50/attachment.htm>


More information about the erlang-questions mailing list