Author: Travis
Posted: 24 Mar 2013 09:56:57 pm (GMT -5)
The part( function may help. It's essentially a parsing tool.
solve(x^2=4,x) returns x=2 or x=-2
part(solve(x^2=4,x)) returns 2, the number of arguments to the top-level function/operator in the expression.
To get each of these two arguments:
part(solve(x^2=4,x),1) returns x=2
part(solve(x^2=4,x),2) returns x=-2
To get the top-level function:
part(solve(x^2=4,x),0) returns or
This can be applied recursively to parse the rest of the expression, for example:
part(solve(x^2=4,x),1)→a [returns x=2 and stores the expression into a]
part(a) returns 2
part(a,1) returns x
part(a,2) returns 2
part(a,0) returns =
You could use this to make a subprogram or function that searches for the values and puts them in a list, or something like that.
_________________
![]()
Posted: 24 Mar 2013 09:56:57 pm (GMT -5)
The part( function may help. It's essentially a parsing tool.
solve(x^2=4,x) returns x=2 or x=-2
part(solve(x^2=4,x)) returns 2, the number of arguments to the top-level function/operator in the expression.
To get each of these two arguments:
part(solve(x^2=4,x),1) returns x=2
part(solve(x^2=4,x),2) returns x=-2
To get the top-level function:
part(solve(x^2=4,x),0) returns or
This can be applied recursively to parse the rest of the expression, for example:
part(solve(x^2=4,x),1)→a [returns x=2 and stores the expression into a]
part(a) returns 2
part(a,1) returns x
part(a,2) returns 2
part(a,0) returns =
You could use this to make a subprogram or function that searches for the values and puts them in a list, or something like that.
_________________
