Opposite of flatten
Nico Weling
nico.weling@REDACTED
Wed Sep 26 11:52:29 CEST 2001
Hi Ulf,
thanks a lot. Very good and simple solution. It's working fine.
Regards,
Nico.
Ulf Wiger wrote:
>
> On Wed, 26 Sep 2001, Nico Weling wrote:
>
> >I need a function which creates tuples and lists from a string,
> >something like the opposite of flatten:
> >
> >1> Msg = "{ms,{5,{send,filename}}".
> >"{ms,{5,{send,filename}}"
> >2> Pid ! opposite_of_flatten(Msg).
>
> First of all, Msg above is syntactically incorrect, but I assume
> that's just a typo.
>
> 1> Str = "{ms,{5,{send,filename}}}".
> "{ms,{5,{send,filename}}}"
> 2> {ok, Toks, _} = erl_scan:string(Str ++ ".").
> {ok,[{'{',1},
> {atom,1,ms},
> {',',1},
> {'{',1},
> {integer,1,5},
> {',',1},
> {'{',1},
> {atom,1,send},
> {',',1},
> {atom,1,filename},
> {'}',1},
> {'}',1},
> {'}',1},
> {dot,1}],
> 1}
> 3> erl_parse:parse_term(Toks).
> {ok,{ms,{5,{send,filename}}}}
>
> Your function, thus, becomes:
>
> opposite_of_flatten(Str) ->
> {ok, Tokens, _} = erl_scan:string(Str ++ "."),
> {ok, Term} = erl_parse:parse_term(Tokens),
> Term.
>
> Appending the dot is necessary for the parsing to work.
>
> /Uffe
> --
> Ulf Wiger tfn: +46 8 719 81 95
> Senior System Architect mob: +46 70 519 81 95
> Strategic Product & System Management ATM Multiservice Networks
> Data Backbone & Optical Services Division Ericsson Telecom AB
--
Nico Weling
Software Designer
Ericsson Eurolab Deutschland GmbH
Verification Tool Design
Tel: +49 2407 575 5217
Fax: +49 2407 575 651
Dect:+49 2407 575 89339
mailto:Nico.Weling@REDACTED
More information about the erlang-questions
mailing list