Compiler macros are often used to lay down code in the calling word. You'll see something like:
: foo ['] + compile ['] . compile ; immediate
This is fine, but sometimes you need to deal with other macros:
Compiler macros are often used to lay down code in the calling word. You'll see something like:
: foo ['] + compile ['] . compile ; immediate
This is fine, but sometimes you need to deal with other macros:
It's sometimes useful to be able to create an empty stub which will be pointed to a real definition later. | |
The simple solution is just to do: | |
: foo ; | |
This creates a new defintion ("foo"), with no runtime action. In Retro all colon definitions can be revectored, so this is all that is strictly required. It does have a downside with regard to readability. We can address this by defining a new word specifically to create stubs. | |
: stub ( "- ) create 0 , 0 , 9 , ['] .word last @ d->class ! ; |
One of the more interesting flow control words in Retro is later. This is a word that returns control to the caller, then regains control when the caller is finished.
A simple example:
: test ( - ) 1 . later 2 . ; : b ( - ) test 3 . ;
Run b, and you should see:
Traditionally, Retro has been released as public domain. In more recent times, with the increase in contributions from users outside the United States, this has lead to questions as most countries do not recognize the ability of an author to give up copyright protection on his work. Further study implies that even in the USA, outside of works developed by the government, it may not be possible to give up copyright protection.
For this reason, we have released the current generation of Retro under the ISC License, which offers as much freedom as possible. Basically the only requirement is that you leave any copyright statements and license file in the source code.
In 10.7 (and beyond) the vocabulary system in Retro has been significantly altered. Prior releases provided nestable, collapsible subsets of the global dictionary. The new approach differs by:
- no nesting
- each vocabulary is a separate dictionary list
- user controllable search order
Creating a Vocabulary
We'll leverage slices. We track a single LOCALS pointing to the current slice for locals.
'LOCALS' variable
'( - )\nVariable; holds a pointer to the current set of local variables' 'LOCALS' describe
Functions will get wrapped in a localize combinator. This needs to save and restore the prior LOCALS. dip makes this easy:
[ &LOCALS @ [ memory.request &LOCALS ! invoke &LOCALS @ memory.release ] dip &LOCALS ! ] 'localize' define
Download a Kindle-compatible version of the dictionary here. Unzip the .rar archive.
Get the "Send to Kindle" program on your computer. Here's the link for the Mac.
Right-click your recently downloaded (unzipped) dictionary file, and click the "Send to Kindle" menu item. It will arrive on your Kindle shortly.
Once the dictionary has arrived, go to your settings -- on my newish paperwhite, it's at Home > Settings > Device Options > Language and Dictionaries > Dictionaries > English. Choose the Webster's 1913.
""" pyrx | |
Implementation of a minimal Forth interpreter/compiler on top of Python 3.6. | |
It is based on Rx [1] and should eventually support Retro [2]. | |
Facts & Features: | |
- New words are compiled to Python bytecode (subroutine threading model). | |
- Dynamically typed: the only data type is the Python object. | |
- Literals are evaluated as Python expressions. | |
- The data stack is a global Python list. |