On Thu, 2003-10-23 at 11:08, Louis Kruger wrote:
> > Perhaps the semantics should be discussed.
> > What should the behavior of the following be (also ignoring syntax
> > issues):
> >
> > global xref
> >
> > procedure f(a)
> > xref := &a
> > a := 3
> > end
> >
> > ...
> > write(*xref)
>
> Logically, it makes the most sense that when a variable goes out of
> scope, all its references should become invalid and therefore the above
> dereference fails.
If you mean 'runtime error' instead of 'fails', then
I agree, but the problem is detecting when the variable is out of
scope - I don't know of a way to do that without incurring a cost
on most references (and probably all references unless the
compiler is pretty smart about it).
Also, doesn't this limit the usefulness of references to
pretty much nothing more than another way to circumvent Icon's
call by value semantics? Is there any other role they can
play?
> > and
> >
> > procedure g()
> > yref := &xref
> > *yref := &yref
> > write(*xref)
> > end
>
> I don't see any source of ambiguity here. This is equivalent to:
>
> yref := &xref
> xref := &yref
> write (yref)
>
> ... and then yref goes out of scope, and *xref becomes invalid.
Agreed, bad example (I was thinking about how *xref would
behave - should it dereference just one level (ala C) or
all the way down to a non-reference type? I suppose the
former would be the only sane way to go, as it avoids the
problem I was seeing in the above code...)
> > There are reasons why functional languages don't like reference
> > types - they can be addressed, but it needs careful thought.
>
> I don't really see Icon as being a functional language. Certainly, many
> of its interesting features are imperitive in nature.
Sorry, I didn't mean to imply that Icon was a functional language,
but rather that there is an entire class of languages that get
by quite nicely without a reference type. Use Java as a more
'Icon'-like example.
> > Languages like C and FORTRAN operate under a 'caveat emptor'
> > philosophy that isn't appropriate for languages like Unicon.
>
> Which is why invalid references would have to be checked. This might
> impose a performance penalty on the use of references, but that's
> consistent with the design of other language features.
Also agreed. People shouldn't assume that reference types are
as cheap as they are in C.
--
Steve Wampler -- [EMAIL PROTECTED]
Quantum materiae materietur marmota monax si marmota
monax materiam possit materiari?
-------------------------------------------------------
This SF.net email is sponsored by: The SF.net Donation Program.
Do you like what SourceForge.net is doing for the Open
Source Community? Make a contribution, and help us add new
features and functionality. Click here: http://sourceforge.net/donate/
_______________________________________________
Unicon-group mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/unicon-group