aboutsummaryrefslogtreecommitdiff
path: root/bash/step6_file.sh
diff options
context:
space:
mode:
authorJoel Martin <github@martintribe.org>2014-04-16 23:57:50 -0500
committerJoel Martin <github@martintribe.org>2014-04-16 23:57:50 -0500
commit8cb5cda46cf3aef847ae3926dc53a5e5f87fe261 (patch)
tree13e5b2878f19ee24272ead8a92a9cb84b33ad0e5 /bash/step6_file.sh
parenta05f7822b10ed4cdd61ed8384299a003baf1c1c6 (diff)
downloadmal-8cb5cda46cf3aef847ae3926dc53a5e5f87fe261.tar.gz
mal-8cb5cda46cf3aef847ae3926dc53a5e5f87fe261.zip
All: move some fns to core. Major cleanup.
- Don't import/require core until step4. - Define cond/or macros from step8
Diffstat (limited to 'bash/step6_file.sh')
-rwxr-xr-xbash/step6_file.sh29
1 files changed, 9 insertions, 20 deletions
diff --git a/bash/step6_file.sh b/bash/step6_file.sh
index 1ebba64..b2a3dc8 100755
--- a/bash/step6_file.sh
+++ b/bash/step6_file.sh
@@ -4,12 +4,12 @@ INTERACTIVE=${INTERACTIVE-yes}
source $(dirname $0)/reader.sh
source $(dirname $0)/printer.sh
-source $(dirname $0)/core.sh
source $(dirname $0)/env.sh
+source $(dirname $0)/core.sh
# READ: read and parse input
READ () {
- READLINE
+ [ "${1}" ] && r="${1}" || READLINE
READ_STR "${r}"
}
@@ -79,7 +79,7 @@ EVAL () {
_slice "${ast}" 1 $(( ${r} - 2 ))
EVAL_AST "${r}" "${env}"
[[ "${__ERROR}" ]] && r= && return 1
- last "${ast}"
+ _last "${ast}"
ast="${r}"
# Continue loop
;;
@@ -106,8 +106,8 @@ EVAL () {
*) EVAL_AST "${ast}" "${env}"
[[ "${__ERROR}" ]] && r= && return 1
local el="${r}"
- first "${el}"; local f="${ANON["${r}"]}"
- rest "${el}"; local args="${ANON["${r}"]}"
+ _first "${el}"; local f="${ANON["${r}"]}"
+ _rest "${el}"; local args="${ANON["${r}"]}"
#echo "invoke: [${f}] ${args}"
if [[ "${f//@/ }" != "${f}" ]]; then
set -- ${f//@/ }
@@ -139,29 +139,18 @@ PRINT () {
ENV; REPL_ENV="${r}"
REP () {
r=
- READ_STR "${1}"
- EVAL "${r}" ${REPL_ENV}
+ READ "${1}" || return 1
+ EVAL "${r}" "${REPL_ENV}"
PRINT "${r}"
}
+# core.sh: defined using bash
_fref () { _function "${2} \"\${@}\""; ENV_SET "${REPL_ENV}" "${1}" "${r}"; }
-
-# Import types functions
for n in "${!core_ns[@]}"; do _fref "${n}" "${core_ns["${n}"]}"; done
-
-read_string () { READ_STR "${ANON["${1}"]}"; }
-_fref "read-string" read_string
_eval () { EVAL "${1}" "${REPL_ENV}"; }
_fref "eval" _eval
-slurp () {
- local lines
- mapfile lines < "${ANON["${1}"]}"
- local text="${lines[*]}"; text=${text//$'\n' /$'\n'}
- _string "${text}"
-}
-_fref "slurp" slurp
-# Defined using the language itself
+# core.mal: defined using the language itself
REP "(def! not (fn* (a) (if a false true)))"
REP "(def! load-file (fn* (f) (eval (read-string (str \"(do \" (slurp f) \")\")))))"