aboutsummaryrefslogtreecommitdiff
path: root/bash/stepA_more.sh
diff options
context:
space:
mode:
authorJoel Martin <github@martintribe.org>2014-04-19 13:04:09 -0500
committerJoel Martin <github@martintribe.org>2014-04-19 13:04:09 -0500
commit86b689f3d7111a9fa13da389a30f3dfdf877d1a4 (patch)
treed72b065f9f987e291f892ceee5a8640363bfd9df /bash/stepA_more.sh
parent718887c3019c49fc807bc18fbd5feb975ec03c85 (diff)
downloadmal-86b689f3d7111a9fa13da389a30f3dfdf877d1a4.tar.gz
mal-86b689f3d7111a9fa13da389a30f3dfdf877d1a4.zip
All: *ARGV* and *host-language*. Misc syncing/fixes.
Diffstat (limited to 'bash/stepA_more.sh')
-rwxr-xr-xbash/stepA_more.sh34
1 files changed, 18 insertions, 16 deletions
diff --git a/bash/stepA_more.sh b/bash/stepA_more.sh
index 8a8366a..88f2d4f 100755
--- a/bash/stepA_more.sh
+++ b/bash/stepA_more.sh
@@ -1,18 +1,17 @@
#!/bin/bash
-INTERACTIVE=${INTERACTIVE-yes}
-
source $(dirname $0)/reader.sh
source $(dirname $0)/printer.sh
source $(dirname $0)/env.sh
source $(dirname $0)/core.sh
-# READ: read and parse input
+# read
READ () {
[ "${1}" ] && r="${1}" || READLINE
READ_STR "${r}"
}
+# eval
IS_PAIR () {
if _sequential? "${1}"; then
_count "${1}"
@@ -104,7 +103,6 @@ EVAL_AST () {
esac
}
-# EVAL: evaluate the parameter
EVAL () {
local ast="${1}" env="${2}"
while true; do
@@ -229,7 +227,7 @@ EVAL () {
done
}
-# PRINT:
+# print
PRINT () {
if [[ "${__ERROR}" ]]; then
_pr_str "${__ERROR}" yes
@@ -240,7 +238,7 @@ PRINT () {
fi
}
-# REPL: read, eval, print, loop
+# repl
ENV; REPL_ENV="${r}"
REP () {
r=
@@ -254,8 +252,9 @@ _fref () { _function "${2} \"\${@}\""; ENV_SET "${REPL_ENV}" "${1}" "${r}"; }
for n in "${!core_ns[@]}"; do _fref "${n}" "${core_ns["${n}"]}"; done
_eval () { EVAL "${1}" "${REPL_ENV}"; }
_fref "eval" _eval
-_time_ms () { local ms=$(date +%s%3N); _number "${ms}"; }
-_fref "time-ms" _time_ms
+_list; argv="${r}"
+for _arg in "${@:2}"; do _string "${_arg}"; _conj! "${argv}" "${r}"; done
+ENV_SET "${REPL_ENV}" "__STAR__ARGV__STAR__" "${argv}";
# core.mal: defined using the language itself
REP "(def! *host-language* \"bash\")"
@@ -264,12 +263,15 @@ REP "(def! load-file (fn* (f) (eval (read-string (str \"(do \" (slurp f) \")\"))
REP "(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)))))))"
REP "(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))))))))"
+# load/run file from command line (then exit)
if [[ "${1}" ]]; then
- echo "${@}"
- REP "(load-file \"${1}\")" && echo "${r}"
-elif [[ -n "${INTERACTIVE}" ]]; then
- while true; do
- READLINE "user> " || exit "$?"
- [[ "${r}" ]] && REP "${r}" && echo "${r}"
- done
-fi
+ REP "(load-file \"${1}\")"
+ exit 0
+fi
+
+# repl loop
+REP "(println (str \"Mal [\" *host-language* \"]\"))"
+while true; do
+ READLINE "user> " || exit "$?"
+ [[ "${r}" ]] && REP "${r}" && echo "${r}"
+done