Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

yeah, i think i get it now. but if variables can only store functions, how would you write something like this in Copper?

  x = foo()
  bar(x.a, x.b)


x = foo()

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] ) }


right, but doesn't that contradict this:

> "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)


Copper does not distinguish between function and object. An object-function has two parts: the member part and the executable body. In C++, it's analogous to:

class FunctionObject {

FunctionObject* members[];

void* operator() { /* executable body */ }

};




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: