bizarre match specs

Ulf Wiger (AL/EAB) ulf.wiger@REDACTED
Thu Jan 19 16:56:33 CET 2006

I was toying around with using match specifications
to search on filenames. The idea was basically to 
take a match specification and compile parts of it to
a regexp-like thingie, and traverse a file tree.

(There is a reason, which at least in my mind seems 
sound, but that's a long story.)


1> MS = fun(Objs,Ms) -> Bin=ets:match_spec_compile(Ms),
             ets:match_spec_run(Objs, Bin) end.

2> L=[{"foo_a.erl",a},{"foo.erl",b},{"fooerl",c}].

3> MS(L,[{{"foo" ++

Cool, eh? /:

Obviously, it's too ground to be generally useful, and 
I haven't tested how deeply I can nest the guards before
the whole thing chokes or gets totally useless.

Boy, would I like to have a regexp pattern in the match spec,
or perhaps 'let' and 'skipwhile' in the guards... ;-)

{{"foo" ++ '$1', '_'}, 
   {let, '$2',
    {skipwhile, {tl,'$1'},
     {'==', '$2', ".erl"}}}}],

One could also imagine bit syntax expressions in 
match specifications, right?  (:

Or should I just look for thrills elsewhere?


More information about the erlang-questions mailing list