rfc: rdbms - new type system

Ulf Wiger (AL/EAB) ulf.wiger@REDACTED
Wed Mar 1 11:10:46 CET 2006


My solution will be to use my own match spec
evaluator. I did some benchmarking, and the 
difference in run-time cost is minimal, partly
because my data is already on the process heap,
and the built-in match specs must be "compiled"
before use in match_spec_run.

Now I can do this:

1> rdbms_ms:run_ms([{1,["deep"," list"]}],
    [{{'$1','$2'},[],[{{'$1',{list_to_binary,'$2'}}}]}]).
[{1,
  <<100,101,101,112,108,105,115,116>>}] 

which of course is very nice for compacting the database.
The corresponding output filter would be:

2>
rdbms_ms:run_ms(v(-1),[{{'$1','$2'},[],[{{'$1',{binary_to_list,'$2'}}}]}
]).                          [{1,"deep list"}]

if one doesn't want to mess with binaries in the program.

My match spec library also has the added bonus of 
'let' and 'subterm' operators in the guards, to
enable recursive matching.  (:

/Ulf W

> -----Original Message-----
> From: owner-erlang-questions@REDACTED 
> [mailto:owner-erlang-questions@REDACTED] On Behalf Of Ulf 
> Wiger (AL/EAB)
> Sent: den 28 februari 2006 11:10
> To: erlang-questions@REDACTED
> Subject: RE: rfc: rdbms - new type system
> 
> 
> Ulf Wiger wrote:
> > 
> > I'm toying with the idea of allowing a match specification as a 
> > table-level 'type' specification:
> > 
> > Ms = [{{1,2,'$1'}, [{is_integer,'$1'}], [{{1,2,{float,'$1'}}}]}].
> > [{{1,2,'$1'},[{is_integer,'$1'}],[{{1,2,{float,'$1'}}}]}]
> > 10> ets:match_spec_run([{1,2,3}],ets:match_spec_compile(Ms)).
> > 
> > [{1,2,3.00000}]
> 
> 
> Why did this work at all, btw?
> 
> Re-reading the manual, I couldn't find mention of 
> {float,'$1'} as a valid term construct.
> 
> After having inserted code in rdbms to allow for a match spec 
> as an input or output filter (basically a term rewriting 
> filter, or just a record-level type check), I started 
> thinking that perhaps the most useful rewriting op of all 
> would be list_to_binary (and binary_to_list in the output filter)
> 
> But list_to_binary obviously doesn't work in a match spec. 
> Why not? And why does {float,'$1'} work?
> 
> /Ulf W
> 



More information about the erlang-questions mailing list