[comp.lang.misc] dynamic symbol binding

jml@bdblues.altair.fr (Jean Marie Larcheveque) (10/01/90)

To my knowledge, there is no language which allows you to
bind a symbol to an object created dynamically.
This would happen for example if C++ had a primitive alloc
with interface Type& alloc(Type). 
Then we could write

int& x = //... some initialization
//...
x = alloc int;  //... previous lvalue of x is lost,
				// perhaps deallocated

I am not suggesting that this is useful, and in fact I
don't think it is, but I am curious to know if this kind of
thing is possible in any language.

--
Jean-Marie Larcheveque  <jml@bdblues.altair.fr> or 
                        <jml@nuri.inria.fr>

pardo@cs.washington.edu (David Keppel) (10/02/90)

jml@bdblues.altair.fr (Jean Marie Larcheveque) writes:
>To my knowledge, there is no language which allows you to
>bind a symbol to an object created dynamically.
>This would happen for example if C++ had a primitive alloc
>with interface Type& alloc(Type). 
>Then we could write
>
>int& x = //... some initialization
>//...
>x = alloc int;  //... previous lvalue of x is lost,
>				// perhaps deallocated

As I undertand it, you want to be able to do something like (C hack):

	foo()
	{
	    int x;
	    int *ip;

	    x = 5;
	    ip = &x;
	    &x = <<reallocate>>
	    x = 6;
	    assert (*ip == 5);
	}

I think that most `dynamic' languages -- LISPs, Smalltalk, etc., let
you do something like this.

	;-D on  ( My symbols in bondage )  Pardo
-- 
		    pardo@cs.washington.edu
    {rutgers,cornell,ucsd,ubc-cs,tektronix}!uw-beaver!june!pardo

lgm@cbnewsc.att.com (lawrence.g.mayka) (10/02/90)

In article <1653@seti.inria.fr>, jml@bdblues.altair.fr (Jean Marie Larcheveque) writes:
> To my knowledge, there is no language which allows you to
> bind a symbol to an object created dynamically.
...
> I am not suggesting that this is useful, and in fact I
> don't think it is, but I am curious to know if this kind of
> thing is possible in any language.

What you are suggesting is a style of programming in which variable
names *refer* to objects instead of *containing* them.  The
abstraction is extremely useful and is synergistic with dynamic typing
(the idea that every object knows its own type during program
execution and behaves only according to the specification of that
type).  Both are found in languages such as Common Lisp and Smalltalk.


	Lawrence G. Mayka
	AT&T Bell Laboratories
	lgm@iexist.att.com

Standard disclaimer.

Chewy@cup.portal.com (Paul Frederick Snively) (10/02/90)

jml@bdblues.altair.fr (Jean Marie Larcheveque) offers the opinion that there's
no language that allows the dynamic binding of a newly-created object to a
symbol.

This is, of course, untrue.  Common Lisp and Scheme both do allow this, as
does Smalltalk.

ok@goanna.cs.rmit.oz.au (Richard A. O'Keefe) (10/02/90)

In article <1653@seti.inria.fr>, jml@bdblues.altair.fr (Jean Marie Larcheveque) writes:
> To my knowledge, there is no language which allows you to
> bind a symbol to an object created dynamically.

How does
	REF REAL x = HEAP REAL := 0.0;
(faint memories of Algol 68) differ from what you want?
What's wrong with
	(let ((now (make-date)))
	    ;; use new object bound to "now"
	    ...
	    (set! now (make-date))
	    ;; use *different* object bound to "now"
	    ...)
(Scheme)

-- 
Fixed in the next release.

poser@csli.Stanford.EDU (Bill Poser) (10/03/90)

A language not in the LISP family or the object-oriented family
that has dynamic typing is ICON, in which values are typed but not
identifiers.

pcg@cs.aber.ac.uk (Piercarlo Grandi) (10/03/90)

On 1 Oct 90 10:46:35 GMT, jml@bdblues.altair.fr (Jean Marie Larcheveque) said:

jml> To my knowledge, there is no language which allows you to
jml> bind a symbol to an object created dynamically.

Well, "bind" is not that difficult -- Algol 68 surely allows you to.
"rebind" is different, and the exmaple you have seems to imply
rebinding, not binding. Even in this case you need not go far -- Lisp
systems are what you want to look at.

Or maybe you should explain what you mean by "bind", because I have the
suspicion that you may actually want to "redeclare", i.e. just reuse an
identifier symbol. Well, macro languages provide the needed example
(#undef, #define).
--
Piercarlo "Peter" Grandi           | ARPA: pcg%uk.ac.aber.cs@nsfnet-relay.ac.uk
Dept of CS, UCW Aberystwyth        | UUCP: ...!mcsun!ukc!aber-cs!pcg
Penglais, Aberystwyth SY23 3BZ, UK | INET: pcg@cs.aber.ac.uk

djones@megatest.UUCP (Dave Jones) (10/10/90)

From article <1653@seti.inria.fr>, by jml@bdblues.altair.fr (Jean Marie Larcheveque):
) To my knowledge, there is no language which allows you to
) bind a symbol to an object created dynamically.
) This would happen for example if C++ had a primitive alloc
) with interface Type& alloc(Type). 

In C++, you say,

  int& x = *new(int);  /* Symbol "x" is bound to new int-object. */

new() is the "primitive alloc" that you desire. It returns a pointer
to a new object. The above statement makes "x" a name for the object
pointed to.

2113av@gmuvax2.gmu.edu (John Porter) (10/12/90)

Maybe I'm just stupid, but it seems rather obvious to me that C (and other
languages) permit just such binding, in that all variables of storage class
'auto' are dynamic, and therefore the symbols bound to them are the symbols
under discussion.

--jp