1
1
mirror of https://github.com/kanaka/mal.git synced 2024-09-21 02:27:10 +03:00
mal/bash/step1_read_print.sh
Joel Martin ea81a8087b All: split types into types, env, printer, core.
- types: low-level mapping to the implementation language.
- core: functions on types that are exposed directly to mal.
- printer: implementation called by pr-str, str, prn, println.
- env: the environment implementation

- Also, unindent all TCO while loops so that the diff of step4 and
  step5 are minimized.
2014-04-02 22:23:37 -05:00

47 lines
784 B
Bash
Executable File

#!/bin/bash
INTERACTIVE=${INTERACTIVE-yes}
source $(dirname $0)/reader.sh
source $(dirname $0)/printer.sh
# READ: read and parse input
READ () {
[ "${1}" ] && r="${1}" || READLINE
READ_STR "${r}"
}
# EVAL: just return the input
EVAL () {
local ast="${1}"
local env="${2}"
r=
[[ "${__ERROR}" ]] && return 1
r="${ast}"
}
# PRINT:
PRINT () {
if [[ "${__ERROR}" ]]; then
_pr_str "${__ERROR}" yes
r="Error: ${r}"
__ERROR=
else
_pr_str "${1}" yes
fi
}
# REPL: read, eval, print, loop
REP () {
READ "${1}" || return 1
EVAL "${r}"
PRINT "${r}"
}
if [[ -n "${INTERACTIVE}" ]]; then
while true; do
READLINE "user> " || exit "$?"
[[ "${r}" ]] && REP "${r}" && echo "${r}"
done
fi