-( = Type predicates = )
+( ==== Type predicates ==== )
:noname ( args -- boolobj )
2dup 1 ensure-arg-count
car primitive-proc-type istype? -rot 2drop boolean-type
; make-primitive procedure?
-( = Type conversions = )
+( ==== Type conversions ==== )
:noname ( args -- fixnum )
2dup 1 ensure-arg-count
charlist>symbol
; make-primitive string->symbol
-( = Arithmetic = )
+( ==== Arithmetic ==== )
: add-prim ( args -- fixnum )
2dup nil objeq? if
hide relcfa
-( = Pairs and Lists = )
+( ==== Pairs and Lists ==== )
:noname ( args -- pair )
2dup 2 ensure-arg-count
ok-symbol
; make-primitive set-cdr!
-( = Polymorphic equality testing = )
+( ==== Polymorphic equality testing ==== )
:noname ( args -- bool )
2dup 2 ensure-arg-count
objeq? boolean-type
; make-primitive eq?
+
+( ==== Input/Output ==== )
+
+:noname ( args -- finalResult )
+ 2dup 1 ensure-arg-count
+ car string-type ensure-arg-type
+
+ drop pair-type
+ pad charlist>cstr
+ pad swap load
+; make-primitive load
+
+:noname ( args -- obj )
+ 0 ensure-arg-count
+ read
+; make-primitive read
+
+defer display
+:noname ( args -- none )
+ 2dup 1 ensure-arg-count
+
+ car print
+
+ none
+; make-primitive write
+
+: displaypair ( pairobj -- )
+ 2dup
+ car display
+ cdr
+ nil? if 2drop exit then
+ pair-type istype? if space recurse exit then
+ ." . " display
+;
+
+: displaychar ( charobj -- )
+ drop emit ;
+
+: (displaystring) ( charlist -- )
+ nil? if
+ 2drop
+ else
+ 2dup car displaychar
+ cdr recurse
+ then
+;
+
+: displaystring ( stringobj -- )
+ drop pair-type (displaystring)
+;
+
+:noname ( obj -- )
+ pair-type istype? if ." (" displaypair ." )" exit then
+ character-type istype? if displaychar exit then
+ string-type istype? if displaystring exit then
+
+ print
+; is display
+
+:noname ( args -- none )
+ 2dup 1 ensure-arg-count
+ car string-type ensure-arg-type
+
+ displaystring
+
+ none
+; make-primitive display-string
+
+:noname ( args -- none )
+ 2dup 1 ensure-arg-count
+ car character-type ensure-arg-type
+
+ displaychar
+
+ none
+; make-primitive display-character
+
+:noname ( args -- none )
+ 2dup 1 ensure-arg-count
+ car
+
+ display
+
+ none
+; make-primitive display
+
+:noname ( args -- none )
+ 0 ensure-arg-count
+
+ cr
+
+ none
+; make-primitive newline
+
+( ==== Evaluation ==== )
+
+:noname ( args -- result )
+ 2dup car 2swap cdr
+
+ nil? false = if car then ( proc argvals )
+
+ apply
+; make-primitive apply
+
+( ==== Error System ==== )
+
+:noname ( args -- result )
+ bold fg red
+
+ nil? if
+ ." Error."
+ else
+ ." Error: " car display
+ then
+
+ reset-term
+
+ recoverable-exception throw
+; make-primitive error