DMUG-Archiv 2008

Frühere

 

Chronologischer Index

 

Spätere

Vorherige

 

Thematischer Index

 

Nächste

scoping Rule[]

liebe mma user folgendes simples problem welches die elemente eines 2er vektors vertauschen soll. es geht hier nicht darum das man das ja mit Reverse[] oder sonstwie bewerkstelligen kann !!
vielmehr geht es darum zu verstehen warum mma was wie macht ??

in der mma hilfe steht das patterns als lokale symbole behandelt werden:

tutorial/VariablesInPureFunctionsAndRules
"
Mathematica has several \[OpenCurlyDoubleQuote]scoping constructs\[CloseCurlyDoubleQuote] in which certain names are treated as local. When you mix these constructs in any way, Mathematica does appropriate renamings to avoid conflicts.
"

warum funktioniert das nicht wie man sich das trivialerweise vorstellt ?
insbesondere der fall 5 ist da sehr beunruhigend !
lediglich die fälle 2 und 4 scheinen das "intuitiv gewollte" zu vollbringen.

wer erleuchtet mich ?
soll man defaultmaessig RuleDelayed[] anstelle von Rule[] verwenden obwohl alle nullachtfünfzehn beispiele Rule[] verwenden ?

In[1]:= x = z;
(* 2 *) {a, b} /. {x_, y_} :> {y, x}
(* 3 *) {a, b} /. {x_, y_} -> {y, x}
(* 4 *) Block[{x, y}, {a, b} /. {x_, y_} -> {y, x}]
(* 5 *) Module[{x, y}, {a, b} /. {x_, y_} -> {y, x}]
(* 6 *) {a, b} /. Block[{x, y}, {x_, y_} -> {y, x}]
(* 7 *) {a, b} /. Module[{x, y}, {x_, y_} -> {y, x}]

Out[2]= {b, a}

Out[3]= {b, z}

Out[4]= {b, a}

Out[5]= {b, z}

Out[6]= {b, z}

Out[7]= {b, z}


glücklicherweise relativiert sich das problem bei verwendung von packages:
wobei Begin[] End[] alleine als klammerung nicht ausreichen ????

In[1]:= x = z;

BeginPackage["c`"];
Begin["Private`"];

(* 2 *) {a, b} /. {x_, y_} :> {y, x}
(* 3 *) {a, b} /. {x_, y_} -> {y, x}
(* 4 *) Block[{x, y}, {a, b} /. {x_, y_} -> {y, x}]
(* 5 *) Module[{x, y}, {a, b} /. {x_, y_} -> {y, x}]
(* 6 *) {a, b} /. Block[{x, y}, {x_, y_} -> {y, x}]
(* 7 *) {a, b} /. Module[{x, y}, {x_, y_} -> {y, x}]

End[];
EndPackage[];

Out[4]= {b, a}

Out[5]= {b, a}

Out[6]= {b, a}

Out[7]= {b, a}

Out[8]= {b, a}

Out[9]= {b, a}

beste grüße
Robert Nowak

--
Robert Nowak
IMS Nanofabrication AG
Phone: +43/12144894/32
Fax: +43/12144894/99

Antworten:
Re: scoping Rule[]
Jens-Peer Kuska, 12.11.2008
Re: scoping Rule[]
Udo und Susanne Krause, 13.11.2008

Frühere

 

Chronologischer Index

 

Spätere

Vorherige

 

Thematischer Index

 

Nächste

DMUG-Archiv, http://www.mathematica.ch/dmug-liste.html; Letzte Änderung: 29.11.2008 16:35