byerly@cars.rutgers.edu (Boyce Byerly ) (12/14/88)
I have two short questions on Smalltalk: 1. Is it possible to create a message at run time and then send it? For those of you who know LISP, I am asking if Smalltalk has a facility analogous to the EVAL statement. 2. Can you redefine the system-defined classes (such as integer, graphic objects, and so forth) to contain a modified set of messages? Thanks in advance for any answers or pointers, Boyce
hansell@oboe.cis.ohio-state.edu (Timothy Hansell) (12/15/88)
Here are some answers to your questions -- note: I am using ParcPlace Smalltalk-80... 1. There is a selector called 'perform:' that allows you to execute a selector that is specified by a string. ex: a perform: 'new'. would eventually send to new message to object a. More concrete examples of this selector and how it is used are contained in the class MouseMenuController and any of it's subclasses. If the selector takes arguments you just add with: for each argument. a perform: 'add:' with: anotherObject. a perform: 'add:after:' with: anotherObject with: yetAnotherObject. 2. Can you change system classes ?? yes.. In ParcPlace Smalltalk-80 you can change things so much the system will actually crash, without telling you that you are changing something important. Try the following in your image: open a browser... define the following class Object subclass: #Link... etc. with blank strings for the arguments for all of the instance variable stuff.. Your system will probably crash before you finish accepting the code. --NOTE: ParcPlace does not suggest that you modify system class, but if you do they suggest that you better know what you are doing. --tim
atoenne@laura.UUCP (Andreas Toenne) (12/16/88)
In article <Dec.14.10.29.16.1988.11156@cars.rutgers.edu> byerly@cars.rutgers.edu (Boyce Byerly ) writes: >1. Is it possible to create a message at run time and then send it? >For those of you who know LISP, I am asking if Smalltalk has a >facility analogous to the EVAL statement. Yes! The message perform: is understood by every object in the system. It takes a symbol (called selector here) as an argument and evaluates the method associated to the selector. Together with perform: come perform:with: and perform:with:with which evaluate the methods with arguments. As one may construct symbols at runtime this feature matches your requirements. >2. Can you redefine the system-defined classes (such as integer, >graphic objects, and so forth) to contain a modified set of messages? Yes! In Smalltalk-80 you are allowed to change everything in the system. The whole system comes with it's source and a powerfull decompiler. However, this is both convenient for the experienced programmer and dangerous to the novice. I remember a real freshmen who decided to add a new instance variable to class Object. After some time (> 1hr) he decided to reboot. :-) Andreas Toenne
johnson@p.cs.uiuc.edu (12/18/88)
>1. Is it possible to create a message at run time and then send it? >For those of you who know LISP, I am asking if Smalltalk has a >facility analogous to the EVAL statement. If you really want to define a new method at run time, then perform: will not do the trick. You can build up a string and send a message to a class asking it to install it as a new method, or you can just ask the compiler to evaluate it for you. It is instructive to see how doIt is implemented in TextController. (Unless it is done in ParagraphEditor. I think it is in TextCOntroller, though.) In general, however, perform: is safer and will probably do what you want. Blocks can also often be used as the solution to problems of this type, as Scheme programmers well know.
mfox@hpbsla.HP.COM (Martin_Fox) (12/20/88)
As long as we're discussing modification of system classes.... Before compiling a new class it may be wise to check if any existing system classes have the same class name. Otherwise the system will attempt to compile the new class definition and then hunt down each and every existing instance of that class and make them conform to the new definition. If you have accidently over-written a system class, you get to watch with horror as a Smalltalk system thrashes around and eventually dies. It is not pretty. At the very least, save your code or an image before compiling new classes. (This from the mouth of a man who didn't know Switch was a system class until an ugly scene ensued). Martin Fox
new@udel.EDU (Darren New) (12/20/88)
In article <80500047@p.cs.uiuc.edu> johnson@p.cs.uiuc.edu writes: > >>1. Is it possible to create a message at run time and then send it? >>For those of you who know LISP, I am asking if Smalltalk has a >>facility analogous to the EVAL statement. > . . . >In general, however, perform: is safer and will probably do what >you want. Blocks can also often be used as the solution to problems >of this type, as Scheme programmers well know. Except that blocks are not reentrant. Also, if a block executes a return (^), then it may not be called again. Beware of this - it is very hard to debug.
pcg@aber-cs.UUCP (Piercarlo Grandi) (12/23/88)
In article <6037@louie.udel.EDU> new@udel.EDU (Darren New) writes: In article <80500047@p.cs.uiuc.edu> johnson@p.cs.uiuc.edu writes: >In general, however, perform: is safer and will probably do what >you want. Blocks can also often be used as the solution to problems >of this type, as Scheme programmers well know. Except that blocks are not reentrant. Also, if a block executes a return (^), then it may not be called again. Beware of this - it is very hard to debug. I suggest that if you are interested in this you get a set of pretty good papers from the Mushroom project at the U. of Manchester. They are building a timesharing system based on a cleaned up Smalltalk-80, called MUST (an imperative language! :->). This MUST is a nice evolution of the original. As to blocks, let me quote from their paper: BLOCKS: In MUST, the semantics of block activations has been "cleaned up". Blocks can have temporaries, are re-entrant, and are full continuations. I think that any of {ifor,miw,trevor}@ux.cs.man.cs.ac.uk will be happy to provide you with a copy of their relevant documents. -- Piercarlo "Peter" Grandi INET: pcg@cs.aber.ac.uk Sw.Eng. Group, Dept. of Computer Science UUCP: ...!mcvax!ukc!aber-cs!pcg UCW, Penglais, Aberystwyth, WALES SY23 3BZ (UK)