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
a2ac2a6547b218088e8982a1a2fcf52a074918b3
804e0b7ef83b4fd12899ba472efc823a286ca52d
/old/FeedReader/serf/obsolete/queue-v1.scm
b123ea12172ab755a5d30d826562af7c9d845b4e
[ "Apache-2.0" ]
permissive
cha63506/CRESTaceans
6ec436d1bcb0256e17499ea9eccd5c034e9158bf
a0d24fd3e93fc39eaf25a0b5df90ce1c4a96ec9b
refs/heads/master
2017-05-06T16:59:57.189426
2013-10-17T15:22:35
2013-10-17T15:22:35
null
0
0
null
null
null
null
UTF-8
Scheme
false
false
13,862
scm
queue-v1.scm
(require-library 'sisc/libs/srfi/srfi-19) (import generic-procedures) (import oo) (import record) (import srfi-19) ; Time/date library. (import threading) (import type-system) (define-nongenerative-record-type <queue-posting> |563130a3-0678-4a9d-b521-57289b05a62d| (make-queue-posting before after posting) <queue-posting>? (before :before :before!) (after :after :after!) (posting :posting :posting!)) (define-generics :head :head! :tail :tail! :cursor :cursor! :capacity :capacity! :backlog :backlog!) ;; General-purpose queue (NOT thread-safe!). (define-class (<queue>) (head :head :head!) ; Queue head. (tail :tail :tail!) ; Queue tail. (cursor :cursor :cursor!) ; Reading cursor. (capacity :capacity :capacity!) ; Maximum capacity of queue (#f => unbounded capacity). (occupancy :backlog :backlog!)) ; Number of items in queue. ;; Unbounded queue. (define-method (initialize (<queue> q)) (:head! q #f) (:tail! q #f) (:cursor! q #f) (:capacity! q #f) ; Infinite capacity. (:backlog! q 0)) ; Empty. ;; Bounded mailbox with maximum capacity n > 0. (define-method (initialize (<queue> q) (<number> n)) (:head! q #f) (:tail! q #f) (:cursor! q #f) (:capacity! q n) ; Capacity = n >=0. (:backlog! q 0)) ; Empty. (define-generics empty? nonempty? full? backlog put! take! rewind! advance! peek extract! queue-to-list) (define (%empty? q) (not (:head q))) (define (%nonempty? q) (and (:head q) #t)) (define (%full? q) (and (:capacity q) (>= (:backlog q) (:capacity q)))) (define (%backlog q) (:backlog q)) (define (%put! q x) (cond ((%full? q) #f) ; Queue is full. ((:tail q) ; Queue is nonempty. Add to tail. (:after! (:tail q) (make-queue-posting (:tail q) #f x)) (:tail! q (:after (:tail q))) (:backlog! q (+ (:backlog q) 1)) #t) (else ; Queue is empty. Add to head. (:head! q (make-queue-posting #f #f x)) (:tail! q (:head q)) (:backlog! q (+ (:backlog q) 1)) #t))) ;; Remove and return the oldest (first) item in the queue. ;; If the queue is empty return the given default value. (define (%take! q default) (%rewind! q) (if (%advance! q) (%extract! q) default)) ;; Rewind the queue cursor. (define (%rewind! q) (:cursor! q #f)) ;; Advance the cursor to the next item in the queue. ;; Return #t if the cursor advanced and #f otherwise. (define (%advance! q) (cond ((boolean? (:cursor q)) ; Cursor was rewound. (:cursor! q (:head q)) ; Set cursor to first item (if any). (and (:cursor q) #t)) ((eq? (:cursor q) (:tail q)) ; Cursor pointing to last <queue-posting>. #f) (else ; Cursor somewhere in the middle of the queue. Advance cursor. (:cursor! q (:after (:cursor q))) #t))) ;; Return the item referenced by the cursor without disturbing its position in the queue. ;; If the cursor is not positioned at an item then the void value is returned. (define (%peek q) (if (:cursor q) (:posting (:cursor q)))) ;; Remove and return the item referenced by the cursor. ;; If the cursor is not positioned at a posting then the void value is returned. (define (%extract! q) (if (:cursor q) (let* ((posting (:cursor q)) ; The posting of interest. (prior (:before posting)) ; The posting immediately before the posting of interest. (successor (:after posting))) ; The posting immediately after the posting of interest. (cond ((and (boolean? prior) (boolean? successor)) ; The posting is the only one in the queue. (:head! q #f) (:tail! q #f)) ((boolean? prior) ; The posting of interest is first in the queue. (:head! q successor) (:before! successor #f) (:after! posting #f)) ((boolean? successor) ; The message of interest is last in the queue. (:tail! q prior) (:after! prior #f) (:before! posting #f)) (else ; The message is somewhere in the middle of the queue. (:after! prior successor) (:before! successor prior) (:before! posting #f) (:after! posting #f))) (:cursor! q #f) ; Rewind the cursor. (:backlog! q (- (:backlog q) 1)) ; Decrement the backlog count. (:posting posting)))) (define (%put! q x) (cond ((%full? q) #f) ; Queue is full. ((:tail q) ; Queue is nonempty. Add to tail. (:after! (:tail q) (make-queue-posting (:tail q) #f x)) (:tail! q (:after (:tail q))) (:backlog! q (+ (:backlog q) 1)) #t) (else ; Queue is empty. Add to head. (:head! q (make-queue-posting #f #f x)) (:tail! q (:head q)) (:backlog! q (+ (:backlog q) 1)) #t))) ;; Returns #t if the queue is empty and #f if items are enqueued. (define-method (empty? (<queue> q)) (%empty? q)) ;; Returns #t if items are enqueued and #f if the queue is empty. (define-method (nonempty? (<queue> q)) (%nonempty? q)) ;; Returns #t if the backlog of waiting messages equals the queue capacity ;; and #f if the backlog is less than the queue capacity. (define-method (full? (<queue> q)) (%full? q)) ;; Returns the number of elements in the queue. (define-method (backlog (<queue> q)) (:backlog q)) ;; Enqueue item x. Returns #t if successful (sufficient capacity) and #f otherwise (insufficient capacity). (define-method (put! (<queue> q) (<value> x)) (%put! q x)) ;; Remove and return the oldest (first) item in the queue. ;; If the queue is empty return the given default value. (define-method (take! (<queue> q) (<value> default)) (%take! q default)) (define (%take-with-filter! q f default) (%rewind! q) (let loop () (if (%advance! q) (if (f (%peek q)) (%extract! q) (loop)) default))) ;; Remove and return the oldest item in the queue that satisfies predicate f. ;; If no such item exists then return the given default value. (define-method (take! (<queue> q) (<procedure> f) (<value> default)) (%take-with-filter! q f default)) ;; Rewind the queue cursor. (define-method (rewind! (<queue> q)) (%rewind! q)) ;; Advance the cursor to the next item in the queue. ;; Return #t if the cursor advanced and #f otherwise. (define-method (advance! (<queue> q)) (%advance! q)) ;; Return the item referenced by the cursor without disturbing its position in the queue. ;; If the cursor is not positioned at an item then the void value is returned. (define-method (peek (<queue> q)) (%peek q)) ;; Remove and return the item referenced by the cursor. ;; If the cursor is not positioned at a posting then the void value is returned. (define-method (extract! (<queue> q)) (%extract! q)) (define-generics :more :more! :busy :busy!) ;; 1:n (SINGLE reader MULTIPLE writers) thread-safe queue. (define-class (<queue-1-n> <queue>) (busy :busy :busy!) ; Mutex. (more :more :more!)) ; Condition variable. (define-method (initialize (next: next) (<queue-1-n> q)) (next q) (:busy! q (mutex/new)) (:more! q (condvar/new))) (define-method (initialize (next: next) (<queue-1-n> q) (<number> n)) (next q n) (:busy! q (mutex/new)) (:more! q (condvar/new))) (define-method (empty? (<queue-1-n> q)) (mutex/lock! (:busy q)) (let ((outcome (%empty? q))) (mutex/unlock! (:busy q)) outcome)) (define-method (nonempty? (<queue-1-n> q)) (mutex/lock! (:busy q)) (let ((outcome (%nonempty? q))) (mutex/unlock! (:busy q)) outcome)) (define-method (full? (<queue-1-n> q)) (mutex/lock! (:busy q)) (let ((outcome (%full? q))) (mutex/unlock! (:busy q)) outcome)) (define-method (backlog (<queue-1-n> q)) (mutex/lock! (:busy q)) (let ((outcome (%backlog q))) (mutex/unlock! (:busy q)) outcome)) (define-method (put! (<queue-1-n> q) (<value> x)) (mutex/lock! (:busy q)) (let ((ok (%put! q x))) (if ok (condvar/notify (:more q))) (mutex/unlock! (:busy q)) ok)) ;; Nonblocking read of queue. Extract and return the oldest item. ;; If no item is waiting then return the default value. (define-method (take! (<queue-1-n> q) (<value> default)) (mutex/lock! (:busy q)) (let ((outcome (%take! q default))) (mutex/unlock! (:busy q)) outcome)) ; Blocking read of queue. (define-method (take! (<queue-1-n> q)) (let loop () (mutex/lock! (:busy q)) (%rewind! q) (cond ((%advance! q) (let ((item (%extract! q))) (mutex/unlock! (:busy q)) item)) ((mutex/unlock! (:busy q) (:more q)) ; Block until something shows up. Safe since we assume single reader. (loop))))) ;; Block waiting, at most timeout milliseconds, for an item to remove from the head of the queue and return. ;; If the timeout expires before an item appears return the default. (define-method (take! (<queue-1-n> q) (<number> timeout) (<value> default)) (let loop () (mutex/lock! (:busy q)) (%rewind! q) (cond ((%advance! q) (let ((item (%extract! q))) (mutex/unlock! (:busy q)) item)) ((mutex/unlock! (:busy q) (:more q) timeout) (loop)) (else default)))) ;; Remove and return the first item in arrival order that satisfies predicate f. ;; Blocks if necessary until such an item is found. (define-method (take! (<queue-1-n> q) (<procedure> f)) (mutex/synchronize (:busy q) (lambda () (%rewind! q) (let loop () (cond ((%advance! q) (if (f (%peek q)) (%extract! q) (loop))) (else (mutex/unlock! (:busy q) (:more q)) ; Blocking wait for something else to arrive. (mutex/lock! (:busy q)) ; Reacquire the lock. (loop))))))) ;; Remove and return the first item in arrival order that satisfies predicate f. ;; If no such item exists return the default value. (define-method (take! (<queue-1-n> q) (<procedure> f) (<value> default)) (mutex/sychronize (:busy q) (lambda () (%take-with-filter! q f default)))) ;; Convert m in milliseconds to a SRFI-19 time-duration. (define (milliseconds-to-duration m) (let ((seconds (quotient m 1000)) (nanoseconds (* (remainder m 1000) 1000000))) (make-time time-duration nanoseconds seconds))) ;; Convert a SRFI-19 time duration d to integer milliseconds. (define (duration-to-milliseconds d) (+ (* (time-second d) 1000) (quotient (time-nanosecond d) 1000000))) (define (%now) (current-time time-monotonic)) ;; Outline ;; rewind the queue cursor ;; try take and filter with no rewind ;; if success then return item ;; if failure then wait ;; q - queue-1-n of interest ;; f - predicate ;; used - time used so far as a time-duration ;; timeout - total time allotted for extraction from queue expressed as a time-duration ;; default - value returned on failure (no item satisfying predicate f found in timeout time) ;; Either returns item from q satisfying predicate f or default. In both cases will return no later ;; than timeout time-duration from call. (define (%subtake! q f used timeout default) ; Debugging ;(write (list '%subtake! 'used: (duration-to-milliseconds used) 'timeout: (duration-to-milliseconds timeout))) ;(newline) (newline) (if (time>? used timeout) ; Have we consumed all of the time allocated by timeout? default ; The total amount of time that we have waited exceeds the timeout. (let* ((unused (time-difference timeout used)) ; Calculate the remaining (unused) wait time. (d (duration-to-milliseconds unused)) ; Convert from time-duration to milliseconds. (start (%now))) ; Debugging. ;(write (list '%subtake! 'unused: d)) ;(newline) (newline) ;(write (list '%subtake! 'backlog: (backlog q))) (newline)(newline) (if (> d 0) (cond ((mutex/unlock! (:busy q) (:more q) d) ; Wait for something tasty to arrive. ;(write (list '%subtake! 'emerged-from-wait)) (newline) (newline) (mutex/lock! (:busy q)) ; One or more items were added to the queue. (let loop () (if (%advance! q) (if (f (%peek q)) (%extract! q) ; Return the item that satisfied predicate f. (loop)) ; Advance to the next item (if any) and try again. ; Oops. Nothing satisfied the filter and we have exhausted the queue so try waiting again. (%subtake! q f (add-duration! (time-difference (%now) start) used) timeout default)))) (else default)) ; We waited for the entire "unused" period. By construction we exceeded the timeout. default)))) ; No more time to wait. (define-method (take! (<queue-1-n> q) (<procedure> f) (<number> timeout) (<value> default)) (mutex/synchronize (:busy q) (lambda () (%rewind! q) (%subtake! q f (make-time time-duration 0 0) (milliseconds-to-duration timeout) default)))) ;; NOTE: Timeouts in Termite (recv ...) violate the law of least surprise since ;; the (recv ...) should EITHER find a matching message in no more than timeout seconds (expressed as a real). ;; or return. However careful reading of the code for Termite (see recv.scm) shows that if messages ;; repeatedly arrive before the timeout expires but are not matched by (recv ...) then the (recv ...) ;; will just wait again for timeout seconds. This could easily lead to either indefinite blocking ;; (as long as non-matching messages continue to arrive) or eventual success but whose total elapsed time ;; exceeds the timeout. (define-method (rewind! (<queue-1-n> q)) (%rewind! q)) (define-method (advance! (<queue-1-n> q)) (mutex/lock! (:busy q)) (let ((outcome (%advance! q))) (mutex/unlock! (:busy q)) outcome)) (define-method (peek (<queue-1-n> q)) (%peek q)) (define-method (extract! (<queue-1-n> q)) (mutex/lock! (:busy q)) (let ((outcome (%extract! q))) (mutex/unlock! (:busy q)) outcome)) (define (%queue-to-list q) (%rewind! q) (let loop ((items '())) (if (%advance! q) (loop (cons (%peek q) items)) (reverse items)))) (define-method (queue-to-list (<queue> q)) (%queue-to-list q)) (define-method (queue-to-list (<queue-1-n> q)) (mutex/lock! (:busy q)) (let ((outcome (%queue-to-list q))) (mutex/unlock! (:busy q)) outcome))
false
85bf504958a51bea399c03515610c61b7fce3f21
eef5f68873f7d5658c7c500846ce7752a6f45f69
/spheres/util/check.scm
b833e3373c2cd03b6ec16d813cfa4c39279c3b4a
[ "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
5,840
scm
check.scm
;;!!! SRFI-78: Lightweight testing ;; ;; .author Sebastian Egner, 2004-2006. ;; .author Álvaro Castro-Castilla, 2014. ;; ;; Permission is hereby granted, free of charge, to any person obtaining ;; a copy of this software and associated documentation files (the ;; ``Software''), to deal in the Software without restriction, including ;; without limitation the rights to use, copy, modify, merge, publish, ;; distribute, sublicense, and/or sell copies of the Software, and to ;; permit persons to whom the Software is furnished to do so, subject to ;; the following conditions: ;; ;; The above copyright notice and this permission notice shall be ;; included in all copies or substantial portions of the Software. ;; ;; THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, ;; EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ;; MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ;; NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE ;; LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION ;; OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION ;; WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ;;-- utilities -- (define check:write write) ;; You can also use a pretty printer if you have one. ;; However, the output might not improve for most cases ;; because the pretty printers usually output a trailing ;; newline. ;; -- mode -- (define check:mode #f) (define (check-set-mode! mode) (set! check:mode (case mode ((off) 0) ((summary) 1) ((report-failed) 10) ((report) 100) (else (error "unrecognized mode" mode))))) (check-set-mode! 'report) ;; -- state -- (define check:correct #f) (define check:failed #f) (define (check-reset!) (set! check:correct 0) (set! check:failed '())) (define (check:add-correct!) (set! check:correct (+ check:correct 1))) (define (check:add-failed! expression actual-result expected-result) (set! check:failed (cons (list expression actual-result expected-result) check:failed))) (check-reset!) ;; -- reporting -- (define (check:report-expression expression) (newline) (check:write expression) (display " => ")) (define (check:report-actual-result actual-result) (check:write actual-result) (display " ; ")) (define (check:report-correct cases) (display "correct") (if (not (= cases 1)) (begin (display " (") (display cases) (display " cases checked)"))) (newline)) (define (check:report-failed expected-result) (display "\033[00;31m*** failed ***\033[00m") (newline) (display " ; expected result: ") (check:write expected-result) (newline)) (define (check-report) (if (>= check:mode 1) (let ((clean? (zero? (length check:failed)))) (display "; *** checks *** : ") (display check:correct) (display " correct, ") (if (not clean?) (display "\033[00;31m")) (display (length check:failed)) (display " failed.") (if (not clean?) (display "\033[00m")) (if (or (null? check:failed) (<= check:mode 1)) (newline) (let* ((w (car (reverse check:failed))) (expression (car w)) (actual-result (cadr w)) (expected-result (caddr w))) (display " First failed example:") (newline) (check:report-expression expression) (check:report-actual-result actual-result) (check:report-failed expected-result)))))) (define (check-passed? expected-total-count) (and (= (length check:failed) 0) (= check:correct expected-total-count))) ;; -- simple checks -- (define (check:proc expression thunk equal expected-result) (case check:mode ((0) #f) ((1) (let ((actual-result (thunk))) (if (equal actual-result expected-result) (check:add-correct!) (check:add-failed! expression actual-result expected-result)))) ((10) (let ((actual-result (thunk))) (if (equal actual-result expected-result) (check:add-correct!) (begin (check:report-expression expression) (check:report-actual-result actual-result) (check:report-failed expected-result) (check:add-failed! expression actual-result expected-result))))) ((100) (check:report-expression expression) (let ((actual-result (thunk))) (check:report-actual-result actual-result) (if (equal actual-result expected-result) (begin (check:report-correct 1) (check:add-correct!)) (begin (check:report-failed expected-result) (check:add-failed! expression actual-result expected-result))))) (else (error "unrecognized check:mode" check:mode))) (if #f #f)) ;; -- parametric checks -- (define (check:proc-ec w) (let ((correct? (car w)) (expression (cadr w)) (actual-result (caddr w)) (expected-result (cadddr w)) (cases (car (cddddr w)))) (if correct? (begin (if (>= check:mode 100) (begin (check:report-expression expression) (check:report-actual-result actual-result) (check:report-correct cases))) (check:add-correct!)) (begin (if (>= check:mode 10) (begin (check:report-expression expression) (check:report-actual-result actual-result) (check:report-failed expected-result))) (check:add-failed! expression actual-result expected-result)))))
false
22fe131b9006767f6c6150861bb02308c00b0387
a74932f6308722180c9b89c35fda4139333703b8
/edwin48/grpops.scm
7af4c47c4984f8cb4ee45e26e7e4c15b89fd7645
[]
no_license
scheme/edwin48
16b5d865492db5e406085e8e78330dd029f1c269
fbe3c7ca14f1418eafddebd35f78ad12e42ea851
refs/heads/master
2021-01-19T17:59:16.986415
2014-12-21T17:50:27
2014-12-21T17:50:27
1,035,285
39
10
null
2022-02-15T23:21:14
2010-10-29T16:08:55
Scheme
UTF-8
Scheme
false
false
14,904
scm
grpops.scm
#| -*-Scheme-*- $Id: grpops.scm,v 1.35 2008/01/30 20:02:01 cph Exp $ Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 Massachusetts Institute of Technology This file is part of MIT/GNU Scheme. MIT/GNU Scheme is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. MIT/GNU Scheme is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with MIT/GNU Scheme; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. |# ;;;; Group Operations ;;; These high-performance ops deal directly with groups and indices ;;; for speed and the least consing. Since indices are not in general ;;; valid across modifications to the group, they can only be used in ;;; limited ways. To save an index across a modification, it must be ;;; consed into a permanent mark. ;;;; Extractions (define (group-extract-string group start end) (let ((text (group-text group)) (gap-start (group-gap-start group)) (string (make-string (fix:- end start)))) (cond ((fix:<= end gap-start) (%substring-move! text start end string 0)) ((fix:>= start gap-start) (%substring-move! text (fix:+ start (group-gap-length group)) (fix:+ end (group-gap-length group)) string 0)) (else (%substring-move! text start gap-start string 0) (%substring-move! text (group-gap-end group) (fix:+ end (group-gap-length group)) string (fix:- gap-start start)))) string)) (define (group-copy-substring! group start end string start*) (let ((text (group-text group)) (gap-start (group-gap-start group))) (cond ((fix:<= end gap-start) (%substring-move! text start end string start*)) ((fix:>= start gap-start) (%substring-move! text (fix:+ start (group-gap-length group)) (fix:+ end (group-gap-length group)) string start*)) (else (%substring-move! text start gap-start string start*) (%substring-move! text (group-gap-end group) (fix:+ end (group-gap-length group)) string (fix:+ start* (fix:- gap-start start))))))) (define (group-left-char group index) (string-ref (group-text group) (fix:- (group-index->position group index #f) 1))) (define (group-right-char group index) (string-ref (group-text group) (group-index->position group index #t))) (define (group-extract-and-delete-string! group start end) (let ((string (group-extract-string group start end))) (group-delete! group start end) string)) ;;;; Insertion (define (group-insert-char! group index char) (group-insert-chars! group index char 1)) (define (group-insert-chars! group index char n) (if (fix:< n 0) (error:bad-range-argument n 'GROUP-INSERT-CHARS!)) (without-interrupts (lambda () (prepare-gap-for-insert! group index n) (string-fill! (group-text group) char index (fix:+ index n)) (finish-group-insert! group index n)))) (define (group-insert-string! group index string) (group-insert-substring! group index string 0 (string-length string))) (define (group-insert-substring! group index string start end) (without-interrupts (lambda () (let ((n (fix:- end start))) (prepare-gap-for-insert! group index n) (%substring-move! string start end (group-text group) index) (finish-group-insert! group index n))))) (define (prepare-gap-for-insert! group new-start n) (if (or (group-read-only? group) (and (group-text-properties group) (text-not-insertable? group new-start))) (barf-if-read-only)) ; (if (not (group-modified? group)) (check-first-group-modification group)) (cond ((fix:< (group-gap-length group) n) (grow-group! group new-start n)) ((fix:< new-start (group-gap-start group)) (let ((new-end (fix:+ new-start (group-gap-length group)))) (%substring-move! (group-text group) new-start (group-gap-start group) (group-text group) new-end) (set-group-gap-start! group new-start) (set-group-gap-end! group new-end))) ((fix:> new-start (group-gap-start group)) (let ((new-end (fix:+ new-start (group-gap-length group)))) (%substring-move! (group-text group) (group-gap-end group) new-end (group-text group) (group-gap-start group)) (set-group-gap-start! group new-start) (set-group-gap-end! group new-end))))) (define (finish-group-insert! group index n) (set-group-gap-start! group (fix:+ index n)) (set-group-gap-length! group (fix:- (group-gap-length group) n)) (if (group-start-changes-index group) (begin (if (fix:< index (group-start-changes-index group)) (set-group-start-changes-index! group index)) (set-group-end-changes-index! group (if (fix:> index (group-end-changes-index group)) (fix:+ index n) (fix:+ (group-end-changes-index group) n)))) (begin (set-group-start-changes-index! group index) (set-group-end-changes-index! group (fix:+ index n)))) (do ((marks (group-marks group) (weak-cdr marks))) ((null? marks)) (if (and (weak-car marks) (or (fix:> (mark-index (weak-car marks)) index) (and (fix:= (mark-index (weak-car marks)) index) (mark-left-inserting? (weak-car marks))))) (set-mark-index! (weak-car marks) (fix:+ (mark-index (weak-car marks)) n)))) (set-group-modified-tick! group (fix:+ (group-modified-tick group) 1)) (undo-record-insertion! group index (fix:+ index n)) ;; The MODIFIED? bit must be set *after* the undo recording. (set-group-modified?! group #t) (if (group-text-properties group) (update-intervals-for-insertion! group index n))) ;;;; Deletion (define (group-delete-left-char! group index) (group-delete! group (fix:- index 1) index)) (define (group-delete-right-char! group index) (group-delete! group index (fix:+ index 1))) (define (group-delete! group start end) (if (not (and (fix:>= end 0) (fix:<= end (group-length group)))) (error:bad-range-argument end 'GROUP-DELETE!)) (if (not (and (fix:>= start 0) (fix:<= start end))) (error:bad-range-argument start 'GROUP-DELETE!)) (if (not (fix:= start end)) (without-interrupts (lambda () (let ((text (group-text group)) (gap-length (group-gap-length group))) (if (or (group-read-only? group) (and (group-text-properties group) (text-not-deleteable? group start end))) (barf-if-read-only)) (if (not (group-modified? group)) (check-first-group-modification group)) ;; Guarantee that the gap is between START and END. This is ;; best done before the undo recording. (cond ((fix:< (group-gap-start group) start) (%substring-move! text (group-gap-end group) (fix:+ start gap-length) text (group-gap-start group))) ((fix:> (group-gap-start group) end) (%substring-move! text end (group-gap-start group) text (fix:+ end gap-length)))) ;; The undo recording must occur *before* the deletion. (undo-record-deletion! group start end) (let ((gap-end (fix:+ end gap-length))) (set-group-gap-start! group start) (set-group-gap-end! group gap-end) (set-group-gap-length! group (fix:- gap-end start)) (if (and (group-shrink-length group) (fix:<= (fix:- (string-length text) (fix:- gap-end start)) (group-shrink-length group))) (shrink-group! group)))) (let ((n (fix:- end start))) (if (group-start-changes-index group) (begin (if (fix:< start (group-start-changes-index group)) (set-group-start-changes-index! group start)) (set-group-end-changes-index! group (if (fix:>= end (group-end-changes-index group)) start (fix:- (group-end-changes-index group) n)))) (begin (set-group-start-changes-index! group start) (set-group-end-changes-index! group start))) (do ((marks (group-marks group) (weak-cdr marks))) ((null? marks)) (cond ((or (not (weak-car marks)) (fix:<= (mark-index (weak-car marks)) start)) unspecific) ((fix:<= (mark-index (weak-car marks)) end) (set-mark-index! (weak-car marks) start)) (else (set-mark-index! (weak-car marks) (fix:- (mark-index (weak-car marks)) n)))))) (set-group-modified-tick! group (fix:+ (group-modified-tick group) 1)) ;; The MODIFIED? bit must be set *after* the undo recording. (set-group-modified?! group #t) (if (group-text-properties group) (update-intervals-for-deletion! group start end)))))) ;;;; Replacement (define (group-replace-char! group index char) (if (not (and (fix:>= index 0) (fix:< index (group-length group)))) (error:bad-range-argument index 'GROUP-REPLACE-CHAR!)) (without-interrupts (lambda () (let ((end-index (fix:+ index 1))) (prepare-gap-for-replace! group index end-index) (string-set! (group-text group) (group-index->position group index #t) char) (finish-group-replace! group index end-index))))) (define (group-replace-string! group index string) (group-replace-substring! group index string 0 (string-length string))) (define (group-replace-substring! group index string start end) (if (fix:< start end) (without-interrupts (lambda () (let ((end-index (fix:+ index (fix:- end start)))) (if (not (and (fix:>= index 0) (fix:<= end-index (group-length group)))) (error:bad-range-argument index 'GROUP-REPLACE-SUBSTRING!)) (prepare-gap-for-replace! group index end-index) (%substring-move! string start end (group-text group) (group-index->position group index #t)) (finish-group-replace! group index end-index)))))) (define (prepare-gap-for-replace! group start end) (if (or (group-read-only? group) (and (group-text-properties group) (text-not-replaceable? group start end))) (barf-if-read-only)) (if (not (group-modified? group)) (check-first-group-modification group)) (if (and (fix:< start (group-gap-start group)) (fix:< (group-gap-start group) end)) (let ((new-end (fix:+ end (group-gap-length group)))) (%substring-move! (group-text group) (group-gap-end group) new-end (group-text group) (group-gap-start group)) (set-group-gap-start! group end) (set-group-gap-end! group new-end))) (undo-record-replacement! group start end)) (define (finish-group-replace! group start end) (if (group-start-changes-index group) (begin (if (fix:< start (group-start-changes-index group)) (set-group-start-changes-index! group start)) (if (fix:> end (group-end-changes-index group)) (set-group-end-changes-index! group end))) (begin (set-group-start-changes-index! group start) (set-group-end-changes-index! group end))) (set-group-modified-tick! group (fix:+ (group-modified-tick group) 1)) ;; The MODIFIED? bit must be set *after* the undo recording. (set-group-modified?! group #t) (if (group-text-properties group) (update-intervals-for-replacement! group start end))) ;;;; Resizing (define (grow-group! group new-gap-start n) (let ((text (group-text group)) (gap-start (group-gap-start group)) (gap-end (group-gap-end group)) (realloc-factor (group-reallocation-factor group))) (let ((text-length (string-length text)) (gap-delta (- new-gap-start gap-start))) (let ((n-chars (- text-length (group-gap-length group)))) (let ((new-text-length (let ((minimum-text-length (+ n-chars n))) (let loop ((length (if (= text-length 0) 1 text-length))) (let ((length (ceiling (* length realloc-factor)))) (if (< length minimum-text-length) (loop length) length)))))) (let ((new-text (make-string new-text-length)) (new-gap-length (- new-text-length n-chars))) (let ((new-gap-end (+ new-gap-start new-gap-length))) (cond ((= gap-delta 0) (%substring-move! text 0 gap-start new-text 0) (%substring-move! text gap-end text-length new-text new-gap-end)) ((< gap-delta 0) (%substring-move! text 0 new-gap-start new-text 0) (%substring-move! text new-gap-start gap-start new-text new-gap-end) (%substring-move! text gap-end text-length new-text (- new-gap-end gap-delta))) (else (let ((ngsp (+ gap-end gap-delta))) (%substring-move! text 0 gap-start new-text 0) (%substring-move! text gap-end ngsp new-text gap-start) (%substring-move! text ngsp text-length new-text new-gap-end)))) (set-group-text! group new-text) (set-group-gap-start! group new-gap-start) (set-group-gap-end! group new-gap-end) (set-group-gap-length! group new-gap-length)))))) (memoize-shrink-length! group realloc-factor))) (define (shrink-group! group) (let ((text (group-text group)) (gap-start (group-gap-start group)) (gap-length (group-gap-length group)) (realloc-factor (group-reallocation-factor group))) (let ((text-length (string-length text))) (let ((n-chars (- text-length gap-length))) (let ((new-text-length (if (= n-chars 0) 0 (let loop ((length text-length)) (let ((length (floor (/ length realloc-factor)))) (let ((sl (compute-shrink-length length realloc-factor))) (if (< sl n-chars) length (loop length))))))) (gap-end (group-gap-end group))) (let ((new-text (make-string new-text-length)) (delta (- text-length new-text-length))) (let ((new-gap-end (- gap-end delta))) (%substring-move! text 0 gap-start new-text 0) (%substring-move! text gap-end text-length new-text new-gap-end) (set-group-gap-end! group new-gap-end) (set-group-gap-length! group (- gap-length delta))) (set-group-text! group new-text))))) (memoize-shrink-length! group realloc-factor))) (define (memoize-shrink-length! group realloc-factor) (set-group-shrink-length! group (compute-shrink-length (string-length (group-text group)) realloc-factor))) (define (compute-shrink-length length realloc-factor) (floor (/ (floor (/ length realloc-factor)) realloc-factor))) (define (group-reallocation-factor group) ;; We assume the result satisfies (LAMBDA (G) (AND (REAL? G) (> G 1))) (inexact->exact (ref-variable buffer-reallocation-factor group)))
false
698196b59a7ddc6aaccdd24c5dc28a67a6d7b18f
f4cf5bf3fb3c06b127dda5b5d479c74cecec9ce9
/Sources/LispKit/Resources/Libraries/srfi/214.sld
bb42392d0093a01e851876540c3981fd5e18421e
[ "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
26,008
sld
214.sld
;;; SRFI 214 ;;; Flexvectors ;;; ;;; A flexvector, also known as a dynamic array or an arraylist, is a mutable vector-like ;;; data structure with an adjustable size. Flexvectors allow fast random access and fast ;;; insertion/removal at the end. This SRFI defines a suite of operations on flexvectors, ;;; modeled after SRFI 133's vector operations. ;;; ;;; Copyright © 2020-2021 Adam Nelson. All rights reserved. ;;; ;;; Permission is hereby granted, free of charge, to any person obtaining a copy of this ;;; software and associated documentation files (the "Software"), to deal in the Software ;;; without restriction, including without limitation the rights to use, copy, modify, merge, ;;; publish, distribute, sublicense, and/or sell copies of the Software, and to permit ;;; persons to whom the Software is furnished to do so, subject to the following conditions: ;;; ;;; The above copyright notice and this permission notice shall be included in all copies or ;;; substantial portions of the Software. ;;; ;;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, ;;; INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR ;;; PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE ;;; FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR ;;; OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER ;;; DEALINGS IN THE SOFTWARE. ;;; ;;; Adaptation to LispKit ;;; Copyright © 2021 Matthias Zenger. All rights reserved. (define-library (srfi 214) (export ; Constructors make-flexvector flexvector flexvector-unfold flexvector-unfold-right flexvector-copy flexvector-reverse-copy flexvector-append flexvector-concatenate flexvector-append-subvectors ; Predicates flexvector? flexvector-empty? flexvector=? ; Selectors flexvector-ref flexvector-front flexvector-back flexvector-length ; Mutators flexvector-add! flexvector-add-front! flexvector-add-back! flexvector-remove! flexvector-remove-front! flexvector-remove-back! flexvector-add-all! flexvector-remove-range! flexvector-clear! flexvector-set! flexvector-swap! flexvector-fill! flexvector-reverse! flexvector-copy! flexvector-reverse-copy! flexvector-append! ; Iteration flexvector-fold flexvector-fold-right flexvector-map flexvector-map! flexvector-map/index flexvector-map/index! flexvector-append-map flexvector-append-map/index flexvector-filter flexvector-filter! flexvector-filter/index flexvector-filter/index! flexvector-for-each flexvector-for-each/index flexvector-count flexvector-cumulate ; Searching flexvector-index flexvector-index-right flexvector-skip flexvector-skip-right flexvector-binary-search flexvector-any flexvector-every flexvector-partition ; Conversion flexvector->vector flexvector->list flexvector->string vector->flexvector list->flexvector string->flexvector reverse-flexvector->list reverse-list->flexvector generator->flexvector flexvector->generator) (import (lispkit base) (srfi 1) (srfi 145)) (begin (define-record-type Flexvector (%make-flexvector fv-vector fv-length) flexvector? (fv-vector vec set-vec!) (fv-length flexvector-length set-flexvector-length!)) (define (cap fv) (vector-length (vec fv))) (define (grow! fv) (define old-vec (vec fv)) (define new-vec (make-vector (quotient (* (vector-length old-vec) 3) 2))) (vector-copy! new-vec 0 old-vec) (set-vec! fv new-vec) new-vec) (define make-flexvector (case-lambda ((size) (assume (>= size 0)) (%make-flexvector (make-vector (max size 4)) size)) ((size fill) (assume (>= size 0)) (%make-flexvector (make-vector (max size 4) fill) size)))) (define (flexvector . xs) (if (null? xs) (%make-flexvector (make-vector 4) 0) (list->flexvector xs))) (define (flexvector-ref fv index) (assume (flexvector? fv)) (assume (integer? index)) (assume (< -1 index (flexvector-length fv))) (vector-ref (vec fv) index)) (define (flexvector-set! fv index x) (assume (flexvector? fv)) (assume (integer? index)) (assume (< -1 index (flexvector-length fv))) (let ((last-value (vector-ref (vec fv) index))) (vector-set! (vec fv) index x) last-value)) (define flexvector-add! (case-lambda ((fv i x) (assume (flexvector? fv)) (assume (integer? i)) (let* ((len (flexvector-length fv)) (v (if (< len (cap fv)) (vec fv) (grow! fv)))) (assume (<= 0 i len)) (vector-copy! v (+ i 1) v i len) (vector-set! v i x) (set-flexvector-length! fv (+ len 1)) fv)) ((fv i . xs) (flexvector-add-all! fv i xs)))) (define flexvector-add-back! (case-lambda ((fv x) (assume (flexvector? fv)) (let* ((len (flexvector-length fv)) (v (if (< len (cap fv)) (vec fv) (grow! fv)))) (vector-set! v len x) (set-flexvector-length! fv (+ len 1)) fv)) ((fv x . xs) (flexvector-add-back! fv x) (apply flexvector-add-back! fv xs)))) (define (flexvector-add-all! fv i xs) (assume (flexvector? fv)) (assume (integer? i)) (assume (list? xs)) (let* ((len (flexvector-length fv)) (xv (list->vector xs)) (xvlen (vector-length xv)) (v (let lp ((v (vec fv))) (if (< (+ len xvlen) (vector-length v)) v (lp (grow! fv)))))) (assume (<= 0 i len)) (vector-copy! v (+ i xvlen) v i len) (vector-copy! v i xv 0 xvlen) (set-flexvector-length! fv (+ len xvlen)) fv)) (define (flexvector-remove! fv i) (assume (flexvector? fv)) (assume (integer? i)) (assume (<= 0 i (- (flexvector-length fv) 1))) (let ((removed (flexvector-ref fv i))) (flexvector-remove-range! fv i (+ i 1)) removed)) (define (flexvector-remove-range! fv start end) (assume (flexvector? fv)) (let ((len (flexvector-length fv))) (when (< start 0) (set! start 0)) (when (>= end len) (set! end len)) (assume (<= start end)) (vector-copy! (vec fv) start (vec fv) end) (let ((new-len (- len (- end start)))) (vector-fill! (vec fv) #f new-len len) (set-flexvector-length! fv new-len))) fv) (define (flexvector-clear! fv) (assume (flexvector? fv)) (set-vec! fv (make-vector 4)) (set-flexvector-length! fv 0) fv) (define vector->flexvector (case-lambda ((vec) (assume (vector? vec)) (vector->flexvector vec 0 (vector-length vec))) ((vec start) (assume (vector? vec)) (vector->flexvector vec start (vector-length vec))) ((vec start end) (assume (vector? vec)) (assume (<= 0 start end (vector-length vec))) (let ((len (- end start))) (cond ((< len 4) (let ((new-vec (make-vector 4))) (vector-copy! new-vec 0 vec start end) (%make-flexvector new-vec len))) (else (%make-flexvector (vector-copy vec start end) len))))))) (define flexvector->vector (case-lambda ((fv) (assume (flexvector? fv)) (flexvector->vector fv 0 (flexvector-length fv))) ((fv start) (assume (flexvector? fv)) (flexvector->vector fv start (flexvector-length fv))) ((fv start end) (assume (flexvector? fv)) (assume (<= 0 start end (flexvector-length fv))) (vector-copy (vec fv) start end)))) (define (list->flexvector xs) (let* ((vec (list->vector xs)) (len (vector-length vec))) (cond ((< len 4) (let ((new-vec (make-vector 4))) (vector-copy! new-vec 0 vec) (%make-flexvector new-vec len))) (else (%make-flexvector vec len))))) (define flexvector-filter/index! (case-lambda ((pred? fv) (assume (flexvector? fv)) (let ((v (vec fv)) (len (flexvector-length fv))) (let lp ((i 0) (j 0)) (cond ((>= i len) (set-flexvector-length! fv j) fv) ((pred? i (vector-ref v i)) (unless (= i j) (vector-set! v j (vector-ref v i))) (lp (+ i 1) (+ j 1))) (else (lp (+ i 1) j)))))) ((pred? fv . fvs) (assume (flexvector? fv)) (let ((v (vec fv)) (len (flexvector-length fv))) (let lp ((i 0) (j 0)) (cond ((>= i len) (set-flexvector-length! fv j) fv) ((apply pred? i (vector-ref v i) (map (lambda (fv) (flexvector-ref fv i)) fvs)) (unless (= i j) (vector-set! v j (vector-ref v i))) (lp (+ i 1) (+ j 1))) (else (lp (+ i 1) j)))))))) (define flexvector-copy (case-lambda ((fv) (assume (flexvector? fv)) (%make-flexvector (vector-copy (vec fv)) (flexvector-length fv))) ((fv start) (assume (flexvector? fv)) (flexvector-copy fv start (flexvector-length fv))) ((fv start end) (assume (flexvector? fv)) (assume (<= 0 start end (flexvector-length fv))) (vector->flexvector (vector-copy (vec fv) start end))))) (define flexvector-copy! (case-lambda ((to at from) (assume (flexvector? from)) (flexvector-copy! to at from 0 (flexvector-length from))) ((to at from start) (assume (flexvector? from)) (flexvector-copy! to at from start (flexvector-length from))) ((to at from start end) (assume (flexvector? to)) (assume (<= 0 at (flexvector-length to))) (assume (<= 0 start end (flexvector-length from))) (let* ((vf (vec from)) (lt (+ (flexvector-length to) (- end start))) (vt (let lp ((v (vec to))) (if (< lt (vector-length v)) v (lp (grow! to)))))) (vector-copy! vt at vf start end) (set-flexvector-length! to (max (flexvector-length to) (+ at (- end start)))))))) ) (begin (define flexvector-unfold (case-lambda ((p f g seed) (let ((fv (flexvector))) (assume (procedure? p)) (assume (procedure? f)) (assume (procedure? g)) (do ((seed seed (g seed))) ((p seed) fv) (flexvector-add-back! fv (f seed))))) ((p f g . seeds) (let ((fv (flexvector))) (assume (procedure? p)) (assume (procedure? f)) (assume (procedure? g)) (do ((seeds seeds (let-values ((seeds (apply g seeds))) seeds))) ((apply p seeds) fv) (flexvector-add-back! fv (apply f seeds))))))) (define (flexvector-unfold-right . args) (let ((fv (apply flexvector-unfold args))) (flexvector-reverse! fv) fv)) (define flexvector-fill! (case-lambda ((fv fill) (flexvector-fill! fv fill 0 (flexvector-length fv))) ((fv fill start) (flexvector-fill! fv fill start (flexvector-length fv))) ((fv fill start end) (let ((actual-end (min end (flexvector-length fv)))) (do ((i (max 0 start) (+ i 1))) ((>= i actual-end)) (flexvector-set! fv i fill)))))) (define (flexvector-reverse-copy . args) (let ((fv (apply flexvector-copy args))) (flexvector-reverse! fv) fv)) (define flexvector-reverse-copy! (case-lambda ((to at from) (assume (flexvector? from)) (flexvector-reverse-copy! to at from 0 (flexvector-length from))) ((to at from start) (assume (flexvector? from)) (flexvector-reverse-copy! to at from start (flexvector-length from))) ((to at from start end) (flexvector-copy! to at from start end) (flexvector-reverse! to at (+ at (- end start)))))) (define (flexvector-append! fv . fvs) (assume (flexvector? fv)) (assume (every flexvector? fvs)) (for-each (lambda (fv2) (flexvector-copy! fv (flexvector-length fv) fv2)) fvs) fv) (define (flexvector-front fv) (assume (flexvector? fv)) (assume (not (flexvector-empty? fv))) (flexvector-ref fv 0)) (define (flexvector-back fv) (assume (flexvector? fv)) (assume (not (flexvector-empty? fv))) (flexvector-ref fv (- (flexvector-length fv) 1))) (define flexvector-add-front! (case-lambda ((fv x) (flexvector-add! fv 0 x)) ((fv . xs) (apply flexvector-add! fv 0 xs)))) (define (flexvector-remove-front! fv) (assume (flexvector? fv)) (assume (not (flexvector-empty? fv))) (flexvector-remove! fv 0)) (define (flexvector-remove-back! fv) (assume (flexvector? fv)) (assume (not (flexvector-empty? fv))) (flexvector-remove! fv (- (flexvector-length fv) 1))) (define (flexvector=? eq . o) (cond ((null? o) #t) ((null? (cdr o)) #t) (else (and (let* ((fv1 (car o)) (fv2 (cadr o)) (len (flexvector-length fv1))) (and (= len (flexvector-length fv2)) (let lp ((i 0)) (or (>= i len) (and (eq (flexvector-ref fv1 i) (flexvector-ref fv2 i)) (lp (+ i 1))))))) (apply flexvector=? eq (cdr o)))))) (define (flexvector-fold kons knil fv1 . o) (assume (procedure? kons)) (assume (flexvector? fv1)) (let ((len (flexvector-length fv1))) (if (null? o) (let lp ((i 0) (acc knil)) (if (>= i len) acc (lp (+ i 1) (kons acc (flexvector-ref fv1 i))))) (let lp ((i 0) (acc knil)) (if (>= i len) acc (lp (+ i 1) (apply kons acc (flexvector-ref fv1 i) (map (lambda (fv) (flexvector-ref fv i)) o)))))))) (define (flexvector-fold-right kons knil fv1 . o) (assume (procedure? kons)) (assume (flexvector? fv1)) (let ((len (flexvector-length fv1))) (if (null? o) (let lp ((i (- len 1)) (acc knil)) (if (negative? i) acc (lp (- i 1) (kons acc (flexvector-ref fv1 i))))) (let lp ((i (- len 1)) (acc knil)) (if (negative? i) acc (lp (- i 1) (apply kons acc (flexvector-ref fv1 i) (map (lambda (fv) (flexvector-ref fv i)) o)))))))) (define flexvector-for-each/index (case-lambda ((proc fv) (assume (procedure? proc)) (assume (flexvector? fv)) (let ((len (flexvector-length fv))) (do ((i 0 (+ i 1))) ((= i len)) (proc i (flexvector-ref fv i))))) ((proc . fvs) (assume (procedure? proc)) (let ((len (apply min (map flexvector-length fvs)))) (do ((i 0 (+ i 1))) ((= i len)) (apply proc i (map (lambda (fv) (flexvector-ref fv i)) fvs))))))) (define flexvector-for-each (case-lambda ((proc fv) (assume (procedure? proc)) (flexvector-for-each/index (lambda (i x) (proc x)) fv)) ((proc . fvs) (assume (procedure? proc)) (apply flexvector-for-each/index (lambda (i . xs) (apply proc xs)) fvs)))) (define flexvector-map/index! (case-lambda ((proc fv) (assume (procedure? proc)) (assume (flexvector? fv)) (flexvector-for-each/index (lambda (i x) (flexvector-set! fv i (proc i x))) fv) fv) ((proc fv . fvs) (assume (procedure? proc)) (assume (flexvector? fv)) (apply flexvector-for-each/index (lambda (i . xs) (flexvector-set! fv i (apply proc i xs))) fv fvs) fv))) (define flexvector-map! (case-lambda ((proc fv) (assume (procedure? proc)) (flexvector-map/index! (lambda (i x) (proc x)) fv)) ((proc . fvs) (assume (procedure? proc)) (apply flexvector-map/index! (lambda (i . xs) (apply proc xs)) fvs)))) (define (flexvector-map/index proc fv . fvs) (assume (flexvector? fv)) (apply flexvector-map/index! proc (flexvector-copy fv) fvs)) (define (flexvector-map proc fv . fvs) (assume (flexvector? fv)) (apply flexvector-map! proc (flexvector-copy fv) fvs)) (define (flexvector-append-map/index proc fv . fvs) (define out (flexvector)) (flexvector-for-each (lambda (x) (flexvector-append! out x)) (apply flexvector-map/index proc fv fvs)) out) (define (flexvector-append-map proc fv . fvs) (define out (flexvector)) (flexvector-for-each (lambda (x) (flexvector-append! out x)) (apply flexvector-map proc fv fvs)) out) (define flexvector-filter! (case-lambda ((pred? fv) (assume (procedure? pred?)) (assume (flexvector? fv)) (flexvector-filter/index! (lambda (i x) (pred? x)) fv)) ((pred? . fvs) (assume (procedure? pred?)) (apply flexvector-filter/index! (lambda (i . xs) (apply pred? xs)) fvs)))) (define (flexvector-filter/index proc fv . fvs) (assume (flexvector? fv)) (apply flexvector-filter/index! proc (flexvector-copy fv) fvs)) (define (flexvector-filter proc fv . fvs) (assume (flexvector? fv)) (apply flexvector-filter! proc (flexvector-copy fv) fvs)) (define (flexvector-index pred? fv1 . o) (assume (procedure? pred?)) (assume (flexvector? fv1)) (let ((len (flexvector-length fv1))) (let lp ((i 0)) (and (< i len) (if (apply pred? (flexvector-ref fv1 i) (map (lambda (fv) (flexvector-ref fv i)) o)) i (lp (+ i 1))))))) (define (flexvector-index-right pred? fv1 . o) (assume (procedure? pred?)) (assume (flexvector? fv1)) (let ((len (flexvector-length fv1))) (let lp ((i (- len 1))) (and (>= i 0) (if (apply pred? (flexvector-ref fv1 i) (map (lambda (fv) (flexvector-ref fv i)) o)) i (lp (- i 1))))))) (define (complement f) (lambda args (not (apply f args)))) (define (flexvector-skip pred? fv1 . o) (assume (procedure? pred?)) (assume (flexvector? fv1)) (apply flexvector-index (complement pred?) fv1 o)) (define (flexvector-skip-right pred? fv1 . o) (assume (procedure? pred?)) (assume (flexvector? fv1)) (apply flexvector-index-right (complement pred?) fv1 o)) (define flexvector-binary-search (case-lambda ((fv value cmp) (flexvector-binary-search fv value cmp 0 (flexvector-length fv))) ((fv value cmp start) (flexvector-binary-search fv value cmp start (flexvector-length fv))) ((fv value cmp start end) (assume (flexvector? fv)) (assume (procedure? cmp)) (assume (integer? start)) (assume (integer? end)) (assume (<= start end)) (let lp ((lo (max start 0)) (hi (- (min end (flexvector-length fv)) 1))) (and (<= lo hi) (let* ((mid (quotient (+ lo hi) 2)) (x (flexvector-ref fv mid)) (y (cmp value x))) (cond ((< y 0) (lp lo (- mid 1))) ((> y 0) (lp (+ mid 1) hi)) (else mid)))))))) (define (flexvector-any pred? fv . o) (assume (procedure? pred?)) (assume (flexvector? fv)) (let ((len (apply min (flexvector-length fv) (map flexvector-length o)))) (let lp ((i 0)) (and (< i len) (or (apply pred? (flexvector-ref fv i) (map (lambda (v) (flexvector-ref v i)) o)) (lp (+ i 1))))))) (define (flexvector-every pred? fv . o) (assume (procedure? pred?)) (assume (flexvector? fv)) (let ((len (apply min (flexvector-length fv) (map flexvector-length o)))) (or (zero? len) (let lp ((i 0)) (let ((x (apply pred? (flexvector-ref fv i) (map (lambda (v) (flexvector-ref v i)) o)))) (if (= i (- len 1)) x (and x (lp (+ i 1))))))))) (define (flexvector-swap! fv i j) (assume (flexvector? fv)) (assume (integer? i)) (assume (integer? j)) (let ((tmp (flexvector-ref fv i))) (flexvector-set! fv i (flexvector-ref fv j)) (flexvector-set! fv j tmp))) (define (flexvector-reverse! fv . o) (assume (flexvector? fv)) (let lp ((left (if (pair? o) (car o) 0)) (right (- (if (and (pair? o) (pair? (cdr o))) (cadr o) (flexvector-length fv)) 1))) (cond ((>= left right) (if #f #f)) (else (flexvector-swap! fv left right) (lp (+ left 1) (- right 1)))))) (define (flexvector-append fv . fvs) (assume (flexvector? fv)) (apply flexvector-append! (flexvector-copy fv) fvs)) (define (flexvector-concatenate ls) (apply flexvector-append ls)) (define (flexvector-append-subvectors . o) (let lp ((ls o) (vecs '())) (if (null? ls) (flexvector-concatenate (reverse vecs)) (lp (cdr (cddr ls)) (cons (flexvector-copy (car ls) (cadr ls) (car (cddr ls))) vecs))))) (define (flexvector-empty? fv) (assume (flexvector? fv)) (zero? (flexvector-length fv))) (define (flexvector-count pred? fv1 . o) (assume (procedure? pred?)) (assume (flexvector? fv1)) (apply flexvector-fold (lambda (count . x) (+ count (if (apply pred? x) 1 0))) 0 fv1 o)) (define (flexvector-cumulate f knil fv) (assume (procedure? f)) (assume (flexvector? fv)) (let* ((len (flexvector-length fv)) (res (make-vector len))) (let lp ((i 0) (acc knil)) (if (>= i len) (vector->flexvector res) (let ((acc (f acc (flexvector-ref fv i)))) (vector-set! res i acc) (lp (+ i 1) acc)))))) (define (flexvector-partition pred? fv) (assume (procedure? pred?)) (assume (flexvector? fv)) (let ((left (flexvector)) (right (flexvector))) (flexvector-for-each (lambda (x) (flexvector-add-back! (if (pred? x) left right) x)) fv) (values left right))) (define (flexvector->list fv) (assume (flexvector? fv)) (flexvector-fold-right (lambda (x y) (cons y x)) '() fv)) (define (reverse-flexvector->list fv . o) (assume (flexvector? fv)) (flexvector->list (apply flexvector-reverse-copy fv o))) (define (reverse-list->flexvector ls) (assume (list? ls)) (let ((fv (list->flexvector ls))) (flexvector-reverse! fv) fv)) (define (string->flexvector s . o) (assume (string? s)) (vector->flexvector (apply string->vector s o))) (define (flexvector->string fv . o) (assume (flexvector? fv)) (vector->string (apply flexvector->vector fv o))) (define (generator->flexvector g) (assume (procedure? g)) (flexvector-unfold eof-object? (lambda (x) x) (lambda (_) (g)) (g))) (define (flexvector->generator fv) (assume (flexvector? fv)) (let ((i 0)) (lambda () (if (< i (flexvector-length fv)) (let ((element (flexvector-ref fv i))) (set! i (+ i 1)) element) (eof-object))))) ) )
false
7984692091a09764207e673122ef052c7f399e04
fba55a7038615b7967256306ee800f2a055df92f
/vvalkyrie/1.1/ex-1-07.scm
eaa3d02b2fd985e99d195f3a902e5d4766d11474
[]
no_license
lisp-korea/sicp2014
7e8ccc17fc85b64a1c66154b440acd133544c0dc
9e60f70cb84ad2ad5987a71aebe1069db288b680
refs/heads/master
2016-09-07T19:09:28.818346
2015-10-17T01:41:13
2015-10-17T01:41:13
26,661,049
2
3
null
null
null
null
UTF-8
Scheme
false
false
467
scm
ex-1-07.scm
#lang planet neil/sicp (define (square x) (* x x)) (define (average x y) (/ (+ x y) 2)) (define (sqrt-iter old-guess guess x) (if (good-enough? old-guess guess x) guess (sqrt-iter guess (improve guess x) x))) (define (good-enough? old-guess guess x) (and (< (abs (- (square guess) x)) 0.001) (< 0 (abs (- old-guess guess)) 0.000001))) (define (improve guess x) (average guess (/ x guess))) (define (sqrt x) (sqrt-iter 0.0 1.0 x))
false
446e2bba18f803373177c6f11a542dd5918345df
86092887e6e28ebc92875339a38271319a87ea0d
/Ch2/2_23.scm
123eb4a2979fb8025a84404b492d0a6b73b5b451
[]
no_license
a2lin/sicp
5637a172ae15cd1f27ffcfba79d460329ec52730
eeb8df9188f2a32f49695074a81a2c684fe6e0a1
refs/heads/master
2021-01-16T23:55:38.885463
2016-12-25T07:52:07
2016-12-25T07:52:07
57,107,602
1
0
null
null
null
null
UTF-8
Scheme
false
false
118
scm
2_23.scm
(define (for-each fn eles) (map fn eles)) (for-each (lambda (x) (newline) (display x)) (list 57 321 88))
false
45a6b7acc5c3aaec6a22d18e599696d943238596
307481dbdfd91619aa5fd854c0a19cd592408f1b
/node_modules/biwascheme/,/77-list-sort/test1.scm
0968a61d97eb381a967a9f2d1e2d501c65121db1
[ "MIT", "CC-BY-3.0" ]
permissive
yukarigohan/firstrepository
38ff2db62bb8baa85b21daf65b12765e10691d46
2bcdb91cbb6f01033e2e0a987a9dfee9d3a98ac7
refs/heads/master
2020-04-20T10:59:02.600980
2019-02-02T07:08:41
2019-02-02T07:08:41
168,803,970
0
0
null
null
null
null
UTF-8
Scheme
false
false
542
scm
test1.scm
; 実際にソートしてみて、ちゃんと安定ソートできてるか確かめる (dotimes (i 30 #f) (define n (random-integer 1000)) (define v (vector-map (lambda (i) (vector (random-integer 12345) i)) (list->vector (iota n)))) ;(print v) (define v2 (js-invoke v "sort" (js-closure (lambda (a b) (- (vector-ref a 0) (vector-ref b 0)))))) (vector-sort! (lambda (a b) (< (vector-ref a 0) (vector-ref b 0))) v) (print (equal? v v2)))
false
89c9b307102ee0f9fe26e3660ea7a3f52e33705d
9998f6f6940dc91a99e0e2acb4bc4e918f49eef0
/src/test/eqhash-performance-check.ss
09c068aedc61f72b227bc2b87ae38f40a10cbc37
[]
no_license
JessamynT/wescheme-compiler2012
326d66df382f3d2acbc2bbf70fdc6b6549beb514
a8587f9d316b3cb66d8a01bab3cf16f415d039e5
refs/heads/master
2020-05-30T07:16:45.185272
2016-03-19T07:14:34
2016-03-19T07:14:34
70,086,162
0
0
null
2016-10-05T18:09:51
2016-10-05T18:09:51
null
UTF-8
Scheme
false
false
798
ss
eqhash-performance-check.ss
#lang s-exp "../moby-lang.ss" ;; A little performance test. ;; On my Macbook pro, (OS X 10.5.8, 2.33Ghz) ;; Moby 2.26: takes about 1300 milliseconds (define BIG-NUMBER 40000) (define-struct blah ()) (define elements (build-list BIG-NUMBER (lambda (x) (make-blah)))) (define ht (make-hasheq)) "starting" (for-each (lambda (x) (hash-set! ht x true)) elements) (for-each (lambda (x) (cond [(hash-ref ht x false) 'ok] [else (error 'broke "It broke.")])) elements) (for-each (lambda (x) (cond [(hash-ref ht x false) (error 'broke "It broke.")] [else 'ok])) (build-list BIG-NUMBER (lambda (x) (make-hash)))) "done"
false
5fc3e5b59fd86f7de29bae713bed85eddd35967f
000dbfe5d1df2f18e29a76ea7e2a9556cff5e866
/ext/crypto/tests/testvectors/hmac/hmac_sha3_256_test.scm
e717ed9d7db63063e8fa2bcdca14b9967e71fa18
[ "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
58,150
scm
hmac_sha3_256_test.scm
(test-hmac "hmac_sha3_256_test" :algorithm "HMACSHA3-256" :key-size 256 :tag-size 256 :tests '(#(1 "empty message" #vu8(30 34 92 175 185 3 57 187 161 178 64 118 212 32 108 62 121 195 85 128 93 133 22 130 188 129 139 170 79 90 119 121) #vu8() #vu8(163 197 132 112 175 168 131 93 110 35 87 251 123 28 208 127 140 75 196 199 135 76 165 157 131 22 63 4 106 158 34 126) #t ()) #(2 "short message" #vu8(129 89 253 21 19 60 217 100 201 166 150 76 148 240 234 38 154 128 111 217 244 63 13 165 139 108 209 179 61 24 155 42) #vu8(119) #vu8(247 9 163 93 65 232 46 54 149 85 18 191 95 193 175 12 26 156 88 15 248 252 49 153 188 183 69 64 39 2 146 130) #t ()) #(3 "short message" #vu8(133 167 203 170 232 37 187 130 201 182 246 197 194 175 90 192 61 31 109 170 99 210 169 60 24 153 72 236 65 185 222 217) #vu8(165 155) #vu8(189 50 62 73 76 61 34 189 225 209 29 189 228 88 248 27 190 89 0 7 180 44 76 238 28 196 80 48 210 183 51 207) #t ()) #(4 "short message" #vu8(72 243 2 147 52 229 92 251 213 116 204 199 101 251 44 54 133 170 177 244 131 125 35 55 8 116 163 230 52 195 167 109) #vu8(199 184 178) #vu8(122 217 40 210 247 233 5 170 202 155 214 61 52 228 184 76 88 237 55 244 57 185 184 91 51 241 244 124 139 170 38 218) #t ()) #(5 "short message" #vu8(222 139 91 91 47 9 100 91 228 126 203 100 7 164 225 217 198 179 58 227 194 210 37 23 211 53 125 160 53 122 49 57) #vu8(204 2 29 101) #vu8(138 93 182 3 69 170 124 196 175 179 158 100 94 222 135 177 110 115 211 125 240 69 98 62 197 142 158 144 31 150 226 36) #t ()) #(6 "short message" #vu8(183 147 137 16 245 24 241 50 5 202 20 146 198 105 0 26 20 255 145 60 138 180 160 220 53 100 231 65 142 145 41 124) #vu8(164 166 239 110 189) #vu8(223 209 221 254 201 197 19 61 26 43 227 60 74 151 141 59 238 120 116 8 149 165 177 225 92 84 84 40 66 228 200 222) #t ()) #(7 "short message" #vu8(27 185 151 255 77 232 165 163 145 222 92 8 163 59 194 199 194 137 30 71 173 91 156 99 17 1 146 247 139 152 254 120) #vu8(102 126 1 93 247 252) #vu8(202 94 143 3 158 252 17 55 206 253 18 140 64 226 117 231 39 129 27 194 247 133 247 34 35 67 194 134 111 128 180 77) #t ()) #(8 "short message" #vu8(50 253 237 163 159 152 180 244 66 108 45 42 192 10 181 221 75 250 187 104 243 17 68 114 86 237 109 61 58 81 177 84) #vu8(65 99 169 247 126 65 245) #vu8(6 211 136 72 185 13 10 121 117 103 203 111 166 142 59 45 151 11 44 82 234 145 20 120 110 181 74 162 45 64 62 112) #t ()) #(9 "short message" #vu8(35 62 79 222 231 11 204 32 35 91 105 119 221 252 5 176 223 102 245 99 93 130 124 102 229 166 60 219 22 162 73 56) #vu8(253 178 238 75 109 26 10 194) #vu8(121 155 48 65 142 194 97 153 54 176 38 11 181 2 100 239 76 130 51 153 116 24 96 77 4 248 232 211 24 212 255 60) #t ()) #(10 "short message" #vu8(185 132 198 115 78 11 209 43 23 55 178 252 122 27 56 3 180 223 236 64 33 64 165 123 158 204 195 84 20 174 102 27) #vu8(222 165 132 208 226 161 74 213 253) #vu8(104 67 131 226 70 15 210 112 4 69 50 233 91 94 131 254 197 32 255 169 157 210 168 152 170 140 136 165 215 109 160 45) #t ()) #(11 "short message" #vu8(208 202 241 69 106 197 226 85 250 106 253 97 167 157 200 199 22 245 53 138 41 138 80 130 113 54 63 225 255 152 53 97) #vu8(24 38 29 200 6 145 60 83 70 102) #vu8(102 91 143 112 60 113 154 106 75 252 233 117 103 5 10 186 119 170 238 166 110 112 253 62 195 125 82 185 184 14 201 55) #t ()) #(12 "short message" #vu8(131 91 200 36 30 216 23 115 94 201 211 208 226 223 76 23 62 228 221 237 74 142 240 192 74 150 196 143 17 130 4 99) #vu8(38 248 8 62 148 75 172 240 78 154 77) #vu8(82 8 133 47 64 197 254 110 151 186 115 58 159 208 170 57 224 57 225 178 210 80 29 163 97 174 14 146 252 189 110 125) #t ()) #(13 "short message" #vu8(5 95 149 201 70 27 8 9 87 94 204 223 165 205 208 98 117 242 93 48 145 92 78 184 219 64 225 172 211 171 117 145) #vu8(191 183 214 160 141 186 165 34 95 50 8 135) #vu8(103 137 8 166 2 201 194 21 4 154 146 34 31 34 152 16 57 194 207 209 198 153 188 54 15 125 165 230 208 150 123 90) #t ()) #(14 "short message" #vu8(228 15 122 62 184 141 222 196 198 52 126 164 214 118 16 117 108 130 200 235 204 35 118 41 191 135 60 202 188 50 152 74) #vu8(127 228 63 235 199 132 116 100 158 69 191 153 178) #vu8(128 189 191 106 188 101 238 66 35 255 245 233 29 97 164 163 227 151 50 134 223 180 230 43 81 191 247 210 228 164 228 60) #t ()) #(15 "short message" #vu8(176 32 173 29 225 193 65 247 236 97 94 229 112 21 33 119 63 155 35 46 77 6 55 108 56 40 148 206 81 166 31 72) #vu8(129 199 88 26 25 75 94 113 180 17 70 165 130 193) #vu8(74 87 231 183 212 56 185 60 139 121 81 239 120 155 147 161 59 32 214 70 63 219 212 250 0 38 53 75 153 89 162 115) #t ()) #(16 "short message" #vu8(159 63 214 26 16 82 2 100 142 207 246 7 76 149 229 2 193 197 26 205 50 236 83 138 92 206 137 239 132 31 121 137) #vu8(42 118 242 172 218 206 66 227 183 121 114 73 70 145 44) #vu8(249 91 98 118 96 236 225 117 48 79 54 167 1 230 71 242 111 7 148 182 213 226 38 242 226 114 239 158 155 246 151 68) #t ()) #(17 "" #vu8(111 163 83 134 140 130 229 222 238 218 199 240 148 113 166 27 247 73 171 84 152 35 158 148 126 1 46 238 60 130 215 196) #vu8(174 237 62 77 76 185 187 182 13 72 46 152 193 38 192 245) #vu8(76 81 152 230 154 66 219 45 119 170 233 151 92 150 66 153 112 164 188 100 221 144 109 140 177 104 131 162 22 163 243 4) #t ()) #(18 "" #vu8(83 0 72 148 148 202 134 34 28 145 214 217 83 149 42 225 165 224 151 19 157 201 207 17 121 194 245 100 51 117 56 36) #vu8(144 254 166 207 43 216 17 180 73 243 51 238 146 51 229 118 151) #vu8(168 173 230 233 30 151 171 180 207 110 146 212 188 241 251 59 143 27 227 185 218 74 221 9 176 228 84 75 151 143 190 20) #t ()) #(19 "" #vu8(56 62 124 92 19 71 106 98 38 132 35 239 5 0 71 159 158 134 226 54 197 160 129 198 68 145 137 230 175 223 42 245) #vu8(50 2 112 90 248 159 149 85 197 64 176 225 39 105 17 208 25 113 171 178 195 92 120 178) #vu8(233 180 254 129 150 114 61 181 109 89 34 17 151 241 26 113 63 33 161 127 210 23 120 135 38 196 217 138 79 87 48 160) #t ()) #(20 "" #vu8(24 110 36 138 216 36 225 235 147 50 154 127 220 213 101 182 203 78 175 63 133 185 11 145 7 119 18 141 140 83 141 39) #vu8(146 239 159 245 47 70 236 204 126 56 185 238 25 253 45 227 179 119 38 200 230 206 158 27 150 219 93 218 76 49 121 2) #vu8(213 101 250 161 121 190 20 216 198 103 158 0 35 95 218 157 181 180 188 19 192 11 135 107 230 44 246 28 48 221 131 146) #t ()) #(21 "long message" #vu8(40 133 92 126 252 133 50 217 37 103 48 9 51 204 28 162 208 88 111 85 220 201 240 84 252 202 47 5 37 79 191 127) #vu8(156 9 32 127 240 230 229 130 203 55 71 220 169 84 201 77 69 192 94 147 241 230 242 17 121 207 14 37 180 206 222 116 181 71 157 50 245 22 105 53 200 111 4 65 144 88 101) #vu8(40 118 1 46 107 223 200 152 153 184 208 128 245 227 172 88 76 65 80 229 224 187 190 163 169 139 170 104 215 76 120 147) #t ()) #(22 "long message" #vu8(142 84 12 179 12 148 131 106 226 165 149 15 53 93 72 42 112 2 226 85 32 126 148 253 163 247 239 26 9 144 19 160) #vu8(214 80 15 149 225 18 98 227 8 191 61 244 223 75 133 95 51 232 87 86 61 69 67 241 149 99 154 10 23 180 66 235 159 220 193 54 125 46 238 117 200 248 5 115 11 137 41 15) #vu8(57 74 209 133 252 141 139 19 81 196 163 170 150 231 246 204 216 232 23 216 111 36 74 66 119 145 248 101 245 170 29 60) #t ()) #(23 "long message" #vu8(105 197 13 82 116 53 129 136 207 244 192 250 231 66 36 61 78 138 94 91 165 93 148 255 64 237 217 15 106 67 221 16) #vu8(26 197 37 90 255 5 40 40 216 234 33 179 118 241 235 221 75 184 121 148 153 19 144 4 5 174 188 232 62 72 254 182 129 59 94 156 137 249 69 1 168 173 228 27 38 184 21 197 33) #vu8(146 141 132 249 206 52 181 181 230 193 215 72 106 54 159 45 148 24 102 41 170 217 77 100 76 22 114 136 99 235 97 154) #t ()) #(24 "long message" #vu8(35 32 155 124 90 173 203 209 63 114 121 175 26 134 211 199 174 143 23 157 27 202 170 208 223 249 161 83 2 231 141 191) #vu8(132 189 172 55 225 175 53 217 53 100 4 226 120 125 71 236 229 131 72 222 167 106 74 70 232 170 222 52 99 212 219 140 148 160 81 190 55 51 179 141 117 105 132 134 93 86 198 14 128 37 241 94 63 150 143 9 62 127 183 235 199 227 17 137 197 105 45 21 237 66 86 115 123 155 24 148 229 128 149 3 170 161 201 152 63 176 150 170 33 145 99 97 238 182 239 69 91 18 151 35 161 161 221 249 222 221 234 32 133 41 166 72) #vu8(14 64 138 136 76 237 172 111 1 157 252 19 54 77 202 244 144 243 245 66 179 212 121 94 16 191 156 85 100 30 59 46) #t ()) #(25 "long message" #vu8(124 156 198 103 202 225 117 244 72 250 169 102 71 49 150 51 178 212 133 49 55 58 231 211 22 196 77 221 139 159 105 207) #vu8(146 51 193 215 59 73 140 81 6 255 136 149 30 7 185 101 44 176 221 174 116 7 55 236 32 92 152 118 208 148 151 139 252 148 127 125 201 55 17 159 214 169 57 21 177 155 98 89 88 167 162 35 99 170 42 195 63 184 105 237 22 179 3 51 106 183 64 160 73 138 45 246 106 101 153 218 113 0 148 72 26 123 84 75 217 85 182 249 113 53 186 70 115 64 29 178 219 20 74 110 40 112 65 228 122 81 237 155 107 169 86 193 53 8 193 192 194 83 16 16 82 57 171 115 98 158 48) #vu8(133 119 165 145 193 207 32 67 52 188 63 69 0 141 195 115 210 195 102 200 149 154 20 77 185 104 27 54 74 89 29 84) #t ()) #(26 "long message" #vu8(130 49 69 64 86 78 163 206 48 89 30 151 246 139 38 2 222 64 250 41 247 115 194 80 131 39 71 27 131 72 232 196) #vu8(106 109 47 69 206 191 39 87 174 22 234 51 198 134 23 103 29 119 248 253 248 11 237 143 197 205 197 200 183 8 107 210 142 126 179 238 204 113 99 73 17 4 229 48 148 85 230 127 131 101 121 184 42 29 163 191 89 145 168 226 178 241 137 164 158 5 112 14 70 196 9 237 93 231 119 128 165 243 137 227 241 61 173 64 108 157 85 103 83 41 197 201 33 240 112 52 24 9 55 192 246 239 52 162 48 139 111 243 225 160 233 220 30 166 95 86 50 115 14 135 68 209 219 44 64 166 89 91) #vu8(119 58 83 151 1 229 86 98 254 17 240 22 144 183 13 172 41 54 110 85 172 87 194 81 153 52 57 151 46 173 124 228) #t ()) #(27 "long message" #vu8(209 21 172 201 166 54 145 82 65 121 95 72 133 32 82 224 123 81 39 58 226 68 130 81 236 29 13 15 152 7 243 219) #vu8(105 109 36 86 222 133 63 160 40 244 134 254 244 55 182 182 209 181 48 168 71 94 41 157 179 169 0 90 233 206 248 64 25 133 183 211 30 23 46 143 67 156 205 26 209 236 68 201 184 107 120 243 242 67 193 48 91 83 188 33 171 173 122 143 197 37 99 17 191 211 76 152 227 125 253 198 73 231 174 75 218 8 207 41 148 176 99 192 199 16 110 208 176 42 31 72 175 145 145 203 251 13 106 149 59 126 4 50 125 254 140 147 119 156 181 116 186 156 186 87 93 1 103 78 131 98 26 160 197 244 0 214 230 205 36 179 1 227 60 159 51 3 231 59 243 87 64 140 27 232 108 36 137 192 157 233 152 255 46 243 45 245 84 241 36 125 147 19 206 26 113 96 17 93 6 244 193 141 101 86 255 121 134 239 138 85 226 173 207 162 126 76 105 199 28 194 255 1 99 158 157 73 189 158 208 104 127 83 15 254 176 137 1 50 69 125 242 8 128 129 188 74 47 127 10 159 77 206 162 200 13 153 29 183 243 116 122 24 3 215 97 154 175 61 211 130 198 149 54 160 188 219 147 28 190) #vu8(47 42 134 43 208 217 243 5 19 86 41 57 107 5 152 128 84 224 245 16 56 131 137 34 113 162 11 121 2 224 203 134) #t ()) #(28 "Flipped bit 0 in tag" #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31) #vu8() #vu8(81 171 22 6 3 67 131 254 75 59 75 192 163 65 168 46 64 172 133 228 85 205 254 237 76 172 144 42 123 140 207 193) #f ()) #(29 "Flipped bit 0 in tag" #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31) #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15) #vu8(10 122 235 158 171 155 87 168 13 123 208 234 39 38 57 74 86 20 78 42 15 192 185 121 208 144 193 132 108 20 179 237) #f ()) #(30 "Flipped bit 1 in tag" #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31) #vu8() #vu8(82 171 22 6 3 67 131 254 75 59 75 192 163 65 168 46 64 172 133 228 85 205 254 237 76 172 144 42 123 140 207 193) #f ()) #(31 "Flipped bit 1 in tag" #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31) #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15) #vu8(9 122 235 158 171 155 87 168 13 123 208 234 39 38 57 74 86 20 78 42 15 192 185 121 208 144 193 132 108 20 179 237) #f ()) #(32 "Flipped bit 7 in tag" #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31) #vu8() #vu8(208 171 22 6 3 67 131 254 75 59 75 192 163 65 168 46 64 172 133 228 85 205 254 237 76 172 144 42 123 140 207 193) #f ()) #(33 "Flipped bit 7 in tag" #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31) #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15) #vu8(139 122 235 158 171 155 87 168 13 123 208 234 39 38 57 74 86 20 78 42 15 192 185 121 208 144 193 132 108 20 179 237) #f ()) #(34 "Flipped bit 8 in tag" #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31) #vu8() #vu8(80 170 22 6 3 67 131 254 75 59 75 192 163 65 168 46 64 172 133 228 85 205 254 237 76 172 144 42 123 140 207 193) #f ()) #(35 "Flipped bit 8 in tag" #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31) #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15) #vu8(11 123 235 158 171 155 87 168 13 123 208 234 39 38 57 74 86 20 78 42 15 192 185 121 208 144 193 132 108 20 179 237) #f ()) #(36 "Flipped bit 31 in tag" #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31) #vu8() #vu8(80 171 22 134 3 67 131 254 75 59 75 192 163 65 168 46 64 172 133 228 85 205 254 237 76 172 144 42 123 140 207 193) #f ()) #(37 "Flipped bit 31 in tag" #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31) #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15) #vu8(11 122 235 30 171 155 87 168 13 123 208 234 39 38 57 74 86 20 78 42 15 192 185 121 208 144 193 132 108 20 179 237) #f ()) #(38 "Flipped bit 32 in tag" #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31) #vu8() #vu8(80 171 22 6 2 67 131 254 75 59 75 192 163 65 168 46 64 172 133 228 85 205 254 237 76 172 144 42 123 140 207 193) #f ()) #(39 "Flipped bit 32 in tag" #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31) #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15) #vu8(11 122 235 158 170 155 87 168 13 123 208 234 39 38 57 74 86 20 78 42 15 192 185 121 208 144 193 132 108 20 179 237) #f ()) #(40 "Flipped bit 33 in tag" #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31) #vu8() #vu8(80 171 22 6 1 67 131 254 75 59 75 192 163 65 168 46 64 172 133 228 85 205 254 237 76 172 144 42 123 140 207 193) #f ()) #(41 "Flipped bit 33 in tag" #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31) #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15) #vu8(11 122 235 158 169 155 87 168 13 123 208 234 39 38 57 74 86 20 78 42 15 192 185 121 208 144 193 132 108 20 179 237) #f ()) #(42 "Flipped bit 63 in tag" #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31) #vu8() #vu8(80 171 22 6 3 67 131 126 75 59 75 192 163 65 168 46 64 172 133 228 85 205 254 237 76 172 144 42 123 140 207 193) #f ()) #(43 "Flipped bit 63 in tag" #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31) #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15) #vu8(11 122 235 158 171 155 87 40 13 123 208 234 39 38 57 74 86 20 78 42 15 192 185 121 208 144 193 132 108 20 179 237) #f ()) #(44 "Flipped bit 64 in tag" #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31) #vu8() #vu8(80 171 22 6 3 67 131 254 74 59 75 192 163 65 168 46 64 172 133 228 85 205 254 237 76 172 144 42 123 140 207 193) #f ()) #(45 "Flipped bit 64 in tag" #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31) #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15) #vu8(11 122 235 158 171 155 87 168 12 123 208 234 39 38 57 74 86 20 78 42 15 192 185 121 208 144 193 132 108 20 179 237) #f ()) #(46 "Flipped bit 71 in tag" #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31) #vu8() #vu8(80 171 22 6 3 67 131 254 203 59 75 192 163 65 168 46 64 172 133 228 85 205 254 237 76 172 144 42 123 140 207 193) #f ()) #(47 "Flipped bit 71 in tag" #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31) #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15) #vu8(11 122 235 158 171 155 87 168 141 123 208 234 39 38 57 74 86 20 78 42 15 192 185 121 208 144 193 132 108 20 179 237) #f ()) #(48 "Flipped bit 77 in tag" #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31) #vu8() #vu8(80 171 22 6 3 67 131 254 75 27 75 192 163 65 168 46 64 172 133 228 85 205 254 237 76 172 144 42 123 140 207 193) #f ()) #(49 "Flipped bit 77 in tag" #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31) #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15) #vu8(11 122 235 158 171 155 87 168 13 91 208 234 39 38 57 74 86 20 78 42 15 192 185 121 208 144 193 132 108 20 179 237) #f ()) #(50 "Flipped bit 80 in tag" #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31) #vu8() #vu8(80 171 22 6 3 67 131 254 75 59 74 192 163 65 168 46 64 172 133 228 85 205 254 237 76 172 144 42 123 140 207 193) #f ()) #(51 "Flipped bit 80 in tag" #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31) #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15) #vu8(11 122 235 158 171 155 87 168 13 123 209 234 39 38 57 74 86 20 78 42 15 192 185 121 208 144 193 132 108 20 179 237) #f ()) #(52 "Flipped bit 96 in tag" #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31) #vu8() #vu8(80 171 22 6 3 67 131 254 75 59 75 192 162 65 168 46 64 172 133 228 85 205 254 237 76 172 144 42 123 140 207 193) #f ()) #(53 "Flipped bit 96 in tag" #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31) #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15) #vu8(11 122 235 158 171 155 87 168 13 123 208 234 38 38 57 74 86 20 78 42 15 192 185 121 208 144 193 132 108 20 179 237) #f ()) #(54 "Flipped bit 97 in tag" #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31) #vu8() #vu8(80 171 22 6 3 67 131 254 75 59 75 192 161 65 168 46 64 172 133 228 85 205 254 237 76 172 144 42 123 140 207 193) #f ()) #(55 "Flipped bit 97 in tag" #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31) #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15) #vu8(11 122 235 158 171 155 87 168 13 123 208 234 37 38 57 74 86 20 78 42 15 192 185 121 208 144 193 132 108 20 179 237) #f ()) #(56 "Flipped bit 103 in tag" #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31) #vu8() #vu8(80 171 22 6 3 67 131 254 75 59 75 192 35 65 168 46 64 172 133 228 85 205 254 237 76 172 144 42 123 140 207 193) #f ()) #(57 "Flipped bit 103 in tag" #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31) #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15) #vu8(11 122 235 158 171 155 87 168 13 123 208 234 167 38 57 74 86 20 78 42 15 192 185 121 208 144 193 132 108 20 179 237) #f ()) #(58 "Flipped bit 248 in tag" #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31) #vu8() #vu8(80 171 22 6 3 67 131 254 75 59 75 192 163 65 168 46 64 172 133 228 85 205 254 237 76 172 144 42 123 140 207 192) #f ()) #(59 "Flipped bit 248 in tag" #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31) #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15) #vu8(11 122 235 158 171 155 87 168 13 123 208 234 39 38 57 74 86 20 78 42 15 192 185 121 208 144 193 132 108 20 179 236) #f ()) #(60 "Flipped bit 249 in tag" #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31) #vu8() #vu8(80 171 22 6 3 67 131 254 75 59 75 192 163 65 168 46 64 172 133 228 85 205 254 237 76 172 144 42 123 140 207 195) #f ()) #(61 "Flipped bit 249 in tag" #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31) #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15) #vu8(11 122 235 158 171 155 87 168 13 123 208 234 39 38 57 74 86 20 78 42 15 192 185 121 208 144 193 132 108 20 179 239) #f ()) #(62 "Flipped bit 254 in tag" #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31) #vu8() #vu8(80 171 22 6 3 67 131 254 75 59 75 192 163 65 168 46 64 172 133 228 85 205 254 237 76 172 144 42 123 140 207 129) #f ()) #(63 "Flipped bit 254 in tag" #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31) #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15) #vu8(11 122 235 158 171 155 87 168 13 123 208 234 39 38 57 74 86 20 78 42 15 192 185 121 208 144 193 132 108 20 179 173) #f ()) #(64 "Flipped bit 255 in tag" #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31) #vu8() #vu8(80 171 22 6 3 67 131 254 75 59 75 192 163 65 168 46 64 172 133 228 85 205 254 237 76 172 144 42 123 140 207 65) #f ()) #(65 "Flipped bit 255 in tag" #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31) #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15) #vu8(11 122 235 158 171 155 87 168 13 123 208 234 39 38 57 74 86 20 78 42 15 192 185 121 208 144 193 132 108 20 179 109) #f ()) #(66 "Flipped bits 0 and 64 in tag" #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31) #vu8() #vu8(81 171 22 6 3 67 131 254 74 59 75 192 163 65 168 46 64 172 133 228 85 205 254 237 76 172 144 42 123 140 207 193) #f ()) #(67 "Flipped bits 0 and 64 in tag" #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31) #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15) #vu8(10 122 235 158 171 155 87 168 12 123 208 234 39 38 57 74 86 20 78 42 15 192 185 121 208 144 193 132 108 20 179 237) #f ()) #(68 "Flipped bits 31 and 63 in tag" #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31) #vu8() #vu8(80 171 22 134 3 67 131 126 75 59 75 192 163 65 168 46 64 172 133 228 85 205 254 237 76 172 144 42 123 140 207 193) #f ()) #(69 "Flipped bits 31 and 63 in tag" #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31) #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15) #vu8(11 122 235 30 171 155 87 40 13 123 208 234 39 38 57 74 86 20 78 42 15 192 185 121 208 144 193 132 108 20 179 237) #f ()) #(70 "Flipped bits 63 and 127 in tag" #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31) #vu8() #vu8(80 171 22 6 3 67 131 126 75 59 75 192 163 65 168 174 64 172 133 228 85 205 254 237 76 172 144 42 123 140 207 193) #f ()) #(71 "Flipped bits 63 and 127 in tag" #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31) #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15) #vu8(11 122 235 158 171 155 87 40 13 123 208 234 39 38 57 202 86 20 78 42 15 192 185 121 208 144 193 132 108 20 179 237) #f ()) #(72 "all bits of tag flipped" #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31) #vu8() #vu8(175 84 233 249 252 188 124 1 180 196 180 63 92 190 87 209 191 83 122 27 170 50 1 18 179 83 111 213 132 115 48 62) #f ()) #(73 "all bits of tag flipped" #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31) #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15) #vu8(244 133 20 97 84 100 168 87 242 132 47 21 216 217 198 181 169 235 177 213 240 63 70 134 47 111 62 123 147 235 76 18) #f ()) #(74 "Tag changed to all zero" #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31) #vu8() #vu8(0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0) #f ()) #(75 "Tag changed to all zero" #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31) #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15) #vu8(0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0) #f ()) #(76 "tag changed to all 1" #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31) #vu8() #vu8(255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255) #f ()) #(77 "tag changed to all 1" #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31) #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15) #vu8(255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255) #f ()) #(78 "msbs changed in tag" #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31) #vu8() #vu8(208 43 150 134 131 195 3 126 203 187 203 64 35 193 40 174 192 44 5 100 213 77 126 109 204 44 16 170 251 12 79 65) #f ()) #(79 "msbs changed in tag" #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31) #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15) #vu8(139 250 107 30 43 27 215 40 141 251 80 106 167 166 185 202 214 148 206 170 143 64 57 249 80 16 65 4 236 148 51 109) #f ()) #(80 "lsbs changed in tag" #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31) #vu8() #vu8(81 170 23 7 2 66 130 255 74 58 74 193 162 64 169 47 65 173 132 229 84 204 255 236 77 173 145 43 122 141 206 192) #f ()) #(81 "lsbs changed in tag" #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31) #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15) #vu8(10 123 234 159 170 154 86 169 12 122 209 235 38 39 56 75 87 21 79 43 14 193 184 120 209 145 192 133 109 21 178 236) #f ()))) (test-hmac "hmac_sha3_256_test" :algorithm "HMACSHA3-256" :key-size 256 :tag-size 128 :tests '(#(82 "empty message" #vu8(123 249 229 54 182 106 33 92 34 35 63 226 218 170 116 58 137 139 154 203 159 120 2 222 112 180 14 61 110 67 239 151) #vu8() #vu8(208 135 121 10 250 178 84 119 69 109 55 156 171 22 57 209) #t ()) #(83 "short message" #vu8(231 84 7 108 234 179 253 175 79 155 202 183 212 240 223 12 187 175 188 135 115 27 143 155 124 210 22 100 114 232 238 188) #vu8(64) #vu8(155 212 83 27 118 147 60 146 103 213 221 14 233 188 129 185) #t ()) #(84 "short message" #vu8(234 59 1 107 221 56 125 214 77 131 124 113 104 56 8 243 53 219 220 83 89 138 78 168 197 249 82 71 63 175 175 95) #vu8(102 1) #vu8(121 150 95 72 79 255 131 80 221 240 252 176 204 81 63 19) #t ()) #(85 "short message" #vu8(115 212 112 150 55 133 125 175 171 106 216 178 176 165 27 6 82 71 23 254 223 16 2 150 100 79 124 253 170 225 128 91) #vu8(241 211 0) #vu8(55 116 126 199 126 120 68 168 28 51 85 249 194 247 40 117) #t ()) #(86 "short message" #vu8(213 200 27 57 157 76 13 21 131 161 61 165 109 230 210 220 69 166 110 123 71 194 74 177 25 46 36 109 201 97 221 119) #vu8(42 230 60 191) #vu8(173 109 22 39 215 161 246 123 133 83 129 218 68 253 78 195) #t ()) #(87 "short message" #vu8(37 33 32 63 160 221 223 89 216 55 178 131 15 135 177 170 97 249 88 21 93 243 202 77 29 242 69 124 180 40 77 200) #vu8(175 58 1 94 161) #vu8(15 202 34 132 165 211 52 108 191 155 152 166 88 34 168 167) #t ()) #(88 "short message" #vu8(102 90 2 188 38 90 102 208 23 117 9 29 165 103 38 182 102 139 253 144 60 183 175 102 251 27 120 168 160 98 228 60) #vu8(63 86 147 93 239 63) #vu8(140 216 127 106 225 97 78 74 115 29 82 173 13 135 116 66) #t ()) #(89 "short message" #vu8(250 205 117 178 34 33 56 0 71 48 91 201 129 245 112 226 161 175 56 146 142 167 226 5 158 58 245 252 107 130 180 147) #vu8(87 187 134 190 237 21 111) #vu8(115 148 27 121 203 124 159 12 123 113 27 185 68 65 180 50) #t ()) #(90 "short message" #vu8(80 90 169 136 25 128 158 246 59 154 54 138 30 139 194 233 34 218 69 176 60 224 45 154 121 102 177 80 6 219 162 213) #vu8(46 78 126 247 40 254 17 175) #vu8(92 242 176 79 227 175 141 38 148 186 78 97 67 103 192 138) #t ()) #(91 "short message" #vu8(249 66 9 56 66 128 139 164 127 100 228 39 247 53 29 222 107 149 70 230 109 228 231 214 10 166 243 40 24 39 18 207) #vu8(133 42 33 217 40 72 230 39 199) #vu8(62 6 171 138 176 31 255 182 88 101 167 232 161 35 179 116) #t ()) #(92 "short message" #vu8(100 190 22 43 57 198 229 241 254 217 195 45 159 103 77 154 140 222 110 170 36 67 33 77 134 189 74 31 181 59 129 180) #vu8(25 90 59 41 47 147 186 255 10 44) #vu8(128 203 42 180 229 126 197 81 253 115 163 252 188 98 37 56) #t ()) #(93 "short message" #vu8(178 89 165 85 212 75 138 32 197 72 158 47 56 57 45 218 166 190 158 53 185 131 59 103 225 181 253 246 203 62 76 108) #vu8(175 215 49 23 51 12 110 133 40 166 228) #vu8(113 206 182 221 60 207 12 150 177 90 228 43 67 44 29 131) #t ()) #(94 "short message" #vu8(44 111 198 45 170 119 186 140 104 129 179 221 105 137 137 143 239 100 102 99 204 123 10 61 184 34 138 112 123 133 242 220) #vu8(15 245 77 107 103 89 18 12 46 138 81 227) #vu8(239 94 94 74 149 142 120 32 177 63 206 61 24 31 42 118) #t ()) #(95 "short message" #vu8(171 171 129 93 81 223 41 247 64 228 226 7 159 183 152 224 21 40 54 230 171 87 209 83 106 232 146 158 82 192 110 184) #vu8(240 5 141 65 42 16 78 83 216 32 185 90 127) #vu8(213 108 186 243 174 233 49 15 102 8 63 36 42 55 175 254) #t ()) #(96 "short message" #vu8(61 93 161 175 131 247 40 116 88 191 247 167 101 30 165 216 219 114 37 148 1 51 63 107 130 9 105 150 221 126 175 25) #vu8(170 204 54 151 47 24 48 87 145 159 245 123 73 225) #vu8(101 32 180 155 138 17 171 219 229 172 70 244 236 0 255 188) #t ()) #(97 "short message" #vu8(193 155 223 49 76 108 246 67 129 66 84 103 244 42 239 161 124 28 201 53 139 225 108 227 27 29 33 72 89 206 134 170) #vu8(93 6 106 146 195 0 233 182 221 214 58 124 19 174 51) #vu8(63 20 230 181 93 38 145 166 4 139 112 186 183 206 173 166) #t ()) #(98 "" #vu8(97 46 131 120 67 206 174 127 97 212 150 37 250 167 231 73 79 146 83 226 12 179 173 206 166 134 81 43 4 57 54 205) #vu8(204 55 250 225 95 116 90 47 64 226 200 177 146 242 179 141) #vu8(34 244 143 134 104 245 194 80 83 21 240 181 37 207 79 149) #t ()) #(99 "" #vu8(115 33 111 175 208 2 45 13 110 226 113 152 178 39 37 120 250 143 4 221 159 68 70 127 187 100 55 170 69 100 27 247) #vu8(213 36 123 143 108 62 220 191 177 213 145 209 62 206 35 210 245) #vu8(49 162 160 55 35 197 30 4 97 26 176 157 71 191 37 152) #t ()) #(100 "" #vu8(4 39 167 14 37 117 40 243 171 112 100 11 186 26 93 225 44 243 136 93 212 200 226 132 251 187 85 254 179 82 148 165) #vu8(19 147 127 133 68 244 66 112 208 17 117 160 17 247 103 14 147 250 107 167 239 2 51 110) #vu8(237 101 26 151 120 84 251 92 197 119 171 125 183 181 103 175) #t ()) #(101 "" #vu8(150 225 228 137 111 178 205 5 241 51 166 161 0 188 86 9 167 172 60 166 216 23 33 233 34 218 221 105 173 7 168 146) #vu8(145 161 126 77 252 195 22 106 26 221 38 255 14 124 18 5 110 138 101 79 40 166 222 36 244 186 115 156 235 91 91 24) #vu8(163 205 249 103 120 225 249 164 42 137 249 20 38 135 63 241) #t ()) #(102 "long message" #vu8(65 32 21 103 190 78 110 160 109 226 41 95 208 230 232 167 216 98 187 87 49 24 148 245 37 216 173 234 187 164 163 228) #vu8(88 200 199 59 221 63 53 12 151 71 120 22 234 228 208 120 156 147 105 192 233 156 36 137 2 199 0 188 41 237 152 100 37 152 94 179 250 85 112 155 115 191 98 12 217 177 203) #vu8(21 207 93 162 49 44 253 143 157 235 221 139 58 176 125 107) #t ()) #(103 "long message" #vu8(100 158 55 62 104 30 245 46 60 16 172 38 84 132 117 9 50 169 145 143 40 251 130 79 124 181 10 218 179 151 129 254) #vu8(57 180 71 189 58 1 152 60 28 183 97 180 86 214 144 0 148 140 235 135 5 98 165 54 18 106 13 24 168 231 228 155 22 222 143 230 114 241 61 8 8 216 183 217 87 137 153 23) #vu8(93 220 172 185 173 11 2 218 201 96 18 180 164 209 114 157) #t ()) #(104 "long message" #vu8(123 13 35 127 123 83 110 44 105 80 153 14 97 179 97 179 132 51 61 218 105 0 69 197 145 50 26 78 63 121 116 127) #vu8(61 98 131 209 28 2 25 181 37 98 14 155 245 185 253 136 125 63 15 112 122 203 31 189 255 171 13 151 165 198 208 127 197 71 118 46 14 125 215 196 58 211 95 171 28 121 15 128 71) #vu8(120 28 25 108 13 113 216 142 141 183 104 85 113 173 19 228) #t ()) #(105 "long message" #vu8(23 201 38 99 116 31 1 46 91 182 113 78 97 76 45 21 89 72 97 127 16 147 98 105 217 84 197 138 186 42 230 45) #vu8(127 221 106 21 200 97 208 49 63 102 53 215 125 197 94 17 95 241 140 138 176 99 181 208 62 171 71 46 236 168 122 55 129 136 242 88 19 81 92 249 11 108 255 169 74 143 243 107 41 214 86 3 234 179 251 210 170 149 0 178 97 225 132 4 152 147 220 108 162 1 11 236 172 22 48 83 242 17 7 11 221 166 33 184 189 138 247 126 69 2 104 96 59 82 219 52 201 11 232 54 223 235 221 239 66 48 63 114 78 99 191 15) #vu8(60 49 233 250 46 166 52 242 191 189 13 127 109 191 41 194) #t ()) #(106 "long message" #vu8(66 76 107 34 96 111 204 9 74 232 47 197 211 203 228 132 23 76 34 17 179 236 119 128 145 202 195 74 142 56 161 82) #vu8(217 111 240 98 226 73 14 142 12 84 197 168 184 158 133 178 90 102 217 61 124 43 147 189 254 248 70 183 13 56 103 39 70 164 185 136 208 143 21 165 197 39 202 79 44 128 229 63 124 106 192 82 27 197 126 190 56 32 145 128 203 249 52 224 187 235 88 207 182 61 117 218 100 175 65 208 156 225 116 175 24 150 244 37 34 145 15 206 211 94 160 0 64 46 149 253 58 199 170 109 94 10 107 83 59 8 121 188 70 96 25 179 165 230 177 110 75 209 234 108 223 201 204 193 214 240 240) #vu8(15 147 122 165 181 170 94 250 111 140 25 64 201 181 123 25) #t ()) #(107 "long message" #vu8(21 213 83 200 218 67 61 83 205 199 241 80 135 167 3 73 202 171 87 179 121 164 7 137 40 206 155 153 48 46 49 166) #vu8(214 192 197 59 115 247 79 180 38 173 253 193 67 215 13 183 247 168 248 237 50 162 250 239 38 60 249 171 17 117 55 182 185 209 114 139 209 0 12 31 40 144 108 108 230 173 33 134 43 250 77 104 156 26 142 190 56 104 185 146 9 139 127 152 27 42 245 24 154 106 222 223 245 58 108 112 200 54 147 245 200 214 56 90 154 138 77 202 1 124 87 22 172 77 91 151 101 197 202 42 181 249 134 126 2 121 81 152 192 185 82 126 7 208 138 245 45 188 185 28 235 61 139 65 42 43 36 2) #vu8(178 148 138 27 111 160 85 141 68 60 11 140 238 135 196 200) #t ()) #(108 "long message" #vu8(255 229 89 70 138 16 49 223 179 206 210 227 129 231 75 88 33 163 109 154 191 95 46 89 137 90 127 220 160 250 86 160) #vu8(35 136 153 168 74 60 241 82 2 161 251 239 71 65 225 51 251 36 192 9 160 205 131 133 76 109 29 124 146 102 212 195 234 254 109 29 252 24 241 56 69 204 218 215 254 39 118 39 181 253 95 242 85 92 230 223 222 30 224 120 84 10 10 53 144 198 217 191 47 182 59 169 175 190 147 128 231 151 190 124 208 23 100 92 90 54 19 238 243 142 248 158 59 116 97 230 231 0 255 43 77 238 245 99 108 157 33 152 177 67 247 151 202 24 32 163 220 197 212 98 235 244 168 196 192 158 178 2 162 53 146 235 149 36 8 44 121 173 218 143 205 86 210 86 4 26 38 191 143 82 57 98 186 145 28 229 165 120 101 112 214 91 227 196 223 114 46 216 131 3 2 6 95 235 223 148 71 21 41 138 31 187 125 16 182 141 125 162 191 136 147 36 49 76 229 30 129 92 127 191 3 170 10 131 88 175 243 168 110 183 163 63 154 73 35 102 13 179 4 126 121 59 235 176 198 145 143 67 149 212 0 56 23 35 253 174 40 50 195 110 252 142 54 138 104 243 15 99 81 195 188 148 44 213 96) #vu8(156 137 146 131 172 224 53 32 213 16 158 67 195 13 70 152) #t ()) #(109 "Flipped bit 0 in tag" #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31) #vu8() #vu8(81 171 22 6 3 67 131 254 75 59 75 192 163 65 168 46) #f ()) #(110 "Flipped bit 0 in tag" #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31) #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15) #vu8(10 122 235 158 171 155 87 168 13 123 208 234 39 38 57 74) #f ()) #(111 "Flipped bit 1 in tag" #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31) #vu8() #vu8(82 171 22 6 3 67 131 254 75 59 75 192 163 65 168 46) #f ()) #(112 "Flipped bit 1 in tag" #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31) #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15) #vu8(9 122 235 158 171 155 87 168 13 123 208 234 39 38 57 74) #f ()) #(113 "Flipped bit 7 in tag" #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31) #vu8() #vu8(208 171 22 6 3 67 131 254 75 59 75 192 163 65 168 46) #f ()) #(114 "Flipped bit 7 in tag" #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31) #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15) #vu8(139 122 235 158 171 155 87 168 13 123 208 234 39 38 57 74) #f ()) #(115 "Flipped bit 8 in tag" #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31) #vu8() #vu8(80 170 22 6 3 67 131 254 75 59 75 192 163 65 168 46) #f ()) #(116 "Flipped bit 8 in tag" #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31) #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15) #vu8(11 123 235 158 171 155 87 168 13 123 208 234 39 38 57 74) #f ()) #(117 "Flipped bit 31 in tag" #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31) #vu8() #vu8(80 171 22 134 3 67 131 254 75 59 75 192 163 65 168 46) #f ()) #(118 "Flipped bit 31 in tag" #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31) #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15) #vu8(11 122 235 30 171 155 87 168 13 123 208 234 39 38 57 74) #f ()) #(119 "Flipped bit 32 in tag" #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31) #vu8() #vu8(80 171 22 6 2 67 131 254 75 59 75 192 163 65 168 46) #f ()) #(120 "Flipped bit 32 in tag" #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31) #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15) #vu8(11 122 235 158 170 155 87 168 13 123 208 234 39 38 57 74) #f ()) #(121 "Flipped bit 33 in tag" #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31) #vu8() #vu8(80 171 22 6 1 67 131 254 75 59 75 192 163 65 168 46) #f ()) #(122 "Flipped bit 33 in tag" #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31) #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15) #vu8(11 122 235 158 169 155 87 168 13 123 208 234 39 38 57 74) #f ()) #(123 "Flipped bit 63 in tag" #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31) #vu8() #vu8(80 171 22 6 3 67 131 126 75 59 75 192 163 65 168 46) #f ()) #(124 "Flipped bit 63 in tag" #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31) #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15) #vu8(11 122 235 158 171 155 87 40 13 123 208 234 39 38 57 74) #f ()) #(125 "Flipped bit 64 in tag" #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31) #vu8() #vu8(80 171 22 6 3 67 131 254 74 59 75 192 163 65 168 46) #f ()) #(126 "Flipped bit 64 in tag" #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31) #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15) #vu8(11 122 235 158 171 155 87 168 12 123 208 234 39 38 57 74) #f ()) #(127 "Flipped bit 71 in tag" #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31) #vu8() #vu8(80 171 22 6 3 67 131 254 203 59 75 192 163 65 168 46) #f ()) #(128 "Flipped bit 71 in tag" #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31) #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15) #vu8(11 122 235 158 171 155 87 168 141 123 208 234 39 38 57 74) #f ()) #(129 "Flipped bit 77 in tag" #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31) #vu8() #vu8(80 171 22 6 3 67 131 254 75 27 75 192 163 65 168 46) #f ()) #(130 "Flipped bit 77 in tag" #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31) #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15) #vu8(11 122 235 158 171 155 87 168 13 91 208 234 39 38 57 74) #f ()) #(131 "Flipped bit 80 in tag" #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31) #vu8() #vu8(80 171 22 6 3 67 131 254 75 59 74 192 163 65 168 46) #f ()) #(132 "Flipped bit 80 in tag" #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31) #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15) #vu8(11 122 235 158 171 155 87 168 13 123 209 234 39 38 57 74) #f ()) #(133 "Flipped bit 96 in tag" #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31) #vu8() #vu8(80 171 22 6 3 67 131 254 75 59 75 192 162 65 168 46) #f ()) #(134 "Flipped bit 96 in tag" #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31) #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15) #vu8(11 122 235 158 171 155 87 168 13 123 208 234 38 38 57 74) #f ()) #(135 "Flipped bit 97 in tag" #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31) #vu8() #vu8(80 171 22 6 3 67 131 254 75 59 75 192 161 65 168 46) #f ()) #(136 "Flipped bit 97 in tag" #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31) #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15) #vu8(11 122 235 158 171 155 87 168 13 123 208 234 37 38 57 74) #f ()) #(137 "Flipped bit 103 in tag" #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31) #vu8() #vu8(80 171 22 6 3 67 131 254 75 59 75 192 35 65 168 46) #f ()) #(138 "Flipped bit 103 in tag" #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31) #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15) #vu8(11 122 235 158 171 155 87 168 13 123 208 234 167 38 57 74) #f ()) #(139 "Flipped bit 120 in tag" #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31) #vu8() #vu8(80 171 22 6 3 67 131 254 75 59 75 192 163 65 168 47) #f ()) #(140 "Flipped bit 120 in tag" #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31) #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15) #vu8(11 122 235 158 171 155 87 168 13 123 208 234 39 38 57 75) #f ()) #(141 "Flipped bit 121 in tag" #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31) #vu8() #vu8(80 171 22 6 3 67 131 254 75 59 75 192 163 65 168 44) #f ()) #(142 "Flipped bit 121 in tag" #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31) #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15) #vu8(11 122 235 158 171 155 87 168 13 123 208 234 39 38 57 72) #f ()) #(143 "Flipped bit 126 in tag" #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31) #vu8() #vu8(80 171 22 6 3 67 131 254 75 59 75 192 163 65 168 110) #f ()) #(144 "Flipped bit 126 in tag" #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31) #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15) #vu8(11 122 235 158 171 155 87 168 13 123 208 234 39 38 57 10) #f ()) #(145 "Flipped bit 127 in tag" #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31) #vu8() #vu8(80 171 22 6 3 67 131 254 75 59 75 192 163 65 168 174) #f ()) #(146 "Flipped bit 127 in tag" #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31) #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15) #vu8(11 122 235 158 171 155 87 168 13 123 208 234 39 38 57 202) #f ()) #(147 "Flipped bits 0 and 64 in tag" #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31) #vu8() #vu8(81 171 22 6 3 67 131 254 74 59 75 192 163 65 168 46) #f ()) #(148 "Flipped bits 0 and 64 in tag" #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31) #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15) #vu8(10 122 235 158 171 155 87 168 12 123 208 234 39 38 57 74) #f ()) #(149 "Flipped bits 31 and 63 in tag" #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31) #vu8() #vu8(80 171 22 134 3 67 131 126 75 59 75 192 163 65 168 46) #f ()) #(150 "Flipped bits 31 and 63 in tag" #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31) #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15) #vu8(11 122 235 30 171 155 87 40 13 123 208 234 39 38 57 74) #f ()) #(151 "Flipped bits 63 and 127 in tag" #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31) #vu8() #vu8(80 171 22 6 3 67 131 126 75 59 75 192 163 65 168 174) #f ()) #(152 "Flipped bits 63 and 127 in tag" #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31) #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15) #vu8(11 122 235 158 171 155 87 40 13 123 208 234 39 38 57 202) #f ()) #(153 "all bits of tag flipped" #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31) #vu8() #vu8(175 84 233 249 252 188 124 1 180 196 180 63 92 190 87 209) #f ()) #(154 "all bits of tag flipped" #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31) #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15) #vu8(244 133 20 97 84 100 168 87 242 132 47 21 216 217 198 181) #f ()) #(155 "Tag changed to all zero" #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31) #vu8() #vu8(0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0) #f ()) #(156 "Tag changed to all zero" #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31) #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15) #vu8(0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0) #f ()) #(157 "tag changed to all 1" #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31) #vu8() #vu8(255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255) #f ()) #(158 "tag changed to all 1" #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31) #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15) #vu8(255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255) #f ()) #(159 "msbs changed in tag" #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31) #vu8() #vu8(208 43 150 134 131 195 3 126 203 187 203 64 35 193 40 174) #f ()) #(160 "msbs changed in tag" #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31) #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15) #vu8(139 250 107 30 43 27 215 40 141 251 80 106 167 166 185 202) #f ()) #(161 "lsbs changed in tag" #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31) #vu8() #vu8(81 170 23 7 2 66 130 255 74 58 74 193 162 64 169 47) #f ()) #(162 "lsbs changed in tag" #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31) #vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15) #vu8(10 123 234 159 170 154 86 169 12 122 209 235 38 39 56 75) #f ()))) (test-hmac "hmac_sha3_256_test" :algorithm "HMACSHA3-256" :key-size 128 :tag-size 256 :tests '(#(163 "short key" #vu8(163 73 172 10 159 159 116 228 142 9 156 195 219 249 169 201) #vu8() #vu8(238 130 52 202 34 182 203 216 124 194 186 73 46 206 163 154 235 198 52 3 41 152 150 86 137 211 147 226 212 248 134 83) #t ()) #(164 "short key" #vu8(172 104 107 160 241 165 27 78 196 240 179 4 146 183 245 86) #vu8(47 164 58 20 174 80 5 7 222 185 90 181 189 50 176 254) #vu8(57 234 234 115 10 114 241 155 49 109 174 122 231 121 4 0 12 142 100 172 91 184 161 231 94 234 234 46 61 195 175 206) #t ()) #(165 "short key" #vu8(115 239 158 241 164 34 94 81 227 193 219 58 206 31 162 79) #vu8(255 173 56 13 154 171 176 172 237 229 193 191 17 41 37 205 252 61 55 159 194 55 106 79 226 100 68 144 208 67 10 195) #vu8(76 133 246 114 88 37 98 38 220 221 230 38 177 0 218 239 52 222 219 140 56 179 75 249 243 185 219 90 254 135 174 155) #t ()))) (test-hmac "hmac_sha3_256_test" :algorithm "HMACSHA3-256" :key-size 128 :tag-size 128 :tests '(#(166 "short key" #vu8(227 79 21 199 189 129 153 48 254 157 102 224 193 102 230 28) #vu8() #vu8(135 32 38 205 48 237 132 130 175 117 8 192 197 44 140 182) #t ()) #(167 "short key" #vu8(224 158 170 90 63 94 86 210 121 213 231 160 51 115 246 234) #vu8(239 78 171 55 24 31 152 66 62 83 233 71 231 5 15 208) #vu8(103 0 207 215 253 177 198 103 234 212 119 251 148 47 240 59) #t ()) #(168 "short key" #vu8(155 211 144 46 208 153 108 134 155 87 34 114 231 111 56 137) #vu8(167 186 25 212 158 225 234 2 240 152 170 142 48 199 64 216 147 164 69 108 204 41 64 64 72 78 216 160 10 85 249 62) #vu8(84 99 43 15 252 187 55 99 183 12 109 214 220 56 237 58) #t ()))) (test-hmac "hmac_sha3_256_test" :algorithm "HMACSHA3-256" :key-size 520 :tag-size 256 :tests '(#(169 "long key" #vu8(138 12 70 235 138 41 89 227 152 101 51 0 121 118 51 65 231 67 157 171 20 150 148 238 87 224 214 30 199 61 148 126 29 83 1 205 151 78 24 165 224 209 207 13 44 55 232 170 221 159 213 137 213 126 243 46 71 2 74 153 188 63 112 192 119) #vu8() #vu8(122 30 160 88 115 247 84 249 153 48 98 36 52 116 211 135 79 79 255 168 35 206 22 168 4 178 44 177 1 165 177 0) #t ()) #(170 "long key" #vu8(40 119 235 184 31 128 51 79 208 5 22 51 116 70 197 207 90 212 163 162 225 151 38 158 91 10 209 136 157 254 43 75 10 170 103 111 172 85 179 108 227 175 252 127 16 146 171 137 197 50 115 168 55 189 91 201 77 26 157 158 91 2 233 133 111) #vu8(186 68 141 184 143 21 79 119 80 40 253 236 249 230 117 45) #vu8(23 131 25 113 184 84 178 33 5 121 9 139 1 154 230 47 59 245 106 255 189 14 205 59 172 119 160 43 215 139 79 73) #t ()) #(171 "long key" #vu8(33 23 142 38 188 40 255 194 124 6 247 98 186 25 10 98 112 117 133 109 124 166 254 171 121 172 99 20 155 23 18 110 52 253 158 85 144 224 233 10 172 128 29 240 149 5 216 175 45 208 162 112 59 53 44 87 58 201 210 203 6 57 39 242 175) #vu8(125 95 29 107 153 52 82 177 181 58 67 117 118 13 16 162 13 70 160 171 158 195 148 63 196 176 122 44 231 53 231 49) #vu8(161 79 136 100 227 199 26 61 161 253 38 135 1 84 124 238 18 192 177 221 196 247 72 15 37 59 124 175 195 208 78 106) #t ()))) (test-hmac "hmac_sha3_256_test" :algorithm "HMACSHA3-256" :key-size 520 :tag-size 128 :tests '(#(172 "long key" #vu8(129 62 12 7 140 34 19 117 232 5 144 172 230 119 78 175 210 210 194 66 53 9 136 208 46 250 85 14 5 174 203 225 0 193 184 191 21 76 147 44 249 229 113 119 1 92 129 108 66 188 127 188 113 206 170 83 40 199 49 107 127 15 48 51 15) #vu8() #vu8(104 31 132 68 43 217 2 35 189 85 119 167 188 232 185 62) #t ()) #(173 "long key" #vu8(87 19 52 48 150 176 170 240 86 42 107 146 193 161 85 53 146 65 96 71 90 78 66 51 88 145 89 114 140 86 46 59 42 217 111 116 12 106 77 162 188 63 118 140 233 140 155 214 107 172 40 209 100 111 245 146 2 140 148 13 69 95 53 238 180) #vu8(113 113 45 226 250 193 251 133 86 115 191 247 42 246 66 87) #vu8(46 105 105 229 127 123 51 233 106 49 234 25 79 62 24 140) #t ()) #(174 "long key" #vu8(114 8 175 190 207 95 31 52 130 143 152 183 25 65 78 40 7 22 222 100 245 237 209 174 28 119 65 83 205 32 34 51 123 178 15 173 225 183 133 111 29 191 212 14 43 67 7 241 41 60 239 241 105 46 233 13 140 144 181 253 249 83 171 1 165) #vu8(67 181 51 2 182 4 214 19 230 45 176 2 4 74 71 130 213 114 172 143 189 60 208 236 233 27 67 188 82 225 142 152) #vu8(198 113 47 44 27 13 243 158 202 151 172 71 43 37 126 205) #t ())))
false
c2b823c6b1c2e4c9b669bc6bb2654bd8312668e1
5927f3720f733d01d4b339b17945485bd3b08910
/tests/mta-test.scm
c50579f71aade99427613ba2749afbdfc4f3552d
[]
no_license
ashinn/hato
85e75c3b6c7ca7abca512dc9707da6db3b50a30d
17a7451743c46f29144ce7c43449eef070655073
refs/heads/master
2016-09-03T06:46:08.921164
2013-04-07T03:22:52
2013-04-07T03:22:52
32,322,276
5
0
null
null
null
null
UTF-8
Scheme
false
false
8,654
scm
mta-test.scm
#!/usr/local/bin/csi -script ;; So how do you unit test a mail server? ;; We need to specify at least: ;; ;; 1) config path ;; 2) base dir ;; 3) listen port ;; 4) virtual (non-OS) users ;; ;; * the config can specify 2 & 3 ;; * if running as non-root and the default port, 5025, is open we ;; don't need to specify 3 ;; ;; What this framework can't test: ;; ;; 1) sanity checks running as root (correct dirs are setup, etc.) ;; 2) delivery checks as root (correct file owners and permissions) ;; 3) tests on non-local connections (SPF, blacklists, etc.) ;; ;; 1 & 2 are effected by a relatively small amount of code which likely ;; won't change much. To verify these it should generally be enough to ;; run a few manual tests on a staging server after confirming the ;; automatic tests. ;; ;; 3 could conceivably be tested using an RPC framework, though I'm ;; making this a low priority for now. ;; ;; WARNING: DO NOT USE ANY REAL EMAIL ADDRESSES IN TESTS! ;; ;; The simplest way to do this is to use non-valid top-level domains ;; (e.g. foo.bar, evil.company, etc.). (use srfi-1 regex extras posix test hato-smtp hato-mime hato-archive) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; first things first - never run this test suite as root! (if (zero? (current-user-id)) (error "won't run the tests as root")) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (define test-port 5025) (define (send-test-mail file) (let* ((headers (with-input-from-file file mime-headers->list)) (from (car (parse-mail-address (mime-ref headers "from")))) (to (map car (parse-mail-address-list (mime-ref headers "to")))) (res (call-with-input-file file (cut send-mail Port: test-port From: from To: to Source: <> No-Sendmail: #t))) (expect-fail? (string-search "fail" file))) (test-assert (sprintf "send-mail ~A~A ~A" file (if expect-fail? " [expect failure]" "") res) (if expect-fail? (pair? res) (null? res))))) (define (mime-equal? a b) (and (equal? (mime-ref (car a) "subject") (mime-ref (car b) "subject")) (equal? (cdr a) (cdr b)))) (define (mail-equal? a b) ;; (and (= (length a) (length b)) ;; (every mime-equal? a b)) (call-with-input-string a (lambda (a-in) (call-with-input-string b (lambda (b-in) (let* ((a-headers (mime-headers->list a-in)) (a-body (read-all a-in)) (b-headers (mime-headers->list b-in)) (b-body (read-all b-in))) (and (equal? (mime-ref a-headers "subject") (mime-ref b-headers "subject")) (equal? a-body b-body)))))))) (define (mail-archive-equal? a b) (let* ((msg-a (mail-archive->list a)) (msg-b (mail-archive->list b))) (test-assert (sprintf "~A = ~A" (substring a (+ 1 (or (substring-index "/" a) -1))) (substring b (+ 1 (or (substring-index "/" b) -1)))) (and (= (length msg-a) (length msg-b)) (every mail-equal? msg-a msg-b))))) (define (file-equal? a b) (call-with-input-file a (lambda (a-in) (call-with-input-file b (lambda (b-in) (let lp () (let ((a-line (read-line a-in)) (b-line (read-line b-in))) (cond ((eof-object? a-line) (eof-object? b-line)) ((eof-object? b-line) #f) (else (and (equal? a-line b-line) (lp))))))))))) (define (ls-a dir) (map (cut string-append dir "/" <>) (sort (directory dir #t) string<?))) (define (copy-directory-tree a b) (cond ((directory? a) (if (file-exists? b) (if (not (directory? b)) (error "can't create directory over existing file" a b)) (create-directory b)) (for-each (lambda (f) (copy-directory-tree (string-append a "/" f) (string-append b "/" f))) (directory a #t))) ((directory? b) (if (file-exists? a) (error "can't copy file over existing directory" a b))) (else (call-with-output-file b (lambda (out) (call-with-input-file a (lambda (in) (let lp () (let ((str (read-string 1024 in))) (cond ((not (or (eof-object? str) (equal? "" str))) (write-string str #f out) (lp)))))))))))) (define (mail-directories-compare a b) (cond ((and (eq? 'maildir (mail-archive-format a)) (eq? 'maildir (mail-archive-format b))) ;; in the event of maildirs the file names won't match so we just ;; test that they're equivalent mail directories (mail-archive-equal? a b)) (else (let lp ((a-files (remove (cut string-match ".*(~|\\.log)$" <>) (ls-a a))) (b-files (remove (cut string-match ".*(~|\\.log)$" <>) (ls-a b)))) ;;(fprintf (current-error-port) "lp a: ~S b: ~S\n" a-files b-files) (cond ((null? a-files) (if (not (null? b-files)) (test-assert (sprintf "extra files: ~S" b-files) #f))) ((null? b-files) (test-assert (sprintf "missing files: ~S" a-files) #f)) (else (let ((a1 (car a-files)) (b1 (car b-files))) (cond ((directory? a1) (and (test-assert (sprintf "(directory? ~S)" b1) (directory? b1)) (mail-directories-compare a1 b1))) ((directory? b1) (test-assert (sprintf "not directory?: ~S" a1) #f)) ((and (mail-archive-format a1) (mail-archive-format b1)) (mail-archive-equal? a1 b1)) (else (test-assert (sprintf "~A = ~A" (substring a1 (+ 1 (or (substring-index "/" a1) -1))) (substring b1 (+ 1 (or (substring-index "/" b1) -1)))) (file-equal? a1 b1)))) (lp (cdr a-files) (cdr b-files))))))))) (define (with-test-server-from-dir dir thunk) ;; clean out any previous test files (keep the log files around) (for-each (lambda (d) (if (directory? d) (for-each delete-file (ls-a d)))) (map (cut string-append dir <>) '("/root/var/queue" "/root/var/run" "/root/var/mail"))) ;; ... wipe out the homes completely (be careful with this!) (letrec ((rm-rf (lambda (f) (if (directory? f) (for-each rm-rf (map (lambda (x) (string-append f "/" x)) (directory f #t))) (delete-file f))))) (rm-rf (string-append dir "/root/home"))) ;; ... and re-populate the homes (copy-directory-tree (string-append dir "/init-home") (string-append dir "/root/home")) ;; start the server (test-assert (sprintf "starting server in ~A" dir) (zero? (system (sprintf "cd .. && ./hato-mta.scm -d --virtual --port ~A --base tests/~A/root/" test-port dir)))) ;; do whatever (thunk) ;; kill the server (test-assert (sprintf "stopping server in ~A" dir) (zero? (system (sprintf "cd .. && ./hato-mta.scm -d --base tests/~A/root/ --kill" dir))))) (define (test-send-mail-dir dir) ;;(fprintf (current-error-port) "testing ~A\n" dir) (if (not (and (directory? (string-append dir "/root")) (directory? (string-append dir "/send-queue")) (directory? (string-append dir "/verify-mail")))) (fprintf (current-error-port) "WARNING: skipping mis-configured test directory ~A\n" dir) (with-test-server-from-dir dir (lambda () ;; send the mails (for-each send-test-mail (filter (cut string-match "^.*test-.*[^~]$" <>) (ls-a (string-append dir "/send-queue")))) ;; give a little time for them to be delivered (sleep 1) ;; verify mails, modulo delivery dates and server name, etc. (mail-directories-compare (string-append dir "/verify-mail") (string-append dir "/root/var/mail")) (mail-directories-compare (string-append dir "/verify-home") (string-append dir "/root/home")) )))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (test-begin "hato") (for-each test-send-mail-dir (filter directory? (ls-a "roots"))) (test-end "hato")
false
705cbcf2a8c86bb37f6e8428fbe8a87075b14df5
958488bc7f3c2044206e0358e56d7690b6ae696c
/scheme/evaluator/file-to-code.scm
091a706a870737de33e203caa1058976416a1313
[]
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
1,364
scm
file-to-code.scm
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; include guard ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (if (not (defined? included-file-to-code)) (begin (define included-file-to-code #f) ; include guard (display "loading file-to-code")(newline) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (define (file->code file) (cons 'begin (reverse (let loop ((acc '())) (let ((input (read file))) (if (not (eof-object? input)) (loop (cons input acc)) acc)))))) (define (filename->code filename) (let ((file (open-file filename "r"))) (let ((code (file->code file))) ; ; Normally, this code runs in native scheme which carries out a ; strict evaluation. However, it may be that we want to run this ; code in our own interpreter which may happen to be lazy. In other ; words, this code could end up being the argument of lazy-eval... ; ; When this happens, the variable 'code' is an unevaluated thunk ; and it is important that we force it in order to ensure the IO ; operation on the port is carried out before we close the port. (force-thunk code) ; has no effect if code is not a thunk (close-port file) ; IO needs to occur before this point code))) )) ; include guard
false
bd9876e85c890678ef1571b846f2014d745bea6f
7666204be35fcbc664e29fd0742a18841a7b601d
/code/3-25.scm
8f02494e6929456e48a958bddc1ec128237916e4
[]
no_license
cosail/sicp
b8a78932e40bd1a54415e50312e911d558f893eb
3ff79fd94eda81c315a1cee0165cec3c4dbcc43c
refs/heads/master
2021-01-18T04:47:30.692237
2014-01-06T13:32:54
2014-01-06T13:32:54
null
0
0
null
null
null
null
UTF-8
Scheme
false
false
2,441
scm
3-25.scm
(define (make-table) (list '*table*)) (define (assoc key records) (cond ((null? records) #f) ((equal? key (caar records)) (car records)) (else (assoc key (cdr records))))) (define (lookup key table) (let ((record (assoc key (cdr table)))) (if record (cdr record) #f))) (define (insert! key value table) (let ((record (assoc key (cdr table)))) (if record (begin (set-cdr! record value) record) (begin (set-cdr! table (cons (cons key value) (cdr table))) (cadr table))))) #| (define t (make-table)) (display (insert! 'a 1 t)) (newline) (display (insert! 'b 1 t)) (newline) (display (insert! 'a 1 t)) (newline) (display t) (newline) (display (lookup 'a t)) (newline) |# (define (lookup-rec keys table) (let* ((key (car keys)) (remain (cdr keys)) (record (assoc key (cdr table)))) (cond ((not record) #f) ((null? remain) (cdr record)) ((list? record) (lookup-rec remain record)) (else #f)))) (define (insert-rec! keys value table) (let* ((key (car keys)) (remain (cdr keys)) (record (lookup key table))) (if record (if (null? remain) (set-cdr! record value) (insert-rec! remain value record)) (if (null? remain) (set-cdr! table (cons (cons key value) (cdr table))) (begin (set-cdr! table (cons (list key) (cdr table))) (insert-rec! remain value (cadr table))))))) (define (D x) (display x) (newline)) ;; tests (define t (make-table)) (D t) (insert-rec! '(a) 1 t) (insert-rec! '(b a) 2 t) (insert-rec! '(b b) 3 t) (insert-rec! '(c a) 4 t) (insert-rec! '(c b a) 5 t) (insert-rec! '(c b b) 6 t) (D t) (D (lookup-rec '(a) t)) (D (lookup-rec '(a b) t)) (D (lookup-rec '(b) t)) (D (lookup-rec '(b a) t)) (D (lookup-rec '(b b) t)) (D (lookup-rec '(b c) t)) (D (lookup-rec '(c) t)) (D (lookup-rec '(c a) t)) (D (lookup-rec '(c b) t)) (D (lookup-rec '(c b a) t)) (D (lookup-rec '(c b b) t)) (D (lookup-rec '(c b c) t))
false
5bc887ff05533a73ab37eddda35acfdca6f67015
ebc5db754946092d65c73d0b55649c50d0536bd9
/2017/day12.scm
a9ed367815c159ed5b721eedc55f1fa5bb8420a7
[]
no_license
shawnw/adventofcode
6456affda0d7423442d0365a2ddfb7b704c0aa91
f0ecba80168289305d438c56f3632d8ca89c54a9
refs/heads/master
2022-12-07T22:54:04.957724
2022-12-02T07:26:06
2022-12-02T07:26:06
225,129,064
0
0
null
null
null
null
UTF-8
Scheme
false
false
2,313
scm
day12.scm
(import (srfi 1) (srfi 126) (kawa regex)) (define-record-type vertex (make-vertex name edges) vertex? (name get-name) (edges get-edges set-edges!)) (define line-re (regex "^(\\d+)\\s+<->\\s+([0-9, ]+)\\s*$")) (define (parse-line line) (let ((bits (regex-match line-re line))) (if bits (cons (string->number (second bits)) (map string->number (string-split (third bits) ", "))) (error "Failed to match line" line)))) (define (add-edge! graph from to) (let ((set-one-edge! (lambda (graph from to) (let ((v (hashtable-ref graph from #f))) (if v (set-edges! v (cons to (get-edges v))) (hashtable-set! graph from (make-vertex from (list to)))))))) (set-one-edge! graph from to) (set-one-edge! graph to from))) (define (read-graph) (let ((graph (make-hashtable (lambda (x) x) =)) (line (read-line))) (let loop ((line line)) (if (eof-object? line) graph (let* ((components (parse-line line)) (origin (car components))) (for-each (lambda (edge) (add-edge! graph origin edge)) (cdr components)) (loop (read-line))))))) (define (extract-cycle graph root #!optional (connected (make-hashtable (lambda (x) x) =))) (let ((rootv (hashtable-ref graph root #f))) (when rootv (hashtable-set! connected (get-name rootv) #t) (for-each (lambda (dest) (let ((dest-node (hashtable-ref graph dest #f))) (unless (hashtable-contains? connected dest) (extract-cycle graph dest connected)))) (get-edges rootv))) connected)) (define (remove-cycle! graph root) (let ((cycle (extract-cycle graph root))) (hashtable-prune! graph (lambda (k v) (hashtable-contains? cycle k))))) (define (count-cycles graph) (let ((graph (hashtable-copy graph #t))) (do ((count 0 (+ count 1))) ((hashtable-empty? graph) count) (let-values (((root v found?) (hashtable-find graph (lambda (k v) #t)))) (remove-cycle! graph root))))) (define graph (read-graph)) (define cycle0 (extract-cycle graph 0)) (format #t "Part 1: ~A~%" (hashtable-size cycle0)) (format #t "Part 2: ~A~%" (count-cycles graph))
false
84d81e4ed87556a9ffab9a00f2d1dee0ff3c410a
358b0f0efbdb9f081245b536c673648abbb6dc41
/entropy-linux.scm
53d8d4839fb71222824a0438b58859e6af7a1226
[ "MIT" ]
permissive
diamond-lizard/srfi-27
edb34a5ab850bfdf342acab61f1b49b87875116a
d54fcd1916ddef175df1d3dda107b149737ce1ca
refs/heads/main
2023-01-13T00:50:41.260636
2020-11-16T17:18:46
2020-11-16T17:18:46
312,747,512
1
0
null
null
null
null
UTF-8
Scheme
false
false
1,299
scm
entropy-linux.scm
;;;; entropy-linux.scm ;;;; Kon Lovett, Oct '17 (module entropy-linux (;export make-entropy-source-getrandom) (import scheme) (import (chicken base)) (import (chicken foreign)) (import entropy-source entropy-procedure) ;;; Entropy from getrandom #> #include <sys/random.h> <# ;FIXME needs GRND_NONBLOCK loop on EAGAIN/EINTR w/ (random ?) wait & max-trys ;FIXME ? handle ENOSYS/EINVAL/EFAULT ? (define getrandom_double (foreign-lambda* double ((u8vector u8vec)) ;Chicken SRFI 4 heap allocated vectors have 8-byte alignment! "double *buf = (double *) u8vec; ssize_t res = getrandom( buf, sizeof buf, 0 ); if (res == sizeof buf) { C_return( (isnormal( *buf ) ? fabs( *buf ) : -1.0) ); } C_return( -1.0 );")) (define getrandom_u8int (foreign-lambda* int () "uint8_t buf; ssize_t res = getrandom( buf, sizeof buf, 0 ); if (res == sizeof buf) { C_return( buf ); } /* WRONG */ C_return( buf );")) (define getrandom_u8proc ) (define getrandom_f64proc ) (define (make-entropy-source-getrandom) (make-entropy-source/procedures getrandom_u8proc getrandom_f64proc "getrandom" 'getrandom "Entropy from getrandom") ) (register-entropy-source! 'getrandom make-entropy-source-getrandom) ) ;module entropy-linux
false
9eafb6c9bd908e21dbdf030ed2b87b2ab978df95
f0747cba9d52d5e82772fd5a1caefbc074237e77
/plat/container-rootfs.scm
0d9845e99c237d1aa6a7eefaa85c50da01c12403
[]
no_license
philhofer/distill
a3b024de260dca13d90e23ecbab4a8781fa47340
152cb447cf9eef3cabe18ccf7645eb597414f484
refs/heads/master
2023-08-27T21:44:28.214377
2023-04-20T03:20:55
2023-04-20T03:20:55
267,761,972
3
0
null
2021-10-13T19:06:55
2020-05-29T04:06:55
Scheme
UTF-8
Scheme
false
false
279
scm
container-rootfs.scm
(import scheme (distill base) (distill image) (distill system)) (define container-rootfs (make-platform config: (default-config 'x86_64) ;; FIXME: multi-arch kernel: #f cmdline: '() packages: '() mkimage: (container-rootfs-image "container-x86_64")))
false
c585efcd2cc383b41769faae0968625ee4a58ae3
958488bc7f3c2044206e0358e56d7690b6ae696c
/scheme/avl/avl.scm
bdda35caf4c2ccbb6dffc893237d8546a08e8787
[]
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
19,409
scm
avl.scm
(load "avl-node.scm") (define (avl proc) ; 'proc' strict total order between keys ;; ;; private data (let ((less? proc) ; procedure allowing comparision < between keys (top '())) ; top node of avl ;; ;; public interface (define (dispatch m) (cond ((eq? m 'insert!) insert!); overwrites value on duplicate key ((eq? m 'delete!) delete!); deletes key from tree if it exists ((eq? m 'min) (find-min)) ; returns pair (key value) ((eq? m 'max) (find-max)) ; returns pair (key value) ((eq? m 'find) search) ; returns pair (key value) or #f if no key ((eq? m 'succ) succ) ; returns pair (key value) or #f if no succ ((eq? m 'pred) pred) ; returns pair (key value) or #f if no pred ((eq? m 'check) (check)) ; returns #t if all checks are successful ((eq? m 'print) (print)) ; primitive display of keys (else (display "avl: unknown operation error\n")))) ;; ;; private members ;; ;; insert (key value) into tree by inserting (key value) ;; into top node and adjusting top node to point to the ;; modified tree. Insert on duplicate keys will overwrite ;; value ;; (define (insert! key value) (set! top (insert-node! top key value))) ;; (define (delete! key) (set! top (delete-node! top key))) ;; ;; returns pair (key value) where key is the min key ;; (define (find-min) (let ((node (find-min-node top))) (cons (node 'key) (node 'value)))) ;; ;; returns pair (key value) where key is the max key ;; (define (find-max) (let ((node (find-max-node top))) (cons (node 'key) (node 'value)))) ;; ;; returns pair (key value) if 'key' successfully found ;; returns #f otherwise. Returning the pair (key value) ;; as opposed to simply 'value' removes the potential ;; ambiguity of a return value being #f. (define (search key) (let ((node (search-node top key))) (if (null? node) #f (cons (node 'key) (node 'value))))) ;; ;; returns pair (key value) corresponding to successor of 'key' ;; returns #f if no successor exists (define (succ key) (let ((node (succ-node top key))) (if (null? node) #f (cons (node 'key) (node 'value))))) ;; ;; returns pair (key value) corresponding to predecessor of 'key' ;; returns #f if no predecessor exists (define (pred key) (let ((node (pred-node top key))) (if (null? node) #f (cons (node 'key) (node 'value))))) ;; ;; checks tree is a properly formed binary search tree (define (check) (cond ((not (check-bst-node top)) #f) ((not (check-parent-node top)) #f) ((not (check-height-node top)) #f) ((not (check-avl-node top)) #f) ((and (not (null? top)) (not (null? (top 'parent)))) #f) (else #t))) ;; (define (print) (print-node top)) ;; (define (insert-node! node key value) (cond ((null? node) ; tree referred to by 'node' is empty (let ((new (avl-node key value))); creating new node ((new 'set-height!) 0) ; new node is a leaf new)) ; returning new node ((less? key (node 'key)) ; should insert from the left ((node 'set-left!) (insert-node! (node 'left) key value)) (((node 'left) 'set-parent!) node) (update-height-node! node); insertion requires height recalc (rebalance! node)) ; returning original node after rebalancing ((less? (node 'key) key) ; should insert from the right ((node 'set-right!) (insert-node! (node 'right) key value)) (((node 'right) 'set-parent!) node) (update-height-node! node); insertion requires height recalc (rebalance! node)) ;; both < and > have failed. Case of duplicate keys. (else ((node 'set-value!) value) node))) ;; (define (find-min-node node) ; returns node with min key from tree 'node' (cond ((null? node) '()) ((null? (node 'left)) node) (else (find-min-node (node 'left))))) ;; (define (find-max-node node) ; returns node with max key from tree 'node' (cond ((null? node) '()) ((null? (node 'right)) node) (else (find-max-node (node 'right))))) ;; ;; returns the node with 'key' from tree referred to by 'node' ;; returns '() if 'key' not present. (define (search-node node key) (cond ((null? node) '()) ((less? key (node 'key)) (search-node (node 'left) key)) ((less? (node 'key) key) (search-node (node 'right) key)) ;; both < and > have failed. key found. returning 'node' (else node))) ;; ;; returns the node whose key is the successor of 'key' within ;; the tree referred to by 'node'. The successor is the smallest ;; key which is greater than 'key'. Returns '() if no successor exists. (define (succ-node node key) (cond ((null? node) '()) ;; key if to the left ((less? key (node 'key)) ;; looking for successor key in left sub-tree (let ((n (succ-node (node 'left) key))) (if (null? n) ; there is no successor of key in left sub-tree node ; current node contains the successor key n))) ; successor key of left sub-tree is successor key ;; key is to the right ((less? (node 'key) key) (succ-node (node 'right) key)) ; successor must be in right sub-tree ;; key is that of 'node' (else (if (null? (node 'right)) ; no right sub-tree exists (let ((n (node 'parent))) ; successor possibly parent (cond ((null? n) '()) ; no successor if no parent ((less? key (n 'key)) n) ; parent key greater => it is succ ((less? (n 'key) key) '()); parent key smaller => no succ (else (display "avl: duplicate key error\n")))) ;; otherwise successor key is min of right sub-tree (find-min-node (node 'right)))))) ;; ;; returns the node whose key is the predecessor of 'key' within ;; the tree referred to by 'node'. The predecessor is the largest ;; key which is smaller than 'key'. Returns '() if no predecessor exists. (define (pred-node node key) (cond ((null? node) '()) ;; key if to the right ((less? (node 'key) key) ;; looking for predecessor key in right sub-tree (let ((n (pred-node (node 'right) key))) (if (null? n) ; there is no predecessor of key in right sub-tree node ; current node contains the predecessor key n))) ; predecessor key of right sub-tree is predecessor key ;; key is to the left ((less? key (node 'key)) (pred-node (node 'left) key)) ; predecessor must be in left sub-tree ;; key is that of 'node' (else (if (null? (node 'left)) ; no left sub-tree exists (let ((n (node 'parent))) ; predecessor possibly parent (cond ((null? n) '()) ; no predecessor if no parent ((less? (n 'key) key) n) ; parent key smaller => it is pred ((less? key (n 'key)) '()); parent key greater => no pred (else (display "avl: duplicate key error\n")))) ;; otherwise predecessor key is max of left sub-tree (find-max-node (node 'left)))))) ;; ;; The following procedure (with side effects) takes a 'node' argument ;; which is interpreted as a tree, and returns a new node, representing ;; a new tree where the maximal key has been placed at the top with no ;; right child. This operation is needed for deletion of keys. ;; This operation has no effect on empty trees. ;; (define (root-max-node! node) (cond ((null? node) node) ((null? (node 'right)) ((node 'set-parent!) '()) node) ; no right child, max node on the top (else ; max node is not at the top, some work is required (let ((n (root-max-node! (node 'right)))) ; recursive call ((node 'set-right!) (n 'left)) ; new right child without max (if (not (null? (node 'right))) ; if new right child exists ... (((node 'right) 'set-parent!) node)) ; ... then set up parent (update-height-node! node) ; new height after new child ((n 'set-left!) node) ; node getting to the left of max ((node 'set-parent!) n) ; not forgetting parent link (update-height-node! n) n)))) ; returning max node ;; ;; The following procedure (with side effects) takes a 'node' argument ;; which is interpreted as a tree, and returns a new node, representing ;; a new tree where the minimal key has been placed at the top with no ;; left child. This operation is needed for deletion of keys. ;; This operation has no effect on empty trees. ;; (define (root-min-node! node) (cond ((null? node) node) ((null? (node 'left)) ((node 'set-parent!) '()) node) ; no left child, min node on the top (else ; min node is not at the top, some work is required (let ((n (root-min-node! (node 'left)))) ; recursive call ((node 'set-left!) (n 'right)) ; new left child without min (if (not (null? (node 'left))) ; if new left child exists ... (((node 'left) 'set-parent!) node)) ; ... then set up parent (update-height-node! node) ; new height after new child ((n 'set-right!) node) ; node getting to the right of min ((node 'set-parent!) n) ; not forgetting parent link (update-height-node! n) n)))) ; returning min node ;; ;; Returns the top node of the tree obtained after deletion of the ;; node corresponding to the 'key' argument from the tree whose ;; top node is the 'node' argument. This should have no impact ;; unless 'key' is part of the original tree. ;; ;; The implementation is somewhat arbitrary in the sense that whenever ;; the key to be deleted is at the top of the tree, and both children ;; exist, it chooses to promote the successor rather than the predecessor ;; at the top of the new tree. ;; (define (delete-node! node key) (cond ((null? node) node) ; nothing to do on empty tree ((less? key (node 'key)) ; key to be deleted is on the left ;; new left child is that obtained after deletion of key (let ((new (delete-node! (node 'left) key))) ((node 'set-left!) new) (if (not (null? new)) ((new 'set-parent!) node)) (update-height-node! node) (rebalance! node))) ; return original node after rebalancing ((less? (node 'key) key) ; key to be deleted is on the right ;; new right child is that obtained after deletion of key (let ((new (delete-node! (node 'right) key))) ((node 'set-right!) new) (if (not (null? new)) ((new 'set-parent!) node)) (update-height-node! node) (rebalance! node))) ; return original node after rebalancing ;; at this stage key to be deleted is (node 'key) ((null? (node 'left)) ; left child does not exist (let ((new (node 'right))) ; candidate for tree after deletion (if (not (null? new)) ((new 'set-parent!) '())) new)) ((null? (node 'right)) ; left child does exist but right doesn't (let ((new (node 'left))) ((new 'set-parent!) '()) new)) ;; at this stage both left and right children exist, while top ;; key needs to be deleted. We arbitrarily choose to promote ;; successor at the top of new tree. (else ;; 'new' is right child after its minimum has been brought to the ;; top. (The minimum of the right child is the successor) ;; note that 'new' should have no left child since min is at the top. (let ((new (root-min-node! (node 'right)))) ((new 'set-left!) (node 'left)) ; gluing initial left child (((new 'left) 'set-parent!) new); not forgetting to set parent (update-height-node! new) (rebalance! new))))) ;; ;; this requires a non-empty right child, whose root is promoted to overall ;; root status, while preserving the avl tree structure. (define (left-rotate-node! node) (if (null? node) (begin (display "avl: left-rotate-node! on empty node\n") '()) (let ((right (node 'right))) ; right cannot be '() or next step will fail (if (null? right) (begin (display "avl: left-rotate-node! on empty child\n") '()) (let ((mid (right 'left))) ; mid is left child of right child ((node 'set-right!) mid) ; new right child for node (if (not (null? mid)) ((mid 'set-parent!) node)) (update-height-node! node) ; new height after new right child ((right 'set-left!) node) ; new left child for right ((node 'set-parent!) right) ((right 'set-parent!) '()); right is now root (update-height-node! right) right))))) ;; ;; this requires a non-empty left child, whose root is promoted to overall ;; root status, while preserving the avl tree structure. (define (right-rotate-node! node) (if (null? node) (begin (display "avl: right-rotate-node! on empty node\n") '()) (let ((left (node 'left))) ; left cannot be '() or next step will fail (if (null? left) (begin (display "avl: right-rotate-node! on empty child\n") '()) (let ((mid (left 'right))) ; mid is right child of left child ((node 'set-left!) mid) ; new left child for node (if (not (null? mid)) ((mid 'set-parent!) node)) (update-height-node! node) ; new height after new left child ((left 'set-right!) node) ; new right child for left ((node 'set-parent!) left) ((left 'set-parent!) '()) ; left is now root (update-height-node! left) left))))) ;; ;; (define (right-rebalance! node) (let ((right (node 'right))) (if (> (left-height right) (right-height right)) (let ((new (right-rotate-node! right))) ((node 'set-right!) new) ((new 'set-parent!) node) (update-height-node! node))) (left-rotate-node! node))) ;; ;; (define (left-rebalance! node) (let ((left (node 'left))) (if (> (right-height left) (left-height left)) (let ((new (left-rotate-node! left))) ((node 'set-left!) new) ((new 'set-parent!) node) (update-height-node! node))) (right-rotate-node! node))) ;; (define (rebalance! node) (cond ((balanced-node? node) node) ((< (left-height node) (right-height node)) (right-rebalance! node)) ((< (right-height node) (left-height node)) (left-rebalance! node)) (else (display "avl: unexpected error in rebalance!\n")))) ;; ;; checks that tree referred to by 'node' has the binary search tree ;; property. Returns #t if that is the case and #f otherwise. (define (check-bst-node node) (cond ((null? node) #t) ((not (check-bst-node (node 'left))) #f) ((not (check-bst-node (node 'right))) #f) ;; if left child exists, every key to the left has to be smaller ((and (not (null? (node 'left))) (less? (node 'key) ((find-max-node (node 'left)) 'key))) #f) ;; if right child exists, every key to the right has to be larger ((and (not (null? (node 'right))) (less? ((find-min-node (node 'right)) 'key) (node 'key))) #f) ;; every test was passed successfully (else #t))) ;; checks that every child has the appropriate parent pointer (define (check-parent-node node) (cond ((null? node) #t) ((not (check-parent-node (node 'left))) #f) ((not (check-parent-node (node 'right))) #f) ;; if left child exists, its parent pointer should refer to 'node' ((and (not (null? (node 'left))) (not (eq? node ((node 'left) 'parent)))) #f) ;; if right child exists, its parent pointer should refer to 'node' ((and (not (null? (node 'right))) (not (eq? node ((node 'right) 'parent)))) #f) ;; every test was passed successfully (else #t))) ;; ;; the procedure returns in constant time but return value possibly incorrect ;; if height values are not properly updated. (define (height-node node) (if (null? node) -1 (node 'height))) ;; ;; will fail on null node (define (left-height node) (if (null? node) (begin (display "avl: left-height on empty node\n") '()) (height-node (node 'left)))) ;; will fail on null node (define (right-height node) (if (null? node) (begin (display "avl: right-height on empty node\n") '()) (height-node (node 'right)))) ;; will fail on null node (define (balanced-node? node) (if (null? node) (begin (display "avl: balanced-node? on empty node\n") '()) (< (abs (- (left-height node) (right-height node))) 2))) ;; ;; update height of node, assuming heights of children have been duly updated (define (update-height-node! node) ((node 'set-height!) (+ 1 (max (left-height node) (right-height node))))) ;; ;; checks that node heights have the correct values (define (check-height-node node) (cond ((null? node) #t) ((not (check-height-node (node 'left))) #f) ((not (check-height-node (node 'right))) #f) (else (let ((lh (left-height node)) (rh (right-height node))) (if (= (node 'height) (+ 1 (max lh rh))) #t #f))))) ;; ;; checks the avl property is satisfied, namely that the for every node, ;; the difference in height between the left and right child is at most 1. ;; being understood that (by convention), an null child has height -1 ;; This procedure should be called after calling check-height-node in ;; order to ensure that pre-calculated node heights are correct. (define (check-avl-node node) (cond ((null? node) #t) ((not (check-avl-node (node 'left))) #f) ((not (check-avl-node (node 'right))) #f) (else (balanced-node? node)))) ;; ;; primitive printout used for debugging (define (print-node node) (if (null? node) (display ".") (begin (display "( ") (display (node 'key)) (display " ") (print-node (node 'left)) (display " ") (print-node (node 'right)) (display " )") ))) ;; ;; returning interface dispatch))
false
8aedd573596807070945b5af4d5bb4e9c71a53b2
fb9a1b8f80516373ac709e2328dd50621b18aa1a
/ch1/exercise1-5.scm
e636ccd0e514a968ac608c374f296c55d9078046
[]
no_license
da1/sicp
a7eacd10d25e5a1a034c57247755d531335ff8c7
0c408ace7af48ef3256330c8965a2b23ba948007
refs/heads/master
2021-01-20T11:57:47.202301
2014-02-16T08:57:55
2014-02-16T08:57:55
null
0
0
null
null
null
null
UTF-8
Scheme
false
false
777
scm
exercise1-5.scm
;; 問題1.5 ;; Ben Bitdiddle は,彼の対面している解釈系が,作用的順序の評価を使っているか, ;; 正規順序の評価を使っているか決定するテストを発明した. (define (p) (p)) (define (test x y) (if (= x 0) 0 y)) (test 0 (p)) ;;を評価した.作用的順序を使う解釈系でどういう振る舞いを見るか ;; 正規順序の評価を行う解釈系でどういう振る舞いをするか ;; http://d.hatena.ne.jp/knowledgetree/20100912/1284305197 ;; goshでは作用的順序を使う解釈系である. ;; testの引数である(p)を評価しようとして無限ループに陥る. ;; 正規順序の評価を行う解釈系では,(p)の評価前にtestの評価を行い,0を返す.
false
231c8af8cc26f2baa24e69b2ed280c34b7db214b
a2d8b4843847507b02085bb8adabd818f57dd09f
/scheme/little-schemer/chapter_04.scm
e412687ed5a704650aca963e0288f0263c0702ab
[]
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
2,935
scm
chapter_04.scm
; The Little Schemer ; Chapter 4 - number games ; ; We only consider positive numbers ; (define add1 (lambda (n) (+ n 1))) (define sub1 (lambda (n) (- n 1))) (define plus (lambda (n m) (cond ((zero? n) m) (else (add1 (plus m (sub1 n))))))) (define minus (lambda (n m) (cond ((zero? m) n) (else (sub1 (minus n (sub1 m))))))) (define addtup (lambda (tup) (cond ((null? tup) 0) (else (plus (car tup) (addtup (cdr tup))))))) (define times (lambda (n m) (cond ((zero? m) 0) (else (plus n (times n (sub1 m))))))) (define tup-plus (lambda (tup1 tup2) (cond ((null? tup1) tup2) ((null? tup2) tup1) (else (cons (plus (car tup1) (car tup2)) (tup-plus (cdr tup1) (cdr tup2))))))) (define > (lambda (n m) (cond ((zero? n) #f) ((zero? m) #t) (else (> (sub1 n) (sub1 m)))))) (define >= (lambda (n m) (cond ((zero? m) #t) ((zero? n) #f) (else (>= (sub1 n) (sub1 m)))))) (define < (lambda (n m) (cond ((zero? m) #f) ((zero? n) #t) (else (< (sub1 n) (sub1 m)))))) (define <= (lambda (n m) (cond ((zero? n) #t) ((zero? m) #f) (else (<= (sub1 n) (sub1 m)))))) (define equal (lambda (n m) (cond ((zero? m) (zero? n)) ((zero? n) #f) (else (= (sub1 n) (sub1 m)))))) (define equal (lambda (n m) (cond ((< n m) #f) ((> n m) #f) (else #t)))) (define exp (lambda (n m) (cond ((zero? m) 1) (else (times n (exp n (sub1 m))))))) (define quotent (lambda (n m) (cond ((< n m) 0) (else (add1 (quotent (minus n m) m)))))) (define length (lambda (lat) (cond ((null? lat) 0) (else (add1 (length (cdr lat))))))) (define pick (lambda (n lat) (cond ((zero? (sub1 n)) (car lat)) (else (pick (sub1 n) (cdr lat)))))) (define rempick (lambda (n lat) (cond ((zero? (sub1 n)) (cdr lat)) (else (cons (car lat) (rempick (sub1 n) (cdr lat))))))) (define no-nums (lambda (lat) (cond ((null? lat) '()) ((number? (car lat)) (no-nums (cdr lat))) (else (cons (car lat) (no-nums (cdr lat))))))) (define all-nums (lambda (lat) (cond ((null? lat) '()) ((number? (car lat)) (cons (car lat) (all-nums (cdr lat)))) (else (all-nums (cdr lat)))))) (define eqan? (lambda (a b) (cond ((and (number? a) (number? b)) (= a b)) ((or (number? a) (number? b)) #f) (else (eq? a b))))) (define occur (lambda (a lat) (cond ((null? lat) 0) ((eqan? (car lat) a) (add1 (occur a (cdr lat)))) (else (occur a (cdr lat)))))) (define one? (lambda (n) (eqan? n 1))) (define rempick (lambda (n lat) (cond ((one? n) (cdr lat)) (else (cons (car lat) (rempick (sub1 n) (cdr lat)))))))
false
ad928eefad35cbf51d75501ecfb57c6e0a3fd39e
defeada37d39bca09ef76f66f38683754c0a6aa0
/mscorlib/system/runtime/remoting/formatter-data.sls
f18eeee402e8c0055367a6eb11cbaa94cde7694e
[]
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
420
sls
formatter-data.sls
(library (system runtime remoting formatter-data) (export new is? formatter-data?) (import (ironscheme-clr-port)) (define-syntax new (lambda (e) (syntax-case e () ((_ a ...) #'(clr-new System.Runtime.Remoting.FormatterData a ...))))) (define (is? a) (clr-is System.Runtime.Remoting.FormatterData a)) (define (formatter-data? a) (clr-is System.Runtime.Remoting.FormatterData a)))
true
ce480cc8f74eb0114111975990945aa1e8525479
260905e8164cf5c08116423147d5c56c4174573b
/utils.rkt
248ef5596f93e7f336ad544c35bf9fafefbdaf2f
[]
no_license
adlai/fci2017
f6ee7c1e3f3ec53107470f8c9a18721808dbdca8
eaac02963151ff83d5cb4176cf1ea5ef18c3fb94
refs/heads/master
2021-01-13T16:40:46.291550
2017-01-05T21:31:14
2017-01-05T21:48:16
78,150,025
0
0
null
2017-01-05T21:32:17
2017-01-05T21:32:17
null
UTF-8
Scheme
false
false
2,602
rkt
utils.rkt
#lang at-exp racket ;;-*- Scheme -*- (require scribble/base scribble/bnf scribble/core scribble/decode scribble/manual scriblib/autobib scriblib/footnote (for-syntax syntax/parse)) (provide (all-defined-out)) (define (note-url url) (note (hyperlink url url))) (define extended-url "http://fare.tunes.org/files/asdf3/asdf3-2014.html") (define variant (make-parameter '#:extended)) (define (extended?) (eq? (variant) '#:extended)) (define-syntax-rule (extended-only x ...) (when (extended?) (list x ...))) (define-syntax-rule (short-only x ...) (unless (extended?) (list x ...))) (define (appref tag alt) (if (extended?) (secref tag) (hyperlink (string-append extended-url "#" tag) alt))) (define backend (make-parameter '#:html)) (define-syntax-rule (html-only x ...) (and (eq? (backend) '#:html) (list x ...))) (define-syntax-rule (pdf-only x ...) (and (eq? (backend) '#:pdf) (list x ...))) (define multiple-sections (make-parameter #f)) (define include-asdf1-diffs (make-parameter #t)) (define include-asdf2-diffs (make-parameter #t)) (define (moneyquote . x) (bold x)) (define (q . x) (list "``" x "''")) (define-syntax (clblock stx) (syntax-parse stx [(_ #:line-numbers ln str ...) #'@codeblock[;;#:keep-lang-line? #f #:line-numbers ln #:line-number-sep 3 str ...]] [(_ str ...) #'(clblock #:line-numbers 0 str ...)])) (define-syntax (clcode stx) (syntax-parse stx [(_ str ...) #'(clblock #:line-numbers #f str ...)])) (define (XXX . rest) '()) (define (latin x) (emph x)) (define (ad_hoc) @latin{ad hoc}) (define (de_facto) @latin{de facto}) (define (bydef . x) (emph x)) (define (FRR) "François-René Rideau") (define (L . x) (apply tt x)) (define-syntax defpretty (lambda (stx) (syntax-case stx () [(_ pretty name ...) (with-syntax ([(string ...) (map symbol->string (syntax->datum #'(name ...)))]) #'(begin (define (name) (pretty string)) ...))]))) (defpretty emph depends-on in-order-to do-first force) (defpretty tt Make make blaze) (define-cite ~cite cite-noun generate-bib) ;; #:style number-style) (define-syntax-rule (define-bib name stuff ...) (define name (make-bib stuff ...))) (define (Phi) "Φ") (define (phi) "φ") (define (Psi) "Ψ") (define (psi) "ψ") (define (raw-latex . args) (element (style "relax" '(exact-chars)) args)) @(define (spacing) @raw-latex{~~~~~~}) @(define (separate-list sep l) (if (or (null? l) (null? (cdr l))) l (cons (car l) (cons sep (separate-list sep (cdr l))))))
true
634836e945c3764d61775ed904e18435296356f6
b7ec5209446e33ec4b524c66c4d52ff852e46ae4
/slideshow/exemples/xft.scm
a0016713c937f12abc07ace03c1c03b89795c78e
[]
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
8,311
scm
xft.scm
;***************************************************** ; PROJET PHYSICS ; ANNEE 2008 ; PROGRAMMEURS : F. CORLAIS & A. JACQUEMIN ; MAJ : 27.04.2008 ;***************************************************** ;***************************************************** ; "xft.scm" ; ce fichier est un des modules du slideshow ; il ne fait appel à aucun autre fichier pour ; être totalement indépendant et utilisé ; indépendemment du projet ; (difusion internet notamment) ; Ce fichier permet de sensibiliser l'utilisateur ;aux graphiques de la forme x=f(t) ;http://projetphysics.teria.org/Slideshow/Physique_du_point.html ;***************************************************** ;***************************************************** ; FILE ; type abstrait de file ;***************************************************** (define (file-vide) (cons '() '())) (define (file-vide? F) (and (pair? F) (null? (car F)) (null? (cdr F)))) (define (enfiler! x F) (let ((new (list x))) (cond ((file-vide? F) (set-car! F new) (set-cdr! F new)) (else (set-cdr! (cdr F) new) (set-cdr! F new))))) (define (defiler! F) (when (not (file-vide? F)) (if (eq? (car F) (cdr F)) (begin (set-car! F '()) (set-cdr! F '())) (set-car! F (cdar F))))) (define (premier F) (if (file-vide? F) (error "La file est vide ! " F) (caar F))) ;***************************************************** ; MODULE ;***************************************************** (define X 100) (define COURBE (file-vide)) (enfiler! X COURBE) (define SIZE 1) (define V 1) (define ACTION #f) ;fenêtre principale du module (define FRAME (new frame% (label "x=f(t)") (style '(metal hide-menu-bar)) (stretchable-height #f) (stretchable-width #f))) ;panel des canvas (define VPANEL (new vertical-panel% (parent FRAME))) ;panel des boutons de gestion du mobile (define HPANEL (new horizontal-panel% (parent FRAME) (alignment '(center center)))) ;panel des boutons de gestion du module (define HPANEL2 (new horizontal-panel% (parent FRAME) (alignment '(center center)))) ;canvas de la courbe (define CANVAS1 (new canvas% (parent VPANEL) (min-height 500) (min-width 500) (style '(no-autoclear)) (paint-callback (lambda (evt dc) (separation BITMAP-DC1) (repere BITMAP-DC1) (draw-courbe BITMAP-DC1) (send dc draw-bitmap BITMAP1 0 0 'solid))))) (define BITMAP1 (make-object bitmap% 500 500)) (define BITMAP-DC1 (new bitmap-dc% (bitmap BITMAP1))) ;canvas de l'axe (define CANVAS2 (new canvas% (parent VPANEL) (min-height 100) (min-width 500) (style '(no-autoclear)) (paint-callback (lambda (evt dc) (axe BITMAP-DC2) (curseur BITMAP-DC2) (send dc draw-bitmap BITMAP2 0 0 'solid))))) (define BITMAP2 (make-object bitmap% 500 500)) (define BITMAP-DC2 (new bitmap-dc% (bitmap BITMAP2))) ;bouton ralentissant la vitesse du mobile (define LENT (new button% (parent HPANEL) (label "-") (callback (lambda (a b) (set! V (- V 0.2)))))) ;bouton stoppant l'animation (define STOP (new button% (parent HPANEL) (label "Go") (callback (lambda (a b) (if ACTION (begin (send STOP set-label "Go") (set! ACTION #f) (action)) (begin (send STOP set-label "Stop") (set! ACTION #t) (action))))))) ;bouton augmentant la vitesse du mobile (define RAPIDE (new button% (parent HPANEL) (label "+") (callback (lambda (a b) (set! V (+ V 0.2)))))) ;pour relancer l'animation (define RESTART (new button% (parent HPANEL2) (label "Restart") (callback (lambda (a b) (set! V 1) (set! X 100) (set! COURBE (file-vide)) (enfiler! X COURBE) (set! SIZE 1) (set! ACTION #f) (send CANVAS1 on-paint) (send CANVAS2 on-paint) (send STOP set-label "Go"))))) ;pour fermer la fenêtre en stoppant l'action (define CLOSE (new button% (parent HPANEL2) (label "Fermer la fenêtre") (callback (lambda (a b) (set! ACTION #f) (send FRAME show #f))))) ;ligne de séparation (define (separation dc) (send dc set-pen "black" 2 'solid) (send dc draw-line 0 500 500 500)) ;création du repère dans le canvas 1 (define (repere dc) (define (curseur y) (send dc set-pen "black" 1 'solid) (send dc draw-line 27 y 33 y)) (send dc clear) (separation dc) (send dc set-pen "black" 1 'solid) (send dc draw-line 30 50 30 450) (send dc draw-line 30 50 35 60) (send dc draw-line 30 50 25 60) (send dc draw-line 30 450 470 450) (send dc draw-line 470 450 460 455) (send dc draw-line 470 450 460 445) (send dc draw-text "O" 15 460) (send dc draw-text "x" 10 40) (send dc draw-text "t" 450 460) (send dc draw-text "xA" 5 370) (curseur 400) (send dc draw-text "xB" 5 70) (curseur 100)) ;création de l'axe dans le canvas 2 (define (axe dc) (define (curseur x) (send dc set-pen "black" 1 'solid) (send dc draw-line x 52 x 48)) (send dc clear) (send dc set-pen "black" 1 'solid) (send dc draw-line 30 50 470 50) (send dc draw-line 470 50 460 55) (send dc draw-line 470 50 460 45) (send dc draw-text "O" 20 55) (curseur 30) (send dc draw-text "x" 460 55) (send dc draw-text "A" 100 55) (curseur 100) (send dc draw-text "B" 400 55) (curseur 400)) ;curseur de la masse courante sur l'axe (define (curseur dc) (axe dc) (send dc set-pen "red" 4 'solid) (send dc draw-point (- X 2) 48)) ;la courbe est une file contenant les couples (x.y) des coordonnées des points ;la constituant (define (draw-courbe dc) (repere dc) (send dc set-pen "red" 1 'solid) (do ((C (car COURBE) (cdr C)) (t 30 (+ t 1)) (L (length (car COURBE)) (- L 1))) ((<= L 1)) (send dc draw-line t (- 500 (car C)) (+ t 1) (- 500 (cadr C))))) ;pour faire évoluer le mobile (define (action) (when ;si le monde est en mouvement ACTION (let ((DC1 BITMAP-DC1) (DC2 BITMAP-DC2)) (when (= SIZE 400) ;si la taille de la courbe excède 400 points, ;on défile avant d'enfiler le nouveau point (defiler! COURBE) (set! SIZE (- SIZE 1))) (cond (;on gère le cas de la collision avec B : fin de l'action (> X 400) (set! ACTION #f)) (;puis le cas de la collision avec A : rebond elastique (< X 100) (set! V (- V)) (set! X 100)) (;sinon, le point est entre A et B, et évolue normalement else (enfiler! X COURBE) (set! X (+ X V)))) (set! SIZE (add1 SIZE)) (draw-courbe DC1) (curseur DC2) (send (send CANVAS1 get-dc) draw-bitmap BITMAP1 0 0 'solid) (send (send CANVAS2 get-dc) draw-bitmap BITMAP2 0 0 'solid) (sleep/yield 0.01) (action)))) (send FRAME show #t) (action)
false
4efec8f1366fa8b3faf08cd094f672261298f6bd
0fb87930229b3bec24d7d6ad3dae79c715fd4c58
/src/scheme/tutorial/src/io.scm
ad82100cb3d6b81ac3c8fdc0f7d998b84335023f
[ "BSD-2-Clause" ]
permissive
klose911/klose911.github.io
76beb22570b8e483532e8f2521b2b6334b4f856e
7d2407ff201af38d6c6178f93793b7d6cf59fbd8
refs/heads/main
2023-09-01T18:04:45.858325
2023-08-29T09:35:25
2023-08-29T09:35:25
73,625,857
3
2
Apache-2.0
2020-09-17T08:27:56
2016-11-13T15:52:32
HTML
UTF-8
Scheme
false
false
1,665
scm
io.scm
;;;;;;;;;;;;;;;;;;;;;;; ;; Input from a file ;; ;;;;;;;;;;;;;;;;;;;;;;; (define (read-file file-name) (let ((p (open-input-file file-name))) (let loop((ls1 '()) (c (read-char p))) (if (eof-object? c) (begin (close-input-port p) (list->string (reverse ls1))) (loop (cons c ls1) (read-char p)))))) (read-file "hello.txt") ;; "Hello world!\r\nScheme is an elegant programming language.\r\n" (display (read-file "hello.txt")) ;; Hello world! ;; Scheme is an elegant programming language. ;;; call-with-input-file (define (read-file file-name) (call-with-input-file file-name (lambda (p) (let loop((ls1 '()) (c (read-char p))) (if (eof-object? c) (begin (close-input-port p) (list->string (reverse ls1))) (loop (cons c ls1) (read-char p))))))) (display (read-file "hello.txt")) ;; Hello world! ;; Scheme is an elegant programming language. ;;; with-input-file (define (read-file file-name) (with-input-from-file file-name (lambda () (let loop((ls1 '()) (c (read-char))) (if (eof-object? c) (list->string (reverse ls1)) (loop (cons c ls1) (read-char))))))) (display (read-file "hello.txt")) ;; Hello world! ;; Scheme is an elegant programming language. ;;;;;;;;;;;;;;;;;;;;;;;; ;; Read S expressions ;; ;;;;;;;;;;;;;;;;;;;;;;;; (define (s-read file-name) (with-input-from-file file-name (lambda () (let loop ((ls1 '()) (s (read))) (if (eof-object? s) (reverse ls1) (loop (cons s ls1) (read))))))) (s-read "paren.txt") ; => ('(Hello world! Scheme is an elegant programming language.) ;; '(Lisp is a programming language ready to evolve.))
false
1590d06d5ded67c76f2e8b24d1d72f57ea63bf32
320a615ef54449a39e2ca9e59847106e30cc8d7a
/test/mobley.scm
0a9436e8a08e3208c3520c27b8cb35c9d8b79a70
[]
no_license
alexei-matveev/bgy3d
5cf08ea24a5c0f7b0d6e1d572effdeef8232f173
0facadd04c6143679033202d18017ae2a533b453
refs/heads/master
2021-01-01T17:47:22.766959
2015-07-10T09:21:49
2015-07-10T09:21:49
38,872,299
2
1
null
null
null
null
UTF-8
Scheme
false
false
2,263
scm
mobley.scm
;;; ;;; Copyright (c) 2014 Alexei Matveev ;;; ;;; FIXME: The default solver does not converge, see snes-solver in ;;; settings. ;;; ;;; ../bgy3d -L ../ -s ./run-ions.scm ;;; (use-modules (srfi srfi-1) (guile bgy3d) ; rism-solute, hnc3d-run-solute (guile molecule) ; find-molecule (guile utils) ; numbers->strings (guile amber) ; from mobley09 (ice-9 pretty-print)) (when #f (let* ((results (with-input-from-file "species" read)) (entries (map car results)) (results (map cdr results)) (energies (map (lambda (d) (assoc-ref d 'free-energy)) results)) (kb-integrals (map (lambda (d) (assoc-ref d 'excess-coordination)) results))) (for-each (lambda (name energy kb) (format #t "~S,~A,~A\n" name energy kb)) entries energies kb-integrals)) (exit 0)) (define *settings* '((L . 10.0) (N . 96) (rho . 0.0333295) (beta . 1.6889) (dielectric . 78.4) (closure . KH) (norm-tol . 1.0e-14) (max-iter . 1500) (damp-start . 1.0) (lambda . 0.02) (bond-length-thresh . 2.0) (derivatives . #f) (snes-solver . "newton"))) (define *solvent* (find-molecule "water, PR-SPC/E")) ;;; Solvent susceptibility: (define *chi* (let ((alist (rism-solvent *solvent* *settings*))) (with-output-to-file "solvent" (lambda () (pretty-print alist))) (assoc-ref alist 'susceptibility))) ;;; ;;; Call sequence for 1D RISM: ;;; (define (run-1d entry) (let* ((alist (rism-solute (make-solute entry) *solvent* *settings* *chi*))) (cons entry alist))) ;;; ;;; Call sequence for 3D RISM. 3D cannot handle large ;;; dimensions. Check the settings! ;;; (define (run-3d entry) (let ((alist (hnc3d-run-solute (make-solute entry) *solvent* *settings*))) (destroy alist) (cons entry (list (assoc 'free-energy alist))))) (let ((results (map run-3d entries))) (with-output-to-file "species" (lambda () (pretty-print results))))
false
62f3767ee598c43804f97cfa4e49fc423004849f
a7557f4e8413259be724646f4b542a550e5baf5e
/usr/share/guile/3.0/ice-9/suspendable-ports.scm
a823f1d37cc8fba3a9277027be8b5c56523bfa93
[]
no_license
git-for-windows/git-sdk-64
cb5558b693ac508417f7503be9e7a149daf973fa
25f0f24eaff909ace7960515a055da2c2fb2aeac
refs/heads/main
2023-08-31T05:40:42.358892
2023-08-30T11:37:51
2023-08-30T11:37:51
87,077,328
195
202
null
2023-08-25T06:33:10
2017-04-03T13:30:02
null
UTF-8
Scheme
false
false
30,576
scm
suspendable-ports.scm
;;; Ports, implemented in Scheme ;;; Copyright (C) 2016, 2019 Free Software Foundation, Inc. ;;; ;;; This library is free software: you can redistribute it and/or modify ;;; it under the terms of the GNU Lesser General Public License as ;;; published by the Free Software Foundation, either version 3 of the ;;; License, or (at your option) any later version. ;;; ;;; This library is distributed in the hope that it will be useful, but ;;; WITHOUT ANY WARRANTY; without even the implied warranty of ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ;;; Lesser General Public License for more details. ;;; ;;; You should have received a copy of the GNU Lesser General Public ;;; License along with this program. If not, see ;;; <http://www.gnu.org/licenses/>. ;;; Commentary: ;;; ;;; We would like to be able to implement green threads using delimited ;;; continuations. When a green thread would block on I/O, it should ;;; suspend and arrange to be resumed when it can make progress. ;;; ;;; The problem is that the ports code is written in C. A delimited ;;; continuation that captures a C activation can't be resumed, because ;;; Guile doesn't know about the internal structure of the C activation ;;; (stack frame) and so can't compose it with the current continuation. ;;; For that reason, to implement this desired future, we have to ;;; implement ports in Scheme. ;;; ;;; If Scheme were fast enough, we would just implement ports in Scheme ;;; early in Guile's boot, and that would be that. However currently ;;; that's not the case: character-by-character I/O is about three or ;;; four times slower in Scheme than in C. This is mostly bytecode ;;; overhead, though there are some ways that compiler improvements ;;; could help us too. ;;; ;;; Note that the difference between Scheme and C is much less for ;;; batched operations, like read-bytes or read-line. ;;; ;;; So the upshot is that we need to keep the C I/O routines around for ;;; performance reasons. We can still have our Scheme routines ;;; available as a module, though, for use by people working with green ;;; threads. That's this module. People that want green threads can ;;; even replace the core bindings, which enables green threading over ;;; other generic routines like the HTTP server. ;;; ;;; Code: (define-module (ice-9 suspendable-ports) #:use-module (rnrs bytevectors) #:use-module (ice-9 ports internal) #:use-module (ice-9 match) #:export (current-read-waiter current-write-waiter install-suspendable-ports! uninstall-suspendable-ports!)) (define (default-read-waiter port) (port-poll port "r")) (define (default-write-waiter port) (port-poll port "w")) (define current-read-waiter (make-parameter default-read-waiter)) (define current-write-waiter (make-parameter default-write-waiter)) (define (wait-for-readable port) ((current-read-waiter) port)) (define (wait-for-writable port) ((current-write-waiter) port)) (define (read-bytes port dst start count) (cond (((port-read port) port dst start count) => (lambda (read) (unless (<= 0 read count) (error "bad return from port read function" read)) read)) (else (wait-for-readable port) (read-bytes port dst start count)))) (define (write-bytes port src start count) (cond (((port-write port) port src start count) => (lambda (written) (unless (<= 0 written count) (error "bad return from port write function" written)) (when (< written count) (write-bytes port src (+ start written) (- count written))))) (else (wait-for-writable port) (write-bytes port src start count)))) (define (flush-input port) (let* ((buf (port-read-buffer port)) (cur (port-buffer-cur buf)) (end (port-buffer-end buf))) (when (< cur end) (set-port-buffer-cur! buf 0) (set-port-buffer-end! buf 0) (seek port (- cur end) SEEK_CUR)))) (define (flush-output port) (let* ((buf (port-write-buffer port)) (cur (port-buffer-cur buf)) (end (port-buffer-end buf))) (when (< cur end) ;; Update cursors before attempting to write, assuming that I/O ;; errors are sticky. That way if the write throws an error, ;; causing the computation to abort, and possibly causing the port ;; to be collected by GC when it's open, any subsequent close-port ;; or force-output won't signal *another* error. (set-port-buffer-cur! buf 0) (set-port-buffer-end! buf 0) (write-bytes port (port-buffer-bytevector buf) cur (- end cur))))) (define utf8-bom #vu8(#xEF #xBB #xBF)) (define utf16be-bom #vu8(#xFE #xFF)) (define utf16le-bom #vu8(#xFF #xFE)) (define utf32be-bom #vu8(#x00 #x00 #xFE #xFF)) (define utf32le-bom #vu8(#xFF #xFE #x00 #x00)) (define (clear-stream-start-for-bom-read port io-mode) (define (maybe-consume-bom bom) (and (eq? (peek-byte port) (bytevector-u8-ref bom 0)) (call-with-values (lambda () (fill-input port (bytevector-length bom))) (lambda (buf cur buffered) (and (<= (bytevector-length bom) buffered) (let ((bv (port-buffer-bytevector buf))) (let lp ((i 1)) (if (= i (bytevector-length bom)) (begin (set-port-buffer-cur! buf (+ cur i)) #t) (and (eq? (bytevector-u8-ref bv (+ cur i)) (bytevector-u8-ref bom i)) (lp (1+ i))))))))))) (when (and (port-clear-stream-start-for-bom-read port) (eq? io-mode 'text)) (case (%port-encoding port) ((UTF-8) (maybe-consume-bom utf8-bom)) ((UTF-16) (cond ((maybe-consume-bom utf16le-bom) (specialize-port-encoding! port 'UTF-16LE)) (else (maybe-consume-bom utf16be-bom) (specialize-port-encoding! port 'UTF-16BE)))) ((UTF-32) (cond ((maybe-consume-bom utf32le-bom) (specialize-port-encoding! port 'UTF-32LE)) (else (maybe-consume-bom utf32be-bom) (specialize-port-encoding! port 'UTF-32BE))))))) (define* (fill-input port #:optional (minimum-buffering 1) (io-mode 'text)) (clear-stream-start-for-bom-read port io-mode) (let* ((buf (port-read-buffer port)) (cur (port-buffer-cur buf)) (buffered (max (- (port-buffer-end buf) cur) 0))) (cond ((or (<= minimum-buffering buffered) (port-buffer-has-eof? buf)) (values buf cur buffered)) (else (unless (input-port? port) (error "not an input port" port)) (when (port-random-access? port) (flush-output port)) (let ((bv (port-buffer-bytevector buf))) (cond ((< (bytevector-length bv) minimum-buffering) (expand-port-read-buffer! port minimum-buffering) (fill-input port minimum-buffering)) (else (when (< 0 cur) (bytevector-copy! bv cur bv 0 buffered) (set-port-buffer-cur! buf 0) (set-port-buffer-end! buf buffered)) (let ((buffering (max (port-read-buffering port) minimum-buffering))) (let lp ((buffered buffered)) (let* ((count (- buffering buffered)) (read (read-bytes port bv buffered count))) (cond ((zero? read) (set-port-buffer-has-eof?! buf #t) (values buf 0 buffered)) (else (let ((buffered (+ buffered read))) (set-port-buffer-end! buf buffered) (if (< buffered minimum-buffering) (lp buffered) (values buf 0 buffered))))))))))))))) (define* (force-output #:optional (port (current-output-port))) (unless (and (output-port? port) (not (port-closed? port))) (error "not an open output port" port)) (flush-output port)) (define close-port (let ((%close-port (@ (guile) close-port))) (lambda (port) (cond ((port-closed? port) #f) (else (when (output-port? port) (flush-output port)) (%close-port port)))))) (define-inlinable (peek-bytes port count kfast kslow) (let* ((buf (port-read-buffer port)) (cur (port-buffer-cur buf)) (buffered (- (port-buffer-end buf) cur))) (if (<= count buffered) (kfast buf (port-buffer-bytevector buf) cur buffered) (call-with-values (lambda () (fill-input port count)) (lambda (buf cur buffered) (kslow buf (port-buffer-bytevector buf) cur buffered)))))) (define (peek-byte port) (peek-bytes port 1 (lambda (buf bv cur buffered) (bytevector-u8-ref bv cur)) (lambda (buf bv cur buffered) (and (> buffered 0) (bytevector-u8-ref bv cur))))) (define* (lookahead-u8 port) (define (fast-path buf bv cur buffered) (bytevector-u8-ref bv cur)) (define (slow-path buf bv cur buffered) (if (zero? buffered) the-eof-object (fast-path buf bv cur buffered))) (peek-bytes port 1 fast-path slow-path)) (define* (get-u8 port) (define (fast-path buf bv cur buffered) (set-port-buffer-cur! buf (1+ cur)) (bytevector-u8-ref bv cur)) (define (slow-path buf bv cur buffered) (if (zero? buffered) (begin (set-port-buffer-has-eof?! buf #f) the-eof-object) (fast-path buf bv cur buffered))) (peek-bytes port 1 fast-path slow-path)) (define (get-bytevector-n! port bv start count) (define (port-buffer-take! pos buf cur to-copy) (bytevector-copy! (port-buffer-bytevector buf) cur bv pos to-copy) (set-port-buffer-cur! buf (+ cur to-copy)) (+ pos to-copy)) (define (take-already-buffered) (let* ((buf (port-read-buffer port)) (cur (port-buffer-cur buf)) (buffered (max (- (port-buffer-end buf) cur) 0))) (port-buffer-take! start buf cur (min count buffered)))) (define (buffer-and-fill pos) (call-with-values (lambda () (fill-input port 1 'binary)) (lambda (buf cur buffered) (if (zero? buffered) ;; We found EOF, which is marked in the port read buffer. ;; If we haven't read any bytes yet, clear the EOF from the ;; buffer and return it. Otherwise return the number of ;; bytes that we have read. (if (= pos start) (begin (set-port-buffer-has-eof?! buf #f) the-eof-object) (- pos start)) (let ((pos (port-buffer-take! pos buf cur (min (- (+ start count) pos) buffered)))) (if (= pos (+ start count)) count (buffer-and-fill pos))))))) (define (fill-directly pos) (when (port-random-access? port) (flush-output port)) (port-clear-stream-start-for-bom-read port) (let lp ((pos pos)) (let ((read (read-bytes port bv pos (- (+ start count) pos)))) (cond ((= (+ pos read) (+ start count)) count) ((zero? read) ;; We found EOF. If we haven't read any bytes yet, return ;; EOF. Otherwise save the EOF in the port read buffer. (if (= pos start) the-eof-object (begin (set-port-buffer-has-eof?! (port-read-buffer port) #t) (- pos start)))) (else (lp (+ pos read))))))) (let ((pos (take-already-buffered))) (cond ((= pos (+ start count)) count) ((< (- (+ start count) pos) (port-read-buffering port)) (buffer-and-fill pos)) (else (fill-directly pos))))) (define (get-bytevector-n port count) (let* ((bv (make-bytevector count)) (result (get-bytevector-n! port bv 0 count))) (cond ((eof-object? result) result) ((= result count) bv) (else (let ((bv* (make-bytevector result))) (bytevector-copy! bv 0 bv* 0 result) bv*))))) (define (get-bytevector-some port) (call-with-values (lambda () (fill-input port 1 'binary)) (lambda (buf cur buffered) (if (zero? buffered) (begin (set-port-buffer-has-eof?! buf #f) the-eof-object) (let ((result (make-bytevector buffered))) (bytevector-copy! (port-buffer-bytevector buf) cur result 0 buffered) (set-port-buffer-cur! buf (+ cur buffered)) result))))) (define (get-bytevector-some! port bv start count) (if (zero? count) 0 (call-with-values (lambda () (fill-input port 1 'binary)) (lambda (buf cur buffered) (if (zero? buffered) (begin (set-port-buffer-has-eof?! buf #f) the-eof-object) (let ((transfer-size (min count buffered))) (bytevector-copy! (port-buffer-bytevector buf) cur bv start transfer-size) (set-port-buffer-cur! buf (+ cur transfer-size)) transfer-size)))))) (define (put-u8 port byte) (let* ((buf (port-write-buffer port)) (bv (port-buffer-bytevector buf)) (end (port-buffer-end buf))) (unless (<= 0 end (bytevector-length bv)) (error "not an output port" port)) (when (and (eq? (port-buffer-cur buf) end) (port-random-access? port)) (flush-input port)) (cond ((= end (bytevector-length bv)) ;; Multiple threads racing; race to flush, then retry. (flush-output port) (put-u8 port byte)) (else (bytevector-u8-set! bv end byte) (set-port-buffer-end! buf (1+ end)) (when (= (1+ end) (bytevector-length bv)) (flush-output port)))))) (define* (put-bytevector port src #:optional (start 0) (count (- (bytevector-length src) start))) (unless (<= 0 start (+ start count) (bytevector-length src)) (error "invalid start/count" start count)) (let* ((buf (port-write-buffer port)) (bv (port-buffer-bytevector buf)) (size (bytevector-length bv)) (cur (port-buffer-cur buf)) (end (port-buffer-end buf)) (buffered (max (- end cur) 0))) (when (and (eq? cur end) (port-random-access? port)) (flush-input port)) (cond ((<= size count) ;; The write won't fit in the buffer at all; write directly. ;; Write directly. Flush write buffer first if needed. (when (< cur end) (flush-output port)) (write-bytes port src start count)) ((< (- size buffered) count) ;; The write won't fit into the buffer along with what's already ;; buffered. Flush and fill. (flush-output port) (set-port-buffer-end! buf count) (bytevector-copy! src start bv 0 count)) (else ;; The write will fit in the buffer, but we need to shuffle the ;; already-buffered bytes (if any) down. (set-port-buffer-cur! buf 0) (set-port-buffer-end! buf (+ buffered count)) (bytevector-copy! bv cur bv 0 buffered) (bytevector-copy! src start bv buffered count) ;; If the buffer completely fills, we flush. (when (= (+ buffered count) size) (flush-output port)))))) (define (decoding-error subr port) ;; GNU definition; fixme? (define EILSEQ 84) (throw 'decoding-error subr "input decoding error" EILSEQ port)) (define-inlinable (decode-utf8 bv start avail u8_0 kt kf) (cond ((< u8_0 #x80) (kt (integer->char u8_0) 1)) ((and (<= #xc2 u8_0 #xdf) (<= 2 avail)) (let ((u8_1 (bytevector-u8-ref bv (1+ start)))) (if (= (logand u8_1 #xc0) #x80) (kt (integer->char (logior (ash (logand u8_0 #x1f) 6) (logand u8_1 #x3f))) 2) (kf)))) ((and (= (logand u8_0 #xf0) #xe0) (<= 3 avail)) (let ((u8_1 (bytevector-u8-ref bv (+ start 1))) (u8_2 (bytevector-u8-ref bv (+ start 2)))) (if (and (= (logand u8_1 #xc0) #x80) (= (logand u8_2 #xc0) #x80) (case u8_0 ((#xe0) (>= u8_1 #xa0)) ((#xed) (>= u8_1 #x9f)) (else #t))) (kt (integer->char (logior (ash (logand u8_0 #x0f) 12) (ash (logand u8_1 #x3f) 6) (logand u8_2 #x3f))) 3) (kf)))) ((and (<= #xf0 u8_0 #xf4) (<= 4 avail)) (let ((u8_1 (bytevector-u8-ref bv (+ start 1))) (u8_2 (bytevector-u8-ref bv (+ start 2))) (u8_3 (bytevector-u8-ref bv (+ start 3)))) (if (and (= (logand u8_1 #xc0) #x80) (= (logand u8_2 #xc0) #x80) (= (logand u8_3 #xc0) #x80) (case u8_0 ((#xf0) (>= u8_1 #x90)) ((#xf4) (>= u8_1 #x8f)) (else #t))) (kt (integer->char (logior (ash (logand u8_0 #x07) 18) (ash (logand u8_1 #x3f) 12) (ash (logand u8_2 #x3f) 6) (logand u8_3 #x3f))) 4) (kf)))) (else (kf)))) (define (bad-utf8-len bv cur buffering first-byte) (define (ref n) (bytevector-u8-ref bv (+ cur n))) (cond ((< first-byte #x80) 0) ((<= #xc2 first-byte #xdf) (cond ((< buffering 2) 1) ((not (= (logand (ref 1) #xc0) #x80)) 1) (else 0))) ((= (logand first-byte #xf0) #xe0) (cond ((< buffering 2) 1) ((not (= (logand (ref 1) #xc0) #x80)) 1) ((and (eq? first-byte #xe0) (< (ref 1) #xa0)) 1) ((and (eq? first-byte #xed) (< (ref 1) #x9f)) 1) ((< buffering 3) 2) ((not (= (logand (ref 2) #xc0) #x80)) 2) (else 0))) ((<= #xf0 first-byte #xf4) (cond ((< buffering 2) 1) ((not (= (logand (ref 1) #xc0) #x80)) 1) ((and (eq? first-byte #xf0) (< (ref 1) #x90)) 1) ((and (eq? first-byte #xf4) (< (ref 1) #x8f)) 1) ((< buffering 3) 2) ((not (= (logand (ref 2) #xc0) #x80)) 2) ((< buffering 4) 3) ((not (= (logand (ref 3) #xc0) #x80)) 3) (else 0))) (else 1))) (define (peek-char-and-next-cur/utf8 port buf cur first-byte) (if (< first-byte #x80) (values (integer->char first-byte) buf (+ cur 1)) (call-with-values (lambda () (fill-input port (cond ((<= #xc2 first-byte #xdf) 2) ((= (logand first-byte #xf0) #xe0) 3) (else 4)))) (lambda (buf cur buffering) (let ((bv (port-buffer-bytevector buf))) (define (bad-utf8) (let ((len (bad-utf8-len bv cur buffering first-byte))) (when (zero? len) (error "internal error")) (if (eq? (port-conversion-strategy port) 'substitute) (values #\xFFFD buf (+ cur len)) (decoding-error "peek-char" port)))) (decode-utf8 bv cur buffering first-byte (lambda (char len) (values char buf (+ cur len))) bad-utf8)))))) (define (peek-char-and-next-cur/iso-8859-1 port buf cur first-byte) (values (integer->char first-byte) buf (+ cur 1))) (define (peek-char-and-next-cur/iconv port) (let lp ((prev-input-size 0)) (let ((input-size (1+ prev-input-size))) (call-with-values (lambda () (fill-input port input-size)) (lambda (buf cur buffered) (cond ((< buffered input-size) ;; Buffer failed to fill; EOF, possibly premature. (cond ((zero? prev-input-size) (values the-eof-object buf cur)) ((eq? (port-conversion-strategy port) 'substitute) (values #\xFFFD buf (+ cur prev-input-size))) (else (decoding-error "peek-char" port)))) ((port-decode-char port (port-buffer-bytevector buf) cur input-size) => (lambda (char) (values char buf (+ cur input-size)))) (else (lp input-size)))))))) (define (peek-char-and-next-cur port) (define (have-byte buf bv cur buffered) (let ((first-byte (bytevector-u8-ref bv cur))) (case (%port-encoding port) ((UTF-8) (peek-char-and-next-cur/utf8 port buf cur first-byte)) ((ISO-8859-1) (peek-char-and-next-cur/iso-8859-1 port buf cur first-byte)) (else (peek-char-and-next-cur/iconv port))))) (peek-bytes port 1 have-byte (lambda (buf bv cur buffered) (if (< 0 buffered) (have-byte buf bv cur buffered) (values the-eof-object buf cur))))) (define* (peek-char #:optional (port (current-input-port))) (define (slow-path) (call-with-values (lambda () (peek-char-and-next-cur port)) (lambda (char buf cur) char))) (define (fast-path buf bv cur buffered) (let ((u8 (bytevector-u8-ref bv cur)) (enc (%port-encoding port))) (case enc ((UTF-8) (decode-utf8 bv cur buffered u8 (lambda (char len) char) slow-path)) ((ISO-8859-1) (integer->char u8)) (else (slow-path))))) (peek-bytes port 1 fast-path (lambda (buf bv cur buffered) (slow-path)))) (define-inlinable (advance-port-position! pos char) ;; FIXME: this cond is a speed hack; really we should just compile ;; `case' better. (cond ;; FIXME: char>? et al should compile well. ((<= (char->integer #\space) (char->integer char)) (set-port-position-column! pos (1+ (port-position-column pos)))) (else (case char ((#\alarm) #t) ; No change. ((#\backspace) (let ((col (port-position-column pos))) (when (> col 0) (set-port-position-column! pos (1- col))))) ((#\newline) (set-port-position-line! pos (1+ (port-position-line pos))) (set-port-position-column! pos 0)) ((#\return) (set-port-position-column! pos 0)) ((#\tab) (let ((col (port-position-column pos))) (set-port-position-column! pos (- (+ col 8) (remainder col 8))))) (else (set-port-position-column! pos (1+ (port-position-column pos)))))))) (define* (read-char #:optional (port (current-input-port))) (define (finish buf char) (advance-port-position! (port-buffer-position buf) char) char) (define (slow-path) (call-with-values (lambda () (peek-char-and-next-cur port)) (lambda (char buf cur) (set-port-buffer-cur! buf cur) (if (eq? char the-eof-object) (begin (set-port-buffer-has-eof?! buf #f) char) (finish buf char))))) (define (fast-path buf bv cur buffered) (let ((u8 (bytevector-u8-ref bv cur)) (enc (%port-encoding port))) (case enc ((UTF-8) (decode-utf8 bv cur buffered u8 (lambda (char len) (set-port-buffer-cur! buf (+ cur len)) (finish buf char)) slow-path)) ((ISO-8859-1) (set-port-buffer-cur! buf (+ cur 1)) (finish buf (integer->char u8))) (else (slow-path))))) (peek-bytes port 1 fast-path (lambda (buf bv cur buffered) (slow-path)))) (define-inlinable (port-fold-chars/iso-8859-1 port proc seed) (let* ((buf (port-read-buffer port)) (cur (port-buffer-cur buf))) (let fold-buffer ((buf buf) (cur cur) (seed seed)) (let ((bv (port-buffer-bytevector buf)) (end (port-buffer-end buf))) (let fold-chars ((cur cur) (seed seed)) (cond ((= end cur) (call-with-values (lambda () (fill-input port)) (lambda (buf cur buffered) (if (zero? buffered) (call-with-values (lambda () (proc the-eof-object seed)) (lambda (seed done?) (if done? seed (fold-buffer buf cur seed)))) (fold-buffer buf cur seed))))) (else (let ((ch (integer->char (bytevector-u8-ref bv cur))) (cur (1+ cur))) (set-port-buffer-cur! buf cur) (advance-port-position! (port-buffer-position buf) ch) (call-with-values (lambda () (proc ch seed)) (lambda (seed done?) (if done? seed (fold-chars cur seed)))))))))))) (define-inlinable (port-fold-chars port proc seed) (case (%port-encoding port) ((ISO-8859-1) (port-fold-chars/iso-8859-1 port proc seed)) (else (let lp ((seed seed)) (let ((ch (read-char port))) (call-with-values (lambda () (proc ch seed)) (lambda (seed done?) (if done? seed (lp seed))))))))) (define* (read-delimited delims #:optional (port (current-input-port)) (handle-delim 'trim)) ;; Currently this function conses characters into a list, then uses ;; reverse-list->string. It wastes 2 words per character but it still ;; seems to be the fastest thing at the moment. (define (finish delim chars) (define (->string chars) (if (and (null? chars) (not (char? delim))) the-eof-object (reverse-list->string chars))) (case handle-delim ((trim) (->string chars)) ((split) (cons (->string chars) delim)) ((concat) (->string (if (char? delim) (cons delim chars) chars))) ((peek) (when (char? delim) (unread-char delim port)) (->string chars)) (else (error "unexpected handle-delim value: " handle-delim)))) (define-syntax-rule (make-folder delimiter?) (lambda (char chars) (if (or (not (char? char)) (delimiter? char)) (values (finish char chars) #t) (values (cons char chars) #f)))) (define-syntax-rule (specialized-fold delimiter?) (port-fold-chars port (make-folder delimiter?) '())) (case (string-length delims) ((0) (specialized-fold (lambda (char) #f))) ((1) (let ((delim (string-ref delims 0))) (specialized-fold (lambda (char) (eqv? char delim))))) (else => (lambda (ndelims) (specialized-fold (lambda (char) (let lp ((i 0)) (and (< i ndelims) (or (eqv? char (string-ref delims i)) (lp (1+ i))))))))))) (define* (read-line #:optional (port (current-input-port)) (handle-delim 'trim)) (read-delimited "\n" port handle-delim)) (define* (%read-line port) (read-line port 'split)) (define* (put-string port str #:optional (start 0) (count (- (string-length str) start))) (let* ((aux (port-auxiliary-write-buffer port)) (pos (port-buffer-position aux)) (line (port-position-line pos))) (set-port-buffer-cur! aux 0) (port-clear-stream-start-for-bom-write port aux) (let lp ((encoded 0)) (when (< encoded count) (let ((encoded (+ encoded (port-encode-chars port aux str (+ start encoded) (- count encoded))))) (let ((end (port-buffer-end aux))) (set-port-buffer-end! aux 0) (put-bytevector port (port-buffer-bytevector aux) 0 end) (lp encoded))))) (when (and (not (eqv? line (port-position-line pos))) (port-line-buffered? port)) (flush-output port)))) (define* (put-char port char) (let ((aux (port-auxiliary-write-buffer port))) (set-port-buffer-cur! aux 0) (port-clear-stream-start-for-bom-write port aux) (port-encode-char port aux char) (let ((end (port-buffer-end aux))) (set-port-buffer-end! aux 0) (put-bytevector port (port-buffer-bytevector aux) 0 end)) (when (and (eqv? char #\newline) (port-line-buffered? port)) (flush-output port)))) (define accept (let ((%accept (@ (guile) accept))) (lambda* (port #:optional (flags 0)) (let lp () (or (%accept port flags) (begin (wait-for-readable port) (lp))))))) (define connect (let ((%connect (@ (guile) connect))) (lambda (port sockaddr . args) (unless (apply %connect port sockaddr args) ;; Clownshoes semantics; see connect(2). (wait-for-writable port) (let ((err (getsockopt port SOL_SOCKET SO_ERROR))) (unless (zero? err) (scm-error 'system-error "connect" "~A" (list (strerror err)) #f))))))) (define saved-port-bindings #f) (define port-bindings '(((guile) read-char peek-char force-output close-port accept connect) ((ice-9 binary-ports) get-u8 lookahead-u8 get-bytevector-n get-bytevector-n! get-bytevector-some get-bytevector-some! put-u8 put-bytevector) ((ice-9 textual-ports) put-char put-string) ((ice-9 rdelim) %read-line read-line read-delimited))) (define (install-suspendable-ports!) (unless saved-port-bindings (set! saved-port-bindings (make-hash-table)) (let ((suspendable-ports (resolve-module '(ice-9 suspendable-ports)))) (for-each (match-lambda ((mod . syms) (let ((mod (resolve-module mod))) (for-each (lambda (sym) (hashq-set! saved-port-bindings sym (module-ref mod sym)) (module-set! mod sym (module-ref suspendable-ports sym))) syms)))) port-bindings)))) (define (uninstall-suspendable-ports!) (when saved-port-bindings (for-each (match-lambda ((mod . syms) (let ((mod (resolve-module mod))) (for-each (lambda (sym) (let ((saved (hashq-ref saved-port-bindings sym))) (module-set! mod sym saved))) syms)))) port-bindings) (set! saved-port-bindings #f)))
true
31a70baa44a12fc425841f1c7d48b9385f66d04f
6bd63be924173b3cf53a903f182e50a1150b60a8
/chapter_2/2.47.scm
88150ab9734f64f57acd815b7ec0ae4fa57fda8e
[]
no_license
lf2013/SICP-answer
d29ee3095f0d018de1d30507e66b12ff890907a5
2712b67edc6df8ccef3156f4ef08a2b58dcfdf81
refs/heads/master
2020-04-06T13:13:51.086818
2019-09-11T11:39:45
2019-09-11T11:39:45
8,695,137
0
1
null
2016-03-17T13:19:21
2013-03-11T02:24:41
Scheme
UTF-8
Scheme
false
false
841
scm
2.47.scm
; the things worth doing typically take time and effort. ; 2.47.scm (define (make-frame origin edge1 edge2) (list origin edge1 edge2)) (define (origin-frame frame) (car frame)) (define (edge1-frame frame) (cadr frame)) (define (edge2-frame frame) (caddr frame)) (define (try) (define f (make-frame 1 2 3)) (display (origin-frame f)) (newline) (display (edge1-frame f)) (newline) (display (edge2-frame f)) ) (define (make-frame-v2 origin edge1 edge2) (cons origin (cons edge1 edge2))) (define (origin-frame-v2 frame) (car frame)) (define (edge1-frame-v2 frame) (cadr frame)) (define (edge2-frame-v2 frame) (cddr frame)) (define (try-v2) (define f (make-frame-v2 1 2 3)) (display (origin-frame-v2 f)) (newline) (display (edge1-frame-v2 f)) (newline) (display (edge2-frame-v2 f)) )
false
2246fb320720eb03f5abf8abc96e31a694f3145c
bcfa2397f02d5afa93f4f53c0b0a98c204caafc1
/scheme/chapter2/ex2_08.scm
52000d39105b3d2fab7317e6962cc357c4dab175
[]
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
402
scm
ex2_08.scm
;; SICP 2.8 ;; Exercise 2.8. Using reasoning analogous to Alyssa's, describe how ;; the difference of two intervals may be computed. Define a ;; corresponding subtraction procedure, called sub-interval. ;; ANSWER ------------------------------------------------------------ (define (sub-interval a b) (make-interval (- (lower-bound a) (upper-bound b)) (- (upper-bound a) (lower-bound b))))
false
a30b4f39cafdaf67df3337f80c49c4d7cfd63b8f
8a0660bd8d588f94aa429050bb8d32c9cd4290d5
/boot/lib/proc.scm
ca4e6be438d044e6bc89f9e93171b518ce785bec
[ "BSD-2-Clause" ]
permissive
david135/sagittarius-scheme
dbec76f6b227f79713169985fc16ce763c889472
2fbd9d153c82e2aa342bfddd59ed54d43c5a7506
refs/heads/master
2016-09-02T02:44:31.668025
2013-12-21T07:24:08
2013-12-21T07:24:08
32,497,456
0
0
null
null
null
null
UTF-8
Scheme
false
false
4,141
scm
proc.scm
;; -*- Scheme -*- #!core ;; procedure ;; procedure might be inline assembler such as CAR, CDR etc. ;; this structure must have both procedure definition and ;; insn. ;; proporties: ;; name - procedure name. mostly for debug i guess... ;; type - if it has insn it has (inline) or #f ;; insn - insn ;; optional - if this procedure takes optional arguments ;; body - procedure body. (define (make-procedure name inliner reqargs optional body) (vector '.procedure name inliner reqargs optional body)) (define (procedure-name p) (vector-ref p 1)) (define (procedure-inliner p) (vector-ref p 2)) (define (procedure-inliner-set! p inliner) (vector-set! p 2 inliner)) (define (procedure-reqargs p) (vector-ref p 3)) (define (procedure-optional p) (vector-ref p 4)) (define (procedure-body p) (vector-ref p 5)) (define (procedure? p) (and (vector? p) (eq? (vector-ref p 0) '.procedure))) (define (inline? p) (or (and (procedure? p) ;; TODO add no-inline flag here (procedure-inliner p)) (and (closure? p) (vector-ref p 2)))) (define (find-procedure name lib) (find-binding lib name #f)) (define-macro (declare-procedure name args type library proc) (let ((lib (ensure-library-name library))) (receive (reqargs opt?) (parse-args args) (let ((inline (parse-type type))) (let ((proc `(make-procedure ',name ,inline ,reqargs ,opt? ,proc))) `(%insert-binding ',lib ',name ,proc)))))) (declare-procedure + objs (:inline ADD) :null +) ;;(declare-procedure +. objs (:inline ADDI) :null +.) (declare-procedure - (obj1 . rest) (:inline SUB) :null -) ;;(declare-procedure -. (obj1 . rest) (:inline SUBI) :null -.) (declare-procedure * objs (:inline MUL) :null *) ;;(declare-procedure *. objs (:inline MULI) :null *.) (declare-procedure / (obj1 . rest) (:inline DIV) :null /) ;;(declare-procedure /. (obj1 . rest) (:inline DIVI) :null /.) (declare-procedure list objs (:inline LIST) :null (lambda a a)) (declare-procedure append a (:inline APPEND) :null append) (declare-procedure eq? (a b) (:inline EQ) :null eq?) (declare-procedure eqv? (a b) (:inline EQV) :null eqv?) (declare-procedure = (a b . rest) (:inline NUM_EQ) :null =) (declare-procedure < (a b . rest) (:inline NUM_LT) :null <) (declare-procedure <= (a b . rest) (:inline NUM_LE) :null <=) (declare-procedure > (a b . rest) (:inline NUM_GT) :null >) (declare-procedure >= (a b . rest) (:inline NUM_GE) :null >=) (declare-procedure zero? (n) (:inline -1) :null zero?) ;; list procedure (declare-procedure car (l) (:inline CAR) :null car) (declare-procedure cdr (l) (:inline CDR) :null cdr) (declare-procedure caar (l) (:inline CAAR) :null car) (declare-procedure cadr (l) (:inline CADR) :null cadr) (declare-procedure cdar (l) (:inline CDAR) :null cdar) (declare-procedure cddr (l) (:inline CDDR) :null cddr) (declare-procedure cons (a b) (:inline CONS) :null cons) (declare-procedure acons (a b c) (:inline -1) :sagittarius acons) (declare-procedure set-car! (a b) (:inline SET_CAR) :null set-car!) (declare-procedure set-cdr! (a b) (:inline SET_CDR) :null set-cdr!) ;; conditions (declare-procedure null? (x) (:inline NULLP) :null null?) (declare-procedure pair? (x) (:inline PAIRP) :null pair?) (declare-procedure symbol? (x) (:inline SYMBOLP) :null symbol?) (declare-procedure not (x) (:inline NOT) :null not) ;; vector (declare-procedure vector rest (:inline VECTOR) :null vector) (declare-procedure vector? (x) (:inline VECTORP) :null vector?) (declare-procedure vector-length (x) (:inline VEC_LEN) :null vector-length) (declare-procedure vector-ref (v i) (:inline -1) :null vector-ref) (declare-procedure vector-set! (vec i v) (:inline -1) :null vector-set!) ;; values (declare-procedure values rest (:inline VALUES) :null values) (declare-procedure apply (a . b) (:inline APPLY) :null apply) (declare-procedure cons* x (:inline -1) :null cons*) ;; dummy ;;(declare-procedure map (p l1 . l2) (:inline -1) :base map) ;;(declare-procedure for-each (p l1 . l2) (:inline -1) :base for-each) ;;;; end of file ;; Local Variables: ;; coding: utf-8-unix ;; End:
false
0b16c6d80254e312d8c2b4ffdd5f567f2623fff3
2fc7c18108fb060ad1f8d31f710bcfdd3abc27dc
/lib/letcc.scm
bb5d82175d56b19067f382a07935bd7a8e0e1114
[ "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
671
scm
letcc.scm
; Scheme 9 from Empty Space, Function Library ; By Nils M Holm, 2010 ; Placed in the Public Domain ; ; (let/cc <name> . <body>) ==> object ; ; (load-from-library "letcc.scm") ; ; Bind the current continuation to <name> and evaluate <body> with ; that binding in effect. ; ; Example: (let/cc exit ; (letrec ; ((f (lambda (x) ; (cond ((null? x) 0) ; ((pair? x) (+ 1 (f (cdr x)))) ; (else (exit 'foo)))))) ; (f '(1 2 3 . 4)))) ==> foo (define-syntax (let/cc name . body) `(call/cc (lambda (,name) ,@body)))
true
b94cb30ab4cc7b438f42b2d12b93ad70da76654b
1384f71796ddb9d11c34c6d988c09a442b2fc8b2
/examples/cli
0f7223bcd038748d4e52f8b895a95f48c5484b51
[]
no_license
ft/xmms2-guile
94c2479eec427a370603425fc9e757611a796254
29670e586bf440c20366478462f425d5252b953c
refs/heads/master
2021-07-08T07:58:15.066996
2020-10-12T01:24:04
2020-10-12T01:24:04
74,858,831
1
2
null
null
null
null
UTF-8
Scheme
false
false
7,958
cli
;; -*- scheme-*- (use-modules (ice-9 format) (srfi srfi-11) (xmms2 client) (xmms2 client synchronous) (xmms2 constants) (xmms2 constants meta) (xmms2 constants collection) (xmms2 fetch-spec) (xmms2 io) ((xmms2 ipc collection) #:prefix coll:) (xmms2 ipc main) (xmms2 ipc media-library) (xmms2 ipc playlist) (xmms2 ipc playback) (xmms2 payload) (xmms2 types)) (define debug? #f) (define pl property-list->dictionary) (define generator-map `(("play" . ,(lambda (server) (ipc-start))) ("stop" . ,(lambda (server) (ipc-stop))) ("pause" . ,(lambda (server) (ipc-pause))) ("tickle" . ,(lambda (server) (ipc-kill-decoder))) ("next" . ,(lambda (server) (ipc-set-next/relative 1))) ("prev" . ,(lambda (server) (ipc-set-next/relative -1))) ("active-playlist" . ,(lambda (server) (ipc-get-currently-active))) ("time" . ,(lambda (server) (ipc-get-playtime))) ("statistics" . ,(lambda (server) (ipc-statistics))) ("list" . ,(lambda (server) (ipc-list-entries (request->value server (ipc-get-currently-active))))) ("current-track" . ,(lambda (server) (ipc-get-current-identifier))) ("list-collections" . ,(lambda (server) (coll:ipc-list "Collections"))) ("count-tracks" . ,(lambda (server) (coll:ipc-query (make-universe) (pl #:type "count")))) ("list-artists" . ,(lambda (server) (coll:ipc-query ;; Takes collection and a fetch-spec... (make-universe) (fetch-spec #:type cluster-list #:cluster-by value #:cluster-field artist #:data (- #:type organize #:data (- #:count (- #:type count) #:artist (- #:type metadata #:fields (artist) #:get (value)))))))))) (define (cmd->generator cmd) (let ((rv (assoc cmd generator-map))) (and rv (cdr rv)))) (define (usage) (format #t "usage: cli COMMAND~%") (format #t "Available commands: ~a~%" (string-join (map car generator-map) ", "))) (unless (= 2 (length (command-line))) (usage) (quit 0)) (define command (cadr (command-line))) (define generator (cmd->generator command)) (unless generator (usage) (quit 0)) (setlocale LC_ALL "") (define (fetch-info server id) (request->value server (ipc-get-information id))) (define (get-info info default) (if (not info) default (cdar (dictionary-data (cdr info))))) (define (format-track info) (let ((artist (dict 'artist info)) (album (dict 'album info)) (title (dict 'title info)) (tracknr (dict 'tracknr info))) (format #t "~a - ~a - ~2,'0d. ~a~%" (get-info artist "<NoArtist>") (get-info album "<NoAlbum>") (get-info tracknr 0) (get-info title "<NoTitle>")))) (define (time->pieces ms) (define ms-per-second 1000) (define ms-per-minute (* 60 ms-per-second)) (define ms-per-hour (* 60 ms-per-minute)) (define ms-per-day (* 24 ms-per-hour)) (define ms-per-year (round (* (inexact->exact 365.2425) ms-per-day))) (let loop ((divs (list ms-per-year ms-per-day ms-per-hour ms-per-minute ms-per-second 1)) (rest ms) (acc '())) (if (null? divs) (apply values (reverse acc)) (let* ((div (car divs)) (piece (truncate (/ rest div)))) (loop (cdr divs) (- rest (* div piece)) (cons piece acc)))))) (define (size->pieces size) (let loop ((names '(t g m k b)) (div (* 1024 1024 1024 1024)) (rest size) (acc '())) (if (null? names) (apply values (reverse acc)) (let ((piece (truncate (/ rest div)))) (loop (cdr names) (/ div 1024) (- rest (* div piece)) (cons piece acc)))))) (define (format-stat n v) (case n ((uptime) (let-values (((y d h m s ms) (time->pieces (* v 1000)))) (format #t "~10,,,@a: ~d year~p ~d day~p ~2,'0d hour~p ~2,'0d minute~p ~2,'0d second~p~%" n y y d d h h m m s s))) ((duration playtime) (let-values (((y d h m s ms) (time->pieces v))) (format #t "~10,,,@a: ~d year~p ~d day~p ~2,'0d hour~p ~2,'0d minute~p ~2,'0d.~3,'0d seconds~%" n y y d d h h m m s ms))) ((size) (let-values (((t g m k b) (size->pieces v))) (format #t "~10,,,@a: ~d TiB~p, ~d GiB~p, ~d MiB~p, ~d KiB~p, ~d Byte~p~%" n t t g g m m k k b b))) (else (format #t "~10,,,@a: ~a~%" n v)))) (define (output-collection data indent) (format #t "~v_Operator: ~a => ~a~%" (if (> indent 2) indent 0) (collection-operator data) (assq-ref xref-collection-types (collection-operator data))) (format #t "~v_ID-List: ~s~%" indent (collection-idlist data)) (format #t "~v_Attributes: ~s~%" indent (collection-attributes data)) (format #t "~v_Children:~%" indent) (for-each (lambda (x) (output-collection x (+ indent 2))) (collection-children data))) (define (show-collection server c) (let ((data (request->value server (coll:ipc-get c "Collections")))) (format #t "~%Name: ~s, " c) (output-collection data 2))) (define (sort-artists lst) (sort lst (lambda (a b) (let ((a* (dict-ref 'count a)) (b* (dict-ref 'count b))) (< a* b*))))) (define (main server client-id cookie) (let ((reply (request->value server (generator server)))) (cond ((string=? command "statistics") (for-each (lambda (x) (let ((name (car x)) (value (cdr x))) (format-stat name value))) (dictionary-data reply))) ((string=? command "current-track") (display "np: ") (format-track (fetch-info server reply))) ((string=? command "list") (for-each (lambda (x) (format-track (fetch-info server x))) reply)) ((string=? command "active-playlist") (format #t "Active Playlist: ~a~%" reply)) ((string=? command "list-collections") (format #t "Collections:~%") (for-each (lambda (x) (show-collection server x)) reply)) ((string=? command "time") (let* ((time-ms reply) (ms (modulo time-ms 1000)) (time (truncate (/ time-ms 1000))) (min (truncate (/ time 60))) (sec (modulo time 60))) (format #t "Current playtime: ~d:~2,'0d.~3,'0d~%" min sec ms))) ((string=? command "count-tracks") (format #t "Server Media-library contains ~a tracks.~%" reply)) ((string=? command "list-artists") (let loop ((rest (reverse (sort-artists reply)))) (if (null? rest) #t (let ((data (dictionary-data (car rest)))) (format #t "~a Tracks by ~a~%" (assq-ref data 'count) (assq-ref data 'artist)) (loop (cdr rest)))))) (else (if debug? (format #t "~a: ~s~%" command reply))))) (when (or (string=? command "next") (string=? command "prev")) (request->reply server (ipc-kill-decoder)))) (with-xmms2-connection #:handler main #:client "example-sync-client" #:server (let* ((env (getenv "XMMS2_GUILE_USE_SOCAT")) (use-socat? (and env (string=? env "1"))) (uri (default-uri))) (if use-socat? (string-append uri ".socat") uri)))
false
8af2271ca75591d8758bdf3635d83ee7d8fbb03b
defeada37d39bca09ef76f66f38683754c0a6aa0
/System/system/diagnostics/trace-source.sls
e0e20f3d5e72711e9bda305ff014b98220e917c6
[]
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
2,449
sls
trace-source.sls
(library (system diagnostics trace-source) (export new is? trace-source? trace-event trace-transfer trace-data flush trace-information close attributes listeners name switch-get switch-set! switch-update!) (import (ironscheme-clr-port)) (define-syntax new (lambda (e) (syntax-case e () ((_ a ...) #'(clr-new System.Diagnostics.TraceSource a ...))))) (define (is? a) (clr-is System.Diagnostics.TraceSource a)) (define (trace-source? a) (clr-is System.Diagnostics.TraceSource a)) (define-method-port trace-event System.Diagnostics.TraceSource TraceEvent (System.Void System.Diagnostics.TraceEventType System.Int32 System.String System.Object[]) (System.Void System.Diagnostics.TraceEventType System.Int32 System.String) (System.Void System.Diagnostics.TraceEventType System.Int32)) (define-method-port trace-transfer System.Diagnostics.TraceSource TraceTransfer (System.Void System.Int32 System.String System.Guid)) (define-method-port trace-data System.Diagnostics.TraceSource TraceData (System.Void System.Diagnostics.TraceEventType System.Int32 System.Object[]) (System.Void System.Diagnostics.TraceEventType System.Int32 System.Object)) (define-method-port flush System.Diagnostics.TraceSource Flush (System.Void)) (define-method-port trace-information System.Diagnostics.TraceSource TraceInformation (System.Void System.String System.Object[]) (System.Void System.String)) (define-method-port close System.Diagnostics.TraceSource Close (System.Void)) (define-field-port attributes #f #f (property:) System.Diagnostics.TraceSource Attributes System.Collections.Specialized.StringDictionary) (define-field-port listeners #f #f (property:) System.Diagnostics.TraceSource Listeners System.Diagnostics.TraceListenerCollection) (define-field-port name #f #f (property:) System.Diagnostics.TraceSource Name System.String) (define-field-port switch-get switch-set! switch-update! (property:) System.Diagnostics.TraceSource Switch System.Diagnostics.SourceSwitch))
true
b48b2f0cc4752ec80855d659f7871b08ad468f44
ec5b4a92882f80b3f62eac8cbd059fb1f000cfd9
/wcp-functional/!tests/mergesort.ss
552a43b8939935a204fdbf16d28afae0cd6605fa
[]
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
766
ss
mergesort.ss
; (define (mergesort ls) (if (null? ls) '() (dosort ls (length ls)))) (define (dosort ls n) (if (= n 1) (cons (car ls) '()) (if (= n 2) (let ([x (car ls)] [y (car (cdr ls))]) (if (< x y) (cons x (cons y '())) (cons y (cons x '())))) (let ([i (quotient n 2)]) (domerge (dosort ls i) (dosort (list-tail ls i) (- n i))))))) (define (domerge ls1 ls2) (if (null? ls1) ls2 (if (null? ls2) ls1 (if (< (car ls1) (car ls2)) (cons (car ls1) (domerge (cdr ls1) ls2)) (cons (car ls2) (domerge ls1 (cdr ls2))))))) (define (list-tail ls i) (if (= i 0) ls (list-tail (cdr ls) (- i 1)))) (define (length ls) (if (null? ls) 0 (+ 1 (length (cdr ls))))) '(mergesort (make-list size))
false
869921e8b50c6fb71711d99d4e1a3d64fbfae3c0
4b570eebce894b4373cba292f09883932834e543
/ch1/returnProcedures.scm
06d497f47dcd7344360bd3ad41fef2c8e0e3cf1e
[]
no_license
Pulkit12083/sicp
ffabc406c66019e5305ad701fbc022509319e4b1
8ea6c57d2b0be947026dd01513ded25991e5c94f
refs/heads/master
2021-06-17T13:44:06.381879
2021-05-14T16:52:30
2021-05-14T16:52:30
197,695,022
0
0
null
2021-04-14T17:04:01
2019-07-19T03:25:41
Scheme
UTF-8
Scheme
false
false
1,702
scm
returnProcedures.scm
;; functions as return values (define (fixedPoint func guess precision) (let ((fixedVal (func guess))) (cond ((< (abs (- fixedVal guess)) precision) guess) (else (fixedPoint func fixedVal precision))))) (fixedPoint cos 1.0 tolerance) (fixedPoint (lambda (x) (+ 1 (/ 1.0 x))) 1.6 tolerance) (define (fixedPointDamped func guess precision) (define (average a b) (/ (+ a b) 2)) (let ((fixedVal (func guess))) (cond ((< (abs (- fixedVal guess)) precision) guess) (else (fixedPoint func (average fixedVal guess) precision))))) (fixedPoint (lambda (x) (/ (log 1000) (log x))) 1.2 tolerance) (define (average x y) (/ (+ x y) 2)) (define (average-damp f) (lambda (x) (average x (f x)))) ;; a procedure that accepts a function f and returns a function that takes a value and retusn the average of that value and the func of that value ((average-damp square) 10) (define (sqrt x) (fixedPoint (average-damp (lambda (y) (/ x y))) 1.0 0.01)) (define (cube-root x) (fixedPoint (average-damp (lambda (y) (/ x (square y)))) 1.0 0.01)) (cube-root 27) (sqrt 5) ;;Newton's method ;; f(x) = x - g(x)/Dg(x) ;; Dg(x) = (g(x+dx) - g(x))/dx (define dx 0.00001) (define (deriv g) (lambda (x) (/ (- (g (+ x dx)) (g x)) dx))) (define (newton-transform g) (lambda (x) (- x (/ (g x) ((deriv g) x))))) (define (newton-method g guess) (fixedPoint (newton-transform g) guess 0.001)) (define (sqroot x) (newton-method (lambda (y) (- (square y) x)) 1.0)) (sqroot 5) (define (cube x) (* x x x)) ((deriv cube) 5) (define (newton-damp f) (lambda (x) (- x (/ ((deriv f) x) (define (fixed-point-of-transform g transform guess precision) (fixed-point (transform g) guess precision))
false
1892d08452fe242a4d12ceeee5b8d8f605ab7aaa
e42c980538d5315b9cca17460c90d9179cc6fd3a
/scm/rwtest.scm
8aa58335b9af50d8c0d9f344a1e9f87f6c9a49f0
[]
no_license
KenDickey/Scheme2Smalltalk-Translator
c4415f2053932a2c83b59ac9a554097836c55873
9ccd4e45fb386f99d2e62fc769f78241fbe29c77
refs/heads/master
2020-12-24T19:46:30.348021
2016-05-13T23:12:06
2016-05-13T23:12:06
58,775,118
1
0
null
null
null
null
UTF-8
Scheme
false
false
1,852
scm
rwtest.scm
; (define (read-display file-name-string) ; (with-input-from-file file-name-string ; (lambda () ; (display "Reading from ") ; (display file-name-string) ; (newline) ; (let loop ( (form (read)) ) ; (if (eof-object? form) ; 'done ; (begin ; (newline) ; (display form) ; (loop (read)))) ; ) ) ) ) ; @@ DEBUG ; (trace 'read1 read1) ; (trace 'read-sharp-thingie read-sharp-thingie) ; (trace 'read-sharp-sym read-sharp-sym) ; (trace 'read-character read-character) ; (trace 'read-identifier-string read-identifier-string) ; (trace 'read-number read-number) ; (trace 'read-identifier read-identifier) ; (trace 'read-abbreviation read-abbreviation) ; (trace 'read-string read-string) ; (trace 'read-pecular read-pecular) ; (trace 'read-list read-list) ; (trace 'read-vector read-vector) ; (trace 'read read) (define (read-display file-name-string) (let ( (in (open-input-file file-name-string)) ) (display "Reading from ") (display file-name-string) (newline) (let loop ( (form (read in)) ) (if (eof-object? form) (close-input-port in) (begin (newline) (display form) (loop (read in))))) ) ) (define (read-write file-name-string) (with-input-from-file file-name-string (lambda () (write "Reading from ") (write file-name-string) (newline) (let loop ( (form (read)) ) (if (eof-object? form) 'done (begin (newline) (write form) (loop (read)))) ) ) ) ) (define (read-pp file-name-string) (with-input-from-file file-name-string (lambda () (write "Reading from ") (write file-name-string) (newline) (let loop ( (form (read)) ) (if (eof-object? form) 'done (begin (newline) (pretty-print form) (loop (read)))) ) ) ) )
false
869bf29c1135007a322d59aa1b6f8672f235976b
e1fc47ba76cfc1881a5d096dc3d59ffe10d07be6
/ch2/2.59.scm
4eab9a81768220e29678eeb2c4f06b27f0d1f59f
[]
no_license
lythesia/sicp-sol
e30918e1ebd799e479bae7e2a9bd4b4ed32ac075
169394cf3c3996d1865242a2a2773682f6f00a14
refs/heads/master
2021-01-18T14:31:34.469130
2019-10-08T03:34:36
2019-10-08T03:34:36
27,224,763
2
0
null
null
null
null
UTF-8
Scheme
false
false
823
scm
2.59.scm
(define (element-of-set? x set) (cond ((null? set) #f) ((equal? x (car set)) #t) (else (element-of-set? x (cdr set))) ) ) (define (adjoin-set x set) (if (element-of-set? x set) set (cons x set)) ) (define (intersection-set s1 s2) (if (or (null? s1) (null? s2)) '() (let ((x (car s1)) (result (intersection-set (cdr s1) s2))) (if (element-of-set? x s2) (cons x result) result) ) ) ) (define (union-set s1 s2) (if (null? s2) s1 (union-set (adjoin-set (car s2) s1) (cdr s2))) ) ; test ; (define s1 '(1 2 3)) ; (define s2 '(3 4 5)) ; (display (element-of-set? '() s1))(newline) ; (display (element-of-set? 1 s1))(newline) ; (display (adjoin-set 0 s1))(newline) ; (display (adjoin-set 1 s1))(newline) ; (display (intersection-set s1 s2))(newline) ; (display (union-set s1 s2))(newline)
false
0942ff0c1ddfc839db3bed12df5d1465361be35e
700b17aea4b9ca5a4980bc5f35c2671451173ca9
/withsyntaxboot.scm
320a533b95737568628b46688642ac0af99461c0
[]
no_license
FredericHamel/define-library
e880486b476d764e98a5bf1f73bae7ba1406d619
56a6eda7ef9248751f4cada832edf98f5c6bb469
refs/heads/master
2021-06-12T03:49:52.508891
2016-12-09T15:11:25
2016-12-09T15:11:25
116,313,381
3
0
null
2018-01-04T22:21:32
2018-01-04T22:21:31
null
UTF-8
Scheme
false
false
715
scm
withsyntaxboot.scm
;;;============================================================================ ;;; File: "withsyntaxboot.scm" ;;; Copyright (c) 2000-2014 by Marc Feeley, All Rights Reserved. ;;;============================================================================ ;; This file implements a version of the (syntax ...) form that is ;; used for bootstrapping. ;;;---------------------------------------------------------------------------- (##define-syntax with-syntax (lambda (src) (include "syntaxboot.scm") (syntax-case src () ((_ ((pattern expr1)) expr2) #'(syntax-case expr1 () (pattern expr2)))))) ;;;============================================================================
true
d24e032fe45b430be94dabe905f4fa7c233a01fe
7cc14e6ab8e064fa967251e3249863e2cfbcc920
/chapter-1/newton-methods.scm
c5a3285a002cfad4434c674450f2ac070ac60598
[]
no_license
xueeinstein/sicp-code
0bec79419286705f58175067d474169afd6ba5fe
49602b0b13cb9c338b6af089f989c17890ba6085
refs/heads/master
2021-01-10T01:20:03.089038
2015-11-24T03:25:54
2015-11-24T03:25:54
43,536,317
0
0
null
null
null
null
UTF-8
Scheme
false
false
641
scm
newton-methods.scm
;;; Bill Xue ;;; 2015-10-06 ;;; Newton Methods ;;; one solution of g(x)=0 ;;; is the fixed point of ;;; x -> f(x) = x - g(x)/Dg(x) (load "fixed-point.scm") (define (newton-method g guess) ; transfroms g(x)=0 ; to f(x) fixed point problem (define (newton-transform g) (lambda (x) (- x (/ (g x) ((deriv g) x))))) ; derivative g(x) (define (deriv g) (lambda (x) (/ (- (g (+ x dx)) (g x)) dx))) (define dx 0.00001) ; main (fixed-point (newton-transform g) guess)) ;; test: solve g(y) = y^2 - x = 0 ;; then get sqrt(x) (define (sqrt-me x) (newton-method (lambda (y) (- (* y y) x)) 1.0))
false
9a6306331e92432271a8e9a57f269b3a885eaa3e
220acd342ded87198721d0e793c83be4711f7311
/src/function/r6rs-lib/unicode.scm
df2b268c140bcfeb6f505c93782552e768582181
[ "MIT" ]
permissive
yoo2001818/r6rs
65c4f0bc33bce2ab234d7d91bb1c807e289cad49
11dd18e451f7ccde6fbe31da7eac1825e3e9a439
refs/heads/master
2020-04-09T22:56:29.218850
2016-08-26T15:32:17
2016-08-26T15:32:17
61,253,960
4
0
null
null
null
null
UTF-8
Scheme
false
false
227
scm
unicode.scm
; module.exports = ` (define char-titlecase char-upcase) (define char-foldcase char-downcase) (define char-title-case? char-upper-case?) (define string-titlecase string-upcase) (define string-foldcase string-downcase) ; `;
false
a2ba6f67e7cd813c81006a2bc403763e6fb53d03
120324bbbf63c54de0b7f1ca48d5dcbbc5cfb193
/packages/box2d-lite/edges.sls
eac718ba4affa26f6f27e7633e03a00710535ec0
[ "MIT" ]
permissive
evilbinary/scheme-lib
a6d42c7c4f37e684c123bff574816544132cb957
690352c118748413f9730838b001a03be9a6f18e
refs/heads/master
2022-06-22T06:16:56.203827
2022-06-16T05:54:54
2022-06-16T05:54:54
76,329,726
609
71
MIT
2022-06-16T05:54:55
2016-12-13T06:27:36
Scheme
UTF-8
Scheme
false
false
1,979
sls
edges.sls
;; Copyright 2016 Eduardo Cavazos ;; ;; 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. (library (box2d-lite edges) (export make-edges edges-in-edge-1 edges-in-edge-1-set! edges-out-edge-1 edges-out-edge-1-set! edges-in-edge-2 edges-in-edge-2-set! edges-out-edge-2 edges-out-edge-2-set! is-edges import-edges create-edges edges-equal? flip) (import (rnrs) (box2d-lite util define-record-type) (box2d-lite edge-numbers)) ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (define-record-type++ edges is-edges import-edges (fields (mutable in-edge-1) (mutable out-edge-1) (mutable in-edge-2) (mutable out-edge-2)) (methods)) (define (create-edges) (make-edges NO-EDGE NO-EDGE NO-EDGE NO-EDGE)) ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (define (edges-equal? a b) (is-edges a) (is-edges b) (and (equal? a.in-edge-1 b.in-edge-1) (equal? a.out-edge-1 b.out-edge-1) (equal? a.in-edge-2 b.in-edge-2) (equal? a.out-edge-2 b.out-edge-2))) ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (define (flip e) (is-edges e) (let ((tmp e.in-edge-1)) (e.in-edge-1! e.in-edge-2) (e.in-edge-2! tmp)) (let ((tmp e.out-edge-1)) (e.out-edge-1! e.out-edge-2) (e.out-edge-2! tmp))) ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; )
false
3a241f1695d4b6f603c4b0af17ce1500026bc634
de21ee2b90a109c443485ed2e25f84daf4327af3
/exercise/section2/2.14.scm
4a58b77904b9c798e0801bccb5c9ec8ee720f459
[]
no_license
s-tajima/SICP
ab82518bdc0551bb4c99447ecd9551f8d3a2ea1d
9ceff8757269adab850d01f238225d871748d5dc
refs/heads/master
2020-12-18T08:56:31.032661
2016-11-10T11:37:52
2016-11-10T11:37:52
18,719,524
0
0
null
null
null
null
UTF-8
Scheme
false
false
2,134
scm
2.14.scm
;= Question ============================================================================= ;問題 2.14 ; ;Lemの正しいことを示せ. いろいろな算術演算の式でシステムの振舞いを調べよ. ;区間AとBを作り, A/AとA/Bを計算するのに使ってみよ. ;幅が中央値に比べて小さいパーセントの区間を使うと, 大体のことは推察出来る. ;中央値とパーセント相対許容誤差の形式の計算結果を調べよ(問題2.12参照). ; ;= Prepared ============================================================================= (define (add-interval x y) (make-interval (+ (lower-bound x) (lower-bound y)) (+ (upper-bound x) (upper-bound y)))) (define (sub-interval x y) (make-interval (- (lower-bound x) (upper-bound y)) (- (upper-bound x) (lower-bound y)))) (define (mul-interval x y) (let ((p1 (* (lower-bound x) (lower-bound y))) (p2 (* (lower-bound x) (upper-bound y))) (p3 (* (upper-bound x) (lower-bound y))) (p4 (* (upper-bound x) (upper-bound y)))) (make-interval (min p1 p2 p3 p4) (max p1 p2 p3 p4)))) (define (div-interval x y) (mul-interval x (make-interval (/ 1.0 (upper-bound y)) (/ 1.0 (lower-bound y))))) (define (make-interval a b) (cons a b)) (define (lower-bound a) (min (car a) (cdr a))) (define (upper-bound a) (max (car a) (cdr a))) (define (center i) (/ (+ (lower-bound i) (upper-bound i)) 2)) (define (width i) (/ (- (upper-bound i) (lower-bound i)) 2)) (define (par1 r1 r2) (div-interval (mul-interval r1 r2) (add-interval r1 r2))) (define (par2 r1 r2) (let ((one (make-interval 1 1))) (div-interval one (add-interval (div-interval one r1) (div-interval one r2))))) ;= Answer ================================================================================ (print (par1 (make-interval 100000 100001) (make-interval 100000 100001))) (print (par2 (make-interval 100000 100001) (make-interval 100000 100001)))
false
2d19a9d9e551d97d57fdb95770b856b6de0194aa
bef125b941c10223d93fbf4bd1b6ef52450ed400
/tool/example/allen2007-example4.12.ss
1afce02558a3198738a3268a7582f41a0c158c74
[ "MIT" ]
permissive
flintproject/Flint
7cc2cf62ff6981974be19a04f04f0d4558a7027a
35e9460cbeaa4f781c4737ecd6db8116bd09436d
refs/heads/master
2023-07-06T10:07:20.734112
2022-12-21T09:08:00
2022-12-21T09:08:00
32,972,376
11
6
MIT
2020-09-07T23:22:55
2015-03-27T07:06:48
C++
UTF-8
Scheme
false
false
437
ss
allen2007-example4.12.ss
;; Example 4.12 in E. Allen, Modeling with Itô Stochastic Differential Equations. <https://doi.org/10.1007/978-1-4020-5953-7> (define-model allen2007-example4.12 (variable t :independent) (variable X :random :default 1) (variable W_1 :Wiener) (variable W_2 :Wiener) (eq (differential X) (plus (times (power t 2) X (differential t)) (times t (differential W_1)) (times X (differential W_2)))) )
false
d8ad151d7de8689db742a5314e4d544b6e8dbc25
d9cb7af1bdc28925fd749260d5d643925185b084
/test/2.38.scm
6de53c969dc2586130dd507a250dfc1719967be0
[]
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
407
scm
2.38.scm
(define (run) (let ((t1 '(2 (1 () ()) (3 () ()))) (t2 '(7 (1 (0 () ()) (4 (2 () ()) (6 () ()))) (13 (10 () ()) ())))) (assert (equal? (lookup 2 t1) 2)) (assert (equal? (lookup 3 t1) 3)) (assert (equal? (lookup 7 t1) #f)) (assert (equal? (lookup 10 t2) 10)) (assert (equal? (lookup 11 t2) #f)) (assert (equal? (lookup 2 t2) 2)) "All tests passed!" ) )
false
debc74d73df1d3f2dead74d44a307097edde9146
174072a16ff2cb2cd60a91153376eec6fe98e9d2
/Chap-Three/3-64.scm
193e25d5ea56bd3098497bc00905019d713b8f6a
[]
no_license
Wang-Yann/sicp
0026d506ec192ac240c94a871e28ace7570b5196
245e48fc3ac7bfc00e586f4e928dd0d0c6c982ed
refs/heads/master
2021-01-01T03:50:36.708313
2016-10-11T10:46:37
2016-10-11T10:46:37
57,060,897
1
0
null
null
null
null
UTF-8
Scheme
false
false
257
scm
3-64.scm
(load "3-5-3.scm") (define (stream-limit s delta) (if (< (abs (- (stream-car s)(stream-car (stream-cdr s)))) delta) (stream-car (stream-cdr s)) (stream-limit (stream-cdr s) delta))) (define (sqrt x tolerance) (stream-limit (sqrt-stream x) tolerance))
false
94cb7ff24b1388b17f0e9476d50a02676a2e3019
ac2a3544b88444eabf12b68a9bce08941cd62581
/lib/_match/_match.scm
b0dab2208783e5dd0284f795218c507ac90faa26
[ "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
401
scm
_match.scm
;;;============================================================================ ;;; File: "_match.scm" ;;; Copyright (c) 2008-2019 by Marc Feeley, All Rights Reserved. ;;;============================================================================ ;; Pattern-matching 'match' special form. (##supply-module _match) ;;;============================================================================
false
7608edc5796e94cb5b8a202f145fa9dfbfc4c549
4d204d78919b942b9174bce87efa922ef2f630ed
/jf647/Ch1/1.12.scm
02b83139059cdd5d40935bef88de3d325a83a3f2
[]
no_license
SeaRbSg/SICP
7edf9c621231c0348cf3c7bb69789afde82998e4
2df6ffc672e9cbf57bed4c2ba0fa89e7871e22ed
refs/heads/master
2016-09-06T02:11:30.837100
2015-07-28T21:21:37
2015-07-28T21:21:37
20,213,338
0
2
null
null
null
null
UTF-8
Scheme
false
false
507
scm
1.12.scm
#lang r5rs (define (pascal-triangle-elem row column) (cond ;;; row n has n columns, so if row < column, return 0 ((< row column) 0) ;;; the leftmost and rightmost columns are value 1 ((or (= 0 column) (= row column)) 1) ;;; otherwise add the row above, this column and the one before it (else (+ (pascal-triangle-elem (- row 1) (- column 1)) (pascal-triangle-elem (- row 1) column))) ) ) (display (pascal-triangle-elem 3 1)) (newline) (display (pascal-triangle-elem 4 2)) (newline)
false
8c6d47f2e74428166f5f284eb97d793fd52f49bb
370ebaf71b077579ebfc4d97309ce879f97335f7
/seasonedSchemer/seasonedSchemerCh13.sld
1c8248e74f21d7ee8295cbe41e9eb271af216cc6
[]
no_license
jgonis/sicp
7f14beb5b65890a86892a05ba9e7c59fc8bceb80
fd46c80b98c408e3fd18589072f02ba444d35f53
refs/heads/master
2023-08-17T11:52:23.344606
2023-08-13T22:20:42
2023-08-13T22:20:42
376,708,557
0
0
null
null
null
null
UTF-8
Scheme
false
false
3,800
sld
seasonedSchemerCh13.sld
(include "seasonedSchemerCh11.sld") (define-library (seasoned-schemer ch13) (export lr-intersect lr-intersectall lr-rember rember-beyond-first rember-upto-last) (import (scheme base) (scheme write) (seasoned-schemer ch11)) (begin (define lr-intersect (lambda (set1 set2) (letrec ((member? (lambda (a lat) (letrec ((helper (lambda (l) (cond ((null? l) #f) ((eq? a (car l)) #t) (else (helper (cdr l))))))) (helper lat)))) (i-helper (lambda (set) (cond ((null? set) '()) ((member? (car set) set2) (cons (car set) (i-helper (cdr set)))) (else (i-helper (cdr set))))))) (cond ((null? set2) '()) (else (i-helper set1)))))) (define lr-intersectall (lambda (lset) (letcc hop (letrec ((iall-helper (lambda (lset) (cond ((null? (car lset)) (hop (quote ()))) ((null? (cdr lset)) (car lset)) (else (intersect (car lset) (iall-helper (cdr lset))))))) (member? (lambda (a lat) (cond ((null? lat) #f) ((eq? a (car lat)) #t) (else (member? a (cdr lat)))))) (intersect (lambda (set1 set2) (letrec ((i-helper (lambda (set) (cond ((null? set) '()) ((member? (car set) set2) (cons (car set) (i-helper (cdr set)))) (else (i-helper (cdr set))))))) (cond ((null? set2) (hop '())) (else (i-helper set1))))))) (cond ((null? lset) '()) (else (iall-helper lset))))))) (define lr-rember (lambda (a lat) (letcc hop (letrec ((helper (lambda (lat) (cond ((null? lat) '()) ((eq? a (car lat)) (cdr lat)) (else (cons (car lat) (helper (cdr lat)))))))) (helper lat))))) (define rember-beyond-first (lambda (a lat) (letrec ((helper (lambda (lat) (cond ((or (null? lat) (eq? a (car lat))) '()) (else (cons (car lat) (helper (cdr lat)))))))) (helper lat)))) (define rember-upto-last (lambda (a lat) (letcc skip (letrec ((helper (lambda (lat) (cond ((null? lat) '()) ((eq? (car lat) a) (skip (helper (cdr lat)))) (else (cons (car lat) (helper (cdr lat)))))))) (helper lat)))))))
false
aea046aed78697c791e305b901f421c9fc08de0b
7aeb920de21547a1d9c714b029bbf3a9e7df449e
/scheme/chip-remote/units.scm
eead339486f50a8be45e638da5671d347b9c949d
[ "BSD-2-Clause" ]
permissive
ft/chip-remote
f8ac5a2d7597d24f44ac287836be3422a32283d4
2a64df611214f7e3eb55d4ead76e270351158cdb
refs/heads/master
2023-04-30T08:38:16.483240
2023-01-05T04:01:44
2023-01-05T04:01:44
117,028,633
2
1
null
null
null
null
UTF-8
Scheme
false
false
6,032
scm
units.scm
;; Copyright (c) 2018-2021 chip-remote workers, All rights reserved. ;; ;; Terms for redistribution and use can be found in LICENCE. (define-module (chip-remote units) #:use-module (ice-9 optargs) #:use-module (srfi srfi-9 gnu) #:export (fundamental-unit? make-unit unit? unit-name unit-symbol unit-dim metre gram second ampere kelvin mole candela yotta zetta exa peta tera giga mega kilo hecto deca deci centi milli micro nano pico femto atto zepto yocto make-fundamental-dimension fundamental-dimension? fundamental-dimension-name length mass time electrical-current thermodynamic-temperature amount-of-substance luminous-intensity put-unit value+unit? vu-value vu-unit convert si-combine define-unit)) (define-immutable-record-type <si-prefix> (make-si-prefix name symbol convert-to convert-from combine) si-prefix? (name si-prefix-name) (symbol si-prefix-symbol) ;; Conversion from fundamental unit TO this one. (convert-to si-prefix-convert-to) ;; Conversion FROM this unit to the fundamental one. (convert-from si-prefix-convert-from) (combine si-prefix-combine)) (define-syntax-rule (new-si-prefix name sym factor) (define name (make-si-prefix 'name 'sym (lambda (n) (/ 1 (* n factor))) (lambda (n) (* n factor)) (lambda (s) (symbol-append (si-prefix-symbol name) s))))) (new-si-prefix yotta Y #e1e24) (new-si-prefix zetta Z #e1e21) (new-si-prefix exa E #e1e18) (new-si-prefix peta P #e1e15) (new-si-prefix tera T #e1e12) (new-si-prefix giga G #e1e9) (new-si-prefix mega M #e1e6) (new-si-prefix kilo k #e1e3) (new-si-prefix hecto h #e1e2) (new-si-prefix deca da #e1e1) (new-si-prefix deci d #e1e-1) (new-si-prefix centi c #e1e-2) (new-si-prefix milli m #e1e-3) (new-si-prefix micro µ #e1e-6) (new-si-prefix nano n #e1e-9) (new-si-prefix pico p #e1e-12) (new-si-prefix femto f #e1e-15) (new-si-prefix atto a #e1e-18) (new-si-prefix zepto z #e1e-21) (new-si-prefix yocto y #e1e-24) (define si-prefix-inversion-table (list (cons yotta yocto) (cons zetta zepto) (cons exa atto) (cons peta femto) (cons tera pico) (cons giga nano) (cons mega micro) (cons kilo milli) (cons hecto centi) (cons deca deci))) (define-immutable-record-type <fundamental-dimension> (make-fundamental-dimension name) fundamental-dimension? (name fundamental-dimension-name)) (define-syntax-rule (define-fundamental-dimension name rest ...) (define name (make-fundamental-dimension 'name))) (define (record-fundim-printer dim port) (format port "<fundamental-dimension: ~a>" (fundamental-dimension-name dim))) (set-record-type-printer! <fundamental-dimension> record-fundim-printer) (define-fundamental-dimension length) (define-fundamental-dimension mass) (define-fundamental-dimension time) (define-fundamental-dimension electrical-current) (define-fundamental-dimension thermodynamic-temperature) (define-fundamental-dimension amount-of-substance) (define-fundamental-dimension luminous-intensity) (define-immutable-record-type <unit> (make-unit* name symbol dimension convert-to convert-from) unit? (name unit-name change-unit-name) (symbol unit-symbol change-unit-symbol) (dimension unit-dim) ;; Conversion from fundamental unit TO this one. (convert-to unit-convert-to change-unit-convert-to) ;; Conversion FROM this unit to the fundamental one. (convert-from unit-convert-from change-unit-convert-from)) (define (record-unit-printer unit port) (format port "<unit: ~a, symbol: ~a, ~a>" (unit-name unit) (unit-symbol unit) (unit-dim unit))) (set-record-type-printer! <unit> record-unit-printer) (define* (make-unit name #:key (symbol #f) (dimension #f) (to identity) (from identity)) (make-unit* name symbol dimension to from)) (define-syntax-rule (define-unit name rest ...) (define name (make-unit 'name rest ...))) (define (fundamental-unit? u) (and (fundamental-dimension? (unit-dim u)) (equal? (unit-convert-to u) identity) (equal? (unit-convert-from u) identity))) (define-unit metre #:symbol 'm #:dimension length) (define-unit gram #:symbol 'g #:dimension mass) (define-unit second #:symbol 's #:dimension time) (define-unit ampere #:symbol 'A #:dimension electrical-current) (define-unit kelvin #:symbol 'K #:dimension thermodynamic-temperature) (define-unit mole #:symbol 'mol #:dimension amount-of-substance) (define-unit candela #:symbol 'cd #:dimension luminous-intensity) (define-immutable-record-type <value+unit> (put-unit value unit) value+unit? (value vu-value) (unit vu-unit)) (define (record-vu-printer x port) (format port "<value+unit: ~a ~a>" (vu-value x) (vu-unit x))) (set-record-type-printer! <value+unit> record-vu-printer) (define (convert x unit) (let ((xu (vu-unit x)) (xv (vu-value x))) (put-unit ((unit-convert-to unit) ((unit-convert-from xu) xv)) unit))) (define (si-combine prefix unit) (let ((old-name (unit-name unit)) (prefix-name (si-prefix-name prefix))) (change-unit-symbol (change-unit-name (change-unit-convert-from (change-unit-convert-to unit (lambda (x) ((si-prefix-convert-to prefix) ((unit-convert-to unit) x)))) (lambda (x) ((si-prefix-convert-from prefix) ((unit-convert-from unit) x)))) (if (list? old-name) (cons prefix-name old-name) (list prefix-name old-name))) ((si-prefix-combine prefix) (unit-symbol unit)))))
true
04efe5fcd4dd4c2303e2a626bf04ed64e50fe1c8
542b1510c22ad5c41ba2f896f674c275c34e9195
/srfi.160.f64.scm
a112faf1a933d2844a7964d7dec938b62d9f22aa
[ "MIT" ]
permissive
diamond-lizard/srfi-160
c88b955a7c5e6a5656876a4b9fea452a282b3d24
69b2abad0da573ee22acebb0dc4eefebea72fae1
refs/heads/main
2023-03-03T22:32:31.181967
2020-11-20T06:00:43
2020-11-20T06:00:43
311,722,584
0
1
MIT
2021-01-28T15:50:57
2020-11-10T16:41:12
Scheme
UTF-8
Scheme
false
false
1,815
scm
srfi.160.f64.scm
(module (srfi 160 f64) () (import (scheme)) (import (only (chicken base) open-input-string include define-record-type case-lambda when unless let-values)) (import (only (chicken module) export)) (import (srfi 128)) (import (srfi 160 base)) ;; Constructors (export make-f64vector f64vector f64vector-unfold f64vector-unfold-right f64vector-copy f64vector-reverse-copy f64vector-append f64vector-concatenate f64vector-append-subvectors) ;; Predicates (export f64? f64vector? f64vector-empty? f64vector=) ;; Selectors (export f64vector-ref f64vector-length) ;; Iteration (export f64vector-take f64vector-take-right f64vector-drop f64vector-drop-right f64vector-segment f64vector-fold f64vector-fold-right f64vector-map f64vector-map! f64vector-for-each f64vector-count f64vector-cumulate) ;; Searching (export f64vector-take-while f64vector-take-while-right f64vector-drop-while f64vector-drop-while-right f64vector-index f64vector-index-right f64vector-skip f64vector-skip-right f64vector-any f64vector-every f64vector-partition f64vector-filter f64vector-remove) ;; Mutators (export f64vector-set! f64vector-swap! f64vector-fill! f64vector-reverse! f64vector-copy! f64vector-reverse-copy! f64vector-unfold! f64vector-unfold-right!) ;; Conversion (export f64vector->list reverse-f64vector->list reverse-list->f64vector list->f64vector f64vector->vector vector->f64vector) ;; Misc (export make-f64vector-generator f64vector-comparator write-f64vector) (include "srfi/160/f64-impl.scm") (define (eof-object) (let* ((p (open-input-string "")) (e (read p))) (close-input-port p) e)) )
false
3c7bdef4560173379eebfe18abfdc78fb0eec997
3604661d960fac0f108f260525b90b0afc57ce55
/SICP-solutions/3.81-rand-order-ans.scm
37c6be1681a74fa898b7d66ff045d423718f8083
[]
no_license
rythmE/SICP-solutions
b58a789f9cc90f10681183c8807fcc6a09837138
7386aa8188b51b3d28a663958b807dfaf4ee0c92
refs/heads/master
2021-01-13T08:09:23.217285
2016-09-27T11:33:11
2016-09-27T11:33:11
69,350,592
0
0
null
null
null
null
UTF-8
Scheme
false
false
1,513
scm
3.81-rand-order-ans.scm
; 参考答案,来自https://wizardbook.wordpress.com/2010/12/23/exercise-3-81/ ;Some of the utilities for handling random numbers (define initial-seed 317) (define (rand-update) (random (expt 2 31))) (define (random-init seed) (random-seed seed) (rand-update)) ;Next, generating an infinite random-stream from a seed value (define (rand seed requests) (define (rand-iter randoms actions) (if (stream-null? actions) null (let ((request (stream-car actions))) (cond ((eq? 'generate request) (cons-stream (stream-car randoms) (rand-iter (stream-cdr randoms) (stream-cdr actions)))) ((eq? 'reset request) (let ((new-randoms (random-stream (random-init seed)))) (cons-stream (stream-car new-randoms) (rand-iter (stream-cdr new-randoms) (stream-cdr (stream-cdr actions)))))) (else (error "RAND -- unknown request" request)))))) (rand-iter (random-stream (random-init seed)) requests)) ; (show-stream (rand (list->stream (list 'generate 'generate 'generate))) 3) ; 1423959383 ; 653588942 ; 1694290797 ; done ; (show-stream (rand (list->stream ; (list 'generate 'generate 'generate 'reset ; 'generate 'generate 'generate))) 6) ; 1423959383 ; 653588942 ; 1694290797 ; 1423959383 ; 653588942 ; 1694290797 ; done
false
d5c8cb9cabef2fe7db485efef6dd8bcf23b65e7f
4b480cab3426c89e3e49554d05d1b36aad8aeef4
/chapter-03/ex3.59a-falsetru.scm
67eb42ea8c8db2c397d04c107f9c2e41d963c7c8
[]
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
659
scm
ex3.59a-falsetru.scm
#lang racket (require "stream-base-falsetru.scm") (provide integrate-series) (define (integers-starting-from n) (cons-stream n (integers-starting-from (+ n 1)))) (define integers (integers-starting-from 1)) (define (reciprocal x) (/ 1 x)) (define (integrate-series s) (stream-map * s (stream-map reciprocal integers))) (require rackunit) (require rackunit/text-ui) (define ex3.59a-tests (test-suite "Test for ex3.59a" (test-case "" (define s (integrate-series (cons-stream 9 (cons-stream 8 (cons-stream 7 the-empty-stream))))) (check-equal? (stream-take s 3) '(9 4 7/3)) ) )) (run-tests ex3.59a-tests)
false
9d78435b152f33b68eb4608ad1e5934eb6aac269
a4a6e51f015e7968b7760d089bbe2c4cf57d7b4d
/ok-lazy-fib.scm
2d108da04df8b114b3a633d7d3e240cbbeb800de
[]
no_license
jpt4/womb
10bcc0c6cee0a6eefb6656518470ad5e64404942
a89cb5733e1d3a1b0a13ec583c9c33309b5c59da
refs/heads/master
2023-07-25T17:16:44.571894
2023-07-07T19:35:31
2023-07-07T19:35:31
37,166,949
0
2
null
null
null
null
UTF-8
Scheme
false
false
1,948
scm
ok-lazy-fib.scm
;http://okmij.org/ftp/Scheme/lazy-Fibonacci.txt ; Give the n-th element of a lazy list (define (n-th L n) (let ((L (force L))) (if (positive? n) (n-th (cdr L) (- n 1)) (car L)))) (define (pointwise f L1 L2) (let ((L1 (force L1)) (L2 (force L2))) (cond ((null? L1) '()) ((null? L2) '()) (else (cons (f (car L1) (car L2)) (delay (pointwise f (cdr L1) (cdr L2)))))))) (define fibs (cons 1 (cons 1 (delay (pointwise + fibs (cdr fibs)))))) ;what I didn't read ; Lazy cons (define-macro (l-cons x y) `(cons ,x (delay ,y))) ; Eager null? car and cdr ; Note, Gambit's null? car and cdr force their arguments ; by default. The following macros can be regular ; functions as well. (define-macro (e-null? x) `(null? (force ,x))) (define-macro (e-car x) `(car (force ,x))) (define-macro (e-cdr x) `(cdr (force ,x))) (define (l-pointwise f L1 L2) (cond ((e-null? L1) '()) ((e-null? L2) '()) (else (l-cons (f (e-car L1) (e-car L2)) (l-pointwise f (e-cdr L1) (e-cdr L2)))))) (define l-fibs (l-cons 1 (l-cons 1 (l-pointwise + l-fibs (e-cdr l-fibs))))) (define (l-n-th L n) (if (positive? n) (l-n-th (e-cdr L) (- n 1)) (e-car L))) ;gavwhela - correcting for R5/6RS car/cdr non-deafault argument forcing (define-syntax gl-cons (syntax-rules () ((gl-cons x y) (cons (delay x) (delay y))))) (define-syntax ge-car (syntax-rules () ((ge-car x) (force (car x))))) (define-syntax ge-cdr (syntax-rules () ((ge-cdr x) (force (cdr x))))) (define (gl-pointwise f L1 L2) (cond ((null? L1) '()) ((null? L2) '()) (else (gl-cons (f (ge-car L1) (ge-car L2)) (gl-pointwise f (ge-cdr L1) (ge-cdr L2)))))) (define gl-fibs (gl-cons 1 (gl-cons 1 (gl-pointwise + gl-fibs (ge-cdr gl-fibs))))) (define (gl-n-th L n) (if (positive? n) (gl-n-th (ge-cdr L) (- n 1)) (ge-car L)))
true
d966e5a1c2ce6eca172893ba62910027d481ad1f
648776d3a0d9a8ca036acaf6f2f7a60dcdb45877
/queries/prisma/highlights.scm
cfdc3a6686a9a1f2b0101069be22076b3e200ab3
[ "Apache-2.0" ]
permissive
nvim-treesitter/nvim-treesitter
4c3c55cbe6ff73debcfaecb9b7a0d42d984be3e6
f8c2825220bff70919b527ee68fe44e7b1dae4b2
refs/heads/master
2023-08-31T20:04:23.790698
2023-08-31T09:28:16
2023-08-31T18:19:23
256,786,531
7,890
980
Apache-2.0
2023-09-14T18:07:03
2020-04-18T15:24:10
Scheme
UTF-8
Scheme
false
false
436
scm
highlights.scm
(variable) @variable [ "datasource" "enum" "generator" "model" "type" "view" ] @keyword (comment) @comment @spell (developer_comment) @comment.documentation @spell [ (attribute) (call_expression) ] @function (arguments) @property (column_type) @type (enumeral) @constant (column_declaration (identifier) @variable) (string) @string [ "(" ")" "[" "]" "{" "}" ] @punctuation.bracket [ "=" "@" ] @operator
false
3cf0eb48a04b61acbe8b12039a5034bf4c1e1dbd
943e73b33b7bc61fee44808cbd18f91c7ed1db7a
/scripts/setversion
af580cde8217acea538679a02f5289d01a289735
[ "BSD-3-Clause" ]
permissive
opt9/chicken-scheme
a631d3fb455c61312e0c9d30d791c78a6d99a7f6
1eb14684c26b7c2250ca9b944c6b671cb62cafbc
refs/heads/master
2020-03-09T15:41:06.499607
2009-07-25T23:49:53
2009-07-25T23:49:53
null
0
0
null
null
null
null
UTF-8
Scheme
false
false
1,798
setversion
#!/bin/sh #| setversion - Bump version-number -*- Scheme -*- exec csi -s "$0" "$@" |# (use srfi-1 utils posix) (define buildversion (->string (car (read-file "buildversion")))) (define buildbinaryversion (car (read-file "buildbinaryversion"))) (define files '("README" "manual/The User's Manual")) (define-syntax rx (syntax-rules () ((_ r) (force (delay (regexp r)))))) (define (patch which rx subst) (cond ((and (list? which) (= 2 (length which))) (let ((from (car which)) (to (cadr which))) (print "patching " from " ...") (with-output-to-file to (lambda () (with-input-from-file from (lambda () (let loop () (let ((ln (read-line))) (unless (eof-object? ln) (write-line (string-substitute rx subst ln #t)) (loop) ) ) ) ) binary:) ) binary:))) (else (let ((tmp (create-temporary-file))) (patch (list which tmp) rx subst) (system* "mv ~S ~S" tmp which) ) ) ) ) (define (parse-version v) (string-match (rx "(\\d+)\\.(\\d+)\\.(\\d+)(.*)") v) ) (define (main args) (cond ((member "-set" args) => (lambda (a) (set! buildversion (cadr a))) ) ((not (member "-noinc" args)) (let* ((v (parse-version buildversion)) (maj (cadr v)) (min (caddr v)) (pl (cadddr v)) (huh (car (cddddr v)))) (set! buildversion (conc maj "." min "." (add1 (string->number pl)) huh)) ) ) ) (with-output-to-file "buildversion" (cut display buildversion) binary:) (with-output-to-file "version.scm" (lambda () (write `(define-constant +build-version+ ,buildversion)) (newline) ) binary:) (system* "cat version.scm") (let ([vstr (sprintf "version ~A" buildversion)]) (for-each (cut patch <> (rx "version [0-9][-.0-9a-zA-Z]+") vstr) files) ) 0) (main (command-line-arguments))
true
90a8dab172446ef0a836eded9248e0f147c2ee99
d8bdd07d7fff442a028ca9edbb4d66660621442d
/scam/tests/10-scheme/repl/interaction.scm
2da9347fb1f3ae7c4ca2ff3fe090ead0d52e4f57
[]
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
200
scm
interaction.scm
(import (scheme repl) (only (scam misc) environment?) (test narc)) (narc-label "Interaction Environment") (narc-expect (#t (environment? (interaction-environment)))) (narc-report)
false
3a5efa254f3fe71ab873254303fade9aafe4ed11
ec5b4a92882f80b3f62eac8cbd059fb1f000cfd9
/higher-order/!tests/lattice.ss
730cbb4e55fea4aef6da660e0fbdaec5cb0ba573
[]
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
5,769
ss
lattice.ss
; Here is my version of the lattice benchmark. Modified slightly from a version ; that I got from Suresh Jagannathan and Andrew Wright. It runs under Scheme->C, ; Gambit-C, Bigloo, Chez, and Stalin. To run it under a specific ; <implementation>, select the stuff between ;;; begin <implementation> and ; ;;; end <implementation> and delete all of the other stuff between other ; ;;; begin and ;;; end comments. ; Jeff (http://www.neci.nj.nec.com/homepages/qobi) ; ;;;; begin Scheme->C ;(define (panic s) (error 'panic s)) ;;;; end Scheme->C ;;;; begin Gambit-C ;(define (panic s) (error s)) ;;;; end Gambit-C ;;;; begin Bigloo ;(define (panic s) (error s 'panic 'panic)) ;;;; end Bigloo ;;; begin Chez ;(define (panic s) (error 'panic s)) ;;; end Chez (define lattice (lambda () (let ((l2 (make-lattice '(low high) (lambda (lhs rhs) (if (eq? lhs 'low) (if (eq? rhs 'low) 'equal (if (eq? rhs 'high) 'less 'error)) (if (eq? lhs 'high) (if (eq? rhs 'low) 'more (if (eq? rhs 'high) 'equal 'error)) 'error)))))) (let ((l3 (maps l2 l2))) (let ((l4 (maps l3 l3))) (cons (count-maps l2 l2) (cons (count-maps l3 l3) (cons (count-maps l2 l3) (cons (count-maps l3 l2) (cons (count-maps l4 l4) '())))))))))) ; Given a comparison routine that returns one of ; less ; more ; equal ; uncomparable ; return a new comparison routine that applies to sequences. (define lexico (lambda (base) (letrec ([lex-first (lambda (lhs rhs) (if (null? lhs) 'equal (let ([probe (base (car lhs) (car rhs))]) (if (if (eq? probe 'less) #t (eq? probe 'more)) (lex-fixed probe (cdr lhs) (cdr rhs)) (if (eq? probe 'equal) (lex-first (cdr lhs) (cdr rhs)) (if (eq? probe 'uncomparable) 'uncomparable 'undefined))))))] [lex-fixed (lambda (fixed lhs rhs) (letrec ([check (lambda (lhs rhs) (if (null? lhs) fixed (let ([probe (base (car lhs) (car rhs))]) (if (if (eq? probe 'equal) #t (eq? probe fixed)) (check (cdr lhs) (cdr rhs)) 'uncomparable))))]) (check lhs rhs)))]) lex-first))) (define make-lattice (lambda (elem-list cmp-func) (cons elem-list cmp-func))) (define lattice->elements car) (define lattice->cmp cdr) ; Select elements of a list which pass some test. (define zulu-select (lambda (test lst) (letrec ([select-a (lambda (ac lst) (if (null? lst) (reverse ac) (select-a (let ((head (car lst))) (if (test head) (cons head ac) ac)) (cdr lst))))]) (select-a '() lst)))) (define reverse (letrec ((rev (lambda (ls answ) (if (null? ls) answ (rev (cdr ls) (cons (car ls) answ)))))) (lambda (ls) (rev ls '())))) (define append (lambda (ls1 ls2) (letrec ([append (lambda (ls1) (if (null? ls1) ls2 (cons (car ls1) (append (cdr ls1)))))]) (append ls1)))) (define map (lambda (f ls) (letrec ([map (lambda (ls) (if (null? ls) '() (cons (f (car ls)) (map (cdr ls)))))]) (map ls)))) ; Select elements of a list which pass some test and map a function ; over the result. Note, only efficiency prevents this from being the ; composition of select and map. (define select-map (lambda (test func lst) (letrec ([select-a (lambda (ac lst) (if (null? lst) (reverse ac) (select-a (let ((head (car lst))) (if (test head) (cons (func head) ac) ac)) (cdr lst))))]) (select-a '() lst)))) ; This version of map-and tail-recurses on the last test. (define map-and (lambda (proc lst) (if (null? lst) #t (letrec ((drudge (lambda (lst) (let ((rest (cdr lst))) (if (null? rest) (proc (car lst)) (if (proc (car lst)) (drudge rest) #f)))))) (drudge lst))))) (define maps-1 (lambda (source target pas new) (let ((scmp (lattice->cmp source)) (tcmp (lattice->cmp target))) (let ((less (select-map (lambda (p) (eq? 'less (scmp (car p) new))) cdr pas)) (more (select-map (lambda (p) (eq? 'more (scmp (car p) new))) cdr pas))) (zulu-select (lambda (t) (if (map-and (lambda (t2) (let ([tcmpt2 (tcmp t2 t)]) (if (eq? tcmpt2 'less) #t (eq? tcmpt2 'equal)))) less) (map-and (lambda (t2) (let ([tcmpt2 (tcmp t2 t)]) (if (eq? tcmpt2 'more) #t (eq? tcmpt2 'equal)))) more) #f)) (lattice->elements target)))))) (define maps-rest (lambda (source target pas rest to-1 to-collect) (if (null? rest) (to-1 pas) (let ((next (car rest)) (rest (cdr rest))) (to-collect (map (lambda (x) (maps-rest source target (cons (cons next x) pas) rest to-1 to-collect)) (maps-1 source target pas next))))))) (define maps (lambda (source target) (make-lattice (maps-rest source target '() (lattice->elements source) (lambda (x) (cons (map cdr x) '())) (lambda (x) (letrec ([loop (lambda (x) (if (null? x) '() (append (car x) (loop (cdr x)))))]) (loop x)))) (lexico (lattice->cmp target))))) (define print-frequency 10000) (define count-maps (lambda (source target) (maps-rest source target '() (lattice->elements source) (lambda (x) 1) (lambda (x) (letrec ([loop (lambda (x c) (if (null? x) c (loop (cdr x) (+ (car x) c))))]) (loop x 0)))))) '(lattice) ;;; Chez 50.14 seconds ~ 0.84 mins ;;; Petite 394.69 seconds ~ 6.58 mins ;;; Gambit-C 1575.33 seconds ~ 26.26 mins
false
509cb5d6e77cd766f950e80f9b7bb1b222c51a73
370b378f48cb3ddd94297240ceb49ff4506bc122
/exercises/1.1.scm
f72e0acfb9278e3fb8c9843f920f27bf62c90434
[]
no_license
valvallow/PAIP
7c0c0702b8c601f4e706b02eea9615d8fdeb7131
ee0a0bd445ef52c5fe38488533fd59a3eed287f0
refs/heads/master
2021-01-20T06:56:48.999920
2010-11-26T08:09:00
2010-11-26T08:09:00
798,236
0
0
null
null
null
null
UTF-8
Scheme
false
false
448
scm
1.1.scm
;; (last-name '((Rex Morgan MD)(Morton Downey Jr))) -> (Morgan Downey) (use gauche.parameter) (define *prefs* (make-parameter '(MD Jr))) (define (last-name name) (let1 name (reverse name) (let rec ((name name)) (if (member (car name)(*prefs*)) (rec (cdr name)) (car name))))) (last-name (car '((Rex Morgan MD)(Morton Downey Jr)))) ;; Morgan (map last-name '((Rex Morgan MD)(Morton Downey Jr))) ;; (Morgan Downey)
false
494021594e7673e9fe2910ae6835dfe5f4c8c29a
c42881403649d482457c3629e8473ca575e9b27b
/src/kahua/test/util.scm
1a5a51f717adfe9cec49d455262aab4aa68e7784
[ "BSD-2-Clause", "BSD-3-Clause" ]
permissive
kahua/Kahua
9bb11e93effc5e3b6f696fff12079044239f5c26
7ed95a4f64d1b98564a6148d2ee1758dbfa4f309
refs/heads/master
2022-09-29T11:45:11.787420
2022-08-26T06:30:15
2022-08-26T06:30:15
4,110,786
19
5
null
2015-02-22T00:23:06
2012-04-23T08:02:03
Scheme
UTF-8
Scheme
false
false
822
scm
util.scm
;; ;; Utilities to implement test script. ;; ;; Copyright (c) 2008 Kahua Project, All rights reserved. (define-module kahua.test.util (use gauche.process) (export kahua:invoke&wait)) (select-module kahua.test.util) (define (kahua:invoke&wait cmd&args . args) (let-keywords* args ((prompt #f) (reader (if (string? prompt) (lambda (in) (read-block (string-size prompt) in)) read-line))) (let* ((p (run-process cmd&args :input :pipe :output :pipe)) (in (process-output p)) (omode (port-buffering in))) (set! (port-buffering in) :full) (unwind-protect (values p (string-incomplete->complete (reader in))) (set! (port-buffering in) omode))))) (provide "kahua/test/util")
false
b31f4f9dc9db28385bfca1526e81d6a6cd85a839
46244bb6af145cb393846505f37bf576a8396aa0
/eopl/ch2/2.5.scm
cb9422cf9a581e2bee8807307c99a77efc418c2d
[]
no_license
aoeuidht/homework
c4fabfb5f45dbef0874e9732c7d026a7f00e13dc
49fb2a2f8a78227589da3e5ec82ea7844b36e0e7
refs/heads/master
2022-10-28T06:42:04.343618
2022-10-15T15:52:06
2022-10-15T15:52:06
18,726,877
4
3
null
null
null
null
UTF-8
Scheme
false
false
920
scm
2.5.scm
#lang racket #| We can use any data structure for representing environments, if we can distinguish empty environments from non-empty ones, and in which one can extract the pieces of a non-empty environment. Implement environments using a representation in which the empty environment is represented as the empty list, and in which extend-env builds an environment that looks like ... This is called an a-list or association-list representation. |# (define empty-env '()) (define (empty-env? env) (and (list? env) (null? env))) (define (extend-env var val env) (cons (cons var val) env)) (define (apply-env env var) (if (empty-env? env) (report-no-binding-found) (if (eq? (car (car env)) var) (cdr (car env)) (apply-env (cdr env) var))) ) (define report-no-binding-found (lambda (search-var) (eopl:error ’apply-env "No binding for ~s" search-var)))
false
9a0270b8cba7f5b11067d8449c66312f8946d2da
e42c980538d5315b9cca17460c90d9179cc6fd3a
/scm/xlate3.scm
36bb84a4d10736cc9aef57c7821660872202a66a
[]
no_license
KenDickey/Scheme2Smalltalk-Translator
c4415f2053932a2c83b59ac9a554097836c55873
9ccd4e45fb386f99d2e62fc769f78241fbe29c77
refs/heads/master
2020-12-24T19:46:30.348021
2016-05-13T23:12:06
2016-05-13T23:12:06
58,775,118
1
0
null
null
null
null
UTF-8
Scheme
false
false
13,782
scm
xlate3.scm
;; xlate part 3 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; DESTRUCTURE, PREDICATE HELPERS ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (define (make-list-prefix-predicate sym) (lambda (exp) (and (pair? exp) (eq? (car exp) sym)))) (define quote? (make-list-prefix-predicate 'quote )) (define lambda? (make-list-prefix-predicate 'lambda )) (define case-lambda? (make-list-prefix-predicate 'case-lambda )) (define set!? (make-list-prefix-predicate 'set! )) (define let? (make-list-prefix-predicate 'let )) (define let*? (make-list-prefix-predicate 'let* )) (define letrec? (make-list-prefix-predicate 'letrec )) (define dynamic-let? (make-list-prefix-predicate 'dynamic-let )) (define dynamic-define? (make-list-prefix-predicate 'dynamic-define )) (define dynamic-ref? (make-list-prefix-predicate 'dynamic-ref )) (define dynamic-ref-with-default? (make-list-prefix-predicate 'dynamic-ref-with-default )) (define dynamic-set!? (make-list-prefix-predicate 'dynamic-set! )) (define quasiquote? (make-list-prefix-predicate 'quasiquote )) (define unquote? (make-list-prefix-predicate 'unquote )) (define unquote-splicing? (make-list-prefix-predicate 'unquote-splicing )) ;; (let name ((..)..) body..) (define (named-let? exp) (and (let? exp) (symbol? (cadr exp)))) ;;(define do? ;; (make-list-prefix-predicate 'do )) ;;(define cond? ;; (make-list-prefix-predicate 'cond )) (define if? (make-list-prefix-predicate 'if )) (define define? (make-list-prefix-predicate 'define )) (define begin? (make-list-prefix-predicate 'begin )) (define values? (make-list-prefix-predicate 'values )) (define magic? (make-list-prefix-predicate ': )) (define smalltalk-ref? (make-list-prefix-predicate '$ )) (define (empty-list? thing) (eq? thing '() )) (define keyword? (lambda (x) (member x '(quote lambda if begin letrec define)))) (define literal? (lambda (exp) (or (number? exp) (boolean? exp) (quote? exp)))) (define variable? (lambda (exp) (and (symbol? exp) (not (keyword? exp))))) (define same-variable? eq?) (define lambda-formals cadr) (define lambda-body cddr) (define set!-target cadr) (define set!-value-exp caddr) (define application? (lambda (exp) (and (pair? exp) (not (keyword? (car exp)))))) (define operator car) (define operands cdr) (define if-predicate cadr) (define if-consequent caddr) (define if-alternate cadddr) (define (if-has-alternate? exp) ;; (if a b c) (not (null? (cdddr exp)))) (define begin-subexpressions cdr) (define (definition-name form) (let ((pattern (cadr form))) (if (pair? pattern) (car pattern) pattern))) (define (definition-body form) (let ((pattern (cadr form))) (if (pair? pattern) `(lambda ,(cdr pattern) ,@(cddr form)) (caddr form)))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; DESUGAR SYNTAX (Scheme -> simplified Scheme) ;;;;;;;;;;;;;;;;;; (define (map* fn . list) ; A map which accepts dotted lists (arg lists (cond ; must be "isomorph" ((null? (car list)) '()) ((pair? (car list)) (cons (apply fn (map car list)) (apply map* fn (map cdr list)))) (else (apply fn list)))) ;; Bootstrap macros before we have macros. (define (desugar exp qq-level) (cond ((or (number? exp) (boolean? exp) (string? exp) (char? exp)) exp) ((symbol? exp) exp) ((quote? exp) exp) ((eq? exp '()) exp) ((lambda? exp) `(lambda ,(lambda-formals exp) ,(desugar-body (lambda-body exp) qq-level)) ) ((define? exp) `(define ,(definition-name exp) ,(desugar (definition-body exp) qq-level)) ) ((set!? exp) `(set! ,(set!-target exp) ,(desugar (set!-value-exp exp) qq-level)) ) ((begin? exp) (desugar-body (begin-subexpressions exp) qq-level) ) ((if? exp) `(if ,@(map (lambda (e) (desugar e qq-level)) (cdr exp))) ) ((named-let? exp) `(let ,(let-name exp) ,(map (lambda (binding) `(,(let-formal binding) ,(desugar (let-init binding) qq-level)) ) (let-bindings exp)) ,(desugar-body (let-body exp) qq-level)) ) ((memq (car exp) '(let let* letrec)) ;; same form `(,(car exp) ,(map (lambda (binding) `(,(let-formal binding) ,(desugar (let-init binding) qq-level)) ) (let-bindings exp)) ,(desugar-body (let-body exp) qq-level)) ) ((quasiquote? exp) (if (zero? qq-level) (rewrite-quasiquote exp qq-level) (desugar (rewrite exp) qq-level)) ) ((sugar? exp) (desugar (rewrite exp) qq-level) ) (else ;; application (map* (lambda (e) (desugar e qq-level)) exp)) ) ) ;; (a ,(+ 1 2) ,@(map abs (-4 5)) 6) ;;-> (cons 'a ;; (cons (+ 1 2) ;; (set-last-pair! (map abs '(- 4 5)) ;; (cons 6 '())))) ;;=> (a 3 4 5 6) ;; ;; (a `(b ,(+ 1 2) `,(foo ,(+ 1 3) d) e) f) ;; -> (a `(b ,(+ 1 2) ,(foo 4 d) e) f) ;; copy the list [scheme48 quoted lists are immutable] (define (set-last-pair list thing) (cond ((null? list) thing) ((not (pair? list)) (error "set-last-pair: expected a list" list)) (else ;; at least 1 pair in list (let loop ( (result '()) (last-pair '()) (old list) ) (if (or (null? old) (not (pair? old))) (begin (set-cdr! last-pair thing) result) (let ( (new (cons (car old) '())) ) (if (null? last-pair) (loop new new (cdr old)) (begin (set-cdr! last-pair new) (loop result new (cdr old))))) ) ) )) ) ;; 'quasiquote, 'quote and 'unquote-splicing should not be ;; used directly in uasiquote-templates (define %quasiquote ''quasiquote) (define %unquote ''unquote) (define %unquote-splicing ''unquote-splicing) (define (rewrite-quasiquote exp level) ;; (quasiquote <whatever>) (if (= level 0) (if (vector? (cadr exp)) `(list->vector ,(build-quasi-list (vector->list (cadr exp)) (+ level 1))) (build-quasi-list (cadr exp) (+ level 1))) `(cons ,%quasiquote (cons ,(build-quasi-list (cadr exp) (+ level 1)) '() )) ) ) ;; NB: assumes set-last-pair returns original list (define (build-quasi-list thing level) (cond ((not (pair? thing)) `',thing) ((pair? (car thing)) (let ( (sublist (car thing)) ) (cond ((quasiquote? sublist) `(cons ,(rewrite-quasiquote sublist level) ,(build-quasi-list (cdr thing) level)) ) ((unquote? sublist) (if (= level 1) ;; (zero? (- level 1)) `(cons ,(desugar (cadr sublist) (- level 1)) ,(build-quasi-list (cdr thing) level)) `(cons ,(build-quasi-list sublist level);;NB not level-1 ,(build-quasi-list (cdr thing) level)) )) ((unquote-splicing? sublist) (if (= level 1) ;; (zero? (- level 1)) `(set-last-pair ,(desugar (cadr sublist) (- level 1)) ,(build-quasi-list (cdr thing) level)) `(cons ,(build-quasi-list sublist (- level 1)) ,(build-quasi-list (cdr thing) level)) )) (else `(cons ,(build-quasi-list sublist level) ,(build-quasi-list (cdr thing) level)) )) ;; end inner-cond )) ((eq? (car thing) 'unquote) (if (= level 1) (if (pair? (cdr thing)) (desugar (cadr thing) (- level 1)) (cdr thing)) `(cons ,%unquote (cons ,(build-quasi-list (cadr thing) (- level 1)) '() )) )) (else `(cons ',(car thing) ,(build-quasi-list (cdr thing) level)) ) )) (define (desugar-body body qq-level) (let loop ( (form (car body)) (forms (cdr body)) (defines '()) (others '()) ) (cond ((define? form) (if (null? forms) (error "expected body" body) (loop (car forms) (cdr forms) (cons form defines) others)) ) ((null? forms) (if (null? defines) ;; just process the body (let ( (body (map (lambda (exp) (desugar exp qq-level)) body)) ) (if (null? (cdr body)) (car body) `(begin ,@body)) ) ;; else internal defines -> letrec `(letrec ,(map (lambda (def) (list (definition-name def) (desugar (definition-body def) qq-level))) (reverse defines)) ,(desugar-body (reverse (cons form others)) qq-level)) )) (else (loop (car forms) (cdr forms) defines (cons form others))) ) ) ) ;; "Syntactic sugar causes cancer of the semicolon." Alan Perlis. (define (SUGAR? exp) (and (pair? exp) (member (car exp) '(and or cond do case delay string vector)))) ;; list ;; let let* handled by xlate, above. (define unspecified "Unspecified") ;; REWRITE (define (REWRITE exp) (cond ((not (pair? exp)) exp) ((eq? (car exp) 'and) (rewrite-and exp)) ((eq? (car exp) 'or) (rewrite-or exp)) ((eq? (car exp) 'cond) (rewrite-cond exp)) ((eq? (car exp) 'do) (rewrite-do exp)) ((eq? (car exp) 'case) (rewrite-case exp)) ((eq? (car exp) 'delay) (rewrite-delay exp)) ;; ((eq? (car exp) 'list) (rewrite-list exp)) ((eq? (car exp) 'string) (rewrite-string exp)) ((eq? (car exp) 'vector) (rewrite-vector exp)) ;; FIXME: other nary procs? ('+' et al) (else exp))) ;; AND (define (rewrite-and exp) (let ( (conjuncts (cdr exp)) ) (cond ;; (and) -> #t ((null? conjuncts) #t) ;; (and <test>) -> <test> ((null? (cdr conjuncts)) (car conjuncts)) ;; (and <test1> <test2> ...) ;;-> (if <test1> (and <test2> ...) #f) (else `(if ,(car conjuncts) (and ,@(cdr conjuncts)) #f))) ) ) ;; OR (define (rewrite-or exp) (let ((disjuncts (cdr exp))) (cond ;; (or) -> #f ((null? disjuncts) `#f) ;; (or <test>) -> <test> ((null? (cdr disjuncts)) (car disjuncts)) ;; ((or <test1> <test2> ...) ;;-> (let ( (temp <test1>) ) ;; (if temp temp (or <test2> ...)) (else (let ( (temp (gensym "temp")) (test (car disjuncts)) (others (cdr disjuncts)) ) `(let ( (,temp ,test) ) (if ,temp ,temp (or ,@others)))))) ) ) ;; COND (define (rewrite-cond exp) (let ( (clauses (cdr exp)) ) (cond ;; (cond) ((null? clauses) `',unspecified ) ;; cond (<test>) <clause> ...) ;;-> (or <test> (cond <clause> ...)) ((null? (cdar clauses)) `(or ,(caar clauses) (cond ,@(cdr clauses))) ) ;; (cond (<test> => <recipient>) <clause> ...) ;;=> ;; (let ( (result <test>) ) ;; (if result ;; (<recipient> result) ;; (cond <clause> ...)) ((eq? (cadar clauses) '=>) (let ( (result (gensym 'result)) (test (caar clauses)) (recipient (caddar clauses)) (others (cdr clauses)) ) `(let ( (,result ,test) ) (if ,result (,recipient ,result) (cond ,@others)))) ) ;; (cond (else <exp1> <exp2> ...)) ;;-> (begin <exp1> <exp2> ...) ((eq? (caar clauses) 'else) `(begin ,@(cdar clauses)) ) ;; (cond (<test> <exp1> <exp2> ...) <clause> ...) ;;-> (if <test> (begin <exp1> <exp2> ...) (cond <clause> ...)) (else `(if ,(caar clauses) (begin ,@(cdar clauses)) (cond ,@(cdr clauses))))))) ;; DO ; (do ( (var init step) ..) ; (exit-test exp ..) ; command..) ;-> ; (let <gensym> ((var init)..) ; (if exit-test ; (begin exp..) ; (begin ; command.. ; (<gensym> step..)))) (define (rewrite-do exp) (let ( (loop-name (gensym "do-loop")) (locals (cadr exp)) (exits (caddr exp)) (commands (cdddr exp)) ) (let ( (var-inits (map (lambda (vis) (list (car vis) (cadr vis))) locals)) (steps (map (lambda (vis) (if (null? (cddr vis)) (car vis) (caddr vis))) locals)) (test (car exits)) (exps (cdr exits)) ) `(let ,loop-name ,var-inits (if ,test (begin ,@exps) (begin ,@commands (,loop-name ,@steps)))) ) ) ) ;; CASE (define (rewrite-case exp) (let ( (clauses (cdr exp)) ) (cond ((null? clauses) `',unspecified ) ; (case <key>) -> <key> ((null? (cdr clauses)) (car clauses) ) ; (case <key> (else <exp1> <exp2> ...)) ; -> (begin <key> <exp1> <exp2> ...) ((eq? (caadr clauses) 'else) `(begin ,(car clauses) ,@(cdadr clauses)) ) ; (case <key> ((<datum> ...) <exp1> <exp2> ...) <clause> ...) ;=> ; (let ( (key <key>) ) ; (if (memv key '(<datum> ...)) ; (begin <exp1> <exp2> ...) ; (case key <clause> ...))) (else (let ( (key-name (gensym 'key)) (key (car clauses)) (datums (caadr clauses)) (exps (cdadr clauses)) (others (cddr clauses)) ) `(let ( (,key-name ,key) ) (if (memv ,key-name ',datums) (begin ,@exps) (case ,key-name ,@others)))))) ) ) ;; DELAY (define (rewrite-delay exp) `(make-promise (lambda () ,(cadr exp)))) ;; The following are needed until we get nary up.. ;; LIST (define (rewrite-list exp) (if (null? (cdr exp)) ''() `(cons ,(cadr exp) (list ,@(cddr exp))))) (define (rewrite-string exp) `(list->string (list ,@(cdr exp)))) (define (rewrite-vector exp) `(list->vector (list ,@(cdr exp)))) ;;; --- E O F --- ;;;
false
03a5f68377cfb1065a6b9cb5a9bfa5436d0288a6
3508dcd12d0d69fec4d30c50334f8deb24f376eb
/tests/runtime/test-promise.scm
bfa6bce7fd0a33291cf1dd084fc958b6c44d4f66
[]
no_license
barak/mit-scheme
be625081e92c2c74590f6b5502f5ae6bc95aa492
56e1a12439628e4424b8c3ce2a3118449db509ab
refs/heads/master
2023-01-24T11:03:23.447076
2022-09-11T06:10:46
2022-09-11T06:10:46
12,487,054
12
1
null
null
null
null
UTF-8
Scheme
false
false
5,501
scm
test-promise.scm
#| -*-Scheme-*- Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022 Massachusetts Institute of Technology This file is part of MIT/GNU Scheme. MIT/GNU Scheme is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. MIT/GNU Scheme is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with MIT/GNU Scheme; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. |# ;;;; Test of promises (declare (usual-integrations)) (define-test 'delay-force-loop (lambda () (assert-error (lambda () (carefully (lambda () (define p (delay-force p)) (force p)) (lambda () 'stack-overflow) (lambda () 'timeout)))))) (define-test 'force-force-delay-delay (lambda () (assert-eqv (force (force (delay (delay 0)))) 0))) ;; Adapted from SRFI 45. (define-test 'memoization-1 (lambda () (let* ((c 0) (s (delay (begin (set! c (+ c 1)) 'ok)))) (assert-eqv (force s) 'ok) (assert-eqv c 1)))) (define-test 'memoization-2 (lambda () (let* ((c 0) (s (delay (begin (set! c (+ c 1)) 42)))) (assert-eqv (+ (force s) (force s)) 84) (assert-eqv c 1)))) (define-test 'memoization-3 (lambda () (let* ((c 0) (r (delay (begin (set! c (+ c 1)) 'ok))) (s (delay-force r)) (t (delay-force s))) (assert-eqv (force t) 'ok) (assert-eqv (force s) 'ok) (assert-eqv c 1)))) (define-test 'memoization-4 (lambda () (define (stream-drop s i) (delay-force (if (zero? i) s (stream-drop (cdr (force s)) (- i 1))))) (define c 0) (define (count-from n) (delay (begin (set! c (+ c 1)) (cons n (count-from (+ n 1)))))) (define s0 (count-from 0)) (assert-eqv (car (force (stream-drop s0 4))) 4) (assert-eqv (car (force (stream-drop s0 4))) 4) (assert-eqv c 5) (assert-eqv (car (force (stream-drop (count-from 0) 4))) 4) (assert-eqv c 10))) (define-test 'reentrancy-1 (lambda () (let ((c 0) (x 5)) (define p (delay (begin (set! c (+ c 1)) (if (> c x) c (force p))))) (assert-eqv (force p) 6) (set! x 10) (assert-eqv (force p) 6)))) (define-test 'reentrancy-2 (lambda () (let ((first? #t)) (define p (delay (if first? (begin (set! first? #f) (force p)) 'second))) (assert-true first?) (assert-eqv (force p) 'second) (assert-false first?)))) (define-test 'reentrancy-3 (lambda () (let ((c 5)) (define p (delay (if (<= c 0) c (begin (set! c (- c 1)) (force p) (set! c (+ c 2)) c)))) (assert-eqv c 5) (assert-eqv (force p) 0) (assert-eqv c 10)))) (define (words-in-heap) (let ((status (gc-space-status))) (let ((heap-start (vector-ref status 4)) (heap-end (vector-ref status 7))) (let ((n-words (- heap-end heap-start))) (if keep-it-fast!? (quotient n-words 100) n-words))))) (define-test 'leak-1 (lambda () (define (count-down n) (delay-force (if (zero? n) (delay 0) (count-down (- n 1))))) (force (count-down (words-in-heap))))) (define-test 'leak-2 (lambda () (define (count-down n) (delay-force (if (zero? n) (delay 0) (count-down (- n 1))))) (let ((p (count-down (words-in-heap)))) (force p) (reference-barrier p)))) (define-test 'leak-3 (lambda () (define (count-from n) (delay (cons n (count-from (+ n 1))))) (define (stream-ref s i) (delay-force (if (zero? i) (delay (car (force s))) (stream-ref (cdr (force s)) (- i 1))))) (let ((n (words-in-heap))) (assert-eqv (force (stream-ref (count-from 0) n)) n)))) ;; Tests 4, 5, and 6 aren't terribly interesting. (define-test 'leak-7 (lambda () (define (count-from n) (delay (cons n (count-from (+ n 1))))) (define (stream-ref s i) (delay-force (if (zero? i) (delay (car (force s))) (stream-ref (cdr (force s)) (- i 1))))) (define (stream-filter f s) (delay-force (if (pair? (force s)) (let ((x (car (force s))) (s* (delay-force (stream-filter f (cdr (force s)))))) (if (f x) (delay (cons x s*)) s*)) (delay '())))) (define ((divisible-by? d) n) (zero? (modulo n d))) (define (times3 n) (force (stream-ref (stream-filter (divisible-by? n) (count-from 0)) 3))) (let ((n (quotient (words-in-heap) 3))) (assert-eqv (times3 n) (* 3 n)))))
false
a6d7151806db0e130e1623e140765459a95a47a1
ac2a3544b88444eabf12b68a9bce08941cd62581
/lib/_prim-misc#.scm
0b5f3a40e3f57b0eea7ed355d13b336e23acf9ef
[ "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
535
scm
_prim-misc#.scm
;;;============================================================================ ;;; File: "_prim-misc#.scm" ;;; Copyright (c) 1994-2019 by Marc Feeley, All Rights Reserved. ;;;============================================================================ ;;; Miscellaneous operations. (##include "~~lib/_prim-misc-r4rs#.scm") (##include "~~lib/_prim-misc-r5rs#.scm") (##include "~~lib/_prim-misc-r7rs#.scm") (##include "~~lib/_prim-misc-gambit#.scm") ;;;============================================================================
false
0661b5611a8aabcd42762232aedb45d00de2dbb2
a1eb2f57bc1e57855ec47daf9ba47922b8272702
/tests/impl-test.scm
51aa57f9517fdf99f2e94f9455a783211631a20c
[ "BSD-3-Clause" ]
permissive
caelia/qolorizer
5d47c4a9058845e8f08e168660996e9f7656c593
f4bf33d130900f0d9c42d10854106ec60a02ed08
refs/heads/master
2023-08-21T02:53:27.410903
2015-01-07T01:04:41
2015-01-07T01:04:41
null
0
0
null
null
null
null
UTF-8
Scheme
false
false
67,112
scm
impl-test.scm
(use test) (include "../qolorizer-impl.scm") (include "test-utils.scm") (current-test-epsilon 0.001) (test-group "[1] parse-color: bad input causes errors" (test-error "1.01: (parse-color \"#00000000\" 1.1) [invalid alpha] => ERROR" (collect-values parse-color "#00000000" 1.1)) (test-error "1.02: (parse-color \"#garbage\" 1.1) [nonsense color spec] => ERROR" (collect-values parse-color "#garbage" 1.1)) (test-error "1.03: (parse-color \"garbage\" #f) [nonsense color spec] => ERROR" (collect-values parse-color "garbage" #f)) (test-error "1.04: (parse-color '(0 0 256) #f) [value out of range] => ERROR" (collect-values parse-color '(0 0 256) #f)) (test-error "1.05: (parse-color '(0 -19 255) #f) [value out of range] => ERROR" (collect-values parse-color '(0 -19 255) #f)) (test-error "1.06: (parse-color \"0,0,256\" #f) [value out of range] => ERROR" (collect-values parse-color "0,0,256" #f)) (test-error "1.07: (parse-color \"0,-19,255\" #f) [value out of range] => ERROR" (collect-values parse-color "0,-19,255" #f)) (test-error "1.08: (parse-color \"#fa28c71\" 1.0) [wrong length] => ERROR" (collect-values parse-color "#fa28c71" 1.0)) (test-error "1.09: (parse-color \"#39e4b\" 1.0) [wrong length] => ERROR" (collect-values parse-color "#39e4b" 1.0)) (test-error "1.10: (parse-color \"#aa\" 1.0) [wrong length] => ERROR" (collect-values parse-color "#aa" 1.0)) ) (test-group "[2] parse-color: correct results" (with-comparator list-fuzzy= (test-group "[2.01] hex strings" (test "2.01.01: (parse-color \"#000000\" #f) => '(0 0 0 1.0)" '(0 0 0 1.0) (collect-values parse-color "#000000" #f)) (test "2.01.02: (parse-color \"#000000ff\" #f) => '(0 0 0 1.0)" '(0 0 0 1.0) (collect-values parse-color "#000000ff" #f)) (test "2.01.03: (parse-color \"#000000\" 1.0) => '(0 0 0 1.0)" '(0 0 0 1.0) (collect-values parse-color "#000000" 1.0)) (test "2.01.04: (parse-color \"#000000ff\" 1.0) => '(0 0 0 1.0)" '(0 0 0 1.0) (collect-values parse-color "#000000ff" 1.0)) (test "2.01.05: (parse-color \"#00000000\" 1.0) => '(0 0 0 1.0)" '(0 0 0 1.0) (collect-values parse-color "#00000000" 1.0)) (test "2.01.06: (parse-color \"#000000\" 0) => '(0 0 0 0.0)" '(0 0 0 0.0) (collect-values parse-color "#000000" 0)) (test "2.01.07: (parse-color \"#000000ff\" 0) => '(0 0 0 0.0)" '(0 0 0 0.0) (collect-values parse-color "#000000ff" 0)) (test "2.01.08: (parse-color \"#000\" #f) => '(0 0 0 1.0)" '(0 0 0 1.0) (collect-values parse-color "#000" #f)) (test "2.01.09: (parse-color \"#fff\" #f) => '(1 1 1 1.0)" '(1 1 1 1.0) (collect-values parse-color "#fff" #f)) (test "2.01.10: (parse-color \"#a7d733\" #f) => '(0.655 0.843 0.200 1.0)" '(0.655 0.843 0.200 1.0) (collect-values parse-color "#a7d733" #f)) (with-comparator list-approx= (test "2.01.11: (parse-color \"#a7d73380\" #f) => '(0.655 0.843 0.200 0.5)" '(0.655 0.843 0.200 0.5) (collect-values parse-color "#a7d73380" #f)) (test "2.01.12: (parse-color \"#a7d7334b\" #f) => '(0.655 0.843 0.200 0.294)" '(0.655 0.843 0.200 0.294) (collect-values parse-color "#a7d7334b" #f))) (test "2.01.13: (parse-color \"#6ac\" #f) => '(0.400 0.667 0.800 1.0)" '(0.400 0.667 0.800 1.0) (collect-values parse-color "#6ac" #f)) (test "2.01.14: (parse-color \"#823f\" #f) => '(0.533 0.133 0.200 1.0)" '(0.533 0.133 0.200 1.0) (collect-values parse-color "#823f" #f)) (test "2.01.15: (parse-color \"#823f\" 0.4) => '(0.533 0.133 0.200 0.4)" '(0.533 0.133 0.200 0.4) (collect-values parse-color "#823f" 0.4)) ) (test-group "[2.02] value lists" (test "2.02.01: (parse-color '(0 0 0) #f) => '(0 0 0 1.0)" '(0 0 0 1.0) (collect-values parse-color '(0 0 0) #f)) (test "2.02.02: (parse-color '(0 0 0 1) #f) => '(0 0 0 1.0)" '(0 0 0 1.0) (collect-values parse-color '(0 0 0 1) #f)) (test "2.02.03: (parse-color '(0 0 0) 1.0) => '(0 0 0 1.0)" '(0 0 0 1.0) (collect-values parse-color '(0 0 0) 1.0)) (test "2.02.04: (parse-color '(0 0 0 1) 1.0) => '(0 0 0 1.0)" '(0 0 0 1.0) (collect-values parse-color '(0 0 0 1) 1.0)) (test "2.02.05: (parse-color '(0 0 0 0) 1.0) => '(0 0 0 1.0)" '(0 0 0 1.0) (collect-values parse-color '(0 0 0 0) 1.0)) (test "2.02.06: (parse-color '(0 0 0) 0) => '(0 0 0 0.0)" '(0 0 0 0.0) (collect-values parse-color '(0 0 0) 0)) (test "2.02.07: (parse-color '(0 0 0 1) 0) => '(0 0 0 0.0)" '(0 0 0 0.0) (collect-values parse-color '(0 0 0 1) 0)) (test "2.02.10: (parse-color '(167 215 51) #f) => '(0.655 0.843 0.200 1.0)" '(0.655 0.843 0.200 1.0) (collect-values parse-color '(167 215 51) #f)) (with-comparator list-approx= (test "2.02.11: (parse-color '(167 215 51 0.5) #f) => '(0.655 0.843 0.200 0.5)" '(0.655 0.843 0.200 0.5) (collect-values parse-color '(167 215 51 0.5) #f)) (test "2.02.12: (parse-color '(167 215 51 0.294) #f) => '(0.655 0.843 0.200 0.294)" '(0.655 0.843 0.200 0.294) (collect-values parse-color '(167 215 51 0.294) #f))) ) (test-group "[2.03] value list strings" (test "2.03.01: (parse-color \"0,0,0\" #f) => '(0 0 0 1.0)" '(0 0 0 1.0) (collect-values parse-color "0,0,0" #f)) (test "2.03.02: (parse-color \"0,0,0,1\" #f) => '(0 0 0 1.0)" '(0 0 0 1.0) (collect-values parse-color "0,0,0,1" #f)) (test "2.03.03: (parse-color \"0,0,0\" 1.0) => '(0 0 0 1.0)" '(0 0 0 1.0) (collect-values parse-color "0,0,0" 1.0)) (test "2.03.04: (parse-color \"0,0,0,1\" 1.0) => '(0 0 0 1.0)" '(0 0 0 1.0) (collect-values parse-color "0,0,0,1" 1.0)) (test "2.03.05: (parse-color \"0,0,0,0\" 1.0) => '(0 0 0 1.0)" '(0 0 0 1.0) (collect-values parse-color "0,0,0,0" 1.0)) (test "2.03.06: (parse-color \"0,0,0\" 0) => '(0 0 0 0.0)" '(0 0 0 0.0) (collect-values parse-color "0,0,0" 0)) (test "2.03.07: (parse-color \"0,0,0,1\" 0) => '(0 0 0 0.0)" '(0 0 0 0.0) (collect-values parse-color "0,0,0,1" 0)) (test "2.03.10: (parse-color \"167,215,51\" #f) => '(0.655 0.843 0.200 1.0)" '(0.655 0.843 0.200 1.0) (collect-values parse-color "167,215,51" #f)) (with-comparator list-approx= (test "2.03.11: (parse-color \"167,215,51,0.5\" #f) => '(0.655 0.843 0.200 0.5)" '(0.655 0.843 0.200 0.5) (collect-values parse-color "167,215,51,0.5" #f)) (test "2.03.12: (parse-color \"167,215,51,0.294\" #f) => '(0.655 0.843 0.200 0.294)" '(0.655 0.843 0.200 0.294) (collect-values parse-color "167,215,51,0.294" #f))) ) )) (test-group "[3] RGB blend ops produce legal results w/ legal input" (with-comparator legal1 (test-group "[3.01] normal" (test "3.01.01: ((normal-op 0) 0)" #:LEGAL ((normal-op 0) 0)) (test "3.01.02: ((normal-op 0.067) 0.067)" #:LEGAL ((normal-op 0.067) 0.067)) (test "3.01.03: ((normal-op 0.486) 0.486)" #:LEGAL ((normal-op 0.486) 0.486)) (test "3.01.04: ((normal-op 1) 1)" #:LEGAL ((normal-op 1) 1)) (test "3.01.05: ((normal-op 1) 0)" #:LEGAL ((normal-op 1) 0)) (test "3.01.06: ((normal-op 0) 1)" #:LEGAL ((normal-op 0) 1)) (test "3.01.07: ((normal-op 0) 0.004)" #:LEGAL ((normal-op 0) 0.004)) (test "3.01.08: ((normal-op 0.004) 0)" #:LEGAL ((normal-op 0.004) 0)) (test "3.01.09: ((normal-op 1) 0.996)" #:LEGAL ((normal-op 1) 0.996)) (test "3.01.10: ((normal-op 0.996) 1)" #:LEGAL ((normal-op 0.996) 1)) (test "3.01.11: ((normal-op 0.110) 0.114)" #:LEGAL ((normal-op 0.110) 0.114)) (test "3.01.12: ((normal-op 0.114) 0.110)" #:LEGAL ((normal-op 0.114) 0.110)) (test "3.01.13: ((normal-op 0.800) 0.067)" #:LEGAL ((normal-op 0.800) 0.067)) (test "3.01.14: ((normal-op 0.067) 0.800)" #:LEGAL ((normal-op 0.067) 0.800)) (test "3.01.15: ((normal-op 0.314) 0.231)" #:LEGAL ((normal-op 0.314) 0.231)) (test "3.01.16: ((normal-op 0.231) 0.314)" #:LEGAL ((normal-op 0.231) 0.314))) (test-group "[3.02] dissolve" (test "3.02.01: ((dissolve-op 0) 0)" #:LEGAL ((dissolve-op 0) 0)) (test "3.02.02: ((dissolve-op 0.067) 0.067)" #:LEGAL ((dissolve-op 0.067) 0.067)) (test "3.02.03: ((dissolve-op 0.486) 0.486)" #:LEGAL ((dissolve-op 0.486) 0.486)) (test "3.02.04: ((dissolve-op 1) 1)" #:LEGAL ((dissolve-op 1) 1)) (test "3.02.05: ((dissolve-op 1) 0)" #:LEGAL ((dissolve-op 1) 0)) (test "3.02.06: ((dissolve-op 0) 1)" #:LEGAL ((dissolve-op 0) 1)) (test "3.02.07: ((dissolve-op 0) 0.004)" #:LEGAL ((dissolve-op 0) 0.004)) (test "3.02.08: ((dissolve-op 0.004) 0)" #:LEGAL ((dissolve-op 0.004) 0)) (test "3.02.09: ((dissolve-op 1) 0.996)" #:LEGAL ((dissolve-op 1) 0.996)) (test "3.02.10: ((dissolve-op 0.996) 1)" #:LEGAL ((dissolve-op 0.996) 1)) (test "3.02.11: ((dissolve-op 0.110) 0.114)" #:LEGAL ((dissolve-op 0.110) 0.114)) (test "3.02.12: ((dissolve-op 0.114) 0.110)" #:LEGAL ((dissolve-op 0.114) 0.110)) (test "3.02.13: ((dissolve-op 0.800) 0.067)" #:LEGAL ((dissolve-op 0.800) 0.067)) (test "3.02.14: ((dissolve-op 0.067) 0.800)" #:LEGAL ((dissolve-op 0.067) 0.800)) (test "3.02.15: ((dissolve-op 0.314) 0.231)" #:LEGAL ((dissolve-op 0.314) 0.231)) (test "3.02.16: ((dissolve-op 0.231) 0.314)" #:LEGAL ((dissolve-op 0.231) 0.314))) (test-group "[3.03] multiply" (test "3.03.01: ((multiply-op 0) 0)" #:LEGAL ((multiply-op 0) 0)) (test "3.03.02: ((multiply-op 0.067) 0.067)" #:LEGAL ((multiply-op 0.067) 0.067)) (test "3.03.03: ((multiply-op 0.486) 0.486)" #:LEGAL ((multiply-op 0.486) 0.486)) (test "3.03.04: ((multiply-op 1) 1)" #:LEGAL ((multiply-op 1) 1)) (test "3.03.05: ((multiply-op 1) 0)" #:LEGAL ((multiply-op 1) 0)) (test "3.03.06: ((multiply-op 0) 1)" #:LEGAL ((multiply-op 0) 1)) (test "3.03.07: ((multiply-op 0) 0.004)" #:LEGAL ((multiply-op 0) 0.004)) (test "3.03.08: ((multiply-op 0.004) 0)" #:LEGAL ((multiply-op 0.004) 0)) (test "3.03.09: ((multiply-op 1) 0.996)" #:LEGAL ((multiply-op 1) 0.996)) (test "3.03.10: ((multiply-op 0.996) 1)" #:LEGAL ((multiply-op 0.996) 1)) (test "3.03.11: ((multiply-op 0.110) 0.114)" #:LEGAL ((multiply-op 0.110) 0.114)) (test "3.03.12: ((multiply-op 0.114) 0.110)" #:LEGAL ((multiply-op 0.114) 0.110)) (test "3.03.13: ((multiply-op 0.800) 0.067)" #:LEGAL ((multiply-op 0.800) 0.067)) (test "3.03.14: ((multiply-op 0.067) 0.800)" #:LEGAL ((multiply-op 0.067) 0.800)) (test "3.03.15: ((multiply-op 0.314) 0.231)" #:LEGAL ((multiply-op 0.314) 0.231)) (test "3.03.16: ((multiply-op 0.231) 0.314)" #:LEGAL ((multiply-op 0.231) 0.314))) (test-group "[3.04] screen" (test "3.04.01: ((screen-op 0) 0)" #:LEGAL ((screen-op 0) 0)) (test "3.04.02: ((screen-op 0.067) 0.067)" #:LEGAL ((screen-op 0.067) 0.067)) (test "3.04.03: ((screen-op 0.486) 0.486)" #:LEGAL ((screen-op 0.486) 0.486)) (test "3.04.04: ((screen-op 1) 1)" #:LEGAL ((screen-op 1) 1)) (test "3.04.05: ((screen-op 1) 0)" #:LEGAL ((screen-op 1) 0)) (test "3.04.06: ((screen-op 0) 1)" #:LEGAL ((screen-op 0) 1)) (test "3.04.07: ((screen-op 0) 0.004)" #:LEGAL ((screen-op 0) 0.004)) (test "3.04.08: ((screen-op 0.004) 0)" #:LEGAL ((screen-op 0.004) 0)) (test "3.04.09: ((screen-op 1) 0.996)" #:LEGAL ((screen-op 1) 0.996)) (test "3.04.10: ((screen-op 0.996) 1)" #:LEGAL ((screen-op 0.996) 1)) (test "3.04.11: ((screen-op 0.110) 0.114)" #:LEGAL ((screen-op 0.110) 0.114)) (test "3.04.12: ((screen-op 0.114) 0.110)" #:LEGAL ((screen-op 0.114) 0.110)) (test "3.04.13: ((screen-op 0.800) 0.067)" #:LEGAL ((screen-op 0.800) 0.067)) (test "3.04.14: ((screen-op 0.067) 0.800)" #:LEGAL ((screen-op 0.067) 0.800)) (test "3.04.15: ((screen-op 0.314) 0.231)" #:LEGAL ((screen-op 0.314) 0.231)) (test "3.04.16: ((screen-op 0.231) 0.314)" #:LEGAL ((screen-op 0.231) 0.314))) (test-group "[3.05] overlay" (test "3.05.01: ((overlay-op 0) 0)" #:LEGAL ((overlay-op 0) 0)) (test "3.05.02: ((overlay-op 0.067) 0.067)" #:LEGAL ((overlay-op 0.067) 0.067)) (test "3.05.03: ((overlay-op 0.486) 0.486)" #:LEGAL ((overlay-op 0.486) 0.486)) (test "3.05.04: ((overlay-op 1) 1)" #:LEGAL ((overlay-op 1) 1)) (test "3.05.05: ((overlay-op 1) 0)" #:LEGAL ((overlay-op 1) 0)) (test "3.05.06: ((overlay-op 0) 1)" #:LEGAL ((overlay-op 0) 1)) (test "3.05.07: ((overlay-op 0) 0.004)" #:LEGAL ((overlay-op 0) 0.004)) (test "3.05.08: ((overlay-op 0.004) 0)" #:LEGAL ((overlay-op 0.004) 0)) (test "3.05.09: ((overlay-op 1) 0.996)" #:LEGAL ((overlay-op 1) 0.996)) (test "3.05.10: ((overlay-op 0.996) 1)" #:LEGAL ((overlay-op 0.996) 1)) (test "3.05.11: ((overlay-op 0.110) 0.114)" #:LEGAL ((overlay-op 0.110) 0.114)) (test "3.05.12: ((overlay-op 0.114) 0.110)" #:LEGAL ((overlay-op 0.114) 0.110)) (test "3.05.13: ((overlay-op 0.800) 0.067)" #:LEGAL ((overlay-op 0.800) 0.067)) (test "3.05.14: ((overlay-op 0.067) 0.800)" #:LEGAL ((overlay-op 0.067) 0.800)) (test "3.05.15: ((overlay-op 0.314) 0.231)" #:LEGAL ((overlay-op 0.314) 0.231)) (test "3.05.16: ((overlay-op 0.231) 0.314)" #:LEGAL ((overlay-op 0.231) 0.314))) (test-group "[3.06] difference" (test "3.06.01: ((difference-op 0) 0)" #:LEGAL ((difference-op 0) 0)) (test "3.06.02: ((difference-op 0.067) 0.067)" #:LEGAL ((difference-op 0.067) 0.067)) (test "3.06.03: ((difference-op 0.486) 0.486)" #:LEGAL ((difference-op 0.486) 0.486)) (test "3.06.04: ((difference-op 1) 1)" #:LEGAL ((difference-op 1) 1)) (test "3.06.05: ((difference-op 1) 0)" #:LEGAL ((difference-op 1) 0)) (test "3.06.06: ((difference-op 0) 1)" #:LEGAL ((difference-op 0) 1)) (test "3.06.07: ((difference-op 0) 0.004)" #:LEGAL ((difference-op 0) 0.004)) (test "3.06.08: ((difference-op 0.004) 0)" #:LEGAL ((difference-op 0.004) 0)) (test "3.06.09: ((difference-op 1) 0.996)" #:LEGAL ((difference-op 1) 0.996)) (test "3.06.10: ((difference-op 0.996) 1)" #:LEGAL ((difference-op 0.996) 1)) (test "3.06.11: ((difference-op 0.110) 0.114)" #:LEGAL ((difference-op 0.110) 0.114)) (test "3.06.12: ((difference-op 0.114) 0.110)" #:LEGAL ((difference-op 0.114) 0.110)) (test "3.06.13: ((difference-op 0.800) 0.067)" #:LEGAL ((difference-op 0.800) 0.067)) (test "3.06.14: ((difference-op 0.067) 0.800)" #:LEGAL ((difference-op 0.067) 0.800)) (test "3.06.15: ((difference-op 0.314) 0.231)" #:LEGAL ((difference-op 0.314) 0.231)) (test "3.06.16: ((difference-op 0.231) 0.314)" #:LEGAL ((difference-op 0.231) 0.314))) (test-group "[3.07] addition" (test "3.07.01: ((addition-op 0) 0)" #:LEGAL ((addition-op 0) 0)) (test "3.07.02: ((addition-op 0.067) 0.067)" #:LEGAL ((addition-op 0.067) 0.067)) (test "3.07.03: ((addition-op 0.486) 0.486)" #:LEGAL ((addition-op 0.486) 0.486)) (test "3.07.04: ((addition-op 1) 1)" #:LEGAL ((addition-op 1) 1)) (test "3.07.05: ((addition-op 1) 0)" #:LEGAL ((addition-op 1) 0)) (test "3.07.06: ((addition-op 0) 1)" #:LEGAL ((addition-op 0) 1)) (test "3.07.07: ((addition-op 0) 0.004)" #:LEGAL ((addition-op 0) 0.004)) (test "3.07.08: ((addition-op 0.004) 0)" #:LEGAL ((addition-op 0.004) 0)) (test "3.07.09: ((addition-op 1) 0.996)" #:LEGAL ((addition-op 1) 0.996)) (test "3.07.10: ((addition-op 0.996) 1)" #:LEGAL ((addition-op 0.996) 1)) (test "3.07.11: ((addition-op 0.110) 0.114)" #:LEGAL ((addition-op 0.110) 0.114)) (test "3.07.12: ((addition-op 0.114) 0.110)" #:LEGAL ((addition-op 0.114) 0.110)) (test "3.07.13: ((addition-op 0.800) 0.067)" #:LEGAL ((addition-op 0.800) 0.067)) (test "3.07.14: ((addition-op 0.067) 0.800)" #:LEGAL ((addition-op 0.067) 0.800)) (test "3.07.15: ((addition-op 0.314) 0.231)" #:LEGAL ((addition-op 0.314) 0.231)) (test "3.07.16: ((addition-op 0.231) 0.314)" #:LEGAL ((addition-op 0.231) 0.314))) (test-group "[3.08] subtract" (test "3.08.01: ((subtract-op 0) 0)" #:LEGAL ((subtract-op 0) 0)) (test "3.08.02: ((subtract-op 0.067) 0.067)" #:LEGAL ((subtract-op 0.067) 0.067)) (test "3.08.03: ((subtract-op 0.486) 0.486)" #:LEGAL ((subtract-op 0.486) 0.486)) (test "3.08.04: ((subtract-op 1) 1)" #:LEGAL ((subtract-op 1) 1)) (test "3.08.05: ((subtract-op 1) 0)" #:LEGAL ((subtract-op 1) 0)) (test "3.08.06: ((subtract-op 0) 1)" #:LEGAL ((subtract-op 0) 1)) (test "3.08.07: ((subtract-op 0) 0.004)" #:LEGAL ((subtract-op 0) 0.004)) (test "3.08.08: ((subtract-op 0.004) 0)" #:LEGAL ((subtract-op 0.004) 0)) (test "3.08.09: ((subtract-op 1) 0.996)" #:LEGAL ((subtract-op 1) 0.996)) (test "3.08.10: ((subtract-op 0.996) 1)" #:LEGAL ((subtract-op 0.996) 1)) (test "3.08.11: ((subtract-op 0.110) 0.114)" #:LEGAL ((subtract-op 0.110) 0.114)) (test "3.08.12: ((subtract-op 0.114) 0.110)" #:LEGAL ((subtract-op 0.114) 0.110)) (test "3.08.13: ((subtract-op 0.800) 0.067)" #:LEGAL ((subtract-op 0.800) 0.067)) (test "3.08.14: ((subtract-op 0.067) 0.800)" #:LEGAL ((subtract-op 0.067) 0.800)) (test "3.08.15: ((subtract-op 0.314) 0.231)" #:LEGAL ((subtract-op 0.314) 0.231)) (test "3.08.16: ((subtract-op 0.231) 0.314)" #:LEGAL ((subtract-op 0.231) 0.314))) (test-group "[3.09] darken-only" (test "3.09.01: ((darken-only-op 0) 0)" #:LEGAL ((darken-only-op 0) 0)) (test "3.09.02: ((darken-only-op 0.067) 0.067)" #:LEGAL ((darken-only-op 0.067) 0.067)) (test "3.09.03: ((darken-only-op 0.486) 0.486)" #:LEGAL ((darken-only-op 0.486) 0.486)) (test "3.09.04: ((darken-only-op 1) 1)" #:LEGAL ((darken-only-op 1) 1)) (test "3.09.05: ((darken-only-op 1) 0)" #:LEGAL ((darken-only-op 1) 0)) (test "3.09.06: ((darken-only-op 0) 1)" #:LEGAL ((darken-only-op 0) 1)) (test "3.09.07: ((darken-only-op 0) 0.004)" #:LEGAL ((darken-only-op 0) 0.004)) (test "3.09.08: ((darken-only-op 0.004) 0)" #:LEGAL ((darken-only-op 0.004) 0)) (test "3.09.09: ((darken-only-op 1) 0.996)" #:LEGAL ((darken-only-op 1) 0.996)) (test "3.09.10: ((darken-only-op 0.996) 1)" #:LEGAL ((darken-only-op 0.996) 1)) (test "3.09.11: ((darken-only-op 0.110) 0.114)" #:LEGAL ((darken-only-op 0.110) 0.114)) (test "3.09.12: ((darken-only-op 0.114) 0.110)" #:LEGAL ((darken-only-op 0.114) 0.110)) (test "3.09.13: ((darken-only-op 0.800) 0.067)" #:LEGAL ((darken-only-op 0.800) 0.067)) (test "3.09.14: ((darken-only-op 0.067) 0.800)" #:LEGAL ((darken-only-op 0.067) 0.800)) (test "3.09.15: ((darken-only-op 0.314) 0.231)" #:LEGAL ((darken-only-op 0.314) 0.231)) (test "3.09.16: ((darken-only-op 0.231) 0.314)" #:LEGAL ((darken-only-op 0.231) 0.314))) (test-group "[3.10] lighten-only" (test "3.10.01: ((lighten-only-op 0) 0)" #:LEGAL ((lighten-only-op 0) 0)) (test "3.10.02: ((lighten-only-op 0.067) 0.067)" #:LEGAL ((lighten-only-op 0.067) 0.067)) (test "3.10.03: ((lighten-only-op 0.486) 0.486)" #:LEGAL ((lighten-only-op 0.486) 0.486)) (test "3.10.04: ((lighten-only-op 1) 1)" #:LEGAL ((lighten-only-op 1) 1)) (test "3.10.05: ((lighten-only-op 1) 0)" #:LEGAL ((lighten-only-op 1) 0)) (test "3.10.06: ((lighten-only-op 0) 1)" #:LEGAL ((lighten-only-op 0) 1)) (test "3.10.07: ((lighten-only-op 0) 0.004)" #:LEGAL ((lighten-only-op 0) 0.004)) (test "3.10.08: ((lighten-only-op 0.004) 0)" #:LEGAL ((lighten-only-op 0.004) 0)) (test "3.10.09: ((lighten-only-op 1) 0.996)" #:LEGAL ((lighten-only-op 1) 0.996)) (test "3.10.10: ((lighten-only-op 0.996) 1)" #:LEGAL ((lighten-only-op 0.996) 1)) (test "3.10.11: ((lighten-only-op 0.110) 0.114)" #:LEGAL ((lighten-only-op 0.110) 0.114)) (test "3.10.12: ((lighten-only-op 0.114) 0.110)" #:LEGAL ((lighten-only-op 0.114) 0.110)) (test "3.10.13: ((lighten-only-op 0.800) 0.067)" #:LEGAL ((lighten-only-op 0.800) 0.067)) (test "3.10.14: ((lighten-only-op 0.067) 0.800)" #:LEGAL ((lighten-only-op 0.067) 0.800)) (test "3.10.15: ((lighten-only-op 0.314) 0.231)" #:LEGAL ((lighten-only-op 0.314) 0.231)) (test "3.10.16: ((lighten-only-op 0.231) 0.314)" #:LEGAL ((lighten-only-op 0.231) 0.314))) (test-group "[3.11] divide" (test "3.11.01: ((divide-op 0) 0)" #:LEGAL ((divide-op 0) 0)) (test "3.11.02: ((divide-op 0.067) 0.067)" #:LEGAL ((divide-op 0.067) 0.067)) (test "3.11.03: ((divide-op 0.486) 0.486)" #:LEGAL ((divide-op 0.486) 0.486)) (test "3.11.04: ((divide-op 1) 1)" #:LEGAL ((divide-op 1) 1)) (test "3.11.05: ((divide-op 1) 0)" #:LEGAL ((divide-op 1) 0)) (test "3.11.06: ((divide-op 0) 1)" #:LEGAL ((divide-op 0) 1)) (test "3.11.07: ((divide-op 0) 0.004)" #:LEGAL ((divide-op 0) 0.004)) (test "3.11.08: ((divide-op 0.004) 0)" #:LEGAL ((divide-op 0.004) 0)) (test "3.11.09: ((divide-op 1) 0.996)" #:LEGAL ((divide-op 1) 0.996)) (test "3.11.10: ((divide-op 0.996) 1)" #:LEGAL ((divide-op 0.996) 1)) (test "3.11.11: ((divide-op 0.110) 0.114)" #:LEGAL ((divide-op 0.110) 0.114)) (test "3.11.12: ((divide-op 0.114) 0.110)" #:LEGAL ((divide-op 0.114) 0.110)) (test "3.11.13: ((divide-op 0.800) 0.067)" #:LEGAL ((divide-op 0.800) 0.067)) (test "3.11.14: ((divide-op 0.067) 0.800)" #:LEGAL ((divide-op 0.067) 0.800)) (test "3.11.15: ((divide-op 0.314) 0.231)" #:LEGAL ((divide-op 0.314) 0.231)) (test "3.11.16: ((divide-op 0.231) 0.314)" #:LEGAL ((divide-op 0.231) 0.314))) (test-group "[3.12] dodge" (test "3.12.01: ((dodge-op 0) 0)" #:LEGAL ((dodge-op 0) 0)) (test "3.12.02: ((dodge-op 0.067) 0.067)" #:LEGAL ((dodge-op 0.067) 0.067)) (test "3.12.03: ((dodge-op 0.486) 0.486)" #:LEGAL ((dodge-op 0.486) 0.486)) (test "3.12.04: ((dodge-op 1) 1)" #:LEGAL ((dodge-op 1) 1)) (test "3.12.05: ((dodge-op 1) 0)" #:LEGAL ((dodge-op 1) 0)) (test "3.12.06: ((dodge-op 0) 1)" #:LEGAL ((dodge-op 0) 1)) (test "3.12.07: ((dodge-op 0) 0.004)" #:LEGAL ((dodge-op 0) 0.004)) (test "3.12.08: ((dodge-op 0.004) 0)" #:LEGAL ((dodge-op 0.004) 0)) (test "3.12.09: ((dodge-op 1) 0.996)" #:LEGAL ((dodge-op 1) 0.996)) (test "3.12.10: ((dodge-op 0.996) 1)" #:LEGAL ((dodge-op 0.996) 1)) (test "3.12.11: ((dodge-op 0.110) 0.114)" #:LEGAL ((dodge-op 0.110) 0.114)) (test "3.12.12: ((dodge-op 0.114) 0.110)" #:LEGAL ((dodge-op 0.114) 0.110)) (test "3.12.13: ((dodge-op 0.800) 0.067)" #:LEGAL ((dodge-op 0.800) 0.067)) (test "3.12.14: ((dodge-op 0.067) 0.800)" #:LEGAL ((dodge-op 0.067) 0.800)) (test "3.12.15: ((dodge-op 0.314) 0.231)" #:LEGAL ((dodge-op 0.314) 0.231)) (test "3.12.16: ((dodge-op 0.231) 0.314)" #:LEGAL ((dodge-op 0.231) 0.314))) (test-group "[3.13] burn" (test "3.13.01: ((burn-op 0) 0)" #:LEGAL ((burn-op 0) 0)) (test "3.13.02: ((burn-op 0.067) 0.067)" #:LEGAL ((burn-op 0.067) 0.067)) (test "3.13.03: ((burn-op 0.486) 0.486)" #:LEGAL ((burn-op 0.486) 0.486)) (test "3.13.04: ((burn-op 1) 1)" #:LEGAL ((burn-op 1) 1)) (test "3.13.05: ((burn-op 1) 0)" #:LEGAL ((burn-op 1) 0)) (test "3.13.06: ((burn-op 0) 1)" #:LEGAL ((burn-op 0) 1)) (test "3.13.07: ((burn-op 0) 0.004)" #:LEGAL ((burn-op 0) 0.004)) (test "3.13.08: ((burn-op 0.004) 0)" #:LEGAL ((burn-op 0.004) 0)) (test "3.13.09: ((burn-op 1) 0.996)" #:LEGAL ((burn-op 1) 0.996)) (test "3.13.10: ((burn-op 0.996) 1)" #:LEGAL ((burn-op 0.996) 1)) (test "3.13.11: ((burn-op 0.110) 0.114)" #:LEGAL ((burn-op 0.110) 0.114)) (test "3.13.12: ((burn-op 0.114) 0.110)" #:LEGAL ((burn-op 0.114) 0.110)) (test "3.13.13: ((burn-op 0.800) 0.067)" #:LEGAL ((burn-op 0.800) 0.067)) (test "3.13.14: ((burn-op 0.067) 0.800)" #:LEGAL ((burn-op 0.067) 0.800)) (test "3.13.15: ((burn-op 0.314) 0.231)" #:LEGAL ((burn-op 0.314) 0.231)) (test "3.13.16: ((burn-op 0.231) 0.314)" #:LEGAL ((burn-op 0.231) 0.314))) (test-group "[3.14] hard-light" (test "3.14.01: ((hard-light-op 0) 0)" #:LEGAL ((hard-light-op 0) 0)) (test "3.14.02: ((hard-light-op 0.067) 0.067)" #:LEGAL ((hard-light-op 0.067) 0.067)) (test "3.14.03: ((hard-light-op 0.486) 0.486)" #:LEGAL ((hard-light-op 0.486) 0.486)) (test "3.14.04: ((hard-light-op 1) 1)" #:LEGAL ((hard-light-op 1) 1)) (test "3.14.05: ((hard-light-op 1) 0)" #:LEGAL ((hard-light-op 1) 0)) (test "3.14.06: ((hard-light-op 0) 1)" #:LEGAL ((hard-light-op 0) 1)) (test "3.14.07: ((hard-light-op 0) 0.004)" #:LEGAL ((hard-light-op 0) 0.004)) (test "3.14.08: ((hard-light-op 0.004) 0)" #:LEGAL ((hard-light-op 0.004) 0)) (test "3.14.09: ((hard-light-op 1) 0.996)" #:LEGAL ((hard-light-op 1) 0.996)) (test "3.14.10: ((hard-light-op 0.996) 1)" #:LEGAL ((hard-light-op 0.996) 1)) (test "3.14.11: ((hard-light-op 0.110) 0.114)" #:LEGAL ((hard-light-op 0.110) 0.114)) (test "3.14.12: ((hard-light-op 0.114) 0.110)" #:LEGAL ((hard-light-op 0.114) 0.110)) (test "3.14.13: ((hard-light-op 0.800) 0.067)" #:LEGAL ((hard-light-op 0.800) 0.067)) (test "3.14.14: ((hard-light-op 0.067) 0.800)" #:LEGAL ((hard-light-op 0.067) 0.800)) (test "3.14.15: ((hard-light-op 0.314) 0.231)" #:LEGAL ((hard-light-op 0.314) 0.231)) (test "3.14.16: ((hard-light-op 0.231) 0.314)" #:LEGAL ((hard-light-op 0.231) 0.314))) (test-group "[3.15] soft-light" (test "3.15.01: ((soft-light-op 0) 0)" #:LEGAL ((soft-light-op 0) 0)) (test "3.15.02: ((soft-light-op 0.067) 0.067)" #:LEGAL ((soft-light-op 0.067) 0.067)) (test "3.15.03: ((soft-light-op 0.486) 0.486)" #:LEGAL ((soft-light-op 0.486) 0.486)) (test "3.15.04: ((soft-light-op 1) 1)" #:LEGAL ((soft-light-op 1) 1)) (test "3.15.05: ((soft-light-op 1) 0)" #:LEGAL ((soft-light-op 1) 0)) (test "3.15.06: ((soft-light-op 0) 1)" #:LEGAL ((soft-light-op 0) 1)) (test "3.15.07: ((soft-light-op 0) 0.004)" #:LEGAL ((soft-light-op 0) 0.004)) (test "3.15.08: ((soft-light-op 0.004) 0)" #:LEGAL ((soft-light-op 0.004) 0)) (test "3.15.09: ((soft-light-op 1) 0.996)" #:LEGAL ((soft-light-op 1) 0.996)) (test "3.15.10: ((soft-light-op 0.996) 1)" #:LEGAL ((soft-light-op 0.996) 1)) (test "3.15.11: ((soft-light-op 0.110) 0.114)" #:LEGAL ((soft-light-op 0.110) 0.114)) (test "3.15.12: ((soft-light-op 0.114) 0.110)" #:LEGAL ((soft-light-op 0.114) 0.110)) (test "3.15.13: ((soft-light-op 0.800) 0.067)" #:LEGAL ((soft-light-op 0.800) 0.067)) (test "3.15.14: ((soft-light-op 0.067) 0.800)" #:LEGAL ((soft-light-op 0.067) 0.800)) (test "3.15.15: ((soft-light-op 0.314) 0.231)" #:LEGAL ((soft-light-op 0.314) 0.231)) (test "3.15.16: ((soft-light-op 0.231) 0.314)" #:LEGAL ((soft-light-op 0.231) 0.314))) (test-group "[3.16] grain-extract" (test "3.16.01: ((grain-extract-op 0) 0)" #:LEGAL ((grain-extract-op 0) 0)) (test "3.16.02: ((grain-extract-op 0.067) 0.067)" #:LEGAL ((grain-extract-op 0.067) 0.067)) (test "3.16.03: ((grain-extract-op 0.486) 0.486)" #:LEGAL ((grain-extract-op 0.486) 0.486)) (test "3.16.04: ((grain-extract-op 1) 1)" #:LEGAL ((grain-extract-op 1) 1)) (test "3.16.05: ((grain-extract-op 1) 0)" #:LEGAL ((grain-extract-op 1) 0)) (test "3.16.06: ((grain-extract-op 0) 1)" #:LEGAL ((grain-extract-op 0) 1)) (test "3.16.07: ((grain-extract-op 0) 0.004)" #:LEGAL ((grain-extract-op 0) 0.004)) (test "3.16.08: ((grain-extract-op 0.004) 0)" #:LEGAL ((grain-extract-op 0.004) 0)) (test "3.16.09: ((grain-extract-op 1) 0.996)" #:LEGAL ((grain-extract-op 1) 0.996)) (test "3.16.10: ((grain-extract-op 0.996) 1)" #:LEGAL ((grain-extract-op 0.996) 1)) (test "3.16.11: ((grain-extract-op 0.110) 0.114)" #:LEGAL ((grain-extract-op 0.110) 0.114)) (test "3.16.12: ((grain-extract-op 0.114) 0.110)" #:LEGAL ((grain-extract-op 0.114) 0.110)) (test "3.16.13: ((grain-extract-op 0.800) 0.067)" #:LEGAL ((grain-extract-op 0.800) 0.067)) (test "3.16.14: ((grain-extract-op 0.067) 0.800)" #:LEGAL ((grain-extract-op 0.067) 0.800)) (test "3.16.15: ((grain-extract-op 0.314) 0.231)" #:LEGAL ((grain-extract-op 0.314) 0.231)) (test "3.16.16: ((grain-extract-op 0.231) 0.314)" #:LEGAL ((grain-extract-op 0.231) 0.314))) (test-group "[3.17] grain-merge" (test "3.17.01: ((grain-merge-op 0) 0)" #:LEGAL ((grain-merge-op 0) 0)) (test "3.17.02: ((grain-merge-op 0.067) 0.067)" #:LEGAL ((grain-merge-op 0.067) 0.067)) (test "3.17.03: ((grain-merge-op 0.486) 0.486)" #:LEGAL ((grain-merge-op 0.486) 0.486)) (test "3.17.04: ((grain-merge-op 1) 1)" #:LEGAL ((grain-merge-op 1) 1)) (test "3.17.05: ((grain-merge-op 1) 0)" #:LEGAL ((grain-merge-op 1) 0)) (test "3.17.06: ((grain-merge-op 0) 1)" #:LEGAL ((grain-merge-op 0) 1)) (test "3.17.07: ((grain-merge-op 0) 0.004)" #:LEGAL ((grain-merge-op 0) 0.004)) (test "3.17.08: ((grain-merge-op 0.004) 0)" #:LEGAL ((grain-merge-op 0.004) 0)) (test "3.17.09: ((grain-merge-op 1) 0.996)" #:LEGAL ((grain-merge-op 1) 0.996)) (test "3.17.10: ((grain-merge-op 0.996) 1)" #:LEGAL ((grain-merge-op 0.996) 1)) (test "3.17.11: ((grain-merge-op 0.110) 0.114)" #:LEGAL ((grain-merge-op 0.110) 0.114)) (test "3.17.12: ((grain-merge-op 0.114) 0.110)" #:LEGAL ((grain-merge-op 0.114) 0.110)) (test "3.17.13: ((grain-merge-op 0.800) 0.067)" #:LEGAL ((grain-merge-op 0.800) 0.067)) (test "3.17.14: ((grain-merge-op 0.067) 0.800)" #:LEGAL ((grain-merge-op 0.067) 0.800)) (test "3.17.15: ((grain-merge-op 0.314) 0.231)" #:LEGAL ((grain-merge-op 0.314) 0.231)) (test "3.17.16: ((grain-merge-op 0.231) 0.314)" #:LEGAL ((grain-merge-op 0.231) 0.314))) )) (test-group "[4] HSV blend ops produce legal results w/ legal input" (with-comparator legal-hsv (test-group "[4.01] color" (test "4.01.01: ((color-op 0 0 0) 0 0 0)" #:LEGAL (collect-values (color-op 0 0 0) 0 0 0)) (test "4.01.02: ((color-op 0 0 0) 0 1 1)" #:LEGAL (collect-values (color-op 0 0 0) 0 1 1)) (test "4.01.03: ((color-op 0 1 1) 0 1 1)" #:LEGAL (collect-values (color-op 0 1 1) 0 1 1)) (test "4.01.04: ((color-op 0 0 0) 360 0 0)" #:LEGAL (collect-values (color-op 0 0 0) 360 0 0)) (test "4.01.05: ((color-op 360 1 1) 360 1 1)" #:LEGAL (collect-values (color-op 360 1 1) 360 1 1)) (test "4.01.06: ((color-op 0 1 1) 360 0 0)" #:LEGAL (collect-values (color-op 0 1 1) 360 0 0)) (test "4.01.07: ((color-op 360 0 0) 360 1 1)" #:LEGAL (collect-values (color-op 360 0 0) 360 1 1)) (test "4.01.08: ((color-op 118 0.5 0.25) 118 0.5 0.25)" #:LEGAL (collect-values (color-op 118 0.5 0.25) 118 0.5 0.25)) (test "4.01.09: ((color-op 99 1 1) 118 0.5 0.25)" #:LEGAL (collect-values (color-op 99 1 1) 118 0.5 0.25)) (test "4.01.10: ((color-op 99 0 0) 118 0.5 0.25)" #:LEGAL (collect-values (color-op 99 0 0) 118 0.5 0.25)) (test "4.01.11: ((color-op 44 1 0.007) 271 0.01 0.002)" #:LEGAL (collect-values (color-op 44 1 0.007) 271 0.01 0.002)) (test "4.01.12: ((color-op 31 1 1) 224 0.999 0.9)" #:LEGAL (collect-values (color-op 31 1 1) 224 0.999 0.9)) (test "4.01.13: ((color-op 88 0.02 0.93) 88 0 1)" #:LEGAL (collect-values (color-op 88 0.02 0.93) 88 0 1)) (test "4.01.14: ((color-op 88 1 0) 88 0 1)" #:LEGAL (collect-values (color-op 88 1 0) 88 0 1)) (test "4.01.15: ((color-op 75 0.95 0.0001) 74 1 0)" #:LEGAL (collect-values (color-op 75 0.95 0.0001) 74 1 0)) (test "4.01.16: ((color-op 299 0.65 0.07) 144 1.0 0.999)" #:LEGAL (collect-values (color-op 299 0.65 0.07) 144 1.0 0.999)) (test "4.01.17: ((color-op 248 0.002 1.0) 243 0.0007 0.4)" #:LEGAL (collect-values (color-op 248 0.002 1.0) 243 0.0007 0.4))) (test-group "[4.02] hue" (test "4.02.01: ((hue-op 0 0 0) 0 0 0)" #:LEGAL (collect-values (hue-op 0 0 0) 0 0 0)) (test "4.02.02: ((hue-op 0 0 0) 0 1 1)" #:LEGAL (collect-values (hue-op 0 0 0) 0 1 1)) (test "4.02.03: ((hue-op 0 1 1) 0 1 1)" #:LEGAL (collect-values (hue-op 0 1 1) 0 1 1)) (test "4.02.04: ((hue-op 0 0 0) 360 0 0)" #:LEGAL (collect-values (hue-op 0 0 0) 360 0 0)) (test "4.02.05: ((hue-op 360 1 1) 360 1 1)" #:LEGAL (collect-values (hue-op 360 1 1) 360 1 1)) (test "4.02.06: ((hue-op 0 1 1) 360 0 0)" #:LEGAL (collect-values (hue-op 0 1 1) 360 0 0)) (test "4.02.07: ((hue-op 360 0 0) 360 1 1)" #:LEGAL (collect-values (hue-op 360 0 0) 360 1 1)) (test "4.02.08: ((hue-op 118 0.5 0.25) 118 0.5 0.25)" #:LEGAL (collect-values (hue-op 118 0.5 0.25) 118 0.5 0.25)) (test "4.02.09: ((hue-op 99 1 1) 118 0.5 0.25)" #:LEGAL (collect-values (hue-op 99 1 1) 118 0.5 0.25)) (test "4.02.10: ((hue-op 99 0 0) 118 0.5 0.25)" #:LEGAL (collect-values (hue-op 99 0 0) 118 0.5 0.25)) (test "4.02.11: ((hue-op 44 1 0.007) 271 0.01 0.002)" #:LEGAL (collect-values (hue-op 44 1 0.007) 271 0.01 0.002)) (test "4.02.12: ((hue-op 31 1 1) 224 0.999 0.9)" #:LEGAL (collect-values (hue-op 31 1 1) 224 0.999 0.9)) (test "4.02.13: ((hue-op 88 0.02 0.93) 88 0 1)" #:LEGAL (collect-values (hue-op 88 0.02 0.93) 88 0 1)) (test "4.02.14: ((hue-op 88 1 0) 88 0 1)" #:LEGAL (collect-values (hue-op 88 1 0) 88 0 1)) (test "4.02.15: ((hue-op 75 0.95 0.0001) 74 1 0)" #:LEGAL (collect-values (hue-op 75 0.95 0.0001) 74 1 0)) (test "4.02.16: ((hue-op 299 0.65 0.07) 144 1.0 0.999)" #:LEGAL (collect-values (hue-op 299 0.65 0.07) 144 1.0 0.999)) (test "4.02.17: ((hue-op 248 0.002 1.0) 243 0.0007 0.4)" #:LEGAL (collect-values (hue-op 248 0.002 1.0) 243 0.0007 0.4))) (test-group "[4.03] saturation" (test "4.03.01: ((saturation-op 0 0 0) 0 0 0)" #:LEGAL (collect-values (saturation-op 0 0 0) 0 0 0)) (test "4.03.02: ((saturation-op 0 0 0) 0 1 1)" #:LEGAL (collect-values (saturation-op 0 0 0) 0 1 1)) (test "4.03.03: ((saturation-op 0 1 1) 0 1 1)" #:LEGAL (collect-values (saturation-op 0 1 1) 0 1 1)) (test "4.03.04: ((saturation-op 0 0 0) 360 0 0)" #:LEGAL (collect-values (saturation-op 0 0 0) 360 0 0)) (test "4.03.05: ((saturation-op 360 1 1) 360 1 1)" #:LEGAL (collect-values (saturation-op 360 1 1) 360 1 1)) (test "4.03.06: ((saturation-op 0 1 1) 360 0 0)" #:LEGAL (collect-values (saturation-op 0 1 1) 360 0 0)) (test "4.03.07: ((saturation-op 360 0 0) 360 1 1)" #:LEGAL (collect-values (saturation-op 360 0 0) 360 1 1)) (test "4.03.08: ((saturation-op 118 0.5 0.25) 118 0.5 0.25)" #:LEGAL (collect-values (saturation-op 118 0.5 0.25) 118 0.5 0.25)) (test "4.03.09: ((saturation-op 99 1 1) 118 0.5 0.25)" #:LEGAL (collect-values (saturation-op 99 1 1) 118 0.5 0.25)) (test "4.03.10: ((saturation-op 99 0 0) 118 0.5 0.25)" #:LEGAL (collect-values (saturation-op 99 0 0) 118 0.5 0.25)) (test "4.03.11: ((saturation-op 44 1 0.007) 271 0.01 0.002)" #:LEGAL (collect-values (saturation-op 44 1 0.007) 271 0.01 0.002)) (test "4.03.12: ((saturation-op 31 1 1) 224 0.999 0.9)" #:LEGAL (collect-values (saturation-op 31 1 1) 224 0.999 0.9)) (test "4.03.13: ((saturation-op 88 0.02 0.93) 88 0 1)" #:LEGAL (collect-values (saturation-op 88 0.02 0.93) 88 0 1)) (test "4.03.14: ((saturation-op 88 1 0) 88 0 1)" #:LEGAL (collect-values (saturation-op 88 1 0) 88 0 1)) (test "4.03.15: ((saturation-op 75 0.95 0.0001) 74 1 0)" #:LEGAL (collect-values (saturation-op 75 0.95 0.0001) 74 1 0)) (test "4.03.16: ((saturation-op 299 0.65 0.07) 144 1.0 0.999)" #:LEGAL (collect-values (saturation-op 299 0.65 0.07) 144 1.0 0.999)) (test "4.03.17: ((saturation-op 248 0.002 1.0) 243 0.0007 0.4)" #:LEGAL (collect-values (saturation-op 248 0.002 1.0) 243 0.0007 0.4))) (test-group "[4.04] value" (test "4.04.01: ((value-op 0 0 0) 0 0 0)" #:LEGAL (collect-values (value-op 0 0 0) 0 0 0)) (test "4.04.02: ((value-op 0 0 0) 0 1 1)" #:LEGAL (collect-values (value-op 0 0 0) 0 1 1)) (test "4.04.03: ((value-op 0 1 1) 0 1 1)" #:LEGAL (collect-values (value-op 0 1 1) 0 1 1)) (test "4.04.04: ((value-op 0 0 0) 360 0 0)" #:LEGAL (collect-values (value-op 0 0 0) 360 0 0)) (test "4.04.05: ((value-op 360 1 1) 360 1 1)" #:LEGAL (collect-values (value-op 360 1 1) 360 1 1)) (test "4.04.06: ((value-op 0 1 1) 360 0 0)" #:LEGAL (collect-values (value-op 0 1 1) 360 0 0)) (test "4.04.07: ((value-op 360 0 0) 360 1 1)" #:LEGAL (collect-values (value-op 360 0 0) 360 1 1)) (test "4.04.08: ((value-op 118 0.5 0.25) 118 0.5 0.25)" #:LEGAL (collect-values (value-op 118 0.5 0.25) 118 0.5 0.25)) (test "4.04.09: ((value-op 99 1 1) 118 0.5 0.25)" #:LEGAL (collect-values (value-op 99 1 1) 118 0.5 0.25)) (test "4.04.10: ((value-op 99 0 0) 118 0.5 0.25)" #:LEGAL (collect-values (value-op 99 0 0) 118 0.5 0.25)) (test "4.04.11: ((value-op 44 1 0.007) 271 0.01 0.002)" #:LEGAL (collect-values (value-op 44 1 0.007) 271 0.01 0.002)) (test "4.04.12: ((value-op 31 1 1) 224 0.999 0.9)" #:LEGAL (collect-values (value-op 31 1 1) 224 0.999 0.9)) (test "4.04.13: ((value-op 88 0.02 0.93) 88 0 1)" #:LEGAL (collect-values (value-op 88 0.02 0.93) 88 0 1)) (test "4.04.14: ((value-op 88 1 0) 88 0 1)" #:LEGAL (collect-values (value-op 88 1 0) 88 0 1)) (test "4.04.15: ((value-op 75 0.95 0.0001) 74 1 0)" #:LEGAL (collect-values (value-op 75 0.95 0.0001) 74 1 0)) (test "4.04.16: ((value-op 299 0.65 0.07) 144 1.0 0.999)" #:LEGAL (collect-values (value-op 299 0.65 0.07) 144 1.0 0.999)) (test "4.04.17: ((value-op 248 0.002 1.0) 243 0.0007 0.4)" #:LEGAL (collect-values (value-op 248 0.002 1.0) 243 0.0007 0.4))) )) (test-group "[5] RGB <-> HSV conversions" (test-group "[5.01] rgb>hsv - match results" (with-comparator list-fuzzy= (test "5.01.01: (rgb>hsv 1.000 1.000 1.000)" '(0 0.000 1.000) (collect-values rgb>hsv 1.000 1.000 1.000)) (test "5.01.02: (rgb>hsv 1.000 0.000 0.000)" '(0 1.000 1.000) (collect-values rgb>hsv 1.000 0.000 0.000)) (test "5.01.03: (rgb>hsv 0.710 0.294 0.294)" '(0 0.586 0.710) (collect-values rgb>hsv 0.710 0.294 0.294)) (test "5.01.04: (rgb>hsv 0.557 0.000 0.000)" '(0 1.000 0.557) (collect-values rgb>hsv 0.557 0.000 0.000)) (test "5.01.05: (rgb>hsv 0.769 0.769 0.769)" '(0 0.000 0.769) (collect-values rgb>hsv 0.769 0.769 0.769)) (test "5.01.06: (rgb>hsv 0.831 1.000 0.000)" '(70 1.000 1.000) (collect-values rgb>hsv 0.831 1.000 0.000)) (test "5.01.07: (rgb>hsv 0.733 0.859 0.145)" '(71 0.831 0.859) (collect-values rgb>hsv 0.733 0.859 0.145)) (test "5.01.08: (rgb>hsv 0.686 0.788 0.216)" '(71 0.726 0.788) (collect-values rgb>hsv 0.686 0.788 0.216)) (test "5.01.09: (rgb>hsv 0.522 0.522 0.522)" '(0 0.000 0.522) (collect-values rgb>hsv 0.522 0.522 0.522)) (test "5.01.10: (rgb>hsv 0.000 1.000 0.416)" '(145 1.000 1.000) (collect-values rgb>hsv 0.000 1.000 0.416)) (test "5.01.11: (rgb>hsv 0.427 0.576 0.490)" '(145 0.259 0.576) (collect-values rgb>hsv 0.427 0.576 0.490)) (test "5.01.12: (rgb>hsv 0.000 0.886 0.376)" '(145 1.000 0.886) (collect-values rgb>hsv 0.000 0.886 0.376)) (test "5.01.13: (rgb>hsv 0.251 0.251 0.251)" '(0 0.000 0.251) (collect-values rgb>hsv 0.251 0.251 0.251)) (test "5.01.14: (rgb>hsv 0.000 0.369 1.000)" '(218 1.000 1.000) (collect-values rgb>hsv 0.000 0.369 1.000)) (test "5.01.15: (rgb>hsv 0.239 0.439 0.765)" '(217 0.687 0.765) (collect-values rgb>hsv 0.239 0.439 0.765)) (test "5.01.16: (rgb>hsv 0.333 0.459 0.671)" '(218 0.503 0.671) (collect-values rgb>hsv 0.333 0.459 0.671)) (test "5.01.17: (rgb>hsv 0.000 0.000 0.000)" '(0 0.000 0.000) (collect-values rgb>hsv 0.000 0.000 0.000)) (test "5.01.18: (rgb>hsv 0.788 0.000 1.000)" '(287 1.000 1.000) (collect-values rgb>hsv 0.788 0.000 1.000)) (test "5.01.19: (rgb>hsv 0.757 0.078 0.925)" '(288 0.915 0.925) (collect-values rgb>hsv 0.757 0.078 0.925)) (test "5.01.20: (rgb>hsv 0.745 0.098 0.906)" '(288 0.892 0.906) (collect-values rgb>hsv 0.745 0.098 0.906)) )) (test-group "[5.02] hsv>rgb - match results" (with-comparator list-fuzzy= (test "5.02.01: (hsv>rgb 0 0.000 1.000)" '(1.000 1.000 1.000) (collect-values hsv>rgb 0 0.000 1.000)) (test "5.02.02: (hsv>rgb 0 1.000 1.000)" '(1.000 0.000 0.000) (collect-values hsv>rgb 0 1.000 1.000)) (test "5.02.03: (hsv>rgb 0 0.586 0.710)" '(0.710 0.294 0.294) (collect-values hsv>rgb 0 0.586 0.710)) (test "5.02.04: (hsv>rgb 0 1.000 0.557)" '(0.557 0.000 0.000) (collect-values hsv>rgb 0 1.000 0.557)) (test "5.02.05: (hsv>rgb 0 0.000 0.769)" '(0.769 0.769 0.769) (collect-values hsv>rgb 0 0.000 0.769)) (test "5.02.06: (hsv>rgb 70 1.000 1.000)" '(0.831 1.000 0.000) (collect-values hsv>rgb 70 1.000 1.000)) (test "5.02.07: (hsv>rgb 71 0.831 0.859)" '(0.733 0.859 0.145) (collect-values hsv>rgb 71 0.831 0.859)) (test "5.02.08: (hsv>rgb 71 0.726 0.788)" '(0.686 0.788 0.216) (collect-values hsv>rgb 71 0.726 0.788)) (test "5.02.09: (hsv>rgb 0 0.000 0.522)" '(0.522 0.522 0.522) (collect-values hsv>rgb 0 0.000 0.522)) (test "5.02.10: (hsv>rgb 145 1.000 1.000)" '(0.000 1.000 0.416) (collect-values hsv>rgb 145 1.000 1.000)) (test "5.02.11: (hsv>rgb 145 0.259 0.576)" '(0.427 0.576 0.490) (collect-values hsv>rgb 145 0.259 0.576)) (test "5.02.12: (hsv>rgb 145 1.000 0.886)" '(0.000 0.886 0.376) (collect-values hsv>rgb 145 1.000 0.886)) (test "5.02.13: (hsv>rgb 0 0.000 0.251)" '(0.251 0.251 0.251) (collect-values hsv>rgb 0 0.000 0.251)) (test "5.02.14: (hsv>rgb 218 1.000 1.000)" '(0.000 0.369 1.000) (collect-values hsv>rgb 218 1.000 1.000)) (test "5.02.15: (hsv>rgb 217 0.687 0.765)" '(0.239 0.439 0.765) (collect-values hsv>rgb 217 0.687 0.765)) (test "5.02.16: (hsv>rgb 218 0.503 0.671)" '(0.333 0.459 0.671) (collect-values hsv>rgb 218 0.503 0.671)) (test "5.02.17: (hsv>rgb 0 0.000 0.000)" '(0.000 0.000 0.000) (collect-values hsv>rgb 0 0.000 0.000)) (test "5.02.18: (hsv>rgb 287 1.000 1.000)" '(0.788 0.000 1.000) (collect-values hsv>rgb 287 1.000 1.000)) (test "5.02.19: (hsv>rgb 288 0.915 0.925)" '(0.757 0.078 0.925) (collect-values hsv>rgb 288 0.915 0.925)) (test "5.02.20: (hsv>rgb 288 0.892 0.906)" '(0.745 0.098 0.906) (collect-values hsv>rgb 288 0.892 0.906)) )) (test-group "[5.03] RGB -> HSV -> RGB roundtrip" (with-comparator list-fuzzy= (test "5.03.01: (hsv>rgb (rgb>hsv 1.000 1.000 1.000))" '(1.000 1.000 1.000) (collect-values* (lambda () (call-with-values (lambda () (rgb>hsv 1.000 1.000 1.000)) hsv>rgb)))) (test "5.03.02: (hsv>rgb (rgb>hsv 1.000 0.000 0.000))" '(1.000 0.000 0.000) (collect-values* (lambda () (call-with-values (lambda () (rgb>hsv 1.000 0.000 0.000)) hsv>rgb)))) (test "5.03.03: (hsv>rgb (rgb>hsv 0.710 0.294 0.294))" '(0.710 0.294 0.294) (collect-values* (lambda () (call-with-values (lambda () (rgb>hsv 0.710 0.294 0.294)) hsv>rgb)))) (test "5.03.04: (hsv>rgb (rgb>hsv 0.557 0.000 0.000))" '(0.557 0.000 0.000) (collect-values* (lambda () (call-with-values (lambda () (rgb>hsv 0.557 0.000 0.000)) hsv>rgb)))) (test "5.03.05: (hsv>rgb (rgb>hsv 0.769 0.769 0.769))" '(0.769 0.769 0.769) (collect-values* (lambda () (call-with-values (lambda () (rgb>hsv 0.769 0.769 0.769)) hsv>rgb)))) (test "5.03.06: (hsv>rgb (rgb>hsv 0.831 1.000 0.000))" '(0.831 1.000 0.000) (collect-values* (lambda () (call-with-values (lambda () (rgb>hsv 0.831 1.000 0.000)) hsv>rgb)))) (test "5.03.07: (hsv>rgb (rgb>hsv 0.733 0.859 0.145))" '(0.733 0.859 0.145) (collect-values* (lambda () (call-with-values (lambda () (rgb>hsv 0.733 0.859 0.145)) hsv>rgb)))) (test "5.03.08: (hsv>rgb (rgb>hsv 0.686 0.788 0.216))" '(0.686 0.788 0.216) (collect-values* (lambda () (call-with-values (lambda () (rgb>hsv 0.686 0.788 0.216)) hsv>rgb)))) (test "5.03.09: (hsv>rgb (rgb>hsv 0.522 0.522 0.522))" '(0.522 0.522 0.522) (collect-values* (lambda () (call-with-values (lambda () (rgb>hsv 0.522 0.522 0.522)) hsv>rgb)))) (test "5.03.10: (hsv>rgb (rgb>hsv 0.000 1.000 0.416))" '(0.000 1.000 0.416) (collect-values* (lambda () (call-with-values (lambda () (rgb>hsv 0.000 1.000 0.416)) hsv>rgb)))) (test "5.03.11: (hsv>rgb (rgb>hsv 0.427 0.576 0.490))" '(0.427 0.576 0.490) (collect-values* (lambda () (call-with-values (lambda () (rgb>hsv 0.427 0.576 0.490)) hsv>rgb)))) (test "5.03.12: (hsv>rgb (rgb>hsv 0.000 0.886 0.376))" '(0.000 0.886 0.376) (collect-values* (lambda () (call-with-values (lambda () (rgb>hsv 0.000 0.886 0.376)) hsv>rgb)))) (test "5.03.13: (hsv>rgb (rgb>hsv 0.251 0.251 0.251))" '(0.251 0.251 0.251) (collect-values* (lambda () (call-with-values (lambda () (rgb>hsv 0.251 0.251 0.251)) hsv>rgb)))) (test "5.03.14: (hsv>rgb (rgb>hsv 0.000 0.369 1.000))" '(0.000 0.369 1.000) (collect-values* (lambda () (call-with-values (lambda () (rgb>hsv 0.000 0.369 1.000)) hsv>rgb)))) (test "5.03.15: (hsv>rgb (rgb>hsv 0.239 0.439 0.765))" '(0.239 0.439 0.765) (collect-values* (lambda () (call-with-values (lambda () (rgb>hsv 0.239 0.439 0.765)) hsv>rgb)))) (test "5.03.16: (hsv>rgb (rgb>hsv 0.333 0.459 0.671))" '(0.333 0.459 0.671) (collect-values* (lambda () (call-with-values (lambda () (rgb>hsv 0.333 0.459 0.671)) hsv>rgb)))) (test "5.03.17: (hsv>rgb (rgb>hsv 0.000 0.000 0.000))" '(0.000 0.000 0.000) (collect-values* (lambda () (call-with-values (lambda () (rgb>hsv 0.000 0.000 0.000)) hsv>rgb)))) (test "5.03.18: (hsv>rgb (rgb>hsv 0.788 0.000 1.000))" '(0.788 0.000 1.000) (collect-values* (lambda () (call-with-values (lambda () (rgb>hsv 0.788 0.000 1.000)) hsv>rgb)))) (test "5.03.19: (hsv>rgb (rgb>hsv 0.757 0.078 0.925))" '(0.757 0.078 0.925) (collect-values* (lambda () (call-with-values (lambda () (rgb>hsv 0.757 0.078 0.925)) hsv>rgb)))) (test "5.03.20: (hsv>rgb (rgb>hsv 0.745 0.098 0.906))" '(0.745 0.098 0.906) (collect-values* (lambda () (call-with-values (lambda () (rgb>hsv 0.745 0.098 0.906)) hsv>rgb)))) )) (test-group "[5.04] HSV -> RGB -> HSV roundtrip" (with-comparator list-fuzzy= (test "5.04.01: (rgb>hsv (hsv>rgb 0 0.000 1.000))" '(0 0.000 1.000) (collect-values* (lambda () (call-with-values (lambda () (hsv>rgb 0 0.000 1.000)) rgb>hsv)))) (test "5.04.02: (rgb>hsv (hsv>rgb 0 1.000 1.000))" '(0 1.000 1.000) (collect-values* (lambda () (call-with-values (lambda () (hsv>rgb 0 1.000 1.000)) rgb>hsv)))) (test "5.04.03: (rgb>hsv (hsv>rgb 0 0.586 0.710))" '(0 0.586 0.710) (collect-values* (lambda () (call-with-values (lambda () (hsv>rgb 0 0.586 0.710)) rgb>hsv)))) (test "5.04.04: (rgb>hsv (hsv>rgb 0 1.000 0.557))" '(0 1.000 0.557) (collect-values* (lambda () (call-with-values (lambda () (hsv>rgb 0 1.000 0.557)) rgb>hsv)))) (test "5.04.05: (rgb>hsv (hsv>rgb 0 0.000 0.769))" '(0 0.000 0.769) (collect-values* (lambda () (call-with-values (lambda () (hsv>rgb 0 0.000 0.769)) rgb>hsv)))) (test "5.04.06: (rgb>hsv (hsv>rgb 70 1.000 1.000))" '(70 1.000 1.000) (collect-values* (lambda () (call-with-values (lambda () (hsv>rgb 70 1.000 1.000)) rgb>hsv)))) (test "5.04.07: (rgb>hsv (hsv>rgb 71 0.831 0.859))" '(71 0.831 0.859) (collect-values* (lambda () (call-with-values (lambda () (hsv>rgb 71 0.831 0.859)) rgb>hsv)))) (test "5.04.08: (rgb>hsv (hsv>rgb 71 0.726 0.788))" '(71 0.726 0.788) (collect-values* (lambda () (call-with-values (lambda () (hsv>rgb 71 0.726 0.788)) rgb>hsv)))) (test "5.04.09: (rgb>hsv (hsv>rgb 0 0.000 0.522))" '(0 0.000 0.522) (collect-values* (lambda () (call-with-values (lambda () (hsv>rgb 0 0.000 0.522)) rgb>hsv)))) (test "5.04.10: (rgb>hsv (hsv>rgb 145 1.000 1.000))" '(145 1.000 1.000) (collect-values* (lambda () (call-with-values (lambda () (hsv>rgb 145 1.000 1.000)) rgb>hsv)))) (test "5.04.11: (rgb>hsv (hsv>rgb 145 0.259 0.576))" '(145 0.259 0.576) (collect-values* (lambda () (call-with-values (lambda () (hsv>rgb 145 0.259 0.576)) rgb>hsv)))) (test "5.04.12: (rgb>hsv (hsv>rgb 145 1.000 0.886))" '(145 1.000 0.886) (collect-values* (lambda () (call-with-values (lambda () (hsv>rgb 145 1.000 0.886)) rgb>hsv)))) (test "5.04.13: (rgb>hsv (hsv>rgb 0 0.000 0.251))" '(0 0.000 0.251) (collect-values* (lambda () (call-with-values (lambda () (hsv>rgb 0 0.000 0.251)) rgb>hsv)))) (test "5.04.14: (rgb>hsv (hsv>rgb 218 1.000 1.000))" '(218 1.000 1.000) (collect-values* (lambda () (call-with-values (lambda () (hsv>rgb 218 1.000 1.000)) rgb>hsv)))) (test "5.04.15: (rgb>hsv (hsv>rgb 217 0.687 0.765))" '(217 0.687 0.765) (collect-values* (lambda () (call-with-values (lambda () (hsv>rgb 217 0.687 0.765)) rgb>hsv)))) (test "5.04.16: (rgb>hsv (hsv>rgb 218 0.503 0.671))" '(218 0.503 0.671) (collect-values* (lambda () (call-with-values (lambda () (hsv>rgb 218 0.503 0.671)) rgb>hsv)))) (test "5.04.17: (rgb>hsv (hsv>rgb 0 0.000 0.000))" '(0 0.000 0.000) (collect-values* (lambda () (call-with-values (lambda () (hsv>rgb 0 0.000 0.000)) rgb>hsv)))) (test "5.04.18: (rgb>hsv (hsv>rgb 287 1.000 1.000))" '(287 1.000 1.000) (collect-values* (lambda () (call-with-values (lambda () (hsv>rgb 287 1.000 1.000)) rgb>hsv)))) (test "5.04.19: (rgb>hsv (hsv>rgb 288 0.915 0.925))" '(288 0.915 0.925) (collect-values* (lambda () (call-with-values (lambda () (hsv>rgb 288 0.915 0.925)) rgb>hsv)))) (test "5.04.20: (rgb>hsv (hsv>rgb 288 0.892 0.906))" '(288 0.892 0.906) (collect-values* (lambda () (call-with-values (lambda () (hsv>rgb 288 0.892 0.906)) rgb>hsv)))) )) ) (test-group "[6] Detailed results of composite function" (let* ((all-data (with-input-from-file "ref-pxx-data.scm" (lambda () (read)))) (base-data (alist-ref 'base all-data)) (ref-data (alist-ref 'ref-images all-data))) (let mode-loop ((m 1) (modes default-blend-modes)) (unless (null? modes) (let* ((mode (car modes)) (mode-idx (zpad m 2)) (mode-ref-data (alist-ref mode ref-data string=?))) (test-group (sprintf "[6.~A] ~A" mode-idx mode) (let color-loop ((c 1) (colors default-colors)) (unless (null? colors) (let* ((color (car colors)) (color-idx (zpad c 2)) (color-ref-data (alist-ref color mode-ref-data string=?))) (test-group (sprintf "[6.~A.~A] ~A/~A" mode-idx color-idx mode color) (let alpha-loop ((a 1) (alphas default-alpha-levels)) (unless (null? alphas) (let* ((alpha (car alphas)) (alpha-idx (zpad c 2)) (alpha-ref-data (alist-ref alpha color-ref-data string=?))) (test-group (sprintf "[6.~A.~A.~A] ~A/~A/~A" mode-idx color-idx alpha-idx mode color alpha) (let* ((blend-op (mk-blend-op (string-append "#" color) blend-mode: (mode-sym mode) alpha: (string->number alpha))) (rows (length base-data)) (cols (length (car base-data)))) (let pix-loop ((y 0) (x 0)) (cond ((>= y rows) #f) ((>= x cols) (pix-loop (+ y 1) 0)) (else (let* ((in-pixel (list-ref (list-ref base-data y) x)) (out-pixel (list-ref (list-ref alpha-ref-data y) x)) (inr (/ (car in-pixel) 255)) (ing (/ (cadr in-pixel) 255)) (inb (/ (caddr in-pixel) 255)) (ina (/ (cadddr in-pixel) 255))) (test (sprintf "6.~A.~A.~A-~A-~A: ~A/~A/~A (~A, ~A)" mode-idx color-idx alpha-idx x y mode color alpha x y) out-pixel (collect-values blend-op inr ing inb ina))) (pix-loop y (+ x 1)))))))) (alpha-loop (+ a 1) (cdr alphas))))))) (color-loop (+ c 1) (cdr colors)))))) (mode-loop (+ m 1) (cdr modes))))) (test-exit) ; (test-group "[6] Detailed results of composite function" ; (let ((ref-data (with-input-from-file "ref-pxx-data.scm" (lambda () (read))))) ; (let mode-loop ((m 1) (modes default-blend-modes)) ; (unless (null? modes) ; (let ((mode (car modes)) ; (mode-idx (zpad m 2))) ; (test-group (sprintf "[6.~A] ~A" mode-idx mode) ; (let color-loop ((c 1) (colors default-colors)) ; (unless (null? colors) ; (let ((color (car colors)) ; (color-idx (zpad c 2))) ; (test-group (sprintf "[6.~A.~A] ~A/~A" mode-idx color-idx mode color) ; (let alpha-loop ((a 1) (alphas default-alphas)) ; (unless (null? alphas) ; (let ((alpha (car alphas)) ; (alpha-idx (zpad c 2))) ; (test-group ; (sprintf "[6.~A.~A.~A] ~A/~A/~A" ; mode-idx color-idx alpha-idx mode color alpha) ; (let* ((test-img-path (mk-img-path "images/test" mode color alpha)) ; (img (image-load test-img-path)) ; (test-pxx (sample-pixels img 4 8 y0: 2 ystep: 4)) ; (rows (length test-pxx)) ; (cols (length (car test-pxx)))) ; (image-destroy img) ; (let pix-loop ((y 0) (x 0)) ; (cond ; ((>= y rows) #f) ; ((>= x cols) (pix-loop (+ y 1) 0)) ; (else ; (let ((ref-pixel (list-ref (list-ref ref-pxx y) x)) ; (test-pixel (list-ref (list-ref test-pxx y) x))) ; (test ; (sprintf "6.~A.~A.~A-~A-~A: ~A/~A/~A (~A, ~A)" ; mode-idx color-idx alpha-idx x y ; mode color alpha x y) ; ref-pixel ; test-pixel)) ; (pix-loop y (+ x 1)))))))) ; (alpha-loop (+ a 1) (cdr alphas))))))) ; (color-loop (+ c 1) (cdr colors)))))) ; (mode-loop (+ m 1) (cdr modes))))) ; ; (test-exit) ;
false
acf8ecc883187e1a6d8314f3d5b9f27e387b5730
e3d507b46b1588f11510b238dd47aac9f0cd0d4a
/06-scheme-4-2020/scm/csound/compile.scm
f22c145fe3830d9c4d8103e21d03e7bdb316a0ce
[]
no_license
noisesmith/abject-noise
a630b33ac752b14046cb4fee4dd763ed4693c315
68a03bc4760e647768e025b13a89bfa77f5ac541
refs/heads/master
2021-10-11T11:51:34.342060
2021-09-30T18:57:57
2021-09-30T18:57:57
204,066,569
0
0
null
null
null
null
UTF-8
Scheme
false
false
911
scm
compile.scm
(define-module (csound compile) #:export (compile <assignment>) #:use-module (noisesmith clojure) #:re-export (ht)) (use-modules (ice-9 format) (oop goops)) (define-generic compile) (define-method (compile (unit <string>)) unit) (define-method (compile (unit <number>)) (compile (number->string unit))) (define-method (compile (unit <list>)) (string-join (map compile unit) " ")) (define-class <assignment> () (lvals #:init-keyword #:lvals #:getter lvals) (opcode #:init-keyword #:opcode #:getter opcode) (parameters #:init-keyword #:parameters #:getter parameters)) (define (paramlist l) (string-join (map compile l) ", ")) (define-method (compile (unit <assignment>)) (format #f "~10a ~a ~a" (paramlist (lvals unit)) (compile (opcode unit)) (paramlist (parameters unit))))
false
f9e7bcde6d5124fa02bf11ac12f06eb2b8742458
8def8726df4eb28d7b22d123c7e3a208d5577999
/new/www/help.ss
a97c804079da5b1aa724b26741d6d3a23a7eb7f1
[]
no_license
racket/old-web
9e0afa241fe443ddb5e9fa083d58c978ed38b459
d7b670c23e570d398257fbc7b658b3948a5f3d81
refs/heads/master
2022-11-11T09:46:58.220698
2020-06-25T13:12:02
2020-06-25T13:12:02
274,562,458
1
1
null
null
null
null
UTF-8
Scheme
false
false
2,172
ss
help.ss
#lang at-exp s-exp "shared.ss" (require "common.ss") (define/provide help (page #:title "Need Help?" #:offer-help? #f (parlist @strong{Don't Panic!} @text{PLT Scheme has a variety of resources designed to help you with any problems you may have.}) (parlist @strong{Help Desk} @text{Your first stop should always be with the help system that's built into PLT Scheme and available from the DrScheme menu @strong{or by pressing F1 with the cursor on a search term}. This documentation is customized for your installation, and may include documentation for optional packages you've installed. As a second line of defense, the documentation for the core of the most recent version of PLT Scheme is available @a[href: "http://docs.plt-scheme.org"]{from this web site}.} @text{Not sure what to search for? The documentation includes a @a[href: "http://docs.plt-scheme.org/guide/"]{guide} (also located in your local copy of the documentation) that provides a narrative introduction to many of PLT Scheme's features.}) (parlist @strong{Learning how to Program} @text{Try going through @|htdp|.}) (parlist @strong{Searching the Web} @text{The @a[href: "http://www.schemecookbook.org"]{Scheme Cookbook} is a wiki for Scheme snippets (though not a PLT-specific one). Additionally, your favorite search engine may well provide answers for many of your questions, particularly if you include "PLT" as a search term.}) (parlist @strong{The Mailing List} @text{The @tt{plt-scheme} mailing list is a great source for answers to questions when the above resources don't pan out; sign up for it in the @a[href: "community.html"]{community} area of the website.}) @br @text{Thanks for using PLT Scheme!}))
false
759ee63be3bce317e41498e2ac1e30feef2ba3c5
bcfa2397f02d5afa93f4f53c0b0a98c204caafc1
/scheme/chapter2/ex2_23_test.scm
70e6c25b69601620ad5f01e137e81a8ca2f58c7c
[]
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
215
scm
ex2_23_test.scm
;; SICP Test 2.23 (test-case "Ex 2.23 For Each" (let ((result ())) (for-each-1 (lambda (x) (set! result (cons x result))) (list 57 321 88)) (assert-equal '(88 321 57) result)))
false
a06ca5c37d62f438babd6eeb1d74916c2dbf4018
26aaec3506b19559a353c3d316eb68f32f29458e
/modules/ssax/stx-engine.scm
75dba1fa9dd2c3bba1b28b6804bf8788f7c1994b
[ "BSD-3-Clause" ]
permissive
mdtsandman/lambdanative
f5dc42372bc8a37e4229556b55c9b605287270cd
584739cb50e7f1c944cb5253966c6d02cd718736
refs/heads/master
2022-12-18T06:24:29.877728
2020-09-20T18:47:22
2020-09-20T18:47:22
295,607,831
1
0
NOASSERTION
2020-09-15T03:48:04
2020-09-15T03:48:03
null
UTF-8
Scheme
false
false
20,388
scm
stx-engine.scm
;;(include "../libs/input-parse.sch") ;;(include "../multi-parser/id/http.sch") ;;(include "../multi-parser/id/srfi-12.sch") ;;(include "../libs/gambit/myenv.sch") ;;(include "../libs/gambit/common.sch") ;;(include "../sxml-tools/sxml-tools.sch") ;;(include "../ssax/SSAX-code.sch") ;;(include "../stx/stx-engine.sch") ;; $Id: stx-engine.scm,v 1.9403 2002/12/25 19:33:48 kl Exp kl $ ; DL: if you are not using "access-remote.scm", uncomment the following line ;(define open-input-resource open-input-file) ;============================================================================= ; Auxilliary (define stx:version (string-append " $Revision: 1.9403 $" nl " $Date: 2002/12/25 19:33:48 $")) (define (stx:error . messages) (cerr nl "STX: ") (apply cerr messages) (cerr nl) (exit -1)) ; Reads content of a given SXML element 'obj' using Scheme reader. ; The content has to be a list of strings (first of them will be read). ; If the content is empty, "" is returned. (define (stx:read-content obj objname) (let ((ct (sxml:content obj))) (cond ((null? ct) "") ((string? (car ct)) (with-exception-handler (lambda(mes) (apply stx:error `("Error " ,nl ,mes ,nl "reading " ,objname " code:" ,nl ,(car ct) ,nl "from element" ,nl ,@(sxml:clean-feed (sxml:sxml->xml obj)) ,nl)) (exit)) (lambda() (call-with-input-string (car ct) read)))) (else (stx:error "Invalid " objname " element:" nl obj))) )) (define (stx:clean-feed . fragments) (reverse (let loop ((fragments fragments) (result '())) (cond ((null? fragments) result) ((not (car fragments)) (loop (cdr fragments) result)) ((null? (car fragments)) (loop (cdr fragments) result)) (else (loop (cdr fragments) (cons (car fragments) result))))))) ; DL: Borrowed from the older version of SXML Tools ; Filter the 'fragments' ; The fragments are a list of strings, characters, ; numbers, thunks, #f -- and other fragments. ; The function traverses the tree depth-first, and returns a list ; of strings, characters and executed thunks, and ignores #f and '(). ; ; If all the meaningful fragments are strings, then ; (apply string-append ... ) ; to a result of this function will return its string-value ; ; It may be considered as a variant of Oleg Kiselyov's SRV:send-reply: ; While SRV:send-reply displays fragments, this function returns the list ; of meaningful fragments and filter out the garbage. (define (sxml:clean-feed . fragments) (reverse (let loop ((fragments fragments) (result '())) (cond ((null? fragments) result) ((not (car fragments)) (loop (cdr fragments) result)) ((null? (car fragments)) (loop (cdr fragments) result)) ((pair? (car fragments)) (loop (cdr fragments) (loop (car fragments) result))) ; ((procedure? (car fragments)) ; (loop (cdr fragments) ; (cons ((car fragments)) ; result))) (else (loop (cdr fragments) (cons (car fragments) result))))))) ;----------------------------------------------------------------------------- ; This functions will be probably moved to sxml-tools ; Transforms top-level *NAMESPACES* in SXML document ; parsed using SSAX 4.9 to aux-list representation compatible to ; SXML-spec. ver. 2.5 (define (sxml:refactor-ns tree) (if (and (pair? tree) (pair? (cdr tree)) (pair? (cadr tree)) (eq? '*NAMESPACES* (caadr tree))) `(,(car tree) (@@ (*NAMESPACES* ,@(cdadr tree))) ,@(cddr tree)) tree)) ; Reads XML document as SXML tree. NS prefixes declared in XML document ; are used as namespace-id's. (define (sxml:xml->sxml-autoprefix name) (sxml:refactor-ns ; workaround for SSAX 4.9 (let ((ns-list (sxml:extract-prefix-assigs name))) (ssax:xml->sxml (open-input-resource name) ns-list)))) ; Extracts a value of attribute with given name from attr-list ;(define (sxml:attr-from-list attr-list name) ; (cond ; ((assq name attr-list) ; => cadr) ; (else #f))) ; Reads a root element of given XML file and returns a list ; of NS-prefix/URIs declared as a list of pairs. (define (sxml:extract-prefix-assigs file) (call-with-input-file file (lambda (p) (ssax:skip-S p) (let loop ((lst (ssax:read-markup-token p))) (case (car lst) ((PI) ; Processing instruction (ssax:skip-pi p) ; ignore until the end (ssax:skip-S p) (loop (ssax:read-markup-token p))) ((START) (filter-and-map (lambda(x) (and (pair? (car x)) (eq? 'xmlns (caar x)))) (lambda(x) (cons (cdar x) (cdr x))) (ssax:read-attributes p '()))) (else (display "Unknown token type: ") (display (car lst)) (exit))))))) ;============================================================================= ; Tree transformation ; stx:apply-templates:: <tree> x <templates> x <root> x <environment> -> <new-tree> ; where ; <templates> ::= <default-template> <text-template> <template>* ; <default-template> ::= (*default* . <handler>) ; <text-template> ::= (*text* . <handler>) ; <template> ::= (<matcher> <handler>) | ( XMLname <handler>) ; <root> ::= <document-root> ; <environment> ::= <lambda-tuple> ; <matcher> ::= <node> <root> -> <nodeset> ; <handler> :: <node> <templates> <root> <environment> -> <new-node> ; ; The stx:apply-templates function visits top-level nodes of a given tree and ; process them in accordance with a list of templates given. ; If a node is a textual one then it is processed usind 'text-template', ; which has to be second element in given list of templates. ; If a node is a pair then stx:apply-templates looks up a corresponding template ; among given <templates> using stx:find-template function. ; If failed, stx:apply-templates tries to locate a *default* template, ; which has to be first element in given list of templates. It's an ; error if this latter attempt fails as well. ; Having found a template, its handler is applied to the current node. ; The result of the handler application, which should ; also be a <tree>, replaces the current node in output tree. ; ; This function is slightly similar to Oleg Kiselyov's "pre-post-order" function ; with *preorder* bindings. (define (stx:apply-templates tree templates root environment) (cond ((nodeset? tree) (map (lambda (a-tree) (stx:apply-templates a-tree templates root environment)) tree)) ((pair? tree) (cond ((tee-4 "Template: " (stx:find-template tree (cddr templates) ; *default* and *text* skipped root)) => (lambda (template) ((cadr template) tree templates root environment))) (else (if (eq? '*default* (caar templates)) ((cadar templates) tree templates root environment) (stx:error "stx:apply-templates: There is no template in: " templates ; nl "for: " tree )) ))) ((string? tree) ; *text* (if (eq? '*text* (caadr templates)) ((cadadr templates) tree) (stx:error "stx:apply-templates: There is no *text* templates for: " templates))) (else (stx:error "Unexpected type of node: " tree)))) ; stx:find-template: <node> x <templates> x <root> -> <template> ; This function returns first template in <templates> whouse <matcher> ; matches given <node> ; <matcher> matches node if: ; - if it is a symbol and its the same as the name of the node matched ; - if it is a procedure (sxpath/txpath generated one) then it is ; applyed (with respect to given <root>) sequentially to the matched node ; and its parents until the matched node is a member of a resulting nodeset ; or root node is reached. In the first case the node matches successfuly, ; in the second case it does not. (define (stx:find-template node templates root) (let ((pattern-matches? (lambda (node pattern-test) (let rpt ((context-node node)) (cond ((null? context-node) #f) ((memq node (pattern-test context-node `((*root* ,root)))) #t) (else ; try PARENT (rpt ((sxml:node-parent root) context-node)))))))) (let rpt ((bnd templates)) (cond ((null? bnd) #f) ((and (symbol? (caar bnd)) (eq? (caar bnd) (car node))) (car bnd)) ((and (procedure? (caar bnd)) ; redundant? (pattern-matches? node (caar bnd))) (car bnd)) (else (rpt (cdr bnd))))))) ; Returns SXML tree for a given link. ; A link is a lambda-tuple of its attributes. (define (stx:load-sst link) ((cond ((equal? (link 'type) "stx") (lambda(x) (call-with-input-file x read))) ((equal? (link 'type) "sxml") (stx:make-stx-stylesheet (lambda(x) (call-with-input-file x read)))) ; default is xml (else (lambda(x) (stx:make-stx-stylesheet (sxml:xml->sxml-autoprefix x))))) (link 'href))) ; Transform top-level objects of stx:stylesheet ; to a list whose car is corresponding template (#f no templates generated) ; and whose cadr is corresponding environment binding (#f if no bindings), (define (stx:stx->tmpl+env stx-objects) (let rpt ((objs stx-objects) (templts '()) (envrt '())) (cond ((null? objs) (list (reverse templts) envrt)) ; templates ((eq? (caar objs) 'stx:template) (let* ((obj (car objs)) (handler (caddr obj))) (rpt (cdr objs) (cond ((sxml:attr obj 'match) => (lambda (x) (cons (list `(sxpath ,x) handler) ;(list `(sxp:xpath+root ,x) handler) templts))) ((sxml:attr obj 'match-lambda) => (lambda (x) (cons (list x handler) templts))) (else (verb-2 nl "NO match for: " (cadr obj)) templts)) (cond ((sxml:attr obj 'name) => (lambda (x) (cons (list (string->symbol x) handler) envrt))) (else (verb-2 nl "NO name for: " (cadr obj) "==" (sxml:attr obj 'name)) envrt))))) ((eq? (caar objs) 'stx:variable) (let* ((obj (car objs)) (name (sxml:attr obj 'name)) (code (caddr obj))) ; (sxml:content obj) (rpt (cdr objs) templts (cons (list (string->symbol name) code) envrt)))) (else (verb-2 nl "Unrecognized object: " (caar objs) nl) (rpt (cdr objs) templts envrt))))) ; (define (stx:write-ss t+e fname) (let* ((of ; DL: replacing this non-R5RS call with the following piece of code ;(open-output-file fname 'replace) (begin (when (file-exists? fname) (delete-file fname)) (open-output-file fname))) (wrt (lambda x (for-each (lambda(y) (display y of)) x)))) (wrt "#cs(module transform mzscheme" nl "(require" nl "(rename (lib \"list.ss\") sort mergesort)" nl "(lib \"stx-engine.ss\" \"sxml\")" nl "(lib \"util.ss\" \"ssax\")" nl "(lib \"txpath.ss\" \"sxml\")" nl "(lib \"sxpath-ext.ss\" \"sxml\")" nl "(lib \"sxml-tools.ss\" \"sxml\")" nl "(lib \"sxpathlib.ss\" \"sxml\")" nl "(lib \"libmisc.ss\" \"sxml\")" nl "(lib \"myenv.ss\" \"ssax\")" nl "(lib \"common.ss\" \"sxml\"))" nl "(provide stylesheet)" nl) (wrt nl "(define stylesheet (list " nl "(list ; templates:") (for-each (lambda(x) (wrt nl "(list ") (pp (car x) of) (wrt "") (pp (cadr x) of) (wrt ")" nl)) (car t+e)) (wrt ") ; end templates" nl nl "( list ; environment:") (for-each (lambda(x) (wrt nl "(list '" (car x) nl) (pp (cadr x) of) (wrt ") ; end of `" (car x) "'" nl)) (cadr t+e)) (wrt ") ; end environment" nl) (wrt ")) ; end stylesheet" nl) (wrt ")" nl) ; end module )) ; transformate given SXML document <doc> using stylesheet <sst> in SXML ; format (define (stx:transform-dynamic doc sst-sxml) (stx:transform doc (stx:eval-transformer (stx:translate sst-sxml)))) ; transformate given SXML document <doc> loading prepared stylesheet from ; a file <sst-file> ; DL: commented out because of DYNAMIC-REQUIRE ;(define (stx:transform-static doc sst-file) ; (stx:transform ; doc ; (dynamic-require sst-file 'stylesheet))) ; writes to a file <sst-file> prepared stylesheet given in SXML format <sst> (define (stx:write-transformer sst file) (stx:write-ss (stx:translate sst) file)) ; evalutes components of given (in Scheme) STX stylesheet and returns a "prepared" ; stylesheet where all the necessary S-expressions are evaluated (define (stx:eval-transformer sst-scm) (list (map (lambda(x) (list (eval (car x)) (eval (cadr x)))) (car sst-scm)) (map (lambda(x) (list (car x) (eval (cadr x)))) (cadr sst-scm)))) ; transforms given SXML document <doc> using prepared (compiled or eval'uated) ; stylesheet <sst-lambda> (define (stx:transform doc sst-lambda) (let ((string-out sxml:sxml->html)) (stx:apply-templates doc ; bindings (tee-3 "Templates: " (append `((*default* ,(lambda (node bindings root environment) (stx:apply-templates (sxml:content node) bindings root environment))) (*text* ,string-out)) (car sst-lambda))) ;root doc ; environment (apply lambda-tuple (tee-3 "Environment: " (append `((stx:version ,stx:version)) (cadr sst-lambda) )))))) ; translate given STX stylesheet <sst> from SXML to Scheme (define (stx:translate sst) (let* ( ; (output-attr ; ; lambda tuple of 'xsl:output' attributes ; (apply lambda-tuple ; (cond ; (((if-car-sxpath '(xsl:stylesheet xsl:output @)) sst) ; => cdr) ; (else '((method "html")))))) ; ((string-out) ; (case (string->symbol (output-attr 'method)) ; ((text) self) ; ((xml) sxml:string->xml) ; (else sxml:sxml->html))) (stx-sst (tee-2 "STX stylesheets: " (append sst (apply append (map (lambda(x) (tee-2 "IMPORTED: " ; just stx:template and stx:variable elements ; are used from imported _STX_ stylesheets ((sxpath '((*or* stx:template stx:variable))) (stx:load-sst (apply lambda-tuple (sxml:attr-list x)))))) ((sxpath '((*or* xsl:import stx:import))) sst)))))) (templates+env (tee-2 "templates+env" (stx:stx->tmpl+env ((sxpath '(*)) stx-sst)))) ) templates+env)) ; Generates an stx:stylesheet from a stylesheet represented as <stx-tree> ; in SXML format (define (stx:make-stx-stylesheet stx-tree) (let* ((output-attr ; lambda tuple of 'xsl:output' attributes (apply lambda-tuple (cond (((if-car-sxpath '(xsl:stylesheet xsl:output @)) stx-tree) => cdr) (else '((method "html")))))) (string-out (case (string->symbol (output-attr 'method)) ((text) 'self) ((xml) 'sxml:string->xml) (else 'sxml:sxml->html))) (custom-prefixes (map string->symbol ((sxpath '(xsl:stylesheet stx:import @ prefix *text*)) stx-tree)))) (cons 'stx:stylesheet (map (lambda(x) (cond ; xsl:template ((eq? (car x) 'xsl:template) (stx:xsl->stx x output-attr string-out custom-prefixes stx-tree)) ; stx:template ((eq? (car x) 'stx:template) (stx:scm->stx x)) ; stx:variable ((eq? (car x) 'stx:variable) (stx:stx-var->stx x)) ; xsl:variable ((eq? (car x) 'xsl:variable) (stx:xsl-var->stx x)) (else x))) ((sxpath `(xsl:stylesheet *)) stx-tree))) )) ;----------------------------------------------------------------------------- ; Transformers for XSL stylesheet elements ; Transforms element stx:template (extracted from XSL stylesheet and ; represented in SXML format) to stx:template (define (stx:scm->stx tmplt) `(stx:template (@ ,@(sxml:attr-list tmplt)) (lambda (current-node stx:templates current-root $) ,(stx:read-content tmplt "<stx:template@match>")))) ; Transforms STX element stx:var to stx:variable (define (stx:stx-var->stx var) `(stx:variable (@ ,@(sxml:attr-list var)) ,(stx:read-content var "<stx:variable"))) ; Transforms XSL element xsl:var to stx:variable (define (stx:xsl-var->stx var) `(stx:variable (@ ,@(sxml:attr-list var)) ',(sxml:content var))) (define (stx:attr->html attr) (if (equal? "" (cadr attr)) `(list " " ,(sxml:ncname attr)) `(list " " ,(sxml:ncname attr) "='" ,(cadr attr) "'"))) ; transforms an xsl:template to stx:template (define (stx:xsl->stx tmplt output-attr doc-string-out custom-prefixes c-root) (let* ; list of template's attributes ((attr-list (sxml:attr-list tmplt)) (sst-method (cond ((sxml:attr-from-list attr-list 'stx:method) => string->symbol) ; xml is default (else 'xml))) ; output string for _template_ (not document!) conversion (sst-string-out (case sst-method ((text) self) ((html) sxml:string->html) (else sxml:sxml->xml)))) `(stx:template (@ ,@attr-list) (lambda (current-node stx:templates current-root $) ,(cons 'list ;(stx:clean-feed (stx:apply-templates (sxml:content tmplt) `((*default* ,(lambda (tt-node bindings root environment) (if (cond ((sxml:name->ns-id (car tt-node)) => (lambda(x) (member (string->symbol x) custom-prefixes))) (else #f)) ; user-defined tag `(stx:call-function ,(sxml:ncname tt-node) "Custom Tag" ,tt-node $) ; XHTML tag (let ((nm (sxml:ncname tt-node)) (content (sxml:content tt-node))) (if (null? content) `(list "<" ,nm ,@(map stx:attr->html (sxml:attr-list tt-node)) "/>") `(list "<" ,nm ,@(map stx:attr->html (sxml:attr-list tt-node)) ">" ,@(stx:apply-templates content bindings root environment) "</" ,nm ">" )))) )) (*text* ; text string in template ,sst-string-out) (xsl:apply-templates ; t-node is <xsl:apply-templates/> ,(lambda (t-node bindings root environment) `(stx:apply-templates ,(cond ((sxml:attr t-node 'select) => (lambda (lp) `((sxpath ,lp) current-node current-root) ;`((sxp:xpath+root ,lp) current-node current-root) )) (else '(sxml:content current-node))) stx:templates current-root $))) (xsl:if ,(lambda (t-node bindings root environment) ``(stx:apply-templates ,(sxml:content ,t-node) bindings root environment) )) (xsl:call-template ; t-node is <xsl:call-template/> ,(lambda (t-node bindings root environment) `(stx:call-function ,(sxml:attr t-node 'name) "Named Template" ,t-node $))) (xsl:value-of ; t-node is <xsl:value-of/> ,(lambda (t-node bindings root environment) `(,(if (equal? "yes" (sxml:attr t-node 'disable-output-escaping)) 'self doc-string-out) (sxml:string ((sxpath ,(sxml:attr t-node 'select)) ;((sxp:xpath ,(sxml:attr t-node 'select)) current-node))))) ; <xsl:copy-of/> (xsl:copy-of ,(lambda (t-node bindings root environment) `((sxpath ,(sxml:attr t-node 'select)) current-node))) ;`((sxp:xpath ,(sxml:attr t-node 'select)) current-node))) (stx:eval ; t-node is <stx:eval/> ,(lambda (t-node bindings root environment) (let ((content (stx:read-content t-node "<stx:eval>"))) `(call-with-err-handler (lambda() (eval ,content)) (lambda(mes) (apply stx:error `("Error " ,nl ,mes ,nl "while evaluating code:" ,nl ,,content ,nl "from element" ,nl ,@(sxml:clean-feed (sxml:sxml->xml ',t-node))))))))) ) c-root (lambda-tuple) ; compile-time environment ))))))
false
c7e6c96e3c45bd399f3814bd6b7bfaba43f942f2
29ed9782cedb0ad46f922fc6d8a1aa90f61cd7a1
/test2-a.scm
cad15bb06ca67c9f297d6fb19f49ff103161f648
[]
no_license
uson-compiladores/proyecto-final-eduardo
fccdc2291252ba61d7dd148aade277c9e082e91f
6cfdb10b13c073856a23fef2215448ede303e117
refs/heads/master
2021-01-10T02:09:16.541021
2015-12-13T02:40:31
2015-12-13T02:40:31
47,208,716
0
0
null
null
null
null
UTF-8
Scheme
false
false
42
scm
test2-a.scm
(begin (set! x 2) (set! y) (* x y))
false
4c7802f7b568c8150e34153f36c3cd227b701245
46244bb6af145cb393846505f37bf576a8396aa0
/sicp/2_20.scm
589f86301920ae9efea9cd55c0aa6a78f52d7502
[]
no_license
aoeuidht/homework
c4fabfb5f45dbef0874e9732c7d026a7f00e13dc
49fb2a2f8a78227589da3e5ec82ea7844b36e0e7
refs/heads/master
2022-10-28T06:42:04.343618
2022-10-15T15:52:06
2022-10-15T15:52:06
18,726,877
4
3
null
null
null
null
UTF-8
Scheme
false
false
778
scm
2_20.scm
#lang racket ; Use this notation to write a procedure same-parity that takes one or more integers and returns a list of ; all the arguments that have the same even-odd parity as the first argument. For example, (define (same-parity sample . rest) (define (sp-wrapper candidate seo rst) (if (null? candidate) rst (if (= seo (remainder (car candidate) 2)) (sp-wrapper (cdr candidate) seo (append rst (list (car candidate)))) (sp-wrapper (cdr candidate) seo rst) ))) (define (sp-wrapper? cand seo rst) (car cand)) (let ((sample-eo (remainder sample 2))) (cons sample (sp-wrapper rest sample-eo '())) ;rest )) (same-parity 1 2 3 4 5 6 7)
false
27781f5f5f9da9ee1323b45b6bec1aeed692320f
e82d67e647096e56cb6bf1daef08552429284737
/constraint-network/constraints.scm
e05a3e98ffa631a99a12e1b904b60d7b1a1949cc
[]
no_license
ashishmax31/sicp-exercises
97dfe101dd5c91208763dcc4eaac2c17977d1dc1
097f76a5637ccb1fba055839d389541a1a103e0f
refs/heads/master
2020-03-28T11:16:28.197294
2019-06-30T20:25:18
2019-06-30T20:25:18
148,195,859
6
0
null
null
null
null
UTF-8
Scheme
false
false
3,693
scm
constraints.scm
(define (adder a1 a2 sum) (define (process-new-value) (cond ((and (has-value? a1) (has-value? a2)) (set-value! sum (+ (get-value a1) (get-value a2)) me)) ((and (has-value? a1) (has-value? sum)) (set-value! a2 (- (get-value sum) (get-value a1)) me)) ((and (has-value? a2) (has-value? sum)) (set-value! a1 (- (get-value sum) (get-value a2)) me)))) (define (forget-value) (forget-value! sum me) (forget-value! a1 me) (forget-value! a2 me) (process-new-value)) (define (me request) (cond ((eq? request 'new-value-present ) (process-new-value)) ((eq? request 'inform-about-no-value ) (forget-value)) (else (error "Unknown operation!")))) (connect a1 me) (connect a2 me) (connect sum me)) (define (multiplier a1 a2 product) (define (process-new-value) (cond ((and (has-value? a1) (has-value? a2)) (set-value! product (* (get-value a1) (get-value a2)) me)) ((and (has-value? a1) (has-value? product)) (set-value! a2 (/ (get-value product) (get-value a1)) me)) ((and (has-value? a2) (has-value? product)) (set-value! a1 (/ (get-value product) (get-value a2)) me)))) (define (forget-value) (forget-value! product me) (forget-value! a1 me) (forget-value! a2 me) (process-new-value)) (define (me request) (cond ((eq? request 'new-value-present ) (process-new-value)) ((eq? request 'inform-about-no-value ) (forget-value)) (else (error "Unknown operation!")))) (connect a1 me) (connect a2 me) (connect product me)) (define (divide a1 a2 result) (define (process-new-value) (cond ((and (has-value? a1) (has-value? a2)) (set-value! result (/ (get-value a1) (get-value a2)) me)) ((and (has-value? a1) (has-value? result)) (set-value! a2 (/ (get-value a1) (get-value result)) me)) ((and (has-value? a2) (has-value? result)) (set-value! a1 (* (get-value result) (get-value a2)) me)))) (define (forget-value) (forget-value! result me) (forget-value! a1 me) (forget-value! a2 me) (process-new-value)) (define (me request) (cond ((eq? request 'new-value-present ) (process-new-value)) ((eq? request 'inform-about-no-value ) (forget-value)) (else (error "Unknown operation!")))) (connect a1 me) (connect a2 me) (connect result me)) (define (constant value connector) (define (me request) (error "Unknown operation!")) (connect connector me) (set-value! connector value me)) (define (squarer a b) (define (square a) (* a a)) (define (process-new-value) (if (has-value? a) (set-value! b (square (get-value a)) me) (if (has-value? b) (if (< (get-value b) 0) (error "Square root of a negative number!") (set-value! a (sqrt (get-value b)) me)) 'ignored ))) (define (forget-value) (forget-value! a me) (forget-value! b me) (process-new-value)) (define (me request) (cond ((eq? request 'new-value-present ) (process-new-value)) ((eq? request 'inform-about-no-value ) (forget-value)) (else (error "Unknown operation!")))) (connect a me) (connect b me)) (define (inform-about-new-value constraint) (constraint 'new-value-present )) (define (inform-about-no-value constraint) (constraint 'inform-about-no-value ))
false
72d784ec4e3b23053a2015b8a4b399bfd150143a
5b65cc6916f779de4c7041445b84010a2fd984dd
/ps05/code/rule-implementation.scm
8545fc435f9ee3aa6a854b85596ee4b17f663f42
[]
no_license
neo4reo/6.945-1
85bed7d5b83881be1a59390f513aceadea95b42f
3373455d89c54d6e2676831fde0bfe779f7364ac
refs/heads/master
2023-03-17T09:42:11.738583
2017-05-22T01:02:41
2017-05-22T01:03:05
null
0
0
null
null
null
null
UTF-8
Scheme
false
false
1,714
scm
rule-implementation.scm
(declare (usual-integrations)) ;;; A rule is a procedure constructed from a pattern and a consequent ;;; procedure. A rule takes data that the rule may apply to and a ;;; success and failure continuation. The consequent procedure binds ;;; the variables named in the pattern. It produces the result of the ;;; rule as a function of the values of those variables that matched ;;; the data presented. (define (make-rule pattern consequent) (let ((match-procedure (match:->combinators pattern)) (bound-variables (procedure-bound-variables consequent))) (define (the-rule data succeed fail) (or (match-procedure (list data) '() ;; A matcher-success continuation (lambda (dict n) (define (matched-value name) (match:value (or (match:lookup name dict) (error "Handler asked for unknown name" name dict)))) (and (= n 1) (let ((result (apply consequent (map matched-value bound-variables)))) (and result (succeed result (lambda () #f))))))) (fail))) the-rule)) (define-syntax rule (sc-macro-transformer (lambda (form use-env) (let ((pattern (cadr form)) (handler-body (caddr form))) `(make-rule ,(close-syntax pattern use-env) ,(compile-handler handler-body use-env (match:pattern-names pattern))))))) (define (compile-handler form env names) ;; See magic in utils.scm (make-lambda names env (lambda (env*) (close-syntax form env*)))) #| (pp (syntax '(rule '(* (? a) (? b)) (and (expr<? a b) `(* ,a ,b))) (the-environment))) ; (make-rule '(* (? a) (? b)) ; (lambda (b a) ; (and (expr<? a b) ; (list '* a b)))) ;Unspecified return value |#
true
0042c580e4b6270157f2aad84e15a185850c3e78
4f97d3c6dfa30d6a4212165a320c301597a48d6d
/interpreter_experiments/chez-load-parse.scm
7c07739180f966e786bfa57aa3085f337894c9c6
[ "MIT", "LicenseRef-scancode-free-unknown" ]
permissive
michaelballantyne/Barliman
8c0b1ccbe5141347a304fe57dc9f85085aae9228
7a58671a85b82c05b364b60aa3a372313d71f8ca
refs/heads/master
2022-09-24T05:59:45.760663
2019-11-25T10:32:26
2019-11-25T10:32:26
268,399,942
0
0
MIT
2020-06-01T01:48:21
2020-06-01T01:48:20
null
UTF-8
Scheme
false
false
64
scm
chez-load-parse.scm
(load "mk/mk-vicare.scm") (load "mk/mk.scm") (load "parse.scm")
false
285f9dfcdc06fe08febb1e549803790521ae13f8
3604661d960fac0f108f260525b90b0afc57ce55
/SICP-solutions/1/search-prime.scm
f97cc4871ab0136910098899c791a38bb60e0e94
[]
no_license
rythmE/SICP-solutions
b58a789f9cc90f10681183c8807fcc6a09837138
7386aa8188b51b3d28a663958b807dfaf4ee0c92
refs/heads/master
2021-01-13T08:09:23.217285
2016-09-27T11:33:11
2016-09-27T11:33:11
69,350,592
0
0
null
null
null
null
UTF-8
Scheme
false
false
115
scm
search-prime.scm
(define (search-for-primes n) (if (prime? (+ n 1)) (timed-prime-test (+ n 1)) (search-for-primes (+ n 2))))
false
29cee4d3614b8f8f27a89c973db19ec1a9604d47
ae0d7be8827e8983c926f48a5304c897dc32bbdc
/nekoie/misc/squid/goshredir.conf.l.so.tir.jp
5822c595c7d88769ec89552ef23bf1a41e2960d7
[]
no_license
ayamada/copy-of-svn.tir.jp
96c2176a0295f60928d4911ce3daee0439d0e0f4
101cd00d595ee7bb96348df54f49707295e9e263
refs/heads/master
2020-04-04T01:03:07.637225
2015-05-28T07:00:18
2015-05-28T07:00:18
1,085,533
3
2
null
2015-05-28T07:00:18
2010-11-16T15:56:30
Scheme
UTF-8
Scheme
false
false
90
jp
goshredir.conf.l.so.tir.jp
;;; coding: euc-jp ;;; -*- scheme -*- ;;; vim:set ft=scheme ts=8 sts=2 sw=2 et: ;;; $Id$
false
d98d6f74a182be79d112292b7cdf4c64d3eae56e
f5083e14d7e451225c8590cc6aabe68fac63ffbd
/cs/01-Programming/cs61a/course/library/concurrent.scm
b0014fc2f478b58db52c924744930c62e517fe0d
[]
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
6,808
scm
concurrent.scm
;; Implementation of parallel-execute using call/cc. ;; ;; By Ben Rudiak-Gould, 10/2002. ;; ;; Requires STk (for "procedure-body" and first-class environments). (define call/cc call-with-current-continuation) (define (parallel-execute . thunks) (apply run-concurrently-with-env random (map (lambda (thunk) (cons (list (uncode (procedure-body thunk))) (make-virtual-env (procedure-environment thunk)) )) thunks )) 'okay ) (define (run-concurrently select . exprs) (apply run-concurrently-with-env select (map (lambda (x) (cons x (make-virtual-env (global-environment))) ) exprs ))) (define (run-concurrently-with-env select . exprs-with-envs) (let ((threads (map (lambda (exp-env) (list (call/cc (lambda (cont) (let ((scheduler (call/cc cont))) (scheduler (myeval (car exp-env) (cdr exp-env) scheduler ))))))) exprs-with-envs ))) (let loop () (let ((active-threads (filter (lambda (x) (continuation? (car x))) threads) )) (if (null? active-threads) (map car threads) (let ((active (list-ref active-threads (select (length active-threads)) ))) (set-car! active (call/cc (car active))) (loop) )))))) (define (make-virtual-env real-env) (cons `((quote **macro** ,macro-quote) (lambda **macro** ,macro-lambda) (let **macro** ,macro-let) (set! **macro** ,macro-set!) (define **macro** ,macro-define) (if **macro** ,macro-if) (cond **macro** ,macro-cond) (and **macro** ,macro-and) (or **macro** ,macro-or) (set-car! **prim** ,prim-set-car!) (set-cdr! **prim** ,prim-set-cdr!) (begin **prim** ,prim-begin) (test-and-set! **prim** ,prim-test-and-set!) ) real-env )) (define (env-lookup-raw sym env scheduler) (call/cc scheduler) (let ((virtual (assq sym (car env)))) (if virtual (cdr virtual) (eval sym (cdr env)) ))) (define (env-lookup sym env scheduler) (let* ((val (env-lookup-raw sym env scheduler)) (proc-body (procedure-body val)) ) (if (and proc-body (not (eq? (cadr proc-body) '**args**))) (myeval (uncode proc-body) (make-virtual-env (procedure-environment val)) scheduler ) val ))) (define (env-set! sym val env scheduler) (call/cc scheduler) (let ((virtual (assq sym (car env)))) (if virtual (set-cdr! virtual val) (eval `(set! ,sym ',val) (cdr env)) ))) (define (env-define! sym val env scheduler) (call/cc scheduler) (set-car! env (cons (cons sym val) (car env))) ) (define (get-special-form name env scheduler) (if (symbol? name) (let ((val (env-lookup-raw name env scheduler))) (if (and (pair? val) (eq? (car val) '**macro**)) val #f )) #f )) (define (myeval expr env scheduler) (cond ((pair? expr) (let ((special (get-special-form (car expr) env scheduler))) (if special ((cadr special) (cdr expr) env scheduler) (let ((evaluated (eval-seq expr env scheduler))) (myapply (car evaluated) (cdr evaluated) scheduler) )))) ((symbol? expr) (env-lookup expr env scheduler) ) (else (eval expr)) )) (define (eval-seq exprs env scheduler) (if (null? exprs) '() (let ((val (myeval (car exprs) env scheduler))) (cons val (eval-seq (cdr exprs) env scheduler)) ))) (define (myapply func args scheduler) (cond ((procedure? func) (apply func args) ) ((and (pair? func) (eq? (car func) '**prim**)) ((cadr func) args scheduler) ) ((and (pair? func) (eq? (car func) '**macro**)) ((cadr func) (map (lambda (x) (list 'quote x)) args) scheduler) ) (else (error "apply of non-procedure" func args)) )) (define (make-call-environment params args env) (cons (let loop ((params params) (args args)) (cond ((pair? params) (cons (cons (car params) (car args)) (loop (cdr params) (cdr args)) )) ((null? params) (car env) ) (else (cons (cons params args) (car env))) )) (cdr env) )) (define (macro-lambda args env scheduler) (let ((params (car args)) (body (cdr args)) ) (lambda **args** (let ((new-env (make-call-environment params **args** env))) (last (map (lambda (x) (myeval x new-env scheduler)) body)) )))) (define (macro-let args env scheduler) (let ((vars (map car (car args))) (vals (map cadr (car args))) (body (cdr args)) ) (myeval `((lambda ,vars ,@body) ,@vals) env scheduler) )) (define (macro-define args env scheduler) (if (pair? (car args)) (macro-define `(,(caar args) (lambda ,(cdar args) ,@(cdr args))) env scheduler ) (let ((val (myeval (cadr args) env scheduler))) (env-define! (car args) val env scheduler) ))) (define (macro-set! args env scheduler) (let ((val (myeval (cadr args) env scheduler))) (env-set! (car args) val env scheduler) )) (define (macro-quote args env scheduler) (car args) ) (define (macro-if args env scheduler) (if (myeval (car args) env scheduler) (myeval (cadr args) env scheduler) (if (pair? (cddr args)) (myeval (caddr args) env scheduler) 'okay ))) (define (macro-cond args env scheduler) (cond ((null? args) 'okay) ((or (eq? (caar args) 'else) (myeval (caar args) env scheduler) ) (car (last-pair (eval-seq (cdar args) env scheduler))) ) (else (macro-cond (cdr args) env scheduler)) )) (define (macro-and args env scheduler) (if (null? args) #t (let ((val (myeval (car args) env scheduler))) (if (null? (cdr args)) val (and val (macro-and (cdr args) env scheduler)) )))) (define (macro-or args env scheduler) (if (null? args) #f (let ((val (myeval (car args) env scheduler))) (if (null? (cdr args)) val (or val (macro-or (cdr args) env scheduler)) )))) (define (prim-set-car! args scheduler) (call/cc scheduler) (apply set-car! args) ) (define (prim-set-cdr! args scheduler) (call/cc scheduler) (apply set-cdr! args) ) (define (prim-begin args scheduler) (car (last-pair args)) ) (define (prim-test-and-set! args scheduler) (call/cc scheduler) (test-and-set! (car args)) ) (define (test-and-set! x) (let ((oldval (car x))) (set-car! x #t) oldval )) (define (last-pair lst) (if (null? (cdr lst)) lst (last-pair (cdr lst)) )) (load "~cs61a/lib/serial.scm")
false
24dcf9dfbc7d6cf5fae6e39e871687e2b543f7f3
2c1b9940ae78fcdb50e728cadc8954c45e7da135
/psenvsub.scm
35aa7a225e07cd050a0c9dfab2a4b744916c3085
[ "MIT" ]
permissive
ursetto/zbguide
2e9bac1033297d8359ac59426ce7ba692efcc0d3
5ef0241b44ed676d9ebdd673ab094caf5645845b
refs/heads/master
2018-12-28T03:33:50.219317
2011-07-20T06:05:59
2011-07-20T06:05:59
2,050,495
1
0
null
null
null
null
UTF-8
Scheme
false
false
226
scm
psenvsub.scm
(use zmq) (define sub (make-socket 'sub)) (socket-option-set! sub 'subscribe "B") (connect-socket sub "tcp://localhost:5563") (let loop () (printf "[~a] " (receive-message sub)) (print (receive-message sub)) (loop))
false
21332a5413dffcb16439aea94e3bf17113b542f8
665da87f9fefd8678b0635e31df3f3ff28a1d48c
/scheme/eval.sld
ba33ae11209f1d77b19d89f590d95f0070a684a6
[ "MIT" ]
permissive
justinethier/cyclone
eeb782c20a38f916138ac9a988dc53817eb56e79
cc24c6be6d2b7cc16d5e0ee91f0823d7a90a3273
refs/heads/master
2023-08-30T15:30:09.209833
2023-08-22T02:11:59
2023-08-22T02:11:59
31,150,535
862
64
MIT
2023-03-04T15:15:37
2015-02-22T03:08:21
Scheme
UTF-8
Scheme
false
false
50,799
sld
eval.sld
;;;; Cyclone Scheme ;;;; https://github.com/justinethier/cyclone ;;;; ;;;; Copyright (c) 2014-2016, Justin Ethier ;;;; All rights reserved. ;;;; ;;;; The Cyclone interpreter, based on the meta-circular evaluator from SICP 4.1: ;;;; http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-26.html#%_sec_4.1 ;;;; (define-library (scheme eval) (import (scheme cyclone util) (scheme cyclone libraries) ;; for handling import sets (scheme cyclone primitives) (scheme base) (scheme file) ;(scheme write) ;; Only used for debugging (scheme read)) (export ;environment eval eval-from-c ; non-standard create-environment ; non-standard setup-environment ; non-standard ;; Dynamic import %import imported? %set-import-dirs! import-shared-object ;; Macros *defined-macros* get-macros macro:macro? macro:expand macro:add! macro:cleanup macro:load-env! macro:get-env macro:get-defined-macros expand expand-lambda-body ) (inline primitive-implementation procedure-environment procedure-body procedure-parameters operands operator application? if-alternative if-consequent if-predicate lambda-body lambda-parameters definition-variable assignment-value assignment-variable variable? macro:macro? ) (begin ;; From r7rs: ;; This procedure returns a specifier for the environment that ;; results by starting with an empty environment and then ;; importing each list, considered as an import set, into it. ;; (See section 5.6 for a description of import sets.) The ;; bindings of the environment represented by the specifier ;; are immutable, as is the environment itself. ;; ;; Ideally, want this to allow creating new env's on top of global-env. ;(define (environment i . is) ; (let ((imports (cons i is))) ; 'TODO ; )) ;; Create a new environment on top of the default one. ;; - vars => Identifiers in the new environment ;; - vals => List of each value assigned to each identifier (define (create-environment vars vals) ;(write `(DEBUG vars ,vars)) ;(write `(DEBUG vals ,vals)) (env:extend-environment vars vals *global-environment*)) ;; TODO: setup? (define (eval exp . env) (define rename-env (env:extend-environment '() '() '())) (if (null? env) ((analyze exp *global-environment* rename-env '()) *global-environment*) ((analyze exp (car env) rename-env '()) (car env)))) (define (eval-from-c exp . _env) (let ((env (if (null? _env) *global-environment* (car _env)))) (eval (wrapc exp) env))) ;; Expressions received from C code are already evaluated, but sometimes too much so. ;; Try to wrap (define (wrapc exp) (cond ((application? exp) (cond ((compound-procedure? (car exp)) (cons (car exp) (map (lambda (e) (if (self-evaluating? e) e `(quote ,e))) (cdr exp)))) (else exp))) (else exp))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Expression handling helper functions (define (self-evaluating? exp) (cond ((number? exp) #t) ((boolean? exp) #t) ((eq? (void) exp) #t) ;; Poor man's (void?) ((string? exp) #t) ((vector? exp) #t) ((bytevector? exp) #t) ((char? exp) #t) ((port? exp) #t) ((eof-object? exp) #t) (else #f))) (define (variable? exp) (symbol? exp)) (define (quoted? exp) (tagged-list? 'quote exp)) (define (assignment? exp) (tagged-list? 'set! exp)) (define (assignment-variable exp) (cadr exp)) (define (assignment-value exp) (caddr exp)) (define (syntax? exp) (tagged-list? 'define-syntax exp)) (define (definition? exp) (tagged-list? 'define exp)) (define (definition-variable exp) (if (symbol? (cadr exp)) (cadr exp) (caadr exp))) (define (definition-value exp) (if (symbol? (cadr exp)) (caddr exp) (make-lambda (cdadr exp) ; formal parameters (cddr exp)))) ; body (define (lambda-parameters exp) (cadr exp)) (define (lambda-body exp) (cddr exp)) (define (make-lambda parameters body) (cons 'lambda (cons parameters body))) (define (if-predicate exp) (cadr exp)) (define (if-consequent exp) (caddr exp)) (define (if-alternative exp) (if (not (null? (cdddr exp))) ;; TODO: add (not) support (cadddr exp) (void))) (define (make-if predicate consequent alternative) (list 'if predicate consequent alternative)) (define (application? exp) (pair? exp)) (define (operator exp) (car exp)) (define (operands exp) (cdr exp)) ;(define (no-operands? ops) (null? ops)) ;(define (first-operand ops) (car ops)) ;(define (rest-operands ops) (cdr ops)) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Evaluator data structures (define procedure-tag 'procedure) (define (make-procedure parameters body env) (list procedure-tag parameters body env)) (define (compound-procedure? p) (tagged-list? procedure-tag p)) (define (procedure-parameters p) (cadr p)) (define (procedure-body p) (caddr p)) (define (procedure-environment p) (cadddr p)) ;; Evaluated macros (define (make-macro expr) (list macro-tag expr)) (define macro-tag 'macro) (define (compound-macro? exp) (tagged-list? macro-tag exp)) ;; Environments (define (primitive-procedure? proc) (tagged-list? 'primitive proc)) (define (primitive-implementation proc) (cadr proc)) (define primitive-procedures (append (list (list 'call/cc call/cc) (list 'Cyc-global-vars Cyc-global-vars) (list 'Cyc-get-cvar Cyc-get-cvar) (list 'Cyc-set-cvar! Cyc-set-cvar!) (list 'Cyc-cvar? Cyc-cvar?) (list 'Cyc-opaque? Cyc-opaque?) (list 'Cyc-has-cycle? Cyc-has-cycle?) (list 'Cyc-spawn-thread! Cyc-spawn-thread!) (list 'Cyc-end-thread! Cyc-end-thread!) (list 'Cyc-default-exception-handler Cyc-default-exception-handler) (list 'Cyc-current-exception-handler Cyc-current-exception-handler) (list '+ +) (list '- -) (list '* *) (list '/ /) (list '= =) (list '> >) (list '< <) (list '>= >=) (list '<= <=) (list 'apply apply) (list '%halt %halt) (list 'exit exit) (list 'Cyc-compilation-environment Cyc-compilation-environment) (list 'Cyc-installation-dir Cyc-installation-dir) (list 'system system) (list 'command-line-arguments command-line-arguments) (list 'error error) (list 'cons cons) (list 'cell-get cell-get) (list 'set-global! set-global!) (list 'set-cell! set-cell!) (list 'cell cell) (list 'eq? eq?) (list 'eqv? eqv?) (list 'equal? equal?) ;(list 'Cyc-fast-assoc Cyc-fast-assoc) (list 'assq assq) (list 'assv assv) (list 'memq memq) (list 'memv memv) ;(list 'Cyc-fast-member Cyc-fast-member) (list 'length length) (list 'set-car! set-car!) (list 'set-cdr! set-cdr!) (list 'car car) (list 'cdr cdr) (list 'caar caar) (list 'cadr cadr) (list 'cdar cdar) (list 'cddr cddr) (list 'caaar caaar) (list 'caadr caadr) (list 'cadar cadar) (list 'caddr caddr) (list 'cdaar cdaar) (list 'cdadr cdadr) (list 'cddar cddar) (list 'cdddr cdddr) (list 'caaaar caaaar) (list 'caaadr caaadr) (list 'caadar caadar) (list 'caaddr caaddr) (list 'cadaar cadaar) (list 'cadadr cadadr) (list 'caddar caddar) (list 'cadddr cadddr) (list 'cdaaar cdaaar) (list 'cdaadr cdaadr) (list 'cdadar cdadar) (list 'cdaddr cdaddr) (list 'cddaar cddaar) (list 'cddadr cddadr) (list 'cdddar cdddar) (list 'cddddr cddddr) ) (list (list 'char->integer char->integer) (list 'integer->char integer->char) (list 'string->number string->number) (list 'string-cmp string-cmp) (list 'string-append string-append) (list 'list->string list->string) (list 'string->symbol string->symbol) (list 'symbol->string symbol->string) (list 'number->string number->string) (list 'string-length string-length) (list 'string-ref string-ref) (list 'string-set! string-set!) (list 'substring substring) (list 'make-bytevector make-bytevector) (list 'bytevector-length bytevector-length) (list 'bytevector-append bytevector-append) (list 'Cyc-bytevector-copy Cyc-bytevector-copy) (list 'Cyc-utf8->string Cyc-utf8->string) (list 'Cyc-string->utf8 Cyc-string->utf8) (list 'bytevector bytevector) (list 'bytevector-u8-ref bytevector-u8-ref) (list 'bytevector-u8-set! bytevector-u8-set!) (list 'make-vector make-vector) (list 'list->vector list->vector) (list 'vector-length vector-length) (list 'vector-ref vector-ref) (list 'vector-set! vector-set!) (list 'boolean? boolean?) (list 'char? char?) (list 'eof-object? eof-object?) (list 'null? null?) (list 'number? number?) (list 'real? real?) (list 'integer? integer?) (list 'pair? pair?) (list 'port? port?) (list 'procedure? procedure?) (list 'Cyc-macro? Cyc-macro?) (list 'vector? vector?) (list 'bytevector? bytevector?) (list 'string? string?) (list 'symbol? symbol?) (list 'open-input-file open-input-file) (list 'open-output-file open-output-file) (list 'open-binary-input-file open-binary-input-file) (list 'open-binary-output-file open-binary-output-file) (list 'close-port close-port) (list 'close-input-port close-input-port) (list 'close-output-port close-output-port) (list 'file-exists? file-exists?) (list 'delete-file delete-file) (list 'read-char read-char) (list 'peek-char peek-char) (list 'Cyc-read-line Cyc-read-line) (list 'Cyc-write-char Cyc-write-char) (list 'Cyc-write Cyc-write) (list 'Cyc-display Cyc-display)))) (define (primitive-procedure-names) (foldr (lambda (x y) (cons (car x) y)) '() primitive-procedures)) (define (primitive-procedure-objects) (foldr (lambda (proc rest) (cons (list 'primitive (cadr proc)) rest)) '() primitive-procedures)) (define (apply-primitive-procedure proc args) (apply (primitive-implementation proc) args)) ;; TODO: temporary testing ;; also, it would be nice to pass around something other than ;; symbols for primitives. could the runtime inject something into the env? ;; of course that is a problem for stuff like make_pair, that is just a ;; C macro... ;; (define (primitive-procedure? proc) ;; (equal? proc 'cons)) (define (setup-environment . env) (let ((initial-env (if (not (null? env)) (car env) (create-initial-environment)))) (cond-expand (cyclone ;; Also include compiled variables (env:extend-environment (map (lambda (v) (car v)) (Cyc-global-vars)) (map (lambda (v) (cdr v)) (Cyc-global-vars)) initial-env)) (else initial-env)))) (define (create-initial-environment) (env:extend-environment (primitive-procedure-names) (primitive-procedure-objects) env:the-empty-environment)) (define *initial-environment* (create-initial-environment)) (define *global-environment* (env:extend-environment '() '() (setup-environment (create-initial-environment)))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; This step separates syntactic analysis from execution. ;; - exp => Code to analyze ;; - env => Environment used to expand macros ;; (define (analyze exp env rename-env local-renamed) ;(newline) ;(display "/* ") ;(write (list 'analyze exp)) ;(display " */") (cond ((self-evaluating? exp) (analyze-self-evaluating exp)) ((quoted? exp) (analyze-quoted exp)) ((variable? exp) (analyze-variable exp local-renamed)) ((and (assignment? exp) (not (null? (cdr exp)))) (analyze-assignment exp env rename-env local-renamed)) ((and (definition? exp) (not (null? (cdr exp)))) (analyze-definition exp env rename-env local-renamed)) ((and (syntax? exp) (not (null? (cdr exp)))) (analyze-syntax exp env local-renamed)) ((and (tagged-list? 'let-syntax exp) (not (null? (cdr exp)))) (analyze-let-syntax exp env rename-env local-renamed)) ((and (tagged-list? 'letrec-syntax exp) (not (null? (cdr exp)))) (analyze-letrec-syntax exp env rename-env local-renamed)) ((and (if? exp) (not (null? (cdr exp)))) (analyze-if exp env rename-env local-renamed)) ((and (lambda? exp) (not (null? (cdr exp)))) (analyze-lambda exp env rename-env local-renamed)) ((tagged-list? 'import exp) (analyze-import exp env)) ;; experimenting with passing these back to eval ((compound-procedure? exp) (lambda (env) exp)) ;; TODO: good enough? update env? ;; END experimental code ((procedure? exp) (lambda (env) exp)) ((application? exp) (pre-analyze-application exp env rename-env local-renamed)) (else (error "Unknown expression type -- ANALYZE" exp)))) ;(lambda () 'TODO-unknown-exp-type)))) ; JAE - this is a debug line (define (analyze-self-evaluating exp) (lambda (env) exp)) (define (analyze-quoted exp) (let ((qval (cadr exp))) (Cyc-set-immutable! qval #t) ;; TODO: OK? Don't want to modify a persistent object (lambda (env) qval))) (define-c assoc-cdr "(void *data, int argc, closure _, object k, object x, object lis)" " return_closcall1(data, k, assoc_cdr(data, x, lis)); ") (define (analyze-variable exp local-renamed) (let* ((lookup (assoc exp local-renamed)) (sym (cond ((pair? lookup) (car lookup)) (else (let ((lookup-by-renamed (assoc-cdr exp local-renamed))) (if lookup-by-renamed (car lookup-by-renamed) ;; Map renamed symbol back to one in env exp)))))) ;; Not found, keep input symbol (lambda (env) (env:lookup-variable-value sym env)))) (define (analyze-assignment exp a-env rename-env local-renamed) (let ((var (assignment-variable exp)) (vproc (analyze (assignment-value exp) a-env rename-env local-renamed))) (lambda (env) (env:set-variable-value! var (vproc env) env) 'ok))) (define (analyze-definition exp a-env rename-env local-renamed) (let ((var (definition-variable exp)) (vproc (analyze (definition-value exp) a-env rename-env local-renamed))) (lambda (env) (env:define-variable! var (vproc env) env) 'ok))) (define (analyze-let-syntax exp a-env rename-env local-renamed) (let* (;(rename-env (env:extend-environment '() '() '())) (expanded (_expand exp a-env rename-env '() local-renamed)) ;(expanded (expand exp (macro:get-env) rename-env)) (cleaned (macro:cleanup expanded rename-env)) ) ;; TODO: probably just create a fresh env for renames ;; TODO: expand, do we need to clean as well? ;; TODO: run results back through analyze: (analyze (expand env? rename-env? ;(display "/* ") ;(write `(DEBUG let-syntax ,exp )) ;(newline) ;(write `(DEBUG EXPANDED ,expanded)) ;(newline) ;(write `(DEBUG CLEANED ,cleaned)) ;(newline) ;(write `(DEBUG env ,a-env)) ;(display "*/ ") ;(newline) (analyze cleaned a-env rename-env local-renamed))) (define (analyze-letrec-syntax exp a-env rename-env local-renamed) (let* (;(rename-env (env:extend-environment '() '() '())) ;; Build up a macro env (vars (foldl (lambda (lis acc) (append acc (car lis))) '() a-env)) (vals (foldl (lambda (lis acc) (append acc (cdr lis))) '() a-env)) (zipped (apply map list vars (list vals))) (defined-macros (filter (lambda (v) (Cyc-macro? (Cyc-get-cvar (cadr v)))) zipped)) (macro-env (env:extend-environment (map car defined-macros) (map (lambda (v) (list 'macro (cadr v))) defined-macros) a-env)) ;(create-environment '() '()))) ;; Proceed with macro env (expanded (_expand exp macro-env rename-env '() local-renamed)) (cleaned (macro:cleanup expanded rename-env)) ) ;(display "/* ") ;(write `(DEBUG letrec-syntax ,exp )) ;(newline) ;(write `(DEBUG EXPANDED ,cleaned)) ;(display "*/ ") ;(newline) (analyze cleaned a-env rename-env local-renamed))) (define (analyze-syntax exp a-env local-renamed) (let ((var (cadr exp))) (cond ((tagged-list? 'er-macro-transformer (caddr exp)) ;; TODO: need to handle renamed er symbol here?? (let ((sproc (make-macro (cadr (caddr exp))))) (lambda (env) (env:define-variable! var sproc env) 'ok))) (else ;; Just expand the syntax rules ;; Possibly want to check the macro system here (let* ((rename-env (env:extend-environment '() '() '())) (expanded (_expand exp a-env rename-env '() local-renamed)) ;(expanded (expand exp a-env rename-env)) (cleaned (macro:cleanup expanded rename-env))) (let ((sproc (make-macro (caddr cleaned)))) (lambda (env) (env:define-variable! var sproc env) 'ok))))))) (define (analyze-import exp env) (lambda (env) ;; FUTURE: allow %import to take env? ;(write `(%import ,(cdr exp))) (apply %import (cdr exp)) 'ok)) (define (analyze-if exp a-env rename-env local-renamed) (let ((args (length exp))) (cond ((< args 3) (error "Not enough arguments" exp)) ((> args 4) (error "Too many arguments" exp))) (let ((pproc (analyze (if-predicate exp) a-env rename-env local-renamed)) (cproc (analyze (if-consequent exp) a-env rename-env local-renamed)) (aproc (analyze (if-alternative exp) a-env rename-env local-renamed))) (lambda (env) (if (pproc env) (cproc env) (aproc env)))))) (define (analyze-lambda exp a-env rename-env local-renamed) (let* ((vars (lambda-parameters exp)) (args (lambda-formals->list exp)) (a-lookup (map (lambda (a) (let ((a/r (cons a (gensym a)))) a/r)) args)) (bproc (analyze-sequence (lambda-body exp) a-env rename-env (append a-lookup local-renamed)))) (lambda (env) (make-procedure vars bproc env)))) (define (analyze-sequence exps a-env rename-env local-renamed) (define (sequentially proc1 proc2) (lambda (env) (proc1 env) (proc2 env))) (define (loop first-proc rest-procs) (if (null? rest-procs) first-proc (loop (sequentially first-proc (car rest-procs)) (cdr rest-procs)))) (let ((procs (map (lambda (e) (analyze e a-env rename-env local-renamed)) exps))) (if (null? procs) (error "Empty sequence -- ANALYZE")) (loop (car procs) (cdr procs)))) (define (pre-analyze-application exp a-env rename-env local-renamed) ;; Notes: ;; look up symbol in env, and expand if it is a macro ;; Adds some extra overhead into eval, which is not ideal. may need to ;; reduce that overhead later... (let* ((op (operator exp)) (var (if (symbol? op) (env:_lookup-variable-value op a-env (lambda () #f)) ; Not found #f)) (expand (lambda (macro-op) (if (Cyc-macro? macro-op) ;; Compiled macro, call directly (let* ((expanded (_expand exp a-env rename-env '() local-renamed)) (cleaned (macro:cleanup expanded rename-env))) (analyze cleaned a-env rename-env local-renamed)) ;; Interpreted macro, build expression and eval (let* ((expanded (_expand exp a-env rename-env '() local-renamed)) (cleaned (macro:cleanup expanded rename-env))) (analyze cleaned a-env rename-env local-renamed)))))) (cond ;; special case - begin can splice in definitions, so we can't use the ;; built-in macro that just expands them within a new lambda scope. ;; Instead we nest them below within the same lexical environment. ((eq? 'begin op) ;(newline) ;(display "/* ") ;(write (list exp)) ;(display "*/ ") (let ((fncs (Cyc-map-loop-1 (lambda (expr) (analyze expr a-env rename-env local-renamed)) (cdr exp)))) (lambda (env) (foldl (lambda (fnc _) (fnc env)) #f fncs)))) ;; compiled macro ((Cyc-macro? var) (expand var)) ;; compiled or interpreted macro in compound form ((compound-macro? var) (let ((macro (Cyc-get-cvar (cadr var)))) (expand macro))) ;; standard interpreted macro ((compound-macro? op) (expand (cdr op))) ;; normal function (else (analyze-application exp a-env rename-env local-renamed))))) (define (analyze-application exp a-env rename-env local-renamed) (let ((fproc (analyze (operator exp) a-env rename-env local-renamed)) (aprocs (map (lambda (o) (analyze o a-env rename-env local-renamed)) (operands exp)))) (lambda (env) (execute-application (fproc env) (map (lambda (aproc) (aproc env)) aprocs))))) (define (execute-application proc args) (cond ((primitive-procedure? proc) (apply-primitive-procedure proc args)) ((compound-procedure? proc) ((procedure-body proc) (env:extend-environment (formals->list (procedure-parameters proc)) (pack-lambda-arguments (procedure-parameters proc) args) (procedure-environment proc)))) ((procedure? proc) (apply proc (map (lambda (a) (cond ;; "unwrap" objects before passing to runtime ((primitive-procedure? a) (primitive-implementation a)) (else a))) args))) (else (error "Unknown procedure type -- EXECUTE-APPLICATION" proc)))) ;(define (analyze-application exp) ; (let ((fproc (analyze (operator exp))) ; (aprocs (operands exp))) ; TODO: (map analyze (operands exp)))) ; (lambda (env) ; (execute-application (fproc env) ;; TODO: (map (lambda (aproc) (aproc env)) ; aprocs)))) ;; TODO: temporary testing w/constants ;; TODO: aprocs))))) ;(define (execute-application proc args) ; (cond ((primitive-procedure? proc) ; (apply proc args)) ; ;(apply-primitive-procedure proc args)) ;;; TODO: ;; ;((compound-procedure? proc) ;; ; ((procedure-body proc) ;; ; (env:extend-environment (procedure-parameters proc) ;; ; args ;; ; (procedure-environment proc)))) ; (else ;#f))) ;; TODO: this is a temporary debug line ;; (error ;; "Unknown procedure type -- EXECUTE-APPLICATION" ;; proc)))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; JAE - Testing, should work both with cyclone and other compilers (husk, chicken, etc) ;; although, that may not be possible with (app) and possibly other forms. ;(write (eval 2 *global-environment*)) ;(write (eval ''(1 2) *global-environment*)) ;(write (eval ''(1 . 2) *global-environment*)) ;(write (eval '(if #t 'test-ok 'test-fail) *global-environment*)) ;(write (eval '(if 1 'test-ok) *global-environment*)) ;(write (eval '(if #f 'test-fail 'test-ok) *global-environment*)) ;(write (eval '((lambda (x) (cons x 2) (cons #t x)) 1) *global-environment*)) ;;(write (eval '((lambda () (cons 1 2) (cons #t #f))) *global-environment*)) ;;(write (eval '(cons 1 2) *global-environment*)) ; TODO ;;(write (eval '(+ 1 2) *global-environment*)) ; TODO ;(define (loop) ; (display (eval (read) *global-environment*)) ; (display (newline)) ; (loop)) ;(loop) (define *append-dirs* '()) (define *prepend-dirs* '()) (define (%set-import-dirs! append-dirs prepend-dirs) (set! *append-dirs* append-dirs) (set! *prepend-dirs* prepend-dirs)) (define (base-expander) (let ((rename-env (env:extend-environment '() '() '())) (macros (filter (lambda (v) (Cyc-macro? (Cyc-get-cvar (cdr v)))) (Cyc-global-vars))) ) (macro:load-env! macros (create-environment '() '())) (lambda (ex) (expand ex (macro:get-env) rename-env)))) ;; TODO: right now this is a hack, just get all the imports sets and call their entry point ;; function to initialize them. longer-term will need to only load the specific identifiers ;; called out in the import sets ;; ;; TODO: for some imports (prefix, maybe other stuff), can we do the renaming in the env?? (define (%import . import-sets) (let (;; Libraries explicitly listed in the import expression (explicit-lib-names (map lib:import->library-name (lib:list->import-set import-sets))) ;; All dependent libraries (lib-names (lib:get-all-import-deps import-sets *append-dirs* *prepend-dirs* (base-expander))) (renamed-syms (filter pair? (map car (lib:imports->idb import-sets *append-dirs* *prepend-dirs* base-expander)))) ) (for-each (lambda (lib-name) (let* ((us (lib:name->unique-string lib-name)) (loaded? (c:lib-loaded? us))) (if (or (not loaded?) (member lib-name explicit-lib-names)) (c:import-shared-obj (lib:import->filename lib-name ".so" *append-dirs* *prepend-dirs*) (string-append "c_" (lib:name->string lib-name) "_entry_pt_first_lambda")) ;(begin (write `(,lib-name ,us ,loaded? is already loaded skipping)) (newline)) ))) lib-names) ;(newline) ;(display "/* ") ;(write (list 'DEBUG-GLO-ENV *global-environment*)) ;(display "*/ ") (set! *global-environment* (cons (car *global-environment*) (setup-environment *initial-environment*))) ;; Load any renamed exports into the environment (for-each (lambda (rename/base) (env:define-variable! (car rename/base) (env:_lookup-variable-value (cdr rename/base) *global-environment*) *global-environment*)) renamed-syms) #t)) ;; Is the given library loaded? (define (imported? lis) (c:lib-loaded? (lib:name->unique-string (lib:list->import-set lis)))) (define (import-shared-object filename) (c:import-shared-obj filename "")) ;; Wrapper around the actual shared object import function (define-c c:import-shared-obj "(void *data, int argc, closure _, object k, object fn, object entry_fnc)" " Cyc_import_shared_object(data, k, fn, entry_fnc); ") (define-c c:lib-loaded? "(void *data, int argc, closure _, object k, object name)" " Cyc_check_str(data, name); return_closcall1(data, k, is_library_loaded(string_str(name))); ") ;; Macro section ;; top-level macro environment (define *macro:env* '()) ;; A list of all macros defined by the program/library being compiled (define *macro:defined-macros* '()) (define (macro:add! name body) (set! *macro:defined-macros* (cons (cons name body) *macro:defined-macros*)) #t) (define (macro:load-env! defined-macros base-env) (set! *macro:env* (env:extend-environment (map car defined-macros) (map (lambda (v) (list 'macro (cdr v))) defined-macros) base-env))) (define (macro:get-env) *macro:env*) (define (macro:get-defined-macros) *macro:defined-macros*) ;; Macro section (define (macro:macro? exp defined-macros) (assoc (car exp) defined-macros)) (define (macro:get-local-renames macro current-rename-lis) (if (and (eq? 3 (length macro)) (not (null? (caddr macro)))) (caddr macro) current-rename-lis)) (define (macro:expand exp macro mac-env rename-env local-renamed-lis) (let* ((use-env (env:extend-environment '() '() '())) (compiled-macro? (or (Cyc-macro? (Cyc-get-cvar (cadr macro))) (procedure? (cadr macro)))) (local-renamed (macro:get-local-renames macro local-renamed-lis)) (result #f)) ;(newline) ;(display "/* ") ;(write (list 'macro:expand exp (memloc exp) (assoc exp *source-loc-lis*) macro compiled-macro? local-renamed)) ;(display "*/ ") ;; Invoke ER macro (set! result (with-handler (lambda (err) (apply error/loc (append (list (car err) exp) (cdr err))) ) (cond ((not macro) (error "macro not found" exp)) (compiled-macro? ((Cyc-get-cvar (cadr macro)) exp (Cyc-er-rename use-env mac-env local-renamed) (Cyc-er-compare? use-env rename-env))) (else (eval (list (Cyc-get-cvar (cadr macro)) (list 'quote exp) (Cyc-er-rename use-env mac-env local-renamed) (Cyc-er-compare? use-env rename-env)) mac-env))))) ;(newline) ;(display "/* ") ;(write (list 'macro:expand exp macro compiled-macro?)) ;(newline) ;(write (list result)) ;(display "*/ ") (macro:add-renamed-vars! use-env rename-env) result)) (define (macro:add-renamed-vars! env renamed-env) (let ((frame (env:first-frame renamed-env))) (for-each (lambda (var val) (env:add-binding-to-frame! var val frame)) (env:all-variables env) (env:all-values env)))) (define (macro:cleanup expr rename-env) (define (clean expr bv) ;; Bound variables ;(newline) ;(display "/* macro:cleanup->clean, bv =") ;(write bv) ;(newline) ;(write expr) ;(newline) ;(display "*/ ") (cond ((and (pair? expr) ;; Improper list (not (list? expr))) (cons (clean (car expr) bv) (clean (cdr expr) bv))) ((const? expr) expr) ((null? expr) expr) ((quote? expr) (let ((atom (cadr expr))) ;; Clean up any renamed symbols that are quoted ;; TODO: good enough for quoted pairs or do ;; we need to traverse those, too? (if (ref? atom) `(quote ,(clean atom bv)) expr))) ((define-c? expr) expr) ((ref? expr) ;; if symbol has been renamed and is not a bound variable, ;; undo the rename (let ((val (env:lookup expr rename-env #f))) (if (and val (not (member expr bv))) (clean val bv) expr))) ((if-syntax? expr) `(if ,(clean (if->condition expr) bv) ,(clean (if->then expr) bv) ,(if (if-else? expr) (clean (if->else expr) bv) #f))) ((lambda? expr) `(lambda ,(lambda->formals expr) ,@(map (lambda (e) (clean e (append (lambda-formals->list expr) bv))) (lambda->exp expr)))) ;; At this point defines cannot be in lambda form. ;; EG: (define (f x) ...) ((define? expr) ;; #361 - Update parent list of bound variables to account ;; for defined variable since it is within that scope (if (null? bv) (set! bv (list bv)) (set-cdr! bv (cons (define->var expr) (cdr bv)))) `(define ,(define->var expr) ,@(map (lambda (e) (clean e bv)) (define->exp expr)))) ;; For now, assume set is not introducing a new binding ((set!? expr) `(set! ,(clean (set!->var expr) bv) ,(clean (set!->exp expr) bv))) ((app? expr) (map (lambda (e) (clean e bv)) expr)) (else (error "macro cleanup unexpected expression: " expr)))) (clean expr (list '____unused____))) ; TODO: get macro name, transformer ;; Macro expansion ;TODO: modify this whole section to use macros:get-env instead of *defined-macros*. macro:get-env becomes the mac-env. any new scopes need to extend that env, and an env parameter needs to be added to (expand). any macros defined with define-syntax use that env as their mac-env (how to store that)? ; expand : exp -> exp (define (expand exp . opts) (let ((env (if (> (length opts) 0) (car opts) *global-environment*)) (rename-env (if (> (length opts) 1) (cadr opts) (env:extend-environment '() '() '())))) (_expand exp env rename-env '() '()))) ;; Internal implementation of expand ;; exp - Expression to expand ;; env - Environment of the expression ;; rename-env - Environment of variables renamed directly by macros ;; local-env - Local macro definitions, used by let-syntax ;; local-renamed - Renamed local variables introduced by lambda expressions (define (_expand exp env rename-env local-env local-renamed) ;(define (log e) ; (display ; (list 'expand e 'env ; (env:frame-variables (env:first-frame env))) ; (current-error-port)) ; (newline (current-error-port))) ;(log exp) ;(display "/* ") ;(write `(expand ,exp)) ;(newline) ;(write `(DEBUG env ,env)) ;(display "*/ ") ;(newline) (cond ((const? exp) exp) ;; Null and Improper lists are just consts, no need to expand ((null? exp) exp) ((and (pair? exp) (not (list? exp))) exp) ((and (prim? exp) ;; Allow lambda vars to shadown primitives (not (assoc exp local-renamed))) exp) ((ref? exp) (let ((renamed (assoc exp local-renamed))) (if renamed (cdr renamed) ;; Extract renamed symbol exp))) ((quote? exp) exp) ;; TODO: rename all lambda formals and update rename-env accordingly. ;; will also require renaming refs later on here in expand... ;; can we use Cyc-er-rename to do this? maybe just use gensym directly as a first-cut ;; TODO: also need to figure out how to deep-copy rename-env and associate it with ;; any defined macro. would need to pull that out when macro is expanded later ((lambda? exp) (let* ((use-env (env:extend-environment '() '() '())) (args (lambda-formals->list exp)) (ltype (lambda-formals-type exp)) ;(a-lookup (map (lambda (a) (cons a (gensym a))) args)) ;; Experimenting with ER renaming. still think there may be a problem with ;; this, though. because when a nested lambda comes around with the same ;; identifier as an enclosing lambda, its vars would not be given unique renames (a-lookup (map (lambda (a) (let ((a/r (cons a (gensym a)))) ; I think we want to pass these a-lookup bindings to Cyc-er-rename and ; use them to rename any locals. ideally want this stored with macro def ; for define-syntax. I think we get it for free with let*-syntax ;; TODO: define needed? ;(env:define-variable! (cdr a/r) (car a/r) rename-env) a/r)) args)) (new-formals (list->lambda-formals (map cdr a-lookup) ltype)) ) ;; (newline) ;; (display "/* ") ;; (display (list 'expand a-lookup)) ;; (newline) ;; (display "*/ ") `(lambda ,new-formals ;,(lambda->formals exp) ,@(_expand-body '() (lambda->exp exp) env rename-env local-env (append a-lookup local-renamed)) ))) ((define? exp) (if (define-lambda? exp) (_expand (define->lambda exp) env rename-env local-env local-renamed) `(define ,(_expand (define->var exp) env rename-env local-env local-renamed) ,@(_expand (define->exp exp) env rename-env local-env local-renamed)))) ((set!? exp) `(set! ,(_expand (set!->var exp) env rename-env local-env local-renamed) ,(_expand (set!->exp exp) env rename-env local-env local-renamed))) ((if-syntax? exp) `(if ,(_expand (if->condition exp) env rename-env local-env local-renamed) ,(_expand (if->then exp) env rename-env local-env local-renamed) ,(if (if-else? exp) (_expand (if->else exp) env rename-env local-env local-renamed) ;; Insert default value for missing else clause ;; FUTURE: append the empty (unprinted) value ;; instead of #f (void)))) ((define-c? exp) exp) ((define-syntax? exp) ;(trace:info `(define-syntax ,exp)) (let* ((name (cadr exp)) (trans (caddr exp)) (body (cadr trans))) (cond ((macro:syntax-rules? (env:lookup (car trans) env #f)) ;; Handles renamed 'syntax-rules' identifier (_expand `(define-syntax ,name ,(_expand trans env rename-env local-env local-renamed)) env rename-env local-env local-renamed)) (else ;; TODO: for now, do not let a compiled macro be re-defined. ;; this is a hack for performance compiling (scheme base) (let ((macro (env:lookup name env #f))) (cond ((and (tagged-list? 'macro macro) (or (Cyc-macro? (Cyc-get-cvar (cadr macro))) (procedure? (cadr macro)))) ;(trace:info `(DEBUG compiled macro ,name do not redefine)) ) (else ;; Use this to keep track of macros for filtering unused defines (set! *defined-macros* (cons (cons name body) *defined-macros*)) ;; Keep track of macros added during compilation. ;; TODO: why in both places? (macro:add! name body) (env:define-variable! name (list 'macro body local-renamed) env))) ;; Keep as a 'define' form so available at runtime ;; TODO: may run into issues with expanding now, before some ;; of the macros are defined. may need to make a special pass ;; to do loading or expansion of macro bodies `(define ,name ,(_expand body env rename-env local-env local-renamed))))))) ((let-syntax? exp) (let* ((body (cons 'begin (cddr exp))) (bindings (cadr exp)) (bindings-as-macros (map (lambda (b) (let* ((name (car b)) (binding (cadr b)) (binding-body (cadr binding))) ;(define tmp (env:lookup (car binding) env #f)) ;(display "/* ") ;(write `(DEBUG expand let-syntax ; ,(if (tagged-list? 'macro tmp) ; (Cyc-get-cvar (cadr tmp)) ; tmp) ; ,syntax-rules)) ;(display "*/ ") ;(newline) (cons name (list 'macro ;; Broken for renames, replace w/below: (if (tagged-list? 'syntax-rules binding) (if (macro:syntax-rules? (env:lookup (car binding) env #f)) ;; TODO: is this ok? (cadr (_expand binding env rename-env local-env local-renamed)) binding-body) ;; Preserve local renames at macro definition time local-renamed )))) bindings)) (new-local-macro-env (append bindings-as-macros local-env)) ) ;(trace:error `(let-syntax ,new-local-macro-env)) (_expand body env rename-env new-local-macro-env local-renamed) ;; TODO: new-local-macro-env )) ((letrec-syntax? exp) (let* ((body (cons 'begin (cddr exp))) (body-env (env:extend-environment '() '() env)) (bindings (cadr exp)) ) (for-each (lambda (b) (let* ((name (car b)) (binding (cadr b)) (binding-body (cadr binding)) (macro-val (list 'macro (if (macro:syntax-rules? (env:lookup (car binding) body-env #f)) (cadr (_expand binding body-env rename-env local-env local-renamed)) binding-body) local-renamed))) (env:define-variable! name macro-val body-env))) bindings) (_expand body body-env rename-env local-env local-renamed) )) ((app? exp) (cond ((symbol? (car exp)) (let ((val (let ((local (assoc (car exp) local-env))) (if local (cdr local) (let ((v (env:lookup (car exp) env #f))) v ;; TODO: below was for looking up a renamed macro. may want to consider using it ;; in the symbol condition below... #;(if v v (env:lookup (car exp) rename-env #f))))))) ;;(display "/* ") ;;(write `(app DEBUG ,(car exp) ,val ,env ,local-env ,rename-env ,(env:lookup (car exp) env #f))) ;;(display "*/ ") ;;(newline) (cond ((tagged-list? 'macro val) (_expand ; Could expand into another macro (macro:expand exp val env rename-env local-renamed) env rename-env local-env local-renamed)) ((Cyc-macro? val) (_expand ; Could expand into another macro (macro:expand exp (list 'macro val) env rename-env local-renamed) env rename-env local-env local-renamed)) ;; TODO: if we are doing this, only want to do so if the original variable is a macro. ;; this is starting to get overly complicated though. ;; if nothing else should encapsulate the above lookup into a function and call that ;; in both places (above and here) to simplify things ;; ;; ((and (symbol? val) ;; (not (eq? val (car exp)))) ;; ;; Original macro symbol was renamed. So try again with the orignal symbol ;;(display "/* ") ;;(write `(app DEBUG-syms ,(car exp) ,val ,local-env ,(cdr exp))) ;;(display "*/ ") ;;(newline) ;; (_expand ;; (cons val (cdr exp)) ;; env rename-env local-env local-renamed)) (else (map (lambda (expr) (_expand expr env rename-env local-env local-renamed)) exp))))) (else ;; TODO: note that map does not guarantee that expressions are ;; evaluated in order. For example, the list might be processed ;; in reverse order. Might be better to use a fold here and ;; elsewhere in (expand). (map (lambda (expr) (_expand expr env rename-env local-env local-renamed)) exp)))) (else (error "unknown exp: " exp)))) (define (macro:syntax-rules? exp) (eq? syntax-rules (if (tagged-list? 'macro exp) (Cyc-get-cvar (cadr exp)) exp))) ;; Nicer interface to expand-body (define (expand-lambda-body exp env rename-env) (expand-body '() exp env rename-env)) ;; Helper to expand a lambda body, so we can splice in any begin's (define (expand-body result exp env rename-env) (_expand-body result exp env rename-env '() '())) (define (_expand-body result exp env rename-env local-env local-renamed) ;(define (log e) ; (display (list 'expand-body e 'env ; (env:frame-variables (env:first-frame env))) ; (current-error-port)) ; (newline (current-error-port))) (if (null? exp) (reverse result) (let ((this-exp (car exp))) ;(display (list 'expand-body this-exp) (current-error-port)) ;(newline (current-error-port)) (cond ((or (const? this-exp) (and (prim? this-exp) (not (assoc this-exp local-renamed))) (quote? this-exp) (define-c? this-exp)) ;(log this-exp) (_expand-body (cons this-exp result) (cdr exp) env rename-env local-env local-renamed)) ((ref? this-exp) (let* ((renamed (assoc this-exp local-renamed)) (sym (if renamed (cdr renamed) ;; Extract renamed symbol this-exp))) (_expand-body (cons sym result) (cdr exp) env rename-env local-env local-renamed))) ((define? this-exp) ;(log this-exp) (_expand-body (cons (_expand this-exp env rename-env local-env local-renamed) result) (cdr exp) env rename-env local-env local-renamed)) ((or (define-syntax? this-exp) (letrec-syntax? this-exp) (let-syntax? this-exp) (lambda? this-exp) (set!? this-exp) (if? this-exp)) ;(log (car this-exp)) (_expand-body (cons (_expand this-exp env rename-env local-env local-renamed) result) (cdr exp) env rename-env local-env local-renamed)) ;; Splice in begin contents and keep expanding body ((begin? this-exp) (let* ((expr this-exp) (begin-exprs (begin->exps expr))) ;(log (car this-exp)) (_expand-body result (append begin-exprs (cdr exp)) env rename-env local-env local-renamed))) ((app? this-exp) (cond ((symbol? (caar exp)) ;(log (car this-exp)) (let ((val (let ((local (assoc (caar exp) local-env))) (if local (cdr local) (env:lookup (caar exp) env #f))))) ;(log `(DONE WITH env:lookup ,(caar exp) ,val ,(tagged-list? 'macro val))) (cond ((tagged-list? 'macro val) ;; Expand macro here so we can catch begins in the expanded code, ;; including nested begins (let ((expanded (macro:expand this-exp val env rename-env local-renamed))) ;(log `(DONE WITH macro:expand)) (_expand-body result (cons expanded (cdr exp)) env rename-env local-env local-renamed))) ((Cyc-macro? val) (let ((expanded (macro:expand this-exp (list 'macro val) env rename-env local-renamed))) (_expand-body result (cons expanded (cdr exp)) env rename-env local-env local-renamed))) (else ;; No macro, use main expand function to process (_expand-body (cons (map (lambda (expr) (_expand expr env rename-env local-env local-renamed)) this-exp) result) (cdr exp) env rename-env local-env local-renamed))))) (else ;(log 'app) (_expand-body (cons (map (lambda (expr) (_expand expr env rename-env local-env local-renamed)) this-exp) result) (cdr exp) env rename-env local-env local-renamed)))) (else (error "unknown exp: " this-exp)))))) ;; TODO: this is copied from (scheme cyclone transforms) need to relocate both into a common place (define (list->lambda-formals args type) (cond ((eq? type 'args:fixed) args) ((eq? type 'args:fixed-with-varargs) (list->pair args)) ((eq? type 'args:varargs) (if (> (length args) 1) (error `(Too many args for varargs ,args)) (car args))) (else (error `(Unexpected type ,type))))) (define (list->pair l) (let loop ((lst l)) (cond ((not (pair? lst)) lst) ((null? (cdr lst)) (car lst)) (else (cons (car lst) (loop (cdr lst))))))) ;; Container for built-in macros (define (get-macros) *defined-macros*) (define *defined-macros* (list)) (define (begin->exps exp) (cdr exp)) ))
true
a2ba8f33c4223a177a5477b8731cd73ae7161562
be06d133af3757958ac6ca43321d0327e3e3d477
/99problems/58.scm
e61ff53bfb9313b54a2d004f1fd95cf504bb2816
[]
no_license
aoyama-val/scheme_practice
39ad90495c4122d27a5c67d032e4ab1501ef9c15
f133d9326699b80d56995cb4889ec2ee961ef564
refs/heads/master
2020-03-13T12:14:45.778707
2018-04-26T07:12:06
2018-04-26T07:12:06
131,115,150
0
0
null
null
null
null
UTF-8
Scheme
false
false
1,763
scm
58.scm
(use srfi-1) (define (bool-and a b) (if (and a b) #t #f)) (define (bool-or a b) (if (or a b) #t #f)) (define (bool-xor p q) (or (and (not p) q) (and p (not q)))) (define (uint-and i1 i2) (map (lambda (x) (apply bool-and x)) (zip i1 i2))) (define (uint-or i1 i2) (map (lambda (x) (apply bool-or x)) (zip i1 i2))) (define (uint-xor i1 i2) (map (lambda (x) (apply bool-xor x)) (zip i1 i2))) (define (uint-not i1) (map not i1)) (define (xor p q) (or (and (not p) q) (and p (not q)))) (define (half-adder p q) (values (xor p q) (and p q))) (define (full-adder p q r) (receive (s c) (half-adder p q) (values (xor s r) (or (and p q) (and r (xor p q)))))) (define (uint-add i1 i2) (cond ((null? i1) (values i2 #f)) ((null? i2) (values i1 #f)) (else (receive (next-sum next-carry) (uint-add (cdr i1) (cdr i2)) (receive (s c) (full-adder (car i1) (car i2) next-carry) (values (cons s next-sum) c)))))) (define (uint-inc i1) (uint-add i1 '(#f #f #f #t))) (define (uint-neg x) (uint-inc (uint-not x))) (define (uint-sub x y) (receive (s c) (uint-add x (uint-neg y)) (values s (not c)))) ; 14 - 5 = 9 (receive (s c) (uint-sub '(#t #t #t #f) '(#f #t #f #t)) (print s) (print c)) ; (#t #f #f #t) ; #f ; 14 - 15 = -1 (receive (s c) (uint-sub '(#t #t #t #f) '(#t #t #t #t)) (print s) (print c)) ; (#t #t #t #t) ; #t ; 15 - 15 = 0 (receive (s c) (uint-sub '(#t #t #t #t) '(#t #t #t #t)) (print s) (print c)) ; (#f #f #f #f) ; #f
false
a5599f8a49b2790abaa09f45e7a6ab3cf042aaeb
a74932f6308722180c9b89c35fda4139333703b8
/edwin48/debug.scm
3b612a65f1c4924feab5e001d7256368a6b9e666
[]
no_license
scheme/edwin48
16b5d865492db5e406085e8e78330dd029f1c269
fbe3c7ca14f1418eafddebd35f78ad12e42ea851
refs/heads/master
2021-01-19T17:59:16.986415
2014-12-21T17:50:27
2014-12-21T17:50:27
1,035,285
39
10
null
2022-02-15T23:21:14
2010-10-29T16:08:55
Scheme
UTF-8
Scheme
false
false
57,996
scm
debug.scm
#| -*-Scheme-*- $Id: debug.scm,v 1.73 2008/01/30 20:02:00 cph Exp $ Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 Massachusetts Institute of Technology This file is part of MIT/GNU Scheme. MIT/GNU Scheme is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. MIT/GNU Scheme is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with MIT/GNU Scheme; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. |# ;;;; Browser-style Debug and Where ;;; Package: (edwin debugger) ;;;; Text prop setup stuff (define (with-output-highlighted port thunk) (let ((start (mark-temporary-copy (port/mark port)))) (thunk) (highlight-region (make-region start (port/mark port)) (highlight-face)))) (define (read-only-between start end) (region-read-only (make-region start end))) (define (readable-between start end) (region-writeable (make-region start end))) (define (dehigh-between start end) (highlight-region (make-region start end) (default-face))) (define (debugger-pp-highlight-subexpression expression subexpression indentation port) (let ((start-mark #f) (end-mark #f)) (fluid-let ((*pp-no-highlights?* #f)) (debugger-pp (unsyntax-with-substitutions expression (list (cons subexpression (make-pretty-printer-highlight (unsyntax subexpression) (lambda (port) (set! start-mark (mark-right-inserting-copy (output-port->mark port))) unspecific) (lambda (port) (set! end-mark (mark-right-inserting-copy (output-port->mark port))) unspecific))))) indentation port)) (if (and start-mark end-mark) (highlight-region-excluding-indentation (make-region start-mark end-mark) (highlight-face))) (if start-mark (mark-temporary! start-mark)) (if end-mark (mark-temporary! end-mark)))) ;;;; Browsers (define-record-type <browser> (%make-browser buffer object name lines selected-line buffers properties) browser? ;; The browser's buffer. (buffer browser/buffer) ;; The object being browsed. (object browser/object) ;; Name of this browser, a string. Not necessarily unique. (name browser/name) ;; Vector of BLINE objects, sorted in order of increasing INDEX. (lines browser/lines set-browser/lines!) ;; The current selected BLINE object. (selected-line browser/selected-line set-browser/selected-line!) ;; List of buffers associated with this browser. (buffers browser/buffers set-browser/buffers!) (properties browser/properties)) (define (make-browser name mode object) (let ((buffer (new-buffer name))) (buffer-reset! buffer) (set-buffer-read-only! buffer) (set-buffer-major-mode! buffer mode) (add-kill-buffer-hook buffer kill-browser-buffer) (let ((browser (%make-browser buffer object name (vector) #f '() (make-1d-table)))) (buffer-put! buffer 'BROWSER browser) browser))) (define (kill-browser-buffer buffer) (let ((browser (buffer-get buffer 'BROWSER))) (if browser (for-each kill-buffer (browser/buffers browser))))) (define (buffer-browser buffer) (let ((browser (buffer-get buffer 'BROWSER))) (if (not browser) (error "This buffer has no associated browser:" buffer)) browser)) (define (browser/new-buffer browser initializer) (let ((buffer (create-buffer (let ((prefix (browser/name browser))) (let loop ((index 1)) (let ((name (string-append (if (1d-table/get (browser/properties browser) 'VISIBLE-SUB-BUFFERS? #f) "" " ") prefix "-" (number->string index)))) (if (find-buffer name) (loop (+ index 1)) name))))))) (if initializer (initializer buffer)) (add-browser-buffer! browser buffer) buffer)) (define (add-browser-buffer! browser buffer) (add-rename-buffer-hook buffer (letrec ((hook (lambda (buffer name) name (set-browser/buffers! browser (delete! buffer (browser/buffers browser) eq?)) (remove-rename-buffer-hook buffer hook)))) hook)) (add-kill-buffer-hook buffer (lambda (buffer) (set-browser/buffers! browser (delete! buffer (browser/buffers browser) eq?)))) (set-browser/buffers! browser (cons buffer (browser/buffers browser))) (buffer-put! buffer 'ASSOCIATED-WITH-BROWSER browser)) (define (browser/new-screen browser) (let ((pair (1d-table/get (browser/properties browser) 'NEW-SCREEN #f))) (and pair (weak-car pair)))) (define (set-browser/new-screen! browser screen) (1d-table/put! (browser/properties browser) 'NEW-SCREEN (weak-cons screen #f))) ;;;; Browser Commands (define-command browser-select-line "Select the current browser line." "d" (lambda (point) (let ((bline (mark->bline point))) (if (not bline) (editor-error "Nothing to select on this line.")) (select-bline bline)))) ;;; If the mouse clicks on a bline, select it. (define-command debugger-mouse-select-bline "Select a bline when mouse clicked there." () (lambda () ((ref-command mouse-set-point)) (let ((bline (mark->bline (current-point)))) (if bline (select-bline bline))))) (define-command browser-next-line "Move down to the next line." "p" (lambda (argument) (let* ((browser (buffer-browser (current-buffer))) (bline (letrec ((loop (lambda (index argument) (let ((bline (browser/line browser index))) (cond ((bline/continuation? bline) (replace-continuation-bline bline) (loop index argument)) ((= argument 0) bline) ((> argument 0) (let ((index (+ index 1))) (if (< index (browser/n-lines browser)) (loop index (- argument 1)) (begin (select-bline bline) #f)))) (else (let ((index (- index 1))) (if (<= 0 index) (loop index (+ argument 1)) (begin (select-bline bline) #f))))))))) (let ((point (current-point))) (let ((index (mark->bline-index point))) (cond (index (loop index argument)) ((= argument 0) #f) (else (let ((n (if (< argument 0) -1 1))) (let find-next ((mark point)) (let ((mark (line-start mark n #f))) (and mark (let ((index (mark->bline-index mark))) (if index (loop index (- argument n)) (find-next mark)))))))))))))) (cond (bline (select-bline bline)) ((= argument 0) (editor-failure "Nothing to select on this line.")) (else (editor-failure)))))) (define-command browser-previous-line "Move up to the previous line." "p" (lambda (argument) ((ref-command browser-next-line) (- argument)))) (define (select-bline bline) (let ((bline (if (bline/continuation? bline) (replace-continuation-bline bline) bline))) (let ((browser (bline/browser bline))) (unselect-bline browser) (let ((mark (bline/start-mark bline))) (with-buffer-open mark (lambda () (insert-char #\> (mark1+ mark)) (delete-right-char mark) (highlight-the-number mark))) (set-browser/selected-line! browser bline) (set-buffer-point! (mark-buffer mark) mark))) (let ((buffer (bline/description-buffer bline))) (if buffer (pop-up-buffer buffer #f))))) (define (highlight-the-number mark) (let ((end (re-search-forward "[RSE][0-9]+ " mark (line-end mark 0)))) (highlight-region (make-region mark (if (mark? end) (mark- end 1) (line-end mark 0))) (highlight-face)))) (define (unselect-bline browser) (let ((bline (browser/selected-line browser))) (if bline (let ((mark (bline/start-mark bline))) (with-buffer-open mark (lambda () (dehigh-between mark (line-end mark 0)) (insert-char #\space (mark1+ mark)) (delete-right-char mark))))))) ;;; For any frame with an environment (excluding the mark frame) an ;;; inferior repl is started below the other descriptions. (define (bline/description-buffer bline) (let* ((system? (and (subproblem? (bline/object bline)) (system-frame? (subproblem/stack-frame (bline/object bline))))) (buffer (1d-table/get (bline/properties bline) 'DESCRIPTION-BUFFER #f)) (get-environment (1d-table/get (bline-type/properties (bline/type bline)) 'GET-ENVIRONMENT #f)) (env-exists? (if (and get-environment (not system?)) (let ((environment* (get-environment bline))) (environment? environment*)) #f)) (environment (if env-exists? (get-environment bline) #f))) (if (and buffer (buffer-alive? buffer)) buffer (let ((write-description (bline-type/write-description (bline/type bline)))) ((message-wrapper #t "Computing, please wait") (lambda () (and write-description (let ((buffer (browser/new-buffer (bline/browser bline) #f))) (call-with-output-mark (buffer-start buffer) (lambda (port) (write-description bline port) (if env-exists? (begin (debugger-newline port) (write-string evaluation-line-marker port) (debugger-newline port))))) (set-buffer-point! buffer (buffer-start buffer)) (1d-table/put! (bline/properties bline) 'DESCRIPTION-BUFFER buffer) (read-only-between (buffer-start buffer) (buffer-end buffer)) (buffer-not-modified! buffer) (if env-exists? (start-inferior-repl! buffer environment #f)) buffer)))))))) (define evaluation-line-marker ";EVALUATION may occur below in the environment of the selected frame.") (define-command browser-quit "Exit the current browser, deleting its buffer." () (lambda () (let ((buffer (current-buffer))) (let ((browser (buffer-browser buffer)) (screen (selected-screen))) ;; Delete all windows that are currently showing buffers that ;; are associated with this browser. (let ((window (screen-selected-window screen)) (buffers (browser/buffers browser))) (for-each (lambda (window*) (if (and (not (eq? window* window)) (not (typein-window? window*)) (memq (window-buffer window*) buffers)) (window-delete! window*))) (screen-window-list screen))) ;; If the browser was popped up in a new screen, and that ;; screen is the current screen, delete it too. (let ((new-screen (browser/new-screen browser))) (if (and (eq? new-screen screen) (other-screen screen 1 #t)) (delete-screen! screen)))) ;; Kill the buffer, then maybe select another browser. (let ((browser (get-buffer-browser buffer 'ASSOCIATED-WITH-BROWSER))) (kill-buffer-interactive buffer) (let ((browser (or browser (let ((buffer (current-buffer))) (or (get-buffer-browser buffer 'BROWSER) (get-buffer-browser buffer 'ASSOCIATED-WITH-BROWSER)))))) (if browser (let ((buffer (browser/buffer browser))) (select-buffer buffer) ((ref-command browser-select-line) (buffer-point buffer)))))) (clear-current-message!) (maybe-restart-buffer-thread buffer)))) (define (get-buffer-browser buffer key) (let ((browser (buffer-get buffer key))) (and (browser? browser) (buffer-alive? (browser/buffer browser)) browser))) (define (maybe-restart-buffer-thread buffer) (let ((cont (maybe-get-continuation buffer)) (thread (buffer-get buffer 'THREAD))) (if (and thread cont) (if (eq? thread editor-thread) (signal-thread-event editor-thread (lambda () (cont unspecific))) (restart-thread thread #f #f))))) ;;;addition for when debugger is called from a break ;;;should quit the debugger, and give the continuation ;;;a value to proceed with (restarting that thread) ;;;if in a normal error debug it will envoke the standard ;;;restarts (define-command quit-with-restart-value "Quit the breakpoint, exiting with a specified value." () (lambda () (let* ((buffer (current-buffer)) (thread (buffer-get buffer 'THREAD))) (if (thread? thread) (let ((value (prompt-for-expression-value "Please enter a value to continue with")) (cont (maybe-get-continuation buffer))) (buffer-remove! buffer 'THREAD) ((ref-command browser-quit)) (cond ((eq? thread editor-thread) (signal-thread-event editor-thread (lambda () (cont value)))) (else (set! value? #t) (restart-thread thread #t (lambda () (cont value)))))) (invoke-restarts #f))))) (define (maybe-get-continuation buffer) (let ((object (browser/object (buffer-get buffer 'BROWSER)))) (and (continuation? object) object))) ;;;Method for invoking the standard restarts from within the ;;;debugger. (define (invoke-restarts avoid-deletion?) (let* ((mark (current-point)) (bline (mark->bline mark)) (browser (bline/browser bline)) (buffer (1d-table/get (bline/properties bline) 'DESCRIPTION-BUFFER #f)) (condition (browser/object browser))) (if (condition? condition) (fluid-let ((prompt-for-confirmation (lambda (prompt #!optional port) port (call-with-interface-port (buffer-end buffer) (lambda (port) port (prompt-for-yes-or-no? prompt))))) (prompt-for-evaluated-expression (lambda (prompt #!optional environment port) port (call-with-interface-port (buffer-end buffer) (lambda (port) port (repl-eval (prompt-for-expression prompt) environment))))) (hook/invoke-restart (lambda (continuation arguments) (invoke-continuation continuation arguments avoid-deletion?)))) (call-with-interface-port (let ((buff (new-buffer " *debug*-RESTARTS"))) (add-browser-buffer! browser buff) (pop-up-buffer buff #f) (buffer-start buff)) (lambda (port) (write-string " " port) (write-condition-report condition port) (debugger-newline port) (command/condition-restart (make-initial-dstate condition) port)))) (message "No condition to restart from.")))) (define (call-with-interface-port mark receiver) (let ((mark (mark-left-inserting-copy mark))) (let ((value (receiver (make-port interface-port-type mark)))) (mark-temporary! mark) value))) (define interface-port-type (make-port-type `((WRITE-CHAR ,(lambda (port char) (guarantee-8-bit-char char) (region-insert-char! (port/state port) char))) (PROMPT-FOR-CONFIRMATION ,(lambda (port prompt) port (prompt-for-confirmation? prompt))) (PROMPT-FOR-EXPRESSION ,(lambda (port environment prompt) port environment (prompt-for-expression prompt)))) #f)) (define (invoke-continuation continuation arguments avoid-deletion?) (let ((buffer (current-buffer))) (if (and (not avoid-deletion?) (ref-variable debugger-quit-on-return?)) ((ref-command browser-quit))) ((or (buffer-get buffer 'INVOKE-CONTINUATION) apply) continuation arguments))) ;;;; Where (define-command browser-where "Select an environment browser for this line's environment." () (lambda () (select-buffer (bline/environment-browser-buffer (current-selected-line))))) (define (bline/environment-browser-buffer bline) (let ((environment (bline/evaluation-environment bline))) (bline/attached-buffer bline 'ENVIRONMENT-BROWSER (lambda () (or (find (lambda (buffer) (let ((browser (buffer-get buffer 'BROWSER))) (and browser (eq? environment (browser/object browser))))) (buffer-list)) (environment-browser-buffer environment)))))) (define (bline/attached-buffer bline type make-buffer) (let ((buffer (1d-table/get (bline/properties bline) type #f))) (if (and buffer (buffer-alive? buffer)) buffer (let ((buffer (make-buffer))) (1d-table/put! (bline/properties bline) type buffer) (add-browser-buffer! (bline/browser bline) buffer) buffer)))) (define (current-selected-line) (let ((bline (browser/selected-line (buffer-browser (current-buffer))))) (if (not bline) (editor-error "There is no selected line; please select one.")) bline)) (define (bline/evaluation-environment bline) (let ((get-environment (1d-table/get (bline-type/properties (bline/type bline)) 'GET-ENVIRONMENT #f)) (lose (lambda () (editor-error "The selected line has no environment.")))) (if get-environment (let ((environment (get-environment bline))) (if (environment? environment) environment (lose))) (lose)))) ;;;; Browser Lines (define-record-type <browser-line> (%make-bline start-mark object type parent depth next prev offset properties) bline? ;; Index of this bline within browser lines vector. #F if line is ;; invisible. (index bline/index set-bline/index!) ;; Line start within browser buffer. #F if line is invisible. (start-mark bline/start-mark set-bline/start-mark!) ;; Object that this line represents. (object bline/object) ;; Type of OBJECT. This type is specific to the browser; it tells ;; the browser how to manipulate OBJECT. (type bline/type) ;; BLINE representing the object that this object is a component of, ;; or #F if none. (parent bline/parent) ;; Nonnegative integer indicating the depth of this object in the ;; component nesting. (depth bline/depth) ;; BLINEs representing the objects that are adjacent to this one in ;; the component ordering, or #F if none. (next bline/next set-bline/next!) (prev bline/prev) ;; Nonnegative integer indicating the position of this object in the ;; component ordering. (offset bline/offset) (properties bline/properties)) (define (make-bline object type parent prev) (let ((bline (%make-bline #f object type parent (if parent (+ (bline/depth parent) 1) 0) #f prev (if prev (+ (bline/offset prev) 1) 0) (make-1d-table)))) (if prev (set-bline/next! prev bline)) bline)) (define (bline/browser bline) (buffer-browser (mark-buffer (bline/start-mark bline)))) ;;;; Browser Line Editing (define (browser/n-lines browser) (vector-length (browser/lines browser))) (define (browser/line browser index) (vector-ref (browser/lines browser) index)) (define (mark->bline mark) (let ((blines (browser/lines (buffer-browser (mark-buffer mark)))) (group (mark-group mark)) (index (mark-index mark))) (let loop ((low 0) (high (vector-length blines))) (and (fix:< low high) (let ((middle (fix:quotient (fix:+ low high) 2))) (let ((bline (vector-ref blines middle))) (let ((ls (mark-index (bline/start-mark bline)))) (cond ((fix:< index ls) (loop low middle)) ((fix:<= index (line-end-index group ls)) bline) (else (loop (fix:+ middle 1) high)))))))))) (define (mark->bline-index mark) (let ((bline (mark->bline mark))) (and bline (bline/index bline)))) (define (delete-blines browser start end) (if (< start end) (let ((bv (browser/lines browser))) (if (subvector-find-next-element bv start end (browser/selected-line browser)) (unselect-bline browser)) (let ((nbv (vector-length bv))) (let ((bv* (make-vector (- nbv (- end start))))) (do ((i 0 (+ i 1))) ((= i start)) (vector-set! bv* i (vector-ref bv i))) (do ((i end (+ i 1)) (j start (+ j 1))) ((= i nbv)) (let ((bline (vector-ref bv i))) (set-bline/index! bline j) (vector-set! bv* j bline))) (let ((start-mark (bline/start-mark (vector-ref bv start)))) (with-buffer-open start-mark (lambda () (delete-string start-mark (if (< end nbv) (bline/start-mark (vector-ref bv end)) (buffer-end (browser/buffer browser))))))) (set-browser/lines! browser bv*)))))) (define (insert-blines browser index blines) (if (not (null? blines)) (let ((bv (browser/lines browser)) (n-blines (length blines))) (let ((nbv (vector-length bv))) (let ((bv* (make-vector (+ nbv n-blines)))) (do ((i 0 (+ i 1))) ((= i index)) (vector-set! bv* i (vector-ref bv i))) (do ((blines blines (cdr blines)) (i index (+ i 1))) ((null? blines)) (let ((bline (car blines))) (set-bline/index! bline i) (vector-set! bv* i bline))) (do ((i index (+ i 1)) (j (+ index n-blines) (+ j 1))) ((= i nbv)) (let ((bline (vector-ref bv i))) (set-bline/index! bline j) (vector-set! bv* j bline))) (let ((start-mark (if (< index nbv) (bline/start-mark (vector-ref bv index)) (buffer-end (browser/buffer browser))))) (with-buffer-open start-mark (lambda () (let ((mark (mark-left-inserting-copy start-mark)) (columns 79)) (for-each (lambda (bline) (let ((index (mark-index mark)) (indentation (+ 1 (* summary-indentation-increment (bline/depth bline))))) (insert-horizontal-space indentation mark) (let ((summary (with-output-to-truncated-string (max summary-minimum-columns (- columns indentation 4)) (lambda () ((bline-type/write-summary (bline/type bline)) bline (current-output-port)))))) (insert-string (cdr summary) mark) (if (car summary) (insert-string " ..." mark))) (insert-newline mark) (set-bline/start-mark! bline (make-permanent-mark (mark-group mark) index #t)))) blines) (mark-temporary! mark))))) (set-browser/lines! browser bv*)))))) (define summary-indentation-increment 3) (define summary-minimum-columns 10) ;;;; Browser Line Types (define-record-type <browser-line-type> (%make-bline-type write-summary write-description selection-mark properties) bline-type? ;; Procedure that is called to generate the browser line that ;; represents this object. Two arguments: BLINE and PORT. The ;; summary of BLINE is written to PORT. The summary should fit on ;; one line; PORT will limit the number of characters that can be ;; printed so that it fits. (write-summary bline-type/write-summary) ;; Procedure that is called to generate a full description of the ;; object. Two arguments: BLINE and PORT. This description may use ;; multiple lines; it will be presented in its own buffer, so the ;; presentation style is not very constrained. This component may ;; be #F to indicate that the object is not normally viewed. (write-description bline-type/write-description) ;; Procedure that generates the standard mark at which the point ;; should be placed when this object is selected. One argument: ;; BLINE. This component may be a nonnegative exact integer meaning ;; an offset from the START-MARK of the bline. (selection-mark bline-type/selection-mark) (properties bline-type/properties)) (define (make-bline-type write-summary write-description selection-mark) (%make-bline-type write-summary write-description selection-mark (make-1d-table))) (define (make-continuation-bline expander parent prev) (make-bline expander bline-type:continuation-line parent prev)) (define (continuation-line/write-summary bline port) bline (write-string "--more--" port)) (define bline-type:continuation-line (make-bline-type continuation-line/write-summary #f 0)) (define (bline/continuation? bline) (eq? (bline/type bline) bline-type:continuation-line)) (define (replace-continuation-bline bline) (let ((browser (bline/browser bline)) (index (bline/index bline)) (expansion ((bline/object bline)))) (delete-blines browser index (+ index 1)) (insert-blines browser index expansion) (car expansion))) ;;;; Control Variables (define (boolean-or-ask? object) (or (boolean? object) (eq? 'ASK object))) (define-variable debugger-one-at-a-time? "Allow only one debugger buffer to exist at a given time. #T means delete an existing debugger buffer before making a new one. #F means leave existing buffers alone. 'ASK means ask user what to do each time." 'ASK boolean-or-ask?) (define-variable debugger-max-subproblems "Maximum number of subproblems displayed when debugger starts. Set this variable to #F to disable this limit." 10 (lambda (object) (or (not object) (and (exact-integer? object) (> object 0))))) (define-variable debugger-confirm-return? "True means prompt for confirmation in \"return\" commands. The prompting occurs prior to returning the value." #t boolean?) (define-variable debugger-quit-on-return? "True means quit debugger when executing a \"return\" command. Quitting the debugger kills the debugger buffer and any associated buffers." #t boolean?) (define-variable debugger-quit-on-restart? "True means quit debugger when executing a \"restart\" command. Quitting the debugger kills the debugger buffer and any associated buffers." #t boolean?) ;;; Limited this because the bindings are now pretty-printed. (define-variable environment-package-limit "Packages with more than this number of bindings will be abbreviated. Set this variable to #F to disable this abbreviation." 10 (lambda (object) (or (not object) (exact-nonnegative-integer? object)))) (define-variable debugger-show-help-message? "True means show the help message, #f means don't." #T boolean?) (define-variable debugger-start-new-frame? "#T means create a new frame whenever the debugger is invoked. #F means continue in same frame. 'ASK means ask user." #T boolean-or-ask?) (define edwin-variable$debugger-start-new-screen? edwin-variable$debugger-start-new-frame?) (define-variable debugger-hide-system-code? "True means don't show subproblems created by the runtime system." #T boolean?) (define-variable debugger-show-frames? "If true show the environment frames in the description buffer. If false show the bindings without frames." #T boolean?) (define-variable debugger-show-inner-frame-topmost? "Affects the debugger display when DEBUGGER-SHOW-FRAMES? is true. If false, frames are displayed with the outer (most global) frame topmost, like in a 6.001 style environment diagram. This is the default. If true, frames are display innermost first." #F boolean?) (define-variable debugger-compact-display? "If true, the debugger omits some blank lines. If false, more blank lines are produced between display elements. This variable is usually set to #F, but setting it to #T is useful to get more information in a short window, for example, when using a fixed size terminal." #F boolean?) ;;;; Predicates ;;; Determines if a frame is marked. (define (system-frame? stack-frame) (stack-frame/repl-eval-boundary? stack-frame)) ;;; Bad implementation to determine for breaks if a value to proceed ;;; with is desired. (define value? #f) (define (invalid-subexpression? subexpression) (or (debugging-info/undefined-expression? subexpression) (debugging-info/unknown-expression? subexpression))) (define (invalid-expression? expression) (or (debugging-info/undefined-expression? expression) (debugging-info/compiled-code? expression))) ;;;; Help Messages ;;; The help messages for the debugger (define where-help-message " COMMANDS: ? - Help q - Quit environment browser This is an environment-browser buffer. Lines identify environment frames. The buffer below shows the bindings of the selected environment. -----------") (define debugger-help-message " COMMANDS: ? - Help q - Quit debugger e - Environment browser This is a debugger buffer. Lines identify stack frames, most recent first. Sx means frame is in subproblem number x. Ry means frame is reduction number y. The buffer below shows the current subproblem or reduction. -----------") ;;;; Debugger entry point (define starting-debugger? #f) (define (debug-scheme-error error-type condition ask?) (if starting-debugger? (quit-editor-and-signal-error condition) (begin (let ((start-debugger (lambda () (fluid-let ((starting-debugger? #t)) (select-continuation-browser-buffer condition))))) (if ask? (if (cleanup-pop-up-buffers (lambda () (standard-error-report error-type condition #t) (editor-beep) (prompt-for-confirmation? "Start debugger"))) (start-debugger)) (begin (start-debugger) (message (string-titlecase (symbol->string error-type)) " error") (editor-beep)))) (return-to-command-loop condition)))) (define (select-continuation-browser-buffer object #!optional thread) (set! value? #f) (let ((buffers (find-debugger-buffers))) (if (and (pair? buffers) (null? (cdr buffers)) (if (eq? 'ASK (ref-variable debugger-one-at-a-time? #f)) (prompt-for-confirmation? "Another debugger buffer exists. Delete it") (ref-variable debugger-one-at-a-time? #f))) (kill-buffer (car buffers)))) (let ((buffer (continuation-browser-buffer object))) (let ((thread (and (not (default-object? thread)) thread))) (if thread (buffer-put! buffer 'THREAD thread))) (let ((screen (make-debug-screen buffer))) (if screen (select-screen screen) (select-buffer buffer))) ((ref-command browser-select-line) (buffer-point buffer)))) (define-command browse-continuation "Invoke the continuation-browser on CONTINUATION." "XBrowse Continuation" select-continuation-browser-buffer) (define (make-debug-screen buffer) (and (multiple-screens?) (let ((new-screen? (ref-variable debugger-start-new-screen? buffer))) (if (eq? new-screen? 'ASK) (prompt-for-confirmation? "Start debugger in new screen") new-screen?)) (let ((screen (apply make-screen buffer (make-debug-screen-args)))) (set-browser/new-screen! (buffer-browser buffer) screen) screen))) (define (make-debug-screen-args) (case (display-type/name (current-display-type)) ((X) (cond ((string? default-screen-geometry) (list default-screen-geometry)) ((eq? default-screen-geometry 'ASK) (let ((geometry (let loop ((default default-screen-geometry)) (let ((geometry (prompt-for-string "Please enter a geometry" default))) (if (geometry? geometry) geometry (loop geometry)))))) (set! default-screen-geometry geometry) geometry)) (else '()))) (else '()))) (define (geometry? geometry) (let ((geometry-pattern "[0-9]+x[0-9]+\\(-[0-9]+\\|+[0-9]+\\|\\)\\(-[0-9]+\\|+[0-9]+\\|\\)")) (re-string-match (re-compile-pattern geometry-pattern #f) geometry))) (define default-screen-geometry #f) (define (continuation-browser-buffer object) (let ((browser (make-browser "*debug*" (ref-mode-object continuation-browser) object)) (blines (continuation->blines (cond ((continuation? object) object) ((condition? object) (condition/continuation object)) (else (error:wrong-type-argument object "condition or continuation" 'CONTINUATION-BROWSER-BUFFER))) (ref-variable debugger-max-subproblems)))) (let ((buffer (browser/buffer browser))) (let ((mark (buffer-end buffer))) (with-buffer-open mark (lambda () (call-with-output-mark mark (lambda (port) (if (ref-variable debugger-show-help-message?) (write-string debugger-help-message port)) (debugger-newline port) (if (condition? object) (begin (write-string "The " port) (write-string (if (condition/error? object) "error" "condition") port) (write-string " that started the debugger is:" port) (debugger-newline port) (debugger-newline port) (write-string " " port) (with-output-highlighted port (lambda () (write-condition-report object port))) (debugger-newline port))) (debugger-newline port)))))) (insert-blines browser 0 blines) (set-buffer-point! buffer (if (null? blines) (buffer-end buffer) (bline/start-mark (car blines)))) buffer))) (define (find-debugger-buffers) (filter (let ((debugger-mode (ref-mode-object continuation-browser))) (lambda (buffer) (eq? (buffer-major-mode buffer) debugger-mode))) (buffer-list))) ;;;; Continuation Browser Mode (define-major-mode continuation-browser read-only "Debug" " ******* Debugger Help ******* Commands: `mouse-button-1' Select a subproblem or reduction and display information in the description buffer. `C-n' `down-arrow' Move the cursor down the list of subproblems and reductions and display info in the description buffer. `C-p' `up-arrow' Move the cursor up the list of subproblems and reductions and display info in the description buffer. `e' Show the environment structure. `q' Quit the debugger, destroying its window. `p' Invoke the standard restarts. `SPC' Display info on current item in the description buffer. `?' Display help information. Each line beginning with `S' represents either a subproblem or stack frame. A subproblem line may be followed by one or more indented lines \(beginning with the letter `R') which represent reductions associated with that subproblem. The subproblems are indexed with the natural numbers. To obtain a more complete description of a subproblem or reduction, click the mouse on the desired line or move the cursor to the line using the arrow keys (or `C-n' and `C-p'). The description buffer will display the additional information. The description buffer contains three major regions. The first region contains a pretty printed version of the current expression. The current subproblem within the expression is highlighted. The second region contains a representation of the frames of the environment of the current expression. The bindings of each frame are listed below the frame header. If there are no bindings in the frame, none will be listed. The frame of the current expression is preceeded with ==>. The bottom of the description buffer contains a region for evaluating expressions in the environment of the selected subproblem or reduction. This is the only portion of the buffer where editing is possible. This region can be used to find the values of variables in different environments; you cannot, however, use mutators (set!, etc.) on compiled code. Typing `e' creates a new buffer in which you may browse through the current environment. In this new buffer, you can use the mouse, the arrows, or `C-n' and `C-p' to select lines and view different environments. The environments listed are the same as those in the description buffer. If the selected environment structure is too large to display (if there are more than `environment-package-limit' items in the environment) an appropriate message is displayed. To display the environment in this case, set the `environment-package-limit' variable to `#f'. This process is initiated by the command `M-x set-variable'. You can not use `set!' to set the variable because it is an editor variable and does not exist in the current scheme environment. At the bottom of the new buffer is a region for evaluating expressions similar to that of the description buffer. The appearance of environment displays is controlled by the editor variables `debugger-show-inner-frame-topmost?' and `debugger-compact-display?' which affect the ordering of environment frames and the line spacing respectively. Type `q' to quit the debugger, killing its primary buffer and any others that it has created. NOTE: The debugger creates discription buffers in which debugging information is presented. These buffers are given names beginning with spaces so that they do not appear in the buffer list; they are automatically deleted when you quit the debugger. If you wish to keep one of these buffers, simply rename it using `M-x rename-buffer': once it has been renamed, it will not be deleted automatically.") (define-key 'continuation-browser (kbd (ctrl #\p)) 'quit-with-restart-value) (define-key 'continuation-browser (kbd down) 'browser-next-line) (define-key 'continuation-browser (kbd up) 'browser-previous-line) (define-key 'continuation-browser button1-down 'debugger-mouse-select-bline) (define-key 'continuation-browser (kbd (ctrl #\n)) 'browser-next-line) (define-key 'continuation-browser (kbd (ctrl #\p)) 'browser-previous-line) (define-key 'continuation-browser (kbd #\?) 'describe-mode) (define-key 'continuation-browser (kbd (ctrl #\q)) 'browser-quit) (define-key 'continuation-browser (kbd (ctrl #\space)) 'browser-select-line) (define-key 'continuation-browser (kbd #\e) 'browser-where) ;;;; Subproblems ;; A continuation consists of subproblems. A subproblem has ;; expression information that identifies what the subproblem means. ;; It additionally has reductions and an environment. Similarly, ;; reductions have expression and environment information. ;; Environments consist of environment frames, and each frame consists ;; of bindings. Subproblems, reductions, and environment frames are ;; ordered; bindings are not. ;;; Stops displaying subproblems past marked frame by default. (define (continuation->blines continuation limit) (let ((beyond-system-code #f)) (let loop ((frame (continuation/first-subproblem continuation)) (prev #f) (n 0)) (if (not frame) '() (let* ((next-subproblem (lambda (bline) (loop (stack-frame/next-subproblem frame) bline (+ n 1)))) (walk-reductions (lambda (bline reductions) (cons bline (let loop ((reductions reductions) (prev #f)) (if (null? reductions) (next-subproblem bline) (let ((bline (make-bline (car reductions) bline-type:reduction bline prev))) (cons bline (loop (cdr reductions) bline)))))))) (continue (lambda () (let* ((subproblem (stack-frame->subproblem frame n))) (if debugger:student-walk? (let ((reductions (subproblem/reductions subproblem))) (if (null? reductions) (let ((bline (make-bline subproblem bline-type:subproblem #f prev))) (cons bline (next-subproblem bline))) (let ((bline (make-bline (car reductions) bline-type:reduction #f prev))) (walk-reductions bline (if (> n 0) '() (cdr reductions)))))) (walk-reductions (make-bline subproblem bline-type:subproblem #f prev) (subproblem/reductions subproblem))))))) (cond ((and (not (ref-variable debugger-hide-system-code?)) (system-frame? frame)) (loop (stack-frame/next-subproblem frame) prev n)) ((or (and limit (>= n limit)) (if (system-frame? frame) (begin (set! beyond-system-code #t) #t) #f) beyond-system-code) (list (make-continuation-bline continue #f prev))) (else (continue)))))))) (define-record-type <subproblem> (make-subproblem stack-frame expression environment subexpression number) subproblem? (stack-frame subproblem/stack-frame) (expression subproblem/expression) (environment subproblem/environment) (subexpression subproblem/subexpression) (number subproblem/number)) (define (stack-frame->subproblem frame number) (receive (expression environment subexpression) (stack-frame/debugging-info frame) (make-subproblem frame expression environment subexpression number))) (define-record-type <reduction> (make-reduction subproblem expression environment number) reduction? (subproblem reduction/subproblem) (expression reduction/expression) (environment reduction/environment) (number reduction/number)) (define (subproblem/reductions subproblem) (let ((frame (subproblem/stack-frame subproblem))) (let loop ((reductions (stack-frame/reductions frame)) (n 0)) (if (pair? reductions) (cons (make-reduction subproblem (caar reductions) (cadar reductions) n) (loop (cdr reductions) (+ n 1))) '())))) (define (subproblem/write-summary bline port) (let* ((subproblem (bline/object bline)) (frame (subproblem/stack-frame subproblem))) (if (system-frame? frame) (write-string "***************Internal System Code Follows***********" port) (begin (write-string "S" port) (write-string (bline/offset-string (subproblem/number subproblem)) port) (write-string " " port) (let ((expression (subproblem/expression subproblem)) (subexpression (subproblem/subexpression subproblem))) (cond ((debugging-info/compiled-code? expression) (write-string ";unknown compiled code" port)) ((not (debugging-info/undefined-expression? expression)) (fluid-let ((*unparse-primitives-by-name?* #t)) (write (unsyntax (if (invalid-subexpression? subexpression) expression subexpression))))) ((debugging-info/noise? expression) (write-string ";" port) (write-string ((debugging-info/noise expression) #f) port)) (else (write-string ";undefined expression" port)))))))) (define (subproblem/write-description bline port) (let* ((subproblem (bline/object bline)) (frame (subproblem/stack-frame subproblem))) (cond ((system-frame? frame) (write-string "The subproblems which follow are part of the " port) (write-string "internal system workings." port)) (else (write-string " SUBPROBLEM LEVEL: " port) (write (subproblem/number subproblem) port) (debugger-newline port) (debugger-newline port) (let ((expression (subproblem/expression subproblem)) (frame (subproblem/stack-frame subproblem))) (cond ((not (invalid-expression? expression)) (write-string (if (stack-frame/compiled-code? frame) "COMPILED expression" "Expression") port) (write-string " (from stack):" port) (debugger-newline port) (write-string " Subproblem being executed is highlighted.\n" port) (debugger-newline port) (let ((subexpression (subproblem/subexpression subproblem))) (if (invalid-subexpression? subexpression) (debugger-pp expression expression-indentation port) (debugger-pp-highlight-subexpression expression subexpression expression-indentation port)))) ((debugging-info/noise? expression) (write-string ((debugging-info/noise expression) #t) port)) (else (write-string (if (stack-frame/compiled-code? frame) "Compiled expression unknown" "Expression unknown") port) (debugger-newline port) (write (stack-frame/return-address frame) port)))) (let ((environment (subproblem/environment subproblem))) (if (not (debugging-info/undefined-environment? environment)) (begin (debugger-newline port) (debugger-newline port) (desc-show-environment-name-and-bindings environment port)))))))) (define bline-type:subproblem (make-bline-type subproblem/write-summary subproblem/write-description 1)) (1d-table/put! (bline-type/properties bline-type:subproblem) 'GET-ENVIRONMENT (lambda (bline) (subproblem/environment (bline/object bline)))) ;;;; Reductions (define (reduction/write-summary bline port) (let ((reduction (bline/object bline))) (if (bline/parent bline) (begin (write-string "R" port) (write-string (bline/offset-string (reduction/number reduction)) port)) (begin (write-string "S" port) (write-string (bline/offset-string (subproblem/number (reduction/subproblem reduction))) port))) (write-string " " port) (fluid-let ((*unparse-primitives-by-name?* #t)) (write (unsyntax (reduction/expression reduction)) port)))) (define (reduction/write-description bline port) (let ((reduction (bline/object bline))) (write-string " SUBPROBLEM LEVEL: " port) (write (subproblem/number (reduction/subproblem reduction)) port) (write-string " REDUCTION NUMBER: " port) (write (reduction/number reduction) port) (debugger-newline port) (debugger-newline port) (write-string "Expression (from execution history):" port) (debugger-newline port) (debugger-newline port) (debugger-pp (reduction/expression reduction) expression-indentation port) (debugger-newline port) (debugger-newline port) (desc-show-environment-name-and-bindings (reduction/environment reduction) port))) (define bline-type:reduction (make-bline-type reduction/write-summary reduction/write-description 1)) (1d-table/put! (bline-type/properties bline-type:reduction) 'GET-ENVIRONMENT (lambda (bline) (reduction/environment (bline/object bline)))) ;;;; Environments (define-command browse-environment "Invoke the environment-browser on ENVIRONMENT." "XBrowse Environment" (lambda (environment) (select-buffer (environment-browser-buffer environment)))) ;;; Adds a help line. (define (environment-browser-buffer object) (let ((environment (->environment object))) (let ((browser (make-browser "*where*" (ref-mode-object environment-browser) object)) (blines (environment->blines environment))) (let ((buffer (browser/buffer browser))) (let ((mark (buffer-end buffer))) (with-buffer-open mark (lambda () (call-with-output-mark mark (lambda (port) (if (ref-variable debugger-show-help-message?) (write-string where-help-message port)) (debugger-newline port)))))) (insert-blines browser 0 blines) (if (null? blines) (set-buffer-point! buffer (buffer-end buffer)) (select-bline (car blines))) buffer)))) (define (environment->blines environment) (let loop ((environment environment) (prev #f)) (let ((bline (make-bline environment bline-type:environment #f prev))) (cons bline (if (eq? #t (environment-has-parent? environment)) (loop (environment-parent environment) bline) '()))))) (define-major-mode environment-browser read-only "Environment Browser" " ********Environment Browser Help******** Commands: `mouse-button-1' Select a subproblem or reduction and display information in the description buffer. `C-n' `down-arrow' Move the cursor down the list of subproblems and reductions and display info in the description buffer. `C-p' `up-arrow' Move the cursor up the list of subproblems and reductions and display info in the description buffer. `q' Quit the environment browser, destroying its window. `SPC' Display info on current item in the description buffer. `?' Display help information. In this buffer, you can use the mouse, the arrows, or `C-n' and `C-p' to select lines and view different environments. If the selected environment structure is too large to display (if there are more than `environment-package-limit' items in the environment) an appropriate message is displayed. To display the environment in this case, set the `environment-package-limit' variable to `#f'. This process is initiated by the command `M-x set-variable'. You can not use `set!' to set the variable because it is an editor variable and does not exist in the current scheme environment. The bottom of the description buffer contains a region for evaluating expressions in the environment of the selected subproblem or reduction. This is the only portion of the buffer where editing is possible. This region can be used to find the values of variables in different environments; you cannot, however, use mutators (set!, etc.) on compiled code. Type `q' to quit the environment browser, killing its primary buffer and any others that it has created. NOTE: The environment browser creates discription buffers in which debugging information is presented. These buffers are given names beginning with spaces so that they do not appear in the buffer list; they are automatically deleted when you quit the debugger. If you wish to keep one of these buffers, simply rename it using `M-x rename-buffer': once it has been renamed, it will not be deleted automatically.") (define-key 'environment-browser (kbd down) 'browser-next-line) (define-key 'environment-browser (kbd up) 'browser-previous-line) (define-key 'environment-browser button1-down 'debugger-mouse-select-bline) (define-key 'environment-browser (kbd (ctrl #\n)) 'browser-next-line) (define-key 'environment-browser (kbd (ctrl #\p)) 'browser-previous-line) (define-key 'environment-browser (kbd #\?) 'describe-mode) (define-key 'environment-browser (kbd (ctrl #\q)) 'browser-quit) (define-key 'environment-browser (kbd (ctrl #\space)) 'browser-select-line) (define (environment/write-summary bline port) (write-string "E" port) (write-string (bline/offset-string (bline/offset bline)) port) (write-string " " port) (show-environment-name (bline/object bline) port)) (define (environment/write-description bline port) (let ((environment (bline/object bline))) (show-environment-name-and-bindings environment port))) (define (show-environment-name-and-bindings environment port) (show-environment-name environment port) (debugger-newline port) (debugger-newline port) (let ((names (environment-bound-names environment)) (package (environment->package environment)) (finish (lambda (names) (debugger-newline port) (for-each (lambda (name) (myprint-binding name (environment-safe-lookup environment name) port)) names)))) (cond ((null? names) (write-string " has no bindings" port)) ((and package (let ((limit (ref-variable environment-package-limit))) (and limit (let ((n (length names))) (and (>= n limit) (begin (write-string " has " port) (write n port) (write-string " bindings (first " port) (write limit port) (write-string " shown):" port) (finish (take names limit)) #t))))))) (else (write-string " BINDINGS:" port) (finish (if package (list-sort symbol<? names) names))))) (debugger-newline port) (debugger-newline port) (write-string "---------------------------------------------------------------------" port)) ;;;This does some stuff who's end product is to pp the bindings (define (myprint-binding name value port) (let ((x-size (output-port/x-size port))) (debugger-newline port) (let ((name1 (output-to-string (quotient x-size 2) (lambda () (write-dbg-name name (current-output-port)))))) (write-string name1 port) (cond ((unassigned-reference-trap? value) (write-string " is unassigned" port)) ((macro-reference-trap? value) (write-string " is a syntactic keyword" port)) (else (let ((separator " = ")) (write-string separator port) (let ((indentation (+ (string-length name1) (string-length separator)))) (write-string (string-tail (with-output-to-string (lambda () (pretty-print value (current-output-port) #t indentation))) indentation) port)))))) (debugger-newline port))) (define bline-type:environment (make-bline-type environment/write-summary environment/write-description 1)) (1d-table/put! (bline-type/properties bline-type:environment) 'GET-ENVIRONMENT bline/object) (define (bline/offset-string number) (let ((string (number->string number))) (if (< (string-length string) offset-string-min) (string-pad-right string offset-string-min) string))) (define offset-string-min 2) (define (with-buffer-open mark thunk) (with-read-only-defeated mark thunk) (buffer-not-modified! (mark-buffer mark))) (define (desc-show-environment-name-and-bindings environment port) (write-string "---------------------------------------------------------------------" port) (if (ref-variable debugger-show-frames?) (show-frames-and-bindings environment port) (print-the-local-bindings environment port)) (debugger-newline port) (write-string "---------------------------------------------------------------------" port)) (define (debugger-newline port) (if (ref-variable debugger-compact-display?) (fresh-line port) (newline port))) (define (show-frames-and-bindings environment port) (define (envs environment) (cons environment (if (environment-has-parent? environment) (envs (environment-parent environment)) '()))) (define (show-frames envs indents) (for-each (lambda (env indent) (debugger-newline port) (if (eq? env environment) (let* ((pointer "==> ") (pl (string-length pointer))) (if (> (string-length indent) pl) (write-string (string-tail indent pl) port)) (write-string pointer port)) (write-string indent port)) (show-environment-name env port) (debugger-newline port) (show-environment-bindings-with-ind env indent port)) envs indents)) (let ((env-list (envs environment))) (cond ((ref-variable debugger-show-inner-frame-topmost?) (show-frames env-list (make-list (length env-list) ""))) (else (show-frames (reverse env-list) (make-initialized-list (length env-list) (lambda (i) (make-string (* i 2) #\space)))))))) (define (print-the-local-bindings environment port) (let ((names (get-all-local-bindings environment))) (let ((n-bindings (length names)) (finish (lambda (names) (for-each (lambda (name) (let loop ((env environment)) (if (environment-bound? env name) (print-binding-with-ind name (environment-safe-lookup env name) " " port) (loop (environment-parent env))))) names)))) (debugger-newline port) (show-environment-name environment port) (cond ((zero? n-bindings) (debugger-newline port) (write-string " has no bindings" port) (debugger-newline port)) ((> n-bindings (ref-variable environment-package-limit))) (else (debugger-newline port) (debugger-newline port) (write-string " Local Bindings:" port) (debugger-newline port) (finish names)))))) (define (show-environment-name environment port) (write-string "ENVIRONMENT " port) (let ((package (environment->package environment))) (if package (begin (write-string "named: " port) (write (package/name package) port)) (begin (write-string "created by " port) (print-user-friendly-name environment port))))) (define (get-all-local-bindings environment) (define (envs environment) (if (environment-has-parent? environment) (cons environment (envs (environment-parent environment))) ; '())) (let* ((env-list (envs environment)) (names1 (map (lambda (envir) (let ((names (environment-bound-names envir))) (if (< (length names) (ref-variable environment-package-limit)) names '()))) env-list)) (names2 (reduce-right append '() names1)) (names3 (let loop ((l names2)) (if (null? l) l (cons (car l) (loop (delete (car l) l)))))) (names4 (list-sort symbol<? names3))) names4)) (define (show-environment-bindings-with-ind environment ind port) (let ((names (environment-bound-names environment))) (let ((n-bindings (length names)) (finish (lambda (names) (debugger-newline port) (for-each (lambda (name) (print-binding-with-ind name (environment-safe-lookup environment name) ind port)) names)))) (cond ((environment->package environment) (write-string (string-append ind " has ") port) (write n-bindings port) (write-string " bindings" port) (debugger-newline port)) ((zero? n-bindings) #|(write-string (string-append ind " has no bindings") port) (debugger-newline port)|#) ((> n-bindings (ref-variable environment-package-limit)) (write-string (string-append ind " has ") port) (write n-bindings port) (write-string " bindings (see editor variable environment-package-limit)" port) (debugger-newline port)) (else (finish names)))))) (define (print-binding-with-ind name value ind port) (let* ((extra " ") (x-size (- (output-port/x-size port) (+ (string-length ind) (string-length extra))))) (write-string ind port) (write-string extra port) (let ((name (output-to-string (quotient x-size 2) (lambda () (write-dbg-name name (current-output-port)))))) (write-string name port) (cond ((unassigned-reference-trap? value) (write-string " is unassigned" port)) ((macro-reference-trap? value) (write-string " is a syntactic keyword" port)) (else (let ((separator " = ")) (write-string separator port) (write-string (output-to-string (max 0 (- (- x-size 1) (+ (string-length name) (string-length separator)))) (lambda () (write value))) port))))) (debugger-newline port)))
false
0867e14bb8e88c37811af61af5d04c4bafbb313f
7ccc32420e7caead27a5a138a02e9c9e789301d0
/coefficient-gpe.sls
08b1bc735c5c85d889ec0acfa52207524527d89a
[ "Apache-2.0" ]
permissive
dharmatech/mpl
03d9c884a51c3aadc0f494e0d0cebf851f570684
36f3ea90ba5dfa0323de9aaffd5fd0f4c11643d7
refs/heads/master
2023-02-05T20:21:56.382533
2023-01-31T18:10:51
2023-01-31T18:10:51
280,353
63
8
Apache-2.0
2023-01-31T18:10:53
2009-08-17T21:02:35
Scheme
UTF-8
Scheme
false
false
2,162
sls
coefficient-gpe.sls
#!r6rs (library (mpl coefficient-gpe) (export coefficient-gpe coefficient-monomial-gpe) (import (mpl rnrs-sans) (mpl misc) (mpl arithmetic) (mpl contains)) ;; (define (base u) ;; (list-ref u 1)) ;; (define (exponent u) ;; (list-ref u 2)) (define undefined 'undefined) (define (coefficient-monomial-gpe u x) (cond ( (equal? u x) '(1 1) ) ( (and (power? u) (equal? (base u) x) (integer? (exponent u)) (> (exponent u) 1)) (list 1 (exponent u)) ) ( (product? u) (let loop ( (m 0) (c u) (i 1) ) (if (>= i (length u)) (list c m) (let ((f (coefficient-monomial-gpe (list-ref u i) x))) (cond ( (eq? f undefined) undefined ) ( (not (equal? (list-ref f 1) 0)) (let ((m (list-ref f 1))) (let ((c (/ u (^ x m)))) (loop m c (+ i 1)))) ) ( else (loop m c (+ i 1)) ))))) ) ( (free? u x) (list u 0) ) ( else undefined ))) (define (coefficient-gpe u x j) (cond ( (not (sum? u)) (let ((f (coefficient-monomial-gpe u x))) (cond ( (eq? f undefined) undefined ) ( (equal? j (list-ref f 1)) (list-ref f 0) ) ( else 0 ))) ) ( (equal? u x) (if (equal? j 1) 1 0) ) ( else (let ((n (length u))) (let loop ( (c 0) (i 1) ) (if (>= i n) c (let ((f (coefficient-monomial-gpe (list-ref u i) x))) (cond ( (equal? f undefined) undefined ) ( (equal? (list-ref f 1) j) (loop (+ c (list-ref f 0)) (+ i 1)) ) ( else (loop c (+ i 1)) )))))) ))) )
false
5366d9e4e7d0ed74d9a3056d07e3a382f005788b
9c36ed1e52d7712599a8cb0e80fd5ac94d328bd3
/bench/physics/gated-magnetic-field.fpcore
a44b3d84959316024101f26ac2bcd0b708b85438
[ "MIT" ]
permissive
oflatt/herbie
e7db30968537f9b03430056408babbcca77f411f
cecba081914fb685fcd962a95c6d6fcaa7f063ad
refs/heads/master
2021-07-30T03:37:47.191038
2021-07-23T19:10:19
2021-07-23T19:10:19
211,983,144
0
0
NOASSERTION
2019-10-01T00:26:43
2019-10-01T00:26:43
null
UTF-8
Scheme
false
false
238
fpcore
gated-magnetic-field.fpcore
; -*- mode: scheme -*- (FPCore (NdChar Ec Vef EDonor mu KbT NaChar Ev EAccept) :name "Bulmash initializePoisson" (+ (/ NdChar (+ 1 (exp (/ (- (- Ec Vef EDonor mu)) KbT)))) (/ NaChar (+ 1 (exp (/ (+ Ev Vef EAccept (- mu)) KbT))))))
false
29f6ad9d8533fd18a874fc4edab8af971e7885b1
4190d7db137e0e2c792c29df012bb9aa36f6fcad
/gi/c/property.sls
80f72871551a81502fbe648760c5e14b7e5b5bcf
[ "Unlicense" ]
permissive
akce/chez-gi
e10e975ceecbb0f97652c70b5ac336ab2572bd2b
d7b78e2991a7120b92478e652d18be7a0a056223
refs/heads/master
2020-09-12T19:27:00.943653
2019-11-21T10:17:35
2019-11-21T10:17:35
222,526,577
2
0
null
null
null
null
UTF-8
Scheme
false
false
1,185
sls
property.sls
;; https://developer.gnome.org/gi/stable/gi-GIPropertyInfo.html ;; Written by Akce 2019. ;; SPDX-License-Identifier: Unlicense (library (gi c property) (export giproperty GParamFlags g-property-info-get-flags g-property-info-get-ownership-transfer g-property-info-get-type) (import (rnrs) (gi c arg) (gi c type) (gi c ftypes-util)) (define load-library (lso)) (define-ftype giproperty void*) ;; GParamFlags are a part of GObject GParamSpec but define here for convenience. ;; https://developer.gnome.org/gobject/stable/gobject-GParamSpec.html#GParamFlags (c-bitmap GParamFlags READABLE WRITABLE READWRITE CONSTRUCT CONSTRUCT_ONLY LAX_VALIDATION STATIC_NAME STATIC_NICK STATIC_BLURB EXPLICIT_NOTIFY DEPRECATED) (c-function (g_property_info_get_flags (giproperty) int) (g_property_info_get_ownership_transfer (giproperty) int) (g-property-info-get-type (giproperty) gitype)) (define g-property-info-get-flags (lambda (gia) (GParamFlags (g_property_info_get_flags gia)))) (define g-property-info-get-ownership-transfer (lambda (gia) (GITransfer (g_property_info_get_ownership_transfer gia)))))
false
513149e3794c24f9efe24d20392131384d2c2c95
b9eb119317d72a6742dce6db5be8c1f78c7275ad
/racket/svn-log.ss
c08b50cb5c613a44b85e06d56b68e2cda05ad2ee
[]
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
4,529
ss
svn-log.ss
#! /bin/sh #| Hey Emacs, this is -*-scheme-*- code! #$Id$ exec mred --no-init-file --mute-banner --version --require "$0" |# (module svn-log mzscheme (require (lib "class.ss") (lib "match.ss") (lib "mred.ss" "mred") (lib "pretty.ss") (only (lib "1.ss" "srfi") filter) (lib "xml.ss" "xml") "web/flickr/mcvicker/progress-bar.ss") (define *repo-URL* ;;"svn+ssh://offby1.ath.cx/home/erich/svn-repos" "http://svn.collab.net/repos/svn" ;;"file:///C:/Documents and Settings/Lenovo User/Desktop/silly-repository" ) (define *interesting-user-names* (list "joe")) (define *svn-exe* "c:/program files/subversion/bin/svn.exe") (define *first-revision* 0) (define *total-revisions* 100) (define (usual-exception-handler e) (message-box "Uh oh" (cond ((exn? e) (format "~a:~a" (exn-message e) (let ((op (open-output-string))) (pretty-display (continuation-mark-set->context (exn-continuation-marks e)) op) (get-output-string op)))) (else (format "Unknown exception ~s" e))))) (define *frame* (new frame% (label "Subversion Log Viewer"))) (define *returned-log-data* #f) (define *do-it!-button* (new button% (parent *frame*) (label "Snarf the log data") (callback (lambda (item event) (send *pb* start!))))) (define *pb* (new pb% (label "Progress!") (worker-proc (lambda (pb) (with-handlers ([void usual-exception-handler]) (define *xml-parse-errors* #f) (define-values (proc stdout-ip stdin-op stderr-ip) (subprocess #f #f #f *svn-exe* "log" "--xml" (format "-r~a:~a" (number->string *first-revision*) (number->string (sub1 (+ *first-revision* *total-revisions*)))) *repo-URL*)) (define snarf-stdout-thread (thread (lambda () (with-handlers ([exn:xml? (lambda (e) (set! *xml-parse-errors* (exn-message e)))]) (set! *returned-log-data* (parameterize ((collapse-whitespace #t)) ((eliminate-whitespace '(log logentry) (lambda (x) x)) (document-element (read-xml stdout-ip)))))) (close-input-port stdout-ip)))) (define snarf-stderr-thread (thread (lambda () (let loop ((error-lines '())) (let ((one-thing (read-line stderr-ip 'any))) (if (eof-object? one-thing) (set! *error-spew* (reverse error-lines)) (loop (cons one-thing error-lines))))) (close-input-port stderr-ip)))) (close-output-port stdin-op) (for-each sync (list snarf-stderr-thread snarf-stdout-thread)) (subprocess-wait proc) (if (not (zero? (subprocess-status proc))) (message-box "Fail!" (format "Subprocess returned a failure code; here's its error output: ~a" (apply string-append *error-spew*))) (if *xml-parse-errors* (message-box "Subprocess didn't emit clean XML" *xml-parse-errors*) (message-box "Yo" (format "~a" (filter-users *interesting-user-names* (xml->xexpr *returned-log-data*))))))) (send pb show #f))) (work-to-do *total-revisions*))) (define (filter-users user-names xml) (match xml [('log atts entries ...) (filter (lambda (one-entry) (match one-entry [('logentry (('revision r)) ('author author-atts auth) ('date date-atts date) ('msg msg-atts msg ...)) (member auth user-names)])) entries)])) (define *error-spew* '()) (send *frame* show #t) (provide (all-defined)) )
false
1f1170046b3aa0684bf39492b9f539ba86d06a53
7c7e1a9237182a1c45aa8729df1ec04abb9373f0
/sicp/2/1-4.scm
15f05fa386333bf63a8b841bee9eb8452a29016b
[ "MIT" ]
permissive
coolsun/heist
ef12a65beb553cfd61d93a6691386f6850c9d065
3f372b2463407505dad7359c1e84bf4f32de3142
refs/heads/master
2020-04-21T15:17:08.505754
2012-06-29T07:18:49
2012-06-29T07:18:49
null
0
0
null
null
null
null
UTF-8
Scheme
false
false
7,242
scm
1-4.scm
; Section 2.1.4 ; http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-14.html#%_sec_2.1.4 (load "../helpers") ; Functions for extended exercise (define (add-interval x y) (make-interval (+ (lower-bound x) (lower-bound y)) (+ (upper-bound x) (upper-bound y)))) (define (mul-interval x y) (let ((p1 (* (lower-bound x) (lower-bound y))) (p2 (* (lower-bound x) (upper-bound y))) (p3 (* (upper-bound x) (lower-bound y))) (p4 (* (upper-bound x) (upper-bound y)))) (make-interval (min p1 p2 p3 p4) (max p1 p2 p3 p4)))) (define (div-interval x y) (mul-interval x (make-interval (/ 1.0 (upper-bound y)) (/ 1.0 (lower-bound y))))) (exercise "2.7") ; Interval constructors ; upper-bound and lower-bound ought to return the greater and lesser bounds, ; respectively (define (make-interval a b) (cons a b)) (define (upper-bound int) (max (car int) (cdr int))) (define (lower-bound int) (min (car int) (cdr int))) (exercise "2.8") ; Interval subtraction (define (sub-interval x y) (make-interval (- (lower-bound x) (upper-bound y)) (- (upper-bound x) (lower-bound y)))) (exercise "2.9") ; Widths of intervals (define (width-interval int) (/ (- (upper-bound int) (lower-bound int)) 2)) ; Expand (w (+ x y)): ; w = width, i = make, l = lower, u = upper ; ; (w (i (+ (l x) (l y)) (+ (u x) (u y)))) ; (/ (- (+ (u x) (u y)) (+ (l x) (l y))) 2) ; ; Which is equal to ; (+ (/ (- (u x) (l x)) 2) (/ (- (u y) (l y)) 2)) ; = (+ (w x) (w y)) (exercise "2.10") ; Check for zero-spanning intervals (define (spans-zero? int) (and (negative? (lower-bound int)) (not (negative? (upper-bound int))))) (define (div-interval x y) (if (spans-zero? y) (error "Cannot divide by an interval that spans zero") (mul-interval x (make-interval (/ 1.0 (upper-bound y)) (/ 1.0 (lower-bound y)))))) (exercise "2.11") ; Handle mul-interval as nine special cases ; 0 ; 1. | lx-----ux ; | ly-----uy ; | ; 2. | lx-----ux ; ly--------|--------uy ; | ; 3. | lx-----ux ; ly-----uy | ; | ; 4. lx--------|--------ux ; | ly-----uy ; | ; 5. lx--------|--------ux ; ly--------|--------uy ; | ; 6. lx--------|--------ux ; ly-----uy | ; | ; 7. lx-----ux | ; | ly-----uy ; | ; 8. lx-----ux | ; ly--------|--------uy ; | ; 9. lx-----ux | ; ly-----uy | ; (define (mul-interval x y) (let ((lx (lower-bound x)) (ux (upper-bound x)) (ly (lower-bound y)) (uy (upper-bound y))) (cond ((and (not (negative? lx)) (not (negative? ly))) (make-interval (* lx ly) (* ux uy))) ((and (not (negative? lx)) (negative? ly) (not (negative? uy))) (make-interval (* ux ly) (* ux uy))) ((and (not (negative? lx)) (negative? uy)) (make-interval (* ux ly) (* lx uy))) ((and (negative? lx) (not (negative? ux)) (not (negative? ly))) (make-interval (* lx uy) (* ux uy))) ((and (negative? lx) (not (negative? ux)) (negative? ly) (not (negative? uy))) (let ((p1 (* ux ly)) (p2 (* lx uy)) (p3 (* lx ly)) (p4 (* ux uy))) (make-interval (min p1 p2) (max p3 p4)))) ((and (negative? lx) (not (negative? ux)) (negative? uy)) (make-interval (* ux ly) (* lx ly))) ((and (negative? ux) (not (negative? ly))) (make-interval (* lx uy) (* ux ly))) ((and (negative? ux) (negative? ly) (not (negative? uy))) (make-interval (* lx uy) (* lx ly))) ((and (negative? ux) (negative? uy)) (make-interval (* ux uy) (* lx ly)))))) (output '(mul-interval (cons 1 3) (cons 2 5))) (output '(mul-interval (cons 1 3) (cons -2 5))) (output '(mul-interval (cons 1 3) (cons -2 -5))) (output '(mul-interval (cons -1 3) (cons 2 5))) (output '(mul-interval (cons -1 3) (cons -2 5))) (output '(mul-interval (cons -1 3) (cons -2 -5))) (output '(mul-interval (cons -1 -3) (cons 2 5))) (output '(mul-interval (cons -1 -3) (cons -2 5))) (output '(mul-interval (cons -1 -3) (cons -2 -5))) (exercise "2.12") ; Allow intervals to be entered as "x +/- y%" ; These are from the text: (define (make-center-width c w) (make-interval (- c w) (+ c w))) (define (center i) (/ (+ (lower-bound i) (upper-bound i)) 2)) (define (width i) (/ (- (upper-bound i) (lower-bound i)) 2)) ; These are my own: (define (make-center-percent value tolerance) (let ((dx (abs (* (/ tolerance 100) value)))) (make-interval (- value dx) (+ value dx)))) (define (percent i) (let ((l (lower-bound i)) (u (upper-bound i))) (let ((center (/ (+ l u) 2)) (tolerance (/ (- u l) 2))) (* 100 (/ tolerance center))))) (output '(make-center-percent 10.0 10)) (output '(percent (make-interval 0.9 1.1))) (exercise "2.13") ; Formula for the tolerance of the product of two intervals, assuming positive ; values ; (percent (mul-interval (make-center-percent x a) ; (make-center-percent y b))) ; ; (percent (mul-interval (make-interval (- x (* (/ a 100) x)) (+ x (* (/ a 100) x))) ; (make-interval (- y (* (/ y 100) b)) (+ y (* (/ b 100) y))))) ; ; (percent (make-interval (* (- x (* (/ a 100) x)) (- y (* (/ b 100) y))) ; (* (+ x (* (/ a 100) x)) (+ y (* (/ b 100) y))))) ; ; (* 100 (/ (/ (- (* (+ x (* (/ a 100) x)) ; (+ y (* (/ b 100) y))) ; (* (- x (* (/ a 100) x)) ; (- y (* (/ b 100) y)))) ; 2) ; (/ (+ (* (- x (* (/ a 100) x)) ; (- y (* (/ b 100) y))) ; (* (+ x (* (/ a 100) x)) ; (+ y (* (/ b 100) y)))) ; 2))) ; ; (* 100 (/ (- (* (+ x (* (/ a 100) x)) ; (+ y (* (/ b 100) y))) ; (* (- x (* (/ a 100) x)) ; (- y (* (/ b 100) y)))) ; (+ (* (- x (* (/ a 100) x)) ; (- y (* (/ b 100) y))) ; (* (+ x (* (/ a 100) x)) ; (+ y (* (/ b 100) y)))))) ; ; (x + ax/100)(y + by/100) - (x - ax/100)(y - by/100) ; = 100 * --------------------------------------------------- ; (x - ax/100)(y - by/100) + (x + ax/100)(y + by/100) ; ; (xy + bxy/100 + axy/100 + abxy/10000) - (xy - bxy/100 - axy/100 + abxy/10000) ; = 100 * ----------------------------------------------------------------------------- ; (xy - bxy/100 - axy/100 + abxy/10000) + (xy + bxy/100 + axy/100 + abxy/10000) ; ; b/50 + a/50 ; = 100 * ----------- ; 2 + ab/5000 ; ; If a,b are small, ab/5000 << 2 -> ignore ab/5000 ; ; -> (percent (mul-interval (make-center-percent x a) ; (make-center-percent y b))) ; =~ a + b (output '(percent (mul-interval (make-center-percent 56.0 0.5) (make-center-percent 34.7 1.2)))) ; => 1.6999 =~ 1.7
false
9e1e045d29365c9dd6f1a45e482a7dc54f9b45fc
99f659e747ddfa73d3d207efa88f1226492427ef
/datasets/srfi/srfi-144/srfi/144.body.scm
32805d898ea263660a5f09df61a1a3c5769c42b9
[ "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
19,031
scm
144.body.scm
;;; Copyright (C) William D Clinger (2016). ;;; ;;; Permission is hereby granted, free of charge, to any person ;;; obtaining a copy of this software and associated documentation ;;; files (the "Software"), to deal in the Software without ;;; restriction, including without limitation the rights to use, ;;; copy, modify, merge, publish, distribute, sublicense, and/or ;;; sell copies of the Software, and to permit persons to whom the ;;; Software is furnished to do so, subject to the following ;;; conditions: ;;; ;;; The above copyright notice and this permission notice shall be ;;; included in all copies or substantial portions of the Software. ;;; ;;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ;;; EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES ;;; OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ;;; NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT ;;; HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, ;;; WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING ;;; FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR ;;; OTHER DEALINGS IN THE SOFTWARE. ;;; References ;;; ;;; Milton Abramowitz and Irene A Stegun [editors]. ;;; Handbook of Mathematical Functions With Formulas, Graphs, and ;;; Mathematical Tables. United States Department of Commerce. ;;; National Bureau of Standards Applied Mathematics Series, 55, ;;; June 1964. Fifth Printing, August 1966, with corrections. ;;; ;;; R W Hamming. Numerical Methods for Scientists and Engineers. ;;; McGraw-Hill, 1962. ;;; ;;; Donald E Knuth. The Art of Computer Programming, Volume 2, ;;; Seminumerical Algorithms, Second Edition. Addison-Wesley, 1981. ;;; ;;; J N Newman. Approximations for the Bessel and Struve Functions. ;;; Mathematics of Computation, 43(168), October 1984, pages 551-556. ;;; I have deliberately avoided recent references, and have also ;;; avoided looking at any code or pseudocode for these or similar ;;; functions. ;;; Quick-and-dirty implementation of a draft of SRFI 144 (flonums), ;;; as specified at http://vrici.lojban.org/~cowan/temp/srfi-144.html ;;; as of 4 June 2017. ;;; ;;; FIXME: not as accurate as it should be ;;; FIXME: not as fast as it should be ;;; FIXME: assumes IEEE arithmetic or similar ;;; FIXME: assumes all inexact reals are flonums ;;; FIXME: assumes (scheme inexact) ;;; Mathematical Constants ;;; ;;; The mathematical constants are now defined in 144.constants.scm ;; Implementation Constants (define fl-greatest (let loop ((x (- (expt 2.0 precision-bits) 1.0))) (if (finite? (* 2.0 x)) (loop (* 2.0 x)) x))) (define fl-least (let loop ((x 1.0)) (if (> (/ x 2.0) 0.0) (loop (/ x 2.0)) x))) (define fl-epsilon (let loop ((eps 1.0)) (if (= 1.0 (+ 1.0 eps)) (* 2.0 eps) (loop (/ eps 2.0))))) (define fl-integer-exponent-zero ; arbitrary (exact (- (log fl-least 2.0) 1.0))) (define fl-integer-exponent-nan ; arbitrary (- fl-integer-exponent-zero 1)) ;;; Constructors (define (flonum x) (if (real? x) (inexact x) (error "bad argument passed to flonum" x))) (define fladjacent (flop2 'fladjacent (lambda (x y) (define (loop y) (let* ((y3 (fl+ (fl* 0.999755859375 x) (fl* 0.000244140625 y)))) (cond ((fl<? x y3 y) (loop y3)) ((fl<? y y3 x) (loop y3)) (else (loop2 y))))) (define (loop2 y) (let* ((y2 (fl/ (fl+ x y) 2.0)) (y2 (if (flinfinite? y2) (fl+ (fl* 0.5 x) (fl* 0.5 y)) y2))) (cond ((fl=? x y2) y) ((fl=? y y2) y) (else (loop2 y2))))) (cond ((flinfinite? x) (cond ((fl<? x y) (fl- fl-greatest)) ((fl>? x y) fl-greatest) (else x))) ((fl=? x y) x) ((flzero? x) (if (flpositive? y) fl-least (fl- fl-least))) ((fl<? x y) (loop (flmin y fl-greatest (flmax (* 2.0 x) (* 0.5 x))))) ((fl>? x y) (loop (flmax y (fl- fl-greatest) (flmin (* 2.0 x) (* 0.5 x))))) (else ; x or y is a NaN x))))) (define flcopysign (flop2 'flcopysign (lambda (x y) (if (= (flsign-bit x) (flsign-bit y)) x (fl- x))))) (define (make-flonum x n) (let ((y (expt 2.0 n))) (cond ((or (not (flonum? x)) (not (exact-integer? n))) (error "bad arguments to make-flonum" x n)) ((finite? y) (* x y)) (else (inexact (* (exact x) (expt 2 n))))))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; Accessors (define (flinteger-fraction x) (check-flonum! 'flinteger-fraction x) (let* ((result1 (fltruncate x)) (result2 (fl- x result1))) (values result1 result2))) (define (flexponent x) (floor (fllog2 (flabs x)))) (define (flinteger-exponent x) (exact (flexponent x))) (define (flnormalized-fraction-exponent x) (define (return result1 result2) (cond ((fl<? result1 0.5) (values (fl* 2.0 result1) (- result2 1))) ((fl>=? result1 1.0) (values (fl* 0.5 result1) (+ result2 1))) (else (values result1 result2)))) (check-flonum! 'flnormalized-fraction-exponent x) (cond ((flnan? x) ; unspecified for NaN (values x 0)) ((fl<? x 0.0) (call-with-values (lambda () (flnormalized-fraction-exponent (fl- x))) (lambda (y n) (values (fl- y) n)))) ((fl=? x 0.0) ; unspecified for 0.0 (values 0.0 0)) ((flinfinite? x) (values 0.5 (+ 3 (exact (round (fllog2 fl-greatest)))))) ((flnormalized? x) (let* ((result2 (exact (flround (fllog2 x)))) (result2 (if (integer? result2) result2 (round result2))) (two^result2 (inexact (expt 2.0 result2)))) (if (flinfinite? two^result2) (call-with-values (lambda () (flnormalized-fraction-exponent (fl/ x 4.0))) (lambda (y n) (values y (+ n 2)))) (return (fl/ x two^result2) result2)))) (else (let* ((k (+ 2 precision-bits)) (two^k (expt 2 k))) (call-with-values (lambda () (flnormalized-fraction-exponent (fl* x (inexact two^k)))) (lambda (y n) (return y (- n k)))))))) (define (flsign-bit x) (check-flonum! 'flsign-bit x) (cond ((fl<? x 0.0) 1) ((eqv? x -0.0) 1) (else 0))) ;;; Predicates ;(define flonum? R6RS) ; defined by (rnrs arithmetic flonums) ;(define fl=? R6RS) ; defined by (rnrs arithmetic flonums) ;(define fl<? R6RS) ; defined by (rnrs arithmetic flonums) ;(define fl>? R6RS) ; defined by (rnrs arithmetic flonums) ;(define fl<=? R6RS) ; defined by (rnrs arithmetic flonums) ;(define fl>=? R6RS) ; defined by (rnrs arithmetic flonums) (define (flunordered? x y) (or (flnan? x) (flnan? y))) ;;; incompatible with (rnrs arithmetic flonums) in zero-argument case (define flmax (let ((flmax2 (flop2 'flmax max))) (lambda args (cond ((null? args) -inf.0) ((null? (cdr args)) (car args)) ((null? (cddr args)) (flmax2 (car args) (cadr args))) (else (flmax2 (flmax2 (car args) (cadr args)) (apply flmax (cddr args)))))))) ;;; incompatible with (rnrs arithmetic flonums) in zero-argument case (define flmin (let ((flmin2 (flop2 'flmin min))) (lambda args (cond ((null? args) +inf.0) ; spec says fl-least, but that's wrong ((null? (cdr args)) (car args)) ((null? (cddr args)) (flmin2 (car args) (cadr args))) (else (flmin2 (flmin2 (car args) (cadr args)) (apply flmin (cddr args)))))))) ;(define flinteger? R6RS) ; defined by (rnrs arithmetic flonums) ;(define flzero? R6RS) ; defined by (rnrs arithmetic flonums) ;(define flpositive? R6RS) ; defined by (rnrs arithmetic flonums) ;(define flnegative? R6RS) ; defined by (rnrs arithmetic flonums) ;(define flodd? R6RS) ; defined by (rnrs arithmetic flonums) ;(define fleven? R6RS) ; defined by (rnrs arithmetic flonums) ;(define flfinite? R6RS) ; defined by (rnrs arithmetic flonums) ;(define flinfinite? R6RS) ; defined by (rnrs arithmetic flonums) ;(define flnan? R6RS) ; defined by (rnrs arithmetic flonums) (define flnormalized? (lambda (x) (check-flonum! 'flnormalized? x) (let ((x (flabs x))) (and (flfinite? x) (fl<? (fl/ fl-greatest) x))))) (define fldenormalized? (lambda (x) (check-flonum! 'fldenormalized? x) (let ((x (flabs x))) (and (flfinite? x) (fl<? 0.0 x) (fl<=? x (fl/ fl-greatest)))))) ;;; Arithmetic ;(define fl+ R6RS) ; defined by (rnrs arithmetic flonums) ;(define fl* R6RS) ; defined by (rnrs arithmetic flonums) ;;; Spec says "as if to infinite precision and rounded only once". (define fl+* (flop3 'fl+* (lambda (x y z) (cond (c-functions-are-available (fma x y z)) ((and (flfinite? x) (flfinite? y)) (if (flfinite? z) (let ((x (exact x)) (y (exact y)) (z (exact z))) (flonum (+ (* x y) z))) z)) (else (fl+ (fl* x y) z)))))) ;(define fl- R6RS) ; defined by (rnrs arithmetic flonums) ;(define fl/ R6RS) ; defined by (rnrs arithmetic flonums) ;(define flabs R6RS) ; defined by (rnrs arithmetic flonums) (define (flabsdiff x y) (flabs (fl- x y))) (define (flposdiff x y) (let ((diff (fl- x y))) (if (flnegative? diff) 0.0 diff))) (define (flsgn x) (flcopysign 1.0 x)) ;;; (flnumerator +nan.0) and (fldenominator +nan.0) must be NaNs, which ;;; is not required by the R6RS specification of (rnrs arithmetic flonums). (define flnumerator (flop1 'flnumerator (lambda (x) (if (flnan? x) x (r6rs:flnumerator x))))) (define fldenominator (flop1 'fldenominator (lambda (x) (if (flnan? x) x (r6rs:fldenominator x))))) ;(define flfloor R6RS) ; defined by (rnrs arithmetic flonums) ;(define flceiling R6RS) ; defined by (rnrs arithmetic flonums) ;(define flround R6RS) ; defined by (rnrs arithmetic flonums) ;(define fltruncate R6RS) ; defined by (rnrs arithmetic flonums) ;;; Exponents and logarithms ;(define flexp R6RS) ; defined by (rnrs arithmetic flonums) (define flexp2 (flop1 'flexp2 (lambda (x) (flexpt 2.0 x)))) ;;; e^x = \sum_n (z^n / (n!)) ;;; ;;; FIXME: the number of terms and the constant 0.5 seem reasonable ;;; for IEEE double precision, but the number of terms might need ;;; to be increased for higher precisions. (define flexp-1 (flop1 'flexp-1 (let ((coefs (cons 0.0 (map fl/ (map factorial '(1.0 2.0 3.0 4.0 5.0 6.0 7.0 8.0 9.0 10.0 11.0 12.0 13.0 14.0 15.0)))))) (lambda (x) (cond ((fl<? (flabs x) 0.5) ; FIXME (polynomial-at x coefs)) (else (fl- (flexp x) 1.0))))))) (define flsquare (flop1 'flsquare (lambda (x) (fl* x x)))) ;(define flsqrt R6RS) ; defined by (rnrs arithmetic flonums) (define flcbrt (flop1 'flcbrt (lambda (x) (cond ((flnegative? x) (fl- (flcbrt (fl- x)))) (else (flexpt x (fl/ 3.0))))))) (define flhypot (flop2 'flhypot (lambda (x y) (cond ((flzero? x) (flabs y)) ((flzero? y) (flabs x)) ((or (flinfinite? x) (flinfinite? y)) +inf.0) ((flnan? x) x) ((flnan? y) y) ((fl>? y x) (flhypot y x)) (else (let* ((y/x (fl/ y x)) (root (flsqrt (fl+ 1.0 (fl* y/x y/x))))) (fl* (flabs x) root))))))) ;(define flexpt R6RS) ; defined by (rnrs arithmetic flonums) ;(define fllog R6RS) ; defined by (rnrs arithmetic flonums) ;;; Returns log(x+1), as in C99 log1p. ;;; ;;; log (x + 1) = \sum_{n=1}^\infty - (-1)^n x^n/n (define fllog1+ (flop1 'fllog1+ (let ((coefs (cons 0.0 (map fl/ '(1.0 -2.0 3.0 -4.0 5.0 -6.0 7.0 -8.0 9.0 -10.0))))) (lambda (x) (cond ((fl<? (flabs x) 0.5) ; FIXME (polynomial-at x coefs)) (else (fllog (fl+ 1.0 x)))))))) (define fllog2 (flop1 'fllog2 (lambda (x) (log x 2.0)))) (define fllog10 (flop1 'fllog10 (lambda (x) (log x 10.0)))) (define (make-fllog-base base) (check-flonum! 'make-fllog-base base) (if (fl>? base 1.0) (flop1 'procedure-created-by-make-fllog-base (lambda (x) (log x base))) (error "argument to make-fllog-base must be greater than 1.0" base))) ;;; Trigonometric functions ;(define flsin R6RS) ; defined by (rnrs arithmetic flonums) ;(define flcos R6RS) ; defined by (rnrs arithmetic flonums) ;(define fltan R6RS) ; defined by (rnrs arithmetic flonums) ;(define flasin R6RS) ; defined by (rnrs arithmetic flonums) ;(define flacos R6RS) ; defined by (rnrs arithmetic flonums) ;(define flatan R6RS) ; defined by (rnrs arithmetic flonums) (define flsinh (flop1 'flsinh (lambda (x) (cond ((not (flfinite? x)) x) ((fl<? (flabs x) 0.75) (fl/ (fl- (flexp-1 x) (flexp-1 (fl- x))) 2.0)) (else (fl/ (fl- (flexp x) (flexp (fl- x))) 2.0)))))) (define flcosh (flop1 'flcosh (lambda (x) (cond ((not (flfinite? x)) (flabs x)) ((fl<? (flabs x) 0.75) (fl+ 1.0 (fl/ (fl+ (flexp-1 x) (flexp-1 (fl- x))) 2.0))) (else (fl/ (fl+ (flexp x) (flexp (fl- x))) 2.0)))))) (define fltanh (flop1 'fltanh (lambda (x) (cond ((flinfinite? x) (flcopysign 1.0 x)) ((flnan? x) x) (else (let ((a (flsinh x)) (b (flcosh x))) (cond ((fl=? a b) 1.0) ((fl=? a (fl- b)) -1.0) (else (fl/ (flsinh x) (flcosh x)))))))))) ;;; inverse hyperbolic functions (define flasinh (flop1 'flasinh (lambda (x) (define (eqn4.6.31 x^2 c k k0) (if (> k 45) ; FIXME c (fl+ c (fl* x^2 (eqn4.6.31 x^2 (fl- (fl/ (fl* c k0 k0) (fl* (fl+ k0 1.0) (fl+ k0 2.0)))) (+ k 2) (fl+ k0 2.0)))))) (cond ((flzero? x) x) ((not (flfinite? x)) x) ((fl<? x 0.0) (fl- (flasinh (fl- x)))) ((fl<? x 0.5) (fl* x (eqn4.6.31 (fl* x x) 1.0 1 1.0))) (else (let* ((x^2+1 (fl+ (fl* x x) 1.0)) (root (if (flfinite? x^2+1) (flsqrt x^2+1) x)) (a (fl+ x root))) (if (flfinite? a) (fllog a) (fl+ fl-log-2 (fllog x))))))))) (define flacosh (flop1 'flacosh (lambda (x) (if (fl<=? x 0.5) +nan.0 (let* ((x^2-1 (fl- (fl* x x) 1.0)) (root (if (flfinite? x^2-1) (flsqrt x^2-1) x)) (a (fl+ x root))) (if (flfinite? a) (fllog a) (fl+ fl-log-2 (fllog x)))))))) (define flatanh (flop1 'flatanh (lambda (x) (define (eqn4.6.33 x^2 k k0) (if (> k 50) ; FIXME (fl/ k0) (fl+ (fl/ k0) (fl* x^2 (eqn4.6.33 x^2 (+ k 2) (+ k0 2.0)))))) (cond ((flzero? x) x) ((not (flfinite? x)) x) ((fl<? x 0.0) (fl- (flatanh (fl- x)))) ((fl<? x 0.5) (fl* x (eqn4.6.33 (fl* x x) 1 1.0))) (else (fl* 0.5 (fllog (fl/ (fl+ 1.0 x) (fl- 1.0 x))))))))) ;;; Integer division (define flquotient (flop2 'flquotient (lambda (x y) (fltruncate (fl/ x y))))) ;;; FIXME: should probably implement the following part of the C spec: ;;; "If the returned value is 0, it will have the same sign as x." (define flremainder (flop2 'flremainder (lambda (x y) (fl- x (fl* y (flquotient x y)))))) (define (flremquo x y) (check-flonum! 'flremquo x) (check-flonum! 'flremquo y) (let* ((quo (flround (fl/ x y))) (rem (fl- x (fl* y quo)))) (values rem (exact quo)))) ;; Special functions are defined in 144.special.scm ; eof
false
48063a5aee8e64490dfaa035df3565b82c6b2fb1
c94361855ba29e0190df993d10856a0a2d53e687
/platform/javascript/files/library/build-in-macros.ss
69d1f22dfdba07e3531642b4ed637715102ed347
[ "MIT" ]
permissive
kghost/Yume
f886431eaa7600192fcd8b0ad04896caf4f96b31
6ec307279fe0036437a9047d49032f4ee6eb286b
refs/heads/master
2023-08-16T11:49:40.270078
2019-04-18T14:02:33
2019-04-18T14:02:33
3,162,103
4
0
null
null
null
null
UTF-8
Scheme
false
false
38
ss
build-in-macros.ss
../../../../library/build-in-macros.ss
false
1ab511dc800d60792e6f319e2ce6637ccd2441df
df0ba5a0dea3929f29358805fe8dcf4f97d89969
/exercises/software-engineering/exams/1/b/3.scm
f55e569bd124753bdfcd95e7c22b021f69dd367a
[ "MIT" ]
permissive
triffon/fp-2019-20
1c397e4f0bf521bf5397f465bd1cc532011e8cf1
a74dcde683538be031186cf18367993e70dc1a1c
refs/heads/master
2021-12-15T00:32:28.583751
2021-12-03T13:57:04
2021-12-03T13:57:04
210,043,805
14
31
MIT
2019-12-23T23:39:09
2019-09-21T19:41:41
Racket
UTF-8
Scheme
false
false
827
scm
3.scm
(define (deep-delete l) (define (helper level l) (cond ((null? l) '()) ((list? (car l)) (cons (helper (+ level 1) (car l)) (helper level (cdr l)))) ((< (car l) level) (helper level (cdr l))) (else (cons (car l) (helper level (cdr l)))))) (helper 1 l)) (load "../../../testing/check.scm") (check (deep-delete '()) => '()) (check (deep-delete '(0)) => '()) (check (deep-delete '(1)) => '(1)) (check (deep-delete '(1 2 3)) => '(1 2 3)) (check (deep-delete '(1 (2 1 0) 3)) => '(1 (2) 3)) (check (deep-delete '(1 () ((2 2 ())) 3)) => '(1 () ((())) 3)) (check (deep-delete '(1 (2 3) 4 ((5 ((6)))))) => '(1 (2 3) 4 ((5 ((6)))))) (check (deep-delete '(1 (2 (2 4) 1) 0 (3 (1)))) => '(1 (2 (4)) (3 ()))) (check-report) (check-reset!)
false
c5c8620f4623de8822e243c3d8c9efba6d13bb0b
4b570eebce894b4373cba292f09883932834e543
/ch1/1.28.scm
984a1260c0daaf44fd76de92de1673eabd1faaa0
[]
no_license
Pulkit12083/sicp
ffabc406c66019e5305ad701fbc022509319e4b1
8ea6c57d2b0be947026dd01513ded25991e5c94f
refs/heads/master
2021-06-17T13:44:06.381879
2021-05-14T16:52:30
2021-05-14T16:52:30
197,695,022
0
0
null
2021-04-14T17:04:01
2019-07-19T03:25:41
Scheme
UTF-8
Scheme
false
false
895
scm
1.28.scm
;; Ex 1.28 ;;miller rabin test for primality ;; modify expmod to signal when it has found a non trivial square congruent to modulo 1 (define (next ctr) (if (= ctr 2) 3 (+ ctr 2))) (define (expmod base exp m) (cond ((= exp 0) 1) ((and (not (= base (- m 1))) (= (remainder (square base) m) 1)) 0) ((even? exp) (remainder (square (expmod base (/ exp 2) m)) m)) (else (remainder (* base (expmod base (- exp 1) m)) m)))) (define (fermatsTest p val) (= (expmod val (- p 1) p) 1)) (define (isPrimeGuess p counter) (cond ((= counter p) true) ((fermatsTest p counter) (isPrimeGuess p (next counter))) (else false))) (define (millerRabinTest p) (isPrimeGuess p 2)) (millerRabinTest 561) ;;#f (millerRabinTest 1105) ;;#f (millerRabinTest 1729) ;;#f (millerRabinTest 2465) ;;#f (millerRabinTest 2821) ;;#f (millerRabinTest 6601) ;;#f (millerRabinTest 7) ;;#t ;;cannot be fooled
false
cd491eff678231c2da5dde6df99576f1f40f5078
defeada37d39bca09ef76f66f38683754c0a6aa0
/System/system/net/ftp-web-response.sls
b5454a39d3c6f1b3e805b9f4c7f7ef44f4404ff8
[]
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,956
sls
ftp-web-response.sls
(library (system net ftp-web-response) (export is? ftp-web-response? get-response-stream close content-length headers response-uri last-modified banner-message welcome-message exit-message status-code status-description) (import (ironscheme-clr-port)) (define (is? a) (clr-is System.Net.FtpWebResponse a)) (define (ftp-web-response? a) (clr-is System.Net.FtpWebResponse a)) (define-method-port get-response-stream System.Net.FtpWebResponse GetResponseStream (System.IO.Stream)) (define-method-port close System.Net.FtpWebResponse Close (System.Void)) (define-field-port content-length #f #f (property:) System.Net.FtpWebResponse ContentLength System.Int64) (define-field-port headers #f #f (property:) System.Net.FtpWebResponse Headers System.Net.WebHeaderCollection) (define-field-port response-uri #f #f (property:) System.Net.FtpWebResponse ResponseUri System.Uri) (define-field-port last-modified #f #f (property:) System.Net.FtpWebResponse LastModified System.DateTime) (define-field-port banner-message #f #f (property:) System.Net.FtpWebResponse BannerMessage System.String) (define-field-port welcome-message #f #f (property:) System.Net.FtpWebResponse WelcomeMessage System.String) (define-field-port exit-message #f #f (property:) System.Net.FtpWebResponse ExitMessage System.String) (define-field-port status-code #f #f (property:) System.Net.FtpWebResponse StatusCode System.Net.FtpStatusCode) (define-field-port status-description #f #f (property:) System.Net.FtpWebResponse StatusDescription System.String))
false
7e783ad15c362020a8aecbc2a2f68c77ac14a8f7
defeada37d39bca09ef76f66f38683754c0a6aa0
/System/system/component-model/attribute-provider-attribute.sls
8e105cdaf7cef5f214e77e562eaebcb5c66b1f2f
[]
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
869
sls
attribute-provider-attribute.sls
(library (system component-model attribute-provider-attribute) (export new is? attribute-provider-attribute? property-name type-name) (import (ironscheme-clr-port)) (define-syntax new (lambda (e) (syntax-case e () ((_ a ...) #'(clr-new System.ComponentModel.AttributeProviderAttribute a ...))))) (define (is? a) (clr-is System.ComponentModel.AttributeProviderAttribute a)) (define (attribute-provider-attribute? a) (clr-is System.ComponentModel.AttributeProviderAttribute a)) (define-field-port property-name #f #f (property:) System.ComponentModel.AttributeProviderAttribute PropertyName System.String) (define-field-port type-name #f #f (property:) System.ComponentModel.AttributeProviderAttribute TypeName System.String))
true
789a627acdd03b0dd82d3438b94c7d663587e52e
a8216d80b80e4cb429086f0f9ac62f91e09498d3
/lib/chibi/uri-test.sld
ca5535d9a102c29fe126116a948175cd7f558521
[ "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
3,066
sld
uri-test.sld
(define-library (chibi uri-test) (export run-tests) (import (scheme base) (chibi test) (chibi uri)) (begin (define (run-tests) (test-begin "uri") (test-assert (uri? (make-uri 'http))) (test 'http (uri-scheme (make-uri 'http))) (test "r" (uri-user (make-uri 'http "r"))) (test "google.com" (uri-host (make-uri 'http "r" "google.com"))) (test 80 (uri-port (make-uri 'http "r" "google.com" 80))) (test "/search" (uri-path (make-uri 'http "r" "google.com" 80 "/search"))) (test "q=cats" (uri-query (make-uri 'http "r" "google.com" 80 "/search" "q=cats"))) (test "recent" (uri-fragment (make-uri 'http "r" "google.com" 80 "/search" "q=cats" "recent"))) (let ((str "http://google.com")) (test-assert (uri? (string->uri str))) (test 'http (uri-scheme (string->uri str))) (test "google.com" (uri-host (string->uri str))) (test #f (uri-port (string->uri str))) (test #f (uri-path (string->uri str))) (test #f (uri-query (string->uri str))) (test #f (uri-fragment (string->uri str)))) (let ((str "http://google.com/")) (test-assert (uri? (string->uri str))) (test 'http (uri-scheme (string->uri str))) (test "google.com" (uri-host (string->uri str))) (test #f (uri-port (string->uri str))) (test "/" (uri-path (string->uri str))) (test #f (uri-query (string->uri str))) (test #f (uri-fragment (string->uri str)))) (let ((str "http://google.com:80/search?q=cats#recent")) (test-assert (uri? (string->uri str))) (test 'http (uri-scheme (string->uri str))) (test "google.com" (uri-host (string->uri str))) (test 80 (uri-port (string->uri str))) (test "/search" (uri-path (string->uri str))) (test "q=cats" (uri-query (string->uri str))) (test "recent" (uri-fragment (string->uri str)))) (test "/%73" (uri-path (string->uri "http://google.com/%73"))) (test "/s" (uri-path (string->uri "http://google.com/%73" #t))) (test "a=1&b=2;c=3" (uri-query (string->uri "http://google.com/%73?a=1&b=2;c=3" #t))) (test '(("a" . "1") ("b" . "2") ("c" . "3")) (uri-query (string->uri "http://google.com/%73?a=1&b=2;c=3" #t #t))) (test '(("a" . "1") ("b" . "2+2") ("c" . "3")) (uri-query (string->uri "http://google.com/%73?a=1&b=2+2;c=%33" #f #t))) (test '(("a" . "1") ("b" . "2 2") ("c" . "3")) (uri-query (string->uri "http://google.com/%73?a=1&b=2+2;c=%33" #t #t))) (let ((str "/")) (test-assert (uri? (string->path-uri 'http str))) (test 'http (uri-scheme (string->path-uri 'http str))) (test #f (uri-host (string->path-uri 'http str))) (test #f (uri-port (string->path-uri 'http str))) (test "/" (uri-path (string->path-uri 'http str))) (test #f (uri-query (string->path-uri 'http str))) (test #f (uri-fragment (string->path-uri 'http str)))) (test-end))))
false
78d41ba17df3d770f4120483265c623d22a69186
defeada37d39bca09ef76f66f38683754c0a6aa0
/System.Xml/system/xml/schema/xml-schema-set.sls
4d1e371b99fad5cb82160b101c32f16ecec52e51
[]
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,457
sls
xml-schema-set.sls
(library (system xml schema xml-schema-set) (export new is? xml-schema-set? reprocess schemas add contains? remove compile copy-to remove-recursive? count global-attributes global-elements global-types is-compiled? name-table compilation-settings-get compilation-settings-set! compilation-settings-update! xml-resolver) (import (ironscheme-clr-port)) (define-syntax new (lambda (e) (syntax-case e () ((_ a ...) #'(clr-new System.Xml.Schema.XmlSchemaSet a ...))))) (define (is? a) (clr-is System.Xml.Schema.XmlSchemaSet a)) (define (xml-schema-set? a) (clr-is System.Xml.Schema.XmlSchemaSet a)) (define-method-port reprocess System.Xml.Schema.XmlSchemaSet Reprocess (System.Xml.Schema.XmlSchema System.Xml.Schema.XmlSchema)) (define-method-port schemas System.Xml.Schema.XmlSchemaSet Schemas (System.Collections.ICollection System.String) (System.Collections.ICollection)) (define-method-port add System.Xml.Schema.XmlSchemaSet Add (System.Xml.Schema.XmlSchema System.Xml.Schema.XmlSchema) (System.Void System.Xml.Schema.XmlSchemaSet) (System.Xml.Schema.XmlSchema System.String System.Xml.XmlReader) (System.Xml.Schema.XmlSchema System.String System.String)) (define-method-port contains? System.Xml.Schema.XmlSchemaSet Contains (System.Boolean System.Xml.Schema.XmlSchema) (System.Boolean System.String)) (define-method-port remove System.Xml.Schema.XmlSchemaSet Remove (System.Xml.Schema.XmlSchema System.Xml.Schema.XmlSchema)) (define-method-port compile System.Xml.Schema.XmlSchemaSet Compile (System.Void)) (define-method-port copy-to System.Xml.Schema.XmlSchemaSet CopyTo (System.Void System.Xml.Schema.XmlSchema[] System.Int32)) (define-method-port remove-recursive? System.Xml.Schema.XmlSchemaSet RemoveRecursive (System.Boolean System.Xml.Schema.XmlSchema)) (define-field-port count #f #f (property:) System.Xml.Schema.XmlSchemaSet Count System.Int32) (define-field-port global-attributes #f #f (property:) System.Xml.Schema.XmlSchemaSet GlobalAttributes System.Xml.Schema.XmlSchemaObjectTable) (define-field-port global-elements #f #f (property:) System.Xml.Schema.XmlSchemaSet GlobalElements System.Xml.Schema.XmlSchemaObjectTable) (define-field-port global-types #f #f (property:) System.Xml.Schema.XmlSchemaSet GlobalTypes System.Xml.Schema.XmlSchemaObjectTable) (define-field-port is-compiled? #f #f (property:) System.Xml.Schema.XmlSchemaSet IsCompiled System.Boolean) (define-field-port name-table #f #f (property:) System.Xml.Schema.XmlSchemaSet NameTable System.Xml.XmlNameTable) (define-field-port compilation-settings-get compilation-settings-set! compilation-settings-update! (property:) System.Xml.Schema.XmlSchemaSet CompilationSettings System.Xml.Schema.XmlSchemaCompilationSettings) (define-field-port #f xml-resolver #f (property:) System.Xml.Schema.XmlSchemaSet XmlResolver System.Xml.XmlResolver))
true
733cd684cdd439e181aa96e485506afd72530455
defeada37d39bca09ef76f66f38683754c0a6aa0
/mscorlib/system/reflection/missing.sls
cf2d4ceab37bf7261c1cd826fadfacba164466e7
[]
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
348
sls
missing.sls
(library (system reflection missing) (export is? missing? value) (import (ironscheme-clr-port)) (define (is? a) (clr-is System.Reflection.Missing a)) (define (missing? a) (clr-is System.Reflection.Missing a)) (define-field-port value #f #f (static:) System.Reflection.Missing Value System.Reflection.Missing))
false
4ac915eadc094bdb86d50f563978197358678c7c
97c107938d7a7b80d319442337316604200fc0ae
/text-world/world-unit.ss
69e89a69c17069ec7d1a974dc0ca6e9ca69ac5f0
[]
no_license
jeapostrophe/rl
ddb131563cb37da80905c5de2debd01ec6c371d6
865f2a68e075bb5cc91754839181a35b03e08cb9
refs/heads/master
2021-01-19T03:10:04.613667
2013-10-31T01:24:57
2013-10-31T01:24:57
null
0
0
null
null
null
null
UTF-8
Scheme
false
false
1,962
ss
world-unit.ss
#lang scheme (require (prefix-in uni: 2htdp/universe) (prefix-in img: lang/private/imageeq) "text-world-sig.ss") (define (make-world-text-world@ text-size) (unit (import) (export text-world^) (define char-img (uni:text "@" text-size "black")) (define cell-width (uni:image-width char-img)) (define cell-height (uni:image-height char-img)) (define scene? (box/c uni:scene?)) (define (empty-scene width height) (uni:place-image (uni:nw:rectangle (* width cell-width) (* height cell-height) 'solid "black") 0 0 (uni:empty-scene (* width cell-width) (* height cell-height)))) (define image? img:image?) (define (place-image! img x y s) (set-box! s (uni:place-image img (* cell-width x) (* cell-height y) (unbox s)))) (define (make-image char fcolor bcolor) (uni:overlay (uni:nw:rectangle (* 1 cell-width) (* 1 cell-height) 'solid bcolor) (uni:text (string char) text-size fcolor))) (define (big-bang init #:height height #:width width #:on-tick the-on-tick #:tick-rate tick-rate #:on-key the-on-key #:on-draw the-on-draw #:stop-when the-stop-when) (uni:big-bang init (uni:on-tick the-on-tick tick-rate) (uni:on-key the-on-key) (uni:on-draw (lambda (w) (define sc (box (empty-scene width height))) (the-on-draw w sc) (unbox sc))) (uni:stop-when the-stop-when))))) (provide/contract [make-world-text-world@ (exact-positive-integer? . -> . (unit/c (import) (export text-world^)))])
false
559b0199890e375e7067a065e436c85ad8f63ec8
7b0df9640ae1b8e1172f0f90c5428b0802df8ed6
/tunein/tests/raw-urls.scm
03c5c57856739ec5f4a389ed07c425797e21231e
[]
no_license
erosness/sm-server
5954edfc441e773c605d2ac66df60bb983be01a3
cc302551e19f6d2b889a41ec28801004b0b28446
refs/heads/master
2020-08-31T13:23:03.670076
2016-02-18T19:10:55
2016-02-18T19:10:55
218,699,588
0
0
null
null
null
null
UTF-8
Scheme
false
false
15,674
scm
raw-urls.scm
;; -*- scheme -*- ;; these babies come from requests to the TuneIn API. They are json ;; representations of TuneIn's responses. They show us some vital ;; information: ;; - is_direct may be #f and the url may still be an audio-payload ;; - many of these don't work ;; - we don't trust anybody ;; ;; we do, however, look at filename extensions. if it ends with .mp3, ;; it's an mp3-file, no matter what TuneIn tells us. '( ;; change mms:// => mmst:// ((element . "audio") (url . "mms://mediaserver.glauco.it/BluSat2000") (reliability . 83) (bitrate . 32) (media_type . "wma") (is_direct . #t)) ;; connection refused ((element . "audio") (url . "http://mfile.akamai.com/52334/live/reflector:36992.asx?bkup=38386") (reliability . 97) (bitrate . 32) (media_type . "wma") (is_direct . #f)) ;; connection refused ((element . "audio") (url . "http://mfile.akamai.com/52334/live/reflector:34354.asx?bkup=34960") (reliability . 98) (bitrate . 32) (media_type . "wma") (is_direct . #f)) ;; pls ((element . "audio") (url . "http://stream.wbai.org/64kmp3stereo.pls") (reliability . 98) (bitrate . 64) (media_type . "mp3") (is_direct . #f)) ;; works ((element . "audio") (url . "http://icy3.abacast.com/progvoices-progvoicesmp3-32") (reliability . 92) (bitrate . 32) (media_type . "mp3") (is_direct . #t)) ;; works ((element . "audio") (url . "http://216.55.165.146:8000") (reliability . 98) (bitrate . 64) (media_type . "mp3") (is_direct . #t)) ;; ((element . "audio") (url . "http://www.kpfa.org/streams/kpfa_64k.m3u") (reliability . 99) (bitrate . 64) (media_type . "mp3") (is_direct . #f)) ((element . "audio") (url . "http://stream.am950ktnf.com:8000/") (reliability . 99) (bitrate . 56) (media_type . "mp3") (is_direct . #t)) ((element . "audio") (url . "http://www.whiterosesociety.org/Kincaid.m3u") (reliability . 98) (bitrate . 48) (media_type . "mp3") (is_direct . #f)) ((element . "audio") (url . "http://audio.str3am.com:5110") (reliability . 100) (bitrate . 128) (media_type . "mp3") (is_direct . #t)) ((element . "audio") (url . "http://main-fm.org/stream/high.m3u") (reliability . 100) (bitrate . 128) (media_type . "mp3") (is_direct . #f)) ((element . "audio") (url . "http://stream-ny.radioparadise.com:8090") (reliability . 97) (bitrate . 120) (media_type . "mp3") (is_direct . #t)) ((element . "audio") (url . "http://www.live365.com/play/radiophx") (reliability . 94) (bitrate . 96) (media_type . "mp3") (is_direct . #t)) ((element . "audio") (url . "http://s5.myradiostream.com:9854") (reliability . 85) (bitrate . 144) (media_type . "mp3") (is_direct . #t)) ((element . "audio") (url . "http://sc1.christiannetcast.com:9042/listen.pls") (reliability . 97) (bitrate . 32) (media_type . "mp3") (is_direct . #f)) ((element . "audio") (url . "http://sc1.slable.com:8054/") (reliability . 97) (bitrate . 24) (media_type . "mp3") (is_direct . #t)) ((element . "audio") (url . "http://s3.voscast.com:7756") (reliability . 96) (bitrate . 32) (media_type . "mp3") (is_direct . #t)) ((element . "audio") (url . "http://thedetour.us/player/talk.pls") (reliability . 94) (bitrate . 63) (media_type . "mp3") (is_direct . #f)) ((element . "audio") (url . "http://www.airprogressive.org:8000/stream") (reliability . 95) (bitrate . 32) (media_type . "mp3") (is_direct . #t)) ((element . "audio") (url . "http://www.thomhartmann.com/streams/mp3stream.pls") (reliability . 59) (bitrate . 32) (media_type . "mp3") (is_direct . #f)) ((element . "audio") (url . "http://50.7.70.58:8309") (reliability . 87) (bitrate . 64) (media_type . "mp3") (is_direct . #t)) ((element . "audio") (url . "http://www.krfp.org/krfp.m3u") (reliability . 100) (bitrate . 80) (media_type . "mp3") (is_direct . #f)) ((element . "audio") (url . "http://kslconline.linfield.edu:8000/kslc.mp3") (reliability . 100) (bitrate . 32) (media_type . "mp3") (is_direct . #t)) ((element . "audio") (url . "http://pbradio.serverroom.us:7528") (reliability . 10) (bitrate . 32) (media_type . "mp3") (is_direct . #t)) ((element . "audio") (url . "mms://178.219.75.139:8080/RoyalFM") (reliability . 10) (bitrate . 32) (media_type . "wma") (is_direct . #t)) ((element . "audio") (url . "http://206.190.150.90:8358") (reliability . 97) (bitrate . 64) (media_type . "mp3") (is_direct . #t) (element . "audio") (url . "http://206.190.150.90:8356/") (reliability . 72) (bitrate . 128) (media_type . "mp3") (is_direct . #t)) ((element . "audio") (url . "http://wms-15.streamsrus.com:12410") (reliability . 92) (bitrate . 64) (media_type . "mp3") (is_direct . #t)) ((element . "audio") (url . "http://50.7.77.179:8024/") (reliability . 99) (bitrate . 128) (media_type . "mp3") (is_direct . #t) (element . "audio") (url . "http://hpr4.hpr.org/") (reliability . 49) (bitrate . 128) (media_type . "mp3") (is_direct . #t)) ((element . "audio") (url . "http://95.211.99.13/listen/khe45wxkb") (reliability . 97) (bitrate . 128) (media_type . "mp3") (is_direct . #t)) ((element . "audio") (url . "http://wamu-2.streamguys.com:80") (reliability . 98) (bitrate . 128) (media_type . "mp3") (is_direct . #t) (element . "audio") (url . "http://wamu.org/streams/live/2/live.asx") (reliability . 60) (bitrate . 32) (media_type . "wma") (is_direct . #f)) ((element . "audio") (url . "http://wms-15.streamsrus.com:12410") (reliability . 92) (bitrate . 64) (media_type . "mp3") (is_direct . #t)) ((element . "audio") (url . "http://listen.radionomy.com/HitsRadioCountry") (reliability . 100) (bitrate . 128) (media_type . "mp3") (is_direct . #t) (element . "audio") (url . "http://listen64.radionomy.com/HitsRadioCountry.m3u") (reliability . 98) (bitrate . 64) (media_type . "mp3") (is_direct . #f)) ((element . "audio") (url . "http://listen.radionomy.com/radio-rockabilly-country-front") (reliability . 92) (bitrate . 128) (media_type . "mp3") (is_direct . #t)) ((element . "audio") (url . "http://stream2.wnrvbluegrassradio.com/live-mp3") (reliability . 98) (bitrate . 64) (media_type . "mp3") (is_direct . #t) (element . "audio") (url . "http://www.wnrvbluegrassradio.com/wnrv-live-stream.asx") (reliability . 50) (bitrate . 64) (media_type . "wma") (is_direct . #f)) ((element . "audio") (url . "http://listen.radionomy.com/AbacusfmCountry") (reliability . 84) (bitrate . 128) (media_type . "mp3") (is_direct . #t)) ((element . "audio") (url . "http://www.181.fm/tunein.pls?station=181-frontporch&style=&description=Front%20Porch%20(Bluegrass)") (reliability . 98) (bitrate . 128) (media_type . "mp3") (is_direct . #f) (element . "audio") (url . "http://www.181.fm/stream/asx/181-frontporch") (reliability . 64) (bitrate . 64) (media_type . "wma") (is_direct . #f)) ((element . "audio") (url . "http://50.7.77.179:8024/") (reliability . 99) (bitrate . 128) (media_type . "mp3") (is_direct . #t) (element . "audio") (url . "http://hpr4.hpr.org/") (reliability . 49) (bitrate . 128) (media_type . "mp3") (is_direct . #t)) ((element . "audio") (url . "http://tess.fast-serv.com:8184") (reliability . 97) (bitrate . 128) (media_type . "mp3") (is_direct . #t)) ((element . "audio") (url . "http://radio.worldwidebluegrass.com:8700") (reliability . 91) (bitrate . 128) (media_type . "mp3") (is_direct . #t)) ((element . "audio") (url . "http://stream2.ndpusa.com:21009") (reliability . 97) (bitrate . 128) (media_type . "mp3") (is_direct . #t)) ((element . "audio") (url . "http://listen.radionomy.com/CountryCrossroadsRadio") (reliability . 97) (bitrate . 128) (media_type . "mp3") (is_direct . #t)) ((element . "audio") (url . "http://s7.viastreaming.net:7430/") (reliability . 99) (bitrate . 128) (media_type . "mp3") (is_direct . #t)) ((element . "audio") (url . "http://waaj-1.dlinkddns.com:8081") (reliability . 98) (bitrate . 32) (media_type . "wma") (is_direct . #t)) ((element . "audio") (url . "http://184.95.62.170:9242/") (reliability . 100) (bitrate . 128) (media_type . "mp3") (is_direct . #t)) ((element . "audio") (url . "http://master.streamonomy.com/roothog") (reliability . 98) (bitrate . 128) (media_type . "mp3") (is_direct . #t)) ((element . "audio") (url . "http://s4.total-streaming.com:8074/") (reliability . 98) (bitrate . 128) (media_type . "mp3") (is_direct . #t)) ((element . "audio") (url . "http://wamu-2.streamguys.com:80") (reliability . 98) (bitrate . 128) (media_type . "mp3") (is_direct . #t)) ((element . "audio") (url . "http://www.live365.com/play/texasman") (reliability . 95) (bitrate . 128) (media_type . "mp3") (is_direct . #t)) ((element . "audio") (url . "mms://nick9.surfernetwork.com/WMTL") (reliability . 94) (bitrate . 32) (media_type . "wma") (is_direct . #t)) ((element . "audio") (url . "http://50.22.212.205:8022") (reliability . 94) (bitrate . 128) (media_type . "mp3") (is_direct . #t)) ((element . "audio") (url . "http://www.live365.com/play/kahfluie") (reliability . 94) (bitrate . 128) (media_type . "mp3") (is_direct . #t)) ((element . "audio") (url . "http://moon.wavestreamer.com:7732") (reliability . 81) (bitrate . 128) (media_type . "mp3") (is_direct . #t)) ((element . "audio") (url . "http://listen.radionomy.com/telluridebluegrassradio") (reliability . 88) (bitrate . 128) (media_type . "mp3") (is_direct . #t)) ((element . "audio") (url . "http://sc2.spacialnet.com:34064") (reliability . 92) (bitrate . 32) (media_type . "mp3") (is_direct . #t)) ((element . "audio") (url . "http://46.28.49.165/stream/cmr.pls") (reliability . 86) (bitrate . 128) (media_type . "mp3") (is_direct . #f)) ((element . "audio") (url . "http://cast1.serverhostingcenter.com/tunein.php/brydietz/playlist.pls") (reliability . 91) (bitrate . 128) (media_type . "mp3") (is_direct . #f)) ((element . "audio") (url . "http://listen.radionomy.com/est-en-ouest-radio") (reliability . 97) (bitrate . 128) (media_type . "mp3") (is_direct . #t)) ((element . "audio") (url . "http://www.live365.com/play/radiowayne") (reliability . 87) (bitrate . 128) (media_type . "mp3") (is_direct . #t)) ((element . "audio") (url . "http://calm11.calmradio.com:8646/") (reliability . 100) (bitrate . 56) (media_type . "mp3") (is_direct . #t) (element . "audio") (url . "http://calmradio.com/playlists-free/bluegrass56.pls") (reliability . 10) (bitrate . 56) (media_type . "mp3") (is_direct . #f)) ((element . "audio") (url . "http://85.214.123.88:19000") (reliability . 100) (bitrate . 128) (media_type . "mp3") (is_direct . #t)) ((element . "audio") (url . "http://www.knewmusic.com:8000/") (reliability . 100) (bitrate . 128) (media_type . "mp3") (is_direct . #t)) ((element . "audio") (url . "http://184.171.160.162:8752") (reliability . 45) (bitrate . 128) (media_type . "mp3") (is_direct . #t)) ((element . "audio") (url . "mms://netshow6.play.cz/country128") (reliability . 10) (bitrate . 128) (media_type . "wma") (is_direct . #t)) ((element . "audio") (url . "http://soundbeat.org/wp-content/uploads/2014/03/PATDOYLE-Bagpipes_mixdown-.mp3") (reliability . 75) (bitrate . 20) (media_type . "mp3") (is_direct . #t)) ((element . "audio") (url . "http://radio.talksport.com/stream?awparams=platform:ts-web;lang:en") (reliability . 99) (bitrate . 32) (media_type . "mp3") (is_direct . #t)) ((element . "audio") (url . "http://shoutcast.zfast.co.uk:2199/tunein/tfm0.pls") (reliability . 98) (bitrate . 96) (media_type . "mp3") (is_direct . #f)) ((element . "audio") (url . "http://stream.amazingradio.co.uk:8000/") (reliability . 96) (bitrate . 128) (media_type . "mp3") (is_direct . #t)) ((element . "audio") (url . "http://www.bbc.co.uk/radio/listen/live/rs.asx") (reliability . 97) (bitrate . 48) (media_type . "wma") (is_direct . #f)) ((element . "audio") (url . "http://www.bbc.co.uk/worldservice/meta/tx/nb/live/eneuk.pls") (reliability . 96) (bitrate . 32) (media_type . "mp3") (is_direct . #f) (element . "audio") (url . "http://www.bbc.co.uk/worldservice/meta/live/nb/eieuk_au_nb.asx") (reliability . 82) (bitrate . 32) (media_type . "wma") (is_direct . #f)) ((element . "audio") (url . "http://usa2-pn.mixstream.net:8466/") (reliability . 95) (bitrate . 128) (media_type . "mp3") (is_direct . #t)) ((element . "audio") (url . "http://media-ice.musicradio.com/CapitalXTRANationalMP3") (reliability . 91) (bitrate . 128) (media_type . "mp3") (is_direct . #t)) ((element . "audio") (url . "http://www.simplexstream.com/tunein.php/jfaulkne/playlist.pls") (reliability . 95) (bitrate . 128) (media_type . "mp3") (is_direct . #f)) ((element . "audio") (url . "http://radio.canstream.co.uk:8070/live.mp3") (reliability . 97) (bitrate . 96) (media_type . "mp3") (is_direct . #t)) ((element . "audio") (url . "http://audio1.ipercast.net/frenchradiolondon.com/hi/mp3") (reliability . 95) (bitrate . 96) (media_type . "mp3") (is_direct . #t)) ((element . "audio") (url . "http://s1.voscast.com:7918") (reliability . 96) (bitrate . 96) (media_type . "mp3") (is_direct . #t)) ((element . "audio") (url . "http://media3.ultrastream.co.uk:80/passionfortheplanet") (reliability . 97) (bitrate . 96) (media_type . "mp3") (is_direct . #t)) ((element . "audio") (url . "http://www.prl24.net/prl96.asx") (reliability . 98) (bitrate . 96) (media_type . "wma") (is_direct . #f)) ((element . "audio") (url . "http://ar.canstream.co.uk:8003/live.mp3") (reliability . 88) (bitrate . 128) (media_type . "mp3") (is_direct . #t)) ((element . "audio") (url . "http://mp3streaming.planetwideradio.com:9360/RadioYorks") (reliability . 97) (bitrate . 96) (media_type . "mp3") (is_direct . #t)) ((element . "audio") (url . "http://67.159.60.45:8096") (reliability . 81) (bitrate . 64) (media_type . "mp3") (is_direct . #t)) ((element . "audio") (url . "http://tx.sharp-stream.com/icecast.php?i=smilesussex.mp3") (reliability . 93) (bitrate . 128) (media_type . "mp3") (is_direct . #t)) ((element . "audio") (url . "http://media-ice.musicradio.com/SmoothUKMP3") (reliability . 93) (bitrate . 320) (media_type . "mp3") (is_direct . #t)) ((element . "audio") (url . "http://tx.sharp-stream.com/icecast.php?i=spectrum2.mp3") (reliability . 96) (bitrate . 64) (media_type . "mp3") (is_direct . #t)) )
false
2f6b1d3c7ff8e1718149e73e2ee216e2499b16e4
4678ab3f30bdca67feeb16453afc8ae26b162e51
/test-object.scm
486c5b511328f26931bc945d13c816ab84e93e77
[ "Apache-2.0" ]
permissive
atship/thunderchez
93fd847a18a6543ed2f654d7dbfe1354e6b54c3d
717d8702f8c49ee0442300ebc042cb5982b3809b
refs/heads/trunk
2021-07-09T14:17:36.708601
2021-04-25T03:13:24
2021-04-25T03:13:24
97,306,402
0
0
null
2017-07-15T09:42:04
2017-07-15T09:42:04
null
UTF-8
Scheme
false
false
733
scm
test-object.scm
(import (object)) (define a (obj)) (define b (obj)) (printf "~a\n" (eq? a b)) (printf "~a\n" (obj-has? a 'ok)) (printf "~a\n" (obj-has? a 'yes)) (obj-set! a 'ok '(we are family)) (obj-set! b 'yes '(good day)) (obj-set! a 'yes (obj)) (obj-set! (obj-ref a 'yes) 'yes '(i am yes field)) (obj-set! a 'array (array)) (array-push (obj-ref a 'array) '(we are good day)) (array-push (obj-ref a 'array) '(yes we are)) (array-push (obj-ref a 'array) '(no no no yes we are)) (printf "~a\n ~a\n" a b) (array-out (obj-ref a 'array)) (printf "~a\n" a) (array-pop (obj-ref a 'array)) (printf "~a\n" a) (array-in (obj-ref a 'array) '(i am in)) (printf "~a\n" a) (obj-rm! a 'array) (array-pop (obj-ref a 'array)) (printf "~a\n" a)
false
2f6a1db0313dc0d62b58c5d1ef0e1ba84b1e9f6f
82038d539f2cffa1223aaa7b302655c8fa0669df
/scripts/merge.ss
43f3b3f6891f6859c609f359c808814d19e41e63
[ "MIT" ]
permissive
helvm/lisper
ee9de53607313835338bde9196a476a14d1ab871
91bc7876e93d5fa4fb65046eedf500a6d99278b3
refs/heads/master
2022-01-06T16:03:43.921499
2019-05-24T05:51:33
2019-07-14T20:37:15
null
0
0
null
null
null
null
UTF-8
Scheme
false
false
708
ss
merge.ss
(define (even l) (if (null? l) '() (if (null? (cdr l)) '() (cons (car (cdr l)) (even (cdr (cdr l))))))) (define (odd l) (if (null? l) '() (if (null? (cdr l)) (list (car l)) (cons (car l) (odd (cdr (cdr l))))))) (define (merge left right) (cond ((null? left) right) ((null? right) left) ((> (car left) (car right)) (cons (car right) (merge left (cdr right)))) (else (cons (car left) (merge (cdr left) right))))) (define (merge-sort l) (if (null? l) l (if (null? (cdr l)) l (merge (merge-sort (odd l)) (merge-sort (even l)))))) (merge-sort '(9 1 6 8))
false
68cc77051b80b19ea15766faccdc6e6213916c5f
acc632afe0d8d8b94b781beb1442bbf3b1488d22
/deps/sdl2/sdl2.setup
ddb1bee143e7ff2283b789a852810d5b95d286a6
[ "BSD-2-Clause", "BSD-3-Clause" ]
permissive
kdltr/life-is-so-pretty
6cc6e6c6e590dda30c40fdbfd42a5a3a23644794
5edccf86702a543d78f8c7e0f6ae544a1b9870cd
refs/heads/master
2021-01-20T21:12:00.963219
2016-05-13T12:19:02
2016-05-13T12:19:02
61,128,206
1
0
null
null
null
null
UTF-8
Scheme
false
false
3,440
setup
sdl2.setup
;;;; -*- Scheme -*- (use srfi-1) (include "lib/version.scm") (define version (apply sprintf "~A.~A.~A" (egg-version))) (define modules '(sdl2-internals sdl2)) (define known-sdl-versions '("2.0.0" "2.0.1" "2.0.2" "2.0.3" "2.0.4" )) (define known-egg-versions '("0.2.0" )) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (define sdl2-flags-list (if (get-environment-variable "SDL2_FLAGS") (string-split (get-environment-variable "SDL2_FLAGS")) (with-input-from-pipe "sdl2-config --cflags --libs" read-lines))) (compile ,@sdl2-flags-list "print-sdl-version.scm" -o "./print-sdl-version") (define sdl-version (with-input-from-pipe "./print-sdl-version" read)) (remove-file* "./print-sdl-version") (printf "~Nsdl2 egg version ~A~%" version) (printf "Compiling with SDL version ~A" sdl-version) ;;; Generate a list with a "sdl2-X.Y.Z" string for every egg version ;;; less than or equal to the current egg version. (define egg-version-features (filter-map (lambda (v) (if (version>=? version v) (sprintf "sdl2-~A+" v) #f)) known-egg-versions)) ;;; Generate a list with a "libSDL-X.Y.Z" string for every SDL version ;;; less than or equal to the current SDL version. (define sdl-version-features (filter-map (lambda (v) (if (version>=? sdl-version v) (sprintf "libSDL-~A+" v) #f)) known-sdl-versions)) ;;; Generate lib/_features.scm which registers feature identifiers. (with-output-to-file "lib/_features.scm" (lambda () (define registrations `((register-feature! #:sdl2) ,@(map (lambda (v) `(register-feature! ,(string->keyword v))) (append egg-version-features sdl-version-features)))) (print "\n;;; NOTE: This file is automatically generated during installation.\n") (pp `(begin-for-syntax ,@registrations)) (print) (pp `(eval-when (compile load eval) ,@registrations)))) (define emit-types? (version>=? (chicken-version) "4.7.4")) (define profile? (cond-expand (sdl2-profile #t) (else #f))) (define verbose? (get-environment-variable "SDL2_VERBOSE_INSTALL")) (define (module-file module extension) (string-append (symbol->string module) extension)) (define (compile-module module #!optional (extra-flags-list '())) (newline) (printf "COMPILING MODULE: ~A~N~%" module) (compile -c -O3 -d1 ,@extra-flags-list -unit ,module ,(module-file module ".scm")) (compile -J -s -O3 -d1 ,@extra-flags-list ,@(if verbose? '(-v) '()) ,@(if profile? '(-profile) '()) ,@(if emit-types? `(-emit-type-file ,(module-file module ".types")) '()) ,(module-file module ".scm")) (compile -v -s -O3 -d0 ,(module-file module ".import.scm")) (newline)) (newline) (compile-module 'sdl2-internals sdl2-flags-list) (compile-module 'sdl2 '()) (newline) (define products (append-map (lambda (module) (cons* (module-file module ".so") (module-file module ".import.so") (module-file module ".o") (if emit-types? (list (module-file module ".types")) '()))) modules)) (install-extension 'sdl2 products `((version ,version)))
false
62084960e04ae4e7f1945b299db236fb39aa8316
432924338995770f121e1e8f6283702653dd1369
/2/p2.68.scm
8a7a4c25ff81d18e967bb2032b983d2aea9f3887
[]
no_license
punchdrunker/sicp-reading
dfaa3c12edf14a7f02b3b5f4e3a0f61541582180
4bcec0aa7c514b4ba48e677cc54b41d72c816b44
refs/heads/master
2021-01-22T06:53:45.096593
2014-06-23T09:51:27
2014-06-23T09:51:27
null
0
0
null
null
null
null
UTF-8
Scheme
false
false
786
scm
p2.68.scm
(load "./eqt.scm") (load "./p2.67.scm") (define (encode message tree) (if (null? message) '() (append (encode-symbol (car message) tree) (encode (cdr message) tree)))) (define (encode-symbol symbol tree) (define (enc-iter tree) (if (leaf? tree) '() (if (memq symbol (symbols (left-branch tree))) (cons 0 (enc-iter (left-branch tree))) (cons 1 (enc-iter (right-branch tree)))))) (if (memq symbol (symbols tree)) (enc-iter tree) (error "Not Found symbol of " symbol))) (define sample-decoded-message '(A D A B B C A)) (define answer (encode sample-decoded-message sample-tree)) (test-start "問題2.68") (eqt sample-message answer) (eqt '(A D A B B C A) (decode sample-message sample-tree)) (test-end)
false
73b53e83a69aa7496ce6d0373731df6a6ede31de
c63772c43d0cda82479d8feec60123ee673cc070
/ch3/14.scm
f86d03c71b266f6b74da82131aea3f203eed7b10
[ "Apache-2.0" ]
permissive
liuyang1/sicp-ans
26150c9a9a9c2aaf23be00ced91add50b84c72ba
c3072fc65baa725d252201b603259efbccce990d
refs/heads/master
2021-01-21T05:02:54.508419
2017-09-04T02:48:46
2017-09-04T02:48:52
14,819,541
2
0
null
null
null
null
UTF-8
Scheme
false
false
306
scm
14.scm
(define (myreverse x) (define (loop x y) (if (null? x) y (let ((temp (cdr x))) (set-cdr! x y) (loop temp x)))) (loop x '())) (define *v* '(a b c d)) (define (displayln x) (display x) (newline)) (displayln *v*) (define *w* (myreverse *v*)) (displayln *v*) (displayln *w*)
false
02ef1f043ff2ff6a8bd5dab8778101a864bc504e
3508dcd12d0d69fec4d30c50334f8deb24f376eb
/tests/runtime/test-string-normalization.scm
d0105c4fc3574c4644a33746e2a1743910531cba
[]
no_license
barak/mit-scheme
be625081e92c2c74590f6b5502f5ae6bc95aa492
56e1a12439628e4424b8c3ce2a3118449db509ab
refs/heads/master
2023-01-24T11:03:23.447076
2022-09-11T06:10:46
2022-09-11T06:10:46
12,487,054
12
1
null
null
null
null
UTF-8
Scheme
false
false
2,982
scm
test-string-normalization.scm
#| -*-Scheme-*- Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022 Massachusetts Institute of Technology This file is part of MIT/GNU Scheme. MIT/GNU Scheme is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. MIT/GNU Scheme is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with MIT/GNU Scheme; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. |# ;;;; Tests of string normalization (declare (usual-integrations)) (define normalization-test-cases (map (lambda (columns) (map list->string columns)) (read-file (merge-pathnames "test-string-normalization-data" (directory-pathname (current-load-pathname)))))) (define (norm-tc-source tc) (car tc)) (define (norm-tc-nfc tc) (cadr tc)) (define (norm-tc-nfd tc) (caddr tc)) (define (norm-tc-nfkc tc) (cadddr tc)) (define (norm-tc-nfkd tc) (car (cddddr tc))) (define (nfc-test source expected) (lambda () (with-test-properties (lambda () (assert-ts= (string->nfc source) expected)) 'expression `(string->nfc ,source)))) (define-test 'string->nfc (map (lambda (tc) (list (nfc-test (norm-tc-source tc) (norm-tc-nfc tc)) (nfc-test (norm-tc-nfc tc) (norm-tc-nfc tc)) (nfc-test (norm-tc-nfd tc) (norm-tc-nfc tc)) (nfc-test (norm-tc-nfkc tc) (norm-tc-nfkc tc)) (nfc-test (norm-tc-nfkd tc) (norm-tc-nfkc tc)))) normalization-test-cases)) (define (nfd-test source expected) (lambda () (with-test-properties (lambda () (assert-ts= (string->nfd source) expected)) 'expression `(string->nfd ,source)))) (define-test 'string->nfd (map (lambda (tc) (list (nfd-test (norm-tc-source tc) (norm-tc-nfd tc)) (nfd-test (norm-tc-nfc tc) (norm-tc-nfd tc)) (nfd-test (norm-tc-nfd tc) (norm-tc-nfd tc)) (nfd-test (norm-tc-nfkc tc) (norm-tc-nfkd tc)) (nfd-test (norm-tc-nfkd tc) (norm-tc-nfkd tc)))) normalization-test-cases)) (define (trivial-string=? s1 s2) (let ((n (string-length s1))) (and (fix:= n (string-length s2)) (let loop ((i 0)) (if (fix:< i n) (and (char=? (string-ref s1 i) (string-ref s2 i)) (loop (fix:+ i 1))) #t))))) (define-comparator trivial-string=? 'string=?) (define assert-ts= (simple-binary-assertion trivial-string=? #f))
false
444b5036669fe2aee5cbf96cc1dc077ee2844ff6
a74932f6308722180c9b89c35fda4139333703b8
/edwin48/scsh/pathnames.scm
fb994b5f88f60ca031b9e27396b529ece70bd69d
[]
no_license
scheme/edwin48
16b5d865492db5e406085e8e78330dd029f1c269
fbe3c7ca14f1418eafddebd35f78ad12e42ea851
refs/heads/master
2021-01-19T17:59:16.986415
2014-12-21T17:50:27
2014-12-21T17:50:27
1,035,285
39
10
null
2022-02-15T23:21:14
2010-10-29T16:08:55
Scheme
UTF-8
Scheme
false
false
26,171
scm
pathnames.scm
;;; -*- Mode: Scheme; scheme48-package: pathname -*- ;;;; Pathnames ;;; This code is written by Taylor R. Campbell and placed in the Public ;;; Domain. All warranties are disclaimed. ; ,open define-record-type* simple-signals util methods receiving fluids cells (define-record-type* pathname (%make-pathname origin directory filename) ()) (define-record-discloser :pathname (lambda (pathname) (cons (if (pathname-origin pathname) 'PATHNAME 'RELATIVE-PATHNAME) (%pathname-namelist pathname)))) (define (make-pathname origin directory filename) (or (%parse-namelist origin directory filename) (call-error "invalid arguments" make-pathname origin directory filename))) (define (make-relative-pathname directory filename) (make-pathname #f directory filename)) (define (maybe-object->pathname obj . fs-type-option) (cond ((pathname? obj) obj) ((symbol? obj) (make-relative-pathname '() obj)) ((string? obj) (apply parse-namestring obj fs-type-option)) ((pair? obj) (parse-namelist obj)) (else #f))) (define (object->pathname obj . fs-type-option) (or (apply maybe-object->pathname obj fs-type-option) (apply call-error "unable to coerce to pathname" object->pathname obj fs-type-option))) (define (pathname-complete? pathname) (and (pathname-origin pathname) (cond ((pathname-filename pathname) => filename-complete?) (else #f)))) (define (filename-complete? filename) (and (filename-base filename) #t)) ;;;; Filenames (define-record-type* filename (%make-filename base types version) ()) (define-record-discloser :filename (lambda (filename) `(FILENAME ,(disclose-filename filename #f)))) (define (disclose-filename filename flatten?) (let ((base (filename-base filename)) (types (filename-types filename)) (version (filename-version filename))) (if (and flatten? base (not (or version (pair? types)))) base `(,base ,(if (and (pair? types) (null? (cdr types))) (car types) '()) ,@(if version (list version) '()))))) (define (make-filename base types . version) (let ((version (if (pair? version) (car version) #f))) (if (not (and (filename-base? base) (filename-types? types) (filename-version? version))) (call-error "invalid arguments" make-filename base types version) (%make-filename base (if (or (string? types) (symbol? types)) (list types) types) version)))) (define (filename-base? obj) (or (not obj) (string? obj) (symbol? obj))) (define (filename-types? obj) (or (string? obj) (symbol? obj) (let loop ((obj obj)) (cond ((pair? obj) (and (or (string? (car obj)) (symbol? (car obj))) (loop (cdr obj)))) ((null? obj) #t) (else #f))))) (define (filename-version? obj) (or (not obj) (eq? obj 'OLDEST) (eq? obj 'NEWEST) (and (integer? obj) (exact? obj) (<= 0 obj)))) (define (filename-type filename) (let ((types (filename-types filename))) (if (pair? types) (last types) #f))) ;;;; Namelists ;;; <namelist> -> (<file namelist>) ;;; | (<directory namelist> <file namelist>) ;;; | (<origin> <directory namelist> <file namelist>) ;;; ;;; <file namelist> -> #F ;;; | <file base namelist> ;;; | (<file base namelist>) ;;; | (<file base namelist> <file types>) ;;; | (<file base namelist> <file types> <file version>) ;;; ;;; <file base namelist> -> <component> ;;; ;;; <file types> -> <component> ;;; | (<component>*) ;;; ;;; <file version> -> #F ;;; | <exact, non-negative integer> ;;; | OLDEST ;;; | NEWEST ;;; ;;; <directory namelist> -> <component> ;;; | (<file namelist>*) ;;; ;;; <component> -> <string> | <symbol> ;++ This is kind of grody and would like to be rewritten with a decent pattern ;++ matcher. (define (parse-namelist namelist) (cond ((not (pair? namelist)) #f) ((null? (cdr namelist)) (%parse-namelist #f '() (car namelist))) ((not (pair? (cdr namelist))) #f) ((null? (cddr namelist)) (%parse-namelist #f (car namelist) (cadr namelist))) ((not (pair? (cddr namelist))) #f) ((null? (cdddr namelist)) (%parse-namelist (car namelist) (cadr namelist) (caddr namelist))) (else #f))) (define (%parse-namelist origin directory filename) ((massage-directory directory) (lambda () #f) (lambda (directory) (let ((win (lambda (filename) (%make-pathname origin directory filename)))) (if (not filename) (win #f) ((massage-filename filename) (lambda () #f) win)))))) (define (massage-directory directory) (lambda (lose win) (cond ((filename? directory) (win (list directory))) ((or (string? directory) (symbol? directory)) (win (list (make-filename directory #f)))) (else (let loop ((in directory) (out '())) (cond ((pair? in) ((massage-filename (car in)) lose (lambda (filename) (loop (cdr in) (cons filename out))))) ((null? in) (win (reverse out))) (else (lose)))))))) (define (massage-filename filename) (lambda (lose win) (cond ((filename? filename) (win filename)) ((or (string? filename) (symbol? filename)) (win (%make-filename filename #f #f))) ((parse-file-namelist filename) => win) (else (lose))))) (define (parse-file-namelist filename) (cond ((not (and (pair? filename) (filename-base? (car filename)))) #f) ((null? (cdr filename)) (make-filename (car filename) '())) ((not (and (pair? (cdr filename)) (filename-types? (cadr filename)))) #f) ((null? (cddr filename)) (make-filename (car filename) (cadr filename))) ((not (and (pair? (cddr filename)) (filename-version? (caddr filename)))) #f) (else (make-filename (car filename) (cadr filename) (caddr filename))))) (define (pathname-namelist pathname) (cond ((maybe-object->pathname pathname) => %pathname-namelist) (else (call-error "invalid pathname argument" pathname-namelist pathname)))) (define (maybe-pathname-namelist pathname) (cond ((maybe-object->pathname pathname) => %pathname-namelist) (else #f))) (define (%pathname-namelist pathname) (let ((origin (pathname-origin pathname)) (directory (pathname-directory pathname)) (filename (pathname-filename pathname))) `(,@(if origin (list origin) '()) ,@(if (null? directory) (if origin '(()) '()) (list (map (lambda (filename) (disclose-filename filename #t)) directory))) ,(if filename (disclose-filename filename #t) #f)))) ;;;; Substituting Components (define (pathname-with-origin pathname origin) (cond ((maybe-object->pathname pathname) => (lambda (pathname) (make-pathname origin (pathname-directory pathname) (pathname-filename pathname)))) (else (call-error "invalid pathname argument" pathname-with-origin pathname origin)))) (define (pathname-with-directory pathname directory) (define (lose message) (call-error message pathname-with-directory pathname directory)) (cond ((maybe-object->pathname pathname) => (lambda (pathname) (cond ((massage-directory directory) => (lambda (directory) (make-pathname (pathname-origin pathname) directory (pathname-filename pathname)))) (else (lose "invalid directory argument"))))) ((massage-directory directory) (lose "invalid pathname argument")) (else (lose "invalid arguments")))) (define (pathname-with-filename pathname filename) (define (lose message) (call-error message pathname-with-filename pathname filename)) (cond ((maybe-object->pathname pathname) => (lambda (pathname) (cond ((massage-filename filename) => (lambda (filename) (make-pathname (pathname-origin pathname) (pathname-directory pathname) filename))) (else (lose "invalid filename argument"))))) ((massage-filename filename) (lose "invalid pathname argument")) (else (lose "invalid arguments")))) ;;;; Directory Pathnames (define (directory-pathname? pathname) (cond ((maybe-object->pathname pathname) => (lambda (pathname) (not (pathname-filename pathname)))) (else (call-error "invalid pathname argument" directory-pathname? pathname)))) (define (pathname-as-directory pathname) (cond ((maybe-object->pathname pathname) => (lambda (pathname) (cond ((pathname-filename pathname) => (lambda (filename) (make-pathname (pathname-origin pathname) (append (pathname-directory pathname) (list filename)) #f))) (else pathname)))) (else (call-error "invalid pathname argument" pathname-as-directory pathname)))) (define (pathname-container pathname) (cond ((maybe-object->pathname pathname) => (lambda (*pathname) (let loop ((*pathname *pathname)) (let ((origin (pathname-origin *pathname)) (directory (pathname-directory *pathname)) (filename (pathname-filename *pathname))) (cond (filename (make-pathname origin directory #f)) ((pair? directory) (make-pathname origin (drop-last directory) #f)) (else (let ((expansion (expand-pathname *pathname))) (if (pathname-eq? expansion *pathname) #f (loop expansion))))))))) (else (call-error "invalid pathname argument" pathname-container pathname)))) (define (drop-last list) (let recur ((list list)) (let ((tail (cdr list))) (if (null? tail) '() (cons (car list) (recur tail)))))) ;;;; Expansion (define (expand-pathname pathname) (cond ((maybe-object->pathname pathname) => (lambda (*pathname) (let ((origin (pathname-origin *pathname))) (define (win default-pathname) (merge-pathnames (pathname-with-origin *pathname #f) default-pathname)) (cond ((not origin) *pathname) ((pair? origin) (cond ((expand-parameterized-origin origin) => win) (else *pathname))) (else (cond ((expand-simple-origin origin) => win) (else *pathname))))))) (else (call-error "invalid pathname argument" expand-pathname pathname)))) (define (expand-parameterized-origin origin) (let ((try (lambda (expander) (if expander (expander origin) #f)))) (or (try (assv-value (car origin) (local-pathname-expanders))) (try (assv-value (car origin) (global-pathname-expanders))) (try (host-origin-expander (car origin)))))) (define (expand-simple-origin origin) (let ((try (lambda (expansion) (if (procedure? expansion) (expansion) expansion)))) (or (try (assv-value origin (local-pathname-expansions))) (try (assv-value origin (global-pathname-expansions))) (try (host-origin-expansion origin))))) (define (assv-value key alist) (cond ((assv key alist) => cdr) (else #f))) (define (expand-pathname* pathname) (cond ((maybe-object->pathname pathname) => (lambda (pathname) (let loop ((pathname pathname)) (let ((expansion (expand-pathname pathname))) (if (pathname-eq? expansion pathname) pathname (loop expansion)))))) (else (call-error "invalid pathname argument" expand-pathname* pathname)))) ;++ Check argument types...clean out #F... (define $global-pathname-expansions (make-fluid (make-cell '()))) (define $global-pathname-expanders (make-fluid (make-cell '()))) (define (global-pathname-expansions) (fluid-cell-ref $global-pathname-expansions)) (define (global-pathname-expanders) (fluid-cell-ref $global-pathname-expanders)) (define (define-global-pathname-expansion origin expansion) (let ((expansions (global-pathname-expansions))) (cond ((assq origin expansions) => (lambda (probe) (warn "redefining global pathname expansion" origin `(old: ,(cdr probe)) `(new: ,expansion)) (set-cdr! probe expansion))) (else (fluid-cell-set! $global-pathname-expansions (cons (cons origin expansion) expansions)))))) (define (define-global-pathname-expander origin-key expander) (let ((expanders (global-pathname-expanders))) (cond ((assq origin-key expanders) => (lambda (probe) (warn "redefining global pathname expander" origin-key `(old: ,(cdr probe)) `(new: ,expander)) (set-cdr! probe expander))) (else (fluid-cell-set! $global-pathname-expanders (cons (cons origin-key expander) expanders)))))) (define (with-pathname-origins-preserved thunk) (let-fluids $global-pathname-expansions (make-cell (global-pathname-expansions)) $global-pathname-expanders (make-cell (global-pathname-expanders)) thunk)) (define $local-pathname-expansions (make-fluid '())) (define $local-pathname-expanders (make-fluid '())) (define (local-pathname-expansions) (fluid $local-pathname-expansions)) (define (local-pathname-expanders) (fluid $local-pathname-expanders)) (define (with-local-pathname-expansion origin expansion thunk) (let-fluid $local-pathname-expansions (cons (cons origin expansion) (local-pathname-expansions)) thunk)) (define (with-local-pathname-expander origin-key expander thunk) (let-fluid $local-pathname-expanders (cons (cons origin-key expander) (local-pathname-expanders)) thunk)) ;;;; Comparison (define (pathname-eq? pathname-a pathname-b) (let ((*pathname-a (maybe-object->pathname pathname-a)) (*pathname-b (maybe-object->pathname pathname-b))) (if (not (and *pathname-a *pathname-b)) (call-error "invalid pathname arguments" pathname-eq? pathname-a pathname-b) (%pathname-eq? pathname-a pathname-b)))) (define (pathname-eqv? pathname-a pathname-b) (let ((*pathname-a (maybe-object->pathname pathname-a)) (*pathname-b (maybe-object->pathname pathname-b))) (if (not (and *pathname-a *pathname-b)) (call-error "invalid pathname arguments" pathname-eqv? pathname-a pathname-b) (%pathname-eq? (expand-pathname* *pathname-a) (expand-pathname* *pathname-b))))) (define (%pathname-eq? pathname-a pathname-b) (and (equal? (pathname-origin pathname-a) (pathname-origin pathname-b)) (let loop ((directory-a (pathname-directory pathname-a)) (directory-b (pathname-directory pathname-b))) (if (and (pair? directory-a) (pair? directory-b)) (and (filename-eq? (car directory-a) (car directory-b)) (loop (cdr directory-a) (cdr directory-b))) (and (null? directory-a) (null? directory-b)))) (let ((filename-a (pathname-filename pathname-a)) (filename-b (pathname-filename pathname-b))) (if (and filename-a filename-b) (filename-eq? filename-a filename-b) (not (or filename-a filename-b)))))) (define (filename-eq? filename-a filename-b) (and (equal? (filename-base filename-a) (filename-base filename-b)) (equal? (filename-types filename-a) (filename-types filename-a)) (eqv? (filename-version filename-a) (filename-version filename-b)))) ;;;; Merging (define (merge-pathnames pathname default-pathname) (let ((*pathname (maybe-object->pathname pathname)) (*default-pathname (maybe-object->pathname default-pathname))) (if (not (and *pathname *default-pathname)) (call-error "invalid arguments" merge-pathnames pathname default-pathname) (let ((origin (pathname-origin *pathname)) (directory (pathname-directory *pathname)) (filename (merge-filenames (pathname-filename *pathname) (pathname-filename *default-pathname)))) (if origin (make-pathname origin directory filename) (make-pathname (pathname-origin *default-pathname) (append (pathname-directory *default-pathname) directory) filename)))))) (define (merge-filenames filename default-filename) (cond ((not filename) default-filename) ((not default-filename) filename) (else (let ((base (filename-base filename)) (types (filename-types filename)) (version (filename-version filename))) (make-filename (or base (filename-base default-filename)) (if (null? types) (filename-types default-filename) types) (or version (and (not base) (filename-version default-filename)))))))) (define (enough-pathname pathname default-pathname) (let ((*pathname (maybe-object->pathname pathname)) (*default-pathname (maybe-object->pathname default-pathname))) (if (not (and *pathname *default-pathname)) (call-error "invalid arguments" enough-pathname pathname default-pathname) (let ((origin (pathname-origin *pathname)) (directory (pathname-directory *pathname)) (filename (enough-filename (pathname-filename *pathname) (pathname-filename *default-pathname)))) (if (and origin (not (equal? origin (pathname-origin *default-pathname)))) (make-pathname origin directory filename) (make-pathname #f (enough-directory directory (pathname-directory *default-pathname)) filename)))))) (define (enough-directory directory default-directory) (strip-common-prefix directory default-directory filename-eq?)) (define (enough-filename filename default-filename) (if (not default-filename) filename (let ((enough (lambda (accessor) (let ((component (accessor filename)) (default-component (accessor default-filename))) (and (not (equal? component default-component)) component))))) (make-filename (enough filename-base) (enough filename-types) (enough filename-version))))) (define (strip-common-prefix datum default-datum equal?) (let loop ((components datum) (default-components default-datum)) (cond ((not (pair? default-components)) components) ((and (pair? components) (equal? (car components) (car default-components))) (loop (cdr components) (cdr default-components))) (else datum)))) ;;;; Namestrings (define (parse-namestring namestring . fs-type-option) (%parse-namestring (file-system-type-option fs-type-option) namestring)) (define (pathname-namestring pathname . fs-type-option) (cond ((maybe-object->pathname pathname) => (lambda (pathname) (%pathname-namestring (file-system-type-option fs-type-option) pathname))) (else (apply call-error "invalid pathname argument" pathname-namestring pathname fs-type-option)))) (define (enough-namestring pathname default-pathname . fs-type-option) (let ((*pathname (maybe-object->pathname pathname)) (*default-pathname (maybe-object->pathname default-pathname))) (if (and *pathname *default-pathname) (%enough-namestring (file-system-type-option fs-type-option) *pathname *default-pathname) (apply call-error "invalid pathname arguments" enough-namestring pathname default-pathname fs-type-option)))) (define (origin-namestring pathname . fs-type-option) (cond ((maybe-object->pathname pathname) => (lambda (pathname) (%origin->namestring (file-system-type-option fs-type-option) (pathname-origin pathname)))) (else (apply call-error "invalid pathname argument" origin-namestring pathname fs-type-option)))) (define (directory-namestring pathname . fs-type-option) (cond ((maybe-object->pathname pathname) => (lambda (pathname) (%directory->namestring (file-system-type-option fs-type-option) (pathname-directory pathname)))) (else (apply call-error "invalid pathname argument" directory-namestring pathname fs-type-option)))) (define (file-namestring pathname . fs-type-option) (cond ((maybe-object->pathname pathname) => (lambda (pathname) (%filename->namestring (file-system-type-option fs-type-option) (pathname-filename pathname)))) (else (apply call-error "invalid pathname argument" file-namestring pathname fs-type-option)))) (define (file-system-type-option fs-type-option) (if (pair? fs-type-option) (car fs-type-option) (host-file-system-type))) ;;;;; Namestring Generics (define-generic %parse-namestring &parse-namestring (fs-type namestring)) (define-generic %canonicalize-namestring &canonicalize-namestring (fs-type namestring)) (define-generic %pathname-namestring &pathname-namestring (fs-type pathname)) (define-generic %enough-namestring &enough-namestring (fs-type pathname default-pathname)) (define-generic %origin->namestring &origin->namestring (fs-type origin)) (define-generic %directory->namestring &directory->namestring (fs-type directory)) (define-generic %filename->namestring &filename->namestring (fs-type filename)) ;;;; Default methods (define-method &canonicalize-namestring (fs-type namestring) (%pathname-namestring fs-type (%parse-namestring fs-type namestring))) (define-method &pathname-namestring (fs-type pathname) (string-append (%origin->namestring fs-type (pathname-origin pathname)) (%directory->namestring fs-type (pathname-directory pathname)) (cond ((pathname-filename pathname) => (lambda (filename) (%filename->namestring fs-type filename))) (else "")))) (define-method &enough-namestring (fs-type pathname default-pathname) (%pathname-namestring fs-type (enough-pathname pathname default-pathname))) ;;;; Local Host Initialization (define (initialize-pathnames! host-type expansion-method expander-method) (fluid-cell-set! $host-file-system-type host-type) (fluid-cell-set! $host-origin-expansion-method expansion-method) (fluid-cell-set! $host-origin-expander-method expander-method)) (define $host-file-system-type (make-fluid (make-cell #f))) (define (host-file-system-type) (fluid-cell-ref $host-file-system-type)) (define $host-origin-expansion-method (make-fluid (make-cell #f))) (define (host-origin-expansion origin) ((fluid-cell-ref $host-origin-expansion-method) origin)) (define $host-origin-expander-method (make-fluid (make-cell #f))) (define (host-origin-expander origin-key) ((fluid-cell-ref $host-origin-expander-method) origin-key)) (define (with-pathnames-initialized host-type expansion-method expander-method thunk) (let-fluids $host-file-system-type (make-cell host-type) $host-origin-expansion-method (make-cell expansion-method) $host-origin-expander-method (make-cell expander-method) thunk))
false