From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 107f24,626a0a064b320310 X-Google-Attributes: gid107f24,public X-Google-Thread: f4fd2,626a0a064b320310 X-Google-Attributes: gidf4fd2,public X-Google-Thread: 103d24,626a0a064b320310 X-Google-Attributes: gid103d24,public X-Google-Thread: 106e63,4d69155937632764 X-Google-Attributes: gid106e63,public X-Google-Thread: 103376,ea8ea502d35ca2ce X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-05-06 13:16:38 PST Path: newsfeed.google.com!newsfeed.stanford.edu!sn-xit-01!sn-post-01!supernews.com!corp.supernews.com!not-for-mail From: brangdon@cix.co.uk (Dave Harris) Newsgroups: comp.lang.ada,comp.lang.lisp,comp.lang.smalltalk.advocacy,comp.lang.functional,comp.lang.scheme Subject: Re: Beginner's Language? Date: Sun, 6 May 2001 21:17 +0100 (BST) Organization: Posted via Supernews, http://www.supernews.com Message-ID: Reply-To: brangdon@cix.co.uk References: X-Complaints-To: newsabuse@supernews.com Xref: newsfeed.google.com comp.lang.ada:7238 comp.lang.lisp:9747 comp.lang.functional:5542 comp.lang.scheme:3656 Date: 2001-05-06T21:17:00+01:00 List-Id: dale@cs.rmit.edu.au (Dale Stanbrough) wrote (abridged): > You can have values such as '#doSoemthing' (it's been a -long- time > since i've done Smalltalk, so please forgive if i get the syntax > wrong). You can convert this symbol into a method call to a routine > called 'doSomething' Actually that is a library call, called #perform:. Arguably it is no more part of the language than #ifTrue:. Eg: |aSymbol| aSymbol:= #message. anObject perform: aSymbol. has the same effect as: anObject message. The equivalent in C++ would be like: void (Object::*aPmf)(); aPmf = &Object::message; (anObject->*aPmf)(); which has the same effect as: anObject->message(); I agree this stuff need not be taught on the first day. Still, it is a useful and powerful technique. I suspect a Smalltalk course could include it earlier than a C++ course. (The syntax alone could make C++ students run screaming, never mind the type-checking issues.) The #message notation itself is part of the language; it produces a Symbol. A Symbol is what Java calls an "interned" String, meaning that two Symbols with the same value will have the same identity. This means that comparing Symbols for equality is fast, because we don't have to look at each of the characters in them like we do with Strings. This means they are quite commonly used in Smalltalk; often in situations where C++ would use an enum. They are not just used with #perform:. Although this is fairly subtle stuff, I would hope a Smalltalk course would cover the difference between: string1 == string2. string1 = string2. just as a C++ course would cover the difference between: string1 == string2; strcmp( string1, string2 ); because a programmer who doesn't grasp this does not yet grasp the object model. Finally, in Smalltalk we can construct Symbols on the fly. Eg: |aPrefix aSuffix aSymbol| aPrefix := 'mess'. aSuffix := 'age'. aSymbol := (aPrefix, aSuffix) asSymbol. anObject perform: aSymbol. I hope it is clear what that is doing. There is no C++ equivalent. Dave Harris, Nottingham, UK | "Weave a circle round him thrice, brangdon@cix.co.uk | And close your eyes with holy dread, | For he on honey dew hath fed http://www.bhresearch.co.uk/ | And drunk the milk of Paradise."