blob_id
stringlengths
40
40
directory_id
stringlengths
40
40
path
stringlengths
3
171
content_id
stringlengths
40
40
detected_licenses
sequencelengths
0
8
license_type
stringclasses
2 values
repo_name
stringlengths
6
82
snapshot_id
stringlengths
40
40
revision_id
stringlengths
40
40
branch_name
stringclasses
13 values
visit_date
timestamp[ns]
revision_date
timestamp[ns]
committer_date
timestamp[ns]
github_id
int64
1.59k
594M
star_events_count
int64
0
77.1k
fork_events_count
int64
0
33.7k
gha_license_id
stringclasses
12 values
gha_event_created_at
timestamp[ns]
gha_created_at
timestamp[ns]
gha_language
stringclasses
46 values
src_encoding
stringclasses
14 values
language
stringclasses
2 values
is_vendor
bool
2 classes
is_generated
bool
1 class
length_bytes
int64
4
7.87M
extension
stringclasses
101 values
filename
stringlengths
2
149
content
stringlengths
4
7.87M
has_macro_def
bool
2 classes
0f80c1a8c5d0b2219e65ca295d6c67e8e826977f
cf8c6fe3a289f26b8c0cca1281cbf89a14985064
/racketwork/schememacros.scm
dff611e79b5449290a2c9b5bf499a9ccb489969f
[]
no_license
chetnashah/emacs-lisp-practice-work
3c9bf47eefe77ebd3b6511593ba1dea7d3732db3
ec6ec1cbe6516017d107f3d1f766bca76ec3680b
refs/heads/master
2020-12-27T12:13:35.757655
2020-09-02T04:55:15
2020-09-02T04:55:15
68,783,499
2
0
null
null
null
null
UTF-8
Scheme
false
false
851
scm
schememacros.scm
;; -*- geiser-scheme-implementation: guile -*- ;; http://www.shido.info/lisp/scheme_syntax_e.html ;; define-syntax + syntax-rules ;; At any places () can be replaced by [] as you wish ;; e.g. [[lambda [x] [* x x]] 10] will give answer 100 (define-syntax nil! (syntax-rules () [(_ x) (set! x '())])) ;; the general syntax can be shown as ;; (define-syntax id ;; (syntax-rules (literal-id ...) ;; [pattern template] ;; [pattern2 template2] ;; ...)) (define-syntax incf (syntax-rules () [(_ x) (begin (set! x (+ x 1)) x)] [(_ x i) (begin (set! x (+ x i)) x)] )) (define bb 1) (incf bb) (display bb) (incf bb 11) (display bb) ;; lets play some more (define-syntax kwote (syntax-rules () [(kwote exp1) (quote exp1)])) ;; (kwote (foo bar)) will not evaluate foo ;; see recursive definition of macros
true
e3107561060802c694af2b16a2c4de2d9d02a4d2
4b2aeafb5610b008009b9f4037d42c6e98f8ea73
/6/6-3.scm
4b484561c5d5d954952f494db983fa2f33872332
[]
no_license
mrinalabrol/clrs
cd461d1a04e6278291f6555273d709f48e48de9c
f85a8f0036f0946c9e64dde3259a19acc62b74a1
refs/heads/master
2021-01-17T23:47:45.261326
2010-09-29T00:43:32
2010-09-29T00:43:32
null
0
0
null
null
null
null
UTF-8
Scheme
false
false
1,567
scm
6-3.scm
(require-extension syntax-case check) (require '../6/chapter) (import chapter-6) (let ((data '(10 2 4 7 8 3 5 6 9 +inf.0 +inf.0 +inf.0 +inf.0 +inf.0 +inf.0))) (check (tableau-data (tableauify (make-tableau 3 5 data) 0)) => '(2 4 6 7 8 3 5 9 10 +inf +inf +inf +inf +inf +inf))) (let ((data '(1 2 4 7 8 3 5 6 9 +inf.0 10 +inf.0 +inf.0 +inf.0 +inf.0))) (check (tableau-max-index (make-tableau 3 5 data)) => 10)) (let* ((data '(1 2 4 7 8 3 5 6 9 +inf.0 10 +inf.0 +inf.0 +inf.0 +inf.0)) (tableau (make-tableau 3 5 data))) (let ((min (tableau-extract-min tableau))) (check min => 1) (check (tableau-data tableau) => '(2 4 6 7 8 3 5 9 10 +inf +inf +inf +inf +inf +inf)))) (let* ((data '(1 2 4 7 8 3 5 6 9 +inf.0 10 +inf.0 +inf.0 +inf.0 +inf.0)) (tableau (make-tableau 3 5 data))) (check (tableau-data (tableau-insert tableau 0)) => '(0 1 2 4 8 3 5 6 7 9 10 +inf +inf +inf +inf))) (let* ((data '(1 2 4 7 8 3 5 6 9 +inf.0 10 +inf.0 +inf.0 +inf.0 +inf.0)) (tableau (make-tableau 3 5 data))) (check (tableau-sort tableau) => '(10 9 8 7 6 5 4 3 2 1))) (let* ((data '(1 2 4 7 8 3 5 6 9 +inf.0 10 +inf.0 +inf.0 +inf.0 +inf.0)) (tableau (make-tableau 3 5 data))) (check (tableau-search tableau 7) => #t) (check (tableau-search tableau 11) => #f))
false
7ec76da06d85388a624ca631b349970f07d0701e
47457420b9a1eddf69e2b2f426570567258f3afd
/3/22.scm
5dfe66b46829e2634f2032968500761a4bb84525
[]
no_license
adromaryn/sicp
797496916620e85b8d85760dc3f5739c4cc63437
342b56d233cc309ffb59dd13b2d3cf9cd22af6c9
refs/heads/master
2021-08-30T06:55:04.560128
2021-08-29T12:47:28
2021-08-29T12:47:28
162,965,433
0
0
null
null
null
null
UTF-8
Scheme
false
false
1,832
scm
22.scm
#lang sicp (define (make-queue) (let ((front-ptr '()) (rear-ptr '())) (begin (define (set-front-ptr! item) (set! front-ptr item)) (define (set-rear-ptr! item) (set! rear-ptr item)) (define (empty-queue?) (null? front-ptr)) (define (front-queue?) (if (empty-queue?) (error "FRONT вызвана с пустой очередью") (car front-ptr))) (define (insert-queue! item) (let ((new-pair (cons item '()))) (cond ((empty-queue?) (set-front-ptr! new-pair) (set-rear-ptr! new-pair) dispatch) (else (set-cdr! rear-ptr new-pair) (set-rear-ptr! new-pair) dispatch)))) (define (delete-queue!) (if (empty-queue?) (error "DELETE! вызвана с пустой очередью") (let ((pop-elem (car front-ptr))) (set-front-ptr! (cdr front-ptr)) pop-elem))) (define (print-queue) (define (iter tail) (if (null? tail) (newline) (begin (display (car tail)) (display "; ") (iter (cdr tail))))) (display "queue | ") (iter front-ptr)) (define (dispatch m . args) (cond ((eq? m 'insert!) (insert-queue! (car args))) ((eq? m 'delete!) (delete-queue!)) ((eq? m 'empty?) (empty-queue?)) ((eq? m 'print) (print-queue)) (else (error "DISPATCH неверное имя метода" m)))) dispatch))) (define q2 (make-queue)) (q2 'print) (q2 'insert! 'a) (q2 'print) (q2 'insert! 'b) (q2 'print) (q2 'delete!) (q2 'print) (q2 'delete!) (q2 'print) (q2 'insert! 'a) (q2 'print)
false
ac92b3d4b08ef5e2e2c345550208322b19e18f3d
9b2eb10c34176f47f7f490a4ce8412b7dd42cce7
/lib/yuniapp/tmpl/cmdline.sls
6a20e8267dd3799770d25bb394983f0d480c761e
[ "LicenseRef-scancode-public-domain", "CC0-1.0" ]
permissive
okuoku/yuni
8be584a574c0597375f023c70b17a5a689fd6918
1859077a3c855f3a3912a71a5283e08488e76661
refs/heads/master
2023-07-21T11:30:14.824239
2023-06-11T13:16:01
2023-07-18T16:25:22
17,772,480
36
6
CC0-1.0
2020-03-29T08:16:00
2014-03-15T09:53:13
Scheme
UTF-8
Scheme
false
false
3,486
sls
cmdline.sls
(library (yuniapp tmpl cmdline) (export cmdline-sh cmdline-win32) (import (yuni scheme) (yuniconfig build)) (define (params sep l) (define (itr acc l) (if (pair? l) (let ((a (car l))) (itr (string-append acc sep a) (cdr l)) ) acc)) (if (pair? l) (itr (car l) (cdr l)) "")) (define (%gen-libs0 param l) (define (itr acc l) (if (pair? l) (let ((a (car l))) (itr (string-append acc " " param a) (cdr l))) acc)) (if (pair? l) (itr (string-append param (car l)) (cdr l)) "")) (define (gen-libs/nospace param l) (%gen-libs0 param l)) (define (gen-libs param l) (%gen-libs0 (string-append param " ") l)) (define (gen-pathsep pathsep l) (define (itr acc l) (if (pair? l) (let ((a (car l))) (itr (string-append acc pathsep a) (cdr l))) acc)) (if (pair? l) (itr (car l) (cdr l)) "")) (define (quote-exec pth) (string-append "\"" pth "\"")) (define (mapgen sym) (case sym ((gauche) "gosh") ((chez) "chez-scheme") (else (symbol->string sym)))) (define (invoke-cmd win32? impl loaderroot libpaths progpath initargs) (define cmd (quote-exec (yuniconfig-executable-path impl))) (define runtime (yuniconfig-runtime-rootpath)) (define platform (yuniconfig-platform)) (define all-libpaths (cons (string-append runtime "/" (symbol->string impl)) libpaths)) (define args (params " " initargs)) (define pathsep (if win32? ";" ":")) (case impl ((guile) (string-append cmd " " (gen-libs "-L" all-libpaths) " " progpath args)) ((vicare) (string-append cmd " " (gen-libs "--source-path" all-libpaths) " --r6rs-script " progpath " -- " args)) ((chez) (string-append cmd " --libdirs " (gen-pathsep pathsep all-libpaths) " --program " progpath args)) ((sagittarius) (string-append cmd " " (gen-libs/nospace "--loadpath=" all-libpaths) " " progpath args)) ((chibi-scheme) (string-append cmd " " (gen-libs "-I" all-libpaths) " " progpath args)) ((racket) (string-append cmd " -I scheme/init -l- r6rs/run.rkt " (gen-libs "++path" all-libpaths) " " progpath args)) ((gauche) (string-append cmd " " (gen-libs "-I" all-libpaths) " " progpath args)) (else (error "Unknown implementation" impl)))) (define (cmdline-win32 impl loaderroot approot libpaths progpath initargs) (define cmdraw (invoke-cmd #t impl loaderroot libpaths progpath initargs)) (define genscr (string-append "gen-" (mapgen impl) ".bat")) (string-append "@echo off\n\n" loaderroot "/../" genscr " " approot " && " cmdraw " %*\n")) (define (cmdline-sh impl loaderroot approot libpaths progpath initargs) (define cmdraw (invoke-cmd #f impl loaderroot libpaths progpath initargs)) (define genscr (string-append "gen-" (mapgen impl))) (string-append "#!/bin/sh\n\n" loaderroot "/../" genscr " " approot " && " "exec " cmdraw " $*\n")) )
false
9c8946d2c3f8aae67d403c312d01b5ad55d37312
648776d3a0d9a8ca036acaf6f2f7a60dcdb45877
/queries/thrift/locals.scm
d95cc5da1d0c906e65abda22e6503debb2028613
[ "Apache-2.0" ]
permissive
nvim-treesitter/nvim-treesitter
4c3c55cbe6ff73debcfaecb9b7a0d42d984be3e6
f8c2825220bff70919b527ee68fe44e7b1dae4b2
refs/heads/master
2023-08-31T20:04:23.790698
2023-08-31T09:28:16
2023-08-31T18:19:23
256,786,531
7,890
980
Apache-2.0
2023-09-14T18:07:03
2020-04-18T15:24:10
Scheme
UTF-8
Scheme
false
false
986
scm
locals.scm
; Scopes [ (document) (definition) ] @scope ; References (identifier) @reference ; Definitions (annotation_identifier) @definition (const_definition (identifier) @definition.constant) (enum_definition "enum" . (identifier) @definition.enum "{" (identifier) @definition.constant "}") (senum_definition "senum" . (identifier) @definition.enum) (field (identifier) @definition.field) (function_definition (identifier) @definition.function) (namespace_declaration "namespace" (namespace_scope) . (_) @definition.namespace (namespace_uri)?) (parameter (identifier) @definition.parameter) (struct_definition "struct" . (identifier) @definition.type) (union_definition "union" . (identifier) @definition.type) (exception_definition "exception" . (identifier) @definition.type) (service_definition "service" . (identifier) @definition.type) (interaction_definition "interaction" . (identifier) @definition.type) (typedef_identifier) @definition.type
false
82c700f5714a8590f70595f3438f811cd159a878
957ca548c81c2c047ef82cdbf11b7b2b77a3130b
/02LAB/02_lab_5.scm
bdfa1542f9fb40df1a0aa0c6389f4776e59e6a98
[]
no_license
emrzvv/Scheme
943d4a55c5703f0e1318ae65aec24d0cb57e3372
e6ae1ed19104f46d22eee2afabea5459f7031a22
refs/heads/master
2023-02-19T08:55:29.470491
2021-01-18T12:56:26
2021-01-18T12:56:26
318,609,955
4
0
null
null
null
null
UTF-8
Scheme
false
false
234
scm
02_lab_5.scm
(define (any? pred? xs) (or (and (not (null? xs)) (pred? (car xs))) (and (not (null? xs)) (any? pred? (cdr xs))))) (define (all? pred? xs) (and (or (null? xs) (pred? (car xs))) (or (null? xs) (all? pred? (cdr xs)))))
false
293d54acc76577adf9e7e1556f272ed7d1a79eb0
a7041c38e194a48f5671f00bf418d9f68a607812
/posix-extras.setup
4154f0674791e786529e544f65922dd764efb0f5
[ "MIT" ]
permissive
dhess/posix-extras-egg
e2f9a8bbe8189aa975f9b1a9fc245b2a5dd96d7f
cfe3d7aa6f9e7ed7755c2bec2252edce88210fb8
refs/heads/master
2020-04-22T00:28:23.958086
2011-02-20T01:40:37
2011-02-20T01:40:37
133,710
1
0
null
null
null
null
UTF-8
Scheme
false
false
348
setup
posix-extras.setup
;;; posix-extras.setup -*- scheme -*- (compile -s -O3 -d1 "posix-extras.scm" -j posix-extras) (compile -c -O3 -d1 "posix-extras.scm" -unit posix-extras) (compile -s -O3 -d0 "posix-extras.import.scm") (install-extension 'posix-extras '("posix-extras.o" "posix-extras.so" "posix-extras.import.so") '((version 0.2) (static "posix-extras.o")))
false
7ab2c8d883114744f96e6786a7ee3d0e46a4648f
5c9a35acae188fc2d694abfe90ecee9f00fa3202
/ssax.sls
2678e1280257d71388648714fe0c2cb17d5c8d06
[]
no_license
enjelbeteu/oleg
ae21c0e9878057fa21e0139881cbdc33a794240b
c6826870436925fd4c873c01d7fcc24a7a7f95dc
refs/heads/master
2020-12-30T09:15:03.536388
2010-03-09T04:13:54
2010-03-09T04:13:54
null
0
0
null
null
null
null
UTF-8
Scheme
false
false
2,306
sls
ssax.sls
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; R6RS Wrapper for Oleg's SSAX Code ;;; ;;; Copyright (c) 2009 Aaron W. Hsu <[email protected]> ;;; ;;; Permission to use, copy, modify, and distribute this software for ;;; any purpose with or without fee is hereby granted, provided that the ;;; above copyright notice and this permission notice appear in all ;;; copies. ;;; ;;; THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL ;;; WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED ;;; WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE ;;; AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL ;;; DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA ;;; OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER ;;; TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR ;;; PERFORMANCE OF THIS SOFTWARE. (library (oleg ssax) (export xml-token? xml-token-kind xml-token-head make-empty-attlist attlist-add attlist-null? attlist-remove-top attlist->alist attlist-fold ssax:uri-string->symbol ssax:skip-internal-dtd ssax:read-pi-body-as-string ssax:reverse-collect-str-drop-ws ssax:read-markup-token ssax:read-cdata-body ssax:read-char-ref ssax:read-attributes ssax:complete-start-tag ssax:read-external-id ssax:read-char-data ssax:make-parser ssax:xml->sxml) (import (rnrs base) (rnrs unicode) (rnrs io simple) (except (rnrs lists) fold-right) (rnrs control) (rnrs mutable-strings) (srfi :0) (only (srfi :13) string-concatenate-reverse string-index string-concatenate/shared string-null? string-concatenate-reverse/shared) (oleg prelude) (only (scheme) warning) (srfi private include)) (define parser-error (lambda (port message . rest) (apply error `(ssax-parser ,message ,@rest)))) (define ssax:warn (lambda (port message . irritants) (apply warning `(ssax ,message ,@irritants)))) (include/resolve ("oleg" "ssax" "lib") "look-for-str.scm") (include/resolve ("oleg" "ssax" "lib") "char-encoding.scm") (include/resolve ("oleg" "ssax" "lib") "input-parse.scm") (include/resolve ("oleg" "ssax" "lib") "SSAX-code.scm") )
false
43302befd4c782fc0fa1b52fdd14c59d5907a39c
752260fe4c9523dcb7575e846d76b42dd4fb881d
/egg-tarballs.meta
9b367cce2d7ff87af9608a5a7002d0a0ea10e4d3
[]
no_license
mario-goulart/egg-tarballs
0936a8ab5a4e823e0864c353e83a28661329a059
fa18fc9d0b4ceccd08c7b4a03213aa670edf9f3c
refs/heads/master
2022-01-01T23:54:55.786953
2021-12-25T19:02:49
2021-12-25T19:02:49
8,138,345
0
0
null
null
null
null
UTF-8
Scheme
false
false
193
meta
egg-tarballs.meta
;; -*- scheme -*- ((synopsis "Creates tarballs for eggs in henrietta cache") (author "Mario Domenech Goulart") (category tools) (license "BSD") (depends simple-sha1) (test-depends test))
false
9ac1b91088ce541f4f5063a3b069f955a46f3eef
25a487e394b2c8369f295434cf862321c26cd29c
/lib/pikkukivi/commands/yotsuba.sls
d156836ae589df948040f1e3359626414ecd685d
[]
no_license
mytoh/loitsu
b11e1ed9cda72c0a0b0f59070c9636c167d01a2c
d197cade05ae4acbf64c08d1a3dd9be6c42aac58
refs/heads/master
2020-06-08T02:00:50.563515
2013-12-17T10:23:04
2013-12-17T10:23:04
null
0
0
null
null
null
null
UTF-8
Scheme
false
false
5,152
sls
yotsuba.sls
(library (pikkukivi commands yotsuba) (export yotsuba) (import (silta base) (silta file) (silta write) (loitsu irregex) (only (srfi :1) every filter delete-duplicates last) (srfi :8 receive) (only (srfi :13 strings) string-join string-every) (srfi :14 char-sets) (srfi :26 cut) (srfi :39 parameters) (srfi :37 args-fold) (only (mosh concurrent) sleep) (loitsu match) (loitsu file) (loitsu process) (loitsu control) (loitsu cli) (maali) (loitsu util) (surl)) (begin (define (yotsuba-url . rest) (string-append "http://boards.4chan.org/" (string-join rest "/"))) (define (make-thread-url board thread) (yotsuba-url board "res" thread)) (define (get-html board thread) (let ((html (surl->utf8 (make-thread-url board thread)))) html)) (define (save-html thread str) (let ((file (build-path thread (path-swap-extension thread "html")))) (if (file-exists? file) (remove-file file)) (call-with-output-file file (lambda (out) (display str out))))) (define (parse-image-url html) (let ((image-regexp '(: "//images.4chan.org/" (+ alphabetic) "/src/" (+ numeric) "." (or "jpeg" "bmp" "jpg" "gif" "png"))) (match->url (lambda (m) (string-append "http:" (irregex-match-substring m))))) (delete-duplicates (map match->url (irregex-fold image-regexp (lambda (i m s) (cons m s)) '() html))))) (define (extract-file-name uri) (last (irregex-split "/" uri))) (define (fetch uri) (let* ((file (extract-file-name uri)) (tmp (temp-name file))) (unless (file-exists? file) (when (file-exists? tmp) (remove-file tmp)) (surl uri tmp) (rename-file tmp file)))) (define (temp-name orig) (let ((ext "!tmp")) (path-add-extension orig ext))) (define (setup-path number) (unless (file-exists? number) (make-directory* number))) (define (thread-exists? body) (not (equal? "" body))) (define (yotsuba-get-one-thread board thread) (let ((res (get-html board thread))) (cond ((thread-exists? res) (setup-path thread) (display thread) (save-html thread res) (let ((urls (parse-image-url res))) (with-cwd thread (map fetch urls))) (newline) #t) (else (display (string-append thread "'s gone")) (newline) #f)))) (define (string-number? s) (string-every char-set:digit s)) (define (yotsuba-get-all-thread board) (map (lambda (t) (yotsuba-get-one-thread board t)) (filter (lambda (d) (string-number? d)) (directory-list2 (current-directory))))) (define (repeat f . args) (let loop () (let ((wait (* (* 60 (* 6 1000)) 5))) (let ((results (apply f args))) (unless (all-false? results) (sleep 10000) (loop)))))) (define (all-false? x) (if (list? x) (every (lambda (e) (eq? e #f)) x) (eq? x #f))) (define option-repeat (option '(#\r "repeat") #f #t (lambda (option name arg repeat all) (values #t all)))) (define option-all (option '(#\a "all") #f #t (lambda (option name arg repeat all) (values repeat #t)))) (define (yotsuba args) (let ((args (cddr args))) (receive (repeat? all?) (args-fold args (list option-repeat option-all) (lambda (option name arg . seeds) ; unrecognized (error "Unrecognized option:" name)) (lambda (operand repeat all) ; operand (values repeat all)) #f ; default value of repeat? #f ; default value of all? ) (cond (repeat? (match (cdr args) ((board) (repeat yotsuba-get-all-thread board)) ((board thread) (repeat yotsuba-get-one-thread board thread)))) (else (match args ((board) (yotsuba-get-all-thread board)) ((board thread) (yotsuba-get-one-thread board thread)))))))) ))
false
66bb952c533bffac12d8f32488bf0b346ebded45
bf1c9803ae38f9aad027fbe4569ccc6f85ba63ab
/chapter_1/1.1.The.Elements.of.Programming/ex_1.7.scm
8b4348f347583176694daf0bba4ad7e6130ce4e9
[]
no_license
mehese/sicp
7fec8750d3b971dd2383c240798dbed339d0345a
611b09280ab2f09cceb2479be98ccc5403428c6c
refs/heads/master
2021-06-12T04:43:27.049197
2021-04-04T22:22:47
2021-04-04T22:23:12
161,924,666
0
0
null
null
null
null
UTF-8
Scheme
false
false
1,312
scm
ex_1.7.scm
#lang sicp (define TOL 0.001) (define (square x) (* x x)) (define (sqrt-iter guess x) (if (good-enough? guess x) guess (sqrt-iter (improve guess x) x))) (define (improve guess x) (average guess (/ x guess))) (define (average x y) (/ (+ x y) 2)) (define (good-enough? guess x) (< (abs (- (square guess) x)) TOL)) (define (sqrt x) (sqrt-iter 1.0 x)) (define (sqrt-iter2 guess x) (define new-guess (improve guess x)) (if (close-enough new-guess guess) new-guess (sqrt-iter2 new-guess x))) (define (close-enough x y) ;(display (cons x (cons y (abs (- (/ y x) 1))))) ;(newline) (< (abs (- (/ y x) 1)) TOL)) (define (sqrt2 x) (sqrt-iter2 1.0 x)) (define lst '(1e-5 2. 3. 4. 1e4 43204350052177.98)) (map sqrt lst) (map sqrt2 lst) ;; New procedure approximates small numbers better since the relative error is ;; closer to the TOL factor. By considering the ratio of guesses as our convergence ;; criterion, we can calculate the square root of really small or large numbers with ;; the same relative error (barring floating point errors that is). ;; Old procedure approximates large numbers better, as the absolute value of guess ;; and new guess is quite high, so their fraction converges even when the absolute ;; error is higher.
false
e713a18314be08d673b37ee7b2573001501c5a28
958488bc7f3c2044206e0358e56d7690b6ae696c
/scheme/guile/delay.scm
6f0c08b3c1f3fd9c6c863e373ee8716813e024e1
[]
no_license
possientis/Prog
a08eec1c1b121c2fd6c70a8ae89e2fbef952adb4
d4b3debc37610a88e0dac3ac5914903604fd1d1f
refs/heads/master
2023-08-17T09:15:17.723600
2023-08-11T12:32:59
2023-08-11T12:32:59
40,361,602
3
0
null
2023-03-27T05:53:58
2015-08-07T13:24:19
Coq
UTF-8
Scheme
false
false
102
scm
delay.scm
(define x (delay (display "I was delayed\n"))) (display (promise? x))(newline) (force x) (exit 0)
false
f749e5093a6db158b91dc16b864a100f3cfd1f9e
8c638eaa88aff5fc2d4c6c87f20f25081a77570b
/test/misc.ss
8d47b5df9c1c58395e934c7be7417b06ff64cd8a
[]
no_license
rmculpepper/scripting
9cc1f7ec82826886019faddc70cc98db4b4707ff
fb27f8779d53982158ab90baf5433f7a33aa1522
refs/heads/master
2021-03-12T23:07:05.902285
2016-10-28T04:08:54
2016-10-28T04:08:54
1,656,344
0
0
null
null
null
null
UTF-8
Scheme
false
false
1,432
ss
misc.ss
(module misc mzscheme (require "../misc.ss" (planet "test.ss" ("schematics" "schemeunit.plt" 2 6))) (provide misc-test) (define misc-test (test-suite "misc.ss" (test-case "map/separated" (let ((sep (lambda () 's))) (check-equal? (map/separated values sep '()) '()) (check-equal? (map/separated values sep '(a)) '(a)) (check-equal? (map/separated values sep '(a b c d e)) '(a s b s c s d s e)))) (test-case "for-each/separated" (let ((mailbox null) (n 0)) (let ((add (lambda (x) (set! mailbox (cons x mailbox)))) (sep (lambda () (set! mailbox (cons n mailbox)) (set! n (add1 n))))) (for-each/separated add sep '(a b c d e)) (check-equal? (reverse mailbox) '(a 0 b 1 c 2 d 3 e))))) (test-case "format-byte-count" (check-equal? (format-byte-count 12) "12 bytes") (check-equal? (format-byte-count 20000) "20 KB") (check-equal? (format-byte-count 20000000) "20 MB") (check-equal? (format-byte-count 20000000000) "20 GB")) (test-case "hash-table-put-fresh!" (let ((h (make-hash-table))) (hash-table-put! h 'a 1) (hash-table-put-fresh! h 'b 2) (check-exn exn:fail? (lambda () (hash-table-put-fresh! h 'a 3))))))) )
false
0605970878bf9533f1894887031d241e2d2fc20e
665da87f9fefd8678b0635e31df3f3ff28a1d48c
/cyclone.scm
c5b14a8be5e67101e0cb341e726dab34cc1f77a4
[ "MIT" ]
permissive
justinethier/cyclone
eeb782c20a38f916138ac9a988dc53817eb56e79
cc24c6be6d2b7cc16d5e0ee91f0823d7a90a3273
refs/heads/master
2023-08-30T15:30:09.209833
2023-08-22T02:11:59
2023-08-22T02:11:59
31,150,535
862
64
MIT
2023-03-04T15:15:37
2015-02-22T03:08:21
Scheme
UTF-8
Scheme
false
false
48,347
scm
cyclone.scm
;;;; Cyclone Scheme ;;;; https://github.com/justinethier/cyclone ;;;; ;;;; Copyright (c) 2014-2016, Justin Ethier ;;;; All rights reserved. ;;;; ;;;; This module contains a front-end for the compiler itself. ;;;; (import (scheme base) (scheme case-lambda) (scheme eval) (scheme file) (scheme lazy) (scheme read) (scheme time) (scheme write) (scheme cyclone ast) (scheme cyclone common) (scheme cyclone util) (scheme cyclone cgen) (scheme cyclone primitives) (scheme cyclone transforms) (scheme cyclone cps-optimizations) (scheme cyclone libraries) (srfi 18)) (define *fe:batch-compile* #t) ;; Batch compilation. TODO: default to false or true?? (define *optimization-level* 2) ;; Default level (define *optimize:memoize-pure-functions* #f) ;; Memoize pure function (define *optimize:beta-expand-threshold* #f) ;; BE threshold or #f to use default (define *optimize:inline-unsafe* #f) ;; Inline primitives even if generated code may be unsafe (define *cgen:track-call-history* #t) (define *cgen:use-unsafe-prims* #f) ; Placeholder for future enhancement to show elapsed time by phase: (define *start* (current-second)) ;; FUTURE: make this a cmd line option (define *report-elapsed* #f) (define (report:elapsed label) (when *report-elapsed* (display "Elapsed is " (current-error-port)) (display (- (current-second) *start*) (current-error-port)) (display (string-append " at " label) (current-error-port)) (newline (current-error-port)))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Batch compilation section ;; Do we need to recompile given library? (define (recompile? lib-dep append-dirs prepend-dirs) (let* ((sld-file (lib:import->filename lib-dep ".sld" append-dirs prepend-dirs)) (includes (lib:read-includes lib-dep append-dirs prepend-dirs)) (included-files (map (lambda (include) (lib:import->path lib-dep append-dirs prepend-dirs include)) includes)) (base (basename sld-file)) (obj-file (string-append base ".o")) (sys-dir (Cyc-installation-dir 'sld)) ) (and (not (in-subdir? sys-dir sld-file)) ;; Never try to recompile installed libraries (or (not (file-exists? obj-file)) ;; No obj file, must rebuild (any (lambda (src-file) (> (file-mtime src-file) (file-mtime obj-file))) ;; obj file out of date (cons sld-file included-files)))))) ;; Is "path" under given subdirectory "dir"? (define (in-subdir? dir path) (and (>= (string-length path) (string-length dir)) (equal? dir (substring path 0 (string-length dir))))) (define-c file-mtime "(void *data, int argc, closure _, object k, object filename)" " make_double(box, 0.0); Cyc_check_str(data, filename); double_value(&box) = Cyc_file_last_modified_time(string_str(filename)); return_closcall1(data, k, &box); ") (define-c calling-program "(void *data, int argc, closure _, object k)" " make_utf8_string(data, s, _cyc_argv[0]); return_closcall1(data, k, &s); ") ;; END batch compilation ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Code emission. ; c-compile-and-emit : (string -> A) exp -> void (define (c-compile-and-emit input-program program:imports/code lib-deps change-lib-deps! src-file append-dirs prepend-dirs) (call/cc (lambda (return) (define globals '()) (define module-globals '()) ;; Globals defined by this module (define program? #t) ;; Are we building a program or a library? (define imports '()) (define inlines '()) (define imported-vars '()) (define lib-name '()) (define lib-exports '()) (define lib-renamed-exports '()) (define lib-pass-thru-exports '()) (define c-headers '()) (define rename-env (env:extend-environment '() '() '())) (emit *c-file-header-comment*) ; Guarantee placement at top of C file (report:elapsed "---------------- input program:") (trace:info "---------------- input program:") (trace:info input-program) (cond ((library? (car input-program)) (let ((includes (lib:includes (car input-program)))) (set! program? #f) (set! lib-name (lib:name (car input-program))) (set! c-headers (lib:include-c-headers (car input-program))) (when (> *optimization-level* 0) (set! inlines (lib:inlines (car input-program)))) (set! lib-exports (cons (lib:name->symbol lib-name) (lib:exports (car input-program)))) (set! lib-pass-thru-exports lib-exports) (set! lib-renamed-exports (lib:rename-exports (car input-program))) (set! imports (lib:imports (car input-program))) (set! input-program (lib:body (car input-program))) ;; Add any renamed exports to the begin section (set! input-program (append (map (lambda (r) `(define ,(caddr r) ,(cadr r))) lib-renamed-exports) input-program)) ;; Prepend any included files into the begin section (if (not (null? includes)) (for-each (lambda (include) (set! input-program (append (read-file ;(string-append (lib:import->path lib-name append-dirs prepend-dirs include) ;include) ) input-program))) (reverse includes))))) ;; Append code in same order as the library's includes (else ;; Handle imports, if present (let ((reduction program:imports/code)) (set! imports (car reduction)) (set! input-program (cdr reduction))) ;; Handle inline list, if present` (let ((lis (lib:inlines `(dummy dummy ,@input-program)))) (cond ((not (null? lis)) (when (> *optimization-level* 0) (set! inlines lis)) (set! input-program (filter (lambda (expr) (not (tagged-list? 'inline expr))) input-program))))) ;; Handle any C headers (let ((headers (lib:include-c-headers `(dummy dummy ,@input-program)))) (cond ((not (null? headers)) (set! c-headers headers) (set! input-program (filter (lambda (expr) (not (tagged-list? 'include-c-header expr))) input-program))))) )) (report:elapsed "inline candidates:") (trace:info "inline candidates:") (trace:info inlines) ;; Process library imports (report:elapsed "imports:") (trace:info "imports:") (trace:info imports) (set! imported-vars (lib:imports->idb imports append-dirs prepend-dirs (base-expander))) (report:elapsed "resolved imports:") (trace:info "resolved imports:") (trace:info imported-vars) (let ((meta (lib:resolve-meta imports append-dirs prepend-dirs))) (set! *defined-macros* (append meta *defined-macros*)) (trace:info "resolved macros:") (trace:info meta)) ;; TODO: how to handle stdlib when compiling a library?? ;; either need to keep track of what was actually used, ;; or just assume all imports were used and include them ;; in final compiled program ;(set! input-program (add-libs input-program)) ;; Load macros for expansion phase (let ((macros (filter (lambda (v) (Cyc-macro? (Cyc-get-cvar (cdr v)))) (Cyc-global-vars)))) (set! *defined-macros* (append macros *defined-macros*))) (macro:load-env! *defined-macros* (create-environment '() '())) ;; Expand macros ;; In each case, the input is expanded in a way that ensures ;; defines from any top-level begins are spliced correctly. (set! input-program (cond (program? (expand-lambda-body input-program (macro:get-env) rename-env)) (else (let ((expanded (expand `(begin ,@input-program) (macro:get-env) rename-env))) (cond ((and (pair? expanded) (tagged-list? 'lambda (car expanded))) (lambda->exp (car expanded))) ((tagged-list? 'define expanded) (list expanded)) ((boolean? expanded) (list expanded)) (else (error `(Unhandled expansion ,expanded)))))))) (report:elapsed "---------------- after macro expansion:") (trace:info "---------------- after macro expansion:") (trace:info input-program) (set! input-program (macro:cleanup input-program rename-env)) (report:elapsed "---------------- after macro expansion cleanup:") (trace:info "---------------- after macro expansion cleanup:") (trace:info input-program) ;; If a program, check to see if any macros expanded into top-level imports (when program? (let ((program:imports/code (import-reduction input-program (base-expander)))) (when (not (null? (car program:imports/code))) (trace:info "-------------- macro expanded into import expression(s):") (set! imports (append imports (car program:imports/code))) (trace:info "imports:") (trace:info imports) (set! imported-vars (lib:imports->idb imports append-dirs prepend-dirs (base-expander))) (report:elapsed "resolved imports:") (trace:info "resolved imports:") (trace:info imported-vars) (let ((meta (lib:resolve-meta imports append-dirs prepend-dirs))) (set! *defined-macros* (append meta *defined-macros*)) (trace:info "resolved macros:") (trace:info meta)) (set! input-program (cdr program:imports/code)) ;(set! lib-deps (append lib-deps (lib:get-all-import-deps (car program:imports/code) append-dirs prepend-dirs))) (let ((changed #f) (new-lib-deps (lib:get-all-import-deps (car program:imports/code) append-dirs prepend-dirs #f))) (for-each (lambda (dep) (when (not (member dep lib-deps)) (set! changed #t) (set! lib-deps (cons dep lib-deps)))) new-lib-deps) (when changed ;; Library dependencies can change if additional import ;; expressions were encountered during macro expansion. ;; If so, update the list of dependencies now (set! ;; Use new deps lib-deps (change-lib-deps! lib-deps)))) ;; Caller updates and returns new deps (trace:info lib-deps) ))) ;; END additional top-level imports ;; Debug output for our dependencies (trace:info "---------------- Library dependencies") (trace:info lib-deps) (trace:info "---------------- Library files") (trace:info (map (lambda (lib-dep) (lib:import->filename lib-dep ".sld" append-dirs prepend-dirs)) lib-deps)) ;; Build dependent libraries, if instructed (when *fe:batch-compile* (for-each (lambda (lib-dep) (when (recompile? lib-dep append-dirs prepend-dirs) (let ((result (system (string-append (calling-program) " " (dirs->args "-A" append-dirs) " " (dirs->args "-I" prepend-dirs) " " (lib:import->filename lib-dep ".sld" append-dirs prepend-dirs))))) (when (> result 0) (error "Unable to compile library" lib-dep))))) lib-deps)) ;; Validate syntax of basic forms (validate-keyword-syntax input-program) ;; Separate global definitions from the rest of the top-level code (set! input-program (isolate-globals input-program program? lib-name rename-env)) ;; Optimize-out unused global variables ;; For now, do not do this if eval is used. ;; TODO: do not have to be so aggressive, unless (eval (read)) or such (if (not (has-global? input-program 'eval)) (set! input-program (filter-unused-variables input-program lib-exports))) (report:elapsed "---------------- after processing globals") (trace:info "---------------- after processing globals") (trace:info input-program) ;; Identify global variables (set! module-globals (global-vars input-program)) (set! globals (append (lib:idb:ids imported-vars) module-globals)) ;; Register inlinable Scheme functions (for-each (lambda (e) (if (define-c-inline? e) (prim:add-udf! (define->var e) (define-c->inline-var e)))) ;(write `(DEBUG add inline ,(define->var e) ,(define-c->inline-var e))))) input-program) ;; Inlines do not have to be non-CPS, they are really two separate things. ;; So keep track of all functions marked as inline because there are still ;; possibilities for optimization even if the function must call into its ;; continuation. (opt:add-inlinable-functions inlines) ;; Trim down the export list to any exports that are just "pass throughs" ;; from imported libraries. That is, they are not actually defined in ;; the library being compiled (set! lib-pass-thru-exports (filter (lambda (e) (let ((module-global? (member e module-globals)) (imported-var? (assoc e imported-vars))) (cond ((eq? e 'call/cc) #f) ;; Special case ((and (not module-global?) (not imported-var?) (not (prim? e))) (error "Identifier is exported but not defined" e)) (else ;; Pass throughs are not defined in this module, ;; but by definition must be defined in an imported lib (and (not module-global?) imported-var?))))) lib-pass-thru-exports)) (report:elapsed "pass thru exports:") (trace:info "pass thru exports:") (trace:info lib-pass-thru-exports) ; Note alpha-conversion is overloaded to convert internal defines to ; set!'s below, since all remaining phases operate on set!, not define. (set! globals (union globals '())) ;; Ensure list is sorted (set! input-program (map (lambda (expr) (alpha-convert expr globals return)) input-program)) (report:elapsed "---------------- after alpha conversion:") (trace:info "---------------- after alpha conversion:") (trace:info input-program) ;; EXPERIMENTAL CODE - Load functions in other modules that are ;; able to be inlined (in this context, from CPS). ;; ;; TODO: extend this initially by, for each import, invoking that module's inlinable_lambdas function ;; behind an exception handler (in case the compiler does not have that module loaded). ;; ;; Longer term, need to test if module is loaded (maybe do that in combo with exception handler above) ;; and if not loaded, eval/import it and try again. ;; ;; assumes (scheme base) is available to compiler AND at runtime in the compiled module/program ;; TODO: probably not good enough since inlines are not in export list ;; ;; TODO: later on, in cgen, only add inlinables that correspond to exported functions (for-each (lambda (import) (with-handler (lambda (err) #f) (let* ((lib-name-str (lib:name->string (lib:list->import-set import))) (inlinable-lambdas-fnc (string->symbol (string-append "c_" lib-name-str "_inlinable_lambdas")))) (cond ((imported? import) (let ((lib-name (lib:import->library-name (lib:list->import-set import))) (vars/inlines (filter (lambda (v/i) ;; Try to avoid name conflicts by not loading inlines ;; that conflict with identifiers in this module. ;; More of a band-aid than a true solution, though. (not (member (car v/i) module-globals))) (eval `( ,inlinable-lambdas-fnc ))))) ;(trace:info `(DEBUG ,import ,vars/inlines ,module-globals)) ;; Register inlines as user-defined primitives (for-each (lambda (v/i) (let ((var (car v/i)) (inline (cdr v/i))) (prim:add-udf! var inline))) vars/inlines) ;; Keep track of inline version of functions along with other imports (set! imported-vars (append imported-vars (map (lambda (v/i) (cons (cdr v/i) lib-name)) vars/inlines))))) (else ;; TODO: try loading if not loaded (but need ex handler in case anything bad happens) #t ;(eval `(import ,import)) ;;(%import import) ;; if this work is done, would need to consolidate inline reg code above #f))))) imports) ;; END ;; Convert some function calls to primitives, if possible (set! input-program (map (lambda (expr) (prim-convert expr)) input-program)) (report:elapsed "---------------- after func->primitive conversion:") (trace:info "---------------- after func->primitive conversion:") (trace:info input-program) ;; Identify native Scheme functions (from module being compiled) that can be inlined ;; ;; NOTE: There is a chicken-and-egg problem here that prevents this from ;; automatically working 100%. Basically we need to know whether the inline logic will ;; work for a given candidate. The problem is, the only way to do that is to run the ;; code through CPS and by then we would have to go back and repeat many phases if a ;; candidate fails the inline tests. At least for now, an alternative is to require ;; user code to specify (via inline) what functions the compiler should try inlining. ;; There is a small chance one of those inlines can pass these tests and still fail ;; the subsequent inline checks though, which causes an error in the C compiler. (define inlinable-scheme-fncs '()) (let ((lib-init-fnc (lib:name->symbol lib-name))) ;; safe to ignore for programs (for-each (lambda (e) (when (and (define? e) (member (define->var e) inlines) ;; Primary check, did use request inline (not (equal? (define->var e) lib-init-fnc)) (inlinable-top-level-lambda? e)) ;; Failsafe, reject if basic checks fail (set! inlinable-scheme-fncs (cons (define->var e) inlinable-scheme-fncs)) (set! module-globals (cons (define-c->inline-var e) module-globals)) (prim:add-udf! (define->var e) (define-c->inline-var e)))) input-program) (report:elapsed "---------------- results of inlinable-top-level-lambda analysis: ") (trace:info "---------------- results of inlinable-top-level-lambda analysis: ") (trace:info inlinable-scheme-fncs)) (let ((cps (map (lambda (expr) (cps-convert expr)) input-program))) (cond ((and library? (equal? lib-name '(scheme base))) (set! globals (append '(call/cc) globals)) (set! module-globals (append '(call/cc) module-globals)) (set! input-program ;(cons ; ;; Experimental version of call-with-values, ; ;; seems OK in compiler but not in eval. ; '(define call-with-values ; (lambda (k producer consumer) ; (let ((x (producer))) ; (if (and (pair? x) (equal? '(multiple values) (car x))) ; (apply consumer (cdr x)) ; (consumer k x)))) ; ; (producer ; ; (lambda (result) ; ; (consumer k result)))) ; ) ;; multiple args requires more than just this. ;; may want to look at: ;; http://stackoverflow.com/questions/16674214/how-to-implement-call-with-values-to-match-the-values-example-in-r5rs ;; (lambda vals ;; (apply k consumer vals))))) (cons ;; call/cc must be written in CPS form, so it is added here `(define call/cc ,(ast:make-lambda '(k f) (list (list 'f 'k (ast:make-lambda '(_ result) (list '(k result))))))) ;(lambda (k f) (f k (lambda (_ result) (k result))))) cps)));) (else ;; No need for call/cc yet (set! input-program cps)))) (report:elapsed "---------------- after CPS:") (trace:info "---------------- after CPS:") (trace:info (ast:ast->pp-sexp input-program)) (define (inject-import lis) (let ((dep (lib:list->import-set lis))) (when (not (member dep lib-deps)) (set! lib-deps (append lib-deps (list dep))) (change-lib-deps! lib-deps))) ) (define (inject-globals! lis) ;; FUTURE: these lines are specifically for memoization optizations. ;; if we need to make this more generic and have other globals ;; injected, then this code will need to be relocated, maybe into ;; an 'inject-memoization!' or such helper. (when (not (member 'Cyc-memoize globals)) (set! globals (append globals '(Cyc-memoize))) (set! imported-vars (cons (lib:list->import-set '(Cyc-memoize srfi 69)) imported-vars)) ) (inject-import '(scheme cyclone common)) (inject-import '(scheme base)) (inject-import '(scheme char)) (inject-import '(srfi 69)) ;; END memoization-specific code (set! module-globals (append module-globals lis)) (set! globals (append globals lis)) (set! globals (union globals '())) ;; Ensure list is sorted ) (define (flag-set? flag) (cond ((eq? flag 'memoize-pure-functions) (and program? ;; Only for programs, because SRFI 69 becomes a new dep *optimize:memoize-pure-functions*)) ((eq? flag 'track-call-history) *cgen:track-call-history*) ((eq? flag 'use-unsafe-prims) *cgen:use-unsafe-prims*) ((eq? flag 'inline-unsafe) *optimize:inline-unsafe*) ((eq? flag 'beta-expand-threshold) *optimize:beta-expand-threshold*) (else #f))) (when (> *optimization-level* 0) (set! input-program (optimize-cps input-program inject-globals! flag-set?)) (report:elapsed "---------------- after cps optimizations (1):") (trace:info "---------------- after cps optimizations (1):") (trace:info (ast:ast->pp-sexp input-program)) (set! input-program (optimize-cps input-program inject-globals! flag-set?)) (report:elapsed "---------------- after cps optimizations (2):") (trace:info "---------------- after cps optimizations (2):") (trace:info (ast:ast->pp-sexp input-program)) (set! input-program (optimize-cps input-program inject-globals! flag-set?)) (report:elapsed "---------------- after cps optimizations (3):") (trace:info "---------------- after cps optimizations (3):") (trace:info (ast:ast->pp-sexp input-program)) ) (set! input-program (opt:local-var-reduction input-program)) (report:elapsed "---------------- after local variable reduction") (trace:info "---------------- after local variable reduction") (trace:info (ast:ast->pp-sexp input-program)) ;; Clean up lambda numbering after code elimination (set! input-program (opt:renumber-lambdas! input-program)) (report:elapsed "---------------- after renumber lambdas") (trace:info "---------------- after renumber lambdas") (trace:info (ast:ast->pp-sexp input-program)) (set! input-program (map (lambda (expr) (clear-mutables) (analyze-mutable-variables expr) (wrap-mutables expr globals)) input-program)) (report:elapsed "---------------- after wrap-mutables:") (trace:info "---------------- after wrap-mutables:") (trace:info (ast:ast->pp-sexp input-program)) ;; Perform this analysis here since we need it later so it doesn't ;; make sense to execute it multiple times during CPS optimization (analyze:find-known-lambdas input-program) (set! input-program (map (lambda (expr) (cond ((define? expr) ;; Global `(define ,(define->var expr) ,@(car (ast:lambda-body (closure-convert (define->exp expr) globals *optimization-level*))))) ((define-c? expr) expr) (else (car (ast:lambda-body ;; Strip off superfluous lambda (closure-convert expr globals *optimization-level*)))))) input-program)) (report:elapsed "---------------- after closure-convert:") (trace:info "---------------- after closure-convert:") (trace:info (ast:ast->pp-sexp input-program)) (report:elapsed "---------------- analysis db: ") (trace:info "---------------- analysis db: ") (trace:info (adb:get-db)) (when (not *do-code-gen*) (trace:error "DEBUG, existing program") (exit 0)) (trace:info "---------------- C headers: ") (trace:info c-headers) (trace:info "---------------- module globals: ") (trace:info module-globals) (report:elapsed "---------------- C code:") (trace:info "---------------- C code:") (mta:code-gen input-program program? lib-name lib-pass-thru-exports imported-vars module-globals c-headers lib-deps src-file flag-set?) (return '())))) ;; No codes to return ;; Read top-level imports from a program and return a cons of: ;; - imports ;; - remaining program (define (import-reduction expr expander) (let ((results (foldl (lambda (ex accum) (define (process e) (cond ((tagged-list? 'import e) (cons (cons (cdr e) (car accum)) (cdr accum))) (else (cons (car accum) (cons e (cdr accum)))))) (cond ((tagged-list? 'cond-expand ex) (let ((ex* (expander ex))) ;(expand ex (macro:get-env) rename-env))) ;(trace:info `(DEBUG ,ex* ,ex)) (if (tagged-list? 'import ex*) (process ex*) (process ex)))) (else (process ex)))) (cons '() '()) expr))) (cons (apply append (reverse (car results))) (reverse (cdr results))))) ;; Return a function to expand any built-in macros ;; NOTE: since this uses a global macro env, it will be overridden later on when ;; macros are loaded from dependent libraries. (define (base-expander) (let ((rename-env (env:extend-environment '() '() '())) (macros (filter (lambda (v) (Cyc-macro? (Cyc-get-cvar (cdr v)))) (Cyc-global-vars)))) (macro:load-env! macros (create-environment '() '())) (lambda (ex) (expand ex (macro:get-env) rename-env)))) ;; TODO: longer-term, will be used to find where cyclone's data is installed (define (get-data-path) ".") (define (get-lib filename) (string-append (get-data-path) "/" filename)) (define (read-file filename) (call-with-input-file filename (lambda (port) (read-all/source port filename)))) ;; Parse given expression and return data from any instances ;; of c-compiler-options (define (program-c-compiler-opts! in-prog) (get-options! 'c-compiler-options in-prog)) (define (program-c-linker-opts! in-prog) (get-options! 'c-linker-options in-prog)) (define (get-options! opt in-prog) (foldl (lambda (expr acc) (cond ((tagged-list? opt expr) ;; Replace expression since it is only used in this initial ;; pass, and would cause problems downstream (set-car! expr (string->symbol "quote")) (cons (cadr expr) acc)) (else acc))) '() in-prog)) ;; Compile and emit: (define (run-compiler args append-dirs prepend-dirs change-cc-opts!) (let* ((in-file (car args)) (expander (base-expander)) (in-prog-raw (read-file in-file)) (program? (not (library? (car in-prog-raw)))) (in-prog (cond (program? (Cyc-add-feature! 'program) ;; Load special feature ;; TODO: what about top-level cond-expands in the program? in-prog-raw) (else ;; Account for any cond-expand declarations in the library (list (lib:cond-expand in-file (car in-prog-raw) expander))))) ;; expand in-prog, if a library, using lib:cond-expand. ;; TODO: will also need to do below in lib:get-all-import-deps, after reading each library (program:imports/code (if program? (import-reduction in-prog expander) '())) (lib-deps (if (and program? (not (null? (car program:imports/code)))) (lib:get-all-import-deps (car program:imports/code) append-dirs prepend-dirs expander) '())) ;; Read C compiler options (cc-opts (cond (program? (let ((opts (program-c-compiler-opts! in-prog))) (when (not (null? opts)) (change-cc-opts! opts)) (string-join ;; Check current program for options opts " "))) (else (string-join (lib:c-compiler-options (car in-prog)) " ")))) ;; Read all linker options from dependent libs (c-linker-options (let ((lib-options (lib:get-all-c-linker-options lib-deps append-dirs prepend-dirs expander))) (if program? (string-append ;; Also read from current program (string-join (program-c-linker-opts! in-prog) " ") " " lib-options) lib-options))) (exec-file (basename in-file)) (src-file (string-append exec-file ".c")) (meta-file (string-append exec-file ".meta")) (get-comp-env (lambda (sym str) (if (> (string-length str) 0) str (Cyc-compilation-environment sym)))) (create-c-file (lambda (program) (with-output-to-file src-file (lambda () (c-compile-and-emit program program:imports/code lib-deps (lambda (new-lib-deps) ;; Deps changed so we need to ;; resolve dependency tree again (set! lib-deps (lib:get-all-import-deps new-lib-deps append-dirs prepend-dirs expander)) ;; Recompute linker options (set! c-linker-options (lib:get-all-c-linker-options lib-deps append-dirs prepend-dirs expander)) ;; Return new deps lib-deps) in-file append-dirs prepend-dirs)))))) (create-c-file in-prog) (cond (program? ;; Use .meta file to store information for C compiler phase (save-program-metadata meta-file lib-deps c-linker-options)) (else ;; Emit .meta file (with-output-to-file meta-file (lambda () (display ";; This file was automatically generated by the Cyclone Scheme compiler") (newline) (write (macro:get-defined-macros)))))))) (define (save-program-metadata filename lib-deps c-linker-options) (with-output-to-file filename (lambda () (display ";; This file was automatically generated by the Cyclone Scheme compiler") (newline) (write `(lib-deps . ,lib-deps)) (newline) (write `(c-linker-options . ,c-linker-options))))) (define (load-program-metadata filename) (let ((data (call-with-input-file filename read-all))) (delete-file filename) data)) (define (get-meta meta symbol default) (if (assoc symbol meta) (cdr (assoc symbol meta)) default)) (define (run-external-compiler args append-dirs prepend-dirs cc? cc-prog cc-exec cc-lib cc-so cc-opts cc-prog-linker-opts cc-prog-linker-objs) (let* ((in-file (car args)) (expander (base-expander)) (in-prog-raw (read-file in-file)) (program? (not (library? (car in-prog-raw)))) (in-prog (cond (program? (Cyc-add-feature! 'program) ;; Load special feature ;; TODO: what about top-level cond-expands in the program? in-prog-raw) (else ;; Account for any cond-expand declarations in the library (list (lib:cond-expand in-file (car in-prog-raw) expander))))) ;; Only read C compiler options from module being compiled (cc-opts* (cond (program? (string-join ;; Check current program for options (program-c-compiler-opts! in-prog) " ")) (else (string-join (lib:c-compiler-options (car in-prog)) " ")))) (exec-file (basename in-file)) (src-file (string-append exec-file ".c")) (meta-file (string-append exec-file ".meta")) (get-comp-env (lambda (sym str) (if (> (string-length str) 0) str (Cyc-compilation-environment sym)))) ) ;; Compile the generated C file (cond (program? (letrec ((metadata (load-program-metadata meta-file)) (c-linker-options (get-meta metadata 'c-linker-options '())) (lib-deps (get-meta metadata 'lib-deps '())) (objs-str (string-append cc-prog-linker-objs (apply string-append (map (lambda (i) (string-append " " (lib:import->filename i ".o" append-dirs prepend-dirs) " ")) lib-deps)))) (comp-prog-cmd (string-append (string-replace-all (string-replace-all (string-replace-all ;(Cyc-compilation-environment 'cc-prog) (get-comp-env 'cc-prog cc-prog) "~src-file~" src-file) "~cc-extra~" cc-opts) "~exec-file~" exec-file) " " cc-opts*)) (comp-objs-cmd (string-append (string-replace-all (string-replace-all (string-replace-all (string-replace-all ;(Cyc-compilation-environment 'cc-exec) (get-comp-env 'cc-exec cc-exec) "~exec-file~" exec-file) "~ld-extra~" cc-prog-linker-opts) "~obj-files~" objs-str) "~exec-file~" exec-file) " " c-linker-options ))) ;(write `(DEBUG all imports ,lib-deps objs ,objs-str)) ;(write `(DEBUG ,(lib:get-all-import-deps (cdar in-prog)))) (cond (cc? (if (equal? 0 (system comp-prog-cmd)) (system comp-objs-cmd))) (else (display comp-prog-cmd) (newline) (display comp-objs-cmd) (newline))))) (else ;; Compile library (let ((comp-lib-cmd (string-append (string-replace-all (string-replace-all (string-replace-all (get-comp-env 'cc-lib cc-lib) "~src-file~" src-file) "~cc-extra~" cc-opts) "~exec-file~" exec-file) " " cc-opts*)) (comp-so-cmd (string-append (string-replace-all (string-replace-all (get-comp-env 'cc-so cc-so) "~src-file~" src-file) "~exec-file~" exec-file) " " cc-opts " " cc-opts*)) ) (cond (cc? (system comp-lib-cmd) (system comp-so-cmd) ) (else (display comp-lib-cmd) (newline) (display comp-so-cmd) (newline)))))))) ;; Collect values for the given command line arguments and option. ;; Will return a list of values for the option. ;; For example: ;; ("-a" "1" "2") ==> ("1") ;; ("-a" "1" "-a" "2") ==> ("1" "2") (define (collect-opt-values args opt) (cdr (foldl (lambda (arg accum) (cond ((equal? arg opt) (cons opt (cdr accum))) ((car accum) ;; we are at an opt value (cons #f (cons arg (cdr accum)))) (else (cons #f (cdr accum))))) (list #f) args))) ;; Convert a list of directories to a string of arguments. ;; EG: (dirs->args "-I" '("dir-1" "dir-2")) => ;; " -I dir-1 -I dir-2 " (define (dirs->args prefix dirs) (apply string-append (map (lambda (dir) (string-append " " prefix " " dir " ")) dirs))) ;; Handle command line arguments (let* ((args (command-line-arguments)) (non-opts (if (null? args) '() (list (car (reverse args))))) ; (filter ; (lambda (arg) ; (not (and (> (string-length arg) 1) ; (equal? #\- (string-ref arg 0))))) ; args)) (compile? #t) (run-scm-compiler? (member "-run-scm-compiler" args)) (no-compiler-subprocess (member "-no-compiler-subprocess" args)) (cc-prog (apply string-append (collect-opt-values args "-CP"))) (cc-exec (apply string-append (collect-opt-values args "-CE"))) (cc-lib (apply string-append (collect-opt-values args "-CL"))) (cc-so (apply string-append (collect-opt-values args "-CS"))) (cc-opts (apply string-append (collect-opt-values args "-COPT"))) (cc-linker-opts (apply string-append (collect-opt-values args "-CLNK"))) (cc-linker-extra-objects (apply string-append (collect-opt-values args "-COBJ"))) (opt-beta-expand-thresh (collect-opt-values args "-opt-be")) (append-dirs (collect-opt-values args "-A")) (prepend-dirs (collect-opt-values args "-I"))) (if (member "-batch" args) (set! *fe:batch-compile* #t)) (if (member "-no-batch" args) (set! *fe:batch-compile* #f)) ;; Set optimization level(s) (if (member "-O0" args) (set! *optimization-level* 0)) ;; Gather other optimization settings (when (pair? opt-beta-expand-thresh) (set! *optimize:beta-expand-threshold* (string->number (car opt-beta-expand-thresh)))) (if (member "-opt-inline-unsafe" args) (set! *optimize:inline-unsafe* #t)) (if (member "-memoization-optimizations" args) (set! *optimize:memoize-pure-functions* #t)) (if (member "-no-memoization-optimizations" args) (set! *optimize:memoize-pure-functions* #f)) (if (member "-use-unsafe-prims" args) (set! *cgen:use-unsafe-prims* #t)) (if (member "-no-call-history" args) (set! *cgen:track-call-history* #f)) ;; TODO: place more optimization reading here as necessary ;; End optimizations (if (member "-t" args) (set! *trace-level* 4)) ;; Show all trace output (if (member "-d" args) (set! compile? #f)) ;; Debug, do not run GCC (cond ((or (member "-h" args) (member "--help" args)) (display " Usage: cyclone [OPTIONS] FILENAME Run the Cyclone Scheme compiler. General options: -A directory Append directory to the list of directories that are searched in order to locate imported libraries. -I directory Prepend directory to the list of directories that are searched in order to locate imported libraries. -CP cc-commands Specify a custom command line for the C compiler to compile a program module. See Makefile.config for an example of how to construct such a command line. -CE cc-commands Specify a custom command line for the C compiler to compile an executable. -CL cc-commands Specify a custom command line for the C compiler to compile a library module. -CS cc-commands Specify a custom command line for the C compiler to compile a shared object module. -COBJ objects Specify additional object files to send to the compiler when linking a program. For example, this may be used to link an executable where some object files are generated via a makefile instead of by Cyclone. -COPT options Specify custom options to provide to the C compiler, EG: \"-Imy-directory\". -CLNK option Specify a custom command to provide as a linker option, EG: \"-lcurl\". -d Only generate intermediate C files, do not compile them -t Show intermediate trace output in generated C files -h, --help Display usage information -v Display version information -vn Display version number Compilation options: -batch Automatically compile local library dependencies (enabled by default). -no-batch Compile as a single unit, do not attempt to compile local library dependencies. Optimization options: -Ox Optimization level, higher means more optimizations will be used. Set to 0 to disable optimizations. -memoization-optimizations Memoize recursive calls to pure functions, where possible (enabled by default). -no-memoization-optimizations Disable the above memoization optimization. Unsafe options: -use-unsafe-prims Emit unsafe primitives. These primitives are faster but do not perform runtime type checking or bounds checking. Debug options: -no-call-history Do not track call history in the compiled code. This allows for a faster runtime at the cost of having no call history in the event of an exception. ") (newline)) ((member "-v" args) (display *version-banner*)) ((member "--autogen" args) (autogen "autogen.out") (newline)) ((member "-v" args) (display *version-banner*)) ((member "-vn" args) (display (Cyc-version))) ((member "--autogen" args) (autogen "autogen.out")) ((or (< (length args) 1) (null? non-opts)) (display "cyclone: no input file") (newline)) (else (with-handler (lambda (err) ;; Top-level exception handler for the compiler. ;; ;; We set this up since call history is generally ;; pointless for users of the compiler, so we don't ;; want to display it. (parameterize ((current-output-port (current-error-port))) (cond ((and (string? (car err)) (equal? (substring (car err) 0 8) "at line ")) (display "Error ")) (else (display "Error: "))) (display (car err)) (display ": ") (newline) (for-each (lambda (obj) (write obj) (newline)) (cdr err)) (newline) (exit 1))) (cond (run-scm-compiler? ;; Compile Scheme code into a C file (run-compiler non-opts append-dirs prepend-dirs (lambda (opts) (set! cc-opts opts)))) (else ;; Generate the C file (cond (no-compiler-subprocess ;; Special case, we can generate .C file within this process (run-compiler non-opts append-dirs prepend-dirs (lambda (opts) (set! cc-opts opts))) ) (else ;; Normal path is to run another instance of cyclone to generate ;; the .C file. This lets us immediately free those resources once ;; the Scheme compilation is done. (when (not (zero? (system (string-append (calling-program) " -run-scm-compiler " (string-join args " "))))) (exit 1)))) ;; Call the C compiler (run-external-compiler non-opts append-dirs prepend-dirs compile? cc-prog cc-exec cc-lib cc-so cc-opts cc-linker-opts cc-linker-extra-objects))) ))))
false
d5449633043cc0d6f84e9915a682cba744a06a03
defeada37d39bca09ef76f66f38683754c0a6aa0
/System/system/net/mail/alternate-view.sls
7710754894ef0eef4c9b679cae59fe1c2618011a
[]
no_license
futsuki/ironscheme-port
2dbac82c0bda4f4ff509208f7f00a5211d1f7cd5
4e7a81b0fbeac9a47440464988e53fb118286c54
refs/heads/master
2016-09-06T17:13:11.462593
2015-09-26T18:20:40
2015-09-26T18:20:40
42,757,369
0
0
null
null
null
null
UTF-8
Scheme
false
false
1,275
sls
alternate-view.sls
(library (system net mail alternate-view) (export new is? alternate-view? create-alternate-view-from-string base-uri-get base-uri-set! base-uri-update! linked-resources) (import (ironscheme-clr-port)) (define-syntax new (lambda (e) (syntax-case e () ((_ a ...) #'(clr-new System.Net.Mail.AlternateView a ...))))) (define (is? a) (clr-is System.Net.Mail.AlternateView a)) (define (alternate-view? a) (clr-is System.Net.Mail.AlternateView a)) (define-method-port create-alternate-view-from-string System.Net.Mail.AlternateView CreateAlternateViewFromString (static: System.Net.Mail.AlternateView System.String System.Text.Encoding System.String) (static: System.Net.Mail.AlternateView System.String System.Net.Mime.ContentType) (static: System.Net.Mail.AlternateView System.String)) (define-field-port base-uri-get base-uri-set! base-uri-update! (property:) System.Net.Mail.AlternateView BaseUri System.Uri) (define-field-port linked-resources #f #f (property:) System.Net.Mail.AlternateView LinkedResources System.Net.Mail.LinkedResourceCollection))
true
cd11f65abc56e461a0792a42d58f7253f339698b
f5b99d59741af88067a78383cf2df94c06fe3710
/sicp/chap2/2.3.ss
b8047ca6319dcd30bd5096993705039131446a41
[ "MIT" ]
permissive
shouya/thinking-dumps
53921a23ff62dd6aa0580cec6da26b11b83dd818
6191a940f3fca4661a6f01663ef38b8ce57c9018
refs/heads/master
2023-06-08T17:53:34.143893
2023-06-04T15:41:18
2023-06-04T15:41:18
22,285,392
24
3
MIT
2022-06-11T12:23:49
2014-07-26T11:40:12
Coq
UTF-8
Scheme
false
false
1,686
ss
2.3.ss
(define (print-point p) (display "(") (display (x-point p)) (display ",") (display (y-point p)) (display ")")) (define (print-point-newline p) (print-point p) (newline)) ; Have fun :) (define (make-point x y) (lambda (q) (if q x y))) (define (x-point p) (p #t)) (define (y-point p) (p #f)) ;; New (define (ver-dist-point p1 p2) (abs (- (y-point p1) (y-point p2)))) (define (hor-dist-point p1 p2) (abs (- (x-point p1) (x-point p2)))) ;; Method 1 to define a rectangle ; (define (make-rect p1 p2) ; (cons p1 p2)) ; (define (start-rect rect) (car rect)) ; (define (end-rect rect) (cdr rect)) ;; Method 2 (define (make-rect p1 p2) (list (x-point p1) (x-point p2) (y-point p1) (y-point p2))) (define (start-rect rect) (make-point (car rect) (caddr rect))) (define (end-rect rect) (make-point (cadr rect) (cadddr rect))) (define (height-rect rect) (ver-dist-point (start-rect rect) (end-rect rect))) (define (width-rect rect) (hor-dist-point (start-rect rect) (end-rect rect))) (define (circum-rect rect) (* 2 (+ (height-rect rect) (width-rect rect)))) (define (area-rect rect) (* (height-rect rect) (width-rect rect))) ;; Abstract Layers: ;; ;; 1. cons / list / car / cdr / cadr ... ;; 2. make-rect / start-rect / end-rect ;; 3. width-rect / height-rect ;; 4. circum-rect / area-rect ;; (let ((rect (make-rect (make-point 1 2) (make-point 3 4)))) (display (area-rect rect)) ;=> 4 (newline) (display (circum-rect rect)) ;=> 8 (newline))
false
f7768ac6cb4bb7f2490ebf32ef7d405cf6ef0420
b8034221175e02a02307ef3efef129badecda527
/tests/doc-custom-properties.scm
9f32b2d2b1ae2964e7c0a54ba7c5e1c0a6b357d1
[]
no_license
nobody246/xlsxWriterScm
ded2410db122dfbe8bbb5e9059239704ee9a5b32
d02ed10c3e8c514cc1b6a9eaf793a2cde34c4c47
refs/heads/master
2022-04-27T23:29:45.258892
2022-04-15T22:04:02
2022-04-15T22:04:02
153,357,109
0
1
null
null
null
null
UTF-8
Scheme
false
false
582
scm
doc-custom-properties.scm
(use xlsxwriterscm) (create-workbook "doc-custom-properties.xlsx") (add-worksheet "") (workbook-set-custom-property-string "Checked By" "Eve") (workbook-set-custom-property-date-time "Date Completed" 2016 12 12 0 0 0) (workbook-set-custom-property-number "Document Number" 12345) (workbook-set-custom-property-number "Reference Number" 1.2345) (workbook-set-custom-property-number "Has Review" 1) (workbook-set-custom-property-number "Signed Off" 0) (worksheet-set-column 50 0 0) (worksheet-write-string "Select 'Workbook Properties' to see properties.") (close-workbook) (exit)
false
4ddc6665826c75e0722d46ea53a6b8b657115584
354ae3428451a81e5a6e07d282edb9bd79ff0e3f
/tests/examples/path.ss
eac06a6b9b849779c03e41135c6ced1c838daed9
[]
no_license
jeapostrophe/datalog
385a478dc18a904a35cbe36ebc7b1a7ec0a26478
a5d59e455b49d091f3c5348e4c1f0071a1bc0134
refs/heads/master
2021-01-18T13:42:51.827415
2013-10-31T01:32:07
2013-10-31T01:32:07
null
0
0
null
null
null
null
UTF-8
Scheme
false
false
188
ss
path.ss
#lang planet jaymccarthy/datalog % path test from Chen & Warren edge(a, b). edge(b, c). edge(c, d). edge(d, a). path(X, Y) :- edge(X, Y). path(X, Y) :- edge(X, Z), path(Z, Y). path(X, Y)?
false
71c681128c4f0c0b057630158d361117cfee4a42
45b0335564f2f65b8eea1196476f6545ec7ac376
/beta-reduce.scm
5a169da41a7649b1b5a8e4e7049c1295d16c8aa7
[ "MIT" ]
permissive
dannypsnl-fork/nanopass
cbc252bb36054550191f16c2353126464268de7c
80e0344a1f143832a75d798be903e05b5dbdd079
refs/heads/master
2021-12-12T16:14:13.733284
2017-02-02T05:17:05
2017-02-02T05:17:05
null
0
0
null
null
null
null
UTF-8
Scheme
false
false
1,158
scm
beta-reduce.scm
(use util.match) (define atomic? (lambda (x) (or (not (pair? x)) (eq? 'quote (car x))))) (define beta-reduce (lambda (exp) (match exp [(? symbol?) exp] [('quote obj) exp] [(('lambda formals body) . args) (if (every atomic? args) (let ([body-u (subst (map cons formals args) body)]) (if (equal? body body-u) body (beta-reduce body-u))) `((lambda ,formals ,(beta-reduce body)) ,@(map beta-reduce args)))] [('lambda formals body) `(lambda ,formals ,(beta-reduce body))] [(rator . rands) (map beta-reduce exp)] [else exp]))) (define subst (lambda (s exp) (match exp [(? symbol?) (let ([p (assq exp s)]) (if p (cdr p) exp))] [('quote obj) exp] [('set! v e) `(set! ,v ,(subst s e))] [('lambda formals body) (let ([s-u (filter (lambda (p) (not (memq (car p) formals))) s)]) `(lambda ,formals ,(subst s-u body)))] [(rator . rands) (map (lambda (e) (subst s e)) exp)] [else exp])))
false
9bac3f94880c1dee12e44ca8889a2d63c323ae2a
9d7417f187812a477793ca23da844b34ab2a139d
/Graphikos/GraphikosTests/lib/ironscheme/web.sls
140fb2657a6d8916be4855c9d08041a292f8d210
[ "MIT", "BSD-3-Clause" ]
permissive
simonmoriat/PLP
5ae19daba4925919b593b4a21dc91dec9de9a6ce
3d130acaa45239cdb289462a242a8c15836a39ca
refs/heads/master
2023-05-11T23:36:28.347462
2016-06-08T07:07:50
2016-06-08T07:07:50
null
0
0
null
null
null
null
UTF-8
Scheme
false
false
5,793
sls
web.sls
#| License Copyright (c) 2007-2015 Llewellyn Pritchard All rights reserved. This source code is subject to terms and conditions of the BSD License. See docs/license.txt. |# (library (ironscheme web) (export context http-method querystring querystring-keys form form-keys header request response redirect rewrite-path application-item application-item-set! context-item context-item-set! session session-set! user-agent url-decode url-encode html-decode html-encode map-path resolve-url forms-authentication-logout forms-authentication-login request-raw-url request-app-path http-output-port error-add! error-clear! user-name user-in-role? user-authenticated? display-html wprintf response-content-type-set!) (import (ironscheme) (ironscheme contracts) (ironscheme xml) (ironscheme web-utils) (ironscheme clr)) (clr-reference System.Web) (clr-using System.Web) (clr-using System.Collections.Specialized) (clr-using System.Web.SessionState) (clr-using System.Security.Principal) (clr-using System.Web.Security) (define (context) (clr-static-prop-get HttpContext Current)) (define (request) (clr-prop-get HttpContext Request (context))) (define (response) (clr-prop-get HttpContext Response (context))) (define (http-method) (string->symbol (string-downcase (clr-prop-get HttpRequest HttpMethod (request))))) (define (get-querystring) (clr-prop-get HttpRequest QueryString (request))) (define (get-form) (clr-prop-get HttpRequest Form (request))) (define (get-headers) (clr-prop-get HttpRequest Headers (request))) (define (error-add! e) (clr-call HttpContext AddError (context) e)) (define (error-clear!) (clr-call HttpContext ClearError (context))) (define (get-user) (clr-prop-get HttpContext User (context))) (define (user-identity) (clr-prop-get IPrincipal Identity (get-user))) (define (user-name) (clr-prop-get IIdentity Name (user-identity))) (define/contract (user-in-role? role:string) (clr-call IPrincipal IsInRole (get-user) role)) (define (user-authenticated?) (clr-prop-get IIdentity IsAuthenticated (user-identity))) (define/contract (resolve-url vpath:string) (clr-call HttpResponse ApplyAppPathModifier (response) vpath)) (define (nv-helper instance key) (define k (clr-indexer-get NameValueCollection instance (clr-cast String key))) (if (null? k) #f k)) (define (querystring key) (nv-helper (get-querystring) (->string key))) (define (querystring-keys) (clr-prop-get NameValueCollection AllKeys (get-querystring))) (define (form key) (nv-helper (get-form) (->string key))) (define (form-keys) (clr-prop-get NameValueCollection AllKeys (get-form))) (define (header key) (nv-helper (get-headers) (->string key))) (define (get-session) (clr-prop-get HttpContext Session (context))) (define (get-app) (clr-prop-get HttpContext Application (context))) (define (session key) (define k (clr-indexer-get HttpSessionState (get-session) (clr-cast String (->string key)))) (if (null? k) #f k)) (define (session-set! key value) (clr-indexer-set! HttpSessionState (get-session) (clr-cast String (->string key)) value) (void)) (define (application-item key) (define k (clr-indexer-get HttpApplicationState (get-app) (clr-cast String (->string key)))) (if (null? k) #f k)) (define (application-item-set! key value) (clr-indexer-set! HttpApplicationState (get-app) (clr-cast String (->string key)) value) (void)) (define (items) (clr-prop-get HttpContext Items (context))) (define (->string s) (cond [(symbol? s) (symbol->string s)] [(or (string? s) (null? s)) s] [else (assertion-violation '->string "not a symbol or string" s)])) (define (context-item key) (hashtable-ref (items) (->string key) #f)) (define (context-item-set! key value) (hashtable-set! (items) (->string key) value)) (define (user-agent) (clr-prop-get HttpRequest UserAgent (request))) (define (server-util) (clr-prop-get HttpContext Server (context))) (define/contract (map-path p:string) (clr-call HttpServerUtility MapPath (server-util) p)) (define/contract (response-content-type-set! p:string) (clr-prop-set! HttpResponse ContentType (response) p) (void)) (define (http-output-port) (clr-prop-get HttpResponse Output (response))) (define/contract (rewrite-path path:string) (clr-call HttpContext RewritePath (context) path)) (define/contract redirect (case-lambda [(path:string) (clr-call HttpResponse Redirect (response) path)] [(path:string endresponse?:boolean) (clr-call HttpResponse Redirect (response) path endresponse?)])) (define (request-raw-url) (clr-prop-get HttpRequest RawUrl (request))) (define (request-app-path) (clr-prop-get HttpRequest ApplicationPath (request))) (define (forms-authentication-logout) (clr-static-call FormsAuthentication SignOut)) (define/contract (forms-authentication-login user:string) (clr-static-call FormsAuthentication SetAuthCookie user #f)) (define (display-html html) (display (->xml html) (http-output-port))) (define (wprintf fmt . args) (apply fprintf (http-output-port) fmt args)))
false
71ebac4a0881a742e8dcac314a0bddf7f9cee68f
9b2eb10c34176f47f7f490a4ce8412b7dd42cce7
/lib-compat/digamma-yuni/compat/file-ops.sls
0f908d0a363f0db10e5e2488b43fa4e053e8b08c
[ "LicenseRef-scancode-public-domain", "CC0-1.0" ]
permissive
okuoku/yuni
8be584a574c0597375f023c70b17a5a689fd6918
1859077a3c855f3a3912a71a5283e08488e76661
refs/heads/master
2023-07-21T11:30:14.824239
2023-06-11T13:16:01
2023-07-18T16:25:22
17,772,480
36
6
CC0-1.0
2020-03-29T08:16:00
2014-03-15T09:53:13
Scheme
UTF-8
Scheme
false
false
624
sls
file-ops.sls
(library (digamma-yuni compat file-ops) (export ;; chez like file-ops file-regular? file-directory? directory-list current-directory ;; mosh directory procedure create-directory delete-directory) (import (yuni scheme) (only (core) create-directory file-regular? file-directory?) (core files)) ;; Digamma uses remove(3) for `delete-file` which is also applicable on dirs (define delete-directory delete-file) )
false
c0e32f150a4f120b9b6db10836042d5bcaf1de34
2a4d841aa312e1759f6cea6d66b4eaae81d67f99
/lisp/scheme/test_chicken.scm
9eeb95e0d55e4142c6790b33ff81e0955893b013
[]
no_license
amit-k-s-pundir/computing-programming
9f8e136658322bb9a61e7160301c1a780cec84ca
9104f371fe97c9cd3c9f9bcd4a06038b936500a4
refs/heads/master
2021-07-12T22:46:09.849331
2017-10-16T08:50:48
2017-10-16T08:50:48
106,879,266
1
2
null
null
null
null
UTF-8
Scheme
false
false
169
scm
test_chicken.scm
(require-extension ssax) (require 'sxml) ;(sxml:document "http://modis.ispras.ru/Lizorkin/XML/poem.xml") (ssax:xml->sxml "http://modis.ispras.ru/Lizorkin/XML/poem.xml")
false
8d8f28aca052dbfb374875cfee8d1e3ab6a66453
3508dcd12d0d69fec4d30c50334f8deb24f376eb
/v8/src/compiler/rtlbase/rgraph.scm
6b1dafb6d991371916408ff194630440d5f51a3c
[]
no_license
barak/mit-scheme
be625081e92c2c74590f6b5502f5ae6bc95aa492
56e1a12439628e4424b8c3ce2a3118449db509ab
refs/heads/master
2023-01-24T11:03:23.447076
2022-09-11T06:10:46
2022-09-11T06:10:46
12,487,054
12
1
null
null
null
null
UTF-8
Scheme
false
false
1,878
scm
rgraph.scm
#| -*-Scheme-*- Copyright (c) 1987-1999 Massachusetts Institute of Technology This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |# ;;;; Program Graph Abstraction (declare (usual-integrations)) (define-structure (rgraph (type vector) (copier false) (constructor make-rgraph (n-registers))) n-registers (entry-edges '()) (bblocks '()) register-bblock register-n-refs register-n-deaths register-live-length register-crosses-call? register-value-classes register-known-values register-known-expressions) (define (add-rgraph-bblock! rgraph bblock) (set-rgraph-bblocks! rgraph (cons bblock (rgraph-bblocks rgraph)))) (define (delete-rgraph-bblock! rgraph bblock) (set-rgraph-bblocks! rgraph (delq! bblock (rgraph-bblocks rgraph)))) (define (add-rgraph-entry-edge! rgraph edge) (set-rgraph-entry-edges! rgraph (cons edge (rgraph-entry-edges rgraph)))) (define-integrable rgraph-register-renumber rgraph-register-bblock) (define-integrable set-rgraph-register-renumber! set-rgraph-register-bblock!) (define *rgraphs*) (define *current-rgraph*) (define (rgraph-initial-edges rgraph) (list-transform-positive (rgraph-entry-edges rgraph) (lambda (edge) (node-previous=0? (edge-right-node edge)))))
false
55c4e26bb9e81ff8e86242a6e197cc19a0d821dc
63396d44120974f0f296f9d896f38ba31c386e33
/t/unit/taptest-config.scm
955c2b54af424fd4e0c269a5549a4e900866eac9
[ "BSD-2-Clause", "LicenseRef-scancode-unknown-license-reference" ]
permissive
ft/olscrbl
5596b69768a62aa3ce4881360da9ca8939a6645c
44b2e938fdf63b953a398a1240da7007c960261b
refs/heads/master
2020-12-30T10:50:15.254629
2014-01-05T17:51:03
2014-01-05T17:51:03
15,658,764
1
1
null
null
null
null
UTF-8
Scheme
false
false
38
scm
taptest-config.scm
(tap/set-option 'fs-suffix "-scm.t$")
false
e80b2de1f77f63341ea37661995aee3395c72393
ae4938300d7eea07cbcb32ea4a7b0ead9ac18e82
/labs/lazy/eval.ss
b1e61d9d6a00a8a558c2788f28e79cfe844ae93e
[]
no_license
keenbug/imi-libs
05eb294190be6f612d5020d510e194392e268421
b78a238f03f31e10420ea27c3ea67c077ea951bc
refs/heads/master
2021-01-01T19:19:45.036035
2012-03-04T21:46:28
2012-03-04T21:46:28
1,900,111
0
1
null
null
null
null
UTF-8
Scheme
false
false
4,940
ss
eval.ss
(import (rnrs) (imi utils print)) (define (haskeval expr) (cond [(lambda? expr) (haskeval-lambda expr)] [(application? expr) (haskeval-app expr)] [(variable? expr) (haskeval-var expr)] [else (haskeval-data expr)])) (define (lambda? expr) (and (pair? expr) (eq? 'lambda (car expr)))) (define (haskeval-lambda expr) (let ([args (cadr expr)] [body (caddr expr)]) (let ([body-compiled (haskeval body)]) (lambda (env) (let ([intern-proc (make-intern env args body-compiled)]) (lambda () intern-proc)))))) (define-record-type intern (fields env args body)) (define (application? expr) (list? expr)) (define (haskeval-app expr) (let ([proc (haskeval (car expr))] [args (map haskeval (cdr expr))]) (lambda (env) (let ([proc (proc env)]) (lambda () (let ([p (proc)]) (cond [(hforeign? p) (hforeign-call p args)] [(intern? p) (intern-call p args)] [else (error 'haskeval-app "not a callable value" p)]))))))) (define (hforeign? proc) (and (pair? proc) (eq? (car proc) 'special-mega-turtle-foreign-id) (procedure? (cdr proc)))) (define (hforeign-call proc args) (apply (cdr proc) args)) (define (intern-call proc args) (let ([env (extend-env/args (intern-env proc) (intern-args proc) args)] [body (intern-body proc)]) (let ([body (body env)]) (body)))) (define (extend-env/args env argnames argvalues) (cond [(null? argnames) env] [(pair? argnames) (extend-env/args (cons (cons (car argnames) (car argvalues)) env) (cdr argnames) (cdr argvalues))] [(symbol? argnames) (cons (cons argnames (lambda (env) (fold-right (lambda (arg haskargs) (lambda () (haskons (arg env) haskargs))) '() argvalues))) env)] [else (error 'extend-env/args "invalid argument" argnames)])) (define (variable? expr) (symbol? expr)) (define (haskeval-var expr) (lambda (env) (let loop ([search-env env]) (cond [(null? search-env) (error 'haskeval-var "variable not bound" expr)] [(eq? expr (caar search-env)) ((cdar search-env) env)] [else (loop (cdr search-env))])))) (define (haskeval-data expr) (lambda (env) (lambda () expr))) (define (scm->hask proc) (lambda (env) (lambda () (cons 'special-mega-turtle-foreign-id (lambda args (apply proc (map (lambda (argproc) ((argproc env))) args))))))) (define (scm->lazy proc) (lambda (env) (lambda () (cons 'special-mega-turtle-foreign-id (lambda args (apply proc (map (lambda (argproc) (argproc env)) args))))))) (define (haskons a d) (cons a d)) (define (haskar pair) ((car (pair)))) (define (haskdr pair) ((cdr (pair)))) (define stdenv (append (map (lambda (var) (cons (car var) (scm->lazy (cadr var)))) `((cons ,haskons) (car ,haskar) (cdr ,haskdr) )) (map (lambda (var) (cons (car var) (scm->hask (cadr var)))) `((= ,fx=) (< ,fx<) (> ,fx>) (+ ,fx+) (- ,fx-) (* ,fx*) (mod ,mod) (div ,div) (null? ,null?) )) '((null . '()) ) )) (define (extend-env env . exprs) (if (null? exprs) env (apply extend-env (cons (cons (car exprs) (haskeval (cadr exprs))) env) (cddr exprs)))) (define extenv (extend-env stdenv 'list '(lambda ls ls) 'map '(lambda (proc ls) (cons (proc (car ls)) (map proc (cdr ls)))) )) (define ownenv extenv) (define (haskdef! name def) (set! ownenv (extend-env ownenf name def))) (define (hasktest expr) (((haskeval expr) ownenv)))
false
83878a86b075d12c4615821dbb28f5285f341422
35f859a6933537955f878e97455cd45b312aa042
/example/example18.tmp.scm
c5cd63c4d0151f8d1c165e42910e3cdcf3865a54
[]
no_license
podhmo/gauche-gl-processing
ebbbe2631830cb7d0e62b5e5aa0275bb176c7084
d57b9c055d2dfe199df5652e1afb0cfd1713257f
refs/heads/master
2021-01-23T08:38:44.547876
2010-10-13T08:40:19
2010-10-13T08:40:19
null
0
0
null
null
null
null
UTF-8
Scheme
false
false
2,448
scm
example18.tmp.scm
;; ;; blending ;; GL_ZERO (0,0,0,0) ;; GL_ONE (1,1,1,1) ;; GL_SRC_COLOR (Rs/kR ,Gs/kG,Bs/kB,As/kA) ;; GL_ONE_MINUS_SRC_COLOR (1,1,1,1)-(Rs/kR,Gs/kG,Bs/kB,As/kA) ;; GL_DST_COLOR (Rd/kR,Gd/kG,Bd/kB,Ad/kA) ;; GL_ONE_MINUS_DST_COLOR (1,1,1,1)-(Rd/kR,Gd/kG,Bd/kB,Ad/kA) ;; GL_SRC_ALPHA (As/kA,As/kA,As/kA,As/kA) ;; GL_ONE_MINUS_SRC_ALPHA (1,1,1,1)-(As/kA,As/kA,As/kA,As/kA) ;; GL_DST_ALPHA (Ad/kA,Ad/kA,Ad/kA,Ad/kA) ;; GL_ONE_MINUS_DST_ALPHA (1,1,1,1)-(Ad/kA,Ad/kA,Ad/kA,Ad/kA) ;; GL_SRC_ALPHA_SATURATE (i,i,i,1) (use gl.processing) (define (tri) ;; draw triangle (gl-begin* GL_TRIANGLES (gl-vertex 120 120) (gl-vertex 0 120) (gl-vertex 60 60))) (define (blend-sample caption x y) (with-matrix (translate x y 0) (gl-color 1 0 0 0.7) (tri) (with-matrix (gl-color 0.4 0.8 0.6 0.5) (translate 50 0 0) (tri)) (with-matrix (fill 255 255 255) (text caption 10 140)))) (define draw (draw-once$ (^ () (translate 20 20) (text "left triangle is GL_SRC_ALPHA L:(1 0 0 0.7) R:(0.4 0.8 0.6 0.5)" 0 0) (gl-blend-func GL_SRC_ALPHA GL_ONE) (blend-sample "GL_ONE" 0 0) (gl-blend-func GL_SRC_ALPHA GL_ZERO) (blend-sample "GL_ZERO" 200 0) (gl-blend-func GL_SRC_ALPHA GL_SRC_COLOR) (blend-sample "GL_SRC_COLOR" 400 0) (gl-blend-func GL_SRC_ALPHA GL_ONE_MINUS_SRC_COLOR) (blend-sample "GL_ONE_MINUS_SRC_COLOR" 600 0) (with-matrix (translate 0 100) (gl-blend-func GL_SRC_ALPHA GL_DST_COLOR) (blend-sample "GL_DST_COLOR" 0 0) (gl-blend-func GL_SRC_ALPHA GL_SRC_ALPHA) (blend-sample "GL_SRC_ALPHA" 200 0) (gl-blend-func GL_SRC_ALPHA GL_ONE_MINUS_DST_ALPHA) (blend-sample "GL_ONE_MINUS_DST_ALPHA" 400 0) (gl-blend-func GL_SRC_ALPHA GL_SRC_ALPHA_SATURATE) (blend-sample "GL_SRC_ALPHA_SATURATE" 600 0)) ) :save "foo.png" :bg (cut background 0 0 0))) (define main (setup$ (^ () (window 900 300 "" 100 100) (font-mode! 'bitmap) (load-font "Utopia" 12) (gl-disable GL_DEPTH_TEST) (gl-enable GL_BLEND)) :draw draw)) (main '())
false
844a150fddb7703d69f6a994cda7cf402e3c74b3
a97e1f9075df3f8eda040e0018eac5e2497f9e16
/share/textbook/lib/textbook/trie.scm
77d6a2d9307e4be08574364426dcec9e8bcb11ce
[ "MIT", "BSD-3-Clause", "BSL-1.0" ]
permissive
hvellyr/textbook
9eefeded45dce203a51419acaeb47864f7a73810
3b7b797c71384222d58b67bded24ee5b5cc6aa2a
refs/heads/master
2023-03-03T20:41:45.450236
2021-01-24T11:18:00
2021-01-24T11:18:32
31,146,671
0
1
null
2018-01-29T10:59:46
2015-02-22T00:17:16
C++
UTF-8
Scheme
false
false
5,115
scm
trie.scm
;; -*-scheme-*- ;; Copyright (c) 2019 by Gregor Klinke ;; All rights reserved. (import (srfi 9)) ;; define record types (import (srfi 69)) ;;; private (define-record-type :trie-empty-value (trie-empty-value) trie-empty-value?) ;;; private (define *trie-empty-value* (trie-empty-value)) ;;; private (define-syntax make-trie-node (syntax-rules () ((make-trie-node) (cons (make-hash-table) *trie-empty-value*)))) ;;; private (define-syntax trie-node-children (syntax-rules () ((trie-node-children node) (car node)))) ;;; private (define-syntax trie-node-value (syntax-rules () ((trie-node-value node) (cdr node)))) ;;; private (define-syntax trie-node-value! (syntax-rules () ((trie-node-value! node value) (set-cdr! node value)))) ;;; private (define-record-type :trie (trie _root) trie? (_root trie-root)) ;;; @doc Creates an empty trie object (define (make-trie) (trie (make-trie-node))) ;;; private (define (trie-find-node c key thunk) (let* ((key-len (string-length key))) (let loop ((cur-node (trie-root c)) (idx 0)) (if (>= idx key-len) cur-node (let* ((cur-char (string-ref key idx)) (next-node (hash-table-ref/default (trie-node-children cur-node) cur-char #f)) (mapped-node (if (not next-node) (thunk cur-node cur-char) next-node)) ) (if (not mapped-node) 'not-found (loop mapped-node (+ idx 1)))) )))) ;;; @doc Returns the value for @prm{key} in @prm{c} or the symbol ;;; @sym{not-found} if @prm{key} is not in @prm{c}. If @prm{key} is a prefix to ;;; some other key in @prm{c} the return value might be an ;;; @ty{trie-empty-value}. (define (trie-ref c key) (let ((nd (trie-find-node c key (lambda (cur-nd cur-char) #f)))) (if (eqv? nd 'not-found) nd (trie-node-value nd)))) (define (trie-prefix? c key) (let ((nd (trie-find-node c key (lambda (cur-nd cur-char) #f)))) (if (eqv? nd 'not-found) #f (> (hash-table-size (trie-node-children nd)) 0)))) ;;; @doc Indicates whether @prm{key} is contained in @prm{c}. @prm{key} is not ;;; contained if is only a prefix to another key. (define (trie-contains c key) (let* ((res (trie-ref c key))) (not (or (eqv? res 'not-found) (trie-empty-value? res))))) ;;; private (define (trie-node-fold nd pfx proc obj) (let* ((obj2 (if (not (trie-empty-value? (trie-node-value nd))) (proc pfx (trie-node-value nd) obj) obj))) (hash-table-fold (trie-node-children nd) (lambda (key value acc) (trie-node-fold value (string-append pfx (string key)) proc acc)) obj2))) ;;; @doc Calls @prm{proc} for every association in @prm{c} with three arguments: ;;; the @em{key} of the association key, the @em{value} of the association ;;; value, and an accumulated value, @em{obj}. @em{val} is @prm{obj} for the ;;; first invocation of @prm{proc}, and for subsequent invocations of ;;; @prm{proc}, the return value of the previous invocation of @prm{proc}. The ;;; return value returned is the return value of the last invocation of ;;; @prm{proc}. The order in which @prm{proc} is called for different ;;; associations is unspecified. (define (trie-fold c pfx proc obj) (let ((nd (trie-find-node c pfx (lambda (cur-nd cur-char) #f)))) (if (eqv? nd 'not-found) obj (trie-node-fold nd pfx proc obj)))) ;;; @doc Returns a list of all keys in @prm{c} which have a common prefix ;;; @prm{pfx} or are identical to @prm{pfx}. (define (trie-keys c pfx) (trie-fold c pfx (lambda (key val obj) (append obj (list key))) (list))) ;;; @doc Returns a list of all values in @prm{c} which are mapped by keys with a ;;; common prefix @prm{pfx} or are identical to @prm{pfx}. (define (trie-values c pfx) (trie-fold c pfx (lambda (key val obj) (append obj (list val))) (list))) ;;; @doc insert @prm{key} with @prm{value} into @prm{c}. A previous inserted ;;; key @prm{key} is overwritten. (define (trie-insert c key value) (let* ((nd (trie-find-node c key (lambda (cur-node cur-char) (let ((new-node (make-trie-node))) (hash-table-set! (trie-node-children cur-node) cur-char new-node) new-node))))) (trie-node-value! nd value) #t)) ;;; @doc Indicates whether the trie @prm{t} is empty. (define (trie-empty? t) (= (hash-table-size (trie-node-children (trie-root t))) 0))
true
39a94de55423ea937d542960cc46854bbb0799df
120324bbbf63c54de0b7f1ca48d5dcbbc5cfb193
/packages/srfi/%3a37.sls
23db6b54c2612914040f40ed13a6f44e072f2239
[ "X11-distribute-modifications-variant", "MIT" ]
permissive
evilbinary/scheme-lib
a6d42c7c4f37e684c123bff574816544132cb957
690352c118748413f9730838b001a03be9a6f18e
refs/heads/master
2022-06-22T06:16:56.203827
2022-06-16T05:54:54
2022-06-16T05:54:54
76,329,726
609
71
MIT
2022-06-16T05:54:55
2016-12-13T06:27:36
Scheme
UTF-8
Scheme
false
false
262
sls
%3a37.sls
#!r6rs ;; Automatically generated by private/make-aliased-libraries.sps (library (srfi :37) (export args-fold option option-names option-optional-arg? option-processor option-required-arg? option?) (import (srfi :37 args-fold)) )
false
f8eb70b4cd17225c998cd0025b9c81c3eb82e13c
f916d100a0510989b96deaa9d2d2f90d86ecc399
/slib/mwtest.scm
93e1d86fdcb66c5e27a2b02277c3b084c61b1bbb
[]
no_license
jjliang/UMB-Scheme
12fd3c08c420715812f933e873110e103236ca67
d8479f2f2eb262b94be6040be5bd4e0fca073a4f
refs/heads/master
2021-01-20T11:19:37.800439
2012-09-27T22:13:50
2012-09-27T22:13:50
5,984,440
2
0
null
null
null
null
UTF-8
Scheme
false
false
6,023
scm
mwtest.scm
; "mwtest.scm" test macros-that-work ; From: William Clinger ; A short test suite. ; Uses PRETTY-PRINT and EVAL, neither of which is standard Scheme. ; Redefine f and g as desired to fix this. (require 'pretty-print) (require 'macros-that-work) ; The value returned by MACWORK:EXPAND is expressed using keywords ; defined in "prefs.sch", which might not be the keywords expected ; by EVAL. (define begin0 'begin) (define define0 'define) (define quote0 'quote) (define lambda0 'lambda) (define if0 'if) (define set!0 'set!) (define begin2 mw:begin1) (define define2 mw:define1) (define quote2 mw:quote1) (define lambda2 mw:lambda1) (define if2 mw:if1) (define set!2 mw:set!1) (define original-code #f) ; assigned by f, used by g (define expanded-code #f) ; assigned by f, used by g (define (f x) (set! original-code x) (set! mw:begin1 begin2) (set! mw:define1 define2) (set! mw:quote1 quote2) (set! mw:lambda1 lambda2) (set! mw:if1 if2) (set! mw:set!1 set!2) (set! expanded-code (macwork:expand x)) (pretty-print expanded-code) ) (define (g answer) (set! mw:begin1 begin0) (set! mw:define1 define0) (set! mw:quote1 quote0) (set! mw:lambda1 lambda0) (set! mw:if1 if0) (set! mw:set!1 set!0) (if (not (equal? (slib:eval (macwork:expand original-code)) answer)) (begin (newline) (display "TEST FAILED!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!") (newline) (display "Original code was:") (newline) (pretty-print original-code) (newline) (newline)) #t)) (f '(let ((a 3)) a)) (g 3) (f '(let ((=> #f)) (cond (#t => 'ok)))) (g 'ok) ; This syntax of set*! matches that of an example in the R4RS. ; That example was put forth as an example of a hygienic macro ; that supposedly couldn't be written using syntax-rules. Hah! (f '(define-syntax set*! (syntax-rules () ((set*! (?var ?val) ...) (set*!-help (?val ...) () (?var ?val) ...))))) (f '(define-syntax set*!-help (syntax-rules () ((set*!-help () (?temp ...) (?var ?val) ...) (let ((?temp ?val) ...) (set! ?var ?temp) ...)) ((set*!-help (?var1 ?var2 ...) ?temps ?assignments ...) (set*!-help (?var2 ...) (temp . ?temps) ?assignments ...))))) (f '(let ((x 3) (y 4) (z 5)) (set*! (x (+ x y z)) (y (- x y z)) (z (* x y z))) (list x y z))) (g '(12 -6 60)) (f '(let ((else #f)) (cond (#f 3) (else 4) (#t 5)))) (g '5) (f '(define-syntax push (syntax-rules () ((push item place) (set! place (cons item place)))))) (f '(let* ((cons (lambda (name) (case name ((phil) '("three-card monte")) ((dick) '("secret plan to end the war" "agnew" "not a crook")) ((jimmy) '("why not the best")) ((ron) '("abolish the draft" "balance the budget")) (else '())))) (scams (cons 'phil))) (push (car (cons 'jimmy)) scams) (push (cadr (cons 'ron)) scams) scams)) (g '("balance the budget" "why not the best" "three-card monte")) ; Tests of quasiquote and the vector extension. (f '`(list ,(+ 1 2) 4)) (g '(list 3 4)) (f '(let ((name 'a)) `(list ,name ',name))) (g '(list a (quote a))) (f '`(a ,(+ 1 2) ,@(map abs '(4 -5 6)) b)) (g '(a 3 4 5 6 b)) (f '`((foo ,(- 10 3)) ,@(cdr '(c)) . ,(car '(cons)))) (g '((foo 7) . cons)) (f '`#(10 5 ,(sqrt 4) ,@(map sqrt '(16 9)) 8)) (g '#(10 5 2 4 3 8)) ;(f '(let ((who "hoo") ; (are "r") ; (you "u")) ; `#(#(,who ,are ,you) ; #(,@(list you are who)) ; #(you are who?)))) ;(g '#(#("hoo" "r" "u") #("u" "r" "hoo") #(you are who?))) ; Tests of the ::: escape symbol. ; This syntax of set*! matches the syntax of an example in ; Clinger, "Macros in Scheme". It is a slightly more difficult ; syntax than the syntax in R4RS. ; Note that pattern variables within the scope of the ::: are ; still expanded, so the auxiliary macro's pattern variables ; must be different from those of the outer macro. (f '(define-syntax set*! (syntax-rules () ((set*! i1 e1 more ...) (letrec-syntax ((set*!-aux (::: (syntax-rules () ((set*!-aux ((i1_ e1_ t1) ...)) (let ((t1 e1_) ...) (set! i1_ t1) ...)) ((set*!-aux ((i1_ e1_ t1) ...) i2 e2 more_ ...) (set*!-aux ((i1_ e1_ t1) ... (i2 e2 newtemp)) more_ ...)))))) (set*!-aux () i1 e1 more ...)))))) (f '(let ((x 3) (y 4) (z 5)) (set*! x (+ x y z) y (- x y z) z (* x y z)) (list x y z))) (g '(12 -6 60)) ; Tests of the scoping extension. (f '(define-syntax set! let* (syntax-rules (car cdr vector-ref) ((set! (car x) y) (set-car! x y)) ((set! (cdr x) y) (set-cdr! x y)) ((set! (vector-ref x e) y) (vector-set! x e y)) ((set! x y) (set! x y))))) (f '(let* ((days (list 'monday 'wednesday 'friday)) (day1 '(sunday))) (set! (car days) 'tuesday) (set! day1 (car days)) day1)) (g 'tuesday) (f '(define-syntax set! let* (syntax-rules (string-ref) ((set! (string-ref x e) y) (string-set! x e y)) ((set! x y) (set! x y))))) (f '(let* ((o (make-string 3 #\o)) (v (vector o o o)) (s "woo")) (set! (string-ref o 0) #\h) (set! (vector-ref v 0) "boo") (set! s (string-append (vector-ref v 0) (vector-ref v 1) s)) s)) (g '"boohoowoo")
true
1a7b05b48552cc0099d89fa527244c4f989fe61b
c763eaf97ffd7226a70d2f9a77465cbeae8937a8
/scheme/test/test-parsing.scm
be1952b1fa09d0e88acc44acc4bfff9e07b12a14
[]
no_license
jhidding/crossword
66907f12e87593a0b72f234ebfabbd2fb56dae9c
b3084b6b1046eb0a996143db1a144fd32379916f
refs/heads/master
2020-12-02T19:33:08.677722
2017-08-21T21:07:43
2017-08-21T21:07:43
96,357,240
1
0
null
null
null
null
UTF-8
Scheme
false
false
1,135
scm
test-parsing.scm
(import (rnrs (6)) (parsing parsing)) (let* ((stream (open-string-input-port "abc"))) (display (parse (return 1) stream)) (newline) (display (parse failure stream)) (newline) (display (parse item stream)) (newline)) (let* ((stream (open-string-input-port "abc")) (p (seq (x <- item) item (y <- item) (return (cons x y))))) (display (parse p stream)) (newline)) (let* ((stream (open-string-input-port "abc")) (p whitespace-char)) (display (parse p stream)) (newline)) (let* ((stream (open-string-input-port "abc")) (p (choice failure alphabetic-char))) (display (parse p stream)) (newline)) (let* ((stream (open-string-input-port "abc")) (p (is-string "abc"))) (display (parse p stream)) (newline)) (let* ((stream (open-string-input-port "abc")) (p (is-string "abx"))) (display (parse p stream)) (newline)) (let* ((stream (open-string-input-port "abc")) (p (many alphabetic-char))) (display (parse p stream)) (newline)) (let* ((stream (open-string-input-port "123"))) (display (parse number stream)) (newline))
false
f61cc53cc51b571b8581c559b709a45427ff6287
0021f53aa702f11464522ed4dff16b0f1292576e
/scm/p51.scm
7a78cd1b350455f3757403f5bfd7674ed47074a6
[]
no_license
mtsuyugu/euler
fe40dffbab1e45a4a2a297c34b729fb567b2dbf2
4b17df3916f1368eff44d6bc36202de4dea3baf7
refs/heads/master
2021-01-18T14:10:49.908612
2016-10-07T15:35:45
2016-10-07T15:35:45
3,059,459
0
0
null
null
null
null
UTF-8
Scheme
false
false
1,879
scm
p51.scm
(use srfi-13) (use text.tr) (load "./eratosthenes.scm") (define (p51) (define N 1000000) (eratosthenes N) (let ((prime-list (prime-list-less-than N))) (letrec ((keta (^n (string-length (number->string n)))) (replace (lambda (num x n) (string->number (apply string-tr (map number->string (list num x n)))))) (check (lambda (p x replace-nums) (let ((result (filter (^x x) (map (lambda (n) (let ((result (replace p x n))) (if (and (= (keta p) (keta result)) (prime? result)) result #f))) replace-nums)))) (if (>= (length result) 7) (apply min p result) #f)))) (iter (lambda (prime-list) (let* ((p (car prime-list)) (str-p (number->string p)) (result (and (prime? p) (or (and (>= (string-count str-p #\0) 2) (check p 0 (list 1 2 3 4 5 6 7 8 9))) (and (>= (string-count str-p #\1) 2) (check p 1 (list 0 2 3 4 5 6 7 8 9))) (and (>= (string-count str-p #\2) 2) (check p 2 (list 0 1 3 4 5 6 7 8 9))))))) (if result result (iter (cdr prime-list))))))) (iter prime-list)))) (print (p51))
false
a58177152b773ab2db17e0e1dd32c121129179d1
94cf31966ccd2721b6f4553a0ac1daa75bfc7b5a
/iterator.scm
7ff79625f3fa98a6e311942a47a277cc78140aee
[]
no_license
helmutkian/SchIt
c8cd4ff5bf087a35be9fcd3479a3aed362f8a100
be68970698e9f65d51ba27bd4108d5ee7c8d9052
refs/heads/master
2020-05-18T18:16:01.169361
2012-03-12T17:50:38
2012-03-12T17:50:38
3,675,017
0
0
null
null
null
null
UTF-8
Scheme
false
false
5,067
scm
iterator.scm
(use (srfi 1 69) vector-lib) ;; Redefines call-with-current-continuation to a shorter name call/cc (define call/cc call-with-current-continuation) ;; Creates a (call/cc (lambda (...) ...)) form (define-syntax let/cc (syntax-rules () ((_ cont-name body ...) (call/cc (lambda (cont-name) body ...))))) ;; Creates an alist from the sublists provided (define-syntax alist (syntax-rules () ((_ (k0 ...) ...) (list (list k0 ...) ...)))) ;; Pushes an object onto a list (define-syntax push! (syntax-rules () ((_ obj lst) (set! lst (cons obj lst))))) ;; Alist associating a collection predicate (ie list? vector? hash?) ;; with an internal iterator and an unpacking function, used to dynamically ;; dispatch make-iterator on a type. (define coll-iterator-list (alist (list? for-each first) (vector? vector-for-each second) ;(hash-table? (lambda (proc hash) (hash-table-walk hash proc)) (lambda x x)) )) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; make-generic-iterator : collection procedure procedure -> procedure ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; make-generic-iterator takes in a collection, its internal iterator, and ;; an unpacking function and returns an external iterator. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; IN: ;; coll -- A collection ;; in-itor -- An internal iterator ;; unpack -- An unpacking function ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; OUT: ;; Returns an external iterator on the collections ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (define (make-generic-iterator coll in-itor unpack) (define (iter) (call/cc control-state)) (define (control-state return) (in-itor (lambda current-state ;; Bind returning continuation to intermediate state (set! return ;; Create new intermediate state (let/cc resume-state ;; Redefine current continuation as intermediate state (set! control-state resume-state) ;; Return current state to calling continuation (return (unpack current-state))))) coll) ;; When continuation is exhausted return false (return #f)) iter) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; define-iterator : procedure procedure procedure -> side-effect ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; define-iterator takes a type predicate, an internal iterator, and an unpacking ;; function and allows for run-time dispatching of make-iterator on a collection ;; that returns #t when the type predicate is applied to it. It does so by ;; pushing a list associating these procedures onto the coll-iterator-list alist ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; IN: ;; type? -- type predicate ;; in-itor -- internal iterator, must not return any values but only allow for ;; side effects ;; unpack -- unpacking function ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; OUT: ;; Associates the type predicate with its internal iterator and unpacking ;; functions which allows run-time dispatch of make-iterator on the collections ;; of that type. Pushes the list containing the associated procedures onto ;; coll-iterator-list. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (define (define-iterator type? in-itor unpack) (push! (list type? in-itor unpack) coll-iterator-list)) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; make-iterator : collection -> procedure ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; make-iterator takes a collection, then creates the appropriate iterator for the ;; collection type by looking up the internal iterator and unpacking function ;; associated with its type predicate. If no type predicate returns true on the ;; collection, then an error is raised. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; IN: ;; coll -- A collection ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; OUT: ;; Returns an external iterator for the collection. If none has been defined, ;; then it raises an error. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (define (make-iterator coll) (let loop ((itors coll-iterator-list)) (if (null? itors) (error "No internal iterator for type") (let* ((head (first itors)) (type? (first head)) (in-itor (second head)) (unpack (third head))) (if (type? coll) (make-generic-iterator coll in-itor unpack) (loop (cdr itors)))))))
true
3aba869769006df987b637733db473757b7fdf93
9d7417f187812a477793ca23da844b34ab2a139d
/Graphikos/GraphikosTests/lib/ironscheme/random.sls
a9dda06f575569970f2946df91fdf014c8231d82
[ "MIT", "BSD-3-Clause" ]
permissive
simonmoriat/PLP
5ae19daba4925919b593b4a21dc91dec9de9a6ce
3d130acaa45239cdb289462a242a8c15836a39ca
refs/heads/master
2023-05-11T23:36:28.347462
2016-06-08T07:07:50
2016-06-08T07:07:50
null
0
0
null
null
null
null
UTF-8
Scheme
false
false
1,211
sls
random.sls
#| License Copyright (c) 2007-2015 Llewellyn Pritchard All rights reserved. This source code is subject to terms and conditions of the BSD License. See docs/license.txt. |# (library (ironscheme random) (export make-random next-fixnum next-bytevector next-flonum random) (import (rnrs) (ironscheme contracts) (ironscheme clr)) (define (rng? obj) (clr-is Random obj)) (define/contract make-random (case-lambda [() (clr-new Random)] [(seed:fixnum) (clr-new Random seed)])) (define/contract next-fixnum (case-lambda [(rg:rng) (clr-call Random Next rg)] [(rg:rng max:fixnum) (clr-call Random Next rg max)] [(rg:rng min:fixnum max:fixnum) (clr-call Random Next rg min max)])) (define/contract (next-bytevector rg:rng bytevector:bytevector) (clr-call Random NextBytes rg bytevector)) (define/contract (next-flonum rg:rng) (clr-call Random NextDouble rg)) ; make parameter like in Racket? (define rng (make-random)) (define/contract random (case-lambda [() (next-flonum rng)] [(n:fixnum) (next-fixnum rng n)])))
false
adf055eddeb900b6e43416ef1a948d707bd5a200
1ed47579ca9136f3f2b25bda1610c834ab12a386
/sec3/q3.15.scm
6edd55e2beea4efae6ba9a63f0a2a913233ef189
[]
no_license
thash/sicp
7e89cf020e2bf5ca50543d10fa89eb1440f700fb
3fc7a87d06eccbe4dcd634406e3b400d9405e9c4
refs/heads/master
2021-05-28T16:29:26.617617
2014-09-15T21:19:23
2014-09-15T21:19:23
3,238,591
0
1
null
null
null
null
UTF-8
Scheme
false
false
323
scm
q3.15.scm
;; sec3.3.scm のz1とz2へのset-to-wow!の効果を説明する箱とポインタをかけ ;; z1: http://www.evernote.com/shard/s11/sh/6f543d63-a585-48e0-9f19-4f9e3698a0eb/9ca6e1e04c69c6b815e145bfe8fe2d4b ;; z2: http://www.evernote.com/shard/s11/sh/57f0d2b1-a3e6-4bf0-a830-8f57c863c3ca/b6dc6b0c2cd165e3150f8c196945f960
false
6857df897f4df6e0721b27a039370581543a0dde
33c1c3b02d092df18cc1cad7a72d5375d5bd524b
/src/lib/stdlib.scm
69137d3fb409e158d211f6ad68866d81c08568cd
[]
no_license
emptyland/ajimu
5a3601366ca52becfc3085390aa3307fdb6734d4
1747465c7d0e0a4dc9e6804f6c685f5ab9c7e677
refs/heads/master
2020-07-04T04:01:14.154418
2014-10-23T08:59:53
2014-10-23T08:59:53
null
0
0
null
null
null
null
UTF-8
Scheme
false
false
982
scm
stdlib.scm
; Basic syntax definition: (define-syntax let (syntax-rules () ((_ ((var val) ...) body ...) ((lambda (var ...) body ...) val ...)) ((_ name ((var val) ...) body ...) ((let ((name #f)) (set! name (lambda (var ...) body ...)) name) val ...)))) (define-syntax not (syntax-rules () ((_ test) (if test #f #t)))) (define-syntax cond (syntax-rules (else) ((_ (else expr ...)) (begin expr ...)) ((_ (test expr ...)) (if test (begin expr ...))) ((_ (test expr ...) rest ...) (if test (begin expr ...) (cond rest ...))))) ; Produre definition (define (number? obj) (or (integer? obj) (real? obj))) (define (caar lst) (car (car lst))) (define (cadr lst) (car (cdr lst))) (define (cdar lst) (cdr (car lst))) (define (cddr lst) (cdr (cdr lst))) (define (>= lhs rhs) (and (= lhs rsh) (> lhs rhs))) (define (<= lhs rhs) (and (= lhs rsh) (< lhs rhs))) (define (for-each f l) (if (null? l) #t (begin (f (car l)) (for-each f (cdr l)))))
true
754848860d3ad2f6c1e3ffed0c649fe60adae910
f956337abdb990945eb91fa03a889b122bbad8c1
/extra/list.scm
ddd6c9b6759846fbb1b8239b9d78822d75975daa
[]
no_license
ayatoy/Gauche-extra
86036a9050a27cd665e1b5d267753b7c3c3c0f07
7242e738fb9900d08db24854a7b72d64dbe1b479
refs/heads/master
2021-01-19T22:13:49.464319
2012-05-29T11:41:28
2012-05-29T11:42:01
null
0
0
null
null
null
null
UTF-8
Scheme
false
false
4,527
scm
list.scm
(define-module extra.list (use gauche.collection) (use gauche.threads) (use srfi-1) (use control.job) (use control.thread-pool) (use sxml.ssax) (use util.list) (use util.queue) (export alist % alref alput alcut set-keyword set-keywords set-keywords* thread-pool-map thread-pool-map1 thread-pool-track-map lset-similar)) (select-module extra.list) ;;;; alist (define (alist . kvs) (reverse (fold (^[kv r] (cons (cons (car kv) (cadr kv)) r)) '() (slices kvs 2)))) (define % alist) (define (alref alist . ks) (fold (^[k alist] (and (list? alist) (assoc-ref alist k))) alist ks)) (define (alset alist . args) ) (define (aldel alist . ks) ) (define (alput1 alist k v) (let loop ([alist alist] [acc '()] [e #f]) (if (null? alist) (reverse (or (and e acc) (cons (cons k v) acc))) (let* ([x (car alist)] [k1 (car x)] [p (equal? k k1)]) (loop (cdr alist) (cons (cons k1 (if p v (cdr x))) acc) (or e p)))))) (define (alput alist . kvs) (fold (^[kv r] (apply alput1 r kv)) alist (slices kvs 2))) (define (alcut alist . ks) (reverse (fold (^[kv r] (let1 k (car kv) (if (any (^[x] (equal? k x)) ks) r (cons kv r)))) '() alist))) ;;;; keywords (define (set-keyword key kv-list obj) `(,@(delete-keyword key kv-list) ,key ,obj)) (define (set-keywords keys kv-list) (fold (^[key kv-list] (set-keyword (car key) kv-list (cadr key))) kv-list (slices keys 2))) (define (set-keywords* kv-list . keys) (let loop ((kv-list kv-list) (keys keys)) (if (null? keys) kv-list (loop (set-keywords (car keys) kv-list) (cdr keys))))) ;;;; mt (define (thread-pool-map size proc col . cols) (let* ([pool (make-thread-pool size)] [jobs (apply map (^ args (add-job! pool (^[] (apply proc args)) #f)) (cons col cols))]) (when (wait-all pool) (begin0 (map job-result jobs) (terminate-all! pool))))) (define (thread-pool-map1 proc col :key (size 1) (force-timeout #f) (force-timeout-val #f)) (let* ([pool (make-thread-pool size)] [jobs (map (^[x] (add-job! pool (^[] (proc x)) #f)) col)]) (terminate-all! pool :force-timeout force-timeout) (map (^[job] (let1 status (job-status job) (case status [(done error) (job-result job)] [else force-timeout-val]))) jobs))) (define (track-for-each proc col :key (key identity) (test eqv?) (interval #e5e8)) (let1 ht (make-hash-table 'eq?) (for-each (^[g] (hash-table-put! ht (list->queue g) 0)) (group-collection col :key key :test test)) (let loop () (unless (= (hash-table-num-entries ht) 0) (sys-nanosleep interval) (hash-table-for-each ht (^[q x] (cond [(= (queue-length q) 0) (hash-table-delete! ht q)] [else (proc (dequeue! q))]))) (loop))))) (define (thread-pool-track-map proc col :key (size 1) (key identity) (test eqv?) (interval #e5e8) (timeout #f) (timeout-val #f)) (let ([pool (make-thread-pool size)] [jobs (make-queue)]) (track-for-each (^[x] (enqueue! jobs (add-job! pool (^[] (proc x)) #f))) col :key key :test test :interval interval) (terminate-all! pool :force-timeout timeout) (map (^[job] (let1 status (job-status job) (case status [(done error) (job-result job)] [else timeout-val]))) (queue->list jobs)))) ;;;; lset (define (lset-similar . lsets) (/ (* (length lsets) (length (apply lset-intersection equal? lsets))) (apply + (map length lsets))))
false
42a39f3d4a54c30c7af64b467335e46a966807a2
e92f708d2ca39757df4cf7e7d0d8f4ebb8bab0eb
/scheme-transforms-master/scheme-transforms-master/transforms/letrec-to-set.ss
9c17b8dc663dfc695a5925a07270021a969b7d8c
[]
no_license
orthometa/304final
503d67345820cb769abedbc49c7029e90874f5b9
114eb45edeaf1a876f4c0a55f6d24213a589f35e
refs/heads/master
2020-03-18T12:57:52.580186
2018-05-24T18:23:08
2018-05-24T18:23:08
134,753,121
0
0
null
null
null
null
UTF-8
Scheme
false
false
1,565
ss
letrec-to-set.ss
#!r6rs ;; Letrec to Set ;; input language: ;; tag | top-level-begin-define | self-eval | primitive | lambda | if | (A B) | begin | set! | letrec ;; output language: ;; tag | top-level-begin-define | self-eval | primitive | lambda | if | (A B) | begin | set! (library (transforms letrec-to-set) (export letrec-to-set) (import (rnrs) (scheme-tools srfi-compat :1) (transforms syntax) (transforms utils) (transforms common)) (define primitives (make-parameter '())) (define (primitive? var) (memq var (primitives))) (define (lrs e) (cond [(definition? e) (error e "letrec-to-set: cannot handle expr type")] [(tag? e) (make-tag (lrs (tag->expr e)) (tag->name e))] [(primitive? e) e] [(self-evaluating? e) e] [(lambda? e) `(lambda ,(lambda->args e) ,(lrs (lambda->body e)))] [(letrec? e) (let* ([defns (letrec->defns e)] [names (map def->name defns)] [vals (map def->val defns)]) `((lambda ,names (begin ,@(map (lambda (n v) `(set! ,n ,(lrs v))) names vals) ,(lrs (letrec->body e)))) ,@(make-list (length names) '#f)))] [(or (if? e) (begin? e) (set? e) (definition? e)) (mapsub lrs e)] [(application? e) (map lrs e)] [else (error e "letrec-to-set: cannot handle expr type")])) (define (top-lrs e) ((begin-define-transform (lambda (def) (mapsub lrs def)) lrs) e)) (define (letrec-to-set e) (parameterize ([primitives (get-primitives e)]) (top-lrs e))) )
false
c62cb57ef2ed41fa7a23ed049fa8729106dbb148
b9d0fc9d5d0d135aadd1e4644b45004fd2c94b94
/scheme/hashes/.svn/text-base/ELFHash.scm.svn-base
ed0b69e8e49a5e67cdf33058b75e6f9029638622
[]
no_license
alvatar/snippets
f704413d39b6c9363e1c435444ec82e270184f75
89ce0c71ff1554a9307ed0726b84dfa5782babe6
refs/heads/master
2021-06-28T21:59:15.358791
2016-10-25T16:26:52
2016-10-25T16:26:52
2,073,559
1
0
null
null
null
null
UTF-8
Scheme
false
false
884
ELFHash.scm.svn-base
;;;; ELFHash.scm ;;;; Kon Lovett, Jan '06 (module ELFHash (;export *ELFHash ELFHash ELFHash-primitive ) (import scheme chicken foreign) (use message-digest hashes-support hash-utils) #> #include "hashes.h" /* * Similar to the PJW Hash function, but tweaked for 32-bit processors. * It's the hash function widely used on most UNIX systems. */ static uint32_t ELFHash( uint8_t *data, uint32_t length, uint32_t key ) { if (data) { for ( ; length; data++, length--) { uint32_t test; key = (key << 4) + ((uint32_t) *data); if ((test = (key & 0xF0000000L))) { key ^= (test >> 24); key &= ~test; } } } return key; } #undef bitsizeof <# (include "hashes-macros") (gen-hash-api ELFHash) (gen-update-proc ELFHash) (gen-md-api ELFHash) ) ;module ELFHash
false
6e8d39cf73e033acabe42f0236093837213c0fa3
2bcf33718a53f5a938fd82bd0d484a423ff308d3
/programming/sicp/ch3/ex-3.26.scm
e1df51b1b97cb0aa70701af63d8472e848121112
[]
no_license
prurph/teach-yourself-cs
50e598a0c781d79ff294434db0430f7f2c12ff53
4ce98ebab5a905ea1808b8785949ecb52eee0736
refs/heads/main
2023-08-30T06:28:22.247659
2021-10-17T18:27:26
2021-10-17T18:27:26
345,412,092
0
0
null
null
null
null
UTF-8
Scheme
false
false
2,216
scm
ex-3.26.scm
#lang sicp ;; https://mitpress.mit.edu/sites/default/files/sicp/full-text/book/book-Z-H-22.html#%_thm_3.26 ;; Inspired by ../ch2/set-as-tree.scm, but with kv pairs as the "entry" of each ;; tree node. (define (tree-entry tree) (car tree)) (define (tree-key tree) (car (tree-entry tree))) (define (tree-value tree) (cdr (tree-entry tree))) (define (left-branch tree) (cadr tree)) (define (right-branch tree) (caddr tree)) (define (make-tree entry left right) (list entry left right)) (define (make-table compare) (define local-table (list '*table*)) (define (lookup key tree) (if (null? tree) #f (let ((cmp (compare key (tree-key tree)))) (cond ((< 0 cmp) (lookup key (left-branch tree))) ((> 0 cmp) (lookup key (right-branch tree))) (else (tree-value tree)))))) (define (insert! key value) (define (tree-add key value tree) (if (null? tree) (make-tree (cons key value) '() '()) (let ((cmp (compare key (tree-key tree)))) (cond ((< 0 cmp) (make-tree (tree-entry tree) (left-branch tree) (tree-add key value (right-branch tree)))) ((> 0 cmp) (make-tree (tree-entry tree) (tree-add key value (left-branch tree)) (right-branch tree))) (else (set-cdr! (tree-entry tree) value) tree))))) (set-cdr! local-table (tree-add key value (cdr local-table))) 'ok) (define (dispatch m) (cond ((eq? m 'lookup-proc) (lambda (key) (lookup key (cdr local-table)))) ((eq? m 'insert-proc!) insert!) ((eq? m 'table) local-table) (else (error "Unknown operation: TABLE" m)))) dispatch) (define (cmp a b) (cond ((< a b) -1) ((> a b) 1) (else 0))) (define table (make-table cmp)) (define get (table 'lookup-proc)) (define put (table 'insert-proc!)) (put 1 'one) (put 5 'five) (put 2 'two) (put 4 'four) (put 3 'three) (put 10 'ten) (get 1) (get 42) (table 'table) ;; Quick hack to use in ex-3.27.scm (#%provide make-table) (#%provide cmp)
false
4c277ccb2bd42a309113f578cc9fcb48b12da8e9
a607e499c18aea91ae4a6f812647dc8c7bde14e3
/ast.ss
b0a1c88b8e3e1c56cfc0a50eaf8ba8d1ebb4b0a5
[ "MIT" ]
permissive
EddieIvan01/yakult
0bae3eb9689e3b210b86f07bc17cb82922216dec
c2634e930b9b13f2d7e729cfd1e83c2a79cbb94f
refs/heads/master
2021-01-09T11:06:24.088990
2020-02-22T04:06:45
2020-02-22T04:06:45
242,276,853
0
0
null
null
null
null
UTF-8
Scheme
false
false
4,248
ss
ast.ss
#!chezscheme (library (ast) (export export make-ast::define ast::define? ast::define-name ast::define-value make-ast::assign ast::assign? ast::assign-name ast::assign-value make-ast::if ast::if? ast::if-condition ast::if-body make-ast::switch ast::switch? ast::switch-value ast::switch-cases make-ast::cond ast::cond? ast::cond-cases make-ast::while ast::while? ast::while-condition ast::while-body make-ast::subs ast::subs? ast::subs-name ast::subs-index make-ast::func ast::func? ast::func-name ast::func-body make-ast::invoke ast::invoke? ast::invoke-func ast::invoke-args make-ast::class ast::class? ast::class-name ast::class-attr ast::class-method make-ast::attr ast::attr? ast::attr-name ast::attr-field make-ast::list ast::list? ast::list-value make-ast::vec ast::vec? ast::vec-value make-ast::hashtable ast::hashtable? ast::hashtable-value make-ast::+ ast::+? ast::+-left ast::+-right make-ast::- ast::-? ast::--left ast::--right make-ast::* ast::*? ast::*-left ast::*-right make-ast::/ ast::/? ast::/-left ast::/-right make-ast::% ast::%? ast::%-left ast::%-right make-ast::** ast::**? ast::**-left ast::**-right make-ast::== ast::==? ast::==-left ast::==-right make-ast::< ast::<? ast::<-left ast::<-right make-ast::> ast::>? ast::>-left ast::>-right make-ast::<= ast::<=? ast::<=-left ast::<=-right make-ast::>= ast::>=? ast::>=-left ast::>=-right make-ast::^ ast::^? ast::^-left ast::^-right make-ast::& ast::&? ast::&-left ast::&-right make-ast::\| ast::\|? ast::\|-left ast::\|-right make-ast::&& ast::&&? ast::&&-left ast::&&-right make-ast::\|\| ast::\|\|? ast::\|\|-left ast::\|\|-right make-ast::!= ast::!=? ast::!=-left ast::!=-right make-ast::! ast::!? ast::!-right make-ast::++ ast::++? ast::++-left ) (import (chezscheme)) (define-record-type ast::define (fields name value)) (define-record-type ast::assign (fields name value)) (define-record-type ast::if (fields condition body)) (define-record-type ast::switch (fields value cases)) (define-record-type ast::cond (fields cases)) (define-record-type ast::while (fields condition body)) (define-record-type ast::subs (fields name index)) (define-record-type ast::func (fields name body)) (define-record-type ast::invoke (fields func args)) (define-record-type ast::class (fields name attr method)) (define-record-type ast::attr (fields name field)) (define-record-type ast::list (fields value)) (define-record-type ast::vec (fields value)) (define-record-type ast::hashtable (fields value)) ;; + - * / % ** ++ ;; == != < > <= >= ;; ^ & | ;; && || ! (define-record-type ast::+ (fields left right)) (define-record-type ast::- (fields left right)) (define-record-type ast::* (fields left right)) (define-record-type ast::/ (fields left right)) (define-record-type ast::% (fields left right)) (define-record-type ast::** (fields left right)) (define-record-type ast::== (fields left right)) (define-record-type ast::!= (fields left right)) (define-record-type ast::< (fields left right)) (define-record-type ast::> (fields left right)) (define-record-type ast::<= (fields left right)) (define-record-type ast::>= (fields left right)) (define-record-type ast::& (fields left right)) (define-record-type ast::\| (fields left right)) (define-record-type ast::^ (fields left right)) (define-record-type ast::&& (fields left right)) (define-record-type ast::\|\| (fields left right)) (define-record-type ast::++ (fields left)) (define-record-type ast::! (fields right)) )
false
ca8eb50a9422a1855010bb1d069ef7ee7a3b27de
acc632afe0d8d8b94b781beb1442bbf3b1488d22
/helpers.scm
4f11fd61278b3e0826bab1fdb30a05645169c26b
[]
no_license
kdltr/life-is-so-pretty
6cc6e6c6e590dda30c40fdbfd42a5a3a23644794
5edccf86702a543d78f8c7e0f6ae544a1b9870cd
refs/heads/master
2021-01-20T21:12:00.963219
2016-05-13T12:19:02
2016-05-13T12:19:02
61,128,206
1
0
null
null
null
null
UTF-8
Scheme
false
false
195
scm
helpers.scm
(define (random-elt l) (list-ref l (random (length l)))) (define (permutation l) (if (null? l) '() (let ((elt (random-elt l))) (cons elt (permutation (delete elt l))))))
false
a3a5160b0fd659526c599880b47630e2f5bf2c83
53cb8287b8b44063adcfbd02f9736b109e54f001
/top/top.scm
df0da25720d2019bc47f441cd12746476c349fce
[]
no_license
fiddlerwoaroof/yale-haskell-reboot
72aa8fcd2ab7346a4990795621b258651c6d6c39
339b7d85e940db0b8cb81759e44abbb254c54aad
refs/heads/master
2021-06-22T10:32:25.076594
2020-10-30T00:00:31
2020-10-30T00:00:31
92,361,235
3
0
null
null
null
null
UTF-8
Scheme
false
false
1,136
scm
top.scm
;;; top.scm -- compilation unit definition for the top level ;;; Global includes the ast definitions and all global data structures ;;; used in the compiler. (define-compilation-unit global (source-filename "top/") (require ast) (unit has-utils (source-filename "has-utils.scm")) (unit core-definitions (require has-utils) (source-filename "core-definitions.scm")) (unit core-symbols (require core-definitions) (source-filename "core-symbols.scm")) (unit core-init (require core-symbols) (source-filename "core-init.scm")) (unit globals (require core-init) (source-filename "globals.scm")) (unit has-macros (source-filename "has-macros.scm")) ) ;;; These files do not need to be required by other units (define-compilation-unit top-level (source-filename "top/") (require global) (unit phases (source-filename "phases.scm")) (unit system-init (source-filename "system-init.scm")) (unit errors (source-filename "errors.scm")) (unit tuple (source-filename "tuple.scm")) (unit symbol-table (source-filename "symbol-table.scm")) )
false
1639e01ef7e79156567be207e6f8718572ae9f52
eef5f68873f7d5658c7c500846ce7752a6f45f69
/spheres/structure/red-black-tree.sld
d5a4f881a952820ba3d352575b2f383536cbdae3
[ "MIT" ]
permissive
alvatar/spheres
c0601a157ddce270c06b7b58473b20b7417a08d9
568836f234a469ef70c69f4a2d9b56d41c3fc5bd
refs/heads/master
2021-06-01T15:59:32.277602
2021-03-18T21:21:43
2021-03-18T21:21:43
25,094,121
13
3
null
null
null
null
UTF-8
Scheme
false
false
14,253
sld
red-black-tree.sld
;;!!! Red-black tree ;; .author Marc Feeley, 2000-2007 ;; .author Massachusetts Institute of Technology, 1993-2000 ;; .license lgpl/v2.1 ;; ;; File: "rbtree.scm", Time-stamp: <2007-04-05 18:53:11 feeley> ;; ;; Copyright (c) 2000-2007 by Marc Feeley, All Rights Reserved. ;; Copyright (c) 1993-2000 Massachusetts Institute of Technology. ;; ;; This red-black tree implementation is inspired by the code ;; in the MIT-Scheme runtime (file "rbtree.scm"). That code is ;; based on the algorithms presented in the book "Introduction to ;; Algorithms" by Cormen, Leiserson, and Rivest. ;; ;; The main differences with the MIT-Scheme code are: ;; ;; 1) Nil pointers are replaced by a special sentinel that is also ;; the cell that contains a pointer (in the "left child" field) ;; to the root of the red-black tree. The "right child" field of ;; the sentinel is never accessed. The sentinel is black. ;; ;; 2) The color field contains #f when the node is red and a ;; reference to the sentinel when the node is black. It is thus ;; possible to find the sentinel from any node in constant time ;; (if the node is black extract the color field, otherwise ;; extract the color field of the parent, which must be black). ;; ;; 3) One field of the sentinel always points to the leftmost node of ;; the red-black tree. This allows constant time access to the ;; "minimum" node, which is a frequent operation of priority queues. ;; ;; 4) Several cases are handled specially (see the code for details). ;; ;; 5) Macros are used to generate code specialized for each case of ;; symmetrical operations (e.g. left and right rotation). ;; ;; 6) Nodes are assumed to be preallocated. Inserting and deleting a ;; node from a red-black tree does not perform any heap ;; allocation. Moreover, all algorithms consume a constant amount ;; of stack space. (define-library (spheres/structure red-black-tree) (export define-rbtree) (define-macro (define-rbtree rbtree-init! node->rbtree insert! remove! reposition! empty? singleton? before? color color-set! parent parent-set! left left-set! right right-set! leftmost leftmost-set! rightmost rightmost-set!) (define (black rbtree) rbtree) (define (black? rbtree) `(lambda (node) (,color node))) (define (blacken! rbtree) `(lambda (node) (,color-set! node ,(black rbtree)))) (define (red) #f) (define (red?) `(lambda (node) (not (,color node)))) (define (reden!) `(lambda (node) (,color-set! node ,(red)))) (define (copy-color!) `(lambda (node1 node2) (,color-set! node1 (,color node2)))) (define (exchange-color!) `(lambda (node1 node2) (let ((color-node1 (,color node1))) (,color-set! node1 (,color node2)) (,color-set! node2 color-node1)))) (define (update-parent!) `(lambda (parent-node old-node new-node) (if (eq? old-node (,left parent-node)) (,left-set! parent-node new-node) (,right-set! parent-node new-node)))) (define (rotate! side1 side1-set! side2 side2-set!) `(lambda (node) (let ((side2-node (,side2 node))) (let ((side1-side2-node (,side1 side2-node))) (,side2-set! node side1-side2-node) (,parent-set! side1-side2-node node)) (let ((parent-node (,parent node))) (,side1-set! side2-node node) (,parent-set! node side2-node) (,parent-set! side2-node parent-node) (,(update-parent!) parent-node node side2-node))))) (define (rotate-left!) (rotate! left left-set! right right-set!)) (define (rotate-right!) (rotate! right right-set! left left-set!)) (define (neighbor side other-side) `(lambda (node rbtree) (let ((side-node (,side node))) (if (eq? side-node rbtree) (let ((parent-node (,parent node))) (if (or (eq? parent-node rbtree) (eq? node (,side parent-node))) rbtree parent-node)) (let loop ((x side-node)) (let ((other-side-x (,other-side x))) (if (eq? other-side-x rbtree) x (loop other-side-x)))))))) (define (insert-below! x) `(let ((x ,x)) (if (,before? node x) (insert-left! (,left x) x) (insert-right! (,right x) x)))) (define (insert-body side1 rotate-side1! side2 rotate-side2!) `(let ((side2-parent-parent-x (,side2 parent-parent-x))) (if (,(red?) side2-parent-parent-x) (begin (,(blacken! 'rbtree) parent-x) (,(blacken! 'rbtree) side2-parent-parent-x) (,(reden!) parent-parent-x) (loop parent-parent-x)) (let ((y (if (eq? x (,side2 parent-x)) (begin (,rotate-side1! parent-x) (,parent parent-x)) (,parent x)))) (,(blacken! 'rbtree) y) (let ((parent-y (,parent y))) (,(reden!) parent-y) (,rotate-side2! parent-y)))))) (define (remove-body side1 rotate-side1! side2 rotate-side2!) `(let ((x (let ((side2-parent-node (,side2 parent-node))) (if (,(red?) side2-parent-node) (begin (,(blacken! 'rbtree) side2-parent-node) (,(reden!) parent-node) (,rotate-side1! parent-node) (,side2 parent-node)) side2-parent-node)))) (define (common-case y) (,(copy-color!) y parent-node) (,(blacken! 'rbtree) parent-node) (,(blacken! 'rbtree) (,side2 y)) (,rotate-side1! parent-node) (,(blacken! 'rbtree) (,left rbtree))) (if (,(red?) (,side2 x)) (common-case x) (let ((side1-x (,side1 x))) (if (,(black? 'rbtree) side1-x) (begin (,(reden!) x) (fixup! (,parent parent-node) parent-node)) (begin (,(blacken! 'rbtree) side1-x) (,(reden!) x) (,rotate-side2! x) (common-case (,side2 parent-node)))))))) `(begin (define (,rbtree-init! rbtree) ,@(if leftmost `((,leftmost-set! rbtree rbtree)) `()) (,(blacken! 'rbtree) rbtree) (,parent-set! rbtree rbtree) (,left-set! rbtree rbtree) rbtree) (define (,node->rbtree node) (or (,color node) (,color (,parent node)))) (define (,insert! rbtree node) (define (fixup!) (let loop ((x node)) (let ((parent-x (,parent x))) (if (,(red?) parent-x) (let ((parent-parent-x (,parent parent-x))) (if (eq? parent-x (,left parent-parent-x)) ,(insert-body left (rotate-left!) right (rotate-right!)) ,(insert-body right (rotate-right!) left (rotate-left!))))))) (,(blacken! 'rbtree) (,left rbtree)) #f) (define (insert-left! left-x x) (if (eq? left-x rbtree) (begin (,left-set! x node) (,parent-set! node x) ;; check if leftmost must be updated ,@(if leftmost `((if (eq? x (,leftmost rbtree)) (,leftmost-set! rbtree node))) `()) (fixup!)) ,(insert-below! 'left-x))) (define (insert-right! right-x x) (if (eq? right-x rbtree) (begin (,right-set! x node) (,parent-set! node x) ;; check if rightmost must be updated ,@(if rightmost `((if (eq? x (,rightmost rbtree)) (,rightmost-set! rbtree node))) `()) (fixup!)) ,(insert-below! 'right-x))) (,(reden!) node) (,left-set! node rbtree) (,right-set! node rbtree) (insert-left! (,left rbtree) rbtree) (,parent-set! rbtree rbtree) node) (define (,remove! node) (let ((rbtree (,node->rbtree node))) (define (fixup! parent-node node) (cond ((or (eq? parent-node rbtree) (,(red?) node)) (,(blacken! 'rbtree) node)) ((eq? node (,left parent-node)) ,(remove-body left (rotate-left!) right (rotate-right!))) (else ,(remove-body right (rotate-right!) left (rotate-left!))))) (let ((parent-node (,parent node)) (left-node (,left node)) (right-node (,right node))) (,parent-set! node #f) ;; to avoid leaks (,left-set! node #f) (,right-set! node #f) (cond ((eq? left-node rbtree) ;; check if leftmost must be updated ,@(if leftmost `((if (eq? node (,leftmost rbtree)) (,leftmost-set! rbtree (if (eq? right-node rbtree) parent-node right-node)))) `()) (,parent-set! right-node parent-node) (,(update-parent!) parent-node node right-node) (if (,(black? 'rbtree) node) (begin (,(reden!) node) ;; to avoid leaks (fixup! parent-node right-node)))) ((eq? right-node rbtree) ;; check if rightmost must be updated ,@(if rightmost `((if (eq? node (,rightmost rbtree)) (,rightmost-set! rbtree left-node))) `()) (,parent-set! left-node parent-node) (,(update-parent!) parent-node node left-node) ;; At this point we know that the node is black. ;; This is because the right child is nil and the ;; left child is red (if the left child was black ;; the tree would not be balanced) (,(reden!) node) ;; to avoid leaks (fixup! parent-node left-node)) (else (let loop ((x right-node) (parent-x node)) (let ((left-x (,left x))) (if (eq? left-x rbtree) (begin (,(exchange-color!) x node) (,parent-set! left-node x) (,left-set! x left-node) (,parent-set! x parent-node) (,(update-parent!) parent-node node x) (if (eq? x right-node) (if (,(black? 'rbtree) node) (begin (,(reden!) node) ;; to avoid leaks (fixup! x (,right x)))) (let ((right-x (,right x))) (,parent-set! right-x parent-x) (,left-set! parent-x right-x) (,parent-set! right-node x) (,right-set! x right-node) (if (,(black? 'rbtree) node) (begin (,(reden!) node) ;; to avoid leaks (fixup! parent-x right-x)))))) (loop left-x x))))))) (,parent-set! rbtree rbtree))) (define (,reposition! node) (let* ((rbtree (,node->rbtree node)) (predecessor-node (,(neighbor left right) node rbtree)) (successor-node (,(neighbor right left) node rbtree))) (if (or (and (not (eq? predecessor-node rbtree)) (,before? node predecessor-node)) (and (not (eq? successor-node rbtree)) (,before? successor-node node))) (begin (,remove! node) (,insert! rbtree node))))) (define (,empty? rbtree) (eq? rbtree (,left rbtree))) (define (,singleton? rbtree) (let ((root (,left rbtree))) (and (not (eq? root rbtree)) (eq? (,left root) rbtree) (eq? (,right root) rbtree)))))))
false
26e74da20624570f4613ff0065358f9c00c659cf
0b1826093fb47c0a7293573d80f03a28e859640f
/chapter-2/ex-2.69.scm
f1fc26588af8addafc52135393f8e983cbe79f57
[ "MIT" ]
permissive
yysaki/sicp
253ef8ef52a330af6c2107ca7063773e63f1a4aa
36d2964c980c58ba13a2687e0af773a5e12d770d
refs/heads/master
2021-01-20T11:50:20.648783
2017-12-10T03:43:38
2017-12-10T08:08:18
56,677,496
0
0
null
null
null
null
UTF-8
Scheme
false
false
620
scm
ex-2.69.scm
(load "./ex-2.68") (define (generate-huffman-tree pairs) (successive-merge (make-leaf-set pairs))) (define (successive-merge leaf-set) (if (= (length leaf-set) 1) (car leaf-set) (successive-merge (adjoin-set (make-code-tree (car leaf-set) (cadr leaf-set)) (cddr leaf-set))))) ; (print (generate-huffman-tree '((C 1) (D 1) (E 1) (F 1) (G 1) (H 1) (B 3) (A 8)))) ; ((leaf A 8) ((((leaf H 1) (leaf G 1) (H G) 2) ((leaf F 1) (leaf E 1) (F E) 2) (H G F E) 4) (((leaf D 1) (leaf C 1) (D C) 2) (leaf B 3) (D C B) 5) (H G F E D C B) 9) (A H G F E D C B) 17)
false
0cbaac16907321108a9c9ef44b71b83754f5602f
6f7df1f0361204fb0ca039ccbff8f26335a45cd2
/scheme/tests/continuous-params.ss
63f8bdadccbdcb5101df047c901735ad8ee1d798
[]
no_license
LFY/bpm
f63c050d8a2080793cf270b03e6cf5661bf3599e
a3bce19d6258ad42dce6ffd4746570f0644a51b9
refs/heads/master
2021-01-18T13:04:03.191094
2012-09-25T10:31:25
2012-09-25T10:31:25
2,099,550
2
0
null
null
null
null
UTF-8
Scheme
false
false
1,856
ss
continuous-params.ss
(import (program-pl) (printing) (program) (prolog-serialize) (program-likelihood) (chart-parsing)) (define prog1 (make-program (list (make-named-abstraction 'F1 '(choose 3 1 2) '() )) '(lambda () (gauss (F1) (F1))))) (define test-query (list (pl-clause (pl-relation 'go) (pl-relation 'pTopLevel '4.4)))) (define prog1-relations (program->pl+features prog1)) (display-pl (append prog1-relations test-query)) (define test-data 4.4) (pretty-print (batch-run-inversion (list prog1) (list test-data) 'use-features)) '(((((2 4 6 7 8 9 10 11 12) ((1 (tree prog_0_F1 0 3 vars)) (2 (tree prog_0_TopLevel 0 1 vars (1) (1))) (3 (tree prog_0_F1 1 3 vars)) (4 (tree prog_0_TopLevel 0 1 vars (3) (1))) (5 (tree prog_0_F1 2 3 vars)) (6 (tree prog_0_TopLevel 0 1 vars (5) (1))) (7 (tree prog_0_TopLevel 0 1 vars (1) (3))) (8 (tree prog_0_TopLevel 0 1 vars (3) (3))) (9 (tree prog_0_TopLevel 0 1 vars (5) (3))) (10 (tree prog_0_TopLevel 0 1 vars (1) (5))) (11 (tree prog_0_TopLevel 0 1 vars (3) (5))) (12 (tree prog_0_TopLevel 0 1 vars (5) (5))))) (features ((2 (gauss 0 0 4.4)) (4 (gauss 0 1 4.4)) (6 (gauss 0 2 4.4)) (7 (gauss 1 0 4.4)) (8 (gauss 1 1 4.4)) (9 (gauss 1 2 4.4)) (10 (gauss 2 0 4.4)) (11 (gauss 2 1 4.4)) (12 (gauss 2 2 4.4))))))) (pretty-print (parse-dag+features->log-prob (caar (batch-run-inversion (list prog1) (list test-data) 'use-features)))) (define test-data2 '(gauss 3 1)) (print "Normal inversion") (pretty-print (batch-run-inversion (list prog1) (list test-data2)))
false
0320b41d076b3850df1269231a9d8f1fde580d1e
58381f6c0b3def1720ca7a14a7c6f0f350f89537
/Chapter 5/5.4/5.27.scm
cd02a6bf22740a95253369b8deb51272223135cd
[]
no_license
yaowenqiang/SICPBook
ef559bcd07301b40d92d8ad698d60923b868f992
c8a0228ebf66d9c1ddc5ef1fcc1d05d8684f090a
refs/heads/master
2020-04-19T04:03:15.888492
2015-11-02T15:35:46
2015-11-02T15:35:46
null
0
0
null
null
null
null
UTF-8
Scheme
false
false
914
scm
5.27.scm
#lang planet neil/sicp (define (factorial n) (if (= n 1) 1 (* (factorial (- n 1)) n))) ;; Results for recursive factorial +-------+--------+-------+ | n | pushes | depth | +-------+--------+-------+ | 1 | 16 | 8 | | 10 | 304 | 53 | | 100 | 3184 | 503 | | 1000 | 31984 | 5003 | | 10000 | 319984 | 50003 | +-------+--------+-------+ ;; pushes ~ 32n - 16 ;; depth ~ 5n + 3 ;; TABLE +---------------------+---------------+------------------+ | | Maximum depth | Number of pushes | +---------------------+---------------+------------------+ | Recursive factorial | 5n + 3 | 32n – 16 | | Iterative factorial | 10 | 35n + 29 | +---------------------+---------------+------------------+ ;; The recursive factorial is only slightly better in terms of pushes ;; but the iterative factorial wins in terms of depth
false
fa9cca0e947157bd149114bb88df853311cedc7e
320a615ef54449a39e2ca9e59847106e30cc8d7a
/guile/compat.scm
cb6f46d84bcc5328b699467245340409482b1f53
[]
no_license
alexei-matveev/bgy3d
5cf08ea24a5c0f7b0d6e1d572effdeef8232f173
0facadd04c6143679033202d18017ae2a533b453
refs/heads/master
2021-01-01T17:47:22.766959
2015-07-10T09:21:49
2015-07-10T09:21:49
38,872,299
2
1
null
null
null
null
UTF-8
Scheme
false
false
1,294
scm
compat.scm
;;; ;;; Copyright (c) 2013 Alexei Matveev ;;; (define-module (guile compat)) (cond-expand ((not guile-2) ;; ;; Code to backport selected features to 1.8 goes here: ;; (use-syntax (ice-9 syncase)) ;; ;; Thanks to taylanub at #guile: ;; (define-syntax define-syntax-rule (syntax-rules () ((define-syntax-rule (keyword . pattern) template) (define-syntax keyword (syntax-rules () ((keyword . pattern) template)))))) ;; ;; Not in the define-module form: ;; (export-syntax define-syntax-rule) ;; ;; When/uless were added in 2.0: ;; (define-syntax-rule (when test stmt stmt* ...) (if test (begin stmt stmt* ...))) (export-syntax when) (define-syntax-rule (unless test stmt stmt* ...) (if (not test) (begin stmt stmt* ...))) (export-syntax unless) ;; ;; Re-export all symbols from (ice-9 syncase). Credit to mark_weaver ;; at #guile. Otherwise the importer of this module, (guile compat), ;; still needs to explicitly import (ice-9 syncase) in order for ;; define-syntax-rule to work. ;; (let ((names (module-map (lambda (name var) name) (resolve-interface '(ice-9 syncase))))) (module-re-export! (current-module) names))) (else) ;; ;; Nothing here. ;; )
true
8e5fd83133282e89a1037469dcaa8a5edbe4620d
1ed47579ca9136f3f2b25bda1610c834ab12a386
/sec3/sec3.5.3.scm
666b32d70d01264164ec8fbfac0822b7c2748610
[]
no_license
thash/sicp
7e89cf020e2bf5ca50543d10fa89eb1440f700fb
3fc7a87d06eccbe4dcd634406e3b400d9405e9c4
refs/heads/master
2021-05-28T16:29:26.617617
2014-09-15T21:19:23
2014-09-15T21:19:23
3,238,591
0
1
null
null
null
null
UTF-8
Scheme
false
false
5,497
scm
sec3.5.3.scm
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; 3.5.3. ストリームパラダイムの開発 (load "./stream") (load "./my_defs") ;; 反復をストリームプロセスとして形式化する (define (sqrt-improve guess x) (average guess (/ x guess))) (define (sqrt-stream x) (define guesses (cons-stream 1.0 (stream-map (lambda (guess) (sqrt-improve guess x)) guesses))) guesses) ;; squrt 2 に収束させる ;(display-stream-n (sqrt-stream 2) 10) ;; 1.0 ;; 1.5 ;; 1.4166666666666665 ;; 1.4142156862745097 ;; 1.4142135623746899 ;; 1.414213562373095 ;; 1.414213562373095 ;; 1.414213562373095 ;; 1.414213562373095 ;; 同様にPIも収束させるよ ; PI/4 = 1 - 1/3 + 1/5 - 1/7 + ... (define (pi-summands n) (cons-stream (/ 1.0 n) (stream-map - (pi-summands (+ n 2))))) ;; partial-sums from q3.55.scm (define (partial-sums s) (cons-stream (stream-car s) (add-streams (stream-cdr s) (partial-sums s)))) (define pi-stream (scale-stream (partial-sums (pi-summands 1)) 4)) ;(display-stream-n pi-stream 10) ;; 4.0 ;; 2.666666666666667 ;; 3.466666666666667 ;; 2.8952380952380956 ;; 3.3396825396825403 ;; 2.9760461760461765 ;; 3.2837384837384844 ;; 3.017071817071818 ;; 3.2523659347188767 ;; この近似は緩やかに収束する。 ; 100 => 3.1516934060711166 ; 200 => 3.146617747495458 ;; 正負が交代するような級数は "euler-transform" を使って加速できる。実はEulerの名が付くのは珍しいらしいが。 (define (euler-transform s) (let ((s0 (stream-ref s 0)) ; S_(n-1) (s1 (stream-ref s 1)) ; S_n (s2 (stream-ref s 2))) ; S_(n+1) (cons-stream (- s2 (/ (square (- s2 s1)) (+ s0 (* -2 s1) s2))) (euler-transform (stream-cdr s))))) ;; 収束が速いよ! ;; (display-stream-n (euler-transform pi-stream) 10) ; 3.166666666666667 ; 3.1333333333333337 ; 3.1452380952380956 ; 3.13968253968254 ; 3.1427128427128435 ; 3.1408813408813416 ; 3.142071817071818 ; 3.1412548236077655 ; 3.1418396189294033 ;; さらに加速されたストリームもストリームなので、加速加速加速できる ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; 対の無限ストリーム ;; # 1つのファイルに長々と書いていって結果出力をcomment outしながら説明していくのいいな ;; i+jが素数であるようなstreamを作ろう。 ;; int-pairsはi <= jな整数(i,j)のすべての対の並びとすれば、次のようにfilterすればよい。 ; (stream-filter (lambda (pair) ; (prime? (+ (car pair) (cadr pair)))) ; int-pairs) ;; ふたつのstream S = (S_i), T = (T_j)を考え、無限の正方配列を作る。 ;; 正方配列の定義を再帰的に捉えると... => [図] ; (define (pairs s t) ; (cons-stream ; (list (stream-car s) (stream-car t)) ; (<conbine-in-some-way> ; (stream-map (lambda (x) (list (stream-car s) x)) ; (stream-cdr t)) ; (pairs (stream-cdr s) (stream-cdr t))))) ;; ↑の<conbine-in-some-way>...内部ストリームを組み合わせる何らかの方法を考えることがキモになる。 ;; <conbine-in-some-way>候補そのいち... (define (stream-append s1 s2) (if (stream-null? s1) s2 (cons-stream (stream-car s1) (stream-append (stream-cdr s1) s2)))) ;; こんなん考えてみましたが、s2を取り込む前にs1をすべての要素を取るので、無限streamには使えない。 ;; (1 . 1), (1 . 2) ... (1 . 100) ... (1 . 9999999) ... と、最初の要素が1である組み合わせをまず全て網羅しようとする。 ;; そこで、無限streamを使いつつ目的を達成するには、対を生成する並び順をちゃんと考えないといけない。 ;; <conbine-in-some-way>候補そのに -- interleave (define (interleave s1 s2) (if (stream-null? s1) s2 (cons-stream (stream-car s1) (interleave s2 (stream-cdr s1))))) ;; 最後の行に注目。s1とs2を入れ替え、順々に消費していくstreamを作っている! ;; これでpairsの完成形ができる。 (define (pairs s t) (cons-stream (list (stream-car s) (stream-car t)) (interleave (stream-map (lambda (x) (list (stream-car s) x)) (stream-cdr t)) (pairs (stream-cdr s) (stream-cdr t))))) ;; この発想から、いくつか並び順と要素の網羅性についての問題が続く。 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; 信号としてのストリーム ;; 時間経過に従った連続する信号の値をstreamで表現する。1秒ごとに1,2,3,1,2,3...と繰り替えす信号を表現する場合 ;; (1 2 3 1 2 3 ...) というリストにするイメージかな。 ;; 積分器(integrator) -- dtがstream要素間の時間間隔. ;; ;; [注] integralはsec3.5.4.scmで再定義されている. 問題3.77.scm以降はそっち利用すること (define (integral integrand initial-value dt) (define int (cons-stream initial-value (add-streams (scale-stream integrand dt) int))) int) ;; integrand: The quantity being integrated, also called the integral kernel. For example, in integral f(x) dx, f(x) is the integrand.
false
3f5e38ce8bda0e5e65c6319a5a8c35bb9b7955ff
61226ac514ed266ef11eb72b97215c8963c0c833
/bootstrap/inc/typedefs.scm
3eed0dcc98e33078ab87ed47c02af9afccfbcd99
[ "MIT" ]
permissive
uz3rname/cons
1d4165dde97afdc7452fab2e284496104311a26a
e8e61af910cf8df7491cbf1f36a2d8c1023281e4
refs/heads/master
2022-12-15T19:08:35.174491
2020-09-02T07:15:35
2020-09-02T07:15:35
292,188,820
0
0
null
null
null
null
UTF-8
Scheme
false
false
740
scm
typedefs.scm
(define type-defs '((throw (casts-to *) (casts-from *)) (void (casts-from *)) (null (casts-to (|:| list *) (|:| array *))) (bool) (byte (class number) (casts-to int real char)) (int (class number) (casts-to byte real (|:| ptr *)) (casts-expl-to char int16 int32)) (int16 (class number) (casts-to int32 int byte) (casts-expl-to char)) (int32 (class number) (casts-to int16 int byte) (casts-expl-to char)) (real (class number) (casts-to byte int)) (char (casts-expl-to int byte)) (ptr (args a) (casts-to (|:| ptr *)) (casts-from (|:| ptr *)) (casts-expl-to int))))
false
e0e82cbe3db4eb89cb0f981c4281e92d2ce20f18
4fa8c99ef03db0aa5806d7e83e61b9cb61a6d5bb
/07_HeapAllocation/compiler.scm
4e904116edb62ee0c18945c8b6be1b06b4efc119
[ "BSD-3-Clause" ]
permissive
horie-t/iacc-riscv
cef150453e2f6f921c8e5f6a6cdd15fce0f4204a
2aea0b27f712f4b9354ecf04a7a0cb08f5c2117e
refs/heads/master
2020-03-28T13:41:20.867468
2018-11-25T08:24:59
2018-11-25T08:24:59
148,417,953
6
1
null
null
null
null
UTF-8
Scheme
false
false
28,146
scm
compiler.scm
(import (rnrs hashtables)) (load "test_cases.scm") ;;;; ユーティリティ関数 ;;; 書式と引数を取って表示し、改行を付け加えます。 ;; 例: (emit "addi t0, t0, ~s" 1) ;; addi t0, t0, 1 ;; が表示されます。 (define (emit . args) (apply format #t args) (newline)) ;;; ユニーク・ラベル生成 ;; 重複のない、ラベルを返します。 (define unique-label (let ((count 0)) (lambda () (let ((L (format "L_~s" count))) (set! count (+ count 1)) L)))) ;;; ユニーク・ラベルのリストを生成します。 ;; vars ラベルの一部を形成する文字のリスト (define (unique-labels vars) (map (lambda (var) (format "~a_~s" (unique-label) var)) vars)) ;;; 値比較ユーティリティ ;; a0と値を比較し、booleanオブジェクトをa0に設定します。 ;; args 比較する即値、省略時はt0と比較 (define (emit-cmp-bool . args) (if (null? args) (emit " sub a0, a0, t0") (emit " addi a0, a0, ~s" (- (car args)))) (emit " seqz a0, a0") (emit " slli a0, a0, ~s" bool_bit) (emit " ori a0, a0, ~s" bool_f)) ;;; 式の書式判定ユーティリティ ;; (tag ....) の形式かどうかを判定します。 (define (tagged-form? tag expr) (and (list? expr) (not (null? expr)) (eq? (car expr) tag))) ;;;; スタック関連 ;;; スタックに値を保存します。 ;; si スタック・インデックス (define (emit-stack-save si) (emit " sw a0, ~s(sp)" si)) (define (emit-stack-load si) (emit " lw a0, ~s(sp)" si)) (define (emit-stack-load-t0 si) (emit " lw t0, ~s(sp)" si)) ;;; 次のスタックインデックスを返します。 (define (next-stack-index si) (- si wordsize)) ;;; スタック・ポインタを移動させます。 (define (emit-adjust-base si) (emit " addi sp, sp, ~s" si)) ;;;; 環境関連 ;;; 環境を生成します。 ;; bindings 初期値。 '((a -8) (b -9))のような、シンボル、スタック・インデックスのリストのリスト。 ;; 何もなければ空リストを渡す (define (make-initial-env bindings) bindings) ;;; 環境に変数を追加します。 ;; var 変数のシンボル ;; si スタック・インデックス ;; env 変数を追加する環境 (define (extend-env var si env) (cons (list var si) env)) ;;; 環境に変数を追加します。 (define (bulk-extend-env vars vals env) (append (map list vars vals) env)) ;;; 環境から変数の値のスタック・インデックスを検索します (define (lookup var env) (cond ((assv var env) (cadr (assv var env))) (else #f))) ;;;; オブジェクト型情報定義: タグ付きポインタ表現を使う ;;; 整数: 下位2ビットが00、上位30ビットが符号付き整数となっている (define fxshift 2) ; 整数変換シフト量 (define fxmask #x03) ; 整数判定ビットマスク(ANDを取って0なら整数オブジェクト) (define fxtag #0x0) ; ;;; boolean: (define bool_f #x2f) ; #fの数値表現 (define bool_t #x6f) ; #t (define boolmask #xbf) ; boolean判定ビットマスク(ANDを取ってis_boolならbooleanオブジェクト) (define is_bool #x2f) ; (define bool_bit 6) ; booleanの判定用ビット位置 ;;; 空リスト: (define empty_list #x3f) ; (define emptymask #xff) ; ;;; 文字: 下位8ビットが00001111。ASCIIコードを8ビットシフトして、0x0fとORを取る。 (define charmask #xff) ; char判定ビットマスク(ANDを取って、chartagならchar) (define chartag #x0f) ; charタグ (define charshift 8) ; char変換シフト量 (define wordsize 4) ; 32bit(4バイト) (define wordshift 2) ; word数 -> バイト数 変換シフト量 (define fixnum-bits (- (* wordsize 8) fxshift)) (define fxlower (- (expt 2 (- fixnum-bits 1)))) (define fxupper (- (expt 2 (- fixnum-bits 1)) 1)) (define (fixnum? x) (and (integer? x) (exact? x) (<= fxlower x fxupper))) ;;;; 即値関連関数 ;;; 即値かどうかを返します。 (define (immediate? x) (or (fixnum? x) (boolean? x) (char? x) (null? x))) ;;; Schemeの即値から、アセンブリ言語でのオブジェクト表現を返します。 (define (immediate-rep x) (cond ((fixnum? x) (ash x fxshift)) ((eq? x #f) bool_f) ((eq? x #t) bool_t) ((char? x) (logior (ash (char->integer x) charshift) chartag)) ((null? x) empty_list) (else (error "invalid immediate")))) ;;; 即値表現から、アセンブリ言語を出力します。 (define (emit-immediate expr) (emit " li a0, ~s" (immediate-rep expr))) ;;;; グローバル・プロバティ (define *prop* (make-eq-hashtable)) (define (getprop x property) (let ((prop (hashtable-ref *prop* x #f))) (if prop (hashtable-ref prop property #f) #f))) (define (putprop x property val) (let ((entry (hashtable-ref *prop* x #f))) (if entry (hashtable-set! entry property val) (hashtable-set! *prop* x (let ((entry (make-eq-hashtable))) (hashtable-set! entry property val) entry))))) ;;;; プリミティブ関連 ;;; プリミティブ定義(*porp*にプリミティブ関連の情報を追加) ;; 例: (define-primitive (fxadd1 arg) ;; 出力内容 ...) (define-syntax define-primitive (syntax-rules () ((_ (prime-name si env arg* ...) body body* ...) (begin (putprop 'prime-name '*is-prime* #t) (putprop 'prime-name '*arg-count (length '(arg* ...))) (putprop 'prime-name '*emmiter* (lambda (si env arg* ...) body body* ...)))))) ;;; 引数が基本演算かどうかを返します。 ; xは、add1のようにシンボルで、*is-prime*が#tにセットされている必要がある (define (primitive? x) (and (symbol? x) (getprop x '*is-prime*))) (define (primitive-emitter x) (or (getprop x '*emmiter*) (error "primitive-emitter: not exist emmiter"))) ;;;; 単項演算関連 ;;; 単項演算呼び出し(単項演算処理)かどうかを返します。 ;; 単項演算呼び出しは(op arg)の形式なので、最初はpairで、carがprimitive?がtrueを返すものでなければならない。 (define (primcall? expr) (and (pair? expr) (primitive? (car expr)))) (define (emit-primcall si env expr) (let ((prim (car expr)) (args (cdr expr))) (apply (primitive-emitter prim) si env args))) ;;; 引数に1を加えた値を返します (define-primitive (fxadd1 si env arg) (emit-expr si env arg) (emit " addi a0, a0, ~s" (immediate-rep 1))) ;;; 引数から1を引いた値を返します (define-primitive (fxsub1 si env arg) (emit-expr si env arg) (emit " addi a0, a0, ~s" (immediate-rep -1))) ;;; fixnumからcharに変換します。 (define-primitive (fixnum->char si env arg) (emit-expr si env arg) (emit " slli a0, a0, ~s" (- charshift fxshift)) (emit " ori a0, a0, ~s" chartag)) ;;; charからfixnumに変換します。 (define-primitive (char->fixnum si env arg) (emit-expr si env arg) (emit " srli a0, a0, ~s" (- charshift fxshift))) ;;; fixnumかどうかを返します (define-primitive (fixnum? si env arg) (emit-expr si env arg) (emit " andi a0, a0, ~s" fxmask) (emit-cmp-bool fxtag)) ;;; 空リストかどうかを返します (define-primitive (null? si env arg) (emit-expr si env arg) (emit " andi a0, a0, ~s" emptymask) (emit-cmp-bool empty_list)) ;;; booleanオブジェクトかどうかを返します (define-primitive (boolean? si env arg) (emit-expr si env arg) (emit " andi a0, a0, ~s" boolmask) (emit-cmp-bool is_bool)) ;;; 文字オブジェクトかどうかを返します (define-primitive (char? si env arg) (emit-expr si env arg) (emit " andi a0, a0, ~s" charmask) (emit-cmp-bool chartag)) ;;; #fなら#tを返し、それ以外は#fを返します。 (define-primitive (not si env arg) (emit-expr si env arg) (emit-cmp-bool bool_f)) ;;; (define-primitive (fxlognot si env arg) (emit-expr si env arg) (emit " xori a0, a0, ~s" (immediate-rep -1))) ;;;; 二項基本演算 ;;; 二項基本演算ユーティリティ ;; arg1、arg2を評価し、結果をそれぞれt0、a0レジスタに代入します (define (emit-binop si env arg1 arg2) (emit-expr si env arg1) (emit-stack-save si) ; 結果をスタックに一時退避 (emit-expr (next-stack-index si) env arg2) (emit-stack-load-t0 si)) ; スタックに退避した値をt0に復元 ;;; 整数加算 (define-primitive (fx+ si env arg1 arg2) ; siは、stack indexの略。siが指す先は、空き領域にしてから呼び出す事 (emit-binop si env arg1 arg2) (emit " add a0, a0, t0")) ;;; 整数減算 (define-primitive (fx- si env arg1 arg2) (emit-binop si env arg1 arg2) (emit " sub a0, t0, a0")) ;;; 整数積 (define-primitive (fx* si env arg1 arg2) (emit-binop si env arg1 arg2) (emit " sra a0, a0, ~s" fxshift) (emit " mul a0, t0, a0")) ;;; 整数ビット論理積 (define-primitive (fxlogand si env arg1 arg2) (emit-binop si env arg1 arg2) (emit " and a0, a0, t0")) ;;; 整数ビット論理和 (define-primitive (fxlogor si env arg1 arg2) (emit-binop si env arg1 arg2) (emit " or a0, a0, t0")) ;;; 整数等号 (define-primitive (fx= si env arg1 arg2) (emit-binop si env arg1 arg2) (emit-cmp-bool)) ;;; 整数小なり (define-primitive (fx< si env arg1 arg2) (emit-binop si env arg1 arg2) (emit " slt a0, t0, a0") (emit " slli a0, a0, ~s" bool_bit) (emit " ori a0, a0, ~s" bool_f)) ;;; 整数以下 (define-primitive (fx<= si env arg1 arg2) (emit-expr si env (list 'fx< arg2 arg1)) ; 大なりを判定して、あとで否定する (emit " xori a0, a0, ~s" (ash 1 bool_bit))) ;;; 整数大なり (define-primitive (fx> si env arg1 arg2) (emit-expr si env (list 'fx< arg2 arg1))) ; 引数を逆にして、小なりを使う ;;; 整数以上 (define-primitive (fx>= si env arg1 arg2) (emit-expr si env (list 'fx< arg1 arg2)) ; 小なりを判定して、あとで否定する (emit " xori a0, a0, ~s" (ash 1 bool_bit))) ;;; 文字等号 (define-primitive (char= si env arg1 arg2) (emit-binop si env arg1 arg2) ; 型判定をしていないので、fx=と同じ内容。eq?をこれにしてOKかも (emit-cmp-bool)) ;;; 整数小なり (define-primitive (char< si env arg1 arg2) (emit-binop si env arg1 arg2) (emit " slt a0, t0, a0") (emit " slli a0, a0, ~s" bool_bit) (emit " ori a0, a0, ~s" bool_f)) ;;; 整数以下 (define-primitive (char<= si env arg1 arg2) (emit-expr si env (list 'char< arg2 arg1)) ; 大なりを判定して、あとで否定する (emit " xori a0, a0, ~s" (ash 1 bool_bit))) ;;; 整数大なり (define-primitive (char> si env arg1 arg2) (emit-expr si env (list 'char< arg2 arg1))) ; 引数を逆にして、小なりを使う ;;; 整数以上 (define-primitive (char>= si env arg1 arg2) (emit-expr si env (list 'char< arg1 arg2)) ; 小なりを判定して、あとで否定する (emit " xori a0, a0, ~s" (ash 1 bool_bit))) ;;;; 条件式 ;;; if形式 ;;; if形式かどうかを返します (define (if? expr) (tagged-form? 'if expr)) ;;; if形式の述部(predicate)を取り出します。 (define (if-test expr) (cadr expr)) ;;; if形式の帰結部(consequent)を取り出します。 (define (if-conseq expr) (caddr expr)) ;;; if形式の代替部(alternative)を取り出します。 (define (if-altern expr) (cadddr expr)) ;;; if形式の出力 (define (emit-if si env tail expr) (let ((alt-label (unique-label)) (end-label (unique-label))) (emit-expr si env (if-test expr)) (emit " addi a0, a0, ~s" (- bool_f)) (emit " beqz a0, ~a" alt-label) (emit-any-expr si env tail (if-conseq expr)) (if (not tail) (emit " j ~a" end-label)) (emit "~a:" alt-label) (emit-any-expr si env tail (if-altern expr)) (emit "~a:" end-label))) ;;; and形式 (define (and? expr) (tagged-form? 'and expr)) (define (emit-and si env expr) (let ((pred-len (length (cdr expr)))) (cond ((= pred-len 0) (emit " li a0, ~s" bool_t)) ;引数なしなら常に真 ((= pred-len 1) (emit-primcall si env (list 'not (cadr expr))) ; まず、(not test)の式に変換して評価する (emit " xori a0, a0, ~s" (ash 1 bool_bit))) ; a0は偽かどうかの値なので、ビット反転でnotを演算する (else ;; (and test test* ...) => (if test (and test* ...) #f)と変換して処理 (emit-if si env #f (list 'if (cadr expr) (cons 'and (cddr expr)) #f)))))) ;;; or形式 (define (or? expr) (tagged-form? 'or expr)) (define (emit-or si env expr) (let ((pred-len (length (cdr expr)))) (cond ((= pred-len 0) (emit " li a0, ~s" bool_f)) ;引数なしなら常に偽 ((= pred-len 1) (emit-primcall si env (list 'not (cadr expr))) ; まず、(not test)の式に変換して評価する (emit " xori a0, a0, ~s" (ash 1 bool_bit))) ; a0は偽かどうかの値なので、ビット反転でnotを演算する (else ;; (or test test* ...) => (if test #t (or test* ...))と変換して処理 (emit-if si env #f (list 'if (cadr expr) #t (cons 'or (cddr expr)))))))) ;;;; let形式 ;;; let形式かどうかを返します (define (let? expr) (tagged-form? 'let expr)) ;;; let形式のbinding部分を返します。 (define (let-bindings expr) (cadr expr)) ;;; let形式のbody部分を返します。 (define (let-body expr) (if (null? (cdddr expr)) (caddr expr) (make-begin (cddr expr)))) (define (emit-let si env tail expr) (define (process-let bindings si new-env) (cond ((null? bindings) (emit-any-expr si new-env tail (let-body expr))) (else (let ((b (car bindings))) (emit-expr si env (cadr b)) (emit-stack-save si) (process-let (cdr bindings) (next-stack-index si) (extend-env (car b) si new-env)))))) (process-let (let-bindings expr) si env)) ;;;; let*形式 ;;; let*形式かどうかを返します。 (define (let*? expr) (tagged-form? 'let* expr)) ;;; ;; let*は、letの入れ子に書き換えてしまう。 ;; 例) ;; (let* ((x 1)) (let ((x 1)) ;; (let* ((x (fx+ x 1)) => (let ((x (fx+ x 1))) ;; (y (fx+ x 1))) (let ((y (fx+ x 1))) ;; y)) y))) (define (emit-let* si env tail expr) (emit-any-expr si env tail (let ((bindings (let-bindings expr)) (body (let-body expr))) (cond ((<= (length bindings) 1) (list 'let bindings body)) (else (list 'let (list (car bindings)) (list 'let* (cdr bindings) body))))))) ;;;; letrec形式 ;;; letrec形式かどうかを返します。 (define (letrec? expr) (tagged-form? 'letrec expr)) (define (emit-letrec expr) (let* ((bindings (let-bindings expr)) (lvars (map car bindings)) (lambdas (map cadr bindings)) (labels (unique-labels lvars)) (env (bulk-extend-env lvars labels ()))) (for-each (emit-lambda env) lambdas labels) (emit-scheme-entry (let-body expr) env))) ;;;; begin形式 ;;; begin形式かどうかを返します。 (define (begin? expr) (tagged-form? 'begin expr)) (define (emit-begin si env tail expr) (emit-seq si env tail (cdr expr))) ;; 連続した式を出力します ;; seq 連続した式。例: ((set-car! some-pair 7) (set-cdr! come-pair 5) some-pair) (define (emit-seq si env tail seq) (cond ((null? seq) (error "empty seq")) ((null? (cdr seq)) ; 連続式の末尾の場合 (emit-any-expr si env tail (car seq))) (else ; 連続式の途中の場合 (emit-expr si env (car seq)) (emit-seq si env tail (cdr seq))))) (define (make-begin seq) (cons 'begin seq)) ;;; 変数参照 (define (variable? expr) (symbol? expr)) (define (emit-variable-ref env var) (cond ((lookup var env) (let ((val (lookup var env))) (cond ((number? val) (emit-stack-load val)) (else (error "emit-variable-ref. " (format #t "looked up unknown value ~s for var ~s" val var)))))))) ;;;; lambda (define (lambda-formals expr) (cadr expr)) (define (lambda-body expr) (caddr expr)) (define (emit-lambda env) (lambda (expr label) (emit-function-header label) (emit " addi sp, sp, ~s" (- wordsize)) (emit " sw ra, 0(sp)") (let ((fmls (lambda-formals expr)) (body (lambda-body expr))) (let f ((fmls fmls) (si (- wordsize)) (env env)) (cond ((null? fmls) (emit-tail-expr si env body)) (else (f (cdr fmls) (- si wordsize) (extend-env (car fmls) si env)))))))) ;;;; app関連 ;;; apply可能かどうか (define (app? expr env) (and (list? expr) (not (null? expr)) (lookup (car expr) env))) ;;; applyの出力 ;; si スタック・インデックス(stack index) ;; env 環境(environment)。変数や関数の名前と、アクセスするための位置情報のリスト ;; tail 式が手続きの末尾(tail)かどうか。 ;; expr lambda式(expression) (define (emit-app si env tail expr) ;;; 呼び出し先の引数をスタックに積む (define (emit-arguments si args) (unless (null? args) (emit-expr si env (car args)) (emit-stack-save si) (emit-arguments (- si wordsize) (cdr args)))) ;;; 末尾呼び出しの場合は、引数を自分の関数のスタックに移動する ;; delta 移動量 (define (move-arguments si delta args) (unless (or (= delta 0) (null? args)) (emit-stack-load si) (emit-stack-save (+ si delta)) (move-arguments (- si wordsize) delta (cdr args)))) (cond ((not tail) (emit-arguments (- si (* 2 wordsize)) (cdr expr)) (emit-adjust-base si) (emit-call (lookup (car expr) env)) (emit-adjust-base (- si))) (else (emit-arguments si (cdr expr)) (move-arguments si (- si) (cdr expr)) (emit-jmp-tail (lookup (car expr) env))))) ;;;; ヒープ領域オブジェクト関連 (define objshift 2) (define objmask #x07) ;;; ヒープメモリ確保時の最低サイズ(バイト) (define heap-cell-size (ash 1 objshift)) ;;; ヒープメモリを確保します。確保したアドレスはa0に設定 ;; size 確保するバイト数 (define (emit-heap-alloc size) (let ((alloc-size (* (+ (div (- size 1) heap-cell-size) 1) heap-cell-size))) (emit " mv a0, s0") (emit " addi s0, s0, ~s" alloc-size))) ;;; 動的にヒープ・メモリを確保します。確保するバイト数はa0にセットして呼び出します。 (define (emit-heap-alloc-dynamic) (emit " addi a0, a0, -1") (emit " srai a0, a0, ~s" objshift) (emit " addi a0, a0, 1") (emit " slli a0, a0, ~s" objshift) (emit " mv t0, a0") (emit " mv a0, s0") (emit " add s0, s0, t0")) ;;; スタックの値をヒープにコピーします。 ;; si コピー元の値のスタックインデックス ;; offset a0+offset のアドレスに値をコピーします。 (define (emit-stack-to-heap si offset) (emit " lw t0, ~s(sp)" si) (emit " sw t0, ~s(a0)" offset)) ;;; ヒープの値をa0に読み込みます。 ;; offset a0+offset のアドレスの値を読み込みます (define (emit-heap-load offset) (emit " lw a0, ~s(a0)" offset)) ;;; オブジェクトの型判定をします。 ;; tag オブジェクトの型タグ (define (emit-object? tag si env arg) (emit-expr si env arg) (emit " andi a0, a0, ~s" objmask) (emit-cmp-bool tag)) ;;;; eq? (define-primitive (eq? si env arg1 arg2) (emit-binop si env arg1 arg2) (emit-cmp-bool)) ;;;; ペア関連 (define pairtag #b001) ; ペアのタグ (define pairsize 8) ; ペアのメモリサイズ(バイト) (define paircar 0) ; ペア中のcar部分のオフセット (define paircdr 4) ; ペア中のcdr部分のオフセット ;;; cons (define-primitive (cons si env arg1 arg2) (emit-binop si env arg1 arg2) (emit-stack-save (next-stack-index si)) (emit-heap-alloc pairsize) (emit " ori a0, a0, ~s" pairtag) (emit-stack-to-heap si (- paircar pairtag)) (emit-stack-to-heap (next-stack-index si) (- paircdr pairtag))) ;;; pair? (define-primitive (pair? si env arg) (emit-object? pairtag si env arg)) ;;; car (define-primitive (car si env arg) (emit-expr si env arg) (emit-heap-load (- paircar pairtag))) ;;; cdr (define-primitive (cdr si env arg) (emit-expr si env arg) (emit-heap-load (- paircdr pairtag))) ;;; set-car! (define-primitive (set-car! si env cell val) (emit-binop si env val cell) (emit-stack-to-heap si (- paircar pairtag))) ;;; set-cdr! (define-primitive (set-cdr! si env cell val) (emit-binop si env val cell) (emit-stack-to-heap si (- paircdr pairtag))) ;;;; ベクトル関連 (define vectortag #x05) ; ベクトルのタグ ;;; ベクトルを作成します。 ;; length ベクトルの要素数 (define-primitive (make-vector si env length) (emit-expr si env length) (emit-stack-save si) (emit " addi a0, a0, ~s" (ash 1 fxshift)) ; 要素数+1のセルを確保する。+1はlengthデータ保存用 (emit " slli a0, a0, ~s" wordshift) ; 要素数 -> バイト数へ変換 (emit-heap-alloc-dynamic) (emit-stack-to-heap si 0) (emit " ori a0, a0, ~s" vectortag)) ;;; ベクトルかどうかを返します。 (define-primitive (vector? si env arg) (emit-object? vectortag si env arg)) ;;; ベクトルの要素数を返します。 (define-primitive (vector-length si env arg) (emit-expr si env arg) (emit-heap-load (- vectortag))) ; タグの値の分だけアドレスをずらす ;;; ベクトルに値をセットします。 ;; vector セットされるベクトル ;; index セットする位置 ;; value セットする値 (define-primitive (vector-set! si env vector index value) (emit-expr si env index) (emit " addi a0, a0, ~s" (ash 1 fxshift)) ; index=0の位置には長さが入っているのでずれる。 (emit " slli a0, a0, ~s" (- objshift fxshift)) (emit-stack-save si) (emit-expr-save (next-stack-index si) env value) (emit-expr si env vector) (emit-stack-load-t0 si) (emit " add a0, a0, t0") (emit-stack-to-heap (next-stack-index si) (- vectortag))) ;;; ベクトルの要素の値を取得します。 (define-primitive (vector-ref si env vector index) (emit-expr si env index) (emit " addi a0, a0, ~s" (ash 1 fxshift)) ; index=0の位置には長さが入っているのでずれる。 (emit " slli a0, a0, ~s" (- objshift fxshift)) (emit-stack-save si) (emit-expr si env vector) (emit-stack-load-t0 si) (emit " add a0, a0, t0") (emit-heap-load (- vectortag))) ;;;; 文字列関連 (define stringtag #x06) ;;; 文字列を作成します。 (define-primitive (make-string si env length) (emit-expr-save si env length) (emit " srai a0, a0, ~s" fxshift) (emit " addi a0, a0, ~s" wordsize) (emit-heap-alloc-dynamic) (emit-stack-to-heap si 0) (emit " ori a0, a0, ~s" stringtag)) ;;; 文字列かどうかを返します。 (define-primitive (string? si env arg) (emit-object? stringtag si env arg)) ;;; 文字列の長さを返します。 (define-primitive (string-length si env arg) (emit-expr si env arg) (emit-heap-load (- stringtag))) ;;; 文字列に文字をセットします。 (define-primitive (string-set! si env string index value) (emit-expr si env index) (emit " srai a0, a0, ~s" fxshift) (emit " addi a0, a0, ~s" wordsize) (emit-stack-save si) (emit-expr (next-stack-index si) env value) (emit " srai a0, a0, ~s" charshift) (emit-stack-save (next-stack-index si)) (emit-expr si env string) (emit-stack-load-t0 si) (emit " add a0, a0, t0") (emit-stack-load-t0 (next-stack-index si)) (emit " sb t0, ~s(a0)" (- stringtag))) ;;; 文字列の文字を参照します。 (define-primitive (string-ref si env string index) (emit-expr si env index) (emit " srai a0, a0, ~s" fxshift) (emit " addi a0, a0, ~s" wordsize) (emit-stack-save si) (emit-expr si env string) (emit-stack-load-t0 si) (emit " add a0, a0, t0") (emit " lb a0, ~s(a0)" (- stringtag)) (emit " slli a0, a0, ~s" charshift) (emit " ori a0, a0, ~s" chartag)) ;;;; コンパイラ・メイン処理 ;;; 手続き内部の式のコンパイル (define (emit-ret-if tail) (when tail (emit " lw ra, 0(sp)") (emit " addi sp, sp, ~s" wordsize) (emit " ret"))) (define (emit-expr si env expr) (emit-any-expr si env #f expr)) ;;; 式を評価して、siに保存します。 (define (emit-expr-save si env arg) (emit-expr si env arg) (emit-stack-save si)) ;;; 手続き末尾の式のコンパイル (define (emit-tail-expr si env expr) (emit-any-expr si env #t expr)) ;;; 式をコンパイルします。 ;; si スタック・インデックス(stack index) ;; env 環境(environment)。変数や関数の名前と、アクセスするための位置情報のリスト ;; tail 式が手続きの末尾(tail)かどうか。 ;; expr コンパイルする式(expression) (define (emit-any-expr si env tail expr) (cond ((immediate? expr) (emit-immediate expr) (emit-ret-if tail)) ; 即値の場合は、si、envを必要としない。 ((variable? expr) (emit-variable-ref env expr) (emit-ret-if tail)) ((if? expr) (emit-if si env tail expr)) ((and? expr) (emit-and si env expr) (emit-ret-if tail)) ((or? expr) (emit-or si env expr) (emit-ret-if tail)) ((let? expr) (emit-let si env tail expr)) ((let*? expr) (emit-let* si env tail expr)) ((begin? expr) (emit-begin si env tail expr)) ((primcall? expr) (emit-primcall si env expr) (emit-ret-if tail)) ((app? expr env) (emit-app si env tail expr)) (else (error "imvalid expr: " expr)))) (define (emit-label label) (emit "~a:" label)) (define (emit-function-header f) (emit "\n") (emit " .text") (emit " .globl ~a" f) (emit " .type ~a, @function" f) (emit-label f)) (define (emit-scheme-entry expr env) (emit-function-header "L_scheme_entry") (emit " addi sp, sp, ~s" (- wordsize)) (emit " sw ra, 0(sp)") (emit-tail-expr (- wordsize) env expr)) (define (emit-call label) (emit " call ~a" label)) ;;; 末尾呼び出しの最後のジャンプ (define (emit-jmp-tail label) (emit " addi sp, sp, ~s" wordsize) (emit " j ~a" label)) (define (emit-program program) (emit-function-header "scheme_entry") (emit " addi sp, sp, ~s" (- (* wordsize 2))) (emit " sw ra, 0(sp)") (emit " sw s0, ~s(sp)" wordsize) (emit " mv s0, a0") ; heapの空きアドレスは、s0レジスタに保存する。 (emit " call L_scheme_entry") (emit " lw ra, 0(sp)") (emit " lw s0, ~s(sp)" wordsize) (emit " addi sp, sp, ~s" (* wordsize 2)) (emit " ret") (cond ((letrec? program) (emit-letrec program)) (else (emit-scheme-entry program ())))) ;;;; 自動テスト関連 ;;; Schemeプログラムのコンパイル (define (compile-program expr) (with-output-to-file (path "stst.s") (lambda () (emit-program expr)))) ;;; 実行ファイルの作成 (define (build) (unless (zero? (process-exit-wait (run-process "make stst --quiet"))) (error "Could not build target."))) ;;; テスト・プログラムの実行 (define (execute) (unless (zero? (process-exit-wait (run-process out-to: (path "./stst.out") "spike pk ./stst > ./stst.out"))) (error "Produced program exited abnormally."))) ;;; テスト・プログラムの実行結果の検証 (define (validate expected-output) (let ((executed-output (path-data (path "stst.out")))) (unless (string=? expected-output executed-output) (error "Output mismatch for expected ~s, got ~s." expected-output executed-output)))) ;;; 一つのテスト・ケースをテストします。 (define (test-one expr expected-output) (compile-program expr) (build) (execute) (validate expected-output)) ;;; 全てのテストケースをテストします。 (define (test-all) (for-each (lambda (test-case) (format #t "TestCase: ~a ..." (car test-case)) (flush-output-port) (test-one (cadr test-case) (caddr test-case)) (format #t " ok.\n")) test-cases))
true
eb5fd93d9b59bbd7e0f417a5aec0c649abf0b5b0
abc7bd420c9cc4dba4512b382baad54ba4d07aa8
/src/old/plt/network_topologies.ss
5a0612e1fe209d8d2e3f6d41ba0a1e1a3104f9fa
[ "BSD-3-Clause" ]
permissive
rrnewton/WaveScript
2f008f76bf63707761b9f7c95a68bd3e6b9c32ca
1c9eff60970aefd2177d53723383b533ce370a6e
refs/heads/master
2021-01-19T05:53:23.252626
2014-10-08T15:00:41
2014-10-08T15:00:41
1,297,872
10
2
null
null
null
null
UTF-8
Scheme
false
false
243
ss
network_topologies.ss
(module network_toplogy mzscheme (require "simulator_nought.ss") (include (build-path "generic" "network_topologies.ss")) ;; Insure provision of verify-regiment: (provide ;graph object-graph all-objs line-graph ) )
false
c3c0cf55cc21cc5489818442f892e008ad76a165
000dbfe5d1df2f18e29a76ea7e2a9556cff5e866
/sitelib/text/json/patch.scm
2f29b4e74e855c35e0dca45d9ad9c18e23516a6a
[ "BSD-3-Clause", "LicenseRef-scancode-other-permissive", "MIT", "BSD-2-Clause" ]
permissive
ktakashi/sagittarius-scheme
0a6d23a9004e8775792ebe27a395366457daba81
285e84f7c48b65d6594ff4fbbe47a1b499c9fec0
refs/heads/master
2023-09-01T23:45:52.702741
2023-08-31T10:36:08
2023-08-31T10:36:08
41,153,733
48
7
NOASSERTION
2022-07-13T18:04:42
2015-08-21T12:07:54
Scheme
UTF-8
Scheme
false
false
10,637
scm
patch.scm
;;; -*- mode:scheme; coding:utf-8; -*- ;;; ;;; text/json/patch.scm - JSON Patch ;;; ;;; Copyright (c) 2018 Takashi Kato <[email protected]> ;;; ;;; Redistribution and use in source and binary forms, with or without ;;; modification, are permitted provided that the following conditions ;;; are met: ;;; ;;; 1. Redistributions of source code must retain the above copyright ;;; notice, this list of conditions and the following disclaimer. ;;; ;;; 2. Redistributions in binary form must reproduce the above copyright ;;; notice, this list of conditions and the following disclaimer in the ;;; documentation and/or other materials provided with the distribution. ;;; ;;; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ;;; "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT ;;; LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR ;;; A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT ;;; OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, ;;; SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED ;;; TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR ;;; PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF ;;; LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING ;;; NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS ;;; SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ;;; ;; reference: ;; RFC 6902: https://tools.ietf.org/html/rfc6902 #!nounbound (library (text json patch) (export json-patcher json-patch-error? json-patch-error-path ;; only for runtime json-patch-error-patch ;; only for compile json-patch-compile-error? json-patch-runtime-error? json-patch-path-not-found-error? json-patch-illegal-type-error? *json-patcher:ignore-no-such-path*) (import (rnrs) (text json pointer) (text json parse) (text json convert) (text json compare) (text json mutable) (srfi :1 lists) (srfi :39 parameters) (srfi :133 vectors) (util vector)) (define (json-patcher patch) (define (->patcher patch) (fold-left (lambda (combined-patcher patch) (let ((patcher (make-patcher patch))) (lambda (mutable-json) (patcher (combined-patcher mutable-json))))) values patch)) (unless (list? patch) (assertion-violation 'json-patcher "A list is required" patch)) (let ((patcher (->patcher patch))) (lambda (json) (if (mutable-json? json) (patcher json) ;; return mutable json (let ((mutable-json (json->mutable-json json))) (mutable-json->json (patcher mutable-json))))))) (define-condition-type &json-patch &error make-json-patch-error json-patch-error?) (define-condition-type &json-patch:compile &json-patch make-json-patch-compile-error json-patch-compile-error? (patch json-patch-error-patch)) (define-condition-type &json-patch:runtime &json-patch make-json-patch-runtime-error json-patch-runtime-error? (path json-patch-error-path)) (define-condition-type &json-patch-path-not-found &json-patch:runtime make-json-patch-path-not-found-error json-patch-path-not-found-error?) (define-condition-type &json-patch-illegal-type &json-patch:runtime make-json-patch-illegal-type-error json-patch-illegal-type-error?) (define (json-patch-path-not-found-error path who message . irr) (raise (condition (make-json-patch-path-not-found-error path) (make-who-condition who) (make-message-condition message) (make-irritants-condition irr)))) (define (json-patch-illegal-type-error path who message . irr) (raise (condition (make-json-patch-path-not-found-error path) (make-who-condition who) (make-message-condition message) (make-irritants-condition irr)))) (define (key=? key) (lambda (e) (string=? (car e) key))) (define op? (key=? "op")) (define path? (key=? "path")) (define value? (key=? "value")) (define from? (key=? "from")) (define (make-patcher patch) (define (err) (raise (condition (make-json-patch-compile-error patch) (make-who-condition 'json-patcher) (make-message-condition "Invalid JSON patch command") (make-irritants-condition patch)))) (define (find pred) (cond ((vector-find pred patch) => cdr) (else (err)))) (define (check-duplicate pred patch) (let ((index (vector-index pred patch))) (unless (eqv? index (vector-index-right pred patch)) (raise (condition (make-json-patch-compile-error patch) (make-who-condition 'json-patcher) (make-message-condition "Duplicate JSON command") (make-irritants-condition patch)))) (cdr (vector-ref patch index)))) (case (string->symbol (check-duplicate op? patch)) ((add) (make-add-command (find path?) (find value?))) ((remove) (make-remove-command (find path?))) ((replace) (make-replace-command (find path?) (find value?))) ((move) (make-move-command (find from?) (find path?))) ((copy) (make-copy-command (find from?) (find path?))) ((test) (make-test-command (find path?) (find value?))) (else (err)))) (define *json-patcher:ignore-no-such-path* (make-parameter '())) (define (nsp who path mutable-json) (define ls (*json-patcher:ignore-no-such-path*)) (unless (or (eq? who ls) (and (pair? ls) (memv who ls))) (json-patch-path-not-found-error path who "No such path in target JSON document" (mutable-json->json mutable-json)))) (define (rte who path msg mutable-json) (raise (condition (make-json-patch-runtime-error path) (make-who-condition who) (make-message-condition msg) (make-irritants-condition mutable-json)))) (define (check-index who path n) (let ((i (string->number n))) (unless (and (fixnum? i) (not (negative? i))) (rte who path "Illegal index" n)) i)) (define-syntax call-with-last-entry (syntax-rules () ((_ name ?path ?object-handler ?array-handler) (let ((path ?path) (object-handler ?object-handler) (array-handler ?array-handler)) (define tokens (parse-json-pointer path)) (define (ile mutable-json) (json-patch-illegal-type-error path 'name "Parent path to add is not a container" (mutable-json->json mutable-json))) (define (pne mutable-json) (json-patch-path-not-found-error path 'name "Parent node to add does not exist" (mutable-json->json mutable-json))) (let-values (((first last-list) (split-at! tokens (- (length tokens) 1)))) (define last (car last-list)) (lambda (mutable-json) (let loop ((tokens first) (json mutable-json)) (cond ((null? tokens) (cond ((mutable-json-object? json) (object-handler last json mutable-json) mutable-json) ((mutable-json-array? json) (array-handler last json mutable-json) mutable-json) (else (ile mutable-json)))) ((mutable-json-object? json) (let ((e (mutable-json-object-ref json (car tokens)))) (if (mutable-json-not-found? e) (pne mutable-json) (loop (cdr tokens) e)))) ((mutable-json-array? json) (let* ((n (check-index 'name path (car tokens))) (e (mutable-json-array-ref json n))) (if (mutable-json-not-found? e) (pne mutable-json) (loop (cdr tokens) e)))) (else (ile mutable-json)))))))))) (define (make-add-command path value) (if (string=? path "") (lambda (_) (json->mutable-json value)) (call-with-last-entry add path (lambda (last json _) (mutable-json-object-set! json last value)) (lambda (last json root-json) (let ((n (mutable-json-array-size json))) (if (equal? last "-") (mutable-json-array-insert! json n value) (let ((i (check-index 'add path last))) (if (or (negative? i) (> i n)) (rte 'add path "Index out of bound" root-json) (mutable-json-array-insert! json i value))))))))) (define (make-remove-command path) (call-with-last-entry remove path (lambda (last json root-json) (if (mutable-json-object-contains? json last) (mutable-json-object-delete! json last) (nsp 'remove path root-json))) (lambda (last json root-json) (let ((n (check-index 'remove path last))) (if (< n (mutable-json-array-size json)) (mutable-json-array-delete! json n) (nsp 'remove path root-json)))))) (define (make-replace-command path value) (if (string=? path "") (lambda (_) (json->mutable-json value)) (call-with-last-entry replace path (lambda (last json root-json) (if (mutable-json-object-contains? json last) (mutable-json-object-set! json last value) (nsp 'replace path root-json))) (lambda (last json root-json) (let ((n (check-index 'replace path last))) (if (< n (mutable-json-array-size json)) (mutable-json-array-set! json n value) (nsp 'replace path root-json))))))) ;; FIXME inefficient... (define (make-move-command from path) (define tokens (parse-json-pointer from)) (define pointer (json-pointer from)) (define remove (make-remove-command from)) (if (string=? from path) ;; a bit of minior optimisation (lambda (mutable-json) mutable-json) (call-with-last-entry move path (lambda (last json root-json) (let ((v (pointer (mutable-json->json root-json)))) (when (json-pointer-not-found? v) (nsp 'move from root-json)) (mutable-json-object-set! json last (json->mutable-json v)) (remove root-json))) (lambda (last json root-json) (let ((v (pointer (mutable-json->json root-json))) (l (car (last-pair tokens)))) (if (json-pointer-not-found? v) (nsp 'move from root-json) (let ((n (check-index 'move path last))) (unless (equal? last l) (remove root-json) (mutable-json-array-insert! json n (json->mutable-json v)))))))))) ;; FIXME inefficient... (define (make-test-command path value) (define pointer (json-pointer path)) (lambda (mutable-json) (let ((v (pointer (mutable-json->json mutable-json)))) (cond ((json-pointer-not-found? v) (nsp 'test path mutable-json)) ((not (json=? v value)) (json-patch-illegal-type-error path 'test "Unexpected value" v))) mutable-json))) ;; FIXME inefficient... (define (make-copy-command from path) (define pointer (json-pointer from)) (lambda (mutable-json) (let* ((v (pointer (mutable-json->json mutable-json))) (add (make-add-command path v))) (if (json-pointer-not-found? v) (nsp 'copy path mutable-json) (add mutable-json))))) )
true
94ae2324995511765a4422aea2991ecf70b670e3
defeada37d39bca09ef76f66f38683754c0a6aa0
/mscorlib/system/not-finite-number-exception.sls
d4039d34212eae09178ce701b8dfcf58a25e8cc3
[]
no_license
futsuki/ironscheme-port
2dbac82c0bda4f4ff509208f7f00a5211d1f7cd5
4e7a81b0fbeac9a47440464988e53fb118286c54
refs/heads/master
2016-09-06T17:13:11.462593
2015-09-26T18:20:40
2015-09-26T18:20:40
42,757,369
0
0
null
null
null
null
UTF-8
Scheme
false
false
855
sls
not-finite-number-exception.sls
(library (system not-finite-number-exception) (export new is? not-finite-number-exception? get-object-data offending-number) (import (ironscheme-clr-port)) (define-syntax new (lambda (e) (syntax-case e () ((_ a ...) #'(clr-new System.NotFiniteNumberException a ...))))) (define (is? a) (clr-is System.NotFiniteNumberException a)) (define (not-finite-number-exception? a) (clr-is System.NotFiniteNumberException a)) (define-method-port get-object-data System.NotFiniteNumberException GetObjectData (System.Void System.Runtime.Serialization.SerializationInfo System.Runtime.Serialization.StreamingContext)) (define-field-port offending-number #f #f (property:) System.NotFiniteNumberException OffendingNumber System.Double))
true
0c8c60ef584fe2b4f6e86c6bbb719558b26ca5d5
3629e5c33ebbc3acbaa660fb324c26357098147c
/examples/glbook/example9-8.scm
de5f0b5498418f1d2f8c0af4330e72af51a2fdd1
[ "LicenseRef-scancode-x11-sg", "MIT" ]
permissive
shirok/Gauche-gl
f31a62ce4c2d91795f972b668861a77626b02cb5
a569e3009314f81bc513827064e05869220c6a9d
refs/heads/master
2023-06-07T15:56:17.514969
2023-06-01T06:56:48
2023-06-01T06:56:48
9,487,174
4
5
MIT
2018-09-24T21:39:18
2013-04-17T02:13:32
C
UTF-8
Scheme
false
false
3,880
scm
example9-8.scm
;; Example 9-8 Automatic Texture-Coordinate Generation (use gl) (use gl.glut) (use gauche.uvector) ;; Create checkerboard image (define-constant *stripe-image-width* 32) (define *stripe-image* (make-u8vector (* *stripe-image-width* 4))) (define *texname* #f) (define (make-stripe-image) (dotimes (j *stripe-image-width*) (set! (ref *stripe-image* (* 4 j)) (if (<= j 4) 255 0)) (set! (ref *stripe-image* (+ (* 4 j) 1)) (if (> j 4) 255 0)) (set! (ref *stripe-image* (+ (* 4 j) 2)) 0) (set! (ref *stripe-image* (+ (* 4 j) 3)) 255))) ;; planes for texture coordinate generation (define x=0plane '#f32(1.0 0.0 0.0 0.0)) (define slanted '#f32(1.0 1.0 1.0 0.0)) (define *current-coeff* x=0plane) (define *current-plane* 0) (define *current-gen-mode* 0) (define (init) (gl-clear-color 0 0 0 0) (gl-enable GL_DEPTH_TEST) (gl-shade-model GL_SMOOTH) (make-stripe-image) (gl-pixel-store GL_UNPACK_ALIGNMENT 1) (set! *texname* (ref (gl-gen-textures 1) 0)) (gl-bind-texture GL_TEXTURE_1D *texname*) (gl-tex-parameter GL_TEXTURE_1D GL_TEXTURE_WRAP_S GL_REPEAT) (gl-tex-parameter GL_TEXTURE_1D GL_TEXTURE_MAG_FILTER GL_LINEAR) (gl-tex-parameter GL_TEXTURE_1D GL_TEXTURE_MIN_FILTER GL_LINEAR) (gl-tex-image-1d GL_TEXTURE_1D 0 GL_RGBA *stripe-image-width* 0 GL_RGBA GL_UNSIGNED_BYTE *stripe-image*) (gl-tex-env GL_TEXTURE_ENV GL_TEXTURE_ENV_MODE GL_MODULATE) (set! *current-coeff* x=0plane) (set! *current-gen-mode* GL_OBJECT_LINEAR) (set! *current-plane* GL_OBJECT_PLANE) (gl-tex-gen GL_S GL_TEXTURE_GEN_MODE *current-gen-mode*) (gl-tex-gen GL_S *current-plane* *current-coeff*) (gl-enable GL_TEXTURE_GEN_S) (gl-enable GL_TEXTURE_1D) (gl-enable GL_CULL_FACE) (gl-enable GL_LIGHTING) (gl-enable GL_LIGHT0) (gl-enable GL_AUTO_NORMAL) (gl-enable GL_NORMALIZE) (gl-front-face GL_CW) (gl-cull-face GL_BACK) (gl-material GL_FRONT GL_SHININESS 64.0) ) (define (disp) (gl-clear (logior GL_COLOR_BUFFER_BIT GL_DEPTH_BUFFER_BIT)) (gl-push-matrix) (gl-rotate 45.0 0.0 0.0 1.0) (gl-bind-texture GL_TEXTURE_1D *texname*) (glut-solid-teapot 2.0) (gl-pop-matrix) (gl-flush)) (define (reshape w h) (gl-viewport 0 0 w h) (gl-matrix-mode GL_PROJECTION) (gl-load-identity) (if (<= w h) (gl-ortho -3.5 3.5 (* -3.5 (/ h w)) (* 3.5 (/ h w)) -3.5 3.5) (gl-ortho (* -3.5 (/ w h)) (* 3.5 (/ w h)) -3.5 3.5 -3.5 3.5)) (gl-matrix-mode GL_MODELVIEW) (gl-load-identity) ) (define (keyboard key x y) (cond ((or (= key (char->integer #\e)) (= key (char->integer #\E))) (set! *current-gen-mode* GL_EYE_LINEAR) (set! *current-plane* GL_EYE_PLANE) (gl-tex-gen GL_S GL_TEXTURE_GEN_MODE *current-gen-mode*) (gl-tex-gen GL_S *current-plane* *current-coeff*) (glut-post-redisplay)) ((or (= key (char->integer #\o)) (= key (char->integer #\O))) (set! *current-gen-mode* GL_OBJECT_LINEAR) (set! *current-plane* GL_OBJECT_PLANE) (gl-tex-gen GL_S GL_TEXTURE_GEN_MODE *current-gen-mode*) (gl-tex-gen GL_S *current-plane* *current-coeff*) (glut-post-redisplay)) ((or (= key (char->integer #\s)) (= key (char->integer #\S))) (set! *current-coeff* slanted) (gl-tex-gen GL_S *current-plane* *current-coeff*) (glut-post-redisplay)) ((or (= key (char->integer #\x)) (= key (char->integer #\X))) (set! *current-coeff* x=0plane) (gl-tex-gen GL_S *current-plane* *current-coeff*) (glut-post-redisplay)) ((= key 27) (exit 0)) )) (define (main args) (glut-init args) (glut-init-display-mode (logior GLUT_SINGLE GLUT_RGB GLUT_DEPTH)) (glut-init-window-size 256 256) (glut-init-window-position 100 100) (glut-create-window (car args)) (init) (glut-display-func disp) (glut-reshape-func reshape) (glut-keyboard-func keyboard) (glut-main-loop) 0)
false
55bf81bfe34a7b65c5f40cabda855f1d237bdb74
10234762a6cdef7661527989b429dbcb028e0c97
/scm/expand.scm
bd9a6e4bda4c3f6a82f5022728b7e9200e771404
[ "MIT" ]
permissive
davedoesdev/mce
5b8648225a98612f487d6c8162a8d17508c0fb80
b4719e74c70ebd163d4de22520fedbaa16899c07
refs/heads/master
2023-07-21T05:12:36.581604
2022-09-27T18:47:50
2022-09-27T18:47:50
163,390,569
5
1
MIT
2023-07-18T20:40:18
2018-12-28T09:10:43
C++
UTF-8
Scheme
false
false
17,775
scm
expand.scm
(module expand (main main)) (define (main argv) (bigloo-warning-set! 0) (write (cdr (expand `(( (define-syntax define (syntax-rules () ((define (f params ...) body ...) (define f (lambda (params ...) body ...))) ((define (f params . rest) body ...) (define f (lambda (params . rest) body ...))) ((define (f . args) body ...) (define f (lambda args body ...))) ((define var val ...) (mce-define var val ...)))) (define-syntax call/cc (syntax-rules () ((call/cc f) (let/cc k (f k))))) (define-syntax call-with-current-continuation (syntax-rules () ((call-with-current-continuation f) (call/cc f)))) (define-syntax not (syntax-rules () ((not v) (if v #f #t)))) ; Simple version of values and call-with-values for the common case (define-syntax values (syntax-rules () ((values v ...) (list v ...)))) (define-syntax call-with-values (syntax-rules () ((call-with-values producer consumer) (apply consumer (producer))))) ; R5RS Section 7.3 ; https://schemers.org/Documents/Standards/R5RS/HTML/ (define-syntax and (syntax-rules () ((and) #t) ((and test) test) ((and test1 test2 ...) (if test1 (and test2 ...) #f)))) (define-syntax or (syntax-rules () ((or) #f) ((or test) test) ((or test1 test2 ...) (let ((x test1)) (if x x (or test2 ...)))))) (define-syntax case (syntax-rules (else) ((case (key ...) clauses ...) (let ((atom-key (key ...))) (case atom-key clauses ...))) ((case key (else result1 result2 ...)) (begin result1 result2 ...)) ((case key ((atoms ...) result1 result2 ...)) (if (memv key '(atoms ...)) (begin result1 result2 ...))) ((case key ((atoms ...) result1 result2 ...) clause clauses ...) (if (memv key '(atoms ...)) (begin result1 result2 ...) (case key clause clauses ...))))) ; R6RS Appendix B ; http://www.r6rs.org/final/html/r6rs/r6rs-Z-H-16.html#node_chap_B (define-syntax cond (syntax-rules (else =>) ((cond (else result1 result2 ...)) (begin result1 result2 ...)) ((cond (test => result)) (let ((temp test)) (if temp (result temp)))) ((cond (test => result) clause1 clause2 ...) (let ((temp test)) (if temp (result temp) (cond clause1 clause2 ...)))) ((cond (test)) test) ((cond (test) clause1 clause2 ...) (let ((temp test)) (if temp temp (cond clause1 clause2 ...)))) ((cond (test result1 result2 ...)) (if test (begin result1 result2 ...))) ((cond (test result1 result2 ...) clause1 clause2 ...) (if test (begin result1 result2 ...) (cond clause1 clause2 ...))))) (define-syntax let* (syntax-rules () ((let* () body1 body2 ...) (let () body1 body2 ...)) ((let* ((name1 expr1) (name2 expr2) ...) body1 body2 ...) (let ((name1 expr1)) (let* ((name2 expr2) ...) body1 body2 ...))))) (define-syntax letrec (syntax-rules () ((letrec () body1 body2 ...) (let () body1 body2 ...)) ((letrec ((var init) ...) body1 body2 ...) (letrec-helper (var ...) () ((var init) ...) body1 body2 ...)))) (define-syntax letrec-helper (syntax-rules () ((letrec-helper () (temp ...) ((var init) ...) body1 body2 ...) (let ((var 'undefined) ...) (let ((temp init) ...) (set! var temp) ...) (let () body1 body2 ...))) ((letrec-helper (x y ...) (temp ...) ((var init) ...) body1 body2 ...) (letrec-helper (y ...) (newtemp temp ...) ((var init) ...) body1 body2 ...)))) (define-syntax letrec* (syntax-rules () ((letrec* ((var1 init1) ...) body1 body2 ...) (let ((var1 'undefined) ...) (set! var1 init1) ... (let () body1 body2 ...))))) (define-syntax let-values (syntax-rules () ((let-values (binding ...) body1 body2 ...) (let-values-helper1 () (binding ...) body1 body2 ...)))) (define-syntax let-values-helper1 ;; map over the bindings (syntax-rules () ((let-values ((id temp) ...) () body1 body2 ...) (let ((id temp) ...) body1 body2 ...)) ((let-values assocs ((formals1 expr1) (formals2 expr2) ...) body1 body2 ...) (let-values-helper2 formals1 () expr1 assocs ((formals2 expr2) ...) body1 body2 ...)))) (define-syntax let-values-helper2 ;; create temporaries for the formals (syntax-rules () ((let-values-helper2 () temp-formals expr1 assocs bindings body1 body2 ...) (call-with-values (lambda () expr1) (lambda temp-formals (let-values-helper1 assocs bindings body1 body2 ...)))) ((let-values-helper2 (first . rest) (temp ...) expr1 (assoc ...) bindings body1 body2 ...) (let-values-helper2 rest (temp ... newtemp) expr1 (assoc ... (first newtemp)) bindings body1 body2 ...)) ((let-values-helper2 rest-formal (temp ...) expr1 (assoc ...) bindings body1 body2 ...) (call-with-values (lambda () expr1) (lambda (temp ... . newtemp) (let-values-helper1 (assoc ... (rest-formal newtemp)) bindings body1 body2 ...)))))) (define-syntax let (syntax-rules () ((let ((name val) ...) body1 body2 ...) ((lambda (name ...) body1 body2 ...) val ...)) ((let tag ((name val) ...) body1 body2 ...) ((letrec ((tag (lambda (name ...) body1 body2 ...))) tag) val ...)))) (define-syntax let*-values (syntax-rules () ((let*-values () body1 body2 ...) (let () body1 body2 ...)) ((let*-values (binding1 binding2 ...) body1 body2 ...) (let-values (binding1) (let*-values (binding2 ...) body1 body2 ...))))) (define-syntax toplevel (syntax-rules () ((toplevel (f params ...) body ...) (f (lambda (params ...) body ...))) ((toplevel (f params . rest) body ...) (f (lambda (params . rest) body ...))) ((toplevel (f . args) body ...) (f (lambda args body ...))) ((toplevel var val ...) (var initialize (begin val ...))))) (define-syntax toplevel-helper (syntax-rules () ((toplevel-helper (f params ...) body ...) (f helper (lambda (params ...) body ...))) ((toplevel-helper (f params . rest) body ...) (f helper (lambda (params . rest) body ...))) ((toplevel-helper (f . args) body ...) (f helper (lambda args body ...))) ((toplevel-helper var val ...) (var helper initialize (begin val ...))))) ) ( (toplevel (list . args) args) (toplevel (null? v) (and (vector? v) (= (vector-length v) 0))) (toplevel (pair? v) (and (vector? v) (= (vector-length v) 2))) (toplevel (car v) (vector-ref v 0)) (toplevel (cdr v) (vector-ref v 1)) (toplevel (set-car! v x) (vector-set! v 0 x)) (toplevel (set-cdr! v y) (vector-set! v 1 y)) (toplevel (length l) (let loop ((i 0) (l l)) (if (null? l) i (loop (+ i 1) (cdr l))))) (toplevel (vector . els) (let* ((len (length els)) (v (make-vector len))) (let loop ((i 0) (els els)) (if (= i len) v (begin (vector-set! v i (car els)) (loop (+ i 1) (cdr els))))))) (toplevel (cons x y) ;(vector x y)) (let ((v (make-vector 2))) (vector-set! v 0 x) (vector-set! v 1 y) v)) (toplevel (cons* . args) (if (null? (cdr args)) (car args) (cons (car args) (apply cons* (cdr args))))) (toplevel (list-ref l i) (if (= i 0) (car l) (list-ref (cdr l) (- i 1)))) (toplevel (binary=? x y) (let ((len (binary-length x))) (if (= (binary-length y) len) (let loop ((i 0)) (cond ((= i len) #t) ((= (binary-ref x i) (binary-ref y i)) (loop (+ i 1))) (else #f))) #f))) (toplevel (eq? x y) (cond ((or (and (char? x) (char? y)) (and (symbol? x) (symbol? y))) (binary=? x y)) ((and (boolean? x) (boolean? y)) (or (and x y) (and (not x) (not y)))) ((and (number? x) (number? y)) (= x y)) ((and (null? x) (null? y)) #t) ((and (string? x) (string? y)) #f) (else (same-object? x y)))) (toplevel eqv? eq?) (toplevel (equal? x y) (cond ((eqv? x y) #t) ((and (string? x) (string? y)) (binary=? x y)) ((and (vector? x) (vector? y)) (let ((len (vector-length x))) (if (= (vector-length y) len) (let loop ((i 0)) (cond ((= i len) #t) ((equal? (vector-ref x i) (vector-ref y i)) (loop (+ i 1))) (else #f))) #f))) (else #f))) (toplevel (memv o l) (cond ((null? l) #f) ((eqv? (car l) o) #t) (else (memv o (cdr l))))) (toplevel (append l1 l2) (if (null? l1) l2 (cons (car l1) (append (cdr l1) l2)))) (toplevel (assoc k alist) (if (null? alist) #f (if (equal? (car (car alist)) k) (car alist) (assoc k (cdr alist))))) (toplevel (abs x) (if (< x 0) (- x) x)) (toplevel (modulo x y) (let ((d (floor (/ x y)))) (- x (* y d)))) (toplevel (<= x y) (or (< x y) (= x y))) (toplevel (>= x y) (or (> x y) (= x y))) (toplevel (char->integer c) (binary-ref c 1)) (toplevel-helper char-code (char->integer #\B)) (toplevel-helper string-code (char->integer #\C)) (toplevel-helper symbol-code (char->integer #\D)) (toplevel (char? x) (and (binary? x) (= (binary-length x) 2) (= (binary-ref x 0) char-code))) (toplevel (string? x) (and (binary? x) (> (binary-length x) 0) (= (binary-ref x 0) string-code))) (toplevel (symbol? x) (and (binary? x) (> (binary-length x) 0) (= (binary-ref x 0) symbol-code))) (toplevel (binary-copy b . args) (let* ((numargs (length args)) (start (if (> numargs 0) (list-ref args 0) 0)) (end (if (> numargs 1) (list-ref args 1) (binary-length b))) (len (- end start)) (r (make-binary len))) (let loop ((i 0)) (if (< i len) (begin (binary-set! r i (binary-ref b (+ start i))) (loop (+ i 1))))) r)) (toplevel (for-each f l) (if (not (null? l)) (begin (f (car l)) (for-each f (cdr l))))) (toplevel (repeat f n) (if (not (= n 0)) (begin (f) (repeat f (- n 1))))) (toplevel-helper (make-port name output) (lambda (x . args) (cond ((and (binary? x) (not (null? args))) (apply output (cons x args))) ((char? x) (output x 1 2)) ((or (symbol? x) (string? x)) (output x 1 (binary-length x))) ((binary? x) (apply output (cons x args))) (else (error name "unknown expression" x))))) (toplevel-helper output-port (make-port "current-output-port" output-binary-to-stdout)) (toplevel-helper error-port (make-port "current-error-port" output-binary-to-stderr)) (toplevel (current-output-port) output-port) (toplevel (current-error-port) error-port) (toplevel-helper hexchars "0123456789abcdef") (toplevel-helper (byte->binhex b) (let ((bin (make-binary 2))) (binary-set! bin 1 (binary-ref hexchars (+ 1 (modulo b 16)))) (binary-set! bin 0 (binary-ref hexchars (+ 1 (floor (/ b 16))))) bin)) (toplevel-helper space-code (char->integer #\space)) (toplevel-helper tilde-code (char->integer #\~)) (toplevel-helper backslash-code (char->integer #\\)) (toplevel-helper (printable? i) (and (>= i space-code) (<= i tilde-code))) (toplevel-helper (write-binary b port start wrap-char) (let ((wrap-code (char->integer wrap-char)) (end (binary-length b))) (port wrap-char) (let loop ((i start) (prev start)) (if (< i end) (let ((c (binary-ref b i))) (cond ((or (= c wrap-code) (= c backslash-code)) (if (< prev i) (port b prev i)) (port #\\) (port b i (+ i 1)) (let ((next (+ i 1))) (loop next next))) ((printable? c) (loop (+ i 1) prev)) (else (if (< prev i) (port b prev i)) (port #\x) (port (byte->binhex c) 0 2) (let ((next (+ i 1))) (loop next next))))) (if (< prev end) (port b prev end)))) (port wrap-char))) (toplevel (display-binary b . args) (let* ((args-len (length args)) (port (if (> args-len 0) (list-ref args 0) (current-output-port))) (start (if (> args-len 1) (list-ref args 1) 0)) (end (if (> args-len 2) (list-ref args 2) (binary-length b)))) (port b start end))) (toplevel-helper (display-aux x port is-write) (cond ((null? x) (port "()")) ((boolean? x) (port (if x "#t" "#f"))) ((number? x) (if (< x 0) (port #\-)) (let* ((ax (abs x)) (whole (floor ax)) (p '())) (let loop ((n whole)) (let ((digit (modulo n 10)) (b (make-binary 1))) (binary-set! b 0 (+ (char->integer #\0) digit)) (set! p (cons b p)) (let ((next (floor (/ n 10)))) (if (= next 0) (for-each (lambda (b) (port b 0 1)) p) (loop next))))) (let* ((digit (modulo (floor ax) 10)) (n (- ax (- (floor ax) digit)))) (if (> n digit) (begin (port #\.) (let loop ((i 0) (f (* n 10)) (zeros 0)) (let* ((digit (modulo (floor f) 10)) (n (- f (- (floor f) digit)))) (if (= digit 0) (set! zeros (+ zeros 1)) (let ((b (make-binary 1))) (repeat (lambda () (port #\0)) zeros) (set! zeros 0) (binary-set! b 0 (+ (char->integer #\0) digit)) (port b 0 1))) (if (and (< i 6) (> n digit)) (loop (+ i 1) (* n 10) zeros))))))))) ((char? x) (if is-write (let ((c (char->integer x))) (port #\\) (if (printable? c) (port x) (begin (port "x" (port (byte->binhex c) 0 2))))) (port x))) ((string? x) (if is-write (write-binary x port 1 #\") (port x))) ((symbol? x) (if is-write (write-binary x port 1 #\|) (port x))) ((pair? x) (port #\() (let loop ((x x)) (display-aux (car x) port is-write) (let ((y (cdr x))) (if (pair? y) (begin (port #\space) (loop y)) (if (not (null? y)) (begin (port " . ") (display-aux y port is-write)))))) (port #\))) ((vector? x) (port "#(") (let loop ((i 0)) (if (< i (vector-length x)) (begin (if (> i 0) (port #\space)) (display-aux (vector-ref x i) port is-write) (loop (+ i 1))))) (port #\))) ((procedure? x) (port "#<procedure>")) (else (error "display-aux" "unknown expression" x)))) (toplevel-helper (port-from-args args) (if (null? args) (current-output-port) (car args))) (toplevel (display x . args) (display-aux x (port-from-args args) #f)) (toplevel (newline . args) ((port-from-args args) #\newline)) (toplevel-helper (print-aux args port) (for-each (lambda (x) (display-aux x port #f)) args) (newline port)) (toplevel (print . args) (print-aux args (current-output-port))) (toplevel (eprint . args) (print-aux args (current-error-port))) (toplevel (write x . args) (display-aux x (port-from-args args) #t)) ) ,(read))))))
true
b5507f6f8d5e94da2696d483d712655454c19ca4
defeada37d39bca09ef76f66f38683754c0a6aa0
/System/system/net/end-point.sls
d4f7c07bde0673cca783511b91614a4d70c5bdd1
[]
no_license
futsuki/ironscheme-port
2dbac82c0bda4f4ff509208f7f00a5211d1f7cd5
4e7a81b0fbeac9a47440464988e53fb118286c54
refs/heads/master
2016-09-06T17:13:11.462593
2015-09-26T18:20:40
2015-09-26T18:20:40
42,757,369
0
0
null
null
null
null
UTF-8
Scheme
false
false
607
sls
end-point.sls
(library (system net end-point) (export is? end-point? create serialize address-family) (import (ironscheme-clr-port)) (define (is? a) (clr-is System.Net.EndPoint a)) (define (end-point? a) (clr-is System.Net.EndPoint a)) (define-method-port create System.Net.EndPoint Create (System.Net.EndPoint System.Net.SocketAddress)) (define-method-port serialize System.Net.EndPoint Serialize (System.Net.SocketAddress)) (define-field-port address-family #f #f (property:) System.Net.EndPoint AddressFamily System.Net.Sockets.AddressFamily))
false
497c32369633a68e7c878b49bdaface3fa853af7
defeada37d39bca09ef76f66f38683754c0a6aa0
/mscorlib/system/text/encoder-fallback-buffer.sls
54fe2231eacbd6b1b97663a0bdc902a5e4e0f500
[]
no_license
futsuki/ironscheme-port
2dbac82c0bda4f4ff509208f7f00a5211d1f7cd5
4e7a81b0fbeac9a47440464988e53fb118286c54
refs/heads/master
2016-09-06T17:13:11.462593
2015-09-26T18:20:40
2015-09-26T18:20:40
42,757,369
0
0
null
null
null
null
UTF-8
Scheme
false
false
1,046
sls
encoder-fallback-buffer.sls
(library (system text encoder-fallback-buffer) (export is? encoder-fallback-buffer? move-previous? fallback? get-next-char reset remaining) (import (ironscheme-clr-port)) (define (is? a) (clr-is System.Text.EncoderFallbackBuffer a)) (define (encoder-fallback-buffer? a) (clr-is System.Text.EncoderFallbackBuffer a)) (define-method-port move-previous? System.Text.EncoderFallbackBuffer MovePrevious (System.Boolean)) (define-method-port fallback? System.Text.EncoderFallbackBuffer Fallback (System.Boolean System.Char System.Char System.Int32) (System.Boolean System.Char System.Int32)) (define-method-port get-next-char System.Text.EncoderFallbackBuffer GetNextChar (System.Char)) (define-method-port reset System.Text.EncoderFallbackBuffer Reset (System.Void)) (define-field-port remaining #f #f (property:) System.Text.EncoderFallbackBuffer Remaining System.Int32))
false
afdc3366670b9cb382d9f180d2d6caa549ca5145
000dbfe5d1df2f18e29a76ea7e2a9556cff5e866
/ext/crypto/tests/test-k-409.scm
74252b451044a88038142e4792faf8c672d1448d
[ "BSD-3-Clause", "LicenseRef-scancode-other-permissive", "MIT", "BSD-2-Clause" ]
permissive
ktakashi/sagittarius-scheme
0a6d23a9004e8775792ebe27a395366457daba81
285e84f7c48b65d6594ff4fbbe47a1b499c9fec0
refs/heads/master
2023-09-01T23:45:52.702741
2023-08-31T10:36:08
2023-08-31T10:36:08
41,153,733
48
7
NOASSERTION
2022-07-13T18:04:42
2015-08-21T12:07:54
Scheme
UTF-8
Scheme
false
false
8,021
scm
test-k-409.scm
;; [K-409,SHA-1] #| Msg = 8c5d3d80e6d03556cd458e6d67b8e5b4b15d3948 d = 020949c88cd44684f6d19c0d7b385796760f1c31f34beb3b8a26ca421eb62fccc51bcd5d1029a648ea1ca16c8f032dc3ebe2472 Qx = 077ae5742fffe220aef07e5cdc001e17f223c22eff6eb5bcfee4d9c9677377f82fcbcd04a6f2a88586802f9dbfabcbe88e1d9c2 Qy = 13957372470c01196758f5e836491649e04c302b5ea11f48e73b8516d2d1c632cdfe7545c6b9b9a7638ded507905659b03dbe7c k = 03b19d4a3b2b7851cc316f323b5d303f2da929392a8ac6fadad82d3117945e9a8c47097a7e21c0dea193d593058022596413dc1 R = 036b1b97d3a2308f11792f04580bc2d194f0f48bd27c71ff98e60ddc6fa73ea8314a8337e4890bc857a9ea84e57f15767e95673 S = 0249ba42cfb7a426a2b4ccac06c6b8d01d390f236a11c0dce7466b7637d4dd0de0522f6553cb8634d3ce71844c88127b15489fe |# (test-ecdsa NIST-K-409 no-20 #x8c5d3d80e6d03556cd458e6d67b8e5b4b15d3948 #x020949c88cd44684f6d19c0d7b385796760f1c31f34beb3b8a26ca421eb62fccc51bcd5d1029a648ea1ca16c8f032dc3ebe2472 #x077ae5742fffe220aef07e5cdc001e17f223c22eff6eb5bcfee4d9c9677377f82fcbcd04a6f2a88586802f9dbfabcbe88e1d9c2 #x13957372470c01196758f5e836491649e04c302b5ea11f48e73b8516d2d1c632cdfe7545c6b9b9a7638ded507905659b03dbe7c #x03b19d4a3b2b7851cc316f323b5d303f2da929392a8ac6fadad82d3117945e9a8c47097a7e21c0dea193d593058022596413dc1 #x036b1b97d3a2308f11792f04580bc2d194f0f48bd27c71ff98e60ddc6fa73ea8314a8337e4890bc857a9ea84e57f15767e95673 #x0249ba42cfb7a426a2b4ccac06c6b8d01d390f236a11c0dce7466b7637d4dd0de0522f6553cb8634d3ce71844c88127b15489fe ) ;; [K-409,SHA-224] #| Msg = ed859725cd0eba74bfaf7d7be2633bc04a98a9d9e18a602d2c69aeac d = 011c6528939672bed3e8c905b7ba594c3ce95f37fb28044f210cccd01dfdb42c10e8e1a0b5d6fc757834ca7f08e98cbc52b0edd Qx = 00b570ec1fd09d7b4d102f83cf37129d94c9cf2f982b702c5d1172bae2df558008518493c08dac6f76a6646156f123c4f33e798 Qy = 0e3cfe1aafbf25a5a4536d6c0cfe13a540b4a3c97d4e7bc6c0346addb4b0c32dce089a7a5385e8a3e67606b45e2062c642bbbad k = 027cecbe83853037cf46aa98e1e1e552a96af0bb24e57756d8239fea5d769b51b83f195b7801b562259ee644ab4047764d130a0 R = 06a1601e07dfdff9d3b4ffdbff124b717403490853099fb4a00ea98f84ddd64e908f99b40a2ba6ab88b2491a8d948fcc2f207db S = 0741d27c0dddca3641b56ba1e9bacb0da1fcee46b9e33ecc6990b98cf0db74668ef1009a50e5d55f80e6642ea48689a529c8a08 |# (test-ecdsa NIST-K-409 no-28 #xed859725cd0eba74bfaf7d7be2633bc04a98a9d9e18a602d2c69aeac #x011c6528939672bed3e8c905b7ba594c3ce95f37fb28044f210cccd01dfdb42c10e8e1a0b5d6fc757834ca7f08e98cbc52b0edd #x00b570ec1fd09d7b4d102f83cf37129d94c9cf2f982b702c5d1172bae2df558008518493c08dac6f76a6646156f123c4f33e798 #x0e3cfe1aafbf25a5a4536d6c0cfe13a540b4a3c97d4e7bc6c0346addb4b0c32dce089a7a5385e8a3e67606b45e2062c642bbbad #x027cecbe83853037cf46aa98e1e1e552a96af0bb24e57756d8239fea5d769b51b83f195b7801b562259ee644ab4047764d130a0 #x06a1601e07dfdff9d3b4ffdbff124b717403490853099fb4a00ea98f84ddd64e908f99b40a2ba6ab88b2491a8d948fcc2f207db #x0741d27c0dddca3641b56ba1e9bacb0da1fcee46b9e33ecc6990b98cf0db74668ef1009a50e5d55f80e6642ea48689a529c8a08 ) ;; [K-409,SHA-256] #| Msg = b54f7fa7896de9313b657f1044c38cde4bdad2fa92cc47575c6d980c197ba685 d = 01b8dfd64563dc219d6eeb53f2e3ad1d771140d0960b211dc1f757af5e297dc7548d6133ddb574711d466688f80dbd65a7bbcdc Qx = 1ec530638ea0663cd3a9b237dd66402adf50d3094391f2343d7d6c52c1d14145c245464a3b771e4b1894462fbfaf440e53eef7e Qy = 18349e244b24c8353811c29a60d8e02caf195a424aeafdfd0361846d5ce5eb83da1901700f00fcb85a0c2543b49a8a3ccbac157 k = 026a26cd09c9329cd45ceb4c798846dd81af67759794f5cadab84de19a835f8a0ae49b12853b1e92822477a73891f85acce4216 R = 04d83a5f9dad246717135bec6e386ec6b73be9ea6d1a17334ea2003a723d510914167d136254d6cb64b16ef7eec5044b8f2ba28 S = 03e81601d0c66b507a491c530075edc5b09d770633a4c2355b3b1c7df9b200ebc7dcb706be1696aab70d4c6e1c4a7e532284670 |# (test-ecdsa NIST-K-409 no-32 #xb54f7fa7896de9313b657f1044c38cde4bdad2fa92cc47575c6d980c197ba685 #x01b8dfd64563dc219d6eeb53f2e3ad1d771140d0960b211dc1f757af5e297dc7548d6133ddb574711d466688f80dbd65a7bbcdc #x1ec530638ea0663cd3a9b237dd66402adf50d3094391f2343d7d6c52c1d14145c245464a3b771e4b1894462fbfaf440e53eef7e #x18349e244b24c8353811c29a60d8e02caf195a424aeafdfd0361846d5ce5eb83da1901700f00fcb85a0c2543b49a8a3ccbac157 #x026a26cd09c9329cd45ceb4c798846dd81af67759794f5cadab84de19a835f8a0ae49b12853b1e92822477a73891f85acce4216 #x04d83a5f9dad246717135bec6e386ec6b73be9ea6d1a17334ea2003a723d510914167d136254d6cb64b16ef7eec5044b8f2ba28 #x03e81601d0c66b507a491c530075edc5b09d770633a4c2355b3b1c7df9b200ebc7dcb706be1696aab70d4c6e1c4a7e532284670 ) ;; [K-409,SHA-384] #| Msg = dc6584ffcc737b12762bf2e98510080f0037d2e50fde81b7bc64531165eb7beb580c4657f4c6f3f9febcfedfcc09c175 d = 06f2c6e9ea8109223d9a349fce14927618fc4fa95e05ecf9aba1546619eaeaca7b5815cc07e97ae8cd1e9973ac603f84d838393 Qx = 1f5a9824584cbb0d5ed57f677caf62df77933ce19495d2df86855fb16456a50f157d18f35ff79b8a841a44ee821b36ea93b4f40 Qy = 1a88299000c07a9ad0e57c22fa8f15218cd90ea1de5b8c56d69506ad0fd12b513ffbd224cb6ad590b79c7677a8eda47a8bdc484 k = 042325aded3f71fc3ff0c84106f80a10af08d76d5e710a35d462e880e015a36d063599573ce2044537b9f62b51ed4fd2ed8b860 R = 0667c74ee2d632aed13cad47e0b46a5176940652d7da613e4965876e7e22d89994bdeadd6b5d9361c516fd51a4fb6b60b537e9c S = 026a01220a1166a4d0172428753e98caf0aaac5b0a09c5a3f11b2645d243991d141f59d6cc502ac44b70e7c48d6b0d7b6ec4869 |# (test-ecdsa NIST-K-409 no-48 #xdc6584ffcc737b12762bf2e98510080f0037d2e50fde81b7bc64531165eb7beb580c4657f4c6f3f9febcfedfcc09c175 #x06f2c6e9ea8109223d9a349fce14927618fc4fa95e05ecf9aba1546619eaeaca7b5815cc07e97ae8cd1e9973ac603f84d838393 #x1f5a9824584cbb0d5ed57f677caf62df77933ce19495d2df86855fb16456a50f157d18f35ff79b8a841a44ee821b36ea93b4f40 #x1a88299000c07a9ad0e57c22fa8f15218cd90ea1de5b8c56d69506ad0fd12b513ffbd224cb6ad590b79c7677a8eda47a8bdc484 #x042325aded3f71fc3ff0c84106f80a10af08d76d5e710a35d462e880e015a36d063599573ce2044537b9f62b51ed4fd2ed8b860 #x0667c74ee2d632aed13cad47e0b46a5176940652d7da613e4965876e7e22d89994bdeadd6b5d9361c516fd51a4fb6b60b537e9c #x026a01220a1166a4d0172428753e98caf0aaac5b0a09c5a3f11b2645d243991d141f59d6cc502ac44b70e7c48d6b0d7b6ec4869 ) ;; [K-409,SHA-512] #| Msg = ebab611a758c1ba987336d3563d8ec35b8437d99e7d8ce94c9d33bb46dd850a681d7aab61c24ebef7a6517140312163556b12e58ae88b780f970694a8f2994ab d = 065b76c6093d9c49591293471286df1a4444e60d9d06cfa114e175afb5f119d2abeb273b0596019a0ec5db5b5869f2cc827b364 Qx = 0266321fd15bf6b1af862496f467069819e3860f74a07825e68f3d023985bfbb838a49b6a41b6515cacf404ebf12ce0bd3d6d70 Qy = 01593c7a8e629599e63d3282cbea78023518277e6731fe8d88cbe525ded554b51a7f8803ab9e330f210619dd07df8f67e1066a4 k = 035682af873829e16b72bb86f3ee99b5d9f052e4a631b07f87d3b361c8d8260a877231dbcb3f4d461b4a1d4467824a26a5a6414 R = 00a483dc2dc6408c256fdf63b04d71d3c58a08db7167da217f466cbbfb2d68444c10e87a9a1bb04efd71135c00226e58414d407 S = 078acfad2f2492f74b0281d53e4224c7544588ca9ceaeb16bf759b20c2f3d3ed69c64615c247213d51800569dc8b00078de68ef |# (test-ecdsa NIST-K-409 no-64 #xebab611a758c1ba987336d3563d8ec35b8437d99e7d8ce94c9d33bb46dd850a681d7aab61c24ebef7a6517140312163556b12e58ae88b780f970694a8f2994ab #x065b76c6093d9c49591293471286df1a4444e60d9d06cfa114e175afb5f119d2abeb273b0596019a0ec5db5b5869f2cc827b364 #x0266321fd15bf6b1af862496f467069819e3860f74a07825e68f3d023985bfbb838a49b6a41b6515cacf404ebf12ce0bd3d6d70 #x01593c7a8e629599e63d3282cbea78023518277e6731fe8d88cbe525ded554b51a7f8803ab9e330f210619dd07df8f67e1066a4 #x035682af873829e16b72bb86f3ee99b5d9f052e4a631b07f87d3b361c8d8260a877231dbcb3f4d461b4a1d4467824a26a5a6414 #x00a483dc2dc6408c256fdf63b04d71d3c58a08db7167da217f466cbbfb2d68444c10e87a9a1bb04efd71135c00226e58414d407 #x078acfad2f2492f74b0281d53e4224c7544588ca9ceaeb16bf759b20c2f3d3ed69c64615c247213d51800569dc8b00078de68ef )
false
783b1f3a26ce3ec269d3b9c4cf1ce78fa503b063
a10b9011582079d783282e79e4cfdc93ace6f6d3
/exercises/01/08fastpow.scm
fea75d4eb3e52cd87012d73595cc66748504862d
[]
no_license
hristozov/fpkn1415
2996a488c1feba6a595e466ca42a1418b03e2a77
9b44eb9c9ff4402ff22c2a5f55285c1f59b99722
refs/heads/master
2016-09-05T13:02:38.264241
2015-08-22T14:11:05
2015-08-22T14:11:05
24,793,324
11
1
null
null
null
null
UTF-8
Scheme
false
false
338
scm
08fastpow.scm
(load "../../lib/scm/unit.scm") (define (pow2 x) (* x x)) (define (pow x n) (cond ((= n 0) 1) ((= (remainder n 2) 0) (pow2 (pow x (/ n 2)))) (else (* x (pow x (- n 1)))))) (assert= 1 (pow 2 0)) (assert= 2 (pow 2 1)) (assert= 4 (pow 2 2)) (assert= 1024 (pow 2 10)) (assert= 1024 (pow -2 10)) (assert= -2048 (pow -2 11))
false
6d486ff3a1e1df947e02655efd285c091126e42f
61a331dd81da7a300e9771514468ff2b50d88090
/srfi/guile2.2/match.scm
685965ac6debf0d86033d3cf7d6369cbe0029d47
[]
no_license
fthibault1969/s204
f89d97efd0b60cf654b5567e8acf77965aafd904
f470aba7f98569886d06e0ab99be7aca1a92632c
refs/heads/master
2022-11-29T13:02:55.681801
2020-07-18T09:33:24
2020-07-18T09:33:24
280,176,151
0
1
null
2020-07-18T17:30:13
2020-07-16T14:30:52
Scheme
UTF-8
Scheme
false
false
507
scm
match.scm
(define-module (guile2.2 match) #:export (match match-lambda match-lambda* match-let match-letrec match-let*)) ;; Support for record matching. (define-syntax slot-ref (syntax-rules () ((_ rtd rec n) (struct-ref rec n)))) (define-syntax slot-set! (syntax-rules () ((_ rtd rec n value) (struct-set! rec n value)))) (define-syntax is-a? (syntax-rules () ((_ rec rtd) (and (struct? rec) (eq? (struct-vtable rec) rtd))))) (include-from-path "./match/match.scm")
true
e68355466703342f22c302ae69b87fe53a37bef8
b14c18fa7a4067706bd19df10f846fce5a24c169
/Chapter2/2.64.scm
8f1ab526a8c9c10c7575eccffb40dde0c818e9b6
[]
no_license
silvesthu/LearningSICP
eceed6267c349ff143506b28cf27c8be07e28ee9
b5738f7a22c9e7967a1c8f0b1b9a180210051397
refs/heads/master
2021-01-17T00:30:29.035210
2016-11-29T17:57:16
2016-11-29T17:57:16
19,287,764
3
0
null
null
null
null
UTF-8
Scheme
false
false
2,694
scm
2.64.scm
#lang scheme (define (entry tree) (car tree)) (define (left-branch tree) (cadr tree)) (define (right-branch tree) (caddr tree)) (define (make-tree entry left right) (list entry left right)) (define (element-of-set? x set) (cond ((null? set) #f) ((= x (entry set)) #t) ((< x (entry set)) (element-of-set? x (left-branch set))) ((> x (entry set)) (element-of-set? x (right-branch set))))) (define (adjoin-set x set) (cond ((null? set) (make-tree x '() '())) ((= x (entry set)) set) ((< x (entry set)) (make-tree (entry set) (adjoin-set x (left-branch set)) (right-branch set))) ((> x (entry set)) (make-tree (entry set) (left-branch set) (adjoin-set x (right-branch set)))))) ; above from https://github.com/jaroslawr/sicp/blob/master/2-64-partial-tree.scm (define (partial-tree elts n) (if (= n 0) (cons '() elts) (let ((left-size (quotient (- n 1) 2))) (let ((left-result (partial-tree elts left-size))) (let ((left-tree (car left-result)) (non-left-elts (cdr left-result)) (right-size (- n (+ left-size 1)))) (let ((this-entry (car non-left-elts)) (right-result (partial-tree (cdr non-left-elts) right-size))) (let ((right-tree (car right-result)) (remaining-elts (cdr right-result))) (cons (make-tree this-entry left-tree right-tree) remaining-elts)))))))) (define (list->tree elements) (car (partial-tree elements (length elements))) ) (list->tree '(1 3 5 7 9 11)) ; 5 ; 1 9 ; 3 7 11 ; a = b * quotient + remainder ; Example: '(1 3 5 7 9 11) ; partial-tree : (list length) -> (left-tree (this-entry elements-left)) ; n = 0 -> '() ; n != 0 ; left-size = (6 - 1) / 2 = 2, right-size = (6 - 2 - 1) = 3 ; for the first iteration ; left-result <- recursive call to split convert left half of sub-list to left-tree ; right-result <- recursive call to split convert right half of sub-ist to left-tree ; this-entry <- center element (left one) in sub-list ; remaining-elts <- elements left in list (those are not converted to tree yet) ; So processing sequence will be a pre-order traversal (construction) which consume the original list form left to right ; ---------------------------- ; order of growth in the numer of steps ; every tree-node will be accessed once (creation) and no complex operation during the iteration ; so overall time complexity should be O(n)
false
dde765227ea0bc6eccbdf63b8e6ff027ba04a347
9b2eb10c34176f47f7f490a4ce8412b7dd42cce7
/lib-r7c/r7c-system/let-syntax.sls
e92727127c80c6ca70543da945409533f3edf4c8
[ "LicenseRef-scancode-public-domain", "CC0-1.0" ]
permissive
okuoku/yuni
8be584a574c0597375f023c70b17a5a689fd6918
1859077a3c855f3a3912a71a5283e08488e76661
refs/heads/master
2023-07-21T11:30:14.824239
2023-06-11T13:16:01
2023-07-18T16:25:22
17,772,480
36
6
CC0-1.0
2020-03-29T08:16:00
2014-03-15T09:53:13
Scheme
UTF-8
Scheme
false
false
793
sls
let-syntax.sls
(library (r7c-system let-syntax) (export let-syntax letrec-syntax) (import (r7c-system core) (r7c-expander-interface) (r7c syntax letcore) (r7c-system synrules)) (define-syntax letrec-syntax (syntax-rules () ((_ ((nam trans) ...) body ...) ($let/core () (define-syntax nam trans) ... ($let/core () body ...))))) (define-syntax let-syntax (syntax-rules () ((_ () body ...) ;; term ($let/core () body ...)) ((_ ((nam trans) . rest) body ...) ;; Rename this step ($let/core () (define-syntax temp trans) (let-syntax rest ($alias nam temp) body ...))))) )
true
aec061681c56dfda1afbfcac699412be3ee41904
ccd36329266324496e5ee15a51d87971a4ad2295
/netprog_chatserver/chat_server.scm
9855deaa2bbd06a3f692840de91a56ac0db56d7c
[]
no_license
aweinstock314/lisp-stuff
5b15366836190fbde37227d3ec77cdc08e026091
ef132d54907a3ee152c91e776f08689dae7243f6
refs/heads/master
2021-01-22T09:18:02.485208
2014-12-09T21:45:50
2014-12-09T21:45:50
20,958,912
1
0
null
null
null
null
UTF-8
Scheme
false
false
19,067
scm
chat_server.scm
(define-alias Integer java.lang.Integer) (define-alias Character java.lang.Character) (define-alias Thread java.lang.Thread) (define-alias StringBuilder java.lang.StringBuilder) (define-alias Short java.lang.Short) (define-alias Socket java.net.Socket) (define-alias SocketAddress java.net.SocketAddress) (define-alias ServerSocket java.net.ServerSocket) (define-alias DatagramSocket java.net.DatagramSocket) (define-alias DatagramPacket java.net.DatagramPacket) (define-alias ServerSocketChannel java.nio.channels.ServerSocketChannel) (define-alias DatagramChannel java.nio.channels.DatagramChannel) (define-alias SocketChannel java.nio.channels.SocketChannel) (define-alias Set java.util.Set) (define-alias Map java.util.Map) (define-alias Math java.lang.Math) (define-alias HashMap java.util.HashMap) (define-alias SelectionKey java.nio.channels.SelectionKey) (define-alias ByteBuffer java.nio.ByteBuffer) (define-alias BufferedInputStream java.io.BufferedInputStream) (define-alias OutputStreamWriter java.io.OutputStreamWriter) (define-alias PrintStream java.io.PrintStream) (define-alias BufferedReader java.io.BufferedReader) (define-alias InputStreamReader java.io.InputStreamReader) (define-alias InputStream java.io.InputStream) (define-alias ByteArrayInputStream java.io.ByteArrayInputStream) (define-alias SynchronousQueue java.util.concurrent.SynchronousQueue) (define-alias LinkedBlockingQueue java.util.concurrent.LinkedBlockingQueue) (define-alias BlockingQueue java.util.concurrent.BlockingQueue) (define (synchronizedHashMap) (java.util.Collections:synchronizedMap (HashMap))) (define (random maximum) ((Math:floor (* maximum (Math:random))):intValue)) (define *verbose-mode* #f) (define *debug-mode* #f) (define *datagram-buffer-max* 500) ;(define *message-queue* ::BlockingQueue (SynchronousQueue)) ;(define tcp-address-map ::HashMap (HashMap)) ; String->Socket ;(define udp-address-map ::HashMap (HashMap)) ; String->SocketAddress (define *address-map* ::java.util.Map (java.util.Collections:synchronizedMap (HashMap))) ; String->sender-context ;(define *revaddr-map* ::java.util.Map (java.util.Collections:synchronizedMap (HashMap))) ; sender-context->String (define *forge-message-count* 3) (define *last-senders* ::Map (synchronizedHashMap)) ; username->list, stores senders to each user, resets to empty list when reaching the counter for a forged message (define-macro (printf fmt #!rest args) `(java.lang.System:out:printf ,fmt ,@args)) (define-macro (dbprintf fmt #!rest args) `(when *debug-mode* (java.lang.System:out:printf ,fmt ,@args))) (define-macro (verbose-printf fmt #!rest args) `(when *verbose-mode* (java.lang.System:out:printf ,fmt ,@args))) ;(define (verbose-printf fmt ::string #!rest args ::Object[]) (if *verbose-mode* (printf fmt args) (printf "not in verbose mode"))) ; "anaphoric if" - binds the variable "it" to avoid redundant computation (define-macro (aif test then-clause #!optional (else-clause '())) `(let ((it ,test)) (if it ,then-clause ,else-clause ) ) ) (define-macro (acond #!rest clauses) (if (not (null? clauses)) (let ((clause (car clauses))) (if (not (null? clause)) (let ( (test (car clause)) (body (cdr clause)) ) `(aif ,test (begin ,@body) (acond ,@(cdr clauses)) ) ) '() ) ) '() ) ) ; if any exceptions are encountered while executing body, just return false (define-macro (ignore-exceptions #!rest body) `(try-catch ,@body (e java.lang.Exception (when *debug-mode* (e:printStackTrace)) #f) ) ) (define-macro (loop-forever #!rest body) `(do () (#f #f) ,@body ) ) (define-macro (regex-case string-expr matcher-name #!rest args) (let ((strvar (gentemp))) `(let ((,strvar ::String ,string-expr) (,matcher-name ::java.util.regex.Matcher #!null)) (cond ,@(map (lambda (arg) (let ((regex-str ::String (car arg)) (body-exprs (cdr arg))) `((begin (set! ,matcher-name (invoke (invoke-static java.util.regex.Pattern 'compile ,regex-str ,(bitwise-ior java.util.regex.Pattern:DOTALL java.util.regex.Pattern:MULTILINE)) 'matcher ,strvar)) (*:find ,matcher-name) ) ,@body-exprs ) ) ) args) (#t (error "Fell off the end of regex-case.")) ) ) ) ) (define-macro (aif/nn test-c then-c #!optional (else-c '())) `(let ((it ,test-c)) (if (not (equal? it #!null)) ,then-c ,else-c) ) ) (define (null-default val default) (if (equal? val #!null) default val)) (define-macro (let/cc ccname #!rest body) `(call-with-current-continuation (lambda (,ccname) ,@body))) ;;postfix type-annotations interact poorly with macros ;(define-macro (foreach-iter var-name iter-name #!rest body) ; `(while (*:hasNext ,iter-name) ; (let ((,var-name (*:next ,iter-name))) ; ,@body ; ) ; ) ;) ;(define (extract-datagram datagram-socket ::DatagramSocket) ; (let* ( ; (bytearr (byte[] *datagram-buffer-max*)) ; (packet ::DatagramPacket (DatagramPacket bytearr bytearr:length)) ; ) ; (datagram-socket:receive packet) ; packet ; ) ;) (define (read-datagram datagram-channel ::DatagramChannel) (let* ( (bytearr (byte[] length: *datagram-buffer-max*)) (buffer ::ByteBuffer (ByteBuffer:wrap bytearr)) (sourceaddr ::java.net.SocketAddress (datagram-channel:receive buffer)) (packet ::DatagramPacket (DatagramPacket bytearr bytearr:length sourceaddr)) ) ;(dbprintf "bytearr: %s\n" (String bytearr)) packet ) ) ; class that listens on a port and provides a receive method that returns either a UDP datagram or a TCP connection ;; some details assisted by "http://stackoverflow.com/questions/2819274/listening-for-tcp-and-udp-requests-on-the-same-port" (define-simple-class tcp-udp-socket () (tcpchannel ::ServerSocketChannel) (udpchannel ::DatagramChannel) (channel-selector ::java.nio.channels.Selector) ((*init* port ::int) access: 'public (let ((sockaddr ::java.net.SocketAddress (java.net.InetSocketAddress port))) (set! tcpchannel (ServerSocketChannel:open)) (set! udpchannel (DatagramChannel:open)) ((tcpchannel:socket):bind sockaddr) ((udpchannel:socket):bind sockaddr) (tcpchannel:configureBlocking #f) (udpchannel:configureBlocking #f) (set! channel-selector (java.nio.channels.Selector:open)) (tcpchannel:register channel-selector SelectionKey:OP_ACCEPT) (udpchannel:register channel-selector SelectionKey:OP_READ) ) ) ((receive) access: 'public (let* ( (num-selected ::int (channel-selector:select)) (keys ::Set (channel-selector:selectedKeys)) (iter ::java.util.Iterator (keys:iterator)) (channel #!null) (retval #f) ) (set! retval #f) (do () ((not (iter:hasNext)) retval) (let ((key ::SelectionKey (iter:next))) (iter:remove) (set! channel (key:channel)) (cond ((and (key:isAcceptable) (eqv? channel tcpchannel)) (set! retval ((tcpchannel:accept):socket))) ((and (key:isReadable) (eqv? channel udpchannel)) (set! retval (read-datagram udpchannel))) (#f (set! retval #!null)) ) ) ) ) ) ) (define (string->bytebuf str ::String) (ByteBuffer:wrap (str:getBytes))) ; instantiated with either a tcp socket or a (datagram channgel,address) pair for udp, and allows sending messages (define-simple-class sender-context () (tcpsock ::Socket #!null) (udpchan ::DatagramChannel #!null) (addr ::SocketAddress #!null) (username ::String #!null) (ctxtype #!null) ((*init* sock ::Socket un ::String) access: 'public (set! tcpsock sock) (tcpsock:setTcpNoDelay #t) (set! addr (sock:getRemoteSocketAddress)) (set! ctxtype 'tcp) (set! username un) ) ((*init* channel ::DatagramChannel address ::SocketAddress un ::String) access: 'public (set! udpchan channel) (set! addr address) (set! ctxtype 'udp) (set! username un) ) ((send msg ::String forged) access: 'public (dbprintf "ctxtype: %s\n" ctxtype) (case ctxtype ;('tcp (let ((osw ::OutputStreamWriter (OutputStreamWriter (tcpsock:getOutputStream)))) (osw:write msg 0 (msg:length)) (osw:flush))) ;('tcp (let ((ps ::PrintStream (PrintStream (tcpsock:getOutputStream)))) (ps:print msg) (ps:flush))) ('tcp (let ((sockchannel ::SocketChannel (tcpsock:getChannel))) (sockchannel:write (string->bytebuf msg)))) ;('udp (udpsock:send (DatagramPacket (msg:getBytes) (msg:getBytes):length addr))) ;doesn't quite work, for some reason ('udp (udpchan:connect addr) (udpchan:write (string->bytebuf msg)) (udpchan:disconnect) ) ) (verbose-printf "SENT%s to %s: %s\n" (if forged " (randomly!)" "") (if (equal? username #!null) addr (String:format "%s (%s)" username addr)) msg) ) ((toString) ::String access: 'public ;; to replace the following line from a printf ;;(if (Socket? addr/sock) (addr/sock:getRemoteSocketAddress) addr/sock) (if (not (equal? addr #!null)) addr "#<sender-context, uninitialized>") ) ) #|(define-simple-class chat-world () (address-map ::java.util.Map (java.util.Collections:synchronizedMap (HashMap))) ; String->sender-context (revaddr-map ::java.util.Map (java.util.Collections:synchronizedMap (HashMap))) ; sender-context->String ((*init* ports ::int[]) access: 'public ; move stuff from instantiate-server here? #f ) )|# (define (parse-int x ::String) (ignore-exceptions (Integer:valueOf x))) (define (fits-unsigned-short? x) (and (>= x 0) (<= x 65565) x)) (define (port-number? x ::String) (fits-unsigned-short? (parse-int x))) (define (instantiate-server port-number ::int) (verbose-printf "Instantiating a server listening on port %s\n" port-number) (let ((listener-socket (tcp-udp-socket port-number))) (future (loop-forever (let ((client-socket-or-dgram (listener-socket:receive))) (future (ignore-exceptions (handle-connection-or-dgram client-socket-or-dgram listener-socket:udpchannel))) ) )) ) ) (define (handle-connection-or-dgram socket-or-dgram dgchannel ::DatagramChannel) (cond ((Socket? socket-or-dgram) (make-client socket-or-dgram)) ((DatagramPacket? socket-or-dgram) (handle-dgram socket-or-dgram dgchannel)) (#t #f) ) ) (define (canonicalize-username username ::String) (username:toLowerCase)) ;(define (construct-message str addr) (make-message-struct str (sender-context addr #!null) #f)) (define (handle-login username ::String sctx ::sender-context) (if (not (*address-map*:containsKey username)) (begin (set! sctx:username (canonicalize-username username)) (*address-map*:put username sctx) (list (make-message-struct "OK\n" username #f)) ) (list (make-message-struct "ERROR username already taken\n" sctx #f)) ) ) (define (handle-logout username ::String) (*address-map*:remove (canonicalize-username username)) #f ) (define (jarray->list jarray ::Object[]) (do ((i 0 (+ 1 i)) (acc '() (cons (jarray i) acc))) ((= i jarray:length) (reverse acc))) ) (define (list->jarray lst) (let* ( (len (length lst)) (tmp (Object[] length: len)) ) (do ((i 0 (+ i 1)) (cur lst (cdr cur)) ) ((= i len) tmp) (set! (tmp i) (car cur)) ) ) ) (define (get-users-list) (map canonicalize-username (jarray->list ((*address-map*:keySet):toArray)))) (define (handle-users-listing username ::String) (list (make-message-struct (str-append (((get-users-list):toString):replaceAll "[()]" "") "\n") (canonicalize-username username) #f)) ) #|(define (slurp-all-lines reader ::BufferedReader) (let ((data ::StringBuilder (StringBuilder))) (do ((line (reader:readLine) (reader:getLine))) ((or (equal? line #!null) (equal? line "")) (dbprintf "Slurp ending\n") (data:toString)) (dbprintf "Line: %s\n" line) (data:append line) (data:append "\n") ) ) )|# (define (foldl fn lst acc) (if (null? lst) acc (foldl fn (cdr lst) (fn acc (car lst))) ) ) (define (list-of-strings->string lst) ((foldl (lambda (acc ::StringBuilder elem) (acc:append elem) acc) lst (StringBuilder)):toString)) (define (str-append s1 ::String s2 ::String) (s1:replaceFirst "$" s2)) (define (read-n-chars reader ::BufferedReader n ::Integer) (let ( (charbuf (char[] length: n)) ) (do ((i 0 (+ i 1))) ((>= i n) charbuf) (set! (charbuf i) (reader:read)) ) ) ) (define (slurp-relevant-lines reader::BufferedReader) (let/cc return (let ( (data '()) (num-chars 0) (chunked #f) (charbuf ::char[] #!null) ) (let ((tmp (reader:readLine))) (if (not (equal? tmp #!null)) (set! data (cons (str-append tmp "\n") data)) ; initial line (return data) ) ) (dbprintf "%s\n" data) (when (regex-case ((car data):toString) m ; get the length line for SEND/BROADCAST ("^SEND" (set! data (cons (str-append (reader:readLine) "\n") data)) #t) ("^BROADCAST" (set! data (cons (str-append (reader:readLine) "\n") data)) #t) (".*" #f) ) (dbprintf "%s\n" data) (when (regex-case (car data) m ; determine the number of bytes to read, dependent on chunking ("C([0-9]*)" (set! chunked #t) (set! num-chars (parse-int (m:group 1))) #t) ("([0-9]*)" (set! chunked #f) (set! num-chars (parse-int (m:group 1))) #t) (".*" #f) ) (dbprintf "num-chars: %s\n" num-chars) ;(set! charbuf (char[] length: num-chars)) ;(reader:read charbuf 0 charbuf:length) (set! charbuf (read-n-chars reader num-chars)) (set! data (cons (String charbuf) data)) (dbprintf "%s\n" data) ) ) (dbprintf "Returning %s from slurp-relevant-lines\n" data) (reverse data) ) ) ) (define-record-type message-struct (make-message-struct message receiver forged-tag) message-struct? (message message set-message!) (receiver receiver set-receiver!) (forged-tag forged-tag set-forged-tag!) ) (define (handle-forging sender receivers) (map (lambda (rec) (let ( (prev-sends (cons sender (null-default (*last-senders*:get rec) '()))) (msg #!null) ) (dbprintf "in (handle-forging %s %s) for rec %s, prev-sends is %s\n" sender receivers rec prev-sends) (when (= (length prev-sends) *forge-message-count*) (dbprintf "in the when-clauses\n") (let ((forged-sender (list-ref prev-sends (random *forge-message-count*)))) (set! msg (make-message-struct (encode-from-message forged-sender (generate-forged-message)) rec #t)) ) (set! prev-sends '()) ) (*last-senders*:put rec prev-sends) (dbprintf "handle-forging returning \"%s\"\n" msg) msg ) ) receivers) ) (define (encode-from-message sender msg ::String) (String:format "FROM %s\n%d\n%s" sender (msg:length) msg)) (define (load-file-lines-as-stringarray fname ::String) (let* ( (reader ::BufferedReader (BufferedReader (InputStreamReader (java.io.FileInputStream fname)))) (result '()) ) (do ((tmp (reader:readLine) (reader:readLine))) ((equal? tmp #!null) (list->jarray (reverse result))) (set! result (cons tmp result)) ) ) ) (define *forgable-messages* ::Object[] (load-file-lines-as-stringarray "forgable_messages.txt")) (define (generate-forged-message) (*forgable-messages* (random *forgable-messages*:length))) (define (handle-message-send sender receivers data broadcast) (let* ( (msg ::String (list-of-strings->string (cddr data))) (msgintsize ::int (msg:length)) (msgsize ::String (String:format "%d" msgintsize)) (msgclaimedsize ::int (aif (parse-int ((cadr data):trim)) it 0)) (retval '()) ) (when (not (= msgintsize msgclaimedsize)) (dbprintf "Mismatch in claimed size (%s) and actual size (%s) of message.\n" (cadr data) msgsize)) (when (not broadcast) (set! retval (append (handle-forging sender receivers) retval))) (set! retval (cons (make-message-struct (encode-from-message sender msg) receivers #f) retval)) (write retval) retval ) ) (define (parse-message instream ::InputStream sctx ::sender-context) (let* ( (reader ::BufferedReader (BufferedReader (InputStreamReader instream))) ;(first-line ::String (reader:readLine)) (data (ident-print (slurp-relevant-lines reader))) (datastr ::String (list-of-strings->string data)) ) (if (null? data) ((Thread:currentThread):join)) (verbose-printf "RCVD from %s: %s\n" sctx datastr) (let ((tmp (regex-case datastr match ("^ME IS ([^\\s]*)$" (match:group 1) (handle-login (match:group 1) sctx)) ("^LOGOUT ([^\\s]*)$" (handle-logout (match:group 1))) ("^SEND ([^\\s]*) ([^\n]*)$" (handle-message-send (match:group 1) (jarray->list ((match:group 2):split "\\s")) data #f)) ("^BROADCAST ([^\\s]*)$" (handle-message-send (match:group 1) (get-users-list) data #t)) ("^WHO HERE ([^\\s]*)$" (handle-users-listing (match:group 1))) (".*" (list (make-message-struct "ERROR Invalid header for message\n" sctx #f))) ) )) (dbprintf "retval for parse-message: %s" tmp) tmp) ) ) ;(define (send-enqueued-message queue ::BlockingQueue) (send-message (queue:take))) (define (send-message msg ::message-struct) (when (not (equal? msg #!null)) (let* ( (msg-str msg:message) (msg-to msg:receiver) (msg-forged msg:forged-tag) ) (dbprintf "sending msg (%s,%s,%s)\n" msg-str msg-to msg-forged) (send-message/parts msg-str msg-to msg-forged) ) ) ) (define (send-message/parts msg-str ::String msg-to msg-forged) (cond ((equal? msg-to #!null) #f) ((sender-context? msg-to) (msg-to:send msg-str msg-forged)) ((String? msg-to) (send-message/parts msg-str (*address-map*:get (canonicalize-username msg-to)) msg-forged)) ((list? msg-to) (map (lambda (dest) (dbprintf "dest: %s\n" dest) (send-message/parts msg-str dest msg-forged) ) msg-to)) (#t (dbprintf "The destination for the enqueued message (%s,%s,%s) is not a sender-context, username, or list of either.\n" msg-str msg-to msg-forged) #f) ) ) (define (make-client socket ::Socket) (verbose-printf "Recieved a TCP connection from %s\n" (socket:getRemoteSocketAddress)) (let ((instream ::BufferedInputStream (BufferedInputStream (socket:getInputStream)))) (loop-forever (aif (parse-message instream (sender-context socket #!null)) (map send-message it)) ) ) ) (define (ident-print x) (dbprintf "%s\n" x) x) (define (handle-dgram dgram ::DatagramPacket dgchannel ::DatagramChannel) (verbose-printf "Recieved a UDP datagram from %s\n" (dgram:getSocketAddress)) (dbprintf "%s\n" (String (dgram:getData))) (aif (parse-message (ByteArrayInputStream (dgram:getData)) (sender-context dgchannel (dgram:getSocketAddress) #!null)) (map send-message it)) ;(*message-queue*:put it)) ) ;(display command-line-arguments) (newline) (define (is-verbose-flag? arg) (or (equal? arg "-v") (equal? arg "--verbose"))) (define port-numbers-list '()) (vector-map (lambda (arg) (acond ((port-number? arg) (set! port-numbers-list (cons it port-numbers-list))) ((is-verbose-flag? arg) (set! *verbose-mode* #t)) (#t (printf "Unknown argument: \"%s\"\n" arg)) ) ) command-line-arguments ) (set! port-numbers-list (reverse! port-numbers-list)) ;(display port-numbers-list) (newline) (map (lambda (port-number) (instantiate-server port-number) ) port-numbers-list ) ;(loop-forever (ignore-exceptions (send-enqueued-message *message-queue*)))
false
dd305c2b7334b11a6e1fb981cec97e65fdde1dbe
5c90b20606ccbd30c23988c26a0b64a0243a8ad2
/tests/t-mlg-characters.scm
dc4bb949fecc3d4b50aeb1d32a7f4463a8332d98
[]
no_license
spk121/mlg-lib
a670ac95e4a3210f7de5fd4d702d4bf2d0ed6ad8
09239a0a126d47aaccf624b7983202f69152aa40
refs/heads/master
2021-06-01T18:26:37.192030
2020-01-08T19:47:34
2020-01-08T19:47:34
1,869,125
0
0
null
null
null
null
UTF-8
Scheme
false
false
347
scm
t-mlg-characters.scm
(use-modules (srfi srfi-64) (mlg characters)) (test-begin "t-mlg-characters") (test-equal (ascii-isdigit? #\a) #f) (test-equal (ascii-isdigit? #\0) #t) ;; U+0661 ARABIC-INDIC DIGIT ONE (test-equal (ascii-isdigit? #\x0661) #f) (test-equal (U+ #x0661) (integer->char #x0661)) (test-equal (U+ #x0020) #\space) (test-end "t-mlg-characters")
false
a07309206bceaaeb6add3830632c51d94d47d7a2
9cce21ddfc07978771a737bdc76c708aa59a11d8
/src/scheme/amb-final.scm.txt
4732392d8595110822db64790d15ffe379701a88
[]
no_license
yugeta/cympfh.github.io
5583ea87a3db7838a6515e9105cfc7bb805e3fce
e6fa4d0fea705b7f473807cb644a34eb44829a4e
refs/heads/master
2021-01-18T09:04:35.099559
2015-03-22T03:39:35
2015-03-22T03:39:35
null
0
0
null
null
null
null
UTF-8
Scheme
false
false
2,765
txt
amb-final.scm.txt
;; いつか役立つその日の為にambオペレータとその周り、ファイナル (define (fail) #f) (define-syntax amb (syntax-rules () ((_) (fail)) ((_ a) a) ((_ a b ...) (let1 fail0 fail (let/cc cc (set! fail (lambda () (set! fail fail0) (cc (amb b ...)))) (cc a)))) )) ;; utility ; pred or fail (define (assert pred) (or pred (amb))) ; see the example below (define-macro (assert-vars vars . bodys) `(if (or ,@(map (cut list 'not <>) vars)) #f (begin ,@bodys))) ; infinity amb (define (int-from n) (amb n (int-from (+ n 1)))) (define (int-down n) (amb n (int-from (- n 1)))) ; iota-list->amb (define (amb-iota n :optional (b 0) (s 1)) (if (zero? n) (amb) (amb b (amb-iota (- n 1) (+ b s) s)))) ; (amb a b c) => (list a b c) (define-macro (amb->list a) `(let1 ls '() (let ((x ,a)) (when x (push! ls x)) (fail)) (reverse ls))) ; (list a b c) => (amb a b c) (define (list->amb ls) (if (null? ls) #f (amb (car ls) (list->amb (cdr ls))))) ; (sublist '(a b c)) => (amb '(a b c) '(a b) '(a c) '(b c) ...) (define (sublist ls) (if (null? ls) '() (amb (cons (car ls) (sublist (cdr ls))) (sublist (cdr ls))))) ;; examples ; [3..7] [10..13] から倍数関係を見つける ; (assert a) などとしても 最後になると通って ; (a #f) (b #f) の状態で (modulo b a) を計算しようとしてエラーを出す ; (assert-vars (a b) bodys ...) は以下のように使う (define (solve) (let ((a (amb-iota 5 3)) (b (amb-iota 4 10))) (assert-vars (a b) (assert (zero? (modulo b a))) (cons a b)))) ; gosh> (amb->list (solve)) ; ((3 . 12) (4 . 12) (5 . 10) (6 . 12)) ; [1,4,3,6,5,3,2,1] からいくつか数字を取ってきて総和が偶数であるような ; ものを非決定的に取り出す. その最大値を計算する ; なんでこちらは assert-vars が必要ないか.なんでだろう? ; amb->list の使い方を示す例である (define (solve2) (define array '(1 4 3 6 5 3 2 1)) (define (dfs) (let* ((ls (sublist array)) (sum (apply + ls))) (assert (even? sum)) sum)) (apply max (amb->list (dfs)))) ; ただDFSで書くと次のように多少長くなる.ambはこれを少しでも短く ; 慣れればきっとそちらのほうが直観的になるだろうというライブラリである ;; ordinary DFS for solve2 (define (solve2.) (define array '(1 4 3 6 5 3 2 1)) (define ans 0) (define (dfs sum idx) (if (= idx (length array)) (when (even? sum) (set! ans (max ans sum))) (begin (dfs sum (+ idx 1)) (dfs (+ sum (list-ref array idx)) (+ idx 1)) ))) (dfs 0 0) ans) ; vim:set ft=scheme:
true
3dce84c56fb1eccd130139c4d6d2728d9cfc2a9d
b8eb3fdd0e4e38a696c4013a8f91054df3f75833
/lib/cidr.ss
6b769aaef0750791719ad9a416471f1366678784
[ "Zlib" ]
permissive
lojikil/digamma
952a7bdf176227bf82b3583020bc41764b12d906
61c7ffdc501f207a84e5d47157c3c84e5882fa0d
refs/heads/master
2020-05-30T07:11:20.716792
2016-05-11T11:32:15
2016-05-11T11:32:15
58,539,277
6
3
null
null
null
null
UTF-8
Scheme
false
false
1,882
ss
cidr.ss
(define (ip->hex ip) (with res (map (fn (x) (coerce x 'int)) (string-split-charset ip ".")) (+ (<< (& (nth res 0) 255) 24) (<< (& (nth res 1) 255) 16) (<< (& (nth res 2) 255) 8) (& (nth res 3) 255)))) (define (hex->ip hexip) (format "~n.~n.~n.~n" (>> (& hexip #xFF000000) 24) (>> (& hexip #x00FF0000) 16) (>> (& hexip #x0000FF00) 8) (& hexip #x000000FF))) (define (bitvec->hint x (idx 0)) (if (>= idx (length x)) 0 (+ (<< (if (nth x idx) 1 0) (- 31 idx)) (bitvec->hint x (+ idx 1))))) (define (gen-netmask l) (bitvec->hint (make-vector l #t))) (define (useable-ips cidr-len) (- (exp2 (- 32 cidr-len)) 2)) (define (cidr->ip-list baseip mask) (define (foobar b o l) (if (< o l) (cons (hex->ip (+ b o)) (foobar b (+ o 1) l)) '())) (foobar (+ (ip->hex baseip) 1) 0 (useable-ips mask))) (define (range-stream start end) (with state start (lambda () (if (< state end) (begin (set! state (+ state 1)) (- state 1)) (error "stream end"))))) ;; causes a crash; look into this (define (map-stream p r) (let ((v '())) (with-exception-handler (fn (c) v) (letrec ((inner-map-stream (lambda () (set! v (append v (list (p (r))))) (inner-map-stream)))) inner-map-stream)))) (define (better-cidr->ip-list baseip mask) (with b (ip->hex baseip) (map-stream (fn (x) (hex->ip (+ b x))) (range-stream 0 (+ (useable-ips mask) 1))))) (define (cidr->ip-stream baseip mask) (with b (ip->hex baseip) (map-stream (fn (x) (hex->ip (+ b x))) (range-stream 0 (+ (useable-ips mask) 1)))))
false
8c10056d16516ba32da8181708cea8a2def9b177
defeada37d39bca09ef76f66f38683754c0a6aa0
/mscorlib/system/security/access-control/access-rule.sls
c37b286036db8532181674943572cca2b4af241a
[]
no_license
futsuki/ironscheme-port
2dbac82c0bda4f4ff509208f7f00a5211d1f7cd5
4e7a81b0fbeac9a47440464988e53fb118286c54
refs/heads/master
2016-09-06T17:13:11.462593
2015-09-26T18:20:40
2015-09-26T18:20:40
42,757,369
0
0
null
null
null
null
UTF-8
Scheme
false
false
486
sls
access-rule.sls
(library (system security access-control access-rule) (export is? access-rule? access-control-type) (import (ironscheme-clr-port)) (define (is? a) (clr-is System.Security.AccessControl.AccessRule a)) (define (access-rule? a) (clr-is System.Security.AccessControl.AccessRule a)) (define-field-port access-control-type #f #f (property:) System.Security.AccessControl.AccessRule AccessControlType System.Security.AccessControl.AccessControlType))
false
e2d8cff2386ea81bf37c45f494420c7fa451c6c4
3508dcd12d0d69fec4d30c50334f8deb24f376eb
/v8/src/compiler/midend/typerew.scm
a4385e9a3c7f2015fbb1196d42647d5504a1b963
[]
no_license
barak/mit-scheme
be625081e92c2c74590f6b5502f5ae6bc95aa492
56e1a12439628e4424b8c3ce2a3118449db509ab
refs/heads/master
2023-01-24T11:03:23.447076
2022-09-11T06:10:46
2022-09-11T06:10:46
12,487,054
12
1
null
null
null
null
UTF-8
Scheme
false
false
86,392
scm
typerew.scm
#| -*-Scheme-*- Copyright (c) 1994-1999 Massachusetts Institute of Technology This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |# ;;;; Type analysis and rewriting ;;; package: (compiler midend) (declare (usual-integrations)) (define *typerew-type-map*) ; form->type (define *typerew-dbg-map*) (define (typerew/top-level program) (let ((program* (copier/top-level program code-rewrite/remember))) ;;(kmp/ppp program*) (fluid-let ((*typerew-type-map* (make-form-map)) (*typerew-dbg-map* (make-form-map))) (typerew/expr program* q-env:top (lambda (q t e) q t e ;;(bkpt "PROGRAM* has been analysed") (typerew/rewrite! program*) program*))))) (define-macro (define-type-rewriter keyword bindings . body) (let ((proc-name (symbol-append 'TYPEREW/ keyword))) (call-with-values (lambda () (%matchup bindings '(handler) '(cdr form))) (lambda (names code) `(DEFINE ,proc-name (NAMED-LAMBDA (,proc-name FORM ENV RECEIVER) ;; FORM, ENV and RECEIVER are in scope in handler FORM (LET ((HANDLER (LAMBDA ,names ,@body))) ,code))))))) (define (typerew/associate-type form type) (form-map/put! *typerew-type-map* form type)) (define (typerew/type form) (or (form-map/get *typerew-type-map* form #F) (internal-error "No type associated with form" form))) (define (typerew/type/no-error form) (form-map/get *typerew-type-map* form #F)) ;; This is incorrect in the following conservative way: QUANTITY may ;; already be bound in ENV to a type that would restrict TYPE. ;;(define-integrable (typerew/send receiver quantity type env) ;; (receiver quantity type (q-env:glb/1 env quantity type))) ;; Do we really have to do an O(n) lookup? (define (typerew/send receiver quantity type env) (let ((env* (q-env:glb/1 env quantity type))) (receiver quantity (q-env:lookup env* quantity) env*))) (define-type-rewriter LOOKUP (name) (let ((quantity (quantity:variable name))) (receiver quantity (q-env:lookup env quantity) env))) (define-type-rewriter LAMBDA (lambda-list body) ;; . Simple analysis: we assume that this procedure escapes and is called ;; after someone has played with every mutable structure in the universe. ;; . The names in the lambda-list are unknown so we dont have ;; to add them to the quantity environment. ;; . It is a shame to waste the returned information: it tells us the ;; return type and constraints imposed on the arguments, and even if the ;; procedure returns at all. (call-with-values (lambda () (lambda-list/parse lambda-list)) (lambda (required optional rest aux) required optional aux ; ignored rest (typerew/expr body (let ((env-at-call-time (q-env:restrict env effect:unknown))) (if rest (q-env:glb/1 env-at-call-time (quantity:variable rest) type:list) env-at-call-time)) (lambda (quantity type env*) quantity type env* ; a shame ;; Creating the procedure or closure itself is no big deal since ;; we dont have reasonable type information for procedures: (typerew/send receiver (quantity:other-expression form effect:none) type:compiled-entry env)))))) (define-type-rewriter CALL (rator cont #!rest rands) cont ; ignored - pre-CPS (define (default) (typerew/expr*/unordered (cdr form) env (lambda (quantities types envs env*) quantities types envs ; we could use these for something ;; Assume that the procedure wrecks everything (receiver (quantity:other-expression form effect:unknown) type:any ; uninteresting => no SEND (q-env:restrict env* effect:unknown))))) (define (apply-method method rands*) (typerew/expr*/unordered rands* env (lambda (quantities types envs env*) envs ; ignored (method quantities types env* form receiver)))) (cond ((LAMBDA/? rator) (let ((formals (lambda/formals rator))) (if (or (hairy-lambda-list? formals) (not (= (length (cdr formals)) (length rands)))) (default) (typerew/bind (cdr formals) rands env receiver (lambda/body rator))))) ((not (QUOTE/? rator)) (default)) ((typerew/type-method? (quote/text rator) (length rands)) => (lambda (method) (apply-method method rands))) ((and (eq? (quote/text rator) %invoke-remote-cache) (typerew/type-method? (first (quote/text (first rands))) (second (quote/text (first rands))))) => (lambda (method) (apply-method method (cddr rands)))) (else (default)))) (define-type-rewriter LET (bindings body) (typerew/bind (map first bindings) (map second bindings) env receiver body)) (define (typerew/bind names exprs env receiver body) (cond ((null? names) (typerew/expr body env receiver)) ((null? (cdr exprs)) (typerew/expr (first exprs) env (lambda (quantity type env*) quantity ; ignored (typerew/expr body (q-env:glb/1 env* (quantity:variable (car names)) type) receiver)))) (else ; lots of arguments in some order (typerew/expr*/unordered exprs env (lambda (quantities types envs env*) envs ; ignored (typerew/expr body (q-env:bind* env* names quantities types) receiver)))))) #| This version is WASTEFUL since letrec bindings are always procedures and we dont do much with that. (define-type-rewriter LETREC (bindings body) ;; This is lame. We need more complex procedure types to summarize what ;; we found out about the procedures, and an intelligent traversal ;; order to maximize the info (or some kind of iterative solution). (let ((env* (q-env:glb env (map (lambda (binding) (cons (quantity:variable (first binding)) type:compiled-entry)) bindings)))) (let loop ((bindings bindings) (env** env*)) (if (null? bindings) (typerew/expr body env** receiver) (typerew/expr (second (car bindings)) env** (lambda (quantity type env***) (loop (cdr bindings) (q-env:glb/1 env*** quantity type))))))) |# (define-type-rewriter LETREC (bindings body) ;; This is lame. We need more complex procedure types to summarize what ;; we found out about the procedures, and an intelligent traversal ;; order to maximize the info (or some kind of iterative solution). (let ((env* env)) (let loop ((bindings bindings) (env** env*)) (if (null? bindings) (typerew/expr body env** receiver) (typerew/expr (second (car bindings)) env** (lambda (quantity type env***) (loop (cdr bindings) (q-env:glb/1 env*** quantity type)))))))) (define-type-rewriter QUOTE (object) (receiver (quantity:constant form) (type:of-object object) env)) (define-type-rewriter DECLARE (#!rest anything) anything ; ignored (receiver (quantity:other-expression form effect:none) type:any env)) (define-type-rewriter BEGIN (#!rest actions) (if (null? actions) (receiver (quantity:other-expression form effect:none) type:any env) (let loop ((actions actions) (env env)) (if (null? (cdr actions)) (typerew/expr (car actions) env receiver) (typerew/expr (car actions) env (lambda (quantity type env*) quantity type ; ignored (loop (cdr actions) env*))))))) (define-type-rewriter IF (pred conseq alt) (typerew/pred pred env (lambda (env_t env_f) ;;(pp `(env_t: ,env_t env_f: ,env_f)) (typerew/expr conseq env_t (lambda (quantity_t type_t env_t*) (typerew/expr alt env_f (lambda (quantity_f type_f env_f*) ;;(pp `(type_t: ,type_t type_f: ,type_f)) ;;(pp `(env_t*: ,env_t* env_f*: ,env_f*)) (typerew/send receiver (quantity:combination/2/assoc 'IF-MERGE quantity_t quantity_f) (type:or (if (q-env:bottom? env_t*) type:empty type_t) (if (q-env:bottom? env_f*) type:empty type_f)) (q-env:lub env_t* env_f*))))))))) (define (typerew/expr*/left-to-right exprs env receiver) ;; receiver = (lambda (quantities types env) ...) (typerew/expr*/%ordered exprs env (lambda (Qs Ts env*) (receiver (reverse! Qs) (reverse! Ts) env*)))) (define (typerew/expr*/right-to-left exprs env receiver) ;; receiver = (lambda (quantities types env) ...) (typerew/expr*/%ordered (reverse exprs) env receiver)) (define (typerew/expr*/%ordered exprs env receiver) ;; receiver = (lambda (quantities types env) ...) ;; Note: Yields quantities and types in reversed order (let loop ((Qs '()) (Ts '()) (env env) (exprs exprs)) (if (not (pair? exprs)) (receiver Qs Ts env) (typerew/expr (car exprs) env (lambda (Q T env*) (loop (cons Q Qs) (cons T Ts) env* (cdr exprs))))))) (define (typerew/expr*/unordered/old-version exprs env receiver) ;; receiver = (lambda (quantities types envs env) ...) ;; . ENVS are returned because they can give hints on how subexpressions ;; should be ordered. ;; . Try every permutation! you must be joking. ;; . An approximation is to evaluate each expression in an environment ;; containing all the deleterious and none of the beneficial effects of ;; the other expressions. This is the worst that the other ;; expressions could do if they were ordered before this ;; expression. The output environment must then have all the ;; deleterious effects of the other expressions applied (thus ;; modelling their evaluation after the current expression). The ;; result is then the GLB of the expression results. ;; . An approximation to the approximation is punt if any expression has ;; side-effects. (let* ((all-effects (if (for-all? exprs form/simple&side-effect-free?) ;exponential! effect:none effect:unknown)) (split-env (q-env:restrict env all-effects))) (define (glb* envs) ;; (reduce q-env:glb q-env:top envs) ;; Hopefully most envs are the same as passed in (lookups & quotes) (call-with-values (lambda () (list-split envs (lambda (env) (eq? env split-env)))) (lambda (splits others) (if (and (null? splits) (pair? others)) (fold-left q-env:glb (car others) (cdr others)) (fold-left q-env:glb split-env others))))) (let loop ((Qs '()) (Ts '()) (Es '()) (exprs exprs)) (if (not (pair? exprs)) (receiver (reverse! Qs) (reverse! Ts) (reverse! Es) (glb* Es)) (typerew/expr (car exprs) split-env (lambda (Q T env*) (loop (cons Q Qs) (cons T Ts) (cons (q-env:restrict env* all-effects) Es) (cdr exprs)))))))) (define (typerew/expr*/unordered exprs env receiver) ;; receiver = (lambda (quantities types envs env) ...) ;; . ENVS are returned because they can give hints on how subexpressions ;; should be ordered. ;; . Try every permutation! you must be joking. ;; . An approximation is to evaluate each expression in an environment ;; containing all the deleterious and none of the beneficial effects of ;; the other expressions. This is the worst that the other ;; expressions could do if they were ordered before this ;; expression. The output environment must then have all the ;; deleterious effects of the other expressions applied (thus ;; modelling their evaluation after the current expression). The ;; result is then the GLB of the expression results. ;; . An approximation to the approximation is punt if any expression has ;; side-effects. ;; . An optimization: LOOKUPs and QUOTES cant do any damage, so (1) we ;; collect them together and process them at the end and (2) if ;; there is only one hard expression then that can be done ;; directly. (define (do-easy easy Qs Ts Es env*) ;; now EASY, and Qs, Ts and Es are reversed wrt EXPRS. (let loop ((easy easy) (Qs Qs) (Ts Ts) (Es Es) (Qs* '()) (Ts* '()) (Es* '()) (env* env*)) (define (take-hard easy) (loop easy (cdr Qs) (cdr Ts) (cdr Es) (cons (car Qs) Qs*) (cons (car Ts) Ts*) (cons (car Es) Es*) env*)) (cond ((null? easy) (if (null? Qs) (receiver Qs* Ts* Es* env*) (take-hard easy))) ((car easy) (typerew/expr (car easy) env* (lambda (Q T env**) (loop (cdr easy) Qs Ts Es (cons Q Qs*) (cons T Ts*) (cons env** Es*) (q-env:glb/1 env** Q T))))) (else (take-hard (cdr easy)))))) (let loop ((exprs exprs) (easy '()) (hard '())) ;; HARD and EASY are reversed wrt EXPRS. EASY ends up the same length as ;; EXPRS, with a #f to mark the slots that are occupied by the ;; hard expression - so we can reassemble them later. (if (pair? exprs) (if (or (LOOKUP/? (car exprs)) (QUOTE/? (car exprs))) (loop (cdr exprs) (cons (car exprs) easy) hard) (loop (cdr exprs) (cons #F easy) (cons (car exprs) hard))) (cond ((null? hard) (do-easy easy '() '() '() env)) ((null? (cdr hard)) (typerew/expr (car hard) env (lambda (Q T env*) (do-easy easy (list Q) (list T) (list env*) env*)))) (else (typerew/expr*/unordered/hard hard env (lambda (Qs Ts Es env*) (do-easy easy Qs Ts Es env*)))))))) (define (typerew/expr*/unordered/hard exprs env receiver) (let* ((all-effects (if (for-all? exprs form/simple&side-effect-free?) ;exponential! effect:none effect:unknown)) (split-env (q-env:restrict env all-effects))) (define (glb* envs) (reduce q-env:glb q-env:top envs)) (let loop ((Qs '()) (Ts '()) (Es '()) (exprs exprs)) (if (not (pair? exprs)) (let ((env* (glb* Es))) ; do before reverse: (receiver (reverse! Qs) (reverse! Ts) (reverse! Es) env*)) (typerew/expr (car exprs) split-env (lambda (Q T env*) (loop (cons Q Qs) (cons T Ts) (cons (q-env:restrict env* all-effects) Es) (cdr exprs)))))))) (define (typerew/pred form env receiver) ;; receiver = (lambda (env_t env_f) ...) (define (->expr) (typerew/expr form env (lambda (quantity type env*) (receiver (q-env:glb/1 env* quantity (type:and type type:not-false)) (q-env:glb/1 env* quantity (type:and type type:false)))))) (cond ((and (CALL/? form) (QUOTE/? (call/operator form)) (operator-predicate-test-type (quote/text (call/operator form)))) => (lambda (test-types) (typerew/expr form env (lambda (quantity type env*) type ;;(pp `((predicate-q ,quantity) (pred-type ,type) (env* ,env*))) (let ((arg-quantity (quantity:operand1 quantity)) (env*_t (q-env:glb/1 env* quantity type:not-false)) (env*_f (q-env:glb/1 env* quantity type:false))) ;;(pp `((arg-quantity ,arg-quantity)(env*_t: ,env*_t) (env*_f: ,env*_f))) (let ((glb-t (q-env:glb/1 env*_t arg-quantity (car test-types))) (glb-f (q-env:glb/1 env*_f arg-quantity (cdr test-types)))) ;;(pp `((glb-t: ,glb-t) (glb-f: ,glb-f))) (receiver glb-t glb-f))))))) ((and (CALL/? form) (QUOTE/? (call/operator form)) (eq? OBJECT-TYPE? (quote/text (call/operator form))) (form/number? (call/operand1 form))) => (lambda (tag) (typerew/expr form env (lambda (quantity type env*) type (let ((arg-quantity (quantity:operand2 quantity)) (env*_t (q-env:glb/1 env* quantity type:not-false)) (env*_f (q-env:glb/1 env* quantity type:false)) (test-types (and (exact-integer? tag) (type:tag->test-types tag)))) ;;(pp `(env*_t: ,env*_t env*_f: ,env*_f)) ;;(pp `(test-types ,test-types)) (receiver (q-env:glb/1 env*_t arg-quantity (car test-types)) (q-env:glb/1 env*_f arg-quantity (cdr test-types)))))))) ((IF/? form) (typerew/pred (if/predicate form) env (lambda (env_t env_f) (typerew/pred (if/consequent form) env_t (lambda (env_tt env_tf) (typerew/pred (if/alternate form) env_f (lambda (env_ft env_ff) (receiver (q-env:lub env_tt env_ft) (q-env:lub env_ff env_tf))))))))) (else (->expr)))) (define (typerew/expr form env receiver) ;; receiver = (lambda (quantity type env*) ...) (if (not (pair? form)) (illegal form)) (define (receiver* quantity type env*) (typerew/associate-type form type) (form-map/put! *typerew-dbg-map* form (list quantity type env*)) (receiver quantity type env*)) (case (car form) ((QUOTE) (typerew/quote form env receiver*)) ((LOOKUP) (typerew/lookup form env receiver*)) ((LAMBDA) (typerew/lambda form env receiver*)) ((LET) (typerew/let form env receiver*)) ((DECLARE) (typerew/declare form env receiver*)) ((CALL) (typerew/call form env receiver*)) ((BEGIN) (typerew/begin form env receiver*)) ((IF) (typerew/if form env receiver*)) ((LETREC) (typerew/letrec form env receiver*)) (else (illegal form)))) (define (typerew/remember new old) (code-rewrite/remember new old)) (define (typerew/remember* new-form old) (let ((info (code-rewrite/original-form old))) (if info (code-rewrite/remember* new-form info) new-form))) (define (typerew/new-name prefix) (new-variable prefix)) (define (typerew/type-checks? class) (and compiler:generate-type-checks? (if (pair? compiler:generate-type-checks?) (memq class compiler:generate-type-checks?) #T))) (define (typerew/range-checks? class) (and compiler:generate-range-checks? (if (pair? compiler:generate-range-checks?) (memq class compiler:generate-range-checks?) #T))) ;; Quantities ;; ;; Quantities are naming scheme for expressions in the program. We do ;; not use the expressions themselves because we want to tell when two ;; different expressions are really the same thing. ;; ;; Note: currently `different' expressions have to be syntactically the ;; same to be the same quantity, i.e. we do not track what variables ;; are bound to. ;; ;; Quantities are represented as vectors: ;; #(<hash> <effects> <variable>) ;; #(<hash> <effects> <quoted-form>) ;; #(<hash> <effects> <operator> . <operand-quantities>) ;; <effects> is the effects to which this quantity is sensitive. (define-integrable (quantity:hash Q) (vector-ref Q 0)) (define-integrable (quantity:effects Q) (vector-ref Q 1)) (define-integrable (quantity:operator Q) (vector-ref Q 2)) (define-integrable (quantity:operand1 Q) (vector-ref Q 3)) (define-integrable (quantity:operand2 Q) (vector-ref Q 4)) (define (quantity:constant quoted-form) (vector (quantity:hash-constant (quote/text quoted-form)) effect:none quoted-form)) (define (quantity:variable name) (vector (quantity:hash-symbol name) effect:none name)) (define (quantity:combination/1 operator operand) (vector (quantity:hash+ (quantity:hash-operator operator) (quantity:hash operand)) (effect:union (operator-sensitive-effects operator) (quantity:effects operand)) operator operand)) (define (quantity:combination/2 operator operand1 operand2) (vector (quantity:hash+ (quantity:hash-operator operator) (quantity:hash+ (quantity:hash operand1) (quantity:hash operand2))) (effect:union (operator-sensitive-effects operator) (effect:union (quantity:effects operand1) (quantity:effects operand2))) operator operand1 operand2)) (define (quantity:combination/2/assoc operator operand1 operand2) (if (fix:<= (quantity:hash operand1) (quantity:hash operand2)) (quantity:combination/2 operator operand1 operand2) (quantity:combination/2 operator operand2 operand1))) (define (quantity:combination operator operands) (define (default) (list->vector (cons* (fold-left (lambda (hash q) (quantity:hash+ hash (quantity:hash q))) (quantity:hash-operator operator) operands) (fold-left (lambda (eff q) (effect:union eff (quantity:effects q))) (operator-sensitive-effects operator) operands) operator operands))) (cond ((not (pair? operands)) (default)) ((not (pair? (cdr operands))) (quantity:combination/1 operator (first operands))) ((not (pair? (cddr operands))) (quantity:combination/2 operator (first operands) (second operands))) (else (default)))) (define (quantity:other-expression source effects) (vector 0 effects source)) (define (quantity:same? q1 q2) (let same? ((q1 q1) (q2 q2)) (or (eq? q1 q2) (and (vector? q1) (vector? q2) (fix:= (quantity:hash q1) (quantity:hash q2)) (= (vector-length q1) (vector-length q2)) (let loop ((i (- (vector-length q1) 1))) (or (fix:< i 2) (and (same? (vector-ref q1 i) (vector-ref q2 i)) (loop (fix:- i 1))))))))) (define (quantity:hash-symbol sym) (let* ((s (symbol-name sym)) (c1 (vector-8b-ref s 0)) (c2 (vector-8b-ref s (- (string-length s) 1)))) (+ c1 (* 17 c2)))) (define (quantity:hash-constant value) (cond ((= 0 (object-gc-type value)) (fix:and #xFFF (object-datum value))) ((flo:flonum? value) 1) (else (object-type value)))) (define-integrable (quantity:hash+ q1 q2) (let ((q1* (fix:* q1 7)) (q2* (fix:* q2 13))) (fix:and #xFFFF (fix:+ (fix:+ q1* (fix:lsh -13 q1)) (fix:+ q2* (fix:lsh -12 q2)))))) (define quantity:hash-operator (let ((table (make-monotonic-strong-eq-hash-table)) (last 0)) (lambda (operator) (or (monotonic-strong-eq-hash-table/get table operator #F) (let ((value (quantity:hash+ last 10000))) (monotonic-strong-eq-hash-table/put! table operator value) value))))) ;; Quantity environments map quantities to types ;; ;; Quantity type lattice ;; ;; . bottom: everything is known to be of type:empty (this means that ;; i.e. the program never gets here) ;; . (): Top. nothing is known, i.e. every quantity may be of any type ;; . alist(quantity*type): listed quantities of of knwon type, others (define (q-env:lookup env quantity) ; -> a type (cond ((q-env:bottom? env) type:empty) ((%q-env:lookup env quantity (quantity:hash quantity)) => cdr) (else type:any))) (define (%q-env:lookup env Q H) ; -> #F or the association (let loop ((env env)) (cond ((not (pair? env)) #F) ((fix:> (quantity:hash (caar env)) H) #F) ((quantity:same? Q (caar env)) (car env)) (else (loop (cdr env)))))) (define (%q-env:delete env Q H) (let loop ((env env)) (cond ((not (pair? env)) '()) ((fix:> (quantity:hash (caar env)) H) env) ((quantity:same? Q (caar env)) (cdr env)) (else (cons (car env) (loop (cdr env))))))) (define (q-env:restrict env effects) ;; Remove quantities depending on EFFECTS. ;; Computes the LUB of ENV and the environment containing all possible ;; quantities dependent on EFFECTS mapped to type:any and all other ;; possible quantities mapped to type:none. (cond ((q-env:bottom? env) env) ;; justified only because it implies dead code ((effect:none? effects) env) (else (list-transform-positive env (lambda (quantity.type) (effect:disjoint? (quantity:effects (car quantity.type)) effects)))))) (define q-env:top '()) (define q-env:bottom 'bottom) (define (q-env:bottom? env) (eq? q-env:bottom env)) (define (q-env:top? env) (null? env)) (define (q-env:lub env1 env2) (define (merge env1 env2) (define (skip1) (merge (cdr env1) env2)) (if (and (pair? env1) (pair? env2)) (let ((q1 (caar env1)) (q2 (caar env2))) (let ((h1 (quantity:hash q1)) (h2 (quantity:hash q2))) (cond ((fix:< h2 h1) (merge env1 (cdr env2))) ((fix:< h1 h2) (skip1)) ((%q-env:lookup env2 q1 h1) => (lambda (q2.type2) (let ((type* (type:or (cdar env1) (cdr q2.type2)))) (if (type:subset? type:any type*) ; useless (skip1) (cons (cons q1 type*) (skip1)))))) (else (skip1))))) '())) (cond ((q-env:bottom? env1) env2) ((q-env:bottom? env2) env1) (else (merge env1 env2)))) (define (q-env:glb/1 env quantity type) (let ((op (quantity:operator quantity))) (if (quote/? op) (if (type:disjoint? (type:of-object (quote/text op)) type) q-env:bottom;; we have just concluded a constant an absurd value env) (if (type:subset? type type:empty) q-env:bottom (q-env:glb env (list (cons quantity type))))))) (define (q-env:glb* env quantities types asserted-types) (let loop ((env2 q-env:top) (Qs quantities) (Ts types) (As asserted-types)) (if (null? Qs) (q-env:glb env env2) (loop (q-env:glb/1 env2 (car Qs) (type:and (car Ts) (car As))) (cdr Qs) (cdr Ts) (cdr As))))) (define (q-env:glb env1 env2) (define (merge env1 env2 accepted) (define (accept1) (merge (cdr env1) env2 (cons (car env1) accepted))) (define (accept2) (merge env1 (cdr env2) (cons (car env2) accepted))) (cond ((null? env1) (append! (reverse! accepted) env2)) ((null? env2) (append! (reverse! accepted) env1)) (else ;(and (pair? env1) (pair? env2)) (let ((q1 (caar env1)) (q2 (caar env2))) (let ((h1 (quantity:hash q1)) (h2 (quantity:hash q2))) (cond ((fix:< h1 h2) (accept1)) ((fix:< h2 h1) (accept2)) ((%q-env:lookup env2 q1 h1) => (lambda (q2.type2) (let ((type* (type:and (cdar env1) (cdr q2.type2)))) (if (type:subset? type* type:empty) q-env:bottom (merge (cdr env1) (%q-env:delete env2 q1 h1) (cons (cons q1 type*) accepted)))))) (else (accept1)))))))) (cond ((q-env:bottom? env1) env1) ((q-env:bottom? env2) env2) (else (merge env1 env2 '())))) (define (q-env:bind* env names quantities types) ;; introduce new names into the environment (if (q-env:bottom? env) env (q-env:glb env (map (lambda (name quantity type) quantity ; we dont know how to chain names yet (cons (quantity:variable name) type)) names quantities types)))) ;;;; TYPE METHODS ;; ;; Operators have type methods. Type methods are procedures of the form ;; (lambda (quantities types env form receiver) ...) ;; They invoke the reciever on ;; a) a new quantity for the combination ;; b) the return type of the combination ;; c) an updated environment reflecting inferences that can be made from the ;; execution of the combination's operator. ;; TYPEREW/GENERAL-TYPE-METHOD is a generator of type methods from an ;; enforced signature and a set of effects. (define *typerew/type-methods* (make-monotonic-strong-eq-hash-table)) (define *typerew/rewrite-methods* (make-monotonic-strong-eq-hash-table)) (define (typerew/type-method? op arity) (let ((arity.method (monotonic-strong-eq-hash-table/get *typerew/type-methods* op #F))) (and arity.method (if (car arity.method) ; specific arity only (and (= (car arity.method) arity) (cdr arity.method)) (cdr arity.method))))) ; #F => any arity (define (define-typerew-type-method op arity method) ;; ARITY = #F means method for any arity (monotonic-strong-eq-hash-table/put! *typerew/type-methods* op (cons arity method))) (define (typerew/general-type-method rator asserted-argument-types result-type effects-performed) (let ((adjusted-asserted-argument-types ; handles #!rest args (if (list? asserted-argument-types) (lambda (Ts) Ts asserted-argument-types) (lambda (Ts) ;; Note: we do not detect any arity errors for procedures with ;; #!rest and !#optional arguments, but it is harmless in the ;; sense that we infer what would happen if the program did not ;; terminate with an error. (let loop ((As asserted-argument-types) (Ts Ts) (As* '())) (cond ((null? Ts) (reverse! As*)) ((pair? As) (loop (cdr As) (cdr Ts) (cons (car As) As*))) (else (loop As (cdr Ts) (cons As As*))))))))) (lambda (quantities types env form receiver) form ; No operator replacement (let ((env* (q-env:restrict (q-env:glb* env quantities types (adjusted-asserted-argument-types types)) effects-performed))) (typerew/send receiver (quantity:combination rator quantities) result-type env*))))) (let ((OBJECT-TYPE? (make-primitive-procedure 'OBJECT-TYPE?))) (define-typerew-type-method OBJECT-TYPE? 2 (typerew/general-type-method OBJECT-TYPE? (list type:unsigned-byte type:any) type:boolean effect:none))) ;; Example: SUBSTRING? ;; SUBSTRING? checks that the two arguments are strings and signals an ;; error if they are not. If it returns, the result is either #T or ;; #F, (THIS IS INACCURATE) and it makes no effects (e.g. it doesnt ;; change the strings). ;;(define-typerew-type-method 'SUBSTRING? 2 ;; (typerew/general-type-method 'SUBSTRING? ;; (list type:string type:string) ;; type:boolean ;; effect:none)) ;; (define (typerew/rewrite! program) (define (rewrite-bindings! bindings) (for-each (lambda (binding) (rewrite! (second binding))) bindings)) (define (rewrite!* forms) (for-each rewrite! forms)) (define (rewrite-call! form rator cont rands) (define (install-replacement! replacement-generator) (sample/1 '(typerew/replaced-operators histogram) (let ((op (quote/text (call/operator form)))) (if (eq? op %invoke-remote-cache) (first (quote/text (call/operand1 form))) op))) (form/rewrite! form (replacement-generator form))) (define (apply-method method rands*) (install-replacement! (cond ((null? rands*) (method form)) ((null? (cdr rands*)) (method form (car rands*))) ((null? (cddr rands*)) (method form (car rands*) (cadr rands*))) ((null? (cdddr rands*)) (method form (car rands*) (cadr rands*) (caddr rands*))) (else (apply method form rands*))))) (rewrite!* rands) (rewrite! cont) (if (QUOTE/? rator) (let ((rator* (quote/text rator))) (if compiler:type-error-warnings? (typerew/type-check form rator* rands)) (cond ((typerew/replacement-method? rator* (length rands)) => (lambda (method) (apply-method method rands))) ((and (eq? rator* %invoke-remote-cache) (typerew/replacement-method? (first (quote/text (first rands))) (second (quote/text (first rands))))) => (lambda (method) (apply-method method (cddr rands)))) (else (rewrite! rator)))) (rewrite! rator))) (define (check-constant form simple?) (let ((type (typerew/type/no-error form))) (if type (let ((cst (type:->constant? type))) (if cst (form/rewrite! form (if simple? cst `(BEGIN ,(code-rewrite/remember (form/preserve form) form) ,cst)))))))) (define (rewrite! form) (cond ((QUOTE/? form)) ((LOOKUP/? form) (check-constant form #T)) ((CALL/? form) (rewrite-call! form (call/operator form) (call/continuation form) (call/operands form)) (check-constant form #F)) ((IF/? form) (rewrite! (if/predicate form)) (rewrite! (if/consequent form)) (rewrite! (if/alternative form)) (check-constant form #F)) ((BEGIN/? form) (rewrite!* (begin/exprs form))) ((LET/? form) (rewrite-bindings! (let/bindings form)) (rewrite! (let/body form))) ((LETREC/? form) (rewrite-bindings! (letrec/bindings form)) (rewrite! (letrec/body form))) ((LAMBDA/? form) (rewrite! (lambda/body form))) ((DECLARE/? form)) (else (illegal form)))) (rewrite! program)) (define (typerew/type-check form rator* rands) ;; Inspect the argument types of FORM and report any errors. ;; FORM = `(call (quote ,RATOR*) '#f ,RANDS) (define (report errors) (user-warning (with-output-to-string (lambda () (display "This form has ") (display (if (null? (cdr errors)) "a type error." "type errors.")) (for-each display errors) errors)) (form->source-irritant form))) (define (format position required-type actual-type) (with-output-to-string (lambda () (display "\n; Argument ") (display position) (display " is ") (display (type:user-description actual-type #F)) (display ", should be ") (display (type:user-description required-type #T)) (display ".")))) (define (check proc-type all-rands) (let ((argument-types (procedure-type/argument-types proc-type)) (asserted-types (procedure-type/argument-assertions proc-type))) (let loop ((rands all-rands) (position 1) (argument-types argument-types) (asserted-types asserted-types) (errors '())) ; list (string) (define (next errors*) (loop (cdr rands) (+ position 1) (if (pair? argument-types) (cdr argument-types) argument-types) (if (pair? asserted-types) (cdr asserted-types) asserted-types) errors*)) (define (test argument-type asserted-type) (let ((rand-type (typerew/type (car rands))) (req-type (type:and asserted-type argument-type))) (if (and (type:disjoint? rand-type req-type) (not (type:subset? rand-type type:empty))) (next (cons (format position req-type rand-type) errors)) (next errors)))) (cond ((null? rands) (if (pair? errors) (report (reverse! errors)))) ((null? argument-types) (internal-warning "Extra arguments in: " proc-type all-rands) (if (pair? errors) (report (reverse! errors)))) ((pair? argument-types) (test (car argument-types) (car asserted-types))) (else (test argument-types asserted-types)))))) (cond ((and (eq? rator* %invoke-remote-cache) (operator-type (first (quote/text (first rands))))) => (lambda (operator-type) (check operator-type (cddr rands)))) ((operator-type rator*) => (lambda (operator-type) (check operator-type rands))) (else unspecific))) ; we know nothing ;; REPLACEMENT METHODS ;; ;; Operators have replacement methods. Replacement methods are produres ;; of the form ;; (lambda (form arg1 arg2 ... argN) ...) ;; where FORM is the combination with the operator for which this is a ;; rewrite method, and ARG1 .. ARGN are the argument forms. FORM is ;; passed as an easy way of copying the original expression (via ;; form/and is necessary for accessing the remote-execute-cache for ;; those operators which are global procedures. ;; ;; Replacement methods returns a replacement generator. The replacement ;; generator is a procedure that when applied to the original FORM, ;; yields new form. It does not modify the program text. (define (typerew/replacement-method? op arity) (let ((arity.method (monotonic-strong-eq-hash-table/get *typerew/rewrite-methods* op #F))) (and arity.method (if (car arity.method) ; specific arity only (and (= (car arity.method) arity) (cdr arity.method)) (cdr arity.method))))) ; #F => any arity (define (define-typerew-replacement-method op arity method) ;; ARITY = #F means method for any arity (monotonic-strong-eq-hash-table/put! *typerew/rewrite-methods* op (cons arity method))) ;; Operator replacement strategies (define (typerew-no-replacement form) form) (define (typerew-simple-operator-replacement new-op) ;; Coerces operator to a replacement procedure (if (and (procedure? new-op) (not (primitive-procedure? new-op))) new-op (lambda (form) (sample/1 '(typerew/simple-replacements histogram) new-op) (let ((rator (quote/text (call/operator form)))) (if (eq? rator %invoke-remote-cache) (begin ;;(pp `(,(fourth form) => ,new-op)) `(CALL (QUOTE ,new-op) '#F ,@(cdr (cddddr form)))) (begin ;;(pp `(,(quote/text (call/operator form)) => ,new-op)) `(CALL (QUOTE ,new-op) ,@(cddr form)))))))) (define (typerew-object-type-test type-name) (let ((OBJECT-TYPE? (make-primitive-procedure 'OBJECT-TYPE?)) (type-code (machine-tag type-name))) (lambda (object) `(CALL ',OBJECT-TYPE? '#F (QUOTE ,type-code) ,object)))) (define (typerew/->unary-combination make-combination/operator) (if (and (procedure? make-combination/operator) (not (primitive-procedure? make-combination/operator))) make-combination/operator (lambda (arg1) `(CALL (QUOTE ,make-combination/operator) '#F ,arg1)))) (define (typerew/->nary-combination make-combination/operator) (if (and (procedure? make-combination/operator) (not (primitive-procedure? make-combination/operator))) make-combination/operator (lambda args `(CALL (QUOTE ,make-combination/operator) '#F ,@args)))) (define typerew/->binary-combination typerew/->nary-combination) (define typerew/->ternary-combination typerew/->nary-combination) (define (typerew/->primitive-error-combination primitive) (if (not (primitive-procedure? primitive)) (internal-error "Expected a primitive procedure" primitive)) (lambda args `(CALL (QUOTE ,%invoke-remote-cache) '#F '(%COMPILED-CODE-SUPPORT:SIGNAL-ERROR-IN-PRIMITIVE ,(+ (length args) 1)) 'bogus-cache-reference ; naughty, should insert a global cache ',primitive ,@args))) (define (typerew/diamond original-form test-form form*1 form*2) (define (equivalent form*) (typerew/remember* form* original-form)) (sample/1 '(typerew/diamond-replacements histogram) (quote/text (call/operator original-form))) (equivalent `(IF ,test-form ,(equivalent form*1) ,(equivalent form*2)))) (define (typerew-operator-replacement/diamond-1-1-1 test good-op bad-op) (let ((test (typerew/->unary-combination test)) (good-op (typerew/->unary-combination good-op)) (bad-op (typerew/->unary-combination bad-op))) (lambda (form) (let ((name (typerew/new-name 'OBJECT))) (bind name (call/operand1 form) (typerew/diamond form (test `(LOOKUP ,name)) (good-op `(LOOKUP ,name)) (bad-op `(LOOKUP ,name)))))))) (define (typerew-operator-replacement/diamond-1-2-2 test good-op bad-op) (let ((test (typerew/->unary-combination test)) (good-op (typerew/->binary-combination good-op)) (bad-op (typerew/->binary-combination bad-op))) (lambda (form) (let ((object (typerew/new-name 'OBJECT)) (value (typerew/new-name 'VALUE))) (bind* (list object value) (list (call/operand1 form) (call/operand2 form)) (typerew/diamond form (test `(LOOKUP ,object)) (good-op `(LOOKUP ,object) `(LOOKUP ,value)) (bad-op `(LOOKUP ,object) `(LOOKUP ,value)))))))) (define (typerew-operator-replacement/diamond-2-2-2 test good-op bad-op) (let ((test (typerew/->binary-combination test)) (good-op (typerew/->binary-combination good-op)) (bad-op (typerew/->binary-combination bad-op))) (lambda (form) (let ((object (typerew/new-name 'OBJECT)) (index (typerew/new-name 'INDEX))) (bind* (list object index) (list (call/operand1 form) (call/operand2 form)) (typerew/diamond form (test `(LOOKUP ,object) `(LOOKUP ,index)) (good-op `(LOOKUP ,object) `(LOOKUP ,index)) (bad-op `(LOOKUP ,object) `(LOOKUP ,index)))))))) (define (typerew-operator-replacement/diamond-2-3-3 test good-op bad-op) (let ((test (typerew/->binary-combination test)) (good-op (typerew/->ternary-combination good-op)) (bad-op (typerew/->ternary-combination bad-op))) (lambda (form) (let ((obj (typerew/new-name 'OBJECT)) (idx (typerew/new-name 'INDEX)) (elt (typerew/new-name 'ELEMENT))) (bind* (list obj idx elt) (list (call/operand1 form) (call/operand2 form) (call/operand3 form)) (typerew/diamond form (test `(LOOKUP ,obj) `(LOOKUP ,idx)) (good-op `(LOOKUP ,obj) `(LOOKUP ,idx) `(LOOKUP ,elt)) (bad-op `(LOOKUP ,obj) `(LOOKUP ,idx) `(LOOKUP ,elt)))))))) (define (typerew-operator-replacement/diamond-3-3-3 test good-op bad-op) (let ((test (typerew/->binary-combination test)) (good-op (typerew/->ternary-combination good-op)) (bad-op (typerew/->ternary-combination bad-op))) (lambda (form) (let ((obj (typerew/new-name 'OBJECT)) (idx (typerew/new-name 'INDEX)) (elt (typerew/new-name 'ELEMENT))) (bind* (list obj idx elt) (list (call/operand1 form) (call/operand2 form) (call/operand3 form)) (typerew/diamond form (test `(LOOKUP ,obj) `(LOOKUP ,idx) `(LOOKUP ,elt)) (good-op `(LOOKUP ,obj) `(LOOKUP ,idx) `(LOOKUP ,elt)) (bad-op `(LOOKUP ,obj) `(LOOKUP ,idx) `(LOOKUP ,elt)))))))) (define (typerew/%1 op) ; (mumble x y z) => (op x) (lambda (form) (define (make args) (sample/1 '(typerew/left-constant-replacements histogram) op) `(CALL (QUOTE ,op) '#F ,(first args))) (if (eq? (quote/text (call/operator form)) %invoke-remote-cache) (make (cddr (cddddr form))) (make (cdddr form))))) (define (typerew-binary-variants-type-method rator domain1 domain2 range effect . spec) ;; spec: repeated (input-type1 input-type2 output-type) ;; Compute result type for an operator that verifies its arguments are in ;; DOMAIN1 and DOMAIN2. Test triples in order. (define (result receiver result-type q1 q2 env) (typerew/send receiver (quantity:combination/2 rator q1 q2) result-type env)) (define universal-domain? (and (type:subset? type:any domain1) (type:subset? type:any domain2))) (define (compile-spec spec) ;; COMPILE-SPEC converts SPEC into a procedure to eliminate the ;; interpretive overhead of analysing SPEC every time. (if (null? spec) ;; Select a DEFAULT-METHOD optimized to reduce useless work (cond ((and (effect:none? effect) universal-domain?) (lambda (t1 t2 q1 q2 env form receiver) t1 t2 form ; ignored (result receiver range q1 q2 env))) ((effect:none? effect) (lambda (t1 t2 q1 q2 env form receiver) form ; ignored (result receiver range q1 q2 (q-env:glb/1 (q-env:glb/1 env q1 t1) q2 t2)))) (else (lambda (t1 t2 q1 q2 env form receiver) form ; ignored (result receiver range q1 q2 (q-env:restrict (q-env:glb/1 (q-env:glb/1 env q1 t1) q2 t2) effect))))) (let* ((a1 (first spec)) (a2 (second spec)) (result-type (third spec))) (let ((more-tests (compile-spec (cdddr spec)))) (lambda (t1 t2 q1 q2 env form receiver) (if (and (type:subset? t1 a1) (type:subset? t2 a2)) (result receiver result-type q1 q2 env) (more-tests t1 t2 q1 q2 env form receiver))))))) (let ((compiled-spec (compile-spec spec))) (lambda (quantities types env form receiver) (compiled-spec (type:and (first types) domain1) (type:and (second types) domain2) (first quantities) (second quantities) env form receiver)))) (define (typerew-binary-variants-replacement-method . spec) ;; spec: repeated (input-type1 input-type2 output-type replacement) ;; Select a replacement according to signature (define (make-search spec) ;; MAKE-SEARCH converts SPEC into a procedure to eliminate the ;; interpretive overhead of analysing SPEC every time. (if (null? spec) (lambda (t1 t2 t-result) t1 t2 t-result ; ignore typerew-no-replacement) (let* ((a1 (first spec)) (a2 (second spec)) (result-type (third spec)) (replacement (fourth spec))) (let ((try-others (make-search (cddddr spec))) (replacement* (if replacement (typerew-simple-operator-replacement replacement) typerew-no-replacement))) (lambda (t1 t2 t-result) (if (and (type:subset? t1 a1) (type:subset? t2 a2) (type:subset? t-result result-type)) (begin replacement*) (try-others t1 t2 t-result))))))) (let ((search (make-search spec))) (lambda (form arg1 arg2) (search (typerew/type arg1) (typerew/type arg2) (typerew/type form))))) (define (typerew-unary-variants-type-method rator domain range effect . spec) ;; spec: repeated (input-type output-type) ;; Compute result type for an operator that verifies its arguments are in ;; DOMAIN. Test in order. (define (result receiver result-type quantity env) (typerew/send receiver (quantity:combination/1 rator quantity) result-type env)) (define universal-domain? (type:subset? type:any domain)) (define (compile-spec spec) ;; COMPILE-SPEC converts SPEC into a procedure to eliminate the ;; interpretive overhead of analysing SPEC every time. (if (null? spec) ;; Select a DEFAULT-METHOD optimized to reduce useless work (cond ((and (effect:none? effect) universal-domain?) (lambda (t q env form receiver) t form ; ignored (result receiver range q env))) ((effect:none? effect) (lambda (t q env form receiver) form ; ignored (result receiver range q (q-env:glb/1 env q t)))) (else (lambda (t q env form receiver) form ; ignored (result receiver range q (q-env:restrict (q-env:glb/1 env q t) effect))))) (let* ((arg-type (first spec)) (result-type (second spec))) (let ((more-tests (compile-spec (cddr spec)))) (lambda (t q env form receiver) (if (type:subset? t arg-type) (result receiver result-type q env) (more-tests t q env form receiver))))))) (let ((compiled-spec (compile-spec spec))) (lambda (quantities types env form receiver) (compiled-spec (type:and (first types) domain) (first quantities) env form receiver)))) (define (typerew-unary-variants-replacement-method . spec) ;; spec: repeated (input-type output-type replacement) ;; Select a replacement according to signature (define (make-search spec) ;; MAKE-SEARCH converts SPEC into a procedure to eliminate the ;; interpretive overhead of analysing SPEC every time. (if (null? spec) (lambda (t-input t-result) t-input t-result ; ignore typerew-no-replacement) (let* ((arg-type (first spec)) (result-type (second spec)) (replacement (third spec))) (let ((try-others (make-search (cdddr spec))) (replacement* (if replacement (typerew-simple-operator-replacement replacement) typerew-no-replacement))) (lambda (t-input t-result) (if (and (type:subset? t-input arg-type) (type:subset? t-result result-type)) replacement* (try-others t-input t-result))))))) (let ((search (make-search spec))) (lambda (form arg1) (search (typerew/type arg1) (typerew/type form))))) (define (define-typerew-unary-predicate-type-method operator method) (define-typerew-type-method operator 1 (lambda (quantities types env form receiver) form ; No operator replacement (let ((env* (q-env:glb* env quantities types (list type:any)))) (typerew/send receiver (quantity:combination operator quantities) (method form (first types)) env*))))) (define (define-typerew-binary-predicate-type-method operator method) (define-typerew-type-method operator 2 (lambda (quantities types env form receiver) form ; No operator replacement (let ((env* (q-env:glb* env quantities types (list type:any type:any)))) (typerew/send receiver (quantity:combination operator quantities) (method form (first types) (second types)) env*))))) (define (define-typerew-unary-variants-type-method name . spec) (define-typerew-type-method name 1 (apply typerew-unary-variants-type-method name spec))) (define (define-typerew-unary-variants-replacement-method name . spec) (define-typerew-replacement-method name 1 (apply typerew-unary-variants-replacement-method spec))) (define (define-typerew-binary-variants-type-method name . spec) (define-typerew-type-method name 2 (apply typerew-binary-variants-type-method name spec))) (define (define-typerew-binary-variants-replacement-method name . spec) (define-typerew-replacement-method name 2 (apply typerew-binary-variants-replacement-method spec))) (define-typerew-unary-variants-type-method 'EXACT->INEXACT type:number type:inexact-number effect:none type:real type:inexact-real ;i.e. flonum type:recnum type:inexact-recnum) (define-typerew-unary-variants-replacement-method 'EXACT->INEXACT type:fixnum type:flonum %fixnum->flonum) (define-typerew-unary-variants-type-method 'INEXACT->EXACT type:number type:exact-number effect:none type:real type:exact-real type:recnum type:exact-recnum) (let () (define (def op flo:op) (define-typerew-unary-variants-type-method op type:number type:exact-integer effect:none) (define-typerew-unary-variants-replacement-method op type:flonum type:exact-integer FLO:op)) (def 'CEILING->EXACT FLO:CEILING->EXACT) (def 'FLOOR->EXACT FLO:FLOOR->EXACT) (def 'ROUND->EXACT FLO:ROUND->EXACT) (def 'TRUNCATE->EXACT FLO:TRUNCATE->EXACT)) (let () (define (def op flo:op) (define-typerew-unary-variants-type-method op type:number type:real effect:none type:flonum type:flonum type:exact-number type:exact-real) (define-typerew-unary-variants-replacement-method op type:flonum type:flonum FLO:op)) (def 'CEILING FLO:CEILING) (def 'FLOOR FLO:FLOOR) (def 'ROUND FLO:ROUND) (def 'TRUNCATE FLO:TRUNCATE)) (let ((INTEGER->FLONUM (ucode-primitive INTEGER->FLONUM 2)) (FIXNUM->FLONUM (ucode-primitive FIXNUM->FLONUM 1)) (type:false/flonum (type:or type:false type:flonum)) (type:0/1 (type:or type:exact-zero type:exact-one))) (define-typerew-binary-variants-type-method INTEGER->FLONUM type:exact-integer type:unsigned-byte type:false/flonum effect:none type:fixnum type:exact-zero type:flonum type:fixnum type:exact-one type:flonum ; [1] type:fixnum type:exact-one type:false/flonum ; [2] type:fixnum type:small-fixnum:2..255 type:flonum type:exact-integer type:0/1 type:false/flonum type:exact-integer type:small-fixnum:2..255 type:flonum) ;; [1] if fixnums guaranteed to fit in a flonum (e.g. 32 bit machine) ;; [2] if fixnums may not fix in a flonum (e.g. 64 bit machine). (define-typerew-binary-variants-replacement-method INTEGER->FLONUM type:fixnum type:any type:flonum (typerew/%1 %fixnum->flonum)) (define-typerew-unary-variants-replacement-method FIXNUM->FLONUM type:fixnum type:flonum %fixnum->flonum)) (define-typerew-unary-variants-type-method 'COS type:number type:number effect:none type:exact-zero type:exact-one type:real type:flonum) (define-typerew-unary-variants-type-method 'SIN type:number type:number effect:none type:exact-zero type:exact-zero type:real type:flonum) (define-typerew-unary-variants-type-method 'TAN type:number type:number effect:none type:exact-zero type:exact-zero type:real type:flonum) (define-typerew-unary-variants-type-method 'ACOS type:number type:number effect:none type:exact-one type:exact-zero type:number type:inexact-number) (define-typerew-unary-variants-type-method 'ASIN type:number type:number effect:none type:exact-zero type:exact-zero type:number type:inexact-number) (define-typerew-unary-variants-type-method 'EXP type:number type:number effect:none type:recnum type:inexact-recnum type:exact-zero type:exact-one type:real type:inexact-real type:number type:inexact-number) (define-typerew-unary-variants-type-method 'LOG type:number type:number effect:none type:exact-one type:exact-zero type:number type:inexact-number) (let () (define (def name flo:op) (define-typerew-unary-variants-replacement-method name type:flonum type:flonum flo:op)) (def 'COS flo:cos) (def 'SIN flo:sin) (def 'TAN flo:tan) (def 'EXP flo:exp)) (define-typerew-unary-variants-type-method 'ABS type:number type:real effect:none type:exact-one type:exact-zero (type:or type:small-fixnum type:big-fixnum+ve) type:fixnum type:fixnum (type:or type:fixnum type:bignum>0) type:exact-integer type:exact-integer type:flonum type:flonum) (define-typerew-unary-variants-replacement-method 'ABS type:flonum type:flonum flo:abs) (define-typerew-unary-variants-replacement-method 'SQRT type:number type:number effect:none type:fixnum+ve (type:or type:small-fixnum+ve type:flonum) type:fixnum+ve (type:or type:small-fixnum+ve type:flonum) type:flonum (type:or type:flonum type:inexact-recnum)) (define-typerew-unary-variants-type-method 'SYMBOL-NAME type:symbol type:string effect:none) (define-typerew-unary-variants-replacement-method 'SYMBOL-NAME type:symbol type:string system-pair-car) (define (typerew/rewrite/coerced-arguments op coerce-left coerce-right) (lambda (form) (define (make args) (sample/1 '(typerew/coerced->flonum-replacements histogram) op) `(CALL (QUOTE ,op) '#F ,(coerce-left (first args)) ,(coerce-right (second args)))) (if (eq? (quote/text (call/operator form)) %invoke-remote-cache) (make (cddr (cddddr form))) (make (cdddr form))))) (define (typerew/coerce/fixnum->flonum expr) (if (QUOTE/? expr) `(QUOTE ,(exact->inexact (quote/text expr))) `(CALL (QUOTE ,%fixnum->flonum) '#F ,expr))) (define (typerew/%l flo:op) (typerew/rewrite/coerced-arguments flo:op typerew/coerce/fixnum->flonum identity-procedure)) (define (typerew/%r flo:op) (typerew/rewrite/coerced-arguments flo:op identity-procedure typerew/coerce/fixnum->flonum)) (define (typerew/%lc op left-constant) ; (mumble x y z) => (op x y z 'c) (lambda (form) (define (make args) (sample/1 '(typerew/left-constant-replacements histogram) op) `(CALL (QUOTE ,op) '#F ,@args (QUOTE ,left-constant))) (if (eq? (quote/text (call/operator form)) %invoke-remote-cache) (make (cddr (cddddr form))) (make (cdddr form))))) (let ((&+ (make-primitive-procedure '&+)) (type:not-fixnum (type:not type:fixnum))) (define (generic-addition-inference op) (define-typerew-binary-variants-type-method op type:number type:number type:number effect:none type:unsigned-byte type:unsigned-byte type:small-fixnum>=0 type:small-fixnum>=0 type:small-fixnum>=0 type:fixnum>=0 type:small-fixnum-ve type:small-fixnum-ve type:fixnum-ve type:small-fixnum>=0 type:small-fixnum-ve type:small-fixnum type:small-fixnum-ve type:small-fixnum>=0 type:small-fixnum type:small-fixnum type:small-fixnum type:fixnum type:fixnum>=0 type:fixnum-ve type:fixnum type:fixnum-ve type:fixnum>=0 type:fixnum type:fixnum type:flonum type:flonum type:flonum type:fixnum type:flonum type:flonum type:flonum type:flonum type:exact-integer type:exact-integer type:exact-integer type:exact-number type:exact-number type:exact-number type:inexact-number type:number type:inexact-number type:number type:inexact-number type:inexact-number)) (generic-addition-inference &+) (generic-addition-inference %+) (define-typerew-binary-variants-replacement-method &+ type:fixnum type:fixnum type:fixnum fix:+ type:flonum type:flonum type:flonum flo:+ type:fixnum type:flonum type:flonum (typerew/%l flo:+) type:flonum type:fixnum type:flonum (typerew/%r flo:+) type:not-fixnum type:any type:any %+ type:any type:not-fixnum type:any %+) (define-typerew-binary-variants-replacement-method %+ type:fixnum type:fixnum type:fixnum fix:+ type:fixnum type:flonum type:flonum (typerew/%l flo:+) type:flonum type:fixnum type:flonum (typerew/%r flo:+) type:flonum type:flonum type:flonum flo:+)) (define-typerew-binary-variants-type-method fix:+ type:any type:any type:fixnum effect:none type:unsigned-byte type:unsigned-byte type:small-fixnum>=0 type:small-fixnum>=0 type:small-fixnum>=0 type:fixnum>=0 type:small-fixnum-ve type:small-fixnum-ve type:fixnum-ve type:small-fixnum>=0 type:small-fixnum-ve type:small-fixnum type:small-fixnum-ve type:small-fixnum>=0 type:small-fixnum) (let ((&- (make-primitive-procedure '&-)) (type:not-fixnum (type:not type:fixnum))) (define (generic-subtraction-inference op) (define-typerew-binary-variants-type-method op type:number type:number type:number effect:none type:small-fixnum type:small-fixnum type:fixnum type:fixnum>=0 type:fixnum>=0 type:fixnum type:fixnum type:flonum type:flonum type:flonum type:fixnum type:flonum type:flonum type:flonum type:flonum type:exact-integer type:exact-integer type:exact-integer type:exact-number type:exact-number type:exact-number type:inexact-number type:number type:inexact-number type:number type:inexact-number type:inexact-number)) (generic-subtraction-inference &-) (generic-subtraction-inference %-) (define-typerew-binary-variants-replacement-method &- type:fixnum type:fixnum type:fixnum fix:- type:flonum type:flonum type:flonum flo:- type:fixnum type:flonum type:flonum (typerew/%l flo:-) type:flonum type:fixnum type:flonum (typerew/%r flo:-) type:not-fixnum type:any type:any %- type:any type:not-fixnum type:any %-) (define-typerew-binary-variants-replacement-method %- type:fixnum type:fixnum type:fixnum fix:- type:fixnum type:flonum type:flonum (typerew/%l flo:-) type:flonum type:fixnum type:flonum (typerew/%r flo:-) type:flonum type:flonum type:flonum flo:-)) (let ((&* (make-primitive-procedure '&*)) (&/ (make-primitive-procedure '&/)) (type:inexact+0 (type:or type:inexact-number type:exact-zero)) (type:exact-int-not-0 (type:except type:exact-integer type:exact-zero)) (type:flonum+0 (type:or type:flonum type:exact-zero)) (type:not-fixnum (type:not type:fixnum))) (define (generic-multiply-inference op) (define-typerew-binary-variants-type-method op type:number type:number type:number effect:none type:unsigned-byte type:unsigned-byte type:small-fixnum>=0 type:exact-int-not-0 type:flonum type:flonum type:flonum type:exact-int-not-0 type:flonum type:exact-integer type:flonum type:flonum+0 type:flonum type:exact-integer type:flonum+0 type:flonum type:flonum type:flonum type:exact-integer type:exact-integer type:exact-integer type:exact-number type:exact-number type:exact-number ;; Note that (* <inexact> 0) = 0 type:inexact-number type:inexact-number type:inexact-number type:inexact-number type:number type:inexact+0 type:number type:inexact-number type:inexact+0)) (generic-multiply-inference &*) (generic-multiply-inference %*) (define-typerew-binary-variants-replacement-method &* type:fixnum type:fixnum type:fixnum fix:* type:flonum type:flonum type:flonum flo:* type:fixnum type:flonum type:flonum (typerew/%l flo:*) type:flonum type:fixnum type:flonum (typerew/%r flo:*) type:not-fixnum type:any type:any %* type:any type:not-fixnum type:any %*) (define-typerew-binary-variants-replacement-method %* type:fixnum type:fixnum type:fixnum fix:* type:fixnum type:flonum type:flonum (typerew/%l flo:*) type:flonum type:fixnum type:flonum (typerew/%r flo:*) type:flonum type:flonum type:flonum flo:*) (define (generic-divide-inference op) (define-typerew-binary-variants-type-method op type:number type:number type:number effect:none type:flonum type:flonum type:flonum type:flonum type:fixnum type:flonum type:exact-int-not-0 type:flonum type:flonum type:exact-integer type:flonum type:flonum+0 type:inexact-number type:number type:inexact-number type:number type:inexact-number type:inexact-number)) (generic-divide-inference &/) (generic-divide-inference %/) (define-typerew-binary-variants-replacement-method &/ type:fixnum type:flonum type:flonum (typerew/%l flo:/) type:flonum type:fixnum type:flonum (typerew/%r flo:/) type:flonum type:flonum type:flonum flo:/) (define-typerew-binary-variants-replacement-method %/ type:fixnum type:flonum type:flonum (typerew/%l flo:/) type:flonum type:fixnum type:flonum (typerew/%r flo:/) type:flonum type:flonum type:flonum flo:/)) (let* ((type:fixnum-not-0 (type:except type:fixnum type:exact-zero)) (type:fixnum-not-0/-1 (type:except type:fixnum-not-0 type:exact-minus-one)) (type:integer-result (type:or type:exact-integer type:flonum)) (QUOTIENT (make-primitive-procedure 'QUOTIENT)) (REMAINDER (make-primitive-procedure 'REMAINDER)) (INTEGER-QUOTIENT (ucode-primitive INTEGER-QUOTIENT)) (INTEGER-REMAINDER (ucode-primitive INTEGER-REMAINDER))) ;; QUOTIENT and REMAINDER on fixnums can overflow only when dividing by 0 ;; or -1. When dividing by -1 it can only overflow when the value ;; is the most negative fixnum (-2^(word-size-1)). The quotient has ;; the same sign as the product. The remainder has the same sign as ;; the dividend. Both return integers (exact or inexact). Note ;; that inexact inputs might be recnums and might yield exact ;; results: ;; (quotient 10+0.i 3) => 3 ;; The flonum cases correspond to a subset of the inexact cases with a ;; known (i.e. flonum) representation. (define-typerew-binary-variants-type-method QUOTIENT type:number type:number type:integer-result effect:none type:unsigned-byte type:fixnum+ve type:unsigned-byte type:small-fixnum type:fixnum-not-0/-1 type:small-fixnum type:small-fixnum type:fixnum-not-0 type:fixnum type:fixnum type:fixnum-not-0/-1 type:fixnum type:exact-integer type:exact-integer type:exact-integer type:flonum type:flonum type:flonum type:inexact-number type:number type:integer-result type:number type:inexact-number type:integer-result) (define-typerew-binary-variants-type-method REMAINDER type:number type:number type:integer-result effect:none type:unsigned-byte type:exact-integer type:unsigned-byte type:fixnum>=0 type:unsigned-byte type:unsigned-byte type:small-fixnum>=0 type:exact-integer type:small-fixnum>=0 type:small-fixnum type:exact-integer type:small-fixnum type:exact-integer type:unsigned-byte type:small-fixnum type:fixnum>=0 type:exact-integer type:fixnum>=0 type:exact-integer type:small-fixnum type:fixnum type:fixnum type:exact-integer type:fixnum type:exact-integer type:exact-integer type:exact-integer type:flonum type:flonum type:flonum type:inexact-number type:number type:integer-result type:number type:inexact-number type:integer-result) (define-typerew-binary-variants-type-method INTEGER-QUOTIENT type:exact-integer type:exact-integer type:exact-integer effect:none) (define-typerew-binary-variants-type-method INTEGER-REMAINDER type:exact-integer type:exact-integer type:exact-integer effect:none type:unsigned-byte type:exact-integer type:unsigned-byte type:fixnum>=0 type:unsigned-byte type:unsigned-byte type:small-fixnum>=0 type:exact-integer type:small-fixnum>=0 type:fixnum>=0 type:exact-integer type:fixnum>=0 type:small-fixnum type:exact-integer type:small-fixnum type:exact-integer type:unsigned-byte type:small-fixnum type:exact-integer type:small-fixnum type:fixnum type:fixnum type:exact-integer type:fixnum) (define-typerew-binary-variants-replacement-method QUOTIENT type:small-fixnum type:fixnum-not-0 type:fixnum fix:quotient type:fixnum type:fixnum-not-0/-1 type:fixnum fix:quotient type:any type:any type:any %quotient) (define-typerew-binary-variants-replacement-method REMAINDER type:fixnum type:fixnum-not-0 type:fixnum fix:remainder type:any type:any type:any %remainder) (define-typerew-binary-variants-replacement-method INTEGER-REMAINDER type:fixnum type:fixnum-not-0 type:fixnum fix:remainder) ;; MODULO is not integrated. ) (let ((INTEGER-ADD-1 (ucode-primitive INTEGER-ADD-1)) (INTEGER-SUBTRACT-1 (ucode-primitive INTEGER-SUBTRACT-1)) (INTEGER-ADD (ucode-primitive INTEGER-ADD)) (INTEGER-SUBTRACT (ucode-primitive INTEGER-SUBTRACT)) (INTEGER-MULTIPLY (ucode-primitive INTEGER-MULTIPLY))) (define-typerew-unary-variants-type-method INTEGER-ADD-1 type:exact-integer type:exact-integer effect:none type:unsigned-byte type:small-fixnum>=0 type:small-fixnum+ve type:fixnum+ve type:small-fixnum>=0 type:fixnum+ve type:small-fixnum-ve type:small-fixnum type:small-fixnum type:fixnum type:fixnum-ve type:fixnum) (define-typerew-unary-variants-type-method INTEGER-SUBTRACT-1 type:exact-integer type:exact-integer effect:none type:small-fixnum-ve type:fixnum-ve type:small-fixnum+ve type:small-fixnum>=0 type:small-fixnum type:fixnum type:fixnum+ve type:fixnum>=0 type:small-fixnum>=0 type:small-fixnum type:fixnum>=0 type:fixnum) (define-typerew-binary-variants-type-method INTEGER-ADD type:exact-integer type:exact-integer type:exact-integer effect:none type:unsigned-byte type:unsigned-byte type:small-fixnum>=0 type:small-fixnum>=0 type:small-fixnum>=0 type:fixnum>=0 type:small-fixnum-ve type:small-fixnum-ve type:fixnum-ve type:small-fixnum>=0 type:small-fixnum-ve type:small-fixnum type:small-fixnum-ve type:small-fixnum>=0 type:small-fixnum type:small-fixnum type:small-fixnum type:fixnum type:fixnum>=0 type:fixnum-ve type:fixnum type:fixnum-ve type:fixnum>=0 type:fixnum type:exact-integer type:exact-integer type:exact-integer) (define-typerew-binary-variants-type-method INTEGER-SUBTRACT type:exact-integer type:exact-integer type:exact-integer effect:none type:small-fixnum type:small-fixnum type:fixnum) (define-typerew-binary-variants-type-method INTEGER-MULTIPLY type:exact-integer type:exact-integer type:exact-integer effect:none type:unsigned-byte type:unsigned-byte type:small-fixnum>=0) (define-typerew-binary-variants-replacement-method INTEGER-ADD type:fixnum type:fixnum type:fixnum fix:+) (define-typerew-binary-variants-replacement-method INTEGER-SUBTRACT type:fixnum type:fixnum type:fixnum fix:-) (define-typerew-binary-variants-replacement-method INTEGER-MULTIPLY type:fixnum type:fixnum type:fixnum fix:*) ) #| (let () ;; Binary MIN and MAX. We can replace ;; (MIN e1 e2) ;; by ;; (if (< e1 e2) e1 e2) ;; only if e1 and e2 always have the same exactness (define (def min/max) (define-typerew-binary-variants-type-method min/max type:number type:number type:real effect:none type:fixnum type:fixnum type:fixnum type:exact-integer type:exact-integer type:exact-integer type:flonum type:flonum type:flonum) (define-typerew-binary-variants-replacement-method min/max type:fixnum type:fixnum type:any (pick fix:op) type:exact-integer type:exact-integer type:any (pick gen:op) type:flonum type:flonum type:any (pick flo:op))) (define (pick compare) (lambda (form) (let ((arg1 (sixth form)) (arg2 (seventh form)) (name1 (typerew/new-name 'ARG1)) (name2 (typerew/new-name 'ARG2))) (bind* (list name1 name2) (list arg1 arg2) `(IF (CALL ',compare '#F (LOOKUP ,name1) (LOOKUP ,name2)) (LOOKUP ,name1) (LOOKUP ,name2)))))) (def 'MIN fix:< (make-primitive-procedure '&<) flo:<) (def 'MAX fix:> (make-primitive-procedure '&>) flo:>)) |# (let ((type:fix:+1/-1 (type:or type:exact-one type:exact-minus-one))) (define-typerew-binary-variants-type-method 'EXPT type:number type:number type:number effect:none type:exact-minus-one type:exact-integer type:fix:+1/-1 type:exact-one type:exact-integer type:exact-one ;; luckily (EXPT <flonum> 0) => <flonum> type:flonum type:exact-integer type:flonum) (define-typerew-replacement-method 'EXPT 2 (lambda (form base exponent) form ; ignored (let* ((t-exponent (typerew/type exponent))) (cond ((and (type:subset? t-exponent type:fixnum) (or (equal? base '(QUOTE -1)) (equal? base '(QUOTE -1.0)))) (let ((negative-one (quote/text base))) (lambda (form) form ; ignored `(IF (CALL ',eq? '#F (CALL ',fix:and '#F ,exponent '1) '0) ',(- negative-one) ',negative-one)))) (else typerew-no-replacement)))))) (let ((type:not-fixnum (type:not type:fixnum))) (define (define-relational-method name fix:op flo:op %op) (let ((primitive (make-primitive-procedure name))) (define-typerew-binary-variants-type-method primitive type:number type:number type:boolean effect:none) (define-typerew-binary-variants-replacement-method primitive type:fixnum type:fixnum type:any fix:op type:fixnum type:flonum type:any (typerew/%l flo:op) type:flonum type:fixnum type:any (typerew/%r flo:op) type:flonum type:flonum type:any flo:op type:not-fixnum type:any type:any %op type:any type:not-fixnum type:any %op) (define-typerew-binary-variants-type-method %op type:number type:number type:boolean effect:none) (define-typerew-binary-variants-replacement-method %op type:fixnum type:fixnum type:any fix:op type:fixnum type:flonum type:any (typerew/%l flo:op) type:flonum type:fixnum type:any (typerew/%r flo:op) type:flonum type:flonum type:any flo:op))) (define-relational-method '&< fix:< flo:< %<) (define-relational-method '&> fix:> flo:> %>)) (let ((&= (make-primitive-procedure '&=)) (EQ? (make-primitive-procedure 'EQ?)) (INTEGER-EQUAL? (make-primitive-procedure 'INTEGER-EQUAL?)) (INTEGER-LESS? (make-primitive-procedure 'INTEGER-LESS?)) (INTEGER-GREATER? (make-primitive-procedure 'INTEGER-GREATER?)) (INTEGER-ZERO? (make-primitive-procedure 'INTEGER-ZERO?)) (INTEGER-NEGATIVE? (make-primitive-procedure 'INTEGER-NEGATIVE?)) (INTEGER-POSITIVE? (make-primitive-procedure 'INTEGER-POSITIVE?)) (type:not-fixnum (type:not type:fixnum))) (define-typerew-binary-variants-type-method &= type:number type:number type:boolean effect:none) (define-typerew-binary-variants-type-method %= type:number type:number type:boolean effect:none) (define-typerew-binary-variants-type-method INTEGER-EQUAL? type:exact-integer type:exact-integer type:boolean effect:none) (define-typerew-binary-variants-replacement-method &= ;; Representation note: EQ? works for comparing any exact number to a ;; fixnum because the generic arithmetic canonicalizes values to ;; fixnums wherever possible. type:fixnum type:exact-number type:any EQ? type:exact-number type:fixnum type:any EQ? type:flonum type:flonum type:any flo:= type:fixnum type:flonum type:any (typerew/%l flo:=) type:flonum type:fixnum type:any (typerew/%r flo:=) type:not-fixnum type:any type:any %= type:any type:not-fixnum type:any %=) (define-typerew-binary-variants-replacement-method %= type:fixnum type:exact-number type:any EQ? type:exact-number type:fixnum type:any EQ? type:flonum type:flonum type:any flo:= type:fixnum type:flonum type:any (typerew/%l flo:=) type:flonum type:fixnum type:any (typerew/%r flo:=)) (define-typerew-binary-variants-replacement-method INTEGER-EQUAL? type:fixnum type:exact-integer type:any EQ? type:exact-integer type:fixnum type:any EQ?) (define-typerew-binary-variants-replacement-method INTEGER-LESS? type:fixnum type:fixnum type:any fix:<) (define-typerew-binary-variants-replacement-method INTEGER-GREATER? type:fixnum type:fixnum type:any fix:>) (define-typerew-unary-variants-replacement-method INTEGER-ZERO? type:exact-integer type:any (typerew/%lc EQ? 0)) (define-typerew-unary-variants-replacement-method INTEGER-NEGATIVE? type:fixnum type:any (typerew/%lc fix:< 0)) (define-typerew-unary-variants-replacement-method INTEGER-POSITIVE? type:fixnum type:any (typerew/%lc fix:> 0)) ) ;; We have no objects which could be EQ? (EQV? EQUAL?) without being the ;; same type. (Numbers are only EQV? or EQUAL? if they have the same ;; exactness.) (let ((define-equality-disjointness (lambda (equality-test) (define-typerew-binary-predicate-type-method equality-test (lambda (form type1 type2) form ; unused (if (type:disjoint? type1 type2) type:false type:boolean)))))) (define-equality-disjointness EQ?) (define-equality-disjointness 'EQV?) (define-equality-disjointness 'EQUAL?)) (let ((type:eqv?-is-eq? (type:or (type:not type:number) type:fixnum)) (type:equal?-is-eq? (type:or* type:fixnum type:character type:tc-constant type:symbol)) (EQ? (make-primitive-procedure 'EQ?))) (define-typerew-binary-variants-type-method 'EQV? type:any type:any type:boolean effect:none) (define-typerew-binary-variants-type-method 'EQUAL? type:any type:any type:boolean effect:none) (define-typerew-binary-variants-replacement-method 'EQV? type:eqv?-is-eq? type:any type:any EQ? type:any type:eqv?-is-eq? type:any EQ?) (define-typerew-binary-variants-replacement-method 'EQUAL? type:equal?-is-eq? type:any type:any EQ? type:any type:equal?-is-eq? type:any EQ?)) (define-typerew-binary-predicate-type-method %small-fixnum? (let ((type:not-small-fixnum (type:not type:small-fixnum)) (type:not-fixnum (type:not type:fixnum))) (lambda (form argtype1 argtype2) argtype2 ; ignored (define (discern type1 type2) (cond ((type:disjoint? argtype1 type1) type:false) ((type:disjoint? argtype1 type2) type:true) (else type:boolean))) (let ((n-bits (form/exact-integer? (call/operand2 form)))) (cond ((= n-bits 1) (discern type:small-fixnum type:not-small-fixnum)) ((= n-bits 0) (discern type:fixnum type:not-fixnum)) (else (discern type:small-fixnum type:any))))))) (let () (define (def-unary-selector name asserted-type type-check-class %test %operation) ;; No effects. (let* ((rator (make-primitive-procedure name)) (checking-replacement (typerew-operator-replacement/diamond-1-1-1 %test %operation (typerew/->primitive-error-combination rator))) (unchecked-replacement (typerew-simple-operator-replacement %operation))) (define-typerew-replacement-method rator 1 (lambda (form arg1) form (if (and (typerew/type-checks? type-check-class) (not (type:subset? (typerew/type arg1) asserted-type))) checking-replacement unchecked-replacement))))) (def-unary-selector 'CAR type:pair 'PAIR PAIR? %car) (def-unary-selector 'CDR type:pair 'PAIR PAIR? %cdr) (def-unary-selector 'VECTOR-LENGTH type:vector 'VECTOR (typerew-object-type-test 'VECTOR) %vector-length) (def-unary-selector '%RECORD-LENGTH type:%record 'RECORD (typerew-object-type-test 'RECORD) %%record-length) (def-unary-selector 'STRING-LENGTH type:string 'STRING (typerew-object-type-test 'VECTOR-8B) %string-length) (def-unary-selector 'FLOATING-VECTOR-LENGTH type:flonum-vector 'FLOATING-VECTOR (typerew-object-type-test 'FLONUM) ; %floating-vector-length) (define (def-unary-mutator name location-type type-check-class %test %operation) (let* ((rator (make-primitive-procedure name)) (checking-replacement (typerew-operator-replacement/diamond-1-2-2 %test %operation (typerew/->primitive-error-combination rator))) (unchecked-replacement (typerew-simple-operator-replacement %operation))) (define-typerew-replacement-method rator 2 (lambda (form arg1 arg2) form arg2 ; (if (and (typerew/type-checks? type-check-class) (not (type:subset? (typerew/type arg1) location-type))) checking-replacement unchecked-replacement))))) (def-unary-mutator 'SET-CAR! type:pair 'PAIR PAIR? %set-car!) (def-unary-mutator 'SET-CDR! type:pair 'PAIR PAIR? %set-cdr!) ) (let () ;; For the indexed selectors or mutators we do not even try to figure out ;; if the index is in range. Range checking also performs ;; type-checking of the index (via an unsigned comarison). Note ;; that %RECORDs are always created with at least a descriptor slot, ;; so an index known to be exact zero does not need a range (or ;; type) check. This is what RANGE-TYPE-OK is for. If not #F, then ;; it is a type describing those index values which never need a ;; check. (define (def-indexed-operations selector-name mutator-name type-check-class element-type collection-type %selector %mutator v-typecode v-length element-typecode range-ok-type) ;; No effects. (let ((selector (make-primitive-procedure selector-name)) (unchecked-selection (typerew-simple-operator-replacement %selector))) (define (make-checked-selection checks) (typerew-operator-replacement/diamond-2-2-2 (lambda (collection index) `(CALL ',%generic-index-check/ref '#F ,collection ,index (QUOTE ,checks))) (typerew/->binary-combination %selector) (typerew/->primitive-error-combination selector))) (define-typerew-replacement-method selector 2 (lambda (form collection index) form index (let ((v-type (typerew/type collection)) (i-type (typerew/type index)) (type-checks? (typerew/type-checks? type-check-class)) (range-checks? (typerew/range-checks? type-check-class))) (let ((check/1? (and type-checks? (not (type:subset? v-type collection-type)) v-typecode)) (check/2? ; length check incorporates type check (and (or (and range-checks? (not (and range-ok-type (type:subset? i-type range-ok-type)))) (and type-checks? (not (type:subset? i-type type:fixnum)))) v-length))) (if (or check/1? check/2?) (make-checked-selection (vector check/1? check/2?)) unchecked-selection)))))) (let ((mutator (make-primitive-procedure mutator-name)) (unsafe-mutation (typerew-simple-operator-replacement %mutator))) (define (make-checked-mutation checks) (typerew-operator-replacement/diamond-3-3-3 (lambda (collection index element) `(CALL ',%generic-index-check/set! '#F ,collection ,index ,element (QUOTE ,checks))) %mutator (typerew/->primitive-error-combination mutator))) (define-typerew-replacement-method mutator 3 (lambda (form collection index element) form index (let ((v-type (typerew/type collection)) (i-type (typerew/type index)) (e-type (typerew/type element)) (type-checks? (typerew/type-checks? type-check-class)) (range-checks? (typerew/range-checks? type-check-class))) (let ((check/1? (and type-checks? (not (type:subset? v-type collection-type)) v-typecode)) (check/2? (and (or (and range-checks? (not (and range-ok-type (type:subset? i-type range-ok-type)))) (and type-checks? (not (type:subset? i-type type:fixnum)))) v-length)) (check/3? (and type-checks? element-typecode (not (type:subset? e-type element-type)) element-typecode))) (if (or check/1? check/2? check/3?) (make-checked-mutation (vector check/1? check/2? check/3?)) unsafe-mutation))))))) (def-indexed-operations 'VECTOR-REF 'VECTOR-SET! 'VECTOR type:any type:vector %vector-ref %vector-set! (machine-tag 'VECTOR) %vector-length #F #F) (def-indexed-operations '%RECORD-REF '%RECORD-SET! 'RECORD type:any type:%record %%record-ref %%record-set! (machine-tag 'RECORD) %%record-length #F type:exact-zero) (def-indexed-operations 'STRING-REF 'STRING-SET! 'STRING type:character type:string %string-ref %string-set! (machine-tag 'VECTOR-8B) %string-length (machine-tag 'CHARACTER) #F) (def-indexed-operations 'VECTOR-8B-REF 'VECTOR-8B-SET! 'STRING type:unsigned-byte type:string %vector-8b-ref %vector-8b-set! (machine-tag 'VECTOR-8B) %string-length (machine-tag 'POSITIVE-FIXNUM) #F) (def-indexed-operations 'FLOATING-VECTOR-REF 'FLOATING-VECTOR-SET! 'FLOATING-VECTOR type:flonum type:flonum-vector %floating-vector-ref %floating-vector-set! (machine-tag 'FLONUM) %floating-vector-length (machine-tag 'FLONUM) #F) ) (define (typerew/initialize-known-operators!) ;; Augment our special knowledge. ;; (1) Predicates defined in terms of the types they distinguish: (for-every (monotonic-strong-eq-hash-table->alist *operator-predicate-test-types*) (lambda (operator.t1.t2) (let ((operator (car operator.t1.t2)) (types-possibly-true (cadr operator.t1.t2)) (types-possibly-false (cddr operator.t1.t2))) (if (not (monotonic-strong-eq-hash-table/get *typerew/type-methods* operator #F)) (define-typerew-unary-predicate-type-method operator (lambda (form argtype) form ; unused (cond ((type:disjoint? argtype types-possibly-false) type:true) ((type:disjoint? argtype types-possibly-true) type:false) (else type:boolean)))) (warn "Already defined:" operator))))) ;; (2) Any operations defined in typedb.scm: (for-every (monotonic-strong-eq-hash-table->alist *operator-types*) (lambda (operator.procedure-type) (let ((operator (car operator.procedure-type)) (proc-type (cdr operator.procedure-type))) (if (not (monotonic-strong-eq-hash-table/get *typerew/type-methods* operator #F)) (let ((argtypes (procedure-type/argument-assertions proc-type))) (if (list? argtypes) (define-typerew-type-method operator (length argtypes) (typerew/general-type-method operator argtypes (procedure-type/result-type proc-type) (procedure-type/effects-performed proc-type))) (define-typerew-type-method operator #F (typerew/general-type-method operator argtypes (procedure-type/result-type proc-type) (procedure-type/effects-performed proc-type)))))))))) (typerew/initialize-known-operators!) (define (pp/ann/ty program) (let ((type-map *typerew-type-map*) (dbg-map *typerew-dbg-map*) (cache (make-form-map))) ; prevents GC dbg-map (define (annotate e) (or (form-map/get cache e #F) (let ((type (form-map/get type-map e #F))) (let ((annotation type)) (form-map/put! cache e annotation) annotation)))) (pp/ann program annotate)))
false
28baa91d9b553bbafcc53fbcab219b69ce83418a
b60cb8e39ec090137bef8c31ec9958a8b1c3e8a6
/test/R5RS/ad/qstand.scm
7b9de518c049cbe81c13745444bef785b5194786
[]
no_license
acieroid/scala-am
eff387480d3baaa2f3238a378a6b330212a81042
13ef3befbfc664b77f31f56847c30d60f4ee7dfe
refs/heads/master
2021-01-17T02:21:41.692568
2021-01-15T07:51:20
2021-01-15T07:51:20
28,140,080
32
16
null
2020-04-14T08:53:20
2014-12-17T14:14:02
Scheme
UTF-8
Scheme
false
false
1,778
scm
qstand.scm
(define (quick-sort vector) (define (swap vector index1 index2) (let ((temp (vector-ref vector index1))) (vector-set! vector index1 (vector-ref vector index2)) (vector-set! vector index2 temp))) (define (quick-sort-aux low high) (define (quick-sort-aux-iter mid-value from to) (define (quick-right index1) (if (< (vector-ref vector index1) mid-value) (quick-right (+ index1 1)) index1)) (define (quick-left index2) (if (> (vector-ref vector index2) mid-value) (quick-left (- index2 1)) index2)) (let ((index1 (quick-right (+ from 1))) (index2 (quick-left to))) (cond ((< index1 index2) (swap vector index1 index2) (quick-sort-aux-iter mid-value index1 index2)) (else index2)))) (if (< low high) (begin (if (> (vector-ref vector low) (vector-ref vector high)) (swap vector low high)) (let ((mid-index (quick-sort-aux-iter (vector-ref vector low) low high))) (swap vector mid-index low) (quick-sort-aux low (- mid-index 1)) (quick-sort-aux (+ mid-index 1) high))))) (quick-sort-aux 0 (- (vector-length vector) 1))) (define test1 (vector 7 2 4 6 0 8 5 3 1)) (quick-sort test1) (define test2 (vector 8 1 4 9 6 3 5 2 7 0)) (quick-sort test2) (define test3 (vector 8 3 6 6 1 5 4 2 9 6)) (quick-sort test3) (and (equal? test1 (vector 0 1 2 3 4 5 6 7 8)) (equal? test2 (vector 0 1 2 3 4 5 6 7 8 9)) (equal? test3 (vector 1 2 3 4 5 6 6 6 8 9)))
false
6c75cc9b304e7b390825f5e418cd572ac8cffbe1
09e309c8c7dd86d201f965a12f4f174fd2bf8cf5
/scheme/for-each-numbers.scm
2898cfe5d646277cbd8e0f0801c7d3282bfa46d5
[]
no_license
googol-lab/lang
f21076846b2364ee08875530ab7a6680de61f55c
38cae455f85464a7f918d1a5a481a577ed5549fe
refs/heads/master
2020-03-29T13:32:29.159544
2010-05-24T03:09:54
2010-05-24T03:09:54
null
0
0
null
null
null
null
UTF-8
Scheme
false
false
743
scm
for-each-numbers.scm
(define (filter pred lis) (if (null? lis) lis (if (pred (car lis)) (cons (car lis) (filter pred (cdr lis))) (filter pred (cdr lis))))) (define (for-each-numbers proc lis) (for-each proc (filter number? lis))) (define (map-numbers proc lis) (map proc (filter number? lis))) (define (numbers-only walker) (lambda (proc lis) (walker proc (filter number? lis)))) (define (tree-walk walker proc tree) (walker (lambda (elt) (if (list? elt) (tree-walk walker proc elt) (proc elt))) tree)) (define (numbers-only-for-tree walker) (lambda (proc lis) (walker proc (tree-walk filter number? lis)))) (define (main args) (tree-walk (numbers-only-for-tree map) print '((1 2 3) a 39 (b 3 2))))
false
52be8e87c814840edd09e37005d8e46d713404d3
af3b4c56ca4b1b891cb10f08bd71555181f256d5
/round2/a2.ss
89c82ea1833237ba253f4b213fba01b4ae5f4bd6
[]
no_license
fangyuchen86/c311
7a9cd8b86072cc041b94e510faf33ff4c0075592
7da206f36922d876264f5f194a7a7dba789bde71
refs/heads/master
2020-12-28T21:39:56.087636
2014-12-05T06:17:21
2014-12-05T06:17:21
28,654,072
0
2
null
null
null
null
UTF-8
Scheme
false
false
639
ss
a2.ss
;; problem 1 ;; list-ref (define list-ref (lambda (ls n) (letrec ([nth-cdr (lambda (n) (cond [(zero? n) ls] [else (cdr (nth-cdr (sub1 n)))]))] ) (car (nth-cdr n))))) ;; problem 2 ;; union (define (union ls1 ls2) (letrec ([contains (lambda (e ls) (cond [(null? ls) #f] [(eq? e (car ls)) #t] [else (contains e (cdr ls))]))]) (cond [(null? ls1) ls2] [(contains (car ls1) ls2) (union (cdr ls1) ls2)] [else (union (cdr ls1) (cons (car ls1) ls2))]) ))
false
6e53e8731d873bcead73db06b941b00ace41a820
b9eb119317d72a6742dce6db5be8c1f78c7275ad
/autograms/scheme/v1/monitor.ss
3998ce287ac0d839a048901e2aa0da53e63e98b7
[]
no_license
offby1/doodles
be811b1004b262f69365d645a9ae837d87d7f707
316c4a0dedb8e4fde2da351a8de98a5725367901
refs/heads/master
2023-02-21T05:07:52.295903
2022-05-15T18:08:58
2022-05-15T18:08:58
512,608
2
1
null
2023-02-14T22:19:40
2010-02-11T04:24:52
Scheme
UTF-8
Scheme
false
false
2,999
ss
monitor.ss
#! /bin/sh #| Hey Emacs, this is -*-scheme-*- code! #$Id$ exec mzscheme -M errortrace -qu "$0" ${1+"$@"} |# #lang scheme ;; this seems overly complex. (provide monitor once-more-and-then-quit) (require (planet offby1/offby1/round) (planet neil/numspell:1:0/numspell) (lib "date.ss") "globals.ss") (define-struct sample (cpu-ms bytes-used unique-tries loop-passes) #:transparent) (define *the-samples* '()) (define (seconds->string s) (let* ((s (inexact->exact (round s))) (minutes (quotient s 60)) (hour (quotient minutes 60)) (day (quotient hour 24))) (format "~a days, ~a hours, ~a minutes, ~a seconds" day (remainder hour 24) (remainder minutes 60) (remainder s 60)))) (define *trigger-o-death* (make-semaphore 0)) (define (once-more-and-then-quit) (semaphore-post *trigger-o-death*)) (define (monitor max-tries) (parameterize ((current-output-port (current-error-port))) (let loop ((last-time? #f)) (collect-garbage) (let ((this-sample (make-sample (current-process-milliseconds) (current-memory-use *worker-custodian*) (*tries*) (*loop-passes*)))) (set! *the-samples* (cons this-sample *the-samples*)) (let* ((this-cpu-ms (sample-cpu-ms this-sample)) (current-tries (sample-unique-tries this-sample)) (this-bytes (sample-bytes-used this-sample)) (remaining-tries (- max-tries current-tries))) (nl) (printf "~a/~a tries/loops; ~a/~a bytes used (~a% done)" (number->english (my-round current-tries 2)) (number->english (my-round (sample-loop-passes this-sample) 2)) (number->english (round (my-round this-bytes 2))) (number->english *max-worker-mem*) (exact->inexact (my-round (/ (* 100 this-bytes) *max-worker-mem*) 2)) ) (when (not (null? (cdr *the-samples*))) (let* ((last-sample (cadr *the-samples*)) (delta-cpu-ms (max 1 (- this-cpu-ms (sample-cpu-ms last-sample)))) (delta-tries (max 1 (- current-tries (sample-unique-tries last-sample)))) (tries-per-cpu-second (/ (* 1000 delta-tries) delta-cpu-ms )) (delta-bytes (max 1 (- this-bytes (sample-bytes-used last-sample))))) (nl) (printf "~a tries per CPU second; ~a bytes per try" (number->english (round (my-round tries-per-cpu-second 2))) (number->english (round (my-round (/ delta-bytes delta-tries) 2)))) )) (printf "~%") (unless last-time? (loop (sync/timeout 3 *trigger-o-death*))))))))
false
b1ef6034331564333fbd2be058b8d4b06adda0c4
120324bbbf63c54de0b7f1ca48d5dcbbc5cfb193
/packages/gui/window.ss
32b7ef3bf0786496269985e1e4ff5e23ac8aadd6
[ "MIT" ]
permissive
evilbinary/scheme-lib
a6d42c7c4f37e684c123bff574816544132cb957
690352c118748413f9730838b001a03be9a6f18e
refs/heads/master
2022-06-22T06:16:56.203827
2022-06-16T05:54:54
2022-06-16T05:54:54
76,329,726
609
71
MIT
2022-06-16T05:54:55
2016-12-13T06:27:36
Scheme
UTF-8
Scheme
false
false
1,037
ss
window.ss
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;Copyright 2016-2080 evilbinary. ;;作者:evilbinary on 12/24/16. ;;邮箱:[email protected] ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (library (gui window) (export window-create window-destroy window-loop window-get-mouse-pos window-get-mouse-x window-get-mouse-y window-show-fps window-post-empty-event window-set-fps-pos window-add-loop window-loop-one window-set-wait-mode window-set-size window-set-title window-set-input-mode) (import (scheme) (glut glut)) (define-syntax import-platform-window (lambda (x) (syntax-case x () [(_ k) (datum->syntax #'k `(import (glut glut) ,(case (machine-type) [(arm32le) '(gui android-window)] [(a6nt i3nt ta6nt ti3nt a6osx i3osx ta6osx ti3osx a6le i3le ta6le ti3le) '(gui pc-window)])))]))) (import-platform-window window))
true
e5e5f76e95664a37e31b6e0be43323e9ba7b0533
b17836b5720d469d479ec398c97415b889dc6a89
/packrat-ext/packrat-utils.ss
df2e41b485f2cf1a704fc39416a24999a6995b9a
[ "MIT" ]
permissive
ChaosEternal/packrat-extended
1e35e230bb055ec236deea031d905739ac6b3f85
28ac35f51763b82c810ec63f4d53ccd8402e1284
refs/heads/master
2021-06-05T21:09:09.144876
2020-08-06T08:39:52
2020-08-06T08:39:52
94,386,932
1
0
null
null
null
null
UTF-8
Scheme
false
false
3,172
ss
packrat-utils.ss
;; Packrat Parser Library Extended ;; ;; Copyright (c) 2017 Chaos Eternal <[email protected]> ;; ;; Permission is hereby granted, free of charge, to any person ;; obtaining a copy of this software and associated documentation ;; files (the "Software"), to deal in the Software without ;; restriction, including without limitation the rights to use, copy, ;; modify, merge, publish, distribute, sublicense, and/or sell copies ;; of the Software, and to permit persons to whom the Software is ;; furnished to do so, subject to the following conditions: ;; ;; The above copyright notice and this permission notice shall be ;; included in all copies or substantial portions of the Software. ;; ;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ;; EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ;; MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ;; NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ;; BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ;; ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ;; CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ;; SOFTWARE. (library (packrat-ext packrat-utils) (export true inverse test-all test-any char-newline? char-valid-hex? jstring-body token ) (import (packrat-ext packrat) (rnrs)) (define (true . dummy) #t) (define (inverse l) (lambda (x) (not (l x)))) (define (test-all . pred) (lambda (c) (fold-left (lambda (r p) (and r (p c))) #t pred))) (define (test-any . pred) (lambda (c) (fold-left (lambda (r p) (or r (p c))) #f pred))) (define (char-newline? x) (memv x '(#\newline #\return))) (define char-valid-hex? (test-any char-numeric? (lambda (x) (and (char-ci<=? x #\F) (char-ci>=? x #\A))) (lambda (x) (and (char-ci<=? x #\f) (char-ci>=? x #\a))))) (define (a-char x) (lambda (y) (char=? x y))) (define (a-char-ci x) (lambda (y) (char-ci=? x y))) (define jstring-body (packrat-parser any (any ((c <- jstring-char s <- any) (cons c s)) ((c <- jstring-char) (cons c '()))) (jstring-char (((! '#\\) (! '#\") c <- (? true)) c) (('#\\ '#\n) #\newline) (('#\\ '#\b) #\backspace) (('#\\ '#\f) #\page) (('#\\ '#\r) #\return) (('#\\ '#\t) #\tab) (('#\\ '#\u a <- (? char-valid-hex?) b <- (? char-valid-hex?) c <- (? char-valid-hex?) d <- (? char-valid-hex?) ) (integer->char (string->number (list->string (list a b c d)) 16))) (('#\\ (! '#\u) c <- (? true)) c)))) (define (token str . comp?) (let ((cmp? (if (null? comp?) char=? comp?))) (lambda (starting-results) (let loop ((pos 0) (results starting-results)) (if (= pos (string-length str)) (make-result str results) (let ((res-token-value (parse-results-token-value results))) (if (and res-token-value (cmp? res-token-value (string-ref str pos))) (loop (+ pos 1) (parse-results-next results)) (make-expected-result (parse-results-position starting-results) str)))))))))
false
4d5e9e53fcaa010f38564d399f818545bd265463
f08220a13ec5095557a3132d563a152e718c412f
/logrotate/skel/usr/share/guile/2.0/rnrs/bytevectors.scm
9744359f03e98977e5060bc2ec5b2a8c43c384dc
[ "Apache-2.0" ]
permissive
sroettger/35c3ctf_chals
f9808c060da8bf2731e98b559babd4bf698244ac
3d64486e6adddb3a3f3d2c041242b88b50abdb8d
refs/heads/master
2020-04-16T07:02:50.739155
2020-01-15T13:50:29
2020-01-15T13:50:29
165,371,623
15
5
Apache-2.0
2020-01-18T11:19:05
2019-01-12T09:47:33
Python
UTF-8
Scheme
false
false
3,383
scm
bytevectors.scm
;;;; bytevectors.scm --- R6RS bytevector API -*- coding: utf-8 -*- ;;;; Copyright (C) 2009, 2010 Free Software Foundation, Inc. ;;;; ;;;; This library is free software; you can redistribute it and/or ;;;; modify it under the terms of the GNU Lesser General Public ;;;; License as published by the Free Software Foundation; either ;;;; version 3 of the License, or (at your option) any later version. ;;;; ;;;; This library is distributed in the hope that it will be useful, ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ;;;; Lesser General Public License for more details. ;;;; ;;;; You should have received a copy of the GNU Lesser General Public ;;;; License along with this library; if not, write to the Free Software ;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ;;; Author: Ludovic Courtès <[email protected]> ;;; Commentary: ;;; ;;; A "bytevector" is a raw bit string. This module provides procedures to ;;; manipulate bytevectors and interpret their contents in a number of ways: ;;; bytevector contents can be accessed as signed or unsigned integer of ;;; various sizes and endianness, as IEEE-754 floating point numbers, or as ;;; strings. It is a useful tool to decode binary data. ;;; ;;; Code: (define-module (rnrs bytevectors) #:version (6) #:export-syntax (endianness) #:export (native-endianness bytevector? make-bytevector bytevector-length bytevector=? bytevector-fill! bytevector-copy! bytevector-copy uniform-array->bytevector bytevector-u8-ref bytevector-s8-ref bytevector-u8-set! bytevector-s8-set! bytevector->u8-list u8-list->bytevector bytevector-uint-ref bytevector-uint-set! bytevector-sint-ref bytevector-sint-set! bytevector->sint-list bytevector->uint-list uint-list->bytevector sint-list->bytevector bytevector-u16-ref bytevector-s16-ref bytevector-u16-set! bytevector-s16-set! bytevector-u16-native-ref bytevector-s16-native-ref bytevector-u16-native-set! bytevector-s16-native-set! bytevector-u32-ref bytevector-s32-ref bytevector-u32-set! bytevector-s32-set! bytevector-u32-native-ref bytevector-s32-native-ref bytevector-u32-native-set! bytevector-s32-native-set! bytevector-u64-ref bytevector-s64-ref bytevector-u64-set! bytevector-s64-set! bytevector-u64-native-ref bytevector-s64-native-ref bytevector-u64-native-set! bytevector-s64-native-set! bytevector-ieee-single-ref bytevector-ieee-single-set! bytevector-ieee-single-native-ref bytevector-ieee-single-native-set! bytevector-ieee-double-ref bytevector-ieee-double-set! bytevector-ieee-double-native-ref bytevector-ieee-double-native-set! string->utf8 string->utf16 string->utf32 utf8->string utf16->string utf32->string)) (load-extension (string-append "libguile-" (effective-version)) "scm_init_bytevectors") (define-macro (endianness sym) (if (memq sym '(big little)) `(quote ,sym) (error "unsupported endianness" sym))) ;;; bytevector.scm ends here
false
bf7a9c84e371810f1172ac51efff3b7c0016a310
2c01a6143d8630044e3629f2ca8adf1455f25801
/scheme-tools/math/distributions.ss
488773f9e12d75d14b019d375a87324110b236f2
[]
no_license
stuhlmueller/scheme-tools
e103fac13cfcb6d45e54e4f27e409adbc0125fe1
6e82e873d29b34b0de69b768c5a0317446867b3c
refs/heads/master
2021-01-25T10:06:33.054510
2017-05-09T19:44:12
2017-05-09T19:44:12
1,092,490
5
1
null
null
null
null
UTF-8
Scheme
false
false
1,646
ss
distributions.ss
#!r6rs ;; A hashtable-based data structure for discrete log probability distributions (library (scheme-tools math distributions) (export make-empty-dist empty-dist? make-dist copy-dist dist-vals dist-ps dist-vals&ps sample-dist get-dist-prob set-dist-prob! dist-mass) (import (rnrs) (scheme-tools srfi-compat :1) (scheme-tools hashtable) (scheme-tools math math)) (define (make-empty-dist) (make-eq-hashtable)) (define (empty-dist? dist) (= (hashtable-size dist) 0)) (define (make-dist vals probs) (let ([dist (make-empty-dist)]) (vector-for-each (lambda (val prob) (hashtable-set! dist val prob)) vals probs) dist)) (define (dist-vals dist) (hashtable-keys dist)) (define (dist-ps dist) (hashtable-values dist)) (define (dist-vals&ps dist) (hashtable-entries dist)) (define (copy-dist dist) (let-values ([(vals ps) (dist-vals&ps dist)]) (make-dist vals ps))) (define (sample-dist dist) (assert (not (= (dist-mass dist) LOG-PROB-0))) (let-values ([(vals ps) (dist-vals&ps dist)]) (if (= (vector-length vals) 1) (vector-ref vals 0) (multinomial (vector->list vals) (map exp (vector->list ps)))))) (define (get-dist-prob dist val) (hashtable-ref dist val LOG-PROB-0)) (define (set-dist-prob! dist val p) (hashtable-set! dist val p)) (define (dist-mass dist) (if (empty-dist? dist) LOG-PROB-0 (apply logsumexp (vector->list (dist-ps dist))))) )
false
954ef46d17ec1c0eb60520f79fd90277b7a42063
923209816d56305004079b706d042d2fe5636b5a
/test/http/language-tag.scm
a5f18c5c1adb0aa9ff74eb2d3b7c13bf9860493a
[ "BSD-3-Clause", "BSD-2-Clause" ]
permissive
tabe/http
4144cb13451dc4d8b5790c42f285d5451c82f97a
ab01c6e9b4e17db9356161415263c5a8791444cf
refs/heads/master
2021-01-23T21:33:47.859949
2010-06-10T03:36:44
2010-06-10T03:36:44
674,308
1
0
null
null
null
null
UTF-8
Scheme
false
false
627
scm
language-tag.scm
#!r6rs (import (rnrs (6)) (http language-tag) (http assertion) (xunit)) (assert-parsing-successfully language-tag "en" `(,(string->list "en") ())) (assert-parsing-successfully language-tag "en-US" `(,(string->list "en") ((#\- ,(string->list "US"))))) (assert-parsing-successfully language-tag "en-cockney" `(,(string->list "en") ((#\- ,(string->list "cockney"))))) (assert-parsing-successfully language-tag "i-cherokee" `((#\i) ((#\- ,(string->list "cherokee"))))) (assert-parsing-successfully language-tag "x-pig-latin" `((#\x) ((#\- ,(string->list "pig")) (#\- ,(string->list "latin"))))) (report)
false
2c7a7c9a4f30588f89ff37e5ea0f96bac9568242
d6910224fa09f702ff00eda6d83ba0631dd36e13
/3-5.scm
73cd8cfe93a1cddb797b51e297d580a7a6dacf40
[]
no_license
jeffgyf/sicp_homework
786dd9f5eed315018279d79ad8a1c73662d9f4ce
f2564b06e19362af78206b51cd963ff34787a8e8
refs/heads/master
2020-04-12T14:17:03.342146
2019-05-06T05:54:27
2019-05-06T05:54:27
162,547,609
1
0
null
null
null
null
UTF-8
Scheme
false
false
939
scm
3-5.scm
;3.17 (define (count-pairs l) (define counted_list '()) (define (count l) (cond ((not (pair? l)) 0) ((memq l counted_list) 0) (else (set! counted_list (cons l counted_list)) (+ (count (car l)) (count (cdr l)) 1)))) (count l)) ;3.18 (define (cycle? l) (define checked_list '()) (define (check l) (cond ((null? l) #f) ((memq l checked_list) #t) (else (set! checked_list (cons (car l) checked_list)) (check (cdr l))))) (check l)) ;3.19初见杀面试问题 (define (cycle? l) (define (check p1 p2) (cond ((or (null? p2) (null? (cdr p2))) #f) ((eq? p1 p2) #t) (else (check (cdr p1) (cddr p2))))) (cond ((null? l) #f) (else (check l (cdr l)))))
false
44558fd9f01697332945157dce334c4d1e39d50a
382770f6aec95f307497cc958d4a5f24439988e6
/projecteuler/493/493.scm
031ddb9f382f03eca9782009a3f8122ef2fba31b
[ "Unlicense" ]
permissive
include-yy/awesome-scheme
602a16bed2a1c94acbd4ade90729aecb04a8b656
ebdf3786e54c5654166f841ba0248b3bc72a7c80
refs/heads/master
2023-07-12T19:04:48.879227
2021-08-24T04:31:46
2021-08-24T04:31:46
227,835,211
1
0
null
null
null
null
UTF-8
Scheme
false
false
4,004
scm
493.scm
(define fac (lambda (n) (cond ((< n 0) 0.0) ((= n 0) 1.0) ((= n 1) 1.0) (else (* n (fac (- n 1))))))) (define Com (lambda (m n) (cond ((or (< m 0) (< n 0)) 0) ((< m n) 0) ((= n 0) 1) (else (/ (fac m) (* (fac (- m n))(fac n))))))) (define gong (Com 70 20)) (define ratio-gong (lambda (n) (/ (Com 7 n) gong))) (define r2 (let ([tot 0.0]) (let f1 ([i1 1]) (cond ((> i1 10)) (else (let f2 ([i2 1]) (cond ((> i2 10) (f1 (+ i1 1))) ((= (+ i1 i2) 20) (set! tot (+ tot (* (Com 10 i1) (Com 10 i2)))) (f1 (+ i1 1))) (else (f2 (+ i2 1)))))))) (* (ratio-gong 2) tot))) (define r3 (let ([tot 0.0]) (let f1 ([i1 1]) (cond ((> i1 10)) (else (let f2 ([i2 1]) (cond ((> i2 10) (f1 (+ i1 1))) (else (let f3 ([i3 1]) (cond ((> i3 10) (f2 (+ i2 1))) ((= (+ i1 i2 i3) 20) (set! tot (+ tot (* (Com 10 i1) (Com 10 i2) (Com 10 i3)))) (f2 (+ i2 1))) (else (f3 (+ i3 1))))))))))) (* (ratio-gong 3) tot))) (define r4 (let ([tot 0.0]) (let f1 ([i1 1]) (cond ((> i1 10)) (else (let f2 ([i2 1]) (cond ((> i2 10) (f1 (+ i1 1))) (else (let f3 ([i3 1]) (cond ((> i3 10) (f2 (+ i2 1))) (else (let f4 ([i4 1]) (cond ((> i4 10) (f3 (+ i3 1))) ((= (+ i1 i2 i3 i4) 20) (set! tot (+ tot (* (Com 10 i1) (Com 10 i2) (Com 10 i3) (Com 10 i4)))) (f3 (+ i3 1))) (else (f4 (+ i4 1)))))))))))))) (* (ratio-gong 4) tot))) (define r5 (let ([tot 0.0]) (let f1 ([i1 1]) (cond ((> i1 10)) (else (let f2 ([i2 1]) (cond ((> i2 10) (f1 (+ i1 1))) (else (let f3 ([i3 1]) (cond ((> i3 10) (f2 (+ i2 1))) (else (let f4 ([i4 1]) (cond ((> i4 10) (f3 (+ i3 1))) (else (let f5 ([i5 1]) (cond ((> i5 10) (f4 (+ i4 1))) ((= (+ i1 i2 i3 i4 i5) 20) (set! tot (+ tot (* (Com 10 i1) (Com 10 i2) (Com 10 i3) (Com 10 i4) (Com 10 i5)))) (f4 (+ i4 1))) (else (f5 (+ i5 1))))))))))))))))) (* (ratio-gong 5) tot))) (define r6 (let ([tot 0.0]) (let f1 ([i1 1]) (cond ((> i1 10)) (else (let f2 ([i2 1]) (cond ((> i2 10) (f1 (+ i1 1))) (else (let f3 ([i3 1]) (cond ((> i3 10) (f2 (+ i2 1))) (else (let f4 ([i4 1]) (cond ((> i4 10) (f3 (+ i3 1))) (else (let f5 ([i5 1]) (cond ((> i5 10) (f4 (+ i4 1))) (else (let f6 ([i6 1]) (cond ((> i6 10) (f5 (+ i5 1))) ((= (+ i1 i2 i3 i4 i5 i6) 20) (set! tot (+ tot (* (Com 10 i1) (Com 10 i2) (Com 10 i3) (Com 10 i4) (Com 10 i5) (Com 10 i6)))) (f5 (+ i5 1))) (else (f6 (+ i6 1)))))))))))))))))))) (* (ratio-gong 6) tot))) (define r7 (let ([tot 0.0]) (let f1 ([i1 1]) (cond ((> i1 10)) (else (let f2 ([i2 1]) (cond ((> i2 10) (f1 (+ i1 1))) (else (let f3 ([i3 1]) (cond ((> i3 10) (f2 (+ i2 1))) (else (let f4 ([i4 1]) (cond ((> i4 10) (f3 (+ i3 1))) (else (let f5 ([i5 1]) (cond ((> i5 10) (f4 (+ i4 1))) (else (let f6 ([i6 1]) (cond ((> i6 10) (f5 (+ i5 1))) (else (let f7 ([i7 1]) (cond ((> i7 10) (f6 (+ i6 1))) ((= (+ i1 i2 i3 i4 i5 i6 i7) 20) (set! tot (+ tot (* (Com 10 i1) (Com 10 i2) (Com 10 i3) (Com 10 i4) (Com 10 i5) (Com 10 i6) (Com 10 i7)))) (f6 (+ i6 1))) (else (f7 (+ i7 1))))))))))))))))))))))) (* (ratio-gong 7) tot))) (+ (* 2 r2) (* 3 r3) (* 4 r4) (* 5 r5) (* 6 r6) (* 7 r7)) ;;6.8187418020197175 ;;ugly
false
97adc2f003317280bbcffb10abbf12866d759041
6b961ef37ff7018c8449d3fa05c04ffbda56582b
/bbn_cl/mach/zcomp/base/sets.scm
e1d3f119ce0b7b7d7fb0581f57ce78a982944d51
[]
no_license
tinysun212/bbn_cl
7589c5ac901fbec1b8a13f2bd60510b4b8a20263
89d88095fc2a71254e04e57cf499ae86abf98898
refs/heads/master
2021-01-10T02:35:18.357279
2015-05-26T02:44:00
2015-05-26T02:44:00
36,267,589
4
3
null
null
null
null
UTF-8
Scheme
false
false
5,233
scm
sets.scm
#| -*-Scheme-*- $Header: sets.scm,v 1.2 88/08/31 10:37:22 jinx Exp $ $MIT-Header: sets.scm,v 4.1 87/12/04 20:05:03 GMT cph Exp $ Copyright (c) 1987 Massachusetts Institute of Technology This material was developed by the Scheme project at the Massachusetts Institute of Technology, Department of Electrical Engineering and Computer Science. Permission to copy this software, to redistribute it, and to use it for any purpose is granted, subject to the following restrictions and understandings. 1. Any copy made of this software must include this copyright notice in full. 2. Users of this software agree to make their best efforts (a) to return to the MIT Scheme project any improvements or extensions that they make, so that these may be included in future releases; and (b) to inform MIT of noteworthy uses of this software. 3. All materials developed as a consequence of the use of this software shall duly acknowledge such use, in accordance with the usual standards of acknowledging credit in academic research. 4. MIT has made no warrantee or representation that the operation of this software will be error-free, and MIT is under no obligation to provide any services, by way of maintenance, update, or otherwise. 5. In conjunction with products arising from the use of this material, there shall be no use of the name of the Massachusetts Institute of Technology nor of any adaptation thereof in any advertising, promotional, or sales literature without prior written consent from MIT in each case. |# ;;;; Simple Set Abstraction (declare (usual-integrations)) (define (eq-set-adjoin element set) (if (memq element set) set (cons element set))) (define (eqv-set-adjoin element set) (if (memv element set) set (cons element set))) (define (eq-set-delete set item) (define (loop set) (cond ((null? set) '()) ((eq? (car set) item) (cdr set)) (else (cons (car set) (loop (cdr set)))))) (loop set)) (define (eqv-set-delete set item) (define (loop set) (cond ((null? set) '()) ((eqv? (car set) item) (cdr set)) (else (cons (car set) (loop (cdr set)))))) (loop set)) (define (eq-set-substitute set old new) (define (loop set) (cond ((null? set) '()) ((eq? (car set) old) (cons new (cdr set))) (else (cons (car set) (loop (cdr set)))))) (loop set)) (define (eqv-set-substitute set old new) (define (loop set) (cond ((null? set) '()) ((eqv? (car set) old) (cons new (cdr set))) (else (cons (car set) (loop (cdr set)))))) (loop set)) (define (set-search set procedure) (define (loop items) (and (not (null? items)) (or (procedure (car items)) (loop (cdr items))))) (loop set)) ;;; The dataflow analyzer assumes that ;;; (eq? (list-tail (eq-set-union x y) n) y) for some n. (define (eq-set-union x y) (if (null? y) x (let loop ((x x) (y y)) (if (null? x) y (loop (cdr x) (if (memq (car x) y) y (cons (car x) y))))))) (define (eqv-set-union x y) (if (null? y) x (let loop ((x x) (y y)) (if (null? x) y (loop (cdr x) (if (memv (car x) y) y (cons (car x) y))))))) (define (eq-set-difference x y) (define (loop x) (cond ((null? x) '()) ((memq (car x) y) (loop (cdr x))) (else (cons (car x) (loop (cdr x)))))) (loop x)) (define (eqv-set-difference x y) (define (loop x) (cond ((null? x) '()) ((memv (car x) y) (loop (cdr x))) (else (cons (car x) (loop (cdr x)))))) (loop x)) (define (eq-set-intersection x y) (define (loop x) (cond ((null? x) '()) ((memq (car x) y) (cons (car x) (loop (cdr x)))) (else (loop (cdr x))))) (loop x)) (define (eqv-set-intersection x y) (define (loop x) (cond ((null? x) '()) ((memv (car x) y) (cons (car x) (loop (cdr x)))) (else (loop (cdr x))))) (loop x)) (define (eq-set-disjoint? x y) (define (loop x) (cond ((null? x) true) ((memq (car x) y) false) (else (loop (cdr x))))) (loop x)) (define (eqv-set-disjoint? x y) (define (loop x) (cond ((null? x) true) ((memv (car x) y) false) (else (loop (cdr x))))) (loop x)) (define (eq-set-subset? x y) (define (loop x) (cond ((null? x) true) ((memq (car x) y) (loop (cdr x))) (else false))) (loop x)) (define (eqv-set-subset? x y) (define (loop x) (cond ((null? x) true) ((memv (car x) y) (loop (cdr x))) (else false))) (loop x)) (define (eq-set-same-set? x y) (and (eq-set-subset? x y) (eq-set-subset? y x))) (define (eqv-set-same-set? x y) (and (eqv-set-subset? x y) (eqv-set-subset? y x))) (define (list->eq-set elements) (if (null? elements) '() (eq-set-adjoin (car elements) (list->eq-set (cdr elements))))) (define (list->eqv-set elements) (if (null? elements) '() (eqv-set-adjoin (car elements) (list->eqv-set (cdr elements))))) (define (map->eq-set procedure items) (let loop ((items items)) (if (null? items) '() (eq-set-adjoin (procedure (car items)) (loop (cdr items)))))) (define (map->eqv-set procedure items) (let loop ((items items)) (if (null? items) '() (eqv-set-adjoin (procedure (car items)) (loop (cdr items))))))
false
c100d96ac2dad047a423d449a3917dff686b8754
7168cedb23c0a8f2b81419507dab5e87436821f8
/16.ReadingSetBang.scm
98f231594553a41e7222be8cd9dc6b21a397d030
[]
no_license
valvallow/TheSeasonedSchemer
9b6f50706c473a40af0ed20f1b9bd880538e96ad
d36b57e8eb14389015e51841957428ecc8aaa5db
refs/heads/master
2020-05-04T20:06:52.902979
2010-05-10T12:12:15
2010-05-10T12:12:15
511,208
1
1
null
null
null
null
UTF-8
Scheme
false
false
7,594
scm
16.ReadingSetBang.scm
;; chapter.16 (define sweet-tooth (lambda (food) (cons food (cons (quote cake) (quote ()))))) (define last (quote angelfood)) (sweet-tooth (quote chocolate)) ; -> (chocolate cake) last ; -> angelfood (sweet-tooth (quote fruit)) ; -> (fruit cake) last ; -> angelfood (define sweet-toothL (lambda (food) (set! last food) (cons food (cons (quote cake) (quote ()))))) (sweet-toothL (quote chocolate)) ; -> (chocolate cake) last ; -> chocolate (sweet-toothL (quote fruit)) ; -> (fruit cake) last ; -> fruit (sweet-toothL (quote cheese)) ; -> (cheese cake) (sweet-toothL (quote carrot)) ; -> (carrot cake) (define ingredients (quote ())) (define sweet-toothR (lambda (food) (set! ingredients (cons food ingredients)) (cons food (cons (quote cake) (quote ()))))) (sweet-toothR (quote chocolate)) ; -> (chocolate cake) ingredients ; -> (chocolate) (sweet-toothR (quote fruit)) ; -> (fruit cake) ingredients ; -> (fruit chocolate) (sweet-toothR (quote cheese)) ; -> (cheese cake) ingredients ; -> (cheese fruit chocolate) (sweet-toothR (quote cheese)) ; -> (cheese cake) ingredients ; -> (cheese cheese fruit chocolate) ;; deep ;; (deep 3) ;; -> (((pizza))) ;; (deep 7) ;; -> (((((((pizza))))))) ;; (deep 0) ;; -> pizza (define (deep n) (if (zero? n) 'pizza (cons (deep (- n 1)) '()))) (deep 3) ; -> (((pizza))) ;; again letrec (define (make-deep a) (lambda (n) (letrec ((d (lambda (n) (if (zero? n) a (cons (d (- n 1)) '()))))) (d n)))) ((make-deep 'pizza) 3) ; -> (((pizza))) ;; again named-let, accumulate (define (make-deep a) (lambda (n) (let loop ((n n) (acc a)) (if (zero? n) acc (loop (- n 1) (cons acc '())))))) ((make-deep 'pizza) 3) ; -> (((pizza))) ;; again fold-right (use srfi-1) (define (make-deep a) (lambda (n) (fold-right (lambda (e acc) (if (zero? e) acc (cons acc '()))) a (iota (+ n 1))))) ((make-deep 'pizza) 5) ; -> (((((pizza))))) ;; The Seasoned Schemer (define sub1 (lambda (n) (- n 1))) (define deep (lambda (n) (cond ((zero? n)(quote pizza)) (else (cons (deep (sub1 n)) (quote ())))))) (deep 3) ; -> (((pizza))) ;; Ns, Rs (define Ns (quote ())) (define deepR (lambda (n) (set! Ns (cons n Ns)) (deep n))) (deepR 3) ; -> (((pizza))) Ns ; -> (3) (define Rs (quote ())) (define Ns (quote ())) (define deepR (lambda (n) (set! Rs (cons (deep n) Rs)) (set! Ns (cons n Ns)) (deep n))) (deepR 3) ; -> (((pizza))) Ns ; -> (3) Rs ; -> ((((pizza)))) (deepR 5) ; -> (((((pizza))))) Ns ; -> (5 3) Rs ; -> ((((((pizza))))) (((pizza)))) (deepR 3) ; -> (((pizza))) Ns ; -> (3 5 3) Rs ; -> ((((pizza))) (((((pizza))))) (((pizza)))) ;; ((((pizza))) ;; (((((pizza))))) ;; (((pizza)))) ;; find ;; (find 3 Ns Rs) ;; -> (((pizza))) ;; (find 5 Ns Rs) ;; -> (((((pizza))))) (define (find n ns rs) (cond ((or (null? ns) (null? rs)) #f) ((= n (car ns))(car rs)) (else (find (- n 1)(cdr ns)(cdr rs))))) (find 3 Ns Rs) ; -> (((pizza))) ;; The Seasoned Schemer (define find (lambda (n Ns Rs) (letrec ((A (lambda (ns rs) (cond ((= (car ns) n)(car rs)) (else (A (cdr ns)(cdr rs))))))) (A Ns Rs)))) (find 5 Ns Rs) ; -> (((((pizza))))) ;; deepM (define (member? a lat) (let/cc skip (fold (lambda (e acc) (if (eq? e a) (skip #t) acc)) #f lat))) (member? 1 '(a b c)) ; -> #f (member? 'c '(a b c d e)) ; -> #t (define deepM (lambda (n) (if (member? n Ns) (find n Ns Rs) (deepR n)))) Ns ; -> (3 5 3) Rs ; -> ((((pizza))) (((((pizza))))) (((pizza)))) (set! Ns (cdr Ns)) (set! Rs (cdr Rs)) Ns ; -> (5 3) Rs ; -> ((((((pizza))))) (((pizza)))) (define deepM (lambda (n) (if (member? n Ns) (find n Ns Rs) (let ((result (deep n))) (set! Rs (cons result Rs)) (set! Ns (cons n Ns)) result)))) ; (deep 6) -> (cons (deep 5)(quote ())) (define deep (lambda (m) (cond ((zero? m)(quote pizza)) (else (cons (deepM (sub1 m)) (quote ())))))) (deep 6) ; -> ((((((pizza)))))) Ns ; -> (5 3) (deep 9) ; -> (((((((((pizza))))))))) Ns ; -> (8 7 6 5 3) (define deepM (let ((Rs (quote ())) (Ns (quote ()))) (lambda (n) (if (member? n Ns) (find n Ns Rs) (let ((result (deep n))) (set! Rs (cons result Rs)) (set! Ns (cons n Ns)) result))))) (deepM 16) ; -> ((((((((((((((((pizza)))))))))))))))) (define find (lambda (n Ns Rs) (letrec ((A (lambda (ns rs) (cond ((null? ns) #f) ((= (car ns) n)(car rs)) (else (A (cdr ns)(cdr rs))))))) (A Ns Rs)))) (define (atom? a) (and (not (pair? a)) (not (null? a)))) (define deepM (let ((Rs (quote ())) (Ns (quote ()))) (lambda (n) (if (atom? (find n Ns Rs)) (let ((result (deep n))) (set! Rs (cons result Rs)) (set! Ns (cons n Ns)) result) (find n Ns Rs))))) (define deepM (let ((Rs (quote ())) (Ns (quote ()))) (lambda (n) (let ((exists (find n Ns Rs))) (if (atom? exists) (let ((result (deep n))) (set! Rs (cons result Rs)) (set! Ns (cons n Ns)) result) exists))))) ;; length (define add1 (lambda (n) (+ n 1))) (define length (lambda (l) (cond ((null? l) 0) (else (add1 (length (cdr l))))))) (define length (lambda (l) 0)) (set! length (lambda (l) (cond ((null? l) 0) (else (add1 (length (cdr l))))))) (define length (let ((h (lambda (l) 0))) (set! h (lambda (l) (cond ((null? l) 0) (else (add1 (h (cdr l))))))) h)) (length '(1 2 3)) ; -> 3 ; ? (define length (let ((h #f)) (set! h (lambda (l) (if (null? l) 0 (add1 (h (cdr l)))))))) (length '(1 2 3 4 5)) ; -> 5 (define L (lambda (length) (lambda (l) (cond ((null? l) 0) (else (add1 (length (cdr l)))))))) (define length (let ((h (lambda (l) 0))) (set! h (L (lambda (arg) (h arg)))))) ;; Y! (define Y! (lambda (L) (let ((h (lambda (l) (quote ())))) (set! h (L (lambda (arg) (h arg)))) h))) (define Y-bang (lambda (f) (letrec ((h (f (lambda (arg) (h arg))))) h))) ((Y! L) '(1 2 3)) ; -> 3 ;; D (define D (lambda (depth*) (lambda (s) (cond ((null? s) 1) ((atom? (car s)) (depth* (cdr s))) (else (max (add1 (depth* (car s))) (depth* (cdr s)))))))) (define depth* (Y! D)) (depth* '(1 (2 (3 (4 (5 (6 (7 (8))))))))) ; -> 8 ;; biz (define biz (lambda (f) (let ((x 0)) (set! x (add1 x)) (lambda (a) (if (= a x) 0 (f a)))))) (define (biz f) (let ((x 0)) (set! x (add1 x)) (lambda (a) (if (= a x) 0 (f a)))))
false
92d8d495b1f5d087338b37d35759915d4c5224c4
8a0660bd8d588f94aa429050bb8d32c9cd4290d5
/sitelib/srfi/%3a78/lightweight-testing.scm
00330b27dac6238afcf6adf3ea2cf29c9dbd7e35
[ "BSD-2-Clause" ]
permissive
david135/sagittarius-scheme
dbec76f6b227f79713169985fc16ce763c889472
2fbd9d153c82e2aa342bfddd59ed54d43c5a7506
refs/heads/master
2016-09-02T02:44:31.668025
2013-12-21T07:24:08
2013-12-21T07:24:08
32,497,456
0
0
null
null
null
null
UTF-8
Scheme
false
false
11,899
scm
lightweight-testing.scm
;;;Copyright (c) 2008-2010 Derick Eddington. All rights reserved. ;;;Modified for Sagittarius Scheme by Marco Maggi. ;;; ;;;Permission is hereby granted, free of charge, to any person obtaining ;;;a copy of this software and associated documentation files (the ;;;"Software"), to deal in the Software without restriction, including ;;;without limitation the rights to use, copy, modify, merge, publish, ;;;distribute, sublicense, and/or sell copies of the Software, and to ;;;permit persons to whom the Software is furnished to do so, subject to ;;;the following conditions: ;;; ;;;The above copyright notice and this permission notice shall be ;;;included in all copies or substantial portions of the Software. ;;; ;;;Except as contained in this notice, the name(s) of the above ;;;copyright holders shall not be used in advertising or otherwise to ;;;promote the sale, use or other dealings in this Software without ;;;prior written authorization. ;;; ;;;THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ;;;EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ;;;MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ;;;NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ;;;BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ;;;ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ;;;CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ;;;SOFTWARE. ;;;Copyright (c) 2005-2006 Sebastian Egner. ;;; ;;;Permission is hereby granted, free of charge, to any person obtaining ;;;a copy of this software and associated documentation files (the ;;;``Software''), to deal in the Software without restriction, including ;;;without limitation the rights to use, copy, modify, merge, publish, ;;;distribute, sublicense, and/or sell copies of the Software, and to ;;;permit persons to whom the Software is furnished to do so, subject to ;;;the following conditions: ;;; ;;;The above copyright notice and this permission notice shall be ;;;included in all copies or substantial portions of the Software. ;;; ;;;THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, ;;;EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ;;;MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ;;;NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ;;;BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ;;;ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ;;;CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ;;;SOFTWARE. ;;; ;;;--------------------------------------------------------------------- ;;; ;;;Lightweight testing (reference implementation) ;;;============================================== ;;; ;;;[email protected] ;;;in R5RS + SRFI 23 (error) + SRFI 42 (comprehensions) ;;; ;;;history of this file: ;;; SE, 25-Oct-2004: first version based on code used in SRFIs 42 and 67 ;;; SE, 19-Jan-2006: (arg ...) made optional in check-ec ;;; ;;;Naming convention "check:<identifier>" is used only internally. ;;; ;;#!r6rs ;; for Sagittarius we can't use #!r6rs notation #!compatible (library (srfi :78 lightweight-testing) (export check check-ec check-report check-set-mode! check-reset! check-passed?) (import (rnrs) (srfi :39 parameters) (srfi :42 eager-comprehensions) (rename (pp) (pretty-print check:write))) #;(define-syntax check:mode (identifier-syntax (_ (check:mode-param)) ((set! _ expr) (check:mode-param expr)))) (define check:mode-param (make-parameter #F)) (define (print/header/padded x header padding) (define (print/lines) (let* ((str (call-with-string-output-port (lambda (sop) (check:write x sop)))) (sip (open-string-input-port str))) (let loop ((lines '())) (let ((l (get-line sip))) (if (eof-object? l) (reverse lines) (loop (cons l lines))))))) (let ((lines (print/lines))) (display header) (display (car lines)) (let loop ((lines (cdr lines))) (unless (null? lines) (newline) (display padding) (display (car lines)) (loop (cdr lines)))))) ; You can also use a pretty printer if you have one. ; However, the output might not improve for most cases ; because the pretty printers usually output a trailing ; newline. ; PLT. (require (lib "pretty.ss")) (define check:write pretty-print) ; Scheme48. ,open pp (define check:write p) ; -- mode -- (define check:mode #f) (define (check-set-mode! md) (set! check:mode (case md ((off) 0) ((summary) 1) ((report-failed) 10) ((report) 100) (else (error "unrecognized mode" md))))) ; -- state -- (define check:correct #f) (define check:failed #f) (define (check-reset!) (set! check:correct 0) (set! check:failed '())) (define (check:add-correct!) (set! check:correct (+ check:correct 1))) (define (check:add-failed! expression actual-result expected-result pred) (set! check:failed (cons (list expression actual-result expected-result pred) check:failed))) ; -- reporting -- (define (check:report-expression expression pred) (newline) (check:write expression) (if pred (begin (print/header/padded pred "(=> " " ") (display ")")) (display "=>")) (newline)) (define (check:report-actual-result actual-result) (check:write actual-result) (display ";; ")) (define (check:report-correct cases) (display "correct") (if (not (= cases 1)) (begin (display " (") (display cases) (display " cases checked)"))) (newline)) (define (check:report-failed expected-result) (display "*** failed ***") (newline) (print/header/padded expected-result ";; expected result. " ";; ") (newline)) (define (check-report) (if (>= check:mode 1) (begin (newline) (display ";; *** checks *** . ") (display check:correct) (display " correct, ") (display (length check:failed)) (display " failed.") (if (or (null? check:failed) (<= check:mode 1)) (newline) (let* ((w (car (reverse check:failed))) (expression (car w)) (actual-result (cadr w)) (expected-result (caddr w)) (pred (cadddr w))) (display " First failed example.") (newline) (check:report-expression expression pred) (check:report-actual-result actual-result) (check:report-failed expected-result)))))) (define (check-passed? expected-total-count) (and (= (length check:failed) 0) (= check:correct expected-total-count))) ; -- simple checks -- (define (check:proc expression thunk equal equal-expr expected-result) (define equal-expr* (and (not (eq? equal? equal)) equal-expr)) (case check:mode ((0) #f) ((1) (let ((actual-result (thunk))) (if (equal actual-result expected-result) (check:add-correct!) (check:add-failed! expression actual-result expected-result equal-expr*)))) ((10) (let ((actual-result (thunk))) (if (equal actual-result expected-result) (check:add-correct!) (begin (check:report-expression expression equal-expr*) (check:report-actual-result actual-result) (check:report-failed expected-result) (check:add-failed! expression actual-result expected-result equal-expr*))))) ((100) (check:report-expression expression equal-expr*) (let ((actual-result (thunk))) (check:report-actual-result actual-result) (if (equal actual-result expected-result) (begin (check:report-correct 1) (check:add-correct!)) (begin (check:report-failed expected-result) (check:add-failed! expression actual-result expected-result equal-expr*))))) (else (error "unrecognized check:mode" check:mode))) (if #f #f)) (define-syntax check (syntax-rules (=>) ((check expr => expected) (check expr (=> equal?) expected)) ((check expr (=> equal) expected) (if (>= check:mode 1) (check:proc 'expr (lambda () #F expr) equal 'equal expected))))) ; -- parametric checks -- (define (check:proc-ec w) (let ((correct? (car w)) (expression (cadr w)) (actual-result (caddr w)) (expected-result (cadddr w)) (cases (car (cddddr w))) (equal-expr (cadr (cddddr w)))) (if correct? (begin (if (>= check:mode 100) (begin (check:report-expression expression equal-expr) (check:report-actual-result actual-result) (check:report-correct cases))) (check:add-correct!)) (begin (if (>= check:mode 10) (begin (check:report-expression expression equal-expr) (check:report-actual-result actual-result) (check:report-failed expected-result))) (check:add-failed! expression actual-result expected-result equal-expr))))) (define-syntax check-ec.make (syntax-rules (=>) ((check-ec.make qualifiers expr (=> equal) expected (arg ...)) (if (>= check:mode 1) (check:proc-ec (let* ((cases 0) (eq-p equal) (equal-expr (and (not (eq? equal? eq-p)) 'equal))) (let ((w (first-ec #f qualifiers (:let equal-pred eq-p) (:let expected-result expected) (:let actual-result (let ((arg arg) ...) ; (*) expr)) (begin (set! cases (+ cases 1))) (if (not (equal-pred actual-result expected-result))) (list (list 'let (list (list 'arg arg) ...) 'expr) actual-result expected-result cases equal-expr)))) (if w (cons #f w) (list #t '(check-ec qualifiers expr (=> equal) expected (arg ...)) (if #f #f) (if #f #f) cases equal-expr))))))))) ; (*) is a compile-time check that (arg ...) is a list ; of pairwise disjoint bound variables at this point. (define-syntax check-ec (syntax-rules (nested =>) ((check-ec expr => expected) (check-ec.make (nested) expr (=> equal?) expected ())) ((check-ec expr (=> equal) expected) (check-ec.make (nested) expr (=> equal) expected ())) ((check-ec expr => expected (arg ...)) (check-ec.make (nested) expr (=> equal?) expected (arg ...))) ((check-ec expr (=> equal) expected (arg ...)) (check-ec.make (nested) expr (=> equal) expected (arg ...))) ((check-ec qualifiers expr => expected) (check-ec.make qualifiers expr (=> equal?) expected ())) ((check-ec qualifiers expr (=> equal) expected) (check-ec.make qualifiers expr (=> equal) expected ())) ((check-ec qualifiers expr => expected (arg ...)) (check-ec.make qualifiers expr (=> equal?) expected (arg ...))) ((check-ec qualifiers expr (=> equal) expected (arg ...)) (check-ec.make qualifiers expr (=> equal) expected (arg ...))) ((check-ec (nested q1 ...) q etc ...) (check-ec (nested q1 ... q) etc ...)) ((check-ec q1 q2 etc ...) (check-ec (nested q1 q2) etc ...)))) (check-set-mode! 'report) (check-reset!) ;;; end of file ) ;;; end of file
true
87e6ca4ff1f51d21c95e72841bdfa3793e79bfc9
b7f6929575ae60469e07b132f8bc843922e16abd
/examples/native/string.sch
d80a5ea3c97e7bcdcd609fd731d90e1c93fb1724
[ "MIT" ]
permissive
shima3/sch-script
2136048cdcb0e9ec42b228819447a3a9859a73b3
fa1e8ec5ee161a8b5702af68cc3d7ecd5376378b
refs/heads/master
2021-01-23T06:20:59.407358
2020-08-04T15:43:18
2020-08-04T15:43:18
86,357,889
0
0
null
null
null
null
UTF-8
Scheme
false
false
701
sch
string.sch
(defineCPS substring/shared ^(s start end) start ^(start) end ^(end) (lambda(s start end) (substring/shared s start end) ) s start end) (defineCPS string_tokenize ^($s) (lambda(s) (string-tokenize s) ) $s) (defineCPS string-ref ^(s idx) idx ^(idx) (lambda(S Idx) (string-ref S Idx) ) s idx) (defineCPS string-length ^(s) (lambda(S) (string-length S) ) s) ( defineCPS makeString ^(len) len ^(len) (lambda (len)(make-string len)) len ) ( defineCPS stringSet! ^(str index char . return) index ^(index) (lambda (S I C)(string-set! S I C)) str index char ^(dummy) return ) ( defineCPS stringToNumber ^(str) (lambda (str)(string->number str)) str )
false
4be8b04db9d04c51eeecf2172a96c65755e94964
2c01a6143d8630044e3629f2ca8adf1455f25801
/xitomatl/rnrs-restricted.sls
e1e500cdc5ba4434f08bdd3ab4ac5fb527c347f3
[ "X11-distribute-modifications-variant" ]
permissive
stuhlmueller/scheme-tools
e103fac13cfcb6d45e54e4f27e409adbc0125fe1
6e82e873d29b34b0de69b768c5a0317446867b3c
refs/heads/master
2021-01-25T10:06:33.054510
2017-05-09T19:44:12
2017-05-09T19:44:12
1,092,490
5
1
null
null
null
null
UTF-8
Scheme
false
false
11,825
sls
rnrs-restricted.sls
#!r6rs ;; Copyright 2009 Derick Eddington. My MIT-style license is in the file named ;; LICENSE from the original collection this file is distributed with. (library (xitomatl rnrs-restricted) ;; This library is intended to be used as the language / main import of ;; untrusted source-code. It does not provide: any file-system related ;; procedures; any procedures which by default use the ;; current-{input,output,error}-port; procedures which reveal record ;; constructor descriptors or record type descriptors. ;; ;; NOTE: Using this language can not prevent excessive memory or CPU usage. ;; Doing that requires using additional OS/system infrastructure. ;; ;; QUESTION: Should call-with-current-continuation and call/cc be excluded ;; as well? ;; ;; NOTE: There could still be security issues, like do exceptions reveal too ;; much info or grant access to an object the untrusted code shouldn't get? (export &assertion &condition &error &i/o &i/o-decoding &i/o-encoding #;&i/o-file-already-exists #;&i/o-file-does-not-exist #;&i/o-file-is-read-only #;&i/o-file-protection #;&i/o-filename &i/o-invalid-position &i/o-port &i/o-read &i/o-write &implementation-restriction &irritants &lexical &message &no-infinities &no-nans &non-continuable &serious &syntax &undefined &violation &warning &who * + - ... / < <= = => > >= _ abs acos and angle append apply asin assert assertion-violation assertion-violation? assoc assp assq assv atan begin binary-port? bitwise-and bitwise-arithmetic-shift bitwise-arithmetic-shift-left bitwise-arithmetic-shift-right bitwise-bit-count bitwise-bit-field bitwise-bit-set? bitwise-copy-bit bitwise-copy-bit-field bitwise-first-bit-set bitwise-if bitwise-ior bitwise-length bitwise-not bitwise-reverse-bit-field bitwise-rotate-bit-field bitwise-xor boolean=? boolean? bound-identifier=? #;buffer-mode #;buffer-mode? bytevector->sint-list bytevector->string bytevector->u8-list bytevector->uint-list bytevector-copy bytevector-copy! bytevector-fill! bytevector-ieee-double-native-ref bytevector-ieee-double-native-set! bytevector-ieee-double-ref bytevector-ieee-double-set! bytevector-ieee-single-native-ref bytevector-ieee-single-native-set! bytevector-ieee-single-ref bytevector-ieee-single-set! bytevector-length bytevector-s16-native-ref bytevector-s16-native-set! bytevector-s16-ref bytevector-s16-set! bytevector-s32-native-ref bytevector-s32-native-set! bytevector-s32-ref bytevector-s32-set! bytevector-s64-native-ref bytevector-s64-native-set! bytevector-s64-ref bytevector-s64-set! bytevector-s8-ref bytevector-s8-set! bytevector-sint-ref bytevector-sint-set! bytevector-u16-native-ref bytevector-u16-native-set! bytevector-u16-ref bytevector-u16-set! bytevector-u32-native-ref bytevector-u32-native-set! bytevector-u32-ref bytevector-u32-set! bytevector-u64-native-ref bytevector-u64-native-set! bytevector-u64-ref bytevector-u64-set! bytevector-u8-ref bytevector-u8-set! bytevector-uint-ref bytevector-uint-set! bytevector=? bytevector? caaaar caaadr caaar caadar caaddr caadr caar cadaar cadadr cadar caddar cadddr caddr cadr call-with-bytevector-output-port call-with-current-continuation #;call-with-input-file #;call-with-output-file call-with-port call-with-string-output-port call-with-values call/cc car case case-lambda cdaaar cdaadr cdaar cdadar cdaddr cdadr cdar cddaar cddadr cddar cdddar cddddr cdddr cddr cdr ceiling char->integer char-alphabetic? char-ci<=? char-ci<? char-ci=? char-ci>=? char-ci>? char-downcase char-foldcase char-general-category char-lower-case? char-numeric? char-title-case? char-titlecase char-upcase char-upper-case? char-whitespace? char<=? char<? char=? char>=? char>? char? close-input-port close-output-port close-port command-line complex? cond condition condition-accessor condition-irritants condition-message condition-predicate condition-who condition? cons cons* cos #;current-error-port #;current-input-port #;current-output-port datum->syntax define define-condition-type define-enumeration define-record-type define-syntax #;delete-file denominator #;display div div-and-mod div0 div0-and-mod0 do dynamic-wind else endianness enum-set->list enum-set-complement enum-set-constructor enum-set-difference enum-set-indexer enum-set-intersection enum-set-member? enum-set-projection enum-set-subset? enum-set-union enum-set-universe enum-set=? eof-object eof-object? eol-style eq? equal-hash equal? eqv? error error-handling-mode error? even? exact exact-integer-sqrt exact? exists exit exp expt fields #;file-exists? #;file-options filter find finite? fixnum->flonum fixnum-width fixnum? fl* fl+ fl- fl/ fl<=? fl<? fl=? fl>=? fl>? flabs flacos flasin flatan flceiling flcos fldenominator fldiv fldiv-and-mod fldiv0 fldiv0-and-mod0 fleven? flexp flexpt flfinite? flfloor flinfinite? flinteger? fllog flmax flmin flmod flmod0 flnan? flnegative? flnumerator flodd? flonum? floor flpositive? flround flsin flsqrt fltan fltruncate flush-output-port flzero? fold-left fold-right for-all for-each free-identifier=? fx* fx*/carry fx+ fx+/carry fx- fx-/carry fx<=? fx<? fx=? fx>=? fx>? fxand fxarithmetic-shift fxarithmetic-shift-left fxarithmetic-shift-right fxbit-count fxbit-field fxbit-set? fxcopy-bit fxcopy-bit-field fxdiv fxdiv-and-mod fxdiv0 fxdiv0-and-mod0 fxeven? fxfirst-bit-set fxif fxior fxlength fxmax fxmin fxmod fxmod0 fxnegative? fxnot fxodd? fxpositive? fxreverse-bit-field fxrotate-bit-field fxxor fxzero? gcd generate-temporaries get-bytevector-all get-bytevector-n get-bytevector-n! get-bytevector-some get-char get-datum get-line get-string-all get-string-n get-string-n! get-u8 greatest-fixnum guard hashtable-clear! hashtable-contains? hashtable-copy hashtable-delete! hashtable-entries hashtable-equivalence-function hashtable-hash-function hashtable-keys hashtable-mutable? hashtable-ref hashtable-set! hashtable-size hashtable-update! hashtable? i/o-decoding-error? i/o-encoding-error-char i/o-encoding-error? #;i/o-error-filename i/o-error-port i/o-error-position i/o-error? #;i/o-file-already-exists-error? #;i/o-file-does-not-exist-error? #;i/o-file-is-read-only-error? #;i/o-file-protection-error? #;i/o-filename-error? i/o-invalid-position-error? i/o-port-error? i/o-read-error? i/o-write-error? identifier-syntax identifier? if imag-part implementation-restriction-violation? immutable inexact inexact? infinite? input-port? integer->char integer-valued? integer? irritants-condition? lambda latin-1-codec lcm least-fixnum length let let* let*-values let-syntax let-values letrec letrec* letrec-syntax lexical-violation? list list->string list->vector list-ref list-sort list-tail list? log lookahead-char lookahead-u8 magnitude make-assertion-violation make-bytevector make-custom-binary-input-port make-custom-binary-input/output-port make-custom-binary-output-port make-custom-textual-input-port make-custom-textual-input/output-port make-custom-textual-output-port make-enumeration make-eq-hashtable make-eqv-hashtable make-error make-hashtable make-i/o-decoding-error make-i/o-encoding-error make-i/o-error #;make-i/o-file-already-exists-error #;make-i/o-file-does-not-exist-error #;make-i/o-file-is-read-only-error #;make-i/o-file-protection-error #;make-i/o-filename-error make-i/o-invalid-position-error make-i/o-port-error make-i/o-read-error make-i/o-write-error make-implementation-restriction-violation make-irritants-condition make-lexical-violation make-message-condition make-no-infinities-violation make-no-nans-violation make-non-continuable-violation make-polar make-record-constructor-descriptor make-record-type-descriptor make-rectangular make-serious-condition make-string make-syntax-violation make-transcoder make-undefined-violation make-variable-transformer make-vector make-violation make-warning make-who-condition map max member memp memq memv message-condition? min mod mod0 mutable nan? native-endianness native-eol-style native-transcoder negative? #;newline no-infinities-violation? no-nans-violation? non-continuable-violation? nongenerative not null? number->string number? numerator odd? opaque open-bytevector-input-port open-bytevector-output-port #;open-file-input-port #;open-file-input/output-port #;open-file-output-port #;open-input-file #;open-output-file open-string-input-port open-string-output-port or output-port-buffer-mode output-port? pair? parent parent-rtd partition #;peek-char port-eof? port-has-port-position? port-has-set-port-position!? port-position port-transcoder port? positive? procedure? protocol put-bytevector put-char put-datum put-string put-u8 quasiquote quasisyntax quote raise raise-continuable rational-valued? rational? rationalize #;read #;read-char real->flonum real-part real-valued? real? record-accessor record-constructor #;record-constructor-descriptor record-field-mutable? record-mutator record-predicate #;record-rtd #;record-type-descriptor record-type-descriptor? record-type-field-names record-type-generative? record-type-name record-type-opaque? record-type-parent record-type-sealed? record-type-uid record? remove remp remq remv reverse round serious-condition? sealed set! set-port-position! simple-conditions sin sint-list->bytevector sqrt #;standard-error-port #;standard-input-port #;standard-output-port string string->bytevector string->list string->number string->symbol string->utf16 string->utf32 string->utf8 string-append string-ci-hash string-ci<=? string-ci<? string-ci=? string-ci>=? string-ci>? string-copy string-downcase string-foldcase string-for-each string-hash string-length string-normalize-nfc string-normalize-nfd string-normalize-nfkc string-normalize-nfkd string-ref string-titlecase string-upcase string<=? string<? string=? string>=? string>? string? substring symbol->string symbol-hash symbol=? symbol? syntax syntax->datum syntax-case syntax-rules syntax-violation syntax-violation-form syntax-violation-subform syntax-violation? tan textual-port? transcoded-port transcoder-codec transcoder-eol-style transcoder-error-handling-mode truncate u8-list->bytevector uint-list->bytevector undefined-violation? unless unquote unquote-splicing unsyntax unsyntax-splicing utf-16-codec utf-8-codec utf16->string utf32->string utf8->string values vector vector->list vector-fill! vector-for-each vector-length vector-map vector-ref vector-set! vector-sort vector-sort! vector? violation? warning? when who-condition? with-exception-handler #;with-input-from-file #;with-output-to-file with-syntax #;write #;write-char zero? ;; From this library (rename (my:read read) (my:write write) (my:display display) (my:newline newline) (my:read-char read-char) (my:write-char write-char) (my:peek-char peek-char))) (import (rnrs)) (define (my:read p) (read p)) (define (my:write x p) (write x p)) (define (my:display x p) (display x p)) (define (my:newline p) (newline p)) (define (my:read-char p) (read-char p)) (define (my:write-char x p) (write-char x p)) (define (my:peek-char p) (peek-char p)) )
true
fe9d82727dcb481d64c2fad6a77c075103d0c8e2
b9eb119317d72a6742dce6db5be8c1f78c7275ad
/guile/check-katie-backup.scm
606923611bf3c3fdd75bea2e7000cf6d41fc26bf
[]
no_license
offby1/doodles
be811b1004b262f69365d645a9ae837d87d7f707
316c4a0dedb8e4fde2da351a8de98a5725367901
refs/heads/master
2023-02-21T05:07:52.295903
2022-05-15T18:08:58
2022-05-15T18:08:58
512,608
2
1
null
2023-02-14T22:19:40
2010-02-11T04:24:52
Scheme
UTF-8
Scheme
false
false
636
scm
check-katie-backup.scm
#!/usr/bin/guile -s !# ;; Checks that katie's Windows PC has recently been backed up. It ;; does this by looking at the timestamp on ;; /katie-local/WINDOWS/WIN386.SWP -- if that file was modified early ;; this morning, then things are OK; if it's older, then things are ;; not OK. (define filename "/katie-local/WINDOWS/WIN386.SWP") (define ok? (let* ((age-in-seconds (- (current-time) (stat:mtime (stat filename)))) (age-in-hours (/ age-in-seconds 3600))) (< age-in-hours 24))) (begin (write filename) (if (not ok?) (display " is more than a day old") (display " is nice and fresh")) (newline))
false
3faf712fde805e99f3f912fad77c67ba9f7f4cd5
1a64a1cff5ce40644dc27c2d951cd0ce6fcb6442
/testing/test-optional-kw-arg-app.scm
0a8787307cb046771363acce8be1367ebf8c8063
[]
no_license
skchoe/2007.rviz-objects
bd56135b6d02387e024713a9f4a8a7e46c6e354b
03c7e05e85682d43ab72713bdd811ad1bbb9f6a8
refs/heads/master
2021-01-15T23:01:58.789250
2014-05-26T17:35:32
2014-05-26T17:35:32
null
0
0
null
null
null
null
UTF-8
Scheme
false
false
179
scm
test-optional-kw-arg-app.scm
(module test-optional-kw-arg-app scheme (require "test-optional-kw-arg.scm") (optl-arg-S 1000) (optl-arg 33 #:s 3 #:S 4) (optl-arg 33 #:s 3) (optl-arg 22 ) )
false
66541d1d1d038e3f6033d4012e031ef550c60641
b14c18fa7a4067706bd19df10f846fce5a24c169
/Chapter3/3.65.scm
e176a22a93be847d5ac59cccbb97311d3440a11b
[]
no_license
silvesthu/LearningSICP
eceed6267c349ff143506b28cf27c8be07e28ee9
b5738f7a22c9e7967a1c8f0b1b9a180210051397
refs/heads/master
2021-01-17T00:30:29.035210
2016-11-29T17:57:16
2016-11-29T17:57:16
19,287,764
3
0
null
null
null
null
UTF-8
Scheme
false
false
1,431
scm
3.65.scm
#lang racket (require racket/stream) (define (add-streams s1 s2) (stream-cons (+ (stream-first s1) (stream-first s2)) (add-streams (stream-rest s1) (stream-rest s2)))) (define (mul-streams s1 s2) (stream-cons (* (stream-first s1) (stream-first s2)) (mul-streams (stream-rest s1) (stream-rest s2)))) (define (partial-sums s) (define first-copies (stream-cons (stream-first s) first-copies)) (stream-cons (stream-first s) (add-streams first-copies (partial-sums (stream-rest s))))) (define (log2-summands n) (stream-cons (/ 1.0 n) (stream-map - (log2-summands (+ n 1))))) (define log2-stream (partial-sums (log2-summands 1))) (define (square x) (* x x)) (define (euler-transform s) (let ((s0 (stream-ref s 0)) (s1 (stream-ref s 1)) (s2 (stream-ref s 2))) (stream-cons (- s2 (/ (square (- s2 s1)) (+ s0 (* -2 s1) s2))) (euler-transform (stream-rest s))))) (define (make-tableau transform s) (stream-cons s (make-tableau transform (transform s)))) (define (accelerated-sequence transform s) (stream-map stream-first (make-tableau transform s))) (define ln2 (accelerated-sequence euler-transform log2-stream)) (stream-ref ln2 0) (stream-ref ln2 1) (stream-ref ln2 2) (stream-ref ln2 3) (stream-ref ln2 4) (stream-ref ln2 5) (stream-ref ln2 6) (stream-ref ln2 7) ; how rapid ?
false
83894de75e07e4476c5aeba8973d43965f335f6b
b60cb8e39ec090137bef8c31ec9958a8b1c3e8a6
/test/concurrentScheme/threads/variations/count3.scm
4aba386fd1ff25e666fa0b9757bf9e432e30393d
[]
no_license
acieroid/scala-am
eff387480d3baaa2f3238a378a6b330212a81042
13ef3befbfc664b77f31f56847c30d60f4ee7dfe
refs/heads/master
2021-01-17T02:21:41.692568
2021-01-15T07:51:20
2021-01-15T07:51:20
28,140,080
32
16
null
2020-04-14T08:53:20
2014-12-17T14:14:02
Scheme
UTF-8
Scheme
false
false
260
scm
count3.scm
(letrec ((i 100) (thread (lambda (n) (if (<= i 0) #t (begin (set! i (- i 1)) (thread n))))) (t1 (fork (thread 1))) (t2 (fork (thread 2))) (t3 (fork (thread 3)))) (join t1) (join t2) (join t3))
false
5276c04035a862e4d799691c12cd831a8c099172
ac2a3544b88444eabf12b68a9bce08941cd62581
/lib/scheme/write/write.sld
e4d6aca4af8851b399bae55f55d395b84678b715
[ "Apache-2.0", "LGPL-2.1-only" ]
permissive
tomelam/gambit
2fd664cf6ea68859d4549fdda62d31a25b2d6c6f
d60fdeb136b2ed89b75da5bfa8011aa334b29020
refs/heads/master
2020-11-27T06:39:26.718179
2019-12-15T16:56:31
2019-12-15T16:56:31
229,341,552
1
0
Apache-2.0
2019-12-20T21:52:26
2019-12-20T21:52:26
null
UTF-8
Scheme
false
false
105
sld
write.sld
(define-library (scheme write) (namespace "") (export display write write-shared write-simple ))
false
2922a45be6fc4dba6b5727f756be21dfb362aad6
1645add1bc3f780e0deaf3ca323b263037065c8f
/samselpla.scm
e891a55353f92164d74d701c4f5c9378b08da96b
[ "ISC" ]
permissive
alanpost/jbogenturfahi
b4c57e80000d30bc6c0dff54ee780264a201006e
7a6b50eb13ab5bd4d0d6122638c4a63a55e59aef
refs/heads/master
2020-12-24T14:27:34.229766
2013-01-04T19:38:49
2013-01-04T19:38:49
1,044,613
3
1
null
null
null
null
UTF-8
Scheme
false
false
74,697
scm
samselpla.scm
;;;; ;;;; jbogenturfahi - lo lojbo ke pe'a jajgau ratcu ke'e genturfa'i ;;;; `-> A Lojban grammar parser ;;;; ;;;; Copyright (c) 2010 ".alyn.post." <[email protected]> ;;;; ;;;; Permission to use, copy, modify, and/or distribute this software for any ;;;; purpose with or without fee is hereby granted, provided that the above ;;;; copyright notice and this permission notice appear in all copies. ;;;; ;;;; THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES ;;;; WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF ;;;; MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ;;;; ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES ;;;; WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ;;;; ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF ;;;; OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ;;;; ;;; ;;; Helper routines ;;; ;; if an optional rule was not matched, return null. ;; Otherwise return the rule. ;; (define-syntax ?-null (syntax-rules () ((_ jalge) (if (and (string? jalge) (string=? "" jalge)) '() `(,jalge))))) (define-syntax ?*-null (syntax-rules () ((_ jalge) (if (and (string? jalge) (string=? "" jalge)) '() jalge)))) (define-syntax ?+-null (syntax-rules () ((_ jalge) (if (and (string? jalge) (string=? "" jalge)) '() jalge)))) ;; if a zero-or-more rule was not matched, return ;; null. Otherwise return the rule. ;; (define-syntax *-null (syntax-rules () ((_ jalge) jalge))) ;; if a one-or-more rule was matched. ;; (define-syntax +-null (syntax-rules () ((_ jalge) jalge))) ;;; ;;; rafske ;;; ;; ;; lerfu ;; (define (a comma lerfu) (string-append (apply string comma) (string lerfu))) (define (e comma lerfu) (string-append (apply string comma) (string lerfu))) (define (i comma lerfu) (string-append (apply string comma) (string lerfu))) (define (o comma lerfu) (string-append (apply string comma) (string lerfu))) (define (u comma lerfu) (string-append (apply string comma) (string lerfu))) (define (y comma lerfu) (string-append (apply string comma) (string lerfu))) (define (l comma lerfu) (string-append (apply string comma) (string lerfu))) (define (m comma lerfu) (string-append (apply string comma) (string lerfu))) (define (n comma lerfu) (string-append (apply string comma) (string lerfu))) (define (r comma lerfu) (string-append (apply string comma) (string lerfu))) (define (b comma lerfu) (string-append (apply string comma) (string lerfu))) (define (d comma lerfu) (string-append (apply string comma) (string lerfu))) (define (g comma lerfu) (string-append (apply string comma) (string lerfu))) (define (v comma lerfu) (string-append (apply string comma) (string lerfu))) (define (j comma lerfu) (string-append (apply string comma) (string lerfu))) (define (z comma lerfu) (string-append (apply string comma) (string lerfu))) (define (s comma lerfu) (string-append (apply string comma) (string lerfu))) (define (c comma lerfu) (string-append (apply string comma) (string lerfu))) (define (x comma lerfu) (string-append (apply string comma) (string lerfu))) (define (k comma lerfu) (string-append (apply string comma) (string lerfu))) (define (f comma lerfu) (string-append (apply string comma) (string lerfu))) (define (p comma lerfu) (string-append (apply string comma) (string lerfu))) (define (t comma lerfu) (string-append (apply string comma) (string lerfu))) (define (h comma lerfu) (string-append (apply string comma) (string lerfu))) (define (digit comma digit) (string-append (apply string comma) (string digit))) ;; ;; parts ;; (define (final-syllable onset nucleus) (string-append onset nucleus)) (define (any-syllable onset nucleus coda) (string-append onset nucleus coda)) (define (syllable onset nucleus coda) (string-append onset nucleus coda)) (define (consonantal-syllable consonant0 syllabic consonant1) (string-append consonant0 syllabic consonant1)) (define (coda syllabic consonant) (string-append syllabic consonant)) (define (onset consonant glide) (string-append consonant glide)) (define (diphthong vowel0 vowel1) (string-append vowel0 vowel1)) (define (cluster cfari fanmo) (apply string-append cfari fanmo)) (define (initial-pair consonant0 consonant1) (string-append consonant0 consonant1)) (define (initial sibilant other liquid) (string-append sibilant other liquid)) (define (affricate stop fricative) (string-append stop fricative)) ;; brivla ;; (define (brivla-gismu gismu) `(gismu ,gismu)) (define (brivla-fuhivla fuhivla) `(fuhivla ,fuhivla)) (define (brivla-lujvo lujvo) `(lujvo ,lujvo)) ;; cmene ;; (define (zifcme nafanmo consonant) `(cmene ,(string-append (apply string-append nafanmo) consonant))) (define (jbocme any-syllable-or-digit) `(cmene ,(apply string-append any-syllable-or-digit))) ;; cmavo ;; (define (CVCy-lujvo-brivla-core CVC-rafsi y h initial-rafsi brivla-core) (string-append CVC-rafsi y h (apply string-append initial-rafsi) brivla-core)) (define (CVCy-lujvo-short-final-rafsi stressed-CVC-rafsi y short-final-rafsi) (string-append stressed-CVC-rafsi y short-final-rafsi)) (define (cmavo-form onset nucleus-h nucleus) (string-append onset (apply string-append (map-apply string-append nucleus-h)) nucleus)) (define (cmavo-form-y y) (apply string-append y)) ;; lujvo ;; (define (lujvo initial-rafsi brivla-core) (string-append (apply string-append initial-rafsi) brivla-core)) (define (brivla-core stressed-initial-rafsi short-final-rafsi ) (string-append stressed-initial-rafsi short-final-rafsi)) ;; fu'ivla ;; (define (fuhivla fuhivla-head stressed-syllable consonantal-syllable final-syllable) (string-append fuhivla-head stressed-syllable (apply string-append consonantal-syllable) final-syllable)) (define (stressed-brivla-rafsi brivla-head stressed-syllable h y) (string-append brivla-head stressed-syllable h y)) (define (brivla-rafsi brivla-head h0 y h1) (string-append brivla-head h0 y h1)) (define (stressed-fuhivla-rafsi fuhivla-head stressed-syllable onset y) (string-append fuhivla-head stressed-syllable onset y)) (define (fuhivla-rafsi fuhivla-head onset y h) (string-append fuhivla-head onset y h)) (define (brivla-head unstressed-syllable) (apply string-append unstressed-syllable)) (define (slinkuhi consonant rafsi-string) (string-append consonant rafsi-string)) (define (rafsi-string y-less-rafsi rest) (string-append (apply string-append y-less-rafsi) rest)) (define (rafsi-string-short-final stressed-y-less-rafsi short-final-rafsi) (string-append stressed-y-less-rafsi short-final-rafsi)) (define (rafsi-string-initial-pair stressed-y-less-rafsi initial-pair y) (string-append stressed-y-less-rafsi initial-pair y)) ;; gismu ;; (define (gismu . rodalerfu) (apply string-append rodalerfu)) (define (CVV-final-rafsi consonant stressed-vowel h vowel) (string-append consonant stressed-vowel h vowel)) (define (short-final-rafsi initial vowel) (string-append initial vowel)) (define (stressed-y-rafsi rafsi y) (string-append rafsi y)) (define (stressed-long-rafsi-CCVC initial-pair stressed-vowel consonant) (string-append initial-pair stressed-vowel consonant)) (define (stressed-long-rafsi-CVCC consonant0 stressed-vowel consonant1 consonant2) (string-append consonant0 stressed-vowel consonant1 consonant2)) (define (stressed-CVC-rafsi consonant0 stressed-vowel consonant1) (string-append consonant0 stressed-vowel consonant1)) (define (stressed-CCV-rafsi initial-pair stressed-vowel) (string-append initial-pair stressed-vowel)) (define (stressed-CVV-rafsi consonant vowel r-hyphen) (string-append consonant vowel r-hyphen)) (define (stressed-CVV-rafsi-VhV unstressed-vowel h stressed-vowel) (string-append unstressed-vowel h stressed-vowel)) (define (y-rafsi rafsi y h) (string-append rafsi y h)) (define (long-rafsi-CCVC initial-pair unstressed-vowel consonant) (string-append initial-pair unstressed-vowel consonant)) (define (long-rafsi-CVCC consonant0 unstressed-vowel consonant1 consonant2) (string-append consonant0 unstressed-vowel consonant1 consonant2)) (define (CVC-rafsi consonant0 unstressed-vowel consonant1) (string-append consonant0 unstressed-vowel consonant1)) (define (CCV-rafsi initial-pair unstressed-vowel) (string-append initial-pair unstressed-vowel)) (define (CVV-rafsi consonant vowel r-hyphen) (string-append consonant vowel r-hyphen)) (define (CVV-rafsi-VhV unstressed-vowel0 h unstressed-vowel1) (string-append unstressed-vowel0 h unstressed-vowel1)) ;; non-Lojban word ;; (define (non-lojban-word rodalerfu) `(non-lojban-word ,(apply string rodalerfu))) ;; spaces ;; (define (ybu y bu) `(cmavo (BY ,(string-append (cadadr y) (cadadr bu))))) ;; ;; selma'o ;; (define (cmavo cmavo-form) `(cmavo ,cmavo-form)) ; ji is the only two-letter cmavo in A. The rest are ; a single letter. ; (define (A . rodalerfu) `(cmavo (A ,(apply string-append rodalerfu)))) (define (BAI . rodalerfu) `(cmavo (BAI ,(apply string-append rodalerfu)))) (define (BAhE . rodalerfu) `(cmavo (BAhE ,(apply string-append rodalerfu)))) (define (BE . rodalerfu) `(cmavo (BE ,(apply string-append rodalerfu)))) (define (BEI . rodalerfu) `(cmavo (BEI ,(apply string-append rodalerfu)))) (define (BEhO . rodalerfu) `(cmavo (BEhO ,(apply string-append rodalerfu)))) (define (BIhE . rodalerfu) `(cmavo (BIhE ,(apply string-append rodalerfu)))) (define (BIhI . rodalerfu) `(cmavo (BIhI ,(apply string-append rodalerfu)))) (define (BO . rodalerfu) `(cmavo (BO ,(apply string-append rodalerfu)))) (define (BOI . rodalerfu) `(cmavo (BOI ,(apply string-append rodalerfu)))) (define (BU . rodalerfu) `(cmavo (BU ,(apply string-append rodalerfu)))) (define (BY . rodalerfu) `(cmavo (BY ,(apply string-append rodalerfu)))) (define (CAhA . rodalerfu) `(cmavo (CAhA ,(apply string-append rodalerfu)))) (define (CAI . rodalerfu) `(cmavo (CAI ,(apply string-append rodalerfu)))) (define (CEI . rodalerfu) `(cmavo (CEI ,(apply string-append rodalerfu)))) (define (CEhE . rodalerfu) `(cmavo (CEhE ,(apply string-append rodalerfu)))) (define (CO . rodalerfu) `(cmavo (CO ,(apply string-append rodalerfu)))) (define (COI . rodalerfu) `(cmavo (COI ,(apply string-append rodalerfu)))) (define (CU . rodalerfu) `(cmavo (CU ,(apply string-append rodalerfu)))) (define (CUhE . rodalerfu) `(cmavo (CUhE ,(apply string-append rodalerfu)))) (define (DAhO . rodalerfu) `(cmavo (DAhO ,(apply string-append rodalerfu)))) (define (DOI . rodalerfu) `(cmavo (DOI ,(apply string-append rodalerfu)))) (define (DOhU . rodalerfu) `(cmavo (DOhU ,(apply string-append rodalerfu)))) (define (FA . rodalerfu) `(cmavo (FA ,(apply string-append rodalerfu)))) (define (FAhA . rodalerfu) `(cmavo (FAhA ,(apply string-append rodalerfu)))) (define (FAhO . rodalerfu) `(cmavo (FAhO ,(apply string-append rodalerfu)))) (define (FEhE . rodalerfu) `(cmavo (FEhE ,(apply string-append rodalerfu)))) (define (FEhU . rodalerfu) `(cmavo (FEhU ,(apply string-append rodalerfu)))) (define (FIhO . rodalerfu) `(cmavo (FIhO ,(apply string-append rodalerfu)))) (define (FOI . rodalerfu) `(cmavo (FOI ,(apply string-append rodalerfu)))) (define (FUhA . rodalerfu) `(cmavo (FUhA ,(apply string-append rodalerfu)))) (define (FUhE . rodalerfu) `(cmavo (FUhE ,(apply string-append rodalerfu)))) (define (FUhO . rodalerfu) `(cmavo (FUhO ,(apply string-append rodalerfu)))) (define (GA . rodalerfu) `(cmavo (GA ,(apply string-append rodalerfu)))) (define (GAhO . rodalerfu) `(cmavo (GAhO ,(apply string-append rodalerfu)))) (define (GEhU . rodalerfu) `(cmavo (GEhU ,(apply string-append rodalerfu)))) (define (GI . rodalerfu) `(cmavo (GI ,(apply string-append rodalerfu)))) (define (GIhA . rodalerfu) `(cmavo (GIhA ,(apply string-append rodalerfu)))) (define (GOI . rodalerfu) `(cmavo (GOI ,(apply string-append rodalerfu)))) (define (GOhA . rodalerfu) `(cmavo (GOhA ,(apply string-append rodalerfu)))) (define (GUhA . rodalerfu) `(cmavo (GUhA ,(apply string-append rodalerfu)))) (define (I . rodalerfu) `(cmavo (I ,(apply string-append rodalerfu)))) (define (JA . rodalerfu) `(cmavo (JA ,(apply string-append rodalerfu)))) (define (JAI . rodalerfu) `(cmavo (JAI ,(apply string-append rodalerfu)))) (define (JOhI . rodalerfu) `(cmavo (JOhI ,(apply string-append rodalerfu)))) (define (JOI . rodalerfu) `(cmavo (JOI ,(apply string-append rodalerfu)))) (define (KE . rodalerfu) `(cmavo (KE ,(apply string-append rodalerfu)))) (define (KEhE . rodalerfu) `(cmavo (KEhE ,(apply string-append rodalerfu)))) (define (KEI . rodalerfu) `(cmavo (KEI ,(apply string-append rodalerfu)))) (define (KI . rodalerfu) `(cmavo (KI ,(apply string-append rodalerfu)))) (define (KOhA . rodalerfu) `(cmavo (KOhA ,(apply string-append rodalerfu)))) (define (KU . rodalerfu) `(cmavo (KU ,(apply string-append rodalerfu)))) (define (KUhE . rodalerfu) `(cmavo (KUhE ,(apply string-append rodalerfu)))) (define (KUhO . rodalerfu) `(cmavo (KUhO ,(apply string-append rodalerfu)))) (define (LA . rodalerfu) `(cmavo (LA ,(apply string-append rodalerfu)))) (define (LAU . rodalerfu) `(cmavo (LAU ,(apply string-append rodalerfu)))) (define (LAhE . rodalerfu) `(cmavo (LAhE ,(apply string-append rodalerfu)))) (define (LE . rodalerfu) `(cmavo (LE ,(apply string-append rodalerfu)))) (define (LEhU . rodalerfu) `(cmavo (LEhU ,(apply string-append rodalerfu)))) (define (LI . rodalerfu) `(cmavo (LI ,(apply string-append rodalerfu)))) (define (LIhU . rodalerfu) `(cmavo (LIhU ,(apply string-append rodalerfu)))) (define (LOhO . rodalerfu) `(cmavo (LOhO ,(apply string-append rodalerfu)))) (define (LOhU . rodalerfu) `(cmavo (LOhU ,(apply string-append rodalerfu)))) (define (LU . rodalerfu) `(cmavo (LU ,(apply string-append rodalerfu)))) (define (LUhU . rodalerfu) `(cmavo (LUhU ,(apply string-append rodalerfu)))) (define (MAhO . rodalerfu) `(cmavo (MAhO ,(apply string-append rodalerfu)))) (define (MAI . rodalerfu) `(cmavo (MAI ,(apply string-append rodalerfu)))) (define (ME . rodalerfu) `(cmavo (ME ,(apply string-append rodalerfu)))) (define (MEhU . rodalerfu) `(cmavo (MEhU ,(apply string-append rodalerfu)))) (define (MOhE . rodalerfu) `(cmavo (MOhE ,(apply string-append rodalerfu)))) (define (MOhI . rodalerfu) `(cmavo (MOhI ,(apply string-append rodalerfu)))) (define (MOI . rodalerfu) `(cmavo (MOI ,(apply string-append rodalerfu)))) (define (NA . rodalerfu) `(cmavo (NA ,(apply string-append rodalerfu)))) (define (NAI . rodalerfu) `(cmavo (NAI ,(apply string-append rodalerfu)))) (define (NAhE . rodalerfu) `(cmavo (NAhE ,(apply string-append rodalerfu)))) (define (NAhU . rodalerfu) `(cmavo (NAhU ,(apply string-append rodalerfu)))) (define (NIhE . rodalerfu) `(cmavo (NIhE ,(apply string-append rodalerfu)))) (define (NIhO . rodalerfu) `(cmavo (NIhO ,(apply string-append rodalerfu)))) (define (NOI . rodalerfu) `(cmavo (NOI ,(apply string-append rodalerfu)))) (define (NU . rodalerfu) `(cmavo (NU ,(apply string-append rodalerfu)))) (define (NUhA . rodalerfu) `(cmavo (NUhA ,(apply string-append rodalerfu)))) (define (NUhI . rodalerfu) `(cmavo (NUhI ,(apply string-append rodalerfu)))) (define (NUhU . rodalerfu) `(cmavo (NUhU ,(apply string-append rodalerfu)))) (define (PA . rodalerfu) `(cmavo (PA ,(apply string-append rodalerfu)))) (define (PEhE . rodalerfu) `(cmavo (PEhE ,(apply string-append rodalerfu)))) (define (PEhO . rodalerfu) `(cmavo (PEhO ,(apply string-append rodalerfu)))) (define (PU . rodalerfu) `(cmavo (PU ,(apply string-append rodalerfu)))) (define (RAhO . rodalerfu) `(cmavo (RAhO ,(apply string-append rodalerfu)))) (define (ROI . rodalerfu) `(cmavo (ROI ,(apply string-append rodalerfu)))) (define (SA . rodalerfu) `(cmavo (SA ,(apply string-append rodalerfu)))) (define (SE . rodalerfu) `(cmavo (SE ,(apply string-append rodalerfu)))) (define (SEI . rodalerfu) `(cmavo (SEI ,(apply string-append rodalerfu)))) (define (SEhU . rodalerfu) `(cmavo (SEhU ,(apply string-append rodalerfu)))) (define (SI . rodalerfu) `(cmavo (SI ,(apply string-append rodalerfu)))) (define (SOI . rodalerfu) `(cmavo (SOI ,(apply string-append rodalerfu)))) (define (SU . rodalerfu) `(cmavo (SU ,(apply string-append rodalerfu)))) (define (TAhE . rodalerfu) `(cmavo (TAhE ,(apply string-append rodalerfu)))) (define (TEhU . rodalerfu) `(cmavo (TEhU ,(apply string-append rodalerfu)))) (define (TEI . rodalerfu) `(cmavo (TEI ,(apply string-append rodalerfu)))) (define (TO . rodalerfu) `(cmavo (TO ,(apply string-append rodalerfu)))) (define (TOI . rodalerfu) `(cmavo (TOI ,(apply string-append rodalerfu)))) (define (TUhE . rodalerfu) `(cmavo (TUhE ,(apply string-append rodalerfu)))) (define (TUhU . rodalerfu) `(cmavo (TUhU ,(apply string-append rodalerfu)))) (define (UI . rodalerfu) `(cmavo (UI ,(apply string-append rodalerfu)))) (define (VA . rodalerfu) `(cmavo (VA ,(apply string-append rodalerfu)))) (define (VAU . rodalerfu) `(cmavo (VAU ,(apply string-append rodalerfu)))) (define (VEI . rodalerfu) `(cmavo (VEI ,(apply string-append rodalerfu)))) (define (VEhO . rodalerfu) `(cmavo (VEhO ,(apply string-append rodalerfu)))) (define (VEhA . rodalerfu) `(cmavo (VEhA ,(apply string-append rodalerfu)))) (define (VIhA . rodalerfu) `(cmavo (VIhA ,(apply string-append rodalerfu)))) (define (VUhO . rodalerfu) `(cmavo (VUhO ,(apply string-append rodalerfu)))) (define (VUhU . rodalerfu) `(cmavo (VUhU ,(apply string-append rodalerfu)))) (define (XI . rodalerfu) `(cmavo (XI ,(apply string-append rodalerfu)))) (define (Y rodalerfu) `(cmavo (Y ,(apply string-append rodalerfu)))) (define (ZAhO . rodalerfu) `(cmavo (ZAhO ,(apply string-append rodalerfu)))) (define (ZEhA . rodalerfu) `(cmavo (ZEhA ,(apply string-append rodalerfu)))) (define (ZEI . rodalerfu) `(cmavo (ZEI ,(apply string-append rodalerfu)))) (define (ZI . rodalerfu) `(cmavo (ZI ,(apply string-append rodalerfu)))) (define (ZIhE . rodalerfu) `(cmavo (ZIhE ,(apply string-append rodalerfu)))) (define (ZO . rodalerfu) `(cmavo (ZO ,(apply string-append rodalerfu)))) (define (ZOI . rodalerfu) `(cmavo (ZOI ,(apply string-append rodalerfu)))) (define (ZOhU . rodalerfu) `(cmavo (ZOhU ,(apply string-append rodalerfu)))) ;;; ;;; gerna ;;; (define (text intro-null NAI-clause* text-part-2 joik-jek? text-1? faho-clause EOF?) `(text ,@intro-null ,@(*-null NAI-clause*) ,@text-part-2 ,@(?-null joik-jek?) ,@(?*-null text-1?) ,@faho-clause ,@(?*-null EOF?))) (define (intro-null su-clause* intro-si-clause) `(,@(*-null su-clause*) ,@intro-si-clause)) ; |text-part| is either |CMENE-clause+| or |indicators?| ; |?-null| handles |CMENE-clause+| ; (define (text-part-2 text-part free*) `(,@(?-null text-part) ,@(*-null free*))) (define (intro-si-clause si-clause? SI-clause*) `(,@(?-null si-clause?) ,@(*-null SI-clause*))) (define (faho-clause FAhO-clause?) (?-null FAhO-clause?)) (define (text-1-I I-clause jek-or-joik? stag? BO-clause? free* text-1?) `(,I-clause ,@(?-null jek-or-joik?) ,@(?-null stag?) ,@(?-null BO-clause?) ,@(*-null free*) ,@(?*-null text-1?))) (define (text-1-NIhO NIhO-clause+ free* su-clause* paragraphs?) `(,@(+-null NIhO-clause+) ,@(*-null free*) ,@(*-null su-clause*) ,@(?*-null paragraphs?))) (define (text-1-paragraphs paragraphs) `(,paragraphs)) ;; NIhO-clause? is: ( NIhO-clause+ free* su-clause* paragraphs )? ;; ?-null handles + and *. ;; (define (paragraphs paragraph NIhO-clause+ free* su-clause* paragraphs-0) `(paragraphs ,@paragraph ,@(?*-null NIhO-clause+) ,@(?*-null free*) ,@(?*-null su-clause*) ,@(?*-null paragraphs-0))) (define (paragraph statement-or-fragment I-clause*) (define (I I-clause free* statement-or-fragment?) ; ; statement-or-fragment? uses ?*-null, rather than ?-null, ; because an extra list is created in |statement|. This ; normalizes it to the same list structure everywhere it ; is used. ; `(,@I-clause ,@(*-null free*) ,@(?*-null statement-or-fragment?))) `((paragraph ,@statement-or-fragment ,@(map-apply I I-clause*)))) (define (statement statement-1) `(,statement-1)) (define (statement-prenex prenex statement-1) `(,prenex ,statement-1)) (define (statement-1 statement-2 I-clause*) (define (I I-clause joik-jek statement-2?) `(,@I-clause ,@joik-jek ,@(?-null statement-2?))) `(,@statement-2 ,@(map-apply I I-clause*))) (define (statement-2 statement-3 I-clause? jek-or-joik? stag? BO-clause? free* statement-2?) `(,@statement-3 ,@(?-null I-clause?) ,@(?-null jek-or-joik?) ,@(?-null stag?) ,@(?-null BO-clause?) ,@(?*-null free*) ,@(?-null statement-2?))) (define (statement-3 sentence) sentence) (define (statement-3-TUhE tag? TUhE-clause free* text-1 TUhU-clause? free*) `(,@(?-null tag?) ,@TUhE-clause ,@(*-null free*) ,@text-1 ,@(?-null TUhU-clause?) ,@(*-null free*))) (define (fragment-prenex prenex) prenex) (define (fragment-terms terms VAU-clause? free*) `(,@(+-null terms) ,@(?-null VAU-clause?) ,@(*-null free*))) (define (fragment-ek ek free*) `(,@ek ,@(*-null free*))) (define (fragment-gihek gihek free*) `(,@gihek ,@(*-null free*))) (define (fragment-quantifier quantifier) quantifier) (define (fragment-NA NA-clause free*) `(,@NA-clause ,@(*-null free*))) (define (fragment-relative-clauses relative-clauses) relative-clauses) (define (fragment-links links) links) (define (fragment-linkargs linkargs) linkargs) (define (prenex . rodasumti) `(prenex ,@rodasumti)) (define (sentence terms? bridi-tail-sa?* CU-clause? free?* bridi-tail-sa* bridi-tail) `(sentence ,@(?+-null terms?) ,@(?*-null bridi-tail-sa?*) ,@(?-null CU-clause?) ,@(?*-null free?*) ,@(*-null bridi-tail-sa*) ,@bridi-tail)) (define (sentence-sa sentence-start sa-word* SA-clause) `(sa-clause ,@sentence-start ,@(apply append (*-null sa-word*)) ,@SA-clause)) (define (sentence-start-I I-pre) I-pre) (define (sentence-start-NIhO NIhO-pre) NIhO-pre) (define (subsentence sentence) sentence) (define (subsentence-prenex prenex subsentence) `(,@prenex ,@subsentence)) (define (bridi-tail bridi-tail-1 gihek? stag? KE-clause? free-0?* bridi-tail? KEhE-clause? free-1?* tail-terms?) `(,@bridi-tail-1 ,@(?-null gihek?) ,@(?-null stag?) ,@(?-null KE-clause?) ,@(?*-null free-0?*) ,@(?-null bridi-tail?) ,@(?-null KEhE-clause?) ,@(?*-null free-1?*) ,@(?-null tail-terms?))) (define (bridi-tail-sa . rodasumti) `(bridi-tail-sa ,@rodasumti)) (define (bridi-tail-start-ME ME-clause) ME-clause) (define (bridi-tail-start-NUhA NUhA-clause) NUhA-clause) (define (bridi-tail-start-NU NU-clause) NU-clause) (define (bridi-tail-start-NA NA-clause) NA-clause) (define (bridi-tail-start-NAhE NAhE-clause) NAhE-clause) (define (bridi-tail-start-selbri selbri) selbri) (define (bridi-tail-start-tag tag bridi-tail-start) `(,@tag ,@bridi-tail-start)) (define (bridi-tail-start-KE KE-clause bridi-tail-start) `(,@KE-clause ,@bridi-tail-start)) (define (bridi-tail-start bridi-tail) bridi-tail) (define (bridi-tail-1 bridi-tail-2 rest*) (define (rest gihek free* bridi-tail-2 tail-terms) `(,@gihek ,@(*-null free*) ,@bridi-tail-2 ,@tail-terms)) `(,@bridi-tail-2 ,@(map-apply rest rest*))) (define (bridi-tail-2 bridi-tail-3 gihek? stag? BO-clause? free?* bridi-tail-2? tail-terms?) `(,@bridi-tail-3 ,@(?-null gihek?) ,@(?-null stag?) ,@(?-null BO-clause?) ,@(?*-null free?*) ,@(?-null bridi-tail-2?) ,@(?-null tail-terms?))) (define (bridi-tail-3-selbri selbri tail-terms) `(,@selbri ,@tail-terms)) (define (bridi-tail-3-gek gek-sentence) gek-sentence) (define (gek-sentence . rodasumti) `(gek-sentence ,@rodasumti)) (define (gek-sentence-KE . rodasumti) `(gek-sentence-KE ,@rodasumti)) (define (gek-sentence-NA . rodasumti) `(gek-sentence-NA ,@rodasumti)) (define (tail-terms terms? VAU-clause? free*) `(,@(?+-null terms?) ,@(?-null VAU-clause?) ,@(*-null free*))) (define (terms terms-1+) terms-1+) (define (terms-1 terms-2 rest*) (define (terms pehe-sa* PEhE-clause free* joik-jek terms-2) `(,@terms ,@(*-null pehe-sa*) ,@PEhE-clause ,@(*-null free*) ,@joik-jek ,@terms-2)) `(,@terms-2 ,@(map-apply terms rest*))) (define (terms-2 term rest*) (define (terms cehe-sa* CEhE-clause free* term ) `(,@(*-null cehe-sa*) ,@CEhE-clause ,@(*-null free*) ,@term)) `(,@term ,@(map-apply terms rest*))) (define (pehe-sa PEhE-clause sa-word* SA-clause) `(,@PEhE-clause ,@(*-null sa-word*) ,@SA-clause)) (define (cehe-sa CEhE-clause sa-word* SA-clause) `(,@CEhE-clause ,@(*-null sa-word*) ,@SA-clause)) (define (term term-sa* term-1) `(term ,@(*-null term-sa*) ,@term-1)) (define (term-1-sumti sumti) sumti) (define (term-1-FA tag-or-FA sumti-or-KU) `(,@tag-or-FA ,@sumti-or-KU)) (define (term-1-FA-tag tag) tag) (define (term-1-FA-clause FA-clause free*) `(,FA-clause ,@(*-null free*))) (define (term-1-FA-sumti sumti) sumti) (define (term-1-FA-KU KU-clause? free*) `(,@(?-null KU-clause?) ,@(*-null free*))) (define (term-1-termset termset) termset) (define (term-1-NA NA-clause KU-clause free*) `(,NA-clause ,KU-clause ,@(*-null free*))) (define (term-sa term-start sa-word* SA-clause) `(sa-clause ,@term-start ,@(*-null sa-word*) ,@SA-clause)) (define (term-start term-1) term-1) (define (term-start-LA LA-clause) LA-clause) (define (term-start-LE LE-clause) LE-clause) (define (term-start-LI LI-clause) LI-clause) (define (term-start-LU LU-clause) LU-clause) (define (term-start-LAhE LAhE-clause) LAhE-clause) (define (term-start-quantifier quantifier term-start) `(,@quantifier ,@term-start)) (define (term-start-gek gek sumti gik) `(,@gek ,@sumti ,@gik)) (define (term-start-FA FA-clause) FA-clause) (define (term-start-tag tag term-start) `(,@tag ,@term-start)) (define (termset . rodasumti) `(termset ,@rodasumti)) (define (termset-gek . rodasumti) `(termset-gek ,@rodasumti)) (define (terms-gik-terms . rodasumti) `(terms-gik-terms ,@rodasumti)) (define (gek-termset . rodasumti) `(gek-termset ,@rodasumti)) (define (termset-terms . rodasumti) `(termset-terms ,@rodasumti)) (define (sumti sumti-1 VUhO-clause? free* relative-clauses?) `((sumti ,@sumti-1 ,@(?-null VUhO-clause?) ,@(?*-null free*) ,@(?-null relative-clauses?)))) (define (sumti-1 sumti-2 joik-ek? stag? KE-clause? free-0* sumti? KEhE-clause? free-1*) `(,@sumti-2 ,@(?-null joik-ek?) ,@(?-null stag?) ,@(?-null KE-clause?) ,@(?*-null free-0*) ,@(?-null sumti?) ,@(?-null KEhE-clause?) ,@(?*-null free-1*))) (define (sumti-2 sumti-3 joik-ek-sumti-3*) (define (sumti joik-ek sumti-3) `(,@joik-ek ,@sumti-3)) `(,@sumti-3 ,@(map-apply sumti joik-ek-sumti-3*))) (define (sumti-3 sumti-4 joik-ek? stag? BO-clause? free* sumti-3?) `(,@sumti-4 ,@(?-null joik-ek?) ,@(?-null stag?) ,@(?-null BO-clause?) ,@(?*-null free*) ,@(?-null sumti-3?))) (define (sumti-4 sumti-5) sumti-5) (define (sumti-4-gek . rodasumti) `(sumti-4-gek ,@rodasumti)) (define (sumti-5 quantifier? sumti-6 relative-clauses?) `(,@(?-null quantifier?) ,sumti-6 ,@(?-null relative-clauses?))) (define (sumti-5-selbri quantifier selbri KU-clause? free* relative-clauses?) `(,@quantifier ,@selbri ,@(?-null KU-clause?) ,@(*-null free*) ,@(?-null relative-clauses?))) (define (sumti-6-ZO ZO-clause free*) `(,@ZO-clause ,@(*-null free*))) (define (sumti-6-ZOI ZOI-clause free*) `(,@ZOI-clause ,@(*-null free*))) (define (sumti-6-LOhU LOhU-clause free*) `(,@LOhU-clause ,@(*-null free*))) (define (sumti-6-BOI lerfu-string BOI-clause? free*) `(,@lerfu-string ,@(?-null BOI-clause?) ,@(*-null free*))) (define (sumti-6-LU LU-clause text LIhU-clause? free*) `(,@LU-clause ,text ,@(?-null LIhU-clause?) ,@(*-null free*))) (define (sumti-6-LAhE-clause LAhE-clause free*) `(,@LAhE-clause ,@(*-null free*))) (define (sumti-6-LAhE-NAhE NAhE-clause BO-clause free*) `(,@NAhE-clause ,@BO-clause ,@(*-null free*))) (define (sumti-6-LAhE clause relative-clauses? sumti LUhU-clause? free*) `(,@clause ,@(?-null relative-clauses?) ,@sumti ,@(?-null LUhU-clause?) ,@(*-null free*))) (define (sumti-6-KOhA KOhA-clause free*) `(,@KOhA-clause ,@(*-null free*))) (define (sumti-6-LA LA-clause free-0* relative-clauses? CMENE-clause+ free-1*) `(,@LA-clause ,@(*-null free-0*) ,@(?-null relative-clauses?) ,@CMENE-clause+ ,@(*-null free-1*))) (define (sumti-6-LE LA-or-LE-clause free-0* sumti-tail KU-clause? free-1*) `(,@LA-or-LE-clause ,@(*-null free-0*) ,@sumti-tail ,@(?-null KU-clause?) ,@(*-null free-1*))) (define (sumti-6-LI LI-clause free-0* mex LOhO-clause? free-1*) `(,@LI-clause ,@(*-null free-0*) ,@mex ,@(?-null LOhO-clause?) ,@(*-null free-1*))) (define (sumti-tail-sumti-6 sumti-6? relative-clauses? sumti-tail-1) `(,@(?-null sumti-6?) ,@(?-null relative-clauses?) ,@sumti-tail-1)) (define (sumti-tail relative-clauses sumti-tail-1) `(,@relative-clauses ,@sumti-tail-1)) (define (sumti-tail-1-selbri quantifier? selbri relative-clauses?) `(,@(?-null quantifier?) ,@selbri ,@(?-null relative-clauses?))) (define (sumti-tail-1-sumti quantifier sumti) `(,@quantifier ,@sumti)) (define (relative-clauses relative-clause rest*) (define (relative-clause* ZIhE-clause free* relative-clause) `(,@ZIhE-clause ,@(*-null free*) ,@relative-clause)) `(,@relative-clause ,@(map-apply relative-clause* rest*))) (define (relative-clause relative-clause-sa* relative-clause-1) `(,@relative-clause-sa* ,@relative-clause-1)) (define (relative-clause-sa relative-clause-start sa-word* SA-clause) `(sa-clause ,@relative-clause-start ,@(*-null sa-word*) ,@SA-clause)) (define (relative-clause-1-GOI GOI-clause free-0* term GEhU-clause? free-1*) `(,@GOI-clause ,@(*-null free-0*) ,term ,@(?-null GEhU-clause?) ,@(*-null free-1*))) (define (relative-clause-1-NOI NOI-clause free-0* subsentence KUhO-clause? free-1*) `(,@NOI-clause ,@(*-null free-0*) ,subsentence ,@(?-null KUhO-clause?) ,@(*-null free-1*))) (define (relative-clause-start . rodasumti) `(relative-clause-start ,@rodasumti)) (define (selbri tag? selbri-1) `((selbri ,@(?-null tag?) ,@selbri-1))) (define (selbri-1 selbri-2) selbri-2) (define (selbri-1-NA NA-clause free* selbri) `((,@NA-clause ,@(*-null free*) ,@selbri))) (define (selbri-2 selbri-3 CO-clause? free?* selbri-2?) `(,@selbri-3 ,@(?-null CO-clause?) ,@(?*-null free?*) ,@(?-null selbri-2?))) (define (selbri-3 selbri-4+) selbri-4+) (define (selbri-4 selbri-5 rest) `(,@selbri-5 ,@rest)) (define (selbri-4-joik-jek joik-jek selbri-5) `(,@joik-jek ,@selbri-5)) (define (selbri-4-joik joik stag? KE-clause free-0* selbri-3 KEhE-clause? free-1*) `(,@joik ,@(?-null stag?) ,@KE-clause ,@(*-null free-0*) ,@selbri-3 ,@(?-null KEhE-clause?) ,@(*-null free-1*))) (define (selbri-5 selbri-6 jek-or-joik? stag? BO-clause? free?* selbri-5?) `(,@selbri-6 ,@(?-null jek-or-joik?) ,@(?-null stag?) ,@(?-null BO-clause?) ,@(?*-null free?*) ,@(?-null selbri-5?))) (define (selbri-6 tanru-unit BO-clause? free?* selbri-6?) `(,@tanru-unit ,@(?-null BO-clause?) ,@(?*-null free?*) ,@(?-null selbri-6?))) (define (selbri-6-NAhE NAhE-clause? free* guhek selbri gik selbri-6) `(,@(?-null NAhE-clause?) ,@(*-null free*) ,@guhek ,@selbri ,@gik ,@selbri-6)) (define (tanru-unit tanru-unit-1 rest*) (define (rest CEI-clause free* tanru-unit-1) `(,@CEI-clause ,@(*-null free*) ,@tanru-unit-1)) `(,@tanru-unit-1 ,@(map-apply rest rest*))) (define (tanru-unit-1 tanru-unit-2 linkargs?) `(,@tanru-unit-2 ,@(?-null linkargs?))) (define (tanru-unit-2-BRIVLA BRIVLA-clause free*) `(,@BRIVLA-clause ,@(*-null free*))) (define (tanru-unit-2-GOhA GOhA-clause RAhO-clause? free*) `(,@GOhA-clause ,@(?-null RAhO-clause?) ,@(*-null free*))) (define (tanru-unit-2-KE KE-clause free-0* selbri-3 KEhE-clause? free-1*) `(,@KE-clause ,@(*-null free-0*) ,@selbri-3 ,@(?-null KEhE-clause?) ,@(*-null free-1*))) (define (tanru-unit-2-ME ME-clause free-0* sumti-or-lerfu-string MEhU-clause? free-1* MOI-clause? free-2*) `(,@ME-clause ,@(*-null free-0*) ,@sumti-or-lerfu-string ,@(?-null MEhU-clause?) ,@(*-null free-1*) ,@(?-null MOI-clause?) ,@(*-null free-2*))) (define (tanru-unit-2-MOI number-or-lerfu-string MOI-clause free*) `(,@number-or-lerfu-string ,@MOI-clause ,@(*-null free*))) (define (tanru-unit-2-NUhA NUhA-clause free* mex-operator) `(,@NUhA-clause ,@(*-null free*) ,@mex-operator)) (define (tanru-unit-2-SE SE-clause free* tanru-unit-2) `(,@SE-clause ,@(*-null free*) ,tanru-unit-2)) (define (tanru-unit-2-JAI JAI-clause free* tag? tanru-unit-2) `(,@JAI-clause ,@(*-null free*) ,@(?-null tag?) ,tanru-unit-2)) (define (tanru-unit-2-NAhE NAhE-clause free* tanru-unit-2) `(,@NAhE-clause ,@(*-null free*) ,tanru-unit-2)) (define (tanru-unit-2-NU NU-clause NAI-clause? free-0* joik-jek-NU* subsentence KEI-clause? free-1*) (define (joik-jek-NU joik-jek NU-clause NAI-clause? free*) `(,@joik-jek ,@NU-clause ,@(?-null NAI-clause?) ,@(*-null free*))) `(,@NU-clause ,@(?-null NAI-clause?) ,@(*-null free-0*) ,@(map-apply joik-jek-NU joik-jek-NU*) ,subsentence ,@(?-null KEI-clause?) ,@(*-null free-1*))) (define (linkargs linkargs-sa* linkargs-1) `(,@(*-null linkargs-sa*) ,@linkargs-1)) (define (linkargs-1 BE-clause free* term links? BEhO-clause? free*) `(,@BE-clause ,@(*-null free*) ,term ,@(?-null links?) ,@(?-null BEhO-clause?) ,@(*-null free*))) (define (linkargs-sa linkargs-start sa-word* SA-clause) `(sa-clause ,@linkargs-start ,@(*-null sa-word*) ,@SA-clause)) (define (linkargs-start BE-clause) BE-clause) (define (links links-sa* links-1) `(,@(*-null links-sa*) ,@links-1)) (define (links-sa links-start sa-word* SA-clause) `(sa-clause ,@links-start ,@(*-null sa-word*) ,@SA-clause)) (define (links-1 BEI-clause free* term links?) `(,@BEI-clause ,@(*-null free*) ,@term ,@(?-null links?))) (define (links-start BEI-clause) BEI-clause) (define (quantifier-BOI number BOI-clause? free*) `(,number ,@(?-null BOI-clause?) ,@(*-null free*))) (define (quantifier-VEI VEI-clause free-0* mex VEhO-clause? free-1*) `(,@VEI-clause ,@(*-null free-0*) ,@mex ,@(?-null VEhO-clause?) ,@(*-null free-1*))) (define (mex . rodasumti) `(mex ,@rodasumti)) (define (mex-sa . rodasumti) `(mex-sa ,@rodasumti)) (define (mex-0 . rodasumti) `(mex-0 ,@rodasumti)) (define (mex-0-rp . rodasumti) `(mex-0-rp ,@rodasumti)) (define (mex-start-FUhA . rodasumti) `(mex-start-FUhA ,@rodasumti)) (define (mex-start-PEhO . rodasumti) `(mex-start-PEhO ,@rodasumti)) (define (mex-start . rodasumti) `(mex-start ,@rodasumti)) (define (rp-clause . rodasumti) `(rp-clause ,@rodasumti)) (define (mex-1 . rodasumti) `(mex-1 ,@rodasumti)) (define (mex-2 . rodasumti) `(mex-2 ,@rodasumti)) (define (mex-forethought . rodasumti) `(mex-forethought ,@rodasumti)) (define (fore-operands . rodasumti) `(fore-operands ,@rodasumti)) (define (rp-expression . rodasumti) `(rp-expression ,@rodasumti)) (define (rp-expression-tail . rodasumti) `(rp-expression-tail ,@rodasumti)) (define (operator . rodasumti) `(operator ,@rodasumti)) (define (operator-0 . rodasumti) `(operator-0 ,@rodasumti)) (define (operator-0-joik-jek . rodasumti) `(operator-0-joik-jek ,@rodasumti)) (define (operator-0-joik . rodasumti) `(operator-0-joik ,@rodasumti)) (define (operator-sa . rodasumti) `(operator-sa ,@rodasumti)) (define (operator-start . rodasumti) `(operator-start ,@rodasumti)) (define (operator-start-KE . rodasumti) `(operator-start-KE ,@rodasumti)) (define (operator-start-NAhE . rodasumti) `(operator-start-NAhE ,@rodasumti)) (define (operator-start-MAhO . rodasumti) `(operator-start-MAhO ,@rodasumti)) (define (operator-start-VUhU . rodasumti) `(operator-start-VUhU ,@rodasumti)) (define (operator-1 . rodasumti) `(operator-1 ,@rodasumti)) (define (operator-gukek . rodasumti) `(operator-gukek ,@rodasumti)) (define (operator-jek . rodasumti) `(operator-jek ,@rodasumti)) (define (operator-2 . rodasumti) `(operator-2 ,@rodasumti)) (define (operator-2-KE . rodasumti) `(operator-2-KE ,@rodasumti)) (define (mex-operator . rodasumti) `(mex-operator ,@rodasumti)) (define (mex-operator-NAhE . rodasumti) `(mex-operator-NAhE ,@rodasumti)) (define (mex-operator-MAhO . rodasumti) `(mex-operator-MAhO ,@rodasumti)) (define (mex-operator-NAhU . rodasumti) `(mex-operator-NAhU ,@rodasumti)) (define (mex-operator-VUhU . rodasumti) `(mex-operator-VUhU ,@rodasumti)) (define (operand . rodasumti) `(operand ,@rodasumti)) (define (operand-sa . rodasumti) `(operand-sa ,@rodasumti)) (define (operand-0 . rodasumti) `(operand-0 ,@rodasumti)) (define (operand-start-quantifier . rodasumti) `(operand-start-quantifier ,@rodasumti)) (define (operand-start-lerfu-word . rodasumti) `(operand-start-lerfu-word ,@rodasumti)) (define (operand-start-NIhE . rodasumti) `(operand-start-NIhE ,@rodasumti)) (define (operand-start-MOhE . rodasumti) `(operand-start-MOhE ,@rodasumti)) (define (operand-start-JOhI . rodasumti) `(operand-start-JOhI ,@rodasumti)) (define (operand-start-gek . rodasumti) `(operand-start-gek ,@rodasumti)) (define (operand-start-LAhE . rodasumti) `(operand-start-LAhE ,@rodasumti)) (define (operand-start-NAhE . rodasumti) `(operand-start-NAhE ,@rodasumti)) (define (operand-1 . rodasumti) `(operand-1 ,@rodasumti)) (define (operand-2 . rodasumti) `(operand-2 ,@rodasumti)) (define (operand-3 . rodasumti) `(operand-3 ,@rodasumti)) (define (operand-3-BOI . rodasumti) `(operand-3-BOI ,@rodasumti)) (define (operand-3-NIhE . rodasumti) `(operand-3-NIhE ,@rodasumti)) (define (operand-3-MOhE . rodasumti) `(operand-3-MOhE ,@rodasumti)) (define (operand-3-JOhI . rodasumti) `(operand-3-JOhI ,@rodasumti)) (define (operand-3-gek . rodasumti) `(operand-3-gek ,@rodasumti)) (define (operand-3-LAhE . rodasumti) `(operand-3-LAhE ,@rodasumti)) (define (operand-3-NAhE . rodasumti) `(operand-3-NAhE ,@rodasumti)) (define (operand-BOI . rodasumti) `(operand-BOI ,@rodasumti)) (define (number PA-clause PA-clause-or-lerfu-word*) `(,@PA-clause ,@(*-null PA-clause-or-lerfu-word*))) (define (lerfu-string lerfu-word PA-clause-or-lerfu-word*) `(,@lerfu-word ,@(*-null PA-clause-or-lerfu-word*))) (define (lerfu-word-BY BY-clause) BY-clause) (define (lerfu-word-LAU LAU-clause lerfu-word) `(,@LAU-clause ,@lerfu-word)) (define (lerfu-word-TEI TEI-clause lerfu-string FOI-clause) `(,@TEI-clause ,@lerfu-string ,@FOI-clause)) (define (ek NA-clause? SE-clause? A-clause NAI-clause?) `(,@(?-null NA-clause?) ,@(?-null SE-clause?) ,@A-clause ,@(?-null NAI-clause?))) (define (gihek gihek-sa* gihek-1) `(gihek ,@(*-null gihek-sa*) ,gihek-1)) (define (gihek-sa gihek-1 sa-word* SA-clause) `(sa-clause ,@gihek-1 ,@(apply append (*-null sa-word*)) ,@SA-clause)) (define (gihek-1 NA-clause? SE-clause? GIhA-clause NAI-clause?) `(,@(?-null NA-clause?) ,@(?-null SE-clause?) ,@GIhA-clause ,@(?-null NAI-clause?))) (define (jek NA-clause? SE-clause? JA-clause NAI-clause?) `(jek ,@(?-null NA-clause?) ,@(?-null SE-clause?) ,@JA-clause ,@(?-null NAI-clause?))) (define (joik-JOI SE-clause? JOI-clause NAI-clause?) `(joik ,@(?-null SE-clause?) ,@JOI-clause ,@(?-null NAI-clause?))) (define (joik-interval interval) `(joik ,@interval)) (define (joik-GAhO GAhO-clause interval GAhO-clause) `(joik ,@GAhO-clause ,@interval ,@GAhO-clause)) (define (interval SE-clause? BIhI-clause NAI-clause?) `(,@(?-null SE-clause?) ,@BIhI-clause ,@(?-null NAI-clause?))) (define (joik-ek . rodasumti) `(joik-ek ,@rodasumti)) (define (joik-ek-sa . rodasumti) `(joik-ek-sa ,@rodasumti)) (define (joik-ek-1-joik . rodasumti) `(joik-ek-1-joik ,@rodasumti)) (define (joik-ek-1-ek . rodasumti) `(joik-ek-1-ek ,@rodasumti)) (define (joik-jek . rodasumti) `(joik-jek ,@rodasumti)) (define (gek-GA . rodasumti) `(gek-GA ,@rodasumti)) (define (gek-GI . rodasumti) `(gek-GI ,@rodasumti)) (define (gek-gik . rodasumti) `(gek-gik ,@rodasumti)) (define (guhek . rodasumti) `(guhek ,@rodasumti)) (define (gik . rodasumti) `(gik ,@rodasumti)) (define (tag tense-modal tense*) (define (tense joik-jek tense-modal) `(,@joik-jek ,@tense-modal)) `(,@tense-modal ,@(map-apply tense tense*))) (define (stag-tense simple-tense-modal sumti*) (define (tense joik-jek simple-tense-modal) `(,@joik-jek ,@simple-tense-modal)) `(,@simple-tense-modal ,@(map-apply tense sumti*))) (define (stag-simple-tense tense-modal sumti*) (define (tense joik-jek tense-modal) `(,@joik-jek ,@tense-modal)) `(,@tense-modal ,@(map-apply tense sumti*))) (define (tense-modal-simple-tense simple-tense-modal free*) `(,@simple-tense-modal ,@(*-null free*))) (define (tense-modal-FIhO FIhO-clause free-0* selbri FEhU-clause? free-1*) `(,@FIhO-clause ,@(*-null free-0*) ,@selbri ,@(?-null FEhU-clause?) ,@(*-null free-1*))) (define (simple-tense-modal-BAI NAhE-clause? SE-clause? BAI-clause NAI-clause? KI-clause?) `(,@(?-null NAhE-clause?) ,@(?-null SE-clause?) ,@BAI-clause ,@(?-null NAI-clause?) ,@(?-null KI-clause?))) (define (simple-tense-modal-time-space-CAhA time? space? CAhA-clause) `(,@(?-null time?) ,@(?-null space?) ,@CAhA-clause)) (define (simple-tense-modal-time-space time? space?) `(,@(?-null time?) ,@(?-null space?))) (define (simple-tense-modal-CAhA CAhA-clause) CAhA-clause) (define (simple-tense-modal NAhE-clause? time-space-CAhA KI-clause?) `(,@(?-null NAhE-clause?) ,@time-space-CAhA ,@(?-null KI-clause?))) (define (simple-tense-modal-KI KI-clause) KI-clause) (define (simple-tense-modal-CUhE CUhE-clause) CUhE-clause) (define (time-ZI ZI-clause? time-offset* ZEhA-clause? PU-clause? NAI-clause? interval-property*) `(,@(?-null ZI-clause?) ,@(*-null time-offset*) ,@(?-null ZEhA-clause?) ,@(?-null PU-clause?) ,@(?-null NAI-clause?) ,@(*-null interval-property*))) (define (time-offset PU-clause NAI-clause? ZI-clause?) `(,@PU-clause ,@(?-null NAI-clause?) ,@(?-null ZI-clause?))) (define (space VA-clause? space-offset* space-interval? MOhI-clause? space-offset?) `(,@(?-null VA-clause?) ,@(apply append space-offset*) ,@(?*-null space-interval?) ,@(?-null MOhI-clause?) ,@(?-null space-offset?))) (define (space-offset FAhA-clause NAI-clause? VA-clause?) `(,@FAhA-clause ,@(?-null NAI-clause?) ,@(?-null VA-clause?))) (define (space-interval-VEhA VEhA-clause VIhA-clause?) `(,@VEhA-clause ,@(?-null VIhA-clause))) (define (space-interval-VIhA VIhA-clause) VIhA-clause) (define (space-interval-VEhA-VIhA VEhA-clause FAhA-clause? NAI-clause? space-int-props?) `(,@VEhA-clause ,@(?-null FAhA-clause?) ,@(?-null NAI-clause?) ,@(?*-null space-int-props?))) (define (space-interval space-int-props) space-int-props) (define (space-int-props prop+) (define (prop FEhE-clause interval-property) `(,@FEhE-clause ,@interval-property)) (map-apply prop prop+)) (define (interval-property number ROI-clause NAI-clause?) `(,@number ,ROI-clause ,@(?-null NAI-clause?))) (define (interval-property-TAhE TAhE-clause NAI-clause?) `(,@TAhE-clause ,@(?-null NAI-clause?))) (define (interval-property-ZAhO ZAhO-clause NAI-clause?) `(,@ZAhO-clause ,@(?-null NAI-clause?))) (define (free-SEI SEI-clause free-0* terms? CU-terms? free-1* selbri SEhU-clause?) `(,@SEI-clause ,@(*-null free-0*) ,@(?*-null terms?) ,@(?-null CU-terms?) ,@(?*-null free-1*) ,@selbri ,@(?-null SEhU-clause?))) (define (free-SOI SOI-clause free* sumti sumti? SEhU-clause?) `(,@SOI-clause ,@(*-null free*) ,@sumti ,@(?-null sumti?) ,@(?-null SEhU-clause?))) (define (free-vocative-selbri vocative relative-clauses-0? selbri relative-clauses-1? DOhU-clause?) `(,@vocative ,@(?-null relative-clauses-0?) ,@selbri ,@(?-null relative-clauses-1?) ,@(?-null DOhU-clause?))) (define (free-vocative-cmene vocative relative-clauses-0? CMENE-clause+ free* relative-clauses-1? DOhU-clause?) `(,@vocative ,@(?-null relative-clauses-0?) ,@CMENE-clause+ ,@(*-null free*) ,@(?-null relative-clauses-1?) ,@(?-null DOhU-clause?))) (define (free-vocative-sumti vocative sumti? DOhU-clause?) `(,@vocative ,@(?-null sumti?) ,@(?-null DOhU-clause?))) (define (free-MAI number-or-lerfu-string MAI-clause) `(,@number-or-lerfu-string ,@MAI-clause)) (define (free-TO TO-clause text TOI-clause?) `(,@TO-clause ,text ,@(?-null TOI-clause?))) (define (xi-clause-BOI XI-clause free* number-or-lerfu-string BOI-clause?) `(,@XI-clause ,@(*-null free*) ,@number-or-lerfu-string ,@(?-null BOI-clause?))) (define (xi-clause-VEI XI-clause free-0* VEI-clause free-1* mex VEhO-clause?) `(,@XI-clause ,@(*-null free-0*) ,@VEI-clause ,@(*-null free-1*) ,@mex ,@(?-null VEhO-clause?))) ;; XXX: I may want to flatten single-element * clauses, much ;; like I do je rules. ;; (define (vocative COI-NAI?-clause* #!optional (DOI-clause? "")) (define (COI-NAI? COI-clause NAI-clause?) `(,@COI-clause ,@(?-null NAI-clause?))) `(,@(apply append (map-apply COI-NAI? COI-NAI?-clause*)) ,@(?*-null DOI-clause?))) (define (indicators FUhE-clause? indicator+) `(,@(?-null FUhE-clause?) ,@(apply append indicator+))) (define (indicator clause #!optional (NAhE-clause? "")) `(,@clause ,@(?-null NAhE-clause?))) (define (zei-clause pre-clause zei-clause-no-pre) `(,@pre-clause ,@zei-clause-no-pre)) (define (zei-clause-no-pre pre-zei-bu zei-bu* zei-tail post-clause) (define (zei-bu zei-tail? bu-tail) `(,@(?-null zei-tail?) ,@bu-tail)) `(,@pre-zei-bu ,@(map-apply zei-bu zei-bu*) ,@(apply append zei-tail) ,@post-clause)) (define (bu-clause pre-clause bu-clause-no-pre) `(,@pre-clause ,@bu-clause-no-pre)) (define (bu-clause-no-pre pre-zei-bu bu-zei* bu-tail post-clause) (define (bu-zei bu-tail? zei-tail) `(,@(?-null bu-tail?) ,@zei-tail)) `(,@pre-zei-bu ,@(map-apply bu-zei bu-zei*) ,@bu-tail ,@post-clause)) (define (zei-tail zei+) (define (zei ZEI-clause any-word) `(,ZEI-clause ,any-word)) (map-apply zei zei+)) (define (bu-tail BU-clause+) BU-clause+) (define (pre-zei-bu any-word si-clause?) `(,any-word ,@(?-null si-clause?))) (define (post-clause si-clause? indicators*) `(,@(?-null si-clause?) ,@(*-null indicators*))) (define (pre-clause BAhE-clause?) (?-null BAhE-clause?)) (define (any-word-SA-LOhU LOhU-pre) `(any-string ,@LOhU-pre)) (define (any-word-SA-ZO ZO-pre) `(any-word ,@ZO-pre)) (define (any-word-SA-ZOI ZOI-pre) `(any-string ,@ZOI-pre)) (define (su-clause clause* SU-clause) `(su-clause ,@clause* ,SU-clause)) (define (si-clause si+) (define (si clause si-clause? SI-clause) `(,@clause ,@(?*-null si-clause?) ,SI-clause)) `(si-clause ,@(apply append (map-apply si si+)))) (define (erasable-clause-bu bu-clause-no-pre) bu-clause-no-pre) (define (erasable-clause-zei zei-clause-no-pre) `((brivla ,@zei-clause-no-pre))) (define (sa-word pre-zei-bu) pre-zei-bu) (define (si-word pre-zei-bu) pre-zei-bu) (define (su-word any-word-SA) any-word-SA) (define (BRIVLA-clause BRIVLA-pre BRIVLA-post) `(BRIVLA-clause ,BRIVLA-pre ,@BRIVLA-post)) (define (BRIVLA-clause-zei zei-clause) `(BRIVLA-clause ,@zei-clause)) (define (BRIVLA-pre pre-clause BRIVLA) `(,@pre-clause ,@BRIVLA)) (define (BRIVLA-post post-clause) post-clause) (define (CMENE-clause CMENE-pre CMENE-post) `(CMENE-clause ,CMENE-pre ,@CMENE-post)) (define (CMENE-pre pre-clause CMENE) `(,@pre-clause ,@CMENE)) (define (CMENE-post post-clause) post-clause) (define (CMAVO-clause pre-clause CMAVO) `(,@pre-clause ,@CMAVO)) (define (A-clause A-pre A-post) `((A-clause ,A-pre ,@A-post))) (define (A-pre pre-clause A) `(,@pre-clause ,@A)) (define (A-post post-clause) post-clause) (define (BAI-clause BAI-pre BAI-post) `(BAI-clause ,BAI-pre ,@BAI-post)) (define (BAI-pre pre-clause BAI) `(,@pre-clause ,@BAI)) (define (BAI-post post-clause) post-clause) (define (BAhE-clause clause+) (define (BAhE BAhE-pre BAhE-post) `(,@BAhE-pre ,@BAhE-post)) `((BAhE-clause ,@(map-apply BAhE clause+)))) (define (BAhE-pre BAhE) BAhE) (define (BAhE-post si-clause?) (?-null si-clause?)) (define (BE-clause BE-pre BE-post) `(BE-clause ,BE-pre ,@BE-post)) (define (BE-pre pre-clause BE) `(,@pre-clause ,@BE)) (define (BE-post post-clause) post-clause) (define (BEI-clause BEI-pre BEI-post) `(BEI-clause ,BEI-pre ,@BEI-post)) (define (BEI-pre pre-clause BEI) `(,@pre-clause ,@BEI)) (define (BEI-post post-clause) post-clause) (define (BEhO-clause BEhO-pre BEhO-post) `(BEhO-clause ,BEhO-pre ,@BEhO-post)) (define (BEhO-pre pre-clause BEhO) `(,@pre-clause ,@BEhO)) (define (BEhO-post post-clause) post-clause) (define (BIhE-clause BIhE-pre BIhE-post) `(BIhE-clause ,BIhE-pre ,@BIhE-post)) (define (BIhE-pre pre-clause BIhE) `(,@pre-clause ,@BIhE)) (define (BIhE-post post-clause) post-clause) (define (BIhI-clause BIhI-pre BIhI-post) `(BIhI-clause ,BIhI-pre ,@BIhI-post)) (define (BIhI-pre pre-clause BIhI) `(,@pre-clause ,@BIhI)) (define (BIhI-post post-clause) post-clause) (define (BO-clause BO-pre BO-post) `(BO-clause ,BO-pre ,@BO-post)) (define (BO-pre pre-clause BO) `(,@pre-clause ,@BO)) (define (BO-post post-clause) post-clause) (define (BOI-clause BOI-pre BOI-post) `(BOI-clause ,BOI-pre ,@BOI-post)) (define (BOI-pre pre-clause bOI) `(,@pre-clause ,@bOI)) (define (BOI-post post-clause) post-clause) (define (BU-clause pre-clause BU) `(,@pre-clause ,@BU)) (define (BY-clause BY-pre BY-post) `(BY-clause ,BY-pre ,@BY-post)) (define (BY-clause-bu bu-clause) `(BY-clause ,@bu-clause)) (define (BY-pre pre-clause BY) `(,@pre-clause ,@BY)) (define (BY-post post-clause) post-clause) (define (CAhA-clause . rodasumti) `(CAhA-clause ,@rodasumti)) (define (CAhA-pre pre-clause CAhA) `(,@pre-clause ,@CAhA)) (define (CAhA-post post-clause) post-clause) (define (CAI-clause . rodasumti) `(CAI-clause ,@rodasumti)) (define (CAI-pre pre-clause CAI) `(,@pre-clause ,@CAI)) (define (CAI-post post-clause) post-clause) (define (CEI-clause . rodasumti) `(CEI-clause ,@rodasumti)) (define (CEI-pre pre-clause CEI) `(,@pre-clause ,@CEI)) (define (CEI-post post-clause) post-clause) (define (CEhE-clause . rodasumti) `(CEhE-clause ,@rodasumti)) (define (CEhE-pre pre-clause CEhE) `(,@pre-clause ,@CEhE)) (define (CEhE-post post-clause) post-clause) (define (CO-clause . rodasumti) `(CO-clause ,@rodasumti)) (define (CO-pre pre-clause CO) `(,@pre-clause ,@CO)) (define (CO-post post-clause) post-clause) (define (COI-clause COI-pre COI-post) `((COI-clause ,COI-pre ,@COI-post))) (define (COI-pre pre-clause COI) `(,@pre-clause ,@COI)) (define (COI-post post-clause) post-clause) (define (CU-clause CU-pre CU-post) `(CU-clause ,CU-pre ,@CU-post)) (define (CU-pre pre-clause CU) `(,@pre-clause ,@CU)) (define (CU-post post-clause) post-clause) (define (CUhE-clause . rodasumti) `(CUhE-clause ,@rodasumti)) (define (CUhE-pre pre-clause CUhE) `(,@pre-clause ,@CUhE)) (define (CUhE-post post-clause) post-clause) (define (DAhO-clause . rodasumti) `(DAhO-clause ,@rodasumti)) (define (DAhO-pre pre-clause DAhO) `(,@pre-clause ,@DAhO)) (define (DAhO-post post-clause) post-clause) (define (DOI-clause DOI-pre DOI-post) `(DOI-clause ,DOI-pre ,@DOI-post)) (define (DOI-pre pre-clause DOI) `(,@pre-clause ,@DOI)) (define (DOI-post post-clause) post-clause) (define (DOhU-clause DOI-pre DOI-post) `(DOhU-clause ,DOI-pre ,@DOI-post)) (define (DOhU-pre pre-clause DOhU) `(,@pre-clause ,@DOhU)) (define (DOhU-post post-clause) post-clause) (define (FA-clause FA-pre FA-post) `(FA-clause ,FA-pre ,@FA-post)) (define (FA-pre pre-clause FA) `(,@pre-clause ,@FA)) (define (FA-post post-clause) post-clause) (define (FAhA-clause FAhA-pre FAhA-post) `(FAhA-clause ,FAhA-pre ,@FAhA-post)) (define (FAhA-pre pre-clause FAhA) `(,@pre-clause ,@FAhA)) (define (FAhA-post post-clause) post-clause) (define (FAhO-clause pre-clause FAhO) `(FAhO-clause ,@pre-clause ,FAhO)) (define (FEhE-clause FEhE-pre FEhE-post) `(FEhE-clause ,FEhE-pre ,@FEhE-post)) (define (FEhE-pre pre-clause FEhE) `(,@pre-clause ,@FEhE)) (define (FEhE-post post-clause) post-clause) (define (FEhU-clause FEhU-pre FEhU-post) `(FEhU-clause ,FEhU-pre ,@FEhU-post)) (define (FEhU-pre pre-clause FEhU) `(,@pre-clause ,@FEhU)) (define (FEhU-post post-clause) post-clause) (define (FIhO-clause FIhO-pre FIhO-post) `(FIhO-clause ,FIhO-pre ,@FIhO-post)) (define (FIhO-pre pre-clause FIhO) `(,@pre-clause ,@FIhO)) (define (FIhO-post post-clause) post-clause) (define (FOI-clause FOI-pre FOI-post) `(FOI-clause ,FOI-pre ,@FOI-post)) (define (FOI-pre pre-clause FOI) `(,@pre-clause ,@FOI)) (define (FOI-post post-clause) post-clause) (define (FUhA-clause FUhA-pre FUhA-post) `(FUhA-clause ,FUhA-pre ,@FUhA-post)) (define (FUhA-pre pre-clause FUhA) `(,@pre-clause ,@FUhA)) (define (FUhA-post post-clause) post-clause) (define (FUhE-clause FUhE-pre FUhE-post) `(FUhE-clause ,FUhO-pre ,@FUhE-post)) (define (FUhE-pre pre-clause FUhE) `(,@pre-clause ,@FUhE)) (define (FUhE-post post-clause) post-clause) (define (FUhO-clause FUhO-pre FUhO-post) `(FUhO-clause ,FUhO-pre ,@FUhO-post)) (define (FUhO-pre pre-clause FUhO) `(,@pre-clause ,@FUhO)) (define (FUhO-post post-clause) post-clause) (define (GA-clause . rodasumti) `(GA-clause ,@rodasumti)) (define (GA-pre pre-clause GA) `(,@pre-clause ,@GA)) (define (GA-post post-clause) post-clause) (define (GAhO-clause GAhO-pre GAhO-post) `(GAhO-clause ,GAhO-pre ,@GAhO-post)) (define (GAhO-pre pre-clause GAhO) `(,@pre-clause ,@GAhO)) (define (GAhO-post post-clause) post-clause) (define (GEhU-clause . rodasumti) `(GEhU-clause ,@rodasumti)) (define (GEhU-pre pre-clause GEhU) `(,@pre-clause ,@GEhU)) (define (GEhU-post post-clause) post-clause) (define (GI-clause . rodasumti) `(GI-clause ,@rodasumti)) (define (GI-pre pre-clause GI) `(,@pre-clause ,@GI)) (define (GI-post post-clause) post-clause) (define (GIhA-clause . rodasumti) `(GIhA-clause ,@rodasumti)) (define (GIhA-pre pre-clause GIhA) `(,@pre-clause ,@GIhA)) (define (GIhA-post post-clause) post-clause) (define (GOI-clause GOI-pre GOI-post) `(GOI-clause ,GOI-pre ,@GOI-post)) (define (GOI-pre pre-clause GOI) `(,@pre-clause ,@GOI)) (define (GOI-post post-clause) post-clause) (define (GOhA-clause GOhA-pre GOhA-post) `(GOhA-clause ,GOhA-pre ,@GOhA-post)) (define (GOhA-pre pre-clause GOhA) `(,@pre-clause ,@GOhA)) (define (GOhA-post post-clause) post-clause) (define (GUhA-clause . rodasumti) `(GUhA-clause ,@rodasumti)) (define (GUhA-pre pre-clause GUhA) `(,@pre-clause ,@GUhA)) (define (GUhA-post post-clause) post-clause) (define (I-clause sentence-sa* I-pre I-post) `(I-clause ,@(*-null sentence-sa*) ,I-pre ,@I-post)) (define (I-pre pre-clause I) `(,@pre-clause ,@I)) (define (I-post post-clause) post-clause) (define (JA-clause . rodasumti) `(JA-clause ,@rodasumti)) (define (JA-pre pre-clause JA) `(,@pre-clause ,@JA)) (define (JA-post post-clause) post-clause) (define (JAI-clause . rodasumti) `(JAI-clause ,@rodasumti)) (define (JAI-pre pre-clause JAI) `(,@pre-clause ,@JAI)) (define (JAI-post post-clause) post-clause) (define (JOhI-clause . rodasumti) `(JOhI-clause ,@rodasumti)) (define (JOhI-pre pre-clause JOhI) `(,@pre-clause ,@JOhI)) (define (JOhI-post post-clause) post-clause) (define (JOI-clause . rodasumti) `(JOI-clause ,@rodasumti)) (define (JOI-pre pre-clause JOI) `(,@pre-clause ,@JOI)) (define (JOI-post post-clause) post-clause) (define (KE-clause . rodasumti) `(KE-clause ,@rodasumti)) (define (KE-pre pre-clause KE) `(,@pre-clause ,@KE)) (define (KE-post post-clause) post-clause) (define (KEhE-clause . rodasumti) `(KEhE-clause ,@rodasumti)) (define (KEhE-pre pre-clause KEhE) `(,@pre-clause ,@KEhE)) (define (KEhE-post post-clause) post-clause) (define (KEI-clause KEI-pre KEI-post) `(KEI-clause ,KEI-pre ,@KEI-post)) (define (KEI-pre pre-clause KEI) `(,@pre-clause ,@KEI)) (define (KEI-post post-clause) post-clause) (define (KI-clause . rodasumti) `(KI-clause ,@rodasumti)) (define (KI-pre pre-clause KI) `(,@pre-clause ,@KI)) (define (KI-post post-clause) post-clause) (define (KOhA-clause KOhA-pre KOhA-post) `(KOhA-clause ,KOhA-pre ,@KOhA-post)) (define (KOhA-pre pre-clause KOhA) `(,@pre-clause ,@KOhA)) (define (KOhA-post post-clause) post-clause) (define (KU-clause KU-pre KU-post) `(KU-clause ,KU-pre ,@KU-post)) (define (KU-pre pre-clause KU) `(,@pre-clause ,@KU)) (define (KU-post post-clause) post-clause) (define (KUhE-clause . rodasumti) `(KUhE-clause ,@rodasumti)) (define (KUhE-pre pre-clause KUhE) `(,@pre-clause ,@KUhE)) (define (KUhE-post post-clause) post-clause) (define (KUhO-clause . rodasumti) `(KUhO-clause ,@rodasumti)) (define (KUhO-pre pre-clause KUhO) `(,@pre-clause ,@KUhO)) (define (KUhO-post post-clause) post-clause) (define (LA-clause LA-pre LA-post) `(LA-clause ,LA-pre ,@LA-post)) (define (LA-pre pre-clause LA) `(,@pre-clause ,@LA)) (define (LA-post post-clause) post-clause) (define (LAU-clause . rodasumti) `(LAU-clause ,@rodasumti)) (define (LAU-pre pre-clause LAU) `(,@pre-clause ,@LAU)) (define (LAU-post post-clause) post-clause) (define (LAhE-clause LAhE-pre LAhE-post) `(LAhE-clause ,LAhE-pre ,@LAhE-post)) (define (LAhE-pre pre-clause LAhE) `(,@pre-clause ,@LAhE)) (define (LAhE-post post-clause) post-clause) (define (LE-clause LE-pre LE-post) `(LE-clause ,LE-pre ,@LE-post)) (define (LE-pre pre-clause LE) `(,@pre-clause ,@LE)) (define (LE-post post-clause) post-clause) (define (LEhU-clause LEhU-pre) `(LEhU-clause ,LEhU-pre)) (define (LEhU-pre pre-clause LEhU) `(,@pre-clause ,@LEhU)) (define (LI-clause LI-pre LI-post) `(LI-clause ,LI-pre ,@LI-post)) (define (LI-pre pre-clause LI) `(,@pre-clause ,@LI)) (define (LI-post post-clause) post-clause) (define (LIhU-clause LIhU-pre LIhU-post) `(LIhU-clause ,LIhU-pre ,@LIhU-post)) (define (LIhU-pre pre-clause LIhU) `(,@pre-clause ,@LIhU)) (define (LIhU-post post-clause) post-clause) (define (LOhO-clause LOhO-pre LOhO-post) `(LOhO-clause ,LOhO-pre ,@LOhO-post)) (define (LOhO-pre pre-clause LOhO) `(,@pre-clause ,@LOhO)) (define (LOhO-post post-clause) post-clause) (define (LOhU-clause LOhU-pre LOhU-post) `(LOhU-clause ,@LOhU-pre ,@LOhU-post)) (define (LOhU-pre pre-clause LOhU any-word* LEhU-clause) `(,@pre-clause ,LOhU ,@(*-null any-word*) ,LEhU-clause)) (define (LOhU-post post-clause) post-clause) (define (LU-clause LU-pre LU-post) `(LU-clause ,LU-pre ,@LU-post)) (define (LU-pre pre-clause LU) `(,@pre-clause ,@LU)) (define (LU-post post-clause) post-clause) (define (LUhU-clause LUhU-pre LUhU-post) `(LUhU-clause ,LUhU-pre ,@LUhU-post)) (define (LUhU-pre pre-clause LUhU) `(,@pre-clause ,@LUhU)) (define (LUhU-post post-clause) post-clause) (define (MAhO-clause MAhO-pre MAhO-post) `(MAhO-clause ,MAhO-pre ,@MAhO-post)) (define (MAhO-pre pre-clause MAhO) `(,@pre-clause ,@MAhO)) (define (MAhO-post post-clause) post-clause) (define (MAI-clause MAI-pre MAI-post) `(MAI-clause ,MAI-pre ,@MAI-post)) (define (MAI-pre pre-clause MAI) `(,@pre-clause ,@MAI)) (define (MAI-post post-clause) post-clause) (define (ME-clause ME-pre ME-post) `(ME-clause ,ME-pre ,@ME-post)) (define (ME-pre pre-clause ME) `(,@pre-clause ,@ME)) (define (ME-post post-clause) post-clause) (define (MEhU-clause MEhU-pre MEhU-post) `(MEhU-clause ,MEhU-pre ,@MEhU-post)) (define (MEhU-pre pre-clause MEhU) `(,@pre-clause ,@MEhU)) (define (MEhU-post post-clause) post-clause) (define (MOhE-clause MOhE-pre MOhE-post) `(MOhE-clause ,MOhE-pre ,@MOhE-post)) (define (MOhE-pre pre-clause MOhE) `(,@pre-clause ,@MOhE)) (define (MOhE-post post-clause) post-clause) (define (MOhI-clause MOhI-pre MOhI-post) `(MOhI-clause ,MOhI-pre ,@MOhI-post)) (define (MOhI-pre pre-clause MOhI) `(,@pre-clause ,@MOhI)) (define (MOhI-post post-clause) post-clause) (define (MOI-clause MOI-pre MOI-post) `(MOI-clause ,MOI-pre ,@MOI-post)) (define (MOI-pre pre-clause MOI) `(,@pre-clause ,@MOI)) (define (MOI-post post-clause) post-clause) (define (NA-clause NA-pre NA-post) `(NA-clause ,NA-pre ,@NA-post)) (define (NA-pre pre-clause NA) `(,@pre-clause ,@NA)) (define (NA-post post-clause) post-clause) (define (NAI-clause NAI-pre NAI-post) `(NAI-clause ,NAI-pre ,@NAI-post)) (define (NAI-pre pre-clause NAI) `(,@pre-clause ,@NAI)) (define (NAI-post post-clause) post-clause) (define (NAhE-clause NAhE-pre NAhE-post) `(NAhE-clause ,NAhE-pre ,@NAhE-post)) (define (NAhE-pre pre-clause NAhE) `(,@pre-clause ,@NAhE)) (define (NAhE-post post-clause) post-clause) (define (NAhU-clause NAhU-pre NAhU-post) `(NAhU-clause ,NAhU-pre ,@NAhU-post)) (define (NAhU-pre pre-clause NAhU) `(,@pre-clause ,@NAhU)) (define (NAhU-post post-clause) post-clause) (define (NIhE-clause NIhE-pre NIhE-post) `(NIhE-clause ,NIhE-pre ,@NIhE-post)) (define (NIhE-pre pre-clause NIhE) `(,@pre-clause ,@NIhE)) (define (NIhE-post post-clause) post-clause) (define (NIhO-clause sentence-sa* NIhO-pre NIhO-post) `(NIhO-clause ,@(*-null sentence-sa*) ,@NIhO-pre ,@NIhO-post)) (define (NIhO-pre pre-clause NIhO) `(,@pre-clause ,@NIhO)) (define (NIhO-post su-clause* post-clause) `(,@(*-null su-clause*) ,@post-clause)) (define (NOI-clause NOI-pre NOI-post) `(NOI-clause ,NOI-pre ,@NOI-post)) (define (NOI-pre pre-clause NOI) `(,@pre-clause ,@NOI)) (define (NOI-post post-clause) post-clause) (define (NU-clause NU-pre NU-post) `(NU-clause ,NU-pre ,@NU-post)) (define (NU-pre pre-clause NU) `(,@pre-clause ,@NU)) (define (NU-post post-clause) post-clause) (define (NUhA-clause NUhA-pre NUhA-post) `(NUhA-clause ,NUhA-pre ,@NUhA-post)) (define (NUhA-pre pre-clause NUhA) `(,@pre-clause ,@NUhA)) (define (NUhA-post post-clause) post-clause) (define (NUhI-clause NUhI-pre NUhI-post) `(NUhI-clause ,NUhI-pre ,@NUhI-post)) (define (NUhI-pre pre-clause NUhI) `(,@pre-clause ,@NUhI)) (define (NUhI-post post-clause) post-clause) (define (NUhU-clause NUhU-pre NUhU-post) `(NUhU-clause ,NUhU-pre ,@NUhU-post)) (define (NUhU-pre pre-clause NUhU) `(,@pre-clause ,@NUhU)) (define (NUhU-post post-clause) post-clause) (define (PA-clause PA-pre PA-post) `(PA-clause ,PA-pre ,@PA-post)) (define (PA-pre pre-clause PA) `(,@pre-clause ,@PA)) (define (PA-post post-clause) post-clause) (define (PEhE-clause PEhE-pre PEhE-post) `(PEhE-clause ,PEhE-pre ,@PEhE-post)) (define (PEhE-pre pre-clause PEhE) `(,@pre-clause ,@PEhE)) (define (PEhE-post post-clause) post-clause) (define (PEhO-clause PEhO-pre PEhO-post) `(PEhO-clause ,PEhO-pre ,@PEhO-post)) (define (PEhO-pre pre-clause PEhO) `(,@pre-clause ,@PEhO)) (define (PEhO-post post-clause) post-clause) (define (PU-clause PU-pre PU-post) `(PU-clause ,PU-pre ,@PU-post)) (define (PU-pre pre-clause PU) `(,@pre-clause ,@PU)) (define (PU-post post-clause) post-clause) (define (RAhO-clause RAhO-pre RAhO-post) `(RAhO-clause ,RAhO-pre ,@RAhO-post)) (define (RAhO-pre pre-clause RAhO) `(,@pre-clause ,@RAhO)) (define (RAhO-post post-clause) post-clause) (define (ROI-clause ROI-pre ROI-post) `(ROI-clause ,ROI-pre ,@ROI-post)) (define (ROI-pre pre-clause ROI) `(,@pre-clause ,@ROI)) (define (ROI-post post-clause) post-clause) (define (SA-clause SA-pre) `((SA-clause ,SA-pre))) (define (SA-pre pre-clause SA) `(,@pre-clause ,@SA)) (define (SE-clause SE-pre SE-post) `(SE-clause ,SE-pre ,@SE-post)) (define (SE-pre pre-clause SE) `(,@pre-clause ,@SE)) (define (SE-post post-clause) post-clause) (define (SEI-clause SEI-pre SEI-post) `(SEI-clause ,SEI-pre ,@SEI-post)) (define (SEI-pre pre-clause SEI) `(,@pre-clause ,@SEI)) (define (SEI-post post-clause) post-clause) (define (SEhU-clause SEhU-pre SEhU-post) `(SEhU-clause ,SEhU-pre ,@SEhU-post)) (define (SEhU-pre pre-clause SEhU) `(,@pre-clause ,@SEhU)) (define (SEhU-post post-clause) post-clause) (define (SI-clause SI) `(SI-clause ,SI)) (define (SI-pre pre-clause SI) `(,@pre-clause ,@SI)) (define (SI-post post-clause) post-clause) (define (SOI-clause SOI-pre SOI-post) `(SOI-clause ,SOI-pre ,@SOI-post)) (define (SOI-pre pre-clause SOI) `(,@pre-clause ,@SOI)) (define (SOI-post post-clause) post-clause) (define (SU-clause SU-pre SU-post) `(SU-clause ,SU-pre ,@SU-post)) (define (SU-pre pre-clause SU) `(,@pre-clause ,@SU)) (define (SU-post post-clause) post-clause) (define (TAhE-clause TAhE-pre TAhE-post) `(TAhE-clause ,TAhE-pre ,@TAhE-post)) (define (TAhE-pre pre-clause TAhE) `(,@pre-clause ,@TAhE)) (define (TAhE-post post-clause) post-clause) (define (TEhU-clause TEhU-pre TEhU-post) `(TEhU-clause ,TEhU-pre ,@TEhU-post)) (define (TEhU-pre pre-clause TEhU) `(,@pre-clause ,@TEhU)) (define (TEhU-post post-clause) post-clause) (define (TEI-clause TEI-pre TEI-post) `(TEI-clause ,TEI-pre ,@TEI-post)) (define (TEI-pre pre-clause TEI) `(,@pre-clause ,@TEI)) (define (TEI-post post-clause) post-clause) (define (TO-clause TO-pre TO-post) `(TO-clause ,TO-pre ,@TO-post)) (define (TO-pre pre-clause TO) `(,@pre-clause ,@TO)) (define (TO-post post-clause) post-clause) (define (TOI-clause TOI-pre TOI-post) `(TOI-clause ,TOI-pre ,@TOI-post)) (define (TOI-pre pre-clause TOI) `(,@pre-clause ,@TOI)) (define (TOI-post post-clause) post-clause) (define (TUhE-clause TUhE-pre TUhE-post) `(TUhE-clause ,TUhE-pre ,@TUhE-post)) (define (TUhE-pre pre-clause TUhE) `(,@pre-clause ,@TUhE)) (define (TUhE-post su-clause* post-clause) `(,@(*-null su-clause*) ,@post-clause)) (define (TUhU-clause TUhU-pre TUhU-post) `(TUhU-clause ,TUhU-pre TUhU-post)) (define (TUhU-pre pre-clause TUhU) `(,@pre-clause ,@TUhU)) (define (TUhU-post post-clause) post-clause) (define (UI-clause UI-pre UI-post) `(UI-clause ,UI-pre ,@UI-post)) (define (UI-pre pre-clause UI) `(,@pre-clause ,@UI)) (define (UI-post post-clause) post-clause) (define (VA-clause VA-pre VA-post) `(VA-clause ,VA-pre ,@VA-post)) (define (VA-pre pre-clause VA) `(,@pre-clause ,@VA)) (define (VA-post post-clause) post-clause) (define (VAU-clause VAU-pre VAU-post) `(VAU-clause ,VAU-pre ,@VAU-post)) (define (VAU-pre pre-clause VAU) `(,@pre-clause ,@VAU)) (define (VAU-post post-clause) post-clause) (define (VEI-clause VEI-pre VEI-post) `(VEI-clause ,VEI-pre ,@VEI-post)) (define (VEI-pre pre-clause VEI) `(,@pre-clause ,@VEI)) (define (VEI-post post-clause) post-clause) (define (VEhO-clause VEhO-pre VEhO-post) `(VEhO-clause ,VEhO-pre ,@VEhO-post)) (define (VEhO-pre pre-clause VEhO) `(,@pre-clause ,@VEhO)) (define (VEhO-post post-clause) post-clause) (define (VUhU-clause VUhU-pre VUhU-post) `(VUhU-clause ,VUhU-pre ,@VUhU-post)) (define (VUhU-pre pre-clause VUhU) `(,@pre-clause ,@VUhU)) (define (VUhU-post post-clause) post-clause) (define (VEhA-clause VEhA-pre VEhA-post) `(VEhA-clause ,VEhA-pre ,@VEhA-post)) (define (VEhA-pre pre-clause VEhA) `(,@pre-clause ,@VEhA)) (define (VEhA-post post-clause) post-clause) (define (VIhA-clause VEhA-pre VEhA-post) `(VIhA-clause ,VEhA-pre ,@VEhA-post)) (define (VIhA-pre pre-clause VIhA) `(,@pre-clause ,@VIhA)) (define (VIhA-post post-clause) post-clause) (define (VUhO-clause VUhO-pre VUhO-post) `(VUhO-clause ,VUhO-pre ,@VUhO-post)) (define (VUhO-pre pre-clause VUhO) `(,@pre-clause ,@VUhO)) (define (VUhO-post post-clause) post-clause) (define (XI-clause XI-pre XI-post) `(XI-clause ,XI-pre ,@XI-post)) (define (XI-pre pre-clause XI) `(,@pre-clause ,@XI)) (define (XI-post post-clause) post-clause) ;(define (Y-clause Y) ; `((Y-clause ,@Y))) (define (ZAhO-clause ZAhO-pre ZAhO-post) `(ZAhO-clause ,ZAhO-pre ,@ZAhO-post)) (define (ZAhO-pre pre-clause ZAhO) `(,@pre-clause ,@ZAhO)) (define (ZAhO-post post-clause) post-clause) (define (ZEhA-clause ZEhA-pre ZEhA-post) `(ZEhA-clause ,ZEhA-pre ,@ZEhA-post)) (define (ZEhA-pre pre-clause ZEhA) `(,@pre-clause ,@ZEhA)) (define (ZEhA-post post-clause) post-clause) (define (ZEI-clause ZEI-pre) `(ZEI-clause ,ZEI-pre)) (define (ZEI-pre pre-clause ZEI) `(,@pre-clause ,@ZEI)) (define (ZI-clause ZI-pre ZI-post) `(ZI-clause ,ZI-pre ,@ZI-post)) (define (ZI-pre pre-clause ZI) `(,@pre-clause ,@ZI)) (define (ZI-post post-clause) post-clause) (define (ZIhE-clause ZIhE-pre ZIhE-post) `(ZIhE-clause ,ZIhE-pre ,@ZIhE-post)) (define (ZIhE-pre pre-clause ZIhE) `(,@pre-clause ,@ZIhE)) (define (ZIhE-post post-clause) post-clause) (define (ZO-clause ZO-pre ZO-post) `(ZO-clause ,@ZO-pre ,@ZO-post)) (define (ZO-pre pre-clause ZO any-word) `(,@pre-clause ,ZO ,any-word)) (define (ZO-post post-clause) post-clause) (define (ZOI-clause ZOI-pre ZOI-post) `(ZOI-clause ,@ZOI-pre ,@ZOI-post)) (define (ZOI-pre pre-clause ZOI zoi-open zoi-word* zoi-close) `(,@pre-clause ,ZOI ,zoi-open ,@(*-null zoi-word*) ,zoi-close)) (define (ZOI-post post-clause) post-clause) (define (ZOhU-clause ZOhU-pre ZOhU-post) `(ZOhU-clause ,ZOhU-pre ,@ZOhU-post)) (define (ZOhU-pre pre-clause ZOhU) `(,@pre-clause ,@ZOhU)) (define (ZOhU-post post-clause) post-clause) ;; zoi ;; (define-values (zoi-open zoi-word zoi-close) (let ((zoi '())) (values (lambda (any-word) (set! zoi any-word) any-word) (lambda (any-word) (if (not (equal=? zoi any-word)) any-word #f)) (lambda (any-word) (if (equal=? zoi any-word) any-word #f)))))
true
5651a16ca34bac4d91669950d01fac0c752cc7de
bf1c9803ae38f9aad027fbe4569ccc6f85ba63ab
/chapter_2/2.4.Multiple.Representations.for.Abstract.Data/ex_2.73.scm
a5c8aea62c45715b8fa5bb565cc6ee7e92eee9db
[]
no_license
mehese/sicp
7fec8750d3b971dd2383c240798dbed339d0345a
611b09280ab2f09cceb2479be98ccc5403428c6c
refs/heads/master
2021-06-12T04:43:27.049197
2021-04-04T22:22:47
2021-04-04T22:23:12
161,924,666
0
0
null
null
null
null
UTF-8
Scheme
false
false
9,383
scm
ex_2.73.scm
#lang sicp ;; Racket hash table (#%require (only racket/base make-hash)) (#%require (only racket/base hash-set!)) (#%require (only racket/base hash-ref)) (define *op-table* (make-hash)) (define (put op type proc) (hash-set! *op-table* (list op type) proc)) (define (get op type) (hash-ref *op-table* (list op type) '())) ;; Generic derivative (define (variable? x) (symbol? x)) (define (same-variable? v1 v2) (and (variable? v1) (variable? v2) (eq? v1 v2))) (define (deriv exp var) (cond ((number? exp) 0) ((variable? exp) (if (same-variable? exp var) 1 0)) (else ((get 'deriv (operator exp)) (operands exp) var)))) (define (operator exp) (car exp)) (define (operands exp) (cdr exp)) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; ;; ;; 1 ;; ;; ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; The new code is blind to the types of derivative rules available for expressions. ;; So if we add a new type of operation, say log, we don't need to add a new branc in ;; the cond of the deriv, as long as our operators table contains a deriv for that operation ;; Variable and exp and not included into the data directed dispatch, as these are independent ;; of the operations previously appearing. No matter what derivation rules we might want to add ;; for various functions d(23)/dx = 0, dy/dx = 0 if y is not a function of x, and dx/dx will ;; always be 1. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; ;; ;; 2 ;; ;; ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (define (install-sum-derivative-rule) ;; Sum imports (define (=number? exp num) (and (number? exp) (= exp num))) (define (make-sum a1 a2) (cond ((=number? a1 0) a2) ((=number? a2 0) a1) ((and (number? a1) (number? a2)) (+ a1 a2)) (else (list '+ a1 a2)))) ;; modify selectors, since (operands exp) get passed here, not the whole expression (define (addend operands) (car operands)) (define (augend s) (if (null? (cddr s)) (cadr s) ;; If there's no term, works the same as the above (cons '+ (cdr s)))) ;; else return (b + c) ;; Register this to our magic table (put 'deriv '+ (lambda (exp var) (make-sum (deriv (addend exp) var) (deriv (augend exp) var)))) 'done-installing-sum-derivatives) (install-sum-derivative-rule) (deriv '(+ a a 2 2 a a) 'a) ; ✔ (deriv '(+ a 2) 'x) ; ✔ (deriv '(+ 1 2) 'a) ; ✔ (define (install-prod-derivative-rule) ;; Product imports (define (=number? exp num) (and (number? exp) (= exp num))) (define (make-sum a1 a2) (cond ((=number? a1 0) a2) ((=number? a2 0) a1) ((and (number? a1) (number? a2)) (+ a1 a2)) (else (list '+ a1 a2)))) (define (make-product m1 m2) (cond ((or (=number? m1 0) (=number? m2 0)) 0) ((=number? m1 1) m2) ((=number? m2 1) m1) ((and (number? m1) (number? m2)) (* m1 m2)) (else (list '* m1 m2)))) ;; Redefine multiplicand and multiplier, as we pass the operands not the full expression (define (multiplier p) (car p)) (define (multiplicand p) (if (null? (cddr p)) (cadr p) (cons '* (cdr p)))) ;; Register this to our magic table (put 'deriv '* (lambda (exp var) (make-sum (make-product (multiplier exp) (deriv (multiplicand exp) var)) (make-product (deriv (multiplier exp) var) (multiplicand exp))))) 'done-installing-prod-derivatives) (install-prod-derivative-rule) (deriv '(* x y) 'x) ; ✔ (deriv '(* a a a a a) 'x) ; ✔ (deriv '(* a a a x) 'x) ; ✔ (deriv '(* x x x) 'x) ; ✔ (deriv '(* x x) 'x) ; ✔ (deriv '(+ (* a x 2) x 2) 'x) ; ✔ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; ;; ;; 3 ;; ;; ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (define (install-expt-derivative-rule) ;; Exponentiation imports (define (=number? exp num) (and (number? exp) (= exp num))) (define (make-sum a1 a2) (cond ((=number? a1 0) a2) ((=number? a2 0) a1) ((and (number? a1) (number? a2)) (+ a1 a2)) (else (list '+ a1 a2)))) (define (make-product m1 m2) (cond ((or (=number? m1 0) (=number? m2 0)) 0) ((=number? m1 1) m2) ((=number? m2 1) m1) ((and (number? m1) (number? m2)) (* m1 m2)) (else (list '* m1 m2)))) (define (make-exponentiation b n) (cond ((=number? n 0) 1) ((=number? n 1) b) ((and (number? b) (number? n) (expt b n))) (else (list '** b n)))) ;; Redefine multiplicand and multiplier, as we pass the operands not the full expression= (define (get-base p) (car p)) (define (get-exponent p) (cadr p)) ;; Register this to our magic table (put 'deriv '** (lambda (exp var) (let ((expnt (get-exponent exp)) (base (get-base exp))) (make-product (make-product expnt (make-exponentiation base (make-sum expnt -1))) (deriv base var))))) 'done-installing-expt-derivatives) (install-expt-derivative-rule) (deriv '(** u n) 'u) ; ✔ (deriv '(** (* y x) n) 'x) ; ✔ (deriv '(+ (* a x) (** x (- n 1))) 'x); ✔ (deriv '(** (+ a x x b) n) 'x); ✔ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; ;; ;; 4 ;; ;; ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; New derivative (define (deriv-new exp var) (cond ((number? exp) 0) ((variable? exp) (if (same-variable? exp var) 1 0)) (else ((get (operator exp) 'deriv) (operands exp) var)))) ;; Import the same, except with swapped symbol expression (define (install-reverse-derivative-rule) ;; Basic imports (define (=number? exp num) (and (number? exp) (= exp num))) (define (make-sum a1 a2) (cond ((=number? a1 0) a2) ((=number? a2 0) a1) ((and (number? a1) (number? a2)) (+ a1 a2)) (else (list '+ a1 a2)))) (define (make-product m1 m2) (cond ((or (=number? m1 0) (=number? m2 0)) 0) ((=number? m1 1) m2) ((=number? m2 1) m1) ((and (number? m1) (number? m2)) (* m1 m2)) (else (list '* m1 m2)))) (define (make-exponentiation b n) (cond ((=number? n 0) 1) ((=number? n 1) b) ((and (number? b) (number? n) (expt b n))) (else (list '** b n)))) ;; Selectors (define (addend operands) (car operands)) (define (augend s) (if (null? (cddr s)) (cadr s) (cons '+ (cdr s)))) (define (multiplier p) (car p)) (define (multiplicand p) (if (null? (cddr p)) (cadr p) (cons '* (cdr p)))) (define (get-base p) (car p)) (define (get-exponent p) (cadr p)) ;; Register the above for deriv-new (put '+ 'deriv (lambda (exp var) (make-sum (deriv-new (addend exp) var) (deriv-new (augend exp) var)))) (put '* 'deriv (lambda (exp var) (make-sum (make-product (multiplier exp) (deriv-new (multiplicand exp) var)) (make-product (deriv-new (multiplier exp) var) (multiplicand exp))))) (put '** 'deriv (lambda (exp var) (let ((expnt (get-exponent exp)) (base (get-base exp))) (make-product (make-product expnt (make-exponentiation base (make-sum expnt -1))) (deriv-new base var))))) 'done-installing-reverse-derivatives) (install-reverse-derivative-rule) (deriv-new '(+ a a 2 2 a a) 'a) ; ✔ (deriv-new '(+ a 2) 'x) ; ✔ (deriv-new '(+ 1 2) 'a) ; ✔ (newline) (deriv-new '(* x y) 'x) ; ✔ (deriv-new '(* a a a a a) 'x) ; ✔ (deriv-new '(* a a a x) 'x) ; ✔ (deriv-new '(* x x x) 'x) ; ✔ (deriv-new '(* x x) 'x) ; ✔ (deriv-new '(+ (* a x 2) x 2) 'x) ; ✔ (newline) (deriv-new '(** u n) 'u) ; ✔ (deriv-new '(** (* y x) n) 'x) ; ✔ (deriv-new '(+ (* a x) (** x (- n 1))) 'x); ✔ (deriv-new '(** (+ a x x b) n) 'x); ✔
false
1383b95b978f2dec452c67cbf94b739a7885f1cb
648776d3a0d9a8ca036acaf6f2f7a60dcdb45877
/queries/lua/injections.scm
85c677665c81e58b1f19e7e0f21bf5f33822ac44
[ "Apache-2.0" ]
permissive
nvim-treesitter/nvim-treesitter
4c3c55cbe6ff73debcfaecb9b7a0d42d984be3e6
f8c2825220bff70919b527ee68fe44e7b1dae4b2
refs/heads/master
2023-08-31T20:04:23.790698
2023-08-31T09:28:16
2023-08-31T18:19:23
256,786,531
7,890
980
Apache-2.0
2023-09-14T18:07:03
2020-04-18T15:24:10
Scheme
UTF-8
Scheme
false
false
2,996
scm
injections.scm
((function_call name: [ (identifier) @_cdef_identifier (_ _ (identifier) @_cdef_identifier) ] arguments: (arguments (string content: _ @injection.content))) (#set! injection.language "c") (#eq? @_cdef_identifier "cdef")) ((function_call name: (_) @_vimcmd_identifier arguments: (arguments (string content: _ @injection.content))) (#set! injection.language "vim") (#any-of? @_vimcmd_identifier "vim.cmd" "vim.api.nvim_command" "vim.api.nvim_command" "vim.api.nvim_exec2")) ((function_call name: (_) @_vimcmd_identifier arguments: (arguments (string content: _ @injection.content) .)) (#set! injection.language "query") (#any-of? @_vimcmd_identifier "vim.treesitter.query.set" "vim.treesitter.query.parse")) ((function_call name: (_) @_vimcmd_identifier arguments: (arguments . (_) . (string content: _ @_method) . (string content: _ @injection.content))) (#any-of? @_vimcmd_identifier "vim.rpcrequest" "vim.rpcnotify") (#eq? @_method "nvim_exec_lua") (#set! injection.language "lua")) ;; highlight string as query if starts with `;; query` (string content: _ @injection.content (#lua-match? @injection.content "^%s*;+%s?query") (#set! injection.language "query")) ((comment) @injection.content (#lua-match? @injection.content "^[-][-][-][%s]*@") (#set! injection.language "luadoc") (#set! injection.include-children) (#offset! @injection.content 0 3 0 0)) ; string.match("123", "%d+") (function_call (dot_index_expression field: (identifier) @_method (#any-of? @_method "find" "match")) arguments: (arguments . (_) . (string content: (string_content) @injection.content (#set! injection.language "luap") (#set! injection.include-children)))) (function_call (dot_index_expression field: (identifier) @_method (#any-of? @_method "gmatch" "gsub")) arguments: (arguments . (_) . (string content: (string_content) @injection.content (#set! injection.language "luap") (#set! injection.include-children)))) ;("123"):match("%d+") (function_call (method_index_expression method: (identifier) @_method (#any-of? @_method "find" "match")) arguments: (arguments . (string content: (string_content) @injection.content (#set! injection.language "luap") (#set! injection.include-children)))) (function_call (method_index_expression method: (identifier) @_method (#any-of? @_method "gmatch" "gsub")) arguments: (arguments . (string content: (string_content) @injection.content (#set! injection.language "luap") (#set! injection.include-children)))) ((comment) @injection.content (#set! injection.language "comment") (#set! injection.include-children))
false
feb64939be5c7a6435347249439fd60ec3713404
957ca548c81c2c047ef82cdbf11b7b2b77a3130b
/04LAB/04_lab_6b.scm
8126c25aaa3e958627fbfbc5996759a3fc084359
[]
no_license
emrzvv/Scheme
943d4a55c5703f0e1318ae65aec24d0cb57e3372
e6ae1ed19104f46d22eee2afabea5459f7031a22
refs/heads/master
2023-02-19T08:55:29.470491
2021-01-18T12:56:26
2021-01-18T12:56:26
318,609,955
4
0
null
null
null
null
UTF-8
Scheme
false
false
487
scm
04_lab_6b.scm
#|(define-syntax for (syntax-rules (in as) ((_ x in xs . f) (map (lambda (x) . f) xs)) ((_ xs as x . f) (map (lambda (x) . f) xs))))|# (define-syntax for (syntax-rules (in as) ((_ x in xs . f) (for-each (lambda (x) . f) xs)) ((_ xs as x . f) (for-each (lambda (x) . f) xs)))) #|(for i in '(1 2 3) (for j in '(4 5 6) (display (list i j)) (newline))) (for '(1 2 3) as i (for '(4 5 6) as j (display (list i j)) (newline)))|#
true
3f191b273de9c49a9b937fbd0608cb7f62c36fee
1645add1bc3f780e0deaf3ca323b263037065c8f
/c0re.scm
912af5adc87346bafb08c286e288dc5d46e416e0
[ "ISC" ]
permissive
alanpost/jbogenturfahi
b4c57e80000d30bc6c0dff54ee780264a201006e
7a6b50eb13ab5bd4d0d6122638c4a63a55e59aef
refs/heads/master
2020-12-24T14:27:34.229766
2013-01-04T19:38:49
2013-01-04T19:38:49
1,044,613
3
1
null
null
null
null
UTF-8
Scheme
false
false
1,721
scm
c0re.scm
;;;; ;;;; jbogenturfahi - lo lojbo ke pe'a jajgau ratcu ke'e genturfa'i ;;;; `-> A Lojban grammar parser ;;;; ;;;; Copyright (c) 2010 ".alyn.post." <[email protected]> ;;;; ;;;; Permission to use, copy, modify, and/or distribute this software for any ;;;; purpose with or without fee is hereby granted, provided that the above ;;;; copyright notice and this permission notice appear in all copies. ;;;; ;;;; THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES ;;;; WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF ;;;; MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ;;;; ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES ;;;; WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ;;;; ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF ;;;; OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ;;;; ;; curry - supply some arguments to |f|. ;; ;; (curry f a ...) ;; (f a ... ...) ;; ;; basic curry function ;; (define (curry f . a) (lambda x (apply f (append a x)))) ;; map-apply - apply each element in a list to function ;; ;; (map-apply f l) ;; (define (map-apply f l) (map (lambda (x) (apply f x)) l)) ;; seq - return a sequence of numbers as a list ;; ;; (seq f l) ;; (define (seq f l) (if (>= f l) '() (cons f (seq (+ 1 f) l)))) ;; until -- call until predicate returns |#f|. ;; ;; (until p f) ;; (p) ;; (f) ;; ;; call |p|, and if the result is not |#f|, ;; call |f| and recurse. return the results ;; from |f| as a list, or |'()| if |p| never ;; returns non-|#f|. ;; (define (until p f) (if (p) (cons (f) (until p f)) '()))
false
b8f07bdb9467df72db0b8c68c076faf7323fbded
ad37532cc29a3ec1f4054c9f1f010a79de235cb6
/src/parser.scm
1898ee15bb46ba9f48bc3f9c0bb610f148359f5d
[]
no_license
liquidz/namakemono
575b1d0d89ffbbc79c19d24be72692b1916b1eba
7ba985248da8566f25bd68ca2f0775a35e906475
refs/heads/master
2016-09-05T10:07:15.646161
2009-01-30T09:20:33
2009-01-30T09:20:33
106,346
1
0
null
null
null
null
UTF-8
Scheme
false
false
11,114
scm
parser.scm
(define *nil-returned-value* 'nothing) ; =my-string-drop ; ほんのちょっとだけstring-dropより速い ; --------------------------------- (define (my-string-drop str n) (substring str n (string-length str)) ) ; =pickup ; ---------------------- (define (pickup ls start end) (drop (take ls (++ end)) start) ) #| (define (pickup ls start end) (define (pickup-body b-ls n) (if (= n 0) b-ls (pickup-body (cdr b-ls) (-- n))) ) (r pickup-body (r pickup-body ls start) (- end start)) ) |# ; =append-with-null ; ---------------------------- (define (append-with-null ls1 ls2) (let ((ls1-2 (if (null? ls1) '(()) ls1)) (ls2-2 (if (null? ls2) '(()) ls2)) ) (append ls1-2 ls2-2) ) ) ; =list-insert ; ---------------------- (define (list-insert original-ls target num) (let loop((ls original-ls) (i 0) (res '())) (cond [(null? ls) (r res)] [(= i num) (loop (cdr ls) (++ i) (cons (car ls) (cons target res))) ] [else (loop (cdr ls) (++ i) (cons (car ls) res)) ] ) ) ) ; =has-flexible-length-argument? ; -------------------------------- (define (has-flexible-length-argument? arg-ls) (char=? (string-ref (keyword->string (cadr (last arg-ls))) 0) #\*) ) ; =count-make-lambda-params ; --------------------------- (define (count-make-lambda-params param) (if (char=? #\* (string-ref (keyword->string (value (last param))) 0)) -1 (length param) ) ) ; =make-lambda ; ---------------------- (define (make-lambda param body) (let1 flexible-arg (has-flexible-length-argument? param) (debug 2 "* lambda: param = " param ", body = " body) (lambda p (cond [(and (! null? p) (eq? (car p) *get-lambda-params-length*)) ; この場合だけは特別にパラメータ数を返す ; (オーバーロード用) (count-make-lambda-params param) ;(length param) ] [else (let ((uid (make-uid)) (last-uid *current-uid*)) (change-current-uid uid) (make-local-namespace uid) (take-over-variables last-uid uid) (cond ; 可変長の引数の場合 [flexible-arg ; register temporary variable (block _break (dotimes (n (length p)) (let* ((var-name (value (list-ref param n))) (s-var-name (keyword->string var-name))) (cond [(char=? (string-ref s-var-name 0) #\*) (set-variable (make-keyword ; 先頭の*は抜かす (my-string-drop s-var-name 1)) (drop p n)) ; 残りのパラメータは全て1つの引数に登録されたので ; for-each を抜ける (_break) ] [else (set-variable var-name (list-ref p n)) ] ) ) ) ) ; execute (let1 result (run-tokens body) ; delete temporary variables (delete-local-namespace uid) (change-current-uid last-uid) result ) ] ; 固定長の引数の場合 [else (cond [(= (length p) (length param)) ; register temporary variable (for-each (lambda (n) (set-variable (value (list-ref param n)) (list-ref p n)) ) (iota (length p) 0)) (let1 result (run-tokens body) ; delete temporary variables (delete-local-namespace uid) (change-current-uid last-uid) result ) ] [else (change-current-uid last-uid) (error "lambda parameter error:" 'required (length p) 'got (length param)) ] ) ] ) ) ]) ) ) ) ; =parse-lambda (define (parse-lambda ls) (cond [(null? ls) (error "parsing lambda error: body is empty") ] [else (receive (param body) (if (eq? (caar ls) :parameter-start) (let1 index (list-index (lambda (x) (eq? (car x) :parameter-end)) ls) (if index (values (pickup ls 1 (-- index)) (drop ls (++ index))) (error "parsing lambda error: parameter is not closed" ls) ) ) (values (scanner *implicit-variable*) ls) ) ;(print " param = " param) ;(print " body = " body) (make-lambda param (collect-lambda body)) ) ] ) ) ; =get-correct-end ; ----------------------- (define (get-correct-end scanned-ls start-key end-key) (let loop((ls scanned-ls) (num 0) (level 0)) (if (null? ls) (error "dameda!") (let1 first-token (caar ls) (cond [(eq? first-token start-key) (loop (cdr ls) (++ num) (++ level)) ] [(eq? first-token end-key) (if (= (-- level) 0) num (loop (cdr ls) (++ num) (-- level)) ) ] [else (loop (cdr ls) (++ num) level) ] ) ) ) ) ) ; =collect-lambda ; -------------------------- (define (collect-lambda scanned-ls) (let1 len (length scanned-ls) (let loop((index 0) (res '())) (if (= len index) (r res) (let1 first-token (list-ref scanned-ls index) (cond [(eq? (car first-token) :lambda-start) (let1 end (get-correct-end (drop scanned-ls index) :lambda-start :lambda-end) ; 先頭のlambda-startと終わりのlambda-endは抜かしてtarget-lsとする (let1 target-ls (pickup scanned-ls (++ index) (+ index end -1)) ; 終わりのlambda-endの次から始めたいので + 1 (loop (+ index end 1) (cons (list :lambda (parse-lambda target-ls)) res)) ) ) ] [else (loop (++ index) (cons first-token res)) ] ) ) ) ) ) ) ; =make-params ; @position: ; null => 他パラメータの末尾にreturned-valueを追加 ; else => 他パラーメータの指定された箇所にreturned-valueを挿入 ; --------------------- (define (make-params expr returned-value position) ; 引数の有無を明確にするため予めexprの長さを調べる ; ex) command emp ; command ; の違いを明確に分けるため (let1 tmp-param (if (= 1 (length expr)) 'no-param (r fold (lambda (x res) (cons (if (_word? x) (get-variable (value x)) (value x)) res) ) '() (cdr expr)) ) (cond [(! eq? returned-value *nil-returned-value*) (if (eq? tmp-param 'no-param) (list returned-value) (if (null? position) (append-with-null tmp-param (list returned-value)) (list-insert tmp-param returned-value position) ) ) ] [else ; 暗黙変数"_"のために何も引数がない場合には nil を入れておく (if (eq? tmp-param 'no-param) (list *nil*) tmp-param) ] ) ) ) ; =execute ; --------------------------- (define (execute expr returned-value pos) (let ((first-token (car expr)) (expr-len (length expr)) (cdr-expr-len (length (cdr expr))) ) (cond ; トークン列の最初が関数や変数の場合 [(_word? first-token) (let1 first-val (get-variable (value first-token) (if (eq? returned-value *nil-returned-value*) cdr-expr-len (++ cdr-expr-len))) ; return-valueの分を増やす (cond ; 関数の場合は無条件で実行 ; 正規表現の結果セットの場合は引数(または前の関数の戻り値)があれば実行 [(or (procedure? first-val) (and (regmatch? first-val) (or (> expr-len 1) (! eq? returned-value *nil-returned-value*) )) ) (apply first-val (make-params expr returned-value pos)) ] [else first-val] ) ) ] ; トークン列の最初が無名関数、または正規表現オブジェクトの場合 ; 引数があれば実行。引数がなければ else パートに飛びオブジェクトと見なす [(or (and (_lambda? first-token) (or (> expr-len 1) (! eq? returned-value *nil-returned-value*))) (and (_regexp? first-token) (or (> expr-len 1) (! eq? returned-value *nil-returned-value*)))) (let1 first-val (value first-token) (apply first-val (make-params expr returned-value pos)) ) ] ; 直前の処理の戻り値をそのまま処理対象ワードをして扱う場合 (this構文) [(_this? first-token) (when (! eq? *nil-returned-value* returned-value) (apply returned-value (make-params expr *nil-returned-value* pos)) ) ] ; 戻り値のパラメータへの挿入場所指定がある場合 [(_pipe-pos? first-token) (when (! eq? *nil-returned-value* returned-value) (execute (cdr expr) returned-value (value first-token)) ) ] ; トークン列の最初がそれ以外(数字・文字列など)の場合 [else (value first-token) ] ) ) ) ; =parser ; -------------------- (define (parser each-pipe-token . default-returned-value) (define returned-value (if (null? default-returned-value) *nil-returned-value* (car default-returned-value))) (for-each (lambda (expr) (debug 3 "* parsing token\n " expr) (let1 _return (execute expr returned-value '()) (set! returned-value _return) (debug 3 "* set returned value = " _return " -- " each-pipe-token) ) ) each-pipe-token) returned-value )
false
50a2ec04d6b7f238fdb1da1c719e5aebaa18a0b7
09e309c8c7dd86d201f965a12f4f174fd2bf8cf5
/scheme/delete-1.scm
5ed17c8270be37182b6866931ada8842fc2f948c
[]
no_license
googol-lab/lang
f21076846b2364ee08875530ab7a6680de61f55c
38cae455f85464a7f918d1a5a481a577ed5549fe
refs/heads/master
2020-03-29T13:32:29.159544
2010-05-24T03:09:54
2010-05-24T03:09:54
null
0
0
null
null
null
null
UTF-8
Scheme
false
false
536
scm
delete-1.scm
(define (delete-1 elt lis . options) (let-optionals* options ((cmp-fn equal?)) (define (loop lis) (cond [(null? lis) '()] [(cmp-fn elt (car lis)) (cdr lis)] [else (cons (car lis) (loop (cdr lis)))])) (loop lis))) (define (delete-1-ncp elt lis . options) (let-optionals* options ((cmp-fn equal?)) (define (loop lis) (cond [(null? lis) '()] [(cmp-fn elt (car lis)) (cdr lis)] [else (if (eq? (loop (cdr lis)) (cdr lis)) lis (cons (car lis) (loop (cdr lis))))])) (loop lis)))
false
f260440fcc41b48af57a33c84af934e6795a6ad9
d63c4c79d0bf83ae646d0ac023ee0528a0f4a879
/cs133/assn6/a6q5.scm
7418438678486db65a56d946c1d4155249c989d8
[]
no_license
stratigoster/UW
4dc31f08f7f1c9a958301105dcad481c39c5361f
7a4bff4f1476607c43278c488f70d01077b1566b
refs/heads/master
2021-07-07T04:52:01.543221
2011-08-15T05:08:48
2011-08-15T05:08:48
10,858,995
1
1
null
null
null
null
UTF-8
Scheme
false
false
2,741
scm
a6q5.scm
;; Contract- ;; DNAprefix: los los -> boolean ;; Purpose- ;; consumes 2 lists of symbols (los); the first list is called a pattern, ;; the 2nd one a search-string. The function returns true if the pattern ;; is a prefix of the search-string. Otherwise the function returns false. ;; Examples- ;; 1. (DNAprefix '(a t) '(a t c)) => true ;; 2. (DNAprefix '(a t) '(a)) => false ;; 3. (DNAprefix '(a t) '(a t)) => true ;; 4. (DNAprefix '(a c g t) '(a g)) => false ;; 5. (DNAprefix '(a a c c) '(a c)) => false ;; 6. (DNAprefix '(a b c) empty) => false ;; 7. (DNAprefix empty '(a b c)) => true (define (DNAprefix patt sstring) (cond [(empty? patt) true] [(empty? sstring) false] [(equal? (first patt) (first sstring)) (DNAprefix (rest patt) (rest sstring))] [else false])) ;; testing DNAprefix ;; 1. (equal? (DNAprefix '(a t) '(a t c)) true) ;; 2. (equal? (DNAprefix '(a t) '(a)) false) ;; 3. (equal? (DNAprefix '(a t) '(a t)) true) ;; 4. (equal? (DNAprefix '(a c g t) '(a g)) false) ;; 5. (equal? (DNAprefix '(a a c c) '(a c)) false) ;; 6. (equal? (DNAprefix '(a b c) empty) false) ;; 7. (equal? (DNAprefix empty '(a b c)) true) ;; -------------------------------------------------------------------------------- ;; Contract- ;; DNAsubstring: los los -> boolean ;; Purpose- ;; consumes 2 lists of symbols (lon); the first list is called a pattern ;; and the 2nd one a search-string. The function returns true if the pattern ;; occurs somewhere in the search-string (not necessarily as a prefix, but ;; consecutively). ;; Examples- ;; 1. (DNAsubstring '(a t) '(a t c)) => true ;; 2. (DNAsubstring '(a t) '(a)) => false ;; 3. (DNAsubstring '(a t) '(a t)) => true ;; 4. (DNAsubstring '(a c g t) '(a g)) => false ;; 5. (DNAsubstring '(a c) '(a a c c)) => true ;; 6. (DNAsubstring '(a c g) '(a b c a c g j)) => true ;; 7. (DNAsubstring '(a b c) empty) => false (define (DNAsubstring patt sstring) (cond [(empty? sstring) false] [(empty? patt) true] [else (cond [(DNAprefix patt sstring) true] [else (DNAsubstring patt (rest sstring))])])) ;; testing DNAsubstring ;; 1. (equal? (DNAsubstring '(a b c) empty) false) ;; 2. (equal? (DNAsubstring '(a t) '(a t c)) true) ;; 3. (equal? (DNAsubstring '(a t) '(a)) false) ;; 4. (equal? (DNAsubstring '(a t) '(a t)) true) ;; 5. (equal? (DNAsubstring '(a c g t) '(a g)) false) ;; 6. (equal? (DNAsubstring '(a c) '(a a c c)) true) ;; 7. (equal? (DNAsubstring '(a c g) '(a b c a c g j)) true) ;; 8. (equal? (DNAsubstring '(a t) '(a a t t)) true) ;; 9. (equal? (DNAsubstring empty '(a b c)) true)
false
86cd4c9a5014f603d1f4af9842cfd29ea6a03660
0964d931c7146fbdd1eb72fba2c0bcc492ca526b
/schemeray.scm
d61fd1b371ad4069fc9530e9643f9067eec62fb5
[]
no_license
kaveman-/schemeray
b30f67f0b0d3f8285b70d23266c13a34b6e96f7e
0ea0f1596cbafa05e541131fd64d482c79dd4173
refs/heads/master
2021-05-27T03:29:43.126547
2009-03-26T03:56:42
2009-03-26T03:56:42
null
0
0
null
null
null
null
UTF-8
Scheme
false
false
14,022
scm
schemeray.scm
;;; Scheme Raytracer v0.1 ;;; ;;; Performs sphere/plane/triangle intersection tests, loads ;;; .obj files as a list of triangles, applies Phong ;;; illumination and reflections. ;;; ;;; The math here hasn't been optimized at all, and there's ;;; a good deal that could be done. However, I simply wanted ;;; to build a prototype. Optimization will come in the ;;; next version. ;;; ;;; This outputs to a file 'image.ppm' which is of the format ;;; Portable Pixmap. Netpbm provides nice tools to convert ;;; ppm's to other file formats if you need it. ;;; ;;; 10/04/2007 ;;; James Long (declare (standard-bindings) (extended-bindings) (block) (mostly-flonum-fixnum) (not safe)) (define flonum->fixnum ##flonum.->fixnum) (define current-log-port (make-parameter (current-error-port))) (define (display-args . rest) (display rest)) (define (write-log . rest) (with-output-to-port (current-log-port) (lambda () (display rest) (newline)))) (define (real->u8 n) (flonum->fixnum (flmax 0. (flmin 255. (flfloor n))))) (define (real->percentage n) (flonum->fixnum (flfloor (fl* 100.0 n)))) (define (write-color v1) (write-u8 (real->u8 (fl* (vec3d-x v1) 255.0))) (write-u8 (real->u8 (fl* (vec3d-y v1) 255.0))) (write-u8 (real->u8 (fl* (vec3d-z v1) 255.0)))) ;;; Utility stuff to help with math (define (make-vec2d x y) (f64vector x y)) (define (vec2d-x v) (f64vector-ref v 0)) (define (vec2d-y v) (f64vector-ref v 1)) (define (make-vec3d x y z) (f64vector x y z)) (define (vec3d-x v) (f64vector-ref v 0)) (define (vec3d-y v) (f64vector-ref v 1)) (define (vec3d-z v) (f64vector-ref v 2)) (define (vec3d-op v1 v2 op) (make-vec3d (op (vec3d-x v1) (vec3d-x v2)) (op (vec3d-y v1) (vec3d-y v2)) (op (vec3d-z v1) (vec3d-z v2)))) (define (vec3d-add v1 v2) (declare (inlining-limit 10000)) (vec3d-op v1 v2 fl+)) (define (vec3d-sub v1 v2) (declare (inlining-limit 10000)) (vec3d-op v1 v2 fl-)) (define (vec3d-component-mul v1 v2) (declare (inlining-limit 10000)) (vec3d-op v1 v2 fl*)) (define (vec3d-scalar-mul v1 f) (make-vec3d (fl* (vec3d-x v1) f) (fl* (vec3d-y v1) f) (fl* (vec3d-z v1) f))) (define (vec3d-length v1) (declare (inlining-limit 10000)) (flsqrt (vec3d-dot v1 v1))) (define (vec3d-unit v1) (declare (inlining-limit 10000)) (vec3d-scalar-mul v1 (fl/ (vec3d-length v1)))) (define (vec3d-dot v1 v2) (fl+ (fl* (vec3d-x v1) (vec3d-x v2)) (fl* (vec3d-y v1) (vec3d-y v2)) (fl* (vec3d-z v1) (vec3d-z v2)))) (define (vec3d-cross v1 v2) (let ((v1-x (vec3d-x v1)) (v2-x (vec3d-x v2)) (v1-y (vec3d-y v1)) (v2-y (vec3d-y v2)) (v1-z (vec3d-z v1)) (v2-z (vec3d-z v2))) (make-vec3d (fl- (fl* v1-y v2-z(vec3d-z v2)) (fl* v1-z v2-y)) (fl- (fl* v1-z v2-x) (fl* v1-x v2-z)) (fl- (fl* v1-x v2-y) (fl* v1-y v2-x))))) (define (saturate n) (flmin 1.0 (flmax 0.0 n))) (include "obj-file-parser.scm") (define-structure window x y) ;;; Config constants (define screenDimen (make-vec2d 8.0 6.0)) (define res (make-window 800 600)) (define eye (make-vec3d 0.0 0.0 -5.0)) (define depth 10000.0) (define backColor (make-vec3d 0.0 0.0 0.0)) (define ambient (make-vec3d .1 .1 .1)) (define maxsteps 3) (define coptix (delay (load-obj "meshes/coptix_slim"))) (define box (delay (load-obj "meshes/box"))) (define (generate-spheres) (let ((start (make-vec3d 0.0 0.0 65.0)) (dX (make-vec3d -1.0 -.25 .5)) (dY (make-vec3d 0.0 -1.0 0.0))) (let loop ((num 0) (acc '())) (if (fx< num 50) (loop (fx+ num 1) (cons `(sphere ,(make-vec3d .8 (fl+ .2 (fl/ (fixnum->flonum num) 50.0)) .2) ,(vec3d-add (vec3d-add start (vec3d-scalar-mul (vec3d-scalar-mul dX 10.0) (fixnum->flonum (fxremainder num 5)))) (vec3d-scalar-mul (vec3d-scalar-mul dY 10.0) (fixnum->flonum (fxquotient num 5)))) 5.0) acc)) acc)))) (define scene `(,@(generate-spheres) ;(sphere ,(make-vec3d .4 .6 .5) ,(make-vec3d -15.0 0.0 90.0) 20.0) ;(sphere ,(make-vec3d .75 .95 .92) ,(make-vec3d 20.0 -20.0 65.0) 5.0) (plane ,(make-vec3d .7 .7 1.0) 10.0 ,(make-vec3d .25 -1.0 0.0)) ;(mesh #f ,(make-vec3d 23.0 0.0 50.0) ,coptix) (light ,(make-vec3d .7 .9 .9) ,(make-vec3d -40.0 -15.0 60.0) 1.0))) ;;; Types (define-syntax obj-dispatch (syntax-rules (else) ((obj-dispatch obj (else body ...)) (begin body ...)) ((obj-dispatch obj (type body ...) almost last ...) (if (eq? 'type (obj-type obj)) (begin body ...) (obj-dispatch obj almost last ...))) ((obj-dispatch obj (type body ...) last ...) (if (eq? 'type (obj-type obj)) (begin body ...))))) (define (obj-type obj) (car obj)) (define (obj-color obj) (cadr obj)) (define (obj-normal obj point) (declare (inlining-limit 0)) (obj-dispatch obj (sphere (sphere-normal obj point)) (light (sphere-normal obj point)) (plane (plane-normal obj)) (triangle (triangle-normal obj)))) ;;; Light (define (light-pos obj) (sphere-pos obj)) (define (light-intersection obj origVec dirVec) (sphere-intersection obj origVec dirVec)) ;;; Sphere (define (sphere-pos obj) (caddr obj)) (define (sphere-radius obj) (cadddr obj)) (define (sphere-intersection obj origVec dirVec) (declare (inlining-limit 10000)) (let* ((eo (vec3d-sub origVec (sphere-pos obj))) (b (vec3d-dot eo dirVec)) (c (fl- (vec3d-dot eo eo) (flexpt (sphere-radius obj) 2.0))) (d (fl- (fl* b b) c))) (if (fl<= d 0.0) depth (let ((r (fl- (fl- b) (flsqrt d)))) (if (fl> r 0.0) r depth))))) (define (sphere-normal obj point) (declare (inlining-limit 10000)) (vec3d-unit (vec3d-sub point (sphere-pos obj)))) ;;; Plane (define (plane-normal obj) (cadddr obj)) (define (plane-distance obj) (caddr obj)) (define (plane-intersection obj origVec dirVec) (declare (inlining-limit 10000)) (let ((d (vec3d-dot (plane-normal obj) dirVec))) (if (not (flzero? d)) (let ((dist (fl/ (fl- (fl+ (vec3d-dot (plane-normal obj) origVec) (plane-distance obj))) d))) (if (flpositive? dist) dist depth)) depth))) ;;; Triangles (define (triangle-v1 obj) (caddr obj)) (define (triangle-v2 obj) (cadddr obj)) (define (triangle-v3 obj) (car (cddddr obj))) (define (triangle-normal obj) (declare (inlining-limit 10000)) (vec3d-unit (vec3d-cross (vec3d-sub (triangle-v2 obj) (triangle-v1 obj)) (vec3d-sub (triangle-v3 obj) (triangle-v1 obj))))) (define (triangle-intersection obj origVec dirVec) (declare (inlining-limit 10000)) (let* ((n (triangle-normal obj)) (v.n (vec3d-dot dirVec n))) (if (fl>= v.n 0.0) depth (let* ((a (triangle-v1 obj)) (b (triangle-v2 obj)) (c (triangle-v3 obj)) (o-a.n (vec3d-dot (vec3d-sub origVec a) n)) (d (fl- (fl/ o-a.n v.n))) (p (vec3d-add origVec (vec3d-scalar-mul dirVec d)))) (let ((val (vec3d-dot (vec3d-cross (vec3d-sub b a) (vec3d-sub p a)) n))) (define (same-sign? x y) (eq? (flnegative? x) (flnegative? y))) (if (and (fl>= d 0.0) (same-sign? val (vec3d-dot (vec3d-cross (vec3d-sub c b) (vec3d-sub p b)) n)) (same-sign? val (vec3d-dot (vec3d-cross (vec3d-sub a c) (vec3d-sub p c)) n))) d depth)) ;; Barycentric projection - has some bugs #;(let ((u (/ (- (* (vec3d-y p) (vec3d-x c)) (* (vec3d-x p) (vec3d-y c))) (- (* (vec3d-y b) (vec3d-x c)) (* (vec3d-x b) (vec3d-y c))))) (v (/ (- (* (vec3d-y p) (vec3d-x b)) (* (vec3d-x p) (vec3d-y b))) (- (* (vec3d-y c) (vec3d-x b)) (* (vec3d-x c) (vec3d-y b)))))) (if (and (>= u 0.0) (>= v 0.0) (< (+ u v) 1.0)) d depth)))))) ;; Simplistic meshes (define (mesh-pos obj) (caddr obj)) (declare (not inline)) (define (mesh-primitives obj) (declare (inlining-limit 0)) (let ((a (cadddr obj))) (if (pair? a) a (force a)))) (declare (inline)) ;;; Intersections and casting (define (test-intersection obj origVec dirVec) (declare (inlining-limit 0)) (obj-dispatch obj (sphere (sphere-intersection obj origVec dirVec)) (light (sphere-intersection obj origVec dirVec)) (plane (plane-intersection obj origVec dirVec)) (triangle (triangle-intersection obj origVec dirVec)))) (declare (not inline)) (define (apply-lighting hitObj point v) (if (eq? (obj-type hitObj) 'light) (obj-color hitObj) (let ((acc (make-vec3d 0.0 0.0 0.0))) (for-each (lambda (obj) (declare (inlining-limit 100000)) (if (eq? (obj-type obj) 'light) (let* ((pointToLight (vec3d-sub (light-pos obj) point)) (l (vec3d-unit pointToLight)) (n (obj-normal hitObj point)) (n.l (saturate (vec3d-dot n l))) (r (vec3d-sub l (vec3d-scalar-mul n (fl* 2.0 (vec3d-dot n l))))) (r.v (saturate (vec3d-dot r v))) (diff n.l) (spec (flexpt r.v 30.)) (shadow (saturate (fl* 4.0 diff)))) (if (fl> diff 0.0) (set! acc (vec3d-add acc (vec3d-component-mul (vec3d-scalar-mul (vec3d-add (vec3d-scalar-mul (obj-color hitObj) diff) (obj-dispatch hitObj (plane (make-vec3d 0.0 0.0 0.0)) (else (make-vec3d spec spec spec)))) shadow) (obj-color obj)))))))) scene) (obj-dispatch hitObj (plane acc) (else (vec3d-add ambient acc)))))) (define (find-closest-prim orig dir prims cont) (declare (inlining-limit 100000)) (let ((closestObj #f) (closestDepth depth)) (for-each (lambda (obj) (if (eq? (obj-type obj) 'mesh) (find-closest-prim (vec3d-sub orig (mesh-pos obj)) dir (mesh-primitives obj) (lambda (o d) (if (fl< d closestDepth) (begin (set! closestDepth d) (set! closestObj o))))) (let ((d (test-intersection obj orig dir))) (if (fl< d closestDepth) (begin (set! closestDepth d) (set! closestObj obj)))))) prims) (if closestObj (cont closestObj closestDepth) backColor))) (define (shoot-ray orig dir step) (declare (inlining-limit 100000)) (if (fx< step maxsteps) (find-closest-prim orig dir scene (lambda (closestObj closestDepth) (if closestObj (let* ((d closestDepth) (point (vec3d-add orig (vec3d-scalar-mul dir d))) (n (obj-normal closestObj point)) (r (vec3d-unit (vec3d-sub dir (vec3d-scalar-mul n (fl* 2.0 (vec3d-dot dir n)))))) (view (vec3d-unit (vec3d-sub point eye)))) (vec3d-add (apply-lighting closestObj point view) (vec3d-scalar-mul (shoot-ray (vec3d-add point (vec3d-scalar-mul r .0001)) r (fx+ step 1)) (fl/ (fl* (fixnum->flonum (fx+ step 1)) 2.0))))) backColor))) (make-vec3d 0.0 0.0 0.0))) (define (shoot-screen-rays proc) (declare (inlining-limit 10000)) (let ((dX (fl/ (vec2d-x screenDimen) (fixnum->flonum (window-x res)))) (dY (fl/ (vec2d-y screenDimen) (fixnum->flonum (window-y res)))) (screenCorner (make-vec3d (fl- (fl/ (vec2d-x screenDimen) 2.0)) (fl- (fl/ (vec2d-y screenDimen) 2.0)) 0.0)) (count (fx* (window-x res) (window-y res)))) (let loop ((n 0)) (if (fx< n count) (let* ((curPoint (make-vec3d (fl* (fixnum->flonum (fxremainder n (window-x res))) dX) (fl* (fixnum->flonum (fxquotient n (window-x res))) dY) 0.0)) (view (vec3d-unit (vec3d-sub (vec3d-add screenCorner curPoint) eye))) (curColor (shoot-ray eye view 0))) (proc curColor) (loop (fx+ n 1))))))) (define (make-image) (write-log "Starting...") (with-output-to-file "image.ppm" (lambda () (display-args "P6\n") (display-args (window-x res) " " (window-y res) "\n") (display-args "255\n") (shoot-screen-rays write-color)))) (make-image)
true
d0f799db09831eea23a56292fe618edc7a5e1dac
ecfd9ed1908bdc4b099f034b121f6e1fff7d7e22
/old1/sicp/3/p56.scm
4882ca1c9971c5578cbba8b92635c87dd2dff987
[ "MIT" ]
permissive
sKabYY/palestra
36d36fc3a03e69b411cba0bc2336c43b3550841c
06587df3c4d51961d928bd8dd64810c9da56abf4
refs/heads/master
2021-12-14T04:45:20.661697
2021-11-25T08:29:30
2021-11-25T08:29:30
12,856,067
6
3
null
null
null
null
UTF-8
Scheme
false
false
302
scm
p56.scm
(load "stream.scm") (define S (cons 1 (delay (merge (merge (scale-stream S 2) (scale-stream S 3)) (scale-stream S 5))))) (stream-for-n println ;(lambda (x) (if (> x 9000) (println x) (void))) S 20)
false
f787bca1db2e49901734682b95167b6e0fba4a7a
e431ffc80b17660454f48a2e507ff170912e944a
/run-tests.scm
c9f8cd46626085da4c1b8e0bd9e309844450648b
[ "MIT" ]
permissive
toroidal-code/propellisp
42b0520d5e409b494b989fe0ac48738dd8232770
fac0e21583c3451e216a53f40d8b16c65afc5d47
refs/heads/master
2016-09-15T21:49:23.009711
2013-07-21T22:59:45
2013-07-21T22:59:45
10,539,499
3
0
null
null
null
null
UTF-8
Scheme
false
false
91
scm
run-tests.scm
(system "make runtime.o") (load "load.scm") (test-all) (system "make test_clean") (exit)
false