DUP Language Interpreter



Data Stack
Return Stack


PICK (ø) works, FLUSH (ß) is ignored.

Ian Osgood has defined a variant of FALSE called DUP (Ian's favorite stack operator). It has a few changes to make programming somewhat more convenient and to make the language Turing-complete:

The JavaScript source of this interpreter is here. A C interpreter which uses stdio is here. A Forth compiler from DUP to GNU Forth 0.7.0 is here.

Access to strings and memory allows solving many of the Rosetta Code problems.

Other samples:

99 3[^^>][^^/^>[[2+][%2-3]?][%^.' ,%2-3]?]#.' ,2.%

[$1>[$1-f;!*][%1]?]f: 6f;!

[[$][\^/%]#%]g: 12 8g;! 63 18g;! 53 25g;!

[1\[2/\[@@^*@][]?$][@$*@@]#%\%]p: 3 5p;!

[0 1[@$][1-@@^+$.' ,\]#%%%]f: 20f;!

[(^^&)\^&]p:  {3and}
0s:0n: 0~$$255t;!%
s;.0$" solutions, "o;!n;.0$" nodes"o;!

[%%%%%%' 1$$]o:
[@@^$f;!^$f;!^^+65536< z;o;?]w:

1 1(1+)  {dip}
[$[1-\(p;!)\][%$]?]p:   {pick}
[$[1-\(r;!)\][% ]?]r:   {roll}
1 2 3 4 2r;! 4p;!
[$(![)%)%][)%)u;(]?]u:  {until}

0a:                      {array base}
0[$9<][$2*^a;+:1+]#%     {fill array}
a;5+;.   {10}            {access array}
[[$][\$;.' ,1+\1-]#%%]p: {print array}
[[$][@@^^;\!^:1+@1-]#%%%]m:  {map}
[$$**]a;9m;! a;9p;!

0$"alphaBETA"^-  {str len}
^^[$][\$;32 ~& , 1+\1-]#10,%%  {print upper}
^^[$][\$;32^~&|, 1+\1-]#10,%%  {print lower}
^^^+1-\[^^>][^^^;^;\@:\:\1-\1+]#%% {reverse}

  ^^>[][^^^;^;\@:\: \1+\1-]?
 ^^< q;[%%]?
 ^^< q;[%%]?]q:

4$"random text"1-q;!

{Conway's Game of Life}

16w: 16h:       {width height, powers of two}
0o: w;n:        { old/new }
w;2*h;*w;-1-m:  {wrapping mask}

[w;2*h;*0[^^>][0^:1+]#%%]c: {clear}

[o;+ 1^: w;2*+1+1^: w;2*+1^: 1-1^: 1-1^:%]d:  {glider}
[o;+ 1^: 1+1^: 1+1^:%]b: {blinker}

[w;2*h;*0[^^>][$w;+\[^^>][$o;+;['*][' ]?,1+]#%10,w;+]#%%]p:  {print}

{ row  col    w@ }
 ^w;2*-       m;&o;+;+
 ^w;2*-1+     m;&o;+;+
 ^     1-$w;&+m;&o;+;+
 ^     1+     m;&o;+;+
 ^w;2*+       m;&o;+;+
 ^w;2*+1+     m;&o;+;+    {neighbors}
 ^o;+;^~&|3=1&^n;+:]g:     {gen cell}
[w;2*h;*0[^^>][$w;+\[^^>][g;!1+]#%w;+]#%% o;n;o:n:]l: {gen}

c;! 1d;! p;! 19[$][l;!1-]# p;!

[9]⇒K              { define a constant }
[/\%]⇒÷               { divide only }
[^~&|]⇒V              { inclusive OR }
[\[^^>][$;,1+]#%%]⇒P  { string print }
0$" string"P

Last modified: 2015.07.02