MathGroup Archive 2005

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

Search the Archive

Re: A few usage based questions

  • To: mathgroup at
  • Subject: [mg61170] Re: A few usage based questions
  • From: "Jens-Peer Kuska" <kuska at>
  • Date: Tue, 11 Oct 2005 06:29:56 -0400 (EDT)
  • Organization: Uni Leipzig
  • References: <difrd0$ffr$>
  • Sender: owner-wri-mathgroup at


expr = whatReplace[{a, 2, 3, b, c} , {a_Symbol -> 
0, a_Integer -> "Ho ho!"}]

Block[{whatReplace = ReplaceAll},


Block[{whatReplace = ReplaceRepeated},

you cant use the short form "/." or  "//.", 
Mathematica has a parser and not a string 
rewriting system.

b) Mathematica has not types and it is a untyped 
language. You can restrict the pattern for a rule 
application. A pattern is mutch more powerfull 
than an "type". In your example I would prefer

ff[x : (_Real | _Integer)] := Boah

because it avoid the repeated usage of the x. But 
as long as it works there should be no problem.

c) you always know, that a function return a 
Mathematica expression.



"Matt" <anonmous69 at> schrieb im 
Newsbeitrag news:difrd0$ffr$1 at
| Hello,
|  any light shed on the following would be 
| Question 1:  If I wanted to experiment with 
ReplaceAll and
| ReplaceRepeated, how would I use a variable to 
achieve this?
| e.g.  I tried this:
| replaceType = /.; (* replaceType would also be 
//. for subsequent
| runs*)
| (* initialize counter *)
| counter = 0;
| resultOne = (2 a M[1] M[
|  2] M[] + 3 b M[1, 3] M[2] M["s"] + Log[f[
|        M[1] M[1.2] M[3.4] M[M]]]) replaceType 
|        m2_M :> (++counter; MContainer[m1, m2])}
| but got the following error:
| Syntax::sntxb : Expression cannot begin with 
"replaceType = /.;".
| More...
| What I was trying to achieve (for an obviously 
longer example) was to
| be able to set the type of replace I wanted to 
do at the beginning of
| the cell, then use that symbolic name inside of 
the actual 'code'.
| BTW, the sample I am attempting to modify is 
from page 615 of Michael
| Trott's "The Mathematica Guidebook for 
| Question 2:  What is the correct method to limit 
the types of values a
| function will accept?
| If I wanted to constrain the argument type of a 
function to be all
| reals, is this the right way?
| f[x_Real|x_Integer] := something
| The above works, but I haven't seen my attempt 
confirmed in any
| documentation.
| Question 3:  How do I know what a function 
returns?  (e.g. a boolean or
| Null or an integer, a string, etc.)
| Thanks much,
| Matt

  • Prev by Date: Re: Argument checking while allowing specific assignments
  • Next by Date: Re: A few usage based questions
  • Previous by thread: A few usage based questions
  • Next by thread: Re: A few usage based questions