From db4c329aff4621e05b92a55be4f18173f5a4f655 Mon Sep 17 00:00:00 2001 From: Joel Martin Date: Thu, 17 Apr 2014 21:49:07 -0500 Subject: All: perf test, Makefile refactor, add *host-language* Other: - bash,make,postscript: quasiquote of vectors - Fix Java slurp - add time function to core.mal - switches on *host-language* for make time-secs vs time-ms - Ignore */experiments directories --- bash/core.sh | 9 ++++++++- bash/step7_quote.sh | 2 +- bash/step8_macros.sh | 2 +- bash/step9_interop.sh | 2 +- bash/stepA_more.sh | 5 ++++- 5 files changed, 15 insertions(+), 5 deletions(-) (limited to 'bash') diff --git a/bash/core.sh b/bash/core.sh index e0cba38..c8a0261 100644 --- a/bash/core.sh +++ b/bash/core.sh @@ -56,6 +56,12 @@ num_gte () { r=$(( ${ANON["${1}"]} >= ${ANON["${2}"]} )); _num_bool "${r}"; num_lt () { r=$(( ${ANON["${1}"]} < ${ANON["${2}"]} )); _num_bool "${r}"; } num_lte () { r=$(( ${ANON["${1}"]} <= ${ANON["${2}"]} )); _num_bool "${r}"; } +# return number of milliseconds since epoch +time_ms () { + local ms=$(date +%s%3N) + _number "${ms}" +} + # String functions @@ -280,7 +286,7 @@ meta () { } -# atoms +# Atom functions atom? () { _atom? "${1}" && r="${__true}" || r="${__false}"; } deref () { @@ -327,6 +333,7 @@ declare -A core_ns=( [-]=num_minus [__STAR__]=num_multiply [/]=num_divide + [time-ms]=time_ms [list]=_list [list?]=list? diff --git a/bash/step7_quote.sh b/bash/step7_quote.sh index b541d67..14721ba 100755 --- a/bash/step7_quote.sh +++ b/bash/step7_quote.sh @@ -14,7 +14,7 @@ READ () { } IS_PAIR () { - if _list? "${1}"; then + if _sequential? "${1}"; then _count "${1}" [[ "${r}" > 0 ]] && return 0 fi diff --git a/bash/step8_macros.sh b/bash/step8_macros.sh index 0e58404..e311489 100755 --- a/bash/step8_macros.sh +++ b/bash/step8_macros.sh @@ -14,7 +14,7 @@ READ () { } IS_PAIR () { - if _list? "${1}"; then + if _sequential? "${1}"; then _count "${1}" [[ "${r}" > 0 ]] && return 0 fi diff --git a/bash/step9_interop.sh b/bash/step9_interop.sh index c2b0931..0491f7f 100755 --- a/bash/step9_interop.sh +++ b/bash/step9_interop.sh @@ -14,7 +14,7 @@ READ () { } IS_PAIR () { - if _list? "${1}"; then + if _sequential? "${1}"; then _count "${1}" [[ "${r}" > 0 ]] && return 0 fi diff --git a/bash/stepA_more.sh b/bash/stepA_more.sh index d968942..8a8366a 100755 --- a/bash/stepA_more.sh +++ b/bash/stepA_more.sh @@ -14,7 +14,7 @@ READ () { } IS_PAIR () { - if _list? "${1}"; then + if _sequential? "${1}"; then _count "${1}" [[ "${r}" > 0 ]] && return 0 fi @@ -254,8 +254,11 @@ _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 # core.mal: defined using the language itself +REP "(def! *host-language* \"bash\")" REP "(def! not (fn* (a) (if a false true)))" 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)))))))" -- cgit v1.2.3