tisp

tiny lisp
git clone git://edryd.org/tisp
Log | Files | Refs | LICENSE

commit d3615060eb8b262893c276c78dd951d9d3c1307c
parent 53ffeea163e349956099cdcdd4a32ff411f38a3a
Author: Ed van Bruggen <edvb@uw.edu>
Date:   Mon,  1 Apr 2019 19:50:17 -0700

Support improper lists for function arguments

Allows for function to accept arbitrary number of arguments as a list.
Used to define list function.

Diffstat:
tibs/lib.tsp | 1+
tisp.c | 11+++++++++--
tisp.h | 2+-
3 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/tibs/lib.tsp b/tibs/lib.tsp @@ -60,6 +60,7 @@ (define (not x) (cond (x ()) (t t))) +(define (list . rest) rest) (define e (exp 1.)) (define (root b p) (pow b (/ 1 p))) diff --git a/tisp.c b/tisp.c @@ -304,11 +304,18 @@ hash_extend(Hash ht, Val args, Val vals) { Val arg, val; for (; !nilp(args) && !nilp(vals); args = cdr(args), vals = cdr(vals)) { - arg = car(args); - val = car(vals); + if (args->t == PAIR) { + arg = car(args); + val = car(vals); + } else { + arg = args; + val = vals; + } if (arg->t != SYMBOL) tsp_warn("hash_extend: argument not a symbol"); hash_add(ht, arg->v.s, val); + if (args->t != PAIR) + break; } return ht; } diff --git a/tisp.h b/tisp.h @@ -30,7 +30,7 @@ return NULL; \ } while(0) #define tsp_arg_num(ARGS, NAME, NARGS) do { \ - if (list_len(ARGS) != NARGS) \ + if (list_len(ARGS) != NARGS && NARGS != -1) \ tsp_warnf("%s: expected %d argument%s, received %d", \ NAME, NARGS, NARGS > 1 ? "s" : "", list_len(ARGS)); \ } while(0)