Hacker News new | comments | show | ask | jobs | submit login

No, it isn't. I mean, it's possible to call what the majority of dynamic languages do "passing by reference", but it isn't the same thing as Clay does.

In C#, if I do

  int foo(int x) { x += 1; return x; }
  int x = 3;
then afterwards the value of x is still 3. In Clay, if I do

  foo(x : Int) { x += 1; return x; }
  var x = 3;
then the value of x is now 4. I agree with the grandparent: this seems like a really terrible idea. (In fact, I was going to post a comment saying so until I saw that someone else had got there before me.)

[EDITED to add: By the way, usually "dynamic languages" means "languages with dynamic typing", and Java and C# would be excellent examples of widely used languages that are not dynamic in that sense. The question of whether values are passed "by object reference" (my preferred way of describing what they do) is pretty much entirely separate from whether the language is dynamic. For instance: C++ (not dynamic, not p.b.o.r.), Java (not dynamic, p.b.o.r.), MATLAB (dynamic, not p.b.o.r), Python (dynamic, p.b.o.r). C# has the unusual feature that some kinds of mutable objects are passed that way while others -- structs -- are passed by value, with the object (in principle) being copied when the call happens.]

Yet, in c# if you do

  int foo(obBob o) { o.x += 1; return o; }
  Car.x = 3;
Then Car.x = 4 which has confused a lot of new programmers. More importantly it's a more consice standard for cube(x) to cube(x) than to say x=cube(x).

Object fields are always passed implicitly by reference (if that makes sense). The value that holds the reference to the object itself is passed by value, unless you specify the "ref" argument modifier (in C#).

Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | DMCA | Apply to YC | Contact