X-Git-Url: https://thelambdalab.xyz/gitweb/index.cgi?a=blobdiff_plain;f=scheme-primitives.4th;h=c99a0c000bc3ccc64a20e9298dcfec54d407a20c;hb=8a9d83b586844a04f7ee19f98b56f460063bdcad;hp=a9ea386f919397377da00babfcd045367638a00d;hpb=871b6800c52715e27f968bf1203e7f3144893a9c;p=scheme.forth.jl.git diff --git a/scheme-primitives.4th b/scheme-primitives.4th index a9ea386..c99a0c0 100644 --- a/scheme-primitives.4th +++ b/scheme-primitives.4th @@ -64,7 +64,7 @@ drop character-type ; make-primitive integer->char -: build-fixnum-charlist ( num ) +: num-to-charlist ( num -- charlist ) ?dup 0= if [char] 0 character-type nil cons exit @@ -90,7 +90,7 @@ drop dup 0< swap abs ( bool num ) - build-fixnum-charlist + num-to-charlist rot if [char] - character-type 2swap cons then @@ -98,6 +98,56 @@ drop string-type ; make-primitive number->string +:noname ( args -- symbol ) + 2dup 1 ensure-arg-count + car string-type ensure-arg-type + + drop pair-type + + 2dup car [char] - character-type objeq? if + cdr + true -rot + else + 2dup car [char] + character-type objeq? if + cdr + then + false -rot + then + + 0 -rot + begin + 2dup nil objeq? false = + while + 2dup car drop [char] 0 - -rot + 2swap swap 10 * + -rot + cdr + repeat + + 2drop + + swap if -1 * then + + fixnum-type +; make-primitive string->number + +:noname ( args -- string ) + 2dup 1 ensure-arg-count + car symbol-type ensure-arg-type + + drop pair-type + duplicate-charlist + drop string-type +; make-primitive symbol->string + +:noname ( args -- symbol ) + 2dup 1 ensure-arg-count + car string-type ensure-arg-type + + drop pair-type + duplicate-charlist + charlist>symbol +; make-primitive string->symbol + ( = Arithmetic = ) : add-prim ( args -- fixnum ) @@ -118,8 +168,14 @@ 0 fixnum-type else 2dup car drop - -rot cdr add-prim drop - - fixnum-type + -rot cdr + 2dup nil objeq? if + 2drop negate + else + add-prim drop + - + then + fixnum-type then ; make-primitive - @@ -134,3 +190,24 @@ then ; make-primitive * +:noname ( args -- fixnum ) + 2dup 2 ensure-arg-count + + 2dup car fixnum-type ensure-arg-type + 2swap cdr car fixnum-type ensure-arg-type + + drop swap drop + + / fixnum-type +; make-primitive quotient + +:noname ( args -- fixnum ) + 2dup 2 ensure-arg-count + + 2dup car fixnum-type ensure-arg-type + 2swap cdr car fixnum-type ensure-arg-type + + drop swap drop + + mod fixnum-type +; make-primitive remainder