DUP
Ian Osgood created a FALSE interpreter which he enhanced into a variant called DUP with several changes to make coding somewhat more convenient. In the spirit of FALSE, the language is named after Ian's favorite Forth stack operator.
- The if command (?) takes both true and false blocks. So what would be written '$[\true\]?~[false]?' is now written '[true][false]?'
- There is an extra stack function from Forth: OVER (^).
- Character input was moved to the backquote (`).
- The otherwise unused parentheses give access to the return stack, like Forth's >R and R>, which makes the variant Turing complete.
- To get at the MOD operator, the slash (/) does Forth's /MOD. DIV is '/\%' and MOD '/%'.
- Like colorForth, XOR replaces OR (|). Inclusive OR is ^~&|
- The less than operator (<) is also implemented, to balance greater than (>).
- You can store to numeric addresses, not just the 26 letter variables. This JavaScript side effect was made an official language feature in order to construct arrays, strings, and structures.
- String constants, "like this", now store to memory, one character per cell, to allow for string manipulation as well as string output.
- Experimental: operator definition: [block]⇒C defines an operator which is executed when referenced. Probably only for JavaScript. Example: [^~&|]⇒V {inclusive OR}
PICK (ø, U+00F8) is supported. FLUSH (ß, U+00DF) is a no-op.
Secondary stack
Access to the continuation stack makes DUP Turing-complete.
- ( push from data to secondary stack
- ) pop from secondary to data stack
which allows many further stack extensions and custom control structures.
1 1(1+) {dip} ($)\ {over} (\)\ {rot} [$[1-\(p;!)\][%$]?]p: {pick} [$[1-\(r;!)\][% ]?]r: {roll} 1 2 3 4 2r;! 4p;! [10/$u;[%]?'0+,]u: {unsigned print, like .} [$0<['-,_][]?u;(]p: {tail call optimization} 0p;! 1234_p;! [$(![)%)%][)%)u;(]?]u: {until} 0[$.1+$9>]u;!% {test again body stop } [($(![)%))\^w;(((!))][)%)%)%]?]w: {while, like #} 0[$2<][$.1+]w;!% [[)%))^^((t;(((][)%)%)%]?]t: {test check body test} [^((t;((]w: {while setup} 0[$2<][$.1+]w;!%
Memory
DUP gives access to bulk memory in the form of a cell array, using the standard STORE (:) and FETCH (;) operators. This space is disjoint from the memory used by the 26 letter variables. The bounds are currently undefined; the JavaScript interpreter is essentially unlimited, but zero to some large index is likely to be supported.
0a: {array base} a;0[$9<][^^\: \1+\1+]#%% {fill array} [[$][\;.' ,1+\1-]#%%]p: {print array} a;9p;!
The string syntax of FALSE was changed from string output to string definition. The starting location is given on the stack before the string, and the value is modified by the length of the string. One character is stored per cell, which easily allows multibyte encodings like Unicode.
[[$][\$;,1+\1-]#%%]p: {string print} 0$"string" {str end} ^- {str len} p;!
External resources
- Interpreter/debugger in JavaScript running on a web page
- C interpreter which uses stdio
- Forth compiler which uses stdio and UTF-8 (requires GNU Forth 0.7.0)
- Julia interpreter with full Unicode support and detailed instruction explanation. (includes
⇒
operator)