Talk:Walnut/Ordinary Programming
From Erights
(Difference between revisions)
(Parameters implicitly defined by "var", not "def") |
(Random nonsense?) |
||
| Line 35: | Line 35: | ||
# value: "new name" | # value: "new name" | ||
</pre> | </pre> | ||
| + | |||
| + | == Random nonsense? == | ||
| + | |||
| + | What is this stuff in the middle of the page? Image:http://i.imgur.com/bPaUV.png | ||
Revision as of 02:03, 5 December 2010
Parameters implicitly defined by "var", not "def"
Where the article says:
Rather, they are true variables (implicitly declared with "def" )
Aren't they declared by "var"? You can modify them in the object's scope:
def makeCar(var name) {
var x := 0
var y := 0
def car {
to moveTo(newX,newY) {
name := "new name"
x := newX
y := newY
}
to getName() {return name}
}
return car
}
? def car := makeCar("a car")
# value: <car>
? car.getName()
# value: "a car"
? car.moveTo(1,2)
? car.getName()
# value: "new name"
Random nonsense?
What is this stuff in the middle of the page? Image:http://i.imgur.com/bPaUV.png

