Am 17.08.2014 00:37, schrieb Keith McDonald:
> Thanks for the quick response.
>
> I understand most of what was said.
>
> How does one generate an expression out of key => value
>
> Pretend I have a really simple example. My map has "key1" => "value1"
> and "key2" => "value2". So I create an array. The first item in the
> array will be an expression representing "key1" => "value1". What is
> the syntax to create such an expression? A string like "key1 =>
> value1" is just a literal which isn't an expression I am assuming. The
> syntax is a little bewildering at the start and I am just trying to
> get my head around it.
Speaking in ExprDef it's EBinop(OpArrow, EConst(String("key1")),
EConst(String("value1"))), so => is a binary operator like + and -. It's
much simpler with reification because you can just use `macro $eKey =>
$eValue` where both eKey and eValue are Expr. If you only have strings
or other basic types, you can use `$v{yourString}` to get an expression
out of it. See
http://haxe.org/manual/macro-reification-expression.html
for more information on reification.
> Also - can I make an expression out of something a little more
> complicated like "key1" => ["key3" => "value3", "key4" => "value4"]
Anything you can write in syntax you can generate from macros, so yes.
Simon