17.06.2009 - 14:36
Language design issue: reference types, or pass-by-reference?
excepting comp.compilers?]
I've got a fairly simple domain-specific language for engineers (*not*
programmers), which has functions, and which exclusively uses
pass-by-value.
Problem: I've just had to add a complex new stream type. I can't pass
objects of this type to functions by value, because of an
implementation issue; it also wouldn't make much sense, because I
would then be creating multiple objects that shared file state.
However, pass-by-reference is trivial.
The obvious fix is to prohibit pass-by-value in some way. Any thoughts
on the best way to do this? There are two obvious ways to do this, but
I can't make up my mind which is best. Comments welcome.
#1: a Java-style solution: define the new type to be a reference type.
This is nice and simple, and is transparent to the user. However, this
does restrict me if I decide in future that I want to add
pass-by-reference as well as pass-by-value; having a reference type,
*and* pass-by-reference semantics, may just cause confusion to the
user.
#2: a C++-style solution: add pass-by-reference semantics; the user is
forced to add an '&' character, or whatever, to a formal to specify
that it's passed by reference. This is complex, for a couple of
reasons: there's some busywork in semantic checking, but the real
issue is how I handle structures and arrays containing these new
objects. Having said that, I think it's sufficient to force the user
to add the '&' anywhere an object of the new type can appear:
structure definitions, array declarations, function parameters,
function return values.
The Java solution is simpler, but I can't help feeling that it's not
the right way to do references. It feels like a bodge.
Thanks
-Charlie
17.06.2009 - 15:41
Charlie Dawson <cd4573@yahoo.com> writes:
