MathGroup Archive 2009

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: How can I parse arguments of an expression unevaluated?


Erich Neuwirth wrote:
> What I would like to have is the following:
> I want to give the expression
> MyFunArgs[1, 2, a = 3, b = 4]
> and I would like to get 3 lists,
> the first list has all the arguments which are
> not written as an assignment, {1,2}
> The second list should be a list of strings
> with the names of the variables to be assignes
> {"a","b"}
> and the third list should be the values to be assigned:
> {3,4}
> 
> so
> MyFunArgs[1, 2, a = 3, b = 4]
> should produce
> {{1,2},{"a","b"},{3,4}}
> 
> How can I accomplish this?

SetAttributes[MyFunArgs, HoldAll]

MyFunArgs[args___] := Join[
  {List @@ DeleteCases[Hold[args], _Set]},
  Transpose[
   Cases[Hold /@ Hold[args],
    Hold[Set[a_, b_]] :> {ToString[Unevaluated[a]], b}]]
  ]


hth,

albert


  • Prev by Date: Re: Problem with 3d graphics on Linux
  • Next by Date: Re: How to define the coefficients of a polynomial to be real?
  • Previous by thread: Re: How can I parse arguments of an expression unevaluated?
  • Next by thread: Plotting surface with thickness