Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
1998
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 1998

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

Search the Archive

Re: Impossible?



> 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: acus@itpa.lt
>    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[1]:= AbsoluteLevel[___] := $AbsoluteLevel[0]

In[2]:= _[___, $AbsoluteLevel[p_], ___] ^:= $AbsoluteLevel[p+1]

In[3]:= AbsoluteLevelCatch[$AbsoluteLevel[p_]] ^:= p

In[4]:= AbsoluteLevelCatch[
            a*(b+c*(d+AbsoluteLevel[e]))]

Out[4]= 4

If you really want this to just climb out to the outer level, you could
do

In[5]:= $Pre = AbsoluteLevelCatch ;

In[6]:= a*(b+c*(d+AbsoluteLevel[e]))

Out[6]= 4

Dave Withoff
Wolfram Research



  • Prev by Date: Re: List Manipulation
  • Next by Date: Re: lists
  • Prev by thread: Re: Impossible?
  • Next by thread: Questions on MultipleListPlot