Operationally, variables are Symbols in the parse tree, minus those 
occurring in e.g. the first argument of a :call expression or a 
:conditional expression, or some other special forms.

You can get a feel for the structure of a parsed expression using head and 
args recursively:

julia> :(3*x+cos(z)).head
:call

julia> :(3*x+cos(z)).args[1]
:+

julia> :(3*x+cos(z)).args[2]
:(3x)

julia> :(3*x+cos(z)).args[2].head
:call

julia> :(3*x+cos(z)).args[2].head.args[1]
ERROR: type Symbol has no field args

julia> :(3*x+cos(z)).args[2].args[1]
:*

etc. 

The tricky part, then, is making sure you take account of all the relevant 
special forms.

Is there a list somewhere of all the symbols that might be the head of an 
expression?

On Tuesday, May 6, 2014 12:23:29 PM UTC-7, El Afrit Mariem wrote:
>
> Hi,
>
> Is it possible to extract the list of variables from an expression?
>
> Example:
>
> expr = "3*x+cos(z)"
>
> and I want to have as a result this list : [x,z]
>
> Thank you
>

Reply via email to