Lambda the Ultimate

inactiveTopic late binding and self reference
started 5/13/2004; 5:43:56 AM - last post 5/13/2004; 10:06:26 AM
andrew cooke - late binding and self reference  blueArrow
5/13/2004; 5:43:56 AM (reads: 163, responses: 4)
does anyone know how late binding works in practice when you want to refer to a previous definition?

say i want to redefine "print" to print as before, but add a newline. presumably i type something like (invented syntax):

def print x = print (x + "\n")

if i understand what late binding means, that should affect all printing (including code written earlier). so how do i indicate in the definition above that the second occurence of the word "print" refers to the previous definition? what if my function is recursive?


Andris Birkmanis - Re: late binding and self reference  blueArrow
5/13/2004; 6:47:10 AM (reads: 155, responses: 1)
I would say it depends entirely on the model chosen for "def". I see a problem if the names of functions are global and immutable. If they are either scoped or mutable (think let or define), I refuse to see a problem.

andrew cooke - Re: late binding and self reference  blueArrow
5/13/2004; 7:03:26 AM (reads: 151, responses: 0)
ah, ok. i thought late binding meant resolving *global* names at "run time". i guess it could mean just resolving names in some scope (which seems rather less interesting, but presumably still gives you something).

Chris Rathman - Re: late binding and self reference  blueArrow
5/13/2004; 8:41:03 AM (reads: 140, responses: 1)
Offhand, I'd say that you usually want the new version to be called instead of the previous version. That is, perhaps the previous version of print was incomplete or had a bug, so you fix print. You don't wont the old buggy one to continue to be called.

Internally, the functions are just items allocated in the heap. The old version of print will still exist in memory but most likely will be marked as garbage. The name resolution most likely occurs through a dictionary lookup at runtime (or some sort of vtable). It's quite possible that the dictionary could hold both functions at various levels of scope.

On a side note, one of the interesting (though quite dangerous) operators for object mutation in Smalltalk is anObject become: anotherObject. All reference3s to anObject are rerouted to anotherObject. This comes in handy for AOP type operations where you might want to intercept the messages between objects. I'm not sure, though, whether the compiler also uses the become: to change all references to the previous function to the new function - though that's basically the effect that Smalltalk achieves.

andrew cooke - Re: late binding and self reference  blueArrow
5/13/2004; 10:06:26 AM (reads: 132, responses: 0)
thanks. getting rid of lexical scoping makes more things harder than i first suspected... :o/