Live data from Hacker News

Copper: A statically-typed, loose syntax programming language

github.com

31–32 of 32 posts

Re: Copper: A statically-typed, loose syntax programming language

#31
post #30

Earlier quoted context omitted.

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 */ }

};

Re: Copper: A statically-typed, loose syntax programming language

#32

Earlier quoted context omitted.

Not the parent, but I personally don't like prefix syntax for such common operators. As for the colons combined with the absence of commas, this suggests keyword syntax to me. I.e., as if the gte function took one argument named a. Like this Python call: gte(a=100)

Actually, it can take multiple. gte(a: b: c: d:) is equivalent to (in C) a >= b && a >= c && a >= d. By making operators like functions, you can group like-operations and simplify code. Admittedly, it's not as readable for someone accustomed to seeing C style. Last note: gte(a=100) would produce an error in Copper because a=100 is an assignment statement that returns "a" (a function), and gte( function ) means nothin…

That's... surprising, I could easily expect

    gte(a: b: c: d:)
to possibly mean

    a >= b && b >= c && c >= d
I think it's just not as readable precisely because of the ambiguity.
Post reply on HN