MathGroup Archive 1992

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

Search the Archive

A List of Mathematica Functions

Is there some way to create anonymous (pure) functions that have do pattern
match? Let me first describe my application and then return to this question:

My applications:

I have two lists:

1) a list of tuples of the form {x1, x2, x3, ... xn}
where x can be either an integer or string literal

2) a list of pattern matching functions of the form:

f[{p1, p2, p3 ... pn}] := ! body !

p is any legal mathematica pattern,
body is usually a Block[] of Mathematica statements.

I want to map the functions over the list of tuples. Speed/Performance IS

[This is almost like a list of transformation rules mapped via the /. operator,
but in this case I do not care to have any side-effects, and I want all rules
tried for all tuples].

Users enter the functions in string form. I parse them and convert them
(via ToExpression) to the form:

[{p1, p2, p3, ... pn}] := ! body !


I create symbols for each one (f1, f2, f3, ...) and save them away as follows:

f1[{p1, p2, p3, ... pn}] := ! body !


using a different f symbol for each function. I then put the pure
function form in the list {f1[#]&, f2[#]&, .....}

(actually it is a composed function that has a setup routine called g1 so
the list looks like:

{f1[g1[#]]&, f2[g2[#]]&, ....}

I find this clumsy and awkward. I.e this business of creating dummy functions
called f1, g1, f2, g2, etc. 

Can I not store the functions in the following list of cells:

f[1] := !function 1!
f[2] := !function 2!

where function 1 is a pure function form (with pattern matching)?

Or store the pure functions directly in a list. But again, the only functions
I have seen that one can store in a list or in a cell (e.g. f[1]) are
pure functions and pure functions do not seem to have pattern matching

Or is there another way to do this that will give good performance and
be somewhat cleaner?

Yechezkal Shimon Gutfreund		 		  sgutfreund at
GTE Laboratories, Waltham MA			    harvard!bunny!sgutfreund

  • Prev by Date: Vector multiplication??
  • Next by Date: help on integration
  • Previous by thread: Vector multiplication??
  • Next by thread: time consumption FindRoot