Converting string to match specification

Anders Nygren anders_nygren2002@REDACTED
Thu Jul 31 21:59:10 CEST 2003


 --- Vladimir Sekissov <svg@REDACTED> skrev: > Opps,
sorry, I forgot code.
> 
> -module(test).
> 
> -export([str2ms/1]).
> 
> str2ms(FunStr) ->
>   {ok, Tokens, _} = erl_scan:string(FunStr),
>   {ok, [Form]} = erl_parse:parse_exprs(Tokens),
>   {'fun', _, {clauses, Clauses}} = Form,
>   case ms_transform:transform_from_shell(ets,
> Clauses, []) of
>     {error,[{_,[{_,_,Code}|_]}|_],_} ->
>       io:format("Error: ~s~n",
> 		[ms_transform:format_error(Code)]),
>       {error,transform_error};
>     Else ->
>       Else
>   end.
> 
> 
> (svg@REDACTED)17> test:str2ms("fun (X) -> {x, X}
> end.").
> [{'$1',[],[{{x,'$1'}}]}]
> 

Thank You Vlad,
Unfortunately it does not completely solve my problem,
because ms_transform_from_shell does not allow
records.
I was not clear in my first email, what I want is
something similar to.

-module(test).
-include("..../event.hrl").
-export([do/0]).

do()->
   ets:fun2ms("fun (X) when is_record(X,event) ->
                  {foo,X,bar}
               end.").


/Anders

_____________________________________________________
Gå före i kön och få din sajt värderad på nolltid med Yahoo! Express
Se mer på: http://se.docs.yahoo.com/info/express/help/index.html



More information about the erlang-questions mailing list