Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!csd4.milw.wisc.edu!lll-winken!uunet!mcvax!kth!draken!liuida!mikpa From: mikpa@massormetrix.ida.liu.se (Mikael Patel) Newsgroups: comp.lang.forth Subject: Re: FIFTH? Message-ID: <1245@massormetrix.ida.liu.se> Date: 14 Apr 89 12:45:25 GMT References: <8904140055.AA18922@jade.berkeley.edu> Organization: CIS Dept, Univ of Linkoping, Sweden Lines: 41 In-reply-to: HALDANE@UFPINE.BITNET's message of 13 Apr 89 17:49:00 GMT Its quite easy to simulate operator overloading in Forth using vocabularies. In my C based Forth 83 implementation, XFORTH, I have added a facility in the Forth top-loop so that overloading and casting ala C are possible. For instance, in a vocabulary with string function one may have a function plus, "+", for string concatination (not $+ as often advocated). If the vocabulary is in the search order and found first there's no real problem. To hard bind to the plus operator from this vocabulary in other cases when, for instance, forth preceeds the string vocabulary in the search order, I allow a "casting" operation: "(string) +" The implementation is very simple (as everything in Forth). In the top loop, normally interpret, if "find" fails I examine the token it see if it could be a casting operation, i.e., some word in parenpheses. In this case I remove the parenpheses and call "find" again. If it returns with a vocabulary entry I just scan the next symbol and repeat the procedure until it either fails, or an entry is found (which is not a vocabulary). So, "(float) +", would mean plus from float. Now all of this talk is early binding. If you want to do late binding ala Smalltalk the problem is somewhat different. Maybe we can discuss late binding in Forth in this news group because there alot of way of introducing it. So let's continue this discussion on late binding!! May the Forth be with you... Mikael R.K. Patel Researcher and Lecturer Computer Aided Design Laboratory Department of Computer and Information Science Linkoping University S-581 83 LINKOPING SWEDEN Phone: +46 13281821 Telex: 8155076 LIUIDA S Telefax: +46 13142231 Internet: mip@ida.liu.se UUCP: ...!enea!liuida!mip Bitnet: MIP@SELIUIDA SUNET: LIUIDA::MIP