POV-Ray : Newsgroups : povray.off-topic : Smalltalk become: Server Time
5 Sep 2024 13:11:07 EDT (-0400)
  Smalltalk become: (Message 1 to 7 of 7)  
From: Darren New
Subject: Smalltalk become:
Date: 31 Jul 2009 13:27:10
Message: <4a73296e$1@news.povray.org>
http://gbracha.blogspot.com/2009/07/miracle-of-become.html

It never occurred to me that GC makes this very tractable even without an 
object table. Kewl.

-- 
   Darren New, San Diego CA, USA (PST)
   "We'd like you to back-port all the changes in 2.0
    back to version 1.0."
   "We've done that already. We call it 2.0."


Post a reply to this message

From: Slime
Subject: Re: Smalltalk become:
Date: 31 Jul 2009 23:19:17
Message: <4a73b435$1@news.povray.org>
Seems like you can do this in C/C++ by just swapping a and b... then all 
pointers (and references) to a effectively point to b and vice versa.

Or maybe I misunderstand the feature.

 - Slime
 [ http://www.slimeland.com/ ]


Post a reply to this message

From: Darren New
Subject: Re: Smalltalk become:
Date: 31 Jul 2009 23:32:07
Message: <4a73b737$1@news.povray.org>
Slime wrote:
> Seems like you can do this in C/C++ by just swapping a and b... then all 
> pointers (and references) to a effectively point to b and vice versa.
> 
> Or maybe I misunderstand the feature.

Works great, as long as they're the same type. Try swapping an array of 
integers with a socket.

-- 
   Darren New, San Diego CA, USA (PST)
   "We'd like you to back-port all the changes in 2.0
    back to version 1.0."
   "We've done that already. We call it 2.0."


Post a reply to this message

From: Warp
Subject: Re: Smalltalk become:
Date: 1 Aug 2009 06:45:14
Message: <4a741cba@news.povray.org>
Darren New <dne### [at] sanrrcom> wrote:
> Works great, as long as they're the same type. Try swapping an array of 
> integers with a socket.

  Wouldn't it break the code which expects the object to be an array, but
the object gets suddenly changed to something completely different?

  (What does Smalltalk do when an inexistent method is called? Runtime error?
That's at least what happens in Objective-C, which is based on the same
principles as Smalltalk, IIRC.)

-- 
                                                          - Warp


Post a reply to this message

From: Orchid XP v8
Subject: Re: Smalltalk become:
Date: 1 Aug 2009 08:38:09
Message: <4a743731$1@news.povray.org>
>> Works great, as long as they're the same type. Try swapping an array of 
>> integers with a socket.
> 
>   Wouldn't it break the code which expects the object to be an array, but
> the object gets suddenly changed to something completely different?

One would presume so, yes. Depends what you decide to replace it with.

>   (What does Smalltalk do when an inexistent method is called? Runtime error?
> That's at least what happens in Objective-C, which is based on the same
> principles as Smalltalk, IIRC.)

Does calls #doesNotUnderstand:, which is a regular method. BY DEFAULT 
this throws an exception, but you can override it to do... whatever you 
want.

Darren's original article describes using it to load objects from disk 
the first time somebody tries to access them, for example.

I saw somebody else describe overriding it to implement multiple 
dispatch. (Smalltalk itself supports only single dispatch, like most OO 
languages.)

-- 
http://blog.orphi.me.uk/
http://www.zazzle.com/MathematicalOrchid*


Post a reply to this message

From: clipka
Subject: Re: Smalltalk become:
Date: 1 Aug 2009 11:35:00
Message: <web.4a745f7cd63f83a67cb678b90@news.povray.org>
Warp <war### [at] tagpovrayorg> wrote:
>   (What does Smalltalk do when an inexistent method is called? Runtime error?
> That's at least what happens in Objective-C, which is based on the same
> principles as Smalltalk, IIRC.)

If I understood the article right, then Smalltalk calls some "doesNotUnderstand"
method of the object (which, of course, may default to raising a runtime error I
guess).


Post a reply to this message

From: Darren New
Subject: Re: Smalltalk become:
Date: 1 Aug 2009 14:18:15
Message: <4a7486e7$1@news.povray.org>
Warp wrote:
> Darren New <dne### [at] sanrrcom> wrote:
>> Works great, as long as they're the same type. Try swapping an array of 
>> integers with a socket.
> 
>   Wouldn't it break the code which expects the object to be an array, but
> the object gets suddenly changed to something completely different?

It depends on whether (say) there's some other data structure telling you 
what to do with the thing. That, of course, was a rather extreme example 
that might in practice never be useful.

Smalltalk used becomes: all the time while running to make variable-size 
arrays. Rather than having one object hold the description of the array and 
forward all messages to it, instead when the array had to grow, you created 
a new array, copied the data into it, and then "becomes:" the new array.

Also, remember that Smalltalk used a process image. There was all kinds of 
data in memory even as you're editing code. So if you changed a class to add 
an instance variable, the system would find all the existing instances, copy 
them to instances of the new class, and have each become: the new version, 
even as the system is running.

>   (What does Smalltalk do when an inexistent method is called? Runtime error?

It packages up the method invocation as an object of type "Message" (which 
gives the selector and arguments, basically) and then sends the original 
receiver a message called "doesNotUnderstand:" with the message as an 
argument.  (Knowing that, rereading the article where they're talking about 
hunks pointing to on-disk structures probably makes more sense.) 
Technically, in a safe language, there's no such thing as a "runtime error"; 
they all get translated to something well-defined.  And since Smalltalk was 
originally also the OS, you had nowhere for a "runtime error" in the SIGSEGV 
sense to go.

Now, the top of the inheritance heirarchy is class Object, and Object 
implements "doesNotUnderstand:" to (basically) start up the debugger as if 
you hit a breakpoint at the address of the original message send. So in that 
sense, yes, if you don't catch "doesNotUnderstand" then you have a runtime 
error. But the system keeps happily humming along, running other processes, 
and you can go back and fix whatever was broken (see above) and then resume 
from whichever frame on the stack makes the most sense.

> That's at least what happens in Objective-C, which is based on the same
> principles as Smalltalk, IIRC.)

The language is, but the run-time system is quite different. Smalltalk and 
APL both have "workspaces" where things live. With the original Smalltalk, 
you'd put your disk in, boot the system, and you'd be back to where you were 
when you last shut down, quite a lot like "hibernate" nowadays. The 
Smalltalk primitives were the microcode of the CPU while you were running 
Smalltalk, and there was no "OS" or "file system" outside the language 
interpreter. (Which explains, incidentally, the lack of a need for 
destructors - there were no external resources needing to be cleaned up.)

-- 
   Darren New, San Diego CA, USA (PST)
   "We'd like you to back-port all the changes in 2.0
    back to version 1.0."
   "We've done that already. We call it 2.0."


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.