aboutsummaryrefslogtreecommitdiff
path: root/bash/step7_quote.sh
diff options
context:
space:
mode:
authorJoel Martin <github@martintribe.org>2014-12-18 20:33:49 -0600
committerJoel Martin <github@martintribe.org>2015-01-09 16:16:50 -0600
commitb8ee29b22fbaa7a01f2754b4d6dd9af52e02017c (patch)
treef4d977ed220e9a3f665cfbf4f68770a81e4c2095 /bash/step7_quote.sh
parentaaba249304b184e12e2445ab22d66df1f39a51a5 (diff)
downloadmal-b8ee29b22fbaa7a01f2754b4d6dd9af52e02017c.tar.gz
mal-b8ee29b22fbaa7a01f2754b4d6dd9af52e02017c.zip
All: add keywords.
Also, fix nth and count to match cloure.
Diffstat (limited to 'bash/step7_quote.sh')
-rwxr-xr-xbash/step7_quote.sh25
1 files changed, 14 insertions, 11 deletions
diff --git a/bash/step7_quote.sh b/bash/step7_quote.sh
index d71e24b..2f2e67e 100755
--- a/bash/step7_quote.sh
+++ b/bash/step7_quote.sh
@@ -56,8 +56,7 @@ EVAL_AST () {
_obj_type "${ast}"; local ot="${r}"
case "${ot}" in
symbol)
- local val="${ANON["${ast}"]}"
- ENV_GET "${env}" "${val}"
+ ENV_GET "${env}" "${ast}"
return ;;
list)
_map_with_type _list EVAL "${ast}" "${env}" ;;
@@ -84,8 +83,7 @@ EVAL () {
r=
[[ "${__ERROR}" ]] && return 1
#_pr_str "${ast}"; echo "EVAL '${r} / ${env}'"
- _obj_type "${ast}"; local ot="${r}"
- if [[ "${ot}" != "list" ]]; then
+ if ! _list? "${ast}"; then
EVAL_AST "${ast}" "${env}"
return
fi
@@ -95,10 +93,9 @@ EVAL () {
_nth "${ast}" 1; local a1="${r}"
_nth "${ast}" 2; local a2="${r}"
case "${ANON["${a0}"]}" in
- def!) local k="${ANON["${a1}"]}"
- #echo "def! ${k} to ${a2} in ${env}"
- EVAL "${a2}" "${env}"
- ENV_SET "${env}" "${k}" "${r}"
+ def!) EVAL "${a2}" "${env}"
+ [[ "${__ERROR}" ]] && return 1
+ ENV_SET "${env}" "${a1}" "${r}"
return ;;
let*) ENV "${env}"; local let_env="${r}"
local let_pairs=(${ANON["${a1}"]})
@@ -106,7 +103,7 @@ EVAL () {
#echo "let: [${let_pairs[*]}] for ${a2}"
while [[ "${let_pairs["${idx}"]}" ]]; do
EVAL "${let_pairs[$(( idx + 1))]}" "${let_env}"
- ENV_SET "${let_env}" "${ANON["${let_pairs[${idx}]}"]}" "${r}"
+ ENV_SET "${let_env}" "${let_pairs[${idx}]}" "${r}"
idx=$(( idx + 2))
done
ast="${a2}"
@@ -130,6 +127,7 @@ EVAL () {
# Continue loop
;;
if) EVAL "${a1}" "${env}"
+ [[ "${__ERROR}" ]] && return 1
if [[ "${r}" == "${__false}" || "${r}" == "${__nil}" ]]; then
# eval false form
_nth "${ast}" 3; local a3="${r}"
@@ -191,13 +189,18 @@ REP () {
}
# core.sh: defined using bash
-_fref () { _function "${2} \"\${@}\""; ENV_SET "${REPL_ENV}" "${1}" "${r}"; }
+_fref () {
+ _symbol "${1}"; local sym="${r}"
+ _function "${2} \"\${@}\""
+ ENV_SET "${REPL_ENV}" "${sym}" "${r}"
+}
for n in "${!core_ns[@]}"; do _fref "${n}" "${core_ns["${n}"]}"; done
_eval () { EVAL "${1}" "${REPL_ENV}"; }
_fref "eval" _eval
_list; argv="${r}"
for _arg in "${@:2}"; do _string "${_arg}"; _conj! "${argv}" "${r}"; done
-ENV_SET "${REPL_ENV}" "__STAR__ARGV__STAR__" "${argv}";
+_symbol "__STAR__ARGV__STAR__"
+ENV_SET "${REPL_ENV}" "${r}" "${argv}";
# core.mal: defined using the language itself
REP "(def! not (fn* (a) (if a false true)))"