tisp

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

commit 56064fb6d382250e9067beb303ba52b82aa3ca63
parent 23d8b441a09ac855870b5e9f4310b3ef1d0f78af
Author: Ed van Bruggen <edvb@uw.edu>
Date:   Sat, 10 Oct 2020 14:30:26 -0700

Implement numerator and denominator with get

Diffstat:
tib/math.c | 21---------------------
tib/math.tsp | 2++
2 files changed, 2 insertions(+), 21 deletions(-)

diff --git a/tib/math.c b/tib/math.c @@ -31,24 +31,6 @@ tsp_arg_type(A, NAME, TYPE); \ } while(0) -static Val -prim_numerator(Tsp st, Hash vars, Val args) -{ - Val a; - tsp_arg_num(args, "numerator", 1); - EVAL_CHECK(a, car(args), "numerator", TSP_RATIONAL); - return mk_int(num(a)); -} - -static Val -prim_denominator(Tsp st, Hash vars, Val args) -{ - Val a; - tsp_arg_num(args, "denominator", 1); - EVAL_CHECK(a, car(args), "denominator", TSP_RATIONAL); - return mk_int(den(a)); -} - /* wrapper functions to be returned by mk_num, all need same arguments */ static Val create_int(double num, double den) @@ -256,9 +238,6 @@ PRIM_TRIG(log) void tib_env_math(Tsp st) { - tsp_env_fn(numerator); - tsp_env_fn(denominator); - tsp_env_fn(Int); tsp_env_fn(Dec); tsp_env_fn(floor); diff --git a/tib/math.tsp b/tib/math.tsp @@ -6,6 +6,8 @@ ;;; Functions +(def (numerator x) (get x 'num)) +(def (denominator x) (get x 'den)) (def (inc x) (+ x 1)) (def (dec x) (- x 1)) (def (truncate x) (* (floor (abs x)) (sgn x)))