Commits

Michael  committed 94bafd3

go forth and prosper

  • Participants
  • Parent commits 0fab04e

Comments (0)

Files changed (3)

File forth/helloworld.fs

+: hello ( -- "hello world" )
+  s" hello, world" type cr ;
+
+hello

File forth/sequences.fs

+: upto-n ( n -- n n-1 .. 0 )
+  dup 0> if
+    dup 1 - recurse
+  endif ;

File forth/test.fs

+\ Here is a test code
+( Here is a
+multi-line comment )
+
+: squared ( n -- n^2 )
+  dup * ;
+
+5 squared .
+7 squared .
+
+: nip ( .. B A -- .. A )
+  swap drop ;
+
+: tuck ( .. B A -- .. A B A )
+  swap over ;
+
+: negate ( n -- -n )
+  dup 2 * - ;
+
+: abs ( n -- |n| )
+  dup 0 < if
+      negate
+  endif ;
+
+: factorial ( n -- n! )
+  dup 0> if
+    dup 1- recurse *
+  else
+    drop 1
+  endif ;