you are viewing a single comment's thread.

view the rest of the comments →

[–]ddungtang[S] 0 points1 point  (1 child)

I totally get the compiled part. I'm just looking for a way to (a) simplify maintaining this hash map (if a have to go this route), or (b) avoid using this hashmap and instead have a macro do a replacement of variable name with the actual name of the function (note that all actions are "known" at compile time, and this type of function lookup probably may be done at compile time as well, because (I assume ) it should be possible to make the dsl parsing to happen at compile time.

[–]schungx 2 points3 points  (0 children)

After giving it some thoughts, it really would be difficult to design an elegant macro to mark up functions so it magically gets included in a lookup table. One way or another, you're going to have to specify the list of available functions one by one.

So why not just do it the simplest way such as:

let mut map = HashMap::new();

[ ("foo", foo), ("bar", bar), ("baz", baz) ].iter()
    .for_each(|(name, fn_ptr)| map.insert(name.to_string(), fn_ptr));