A List of Mathematica Functions
- To: mathgroup at yoda.physics.unc.edu
- Subject: A List of Mathematica Functions
- From: sg04%ploni at gte.com (Yechezkal Shimon Gutfreund)
- Date: Wed, 25 Nov 92 11:53:41 EST
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 an ISSUE. [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 ! [{p1.................. [{p1................... etc. I create symbols for each one (f1, f2, f3, ...) and save them away as follows: f1[{p1, p2, p3, ... pn}] := ! body ! f2[{p1.................. f3[{p1................... etc. 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 capabilities. Or is there another way to do this that will give good performance and be somewhat cleaner? -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= Yechezkal Shimon Gutfreund sgutfreund at gte.com GTE Laboratories, Waltham MA harvard!bunny!sgutfreund -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=