list-comprehension-like expansion inside Julia expression? -


is possible have list comprehension building complicated expressions in julia?

for example, have symbols , types, , want build type them. right now, have like.

syms = [:a, :b, :c] typs = [int, float32, char] new_type = :(type foo end) new_type.args[3].args = [:($sym::$typ) (sym,typ) in zip(syms,typs)] 

this works in new_type expression containing

:(type foo     a::int64     b::float32     c::char end) 

but building complicated expressions both extremely error prone (because have intimately knowledgeable expr data type in order know, eg expressions data types of tuple have stored in new_type.args[3].args) , extremely brittle in change ast of expression being built mean having change where/how every sub-expression stored.

so there way like

:(type foo     $(sym::typ (sym,typ) in zip(syms,typs)) end) 

and end same expression above?

yes, can splat arrays of expressions directly syntax:

julia> :(type foo            $([:($sym::$typ) (sym,typ) in zip(syms,typs)]...)        end) :(type foo # none, line 2:         a::int64         b::float32         c::char     end) 

Comments

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -