stillearningsomething
stillearningsomething

Reputation: 572

make list of expressions from expression of a list in julia

Is there a way to go from an expression of a list to a list of expressions in julia without having to evaluate the intermediaries?

i.e.

julia> l = :([1, 2+x, 5, 3/x])
:([1, 2 + x, 5, 3 / x])

julia> @eval [$(quote e end) for e in $l]
ERROR: UndefVarError: x not defined

The ideal state would be:

[1, :(2 + x), 5, :(3 / x)])

Upvotes: 2

Views: 127

Answers (1)

Bogumił Kamiński
Bogumił Kamiński

Reputation: 69869

This is the way to do it (if I understand correctly what you want):

julia> l.args
4-element Array{Any,1}:
 1
  :(2 + x)
 5
  :(3 / x)

Upvotes: 3

Related Questions