Metaprogramming

Yariv Sadan yarivvv@REDACTED
Thu Aug 24 16:05:27 CEST 2006


>
>   Fields = [id, name, age],
>   <|sql| SELECT @@Fields FROM @Table |>
>

FYI,

There's a (less slick but pure Erlang) runtime way of doing something
similar with smerl:

-module(db).
-compile(export_all).

meta_select(Fields, Table) ->
   "SELECT " ++ cocat(Fields) ++ " FROM " ++ atom_to_list(Table).

main() ->
  M1 = smerl:for_module(db),
  {ok, M2} = smerl:curry_add(M1, db, meta_select, 2, [[name, age],
person], people),
  {ok, M3} = smerl:curry_add(M2, db, meta_select, 2, [[color,
num_edges], shape], shapes),
  smerl:compile(M3),
  db:people(),  %% returns  "SELECT name, age FROM person"
  db:shapes(). %% returns "SELECT color, num_edges FROM shape"


Cheers,
Yariv



More information about the erlang-questions mailing list