Gnu Smalltalk User's Guide
Total Page:16
File Type:pdf, Size:1020Kb
gnu Smalltalk User’s Guide Version 1.95.10 13 November 2001 by Steven B. Byrne, Paolo Bonzini, Andy Valencia. Copyright c 1988-92, 1994-95, 1999, 2000 Free Software Foundation, Inc. This document is released under the terms of the gnu Free Documentation License as published by the Free Software Foundation; either version 1.1, or (at your option) any later version. You should have received a copy of the gnu Free Documentation License along with gnu Smalltalk; see the file ‘COPYING.DOC’. If not, write to the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. There are no Cover Texts and no Invariant Sections; this text, along with its equivalent in the Info documentation, constitutes the Title Page. 1 2 GNU Smalltalk User’s Guide Introduction 3 Introduction gnu Smalltalk is an implementation that closely follows the Smalltalk-80 language as de- scribed in the book Smalltalk-80: the Language and its Implementation by Adele Goldberg and David Robson, which will hereinafter be referred to as the Blue Book. The Smalltalk programming language is an object oriented programming language. This means, for one thing, that when programming you are thinking of not only the data that an object contains, but also of the operations available on that object. The object’s data representation capabilities and the operations available on the object are “inseparable”; the set of things that you can do with an object is defined precisely by the set of operations, which Smalltalk calls methods, that are available for that object: each object belongs to a class (a datatype and the set of functions that operate on it) or, better, it is an instance of that class. You cannot even examine the contents of an object from the outside—to an outsider, the object is a black box that has some state and some operations available, but that’s all you know: when you want to perform an operation on an object, you can only send it a message, and the object picks up the method that corresponds to that message. In the Smalltalk language, everything is an object. This includes not only numbers and all data structures, but even classes, methods, pieces of code within a method (blocks or closures), stack frames (contexts), etc. Even if and while structures are implemented as methods sent to particular objects. Unlike other Smalltalks (including Smalltalk-80), gnu Smalltalk emphasizes Smalltalk’s rapid prototyping features rather than the graphical and easy-to-use nature of the pro- gramming environment (did you know that the first GUIs ever ran under Smalltalk?). The availability of a large body of system classes, once you master them, makes it pretty easy to write complex programs which are usually a task for the so called scripting languages. Therefore, even though we have a nice GUI environment including a class browser (see hundefinedi [Blox], page hundefinedi), the goal of the gnu Smalltalk project is currently to produce a complete system to be used to write your scripts in a clear, aesthetically pleasing, and philosophically appealing programming language. An example of what can be obtained with Smalltalk in this novel way can be found in hundefinedi [Class reference], page hundefinedi. That part of the manual is entirely generated by a Smalltalk program, starting from the source code for the system classes as distributed together with the system. I’d like to end this introduction reporting an article I posted to Usenet in September 1999. It’s about gnu Smalltalk’s ‘place in the world’ and its comparison with another open source Smalltalk, Squeak (a new version of Smalltalk-80 written by lots of people including the great wise behind the original Smalltalk implementation). 4 GNU Smalltalk User’s Guide Re: gnu Smalltalk and Squeak (was Re: gnu Smalltalk 1.7 development) ¨ I enjoy discussions about the relationship between gnu Smalltalk and Squeak, because I also think about it sometimes. And, believe it or not, I cannot tell which system is more “winning”. Actually, they’re fundamentally different—the only thing they share is that both are free. Squeak is Smalltalk for the pure. Smalltalk for die-hard object-oriented folks. Don’t flame me please, and interpret this article with the necessary irony and benevolence. Why do I say this? Because only a die-hard object-oriented folk, IMO, would write BitBlt and real-time FM synthesis stuff in Smalltalk—even Adele Goldberg wrote her Smalltalk implementation in Smalltalk mostly for clarity (at least she says so). gnu Smalltalk is Smalltalk for hacking object-oriented folks. You know them: they like the object-oriented paradigm because it’s clearer and powerful, and maybe they learnt something of design too. but they nevertheless like to toy with C and think that only pointers make them feel like they are “really” programming. Why do I say this? Because I am one of them, and proud of it. Having said so, I must admit that I have Squeak on my hard disk. And I’d be happy if one of the ‘great wise’ behind Squeak told me he dignated himself to have a look at my humble creation. Because both do have good points. Let’s take a bird’s fly on them. Squeak had LargeIntegers ever since it was born, I added them three months ago to a ten-year old GST. Squeak has Namespaces and I already confessed that I’m taking inspiration from them. But GST has closures, it has a better compiler, better C interoperability, and (I beg your pardon Squeakers) an easy to use window framework. I added closures to GST in three days of work without taking extra caffeine; the Squeak Mailing List has been wondering for two years about when they will be finally there. Having to choose between 1000 downloads a day and Dan Ingalls adding closures to Squeak after peeping at my source code, I’d surely pick the second!!! Being too loquacious? Probably, so I stop here. The moral is, no civil wars between Smalltalk dialects please; let’s all write good programs and let others write good programs. It’ll surely be a better world for both. Paolo Bonzini © Chapter 1: Installation 5 1 Installation 1.1 Compiling gnu Smalltalk The first thing to do to compile gnu Smalltalk is to configure the program, creating the makefiles and a ‘gstconf.h’, which contains guesses at the system’s peculiarities. This configuration is performed automatically by the ‘configure’ shell script; to run it, merely type: ./configure Options that you can pass to configure include --disable-dld, which precludes Smalltalk programs from dynamically linking libraries at run-time. After you’ve configured gnu Smalltalk, you can compile the system by typing: make Smalltalk should compile and link with no errors. If compiling goes wrong you might want to check the commands used to launch the compiler. For example, be sure to check if your compiler has extensions which, if not enabled, don’t make it ANSI compatible. If this is the case, type make distclean CFLAGS=needed command-line flags and retry the configure/make process. In very particular cases, the configure script might miss the presence of a header file or a function on your system. You can patch the ‘config.cache’ file created by the configure process. For example, if configure did not find your ‘unistd.h’ header file, change the line reading ac_cv_header_unistd_h=${ac_cv_header_unistd_h=’no’} to ac_cv_header_unistd_h=${ac_cv_header_unistd_h=’yes’} and, again, retry the configure/make process. The last lines of the make output should be like this: export SMALLTALK KERNEL=‘cd ./kernel; pwd‘; \ ./gst -iQ dummy file make[2]: Leaving directory ‘/home/utente/devel-gst’ make[1]: Leaving directory ‘/home/utente/devel-gst’ At this point, you have a working gnu Smalltalk. Congratulations!!! You will also want to store the Smalltalk sources and create the image file in the proper place (the image file contains a full snapshot of the status of the system). This is done automatically when you do a make install. Specifying --enable-modules as an option to configure will load Smalltalk packages in the automatically installed image. For example ./configure --enable-modules=Blox,TCP will create an image with the Blox user interface toolkit and the tcp abstraction library built-in. 6 GNU Smalltalk User’s Guide 1.2 Including gnu Smalltalk in your programs (legal information) Believe it or not, Smalltalk is (also) a very good scripting and macro language. For this reason, gnu Smalltalk is distributed as a library that you can link your programs to. It’s very simple: just include ‘gstpub.h’, link to ‘libgst.a’, and you’re done. For more information on what to do in your program so that it communicates well with Smalltalk, relate to hundefinedi [C and Smalltalk], page hundefinedi. In this case, your program must be free, licensed under a license that is compatible with the gnu General Public License, under which the gnu Smalltalk virtual machine is licensed. The Smalltalk programs that we bundle with gnu Smalltalk (currently the browser and the compiler) are also subject to the General Public License, and must be made free. On the other hand, the core gnu Smalltalk class libraries (standard classes, Blox, tcp abstraction, xml parsing) are released under the gnu Lesser General Public License. It is not necessary (although we would appreciate it) that programs that only use these libraries are made free. Chapter 2: Using gnu Smalltalk 7 2 Using gnu Smalltalk 2.1 Command line arguments gnu Smalltalk may be invoked via the following command: gst [ flags ... ] [ file ..