1 \ ==== Type predicates ==== {{{
3 :noname ( args -- boolobj )
4 nil objeq? boolean-type
5 ; 1 make-fa-primitive null?
7 :noname ( args -- boolobj )
8 boolean-type istype? -rot 2drop boolean-type
9 ; 1 make-fa-primitive boolean?
11 :noname ( args -- boolobj )
12 symbol-type istype? -rot 2drop boolean-type
13 ; 1 make-fa-primitive symbol?
15 :noname ( args -- boolobj )
16 fixnum-type istype? -rot 2drop boolean-type
17 ; 1 make-fa-primitive fixnum?
19 :noname ( args -- boolobj )
20 character-type istype? -rot 2drop boolean-type
21 ; 1 make-fa-primitive char?
23 :noname ( args -- boolobj )
24 string-type istype? -rot 2drop boolean-type
25 ; 1 make-fa-primitive string?
27 :noname ( args -- boolobj )
28 pair-type istype? -rot 2drop boolean-type
29 ; 1 make-fa-primitive pair?
31 :noname ( args -- boolobj )
32 primitive-proc-type istype? if
35 compound-proc-type istype?
38 -rot 2drop boolean-type
39 ; 1 make-fa-primitive procedure?
43 \ ==== Type conversions ==== {{{
45 :noname ( args -- fixnum )
46 2dup 1 ensure-arg-count
47 car character-type ensure-arg-type
50 ; make-primitive char->integer
52 :noname ( args -- char )
53 2dup 1 ensure-arg-count
54 car fixnum-type ensure-arg-type
57 ; make-primitive integer->char
59 : fixnum-to-charlist ( fixnum -- charlist )
62 [char] 0 character-type nil cons
66 nil 2swap ( charlist fixnum )
71 2dup swap 10 mod swap ( charlist fixnum fixnummod )
72 2swap swap 10 / swap ( charlist fixnummod fixnumdiv )
73 -2rot ( fixnumdiv charlist fixnummod )
75 drop [char] 0 + character-type 2swap
76 cons ( fixnumdiv newcharlist )
84 :noname ( args -- string )
85 2dup 1 ensure-arg-count
86 car fixnum-type ensure-arg-type
90 fixnum-to-charlist ( fixnum charlist )
92 [char] - character-type 2swap cons
96 ; make-primitive number->string
98 :noname ( args -- symbol )
99 2dup 1 ensure-arg-count
100 car string-type ensure-arg-type
104 2dup car [char] - character-type objeq? if
108 2dup car [char] + character-type objeq? if
116 2dup nil objeq? false =
118 2dup car drop [char] 0 - -rot
119 2swap swap 10 * + -rot
128 ; make-primitive string->number
130 :noname ( args -- string )
131 2dup 1 ensure-arg-count
132 car symbol-type ensure-arg-type
137 ; make-primitive symbol->string
139 :noname ( args -- symbol )
140 2dup 1 ensure-arg-count
141 car string-type ensure-arg-type
146 ; make-primitive string->symbol
150 \ ==== Primitivle Arithmetic ==== {{{
154 :noname ( fixnum fixnum -- boolobj )
156 ; 2 make-fa-primitive fix:=
158 :noname ( fixnum fixnum -- boolobj )
159 drop swap drop < boolean-type
160 ; 2 make-fa-primitive fix:<
162 :noname ( fixnum fixnum -- boolobj )
163 drop swap drop > boolean-type
164 ; 2 make-fa-primitive fix:>
166 :noname ( fixnum fixnum -- boolobj )
167 drop swap drop <= boolean-type
168 ; 2 make-fa-primitive fix:<=
170 :noname ( fixnum fixnum -- boolobj )
171 drop swap drop >= boolean-type
172 ; 2 make-fa-primitive fix:>=
174 :noname ( fixnum fixnum -- boolobj )
176 ; 1 make-fa-primitive fix:zero?
178 :noname ( fixnum fixnum -- boolobj )
180 ; 1 make-fa-primitive fix:positive?
182 :noname ( fixnum fixnum -- boolobj )
184 ; 1 make-fa-primitive fix:negative?
186 :noname ( fixnum fixnum -- fixnum' )
187 drop swap drop + fixnum-type
188 ; 2 make-fa-primitive fix:+
190 :noname ( fixnum fixnum -- fixnum' )
191 drop swap drop - fixnum-type
192 ; 2 make-fa-primitive fix:-
194 :noname ( fixnum fixnum -- fixnum' )
195 drop swap drop * fixnum-type
196 ; 2 make-fa-primitive fix:*
198 :noname ( fixnum fixnum -- fixnum' )
199 drop swap drop / fixnum-type
200 ; 2 make-fa-primitive fix:quotient
202 :noname ( fixnum fixnum -- fixnum' )
203 drop swap drop mod fixnum-type
204 ; 2 make-fa-primitive fix:remainder
206 :noname ( fixnum -- fixnum+1 )
208 ; 1 make-fa-primitive fix:1+
210 :noname ( fixnum -- fixnum-1 )
212 ; 1 make-fa-primitive fix:-1+
214 :noname ( fixnum -- -fixnum )
216 ; 1 make-fa-primitive fix:neg
218 ( Find the GCD of n1 and n2 where n2 < n1. )
225 \ ==== Pairs and Lists ==== {{{
227 :noname ( arg1 arg2 -- pair )
229 ; 2 make-fa-primitive cons
231 :noname ( pair-obj -- obj )
233 ; pair-type 1 make-fa-type-primitive car
235 :noname ( args -- obj )
237 ; pair-type 1 make-fa-type-primitive cdr
239 :noname ( pair obj -- ok )
240 2swap pair-type ensure-arg-type
245 ; 2 make-fa-primitive set-car!
247 :noname ( pair obj -- ok )
248 2swap pair-type ensure-arg-type
253 ; 2 make-fa-primitive set-cdr!
257 \ ==== Polymorphic equality testing ==== {{{
259 :noname ( arg1 arg2 -- bool )
261 ; 2 make-fa-primitive eq?
265 \ ==== Input/Output ==== {{{
267 :noname ( args -- finalResult )
271 ; string-type 1 make-fa-type-primitive load
273 :noname ( args -- obj )
275 ; 0 make-fa-primitive read
279 :noname ( obj -- none )
281 ; 1 make-fa-primitive write
283 : displaypair ( pairobj -- )
287 nil? if 2drop exit then
288 pair-type istype? if space recurse exit then
292 : displaychar ( charobj -- )
295 : (displaystring) ( charlist -- )
304 : displaystring ( stringobj -- )
305 drop pair-type (displaystring)
309 pair-type istype? if ." (" displaypair ." )" exit then
310 character-type istype? if displaychar exit then
311 string-type istype? if displaystring exit then
316 :noname ( stringobj -- none )
318 ; string-type 1 make-fa-type-primitive display-string
320 :noname ( charobj -- none )
322 ; character-type 1 make-fa-type-primitive display-character
324 :noname ( obj -- none )
326 ; 1 make-fa-primitive display
328 :noname ( args -- none )
330 ; 0 make-fa-primitive newline
334 \ ==== Evaluation ==== {{{
336 :noname ( args -- result )
339 nil? false = if car then ( proc argvals )
342 ; make-primitive apply
346 \ ==== Miscellaneous ==== {{{
348 ( Produce a recoverable exception. )
349 :noname ( args -- result )
355 ." Error: " car display
360 recoverable-exception throw
361 ; make-primitive error
363 ( Generate a temporary unique symbol. Used in the creation of hygienic macros. )
364 :noname ( args -- result )
365 [char] _ character-type nil cons
367 ; 0 make-fa-primitive gensym
369 ( Generate the NONE object indicating an unspecified return value. )
370 :noname ( args -- result )
372 ; 0 make-fa-primitive none