[erlang-questions] how: to construct and evaluate qlc expressions dynamically

Rick Pettit rpettit@REDACTED
Mon Dec 17 23:21:17 CET 2007


I am trying to write a function which takes as input a table name and a 
list of query constraints in the form of triplets (column id, operator, value)
which returns a fun wrapping the equivalent qlc expression.

For example:

  QLCFun = generate_qlc_fun("favorites",[{"flavor","==","chocolate"},
                                         {"number","<=","3"}]).

QLCFun should be roughly equivalent to:

  qlc:q([X || X <- mnesia:table(favorites),
              X#favorites.flavor == "chocolate",
              X#favorites.number <= 3]).
    
So far I've stumbled across the erl_syntax manpage and functions:

  list_comp_template/1
  list_comp_body/1
  list_comp/2

Am I in the ballpark, or is there a better way to do this?

Anyone know of a place where a beginner (to dynamic generation and evaluation
of erlang code) can find decent sample code?

-Rick



More information about the erlang-questions mailing list