blob_id
stringlengths
40
40
directory_id
stringlengths
40
40
path
stringlengths
3
171
content_id
stringlengths
40
40
detected_licenses
listlengths
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
f7b4b1fa017587d64bc34a97d18685f19abc0ebd
4bd59493b25febc53ac9e62c259383fba410ec0e
/Scripts/Task/string-case/scheme/string-case-2.ss
b3569ff1f5365359300116da5a023d94e36a50b1
[]
no_license
stefanos1316/Rosetta-Code-Research
160a64ea4be0b5dcce79b961793acb60c3e9696b
de36e40041021ba47eabd84ecd1796cf01607514
refs/heads/master
2021-03-24T10:18:49.444120
2017-08-28T11:21:42
2017-08-28T11:21:42
88,520,573
5
1
null
null
null
null
UTF-8
Scheme
false
false
266
ss
string-case-2.ss
> (define s "alphaBETA gammaDELTA") > (string-upcase s) ;; turn all into upper case "ALPHABETA GAMMADELTA" > (string-downcase s) ;; turn all into lower case "alphabeta gammadelta" > (string-titlecase s) ;; capitalise start of each word "Alphabeta Gammadelta"
false
ef9399cb245e77f2b6fd9bac93d27574d506dd08
d19c7aa6544171df1870f793eaf685e65ddb61fa
/list_comprehension.scm
1dc6cd2e3f753e7848c623028f61b6bde0489792
[]
no_license
stanleytangerror/FPToyCodes
e58cc78195e91a10c160b3ea2ebf49f9ec54a03b
7531847c96048b15156d1e86f6133b1a29cc1d6d
refs/heads/master
2020-05-17T01:13:05.841586
2015-07-11T15:28:23
2015-07-11T15:28:23
34,507,109
1
0
null
null
null
null
UTF-8
Scheme
false
false
743
scm
list_comprehension.scm
#lang scheme (require r5rs) (define (flat-map f lst) (apply append (map f lst))) (define-syntax list-of (syntax-rules (<-) ; generate list with given exp, range, and rules [(_ exp (v <- alist) rule ...) (flat-map (lambda (v) (list-of exp rule ...)) alist)] ; first rule as filter, remaining rules as rule ... [(_ exp filter rule ...) (if filter (list-of exp rule ...) '())] ; no rule [(_ exp) (cons exp '())])) (define (add-one x) (+ x 1)) (list-of (list 1 2 3)) (list-of (* 2 x) (x <- '(1 2 3 4 5)) (> 3 x)) (flat-map (lambda (x) (list-of (* 2 x) (> 3 x))) '(1 2 3 4 5)) (flat-map (lambda (x) (list-of (list x y) (y <- '(a b)))) '(1 2)) (list-of (list x y) (x <- '(1 2)) (y <- '(a b)))
true
a590226867976433bce9276e7a2793cf4d252210
185024f40e1ceed452781a1f3f57e6d16f57d799
/util.ss
154d1316730faa8df9853e826ef58d4330c3a938
[]
no_license
noelwelsh/numeric
b82cd4ca9e4afb18df0129ec2231fc03f9b66450
ac4488cf8cc6f0558f74ca9b8faad0f198e76a84
refs/heads/master
2021-01-18T21:32:27.393991
2010-02-22T14:05:19
2010-02-22T14:05:19
275,898
1
0
null
null
null
null
UTF-8
Scheme
false
false
3,735
ss
util.ss
#lang scheme/base (require (for-syntax scheme/base)) (require (planet "srfi-4-comprehensions.ss" ("wmfarr" "srfi-4-comprehensions.plt" 1)) (planet schematics/schemeunit:3) "matrix.ss" "f64vector.ss") (provide (all-defined-out)) (define-check (check-m= m1 m2 epsilon) (with-check-info (['message "Unequal number of rows"]) (check-eq? (mrows m1) (mrows m2))) (with-check-info (['message "Unequal number of columns"]) (check-eq? (mcols m1) (mcols m2))) (for* ([r (in-range (mrows m1))] [c (in-range (mcols m1))]) (let ([x1 (mref m1 r c)] [x2 (mref m2 r c)]) (with-check-info (['message (format "Elements ~a and ~a at row ~a, col ~a not within ~a" x1 x2 r c epsilon)]) (check <= (abs (- x1 x2)) epsilon))))) (define-check (check-v= v1 v2 epsilon) (with-check-info (['message "Unequal length"]) (check-eq? (vlength v1) (vlength v2))) (for ([i (in-range (vlength v1))] [x1 (in-f64vector v1)] [x2 (in-f64vector v2)]) (with-check-info (['message (format "Elements ~a and ~a at index ~a are not within ~a" x1 x2 i epsilon)]) (check <= (abs (- x1 x2)) epsilon)))) (define in-2d-range (case-lambda [(b) (in-range 0 b 1)] [(a b) (in-range a b 1)] [(a b step) (unless (real? a) (raise-type-error 'in-range "real-number" a)) (unless (real? b) (raise-type-error 'in-range "real-number" b)) (unless (real? step) (raise-type-error 'in-range "real-number" step)) (make-do-sequence (lambda () (values (lambda (x) x) (lambda (x) (+ x step)) a (if (step . >= . 0) (lambda (x) (< x b)) (lambda (x) (> x b))) (lambda (x) #t) (lambda (x y) #t))))])) (define-sequence-syntax *in-2d-range (lambda () #'in-range) (lambda (stx) (let loop ([stx stx]) (syntax-case stx () [[(id) (_ a b step)] #`[(id) (:do-in ;; outer bindings: ([(start) a] [(end) b] [(inc) step]) ;; outer check: (unless (and (real? start) (real? end) (real? inc)) ;; let `in-range' report the error: (in-range start end inc)) ;; loop bindings: ([pos start]) ;; pos check #,(cond [(not (number? (syntax-e #'step))) #`(if (step . >= . 0) (< pos end) (> pos end))] [((syntax-e #'step) . >= . 0) #'(< pos end)] [else #'(> pos end)]) ;; inner bindings ([(id) pos]) ;; pre guard #t ;; post guard #t ;; loop args ((+ pos inc)))]] [[(id) (_ a b)] (loop #'[(id) (_ a b 1)])] [[(id) (_ b)] (loop #'[(id) (_ 0 b 1)])] [_ #f]))))
false
9ba4a6b59eb697daa91f5acb69f327be1d1b6169
ae48f96aedc36427718dc50276377df48829a64b
/scheme/flatten.scm
402627083c3768a574d7d9d345fbcbae875bc398
[ "Unlicense" ]
permissive
gregr/old-and-miscellaneous
8fce2c8767302c450c8f01f3528b28b0f91fd995
c7a147037b806058d18d9a200ffa4a14f3402d04
refs/heads/master
2021-01-10T18:38:16.311759
2015-04-27T01:00:45
2015-04-27T01:00:45
9,311,629
2
0
null
null
null
null
UTF-8
Scheme
false
false
402
scm
flatten.scm
(define (empty? x) (null? x)) (define (char? x) (and (not (empty? x)) (not (pair? x)))) (define (first x) (car x)) (define (rest x) (cdr x)) (define empty '()) (define (flatten s) (define (flatten-onto s rst) (if (empty? s) rst (let ((fst (first s)) (rst (flatten-onto (rest s) rst))) (if (char? fst) (cons fst rst) (flatten-onto fst rst))))) (flatten-onto s empty))
false
5163ccf5851c2d9cdedcc518194a7e3d856782dc
d074b9a2169d667227f0642c76d332c6d517f1ba
/sicp/ch_4/exercise.4.76.scm
70ab5196a6d8b0e4d97086b66565bfac6b73826e
[]
no_license
zenspider/schemers
4d0390553dda5f46bd486d146ad5eac0ba74cbb4
2939ca553ac79013a4c3aaaec812c1bad3933b16
refs/heads/master
2020-12-02T18:27:37.261206
2019-07-14T15:27:42
2019-07-14T15:27:42
26,163,837
7
0
null
null
null
null
UTF-8
Scheme
false
false
1,223
scm
exercise.4.76.scm
#!/usr/bin/env csi -s (require rackunit) ;;; Exercise 4.76 ;; Our implementation of `and' as a series ;; combination of queries (*Note Figure 4-5::) is elegant, but it is ;; inefficient because in processing the second query of the `and' we ;; must scan the data base for each frame produced by the first ;; query. If the data base has n elements, and a typical query ;; produces a number of output frames proportional to n (say n/k), ;; then scanning the data base for each frame produced by the first ;; query will require n^2/k calls to the pattern matcher. Another ;; approach would be to process the two clauses of the `and' ;; separately, then look for all pairs of output frames that are ;; compatible. If each query produces n/k output frames, then this ;; means that we must perform n^2/k^2 compatibility checks--a factor ;; of k fewer than the number of matches required in our current ;; method. ;; ;; Devise an implementation of `and' that uses this strategy. You ;; must implement a procedure that takes two frames as inputs, checks ;; whether the bindings in the frames are compatible, and, if so, ;; produces a frame that merges the two sets of bindings. This ;; operation is similar to unification.
false
8172e391f668f883cc05923ec8bbfc2fb2e126ad
b60cb8e39ec090137bef8c31ec9958a8b1c3e8a6
/test/R5RS/scp1/circus.scm
df1da35183616deaec55137d42172a237d8315ed
[]
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,966
scm
circus.scm
(define (atom? x) (not (pair? x))) (define VUB-circus '(ann (mien (eef (bas) (bob)) (els (jan) (jos)) (eva (tom) (tim))) (mies (ine (cas) (cor)) (ils (rik) (raf)) (ines (stef) (staf))))) (define (hoofdartiest piramide) (car piramide)) (define (artiesten piramide) (cdr piramide)) (define (artiest? piramide) (and (pair? piramide) (atom? (car piramide)))) (define (onderaan? piramide) (null? (cdr piramide))) (define (jump piramide artiest) (define (jump-hulp piramide pad) (if (and (artiest? piramide) (eq? (hoofdartiest piramide) artiest)) pad (jump-in (artiesten piramide) (cons (hoofdartiest piramide) pad)))) (define (jump-in lst pad) (if (null? lst) #f (or (jump-hulp (car lst) pad) (jump-in (cdr lst) pad)))) (reverse (jump-hulp piramide '()))) (define (fall piramide artiest) (define (fall-hulp piramide pad) (if (and (artiest? piramide) (eq? (hoofdartiest piramide) artiest)) (append pad (list (hoofdartiest piramide)) (map hoofdartiest (artiesten piramide)))) (fall-in (artiesten piramide) (append pad (list (hoofdartiest piramide))))) (define (fall-in lst pad) (if (null? lst) #f (or (fall-hulp (car lst) pad) (fall-in (cdr lst) pad)))) (fall-hulp piramide '())) (and (equal? (jump VUB-circus 'eva) '(ann mien)) (equal? (jump VUB-circus 'stef) '(ann mies ines)) (not (or (fall VUB-circus 'eva) (fall VUB-circus 'stef) (fall VUB-circus 'mies))))
false
635a8cc423e3e9774a45d0760c2f575f5ab1c26d
defeada37d39bca09ef76f66f38683754c0a6aa0
/System/system/code-dom/code-object.sls
8336123ba24d3dd3991631b2c81347c22b66fed0
[]
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
508
sls
code-object.sls
(library (system code-dom code-object) (export new is? code-object? user-data) (import (ironscheme-clr-port)) (define-syntax new (lambda (e) (syntax-case e () ((_ a ...) #'(clr-new System.CodeDom.CodeObject a ...))))) (define (is? a) (clr-is System.CodeDom.CodeObject a)) (define (code-object? a) (clr-is System.CodeDom.CodeObject a)) (define-field-port user-data #f #f (property:) System.CodeDom.CodeObject UserData System.Collections.IDictionary))
true
612c7e76c90242fd46ecb0de8371960910800d6c
defeada37d39bca09ef76f66f38683754c0a6aa0
/mscorlib/system/runtime/compiler-services/is-pinned.sls
2e8b446f410de68403b055d42d8da8fa99f3b9b2
[]
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
267
sls
is-pinned.sls
(library (system runtime compiler-services is-pinned) (export is? is-pinned?) (import (ironscheme-clr-port)) (define (is? a) (clr-is System.Runtime.CompilerServices.IsPinned a)) (define (is-pinned? a) (clr-is System.Runtime.CompilerServices.IsPinned a)))
false
349536a04fc60ce175780e62c0a85223327cbc7f
f4cf5bf3fb3c06b127dda5b5d479c74cecec9ce9
/Sources/LispKit/Resources/Examples/Simplifier.scm
12e72a668d8ee38e144c914981f067600cd22198
[ "Apache-2.0" ]
permissive
objecthub/swift-lispkit
62b907d35fe4f20ecbe022da70075b70a1d86881
90d78a4de3a20447db7fc33bdbeb544efea05dda
refs/heads/master
2023-08-16T21:09:24.735239
2023-08-12T21:37:39
2023-08-12T21:37:39
57,930,217
356
17
Apache-2.0
2023-06-04T12:11:51
2016-05-03T00:37:22
Scheme
UTF-8
Scheme
false
false
2,733
scm
Simplifier.scm
;;; Symbolic Algebraic Simplification ;;; ;;; The code in the subdirectory `paip` implements the pattern matcher and the ;;; algebraic simplifier described in chapter 6.2 and 8 of Peter Norvig's book ;;; "Paradigms of Artificial Intelligence Programming: Case Studies in Common ;;; Lisp" (1992). It was ported from the original Common Lisp code which has ;;; been published under an MIT license at https://github.com/norvig/paip-lisp . ;;; ;;; This program is simply loading the libraries (from a custom location) and ;;; executing a few test cases for procedures `infix->prefix` and `simp`. ;;; More details about the code and its usage can be found at: ;;; https://github.com/norvig/paip-lisp/blob/main/docs/chapter6.md and ;;; https://github.com/norvig/paip-lisp/blob/main/docs/chapter8.md . ;;; ;;; Author: Matthias Zenger ;;; Copyright © 2021 Matthias Zenger. All rights reserved. ;;; ;;; Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file ;;; except in compliance with the License. You may obtain a copy of the License at ;;; ;;; http://www.apache.org/licenses/LICENSE-2.0 ;;; ;;; Unless required by applicable law or agreed to in writing, software distributed under the ;;; License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, ;;; either express or implied. See the License for the specific language governing permissions ;;; and limitations under the License. (import (lispkit base)) ;; Make LispKit aware where the custom libraries are located (load (path (source-directory) "paip/util.sld")) (load (path (source-directory) "paip/patmatch.sld")) (load (path (source-directory) "paip/simplifier.sld")) ;; Import the symbolic simplifier (import (paip simplifier)) (define-syntax display-trans (syntax-rules () ((_ label f expr) (begin (display label) (display " ") (display (quote expr)) (newline) (display " ⟹ ") (display (f (quote expr))) (newline))))) (display-trans "[PRE]" infix->prefix (1 + 2 * sin (1 / x))) (display-trans "[PRE]" infix->prefix ((x + 1) ^ 2 * 3)) (display-trans "[PRE]" infix->prefix (Int 3 * (x + 2) d x)) (display-trans "[SIM]" simp (1 + 2 + x + 3 + 4)) (display-trans "[SIM]" simp (4 * (9 / x) * x - 10)) (display-trans "[SIM]" simp (9 - 3 * (x + x) * x)) (display-trans "[SIM]" simp (d ((cos x) / x) / d x)) (display-trans "[SIM]" simp (d ((a * x ^ 2 + b * x + c) / x) / d x)) (display-trans "[SIM]" simp (Int x * sin(x ^ 2) d x)) (display-trans "[SIM]" simp (Int (3 * x + 2) ^ -2/3 d x)) (display-trans "[SIM]" simp (Int sin(x) / (1 + cos(x)) d x)) (display-trans "[SIM]" simp (Int 8 * x ^ 2 / (x ^ 3 + 2) ^ 3 d x))
true
68753fac813e64250c71eebc663f6b81ebea0316
ebf46dd33d0710f4fe75f85e6ef50f7c000d5e73
/scm/inc/program.scm
25a3cd65663026e7cc39e99f530c4180698fcf80
[]
no_license
heyLu/lp
09b68851599f32c2ed76158639e12d7ab0b5ce1d
df2ccb61b32b06ef0280795289991cc1ade7abf6
refs/heads/main
2023-03-04T06:42:08.346832
2023-02-28T13:25:52
2023-02-28T13:25:52
7,921,157
6
0
null
null
null
null
UTF-8
Scheme
false
false
55
scm
program.scm
(load "compiler.scm") (compile-program '(cons 10 20))
false
6ea7e7bfee7b4fe583817cd4c28d374f813e3201
bf1c9803ae38f9aad027fbe4569ccc6f85ba63ab
/chapter_1/1.2.Procedures.and.the.Processes.They.Generate/ex_1.15.scm
8646162820c82a88b71c096c0b7ff27832e63261
[]
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
668
scm
ex_1.15.scm
#lang sicp (define (cube x) (* x x x)) (define (p x) (display ".") (- (* 3 x) (* 4 (cube x)))) (define (sine angle) (if (not (> (abs angle) 0.1)) angle (p (sine (/ angle 3.0))))) (sine 12.15) ;; 1. function p prints 5 dots => gets called 5 times ;; 2. Order of growth for function ;; The function calls itself until angle < 0.01. It shrinks ;; angle each time by 3. So the function will stop its steps calls ;; when ;; ;; angle/(3^steps) = 0.01 ;; angle = 0.01*3^steps ;; log(angle) = steps * log(0.01*3) ;; steps ~ log(angle) ;; => O(log(n)) ;; Space complexity is log(n) too as the procedure is not tail ;; recursive optimized
false
265be44e3f93285c44325ea60ca1d65ab2a5df9c
c693dbc183fdf13b8eeab4590b91bb6cac786a22
/scheme/sicp/test/set-test.ss
7cf6352d37cfaa998d65e43ab0057e326413fedc
[]
no_license
qianyan/functional-programming
4600a11400176978244f7aed386718614428fd13
34ba5010f9bf68c1ef4fa41ce9e6fdb9fe5a10b5
refs/heads/master
2016-09-01T21:09:32.389073
2015-08-14T07:58:59
2015-08-14T07:58:59
26,963,148
0
0
null
null
null
null
UTF-8
Scheme
false
false
255
ss
set-test.ss
(import (rough-draft unit-test) (rough-draft console-test-runner)) (load "../src/p103_set.ss") (define-test-suite set-operation (define-test should-find-element-of-set (assert-true (element-of-set 1 '(1 2 3))))) (run-test-suite set-operation)
false
9b2ed2586a16578a424b66b9431e87aac3186e62
d6ba773f1c822a5003692c47a6d2b645e47c0907
/lib/postgresql/misc/ssl.sld
9904c06f9448a04d8ff5d9bde40a6162c67bdc5c
[ "BSD-2-Clause", "BSD-3-Clause" ]
permissive
ktakashi/r7rs-postgresql
a2d93e39cd95c0cf659e8336f5aaf62ad61f4f75
94fdaeccee6caa5e9562a8f231329e59ce15aae7
refs/heads/master
2020-04-06T13:13:50.481891
2017-12-11T20:09:43
2017-12-11T20:09:43
26,015,242
23
3
null
2015-02-04T19:40:18
2014-10-31T12:26:02
Scheme
UTF-8
Scheme
false
false
2,632
sld
ssl.sld
;;; -*- mode:scheme; coding:utf-8; -*- ;;; ;;; postgresql/misc/ssl.sld - SSL/TLS ;;; ;;; Copyright (c) 2017 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. ;;; (define-library (postgresql misc ssl) (export socket->ssl-socket ssl-socket-input-port ssl-socket-output-port ssl-socket? ssl-socket-close) (import (scheme base)) (cond-expand (sagittarius (import (rfc tls)) (begin (define (socket->ssl-socket sock) (let ((tls-sock (socket->tls-socket sock))) ;; TODO hello extension (tls-client-handshake tls-sock))) (define ssl-socket-input-port tls-socket-input-port) (define ssl-socket-output-port tls-socket-output-port) (define ssl-socket? tls-socket?) (define ssl-socket-close tls-socket-close))) (else (begin (define (socket->ssl-socket socket) (error "socket->ssl-socket: not supported (PR is welcome)")) (define (ssl-socket-input-port socket) (error "ssl-socket-input-port: not supported (PR is welcome)")) (define (ssl-socket-output-port socket) (error "ssl-socket-output-port: not supported (PR is welcome)")) (define (ssl-socket? obj) #f) (define (ssl-socket-close socket) (error "ssl-socket-close: not supported (PR is welcome)"))))))
false
0f768b60e16bcac5d82b2de8da89e5a1bf02a992
ae4938300d7eea07cbcb32ea4a7b0ead9ac18e82
/proc/predicate/standard.ss
076d0e04e859952439929edcce10e3c03d889d82
[]
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
2,133
ss
standard.ss
#!r6rs (library (imi proc predicate standard) (export any? false? cons/p list/p list*/p listof/p vector/p vectorof/p) (import (rnrs) (imi proc predicate check) (imi proc predicate logic) (imi utils math curried-operator)) ;;; matches any value (define any? (lambda (x) #t)) ;;; matches false (define false? (lambda (x) (not x))) ;;; pair/cons predicate (define (cons/p car-pred cdr-pred) (lambda (x) (and (pair? x) (check-predicate (car x) car-pred) (check-predicate (cdr x) cdr-pred)))) ;;; list predicate, which matches ;;; exact length and args (define (list/p . preds) (if (null? preds) null? (cons/p (car preds) (apply list/p (cdr preds))))) ;;; list predicate, which matches ;;; all preds and the cdr of the ;;; rest with the last pred (define (list*/p pred . preds) (if (null? preds) pred (cons/p pred (apply list*/p (cdr preds))))) ;;; list predicate for a list with ;;; a variable type, but only with ;;; a specific value type in it (define (listof/p pred) (or/p null? (cons/p pred (listof/p pred)))) ;;; vector predicate which matches ;;; exact length and args (define (vector/p . preds) (lambda (x) (and (vector? x) (let loop ([i 0] [preds preds]) (if (null? preds) (= i (vector-length x)) (and (< i (vector-length x)) (check-predicate (vector-ref x i) (car preds)) (loop (add1 i) (cdr preds)))))))) ;;; vector predicate which matches ;;; all elements of vector to `pred` (define (vectorof/p pred) (lambda (x) (and (vector? x) (let loop ([i 0]) (or (= i (vector-length x)) (and (check-predicate (vector-ref x i) pred) (loop (add1 i)))))))) )
false
785ac8bf79f0ca392fe142ae1d0efa72ca6582e1
784dc416df1855cfc41e9efb69637c19a08dca68
/src/std/db/lmdb-test.ss
741f66da1018183ac4c669858c13c70b233d98a4
[ "LGPL-2.1-only", "Apache-2.0", "LGPL-2.1-or-later" ]
permissive
danielsz/gerbil
3597284aa0905b35fe17f105cde04cbb79f1eec1
e20e839e22746175f0473e7414135cec927e10b2
refs/heads/master
2021-01-25T09:44:28.876814
2018-03-26T21:59:32
2018-03-26T21:59:32
123,315,616
0
0
Apache-2.0
2018-02-28T17:02:28
2018-02-28T17:02:28
null
UTF-8
Scheme
false
false
1,706
ss
lmdb-test.ss
;;; -*- Gerbil -*- ;;; (C) vyzo at hackzen.org ;;; :std/db/lmdb unit-test (import :std/test :std/db/lmdb :std/db/_lmdb :gerbil/gambit/random :std/format) (export lmdb-test) (def lmdb-test (test-suite "test :std/db/lmdb library" (def env (lmdb-open (format "/tmp/test.db.~a" (random-integer (expt 2 32))))) (def db (lmdb-open-db env "test")) (test-case "test put txn" (let (txn (lmdb-txn-begin env)) (lmdb-put txn db "hello" "world") (lmdb-put txn db "hello2" "world2") (check (bytes->string (lmdb-get txn db "hello")) => "world") (check (bytes->string (lmdb-get txn db "hello2")) => "world2") (lmdb-txn-commit txn))) (test-case "test get" (let (txn (lmdb-txn-begin env)) (check (bytes->string (lmdb-get txn db "hello")) => "world") (check (bytes->string (lmdb-get txn db "hello2")) => "world2") (lmdb-txn-commit txn))) (test-case "test cursors" (let* ((txn (lmdb-txn-begin env)) (cursor (lmdb-cursor-open txn db)) (entries (let lp ((next (lmdb-cursor-get cursor MDB_FIRST)) (vals [])) (match next ((values key val) (lp (lmdb-cursor-get cursor MDB_NEXT) (cons (cons (bytes->string key) (bytes->string val)) vals))) (#f (reverse vals)))))) (check (length entries) => 2) (check (cdr (assoc "hello" entries)) => "world") (check (cdr (assoc "hello2" entries)) => "world2") (lmdb-txn-commit txn)))))
false
cbb92e217f76c5cc5c41239b150c0781d63524bb
a8e69b82efa3125947b3af219d8f14335e52d057
/prelude.scm
1d76b04ec2cbd4c29d8069a338841789606aca98
[ "MIT" ]
permissive
ArunGant8/n-grams-for-synthesis
ad3f14bb082c1220fcea5cfb69029953a2501508
b53b071e53445337d3fe20db0249363aeb9f3e51
refs/heads/master
2023-04-06T05:51:47.903781
2020-05-26T17:09:14
2020-05-26T17:09:14
null
0
0
null
null
null
null
UTF-8
Scheme
false
false
782
scm
prelude.scm
(define write-data-to-file (lambda (data file-name) (let ((op (open-file-output-port file-name (file-options no-fail) (buffer-mode block) (make-transcoder (utf-8-codec))))) (write data op) (close-output-port op)))) (define display-data-to-file (lambda (data file-name) (let ((op (open-file-output-port file-name (file-options no-fail) (buffer-mode block) (make-transcoder (utf-8-codec))))) (display data op) (close-output-port op)))) (define read-data-from-file (lambda (file-name) (let ((op (open-file-input-port file-name (file-options no-fail) (buffer-mode block) (make-transcoder (utf-8-codec))))) (let ((res (read op))) (close-input-port op) res))))
false
c39b87ad91fa676c5b449767e7cae2ee33a43799
000dbfe5d1df2f18e29a76ea7e2a9556cff5e866
/sitelib/dbm/dumb.scm
5f1d63ae3e12ada454f30fa87f7a80f66daef765
[ "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
5,394
scm
dumb.scm
;;; -*- mode: scheme; coding: utf-8; -*- ;;; ;;; dbm/dumb.scm - A dumb and slow but simple dbm clone ;;; ;;; Copyright (c) 2010-2013 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. ;;; ;; inspired from Python dumbdbm (library (dbm dumb) (export <dumb>) (import (rnrs) (clos user) (sagittarius) (dbm) (dbm private) (binary pack) (srfi :26 cut)) (define-class <dumb-meta> (<dbm-meta>) ()) (define-class <dumb> (<dbm>) ;; we read/write all data at once... ((kv :init-form (make-string-hashtable))) :metaclass <dumb-meta>) ;; TODO these should be somewhere ... (define (write-to-string sexp) (call-with-string-output-port (cut write/ss sexp <>))) (define (read-from-string str) (read/ss (open-string-input-port str))) (define-method dbm-open ((self <dumb>)) (call-next-method) (let ((path (slot-ref self 'path))) (when (eq? (slot-ref self 'rw-mode) :create) ;; we don't create but delete. creation will be done in dbm-close... (when (file-exists? path) (delete-file path))) (when (file-exists? path) (call-with-input-file path (cut read-dumbdbm! <> (slot-ref self 'kv)) :transcoder #f))) self) (define-method dbm-close ((self <dumb>)) (unless (eqv? (slot-ref self 'rw-mode) :read) (call-with-port (open-file-output-port (slot-ref self 'path) (file-options no-fail)) (cut write-dumbdbm <> (slot-ref self 'kv)))) (slot-set! self 'kv #f)) (define-method dbm-closed? ((self <dumb>)) (not (slot-ref self 'kv))) ;;; accessors (define-method dbm-put! ((self <dumb>) key value) (hashtable-set! (slot-ref self 'kv) (%dbm-k2s self key) (%dbm-v2s self value))) (define-method dbm-get ((self <dumb>) key :optional args) (cond ((hashtable-ref (slot-ref self 'kv) (%dbm-k2s self key) #f) => (lambda (v) (%dbm-s2v self v))) ((not (undefined? args)) args) ;; fallback (else (error 'dbm-get "no data for given key" key (slot-ref self 'path))))) (define-method dbm-exists? ((self <dumb>) key) (hashtable-ref (slot-ref self 'kv) (%dbm-k2s self key) #f)) (define-method dbm-delete! ((self <dumb>) key) (hashtable-delete! (slot-ref self 'kv) (%dbm-k2s self key))) ;;; iterations (define-method dbm-fold ((self <dumb>) proc knil) (let ((kv (slot-ref self 'kv))) (let loop ((keys (hashtable-keys-list kv)) (r knil)) (if (null? keys) r (let* ((k (car keys)) (v (hashtable-ref kv k #f))) (loop (cdr keys) (proc (%dbm-s2k self k) (%dbm-s2v self v) r))))))) ;; metaoperations (define-method dbm-db-exists? ((class <dumb-meta>) name) (file-exists? name)) (define-method dbm-db-remove ((class <dumb-meta>) name) (delete-file name)) (define-method dbm-db-copy ((class <dumb-meta>) from to :key (overwrite #f) :rest ignore) (when (and overwrite (file-exists? to)) (delete-file to)) (copy-file from to)) (define-method dbm-db-move ((class <dumb-meta>) from to :key (overwrite #f) :rest ignore) (when (and overwrite (file-exists? to)) (delete-file to)) (copy-file from to) (delete-file from)) ;; it's simple pair of length value records ;; NOTE ;; key-length: 2 byte ;; value-length: 4 byte (define (read-dumbdbm! in store) (let loop ((b (lookahead-u8 in))) (unless (eof-object? b) ;; if something happens then invalid format (let* ((kl (get-unpack in "!uS")) (kv (get-bytevector-n in kl)) (vl (get-unpack in "!uL")) (vv (get-bytevector-n in vl))) (hashtable-set! store (utf8->string kv) (utf8->string vv)))))) (define (write-dumbdbm out store) (for-each (lambda (k) (let* ((v (hashtable-ref store k)) (kv (string->utf8 k)) (vv (string->utf8 v))) (put-bytevector out (pack "!uS" (bytevector-length kv))) (put-bytevector out kv) (put-bytevector out (pack "!uL" (bytevector-length vv))) (put-bytevector out vv))) (hashtable-keys-list store))) )
false
2eda09ff638b66afa12b98efbf41419cebe06c58
29240879328fad0e3d99383f21161cd276dc8dad
/clojure.scm
ccd6eefc0cb94fab5d663ef36d128ecde86a535c
[]
no_license
catharinejm/chicken-clojure
706986bb11fe98e74587e40ec9cad3e8366475e8
1124cd81f59ee6258af426c29a27a6b84b8f9546
refs/heads/master
2021-05-27T07:08:34.045515
2014-10-09T18:04:15
2014-10-09T18:04:15
15,209,931
1
0
null
null
null
null
UTF-8
Scheme
false
false
3,724
scm
clojure.scm
(module clojure * (import chicken scheme data-structures) (set-read-syntax! 'clj (lambda (port) (init-clojure) #:clj)) (set-read-syntax! 'end-clj (lambda (port) (unload-clojure) #:scm)) (define *clj-loaded* (make-parameter #f)) (define scheme-read-table (copy-read-table (current-read-table))) (define clojure-read-table (copy-read-table (current-read-table))) (define old-keyword-style (keyword-style)) (define (is-whitespace? chr) (or (eq? chr #\space) (eq? chr #\tab) (eq? chr #\newline))) (define (read-coll port delim) (let ((chr (peek-char port))) (cond ((eq? chr delim) (read-char port) '()) ((is-whitespace? chr) (read-char port) (read-coll port delim)) (else (cons (read port) (read-coll port delim)))))) (define (contains? lis elm) (cond ((null? lis) #f) ((eqv? elm (car lis)) #t) (else (contains? (cdr lis) elm)))) (define clj-redefines (list 'let 'if 'and 'or)) (define (bind-clojure-literals!) (current-read-table clojure-read-table) (set-read-syntax! #\( (lambda (port) (let ((lis (read-coll port #\)))) (if (and (pair? lis) (symbol? (car lis)) (contains? clj-redefines (car lis))) (cons (string->symbol (conc "clj-" (car lis))) (cdr lis)) lis)))) (set-read-syntax! #\[ (lambda (port) `(vector ,@(read-coll port #\]))))) (define-for-syntax nil '()) (define-for-syntax true #t) (define-for-syntax false #f) (define-for-syntax (take n lis) (cond ((or (null? lis) (< n 1)) '()) (else (cons (car lis) (take (sub1 n) (cdr lis)))))) (define-for-syntax (drop n lis) (cond ((or (null? lis) (< n 1)) lis) (else (drop (sub1 n) (cdr lis))))) (define-for-syntax (partition n lis) (let loop ((lis lis)) (if (null? lis) '() (cons (take n lis) (loop (drop n lis)))))) (define-syntax clj-and (syntax-rules () ((_) #t) ((_ c1) c1) ((_ c1 c2 . r) (##core#let ((c c1)) (clj-if c (clj-and c2 . r) c))))) (define-syntax clj-or (syntax-rules () ((_) nil) ((_ c1 . r) (##core#let ((c c1)) (clj-if c c (clj-or . r)))))) (define-syntax clj-let (ir-macro-transformer (lambda (form i c) (let* ((bindings (cadr form)) (bindings (if (and (list? bindings) (c (car bindings) 'vector)) (cdr bindings) (syntax-error "Bindings must be a vector"))) (body (cddr form))) (if (not (even? (length bindings))) (syntax-error "Even number of binding forms required")) (let ((scm-bindings (partition 2 bindings))) `(let* ,scm-bindings ,@body)))))) (define-syntax clj-if (syntax-rules () ((_) (syntax-error "Too few arguments to if")) ((_ c) (syntax-error "Too few arguments to if")) ((_ cnd then-c) (clj-if cnd then-c '())) ((_ cnd then-c else-c) (if (and cnd (not (null? cnd))) then-c else-c)))) (define (init-clojure) (if (not (*clj-loaded*)) (begin (keyword-style #:prefix) (bind-clojure-literals!) (*clj-loaded* #t)))) (define (unload-clojure) (if (*clj-loaded*) (begin (keyword-style old-keyword-style) (current-read-table scheme-read-table) (*clj-loaded* #f)))) )
true
816f493b34b79f696c1526dc076dc5f7f52abf7e
7f8e3eb6b64a12225cbc704aedb390f8fb9186de
/ch4/ex4.24.scm
e71a1f9d6bf868b71af936950f15241c1d0b2897
[]
no_license
fasl/sicp
70e257b6a5fdd44d2dc5783e99d98f0af527fe45
c7228b6b284c525a4195358f91e27ebd6a419fa3
refs/heads/master
2020-12-26T01:12:07.019658
2017-02-01T10:13:38
2017-02-01T10:13:38
17,853,161
0
0
null
null
null
null
UTF-8
Scheme
false
false
820
scm
ex4.24.scm
;;; ex4.24 (load "../global.scm") (load "./ch4-mceval.scm") (load "./ch4-analyzingmceval.scm") ;; time で計測できるそうです ;; http://www.serendip.ws/archives/2140 (define (driver-loop) (prompt-for-input input-prompt) (let ((input (read))) (let ((output (time (eval input the-global-environment)))) (announce-output output-prompt) (user-print output))) (driver-loop)) (define the-global-environment (setup-environment)) (driver-loop) ;> ;;; M-Eval input: (define (fib n) (define (fib-iter a b count) (if (= count 0) b (fib-iter (+ a b) a (- count 1)))) (fib-iter 1 0 n)) ;> ok (fib 150) ;> 354224848179261915075 q ;; ...違いが出ない... ;; analyzeを使わない方が評価のたびに構文解析を繰り返しているため遅くなるはず... ;;
false
094aa716c2b6a2e615c2cd6aab1b5ecc08ca1191
c3523080a63c7e131d8b6e0994f82a3b9ed901ce
/hertfordstreet/schemes/ergos/ergs.scm
b378ae2ad276e0bb233ebbed0dd4973415902b83
[]
no_license
johnlawrenceaspden/hobby-code
2c77ffdc796e9fe863ae66e84d1e14851bf33d37
d411d21aa19fa889add9f32454915d9b68a61c03
refs/heads/master
2023-08-25T08:41:18.130545
2023-08-06T12:27:29
2023-08-06T12:27:29
377,510
6
4
null
2023-02-22T00:57:49
2009-11-18T19:57:01
Clojure
UTF-8
Scheme
false
false
971
scm
ergs.scm
(title "Simoco Ergo Table 2006") (table (title "VIII Adjusted") (Standard Rower Weight (80 kg)) (Boat Weight (110 kg)) (Oars Weight (10 kg)) (Cox Weight (50 kg)) (Adjusting Exponent 1/6) (Number of Oarsmen 8)) (table (Title "Scull Adjusted") (Standard Rower Weight (80 kg)) (Boat Weight (15 kg)) (Oars Weight (3 kg)) (Adjusting Exponent 2/9) (Number of Oarsmen 1)) ( erg-scores ( (Chris Smith) (76 kg) (30 min 8341 m) ) ( ("Tom Watt") (82 kg) (30 min 8380 m) ( 2000 m 7:30 min) ) ( (Andy Southgate) (13 st 3 lb) (30 min 8194 m) ) ( (Sam Thompson) (82 kg) (30 min 8144 m)) ( (Chris Metcalfe) (192 lb) (30 min 7930 m)) ( (Ollie Crabbe) (13 st) (30 min 7750 m)) ( (John Lawrence Aspden) (86 kg) (2000 m 6:59 min) (30 min 7750 m)) ( (Andy Nicol) (84 kg) (7501 m 30 min)) ( (Gary Dadd) (13 st) (7349 m 30 min)) ( (Dave Byrne) (75 kg) (6865 m 30 min)))
false
278a0d550070c6bb4c66b6dc08743b8c3b59b861
b9eb119317d72a6742dce6db5be8c1f78c7275ad
/random-scheme-stuff/power-set.scm
ee9742b35d0487ddfb26e1cbc6ee4b3336ffcedc
[]
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
380
scm
power-set.scm
;; () => () ;; (foo) => ((foo) ()) ;; (foo bar) => ((foo bar) (foo) (bar) ()) ;; (f b z) => ((f b z) (f b) (f z) (b z) (f) (b) (z) ()) (define (power-set seq) (define (combine sym ps-list) (append (map (lambda (sym-seq) (cons sym sym-seq)) ps-list) ps-list)) (if (null? seq) '(()) (combine (car seq) (power-set (cdr seq)))) )
false
8b0eb171dc27deff695adee54b355a9cd41ae19e
2861d122d2f859f287a9c2414057b2768870b322
/lib/aeolus/cipher/des/schedule.scm
b1b28b3ee2f766ba9f129f64de8441cbe2272cec
[ "BSD-3-Clause" ]
permissive
ktakashi/aeolus
c13162e47404ad99c4834da6677fc31f5288e02e
2a431037ea53cb9dfb5b585ab5c3fbc25374ce8b
refs/heads/master
2016-08-10T08:14:20.628720
2015-10-13T11:18:13
2015-10-13T11:18:13
43,139,534
5
0
null
null
null
null
UTF-8
Scheme
false
false
87,089
scm
schedule.scm
(define BYTEBIT #u8(#o200 #o100 #o40 #o20 #o10 #o4 #o2 #o1)) (define BIGBYTE #( #x800000 #x400000 #x200000 #x100000 #x80000 #x40000 #x20000 #x10000 #x8000 #x4000 #x2000 #x1000 #x800 #x400 #x200 #x100 #x80 #x40 #x20 #x10 #x8 #x4 #x2 #x1 )) (define PC1 #u8(56 48 40 32 24 16 8 0 57 49 41 33 25 17 9 1 58 50 42 34 26 18 10 2 59 51 43 35 62 54 46 38 30 22 14 6 61 53 45 37 29 21 13 5 60 52 44 36 28 20 12 4 27 19 11 3)) (define TOTROT #u8( 1 2 4 6 8 10 12 14 15 17 19 21 23 25 27 28)) (define PC2 #u8(13 16 10 23 0 4 2 27 14 5 20 9 22 18 11 3 25 7 15 6 26 19 12 1 40 51 30 36 46 54 29 39 50 44 32 47 43 48 38 55 33 52 45 41 49 35 28 31)) (define SP1 #( #x01010400 #x00000000 #x00010000 #x01010404 #x01010004 #x00010404 #x00000004 #x00010000 #x00000400 #x01010400 #x01010404 #x00000400 #x01000404 #x01010004 #x01000000 #x00000004 #x00000404 #x01000400 #x01000400 #x00010400 #x00010400 #x01010000 #x01010000 #x01000404 #x00010004 #x01000004 #x01000004 #x00010004 #x00000000 #x00000404 #x00010404 #x01000000 #x00010000 #x01010404 #x00000004 #x01010000 #x01010400 #x01000000 #x01000000 #x00000400 #x01010004 #x00010000 #x00010400 #x01000004 #x00000400 #x00000004 #x01000404 #x00010404 #x01010404 #x00010004 #x01010000 #x01000404 #x01000004 #x00000404 #x00010404 #x01010400 #x00000404 #x01000400 #x01000400 #x00000000 #x00010004 #x00010400 #x00000000 #x01010004 )) (define SP2 #( #x80108020 #x80008000 #x00008000 #x00108020 #x00100000 #x00000020 #x80100020 #x80008020 #x80000020 #x80108020 #x80108000 #x80000000 #x80008000 #x00100000 #x00000020 #x80100020 #x00108000 #x00100020 #x80008020 #x00000000 #x80000000 #x00008000 #x00108020 #x80100000 #x00100020 #x80000020 #x00000000 #x00108000 #x00008020 #x80108000 #x80100000 #x00008020 #x00000000 #x00108020 #x80100020 #x00100000 #x80008020 #x80100000 #x80108000 #x00008000 #x80100000 #x80008000 #x00000020 #x80108020 #x00108020 #x00000020 #x00008000 #x80000000 #x00008020 #x80108000 #x00100000 #x80000020 #x00100020 #x80008020 #x80000020 #x00100020 #x00108000 #x00000000 #x80008000 #x00008020 #x80000000 #x80100020 #x80108020 #x00108000 )) (define SP3 #( #x00000208 #x08020200 #x00000000 #x08020008 #x08000200 #x00000000 #x00020208 #x08000200 #x00020008 #x08000008 #x08000008 #x00020000 #x08020208 #x00020008 #x08020000 #x00000208 #x08000000 #x00000008 #x08020200 #x00000200 #x00020200 #x08020000 #x08020008 #x00020208 #x08000208 #x00020200 #x00020000 #x08000208 #x00000008 #x08020208 #x00000200 #x08000000 #x08020200 #x08000000 #x00020008 #x00000208 #x00020000 #x08020200 #x08000200 #x00000000 #x00000200 #x00020008 #x08020208 #x08000200 #x08000008 #x00000200 #x00000000 #x08020008 #x08000208 #x00020000 #x08000000 #x08020208 #x00000008 #x00020208 #x00020200 #x08000008 #x08020000 #x08000208 #x00000208 #x08020000 #x00020208 #x00000008 #x08020008 #x00020200 )) (define SP4 #( #x00802001 #x00002081 #x00002081 #x00000080 #x00802080 #x00800081 #x00800001 #x00002001 #x00000000 #x00802000 #x00802000 #x00802081 #x00000081 #x00000000 #x00800080 #x00800001 #x00000001 #x00002000 #x00800000 #x00802001 #x00000080 #x00800000 #x00002001 #x00002080 #x00800081 #x00000001 #x00002080 #x00800080 #x00002000 #x00802080 #x00802081 #x00000081 #x00800080 #x00800001 #x00802000 #x00802081 #x00000081 #x00000000 #x00000000 #x00802000 #x00002080 #x00800080 #x00800081 #x00000001 #x00802001 #x00002081 #x00002081 #x00000080 #x00802081 #x00000081 #x00000001 #x00002000 #x00800001 #x00002001 #x00802080 #x00800081 #x00002001 #x00002080 #x00800000 #x00802001 #x00000080 #x00800000 #x00002000 #x00802080 )) (define SP5 #( #x00000100 #x02080100 #x02080000 #x42000100 #x00080000 #x00000100 #x40000000 #x02080000 #x40080100 #x00080000 #x02000100 #x40080100 #x42000100 #x42080000 #x00080100 #x40000000 #x02000000 #x40080000 #x40080000 #x00000000 #x40000100 #x42080100 #x42080100 #x02000100 #x42080000 #x40000100 #x00000000 #x42000000 #x02080100 #x02000000 #x42000000 #x00080100 #x00080000 #x42000100 #x00000100 #x02000000 #x40000000 #x02080000 #x42000100 #x40080100 #x02000100 #x40000000 #x42080000 #x02080100 #x40080100 #x00000100 #x02000000 #x42080000 #x42080100 #x00080100 #x42000000 #x42080100 #x02080000 #x00000000 #x40080000 #x42000000 #x00080100 #x02000100 #x40000100 #x00080000 #x00000000 #x40080000 #x02080100 #x40000100 )) (define SP6 #( #x20000010 #x20400000 #x00004000 #x20404010 #x20400000 #x00000010 #x20404010 #x00400000 #x20004000 #x00404010 #x00400000 #x20000010 #x00400010 #x20004000 #x20000000 #x00004010 #x00000000 #x00400010 #x20004010 #x00004000 #x00404000 #x20004010 #x00000010 #x20400010 #x20400010 #x00000000 #x00404010 #x20404000 #x00004010 #x00404000 #x20404000 #x20000000 #x20004000 #x00000010 #x20400010 #x00404000 #x20404010 #x00400000 #x00004010 #x20000010 #x00400000 #x20004000 #x20000000 #x00004010 #x20000010 #x20404010 #x00404000 #x20400000 #x00404010 #x20404000 #x00000000 #x20400010 #x00000010 #x00004000 #x20400000 #x00404010 #x00004000 #x00400010 #x20004010 #x00000000 #x20404000 #x20000000 #x00400010 #x20004010 )) (define SP7 #( #x00200000 #x04200002 #x04000802 #x00000000 #x00000800 #x04000802 #x00200802 #x04200800 #x04200802 #x00200000 #x00000000 #x04000002 #x00000002 #x04000000 #x04200002 #x00000802 #x04000800 #x00200802 #x00200002 #x04000800 #x04000002 #x04200000 #x04200800 #x00200002 #x04200000 #x00000800 #x00000802 #x04200802 #x00200800 #x00000002 #x04000000 #x00200800 #x04000000 #x00200800 #x00200000 #x04000802 #x04000802 #x04200002 #x04200002 #x00000002 #x00200002 #x04000000 #x04000800 #x00200000 #x04200800 #x00000802 #x00200802 #x04200800 #x00000802 #x04000002 #x04200802 #x04200000 #x00200800 #x00000000 #x00000002 #x04200802 #x00000000 #x00200802 #x04200000 #x00000800 #x04000002 #x04000800 #x00000800 #x00200002 )) (define SP8 #( #x10001040 #x00001000 #x00040000 #x10041040 #x10000000 #x10001040 #x00000040 #x10000000 #x00040040 #x10040000 #x10041040 #x00041000 #x10041000 #x00041040 #x00001000 #x00000040 #x10040000 #x10000040 #x10001000 #x00001040 #x00041000 #x00040040 #x10040040 #x10041000 #x00001040 #x00000000 #x00000000 #x10040040 #x10000040 #x10001000 #x00041040 #x00040000 #x00041040 #x00040000 #x10041000 #x00001000 #x00000040 #x10040040 #x00001000 #x00041040 #x10001000 #x00000040 #x10000040 #x10040000 #x10040040 #x10000000 #x00040000 #x10001040 #x00000000 #x10041040 #x00040040 #x10000040 #x10040000 #x10001000 #x10001040 #x00000000 #x10041040 #x00041000 #x00041000 #x00001040 #x00001040 #x00040040 #x10000000 #x10041000 )) (define DES-IP #( #(#x0000000000000000 #x0000001000000000 #x0000000000000010 #x0000001000000010 #x0000100000000000 #x0000101000000000 #x0000100000000010 #x0000101000000010 #x0000000000001000 #x0000001000001000 #x0000000000001010 #x0000001000001010 #x0000100000001000 #x0000101000001000 #x0000100000001010 #x0000101000001010 #x0010000000000000 #x0010001000000000 #x0010000000000010 #x0010001000000010 #x0010100000000000 #x0010101000000000 #x0010100000000010 #x0010101000000010 #x0010000000001000 #x0010001000001000 #x0010000000001010 #x0010001000001010 #x0010100000001000 #x0010101000001000 #x0010100000001010 #x0010101000001010 #x0000000000100000 #x0000001000100000 #x0000000000100010 #x0000001000100010 #x0000100000100000 #x0000101000100000 #x0000100000100010 #x0000101000100010 #x0000000000101000 #x0000001000101000 #x0000000000101010 #x0000001000101010 #x0000100000101000 #x0000101000101000 #x0000100000101010 #x0000101000101010 #x0010000000100000 #x0010001000100000 #x0010000000100010 #x0010001000100010 #x0010100000100000 #x0010101000100000 #x0010100000100010 #x0010101000100010 #x0010000000101000 #x0010001000101000 #x0010000000101010 #x0010001000101010 #x0010100000101000 #x0010101000101000 #x0010100000101010 #x0010101000101010 #x1000000000000000 #x1000001000000000 #x1000000000000010 #x1000001000000010 #x1000100000000000 #x1000101000000000 #x1000100000000010 #x1000101000000010 #x1000000000001000 #x1000001000001000 #x1000000000001010 #x1000001000001010 #x1000100000001000 #x1000101000001000 #x1000100000001010 #x1000101000001010 #x1010000000000000 #x1010001000000000 #x1010000000000010 #x1010001000000010 #x1010100000000000 #x1010101000000000 #x1010100000000010 #x1010101000000010 #x1010000000001000 #x1010001000001000 #x1010000000001010 #x1010001000001010 #x1010100000001000 #x1010101000001000 #x1010100000001010 #x1010101000001010 #x1000000000100000 #x1000001000100000 #x1000000000100010 #x1000001000100010 #x1000100000100000 #x1000101000100000 #x1000100000100010 #x1000101000100010 #x1000000000101000 #x1000001000101000 #x1000000000101010 #x1000001000101010 #x1000100000101000 #x1000101000101000 #x1000100000101010 #x1000101000101010 #x1010000000100000 #x1010001000100000 #x1010000000100010 #x1010001000100010 #x1010100000100000 #x1010101000100000 #x1010100000100010 #x1010101000100010 #x1010000000101000 #x1010001000101000 #x1010000000101010 #x1010001000101010 #x1010100000101000 #x1010101000101000 #x1010100000101010 #x1010101000101010 #x0000000010000000 #x0000001010000000 #x0000000010000010 #x0000001010000010 #x0000100010000000 #x0000101010000000 #x0000100010000010 #x0000101010000010 #x0000000010001000 #x0000001010001000 #x0000000010001010 #x0000001010001010 #x0000100010001000 #x0000101010001000 #x0000100010001010 #x0000101010001010 #x0010000010000000 #x0010001010000000 #x0010000010000010 #x0010001010000010 #x0010100010000000 #x0010101010000000 #x0010100010000010 #x0010101010000010 #x0010000010001000 #x0010001010001000 #x0010000010001010 #x0010001010001010 #x0010100010001000 #x0010101010001000 #x0010100010001010 #x0010101010001010 #x0000000010100000 #x0000001010100000 #x0000000010100010 #x0000001010100010 #x0000100010100000 #x0000101010100000 #x0000100010100010 #x0000101010100010 #x0000000010101000 #x0000001010101000 #x0000000010101010 #x0000001010101010 #x0000100010101000 #x0000101010101000 #x0000100010101010 #x0000101010101010 #x0010000010100000 #x0010001010100000 #x0010000010100010 #x0010001010100010 #x0010100010100000 #x0010101010100000 #x0010100010100010 #x0010101010100010 #x0010000010101000 #x0010001010101000 #x0010000010101010 #x0010001010101010 #x0010100010101000 #x0010101010101000 #x0010100010101010 #x0010101010101010 #x1000000010000000 #x1000001010000000 #x1000000010000010 #x1000001010000010 #x1000100010000000 #x1000101010000000 #x1000100010000010 #x1000101010000010 #x1000000010001000 #x1000001010001000 #x1000000010001010 #x1000001010001010 #x1000100010001000 #x1000101010001000 #x1000100010001010 #x1000101010001010 #x1010000010000000 #x1010001010000000 #x1010000010000010 #x1010001010000010 #x1010100010000000 #x1010101010000000 #x1010100010000010 #x1010101010000010 #x1010000010001000 #x1010001010001000 #x1010000010001010 #x1010001010001010 #x1010100010001000 #x1010101010001000 #x1010100010001010 #x1010101010001010 #x1000000010100000 #x1000001010100000 #x1000000010100010 #x1000001010100010 #x1000100010100000 #x1000101010100000 #x1000100010100010 #x1000101010100010 #x1000000010101000 #x1000001010101000 #x1000000010101010 #x1000001010101010 #x1000100010101000 #x1000101010101000 #x1000100010101010 #x1000101010101010 #x1010000010100000 #x1010001010100000 #x1010000010100010 #x1010001010100010 #x1010100010100000 #x1010101010100000 #x1010100010100010 #x1010101010100010 #x1010000010101000 #x1010001010101000 #x1010000010101010 #x1010001010101010 #x1010100010101000 #x1010101010101000 #x1010100010101010 #x1010101010101010) #(#x0000000000000000 #x0000000800000000 #x0000000000000008 #x0000000800000008 #x0000080000000000 #x0000080800000000 #x0000080000000008 #x0000080800000008 #x0000000000000800 #x0000000800000800 #x0000000000000808 #x0000000800000808 #x0000080000000800 #x0000080800000800 #x0000080000000808 #x0000080800000808 #x0008000000000000 #x0008000800000000 #x0008000000000008 #x0008000800000008 #x0008080000000000 #x0008080800000000 #x0008080000000008 #x0008080800000008 #x0008000000000800 #x0008000800000800 #x0008000000000808 #x0008000800000808 #x0008080000000800 #x0008080800000800 #x0008080000000808 #x0008080800000808 #x0000000000080000 #x0000000800080000 #x0000000000080008 #x0000000800080008 #x0000080000080000 #x0000080800080000 #x0000080000080008 #x0000080800080008 #x0000000000080800 #x0000000800080800 #x0000000000080808 #x0000000800080808 #x0000080000080800 #x0000080800080800 #x0000080000080808 #x0000080800080808 #x0008000000080000 #x0008000800080000 #x0008000000080008 #x0008000800080008 #x0008080000080000 #x0008080800080000 #x0008080000080008 #x0008080800080008 #x0008000000080800 #x0008000800080800 #x0008000000080808 #x0008000800080808 #x0008080000080800 #x0008080800080800 #x0008080000080808 #x0008080800080808 #x0800000000000000 #x0800000800000000 #x0800000000000008 #x0800000800000008 #x0800080000000000 #x0800080800000000 #x0800080000000008 #x0800080800000008 #x0800000000000800 #x0800000800000800 #x0800000000000808 #x0800000800000808 #x0800080000000800 #x0800080800000800 #x0800080000000808 #x0800080800000808 #x0808000000000000 #x0808000800000000 #x0808000000000008 #x0808000800000008 #x0808080000000000 #x0808080800000000 #x0808080000000008 #x0808080800000008 #x0808000000000800 #x0808000800000800 #x0808000000000808 #x0808000800000808 #x0808080000000800 #x0808080800000800 #x0808080000000808 #x0808080800000808 #x0800000000080000 #x0800000800080000 #x0800000000080008 #x0800000800080008 #x0800080000080000 #x0800080800080000 #x0800080000080008 #x0800080800080008 #x0800000000080800 #x0800000800080800 #x0800000000080808 #x0800000800080808 #x0800080000080800 #x0800080800080800 #x0800080000080808 #x0800080800080808 #x0808000000080000 #x0808000800080000 #x0808000000080008 #x0808000800080008 #x0808080000080000 #x0808080800080000 #x0808080000080008 #x0808080800080008 #x0808000000080800 #x0808000800080800 #x0808000000080808 #x0808000800080808 #x0808080000080800 #x0808080800080800 #x0808080000080808 #x0808080800080808 #x0000000008000000 #x0000000808000000 #x0000000008000008 #x0000000808000008 #x0000080008000000 #x0000080808000000 #x0000080008000008 #x0000080808000008 #x0000000008000800 #x0000000808000800 #x0000000008000808 #x0000000808000808 #x0000080008000800 #x0000080808000800 #x0000080008000808 #x0000080808000808 #x0008000008000000 #x0008000808000000 #x0008000008000008 #x0008000808000008 #x0008080008000000 #x0008080808000000 #x0008080008000008 #x0008080808000008 #x0008000008000800 #x0008000808000800 #x0008000008000808 #x0008000808000808 #x0008080008000800 #x0008080808000800 #x0008080008000808 #x0008080808000808 #x0000000008080000 #x0000000808080000 #x0000000008080008 #x0000000808080008 #x0000080008080000 #x0000080808080000 #x0000080008080008 #x0000080808080008 #x0000000008080800 #x0000000808080800 #x0000000008080808 #x0000000808080808 #x0000080008080800 #x0000080808080800 #x0000080008080808 #x0000080808080808 #x0008000008080000 #x0008000808080000 #x0008000008080008 #x0008000808080008 #x0008080008080000 #x0008080808080000 #x0008080008080008 #x0008080808080008 #x0008000008080800 #x0008000808080800 #x0008000008080808 #x0008000808080808 #x0008080008080800 #x0008080808080800 #x0008080008080808 #x0008080808080808 #x0800000008000000 #x0800000808000000 #x0800000008000008 #x0800000808000008 #x0800080008000000 #x0800080808000000 #x0800080008000008 #x0800080808000008 #x0800000008000800 #x0800000808000800 #x0800000008000808 #x0800000808000808 #x0800080008000800 #x0800080808000800 #x0800080008000808 #x0800080808000808 #x0808000008000000 #x0808000808000000 #x0808000008000008 #x0808000808000008 #x0808080008000000 #x0808080808000000 #x0808080008000008 #x0808080808000008 #x0808000008000800 #x0808000808000800 #x0808000008000808 #x0808000808000808 #x0808080008000800 #x0808080808000800 #x0808080008000808 #x0808080808000808 #x0800000008080000 #x0800000808080000 #x0800000008080008 #x0800000808080008 #x0800080008080000 #x0800080808080000 #x0800080008080008 #x0800080808080008 #x0800000008080800 #x0800000808080800 #x0800000008080808 #x0800000808080808 #x0800080008080800 #x0800080808080800 #x0800080008080808 #x0800080808080808 #x0808000008080000 #x0808000808080000 #x0808000008080008 #x0808000808080008 #x0808080008080000 #x0808080808080000 #x0808080008080008 #x0808080808080008 #x0808000008080800 #x0808000808080800 #x0808000008080808 #x0808000808080808 #x0808080008080800 #x0808080808080800 #x0808080008080808 #x0808080808080808) #(#x0000000000000000 #x0000000400000000 #x0000000000000004 #x0000000400000004 #x0000040000000000 #x0000040400000000 #x0000040000000004 #x0000040400000004 #x0000000000000400 #x0000000400000400 #x0000000000000404 #x0000000400000404 #x0000040000000400 #x0000040400000400 #x0000040000000404 #x0000040400000404 #x0004000000000000 #x0004000400000000 #x0004000000000004 #x0004000400000004 #x0004040000000000 #x0004040400000000 #x0004040000000004 #x0004040400000004 #x0004000000000400 #x0004000400000400 #x0004000000000404 #x0004000400000404 #x0004040000000400 #x0004040400000400 #x0004040000000404 #x0004040400000404 #x0000000000040000 #x0000000400040000 #x0000000000040004 #x0000000400040004 #x0000040000040000 #x0000040400040000 #x0000040000040004 #x0000040400040004 #x0000000000040400 #x0000000400040400 #x0000000000040404 #x0000000400040404 #x0000040000040400 #x0000040400040400 #x0000040000040404 #x0000040400040404 #x0004000000040000 #x0004000400040000 #x0004000000040004 #x0004000400040004 #x0004040000040000 #x0004040400040000 #x0004040000040004 #x0004040400040004 #x0004000000040400 #x0004000400040400 #x0004000000040404 #x0004000400040404 #x0004040000040400 #x0004040400040400 #x0004040000040404 #x0004040400040404 #x0400000000000000 #x0400000400000000 #x0400000000000004 #x0400000400000004 #x0400040000000000 #x0400040400000000 #x0400040000000004 #x0400040400000004 #x0400000000000400 #x0400000400000400 #x0400000000000404 #x0400000400000404 #x0400040000000400 #x0400040400000400 #x0400040000000404 #x0400040400000404 #x0404000000000000 #x0404000400000000 #x0404000000000004 #x0404000400000004 #x0404040000000000 #x0404040400000000 #x0404040000000004 #x0404040400000004 #x0404000000000400 #x0404000400000400 #x0404000000000404 #x0404000400000404 #x0404040000000400 #x0404040400000400 #x0404040000000404 #x0404040400000404 #x0400000000040000 #x0400000400040000 #x0400000000040004 #x0400000400040004 #x0400040000040000 #x0400040400040000 #x0400040000040004 #x0400040400040004 #x0400000000040400 #x0400000400040400 #x0400000000040404 #x0400000400040404 #x0400040000040400 #x0400040400040400 #x0400040000040404 #x0400040400040404 #x0404000000040000 #x0404000400040000 #x0404000000040004 #x0404000400040004 #x0404040000040000 #x0404040400040000 #x0404040000040004 #x0404040400040004 #x0404000000040400 #x0404000400040400 #x0404000000040404 #x0404000400040404 #x0404040000040400 #x0404040400040400 #x0404040000040404 #x0404040400040404 #x0000000004000000 #x0000000404000000 #x0000000004000004 #x0000000404000004 #x0000040004000000 #x0000040404000000 #x0000040004000004 #x0000040404000004 #x0000000004000400 #x0000000404000400 #x0000000004000404 #x0000000404000404 #x0000040004000400 #x0000040404000400 #x0000040004000404 #x0000040404000404 #x0004000004000000 #x0004000404000000 #x0004000004000004 #x0004000404000004 #x0004040004000000 #x0004040404000000 #x0004040004000004 #x0004040404000004 #x0004000004000400 #x0004000404000400 #x0004000004000404 #x0004000404000404 #x0004040004000400 #x0004040404000400 #x0004040004000404 #x0004040404000404 #x0000000004040000 #x0000000404040000 #x0000000004040004 #x0000000404040004 #x0000040004040000 #x0000040404040000 #x0000040004040004 #x0000040404040004 #x0000000004040400 #x0000000404040400 #x0000000004040404 #x0000000404040404 #x0000040004040400 #x0000040404040400 #x0000040004040404 #x0000040404040404 #x0004000004040000 #x0004000404040000 #x0004000004040004 #x0004000404040004 #x0004040004040000 #x0004040404040000 #x0004040004040004 #x0004040404040004 #x0004000004040400 #x0004000404040400 #x0004000004040404 #x0004000404040404 #x0004040004040400 #x0004040404040400 #x0004040004040404 #x0004040404040404 #x0400000004000000 #x0400000404000000 #x0400000004000004 #x0400000404000004 #x0400040004000000 #x0400040404000000 #x0400040004000004 #x0400040404000004 #x0400000004000400 #x0400000404000400 #x0400000004000404 #x0400000404000404 #x0400040004000400 #x0400040404000400 #x0400040004000404 #x0400040404000404 #x0404000004000000 #x0404000404000000 #x0404000004000004 #x0404000404000004 #x0404040004000000 #x0404040404000000 #x0404040004000004 #x0404040404000004 #x0404000004000400 #x0404000404000400 #x0404000004000404 #x0404000404000404 #x0404040004000400 #x0404040404000400 #x0404040004000404 #x0404040404000404 #x0400000004040000 #x0400000404040000 #x0400000004040004 #x0400000404040004 #x0400040004040000 #x0400040404040000 #x0400040004040004 #x0400040404040004 #x0400000004040400 #x0400000404040400 #x0400000004040404 #x0400000404040404 #x0400040004040400 #x0400040404040400 #x0400040004040404 #x0400040404040404 #x0404000004040000 #x0404000404040000 #x0404000004040004 #x0404000404040004 #x0404040004040000 #x0404040404040000 #x0404040004040004 #x0404040404040004 #x0404000004040400 #x0404000404040400 #x0404000004040404 #x0404000404040404 #x0404040004040400 #x0404040404040400 #x0404040004040404 #x0404040404040404) #(#x0000000000000000 #x0000000200000000 #x0000000000000002 #x0000000200000002 #x0000020000000000 #x0000020200000000 #x0000020000000002 #x0000020200000002 #x0000000000000200 #x0000000200000200 #x0000000000000202 #x0000000200000202 #x0000020000000200 #x0000020200000200 #x0000020000000202 #x0000020200000202 #x0002000000000000 #x0002000200000000 #x0002000000000002 #x0002000200000002 #x0002020000000000 #x0002020200000000 #x0002020000000002 #x0002020200000002 #x0002000000000200 #x0002000200000200 #x0002000000000202 #x0002000200000202 #x0002020000000200 #x0002020200000200 #x0002020000000202 #x0002020200000202 #x0000000000020000 #x0000000200020000 #x0000000000020002 #x0000000200020002 #x0000020000020000 #x0000020200020000 #x0000020000020002 #x0000020200020002 #x0000000000020200 #x0000000200020200 #x0000000000020202 #x0000000200020202 #x0000020000020200 #x0000020200020200 #x0000020000020202 #x0000020200020202 #x0002000000020000 #x0002000200020000 #x0002000000020002 #x0002000200020002 #x0002020000020000 #x0002020200020000 #x0002020000020002 #x0002020200020002 #x0002000000020200 #x0002000200020200 #x0002000000020202 #x0002000200020202 #x0002020000020200 #x0002020200020200 #x0002020000020202 #x0002020200020202 #x0200000000000000 #x0200000200000000 #x0200000000000002 #x0200000200000002 #x0200020000000000 #x0200020200000000 #x0200020000000002 #x0200020200000002 #x0200000000000200 #x0200000200000200 #x0200000000000202 #x0200000200000202 #x0200020000000200 #x0200020200000200 #x0200020000000202 #x0200020200000202 #x0202000000000000 #x0202000200000000 #x0202000000000002 #x0202000200000002 #x0202020000000000 #x0202020200000000 #x0202020000000002 #x0202020200000002 #x0202000000000200 #x0202000200000200 #x0202000000000202 #x0202000200000202 #x0202020000000200 #x0202020200000200 #x0202020000000202 #x0202020200000202 #x0200000000020000 #x0200000200020000 #x0200000000020002 #x0200000200020002 #x0200020000020000 #x0200020200020000 #x0200020000020002 #x0200020200020002 #x0200000000020200 #x0200000200020200 #x0200000000020202 #x0200000200020202 #x0200020000020200 #x0200020200020200 #x0200020000020202 #x0200020200020202 #x0202000000020000 #x0202000200020000 #x0202000000020002 #x0202000200020002 #x0202020000020000 #x0202020200020000 #x0202020000020002 #x0202020200020002 #x0202000000020200 #x0202000200020200 #x0202000000020202 #x0202000200020202 #x0202020000020200 #x0202020200020200 #x0202020000020202 #x0202020200020202 #x0000000002000000 #x0000000202000000 #x0000000002000002 #x0000000202000002 #x0000020002000000 #x0000020202000000 #x0000020002000002 #x0000020202000002 #x0000000002000200 #x0000000202000200 #x0000000002000202 #x0000000202000202 #x0000020002000200 #x0000020202000200 #x0000020002000202 #x0000020202000202 #x0002000002000000 #x0002000202000000 #x0002000002000002 #x0002000202000002 #x0002020002000000 #x0002020202000000 #x0002020002000002 #x0002020202000002 #x0002000002000200 #x0002000202000200 #x0002000002000202 #x0002000202000202 #x0002020002000200 #x0002020202000200 #x0002020002000202 #x0002020202000202 #x0000000002020000 #x0000000202020000 #x0000000002020002 #x0000000202020002 #x0000020002020000 #x0000020202020000 #x0000020002020002 #x0000020202020002 #x0000000002020200 #x0000000202020200 #x0000000002020202 #x0000000202020202 #x0000020002020200 #x0000020202020200 #x0000020002020202 #x0000020202020202 #x0002000002020000 #x0002000202020000 #x0002000002020002 #x0002000202020002 #x0002020002020000 #x0002020202020000 #x0002020002020002 #x0002020202020002 #x0002000002020200 #x0002000202020200 #x0002000002020202 #x0002000202020202 #x0002020002020200 #x0002020202020200 #x0002020002020202 #x0002020202020202 #x0200000002000000 #x0200000202000000 #x0200000002000002 #x0200000202000002 #x0200020002000000 #x0200020202000000 #x0200020002000002 #x0200020202000002 #x0200000002000200 #x0200000202000200 #x0200000002000202 #x0200000202000202 #x0200020002000200 #x0200020202000200 #x0200020002000202 #x0200020202000202 #x0202000002000000 #x0202000202000000 #x0202000002000002 #x0202000202000002 #x0202020002000000 #x0202020202000000 #x0202020002000002 #x0202020202000002 #x0202000002000200 #x0202000202000200 #x0202000002000202 #x0202000202000202 #x0202020002000200 #x0202020202000200 #x0202020002000202 #x0202020202000202 #x0200000002020000 #x0200000202020000 #x0200000002020002 #x0200000202020002 #x0200020002020000 #x0200020202020000 #x0200020002020002 #x0200020202020002 #x0200000002020200 #x0200000202020200 #x0200000002020202 #x0200000202020202 #x0200020002020200 #x0200020202020200 #x0200020002020202 #x0200020202020202 #x0202000002020000 #x0202000202020000 #x0202000002020002 #x0202000202020002 #x0202020002020000 #x0202020202020000 #x0202020002020002 #x0202020202020002 #x0202000002020200 #x0202000202020200 #x0202000002020202 #x0202000202020202 #x0202020002020200 #x0202020202020200 #x0202020002020202 #x0202020202020202) #(#x0000000000000000 #x0000010000000000 #x0000000000000100 #x0000010000000100 #x0001000000000000 #x0001010000000000 #x0001000000000100 #x0001010000000100 #x0000000000010000 #x0000010000010000 #x0000000000010100 #x0000010000010100 #x0001000000010000 #x0001010000010000 #x0001000000010100 #x0001010000010100 #x0100000000000000 #x0100010000000000 #x0100000000000100 #x0100010000000100 #x0101000000000000 #x0101010000000000 #x0101000000000100 #x0101010000000100 #x0100000000010000 #x0100010000010000 #x0100000000010100 #x0100010000010100 #x0101000000010000 #x0101010000010000 #x0101000000010100 #x0101010000010100 #x0000000001000000 #x0000010001000000 #x0000000001000100 #x0000010001000100 #x0001000001000000 #x0001010001000000 #x0001000001000100 #x0001010001000100 #x0000000001010000 #x0000010001010000 #x0000000001010100 #x0000010001010100 #x0001000001010000 #x0001010001010000 #x0001000001010100 #x0001010001010100 #x0100000001000000 #x0100010001000000 #x0100000001000100 #x0100010001000100 #x0101000001000000 #x0101010001000000 #x0101000001000100 #x0101010001000100 #x0100000001010000 #x0100010001010000 #x0100000001010100 #x0100010001010100 #x0101000001010000 #x0101010001010000 #x0101000001010100 #x0101010001010100 #x0000000100000000 #x0000010100000000 #x0000000100000100 #x0000010100000100 #x0001000100000000 #x0001010100000000 #x0001000100000100 #x0001010100000100 #x0000000100010000 #x0000010100010000 #x0000000100010100 #x0000010100010100 #x0001000100010000 #x0001010100010000 #x0001000100010100 #x0001010100010100 #x0100000100000000 #x0100010100000000 #x0100000100000100 #x0100010100000100 #x0101000100000000 #x0101010100000000 #x0101000100000100 #x0101010100000100 #x0100000100010000 #x0100010100010000 #x0100000100010100 #x0100010100010100 #x0101000100010000 #x0101010100010000 #x0101000100010100 #x0101010100010100 #x0000000101000000 #x0000010101000000 #x0000000101000100 #x0000010101000100 #x0001000101000000 #x0001010101000000 #x0001000101000100 #x0001010101000100 #x0000000101010000 #x0000010101010000 #x0000000101010100 #x0000010101010100 #x0001000101010000 #x0001010101010000 #x0001000101010100 #x0001010101010100 #x0100000101000000 #x0100010101000000 #x0100000101000100 #x0100010101000100 #x0101000101000000 #x0101010101000000 #x0101000101000100 #x0101010101000100 #x0100000101010000 #x0100010101010000 #x0100000101010100 #x0100010101010100 #x0101000101010000 #x0101010101010000 #x0101000101010100 #x0101010101010100 #x0000000000000001 #x0000010000000001 #x0000000000000101 #x0000010000000101 #x0001000000000001 #x0001010000000001 #x0001000000000101 #x0001010000000101 #x0000000000010001 #x0000010000010001 #x0000000000010101 #x0000010000010101 #x0001000000010001 #x0001010000010001 #x0001000000010101 #x0001010000010101 #x0100000000000001 #x0100010000000001 #x0100000000000101 #x0100010000000101 #x0101000000000001 #x0101010000000001 #x0101000000000101 #x0101010000000101 #x0100000000010001 #x0100010000010001 #x0100000000010101 #x0100010000010101 #x0101000000010001 #x0101010000010001 #x0101000000010101 #x0101010000010101 #x0000000001000001 #x0000010001000001 #x0000000001000101 #x0000010001000101 #x0001000001000001 #x0001010001000001 #x0001000001000101 #x0001010001000101 #x0000000001010001 #x0000010001010001 #x0000000001010101 #x0000010001010101 #x0001000001010001 #x0001010001010001 #x0001000001010101 #x0001010001010101 #x0100000001000001 #x0100010001000001 #x0100000001000101 #x0100010001000101 #x0101000001000001 #x0101010001000001 #x0101000001000101 #x0101010001000101 #x0100000001010001 #x0100010001010001 #x0100000001010101 #x0100010001010101 #x0101000001010001 #x0101010001010001 #x0101000001010101 #x0101010001010101 #x0000000100000001 #x0000010100000001 #x0000000100000101 #x0000010100000101 #x0001000100000001 #x0001010100000001 #x0001000100000101 #x0001010100000101 #x0000000100010001 #x0000010100010001 #x0000000100010101 #x0000010100010101 #x0001000100010001 #x0001010100010001 #x0001000100010101 #x0001010100010101 #x0100000100000001 #x0100010100000001 #x0100000100000101 #x0100010100000101 #x0101000100000001 #x0101010100000001 #x0101000100000101 #x0101010100000101 #x0100000100010001 #x0100010100010001 #x0100000100010101 #x0100010100010101 #x0101000100010001 #x0101010100010001 #x0101000100010101 #x0101010100010101 #x0000000101000001 #x0000010101000001 #x0000000101000101 #x0000010101000101 #x0001000101000001 #x0001010101000001 #x0001000101000101 #x0001010101000101 #x0000000101010001 #x0000010101010001 #x0000000101010101 #x0000010101010101 #x0001000101010001 #x0001010101010001 #x0001000101010101 #x0001010101010101 #x0100000101000001 #x0100010101000001 #x0100000101000101 #x0100010101000101 #x0101000101000001 #x0101010101000001 #x0101000101000101 #x0101010101000101 #x0100000101010001 #x0100010101010001 #x0100000101010101 #x0100010101010101 #x0101000101010001 #x0101010101010001 #x0101000101010101 #x0101010101010101) #(#x0000000000000000 #x0000008000000000 #x0000000000000080 #x0000008000000080 #x0000800000000000 #x0000808000000000 #x0000800000000080 #x0000808000000080 #x0000000000008000 #x0000008000008000 #x0000000000008080 #x0000008000008080 #x0000800000008000 #x0000808000008000 #x0000800000008080 #x0000808000008080 #x0080000000000000 #x0080008000000000 #x0080000000000080 #x0080008000000080 #x0080800000000000 #x0080808000000000 #x0080800000000080 #x0080808000000080 #x0080000000008000 #x0080008000008000 #x0080000000008080 #x0080008000008080 #x0080800000008000 #x0080808000008000 #x0080800000008080 #x0080808000008080 #x0000000000800000 #x0000008000800000 #x0000000000800080 #x0000008000800080 #x0000800000800000 #x0000808000800000 #x0000800000800080 #x0000808000800080 #x0000000000808000 #x0000008000808000 #x0000000000808080 #x0000008000808080 #x0000800000808000 #x0000808000808000 #x0000800000808080 #x0000808000808080 #x0080000000800000 #x0080008000800000 #x0080000000800080 #x0080008000800080 #x0080800000800000 #x0080808000800000 #x0080800000800080 #x0080808000800080 #x0080000000808000 #x0080008000808000 #x0080000000808080 #x0080008000808080 #x0080800000808000 #x0080808000808000 #x0080800000808080 #x0080808000808080 #x8000000000000000 #x8000008000000000 #x8000000000000080 #x8000008000000080 #x8000800000000000 #x8000808000000000 #x8000800000000080 #x8000808000000080 #x8000000000008000 #x8000008000008000 #x8000000000008080 #x8000008000008080 #x8000800000008000 #x8000808000008000 #x8000800000008080 #x8000808000008080 #x8080000000000000 #x8080008000000000 #x8080000000000080 #x8080008000000080 #x8080800000000000 #x8080808000000000 #x8080800000000080 #x8080808000000080 #x8080000000008000 #x8080008000008000 #x8080000000008080 #x8080008000008080 #x8080800000008000 #x8080808000008000 #x8080800000008080 #x8080808000008080 #x8000000000800000 #x8000008000800000 #x8000000000800080 #x8000008000800080 #x8000800000800000 #x8000808000800000 #x8000800000800080 #x8000808000800080 #x8000000000808000 #x8000008000808000 #x8000000000808080 #x8000008000808080 #x8000800000808000 #x8000808000808000 #x8000800000808080 #x8000808000808080 #x8080000000800000 #x8080008000800000 #x8080000000800080 #x8080008000800080 #x8080800000800000 #x8080808000800000 #x8080800000800080 #x8080808000800080 #x8080000000808000 #x8080008000808000 #x8080000000808080 #x8080008000808080 #x8080800000808000 #x8080808000808000 #x8080800000808080 #x8080808000808080 #x0000000080000000 #x0000008080000000 #x0000000080000080 #x0000008080000080 #x0000800080000000 #x0000808080000000 #x0000800080000080 #x0000808080000080 #x0000000080008000 #x0000008080008000 #x0000000080008080 #x0000008080008080 #x0000800080008000 #x0000808080008000 #x0000800080008080 #x0000808080008080 #x0080000080000000 #x0080008080000000 #x0080000080000080 #x0080008080000080 #x0080800080000000 #x0080808080000000 #x0080800080000080 #x0080808080000080 #x0080000080008000 #x0080008080008000 #x0080000080008080 #x0080008080008080 #x0080800080008000 #x0080808080008000 #x0080800080008080 #x0080808080008080 #x0000000080800000 #x0000008080800000 #x0000000080800080 #x0000008080800080 #x0000800080800000 #x0000808080800000 #x0000800080800080 #x0000808080800080 #x0000000080808000 #x0000008080808000 #x0000000080808080 #x0000008080808080 #x0000800080808000 #x0000808080808000 #x0000800080808080 #x0000808080808080 #x0080000080800000 #x0080008080800000 #x0080000080800080 #x0080008080800080 #x0080800080800000 #x0080808080800000 #x0080800080800080 #x0080808080800080 #x0080000080808000 #x0080008080808000 #x0080000080808080 #x0080008080808080 #x0080800080808000 #x0080808080808000 #x0080800080808080 #x0080808080808080 #x8000000080000000 #x8000008080000000 #x8000000080000080 #x8000008080000080 #x8000800080000000 #x8000808080000000 #x8000800080000080 #x8000808080000080 #x8000000080008000 #x8000008080008000 #x8000000080008080 #x8000008080008080 #x8000800080008000 #x8000808080008000 #x8000800080008080 #x8000808080008080 #x8080000080000000 #x8080008080000000 #x8080000080000080 #x8080008080000080 #x8080800080000000 #x8080808080000000 #x8080800080000080 #x8080808080000080 #x8080000080008000 #x8080008080008000 #x8080000080008080 #x8080008080008080 #x8080800080008000 #x8080808080008000 #x8080800080008080 #x8080808080008080 #x8000000080800000 #x8000008080800000 #x8000000080800080 #x8000008080800080 #x8000800080800000 #x8000808080800000 #x8000800080800080 #x8000808080800080 #x8000000080808000 #x8000008080808000 #x8000000080808080 #x8000008080808080 #x8000800080808000 #x8000808080808000 #x8000800080808080 #x8000808080808080 #x8080000080800000 #x8080008080800000 #x8080000080800080 #x8080008080800080 #x8080800080800000 #x8080808080800000 #x8080800080800080 #x8080808080800080 #x8080000080808000 #x8080008080808000 #x8080000080808080 #x8080008080808080 #x8080800080808000 #x8080808080808000 #x8080800080808080 #x8080808080808080) #(#x0000000000000000 #x0000004000000000 #x0000000000000040 #x0000004000000040 #x0000400000000000 #x0000404000000000 #x0000400000000040 #x0000404000000040 #x0000000000004000 #x0000004000004000 #x0000000000004040 #x0000004000004040 #x0000400000004000 #x0000404000004000 #x0000400000004040 #x0000404000004040 #x0040000000000000 #x0040004000000000 #x0040000000000040 #x0040004000000040 #x0040400000000000 #x0040404000000000 #x0040400000000040 #x0040404000000040 #x0040000000004000 #x0040004000004000 #x0040000000004040 #x0040004000004040 #x0040400000004000 #x0040404000004000 #x0040400000004040 #x0040404000004040 #x0000000000400000 #x0000004000400000 #x0000000000400040 #x0000004000400040 #x0000400000400000 #x0000404000400000 #x0000400000400040 #x0000404000400040 #x0000000000404000 #x0000004000404000 #x0000000000404040 #x0000004000404040 #x0000400000404000 #x0000404000404000 #x0000400000404040 #x0000404000404040 #x0040000000400000 #x0040004000400000 #x0040000000400040 #x0040004000400040 #x0040400000400000 #x0040404000400000 #x0040400000400040 #x0040404000400040 #x0040000000404000 #x0040004000404000 #x0040000000404040 #x0040004000404040 #x0040400000404000 #x0040404000404000 #x0040400000404040 #x0040404000404040 #x4000000000000000 #x4000004000000000 #x4000000000000040 #x4000004000000040 #x4000400000000000 #x4000404000000000 #x4000400000000040 #x4000404000000040 #x4000000000004000 #x4000004000004000 #x4000000000004040 #x4000004000004040 #x4000400000004000 #x4000404000004000 #x4000400000004040 #x4000404000004040 #x4040000000000000 #x4040004000000000 #x4040000000000040 #x4040004000000040 #x4040400000000000 #x4040404000000000 #x4040400000000040 #x4040404000000040 #x4040000000004000 #x4040004000004000 #x4040000000004040 #x4040004000004040 #x4040400000004000 #x4040404000004000 #x4040400000004040 #x4040404000004040 #x4000000000400000 #x4000004000400000 #x4000000000400040 #x4000004000400040 #x4000400000400000 #x4000404000400000 #x4000400000400040 #x4000404000400040 #x4000000000404000 #x4000004000404000 #x4000000000404040 #x4000004000404040 #x4000400000404000 #x4000404000404000 #x4000400000404040 #x4000404000404040 #x4040000000400000 #x4040004000400000 #x4040000000400040 #x4040004000400040 #x4040400000400000 #x4040404000400000 #x4040400000400040 #x4040404000400040 #x4040000000404000 #x4040004000404000 #x4040000000404040 #x4040004000404040 #x4040400000404000 #x4040404000404000 #x4040400000404040 #x4040404000404040 #x0000000040000000 #x0000004040000000 #x0000000040000040 #x0000004040000040 #x0000400040000000 #x0000404040000000 #x0000400040000040 #x0000404040000040 #x0000000040004000 #x0000004040004000 #x0000000040004040 #x0000004040004040 #x0000400040004000 #x0000404040004000 #x0000400040004040 #x0000404040004040 #x0040000040000000 #x0040004040000000 #x0040000040000040 #x0040004040000040 #x0040400040000000 #x0040404040000000 #x0040400040000040 #x0040404040000040 #x0040000040004000 #x0040004040004000 #x0040000040004040 #x0040004040004040 #x0040400040004000 #x0040404040004000 #x0040400040004040 #x0040404040004040 #x0000000040400000 #x0000004040400000 #x0000000040400040 #x0000004040400040 #x0000400040400000 #x0000404040400000 #x0000400040400040 #x0000404040400040 #x0000000040404000 #x0000004040404000 #x0000000040404040 #x0000004040404040 #x0000400040404000 #x0000404040404000 #x0000400040404040 #x0000404040404040 #x0040000040400000 #x0040004040400000 #x0040000040400040 #x0040004040400040 #x0040400040400000 #x0040404040400000 #x0040400040400040 #x0040404040400040 #x0040000040404000 #x0040004040404000 #x0040000040404040 #x0040004040404040 #x0040400040404000 #x0040404040404000 #x0040400040404040 #x0040404040404040 #x4000000040000000 #x4000004040000000 #x4000000040000040 #x4000004040000040 #x4000400040000000 #x4000404040000000 #x4000400040000040 #x4000404040000040 #x4000000040004000 #x4000004040004000 #x4000000040004040 #x4000004040004040 #x4000400040004000 #x4000404040004000 #x4000400040004040 #x4000404040004040 #x4040000040000000 #x4040004040000000 #x4040000040000040 #x4040004040000040 #x4040400040000000 #x4040404040000000 #x4040400040000040 #x4040404040000040 #x4040000040004000 #x4040004040004000 #x4040000040004040 #x4040004040004040 #x4040400040004000 #x4040404040004000 #x4040400040004040 #x4040404040004040 #x4000000040400000 #x4000004040400000 #x4000000040400040 #x4000004040400040 #x4000400040400000 #x4000404040400000 #x4000400040400040 #x4000404040400040 #x4000000040404000 #x4000004040404000 #x4000000040404040 #x4000004040404040 #x4000400040404000 #x4000404040404000 #x4000400040404040 #x4000404040404040 #x4040000040400000 #x4040004040400000 #x4040000040400040 #x4040004040400040 #x4040400040400000 #x4040404040400000 #x4040400040400040 #x4040404040400040 #x4040000040404000 #x4040004040404000 #x4040000040404040 #x4040004040404040 #x4040400040404000 #x4040404040404000 #x4040400040404040 #x4040404040404040) #(#x0000000000000000 #x0000002000000000 #x0000000000000020 #x0000002000000020 #x0000200000000000 #x0000202000000000 #x0000200000000020 #x0000202000000020 #x0000000000002000 #x0000002000002000 #x0000000000002020 #x0000002000002020 #x0000200000002000 #x0000202000002000 #x0000200000002020 #x0000202000002020 #x0020000000000000 #x0020002000000000 #x0020000000000020 #x0020002000000020 #x0020200000000000 #x0020202000000000 #x0020200000000020 #x0020202000000020 #x0020000000002000 #x0020002000002000 #x0020000000002020 #x0020002000002020 #x0020200000002000 #x0020202000002000 #x0020200000002020 #x0020202000002020 #x0000000000200000 #x0000002000200000 #x0000000000200020 #x0000002000200020 #x0000200000200000 #x0000202000200000 #x0000200000200020 #x0000202000200020 #x0000000000202000 #x0000002000202000 #x0000000000202020 #x0000002000202020 #x0000200000202000 #x0000202000202000 #x0000200000202020 #x0000202000202020 #x0020000000200000 #x0020002000200000 #x0020000000200020 #x0020002000200020 #x0020200000200000 #x0020202000200000 #x0020200000200020 #x0020202000200020 #x0020000000202000 #x0020002000202000 #x0020000000202020 #x0020002000202020 #x0020200000202000 #x0020202000202000 #x0020200000202020 #x0020202000202020 #x2000000000000000 #x2000002000000000 #x2000000000000020 #x2000002000000020 #x2000200000000000 #x2000202000000000 #x2000200000000020 #x2000202000000020 #x2000000000002000 #x2000002000002000 #x2000000000002020 #x2000002000002020 #x2000200000002000 #x2000202000002000 #x2000200000002020 #x2000202000002020 #x2020000000000000 #x2020002000000000 #x2020000000000020 #x2020002000000020 #x2020200000000000 #x2020202000000000 #x2020200000000020 #x2020202000000020 #x2020000000002000 #x2020002000002000 #x2020000000002020 #x2020002000002020 #x2020200000002000 #x2020202000002000 #x2020200000002020 #x2020202000002020 #x2000000000200000 #x2000002000200000 #x2000000000200020 #x2000002000200020 #x2000200000200000 #x2000202000200000 #x2000200000200020 #x2000202000200020 #x2000000000202000 #x2000002000202000 #x2000000000202020 #x2000002000202020 #x2000200000202000 #x2000202000202000 #x2000200000202020 #x2000202000202020 #x2020000000200000 #x2020002000200000 #x2020000000200020 #x2020002000200020 #x2020200000200000 #x2020202000200000 #x2020200000200020 #x2020202000200020 #x2020000000202000 #x2020002000202000 #x2020000000202020 #x2020002000202020 #x2020200000202000 #x2020202000202000 #x2020200000202020 #x2020202000202020 #x0000000020000000 #x0000002020000000 #x0000000020000020 #x0000002020000020 #x0000200020000000 #x0000202020000000 #x0000200020000020 #x0000202020000020 #x0000000020002000 #x0000002020002000 #x0000000020002020 #x0000002020002020 #x0000200020002000 #x0000202020002000 #x0000200020002020 #x0000202020002020 #x0020000020000000 #x0020002020000000 #x0020000020000020 #x0020002020000020 #x0020200020000000 #x0020202020000000 #x0020200020000020 #x0020202020000020 #x0020000020002000 #x0020002020002000 #x0020000020002020 #x0020002020002020 #x0020200020002000 #x0020202020002000 #x0020200020002020 #x0020202020002020 #x0000000020200000 #x0000002020200000 #x0000000020200020 #x0000002020200020 #x0000200020200000 #x0000202020200000 #x0000200020200020 #x0000202020200020 #x0000000020202000 #x0000002020202000 #x0000000020202020 #x0000002020202020 #x0000200020202000 #x0000202020202000 #x0000200020202020 #x0000202020202020 #x0020000020200000 #x0020002020200000 #x0020000020200020 #x0020002020200020 #x0020200020200000 #x0020202020200000 #x0020200020200020 #x0020202020200020 #x0020000020202000 #x0020002020202000 #x0020000020202020 #x0020002020202020 #x0020200020202000 #x0020202020202000 #x0020200020202020 #x0020202020202020 #x2000000020000000 #x2000002020000000 #x2000000020000020 #x2000002020000020 #x2000200020000000 #x2000202020000000 #x2000200020000020 #x2000202020000020 #x2000000020002000 #x2000002020002000 #x2000000020002020 #x2000002020002020 #x2000200020002000 #x2000202020002000 #x2000200020002020 #x2000202020002020 #x2020000020000000 #x2020002020000000 #x2020000020000020 #x2020002020000020 #x2020200020000000 #x2020202020000000 #x2020200020000020 #x2020202020000020 #x2020000020002000 #x2020002020002000 #x2020000020002020 #x2020002020002020 #x2020200020002000 #x2020202020002000 #x2020200020002020 #x2020202020002020 #x2000000020200000 #x2000002020200000 #x2000000020200020 #x2000002020200020 #x2000200020200000 #x2000202020200000 #x2000200020200020 #x2000202020200020 #x2000000020202000 #x2000002020202000 #x2000000020202020 #x2000002020202020 #x2000200020202000 #x2000202020202000 #x2000200020202020 #x2000202020202020 #x2020000020200000 #x2020002020200000 #x2020000020200020 #x2020002020200020 #x2020200020200000 #x2020202020200000 #x2020200020200020 #x2020202020200020 #x2020000020202000 #x2020002020202000 #x2020000020202020 #x2020002020202020 #x2020200020202000 #x2020202020202000 #x2020200020202020 #x2020202020202020) )) (define DES-FP #( #(#x0000000000000000 #x0000008000000000 #x0000000002000000 #x0000008002000000 #x0000000000020000 #x0000008000020000 #x0000000002020000 #x0000008002020000 #x0000000000000200 #x0000008000000200 #x0000000002000200 #x0000008002000200 #x0000000000020200 #x0000008000020200 #x0000000002020200 #x0000008002020200 #x0000000000000002 #x0000008000000002 #x0000000002000002 #x0000008002000002 #x0000000000020002 #x0000008000020002 #x0000000002020002 #x0000008002020002 #x0000000000000202 #x0000008000000202 #x0000000002000202 #x0000008002000202 #x0000000000020202 #x0000008000020202 #x0000000002020202 #x0000008002020202 #x0200000000000000 #x0200008000000000 #x0200000002000000 #x0200008002000000 #x0200000000020000 #x0200008000020000 #x0200000002020000 #x0200008002020000 #x0200000000000200 #x0200008000000200 #x0200000002000200 #x0200008002000200 #x0200000000020200 #x0200008000020200 #x0200000002020200 #x0200008002020200 #x0200000000000002 #x0200008000000002 #x0200000002000002 #x0200008002000002 #x0200000000020002 #x0200008000020002 #x0200000002020002 #x0200008002020002 #x0200000000000202 #x0200008000000202 #x0200000002000202 #x0200008002000202 #x0200000000020202 #x0200008000020202 #x0200000002020202 #x0200008002020202 #x0002000000000000 #x0002008000000000 #x0002000002000000 #x0002008002000000 #x0002000000020000 #x0002008000020000 #x0002000002020000 #x0002008002020000 #x0002000000000200 #x0002008000000200 #x0002000002000200 #x0002008002000200 #x0002000000020200 #x0002008000020200 #x0002000002020200 #x0002008002020200 #x0002000000000002 #x0002008000000002 #x0002000002000002 #x0002008002000002 #x0002000000020002 #x0002008000020002 #x0002000002020002 #x0002008002020002 #x0002000000000202 #x0002008000000202 #x0002000002000202 #x0002008002000202 #x0002000000020202 #x0002008000020202 #x0002000002020202 #x0002008002020202 #x0202000000000000 #x0202008000000000 #x0202000002000000 #x0202008002000000 #x0202000000020000 #x0202008000020000 #x0202000002020000 #x0202008002020000 #x0202000000000200 #x0202008000000200 #x0202000002000200 #x0202008002000200 #x0202000000020200 #x0202008000020200 #x0202000002020200 #x0202008002020200 #x0202000000000002 #x0202008000000002 #x0202000002000002 #x0202008002000002 #x0202000000020002 #x0202008000020002 #x0202000002020002 #x0202008002020002 #x0202000000000202 #x0202008000000202 #x0202000002000202 #x0202008002000202 #x0202000000020202 #x0202008000020202 #x0202000002020202 #x0202008002020202 #x0000020000000000 #x0000028000000000 #x0000020002000000 #x0000028002000000 #x0000020000020000 #x0000028000020000 #x0000020002020000 #x0000028002020000 #x0000020000000200 #x0000028000000200 #x0000020002000200 #x0000028002000200 #x0000020000020200 #x0000028000020200 #x0000020002020200 #x0000028002020200 #x0000020000000002 #x0000028000000002 #x0000020002000002 #x0000028002000002 #x0000020000020002 #x0000028000020002 #x0000020002020002 #x0000028002020002 #x0000020000000202 #x0000028000000202 #x0000020002000202 #x0000028002000202 #x0000020000020202 #x0000028000020202 #x0000020002020202 #x0000028002020202 #x0200020000000000 #x0200028000000000 #x0200020002000000 #x0200028002000000 #x0200020000020000 #x0200028000020000 #x0200020002020000 #x0200028002020000 #x0200020000000200 #x0200028000000200 #x0200020002000200 #x0200028002000200 #x0200020000020200 #x0200028000020200 #x0200020002020200 #x0200028002020200 #x0200020000000002 #x0200028000000002 #x0200020002000002 #x0200028002000002 #x0200020000020002 #x0200028000020002 #x0200020002020002 #x0200028002020002 #x0200020000000202 #x0200028000000202 #x0200020002000202 #x0200028002000202 #x0200020000020202 #x0200028000020202 #x0200020002020202 #x0200028002020202 #x0002020000000000 #x0002028000000000 #x0002020002000000 #x0002028002000000 #x0002020000020000 #x0002028000020000 #x0002020002020000 #x0002028002020000 #x0002020000000200 #x0002028000000200 #x0002020002000200 #x0002028002000200 #x0002020000020200 #x0002028000020200 #x0002020002020200 #x0002028002020200 #x0002020000000002 #x0002028000000002 #x0002020002000002 #x0002028002000002 #x0002020000020002 #x0002028000020002 #x0002020002020002 #x0002028002020002 #x0002020000000202 #x0002028000000202 #x0002020002000202 #x0002028002000202 #x0002020000020202 #x0002028000020202 #x0002020002020202 #x0002028002020202 #x0202020000000000 #x0202028000000000 #x0202020002000000 #x0202028002000000 #x0202020000020000 #x0202028000020000 #x0202020002020000 #x0202028002020000 #x0202020000000200 #x0202028000000200 #x0202020002000200 #x0202028002000200 #x0202020000020200 #x0202028000020200 #x0202020002020200 #x0202028002020200 #x0202020000000002 #x0202028000000002 #x0202020002000002 #x0202028002000002 #x0202020000020002 #x0202028000020002 #x0202020002020002 #x0202028002020002 #x0202020000000202 #x0202028000000202 #x0202020002000202 #x0202028002000202 #x0202020000020202 #x0202028000020202 #x0202020002020202 #x0202028002020202) #(#x0000000000000000 #x0000000200000000 #x0000000008000000 #x0000000208000000 #x0000000000080000 #x0000000200080000 #x0000000008080000 #x0000000208080000 #x0000000000000800 #x0000000200000800 #x0000000008000800 #x0000000208000800 #x0000000000080800 #x0000000200080800 #x0000000008080800 #x0000000208080800 #x0000000000000008 #x0000000200000008 #x0000000008000008 #x0000000208000008 #x0000000000080008 #x0000000200080008 #x0000000008080008 #x0000000208080008 #x0000000000000808 #x0000000200000808 #x0000000008000808 #x0000000208000808 #x0000000000080808 #x0000000200080808 #x0000000008080808 #x0000000208080808 #x0800000000000000 #x0800000200000000 #x0800000008000000 #x0800000208000000 #x0800000000080000 #x0800000200080000 #x0800000008080000 #x0800000208080000 #x0800000000000800 #x0800000200000800 #x0800000008000800 #x0800000208000800 #x0800000000080800 #x0800000200080800 #x0800000008080800 #x0800000208080800 #x0800000000000008 #x0800000200000008 #x0800000008000008 #x0800000208000008 #x0800000000080008 #x0800000200080008 #x0800000008080008 #x0800000208080008 #x0800000000000808 #x0800000200000808 #x0800000008000808 #x0800000208000808 #x0800000000080808 #x0800000200080808 #x0800000008080808 #x0800000208080808 #x0008000000000000 #x0008000200000000 #x0008000008000000 #x0008000208000000 #x0008000000080000 #x0008000200080000 #x0008000008080000 #x0008000208080000 #x0008000000000800 #x0008000200000800 #x0008000008000800 #x0008000208000800 #x0008000000080800 #x0008000200080800 #x0008000008080800 #x0008000208080800 #x0008000000000008 #x0008000200000008 #x0008000008000008 #x0008000208000008 #x0008000000080008 #x0008000200080008 #x0008000008080008 #x0008000208080008 #x0008000000000808 #x0008000200000808 #x0008000008000808 #x0008000208000808 #x0008000000080808 #x0008000200080808 #x0008000008080808 #x0008000208080808 #x0808000000000000 #x0808000200000000 #x0808000008000000 #x0808000208000000 #x0808000000080000 #x0808000200080000 #x0808000008080000 #x0808000208080000 #x0808000000000800 #x0808000200000800 #x0808000008000800 #x0808000208000800 #x0808000000080800 #x0808000200080800 #x0808000008080800 #x0808000208080800 #x0808000000000008 #x0808000200000008 #x0808000008000008 #x0808000208000008 #x0808000000080008 #x0808000200080008 #x0808000008080008 #x0808000208080008 #x0808000000000808 #x0808000200000808 #x0808000008000808 #x0808000208000808 #x0808000000080808 #x0808000200080808 #x0808000008080808 #x0808000208080808 #x0000080000000000 #x0000080200000000 #x0000080008000000 #x0000080208000000 #x0000080000080000 #x0000080200080000 #x0000080008080000 #x0000080208080000 #x0000080000000800 #x0000080200000800 #x0000080008000800 #x0000080208000800 #x0000080000080800 #x0000080200080800 #x0000080008080800 #x0000080208080800 #x0000080000000008 #x0000080200000008 #x0000080008000008 #x0000080208000008 #x0000080000080008 #x0000080200080008 #x0000080008080008 #x0000080208080008 #x0000080000000808 #x0000080200000808 #x0000080008000808 #x0000080208000808 #x0000080000080808 #x0000080200080808 #x0000080008080808 #x0000080208080808 #x0800080000000000 #x0800080200000000 #x0800080008000000 #x0800080208000000 #x0800080000080000 #x0800080200080000 #x0800080008080000 #x0800080208080000 #x0800080000000800 #x0800080200000800 #x0800080008000800 #x0800080208000800 #x0800080000080800 #x0800080200080800 #x0800080008080800 #x0800080208080800 #x0800080000000008 #x0800080200000008 #x0800080008000008 #x0800080208000008 #x0800080000080008 #x0800080200080008 #x0800080008080008 #x0800080208080008 #x0800080000000808 #x0800080200000808 #x0800080008000808 #x0800080208000808 #x0800080000080808 #x0800080200080808 #x0800080008080808 #x0800080208080808 #x0008080000000000 #x0008080200000000 #x0008080008000000 #x0008080208000000 #x0008080000080000 #x0008080200080000 #x0008080008080000 #x0008080208080000 #x0008080000000800 #x0008080200000800 #x0008080008000800 #x0008080208000800 #x0008080000080800 #x0008080200080800 #x0008080008080800 #x0008080208080800 #x0008080000000008 #x0008080200000008 #x0008080008000008 #x0008080208000008 #x0008080000080008 #x0008080200080008 #x0008080008080008 #x0008080208080008 #x0008080000000808 #x0008080200000808 #x0008080008000808 #x0008080208000808 #x0008080000080808 #x0008080200080808 #x0008080008080808 #x0008080208080808 #x0808080000000000 #x0808080200000000 #x0808080008000000 #x0808080208000000 #x0808080000080000 #x0808080200080000 #x0808080008080000 #x0808080208080000 #x0808080000000800 #x0808080200000800 #x0808080008000800 #x0808080208000800 #x0808080000080800 #x0808080200080800 #x0808080008080800 #x0808080208080800 #x0808080000000008 #x0808080200000008 #x0808080008000008 #x0808080208000008 #x0808080000080008 #x0808080200080008 #x0808080008080008 #x0808080208080008 #x0808080000000808 #x0808080200000808 #x0808080008000808 #x0808080208000808 #x0808080000080808 #x0808080200080808 #x0808080008080808 #x0808080208080808) #(#x0000000000000000 #x0000000800000000 #x0000000020000000 #x0000000820000000 #x0000000000200000 #x0000000800200000 #x0000000020200000 #x0000000820200000 #x0000000000002000 #x0000000800002000 #x0000000020002000 #x0000000820002000 #x0000000000202000 #x0000000800202000 #x0000000020202000 #x0000000820202000 #x0000000000000020 #x0000000800000020 #x0000000020000020 #x0000000820000020 #x0000000000200020 #x0000000800200020 #x0000000020200020 #x0000000820200020 #x0000000000002020 #x0000000800002020 #x0000000020002020 #x0000000820002020 #x0000000000202020 #x0000000800202020 #x0000000020202020 #x0000000820202020 #x2000000000000000 #x2000000800000000 #x2000000020000000 #x2000000820000000 #x2000000000200000 #x2000000800200000 #x2000000020200000 #x2000000820200000 #x2000000000002000 #x2000000800002000 #x2000000020002000 #x2000000820002000 #x2000000000202000 #x2000000800202000 #x2000000020202000 #x2000000820202000 #x2000000000000020 #x2000000800000020 #x2000000020000020 #x2000000820000020 #x2000000000200020 #x2000000800200020 #x2000000020200020 #x2000000820200020 #x2000000000002020 #x2000000800002020 #x2000000020002020 #x2000000820002020 #x2000000000202020 #x2000000800202020 #x2000000020202020 #x2000000820202020 #x0020000000000000 #x0020000800000000 #x0020000020000000 #x0020000820000000 #x0020000000200000 #x0020000800200000 #x0020000020200000 #x0020000820200000 #x0020000000002000 #x0020000800002000 #x0020000020002000 #x0020000820002000 #x0020000000202000 #x0020000800202000 #x0020000020202000 #x0020000820202000 #x0020000000000020 #x0020000800000020 #x0020000020000020 #x0020000820000020 #x0020000000200020 #x0020000800200020 #x0020000020200020 #x0020000820200020 #x0020000000002020 #x0020000800002020 #x0020000020002020 #x0020000820002020 #x0020000000202020 #x0020000800202020 #x0020000020202020 #x0020000820202020 #x2020000000000000 #x2020000800000000 #x2020000020000000 #x2020000820000000 #x2020000000200000 #x2020000800200000 #x2020000020200000 #x2020000820200000 #x2020000000002000 #x2020000800002000 #x2020000020002000 #x2020000820002000 #x2020000000202000 #x2020000800202000 #x2020000020202000 #x2020000820202000 #x2020000000000020 #x2020000800000020 #x2020000020000020 #x2020000820000020 #x2020000000200020 #x2020000800200020 #x2020000020200020 #x2020000820200020 #x2020000000002020 #x2020000800002020 #x2020000020002020 #x2020000820002020 #x2020000000202020 #x2020000800202020 #x2020000020202020 #x2020000820202020 #x0000200000000000 #x0000200800000000 #x0000200020000000 #x0000200820000000 #x0000200000200000 #x0000200800200000 #x0000200020200000 #x0000200820200000 #x0000200000002000 #x0000200800002000 #x0000200020002000 #x0000200820002000 #x0000200000202000 #x0000200800202000 #x0000200020202000 #x0000200820202000 #x0000200000000020 #x0000200800000020 #x0000200020000020 #x0000200820000020 #x0000200000200020 #x0000200800200020 #x0000200020200020 #x0000200820200020 #x0000200000002020 #x0000200800002020 #x0000200020002020 #x0000200820002020 #x0000200000202020 #x0000200800202020 #x0000200020202020 #x0000200820202020 #x2000200000000000 #x2000200800000000 #x2000200020000000 #x2000200820000000 #x2000200000200000 #x2000200800200000 #x2000200020200000 #x2000200820200000 #x2000200000002000 #x2000200800002000 #x2000200020002000 #x2000200820002000 #x2000200000202000 #x2000200800202000 #x2000200020202000 #x2000200820202000 #x2000200000000020 #x2000200800000020 #x2000200020000020 #x2000200820000020 #x2000200000200020 #x2000200800200020 #x2000200020200020 #x2000200820200020 #x2000200000002020 #x2000200800002020 #x2000200020002020 #x2000200820002020 #x2000200000202020 #x2000200800202020 #x2000200020202020 #x2000200820202020 #x0020200000000000 #x0020200800000000 #x0020200020000000 #x0020200820000000 #x0020200000200000 #x0020200800200000 #x0020200020200000 #x0020200820200000 #x0020200000002000 #x0020200800002000 #x0020200020002000 #x0020200820002000 #x0020200000202000 #x0020200800202000 #x0020200020202000 #x0020200820202000 #x0020200000000020 #x0020200800000020 #x0020200020000020 #x0020200820000020 #x0020200000200020 #x0020200800200020 #x0020200020200020 #x0020200820200020 #x0020200000002020 #x0020200800002020 #x0020200020002020 #x0020200820002020 #x0020200000202020 #x0020200800202020 #x0020200020202020 #x0020200820202020 #x2020200000000000 #x2020200800000000 #x2020200020000000 #x2020200820000000 #x2020200000200000 #x2020200800200000 #x2020200020200000 #x2020200820200000 #x2020200000002000 #x2020200800002000 #x2020200020002000 #x2020200820002000 #x2020200000202000 #x2020200800202000 #x2020200020202000 #x2020200820202000 #x2020200000000020 #x2020200800000020 #x2020200020000020 #x2020200820000020 #x2020200000200020 #x2020200800200020 #x2020200020200020 #x2020200820200020 #x2020200000002020 #x2020200800002020 #x2020200020002020 #x2020200820002020 #x2020200000202020 #x2020200800202020 #x2020200020202020 #x2020200820202020) #(#x0000000000000000 #x0000002000000000 #x0000000080000000 #x0000002080000000 #x0000000000800000 #x0000002000800000 #x0000000080800000 #x0000002080800000 #x0000000000008000 #x0000002000008000 #x0000000080008000 #x0000002080008000 #x0000000000808000 #x0000002000808000 #x0000000080808000 #x0000002080808000 #x0000000000000080 #x0000002000000080 #x0000000080000080 #x0000002080000080 #x0000000000800080 #x0000002000800080 #x0000000080800080 #x0000002080800080 #x0000000000008080 #x0000002000008080 #x0000000080008080 #x0000002080008080 #x0000000000808080 #x0000002000808080 #x0000000080808080 #x0000002080808080 #x8000000000000000 #x8000002000000000 #x8000000080000000 #x8000002080000000 #x8000000000800000 #x8000002000800000 #x8000000080800000 #x8000002080800000 #x8000000000008000 #x8000002000008000 #x8000000080008000 #x8000002080008000 #x8000000000808000 #x8000002000808000 #x8000000080808000 #x8000002080808000 #x8000000000000080 #x8000002000000080 #x8000000080000080 #x8000002080000080 #x8000000000800080 #x8000002000800080 #x8000000080800080 #x8000002080800080 #x8000000000008080 #x8000002000008080 #x8000000080008080 #x8000002080008080 #x8000000000808080 #x8000002000808080 #x8000000080808080 #x8000002080808080 #x0080000000000000 #x0080002000000000 #x0080000080000000 #x0080002080000000 #x0080000000800000 #x0080002000800000 #x0080000080800000 #x0080002080800000 #x0080000000008000 #x0080002000008000 #x0080000080008000 #x0080002080008000 #x0080000000808000 #x0080002000808000 #x0080000080808000 #x0080002080808000 #x0080000000000080 #x0080002000000080 #x0080000080000080 #x0080002080000080 #x0080000000800080 #x0080002000800080 #x0080000080800080 #x0080002080800080 #x0080000000008080 #x0080002000008080 #x0080000080008080 #x0080002080008080 #x0080000000808080 #x0080002000808080 #x0080000080808080 #x0080002080808080 #x8080000000000000 #x8080002000000000 #x8080000080000000 #x8080002080000000 #x8080000000800000 #x8080002000800000 #x8080000080800000 #x8080002080800000 #x8080000000008000 #x8080002000008000 #x8080000080008000 #x8080002080008000 #x8080000000808000 #x8080002000808000 #x8080000080808000 #x8080002080808000 #x8080000000000080 #x8080002000000080 #x8080000080000080 #x8080002080000080 #x8080000000800080 #x8080002000800080 #x8080000080800080 #x8080002080800080 #x8080000000008080 #x8080002000008080 #x8080000080008080 #x8080002080008080 #x8080000000808080 #x8080002000808080 #x8080000080808080 #x8080002080808080 #x0000800000000000 #x0000802000000000 #x0000800080000000 #x0000802080000000 #x0000800000800000 #x0000802000800000 #x0000800080800000 #x0000802080800000 #x0000800000008000 #x0000802000008000 #x0000800080008000 #x0000802080008000 #x0000800000808000 #x0000802000808000 #x0000800080808000 #x0000802080808000 #x0000800000000080 #x0000802000000080 #x0000800080000080 #x0000802080000080 #x0000800000800080 #x0000802000800080 #x0000800080800080 #x0000802080800080 #x0000800000008080 #x0000802000008080 #x0000800080008080 #x0000802080008080 #x0000800000808080 #x0000802000808080 #x0000800080808080 #x0000802080808080 #x8000800000000000 #x8000802000000000 #x8000800080000000 #x8000802080000000 #x8000800000800000 #x8000802000800000 #x8000800080800000 #x8000802080800000 #x8000800000008000 #x8000802000008000 #x8000800080008000 #x8000802080008000 #x8000800000808000 #x8000802000808000 #x8000800080808000 #x8000802080808000 #x8000800000000080 #x8000802000000080 #x8000800080000080 #x8000802080000080 #x8000800000800080 #x8000802000800080 #x8000800080800080 #x8000802080800080 #x8000800000008080 #x8000802000008080 #x8000800080008080 #x8000802080008080 #x8000800000808080 #x8000802000808080 #x8000800080808080 #x8000802080808080 #x0080800000000000 #x0080802000000000 #x0080800080000000 #x0080802080000000 #x0080800000800000 #x0080802000800000 #x0080800080800000 #x0080802080800000 #x0080800000008000 #x0080802000008000 #x0080800080008000 #x0080802080008000 #x0080800000808000 #x0080802000808000 #x0080800080808000 #x0080802080808000 #x0080800000000080 #x0080802000000080 #x0080800080000080 #x0080802080000080 #x0080800000800080 #x0080802000800080 #x0080800080800080 #x0080802080800080 #x0080800000008080 #x0080802000008080 #x0080800080008080 #x0080802080008080 #x0080800000808080 #x0080802000808080 #x0080800080808080 #x0080802080808080 #x8080800000000000 #x8080802000000000 #x8080800080000000 #x8080802080000000 #x8080800000800000 #x8080802000800000 #x8080800080800000 #x8080802080800000 #x8080800000008000 #x8080802000008000 #x8080800080008000 #x8080802080008000 #x8080800000808000 #x8080802000808000 #x8080800080808000 #x8080802080808000 #x8080800000000080 #x8080802000000080 #x8080800080000080 #x8080802080000080 #x8080800000800080 #x8080802000800080 #x8080800080800080 #x8080802080800080 #x8080800000008080 #x8080802000008080 #x8080800080008080 #x8080802080008080 #x8080800000808080 #x8080802000808080 #x8080800080808080 #x8080802080808080) #(#x0000000000000000 #x0000004000000000 #x0000000001000000 #x0000004001000000 #x0000000000010000 #x0000004000010000 #x0000000001010000 #x0000004001010000 #x0000000000000100 #x0000004000000100 #x0000000001000100 #x0000004001000100 #x0000000000010100 #x0000004000010100 #x0000000001010100 #x0000004001010100 #x0000000000000001 #x0000004000000001 #x0000000001000001 #x0000004001000001 #x0000000000010001 #x0000004000010001 #x0000000001010001 #x0000004001010001 #x0000000000000101 #x0000004000000101 #x0000000001000101 #x0000004001000101 #x0000000000010101 #x0000004000010101 #x0000000001010101 #x0000004001010101 #x0100000000000000 #x0100004000000000 #x0100000001000000 #x0100004001000000 #x0100000000010000 #x0100004000010000 #x0100000001010000 #x0100004001010000 #x0100000000000100 #x0100004000000100 #x0100000001000100 #x0100004001000100 #x0100000000010100 #x0100004000010100 #x0100000001010100 #x0100004001010100 #x0100000000000001 #x0100004000000001 #x0100000001000001 #x0100004001000001 #x0100000000010001 #x0100004000010001 #x0100000001010001 #x0100004001010001 #x0100000000000101 #x0100004000000101 #x0100000001000101 #x0100004001000101 #x0100000000010101 #x0100004000010101 #x0100000001010101 #x0100004001010101 #x0001000000000000 #x0001004000000000 #x0001000001000000 #x0001004001000000 #x0001000000010000 #x0001004000010000 #x0001000001010000 #x0001004001010000 #x0001000000000100 #x0001004000000100 #x0001000001000100 #x0001004001000100 #x0001000000010100 #x0001004000010100 #x0001000001010100 #x0001004001010100 #x0001000000000001 #x0001004000000001 #x0001000001000001 #x0001004001000001 #x0001000000010001 #x0001004000010001 #x0001000001010001 #x0001004001010001 #x0001000000000101 #x0001004000000101 #x0001000001000101 #x0001004001000101 #x0001000000010101 #x0001004000010101 #x0001000001010101 #x0001004001010101 #x0101000000000000 #x0101004000000000 #x0101000001000000 #x0101004001000000 #x0101000000010000 #x0101004000010000 #x0101000001010000 #x0101004001010000 #x0101000000000100 #x0101004000000100 #x0101000001000100 #x0101004001000100 #x0101000000010100 #x0101004000010100 #x0101000001010100 #x0101004001010100 #x0101000000000001 #x0101004000000001 #x0101000001000001 #x0101004001000001 #x0101000000010001 #x0101004000010001 #x0101000001010001 #x0101004001010001 #x0101000000000101 #x0101004000000101 #x0101000001000101 #x0101004001000101 #x0101000000010101 #x0101004000010101 #x0101000001010101 #x0101004001010101 #x0000010000000000 #x0000014000000000 #x0000010001000000 #x0000014001000000 #x0000010000010000 #x0000014000010000 #x0000010001010000 #x0000014001010000 #x0000010000000100 #x0000014000000100 #x0000010001000100 #x0000014001000100 #x0000010000010100 #x0000014000010100 #x0000010001010100 #x0000014001010100 #x0000010000000001 #x0000014000000001 #x0000010001000001 #x0000014001000001 #x0000010000010001 #x0000014000010001 #x0000010001010001 #x0000014001010001 #x0000010000000101 #x0000014000000101 #x0000010001000101 #x0000014001000101 #x0000010000010101 #x0000014000010101 #x0000010001010101 #x0000014001010101 #x0100010000000000 #x0100014000000000 #x0100010001000000 #x0100014001000000 #x0100010000010000 #x0100014000010000 #x0100010001010000 #x0100014001010000 #x0100010000000100 #x0100014000000100 #x0100010001000100 #x0100014001000100 #x0100010000010100 #x0100014000010100 #x0100010001010100 #x0100014001010100 #x0100010000000001 #x0100014000000001 #x0100010001000001 #x0100014001000001 #x0100010000010001 #x0100014000010001 #x0100010001010001 #x0100014001010001 #x0100010000000101 #x0100014000000101 #x0100010001000101 #x0100014001000101 #x0100010000010101 #x0100014000010101 #x0100010001010101 #x0100014001010101 #x0001010000000000 #x0001014000000000 #x0001010001000000 #x0001014001000000 #x0001010000010000 #x0001014000010000 #x0001010001010000 #x0001014001010000 #x0001010000000100 #x0001014000000100 #x0001010001000100 #x0001014001000100 #x0001010000010100 #x0001014000010100 #x0001010001010100 #x0001014001010100 #x0001010000000001 #x0001014000000001 #x0001010001000001 #x0001014001000001 #x0001010000010001 #x0001014000010001 #x0001010001010001 #x0001014001010001 #x0001010000000101 #x0001014000000101 #x0001010001000101 #x0001014001000101 #x0001010000010101 #x0001014000010101 #x0001010001010101 #x0001014001010101 #x0101010000000000 #x0101014000000000 #x0101010001000000 #x0101014001000000 #x0101010000010000 #x0101014000010000 #x0101010001010000 #x0101014001010000 #x0101010000000100 #x0101014000000100 #x0101010001000100 #x0101014001000100 #x0101010000010100 #x0101014000010100 #x0101010001010100 #x0101014001010100 #x0101010000000001 #x0101014000000001 #x0101010001000001 #x0101014001000001 #x0101010000010001 #x0101014000010001 #x0101010001010001 #x0101014001010001 #x0101010000000101 #x0101014000000101 #x0101010001000101 #x0101014001000101 #x0101010000010101 #x0101014000010101 #x0101010001010101 #x0101014001010101) #(#x0000000000000000 #x0000000100000000 #x0000000004000000 #x0000000104000000 #x0000000000040000 #x0000000100040000 #x0000000004040000 #x0000000104040000 #x0000000000000400 #x0000000100000400 #x0000000004000400 #x0000000104000400 #x0000000000040400 #x0000000100040400 #x0000000004040400 #x0000000104040400 #x0000000000000004 #x0000000100000004 #x0000000004000004 #x0000000104000004 #x0000000000040004 #x0000000100040004 #x0000000004040004 #x0000000104040004 #x0000000000000404 #x0000000100000404 #x0000000004000404 #x0000000104000404 #x0000000000040404 #x0000000100040404 #x0000000004040404 #x0000000104040404 #x0400000000000000 #x0400000100000000 #x0400000004000000 #x0400000104000000 #x0400000000040000 #x0400000100040000 #x0400000004040000 #x0400000104040000 #x0400000000000400 #x0400000100000400 #x0400000004000400 #x0400000104000400 #x0400000000040400 #x0400000100040400 #x0400000004040400 #x0400000104040400 #x0400000000000004 #x0400000100000004 #x0400000004000004 #x0400000104000004 #x0400000000040004 #x0400000100040004 #x0400000004040004 #x0400000104040004 #x0400000000000404 #x0400000100000404 #x0400000004000404 #x0400000104000404 #x0400000000040404 #x0400000100040404 #x0400000004040404 #x0400000104040404 #x0004000000000000 #x0004000100000000 #x0004000004000000 #x0004000104000000 #x0004000000040000 #x0004000100040000 #x0004000004040000 #x0004000104040000 #x0004000000000400 #x0004000100000400 #x0004000004000400 #x0004000104000400 #x0004000000040400 #x0004000100040400 #x0004000004040400 #x0004000104040400 #x0004000000000004 #x0004000100000004 #x0004000004000004 #x0004000104000004 #x0004000000040004 #x0004000100040004 #x0004000004040004 #x0004000104040004 #x0004000000000404 #x0004000100000404 #x0004000004000404 #x0004000104000404 #x0004000000040404 #x0004000100040404 #x0004000004040404 #x0004000104040404 #x0404000000000000 #x0404000100000000 #x0404000004000000 #x0404000104000000 #x0404000000040000 #x0404000100040000 #x0404000004040000 #x0404000104040000 #x0404000000000400 #x0404000100000400 #x0404000004000400 #x0404000104000400 #x0404000000040400 #x0404000100040400 #x0404000004040400 #x0404000104040400 #x0404000000000004 #x0404000100000004 #x0404000004000004 #x0404000104000004 #x0404000000040004 #x0404000100040004 #x0404000004040004 #x0404000104040004 #x0404000000000404 #x0404000100000404 #x0404000004000404 #x0404000104000404 #x0404000000040404 #x0404000100040404 #x0404000004040404 #x0404000104040404 #x0000040000000000 #x0000040100000000 #x0000040004000000 #x0000040104000000 #x0000040000040000 #x0000040100040000 #x0000040004040000 #x0000040104040000 #x0000040000000400 #x0000040100000400 #x0000040004000400 #x0000040104000400 #x0000040000040400 #x0000040100040400 #x0000040004040400 #x0000040104040400 #x0000040000000004 #x0000040100000004 #x0000040004000004 #x0000040104000004 #x0000040000040004 #x0000040100040004 #x0000040004040004 #x0000040104040004 #x0000040000000404 #x0000040100000404 #x0000040004000404 #x0000040104000404 #x0000040000040404 #x0000040100040404 #x0000040004040404 #x0000040104040404 #x0400040000000000 #x0400040100000000 #x0400040004000000 #x0400040104000000 #x0400040000040000 #x0400040100040000 #x0400040004040000 #x0400040104040000 #x0400040000000400 #x0400040100000400 #x0400040004000400 #x0400040104000400 #x0400040000040400 #x0400040100040400 #x0400040004040400 #x0400040104040400 #x0400040000000004 #x0400040100000004 #x0400040004000004 #x0400040104000004 #x0400040000040004 #x0400040100040004 #x0400040004040004 #x0400040104040004 #x0400040000000404 #x0400040100000404 #x0400040004000404 #x0400040104000404 #x0400040000040404 #x0400040100040404 #x0400040004040404 #x0400040104040404 #x0004040000000000 #x0004040100000000 #x0004040004000000 #x0004040104000000 #x0004040000040000 #x0004040100040000 #x0004040004040000 #x0004040104040000 #x0004040000000400 #x0004040100000400 #x0004040004000400 #x0004040104000400 #x0004040000040400 #x0004040100040400 #x0004040004040400 #x0004040104040400 #x0004040000000004 #x0004040100000004 #x0004040004000004 #x0004040104000004 #x0004040000040004 #x0004040100040004 #x0004040004040004 #x0004040104040004 #x0004040000000404 #x0004040100000404 #x0004040004000404 #x0004040104000404 #x0004040000040404 #x0004040100040404 #x0004040004040404 #x0004040104040404 #x0404040000000000 #x0404040100000000 #x0404040004000000 #x0404040104000000 #x0404040000040000 #x0404040100040000 #x0404040004040000 #x0404040104040000 #x0404040000000400 #x0404040100000400 #x0404040004000400 #x0404040104000400 #x0404040000040400 #x0404040100040400 #x0404040004040400 #x0404040104040400 #x0404040000000004 #x0404040100000004 #x0404040004000004 #x0404040104000004 #x0404040000040004 #x0404040100040004 #x0404040004040004 #x0404040104040004 #x0404040000000404 #x0404040100000404 #x0404040004000404 #x0404040104000404 #x0404040000040404 #x0404040100040404 #x0404040004040404 #x0404040104040404) #(#x0000000000000000 #x0000000400000000 #x0000000010000000 #x0000000410000000 #x0000000000100000 #x0000000400100000 #x0000000010100000 #x0000000410100000 #x0000000000001000 #x0000000400001000 #x0000000010001000 #x0000000410001000 #x0000000000101000 #x0000000400101000 #x0000000010101000 #x0000000410101000 #x0000000000000010 #x0000000400000010 #x0000000010000010 #x0000000410000010 #x0000000000100010 #x0000000400100010 #x0000000010100010 #x0000000410100010 #x0000000000001010 #x0000000400001010 #x0000000010001010 #x0000000410001010 #x0000000000101010 #x0000000400101010 #x0000000010101010 #x0000000410101010 #x1000000000000000 #x1000000400000000 #x1000000010000000 #x1000000410000000 #x1000000000100000 #x1000000400100000 #x1000000010100000 #x1000000410100000 #x1000000000001000 #x1000000400001000 #x1000000010001000 #x1000000410001000 #x1000000000101000 #x1000000400101000 #x1000000010101000 #x1000000410101000 #x1000000000000010 #x1000000400000010 #x1000000010000010 #x1000000410000010 #x1000000000100010 #x1000000400100010 #x1000000010100010 #x1000000410100010 #x1000000000001010 #x1000000400001010 #x1000000010001010 #x1000000410001010 #x1000000000101010 #x1000000400101010 #x1000000010101010 #x1000000410101010 #x0010000000000000 #x0010000400000000 #x0010000010000000 #x0010000410000000 #x0010000000100000 #x0010000400100000 #x0010000010100000 #x0010000410100000 #x0010000000001000 #x0010000400001000 #x0010000010001000 #x0010000410001000 #x0010000000101000 #x0010000400101000 #x0010000010101000 #x0010000410101000 #x0010000000000010 #x0010000400000010 #x0010000010000010 #x0010000410000010 #x0010000000100010 #x0010000400100010 #x0010000010100010 #x0010000410100010 #x0010000000001010 #x0010000400001010 #x0010000010001010 #x0010000410001010 #x0010000000101010 #x0010000400101010 #x0010000010101010 #x0010000410101010 #x1010000000000000 #x1010000400000000 #x1010000010000000 #x1010000410000000 #x1010000000100000 #x1010000400100000 #x1010000010100000 #x1010000410100000 #x1010000000001000 #x1010000400001000 #x1010000010001000 #x1010000410001000 #x1010000000101000 #x1010000400101000 #x1010000010101000 #x1010000410101000 #x1010000000000010 #x1010000400000010 #x1010000010000010 #x1010000410000010 #x1010000000100010 #x1010000400100010 #x1010000010100010 #x1010000410100010 #x1010000000001010 #x1010000400001010 #x1010000010001010 #x1010000410001010 #x1010000000101010 #x1010000400101010 #x1010000010101010 #x1010000410101010 #x0000100000000000 #x0000100400000000 #x0000100010000000 #x0000100410000000 #x0000100000100000 #x0000100400100000 #x0000100010100000 #x0000100410100000 #x0000100000001000 #x0000100400001000 #x0000100010001000 #x0000100410001000 #x0000100000101000 #x0000100400101000 #x0000100010101000 #x0000100410101000 #x0000100000000010 #x0000100400000010 #x0000100010000010 #x0000100410000010 #x0000100000100010 #x0000100400100010 #x0000100010100010 #x0000100410100010 #x0000100000001010 #x0000100400001010 #x0000100010001010 #x0000100410001010 #x0000100000101010 #x0000100400101010 #x0000100010101010 #x0000100410101010 #x1000100000000000 #x1000100400000000 #x1000100010000000 #x1000100410000000 #x1000100000100000 #x1000100400100000 #x1000100010100000 #x1000100410100000 #x1000100000001000 #x1000100400001000 #x1000100010001000 #x1000100410001000 #x1000100000101000 #x1000100400101000 #x1000100010101000 #x1000100410101000 #x1000100000000010 #x1000100400000010 #x1000100010000010 #x1000100410000010 #x1000100000100010 #x1000100400100010 #x1000100010100010 #x1000100410100010 #x1000100000001010 #x1000100400001010 #x1000100010001010 #x1000100410001010 #x1000100000101010 #x1000100400101010 #x1000100010101010 #x1000100410101010 #x0010100000000000 #x0010100400000000 #x0010100010000000 #x0010100410000000 #x0010100000100000 #x0010100400100000 #x0010100010100000 #x0010100410100000 #x0010100000001000 #x0010100400001000 #x0010100010001000 #x0010100410001000 #x0010100000101000 #x0010100400101000 #x0010100010101000 #x0010100410101000 #x0010100000000010 #x0010100400000010 #x0010100010000010 #x0010100410000010 #x0010100000100010 #x0010100400100010 #x0010100010100010 #x0010100410100010 #x0010100000001010 #x0010100400001010 #x0010100010001010 #x0010100410001010 #x0010100000101010 #x0010100400101010 #x0010100010101010 #x0010100410101010 #x1010100000000000 #x1010100400000000 #x1010100010000000 #x1010100410000000 #x1010100000100000 #x1010100400100000 #x1010100010100000 #x1010100410100000 #x1010100000001000 #x1010100400001000 #x1010100010001000 #x1010100410001000 #x1010100000101000 #x1010100400101000 #x1010100010101000 #x1010100410101000 #x1010100000000010 #x1010100400000010 #x1010100010000010 #x1010100410000010 #x1010100000100010 #x1010100400100010 #x1010100010100010 #x1010100410100010 #x1010100000001010 #x1010100400001010 #x1010100010001010 #x1010100410001010 #x1010100000101010 #x1010100400101010 #x1010100010101010 #x1010100410101010) #(#x0000000000000000 #x0000001000000000 #x0000000040000000 #x0000001040000000 #x0000000000400000 #x0000001000400000 #x0000000040400000 #x0000001040400000 #x0000000000004000 #x0000001000004000 #x0000000040004000 #x0000001040004000 #x0000000000404000 #x0000001000404000 #x0000000040404000 #x0000001040404000 #x0000000000000040 #x0000001000000040 #x0000000040000040 #x0000001040000040 #x0000000000400040 #x0000001000400040 #x0000000040400040 #x0000001040400040 #x0000000000004040 #x0000001000004040 #x0000000040004040 #x0000001040004040 #x0000000000404040 #x0000001000404040 #x0000000040404040 #x0000001040404040 #x4000000000000000 #x4000001000000000 #x4000000040000000 #x4000001040000000 #x4000000000400000 #x4000001000400000 #x4000000040400000 #x4000001040400000 #x4000000000004000 #x4000001000004000 #x4000000040004000 #x4000001040004000 #x4000000000404000 #x4000001000404000 #x4000000040404000 #x4000001040404000 #x4000000000000040 #x4000001000000040 #x4000000040000040 #x4000001040000040 #x4000000000400040 #x4000001000400040 #x4000000040400040 #x4000001040400040 #x4000000000004040 #x4000001000004040 #x4000000040004040 #x4000001040004040 #x4000000000404040 #x4000001000404040 #x4000000040404040 #x4000001040404040 #x0040000000000000 #x0040001000000000 #x0040000040000000 #x0040001040000000 #x0040000000400000 #x0040001000400000 #x0040000040400000 #x0040001040400000 #x0040000000004000 #x0040001000004000 #x0040000040004000 #x0040001040004000 #x0040000000404000 #x0040001000404000 #x0040000040404000 #x0040001040404000 #x0040000000000040 #x0040001000000040 #x0040000040000040 #x0040001040000040 #x0040000000400040 #x0040001000400040 #x0040000040400040 #x0040001040400040 #x0040000000004040 #x0040001000004040 #x0040000040004040 #x0040001040004040 #x0040000000404040 #x0040001000404040 #x0040000040404040 #x0040001040404040 #x4040000000000000 #x4040001000000000 #x4040000040000000 #x4040001040000000 #x4040000000400000 #x4040001000400000 #x4040000040400000 #x4040001040400000 #x4040000000004000 #x4040001000004000 #x4040000040004000 #x4040001040004000 #x4040000000404000 #x4040001000404000 #x4040000040404000 #x4040001040404000 #x4040000000000040 #x4040001000000040 #x4040000040000040 #x4040001040000040 #x4040000000400040 #x4040001000400040 #x4040000040400040 #x4040001040400040 #x4040000000004040 #x4040001000004040 #x4040000040004040 #x4040001040004040 #x4040000000404040 #x4040001000404040 #x4040000040404040 #x4040001040404040 #x0000400000000000 #x0000401000000000 #x0000400040000000 #x0000401040000000 #x0000400000400000 #x0000401000400000 #x0000400040400000 #x0000401040400000 #x0000400000004000 #x0000401000004000 #x0000400040004000 #x0000401040004000 #x0000400000404000 #x0000401000404000 #x0000400040404000 #x0000401040404000 #x0000400000000040 #x0000401000000040 #x0000400040000040 #x0000401040000040 #x0000400000400040 #x0000401000400040 #x0000400040400040 #x0000401040400040 #x0000400000004040 #x0000401000004040 #x0000400040004040 #x0000401040004040 #x0000400000404040 #x0000401000404040 #x0000400040404040 #x0000401040404040 #x4000400000000000 #x4000401000000000 #x4000400040000000 #x4000401040000000 #x4000400000400000 #x4000401000400000 #x4000400040400000 #x4000401040400000 #x4000400000004000 #x4000401000004000 #x4000400040004000 #x4000401040004000 #x4000400000404000 #x4000401000404000 #x4000400040404000 #x4000401040404000 #x4000400000000040 #x4000401000000040 #x4000400040000040 #x4000401040000040 #x4000400000400040 #x4000401000400040 #x4000400040400040 #x4000401040400040 #x4000400000004040 #x4000401000004040 #x4000400040004040 #x4000401040004040 #x4000400000404040 #x4000401000404040 #x4000400040404040 #x4000401040404040 #x0040400000000000 #x0040401000000000 #x0040400040000000 #x0040401040000000 #x0040400000400000 #x0040401000400000 #x0040400040400000 #x0040401040400000 #x0040400000004000 #x0040401000004000 #x0040400040004000 #x0040401040004000 #x0040400000404000 #x0040401000404000 #x0040400040404000 #x0040401040404000 #x0040400000000040 #x0040401000000040 #x0040400040000040 #x0040401040000040 #x0040400000400040 #x0040401000400040 #x0040400040400040 #x0040401040400040 #x0040400000004040 #x0040401000004040 #x0040400040004040 #x0040401040004040 #x0040400000404040 #x0040401000404040 #x0040400040404040 #x0040401040404040 #x4040400000000000 #x4040401000000000 #x4040400040000000 #x4040401040000000 #x4040400000400000 #x4040401000400000 #x4040400040400000 #x4040401040400000 #x4040400000004000 #x4040401000004000 #x4040400040004000 #x4040401040004000 #x4040400000404000 #x4040401000404000 #x4040400040404000 #x4040401040404000 #x4040400000000040 #x4040401000000040 #x4040400040000040 #x4040401040000040 #x4040400000400040 #x4040401000400040 #x4040400040400040 #x4040401040400040 #x4040400000004040 #x4040401000004040 #x4040400040004040 #x4040401040004040 #x4040400000404040 #x4040401000404040 #x4040400040404040 #x4040401040404040) ))
false
49319b2d43e819a06e1e9bca8cc02bbb1aae74c9
6b288a71553cf3d8701fe7179701d100c656a53c
/s/patch.ss
5bf1f9a39b7275d66a2c25215aec98df80dfa426
[ "Apache-2.0" ]
permissive
cisco/ChezScheme
03e2edb655f8f686630f31ba2574f47f29853b6f
c048ad8423791de4bf650fca00519d5c2059d66e
refs/heads/main
2023-08-26T16:11:15.338552
2023-08-25T14:17:54
2023-08-25T14:17:54
56,263,501
7,763
1,410
Apache-2.0
2023-08-28T22:45:52
2016-04-14T19:10:25
Scheme
UTF-8
Scheme
false
false
1,256
ss
patch.ss
;;; patch.ss ;;; Copyright 1984-2017 Cisco Systems, Inc. ;;; ;;; Licensed under the Apache License, Version 2.0 (the "License"); ;;; you may not use this file except in compliance with the License. ;;; You may obtain a copy of the License at ;;; ;;; http://www.apache.org/licenses/LICENSE-2.0 ;;; ;;; Unless required by applicable law or agreed to in writing, software ;;; distributed under the License is distributed on an "AS IS" BASIS, ;;; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ;;; See the License for the specific language governing permissions and ;;; limitations under the License. (printf "loading ~s cross compiler~%" (constant machine-type-name)) ; (current-expand (lambda args (apply sc-expand args))) ; (current-eval (lambda args (apply interpret args))) (when-feature pthreads (meta-cond [(not (threaded?)) ; we must be cross-compiling from nonthreaded to threaded version ; handle thread parameter creation (define-syntax with-mutex (syntax-rules () [(_ mexp e0 e1 ...) (begin e0 e1 ...)])) (set! make-thread-parameter make-parameter) (set! mutex-acquire (lambda (m) (void))) (set! mutex-release (lambda (m) (void))) (set! $tc-mutex (void))]))
true
840ad0380068187a9837127180969d86cc5e9c96
d3e9eecbf7fa7e015ab8b9c357882763bf6d6556
/solutions/exercises/2.53-2.72.ss
1d94024113088dc93b6c7fea74939453b3b2c203
[]
no_license
yangchenyun/learning-sicp
37d43f18836055274f78755ff93eb20fba63d383
99a19a06eddc282e0eb364536e297f27c32a9145
refs/heads/master
2021-01-19T02:15:15.634140
2017-02-13T22:26:58
2017-02-13T22:26:58
5,344,488
17
3
null
null
null
null
UTF-8
Scheme
false
false
24,215
ss
2.53-2.72.ss
#lang sicp (define (make-set l) l) (define (memq? item x) (cond ((null? x) #f) ((eq? item (car x)) x) (else (memq item (cdr x))))) (define (repeated f n) (cond ((= n 0) identity) ((= n 1) f) (else (compose f (repeated f (- n 1)))))) ;; Exercise 2.53 (list 'a 'b 'c) ;; (a b c) (list (list 'george)) ;; ((george)) (cdr '((x1 x2) (y1 y2))) ;; ((y1 y2)) (cadr '((x1 x2) (y1 y2))) ;; (y1 y2) (pair? (car '(a short list))) ;; #f (memq 'red '((red shoes) (blue socks))) ;; #f (memq 'red '(red shoes blue socks)) ;; (red shoes blue socks) ;; Exercise 2.54 (define (equal? l1 l2) (cond ((and (symbol? l1) (symbol? l2)) (eq? l1 l2)) ((and (number? l1) (number? l2)) (= l1 l2)) ((and (null? l1) (null? l2)) #t) ((and (pair? l1) (pair? l2)) (and (equal? (car l1) (car l2)) (equal? (cdr l1) (cdr l2)))) (else #f))) (equal? '(this is a list) '(this is a list)) (equal? '(this is a list) '(this (is a) list)) ;; Exercise 2.55 (car ''abracadabra) ;; the interpreter expands the expression as (car '(quote abracadabra)) ;; and apply `car' onto it produce the symbol quote 'quote ;; Exercise 2.56 (define (deriv exp var) (define (variable? x) (symbol? x)) (define (same-variable? v1 v2) (and (variable? v1) (variable? v2) (eq? v1 v2))) (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 base expo) (cond ((=number? expo 1) base) ((=number? expo 0) 1) (else (list '** base expo)))) (define (sum? x) (and (pair? x) (eq? (car x) '+))) (define (addend s) (cadr s)) (define (augend s) (caddr s)) (define (product? x) (and (pair? x) (eq? (car x) '*))) (define (multiplier s) (cadr s)) (define (multiplicand s) (caddr s)) (define (exponentiation? x) (and (pair? x) (eq? (car x) '**))) (define (base s) (cadr s)) (define (exponent s) (caddr s)) (cond ((number? exp) 0) ((variable? exp) (if (same-variable? exp var) 1 0)) ((sum? exp) (make-sum (deriv (addend exp) var) (deriv (augend exp) var))) ((product? exp) (make-sum (make-product (multiplier exp) (deriv (multiplicand exp) var)) (make-product (deriv (multiplier exp) var) (multiplicand exp)))) ((exponentiation? exp) (make-product (exponent exp) (make-product (make-exponentiation (base exp) (make-sum (exponent exp) -1)) (deriv (base exp) var)))) (else (error "unknown expression type: DERIV" exp)))) (deriv '(** x 0) 'x) (deriv '(** x 1) 'x) (deriv '(** x 2) 'x) (deriv '(** (+ x 2) 3) 'x) (deriv '(** (+ (** x 2) 2) 3) 'x) (deriv '(** x n) 'x) ;; Exercise 2.57 (define (deriv exp var) (define (variable? x) (symbol? x)) (define (same-variable? v1 v2) (and (variable? v1) (variable? v2) (eq? v1 v2))) (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 (sum? x) (and (pair? x) (eq? (car x) '+))) (define (addend s) (cadr s)) (define (augend s) (if (= 2 (length (cdr s))) (caddr s) (cons '+ (cddr s)))) (define (product? x) (and (pair? x) (eq? (car x) '*))) (define (multiplier s) (cadr s)) (define (multiplicand s) (if (= 2 (length (cdr s))) (caddr s) (cons '* (cddr s)))) (cond ((number? exp) 0) ((variable? exp) (if (same-variable? exp var) 1 0)) ((sum? exp) (make-sum (deriv (addend exp) var) (deriv (augend exp) var))) ((product? exp) (make-sum (make-product (multiplier exp) (deriv (multiplicand exp) var)) (make-product (deriv (multiplier exp) var) (multiplicand exp)))) (else (error "unknown expression type: DERIV" exp)))) (deriv '(* x y (+ x 3)) 'x) (deriv '(* (* x y) (+ x 3)) 'x) ;; Exercise 2.58 ;; a. ;; simplified conditions: ;; 1. +, * is binary operation ;; 2. expression are fully parenthesized (define (deriv exp var) (define (variable? x) (symbol? x)) (define (same-variable? v1 v2) (and (variable? v1) (variable? v2) (eq? v1 v2))) (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 (sum? x) (and (pair? x) (eq? (cadr x) '+))) (define (addend s) (car s)) (define (augend s) (caddr s)) (define (product? x) (and (pair? x) (eq? (cadr x) '*))) (define (multiplier s) (car s)) (define (multiplicand s) (caddr s)) (cond ((number? exp) 0) ((variable? exp) (if (same-variable? exp var) 1 0)) ((sum? exp) (make-sum (deriv (addend exp) var) (deriv (augend exp) var))) ((product? exp) (make-sum (make-product (multiplier exp) (deriv (multiplicand exp) var)) (make-product (deriv (multiplier exp) var) (multiplicand exp)))) (else (error "unknown expression type: DERIV" exp)))) (deriv '(x + (3 * (x + (y + 2)))) 'x) ;; b. ;; 1. unnecessary parentheses are dropped ;; 2. multiplication is done before addition (define (deriv exp var) ;;; utility methods (define (prefix item x) (cond ((null? x) #f) ((eq? item (car x)) '()) (else (let ((rest (prefix item (cdr x)))) (if rest (cons (car x) rest) #f))))) (define (suffix item x) (cond ((null? x) #f) ((eq? item (car x)) (cdr x)) (else (suffix item (cdr x))))) (define (singleton? list) (null? (cdr list))) (define (min-op exp) (cond ((memq? '+ exp) '+) ((memq? '* exp) '*) ((memq? '** exp) '**) (else (error "unknown operator for expression" exp)))) ;; domain-related methods (define (variable? x) (symbol? x)) (define (same-variable? v1 v2) (and (variable? v1) (variable? v2) (eq? v1 v2))) (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 base expo) (cond ((=number? expo 1) base) ((=number? expo 0) 1) (else (list base '** expo)))) (define (sum? x) (and (pair? x) (eq? (min-op x) '+))) (define (addend s) (let ((a (prefix '+ s))) (if (singleton? a) (car a) a))) (define (augend s) (let ((a (suffix '+ s))) (if (singleton? a) (car a) a))) (define (product? x) (and (pair? x) (eq? (min-op x) '*))) (define (multiplier s) (let ((a (prefix '* s))) (if (singleton? a) (car a) a))) (define (multiplicand s) (let ((a (suffix '* s))) (if (singleton? a) (car a) a))) (define (exponentiation? x) (and (pair? x) (eq? (min-op x) '**))) (define (base s) (let ((a (prefix '** s))) (if (singleton? a) (car a) a))) (define (exponent s) (let ((a (suffix '** s))) (if (singleton? a) (car a) a))) (cond ((number? exp) 0) ((variable? exp) (if (same-variable? exp var) 1 0)) ((sum? exp) (make-sum (deriv (addend exp) var) (deriv (augend exp) var))) ((product? exp) (make-sum (make-product (multiplier exp) (deriv (multiplicand exp) var)) (make-product (deriv (multiplier exp) var) (multiplicand exp)))) ((exponentiation? exp) (make-product (exponent exp) (make-product (make-exponentiation (base exp) (make-sum (exponent exp) -1)) (deriv (base exp) var)))) (else (error "unknown expression type: DERIV" exp)))) (deriv '(x + 3 * (x + y + 2)) 'x) (deriv '(x + 3 * (x + x + 2)) 'x) (deriv '(x + 3 * x + x + 2) 'x) (deriv '(3 * x + 10 * x + 2 * (3 * x)) 'x) (deriv '(x * y * (x + 3)) 'x) (deriv '(x ** y * (x + 3)) 'x) ;; Exercise 2.59 (define (union-set s1 s2) (cond ((null? s1) s2) ((element-of-set? (car s1) s2) (union-set (cdr s1) s2)) (else (cons (car s1) (union-set (cdr s1) s2))))) ;; Exercise 2.60 ;; Represent set as list with duplicate elements ;; O(n) (define (element-of-set? x set) (cond ((null? set) #f) ((equal? (car set) x) #t) (else (element-of-set? x (cdr set))))) ;; as duplicates are allowed, just cons the element to the set, O(1) (define (adjoin-set x set) (cons x set)) ;; perform the direct append O(1) (define (union-set s1 s2) (append s1 s2)) ;; perform O(n^2) (define (intersection-set s1 s2) (cond ((or (null? s1) (null? s2)) '()) ((element-of-set? (car s1) s2) (cons (car s1) (intersection-set (cdr s1) s2))) (else (intersection-set (cdr s1) s2)))) ;; in application where adjoin-set and union-set is mostly used, ;; this representation is more efficient (let ((s (make-set '(1 2 3 4)))) (map (lambda (x) (element-of-set? x (adjoin-set x s))) '(2 5 a))) (let ((s (make-set '(1 2 3 4))) (t (make-set '(a b c d (1))))) (map (lambda (x) (equal? (element-of-set? x (union-set t s)) (or (element-of-set? x s) (element-of-set? x t)))) '(2 a '() (1)))) (map (lambda (x) (element-of-set? x '())) '(2 a '())) ;; Exercise 2.61 ;; O(n) (define (adjoin-set el set) (cond ((null? set) (list el)) ((= el (car set)) set) ((< el (car set)) (cons el set)) ((> el (car set)) (cons (car set) (adjoin-set el (cdr set)))))) ;; Exercise 2.62 (define (union-set s1 s2) (cond ((null? s1) s2) ((null? s2) s1) (else (let ((x1 (car s1)) (x2 (car s2))) (cond ((= x1 x2) (cons x1 (union-set (cdr s1) (cdr s2)))) ((< x1 x2) (cons x1 (union-set (cdr s1) s2))) ((> x1 x2) (cons x2 (union-set s1 (cdr s2))))))))) (union-set '(1 2 5 8) '(2 4 8)) ;; Exercise 2.63 (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 (tree->list-1 tree) (if (null? tree) '() (append (tree->list-1 (left-branch tree)) (cons (entry tree) (tree->list-1 (right-branch tree)))))) (define (tree->list-2 tree) (define (copy-to-list tree result-list) (if (null? tree) result-list (copy-to-list (left-branch tree) (cons (entry tree) (copy-to-list (right-branch tree) result-list))))) (copy-to-list tree '())) ;; a. ;; the produces the same result for every tree ;; the procedure they perform is identical: ;; 1. turn the right branch into list ;; 2. cons the entry to the right list ;; 3. turn the left branch into list and append to the above list ;; ORIGINAL ANSWER, failed to consider the `cons' and `append' complexity ;; b. ;; tree->list-1 will be applied to every node of the tree ;; including the empty subtree for all leaves ;; to convert a balanced n elements tree, ;; for a balanced tree, the depth will be log(n) + 1 ;; so the time complexity is O(2^log(n)) and is O(2n) ;; tree->list-2 will be applied to every node of the tree as well ;; to convert a balanced n elements tree, ;; so tree->list-2 is more efficient (define (make-balanced-tree n) (let* ((midpoint (ceiling (/ n 2))) (left (if (even? n) (- (- n 1) midpoint) (- n midpoint))) (right (- n midpoint))) (cond ((= n 0) '()) ((= n 1) (make-tree midpoint '() '())) (else (make-tree midpoint (make-balanced-tree left) (make-balanced-tree right) ))))) (time (begin (tree->list-2 (make-balanced-tree 1000000)) #t)) (time (begin (tree->list-1 (make-balanced-tree 1000000)) #t)) ;; CORRECT ANSWER, consider the complexity of cons and append ;; for tree->list-1, there will be 1 `append' and 1 `cons' for each node ;; cons is O(1), append is O(n), so the complexity if O(n^2) ;; for tree->list-2, there will be 1 `cons' for each node, ;; cons is O(1), so the complexity is O(n) ;; Exercise 2.64 (define (list->tree elements) (car (partial-tree elements (length elements)))) (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)))))))) ;; a. ;; partial-tree builds a balanced tree from left to right ;; it first builds the left tree recursively by: ;; 1. calculates the left-tree size with `quotient' ;; 2. passed in the elements to be used. ;; then it fetches the current entry by: ;; 1. `car' on the rest elements ;; later, it builds the right subtree by: ;; 1. calculates the right-tree size, by n - 1 - left-size ;; 2. passed in the remaining elements from above ;; finally, it put the tree part together with `make-tree' ;; and builds a list with the tree and remaining elements (partial-tree '(1 3 5 7 9 11) 6) ;; left part is built by (partial-tree '(1 3 5 7 9 11) 2) ;; entry is (car '(5 7 9 11)) ;; right part is built by (partial-tree (cdr '(5 7 9 11)) 3) ;; b. ;; every step will cut the size of problem in half ;; and each step is a tree recursion ;; so the order of growth is 2^log(n) = n ;; Exercise 2.65 ;; using procedures from Exercises 2.62 (define (union-list-set s1 s2) (cond ((null? s1) s2) ((null? s2) s1) (else (let ((x1 (car s1)) (x2 (car s2))) (cond ((= x1 x2) (cons x1 (union-list-set (cdr s1) (cdr s2)))) ((< x1 x2) (cons x1 (union-list-set (cdr s1) s2))) ((> x1 x2) (cons x2 (union-list-set s1 (cdr s2))))))))) ;; tree->list-2, list->tree and union-list-set are all O(n) ;; so the final complexity is O(n) (define (union-set s1 s2) (list->tree (union-list-set (tree->list-2 s1) (tree->list-2 s2)))) (union-set (list->tree '(1 3 5 7 9 11)) (list->tree '(2 4 6 8 10))) (define (intersection-list-set s1 s2) (if (or (null? s1) (null? s2)) '() (let ((x1 (car s1)) (x2 (car s2))) (cond ((= x1 x2) (cons x1 (intersection-list-set (cdr s1) (cdr s2)))) ((< x1 x2) (intersection-list-set (cdr s1) s2)) ((> x1 x2) (intersection-list-set s1 (cdr s2))))))) (define (intersection-set s1 s2) (list->tree (intersection-list-set (tree->list-2 s1) (tree->list-2 s2)))) (intersection-set (list->tree '(1 3 5 8 9 10)) (list->tree '(2 3 6 8 10))) ;; Exercise 2.66 (define (lookup given-key set-of-records) (cond ((null? set-of-records) #f) ((= given-key (key (entry set-of-records))) (entry set-of-records)) ((> given-key (key (entry set-of-records))) (lookup given-key (right-branch set-of-records))) ((< given-key (key (entry set-of-records))) (lookup given-key (left-branch set-of-records))))) ;; for Exercises 2.67 - 2.72 ;; Huffman Encoding Trees ;; leave node: symbols that are encoded, weight ;; non-leaf node: a set containing all the symbols in the subtree, sum of weight ;; the path from root to the symbol is the binary encoding representation ;; the data structure (define (make-leaf symbol weight) (list 'leaf symbol weight)) (define (symbol-leaf leaf) (cadr leaf)) (define (weight-leaf leaf) (caddr leaf)) (define (make-code-tree left right) (list left right (append (symbols left) (symbols right)) (+ (weight left) (weight right)))) (define (left-branch tree) (car tree)) (define (right-branch tree) (cadr tree)) (define (symbols-tree tree) (caddr tree)) (define (weight-tree tree) (cadddr tree)) ;; generic procedures (define (leaf? node) (eq? (car node) 'leaf)) (define (symbols node) (if (leaf? node) (list (symbol-leaf node)) (symbols-tree node))) (define (weight node) (if (leaf? node) (weight-leaf node) (weight-tree node))) (define book-sample-tree (make-code-tree ;; 17 {A B C D E F G H} (make-leaf 'A 8) (make-code-tree ;; 9 {B C D E F G H} (make-code-tree ;; 5 {B C D} (make-leaf 'B 3) (make-code-tree (make-leaf 'C 1) (make-leaf 'D 1))) (make-code-tree ;; 4 {E F G H} (make-code-tree ;; 2 {E F} (make-leaf 'E 1) (make-leaf 'F 1)) (make-code-tree ;; 2 {G H} (make-leaf 'G 1) (make-leaf 'H 1)))))) ;; decoding procedure ;; the idea is to treat the encoding string as a stack and ;; transform the encoding symbol list "in place" (define (decode bits tree) (define (choose-branch bit branch) ;; to make the proc more robust (cond ((= bit 1) (right-branch branch)) ((= bit 0) (left-branch branch)) (else (error "bad bit: CHOOSE-BRANCH" bit)))) (define (decode-char bits subtree) (if (null? bits) '() (let ((next-branch (choose-branch (car bits) subtree))) (if (leaf? next-branch) (cons (symbol-leaf next-branch) (decode-char (cdr bits) tree)) ;; push on the list in place (decode-char (cdr bits) next-branch))))) (decode-char bits tree)) (define book-sample-code '(1 0 0 0 1 0 1 0)) (decode book-sample-code book-sample-tree) ;; => (B A C) ;; Exercise 2.67 (define sample-tree (make-code-tree (make-leaf 'A 4) (make-code-tree (make-leaf 'B 2) (make-code-tree (make-leaf 'D 1) (make-leaf 'C 1))))) (define sample-message '(0 1 1 0 0 1 0 1 0 1 1 1 0)) (decode sample-message sample-tree) ;; Exercise 2.68 (define (encode message tree) (define (encode-symbol char tree) (if (null? tree) (error "ENCODE: cannot encode the symbol" char) (let ((left (left-branch tree)) (right (right-branch tree))) (cond ((and (leaf? left) (eq? (symbol-leaf left) char)) '(0)) ((and (leaf? right) (eq? (symbol-leaf right) char)) '(1)) ((memq char (symbols left)) (cons 0 (encode-symbol char left))) ((memq char (symbols right)) (cons 1 (encode-symbol char right))) (else (error "ENCODE: cannot encode the symbol" char)))))) (if (null? message) '() (append (encode-symbol (car message) tree) (encode (cdr message) tree)))) (define sample-string '(A D A B B C A)) (encode sample-string sample-tree) ;; should be '(0 1 1 0 0 1 0 1 0 1 1 1 0) ;; Exercise 2.69 ;; supporting data structure - weighted set (define (adjoin-set el set) (cond ((null? set) (list el)) ((<= (weight el) (weight (car set))) (cons el set)) (else (cons (car set) (adjoin-set el (cdr set)))))) ;; test cases with simple pairs (let ((weight cdr)) (map (lambda (x) (adjoin-set x '((A 2) (B 4) (C 6) (D 8)))) '((E 1) (E 5) (E 10)))) (make-leaf 'G 1) ;; return an weight-ordered set (define (make-leaf-set pairs) (if (null? pairs) '() (let ((pair (car pairs))) (adjoin-set (make-leaf (car pair) (cadr pair)) (make-leaf-set (cdr pairs)))))) ;; return a huffman encoding tree (define (successive-merge set) (if (= (length set) 1) (car set) (let* ((left (car set)) (right (cadr set)) (merged (make-code-tree left right))) (successive-merge (adjoin-set merged (cddr set)))))) (define (generate-huffman-tree pairs) (successive-merge (make-leaf-set pairs))) (define sample-huffman-tree (generate-huffman-tree '((A 2) (B 4) (C 6) (D 8)))) (symbols sample-huffman-tree) (weight sample-huffman-tree) ;; Exercise 2.70 (define rock-song-alphabet '((A 2) (GET 2) (SHA 3) (WAH 1) (BOOM 1) (JOB 2) (NA 16) (YIP 9))) (define rock-song-huffman-tree (generate-huffman-tree rock-song-alphabet)) (define lyric '(GET A JOB SHA NA NA NA NA NA NA NA NA GET A JOB SHA NA NA NA NA NA NA NA NA WAH YIP YIP YIP YIP YIP YIP YIP YIP YIP SHA BOOM)) (length (encode lyric rock-song-huffman-tree)) ;; 84 bits are used to encode ;; if we are using fixed length encode, 3 bit will be need for each char ;; so the total will be 108 (* 3 (length lyric)) ;; Exercise 2.71 ;; the tree is merged strictly from the left to right ;; so there is (n - 1) merges ;; 1 bit for the most frequent ;; (n-1) bit for the least frequent ;; Exercise 2.72 ;; for the special cases, every tree forms from a leaf and a subtree ;; the symbols contains for a tree at level k are (n - k) ;; the `encode' procedure in linear recursive. ;; At each step, it apply two procedures: ;; 1. comparison of leaf symbols ;; 2. search char in subtree's symbols set ;; for procedure 1, the order of growth is O(1). Because of `left-branch' ;; and `symbol-leaf' is O(1) ;; However, if the implementation chooses to search first, then this will ;; be O(N) ;; for procedure 2, the order of growth is O(N). Because `right-branch' and ;; `symbols-tree' is constant and `memq' is O(N). ;; For the most frequent symbols, one step is required, the order of growth is O(1) ;; For the least frequent symbols, (n - 1) steps are required, ;; the order of growth is O(N^2) 1 + 2 + ... + (n - 1) = (n + 1) * (n - 1) / 2
false
6efefdea02c19d07e5a1daeca73b9a4878e821c2
2e4afc99b01124a1d69fa4f44126ef274f596777
/apng/resources/dracula/lang/dracula-module-begin.ss
461872532dbd8a3e218b0a16f3ae03d66aee1590
[]
no_license
directrix1/se2
8fb8204707098404179c9e024384053e82674ab8
931e2e55dbcc55089d9728eb4194ebc29b44991f
refs/heads/master
2020-06-04T03:10:30.843691
2011-05-05T03:32:54
2011-05-05T03:32:54
1,293,430
0
0
null
null
null
null
UTF-8
Scheme
false
false
815
ss
dracula-module-begin.ss
#lang scheme (require "check.ss" "../teachpacks/testing.ss" "../teachpacks/doublecheck.ss" (for-syntax "../proof/proof.ss" "../proof/syntax.ss")) (provide dracula-module-begin) (define-syntax (dracula-module-begin stx) (syntax-case stx () [(_ . forms) (with-syntax ([exports (datum->syntax stx `(,#'all-defined-out))]) (quasisyntax/loc stx (#%module-begin (define-values [] #,(annotate-proof (make-proof (make-part 'Dracula (syntax->loc stx) (map syntax->term (syntax->list #'forms)))) (syntax/loc stx (values)))) (provide exports) (begin-below . forms) (generate-report!) (check-properties!))))]))
true
35572d7d2b0b4ae69214673e64b2359e89805696
ac2a3544b88444eabf12b68a9bce08941cd62581
/gsc/_univadt.scm
05b0bc8651e5686b50170718f8b5a8877520cb21
[ "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
31,744
scm
_univadt.scm
;; ***** TARGET CODE EMITTERS (define-macro (^ . forms) (if (null? forms) `'() `(list ,@forms))) (define-macro (^var-declaration type name #!optional (init #f)) `(univ-emit-var-declaration ctx ,type ,name ,init)) (define-macro (^expr-statement expr) `(univ-emit-expr-statement ctx ,expr)) (define-macro (^if test true #!optional (false #f)) `(univ-emit-if ctx ,test ,true ,false)) (define-macro (^if-expr type expr1 expr2 expr3) `(univ-emit-if-expr ctx ,type ,expr1 ,expr2 ,expr3)) (define-macro (^if-instanceof class expr true #!optional (false #f)) `(univ-emit-if-instanceof ctx ,class ,expr ,true ,false)) (define-macro (^while test body) `(univ-emit-while ctx ,test ,body)) (define-macro (^eq? expr1 expr2) `(univ-emit-eq? ctx ,expr1 ,expr2)) (define-macro (^+ expr1 #!optional (expr2 #f)) `(univ-emit-+ ctx ,expr1 ,expr2)) (define-macro (^- expr1 #!optional (expr2 #f)) `(univ-emit-- ctx ,expr1 ,expr2)) (define-macro (^* expr1 expr2) `(univ-emit-* ctx ,expr1 ,expr2)) (define-macro (^/ expr1 expr2) `(univ-emit-/ ctx ,expr1 ,expr2)) (define-macro (^<< expr1 expr2) `(univ-emit-<< ctx ,expr1 ,expr2)) (define-macro (^>> expr1 expr2) `(univ-emit->> ctx ,expr1 ,expr2)) (define-macro (^>>> expr1 expr2) `(univ-emit->>> ctx ,expr1 ,expr2)) (define-macro (^bitnot expr) `(univ-emit-bitnot ctx ,expr)) (define-macro (^bitand expr1 expr2) `(univ-emit-bitand ctx ,expr1 ,expr2)) (define-macro (^bitior expr1 expr2) `(univ-emit-bitior ctx ,expr1 ,expr2)) (define-macro (^bitxor expr1 expr2) `(univ-emit-bitxor ctx ,expr1 ,expr2)) (define-macro (^= expr1 expr2) `(univ-emit-= ctx ,expr1 ,expr2)) (define-macro (^!= expr1 expr2) `(univ-emit-!= ctx ,expr1 ,expr2)) (define-macro (^< expr1 expr2) `(univ-emit-< ctx ,expr1 ,expr2)) (define-macro (^<= expr1 expr2) `(univ-emit-<= ctx ,expr1 ,expr2)) (define-macro (^> expr1 expr2) `(univ-emit-> ctx ,expr1 ,expr2)) (define-macro (^>= expr1 expr2) `(univ-emit->= ctx ,expr1 ,expr2)) (define-macro (^not expr) `(univ-emit-not ctx ,expr)) (define-macro (^&& expr1 expr2) `(univ-emit-&& ctx ,expr1 ,expr2)) (define-macro (^and expr1 expr2) `(univ-emit-and ctx ,expr1 ,expr2)) (define-macro (^or expr1 expr2) `(univ-emit-or ctx ,expr1 ,expr2)) (define-macro (^concat expr1 expr2) `(univ-emit-concat ctx ,expr1 ,expr2)) (define-macro (^tostr expr) `(univ-emit-tostr ctx ,expr)) (define-macro (^conv* type-name expr) `(univ-emit-conv* ctx ,type-name ,expr)) (define-macro (^cast type expr) `(univ-emit-cast ctx ,type ,expr)) (define-macro (^cast* type-name expr) `(univ-emit-cast* ctx ,type-name ,expr)) (define-macro (^cast*-scmobj expr) `(univ-emit-cast*-scmobj ctx ,expr)) (define-macro (^cast*-jumpable expr) `(univ-emit-cast*-jumpable ctx ,expr)) (define-macro (^upcast* from-type-name to-type-name expr) `(univ-emit-upcast* ctx ,from-type-name ,to-type-name ,expr)) (define-macro (^downcast* type-name expr) `(univ-emit-downcast* ctx ,type-name ,expr)) (define-macro (^downupcast* down-type-name up-type-name expr) `(univ-emit-downupcast* ctx ,down-type-name ,up-type-name ,expr)) (define-macro (^seq expr1 expr2) `(univ-emit-seq ctx ,expr1 ,expr2)) (define-macro (^parens expr) `(univ-emit-parens ctx ,expr)) (define-macro (^parens-php expr) `(univ-emit-parens-php ctx ,expr)) (define-macro (^local-var name) `(univ-emit-local-var ctx ,name)) (define-macro (^global-var name) `(univ-emit-global-var ctx ,name)) (define-macro (^global-function name) `(univ-emit-global-function ctx ,name)) (define-macro (^id-to-jumpable name) `(univ-emit-id-to-jumpable ctx ,name)) (define-macro (^rts-field name) `(univ-emit-rts-field ctx ,name #t)) (define-macro (^rts-field-priv name) `(univ-emit-rts-field ctx ,name #f)) (define-macro (^rts-field-ref name) `(univ-emit-rts-field-ref ctx ,name #t)) (define-macro (^rts-field-ref-priv name) `(univ-emit-rts-field-ref ctx ,name #f)) (define-macro (^rts-field-use name) `(univ-emit-rts-field-use ctx ,name #t)) (define-macro (^rts-field-use-priv name) `(univ-emit-rts-field-use ctx ,name #f)) (define-macro (^rts-method name) `(univ-emit-rts-method ctx ,name #t)) (define-macro (^rts-method-priv name) `(univ-emit-rts-method ctx ,name #f)) (define-macro (^rts-method-ref name) `(univ-emit-rts-method-ref ctx ,name #t)) (define-macro (^rts-method-ref-priv name) `(univ-emit-rts-method-ref ctx ,name #f)) (define-macro (^rts-method-use name) `(univ-emit-rts-method-use ctx ,name #t)) (define-macro (^rts-method-use-priv name) `(univ-emit-rts-method-use ctx ,name #f)) (define-macro (^rts-class name) `(univ-emit-rts-class ctx ,name #t)) (define-macro (^rts-class-priv name) `(univ-emit-rts-class ctx ,name #f)) (define-macro (^rts-class-ref name) `(univ-emit-rts-class-ref ctx ,name #t)) (define-macro (^rts-class-ref-priv name) `(univ-emit-rts-class-ref ctx ,name #f)) (define-macro (^rts-class-use name) `(univ-emit-rts-class-use ctx ,name #t)) (define-macro (^rts-class-use-priv name) `(univ-emit-rts-class-use ctx ,name #f)) (define-macro (^rts-jumpable-use name) `(univ-emit-rts-jumpable-use ctx ,name)) (define-macro (^prefix name #!optional (public? #f)) `(univ-emit-prefix ctx ,name ,public?)) (define-macro (^prefix-class name #!optional (public? #f)) `(univ-emit-prefix-class ctx ,name ,public?)) (define-macro (^assign-expr loc expr) `(univ-emit-assign-expr ctx ,loc ,expr)) (define-macro (^assign loc expr) `(univ-emit-assign ctx ,loc ,expr)) (define-macro (^inc-by loc expr #!optional (embed #f)) `(univ-emit-inc-by ctx ,loc ,expr ,embed)) (define-macro (^alias expr) `(univ-emit-alias ctx ,expr)) (define-macro (^unalias expr) `(univ-emit-unalias ctx ,expr)) (define-macro (^array? expr) `(univ-emit-array? ctx ,expr)) (define-macro (^array-length expr) `(univ-emit-array-length ctx ,expr)) (define-macro (^array-shrink! expr1 expr2) `(univ-emit-array-shrink! ctx ,expr1 ,expr2)) (define-macro (^array-shrink-possibly-copy! expr1 expr2) `(univ-emit-array-shrink-possibly-copy! ctx ,expr1 ,expr2)) (define-macro (^move-array-to-array array1 srcpos array2 destpos len) `(univ-emit-move-array-to-array ctx ,array1 ,srcpos ,array2 ,destpos ,len)) (define-macro (^copy-array-to-extensible-array expr len) `(univ-emit-copy-array-to-extensible-array ctx ,expr ,len)) (define-macro (^extensible-array-to-array! var len) `(univ-emit-extensible-array-to-array! ctx ,var ,len)) (define-macro (^extensible-subarray expr start len) `(univ-emit-extensible-subarray ctx ,expr ,start ,len)) (define-macro (^subarray expr1 expr2 expr3) `(univ-emit-subarray ctx ,expr1 ,expr2 ,expr3)) (define-macro (^array-index expr1 expr2) `(univ-emit-array-index ctx ,expr1 ,expr2)) (define-macro (^prop-index type expr1 expr2 #!optional (expr3 #f)) `(univ-emit-prop-index ctx ,type ,expr1 ,expr2 ,expr3)) (define-macro (^prop-index-or-null type expr1 expr2) `(univ-emit-prop-index-or-null ctx ,type ,expr1 ,expr2)) (define-macro (^prop-index-exists? expr1 expr2) `(univ-emit-prop-index-exists? ctx ,expr1 ,expr2)) (define-macro (^get obj name) `(univ-emit-get ctx ,obj ,name)) (define-macro (^set obj name val) `(univ-emit-set ctx ,obj ,name ,val)) (define-macro (^attribute-exists? obj name) `(univ-emit-attribute-exists? ctx ,obj ,name)) (define-macro (^obj obj) `(univ-emit-obj ctx ,obj)) (define-macro (^obj-proc-as type obj) `(univ-emit-obj-proc-as ctx ,type ,obj)) (define-macro (^array-literal type elems) `(univ-emit-array-literal ctx ,type ,elems)) (define-macro (^extensible-array-literal type elems) `(univ-emit-extensible-array-literal ctx ,type ,elems)) (define-macro (^new-array type len) `(univ-emit-new-array ctx ,type ,len)) (define-macro (^make-array type return len init) `(univ-emit-make-array ctx ,type ,return ,len ,init)) (define-macro (^call-prim expr . params) `(univ-emit-call-prim ctx ,expr ,@params)) (define-macro (^call-member expr fct . params) `(univ-emit-call-member ctx ,expr ,fct ,@params)) (define-macro (^jump expr . params) `(univ-emit-jump ctx ,expr ,@params)) (define-macro (^apply expr params) `(univ-emit-apply ctx ,expr ,params)) (define-macro (^this) `(univ-emit-this ctx)) (define-macro (^new type . params) `(univ-emit-new ctx ,type ,@params)) (define-macro (^new* class params) `(univ-emit-new* ctx ,class ,params)) (define-macro (^construct class . params) `(univ-emit-construct ctx ,class ,@params)) (define-macro (^construct* class params) `(univ-emit-construct* ctx ,class ,params)) (define-macro (^typeof type expr) `(univ-emit-typeof ctx ,type ,expr)) (define-macro (^instanceof class expr) `(univ-emit-instanceof ctx ,class ,expr)) (define-macro (^getopnd opnd) `(univ-emit-getopnd ctx ,opnd)) (define-macro (^setloc loc val) `(univ-emit-setloc ctx ,loc ,val)) (define-macro (^var-decl var-descr) `(univ-emit-var-decl ctx ,var-descr)) (define-macro (^decl type name) `(univ-emit-decl ctx ,type ,name)) (define-macro (^type type) `(univ-emit-type ctx ,type)) (define-macro (^procedure-declaration global? proc-type root-name params header attribs body) `(univ-emit-procedure-declaration ctx ,global? ,proc-type ,root-name ,params ,attribs (univ-emit-fn-body ctx ,header (lambda (ctx) ,body)))) ;;TODO: remove (define-macro (^prim-function-declaration root-name result-type params header attribs body) `(univ-emit-function-declaration ctx #t ,root-name ,result-type ,params ,attribs (univ-emit-fn-body ctx ,header (lambda (ctx) ,body)) #f #t)) (define-macro (^tos) `(univ-emit-tos ctx)) (define-macro (^pop receiver) `(univ-emit-pop ctx ,receiver)) (define-macro (^push val) `(univ-emit-push ctx ,val)) (define-macro (^getnargs) `(univ-emit-getnargs ctx)) (define-macro (^setnargs nb-args) `(univ-emit-setnargs ctx ,nb-args)) (define-macro (^getreg num) `(univ-emit-getreg ctx ,num)) (define-macro (^setreg num val) `(univ-emit-setreg ctx ,num ,val)) (define-macro (^getstk offset) `(univ-emit-getstk ctx ,offset)) (define-macro (^setstk offset val) `(univ-emit-setstk ctx ,offset ,val)) (define-macro (^getclo closure index) `(univ-emit-getclo ctx ,closure ,index)) (define-macro (^setclo closure index val) `(univ-emit-setclo ctx ,closure ,index ,val)) (define-macro (^getpeps name) `(univ-emit-getpeps ctx ,name)) (define-macro (^setpeps name val) `(univ-emit-setpeps ctx ,name ,val)) (define-macro (^getglo name) `(univ-emit-getglo ctx ,name)) (define-macro (^setglo name val) `(univ-emit-setglo ctx ,name ,val)) (define-macro (^glo-var-ref sym) `(univ-emit-glo-var-ref ctx ,sym)) (define-macro (^glo-var-primitive-ref sym) `(univ-emit-glo-var-primitive-ref ctx ,sym)) (define-macro (^glo-var-set! sym val) `(univ-emit-glo-var-set! ctx ,sym ,val)) (define-macro (^glo-var-primitive-set! sym val) `(univ-emit-glo-var-primitive-set! ctx ,sym ,val)) (define-macro (^return-poll expr poll? call?) `(univ-emit-return-poll ctx ,expr ,poll? ,call?)) (define-macro (^return-call-prim expr . params) `(univ-emit-return-call-prim ctx ,expr ,@params)) (define-macro (^return-jump expr) `(univ-emit-return-jump ctx ,expr)) (define-macro (^return expr) `(univ-emit-return ctx ,expr)) (define-macro (^map fn array) `(univ-emit-map ctx ,fn ,array)) (define-macro (^call-with-arg-array fn vals) `(univ-emit-call-with-arg-array ctx ,fn ,vals)) ;; ;; Host vs Scheme type correspondance ;; ;; ============================== ;; | Host | Scheme | ;; ============================== ;; | void | void-obj | ;; | null | null-obj | ;; | bool | boolean | ;; | int | fixnum | ;; | float | flonum | ;; | str | string | ;; | array | | ;; | object | | ;; | | list | ;; | function | procedure | ;; ============================== ;; (define-macro (^null) `(univ-emit-null ctx)) (define-macro (^null? expr) `(univ-emit-null? ctx ,expr)) (define-macro (^null-obj) `(univ-emit-null-obj ctx)) (define-macro (^null-obj? expr) `(univ-emit-null-obj? ctx ,expr)) (define-macro (^void) `(univ-emit-void ctx)) (define-macro (^void? expr) `(univ-emit-void? ctx ,expr)) (define-macro (^void-obj) `(univ-emit-void-obj ctx)) (define-macro (^str->string expr) `(univ-emit-str->string ctx ,expr)) (define-macro (^string->str expr) `(univ-emit-string->str ctx ,expr)) (define-macro (^void-obj? expr) `(univ-emit-void-obj? ctx ,expr)) (define-macro (^str? expr) `(univ-emit-str? ctx ,expr)) (define-macro (^float? expr) `(univ-emit-float? ctx ,expr)) (define-macro (^int? expr) `(univ-emit-int? ctx ,expr)) (define-macro (^eof) `(univ-emit-eof ctx)) (define-macro (^absent) `(univ-emit-absent ctx)) (define-macro (^deleted) `(univ-emit-deleted ctx)) (define-macro (^unused) `(univ-emit-unused ctx)) (define-macro (^unbound1) `(univ-emit-unbound1 ctx)) (define-macro (^unbound2) `(univ-emit-unbound2 ctx)) (define-macro (^unbound? val) `(univ-emit-unbound? ctx ,val)) (define-macro (^optional) `(univ-emit-optional ctx)) (define-macro (^key) `(univ-emit-key ctx)) (define-macro (^rest) `(univ-emit-rest ctx)) (define-macro (^bool val) `(univ-emit-bool ctx ,val)) (define-macro (^bool? val) `(univ-emit-bool? ctx ,val)) (define-macro (^boolean-obj obj) `(univ-emit-boolean-obj ctx ,obj)) (define-macro (^boolean-box val) `(univ-emit-boolean-box ctx ,val)) (define-macro (^boolean-unbox boolean) `(univ-emit-boolean-unbox ctx ,boolean)) (define-macro (^boolean? val) `(univ-emit-boolean? ctx ,val)) (define-macro (^chr val) `(univ-emit-chr ctx ,val)) (define-macro (^char-obj obj force-var?) `(univ-emit-char-obj ctx ,obj ,force-var?)) (define-macro (^char-box val) `(univ-emit-char-box ctx ,val)) (define-macro (^char-box-uninterned val) `(univ-emit-char-box-uninterned ctx ,val)) (define-macro (^char-unbox char) `(univ-emit-char-unbox ctx ,char)) (define-macro (^chr-fromint val) `(univ-emit-chr-fromint ctx ,val)) (define-macro (^chr-toint val) `(univ-emit-chr-toint ctx ,val)) (define-macro (^chr-tostr val) `(univ-emit-chr-tostr ctx ,val)) (define-macro (^char? val) `(univ-emit-char? ctx ,val)) (define-macro (^int val) `(univ-emit-int ctx ,val)) (define-macro (^num-of-type type val) `(univ-emit-num-of-type ctx ,type ,val)) (define-macro (^fixnum-box val) `(univ-emit-fixnum-box ctx ,val)) (define-macro (^fixnum-unbox fixnum) `(univ-emit-fixnum-unbox ctx ,fixnum)) (define-macro (^fixnum? val) `(univ-emit-fixnum? ctx ,val)) (define-macro (^empty-dict type) `(univ-emit-empty-dict ctx ,type)) (define-macro (^dict-key-exists? expr1 expr2) `(univ-emit-dict-key-exists? ctx ,expr1 ,expr2)) (define-macro (^dict-get type expr1 expr2 #!optional (expr3 #f)) `(univ-emit-dict-get ctx ,type ,expr1 ,expr2 ,expr3)) (define-macro (^dict-get-or-null type expr1 expr2) `(univ-emit-dict-get-or-null ctx ,type ,expr1 ,expr2)) (define-macro (^dict-set type expr1 expr2 expr3) `(univ-emit-dict-set ctx ,type ,expr1 ,expr2 ,expr3)) (define-macro (^dict-delete expr1 expr2) `(univ-emit-dict-delete ctx ,expr1 ,expr2)) (define-macro (^dict-length expr) `(univ-emit-dict-length ctx ,expr)) (define-macro (^member expr name) `(univ-emit-member ctx ,expr ,name)) (define-macro (^public name) `(univ-emit-public ctx ,name)) (define-macro (^pair? expr) `(univ-emit-pair? ctx ,expr)) (define-macro (^cons expr1 expr2) `(univ-emit-cons ctx ,expr1 ,expr2)) (define-macro (^getcar expr) `(univ-emit-getcar ctx ,expr)) (define-macro (^getcdr expr) `(univ-emit-getcdr ctx ,expr)) (define-macro (^setcar expr1 expr2) `(univ-emit-setcar ctx ,expr1 ,expr2)) (define-macro (^setcdr expr1 expr2) `(univ-emit-setcdr ctx ,expr1 ,expr2)) (define-macro (^float val) `(univ-emit-float ctx ,val)) (define-macro (^float-fromint val) `(univ-emit-float-fromint ctx ,val)) (define-macro (^float-toint val) `(univ-emit-float-toint ctx ,val)) (define-macro (^float-math fn . params) `(univ-emit-float-math ctx ,fn ,@params)) (define-macro (^float-abs val) `(univ-emit-float-abs ctx ,val)) (define-macro (^float-floor val) `(univ-emit-float-floor ctx ,val)) (define-macro (^float-ceiling val) `(univ-emit-float-ceiling ctx ,val)) (define-macro (^float-truncate val) `(univ-emit-float-truncate ctx ,val)) (define-macro (^float-round-half-up val) `(univ-emit-float-round-half-up ctx ,val)) (define-macro (^float-round-half-towards-0 val) `(univ-emit-float-round-half-towards-0 ctx ,val)) (define-macro (^float-round-half-to-even val) `(univ-emit-float-round-half-to-even ctx ,val)) (define-macro (^float-mod val1 val2) `(univ-emit-float-mod ctx ,val1 ,val2)) (define-macro (^float-exp val) `(univ-emit-float-exp ctx ,val)) (define-macro (^float-expm1 val) `(univ-emit-float-expm1 ctx ,val)) (define-macro (^float-log val) `(univ-emit-float-log ctx ,val)) (define-macro (^float-log1p val) `(univ-emit-float-log1p ctx ,val)) (define-macro (^float-sin val) `(univ-emit-float-sin ctx ,val)) (define-macro (^float-cos val) `(univ-emit-float-cos ctx ,val)) (define-macro (^float-tan val) `(univ-emit-float-tan ctx ,val)) (define-macro (^float-asin val) `(univ-emit-float-asin ctx ,val)) (define-macro (^float-acos val) `(univ-emit-float-acos ctx ,val)) (define-macro (^float-atan val) `(univ-emit-float-atan ctx ,val)) (define-macro (^float-atan2 val1 val2) `(univ-emit-float-atan2 ctx ,val1 ,val2)) (define-macro (^float-sinh val) `(univ-emit-float-sinh ctx ,val)) (define-macro (^float-cosh val) `(univ-emit-float-cosh ctx ,val)) (define-macro (^float-tanh val) `(univ-emit-float-tanh ctx ,val)) (define-macro (^float-asinh val) `(univ-emit-float-asinh ctx ,val)) (define-macro (^float-acosh val) `(univ-emit-float-acosh ctx ,val)) (define-macro (^float-atanh val) `(univ-emit-float-atanh ctx ,val)) (define-macro (^float-expt val1 val2) `(univ-emit-float-expt ctx ,val1 ,val2)) (define-macro (^float-sqrt val) `(univ-emit-float-sqrt ctx ,val)) (define-macro (^float-scalbn val1 val2) `(univ-emit-float-scalbn ctx ,val1 ,val2)) (define-macro (^float-ilogb val) `(univ-emit-float-ilogb ctx ,val)) (define-macro (^float-integer? val) `(univ-emit-float-integer? ctx ,val)) (define-macro (^float-finite? val) `(univ-emit-float-finite? ctx ,val)) (define-macro (^float-infinite? val) `(univ-emit-float-infinite? ctx ,val)) (define-macro (^float-nan? val) `(univ-emit-float-nan? ctx ,val)) (define-macro (^float-copysign val1 val2) `(univ-emit-float-copysign ctx ,val1 ,val2)) (define-macro (^float-eqv? val1 val2) `(univ-emit-float-eqv? ctx ,val1 ,val2)) (define-macro (^flonum-box val) `(univ-emit-flonum-box ctx ,val)) (define-macro (^flonum-unbox flonum) `(univ-emit-flonum-unbox ctx ,flonum)) (define-macro (^flonum? val) `(univ-emit-flonum? ctx ,val)) (define-macro (^cpxnum-make expr1 expr2) `(univ-emit-cpxnum-make ctx ,expr1 ,expr2)) (define-macro (^cpxnum? val) `(univ-emit-cpxnum? ctx ,val)) (define-macro (^ratnum-make expr1 expr2) `(univ-emit-ratnum-make ctx ,expr1 ,expr2)) (define-macro (^ratnum? val) `(univ-emit-ratnum? ctx ,val)) (define-macro (^bignum expr1 expr2) `(univ-emit-bignum ctx ,expr1 ,expr2)) (define-macro (^bignum? val) `(univ-emit-bignum? ctx ,val)) (define-macro (^bignum-digits val) `(univ-emit-bignum-digits ctx ,val)) (define-macro (^u32-box val) `(univ-emit-u32-box ctx ,val)) (define-macro (^u32-unbox u32) `(univ-emit-u32-unbox ctx ,u32)) (define-macro (^s32-box val) `(univ-emit-s32-box ctx ,val)) (define-macro (^s32-unbox s32) `(univ-emit-s32-unbox ctx ,s32)) (define-macro (^u64-box val) `(univ-emit-u64-box ctx ,val)) (define-macro (^u64-unbox u64) `(univ-emit-u64-unbox ctx ,u64)) (define-macro (^s64-box val) `(univ-emit-s64-box ctx ,val)) (define-macro (^s64-unbox s64) `(univ-emit-s64-unbox ctx ,s64)) (define-macro (^box? val) `(univ-emit-box? ctx ,val)) (define-macro (^box val) `(univ-emit-box ctx ,val)) (define-macro (^unbox val) `(univ-emit-unbox ctx ,val)) (define-macro (^setbox val1 val2) `(univ-emit-setbox ctx ,val1 ,val2)) (define-macro (^values-box val) `(univ-emit-values-box ctx ,val)) (define-macro (^values-unbox values) `(univ-emit-values-unbox ctx ,values)) (define-macro (^values? val) `(univ-emit-values? ctx ,val)) (define-macro (^values-length val) `(univ-emit-values-length ctx ,val)) (define-macro (^values-ref val1 val2) `(univ-emit-values-ref ctx ,val1 ,val2)) (define-macro (^values-set! val1 val2 val3) `(univ-emit-values-set! ctx ,val1 ,val2 ,val3)) (define-macro (^vect-box type val) `(univ-emit-vect-box ctx ,type ,val)) (define-macro (^vect-unbox type vect) `(univ-emit-vect-unbox ctx ,type ,vect)) (define-macro (^vect? type val) `(univ-emit-vect? ctx ,type ,val)) (define-macro (^vector-box val) `(univ-emit-vector-box ctx ,val)) (define-macro (^vector-unbox vector) `(univ-emit-vector-unbox ctx ,vector)) (define-macro (^vector? val) `(univ-emit-vector? ctx ,val)) (define-macro (^vector-length val) `(univ-emit-vector-length ctx ,val)) (define-macro (^vector-shrink! val1 val2) `(univ-emit-vector-shrink! ctx ,val1 ,val2)) (define-macro (^vector-ref val1 val2) `(univ-emit-vector-ref ctx ,val1 ,val2)) (define-macro (^vector-set! val1 val2 val3) `(univ-emit-vector-set! ctx ,val1 ,val2 ,val3)) (define-macro (^u8vector-box val) `(univ-emit-u8vector-box ctx ,val)) (define-macro (^u8vector-unbox u8vector) `(univ-emit-u8vector-unbox ctx ,u8vector)) (define-macro (^u8vector? val) `(univ-emit-u8vector? ctx ,val)) (define-macro (^u8vector-length val) `(univ-emit-u8vector-length ctx ,val)) (define-macro (^u8vector-shrink! val1 val2) `(univ-emit-u8vector-shrink! ctx ,val1 ,val2)) (define-macro (^u8vector-ref val1 val2) `(univ-emit-u8vector-ref ctx ,val1 ,val2)) (define-macro (^u8vector-set! val1 val2 val3) `(univ-emit-u8vector-set! ctx ,val1 ,val2 ,val3)) (define-macro (^u16vector-box val) `(univ-emit-u16vector-box ctx ,val)) (define-macro (^u16vector-unbox u16vector) `(univ-emit-u16vector-unbox ctx ,u16vector)) (define-macro (^u16vector? val) `(univ-emit-u16vector? ctx ,val)) (define-macro (^u16vector-length val) `(univ-emit-u16vector-length ctx ,val)) (define-macro (^u16vector-shrink! val1 val2) `(univ-emit-u16vector-shrink! ctx ,val1 ,val2)) (define-macro (^u16vector-ref val1 val2) `(univ-emit-u16vector-ref ctx ,val1 ,val2)) (define-macro (^u16vector-set! val1 val2 val3) `(univ-emit-u16vector-set! ctx ,val1 ,val2 ,val3)) (define-macro (^u32vector-box val) `(univ-emit-u32vector-box ctx ,val)) (define-macro (^u32vector-unbox u32vector) `(univ-emit-u32vector-unbox ctx ,u32vector)) (define-macro (^u32vector? val) `(univ-emit-u32vector? ctx ,val)) (define-macro (^u32vector-length val) `(univ-emit-u32vector-length ctx ,val)) (define-macro (^u32vector-shrink! val1 val2) `(univ-emit-u32vector-shrink! ctx ,val1 ,val2)) (define-macro (^u32vector-ref val1 val2) `(univ-emit-u32vector-ref ctx ,val1 ,val2)) (define-macro (^u32vector-set! val1 val2 val3) `(univ-emit-u32vector-set! ctx ,val1 ,val2 ,val3)) (define-macro (^u64vector-box val) `(univ-emit-u64vector-box ctx ,val)) (define-macro (^u64vector-unbox val) `(univ-emit-u64vector-unbox ctx ,val)) (define-macro (^u64vector? val) `(univ-emit-u64vector? ctx ,val)) (define-macro (^u64vector-length val) `(univ-emit-u64vector-length ctx ,val)) (define-macro (^u64vector-shrink! val1 val2) `(univ-emit-u64vector-shrink! ctx ,val1 ,val2)) (define-macro (^u64vector-ref val1 val2) `(univ-emit-u64vector-ref ctx ,val1 ,val2)) (define-macro (^u64vector-set! val1 val2 val3) `(univ-emit-u64vector-set! ctx ,val1 ,val2 ,val3)) (define-macro (^s8vector-box val) `(univ-emit-s8vector-box ctx ,val)) (define-macro (^s8vector-unbox val) `(univ-emit-s8vector-unbox ctx ,val)) (define-macro (^s8vector? val) `(univ-emit-s8vector? ctx ,val)) (define-macro (^s8vector-length val) `(univ-emit-s8vector-length ctx ,val)) (define-macro (^s8vector-shrink! val1 val2) `(univ-emit-s8vector-shrink! ctx ,val1 ,val2)) (define-macro (^s8vector-ref val1 val2) `(univ-emit-s8vector-ref ctx ,val1 ,val2)) (define-macro (^s8vector-set! val1 val2 val3) `(univ-emit-s8vector-set! ctx ,val1 ,val2 ,val3)) (define-macro (^s16vector-box val) `(univ-emit-s16vector-box ctx ,val)) (define-macro (^s16vector-unbox val) `(univ-emit-s16vector-unbox ctx ,val)) (define-macro (^s16vector? val) `(univ-emit-s16vector? ctx ,val)) (define-macro (^s16vector-length val) `(univ-emit-s16vector-length ctx ,val)) (define-macro (^s16vector-shrink! val1 val2) `(univ-emit-s16vector-shrink! ctx ,val1 ,val2)) (define-macro (^s16vector-ref val1 val2) `(univ-emit-s16vector-ref ctx ,val1 ,val2)) (define-macro (^s16vector-set! val1 val2 val3) `(univ-emit-s16vector-set! ctx ,val1 ,val2 ,val3)) (define-macro (^s32vector-box val) `(univ-emit-s32vector-box ctx ,val)) (define-macro (^s32vector-unbox val) `(univ-emit-s32vector-unbox ctx ,val)) (define-macro (^s32vector? val) `(univ-emit-s32vector? ctx ,val)) (define-macro (^s32vector-length val) `(univ-emit-s32vector-length ctx ,val)) (define-macro (^s32vector-shrink! val1 val2) `(univ-emit-s32vector-shrink! ctx ,val1 ,val2)) (define-macro (^s32vector-ref val1 val2) `(univ-emit-s32vector-ref ctx ,val1 ,val2)) (define-macro (^s32vector-set! val1 val2 val3) `(univ-emit-s32vector-set! ctx ,val1 ,val2 ,val3)) (define-macro (^s64vector-box val) `(univ-emit-s64vector-box ctx ,val)) (define-macro (^s64vector-unbox val) `(univ-emit-s64vector-unbox ctx ,val)) (define-macro (^s64vector? val) `(univ-emit-s64vector? ctx ,val)) (define-macro (^s64vector-length val) `(univ-emit-s64vector-length ctx ,val)) (define-macro (^s64vector-shrink! val1 val2) `(univ-emit-s64vector-shrink! ctx ,val1 ,val2)) (define-macro (^s64vector-ref val1 val2) `(univ-emit-s64vector-ref ctx ,val1 ,val2)) (define-macro (^s64vector-set! val1 val2 val3) `(univ-emit-s64vector-set! ctx ,val1 ,val2 ,val3)) (define-macro (^f32vector-box val) `(univ-emit-f32vector-box ctx ,val)) (define-macro (^f32vector-unbox val) `(univ-emit-f32vector-unbox ctx ,val)) (define-macro (^f32vector? val) `(univ-emit-f32vector? ctx ,val)) (define-macro (^f32vector-length val) `(univ-emit-f32vector-length ctx ,val)) (define-macro (^f32vector-shrink! val1 val2) `(univ-emit-f32vector-shrink! ctx ,val1 ,val2)) (define-macro (^f32vector-ref val1 val2) `(univ-emit-f32vector-ref ctx ,val1 ,val2)) (define-macro (^f32vector-set! val1 val2 val3) `(univ-emit-f32vector-set! ctx ,val1 ,val2 ,val3)) (define-macro (^f64vector-box val) `(univ-emit-f64vector-box ctx ,val)) (define-macro (^f64vector-unbox f64vector) `(univ-emit-f64vector-unbox ctx ,f64vector)) (define-macro (^f64vector? val) `(univ-emit-f64vector? ctx ,val)) (define-macro (^f64vector-length val) `(univ-emit-f64vector-length ctx ,val)) (define-macro (^f64vector-shrink! val1 val2) `(univ-emit-f64vector-shrink! ctx ,val1 ,val2)) (define-macro (^f64vector-ref val1 val2) `(univ-emit-f64vector-ref ctx ,val1 ,val2)) (define-macro (^f64vector-set! val1 val2 val3) `(univ-emit-f64vector-set! ctx ,val1 ,val2 ,val3)) (define-macro (^structure-box val) `(univ-emit-structure-box ctx ,val)) (define-macro (^structure-unbox structure) `(univ-emit-structure-unbox ctx ,structure)) (define-macro (^structure? val) `(univ-emit-structure? ctx ,val)) (define-macro (^structure-ref val1 val2) `(univ-emit-structure-ref ctx ,val1 ,val2)) (define-macro (^structure-set! val1 val2 val3) `(univ-emit-structure-set! ctx ,val1 ,val2 ,val3)) (define-macro (^str val) `(univ-emit-str ctx ,val)) (define-macro (^str-to-codes str) `(univ-emit-str-to-codes ctx ,str)) (define-macro (^str-length str) `(univ-emit-str-length ctx ,str)) (define-macro (^str-index-code str i) `(univ-emit-str-index-code ctx ,str ,i)) (define-macro (^string-obj obj force-var?) `(univ-emit-string-obj ctx ,obj ,force-var?)) (define-macro (^string-box val) `(univ-emit-string-box ctx ,val)) (define-macro (^string-unbox string) `(univ-emit-string-unbox ctx ,string)) (define-macro (^string? val) `(univ-emit-string? ctx ,val)) (define-macro (^string-length val) `(univ-emit-string-length ctx ,val)) (define-macro (^string-shrink! val1 val2) `(univ-emit-string-shrink! ctx ,val1 ,val2)) (define-macro (^string-ref val1 val2) `(univ-emit-string-ref ctx ,val1 ,val2)) (define-macro (^string-set! val1 val2 val3) `(univ-emit-string-set! ctx ,val1 ,val2 ,val3)) (define-macro (^substring val1 val2 val3) `(univ-emit-substring ctx ,val1 ,val2 ,val3)) (define-macro (^str-toint val) `(univ-emit-str-toint ctx ,val)) (define-macro (^str-tofloat val) `(univ-emit-str-toint ctx ,val)) (define-macro (^symbol-obj obj force-var?) `(univ-emit-symbol-obj ctx ,obj ,force-var?)) (define-macro (^symbol-box name) `(univ-emit-symbol-box ctx ,name)) (define-macro (^symbol-box-uninterned name hash) `(univ-emit-symbol-box-uninterned ctx ,name ,hash)) (define-macro (^symbol-unbox symbol) `(univ-emit-symbol-unbox ctx ,symbol)) (define-macro (^symbol? val) `(univ-emit-symbol? ctx ,val)) (define-macro (^keyword-obj obj force-var?) `(univ-emit-keyword-obj ctx ,obj ,force-var?)) (define-macro (^keyword-box name) `(univ-emit-keyword-box ctx ,name)) (define-macro (^keyword-box-uninterned name hash) `(univ-emit-keyword-box-uninterned ctx ,name ,hash)) (define-macro (^keyword-unbox keyword) `(univ-emit-keyword-unbox ctx ,keyword)) (define-macro (^keyword? val) `(univ-emit-keyword? ctx ,val)) (define-macro (^frame-box expr) `(univ-emit-frame-box ctx ,expr)) (define-macro (^frame-unbox expr) `(univ-emit-frame-unbox ctx ,expr)) (define-macro (^frame-slots expr) `(univ-emit-frame-slots ctx ,expr)) (define-macro (^frame? val) `(univ-emit-frame? ctx ,val)) (define-macro (^new-continuation expr1 expr2) `(univ-emit-new-continuation ctx ,expr1 ,expr2)) (define-macro (^continuation? val) `(univ-emit-continuation? ctx ,val)) (define-macro (^function? val) `(univ-emit-function? ctx ,val)) (define-macro (^procedure? val) `(univ-emit-procedure? ctx ,val)) (define-macro (^return? val) `(univ-emit-return? ctx ,val)) (define-macro (^closure? val) `(univ-emit-closure? ctx ,val)) (define-macro (^closure-length val) `(univ-emit-closure-length ctx ,val)) (define-macro (^closure-code val) `(univ-emit-closure-code ctx ,val)) (define-macro (^closure-ref val1 val2) `(univ-emit-closure-ref ctx ,val1 ,val2)) (define-macro (^closure-set! val1 val2 val3) `(univ-emit-closure-set! ctx ,val1 ,val2 ,val3)) (define-macro (^new-delay-promise expr) `(univ-emit-new-delay-promise ctx ,expr)) (define-macro (^promise? val) `(univ-emit-promise? ctx ,val)) (define-macro (^new-will expr1 expr2) `(univ-emit-new-will ctx ,expr1 ,expr2)) (define-macro (^will? val) `(univ-emit-will? ctx ,val)) (define-macro (^new-foreign expr1 expr2) `(univ-emit-new-foreign ctx ,expr1 ,expr2)) (define-macro (^foreign? val) `(univ-emit-foreign? ctx ,val)) (define-macro (^popcount! arg) `(univ-emit-popcount! ctx ,arg)) (define-macro (^host-primitive? arg) `(univ-emit-host-primitive? ctx ,arg))
false
614fa211429640d448b69751712cfaf12f645fd0
c9a2cb859ab0a460f6c5519fce0422cbf9da9374
/shapefile/prj.scm
4e36c2a2c731761b3a5e28c632d5c464610adb16
[ "MIT" ]
permissive
HugoNikanor/guile-shapefile
f34d349bce62652e5a92ca6df01f472289414e86
4963752d8d052094ed5c6769fad0aa10670d74f9
refs/heads/master
2023-07-07T01:08:41.070277
2022-02-15T21:58:04
2022-02-15T21:58:04
325,540,289
4
1
null
null
null
null
UTF-8
Scheme
false
false
1,135
scm
prj.scm
(define-module (shapefile prj) :use-module (ice-9 peg) :use-module (ice-9 match) :export (parse-prj-file)) (define-peg-pattern string all (and (ignore "\"") (* (and (not-followed-by "\"") peg-any)) (ignore "\""))) (define-peg-pattern digit body (range #\0 #\9) ) (define-peg-pattern integer body (+ digit)) (define-peg-pattern number all (and integer "." integer)) (define-peg-pattern record all (and (+ (range #\A #\Z)) (ignore "[") string (* (and (ignore ",") (or record string number))) (ignore "]"))) ;; (peg:tree (match-pattern record str)) (define (parse-tree tree) (match tree (('string s) s) (('number s) (string->number s)) (('record name body ...) `(,(string->symbol name) ,@(map parse-tree (keyword-flatten '(string record number) body)))) (dflt (display dflt (current-error-port)) (newline (current-error-port)) ))) (define (parse-prj-file port) (define string ((@ (ice-9 rdelim) read-delimited) "" port)) (parse-tree (peg:tree (match-pattern record string))))
false
a8fb68afc7ce4f3d72dc934e1998d97a89244270
e26e24bec846e848630bf97512f8158d8040689c
/lib/chibi/bytevector.sld
42b83a8693a56f72f23fdf30dc667c5b117eea0c
[ "BSD-3-Clause" ]
permissive
traviscross/chibi-scheme
f989df49cb76512dc59f807aeb2426bd6fe1c553
97b81d31300945948bfafad8b8a7dbffdcd61ee3
refs/heads/master
2023-09-05T16:57:14.338631
2014-04-01T22:02:02
2014-04-01T22:02:02
18,473,315
2
0
null
null
null
null
UTF-8
Scheme
false
false
335
sld
bytevector.sld
(define-library (chibi bytevector) (export bytevector-u16-ref-le bytevector-u16-ref-be bytevector-u32-ref-le bytevector-u32-ref-be integer->bytevector bytevector->integer integer->hex-string hex-string->integer bytevector->hex-string hex-string->bytevector) (import (chibi) (srfi 33)) (include "bytevector.scm"))
false
a9bc92ab698a6adee68580cf124d4f28bc10474e
f5083e14d7e451225c8590cc6aabe68fac63ffbd
/cs/01-Programming/cs61a/exercises/06_midterm_1.scm
e8d66b7ce819fe14a9897ba5b3442664846632ab
[]
no_license
Phantas0s/playground
a362653a8feb7acd68a7637334068cde0fe9d32e
c84ec0410a43c84a63dc5093e1c214a0f102edae
refs/heads/master
2022-05-09T06:33:25.625750
2022-04-19T14:57:28
2022-04-19T14:57:28
136,804,123
19
5
null
2021-03-04T14:21:07
2018-06-10T11:46:19
Racket
UTF-8
Scheme
false
false
7,065
scm
06_midterm_1.scm
; +-----------+ ; | Problem 1 | ; +-----------+ ; What will Scheme print in response to the following expressions? If an expression produces ; an error message, you may just say “error”; you don’t have to provide the exact text of ; the message. If the value of an expression is a procedure, just say “procedure”; you don’t ; have to show the form in which Scheme prints procedures. (every - (keep number? ’(the 1 after 909))) ; -910 ; **WRONG** ((lambda (a b) ((if (< b a) + *) b a)) 4 6) ; 10 ; **WRONG** (word (first ’(cat)) (butlast ’dog)) ; cdo ; **WRONG** (cons (list 1 2) (cons 3 4)) ; ((1 2) 3 . 4) ; **WRONG** (let ((p (list 4 5))) (cons (cdr p) (cddr p))) ; ((5)) ; **WRONG** ; (cadadr '((a (b) c) (d (e) f) (g (h) i)) ; **GOOD** ; error - there is one parent missing!! ; +-------------------------------+ ; | Problem 2 (Orders of growth). | ; +-------------------------------+ ; (a) Indicate the order of growth in time of foo below: (define (foo n) (if (< n 2) 1 (+ (baz (- n 1)) (baz (- n 2))))) (define (baz n) (+ n (- n 1)) ) ; Θ(n) ; **WRONG** - no recursion here!! ; (b) Indicate the order of growth in time of garply below: (define (garply n) (if (= n 0) 0 (+ (factorial n) (garply (- n 1))))) (define (factorial n) (if (= n 0) 1 (* n (factorial (- n 1))))) ; Θ(n^2) ; **PERFECT** ; +-------------------------------------------+ ; | Problem 3 (Normal and applicative order). | ; +-------------------------------------------+ ; Imagine that there is a primitive procedure called counter, with no arguments, that ; returns 1 the first time you call it, 2 the second time, and so on. (The multiplication ; procedure *, used below, is also primitive.) ; Supposing that counter hasn’t been called until now, what is the value of the expression (* (counter) (counter)) ; under applicative order? 2 ; under normal order? 1 ; **WRONG** ; +------------------------------------------------+ ; | Problem 4 (Iterative and recursive processes). | ; +------------------------------------------------+ ; One or more of the following procedures generates an iterative process. Circle them. Don’t ; circle the ones that generate a recursive process. (define (butfirst-n num stuff) (if (= num 0) stuff (butfirst-n (- num 1) (bf stuff)))) ; iterative process ; **PERFECT** (define (member? thing stuff) (cond ((empty? stuff) #f) ((equal? thing (first stuff)) #t) (else (member? thing (bf stuff))))) ; iterative process ; **PERFECT** (define (addup nums) (if (empty? nums) 0 (+ (first nums) (addup (bf nums))))) ; recursive process ; **PERFECT** ; +-----------------------------------+ ; | Problem 5 (Recursive procedures). | ; +-----------------------------------+ (define (syllables w) (define (count-syllables w count) (if (empty? w) count (cond ((vowel? (first w)) (count-syllables (bf w) (+ count 1))) (else (count-syllables (bf w) count))))) (count-syllables w 0)) (define (vowel? letter) (member? letter ’(a e i o u))) ; **WRONG** - didn't read the problem properly :'( ; +-------------------------------------+ ; | Problem 6 (Higher order functions). | ; +-------------------------------------+ ; (Part a) Write a procedure in-order? that takes two arguments: first, a predicate function ; of two arguments that returns #t if its first argument comes before its second; second, a ; sentence. Your procedure should return #t if the sentence is in increasing order according ; to the given predicate. Examples: ; > (define (shorter? a b) ; (< (count a) (count b)) ) ; > (in-order? shorter? ’(i saw them standing together)) ; #t ; > (in-order? shorter? ’(i saw her standing there)) ; #f ; > (in-order? < ’(2 3 5 5 8 13)) ; #f ; > (in-order? <= ’(2 3 5 5 8 13)) ; #t ; > (in-order? > ’(23 14 7 5 2)) ; #t (define (shorter? a b) (< (count a) (count b)) ) (define (in-order? pred s) (if (empty? s) #t (cond ((pred (first s) (second s)) (in-order? pred (bf s))) (else #f)))) ; **WRONG** ; (Part b) Write a procedure order-checker that takes as its only argument a predicate ; function of two arguments. Your procedure should return a predicate function with one ar- ; gument, a sentence; this returned procedure should return #t if the sentence is in ascending ; order according to the predicate argument. For example: ; > (define length-ordered? (order-checker shorter?)) ; > (length-ordered? ’(i saw them standing together)) ; #t ; > (length-ordered? ’(i saw her standing there)) ; #f ; > ((order-checker <) ’(2 3 5 5 8 13)) ; #f ; > ((order-checker <=) ’(2 3 5 5 8 13)) ; #t ; > ((order-checker >) ’(23 14 7 5 2)) ; #t (define (order-checker pred) (lambda (s) (in-order? pred s))) ; **PERFECT** ; Problem 7 (Data abstraction). ; We want to write a program that uses the time of day as an abstract data type. We’ll ; represent times internally as a list of three elements, such as (11 23 am) for 11:23 am. For ; the purposes of this problem, assume that the hour part is never 12, so there’s never any ; special problems about noon and midnight. The hour will be a number 1–11, the minute ; will be a number 0–59, and the third element (which we’ll call the category) must be the ; word am or the word pm. Here’s our implementation: ; (define ; (make-time hr mn cat) (list hr mn cat)) ; (define ; hour car) ; (define ; minute cadr) ; (define ; category caddr) ; (a) This is a good internal representation, but not a good representation for the user of ; our program to see. Write a function time-print-form that takes a time as its argument ; and returns a word of the form 3:07pm. ; (b) If we want to ask whether one time is before or after another, it’s convenient to use the ; 24-hour representation in which 3:47 pm has the form 1547. Write a procedure 24-hour ; that takes a time as its argument and returns the number that represents that time in ; 24-hour notation: ; > (24-hour (make-time 3 47 ’pm)) ; 1547 ; Respect the data abstraction! ; (c) Now we decide to change the internal representation of times to be a number in 24- ; hour form. But we want the constructor and selectors to have the same interface so that ; programs using the abstract data type don’t have to change. Rewrite the constructor and ; selectors to accomplish this. ; (a) (define (make-time hr mn cat) (list hr mn cat)) (define hour car) (define minute cadr) (define category caddr) (define (time-print-form time) (word (hour time) ': (minute time) (category time))) ; **GOOD** ; (b) (define (24-hour time) (if (equal? (category time) 'pm) (+ (* (+ 12 (hour time)) 100) (minute time)) (+ (* (hour time) 100) (minute time)))) ; **PERFECT** ; (c) (define (make-time hr mn cat) (if (equal? cat 'pm) (list (+ 12) mn cat) (list hr mn cat))) (define hour car) (define minute cadr) (define category caddr) ; FINAL SCORE: 15/23 (1 point was given for giving your name / grade)
false
3aed88be9645bdf3fb549e857f874a0eba65a1b7
2e4afc99b01124a1d69fa4f44126ef274f596777
/apng/resources/dracula/modular/list-set.ss
48cc113f2e2631530942a018cb58767670f4acf9
[]
no_license
directrix1/se2
8fb8204707098404179c9e024384053e82674ab8
931e2e55dbcc55089d9728eb4194ebc29b44991f
refs/heads/master
2020-06-04T03:10:30.843691
2011-05-05T03:32:54
2011-05-05T03:32:54
1,293,430
0
0
null
null
null
null
UTF-8
Scheme
false
false
1,010
ss
list-set.ss
#lang scheme/base (provide list-union list-union* list-inter list-inter* list-minus) (define (list-minus #:compare [compare equal?] one two) (remove* two one compare)) (define (list-union #:compare [compare equal?] . sets) (list-union* #:compare compare sets)) (define (list-union* #:compare [compare equal?] sets) (if (null? sets) null (let* ([tail (list-union* #:compare compare (cdr sets))] [head (list-minus #:compare compare (car sets) tail)]) (append tail head)))) (define (list-inter #:compare [compare equal?] set . sets) (list-inter* #:compare compare (cons set sets))) (define (list-inter* #:compare [compare equal?] sets) (let* ([head (car sets)] [rest (cdr sets)]) (if (null? rest) head (let* ([tail (list-inter* #:compare compare rest)] [over (list-minus #:compare compare tail head)] [gone (list-minus #:compare compare tail over)]) gone))))
false
c7f97f39b4471f238f8a9235004264830af93cea
d881dacf2327ecd474f11318ea8e2b9536fe3e73
/srfi-tools/interactive.sld
9782bba030887d337632818e154b32990e0ce33f
[ "MIT" ]
permissive
scheme-requests-for-implementation/srfi-common
a84c7eaa6a40a4d1b80ef723759c2d3aed480177
78b45ab8028cfbd462fb1231cafec4ff4c5c5d30
refs/heads/master
2023-07-19T23:14:26.615668
2023-07-14T18:03:06
2023-07-14T18:03:06
37,961,335
31
7
MIT
2023-05-11T13:57:14
2015-06-24T04:00:50
HTML
UTF-8
Scheme
false
false
4,503
sld
interactive.sld
(define-library (srfi-tools interactive) (export srfi-open-dir srfi-open-home-dir srfi-open-file srfi-open-landing-file srfi-browse srfi-browse-file srfi-browse-landing srfi-browse-landing-file srfi-browse-github srfi-browse-home srfi-lucky srfi-pager srfi-edit srfi-browse-mail srfi-compose) (import (scheme base) (scheme char) (srfi-tools private external) (srfi-tools private format) (srfi-tools private list) (srfi-tools private string) (srfi-tools private os) (srfi-tools private command) (srfi-tools private port) (srfi-tools data) (srfi-tools path) (srfi-tools html) (srfi-tools mail) (srfi-tools url) (srfi-tools github)) (begin (define (srfi-open-dir num) (desktop-open (srfi-dir num))) (define-command (open-dir num) "Open home directory for SRFI <num>." (srfi-open-dir (parse-srfi-number num))) (define (srfi-open-home-dir) (desktop-open (srfi-home-dir))) (define-command (open-home-dir) "Open home directory for all SRFIs." (srfi-open-home-dir)) ;; (define (srfi-open-file num) (desktop-open (srfi-html-file num))) (define-command (open-file num) "Open local copy of SRFI document <num>." (srfi-open-file (parse-srfi-number num))) (define (srfi-open-landing-file num) (desktop-open (srfi-landing-html-file num))) (define-command (open-landing-file num) "Open local copy of SRFI landing page <num>." (srfi-open-landing-file (parse-srfi-number num))) ;; (define (srfi-browse num) (browse-url (srfi-html-url num))) (define-command (browse num) "Browse SRFI document <num> on SRFI site." (srfi-browse (parse-srfi-number num))) (define (srfi-browse-file num) (browse-url (srfi-html-file num))) (define-command (browse-file num) "Browse local copy of SRFI document <num>." (srfi-browse-file (parse-srfi-number num))) (define (srfi-browse-landing num) (browse-url (srfi-landing-url num))) (define-command (browse-landing num) "Browse SRFI landing page <num> on SRFI site." (srfi-browse-landing (parse-srfi-number num))) (define (srfi-browse-landing-file num) (browse-url (srfi-landing-html-file num))) (define-command (browse-landing-file num) "Browse local copy of SRFI landing page <num>." (srfi-browse-landing-file (parse-srfi-number num))) (define (srfi-browse-github num) (browse-url (srfi-github-url num))) (define-command (browse-github num) "Browse GitHub page for SRFI <num>." (srfi-browse-github (parse-srfi-number num))) (define (srfi-browse-home) (browse-url (srfi-home-url))) (define-command (browse-home) "Browse home page of the SRFI project." (srfi-browse-home)) (define (srfi-lucky words) (let ((matches (srfi-search words))) (cond ((null? matches) (error "No luck. Try another query?")) (else (unless (null? (cdr matches)) (write-srfi-list matches) (newline)) (let ((srfi (car matches))) (write-line (format "Opening ~a." (srfi-format srfi))) (srfi-browse (srfi-number srfi))))))) (add-command! "lucky" '(word ...) "Browse first SRFI whose title matches all <word>s." 1 #f (lambda words (srfi-lucky words))) ;; (define (srfi-pager num) (run-pager-on-url (srfi-html-file num))) (define-command (pager num) "Run pager on local copy of SRFI document <num>." (srfi-pager (parse-srfi-number num))) ;; (define (srfi-edit num) (edit-text-file (srfi-html-file num))) (define-command (edit num) "Edit local copy of SRFI document <num>." (srfi-edit (parse-srfi-number num))) ;; (define (srfi-browse-mail num) (browse-url (srfi-mail-archive-url num))) (define-command (browse-mail num) "Browse mailing list archive for SRFI <num>." (srfi-browse-mail (parse-srfi-number num))) (define (srfi-compose num) (desktop-open (srfi-mailto-url num))) (define-command (compose num) "Open email app with a new email to SRFI <num> mailing list." (srfi-compose (parse-srfi-number num)))))
false
794719041edc039385aae6a4931ced3b59bb11d0
a8216d80b80e4cb429086f0f9ac62f91e09498d3
/lib/chibi/binary-record.sld
6aca4cc52df41d9a8280837ed9221c9ff692385b
[ "BSD-3-Clause" ]
permissive
ashinn/chibi-scheme
3e03ee86c0af611f081a38edb12902e4245fb102
67fdb283b667c8f340a5dc7259eaf44825bc90bc
refs/heads/master
2023-08-24T11:16:42.175821
2023-06-20T13:19:19
2023-06-20T13:19:19
32,322,244
1,290
223
NOASSERTION
2023-08-29T11:54:14
2015-03-16T12:05:57
Scheme
UTF-8
Scheme
false
false
756
sld
binary-record.sld
(define-library (chibi binary-record) (import (scheme base) (srfi 1)) (cond-expand ((library (srfi 151)) (import (srfi 151))) ((library (srfi 33)) (import (srfi 33))) (else (import (srfi 60)))) (cond-expand ((library (srfi 130)) (import (srfi 130))) (else (import (srfi 13)))) (export ;; interface define-binary-record-type ;; binary types u8 u16/le u16/be padded-string fixed-string octal decimal hexadecimal ;; auxiliary syntax make: pred: read: write: block: ;; indirect exports define-binary-type defrec define-auxiliary-syntax syntax-let-optionals*) (include "binary-types.scm") (cond-expand (chicken (include "binary-record-chicken.scm")) (else (include "binary-record.scm"))))
false
5a13c43ed4248a1fdd49ce52788495581f412925
784dc416df1855cfc41e9efb69637c19a08dca68
/src/gerbil/runtime/gx-gambc.scm
0f825ac41d27592013878fc81a60440f2fabefcb
[ "LGPL-2.1-only", "Apache-2.0", "LGPL-2.1-or-later" ]
permissive
danielsz/gerbil
3597284aa0905b35fe17f105cde04cbb79f1eec1
e20e839e22746175f0473e7414135cec927e10b2
refs/heads/master
2021-01-25T09:44:28.876814
2018-03-26T21:59:32
2018-03-26T21:59:32
123,315,616
0
0
Apache-2.0
2018-02-28T17:02:28
2018-02-28T17:02:28
null
UTF-8
Scheme
false
false
8,618
scm
gx-gambc.scm
;;; -*- Gerbil -*- ;;; (C) vyzo at hackzen.org ;;; Gerbil-gambc interpreter support (##namespace ("")) ;;(include "gx-gambc#.scm") (declare (block) (standard-bindings) (extended-bindings)) (define _gx#loading-scheme-source (make-parameter #f)) (define (_gx#init-gx!) ;; setup expander (gx#current-expander-marks '()) (gx#current-expander-phi 0) (gx#current-expander-context (gx#make-top-context)) (gx#current-expander-module-library-path (&current-module-libpath)) (gx#current-expander-module-registry (make-hash-table)) (gx#current-expander-module-import gx#core-import-module) (gx#current-expander-module-eval gx#core-eval-module) (gx#current-expander-compile _gx#compile-top) (gx#current-expander-eval ##eval) (gx#core-bind-root-syntax! ':<root> (gx#make-prelude-context #f) #t) ;; setup _gx (&current-context _gx#*top*) (&current-compiler _gx#compile-top) (&current-expander gx#core-expand) (set! _gx#eval-module gx#core-eval-module)) ;; load the interpreter environment (define (gerbil-lang) (string->symbol (getenv "GERBIL_LANG" "gerbil"))) (define (_gx#load-gxi #!optional (hook-expander? #t)) (_gx#init-gx!) (let* ((core (gx#import-module ':gerbil/core)) (pre (gx#make-prelude-context core))) (gx#current-expander-module-prelude pre) (gx#core-bind-root-syntax! ':<core> pre #t) (let ((lang (gerbil-lang))) (case lang ((gerbil) (gx#eval-syntax '(import :gerbil/core))) ((r7rs) (gx#eval-syntax '(import :scheme/r7rs :scheme/base))) (else (gx#eval-syntax `(import ,lang)))))) (when hook-expander? ;; avoid loops from phi evals (gx#current-expander-compile _gx#compile-top-source) ;; hook the expander (set! ##expand-source _gx#expand-source) (set! ##display-exception-hook _gx#display-exception) (unless _gx#real-macro-descr (set! _gx#real-macro-descr ##macro-descr)) (set! ##macro-descr _gx#macro-descr) ;; hook the readtables (set! ##main-readtable _gx#*readtable*) (for-each (lambda (port) (input-port-readtable-set! port _gx#*readtable*)) (list ##stdin-port ##console-port)) (for-each (lambda (port) (output-port-readtable-set! port (readtable-sharing-allowed?-set (output-port-readtable port) #t))) (list ##stdout-port ##console-port)))) (define (_gx#gxi-init-interactive! cmdline) (define (load-init init.ss) ;; load gerbil interactive init (let ((init-file (path-expand (string-append "lib/" init.ss) (getenv "GERBIL_HOME")))) (gx#eval-syntax `(include ,init-file))) ;; if it exists, load user's ~/.gerbil/init.ss (let ((init-file (string-append "~/.gerbil/" init.ss))) (if (file-exists? init-file) (gx#eval-syntax `(include ,init-file))))) (case (gerbil-lang) ((gerbil) (load-init "init.ss")) ((r7rs) (load-init "r7rs-init.ss")))) ;; hook load to be able to load raw gambit code when the expander is hooked (define (load-scheme path) (parameterize ((_gx#loading-scheme-source path)) (##load path (lambda args #f) #t #t #f))) ;; load path utils (define (load-path) (values (library-load-path) (expander-load-path))) (define (library-load-path) (&current-module-libpath)) (define (expander-load-path) (gx#current-expander-module-library-path)) (define (add-load-path . paths) (apply add-library-load-path paths) (apply add-expander-load-path paths)) (define (add-library-load-path . paths) (let* ((current (&current-module-libpath)) (paths (map path-normalize paths)) (paths (filter (lambda (x) (not (member x current))) paths))) (&current-module-libpath (append current paths)))) (define (add-expander-load-path . paths) (let* ((current (gx#current-expander-module-library-path)) (paths (map path-normalize paths)) (paths (filter (lambda (x) (not (member x current))) paths))) (gx#current-expander-module-library-path (append current paths)))) (define (cons-load-path . paths) (apply cons-library-load-path paths) (apply cons-expander-load-path paths)) (define (cons-library-load-path . paths) (let* ((current (&current-module-libpath)) (paths (map path-normalize paths))) (&current-module-libpath (append paths current)))) (define (cons-expander-load-path . paths) (let* ((current (gx#current-expander-module-library-path)) (paths (map path-normalize paths))) (gx#current-expander-module-library-path (append paths current)))) ;; stuffs (define (_gx#expand-source src) (define (expand src) (_gx#compile-top (gx#core-expand (_gx#source->syntax src)))) (define (no-expand src) (cond ((##source? src) (let ((code (##source-code src))) (and (pair? code) (eq? __noexpand: (##car code)) (##cdr code)))) ((_gx#loading-scheme-source) src) (else #f))) ;;(displayln "expand-source " src) (cond ((no-expand src) => values) (else (expand src)))) ;; hook to make gambit macro expansion work with a hooked expander ;; ##macro-descr recurses into the expander through ##eval-top, ;; which breaks begin-foreign (define _gx#real-macro-descr #f) (define (_gx#macro-descr . args) (parameterize ((_gx#loading-scheme-source 'macro)) (apply _gx#real-macro-descr args))) (define (_gx#source->syntax src) (let recur ((e src)) (cond ((##source? e) (make-AST (recur (##source-code e)) (##source-locat e))) ((pair? e) (cons (recur (##car e)) (recur (##cdr e)))) ((vector? e) (vector-map recur e)) ((box? e) (box (recur (unbox e)))) (else e)))) (define (_gx#compile-top-source stx) (cons __noexpand: (_gx#compile-top stx))) (define (_gx#compile-top stx) (_gx#compile (gx#core-compile-top-syntax stx))) (define (_gx#eval-import in) (define mods (make-hash-table-eq)) (define (import1 in phi) (cond ((gx#module-import? in) (let ((iphi (fx+ phi (gx#module-import-phi in)))) (when (fxzero? iphi) (eval1 (gx#module-export-context (gx#module-import-source in)))))) ((gx#module-context? in) (when (fxzero? phi) (eval1 in))) ((gx#import-set? in) (let ((iphi (fx+ phi (gx#import-set-phi in)))) (cond ((fxzero? iphi) (eval1 (gx#import-set-source in))) ((fxpositive? iphi) (for-each (lambda (in) (import1 in iphi)) (gx#module-context-import (gx#import-set-source in))))))) (else (error "Unexpected import" in)))) (define (eval1 ctx) (unless (hash-get mods ctx) (hash-put! mods ctx #t) (_gx#eval-module ctx))) (if (pair? in) (for-each (lambda (in) (import1 in 0)) in) (import1 in 0))) ;; bootstrap module eval - init-gx! sets to gx#core-eval-module (define (_gx#eval-module obj) (let ((key (if (gx#module-context? obj) (gx#module-context-path obj) obj))) (cond ((hash-get _gx#*modules* key) => values) ; bootstrap import (else (gx#core-eval-module obj))))) (define (_gx#display-exception e port) (cond ((syntax-error? e) (parameterize ((current-output-port port)) (displayln "Syntax Error") (_gx#display-syntax-error e))) ((method-ref e 'display-exception) => (lambda (f) (f e port))) (else (##default-display-exception e port)))) (define (_gx#display-syntax-error e) (define (location) (let lp ((rest (error-irritants e))) (core-match rest ((hd . rest) (or (&AST-source hd) (lp rest))) (else #f)))) (display "*** ERROR IN ") (cond ((location) => (lambda (where) (##display-locat where #t (current-output-port)))) (else (display "?"))) (newline) (display "--- Syntax Error") (cond ((error-trace e) => (lambda (where) (displayln " at " where ": " (error-message e)))) (else (displayln ": " (error-message e)))) (core-match (error-irritants e) ((stx . rest) (display "... form: ") (_gx#pp-syntax stx) (for-each (lambda (detail) (display "... detail: ") (write (&AST->datum detail)) (cond ((&AST-source detail) => (lambda (loc) (display " at ") (##display-locat loc #t (current-output-port))))) (newline)) rest)) (else (void))) (cond ((method-ref e 'display-error-trace) => (lambda (displayf) (displayf e)))))
false
4aebfa16488eb1c6a1f323abc59563b65e5b1c45
defeada37d39bca09ef76f66f38683754c0a6aa0
/UnityEngine/unity-engine/animation-event.sls
f37e8832eb5a1e430717ac72de2ebfa2f2343e73
[]
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
3,453
sls
animation-event.sls
(library (unity-engine animation-event) (export new is? animation-event? data-get data-set! data-update! string-parameter-get string-parameter-set! string-parameter-update! float-parameter-get float-parameter-set! float-parameter-update! int-parameter-get int-parameter-set! int-parameter-update! object-reference-parameter-get object-reference-parameter-set! object-reference-parameter-update! function-name-get function-name-set! function-name-update! time-get time-set! time-update! message-options-get message-options-set! message-options-update! is-fired-by-legacy? is-fired-by-animator? animation-state animator-state-info animator-clip-info) (import (ironscheme-clr-port)) (define-syntax new (lambda (e) (syntax-case e () ((_ a ...) #'(clr-new UnityEngine.AnimationEvent a ...))))) (define (is? a) (clr-is UnityEngine.AnimationEvent a)) (define (animation-event? a) (clr-is UnityEngine.AnimationEvent a)) (define-field-port data-get data-set! data-update! (property:) UnityEngine.AnimationEvent data System.String) (define-field-port string-parameter-get string-parameter-set! string-parameter-update! (property:) UnityEngine.AnimationEvent stringParameter System.String) (define-field-port float-parameter-get float-parameter-set! float-parameter-update! (property:) UnityEngine.AnimationEvent floatParameter System.Single) (define-field-port int-parameter-get int-parameter-set! int-parameter-update! (property:) UnityEngine.AnimationEvent intParameter System.Int32) (define-field-port object-reference-parameter-get object-reference-parameter-set! object-reference-parameter-update! (property:) UnityEngine.AnimationEvent objectReferenceParameter UnityEngine.Object) (define-field-port function-name-get function-name-set! function-name-update! (property:) UnityEngine.AnimationEvent functionName System.String) (define-field-port time-get time-set! time-update! (property:) UnityEngine.AnimationEvent time System.Single) (define-field-port message-options-get message-options-set! message-options-update! (property:) UnityEngine.AnimationEvent messageOptions UnityEngine.SendMessageOptions) (define-field-port is-fired-by-legacy? #f #f (property:) UnityEngine.AnimationEvent isFiredByLegacy System.Boolean) (define-field-port is-fired-by-animator? #f #f (property:) UnityEngine.AnimationEvent isFiredByAnimator System.Boolean) (define-field-port animation-state #f #f (property:) UnityEngine.AnimationEvent animationState UnityEngine.AnimationState) (define-field-port animator-state-info #f #f (property:) UnityEngine.AnimationEvent animatorStateInfo UnityEngine.AnimatorStateInfo) (define-field-port animator-clip-info #f #f (property:) UnityEngine.AnimationEvent animatorClipInfo UnityEngine.AnimatorClipInfo))
true
6067cf7fcfab060a22265ce75dbbb301fb63b245
c95b424d826780d088a1e797db26717c8b335669
/examples/puzzle.scm
35fc229acb3f9146bb4a7b7b5145b2b914742a63
[]
no_license
kdltr/ezd
c6bb38ef25c22030f09dc4be9bc2bdec2a575242
2e372a159903d674d29b5b3f32e560d35fcac397
refs/heads/master
2021-01-13T17:02:40.005029
2020-01-26T11:09:23
2020-01-26T11:11:28
76,651,078
7
1
null
null
null
null
UTF-8
Scheme
false
false
1,757
scm
puzzle.scm
;;; A simple 4x4 puzzle game. Click on a tile to move it into the ;;; adjacent empty space. Type control-c to exit. ;;; ;;; To run this program: ;;; ;;; csc -s puzzle.scm (import (chicken format) ezd) (define (puzzle pause) (define (control-c-exit) (if (equal? (list->string (list (integer->char 3))) (car *user-event-misc*)) (ezd '(quit)))) (ezd `(window puzzle ,puzzle-size ,puzzle-size fixed-size) '(set-drawing puzzle) '(overlay puzzle puzzle) `(object backing (fill-rectangle 0 0 ,puzzle-size ,puzzle-size white)) `(when * keypress ,control-c-exit)) (draw-puzzle) (if pause (ezd '(pause)))) (define tile-size 40) (define (tile->pixel x) (+ (* (+ x 1) 5) (* x tile-size))) (define puzzle-size (tile->pixel 4)) (define (draw-puzzle) (define zero-x 0) (define zero-y 0) (define (draw-tile x y tile) (let ((tile-name (string->symbol (format "TILE~s" tile)))) (define (draw-tile) (ezd `(object ,tile-name (fill-rectangle ,(tile->pixel x) ,(tile->pixel y) ,tile-size ,tile-size blue) (text ,(tile->pixel x) ,(tile->pixel y) ,tile-size ,tile-size center center ,(format "~s" tile) white "8x13bold")))) (define (clicker) (when (= (+ (abs (- x zero-x)) (abs (- y zero-y))) 1) (let ((zx zero-x) (zy zero-y)) (set! zero-x x) (set! zero-y y) (set! x zx) (set! y zy)) (draw-tile))) (draw-tile) (ezd `(click ,tile-name 1 ,clicker)))) (let ((tiles (list 10 15 12 3 13 8 7 1 2 14 6 4 9 5 11))) (do ((x 0 (+ x 1))) ((= x 4)) (do ((y (if (= x 0) 1 0) (+ y 1))) ((= y 4)) (draw-tile x y (car tiles)) (set! tiles (cdr tiles)))))) (puzzle #t)
false
100828fad6d0a0e260d6e2b1b19128d33831f503
84bd214ba2422524b8d7738fb82dd1b3e2951f73
/02/2.36_accumulate-n.scm
941cae2da52e5fdf2d4dcc5c85d2f6ea50dccfce
[]
no_license
aequanimitas/sicp-redux
e5ef32529fa727de0353da973425a326e152c388
560b2bd40a12df245a8532de5d76b0bd2e033a64
refs/heads/master
2020-04-10T06:49:13.302600
2016-03-15T00:59:24
2016-03-15T00:59:24
21,434,389
1
0
null
null
null
null
UTF-8
Scheme
false
false
143
scm
2.36_accumulate-n.scm
(define (accumulate initial combiner seq) (if (null? seq) initial (combiner (car seq) (accumulate initial combiner (cdr seq)))))
false
e3d350bbf06fa952ac07ec343d9c2671fa6fafb1
5355071004ad420028a218457c14cb8f7aa52fe4
/3.5/e-3.78.scm
67a673a28367693b3c2682c2f0172e267547eb88
[]
no_license
ivanjovanovic/sicp
edc8f114f9269a13298a76a544219d0188e3ad43
2694f5666c6a47300dadece631a9a21e6bc57496
refs/heads/master
2022-02-13T22:38:38.595205
2022-02-11T22:11:18
2022-02-11T22:11:18
2,471,121
376
90
null
2022-02-11T22:11:19
2011-09-27T22:11:25
Scheme
UTF-8
Scheme
false
false
938
scm
e-3.78.scm
; Exercise 3.78. ; ; Consider the problem of designing a signal-processing system to study ; the homogeneous second-order linear differential equation ; d^2y/dt^2 - a*dy/dt - by = 0 ; The output stream, modeling y, is generated by a network that contains ; a loop. This is because the value of d2y/dt2 depends upon the values ; of y and dy/dt and both of these are determined by integrating ; d2y/dt2. The diagram we would like to encode is shown in figure 3.35. ; Write a procedure solve-2nd that takes as arguments the constants a, ; b, and dt and the initial values y0 and dy0 for y and dy/dt and ; generates the stream of successive values of y. ; ------------------------------------------------------------ (define (solve-2nd a b dt y0 dy0) (define y (integral (delay dy) y0 dt)) (define dy (integral (delay ddy) dy0 dt)) (define ddy (add-streams (scale-stream dy a) (scale-stream y b))) y)
false
90a7cdef9ba997b5eb78ee965c515cf9c7604401
bdcc255b5af12d070214fb288112c48bf343c7f6
/autodiff-examples/eg2.sps
812b54037ee74bc967082c1d0eab8f3398690f6e
[]
no_license
xaengceilbiths/chez-lib
089af4ab1d7580ed86fc224af137f24d91d81fa4
b7c825f18b9ada589ce52bf5b5c7c42ac7009872
refs/heads/master
2021-08-14T10:36:51.315630
2017-11-15T11:43:57
2017-11-15T11:43:57
109,713,952
5
1
null
null
null
null
UTF-8
Scheme
false
false
269
sps
eg2.sps
#!chezscheme (import (scheme base) (scheme write) (autodiff stochastic-scheme)) (write (distribution (draw '((1 . 0.25) (2 . 0.25) (3 . 0.25))))) (newline) (write (probability (distribution (draw '((#t . 0.25) (#f . 0.25) (a . 0.25)))))) (newline)
false
19423eec3613d4f3ccc879fb424ec648b18a284b
defeada37d39bca09ef76f66f38683754c0a6aa0
/mscorlib/system/reflection/method-base.sls
61951ec05dcf9e58ffdd80edc2d4aa0ae6d821cf
[]
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
4,992
sls
method-base.sls
(library (system reflection method-base) (export is? method-base? get-generic-arguments invoke get-current-method get-method-from-handle get-method-body get-parameters get-method-implementation-flags method-handle attributes calling-convention is-public? is-private? is-family? is-assembly? is-family-and-assembly? is-family-or-assembly? is-static? is-final? is-virtual? is-hide-by-sig? is-abstract? is-special-name? is-constructor? contains-generic-parameters? is-generic-method-definition? is-generic-method?) (import (ironscheme-clr-port)) (define (is? a) (clr-is System.Reflection.MethodBase a)) (define (method-base? a) (clr-is System.Reflection.MethodBase a)) (define-method-port get-generic-arguments System.Reflection.MethodBase GetGenericArguments (System.Type[])) (define-method-port invoke System.Reflection.MethodBase Invoke (System.Object System.Object System.Reflection.BindingFlags System.Reflection.Binder System.Object[] System.Globalization.CultureInfo) (System.Object System.Object System.Object[])) (define-method-port get-current-method System.Reflection.MethodBase GetCurrentMethod (static: System.Reflection.MethodBase)) (define-method-port get-method-from-handle System.Reflection.MethodBase GetMethodFromHandle (static: System.Reflection.MethodBase System.RuntimeMethodHandle System.RuntimeTypeHandle) (static: System.Reflection.MethodBase System.RuntimeMethodHandle)) (define-method-port get-method-body System.Reflection.MethodBase GetMethodBody (System.Reflection.MethodBody)) (define-method-port get-parameters System.Reflection.MethodBase GetParameters (System.Reflection.ParameterInfo[])) (define-method-port get-method-implementation-flags System.Reflection.MethodBase GetMethodImplementationFlags (System.Reflection.MethodImplAttributes)) (define-field-port method-handle #f #f (property:) System.Reflection.MethodBase MethodHandle System.RuntimeMethodHandle) (define-field-port attributes #f #f (property:) System.Reflection.MethodBase Attributes System.Reflection.MethodAttributes) (define-field-port calling-convention #f #f (property:) System.Reflection.MethodBase CallingConvention System.Reflection.CallingConventions) (define-field-port is-public? #f #f (property:) System.Reflection.MethodBase IsPublic System.Boolean) (define-field-port is-private? #f #f (property:) System.Reflection.MethodBase IsPrivate System.Boolean) (define-field-port is-family? #f #f (property:) System.Reflection.MethodBase IsFamily System.Boolean) (define-field-port is-assembly? #f #f (property:) System.Reflection.MethodBase IsAssembly System.Boolean) (define-field-port is-family-and-assembly? #f #f (property:) System.Reflection.MethodBase IsFamilyAndAssembly System.Boolean) (define-field-port is-family-or-assembly? #f #f (property:) System.Reflection.MethodBase IsFamilyOrAssembly System.Boolean) (define-field-port is-static? #f #f (property:) System.Reflection.MethodBase IsStatic System.Boolean) (define-field-port is-final? #f #f (property:) System.Reflection.MethodBase IsFinal System.Boolean) (define-field-port is-virtual? #f #f (property:) System.Reflection.MethodBase IsVirtual System.Boolean) (define-field-port is-hide-by-sig? #f #f (property:) System.Reflection.MethodBase IsHideBySig System.Boolean) (define-field-port is-abstract? #f #f (property:) System.Reflection.MethodBase IsAbstract System.Boolean) (define-field-port is-special-name? #f #f (property:) System.Reflection.MethodBase IsSpecialName System.Boolean) (define-field-port is-constructor? #f #f (property:) System.Reflection.MethodBase IsConstructor System.Boolean) (define-field-port contains-generic-parameters? #f #f (property:) System.Reflection.MethodBase ContainsGenericParameters System.Boolean) (define-field-port is-generic-method-definition? #f #f (property:) System.Reflection.MethodBase IsGenericMethodDefinition System.Boolean) (define-field-port is-generic-method? #f #f (property:) System.Reflection.MethodBase IsGenericMethod System.Boolean))
false
c801dfe020f60a7c72f68a72f5d9d0ea6687f4c3
557c51d080c302a65e6ef37beae7d9b2262d7f53
/workspace/scheme-tester/tests/Y-combinator-trial.scm
e7585b6aca437ec749961984dc9b80d14106e215
[]
no_license
esaliya/SchemeStack
286a18a39d589773d33e628f81a23bcdd0fc667b
dcfa1bbfa63b928a7ea3fc244f305369763678ad
refs/heads/master
2020-12-24T16:24:08.591437
2016-03-08T15:30:37
2016-03-08T15:30:37
28,023,003
3
4
null
null
null
null
UTF-8
Scheme
false
false
616
scm
Y-combinator-trial.scm
; if we can give the factorial function to the following function then we can compute factorials (lambda (!) (lambda (n) (if (zero? n) 1 (* n (! (sub1 n)))))) ; this will be Y and the input will be the function define above and will output a factorial function (((lambda (r) ((lambda (f) (f f) (lambda (f) ))) ) (lambda (!) (lambda (n) (if (zero? n) 1 (* n (! (sub1 n)))))) ) 5) ;--------------- (define fact-gen (lambda (fact-in) (lambda (n) (if (zero? n) 1 (* n (fact-in (- n 1)))))))
false
83176c308260a8b901826a299932a13691ee0322
d3e9eecbf7fa7e015ab8b9c357882763bf6d6556
/solutions/exercises/3.28-3.32.ss
66e2c1f1f3a0d60f37bd164310f88ad91f25cf90
[]
no_license
yangchenyun/learning-sicp
37d43f18836055274f78755ff93eb20fba63d383
99a19a06eddc282e0eb364536e297f27c32a9145
refs/heads/master
2021-01-19T02:15:15.634140
2017-02-13T22:26:58
2017-02-13T22:26:58
5,344,488
17
3
null
null
null
null
UTF-8
Scheme
false
false
5,329
ss
3.28-3.32.ss
#lang r5rs (require r5rs) ;; Exercise 3.28 (define (or-gate a1 a2 output) (define (or-action-procedure) (let ((new-value (logical-or (get-signal a1) (get-signal a2)))) (after-delay or-gate-delay (lambda () (set-signal! output new-value))))) (add-action! a1 or-action-procedure) (add-action! a2 or-action-procedure) 'ok) ;; Exercise 3.29 ;; (or a b) ;; equals to (not (and (not a) (not b))) (define (or-gate a1 a2 output) (let ((a1-inverted (make-wire)) (a2-inverted (make-wire)) (and-result (make-wire))) (inverter a1 a1-inverted) (inverter a2 a2-inverted) (and-gate a1-inverted a2-inverted and-result) (inverter and-result output))) ;; or-delay = 3 * inverter-delay + and-gate-delay ;; Exercise 3.30 ;; helper functional methods (define (reverse l) (if (null? l) '() (append (reverse (cdr l)) (list (car l))))) (define (fold proc init . lists) (define (any-head-null? lists) (define (and-reduce list) (cond ((null? list) #t) ((car list) (and-reduce (cdr list))) (else #f))) (if (null? lists) #t (and-reduce (map null? lists)))) (if (any-head-null? lists) init (let ((result (apply proc init (map car lists)))) (apply fold proc result (map cdr lists))))) (define (fold-right proc init . lists) (apply fold proc init (map reverse lists))) ;; http://d.hatena.ne.jp/tanakaBox/20080512/1210588399 (define (number->list n . base) (letrec ((b (if (null? base) 10 (car base))) (iter (lambda (acc n) (let ((q (quotient n b)) (m (cons (modulo n b) acc))) (if (zero? q) m (iter m q)))))) (iter '() n))) (define (list->number l . base) (letrec ((b (if (null? base) 10 (car base))) (iter (lambda (l cont) (if (null? l) (cont 0 0) (iter (cdr l) (lambda (sum k) (cont (+ (* (car l) (expt b k)) sum) (+ k 1)))))))) (iter l (lambda (sum k) sum)))) (define (number->wire n . base) (map (lambda (x) (let ((w (make-wire))) (set-signal! w x) w)) (number->list n (car base)))) (define (ripple-carry-adder awires bwires) (define (align-binary-padding awires bwires) (if (>= (length awires) (length bwires)) awires (align-binary-padding (cons (make-wire) awires) bwires))) (let ((res (fold-right (lambda (acc a b) (let ((carry (make-wire)) (sum (make-wire))) (full-adder a b (car acc) sum carry) (cons carry (cons sum (cdr acc))))) (list (make-wire)) (align-binary-padding awires bwires) (align-binary-padding bwires awires)))) (propagate) res)) ;; keep the last carry (let ((a (number->wire 2 2)) (b (number->wire 8 2))) (list->number (map get-signal (ripple-carry-adder a b)) 2)) ;; a half-adder delay is or-gate + 2*and-gate + inverter ;; a full-adder delay is 2 * half-adder + or-gate ;; = 3*or-gate 4*and-gate + 2*inverter ;; so ripple-carry-adder delay for n-bit is: 3n*or-gate 4n*and-gate + 2n*inverter ;; Exercise 3.31 (define (half-addder a b s c) (let ((d (make-wire)) (e (make-wire))) (or-gate a b d) (and-gate a b c) (and-gate d e s) (inverter c e) 'ok)) ;; when a half-adder runs, `add-action!' is called in the following sequence ;; or-gate (add-action! a or-action-procedure) (add-action! b or-action-procedure) ;; and-gate (add-action! a and-action-procedure) (add-action! b and-action-procedure) (add-action! d and-action-procedure) (add-action! e and-action-procedure) ;; inverter (add-action! c invert-input) ;; in the case of definition in the book, the callback will run immediately ;; when it is defined and set the correct initial input and output ;; Without the initialization, the function box will remain incorrect until some ;; changes happened to a wire ;; Exercise 3.32 ;; (define (and-gate a1 a2 output) ;; (define (and-action-procedure) ;; (let ((new-value ;; (logical-and (get-signal a1) (get-signal a2)))) ;; (after-delay and-gate-delay ;; (lambda () (set-signal! output new-value))))) ;; (add-action! a1 and-action-procedure) ;; (add-action! a2 and-action-procedure) ;; 'ok) (define i0 (make-wire)) (define i1 (make-wire)) (define output (make-wire)) (define and-gate-delay 2) (and-gate i0 i1 output) ;; (add-action! i0 and-proc-cbk) ;; (add-action! i1 and-proc-cbk) (set-signal! i0 0) (set-signal! i1 1) (propagate) (set-signal! i0 1) (set-signal! i1 0) ;; the callback in the agenda queue will be as below ;; in a FIFO, this will be executed from first to last, which is correct ;; i0 i1 callback ;; 0 1 0 ;; 1 1 1 (set-signal! output 1) ;; 1 0 1 (set-signal! output 0) ;; in a LIFO, the callbacks will be executed from last to first, so ;; the final result will be 1 which is incorrect
false
2cec3168daf328c991a0e13772ede7edb56d2f24
710bd922d612840b3dc64bd7c64d4eefe62d50f0
/scheme/scheme-runtime/module.scm
1ab68568dd01f1f3bbbf7027bc5f9059f7117b3e
[ "MIT" ]
permissive
prefics/scheme
66c74b93852f2dfafd4a95e04cf5ec6b06057e16
ae615dffa7646c75eaa644258225913e567ff4fb
refs/heads/master
2023-08-23T07:27:02.254472
2023-08-12T06:47:59
2023-08-12T06:47:59
149,110,586
0
0
null
null
null
null
UTF-8
Scheme
false
false
7,931
scm
module.scm
;;; module.scm -- module system for Scheme (define-record-type :module (make-module name export open doc defined syntax) module? (name module/name set-module/name!) (export module/export set-module/export!) (open module/open set-module/open!) (doc module/doc set-module/doc!) (defined module/defined set-module/defined!) (syntax module/syntax set-module/syntax!)) ;;; Module ================================================================= (define *modules* '()) (define (modules) (append *modules* '())) (define (module-names) (map (lambda (b) (car b)) *modules*)) (define (bind-module! name module) (let ((entry (assq name *modules*))) (if entry (set-cdr! entry module) (set! *modules* (cons (cons name module) *modules*))))) (define (unbind-module! name) (set! *modules* (let loop ((modules *modules*)) (if (null? modules) modules (if (eq? name (caar modules)) (loop (cdr modules)) (cons (car modules) (loop (cdr modules)))))))) (define (lookup-module name) (let ((module (assq name *modules*))) (if module (cdr module) #f))) (define *module-providers* '()) (define (require module-name) (let lp ((providers *module-providers*)) (cond ((null? providers) (error "module ~a not found" module-name)) ((pair? providers) (let ((m ((car providers) module-name))) (if m (let ((cm (current-module))) (set-module/open! cm (cons module-name (module/open cm))) m) (lp (cdr providers))))) (else (error "internal error in *module-providers*"))))) (define (add-module-provider provider) (set! *module-providers* (cons provider *module-providers*))) (define (delete-module-provider provider) (set! *module-providers* (let lp ((mps *module-providers*)) (cond ((null? mps) mps) ((pair? mps) (let ((p (car mps))) (if (eq? p provider) (cdr mps) (cons p (lp (cdr mps)))))) (else (error "internal error in *module-providers*")))))) (define (module-providers) (append *module-providers* '())) (define $module$ (make-fluid #f)) (define (with-current-module module proc) (let-fluid $module$ module proc)) (define (current-module) (fluid $module$)) (define (current-module-name) (module/name (current-module))) (define (in-module name) (let ((module (lookup-module name))) (if module (set-fluid! $module$ module) (error "module ~a does not exists in the image" name)))) ;;; Bindings ============================================================== (define (lookup-imported-binding name module) (let loop ((module-names (module/open module))) (if (null? module-names) #f (let* ((module-name (car module-names)) (module (lookup-module module-name)) (found? (memq name (module/export module)))) (if found? ;; (lookup-binding name module) (lookup-ref name module-name) (loop (cdr module-names))))))) (define (lookup-binding name module) ; (write-channel (make-channel 1) "LOOKING-BINDING") ; (write-channel (make-channel 1) name) ; (write-channel (make-channel 1) module) (let loop ((refs (module/defined module))) (if (null? refs) #f (if (eq? name (ref/name (car refs))) (car refs) (loop (cdr refs)))))) (define (bind-ref! name value module) (let ((ref (make-ref name (module/name module) value))) (set-module/defined! module (cons ref (module/defined module))) ref)) (define (unbind-ref! name module) (set-module/defined! module (let loop ((refs (module/defined module))) (if (null? refs) refs (if (eq? (ref/name (car refs)) name) (loop (cdr refs)) (cons (car refs) (loop (cdr refs)))))))) (define (lookup-ref name module-name) (let* ((module (lookup-module module-name))) ; (write-channel (make-channel 1) "LOOKUP-REF") ; (write-channel (make-channel 1) module-name) (if module (let ((ref (lookup-binding name module))) (if ref ref (lookup-imported-binding name module))) (error "Unknown module ~a" module-name)))) (define (lookup/create-ref name module) ; (display "LOOKUP/CREATE-BINDING") (let ((module (if (symbol? module) (lookup-module module) module))) (let ((binding (lookup-binding name module))) ; (display binding) (if binding binding (let ((binding* (lookup-imported-binding name module))) ; (display binding*) (if binding* binding* (let ((ref (make-ref name (module/name module) 'the-unbound-object))) ; (display "creating new ref") (set-module/defined! module (cons ref (module/defined module))) ref))))))) (define (bound? name) (let ((binding (lookup-binding name (current-module)))) (and binding (not (eq? (ref/value binding) (unbound-object)))))) ;;; REF ============================================================================ (define (ref/name ref) (ref-name ref)) (define (ref/module ref) (ref-module ref)) (define (ref/value ref) (ref-value ref)) (define (set-ref/name! ref name) (set-ref-name! ref name)) (define (set-ref/module! ref module) (set-ref-module! ref module)) (define (set-ref/value! ref value) (set-ref-value! ref value)) ;;; SYNTAX ========================================================================= (define (assq* e l) (if (pair? l) (if (eq? e (caar l)) (car l) (assq* e (cdr l))) #f)) (define (make-syntax transformer env) (vector 'syntax transformer env)) (define (syntax? exp) (and (vector? exp) (eq? 'syntax (vector-ref exp 0)))) (define (syntax/env mac) (vector-ref mac 2)) (define (syntax/transformer mac) (vector-ref mac 1)) (define (bind-syntax! name syntax module) (let* ((syntaxes (module/syntax module)) (entry (assq* name syntaxes))) (if entry (set-cdr! entry syntax) (set-module/syntax! module (cons (cons name syntax) syntaxes))))) (define (unbind-syntax! name module) (set-module/syntax! module (let loop ((syntax (module/syntax module))) (if (pair? syntax) (if (eq? name (caar syntax)) (loop (cdr syntax)) (cons (car syntax) (loop (cdr syntax)))) syntax)))) (define (exported-syntax? name module-name) (let* ((module (lookup-module module-name)) (interface (module/export module))) (let loop ((i interface)) (if (null? i) #f (let ((export-name (car i))) (if (and (pair? export-name) (eq? (car export-name) name) (eq? ':syntax (cadr export-name))) #t (loop (cdr i)))))))) (define (lookup-imported-syntax name module) (let loop ((module-names (module/open module))) (if (null? module-names) #f (let* ((module-name (car module-names))) (if (exported-syntax? name module-name) (let* ((module (lookup-module module-name)) (syn (assq* name (module/syntax module)))) (if syn (cdr syn) (loop (cdr module-names)))) (loop (cdr module-names))))))) (define (lookup-syntax name module-name) (let ((module (lookup-module module-name))) (if module (let ((syntax (assq* name (module/syntax module)))) (if syntax (cdr syntax) (lookup-imported-syntax name module))) (error "inexistant module named ~a" module-name)))) ;;; PRIMITIVE ============================================================ (define (primitive? o) (and (vector? o) (eq? 'primitive (vector-ref o 0)))) (define (make-primitive name transformer) (vector 'primitive name transformer)) (define (primitive/name o) (vector-ref o 1)) (define (primitive/transformer o) (vector-ref o 2))
false
78d7ba64e8f52621bec45c5c46332f8738ec2823
b0c1935baa1e3a0b29d1ff52a4676cda482d790e
/tests/t-parser.scm
df08befa97210aef2e69c6d6f2c87242ac2c22e5
[ "MIT" ]
permissive
justinethier/husk-scheme
35ceb8f763a10fbf986340cb9b641cfb7c110509
1bf5880b2686731e0870e82eb60529a8dadfead1
refs/heads/master
2023-08-23T14:45:42.338605
2023-05-17T00:30:56
2023-05-17T00:30:56
687,620
239
28
MIT
2023-05-17T00:30:07
2010-05-26T17:02:56
Haskell
UTF-8
Scheme
false
false
964
scm
t-parser.scm
#| ;; ;; husk-scheme ;; http://github.com/justinethier/husk-scheme ;; ;; Written by Justin Ethier ;; ;; Test cases to validate husk's scheme parser ;; ;; ;; #| a nested block comment |# |# (unit-test-start "parser") (assert/equal (+ 1 2 #| commenting, la, la, la|# 3) 6) (define a 3) a 3 (assert/equal (+ 1 2) 3) (assert/equal ( + 1 2) 3) (assert/equal (+ 1 2 ) 3) (assert/equal ( + 1 2 ) 3) (assert/equal '(a 4) '( a 4 )) (assert/equal '(2 4) '(2 4)) (assert/equal '(2 . 4) '( 2 . 4)) (assert/equal '(a . 4) '( a . 4 )) (assert/equal '((a b) . c) '( (a b) . c)) (assert/equal ;assert/equal x '(a . 4) '(a . 4) ) ; Cases related to issue #41 (assert/equal '(1 2 . 3) '(1 . (2 . 3))) (assert/equal '(1 2 . ()) '(1 . (2 . ()))) (assert/equal '(1 2 . (3 . ())) '(1 2 3)) (assert/equal (list 1 . (1 2 3)) '(1 1 2 3)) (unit-test-handler-results)
false
a53633ff5d6360009aa0bdb397145bdd4a5ece64
58381f6c0b3def1720ca7a14a7c6f0f350f89537
/Chapter 4/4.1/4.01.scm
7f9d57a32c5445af48d82b2ac3f424fcd49e16c4
[]
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
477
scm
4.01.scm
#lang planet neil/sicp (define (list-of-values exps env) (if (no-operands? exps) '() (let ((left (eval (first-operand exps) env))) (cons left (list-of-values (rest-operands exps) env))))) ; right-to-left evaluation (define (list-of-values exps env) (if (no-operands? exps) '() (let ((right (list-of-values (rest-operand exps) env))) (cons (eval (first-operand exps) env) right))))
false
919b1778459b35ab90fd3744e02645a8d413a6ac
6b5618fe9412ac9c1fb94a24a2e4ebd1838a763d
/wak/testeez/utils.sls
6c75576fd826804567a385bcfb7e8ecc6a3c7eef
[]
no_license
okuoku/htmlparse
d959f9589b8d04d1f09400eb3df153324608f68e
e2e88932b1bdc5e2254dd4a66026b6f3a81a803e
refs/heads/master
2021-01-15T11:48:17.368503
2011-08-12T20:20:02
2011-08-12T20:20:02
2,200,602
1
0
null
null
null
null
UTF-8
Scheme
false
false
422
sls
utils.sls
#!r6rs (library (wak testeez utils) (export object->string format-exception) (import (rnrs base) (rnrs io ports) (rnrs io simple) (rnrs conditions) (spells include)) (define (format-exception e) (cond ((condition? e) (map object->string (simple-conditions e))) (else (list (object->string e))))) (include-file ((wak testeez scheme) obj2str)))
false
d5001f1cac45ea507a6b9c091ec43480df86ab98
4bd59493b25febc53ac9e62c259383fba410ec0e
/Scripts/Task/return-multiple-values/scheme/return-multiple-values-1.ss
6c39bd4b12c3663458b625d53d5790028fc95127
[]
no_license
stefanos1316/Rosetta-Code-Research
160a64ea4be0b5dcce79b961793acb60c3e9696b
de36e40041021ba47eabd84ecd1796cf01607514
refs/heads/master
2021-03-24T10:18:49.444120
2017-08-28T11:21:42
2017-08-28T11:21:42
88,520,573
5
1
null
null
null
null
UTF-8
Scheme
false
false
49
ss
return-multiple-values-1.ss
(define (addsub x y) (values (+ x y) (- x y)))
false
1f96ce1c041138242ce3d900c375943cb3398689
abc7bd420c9cc4dba4512b382baad54ba4d07aa8
/src/experimental/expander_chez.ss
17f647ce0c239736b50ff826541d7eb77107ebb7
[ "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
614
ss
expander_chez.ss
(define file->slist (lambda (filename) (let ([p (open-input-file filename)]) (let loop ([exp (read p)]) (if (eof-object? exp) (begin (close-port p) '()) (cons exp (loop (read p)))))))) (define exprs (file->slist "main_chez.ss")) ;; Don't use map because it doesn't guarantee order: (define (map-serial f ls) (let loop ((ls ls) (acc '())) (if (null? ls) (reverse! acc) (loop (cdr ls) (cons (f (car ls)) acc))))) (define expanded (map-serial expand exprs)) (slist->file expanded "main_chez_EXPANDED.ss") (display "File written.")(newline)
false
b9f68cc4de2d8224c79e42d8e88761b707e2a785
ea4dce153f81182f91366f999a419927db665a9c
/scratch.ss
3bda163d446d7b5540ea2b29f326b2a188969b39
[]
no_license
lackhoa/kara
a76546dd392509c081cc52673859b6bcf35b559c
3e20a44c30eb3a5a7ce10a05ffcbb65d0ef3ca64
refs/heads/master
2021-06-27T10:52:58.139154
2019-04-25T07:35:46
2019-04-25T07:35:46
139,874,561
1
0
null
null
null
null
UTF-8
Scheme
false
false
2,592
ss
scratch.ss
(define alpha-equiv? (lambda (e1 e2) (let alpha ([e1 e1] [e2 e2] [xs '()] [ys '()]) (pmatch `(,e1 ,e2) [(,x ,y) (guard (var? x) (var? y)) (pmatch `(,(assq x xs) ,(assq y ys)) [(#f #f) (eq? x y)] [((? ,b1) (? ,b2)) (eq? b1 b2)] [(? ?) #f])] [((forall ,x ,b1) (forall ,y ,b2)) (let ([fresh (gensym)]) (let ([xs `((,x ,fresh) ,@xs)] [ys `((,y ,fresh) ,@ys)]) (alpha b1 b2 xs ys)))] [((,fun1 . ,args1) (,fun2 . ,args2)) (and (eq? fun1 fun2) (= (length args1) (length args2)) (let ([alpha (lambda (arg1 arg2) (alpha arg1 arg2 xs ys))]) (andmap alpha args1 args2)))] [(,c1 ,c2) (eq? c1 c2)])))) (define pat-match (lambda (pat term) (let pat-match ([pat pat] [term term] [S '()]) (cond [(var? pat) (pmatch (assq pat S) [(,pat ,t) (and (equal? term t) S)] [#f `((,pat ,term) ,@S)])] [(and (pair? pat) (pair? term)) (let ([S (pat-match (car pat) (car term) S)]) (and S (pat-match (cdr pat) (cdr term) S)))] [(eq? pat term) S] [else #f])))) (define fill (lambda (pat S) (let fill ([pat pat]) (cond [(var? pat) (pmatch (assq pat S) [(,pat ,res) res] [else (error 'fill "A weird situation!" pat S)])] [(pair? pat) `(,(fill (car pat)) ,@(fill (cdr pat)))] [else pat])))) (define rewrite-outer (lambda (f g) (let rewrite-outer ([g g]) (pmatch g [(forall ? ,g) `(forall ,x ,(rewrite-outer g))] [(-> ,f ,g) `(-> ,(rewrite-outer f) ,(rewrite-outer g))] [(,pred . ,args) (let ([rule (rip f)]) (pmatch rule [(= ,l ,r) (rewrite-core l r `(,pred ,@(map (lambda (t) (rewrite-core t)) args)))] [else (error 'rewrite "Not a rewrite rule" rule)]))])))) (define rewrite-core (lambda (l r t) (let rewrite-core ([t t]) (let ([S (pat-match l t)]) (let ([t (if S (fill r S) t)]) (pmatch t [(,fun . ,args) `(,fun ,@(map rewrite-core args))] [,x x])))))) (define rewrite (lambda (f) (lambda (env) (let ([g (local-g env)]) ((go (assert (rewrite-core f g)) done) env))))) (define rip (lambda (f) (pmatch f [(forall ,? ,g) (rip g)] [else f])))
false
591013c9ee8c26b254a8511291212626a784ef12
99f659e747ddfa73d3d207efa88f1226492427ef
/datasets/srfi/srfi-158/r7rs-shim.scm
af0b8097cb802008a27c428feb17a887f1f051a8
[ "MIT" ]
permissive
michaelballantyne/n-grams-for-synthesis
241c76314527bc40b073b14e4052f2db695e6aa0
be3ec0cf6d069d681488027544270fa2fd85d05d
refs/heads/master
2020-03-21T06:22:22.374979
2018-06-21T19:56:37
2018-06-21T19:56:37
138,215,290
0
0
MIT
2018-06-21T19:51:45
2018-06-21T19:51:45
null
UTF-8
Scheme
false
false
875
scm
r7rs-shim.scm
(define *eof-object* (read (open-input-string ""))) (define (eof-object) *eof-object*) (define (make-bytevector n fill) (make-u8vector n fill)) (define (bytevector . args) (apply u8vector args)) (define (bytevector-u8-set! bv i val) (u8vector-set! bv i val)) (define (bytevector-u8-ref bv i) (u8vector-ref bv i)) (define (bytevector-length bv) (u8vector-length bv)) (define (truncate/ n1 n2) (values (quotient n1 n2) (remainder n1 n2))) ;; trivial version of make-list (define (make-list n fill) (let loop ((n n) (result '())) (if (<= n 0) result (loop (- n 1) (cons fill result))))) ;; trivial version of string-for-each (define (string-for-each proc string) (let ((len (string-length string))) (let loop ((i 0)) (cond ((< i len) (proc (string-ref string i)) (loop (+ i 1))) (else (if #f #f))))))
false
7d92d1606ba8c93444bbf472b362ffab539910b9
bcfa2397f02d5afa93f4f53c0b0a98c204caafc1
/scheme/chapter2/ex2_28.scm
55edd5d939b230b1b344150a82ebd9cfbcce5b34
[]
no_license
rahulkumar96/sicp-study
ec4aa6e1076b46c47dbc7a678ac88e757191c209
4dcd1e1eb607aa1e32277e1c232a321c5de9c0f0
refs/heads/master
2020-12-03T00:37:39.576611
2017-07-05T12:58:48
2017-07-05T12:58:48
96,050,670
0
0
null
2017-07-02T21:46:09
2017-07-02T21:46:09
null
UTF-8
Scheme
false
false
605
scm
ex2_28.scm
;; SICP 2.28 ;; Exercise 2.28. Write a procedure fringe that takes as argument a ;; tree (represented as a list) and returns a list whose elements are ;; all the leaves of the tree arranged in left-to-right order. For ;; example, ;; (define x (list (list 1 2) (list 3 4))) ;; (fringe x) ;; (1 2 3 4) ;; (fringe (list x x)) ;; (1 2 3 4 1 2 3 4) ;; ANSWER ------------------------------------------------------------ (define (fringe items) (cond ((null? items) ()) ((not (pair? items)) (list items)) (else (append (fringe (car items)) (fringe (cdr items))))))
false
6d9ddaed076494a91403a2ef1c5f34752b7d8540
7c2c9c7aa33d90cbcbef8523f6c3a6211218c21b
/chapter09.scm
77a6a01a26170ee057295d174b80622629c0e79f
[]
no_license
hkoktay/the-little-schemer
c738d293a0bbf47985130664253e596ad17dccc8
007e25153a4721a0cd6007c83cc8ce1305f6cf2a
refs/heads/master
2020-04-03T13:02:17.979217
2018-11-07T13:11:36
2018-11-07T13:11:36
155,272,030
10
3
null
null
null
null
UTF-8
Scheme
false
false
16,602
scm
chapter09.scm
;; Chapter 9: ...and Again, and Again and Again,... ;; ;; A [pora] is an ;; - atom or ;; - pair ;; ;; A [sorn] is a ;; - symbol or ;; - [number] (load "test-check.scm") ;; atom?: any -> boolean (define atom? (lambda (x) (and (not (pair? x)) (not (null? x))))) ;; add1: [number] -> [number] ;; Chapter 4 (define add1 (lambda (n) (+ n 1))) ;; sub1: [number] -> [number] ;; Chapter 4 (define sub1 (lambda (n) (- n 1))) ;; o+: [number] [number] -> [number] ;; Returns the addition of 'n' and 'm' ;; ;; Page 60, Chapter 4 (define o+ (lambda (n m) (cond ((zero? m) n) (else (add1 (o+ n (sub1 m))))))) (test "o+" (o+ 2 7) 9) (test "o+" (o+ 2 0) 2) ;; o*: [number] [number] -> [number] ;; Returns the result of the multiplication of 'n' and 'm'. ;; ;; Page 65, Chapter 4 (define o* (lambda (n m) (cond ((zero? m) 0) (else (o+ n (o* n (sub1 m))))))) (test "o*" (o* 12 3) 36) (test "o*" (o* 12 0) 0) (test "o*" (o* 0 3) 0) ;; pick: [number] [lat] -> [atom] ;; Returns the 'n'-th atom of 'lat'. ;; Example: ;; (pick 2 '(a b c d e)) -> b ;; ;; Page 76 (define pick (lambda (n lat) (cond ((zero? (sub1 n)) (car lat)) (else (pick (sub1 n) (cdr lat)))))) (test "pick" (pick 4 '(lasagne spaghetti ravioli macaroni meatball)) 'macaroni) (test "pick" (pick 5 '(lasagne spaghetti ravioli macaroni meatball)) 'meatball) (test "pick" (pick 6 '(6 2 4 cavier 5 7 3)) 7) (test "pick" (pick 7 '(6 2 4 cavier 5 7 3)) 3) ;; keep-looking: [sorn] -> boolean ;; Uses the numbers in 'lat' as indices to recur over 'lat'. ;; This is an unnatural recursion because keep-looking does not recur ;; on a part of lat. ;; ;; Page 150 (define keep-looking (lambda (a sorn lat) (cond ((number? sorn) (keep-looking a (pick sorn lat) lat)) (else (eq? sorn a))))) (test "keep-looking" (keep-looking 'cavier 3 '(6 2 4 cavier 5 7 3)) #t) (test "keep-looking" (keep-looking 'cavier 3 '(6 2 4 cavier 5 7 3)) #t) ;; looking: [atom] [lat] -> boolean ;; looking is a partial function. The functions we have seen so far ;; are called total functions. ;; ;; Page 149 (define looking (lambda (a lat) (keep-looking a (pick 1 lat) lat))) (test "looking" (looking 'cavier '(6 2 4 cavier 5 7 3)) #t) (test "looking" (looking 'cavier '(6 2 grits cavier 5 7 3)) #f) ;; Never ending loop ;; (test "looking" ;; (looking 'cavier '(7 1 2 cavier 5 6 3)) 'does-not-stop) ;; eternity: any -> any ;; eternity is the "most" partial function. It reaches its goal for ;; none of its arguments. (define eternity (lambda (x) (eternity x))) ;; build: [s-exp] [s-exp] -> [pair] ;; Page 119, Chapter 7 (define build (lambda (s1 s2) (cons s1 (cons s2 '())))) (test "build" (build 1 2) '(1 2)) ;; first: [pair] -> [s-exp] ;; Page 119, Chapter 7 (define first (lambda (p) (car p))) (test "first" (first '(1 2)) 1) ;; second: [pair] -> [s-exp] ;; Page 119, Chapter 7 (define second (lambda (p) (car (cdr p)))) (test "second" (second '(1 2)) 2) ;; shift: (list [pair] [s-exp]) -> [pair] ;; Takes a (list [pair] [s-exp]) whose first component is a pair and makes a new ;; pair by shifting the second part of the first component into the ;; second component. ;; ;; Examples: ;; (shift '((a b) (c d))) ;; -> (a (b (c d))) ;; (shift '((a b) c)) ;; -> (a (b c)) (define shift (lambda (pair) (build (first (first pair)) (build (second (first pair)) (second pair))))) (test "shift" (shift '((a b) c)) '(a (b c))) (test "shift" (shift '((a b) (c d))) '(a (b (c d)))) ;; a-pair?: any -> boolean ;; Page 118, Chapter 7 (define a-pair? (lambda (l) (cond ((atom? l) #f) ((null? l) #f) ((null? (cdr l))#f) ((null? (cdr (cdr l))) #t) (else #f)))) (test "a-pair?" (a-pair? '(pear pear)) #t) (test "a-pair?" (a-pair? '(3 7)) #t) (test "a-pair?" (a-pair? '((2) (pair))) #t) (test "a-pair?" (a-pair? '()) #f) (test "a-pair?" (a-pair? '()) #f) (test "a-pair?" (a-pair? 'a) #f) ;; align: [pora] -> [pair] ;; Recursivly 'shifts' pairs in 'pora. ;; In the second cond-line shift creates an argument for align that ;; is not a part of the orignal argument, so it is not guaranteed ;; that align makes progress. This violates the seventh commandment. ;; Align is not a partial function because it yields a value for ;; every argument. (define align (lambda (pora) (cond ((atom? pora) pora) ((a-pair? (first pora)) (align (shift pora))) (else (build (first pora) (align (second pora))))))) ;; length*: [pora] -> [number] ;; Page 153 (define length* (lambda (pora) (cond ((atom? pora) 1) (else (o+ (length* (first pora)) (length* (second pora))))))) (test "length*" (length* '(a b)) 2) (test "length*" (length* 'a) 1) (test "length*" (length* '(a (b c))) 3) ;; weight*: [pora] -> [number] ;; Examples: ;; (weight* '((a b) c)) ;; -> 7 ;; (weight* '(a (b c))) ;; -> 5 ;; ;; Page 154 (define weight* (lambda (pora) (cond ((atom? pora) 1) (else (o+ (o* (weight* (first pora)) 2) (weight* (second pora))))))) (test "weight*" (weight* '((a b) c)) 7) (test "weight*" (weight* '(a (b c))) 5) ;; revpair: [pair] -> [pair] ;; Returns a pair with its elements reversed ;; ;; Page 121, Chapter 7 (define revpair (lambda (p) (build (second p) (first p)))) (test "revpair" (revpair '((a b) (c d))) '((c d) (a b))) ;; shuffle: [pora] -> [pora] ;; Like align but implemented with revpair. ;; ;; Examples: ;; (shuffle '(a (b c))) -> (a (b c)) ;; ;; Page 154 (define shuffle (lambda (pora) (cond ((atom? pora) pora) ((a-pair? (first pora)) (shuffle (revpair pora))) (else (build (first pora) (shuffle (second pora))))))) (test "shuffle" (shuffle '(a (b c))) '(a (b c))) (test "shuffle" (shuffle '(a b)) '(a b)) ;; one?: [number] -> boolean ;; Returns #t if 'n' is 1, else #f ;; Page 79, Chapter 4 (define one? (lambda (n) (= n 1))) (test "one?" (one? 3) #f) (test "one?" (one? 0) #f) (test "one?" (one? 1) #t) ;; o-: [number] [number] -> [number] ;; Returns the subtractions of 'n' and 'm' ;; ;; Page 61, Chapter 4 (define o- (lambda (n m) (cond ((zero? m) n) (else (sub1 (o- n (sub1 m))))))) (test "o-" (o- 5 2) 3) ;; o<: [number] [number] -> boolean ;; Returns #t if n is smaller than m, else #f- ;; ;; Page 73, Chapter 4 (define o< (lambda (n m) (cond ((zero? m) #f) ((zero? n) #t) (else (o< (sub1 n) (sub1 m)))))) (test "o<" (o< 2 4) #t) (test "o<" (o< 4 2) #f) (test "o<" (o< 2 2) #f) ;; oquotient: [number] [number] -> [number] ;; Division of 'n' and 'm'. ;; Example: ;; (oquotient 15 4) -> 3 ;; ;; Page 75, Chapter 4 (define oquotient (lambda (n m) (cond ((o< n m) 0) (else (add1 (oquotient (o- n m) m)))))) (test "oquotient" (oquotient 15 4) 3) (test "oquotient" (oquotient 15 4) 3) (test "oquotient" (oquotient 1 1) 1) ;; C: [number] -> void ;; Page 155 (define C (lambda (n) (cond ((one? n) 1) (else (cond ((even? n) (C (oquotient n 2))) (else (C (add1 (o* 3 n))))))))) ;; [number] [number] -> void ;; Examples: ;; (A 1 0) -> 2 ;; (A 1 1) -> 3 ;; (A 2 2) -> 7 ;; A is a total function because it gives always an answer. ;; (A 4 3) -> takes too long to compute ;; ;; Page 156 (define A (lambda (n m) (cond ((zero? n) (add1 m)) ((zero? m) (A (sub1 n) 1)) (else (A (sub1 n) (A n (sub1 m))))))) (test "A" (A 1 1) 3) (test "A" (A 2 2) 7) ;; The Halting Problem ;; ------------------- ;; ;; Page 157 ;; ;; will-stop?: fun -> boolean ;; Note this is only a hypothetical function not a real one. ;; Returns #t if function 'f' will stop or #f if 'f' will never stop. ;; (define (will-stop? f) ;; ...) ;; ;; Example: ;; (will-stop? eternity) -> would be #f ;; ;; (define (last-try x) ;; (and (will-stop? last-try) ;; (eternity x))) ;; ;; Application of last-try: ;; (last-try '()) ;; ;; The value of (last-try '()) depends on the expression: ;; (and (will-stop? last-try) (eternity '())) ;; And the value of this expression depends on the value of ;; (will-stop? last-try) ;; ;; The value of (will-stop? last-try) can either be #t or #f. ;; 1. (will-stop? last-try) -> #f ;; => (and #f (eternity '())) ;; => #f ;; ;; Thus last-try stopped but this is in conflict with the value of ;; (will-stop? last-try) which was #f, which means that last-try ;; should *not* stop. ;; ;; 2. (will-stop? last-try) -> #t ;; => (and #t (eternity '())) ;; => does not stop ;; ;; This is again in conflict with the result of (will-stop? last-try) ;; which should be #t, meaning that last-try should stop. ;; ;; Conclusion ;; ;; The function will-stop? cannot be defined. In other words you ;; cannot define a function which tests if a function will stop. ;; length0: [listof sexp] -> [number] ;; Determines the length of the empty list. ;; This function gives no answer for non-empty lists. ;; (lambda (l) ;; (cond ;; ((null? l) 0) ;; (else (add1 (eternity (cdrl)))))) ;; ;; You can try this with engines. Engines are a high-level process abstraction ;; supporting timed preemption. You can use engines to run a function a specific ;; amount of time. If the computation of the engine finishes before the "fuel" ;; runs out, it returns the amount of fuel left and the values of the ;; computation. If the fuel runs out (the number of ticks), it returns #t. Thus ;; this test returns always #t, because the engine runs always out of ticks and ;; returns #t. No matter how much ticks the engine gets the computation never ;; finishes, because (eternity (cdr l) never finishes. Try it out by changing ;; the amount of fuel. ;; ;; You can get more information about engines in the chez scheme documentation: ;; https://cisco.github.io/ChezScheme/csug9.5/control.html#./control:h4 (test "length0" (letrec ((e (make-engine (lambda () ((lambda (l) (cond ((null? l) 0) ;; (eternity (cdr l)) runs forever so add1 is never ;; called. (else (add1 (eternity (cdr l)))))) '(1 2 3)))))) ;; We supply the engine with 100 ticks (e 100 list (lambda (eng) #t))) #t) (test "length0" ((lambda (l) (cond ((null? l) 0) (else (add1 (eternity (cdr l)))))) '()) 0) ;; length<=1: [listof sexp] -> [number] ;; (lambda (l) ;; (cond ;; ((null? l) 0) ;; (else ;; (add1 ;; ;; length0 ;; ((lambda (l) ;; (cond ;; ((null? l) 0) ;; (else (add1 (eternity (cdr l)))))) ;; (cdr l)))))) ;; lenght<=2: [listof sexp] -> [number] ;; (lambda (l) ;; (cond ;; ((null? l) 0) ;; (else ;; (add1 ;; ;; length<=1 ;; ((lambda (l) ;; (cond ;; ((null? l) 0) ;; (else ;; (add1 ;; ;; length0 ;; ((lambda (l) ;; (cond ;; ((null? l) 0) ;; (else ;; (add1 (eternity (cdr l)))))) ;; (cdr l)))))) ;; (cdr l)))))) ;; length0: fun -> fun ;; ((lambda (length) ;; (lambda (l) ;; (cond ;; ((null? l) 0) ;; (else (add1 (length (cdr l))))))) ;; eternity) ;; length<=1: fun -> fun ;; ((lambda (f) ;; (lambda (l) ;; (cond ;; ((null? l) 0) ;; (else (add1 (f (cdr l))))))) ;; ((lambda (g) ;; (lambda (l) ;; (cond ;; ((null? l) 0) ;; (else (add1 (g (cdr l))))))) ;; eternity)) ;; length<=2: fun -> fun ;; ((lambda (length) ;; (lambda (l) ;; (cond ;; ((null? l) 0) ;; (else (add1 (length (cdr l))))))) ;; ((lambda (length) ;; (lambda (l) ;; (cond ;; ((null? l) 0) ;; (else (add1 (length (cdr l))))))) ;; ((lambda (length) ;; (lambda (l) ;; (cond ;; ((null? l) 0) ;; (else (add1 (length (cdr l))))))) ;; eternity))) ;; mk-length, length0 ;; ((lambda (mk-length) ;; (mk-length eternity)) ;; (lambda (length) ;; (lambda (l) ;; (cond ;; ((null? l) 0) ;; (else (add1 (length (cdr l)))))))) ;; make-lenght, length<=1 ;; ((lambda (mk-length) ;; (mk-length ;; (mk-length eternity))) ;; (lambda (length) ;; (lambda (l) ;; (cond ;; ((null? l) 0) ;; (else (add1 (length (cdr l)))))))) ;; make-length, length<=2 ;; ((lambda (mk-length) ;; (mk-length ;; (mk-length ;; (mk-length eternity)))) ;; (lambda (length) ;; (lambda (l) ;; (cond ;; ((null? l) 0) ;; (else (add1 (length (cdr l)))))))) ;; make-length, length<=3 ;; ((lambda (mk-length) ;; (mk-length ;; (mk-length ;; (mk-length ;; (mk-length eternity))))) ;; (lambda (length) ;; (lambda (l) ;; (cond ;; ((null? l) 0) ;; (else (add1 (length (cdr l)))))))) ;; make-length, length0 ;; ((lambda (mk-length) ;; (mk-length mk-length)) ;; (lambda (mk-length) ;; (lambda (l) ;; (cond ;; ((null? l) 0) ;; (else (add1 (mk-length (cdr l)))))))) ;; mk-length, length<=1 ;; ;; ((lambda (mk-length) ;; (mk-length mk-length)) ;; (lambda (mk-length) ;; (lambda (l) ;; (cond ;; ((null l) 0) ;; (else ;; (add1 ((mk-length eternity) (cdr l)))))))) ;; Example ;; Page 166 ;; ;; (((lambda (mk-length) ;; (mk-length mk-length)) ;; (lambda (mk-length) ;; (lambda (l) ;; (cond ;; ((null? l) 0) ;; (else ;; (add1 ((mk-length eternity) (cdr l)))))))) ;; '(apples)) ;; Apply mk-length to itself ;; ;; ((lambda (mk-length) ;; (mk-length mk-length)) ;; (lambda (mk-length) ;; (lambda (l) ;; (cond ;; ((null l) 0) ;; (else (add1 ((mk-length mk-length) ;; (cdr l)))))))) ;; Simplification ;; Page 167 ;; ;; ((lambda (mk-length) ;; (mk-length mk-length)) ;; (lambda (mk-length) ;; ((lambda (length) ;; (lambda (l) ;; (cond ;; ((null? l) 0) ;; (else (add1 (length (cdr l))))))) ;; (mk-length mk-length)))) ;; Application of this function does not end! ;; ;; (((lambda (mk-length) ;; (mk-length mk-length)) ;; (lambda (mk-length) ;; ((lambda (length) ;; (lambda (l) ;; (cond ;; ((null? l) 0) ;; (else (add1 (length (cdr l))))))) ;; (mk-length mk-length)))) ;; '(apples)) ;; ((lambda (mk-length) ;; (mk-length mk-length)) ;; (lambda (mk-length) ;; (lambda (l) ;; (cond ;; ((null? l 0)) ;; (else ;; (add1 ;; ((lambda (x) ;; ((mk-length mk-length)) x) ;; (cdr l)))))))) ;; Page 171 ;; ((lambda (mk-length) ;; (mk-length mk-length)) ;; (lambda (mk-length) ;; ((lambda (length) ;; (lambda (l) ;; (cond ;; ((null? l 0)) ;; (else ;; (add1 (length (cdr l))))))) ;; (lambda (x) ;; ((mk-length mk-length)) x)))) ;; Abstraction of the "length" lambda ;; Page 172 ;; ;; ((lambda (le) ;; ((lambda (mk-length) ;; (mk-length mk-length)) ;; (lambda (mk-length) ;; (le (lambda (x) ;; ((mk-length mk-length) x)))))) ;; (lambda (length) ;; (lambda (l) ;; (cond ;; ((null? l) 0) ;; (else (add1 (length (cdr l)))))))) ;; The "le" lambda ;; ;; (lambda (le) ;; ((lambda (mk-length) ;; (mk-length mk-length)) ;; (lambda (mk-length) ;; (le (lambda (x) ;; ((mk-length mk-length) x)))))) ;; The applicative-order Y combinator ;; Page 172 (define Y (lambda (le) ((lambda (f) (f f)) (lambda (f) (le (lambda (x) ((f f) x))))))) (test "Y" ((Y (lambda (length) (lambda (l) (cond ((null? l) 0) (else (add1 (length (cdr l)))))))) '(a b c)) 3) (test "Y" ((Y (lambda (length) (lambda (l) (cond ((null? l) 0) (else (add1 (length (cdr l)))))))) '(a b c d e f)) 6) (test "Y" ((Y (lambda (leftmost) (lambda (l) (cond ((atom? l) l) (else (leftmost (car l))))))) '((potato) (chips ((with) fish) (chips)))) 'potato)
false
226a23ac66dab39a78caeabd44787625d9d1d82b
710e486f87b70e57cc3c2a411d12c30644544b75
/show/base.sld
fd18523a297006cbb6c4963035ffd8b01bc85804
[ "BSD-3-Clause", "MIT", "LicenseRef-scancode-unknown-license-reference", "BlueOak-1.0.0" ]
permissive
ar-nelson/schemepunk
6236a3200343257a9ce15a6e3f4bda1dd450c729
249bf057b256bbb9212f60345a84d84615c61893
refs/heads/master
2021-05-18T07:47:36.721609
2021-04-24T17:05:48
2021-04-24T17:05:48
251,185,680
92
7
NOASSERTION
2021-05-12T14:07:38
2020-03-30T02:53:33
Scheme
UTF-8
Scheme
false
false
23,314
sld
base.sld
(define-library (schemepunk show base) (export show each each-in-list displayed written written-shared written-simply escaped maybe-escaped numeric numeric/comma numeric/si numeric/fitted nl fl space-to tab-to nothing joined joined/prefix joined/suffix joined/last joined/dot joined/range padded padded/right padded/both trimmed trimmed/right trimmed/both trimmed/lazy fitted fitted/right fitted/both fn with with! forked call-with-output make-state-variable port row col width output writer string-width substring/width pad-char ellipsis radix precision decimal-sep decimal-align sign-rule comma-rule comma-sep word-separator? ambiguous-is-wide? break-into-spans? span-generator->formatter call-with-output-generator) (cond-expand (chicken (import (except (scheme base) string-length substring string make-string) (only (utf8) string-length substring string make-string))) (else (import (scheme base)))) (import (scheme case-lambda) (scheme char) (scheme write) (schemepunk syntax) (schemepunk function) (schemepunk list) (schemepunk string) (schemepunk generator) (schemepunk comparator) (schemepunk mapping) (schemepunk box) (schemepunk show span) (schemepunk show block) (schemepunk show block datum) (schemepunk show numeric) (schemepunk show terminal-width)) (begin (define-record-type State-Variable (%make-state-variable name index immutable) state-variable? (name state-variable-name) (index state-variable-index) (immutable state-variable-immutable?)) (define state-variable-comparator (make-comparator state-variable? eq? (λ(x y) (< (state-variable-index x) (state-variable-index y))) state-variable-index)) (define next-state-variable-index 0) (define default-state-variables (mapping state-variable-comparator)) (define+ (make-state-variable name default :optional (immutable #f)) (define var (%make-state-variable name next-state-variable-index immutable)) (set! next-state-variable-index (+ 1 next-state-variable-index)) (mapping-set! default-state-variables var (box default)) var) (define string-width-default (case-lambda ((str) (string-length str)) ((str start) (- (string-length str) start)) ((str start end) (- end start)))) (define+ (substring-default str start :optional (end (string-length str))) (substring str start end)) (define port (make-state-variable "port" (current-output-port))) (define row (make-state-variable "row" 0)) (define col (make-state-variable "col" 0)) (define width (make-state-variable "width" 80)) (define string-width (make-state-variable "string-width" string-width-default)) (define substring/width (make-state-variable "substring/width" substring-default)) (define pad-char (make-state-variable "pad-char" #\space)) (define ellipsis (make-state-variable "ellipsis" "")) (define radix (make-state-variable "radix" 10)) (define precision (make-state-variable "precision" #f)) (define decimal-sep (make-state-variable "decimal-sep" #\.)) (define decimal-align (make-state-variable "decimal-align" 0)) (define sign-rule (make-state-variable "sign-rule" #f)) (define comma-rule (make-state-variable "comma-rule" #f)) (define comma-sep (make-state-variable "comma-sep" #\,)) (define word-separator? (make-state-variable "word-separator?" char-whitespace?)) (define ambiguous-is-wide? (make-state-variable "ambiguous-is-wide?" #f)) (define break-into-spans? (make-state-variable "break-into-spans?" #f)) (define (copy-vars vars) (mapping-map/monotone (λ(k v) (values k (box (unbox v)))) state-variable-comparator vars)) (define (get-var vars var) (unbox (mapping-ref vars var))) (define state-variables (make-parameter default-state-variables)) (define (track-position vars gen) (let ((string-width (get-var vars string-width)) (row (mapping-ref vars row)) (col (mapping-ref vars col))) (gmap (λ x (case (span-type x) ((newline) (update-box! row (cut + <> (chain (span-text x) (string->list _) (count (is _ eqv? #\newline) _)))) (set-box! col 0)) (else (update-box! col (cut + <> (string-width (span-text x)))))) x) gen))) (define-syntax span-generator->formatter (syntax-rules () ((_ gen) (lambda (vars) (track-position vars gen))))) (define (output-default str) (λ vars (chain (if (get-var vars break-into-spans?) (char-generator->span-generator (cute read-char (open-input-string str)) (get-var vars word-separator?)) (chain (string-split str "\n") (map text-span _) (intercalate (newline-span) _) (list->generator _))) (span-generator->formatter _) (_ vars)))) (define output (make-state-variable "output" output-default)) (define (%with state-variable value fmt) (λ vars (fmt (mapping-set vars state-variable (box value))))) (define (%with! state-variable value) (if (state-variable-immutable? state-variable) (error "state variable is immutable" (state-variable-name state-variable)) (set-box! (mapping-ref (state-variables) state-variable) value))) (define-syntax %fn (syntax-rules () ((_ vars ((id state-var) . rest) . body) (let1 id (get-var vars state-var) (%fn vars rest . body))) ((_ vars (id . rest) . body) (let1 id (get-var vars id) (%fn vars rest . body))) ((_ vars () exprs ... fmt) (begin exprs ... (fmt vars))))) (define (%show vars output-port fmt) (parameterize ((state-variables (mapping-set! vars port (box output-port)))) (generator-for-each (cut write-span <> (get-var vars port)) (fmt vars)))) (define-syntax with (syntax-rules () ((_ () . fmts) (each . fmts)) ((_ ((var val) . rest) . fmts) (%with var val (with rest . fmts))))) (define-syntax with! (syntax-rules () ((_ (var val) ...) (begin (%with! var val) ...)))) (define-syntax fn (syntax-rules () ((_ (bindings ...) exprs ... fmt) (λ vars (parameterize ((state-variables vars)) (%fn vars (bindings ...) exprs ... fmt)))))) (define (show output-dest . fmts) (define vars (chain (copy-vars default-state-variables) (mapping-set! _ width (box (get-terminal-width))))) (define fmt (each-in-list fmts)) (case output-dest ((#t) (%show vars (current-output-port) fmt)) ((#f) (let1 str (open-output-string) (%show vars str fmt) (get-output-string str))) (else (%show vars output-dest fmt)))) (define (each . fmts) (each-in-list fmts)) (define (each-in-list list-of-fmts) (define (get-fmt fmt) (if (procedure? fmt) fmt (displayed fmt))) (assume (or (null? list-of-fmts) (pair? list-of-fmts))) (match list-of-fmts (() nothing) ((fmt) (get-fmt fmt)) (else (λ vars (let ((gen ((get-fmt (car list-of-fmts)) vars)) (fmts (cdr list-of-fmts))) (λ () (let loop ((next (gen))) (if (and (eof-object? next) (pair? fmts)) (begin (set! gen ((get-fmt (car fmts)) vars)) (set! fmts (cdr fmts)) (loop (gen))) next)))))))) (define+ (joined mapper xs :optional (sep "")) (chain (map mapper xs) (intercalate sep _) (each-in-list _))) (define+ (joined/prefix mapper xs :optional (sep "")) (each-in-list (append-map (λ x (list sep (mapper x))) xs))) (define+ (joined/suffix mapper xs :optional (sep "")) (each-in-list (append-map (λ x (list (mapper x) sep)) xs))) (define+ (joined/last mapper last-mapper xs :optional (sep "")) (if (null? xs) nothing (chain (last-mapper (last xs)) (snoc (map mapper (drop-right xs 1)) _) (intercalate sep _) (each-in-list _)))) (define+ (joined/dot mapper dot-mapper xs :optional (sep "")) (let loop ((out '()) (xs xs)) (cond ((null? xs) (chain (reverse out) (intercalate sep _) (each-in-list _))) ((pair? xs) (loop (cons (mapper (car xs)) out) (cdr xs))) (else (chain (cons (dot-mapper xs) out) (reverse _) (intercalate sep _) (each-in-list _)))))) (define+ (joined/range mapper start :optional (end #f) (sep "")) (define last (and (number? end) (- end 1))) (λ vars (chain (make-range-generator start end) (gmap (λ i (chain (if (= i last) (each (mapper i)) (each (mapper i) sep)) (_ vars))) _) (generator-fold (flip gappend) (generator) _)))) (define (displayed obj) (cond ((string? obj) (λ vars (((get-var vars output) obj) vars))) ((char? obj) (λ vars (((get-var vars output) (string obj)) vars))) (else (written obj)))) (define (written obj) (span-generator->formatter (block->span-generator (datum->block obj)))) (define writer (make-state-variable "writer" written)) (define (written-shared obj) (span-generator->formatter (block->span-generator (datum->block/shared obj)))) (define (written-simply obj) (span-generator->formatter (block->span-generator (datum->block/simple obj)))) (define (nl vars) (update-box! (mapping-ref vars row) (cut + <> 1)) (set-box! (mapping-ref vars col) 0) (generator (newline-span))) (define (fl vars) (if (zero? (get-var vars col)) (generator) (nl vars))) (define (space-to column) (assume (nonnegative-integer? column)) (λ vars (let1 current-column (get-var vars col) (if (< current-column column) (begin (set-box! (mapping-ref vars col) column) (generator (whitespace-span (make-string (- column current-column) (get-var vars pad-char))))) (generator))))) (define+ (tab-to :optional (tab-width 8)) (assume (nonnegative-integer? tab-width)) (λ vars (let* ((current-column (get-var vars col)) (offset (remainder current-column tab-width)) (tab (- tab-width offset))) (if (zero? offset) (generator) (begin (set-box! (mapping-ref vars col) (+ current-column tab)) (generator (whitespace-span (make-string tab (get-var vars pad-char))))))))) (define (nothing _) (generator)) (define (escape str quote-ch esc-ch renamer) (with-output-to-string (λ() (with-input-from-string str (λ() (let loop ((ch (read-char))) (cond ((eof-object? ch) #f) ((eqv? quote-ch ch) (if esc-ch (write-char esc-ch) (write-char ch)) (write-char ch) (loop (read-char))) ((not esc-ch) (write-char ch) (loop (read-char))) ((eqv? esc-ch ch) (write-char esc-ch) (write-char ch) (loop (read-char))) ((renamer ch) => (λ renamed (write-char esc-ch) (write-char renamed) (loop (read-char)))) (else (write-char ch) (loop (read-char)))))))))) (define+ (escaped str :optional (quote-ch #\") (esc-ch #\\) (renamer (const #f))) (assume (string? str)) (assume (char? quote-ch)) (assume (or (not esc-ch) (char? esc-ch))) (assume (procedure? renamer)) (displayed (escape str quote-ch esc-ch renamer))) (define+ (maybe-escaped str pred? :optional (quote-ch #\") (esc-ch #\\) (renamer (const #f))) (assume (string? str)) (assume (procedure? pred?)) (call/cc (λ return (string-for-each (λ ch (when (or (eqv? quote-ch ch) (eqv? esc-ch ch) (pred? ch)) (return (each quote-ch (escaped str quote-ch esc-ch renamer) quote-ch)))) str) (displayed str)))) (define+ (numeric num :optional (radix/arg #f) (precision/arg #f) (sign-rule/arg #f) (comma-rule/arg #f) (comma-sep/arg #f) (decimal-sep/arg #f)) (assume (number? num)) (λ vars (chain (numeric->string num (or radix/arg (get-var vars radix)) (or precision/arg (get-var vars precision)) (or sign-rule/arg (get-var vars sign-rule)) (or comma-rule/arg (get-var vars comma-rule)) (or comma-sep/arg (get-var vars comma-sep)) (or decimal-sep/arg (get-var vars decimal-sep)) (get-var vars decimal-align)) (displayed _) (_ vars)))) (define+ (numeric/comma num :optional (comma-rule 3) (radix #f) (precision #f) (sign-rule #f)) (numeric num radix precision sign-rule comma-rule)) (define+ (numeric/si num :optional (base 1000) (separator "")) (assume (number? num)) (assume (or (= base 1000) (= base 1024))) (assume (string? separator)) (λ vars (chain (numeric->string/si num base separator (get-var vars radix) (get-var vars precision) (get-var vars sign-rule) (get-var vars comma-rule) (get-var vars comma-sep) (get-var vars decimal-sep) (get-var vars decimal-align)) (displayed _) (_ vars)))) (define (numeric/fitted width num . args) (assume (number? num)) (assume (nonnegative-integer? width)) (call-with-output (apply numeric num args) (λ str (if (is (string-length str) > width) (fn (precision decimal-sep comma-sep) (let ((prec (if (and (pair? args) (pair? (cdr args))) (cadr args) precision))) (if (and prec (not (zero? prec))) (let* ((dec-sep (or decimal-sep (if (eqv? #\. comma-sep) #\, #\.))) (diff (- width (+ prec (if (char? dec-sep) 1 (string-length dec-sep)))))) (each (if (positive? diff) (make-string diff #\#) "") dec-sep (make-string prec #\#))) (displayed (make-string width #\#))))) (displayed str))))) (define (fork-width vars width fmts) (let1-values (gen gen/length) (gfork ((each-in-list fmts) vars)) (values gen (unindented-length gen/length (+ width 1) (get-var vars string-width))))) (define (padded width . fmts) (assume (nonnegative-integer? width)) (λ vars (let1-values (gen actual-width) (fork-width vars width fmts) (if (is actual-width < width) (chain (- width actual-width) (make-string _ (get-var vars pad-char)) (whitespace-span _) (generator _) (gappend _ gen)) gen)))) (define (padded/right width . fmts) (assume (nonnegative-integer? width)) (λ vars (let1-values (gen actual-width) (fork-width vars width fmts) (if (is actual-width < width) (chain (- width actual-width) (make-string _ (get-var vars pad-char)) (whitespace-span _) (generator _) (gappend gen _)) gen)))) (define (padded/both width . fmts) (assume (nonnegative-integer? width)) (λ vars (let1-values (gen actual-width) (fork-width vars width fmts) (if (is actual-width < width) (let* ((pad (- width actual-width)) (half-pad (quotient pad 2)) (ch (get-var vars pad-char))) (gappend (generator (whitespace-span (make-string half-pad ch))) gen (generator (whitespace-span (make-string (- pad half-pad) ch))))) gen)))) (define (trimmed width . fmts) (assume (nonnegative-integer? width)) (call-with-output (each-in-list fmts) (λ str (λ vars (let* ((string-width (get-var vars string-width)) (substring/width (get-var vars substring/width)) (actual-width (string-width str))) ((displayed (if (is actual-width > width) (let* ((ellipsis (get-var vars ellipsis)) (ellipsis-width (string-width ellipsis))) (string-append ellipsis (substring/width str (- actual-width (- width ellipsis-width)) actual-width))) str)) vars)))))) (define (trimmed/right width . fmts) (assume (nonnegative-integer? width)) (call-with-output (each-in-list fmts) (λ str (λ vars (let* ((string-width (get-var vars string-width)) (substring/width (get-var vars substring/width)) (actual-width (string-width str))) ((displayed (if (is actual-width > width) (let* ((ellipsis (get-var vars ellipsis)) (ellipsis-width (string-width ellipsis))) (string-append (substring/width str 0 (- width ellipsis-width)) ellipsis)) str)) vars)))))) (define (trimmed/both width . fmts) (assume (nonnegative-integer? width)) (call-with-output (each-in-list fmts) (λ str (λ vars (let* ((string-width (get-var vars string-width)) (substring/width (get-var vars substring/width)) (actual-width (string-width str))) ((displayed (if (is actual-width > width) (let* ((ellipsis (get-var vars ellipsis)) (ellipsis-width (string-width ellipsis)) (pad (- actual-width width (* -2 ellipsis-width))) (half-pad (quotient pad 2))) (string-append ellipsis (substring/width str half-pad (- actual-width (- pad half-pad))) ellipsis)) str)) vars)))))) (define (trimmed/lazy width . fmts) (assume (nonnegative-integer? width)) (λ vars (match-let* ((string-width (get-var vars string-width)) (substring/width (get-var vars substring/width)) ((len spans) (call/cc (λ return (generator-fold (λ(span (len spans)) (if (is len >= width) (return (list len spans)) (list (+ len (string-width (span-text span))) (cons span spans)))) '(0 ()) ((with ((break-into-spans? #t)) (each-in-list fmts)) vars))))) (reverse-trimmed-spans (if (is len > width) (let loop ((len len) (spans spans)) (let1 span-len (string-width (span-text (car spans))) (cond ((is (- len span-len) > width) (loop (- len span-len) (cdr spans))) ((is (- len span-len) = width) (cdr spans)) (else (cons (span-map-text (cut substring/width <> 0 (- span-len (- len width))) (car spans)) (cdr spans)))))) spans))) (list->generator (reverse reverse-trimmed-spans))))) (define (fitted width . fmts) (assume (nonnegative-integer? width)) (call-with-output (padded width (each-in-list fmts)) (cut trimmed width <>))) (define (fitted/right width . fmts) (assume (nonnegative-integer? width)) (call-with-output (padded/right width (each-in-list fmts)) (cut trimmed/right width <>))) (define (fitted/both width . fmts) (assume (nonnegative-integer? width)) (call-with-output (padded/both width (each-in-list fmts)) (cut trimmed/both width <>))) (define (forked fmt1 fmt2) (each (λ vars (fmt1 (copy-vars vars))) fmt2)) (define (call-with-output fmt mapper) (assume (procedure? mapper)) (λ vars (let1 str-port (open-output-string) (%show (copy-vars vars) str-port fmt) ((mapper (get-output-string str-port)) vars)))) (define (call-with-output-generator fmt mapper) (assume (procedure? mapper)) (λ vars ((mapper (fmt (copy-vars vars))) vars)))))
true
44fe4a4d7d3d5f674ae5882fb95e16eb30a13b1e
46a26f8b026f5b7036bebd9d0baaa6edf18bfe12
/tests/logarithm-tests.scm
079625ecc31f88bc438aeaaa2a4c6dff0c5df458
[ "MIT" ]
permissive
pqnelson/calculator
4d8be428e2efc45bb40c0f3f8f193806a6049449
d8fd94703dcbe7917dbcc140fd0f5271093379c4
refs/heads/master
2016-09-05T21:42:41.524941
2014-02-09T17:27:54
2014-02-09T17:27:54
null
0
0
null
null
null
null
UTF-8
Scheme
false
false
77
scm
logarithm-tests.scm
(import "../src/logarithm.scm") (assert (< :ln-2 1)) (assert (> :ln-10 2))
false
222ca724c659c62cb2993b9b8d79b0e3dba87f49
eef5f68873f7d5658c7c500846ce7752a6f45f69
/spheres/structure/fifo.sld
5e27457128de8902cca0d7c66602aacf8a641ac8
[ "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
4,084
sld
fifo.sld
;;!!! FIFO ;; .author Marc Feeley. Copyright (c) 2005-2008 by Marc Feeley, All Rights Reserved. ;; .author Álvaro Castor-Castilla, 2015. Minor modifications and compatibility. (define-library (spheres/structure fifo) (export macro-make-fifo macro-fifo-next macro-fifo-next-set! macro-fifo-tail macro-fifo-tail-set! macro-fifo-elem macro-fifo-elem-set! macro-fifo->list macro-fifo-remove-all! macro-fifo-remove-head! macro-fifo-insert-at-head! macro-fifo-insert-at-tail! macro-fifo-advance! fifo->u8vector fifo->string) (cond-expand (gambit (define-macro (macro-make-fifo) `(let ((fifo (##cons '() '()))) (macro-fifo-tail-set! fifo fifo) fifo)) (define-macro (macro-fifo-next fifo) `(##cdr ,fifo)) (define-macro (macro-fifo-next-set! fifo x) `(##set-cdr! ,fifo ,x)) (define-macro (macro-fifo-tail fifo) `(##car ,fifo)) (define-macro (macro-fifo-tail-set! fifo x) `(##set-car! ,fifo ,x)) (define-macro (macro-fifo-elem fifo) `(##car ,fifo)) (define-macro (macro-fifo-elem-set! fifo x) `(##set-car! ,fifo ,x)) (define-macro (macro-fifo->list fifo) `(macro-fifo-next ,fifo)) (define-macro (macro-fifo-remove-all! fifo) `(let ((fifo ,fifo)) (##declare (not interrupts-enabled)) (let ((head (macro-fifo-next fifo))) (macro-fifo-tail-set! fifo fifo) (macro-fifo-next-set! fifo '()) head))) (define-macro (macro-fifo-remove-head! fifo) `(let ((fifo ,fifo)) (##declare (not interrupts-enabled)) (let ((head (macro-fifo-next fifo))) (if (##pair? head) (let ((next (macro-fifo-next head))) (if (##null? next) (macro-fifo-tail-set! fifo fifo)) (macro-fifo-next-set! fifo next) (macro-fifo-next-set! head '()))) head))) (define-macro (macro-fifo-insert-at-tail! fifo elem) `(let ((fifo ,fifo) (elem ,elem)) (let ((x (##cons elem '()))) (##declare (not interrupts-enabled)) (let ((tail (macro-fifo-tail fifo))) (macro-fifo-next-set! tail x) (macro-fifo-tail-set! fifo x) (##void))))) (define-macro (macro-fifo-insert-at-head! fifo elem) `(let ((fifo ,fifo) (elem ,elem)) (let ((x (##cons elem '()))) (##declare (not interrupts-enabled)) ;; To obtain an atomic update of the fifo, we must force a ;; garbage-collection to occur right away if needed by the ;; ##cons, so that any finalization that might mutate this fifo ;; will be done before updating the fifo. (##check-heap-limit) (let ((head (macro-fifo-next fifo))) (if (##null? head) (macro-fifo-tail-set! fifo x)) (macro-fifo-next-set! fifo x) (macro-fifo-next-set! x head) (##void))))) (define-macro (macro-fifo-advance-to-tail! fifo) `(let ((fifo ,fifo)) ;; It is assumed that the fifo contains at least one element ;; (i.e. the fifo's tail does not change). (let ((new-head (macro-fifo-tail fifo))) (macro-fifo-next-set! fifo new-head) (macro-fifo-elem new-head)))) (define-macro (macro-fifo-advance! fifo) `(let ((fifo ,fifo)) ;; It is assumed that the fifo contains at least two elements ;; (i.e. the fifo's tail does not change). (let* ((head (macro-fifo-next fifo)) (new-head (macro-fifo-next head))) (macro-fifo-next-set! fifo new-head) (macro-fifo-elem new-head)))) (define-macro (fifo->u8vector fifo start end) `(##fifo->u8vector ,fifo ,start ,end)) (define-macro (fifo->string fifo start end) `(##fifo->string ,fifo ,start ,end))) (else (include "fifo.scm"))))
false
68156b3fc0da8a5696b00a8c0c38e39c71e8a522
66face060b57fab316ae7fbfc23af33a683ee9b2
/chez/pr034.ss
52a913481cb9a0d3983e8de6fc71d55a5846054c
[]
no_license
d3zd3z/euler
af56ec84c0cd59f682489dd3b47f713d206ef377
af7365ea58ed317b5c818d8ca7d9df73b961ae18
refs/heads/main
2021-07-09T05:24:05.173898
2021-04-24T23:35:14
2021-04-24T23:35:14
238,053
3
0
null
null
null
null
UTF-8
Scheme
false
false
1,251
ss
pr034.ss
;; Problem 34 ;; ;; 03 January 2003 ;; ;; ;; 145 is a curious number, as 1! + 4! + 5! = 1 + 24 + 120 = 145. ;; ;; Find the sum of all numbers which are equal to the sum of the factorial of ;; their digits. ;; ;; Note: as 1! = 1 and 2! = 2 are not sums they are not included. ;; ;; 40730 (import (rnrs base (6)) (rnrs control (6)) (rnrs io simple (6))) ;;; Return the factorial of a given digit. (define digit-factorial (let () (define (make-facts) (do ([i 1 (+ i 1)] [cur 1 (* cur i)] [cum '() (cons cur cum)]) [(= i 11) (list->vector (reverse cum))])) (define *facts* (make-facts)) (lambda (n) (vector-ref *facts* n)))) (define (euler-34) ;; Start with -3, since the problem states that 1! and 2! are not to ;; be included in the sum. (define total -3) (define last-fact (digit-factorial 9)) (let chain ([number 0] [fact-sum 0]) (when (and (> number 0) (= number fact-sum)) (set! total (+ total number))) (when (<= (* number 10) (+ fact-sum last-fact)) (do ([i (if (positive? number) 0 1) (+ i 1)]) [(= i 10) total] (chain (+ (* number 10) i) (+ fact-sum (digit-factorial i))))))) (define (main) (display (euler-34)) (newline)) (main)
false
b3ad8adc30e1cb86add53193d9c94984d046e197
5fa722a5991bfeacffb1d13458efe15082c1ee78
/src/eval/c4_23.scm
36b4568cbbe29bf654c022196f03a0450a5bc409
[]
no_license
seckcoder/sicp
f1d9ccb032a4a12c7c51049d773c808c28851c28
ad804cfb828356256221180d15b59bcb2760900a
refs/heads/master
2023-07-10T06:29:59.310553
2013-10-14T08:06:01
2013-10-14T08:06:01
11,309,733
3
0
null
null
null
null
UTF-8
Scheme
false
false
390
scm
c4_23.scm
; I've implemented one analyze-sequence in eval1.scm, ; the text has a version of analyze-sequence(analyze-sequence-text in eval1.scm) ; and analyze-sequence-alyssa has a version of analyze-sequence(analyze-sequence-alyssa). ; Of those, analyze-sequence-text and my version are better. Since they try to expand all the sequence ; during the analysis stage(try to add a print func in loop).
false
b9ec25b08d0b41a3cdbadeedcfb35387cec790ab
ec5b4a92882f80b3f62eac8cbd059fb1f000cfd9
/higher-order/!timing/cost-procedures.ss
4ba3b76f2a417e8c74d1a4040f083cb006aee626
[]
no_license
ggem/alpa
ee35ffc91d9f4b1d540ce8b2207595813e488e5f
4f53b888b5a5b4ffebd220c6e0458442325fbff2
refs/heads/master
2019-01-02T03:12:17.899768
2005-01-04T03:43:12
2005-01-04T03:43:12
42,612,681
0
0
null
null
null
null
UTF-8
Scheme
false
false
17,244
ss
cost-procedures.ss
; ; ; (define costs '((ack-c (3 1) (+ (* 4 cost_closure) (* 111 cost_funcall) (* 3 cost_letrec) (* 3 cost_let) (* 62 cost_if) (* 277 cost_varref) (* 171 cost_const) (* 62 cost_equal) (* 50 cost_minus) (* 48 cost_plus))) (ack-c (3 5) (+ (* 4 cost_closure) (* 42443 cost_funcall) (* 3 cost_letrec) (* 3 cost_let) (* 21346 cost_if) (* 105989 cost_varref) (* 63787 cost_const) (* 21346 cost_equal) (* 21098 cost_minus) (* 21096 cost_plus))) (ack-c (3 7) (+ (* 4 cost_closure) (* 693969 cost_funcall) (* 3 cost_letrec) (* 3 cost_let) (* 347492 cost_if) (* 1734421 cost_varref) (* 1041459 cost_const) (* 347492 cost_equal) (* 346478 cost_minus) (* 346476 cost_plus))) (ack-c (3 9) (+ (* 4 cost_closure) (* 11164375 cost_funcall) (* 3 cost_letrec) (* 3 cost_let) (* 5584230 cost_if) (* 27908901 cost_varref) (* 16748603 cost_const) (* 5584230 cost_equal) (* 5580146 cost_minus) (* 5580144 cost_plus))) (ack (3 1) (+ (* 106 cost_funcall) (* 164 cost_if) (* 472 cost_varref) (* 328 cost_const) (* 164 cost_equal) (* 105 cost_minus) (* 48 cost_plus))) (ack (3 5) (+ (* 42438 cost_funcall) (* 63780 cost_if) (* 190848 cost_varref) (* 127560 cost_const) (* 63780 cost_equal) (* 42437 cost_minus) (* 21096 cost_plus))) (ack (3 7) (+ (* 693964 cost_funcall) (* 1041452 cost_if) (* 3122332 cost_varref) (* 2082904 cost_const) (* 1041452 cost_equal) (* 693963 cost_minus) (* 346476 cost_plus))) (ack (3 9) (+ (* 11164370 cost_funcall) (* 16748596 cost_if) (* 50237624 cost_varref) (* 33497192 cost_const) (* 16748596 cost_equal) (* 11164369 cost_minus) (* 5580144 cost_plus))) (cpstak (19 8 1) (+ (* 1560185 cost_closure) (* 3640430 cost_funcall) cost_letrec (* 2080245 cost_if) (* 16121904 cost_varref) (* 1560183 cost_const) (* 2080245 cost_lessthan) (* 1560183 cost_minus))) (cpstak (19 9 1) (+ (* 4503698 cost_closure) (* 10508627 cost_funcall) cost_letrec (* 6004929 cost_if) (* 46538205 cost_varref) (* 4503696 cost_const) (* 6004929 cost_lessthan) (* 4503696 cost_minus))) (cpstak (19 9 3) (+ (* 249896 cost_closure) (* 583089 cost_funcall) cost_letrec (* 333193 cost_if) (* 2582251 cost_varref) (* 249894 cost_const) (* 333193 cost_lessthan) (* 249894 cost_minus))) (cpstak (19 10 1) (+ (* 11872268 cost_closure) (* 27701957 cost_funcall) cost_letrec (* 15829689 cost_if) (* 122680095 cost_varref) (* 11872266 cost_const) (* 15829689 cost_lessthan) (* 11872266 cost_minus))) (fix (10) (+ (* 212 cost_closure) (* 233 cost_funcall) (* 11 cost_if) (* 275 cost_varref) (* 22 cost_const) (* 11 cost_equal) (* 10 cost_minus) (* 10 cost_plus))) (fix (20) (+ (* 422 cost_closure) (* 463 cost_funcall) (* 21 cost_if) (* 545 cost_varref) (* 42 cost_const) (* 21 cost_equal) (* 20 cost_minus) (* 20 cost_plus))) (fix (50) (+ (* 1052 cost_closure) (* 1153 cost_funcall) (* 51 cost_if) (* 1355 cost_varref) (* 102 cost_const) (* 51 cost_equal) (* 50 cost_minus) (* 50 cost_plus))) (fix (100) (+ (* 2102 cost_closure) (* 2303 cost_funcall) (* 101 cost_if) (* 2705 cost_varref) (* 202 cost_const) (* 101 cost_equal) (* 100 cost_minus) (* 100 cost_plus))) (fix (200) (+ (* 4202 cost_closure) (* 4603 cost_funcall) (* 201 cost_if) (* 5405 cost_varref) (* 402 cost_const) (* 201 cost_equal) (* 200 cost_minus) (* 200 cost_plus))) (fix (500) (+ (* 10502 cost_closure) (* 11503 cost_funcall) (* 501 cost_if) (* 13505 cost_varref) (* 1002 cost_const) (* 501 cost_equal) (* 500 cost_minus) (* 500 cost_plus))) (fix (1000) (+ (* 21002 cost_closure) (* 23003 cost_funcall) (* 1001 cost_if) (* 27005 cost_varref) (* 2002 cost_const) (* 1001 cost_equal) (* 1000 cost_minus) (* 1000 cost_plus))) (fix (2000) (+ (* 42002 cost_closure) (* 46003 cost_funcall) (* 2001 cost_if) (* 54005 cost_varref) (* 4002 cost_const) (* 2001 cost_equal) (* 2000 cost_minus) (* 2000 cost_plus))) (index (10) (+ (* 12 cost_closure) (* 21 cost_funcall) cost_letrec (* 21 cost_if) (* 72 cost_varref) (* 11 cost_const) (* 9 cost_plus) (* 10 cost_eq) (* 11 cost_null) (* 10 cost_cdr) (* 10 cost_car))) (index (20) (+ (* 22 cost_closure) (* 41 cost_funcall) cost_letrec (* 41 cost_if) (* 142 cost_varref) (* 21 cost_const) (* 19 cost_plus) (* 20 cost_eq) (* 21 cost_null) (* 20 cost_cdr) (* 20 cost_car))) (index (50) (+ (* 52 cost_closure) (* 101 cost_funcall) cost_letrec (* 101 cost_if) (* 352 cost_varref) (* 51 cost_const) (* 49 cost_plus) (* 50 cost_eq) (* 51 cost_null) (* 50 cost_cdr) (* 50 cost_car))) (index (100) (+ (* 102 cost_closure) (* 201 cost_funcall) cost_letrec (* 201 cost_if) (* 702 cost_varref) (* 101 cost_const) (* 99 cost_plus) (* 100 cost_eq) (* 101 cost_null) (* 100 cost_cdr) (* 100 cost_car))) (index (200) (+ (* 202 cost_closure) (* 401 cost_funcall) cost_letrec (* 401 cost_if) (* 1402 cost_varref) (* 201 cost_const) (* 199 cost_plus) (* 200 cost_eq) (* 201 cost_null) (* 200 cost_cdr) (* 200 cost_car))) (index (500) (+ (* 502 cost_closure) (* 1001 cost_funcall) cost_letrec (* 1001 cost_if) (* 3502 cost_varref) (* 501 cost_const) (* 499 cost_plus) (* 500 cost_eq) (* 501 cost_null) (* 500 cost_cdr) (* 500 cost_car))) (index (1000) (+ (* 1002 cost_closure) (* 2001 cost_funcall) cost_letrec (* 2001 cost_if) (* 7002 cost_varref) (* 1001 cost_const) (* 999 cost_plus) (* 1000 cost_eq) (* 1001 cost_null) (* 1000 cost_cdr) (* 1000 cost_car))) (index (2000) (+ (* 2002 cost_closure) (* 4001 cost_funcall) cost_letrec (* 4001 cost_if) (* 14002 cost_varref) (* 2001 cost_const) (* 1999 cost_plus) (* 2000 cost_eq) (* 2001 cost_null) (* 2000 cost_cdr) (* 2000 cost_car))) (lattice () (+ (* 23163134 cost_closure) (* 155861132 cost_funcall) (* 20401721 cost_letrec) (* 65397793 cost_let) (* 351368357 cost_if) (* 836501523 cost_varref) (* 292435589 cost_const) (* 275911 cost_plus) (* 238802570 cost_eq) (* 90766332 cost_null) (* 3875840 cost_cons) (* 118960899 cost_cdr) (* 120385115 cost_car))) (map (10) (+ cost_closure (* 22 cost_funcall) (* 11 cost_if) (* 84 cost_varref) (* 2 cost_const) (* 10 cost_plus) (* 11 cost_null) (* 10 cost_cons) (* 10 cost_cdr) (* 10 cost_car))) (map (20) (+ cost_closure (* 42 cost_funcall) (* 21 cost_if) (* 164 cost_varref) (* 2 cost_const) (* 20 cost_plus) (* 21 cost_null) (* 20 cost_cons) (* 20 cost_cdr) (* 20 cost_car))) (map (50) (+ cost_closure (* 102 cost_funcall) (* 51 cost_if) (* 404 cost_varref) (* 2 cost_const) (* 50 cost_plus) (* 51 cost_null) (* 50 cost_cons) (* 50 cost_cdr) (* 50 cost_car))) (map (100) (+ cost_closure (* 202 cost_funcall) (* 101 cost_if) (* 804 cost_varref) (* 2 cost_const) (* 100 cost_plus) (* 101 cost_null) (* 100 cost_cons) (* 100 cost_cdr) (* 100 cost_car))) (map (200) (+ cost_closure (* 402 cost_funcall) (* 201 cost_if) (* 1604 cost_varref) (* 2 cost_const) (* 200 cost_plus) (* 201 cost_null) (* 200 cost_cons) (* 200 cost_cdr) (* 200 cost_car))) (map (500) (+ cost_closure (* 1002 cost_funcall) (* 501 cost_if) (* 4004 cost_varref) (* 2 cost_const) (* 500 cost_plus) (* 501 cost_null) (* 500 cost_cons) (* 500 cost_cdr) (* 500 cost_car))) (map (1000) (+ cost_closure (* 2002 cost_funcall) (* 1001 cost_if) (* 8004 cost_varref) (* 2 cost_const) (* 1000 cost_plus) (* 1001 cost_null) (* 1000 cost_cons) (* 1000 cost_cdr) (* 1000 cost_car))) (map (2000) (+ cost_closure (* 4002 cost_funcall) (* 2001 cost_if) (* 16004 cost_varref) (* 2 cost_const) (* 2000 cost_plus) (* 2001 cost_null) (* 2000 cost_cons) (* 2000 cost_cdr) (* 2000 cost_car))) (reverse (10) (+ (* 66 cost_funcall) (* 66 cost_if) (* 299 cost_varref) (* 10 cost_const) (* 66 cost_null) (* 55 cost_cons) (* 55 cost_cdr) (* 55 cost_car))) (reverse (20) (+ (* 231 cost_funcall) (* 231 cost_if) (* 1094 cost_varref) (* 20 cost_const) (* 231 cost_null) (* 210 cost_cons) (* 210 cost_cdr) (* 210 cost_car))) (reverse (50) (+ (* 1326 cost_funcall) (* 1326 cost_if) (* 6479 cost_varref) (* 50 cost_const) (* 1326 cost_null) (* 1275 cost_cons) (* 1275 cost_cdr) (* 1275 cost_car))) (reverse (100) (+ (* 5151 cost_funcall) (* 5151 cost_if) (* 25454 cost_varref) (* 100 cost_const) (* 5151 cost_null) (* 5050 cost_cons) (* 5050 cost_cdr) (* 5050 cost_car))) (reverse (200) (+ (* 20301 cost_funcall) (* 20301 cost_if) (* 100904 cost_varref) (* 200 cost_const) (* 20301 cost_null) (* 20100 cost_cons) (* 20100 cost_cdr) (* 20100 cost_car))) (reverse (500) (+ (* 125751 cost_funcall) (* 125751 cost_if) (* 627254 cost_varref) (* 500 cost_const) (* 125751 cost_null) (* 125250 cost_cons) (* 125250 cost_cdr) (* 125250 cost_car))) (reverse (1000) (+ (* 501501 cost_funcall) (* 501501 cost_if) (* 2504504 cost_varref) (* 1000 cost_const) (* 501501 cost_null) (* 500500 cost_cons) (* 500500 cost_cdr) (* 500500 cost_car))) (reverse (2000) (+ (* 2003001 cost_funcall) (* 2003001 cost_if) (* 10009004 cost_varref) (* 2000 cost_const) (* 2003001 cost_null) (* 2001000 cost_cons) (* 2001000 cost_cdr) (* 2001000 cost_car))) (rev-cps (10) (+ (* 56 cost_closure) (* 123 cost_funcall) (* 66 cost_if) (* 422 cost_varref) (* 11 cost_const) (* 66 cost_null) (* 55 cost_cons) (* 55 cost_cdr) (* 55 cost_car))) (rev-cps (20) (+ (* 211 cost_closure) (* 443 cost_funcall) (* 231 cost_if) (* 1537 cost_varref) (* 21 cost_const) (* 231 cost_null) (* 210 cost_cons) (* 210 cost_cdr) (* 210 cost_car))) (rev-cps (50) (+ (* 1276 cost_closure) (* 2603 cost_funcall) (* 1326 cost_if) (* 9082 cost_varref) (* 51 cost_const) (* 1326 cost_null) (* 1275 cost_cons) (* 1275 cost_cdr) (* 1275 cost_car))) (rev-cps (100) (+ (* 5051 cost_closure) (* 10203 cost_funcall) (* 5151 cost_if) (* 35657 cost_varref) (* 101 cost_const) (* 5151 cost_null) (* 5050 cost_cons) (* 5050 cost_cdr) (* 5050 cost_car))) (rev-cps (200) (+ (* 20101 cost_closure) (* 40403 cost_funcall) (* 20301 cost_if) (* 141307 cost_varref) (* 201 cost_const) (* 20301 cost_null) (* 20100 cost_cons) (* 20100 cost_cdr) (* 20100 cost_car))) (rev-cps (500) (+ (* 125251 cost_closure) (* 251003 cost_funcall) (* 125751 cost_if) (* 878257 cost_varref) (* 501 cost_const) (* 125751 cost_null) (* 125250 cost_cons) (* 125250 cost_cdr) (* 125250 cost_car))) (rev-cps (1000) (+ (* 500501 cost_closure) (* 1002003 cost_funcall) (* 501501 cost_if) (* 3506507 cost_varref) (* 1001 cost_const) (* 501501 cost_null) (* 500500 cost_cons) (* 500500 cost_cdr) (* 500500 cost_car))) (rev-cps (2000) (+ (* 2001001 cost_closure) (* 4004003 cost_funcall) (* 2003001 cost_if) (* 14013007 cost_varref) (* 2001 cost_const) (* 2003001 cost_null) (* 2001000 cost_cons) (* 2001000 cost_cdr) (* 2001000 cost_car))) (split (10) (+ (* 10 cost_closure) (* 32 cost_funcall) (* 41 cost_if) (* 128 cost_varref) (* 33 cost_const) (* 20 cost_greater) (* 11 cost_null) (* 12 cost_cons) (* 10 cost_cdr) (* 20 cost_car))) (split (20) (+ (* 20 cost_closure) (* 62 cost_funcall) (* 81 cost_if) (* 248 cost_varref) (* 63 cost_const) (* 40 cost_greater) (* 21 cost_null) (* 22 cost_cons) (* 20 cost_cdr) (* 40 cost_car))) (split (50) (+ (* 50 cost_closure) (* 152 cost_funcall) (* 201 cost_if) (* 608 cost_varref) (* 153 cost_const) (* 100 cost_greater) (* 51 cost_null) (* 52 cost_cons) (* 50 cost_cdr) (* 100 cost_car))) (split (100) (+ (* 100 cost_closure) (* 302 cost_funcall) (* 401 cost_if) (* 1208 cost_varref) (* 303 cost_const) (* 200 cost_greater) (* 101 cost_null) (* 102 cost_cons) (* 100 cost_cdr) (* 200 cost_car))) (split (200) (+ (* 200 cost_closure) (* 602 cost_funcall) (* 801 cost_if) (* 2408 cost_varref) (* 603 cost_const) (* 400 cost_greater) (* 201 cost_null) (* 202 cost_cons) (* 200 cost_cdr) (* 400 cost_car))) (split (500) (+ (* 500 cost_closure) (* 1502 cost_funcall) (* 2001 cost_if) (* 6008 cost_varref) (* 1503 cost_const) (* 1000 cost_greater) (* 501 cost_null) (* 502 cost_cons) (* 500 cost_cdr) (* 1000 cost_car))) (split (1000) (+ (* 1000 cost_closure) (* 3002 cost_funcall) (* 4001 cost_if) (* 12008 cost_varref) (* 3003 cost_const) (* 2000 cost_greater) (* 1001 cost_null) (* 1002 cost_cons) (* 1000 cost_cdr) (* 2000 cost_car))) (split (2000) (+ (* 2000 cost_closure) (* 6002 cost_funcall) (* 8001 cost_if) (* 24008 cost_varref) (* 6003 cost_const) (* 4000 cost_greater) (* 2001 cost_null) (* 2002 cost_cons) (* 2000 cost_cdr) (* 4000 cost_car))) (union (10 10) (+ (* 121 cost_funcall) (* 10 cost_let) (* 231 cost_if) (* 705 cost_varref) (* 10 cost_const) (* 100 cost_eq) (* 121 cost_null) (* 10 cost_cons) (* 110 cost_cdr) (* 120 cost_car))) (union (20 20) (+ (* 441 cost_funcall) (* 20 cost_let) (* 861 cost_if) (* 2605 cost_varref) (* 20 cost_const) (* 400 cost_eq) (* 441 cost_null) (* 20 cost_cons) (* 420 cost_cdr) (* 440 cost_car))) (union (50 50) (+ (* 2601 cost_funcall) (* 50 cost_let) (* 5151 cost_if) (* 15505 cost_varref) (* 50 cost_const) (* 2500 cost_eq) (* 2601 cost_null) (* 50 cost_cons) (* 2550 cost_cdr) (* 2600 cost_car))) (union (100 100) (+ (* 10201 cost_funcall) (* 100 cost_let) (* 20301 cost_if) (* 61005 cost_varref) (* 100 cost_const) (* 10000 cost_eq) (* 10201 cost_null) (* 100 cost_cons) (* 10100 cost_cdr) (* 10200 cost_car))) (union (200 200) (+ (* 40401 cost_funcall) (* 200 cost_let) (* 80601 cost_if) (* 242005 cost_varref) (* 200 cost_const) (* 40000 cost_eq) (* 40401 cost_null) (* 200 cost_cons) (* 40200 cost_cdr) (* 40400 cost_car))) (union (500 500) (+ (* 251001 cost_funcall) (* 500 cost_let) (* 501501 cost_if) (* 1505005 cost_varref) (* 500 cost_const) (* 250000 cost_eq) (* 251001 cost_null) (* 500 cost_cons) (* 250500 cost_cdr) (* 251000 cost_car))) (union (1000 1000) (+ (* 1002001 cost_funcall) (* 1000 cost_let) (* 2003001 cost_if) (* 6010005 cost_varref) (* 1000 cost_const) (* 1000000 cost_eq) (* 1002001 cost_null) (* 1000 cost_cons) (* 1001000 cost_cdr) (* 1002000 cost_car))) (union (2000 2000) (+ (* 4004001 cost_funcall) (* 2000 cost_let) (* 8006001 cost_if) (* 24020005 cost_varref) (* 2000 cost_const) (* 4000000 cost_eq) (* 4004001 cost_null) (* 2000 cost_cons) (* 4002000 cost_cdr) (* 4004000 cost_car))))) (let ([titles '(car/cdr closure cons const compare call if binding null? +/- varref)] [names '((cost_car 0) (cost_cdr 0) (cost_closure 1) (cost_cons 2) (cost_const 3) (cost_eq 4) (cost_equal 4) (cost_funcall 5) (cost_greater 4) (cost_if 6) (cost_lessthan 4) (cost_let 7) (cost_letrec 7) (cost_null 8) (cost_minus 9) (cost_plus 9) (cost_varref 10))]) (let ([update-cost (lambda (cost vec) (let* ([cost-name (if (symbol? cost) cost (caddr cost))] [cost-amount (if (symbol? cost) 1 (cadr cost))] [index (cadr (assq cost-name names))]) (vector-set! vec index (+ cost-amount (vector-ref vec index)))))]) (letrec ([costs->table-row (lambda (costs) (let ([vec (make-vector (length names))]) (for-each (lambda (cost) (update-cost cost vec)) costs) (do ([i 0 (+ i 1)] [str "" (format "~a & ~a" str (vector-ref vec i))]) ((= i (length titles)) str))))]) (printf "\\hline~%program & size") (for-each (lambda (x) (display " & ") (display x)) titles) (printf "\\\\~%\\hline~%") (do ([costs costs (cdr costs)] [previous 'no-previous (caar costs)]) [(null? costs) (printf "\\hline~%")] (let* ([test-case (car costs)] [costs (cdaddr test-case)] [row (costs->table-row costs)] [name (car test-case)] [args (cadr test-case)]) (if (eq? previous name) (printf "& ~a~a \\\\~%" args row) (printf "\\hline~%~a & ~a~a \\\\~%" name args row))))))) (load "measured-prim.txt") '(for-each (lambda (test-case) (printf "~a ==> ~a milliseconds.~%" (cons (car test-case) (cadr test-case)) (/ (eval (caddr test-case)) 1000000))) costs)
false
3af7b5c4d4bd38f8128f3f6c24cec79386146be6
657a95c82617af612da2a5fa410ac44a67a39feb
/sicp/02/2.28.ss
d94c68360135eb12c8b592ab9080bb8711def269
[]
no_license
wangjiezhe/sicp
ed16395576ac163f000b6dc59ef4928bfab3013f
635dad3bc6dacd07665c17eba2bbe4fcdbbb530f
refs/heads/master
2020-04-06T07:02:32.281885
2016-08-20T08:10:24
2016-08-20T08:10:24
57,348,685
0
0
null
null
null
null
UTF-8
Scheme
false
false
430
ss
2.28.ss
(define (fringe tree) (let loop ([rem tree] [res '()]) (cond [(null? rem) res] [(atom? (car rem)) (loop (cdr rem) (append res (list (car rem))))] [else (loop (cdr rem) (append res (loop (car rem) '())))]))) (define x (list (list 1 2) (list 3 4))) (print (fringe x)) ;; => (1 2 3 4) (print (fringe (list x x))) ;; => (1 2 3 4 1 2 3 4)
false
973049e79fbbc819288184394297a4a728ee28a1
a40182acad8084da3d5a55fc481c108aa4f0b733
/examples/uadeplay-poll.ss
dd14eb7ca9d2b10337788160195a3469a93f2592
[]
no_license
akce/chez-uade
20e6589e95065f0a3ba604c34145b9e8067bcf98
88bad8abb89ebca489a7f571aea67102ac92faf4
refs/heads/master
2022-11-12T02:20:42.634979
2020-07-09T04:20:23
2020-07-09T04:20:23
278,019,459
0
0
null
null
null
null
UTF-8
Scheme
false
false
5,488
ss
uadeplay-poll.ss
#! /usr/bin/chez-scheme --script (debug-on-exception #t) ;; This example uses poll and snd-pcm-avail-update to fill the ALSA PCM ring buffer to exactly what it needs. (import (rnrs) (only (chezscheme) command-line-arguments) (alsa pcm) (uade)) (define device "default") (define buffer/frames #f) (define period/frames #f) (define configure-hw-params (lambda (handle uade-state) (let ([hwp (snd-pcm-hw-params-mallocz)]) (snd-pcm-hw-params-any handle hwp) (snd-pcm-hw-params-set-access handle hwp 'rw-interleaved) (snd-pcm-hw-params-set-format handle hwp 's16-le) (snd-pcm-hw-params-set-channels handle hwp *uade-channels*) (snd-pcm-hw-params-set-rate-near handle hwp (uade-get-sampling-rate uade-state)) (snd-pcm-hw-params-set-buffer-time-near handle hwp 500000) (snd-pcm-hw-params-set-period-time-near handle hwp 100000) (set! buffer/frames (snd-pcm-hw-params-get-buffer-size hwp)) (display "hw buffer size (frames): ")(display buffer/frames)(newline) (set! period/frames (snd-pcm-hw-params-get-period-size hwp)) (display "hw period size (frames): ")(display period/frames)(newline) (snd-pcm-hw-params handle hwp) (snd-pcm-hw-params-free hwp)))) (define configure-sw-params (lambda (handle) (let ([swp (snd-pcm-sw-params-mallocz)] [period-event #f]) (snd-pcm-sw-params-current handle swp) (snd-pcm-sw-params-set-period-event handle swp period-event) ;; Disable auto-play by setting auto-start position to greater than the buffer. ;; This means an snd-pcm-start call is needed to begin play. (snd-pcm-sw-params-set-start-threshold handle swp (+ buffer/frames 1)) ;; Wake client up via poll fd (POLLOUT) when the ring buffer is this empty. ;; eg, buffer/frames - (2 * period/frames). ;; There's a balance between waking up too often and keeping the buffer near always full vs ;; waiting a bit longer and saving on processing, but waiting too long and running the chance ;; of a buffer underrun. (snd-pcm-sw-params-set-avail-min handle swp (- buffer/frames (* period/frames 2))) (snd-pcm-sw-params handle swp) (snd-pcm-sw-params-free swp)))) (define main (lambda (modfile) (let ([handle (snd-pcm-open device 'playback 'nonblock)] [uade-state (uade-new-state)]) (configure-hw-params handle uade-state) (configure-sw-params handle) ;; setup frame buffer and poll descriptors. (let* ([framebuf (uade-malloc/frames buffer/frames)] [fd-count (snd-pcm-poll-descriptors-count handle)] [fds (snd-pcm-poll-descriptors-alloc handle fd-count)]) ;; [proc] load-frames: loads frames into framebuf. ;; [return] the actual number of frames loaded into framebuf. ;; It helps juggle between the: ;; - max local memory buffer size, ;; - max available frame space in alsa-lib ring buffer, ;; - actual amount of frames loadable from the music file. (define load-frames (lambda () (let ([max-frames (fxmin buffer/frames (snd-pcm-avail-update handle))]) (uade-read/frames uade-state framebuf max-frames)))) (snd-pcm-poll-descriptors handle fds fd-count) (display "pcm stream: ")(display (snd-pcm-stream handle))(newline) (display "pcm type ")(display (snd-pcm-type handle))(newline) (display "pollfd count: ")(display fd-count)(newline) (do ([i 0 (+ i 1)]) ((= i fd-count)) (display " fd: ")(display (pollfd-fd fds i)) (display " events: ")(display (poll-flags (pollfd-events fds i))) (display " revents: ")(display (pollfd-revents fds i)) (newline)) (display "pcm state: ")(display (snd-pcm-state handle))(newline) (uade-play uade-state modfile) ;; Prime the alsa ring buffer before play proper. (let ([n (load-frames)]) (display "pre-loading uade frames: ")(display n)(newline) (snd-pcm-writei handle framebuf n)) ;; Begin play loop. (display "pcm state: ")(display (snd-pcm-state handle))(newline) (snd-pcm-start handle) (display "pcm state: ")(display (snd-pcm-state handle))(newline) (let loop () (poll fds fd-count -1) (let ([revs (snd-pcm-poll-descriptors-revents/flags handle fds fd-count)]) (cond [(null? revs) (loop)] [(memq 'out revs) ;; we can write more frames to the buffer. (let ([frames-read (load-frames)]) ;;(display "# ")(display frames-read)(display " revs ")(display revs)(newline) (cond [(= frames-read 0) (display "song end")(newline) #t] [else (snd-pcm-writei handle framebuf frames-read) (loop)]))] [(memq 'err revs) ;; TODO check for underruns. (display "pcm underrun detected! aborting.")(newline)] [else (display "unknown poll ")(display revs)(newline) (loop)]))) (uade-free framebuf)) (snd-pcm-drain handle) (display "pcm state: ")(display (snd-pcm-state handle))(newline) (uade-stop uade-state) (snd-pcm-close handle)))) (main (car (command-line-arguments)))
false
963a7ee288b98fae472fc00e70e71b6b4564d4b0
a19179bb62bce1795f8918e52b2964a33d1534ec
/ch4/tests.scm
081588afed3a6fff5aed22d7e04cb5ab6d23c6da
[]
no_license
b0oh/sicp-exercises
67c22433f761e3ba3818050da9fdcf1abf38815e
58b1c6dfa8bb74499f0d674ab58ad5c21d85ba1a
refs/heads/master
2020-12-24T16:58:55.398175
2013-12-09T09:16:42
2013-12-09T09:16:42
null
0
0
null
null
null
null
UTF-8
Scheme
false
false
529
scm
tests.scm
(define (describe message) (newline) (display "Test ") (display message) (newline)) (define-syntax assert (syntax-rules () ((_ form test) (let* ((value form) (equal (equal? value test))) (if equal (display "[OK] ") (display "[FAIL] ")) (write 'form) (display " should be equal to ") (write test) (if (not equal) (begin (display ". Actual value is ") (write value))) (newline))))) 'test-framework-loaded
true
3618ad015bc8709b3bfe96b740d670386d1d29b0
6b961ef37ff7018c8449d3fa05c04ffbda56582b
/bbn_cl/mach/runtime/bf-futu.scm
5d4a62f95c0203f30717909653114f132d241168
[]
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,996
scm
bf-futu.scm
;;; ******** ;;; ;;; Copyright 1992 by BBN Systems and Technologies, A division of Bolt, ;;; Beranek and Newman Inc. ;;; ;;; Permission to use, copy, modify and distribute this software and its ;;; documentation is hereby granted without fee, provided that the above ;;; copyright notice and this permission appear in all copies and in ;;; supporting documentation, and that the name Bolt, Beranek and Newman ;;; Inc. not be used in advertising or publicity pertaining to distribution ;;; of the software without specific, written prior permission. In ;;; addition, BBN makes no respresentation about the suitability of this ;;; software for any purposes. It is provided "AS IS" without express or ;;; implied warranties including (but not limited to) all implied warranties ;;; of merchantability and fitness. In no event shall BBN be liable for any ;;; special, indirect or consequential damages whatsoever resulting from ;;; loss of use, data or profits, whether in an action of contract, ;;; negligence or other tortuous action, arising out of or in connection ;;; with the use or performance of this software. ;;; ;;; ******** ;;; ;;;; -*- Mode: Scheme ; ; This code is responsible for metering the behavior of futures ; and for the interface to the metering package in general. (declare (usual-integrations) (integrate-primitive-procedures get-fixed-objects-vector set-fixed-objects-vector!)) (define *meter-list* ()) (define *future-creation-meter* ()) (define *future-start-meter* ()) (define *future-await-meter* ()) (define *future-suspend-meter* ()) (define *future-restart-meter* ()) (define *future-determine-meter* ()) (define *gc-start-meter* ()) (define *gc-finish-meter* ()) (define (lookup-meter name) (let ((found (assoc name *meter-list*))) (if (null? found) (let ((number ((access io-next-hash-number butterfly-io)))) (set! *meter-list* (cons (cons name number) *meter-list*)) (bfly-send-output-string 5 number (string-append "METER:" name)) number) (let ((number (cdr found))) (bfly-send-output-string 5 number (string-append "METER:" name)) number)))) (define send-metering (make-primitive-procedure 'send-metering)) (define bfio-start-metering (make-primitive-procedure 'bfio-start-metering)) (define bfio-end-metering (make-primitive-procedure 'bfio-end-metering)) (define atomic-add-car! (make-primitive-procedure 'atomic-add-car!)) (define atomic-add-cdr! (make-primitive-procedure 'atomic-add-cdr!)) (define atomic-add-vector! (make-primitive-procedure 'atomic-add-vector!)) (define *future-counter* (cons 'future-number 0)) (define (reset-metering) (set! *future-counter* (cons 'future-number 0))) (define (*future-creation-handler* process name) (send-metering *future-creation-meter* (vector (future-ref process FUTURE-METERING-SLOT) (future-ref (current-future) FUTURE-METERING-SLOT)) name)) (define (*future-determine-handler* future) (if (not (eq? (future-ref future FUTURE-PROCESS-SLOT) 'input-wait)) (send-metering *future-determine-meter* (future-ref future FUTURE-METERING-SLOT) 0))) (define (*future-start-handler* future) (if (not (eq? (future-ref future FUTURE-PROCESS-SLOT) 'input-wait)) (send-metering *future-start-meter* (future-ref future FUTURE-METERING-SLOT) 0))) (define (*future-restart-handler* started starter) (if (not (eq? (future-ref starter FUTURE-PROCESS-SLOT) 'input-wait)) (send-metering *future-restart-meter* (future-ref started FUTURE-METERING-SLOT) (future-ref starter FUTURE-METERING-SLOT)))) (define (*future-await-handler* waiter awaited) (if (not (eq? (future-ref awaited FUTURE-PROCESS-SLOT) 'input-wait)) (send-metering *future-await-meter* (future-ref waiter FUTURE-METERING-SLOT) (future-ref awaited FUTURE-METERING-SLOT)))) (define (*future-suspend-handler* waiter) (send-metering *future-await-meter* (future-ref waiter FUTURE-METERING-SLOT) 0)) (define (*gc-start-handler*) (send-metering *gc-start-meter* 0 0)) (define (*gc-finish-handler*) (send-metering *gc-finish-meter* 0 0)) (define (metering-on #!optional filename) (if (not (unassigned? filename)) (bfio-start-metering filename)) (set! *future-creation-meter* (lookup-meter "FUTURE-CREATION")) (set! *future-start-meter* (lookup-meter "FUTURE-START")) (set! *future-await-meter* (lookup-meter "FUTURE-AWAIT")) (set! *future-restart-meter* (lookup-meter "FUTURE-RESTART")) (set! *future-determine-meter* (lookup-meter "FUTURE-DETERMINE")) (set! *gc-start-meter* (lookup-meter "GC-STARTING")) (set! *gc-finish-meter* (lookup-meter "GC-FINISHED")) (set-microcode-metering! (vector *future-creation-meter* *future-start-meter* *future-await-meter* *future-restart-meter* *future-determine-meter*)) (set! *future-creation-hook* *future-creation-handler*) (set! *future-start-hook* *future-start-handler*) (set! *future-determine-hook* *future-determine-handler*) (set! *future-restart-hook* *future-restart-handler*) (set! *future-await-hook* *future-await-handler*) (set! *future-suspend-hook* *future-suspend-handler*) (set! *gc-start-hook* *gc-start-handler*) (set! *gc-finish-hook* *gc-finish-handler*)) (define (metering-off) (bfio-end-metering) (set-microcode-metering! #f) (set! *future-creation-hook* ()) (set! *future-start-hook* ()) (set! *future-determine-hook* ()) (set! *future-restart-hook* ()) (set! *future-await-hook* ()) (set! *future-suspend-hook* ()) (set! *gc-start-hook* ()) (set! *gc-finish-hook* ())) (define (set-microcode-metering! state) (let ((fov (get-fixed-objects-vector))) (vector-set! fov (fixed-objects-vector-slot 'metering-on) state) (set-fixed-objects-vector! fov))) (define (with-metering file thunk) (dynamic-wind (lambda () (metering-on file)) thunk (lambda () (metering-off))))
false
8fa4281a336bd3e91b9da04776b36982d9e7ad94
018a7ce673c5be3cf3df61bd5c5036581d6646a7
/spec/swapit.scm
0afc81961a32a07358c70b8d3aecbbc64f7473bb
[ "MIT" ]
permissive
iwillspeak/feersum
e857deec2b8683960f9ac6d1f395fb5f625204a8
1602e8333aa11c0335c9775c0ab49bf01389ba98
refs/heads/main
2023-08-07T17:15:19.843607
2023-06-20T06:28:28
2023-06-20T06:28:28
223,348,583
31
2
MIT
2023-06-10T21:29:11
2019-11-22T07:33:04
F#
UTF-8
Scheme
false
false
403
scm
swapit.scm
(import (scheme base) (scheme write)) (define (swap me you) (let ((me you) (you me)) you)) (let ((x 1) (y 2)) (define-syntax swap! (syntax-rules () ((swap! a b) (let ((tmp a)) (set! a b) (set! b tmp))))) (swap! x y) (display (list x y))) (display (swap "Fooble" "Barble")) (= (swap 123 "Test") 123)
true
0543d0d8d9325b8358f4d9efe6fa4c5d05e6be3a
7f06d5e6355d52cfffa1c9a21a7b3c8eceafe197
/tests/test.scm
a08a4388067159af22d2861be4655d8fbba04c80
[ "BSD-3-Clause" ]
permissive
tabe/xunit
72695181b8a78131a63310bbbcf372941a1f17f2
515a2487f64d973ea918159402aa31e258857c6e
refs/heads/master
2020-03-27T23:12:58.397358
2019-02-06T03:34:44
2019-02-06T03:36:34
277,786
0
0
null
null
null
null
UTF-8
Scheme
false
false
1,597
scm
test.scm
#!r6rs (import (rnrs) (xunit)) (define-syntax should-be-false (syntax-rules () ((_ expr) (assert (not expr))))) (add-message! "this is a message") (should-be-false (fail! "this is a to-be-reset failure")) (reset!) (assert (assert-raise message-condition? (raise (make-message-condition "OK")))) (assert (assert-= 2 (+ 1 1))) (assert (assert-boolean=? #t (not (not (not #f))))) (assert (assert-char-ci=? #\z (integer->char (+ 25 (char->integer #\A))))) (assert (assert-char=? #\Z (integer->char (+ 25 (char->integer #\A))))) (assert (assert-string=? "R6RS" (string-append "R" (number->string 6) "RS"))) (assert (assert-boolean? #t)) (assert (assert-char? #\a)) (assert (assert-complex? +i)) (assert (assert-even? 2)) (assert (assert-exact? 1)) (assert (assert-finite? 0)) (assert (assert-inexact? #i3)) (assert (assert-infinite? +inf.0)) (assert (assert-integer-valued? 3+0i)) (assert (assert-integer? 3)) (assert (assert-list? '(l i s t))) (assert (assert-nan? +nan.0)) (assert (assert-negative? -1)) (assert (assert-null? '())) (assert (assert-number? 7)) (assert (assert-odd? 1)) (assert (assert-pair? '(car . cdr))) (assert (assert-positive? 1)) (assert (assert-procedure? call/cc)) (assert (assert-rational-valued? 6/10+0.0i)) (assert (assert-rational? 6/10)) (assert (assert-real-valued? +nan.0+0i)) (assert (assert-real? -2.5+0i)) (assert (assert-string? "string")) (assert (assert-symbol? 'symbol)) (assert (assert-vector? '#(v e c t o r))) (assert (assert-zero? (- 1 1))) (assert (skip-unless #f (assert (assert-boolean=? #t #f)) (assert (assert-= 0 1)))) (report)
true
6cfbe566607a0f92457a97aab8959e70bacd6bbb
d8bdd07d7fff442a028ca9edbb4d66660621442d
/scam/tests/00-syntax/import/prefix.scm
7b9f84bdbb8591fd69dfcd6647eb611936dfbf9a
[]
no_license
xprime480/scam
0257dc2eae4aede8594b3a3adf0a109e230aae7d
a567d7a3a981979d929be53fce0a5fb5669ab294
refs/heads/master
2020-03-31T23:03:19.143250
2020-02-10T20:58:59
2020-02-10T20:58:59
152,641,151
0
0
null
null
null
null
UTF-8
Scheme
false
false
268
scm
prefix.scm
(import (test narc)) (narc-label "Import Library Prefix") (narc-catch (:eval (sample)) (:eval (example))) (import (prefix sample yo-)) (narc-expect (123 (yo-sample)) ("howdy" (yo-example))) (narc-catch (:eval (sample)) (:eval (example))) (narc-report)
false
baa3446b858b2d715db302af3de4e4d0de89ff14
5355071004ad420028a218457c14cb8f7aa52fe4
/2.5/test/arithmetic.scm
333474435caebf9ac7256293d35070d728266df4
[]
no_license
ivanjovanovic/sicp
edc8f114f9269a13298a76a544219d0188e3ad43
2694f5666c6a47300dadece631a9a21e6bc57496
refs/heads/master
2022-02-13T22:38:38.595205
2022-02-11T22:11:18
2022-02-11T22:11:18
2,471,121
376
90
null
2022-02-11T22:11:19
2011-09-27T22:11:25
Scheme
UTF-8
Scheme
false
false
1,686
scm
arithmetic.scm
(load "../../helpers.scm") (load "../arithmetics.scm") (load "../symbolic_algebra.scm") ; All the test situations should be defined here. ; This is for the sake of seeing if soemthing is awfully broken ; Not for the sake of automatizing testing. (output (add 4 5)) (output (sub 4 5)) (output (mul 4 5)) (output (div 4 5)) (output (equ? 4 5)) (output (equ? 5 5)) (output (=zero? 5)) (output (=zero? 0)) (output (add 5 (make-rational 5 2))) (output (add (make-rational 5 2) (make-rational 3 1))) (output (raise (raise 5))) (output (equ? (make-complex-from-real-imag 3 4) (make-complex-from-real-imag 3 4))) (output (equ? (make-rational 3 4) (make-rational 3 4))) (output (equ? 5 5)) (output (equ? 5 (make-rational 5 1))) (output (equ? 5 (make-complex-from-real-imag 5 0))) (output (equ? 5 (make-complex-from-real-imag 5 1))) (output (equ? (make-complex-from-real-imag 5 1) (make-complex-from-real-imag 5 1))) (output (push-down (make-rational 5 2))) (output (push-down (make-complex-from-real-imag 5 2))) (output (drop (make-rational 4 2))) ; 2 (output (drop (make-rational 4 3))) ; (rational 4 . 3) (output (drop (make-complex-from-real-imag 5 0))) ; (rational 4 . 3) (output (drop (make-complex-from-real-imag 5 1))) ; (complex rectangular 5 1) (output (drop (add 3 5))) (output (drop (add 3 (make-rational 5 1)))) (push-down (make-rational 4 1)) (output (pushable? (make-rational 4 2))) (output (add (make-rational 4 1) (make-rational 4 1))) (output (push-down (make-rational 4 1))) (output (=zero? (make-polynomial 'x (list (list 1 0) (list 0 0)) ))) ; #t (output (=zero? (make-polynomial 'x (list (list 1 0) (list 0 1)) ))) ; #f
false
714320659d9c18bc71100ff35fc834e72f8acc5b
e44c651f315b2cca4a6e8b2a6715ac0d8943814d
/src/MIT-prelude.scm
93d141eb17675a6dacded14a3cb94d82819ecc24
[]
no_license
ecraven/r7rs-benchmarks
75dd4d895fde857077da6e0b6469d2cc0ee9b9f8
845345f7e13ac07bb6cd3c6bf745ae9caf9ed7b8
refs/heads/master
2022-12-10T18:36:21.777848
2022-10-17T11:40:09
2022-10-17T11:40:09
58,028,745
271
40
null
2022-12-05T10:00:54
2016-05-04T06:36:49
Scheme
UTF-8
Scheme
false
false
378
scm
MIT-prelude.scm
(declare (usual-integrations)) (define old-values values) (define (values . objects) (if (= (length objects) 1) (car objects) (apply old-values objects))) (define-syntax import (syntax-rules () ((import stuff ...) (begin) ;; do nothing ))) (define (this-scheme-implementation-name) (string-append "mit-" (get-subsystem-version-string "Release")))
true
743bda0cc1460f98d90892e704411afa4e4ccef9
923209816d56305004079b706d042d2fe5636b5a
/sitelib/http/header-field/allow.scm
466eb70aff472991a2cd4f67789eb2818014658f
[ "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
219
scm
allow.scm
(library (http header-field allow) (export Allow) (import (rnrs (6)) (http abnf) (http method)) ;;; 14.7 Allow (define Allow (seq (string->rule "Allow") (char->rule #\:) (num* Method))) )
false
b606a925462fc8bc42a3e3d96d193b2cc17151ce
99f659e747ddfa73d3d207efa88f1226492427ef
/datasets/srfi/srfi-77/arithmetic-reference/string2number.scm
97c0c5b44b55dfd4fdc764c215e1af5545fe7b7d
[ "MIT" ]
permissive
michaelballantyne/n-grams-for-synthesis
241c76314527bc40b073b14e4052f2db695e6aa0
be3ec0cf6d069d681488027544270fa2fd85d05d
refs/heads/master
2020-03-21T06:22:22.374979
2018-06-21T19:56:37
2018-06-21T19:56:37
138,215,290
0
0
MIT
2018-06-21T19:51:45
2018-06-21T19:51:45
null
UTF-8
Scheme
false
false
18,831
scm
string2number.scm
; This file is part of the reference implementation of the R6RS Arithmetic SRFI. ; See file COPYING. ; A parser for numeric constants in MacScheme. ; from Larceny ; Designed to be called by the reader. ; Captures a procedure named bellerophon, which should implement ; Algorithm Bellerophon for reading floating point numbers perfectly. ; ; Number syntax; note the code also supports +inf.0, -inf.0, +nan.0, ; -nan.0, and their complex combinations: ; ; <number> --> <num 2> | <num 8> | <num 10> | <num 16> ; ; The following rules for <num R>, <complex R>, <real R>, <ureal R>, ; <uinteger R>, and <prefix R> should be replicated for R = 2, 8, 10, ; and 16. There are no rules for <decimal 2>, <decimal 8>, and ; <decimal 16>, which means that numbers containing decimal points ; or exponents or mantissa widths must be in decimal radix. ; ; <num R> --> <prefix R> <complex R> ; <complex R> --> <real R> | <real R> @ <real R> ; | <real R> + <ureal R> i | <real R> - <ureal R> i ; | <real R> + i | <real R> - i ; | + <ureal R> i | - <ureal R> i | + i | - i ; <real R> --> <sign> <ureal R> ; <ureal R> --> <uinteger R> ; | <uinteger R> / <uinteger R> ; | <decimal R> <mantissa width> ; <decimal 10> --> <uinteger 10> <suffix> ; | . <digit 10>+ #* <suffix> ; | <digit 10>+ . <digit 10>* #* <suffix> ; | <digit 10>+ #* . #* <suffix> ; <uinteger R> --> <digit R>+ #* ; <prefix R> --> <radix R> <exactness> ; | <exactness> <radix R> ; ; <suffix> --> <empty> ; | <exponent marker> <sign> <digit 10>+ ; <exponent marker> --> e | s | f | d | l ; <mantissa width> -> <empty> ; | | <digit 10>+ ; <sign> --> <empty> | + | - ; <exactness> --> <empty> | #i | #e ; <radix 2> --> #b ; <radix 8> --> #o ; <radix 10> --> <empty> | #d ; <radix 16> --> #x ; <digit 2> --> 0 | 1 ; <digit 8> --> 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 ; <digit 10> --> 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 ; <digit 16> --> <digit 10> | a | b | c | d | e | f ; NOT IEEE-specific---R6RS! (define default-precision (r5rs->integer 53)) (define (decimal-digit? c) (and (char>=? c #\0) (char<=? c #\9))) ; works if characters are Unicode scalar values, as will be the case ; in R6RS (define zero-scalar-value (r5rs->integer (char->integer #\0))) (define (decimal-value c) (integer- (r5rs->integer (char->integer c)) zero-scalar-value)) ; Parse-number takes a list of characters to be parsed. ; Its output is a number, or #f. (define (parse-number input) (let ((c (car input))) (cond ((decimal-digit? c) ; (parse-decimal (cdr input) (decimal-value c) 1) (parse-complex input #f (r5rs->integer 10))) ((memq c '(#\- #\+ #\.)) (parse-complex input #f (r5rs->integer 10))) ((char=? c #\#) (parse-prefix input #f #f)) (else #f)))) ; Prefix has been consumed, but not anything else. ; Simplified grammar for complexes: ; complex --> [+-]i ; | <real>@<real> ; | <real>i ; | <real>[+-]i ; | <real>[+-]<ureal>i (define (parse-complex input exactness radix) (define (stage1 input) (let ((c (car input))) (cond ((char=? c #\-) (if (and (not (null? (cdr input))) (null? (cddr input)) (char=? (char-downcase (cadr input)) #\i)) (coerce-exactness exactness -i) (parse-ureal (cdr input) exactness radix (r5rs->integer -1)))) ((char=? c #\+) (if (and (not (null? (cdr input))) (null? (cddr input)) (char=? (char-downcase (cadr input)) #\i)) (coerce-exactness exactness (r5rs->recnum +i)) (parse-ureal (cdr input) exactness radix (r5rs->integer 1)))) ((char=? c #\.) (parse-ureal input 'i (r5rs->integer 10) (r5rs->integer 1))) (else (parse-real input exactness radix))))) (define (stage2 real input) (let ((c (char-downcase (car input)))) (cond ((char=? c #\@) (let ((r (parse-real (cdr input) exactness radix))) (if r (make-compnum-polar real r) #f))) ((char=? c #\i) (if (null? (cdr input)) (if (flonum? real) (make-compnum (r5rs->flonum 0.0) real) (make-recnum (r5rs->integer 0) real)) #f)) ((or (char=? c #\+) (char=? c #\-)) (if (null? (cdr input)) #f (let ((d (char-downcase (cadr input))) (s (if (char=? c #\+) (r5rs->integer 1) (r5rs->integer -1)))) (if (and (char=? d #\i) (null? (cddr input))) (if (flonum? real) (make-compnum real (integer->flonum s)) (make-recnum real s)) (let ((v (parse-ureal (cdr input) exactness radix s))) (if (not (pair? v)) #f (stage3 real (car v) (cdr v)))))))) (else (error "Internal error in parse-complex: " c) #t)))) (define (stage3 real imag input) (cond ((null? input) #f) ((not (null? (cdr input))) #f) ((char=? (char-downcase (car input)) #\i) (if (and (exact-rational? real) (exact-rational? imag)) (make-recnum real imag) (make-compnum (x->flonum real) (x->flonum imag)))) (else #f))) (let ((v (stage1 input))) (if (not (pair? v)) v (let ((real (car v)) (input (cdr v))) (if (null? input) real (stage2 real input)))))) (define (x->flonum x) (if (flonum? x) x (rational->flonum x))) ; input = list of characters remaining to parse ; exactness = the symbol e if #e has been read ; the symbol i if #i has been read ; otherwise #f ; radix = 2, 8, 10, 16 or #f if no explicit radix prefix ; has yet been read (define (parse-prefix input exactness radix) (cond ((null? input) #f) ((char=? (car input) #\#) (cond ((null? (cdr input)) #f) (else (let ((c (char-downcase (cadr input)))) (case c ((#\e #\i) (if exactness #f (parse-prefix (cddr input) (if (char=? c #\e) 'e 'i) radix))) ((#\b #\o #\d #\x) (if radix #f (parse-prefix (cddr input) exactness (r5rs->integer (cdr (assq c '((#\b . 2) (#\o . 8) (#\d . 10) (#\x . 16)))))))) (else #f)))))) (else (parse-complex input exactness (if radix radix (r5rs->integer 10)))))) ; The prefix has been consumed, but nothing else. ; e is exactness prefix: e, i, or #f if no explicit prefix ; r is the radix: 2, 8, 10, or 16 (define (parse-real input e r) (cond ((null? input) #f) ((char=? (car input) #\+) (parse-ureal (cdr input) e r (r5rs->integer 1))) ((char=? (car input) #\-) (parse-ureal (cdr input) e r (r5rs->integer -1))) (else (parse-ureal input e r (r5rs->integer 1))))) ; The prefix and sign have been consumed. ; exactness = e, i, or #f if there is no explicit exactness. ; radix = 2, 8, 10, or 16. ; sign = 1 or -1. ; ; The numeric value of the number parsed is ; (/ (* numerator (expt 10 exponent)) denominator) (define (parse-ureal input exactness radix sign) (cond ((null? input) #f) ((and (integer= radix (r5rs->integer 10)) (radix-digit? (car input) (r5rs->integer 10)) (not exactness)) (parse-decimal (cdr input) (decimal-value (car input)) sign)) ((radix-digit? (car input) radix) (q1 (cdr input) exactness radix sign (radix-digit-value (car input) radix))) ((and (integer= radix (r5rs->integer 10)) (char=? (car input) #\.) (not (null? (cdr input))) (radix-digit? (cadr input) (r5rs->integer 10))) (q3 (cdr input) (or exactness 'i) sign (r5rs->integer 0) (r5rs->integer 0))) ((char=? (char-downcase (car input)) #\n) (special-syntax (cdr input) '(#\a #\n #\. #\0) flnan)) ((char=? (char-downcase (car input)) #\i) (special-syntax (cdr input) '(#\n #\f #\. #\0) (fl* (fixnum->flonum sign) flinf+))) (else #f))) ; Special syntax: ; +inf.0 -inf.0 +nan.0 -nan.0 and complex combinations. ; ; The sign has been consumed, as has the first character. (define (special-syntax input pattern val) (let loop ((i input) (l pattern)) (cond ((null? i) (if (null? l) (cons val i) #f)) ((null? l) (cons val i)) ((char=? (char-downcase (car i)) (car l)) (loop (cdr i) (cdr l))) (else #f)))) ; At least one digit has been consumed. ; This is an accepting state. ; ; MacScheme deliberately accepts numbers like 3#4 in order to save ; code space. (define (q1 input e r s m) (if (null? input) (create-number (or e 'e) s m (r5rs->integer 1) (r5rs->integer 0) default-precision) (let ((c (char-downcase (car input)))) (cond ((radix-digit? c r) (q1 (cdr input) e r s (integer+ (integer* r m) (radix-digit-value c r)))) ((char=? c #\#) ;; FIXME: should call q2 here (q1 (cdr input) (or e 'i) r s (integer* r m))) ((char=? c #\/) (q7 (cdr input) e r s m)) ((not (integer= r (r5rs->integer 10))) #f) ((char=? c #\.) (q3 (cdr input) (or e 'i) s m (r5rs->integer 0))) ((exponent-marker? c) (q5 (cdr input) (or e 'i) s m (r5rs->integer 0))) ((follow-char? c) (cons (create-number (or e 'e) s m (r5rs->integer 1) (r5rs->integer 0) default-precision) input)) (else #f))))) ; The parse-decimal procedure is a version of q1 for use when there is ; no explicit exactness prefix and the radix is 10 (e = #f, r = 10). ; Since it takes fewer arguments and doesn't have to call char-downcase, ; it runs quicker. I have also permuted its arguments so the compiler ; will keep m in a hardware register. ; Speed matters here because this is by far the most common case. (define (parse-decimal input m s) (if (null? input) (create-number 'e s m (r5rs->integer 1) (r5rs->integer 0) default-precision) (let ((c (car input))) (cond ((decimal-digit? c) (parse-decimal (cdr input) (integer+ (integer* (r5rs->integer 10) m) (decimal-value c)) s)) ((char=? c #\#) ;; FIXME: should call q2 here (q1 (cdr input) 'i (r5rs->integer 10) s (integer* (r5rs->integer 10) m))) ((char=? c #\/) (q7 (cdr input) #f (r5rs->integer 10) s m)) ((char=? c #\.) (q3 (cdr input) 'i s m (r5rs->integer 0))) ((char=? c #\|) (q10 (cdr input) s m (r5rs->integer 0))) ((exponent-marker? (char-downcase c)) (q5 (cdr input) 'i s m (r5rs->integer 0))) ((follow-char? c) (cons (create-number 'e s m (r5rs->integer 1) (r5rs->integer 0) default-precision) input)) (else #f))))) ; The radix is 10, a decimal point has been consumed, ; and either a digit has been consumed or a digit is the next character. ; The value read so far is (* m (expt 10 o)). ; This is an accepting state. ; ; MacScheme deliberately accepts 3.#4 in order to save code space. (define (q3 input e s m o) (if (null? input) (create-number e s m (r5rs->integer 1) o default-precision) (let ((c (char-downcase (car input)))) (cond ((radix-digit? c (r5rs->integer 10)) (q3 (cdr input) e s (integer+ (integer* (r5rs->integer 10) m) (decimal-value c)) (integer- o (r5rs->integer 1)))) ((char=? c #\#) ; FIXME: should call q4 here (q3 (cdr input) e s (integer* (r5rs->integer 10) m) (integer- o (r5rs->integer 1)))) ((char=? c #\|) (q10 (cdr input) s m o)) ((exponent-marker? c) (q5 (cdr input) (or e 'i) s m o)) ((follow-char? c) (cons (create-number e s m (r5rs->integer 1) o default-precision) input)) (else #f))))) ; The radix is 10 and an exponent marker has been consumed. ; The value read so far is (* m (expt 10 o)). (define (q5 input e s m o) (if (null? input) #f (let ((c (car input))) (cond ((and (or (char=? c #\+) (char=? c #\-)) (not (null? (cdr input)))) (let ((d (cadr input))) (if (radix-digit? d (r5rs->integer 10)) (q6 (cddr input) e s m o (if (char=? c #\-) (r5rs->integer -1) (r5rs->integer 1)) (decimal-value d)) #f))) ((radix-digit? c (r5rs->integer 10)) (q6 (cdr input) e s m o (r5rs->integer 1) (decimal-value c))) (else #f))))) ; The radix is 10 and an exponent marker, the exponent sign (if any), ; and the first digit of the exponent have been consumed. ; This is an accepting state. (define (q6 input e s m o esign exp) (if (null? input) (create-number e s m (r5rs->integer 1) (integer+ o (integer* esign exp)) default-precision) (let ((c (car input))) (cond ((radix-digit? c (r5rs->integer 10)) (q6 (cdr input) e s m o esign (integer+ (integer* (r5rs->integer 10) exp) (decimal-value c)))) ((char=? c #\|) (q10 (cdr input) s m (integer+ o (integer* esign exp)))) ((follow-char? c) (cons (create-number e s m (r5rs->integer 1) (integer+ o (integer* esign exp)) default-precision) input)) (else #f))))) ; Here we are parsing the denominator of a ratio. ; e = e, i, or #f if no exactness has been specified or inferred. ; r is the radix ; s is the sign ; m is the numerator (define (q7 input e r s m) (if (null? input) #f (let ((c (car input))) (cond ((radix-digit? c r) (q8 (cdr input) e r s m (radix-digit-value c r))) (else #f))))) ; A digit has been read while parsing the denominator of a ratio. ; n is the denominator read so far. ; This is an accepting state. ; ; MacScheme accepts 3/4#5 to save code space. (define (q8 input e r s m n) (if (null? input) (create-number (or e 'e) s m n (r5rs->integer 0) default-precision) (let ((c (car input))) (cond ((radix-digit? c r) (q8 (cdr input) e r s m (integer+ (integer* r n) (radix-digit-value c r)))) ((char=? c #\#) ; FIXME: should call q9 here (q8 (cdr input) (or e 'i) r s m (integer* r n))) ((follow-char? c) (cons (create-number (or e 'e) s m n (r5rs->integer 0) default-precision) input)) (else #f))))) ; The mantissa-width separator has been read. ; This is an accepting state. ; s sign, m mantissa (define (q10 input s m exp) (if (or (null? input) (not (decimal-digit? (car input)))) #f (let loop ((input input) (width (r5rs->integer 0))) (if (and (pair? input) (decimal-digit? (car input))) (loop (cdr input) (integer+ (integer* (r5rs->integer 10) width) (decimal-value (car input)))) (create-number 'i s m (r5rs->integer 1) exp width))))) (define (follow-char? c) (memq c '(#\+ #\- #\@ #\i #\I))) (define (exponent-marker? c) (memq c '(#\e #\s #\f #\d #\l))) (define (radix-digit? c r) (if (integer= r (r5rs->integer 16)) (or (decimal-digit? c) (let ((c (char-downcase c))) (and (char<=? #\a c) (char<=? c #\f)))) (and (char<=? #\0 c) (char<=? c (integer->char (integer->r5rs (integer+ (r5rs->integer (char->integer #\0)) r))))))) (define (radix-digit-value c r) (cond ((not (integer= r (r5rs->integer 16))) (integer- (r5rs->integer (char->integer c)) (r5rs->integer (char->integer #\0)))) ((char<=? c #\9) (radix-digit-value c (r5rs->integer 10))) (else (integer+ (r5rs->integer 10) (integer- (r5rs->integer (char->integer (char-downcase c))) (r5rs->integer (char->integer #\a))))))) ;---------------------------------------------------------------- ; ; The arguments to create-number contain all the information needed to ; create a real number of the correct sign, magnitude, and exactness. ; ; sign = 1 or -1 ; exactness = a symbol, e or i ; numerator = an exact integer ; denominator = an exact integer ; exponent = an exact integer ; precision = an exact integer (define (create-number exactness sign numerator denominator exponent precision) (cond ((not (integer= denominator (r5rs->integer 1))) (coerce-exactness exactness (integer/ (integer* sign numerator) denominator))) ((eq? exactness 'i) (fl* (integer->flonum sign) (bellerophon numerator exponent precision))) ((integer-zero? exponent) (integer* sign numerator)) ((integer-negative? exponent) (integer/ (integer* sign numerator) (integer-expt (r5rs->integer 10) (integer-negate exponent)))) (else (integer* sign (integer* numerator (integer-expt (r5rs->integer 10) exponent)))))) (define (coerce-exactness exactness x) (cond ((eq? exactness 'i) (cond ((fixnum? x) (fixnum->flonum x)) ((bignum? x) (bignum->flonum x)) ((ratnum? x) (rational->flonum x)) ((recnum? x) (recnum->compnum x)) ((flonum? x) x) ((compnum? x) x))) ((fixnum? x) x) ((bignum? x) x) ((ratnum? x) x) ((recnum? x) x) ((flonum? x) (flonum->rational x)) ((compnum? x) (compnum->recnum x)))) ; String->number takes a number or a number and a radix. ; Its output is a number, or #f. (define (string->number string . rest) (let ((input (string->list string))) (cond ((null? input) #f) ((null? rest) (parse-number input)) ((null? (cdr rest)) (let ((radix (car rest))) (if (or (integer= (r5rs->integer 2) radix) (integer= (r5rs->integer 8) radix) (integer= (r5rs->integer 10) radix) (integer= (r5rs->integer 16) radix)) (parse-prefix input #f (car rest)) (begin (error "string->number: Invalid radix: " (car rest)) #t)))) (else (begin (error "string->number: Too many arguments: " rest) #t))))) ; eof
false
98f79e23a306c89b36d710e38d3dfe6c1eedf6ad
9bc3d1c5f20d268df5b86e6d4af0402d1bf931b4
/libschell.sld
0be76398e92c45d560bbb0179abfaf662ab95557
[ "MIT", "LicenseRef-scancode-unknown-license-reference" ]
permissive
leahneukirchen/schell
86f44cd9701cf49ef624fd31eecf901d0d2ac2f1
3ed181bc19ac9f8f53f5392cffbc1f79255e71f2
refs/heads/master
2023-07-19T23:56:17.339682
2021-08-24T11:08:39
2021-08-24T11:08:39
398,331,477
7
0
null
null
null
null
UTF-8
Scheme
false
false
862
sld
libschell.sld
; -*- scheme -*- (define-library (libschell) (import (except (chibi) = do if let) (chibi io) (chibi string) (rename (chibi filesystem) (open-pipe pipe) (duplicate-file-descriptor dup) (duplicate-file-descriptor-to dup2) (close-file-descriptor close) ) (rename (chibi process) (current-process-id getpid) ) (chibi ast) (srfi 1) (rename (srfi 98) (get-environment-variable getenv)) (srfi 151) (meowlisp) (glob) ) (include "libschell/schell.scm") (export ; execvp pipe fork exit dup2 dup close waitpid wait/no-hang getpid cd getenv $ run run/str run/lines glob argv *status* *pipestatus* ~ run/pipe & wait ) )
false
11389ef88e4b2eda1868f6b182f51fff56f689b1
f52affabccfa184faaa762562a7be6dd509dcf1e
/scratchpad/datatype.ss
fb56ad854b3a79f0d20a67a5b4764cbd8ea484ad
[ "BSD-3-Clause" ]
permissive
stumtjener/t20-mirror
98e08caaf70309fc1d8904dbe1afc3a0f156433b
7444eac55411b0f4d799fbfb52c886f3a27abef6
refs/heads/master
2020-03-29T23:13:45.383239
2019-01-29T19:01:44
2019-01-30T16:01:57
150,462,609
0
0
null
null
null
null
UTF-8
Scheme
false
false
9,736
ss
datatype.ss
;;; datatype.ss ;;; Time-stamp: <2005-01-29 12:58:30 ksm> ;;; (time-stamp generated by emacs: Type M-x time-stamp anywhere to update) ;;; This is based on the version of 1999-12-13 16:00:24 due to Erik Hilsdale ;;; <2005-01-29 12:57:34 ksm> ;;; Changed from Chez 6.0 print-method to 6.9c record-writer ;;; This is a Chez-specific (version 6.0) implementation of a datatype ;;; system, with automagic generation of anas and catas over the ;;; datatype. ;;; ------------------------------ ;;; User interface ;;;(define-datatype Type-name Predicate-name ;;; (Variant-name (Field-name Predicate-exp) ...) ...) ;;; -> defines Variant-name ..., Predicate-name, Type-name ;;;(cases Type-name Exp Clause ...) ;;;(cata Type-name Clause ...) ;;;(ana Type-name (arg ...) Exp) (eval-when (compile) (generate-inspector-information #f) (optimize-level 2)) (define-syntax with-capture (syntax-rules () [($ context (name ...) exp0 exp1 ...) (with-syntax ((name (datum->syntax-object context 'name)) ...) exp0 exp1 ...)])) (define-syntax with-values (syntax-rules () ((_ Producer Consumer) (call-with-values (lambda () Producer) Consumer)))) (module ( datatype-transluscent (define-datatype do-define-datatype define-constructor syn-err) (cases syn-err) (cata syn-err) (ana syn-err)) (define datatype-transluscent (make-parameter #t)) (define-syntax define-datatype (syntax-rules () ((_ . Rest) (do-define-datatype . Rest)))) (define-syntax cases (syntax-rules () ((_ Type-name Exp Clause ...) (let ((v Exp)) (Type-name 'CASES (syn-err (cases Type-name Exp Clause ...) "undefined datatype: ~s" Type-name) '((cases Type-name Exp Clause ...) v Clause ...)))))) (define-syntax cata (syntax-rules () ((_ Type-name Clause ...) (Type-name 'CATA (syn-err (cata Type-name Clause ...) "undefined datatype: ~s" Type-name) '((cata Type-name Clause ...) Clause ...))))) (define-syntax ana (syntax-rules () ((_ Type-name (formal ...) Body0 Body ...) (Type-name 'ANA (syn-err (ana Type-name (formal ...) Body0 Body ...) "undefined datatype: ~s" Type-name) '((ana Type-name (formal ...) Body0 Body ...) (formal ...) (begin Body0 Body ...)))))) ;;; ------------------------------ ;;; datatype definition ;;; this uses an extremely annoying temporary macro to allow this to ;;; be used both at top-level and within stuff. (define-syntax do-define-datatype (syntax-rules () ((_ Type-name Pred-name (Variant-name (Field-name Pred?) ...) ...) (begin (module ((Type-name dd-rec-variant dd-rec-contents) (annoying-invisible-identifier make-dd-rec dd-rec?)) (define-record dd-rec ((immutable variant) (immutable contents)) () ( ; (print-method ; (let ((name (format "#<~s>" 'Type-name))) ; (lambda (r p wr) ; (if (datatype-transluscent) ; (fprintf p "#<~a:~a>" 'Type-name (dd-rec-variant r)) ; (display name p))))) )) (define-syntax annoying-invisible-identifier (syntax-rules (make check) ((_ make) make-dd-rec) ((_ check) dd-rec?))) (define-syntax Type-name (lambda (x) (syntax-case x (Pred-name quote ANA ANA-DISP CATA CASES C-TEST C-CLAUSE UNROLL else ANA-MAP) ((_ 'CASES Blah '(Src Var Clause (... ...))) #'(let ((tag (dd-rec-variant Var)) (contents (dd-rec-contents Var))) (cond ((Type-name 'C-TEST Clause tag) (Type-name 'C-CLAUSE 'CASES Clause ignored-f contents)) (... ...)))) ((_ 'CATA Blah '(Src Clause (... ...))) #'(rec f (lambda (x) (let ((tag (dd-rec-variant x)) (contents (dd-rec-contents x))) (cond ((Type-name 'C-TEST Clause tag) (Type-name 'C-CLAUSE 'CATA Clause f contents)) (... ...)))))) ((_ 'C-TEST (else Exp . Exps) tag) #'#t) ((_ 'C-TEST (Var-name Formals Exp . Exps) Tag) (equal? (syntax-object->datum #'Var-name) (syntax-object->datum #'Variant-name)) #'(eq? Tag 'Variant-name)) ... ((_ 'C-CLAUSE Ctype (else Exp . Exps) F Contents) #'(begin Exp . Exps)) ((_ 'C-CLAUSE Ctype (Var-name Formals Exp . Exps) F Contents) (equal? (syntax-object->datum #'Var-name) (syntax-object->datum #'Variant-name)) #'(Type-name 'UNROLL Ctype Formals (Pred? ...) F Contents (begin Exp . Exps))) ... ((_ 'UNROLL Ctype () () F Contents Body) #'Body) ((_ 'UNROLL 'CATA (Formals . Restf) (Pred-name . Restp) F V Body) #'(let ((t (car V)) (V (cdr V))) (with-values (F t) (lambda Formals (Type-name 'UNROLL 'CATA Restf Restp F V Body))))) ((_ 'UNROLL XX (Formal . Restf) (YY . Restp) F V Body) #'(let ((Formal (car V)) (V (cdr V))) (Type-name 'UNROLL XX Restf Restp F V Body))) ((_ 'ANA Blah '(Src Formals Body)) (with-capture #'_ (Variant-name ...) #'(rec f (lambda Formals (let-syntax ((Variant-name (syntax-rules () ((_ Arg ((... ...) (... ...))) (Type-name 'ANA-MAP f Variant-name (Pred? ...) (Arg ((... ...) (... ...))))))) ...) Body))))) ((_ 'ANA-MAP F Variant (Pred (... ...)) (Arg (... ...))) #'(Variant (Type-name 'ANA-DISP F Pred Arg) (... ...))) ((_ 'ANA-DISP F Pred-name Arg) #'(F . Arg)) ((_ 'ANA-DISP F Non-recur Arg) #'Arg)))) (record-writer (type-descriptor dd-rec) (let ((name (format "#<~s>" 'Type-name))) (lambda (r p wr) (if (datatype-transluscent) (fprintf p "#<~a:~a>" 'Type-name (dd-rec-variant r)) (display name p)))))) (define Pred-name (lambda (x) ((annoying-invisible-identifier check) x))) (define-constructor Variant-name (annoying-invisible-identifier make) (Field-name ...) (Pred? ...)) ...)))) (define-syntax define-constructor (lambda (x) (syntax-case x () ((_ Variant-name Maker () ()) #'(define Variant-name (lambda () (let ((variant (Maker 'Variant-name '()))) (set! Variant-name (lambda () variant)) variant)))) ((_ Variant-name Maker (Field-name ...) (Pred ...)) (with-syntax (((Temp ...) (generate-temporaries #'(Field-name ...)))) #'(define Variant-name (lambda (Temp ...) (unless (Pred Temp) (error 'Variant-name "bad ~a field: (~s ~s) => #f" 'Field-name 'Pred Temp)) ... (let ((contents (list Temp ...))) (Maker 'Variant-name contents))))))))) ;;; ------------------------------ ;;; errors (define-syntax syn-err (lambda (x) (syntax-case x () ((_ Src Format-string Arg ...) (let ((fs (syntax-object->datum #'Format-string)) (args (map syntax-object->datum #'(Arg ... Src)))) (apply error #f (string-append fs "~n ~a") args)))))) ) (define always? (lambda (x) #t)) (define list-of (lambda (pred . l) (let ((all-preds (cons pred l))) (lambda (obj) (let loop ((obj obj) (preds '())) (or ;; if list is empty, preds should be, too (and (null? obj) (null? preds)) (if (null? preds) ;; if preds is empty, but list isn't, then recycle (loop obj all-preds) ;; otherwise check and element and recur. (and (pair? obj) ((car preds) (car obj)) (loop (cdr obj) (cdr preds)))))))))) (define vector-of (lambda (pred) (lambda (v) (andmap pred (vector->list v))))) #!eof (define-datatype Exp exp? (Var (id symbol?)) (Proc (formal symbol?) (body exp?))) (define free+bound (cata Exp (Var (x) (values (list x) '())) (Proc (formal (bodyfree bodybound)) (values (remove formal bodyfree) (append (if (member formal bodyfree) (list formal) '()) bodybound))))) (define alpha-subst (ana Exp (e env) (cases Exp e (Var (x) (Var (cond ((assv name env) => cdr) (else name)))) (Proc (formal body) (Proc formal [body (cons (formal formal) env)]))))) (define-datatype Lyst lyst? (Nil) (Pair (head integer?) (tail lyst?))) (define make-list (ana Lyst (n) (if (zero? n) (Nil) (Pair 3 [(sub1 n)]))))
true
f11b6f02e7dd90dd903485a6930a1025ed8469d1
3e2f30eba7bc37c77628f5b10229ec6e4a5bcda9
/compiler/stack.ss
6cc862ed87272e6f95fa9a3544d38d01a73e07ed
[]
no_license
luohaha/some-interpreters
ce88706578b56dcbca0b66ae7265ccc59fc4db48
be943da9b25f7d2694f478ace1c021ef38db3676
refs/heads/master
2020-04-06T07:54:27.051677
2016-08-25T04:48:34
2016-08-25T04:48:34
64,315,669
1
0
null
null
null
null
UTF-8
Scheme
false
false
636
ss
stack.ss
(define stack (make-vector 1000)) (define push (lambda (x s) (vector-set! stack s x) (+ s 1))) (define index (lambda (s i) (vector-ref stack (- (- s i) 1)))) (define index-set! (lambda (s i x) (vector-set! stack (- (- s i) 1) x))) (define save-stack (lambda (s) (let ([v (make-vector s)]) (let copy ([i 0]) (if (= i s) v (begin (vector-set! v i (vector-ref stack i)) (copy (+ i 1)))))))) (define restore-stack (lambda (v) (let ([s (vector-length v)]) (let copy ([i 0]) (if (= i s) s (begin (vector-set! stack i (vector-ref v i)) (copy (+ i 1))))))))
false
ac2010cb52efdc0798e46e332047620cd6de4782
86c001154e57121157873d0f1348c540ecea6675
/lib/console.ss
4662fb9f1e5bc9efc8dd8ff33cc86661b1dc14de
[]
no_license
Memorytaco/melt-core
d9d3cd2d38cf4154bd9544a87a02ee0c3d6f765a
e6cf20ae881b33523f17959019d66499ae74c667
refs/heads/master
2020-04-30T02:00:16.058976
2019-04-18T13:24:50
2019-04-18T13:24:50
176,546,164
1
0
null
null
null
null
UTF-8
Scheme
false
false
2,122
ss
console.ss
#!chezscheme (library (melt lib console) (export gem:command gem:text gem:display gem:format gemd:info gemd:warn gemd:error gemd:help gemd:item) (import (scheme) (melt utils) (melt cell)) ;; apply one shell sequence, and it won't reset it (define (gem:command shell-sequence) (string-append (string #\033) shell-sequence)) ;; generate code sequence text string (define (gem:text shell-sequence text) (string-append (gem:command shell-sequence) text (gem:command "[0m"))) ;; just append strings and display it (define gem:display (lambda args (display (apply string-append args)))) ;; first is the format string, others are inserted strings ;; (gem:format template-string assoc-list) ;; assoc-list: ((code-sequence . str) ... ) (define gem:format (lambda args (apply format (flatten (list #t (car args) (map gem:text (map car (cadr args)) (map cdr(cadr args)))))))) ;; display info text (define (gemd:info text) (gem:display (gem:text "[37m" "[") (gem:text "[38;5;155m" "info") (gem:text "[37m" "] ") text "\n")) ;; display warn text (define (gemd:warn text) (gem:display (gem:text "[37m" "{") (gem:text "[38;5;220m" "warn") (gem:text "[37m" "} ") text "\n")) ;; display error text (define (gemd:error text) (gem:display (gem:text "[37m" "(") (gem:text "[38;5;197m" "error") (gem:text "[37m" ") ") text "\n")) ;; display list text (define (gemd:item text) (gem:display (gem:text "[37m" "|") (gem:text "[38;5;103m" "item") (gem:text "[37m" "| ") text "\n")) ;; display help info (define (gemd:help text) (gem:display (gem:text "[37;1m" "%") (gem:text "[38;5;123m" "help") (gem:text "[37;1m" ">> ") text "\n")) )
false
6287bb8f890c29f7f798c01dcdc94d5f1fd46774
b9eb119317d72a6742dce6db5be8c1f78c7275ad
/random-scheme-stuff/rand-linux.scm
82a128aad1cfd04ca549512002b42f94000b8299
[]
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
3,423
scm
rand-linux.scm
;; Generate truly random (i.e., cryptographically strong) numbers, by ;; using Linux's `/dev/random' device. See `random (4)'. ;; Returns LENGTH random characters. ;; If STRONG is #f, generate cryptographically weak random numbers by ;; reading "/dev/urandom". Otherwise, generate cryptographically ;; strong random numbers by reading "/dev/random". ;; If STRONG is not #f, might not return for a while, depending on how ;; much entropy is in the "entropy pool". If it hangs, wiggle the ;; mouse, or hit the shift key a few times; that will probably give it ;; enough entropy to complete. (define (random-character-stream length strong) (with-input-from-file (if strong "/dev/random" "/dev/urandom") (lambda () (let ((so-far (make-string length))) (let loop ((char (read-char)) (chars-read 0)) (if (= chars-read length) so-far (begin (string-set! so-far chars-read char) (loop (read-char) (+ 1 chars-read))))))))) ;; Generates a random integer by converting a random string. It's ;; quite inefficient -- each character in the string only contributes ;; one bit to the random integer. It might seem more reasonable for ;; each character to contribute, say, eight bits, but that would ;; require that I know the number of bits in a character, and in ;; general, I don't know that. Of course there are seven bits in each ;; ASCII character, but how do I know that the character set in use is ;; ASCII? ;; This also assumes that half the characters in the character set are ;; "odd", in the sense of `(odd? (char->integer c))'. This of course ;; is true for ASCII, and is probably true for other character sets, ;; but is not guaranteed. If in fact half the characters are *not* ;; odd, then the numbers will still be random -- i.e., unpredictable ;; -- but they will not be uniformly distributed. (define random-integer (lambda (bits) (define (char->digit c) (if (odd? (char->integer c)) #\1 #\0)) (string->number (list->string (map char->digit (string->list (random-character-stream bits #f)))) 2))) ;; 0 <= (random-float) < 1, uniformly distributed (define random-float (let ((two-to-the-128 (expt 2 128))) (lambda () (/ (random-integer 128) two-to-the-128)))) (define normal-float (let ((two-pi (* 4 (acos 0)))) (lambda () (let ((r (sqrt (* -2 (log (random-float))))) (t (* two-pi (random-float)))) (* r (cos t)))))) (define (call-repeatedly thunk n) (let loop ((so-far '()) (length 0)) (if (= length n) so-far (loop (cons (thunk) so-far) (+ 1 length))))) (define (read-whats-available filename) (with-input-from-file filename (lambda () (define (my-append str used ch) (define (larger str) (string-append str (make-string (+ 1 (string-length str))))) (if (= used (string-length str)) (set! str (larger str))) (string-set! str used ch) str) (let loop ((result "") (chars 0)) (if (not (char-ready?)) (make-shared-substring result 0 chars) (loop (my-append result chars (read-char)) (+ 1 chars)))))))
false
cd18ec429c3c1031ca0d99f20aad38824e6219de
b7ec5209446e33ec4b524c66c4d52ff852e46ae4
/Exemples/Polygones imbriques.scm
da8c8dffdd448010c9f6b383950d4b68b1d178fa
[]
no_license
antjacquemin/physics
a2751f69ee0a54bbb17e46c6bbb2d3b478776136
fd0444c838d097c795fdb1af3a8f3507e810fae5
refs/heads/master
2023-03-31T23:58:49.022201
2020-07-13T09:33:35
2020-07-13T09:33:35
279,257,815
1
0
null
null
null
null
UTF-8
Scheme
false
false
1,554
scm
Polygones imbriques.scm
;***************************************************** ; PROJET PHYSICS ; ANNEE 2008 ; PROGRAMMEURS : F. CORLAIS & A. JACQUEMIN ; MAJ : 27.04.2008 ;***************************************************** ;***************************************************** ; "Polygones imbriques.scm" ; Exemple de la partie "Exemples paramétrés" ; Section "Chocs" ; Des polygones imbriqués les uns dans les autres ;***************************************************** (define POLY2 (make-poly (build-list 7 (lambda (i) (let ((k (* i 2 pi (/ 7.)))) (make-masse 2.8 (make-vect (+ (* 200 (sin k)) 250) (+ (* 200 (cos k)) 250)) 0)))) 0. (make-vect 0 0))) (define POLY3 (make-poly (build-list 5 (lambda (i) (let ((k (* i 2 pi (/ 5.)))) (make-masse 4 (make-vect (+ (* 150 (sin k)) 250) (+ (* 150 (cos k)) 200)) 0)))) 0. (make-vect 0 0))) (define POLY4 (make-poly (build-list 3 (lambda (i) (let ((k (* i 2 pi (/ 3.)))) (make-masse 6.6 (make-vect (+ (* 100 (sin k)) 250) (+ (* 100 (cos k)) 200)) 0)))) 0. (make-vect 0 0))) (define POLY5 (make-poly (build-list 20 (lambda (i) (let ((k (* i 2 pi (/ 20.)))) (make-masse 1 (make-vect (+ (* 22 (sin k)) 250) (+ (* 22 (cos k)) 200)) 0)))) 0. (make-vect 0 0.5))) (set! GRAVITE (make-vect 0 0)) (define POLYGONE_EXS (vector POLY2 POLY3 POLY4 POLY5))
false
e5e5d5d05ee4076bbd29219ed7dd38c577997785
60da79cf89177b72152d8aab846e21e4a5f4644f
/sicp1-3-4.scm
7dc6a011a456405a31f5c6ff28cf9888b07e59a0
[]
no_license
deltam/sicp-reading
6dfa6a608f40085eba5821436a3eaef2d1024b6c
c05c3a97fb201da89890887e6bacef3a1abab41c
refs/heads/master
2021-01-19T14:56:05.349608
2014-05-18T17:56:47
2014-05-18T17:56:47
null
0
0
null
null
null
null
UTF-8
Scheme
false
false
16,714
scm
sicp1-3-4.scm
;;;; 前節で定義した手続き (define (average x y) (/ (+ x y) 2)) (define (square x) (* x x)) (define tolerance 0.0001) (define (fixed-point f first-guess) (define (close-enough? v1 v2) (< (abs (- v1 v2)) tolerance)) (define (try guess) ; (display guess) (newline) ; debug (let ((next (f guess))) (if (close-enough? guess next) next (try next)))) (try first-guess)) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;; 1.3.4 値として返される手続き ;;; 平均緩和法に変換した手続きを返す (define (average-damp f) (lambda (x) (average x (f x)))) ((average-damp square) 10) ;> 55 ;; x^2 -> (x + x^2)/2 ;; (10 + 10^2)/2 = 110/2 = 55. ;; 上記の55は合っている。 ;;; average-dampを使ってsqrtを定義する (define (sqrt-ad x) (fixed-point (average-damp (lambda (y) (/ x y))) 1.0)) (sqrt-ad 2) ;> 1.4142135623746899 ;;; average-dampをつかって三乗根を求める (define (cube-root x) (fixed-point (average-damp (lambda (y) (/ x (square y)))) 1.0)) (cube-root 27) ;> 3.000022143521597 ;;;; Newton法 ;;; 微分の limの下で極限0のやつを以下で近似 (define dx 0.00001) ;;; 1変数関数の手続きを 微分した手続きを 返す手続き (define (deriv g) (lambda (x) (/ (- (g (+ x dx)) (g x)) dx))) ;;; f(x) = x^3 (define (cube x) (* x x x)) ;; Df(x) = 3x^2 ;; Df(5) = 3*5^2 = 75 ((deriv cube) 5) ;> 75.00014999664018 ;; OK! ;;;; Newton法を不動点プロセスとして表す ;;; 1変数手続きを受け取って、Newton法用の手続きに変換して返す ;;; 最初の例でいえば g を受け取って f にして返す (define (newton-transform g) (lambda (x) (- x (/ (g x) ((deriv g) x))))) ;;; Newton法で手続きの零点を探す (define (newtons-method g guess) (fixed-point (newton-transform g) guess)) ;;; テスト:平方根を計算する ;;; y |-> y^2 - x の零点を見つける (define (sqrt x) (newtons-method (lambda (y) (- (square y) x)) 1.0)) (sqrt 2) ;> 1.4142135623822438 ; TODO 不動点見つける が 零点を見つける になる理由説明が必要。 ; TODO 平均緩和法とNewton法のステップ数を比較したい ;;;; 抽象と第一級手続き ;; 平均緩和法もNewton法も「手続きを変換して不動点を見つける」というパターンが同じ。 ;; 処理を共通化できそう ;;; 手続きとそれを変換する手続きを受け取って、不動点を探す (define (fixed-point-of-transform g transform guess) (fixed-point (transform g) guess)) ;;; 平均緩和法で平方根を出す手続きを上記で書きなおす (define (sqrt-fpot-ad x) (fixed-point-of-transform (lambda (y) (/ x y)) average-damp 1.0)) (sqrt-fpot-ad 2) ;> 1.4142135623746899 ;;; Newton法で平方根を出す手続きを上記で書き直す ;; 渡す手続きが違うので注意! (define (sqrt-fpot-nt x) (fixed-point-of-transform (lambda (y) (- (square y) x)) newton-transform 1.0)) (sqrt-fpot-nt 2) ;> 1.4142135623822438 ;; 精度比較 ;ad> 1.4142135623 746899 ;nt> 1.4142135623 822438 ; 1.4142135623 730950488016887242096... ; TODO なんかNewton法のほうが精度悪いんだけど。。。 ;; 抽象化についてのところを3行でまとめる ;; ・プログラムを書く上で抽象化を心がけることは大事 ;; ・でも抽象化しすぎも良くない、ほどよい抽象化ができるように抽象化の方法は覚えておくべき ;; ・高階手続きは、手続きをプログラム言語の要素として表せる抽象化だから便利で重要 ;;;; Lispは手続きに第一級の身分を与えた ;; 第一級要素の「権利と特権」 ;; ・変数として名前が付けられる ;; -> define で手続きに名前が付けられる ;; ・手続きに引数として渡せる ;; -> 渡せる。1.3.1〜3節で確認済み。 ;; ・手続きの結果として返される ;; ->返せる。1.3.4節(今回)で確認済み。 ;; ・データ構造に組み込める ;; ->COMING SOON... ;; 脚注65によると 2章でデータ構造を紹介した後に分かるらしい ;; これらができるとプログラムでプログラムをいろいろ操作できるから大事っぽい ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;; Q 1.40 ;;; 三次式 y = x^3 + ax^2 + bx + c ;;; を計算する手続きを返す (define (cubic a b c) (lambda (x) (+ (cube x) (* a (square x)) (* b x) c))) ;; TEST: y = x^3 ((cubic 0 0 0) 3) ;> 27 ;; TEST: y = x^3 + 1 ((cubic 0 0 1) 3) ;> 28 ;; TEST: y = x^3 + 2x + 1 ((cubic 0 2 1) 3) ;> 34 ;; TEST: y = x^3 + 4x^2 + 2x + 1 ((cubic 4 2 1) 3) ;> 70 ;;; 上記の三次式の零点を計算してみる (newtons-method (cubic 4 2 1) 1) ;> -3.5115471416944994 ;; 検算 ((cubic 4 2 1) -3.5115471416944994) ;> 3.561595462997502e-13 ;; ほぼ 0 ;; OK ;;;; Q 1.41 ;;; 1引数手続きを2回作用させる手続きを返す手続き (define (double f) (lambda (x) (f (f x)))) ;;; 引数に+1する手続き (define (inc x) (+ x 1)) (inc 2) ;> 3 ;; TEST 引数に+2する手続きを返す ((double inc) 5) ;> 7 ;; Q.以下の手続きは何を返すか (((double (double double)) inc) 5) ;; 説明のため、n回作用させる関数をapply-Nと書いて表現する ;(((apply-2 (apply-2 apply-2)) inc) 5) ;(((apply-2 apply-4) inc) 5) ;; (apply-4 (apply-4 ... ;; 4回作用させるのを4回作用させてる ;; 回数は4^2 ;((apply-16 inc) 5) ;; incを16回作用させてる ;; 答えは5+16=21のはず (((double (double double)) inc) 5) ;> 21 ;; OK! ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;; Q 1.42 ;;; 手続きを合成する手続き (define (compose f g) (lambda (x) (f (g x)))) ;; TEST ((compose square inc) 6) ;> 49 ((compose inc inc) 3) ;> 5 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;; Q 1.43 ;;; f をn回作用させる手続き (define (repeated f n) (if (= n 1) f (compose f (repeated f (- n 1))))) ((repeated inc 2) 5) ;> 7 ((repeated square 2) 2) ;> 16 ;;; 最初に書いたバージョン ;; 手続きを値として扱うことに慣れてなかったせい? (define (repeated-first f n) (lambda (x) (define (rec f x2 n) (if (= n 0) x2 (f (rec f x2 (- n 1))))) (rec f x n))) ((repeated-first inc 2) 5) ;> 7 ((repeated-first square 2) 2) ;> 16 ;;; おまけ ;;; repeatedを反復的プロセスで書いてみた (define (repeated-iter f n) (define (iter f n ret) (if (= n 1) ret (iter f (- n 1) (compose f ret)))) (iter f n f)) ((repeated-iter inc 2) 5) ;> 7 ((repeated-iter square 2) 2) ;> 16 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;; Q 1.44 ;; 関数の平滑化 ;;; 手続きを受け取って平滑化した手続きを返す (define (smooth f) (lambda (x) (/ (+ (f (- x dx)) ; dx は微分derivを定義するときにつかったものを流用 (f x) (f (+ x dx))) 3.0))) (square 2) ;> 4 ((smooth square) 2) ;> 4.000000000066667 (sin 1.0) ;> 0.841470984 8078965 ((smooth sin) 1.0) ;> 0.841470984 7798475 ; TODO 平滑化はなにをやっているのか? ;   傾きが少なくなっていく? ; x軸に対して平行に近づいていく? (define (n-fold-smoothed f n) ((repeated smooth n) f)) ; (smooth (smooth .. f) .. ) (square 2) ;> 4 ((n-fold-smoothed square 1) 2) ;> 4.000000000066667 ((n-fold-smoothed square 2) 2) ;> 4.000000000133333 ((n-fold-smoothed square 10) 2) ;> 4.000000000666667 ;((n-fold-smoothed square 20) 2) ;; 返ってこないぞ。。。 (sin 1.0) ;> 0.841470984 8078965 ((n-fold-smoothed sin 1) 1.0) ;> 0.841470984 7798475 ((n-fold-smoothed sin 15) 1.0) ;; 単純に処理が糞重いだけか? (time ((n-fold-smoothed sin 15) 1.0)) ;(time ((n-fold-smoothed sin 15) 1.0)) ; real 2.677 ; user 2.660 ; sys 0.000 ;; いろいろ試した ;(time ((n-fold-smoothed square 15) 2)) ; real 2.120 ; user 2.110 ; sys 0.000 4.000000001 ;(time ((n-fold-smoothed square 16) 2)) ; real 6.339 ; user 6.300 ; sys 0.020 ;(time ((n-fold-smoothed square 20) 2)) ; real 530.126 ; user 523.380 ; sys 1.420 4.000000001333333 ;; 糞重くなる説明 ;; 平滑化1回でf を3回計算している ;; それをさらに平滑化するとfを9回計算することになる ;; n重平滑化はfを3^n回計算する ;; 3^nに手続きが増える ;; 3^10 = 59049 ;; 3^15 = 14348907 ;; 3^20 = 3486784401 ;; n-fold-smoothedのオーダーは、O(3^n) ;; 実行時間で検証 ;; n=15, time=2.120 ;; n=16, time=6.339 ;; 約3倍増えている ;; n=20 time? (* 6.339 (* 3 3 3 3)) ;> 513.4590000000001 ; real 530.126 ;; 大体あってる ;; TODO n重平滑化関数をもっと効率化できないか。 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;; Q 1.45 ;; TODO なぜ4乗根の計算に単一の平均緩和法が使えないのか? ;;; 安全に計算の動きをおうため、計算回数の上限を指定できるように改造した (define (fixed-point-limited f first-guess limit) (define (close-enough? v1 v2) (< (abs (- v1 v2)) tolerance)) (define (try guess count) (let ((next (f guess))) ;; 計算過程を表示する (display count) (display ": ") (display next) (newline) (if (or (= count limit) (close-enough? guess next)) (list count next) ; 計算回数も一緒に返す (try next (+ count 1))))) (try first-guess 1)) ;;; 平均緩和法1回での4乗根計算手続き (define (root4-ad1 x limit) (fixed-point-limited (average-damp (lambda (y) (/ x (* y y y)))) 1.0 limit)) (root4-ad1 16 10) ;> (10 1.8597959434977196) (root4-ad1 16 100) ;> (100 1.9364452032204889) (root4-ad1 16 1000) ;> (1000 1.9781656271972445) ;(time (root4-ad1 81 0)) ; real 176.408 ; user 175.530 ; sys 0.380 ;> (449999982 3.000050001249936) ;; 4乗根を求める場合、「単一の平均緩和法は(中略)収束するのに十分ではない」 ;; とあるけど、収束自体はする。 ただし超遅くなる ;; 不動点を求めるときの関数グラフはできるだけx軸に平行なほうがよい ;; 傾きが0に近く、緩やかに増加していくグラフだとよいはず ;; 不動点よりしたにグラフが下がってるとマズイのか? ;; 不動点より正の方向の関数の値は、増加して行かないとマズイ。 ;; (斜め45度の線より下の値の話し) ;; そうじゃないと不動点をもとめる値が不動点を中心として螺旋状になってしまう。 ;; 不動点の両端から狭めていくから、単純に考えると計算が2倍になる ;; N回平均緩和法したのを微分して最下点を〜とか考えたけどギブアップ! ;; 地道にグラフ書いた結果から発見的に答え出すかと思ったがそれも面倒くさい ;;;; 問題文にあるようにいろいろ実験してみる ;;; 不動点探索が螺旋状になってないかチェックする ;;; 増加or減少が続いたらOK ;;; 増加と減少が交互にきたらNG (define (fixed-point-check f first-guess) (define (close-enough? v1 v2) (< (abs (- v1 v2)) tolerance)) ;; 値の増減を返す (define (value-sign v1 v2) (cond ((< v1 v2) 1) ((> v1 v2) -1) (else 0))) (define (try guess sign) (let ((next (f guess))) ;; letで束縛した変数をlet内で使えないらしい (let ((next-sign (value-sign guess next))) (cond ((= next-sign 0) next) ; すでに不動点 ((= sign next-sign) ; 符号が同じなら単調増加or減少 (display "ok!") (newline) (display sign) (newline) (display guess) (newline) (display next)) ((not (= sign next-sign)) ; 符号が違う=増加減少が交互 (display "NG") (newline) (display sign) (newline) (display next-sign)) (else (if (close-enough? guess next) next (try next next-sign))))))) ;; 初期値によって増加減少が変わるので、何度か計算してから探索を始める (let ((guess1 (f (f first-guess))) (guess2 (f (f (f first-guess))))) (try guess2 (value-sign guess1 guess2)))) ;; 4乗根の計算で実験する ;; 平均緩和法1回の場合 (fixed-point-check (average-damp (lambda (y) (/ 2.0 (* y y y)))) 1.0) ;; 平均緩和法2回の場合 (fixed-point-check (average-damp (average-damp (lambda (y) (/ 2.0 (* y y y))))) 1.0) ;;; 平均緩和法をm回適用してn乗根を見つける手続き ;;; 平均緩和法の適用回数を特定するための実験版 (define (root-n-test x n m) (fixed-point-check ((repeated average-damp m) (lambda (y) (/ x (expt y (- n 1))))) ; exptはべき乗関数 1.0)) ;; 4乗根 平均緩和法1回適用 (root-n-test 8.0 4 1) ;> NG ;-1 ;1#<undef> ;; 4乗根 平均緩和法2回適用 (root-n-test 8.0 4 2) ;> ok! ;-1 ;1.8178268004543974 ;1.6963150945303935#<undef> ;; 5乗根のテスト 3回適用でOK (root-n-test 2.0 5 1) ; NG (root-n-test 2.0 5 2) ; NG (root-n-test 2.0 5 3) ; OK! ;; 6乗根のテスト (root-n-test 2.0 6 1) ; NG (root-n-test 2.0 6 2) ; NG (root-n-test 2.0 6 3) ; OK! ;; 7乗根のテスト (root-n-test 2.0 7 1) ; NG (root-n-test 2.0 7 2) ; NG (root-n-test 2.0 7 3) ; OK! ;; 8乗根のテスト (root-n-test 2.0 8 1) ; NG (root-n-test 2.0 8 2) ; NG (root-n-test 2.0 8 3) ; OK! ;; 20乗根のテスト (root-n-test 2.0 20 1) ; NG (root-n-test 2.0 20 2) ; NG (root-n-test 2.0 20 3) ; NG (root-n-test 2.0 20 4) ; NG (root-n-test 2.0 20 5) ; OK! ;; もしかしてn乗根の平均緩和法適用回数はnの平方根なんでは? ;; ー>ダメでした ;; 100乗根 (root-n-test 2.0 100 6) ; NG (root-n-test 2.0 100 7) ; ok! (root-n-test 2.0 100 8) ; ok! (root-n-test 2.0 100 9) ; ok! ;; 1000乗根 (root-n-test 2.0 1000 6) ; NG (root-n-test 2.0 1000 7) ; NG (root-n-test 2.0 1000 8) ; NG (root-n-test 2.0 1000 9) ; NG (root-n-test 2.0 1000 10) ; ok! ;; カンニングした結果と実験結果をもとにすると1000乗根の平均緩和法の回数はこうなる (ceiling (/ (log 1000) (log 2))) ;> 10.0 ;; なぜこうなるか、その説明は./1-3-4/root-n-calc.pdfにまとめておいた ;;; n乗根を探す手続き (define (root-n x n) (fixed-point ((repeated average-damp ;; 回数:2を底とするlog nの小数点以下切上げ (ceiling (/ (log n) (log 2)))) (lambda (y) (/ x (expt y (- n 1))))) ; exptはべき乗 1.0)) ;; test (root-n 2 2) ;> 1.4142135623746899 (root-n 27 3) ;> 3.0000234260125787 (root-n 256 8) ;> 2.0000000000039666 (root-n 65536 16) ;> 2.000000000076957 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;; Q 1.46 ;;;; 反復改良法を一般化する ;;; 予測値の良好さチェック手続きと、予測値改良手続きを受け取り、予測値を改良する手続きを返す (define (iterative-improve good-enough? improve) (lambda (first-guess) (define (iter guess) (let ((next (improve guess))) (if (good-enough? guess next) next (iter next)))) (iter first-guess))) ;;; 1.1.7節のsqrtをiterative-improveをつかって書き直す (define (sqrt-ii x) ((iterative-improve (lambda (v1 v2) (< (abs (- v1 v2)) tolerance)) ; fixed-pointで使ってるやつ (lambda (v) (average v (/ x v)))) 1.0)) (sqrt-ii 2) ;> 1.4142135623746899 (sqrt-ii 3) ;> 1.7320508100147274 (sqrt-ii 25) ;> 5.000000000053722 (sqrt-ii 49) ;> 7.000000000000002 (sqrt-ii 144) ;> 12.0 ;;; 1.3.3節のfixed-pointをiterative-improveをつかって書きなおす (define (fixed-point-ii f first-guess) ((iterative-improve (lambda (v1 v2) (< (abs (- v1 v2)) tolerance)) f) first-guess)) ;; TEST cos (fixed-point cos 1.0) ;> 0.7390547907469174 (fixed-point-ii cos 1.0) ;> 0.7390547907469174 ;; OK ;;;; 第1章 終了! ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
false
98aaac46e24747d3504779e4a6daca1ae2261a09
223f8e07bd9fd7d43e4b8a6e7413e1d53c47ce4c
/lib/chibi/show.sld
04b2dcb9de58da6dfd3c8c342eb53435fb84031a
[ "BSD-3-Clause" ]
permissive
norton-archive/chibi-scheme
d5092480d22396ad63aae96c58b6e8e0e99103ed
38b8a6056c0b935dc8eb0d80dd774dde871757ef
refs/heads/master
2021-06-14T22:34:12.096599
2016-09-28T14:31:06
2016-09-28T14:31:06
33,801,264
3
0
null
null
null
null
UTF-8
Scheme
false
false
541
sld
show.sld
(define-library (chibi show) (export show fn fn-fork with update! each each-in-list call-with-output displayed written written-shared written-simply numeric nothing nl fl space-to tab-to padded padded/left padded/right padded/both trimmed trimmed/left trimmed/right trimmed/both trimmed/lazy fitted fitted/left fitted/right fitted/both joined joined/prefix joined/suffix joined/last joined/dot upcased downcased) (import (scheme base) (scheme char) (chibi show base) (scheme write)) (include "show/show.scm"))
false
f5e211b1d599d1421d40141857855810f8be1acf
ac2a3544b88444eabf12b68a9bce08941cd62581
/lib/termite/match#.scm
d6cb62f36f43035cd6c9e5450109751496727f97
[ "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
839
scm
match#.scm
(##namespace ("termite/match#" match/action match)) (define-macro (match/action on-success on-fail datum . clauses) (##import termite/match-support) (let ((tmp (gensym)) (succ (gensym)) (fail (gensym))) `(let ((,tmp ,datum) (,succ (lambda () ,on-success)) ;; the thunk for success is lifted (,fail (lambda () ,on-fail))) ;; the thunk for failure is lifted ,(compile-pattern-match `(,succ) `(,fail) clauses tmp)))) (define-macro (match datum . clauses) (##import termite/match-support) (let ((tmp (gensym)) (fail (gensym))) `(let* ((,tmp ,datum) (,fail (lambda () (raise (list bad-match: ,tmp))))) ,(compile-pattern-match #f `(,fail) clauses tmp))))
false
1e5bb28a711906ae274427f556a04602fe06d39c
f03b4ca9cfcdbd0817ec90869b2dba46cedd0937
/figure/core.scm
bcabf5045ff39bb1a1e987618eeb8495f148e779
[]
no_license
lrsjohnson/upptackt
d696059263d18cd7390eb7c3d3650954f0b5f732
9bfd2ec70b82116701e791620ab342f3e7d9750e
refs/heads/master
2021-01-19T00:08:06.163617
2015-06-24T14:01:03
2015-06-24T14:01:03
31,883,429
2
0
null
null
null
null
UTF-8
Scheme
false
false
1,104
scm
core.scm
;;; core.scm --- Core definitions used throughout the figure elements ;;; Commentary: ;; Ideas: ;; - Some gemeric handlers used in figure elements ;; Future: ;; - figure-element?, e.g. ;;; Code: ;;;;;;;;;;;;;;;;;;;;;;;;; Element Component ;;;;;;;;;;;;;;;;;;;;;;;;;; (define element-component (make-generic-operation 2 'element-component (lambda (el i) (error "No component procedure for element" el)))) (define (component-procedure-from-getters . getters) (let ((num-getters (length getters))) (lambda (el i) (if (not (<= 0 i (- num-getters 1))) (error "Index out of range for component procedure: " i)) ((list-ref getters i) el)))) (define (declare-element-component-handler handler type) (defhandler element-component handler type number?)) (declare-element-component-handler list-ref list?) #| Example Usage: (declare-element-component-handler (component-procedure-from-getters car cdr) pair?) (declare-element-component-handler vector-ref vector?) (element-component '(3 . 4 ) 1) ;Value: 4 (element-component #(1 2 3) 2) ;Value: 3 |#
false
f5af897c384e41907d808093be3ccda618c35050
b26941aa4aa8da67b4a7596cc037b92981621902
/SICP/sicp_backup_2013_11_04_13_55.scm
f62bde6c36756fb0c2f9aff10daac9ad7e5129ca
[]
no_license
Alaya-in-Matrix/scheme
a1878ec0f21315d5077ca1c254c3b9eb4c594c10
bdcfcf3367b664896e8a7c6dfa0257622493e184
refs/heads/master
2021-01-01T19:42:32.633019
2015-01-31T08:24:02
2015-01-31T08:24:02
22,753,765
0
0
null
null
null
null
UTF-8
Scheme
false
false
17,402
scm
sicp_backup_2013_11_04_13_55.scm
(load "ch2support.scm") (load "complex_package.scm") (load "types.scm") (load "coercion.scm"); (load "common-define.scm"); ;;================================================= (define (install) (install-polynomial-package) (install-raise) (install-polar-package) (install-rectangular-package) (install-complex-package) (install-rational-package) (install-scheme-number-package)) (define (add x y) (apply-generic 'add x y)) (define (sub x y) (apply-generic 'sub x y)) (define (mul x y) (apply-generic 'mul x y)) (define (div x y) (apply-generic 'div x y)) (define (exp x y) (apply-generic 'exp x y)) ;;整数包 (define (install-scheme-number-package) (define (tag x) (attach-tag 'scheme-number x)) (put 'add '(scheme-number scheme-number) (lambda (x y) (+ x y))) (put 'sub '(scheme-number scheme-number) (lambda (x y) (- x y))) (put 'mul '(scheme-number scheme-number) (lambda (x y) (* x y))) (put 'div '(scheme-number scheme-number) (lambda (x y) (/ x y))) (put 'make 'scheme-number (lambda (x) (tag x))) ;;============================================ (put '=zero? '(scheme-number) (lambda (x) (= x 0))) (put 'exp '(scheme-number scheme-number) (lambda (x y) (tag (expt x y)))) (put 'neg '(scheme-number) (lambda (x) (* x -1))) ;;============================================ 'done) (define (make-scheme-number n) ((get 'make 'scheme-number) n)) ;;有理数包 (define (install-rational-package) ;;internal procedures (define (numer x) (car x)) (define (denom x) (cdr x)) (define (make-rat n d) (let ((g (abs (gcd n d)))) (cons (/ n g) (/ d g)))) (define (add-rat x y) (make-rat (+ (* (numer x) (denom y)) (* (numer y) (denom x))) (* (denom x) (denom y)))) (define (sub-rat x y) (make-rat (- (* (numer x) (denom y)) (* (numer y) (denom x))) (* (denom x) (denom y)))) (define (mul-rat x y) (make-rat (* (numer x) (numer y)) (* (denom x) (denom y)))) (define (div-rat x y) (make-rat (* (numer x) (denom y)) (* (denom x) (numer y)))) ;; interface to rest of the system (define (tag x) (attach-tag 'rational x)) (put 'numer '(rational) numer) (put 'denom '(rational) denom) (put 'add '(rational rational) (lambda (x y) (tag (add-rat x y)))) (put 'sub '(rational rational) (lambda (x y) (tag (sub-rat x y)))) (put 'mul '(rational rational) (lambda (x y) (tag (mul-rat x y)))) (put 'div '(rational rational) (lambda (x y) (tag (div-rat x y)))) (put 'make 'rational (lambda (n d) (tag (make-rat n d)))) ;;========================================= (put '=zero? '(rational) (lambda (r) (= (numer r) 0))) (put 'neg '(rational) (lambda (r) (tag (make-rat (* -1 (numer r)) (denom r))))) ;;======================================== 'done) (define (make-rational n d) ((get 'make 'rational) n d)) (define (numer x) (apply-generic 'numer x)) (define (denom x) (apply-generic 'denom x)) ;;复数包 (define (install-complex-package) ;;my_code ;;(install-rectangular-package) ;;(install-polar-package) ;;imported procedures from rectangular and polar packages (define (make-from-real-imag x y) ((get 'make-from-real-imag 'rectangular) x y)) (define (make-from-mag-ang r a) ((get 'make-from-mag-ang 'polar) r a)) ;;internal procedures (define (add-complex z1 z2) (make-from-real-imag (+ (real-part z1) (real-part z2)) (+ (imag-part z1) (imag-part z2)))) (define (sub-complex z1 z2) (make-from-real-imag (- (real-part z1) (real-part z2)) (- (imag-part z1) (imag-part z2)))) (define (mul-complex z1 z2) (make-from-mag-ang (* (magnitude z1) (magnitude z2)) (+ (angle z1) (angle z2)))) (define (div-complex z1 z2) (make-from-mag-ang (/ (magnitude z1) (magnitude z2)) (- (angle z1) (angle z2)))) ;; interface to rest of the system (define (tag z) (attach-tag 'complex z)) (put 'add '(complex complex) (lambda (z1 z2) (tag (add-complex z1 z2)))) (put 'sub '(complex complex) (lambda (z1 z2) (tag (sub-complex z1 z2)))) (put 'mul '(complex complex) (lambda (z1 z2) (tag (mul-complex z1 z2)))) (put 'div '(complex complex) (lambda (z1 z2) (tag (div-complex z1 z2)))) (put 'make-from-real-imag 'complex (lambda (x y ) (tag (make-from-real-imag x y)))) (put 'make-from-mag-ang 'complex (lambda (r a) (tag (make-from-mag-ang r a)))) ;;+++++++++++++++++++++++++++++++++ (put 'real-part '(complex) real-part) (put 'imag-part '(complex) imag-part) (put 'magnitude '(complex) magnitude) (put 'angle '(complex) angle) ;;++++++++++++++++++++++++++++++++ (put '=zero? '(complex) (lambda (z) (= (magnitude z) 0))) (put 'neg '(complex) (lambda (z) (tag (make-from-real-imag (* -1 (real-part z)) (* -1 (imag-part z)))))) ;;++++++++++++++++++++++++++++++++ 'done) (define (make-complex-from-real-imag x y) ((get 'make-from-real-imag 'complex) x y)) (define (make-complex-from-mag-ang r a) ((get 'make-from-mag-ang 'complex) r a)) ;;2.78 (define (attach-tag type content) (if (number? content) content (cons type content))) (define (type-tag datum) (cond ((pair? datum) (car datum)) ((number? datum) 'scheme-number) (else (error "Bad typed datum -- TYPE-TAG" datum)))) (define (contents datum) (cond ((pair? datum) (cdr datum)) ((number? datum) datum) (else (error "Bad typed datum -- CONTENTS" datum)))) ;;2.79 (define (equ? x1 x2) (let ((sub_result (sub x1 x2))) (=zero? sub_result))) ;;2.80 (define (=zero? num) (apply-generic '=zero? num)) (define (apply-generic op . args) (let ((type-tags (map type-tag args))) (let ((proc (get op type-tags))) (if proc (apply proc (map contents args)) (if (= (length args) 2) ;;目前只能支持两个参数的问题 (let ((type1 (car type-tags)) (type2 (cadr type-tags)) (a1 (car args)) (a2 (cadr args))) (let ((t1->t2 (get-coercion type1 type2)) (t2->t1 (get-coercion type2 type1))) (cond (t1->t2 (apply-generic op (t1->t2 a1) a2)) (t2->t1 (apply-generic op a1 (t2->t1 a2))) (else (error "No method for these types" (list op type-tags)))))) (error "No method for these types" (list op type-tags))))))) ;;2.81 ;;(a) 会死循环 ;;(b) 会死循环,无法正常工作 ;;(c) (define (apply-generic op . args) (let ((type-tags (map type-tag args))) (let ((proc (get op type-tags))) (if proc (apply proc (map contents args)) (if (= (length args) 2) ;;目前只能支持两个参数的问题 (let ((type1 (car type-tags)) (type2 (cadr type-tags))) (if (not (equal? type1 type2)) (let ((a1 (car args)) (a2 (cadr args)) (t1->t2 (get-coercion type1 type2)) (t2->t1 (get-coercion type2 type1))) (cond (t1->t2 (apply-generic op (t1->t2 a1) a2)) (t2->t1 (apply-generic op a1 (t2->t1 a2))) (else (error "No method for these types" (list op type-tags))))) (error "No method for these types" (list op type-tags)))) (error "No method for these fucking types" (list op type-tags))))))) ;; 2.82 ;; 应该找到共同的基类? ;;2.83 ;;(define (raise num) (apply-generic 'raise num)) 可以这样定义,然后相应的过程在相关的包中定义 ;;但是,2.84要求用raise重新定义apply-generic,其实也不会造成任何问题,但觉得这是不好的style (define (install-raise) (put 'raise '(complex) (lambda (z) (make-polynomial 'x (list (list 0 z))))) (put 'raise '(scheme-number) (lambda (n) (make-rational n 1))) (put 'raise '(rational) (lambda (r) (make-complex-from-real-imag (/ (numer r) (denom r)) 0)))) (define (raise x) (let ((proc (get 'raise (list (type-tag x))))) (if proc (proc x) #f))) ;;2.84 (define (apply-generic op . args) (define (coerce-into s t) (let ((type_s (type-tag s)) (type_t (type-tag t))) (cond ((equal? type_s type_t) s) (else (if (not (get 'raise (list type_s))) #f (coerce-into (raise s) t)))))) (let ((type_tags (map type-tag args))) (let ((proc (get op type_tags))) (if proc (apply proc (map contents args)) (if (= (length args) 2) (let ((type_1 (car type_tags)) (type_2 (cadr type_tags))) (if (not (equal? type_1 type_2)) (let ((a1 (car args)) (a2 (cadr args))) (cond ((coerce-into a1 a2) (apply-generic op (coerce-into a1 a2) a2)) ((coerce-into a2 a1) (apply-generic op a1 (coerce-into a2 a1))) (else (error "No method for these types" (list op type_tags))))) (error "No method for these types" (list op type_tags)))) (error "No method for these types" (list op type_tags))))))) ;;2.5.3 (define (install-polynomial-package) ;;internal procedures ;;representation of poly (define (make-poly variable term-list) (cons variable term-list)) (define (variable p) (car p)) (define (term-list p) (cdr p)) (define (variable? x) (symbol? x)) (define (same-variable? v1 v2) (and (variable? v1) (variable? v2) (eq? v1 v2))) (define (add-terms L1 L2) (cond ((empty-termlist? L1) L2) ((empty-termlist? L2) L1) (else (let ((t1 (first-term L1)) (t2 (first-term L2))) (cond ((> (order t1) (order t2)) (adjoin-term t1 (add-terms (rest-terms L1) L2))) ((< (order t1) (order t2)) (adjoin-term t2 (add-terms L1 (rest-terms L2)))) (else (adjoin-term (make-term (order t1) (add (coeff t1) (coeff t2))) (add-terms (rest-terms L1) (rest-terms L2))))))))) (define (mul-terms L1 L2) (if (empty-termlist? L1) (the-empty-termlist) (add-terms (mul-term-by-all-terms (first-term L1) L2) (mul-terms (rest-terms L1) L2)))) (define (mul-term-by-all-terms t1 L) (if (empty-termlist? L) (the-empty-termlist) (adjoin-term (make-term (+ (order t1) (order (first-term L))) ;;此处似乎用"add"代替"+"也可以吧,而且通用性会好,不过课本代码如此 (mul (coeff t1) (coeff (first-term L)))) (mul-term-by-all-terms t1 (rest-terms L))))) (begin "debug" (put 'mul-term-by-all-terms '(term term-list) mul-term-by-all-terms)) (define (negate-terms L) (map (lambda (term) (make-term (order term) (neg (coeff term)))) L)) (define (div-terms L1 L2) (if (empty-termlist? L1) (list (the-empty-termlist) (the-empty-termlist)) (let ((t1 (first-term L1)) (t2 (first-term L2))) (if (> (order t2) (order t1)) (list (the-empty-termlist) L1) (let ((new-term (make-term (- (order t1) (order t2)) (div (coeff t1) (coeff t2))))) (let ((rest-of-result (div-terms (add-terms L1 (mul-term-by-all-terms new-term (negate-terms L2))) L2))) (list (adjoin-term new-term (car rest-of-result)) (cadr rest-of-result)))))))) (define (div-poly p1 p2) (if (same-variable? (variable p1) (variable p2)) (map (lambda (L) (make-poly (variable p1) L)) (div-terms (term-list p1) (term-list p2))) (error "Polys not in same var -- DIV-POLY" (list p1 p2)))) (define (the-empty-termlist) '()) (define (first-term term-list) (car term-list)) (define (rest-terms term-list) (cdr term-list)) (define (empty-termlist? term-list) (null? term-list)) (define (make-term order coeff) (list order coeff)) (define (order term) (car term)) (define (coeff term) (cadr term)) (define (adjoin-term term term-list) ;;要保证希望加入term-list中的term的order高于原term-list中的所有项 (if (=zero? (coeff term)) term-list (cons term term-list))) (define (add-poly p1 p2) ;;多项式用一种称为poly的数据结构表示 (if (same-variable? (variable p1) (variable p2)) (make-poly (variable p1) (add-terms (term-list p1) (term-list p2))) (error "Ploys not in save var -- ADD-POLY" (list p1 p2)))) (define (mul-poly p1 p2) (if (same-variable? (variable p1) (variable p2)) (make-poly (variable p1) (mul-terms (term-list p1) (term-list p2))) (error "Ploys not in same var -- MUL-POLY" (list p1 p2)))) (define (coerce-poly p var) (if (=zero-poly? p) (the-empty-termlist) (let ((now-var (variable p))) (if (same-variable? var now-var) (term-list p) (let ((L (term-list p))) (let ((t (first-term L)) (rest (rest-terms L))) (let ((o (order t)) (c (coeff t))) (let ((t1 (make-term 0 (make-polynomial now-var (adjoin-term (make-term o 1) (the-empty-termlist))))) (L1 (if (equal? (type-tag c) 'polynomial) ;;not satisfying style (let ((content (contents c))) (if (same-variable? var (variable content)) (term-list content) (coerce-poly content var))) (adjoin-term (make-term 0 c) (the-empty-termlist))))) (display (list "L" L)) (newline) (display (list "t" t)) (newline) (display (list "o" o)) (newline) (display (list "c" c)) (newline) (display (list "t1" t1)) (newline) (display (list "L1" L1)) (newline) (add-terms (mul-term-by-all-terms t1 L1) (coerce-poly (make-poly now-var rest) var)))))))))) (put 'coerce-poly '(polynomial var) coerce-poly) (define (tag p) (attach-tag 'polynomial p)) ;; (put 'add '(polynomial polynomial) ;; (lambda (p1 p2) (tag (add-poly p1 p2)))) (put 'add '(polynomial polynomial) (lambda (p1 p2) (tag (add-poly p1 (make-poly (variable p1) (coerce-poly p2 (variable p1))))))) ;; (put 'mul '(polynomial polynomial) ;; (lambda (p1 p2) (tag (mul-poly p1 p2)))) (put 'mul '(polynomial polynomial) (lambda (p1 p2) (tag (mul-poly p1 (make-poly (variable p1) (coerce-poly p2 (variable p1))))))) (put 'make '(polynomial) (lambda (var terms) (tag (make-poly var terms)))) ;;======================================================= (define (=zero-poly? p) (let ((L (term-list p))) (or (empty-termlist? L) (and (=zero? (coeff (first-term L))) (=zero-poly? (make-poly (variable p) (rest-terms L))))))) (put '=zero? '(polynomial) =zero-poly?) ;; (lambda (p) (empty-termlist? (term-list p))));;term为(0 0)时会出错,不过运算结果不会错 (define (negate p) ;;这个解法丧失了通用型,只适用于termlist是用list来表示时,可以参考Eli Bendersky的解法 (make-poly (variable p) ;;比如,当多项式用稠密多项式的表示法时,似乎就不能这样用了 (map (lambda (term) (make-term (order term) (neg (coeff term)))) (term-list p)))) (put 'neg '(polynomial) (lambda (p) (tag (negate p)))) (put 'sub '(polynomial polynomial) (lambda (p1 p2) (tag (add-poly p1 (negate p2))))) (put 'div '(polynomial polynomial) (lambda (p1 p2) (map tag (div-poly p1 p2)))) (put 'div-result '(polynomial polynomial) (lambda (p1 p2) (tag (car (div-poly p1 p2))))) (put 'p-remainder '(polynomial polynomial) (lambda (p1 p2) (tag (cadr (div-poly p1 p2))))) ;;======================================================= 'done) (define (fuck x y) (apply-generic 'fuck x y)) (define (make-polynomial var terms) ((get 'make '(polynomial)) var terms)) (define (div-result p1 p2) (apply-generic 'div-result p1 p2)) (define (p-remainder p1 p2) (apply-generic 'p-remainder p1 p2)) ;;2.87 ;;已经安装在install-polynomial-package中 ;;2.88 (define (neg x) (apply-generic 'neg x)) ;;2.89 ;;在2.90中做掉吧! ;; ;;2.90 ;;不想做了怎么办 ;;2.91 ;;多项式除法 ;;2.92 ;;(define (coerce-poly p var) ;;p是没有tag的polynomial,var是新的变元符号,返回以新符号为变元的项表 ;; (let ((now-var (variable p))) ;; (if (same-varialbe? var now-var) ;; (term-list p) ;; (let ((L (term-list p))) ;; (let ((t (first-term L)) ;; (rest (rest-terms L))) ;; (let ((o (order t)) ;; (c (coeff t))) ;; (let ((t1 (make-term 0 ;; (make-polynomial now-var (adjoin-term (make-term o 1) ;; (the-empty-termlist))))) ;; (L1 (if (equal? (type-tag c) 'polynomial) ;; (let ((content (contents c))) ;; (if (same-variable? var (variable content)) ;; (term-list content) ;; (coerce-poly content var))) ;; (adjoin-term (make-term 0 c) ;; (the-empty-termlist))))) ;; (add-terms (mul-term-by-all-terms t1 L1) ;; (coerce-poly (make-poly now-var rest) var))))))))) ;; ;; (define (coerce-poly p var) ((get 'coerce-poly '(polynomial var)) (contents p) var)) (define (mul-term-by-all-terms t L) ((get 'mul-term-by-all-terms '(term term-list)) t L))
false
69bc1a58e581a0d500a9bd8f7ed3d5680eaaa265
6838bac9a2c58698df1ed964b977ac0ab8ee6c55
/legacy/portability.scm
2fea32c8a04612603bed00b83c883bb32ae1d82a
[ "MIT", "LicenseRef-scancode-public-domain" ]
permissive
jpt4/nocko
4be73b1945927bcb50fd16ebffa35736aa9a9d07
d12d569adc0c39e4fc5cfdbdd8c4b833f493cee2
refs/heads/master
2023-06-07T21:38:15.084127
2023-06-02T03:59:31
2023-06-02T03:59:31
36,998,031
0
0
null
null
null
null
UTF-8
Scheme
false
false
154
scm
portability.scm
;; portability.scm jpt4 UTC20151108 ;; Scheme functions not necessarily present in all implementations. ;; guile (define (atom? a) (not (pair? a)))
false
a6f4b1e429443e08b8de6a4cfb0ea3c76027d9aa
314ebaed53c58ca25553493222fec30942d08803
/chapter4/4.1/4.11.ss
f0a38cf0f2c2520f12976971411c648affdf0e48
[]
no_license
Cltsu/SICP
45dc6a003e6977e6b7e339f7ff71a00638a28279
92402f2e6f06be5c967d60590c7bf13b070f0a5e
refs/heads/master
2021-02-08T08:31:30.491089
2020-06-17T13:32:37
2020-06-17T13:32:37
244,130,747
0
0
null
null
null
null
UTF-8
Scheme
false
false
1,768
ss
4.11.ss
;4.11 (define (make-frame vars vals) (if (null? vars) '() (cons (cons (car vars) (car vals)) (make-frame (cdr vars) (cdr vals))))) (define (first-pair frame) (car frame)) (define (rest-pairs frame) (cdr frame)) (define (add-binding-to-frame! var val frame) (cons (cons (var val)) frame)) (define (lookup-var-val var env) (define (scan pairs) (cond ((null? pairs) (lookup-var-val var (enclosing-environment env))) ((eq? (car (first-pair pairs)) var) ((cdr (first-pair pairs)))) (else (scan (rest-pairs pairs))))) (if (eq? env the-empty-environment) (error "can't find var" var) (let ((frame (first-frame env))) (scan frame)))) (define (set-var-val! var val env) (define (env-loop env) (define (scan pairs) (let ((cur (first-pair pairs)) (rest (rest-pairs pairs))) (cond ((null? pairs) (env-loop (enclosing-environment env))) ((eq? (car cur) var) (set-cdr! cur val)) (else (scan rest))))) (if (eq? the-empty-environment env) (error "can't find var" var) (scan (first-frame env)))) (env-loop env)) (define (define-var! var val env) (let ((frame (first-frame env))) (define (scan pairs) (let ((cur (first-pair pairs)) (rest (rest-pairs pairs))) (cond ((null? pairs) (add-binding-to-frame! var val frame)) ((eq? var (car cur)) (set-cdr! cur val)) (else (scan rest))))) (scan frame)))
false
712d77d08cafc4a412d702c627aa5f7dd927fc8a
4b480cab3426c89e3e49554d05d1b36aad8aeef4
/chapter-03/ex3.01-falsetru-test.scm
640e859925a93e369c35a7f4546014429685d8ce
[]
no_license
tuestudy/study-sicp
a5dc423719ca30a30ae685e1686534a2c9183b31
a2d5d65e711ac5fee3914e45be7d5c2a62bfc20f
refs/heads/master
2021-01-12T13:37:56.874455
2016-10-04T12:26:45
2016-10-04T12:26:45
69,962,129
0
0
null
null
null
null
UTF-8
Scheme
false
false
480
scm
ex3.01-falsetru-test.scm
(require (planet schematics/schemeunit:3)) (require (planet schematics/schemeunit:3/text-ui)) (load "ex3.01-falsetru.scm") (define ex3.01-falsetru-tests (test-suite "Test for ex3.01-falsetru" (test-case "accumulator" (define A (make-accumulator 5)) (define B (make-accumulator 10)) (check-equal? (A 10) 15) (check-equal? (A 10) 25) (check-equal? (B 10) 20) ) )) (exit (cond ((= (run-tests ex3.01-falsetru-tests) 0)) (else 1)))
false
e7043c74211f7ad24a7def4bdd783a560ff396e7
018a7ce673c5be3cf3df61bd5c5036581d6646a7
/spec/fail/bad-library-names.scm
bddf70af40f6364aeeea76583ccd7d7abde449d7
[ "MIT" ]
permissive
iwillspeak/feersum
e857deec2b8683960f9ac6d1f395fb5f625204a8
1602e8333aa11c0335c9775c0ab49bf01389ba98
refs/heads/main
2023-08-07T17:15:19.843607
2023-06-20T06:28:28
2023-06-20T06:28:28
223,348,583
31
2
MIT
2023-06-10T21:29:11
2019-11-22T07:33:04
F#
UTF-8
Scheme
false
false
207
scm
bad-library-names.scm
(define-library "hello") (define-library .) (define-library (scheme |silly'chars|)) (define-library (some 't)) (define-library (srfi trust me)) (define-library (missing export) (export we |don't| exist))
false
6824a02d395489ee2645aa273f3a5c4998cd6075
97ad1c64e387c302e7f876deae58835d6e2d87a7
/sqlite3-common.scm
ccef42db8c1a991862f0a88103434379d8f19b18
[]
no_license
mbenelli/gambit-sqlite3
3f090169df9350036f812b92d8848716993b1bbc
18dc75386508b35a806b06ffe65149f27f0db1d4
refs/heads/master
2021-01-22T09:58:24.593844
2014-02-23T18:48:31
2014-02-23T18:48:31
6,816,162
2
0
null
null
null
null
UTF-8
Scheme
false
false
3,865
scm
sqlite3-common.scm
;; Gambit-c's sqlite3 binding. High-level interface. ;; ;; Copyright (c) 2008, Marco Benelli <[email protected]> ;; All rights reserved. ;; ;; Redistribution and use in source and binary forms, with or without ;; modification, are permitted provided that the following conditions ;; are met: ;; ;; Redistributions of source code must retain the above copyright ;; notice, this list of conditions and the following disclaimer. ;; ;; 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. ;; ;; Neither the name of the author nor the names of its contributors ;; may be used to endorse or promote products derived from this ;; software without specific prior written permission. ;; ;; 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 ;; HOLDERS 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. (define sqlite3 #f) (let () ;;; Utils (define (iota n . opt) (let ([%iota (lambda (start count step) (let loop ([i start] [res '()]) (if (= (length res) count) (reverse res) (loop (+ i step) (cons i res)))))]) (cond [(null? opt) (%iota 0 n 1)] [(= (length opt) 1) (%iota (car opt) n 1)] [(= (length opt) 2) (%iota (car opt) n (cadr opt))] [else (error "iota: wrong argument number.")]))) ;;; Constants (define (sqlite-integer? x) (eq? x 1)) (define (sqlite-float? x) (eq? x 2)) (define (sqlite-text? x) (eq? x 3)) (define (sqlite-blob? x) (eq? x 4)) (define (sqlite-null? x) (eq? x 5)) (define (sqlite-busy? x) (eq? x 5)) (define (sqlite-row? x) (eq? x 100)) (define (sqlite-done? x) (eq? x 101)) (define (open name) (let ([db (%sqlite3-open name)]) (if (zero? (sqlite3-errcode db)) db (raise (sqlite3-errmsg db))))) ;;; Result handling (define (process-row query ncol fn seed) (let ([get-item (lambda (i) (let ([x (sqlite3-column-type query i)]) (cond [(sqlite-integer? x) (sqlite3-column-int query i)] [(sqlite-float? x) (sqlite3-column-double query i)] [(sqlite-text? x) (sqlite3-column-text query i)] [(sqlite-blob? x) (sqlite3-column-blob query i)] [(sqlite-null? x) #f])))]) (apply fn (cons seed (map get-item (iota ncol)))))) ; Interface ; fn: seed col col ... -> continue? new-seed (define (db-fold-left db fn seed query) (let ([x (sqlite3-step query)]) (cond [(sqlite-done? x) (sqlite3-finalize query) seed] [(sqlite-row? x) (let ([ncol (sqlite3-column-count query)]) (call-with-values (lambda () (process-row query ncol fn seed)) (lambda (continue? res) (if (not continue?) res (db-fold-left db fn res query)))))] [(sqlite-busy? x) #f] [else (raise (sqlite3-errmsg db))]))) (set! sqlite3 (lambda ( name) (let ([db (open name)]) (values (lambda (fn seed query) (db-fold-left db fn seed (%sqlite3-prepare-v2 db query))) (lambda () (sqlite3-close db)))))) )
false
4a6a809cd4e16ea6041cd8d8d345f4059277db6e
2fc7c18108fb060ad1f8d31f710bcfdd3abc27dc
/lib/iota.scm
d806f8ad3835c6e96e0241143da329d8afde5e45
[ "LicenseRef-scancode-public-domain", "LicenseRef-scancode-warranty-disclaimer", "CC0-1.0" ]
permissive
bakul/s9fes
97a529363f9a1614a85937a5ef9ed6685556507d
1d258c18dedaeb06ce33be24366932143002c89f
refs/heads/master
2023-01-24T09:40:47.434051
2022-10-08T02:11:12
2022-10-08T02:11:12
154,886,651
68
10
NOASSERTION
2023-01-25T17:32:54
2018-10-26T19:49:40
Scheme
UTF-8
Scheme
false
false
1,102
scm
iota.scm
; Scheme 9 from Empty Space, Function Library ; By Nils M Holm, 2009-2012 ; Placed in the Public Domain ; ; (iota integer) ==> list ; (iota integer1 integer2) ==> list ; (iota* integer1 integer2) ==> list ; ; (load-from-library "iota.scm") ; ; IOTA creates a sequence of integers starting at 1 and ending ; at INTEGER (including both). When a second argument is passed ; to IOTA, the sequence returned by it will start at INTEGER1 ; and ; end at INTEGER2 (again, including both). ; ; IOTA* differs from IOTA in two ways: it always takes two ; arguments and excludes INTEGER2 from the generated sequence. ; ; Example: (iota 7) ==> (1 2 3 4 5 6 7) ; (iota 17 21) ==> (17 18 19 20 21) ; (iota* 17 21) ==> (17 18 19 20) ; (iota* 1 1) ==> () (define (iota* l h) (if (> l h) (error "iota*: bad range" (list l h))) (let j ((x (- h 1)) (r '())) (if (< x l) r (j (- x 1) (cons x r))))) (define (iota l . h) (let ((l (if (null? h) 1 l)) (h (if (null? h) l (car h)))) (iota* l (+ 1 h))))
false
ecc7d9257201e5b3c2dc608432427ed94d73876a
4b480cab3426c89e3e49554d05d1b36aad8aeef4
/chapter-03/ex3.61-falsetru.scm
cd22b209c36cc130cfb923fa102d5db7074a16d6
[]
no_license
tuestudy/study-sicp
a5dc423719ca30a30ae685e1686534a2c9183b31
a2d5d65e711ac5fee3914e45be7d5c2a62bfc20f
refs/heads/master
2021-01-12T13:37:56.874455
2016-10-04T12:26:45
2016-10-04T12:26:45
69,962,129
0
0
null
null
null
null
UTF-8
Scheme
false
false
575
scm
ex3.61-falsetru.scm
#lang racket (require "stream-base-falsetru.scm") (require "ex3.60-falsetru.scm") (provide invert-unit-series) (define (invert-unit-series S) (define series (cons-stream 1 (mul-series (stream-map - (stream-cdr S)) series))) series) (require rackunit) (require rackunit/text-ui) (define ex3.61-tests (test-suite "Test for ex3.61" (test-case "" (define s (cons-stream 1 s)) (define s2 (invert-unit-series s)) (define ivs (mul-series s s2)) (check-equal? (stream-take ivs 9) '(1 0 0 0 0 0 0 0 0)) ) )) (run-tests ex3.61-tests)
false
23abe3161caf5240d7bcd2630afa8ac2c5d15bcc
defeada37d39bca09ef76f66f38683754c0a6aa0
/System/system/collections/specialized/name-object-collection-base.sls
6801eba3857fc5a93c95f1ee559ad4560145133a
[]
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,389
sls
name-object-collection-base.sls
(library (system collections specialized name-object-collection-base) (export is? name-object-collection-base? get-object-data get-enumerator on-deserialization keys count) (import (ironscheme-clr-port)) (define (is? a) (clr-is System.Collections.Specialized.NameObjectCollectionBase a)) (define (name-object-collection-base? a) (clr-is System.Collections.Specialized.NameObjectCollectionBase a)) (define-method-port get-object-data System.Collections.Specialized.NameObjectCollectionBase GetObjectData (System.Void System.Runtime.Serialization.SerializationInfo System.Runtime.Serialization.StreamingContext)) (define-method-port get-enumerator System.Collections.Specialized.NameObjectCollectionBase GetEnumerator (System.Collections.IEnumerator)) (define-method-port on-deserialization System.Collections.Specialized.NameObjectCollectionBase OnDeserialization (System.Void System.Object)) (define-field-port keys #f #f (property:) System.Collections.Specialized.NameObjectCollectionBase Keys System.Collections.Specialized.NameObjectCollectionBase+KeysCollection) (define-field-port count #f #f (property:) System.Collections.Specialized.NameObjectCollectionBase Count System.Int32))
false
b574ab2aaa0d27c3b27e1c162f9d15a9125986ef
0011048749c119b688ec878ec47dad7cd8dd00ec
/src/spoilers/517/solution.scm
7141d819c0e9a71ebd3d0ad8c066dc43ef8feb7a
[ "0BSD" ]
permissive
turquoise-hexagon/euler
e1fb355a44d9d5f9aef168afdf6d7cd72bd5bfa5
852ae494770d1c70cd2621d51d6f1b8bd249413c
refs/heads/master
2023-08-08T21:01:01.408876
2023-07-28T21:30:54
2023-07-28T21:30:54
240,263,031
8
0
null
null
null
null
UTF-8
Scheme
false
false
1,136
scm
solution.scm
(import (euler)) (define (exact n) (inexact->exact (floor n))) (define (make-factorial n p) (let loop ((acc (make-vector (+ n 1)))) (vector-set! acc 0 1) (do ((i 1 (+ i 1))) ((> i n)) (vector-set! acc i (modulo (* (vector-ref acc (- i 1)) i) p))) (lambda (n) (vector-ref acc n)))) (define (make-binomial n p) (let ((factorial (make-factorial n p))) (lambda (n k) (let ((a (factorial n)) (b (factorial k)) (c (factorial (- n k)))) (modulo (* a (modular-inverse (modulo (* b c) p) p)) p))))) (define (make-function n p) (let ((binomial (make-binomial n p))) (lambda (a x) (let ((l (exact (/ x a)))) (do ((i 0 (+ i 1)) (acc 0 (modulo (+ acc (binomial (exact (- x (* (- a 1) i))) i)) p))) ((> i l) acc)))))) (define (solve a b p) (let ((function (make-function b p))) (do ((i a (+ i 1)) (acc 0 (if (prime? i) (modulo (+ acc (function (sqrt i) i)) p) acc))) ((> i b) acc)))) (let ((_ (solve 10000000 10010000 1000000007))) (print _) (assert (= _ 581468882)))
false
a38cf4aca6e042edc5d27f6108c85c03570c6f31
fbf26efb5a0ffe1784314f070182432da7b74c9b
/yunilib/jsutil.sls
183094512458e235f2bcba12b0c2ea89286d7703
[]
no_license
okuoku/biwasyuni-editortest
3092a80c1321603fed8ce838f6f35d7673e6eade
52b939f9fddcb130f51282eb51f1f226b43434bf
refs/heads/master
2021-06-03T07:52:11.595613
2019-12-29T07:15:01
2019-12-29T07:15:01
143,189,743
0
0
null
2019-12-29T07:15:25
2018-08-01T17:50:51
JavaScript
UTF-8
Scheme
false
false
522
sls
jsutil.sls
(library (jsutil) (export wrap-this delay-load ) (import (yuni scheme)) ;; (define %thiswrap/wrap-this (yuni/js-import "thiswrap")) (define %js-load-async/delay-load (yuni/js-import "js-load-async")) (define (delay-load libname) (vector-ref (yuni/js-invoke/async1 %js-load-async/delay-load libname) 0)) (define-syntax wrap-this (syntax-rules () ((_ this form ...) (js-call %thiswrap/wrap-this (js-closure (lambda (this) form ...)))))) )
true
3616e7117b981e307fb4c651d86c25db622c11b5
d9cb7af1bdc28925fd749260d5d643925185b084
/lib/3.streams.scm
50b72e12a66b240e87aa85c53151f44e375dc164
[]
no_license
akerber47/sicp
19e0629df360e40fd2ea9ba34bf7bd92be562c3e
9e3d72b3923777e2a66091d4d3f3bfa96f1536e0
refs/heads/master
2021-07-16T19:36:31.635537
2020-07-19T21:10:54
2020-07-19T21:10:54
14,405,303
0
0
null
null
null
null
UTF-8
Scheme
false
false
1,290
scm
3.streams.scm
; Note: main stream interface (section 3.4.3) ; is already built into MIT scheme ; but with some slightly different names (define head stream-car) (define tail stream-cdr) (define empty-stream? stream-null?) (define the-empty-stream (stream)) (define (accumulate combiner initial-value stream) (if (empty-stream? stream) initial-value (combiner (head stream) (accumulate combiner initial-value (tail stream))))) (define (enumerate-interval low high) (if (> low high) the-empty-stream (cons-stream low (enumerate-interval (1+ low) high)))) (define map stream-map) (define (filter pred stream) (cond ((empty-stream? stream) the-empty-stream) ((pred (head stream)) (cons-stream (head stream) (filter pred (tail stream)))) (else (filter pred (tail stream))))) (define (append-streams s1 s2) (if (empty-stream? s1) s2 (cons-stream (head s1) (append-streams (tail s1) s2)))) (define (flatten stream) (accumulate append-streams the-empty-stream stream)) (define (flatmap f s) (flatten (map f s))) (define (print-stream stream) (write-string "\n{") (write (stream->list stream)) (write-string "}"))
false
ae249c5cc56d0713cb4177e58de2f1251e6b6e64
fca0221e2352708d385b790c665abab64e92a314
/redaction/benchmarks/thread-simulation/tests/thread-simulation-tests.scm
cb9b57d7d7be1e6036f2d93a049cdedd81b06d19
[]
no_license
sthilaid/memoire
a32fdb1f9add0cc0d97c095d11de0c52ae2ed2e2
9b26b0c76fddd5affaf06cf8aad2592b87f68069
refs/heads/master
2020-05-18T04:19:46.976457
2010-01-26T01:18:56
2010-01-26T01:18:56
141,195
1
2
null
null
null
null
UTF-8
Scheme
false
false
21,407
scm
thread-simulation-tests.scm
(include "../include/scm-lib_.scm") (include "../include/thread-simulation_.scm") (include "../include/match.scm") (include "test-macro.scm") ;; Usage of load is better but cannot because of the oo system. Here ;; copied the thread-simulation package load requirements and include it... ;; (load "rbtree.scm") ;; (load "scm-lib") ;;(include "thread-simulation.scm") ;;(load "thread-simulation.scm") ;;(load "test") ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; Thread Simulation Tests ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (define-test simple-test "A1B2" 3 (let ((c1 (new-corout 'c1 (lambda () (display 'A) (yield) (display 'B) (terminate-corout 'C)))) (c2 (new-corout 'c2 (lambda () (display 1) (yield) (display 2) (terminate-corout 3))))) (boot (list c1 c2)) (corout-get-result c2))) (define-test test-kill-all "12" 'killed-all (let ((c1 (new-corout 'c1 (lambda () (for i 0 (< i 3) (begin (if (= i 1) (kill-all! 'killed-all)) (display 1) (yield)))))) (c2 (new-corout 'c2 (lambda () (for i 0 (< i 3) (begin (display 2) (yield))))))) (boot (list c1 c2)))) (define-test test-ret-val-handler "A1aB2" 6 (let ((c1 (new-corout 'c1 (lambda () (begin (display 'A) (yield) (display 'B) 1)))) (c2 (new-corout 'c2 (lambda () (begin (display 1) (yield) (display 2) 2)))) ;; here terminate-corout is used to shortcircuit the flow of ;; the thunk and finish earlier this thread. (c3 (new-corout 'c3 (lambda () (begin (display #\a) (terminate-corout 3) (yield) (display #\b)))))) (boot (list c1 c2 c3) (start-timer! 0.001)) (fold-l + 0 (map corout-get-result (list c1 c2 c3))))) (define-test test-mailboxes (string-append "sending-data-from-c2\n" "sending-data-from-c3\n" "(c1 received allo)\n" "(c1 received salut)\n") 'done (letrec ((c1 (new-corout 'c1 (lambda () (pretty-print `(c1 received ,(?))) (pretty-print `(c1 received ,(?))) 'done))) (c2 (new-corout 'c2 (lambda () (pretty-print 'sending-data-from-c2) (! c1 'allo)))) (c3 (new-corout 'c3 (lambda () (pretty-print 'sending-data-from-c3) (! c1 'salut))))) (boot (list c1 c2 c3)) (corout-get-result c1))) (define-test test-recursive-sim "A12BA12BA12B" 'meta-12-done! (let* ((sA (new-corout 'sA (lambda () (for i 0 (< i 3) (begin (display 'A) (super-yield) (yield)))))) (sB (new-corout 'sB (lambda () (for i 0 (< i 3) (begin (display 'B) (yield))) (terminate-corout 'sB)))) (s1 (new-corout 's1 (lambda () (for i 0 (< i 3) (begin (display 1) (yield)))))) (s2 (new-corout 's2 (lambda () (for i 0 (< i 3) (begin (display 2) (super-yield) (yield)))))) (meta-AB (new-corout 'meta-AB (lambda () (boot (list sA sB)) 'meta-AB-done!))) (meta-12 (new-corout 'meta-12 (lambda () (boot (list s1 s2)) 'meta-12-done!)))) (boot (list meta-AB meta-12)) (corout-get-result meta-12))) (define-test test-kill-all-rec "A1B2ABAB" 'meta-AB-done! (let* ((sA (new-corout 'sA (lambda () (for i 0 (< i 3) (begin (display 'A) (super-yield) (yield)))))) (sB (new-corout 'sB (lambda () (for i 0 (< i 3) (begin (display 'B) (super-yield) (yield)))))) (s1 (new-corout 's1 (lambda () (for i 0 (< i 3) (begin (if (= i 1) (kill-all! 'over)) (display 1) (super-yield) (yield)))))) (s2 (new-corout 's2 (lambda () (for i 0 (< i 3) (begin (display 2) (super-yield) (yield)))))) (meta-AB (new-corout 'meta-AB (lambda () (boot (list sA sB)) 'meta-AB-done!))) (meta-12 (new-corout 'meta-12 (lambda () (boot (list s1 s2)) 'meta-12-done!)))) (boot (list meta-AB meta-12)) (corout-get-result meta-AB))) ;; We are here expecting that running 5 times inside the scheduler ;; should occur faster than 2 secs... (should take about 5*0.1 secs) (define-test test-sleep (string-append "bon-matin\n" "bonne-aprem\n" "bonne-nuit\n") 'dont-care (let ((c1 (new-corout 'c1 (lambda () (sleep-for 0.2) (pretty-print 'bonne-nuit)))) (c2 (new-corout 'c2 (lambda () (pretty-print 'bon-matin)))) (c3 (new-corout 'c3 (lambda () (sleep-for 0.1) (pretty-print 'bonne-aprem))))) (boot (list c1 c2 c3)) 'dont-care)) (define-test test-mutex "4123" 'done (let* ((mut (new-mutex)) (c1 (new-corout 'c1 (lambda () (critical-section! mut (yield) (display "1"))))) (c2 (new-corout 'c2 (lambda () (critical-section! mut (yield) (display "2"))))) (c3 (new-corout 'c3 (lambda () (critical-section! mut (yield) (display "3"))))) (c4 (new-corout 'c4 (lambda () (display "4"))))) (boot (list c1 c2 c3 c4)) 'done)) (define-test test-continuation "210" 'done (let* ((c1 (new-corout 'c1 (lambda () (display "1") (continue-with-thunk! (lambda () (display "0") 'done)) (display "oups-again!")))) (c2 (new-corout 'c2 (lambda () (display "2") (continue-with c1) (display "oups!"))))) (boot (list c2)) 'done)) (define-test test-thunk-composition "123" 'ok (let* ((t1 (lambda () (display "1"))) (t2 (lambda () (display "2"))) (t3 (lambda () (display "3") 'ok)) (c1 (new-corout 'c1 (compose-thunks t1 t2 t3)))) (boot (list c1)) 'ok)) (define-test test-spawning "CABD" 'done (let* ((c1 (new-corout 'c1 (lambda () (display 'A)))) (t2 (lambda () (display 'B) (yield) 'done)) (c3 (new-corout 'c3 (lambda () (display 'C) (spawn-brother c1) (spawn-brother-thunk 'c2 t2) (yield) (display 'D))))) (boot (list c3)) 'done)) (define-test test-extended-mailboxes (string-append "c2-sent-data\n" "c3-sleeps\n" "c3-sent-data\n" "3\n") 2 (let* ((c1 (new-corout 'c1 (lambda () (pretty-print (?? odd?)) (?)))) (c2 (new-corout 'c2 (lambda () (! c1 2) (pretty-print 'c2-sent-data)))) (c3 (new-corout 'c3 (lambda () (pretty-print 'c3-sleeps) (sleep-for 0.2) (! c1 3) (pretty-print 'c3-sent-data))))) (boot (list c1 c2 c3)) (corout-get-result c1))) (define-test test-timeout-? "12ok" 'done (let* ((c1 (new-corout 'c1 (lambda () (with-exception-catcher (lambda (e) (display 'ok)) (lambda () (display (?)) (display (? timeout: 0. timeout-val: 2)) (display (? timeout: 0.1)))) 'done))) (c2 (new-corout 'c2 (lambda () (! c1 1))))) (boot (list c1 c2)) (corout-get-result c1))) (define-test test-timeout-?? "35ok" 'done (let* ((c1 (new-corout 'c1 (lambda () (with-exception-catcher (lambda (e) (display 'ok)) (lambda () (display (?? odd? timeout: 1)) (display (?? odd? timeout: 1 timeout-val: 5)) (display (?? odd? timeout: 0.2)))) 'done))) (c2 (new-corout 'c2 (lambda () (! c1 2) (yield) (! c1 3))))) (boot (list c1 c2)) (corout-get-result c1))) (define-test test-timeout-extended "allogot-nothing" 'done (let* ((c1 (new-corout 'c1 (lambda () (cond ((timeout? #f (? timeout: 0)) => (lambda (x) (display x))) (else (display 'got-nothing))) (cond ((timeout? #f (? timeout: 0.2)) => (lambda (x) (display x))) (else (display 'got-nothing))) 'done))) (c2 (new-corout 'c2 (lambda () (! c1 'allo))))) (boot (list c1 c2)) (corout-get-result c1))) (define-test test-recv "pongpingfinished!" 'done (let* ((c1 (new-corout 'c1 (lambda () (let loop () (recv (ping (display 'ping) (loop)) (pong (display 'pong) (loop)) (after 0.1 (display 'finished!) 'done)))))) (c2 (new-corout 'c2 (lambda () (! c1 'pong)))) (c3 (new-corout 'c3 (lambda () (! c1 'ping))))) (boot (list c1 c2 c3)) (corout-get-result c1))) (define-test test-recv-ext "pong1pong2pong" 'ok (let* ((c1 (new-corout 'c1 (lambda () (let loop () (recv ((,from ping) (where (corout? from)) (! from 'pong))) (loop))))) (c2 (new-corout 'c2 (lambda () (let loop ((n 1)) (recv ((,from inc) (if (< n 3) (begin (! from `(ack ,n)) (loop (+ n 1))) (kill-all! 'ok)))))))) (c3 (new-corout 'c3 (lambda () (let loop () (! c1 `(,(current-corout) ping)) (recv (pong (! c2 `(,(current-corout) inc)))) (display 'pong) (recv ((ack ,n) (display n))) (loop)))))) (boot (list c1 c2 c3)) 'ok)) (define-test test-recv-ensure-timeout "timeout!-finished!" 'ok (let* ((c1 (new-corout 'c1 (lambda () (recv (ping (display 'ping-)) (after 1 (display 'timeout!-))) (display 'finished!) (kill-all! 'ok)))) (loop-corout (new-corout 'loop (lambda () (let loop () (! c1 'toto) (yield) (loop)))))) (boot (list loop-corout c1)))) (define-test test-msg-lists "alloallosalut#tallo" 'salut (let ((c1 (new-corout 'c1 (lambda () (subscribe 'toto (current-corout)) (recv (,x (display x))) (unsubscribe 'toto (current-corout)) (recv (,x (display x)) (after 0.1 'no))))) (c2 (new-corout 'c2 (lambda () (subscribe 'toto (current-corout)) (recv (,x (display x))) (recv (,x (display x)))))) (c4 (new-corout 'c4 (lambda () (subscribe 'toto (current-corout)) ;; ensure not woken up (let ((t (current-sim-time))) (sleep-for 0.5) (display (>= (- (current-sim-time) t) 0.4)) (display (?)) (?))))) (c3 (new-corout 'c3 (lambda () (broadcast 'toto 'allo) (yield) (broadcast 'toto 'salut) (yield))))) (boot (list c1 c2 c4 c3)) (corout-get-result c4))) (define-test test-dynamic-handlers "allononotutututuallono" 'ok (let ((c1 (new-corout 'c1 (lambda () (! (self) 'allo) (with-dynamic-handlers ((allo (display 'allo))) (recv (toto (display 'toto)) (after 0.02 (display 'no)))) (recv (toto (display 'toto)) (after 0.02 (display 'no))) (! (self) 'tutu) (! (self) 'allo) (with-dynamic-handlers ((allo (display 'allo))) (recv (tutu (display 'tutu)) (after 0.02 (display 'no)))) ;; still 'allo in msg box... (! (self) 'tutu) (with-dynamic-handlers ((allo (display 'allo))) (recv (tutu (display 'tutu)) (after 0.02 (display 'no)))) ;; still 'allo in msg box... (with-dynamic-handlers ((allo (display 'allo))) (recv (after 0.02 (display 'no)))) 'ok)))) (boot (list c1)) (corout-get-result c1))) (define-test test-msg-box-cleaning "allo" 3 (let ((c1 (new-corout 'c1 (lambda () (subscribe 'toto (current-corout)) (recv (allo (display 'allo))) (let ((x (clean-mailbox allo))) (recv (allo (display 'no)) (after 0 x)))))) (c2 (new-corout 'c2 (lambda () (broadcast 'toto 'allo) (broadcast 'toto 'allo) (broadcast 'toto 'allo) (broadcast 'toto 'allo))))) (boot (list c1 c2)) (corout-get-result c1))) (define-test test-after0 "noallo" 'done (let ((c1 (new-corout 'c1 (lambda () (! (self) 'salut) (recv (allo (display 'allo)) (after 0 (display 'no))) (! (self) 'allo) (recv (allo (display 'allo)) (after 0 (display 'no))) 'done)))) (boot (list c1)) (corout-get-result c1))) (define-test test-deadlock-detection "" 'ok (let ((c1 (new-corout 'c1 (lambda () (?)))) (c2 (new-corout 'c2 (lambda () 'allo (yield) 'allo)))) (with-exception-catcher (lambda (e) 'ok) (lambda () (boot (list c1 c2)))))) ;; Test the reception of correct message, of timeout and of unexpected msg (define-test test-recv-only "allono" 'ok (let* ((c1 (new-corout 'c1 (lambda () (recv-only ((allo from ,sender) (display 'allo) (recv-only (allo (display 'allo)) (after 0.05 (display 'no))) (! sender 'ok)) (after 1 (display 'no))) (yield) (recv-only (allo (display 'allo)) (after 0.05 (display 'no)))))) (c2 (new-corout 'c2 (lambda () (! c1 `(allo from (current-corout))) (?) (! c1 'toto!))))) (with-exception-catcher (lambda (e) 'ok) (lambda () (boot (list c1 c2)))))) (define-test test-dynamic-handlers-return "allototo" 'ok (let ((c1 (new-corout 'c1 (lambda () (! (self) 'allo) (with-dynamic-handlers ((allo (! (self) 'toto) (display 'allo))) (recv (toto (display 'toto)) (after 0.02 (display 'no)))) 'ok)))) (boot (list c1)) (corout-get-result c1))) (define-test test-corout-pause "ATTAT" 'ok (let* ((aux (new-corout 'aux (lambda () (write 'A) (corout-pause) (write 'A)))) (main (new-corout 'main (lambda () (write 'T) (yield) (write 'T) (spawn-brother aux) (yield) (write 'T) 'ok)))) (boot (list aux main)) (corout-get-result main))) (define-test test-yield-to "AC1DB2" 'ok (let* ((c3 (new-corout 'c3 (lambda () (display 'C) (yield) (display 'D)))) (c2 (new-corout 'c2 (lambda () (display 1) (yield-to c3) (display 2)))) (c1 (new-corout 'c1 (lambda () (display 'A) (yield-to c3) (display 'B))))) (boot (list c1 c2)) 'ok))
false
6f4667b9f2b1c7479d69ac7bdd9a86d422b7c2e2
f59b3ca0463fed14792de2445de7eaaf66138946
/section-3/3_39.scm
54e39cf9e78689a615222a9ee838ff4b0e9e8432
[]
no_license
uryu1994/sicp
f903db275f6f8c2da0a6c0d9a90c0c1cf8b1e718
b14c728bc3351814ff99ace3b8312a651f788e6c
refs/heads/master
2020-04-12T01:34:28.289074
2018-06-26T15:17:06
2018-06-26T15:17:06
58,478,460
0
1
null
2018-06-20T11:32:33
2016-05-10T16:53:00
Scheme
UTF-8
Scheme
false
false
781
scm
3_39.scm
(define x 10) (define s (make-serializer)) (parallel-execute (lambda () (set! x ((s (lambda () (* x x))))));;P1 (s (lambda () (set! x (+ x 1)))));;P2 ;; P1) ;; P11: P1の1番目と2番目のxへのアクセス ;; P12: P1のxへの設定 ;; P2: P2のxへのアクセスとP2のxへの設定 ;; P11(10) -> P12(100) -> P2(101) ;; P11(10) -> P2(11) -> P12(100) ;; P2(11) -> P11(11) -> P12(121) ;;※P11(10) -> P2(10) -> P12(100) -> P211) ;; 101: P1がxを100に設定し, 次にP2がxを101に増加する. ;; 121: P2がxを11に増加し, 次にP1がxをx掛けるxに設定する. ;; 11: P2がxにアクセスし,P1がxを100に設定,P2がxを設定する. ;; 100: P1がxに(二回)アクセスし, P2がxを11に設定し, P1がxを設定する.
false
dbd05f97b05ca9f21f3c33f5e820ca6bc5ae4df3
defeada37d39bca09ef76f66f38683754c0a6aa0
/mscorlib/system/runtime/compiler-services/runtime-wrapped-exception.sls
f6c453c7640c6b139b14a5b6f76af2a67a09aed3
[]
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
830
sls
runtime-wrapped-exception.sls
(library (system runtime compiler-services runtime-wrapped-exception) (export is? runtime-wrapped-exception? get-object-data wrapped-exception) (import (ironscheme-clr-port)) (define (is? a) (clr-is System.Runtime.CompilerServices.RuntimeWrappedException a)) (define (runtime-wrapped-exception? a) (clr-is System.Runtime.CompilerServices.RuntimeWrappedException a)) (define-method-port get-object-data System.Runtime.CompilerServices.RuntimeWrappedException GetObjectData (System.Void System.Runtime.Serialization.SerializationInfo System.Runtime.Serialization.StreamingContext)) (define-field-port wrapped-exception #f #f (property:) System.Runtime.CompilerServices.RuntimeWrappedException WrappedException System.Object))
false
73961824c9b97b55be1a7f29550198e791dacf95
02169c53cb0b21d67861bab2910a9faa60f24a72
/pc2j.ss
7fb4583e40cfd2c92a78b7b6de867019272d9db5
[]
no_license
hallbh/InterpreterProject
a268416fa5102ff0bbb3972093278e9fe7e72a02
d0e57d7d9f49f72b2c321faf274fb85ac4cfa222
refs/heads/master
2021-05-08T19:59:21.418699
2018-02-16T02:34:31
2018-02-16T02:34:31
119,591,796
0
0
null
null
null
null
UTF-8
Scheme
false
false
21,391
ss
pc2j.ss
;; Adam C. Foltzer ;; pc2j ParentheC to Java converter ;; For starters, try: ;; > (load "pc2j.scm") ;; > (pc2j "interp.pc") ;; If you have javac and java in your PATH: ;; > (compile/run "interp.pc") ;;; pmatch code written by Oleg Kiselyov ;; (http://pobox.com/~oleg/ftp/) ;;; ;;; Taken from leanTAP.scm ;;; http://kanren.cvs.sourceforge.net/kanren/kanren/mini/leanTAP.scm?view=log ; A simple linear pattern matcher ; It is efficient (generates code at macro-expansion time) and simple: ; it should work on any R5RS Scheme system. ; (pmatch exp <clause> ...[<else-clause>]) ; <clause> ::= (<pattern> <guard> exp ...) ; <else-clause> ::= (else exp ...) ; <guard> ::= boolean exp | () ; <pattern> :: = ; ,var -- matches always and binds the var ; pattern must be linear! No check is done ; _ -- matches always ; 'exp -- comparison with exp (using equal?) ; exp -- comparison with exp (using equal?) ; (<pattern1> <pattern2> ...) -- matches the list of patterns ; (<pattern1> . <pattern2>) -- ditto ; () -- matches the empty list ; Modified by Adam C. Foltzer for Chez 8 compatibility (define-syntax pmatch (syntax-rules (else guard) ((_ (rator rand ...) cs ...) (let ((v (rator rand ...))) (pmatch v cs ...))) ((_ v) (errorf 'pmatch "failed: ~s" v)) ((_ v (else e0 e ...)) (begin e0 e ...)) ((_ v (pat (guard g ...) e0 e ...) cs ...) (let ((fk (lambda () (pmatch v cs ...)))) (ppat v pat (if (and g ...) (begin e0 e ...) (fk)) (fk)))) ((_ v (pat e0 e ...) cs ...) (let ((fk (lambda () (pmatch v cs ...)))) (ppat v pat (begin e0 e ...) (fk)))))) (define-syntax ppat (syntax-rules (uscore quote unquote) ((_ v uscore kt kf) ; _ can't be listed in literals list in R6RS Scheme (and (identifier? #'uscore) (free-identifier=? #'uscore #'_)) kt) ((_ v () kt kf) (if (null? v) kt kf)) ((_ v (quote lit) kt kf) (if (equal? v (quote lit)) kt kf)) ((_ v (unquote var) kt kf) (let ((var v)) kt)) ((_ v (x . y) kt kf) (if (pair? v) (let ((vx (car v)) (vy (cdr v))) (ppat vx x (ppat vy y kt kf) kf)) kf)) ((_ v lit kt kf) (if (equal? v (quote lit)) kt kf)))) ;; From the compiler class helpers; handy for building error msgs (define-syntax define-who (lambda (x) (syntax-case x () [(k name defn ... expr) (with-syntax ([who (datum->syntax-object #'k 'who)]) #'(define name (let ([who 'name]) defn ... expr)))]))) ;; Reads a file containing Scheme data as a list (define read-file-as-list (lambda (filename) (letrec ([read-loop (lambda (dat) (cond [(eof-object? dat) '()] [else (cons dat (read-loop (read)))]))]) (with-input-from-file filename (lambda () (read-loop (read))))))) ;; Prefix for all generated Java identifiers to avoid keyword collisions (define java-identifier-prefix "_") ;; Produces a safe identifier string from a Scheme symbol, string, or integer (define-who safe (define char->safe (lambda (char) (case char [(#\?) "$q"] [(#\!) "$b"] [(#\.) "$d"] [(#\+) "$p"] [(#\-) "$_"] [(#\_) "_"] [(#\*) "$t"] [(#\/) "$di"] [(#\<) "$lt"] [(#\>) "$gt"] [(#\:) "$co"] [(#\%) "$pe"] [(#\^) "$ex"] [(#\&) "$am"] [(#\~) "$ti"] [else (string char)]))) (lambda (x) (cond [(symbol? x) (apply string-append java-identifier-prefix (map char->safe (string->list (symbol->string x))))] [(integer? x) (format "~d" x)] [(string? x) (safe (string->symbol x))] [(eq? (car x) 'quote) (safe (cadr x))] [else (errorf who "can only handle symbols, strings, and integers")]))) ;; Gets all of the labels, excluding the special label main (define labels (lambda (exp*) (pmatch exp* [() '()] [((define-label ,name . ,body) . ,exp*) (guard (not (eq? name 'main))) `(,name . ,(labels exp*))] [(,exp . ,exp*) (labels exp*)]))) ;; Makes the declarations for the label constants, given a list of labels (define label-declarations (lambda (label*) (let loop ([label* label*] [i 0]) (cond [(null? label*) ""] [else (let* ([label (safe (car label*))] [decl (format "static final int ~a = ~d;\n" label i)]) (string-append decl (loop (cdr label*) (add1 i))))])))) ;; Makes a list of all the registers defined at the top level (define registers (lambda (exp*) (pmatch exp* [() '()] [((define-registers . ,reg*) . ,exp*) (append reg* (registers exp*))] ;; support more than one def? [(,exp . ,exp*) (registers exp*)]))) ;; Makes the declaration of the registers, warning if none exist (define register-declarations (lambda (reg*) (cond [(null? reg*) (warningf who "no registers defined") ""] [else (object-declarations reg*)]))) ;; Declares a list of variables as Objects (define object-declarations (lambda (var*) (cond [(null? var*) ""] [else (apply string-append "Object " (let loop ([var* var*]) (cond [(null? var*) '()] [(null? (cdr var*)) `(,(format "~a;\n" (safe (car var*))))] [else (cons (format "~a, " (safe (car var*))) (loop (cdr var*)))])))]))) ;; Gets the program counter, and errors out if there is not exactly one (define program-counter (lambda (exp*) (letrec ([loop (lambda (exp*) (pmatch exp* [() #f] [((define-program-counter ,pc) . ,exp*) (and (not (loop exp*)) pc)] [(,exp . ,exp*) (loop exp*)]))]) (let ([pc (loop exp*)]) (when (not pc) (errorf 'pc2j "exactly one program counter must be defined")) pc)))) ;; Makes the program counter declaration string (define program-counter-declaration (lambda (pc) (format "int ~a;\n" (safe pc)))) ;; Makes a list of all define-union expressions at the top ;; level of the given expression (define unions (lambda (exp*) (pmatch exp* [() '()] [((define-union . ,def) . ,exp*) `((define-union . ,def) . ,(unions exp*))] [(,exp . ,exp*) (unions exp*)]))) ;; Generates a sequence of assignments, usually to map arguments to ;; fields in a constructor or to map fields to local variables. Takes ;; a *safe* string prefix for each side, a list of corresponding ;; variables for each side. The variable lists must each be the same ;; length. ;; Example: ;; > (printf (generate-assignments "this." '(body env) "" '(body env))) ;; this._body = _body; ;; this._env = _env; ;; > (printf (generate-assignments "Object " '(body env) "((clos_closure) _p$t)." '(body env))) ;; Object _body = ((clos_closure) _p$t)._body; ;; Object _env = ((clos_closure) _p$t)._env; (define-who generate-assignments (lambda (lhs-prefix lhs-var* rhs-prefix rhs-var*) (pmatch `(,lhs-var* ,rhs-var*) [(() ()) ""] [(() ,x) (errorf who "variable lists must be the same length")] [(,x ()) (errorf who "variable lists must be the same length")] [((,lhs . ,lhs*) (,rhs . ,rhs*)) (string-append (format "~a~a = ~a~a;\n" lhs-prefix (safe lhs) rhs-prefix (safe rhs)) (generate-assignments lhs-prefix lhs* rhs-prefix rhs*))]))) ;; Makes the declarations for a single union type Most of the work is ;; done by helpers: variant-declaration handles each class ;; declaration, and calls off to generate-constructor for help (define-who union-declaration (define variant-declaration (lambda (variant type) (pmatch variant [(,tag . ,field*) (let* ([name (safe (string-append (symbol->string type) "_" (symbol->string tag)))] [field-decls (object-declarations field*)] [constructor (generate-constructor name field*)]) (format "static class ~a {\n~a\n~a\n}\n\n" name field-decls constructor))]))) (define generate-constructor (lambda (name field*) (cond [(null? field*) ""] [else (let ([arg* (let loop ([field* field*]) (cond [(null? field*) ""] [(null? (cdr field*)) (format "Object ~a" (safe (car field*)))] [else (string-append (format "Object ~a, " (safe (car field*))) (loop (cdr field*)))]))] [assign* (generate-assignments "this." field* "" field*)]) (format "~a(~a) {\n~a}" name arg* assign*))]))) (lambda (union) (pmatch union [(define-union ,type . ,variants) (apply string-append (map (lambda (v) (variant-declaration v type)) variants))]))) ;; Builds a complete variant name from the type and the tag (define build-type-name (lambda (type tag) (string->symbol (format "~a_~a" type tag)))) ;; Makes a list of all the union types based on output from unions (define-who union-types (lambda (union*) (pmatch union* [() '()] [((define-union ,type . ,variants) . ,union*) (let* ([variants (map car variants)] [types (map (lambda (v) (build-type-name type v)) variants)]) (append types (union-types union*)))] [,x (errorf who "Input not a list of define-union expressions: ~s" x)]))) ;; Returns a list of fields for a particular type/variant combo (define-who union-variant-fields (lambda (type tag union*) (pmatch union* [() (errorf who "invalid type ~a" type)] [((define-union ,t . ,variants) . ,union*) (guard (eq? type t)) (cond [(assq tag variants) => cdr] [else (errorf who "invalid tag ~a for type ~a" tag type)])] [(,union . ,union*) (union-variant-fields type tag union*)]))) ;; label-exprs returns a list of all the non-main define-label expressions (define label-exprs (lambda (expr*) (pmatch expr* [() '()] [((define-label ,label . ,body) . ,expr*) (guard (not (eq? label 'main))) `((define-label ,label . ,body) . ,(label-exprs expr*))] [(,expr . ,expr*) (label-exprs expr*)]))) ;; Returns the expressions in the main label (define main-body (lambda (expr*) (letrec ([loop (lambda (expr*) (pmatch expr* [() #f] [((define-label main . ,body) . ,expr*) (and (not (loop expr*)) body)] [(,expr . ,expr*) (loop expr*)]))]) (let ([body (loop expr*)]) (when (not body) (errorf 'pc2j "exactly one main label must be defined")) body)))) ;; generate-body takes a non-main define-label form and generates Java ;; code for its body to be used in the trampoline's switch (define generate-label-body (lambda (label-expr types) (pmatch label-expr [(define-label ,label . ,body) (format "case ~a:\n~a\nbreak;\n" (safe label) (apply string-append (map (generate-statement types) body)))]))) ;; generate-statement implements individual expressions, including ;; primitives, control flow, union type constructors, and more. Needs ;; access to names of union types in order to call their constructors ;; where appropriate. (define-who generate-statement (lambda (types) (define type-names (union-types types)) (define constructor? (lambda (sym) (memq sym type-names))) ;; only handles single-character escapes like ~a (define convert-format-string (lambda (fmt) (let ([fmt (let loop ([fmt (string->list fmt)]) (cond [(null? fmt) '()] [(and (eq? (car fmt) #\~) (not (null? (cdr fmt))) (char-alphabetic? (cadr fmt))) `(#\% #\s . ,(loop (cddr fmt)))] [else (cons (car fmt) (loop (cdr fmt)))]))]) (list->string fmt)))) ;; adds commas and safeifies a list of arguments (define arg*->safe (lambda (arg*) (cond [(null? arg*) ""] [(null? (cdr arg*)) (safe (car arg*))] [else (format "~a, ~a" (safe (car arg*)) (arg*->safe (cdr arg*)))]))) (define generate-arg* (lambda (arg*) (cond [(null? arg*) ""] [(null? (cdr arg*)) ((generate-statement types) (car arg*))] [else (format "~a, ~a" ((generate-statement types) (car arg*)) (generate-arg* (cdr arg*)))]))) ;; generates the if-then-else chain for union-case statements (define generate-union-case (lambda (reg type case*) (pmatch case* [() (warningf who "empty union-case converted to noop") ""] [(((,tag . ,field*) . ,body)) (format "if (~a instanceof ~a) {\n~a~a\n} else { throw new Exception((new Formatter()).format(\"Error in union-case: could not match %s against type ~a\", ~a.getClass().getName()).out().toString());\n}\n" (safe reg) (safe (build-type-name type tag)) (generate-assignments "Object " field* (format "((~a) ~a)." (safe (build-type-name type tag)) (safe reg)) (union-variant-fields type tag types)) (apply string-append (map (generate-statement types) body)) (safe type) (safe reg))] [(((,tag . ,field*) . ,body) . ,case*) (let ([this (format "if (~a instanceof ~a) {\n~a~a\n} else " (safe reg) (safe (build-type-name type tag)) (generate-assignments "Object " field* (format "((~a) ~a)." (safe (build-type-name type tag)) (safe reg)) (union-variant-fields type tag types)) (apply string-append (map (generate-statement types) body)))]) (string-append this (generate-union-case reg type case*)))]))) (lambda (expr) (let ([gs (generate-statement types)]) (pmatch expr [,x (guard (symbol? x)) (safe x)] [,n (guard (integer? n)) (format "Integer.valueOf(~a)" n)] [#t "Boolean.valueOf(true)"] [#f "Boolean.valueOf(false)"] [(void) "null"] [(,constructor . ,arg*) (guard (constructor? constructor)) (format "new ~a(~a)" (safe constructor) (generate-arg* arg*))] [(begin . ,expr*) (apply string-append (map gs expr*))] [(if ,test ,conseq, altern) (format "if ((Boolean)~a) {\n~a } else {\n~a }\n" (gs test) (gs conseq) (gs altern))] [(set! ,var ,expr) (format "~a = ~a;\n" (safe var) (gs expr))] [(union-case ,reg ,type . ,case*) (generate-union-case reg type case*)] [(mount-trampoline ,constructor ,k-reg ,pc) (format "~a\ntrampoline();\n" (gs `(set! ,k-reg (,constructor (void)))))] [(dismount-trampoline ,dismount) (format "break ~a;\n" trampoline-label)] [(error . ,rest) (gs `(errorf . ,rest))] [(errorf ,who ,fmt . ,arg*) (format "throw new Exception((new Formatter()).format(\"Error in ~a: ~a\"~a).out().toString());\n" (safe who) (convert-format-string fmt) (if (null? arg*) "" (string-append ", " (arg*->safe arg*))))] [(printf ,fmt . ,arg*) (format "System.out.printf(~s~a);" (convert-format-string fmt) (if (null? arg*) "" (string-append ", " (arg*->safe arg*))))] [(and ,a ,b) (format "((Boolean)~a && (Boolean)~a)" (gs a) (gs b))] [(or ,a ,b) (format "((Boolean)~a || (Boolean)~a)" (gs a) (gs b))] [(not ,a) (format "(! (Boolean)~a)" (gs a))] [(add1 ,n) (format "((Integer)~a + 1)" (gs n))] [(sub1 ,n) (format "((Integer)~a - 1)" (gs n))] [(zero? ,n) (format "((Integer)~a == 0)" (gs n))] [(random ,n) (format "(new java.util.Random()).nextInt(~a)" (gs n))] [(,op ,n1 ,n2) (guard (memq op '(< > <= >= + * - /))) (format "((Integer)~a ~a (Integer)~a)" (gs n1) op (gs n2))] [,x (errorf who "invalid expression ~a" x)]))))); ;; Emits the program, the main portion of which is a labeled ;; while(true) infinite loop. The loop switches on the contents of the ;; program counter, and the cases are provided by generate-body of ;; each non-main label. (define trampoline-label "tramp") (define-who emit-program (lambda (name label-decl* register-decl* pc-decl pc union-decl* label-body* main) (printf "import java.util.Formatter; public class ~a { //labels ~a //registers ~a //program counter ~a //union types ~a //trampoline void trampoline() throws Exception { ~a: while(true) { switch (~a) { ~a default: throw new Exception(\"Invalid label \" + ~a); } } } //run corresponds to main label from ParentheC public void run() throws Exception { ~a }\n public static void main(String[] args) throws Exception { new ~a().run();\n}\n}\n" name label-decl* register-decl* pc-decl union-decl* trampoline-label pc label-body* pc main name))) ;; Gets the program name from the file input. This amounts to ;; stripping the file extension off the file, and then safeifying it, ;; i.e.: ;; > (safe-program-name "~/c311/interp.pc") ;; "_interp" (define safe-program-name (lambda (filename) (safe (string->symbol (path-root (path-last filename)))))) ;; Output conversion to current-output-port (define pc2j* (lambda (source-file) (let ([source (read-file-as-list source-file)]) (emit-program (safe-program-name source-file) (label-declarations (labels source)) (register-declarations (registers source)) (program-counter-declaration (program-counter source)) (safe (program-counter source)) (apply string-append (map union-declaration (unions source))) (apply string-append (map (lambda (label) (generate-label-body label (unions source))) (label-exprs source))) (apply string-append (map (generate-statement (unions source)) (main-body source))))))) ;; Output conversion to <safe-program-name>.java (define pc2j (lambda (source-file) (let ([output-file (format "~a.java" (safe-program-name source-file))]) (delete-file output-file) (with-output-to-file output-file (lambda () (pc2j* source-file))) (printf "pc2j: generated ~a\n" output-file) (flush-output-port)))) ;; Converts, compiles, and runs, with output collected back to Scheme (define-who compile/run (lambda (source-file) (let* ([tempdir (gensym->unique-string (gensym "temp"))] [compile-command (format "javac -d ~a ~a.java" tempdir (safe-program-name source-file))]) (pc2j source-file) (mkdir tempdir) (let ([compile-value (system compile-command)]) (unless (zero? compile-value) (errorf who "compiler command failed:\nInvoked: ~a\n Returned:\n~a" compile-command compile-value)) (system (format "java -cp ~a ~a" tempdir (safe-program-name source-file))) (for-each (lambda (f) (let ([filename (format "~a~a~a" tempdir (directory-separator) f)]) (delete-file filename))) (directory-list tempdir)) (delete-directory tempdir) (void)))))
true
f11ee2343014e155bf602dfab8a951b43024c0df
eef5f68873f7d5658c7c500846ce7752a6f45f69
/test/object-record.scm
af6d94dd2fcf0c157bb5fec813be1c9738da829b
[ "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
79
scm
object-record.scm
(%load-library '(spheres/util test)) (%load-library '(spheres/object record))
false
d1ef82d950c1dfe834ac0bcad615efa1652d0e17
c3523080a63c7e131d8b6e0994f82a3b9ed901ce
/dojo.scm
3496df26a167a4aa7b8e18878d9150d5e5587b53
[]
no_license
johnlawrenceaspden/hobby-code
2c77ffdc796e9fe863ae66e84d1e14851bf33d37
d411d21aa19fa889add9f32454915d9b68a61c03
refs/heads/master
2023-08-25T08:41:18.130545
2023-08-06T12:27:29
2023-08-06T12:27:29
377,510
6
4
null
2023-02-22T00:57:49
2009-11-18T19:57:01
Clojure
UTF-8
Scheme
false
false
939
scm
dojo.scm
;; So today we're going to learn how to find the square root of two ;; Can anyone remember what it is? Or make a guess at it? ;; Okay, I'll take 1.414 ;; Now, how good a guess is that? What do we need to do to it find out? ;; We need to square it. ;; So here we have an extremely powerful computer, and it's running a language called Scheme, which is one of the most powerful and ;; expressive languages in the world. ;; And our first task is to find out how to use it as a calculator, so that we can multiply 1.414 by 1.414 and see how close that is to two. (sqrt 2) ;; so we're done. ; interact with the interpreter 2 "a" + (+ 2 3) (define square (lambda (x) (* x x))) (define average (lambda (a b) (/ (+ a b) 2))) (define improve (lambda(x) (average x (/ 2 x)))) (square 1) (square (improve 1)) (square (improve (improve 1))) (square (improve (improve (improve 1)))) (square (improve (improve (improve (improve 1)))))
false
99e8388d39270d0746cdfe990428e54dad0f4eef
a2d8b4843847507b02085bb8adabd818f57dd09f
/scheme/sicp/ch_2/tst-car-cons.scm
9d83675c31975521a95b50df27a1a0a8dda3e8da
[]
no_license
tcharding/self_learning
df911b018fc86bd5f918394b79d2456bf51f35a8
f6bb5c6f74092177aa1b71da2ce87ca1bfc5ef3c
refs/heads/master
2022-05-13T05:09:32.284093
2022-05-02T08:25:18
2022-05-02T08:25:18
41,029,057
13
2
null
null
null
null
UTF-8
Scheme
false
false
499
scm
tst-car-cons.scm
;;;; Test suite for example representation of car/cons ;;;; ;;;; Exercise 2.4 (load "../test-framework.scm") (load "car-cons.scm") (load "../lib.scm") (define raw-data '((1 2) (3 6) (-1 2) (-3 0))) (define (test-basic x y) "test constructor and selectors" (let ((tobj (*cons x y))) (test-eq "car" (*car tobj) x) (test-eq "cdr" (*cdr tobj) y))) ;;;; ;;;; Test suite run when file loaded ;;;; (for-each (lambda (ls) (test-basic (first ls) (second ls))) raw-data)
false
916a42c3e73d7d4eff07a760f9a87902cb49bfce
f1a8c6d5d1178b81132f70e61ab5a53361902e90
/2.1/exercises.scm
92b8ac99d276b9b7d1139c05f3c3b64d6bd2a444
[]
no_license
jlam55555/sicp
99862a8eedcb47034f361b38639247ecf0800b50
64d15f48b9b8ea77f7d38794179874c7d65e975a
refs/heads/master
2023-07-14T11:08:57.981072
2021-08-24T01:10:20
2021-08-24T01:10:20
371,579,084
1
0
null
null
null
null
UTF-8
Scheme
false
false
13,925
scm
exercises.scm
;;; 2.1 exercises (load "../2.1/2.1.scm") ;;; 2.1: improving the make-rat constructor (define (make-rat x y) ;; a better make-rat with better handling of negatives and ;; zero denominator ;; if positive, both numerator and denominator will be positive; ;; if negative, only numerator will be negative (if [zero? y] (error 'make-rat "zero denominator") (let ([d (gcd x y)]) (cons (* (if [boolean=? (negative? x) (negative? y)] 1 -1) (/ (abs x) d)) (/ (abs y) d))))) ;;; 2.2: reprenting line segments ;;; note: I flipped the names so that they all have the same prefix ;;; (e.g., this makes autocomplete work nicely) (define (point-make x y) ;; create a point representation given the x and y coordinates (cons x y)) (define (point-x p) ;; get the x coordinate of a point (car p)) (define (point-y p) ;; get the y coordinate of a point (cdr p)) (define (point-print p) ;; print a point to the screen (format #t "(~a,~a)\n" (point-x p) (point-y p))) (define (segment-make start end) ;; create a segment representation given the two endpoints (cons start end)) (define (segment-start s) ;; get the starting point of a segment (car s)) (define (segment-end s) ;; get the ending point of a segment (cdr s)) (define (segment-midpoint s) ;; return the midpoint of a segment (let ([p1 (segment-start s)] [p2 (segment-end s)]) (point-make (average (point-x p1) (point-x p2)) (average (point-y p1) (point-y p2))))) ;;; test cases (define seg (segment-make (point-make 0 1) (point-make 2 -3))) (point-print (segment-midpoint seg)) ;;; 2.3: representation for rectangles ;;; Greatly simplify the problem by assuming that the rectangle is ;;; orthogonal to the Cartesian axes (define (rectangle-make top-left bottom-right) ;; define a rectangle in terms of its top-left and bottom-right points ;; assumes that the three points are not collinear (cons top-left bottom-right)) (define (rectangle-top-left r) ;; gets the top-left point of a rectangle (car r)) (define (rectangle-bottom-right r) ;; gets the bottom-right point of a rectangle (cdr r)) (define (rectangle-area r) ;; calculates the area of the rectangle r (let ([tl (rectangle-top-left r)] [br (rectangle-bottom-right r)]) (* (- (point-x br) (point-x tl)) (- (point-y br) (point-y tl))))) (define (rectangle-perimeter r) ;; calculates the perimeter of the rectangle r (let ([tl (rectangle-top-left r)] [br (rectangle-bottom-right r)]) (* (+ (- (point-x br) (point-x tl)) (- (point-y br) (point-y tl))) 2))) ;;; a second internal representation for rectangles such that ;;; rectangle-area and rectangle-perimeter still work (define (rectangle-make top-left width height) ;; constructs a rectangle with a different concrete implementation (cons top-left (cons width height))) (define (rectangle-top-left r) ;; gets the top-left point of a rectangle defined with the ;; second rectangle constructor (car r)) (define (rectangle-bottom-right r) ;; gets the bottom-right point of a rectangle defined with the ;; second rectangle constructor (point-make (+ (point-x (car r)) (cadr r)) (+ (point-y (car r)) (cddr r)))) ;;; 2.4: another procedural implementation of cons (define (my-cons-2 x y) ;; procedural implementation of cons (lambda (m) (m x y))) (define (my-car-2 z) ;; procedural implementation of car (z (lambda (p q) p))) (define (my-cdr-2 z) ;; procedural implementation of cdr (z (lambda (p q) q))) ;;; 2.5: a numeric representation for cons ;;; this works because of the Fundamental Theorem of Arithmetic ;;; (or, more generally, because 2 and 3 are coprime) (define (my-cons-3 x y) ;; a numeric implementation of cons ;; assume x, y are nonnegative integers (* (expt 2 x) (expt 3 y))) (define (my-car-3 z) ;; a numeric implementation of car ;; (is there a faster way of doing this?) (let iter ([n z] [result 0]) (if [not (divides? 2 n)] result (iter (fx/ n 2) (fx1+ result))))) (define (my-cdr-3 z) ;; a numeric implementation of cdr (let iter ([n z] [result 0]) (if [not (divides? 3 n)] result (iter (fx/ n 3) (fx1+ result))))) ;;; 2.6: a procedural implementation for nonnegative integers (define church-zero ;; Church numeral implementation of 0 (lambda (f) (lambda (x) x))) (define (church-1+ n) ;; Church numeral implementation of 1+ (lambda (f) (lambda (x) (f ((n f) x))))) ;;; notes: ;;; - zero is a procedure that always returns the identity ;;; function, so it is the same as writing: (define (church-zero f) identity) ;;; where identity is defined in ../utils/utils. This makes ;;; sense as the zero of some function group. ;;; Thus we can imagine each "number" to be represented as ;;; a function. ;;; - From the previous observation, we can expect add-1 to ;;; be some map on functions F -> F. ;;; The reprentation of 1 in this function space is (add-1 zero), ;;; which simplifies to: (define (church-one f) (lambda (x) (f x))) ;;; in other words, it returns f. Even more simply: (define (church-one f) f) ;;; or (define church-one identity) ;;; (assuming that f is a unary procedure) ;;; From the above, we can clearly see that the representation ;;; of 2 is: (define church-two (lambda (f) (lambda (x) (f (f x))))) ;;; simplifying: (define (church-two f) (lambda (x) (f (f x)))) ;;; in terms of our friends from ../1.3/exercises.scm: (define church-two double) ;;; the generalized version of this is that the number n is represented ;;; by the function that autocomposes a function n times. Thus, to sum ;;; of two "numbers" a+b is the function that autocomposes a function n+m times (define (church-add a b) ;; add two Church numerals (lambda (f) (lambda (x) ((a f) ((b f) x))))) ;;; with this understanding, the definition of multiplication is ;;; also pretty clear: (define (church-multiply a b) ;; multiply two Church numerals (lambda (f) (lambda (x) ((a (b f)) x)))) ;;; now, it's intuitive that the church numerals are isomorphic to the ;;; nonnegative integers by the autocompose mapping (from 1.3 exercises), ;;; so the conversion to/from Church numerals is well-defined (define (fx->church n) ;; generate an arbitrary church numeral from a regular nonnegative number (lambda (f) (n-fold-compose f n))) (define (church->fx n) ;; converts a church numeral into a number equivalent ((n 1+) 0)) ;;; 2.7: continuing the interval example (define (interval-make lower upper) ;; construct an interval object (cons lower upper)) (define (interval-upper-bound i) ;; get the upper bound of an interval (cdr i)) (define (interval-lower-bound i) ;; get the lower bound of an interval (car i)) ;;; 2.8: interval difference (define (interval-sub a b) ;; return the difference between two intervals ((interval-make (- (interval-lower-bound a) (interval-upper-bound b)) (- (interval-upper-bound a) (interval-lower-bound b))))) ;;; 2.9: interval widths ;;; let interval1 be (l1, u1), interval2 be (l2, u2) ;;; +: w = ((u1+u2) - (l1+l2))/2 = (u1-l1)/2 + (u2-l2)/2 = w1 + w2 ;;; -: w = ((u1-l2) - (l1-u2))/2 = (u1-l1)/2 + (l2-l2)/2 = w1 + w2 ;;; *: [0,1] * [0,1] = [0,1] but [1,2] * [1,2] = [1,4] ;;; input widths are the same, output widths are not ;;; /: [0,1] / [1,2] = [0,1] * [1,1/2] = [0,1] ;;; [0,1] / [2,3] = [0,1] * [1/2,1/3] = [0,1/2] ;;; input widths are the same, output widths are not ;;; 2.10: prevent divide by zero (interval) (define (interval-div x y) ;; divide an interval by another (multiply by the reciprocal) ;; prevent divide by interval that spans zero (including endpoints) (if [and (<= (interval-lower-bound y) 0) (>= (interval-upper-bound y) 0)] (errorf 'interval-div "interval [~a,~a] spans 0" (interval-lower-bound a) (interval-upper-bound b)) (interval-mul x (interval-make (/ 1.0 (interval-upper-bound y)) (/ 1.0 (interval-lower-bound y)))))) ;;; 2.11: ben's suggestion (define (interval-mul x y) ;; break up multiplication into nine cases, only one of which requires ;; more than two multiplications ;; store endpoints because fncalls are long (let ([u1 (interval-upper-bound x)] [l1 (interval-lower-bound x)] [u2 (interval-upper-bound y)] [l2 (interval-lower-bound y)]) ;; get signs of endpoints (let ([su1 (>= u1 0)] [sl1 (>= l1 0)] [su2 (>= u2 0)] [sl2 (>= l2 0)]) (cond ;; all positive or negative ([and sl1 su1 sl2 su2] (interval-make (* l1 l2) (* u1 u2))) ([and (not sl1) (not su1) (not sl2) (not su2)] (interval-make (* u1 u2) (* l1 l2))) ;; one positive, one negative ([and sl1 su1 (not sl2) (not su2)] (interval-make (* u1 l2) (* l1 u2))) ([and (not sl1) (not su1) sl2 su2] (interval-make (* l1 u2) (* u1 l2))) ;; one spanning zero ([and sl1 su1 (not sl2) su2] (interval-make (* u1 l2) (* u1 u2))) ([and (not sl1) (not su1) (not sl2) su2] (interval-make (* l1 u2) (* l1 l2))) ([and (not sl1) su1 sl2 su2] (interval-make (* l1 u2) (* u1 u2))) ([and (not sl1) su1 (not sl2) (not su2)] (interval-make (* u1 l2) (* l1 l2))) ;; both spanning zero (#t (let ([p1 (* u1 u2)] [p2 (* u1 l2)] [p3 (* l1 u2)] [p4 (* l1 l2)]) (interval-make (min p1 p2 p3 p4) (max p1 p2 p3 p4)))))))) ;;; 2.12: different constructors (define (interval-make-center-width c w) ;; constructs an interval given center and width (interval-make (- c w) (+ c w))) (define (interval-center i) ;; the center of an interval (average (interval-lower-bound i) (interval-upper-bound i))) (define (interval-width i) ;; the width of an interval (/ (- (interval-upper-bound i) (interval-lower-bound i)) 2)) (define (interval-make-center-tolerance c p) ;; constructs an interval given center and percentage tolerance (interval-make-center-width c (abs (* c p)))) (define (interval-tolerance i) ;; the percent tolerance of an interval around its center (abs (/ (interval-width i) (interval-center i)))) ;;; 2.13: interval width as a function of percent ;;; (see assumptions below) ;;; We basically make a linearizing assumption because tolerances are small ;;; (A +- a) * (B +- b) ~= AB +- ab (not actually true, but we can estimate ;;; that the center is ~= AB) ;;; ;;; Really the product is [(A-a)(B-b),(A+a)(B+b)] = [AB-Ab-Ba+ab,AB+Ab+Ba+ab] ;;; so width = ((AB+Ab+Ba+ab)-(AB-Ab-Ba+ab))/2 = 2*(Ab+Ba)/2 = Ab+Ba ;;; Let a=p1*A, b=p2*B, then w=AB*p2 + AB*p1 = AB*(p1+p2) ;;; Thus output percentage is p=w/c = AB*(p1+p2)/AB = p1+p2 (define (interval-estimate-prod-tolerance x y) ;; estimates the width of the product of x and y ;; for simplicity, assume x,y are both positive ;; and the percent tolerances are small (+ (interval-tolerance x) (interval-tolerance y))) ;;; 2.14: Lem's complaints (define (par1 r1 r2) ;; parallel resistor calculation using r1*r2/(r1+r2) (interval-div (interval-mul r1 r2) (interval-add r1 r2))) (define (par2 r1 r2) ;; parallel resistor calculation using 1/(1/r1+1/r2) (let ([one (interval-make 1 1)]) (interval-div one (interval-add (interval-div one r1) (interval-div one r2))))) ;;; helper functions (define (interval-print i) ;; prints the interval to a string (format #f "[~a,~a]" (interval-upper-bound i) (interval-lower-bound i))) (define (interval-print-center-width i) ;; prints the interval in center-width form to a string (format #f "[~a +- ~a]" (interval-center i) (interval-width i))) (define (interval-print-center-tolerance i) ;; prints the interval in center-tolerance form to a string (format #f "[~a +- ~a%]" (interval-center i) (* (interval-tolerance i) 100))) ;;; sample tests: lem's example (define r1 (interval-make-center-tolerance 560 .05)) (define r2 (interval-make-center-tolerance 330 .05)) (interval-print-center-tolerance (par1 r1 r2)) (interval-print-center-tolerance (par2 r1 r2)) ;;; sample tests: A/A and A/B ;;; as expected, dividing/multiplying roughly sums the tolerances (interval-print-center-tolerance (interval-div r1 r1)) (interval-print-center-tolerance (interval-div r2 r2)) (interval-print-center-tolerance (interval-div r1 r2)) (interval-print-center-tolerance (interval-div r2 r1)) ;;; 2.15: eva's explanation ;;; I think she is right. When we simplify the formulas and say they are ;;; algebraically equivalent, we are performing symbolic (exact) manipulations. ;;; ;;; The problem is that if we have an expression with an inexact value ;;; multiple times, its uncertainty gets factored in multiple times, when ;;; it should only be counted once. ;;; ;;; In other words, it's about the interpretation of an interval. We're not ;;; *really* operating on the intervals themselves; we're acting on a specific ;;; value that may lie in that interval. If r1 (from the above tests) is 554 ;;; Ohms, then it is 554 Ohms wherever r1 shows in the equation. Similarly, ;;; if I is an interval, I/I should be exactly 1 (the range [1,1]) in this ;;; interpretation: for any value i in I, i/i = 1. ;;; ;;; In other other words, we can't treat intervals like we would with regular ;;; deterministic values, because what we are really operating on are the ;;; results for all the possible values that lie within that interval. ;;; 2.16: a solution for this phenomenon ;;; According to some online sources, performing interval arithmetic with the ;;; correct bookkeeping (i.e., only counting uncertainties once) is a hard ;;; but solvable problem. See ;;; https://en.wikipedia.org/wiki/Interval_arithmetic#Dependency_problem ;;; for a discussion of this problem. These answers on Stack Overflow ;;; (https://stackoverflow.com/a/14131196/2397327, ;;; https://stackoverflow.com/a/67394859/2397327) help to give a good idea ;;; of the problem.
false
da98a14ac24f1032d8f5a93d594c7aebdbb36d22
958488bc7f3c2044206e0358e56d7690b6ae696c
/scheme/evaluator/link.scm
617afb1bb38f195092f92abe91294e8bec0968b4
[]
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
16
scm
link.scm
../link/link.scm
false
26f0c54fb4df847563dcab19bdc37e664e840a48
2fc7c18108fb060ad1f8d31f710bcfdd3abc27dc
/lib/string-case.scm
9a9b652e0cba53e91e16497aafd716aa59f69036
[ "LicenseRef-scancode-public-domain", "LicenseRef-scancode-warranty-disclaimer", "CC0-1.0" ]
permissive
bakul/s9fes
97a529363f9a1614a85937a5ef9ed6685556507d
1d258c18dedaeb06ce33be24366932143002c89f
refs/heads/master
2023-01-24T09:40:47.434051
2022-10-08T02:11:12
2022-10-08T02:11:12
154,886,651
68
10
NOASSERTION
2023-01-25T17:32:54
2018-10-26T19:49:40
Scheme
UTF-8
Scheme
false
false
725
scm
string-case.scm
; Scheme 9 from Empty Space, Function Library ; By Nils M Holm, 2009,2010 ; Placed in the Public Domain ; ; (string-upcase string) ==> string ; (string-downcase string) ==> string ; ; (load-from-library "string-case.scm") ; ; Return a fresh string containing the characters of STRING, but ; with the case of alphabetic characters converted. STRING-UPCASE ; converts characters to upper case, STRING-DOWNCASE to lower case. ; ; Example: (string-upcase "Hello, World!") ==> "HELLO, WORLD!" ; (string-downcase "Hello, World!") ==> "hello, world!" (load-from-library "string-map.scm") (define (string-downcase s) (string-map char-downcase s)) (define (string-upcase s) (string-map char-upcase s))
false