Prev: The side-effects of mixing TraditionalForm inside expressions.
Next: a 4d algebraic geometry problem
From: E. Martin-Serrano on 5 Jul 2010 06:02 Hi, 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}]}; In the first part of the example: 'f[{x, y}, {a, b}]', the list =91{x, y}' is a two - elements list, so is '{a, b}', then syntax constrain holds and it is understandable for me. In the second part of the example: 'f[x, {a, b}, {x, y, z}]', the symbol ' x=92 evaluates to a list but not necessarily to a 'two - elements list' as demanded in the SyntaxInformation[f] = {"ArgumentsPattern" -> {{_, _} ...}} declaration. According to the scarce explanation in the example it is not excluded for 'x' to evaluate to a '12 - elements list=92 {x, y}'; however the syntax constrain allows it to pass; following with the example the list ' {a, b}' is again a two - elements list, so it pass the check. 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}, and any list of whatever any other length as this {f[{x, y}, {a, b}], f[x, {a, b}, Sequence@@Array[x&, 100]]}. 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.. I am certainly missing something important here and, clearly I do not understand the explanation given to this very basic programming command. So I would appreciate any clarification or help from the group. Or maybe Wolfram should provide a complete tutorial on it or a clearer explanation. This occurs in version 7.0.1. for Windows XP SP3. E. Martin-Serrano ___________________________________________________ This e-mail and the documents attached are confidential and intended = solely for the addressee; it may also be privileged. If you receive this e-mail = in error, please notify the sender immediately and destroy it. As its = integrity cannot be secured on the Internet, E. Mart=EDn-Serrano liability cannot = be triggered for the message content. Although the sender endeavors to = maintain a computer virus-free network, the sender does not warrant that this transmission is virus-free and will not be liable for any damages = resulting from any virus transmitted. Este mensaje y los ficheros adjuntos pueden contener informaci=F3n confidencial destinada solamente a la(s) persona(s) mencionadas anteriormente pueden estar protegidos por secreto profesional y en cualquier caso el mensaje en su totalidad est=E1 amparado y protegido = por la legislaci=F3n vigente que preserva el secreto de las comunicaciones, y = por la legislaci=F3n de protecci=F3n de datos de car=E1cter personal. Si usted = recibe este correo electr=F3nico por error, gracias por informar = inmediatamente al remitente y destruir el mensaje. Al no estar asegurada la integridad de = este mensaje sobre la red, E. Mart=EDn-Serrano no se hace responsable por su contenido. Su contenido no constituye ning=FAn compromiso para el = remitente, salvo ratificaci=F3n escrita por ambas partes. Aunque se esfuerza al = m=E1ximo por mantener su red libre de virus, el emisor no puede garantizar nada = al respecto y no ser=E1 responsable de cualesquiera da=F1os que puedan = resultar de una transmisi=F3n de virus. ------=_NextPart_000_0000_01CB1C2F.C9826E00 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable <html xmlns:v="urn:schemas-microsoft-com:vml" = xmlns:o="urn:schemas-microsoft-com:office:office" = xmlns:w="urn:schemas-microsoft-com:office:word" = xmlns="http://www.w3.org/TR/REC-html40"> <head> <meta http-equiv=Content-Type content="text/html; = charset=iso-8859-1"> <meta name=Generator content="Microsoft Word 11 (filtered medium)"> <style> <!-- /* Font Definitions */ @font-face {font-family:Courier; panose-1:2 7 4 9 2 2 5 2 4 4;} /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal {margin:0in; margin-bottom:.0001pt; font-size:12.0pt; font-family:"Times New Roman";} a:link, span.MsoHyperlink {color:blue; text-decoration:underline;} a:visited, span.MsoHyperlinkFollowed {color:purple; text-decoration:underline;} span.EmailStyle17 {mso-style-type:personal-compose; font-family:Arial; color:windowtext;} span.MathematicaFormatStandardForm {font-family:Courier;} @page Section1 {size:8.5in 11.0in; margin:1.0in 1.25in 1.0in 1.25in;} div.Section1 {page:Section1;} --> </style> </head> <body lang=EN-US link=blue vlink=purple> <div class=Section1> <p class=MsoNormal style='text-autospace:none'><font size=3 face="Times New Roman"><span = style='font-size:12.0pt'>Hi,<o:p></o:p></span></font></p> <p class=MsoNormal style='text-autospace:none'><font size=3 face="Times New Roman"><span = style='font-size:12.0pt'><o:p> </o:p></span></font></p> <p class=MsoNormal style='text-autospace:none'><font size=3 face="Times New Roman"><span style='font-size:12.0pt'>In the = ref/SyntaxInformation in the Help there is the following example or explanation can be = found:<o:p></o:p></span></font></p> <p class=MsoNormal style='text-autospace:none'><font size=3 face="Times New Roman"><span = style='font-size:12.0pt'><o:p> </o:p></span></font></p> <p class=MsoNormal style='text-autospace:none'><font size=3 face="Times New Roman"><span = style='font-size:12.0pt'>"</span></font><span class=MathematicaFormatStandardForm><font = face=Courier>f</font></span> can have any number of arguments, but each should be a two-element list:" = <o:p></o:p></p> <p class=MsoNormal style='text-autospace:none'><font size=3 face="Times New Roman"><span = style='font-size:12.0pt'><o:p> </o:p></span></font></p> <p class=MsoNormal style='text-autospace:none'><font size=3 face="Times New Roman"><span = style='font-size:12.0pt'>SyntaxInformation[f] = {"ArgumentsPattern" -> {{_, _} = ....}};<o:p></o:p></span></font></p> <p class=MsoNormal style='text-autospace:none'><font size=3 face="Times New Roman"><span = style='font-size:12.0pt'><o:p> </o:p></span></font></p> <p class=MsoNormal style='text-autospace:none'><font size=3 face="Times New Roman"><span style='font-size:12.0pt'>{f[{x, y}, {a, = b}], f[x, {a, b}, {x, y, z}]};<o:p></o:p></span></font></p> <p class=MsoNormal style='text-autospace:none'><font size=3 face="Times New Roman"><span = style='font-size:12.0pt'><o:p> </o:p></span></font></p> <p class=MsoNormal = style='margin-right:-.5in;text-autospace:none'><font size=3 face="Times New Roman"><span style='font-size:12.0pt'>In the first = part of the example: 'f[{x, y}, {a, b}]', the list ‘{x, y}' is a two - = elements list, so is '{a, b}', then syntax constrain holds and it is = understandable for me.<o:p></o:p></span></font></p> <p class=MsoNormal = style='margin-right:-.25in;text-autospace:none'><font size=3 face="Times New Roman"><span = style='font-size:12.0pt'><o:p> </o:p></span></font></p> <p class=MsoNormal style='text-autospace:none'><font size=3 face="Times New Roman"><span style='font-size:12.0pt'>In the second = part of the example: 'f[x, {a, b}, {x, y, z}]', the symbol ' x’ evaluates to a = list but not necessarily to a 'two - elements list' as demanded in the = SyntaxInformation[f] = {"ArgumentsPattern" -> {{_, _} ...}} declaration. = According to the scarce explanation in the example it is not excluded for 'x' to = evaluate to a '12 - elements list’ {x, y}'; however the syntax constrain = allows it to pass; following with the example the list ' {a, b}' is again a two - = elements list, so it pass the check. 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}, and any list of whatever any other length as this {f[{x, y}, = {a, b}], f[x, {a, b}, Sequence@@Array[x&, = 100]]}.<o:p></o:p></span></font></p> <p class=MsoNormal style='text-autospace:none'><font size=3 face="Times New Roman"><span = style='font-size:12.0pt'><o:p> </o:p></span></font></p> <p class=MsoNormal style='text-autospace:none'><font size=3 face="Times New Roman"><span style='font-size:12.0pt'>In the example = <o:p></o:p></span></font></p> <p class=MsoNormal style='text-autospace:none'><font size=3 face="Times New Roman"><span = style='font-size:12.0pt'><o:p> </o:p></span></font></p> <p class=MsoNormal style='text-autospace:none'><font size=3 face="Times New Roman"><span = style='font-size:12.0pt'>Options[f]={aaa->1,bbb->2,ccc -> 4};<o:p></o:p></span></font></p> <p class=MsoNormal style='text-autospace:none'><font size=3 face="Times New Roman"><span = style='font-size:12.0pt'><o:p> </o:p></span></font></p> <p class=MsoNormal style='text-autospace:none'><font size=3 face="Times New Roman"><span = style='font-size:12.0pt'>SyntaxInformation[f]={"ArgumentsPattern= "->{_,_,OptionsPattern[]}}; <o:p></o:p></span></font></p> <p class=MsoNormal style='text-autospace:none'><font size=3 face="Times New Roman"><span = style='font-size:12.0pt'><o:p> </o:p></span></font></p> <p class=MsoNormal style='text-autospace:none'><font size=3 face="Times New Roman"><span style='font-size:12.0pt'>The syntax = specification allows for two parameters and a list of options to be submitted to the function ‘f[]’.<o:p></o:p></span></font></p> <p class=MsoNormal style='text-autospace:none'><font size=3 face="Times New Roman"><span = style='font-size:12.0pt'><o:p> </o:p></span></font></p> <p class=MsoNormal style='text-autospace:none'><font size=3 face="Times New Roman"><span style='font-size:12.0pt'>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)<o:p></o:p></span></font></p> <p class=MsoNormal style='text-autospace:none'><font size=3 face="Times New Roman"><span = style='font-size:12.0pt'><o:p> </o:p></span></font></p> <p class=MsoNormal style='text-autospace:none'><font size=3 face="Times New Roman"><span lang=ES = style='font-size:12.0pt'>f[x,y, aaa->2,bbb->3,ccc ->4];<o:p></o:p></span></font></p> <p class=MsoNormal style='text-autospace:none'><font size=3 face="Times New Roman"><span lang=ES = style='font-size:12.0pt'><o:p> </o:p></span></font></p> <p class=MsoNormal style='text-autospace:none'><font size=3 face="Times New Roman"><span style='font-size:12.0pt'>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.<o:p></o:p></span></font></p> <p class=MsoNormal style='text-autospace:none'><font size=3 face="Times New Roman"><span = style='font-size:12.0pt'><o:p> </o:p></span></font></p> <p class=MsoNormal style='text-autospace:none'><font size=3 face="Times New Roman"><span lang=ES style='font-size:12.0pt'>f[x, = y, z, k, l, m, aaa->2,bbb->3,ccc->4];<o:p></o:p></span></font></p> <p class=MsoNormal style='text-autospace:none'><font size=3 face="Times New Roman"><span lang=ES = style='font-size:12.0pt'><o:p> </o:p></span></font></p> <p class=MsoNormal style='text-autospace:none'><font size=3 face="Times New Roman"><span style='font-size:12.0pt'>When I say = they pass, I mean nothing is colored red saying that something is syntactically wrong = and must be corrected.. <o:p></o:p></span></font></p> <p class=MsoNormal style='text-autospace:none'><font size=3 face="Times New Roman"><span = style='font-size:12.0pt'><o:p> </o:p></span></font></p> <p class=MsoNormal style='text-autospace:none'><font size=3 face="Times New Roman"><span style='font-size:12.0pt'>I am certainly = missing something important here and, clearly I do not understand the = explanation given to this very basic programming command. So I would appreciate any = clarification or help from the group.<o:p></o:p></span></font></p> <p class=MsoNormal style='text-autospace:none'><font size=3 face="Times New Roman"><span = style='font-size:12.0pt'><o:p> </o:p></span></font></p> <p class=MsoNormal><font size=3 face="Times New Roman"><span = style='font-size: 12.0pt'>Or maybe Wolfram should provide a complete tutorial on it or a = clearer explanation.<o:p></o:p></span></font></p> <p class=MsoNormal><font size=3 face="Times New Roman"><span = style='font-size: 12.0pt'><o:p> </o:p></span></font></p> <p class=MsoNormal><font size=3 face="Times New Roman"><span = style='font-size: 12.0pt'>This occurs in version 7.0.1. for Windows XP = SP3.<o:p></o:p></span></font></p> <p class=MsoNormal><font size=3 face="Times New Roman"><span = style='font-size: 12.0pt'><o:p> </o:p></span></font></p> <p class=MsoNormal><font size=3 face="Times New Roman"><span = style='font-size: 12.0pt'>E. Martin-Serrano<o:p></o:p></span></font></p> <p class=MsoNormal><font size=2 face=Arial><span = style='font-size:10.0pt; font-family:Arial'><o:p> </o:p></span></font></p> <p class=MsoNormal><font size=2 face=Arial><span = style='font-size:10.0pt; font-family:Arial'><o:p> </o:p></span></font></p> <p class=MsoNormal><font size=2 face=Arial><span = style='font-size:10.0pt; font-family:Arial'>___________________________________________________</s= pan></font><o:p></o:p></p> <p class=MsoNormal><font size=3 face="Times New Roman"><span = style='font-size: 12.0pt'> <o:p></o:p></span></font></p> <p class=MsoNormal><font size=3 face="Times New Roman"><span = style='font-size: 12.0pt'>This e-mail and the documents attached are confidential and = intended solely for the addressee; it may also be privileged. If you receive this = in error, please notify the sender immediately and destroy it. As its = integrity cannot be secured on the Internet, E. Mart=EDn-Serrano liability = cannot be triggered for the message content. Although the sender endeavors to = maintain a computer virus-free network, the sender does not warrant that this transmission is virus-free and will not be liable for any damages = resulting from any virus transmitted. <br> <br> </span><span lang=ES-TRAD>Este mensaje y los ficheros adjuntos pueden = contener informaci=F3n confidencial destinada solamente a la(s) persona(s) mencionadas anteriormente pueden estar protegidos por secreto = profesional y en cualquier caso el mensaje en su totalidad est=E1 amparado y = protegido por la legislaci=F3n vigente que preserva el secreto de las comunicaciones, = y por la legislaci=F3n de protecci=F3n de datos de car=E1cter personal. Si usted = recibe este correo electr=F3nico por error, gracias por informar = inmediatamente al remitente y destruir el mensaje. Al no estar asegurada la integridad de = este mensaje sobre la red, E. Mart=EDn-Serrano no se hace responsable por su = contenido. Su contenido no constituye ning=FAn compromiso para el remitente, = salvo ratificaci=F3n escrita por ambas partes. Aunque se esfuerza al = m=E1ximo por mantener su red libre de virus, el emisor no puede garantizar nada al = respecto y no ser=E1 responsable de cualesquiera da=F1os que puedan resultar de = una transmisi=F3n de virus. </span></font><font size=2 face=Arial><span = lang=ES-TRAD style='font-size:10.0pt;font-family:Arial'><o:p></o:p></span></font></p= > <p class=MsoNormal><font size=3 face="Times New Roman"><span = lang=ES-TRAD style='font-size:12.0pt'><o:p> </o:p></span></font></p> </div> </body> </html> ------=_NextPart_000_0000_01CB1C2F.C9826E00--
From: E. Martin-Serrano on 5 Jul 2010 21:13 Hi, Sorry for the previous post that looks almost unreadable on my screen probably due to problems with hidden special characters which distort the page format and others. I hope this one reads better. __________________________________________________ In the ref/SyntaxInformation in the Help the following example 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}]}; In the first part of the example: 'f[{x, y}, {a, b}]', '{x, y}' is a two-elements list, so is '{a, b}'; then syntax constrain holds and it is understandable for me. In the second part of the example: 'f[x, {a, b}, {x, y, z}]', 'x' evaluates to a list but not necessarily to a two-elements list. According to the scarce explanation given in the example, it is not excluded for 'x' to evaluate to a 12-elements list '{x, y}', however the syntax constrain allows it to pass; following with the example the list '{a, b}' is again a two-elements list, so it pass the check. 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}, and any list of whatever any other length as this {f[{x, y}, {a, b}], f[x, {a, b}, Array[100, x]]}. 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 'f[]'. But it does no seem to work as expected since the following is allowed to pass (and it seems Ok since just two parameters and a list of options are submitted) f[x,y, aaa->2,bbb->3,ccc ->4]; but the following is allowed to pass too, despite, in this case, 6 parameters (plus the options) are submitted instead of just the two parameters specified in the SyntaxInformation[f] definition f[x, y, z, k, l, m, aaa->2,bbb->3,ccc->4]; I am certainly missing something important here and, clearly, I do not understand the explanation given for this very basic command. So I would appreciate any clarification from the Group. Or maybe Wolfram should provide a complete tutorial on it or a clearer explanation. Regards E. Martin-Serrano
From: Bill Rowe on 5 Jul 2010 21:13 On 7/5/10 at 6:02 AM, eMartinSerrano(a)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.
From: E. Martin-Serrano on 7 Jul 2010 07:39
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(a)sbcglobal.net] Sent: Tuesday, July 06, 2010 3:14 AM Subject: Re: SyntaxInformation Question On 7/5/10 at 6:02 AM, eMartinSerrano(a)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. |