- To: email@example.com
- Subject: [mg10516] Re: [mg10458] Impossible?
- From: David Withoff <firstname.lastname@example.org>
- Date: Tue, 20 Jan 1998 02:23:03 -0500
> Hello, > > I would like to construct a function which gives me an absolute Level of > subexpression in expression. For example I want: > > a*(b+c*(d+AbsoluteLevelQ[e])) > > evaluate to > > Level[a*(b+c*(d+e)),e]. > ( AbsoiuteLevelQ climbs up until reaches In, after that calls Level > ) > > More generally, I would like to control absolute level (level in respect > to In[%]) at which patter matching take place. For example if pattern > matches at Level n>3, then rule is applied, but if it matches at > Level n<3 then not. > > I suspect, that evaluation machinery here is hardly involved. Do > Mathematica language provides tools for such a control? Please comment > if solution don't exist. > > > > Arturas Acus > Institute of Theoretical > Physics and Astronomy > Gostauto 12, 2600,Vilnius > Lithuania > > > E-mail: email@example.com > Fax: 370-2-225361 > Tel: 370-2-612906 I think that for this function to be useful you will need to introduce a second function that defines where AbsoluteLevel should climb to. If AbsoluteLevel climbs through until it reaches the outermost level of evaluation, you would never be able to use it in a program, since it would climb right out through your program. With that second function, you could do this: In:= AbsoluteLevel[___] := $AbsoluteLevel In:= _[___, $AbsoluteLevel[p_], ___] ^:= $AbsoluteLevel[p+1] In:= AbsoluteLevelCatch[$AbsoluteLevel[p_]] ^:= p In:= AbsoluteLevelCatch[ a*(b+c*(d+AbsoluteLevel[e]))] Out= 4 If you really want this to just climb out to the outer level, you could do In:= $Pre = AbsoluteLevelCatch ; In:= a*(b+c*(d+AbsoluteLevel[e])) Out= 4 Dave Withoff Wolfram Research