Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2010

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

Search the Archive

Re: SyntaxInformation Question

  • To: mathgroup at smc.vnet.net
  • Subject: [mg110792] Re: SyntaxInformation Question
  • From: "E. Martin-Serrano" <eMartinSerrano at telefonica.net>
  • Date: Wed, 7 Jul 2010 07:40:40 -0400 (EDT)

Thanks Bill,

Very useful your remarks. Mainly the one about the symbols that might
evaluate to options as in 

Options[f]={aaa->1,bbb->2,ccc -> 4};

SyntaxInformation[f]={"ArgumentsPattern"->{_,_,OptionsPattern[]}};

f[x, y, z, k, l, m, aaa->2,bbb->3,ccc->4].

It seems to me that SintaxInformation[] is a bit tricky to use as a syntax
oriented tool; since, at least in this respect, the form that Mathematica
treats SyntaxInformation[] involves both semantics and syntax. In the
example, "k", "l", "m" are not by any means under the form of an option rule
and if the parser were able to color separately the hypothetically offending
elements (due to semantics) one could decide whether these elements are
meant to evaluate to options or not. 

That is why your remark has been usefull. By keeping the focus in the form,
I had hardly ever thought "k", "l", "m" were being taken as potential
options. 

Besides, IMO in the case of

f[x, {a, b}, Sequence@@Array[x&, 100]], the parser should be able to know
that Sequence@@Array[x&, 100] is just a sequence of 100 elements which
clearly breaks the syntaz specification.

In other words perhaps SintaxInformation[] should distinguish between sintax
violation indications and semantic warnings.

Thanks again.

Emilio.  



-----Original Message-----
From: Bill Rowe [mailto:readnews at sbcglobal.net] 
Sent: Tuesday, July 06, 2010 3:14 AM
To: mathgroup at smc.vnet.net
Subject: [mg110792] [mg110775] Re: SyntaxInformation Question

On 7/5/10 at 6:02 AM, eMartinSerrano at telefonica.net (E.
Martin-Serrano) wrote:


>In the ref/SyntaxInformation in the Help there is the following
>example or explanation can be found:

>"f can have any number of arguments, but each should be a
>two-element list:"

>SyntaxInformation[f] = {"ArgumentsPattern" -> {{_, _} ...}};

>{f[{x, y}, {a, b}], f[x, {a, b}, {x, y, z}]};

>But finally '{x, y, z}' is a three elements list but it is allowed to
>pass the constrain too; and so do {v, x, y, z}, and {u, v, x, y, z},

No, not true. When you look at the documentation page for
SyntaxInformation, actually execute the cell containing:

SyntaxInformation[f] = {"ArgumentsPattern" -> {{_, _} ...}};

and note the color for z changes from blue to red (assuming
default syntax coloring) indicating a syntax error. And further
if you paste any of the above examples into the documentation
notebook you will find all of the elements of the last list past
the first two are colored red.

>and any list of whatever any other length as this {f[{x, y}, {a, b}],
>f[x, {a, b}, Sequence@@Array[x&, 100]]}.

In this last example, you have an expression being given as an
argument. There is no way for Mathematica to show an syntax
error until that expression is evaluated. So, simply typing it
in cannot cause an indication of a syntax error.

>In the example

>Options[f]={aaa->1,bbb->2,ccc -> 4};
>SyntaxInformation[f]={"ArgumentsPattern"->{_,_,OptionsPattern[]}};

>The syntax specification allows for two parameters and a list of
>options to be submitted to the function =91f[]=92.

>The following does work as expected since the following is allowed
>to pass it is right since just two parameters and a list of options
>are submitted as specified)

>f[x,y, aaa->2,bbb->3,ccc ->4];

>But the following is allowed to pass too, despite, in this case, 6
>parameters *x, y, z, k, l, m* (plus the options) are submitted
>instead of just the two specified parameters.

>f[x, y, z, k, l, m, aaa->2,bbb->3,ccc->4];

>When I say they pass, I mean nothing is colored red saying that
>something is syntactically wrong and must be corrected..

The additional arguments z, k, l, m could all evaluate as a
options rule. So, they are not colored red since they might be
valid syntax.

>This occurs  in version 7.0.1. for Windows XP SP3.

I am using version 7.0.1 on Mac OS X version 10.6.4. But I don't
believe the difference in platform is significant.




  • Prev by Date: Problem with a diagram
  • Next by Date: Re: PlotLegend-> and DateListPlot[]...incompatible or broken?
  • Previous by thread: Re: SyntaxInformation Question
  • Next by thread: Change Default Button Method