From: Tim Vaughan Date: Tue, 19 Jul 2016 20:25:45 +0000 (+1200) Subject: Added some type conversion prims. X-Git-Url: https://thelambdalab.xyz/gitweb/index.cgi?a=commitdiff_plain;h=22e181f918b5518f64ee693c492469d11f2898ac;p=scheme.forth.jl.git Added some type conversion prims. --- diff --git a/scheme-primitives.4th b/scheme-primitives.4th index 3de4d37..4cba91e 100644 --- a/scheme-primitives.4th +++ b/scheme-primitives.4th @@ -48,6 +48,22 @@ car primitive-type istype? -rot 2drop boolean-type ; make-primitive procedure? +( = Type conversions = ) + +:noname ( args -- fixnum ) + 2dup 1 ensure-arg-count + car character-type ensure-arg-type + + drop fixnum-type +; make-primitive char->integer + +:noname ( args -- fixnum ) + 2dup 1 ensure-arg-count + car fixnum-type ensure-arg-type + + drop character-type +; make-primitive integer->char + ( = Arithmeic = ) : add-prim ( args -- fixnum ) diff --git a/scheme.4th b/scheme.4th index 1953cf9..644ee19 100644 --- a/scheme.4th +++ b/scheme.4th @@ -296,6 +296,17 @@ global-env setobj then ; +: arg-type-error + bold fg red ." Incorrect argument type." reset-term cr + abort +; + +: ensure-arg-type ( arg type -- ) + istype? false = if + arg-type-error + then +; + include scheme-primitives.4th \ }}}