by uryga · 6y ago · 0 comments
not 100% sure but it kind of looks like copper's Whole Deal™ are "object-functions" (closures?) and you use colons to get an object function's return value. something like this
adder = [a b]{ ret(this.a + this.b) }
x = adder(3 5)
print(x.a x.b x:) # 3 5 8
(i looked at the docs for like 10 minutes, could be wrong)In Copper, variables only store functions. This separates routine from data so you never end up with null pointer errors like in languages that have Any Types or pointers. Functions can return data, so you end up having function calls everywhere. a=5 is basically a={ret(5)}
In your above example the correct first line would be: adder = [a b] { ret(+(a: b:)) }
Parameters to a function are those that are not assigned data, whereas members are: add = [Param, Member=10) { ret(+(Param: this.Member:)) }
Now you can probably see what's wrong with your third line.
x = foo()
bar(x.a, x.b)bar(x.a: x.b:)
Functions can return data. So say, a=5, then to get the value of 5 out, all you have to do is call the function a.
Edit: I'm assuming foo() here returns an object with members "a" and "b". An example of such a function-object would be:
foo = [] { ret( [a=5, b=10] ) }
> "in Copper, variables only store functions"
because here, `x` clearly stores an object... is this about the whole "object-function" thing where Copper doesn't really distinguish the two?
(btw i'm sure this is explained in the docs... but maybe this'll help folks like me who often just read the comments)