DUP Language Interpreter



    

or

Input
Variables
Data Stack
Return Stack
Output:

    

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;!

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

[(^^&)\^&]p:  {3and}
[r:z:y:x:x;y;z;r;$$_&~q:]b:
[x;q;&2*1|y;q;&2/+z;q;&]a:
[p;![$][b;!a;!t;!$1-&]#%]l:
[$[n;1+n:l;!][s;1+s:]?%%%]t:
[\[^^>][$;,1+]#%%]o:
0s:0n: 0~$$255t;!%
s;.0$" solutions, "o;!n;.0$" nodes"o;!

[*16384/\%]f:
[-i;+@@f;!2*j;+]z:
[%%%%%%' 1$$]o:
[@@^$f;!^$f;!^^+65536< z;o;?]w:
['*30i;j;[@1-$]w;#%%%,]c:
[32768_[$16384<][$i:c;!616+]#%10,]r:
[18022_[$18022<][$j:r;!1502+]#%]m:
10,m;!

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

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-]#10,%%

[^^+2/;v:%
 ^^[^^<]
 [\[$;v;<][1+]#
  \[v;^;<][1-]#
  ^^>[][^^^;^;\@:\: \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*-1-$w;&+m;&o;+;
 ^w;2*-       m;&o;+;+
 ^w;2*-1+     m;&o;+;+
 ^     1-$w;&+m;&o;+;+
 ^     1+     m;&o;+;+
 ^w;2*+1-$w;&+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 }
K3÷.
[^~&|]⇒V              { inclusive OR }
[\[^^>][$;,1+]#%%]⇒P  { string print }
0$" string"P

Last modified: 2015.07.02