aboutsummaryrefslogtreecommitdiff
path: root/ps
diff options
context:
space:
mode:
Diffstat (limited to 'ps')
-rw-r--r--ps/core.ps4
-rw-r--r--ps/step3_env.ps2
-rw-r--r--ps/step4_if_fn_do.ps4
-rw-r--r--ps/step5_tco.ps4
-rw-r--r--ps/step6_file.ps8
-rw-r--r--ps/step7_quote.ps8
-rw-r--r--ps/step8_macros.ps10
-rw-r--r--ps/step9_interop.ps10
-rw-r--r--ps/stepA_more.ps11
9 files changed, 31 insertions, 30 deletions
diff --git a/ps/core.ps b/ps/core.ps
index 34e846e..f9397fa 100644
--- a/ps/core.ps
+++ b/ps/core.ps
@@ -223,10 +223,14 @@ end } def
(true?) { 0 _nth _true? }
(false?) { 0 _nth _false? }
(symbol?) { 0 _nth _symbol? }
+
(pr-str) { /data get ( ) true _pr_str_args }
(str) { /data get () false _pr_str_args }
(prn) { /data get ( ) true _pr_str_args print (\n) print null }
(println) { /data get ( ) false _pr_str_args print (\n) print null }
+ (readline) { 0 _nth _readline not { pop null } if }
+ (read-string) { 0 _nth read_str }
+ (slurp) { 0 _nth (r) file dup bytesavailable string readstring pop }
(<) { dup 0 _nth exch 1 _nth lt }
(<=) { dup 0 _nth exch 1 _nth le }
(>) { dup 0 _nth exch 1 _nth gt }
diff --git a/ps/step3_env.ps b/ps/step3_env.ps
index e94f92c..42eda2c 100644
--- a/ps/step3_env.ps
+++ b/ps/step3_env.ps
@@ -81,8 +81,8 @@ end } def
/repl_env null null null env_new def
/REP { READ repl_env EVAL PRINT } def
-/_ref { repl_env 3 1 roll env_set pop } def
+/_ref { repl_env 3 1 roll env_set pop } def
(+) { dup 0 _nth exch 1 _nth add } _ref
(-) { dup 0 _nth exch 1 _nth sub } _ref
(*) { dup 0 _nth exch 1 _nth mul } _ref
diff --git a/ps/step4_if_fn_do.ps b/ps/step4_if_fn_do.ps
index 952661a..b01c594 100644
--- a/ps/step4_if_fn_do.ps
+++ b/ps/step4_if_fn_do.ps
@@ -111,10 +111,12 @@ end } def
/RE { READ repl_env EVAL } def
/REP { READ repl_env EVAL PRINT } def
-/_ref { _function repl_env 3 1 roll env_set pop } def
+% core.ps: defined using postscript
+/_ref { _function repl_env 3 1 roll env_set pop } def
core_ns { _ref } forall
+% core.mal: defined using the language itself
(\(def! not \(fn* \(a\) \(if a false true\)\)\)) RE pop
{ % loop
diff --git a/ps/step5_tco.ps b/ps/step5_tco.ps
index 802f3d3..50bcdbf 100644
--- a/ps/step5_tco.ps
+++ b/ps/step5_tco.ps
@@ -121,10 +121,12 @@ end } def
/RE { READ repl_env EVAL } def
/REP { READ repl_env EVAL PRINT } def
-/_ref { _function repl_env 3 1 roll env_set pop } def
+% core.ps: defined using postscript
+/_ref { _function repl_env 3 1 roll env_set pop } def
core_ns { _ref } forall
+% core.mal: defined using the language itself
(\(def! not \(fn* \(a\) \(if a false true\)\)\)) RE pop
{ % loop
diff --git a/ps/step6_file.ps b/ps/step6_file.ps
index fc12cc1..faa7101 100644
--- a/ps/step6_file.ps
+++ b/ps/step6_file.ps
@@ -121,15 +121,13 @@ end } def
/RE { READ repl_env EVAL } def
/REP { READ repl_env EVAL PRINT } def
-/_ref { _function repl_env 3 1 roll env_set pop } def
+% core.ps: defined using postscript
+/_ref { _function repl_env 3 1 roll env_set pop } def
core_ns { _ref } forall
-
-(read-string) { 0 _nth read_str } _ref
(eval) { 0 _nth repl_env EVAL } _ref
-/slurp { (r) file dup bytesavailable string readstring pop } def
-(slurp) { 0 _nth slurp } _ref
+% core.mal: defined using the language itself
(\(def! not \(fn* \(a\) \(if a false true\)\)\)) RE pop
(\(def! load-file \(fn* \(f\) \(eval \(read-string \(str "\(do " \(slurp f\) "\)"\)\)\)\)\)) RE pop
diff --git a/ps/step7_quote.ps b/ps/step7_quote.ps
index 6913bf6..f335683 100644
--- a/ps/step7_quote.ps
+++ b/ps/step7_quote.ps
@@ -153,15 +153,13 @@ end } def
/RE { READ repl_env EVAL } def
/REP { READ repl_env EVAL PRINT } def
-/_ref { _function repl_env 3 1 roll env_set pop } def
+% core.ps: defined using postscript
+/_ref { _function repl_env 3 1 roll env_set pop } def
core_ns { _ref } forall
-
-(read-string) { 0 _nth read_str } _ref
(eval) { 0 _nth repl_env EVAL } _ref
-/slurp { (r) file dup bytesavailable string readstring pop } def
-(slurp) { 0 _nth slurp } _ref
+% core.mal: defined using the language itself
(\(def! not \(fn* \(a\) \(if a false true\)\)\)) RE pop
(\(def! load-file \(fn* \(f\) \(eval \(read-string \(str "\(do " \(slurp f\) "\)"\)\)\)\)\)) RE pop
diff --git a/ps/step8_macros.ps b/ps/step8_macros.ps
index 286c1ab..87fafb1 100644
--- a/ps/step8_macros.ps
+++ b/ps/step8_macros.ps
@@ -195,17 +195,17 @@ end } def
/RE { READ repl_env EVAL } def
/REP { READ repl_env EVAL PRINT } def
-/_ref { _function repl_env 3 1 roll env_set pop } def
+% core.ps: defined using postscript
+/_ref { _function repl_env 3 1 roll env_set pop } def
core_ns { _ref } forall
-
-(read-string) { 0 _nth read_str } _ref
(eval) { 0 _nth repl_env EVAL } _ref
-/slurp { (r) file dup bytesavailable string readstring pop } def
-(slurp) { 0 _nth slurp } _ref
+% core.mal: defined using the language itself
(\(def! not \(fn* \(a\) \(if a false true\)\)\)) RE pop
(\(def! load-file \(fn* \(f\) \(eval \(read-string \(str "\(do " \(slurp f\) "\)"\)\)\)\)\)) RE pop
+(\(defmacro! cond \(fn* \(& xs\) \(if \(> \(count xs\) 0\) \(list 'if \(first xs\) \(if \(> \(count xs\) 1\) \(nth xs 1\) \(throw "odd number of forms to cond"\)\) \(cons 'cond \(rest \(rest xs\)\)\)\)\)\)\)) RE pop
+(\(defmacro! or \(fn* \(& xs\) \(if \(empty? xs\) nil \(if \(= 1 \(count xs\)\) \(first xs\) `\(let* \(or_FIXME ~\(first xs\)\) \(if or_FIXME or_FIXME \(or ~@\(rest xs\)\)\)\)\)\)\)\)) RE pop
userdict /ARGUMENTS known { %if command line arguments
ARGUMENTS length 0 gt { %if more than 0 arguments
diff --git a/ps/step9_interop.ps b/ps/step9_interop.ps
index f4380da..fbf51a5 100644
--- a/ps/step9_interop.ps
+++ b/ps/step9_interop.ps
@@ -209,17 +209,17 @@ end } def
/RE { READ repl_env EVAL } def
/REP { READ repl_env EVAL PRINT } def
-/_ref { _function repl_env 3 1 roll env_set pop } def
+% core.ps: defined using postscript
+/_ref { _function repl_env 3 1 roll env_set pop } def
core_ns { _ref } forall
-
-(read-string) { 0 _nth read_str } _ref
(eval) { 0 _nth repl_env EVAL } _ref
-/slurp { (r) file dup bytesavailable string readstring pop } def
-(slurp) { 0 _nth slurp } _ref
+% core.mal: defined using the language itself
(\(def! not \(fn* \(a\) \(if a false true\)\)\)) RE pop
(\(def! load-file \(fn* \(f\) \(eval \(read-string \(str "\(do " \(slurp f\) "\)"\)\)\)\)\)) RE pop
+(\(defmacro! cond \(fn* \(& xs\) \(if \(> \(count xs\) 0\) \(list 'if \(first xs\) \(if \(> \(count xs\) 1\) \(nth xs 1\) \(throw "odd number of forms to cond"\)\) \(cons 'cond \(rest \(rest xs\)\)\)\)\)\)\)) RE pop
+(\(defmacro! or \(fn* \(& xs\) \(if \(empty? xs\) nil \(if \(= 1 \(count xs\)\) \(first xs\) `\(let* \(or_FIXME ~\(first xs\)\) \(if or_FIXME or_FIXME \(or ~@\(rest xs\)\)\)\)\)\)\)\)) RE pop
userdict /ARGUMENTS known { %if command line arguments
ARGUMENTS length 0 gt { %if more than 0 arguments
diff --git a/ps/stepA_more.ps b/ps/stepA_more.ps
index 91a1fc7..1720b94 100644
--- a/ps/stepA_more.ps
+++ b/ps/stepA_more.ps
@@ -245,20 +245,17 @@ end } def
/RE { READ repl_env EVAL } def
/REP { READ repl_env EVAL PRINT } def
-/_ref { _function repl_env 3 1 roll env_set pop } def
+% core.ps: defined using postscript
+/_ref { _function repl_env 3 1 roll env_set pop } def
core_ns { _ref } forall
-
-(readline) { 0 _nth _readline not { pop null } if } _ref
-(read-string) { 0 _nth read_str } _ref
(eval) { 0 _nth repl_env EVAL } _ref
-/slurp { (r) file dup bytesavailable string readstring pop } def
-(slurp) { 0 _nth slurp } _ref
+% core.mal: defined using the language itself
(\(def! not \(fn* \(a\) \(if a false true\)\)\)) RE pop
+(\(def! load-file \(fn* \(f\) \(eval \(read-string \(str "\(do " \(slurp f\) "\)"\)\)\)\)\)) RE pop
(\(defmacro! cond \(fn* \(& xs\) \(if \(> \(count xs\) 0\) \(list 'if \(first xs\) \(if \(> \(count xs\) 1\) \(nth xs 1\) \(throw "odd number of forms to cond"\)\) \(cons 'cond \(rest \(rest xs\)\)\)\)\)\)\)) RE pop
(\(defmacro! or \(fn* \(& xs\) \(if \(empty? xs\) nil \(if \(= 1 \(count xs\)\) \(first xs\) `\(let* \(or_FIXME ~\(first xs\)\) \(if or_FIXME or_FIXME \(or ~@\(rest xs\)\)\)\)\)\)\)\)) RE pop
-(\(def! load-file \(fn* \(f\) \(eval \(read-string \(str "\(do " \(slurp f\) "\)"\)\)\)\)\)) RE pop
userdict /ARGUMENTS known { %if command line arguments
ARGUMENTS length 0 gt { %if more than 0 arguments