Article View: net.lang.forth
Article #163Re: redefine "+" ??
From: D Gary Grady
Date: Mon, 11 Feb 1985 18:59
Date: Mon, 11 Feb 1985 18:59
22 lines
1449 bytes
1449 bytes
> Do any of you FORTH experts out there know the answer to this:
> How do you redefine the "+" function (or any other operator) such that
> entering "2 + 2" yields "4" instead of typing "2 2 +". Is this
> impossible in FORTH ?
You can do something like this:
: + 32 WORD NUMBER + ;
This defines plus to be a word that reads in the following word,
converts it to a number on the stack, then adds that to the number
previously put there. This is almost identical to a similar word
defined on page 277 of Brodie's _Starting Forth_.
A similar idea is used with almost all text-oriented operations in
Forth. Although Forth uses postfix notation for numbers, for text it
(of practical necessity) reverts to prefix or infix.
--
D Gary Grady
Duke U Comp Center, Durham, NC 27706
(919) 684-3695
USENET: {seismo,decvax,ihnp4,akgua,etc.}!mcnc!ecsvax!dgary
Technical Details
Message-ID:
<689@ecsvax.UUCP>Path:
arc1-ca.pugleaf.net!utzoo!watmath!clyde!burl!ulysses!allegra!mit-eddie!genrad!decvax!mcnc!ecsvax!dgaryReferences:
<2480@tekig.UUCP>, <375@harvard.ARPA>Show Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.1 6/24/83; site ecsvax.UUCP Path: arc1-ca.pugleaf.net!utzoo!watmath!clyde!burl!ulysses!allegra!mit-eddie!genrad!decvax!mcnc!ecsvax!dgary From: dgary@ecsvax.UUCP (D Gary Grady) Newsgroups: net.lang.forth Subject: Re: redefine "+" ?? Message-ID: <689@ecsvax.UUCP> Date: Mon, 11-Feb-85 13:59:26 EST Article-I.D.: ecsvax.689 Posted: Mon Feb 11 13:59:26 1985 Date-Received: Thu, 14-Feb-85 01:43:47 EST References: <2480@tekig.UUCP>, <375@harvard.ARPA> Organization: Duke U Comp Ctr Lines: 22