All: split types into types, env, printer, core.
[jackhill/mal.git] / bash / step7_quote.sh
index cecc3b8..5aa2991 100755 (executable)
@@ -3,6 +3,9 @@
 INTERACTIVE=${INTERACTIVE-yes}
 
 source $(dirname $0)/reader.sh
+source $(dirname $0)/printer.sh
+source $(dirname $0)/core.sh
+source $(dirname $0)/env.sh
 
 # READ: read and parse input
 READ () {
@@ -20,8 +23,8 @@ IS_PAIR () {
 
 QUASIQUOTE () {
     if ! IS_PAIR "${1}"; then
-        symbol quote
-        list "${r}" "${1}"
+        _symbol quote
+        _list "${r}" "${1}"
         return
     else
         _nth "${1}" 0; local a0="${r}"
@@ -31,20 +34,20 @@ QUASIQUOTE () {
         elif IS_PAIR "${a0}"; then
             _nth "${a0}" 0; local a00="${r}"
             if [[ "${ANON["${a00}"]}" == "splice-unquote" ]]; then
-                symbol concat; local a="${r}"
+                _symbol concat; local a="${r}"
                 _nth "${a0}" 1; local b="${r}"
                 rest "${1}"
                 QUASIQUOTE "${r}"; local c="${r}"
-                list "${a}" "${b}" "${c}"
+                _list "${a}" "${b}" "${c}"
                 return
             fi
         fi
     fi
-    symbol cons; local a="${r}"
+    _symbol cons; local a="${r}"
     QUASIQUOTE "${a0}"; local b="${r}"
     rest "${1}"
     QUASIQUOTE "${r}"; local c="${r}"
-    list "${a}" "${b}" "${c}"
+    _list "${a}" "${b}" "${c}"
     return
 }
 
@@ -58,17 +61,17 @@ EVAL_AST () {
         ENV_GET "${env}" "${val}"
         return ;;
     list)
-        _map_with_type list EVAL "${ast}" "${env}" ;;
+        _map_with_type _list EVAL "${ast}" "${env}" ;;
     vector)
-        _map_with_type vector EVAL "${ast}" "${env}" ;;
+        _map_with_type _vector EVAL "${ast}" "${env}" ;;
     hash_map)
         local res="" val="" hm="${ANON["${ast}"]}"
-        hash_map; local new_hm="${r}"
+        _hash_map; local new_hm="${r}"
         eval local keys="\${!${hm}[@]}"
         for key in ${keys}; do
             eval val="\${${hm}[\"${key}\"]}"
             EVAL "${val}" "${env}"
-            assoc! "${new_hm}" "${key}" "${r}"
+            _assoc! "${new_hm}" "${key}" "${r}"
         done
         r="${new_hm}" ;;
     *)
@@ -141,9 +144,9 @@ EVAL () {
               fi
               # Continue loop
               ;;
-        fn*)  new_function "ENV \"${env}\" \"${a1}\" \"\${@}\"; \
-                            EVAL \"${a2}\" \"\${r}\"" \
-                           "${a2}" "${env}" "${a1}"
+        fn*)  _function "ENV \"${env}\" \"${a1}\" \"\${@}\"; \
+                         EVAL \"${a2}\" \"\${r}\"" \
+                        "${a2}" "${env}" "${a1}"
               return ;;
         *)    EVAL_AST "${ast}" "${env}"
               [[ "${__ERROR}" ]] && r= && return 1
@@ -182,14 +185,14 @@ ENV; REPL_ENV="${r}"
 REP () {
     r=
     READ_STR "${1}"
-    EVAL "${r}" ${REPL_ENV}
+    EVAL "${r}" "${REPL_ENV}"
     PRINT "${r}"
 }
 
-_fref () { new_function "${2} \"\${@}\""; ENV_SET "${REPL_ENV}" "${1}" "${r}"; }
+_fref () { _function "${2} \"\${@}\""; ENV_SET "${REPL_ENV}" "${1}" "${r}"; }
 
 # Import types functions
-for n in "${!types_ns[@]}"; do _fref "${n}" "${types_ns["${n}"]}"; done
+for n in "${!core_ns[@]}"; do _fref "${n}" "${core_ns["${n}"]}"; done
 
 read_string () { READ_STR "${ANON["${1}"]}"; }
 _fref "read-string" read_string
@@ -199,7 +202,7 @@ slurp () {
     local lines
     mapfile lines < "${ANON["${1}"]}"
     local text="${lines[*]}"; text=${text//$'\n' /$'\n'}
-    string "${text}"
+    _string "${text}"
 }
 _fref "slurp" slurp