| 1 |
;;; SCHEME -- A Scheme interpreter evaluating a sort, written by Marc Feeley. |
| 2 |
|
| 3 |
; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 4 |
|
| 5 |
(library (rnrs-benchmarks scheme) |
| 6 |
(export main) |
| 7 |
(import (rnrs) (rnrs r5rs) |
| 8 |
(rnrs mutable-pairs) |
| 9 |
(rnrs mutable-strings) |
| 10 |
(rnrs-benchmarks)) |
| 11 |
|
| 12 |
(define (scheme-eval expr) |
| 13 |
(let ((code (scheme-comp expr scheme-global-environment))) |
| 14 |
(code #f))) |
| 15 |
|
| 16 |
(define scheme-global-environment |
| 17 |
(cons '() ; environment chain |
| 18 |
'())) ; macros |
| 19 |
|
| 20 |
(define (scheme-add-macro name proc) |
| 21 |
(set-cdr! scheme-global-environment |
| 22 |
(cons (cons name proc) (cdr scheme-global-environment))) |
| 23 |
name) |
| 24 |
|
| 25 |
(define (scheme-error msg . args) |
| 26 |
(fatal-error msg args)) |
| 27 |
|
| 28 |
; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 29 |
|
| 30 |
(define (lst->vector l) |
| 31 |
(let* ((n (length l)) |
| 32 |
(v (make-vector n))) |
| 33 |
(let loop ((l l) (i 0)) |
| 34 |
(if (pair? l) |
| 35 |
(begin |
| 36 |
(vector-set! v i (car l)) |
| 37 |
(loop (cdr l) (+ i 1))) |
| 38 |
v)))) |
| 39 |
|
| 40 |
(define (vector->lst v) |
| 41 |
(let loop ((l '()) (i (- (vector-length v) 1))) |
| 42 |
(if (< i 0) |
| 43 |
l |
| 44 |
(loop (cons (vector-ref v i) l) (- i 1))))) |
| 45 |
|
| 46 |
; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 47 |
|
| 48 |
(define scheme-syntactic-keywords |
| 49 |
'(quote quasiquote unquote unquote-splicing |
| 50 |
lambda if set! cond => else and or |
| 51 |
case let let* letrec begin do define |
| 52 |
define-macro)) |
| 53 |
|
| 54 |
; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 55 |
|
| 56 |
(define (push-frame frame env) |
| 57 |
(if (null? frame) |
| 58 |
env |
| 59 |
(cons (cons (car env) frame) (cdr env)))) |
| 60 |
|
| 61 |
(define (lookup-var name env) |
| 62 |
(let loop1 ((chain (car env)) (up 0)) |
| 63 |
(if (null? chain) |
| 64 |
name |
| 65 |
(let loop2 ((chain chain) |
| 66 |
(up up) |
| 67 |
(frame (cdr chain)) |
| 68 |
(over 1)) |
| 69 |
(cond ((null? frame) |
| 70 |
(loop1 (car chain) (+ up 1))) |
| 71 |
((eq? (car frame) name) |
| 72 |
(cons up over)) |
| 73 |
(else |
| 74 |
(loop2 chain up (cdr frame) (+ over 1)))))))) |
| 75 |
|
| 76 |
(define (macro? name env) |
| 77 |
(assq name (cdr env))) |
| 78 |
|
| 79 |
(define (push-macro name proc env) |
| 80 |
(cons (car env) (cons (cons name proc) (cdr env)))) |
| 81 |
|
| 82 |
(define (lookup-macro name env) |
| 83 |
(cdr (assq name (cdr env)))) |
| 84 |
|
| 85 |
; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 86 |
|
| 87 |
(define (variable x) |
| 88 |
(if (not (symbol? x)) |
| 89 |
(scheme-error "Identifier expected" x)) |
| 90 |
(if (memq x scheme-syntactic-keywords) |
| 91 |
(scheme-error "Variable name can not be a syntactic keyword" x))) |
| 92 |
|
| 93 |
(define (shape form n) |
| 94 |
(let loop ((form form) (n n) (l form)) |
| 95 |
(cond ((<= n 0)) |
| 96 |
((pair? l) |
| 97 |
(loop form (- n 1) (cdr l))) |
| 98 |
(else |
| 99 |
(scheme-error "Ill-constructed form" form))))) |
| 100 |
|
| 101 |
; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 102 |
|
| 103 |
(define (macro-expand expr env) |
| 104 |
(apply (lookup-macro (car expr) env) (cdr expr))) |
| 105 |
|
| 106 |
; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 107 |
|
| 108 |
(define (comp-var expr env) |
| 109 |
(variable expr) |
| 110 |
(gen-var-ref (lookup-var expr env))) |
| 111 |
|
| 112 |
; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 113 |
|
| 114 |
(define (comp-self-eval expr env) |
| 115 |
(gen-cst expr)) |
| 116 |
|
| 117 |
; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 118 |
|
| 119 |
(define (comp-quote expr env) |
| 120 |
(shape expr 2) |
| 121 |
(gen-cst (cadr expr))) |
| 122 |
|
| 123 |
; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 124 |
|
| 125 |
(define (comp-quasiquote expr env) |
| 126 |
(comp-quasiquotation (cadr expr) 1 env)) |
| 127 |
|
| 128 |
(define (comp-quasiquotation form level env) |
| 129 |
(cond ((= level 0) |
| 130 |
(scheme-comp form env)) |
| 131 |
((pair? form) |
| 132 |
(cond |
| 133 |
((eq? (car form) 'quasiquote) |
| 134 |
(comp-quasiquotation-list form (+ level 1) env)) |
| 135 |
((eq? (car form) 'unquote) |
| 136 |
(if (= level 1) |
| 137 |
(scheme-comp (cadr form) env) |
| 138 |
(comp-quasiquotation-list form (- level 1) env))) |
| 139 |
((eq? (car form) 'unquote-splicing) |
| 140 |
(if (= level 1) |
| 141 |
(scheme-error "Ill-placed 'unquote-splicing'" form)) |
| 142 |
(comp-quasiquotation-list form (- level 1) env)) |
| 143 |
(else |
| 144 |
(comp-quasiquotation-list form level env)))) |
| 145 |
((vector? form) |
| 146 |
(gen-vector-form |
| 147 |
(comp-quasiquotation-list (vector->lst form) level env))) |
| 148 |
(else |
| 149 |
(gen-cst form)))) |
| 150 |
|
| 151 |
(define (comp-quasiquotation-list l level env) |
| 152 |
(if (pair? l) |
| 153 |
(let ((first (car l))) |
| 154 |
(if (= level 1) |
| 155 |
(if (unquote-splicing? first) |
| 156 |
(begin |
| 157 |
(shape first 2) |
| 158 |
(gen-append-form (scheme-comp (cadr first) env) |
| 159 |
(comp-quasiquotation (cdr l) 1 env))) |
| 160 |
(gen-cons-form (comp-quasiquotation first level env) |
| 161 |
(comp-quasiquotation (cdr l) level env))) |
| 162 |
(gen-cons-form (comp-quasiquotation first level env) |
| 163 |
(comp-quasiquotation (cdr l) level env)))) |
| 164 |
(comp-quasiquotation l level env))) |
| 165 |
|
| 166 |
(define (unquote-splicing? x) |
| 167 |
(if (pair? x) |
| 168 |
(if (eq? (car x) 'unquote-splicing) #t #f) |
| 169 |
#f)) |
| 170 |
|
| 171 |
; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 172 |
|
| 173 |
(define (comp-unquote expr env) |
| 174 |
(scheme-error "Ill-placed 'unquote'" expr)) |
| 175 |
|
| 176 |
; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 177 |
|
| 178 |
(define (comp-unquote-splicing expr env) |
| 179 |
(scheme-error "Ill-placed 'unquote-splicing'" expr)) |
| 180 |
|
| 181 |
; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 182 |
|
| 183 |
(define (comp-set! expr env) |
| 184 |
(shape expr 3) |
| 185 |
(variable (cadr expr)) |
| 186 |
(gen-var-set (lookup-var (cadr expr) env) (scheme-comp (caddr expr) env))) |
| 187 |
|
| 188 |
; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 189 |
|
| 190 |
(define (comp-lambda expr env) |
| 191 |
(shape expr 3) |
| 192 |
(let ((parms (cadr expr))) |
| 193 |
(let ((frame (parms->frame parms))) |
| 194 |
(let ((nb-vars (length frame)) |
| 195 |
(code (comp-body (cddr expr) (push-frame frame env)))) |
| 196 |
(if (rest-param? parms) |
| 197 |
(gen-lambda-rest nb-vars code) |
| 198 |
(gen-lambda nb-vars code)))))) |
| 199 |
|
| 200 |
(define (parms->frame parms) |
| 201 |
(cond ((null? parms) |
| 202 |
'()) |
| 203 |
((pair? parms) |
| 204 |
(let ((x (car parms))) |
| 205 |
(variable x) |
| 206 |
(cons x (parms->frame (cdr parms))))) |
| 207 |
(else |
| 208 |
(variable parms) |
| 209 |
(list parms)))) |
| 210 |
|
| 211 |
(define (rest-param? parms) |
| 212 |
(cond ((pair? parms) |
| 213 |
(rest-param? (cdr parms))) |
| 214 |
((null? parms) |
| 215 |
#f) |
| 216 |
(else |
| 217 |
#t))) |
| 218 |
|
| 219 |
(define (comp-body body env) |
| 220 |
|
| 221 |
(define (letrec-defines vars vals body env) |
| 222 |
(if (pair? body) |
| 223 |
|
| 224 |
(let ((expr (car body))) |
| 225 |
(cond ((not (pair? expr)) |
| 226 |
(letrec-defines* vars vals body env)) |
| 227 |
((macro? (car expr) env) |
| 228 |
(letrec-defines vars |
| 229 |
vals |
| 230 |
(cons (macro-expand expr env) (cdr body)) |
| 231 |
env)) |
| 232 |
(else |
| 233 |
(cond |
| 234 |
((eq? (car expr) 'begin) |
| 235 |
(letrec-defines vars |
| 236 |
vals |
| 237 |
(append (cdr expr) (cdr body)) |
| 238 |
env)) |
| 239 |
((eq? (car expr) 'define) |
| 240 |
(let ((x (definition-name expr))) |
| 241 |
(variable x) |
| 242 |
(letrec-defines (cons x vars) |
| 243 |
(cons (definition-value expr) vals) |
| 244 |
(cdr body) |
| 245 |
env))) |
| 246 |
((eq? (car expr) 'define-macro) |
| 247 |
(let ((x (definition-name expr))) |
| 248 |
(letrec-defines vars |
| 249 |
vals |
| 250 |
(cdr body) |
| 251 |
(push-macro |
| 252 |
x |
| 253 |
(scheme-eval (definition-value expr)) |
| 254 |
env)))) |
| 255 |
(else |
| 256 |
(letrec-defines* vars vals body env)))))) |
| 257 |
|
| 258 |
(scheme-error "Body must contain at least one evaluable expression"))) |
| 259 |
|
| 260 |
(define (letrec-defines* vars vals body env) |
| 261 |
(if (null? vars) |
| 262 |
(comp-sequence body env) |
| 263 |
(comp-letrec-aux vars vals body env))) |
| 264 |
|
| 265 |
(letrec-defines '() '() body env)) |
| 266 |
|
| 267 |
(define (definition-name expr) |
| 268 |
(shape expr 3) |
| 269 |
(let ((pattern (cadr expr))) |
| 270 |
(let ((name (if (pair? pattern) (car pattern) pattern))) |
| 271 |
(if (not (symbol? name)) |
| 272 |
(scheme-error "Identifier expected" name)) |
| 273 |
name))) |
| 274 |
|
| 275 |
(define (definition-value expr) |
| 276 |
(let ((pattern (cadr expr))) |
| 277 |
(if (pair? pattern) |
| 278 |
(cons 'lambda (cons (cdr pattern) (cddr expr))) |
| 279 |
(caddr expr)))) |
| 280 |
|
| 281 |
; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 282 |
|
| 283 |
(define (comp-if expr env) |
| 284 |
(shape expr 3) |
| 285 |
(let ((code1 (scheme-comp (cadr expr) env)) |
| 286 |
(code2 (scheme-comp (caddr expr) env))) |
| 287 |
(if (pair? (cdddr expr)) |
| 288 |
(gen-if code1 code2 (scheme-comp (cadddr expr) env)) |
| 289 |
(gen-when code1 code2)))) |
| 290 |
|
| 291 |
; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 292 |
|
| 293 |
(define (comp-cond expr env) |
| 294 |
(comp-cond-aux (cdr expr) env)) |
| 295 |
|
| 296 |
(define (comp-cond-aux clauses env) |
| 297 |
(if (pair? clauses) |
| 298 |
(let ((clause (car clauses))) |
| 299 |
(shape clause 1) |
| 300 |
(cond ((eq? (car clause) 'else) |
| 301 |
(shape clause 2) |
| 302 |
(comp-sequence (cdr clause) env)) |
| 303 |
((not (pair? (cdr clause))) |
| 304 |
(gen-or (scheme-comp (car clause) env) |
| 305 |
(comp-cond-aux (cdr clauses) env))) |
| 306 |
((eq? (cadr clause) '=>) |
| 307 |
(shape clause 3) |
| 308 |
(gen-cond-send (scheme-comp (car clause) env) |
| 309 |
(scheme-comp (caddr clause) env) |
| 310 |
(comp-cond-aux (cdr clauses) env))) |
| 311 |
(else |
| 312 |
(gen-if (scheme-comp (car clause) env) |
| 313 |
(comp-sequence (cdr clause) env) |
| 314 |
(comp-cond-aux (cdr clauses) env))))) |
| 315 |
(gen-cst '()))) |
| 316 |
|
| 317 |
; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 318 |
|
| 319 |
(define (comp-and expr env) |
| 320 |
(let ((rest (cdr expr))) |
| 321 |
(if (pair? rest) (comp-and-aux rest env) (gen-cst #t)))) |
| 322 |
|
| 323 |
(define (comp-and-aux l env) |
| 324 |
(let ((code (scheme-comp (car l) env)) |
| 325 |
(rest (cdr l))) |
| 326 |
(if (pair? rest) (gen-and code (comp-and-aux rest env)) code))) |
| 327 |
|
| 328 |
; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 329 |
|
| 330 |
(define (comp-or expr env) |
| 331 |
(let ((rest (cdr expr))) |
| 332 |
(if (pair? rest) (comp-or-aux rest env) (gen-cst #f)))) |
| 333 |
|
| 334 |
(define (comp-or-aux l env) |
| 335 |
(let ((code (scheme-comp (car l) env)) |
| 336 |
(rest (cdr l))) |
| 337 |
(if (pair? rest) (gen-or code (comp-or-aux rest env)) code))) |
| 338 |
|
| 339 |
; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 340 |
|
| 341 |
(define (comp-case expr env) |
| 342 |
(shape expr 3) |
| 343 |
(gen-case (scheme-comp (cadr expr) env) |
| 344 |
(comp-case-aux (cddr expr) env))) |
| 345 |
|
| 346 |
(define (comp-case-aux clauses env) |
| 347 |
(if (pair? clauses) |
| 348 |
(let ((clause (car clauses))) |
| 349 |
(shape clause 2) |
| 350 |
(if (eq? (car clause) 'else) |
| 351 |
(gen-case-else (comp-sequence (cdr clause) env)) |
| 352 |
(gen-case-clause (car clause) |
| 353 |
(comp-sequence (cdr clause) env) |
| 354 |
(comp-case-aux (cdr clauses) env)))) |
| 355 |
(gen-case-else (gen-cst '())))) |
| 356 |
|
| 357 |
; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 358 |
|
| 359 |
(define (comp-let expr env) |
| 360 |
(shape expr 3) |
| 361 |
(let ((x (cadr expr))) |
| 362 |
(cond ((symbol? x) |
| 363 |
(shape expr 4) |
| 364 |
(let ((y (caddr expr))) |
| 365 |
(let ((proc (cons 'lambda (cons (bindings->vars y) (cdddr expr))))) |
| 366 |
(scheme-comp (cons (list 'letrec (list (list x proc)) x) |
| 367 |
(bindings->vals y)) |
| 368 |
env)))) |
| 369 |
((pair? x) |
| 370 |
(scheme-comp (cons (cons 'lambda (cons (bindings->vars x) (cddr expr))) |
| 371 |
(bindings->vals x)) |
| 372 |
env)) |
| 373 |
(else |
| 374 |
(comp-body (cddr expr) env))))) |
| 375 |
|
| 376 |
(define (bindings->vars bindings) |
| 377 |
(if (pair? bindings) |
| 378 |
(let ((binding (car bindings))) |
| 379 |
(shape binding 2) |
| 380 |
(let ((x (car binding))) |
| 381 |
(variable x) |
| 382 |
(cons x (bindings->vars (cdr bindings))))) |
| 383 |
'())) |
| 384 |
|
| 385 |
(define (bindings->vals bindings) |
| 386 |
(if (pair? bindings) |
| 387 |
(let ((binding (car bindings))) |
| 388 |
(cons (cadr binding) (bindings->vals (cdr bindings)))) |
| 389 |
'())) |
| 390 |
|
| 391 |
; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 392 |
|
| 393 |
(define (comp-let* expr env) |
| 394 |
(shape expr 3) |
| 395 |
(let ((bindings (cadr expr))) |
| 396 |
(if (pair? bindings) |
| 397 |
(scheme-comp (list 'let |
| 398 |
(list (car bindings)) |
| 399 |
(cons 'let* (cons (cdr bindings) (cddr expr)))) |
| 400 |
env) |
| 401 |
(comp-body (cddr expr) env)))) |
| 402 |
|
| 403 |
; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 404 |
|
| 405 |
(define (comp-letrec expr env) |
| 406 |
(shape expr 3) |
| 407 |
(let ((bindings (cadr expr))) |
| 408 |
(comp-letrec-aux (bindings->vars bindings) |
| 409 |
(bindings->vals bindings) |
| 410 |
(cddr expr) |
| 411 |
env))) |
| 412 |
|
| 413 |
(define (comp-letrec-aux vars vals body env) |
| 414 |
(if (pair? vars) |
| 415 |
(let ((new-env (push-frame vars env))) |
| 416 |
(gen-letrec (comp-vals vals new-env) |
| 417 |
(comp-body body new-env))) |
| 418 |
(comp-body body env))) |
| 419 |
|
| 420 |
(define (comp-vals l env) |
| 421 |
(if (pair? l) |
| 422 |
(cons (scheme-comp (car l) env) (comp-vals (cdr l) env)) |
| 423 |
'())) |
| 424 |
|
| 425 |
; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 426 |
|
| 427 |
(define (comp-begin expr env) |
| 428 |
(shape expr 2) |
| 429 |
(comp-sequence (cdr expr) env)) |
| 430 |
|
| 431 |
(define (comp-sequence exprs env) |
| 432 |
(if (pair? exprs) |
| 433 |
(comp-sequence-aux exprs env) |
| 434 |
(gen-cst '()))) |
| 435 |
|
| 436 |
(define (comp-sequence-aux exprs env) |
| 437 |
(let ((code (scheme-comp (car exprs) env)) |
| 438 |
(rest (cdr exprs))) |
| 439 |
(if (pair? rest) (gen-sequence code (comp-sequence-aux rest env)) code))) |
| 440 |
|
| 441 |
; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 442 |
|
| 443 |
(define (comp-do expr env) |
| 444 |
(shape expr 3) |
| 445 |
(let ((bindings (cadr expr)) |
| 446 |
(exit (caddr expr))) |
| 447 |
(shape exit 1) |
| 448 |
(let* ((vars (bindings->vars bindings)) |
| 449 |
(new-env1 (push-frame '(#f) env)) |
| 450 |
(new-env2 (push-frame vars new-env1))) |
| 451 |
(gen-letrec |
| 452 |
(list |
| 453 |
(gen-lambda |
| 454 |
(length vars) |
| 455 |
(gen-if |
| 456 |
(scheme-comp (car exit) new-env2) |
| 457 |
(comp-sequence (cdr exit) new-env2) |
| 458 |
(gen-sequence |
| 459 |
(comp-sequence (cdddr expr) new-env2) |
| 460 |
(gen-combination |
| 461 |
(gen-var-ref '(1 . 1)) |
| 462 |
(comp-vals (bindings->steps bindings) new-env2)))))) |
| 463 |
(gen-combination |
| 464 |
(gen-var-ref '(0 . 1)) |
| 465 |
(comp-vals (bindings->vals bindings) new-env1)))))) |
| 466 |
|
| 467 |
(define (bindings->steps bindings) |
| 468 |
(if (pair? bindings) |
| 469 |
(let ((binding (car bindings))) |
| 470 |
(cons (if (pair? (cddr binding)) (caddr binding) (car binding)) |
| 471 |
(bindings->steps (cdr bindings)))) |
| 472 |
'())) |
| 473 |
|
| 474 |
; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 475 |
|
| 476 |
(define (comp-define expr env) |
| 477 |
(shape expr 3) |
| 478 |
(let ((pattern (cadr expr))) |
| 479 |
(let ((x (if (pair? pattern) (car pattern) pattern))) |
| 480 |
(variable x) |
| 481 |
(gen-sequence |
| 482 |
(gen-var-set (lookup-var x env) |
| 483 |
(scheme-comp (if (pair? pattern) |
| 484 |
(cons 'lambda (cons (cdr pattern) (cddr expr))) |
| 485 |
(caddr expr)) |
| 486 |
env)) |
| 487 |
(gen-cst x))))) |
| 488 |
|
| 489 |
; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 490 |
|
| 491 |
(define (comp-define-macro expr env) |
| 492 |
(let ((x (definition-name expr))) |
| 493 |
(gen-macro x (scheme-eval (definition-value expr))))) |
| 494 |
|
| 495 |
; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 496 |
|
| 497 |
(define (comp-combination expr env) |
| 498 |
(gen-combination (scheme-comp (car expr) env) (comp-vals (cdr expr) env))) |
| 499 |
|
| 500 |
;------------------------------------------------------------------------------ |
| 501 |
|
| 502 |
(define (gen-var-ref var) |
| 503 |
(if (pair? var) |
| 504 |
(gen-rte-ref (car var) (cdr var)) |
| 505 |
(gen-glo-ref (scheme-global-var var)))) |
| 506 |
|
| 507 |
(define (gen-rte-ref up over) |
| 508 |
(case up |
| 509 |
((0) (gen-slot-ref-0 over)) |
| 510 |
((1) (gen-slot-ref-1 over)) |
| 511 |
(else (gen-slot-ref-up-2 (gen-rte-ref (- up 2) over))))) |
| 512 |
|
| 513 |
(define (gen-slot-ref-0 i) |
| 514 |
(case i |
| 515 |
((0) (lambda (rte) (vector-ref rte 0))) |
| 516 |
((1) (lambda (rte) (vector-ref rte 1))) |
| 517 |
((2) (lambda (rte) (vector-ref rte 2))) |
| 518 |
((3) (lambda (rte) (vector-ref rte 3))) |
| 519 |
(else (lambda (rte) (vector-ref rte i))))) |
| 520 |
|
| 521 |
(define (gen-slot-ref-1 i) |
| 522 |
(case i |
| 523 |
((0) (lambda (rte) (vector-ref (vector-ref rte 0) 0))) |
| 524 |
((1) (lambda (rte) (vector-ref (vector-ref rte 0) 1))) |
| 525 |
((2) (lambda (rte) (vector-ref (vector-ref rte 0) 2))) |
| 526 |
((3) (lambda (rte) (vector-ref (vector-ref rte 0) 3))) |
| 527 |
(else (lambda (rte) (vector-ref (vector-ref rte 0) i))))) |
| 528 |
|
| 529 |
(define (gen-slot-ref-up-2 code) |
| 530 |
(lambda (rte) (code (vector-ref (vector-ref rte 0) 0)))) |
| 531 |
|
| 532 |
(define (gen-glo-ref i) |
| 533 |
(lambda (rte) (scheme-global-var-ref i))) |
| 534 |
|
| 535 |
; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 536 |
|
| 537 |
(define (gen-cst val) |
| 538 |
(case val |
| 539 |
((()) (lambda (rte) '())) |
| 540 |
((#f) (lambda (rte) #f)) |
| 541 |
((#t) (lambda (rte) #t)) |
| 542 |
((-2) (lambda (rte) -2)) |
| 543 |
((-1) (lambda (rte) -1)) |
| 544 |
((0) (lambda (rte) 0)) |
| 545 |
((1) (lambda (rte) 1)) |
| 546 |
((2) (lambda (rte) 2)) |
| 547 |
(else (lambda (rte) val)))) |
| 548 |
|
| 549 |
; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 550 |
|
| 551 |
(define (gen-append-form code1 code2) |
| 552 |
(lambda (rte) (append (code1 rte) (code2 rte)))) |
| 553 |
|
| 554 |
(define (gen-cons-form code1 code2) |
| 555 |
(lambda (rte) (cons (code1 rte) (code2 rte)))) |
| 556 |
|
| 557 |
(define (gen-vector-form code) |
| 558 |
(lambda (rte) (lst->vector (code rte)))) |
| 559 |
|
| 560 |
; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 561 |
|
| 562 |
(define (gen-var-set var code) |
| 563 |
(if (pair? var) |
| 564 |
(gen-rte-set (car var) (cdr var) code) |
| 565 |
(gen-glo-set (scheme-global-var var) code))) |
| 566 |
|
| 567 |
(define (gen-rte-set up over code) |
| 568 |
(case up |
| 569 |
((0) (gen-slot-set-0 over code)) |
| 570 |
((1) (gen-slot-set-1 over code)) |
| 571 |
(else (gen-slot-set-n (gen-rte-ref (- up 2) 0) over code)))) |
| 572 |
|
| 573 |
(define (gen-slot-set-0 i code) |
| 574 |
(case i |
| 575 |
((0) (lambda (rte) (vector-set! rte 0 (code rte)))) |
| 576 |
((1) (lambda (rte) (vector-set! rte 1 (code rte)))) |
| 577 |
((2) (lambda (rte) (vector-set! rte 2 (code rte)))) |
| 578 |
((3) (lambda (rte) (vector-set! rte 3 (code rte)))) |
| 579 |
(else (lambda (rte) (vector-set! rte i (code rte)))))) |
| 580 |
|
| 581 |
(define (gen-slot-set-1 i code) |
| 582 |
(case i |
| 583 |
((0) (lambda (rte) (vector-set! (vector-ref rte 0) 0 (code rte)))) |
| 584 |
((1) (lambda (rte) (vector-set! (vector-ref rte 0) 1 (code rte)))) |
| 585 |
((2) (lambda (rte) (vector-set! (vector-ref rte 0) 2 (code rte)))) |
| 586 |
((3) (lambda (rte) (vector-set! (vector-ref rte 0) 3 (code rte)))) |
| 587 |
(else (lambda (rte) (vector-set! (vector-ref rte 0) i (code rte)))))) |
| 588 |
|
| 589 |
(define (gen-slot-set-n up i code) |
| 590 |
(case i |
| 591 |
((0) (lambda (rte) (vector-set! (up (vector-ref rte 0)) 0 (code rte)))) |
| 592 |
((1) (lambda (rte) (vector-set! (up (vector-ref rte 0)) 1 (code rte)))) |
| 593 |
((2) (lambda (rte) (vector-set! (up (vector-ref rte 0)) 2 (code rte)))) |
| 594 |
((3) (lambda (rte) (vector-set! (up (vector-ref rte 0)) 3 (code rte)))) |
| 595 |
(else (lambda (rte) (vector-set! (up (vector-ref rte 0)) i (code rte)))))) |
| 596 |
|
| 597 |
(define (gen-glo-set i code) |
| 598 |
(lambda (rte) (scheme-global-var-set! i (code rte)))) |
| 599 |
|
| 600 |
; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 601 |
|
| 602 |
(define (gen-lambda-rest nb-vars body) |
| 603 |
(case nb-vars |
| 604 |
((1) (gen-lambda-1-rest body)) |
| 605 |
((2) (gen-lambda-2-rest body)) |
| 606 |
((3) (gen-lambda-3-rest body)) |
| 607 |
(else (gen-lambda-n-rest nb-vars body)))) |
| 608 |
|
| 609 |
(define (gen-lambda-1-rest body) |
| 610 |
(lambda (rte) |
| 611 |
(lambda a |
| 612 |
(body (vector rte a))))) |
| 613 |
|
| 614 |
(define (gen-lambda-2-rest body) |
| 615 |
(lambda (rte) |
| 616 |
(lambda (a . b) |
| 617 |
(body (vector rte a b))))) |
| 618 |
|
| 619 |
(define (gen-lambda-3-rest body) |
| 620 |
(lambda (rte) |
| 621 |
(lambda (a b . c) |
| 622 |
(body (vector rte a b c))))) |
| 623 |
|
| 624 |
(define (gen-lambda-n-rest nb-vars body) |
| 625 |
(lambda (rte) |
| 626 |
(lambda (a b c . d) |
| 627 |
(let ((x (make-vector (+ nb-vars 1)))) |
| 628 |
(vector-set! x 0 rte) |
| 629 |
(vector-set! x 1 a) |
| 630 |
(vector-set! x 2 b) |
| 631 |
(vector-set! x 3 c) |
| 632 |
(let loop ((n nb-vars) (x x) (i 4) (l d)) |
| 633 |
(if (< i n) |
| 634 |
(begin (vector-set! x i (car l)) (loop n x (+ i 1) (cdr l))) |
| 635 |
(vector-set! x i l))) |
| 636 |
(body x))))) |
| 637 |
|
| 638 |
(define (gen-lambda nb-vars body) |
| 639 |
(case nb-vars |
| 640 |
((0) (gen-lambda-0 body)) |
| 641 |
((1) (gen-lambda-1 body)) |
| 642 |
((2) (gen-lambda-2 body)) |
| 643 |
((3) (gen-lambda-3 body)) |
| 644 |
(else (gen-lambda-n nb-vars body)))) |
| 645 |
|
| 646 |
(define (gen-lambda-0 body) |
| 647 |
(lambda (rte) |
| 648 |
(lambda () |
| 649 |
(body rte)))) |
| 650 |
|
| 651 |
(define (gen-lambda-1 body) |
| 652 |
(lambda (rte) |
| 653 |
(lambda (a) |
| 654 |
(body (vector rte a))))) |
| 655 |
|
| 656 |
(define (gen-lambda-2 body) |
| 657 |
(lambda (rte) |
| 658 |
(lambda (a b) |
| 659 |
(body (vector rte a b))))) |
| 660 |
|
| 661 |
(define (gen-lambda-3 body) |
| 662 |
(lambda (rte) |
| 663 |
(lambda (a b c) |
| 664 |
(body (vector rte a b c))))) |
| 665 |
|
| 666 |
(define (gen-lambda-n nb-vars body) |
| 667 |
(lambda (rte) |
| 668 |
(lambda (a b c . d) |
| 669 |
(let ((x (make-vector (+ nb-vars 1)))) |
| 670 |
(vector-set! x 0 rte) |
| 671 |
(vector-set! x 1 a) |
| 672 |
(vector-set! x 2 b) |
| 673 |
(vector-set! x 3 c) |
| 674 |
(let loop ((n nb-vars) (x x) (i 4) (l d)) |
| 675 |
(if (<= i n) |
| 676 |
(begin (vector-set! x i (car l)) (loop n x (+ i 1) (cdr l))))) |
| 677 |
(body x))))) |
| 678 |
|
| 679 |
; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 680 |
|
| 681 |
(define (gen-sequence code1 code2) |
| 682 |
(lambda (rte) (code1 rte) (code2 rte))) |
| 683 |
|
| 684 |
; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 685 |
|
| 686 |
(define (gen-when code1 code2) |
| 687 |
(lambda (rte) |
| 688 |
(if (code1 rte) |
| 689 |
(code2 rte) |
| 690 |
'()))) |
| 691 |
|
| 692 |
(define (gen-if code1 code2 code3) |
| 693 |
(lambda (rte) |
| 694 |
(if (code1 rte) |
| 695 |
(code2 rte) |
| 696 |
(code3 rte)))) |
| 697 |
|
| 698 |
; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 699 |
|
| 700 |
(define (gen-cond-send code1 code2 code3) |
| 701 |
(lambda (rte) |
| 702 |
(let ((temp (code1 rte))) |
| 703 |
(if temp |
| 704 |
((code2 rte) temp) |
| 705 |
(code3 rte))))) |
| 706 |
|
| 707 |
; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 708 |
|
| 709 |
(define (gen-and code1 code2) |
| 710 |
(lambda (rte) |
| 711 |
(let ((temp (code1 rte))) |
| 712 |
(if temp |
| 713 |
(code2 rte) |
| 714 |
temp)))) |
| 715 |
|
| 716 |
; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 717 |
|
| 718 |
(define (gen-or code1 code2) |
| 719 |
(lambda (rte) |
| 720 |
(let ((temp (code1 rte))) |
| 721 |
(if temp |
| 722 |
temp |
| 723 |
(code2 rte))))) |
| 724 |
|
| 725 |
; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 726 |
|
| 727 |
(define (gen-case code1 code2) |
| 728 |
(lambda (rte) (code2 rte (code1 rte)))) |
| 729 |
|
| 730 |
(define (gen-case-clause datums code1 code2) |
| 731 |
(lambda (rte key) (if (memv key datums) (code1 rte) (code2 rte key)))) |
| 732 |
|
| 733 |
(define (gen-case-else code) |
| 734 |
(lambda (rte key) (code rte))) |
| 735 |
|
| 736 |
; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 737 |
|
| 738 |
(define (gen-letrec vals body) |
| 739 |
(let ((nb-vals (length vals))) |
| 740 |
(case nb-vals |
| 741 |
((1) (gen-letrec-1 (car vals) body)) |
| 742 |
((2) (gen-letrec-2 (car vals) (cadr vals) body)) |
| 743 |
((3) (gen-letrec-3 (car vals) (cadr vals) (caddr vals) body)) |
| 744 |
(else (gen-letrec-n nb-vals vals body))))) |
| 745 |
|
| 746 |
(define (gen-letrec-1 val1 body) |
| 747 |
(lambda (rte) |
| 748 |
(let ((x (vector rte #f))) |
| 749 |
(vector-set! x 1 (val1 x)) |
| 750 |
(body x)))) |
| 751 |
|
| 752 |
(define (gen-letrec-2 val1 val2 body) |
| 753 |
(lambda (rte) |
| 754 |
(let ((x (vector rte #f #f))) |
| 755 |
(vector-set! x 1 (val1 x)) |
| 756 |
(vector-set! x 2 (val2 x)) |
| 757 |
(body x)))) |
| 758 |
|
| 759 |
(define (gen-letrec-3 val1 val2 val3 body) |
| 760 |
(lambda (rte) |
| 761 |
(let ((x (vector rte #f #f #f))) |
| 762 |
(vector-set! x 1 (val1 x)) |
| 763 |
(vector-set! x 2 (val2 x)) |
| 764 |
(vector-set! x 3 (val3 x)) |
| 765 |
(body x)))) |
| 766 |
|
| 767 |
(define (gen-letrec-n nb-vals vals body) |
| 768 |
(lambda (rte) |
| 769 |
(let ((x (make-vector (+ nb-vals 1)))) |
| 770 |
(vector-set! x 0 rte) |
| 771 |
(let loop ((x x) (i 1) (l vals)) |
| 772 |
(if (pair? l) |
| 773 |
(begin (vector-set! x i ((car l) x)) (loop x (+ i 1) (cdr l))))) |
| 774 |
(body x)))) |
| 775 |
|
| 776 |
; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 777 |
|
| 778 |
(define (gen-macro name proc) |
| 779 |
(lambda (rte) (scheme-add-macro name proc))) |
| 780 |
|
| 781 |
; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 782 |
|
| 783 |
(define (gen-combination oper args) |
| 784 |
(case (length args) |
| 785 |
((0) (gen-combination-0 oper)) |
| 786 |
((1) (gen-combination-1 oper (car args))) |
| 787 |
((2) (gen-combination-2 oper (car args) (cadr args))) |
| 788 |
((3) (gen-combination-3 oper (car args) (cadr args) (caddr args))) |
| 789 |
(else (gen-combination-n oper args)))) |
| 790 |
|
| 791 |
(define (gen-combination-0 oper) |
| 792 |
(lambda (rte) ((oper rte)))) |
| 793 |
|
| 794 |
(define (gen-combination-1 oper arg1) |
| 795 |
(lambda (rte) ((oper rte) (arg1 rte)))) |
| 796 |
|
| 797 |
(define (gen-combination-2 oper arg1 arg2) |
| 798 |
(lambda (rte) ((oper rte) (arg1 rte) (arg2 rte)))) |
| 799 |
|
| 800 |
(define (gen-combination-3 oper arg1 arg2 arg3) |
| 801 |
(lambda (rte) ((oper rte) (arg1 rte) (arg2 rte) (arg3 rte)))) |
| 802 |
|
| 803 |
(define (gen-combination-n oper args) |
| 804 |
(lambda (rte) |
| 805 |
(define (evaluate l rte) |
| 806 |
(if (pair? l) |
| 807 |
(cons ((car l) rte) (evaluate (cdr l) rte)) |
| 808 |
'())) |
| 809 |
(apply (oper rte) (evaluate args rte)))) |
| 810 |
|
| 811 |
; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 812 |
|
| 813 |
(define (scheme-comp expr env) |
| 814 |
(cond ((symbol? expr) |
| 815 |
(comp-var expr env)) |
| 816 |
((not (pair? expr)) |
| 817 |
(comp-self-eval expr env)) |
| 818 |
((macro? (car expr) env) |
| 819 |
(scheme-comp (macro-expand expr env) env)) |
| 820 |
(else |
| 821 |
(cond |
| 822 |
((eq? (car expr) 'quote) (comp-quote expr env)) |
| 823 |
((eq? (car expr) 'quasiquote) (comp-quasiquote expr env)) |
| 824 |
((eq? (car expr) 'unquote) (comp-unquote expr env)) |
| 825 |
((eq? (car expr) 'unquote-splicing) (comp-unquote-splicing expr env)) |
| 826 |
((eq? (car expr) 'set!) (comp-set! expr env)) |
| 827 |
((eq? (car expr) 'lambda) (comp-lambda expr env)) |
| 828 |
((eq? (car expr) 'if) (comp-if expr env)) |
| 829 |
((eq? (car expr) 'cond) (comp-cond expr env)) |
| 830 |
((eq? (car expr) 'and) (comp-and expr env)) |
| 831 |
((eq? (car expr) 'or) (comp-or expr env)) |
| 832 |
((eq? (car expr) 'case) (comp-case expr env)) |
| 833 |
((eq? (car expr) 'let) (comp-let expr env)) |
| 834 |
((eq? (car expr) 'let*) (comp-let* expr env)) |
| 835 |
((eq? (car expr) 'letrec) (comp-letrec expr env)) |
| 836 |
((eq? (car expr) 'begin) (comp-begin expr env)) |
| 837 |
((eq? (car expr) 'do) (comp-do expr env)) |
| 838 |
((eq? (car expr) 'define) (comp-define expr env)) |
| 839 |
((eq? (car expr) 'define-macro) (comp-define-macro expr env)) |
| 840 |
(else (comp-combination expr env)))))) |
| 841 |
|
| 842 |
; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 843 |
|
| 844 |
(define (scheme-global-var name) |
| 845 |
(let ((x (assq name scheme-global-variables))) |
| 846 |
(if x |
| 847 |
x |
| 848 |
(let ((y (cons name '()))) |
| 849 |
(set! scheme-global-variables (cons y scheme-global-variables)) |
| 850 |
y)))) |
| 851 |
|
| 852 |
(define (scheme-global-var-ref i) |
| 853 |
(cdr i)) |
| 854 |
|
| 855 |
(define (scheme-global-var-set! i val) |
| 856 |
(set-cdr! i val) |
| 857 |
'()) |
| 858 |
|
| 859 |
(define scheme-global-variables '()) |
| 860 |
|
| 861 |
(define (def-proc name value) |
| 862 |
(scheme-global-var-set! |
| 863 |
(scheme-global-var name) |
| 864 |
value)) |
| 865 |
|
| 866 |
|
| 867 |
(define (main . args) |
| 868 |
(run-benchmark |
| 869 |
"scheme" |
| 870 |
scheme-iters |
| 871 |
(lambda (result) |
| 872 |
(equal? result |
| 873 |
'("eight" "eleven" "five" "four" "nine" "one" |
| 874 |
"seven" "six" "ten" "three" "twelve" "two"))) |
| 875 |
(lambda (expr) (lambda () (scheme-eval expr))) |
| 876 |
'(let () |
| 877 |
|
| 878 |
(define (sort-list obj pred) |
| 879 |
|
| 880 |
(define (loop l) |
| 881 |
(if (and (pair? l) (pair? (cdr l))) |
| 882 |
(split l '() '()) |
| 883 |
l)) |
| 884 |
|
| 885 |
(define (split l one two) |
| 886 |
(if (pair? l) |
| 887 |
(split (cdr l) two (cons (car l) one)) |
| 888 |
(merge (loop one) (loop two)))) |
| 889 |
|
| 890 |
(define (merge one two) |
| 891 |
(cond ((null? one) two) |
| 892 |
((pred (car two) (car one)) |
| 893 |
(cons (car two) |
| 894 |
(merge (cdr two) one))) |
| 895 |
(else |
| 896 |
(cons (car one) |
| 897 |
(merge (cdr one) two))))) |
| 898 |
|
| 899 |
(loop obj)) |
| 900 |
|
| 901 |
(sort-list '("one" "two" "three" "four" "five" "six" |
| 902 |
"seven" "eight" "nine" "ten" "eleven" "twelve") |
| 903 |
string<?)))) |
| 904 |
|
| 905 |
|
| 906 |
(def-proc 'not (lambda (x) (not x))) |
| 907 |
(def-proc 'boolean? boolean?) |
| 908 |
(def-proc 'eqv? eqv?) |
| 909 |
(def-proc 'eq? eq?) |
| 910 |
(def-proc 'equal? equal?) |
| 911 |
(def-proc 'pair? (lambda (obj) (pair? obj))) |
| 912 |
(def-proc 'cons (lambda (x y) (cons x y))) |
| 913 |
(def-proc 'car (lambda (x) (car x))) |
| 914 |
(def-proc 'cdr (lambda (x) (cdr x))) |
| 915 |
(def-proc 'set-car! set-car!) |
| 916 |
(def-proc 'set-cdr! set-cdr!) |
| 917 |
(def-proc 'caar caar) |
| 918 |
(def-proc 'cadr cadr) |
| 919 |
(def-proc 'cdar cdar) |
| 920 |
(def-proc 'cddr cddr) |
| 921 |
(def-proc 'caaar caaar) |
| 922 |
(def-proc 'caadr caadr) |
| 923 |
(def-proc 'cadar cadar) |
| 924 |
(def-proc 'caddr caddr) |
| 925 |
(def-proc 'cdaar cdaar) |
| 926 |
(def-proc 'cdadr cdadr) |
| 927 |
(def-proc 'cddar cddar) |
| 928 |
(def-proc 'cdddr cdddr) |
| 929 |
(def-proc 'caaaar caaaar) |
| 930 |
(def-proc 'caaadr caaadr) |
| 931 |
(def-proc 'caadar caadar) |
| 932 |
(def-proc 'caaddr caaddr) |
| 933 |
(def-proc 'cadaar cadaar) |
| 934 |
(def-proc 'cadadr cadadr) |
| 935 |
(def-proc 'caddar caddar) |
| 936 |
(def-proc 'cadddr cadddr) |
| 937 |
(def-proc 'cdaaar cdaaar) |
| 938 |
(def-proc 'cdaadr cdaadr) |
| 939 |
(def-proc 'cdadar cdadar) |
| 940 |
(def-proc 'cdaddr cdaddr) |
| 941 |
(def-proc 'cddaar cddaar) |
| 942 |
(def-proc 'cddadr cddadr) |
| 943 |
(def-proc 'cdddar cdddar) |
| 944 |
(def-proc 'cddddr cddddr) |
| 945 |
(def-proc 'null? (lambda (x) (null? x))) |
| 946 |
(def-proc 'list? list?) |
| 947 |
(def-proc 'list list) |
| 948 |
(def-proc 'length length) |
| 949 |
(def-proc 'append append) |
| 950 |
(def-proc 'reverse reverse) |
| 951 |
(def-proc 'list-ref list-ref) |
| 952 |
(def-proc 'memq memq) |
| 953 |
(def-proc 'memv memv) |
| 954 |
(def-proc 'member member) |
| 955 |
(def-proc 'assq assq) |
| 956 |
(def-proc 'assv assv) |
| 957 |
(def-proc 'assoc assoc) |
| 958 |
(def-proc 'symbol? symbol?) |
| 959 |
(def-proc 'symbol->string symbol->string) |
| 960 |
(def-proc 'string->symbol string->symbol) |
| 961 |
(def-proc 'number? number?) |
| 962 |
(def-proc 'complex? complex?) |
| 963 |
(def-proc 'real? real?) |
| 964 |
(def-proc 'rational? rational?) |
| 965 |
(def-proc 'integer? integer?) |
| 966 |
(def-proc 'exact? exact?) |
| 967 |
(def-proc 'inexact? inexact?) |
| 968 |
;(def-proc '= =) |
| 969 |
;(def-proc '< <) |
| 970 |
;(def-proc '> >) |
| 971 |
;(def-proc '<= <=) |
| 972 |
;(def-proc '>= >=) |
| 973 |
;(def-proc 'zero? zero?) |
| 974 |
;(def-proc 'positive? positive?) |
| 975 |
;(def-proc 'negative? negative?) |
| 976 |
;(def-proc 'odd? odd?) |
| 977 |
;(def-proc 'even? even?) |
| 978 |
(def-proc 'max max) |
| 979 |
(def-proc 'min min) |
| 980 |
;(def-proc '+ +) |
| 981 |
;(def-proc '* *) |
| 982 |
;(def-proc '- -) |
| 983 |
(def-proc '/ /) |
| 984 |
(def-proc 'abs abs) |
| 985 |
;(def-proc 'quotient quotient) |
| 986 |
;(def-proc 'remainder remainder) |
| 987 |
;(def-proc 'modulo modulo) |
| 988 |
(def-proc 'gcd gcd) |
| 989 |
(def-proc 'lcm lcm) |
| 990 |
;(def-proc 'numerator numerator) |
| 991 |
;(def-proc 'denominator denominator) |
| 992 |
(def-proc 'floor floor) |
| 993 |
(def-proc 'ceiling ceiling) |
| 994 |
(def-proc 'truncate truncate) |
| 995 |
(def-proc 'round round) |
| 996 |
;(def-proc 'rationalize rationalize) |
| 997 |
(def-proc 'exp exp) |
| 998 |
(def-proc 'log log) |
| 999 |
(def-proc 'sin sin) |
| 1000 |
(def-proc 'cos cos) |
| 1001 |
(def-proc 'tan tan) |
| 1002 |
(def-proc 'asin asin) |
| 1003 |
(def-proc 'acos acos) |
| 1004 |
(def-proc 'atan atan) |
| 1005 |
(def-proc 'sqrt sqrt) |
| 1006 |
(def-proc 'expt expt) |
| 1007 |
;(def-proc 'make-rectangular make-rectangular) |
| 1008 |
;(def-proc 'make-polar make-polar) |
| 1009 |
;(def-proc 'real-part real-part) |
| 1010 |
;(def-proc 'imag-part imag-part) |
| 1011 |
;(def-proc 'magnitude magnitude) |
| 1012 |
;(def-proc 'angle angle) |
| 1013 |
(def-proc 'exact->inexact exact->inexact) |
| 1014 |
(def-proc 'inexact->exact inexact->exact) |
| 1015 |
(def-proc 'number->string number->string) |
| 1016 |
(def-proc 'string->number string->number) |
| 1017 |
(def-proc 'char? char?) |
| 1018 |
(def-proc 'char=? char=?) |
| 1019 |
(def-proc 'char<? char<?) |
| 1020 |
(def-proc 'char>? char>?) |
| 1021 |
(def-proc 'char<=? char<=?) |
| 1022 |
(def-proc 'char>=? char>=?) |
| 1023 |
(def-proc 'char-ci=? char-ci=?) |
| 1024 |
(def-proc 'char-ci<? char-ci<?) |
| 1025 |
(def-proc 'char-ci>? char-ci>?) |
| 1026 |
(def-proc 'char-ci<=? char-ci<=?) |
| 1027 |
(def-proc 'char-ci>=? char-ci>=?) |
| 1028 |
(def-proc 'char-alphabetic? char-alphabetic?) |
| 1029 |
(def-proc 'char-numeric? char-numeric?) |
| 1030 |
(def-proc 'char-whitespace? char-whitespace?) |
| 1031 |
(def-proc 'char-lower-case? char-lower-case?) |
| 1032 |
(def-proc 'char->integer char->integer) |
| 1033 |
(def-proc 'integer->char integer->char) |
| 1034 |
(def-proc 'char-upcase char-upcase) |
| 1035 |
(def-proc 'char-downcase char-downcase) |
| 1036 |
(def-proc 'string? string?) |
| 1037 |
(def-proc 'make-string make-string) |
| 1038 |
(def-proc 'string string) |
| 1039 |
(def-proc 'string-length string-length) |
| 1040 |
(def-proc 'string-ref string-ref) |
| 1041 |
(def-proc 'string-set! string-set!) |
| 1042 |
(def-proc 'string=? string=?) |
| 1043 |
(def-proc 'string<? string<?) |
| 1044 |
(def-proc 'string>? string>?) |
| 1045 |
(def-proc 'string<=? string<=?) |
| 1046 |
(def-proc 'string>=? string>=?) |
| 1047 |
(def-proc 'string-ci=? string-ci=?) |
| 1048 |
(def-proc 'string-ci<? string-ci<?) |
| 1049 |
(def-proc 'string-ci>? string-ci>?) |
| 1050 |
(def-proc 'string-ci<=? string-ci<=?) |
| 1051 |
(def-proc 'string-ci>=? string-ci>=?) |
| 1052 |
(def-proc 'substring substring) |
| 1053 |
(def-proc 'string-append string-append) |
| 1054 |
(def-proc 'vector? vector?) |
| 1055 |
(def-proc 'make-vector make-vector) |
| 1056 |
(def-proc 'vector vector) |
| 1057 |
(def-proc 'vector-length vector-length) |
| 1058 |
(def-proc 'vector-ref vector-ref) |
| 1059 |
(def-proc 'vector-set! vector-set!) |
| 1060 |
(def-proc 'procedure? procedure?) |
| 1061 |
(def-proc 'apply apply) |
| 1062 |
(def-proc 'map map) |
| 1063 |
(def-proc 'for-each for-each) |
| 1064 |
;(def-proc 'call-with-current-continuation call-with-current-continuation) |
| 1065 |
(def-proc 'call-with-input-file call-with-input-file) |
| 1066 |
(def-proc 'call-with-output-file call-with-output-file) |
| 1067 |
(def-proc 'input-port? input-port?) |
| 1068 |
(def-proc 'output-port? output-port?) |
| 1069 |
(def-proc 'current-input-port current-input-port) |
| 1070 |
(def-proc 'current-output-port current-output-port) |
| 1071 |
(def-proc 'open-input-file open-input-file) |
| 1072 |
(def-proc 'open-output-file open-output-file) |
| 1073 |
(def-proc 'close-input-port close-input-port) |
| 1074 |
(def-proc 'close-output-port close-output-port) |
| 1075 |
(def-proc 'eof-object? eof-object?) |
| 1076 |
(def-proc 'read read) |
| 1077 |
(def-proc 'read-char read-char) |
| 1078 |
(def-proc 'peek-char peek-char) |
| 1079 |
(def-proc 'write write) |
| 1080 |
(def-proc 'display display) |
| 1081 |
(def-proc 'newline newline) |
| 1082 |
(def-proc 'write-char write-char) |
| 1083 |
|
| 1084 |
; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
| 1085 |
|
| 1086 |
) |