Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Everything Is References

Name: Anonymous 2010-08-20 16:29

Is there a language in which variables, function arguments, etc, are always references by default?

For example:

int x = 5;
int y = x;
y++;  // x and y are both 6


If you really did want a copy of something, you'd have to use a keyword:

int x = 5;
int y = copy(x);


And pass-by-value would also have to be done explicitly:

void func(int z)
{
   int w = copy(z); // now w is effectively "local"
}


It would force programmers to at least be aware of the fact that they're making a copy.

Name: Anonymous 2010-08-20 19:44

In Lisps though (well except Clojure), there are no immutable objects.
and Scheme
If someone passes you an int, you can set! or setf on it, and they get the change as well (since it's the same object)
Wait, what?
* (defvar x 1)
X
* (defun foo (x)
    (setf x 2)
    x)
FOO
* x
1
* (foo x)
2
* x
1

Am I missing something?
I think you have made a slight misjudgement on your part, what you are saying is that any identifier can conceivably be modified, which is true, but that isn't to say that the identifier cannot be referencing an immutable object. It's funny that you made this mistake in regard to Lisp, as you didn't with python.

As for examples of immutable objects in Scheme, one can argue that all the non-aggregate types e.g. symbols, numbers and characters are immutable, certainly there are no defined mutators for them. As for aggregates, Record types in both srfi 9 and r6rs can have immutable slots, srfi 69 hashtables can be immutable, as can the return value of hashtable-copy. Anything returned from a quoted expression is allowed to be immutable, but I don't think this is a requirement. And the draft srfi 101 (random access lists) is purely functional.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List