MathGroup Archive 2007

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

Search the Archive

Re: Re: MakeExpression problem

  • To: mathgroup at smc.vnet.net
  • Subject: [mg77167] Re: [mg77110] Re: [mg77095] MakeExpression problem
  • From: DrMajorBob <drmajorbob at bigfoot.com>
  • Date: Tue, 5 Jun 2007 06:38:25 -0400 (EDT)
  • References: <200706031013.GAA02923@smc.vnet.net> <20534386.1180947138240.JavaMail.root@m35>
  • Reply-to: drmajorbob at bigfoot.com

For instance:

DoubleLongRightArrow[a_, b_] := Rule[a, b]
a==>b

a -> b

(The second input line is entered as a Esc==>Esc b.

Bobby

On Mon, 04 Jun 2007 02:45:02 -0500, Chris Chiasson <chris at chiasson.name>
wrote:

> Warning: I do not fully understand how operators are defined in
> Mathematica, however I have some idea.
>
> AFAIK, a MakeExpression rule is useless in a non-notebook environment
> because the commands are (then) not represented as boxes.
>
> You do not have to catch the DoubleLongRightArrow operator at the
> "parsing" stage. Once
> a==>b is read into Mathematica, it becomes the following expression  
> (AFAIK):
>
> DoubleLongRightArrow[a,b]
>
> You can easily define a DownValue for DoubleLongRightArrow to do what 
> you want.
>
> This method should work for both notebooks and package files.
>
> On 6/3/07, Hannes Kessler <HannesKessler at hushmail.com> wrote:
>> Hello,
>>
>> here is a small package defining and using a generic MakeExpression
>> interpretation rule:
>>
>> BeginPackage["DoubleLongRightArrow`"];
>> {test1,test2,a,b,interpretation};
>> Begin["`Private`"];
>> MakeExpression[RowBox[{x_,"\[DoubleLongRightArrow]",y_}],form_]:=
>>    MakeExpression[RowBox[{"interpretation"}],form];
>> test1=a\[DoubleLongRightArrow]b;
>> (*The following assigment forces an interpretation by additional
>> application of //ToBoxes//ToExpression*)
>> test2=a\[DoubleLongRightArrow]b//ToBoxes//ToExpression;
>> End[];
>> EndPackage[];
>>
>> Here is a small notebook which calls the package.
>> The typesetted \[DoubleLongRightArrow] looks in the notebook like ==
=>.
>>
>> Needs["DoubleLongRightArrow`"];
>> (*The following expression is correctly interpreted in the notebook:*)
>> In[] a==>b
>> Out[] interpretation
>> (*The expression read in the package is not interpreted:*)
>> In[] test1
>> Out[] a==>b
>> (*Only the second expression converted first to boxes and then again
>> to an expression is interpreted correctly*)
>> In[] test2
>> Out[] interpretation
>>
>> My question is, how can I define an interpretation rule in a package
>> and use it in the same or other packages, not only in notebooks?
>>
>> Regards,
>> Hannes Kessler
>>
>>
>>
>
>



-- 
DrMajorBob at bigfoot.com


  • Prev by Date: Re: Evaluate, Replace, and Hold
  • Next by Date: Dynamic 2D plotting in V6
  • Previous by thread: Re: MakeExpression problem
  • Next by thread: Re: MakeExpression problem