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 |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
d91a13433b8a9121721a69753a735c18029849e8
|
d51c8c57288cacf9be97d41079acc7c9381ed95a
|
/scsh/scheme/bufpol.scm
|
d314b8a6ed8a500eb3dcc93f0915a87022e690a8
|
[] |
no_license
|
yarec/svm
|
f926315fa5906bd7670ef77f60b7ef8083b87860
|
d99fa4d3d8ecee1353b1a6e9245d40b60f98db2d
|
refs/heads/master
| 2020-12-13T08:48:13.540156 | 2020-05-04T06:42:04 | 2020-05-04T06:42:04 | 19,306,837 | 2 | 0 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 507 |
scm
|
bufpol.scm
|
;;; Flags that control buffering policy.
;;; Copyright (c) 1993 by Olin Shivers. See file COPYING.
;;; Copyright (c) 1995 by Brian D. Carlstrom.
;;; These are for the SET-PORT-BUFFERING procedure, essentially a Scheme
;;; analog of the setbuf(3S) stdio call. We use the actual stdio values.
;;; These constants are not likely to change from stdio lib to stdio lib,
;;; but you need to check when you do a port.
(define-enum-constants bufpol
(block 0) ; _IOFBF
(line 1) ; _IOLBF
(none 2)) ; _IONBF
| false |
4657608b60b9e7eb5660b36199e6252956627657
|
fb9a1b8f80516373ac709e2328dd50621b18aa1a
|
/ch3/exercise3-33.scm
|
8c9e652d810ccbc0426e82b0f0f9d85da94ceb70
|
[] |
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 | 445 |
scm
|
exercise3-33.scm
|
;;問題3.33
(define (averager a b c)
(let ((u (make-connector))
(v (make-connector)))
(adder a b u)
(multiplier v c u)
(constant 2 v)
'ok))
(define false #f)
(define true #t)
(define A (make-connector))
(define B (make-connector))
(define C (make-connector))
(probe "A" A)
(probe "B" B)
(averager A B C)
(set-value! A 10 'user)
(set-value! B 30 'user)
(get-value C)
(forget-value! A 'user)
(set-value! A 90 'user)
| false |
c73ec4fb0af1b1a7e93064c5b7338e21df8f4792
|
8844dce861bb91137e1566599a6e7bc41a183b9e
|
/lib/mmck.pfds.deques.scm
|
61cab88b35f1ee45cff42a4cfa0ee114a538a5b0
|
[
"BSD-3-Clause"
] |
permissive
|
marcomaggi/mmck-pfds
|
354adc3e0809011494e7feab8af6adfd152f1b58
|
f8bc3626ed9e2558210d5f169110b123d8e817d4
|
refs/heads/master
| 2020-05-18T05:14:59.560841 | 2019-07-12T19:17:57 | 2019-07-12T19:17:57 | 184,199,945 | 0 | 0 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 8,058 |
scm
|
mmck.pfds.deques.scm
|
;;; -*- coding: utf-8-unix -*-
;;;
;;;Part of: MMCK Pfds
;;;Contents: module deques
;;;Date: Apr 29, 2019
;;;
;;;Abstract
;;;
;;; This unit defines the module deques: purely functional deques.
;;;
;;;Copyright (c) 2019 Marco Maggi <[email protected]>
;;;Copyright (c) 2012 Ian Price <[email protected]>
;;;All rights reserved.
;;;
;;;Redistribution and use in source and binary forms, with or without modification,
;;;are permitted provided that the following conditions are met:
;;;
;;;1. Redistributions of source code must retain the above copyright notice, this
;;; list of conditions and the following disclaimer.
;;;
;;;2. Redistributions in binary form must reproduce the above copyright notice, this
;;; list of conditions and the following disclaimer in the documentation and/or
;;; other materials provided with the distribution.
;;;
;;;3. The name of the author may not be used to endorse or promote products derived
;;; from this software without specific prior written permission.
;;;
;;;THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
;;;WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
;;;MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
;;;SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
;;;EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
;;;SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
;;;INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
;;;STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
;;;OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
;;;DAMAGE.
;;;; documentation:
;;
;; make-deque : () -> deque
;; returns a deque containing to items
;;
;; deque? : any -> boolean
;; tests if an object is a deque
;;
;; deque-length : deque -> non-negative integer
;; returns the number of items in the deque
;;
;; deque-empty? : deque -> boolean
;; returns true if there are no items in the deque, false otherwise
;;
;; enqueue-front : deque any -> deque
;; returns a new deque with the inserted item at the front
;;
;; enqueue-rear : deque any -> deque
;; returns a new deque with the inserted item at the rear
;;
;; dequeue-front : deque -> any queue
;; returns two values, the item at the front of the deque, and a new
;; deque containing all the other items
;; raises a &deque-empty condition if the deque is empty
;;
;; dequeue-rear : deque -> any queue
;; returns two values, the item at the rear of the deque, and a new
;; deque containing all the other items
;; raises a &deque-empty condition if the deque is empty
;;
;; deque-empty-condition? : object -> boolean
;; tests if an object is a &deque-empty condition
;;
;; deque->list : deque -> listof(any)
;; returns a list containing all the elements of the deque. The order
;; of the elements in the list is the same as the order they would be
;; dequeued from the front of the deque.
;;
;; list->deque : listof(any) -> deque
;; returns a deque containing all of the elements in the list. The
;; order of the elements in the deque is the same as the order of the
;; elements in the list.
;;
(declare (unit mmck.pfds.deques)
(uses mmck.pfds.helpers)
(uses mmck.pfds.lazy-lists)
(emit-import-library mmck.pfds.deques))
(module (mmck.pfds.deques)
(make-deque
deque?
deque-length
deque-empty?
enqueue-front
enqueue-rear
dequeue-front
dequeue-rear
deque-empty-condition?
deque->list
list->deque)
(import (scheme)
(mmck pfds helpers)
(mmck pfds lazy-lists))
;;;; helpers
(define-constant c 2)
(define (rot1 n l r)
(if (>= n c)
(cons* (head l)
(rot1 (- n c) (tail l) (drop c r)))
(rot2 l (drop n r) '())))
(define (rot2 l r a)
(if (empty? l)
(append* (rev r) a)
(cons* (head l)
(rot2 (tail l)
(drop c r)
(append* (rev (take c r)) a)))))
;;;; implementation
(define-record-type <deque>
(%make-deque length lenL lenR l r l^ r^)
deque?
(length deque-length)
(lenL deque-lenL)
(lenR deque-lenR)
(l deque-l)
(r deque-r)
(l^ deque-l^)
(r^ deque-r^))
(define-record-printer (<deque> record port)
(format port "#[deque]"))
(define (make-deque)
(%make-deque 0 0 0 '() '() '() '()))
(define* (deque-empty? deque)
(assert-argument-type __who__ "<deque>" deque? deque 1)
(zero? (deque-length deque)))
(define* (enqueue-front deque item)
(assert-argument-type __who__ "<deque>" deque? deque 1)
(let ((len (deque-length deque))
(l (deque-l deque))
(r (deque-r deque))
(lenL (deque-lenL deque))
(lenR (deque-lenR deque))
(l^ (deque-l^ deque))
(r^ (deque-r^ deque)))
(makedq (+ 1 len) (+ 1 lenL) lenR (cons* item l) r (tail l^) (tail r^))))
(define* (enqueue-rear deque item)
(assert-argument-type __who__ "<deque>" deque? deque 1)
(let ((len (deque-length deque))
(l (deque-l deque))
(r (deque-r deque))
(lenL (deque-lenL deque))
(lenR (deque-lenR deque))
(l^ (deque-l^ deque))
(r^ (deque-r^ deque)))
(makedq (+ 1 len) lenL (+ 1 lenR) l (cons* item r) (tail l^) (tail r^))))
(define* (dequeue-front deque)
(assert-argument-type __who__ "<deque>" deque? deque 1)
(assert-deque-not-empty __who__ deque)
(let ((len (deque-length deque))
(lenL (deque-lenL deque))
(lenR (deque-lenR deque))
(l (deque-l deque))
(r (deque-r deque))
(l^ (deque-l^ deque))
(r^ (deque-r^ deque)))
(if (empty? l)
(values (head r) (make-deque))
(values (head l)
(makedq (- len 1)
(- lenL 1)
lenR
(tail l)
r
(tail (tail l^))
(tail (tail r^)))))))
(define* (dequeue-rear deque)
(assert-argument-type __who__ "<deque>" deque? deque 1)
(assert-deque-not-empty __who__ deque)
(let ((len (deque-length deque))
(lenL (deque-lenL deque))
(lenR (deque-lenR deque))
(l (deque-l deque))
(r (deque-r deque))
(l^ (deque-l^ deque))
(r^ (deque-r^ deque)))
(if (empty? r)
(values (head l) (make-deque))
(values (head r)
(makedq (- len 1)
lenL
(- lenR 1)
l
(tail r)
(tail (tail l^))
(tail (tail r^)))))))
(define (makedq len lenL lenR l r l^ r^)
(cond ((> lenL (+ 1 (* c lenR)))
(let* ((n (floor (/ (+ lenL lenR) 2)))
(l* (take n l))
(r* (rot1 n r l)))
(%make-deque len n (- len n) l* r* l* r*)))
((> lenR (+ 1 (* c lenL)))
(let* ((n (floor (/ (+ lenL lenR) 2)))
(l* (rot1 n l r))
(r* (take n r)))
(%make-deque len (- len n) n l* r* l* r*)))
(else
(%make-deque len lenL lenR l r l^ r^))))
(define* (list->deque ell)
(assert-argument-type __who__ "<list>" list? ell 1)
(fold-left enqueue-rear (make-deque) ell))
(define* (deque->list deq)
(assert-argument-type __who__ "<deque>" deque? deq 1)
(define (recur deq l)
(if (deque-empty? deq)
l
(receive (last deq*)
(dequeue-rear deq)
(recur deq* (cons last l)))))
(recur deq '()))
;;;; exceptional conditions
(define deque-empty-condition?
(condition-predicate 'pfds-deque-empty-condition))
(define (assert-deque-not-empty who deque)
(when (deque-empty? deque)
(raise
(condition
`(exn location ,who
message "empty deque, there are no elements to remove"
arguments ,(list deque))
'(pfds-deque-empty-condition)))))
;;;; done
#| end of module |# )
;;; end of file
| false |
bf7a1ef411559df02da62dc281d4d0e31872d729
|
b30896ca57a43c4c788dbb89de6ffa32c5d29338
|
/layering-example.scm
|
689d223b4577e201ab8c8b0f15210a4060ae6993
|
[
"MIT"
] |
permissive
|
alokthapa/leftparen
|
1820b543fe28a15bd649f228bf8c17d88e5f7f62
|
dd0ac601763bf80ab4e21b4951d152553d26e189
|
refs/heads/master
| 2021-01-09T05:36:02.280732 | 2009-01-12T16:51:04 | 2009-01-12T16:51:04 | 120,912 | 1 | 0 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 822 |
scm
|
layering-example.scm
|
#lang scheme/base
(require scheme/unit)
(provide foo bar)
;; we want to be able to extend and have original library calls be able to call the
;; extended version.
;; the trick is to use a recursive unit. very cool.
(define-signature my-sig^ (foo bar))
(define-unit base-unit%
(import (prefix from-future: my-sig^))
(export my-sig^)
(define (foo)
(list "foo base" (from-future:bar)))
(define (bar)
"bar base")
)
(define-unit extension-unit%
(import (prefix base: my-sig^))
(export my-sig^)
(define foo base:foo)
(define (bar)
"bar extension")
)
(define-compound-unit merged-unit%
(import)
(export RESULT)
(link [((BASE : my-sig^)) base-unit% RESULT]
[((RESULT : my-sig^)) extension-unit% BASE]))
(define-values/invoke-unit merged-unit% (import) (export my-sig^))
| false |
906bddf303c394961718a712a4d443b21550c520
|
27b46612047e4f2b0a2d47b6c35a0078d4b16ee9
|
/examples/direct-lr-cps.scm
|
3a446039b59cd6fda56f4d8ec2b8ed64408175d2
|
[
"BSD-2-Clause"
] |
permissive
|
narslan/pgg
|
f709705861e3d6a6b46fd9519d3635d073fb2c28
|
620f6596e8791e4ea94103a5b8ace6a30aadc0a8
|
refs/heads/master
| 2023-06-10T15:01:42.934875 | 2012-12-31T15:09:37 | 2012-12-31T15:09:37 | null | 0 | 0 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 85 |
scm
|
direct-lr-cps.scm
|
(define-primitive eval (all t t) dynamic)
(define-primitive apply (all t t) dynamic)
| false |
78e035382e6f2feff40f9a9cb0e019574e0480bb
|
941acd91e0194a1df0b53a2ba44f32b50e19c789
|
/sitelib/ypsilon/gcrypt.scm
|
c306a4ab6278bd5c8dec327cf22c5224464f7198
|
[
"BSD-3-Clause"
] |
permissive
|
tabe/ypsilon-foreign-lib
|
03632198e36d23e6c2d3db4e75c314f3835ae39b
|
c2784da0f2bc52c64d30a9a6e5c57d6843edc80b
|
refs/heads/master
| 2021-01-01T16:34:21.727649 | 2010-03-08T10:51:34 | 2010-03-08T10:51:34 | null | 0 | 0 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 6,583 |
scm
|
gcrypt.scm
|
(library (ypsilon gcrypt)
(export GCRYCTL_SET_KEY
GCRYCTL_SET_IV
GCRYCTL_CFB_SYNC
GCRYCTL_RESET
GCRYCTL_FINALIZE
GCRYCTL_GET_KEYLEN
GCRYCTL_GET_BLKLEN
GCRYCTL_TEST_ALGO
GCRYCTL_IS_SECURE
GCRYCTL_GET_ASNOID
GCRYCTL_ENABLE_ALGO
GCRYCTL_DISABLE_ALGO
GCRYCTL_DUMP_RANDOM_STATS
GCRYCTL_DUMP_SECMEM_STATS
GCRYCTL_GET_ALGO_NPKEY
GCRYCTL_GET_ALGO_NSKEY
GCRYCTL_GET_ALGO_NSIGN
GCRYCTL_GET_ALGO_NENCR
GCRYCTL_SET_VERBOSITY
GCRYCTL_SET_DEBUG_FLAGS
GCRYCTL_CLEAR_DEBUG_FLAGS
GCRYCTL_USE_SECURE_RNDPOOL
GCRYCTL_DUMP_MEMORY_STATS
GCRYCTL_INIT_SECMEM
GCRYCTL_TERM_SECMEM
GCRYCTL_DISABLE_SECMEM_WARN
GCRYCTL_SUSPEND_SECMEM_WARN
GCRYCTL_RESUME_SECMEM_WARN
GCRYCTL_DROP_PRIVS
GCRYCTL_ENABLE_M_GUARD
GCRYCTL_START_DUMP
GCRYCTL_STOP_DUMP
GCRYCTL_GET_ALGO_USAGE
GCRYCTL_IS_ALGO_ENABLED
GCRYCTL_DISABLE_INTERNAL_LOCKING
GCRYCTL_DISABLE_SECMEM
GCRYCTL_INITIALIZATION_FINISHED
GCRYCTL_INITIALIZATION_FINISHED_P
GCRYCTL_ANY_INITIALIZATION_P
GCRYCTL_SET_CBC_CTS
GCRYCTL_SET_CBC_MAC
GCRYCTL_SET_CTR
GCRYCTL_ENABLE_QUICK_RANDOM
GCRYCTL_SET_RANDOM_SEED_FILE
GCRYCTL_UPDATE_RANDOM_SEED_FILE
GCRYCTL_SET_THREAD_CBS
GCRYCTL_FAST_POLL
GCRYCTL_SET_RANDOM_DAEMON_SOCKET
GCRYCTL_USE_RANDOM_DAEMON
GCRYCTL_FAKED_RANDOM_P
GCRYCTL_SET_RNDEGD_SOCKET
GCRYCTL_PRINT_CONFIG
GCRYCTL_OPERATIONAL_P
GCRYCTL_FIPS_MODE_P
GCRYCTL_FORCE_FIPS_MODE
GCRYCTL_SELFTEST
GCRY_MD_NONE
GCRY_MD_MD5
GCRY_MD_SHA1
GCRY_MD_RMD160
GCRY_MD_MD2
GCRY_MD_TIGER
GCRY_MD_HAVAL
GCRY_MD_SHA256
GCRY_MD_SHA384
GCRY_MD_SHA512
GCRY_MD_SHA224
GCRY_MD_MD4
GCRY_MD_CRC32
GCRY_MD_CRC32_RFC1510
GCRY_MD_CRC24_RFC2440
GCRY_MD_WHIRLPOOL
GCRY_MD_FLAG_SECURE
GCRY_MD_FLAG_HMAC
gcry_check_version
gcry_control
gcry_md_open
gcry_md_enable
gcry_md_setkey
gcry_md_close
gcry_md_reset
gcry_md_copy
gcry_md_write
gcry_md_putc
gcry_md_read
gcry_md_hash_buffer
)
(import (rnrs) (ypsilon ffi))
(define lib-name
(cond (on-linux "libgcrypt.so")
(on-sunos "libgcrypt.so")
(on-freebsd "libgcrypt.so")
(on-openbsd "libgcrypt.so")
(else
(assertion-violation #f "can not locate libgcrypt, unknown operating system"))))
(define lib (load-shared-object lib-name))
(define-syntax define-function
(syntax-rules ()
((_ ret name args)
(define name (c-function lib lib-name ret name args)))))
(define-c-enum
(GCRYCTL_SET_KEY . 1)
GCRYCTL_SET_IV
GCRYCTL_CFB_SYNC
GCRYCTL_RESET
GCRYCTL_FINALIZE
GCRYCTL_GET_KEYLEN
GCRYCTL_GET_BLKLEN
GCRYCTL_TEST_ALGO
GCRYCTL_IS_SECURE
GCRYCTL_GET_ASNOID
GCRYCTL_ENABLE_ALGO
GCRYCTL_DISABLE_ALGO
GCRYCTL_DUMP_RANDOM_STATS
GCRYCTL_DUMP_SECMEM_STATS
GCRYCTL_GET_ALGO_NPKEY
GCRYCTL_GET_ALGO_NSKEY
GCRYCTL_GET_ALGO_NSIGN
GCRYCTL_GET_ALGO_NENCR
GCRYCTL_SET_VERBOSITY
GCRYCTL_SET_DEBUG_FLAGS
GCRYCTL_CLEAR_DEBUG_FLAGS
GCRYCTL_USE_SECURE_RNDPOOL
GCRYCTL_DUMP_MEMORY_STATS
GCRYCTL_INIT_SECMEM
GCRYCTL_TERM_SECMEM
GCRYCTL_DISABLE_SECMEM_WARN
GCRYCTL_SUSPEND_SECMEM_WARN
GCRYCTL_RESUME_SECMEM_WARN
GCRYCTL_DROP_PRIVS
GCRYCTL_ENABLE_M_GUARD
GCRYCTL_START_DUMP
GCRYCTL_STOP_DUMP
GCRYCTL_GET_ALGO_USAGE
GCRYCTL_IS_ALGO_ENABLED
GCRYCTL_DISABLE_INTERNAL_LOCKING
GCRYCTL_DISABLE_SECMEM
GCRYCTL_INITIALIZATION_FINISHED
GCRYCTL_INITIALIZATION_FINISHED_P
GCRYCTL_ANY_INITIALIZATION_P
GCRYCTL_SET_CBC_CTS
GCRYCTL_SET_CBC_MAC
GCRYCTL_SET_CTR
GCRYCTL_ENABLE_QUICK_RANDOM
GCRYCTL_SET_RANDOM_SEED_FILE
GCRYCTL_UPDATE_RANDOM_SEED_FILE
GCRYCTL_SET_THREAD_CBS
GCRYCTL_FAST_POLL
GCRYCTL_SET_RANDOM_DAEMON_SOCKET
GCRYCTL_USE_RANDOM_DAEMON
GCRYCTL_FAKED_RANDOM_P
GCRYCTL_SET_RNDEGD_SOCKET
GCRYCTL_PRINT_CONFIG
GCRYCTL_OPERATIONAL_P
GCRYCTL_FIPS_MODE_P
GCRYCTL_FORCE_FIPS_MODE
GCRYCTL_SELFTEST
)
(define-c-enum
GCRY_MD_NONE
GCRY_MD_MD5
GCRY_MD_SHA1
GCRY_MD_RMD160
(GCRY_MD_MD2 . 5)
GCRY_MD_TIGER
GCRY_MD_HAVAL
GCRY_MD_SHA256
GCRY_MD_SHA384
GCRY_MD_SHA512
GCRY_MD_SHA224
(GCRY_MD_MD4 . 301)
GCRY_MD_CRC32
GCRY_MD_CRC32_RFC1510
GCRY_MD_CRC24_RFC2440
GCRY_MD_WHIRLPOOL
)
(define-c-enum
(GCRY_MD_FLAG_SECURE . 1)
GCRY_MD_FLAG_HMAC
)
;; const char * gcry_check_version (const char *req_version)
(define-function char* gcry_check_version (char*))
;; gcry_error_t gcry_control (enum gcry_ctl_cmds cmd, ...)
(define-function unsigned-int gcry_control (int ...))
;; gcry_error_t gcry_md_open (gcry_md_hd_t *hd, int algo, unsigned int flags)
(define-function unsigned-int gcry_md_open (void* int unsigned-int))
;; gcry_error_t gcry_md_enable (gcry_md_hd_t h, int algo)
(define-function unsigned-int gcry_md_enable (void* int))
;; gcry_error_t gcry_md_setkey (gcry_md_hd_t h, const void *key, size_t keylen)
(define-function unsigned-int gcry_md_setkey (void* void* size_t))
;; void gcry_md_close (gcry_md_hd_t h)
(define-function void gcry_md_close (void*))
;; void gcry_md_reset (gcry_md_hd_t h)
(define-function void gcry_md_reset (void*))
;; gcry_error_t gcry_md_copy (gcry_md_hd_t *handle_dst, gcry_md_hd_t handle_src)
(define-function unsigned-int gcry_md_copy (void* void*))
;; void gcry_md_write (gcry_md_hd_t h, const void *buffer, size_t length)
(define-function void gcry_md_write (void* void* size_t))
;; void gcry_md_putc (gcry_md_hd_t h, int c)
(define-function void gcry_md_putc (void* int))
;; unsigned char * gcry_md_read (gcry_md_hd_t h, int algo)
(define-function void* gcry_md_read (void* int))
;; void gcry_md_hash_buffer (int algo, void *digest, const void *buffer, size_t length)
(define-function void gcry_md_hash_buffer (int void* void* size_t))
)
| true |
c887c21c73bc07dee2819ea0813b32c408cb8e7e
|
ee232691dcbaededacb0778247f895af992442dd
|
/kirjasto/lib/kaava/python3.scm
|
a0c5060c1b2ff08446fecc1546653d9ee9ed6ee8
|
[] |
no_license
|
mytoh/panna
|
c68ac6c6ef6a6fe79559e568d7a8262a7d626f9f
|
c6a193085117d12a2ddf26090cacb1c434e3ebf9
|
refs/heads/master
| 2020-05-17T02:45:56.542815 | 2013-02-13T19:18:38 | 2013-02-13T19:18:38 | null | 0 | 0 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 310 |
scm
|
python3.scm
|
;;; -*- coding: utf-8 -*-
(use panna.kaava)
(kaava "python3")
(homepage "www.python.org")
(repository "http://hg.python.org/cpython")
(define (install tynnyri)
(system
`(./configure ,(string-append "--prefix=" tynnyri))
'(make)
'(make install)
'(make clean)
'(make distclean)
))
| false |
e626f82d42006549bb5ddd485fef4b8bee67a91d
|
6c6cf6e4b77640825c2457e54052a56d5de6f4d2
|
/ch3/3_71-ramanujan.scm
|
3c78b72e6a72b260bb9226955175ff59f29620ed
|
[] |
no_license
|
leonacwa/sicp
|
a469c7bc96e0c47e4658dccd7c5309350090a746
|
d880b482d8027b7111678eff8d1c848e156d5374
|
refs/heads/master
| 2018-12-28T07:20:30.118868 | 2015-02-07T16:40:10 | 2015-02-07T16:40:10 | 11,738,761 | 0 | 0 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 731 |
scm
|
3_71-ramanujan.scm
|
(define (ramanujan-weight p)
(let ((i (car p))
(j (cadr p)))
(let ((sum (+ (* i i i)
(* j j j))))
(+ (* sum sum)
(* i j)))))
(define (r-weight p)
(let ((i (car p))
(j (cadr p)))
(+ (* i i i)
(* j j j))))
(define (ramanujan-stream s show)
(if (stream-null? s)
the-empty-stream
;else
(let ((w1 (r-weight (stream-car s)))
(w2 (r-weight (stream-car (stream-cdr s)))))
(if (= w1 w2)
(if show
(cons-stream w1
(ramanujan-stream (stream-cdr (stream-cdr s)) false))
;else
(ramanujan-stream (stream-cdr (stream-cdr s)) true))
;else
(ramanujan-stream (stream-cdr s) true)))))
(define ramanujan (ramanujan-stream (weighted-pairs integers integers ramanujan-weight) true))
| false |
93943ebeaa84a5cec2d7a3e7bbebf67263bb6d00
|
defeada37d39bca09ef76f66f38683754c0a6aa0
|
/System/system/code-dom/code-namespace-import-collection.sls
|
df9ab8c6c5ea98d62f1db777f3e6026923c77f41
|
[] |
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,571 |
sls
|
code-namespace-import-collection.sls
|
(library (system code-dom code-namespace-import-collection)
(export new
is?
code-namespace-import-collection?
add-range
get-enumerator
add
clear
count
item-get
item-set!
item-update!)
(import (ironscheme-clr-port))
(define-syntax new
(lambda (e)
(syntax-case e ()
((_ a ...)
#'(clr-new
System.CodeDom.CodeNamespaceImportCollection
a
...)))))
(define (is? a)
(clr-is System.CodeDom.CodeNamespaceImportCollection a))
(define (code-namespace-import-collection? a)
(clr-is System.CodeDom.CodeNamespaceImportCollection a))
(define-method-port
add-range
System.CodeDom.CodeNamespaceImportCollection
AddRange
(System.Void System.CodeDom.CodeNamespaceImport[]))
(define-method-port
get-enumerator
System.CodeDom.CodeNamespaceImportCollection
GetEnumerator
(System.Collections.IEnumerator))
(define-method-port
add
System.CodeDom.CodeNamespaceImportCollection
Add
(System.Void System.CodeDom.CodeNamespaceImport))
(define-method-port
clear
System.CodeDom.CodeNamespaceImportCollection
Clear
(System.Void))
(define-field-port
count
#f
#f
(property:)
System.CodeDom.CodeNamespaceImportCollection
Count
System.Int32)
(define-field-port
item-get
item-set!
item-update!
(property:)
System.CodeDom.CodeNamespaceImportCollection
Item
System.CodeDom.CodeNamespaceImport))
| true |
1d9c033a4be3ea2751eb4017583af82f235306e1
|
1faa631fa173707f8482a6d05548b9c483ca5d99
|
/libdir/chez-future.ss
|
bd8fb9a5d184cd15580f03d74992e79d7b90b05d
|
[
"Apache-2.0"
] |
permissive
|
localchart/exercises
|
4d02f65ff40a27c08edb408cf0e2c5ca467b7358
|
2aad9d25040774c43c31acac6f0bd5af3447e5a7
|
refs/heads/master
| 2021-01-01T03:57:24.138974 | 2016-12-29T02:26:29 | 2016-12-29T02:26:29 | 58,983,223 | 0 | 0 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 682 |
ss
|
chez-future.ss
|
(define-record fitem (result ready mutex cond))
(define future
(lambda (thunk)
(let ([item (make-fitem #f #f (make-mutex) (make-condition))])
(fork-thread
(lambda ()
(let ([result (thunk)])
(with-mutex (fitem-mutex item)
(set-fitem-result! item result)
(set-fitem-ready! item #t)
(condition-broadcast (fitem-cond item))))))
item)))
(define touch
(lambda (item)
(let ([mutex (fitem-mutex item)])
(with-mutex mutex
(let loop ()
(when (not (fitem-ready item))
(condition-wait (fitem-cond item) mutex)
(loop)))
(fitem-result item)))))
| false |
3d7c1678ec202cd4986cece968942c41dad05632
|
fe0de995a95bcf09cd447349269dc0e550851b5a
|
/tests/0013-callcc-2.program.scm
|
d9cdb62174afb14dfe1aeee3741dfb56ec4ad7b1
|
[
"MIT"
] |
permissive
|
mugcake/ruse-scheme
|
4974021858be5b7f2421212ec2eeafd34c53bce8
|
dd480e17edd9a233fd2bc4e8b41ff45d13fcc328
|
refs/heads/master
| 2022-02-12T04:31:55.031607 | 2019-08-01T21:44:14 | 2019-08-01T21:44:14 | null | 0 | 0 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 32 |
scm
|
0013-callcc-2.program.scm
|
(call/cc
(lambda (cont) 0 42))
| false |
feaf47abe780942e43bf8c9d2cc44566fb715923
|
d51c8c57288cacf9be97d41079acc7c9381ed95a
|
/scsh/test/terminal-device-control-test.scm
|
80cefdd125e443fc810e6acba2b35ad7e9fb8d61
|
[] |
no_license
|
yarec/svm
|
f926315fa5906bd7670ef77f60b7ef8083b87860
|
d99fa4d3d8ecee1353b1a6e9245d40b60f98db2d
|
refs/heads/master
| 2020-12-13T08:48:13.540156 | 2020-05-04T06:42:04 | 2020-05-04T06:42:04 | 19,306,837 | 2 | 0 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 7,269 |
scm
|
terminal-device-control-test.scm
|
;;; Test for the function in section 3.12 of the scsh-manual "Terminal device control"
;;; Author: Christoph Hetz
;; for testing: (certainly the path will be an other on other systems...)
;; ,open define-record-types handle
;; ,config ,load C:/cygwin/home/mephisto/cvs-scsh/scsh/scsh/test/test-packages.scm
;; ,load C:/cygwin/home/mephisto/cvs-scsh/scsh/scsh/test/test-base.scm
;; load this file
;; (test-all)
(add-test! 'tty-info-record-test 'terminal-devive-control
(lambda ()
(let ((ti (tty-info)))
(and (string? (tty-info:control-chars ti))
(or (integer? (tty-info:input-flags ti))
(not (tty-info:input-flags ti)))
(or (integer? (tty-info:output-flags ti))
(not (tty-info:output-flags ti)))
(or (integer? (tty-info:control-flags ti))
(not (tty-info:control-flags ti)))
(or (integer? (tty-info:local-flags ti))
(not (tty-info:local-flags ti)))
(or (or (integer? (tty-info:input-speed ti))
(memq (tty-info:input-speed ti) '(exta extb)))
(not (tty-info:input-speed ti)))
(or (or (integer? (tty-info:output-speed ti))
(memq (tty-info:output-speed ti) '(exta extb)))
(not (tty-info:output-speed ti)))
(or (integer? (tty-info:min ti))
(not (tty-info:min ti)))
(or (integer? (tty-info:time ti))
(not(tty-info:time ti)))))))
(add-test! 'make-tty-info-test 'terminal-device-control
(lambda ()
(let* ((in-fl 770)
(out-fl 3)
(c-fl 19200)
(loc-fl 1482)
(in-spd 1200)
(out-spd 1200)
(min 1)
(time 0)
(ti (make-tty-info in-fl
out-fl
c-fl
loc-fl
in-spd
out-spd
min
time)))
(and (= in-fl
(tty-info:input-flags ti))
(= out-fl
(tty-info:output-flags ti))
(= c-fl
(tty-info:control-flags ti))
(= in-spd
(tty-info:input-speed ti))
(= out-spd
(tty-info:output-speed ti))
(= min
(tty-info:min ti))
(= time
(tty-info:time ti))))))
(add-test! 'copy-tty-test 'terminal-device-control
(lambda ()
(let* ((ti (tty-info))
(ti-c (copy-tty-info ti)))
(and (tty-info? ti)
(tty-info? ti-c)
(equal? (tty-info:control-chars ti)
(tty-info:control-chars ti-c))
(= (tty-info:input-flags ti)
(tty-info:input-flags ti-c))
(= (tty-info:output-flags ti)
(tty-info:output-flags ti-c))
(= (tty-info:control-flags ti)
(tty-info:control-flags ti-c))
(= (tty-info:local-flags ti)
(tty-info:local-flags ti-c))
(equal? (tty-info:input-speed ti)
(tty-info:input-speed ti-c))
(equal? (tty-info:output-speed ti)
(tty-info:output-speed ti-c))
(= (tty-info:min ti)
(tty-info:min ti-c))
(= (tty-info:time ti)
(tty-info:time ti-c))))))
(add-test! 'tty-info-record-posix-indicies-test 'terminal-device-control
(lambda ()
(and ttychar/delete-char
ttychar/delete-line
ttychar/eof
ttychar/eol
ttychar/interrupt
ttychar/quit
ttychar/suspend
ttychar/start
ttychar/stop)))
(add-test! 'tty-info-record-posix-input-flags 'terminal-device-control
(lambda ()
(and ttyin/check-parity
ttyin/ignore-bad-parity-chars
ttyin/mark-parity-errors
ttyin/ignore-break
ttyin/interrupt-on-break
ttyin/7bits
ttyin/cr->nl
ttyin/ignore-cr
ttyin/nl->cr
ttyin/input-flow-ctl
ttyin/output-flow-ctl)))
(add-test! 'tty-info-record-posix-output-flags 'terminal-device-control
(lambda ()
ttyout/enable))
(add-test! 'tty-info-record-delay-constants-for-output-flags 'terminal-device-control
(lambda ()
(or (and ttyout/bs-delay
ttyout/bs-delay0
ttyout/bs-delay1
ttyout/cr-delay
ttyout/cr-delay0
ttyout/cr-delay1
ttyout/cr-delay2
ttyout/cr-delay3
ttyout/ff-delay
ttyout/ff-delay0
ttyout/ff-delay1
ttyout/tab-delay
ttyout/tab-delay0
ttyout/tab-delay1
ttyout/tab-delay2
ttyout/tab-delayx
ttyout/nl-delay
ttyout/nl-delay0
ttyout/nl-delay1
ttyout/vtab-delay
ttyout/vtab-delay0
ttyout/vtab-delay1
ttyout/all-delay)
(not (and ttyout/bs-delay
ttyout/bs-delay0
ttyout/bs-delay1
ttyout/cr-delay
ttyout/cr-delay0
ttyout/cr-delay1
ttyout/cr-delay2
ttyout/cr-delay3
ttyout/ff-delay
ttyout/ff-delay0
ttyout/ff-delay1
ttyout/tab-delay
ttyout/tab-delay0
ttyout/tab-delay1
ttyout/tab-delay2
ttyout/tab-delayx
ttyout/nl-delay
ttyout/nl-delay0
ttyout/nl-delay1
ttyout/vtab-delay
ttyout/vtab-delay0
ttyout/vtab-delay1
ttyout/all-delay)))))
(add-test! 'tty-info-record-posix-control-flags 'terminal-device-control
(lambda ()
(and ttyc/char-size
ttyc/char-size5
ttyc/char-size6
ttyc/char-size7
ttyc/char-size8
ttyc/enable-parity
ttyc/odd-parity
ttyc/enable-read
ttyc/hup-on-close
ttyc/no-modem-sync
ttyc/2-stop-bits)))
(add-test! 'tty-info-record-4.3+bsd-control-flags 'terminal-device-control
(lambda ()
(or (and ttyc/ignore-flags
ttyc/CTS-output-flow-ctl
ttyc/RTS-input-flow-ctl
ttyc/carrier-flow-ctl)
(not (and ttyc/ignore-flags
ttyc/CTS-output-flow-ctl
ttyc/RTS-input-flow-ctl
ttyc/carrier-flow-ctl)))))
(add-test! 'tty-info-record-posix-local-flags 'terminal-device-control
(lambda ()
(and ttyl/canonical
ttyl/echo
ttyl/echo-delete-line
ttyl/echo-nl
ttyl/visual-delete
ttyl/enable-signals
ttyl/extended
ttyl/no-flush-on-interrupt
ttyl/ttou-signal)))
(add-test! 'tty-info-record-svr4&4.3+bsd-local-flags 'terminal-device-control
(lambda ()
(or (and ttyl/echo-ctl
ttyl/flush-output
ttyl/hardcopy-delete
ttyl/reprint-unread-chars
ttyl/visual-delete-line
ttyl/alt-delete-word
ttyl/no-kernel-status
ttyl/case-map)
(not (and ttyl/echo-ctl
ttyl/flush-output
ttyl/hardcopy-delete
ttyl/reprint-unread-chars
ttyl/visual-delete-line
ttyl/alt-delete-word
ttyl/no-kernel-status
ttyl/case-map)))))
(add-test! 'open-pty-test 'terminal-device-control
(lambda ()
(receive (pty-inport tty-name) (open-pty)
(let ((tty-in (open-input-file tty-name)))
(let ((pty-out (dup->outport pty-inport)))
(write 23 pty-out)
(newline pty-out)
(let ((res (equal? 23 (read tty-in))))
(close-output-port pty-out) ;; necessary on some systems for proper exit
res))))))
;; fails on Solaris because local echo is not turned off
(add-test! 'fork-pty-session 'terminal-device-control
(lambda ()
(receive (process pty-in pty-out tty-name)
(fork-pty-session (lambda ()
(let ((inp (read)))
(write (string-append inp inp)))
(newline)))
(let ((ti (copy-tty-info (tty-info pty-out))))
(set-tty-info:local-flags ti
(bitwise-xor ttyl/echo (tty-info:local-flags ti)))
(set-tty-info/now pty-out ti))
(write "hello" pty-out)
(newline pty-out)
(let ((reply (read pty-in)))
(close-output-port pty-out) ;; necessary on some systems for proper exit
(string=? "hellohello" reply)))))
| false |
c770080099d6d2c70fca43f04572e363d6175598
|
d074b9a2169d667227f0642c76d332c6d517f1ba
|
/sicp/ch_4/exercise.4.67.scm
|
a640b6c7aa679a7c976ee657e8f94b54a43d6564
|
[] |
no_license
|
zenspider/schemers
|
4d0390553dda5f46bd486d146ad5eac0ba74cbb4
|
2939ca553ac79013a4c3aaaec812c1bad3933b16
|
refs/heads/master
| 2020-12-02T18:27:37.261206 | 2019-07-14T15:27:42 | 2019-07-14T15:27:42 | 26,163,837 | 7 | 0 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 704 |
scm
|
exercise.4.67.scm
|
#!/usr/bin/env csi -s
(require rackunit)
;;; Exercise 4.67
;; Devise a way to install a loop detector in the
;; query system so as to avoid the kinds of simple loops illustrated
;; in the text and in *Note Exercise 4-64::. The general idea is that
;; the system should maintain some sort of history of its current
;; chain of deductions and should not begin processing a query that
;; it is already working on. Describe what kind of information
;; (patterns and frames) is included in this history, and how the
;; check should be made. (After you study the details of the
;; query-system implementation in section *Note 4-4-4::, you may want
;; to modify the system to include your loop detector.)
| false |
1e703fca69b76c83095e0008f4760f5374b16c68
|
09064c6952d82d4e0ca1480524c49aaad213d90a
|
/chez-iup-scintilla.sls
|
1ef17c333e1ca2b1cd3642e5b9f3bdac5bb69bf9
|
[
"MIT"
] |
permissive
|
vidjuheffex/chez-iup
|
7b269739ce74a8cc254a997ea8bfa06fcd705233
|
82396d7a27e074e27e9f403d0cd874aecd074b23
|
refs/heads/master
| 2022-11-09T09:42:56.569754 | 2020-07-01T05:31:08 | 2020-07-01T05:31:08 | 269,530,945 | 1 | 0 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 561 |
sls
|
chez-iup-scintilla.sls
|
(library (iup-scintilla)
(export
iup-scintilla-open
iup-scintilla
iup-scintilla-dialog)
(import (chezscheme))
(define lib-iup-scintilla (load-shared-object "libiup_scintilla.so"))
(define-syntax define-function
(syntax-rules ()
((_ ret name fpname args)
(define name
(foreign-procedure (symbol->string 'fpname) args ret)))))
(define-function void* iup-scintilla IupScintilla ())
(define-function void* iup-scintilla-dialog IupScintillaDlg ())
(define-function void iup-scintilla-open IupScintillaOpen ()))
| true |
153056d6f7ee86c03cee6eef024151e8c3c6674e
|
f4aeaa0812ac15d5a8d2cb6da75ac335c3cf5cf4
|
/t/t2.scm
|
990a60cef2e2790f7dbf4c465304e3b429b384b1
|
[
"MIT"
] |
permissive
|
orchid-hybrid/microKanren-sagittarius
|
13f7916f8ef7c946cefeb87e9e52d6d4a5dfe6c9
|
9e740bbf94ed2930f88bbcf32636d3480934cfbb
|
refs/heads/master
| 2021-01-13T01:54:20.589391 | 2015-06-13T12:40:14 | 2015-06-13T12:40:14 | 29,868,626 | 12 | 4 | null | 2015-02-12T07:11:25 | 2015-01-26T16:01:10 |
Scheme
|
UTF-8
|
Scheme
| false | false | 1,465 |
scm
|
t2.scm
|
(import (scheme base)
(test-check)
(miruKanren micro)
(miruKanren mini)
(miruKanren run)
(miruKanren eqeq))
(test-check "== #1"
(run* (lambda (q)
(== q 'yes)))
'((yes where)))
(test-check "== #2"
(run* (lambda (q)
(fresh ()
(== q 'yes)
(== q 'no))))
'())
(test-check "== #3"
(run* (lambda (q)
(fresh (x y)
(== q (cons x y))
(== x 'yes)
(== y 'no))))
'(((yes . no) where)))
(test-check "==/occurs-check #4"
(run* (lambda (q)
(== q (cons q q))))
'())
(test-check "==/conde #1"
(run* (lambda (q)
(conde
((== q 'yes))
((== q 'no)))))
'((yes where)
(no where)))
(test-check "==/conde #2"
(run* (lambda (q)
(fresh (x y)
(== q (cons x y))
(conde
((== x 'yes))
((== x 'no)))
(conde
((== y 'foo))
((== y 'bar))))))
'(((yes . foo) where)
((yes . bar) where)
((no . foo) where)
((no . bar) where)))
| false |
2097adeee59b0f08b1815a0dbbd1997bea124bfa
|
958488bc7f3c2044206e0358e56d7690b6ae696c
|
/scheme/execl.scm
|
5c82ba3136a7427f318d14a6325c3a4d71e1bfd6
|
[] |
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 | 3,275 |
scm
|
execl.scm
|
; example of code using 'execl' and 'fork'
; made unnecessary by the existence of 'system'
; wrapper around execl to execute linux command 'rm -f filename'
(define (cleanUpFile filename)
(let ((pid (fork)))
(if (= 0 pid)
(begin ; child process
(execl "/bin/rm" "/bin/rm" "-f" filename)
(exit 1)) ; does not return from execve unless failure
(begin ; parent process
(let ((status (waitpid pid 0))) ; waiting for child to complete
(if (not (= 0 status)) ; child failed
(begin
(display "Failed to remove ")
(display filename)
(newline)
(exit 1))))))))
; wrapper around execl to execute command 'javac -classpath acm.jar filename'
(define (compileFile filename)
(let ((pid (fork)))
(if (= 0 pid)
(begin ; child process
(execl "/usr/bin/javac" "/usr/bin/javac" "-classpath" "acm.jar" filename)
(exit 1)) ; does not return from execve unless failure
(begin ; parent process
(let ((status (waitpid pid 0))) ; waiting for child to complete
(if (not (= 0 status)) ; child failed
(begin
(display "Failed to compile ")
(display filename)
(newline)
(exit 1))))))))
; wrapper around execl to execute command 'cp acm.jar filename.jar'
(define (copyAcmAsFile filename)
(let ((pid (fork)))
(if (= 0 pid)
(begin ; child process
(execl "/bin/cp" "/bin/cp" "acm.jar" filename)
(exit 1)) ; does not return from execve unless failure
(begin ; parent process
(let ((status (waitpid pid 0))) ; waiting for child to complete
(if (not (= 0 status)) ; child failed
(begin
(display "Failed to copy acm.jar as ")
(display filename)
(newline)
(exit 1))))))))
; wrapper around execl to execute command 'jar uf filename.jar filename.class'
(define (addToJarFile filename-jar filename-class)
(let ((pid (fork)))
(if (= 0 pid)
(begin ; child process
(execl "/usr/bin/jar" "/user/bin/jar" "uf" filename-jar filename-class)
(exit 1)) ; does not return from execve unless failure
(begin ; parent process
(let ((status (waitpid pid 0))) ; waiting for child to complete
(if (not (= 0 status)) ; child failed
(begin
(display "Failed to add ")
(display filename-class)
(display " to ")
(display filename-jar)
(newline)
(exit 1))))))))
; wrapper around execl to execute linux command 'appletviewer filename.html'
(define (launchApplet filename)
(let ((pid (fork)))
(if (= 0 pid)
(begin ; child process
(execl "/usr/bin/appletviewer" "/usr/bin/appletviewer" filename)
(exit 1)) ; does not return from execve unless failure
(begin ; parent process
(let ((status (waitpid pid 0))) ; waiting for child to complete
(if (not (= 0 status)) ; child failed
(begin
(display "Failed to launch applet ")
(display filename)
(newline)
(exit 1))))))))
| false |
2397f6c6b48bb39c00d2c4654b87a3ab10481ffe
|
f64f5a8f22d6eae00d4d50d899fdecb65a8539dc
|
/srfi/srfi-27/srfi-27-a.scm
|
9a284088dfd8fa1ffca99030ec98335462a0742c
|
[
"BSD-3-Clause"
] |
permissive
|
sethalves/snow2-client
|
79907fe07c218d21c4d60f1787a22e8bfea062f9
|
b70c3ca5522a666a71a4c8992f771d5faaceccd6
|
refs/heads/master
| 2021-05-16T02:08:21.326561 | 2019-03-18T02:44:11 | 2019-03-18T02:44:11 | 11,485,062 | 16 | 3 |
BSD-3-Clause
| 2018-08-14T16:37:09 | 2013-07-17T19:13:22 |
Scheme
|
UTF-8
|
Scheme
| false | false | 1,348 |
scm
|
srfi-27-a.scm
|
; MODULE DEFINITION FOR SRFI-27
; =============================
;
; [email protected], Mar-2002, in Scheme 48 0.57
;
; This file contains the top-level definition for the 54-bit integer-only
; implementation of SRFI-27 for the Scheme 48 0.57 system.
;
; 1. The core generator is implemented in 'mrg32k3a-a.scm'.
; 2. The generic parts of the interface are in 'mrg32k3a.scm'.
; 3. The non-generic parts (record type, time, error) are here.
;
; creating the module:
; ,config ,load srfi-27-a.scm
;
; loading the module, once created:
; ,open srfi-27
;
; history of this file:
; SE, 22-Mar-2002: initial version
; SE, 27-Mar-2002: checked again
;; (open
;; scheme-level-1
;; (subset srfi-9 (define-record-type))
;; (subset srfi-23 (error))
;; (subset posix-time (current-time))
;; (subset posix (time-seconds)))
(define-record-type :random-source
(:random-source-make
state-ref
state-set!
randomize!
pseudo-randomize!
make-integers
make-reals)
:random-source?
(state-ref :random-source-state-ref)
(state-set! :random-source-state-set!)
(randomize! :random-source-randomize!)
(pseudo-randomize! :random-source-pseudo-randomize!)
(make-integers :random-source-make-integers)
(make-reals :random-source-make-reals))
(define (:random-source-current-time)
(exact (round (current-second))))
| false |
5c02cefccfdf5a8bffd5ad616bffab83aaa62a60
|
daad090dd655bec07a9a6d54ade3e5ed7045f68a
|
/hw7/save_continuation.scm
|
8fc9c30bc567a34ca709e0243544be42a3269d03
|
[] |
no_license
|
lukemvu/cs450
|
3482cac68cf4d080048fd015861318665985717e
|
e02a924052886302eb12519702cba980d0fa283b
|
refs/heads/master
| 2023-03-22T15:34:11.487946 | 2021-03-16T17:22:24 | 2021-03-16T17:22:24 | 348,432,607 | 0 | 1 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 1,028 |
scm
|
save_continuation.scm
|
(define call/cc call-with-current-continuation)
(define target '())
;;; Define a procedure which needs to escape. Use the target to tell
;;; it where to escape to.
(define (f x)
(cond ((= x 0)
(display "0 entered; try again.")
(newline)
(target x)) ;;; the argument x will be ignored.
(else
(display "Success: ")
(display x)
(newline))
)
)
;;; Define the calling routine, which in turn defines the target.
(define (main_loop)
(call/cc
(lambda(here)
(set! target here)))
(display "Type a number different from 0: ")
(let ((n (read)))
;; First check to make sure that a number was entered.
(if (not (number? n))
(begin
(display n)
(display " is not a number; try again.")
(newline)
(target n) ;;; the argument n will be ignored.
)
)
;; OK; a number was entered. Now call f to do the rest of the
;; processing.
(f n)
)
(main_loop)
)
(main_loop)
| false |
81ad77c5098e76e2a991de09eb19907578b10e03
|
c9a2cb859ab0a460f6c5519fce0422cbf9da9374
|
/shapefile/shx.scm
|
438a4772f00dbe3efa1ab5ade9a265a0f28a7c1b
|
[
"MIT"
] |
permissive
|
HugoNikanor/guile-shapefile
|
f34d349bce62652e5a92ca6df01f472289414e86
|
4963752d8d052094ed5c6769fad0aa10670d74f9
|
refs/heads/master
| 2023-07-07T01:08:41.070277 | 2022-02-15T21:58:04 | 2022-02-15T21:58:04 | 325,540,289 | 4 | 1 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 706 |
scm
|
shx.scm
|
(define-module (shapefile shx)
:use-module ((shapefile internal shp-header)
:select (parse-header shp-header-length))
:use-module (rnrs bytevectors)
:use-module (rnrs io ports)
:use-module ((srfi srfi-1) :select (iota))
:export (parse-shx-file)
)
;; mostly here for completeness
(define (parse-shx-file port)
(define header (parse-header (get-bytevector-n port 100)))
(define data (get-bytevector-n port (- (shp-header-length header) 100)))
(map (lambda (i)
(cons (bytevector-sint-ref data i (endianness big) 4)
(bytevector-sint-ref data (+ i 4) (endianness big) 4)))
(iota (/ (- (shp-header-length header) 100) 8)
0 8)))
| false |
aaf2d93e7c4afc6840cf328f42230ad60188b4d7
|
b780251bb60ae41f158cff824973c5dba9f3288d
|
/lambda-target.scm
|
9bb57ad8a0f8046d3102fe4f5d6aa0836424c8fd
|
[] |
no_license
|
drewt/Church
|
2bb742bf37cbe4c95e1386b87dcfe197d5fe4d9d
|
90b32d12bf65684665b4d87f744ee4ded63418e6
|
refs/heads/master
| 2020-06-02T09:08:06.236411 | 2014-04-19T00:58:40 | 2014-04-19T01:10:03 | 18,859,972 | 0 | 0 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 2,140 |
scm
|
lambda-target.scm
|
;;
;; Lambda calculus target. Takes a lambda AST back to its representation in
;; (shorthand) lambda calculus.
;;
(declare (unit lambda-target)
(uses lambda-ast)
(export *lambda-target*))
(define-syntax parenthesize
(syntax-rules ()
((parenthesize expr)
(begin (display #\()
expr
(display #\))))))
(define (compile-type type out)
(cond
((base-type? type)
(display (type-param type) out))
((base-type? (type-param type))
(compile-type (type-param type) out)
(display #\u2192 out)
(compile-type (type-return type) out))
(else
(parenthesize (compile-type (type-param type) out))
(display #\u2192 out)
(compile-type (type-return type) out))))
(define (compile-variable var out)
(let ((name (variable-name var))
(type (variable-type var)))
(display name out)
(when type
(display #\: out)
(compile-type type out))))
(define (compile-abstraction fun out)
(define (compile-subabstraction fun out)
(lambda-compile (abstraction-variable fun) out)
(let ((body (abstraction-body fun)))
(if (abstraction? body)
(begin (display #\, out)
(compile-subabstraction body out))
(begin (display #\. out)
(lambda-compile body out)))))
(display #\u03bb out)
(compile-subabstraction fun out))
(define (compile-application ast out)
(let ((fun (application-function ast))
(arg (application-argument ast)))
(when (abstraction? fun)
(display #\())
(lambda-compile fun out)
(when (abstraction? fun)
(display #\)))
(when (not (variable? arg))
(display #\())
(lambda-compile arg out)
(when (not (variable? arg))
(display #\)))))
(define (lambda-compile ast out)
(cond
((variable? ast) (compile-variable ast out))
((abstraction? ast) (compile-abstraction ast out))
((application? ast) (compile-application ast out))
(else (fprintf (current-error-port)
"ERROR: unexpected value: ~a~n" ast))))
(define *lambda-target*
(make-compiler-target lambda-compile))
| true |
f73d4540c273bdd8ad89ca2f22e8782c29943939
|
defeada37d39bca09ef76f66f38683754c0a6aa0
|
/mscorlib/system/reflection/event-info.sls
|
b1919061fa684f2c5fd6cbd89ecf6e8aef4311d6
|
[] |
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,269 |
sls
|
event-info.sls
|
(library (system reflection event-info)
(export is?
event-info?
get-remove-method
get-other-methods
get-add-method
remove-event-handler
get-raise-method
add-event-handler
attributes
event-handler-type
is-multicast?
is-special-name?
member-type)
(import (ironscheme-clr-port))
(define (is? a) (clr-is System.Reflection.EventInfo a))
(define (event-info? a) (clr-is System.Reflection.EventInfo a))
(define-method-port
get-remove-method
System.Reflection.EventInfo
GetRemoveMethod
(System.Reflection.MethodInfo System.Boolean)
(System.Reflection.MethodInfo))
(define-method-port
get-other-methods
System.Reflection.EventInfo
GetOtherMethods
(System.Reflection.MethodInfo[])
(System.Reflection.MethodInfo[] System.Boolean))
(define-method-port
get-add-method
System.Reflection.EventInfo
GetAddMethod
(System.Reflection.MethodInfo System.Boolean)
(System.Reflection.MethodInfo))
(define-method-port
remove-event-handler
System.Reflection.EventInfo
RemoveEventHandler
(System.Void System.Object System.Delegate))
(define-method-port
get-raise-method
System.Reflection.EventInfo
GetRaiseMethod
(System.Reflection.MethodInfo System.Boolean)
(System.Reflection.MethodInfo))
(define-method-port
add-event-handler
System.Reflection.EventInfo
AddEventHandler
(System.Void System.Object System.Delegate))
(define-field-port
attributes
#f
#f
(property:)
System.Reflection.EventInfo
Attributes
System.Reflection.EventAttributes)
(define-field-port
event-handler-type
#f
#f
(property:)
System.Reflection.EventInfo
EventHandlerType
System.Type)
(define-field-port
is-multicast?
#f
#f
(property:)
System.Reflection.EventInfo
IsMulticast
System.Boolean)
(define-field-port
is-special-name?
#f
#f
(property:)
System.Reflection.EventInfo
IsSpecialName
System.Boolean)
(define-field-port
member-type
#f
#f
(property:)
System.Reflection.EventInfo
MemberType
System.Reflection.MemberTypes))
| false |
8921f7c67c435b35a03f4c7538a6e12f5dbbf7b8
|
b26941aa4aa8da67b4a7596cc037b92981621902
|
/SICP/test.scm
|
8146120fe74a7953306163166a1979bb10cadabe
|
[] |
no_license
|
Alaya-in-Matrix/scheme
|
a1878ec0f21315d5077ca1c254c3b9eb4c594c10
|
bdcfcf3367b664896e8a7c6dfa0257622493e184
|
refs/heads/master
| 2021-01-01T19:42:32.633019 | 2015-01-31T08:24:02 | 2015-01-31T08:24:02 | 22,753,765 | 0 | 0 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 349 |
scm
|
test.scm
|
(load "sicp.scm")
(install)
(define x1
(make-scheme-number 0))
(define x2
(make-scheme-number 1))
(define r1
(make-rational 0 1))
(define r2
(make-rational 3 3))
(define re1
(make-real 0))
(define re2
(make-real (sqrt 3)))
(define z1
(make-complex-from-real-imag 0 0))
(define z2
(make-complex-from-real-imag 1 1))
| false |
84116183982d0cc1e4a09f7bfc41d6aa9a413635
|
defeada37d39bca09ef76f66f38683754c0a6aa0
|
/mscorlib/system/security/cryptography/dsa.sls
|
5a67b881545157bb90eeb548e23e306692f3b883
|
[] |
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,479 |
sls
|
dsa.sls
|
(library (system security cryptography dsa)
(export is?
dsa?
from-xml-string
verify-signature?
create
import-parameters
create-signature
to-xml-string
export-parameters)
(import (ironscheme-clr-port))
(define (is? a) (clr-is System.Security.Cryptography.DSA a))
(define (dsa? a) (clr-is System.Security.Cryptography.DSA a))
(define-method-port
from-xml-string
System.Security.Cryptography.DSA
FromXmlString
(System.Void System.String))
(define-method-port
verify-signature?
System.Security.Cryptography.DSA
VerifySignature
(System.Boolean System.Byte[] System.Byte[]))
(define-method-port
create
System.Security.Cryptography.DSA
Create
(static: System.Security.Cryptography.DSA System.String)
(static: System.Security.Cryptography.DSA))
(define-method-port
import-parameters
System.Security.Cryptography.DSA
ImportParameters
(System.Void System.Security.Cryptography.DSAParameters))
(define-method-port
create-signature
System.Security.Cryptography.DSA
CreateSignature
(System.Byte[] System.Byte[]))
(define-method-port
to-xml-string
System.Security.Cryptography.DSA
ToXmlString
(System.String System.Boolean))
(define-method-port
export-parameters
System.Security.Cryptography.DSA
ExportParameters
(System.Security.Cryptography.DSAParameters System.Boolean)))
| false |
0f7aba354ce9f34b711d28c6c1debf80653fd729
|
ae4938300d7eea07cbcb32ea4a7b0ead9ac18e82
|
/match/basic.sls
|
7b5fbb2c5b22733d451895902fd7c5387f6a4904
|
[] |
no_license
|
keenbug/imi-libs
|
05eb294190be6f612d5020d510e194392e268421
|
b78a238f03f31e10420ea27c3ea67c077ea951bc
|
refs/heads/master
| 2021-01-01T19:19:45.036035 | 2012-03-04T21:46:28 | 2012-03-04T21:46:28 | 1,900,111 | 0 | 1 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 1,420 |
sls
|
basic.sls
|
#!r6rs
(library (imi match basic)
(export basic-matcher
basic-matcher*)
(import (rnrs))
(define (basic-matcher pattern)
(basic-matcher* pattern basic-matcher*))
(define (basic-matcher* pattern matcher)
(cond
[(procedure? pattern)
(pattern matcher)]
[(pair? pattern)
(pair-matcher pattern matcher)]
[(vector? pattern)
(vector-matcher pattern matcher)]
[(symbol? pattern)
(symbol-matcher pattern matcher)]
[else
(equal-matcher pattern matcher)]))
(define (pair-matcher pattern matcher)
(let ([match-car (matcher (car pattern) matcher)]
[match-cdr (matcher (cdr pattern) matcher)])
(lambda (expr)
(and (pair? expr)
(let ([mcar (match-car (car expr))]
[mcdr (match-cdr (cdr expr))])
(and mcar
mcdr
(append (match-car (car expr))
(match-cdr (cdr expr)))))))))
(define (vector-matcher pattern matcher)
(let ([match-list (matcher (vector->list pattern) matcher)])
(lambda (expr)
(and (vector? expr)
(match-list (vector->list expr))))))
(define (symbol-matcher pattern matcher)
(lambda (expr)
(list (cons pattern expr))))
(define (equal-matcher pattern matcher)
(lambda (expr)
(and (equal? expr pattern)
'())))
)
| false |
19ea055bbde95d1d70584fe133b50162312c2045
|
99f659e747ddfa73d3d207efa88f1226492427ef
|
/datasets/srfi/srfi-122/srfi-122.scm
|
4f5491dc73c40d63dbb00b5c08a4d09b9822f913
|
[
"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 | 102,306 |
scm
|
srfi-122.scm
|
(include "html-lib.scm")
(define (format-lambda-list lst)
(let ((name (car lst))
(arguments (cdr lst)))
(<p> (<b> "Procedure: ")
(<code> (<a> name: name name)
(map (lambda (arg)
(list " " (cond ((symbol? arg)
(<var> arg))
((keyword? arg)
arg)
(else
arg))))
arguments)))))
(define (format-global-variable name)
(<p> (<b> "Variable: ")
(<code> (<a> name: name name))))
(with-output-to-file
"srfi-122.html"
(lambda()
(html-display
(list
(<unprotected> "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">")
(<html>
(<head>
(<meta> charset: "utf-8")
(<title> "Nonempty Intervals and Generalized Arrays")
(<link> href: "http://srfi.schemers.org/srfi.css"
rel: "stylesheet")
(<script> type: "text/x-mathjax-config" "
MathJax.Hub.Config({
tex2jax: {inlineMath: [['$','$'], ['\\\\(','\\\\)']]}
});")
(<script> type: "text/javascript"
src: "https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML")
)
(<body>
(<h1> "Title")
(<p> "Nonempty Intervals and Generalized Arrays")
(<h2> "Author")
(<p> "Bradley J. Lucier")
(<h2> "Status")
(<p> "This SRFI is currently in " (<em> "final") " status. Here is "
(<a> href: "http://srfi.schemers.org/srfi-process.html" "an explanation")
" of each status that a SRFI can hold. To provide input on this SRFI, please send email to "
(<code> (<a> href: "mailto:srfi minus 122 at srfi dot schemers dot org"
"srfi-122@" (<span> class: "antispam" "nospam") "srfi.schemers.org"))
". To subscribe to the list, follow "
(<a> href: "http://srfi.schemers.org/srfi-list-subscribe.html" "these instructions")
". You can access previous messages via the mailing list "
(<a> href: "http://srfi-email.schemers.org/srfi-122" "archive")". There is a "(<a> href: "https://github.com/scheme-requests-for-implementation/srfi-122" "git repository")" of this document, a reference implementation, a test file, and other materials.")
(<ul> (<li> "Received: 2015/7/23")
(<li> "Draft #1 published: 2015/7/27")
(<li> "Draft #2 published: 2015/7/31")
(<li> "Draft #3 published: 2015/7/31")
(<li> "Draft #4 published: 2015/9/03")
(<li> "Draft #5 published: 2015/9/18")
(<li> "Draft #6 published: 2015/10/19")
(<li> "Draft #7 published: 2016/8/15")
(<li> "Draft #8 published: 2016/8/19")
(<li> "Draft #9 published: 2016/8/25")
(<li> "Draft #10 published: 2016/8/30")
(<li> "Draft #11 published: 2016/9/7")
(<li> "Draft #12 published: 2016/9/17")
(<li> "Draft #13 published: 2016/11/18")
(<li> "Draft #14 published: 2016/11/28")
(<li> "Draft #15 published: 2016/12/15")
(<li> "Finalized: 2016/12/24"))
(<h2> "Abstract")
(<p>
"This SRFI specifies an array mechanism for Scheme. Arrays as defined here are quite general; at their most basic, an array is simply a "
"mapping, or function, from multi-indices of exact integers $i_0,\\ldots,i_{d-1}$ to Scheme values. The set of multi-indices "
"$i_0,\\ldots,i_{d-1}$ that are valid for a given array form the "(<i>'domain)" of the array. In this SRFI, each array's domain consists "
" of a rectangular interval $[l_0,u_0)\\times[l_1,u_1)\\times\\cdots\\times[l_{d-1},u_{d-1})$, a subset of $\\mathbb Z^d$, $d$-tuples of "
"integers. Thus, we introduce a data type "
"called "(<i> 'intervals)", which encapsulate the cross product of nonempty intervals of exact integers. "
"Specialized variants of arrays are specified to provide portable programs with efficient representations for common use cases.")
(<h2> "Overview")
(<h3> "Bawden-style arrays")
(<p> "In a "(<a> href: "https://groups.google.com/forum/?hl=en#!msg/comp.lang.scheme/7nkx58Kv6RI/a5hdsduFL2wJ" "1993 post")
" to the news group comp.lang.scheme, Alan Bawden gave a simple implementation of multi-dimensional arrays in R4RS scheme. "
"The only constructor of new arrays required specifying an initial value, and he provided the three low-level primitives "
(<code>'array-ref)", "(<code>'array-set!)", and "(<code>'array?)". His arrays were defined on rectangular intervals in "
"$\\mathbb Z^d$ of the form $[0,u_0)\\times\\cdots\\times [0,u_{d-1})$. I'll note that his function "(<code>'array-set!)
" put the value to be entered into the array at the front of the variable-length list of indices that indicate where to "
"place the new value. He offered an intriguing way to \"share\" arrays "
"in the form of a routine "(<code>'make-shared-array)" that took a mapping from a new interval of indices into the domain "
"of the array to be shared. His implementation incorporated what he called an "(<i>'indexer)", which was a function from "
"the interval $[0,u_0)\\times\\cdots\\times [0,u_{d-1})$ to an interval $[0,N)$, where the "(<i>'body)" of the array consisted of "
"a single Scheme vector of length $N$. Bawden called the mapping specified in "(<code>'make-shared-array)" "
(<i>'linear)", but I prefer the term "(<i>'affine)", as I explain later.")
(<p> "Mathematically, Bawden's arrays can be described as follows. We'll use the vector notation $\\vec i$ for a multi-index "
"$i_0,\\ldots,i_{d-1}$. (Multi-indices correspond to Scheme "(<code>'values)".) Arrays will be denoted by capital letters "
"$A,B,\\ldots$, the domain of the array $A$ (in Bawden's case $[0,u_0)\\times \\cdots\\times [0,u_{d-1})$) will be denoted by $D_A$, "
"and the indexer of $A$, mapping $D_A$ to the interval $[0,N)$ will be denoted by $I_A$. Initially, Bawden constructs "
"$I_A$ such that $I_A(\\vec i)$ steps consecutively through the values $0,1,\\ldots,N-1$ as $\\vec i$ steps through the "
"multi-indices $(0,\\ldots,0,0)$, $(0,\\ldots,0,1)$, $\\ldots$, $(0,\\ldots,1,0)$, etc., in lexicographical order, which means "
"that if $\\vec i$ and $\\vec j$ are two multi-indices, then $\\vec i<\\vec j$ iff the first coordinate $k$ where $\\vec i$ and $\\vec j$ "
"differ satisfies $\\vec i_k<\\vec j_k$. In fact, $I_A(\\vec i)=\\vec v\\cdot\\vec i$ for some specially-constructed vector $\\vec v$ "
"that depends only on $D_A$, the domain of $A$, where $\\vec v\\cdot\\vec i$ is the dot product of $\\vec v$ and $\\vec i$.")
(<p> "In "(<code>'make-shared-array)", Bawden allows you to specify a new $r$-dimensional interval $D_B$ as the domain of a new array $B$, and a "
"mapping $T_{BA}:D_B\\to D_A$ of the form $T_{BA}(\\vec i)=M\\vec i+\\vec b$; here $M$ is a $d\\times r$ matrix of integer values and "
"$\\vec b$ is a $d$-vector. So this mapping $T_{BA}$ is "(<i>'affine)", in that $T_{BA}(\\vec i)-T_{BA}(\\vec j)=M(\\vec i-\\vec j)$ is "
(<i>'linear)" (in a linear algebra sense) in $\\vec i-\\vec j$. The new indexer of $B$ satisfies $I_B(\\vec i)=I_A(T_{BA}(\\vec i))$.")
(<p> "A fact Bawden exploits in the code, but doesn't point out in the short post, is that $I_B$ is again an affine map, and indeed, the composition "
"of "(<i>'any)" two affine maps is again affine.")
(<h3> "Our extensions of Bawden-style arrays")
(<p> "We incorporate Bawden-style arrays into this SRFI, but extend them in two relatively minor ways that we find quite useful.")
(<p> "First, we allow the intervals of multi-indices that form the domains of arrays to have nonzero lower bounds as "
"well as upper bounds, so domains are rectangular, $d$-dimensional intervals $[l_0,u_0)\\times\\cdots\\times[l_{d-1},u_{d-1})$.")
(<p> "Second, we introduce the notion of a "(<i>"storage class")", an object that contains functions that manipulate, store, check, etc., different types of values. "
"A "(<code>'generic-storage-class)" can manipulate any Scheme value, "
"whereas,e.g., a "(<code>'u1-storage-class)" can store only the values 0 and 1 in each element of a body.")
(<p> "We also require that our affine maps be one-to-one, so that if $\\vec i\\neq\\vec j$ then $T(\\vec i)\\neq T(\\vec j)$. Without this property, modifying "
"the $\\vec i$th component of $A$ would cause the $\\vec j$th component to change.")
(<h3> "Common transformations on Bawden-style arrays")
(<p> "Requiring the transformations $T_{BA}:D_B\\to D_A$ to be affine may seem esoteric and restricting, but in fact many common and useful array transformations "
"can be expressed in this way. We give several examples below: ")
(<ul>
(<li> (<b> "Restricting the domain of an array: ")
" If the domain of $B$, $D_B$, is a subset of the domain of $A$, then $T_{BA}(\\vec i)=\\vec i$ is a one-to-one affine mapping. We define "
(<code>'array-extract)" to define this common operation; it's like looking at a rectangular sub-part of a spreadsheet. We use it to extract the common part of overlapping domains of three arrays in an image processing example below. ")
(<li> (<b> "Translating the domain of an array: ")
"If $\\vec d$ is a vector of integers, then $T_{BA}(\\vec i)=\\vec i-\\vec d$ is a one-to-one affine map of $D_B=\\{\\vec i+\\vec d\\mid \\vec i\\in D_A\\}$ onto $D_A$. "
"We call $D_B$ the "(<i>'translate)" of $D_A$, and we define "(<code>'array-translate)" to provide this operation.")
(<li> (<b> "Permuting the coordinates of an array: ")
"If $\\pi$ "(<a> href: "https://en.wikipedia.org/wiki/Permutation" 'permutes)" the coordinates of a multi-index $\\vec i$, and $\\pi^{-1}$ is the inverse of $\\pi$, then "
"$T_{BA}(\\vec i)=\\pi (\\vec i)$ is a one-to-one affine map from $D_B=\\{\\pi^{-1}(\\vec i)\\mid \\vec i\\in D_A\\}$ onto $D_A$. We provide "(<code>'array-permute)" for this operation. "
"The only nonidentity permutation of a two-dimensional spreadsheet turns rows into columns and vice versa.")
(<li> (<b> "Currying an array: ")
"Let's denote the cross product of two intervals $\\text{Int}_1$ and $\\text{Int}_2$ by $\\text{Int}_1\\times\\text{Int}_2$; "
"if $\\vec j=(j_0,\\ldots,j_{r-1})\\in \\text{Int}_1$ and $\\vec i=(i_0,\\ldots,i_{s-1})\\in \\text{Int}_2$, then "
"$\\vec j\\times\\vec i$, which we define to be $(j_0,\\ldots,j_{r-1},i_0,\\ldots,i_{s-1})$, is in $\\text{Int}_1\\times\\text{Int}_2$. "
"If $D_A=\\text{Int}_1\\times\\text{Int}_2$ and $\\vec j\\in\\text{Int}_1$, then $T_{BA}(\\vec i)=\\vec j\\times\\vec i$ "
"is a one-to-one affine mapping from $D_B=\\text{Int}_2$ into $D_A$. For each vector $\\vec j$ we can compute a new array in this way; we provide "
(<code>'array-curry)" for this operation, which returns an array whose domain is $\\text{Int}_1$ and whose elements are themselves arrays, each of which is defined on $\\text{Int}_2$. "
"Currying a two-dimensional array would be like organizing a spreadsheet into a one-dimensional array of rows of the spreadsheet.")
(<li> (<b> "Traversing some indices in a multi-index in reverse order: ")
"Consider an array $A$ with domain $D_A=[l_0,u_0)\\times\\cdots\\times[l_{d-1},u_{d-1})$. Fix $D_B=D_A$ and assume we're given a vector of booleans $F$ ($F$ for \"flip?\"). "
"Then define $T_{BA}:D_B\\to D_A$ by $i_j\\to i_j$ if $F_j$ is "(<code>'#f)" and $i_j\\to u_j+l_j-1-i_j$ if $F_j$ is "(<code>'#t)"."
"In other words, we reverse the ordering of the $j$th coordinate of $\\vec i$ if and only if $F_j$ is true. "
"$T_{BA}$ is an affine mapping from $D_B\\to D_A$, which defines a new array $B$, and we can provide "(<code>'array-reverse)" for this operation. "
"Applying "(<code>'array-reverse)" to a two-dimensional spreadsheet might reverse the order of the rows or columns (or both).")
(<li> (<b> "Uniformly sampling an array: ")
"Assume that $A$ is an array with domain $[0,u_1)\\times\\cdots\\times[0,u_{d-1})$ (i.e., an interval all of whose lower bounds are zero). "
"We'll also assume the existence of vector $S$ of scale factors, which are positive exact integers. "
"Let $D_B$ be a new interval with $j$th lower bound equal to zero and $j$th upper bound equal to $\\operatorname{ceiling}(u_j/S_j)$ and let "
"$T_{BA}(\\vec i)_j=i_j\\times S_j$, i.e., the $j$th coordinate is scaled by $S_j$. ($D_B$ contains precisely those multi-indices that $T_{BA}$ maps into $D_A$.) "
" Then $T_{BA}$ is an affine one-to-one mapping, and we provide "(<code>'interval-scale)" and "(<code>'array-sample)" for these operations.")
)
(<p> "We make several remarks. First, all these operations could have been computed by specifying the particular mapping $T_{BA}$ explicitly, so that these routines are simply "
"\"convenience\" procedures. Second, because the composition of any number of affine mappings are again affine, accessing or changing the elements of a "
"restricted, translated, curried, permuted array is no slower than accessing or changing the elements of the original array itself. "
"Finally, we note that by combining array currying and permuting, say, one can come up with simple expressions of powerful algorithms, such as extending "
"one-dimensional transforms to multi-dimensional separable transforms, or quickly generating two-dimensional slices of three-dimensional image data. "
"Examples are given below.")
(<h3> "Generalized arrays")
(<p> "Bawden-style arrays are clearly useful as a programming construct, but they do not fulfill all our needs in this area. "
"An array, as commonly understood, provides a mapping from multi-indices $(i_0,\\ldots,i_{d-1})$ of exact integers
in a nonempty, rectangular, $d$-dimensional interval $[l_0,u_0)\\times[l_1,u_1)\\times\\cdots\\times[l_{d-1},u_{d-1})$ (the "(<i>'domain)" of the array) to Scheme objects.
Thus, two things are necessary to specify an array: an interval and a mapping that has that interval as its domain.")
(<p> "Since these two things are often sufficient for certain algorithms, we introduce in this SRFI a minimal set of interfaces for dealing with such arrays.")
(<p> "Specifically, an array specifies a nonempty, multi-dimensional interval, called its "(<i> "domain")", and a mapping from this domain to Scheme objects. This mapping is called the "(<i> 'getter)" of the array, accessed with the procedure "(<code>'array-getter)"; the domain of the array (more precisely, the domain of the array's getter) is accessed with the procedure "(<code>'array-domain)".")
(<p> "If this mapping can be changed, the array is said to be "(<i> 'mutable)" and the mutation is effected
by the array's "(<i> 'setter)", accessed by the procedure "(<code>'array-setter)". We call an object of this type a mutable array. Note: If an array does not have a setter, then we call it immutable even though the array's getter might not be a \"pure\" function, i.e., the value it returns may not depend solely on the arguments passed to the getter.")
(<p> "In general, we leave the implementation of generalized arrays completely open. They may be defined simply by closures, or
they may have hash tables or databases behind an implementation, one may read the values from a file, etc.")
(<p> "In this SRFI, Bawden-style arrays are called "(<i> 'specialized)". A specialized array is an example of a mutable array.")
(<h3> "Sharing generalized arrays")
(<p> "Even if an array $A$ is not a specialized array, then it could be \"shared\" by specifying a new interval $D_B$ as the domain of "
"a new array $B$ and an affine map $T_{BA}:D_B\\to D_A$. Each call to $B$ would then be computed as $B(\\vec i)=A(T_{BA}(\\vec i))$.")
(<p> "One could again \"share\" $B$, given a new interval $D_C$ as the domain of a new array $C$ and an affine transform $T_{CB}:D_C\\to D_B$, and then each access $C(\\vec i)=A(T_{BA}(T_{CB}(\\vec i)))$. The composition $T_{BA}\\circ T_{CB}:D_C\\to D_A$, being itself affine, could be precomputed and stored as $T_{CA}:D_C\\to D_A$, and $C(\\vec i)=A(T_{CA}(\\vec i))$ can be computed with the overhead of computing a single affine transformation.")
(<p> "So, if we wanted, we could share generalized arrays with constant overhead by adding a single layer of (multi-valued) affine transformations on top of evaluating generalized arrays. Even though this could be done transparently to the user, we do not do that here; it would be a compatible extension of this SRFI to do so. We provide only the routine "(<code>'specialized-array-share)", not a more general "(<code>'array-share)".")
(<p> "Certain ways of sharing generalized arrays, however, are relatively easy to code and not that expensive. If we denote "(<code>"(array-getter A)")" by "(<code>'A-getter)", then if B is the result of "(<code>'array-extract)" applied to A, then "
(<code>"(array-getter B)")" is simply "(<code>'A-getter)". Similarly, if A is a two-dimensional array, and B is derived from A by applying the permutation $\\pi((i,j))=(j,i)$, then "(<code>"(array-getter B)")" is "
(<code>"(lambda (i j) (A-getter j i))")". Translation and currying also lead to transformed arrays whose getters are relatively efficiently derived from "(<code>'A-getter)", at least for arrays of small dimension.")
(<p> "Thus, while we do not provide for sharing of generalized arrays for general one-to-one affine maps $T$, we do allow it for the specific functions "(<code>'array-extract)", "(<code>'array-translate)", "(<code>'array-permute)", "
(<code>'array-curry)", "(<code>'array-reverse)", and "(<code>'array-sample)", and we provide relatively efficient implementations of these functions for arrays of dimension no greater than four.")
(<h3> "Array-map does not produce a specialized array")
(<p> "Daniel Friedman and David Wise wrote a famous paper "(<a> href: "http://www.cs.indiana.edu/cgi-bin/techreports/TRNNN.cgi?trnum=TR44" "CONS should not Evaluate its Arguments")". "
"In the spirit of that paper, our procedure "(<code>'array-map)" does not immediately produce a specialized array, but a simple immutable array, whose elements are recomputed from the arguments of "(<code>'array-map)
" each time they are accessed. This immutable array can be passed on to further applications of "(<code>'array-map)" for further processing, without generating the storage bodies for intermediate arrays.")
(<p> "We provide the procedure "(<code>'array->specialized-array)" to transform a generalized array (like that returned by "(<code>'array-map)
") to a specialized, Bawden-style array, for which accessing each element again takes $O(1)$ operations.")
(<h2> "Issues and Notes")
(<ul>
(<li> (<b> "Relationship to "(<a> href: "http://docs.racket-lang.org/math/array_nonstrict.html#%28tech._nonstrict%29" "nonstrict arrays")" in Racket. ")
"It appears that what we call simply arrays in this SRFI are called nonstrict arrays in the math/array library of Racket, which in turn was influenced by an "(<a> href: "http://research.microsoft.com/en-us/um/people/simonpj/papers/ndp/RArrays.pdf" "array proposal for Haskell")". Our \"specialized\" arrays are related to Racket's \"strict\" arrays.")
(<li> (<b> "Indexers. ")"The argument new-domain->old-domain to "(<code> 'specialized-array-share)" is, conceptually, a multi-valued array.")
(<li> (<b> "Source of function names. ")"The function "(<code> 'array-curry)" gets its name from the " #\newline
(<a> href: "http://en.wikipedia.org/wiki/Currying" "curry operator")
" in programming---we are currying the getter of the array and keeping careful track of the domains. " #\newline
(<code>'interval-projections)" can be thought of as currying the " #\newline
"characteristic function of the interval, encapsulated here as "(<code> 'interval-contains-multi-index?)".")
(<li> (<b> "Choice of functions on intervals. ")"The choice of functions for both arrays and intervals was motivated almost solely by what I needed for arrays. There are " #\newline
"natural operations on intervals, like "
(<pre> (<code>"(interval-cross-product interval1 interval2 ...)"))
"(the inverse of "(<code> 'interval-projections)"),
which don't seem terribly natural for arrays.")
(<li> (<b> "No empty intervals. ")"This SRFI considers arrays over only nonempty intervals of positive dimension. The author of this proposal acknowledges that other languages and array systems allow either zero-dimensional intervals or empty intervals of positive dimension, but prefers to leave such empty intervals as possibly compatible extensions to the current proposal.")
(<li> (<b> "Multi-valued arrays. ")"While this SRFI restricts attention to single-valued arrays, wherein the getter of each array returns a single value, allowing multi-valued immutable arrays would a compatible extension of this SRFI.")
(<li> (<b> "No low-level specialized-array constructor. ")
"While the author of the SRFI uses mainly "(<code>"(make-array ...)")", "(<code>'array-map)", and "(<code>'array->specialized-array)" to construct arrays, and while there are several other ways to construct arrays, there is no really low-level interface given for constructing specialized arrays (where one specifies a body, an indexer, etc.). It was felt that certain difficulties, some surmountable (such as checking that a given body is compatible with a given storage class) and some not (such as checking that an indexer is indeed affine), made a low-level interface less useful. At the same time, the simple "(<code>"(make-array ...)")" mechanism is so general, allowing one to specify getters and setters as general functions, as to cover nearly all needs.")
)
(<h2> "Specification")
(let ((END ",\n"))
(<p> "Names defined in this SRFI:")
(<dl>
(<dt> "Miscellaneous Functions")
(<dd> (<a> href: "#translation?" "translation?") END
(<a> href: "#permutation?" "permutation?")
".")
(<dt> "Intervals")
(<dd> (<a> href: "#make-interval" "make-interval")END
(<a> href: "#interval?" "interval?")END
(<a> href: "#interval-dimension" "interval-dimension")END
(<a> href: "#interval-lower-bound" "interval-lower-bound")END
(<a> href: "#interval-upper-bound" "interval-upper-bound")END
(<a> href: "#interval-lower-bounds->list" "interval-lower-bounds->list")END
(<a> href: "#interval-upper-bounds->list" "interval-upper-bounds->list")END
(<a> href: "#interval-lower-bounds->vector" "interval-lower-bounds->vector")END
(<a> href: "#interval-upper-bounds->vector" "interval-upper-bounds->vector")END
(<a> href: "#interval=" "interval=")END
(<a> href: "#interval-volume" "interval-volume")END
(<a> href: "#interval-subset?" "interval-subset?")END
(<a> href: "#interval-contains-multi-index?" "interval-contains-multi-index?")END
(<a> href: "#interval-projections" "interval-projections")END
(<a> href: "#interval-for-each" "interval-for-each")END
(<a> href: "#interval-dilate" "interval-dilate")END
(<a> href: "#interval-intersect" "interval-intersect")END
(<a> href: "#interval-translate" "interval-translate")END
(<a> href: "#interval-permute" "interval-permute") END
(<a> href: "#interval-scale" "interval-scale")
".")
(<dt> "Storage Classes")
(<dd> (<a> href: "#make-storage-class" "make-storage-class") END
(<a> href: "#storage-class?" "storage-class?") END
(<a> href: "#storage-class-getter" "storage-class-getter") END
(<a> href: "#storage-class-setter" "storage-class-setter") END
(<a> href: "#storage-class-checker" "storage-class-checker") END
(<a> href: "#storage-class-maker" "storage-class-maker") END
(<a> href: "#storage-class-length" "storage-class-length") END
(<a> href: "#storage-class-default" "storage-class-default") END
(<a> href: "#generic-storage-class" "generic-storage-class") END
(<a> href: "#s8-storage-class" "s8-storage-class") END
(<a> href: "#s16-storage-class" "s16-storage-class") END
(<a> href: "#s32-storage-class" "s32-storage-class") END
(<a> href: "#s64-storage-class" "s64-storage-class") END
(<a> href: "#u1-storage-class" "u1-storage-class") END
(<a> href: "#u8-storage-class" "u8-storage-class") END
(<a> href: "#u16-storage-class" "u16-storage-class") END
(<a> href: "#u32-storage-class" "u32-storage-class") END
(<a> href: "#u64-storage-class" "u64-storage-class") END
(<a> href: "#f32-storage-class" "f32-storage-class") END
(<a> href: "#f64-storage-class" "f64-storage-class") END
(<a> href: "#c64-storage-class" "c64-storage-class") END
(<a> href: "#c128-storage-class" "c128-storage-class")
".")
(<dt> "Arrays")
(<dd> (<a> href: "#make-array" "make-array")END
(<a> href: "#array?" "array?")END
(<a> href: "#array-domain" "array-domain")END
(<a> href: "#array-getter" "array-getter")END
(<a> href: "#array-dimension" "array-dimension")END
(<a> href: "#mutable-array?" "mutable-array?")END
(<a> href: "#array-setter" "array-setter")END
(<a> href: "#specialized-array-default-safe?" "specialized-array-default-safe?") END
(<a> href: "#make-specialized-array" "make-specialized-array")END
(<a> href: "#specialized-array?" "specialized-array?")END
(<a> href: "#array-storage-class" "array-storage-class")END
(<a> href: "#array-indexer" "array-indexer")END
(<a> href: "#array-body" "array-body")END
(<a> href: "#array-safe?" "array-safe?") END
(<a> href: "#specialized-array-share" "specialized-array-share")END
(<a> href: "#array->specialized-array" "array->specialized-array")END
(<a> href: "#array-curry" "array-curry")END
(<a> href: "#array-extract" "array-extract") END
(<a> href: "#array-translate" "array-translate")END
(<a> href: "#array-permute" "array-permute")END
(<a> href: "#array-reverse" "array-reverse")END
(<a> href: "#array-sample" "array-sample")END
(<a> href: "#array-map" "array-map")END
(<a> href: "#array-for-each" "array-for-each")END
(<a> href: "#array-fold" "array-fold")END
(<a> href: "#array-fold-right" "array-fold-right")END
(<a> href: "#array-any" "array-any")END
(<a> href: "#array-every" "array-every")END
(<a> href: "#array->list" "array->list") END
(<a> href: "#list->specialized-array" "list->specialized-array")
"."
)))
(<h2> "Miscellaneous Functions")
(<p> "This document refers to "(<i> 'translations)" and "(<i> 'permutations)".
A translation is a vector of exact integers. A permutation of dimension $n$
is a vector whose entries are the exact integers $0,1,\\ldots,n-1$, each occurring once, in any order.")
(<h3> "Procedures")
(format-lambda-list '(translation? object))
(<p> "Returns "(<code> '#t)" if "(<code>(<var>'object))" is a translation, and "(<code> '#f)" otherwise.")
(format-lambda-list '(permutation? object))
(<p> "Returns "(<code> '#t)" if "(<code>(<var>'object))" is a permutation, and "(<code> '#f)" otherwise.")
(<h2> "Intervals")
(<p> "An interval represents the set of all multi-indices of exact integers
$i_0,\\ldots,i_{d-1}$
satisfying
$l_0\\leq i_0<u_0,\\ldots,l_{d-1}\\leq i_{d-1}<u_{d-1}$,
where the "(<i>"lower bounds")"
$l_0,\\ldots,l_{d-1}$
and the "(<i>"upper bounds")"
$u_0,\\ldots,u_{d-1}$
are specified multi-indices of exact integers. The positive integer $d$ is the "(<i>"dimension")"
of the interval. It is required that
$l_0<u_0,\\ldots,l_{d-1}<u_{d-1}$.")
(<p> "Intervals are a data type distinct from other Scheme data types.")
(<h3> "Procedures")
(format-lambda-list '(make-interval lower-bounds upper-bounds))
(<p> "Create a new interval; "(<code> (<var>"lower-bounds"))" and "(<code> (<var>"upper-bounds"))"
are nonempty vectors (of the same length) of exact integers that satisfy")
(<pre>
(<code>" (< (vector-ref "(<var>"lower-bounds")" i) (vector-ref "(<var>"upper-bounds")" i))"))
(<p> " for
$0\\leq i<{}$"(<code>"(vector-length "(<var>"lower-bounds")")")". It is an error if
"(<code>(<var>"lower-bounds"))" and "(<code>(<var>"upper-bounds"))" do not satisfy these conditions.")
(format-lambda-list '(interval? obj))
(<p> "Returns "(<code> "#t")" if "(<code> (<var>"obj"))" is an interval, and "(<code>"#f")" otherwise.")
(format-lambda-list '(interval-dimension interval))
(<p> "If "(<code>(<var>"interval"))" is an interval built with ")
(<pre>
(<code>"(make-interval "(<var>"lower-bounds")" "(<var>"upper-bounds")")"))
(<p> "then "(<code> 'interval-dimension)" returns "(<code>"(vector-length "(<var>"lower-bounds")")")". It is an error to call "(<code> 'interval-dimension)"
if "(<code>(<var>"interval"))" is not an interval.")
(format-lambda-list '(interval-lower-bound interval i))
(format-lambda-list '(interval-upper-bound interval i))
(<p> "If "(<code>(<var>"interval"))" is an interval built with ")
(<blockquote>
(<code>"(make-interval "(<var>"lower-bounds")" "(<var>"upper-bounds")")"))
(<p> "and "(<code>(<var>"i"))" is an exact integer that satisfies")
(<blockquote>
"$0 \\leq i<$ "(<code>"(vector-length "(<var>"lower-bounds")")")",")
(<p> " then "(<code> 'interval-lower-bound)" returns
"(<code>"(vector-ref "(<var>"lower-bounds")" "(<var>"i")")")" and "(<code> 'interval-upper-bound)" returns
"(<code>"(vector-ref "(<var>"upper-bounds")" "(<var>"i")")")". It is an error to call "(<code> 'interval-lower-bound)" or "(<code> 'interval-upper-bound)"
if "(<code>(<var>"interval"))" and "(<code>(<var>"i"))" do not satisfy these conditions.")
(format-lambda-list '(interval-lower-bounds->list interval))
(format-lambda-list '(interval-upper-bounds->list interval))
(<p> "If "(<code>(<var>"interval"))" is an interval built with ")
(<pre>
(<code>"(make-interval "(<var>"lower-bounds")" "(<var>"upper-bounds")")"))
(<p> " then "(<code> 'interval-lower-bounds->list)" returns "(<code> "(vector->list "(<var>"lower-bounds")")")
" and "(<code> 'interval-upper-bounds->list)" returns "(<code> "(vector->list "(<var>"upper-bounds")")")". It is an error to call
"(<code> 'interval-lower-bounds->list)" or "(<code> 'interval-upper-bounds->list)" if "(<code>(<var>"interval"))" does not satisfy these conditions.")
(format-lambda-list '(interval-lower-bounds->vector interval))
(format-lambda-list '(interval-upper-bounds->vector interval))
(<p> "If "(<code>(<var>"interval"))" is an interval built with ")
(<pre>
(<code>"(make-interval "(<var>"lower-bounds")" "(<var>"upper-bounds")")"))
(<p> " then "(<code> 'interval-lower-bounds->vector)" returns a copy of "(<code> (<var>"lower-bounds"))
" and "(<code> 'interval-upper-bounds->vector)" returns a copy of "(<code> (<var>"upper-bounds"))". It is an error to call
"(<code> 'interval-lower-bounds->vector)" or "(<code> 'interval-upper-bounds->vector)" if "(<code>(<var>"interval"))" does not satisfy these conditions.")
(format-lambda-list '(interval-volume interval))
(<p> "If "(<code>(<var>"interval"))" is an interval built with ")
(<pre>
(<code>"(make-interval "(<var>"lower-bounds")" "(<var>"upper-bounds")")"))
(<p> "then, assuming the existence of "(<code>'vector-map)", "(<code> 'interval-volume)" returns ")
(<pre>
(<code> "(apply * (vector->list (vector-map - "(<var>"upper-bounds")" "(<var>"lower-bounds")")))"))
(<p> "It is an error to call "(<code> 'interval-volume)" if "(<code>(<var> 'interval))" does not satisfy this condition.")
(format-lambda-list '(interval= interval1 interval2))
(<p> "If "(<code>(<var>"interval1"))" and "(<code>(<var>"interval2"))" are intervals built with ")
(<pre>
(<code>"(make-interval "(<var>"lower-bounds1")" "(<var>"upper-bounds1")")"))
(<p> "and")
(<pre>
(<code>"(make-interval "(<var>"lower-bounds2")" "(<var>"upper-bounds2")")"))
(<p> "respectively, then "(<code> 'interval=)" returns")
(<pre>
(<code> "(and (equal? "(<var> 'lower-bounds1)" "(<var> 'lower-bounds2)") (equal? "(<var> 'upper-bounds1)" "(<var> 'upper-bounds2)"))"))
(<p> "It is an error to call "(<code> 'interval=)" if "(<code>(<var> 'interval1))" or "(<code>(<var> 'interval2))" do not satisfy this condition.")
(format-lambda-list '(interval-subset? interval1 interval2))
(<p> "If "(<code>(<var>"interval1"))" and "(<code>(<var>"interval2"))" are intervals of the same dimension $d$, "
"then "(<code>'interval-subset?)" returns "(<code>'#t)" if ")
(<pre>
(<code>"(<= (interval-lower-bound "(<var>'interval1)" j) (interval-lower-bound "(<var>'interval2)" j))"))
(<p> "and")
(<pre>
(<code>"(<= (interval-upper-bound "(<var>'interval1)" j) (interval-upper-bound "(<var>'interval2)" j))"))
(<p> "for all $0\\leq j<d$, otherwise it returns "(<code>'#f)". It is an error if the arguments do not satisfy these conditions.")
(format-lambda-list '(interval-contains-multi-index? interval index-0 index-1 ...))
(<p> "If "(<code>(<var> 'interval))" is an interval with dimension $d$ and "(<code>(<var> 'index-0))", "(<code>(<var> 'index-1))", ..., is a multi-index of length $d$,
then "(<code> 'interval-contains-multi-index?)" returns "(<code> #t)" if ")
(<blockquote>
(<code> "(interval-lower-bound "(<var> 'interval)" j)")" $\\leq$ "(<code> (<var> 'index-j))" $<$ "(<code> "(interval-upper-bound "(<var> 'interval)" j)"))
(<p>"for $0\\leq j < d$, and "(<code>'#f)" otherwise.")
(<p> "It is an error to call "(<code> 'interval-contains-multi-index?)" if "(<code>(<var> 'interval))" and "(<code>(<var> 'index-0))",..., do not satisfy this condition.")
(format-lambda-list '(interval-projections interval right-dimension))
(<p> "Conceptually, "(<code> 'interval-projections)" takes a $d$-dimensional interval
$[l_0,u_0)\\times [l_1,u_1)\\times\\cdots\\times[l_{d-1},u_{d-1})$\n"
"and splits it into two parts")
(<blockquote> "$[l_0,u_0)\\times\\cdots\\times[l_{d-\\text{right-dimension}-1},u_{d-\\text{right-dimension}-1})$")
(<p> "and")
(<blockquote> "$[l_{d-\\text{right-dimension}},u_{d-\\text{right-dimension}})\\times\\cdots\\times[l_{d-1},u_{d-1})$")
(<p> "This function, the inverse of Cartesian products or cross products of intervals, is used to keep track of the domains of curried arrays.")
(<p> "More precisely, if "(<code>(<var> 'interval))" is an interval and "(<code>(<var> 'right-dimension))" is an exact integer that satisfies "
(<code> "0 < "(<var> 'right-dimension)" < "(<var>'d))" then "(<code> 'interval-projections)" returns two intervals:")
(<pre>
(<code> "
(values
(make-interval
(vector (interval-lower-bound "(<var>'interval)" 0)
...
(interval-lower-bound "(<var>'interval)"
(- "(<var>'d)" "(<var>'right-dimension)" 1)))
(vector (interval-upper-bound "(<var>'interval)" 0)
...
(interval-upper-bound "(<var>'interval)"
(- "(<var>'d)" "(<var>'right-dimension)" 1))))
(make-interval
(vector (interval-lower-bound "(<var>'interval)"
(- "(<var>'d)" "(<var>'right-dimension)"))
...
(interval-lower-bound "(<var>'interval)"
(- "(<var>'d)" 1)))
(vector (interval-upper-bound "(<var>'interval)"
(- "(<var>'d)" "(<var>'right-dimension)"))
...
(interval-upper-bound "(<var>'interval)"
(- "(<var>'d)" 1)))))"))
(<p> "It is an error to call "(<code> 'interval-projections)" if its arguments do not satisfy these conditions.")
(format-lambda-list '(interval-for-each f interval))
(<p> "This routine assumes that "(<code>(<var> 'interval))" is an interval and "(<code>(<var> 'f))" is a routine whose domain includes elements of "(<code>(<var> 'interval))". It is an error to call
"(<code> 'interval-for-each)" if "(<code>(<var> 'interval))" and "(<code>(<var> 'f))" do not satisfy these conditions.")
(<p> (<code> 'interval-for-each)" calls "(<code>(<var> 'f))" with each multi-index of "(<code>(<var> 'interval))" as arguments, all in lexicographical order.")
(format-lambda-list '(interval-dilate interval lower-diffs upper-diffs))
(<p> "If "(<code>(<var> 'interval))" is an interval with
lower bounds l"(<sub>"0")", ..., l"(<sub>"d-1")" and
upper bounds u"(<sub>"0")", ..., u"(<sub>"d-1")", and "
(<code>(<var> "lower-diffs"))" is a vector of exact integers L"(<sub>"0")", ..., L"(<sub>"d-1")" and "
(<code>(<var> "upper-diffs"))" is a vector of exact integers U"(<sub>"0")", ..., U"(<sub>"d-1")", then "
(<code>"interval-dilate")" returns a new interval with
lower bounds l"(<sub>"0")"+L"(<sub>"0")", ..., l"(<sub>"d-1")"+L"(<sub>"d-1")" and
upper bounds u"(<sub>"0")"+U"(<sub>"0")", ..., u"(<sub>"d-1")"+U"(<sub>"d-1")", as long as this is a
nonempty interval. It is an error if the arguments do not satisfy these conditions.")
(<p> "Examples:")
(<pre>(<code>"
(interval=
(interval-dilate (make-interval '#(0 0) '#(100 100))
'#(1 1) '#(1 1))
(make-interval '#(1 1) '#(101 101))) => #t
(interval=
(interval-dilate (make-interval '#(0 0) '#(100 100))
'#(-1 -1) '#(1 1))
(make-interval '#(-1 -1) '#(101 101))) => #t
(interval=
(interval-dilate (make-interval '#(0 0) '#(100 100))
'#(0 0) '#(-50 -50))
(make-interval '#(0 0) '#(50 50))) => #t
(interval-dilate
(make-interval '#(0 0) '#(100 100))
'#(0 0) '#(-500 -50)) => error
"))
(format-lambda-list '(interval-intersect interval-1 interval-2 ...))
(<p> "If all the arguments are intervals of the same dimension and they have a nonempty intersection,
the "(<code> 'interval-intersect)" returns that intersection; otherwise it returns "(<code>'#f)".")
(<p> "It is an error if the arguments are not all intervals with the same dimension.")
(format-lambda-list '(interval-translate interval translation))
(<p> "If "(<code>(<var> 'interval))" is an interval with
lower bounds l"(<sub>"0")", ..., l"(<sub>"d-1")" and
upper bounds u"(<sub>"0")", ..., u"(<sub>"d-1")", and "
(<code>(<var> "translation"))" is a translation with entries T"(<sub>"0")", ..., T"(<sub>"d-1")
", then "
(<code>"interval-translate")" returns a new interval with
lower bounds l"(<sub>"0")"+T"(<sub>"0")", ..., l"(<sub>"d-1")"+T"(<sub>"d-1")" and
upper bounds u"(<sub>"0")"+T"(<sub>"0")", ..., u"(<sub>"d-1")"+T"(<sub>"d-1")".
It is an error if the arguments do not satisfy these conditions.")
(<p> "One could define "(<code> "(interval-translate interval translation)")" by "(<code> "(interval-dilate interval translation translation)")".")
(format-lambda-list '(interval-permute interval permutation))
(<p> "The argument "(<code>(<var>'interval))" must be an interval, and the argument "(<code>(<var>'permutation))" must be a valid permutation with the same dimension as "(<code>(<var>'interval))". It is an error if the arguments do not satisfy these conditions.")
(<p> "Heuristically, this function returns a new interval whose axes have been permuted in a way consistent with "(<code>(<var>'permutation))".
But we have to say how the entries of "(<code>(<var>'permutation))" are associated with the new interval.")
(<p> "We have chosen the following convention: If the permutation is $(\\pi_0,\\ldots,\\pi_{d-1})$, and the argument interval
represents the cross product
$[l_0,u_0)\\times[l_1,u_1)\\times\\cdots\\times[l_{d-1},u_{d-1})$,
then the result represents the cross product
$[l_{\\pi_0},u_{\\pi_0})\\times[l_{\\pi_1},u_{\\pi_1})\\times\\cdots\\times[l_{\\pi_{d-1}},u_{\\pi_{d-1}})$.")
(<p> "For example, if the argument interval represents $[0,4)\\times[0,8)\\times[0,21)\\times [0,16)$ and the
permutation is "(<code>'#(3 0 1 2))", then the result of "(<code> "(interval-permuate "(<var>'interval)" "(<var>' permutation)")")" will be
the representation of $[0,16)\\times [0,4)\\times[0,8)\\times[0,21)$.")
(format-lambda-list '(interval-scale interval scales))
(<p> "If "(<code>(<var>'interval))" is a $d$-dimensional interval $[0,u_1)\\times\\cdots\\times[0,u_{d-1})$ with all lower bounds zero, "
"and "(<code>(<var>'scales))" is a length-$d$ vector of positive exact integers, which we'll denote by $\\vec s$, then "(<code>'interval-scale)
" returns the interval $[0,\\operatorname{ceiling}(u_1/s_1))\\times\\cdots\\times[0,\\operatorname{ceiling}(u_{d-1}/s_{d-1})$.")
(<p> "It is an error if "(<code>(<var>'interval))" and "(<code>(<var>'scales))" do not satisfy this condition.")
(<h2> "Storage classes")
(<p> "Conceptually, a storage-class is a set of functions to manage the backing store of a specialized-array.
The functions allow one to make a backing store, to get values from the store and to set new values, to return the length of the store, and to specify a default value for initial elements of the backing store. Typically, a backing store is a (heterogeneous or homogeneous) vector. A storage-class has a type distinct from other Scheme types.")
(<h3> "Procedures")
(format-lambda-list '(make-storage-class getter setter checker maker length default))
(<p> "Here we assume the following relationships between the arguments of "(<code> 'make-storage-class)". Assume that the \"elements\" of
the backing store are of some \"type\", either heterogeneous (all Scheme types) or homogeneous (of some restricted type).")
(<ul>
(<li> (<code> "("(<var>"maker n")" "(<var> 'value)")")" returns an object containing "(<code>(<var> 'n))" elements of value "(<code>(<var> 'value))".")
(<li> "If "(<code>(<var> 'v))" is an object created by "
(<code>"("(<var> "maker n value")")")
" and 0 <= "(<code>(<var> 'i))" < "(<code>(<var> 'n))", then "(<code> "("(<var>"getter v i")")")" returns the current value of the "(<code>(<var> 'i))"'th element of "(<code>(<var> 'v))", and "(<code> "("(<var> 'checker)" ("(<var>"getter v i")")) => #t")".")
(<li> "If "(<code>(<var> 'v))" is an object created by "
(<code>"("(<var> "maker n value")")")
", 0 <= "(<code>(<var> 'i))" < "(<code>(<var> 'n))", and "(<code>"("(<var> 'checker)" "(<var> 'val)") => #t")", then "(<code> "("(<var>"setter v i val")")")" sets the value of the "(<code>(<var> 'i))"'th element of "(<code>(<var> 'v))" to "(<code>(<var> 'val))".")
(<li> "If "(<code>(<var> 'v))" is an object created by "
(<code>"("(<var> "maker n value")")")
" then "(<code> "("(<var>"length v")")")" returns "(<code>(<var> 'n))"."))
(<p> "If the arguments do not satisfy these conditions, then it is an error to call "(<code> 'make-storage-class)".")
(<p> "Note that we assume that "(<code>(<var> 'getter))" and "(<code>(<var> 'setter))" generally take "(<i> 'O)"(1) time to execute.")
(format-lambda-list '(storage-class? m))
(<p> "Returns "(<code>'#t)" if "(<code>(<var>'m))" is a storage class, and "(<code>'#f)" otherwise.")
(format-lambda-list '(storage-class-getter m))
(format-lambda-list '(storage-class-setter m))
(format-lambda-list '(storage-class-checker m))
(format-lambda-list '(storage-class-maker m))
(format-lambda-list '(storage-class-length m))
(format-lambda-list '(storage-class-default m))
(<p> "If "(<code>(<var> 'm))" is an object created by")
(<blockquote>
(<code>"(make-storage-class "(<var> "getter setter checker maker length default")")"))
(<p> " then "
(<code> 'storage-class-getter)" returns "(<code>(<var> 'getter))", "
(<code> 'storage-class-setter)" returns "(<code>(<var> 'setter))", "
(<code> 'storage-class-checker)" returns "(<code>(<var> 'checker))", "
(<code> 'storage-class-maker)" returns "(<code>(<var> 'maker))", and "
(<code> 'storage-class-length)" returns "(<code>(<var> 'length))", and "
(<code> 'storage-class-default)" returns "(<code>(<var> 'default))". Otherwise, it is an error to call any of these routines.")
(<h3> "Global Variables")
(format-global-variable 'generic-storage-class)
(format-global-variable 's8-storage-class)
(format-global-variable 's16-storage-class)
(format-global-variable 's32-storage-class)
(format-global-variable 's64-storage-class)
(format-global-variable 'u1-storage-class)
(format-global-variable 'u8-storage-class)
(format-global-variable 'u16-storage-class)
(format-global-variable 'u32-storage-class)
(format-global-variable 'u64-storage-class)
(format-global-variable 'f32-storage-class)
(format-global-variable 'f64-storage-class)
(format-global-variable 'c64-storage-class)
(format-global-variable 'c128-storage-class)
(<p> (<code> 'generic-storage-class)" is defined as if by")
(<pre>
(<code> "
(define generic-storage-class
(make-storage-class vector-ref
vector-set!
(lambda (arg) #t)
make-vector
vector-length
#f))"))
"Furthermore, "(<code> "s"(<var> 'X)"-storage-class")" is defined for "(<code>(<var> 'X))"=8, 16, 32, and 64 (which have default values 0 and
manipulate exact integer values between -2"(<sup>(<var> 'X)"-1")" and
2"(<sup> (<var> 'X)"-1")"-1 inclusive),
"(<code> "u"(<var> 'X)"-storage-class")" is defined for "(<code>(<var> 'X))"=1, 8, 16, 32, and 64 (which have default values 0 and manipulate exact integer values between 0 and
2"(<sup> (<var> 'X))"-1 inclusive),
"(<code> "f"(<var> 'X)"-storage-class")" is defined for "(<code>(<var> 'X))"= 32 and 64 (which have default value 0.0 and manipulate 32- and 64-bit floating-point numbers), and
"(<code> "c"(<var> 'X)"-storage-class")" is defined for "(<code>(<var> 'X))"= 64 and 128 (which have default value 0.0+0.0i and manipulate complex numbers with, respectively, 32- and 64-bit floating-point numbers as real and imaginary parts). Each of these
could be defined simply as "(<code>'generic-storage-class)", but it is assumed that implementations with homogeneous vectors will give definitions
that either save space, avoid boxing, etc., for the specialized arrays."
(<h2> "Arrays")
(<p> "Arrays are a data type distinct from other Scheme data types.")
(<h3> "Procedures")
(format-lambda-list '(make-array interval getter #\[ setter #\]))
(<p> "Assume first that the optional argument "(<code>'setter)" is not given.")
(<p> "If "(<code>(<var> 'interval))" is an interval and "(<code>(<var> 'getter))" is a function from
"(<code>(<var> 'interval))" to Scheme objects, then "(<code> 'make-array)" returns an array with domain "(<code>(<var> 'interval))"
and getter "(<code>(<var> 'getter))".")
(<p> "It is an error to call "(<code> 'make-array)" if "(<code>(<var> 'interval))" and "(<code>(<var> 'getter))"
do not satisfy these conditions.")
(<p> "If now "(<code>(<var> 'setter))" is specified, assume that it is a procedure such that getter and setter satisfy: If")
(<blockquote>
(<code>"("(<var> 'i)(<sub> '1)",...,"(<var> 'i)(<sub> 'n)")")" $\\neq$ "(<code> "("(<var> 'j)(<sub> '1)",...,"(<var> 'j)(<sub> 'n)")"))
(<p> "are elements of "(<code>(<var> 'interval))" and ")
(<blockquote>
(<code> "(getter "(<var> 'j)(<sub> '1)" ... "(<var> 'j)(<sub> 'n)") => x"))
(<p> "then \"after\"")
(<blockquote>
(<code> "(setter v "(<var> 'i)(<sub> '1)" ... "(<var> 'i)(<sub> 'n)")"))
(<p> "we have")
(<blockquote>
(<code> "(getter "(<var> 'j)(<sub> '1)" ... "(<var> 'j)(<sub> 'n)") => x"))
(<p> "and")
(<blockquote>
(<code> "(getter "(<var> 'i)(<sub> '1)",...,"(<var> 'i)(<sub> 'n)") => v"))
(<p> "Then "(<code> 'make-array)" builds a mutable array with domain "(<code>(<var> 'interval))", getter "(<code>(<var> 'getter))", and
setter "(<code>(<var> 'setter))". It is an error to call "(<code> 'make-array)" if its arguments do not satisfy these conditions.")
(<p> "Example: ")
(<pre>
(<code>"
(define a (make-array (make-interval '#(1 1) '#(11 11))
(lambda (i j)
(if (= i j)
1
0))))"))
(<p> "defines an array for which "(<code> "(array-getter a)")" returns 1 when i=j and 0 otherwise.")
(<p> "Example: ")
(<pre>
(<code>"
(define sparse-array
(let ((domain
(make-interval '#(0 0)
'#(1000000 1000000)))
(sparse-rows
(make-vector 1000000 '())))
(make-array
domain
(lambda (i j)
(cond ((assv j (vector-ref sparse-rows i))
=> cdr)
(else
0.0)))
(lambda (v i j)
(cond ((assv j (vector-ref sparse-rows i))
=> (lambda (pair)
(set-cdr! pair v)))
(else
(vector-set!
sparse-rows
i
(cons (cons j v)
(vector-ref sparse-rows i)))))))))
((array-getter sparse-array) 12345 6789) => 0.
((array-getter sparse-array) 0 0) => 0.
((array-setter sparse-array) 1.0 0 0) => undefined
((array-getter sparse-array) 12345 6789) => 0.
((array-getter sparse-array) 0 0) => 1."))
(format-lambda-list '(array? obj))
(<p> "Returns "(<code> "#t")" if "(<code>(<var> 'obj))" is an array and "(<code> '#f)" otherwise.")
(format-lambda-list '(array-domain array))
(format-lambda-list '(array-getter array))
(<p> "If "(<code>(<var> 'array))" is an array built by")
(<pre>
(<code> "(make-array "(<var> 'interval)" "(<var> 'getter)" ["(<var> 'setter)"])"))
(<p> "(with or without the optional "(<code>(<var> 'setter))" argument) then "(<code> 'array-domain)" returns "(<code>(<var> 'interval))
" and "(<code> 'array-getter)" returns "(<code>(<var> 'getter))".
It is an error to call "(<code> 'array-domain)" or "(<code> 'array-getter)" if "(<code>(<var> 'array))" is not an array.")
(<p> "Example: ")
(<pre>
(<code>"
(define a (make-array (make-interval '#(1 1) '#(11 11))
(lambda (i j)
(if (= i j)
1
0))))
((array-getter a) 3 3) => 1
((array-getter a) 2 3) => 0
((array-getter a) 11 0) => is an error"))
(format-lambda-list '(array-dimension array))
(<p> "Shorthand for "(<code>"(interval-dimension (array-domain "(<var>'array)"))")". It is an error to call this function if "(<code>(<var>'array))" is not an array.")
(format-lambda-list '(mutable-array? obj))
(<p> "Returns "(<code>"#t")" if "(<code>(<var> 'obj))" is a mutable array and "(<code> '#f)" otherwise.")
(format-lambda-list '(array-setter array))
(<p> "If "(<code>(<var> 'array))" is an array built by")
(<pre>
(<code> "(make-array "(<var> 'interval)" "(<var> 'getter)" "(<var> 'setter)")"))
(<p> "then "(<code> 'array-setter)" returns "(<code>(<var> 'setter))". It is an error to call "(<code> 'array-setter)"
if "(<code>(<var> 'array))" is not a mutable array.")
(format-lambda-list '(specialized-array-default-safe? #\[ bool #\]))
(<p> "With no argument, returns "(<code>'#t)" if newly-constructed specialized arrays check the arguments of setters and getters by default, and "(<code>'#f)" otherwise.")
(<p> "If "(<code>(<var>'bool))" is "(<code>'#t)" then the next call to "(<code>'specialized-array-default-safe?)" will return "(<code>'#t)";
if "(<code>(<var>'bool))" is "(<code>'#f)" then the next call to "(<code>'specialized-array-default-safe?)" will return "(<code>'#f)";
otherwise it is an error.")
(format-lambda-list '(make-specialized-array interval #\[ storage-class "generic-storage-class" #\] #\[ safe? "(specialized-array-default-safe?)"#\]))
(<p> "Constructs a specialized-array from its arguments.")
(<p> (<code>(<var>'interval))" must be given as a nonempty interval. If given, "(<code>(<var>'storage-class))" must be a storage class; if it is not given it defaults to "(<code>'generic-storage-class)". If given, "(<code>(<var>'safe?))" must be a boolean; if it is not given it defaults to the current value of "(<code>"(specialized-array-default-safe?)")".")
(<p>"The body of the result is constructed as ")
(<pre>
(<code>"
((storage-class-maker "(<var>'storage-class)")
(interval-volume "(<var>'interval)")
(storage-class-default "(<var>'storage-class)"))
"))
(<p> "The indexer of the resulting array is constructed as the lexicographical mapping of "(<code>(<var>'interval))" onto the interval "(<code> "[0,(interval-volume "(<var>'interval)"))")".")
(<p> "If "(<code>(<var>'safe))" is "(<code>'#t)", then the arguments of the getter and setter (including the value to be stored) of the resulting array are always checked for correctness.")
(<p> "After correctness checking (if needed), "(<code>"(array-getter "(<var>'array)")")" is defined simply as ")
(<pre>
(<code>"
(lambda multi-index
((storage-class-getter "(<var>'storage-class)")
(array-body "(<var>'array)")
(apply (array-indexer "(<var>'array)") multi-index)))
"))
(<p> " and "(<code>"(array-setter "(<var>'array)")")" is defined as ")
(<pre>
(<code>"
(lambda (val . multi-index)
((storage-class-setter "(<var>'storage-class)")
(array-body "(<var>'array)")
(apply (array-indexer "(<var>'array)") multi-index)
val))
"
))
(<p> "It is an error if the arguments of "(<code>'make-specialized-array)" do not satisfy these conditions.")
(<p> (<b> "Examples. ")"A simple array that can hold any type of element can be defined with "(<code>"(make-specialized-array (make-interval '#(0 0) '#(3 3)))")". If you find that you're using a lot of unsafe arrays of unsigned 16-bit integers, one could define ")
(<pre>
(<code>"
(define (make-u16-array interval)
(make-specialized-array interval u16-storage-class #f))
"))
(<p> "and then simply call, e.g., "(<code>"(make-u16-array (make-interval '#(0 0) '#(3 3)))")".")
(format-lambda-list '(specialized-array? obj))
(<p> "Returns "(<code>"#t")" if "(<code>(<var> 'obj))" is a specialized-array, and "(<code>"#f")" otherwise. A specialized-array is an array.")
(format-lambda-list '(array-storage-class array))
(format-lambda-list '(array-indexer array))
(format-lambda-list '(array-body array))
(format-lambda-list '(array-safe? array))
(<p> (<code>'array-storage-class)" returns the storage-class of "(<code>(<var> 'array))". "
(<code>'array-safe?)" is true if and only if the arguments of "(<code> "(array-getter "(<var> 'array)")")" and "(<code> "(array-setter "(<var> 'array)")")" (including the value to be stored in the array) are checked for correctness.")
(<p> (<code>"(array-indexer "(<var> 'array)")")" is assumed to be a one-to-one, but not necessarily onto, affine mapping from "(<code> "(array-domain "(<var> 'array)")")" into "(<code>"(array-body "(<var> 'array)")")".")
(<p> "It is an error to call any of these routines if "(<code>(<var> 'array))" is not a specialized-array.")
(format-lambda-list '(specialized-array-share array new-domain new-domain->old-domain))
(<p> "Constructs a new specialized-array that shares the body of the specialized-array "(<code>(<var> 'array))".
Returns an object that is behaviorally equivalent to a specialized array with the following fields:")
(<pre>
(<code>"
domain: new-domain
storage-class: (array-storage-class "(<var> 'array)")
body: (array-body "(<var> 'array)")
indexer: (lambda multi-index
(call-with-values
(lambda ()
(apply "(<var>'new-domain->old-domain)"
multi-index))
(array-indexer "(<var> 'array)")))"))
(<p> (<code>(<var> 'new-domain->old-domain))" must be an affine one-to-one mapping from "(<code>(<var> 'new-domain))" to
"(<code>"(array-domain "(<var> 'array)")")".")
(<p> "Note: It is assumed that affine structure of the composition of "(<code>(<var> 'new-domain->old-domain))" and "(<code>"(array-indexer "(<var> 'array))" will be used to simplify:")
(<pre>
(<code>"
(lambda multi-index
(call-with-values
(lambda ()
(apply "(<var>'new-domain->old-domain)" multi-index))
(array-indexer "(<var> 'array)")))"
))
(<p> "It is an error if "(<code>(<var>'array))" is not a specialized array, or if "(<code>(<var>'new-domain))" is not an interval, or if "(<code>(<var>'new-domain->old-domain))" is not a one-to-one affine mapping with the appropriate domain and range.")
(<p> (<b> "Example: ")
"One can apply a \"shearing\" operation to an array as follows: ")
(<pre>
(<code>"
(define a
(array->specialized-array
(make-array (make-interval '#(0 0) '#(5 10))
list)))
(define b
(specialized-array-share
a
(make-interval '#(0 0) '#(5 5))
(lambda (i j)
(values i (+ i j)))))
;; Print the \"rows\" of b
(array-for-each (lambda (row)
(pretty-print (array->list row)))
(array-curry b 1))
;; which prints
;; ((0 0) (0 1) (0 2) (0 3) (0 4))
;; ((1 1) (1 2) (1 3) (1 4) (1 5))
;; ((2 2) (2 3) (2 4) (2 5) (2 6))
;; ((3 3) (3 4) (3 5) (3 6) (3 7))
;; ((4 4) (4 5) (4 6) (4 7) (4 8))
"
))
(<p> "This \"shearing\" operation cannot be achieved by combining the procedures "(<code>'array-extract)", "(<code>'array-translate)", "(<code>'array-permute)", "(<code>'array-translate)", "(<code>'array-curry)", "(<code>'array-reverse)", and "(<code>'array-sample)".")
(format-lambda-list '(array->specialized-array array #\[ result-storage-class "generic-storage-class" #\] #\[ safe? "(specialized-array-default-safe?)" #\]))
(<p> "If "(<code>(<var> 'array))" is an array whose elements can be manipulated by the storage-class
"(<code>(<var> 'result-storage-class))", then the specialized-array returned by "(<code> 'array->specialized-array)" can be defined by:")
(<pre>
(<code>"
(let* ((domain
(array-domain "(<var>'array)"))
(getter
(array-getter "(<var>'array)"))
(result
(make-specialized-array domain
"(<var>'result-storage-class)"
"(<var>'safe?)"))
(result-setter
(array-setter result)))
(interval-for-each (lambda multi-index
(apply result-setter
(apply getter
multi-index)
multi-index))
domain)
result)"))
(<p> "It is guaranteed that "(<code>"(array-getter "(<var>'array)")")" is called precisely once for each multi-index in "(<code>"(array-domain "(<var>'array)")")" in lexicographical order.")
(<p> "It is an error if "(<code>(<var>'result-storage-class))" does not satisfy these conditions, or if "(<code>(<var>'safe?))" is not a boolean.")
(format-lambda-list '(array-curry array inner-dimension))
(<p> "If "
(<code>(<var> 'array))
" is an array whose domain is an interval $[l_0,u_0)\\times\\cdots\\times[l_{d-1},u_{d-1})$, and "
(<code>(<var> 'inner-dimension))
" is an exact integer strictly between $0$ and $d$, then "(<code>'array-curry)" returns an immutable array with domain "
"$[l_0,u_0)\\times\\cdots\\times[l_{d-\\text{inner-dimension}-1},u_{d-\\text{inner-dimension}-1})$"
", each of whose entries is in itself an array with domain $[l_{d-\\text{inner-dimension}},u_{d-\\text{inner-dimension}})\\times\\cdots\\times[l_{d-1},u_{d-1})$.")
(<p> "For example, if "(<code>'A)" and "(<code> 'B)" are defined by ")
(<pre>
(<code>"
(define interval (make-interval '#(0 0 0 0)
'#(10 10 10 10)))
(define A (make-array interval list))
(define B (array-curry A 1))
"))
(<p> "so")
(<pre>
(<code>"
((array-getter A) i j k l) => (list i j k l)"))
(<p> "then "(<code>'B)" is an immutable array with domain "(<code>"(make-interval '#(0 0 0) '#(10 10 10))")", each
of whose elements is itself an (immutable) array and ")
(<pre>
(<code>"
(equal?
((array-getter A) i j k l)
((array-getter ((array-getter B) i j k)) l)) => #t
"))
(<p> "for all multi-indices "(<code> "i j k l")" in "(<code> 'interval)".")
(<p> "The subarrays are immutable, mutable, or specialized according to whether the array argument is immutable, mutable, or specialized.")
(<p> "More precisely, if ")
(<pre>
(<code> "0 < "(<var> 'inner-dimension)" < (interval-dimension (array-domain "(<var> 'array)"))"))
(<p> "then "(<code> 'array-curry)" returns a result as follows.")
(<p> "If the input array is specialized, then array-curry returns")
(<pre>
(<code>"
(call-with-values
(lambda () (interval-projections (array-domain "(<var> 'array)")
"(<var> 'inner-dimension)"))
(lambda (outer-interval inner-interval)
(make-array
outer-interval
(lambda outer-multi-index
(specialized-array-share
"(<var> 'array)"
inner-interval
(lambda inner-multi-index
(apply values
(append outer-multi-index
inner-multi-index))))))))"))
(<p> "Otherwise, if the input array is mutable, then array-curry returns")
(<pre>
(<code>"
(call-with-values
(lambda () (interval-projections (array-domain "(<var> 'array)")
"(<var> 'inner-dimension)"))
(lambda (outer-interval inner-interval)
(make-array
outer-interval
(lambda outer-multi-index
(make-array
inner-interval
(lambda inner-multi-index
(apply (array-getter "(<var> 'array)")
(append outer-multi-index
inner-multi-index)))
(lambda (v . inner-multi-index)
(apply (array-setter "(<var> 'array)")
v
(append outer-multi-index
inner-multi-index))))))))"))
(<p> "Otherwise, array-curry returns")
(<pre>
(<code>"
(call-with-values
(lambda () (interval-projections (array-domain "(<var> 'array)")
"(<var> 'inner-dimension)"))
(lambda (outer-interval inner-interval)
(make-array
outer-interval
(lambda outer-multi-index
(make-array
inner-interval
(lambda inner-multi-index
(apply (array-getter "(<var> 'array)")
(append outer-multi-index
inner-multi-index))))))))"))
(<p> "It is an error to call "(<code> 'array-curry)" if its arguments do not satisfy these conditions.")
(<p>"Example:")
(<pre>
(<code>"
(define a (make-array (make-interval '#(0 0)
'#(10 10))
list))
((array-getter a) 3 4) => (3 4)
(define curried-a (array-curry a 1))
((array-getter ((array-getter curried-a) 3)) 4)
=> (3 4)"))
(format-lambda-list '(array-extract array new-domain))
(<p> "Returns a new array with the same getter (and setter, if appropriate) of the first argument, defined on the second argument.")
(<p> "Assumes that "(<code>(<var> 'array))" is an array and "(<code>(<var> 'new-domain))" is an interval that is a sub-interval of "(<code> "(array-domain "(<var> 'array)")")". If "(<code>(<var>'array))" is a specialized array, then returns ")
(<pre>
(<code>"
(specialized-array-share "(<var> 'array)"
"(<var> 'new-domain)"
values)
"))
(<p> "Otherwise, if "(<code>(<var>'array))" is a mutable array, then "(<code> 'array-extract)" returns ")
(<pre>
(<code>"
(make-array "(<var> 'new-domain)"
(array-getter "(<var> 'array)")
(array-setter "(<var> 'array)"))
" ))
(<p> "Finally, if "(<code>(<var>'array))" is an immutable array, then "(<code> 'array-extract)" returns ")
(<pre>
(<code>"
(make-array "(<var> 'new-domain)"
(array-getter "(<var> 'array)"))
"
))
(<p> "It is an error if the arguments of "(<code>'array-extract)" do not satisfy these conditions.")
(format-lambda-list '(array-translate array translation))
(<p> "Assumes that "(<code>(<var>'array))" is a valid array, "(<code>(<var>'translation))" is a valid translation, and that the dimensions of the array and the translation are the same. The resulting array will have domain "(<code>"(interval-translate (array-domain array) translation)")".")
(<p> "If "(<code>(<var>'array))" is a specialized array, returns a new specialized array")
(<pre>
(<code>"
(specialized-array-share
"(<var>'array)"
(interval-translate (array-domain "(<var>'array)")
"(<var>'translation)")
(lambda multi-index
(apply values
(map -
multi-index
(vector->list "(<var>'translation)")))))
"))
(<p>"that shares the body of "(<code>(<var>'array))".")
(<p> "If "(<code>(<var>'array))" is not a specialized array but is a mutable array, returns a new mutable array")
(<pre>
(<code>"
(make-array
(interval-translate (array-domain "(<var>'array)")
"(<var>'translation)")
(lambda multi-index
(apply (array-getter "(<var>'array)")
(map -
multi-index
(vector->list "(<var>'translation)"))))
(lambda (val . multi-index)
(apply (array-setter "(<var>'array)")
val
(map -
multi-index
(vector->list "(<var>'translation)")))))
"))
(<p> "that employs the same getter and setter as the original array argument.")
(<p> "If "(<code>(<var>'array))" is not a mutable array, returns a new array")
(<pre>
(<code>"
(make-array
(interval-translate (array-domain "(<var>'array)")
"(<var>'translation)")
(lambda multi-index
(apply (array-getter "(<var>'array)")
(map - multi-index (vector->list "(<var>'translation)")))))
"))
(<p> "that employs the same getter as the original array.")
(<p> "It is an error if the arguments do not satisfy these conditions.")
(format-lambda-list '(array-permute array permutation))
(<p> "Assumes that "(<code>(<var>'array))" is a valid array, "(<code>(<var>'permutation))" is a valid permutation, and that the dimensions of the array and the permutation are the same. The resulting array will have domain "(<code>"(interval-permute (array-domain array) permutation)")".")
(<p> "We begin with an example. Assume that the domain of "(<code>(<var>'array))" is represented by the interval $[0,4)\\times[0,8)\\times[0,21)\\times [0,16)$, as in the example for "(<code>'interval-permute)", and the permutation is "(<code>'#(3 0 1 2))". Then the domain of the new array is the interval $[0,16)\\times [0,4)\\times[0,8)\\times[0,21)$.")
(<p> "So the multi-index argument of the "(<code>'getter)" of the result of "(<code>'array-permute)" must lie in the new domain of the array, the interval $[0,16)\\times [0,4)\\times[0,8)\\times[0,21)$. So if we define "(<code>(<var>'old-getter))" as "(<code>"(array-getter "(<var>'array)")")", the definition of the new array must be in fact")
(<pre>
(<code>"
(make-array (interval-permute (array-domain "(<var>'array)")
'#(3 0 1 2))
(lambda (l i j k)
(old-getter i j k l)))
" ))
(<p> "So you see that if the first argument if the new getter is in $[0,16)$, then indeed the fourth argument of "(<code>(<var>'old-getter))" is also in $[0,16)$, as it should be. This is a subtlety that I don't see how to overcome. It is the listing of the arguments of the new getter, the "(<code>'lambda)", that must be permuted.")
(<p> "Mathematically, we can define $\\pi^{-1}$, the inverse of a permutation $\\pi$, such that $\\pi^{-1}$ composed with $\\pi$ gives the identity permutation. Then the getter of the new array is, in pseudo-code, "(<code>"(lambda multi-index (apply "(<var>'old-getter)" (")"$\\pi^{-1}$"(<code>" multi-index)))")". We have assumed that $\\pi^{-1}$ takes a list as an argument and returns a list as a result.")
(<p> "Employing this same pseudo-code, if "(<code>(<var>'array))" is a specialized-array and we denote the permutation by $\\pi$, then "(<code>'array-permute)" returns the new specialized array")
(<pre>(<code>"
(specialized-array-share "(<var>'array)"
(interval-permute (array-domain "(<var>'array)") "(<unprotected>"π")")
(lambda multi-index
(apply values ("(<unprotected> "π")(<sup>"-1")" multi-index))))"))
(<p> "The result array shares "(<code>"(array-body "(<var>'array)")")" with the argument.")
(<p> "Again employing this same pseudo-code, if "(<code>(<var>'array))" is not a specialized array, but is
a mutable-array, then "(<code>'array-permute)" returns the new mutable")
(<pre>(<code>"
(make-array (interval-permute (array-domain "(<var>'array)") "(<unprotected>"π")")
(lambda multi-index
(apply (array-getter "(<var>'array)")
("(<unprotected> "π")(<sup>"-1")" multi-index)))
(lambda (val . multi-index)
(apply (array-setter "(<var>'array)")
val
("(<unprotected> "π")(<sup>"-1")" multi-index))))"))
(<p> "which employs the setter and the getter of the argument to "(<code>'array-permute)".")
(<p> "Finally, if "(<code>(<var>'array))" is not a mutable array, then "(<code>'array-permute)" returns")
(<pre>(<code>"
(make-array (interval-permute (array-domain "(<var>'array)") "(<unprotected>"π")")
(lambda multi-index
(apply (array-getter "(<var>'array)")
("(<unprotected> "π")(<sup>"-1")" multi-index))))"))
(<p>"It is an error to call "(<code>'array-permute)" if its arguments do not satisfy these conditions.")
(format-lambda-list '(array-reverse array flip?))
(<p> "We assume that "(<code>(<var>'array))" is an array and "(<code>(<var>'flip?))" is a vector of booleans whose length is the same as the dimension of "(<code>(<var>'array))".")
(<p> (<code>'array-reverse)" returns a new array that is specialized, mutable, or immutable according to whether "(<code>(<var>'array))" is specialized, mutable, or immutable, respectively. Informally, if "(<code>"(vector-ref "(<var>'flip?)" k)")" is true, then the ordering of multi-indices in the k'th coordinate direction is reversed, and is left undisturbed otherwise.")
(<p> "More formally, we introduce the function ")
(<pre>
(<code>"
(define flip-multi-index
(let* ((domain (array-domain "(<code>(<var>'array))"))
(lowers (interval-lower-bounds->list domain))
(uppers (interval-upper-bounds->list domain)))
(lambda (multi-index)
(map (lambda (i_k flip?_k l_k u_k)
(if flip?
(- (+ l_k u_k -1) i_k)
i_k))
multi-index
(vector->list "(<var>'flip?)")
lowers
uppers))))"))
(<p> "Then if "(<code>(<var>'array))" is specialized, then "(<code>'array-reverse)" returns ")
(<pre>
(<code>"
(specialized-array-share
"(<code>(<var>'array))"
domain
(lambda multi-index
(apply values
(flip-multi-index multi-index))))"))
(<p> "Otherwise, if "(<code>(<var>'array))" is mutable, then "(<code>'array-reverse)" returns")
(<pre>
(<code>"
(make-array
domain
(lambda multi-index
(apply (array-getter "(<code>(<var>'array))")
(flip-multi-index multi-index)))
(lambda (v . multi-index)
(apply (array-setter "(<code>(<var>'array))")
v
(flip-multi-index multi-index)))))"))
(<p> "Finally, if "(<code>(<var>'array))" is immutable, then "(<code>'array-reverse)" returns ")
(<pre>
(<code>"
(make-array
domain
(lambda multi-index
(apply (array-getter "(<code>(<var>'array))")
(flip-multi-index multi-index))))) "))
(<p> "It is an error if "(<code>(<var>'array))" and "(<code>(<var>'flip?))" don't satisfy these requirements.")
(format-lambda-list '(array-sample array scales))
(<p> "We assume that "(<code>(<var>'array))" is an array all of whose lower bounds are zero, "
"and "(<code>(<var>'scales))" is a vector of positive exact integers whose length is the same as the dimension of "(<code>(<var>'array))".")
(<p> (<code>'array-sample)" returns a new array that is specialized, mutable, or immutable according to whether "(<code>(<var>'array))" is specialized, mutable, or immutable, respectively. Informally, if we construct a new matrix $S$ with the entries of "(<code>(<var>'scales))" on the main diagonal, then "
"the $\\vec i$th element of "(<code>"(array-sample "(<var>'array)" "(<var>'scales)")")" is the $S\\vec i$th element of "(<code>(<var>'array))".")
(<p> "More formally, if "(<code>(<var>'array))" is specialized, then "(<code>'array-sample)" returns ")
(<pre>
(<code>"
(specialized-array-share
"(<code>(<var>'array))"
(interval-scale (array-domain "(<code>(<var>'array))")
"(<code>(<var>'scales))")
(lambda multi-index
(apply values
(map * multi-index (vector->list "(<code>(<var>'scales))")))))"))
(<p> "Otherwise, if "(<code>(<var>'array))" is mutable, then "(<code>'array-sample)" returns")
(<pre>
(<code>"
(make-array
(interval-scale (array-domain "(<code>(<var>'array))")
"(<code>(<var>'scales))")
(lambda multi-index
(apply (array-getter "(<code>(<var>'array))")
(map * multi-index (vector->list "(<code>(<var>'scales))"))))
(lambda (v . multi-index)
(apply (array-setter "(<code>(<var>'array))")
v
(map * multi-index (vector->list "(<code>(<var>'scales))")))))"))
(<p> "Finally, if "(<code>(<var>'array))" is immutable, then "(<code>'array-sample)" returns ")
(<pre>
(<code>"
(make-array
(interval-scale (array-domain "(<code>(<var>'array))")
"(<code>(<var>'scales))")
(lambda multi-index
(apply (array-getter "(<code>(<var>'array))")
(map * multi-index (vector->list "(<code>(<var>'scales))")))))"))
(<p> "It is an error if "(<code>(<var>'array))" and "(<code>(<var>'scales))" don't satisfy these requirements.")
(format-lambda-list '(array-map f array #\. arrays))
(<p> "If "(<code>(<var> 'array))", "(<code>"(car "(<var> 'arrays)")")", ... all have the same domain and "(<code>(<var> 'f))" is a procedure, then "(<code> 'array-map)"
returns a new array with the same domain and getter")
(<pre>
(<code>"
(lambda multi-index
(apply "(<var>'f)"
(map (lambda (g)
(apply g multi-index))
(map array-getter
(cons "(<var> 'array)" "(<var> 'arrays)")))))"))
(<p> "It is assumed that "(<code>(<var> 'f))" is appropriately defined to be evaluated in this context.")
(<p> "It is an error to call "(<code> 'array-map)" if its arguments do not satisfy these conditions.")
(format-lambda-list '(array-for-each f array #\. arrays))
(<p> "If "(<code>(<var> 'array))", "(<code>"(car "(<var> 'arrays)")")", ... all have the same domain and "(<code>(<var> 'f))" is an appropriate procedure, then "(<code> 'array-for-each)"
calls")
(<pre>
(<code>"
(interval-for-each
(lambda multi-index
(apply "(<var>'f)"
(map (lambda (g)
(apply g multi-index))
(map array-getter
(cons "(<var> 'array)"
"(<var> 'arrays)")))))
(array-domain "(<var> 'array)"))"))
(<p> "In particular, "(<code> 'array-for-each)" always walks the indices of the arrays in lexicographical order.")
(<p> "It is expected that "(<code> 'array-map)" and "(<code> 'array-for-each)" will specialize the construction of")
(<pre>
(<code>"
(lambda multi-index
(apply "(<var>'f)"
(map (lambda (g)
(apply g multi-index))
(map array-getter
(cons "(<var> 'array)"
"(<var> 'arrays)")))))"))
(<p> "It is an error to call "(<code> 'array-for-each)" if its arguments do not satisfy these conditions.")
(format-lambda-list '(array-fold kons knil array))
(<p> "If we use the defining relations for fold over lists from SRFI-1:")
(<pre>
(<code>"
(fold kons knil lis)
= (fold kons (kons (car lis) knil) (cdr lis))
(fold kons knil '())
= knil
"))
(<p> "then "(<code>"(array-fold "(<var>'kons)" " (<var>'knil)" "(<var> 'array)")")" returns ")
(<pre>
(<code>"
(fold "(<var>'kons)" " (<var>'knil)" (array->list "(<var> 'array)"))"))
(<p> "It is an error if "(<code>(<var>'array))" is not an array, or if "(<code>(<var>'kons))" is not a procedure.")
(format-lambda-list '(array-fold-right kons knil array))
(<p> "If we use the defining relations for fold-right over lists from SRFI-1:")
(<pre>
(<code>"
(fold-right kons knil lis)
= (kons (car lis) (fold-right kons knil (cdr lis)))
(fold-right kons knil '())
= knil
"))
(<p> "then "(<code>"(array-fold-right "(<var>'kons)" " (<var>'knil)" "(<var> 'array)")")" returns ")
(<pre>
(<code>"
(fold-right "(<var>'kons)" " (<var>'knil)" (array->list "(<var> 'array)"))"))
(<p> "It is an error if "(<code>(<var>'array))" is not an array, or if "(<code>(<var>'kons))" is not a procedure.")
(format-lambda-list '(array-any pred array1 array2 "..."))
(<p> "Assumes that "(<code>(<var>'array1))", "(<code>(<var>'array2))", etc., are arrays, all with the same domain, which we'll call "(<code>'interval)". Also assumes that "(<code>(<var>'pred))" is a procedure that takes as many arguments as there are arrays and returns a single value.")
(<p> (<code>'array-any)" first applies "(<code>"(array-getter "(<var>'array1)")")", etc., to the first element of "(<code>'interval)" in lexicographical order, to which values it then applies "(<code>(<var>'pred))".")
(<p> "If the result of "(<code>(<var>'pred))" is not "(<code>'#f)", then that result is returned by "(<code>'array-any)". If the result of "(<code>(<var>'pred))" is "(<code>'#f)", then "(<code>'array-any)" continues with the second element of "(<code>'interval)", etc., returning the first nonfalse value of "(<code>(<var>'pred))".")
(<p> "If "(<code>(<var>'pred))" always returns "(<code>'#f)", then "(<code>'array-any)" returns "(<code>'#f)".")
(<p> "If it happens that "(<code>(<var>'pred))" is applied to the results of applying "(<code>"(array-getter "(<var>'array1)")")", etc., to the last element of "(<code>'interval)", then this last call to "(<code>(<var>'pred))" is in tail position.")
(<p> "The functions "(<code>"(array-getter "(<var>'array1)")")", etc., are applied only to those values of "(<code>'interval)" necessary to determine the result of "(<code>'array-any)".")
(<p> "It is an error if the arguments do not satisfy these assumptions.")
(format-lambda-list '(array-every pred array1 array2 "..."))
(<p> "Assumes that "(<code>(<var>'array1))", "(<code>(<var>'array2))", etc., are arrays, all with the same domain, which we'll call "(<code>'interval)". Also assumes that "(<code>(<var>'pred))" is a procedure that takes as many arguments as there are arrays and returns a single value.")
(<p> (<code>'array-every)" first applies "(<code>"(array-getter "(<var>'array1)")")", etc., to the first element of "(<code>'interval)" in lexicographical order, to which values it then applies "(<code>(<var>'pred))".")
(<p> "If the result of "(<code>(<var>'pred))" is "(<code>'#f)", then that result is returned by "(<code>'array-every)". If the result of "(<code>(<var>'pred))" is nonfalse, then "(<code>'array-every)" continues with the second element of "(<code>'interval)", etc., returning the first value of "(<code>(<var>'pred))" that is "(<code>'#f)".")
(<p> "If "(<code>(<var>'pred))" always returns a nonfalse value, then the last nonfalse value returned by "(<code>(<var>'pred))" is also returned by "(<code>'array-every)".")
(<p> "If it happens that "(<code>(<var>'pred))" is applied to the results of applying "(<code>"(array-getter "(<var>'array1)")")", etc., to the last element of "(<code>'interval)", then this last call to "(<code>(<var>'pred))" is in tail position.")
(<p> "The functions "(<code>"(array-getter "(<var>'array1)")")", etc., are applied only to those values of "(<code>'interval)" necessary to determine the result of "(<code>'array-every)".")
(<p> "It is an error if the arguments do not satisfy these assumptions.")
(format-lambda-list '(array->list array))
(<p> "Stores the elements of "(<code>(<var>'array))" into a newly-allocated list in lexicographical order. It is an error if "(<code>(<var>'array))" is not an array.")
(format-lambda-list '(list->specialized-array l interval #\[ result-storage-class "generic-storage-class" #\] #\[ safe? "(specialized-array-default-safe?)" #\]))
(<p> "Returns a specialized-array with domain "(<code>(<var>'interval))" whose elements are the elements of the list "(<code>(<var>'l))" stored in lexicographical order. It is an error if "(<code>(<var>'l))" is not a list, if "(<code>(<var>'interval))" is not an interval, if the length of "(<code>(<var>'l))" is not the same as the volume of "(<code>(<var>'interval))", if "(<code>(<var>'result-storage-class))" (when given) is not a storage class, if "(<code>(<var>'safe?))" (when given) is not a boolean, or if any element of "(<code>(<var>'l))" cannot be stored in the body of "(<code>(<var>'result-storage-class))", and this last error shall be detected and raised if "(<code>(<var>'safe))" is "(<code>'#t)".")
(<h2> "Implementation")
(<p> "We provide an implementation in Gambit-C; the nonstandard techniques used
in the implementation are: DSSSL-style optional and keyword arguments; a
unique object to indicate absent arguments; "(<code>"define-structure")";
and "(<code>"define-macro")".")
(<h2> "Relationship to other SRFIs")
(<p> "Final SRFIs "(<a> href: "#SRFI-25" "25")", "(<a> href: "#SRFI-47" "47")", "(<a> href: "#SRFI-58" "58")", and "(<a> href: "#SRFI-63" "63")" deal with \"Multi-dimensional Array Primitives\", \"Array\", \"Array Notation\",
and \"Homogeneous and Heterogeneous Arrays\", respectively. Each of these previous SRFIs deal with what we call in this SRFI
specialized-arrays. Many of the functions in these previous SRFIs have corresponding forms in this SRFI. For example, from SRFI 63, we can
translate: ")
(<dl>
(<dt> (<code> "(array? obj)"))
(<dd> (<code> "(array? obj)"))
(<dt> (<code> "(array-rank a)"))
(<dd> (<code> "(array-dimension obj)"))
(<dt> (<code> "(make-array prototype k1 ...)"))
(<dd> (<code> "(make-specialized-array (make-interval (vector 0 ...) (vector k1 ...)) storage-class)")".")
(<dt> (<code> "(make-shared-array array mapper k1 ...)"))
(<dd> (<code> "(specialized-array-share array (make-interval (vector 0 ...) (vector k1 ...)) mapper)"))
(<dt> (<code> "(array-in-bounds? array index1 ...)"))
(<dd> (<code> "(interval-contains-multi-index? (array-domain array) index1 ...)"))
(<dt> (<code> "(array-ref array k1 ...)"))
(<dd> (<code> "((array-getter array) k1 ...)"))
(<dt> (<code> "(array-set! array obj k1 ...)"))
(<dd> (<code> "((array-setter array) obj k1 ...)"))
)
(<p> "At the same time, this SRFI has some special features:")
(<ul>
(<li> "Intervals, used as the domains of arrays in this SRFI, are useful
objects in their own rights, with their own procedures. We make a sharp distinction between the domains
of arrays and the arrays themselves.")
(<li> "Intervals can have nonzero lower bounds in each dimension.")
(<li> "Intervals cannot be empty.")
(<li> "Arrays must have a getter, but may have no setter."))
(<h2> "Other examples")
(<p> "Image processing applications provided significant motivation for this SRFI.")
(<p> (<b> "Reading an image file in PGM format. ")"On a system with eight-bit chars, one
can write a function to read greyscale images in the PGM format of the netpbm package as follows. The lexicographical
order in array->specialized-array guarantees the the correct order of execution of the input procedures:")
(<pre>
(<code>"
(define make-pgm cons)
(define pgm-greys car)
(define pgm-pixels cdr)
(define (read-pgm file)
(define (read-pgm-object port)
(skip-white-space port)
(let ((o (read port)))
;; to skip the newline or next whitespace
(read-char port)
(if (eof-object? o)
(error \"reached end of pgm file\")
o)))
(define (skip-to-end-of-line port)
(let loop ((ch (read-char port)))
(if (not (eq? ch #\\newline))
(loop (read-char port)))))
(define (white-space? ch)
(case ch
((#\\newline #\\space #\\tab) #t)
(else #f)))
(define (skip-white-space port)
(let ((ch (peek-char port)))
(cond ((white-space? ch)
(read-char port)
(skip-white-space port))
((eq? ch #\\#)
(skip-to-end-of-line port)
(skip-white-space port))
(else #f))))
;; The image file formats defined in netpbm
;; are problematical, because they read the data
;; in the header as variable-length ISO-8859-1 text,
;; including arbitrary whitespace and comments,
;; and then they may read the rest of the file
;; as binary data.
;; So we give here a solution of how to deal
;; with these subtleties in Gambit Scheme.
(call-with-input-file
(list path: file
char-encoding: 'ISO-8859-1
eol-encoding: 'lf)
(lambda (port)
;; We're going to read text for a while,
;; then switch to binary.
;; So we need to turn off buffering until
;; we switch to binary.
(port-settings-set! port '(buffering: #f))
(let* ((header (read-pgm-object port))
(columns (read-pgm-object port))
(rows (read-pgm-object port))
(greys (read-pgm-object port)))
;; now we switch back to buffering
;; to speed things up
(port-settings-set! port '(buffering: #t))
(make-pgm
greys
(array->specialized-array
(make-array
(make-interval '#(0 0)
(vector rows columns))
(cond ((or (eq? header 'p5)
(eq? header 'P5))
;; pgm binary
(if (< greys 256)
;; one byte/pixel
(lambda (i j)
(char->integer
(read-char port)))
;; two bytes/pixel,
;;little-endian
(lambda (i j)
(let* ((first-byte
(char->integer
(read-char port)))
(second-byte
(char->integer
(read-char port))))
(+ (* second-byte 256)
first-byte)))))
;; pgm ascii
((or (eq? header 'p2)
(eq? header 'P2))
(lambda (i j)
(read port)))
(else
(error \"not a pgm file\"))))
(if (< greys 256)
u8-storage-class
u16-storage-class)))))))"
))
(<p> (<b> "Viewing two-dimensional slices of three-dimensional data. ")"One example might be viewing two-dimensional slices of three-dimensional data in different ways. If one has a $1024 \\times 512\\times 512$ 3D image of the body stored as a variable "(<code>(<var>'body))", then one could get 1024 axial views, each $512\\times512$, of this 3D body by "(<code> "(array-curry "(<var>'body)" 2)")"; or 512 median views, each $1024\\times512$, by "(<code> "(array-curry (array-permute "(<var>'body)" '#(1 0 2)) 2)")"; or finally 512 frontal views, each again $1024\\times512$ pixels, by "(<code> "(array-curry (array-permute "(<var>'body)" '#(2 0 1)) 2)")"; see "(<a> href: "https://en.wikipedia.org/wiki/Anatomical_plane" "Anatomical plane")".")
(<p> (<b> "Calculating second differences of images. ")"For another example, if a real-valued function is defined
on a two-dimensional interval $I$, its second difference in the direction $d$ at the point $x$ is defined as $\\Delta^2_df(x)=f(x+2d)-2f(x+d)+f(x)$,
and this function is defined only for those $x$ for which $x$, $x+d$, and $x+2d$ are all in $I$. See the beginning of the section on \"Moduli of smoothness\" in "(<a> href: "http://www.math.purdue.edu/~lucier/692/related_papers_summaries.html#Wavelets-and-approximation-theory" "these notes on wavelets and approximation theory")" for more details.")
(<p> "Using this definition, the following code computes all second-order forward differences of an image in the directions
$d,2 d,3 d,\\ldots$, defined only on the domains where this makes sense: ")
(<pre>
(<code>"
(define (all-second-differences image direction)
(let ((image-domain (array-domain image)))
(let loop ((i 1)
(result '()))
(let ((negative-scaled-direction
(vector-map (lambda (j)
(* -1 j i))
direction))
(twice-negative-scaled-direction
(vector-map (lambda (j)
(* -2 j i))
direction)))
(cond ((interval-intersect
image-domain
(interval-translate
image-domain
negative-scaled-direction)
(interval-translate
image-domain
twice-negative-scaled-direction))
=>
(lambda (subdomain)
(loop
(+ i 1)
(cons
(array->specialized-array
(array-map
(lambda (f_i f_i+d f_i+2d)
(+ f_i+2d
(* -2. f_i+d)
f_i))
(array-extract
image
subdomain)
(array-extract
(array-translate
image
negative-scaled-direction)
subdomain)
(array-extract
(array-translate
image
twice-negative-scaled-direction)
subdomain)))
result))))
(else
(reverse result)))))))
"))
(<p> "We can define a small synthetic image of size 8x8 pixels and compute its second differences in various directions: ")
(<pre>(<code> "
(define image
(array->specialized-array
(make-array (make-interval '#(0 0) '#(8 8))
(lambda (i j)
(exact->inexact (+ (* i i) (* j j)))))))
(define (expose difference-images)
(pretty-print (map (lambda (difference-image)
(list (array-domain difference-image)
(array->list difference-image)))
difference-images)))
(begin
(display
\"\\nSecond-differences in the direction $k\\times (1,0)$:\\n\")
(expose (all-second-differences image '#(1 0)))
(display
\"\\nSecond-differences in the direction $k\\times (1,1)$:\\n\")
(expose (all-second-differences image '#(1 1)))
(display
\"\\nSecond-differences in the direction $k\\times (1,-1)$:\\n\")
(expose (all-second-differences image '#(1 -1))))
"))
(<p> "On Gambit 4.8.5, this yields (after some hand editing): ")
(<pre> "
Second-differences in the direction $k\\times (1,0)$:
((#<##interval #2 lower-bounds: #(0 0) upper-bounds: #(6 8)>
(2. 2. 2. 2. 2. 2. 2. 2. 2. 2. 2. 2. 2. 2. 2. 2.
2. 2. 2. 2. 2. 2. 2. 2. 2. 2. 2. 2. 2. 2. 2. 2.
2. 2. 2. 2. 2. 2. 2. 2. 2. 2. 2. 2. 2. 2. 2. 2.))
(#<##interval #3 lower-bounds: #(0 0) upper-bounds: #(4 8)>
(8. 8. 8. 8. 8. 8. 8. 8. 8. 8. 8. 8. 8. 8. 8. 8.
8. 8. 8. 8. 8. 8. 8. 8. 8. 8. 8. 8. 8. 8. 8. 8.))
(#<##interval #4 lower-bounds: #(0 0) upper-bounds: #(2 8)>
(18. 18. 18. 18. 18. 18. 18. 18. 18.
18. 18. 18. 18. 18. 18. 18.)))
Second-differences in the direction $k\\times (1,1)$:
((#<##interval #5 lower-bounds: #(0 0) upper-bounds: #(6 6)>
(4. 4. 4. 4. 4. 4. 4. 4. 4. 4. 4. 4. 4. 4. 4. 4. 4. 4. 4.
4. 4. 4. 4. 4. 4. 4. 4. 4. 4. 4. 4. 4. 4. 4. 4. 4.))
(#<##interval #6 lower-bounds: #(0 0) upper-bounds: #(4 4)>
(16. 16. 16. 16. 16. 16. 16. 16. 16. 16. 16. 16. 16. 16.
16. 16.))
(#<##interval #7 lower-bounds: #(0 0) upper-bounds: #(2 2)>
(36. 36. 36. 36.)))
Second-differences in the direction $k\\times (1,-1)$:
((#<##interval #8 lower-bounds: #(0 2) upper-bounds: #(6 8)>
(4. 4. 4. 4. 4. 4. 4. 4. 4. 4. 4. 4. 4. 4. 4. 4. 4. 4. 4.
4. 4. 4. 4. 4. 4. 4. 4. 4. 4. 4. 4. 4. 4. 4. 4. 4.))
(#<##interval #9 lower-bounds: #(0 4) upper-bounds: #(4 8)>
(16. 16. 16. 16. 16. 16. 16. 16. 16. 16. 16. 16. 16. 16.
16. 16.))
(#<##interval #10 lower-bounds: #(0 6) upper-bounds: #(2 8)>
(36. 36. 36. 36.)))
")
(<p> "You can see that with differences in the direction of only the first coordinate, the domains of the difference arrays get smaller in the first coordinate while staying the same in the second coordinate, and with differences in the diagonal directions, the domains of the difference arrays get smaller in both coordinates.")
(<p> (<b> "Separable operators. ")"Many multi-dimensional transforms in signal processing are "(<i> 'separable)", in that that the multi-dimensional transform can be computed by applying one-dimensional transforms in each of the coordinate directions. Examples of such transforms include the Fast Fourier Transform and the Fast Wavelet Transform. Each one-dimensional subdomain of the complete domain is called a "(<i> 'pencil)", and the same one-dimensional transform is applied to all pencils in a given direction. Given the one-dimensional array transform, one can compute the multidimensional transform as follows:")
(<pre> (<code>"
(define (make-separable-transform 1D-transform)
(lambda (array)
;; Works on arrays of any dimension.
(let* ((n
(array-dimension array))
(permutation
;; we start with the identity permutation
(let ((result (make-vector n)))
(do ((i 0 (fx+ i 1)))
((fx= i n) result)
(vector-set! result i i)))))
;; We apply the one-dimensional transform
;; in each coordinate direction.
(do ((d 0 (fx+ d 1)))
((fx= d n))
;; Swap the d'th and n-1'st coordinates
(vector-set! permutation (fx- n 1) d)
(vector-set! permutation d (fx- n 1))
;; Apply the transform in the d'th coordinate
;; direction to all \"pencils\" in that direction.
;; array-permute re-orders the coordinates to
;; put the d'th coordinate at the end, array-curry
;; returns an $n-1$-dimensional array of
;; one-dimensional subarrays, and 1D-transform
;; is applied to each of those sub-arrays.
(array-for-each
1D-transform
(array-curry (array-permute array permutation)
1))
;; return the permutation to the identity
(vector-set! permutation d d)
(vector-set! permutation (fx- n 1) (fx- n 1))))))
"))
(<p> "We can test this by turning a one-dimensional Haar wavelet transform into a multi-dimensional Haar transform:")
(<pre>
(<code>"
(define (1D-Haar-loop a)
(let ((getter (array-getter a))
(setter (array-setter a))
(n (interval-upper-bound (array-domain a) 0)))
(do ((i 0 (fx+ i 2)))
((fx= i n))
(let* ((a_i
(getter i))
(a_i+1
(getter (fx+ i 1)))
(scaled-sum
(fl/ (fl+ a_i a_i+1) (flsqrt 2.0)))
(scaled-difference
(fl/ (fl- a_i a_i+1) (flsqrt 2.0))))
(setter scaled-sum i)
(setter scaled-difference (fx+ i 1))))))
(define (1D-Haar-transform a)
;; works only on mutable arrays with domains
;; $[0, 2^k)$ for some $k$
(let ((n (interval-upper-bound (array-domain a) 0)))
(if (fx< 1 n)
(begin
;; calculate the scaled sums and differences
(1D-Haar-loop a)
;; Apply the transform to the
;; sub-array of scaled sums
(1D-Haar-transform (array-sample a '#(2)))))))
(define (1D-Haar-inverse-transform a)
;; works only on mutable arrays with domains
;; $[0, 2^k)$ for some $k$
(let* ((n (interval-upper-bound (array-domain a) 0)))
(if (fx< 1 n)
(begin
;; Apply the inverse transform to
;; get the array of scaled sums
(1D-Haar-inverse-transform
(array-sample a '#(2)))
;; reconstruct the array values from
;; the scaled sums and differences
(1D-Haar-loop a)))))
(define Haar-transform
(make-separable-transform 1D-Haar-transform))
(define Haar-inverse-transform
(make-separable-transform 1D-Haar-inverse-transform))
" ))
(<p> "We then define an image that is a multiple of a single, two-dimensional Haar wavelet, compute its transform (which should be nonzero for only a single Haar coefficient), and then the inverse transform:")
(<pre>
(<code>"
(let ((image
(array->specialized-array
(make-array (make-interval '#(0 0) '#(4 4))
(lambda (i j)
(if (fx< i 2) 1. -1.))))))
(display \"\\nInitial image: \\n\")
(pretty-print (list (array-domain image)
(array->list image)))
(Haar-transform image)
(display \"\\nArray of Haar wavelet coefficients: \\n\")
(pretty-print (list (array-domain image)
(array->list image)))
(Haar-inverse-transform image)
(display \"\\nReconstructed image: \\n\")
(pretty-print (list (array-domain image)
(array->list image))))
"))
(<p> "This yields: ")
(<pre>"
Initial image:
(#<##interval #11 lower-bounds: #(0 0) upper-bounds: #(4 4)>
(1. 1. 1. 1. 1. 1. 1. 1. -1. -1. -1. -1. -1. -1. -1. -1.))
Array of Haar wavelet coefficients:
(#<##interval #11 lower-bounds: #(0 0) upper-bounds: #(4 4)>
(0. 0. 0. 0. 0. 0. 0. 0. 3.9999999999999987
0. 0. 0. 0. 0. 0. 0.))
Reconstructed image:
(#<##interval #11 lower-bounds: #(0 0) upper-bounds: #(4 4)>
(.9999999999999993
.9999999999999993
.9999999999999993
.9999999999999993
.9999999999999993
.9999999999999993
.9999999999999993
.9999999999999993
-.9999999999999993
-.9999999999999993
-.9999999999999993
-.9999999999999993
-.9999999999999993
-.9999999999999993
-.9999999999999993
-.9999999999999993))
" )
(<p> "In perfect arithmetic, this Haar transform is "(<i>'orthonormal)", in that the sum of the squares of the elements of the image is the same as the sum of the squares of the Haar coefficients of the image. We can see that this is approximately true here.")
(<h2> "Acknowledgments")
(<p> "The SRFI author thanks Edinah K Gnang, John Cowan, Sudarshan S Chawathe, Jamison Hope, and Per Bothner for their comments and suggestions, and Arthur A Gleckler, SRFI Editor, for his guidance and patience.")
(<h2> "References")
(<ol>
(<li> (<a> name: 'bawden href: "http://groups-beta.google.com/group/comp.lang.scheme/msg/6c2f85dbb15d986b?hl=en&" "\"multi-dimensional arrays in R5RS?\"")
", by Alan Bawden.")
(<li> (<a> name: 'SRFI-4 href: "http://srfi.schemers.org/srfi-4/" "SRFI 4: Homogeneous Numeric Vector Datatypes")", by Marc Feeley.")
(<li> (<a> name: 'SRFI-25 href: "http://srfi.schemers.org/srfi-25/" "SRFI 25: Multi-dimensional Array Primitives")", by Jussi Piitulainen.")
(<li> (<a> name: 'SRFI-47 href: "http://srfi.schemers.org/srfi-47/" "SRFI 47: Array")", by Aubrey Jaffer.")
(<li> (<a> name: 'SRFI-58 href: "http://srfi.schemers.org/srfi-58/" "SRFI 58: Array Notation")", by Aubrey Jaffer.")
(<li> (<a> name: 'SRFI-63 href: "http://srfi.schemers.org/srfi-63/" "SRFI 63: Homogeneous and Heterogeneous Arrays")", by Aubrey Jaffer."))
(<h2> "Copyright")
(<p> (<unprotected> "©")" 2016 Bradley J Lucier. All Rights Reserved.")
(<p> "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: ")
(<p> "The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.")
(<p> " 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.
")
))))))
| false |
9a78ea146a847a07f97a594caaed200f4a53a92e
|
4bd59493b25febc53ac9e62c259383fba410ec0e
|
/Scripts/Task/combinations/scheme/combinations.ss
|
d996ce2fa39dcd2aba56fce10746ec39820f7513
|
[] |
no_license
|
stefanos1316/Rosetta-Code-Research
|
160a64ea4be0b5dcce79b961793acb60c3e9696b
|
de36e40041021ba47eabd84ecd1796cf01607514
|
refs/heads/master
| 2021-03-24T10:18:49.444120 | 2017-08-28T11:21:42 | 2017-08-28T11:21:42 | 88,520,573 | 5 | 1 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 251 |
ss
|
combinations.ss
|
(define (comb m lst)
(cond ((= m 0) '(()))
((null? lst) '())
(else (append (map (lambda (y) (cons (car lst) y))
(comb (- m 1) (cdr lst)))
(comb m (cdr lst))))))
(comb 3 '(0 1 2 3 4))
| false |
0bf7d6e838c2d8f4bfbd2cab53d841773f78d269
|
2e50e13dddf57917018ab042f3410a4256b02dcf
|
/contrib/20.r7rs/scheme/write.scm
|
2e495373a117c37af891904dcda64f8d4b9d01b8
|
[
"MIT"
] |
permissive
|
koba-e964/picrin
|
c0ca2596b98a96bcad4da9ec77cf52ce04870482
|
0f17caae6c112de763f4e18c0aebaa73a958d4f6
|
refs/heads/master
| 2021-01-22T12:44:29.137052 | 2016-07-10T16:12:36 | 2016-07-10T16:12:36 | 17,021,900 | 0 | 0 |
MIT
| 2019-05-17T03:46:41 | 2014-02-20T13:55:33 |
Scheme
|
UTF-8
|
Scheme
| false | false | 139 |
scm
|
write.scm
|
(define-library (scheme write)
(import (picrin base))
(export write
write-simple
write-shared
display))
| false |
0e376d1a25fd42a1f85d39dd2e501431a8dd09a7
|
b62560d3387ed544da2bbe9b011ec5cd6403d440
|
/cogs/collections/dll.scm
|
c1ae385a92bc983773c0f9ab6a518f6da7969add
|
[
"LicenseRef-scancode-unknown-license-reference",
"MIT",
"Apache-2.0"
] |
permissive
|
mattwparas/steel
|
c6fb91b20c4e613e6a8db9d9310d1e1c72313df2
|
700144a5a1aeb33cbdb2f66440bbe38cf4152458
|
refs/heads/master
| 2023-09-04T03:41:35.352916 | 2023-09-01T03:26:01 | 2023-09-01T03:26:01 | 241,949,362 | 207 | 10 |
Apache-2.0
| 2023-09-06T04:31:21 | 2020-02-20T17:39:28 |
Rust
|
UTF-8
|
Scheme
| false | false | 2,226 |
scm
|
dll.scm
|
(struct dllist (head tail) #:mutable #:transparent)
(struct dllink (content prev next) #:mutable #:transparent)
(define (insert-between dlist before after data)
; Insert a fresh link containing DATA after existing link
; BEFORE if not nil and before existing link AFTER if not nil
(define new-link (dllink data before after))
(if before
(set-dllink-next! before new-link)
(set-dllist-head! dlist new-link))
(if after
(set-dllink-prev! after new-link)
(set-dllist-tail! dlist new-link))
new-link)
(define (insert-before dlist dlink data)
; Insert a fresh link containing DATA before existing link DLINK
(insert-between dlist (dllink-prev dlink) dlink data))
(define (insert-after dlist dlink data)
; Insert a fresh link containing DATA after existing link DLINK
(insert-between dlist dlink (dllink-next dlink) data))
(define (insert-head dlist data)
; Insert a fresh link containing DATA at the head of DLIST
(insert-between dlist #f (dllist-head dlist) data))
(define (insert-tail dlist data)
; Insert a fresh link containing DATA at the tail of DLIST
(insert-between dlist (dllist-tail dlist) #f data))
(define (remove-link dlist dlink)
; Remove link DLINK from DLIST and return its content
(let ((before (dllink-prev dlink))
(after (dllink-next dlink)))
(if before
(set-dllink-next! before after)
(set-dllist-head! dlist after))
(if after
(set-dllink-prev! after before)
(set-dllist-tail! dlist before))))
(define (dllist-elements dlist)
; Returns the elements of DLIST as a list
(define (extract-values dlink acc)
(if dlink
(extract-values (dllink-next dlink) (cons (dllink-content dlink) acc))
acc))
(reverse (extract-values (dllist-head dlist) '())))
(let ((dlist (dllist #f #f)))
(insert-head dlist 1)
(displayln dlist)
(insert-tail dlist 4)
(displayln dlist)
(insert-after dlist (dllist-head dlist) 2)
(displayln dlist)
(let* ((next-to-last (insert-before dlist (dllist-tail dlist) 3))
(bad-link (insert-before dlist next-to-last 42)))
(remove-link dlist bad-link))
(displayln dlist)
(displayln (dllist-elements dlist))
(displayln dlist))
| false |
a10d5b767d21e60974bfaf95fb0730bd78a8e09a
|
b21f59bbd4faf31159321e8d26eb170f9aa410c0
|
/2.2.3-sequences-as-conventional-interfaces/find-triples.scm
|
c1b7507deaf08badbd1b88564b79807f637a3f55
|
[] |
no_license
|
furkhat/sicp-practice
|
4774048022718c165e0ec35602bb192241d9f97a
|
301fea9ee4d6cea895cec4b618c664b48c2106f0
|
refs/heads/master
| 2021-06-08T06:01:01.760120 | 2016-12-11T08:11:34 | 2016-12-11T08:11:34 | null | 0 | 0 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 563 |
scm
|
find-triples.scm
|
(load "flatmap.scm")
(load "enumerate-interval.scm")
(define (get-sum-test-for n)
(lambda (x)
(= (+ (car x)
(cadr x)
(cadr (cdr x)))
n)))
(define (unique-triples n)
(flatmap
(lambda (x)
(flatmap
(lambda (y)
(map
(lambda (z) (list x y z))
(enumerate-interval 1 (- y 1))))
(enumerate-interval 1 (- x 1))))
(enumerate-interval 1 n)))
(define (find-triples-with-sum val n)
(filter (get-sum-test-for val) (unique-triples n)))
(find-triples-with-sum 15 10)
| false |
9fa35c00c9ca24b38cf0f6daabf071e57938df26
|
fca62d08480d0db43627f51449b9caea48295601
|
/sources/units/configuration-intern.scm
|
879847eca4cc341070521c8881019656d37b128f
|
[
"MIT"
] |
permissive
|
alxbnct/Schemings
|
aa4783cca04b4a393972ead754cd3e2ce89bf193
|
a7c322ee37bf9f43b696c52fc290488aa2dcc238
|
refs/heads/master
| 2023-06-01T02:06:38.441543 | 2021-06-12T15:27:28 | 2021-06-12T15:27:28 | null | 0 | 0 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 1,163 |
scm
|
configuration-intern.scm
|
(declare (unit configuration-intern))
(declare (uses config))
(declare (uses date-time))
;; returns the value of a config-setting-t*
(: get-value-from-config-setting-t* (pointer -> *))
(define (get-value-from-config-setting-t* config-setting-t*)
(let ((config-type (config-setting-type config-setting-t*)))
(cond ((eq? config-type config-type-int) (config-setting-get-int config-setting-t*))
((eq? config-type config-type-float) (config-setting-get-float config-setting-t*))
((eq? config-type config-type-string) (config-setting-get-string config-setting-t*))
((eq? config-type config-type-bool) (not (eq? (config-setting-get-bool config-setting-t*) 0)))
(else #f))))
;; upgrades a value from a config supported format
(: config-value->setting-value (* symbol -> *))
(define (config-value->setting-value value value-type)
(cond ((not value) #f)
((eq? value-type 'date) (or (try-string->date value) 'invalid-value))
((eq? value-type 'date-time) (or (try-string->date-time value) 'invalid-value))
((eq? value-type 'time) (or (try-string->time value) 'invalid-value))
(else value)))
| false |
aa31c7f45a149f1f88a863e09c285ceb98bb9123
|
2bcf33718a53f5a938fd82bd0d484a423ff308d3
|
/programming/sicp/ch2/ex-2.48.scm
|
d39bddac891c935109b63bb63efb008fb49cd55f
|
[] |
no_license
|
prurph/teach-yourself-cs
|
50e598a0c781d79ff294434db0430f7f2c12ff53
|
4ce98ebab5a905ea1808b8785949ecb52eee0736
|
refs/heads/main
| 2023-08-30T06:28:22.247659 | 2021-10-17T18:27:26 | 2021-10-17T18:27:26 | 345,412,092 | 0 | 0 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 308 |
scm
|
ex-2.48.scm
|
#lang sicp
;; https://mitpress.mit.edu/sites/default/files/sicp/full-text/book/book-Z-H-15.html#%_thm_2.48
(#%require sicp-pict)
;; Direccted line segment as a pair of vectors from origin to start and origin
;; to end
(define (make-segment) cons)
(define (start-segment) car)
(define (end-segment) cdr)
| false |
8ec4e1b16e5899c599b524d415260ce7df914946
|
32130475e9aa1dbccfe38b2ffc562af60f69ac41
|
/algo/insertionsort.scm
|
4643cd72206b01e2d2ee057478abfa84916db472
|
[] |
no_license
|
cinchurge/SICP
|
16a8260593aad4e83c692c4d84511a0bb183989a
|
06ca44e64d0d6cb379836d2f76a34d0d69d832a5
|
refs/heads/master
| 2020-05-20T02:43:30.339223 | 2015-04-12T17:54:45 | 2015-04-12T17:54:45 | 26,970,643 | 0 | 0 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 986 |
scm
|
insertionsort.scm
|
(use test)
; Insert x into a sorted list:
; Given a sorted-list, iterate through each element and compare
; value to x. Keep going until we've hit a value that is greater
; than x and insert x before it.
(define (insert x sorted-list)
(if (null? sorted-list)
(list x)
(let ((first-element (car sorted-list))
(rest-elements (cdr sorted-list)))
(if (>= x first-element)
(cons first-element (insert x rest-elements))
(cons x sorted-list)))))
; Insertion sort:
; Iterate through unsorted-list and recursively insert each element
; into a sorted list.
(define (insertion-sort unsorted-list)
(define (insertion-sort-helper sorted-list unsorted-list)
(if (null? unsorted-list)
sorted-list
(let ((next-element (car unsorted-list))
(rest-elements (cdr unsorted-list)))
(insertion-sort-helper (insert next-element sorted-list) rest-elements))))
(insertion-sort-helper '() unsorted-list))
| false |
9162f37f26ae507f72cb20d77bc0cb0284cb81d6
|
3b599e0f15d1b7ce3e42789b2e5c6d477b6a572b
|
/Lisp/sicp/prime.ss
|
3ef426b014f36baf0908d8f4e25435078f8dbe3d
|
[] |
no_license
|
iacxc/MyProjects
|
1b2ccc80fca2c0935e1a91c98a7555b880745297
|
6998c87012273726bb290f5268ba1f8a9fd37381
|
refs/heads/master
| 2021-01-15T15:45:01.742263 | 2018-03-05T10:41:32 | 2018-03-05T10:41:32 | 25,804,036 | 0 | 0 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 890 |
ss
|
prime.ss
|
(load "../common/common.ss")
;;;
(define (smallest-divisior n)
(define (divides? a b)
(= (remainder b a ) 0))
(define (find-divisior n test-divisior)
(cond ((> (square test-divisior) n) n)
((divides? test-divisior n) test-divisior)
(else (find-divisior n (+ test-divisior 1)))))
(find-divisior n 2))
(define (prime? n)
(= n (smallest-divisior n)))
(define (fermat-test n)
(define (try-it a)
(= (remainder (expt a n) n) a))
(try-it (+ 1 (random (- n 1)))))
(define (fast-prime? n times)
(cond ( (= times 0) #t )
( (fermat-test n) (fast-prime? n (- times 1)))
( else #f )))
(define number 249823048)
(display "Using prime? ")
(time (display (prime? number)) (display " "))
(newline)
(display "Using fast-prime? ")
(time (display (fast-prime? number 5)) (display " "))
(newline)
(exit)
| false |
5f06e6a336b013660d1f3ab6e7d00120213c74bc
|
c5de45adc74a609415f9318fda24479561a5728b
|
/15.ss
|
f4888f5c892a2f3e9e52e33e2d3a54571f226086
|
[] |
no_license
|
rhit-zhuz9/CSSE304
|
8b7498336cf9573b18b3cd0f5654ddfb1b1dfc69
|
f3a10bf17ca1daa532f277a0cf4f7c9746ea89e7
|
refs/heads/master
| 2023-03-15T11:54:52.913169 | 2018-05-30T03:00:43 | 2018-05-30T03:00:43 | null | 0 | 0 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 5,854 |
ss
|
15.ss
|
; Problem 2/(2): The code I write is a top-down version. I main save the calculation times, but I still need to call every value when I
; get there. The procedure calls take time. There are many duplicates during the call. So it is not that fast.
; The code wrote in class is bottom-up version. It avoid duplicate calls to the same value. It build all the way through. So it will
; never get back to smaller values.
; CSSE304-01 Yuankai Wang (Kevin) Assignment15
; Problem 1
(define apply-continuation
(lambda (k v)
(k v)))
; a
(define member?-cps
(lambda (item list continuation)
(if (null? list)
(apply-continuation continuation #f)
(if (equal? item (car list))
(apply-continuation continuation #t)
(member?-cps item (cdr list) continuation)))))
; b
(define set?-cps
(lambda (ls continuation)
(cond [(null? ls) (apply-continuation continuation #t)]
[(not (pair? ls)) (apply-continuation continuation #f)]
[else (member?-cps (car ls) (cdr ls)
(lambda (x)
(if x
(apply-continuation continuation #f)
(set?-cps (cdr ls) continuation))))])))
; c
(define set-of-cps
(lambda (s continuation)
(cond [(null? s) (apply-continuation continuation '())]
[else (member?-cps (car s) (cdr s)
(lambda (x)
(set-of-cps (cdr s)
(lambda (y)
(if x
(apply-continuation continuation y)
(apply-continuation continuation (cons (car s) y)))))))])))
(define map-cps
(lambda (proc-cps L continuation)
(cond [(null? L) (apply-continuation continuation '())]
[else (map-cps proc-cps (cdr L)
(lambda (x)
(proc-cps (car L)
(lambda (y)
(apply-continuation continuation (cons y x))))))])))
(define domain-cps
(lambda (rel continuation)
(map-cps 1st-cps rel
(lambda (x)
(set-of-cps x continuation)))))
(define 1st-cps
(lambda (L continuation)
(apply-continuation continuation (car L))))
; d
(define make-cps
(lambda (proc)
(lambda (L continuation)
(apply-continuation continuation (proc L)))))
; e
(define andmap-cps
(lambda (pred-cps list continuation)
(cond [(null? list) (apply-continuation continuation #t)]
[else (1st-cps list
(lambda (x)
(pred-cps x
(lambda (y)
(if y
(andmap-cps pred-cps (cdr list) continuation)
(apply-continuation continuation #f))))))])))
; f
(define snlist-recur
(lambda (seed item-proc list-proc)
(letrec ([helper
(lambda (ls)
(if (null? ls)
seed
(let ([c (car ls)])
(if (or (pair? c) (null? c))
(list-proc (helper c) (helper (cdr ls)))
(item-proc c (helper (cdr ls)))))))])
helper)))
(define cps-snlist-recur
(lambda (base-value item-proc-cps list-proc-cps)
(letrec ([helper
(lambda (ls continuation)
(cond [(null? ls)
(apply-continuation continuation base-value)]
[(or (pair? (car ls)) (null? (car ls)))
(helper (car ls)
(lambda (x)
(helper (cdr ls)
(lambda (y)
(list-proc-cps x y continuation)))))]
[else (1st-cps ls
(lambda (x)
(helper (cdr ls)
(lambda (y)
(item-proc-cps x y continuation)))))]))])
helper)))
(define +-cps
(lambda (a b continuation)
(apply-continuation continuation (+ a b))))
(define sn-list-depth-cps
(cps-snlist-recur
1
(lambda (x y continuation)
(apply-continuation continuation y))
(lambda (x y continuation)
(apply-continuation continuation (max (+ x 1) y)))))
(define sn-list-reverse-cps
(cps-snlist-recur
'()
(lambda (x y continuation)
(apply-continuation continuation (append y (list x))))
(lambda (x y continuation)
(apply-continuation continuation (append y (list x))))))
(define sn-list-occur-cps
(lambda (sym slist continuation)
((cps-snlist-recur
0
(lambda (x y continuation)
(apply-continuation continuation
(if (eq? x sym)
(+ y 1)
y)))
+-cps)
slist continuation)))
; Problem 2
(define memoize
(lambda (f hash equiv?)
(let* ([htable (make-hashtable hash equiv?)]
[contains? (lambda (key)
(hashtable-contains? htable key))]
[set (lambda (key value)
(hashtable-set! htable key value))]
[get (lambda (key)
(hashtable-ref htable key '()))])
(lambda input
(if (contains? input)
(get input)
(let ([temp-result (apply f input)])
(set input temp-result)
temp-result))))))
; Problem 3
(define subst-leftmost
(lambda (new old slist equality-pred?)
(call-with-values
(lambda ()
(subst-leftmost-changed new old slist equality-pred? 0))
(lambda (output found) output))))
(define subst-leftmost-changed
(lambda (new old slist equality-pred? changed)
(cond [(not (zero? changed)) (values slist 1)]
[(null? slist) (values '() 0)]
[(list? (car slist))
(call-with-values
(lambda ()
(subst-leftmost-changed new old (car slist) equality-pred? changed))
(lambda (output found)
(if (zero? found)
(call-with-values
(lambda ()
(subst-leftmost-changed new old (cdr slist) equality-pred? found))
(lambda (output found)
(values (cons (car slist) output) found)))
(values (cons output (cdr slist)) 1))))]
[else (if (equality-pred? (car slist) old)
(call-with-values
(lambda ()
(subst-leftmost-changed new old (cdr slist) equality-pred? 1))
(lambda (output found)
(values (cons new output) 1)))
(call-with-values
(lambda ()
(subst-leftmost-changed new old (cdr slist) equality-pred? 0))
(lambda (output found)
(values (cons (car slist) output) found))))])))
| false |
d080a9b0e5e99ea0c7419dd66913adb8fafc50b9
|
542b1510c22ad5c41ba2f896f674c275c34e9195
|
/srfi.160.s64.scm
|
df6295d0f20da7cbdbd11abcc4c0a6727635cf61
|
[
"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.s64.scm
|
(module (srfi 160 s64) ()
(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-s64vector s64vector
s64vector-unfold s64vector-unfold-right
s64vector-copy s64vector-reverse-copy
s64vector-append s64vector-concatenate
s64vector-append-subvectors)
;; Predicates
(export s64? s64vector? s64vector-empty? s64vector=)
;; Selectors
(export s64vector-ref s64vector-length)
;; Iteration
(export s64vector-take s64vector-take-right
s64vector-drop s64vector-drop-right
s64vector-segment
s64vector-fold s64vector-fold-right
s64vector-map s64vector-map! s64vector-for-each
s64vector-count s64vector-cumulate)
;; Searching
(export s64vector-take-while s64vector-take-while-right
s64vector-drop-while s64vector-drop-while-right
s64vector-index s64vector-index-right s64vector-skip s64vector-skip-right
s64vector-any s64vector-every s64vector-partition
s64vector-filter s64vector-remove)
;; Mutators
(export s64vector-set! s64vector-swap! s64vector-fill! s64vector-reverse!
s64vector-copy! s64vector-reverse-copy!
s64vector-unfold! s64vector-unfold-right!)
;; Conversion
(export s64vector->list reverse-s64vector->list reverse-list->s64vector
list->s64vector s64vector->vector vector->s64vector)
;; Misc
(export make-s64vector-generator s64vector-comparator write-s64vector)
(include "srfi/160/s64-impl.scm")
(define (eof-object)
(let* ((p (open-input-string "")) (e (read p)))
(close-input-port p) e))
)
| false |
9218cab5f70954a634fb25aadba53138313bc8d9
|
91fc138a1cbcbeffaf6cf4eb0e3ae188b2ca257f
|
/Chapter 1 Exercises/1.24.scm
|
0dfb5ace5fb5357101ed1da129153031a1288e16
|
[] |
no_license
|
jlollis/sicp-solutions
|
0bd8089aea5a85c7b34e43a0f34db87e4161bee0
|
7b03befcfe82e26a7fb28d94bc99292bc484f9dd
|
refs/heads/master
| 2022-06-15T23:34:10.541201 | 2022-06-02T03:32:46 | 2022-06-02T03:32:46 | 130,729,626 | 9 | 1 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 2,434 |
scm
|
1.24.scm
|
#lang sicp
#|
Exercise 1.24. Modify the timed-prime-test procedure of exercise 1.22 to use fast-prime?
(the Fermat method), and test each of the 12 primes you found in that exercise. Since the Fermat test
has (log n) growth, how would you expect the time to test primes near 1,000,000 to compare with
the time needed to test primes near 1000? Do your data bear this out? Can you explain any discrepancy
you find?
|#
;;; square
(define (square x) (* x x))
;;; divides?
;(define (divides? a b)
; (= (remainder b a) 0))
;; fast-prime? from 1.2.6 text
(define (expmod base exp m)
(cond ((= exp 0) 1)
((even? exp)
(remainder (square (expmod base (/ exp 2) m))
m))
(else
(remainder (* base (expmod base (- exp 1) m))
m))))
(define (fermat-test n)
(define (try-it a)
(= (expmod a n n) a))
(try-it (+ 1 (random (- n 1)))))
(define (fast-prime? n times)
(cond ((= times 0) true)
((fermat-test n) (fast-prime? n (- times 1)))
(else false)))
;;; smallest-divisor definition, from 1.20
(define (smallest-divisor n)
(define max-divisor (sqrt n))
(define (next n)
(if (= n 2)
3
(+ 2 n)
)
)
(define (try divisor)
(if (> divisor max-divisor)
n
(if (= (remainder n divisor) 0)
divisor
(try (next divisor))
)
)
)
(try 2)
)
;;; prime?
(define (prime? n)
(= n (smallest-divisor n))
(fast-prime? n 100))
;;; timed prime test definition, from 1.22
(define (timed-prime-test n)
(newline)
(display n)
(start-prime-test n (runtime)))
(define (start-prime-test n start-time)
(if (prime? n)
(report-prime (- (runtime) start-time))))
(define (report-prime elapsed-time)
(display " *** ")
(display elapsed-time))
(timed-prime-test 1009)
(timed-prime-test 1013)
(timed-prime-test 1019)
(timed-prime-test 10007)
(timed-prime-test 10009)
(timed-prime-test 10037)
(timed-prime-test 100003)
(timed-prime-test 100019)
(timed-prime-test 100043)
(timed-prime-test 1000003)
(timed-prime-test 1000033)
(timed-prime-test 1000037)
(timed-prime-test 1000000007)
(timed-prime-test 1000000009)
(timed-prime-test 1000000021)
;;; Answer: Time expected is double, as we know from the previous question, and this is what we find in the REPL when testing.
| false |
0768d8c77c993d8508d2394a46e4ca20206494a4
|
6bd63be924173b3cf53a903f182e50a1150b60a8
|
/chapter_3/3.51_2.scm
|
d3bec19c03b35601f95e8333e1c687366410965a
|
[] |
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 | 818 |
scm
|
3.51_2.scm
|
(define (stream-enumerate-interval low high)
(if (> low high)
the-empty-stream
(cons-stream low
(stream-enumerate-interval (+ 1 low) high))))
(define (stream-ref s n)
(if (= n 0) (stream-car s)
(stream-ref (stream-cdr s) (- n 1))))
(define (stream-map proc . argstreams )
(if (stream-null? (car argstreams))
the-empty-stream
(cons-stream
(apply proc (map stream-car argstreams))
(apply stream-map
(cons proc (map stream-cdr argstreams))))))
(define (show x)
(display x)(newline)
x)
(define (try)
(define x (stream-map show (stream-enumerate-interval 0 10)))
; with cache version
; 0
; 1
; 2
; 3
; 4
; 5
(display (stream-ref x 5))(newline)
; 6
; 7
(display (stream-ref x 7))(newline)
)
(try)
| false |
0861f296f662d708b1e5892fae4893de80843a93
|
bf6fad8f5227d0b0ef78598065c83b89b8f74bbc
|
/chapter03/ex3-6-3/main.ss
|
6e1cfac1b43559235648ecd3e546dab726d18454
|
[] |
no_license
|
e5pe0n/tspl
|
931d1245611280457094bd000e20b1790c3e2499
|
bc76cac2307fe9c5a3be2cea36ead986ca94be43
|
refs/heads/main
| 2023-08-18T08:21:29.222335 | 2021-09-28T11:04:54 | 2021-09-28T11:04:54 | 393,668,056 | 0 | 0 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 206 |
ss
|
main.ss
|
(define print
(lambda (x)
(for-each display `(,x "\n"))
)
)
(import grades)
(histogram
(current-output-port)
(distribution a b a c c a c a f b a)
)
; a: *****
; b: **
; c: ***
; d:
; e:
; f: *
| false |
0da93c533728adf7b78acc55f02c862ac001d13b
|
2c291b7af5cd7679da3aa54fdc64dc006ee6ff9b
|
/ch2/prob.2.71.scm
|
8f257c066bbc33fc4e30a395b0c71d9cd46c28b6
|
[] |
no_license
|
etscrivner/sicp
|
caff1b3738e308c7f8165fc65a3f1bc252ce625a
|
3b45aaf2b2846068dcec90ea0547fd72b28f8cdc
|
refs/heads/master
| 2021-01-10T12:08:38.212403 | 2015-08-22T20:01:44 | 2015-08-22T20:01:44 | 36,813,957 | 1 | 0 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 1,091 |
scm
|
prob.2.71.scm
|
(load "prob.2.69.scm")
(define letters '(A B C D E F G H I J K L M N O P Q R S T U V W X Y Z))
(define (generate-powers-of-two-freq-list current-exponent)
(if (= 0 current-exponent)
(list (list (list-ref letters 0) 1))
(append (generate-powers-of-two-freq-list (- current-exponent 1))
(list (list (list-ref letters current-exponent)
(expt 2 current-exponent))))))
;; Requires 5 symbols to encode 'A
(define pow-2-5 (generate-huffman-tree (generate-powers-of-two-freq-list 5)))
(length (encode-symbol 'A pow-2-5))
(length (encode-symbol 'F pow-2-5))
;; Requires 10 symbols to encode 'A
(define pow-2-10 (generate-huffman-tree (generate-powers-of-two-freq-list 10)))
(length (encode-symbol 'A pow-2-10))
(length (encode-symbol 'K pow-2-10))
;; In general, constructing a tree from items with frequencies that are
;; successive powers of two results in the least frequent symbol requiring
;; log_2(n) bits where n is the frequency of the least frequent element.
;; The most frequent symbol, on the other hand, always requires one bit.
| false |
2ccaa7f5e1a3b209a35eb0686524ee3c61c71ca4
|
80c8c43dd7956bb78a0c586ea193e3114de31046
|
/practice-3.scm
|
440555648ac44cc495b461313ebde2bfcb82b06b
|
[] |
no_license
|
UeharaYou/Learning-SICP
|
78b9d29e6a84a0890ec9788073160c3f7fd8a231
|
3a6cf413a313d7249e121bdd1515e374d2a369ea
|
refs/heads/master
| 2021-04-05T14:00:36.752016 | 2020-03-19T17:27:39 | 2020-03-19T17:27:39 | 248,564,129 | 0 | 0 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 1,617 |
scm
|
practice-3.scm
|
;; SICP Practice: 3
;; Action - Effect Sheet
;; Principles:
;; 0. Internal Properties shall be encapsulated by methods, which are later exposed via Unary Operations.
;; 1. Unary Operations might yields effects to itself (either groups or individuals).
;; 2. Interations involing multiple participants (either groups or individuals) in order will yields effects to ALL participants simultanelously.
;; 3. Participants can group up to perform Actions, while Effects on a group could translate into effects to ALL group members.
;; Definitions:
;; 1. Participants: Objects which has its internal properties encapsulated by unary operators.
;; 1.1. Individuals: Primitive Praticipants.
;; 1.2. Groups: Concatenations of Members that act as a unified Participant.
;; 1.2.1. Members: Individuals or other groups satisfying relationships on the Grouping Hierarchy.
;; 2. Interations: Operations taking a list of Participants as arguments and yield set of Interactions to another lists of Participants.
;; 2.1. Unary Operations: Interactions taking a list of ONE participant inquiring or shifting its Internal Properties.
;; 2.2. Actions: Interactions that will yield other Interactions.
;; 2.3. Effects: Interactions yielded from other Interactions.
;; Constraints:
;; 1. Effects yielded from actions might take Participants unbound to the current environment, those from hypervisors for examples.
;; 2.
;; DEAFT
Actions: Interactions that yields an Action <??> to super-lists of Participants or Effects to ALL participants.
Effects: Interactions that yields Effects to sub-lists of Participants.
| false |
074ce5926122a172a66585f902b557f398745a88
|
669b06943e802449ed812bfafec9eec2c50647da
|
/deps/share/guile/site/2.2/gl/parse.scm
|
18096342a2328dba9d474b58a824bf709ee7c312
|
[] |
no_license
|
bananaoomarang/chickadee-game
|
f9dcdb8b2e2b3b1909d30af52c1e6a7c16b27194
|
8733941202243956252b19a1a3ceb35a84b61e56
|
refs/heads/master
| 2020-06-04T17:35:32.420313 | 2019-06-24T22:59:04 | 2019-06-24T22:59:04 | 192,126,835 | 1 | 1 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 26,957 |
scm
|
parse.scm
|
;;; Guile-OpenGL
;;; Copyright (C) 2014 Free Software Foundation, Inc.
;;;
;;; Guile-OpenGL 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.
;;;
;;; Guile-OpenGL 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:
;;
;; figl is the Foreign Interface to GL.
;;
;;; Code:
(define-module (gl parse)
#:use-module (gl config)
#:use-module (gl contrib)
#:use-module (sxml simple)
#:use-module ((sxml xpath) #:hide (filter))
#:use-module (sxml transform)
#:use-module (sxml fold)
#:use-module ((srfi srfi-1) #:select (filter fold append-map filter-map))
#:use-module (srfi srfi-9) ; define-record-type
#:use-module (srfi srfi-42) ; eager comprehensions
#:use-module (texinfo docbook)
#:use-module (ice-9 ftw)
#:use-module (ice-9 rdelim)
#:use-module (ice-9 match)
#:use-module (ice-9 regex)
#:export (gl-definition?
make-gl-definition
gl-definition-name
gl-definition-prototypes
gl-definition-documentation
gl-definition-copyright
parse-gl-definitions
gl-enumeration?
make-gl-enumeration
gl-enumeration-category
gl-enumeration-values
parse-gl-enumerations
gl-param-type?
make-gl-param-type
gl-param-type-type
gl-param-type-direction
gl-param-type-transfer-type
parse-gl-type-map))
(define-record-type gl-definition
(make-gl-definition name prototypes documentation copyright)
gl-definition?
(name gl-definition-name)
(prototypes gl-definition-prototypes)
(documentation gl-definition-documentation)
(copyright gl-definition-copyright))
;; values := (name . number) ...
(define-record-type gl-enumeration
(make-gl-enumeration category values)
gl-enumeration?
(category gl-enumeration-category)
(values gl-enumeration-values))
;; Seed of gl-param and more.
;; TODO: Is this not really gl-type?
(define-record-type gl-param-type
(%make-gl-param-type type direction transfer-type)
gl-param-type?
(type gl-param-type-type)
(direction gl-param-type-direction)
(transfer-type gl-param-type-transfer-type))
;; Memoized for eq?, hash, memory usage.
(define make-gl-param-type (memoize %make-gl-param-type))
(define *namespaces*
'((mml . "http://www.w3.org/1998/Math/MathML")))
(define *entities*
'(;; From http://www.w3.org/TR/MathML2/mmlextra.html
(af . "\u2061") ;; Function application.
(it . "\u2062") ;; Invisible times.
;; http://www.w3.org/TR/MathML2/isonum.html
(plus . "\u002B") ;; Plus sign.
(times . "\u00D7") ;; Multiplication sign.
;; http://www.w3.org/TR/MathML2/isotech.html
(Prime . "\u2033") ;; Double prime.
(le . "\u2264") ;; Less than or equal to.
(ne . "\u2260") ;; Not equal to.
(minus . "\u2212") ;; Minus sign.
;; http://www.w3.org/TR/MathML2/isoamsc.html
(lceil . "\u2308") ;; Left ceiling.
(rceil . "\u2309") ;; Right ceiling.
(lfloor . "\u230A") ;; Left floor.
(rfloor . "\u230B") ;; Right floor.
;; http://www.w3.org/TR/MathML2/mmlalias.html
(DoubleVerticalBar . "\u2225") ;; Parallel to.
(LeftFloor . "\u230A") ;; Left floor.
(RightFloor . "\u230B") ;; Right floor.
(LeftCeiling . "\u2308") ;; Left ceiling.
(RightCeiling . "\u2309") ;; Right ceiling.
(CenterDot . "\u00B7") ;; Middle dot.
(VerticalBar . "\u2223") ;; Divides.
(PartialD . "\u2202") ;; Partial derivative.
;; http://www.w3.org/TR/MathML2/mmlextra.html
(Hat . "\u005E") ;; Circumflex accent.
;; http://www.w3.org/TR/MathML2/isogrk3.html
(Delta . "\u0394") ;; Greek capital letter delta.
(Sigma . "\u03A3") ;; Greek capital letter sigma.
;; Misc.
(nbsp . "\u00A0")
))
(define (default-entity-handler port name)
(format (current-warning-port)
"~a:~a:~a: undefined entitity: &~a;\n"
(or (port-filename port) "<unknown file>")
(port-line port) (port-column port)
name)
(symbol->string name))
(define dbmathml
"http://www.oasis-open.org/docbook/xml/mathml/1.1CR1/dbmathml.dtd")
(define (docbook-with-mathml-handler docname systemid internal)
(unless (equal? systemid dbmathml)
(warn "unexpected doctype" docname systemid internal))
(values #:entities *entities* #:namespaces *namespaces*))
(define (trim-whitespace-left str)
(let ((first (and (not (string-null? str))
(string-ref str 0))))
(if (and first (char-whitespace? first))
(string-append (string first) (string-trim str char-whitespace?))
str)))
(define (trim-whitespace-right str)
(let ((last (and (not (string-null? str))
(string-ref str (1- (string-length str))))))
(if (and last (char-whitespace? last))
(string-append (string-trim-right str char-whitespace?) (string last))
str)))
(define (trim-whitespace str)
(trim-whitespace-left
(trim-whitespace-right str)))
(define (zap-whitespace sxml)
(define (not-whitespace x)
(or (not (string? x))
(not (string-every char-whitespace? x))))
(pre-post-order sxml
`((*default* . ,(lambda (tag . body)
(cons tag
(filter not-whitespace body))))
(*text* . ,(lambda (tag text)
(if (string? text)
(trim-whitespace text)
text))))))
(define (parse-man-xml version filename)
(define subdir (format #f "man~A" version))
(call-with-input-file (in-vicinity (upstream-doc)
(in-vicinity subdir filename))
(lambda (port)
(zap-whitespace
(xml->sxml port #:declare-namespaces? #t
#:default-entity-handler default-entity-handler
#:doctype-handler docbook-with-mathml-handler)))))
(define (xml-files version)
(define subdir (format #f "man~A" version))
(scandir (in-vicinity (upstream-doc) subdir)
(lambda (x) (string-suffix? ".xml" x))))
(define (take-first proc)
(lambda (xml)
(let ((res (proc xml)))
(and (pair? res) (car res)))))
(define xml-name
(take-first (sxpath '(refentry refnamediv refname *text*))))
(define xml-purpose
(take-first (sxpath '(refentry refnamediv refpurpose *text*))))
(define xml-funcprototypes
(sxpath '(refentry refsynopsisdiv funcsynopsis funcprototype)))
(define xml-parameters
(take-first (sxpath '(refentry (refsect1 (@ id (equal? "parameters")))))))
(define xml-description
(take-first (sxpath '(refentry (refsect1 (@ id (equal? "description")))))))
(define xml-errors
(take-first (sxpath '(refentry (refsect1 (@ id (equal? "errors")))))))
(define xml-copyright
(take-first (sxpath '(refentry (refsect1 (@ id (equal? "Copyright")))))))
(define (string->gl-type str)
(string->symbol
(string-join (string-split (string-trim-both str) #\space) "-")))
(define (parse-prototypes sxml)
(define all-names
(match sxml
((('funcprototype ('funcdef return-type ('function names))
. _)
...)
names)))
(define (redundant-variant? s shun-suffix prefer-suffix)
(and (string-suffix? shun-suffix s)
(member (string-append (substring s 0 (- (string-length s)
(string-length shun-suffix)))
prefer-suffix)
all-names)))
(filter-map
(lambda (sxml)
(match sxml
(('funcprototype ('funcdef return-type ('function name))
('paramdef ('parameter "void")))
`(,(string->symbol name)
-> ,(string->gl-type return-type)))
(('funcprototype ('funcdef return-type ('function name))
('paramdef ptype ('parameter pname))
...)
`(,(string->symbol name)
,@(map (lambda (pname ptype)
(list (string->symbol pname)
(string->gl-type ptype)))
pname ptype)
-> ,(string->gl-type return-type)))))
sxml))
(define (collapse-fragments nodeset)
(match nodeset
((('*fragment* elts ...) nodes ...)
(append (collapse-fragments elts)
(collapse-fragments nodes)))
((((and tag (? symbol?)) elts ...) nodes ...)
(acons tag (collapse-fragments elts) (collapse-fragments nodes)))
((elt nodes ...)
(cons elt (collapse-fragments nodes)))
(() '())))
(define (list-intersperse src-l elem)
(if (null? src-l) src-l
(let loop ((l (cdr src-l)) (dest (cons (car src-l) '())))
(if (null? l) (reverse dest)
(loop (cdr l) (cons (car l) (cons elem dest)))))))
(define (lift-tables sdocbook)
;; Like sdocbook-flatten, but tweaked to lift tables from inside
;; paras, but not paras from inside tables. Pretty hacky stuff.
(define *sdocbook-block-commands*
'(informaltable programlisting variablelist))
(define (inline-command? command)
(not (memq command *sdocbook-block-commands*)))
(define (fhere str accum block cont)
(values (cons str accum)
block
cont))
(define (fdown node accum block cont)
(match node
((command (and attrs ('% . _)) body ...)
(values body '() '()
(lambda (accum block)
(values
`(,command ,attrs ,@(reverse accum))
block))))
((command body ...)
(values body '() '()
(lambda (accum block)
(values
`(,command ,@(reverse accum))
block))))))
(define (fup node paccum pblock pcont kaccum kblock kcont)
(call-with-values (lambda () (kcont kaccum kblock))
(lambda (ret block)
(if (inline-command? (car ret))
(values (cons ret paccum) (append kblock pblock) pcont)
(values paccum (append kblock (cons ret pblock)) pcont)))))
(call-with-values
(lambda () (foldts*-values fdown fup fhere sdocbook '() '() #f))
(lambda (accum block cont)
(append (reverse accum)
(reverse block)
))))
(define (canonicalize-heading heading)
(match heading
(()
;; Some headings are empty. makeinfo wants them to be present, so
;; appease.
'("."))
(else
(map (lambda (x)
(cond
((string? x)
(string-join (string-split x #\newline) " "))
((symbol? x) x)
(else (canonicalize-heading x))))
heading))))
(define *rules*
`((refsect1
*preorder*
. ,(lambda (tag id . body)
(append-map (lambda (nodeset)
(map
(lambda (x)
(pre-post-order x *rules*))
nodeset))
(map lift-tables
(match body
((('title _) body ...) body)
(_ body))))))
(variablelist
((varlistentry
. ,(lambda (tag term . body)
`(entry (% (heading ,@(canonicalize-heading
(cdar term))))
,@(apply append body))))
(listitem
. ,(lambda (tag . body)
(map (lambda (x)
(if (string? x)
`(para ,x)
x))
body)))
(term
. ,(lambda (tag . rest)
`((itemx ,@rest)))))
. ,(lambda (tag . body)
`(table (% (formatter (asis))) ,@body)))
(trademark
. ,(match-lambda*
((_ ('@ ('class "copyright"))) '(copyright))))
(parameter
. ,(lambda (tag body)
`(var ,body)))
(type
. ,(lambda (tag body)
`(code ,body)))
(constant
. ,(lambda (tag . body)
`(code . ,body)))
(code
. ,(lambda (tag . body)
`(code . ,body)))
(function
. ,(lambda (tag body . ignored)
(or (null? ignored) (warn "ignored function tail" ignored))
`(code ,body)))
(emphasis
. ,(match-lambda*
((_) "")
((_ ('@ ('role "bold")) (and body (? string?)))
`(strong ,(string-trim-both body)))
((_ ('@ ('role "bold")) . body) `(strong ,@body))
((_ body) `(var ,body))))
(citerefentry
. ,(lambda (tag contents)
contents))
(refentrytitle
. ,(lambda (tag contents)
`(code ,contents)))
(inlineequation
. ,(lambda (tag contents)
contents))
(informalequation
. ,(lambda (tag contents)
contents))
(informaltable
. ,(lambda (tag attrs tgroup)
tgroup))
(tgroup
((thead
. ,(lambda (tag . rows)
rows))
(colspec
. ,(lambda _
#f))
(tbody
. ,(lambda (tag . rows)
rows))
(row
. ,(lambda (tag first . rest)
`(entry (% (heading ,@(canonicalize-heading first)))
(para ,@(apply
append
(list-intersperse rest '(", ")))))))
(entry
. ,(match-lambda*
((_) '())
((_ ('@ . _)) '())
((_ ('@ . _) x ...) x)
((_ x ...) x))))
. ,(lambda (tag attrs . contents)
`(table (% (formatter (asis)))
,@(apply append (filter identity contents)))))
;; Poor man's mathml.
(mml:math
. ,(lambda (tag . contents)
`(r . ,(collapse-fragments contents))))
(mml:mn
. ,(lambda (tag n . rest)
(if (pair? rest)
`(*fragment* ,n . ,rest)
n)))
(mml:mi
. ,(case-lambda
((tag contents)
`(code ,contents))
((tag attrs contents)
(match attrs
(('@ (mathvariant "italic"))
`(var ,contents))
(_ `(code ,contents))))))
;; It would be possible to represent a matrix as a @multitable, but
;; Guile doesn't really have support for that. So instead print
;; each row in parentheses.
(mml:mtable
((mml:mtr
. ,(lambda (tag . body)
`("(" ,@(list-intersperse body " ") ")")))
(mml:mtd
. ,(match-lambda*
((tag ('@ . _) body ...)
`(*fragment* ,@body))
((tag body ...)
`(*fragment* ,@body)))))
. ,(lambda (tag . rows)
;; Rely on outer mfence for outer parens, if any
(let ((rows (if (and (pair? rows) (eq? (caar rows) '@))
(cdr rows)
rows)))
`(*fragment* ,@(apply append (list-intersperse rows '(", ")))))))
(mml:mspace
. ,(lambda (tag . _)
" "))
(mml:msup
. ,(lambda (tag base exponent)
`(*fragment* ,base "^" ,exponent)))
(mml:msub
. ,(lambda (tag base exponent)
`(*fragment* ,base "_" ,exponent)))
(mml:mover
. ,(lambda (tag base over)
`(*fragment* ,base ,over)))
(mml:munderover
. ,(lambda (tag under base over)
`(*fragment* ,under ,base ,over)))
(mml:mfrac
. ,(lambda (tag num denom)
`(*fragment* ,num "/" ,denom)))
(mml:msqrt
. ,(lambda (tag base)
`(*fragment* "√" ,base)))
(mml:infinity
. ,(lambda (tag)
"∞"))
(mml:mo
. ,(lambda (tag operator)
operator))
(mml:mrow
. ,(lambda (tag . contents)
`(*fragment* . ,contents)))
(mml:mfenced
. ,(lambda (tag attrs left . right)
`(*fragment* ,@(assq-ref attrs 'open)
,left
","
,@right
,@(assq-ref attrs 'close))))
(*text*
. ,(lambda (tag text)
text))
,@*sdocbook->stexi-rules*))
(define (sdocbook->stexi sdocbook)
(pre-post-order sdocbook *rules*))
;; Produces an stexinfo fragment.
(define (generate-documentation purpose parameters description errors)
`(*fragment*
(para ,(string-append (string (char-upcase (string-ref purpose 0)))
(substring purpose 1)
"."))
,@(if parameters (sdocbook->stexi parameters) '())
,@(if description (sdocbook->stexi description) '())
,@(if errors (sdocbook->stexi errors) '())))
(define (xml->definition xml)
(let ((prototypes (parse-prototypes (xml-funcprototypes xml))))
(and (pair? prototypes)
(make-gl-definition (xml-name xml)
prototypes
(generate-documentation (xml-purpose xml)
(xml-parameters xml)
(xml-description xml)
(xml-errors xml))
(and=> (xml-copyright xml)
(lambda (c)
`(*fragment* ,@(sdocbook->stexi c))))))))
(define (parse-gl-definitions version)
(filter-map (lambda (file)
(xml->definition (parse-man-xml version file)))
(xml-files version)))
(define (trim-comment line)
(cond
((string-index line #\#)
=> (lambda (idx) (substring line 0 idx)))
(else line)))
(define (expand-camel-case s)
(define (add-humps humps out more?)
(match humps
(() out)
((head)
(if (null? out)
humps
(cons* head #\- out)))
((head tail ...)
(let ((out (if (null? out)
tail
(append tail (cons #\- out)))))
(if more?
(cons* head #\- out)
(cons head out))))))
(let lp ((in (string->list s)) (humps '()) (out '()))
(match in
(()
(list->string (reverse (add-humps humps out #f))))
((c in ...)
(if (and (char-lower-case? c)
;; Try to keep subtokens like 12x3 in one piece.
(or (null? humps)
(not (and-map char-numeric? humps))))
(lp in '() (cons c (add-humps humps out #t)))
(lp in (cons (char-downcase c) humps) out))))))
(define (mangle-name name)
(string->symbol
(string-join (map expand-camel-case (string-split name #\_))
"-")))
(define (parse-number num)
(cond
((equal? "0xFFFFFFFFu" num)
#xFFFFFFFF)
((equal? "0xFFFFFFFFFFFFFFFFull" num)
#xFFFFFFFFFFFFFFFF)
((string-prefix? "0x" num)
(string->number (substring num 2) 16))
((string-prefix? "GL_" num)
(cons #f (mangle-name (substring num 3))))
;; Hackety hack...
((string-prefix? "GLX_" num)
(cons #f (mangle-name (substring num 4))))
(else
(string->number num))))
(define (read-line-and-trim-comment port)
(let ((line (read-line port)))
(if (eof-object? line)
line
(string-trim-both (trim-comment line)))))
(define (resolve-enumerations enums)
;; We shouldn't fail to resolve anything, but there are a couple bugs
;; in enum.spec currently:
;; http://www.khronos.org/bugzilla/show_bug.cgi?id=787. Until they
;; are fixed, allow resolution to fail.
(define (resolve-value category name value)
(match value
(#f #f)
((? number?)
value)
((#f . (and name (? symbol?)))
(resolve-value category name category))
((? symbol?)
(resolve-value value name (assq-ref (assq-ref enums value) name)))))
(let lp ((in enums) (out '()))
(match in
(()
(reverse out))
(((category (name . value) ...) . in)
(lp in
(cons (make-gl-enumeration
category
(filter-map
(lambda (name value)
(and=> (resolve-value category name value)
(lambda (value)
(cons name value))))
name value))
out))))))
(define (merge-alists in)
;; O(n^2), whee
(define (collect-values key values in)
(let lp ((in in) (values values))
(if (null? in)
values
(lp (cdr in)
(if (eq? (caar in) key)
(append values (cdar in))
values)))))
(let lp ((in in) (out '()))
(cond
((null? in) (reverse out))
((assq (caar in) out) (lp (cdr in) out))
(else (lp (cdr in)
(acons (caar in)
(collect-values (caar in) (cdar in) (cdr in))
out))))))
(define (parse-enumerations-from-port port)
(define (finish-block headers enums accum)
(if (null? enums)
accum
(fold (lambda (header accum)
(acons header (reverse enums) accum))
accum
headers)))
(let lp ((current-headers '()) (current-enums '()) (accum '()))
(let ((line (read-line-and-trim-comment port)))
(cond
((eof-object? line)
(resolve-enumerations
(merge-alists
(reverse (finish-block current-headers current-enums accum)))))
((string-index line #\:)
=> (lambda (pos)
(let* ((ws (or (string-index-right line char-whitespace? 0 pos) 0))
(headers (filter
(compose not string-null?)
(map string-trim-both
(string-split (substring line 0 ws) #\,))))
(def (substring line (1+ ws) pos)))
(match (cons def headers)
((or ("define" _ ...)
((? (lambda (x) (string-suffix? "_future_use" x)))))
(lp '()
'()
(finish-block current-headers current-enums accum)))
(("enum" headers ...)
(if (null? current-enums)
(lp (append current-headers (map mangle-name headers))
current-enums
accum)
(lp (map mangle-name headers)
'()
(finish-block current-headers current-enums accum))))
(x (error "qux." x))))))
((string-null? line)
(lp current-headers current-enums accum))
(else
(match (filter (compose not string-null?)
(string-split (trim-comment line) char-whitespace?))
((enum "=" value)
(lp current-headers
(acons (mangle-name enum)
(or (parse-number value)
(error "failed to parse" value))
current-enums)
accum))
(("use" header enum)
(lp current-headers
(acons (mangle-name enum)
(mangle-name header)
current-enums)
accum))
(x (error x))))))))
(define (parse-gl-enumerations spec)
(call-with-input-file (in-vicinity (upstream-doc)
(in-vicinity "spec" spec))
parse-enumerations-from-port))
;;;
;;; Type Map
;;;
(define valid-directions '(in out in/out))
(define valid-transfer-types '(array reference value))
(define* (string->directions str #:optional
(expansion valid-directions))
(let ((direction (string->symbol str)))
(cond
((and (eq? direction '*) expansion)
expansion)
((memq direction valid-directions)
(list direction))
(else
(error "unknown direction" str)))))
(define* (string->transfer-types str #:optional
(expansion valid-transfer-types))
(let ((trans (string->symbol str)))
(cond
((and (eq? trans '*) expansion)
expansion)
((memq trans valid-transfer-types)
(list trans))
(else
(error "unknown transfer-type" str)))))
(define (expand-type-map-entry type
direction
transfer-type
mapped-type
mapped-direction
mapped-transfer-type)
(let ((type (mangle-name type))
(mapped-type (string->gl-type mapped-type)))
(list-ec (:list direction (string->directions direction))
(:list transfer-type (string->transfer-types transfer-type))
(:list mapped-direction
(string->directions mapped-direction
(list direction)))
(:list mapped-transfer-type
(string->transfer-types mapped-transfer-type
(list transfer-type)))
(cons (make-gl-param-type type
direction
transfer-type)
(make-gl-param-type mapped-type
mapped-direction
mapped-transfer-type)))))
(define (parse-type-map-from-port port)
(define delimiter (make-regexp "[ \t]*,[ \t]*"))
(let lp ((accum '()))
(let ((line (read-line-and-trim-comment port)))
(cond
((eof-object? line)
(reverse accum))
((string-null? line)
(lp accum))
(else
;; TODO: Filter needed here to avoid formatting bug:
;; http://www.khronos.org/bugzilla/show_bug.cgi?id=790
(match (filter (compose not string-null?)
(string-split line delimiter))
((type direction transfer-type
mapped-type mapped-direction mapped-transfer-type)
(lp (append (expand-type-map-entry type
direction
transfer-type
mapped-type
mapped-direction
mapped-transfer-type)
accum)))
(x (error x))))))))
(define (parse-gl-type-map tm)
(call-with-input-file (in-vicinity (upstream-doc)
(in-vicinity "spec" tm))
parse-type-map-from-port))
| false |
f9f71909fc86c4113fa2fbad69db94b43621144a
|
7053803109172ee3fe36594257fb9f323f860c9a
|
/chapters/2/2.5.scm
|
182170923717d12a6c8ece70edd54ed9d2000def
|
[] |
no_license
|
david-davidson/SICP
|
0c7c38a11b11ef70146f4a511e4ac8d7c0651b82
|
393932a507afdc35cb99451ef53a059e72f71eb1
|
refs/heads/main
| 2021-06-14T00:36:59.503919 | 2021-05-28T01:54:39 | 2021-05-28T01:55:42 | 195,283,241 | 0 | 0 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 1,255 |
scm
|
2.5.scm
|
; --------------------------------------------------------------------------------------------------
; We can represent pairs of nonnegative integers using only numbers and arithmetic if we represent
; `a` and `b` as the product `2^a * 3^b`. Implement `cons`, `car`, and `cdr`:
; --------------------------------------------------------------------------------------------------
(define (cons a b)
(* (expt 2 a)
(expt 3 b)))
(define (car n)
(get-divisors n (lambda (even-divisor odd-divisor)
(log-base 2 even-divisor))))
(define (cdr n)
(get-divisors n (lambda (even-divisor odd-divisor)
(log-base 3 odd-divisor))))
(define (get-divisors n next)
(let ((odd-divisor (get-odd-divisor n)))
(next (/ n odd-divisor)
odd-divisor)))
(define (get-odd-divisor n)
(define (iter x)
(if (even? x)
(iter (/ x 2))
x))
(iter n))
; Per https://en.wikibooks.org/wiki/Scheme_Programming/Further_Maths#Logarithm, Scheme's built-in
; `log` is the natural log, but we can get to an arbitrary base like this:
(define (log-base base x)
(/ (log x)
(log base)))
#|
(define pair (cons 7 8))
(car pair) ; => 7
(cdr pair) ; => 8
|#
| false |
6ffbc2eab999544801f34016d8659f68286bb0d6
|
4f17c70ae149426a60a9278c132d5be187329422
|
/scheme/tests/racket-r6rs/sorting.sls
|
93b6614dec4df124c179ea82979886aabb38ff80
|
[] |
no_license
|
okuoku/yuni-core
|
8da5e60b2538c79ae0f9d3836740c54d904e0da4
|
c709d7967bcf856bdbfa637f771652feb1d92625
|
refs/heads/master
| 2020-04-05T23:41:09.435685 | 2011-01-12T15:54:23 | 2011-01-12T15:54:23 | 889,749 | 2 | 0 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 409 |
sls
|
sorting.sls
|
#!r6rs
(library (yuni scheme tests racket-r6rs sorting)
(export run-sorting-tests)
(import (yuni scheme r6rs)
(yuni scheme tests racket-r6rs test))
(define (run-sorting-tests)
(test (list-sort < '(3 5 2 1)) '(1 2 3 5))
(test (vector-sort < '#(3 5 2 1)) '#(1 2 3 5))
(let ([v (vector 3 5 2 1)])
(test/unspec (vector-sort! < v))
(test v '#(1 2 3 5)))
;;
))
| false |
49998848a0dea10c72c64fce45edf9860458c79c
|
6b961ef37ff7018c8449d3fa05c04ffbda56582b
|
/bbn_cl/mach/zcomp/back/linear.scm
|
a1904f921e3f0afe03edd912ef51fd41b7565d6d
|
[] |
no_license
|
tinysun212/bbn_cl
|
7589c5ac901fbec1b8a13f2bd60510b4b8a20263
|
89d88095fc2a71254e04e57cf499ae86abf98898
|
refs/heads/master
| 2021-01-10T02:35:18.357279 | 2015-05-26T02:44:00 | 2015-05-26T02:44:00 | 36,267,589 | 4 | 3 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 3,302 |
scm
|
linear.scm
|
#| -*-Scheme-*-
$Header: linear.scm,v 1.2 88/08/31 10:33:01 jinx Exp $
$MIT-Header: linear.scm,v 4.1 87/12/30 06:57:09 GMT cph Exp $
Copyright (c) 1987 Massachusetts Institute of Technology
This material was developed by the Scheme project at the Massachusetts
Institute of Technology, Department of Electrical Engineering and
Computer Science. Permission to copy this software, to redistribute
it, and to use it for any purpose is granted, subject to the following
restrictions and understandings.
1. Any copy made of this software must include this copyright notice
in full.
2. Users of this software agree to make their best efforts (a) to
return to the MIT Scheme project any improvements or extensions that
they make, so that these may be included in future releases; and (b)
to inform MIT of noteworthy uses of this software.
3. All materials developed as a consequence of the use of this
software shall duly acknowledge such use, in accordance with the usual
standards of acknowledging credit in academic research.
4. MIT has made no warrantee or representation that the operation of
this software will be error-free, and MIT is under no obligation to
provide any services, by way of maintenance, update, or otherwise.
5. In conjunction with products arising from the use of this material,
there shall be no use of the name of the Massachusetts Institute of
Technology nor of any adaptation thereof in any advertising,
promotional, or sales literature without prior written consent from
MIT in each case. |#
;;;; LAP linearizer
(declare (usual-integrations))
(package (bblock-linearize-bits)
(define-export (bblock-linearize-bits bblock)
(node-mark! bblock)
(if (and (not (bblock-label bblock))
(node-previous>1? bblock))
(bblock-label! bblock))
(let ((kernel
(lambda ()
(LAP ,@(bblock-instructions bblock)
,@(if (sblock? bblock)
(linearize-sblock-next (snode-next bblock))
(linearize-pblock bblock
(pnode-consequent bblock)
(pnode-alternative bblock)))))))
(if (bblock-label bblock)
(LAP ,(lap:make-label-statement (bblock-label bblock)) ,@(kernel))
(kernel))))
(define (linearize-sblock-next bblock)
(cond ((not bblock) (LAP))
((node-marked? bblock)
(LAP ,(lap:make-unconditional-branch (bblock-label! bblock))))
(else (bblock-linearize-bits bblock))))
(define (linearize-pblock pblock cn an)
(if (node-marked? cn)
(if (node-marked? an)
(LAP ,@((pblock-consequent-lap-generator pblock) (bblock-label! cn))
,(lap:make-unconditional-branch (bblock-label! an)))
(LAP ,@((pblock-consequent-lap-generator pblock) (bblock-label! cn))
,@(bblock-linearize-bits an)))
(if (node-marked? an)
(LAP ,@((pblock-alternative-lap-generator pblock) (bblock-label! an))
,@(bblock-linearize-bits cn))
(let ((label (bblock-label! cn))
(alternative (bblock-linearize-bits an)))
(LAP ,@((pblock-consequent-lap-generator pblock) label)
,@alternative
,@(if (node-marked? cn)
(LAP)
(bblock-linearize-bits cn)))))))
)
(define (map-lap procedure objects)
(let loop ((objects objects))
(if (null? objects)
(LAP)
(LAP ,@(procedure (car objects))
,@(loop (cdr objects))))))
(define linearize-bits
(make-linearizer map-lap bblock-linearize-bits))
| false |
8a36ffc9c83200c09d25fab9b60b6a3edf8b015c
|
323d2a98cec91f5bd5f805f745a9085e027cc10d
|
/Resources/src/config.ss
|
2de737b50fc0f854f3672b126f37b7ef65dff248
|
[
"MIT",
"LicenseRef-scancode-public-domain"
] |
permissive
|
becls/convert-and-search
|
11a559580c9b1a2e48a5e6b583b9a3e1cb32420b
|
e5731689e354175551a388ba744a494f4d0f3ab0
|
refs/heads/dev
| 2023-02-09T04:55:24.531041 | 2023-02-03T18:29:55 | 2023-02-03T18:29:55 | 144,314,963 | 1 | 0 |
MIT
| 2023-02-03T18:29:57 | 2018-08-10T17:31:01 |
Scheme
|
UTF-8
|
Scheme
| false | false | 1,899 |
ss
|
config.ss
|
;;; Copyright 2018 Beckman Coulter, Inc.
;;;
;;; 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 permirespot persons to whom the Software is
;;; furnished to do so, subject to the following conditions:
;;;
;;; The above copyright notice and this permission notice shall be
;;; included in all copies or substantial portions of the Software.
;;;
;;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
;;; EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
;;; MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
;;; NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
;;; HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
;;; WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
;;; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
;;; DEALINGS IN THE SOFTWARE.
(library (config)
(export
setup-config-db
user-log-path
)
(import
(chezscheme)
(swish imports)
)
(define schema-name 'config)
(define schema-version "2018-06-21")
(define (setup-config-db)
(match (log-db:version schema-name)
[,@schema-version (create-db)]
[#f
(log-db:version schema-name schema-version)
(create-db)]
[,version (raise `#(unsupported-db-version ,schema-name ,version))]))
(define (create-db)
(execute "create table if not exists database (Name text, Description text, File_Path text primary key)")
(execute "create table if not exists search (Name text, Description text, SQLite text primary key)")
)
(define user-log-path (make-parameter #f))
)
| false |
359a934f0d2eda1657932ce4d5b8725c5ad78212
|
a8216d80b80e4cb429086f0f9ac62f91e09498d3
|
/lib/chibi/net/http.sld
|
ab53fd2661b2ad4a9c08243937f7f0640bf6e01e
|
[
"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 | 1,724 |
sld
|
http.sld
|
(define-library (chibi net http)
(export http-get http-get/headers http-get-to-file
http-head http-post http-put http-delete
call-with-input-url call-with-input-url/headers
with-input-from-url
http-parse-request http-parse-form)
(import (scheme base) (scheme write) (scheme char) (scheme file)
(srfi 27)
(chibi uri) (chibi mime))
(cond-expand
(chicken
(import (only (chicken) parameterize))
(import (only (ports) make-input-port))
(import (only (tcp) tcp-connect))
(begin
(define (make-custom-binary-input-port read-bv)
(let ((bv (make-bytevector 1024))
(off 0)
(fill 0))
(define (refill!)
(set! off 0)
(set! fill (read-bv bv 0 1024)))
(make-input-port
(lambda ()
(if (>= off fill)
(refill!))
(if (< off fill)
(read-char (open-input-string ""))
(let ((res (integer->char (bytevector-u8-ref bv off))))
(set! off (+ 1 off))
res)))
(lambda ()
(or (< off fill)
(begin (refill!) (< off fill))))
(lambda () #f))))
(define (open-net-io host port . o)
(call-with-values (lambda () (tcp-connect host port))
(lambda (in out)
(list #f in out))))
(define (port->bytevector in)
(let ((out (open-output-bytevector)))
(do ((c (read-u8 in) (read-u8 in)))
((eof-object? c) (get-output-bytevector out))
(write-u8 c out))))))
(else
(import (srfi 39) (chibi io) (chibi net))))
(include "http.scm"))
| false |
396da6cc853bece8c2590ffb19d970e3c4c84086
|
b43e36967e36167adcb4cc94f2f8adfb7281dbf1
|
/sicp/ch3/exercises/3.50.scm
|
42e5015d06ae98115216d82a79b1fc757f627966
|
[] |
no_license
|
ktosiu/snippets
|
79c58416117fa646ae06a8fd590193c9dd89f414
|
08e0655361695ed90e1b901d75f184c52bb72f35
|
refs/heads/master
| 2021-01-17T08:13:34.067768 | 2016-01-29T15:42:14 | 2016-01-29T15:42:14 | 53,054,819 | 1 | 0 | null | 2016-03-03T14:06:53 | 2016-03-03T14:06:53 | null |
UTF-8
|
Scheme
| false | false | 447 |
scm
|
3.50.scm
|
(define (stream-map proc . argstreams)
(if (stream-null? (car argstreams))
the-empty-stream
(cons-stream
(apply proc (map stream-car argstreams))
(apply stream-map
(cons proc (map stream-cdr argstreams))))))
(define s1 (stream-enumerate-interval 10 100))
(define s2 (stream-enumerate-interval 20 200))
(define s3 (stream-enumerate-interval 30 300))
(define s (stream-map + s1 s2 s3))
(stream-ref s 2)
| false |
c0da22cdd745341a8af89b25e3cef0d3cbc962d9
|
2e50e13dddf57917018ab042f3410a4256b02dcf
|
/t/parameterize.scm
|
44b82f5def0cb43fa6b53e8d357687b4c57fbf37
|
[
"MIT"
] |
permissive
|
koba-e964/picrin
|
c0ca2596b98a96bcad4da9ec77cf52ce04870482
|
0f17caae6c112de763f4e18c0aebaa73a958d4f6
|
refs/heads/master
| 2021-01-22T12:44:29.137052 | 2016-07-10T16:12:36 | 2016-07-10T16:12:36 | 17,021,900 | 0 | 0 |
MIT
| 2019-05-17T03:46:41 | 2014-02-20T13:55:33 |
Scheme
|
UTF-8
|
Scheme
| false | false | 340 |
scm
|
parameterize.scm
|
(import (scheme base)
(scheme write)
(picrin test))
(test-begin)
(test "piece by piece by piece.\n"
(parameterize
((current-output-port (open-output-string)))
(display "piece")
(display " by piece ")
(display "by piece.")
(newline)
(get-output-string)))
(test-end)
| false |
3fb598cba559518092f124136a76905cd4be748a
|
f07bc117302b8959f25449863c6fdabdda510c48
|
/z3-server-robust.scm
|
2fcf46ac1b8bd2c34dfa9f0d1bd203342194dbf4
|
[
"MIT"
] |
permissive
|
namin/clpsmt-miniKanren
|
3a1165a20dc1c50e4d568e2e493b701fb9f5caea
|
d2270aa14410805fa7068150bc2ab2f3bf9391b4
|
refs/heads/master
| 2022-03-10T07:05:21.950751 | 2022-02-26T23:54:05 | 2022-02-26T23:54:05 | 129,262,229 | 33 | 9 |
MIT
| 2021-08-03T16:02:50 | 2018-04-12T14:14:59 |
Scheme
|
UTF-8
|
Scheme
| false | false | 3,050 |
scm
|
z3-server-robust.scm
|
(define z3-counter-check-sat 0)
(define z3-counter-get-model 0)
(define log-all-calls #f)
(define-values (z3-out z3-in z3-err z3-p)
(open-process-ports "z3 -in" 'block (native-transcoder)))
(define (z3-reset!)
(let-values (((out in err p)
(open-process-ports "z3 -in" 'block (native-transcoder))))
(set! z3-out out)
(set! z3-in in)
(set! z3-err err)
(set! z3-p p)))
(define (z3-check-in!)
(if (eof-object? z3-in)
(error 'z3-check-in "z3 input port")
;; (if (= 0 (mod z3-counter-check-sat 300))
;; (z3-reset!)
;; #t)
#t))
(define read-sat
(lambda ()
(z3-check-in!)
(let ([r (read z3-in)])
(when log-all-calls (printf ";; ~a\n" r))
(if (eq? r 'sat)
#t
(if (eq? r 'unsat)
#f
(if (eq? r 'unknown)
(begin
(printf "read-sat: unknown\n")
(call-z3 '((pop)))
#f)
(error 'read-sat (format "~a" r))))))))
(define call-z3
(lambda (xs)
(for-each (lambda (x)
(when log-all-calls (printf "~a\n" x))
(when (and (pair? x)
(eq? 'assert (car x))
(pair? (cadr x))
(eq? '=> (caadr x)))
(fprintf z3-out "(push) "))
(fprintf z3-out "~a\n" x)) xs)
(flush-output-port z3-out)))
(define check-sat
(lambda (xs)
(call-z3 (append (cons '(reset) xs) '((check-sat))))
(set! z3-counter-check-sat (+ z3-counter-check-sat 1))
(read-sat)))
(define read-model
(lambda ()
(let ([m (read z3-in)])
(when log-all-calls (printf "~a\n" m))
(map (lambda (x)
(cons (cadr x)
(if (null? (caddr x))
(let ([r (cadddr (cdr x))])
(cond
((eq? r 'false) #f)
((eq? r 'true) #t)
((and (pair? (cadddr x)) (eq? (cadr (cadddr x)) 'BitVec)) r)
(else (eval r))))
`(lambda ,(map car (caddr x)) ,(cadddr (cdr x))))))
(cdr m)))))
(define get-model-inc
(lambda ()
(call-z3 '((get-model)))
(set! z3-counter-get-model (+ z3-counter-get-model 1))
(read-model)))
(define get-model
(lambda (xs)
(and (check-sat xs)
(get-model-inc))))
(define neg-model
(lambda (model)
(cons
'assert
(list
(cons
'or
(map
(lambda (xv)
`(not (= ,(car xv) ,(cdr xv))))
model))))))
(define get-next-model
(lambda (xs ms)
(let* ([ms (map (lambda (m)
(filter (lambda (x) ; ignoring functions
(or (number? (cdr x))
(symbol? (cdr x)) ; for bitvectors
)) m))
ms)])
(if (member '() ms) #f ; if we're skipping a model, let us stop
(and (check-sat (append xs (map neg-model ms)))
(get-model-inc))))))
| false |
7ca6cd49b9e02a6ef03a9a195c30bbf036349852
|
dd4cc30a2e4368c0d350ced7218295819e102fba
|
/vendored_parsers/vendor/highlights/hare.scm
|
c4cd781c3a09ddca566e4dc1ed43fb980bdf7336
|
[
"LicenseRef-scancode-unknown-license-reference",
"MIT",
"Apache-2.0"
] |
permissive
|
Wilfred/difftastic
|
49c87b4feea6ef1b5ab97abdfa823aff6aa7f354
|
a4ee2cf99e760562c3ffbd016a996ff50ef99442
|
refs/heads/master
| 2023-08-28T17:28:55.097192 | 2023-08-27T04:41:41 | 2023-08-27T04:41:41 | 162,276,894 | 14,748 | 287 |
MIT
| 2023-08-26T15:44:44 | 2018-12-18T11:19:45 |
Rust
|
UTF-8
|
Scheme
| false | false | 42 |
scm
|
hare.scm
|
../tree-sitter-hare/queries/highlights.scm
| false |
73beb578f17da2c3313bcb78a7ea6ef453eadc56
|
defeada37d39bca09ef76f66f38683754c0a6aa0
|
/UnityEngine/unity-engine/rect-offset.sls
|
5ea429a148691f42730a13926c6d38326efb0a64
|
[] |
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,818 |
sls
|
rect-offset.sls
|
(library (unity-engine rect-offset)
(export new
is?
rect-offset?
add
remove
to-string
left-get
left-set!
left-update!
right-get
right-set!
right-update!
top-get
top-set!
top-update!
bottom-get
bottom-set!
bottom-update!
horizontal
vertical)
(import (ironscheme-clr-port))
(define-syntax new
(lambda (e)
(syntax-case e ()
((_ a ...) #'(clr-new UnityEngine.RectOffset a ...)))))
(define (is? a) (clr-is UnityEngine.RectOffset a))
(define (rect-offset? a) (clr-is UnityEngine.RectOffset a))
(define-method-port
add
UnityEngine.RectOffset
Add
(UnityEngine.Rect UnityEngine.Rect))
(define-method-port
remove
UnityEngine.RectOffset
Remove
(UnityEngine.Rect UnityEngine.Rect))
(define-method-port
to-string
UnityEngine.RectOffset
ToString
(System.String))
(define-field-port
left-get
left-set!
left-update!
(property:)
UnityEngine.RectOffset
left
System.Int32)
(define-field-port
right-get
right-set!
right-update!
(property:)
UnityEngine.RectOffset
right
System.Int32)
(define-field-port
top-get
top-set!
top-update!
(property:)
UnityEngine.RectOffset
top
System.Int32)
(define-field-port
bottom-get
bottom-set!
bottom-update!
(property:)
UnityEngine.RectOffset
bottom
System.Int32)
(define-field-port
horizontal
#f
#f
(property:)
UnityEngine.RectOffset
horizontal
System.Int32)
(define-field-port
vertical
#f
#f
(property:)
UnityEngine.RectOffset
vertical
System.Int32))
| true |
d6be1da52d472be1b6c68895cd64b2350bd2f867
|
46244bb6af145cb393846505f37bf576a8396aa0
|
/sicp/4_36.scm
|
01fae585daf5714cb7e28fbc095f3d9b4d2d78e3
|
[] |
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 | 1,245 |
scm
|
4_36.scm
|
#lang racket
#|
Exercise 4.36. Exercise 3.69 discussed how to generate the stream of all
Pythagorean triples, with no upper bound on the size of the integers to be
searched. Explain why simply replacing an-integer-between by an-integer-starting-from
in the procedure in exercise 4.35 is not an adequate way to generate arbitrary Pythagorean triples.
Write a procedure that actually will accomplish this. (That is, write a procedure for which repeatedly
typing try-again would in principle eventually generate all Pythagorean triples.)
|#
; Explain why simply replacing an-integer-between by an-integer-starting-from
; in the procedure in exercise 4.35 is not an adequate way to generate arbitrary Pythagorean triples.
; Answer
; Because it will try to travel all values of k in the last an-integer-starting-from after amb give the
; 1st and 2nd value for i, j
; to avoid this, we have to make the amb end at j and k, so let's just assume i is the biggest bound.
; and use the rule `a-b<c` in triple
(define (pythagorean-triple)
(let ((i (an-integer-starting-from 5)))
(let ((j (an-integer-between 4 i)))
(let ((k (an-integer-between (- i j) i)))
(require (= (+ (* i i) (* j j)) (* k k)))
(list i j k)))))
| false |
ad04ccd1c25d85d28575391322e0dd8337594b83
|
d688b312fbe1d828993ae4684797475d965406ed
|
/samples/primes.scm
|
c815311101d042a31f05b95f03f15ac22af46d29
|
[
"Apache-2.0"
] |
permissive
|
theschemer/multischeme
|
2b75288509c162df63964be1072b7e6d31b4c7bc
|
637d80ae7e42a660ae8e5d6e609e896a6d826787
|
refs/heads/master
| 2021-05-28T20:21:48.745634 | 2015-01-01T04:50:24 | 2015-01-01T04:50:24 | null | 0 | 0 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 1,898 |
scm
|
primes.scm
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Sample Scheme program that computes the Nth prime number ;;
;; using sieve built from chaining filtering tasks ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(load "samples/mailboxes.scm")
;;;;;;;;;;;;;;;;;;;;;;;;
;; Processing threads ;;
;;;;;;;;;;;;;;;;;;;;;;;;
(define (filter-composites prime mailbox child-mailbox)
(let ((next-number (mailbox-receive mailbox)))
(if (= (remainder next-number prime) 0)
(filter-composites prime mailbox child-mailbox)
(begin (mailbox-send child-mailbox next-number)
(filter-composites prime mailbox child-mailbox)))))
(define (filter-task mailbox primes-mailbox)
(make-task (lambda ()
(let ((prime (mailbox-receive mailbox)))
(begin (mailbox-send primes-mailbox prime)
(let ((child-mailbox (make-mailbox)))
(let ((child (filter-task child-mailbox
primes-mailbox)))
(filter-composites prime mailbox
child-mailbox))))))))
(define (drive next-number mailbox)
(begin (mailbox-send mailbox next-number)
(drive (+ next-number 1) mailbox)))
(define (driver-task mailbox)
(make-task (lambda () (drive 2 mailbox))))
(define (read-primes count primes-mailbox)
(if (> count 0)
(cons (mailbox-receive primes-mailbox)
(read-primes (- count 1) primes-mailbox))
'()))
(let ((numbers-mailbox (make-mailbox))
(primes-mailbox (make-mailbox)))
(let ((filter (filter-task numbers-mailbox primes-mailbox))
(driver (driver-task numbers-mailbox)))
(begin (display (read-primes 100 primes-mailbox))
(newline)
(task-kill filter)
(task-kill driver))))
| false |
2af2c167605fcb687faf690b47a7dc285e169e21
|
86c001154e57121157873d0f1348c540ecea6675
|
/data.ss
|
19f0544d59d23a65bca290e6be604ac7330de867
|
[] |
no_license
|
Memorytaco/melt-core
|
d9d3cd2d38cf4154bd9544a87a02ee0c3d6f765a
|
e6cf20ae881b33523f17959019d66499ae74c667
|
refs/heads/master
| 2020-04-30T02:00:16.058976 | 2019-04-18T13:24:50 | 2019-04-18T13:24:50 | 176,546,164 | 1 | 0 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 3,463 |
ss
|
data.ss
|
(library
(melt data)
(export create-data
update-data!
data-keys
data-values
data-guards
data->alist
data-guard-query
data-value-query)
(import (scheme)
(melt cell)
(melt utils))
;; !!!!!! need to take use of gurd of cell
;; accept nothing or list of keys and list of values
;; keys are a list symbols
;; values are corresponded to the keys
;; or an assoc list
(define create-data
(lambda args
(cond
[(null? args)
(make-cell '())]
[(and (eq? 1 (length args)) (alist? (car args)))
((lambda (keys values)
(make-cell (map cons keys (map make-cell values))))
(map car (car args))
(map cdr (car args)))]
[(and (eq? 2 (length args)) (list? (car args)))
((lambda (keys values)
(make-cell (map cons keys (map make-cell values))))
(car args)
(cadr args))]
[else
(error 'create-data "please provide keys and args or nothing")])))
;; return the data key list
(define (data-keys data)
(map car (data)))
;; return the data value list
(define (data-values data)
(map (lambda (proc) (proc)) (map cdr (data))))
;; return a list of accessors
(define (data-guards data)
(map cdr (data)))
;; delete one item in data, return left item
(define (%delete-data key data)
(remove (assq key (data)) (data)))
;; transform data to an association list
(define (data->alist data)
(map cons (data-keys data) (data-values data)))
;; same as %delete-data, but return unspecific
(define (%delete-data! key data)
(data (remove (assq key (data)) (data))))
;; query one value via a key
(define (data-value-query key data)
(if (memv key (data-keys data))
(force (cdr (assq key (data))))
#f))
;; query one accessor of one item
(define (data-guard-query key data)
(if (memv key (data-keys data))
(cdr (assq key (data)))
#f))
;; add one item in data
;; return the alist if successfully
;; return #f if exist one
(define (%add-data! key value data)
(if (memv key (data-keys data))
#f
(begin
(data (cons (cons key (make-cell value)) (data)))
(data->alist data))))
;; it receives three type args
;; 1. the data type, used to update values or add new values
;; 2. the assoc list, same as 1
;; 3. a list of symbols, all the symbols may be the keys and it
;; will delete items in the data
;; first two is used to update! the data
;; the third is used to delete! the data
(define (update-data! k-values data)
(if (and (procedure? data) (alist? (data)))
(cond
[(alist? k-values)
(do ((keys (map car k-values) (cdr keys)))
((null? keys) data)
(if (memv (car keys) (data-keys data))
((data-guard-query (car keys) data)
(cdr (assq (car keys) k-values)))
(%add-data! (car keys) (cdr (assq (car keys) k-values)) data)))]
[(procedure? k-values)
(update-data! (data->alist k-values) data)]
[(list? k-values)
(do ((keys k-values (cdr keys)))
((null? keys) data)
(%delete-data! (car keys) data))]
[else (error 'update-data! "no matched keys")])
(error 'update-data! "should accept one data")))
)
| false |
fe94bb55f3c2176d0ddd849678f8558c97b11e37
|
958488bc7f3c2044206e0358e56d7690b6ae696c
|
/scheme/changecount.scm
|
492b199355a5a321ac0ccabff66c2515cdd44167
|
[] |
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 | 536 |
scm
|
changecount.scm
|
(define (d k) ; array of coin denominations
(cond ((= k 0) 1)
((= k 1) 5)
((= k 2) 10)
((= k 3) 25)
((= k 4) 50)
(else (display "Out of bound error\n"))))
(define (DP n x) ; ways of changing x using first n coins
(if (= 0 n)
(if (= 0 x) 1 0); (DP 0 0) = 1 and (DP 0 x) = 0 for x <> 0
(if (< x 0)
0 ; (DP n x) = 0 for x < 0
;; n > 0 and x >= 0 at this stage
(+ (DP (- n 1) x) (DP n (- x (d (- n 1))))))))
(display (DP 5 5))(newline)
(exit 0)
| false |
8a21dfa5fdab89317ce212613555ab8569663724
|
11150f2821f9bde74eeb9460149d452e6e689438
|
/fun/scheme/write-file.sch
|
2135d443ea7d5881378cc8149e82b3548f97edd6
|
[] |
no_license
|
doug16rogers/dr
|
a644e3379ddf586e677348225cde9475e654d277
|
2e32fa6eae310cfc0723d88add53249c7d82271b
|
refs/heads/master
| 2023-06-23T08:33:33.696720 | 2018-10-10T15:12:00 | 2018-10-10T15:12:00 | 5,799,618 | 3 | 1 | null | 2012-10-24T23:50:11 | 2012-09-13T19:16:21 |
Emacs Lisp
|
UTF-8
|
Scheme
| false | false | 383 |
sch
|
write-file.sch
|
(define (lwf) (load "write-file.sch"))
(define (write-file-list f xs)
(if (null? xs) '()
(begin
(write (car xs) f)
(write-file-list f (cdr xs)))))
(define (write-file filename s . opt)
(let ((f (open-file filename "w")))
(if (null? f) #f
(begin
(write s f)
(write-file-list f opt)
(close-port f)
#t))))
| false |
ba41686e5b6ec146f30e0736fee6537f7ae97975
|
7666204be35fcbc664e29fd0742a18841a7b601d
|
/code/1-33.scm
|
622dd20c8276b6532264fcc556608bf1ac1cef88
|
[] |
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 | 673 |
scm
|
1-33.scm
|
#lang racket
(define (filtered-acc pred combiner null-value term a next b)
(define (iter a)
(cond ((> a b) null-value)
((pred (term a))
(combiner (term a) (iter (next a))))
(else (iter (next a)))))
(iter a))
(define (accumulate combiner null-value term a next b)
(define (always-true x) #t)
(filtered-acc always-true combiner null-value term a next b))
(define (id x) x)
(define (inc x) (+ x 1))
(define (filtered-sum pred term a next b) (filtered-acc pred + 0 term a next b))
(define (filtered-sum-int pred a b) (filtered-sum pred id a inc b))
(require "prime.scm")
(filtered-sum-int prime? 1 10)
| false |
9dfd48bd12cc310820fa0161bf23d962e2e31951
|
6b8bee118bda956d0e0616cff9ab99c4654f6073
|
/schcuda/glew-libs.ss
|
be09db27bd22ed39d905ccda33e743d1a3c85044
|
[] |
no_license
|
skchoe/2012.Functional-GPU-Programming
|
b3456a92531a8654ae10cda622a035e65feb762d
|
56efdf79842fc465770214ffb399e76a6bbb9d2a
|
refs/heads/master
| 2016-09-05T23:42:36.784524 | 2014-05-26T17:53:34 | 2014-05-26T17:53:34 | 20,194,204 | 1 | 0 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 1,227 |
ss
|
glew-libs.ss
|
(module glew-libs mzscheme
(provide (all-defined))
(require scheme/foreign)
(unsafe!)
;;-----------------------------------------------------------------------------
(define glew-lib (case (system-type)
[(windows) (ffi-lib "glew32")]
; windows: currently unsupported
[(macosx) (ffi-lib "/System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libcuda")]
; macosx: currently unsupported
[else (ffi-lib (string-append (path->string (find-system-path 'home-dir))
"/local/glew/lib/libGLEW"))]))
(define-syntax define-foreign-lib
(syntax-rules (->)
((_ lib name type ... ->)
(define-foreign-lib lib name type ... -> _void))
((_ lib name type ...)
(begin
(provide name)
(define name
(get-ffi-obj 'name lib (_fun type ...) (unavailable 'name)))
;(printf "~s: defined\n" 'name)
))))
(define-syntax define-foreign-glew
(syntax-rules ()
((_ args ...)
(define-foreign-lib glew-lib args ...))))
(define (unavailable name)
(lambda ()
(lambda x
(error name "unavailable on this system")))))
| true |
77882aba259043dd71d49a4907f045e40a5e0dfb
|
35e2b9615d12f8ce2de22224bba58eeb77f0dd75
|
/test-by-expection.scm
|
ebc89a4b30a75a8cf7c6674d7cfc7258f392ce34
|
[] |
no_license
|
k6ky/Gauche-test-utils
|
bfa03c27656d3a7f7b350d66c97b2abf60437e3f
|
87bfb623399ac1a60e7203838cf260e7ba69035e
|
refs/heads/master
| 2020-04-29T16:49:12.810709 | 2015-06-22T08:59:05 | 2015-06-22T08:59:05 | 27,210,981 | 0 | 0 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 1,137 |
scm
|
test-by-expection.scm
|
(define-module test-utils.test-by-expection
(use gauche.test)
(export test-by-ex*
coin-test*))
(select-module test-utils.test-by-expection)
(define (trying number thunk)
(/ (fold (lambda (_ acc)
(+ acc (thunk)))
0
(iota number))
number))
(define (in-pardon? exception pardon value)
(if (and (> value (* exception (- 1 pardon)))
(< value (* exception (+ 1 pardon))))
#t
(error "the value is not in ragne" (+ 0.0 value))))
(define-syntax test-by-ex*
(syntax-rules ()
((_ test-name exception trying-number pardon expr)
(test* (string-append "RANDOM: " test-name)
#t
(in-pardon? exception
pardon
(trying trying-number (lambda () expr)))))))
(define-syntax coin-test*
(syntax-rules ()
((_ test-name trying-number pardon succuess-rate fail-rate expr)
(test-by-ex* test-name
(/ succuess-rate (+ succuess-rate fail-rate))
trying-number
pardon
(if expr 1 0)))))
(provide "test-by-expection")
| true |
749f5d6e8940ff9710cbdad8466a5f8e20c5f34a
|
db442e9ba81eb899a2a1a289ce66311c0cce8021
|
/sample-lib/cyclone/sample.sld
|
3cef1985bbf57ec7a62fbb7db77b8ee22b308e0f
|
[] |
no_license
|
cyclone-scheme/cyclone-packages
|
b336aece25b3031ec03db179303e27703f3f88d0
|
16b41a22f2f55628078409b26f204b6b500834a2
|
refs/heads/master
| 2021-01-20T05:13:08.219700 | 2017-04-16T22:18:42 | 2017-04-16T22:18:42 | 83,856,503 | 0 | 2 | null | 2017-04-17T00:31:28 | 2017-03-04T01:37:13 |
Scheme
|
UTF-8
|
Scheme
| false | false | 149 |
sld
|
sample.sld
|
;; A sample library
(define-library (cyclone sample)
(import (scheme base))
(export info)
(begin
(define (info)
'a-sample-library)))
| false |
8e2801d7b26ad4da1856152cbc0805c87469f2f6
|
ece1c4300b543df96cd22f63f55c09143989549c
|
/Chapter2/Exercise 2.35.scm
|
35a322ceecf8ee4007e8d8ed8cd53a9d6de93d30
|
[] |
no_license
|
candlc/SICP
|
e23a38359bdb9f43d30715345fca4cb83a545267
|
1c6cbf5ecf6397eaeb990738a938d48c193af1bb
|
refs/heads/master
| 2022-03-04T02:55:33.594888 | 2019-11-04T09:11:34 | 2019-11-04T09:11:34 | null | 0 | 0 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 1,145 |
scm
|
Exercise 2.35.scm
|
; Exercise 2.35: Redefine count-leaves from 2.2.2 as an accumulation:
; (define (count-leaves t)
; (accumulate ⟨??⟩ ⟨??⟩ (map ⟨??⟩ ⟨??⟩)))
(define (enumerate-tree tree)
(cond ((null? tree) nil)
((not (pair? tree)) (list tree))
(else (append
(enumerate-tree (car tree))
(enumerate-tree (cdr tree))))))
(define (accumulate op initial sequence)
(if (null? sequence)
initial
(op (car sequence)
(accumulate op
initial
(cdr sequence)))))
(define (count-leaves t)
(accumulate
(lambda (x y)
(+ x y)
)
0
(map (lambda (subtree)
(if (pair? subtree)
(count-leaves subtree)
1
)
)
t)))
(define x (cons (list 1 2) (list 3 4)))
(count-leaves x)
(count-leaves (list x x))
; Welcome to DrRacket, version 6.7 [3m].
; Language: SICP (PLaneT 1.18); memory limit: 128 MB.
; 4
; 8
; >
| false |
b7e2a5f27d99ce677de25a4e967684fad4f52afb
|
58381f6c0b3def1720ca7a14a7c6f0f350f89537
|
/Chapter 2/2.3/Ex2.60.scm
|
c6dad93caccc61e69e5c69727a6fa7703fe5d50c
|
[] |
no_license
|
yaowenqiang/SICPBook
|
ef559bcd07301b40d92d8ad698d60923b868f992
|
c8a0228ebf66d9c1ddc5ef1fcc1d05d8684f090a
|
refs/heads/master
| 2020-04-19T04:03:15.888492 | 2015-11-02T15:35:46 | 2015-11-02T15:35:46 | null | 0 | 0 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 1,286 |
scm
|
Ex2.60.scm
|
#lang planet neil/sicp
;; helpers
(define (element-of-set? x set)
(cond ((null? set) false)
((equal? x (car set)) true)
(else (element-of-set? x (cdr set)))))
;;O(N) no difference from version in 2.59
(define (adjoin-set x set)
(cons x set))
;;O(1) different from version in 2.59 which is O(N)
(define (union-set set1 set2)
(define (iter s1 result)
(if (null? s1)
result
(iter (cdr s1)
(adjoin-set (car s1) result))))
(iter set1 set2))
;;O(N) different version in 2.59 which is O(N**2)
(define (intersection-set set1 set2)
(cond ((or (null? set1) (null? set2))
'())
((element-of-set? (car set1) set2)
(cons (car set1)
(intersection-set (cdr set1)
set2)))
(else (intersection-set (cdr set1)
set2))))
;;O(N**2) not different from version in 2.59
;;This version might be preferred for operations on large datasets
;; which require speed. The flipside is that lookups might take more
;; time as N grows larger due to replication of the same values and more
;; memory usage too.
(union-set '(1 2 3) '(4 5 6))
(union-set '() '(4 5 6 6))
(union-set '(1 2 3) '(1 2 3))
(intersection-set '(1 2 2 3) '(1 2 4 6))
| false |
63a61e1717408f0369126e949d9f90a7b087c8a3
|
8f0ceb57d807ba1c92846ae899736b0418003e4f
|
/INF2810/practice for exam/exercises/1_4.scm
|
68e279d2886d6d2c26fc0c1ae9d8575062c47dd6
|
[] |
no_license
|
hovdis/UiO
|
4549053188302af5202c8294a89124adb4eb981b
|
dcaa236314d5b0022e6be7c2cd0b48e88016475a
|
refs/heads/master
| 2020-09-16T04:04:22.283098 | 2020-02-26T08:21:21 | 2020-02-26T08:21:21 | 223,645,789 | 0 | 0 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 313 |
scm
|
1_4.scm
|
(define (a-plus-abs-b a b)
((if (> b 0) + -) a b))
#|
The function adds a to the absolute-value of b.
If the value of b is negative; the b is subtracted from a.
Since b is then negative, it will be (a - - b).
If the value of b is positive; the b is added to a.
Since b is then positive, it will be (a + b).
|#
| false |
396a36f06e850c6e90934387ee59cd35357815f9
|
6b8bee118bda956d0e0616cff9ab99c4654f6073
|
/suda-ex/test-suda-module-reqprov/testlang-child.ss
|
60961b714a444cd9fa55d3d1e4cbb5d954aeee51
|
[] |
no_license
|
skchoe/2012.Functional-GPU-Programming
|
b3456a92531a8654ae10cda622a035e65feb762d
|
56efdf79842fc465770214ffb399e76a6bbb9d2a
|
refs/heads/master
| 2016-09-05T23:42:36.784524 | 2014-05-26T17:53:34 | 2014-05-26T17:53:34 | 20,194,204 | 1 | 0 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 73 |
ss
|
testlang-child.ss
|
#lang testlang
(require "testlang-parent.ss")
(printf "XXXXX ~a" a)
| false |
60576190ce94ceb3c5ee8bd2323466dc4ec84c95
|
6bd63be924173b3cf53a903f182e50a1150b60a8
|
/chapter_3/3.2.scm
|
e64ee9dfc200d5abc53c5fd3b7dc8bde4dd165da
|
[] |
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 | 758 |
scm
|
3.2.scm
|
; things worth doing typically take time and effort
; 3.2
(define (make-monitored func)
(let ((count 0))
(define (how-many-calls?) count)
(define (reset-count) (set! count 0))
(define (call-func arg) (begin (set! count (+ 1 count)) (func arg)))
(define (dispatch arg)
(cond ((eq? arg 'how-many-calls?) (how-many-calls?))
((eq? arg 'reset-count) (reset-count))
(else (call-func arg))))
dispatch))
(define (try)
(define s (make-monitored sqrt))
(display (s 100))
(newline)
(display (s 100))
(newline)
(display (s 'how-many-calls?))
(s 'reset-count)
(newline)
(display (s 100))
(newline)
(display (s 'how-many-calls?))
)
(try)
| false |
2732ebf9ada7d86c7f368a1fcfa0b8aecf362677
|
9b2eb10c34176f47f7f490a4ce8412b7dd42cce7
|
/lib-compat/larceny-yuni/compat/file-ops.sls
|
5ace99fa347d92f1f305e7e0f3f0d4504c6e6cf4
|
[
"LicenseRef-scancode-public-domain",
"CC0-1.0"
] |
permissive
|
okuoku/yuni
|
8be584a574c0597375f023c70b17a5a689fd6918
|
1859077a3c855f3a3912a71a5283e08488e76661
|
refs/heads/master
| 2023-07-21T11:30:14.824239 | 2023-06-11T13:16:01 | 2023-07-18T16:25:22 | 17,772,480 | 36 | 6 |
CC0-1.0
| 2020-03-29T08:16:00 | 2014-03-15T09:53:13 |
Scheme
|
UTF-8
|
Scheme
| false | false | 1,007 |
sls
|
file-ops.sls
|
(library (larceny-yuni compat file-ops)
(export
;; chez like file-ops
file-regular?
file-directory?
directory-list
current-directory
;; mosh directory procedure
create-directory
delete-directory
)
(import (scheme base)
(primitives
;; Some of them are not described in the manual
list-directory
larceny:directory?
current-directory
;; For create-directory
system))
(define directory-list list-directory)
(define file-directory? larceny:directory?)
(define (file-regular? x)
;; FIXME: Does file-attributes working on Win32??
(not (file-directory? x)))
(define (create-directory pth)
;; FIXME: Seriously??
(system (string-append "mkdir " pth)))
(define (delete-directory pth)
;; FIXME: Seriously??
(system (string-append "rmdir " pth)))
)
| false |
c628e005526b02db4f05a090ca69cfa19f1f7539
|
784dc416df1855cfc41e9efb69637c19a08dca68
|
/src/misc/rpc-perf/baseline-io.ss
|
207d2fba1d4cb400c0b125878a13256aa95cb137
|
[
"LGPL-2.1-only",
"Apache-2.0",
"LGPL-2.1-or-later"
] |
permissive
|
danielsz/gerbil
|
3597284aa0905b35fe17f105cde04cbb79f1eec1
|
e20e839e22746175f0473e7414135cec927e10b2
|
refs/heads/master
| 2021-01-25T09:44:28.876814 | 2018-03-26T21:59:32 | 2018-03-26T21:59:32 | 123,315,616 | 0 | 0 |
Apache-2.0
| 2018-02-28T17:02:28 | 2018-02-28T17:02:28 | null |
UTF-8
|
Scheme
| false | false | 1,674 |
ss
|
baseline-io.ss
|
;; -*- Gerbil -*-
package: misc/rpc-perf
(import :gerbil/gambit/threads
:gerbil/gambit/bytes
:std/net/socket
:std/sugar
:std/getopt)
(export main)
(def (run-client address count)
(let* ((sock (ssocket-connect address))
(msg (@bytes "ping pong! i love ping poong!"))
(inb (make-u8vector (u8vector-length msg))))
(let lp ((k 0))
(when (fx< k count)
(ssocket-send-all sock msg)
(ssocket-recv-all sock inb)
(lp (fx1+ k))))))
(def (run-server address)
(let (sock (ssocket-listen address))
(let lp ()
(let (cli (ssocket-accept sock))
(spawn run-client-connection cli)
(lp)))))
(def (run-client-connection sock)
(def buf (make-u8vector 256))
(let lp ()
(let (rd (ssocket-recv sock buf))
(unless (fx= rd 0)
(ssocket-send-all sock buf 0 rd)
(lp)))))
(def (main . args)
(def srvcmd
(command 'server help: "run as a server"))
(def clicmd
(command 'client help: "run as a client"
(argument 'count help: "number of calls"
value: string->number)))
(def gopt
(getopt (option 'address "-a" "--address"
help: "server address"
default: "127.0.0.1:9999")
srvcmd
clicmd))
(try
(let ((values cmd opt) (getopt-parse gopt args))
(case cmd
((client)
(run-client (hash-get opt 'address)
(hash-get opt 'count)))
((server)
(run-server (hash-get opt 'address)))))
(catch (getopt-error? exn)
(getopt-display-help exn "baseline" (current-error-port))
(exit 1))))
| false |
3844e9643c0e6598a5662a6763121c01a82162ef
|
72f761ae4ce62922cc5b6003afbd785a554c7705
|
/lib/control-operators/primitives.chezscheme.sls
|
b3b4117debac3bab58a8a9435c857003347cbdaa
|
[] |
no_license
|
pre-srfi/control-operators
|
66ee281fd834ee14a0469e4d653004bf24a1bfb5
|
f17333ec535bd4a8732a256423a4a304dd414b19
|
refs/heads/master
| 2023-07-02T18:36:59.879377 | 2021-08-08T08:34:36 | 2021-08-08T08:34:36 | 378,713,951 | 1 | 0 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 2,462 |
sls
|
primitives.chezscheme.sls
|
#!r6rs
;; Copyright (C) Marc Nieper-Wißkirchen (2021). 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.
(library (control-operators primitives)
(export %call-with-current-continuation
%call-in-continuation
(rename [eq? %continuation=?])
%case-lambda-box %case-lambda-box-ref)
(import (except (rnrs (6)) call-with-current-continuation)
(only (chezscheme) make-ephemeron-eq-hashtable))
(define procedure-locations
(let ([locations (make-ephemeron-eq-hashtable)])
(lambda () locations)))
(define-syntax %case-lambda-box
(syntax-rules ()
[(%case-lambda-box expr [formals body] ...)
(let ([proc (case-lambda [formals body] ...)])
(hashtable-set! (procedure-locations) proc expr)
proc)]))
(define %case-lambda-box-ref
(lambda (proc default)
(hashtable-ref (procedure-locations) proc default)))
(define continuation
(let ([continuations (make-ephemeron-eq-hashtable)])
(case-lambda
[(k) (hashtable-ref continuations k #f)]
[(k c) (hashtable-update! continuations k values c)])))
(define %call-with-current-continuation
(lambda (proc)
(call/cc
(lambda (k)
((call/cc
(lambda (abort-k)
(continuation k abort-k)
(lambda ()
(proc k)))))))))
(define %call-in-continuation
(lambda (k thunk)
((assert (continuation k)) thunk))))
;; Local Variables:
;; mode: scheme
;; End:
| true |
ce6f4ce31fdbab321ac2d28081df97bcaa39912d
|
ea1c63550632110b6b4f36dda51afea9fb94b92a
|
/srfi-92.scm
|
b33adf14aa1cf5e7a3072a0f64d1fdb337a5e33b
|
[] |
no_license
|
scheme-requests-for-implementation/srfi-92
|
aab49762a84e6250ec54fa74e835635cce1c5554
|
541ef2be8e4dd8b0b1768df81ac8ab2c68a08f63
|
refs/heads/master
| 2020-12-25T16:49:11.340310 | 2020-05-03T22:30:15 | 2020-05-03T22:30:15 | 37,926,840 | 1 | 1 | null | 2019-09-20T22:09:41 | 2015-06-23T15:15:56 |
Scheme
|
UTF-8
|
Scheme
| false | false | 62,625 |
scm
|
srfi-92.scm
|
(define-syntax alambda
(syntax-rules (cond)
((alambda (g . e) b d ...)
(%alambda "chk" () (() () () ()) () () () (() ()) () (g . e) b d ...))
((alambda (cond clause cl ...))
(lambda z
(let ((len (length z)))
(check-cond z len () () clause cl ...))))
((alambda e b d ...)
(lambda e b d ...))))
(define-syntax %alambda
(syntax-rules ()
;; "chk"
((%alambda "chk" () ((h ...) () () ()) (r ...) ()
() (() ()) () ("required cat" . e) bd ...)
(%alambda "rat" () ((h ...) () () ()) (r ...) () () (() ()) () e bd ...))
((%alambda "chk" () ((h ...) () () ()) (r ...) ()
() (() ()) () ("required key" . e) bd ...)
(%alambda "rey" () ((h ...) () () ()) (r ...) () () (() ()) () e bd ...))
((%alambda "chk" () ((h ...) () () ()) (r ...) ()
() (() ()) () ("opt" . e) bd ...)
(%alambda "opt" () ((h ...) () () ()) (r ...) () () (() ()) () e bd ...))
((%alambda "chk" () ((h ...) () () ()) (r ...) ()
() (() ()) () ("cat" . e) bd ...)
(%alambda "cat" () ((h ...) () () ()) (r ...) () () (() ()) () e bd ...))
((%alambda "chk" () ((h ...) () () ()) (r ...) ()
() (() ()) () ("key" . e) bd ...)
(%alambda "key" () ((h ...) () () ()) (r ...) () () (() ()) () e bd ...))
;; "rat"
((%alambda "rat" () ((h ...) (i in ...) () ()) (r ...) (rk ...)
() (() ()) () ("required key" . e) bd ...)
(%alambda "rey" () ((h ...) (i in ...) () ()) (r ...) (rk ...)
() (() ()) () e bd ...))
((%alambda "rat" () ((h ...) (i in ...) (j ...) (jk ...)) (r ...) (rk ...)
() (() ()) () ("opt" . e) bd ...)
(%alambda "opt" () ((h ...) (i in ...) (j ...) (jk ...)) (r ...) (rk ...)
() (() ()) () e bd ...))
((%alambda "rat" () ((h ...) (i in ...) (j ...) (jk ...)) (r ...) (rk ...)
() (() ()) () ("cat" . e) bd ...)
(%alambda "cat" () ((h ...) (i in ...) (j ...) (jk ...)) (r ...) (rk ...)
() (() ()) () e bd ...))
((%alambda "rat" () ((h ...) (i in ...) (j ...) (jk ...)) (r ...) (rk ...)
() (() ()) () ("key" . e) bd ...)
(%alambda "key" () ((h ...) (i in ...) (j ...) (jk ...)) (r ...) (rk ...)
() (() ()) () e bd ...))
;; "rey"
((%alambda "rey" () ((h ...) () (j jn ...) (jk ...)) (r ...) (rk ...)
() (() ()) () ("required cat" . e) bd ...)
(%alambda "rat" () ((h ...) () (j jn ...) (jk ...)) (r ...) (rk ...)
() (() ()) () e bd ...))
((%alambda "rey" () ((h ...) (i ...) (j jn ...) (jk ...)) (r ...) (rk ...)
() (() ()) () ("opt" . e) bd ...)
(%alambda "opt" () ((h ...) (i ...) (j jn ...) (jk ...)) (r ...) (rk ...)
() (() ()) () e bd ...))
((%alambda "rey" () ((h ...) (i ...) (j jn ...) (jk ...)) (r ...) (rk ...)
() (() ()) () ("cat" . e) bd ...)
(%alambda "cat" () ((h ...) (i ...) (j jn ...) (jk ...)) (r ...) (rk ...)
() (() ()) () e bd ...))
((%alambda "rey" () ((h ...) (i ...) (j jn ...) (jk ...)) (r ...) (rk ...)
() (() ()) () ("key" . e) bd ...)
(%alambda "key" () ((h ...) (i ...) (j jn ...) (jk ...)) (r ...) (rk ...)
() (() ()) () e bd ...))
;; "opt"
((%alambda "opt" () hijk (r ...) (rk ...)
(o on ...) (() ()) () ("cat" . e) bd ...)
(%alambda "cat" () hijk (r ...) (rk ...)
(o on ...) (() ()) () e bd ...))
((%alambda "opt" () hijk (r ...) (rk ...)
(o on ...) (() ()) () ("key" . e) bd ...)
(%alambda "key" () hijk (r ...) (rk ...)
(o on ...) (() ()) () e bd ...))
;; "cat"
((%alambda "cat" () hijk (r ...) (rk ...)
(o ...) ((c cn ...) ()) (ok ...) ("key" . e) bd ...)
(%alambda "key" () hijk (r ...) (rk ...)
(o ...) ((c cn ...) ()) (ok ...) e bd ...))
;; "key"
((%alambda "key" () hijk (r ...) (rk ...)
(o ...) (() (k kn ...)) (ok ...) ("cat" . e) bd ...)
(%alambda "cat" () hijk (r ...) (rk ...)
(o ...) (() (k kn ...)) (ok ...) e bd ...))
;; key option
((%alambda check () ((h ...) (i ...) (j ...) (jk jkn ...)) (r ...)
(rk ...) (o ...) ((c ...) (k ...)) (ok ...) (#t . e) bd ...)
(%alambda check (#t) ((h ...) (i ...) (j ...) (jk jkn ...)) (r ...)
(rk ...) (o ...) ((c ...) (k ...)) (ok ...) e bd ...))
((%alambda check () ((h ...) (i ...) (j ...) (jk jkn ...)) (r ...)
(rk ...) (o ...) ((c ...) (k ...)) (ok ...) (#f . e) bd ...)
(%alambda check (#f) ((h ...) (i ...) (j ...) (jk jkn ...)) (r ...)
(rk ...) (o ...) ((c ...) (k ...)) (ok ...) e bd ...))
((%alambda check () hijk (r ...) (rk ...)
(o ...) ((c ...) (k kn ...)) (ok ...) (#t . e) bd ...)
(%alambda check (#t) hijk (r ...) (rk ...)
(o ...) ((c ...) (k kn ...)) (ok ...) e bd ...))
((%alambda check () hijk (r ...) (rk ...)
(o ...) ((c ...) (k kn ...)) (ok ...) (#f . e) bd ...)
(%alambda check (#f) hijk (r ...) (rk ...)
(o ...) ((c ...) (k kn ...)) (ok ...) e bd ...))
;; required fix arguments
((%alambda "chk" () ((h ...) () () ())
(r ...) () () (() ()) () ((n t s ...) . e) bd ...)
(%alambda "chk" () ((h ... hn) () () ())
(r ... (n t s ...)) () () (() ()) () e bd ...))
((%alambda "chk" () ((h ...) () () ())
(r ...) () () (() ()) () (n . e) bd ...)
(%alambda "chk" () ((h ... hn) () () ())
(r ... (n)) () () (() ()) () e bd ...))
;; required cat arguments
((%alambda "rat" () ((h ...) (i ...) (j ...) (jk ...))
(r ...) (rk ...) () (() ()) () ((n t s ...) . e) bd ...)
(%alambda "rat" () ((h ...) (i ... in) (j ...) (jk ...))
(r ...) (rk ... ((n) t s ...)) () (() ()) () e bd ...))
((%alambda "rat" () ((h ...) (i ...) (j ...) (jk ...))
(r ...) (rk ...) () (() ()) () (n . e) bd ...)
(%alambda "rat" () ((h ...) (i ... in) (j ...) (jk ...))
(r ...) (rk ... ((n))) () (() ()) () e bd ...))
;; required key arguments
((%alambda "rey" () ((h ...) (i ...) (j ...) (jk ...))
(r ...) (rk ...) () (() ()) () (((n key) t ...) . e) bd ...)
(%alambda "rey" () ((h ...) (i ...) (j ... jm jn) (jk ... key))
(r ...) (rk ... ((n key) t ...)) () (() ()) () e bd ...))
((%alambda "rey" () ((h ...) (i ...) (j ...) (jk ...))
(r ...) (rk ...) () (() ()) () ((n t s ...) . e) bd ...)
(%alambda "rey" () ((h ...) (i ...) (j ... jm jn) (jk ... 'n))
(r ...) (rk ... ((n 'n) t s ...)) () (() ()) () e bd ...))
((%alambda "rey" () ((h ...) (i ...) (j ...) (jk ...))
(r ...) (rk ...) () (() ()) () (n . e) bd ...)
(%alambda "rey" () ((h ...) (i ...) (j ... jm jn) (jk ... 'n))
(r ...) (rk ... ((n 'n))) () (() ()) () e bd ...))
;; optional fix arguments
((%alambda "opt" () hijk (r ...) (rk ...)
(o ...) (() ()) () ((n d t ...) . e) bd ...)
(%alambda "opt" () hijk (r ...) (rk ...)
(o ... (n d t ...)) (() ()) () e bd ...))
((%alambda "opt" () hijk (r ...) (rk ...)
(o ...) (() ()) () (n . e) bd ...)
(%alambda "opt" () hijk (r ...) (rk ...)
(o ... (n #f)) (() ()) () e bd ...))
;; optional cat arguments
((%alambda "cat" () hijk (r ...) (rk ...) (o ...)
((c ...) (k ...)) (ok ...) ((n d t ...) . e) bd ...)
(%alambda "cat" () hijk (r ...) (rk ...) (o ...)
((c ... n) (k ...)) (ok ... ((n) d t ...)) e bd ...))
((%alambda "cat" () hijk (r ...) (rk ...) (o ...)
((c ...) (k ...)) (ok ...) (n . e) bd ...)
(%alambda "cat" () hijk (r ...) (rk ...) (o ...)
((c ... n) (k ...)) (ok ... ((n) #f)) e bd ...))
;; optional key arguments
((%alambda "key" () hijk (r ...) (rk ...) (o ...)
((c ...) (k ...)) (ok ...) (((n key) d t ...) . e) bd ...)
(%alambda "key" () hijk (r ...) (rk ...) (o ...)
((c ...) (k ... key)) (ok ... ((n key) d t ...)) e bd ...))
((%alambda "key" () hijk (r ...) (rk ...) (o ...)
((c ...) (k ...)) (ok ...) (((n key)) . e) bd ...)
(%alambda "key" () hijk (r ...) (rk ...) (o ...)
((c ...) (k ... key)) (ok ... ((n key) #f)) e bd ...))
((%alambda "key" () hijk (r ...) (rk ...) (o ...)
((c ...) (k ...)) (ok ...) ((n d t ...) . e) bd ...)
(%alambda "key" () hijk (r ...) (rk ...) (o ...)
((c ...) (k ... 'n)) (ok ... ((n 'n) d t ...)) e bd ...))
((%alambda "key" () hijk (r ...) (rk ...) (o ...)
((c ...) (k ...)) (ok ...) (n . e) bd ...)
(%alambda "key" () hijk (r ...) (rk ...) (o ...)
((c ...) (k ... 'n)) (ok ... ((n 'n) #f)) e bd ...))
;; main
((%alambda check () hijk ((n) ...) () () (() ()) () e bd ...)
(lambda (n ... . e) bd ...))
((%alambda check dft ((h ...) (i ...) (j ...) jk)
((n t ...) ...) (((rn rk ...) rt ...) ...)
() (() ()) () () bd ...)
(lambda (h ... i ... j ...)
(let ((zz (list i ... j ...)))
(let ((n (wow-opt n h t ...)) ...
(rn (wow-req! zz dft jk (rn rk ...) rt ...)) ...)
bd ...))))
((%alambda check dft ((h ...) (i ...) (j ...) jk)
((n t ...) ...) (((rn rk ...) rt ...) ...)
() (() ()) () e bd ...)
(lambda (h ... i ... j ... . te)
(let ((zz (list i ... j ...)))
(let ((n (wow-opt n h t ...)) ...
(rn (wow-req! zz dft jk (rn rk ...) rt ...)) ...
(e te))
bd ...))))
((%alambda check dft ((h ...) () () ()) ((n) ...) ()
(o ...) ((c ...) (k ...)) (ondt ...) e bd ...)
(lambda (h ... . te)
(check-opt te dft ((n h) ...) (o ...) (ondt ...)
e (k ...) bd ...)))
((%alambda check dft ((h ...) (i ...) (j ...) jk)
((n t ...) ...) (((rn rk ...) rt ...) ...)
(o ...) ((c ...) (k ...)) (ondt ...) e bd ...)
(lambda (h ... i ... j ... . te)
(let ((zz (list i ... j ...)))
(check-opt te dft
((n (wow-opt n h t ...)) ...
(rn (wow-req! zz dft jk (rn rk ...) rt ...))
...)
(o ...) (ondt ...) e (k ...) bd ...))))))
(define-syntax alambda*
(syntax-rules (cond)
((alambda* (g . e) b d ...)
(%alambda* "chk" () (() () () ()) () () () (() ()) () (g . e) b d ...))
((alambda* (cond clause cl ...))
(lambda z
(let ((len (length z)))
(check-cond* z len () () clause cl ...))))
((alambda* e b d ...)
(lambda e b d ...))))
(define-syntax %alambda*
(syntax-rules ()
;; "chk"
((%alambda* "chk" () ((h ...) () () ()) (r ...) ()
() (() ()) () ("required cat" . e) bd ...)
(%alambda* "rat" () ((h ...) () () ()) (r ...) () () (() ()) () e bd ...))
((%alambda* "chk" () ((h ...) () () ()) (r ...) ()
() (() ()) () ("required key" . e) bd ...)
(%alambda* "rey" () ((h ...) () () ()) (r ...) () () (() ()) () e bd ...))
((%alambda* "chk" () ((h ...) () () ()) (r ...) ()
() (() ()) () ("opt" . e) bd ...)
(%alambda* "opt" () ((h ...) () () ()) (r ...) () () (() ()) () e bd ...))
((%alambda* "chk" () ((h ...) () () ()) (r ...) ()
() (() ()) () ("cat" . e) bd ...)
(%alambda* "cat" () ((h ...) () () ()) (r ...) () () (() ()) () e bd ...))
((%alambda* "chk" () ((h ...) () () ()) (r ...) ()
() (() ()) () ("key" . e) bd ...)
(%alambda* "key" () ((h ...) () () ()) (r ...) () () (() ()) () e bd ...))
;; "rat"
((%alambda* "rat" () ((h ...) (i in ...) () ()) (r ...) (rk ...)
() (() ()) () ("required key" . e) bd ...)
(%alambda* "rey" () ((h ...) (i in ...) () ()) (r ...) (rk ...)
() (() ()) () e bd ...))
((%alambda* "rat" () ((h ...) (i in ...) (j ...) (jk ...)) (r ...) (rk ...)
() (() ()) () ("opt" . e) bd ...)
(%alambda* "opt" () ((h ...) (i in ...) (j ...) (jk ...)) (r ...) (rk ...)
() (() ()) () e bd ...))
((%alambda* "rat" () ((h ...) (i in ...) (j ...) (jk ...)) (r ...) (rk ...)
() (() ()) () ("cat" . e) bd ...)
(%alambda* "cat" () ((h ...) (i in ...) (j ...) (jk ...)) (r ...) (rk ...)
() (() ()) () e bd ...))
((%alambda* "rat" () ((h ...) (i in ...) (j ...) (jk ...)) (r ...) (rk ...)
() (() ()) () ("key" . e) bd ...)
(%alambda* "key" () ((h ...) (i in ...) (j ...) (jk ...)) (r ...) (rk ...)
() (() ()) () e bd ...))
;; "rey"
((%alambda* "rey" () ((h ...) () (j jn ...) (jk ...)) (r ...) (rk ...)
() (() ()) () ("required cat" . e) bd ...)
(%alambda* "rat" () ((h ...) () (j jn ...) (jk ...)) (r ...) (rk ...)
() (() ()) () e bd ...))
((%alambda* "rey" () ((h ...) (i ...) (j jn ...) (jk ...)) (r ...) (rk ...)
() (() ()) () ("opt" . e) bd ...)
(%alambda* "opt" () ((h ...) (i ...) (j jn ...) (jk ...)) (r ...) (rk ...)
() (() ()) () e bd ...))
((%alambda* "rey" () ((h ...) (i ...) (j jn ...) (jk ...)) (r ...) (rk ...)
() (() ()) () ("cat" . e) bd ...)
(%alambda* "cat" () ((h ...) (i ...) (j jn ...) (jk ...)) (r ...) (rk ...)
() (() ()) () e bd ...))
((%alambda* "rey" () ((h ...) (i ...) (j jn ...) (jk ...)) (r ...) (rk ...)
() (() ()) () ("key" . e) bd ...)
(%alambda* "key" () ((h ...) (i ...) (j jn ...) (jk ...)) (r ...) (rk ...)
() (() ()) () e bd ...))
;; "opt"
((%alambda* "opt" () hijk (r ...) (rk ...)
(o on ...) (() ()) () ("cat" . e) bd ...)
(%alambda* "cat" () hijk (r ...) (rk ...)
(o on ...) (() ()) () e bd ...))
((%alambda* "opt" () hijk (r ...) (rk ...)
(o on ...) (() ()) () ("key" . e) bd ...)
(%alambda* "key" () hijk (r ...) (rk ...)
(o on ...) (() ()) () e bd ...))
;; "cat"
((%alambda* "cat" () hijk (r ...) (rk ...)
(o ...) ((c cn ...) ()) (ok ...) ("key" . e) bd ...)
(%alambda* "key" () hijk (r ...) (rk ...)
(o ...) ((c cn ...) ()) (ok ...) e bd ...))
;; "key"
((%alambda* "key" () hijk (r ...) (rk ...)
(o ...) (() (k kn ...)) (ok ...) ("cat" . e) bd ...)
(%alambda* "cat" () hijk (r ...) (rk ...)
(o ...) (() (k kn ...)) (ok ...) e bd ...))
;; key option
((%alambda* check () ((h ...) (i ...) (j ...) (jk jkn ...)) (r ...)
(rk ...) (o ...) ((c ...) (k ...)) (ok ...) (#t . e) bd ...)
(%alambda* check (#t) ((h ...) (i ...) (j ...) (jk jkn ...)) (r ...)
(rk ...) (o ...) ((c ...) (k ...)) (ok ...) e bd ...))
((%alambda* check () ((h ...) (i ...) (j ...) (jk jkn ...)) (r ...)
(rk ...) (o ...) ((c ...) (k ...)) (ok ...) (#f . e) bd ...)
(%alambda* check (#f) ((h ...) (i ...) (j ...) (jk jkn ...)) (r ...)
(rk ...) (o ...) ((c ...) (k ...)) (ok ...) e bd ...))
((%alambda* check () hijk (r ...) (rk ...)
(o ...) ((c ...) (k kn ...)) (ok ...) (#t . e) bd ...)
(%alambda* check (#t) hijk (r ...) (rk ...)
(o ...) ((c ...) (k kn ...)) (ok ...) e bd ...))
((%alambda* check () hijk (r ...) (rk ...)
(o ...) ((c ...) (k kn ...)) (ok ...) (#f . e) bd ...)
(%alambda* check (#f) hijk (r ...) (rk ...)
(o ...) ((c ...) (k kn ...)) (ok ...) e bd ...))
;; required fix arguments
((%alambda* "chk" () ((h ...) () () ())
(r ...) () () (() ()) () ((n t s ...) . e) bd ...)
(%alambda* "chk" () ((h ... hn) () () ())
(r ... (n t s ...)) () () (() ()) () e bd ...))
((%alambda* "chk" () ((h ...) () () ())
(r ...) () () (() ()) () (n . e) bd ...)
(%alambda* "chk" () ((h ... hn) () () ())
(r ... (n)) () () (() ()) () e bd ...))
;; required cat arguments
((%alambda* "rat" () ((h ...) (i ...) (j ...) (jk ...))
(r ...) (rk ...) () (() ()) () ((n t s ...) . e) bd ...)
(%alambda* "rat" () ((h ...) (i ... in) (j ...) (jk ...))
(r ...) (rk ... ((n) t s ...)) () (() ()) () e bd ...))
((%alambda* "rat" () ((h ...) (i ...) (j ...) (jk ...))
(r ...) (rk ...) () (() ()) () (n . e) bd ...)
(%alambda* "rat" () ((h ...) (i ... in) (j ...) (jk ...))
(r ...) (rk ... ((n))) () (() ()) () e bd ...))
;; required key arguments
((%alambda* "rey" () ((h ...) (i ...) (j ...) (jk ...))
(r ...) (rk ...) () (() ()) () (((n key) t ...) . e) bd ...)
(%alambda* "rey" () ((h ...) (i ...) (j ... jm jn) (jk ... key))
(r ...) (rk ... ((n key) t ...)) () (() ()) () e bd ...))
((%alambda* "rey" () ((h ...) (i ...) (j ...) (jk ...))
(r ...) (rk ...) () (() ()) () ((n t s ...) . e) bd ...)
(%alambda* "rey" () ((h ...) (i ...) (j ... jm jn) (jk ... 'n))
(r ...) (rk ... ((n 'n) t s ...)) () (() ()) () e bd ...))
((%alambda* "rey" () ((h ...) (i ...) (j ...) (jk ...))
(r ...) (rk ...) () (() ()) () (n . e) bd ...)
(%alambda* "rey" () ((h ...) (i ...) (j ... jm jn) (jk ... 'n))
(r ...) (rk ... ((n 'n))) () (() ()) () e bd ...))
;; optional fix arguments
((%alambda* "opt" () hijk (r ...) (rk ...)
(o ...) (() ()) () ((n d t ...) . e) bd ...)
(%alambda* "opt" () hijk (r ...) (rk ...)
(o ... (n d t ...)) (() ()) () e bd ...))
((%alambda* "opt" () hijk (r ...) (rk ...)
(o ...) (() ()) () (n . e) bd ...)
(%alambda* "opt" () hijk (r ...) (rk ...)
(o ... (n #f)) (() ()) () e bd ...))
;; optional cat arguments
((%alambda* "cat" () hijk (r ...) (rk ...) (o ...)
((c ...) (k ...)) (ok ...) ((n d t ...) . e) bd ...)
(%alambda* "cat" () hijk (r ...) (rk ...) (o ...)
((c ... n) (k ...)) (ok ... ((n) d t ...)) e bd ...))
((%alambda* "cat" () hijk (r ...) (rk ...) (o ...)
((c ...) (k ...)) (ok ...) (n . e) bd ...)
(%alambda* "cat" () hijk (r ...) (rk ...) (o ...)
((c ... n) (k ...)) (ok ... ((n) #f)) e bd ...))
;; optional key arguments
((%alambda* "key" () hijk (r ...) (rk ...) (o ...)
((c ...) (k ...)) (ok ...) (((n key) d t ...) . e) bd ...)
(%alambda* "key" () hijk (r ...) (rk ...) (o ...)
((c ...) (k ... key)) (ok ... ((n key) d t ...)) e bd ...))
((%alambda* "key" () hijk (r ...) (rk ...) (o ...)
((c ...) (k ...)) (ok ...) (((n key)) . e) bd ...)
(%alambda* "key" () hijk (r ...) (rk ...) (o ...)
((c ...) (k ... key)) (ok ... ((n key) #f)) e bd ...))
((%alambda* "key" () hijk (r ...) (rk ...) (o ...)
((c ...) (k ...)) (ok ...) ((n d t ...) . e) bd ...)
(%alambda* "key" () hijk (r ...) (rk ...) (o ...)
((c ...) (k ... 'n)) (ok ... ((n 'n) d t ...)) e bd ...))
((%alambda* "key" () hijk (r ...) (rk ...) (o ...)
((c ...) (k ...)) (ok ...) (n . e) bd ...)
(%alambda* "key" () hijk (r ...) (rk ...) (o ...)
((c ...) (k ... 'n)) (ok ... ((n 'n) #f)) e bd ...))
;; main
((%alambda* check () ((h ...) () () ()) ((n) ...) () () (()()) () () bd ...)
(lambda (h ...) (let* ((n h) ...) bd ...)))
((%alambda* check () ((h ...) () () ()) ((n) ...) () () (()()) () e bd ...)
(lambda (h ... . te) (let* ((n h) ... (e te)) bd ...)))
((%alambda* check dft ((h ...) (i ...) (j ...) jk)
((n t ...) ...) (((rn rk ...) rt ...) ...)
() (() ()) () () bd ...)
(lambda (h ... i ... j ...)
(let ((zz (list i ... j ...)))
(let* ((n (wow-opt n h t ...)) ...
(rn (wow-req! zz dft jk (rn rk ...) rt ...)) ...)
bd ...))))
((%alambda* check dft ((h ...) (i ...) (j ...) jk)
((n t ...) ...) (((rn rk ...) rt ...) ...)
() (() ()) () e bd ...)
(lambda (h ... i ... j ... . te)
(let ((zz (list i ... j ...)))
(let* ((n (wow-opt n h t ...)) ...
(rn (wow-req! zz dft jk (rn rk ...) rt ...)) ...
(e te))
bd ...))))
((%alambda* check dft ((h ...) () () ()) ((n) ...) ()
(o ...) ((c ...) (k ...)) (ondt ...) e bd ...)
(lambda (h ... . te)
(let* ((n h) ...)
(check-opt* te dft (o ...) (ondt ...) e (k ...) bd ...))))
((%alambda* check dft ((h ...) (i ...) (j ...) jk)
((n t ...) ...) (((rn rk ...) rt ...) ...)
(o ...) ((c ...) (k ...)) (ondt ...) e bd ...)
(lambda (h ... i ... j ... . te)
(let ((zz (list i ... j ...)))
(let* ((n (wow-opt n h t ...)) ...
(rn (wow-req! zz dft jk (rn rk ...) rt ...)) ...)
(check-opt* te dft (o ...) (ondt ...) e (k ...) bd ...)))))))
(define-syntax check-cond
(syntax-rules ()
((check-cond z len (tt ...) (nt ...) (((n t) . e) bd ...) cl ...)
(check-cond z len (tt ... tn) (nt ... (n t)) (e bd ...) cl ...))
((check-cond z len (tt ...) (nt ...) ((n . e) bd ...) cl ...)
(check-cond z len (tt ... tn) (nt ... (n)) (e bd ...) cl ...))
((check-cond z len () () (() bd ...) cl ...)
(if (= len 0)
((lambda () bd ...))
(check-cond z len () () cl ...)))
((check-cond z len () () (e bd ...) cl ...)
(let ((e z)) bd ...))
((check-cond z len (tt ...) ((n) ...) (() bd ...) cl ...)
(if (= len (length '(tt ...)))
(apply (lambda (n ...) bd ...) z)
(check-cond z len () () cl ...)))
((check-cond z len (tt ...) ((n t ...) ...) (() bd ...) cl ...)
(if (and (= len (length '(tt ...)))
(apply (lambda (tt ...) (cond-and ((n tt t ...) ...))) z))
(apply (lambda (n ...) bd ...) z)
(check-cond z len () () cl ...)))
((check-cond z len (tt ...) ((n) ...) (e bd ...) cl ...)
(if (>= len (length '(tt ...)))
(apply (lambda (n ... . e) bd ...) z)
(check-cond z len () () cl ...)))
((check-cond z len (tt ...) ((n t ...) ...) (e bd ...) cl ...)
(if (and (>= len (length '(tt ...)))
(apply (lambda (tt ...) (cond-and ((n tt t ...) ...))) z))
(apply (lambda (n ... . e) bd ...) z)
(check-cond z len () () cl ...)))
((check-cond z len (tt ...) (nt ...))
(error "actual arguments are not matched to any clause of alambda" z))))
(define-syntax check-cond*
(syntax-rules ()
((check-cond* z len (tt ...) (nt ...) (((n t) . e) bd ...) cl ...)
(check-cond* z len (tt ... tn) (nt ... (n t)) (e bd ...) cl ...))
((check-cond* z len (tt ...) (nt ...) ((n . e) bd ...) cl ...)
(check-cond* z len (tt ... tn) (nt ... (n)) (e bd ...) cl ...))
((check-cond* z len () () (() bd ...) cl ...)
(if (= len 0)
((lambda () bd ...))
(check-cond* z len () () cl ...)))
((check-cond* z len () () (e bd ...) cl ...)
(let ((e z)) bd ...))
((check-cond* z len (tt ...) ((n) ...) (() bd ...) cl ...)
(if (= len (length '(tt ...)))
(apply (lambda (tt ...) (let* ((n tt) ...) bd ...)) z)
(check-cond* z len () () cl ...)))
((check-cond* z len (tt ...) ((n t ...) ...) (() bd ...) cl ...)
(if (and (= len (length '(tt ...)))
(apply (lambda (tt ...) (cond-and* ((n tt t ...) ...))) z))
(apply (lambda (tt ...) (let* ((n tt) ...) bd ...)) z)
(check-cond* z len () () cl ...)))
((check-cond* z len (tt ...) ((n) ...) (e bd ...) cl ...)
(if (>= len (length '(tt ...)))
(apply (lambda (tt ... . te) (let* ((n tt) ... (e te)) bd ...)) z)
(check-cond* z len () () cl ...)))
((check-cond* z len (tt ...) ((n t ...) ...) (e bd ...) cl ...)
(if (and (>= len (length '(tt ...)))
(apply (lambda (tt ...) (cond-and* ((n tt t ...) ...))) z))
(apply (lambda (tt ... . te) (let* ((n tt) ... (e te)) bd ...)) z)
(check-cond* z len () () cl ...)))
((check-cond* z len (tt ...) (nt ...))
(error "actual arguments are not matched to any clause of alambda*" z))))
(define-syntax cond-and
(syntax-rules ()
((cond-and ((n v) nvt ...))
(cond-and (nvt ...)))
((cond-and ((n v t) nvt ...))
(and (let ((n v)) t) (cond-and (nvt ...))))
((cond-and ())
#t)))
(define-syntax cond-and*
(syntax-rules ()
((cond-and* ((n v) nvt ...))
(let ((n v))
(cond-and* (nvt ...))))
((cond-and* ((n v t) nvt ...))
(let ((n v))
(and t (cond-and* (nvt ...)))))
((cond-and* ())
#t)))
(define-syntax check-opt
(syntax-rules ()
((check-opt z dft (nd ...) ((n d t ...) ndt ...) (nodt ...)
e (kk ...) bd ...)
(let ((y (if (null? z) z (cdr z)))
(x (if (null? z)
d
(wow-opt n (car z) t ...))))
(check-opt y dft (nd ... (n x)) (ndt ...) (nodt ...)
e (kk ...) bd ...)))
((check-opt z dft (nd ...) () (((n k) d t ...) nodt ...)
e (kk ...) bd ...)
(let ((x (if (null? z)
d
(wow-key! z dft (kk ...) (n k) d t ...))))
(check-opt z dft (nd ... (n x)) () (nodt ...) e (kk ...) bd ...)))
((check-opt z dft (nd ...) () (((n) d t ...) nodt ...) e (kk ...) bd ...)
(let ((x (if (null? z)
d
(wow-cat! z n d t ...))))
(check-opt z dft (nd ... (n x)) () (nodt ...) e (kk ...) bd ...)))
((check-opt z dft (nd ...) () () () (kk ...) bd ...)
(if (null? z)
(let (nd ...) bd ...)
(error "alambda: too many arguments" z)))
((check-opt z dft (nd ...) () () e (kk ...) bd ...)
(let (nd ... (e z)) bd ...))))
(define-syntax check-opt*
(syntax-rules ()
((check-opt* z dft ((n d t ...) ndt ...) (nodt ...) e (kk ...) bd ...)
(let ((y (if (null? z) z (cdr z)))
(n (if (null? z)
d
(wow-opt n (car z) t ...))))
(check-opt* y dft (ndt ...) (nodt ...) e (kk ...) bd ...)))
((check-opt* z dft () (((n k) d t ...) nodt ...) e (kk ...) bd ...)
(let ((n (if (null? z)
d
(wow-key! z dft (kk ...) (n k) d t ...))))
(check-opt* z dft () (nodt ...) e (kk ...) bd ...)))
((check-opt* z dft () (((n) d t ...) nodt ...) e (kk ...) bd ...)
(let ((n (if (null? z)
d
(wow-cat! z n d t ...))))
(check-opt* z dft () (nodt ...) e (kk ...) bd ...)))
((check-opt* z dft () () () (kk ...) bd ...)
(if (null? z)
(let () bd ...)
(error "alambda*: too many arguments" z)))
((check-opt* z dft () () e (kk ...) bd ...)
(let ((e z)) bd ...))))
(define-syntax wow-opt
(syntax-rules ()
((wow-opt n v)
v)
((wow-opt n v t)
(let ((n v))
(if t n (error "alambda[*]: bad argument" n 'n 't))))
((wow-opt n v t ts)
(let ((n v))
(if t ts (error "alambda[*]: bad argument" n 'n 't))))
((wow-opt n v t ts fs)
(let ((n v))
(if t ts fs)))))
(define-syntax wow-cat!
(syntax-rules ()
((wow-cat! z n d)
(let ((n (car z)))
(set! z (cdr z))
n))
((wow-cat! z n d t)
(let ((n (car z)))
(if t
(begin (set! z (cdr z)) n)
(let lp ((head (list n)) (tail (cdr z)))
(if (null? tail)
d
(let ((n (car tail)))
(if t
(begin (set! z (append (reverse head) (cdr tail))) n)
(lp (cons n head) (cdr tail)))))))))
((wow-cat! z n d t ts)
(let ((n (car z)))
(if t
(begin (set! z (cdr z)) ts)
(let lp ((head (list n)) (tail (cdr z)))
(if (null? tail)
d
(let ((n (car tail)))
(if t
(begin (set! z (append (reverse head) (cdr tail))) ts)
(lp (cons n head) (cdr tail)))))))))
((wow-cat! z n d t ts fs)
(let ((n (car z)))
(if t
(begin (set! z (cdr z)) ts)
(begin (set! z (cdr z)) fs))))))
(define-syntax wow-key!
(syntax-rules ()
((wow-key! z () (kk ...) (n key) d)
(let ((x (car z))
(y (cdr z)))
(if (null? y)
d
(if (equal? key x)
(begin (set! z (cdr y)) (car y))
(let lp ((head (list (car y) x)) (tail (cdr y)))
(if (null? tail)
d
(let ((x (car tail))
(y (cdr tail)))
(if (null? y)
d
(if (equal? key x)
(begin (set! z (append (reverse head) (cdr y)))
(car y))
(lp (cons (car y) (cons x head))
(cdr y)))))))))))
((wow-key! z (#f) (kk ...) (n key) d)
(let ((x (car z))
(y (cdr z)))
(if (null? y)
d
(if (equal? key x)
(begin (set! z (cdr y)) (car y))
(let ((lk (list kk ...)))
(if (not (member x lk))
d
(let lp ((head (list (car y) x)) (tail (cdr y)))
(if (null? tail)
d
(let ((x (car tail))
(y (cdr tail)))
(if (null? y)
d
(if (equal? key x)
(begin (set! z (append (reverse head)
(cdr y)))
(car y))
(if (not (member x lk))
d
(lp (cons (car y) (cons x head))
(cdr y))))))))))))))
((wow-key! z (#t) (kk ...) (n key) d)
(let ((x (car z))
(y (cdr z)))
(if (null? y)
d
(if (equal? key x)
(begin (set! z (cdr y)) (car y))
(let* ((lk (list kk ...))
(m (member x lk)))
(let lp ((head (if m (list (car y) x) (list x)))
(tail (if m (cdr y) y)))
(if (null? tail)
d
(let ((x (car tail))
(y (cdr tail)))
(if (null? y)
d
(if (equal? key x)
(begin (set! z (append (reverse head)
(cdr y)))
(car y))
(let ((m (member x lk)))
(lp (if m
(cons (car y) (cons x head))
(cons x head))
(if m (cdr y) y)))))))))))))
((wow-key! z () (kk ...) (n key) d t)
(let ((x (car z))
(y (cdr z)))
(if (null? y)
d
(if (equal? key x)
(let ((n (car y)))
(if t
(begin (set! z (cdr y)) n)
(error "alambda[*]: bad argument" n 'n 't)))
(let lp ((head (list (car y) x)) (tail (cdr y)))
(if (null? tail)
d
(let ((x (car tail))
(y (cdr tail)))
(if (null? y)
d
(if (equal? key x)
(let ((n (car y)))
(if t
(begin (set! z (append (reverse head)
(cdr y)))
n)
(error "alambda[*]: bad argument"
n 'n 't)))
(lp (cons (car y) (cons x head))
(cdr y)))))))))))
((wow-key! z (#f) (kk ...) (n key) d t)
(let ((x (car z))
(y (cdr z)))
(if (null? y)
d
(if (equal? key x)
(let ((n (car y)))
(if t
(begin (set! z (cdr y)) n)
(error "alambda[*]: bad argument" n 'n 't)))
(let ((lk (list kk ...)))
(if (not (member x lk))
d
(let lp ((head (list (car y) x)) (tail (cdr y)))
(if (null? tail)
d
(let ((x (car tail))
(y (cdr tail)))
(if (null? y)
d
(if (equal? key x)
(let ((n (car y)))
(if t
(begin
(set! z (append (reverse head)
(cdr y)))
n)
(error "alambda[*]: bad argument"
n 'n 't)))
(if (not (member x lk))
d
(lp (cons (car y) (cons x head))
(cdr y))))))))))))))
((wow-key! z (#t) (kk ...) (n key) d t)
(let ((x (car z))
(y (cdr z)))
(if (null? y)
d
(if (equal? key x)
(let ((n (car y)))
(if t
(begin (set! z (cdr y)) n)
(error "alambda[*]: bad argument" n 'n 't)))
(let* ((lk (list kk ...))
(m (member x lk)))
(let lp ((head (if m (list (car y) x) (list x)))
(tail (if m (cdr y) y)))
(if (null? tail)
d
(let ((x (car tail))
(y (cdr tail)))
(if (null? y)
d
(if (equal? key x)
(let ((n (car y)))
(if t
(begin (set! z (append (reverse head)
(cdr y)))
n)
(error "alambda[*]: bad argument"
n 'n 't)))
(let ((m (member x lk)))
(lp (if m
(cons (car y) (cons x head))
(cons x head))
(if m (cdr y) y)))))))))))))
((wow-key! z () (kk ...) (n key) d t ts)
(let ((x (car z))
(y (cdr z)))
(if (null? y)
d
(if (equal? key x)
(let ((n (car y)))
(if t
(begin (set! z (cdr y)) ts)
(error "alambda[*]: bad argument" n 'n 't)))
(let lp ((head (list (car y) x)) (tail (cdr y)))
(if (null? tail)
d
(let ((x (car tail))
(y (cdr tail)))
(if (null? y)
d
(if (equal? key x)
(let ((n (car y)))
(if t
(begin (set! z (append (reverse head)
(cdr y)))
ts)
(error "alambda[*]: bad argument"
n 'n 't)))
(lp (cons (car y) (cons x head))
(cdr y)))))))))))
((wow-key! z (#f) (kk ...) (n key) d t ts)
(let ((x (car z))
(y (cdr z)))
(if (null? y)
d
(if (equal? key x)
(let ((n (car y)))
(if t
(begin (set! z (cdr y)) ts)
(error "alambda[*]: bad argument" n 'n 't)))
(let ((lk (list kk ...)))
(if (not (member x lk))
d
(let lp ((head (list (car y) x)) (tail (cdr y)))
(if (null? tail)
d
(let ((x (car tail))
(y (cdr tail)))
(if (null? y)
d
(if (equal? key x)
(let ((n (car y)))
(if t
(begin
(set! z (append (reverse head)
(cdr y)))
ts)
(error "alambda[*]: bad argument"
n 'n 't)))
(if (not (member x lk))
d
(lp (cons (car y) (cons x head))
(cdr y))))))))))))))
((wow-key! z (#t) (kk ...) (n key) d t ts)
(let ((x (car z))
(y (cdr z)))
(if (null? y)
d
(if (equal? key x)
(let ((n (car y)))
(if t
(begin (set! z (cdr y)) ts)
(error "alambda[*]: bad argument" n 'n 't)))
(let* ((lk (list kk ...))
(m (member x lk)))
(let lp ((head (if m (list (car y) x) (list x)))
(tail (if m (cdr y) y)))
(if (null? tail)
d
(let ((x (car tail))
(y (cdr tail)))
(if (null? y)
d
(if (equal? key x)
(let ((n (car y)))
(if t
(begin (set! z (append (reverse head)
(cdr y)))
ts)
(error "alambda[*]: bad argument"
n 'n 't)))
(let ((m (member x lk)))
(lp (if m
(cons (car y) (cons x head))
(cons x head))
(if m (cdr y) y)))))))))))))
((wow-key! z () (kk ...) (n key) d t ts fs)
(let ((x (car z))
(y (cdr z)))
(if (null? y)
d
(if (equal? key x)
(let ((n (car y)))
(if t
(begin (set! z (cdr y)) ts)
(begin (set! z (cdr y)) fs)))
(let lp ((head (list (car y) x)) (tail (cdr y)))
(if (null? tail)
d
(let ((x (car tail))
(y (cdr tail)))
(if (null? y)
d
(if (equal? key x)
(let ((n (car y)))
(if t
(begin (set! z (append (reverse head)
(cdr y)))
ts)
(begin (set! z (append (reverse head)
(cdr y)))
fs)))
(lp (cons (car y) (cons x head))
(cdr y)))))))))))
((wow-key! z (#f) (kk ...) (n key) d t ts fs)
(let ((x (car z))
(y (cdr z)))
(if (null? y)
d
(if (equal? key x)
(let ((n (car y)))
(if t
(begin (set! z (cdr y)) ts)
(begin (set! z (cdr y)) fs)))
(let ((lk (list kk ...)))
(if (not (member x lk))
d
(let lp ((head (list (car y) x)) (tail (cdr y)))
(if (null? tail)
d
(let ((x (car tail))
(y (cdr tail)))
(if (null? y)
d
(if (equal? key x)
(let ((n (car y)))
(if t
(begin
(set! z (append (reverse head)
(cdr y)))
ts)
(begin
(set! z (append (reverse head)
(cdr y)))
fs)))
(if (not (member x lk))
d
(lp (cons (car y) (cons x head))
(cdr y))))))))))))))
((wow-key! z (#t) (kk ...) (n key) d t ts fs)
(let ((x (car z))
(y (cdr z)))
(if (null? y)
d
(if (equal? key x)
(let ((n (car y)))
(if t
(begin (set! z (cdr y)) ts)
(begin (set! z (cdr y)) fs)))
(let* ((lk (list kk ...))
(m (member x lk)))
(let lp ((head (if m (list (car y) x) (list x)))
(tail (if m (cdr y) y)))
(if (null? tail)
d
(let ((x (car tail))
(y (cdr tail)))
(if (null? y)
d
(if (equal? key x)
(let ((n (car y)))
(if t
(begin (set! z (append (reverse head)
(cdr y)))
ts)
(begin (set! z (append (reverse head)
(cdr y)))
fs)))
(let ((m (member x lk)))
(lp (if m
(cons (car y) (cons x head))
(cons x head))
(if m (cdr y) y)))))))))))))))
(define-syntax wow-req!
(syntax-rules ()
((wow-req! z (ft ...) (kk ...) (n))
(let ((n (car z)))
(set! z (cdr z)) n))
((wow-req! z () (kk ...) (n key))
(let ((x (car z))
(y (cdr z)))
(if (equal? key x)
(begin (set! z (cdr y)) (car y))
(let lp ((head (list (car y) x)) (tail (cdr y)))
(if (null? tail)
(error "alambda[*]: no corresponding value to key"
key (reverse head))
(let ((x (car tail))
(y (cdr tail)))
(if (null? y)
(error "alambda[*]: no corresponding value to key"
key (append (reverse head) tail))
(if (equal? key x)
(begin (set! z (append (reverse head) (cdr y)))
(car y))
(lp (cons (car y) (cons x head)) (cdr y))))))))))
((wow-req! z (#f) (kk ...) (n key))
(let ((x (car z))
(y (cdr z)))
(if (equal? key x)
(begin (set! z (cdr y)) (car y))
(let ((lk (list kk ...)))
(if (not (member x lk))
(error "alambda[*]: no keyword" x lk)
(let lp ((head (list (car y) x)) (tail (cdr y)))
(if (null? tail)
(error "alambda[*]: no corresponding value to key"
key (reverse head))
(let ((x (car tail))
(y (cdr tail)))
(if (null? y)
(error "alambda[*]: no corresponding value to key"
key (append (reverse head) tail))
(if (equal? key x)
(begin
(set! z (append (reverse head) (cdr y)))
(car y))
(if (not (member x lk))
(error "alambda[*]: no keyword" x lk)
(lp (cons (car y) (cons x head))
(cdr y)))))))))))))
((wow-req! z (#t) (kk ...) (n key))
(let ((x (car z))
(y (cdr z)))
(if (equal? key x)
(begin (set! z (cdr y)) (car y))
(let* ((lk (list kk ...))
(m (member x lk)))
(let lp ((head (if m (list (car y) x) (list x)))
(tail (if m (cdr y) y)))
(if (null? tail)
(error "alambda[*]: no corresponding value to key"
key (reverse head))
(let ((x (car tail))
(y (cdr tail)))
(if (null? y)
(error "alambda[*]: no corresponding value to key"
key (append (reverse head) tail))
(if (equal? key x)
(begin (set! z (append (reverse head) (cdr y)))
(car y))
(let ((m (member x lk)))
(lp (if m
(cons (car y) (cons x head))
(cons x head))
(if m (cdr y) y))))))))))))
((wow-req! z (ft ...) (kk ...) (n) t)
(let ((n (car z)))
(if t
(begin (set! z (cdr z)) n)
(let lp ((head (list n)) (tail (cdr z)))
(if (null? tail)
(error "alambda[*]: bad arguments" (reverse head) 'n 't)
(let ((n (car tail)))
(if t
(begin (set! z (append (reverse head) (cdr tail))) n)
(lp (cons n head) (cdr tail)))))))))
((wow-req! z () (kk ...) (n key) t)
(let ((x (car z))
(y (cdr z)))
(if (equal? key x)
(let ((n (car y)))
(if t
(begin (set! z (cdr y)) n)
(error "alambda[*]: bad argument" n 'n 't)))
(let lp ((head (list (car y) x)) (tail (cdr y)))
(if (null? tail)
(error "alambda[*]: no corresponding value to key"
key (reverse head))
(let ((x (car tail))
(y (cdr tail)))
(if (null? y)
(error "alambda[*]: no corresponding value to key"
key (append (reverse head) tail))
(if (equal? key x)
(let ((n (car y)))
(if t
(begin (set! z (append (reverse head)
(cdr y)))
n)
(error "alambda[*]: bad argument" n 'n 't)))
(lp (cons (car y) (cons x head)) (cdr y))))))))))
((wow-req! z (#f) (kk ...) (n key) t)
(let ((x (car z))
(y (cdr z)))
(if (equal? key x)
(let ((n (car y)))
(if t
(begin (set! z (cdr y)) n)
(error "alambda[*]: bad argument" n 'n 't)))
(let ((lk (list kk ...)))
(if (not (member x lk))
(error "alambda[*]: no keyword" x lk)
(let lp ((head (list (car y) x)) (tail (cdr y)))
(if (null? tail)
(error "alambda[*]: no corresponding value to key"
key (reverse head))
(let ((x (car tail))
(y (cdr tail)))
(if (null? y)
(error "alambda[*]: no corresponding value to key"
key (append (reverse head) tail))
(if (equal? key x)
(let ((n (car y)))
(if t
(begin (set! z (append (reverse head)
(cdr y)))
n)
(error "alambda[*]: bad argument"
n 'n 't)))
(if (not (member x lk))
(error "alambda[*]: no keyword" x lk)
(lp (cons (car y) (cons x head))
(cdr y)))))))))))))
((wow-req! z (#t) (kk ...) (n key) t)
(let ((x (car z))
(y (cdr z)))
(if (equal? key x)
(let ((n (car y)))
(if t
(begin (set! z (cdr y)) n)
(error "alambda[*]: bad argument" n 'n 't)))
(let* ((lk (list kk ...))
(m (member x lk)))
(let lp ((head (if m (list (car y) x) (list x)))
(tail (if m (cdr y) y)))
(if (null? tail)
(error "alambda[*]: no corresponding value to key"
key (reverse head))
(let ((x (car tail))
(y (cdr tail)))
(if (null? y)
(error "alambda[*]: no corresponding value to key"
key (append (reverse head) tail))
(if (equal? key x)
(let ((n (car y)))
(if t
(begin (set! z (append (reverse head)
(cdr y)))
n)
(error "alambda[*]: bad argument"
n 'n 't)))
(let ((m (member x lk)))
(lp (if m
(cons (car y) (cons x head))
(cons x head))
(if m (cdr y) y))))))))))))
((wow-req! z (ft ...) (kk ...) (n) t ts)
(let ((n (car z)))
(if t
(begin (set! z (cdr z)) ts)
(let lp ((head (list n)) (tail (cdr z)))
(if (null? tail)
(error "alambda[*]: bad arguments" (reverse head) 'n 't)
(let ((n (car tail)))
(if t
(begin (set! z (append (reverse head) (cdr tail))) ts)
(lp (cons n head) (cdr tail)))))))))
((wow-req! z () (kk ...) (n key) t ts)
(let ((x (car z))
(y (cdr z)))
(if (equal? key x)
(let ((n (car y)))
(if t
(begin (set! z (cdr y)) ts)
(error "alambda[*]: bad argument" n 'n 't)))
(let lp ((head (list (car y) x)) (tail (cdr y)))
(if (null? tail)
(error "alambda[*]: no corresponding value to key"
key (reverse head))
(let ((x (car tail))
(y (cdr tail)))
(if (null? y)
(error "alambda[*]: no corresponding value to key"
key (append (reverse head) tail))
(if (equal? key x)
(let ((n (car y)))
(if t
(begin (set! z (append (reverse head)
(cdr y)))
ts)
(error "alambda[*]: bad argument" n 'n 't)))
(lp (cons (car y) (cons x head)) (cdr y))))))))))
((wow-req! z (#f) (kk ...) (n key) t ts)
(let ((x (car z))
(y (cdr z)))
(if (equal? key x)
(let ((n (car y)))
(if t
(begin (set! z (cdr y)) ts)
(error "alambda[*]: bad argument" n 'n 't)))
(let ((lk (list kk ...)))
(if (not (member x lk))
(error "alambda[*]: no keyword" x lk)
(let lp ((head (list (car y) x)) (tail (cdr y)))
(if (null? tail)
(error "alambda[*]: no corresponding value to key"
key (reverse head))
(let ((x (car tail))
(y (cdr tail)))
(if (null? y)
(error "alambda[*]: no corresponding value to key"
key (append (reverse head) tail))
(if (equal? key x)
(let ((n (car y)))
(if t
(begin (set! z (append (reverse head)
(cdr y)))
ts)
(error "alambda[*]: bad argument"
n 'n 't)))
(if (not (member x lk))
(error "alambda[*]: no keyword" x lk)
(lp (cons (car y) (cons x head))
(cdr y)))))))))))))
((wow-req! z (#t) (kk ...) (n key) t ts)
(let ((x (car z))
(y (cdr z)))
(if (equal? key x)
(let ((n (car y)))
(if t
(begin (set! z (cdr y)) ts)
(error "alambda[*]: bad argument" n 'n 't)))
(let* ((lk (list kk ...))
(m (member x lk)))
(let lp ((head (if m (list (car y) x) (list x)))
(tail (if m (cdr y) y)))
(if (null? tail)
(error "alambda[*]: no corresponding value to key"
key (reverse head))
(let ((x (car tail))
(y (cdr tail)))
(if (null? y)
(error "alambda[*]: no corresponding value to key"
key (append (reverse head) tail))
(if (equal? key x)
(let ((n (car y)))
(if t
(begin (set! z (append (reverse head)
(cdr y)))
ts)
(error "alambda[*]: bad argument"
n 'n 't)))
(let ((m (member x lk)))
(lp (if m
(cons (car y) (cons x head))
(cons x head))
(if m (cdr y) y))))))))))))
((wow-req! z (ft ...) (kk ...) (n) t ts fs)
(let ((n (car z)))
(if t
(begin (set! z (cdr z)) ts)
(begin (set! z (cdr z)) fs))))
((wow-req! z () (kk ...) (n key) t ts fs)
(let ((x (car z))
(y (cdr z)))
(if (equal? key x)
(let ((n (car y)))
(if t
(begin (set! z (cdr y)) ts)
(begin (set! z (cdr y)) fs)))
(let lp ((head (list (car y) x)) (tail (cdr y)))
(if (null? tail)
(error "alambda[*]: no corresponding value to key"
key (reverse head))
(let ((x (car tail))
(y (cdr tail)))
(if (null? y)
(error "alambda[*]: no corresponding value to key"
key (append (reverse head) tail))
(if (equal? key x)
(let ((n (car y)))
(if t
(begin (set! z (append (reverse head)
(cdr y)))
ts)
(begin (set! z (append (reverse head)
(cdr y)))
fs)))
(lp (cons (car y) (cons x head)) (cdr y))))))))))
((wow-req! z (#f) (kk ...) (n key) t ts fs)
(let ((x (car z))
(y (cdr z)))
(if (equal? key x)
(let ((n (car y)))
(if t
(begin (set! z (cdr y)) ts)
(begin (set! z (cdr y)) fs)))
(let ((lk (list kk ...)))
(if (not (member x lk))
(error "alambda[*]: no keyword" x lk)
(let lp ((head (list (car y) x)) (tail (cdr y)))
(if (null? tail)
(error "alambda[*]: no corresponding value to key"
key (reverse head))
(let ((x (car tail))
(y (cdr tail)))
(if (null? y)
(error "alambda[*]: no corresponding value to key"
key (append (reverse head) tail))
(if (equal? key x)
(let ((n (car y)))
(if t
(begin (set! z (append (reverse head)
(cdr y)))
ts)
(begin (set! z (append (reverse head)
(cdr y)))
fs)))
(if (not (member x lk))
(error "alambda[*]: no keyword" x lk)
(lp (cons (car y) (cons x head))
(cdr y)))))))))))))
((wow-req! z (#t) (kk ...) (n key) t ts fs)
(let ((x (car z))
(y (cdr z)))
(if (equal? key x)
(let ((n (car y)))
(if t
(begin (set! z (cdr y)) ts)
(begin (set! z (cdr y)) fs)))
(let* ((lk (list kk ...))
(m (member x lk)))
(let lp ((head (if m (list (car y) x) (list x)))
(tail (if m (cdr y) y)))
(if (null? tail)
(error "alambda[*]: no corresponding value to key"
key (reverse head))
(let ((x (car tail))
(y (cdr tail)))
(if (null? y)
(error "alambda[*]: no corresponding value to key"
key (append (reverse head) tail))
(if (equal? key x)
(let ((n (car y)))
(if t
(begin (set! z (append (reverse head)
(cdr y)))
ts)
(begin (set! z (append (reverse head)
(cdr y)))
fs)))
(let ((m (member x lk)))
(lp (if m
(cons (car y) (cons x head))
(cons x head))
(if m (cdr y) y))))))))))))))
| true |
68def7e30d95c522f308bc7d7ac2661ddafdc6f6
|
12fc725f8273ebfd9ece9ec19af748036823f495
|
/tools/schemelib/wg/node-ctors-4.ss
|
b4a289833062bd1500cca35e32c64e2573c1c598
|
[] |
no_license
|
contextlogger/contextlogger2
|
538e80c120f206553c4c88c5fc51546ae848785e
|
8af400c3da088f25fd1420dd63889aff5feb1102
|
refs/heads/master
| 2020-05-05T05:03:47.896638 | 2011-10-05T23:50:14 | 2011-10-05T23:50:14 | 1,675,623 | 1 | 0 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 1,805 |
ss
|
node-ctors-4.ss
|
#lang scheme/base
;;
;; Copyright 2009 Helsinki Institute for Information Technology (HIIT)
;; and the authors. All rights reserved.
;;
;; Authors: Tero Hasu <[email protected]>
;;
;; Permission is hereby granted, free of charge, to any person
;; obtaining a copy of this software and associated documentation files
;; (the "Software"), to deal in the Software without restriction,
;; including without limitation the rights to use, copy, modify, merge,
;; publish, distribute, sublicense, and/or sell copies of the Software,
;; and to permit persons to whom the Software is furnished to do so,
;; subject to the following conditions:
;;
;; The above copyright notice and this permission notice shall be
;; included in all copies or substantial portions of the Software.
;;
;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
;; EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
;; MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
;; NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
;; BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
;; ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
;; CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
;; SOFTWARE.
;;
(require (lib "usual-4.ss" "common"))
(require* "node-ctors.scm")
(define-syntax sswitch/i
(syntax-rules (case else)
((_)
'nocode)
((_ (else z ...))
(switch-default (block z ...)))
((_ (case x y ...) z ...)
(switch-case x (block y ... (cbreak)) (sswitch/i z ...)))
))
;; An alternative SPECS switch implementation.
;;
;; For some reason this does not work if defined in the mzscheme
;; language.
(define-syntax* sswitch
(syntax-rules ()
((_ ex x ...)
(switch-stmt ex (sswitch/i x ...)))))
| true |
ab29d2c5efedc057f6480bee0914dfd285f58e14
|
92a8acf308f7dfcefa2e3e83b8658b0c305cc374
|
/Assignments/A11.ss
|
2ea822f705cdb03595bc6692cc742dacb6406a56
|
[] |
no_license
|
cbudo/PLC-Assignments
|
0b9ea344e45edae3a55ef4ef318504b97ee4b588
|
91ab84d081ddae5548d72b94768fe72f760e068d
|
refs/heads/master
| 2021-01-25T05:21:57.630870 | 2015-10-13T00:48:04 | 2015-10-13T00:48:04 | 42,824,506 | 0 | 0 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 12,095 |
ss
|
A11.ss
|
; Christopher Budo
; Assignment 11
; October 8, 2015
; starting code
(load "C:/users/budocf/documents/courses/junior/csse304/assignments/chez-init.ss")
; datatypes
(define-datatype bintree bintree?
(leaf-node
(datum number?))
(interior-node
(key symbol?)
(left-tree bintree?)
(right-tree bintree?)))
(define-datatype expression expression?
(var-exp
(id symbol?))
(app-exp
(rator expression?)
(rand (list-of expression?)))
(lit-exp
(id scheme-value?))
(lambda-exp
(id (list-of expression?))
(body (list-of expression?)))
(no-parens-lambda-exp
(id symbol?)
(body (list-of expression?)))
(improper-lambda-exp
(ids expression?)
(body (list-of expression?)))
(let-exp
(ids (list-of expression?))
(values (list-of expression?))
(body (list-of expression?)))
(let*-exp
(ids (list-of expression?))
(values (list-of expression?))
(body (list-of expression?)))
(letrec-exp
(ids (list-of expression?))
(values (list-of expression?))
(body (list-of expression?)))
(named-let-exp
(name expression?)
(ids (list-of expression?))
(values (list-of expression?))
(body (list-of expression?)))
(set!-exp
(id symbol?)
(body expression?))
(if-exp
(test expression?)
(true expression?)
(false expression?))
(no-else-if-exp
(test expression?)
(true expression?)))
(define (scheme-value? val)
#t)
; Problem 1
; Part a
(define-syntax my-let
(syntax-rules ()
[(my-let ((name val) ...) body1 body2 ...)
((lambda (name ...) body1 body2 ...)
val ...)]
[(my-let tag ((name val) ...) body1 body2 ...)
((letrec ((tag (lambda (name ...)
body1 body2 ...)))
tag)
val ...)]))
; Part b
(define-syntax my-or
(syntax-rules ()
[(_) #f]
[(_ e) e]
[(_ e1 e2 ...)
(let [(t e1)]
(if t
t
(my-or e2 ...)))]))
; Part c
(define-syntax +=
(syntax-rules ()
[(+= v e1) (begin (set! v (+ e1 v)) v)]))
; Part d
(define-syntax return-first
(syntax-rules ()
[(_) '()]
[(_ e) e]
[(_ e1 e2 e3 ...)
(let ([a e1])
(begin e2 e3 ... a))]))
; Problem 2
(define (bintree-to-list tree)
(cases bintree tree
[leaf-node (datum)
(list 'leaf-node datum)]
[interior-node (key left right)
(list
'interior-node
key
(bintree-to-list left)
(bintree-to-list right))]))
; Problem 3
(define (max-interior tree)
(car (max-interior-helper tree)))
(define (max-interior-helper tree)
(cases bintree tree
[leaf-node (datum) datum]
[interior-node (key left right)
(let ((l (max-interior-helper left)) (r (max-interior-helper right)))
(cond
[(and (integer? l) (integer? r))
(list key (+ l r) (+ l r))]
[(integer? l)
(let ((rkey (list-ref r 0)) (r1 (list-ref r 1)) (r2 (list-ref r 2)))
(if (> r1 (+ r2 l))
(list rkey r1 (+ r2 l))
(list key (+ r2 l) (+ r2 l))))]
[(integer? r)
(let ((lkey (list-ref l 0)) (l1 (list-ref l 1)) (l2 (list-ref l 2)))
(if (> l1 (+ l2 r))
(list lkey l1 (+ l2 r))
(list key (+ l2 r) (+ l2 r))))]
[else
(let ((curr (+ (list-ref l 2) (list-ref r 2)))
(rkey (list-ref r 0)) (r1 (list-ref r 1))
(lkey (list-ref l 0)) (l1 (list-ref l 1)))
(if (and (>= curr l1) (>= curr r1))
(list key curr curr)
(if (> l1 r1)
(list lkey l1 curr)
(list rkey r1 curr))))]))]))
; Problem 4
; You will want to replace this with your parser that includes more expression types, more options for these types, and error-checking.
; Procedures to make the parser a little bit saner.
(define 1st car)
(define 2nd cadr)
(define 3rd caddr)
(define (parse-exp datum)
(cond
[(symbol? datum) (var-exp datum)]
[(boolean? datum) (lit-exp datum)]
[(string? datum) (lit-exp datum)]
[(vector? datum) (lit-exp datum)]
[(number? datum) (lit-exp datum)]
[(not (proper-list? datum))
(eopl:error 'parse-exp "Error in parse-exp: Improper list in ~s" datum)]
[(pair? datum)
(cond
[(not (proper-list? datum)) (lit-exp datum)]
[(eqv? (car datum) 'quote)
(if (equal? (length datum) 2)
(lit-exp datum)
(eopl:error 'parse-exp "Error in parse-exp: Invalid concrete syntax ~s" datum))]
[(eqv? (car datum) 'lambda)
(if (> (length datum) 2)
(if (symbol? (cadr datum))
(no-parens-lambda-exp (cadr datum) (map parse-exp (cddr datum)))
(if (and (proper-list? (cadr datum))
(and (map symbol? (cadr datum)))
(not (list-contains-multiples? (cadr datum))))
(lambda-exp (map parse-exp (cadr datum)) (map parse-exp (cddr datum)))
(eopl:error 'parse-exp "Error in parse-exp: Invalid concrete syntax ~s" datum)))
(eopl:error 'parse-exp "Error in parse-exp: Incorrect length in ~s" datum))]
[(eqv? (car datum) 'let)
(cond
[(and (> (length datum) 2) (proper-list? (cadr datum))
(and (map proper-list? (cadr datum)))
(and (map (lambda (ls) (equal? (length ls) 2)) (cadr datum)))
(and (map (lambda (ls) (symbol? (car ls))) (cadr datum)))
(not (list-contains-multiples? (map car (cadr datum)))))
(let-exp (map parse-exp (map car (cadr datum))) (map parse-exp (map cadr (cadr datum))) (map parse-exp (cddr datum)))]
[else (eopl:error 'parse-exp "Error in parse-exp: Invalid concrete syntax ~s" datum)])]
[(eqv? (car datum) 'let*)
(if (and (> (length datum) 2) (proper-list? (cadr datum))
(and (map proper-list? (cadr datum)))
(and (map (lambda (ls) (equal? (length ls) 2)) (cadr datum)))
(and (map (lambda (ls) (symbol? (car ls))) (cadr datum)))
(not (list-contains-multiples? (map car (cadr datum)))))
(let*-exp (map parse-exp (map car (cadr datum)))
(map parse-exp (map cadr (cadr datum))) (map parse-exp (cddr datum)))
(eopl:error 'parse-exp "Error in parse-exp: Invalid concrete syntax ~s" datum))]
[(eqv? (car datum) 'letrec)
(if (check-let datum)
(letrec-exp (map parse-exp (map car (cadr datum)))
(map parse-exp (map cadr (cadr datum))) (map parse-exp (cddr datum)))
(eopl:error 'parse-exp "Error in parse-exp: Invalid concrete syntax ~s" datum))]
[(eqv? (car datum) 'set!)
(if (not (equal? (length datum) 3))
(eopl:error 'parse-exp "Error in parse-exp: Incorrect length in ~s" datum)
(set!-exp (cadr datum) (parse-exp (caddr datum))))]
[(eqv? (car datum) 'if)
(if (or (< (length datum) 3) (> (length datum) 4))
(eopl:error 'parse-exp "Error in parse-exp: Incorrect length in ~s" datum)
(if (null? (cdddr datum)) ;w/o else
(no-else-if-exp (parse-exp (cadr datum)) (parse-exp (caddr datum)))
(if-exp (parse-exp (cadr datum)) (parse-exp (caddr datum)) (parse-exp (cadddr datum)))))] ;if w/ else
[else (app-exp (parse-exp (car datum)) (map parse-exp (cdr datum)))])]
[else (eopl:error 'parse-exp "Error in parse-exp: Invalid concrete syntax ~s" datum)]))
(define (check-let datum)
(cond
[(null? (cadr datum))
(eopl:error 'parse-exp "Error in parse-exp: No declarations made in ~s" datum)]
[(null? (cddr datum))
(eopl:error 'parse-exp "Error in parse-exp: Incorrect length in ~s" datum)]
[(null? (caadr datum))
(eopl:error 'parse-exp "Error in parse-exp: No declarations made in ~s" datum)]
[(not (list? (caadr datum)))
(eopl:error 'parse-exp "Error in parse-exp: Invalid concrete syntax, declarations must be lists in ~s" datum)]
[(not (and (map (lambda (ls) (equal? (length ls) 2)) (cadr datum))))
(eopl:error 'parse-exp "Error in parse-exp: not all length 2 in ~s" datum)]
[(not (and (map symbol? (map car (cadr datum)))))
(eop`l:error 'parse-exp "Error in parse-exp: Invalid concrete syntax, declarations must be symbols in ~s" datum)]
[(list-contains-multiples? (map car (cadr datum)))
(eopl:error 'parse-exp "Error in parse-exp: Invalid concrete syntax, declarations must not repeat symbols in ~s" datum)]
[else #t]))
(define (proper-list? x)
(cond
[(null? x) #t]
[(pair? x) (proper-list? (cdr x))]
[else #f]))
(define (list-contains-multiples? ls)
(cond
[(null? ls) #f]
[(member (car ls) (cdr ls)) #t]
[else (list-contains-multiples? (cdr ls))]))
(define (unparse-exp exp)
(cases expression exp
[var-exp (id) id]
[lit-exp (id) id]
[let-exp (ids values body)
(append (list 'let (stitch-let (map unparse-exp ids) (map unparse-exp values))) (map unparse-exp body))]
[named-let-exp (name ids values body)
(append
(list
'let
(unparse-exp name)
(stitch-let (map unparse-exp ids) (map unparse-exp values)))
(map unparse-exp body))]
[let*-exp (ids values body)
(append
(list
'let*
(stitch-let (map unparse-exp ids) (map unparse-exp values)))
(map unparse-exp body))]
[letrec-exp (ids values body)
(append
(list
'letrec
(stitch-let (map unparse-exp ids) (map unparse-exp values)))
(map unparse-exp body))]
[lambda-exp (id body)
(append
(list 'lambda (map unparse-exp id))
(map unparse-exp body))]
[no-parens-lambda-exp (id body)
(append (list 'lambda id)
(map unparse-exp body))]
[improper-lambda-exp (id body)
(append (list 'lambda (unparse-exp id))
(map unparse-exp body))]
[set!-exp (id body)
(list 'set! id (unparse-exp body))]
[if-exp (test true false)
(list 'if (unparse-exp test) (unparse-exp true) (unparse-exp false))]
[no-else-if-exp (test true)
(list 'if (unparse-exp test) (unparse-exp true))]
[app-exp (rator rand)
(append (list (unparse-exp rator)) (map unparse-exp rand))]
[else (eopl:error 'parse-exp "Error in parse-exp: Invalid concrete syntax in ~s" exp)]))
(define (stitch-let ids vals)
(if (null? ids)
'()
(cons
(list (car ids) (car vals))
(stitch-let (cdr ids) (cdr vals)))))
(define (andmap pred? l)
(cond
[(null? l) #t]
[else
(and (pred? (car l))
(andmap pred? (cdr l)))]))
| true |
9f073c157addd539acb89602553c152f3472ef1d
|
37245ece3c767e9434a93a01c2137106e2d58b2a
|
/src/unsyntax/library.sld
|
f4f6437468a97d48eb1f6fcae17a9c7bba41585f
|
[
"MIT"
] |
permissive
|
mnieper/unsyntax
|
7ef93a1fff30f20a2c3341156c719f6313341216
|
144772eeef4a812dd79515b67010d33ad2e7e890
|
refs/heads/master
| 2023-07-22T19:13:48.602312 | 2021-09-01T11:15:54 | 2021-09-01T11:15:54 | 296,947,908 | 12 | 0 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 1,724 |
sld
|
library.sld
|
;; Copyright © Marc Nieper-Wißkirchen (2020).
;; This file is part of Unsyntax.
;; 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 (including the
;; next paragraph) 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.
(define-library (unsyntax library)
(export make-library library?
library-name
library-version
library-visit-requirements
library-invoke-requirements
library-visit-code
library-invoke-code
library-visiter library-set-visiter!
library-invoker library-set-invoker!
library-exports
library-bindings
get-invoke-dependencies)
(import (scheme base)
(srfi 1)
(srfi 125)
(srfi 128))
(include "library.scm"))
| false |
167afe5df961d6adc4b0c11501970d9f2697450e
|
16807220b95bf9a559b97ec0de16665ff31823cb
|
/peacock/peacock-misc.scm
|
f92f27381febd27e40083b701cb866cbc80d998d
|
[
"BSD-3-Clause"
] |
permissive
|
cuauv/software
|
7263df296e01710cb414d340d8807d773c3d8e23
|
5ad4d52d603f81a7f254f365d9b0fe636d03a260
|
refs/heads/master
| 2021-12-22T07:54:02.002091 | 2021-11-18T01:26:12 | 2021-11-18T02:37:55 | 46,245,987 | 76 | 34 | null | 2016-08-03T05:31:00 | 2015-11-16T02:02:36 |
C++
|
UTF-8
|
Scheme
| false | false | 3,628 |
scm
|
peacock-misc.scm
|
; Miscellaneous Peacock Utilities / Functions
(module peacock-misc (
on
vary-get
vary-set
json-read
json-write
rgauss
pos
dump
auvlog
entity-set
)
(import scheme chicken)
(use raisin cuauv-shm (prefix fishbowl bowl:) (prefix random-mtzig rnd:) json nanomsg)
(use extras)
(use ports)
(use srfi-18 srfi-69 srfi-13 srfi-1 posix)
(use matchable)
(import peacock)
(define auvlog-sock (nn-socket 'pub))
(nn-connect auvlog-sock "tcp://127.0.0.1:7654")
(define (auvlog tree msg)
(let ((msg (list->vector `((tree . ,tree) (timestamp . ,(current-seconds)) (message . ,msg) (filename . ,"") (lineno . ,0) (block . ,"") (linetxt . ,"")))))
(nn-send auvlog-sock (call-with-output-string (lambda (port) (json-write msg port))))
)
)
(define (entity-set entity key val) (must (bowl:eset entity key val)))
;; Deferred that becomes determined when the specified reference matches the specified condition, filled with the value of the specified reference at the time of condition fulfillment.
;; Note: SHM variables are consistently named; there should be some way to quote-splice this.
(define (on name name-ref func)
(begin
(define var (new-ivar))
(define (wait-inner)
(>>= (changed name)
(lambda (_)
(let ([current (name-ref)])
(if (func current)
(begin
(ivar-fill! var current)
(return 0))
(wait-inner)
)
)
)
)
)
(begin
(wait-inner)
(ivar-read var)
)
)
)
(define rnd-st (rnd:init))
(define (vary-get name-ref sigma)
(define (get)
(let ((val (name-ref)) (rval (rnd:randn! rnd-st)))
(+ val (* sigma rval))
)
)
(lambda () (get))
)
(define (vary-set name-ref sigma)
(define (set val)
(let ((rval (rnd:randn! rnd-st)))
(name-ref (+ val rval))
)
)
(lambda (val) (set val))
)
(define (rgauss mu sig)
(+ mu (* sig (rnd:randn! rnd-st)))
)
(define-syntax dump
(syntax-rules ()
((_ e e* ...)
(begin
(write (quote e))
(newline)
(display e)
(newline)
(dump e* ...)))
((_)
'())))
(define (lookup k l) (cdr (assoc k l)))
(define locale (lookup "CUAUV_LOCALE" (get-environment-variables)))
(define sw (lookup "CUAUV_SOFTWARE" (get-environment-variables)))
(define lfile (open-input-file (string-append sw (string-append "/conf/" (string-append locale ".json")))))
; https://gist.github.com/dhess/52681
(define (json-read-fixup jro)
(cond ((null? jro) jro)
((vector? jro) (json-read-fixup (vector->list jro)))
((pair? jro) (cons (json-read-fixup (car jro))
(json-read-fixup (cdr jro))))
(else jro)))
(define ldata (lookup "objects" (json-read-fixup (json-read lfile))))
(define (pos obj) (list->vector (take (lookup "initial_position" (car (filter (lambda (v) (string= obj (lookup "name" v))) ldata))) 3)))
(define (rguard name name-ref min-val max-val msg)
(on name name-ref (lambda (val) (or (< val min-val) (> val max-val))) (lambda (_) (fail msg)))
)
(define (guard north-min north-max east-min east-max depth-min depth-max)
(rguard 'kalman.north kalman.north-ref north-min north-max "North out of bounds!")
(rguard 'kalman.east kalman.east-ref east-min east-max "East out of bounds!")
(rguard 'kalman.depth kalman.depth-ref depth-min depth-max "Depth out of bounds!")
)
)
| true |
be040ef92e5bbb3ad2ef15f62ff7d30b6f815293
|
bf1c9803ae38f9aad027fbe4569ccc6f85ba63ab
|
/chapter_2/2.1.Introduction.to.Data.Abstraction/ex_2.2.scm
|
11fe335ae5c6e1bced396fa215c0cd5f336429e2
|
[] |
no_license
|
mehese/sicp
|
7fec8750d3b971dd2383c240798dbed339d0345a
|
611b09280ab2f09cceb2479be98ccc5403428c6c
|
refs/heads/master
| 2021-06-12T04:43:27.049197 | 2021-04-04T22:22:47 | 2021-04-04T22:23:12 | 161,924,666 | 0 | 0 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 1,165 |
scm
|
ex_2.2.scm
|
#lang sicp
(define (make-point x y)
(cons x y))
(define (x-point p)
(car p))
(define (y-point p)
(cdr p))
(define (make-segment p1 p2)
(cons p1 p2))
(define (start-segment segm)
(car segm))
(define (end-segment segm)
(cdr segm))
(define (div-point p constant)
(make-segment (/ (x-point p) constant) (/ (y-point p) constant)))
(define (add-point p1 p2)
(make-segment (+ (x-point p1) (x-point p2)) (+ (y-point p1) (y-point p2))))
(define (midpoint-segment segm)
(div-point (add-point (start-segment segm) (end-segment segm)) 2))
(define (print-point p)
(newline)
(display "(")
(display (x-point p))
(display ",")
(display (y-point p))
(display ")"))
(newline)
(display "Check 1")
(let
((a (make-point 0 0))
(b (make-point 6 4)))
(print-point a)
(print-point b)
(let
((s (make-segment a b)))
(print-point (start-segment s))
(print-point (end-segment s))
(print-point (midpoint-segment s))))
(newline)
(display "Check 2")
(let
((a (make-point 5 5))
(b (make-point 1 1)))
(print-point a)
(print-point b)
(let
((s (make-segment a b)))
(print-point (midpoint-segment s))))
| false |
ce104bff4975133da047a09409183795ce7b6950
|
a09ad3e3cf64bc87282dea3902770afac90568a7
|
/5/4.scm
|
d2acfed8d0c0ed48f667a854bf8223153bbef2d5
|
[] |
no_license
|
lockie/sicp-exercises
|
aae07378034505bf2e825c96c56cf8eb2d8a06ae
|
011b37387fddb02e59e05a70fa3946335a0b5b1d
|
refs/heads/master
| 2021-01-01T10:35:59.759525 | 2018-11-30T09:35:35 | 2018-11-30T09:35:35 | 35,365,351 | 0 | 0 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 723 |
scm
|
4.scm
|
;; a
(controller
(assign continue (label expt-done))
expt-loop
(test (op =) (reg n) (const 0))
(branch (label base-case))
(save continue)
(save n)
(assign n (op -) (reg n) (const 1))
(assign continue (label after-expt))
(goto (label expt-loop))
after-expt
(restore n)
(restore continue)
(assign val (op *) (reg b) (reg val))
(goto (reg continue))
base-case
(assign val (const 1))
(goto (reg continue))
expt-done)
;; b
(controller
(assign counter (reg n))
(assign product (const 1))
expt-iter
(test (op =) (reg counter) (const 0))
(branch (label nonzero))
(assign counter (op -) (reg counter) (const 1))
(assign product (op *) (reg b) (reg product))
(goto (label expt-iter))
nonzero
expt-done)
| false |
b27779e1250a85c330d9aeb464c1264ebd638959
|
120324bbbf63c54de0b7f1ca48d5dcbbc5cfb193
|
/packages/slib/chap.scm
|
dfd3c1f8561f8f2515de690541fbed6eb35316c3
|
[
"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 | 6,163 |
scm
|
chap.scm
|
;;;; "chap.scm" Chapter ordering -*-scheme-*-
;;; Copyright 1992, 1993, 1994, 2003 Aubrey Jaffer
;
;Permission to copy this software, to modify it, to redistribute it,
;to distribute modified versions, and to use it for any purpose is
;granted, subject to the following restrictions and understandings.
;
;1. Any copy made of this software must include this copyright notice
;in full.
;
;2. I have made no warranty or representation that the operation of
;this software will be error-free, and I am under no obligation to
;provide any services, by way of maintenance, update, or otherwise.
;
;3. In conjunction with products arising from the use of this
;material, there shall be no use of my name in any advertising,
;promotional, or sales literature without prior written consent in
;each case.
;;; The CHAP: functions deal with strings which are ordered like
;;; chapters in a book. For instance, a_9 < a_10 and 4c < 4aa. Each
;;; section of the string consists of consecutive numeric or
;;; consecutive aphabetic characters.
(require 'rev4-optional-procedures) ; string-copy
;;@code{(require 'chapter-order)}
;;@ftindex chapter-order
;;
;;The @samp{chap:} functions deal with strings which are ordered like
;;chapter numbers (or letters) in a book. Each section of the string
;;consists of consecutive numeric or consecutive aphabetic characters of
;;like case.
;;@args string1 string2
;;Returns #t if the first non-matching run of alphabetic upper-case or
;;the first non-matching run of alphabetic lower-case or the first
;;non-matching run of numeric characters of @var{string1} is
;;@code{string<?} than the corresponding non-matching run of
;;characters of @var{string2}.
;;
;;@example
;;(chap:string<? "a.9" "a.10") @result{} #t
;;(chap:string<? "4c" "4aa") @result{} #t
;;(chap:string<? "Revised^@{3.99@}" "Revised^@{4@}") @result{} #t
;;@end example
(define (chap:string<? s1 s2)
(let ((l1 (string-length s1))
(l2 (string-length s2)))
(define (match-so-far i ctypep)
(cond ((>= i l1) (not (>= i l2)))
((>= i l2) #f)
(else
(let ((c1 (string-ref s1 i))
(c2 (string-ref s2 i)))
(cond ((char=? c1 c2)
(if (ctypep c1)
(match-so-far (+ 1 i) ctypep)
(delimited i)))
((ctypep c1)
(if (ctypep c2)
(length-race (+ 1 i) ctypep (char<? c1 c2))
#f))
((ctypep c2) #t)
(else
(let ((ctype1 (ctype c1)))
(cond
((and ctype1 (eq? ctype1 (ctype c2)))
(length-race (+ 1 i) ctype1 (char<? c1 c2)))
(else (char<? c1 c2))))))))))
(define (length-race i ctypep def)
(cond ((>= i l1) (if (>= i l2) def #t))
((>= i l2) #f)
(else
(let ((c1 (string-ref s1 i))
(c2 (string-ref s2 i)))
(cond ((ctypep c1)
(if (ctypep c2)
(length-race (+ 1 i) ctypep def)
#f))
((ctypep c2) #t)
(else def))))))
(define (ctype c1)
(cond
((char-numeric? c1) char-numeric?)
((char-lower-case? c1) char-lower-case?)
((char-upper-case? c1) char-upper-case?)
(else #f)))
(define (delimited i)
(cond ((>= i l1) (not (>= i l2)))
((>= i l2) #f)
(else
(let* ((c1 (string-ref s1 i))
(c2 (string-ref s2 i))
(ctype1 (ctype c1)))
(cond ((char=? c1 c2)
(if ctype1 (match-so-far (+ i 1) ctype1)
(delimited (+ i 1))))
((and ctype1 (eq? ctype1 (ctype c2)))
(length-race (+ 1 i) ctype1 (char<? c1 c2)))
(else (char<? c1 c2)))))))
(delimited 0)))
;;@body
;;Implement the corresponding chapter-order predicates.
(define (chap:string>? string1 string2) (chap:string<? string2 string1))
(define (chap:string<=? string1 string2) (not (chap:string<? string2 string1)))
(define (chap:string>=? string1 string2) (not (chap:string<? string1 string2)))
(define chap:char-incr (- (char->integer #\2) (char->integer #\1)))
(define (chap:inc-string s p)
(let ((c (string-ref s p)))
(cond ((char=? c #\z)
(string-set! s p #\a)
(cond ((zero? p) (string-append "a" s))
((char-lower-case? (string-ref s (+ -1 p)))
(chap:inc-string s (+ -1 p)))
(else
(string-append
(substring s 0 p)
"a"
(substring s p (string-length s))))))
((char=? c #\Z)
(string-set! s p #\A)
(cond ((zero? p) (string-append "A" s))
((char-upper-case? (string-ref s (+ -1 p)))
(chap:inc-string s (+ -1 p)))
(else
(string-append
(substring s 0 p)
"A"
(substring s p (string-length s))))))
((char=? c #\9)
(string-set! s p #\0)
(cond ((zero? p) (string-append "1" s))
((char-numeric? (string-ref s (+ -1 p)))
(chap:inc-string s (+ -1 p)))
(else
(string-append
(substring s 0 p)
"1"
(substring s p (string-length s))))))
((or (char-alphabetic? c) (char-numeric? c))
(string-set! s p (integer->char
(+ chap:char-incr
(char->integer (string-ref s p)))))
s)
(else (slib:error "inc-string error" s p)))))
;;@args string
;;Returns the next string in the @emph{chapter order}. If @var{string}
;;has no alphabetic or numeric characters,
;;@code{(string-append @var{string} "0")} is returnd. The argument to
;;chap:next-string will always be @code{chap:string<?} than the result.
;;
;;@example
;;(chap:next-string "a.9") @result{} "a.10"
;;(chap:next-string "4c") @result{} "4d"
;;(chap:next-string "4z") @result{} "4aa"
;;(chap:next-string "Revised^@{4@}") @result{} "Revised^@{5@}"
;;
;;@end example
(define (chap:next-string s)
(do ((i (+ -1 (string-length s)) (+ -1 i)))
((or (negative? i)
(char-numeric? (string-ref s i))
(char-alphabetic? (string-ref s i)))
(if (negative? i) (string-append s "0")
(chap:inc-string (string-copy s) i)))))
;;; testing utilities
;(define (ns s1) (chap:next-string s1))
;(define (ts s1 s2)
; (let ((s< (chap:string<? s1 s2))
; (s> (chap:string<? s2 s1)))
; (cond (s<
; (display s1)
; (display " < ")
; (display s2)
; (newline)))
; (cond (s>
; (display s1)
; (display " > ")
; (display s2)
; (newline)))))
| false |
d9829bf6cf6b0677cab099a0b1dacee95335446b
|
120324bbbf63c54de0b7f1ca48d5dcbbc5cfb193
|
/packages/slib/mulapply.scm
|
6c589594bfe1d6064ad1a4686323f0da54d82509
|
[
"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,056 |
scm
|
mulapply.scm
|
; "mulapply.scm" Redefine APPLY take more than 2 arguments.
;Copyright (C) 1991, 2003 Aubrey Jaffer
;
;Permission to copy this software, to modify it, to redistribute it,
;to distribute modified versions, and to use it for any purpose is
;granted, subject to the following restrictions and understandings.
;
;1. Any copy made of this software must include this copyright notice
;in full.
;
;2. I have made no warranty or representation that the operation of
;this software will be error-free, and I am under no obligation to
;provide any services, by way of maintenance, update, or otherwise.
;
;3. In conjunction with products arising from the use of this
;material, there shall be no use of my name in any advertising,
;promotional, or sales literature without prior written consent in
;each case.
;@
(define apply
(letrec ((apply-2 apply)
(append-to-last
(lambda (lst)
(if (null? (cdr lst))
(car lst)
(cons (car lst) (append-to-last (cdr lst)))))))
(lambda args
(apply-2 (car args) (append-to-last (cdr args))))))
| false |
a83ac23d1766bda1fd4ece53b43ff98a302b4059
|
50158f206d401a6009d4bf13119eb4dda47d762f
|
/disequality-tests.scm
|
a3f7db3315021a5422f4b476950532ec5a8ce0b4
|
[
"MIT"
] |
permissive
|
orchid-hybrid/microKanren
|
150ed4386d8f8698474ea344cba111d66dd6ebe8
|
6788641b9cf37d3fddd0a5789a5d16c6dcaa3ba6
|
refs/heads/master
| 2020-04-05T19:00:16.425059 | 2015-01-23T12:00:39 | 2015-01-23T12:00:39 | 29,727,501 | 0 | 0 | null | 2015-01-23T10:13:10 | 2015-01-23T10:13:10 |
Scheme
|
UTF-8
|
Scheme
| false | false | 1,138 |
scm
|
disequality-tests.scm
|
(define-syntax test-checko
(syntax-rules ()
((_ title tested-expression expected-result)
(begin
(printf "Testing ~s\n" title)
(let* ((expected expected-result)
(produced tested-expression))
(or (equal? expected produced)
(error 'test-check
"Failed: ~a~%Expected: ~a~%Computed: ~a~%"
'tested-expression expected produced)))))))
(define (rembero e l r)
(conde
((== l '()) (== r '()))
((fresh (x xs ys)
(== l `(,x . ,xs))
(== e x)
(== ys r)
(rembero e xs ys)))
((fresh (x xs ys)
(== l `(,x . ,xs))
(=/= e x)
(== `(,x . ,ys) r)
(rembero e xs ys)))))
(test-checko 'xy (run 1 (q) (== q 'x) (=/= q 'y))
'((x (and (or)))))
(test-checko 'xx (run 1 (q) (== q 'x) (=/= q 'x))
'())
(test-checko 'yy (run 1 (q) (=/= q 'y) (== q 'y))
'())
(test-checko 'yx (run 1 (q) (=/= q 'y) (== q 'x))
'((x (and (or)))))
(test-checko 'u-v-different
(run* (q) (fresh (u v) (=/= q `(,u ,v)) (== q `(,v ,u)) (membero u '(x y)) (membero v '(x y))))
'(((y x) (and (or))) ((x y) (and (or)))))
| true |
1b2895b1a3906c9248b18de4bed22b0993ddf0e0
|
025c71211d8c0b4cf40c65d5add4c3d1fe10fa59
|
/mk-misc/smt-evalo.scm
|
3dcb090784bb052c312fa7482d852299a1fda1db
|
[] |
no_license
|
gregr/experiments
|
5ce58d6ac6ae034d3955a96a434272ab3671bf6f
|
a6c5461bda9f8e221225a403f21d61ad4673c57a
|
refs/heads/master
| 2023-08-10T23:48:05.730805 | 2023-08-01T18:58:56 | 2023-08-01T18:58:56 | 4,839,336 | 9 | 2 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 2,852 |
scm
|
smt-evalo.scm
|
(declare-datatypes () ((Symbol quote var lambda pair app)))
(declare-datatypes () ((S null (qint (unqint Int)) (qsym (unqsym Symbol)) (cons (car S) (cdr S)))))
(declare-fun x () S)
;(declare-fun lookupo (S S S) Bool)
;(declare-fun eval-expo (S S S) Bool)
;(define-fun eval-expo ((exp S) (env S) (val S)) Bool
;(ite (and (= exp (cons (qsym quote) (cons (qsym lambda) null)))
;(= val (qsym lambda)))
;true
;(= exp (cons (qsym quote) (cons val null)))))
(define-fun eval-expo ((exp S) (env S) (val S)) Bool
(or (and (= (car exp) (qsym quote))
(= val (car (cdr exp))))
(and (= (car exp) (qsym var))
(let ((name (car (cdr exp))))
(lookupo name env val)))))
(define-fun lookupo ((x S) (env S) (t S)) Bool
(let ((bp (car env)))
(or (and (= x (car bp)) (= t (cdr bp)))
(and (not (= x (car bp))) (lookupo x (cdr env) t)))))
;(assert
;(forall ((exp S) (env S) (val S))
;(iff (or (exists ((v S))
;(and (= exp (cons (qsym quote) (cons v null)))
;(= val v))))
;(eval-expo exp env val))))
(assert
(forall ((exp S) (env S) (val S))
(iff (or (= exp (cons (qsym quote) (cons val null)))
(exists ((name S))
(and (= exp (cons (qsym var) (cons name null)))
(lookupo name env val))))
(eval-expo exp env val))))
(assert
(forall ((x S) (env S) (t S))
(iff (exists ((rest S) (y S) (v S))
(and (= env (cons (cons y v) rest))
(or (and (= y x) (= v t))
(and (not (= y x)) (lookupo x rest t)))))
(lookupo x env t))))
(assert (eval-expo (cons (qsym quote)
(cons (qsym lambda)
null))
null
(qsym x)))
(check-sat)
(get-model)
;(declare-fun x () Int)
;(declare-fun edge (Int Int) Bool)
;(declare-fun path (Int Int) Bool)
;(declare-datatypes ()
;((Symbol quote lambda cons)))
;(declare-datatypes ()
;((S null
;(qint (unqint Int))
;(qsym (unqsym Symbol))
;(cons (car S) (cdr S)))))
;(declare-fun x () Symbol)
;(assert (not (or (= x quote))))
;;(assert (not (or (= x null) (exists ((n Int)) (= x (qint n))))))
;;(declare-datatype S (par () ((null))))
;;(quote (unq Int))
;;(cons (car S) (cdr S))))
;;; edge
;;(assert
;; (forall ((a Int) (b Int))
;; (iff
;; (or
;; (and (= a 1) (= b 2))
;; (and (= a 2) (= b 3))
;; (and (= a 2) (= b 4)))
;; (edge a b))))
;;(assert
;; (forall ((a Int) (b Int))
;; (iff
;; (or
;; (edge a b)
;; (exists ((mid Int))
;; (and (edge a mid) (path mid b))))
;; (path a b))))
;;(assert (path 1 x))
;;(assert (not (or (= x 4) (= x 3) (= x 2))))
;; Solve
;(check-sat)
;(get-model)
| false |
0b6cb282fd034ef7f0e4611b7b63bc9661caa73e
|
defeada37d39bca09ef76f66f38683754c0a6aa0
|
/UnityEngine/unity-engine/avatar-builder.sls
|
59e057f33dfd5658aa01d51b8e0300a6cae51546
|
[] |
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 | 811 |
sls
|
avatar-builder.sls
|
(library (unity-engine avatar-builder)
(export new
is?
avatar-builder?
build-generic-avatar
build-human-avatar)
(import (ironscheme-clr-port))
(define-syntax new
(lambda (e)
(syntax-case e ()
((_ a ...) #'(clr-new UnityEngine.AvatarBuilder a ...)))))
(define (is? a) (clr-is UnityEngine.AvatarBuilder a))
(define (avatar-builder? a) (clr-is UnityEngine.AvatarBuilder a))
(define-method-port
build-generic-avatar
UnityEngine.AvatarBuilder
BuildGenericAvatar
(static: UnityEngine.Avatar UnityEngine.GameObject System.String))
(define-method-port
build-human-avatar
UnityEngine.AvatarBuilder
BuildHumanAvatar
(static:
UnityEngine.Avatar
UnityEngine.GameObject
UnityEngine.HumanDescription)))
| true |
de47b6ec25952a17e6c8aee197698c164a7d6b8a
|
68c4bab1f5d5228078d603066b6c6cea87fdbc7a
|
/lab/frozen/just-born/rifle/src/mzscheme/lab/campeonato-paulista-2008.scm
|
25d72fa340f05ce1f95d901503f6876e554d651d
|
[] |
no_license
|
felipelalli/micaroni
|
afab919dab304e21ba916aa6310dca102b1a04a5
|
741b628754b7c7085d3e68009a621242c2a1534e
|
refs/heads/master
| 2023-08-03T06:25:15.405861 | 2023-07-25T14:44:56 | 2023-07-25T14:44:56 | 537,536 | 2 | 1 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 2,431 |
scm
|
campeonato-paulista-2008.scm
|
(load "../util/quicksort.ss")
; Tipo de retorno:
;(append
; (append (list "Time" PG J V SG GP) ; rodada 1
; (list "Time2" PG J V SG GP))
; (append (list ...)) ; rodada 2
; )
(define rodada
(lambda (numero jogos)
numero))
(define campeonato
(lambda rodadas
rodadas))
(define jogos
(lambda jogos
jogos))
(define-syntax cronometra
(syntax-rules ()
((cronometra oque)
(let
((inicio (current-inexact-milliseconds)))
oque
(- (current-inexact-milliseconds) inicio)))))
; (list (list TIME PG J V SG GP) (list TIME2 PG J V SG GP))
(define jogo
(lambda (time1 gols1 time2 gols2)
(let
((vitoria
(lambda (gols1 gols2)
(if (> gols1 gols2) 1 0)))
(pontos
(lambda (gols1 gols2)
(if (< gols1 gols2) 0 (if (= gols1 gols2) 1 3)))))
(list
(list time1 (pontos gols1 gols2)
1 (vitoria gols1 gols2)
(- gols1 gols2) gols1)
(list time2 (pontos gols2 gols1)
1 (vitoria gols2 gols1)
(- gols2 gols1) gols2)))))
(let
((JUV "Juventus")
(NOR "Noroeste")
(AAPP "Ponte Preta")
(ITU "Ituano")
(RC "Rio Claro")
(PAU "Paulista")
(MIR "Mirassol")
(BAR "Barueri")
(POR "Portuguesa")
(SAN "Santos")
(RP "Rio Preto")
(SC "São Caetano")
(PAL "Palmeiras")
(SER "Sertãozinho")
(GUARA "Guaratinguetá")
(SPFC "São Paulo")
(COR "Corinthians")
(GUARANI "Guarani")
(BRA "Bragantino")
(MAR "Marília"))
(campeonato
(rodada 1
(jogos
(jogo JUV 1 NOR 1)
(jogo AAPP 4 ITU 2)
(jogo RC 2 PAL 0)
(jogo MIR 2 BAR 1)
(jogo POR 2 SAN 0)
(jogo RP 2 SC 2)
(jogo PAL 3 SER 1)
(jogo GUARA 1 SPFC 2)
(jogo COR 3 GUARANI 0)
(jogo BRA 0 MAR 2)))
(rodada 2
(jogos
(jogo BAR 2 RC 0)
(jogo ITU 1 POR 0)
(jogo PAL 1 AAPP 2)
(jogo SER 2 MIR 0)
(jogo SAN 0 PAL 0)
(jogo SPFC 1 RP 0)
(jogo NOR 0 GUARA 1)
(jogo GUARANI 0 BRA 2)
(jogo MAR 4 JUV 0)
(jogo SC 3 COR 1)))
)
)
| true |
f95116bfe47bbaa4b809aab7db377a45269a24fb
|
837a5fb8eb8418ed50448b7cfbc049c807e1266d
|
/r5rs-notes.scm
|
150200ce8b95076f689264cbc72d69f42c5cf780
|
[
"MIT"
] |
permissive
|
reddress/scheme-learning
|
afdcd358304e92ae4908ed752457fb4c3aaf0120
|
beaa20d25196ce3eb756dfb6a61898a96372f895
|
refs/heads/master
| 2016-09-13T12:57:20.854212 | 2016-05-18T19:45:35 | 2016-05-18T19:45:35 | 56,538,721 | 0 | 0 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 2,405 |
scm
|
r5rs-notes.scm
|
#!
3.2. Disjointness of types
No object satisfies more than one of the following:
boolean?
symbol?
char?
vector?
procedure?
pair?
number?
string?
port?
4.1.4. Procedures
lambda may have the following form:
(lambda x x)
x may be any number of arguments. When the procedure is called, the sequence of arguments is converted into a newly allocated list.
4.2.1. Conditionals
cond may have clauses like:
(<test> => <expression>)
where expression is a procedure of one argument. The procedure is called on the value of the test, and the value returned is the value of the cond expression.
!#
(cond ((assv 'b '((a 1) (b 2))) => cadr))
;;; >> 2
#!
4.2.1. Conditionals
(case <key> <clause1> <clause2> ...)
a <clause> is ((<datums> ...) (expressions) ...)
<key> is evaluated and compared against <datum> in the sense of eqv?.
!#
(case (* 2 3)
((2 3 5 7) 'prime)
((1 4 6 8 9) 'composite))
;;; >> composite
#!
4.2.2. Binding constructs
Though there is a restriction on letrec (it must be possible to evaluate each <init> without assigning or referring to the value of any <variable>), in most common uses of letrec, all the <init>s are lambda expressions, and this restriction is automatically satisfied.
4.2.4. Iteration
(do ((<variable1> <init1> <step1>)
...)
(<test> <expression> ...)
<command> ...)
Named let
(let <variable> <bindings> <body>)
<variable> is bound to a procedure whose formal arguments are the bound variables and whose body is <body>
#!
4.2.5. Delayed evaluation
(delay <expression>) is used with force to implement lazy evaluation.
6.1. Equivalence predicates
eqv? returns #t if the two arguments should normally be regarded as the same boolean, symbol, character, or number of the same type. For pairs, vectors, or strings, they must be in the same location in the store.
eq? tests the pointers of the two arguments.
equal? is the least discriminating. It recursively compares the contents of pairs, vectors, and strings. A rule of thumb is that objects are generally equal? if they print the same.
6.3.2. Pairs and lists
(memq obj list), memv, and member use eq?, eqv?, and equal? to test for membership of an object in a list. If it is not found, #f is returned.
(assq obj alist), assv, and assoc returns the first pair in an alist (association list) whose car is the given object.
An alist is a list of pairs '((a 1) (b 2) (c 3)).
!#
| false |
6c97930f3540199f13a8a015eacbd20d016746b4
|
8f1401b60f1a0b73577a80129ec7fe7027a27eba
|
/test/test-maybe.scm
|
2e83c1ae9457d0fc3de8f6e5dd11f6bbaa6920c2
|
[
"Apache-2.0"
] |
permissive
|
bluelight1324/geometric-algebra
|
347409d5ef023ab1109b4d6079ef1e73721ebc0b
|
fdc9332a4f5e2dd526c55bbaa57fd043d78f40d1
|
refs/heads/main
| 2023-04-18T08:41:57.832044 | 2021-05-05T20:08:21 | 2021-05-05T20:08:21 | null | 0 | 0 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 504 |
scm
|
test-maybe.scm
|
(import (rnrs (6))
(monads syntax)
(monads maybe))
(define (div x y)
(if (= 0 y)
*nothing*
(/ x y)))
(define (test-with-maybe)
(define (inc x) (+ 1 x))
(assert (nothing? (maybe-bind (div 1 0) inc)))
(assert (= 3/2 (maybe-bind (div 1 2) inc)))
(assert (= 42 (maybe-return 42))))
(define (test-seq-maybe)
(define (f x)
(seq <maybe>
(a <- (div 1 x))
(b <- (+ a 1))
(maybe-return b)))
(assert (nothing? (f 0)))
(assert (= 4/3 (f 3))))
| false |
744de31b4bea8a3744cc36e754ec0acd533e64f6
|
000dbfe5d1df2f18e29a76ea7e2a9556cff5e866
|
/test/tests/text/json.scm
|
d9144222cef71a618a8f13062d3b0fec75af6577
|
[
"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 | 2,951 |
scm
|
json.scm
|
;; -*- mode:scheme; coding:utf-8; -*-
#!compatible
(import (rnrs)
(text json)
(srfi :26)
(srfi :39)
(srfi :64 testing))
(test-begin "(text json)")
;; call #111
(test-assert "empty" (eof-object? (json-read (open-string-input-port ""))))
(define synopsis-data (string-append (current-directory)
"/test/data/json-synopsis.json"))
(define two-objects-data (string-append (current-directory)
"/test/data/json-two-objects.json"))
(define (parse-json-string str)
(call-with-port
(open-string-input-port str)
(cut json-read <>)))
;; the same as test/tests/json.scm test
;; but returns alist
(parameterize ((*json-map-type* 'alist))
;; basic test
(test-equal "synopsis (read)"
'(("some" . (("partial" . #(42))))
("other" . (("partial" . "a string")))
("more" . (("more" . "stuff"))))
(call-with-input-file synopsis-data
(cut json-read <>)))
(test-equal "synopsis (write)"
"{\"some\": {\"partial\": [42]}, \
\"other\": {\"partial\": \"a string\"}, \
\"more\": {\"more\": \"stuff\"}}"
(call-with-string-output-port
(cut json-write
'(("some" . (("partial" . #(42))))
("other" . (("partial" . "a string")))
("more" . (("more" . "stuff"))))
<>)))
;; test cases are from Gauche
(let ()
(define (t str val)
(test-equal (string-append "primitive " str)
`(("x" . ,val)) (parse-json-string str)))
(t "{\"x\": 100 }" 100)
(t "{\"x\" : -100}" -100)
(t "{\"x\": +100 }" 100)
(t "{\"x\": 12.5} " 12.5)
(t "{\"x\":-12.5}" -12.5)
(t "{\"x\":+12.5}" 12.5)
(t "{\"x\": 1.25e1 }" 12.5)
(t "{\"x\":125e-1}" 12.5)
(t "{\"x\":1250.0e-2}" 12.5)
(t "{\"x\": false }" #f)
(t "{\"x\":true}" #t)
(t "{\"x\":null}" 'null)
(t "{\"x\": \"abc\\\"\\\\\\/\\b\\f\\n\\r\\t\\u0040abc\"}"
"abc\"\\/\x0008;\x000c;\x000a;\x000d;\x0009;@abc")
)
(let ()
(define (t str)
(test-error (string-append "parse error " str)
(parse-json-string str)))
(t "{\"x\": 100")
(t "{x : 100}}"))
(test-equal "parsing an array containing two objects"
'#((("precision" . "zip")
("Latitude" . 37.7668)
("Longitude" . -122.3959)
("Address" . "")
("City" . "SAN FRANCISCO")
("State" . "CA")
("Zip" . "94107")
("Country" . "US"))
(("precision" . "zip")
("Latitude" . 37.371991)
("Longitude" . -122.026020)
("Address" . "")
("City" . "SUNNYVALE")
("State" . "CA")
("Zip" . "94085")
("Country" . "US")))
(call-with-input-file two-objects-data
(cut json-read <>)))
)
;; call #129
(test-error "unexpected EOF in string" (parse-json-string "\"a'"))
(let ((alist-json (parameterize ((*json-map-type* 'alist))
(call-with-input-file synopsis-data json-read)))
(vector-json (call-with-input-file synopsis-data json-read)))
(test-equal alist-json (vector-json->alist-json vector-json))
(test-equal vector-json (alist-json->vector-json alist-json)))
(test-end)
| false |
ac0e5f3ad1c66cdd0692a9ec47fe1a40a3ebf8b1
|
575540faca84ddab9d113bd3b1edc01f901faca0
|
/mllang/mlscheme/lexer.scm
|
9c69439b286b25dd12c85bef4656791e4fba6080
|
[] |
no_license
|
juleari/mlscheme
|
c8327b2b3ad2151bb231baa529a25a711341968b
|
5f0cf5bded95fd63ca38c6a3446ec82b429d5c2b
|
refs/heads/master
| 2020-04-12T06:18:39.190401 | 2020-01-11T16:44:05 | 2020-01-11T16:44:05 | 44,351,323 | 2 | 0 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 11,700 |
scm
|
lexer.scm
|
(define kw '(scheme export mod if zero? eval abs odd? even? div round reverse
null? not sin cos tg ctg eq? eqv? equal? gcd lcm exp expt sqrt memo
last heads take give-first))
(define (trim? s)
(or (eqv? s #\space)
(eqv? s #\newline)
(eqv? s #\tab)))
(define (get-cut-tag word)
(assq word '((#\( tag-lprn)
(#\) tag-rprn)
(#\[ tag-lbrk)
(#\] tag-rbrk)
(#\{ tag-lbrc)
(#\} tag-rbrc)
(#\. tag-dot)
(#\: tag-cln))))
(define (sym-or-new-tag? word)
(assq word '((#\\ tag-lmbd)
(#\< tag-lwr)
(#\% tag-mod)
(#\^ tag-xor)
(#\# tag-diez)
(#\! tag-not))))
(define (sym-old-or-new-tag? word)
(assq word '((#\- ((tag-sym tag-sym)
(tag-lwr tag-to)
(#f tag-mns)))
(#\+ ((tag-sym tag-sym)
(tag-pls tag-conc)
(#f tag-pls)))
(#\* ((tag-sym tag-sym)
(tag-mul tag-pow)
(#f tag-mul)))
(#\t ((tag-sym tag-sym)
(tag-diez tag-true)
(#f tag-sym)))
(#\f ((tag-sym tag-sym)
(tag-diez tag-fls)
(#f tag-sym)))
(#\/ ((tag-sym tag-sym)
(tag-rem tag-div)
(#f tag-rem)))
(#\> ((tag-sym tag-sym)
(tag-mns tag-from)
(#f tag-hghr)))
(#\| ((tag-sym tag-sym)
(tag-bor tag-or)
(#f tag-bor)))
(#\& ((tag-sym tag-sym)
(tag-band tag-and)
(#f tag-band)))
(#\= ((tag-sym tag-sym)
(tag-lwr tag-leq)
(tag-hghr tag-heq)
(tag-not tag-neq)
(#f tag-eq))))))
(define tokenize
(let ((line 1)
(position 1)
(iscomment #f)
(isscheme #f)
(parens 0))
(lambda (word)
(define (isnum? token)
(let ((token-word (string->number (get-token-value token))))
(and token-word
(vector 'tag-num (get-token-coords token) token-word))))
(define (isnumber?)
(let ((token-word (string->number word))
(ws (string->list word))
(coords (vector line position)))
(and (not iscomment)
token-word
;(x-not-in-list #\/ ws)
(++ position (length ws))
(list (vector 'tag-num coords token-word)))))
(define (iskw-part? token)
(define (helper kw w)
(and (not (null? kw))
(or (eq? w (car kw))
(helper (cdr kw) w))))
(let ((word (get-token-value token)))
(and (helper kw (string->symbol word))
(vector 'tag-kw (get-token-coords token) word))))
(define (iskw?)
(define (helper kw w)
(and (not (null? kw))
(or (eq? w (car kw))
(helper (cdr kw) w))))
(let ((coords (vector line position)))
(and (not iscomment)
(helper kw (string->symbol word))
(++ position (length (string->list word)))
(or (not (equal? word "scheme"))
(set! isscheme #t))
(list (vector 'tag-kw coords word)))))
(define (isstring?)
(let* ((coords (vector line position))
(ws (string->list word))
(w (car ws)))
(and (not iscomment)
(equal? w #\")
(++ position (length ws))
(list (vector 'tag-str coords word)))))
(define (tag-sym? s token)
(and (eqv? (get-token-tag token) 'tag-sym)
(helper s token)))
(define (new-tag? s token new-tag)
(and (not (get-token-tag token))
(set-token-tag token new-tag)
(helper s token)))
(define (sym-or-new-tag s token new-tag)
(or (tag-sym? s token)
(new-tag? s token new-tag)))
(define (sym-old-or-new-tag s token old-new-tag)
(or (tag-sym? s token)
(let* ((old-tag (get-token-tag token))
(new-tag-assq (assq old-tag old-new-tag))
(new-tag (and new-tag-assq (cadr new-tag-assq))))
(set-token-tag token new-tag)
(and (eq? new-tag 'tag-true)
(set-token-value token #t))
(and (eq? new-tag 'tag-fls)
(set-token-value token #f))
(helper s token))))
(define (cons-tags tag tag-token token s)
(let* ((tail (helper s token))
(tag-tail (car tail)))
#|(write tail)
(newline)|#
(set-token-tag tag-token tag)
(if (vector? tag-tail)
(if (get-token-tag tag-tail)
(cons tag-token tail)
(list tag-token))
(if tag-tail
(cons tag-token (list tail))
(list tag-token)))))
(define (cut-token-by-word token word)
(define (helper ws counter)
(let ((w (car ws))
(s (cdr ws)))
;(print "a" token "b" (list->string (reverse counter)))
(if (eqv? w word)
(list (vector (get-token-tag token)
(get-token-coords token)
(list->string (reverse counter)))
(vector #f (vector line (- position 1)) word)
(vector #f (vector line position) (list->string s)))
(helper s (cons w counter)))))
(helper (string->list (get-token-value token)) '()))
(define (cut-by-tag w s token cut-tag)
(let* ((old-tag (get-token-tag token))
(cuted-list (cut-token-by-word token w))
(before (car cuted-list))
(center (cadr cuted-list))
(after (caddr cuted-list))
(nafter (isnum? after))
(kwafter (iskw-part? after))
(consed (if (or nafter kwafter)
(list (set-token-tag center cut-tag)
(or nafter kwafter))
(cons-tags cut-tag center after s))))
(if old-tag
(cons (or (isnum? before)
(iskw-part? before)
(set-token-tag before old-tag))
consed)
consed)))
(define (helper ws token)
(if (null? ws)
(list token)
(let* ((w (car ws))
(s (cdr ws))
(sont (sym-or-new-tag? w))
(ssont (sym-old-or-new-tag? w))
(ctag (get-cut-tag w)))
(++ position)
(cond ((eqv? w #\newline) (and (set! iscomment #f)
(set! position 1)
(++ line)
'()))
(iscomment (and (++ position (length s))
'()))
((eqv? w #\tab) (and (++ position TAB1)
'()))
((eqv? w #\space) '())
((eqv? w #\;) (and (set! iscomment #t)
'()))
(isscheme (and (set! isscheme #f)
(set-token-tag token 'tag-schm)
(list token)))
(sont (sym-or-new-tag s
token
(cadr sont)))
(ssont (sym-old-or-new-tag s
token
(cadr ssont)))
(ctag (cut-by-tag w s token (cadr ctag)))
(else (helper s (set-token-tag token
'tag-sym)))))))
(or (iskw?)
(isnumber?)
(isstring?)
(helper (string->list word)
(vector #f (vector line position) word))))))
(define tokenize-file
(let ((is-string #f)
(is-scheme #f)
(parens 0)
(errors '()))
(lambda (file)
(define (add-error error-type)
(set! errors
(cons (vector 'error: error-type)
errors))
'())
(define (print-errors)
(if (null? errors)
(display "LEXER OK!")
(begin (display "LEXER ERRORS:")
(newline)
(apply print (reverse errors))))
(newline)
(newline))
(define (set-string)
(set! is-string #t))
(define (unset-string)
(set! is-string #f))
(define (set-scheme)
(set! is-scheme #t))
(define (unset-scheme)
(set! is-scheme #f))
(define (add-word word words)
(if (null? word)
words
(let ((str-word (list->string (reverse word))))
(and (eq? parens 0)
is-scheme
(unset-scheme))
(and (equal? str-word "scheme")
(set-scheme))
(and is-string
(add-error ERR_STRING_HAS_NO_END))
(cons str-word words))))
(define (read-words word words)
(let ((ch (read-char file)))
(or (and (eof-object? ch)
(add-word word words))
(and (equal? ch #\")
(or (and is-string
(unset-string)
(if is-scheme
(read-words (cons ch word) words)
(read-words '()
(add-word (cons ch word) words))))
(and (set-string)
(read-words (cons ch word) words))))
(and is-string
(read-words (cons ch word) words))
(and is-scheme
(or (and (equal? ch #\()
(++ parens))
(and (equal? ch #\))
(++ parens -1))
#t)
(or (and (eq? parens 0)
(or (not-null? word)
(trim? ch)
(add-error ERR_SCHEME))
(read-words '() (add-word (cons ch word) words)))
(read-words (cons ch word) words)))
(and (trim? ch)
(read-words '() (cons (string ch) (add-word word words))))
(read-words (cons ch word) words))))
(define (tokenize-words words tokens)
(if (null? words)
tokens
(let ((t (tokenize (car words))))
(tokenize-words (cdr words) (append tokens t)))))
(let ((t (tokenize-words (reverse (read-words '() '())) '())))
(and (print-errors) t)))))
| false |
ab752ef44ba6cfa80b277397088cb8fb039856f3
|
b14c18fa7a4067706bd19df10f846fce5a24c169
|
/Chapter3/3.25.scm
|
7ba03f61faa0f0a8793c0034e931e1bac734740c
|
[] |
no_license
|
silvesthu/LearningSICP
|
eceed6267c349ff143506b28cf27c8be07e28ee9
|
b5738f7a22c9e7967a1c8f0b1b9a180210051397
|
refs/heads/master
| 2021-01-17T00:30:29.035210 | 2016-11-29T17:57:16 | 2016-11-29T17:57:16 | 19,287,764 | 3 | 0 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 3,964 |
scm
|
3.25.scm
|
#lang scheme
; something like a directory/file structure...
; It's really astonishing how easily I forget (a, (b, c)) is just same thing as (a, b, c) in pair-world...
(require scheme/mpair)
(define (make-entry name type data)
(mcons (mcons name type) (mcons data '()))
)
(define (name-entry entry) (mcar (mcar entry)))
(define (set!-name-entry entry value) (set-mcar! (mcar entry) value))
(define (type-entry entry) (mcdr (mcar entry)))
(define (set!-type-entry entry value) (set-mcdr! (mcar entry) value))
(define (data-entry entry) (mcar (mcdr entry)))
(define (set!-data-entry entry value) (set-mcar! (mcdr entry) value))
(define (next-entry entry) (mcdr (mcdr entry)))
(define (set!-next-entry entry value) (set-mcdr! (mcdr entry) value))
(define (find-entry name type root)
(if (null? root)
'()
(if (and (eq? (name-entry root) name) (eq? (type-entry root) type))
root
(find-entry name type (next-entry root))
)
)
)
;(define root (make-entry 'root 'root '()))
;(define a (make-entry 'a 'file "a"))
;(define b (make-entry 'b 'file "b"))
;(define c (make-entry 'c 'file "c"))
;(set!-next-entry root a)
;(set!-next-entry a b)
;(set!-next-entry b c)
;(display root) (newline)
;(name-entry root)
;(type-entry root)
;(data-entry root)
;(next-entry root)
;(find-entry 'c 'file root)
(define (make-table)
(let ((local-table (make-entry 'root 'root '())))
; let's make ourselves a struct first
(define (peek)
(display local-table)
)
(define (insert!-dir name subroot)
(if (null? (find-entry name 'dir subroot))
(let (
(next (next-entry subroot))
(new-entry (make-entry name 'dir '()))
(dir-root (make-entry name 'root '()))
)
(set!-data-entry new-entry dir-root)
(set!-next-entry subroot new-entry)
(set!-next-entry new-entry next)
dir-root
)
(data-entry (find-entry name 'dir subroot)) ; find twice...
)
)
(define (insert!-file name value subroot)
;(display "Finding ") (display name) (display " ") (display value) (display " ") (display subroot) (newline)
(if (null? (find-entry name 'file subroot))
(let (
(next (next-entry subroot))
(new-entry (make-entry name 'file value))
)
(set!-next-entry subroot new-entry)
(set!-next-entry new-entry next)
new-entry
)
(error "duplication " name value)
)
)
(define (insert!-inner keys value subroot)
(let (
(key
(if (null? keys)
#f
(mcar keys)))
(keys-left
(if (null? keys)
#f
(mcdr keys)))
)
(if (null? keys-left)
(insert!-file key value subroot)
(insert!-inner (mcdr keys) value (insert!-dir key subroot))
)
)
)
(define (insert! keys value) (insert!-inner keys value local-table))
(define (lookup-inner keys subroot)
;(display "Looking up ") (display keys) (display " ") (display subroot) (newline)
(let (
(key
(if (null? keys)
#f
(mcar keys)))
(keys-left
(if (null? keys)
#f
(mcdr keys)))
)
(if (null? keys-left)
(let ((found (find-entry key 'file subroot)))
(if (null? found)
#f
(data-entry found)
)
)
(let ((found (find-entry key 'dir subroot)))
(if (null? found)
#f
(lookup-inner keys-left (data-entry found))
)
)
)
)
)
(define (lookup keys)
(lookup-inner keys local-table)
)
(define (dispatch m)
(cond
((eq? m 'lookup-proc) lookup)
((eq? m 'insert-proc) insert!)
((eq? m 'peek) peek)
(else (error "unknown command"))
)
)
dispatch
)
)
(define T (make-table))
(define get (T 'lookup-proc))
(define put (T 'insert-proc))
(put (mlist "a" "a" "a") "aaa")
(put (mlist "a" "b" "c" "d") "abcd")
(put (mlist "a" "b" "c" "c") "abcc")
((T 'peek))
(get (mlist "a" "b"))
(get (mlist "a" "a" "a"))
(get (mlist "a" "b" "c" "c"))
(get (mlist "a" "b" "c" "d"))
; ah... totally OOP
| false |
732d505b3487788ca432c15bba5ebe2bf2b27408
|
0bc4163b3571382861380e47eef4aa1afc862024
|
/scheme/fluxcadd-system.scm
|
307f928994dd150cd07688bc95f6d641cdff5902
|
[] |
no_license
|
mjgordon/fluxcadd
|
49f7c633d4430d98cfa0f24485bfc737fac1a321
|
afedf70e8a9b43563bb3fe5fdc2265260f4a981b
|
refs/heads/master
| 2023-07-21T10:19:36.544424 | 2023-07-08T00:19:06 | 2023-07-08T00:19:06 | 84,756,384 | 0 | 0 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 519 |
scm
|
fluxcadd-system.scm
|
;;; Master file for fluxcadd scheme integration
;;; This will change a *lot* over time
(import "geometry.*")
(import "scheme.SchemeEnvironment")
(load "scheme/geometry/curve.scm")
(load "scheme/geometry/point.scm")
;;; Overhead stuff
(define geometry ())
(define (set-geometry geo)
(set! geometry geo))
(define (range end)
(let ((n (- end 1)))
(let loop ((n n) (accumulator '()))
(if (< n 0)
accumulator
(loop (- n 1) (cons n accumulator))))))
(define pi 3.141592654)
| false |
0f2770740881e90d357393aa70c5a7b4e845bb96
|
defeada37d39bca09ef76f66f38683754c0a6aa0
|
/UnityEngine.Networking/unity-engine/networking/network-message-handlers.sls
|
79fa5d435ecfd86b9cf5d6d9608295c045dcddb3
|
[] |
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,342 |
sls
|
network-message-handlers.sls
|
(library (unity-engine networking network-message-handlers)
(export new
is?
network-message-handlers?
unregister-handler
register-handler
get-handlers)
(import (ironscheme-clr-port))
(define-syntax new
(lambda (e)
(syntax-case e ()
((_ a ...)
#'(clr-new
UnityEngine.Networking.NetworkMessageHandlers
a
...)))))
(define (is? a)
(clr-is UnityEngine.Networking.NetworkMessageHandlers a))
(define (network-message-handlers? a)
(clr-is UnityEngine.Networking.NetworkMessageHandlers a))
(define-method-port
unregister-handler
UnityEngine.Networking.NetworkMessageHandlers
UnregisterHandler
(System.Void System.Int16))
(define-method-port
register-handler
UnityEngine.Networking.NetworkMessageHandlers
RegisterHandler
(System.Void
System.Int16
UnityEngine.Networking.NetworkMessageDelegate))
(define-method-port
get-handlers
UnityEngine.Networking.NetworkMessageHandlers
GetHandlers
("System.Collections.Generic.Dictionary`2[[System.Int16, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[UnityEngine.Networking.NetworkMessageDelegate, UnityEngine.Networking, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]")))
| true |
89dd8702d03f8ca510422b825d50b11abc242029
|
b30896ca57a43c4c788dbb89de6ffa32c5d29338
|
/contract-lp.ss
|
23327db2cf69b05c7e45a65a5f5cad4dc7813aa4
|
[
"MIT"
] |
permissive
|
alokthapa/leftparen
|
1820b543fe28a15bd649f228bf8c17d88e5f7f62
|
dd0ac601763bf80ab4e21b4951d152553d26e189
|
refs/heads/master
| 2021-01-09T05:36:02.280732 | 2009-01-12T16:51:04 | 2009-01-12T16:51:04 | 120,912 | 1 | 0 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 252 |
ss
|
contract-lp.ss
|
#lang scheme/base
;; a one-stop require that handles the "any" conflict with PLT contracts and SRFI 1.
(require scheme/contract)
(provide (combine-out (except-out (all-from-out scheme/contract) any)
(rename-out (any c:any))))
| false |
919cad05ed69ac145a1997b122efdc861f0a82aa
|
a178d245493d36d43fdb51eaad2df32df4d1bc8b
|
/GrammarCompiler/common/desugar-directives.ss
|
875cb683e47a37bd5bfb9cfb2b9a6d5570b66078
|
[] |
no_license
|
iomeone/testscheme
|
cfc560f4b3a774064f22dd37ab0735fbfe694e76
|
6ddf5ec8c099fa4776f88a50eda78cd62f3a4e77
|
refs/heads/master
| 2020-12-10T10:52:40.767444 | 2020-01-15T08:40:07 | 2020-01-15T08:40:07 | 233,573,451 | 0 | 0 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 4,801 |
ss
|
desugar-directives.ss
|
(library (GrammarCompiler common desugar-directives)
(export desugar-directives)
(import (chezscheme)
(GrammarCompiler common match)
(GrammarCompiler common aux))
(define desugar-directives
(lambda (x)
(match x
((p423-grammars ,init . ,rest)
(let ((gs (process-rest init rest)))
`(p423-grammars . ,gs))))))
(define process-rest
(lambda (prev gs)
(scan-left increment-grammar prev gs)))
(define increment-grammar
(lambda (prev g)
(define Stage1
(lambda (ds)
(match ds
(() '(() () ()))
(((%remove . ,r*) . ,rest)
(cons (map process-remove r*)
(Stage2 rest)))
(,else (cons '() (Stage2 else))))))
(define Stage2
(lambda (ds)
(match ds
(() '(() ()))
(((%rename . ,r*) . ,rest)
(cons (map process-rename r*)
(Stage3 rest)))
(,else (cons '() (Stage3 else))))))
(define Stage3
(lambda (ds)
(match ds
(() '(()))
(((%add . ,a*))
(list (map process-add a*)))
(,else
(errorf 'increment-grammar "Badly ordered directives: ~a" else)))))
(define process-remove
(lambda (r)
(match r
((,NT . ,sub*) r)
(,NT `(,r)))))
(define process-rename
(lambda (r)
(match r
((,NT1 -> ,NT2) `(,NT1 . ,NT2))
(,else (errorf 'process-rename "bad rename directive: ~a" else)))))
(define process-add
(lambda (a)
(match a
((,NT . ,sub*) a)
(,else
(errorf 'process-add "bad add directive: ~a" else)))))
(let ((name (car g)) (ds (cdr g)))
(let ((ds (Stage1 ds)))
(let ((rem (car ds)) (ren (cadr ds)) (add (caddr ds)))
(match prev
((,old-name (start ,st) . ,[(compose (Remove rem) (Rename ren) (Add add) merge-alists) -> types])
(let ((result `(,name (start ,st) . ,types)))
(pretty-print result)
result))
(,e (errorf 'increment-grammar "invalid: ~a" e))))))))
(define Remove
(lambda (r*)
(lambda (g)
(define Terminals
(lambda (ts)
(if
(null? ts) '()
(let ((t (car ts)))
(cond
((assq (car t) r*) =>
(lambda (p)
(Terminals (cdr ts))))
(else
(cons t (Terminals (cdr ts)))))))))
(define Types
(lambda (ts)
(if
(null? ts) '()
(let ((t (car ts)))
(cond
((assq (car t) r*) =>
(lambda (p)
(let ((type (car p)) (rem-subs (cdr p)))
(cond
((null? rem-subs)
(Types (cdr ts)))
(else
(let ((new-subs
(remp
(lambda (s)
(memq (car s) rem-subs))
(cdr t))))
(cond
((null? new-subs)
(Types (cdr ts)))
(else
(cons
(cons type new-subs)
(Types (cdr ts)))))))))))
(else
(cons t (Types (cdr ts)))))))))
(Types g))))
(define Rename
(lambda (r*)
(lambda (g)
(define Types
(lambda (ts)
(cond
((null? ts) '())
((pair? (car ts))
(cons (Types (car ts))
(Types (cdr ts))))
((assq (car ts) r*) =>
(lambda (p)
(cons (cdr p)
(Types (cdr ts)))))
(else (cons (car ts)
(Types (cdr ts)))))))
(Types g))))
(define Add
(lambda (a*)
(lambda (g)
(append g a*))))
(define scan-left
(lambda (f q ls)
(let ((res (cond
((null? ls) '())
(else
(let ((q (f q (car ls))))
(scan-left f q (cdr ls)))))))
(cons q res))))
(define trans2-map
(lambda (f ls)
(let ((ls (map f ls)))
(map (lambda (ls) (apply append ls))
(list (map car ls) (map cdr ls))))))
(define merge-alists
(lambda (als*)
(if
(null? als*) '()
(let ((first (car als*)) (rest (cdr als*)))
(let-values (((these others)
(partition (lambda (ls) (eq? (car ls) (car first))) rest)))
(cons
(cons (car first)
(apply append (cdr first) (map cdr these)))
(merge-alists others)))))))
)
| false |
8a4d10d8f7ab5685dce47004b5d2c7a39fbab1b5
|
bec9f0c739a30427f472afb90bd667d56b5d8d0c
|
/hw/3.ss
|
815f2581a560ef853864f9fef30d8bda15aada4c
|
[] |
no_license
|
compuwizard123/CSSE304
|
d599c820f26476bcda7805a96191ea3b6dc8bf07
|
2a7bf7f080f99edc837e5193ce2abdb544cfa24d
|
refs/heads/master
| 2021-01-16T01:08:06.305879 | 2011-05-05T02:15:46 | 2011-05-05T02:15:46 | 615,614 | 0 | 2 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 2,075 |
ss
|
3.ss
|
; Kevin Risden
; Assignment 3
;
; #1
(define curry2
(lambda (f)
(lambda (n)
(lambda (x)
(f n x)))))
; #2
(define curried-compose
(lambda (f)
(lambda (g)
(lambda (x)
(f (g x))))))
; #3
(define compose
(lambda list-of-functions
(if (null? (cdr list-of-functions))
(car list-of-functions)
(lambda (x) ((car list-of-functions) ((apply compose (cdr list-of-functions)) x))))))
; #4
(define make-list
(lambda (n x)
(if (= n 0)
'()
(cons x (make-list (- n 1) x)))))
(define make-list-c
(lambda (n)
(lambda (x)
(make-list n x))))
; #5
(define matrix-ref
(lambda (m row col)
(list-ref (list-ref m row) col)))
; #6
(define max-edges
(lambda (n)
(/ (* (- n 1) n) 2)))
; #7
(define checkEdges?
(lambda (x ls)
(if (null? ls)
#f
(or (equal? x (car ls)) (checkEdges? x (cdr ls))))))
(define checkList?
(lambda (x ls)
(if (null? ls)
#t
(if (equal? x (caar ls))
(checkList? x (cdr ls))
(and (checkEdges? x (cadar ls)) (checkList? x (cdr ls)))))))
(define checkPoints?
(lambda (points ls)
(if (null? points)
#t
(and (checkList? (car points) ls) (checkPoints? (cdr points) ls)))))
(define complete?
(lambda (ls)
(let ([points (map car ls)])
(if (<= (length points) 1)
#t
(checkPoints? points ls)))))
; #8
(define getCon
(lambda (x ls)
(if (null? ls)
'()
(if (equal? x (car ls))
(getCon x (cdr ls))
(cons (car ls) (getCon x (cdr ls)))))))
(define makeComplete
(lambda (points ls)
(if (null? points)
'()
(cons (list (car points) (getCon (car points) ls)) (makeComplete (cdr points) ls)))))
(define complete
(lambda (ls)
(if (null? ls)
'()
(makeComplete ls ls))))
; #9
(define fact
(lambda (n)
(if (eq? n 0)
1
(* n (fact (- n 1))))))
(define binomial
(lambda (n k)
(/ (fact n) (* (fact k) (fact (- n k))))))
(define create-row
(lambda (n k)
(if (eq? n k)
'(1)
(cons (binomial n k) (create-row n (+ k 1))))))
(define pascal-triangle
(lambda (n)
(if (<= n -1)
'()
(cons (create-row n 0) (pascal-triangle (- n 1))))))
| false |
85c4fc04986407b864b654eb200d1c698e73652f
|
dfa6286dd152d5eb501b020120fda480a6896149
|
/assignment/13.ss
|
095a20621362516fc2ae5ece01eea2f2acbd897f
|
[] |
no_license
|
ruoqlng/PLC---Scheme
|
7f3cd85a7bf7e76d97fdf2379ad777aefca1b440
|
fd4caeb7283a34327a37c42e8d9b4ad3b4f65bc2
|
refs/heads/main
| 2023-01-20T11:35:50.101719 | 2020-11-20T03:27:08 | 2020-11-20T03:27:08 | 314,433,879 | 0 | 1 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 6,756 |
ss
|
13.ss
|
;(load "chez-init.ss") ; put this file in the same folder, or add a pathname
; This is a parser for simple Scheme expressions,
; such as those in EOPL, 3.1 thru 3.3.
; You will want to replace this with your parser that includes more expression types, more options for these types, and error-checking.
(define-datatype expression expression?
[var-exp
(id symbol?)]
[lit-exp
(datum lit?)]
[lambda-exp
(id (list-of symbol?))
(body (list-of expression?))]
[lambdai-exp
(id symbol?)
(body (list-of expression?))]
[app-exp
(rator expression?)
(rand (list-of expression?))]
[if-else-exp
(bool expression?)
(true expression?)
(false expression?)]
[if-exp
(bool expression?)
(true expression?)]
[set!-exp
(id symbol?)
(var expression?)]
[let-exp
(var (list-of (list-of expression?)))
(body (list-of expression?))]
[letrec-exp
(var (list-of (list-of expression?)))
(body (list-of expression?))]
[let*-exp
(var (list-of (list-of expression?)))
(body (list-of expression?))]
)
; Procedures to make the parser a little bit saner.
(define 1st car)
(define 2nd cadr)
(define 3rd caddr)
(define lit? ;;define literate type
(lambda (exp)
(or (number? exp)
(string? exp)
(char? exp)
(vector? exp)
(eq? (car exp) 'quote)
(symbol? exp)
(eq? #t exp)
(eq? #f exp))))
(define list-of-symbols?
(lambda (lst)
(if (list? lst)
(andmap symbol? lst)
#f)))
(define parse-exp
(lambda (datum)
(cond
[(and (pair? datum) (not (list? datum)))
(eopl:error 'parse-exp "Datum not a proper list!")]
[(symbol? datum) (var-exp datum)]
[(lit? datum) (lit-exp datum)]
[(string? datum) (lit-exp datum)]
[(pair? datum)
(cond
[(eqv? (1st datum) 'lambda)
(cond
[(null? (cddr datum)) (eopl:error 'parse-exp "Error 0:incorrect length in Lambda ~a" datum)]
[(symbol? (2nd datum)) (lambdai-exp (2nd datum) (map parse-exp (cddr datum)))]
[else
(cond
[(list-of-symbols? (2nd datum))
(lambda-exp
(2nd datum)
(map parse-exp (cddr datum)))]
[(not (list (2nd datum)));;error case
(eopl:error 'parse-exp "Error 1: Seems not a list structure at parsing lambda : ~a" (cadr datum))]
[else (eopl:error 'parse-exp "Error2: Seems not a symbol in lambda,cannot parse: ~a" (cadr datum))]
)])]
[(eqv? (car datum) 'set!)
(if (equal? 3 (length datum))
(set-exp (2nd datum) (parse-exp (3rd datum)))
(eopl:error 'parse-exp "set! expression ~s does not have the required pair of variable and expression" datum))]
[(eqv? (1st datum) 'let)
(cond
[(or (null? (cdr datum)) (null? (cddr datum))) (eopl:error 'parse-exp "The length of the let expression ~s is incorrect." datum)]
[(not (list? (2nd datum))) (eopl:error 'parse-exp "let expression not a list" datum)]
[(not (andmap symbol? (map car (2nd datum)))) (eopl:error 'parse-exp "let expression declarations not a list of symbols" datum)]
[(not (andmap list? (2nd datum))) (eopl:error 'parse-exp "let expression declarations not a proper list" datum)]
[(not (andmap (lambda (a) (equal? (length a) 2)) (2nd datum))) (eopl:error 'parse-exp "let expression declarations not a list of 2" datum)]
[else (let-exp
(map list (map var-exp (map car (2nd datum))) (map parse-exp (map 2nd (2nd datum))))
(map parse-exp (cddr datum)))])]
[(eqv? (1st datum) 'let*)
(cond
[(or (null? (cdr datum)) (null? (cddr datum)))
(eopl:error 'parse-exp "The length of the let* expression ~s is incorrect." datum)]
[(not (list? (2nd datum))) (eopl:error 'parse-exp "let* expression not a list" datum)]
[(not (andmap symbol? (map car (2nd datum)))) (eopl:error 'parse-exp "let* expression declarations not a list of symbols" datum)]
[(not (andmap list? (2nd datum))) (eopl:error 'parse-exp "let* expression declarations not a proper list" datum)]
[(not (andmap (lambda (a) (equal? (length a) 2)) (2nd datum))) (eopl:error 'parse-exp "let* expression declarations not a list of 2" datum)]
[else (let*-exp
(map list (map var-exp (map car (2nd datum))) (map parse-exp (map 2nd (2nd datum))))
(map parse-exp (cddr datum)))])]
[(eqv? (1st datum) 'letrec)
(cond
[(< (length datum) 3)
(eopl:error 'parse-exp "incorrect length: ~s" datum)]
[(or (not (list? (2nd datum))) (not (andmap list? (2nd datum))))
(eopl:error 'parse-exp "not a proper list: ~s" (2nd datum))]
[(not (andmap (lambda (x) (= 2 (length x))) (2nd datum)))
(eopl:error 'parse-exp "not length 2: ~s" (2nd datum))]
[(not (andmap symbol? (map 1st (2nd datum))))
(eopl:error 'parse-exp "first members must be symbols: ~s" datum)]
[else
(letrec-exp (map list (map parse-exp (map car (2nd datum))) (map parse-exp (map 2nd (2nd datum)))) (map parse-exp (cddr datum)))])]
[(eqv? (1st datum) 'if)
(cond
[(= 3 (length datum))
(if-exp (parse-exp (2nd datum)) (parse-exp (3rd datum)))]
[(= 2 (length datum))
(eopl:error 'parse-exp "missing then or else clauses: ~s" datum)]
[(> (length datum) 4)
(eopl:error 'parse-exp "too many parts: ~s" datum)]
[else
(if-else-exp (parse-exp (2nd datum))
(parse-exp (3rd datum))
(parse-exp (cadddr datum)))])]
[else (app-exp (parse-exp (1st datum))
(map parse-exp (cdr datum)))])]
[else (eopl:error 'parse-exp "bad expression: ~s" datum)]
)))
; An auxiliary procedure that could be helpful.
(define var-exp?
(lambda (x)
(cases expression x
[var-exp (id) #t]
[else #f])))
(define (unparse-exp datum)
(cases expression datum
[var-exp (id) id]
[lit-exp (datum) datum]
[lambda-exp (id body)
(cons 'lambda
(cons id
(map unparse-exp body)))]
[lambdai-exp (id body)
(cons 'lambda
(cons id
(map unparse-exp body)))]
[if-else-exp (bool true false)
(list 'if
(unparse-exp bool)
(unparse-exp true)
(unparse-exp false))]
[if-exp (bool true)
(list 'if
(unparse-exp bool)
(unparse-exp true))]
[set!-exp (id var)
(cons 'set!
(cons id
(unparse-exp var)))]
[app-exp (rator rand)
(cons (unparse-exp rator)
(map unparse-exp rand))]
[let-exp (var body)
(cons
'let
(cons (map
(lambda (x)
(map unparse-exp x))
var)
(map unparse-exp body)))]
[let*-exp (var body )
(cons
'let*
(cons(map
(lambda (x)
(map unparse-exp x))
var)
(map unparse-exp body)))]
[letrec-exp (var body)
(cons
'letrec
(cons (map
(lambda (x)
(map unparse-exp x))
var)
(map unparse-exp body)))]))
| false |
79ef4f1eb44897f63d932c9c3cfe831b16641bae
|
120324bbbf63c54de0b7f1ca48d5dcbbc5cfb193
|
/packages/slib/dbinterp.scm
|
3444fbb0fe6afa2e5546307fb8f1dd193e9c20fe
|
[
"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,769 |
scm
|
dbinterp.scm
|
;;; "dbinterp.scm" Interpolate function from database table.
;Copyright 2003 Aubrey Jaffer
;
;Permission to copy this software, to modify it, to redistribute it,
;to distribute modified versions, and to use it for any purpose is
;granted, subject to the following restrictions and understandings.
;
;1. Any copy made of this software must include this copyright notice
;in full.
;
;2. I have made no warranty or representation that the operation of
;this software will be error-free, and I am under no obligation to
;provide any services, by way of maintenance, update, or otherwise.
;
;3. In conjunction with products arising from the use of this
;material, there shall be no use of my name in any advertising,
;promotional, or sales literature without prior written consent in
;each case.
;;; The procedures returned by MEMOIZE are not reentrant!
(define (dbinterp:memoize proc k)
(define recent (vector->list (make-vector k '(#f))))
(let ((tailr (last-pair recent)))
(lambda args
(define asp (assoc args recent))
(if asp
(cdr asp)
(let ((val (apply proc args)))
(set-cdr! tailr (list (cons args val)))
(set! tailr (cdr tailr))
(set! recent (cdr recent))
val)))))
;;@ This procedure works only for tables with a single primary key.
(define (interpolate-from-table table column)
(define get (table 'get column))
(define prev (table 'isam-prev))
(define next (table 'isam-next))
(dbinterp:memoize
(lambda (x)
(let ((nxt (next x)))
(if nxt (set! nxt (car nxt)))
(let ((prv (prev (or nxt x))))
(if prv (set! prv (car prv)))
(cond ((not nxt) (get prv))
((not prv) (get nxt))
(else (/ (+ (* (- x prv) (get nxt))
(* (- nxt x) (get prv)))
(- nxt prv)))))))
3))
| false |
7e3205184b6e256d1ac608b9f8830e7f9baa88ec
|
b2e11f6584aedd973c62a07ad12b7fad65a90cd5
|
/2.25.scm
|
9e34b356c3f11e079264aaac37bd626348d3223b
|
[] |
no_license
|
hoenigmann/sicp
|
355cca95c6f50caeb2896b2a276c9248a40e9f8b
|
cdccea510da569d7aa4272d6da11ddacd32edb14
|
refs/heads/master
| 2021-01-18T16:28:11.827549 | 2018-06-12T14:42:57 | 2018-06-12T14:42:57 | 2,852,716 | 1 | 0 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 273 |
scm
|
2.25.scm
|
;;; 2.25 Exercise
(define list225 (list 1 3 (list 5 7) 9))
(car (cdr (car (cdr (cdr list225)))))
(define list225listoflist (list (list 7)))
(car (car list225listoflist))
(define list225lists (list 2 (list 3 (list 4 (list (list 6 7))))))
(car (cdaadr (cadadr list225lists)))
| false |
eee7af29853d8de82f6895be5b6b04c8d546fb65
|
4da2fdf33d85021ce3c5aa459ccc998cc3a6b95d
|
/c41-tests.scm
|
c0c404d1edaa137ac982d9c4e09a2912b79075d7
|
[] |
no_license
|
pzel/sicp
|
7bdd9e5fa8648eff8fabdc80aad4df67d2c12618
|
99bace346cc1224724fe715644704f8889b2f6a9
|
refs/heads/master
| 2022-08-30T21:02:26.948669 | 2016-05-28T17:40:05 | 2016-05-28T17:40:05 | 7,996,775 | 0 | 1 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 15,967 |
scm
|
c41-tests.scm
|
(load "./c41.scm")
(load "./c41-4.2b.scm") ;; Ex. 4.2b: Louis Reasoner's LISP-2-ish evaluator
(load "./test.scm")
; helper method
(define (%eval/env exp) (%eval exp %base-env))
(run-tests
'(
;; Unit tests
;; Data predicates
(=? '(quoted? '(quote hello)) 'quote)
(=? '(self-evaluating? 3) 'self-evaluating)
(=? '(self-evaluating? "hello") 'self-evaluating)
(=? '(self-evaluating? '(1 23)) #f)
(=? '(tagged-list? '() 'tag) #f)
(=? '(tagged-list? '(vv) 'vv) 'vv)
(=? '(tagged-list? '(yy 1 2 3) 'yy) 'yy)
(=? '(variable? 'x) 'variable)
(=? '(variable? 2) #f)
;; Definitions
(=? '(definition? '(define x 1)) 'define)
(=? '(definition? '(define (f x) x)) 'define)
(=? '(definition-variable '(define x 1)) 'x)
(=? '(definition-variable '(define (f y) y)) 'f)
(=? '(definition-value '(define x 0)) '0)
(=? '(definition-value '(define (h x) x)) '(lambda (x) x))
;; Assignment
(=? '(assignment? '(set! x 2)) 'set!)
;; Lambdas
(=? '(lambda? '(hello world)) #f)
(=? '(lambda? '(lambda (x) x)) 'lambda)
(=? '(lambda-parameters '(lambda (x y) 2)) '(x y))
(=? '(lambda-body '(lambda (x y) x)) '(x))
(=? '(lambda-body '(lambda (x y) (f x y))) '((f x y)))
(=? '(make-lambda '(x y) '((+ x y))) '(lambda (x y) (+ x y)))
;; ;; Procedures
(=? '(make-procedure '(a b) '((f a b)) %base-env)
`(procedure (a b) ((f a b)) ,%base-env))
(=? '(procedure-parameters (make-procedure '(a b) '((f a b)) %base-env))
'(a b))
(=? '(procedure-body (make-procedure '(a b) '((f a b)) %base-env))
'((f a b)))
(=? '(procedure-environment (make-procedure '(a b) '((f a b)) %base-env))
%base-env)
;; Environments -- see Ex. 4.11
(=? '%null-env '())
;; Lookups
(=? '(lookup-variable-value 'test (extend-environment '(test) '(0) %null-env))
0)
(=?e '(lookup-variable-value 'not-here (extend-environment '(test) '(0) %null-env))
"Undefined variable: ")
;; Ex. 4.16 a
(=?e '(lookup-variable-value 'test (extend-environment '(test) '(%unassigned) %null-env))
"Undefined variable: ")
;; Quotes
(=? '(text-of-quotation '(quote t1)) 't1)
;; Assignment
(=? '(assignment? '(set x 3)) #f)
(=? '(assignment? '(set! x 3)) 'set!)
(=? '(assignment-variable '(set! y 55)) 'y)
(=? '(assignment-value '(set! y 55)) 55)
;; Ifs
(=? '(if? '(if a b c)) 'if)
(=? '(if? '(fi a b c)) #f)
(=? '(if-predicate '(if a b c)) 'a)
(=? '(if-consequent '(if a b c)) 'b)
(=? '(if-alternative '(if a b c)) 'c)
(=? '(if-alternative '(if a b)) %f)
(=? '(make-if 'a 'b 'c) '(if a b c))
;; Conditional expressions
(=? '(cond? '(cond (a 1) (b 2))) 'cond)
(=? '(cond-clauses '(cond (a 1) (b 2))) '((a 1) (b 2)))
(=? '(cond-clauses '(cond (else 0))) '((else 0)))
(=? '(cond-predicate '(a 1)) 'a)
(=? '(cond-actions '(a 1)) '(1))
(=? '(cond-else-clause? '(else whatever)) #t)
(=? '(cond->if '(cond (else 2))) '2)
(=? '(cond->if '(cond (a 1) (else 2))) '(if a 1 2))
(=? '(cond->if '(cond (a 1))) '(if a 1 %f))
(=? '(cond->if '(cond (a 1) (b 2) (else 3))) '(if a 1 (if b 2 3)))
(=? '(cond->if '(cond (a 1) (b 2) (else 3))) '(if a 1 (if b 2 3)))
(=?e '(cond->if '(cond (a 1) (else 3) (b 2))) "ELSE is not last")
;; Sequences
(=? '(sequence->exp '(1)) '1)
(=? '(sequence->exp '(1 1)) '(begin 1 1))
;; Bools
(=? '(true? %t) #t)
(=? '(true? %f) #f)
(=? '(false? %f) #t)
(=? '(false? %t) #f)
;; Application/Evaluation
(=? '(application? '((lambda(x) x) 3)) 'application)
(=? '(application? '(+ 3 4)) 'application)
(=? '(operator '(+ 1 2)) '+)
(=? '(operands '(+ 1 2)) '(1 2))
(=? '(no-operands? '()) #t)
(=? '(no-operands? '(1 2)) #f)
(=? '(first-operand '(1 2)) 1)
(=? '(rest-operands '(1 2)) '(2))
(=? '(list-of-values '(x y z) (extend-environment '(x y z) '(1 2 3) %base-env))
'(1 2 3))
;; High-level Evaluation -- “acceptance” tests
(=? '(%eval 3 %null-env) 3)
(=? '(%eval '(begin 1 2 3 4) %null-env) 4)
(=? '(%eval/env '(begin (define x 77) x)) 77)
(=? '(%eval/env '(quote x)) 'x)
(=? '(%eval/env '(begin (define x 77) (set! x 66) x)) 66)
(=? '(%eval/env '(false? %t)) %f)
(=? '(%eval/env '(if %t 'conseq dont-eval-me)) 'conseq)
(=? '(%eval/env '(if %f dont-eval-me 'alt)) 'alt)
(=? '(%eval/env '(cond (%f dont-eval1) (%f dont-eval2) (%t 'yes))) 'yes)
(=? '(%eval '(lambda (x) x) %base-env) `(procedure (x) (x) ,%base-env))
(=? '(%eval/env '((lambda(x) x) 3)) 3)
(=? '(%eval/env '((lambda(x y) x) 1 2)) 1)
(=? '(%eval/env '(+ 2 2)) 4)
(=? '(%eval/env '(cons 2 (cons 3 '()))) '(2 3))
(=?e '(%eval/env '(list 1 2 3)) "Undefined variable: ")
;; Ex. 4.1
(=?o '(list-of-values '((display 1)(display 2)(display 3)) %base-env)
"123")
(=?o '(list-of-values-backend-dependent
'((display 1)(display 2)(display 3)) %base-env 'left)
"123")
;; Backend evals RTL, we're in trouble.
(=?o '(list-of-values-backend-dependent
'((display 1)(display 2)(display 3)) %base-env 'right)
"321")
(=?o '(list-of-values-backend-agnostic
'((display 1)(display 2)(display 3)) %base-env 'left)
"123")
;; Backend evals RTL, but we get values in source order.
(=?o '(list-of-values-backend-agnostic
'((display 1)(display 2)(display 3)) %base-env 'right)
"123")
;; Ex. 4.2b
(=?e '(%eval42b '(+ 1 2) %base-env42b) "%eval: unknown expression")
(=? '(%eval42b '(call + 1 2) %base-env42b) 3)
(=? '(%eval42b '(call + (call + 10 5) (call (lambda(x) 5) 'whatever)) %base-env42b) 20)
(=? '(%eval42b '(begin (define (f x) (call + 1 x)) (call f 5)) %base-env42b) 6)
;; Ex. 4.3
(=? '(type-of '(quote x)) 'quote)
(=? '(type-of '(begin a b c)) 'begin)
(=? '(type-of 3) 'self-evaluating)
(=? '(type-of '(set! x 3)) 'set!)
(=? '(type-of '(define x 3)) 'define)
(=? '(type-of 'x) 'variable)
(=? '(type-of '(if x y z)) 'if)
(=? '(type-of '(cond (x y) z)) 'cond)
(=? '(type-of '(lambda(x) (+ x x))) 'lambda)
(=? '(type-of '(+ 1 2)) 'application)
(=? '(first (lambda(x) (= x 0)) '(1 2 3)) #f)
(=? '(first (lambda(x) (= x 0)) '(1 2 0 3)) #t)
(=? '(get-eval-method 'quoted '((quoted . 0))) 0)
(=? '(get-eval-method 'quoted '((not-here . #f) (quoted . 0))) 0)
;; Ex 4.4
;; ANDs
(=? '(and? '(and #t #t)) 'and)
(=? '(and? '(blah #t #t)) #f)
(=? '(and-actions '(and a b)) '(a b))
(=? '(%eval/env '(and %t %t)) %t)
(=? '(%eval/env '(and %t %f)) %f)
(=?o '(%eval/env '(and (begin (display "1") %t)
(begin (display "2") %f)
(begin (display "3") %t))) "12")
;; derived and
(=? '(%eval/env '(dand %t %t)) %t)
(=? '(%eval/env '(dand %t %f)) %f)
(=?o '(%eval/env '(dand (begin (display "1") %t)
(begin (display "2") %f)
(begin (display "3") %t))) "12")
;; ORs
(=? '(or? '(or #t #t)) 'or)
(=? '(or? '(blah #t #t)) #f)
(=? '(or-actions '(or a b)) '(a b))
(=? '(%eval/env '(or %t %t)) %t)
(=? '(%eval/env '(or %f %t)) %t)
(=? '(%eval/env '(or %f %f)) %f)
(=?o '(%eval/env '(or (begin (display "1") %f)
(begin (display "2") %t)
(begin (display "3") %f))) "12")
;; derived or
(=? '(%eval/env '(dor %t %t)) %t)
(=? '(%eval/env '(dor %f %t)) %t)
(=? '(%eval/env '(dor %f %f)) %f)
(=?o '(%eval/env '(dor (begin (display "1") %f)
(begin (display "2") %t)
(begin (display "3") %f))) "12")
;; 4.5 Cond arrow syntax
(=? '(arrow-syntax? '(=> grue)) #t)
(=? '(arrow->exp '(cons 1 2) '(=> car)) '(car (cons 1 2)))
(=? '(cond->if '(cond (a 1) (else 2))) '(if a 1 2))
(=? '(cond->if '(cond ((cons 1 2) => car) (else 0))) '(if (cons 1 2) (car (cons 1 2)) 0))
(=? '(%eval/env '(cond ((cons 1 2) => cdr) (else %f))) '2)
(=? '(%eval/env '(cond (%f => never-run) ((cons 2 3) => car) (else 0))) '2)
(=? '(%eval/env '(cond (%f => never-run) (else 'exit))) 'exit)
;; 4.6 Let-to-lambda
(=? '(let? '(let ((a 1)) a)) 'let)
(=? '(let-bindings '(let ((a 1)) a)) '((a 1)))
(=? '(let-body '(let ((a 1)) a)) '(a))
(=? '(let-vars '(let ((a 1) (b 2)) a)) '(a b))
(=? '(let-vals '(let ((a 1) (b 2)) a)) '(1 2))
(=? '(let->combination '(let ((a 1)) (f a))) '((lambda (a) (f a)) 1))
(=? '(let->combination '(let ((a 1) (b 2)) (f a b))) '((lambda (a b) (f a b)) 1 2))
(=? '(%eval/env '(let () 3)) 3)
(=? '(%eval/env '(let ((a 11)) a)) 11)
(=? '(%eval/env '(let ((a 11) (b 22)) (+ a b))) 33)
;; 4.7 let*
(=? '(let*? '(let* ((a 1) (b a)) b)) 'let*)
(=? '(let*->nested-let '(let* ((a 1) (b a)) b))
'(let ((a 1)) (let ((b a)) b)))
(=? '(%eval/env '(let* ((a 11) (b a) (c b)) 11)) 11)
;; If the evaluator already supports let, then it's enough that we transform
;; let* to let, and make the evaluator handle the expansion when it
;; gets to the generated let-clause.
;; 4.8 Named-let
(=? '(let? '(let foo ((a 1))(if (= a 10) (cons a "done") (foo (+ 1 a))))) 'let)
(=? '(named-let? '(let foo ((a 1))(if (= a 10) (cons a "done") (foo (+ 1 a))))) 'named-let)
(=? '(named-let-name '(let foo ((a 1))(if (= a 10) (cons a "done") (foo (+ 1 a)))))
'foo)
(=? '(named-let-bindings '(let foo ((a 1))(if (= a 10) (cons a "done") (foo (+ 1 a)))))
'((a 1)))
(=? '(named-let-vars '(let foo ((a 1))(if (= a 10) (cons a "done") (foo (+ 1 a)))))
'(a))
(=? '(named-let-vals '(let foo ((a 1))(if (= a 10) (cons a "done") (foo (+ 1 a)))))
'(1))
(=? '(named-let-body '(let foo ((a 1))(if (= a 10) (cons a "done") (foo (+ 1 a)))))
'((if (= a 10) (cons a "done") (foo (+ 1 a)))))
(=? '(named-let->seq '(let foo ((a 1))(if (= a 10) (cons a "done") (foo (+ 1 a)))))
'(begin
(define foo (lambda (a) (if (= a 10) (cons a "done") (foo (+ 1 a)))))
(foo 1)))
(=? '(%eval/env '(let foo ((a 1))(if (= a 10) (cons a "done") (foo (+ 1 a)))))
'(10 . "done"))
;; 4.9 For loop
;; We'll need an empty-list
(=? '(%eval/env '(empty)) '())
(=? '(for? '(for (i 0 10) i)) 'for)
(=? '(for-var '(for (i 0 10) i)) 'i)
(=? '(for-start '(for (i 0 10) i)) 0)
(=? '(for-end '(for (i 0 10) i)) 10)
(=? '(for-body '(for (i 0 10) i)) 'i)
(=? '(for->let '(for (i 0 10) (display i)))
'(let loop-i ((res-i (empty)) (i 0))
(if (= i 10)
(reverse res-i)
(let ((res-i (cons (display i) res-i)))
(loop-i res-i (+ 1 i))))))
(=? '(%eval/env '(for (i 0 10) i))
'(0 1 2 3 4 5 6 7 8 9))
(=?o '(%eval/env '(for (i 0 10) (display i)))
"0123456789")
(=? '(for->let '(for (i 0 10) (for (j 0 2) (display (+ i j)))))
'(let loop-i ((res-i (empty)) (i 0))
(if (= i 10)
(reverse res-i)
(let ((res-i (cons (for (j 0 2) (display (+ i j))) res-i)))
(loop-i res-i (+ 1 i))))))
(=?o '(%eval/env '(for (i 0 2) (for (j 0 2) (display (+ i j)))))
"0112")
(=? '(%eval/env '(for (i 0 2) (for (j 0 2) (+ i j))))
'((0 1) (1 2)))
;; Ex 4.10 -- TODO
;; Ex 4.11
(=? '(make-aframe '() '()) (list %NF))
(=? '(make-aframe '(a) '(1)) (list '(a . 1) %NF))
(=? '(make-aframe '(a b) '(1 2)) (list '(a . 1) '(b . 2) %NF))
(=? '(aframe-get (make-aframe '(a b) '(1 2)) 'a) 1)
(=? '(make-binding 'a 5) '(a . 5))
(=? '(let ((b (make-binding 'a 10)))
(set-binding-val! b 1) b)
(make-binding 'a 1))
(=? '(let [(f (make-aframe '(a) '(1)))] (add-binding-to-aframe! 'z 9 f) f)
(make-aframe '(z a) '(9 1)))
(=? '(extend-environment '(a) '(1) %null-env) (list (make-aframe '(a) '(1))))
(=?e '(extend-environment'(a) '() %null-env) "extend-environment: too few values: ")
(=?e '(extend-environment '() '(1) %null-env) "extend-environment: too few variables: ")
(=? '(first-frame (extend-environment '(x y ) '(5 7 ) %null-env))
(list '(x . 5) '(y . 7) %NF))
(=? '(let* [(e1 (extend-environment '(a) '(1) %null-env))
(e2 (extend-environment '(b) '(2) e1))]
(enclosing-environment e2)) `(((a . 1) ,%NF)))
;; Ex. 4.12 refactoring -- uses existing tests.
;; Ex. 4.13 make-unbound!
(=? '(unbinding? '(make-unbound! a)) 'make-unbound!)
(=? '(unbound-var '(make-unbound! a)) 'a)
(=?e '(let ((f (make-aframe '() '())))
(destroy-first-binding! f))
"cannot remove binding from empty frame")
(=? '(let ((f (make-aframe '(a) '(1))))
(destroy-first-binding! f)
f)
(make-aframe '() '()))
(=? '(%eval/env '(begin (define x 3)
(let ((not 'used)) (define x 4) (make-unbound! x) x)))
3)
(=?e '(%eval/env '(make-unbound! ghost-var)) "Variable not bound: ")
;; Ex. 4.16 b
(=? '(find-defines '((define (f x) (blaf)) (hello world) (define (g x) (blag))))
'((define (f x) (blaf)) (define (g x) (blag))))
(=? '(filter-out-defines '((define (f x) (blaf)) (hello world) (define (g x) (blag)) (f (g 3))))
'((hello world) (f (g 3))))
(=? '(scan-out-defines '((define (g x) (+ 2 x)) (+ (g a) b)))
'((let ((g '%unassigned))
(set! g (lambda (x) (+ 2 x)))
(+ (g a) b))))
(=? '(scan-out-defines '((define (g x) (+ 2 x)) (define (h y) (+ (g y) 7)) (+ (g a) (h 2))))
'((let ((g '%unassigned)
(h '%unassigned))
(set! g (lambda (x) (+ 2 x)))
(set! h (lambda (y) (+ (g y) 7)))
(+ (g a) (h 2)))))
;; This is pretty low-level...
(=? '(make-procedure '(x)
'((define (f y) (g y))
(define (g z) (* 2 z))
(f x))
%null-env)
'(procedure (x)
((let ((f '%unassigned)
(g '%unassigned))
(set! f (lambda (y) (g y)))
(set! g (lambda (z) (* 2 z)))
(f x)))
()))
;; Ex. 4.18 -- see source
;; Ex. 4.19 Skip
;; Ex. 4.20
(=? '(%eval/env '(begin (define (f x)
(define (even? x) (if (= x 0) %t (odd? (- x 1))))
(define (odd? x) (if (= x 0) %f (even? (- x 1))))
(even? x))
(f 8)))
%t)
(=? '(extract-vars '(letrec ((f (f-body)) (g (g-body))) (f (g 1))))
'(f g))
(=? '(extract-bodies '(letrec ((f (f-body)) (g (g-body))) (f (g 1))))
'((f-body) (g-body)))
(=? '(letrec-vars '(letrec ((f (f-body)) (g (g-body))) (f (g 1))))
'((f '*unassigned*) (g '*unassigned*)))
(=? '(letrec-assignments '(letrec ((f (f-body)) (g (g-body))) (f (g 1))))
'((set! f (f-body))
(set! g (g-body))))
(=? '(letrec-body '(letrec ((f (f-body)) (g (g-body))) (f (g 1))))
'((f (g 1))))
(=? '(letrec->let '(letrec ((f (f-body)) (g (g-body))) (f (g 1))))
'(let ((f '*unassigned*)
(g '*unassigned*))
(set! f (f-body))
(set! g (g-body))
(f (g 1))))
(=? '(%eval/env '(begin (define (f x)
(letrec ((even? (lambda(x) (if (= x 0) %t (odd? (- x 1)))))
(odd? (lambda(x) (if (= x 0) %f (even? (- x 1))))))
(even? x)))
(f 8)))
%t)
;; Ex 4.21
(=? '(%eval/env '(begin (define (f x)
((lambda (even? odd?) (even? even? odd? x))
(lambda (ev? od? n)
(if (= n 0) %t (od? ev? od? (- n 1))))
(lambda (ev? od? n)
(if (= n 0) %f (ev? ev? od? (- n 1))))))
(f 11)))
%f)
))
| false |
fae138fc8b5fa9ff8dc86a27898242ff13bc97db
|
53cb8287b8b44063adcfbd02f9736b109e54f001
|
/command-interface/incremental-compiler.scm
|
207b79d381086eb1ea32bf046f459bbb5bf7e14d
|
[] |
no_license
|
fiddlerwoaroof/yale-haskell-reboot
|
72aa8fcd2ab7346a4990795621b258651c6d6c39
|
339b7d85e940db0b8cb81759e44abbb254c54aad
|
refs/heads/master
| 2021-06-22T10:32:25.076594 | 2020-10-30T00:00:31 | 2020-10-30T00:00:31 | 92,361,235 | 3 | 0 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 5,365 |
scm
|
incremental-compiler.scm
|
;;; ==================================================================
;;; This deals with incremental compilation as used by the command interface.
;;; The basic theory is to create new modules which import the entire
;;; symbol table of an existing module.
;;; This adds a new module to the extension environment. This env is an alist
;;; of module names & extended modules.
(define *extension-env* '())
(define (extend-module mod-name new-ast)
(push (tuple mod-name new-ast) *extension-env*))
;;; This cleans out extensions for a module.
(define (remove-extended-modules mod-name)
(setf *extension-env* (rem-ext1 *extension-env* mod-name)))
(define (rem-ext1 env name)
(cond ((null? env)
'())
((eq? (tuple-2-1 (car env)) name)
(rem-ext1 (cdr env) name))
(else
(cons (car env) (rem-ext1 (cdr env) name)))))
(define (clear-extended-modules)
(setf *extension-env* '()))
;;; This retrieves the current extension to a module (if any).
(define (updated-module name)
(let ((name+mod (assq name *extension-env*)))
(if (not (eq? name+mod '#f))
(tuple-2-2 name+mod)
(let ((mod-in-table (table-entry *modules* name)))
(cond ((eq? mod-in-table '#f)
(signal-module-not-ready name))
((eq? (module-type mod-in-table) 'interface)
(signal-cant-eval-interface name))
(else mod-in-table))))))
(define (signal-module-not-ready name)
(fatal-error 'module-not-ready
"Module ~A is not loaded and ready."
name))
(define (signal-cant-eval-interface name)
(fatal-error 'no-evaluation-in-interface
"Module ~A is an interface: evaluation not allowed."
name))
(define (compile-fragment module str filename)
(let ((mod-ast (updated-module module)))
(dynamic-let
((*printers* (if (memq 'extension *printers*) *printers* '()))
(*abort-phase* '#f))
(mlet (((t-code new-ast) (compile-fragment1 module mod-ast str filename)))
(cond ((eq? t-code 'error)
'error)
(else
(eval t-code)
new-ast))))))
(define (compile-fragment1 mod-name mod-ast str filename)
(let/cc x
(dynamic-let ((*abort-compilation* (lambda () (funcall x 'error '()))))
(let* ((mods (parse-from-string
(format '#f "module ~A where~%~A~%" mod-name str)
(function parse-module-list)
filename))
(new-mod (car mods)))
(when (not (null? (cdr mods)))
(signal-module-decl-in-extension))
(when (not (null? (module-imports new-mod)))
(signal-import-decl-in-extension))
(fragment-initialize new-mod mod-ast)
(values (modules->lisp-code mods) new-mod)))))
(define (signal-module-decl-in-extension)
(fatal-error 'module-decl-in-extension
"Module declarations are not allowed in extensions."))
(define (signal-import-decl-in-extension)
(fatal-error 'import-decl-in-extension
"Import declarations are not allowed in extensions."))
;;; Copy stuff into the fragment module structure from its parent module.
;;; The inverted symbol table is not necessary since the module contains
;;; no imports.
(define (fragment-initialize new old)
(setf (module-name new) (gensym))
(setf (module-type new) 'extension)
(setf (module-unit new) (module-unit old))
(setf (module-uses-standard-prelude? new)
(module-uses-standard-prelude? old))
(setf (module-inherited-env new) old)
(setf (module-fixity-table new)
(copy-table (module-fixity-table old)))
(setf (module-default new) (module-default old)))
;;; This code deals with the actual evaluation of Haskell code.
;;; This decides whether a variable has type `Dialogue'.
(define (io-type? var)
(let ((type (var-type var)))
(when (not (gtype? type))
(error "~s is not a Gtype." type))
(and (null? (gtype-context type))
(is-dialogue? (gtype-type type)))))
(define (is-dialogue? type)
(let ((type (expand-ntype-synonym type)))
(and (ntycon? type)
(eq? (ntycon-tycon type) (core-symbol "Arrow"))
(let* ((args (ntycon-args type))
(a1 (expand-ntype-synonym (car args)))
(a2 (expand-ntype-synonym (cadr args))))
(and
(ntycon? a1)
(eq? (ntycon-tycon a1) (core-symbol "SystemState"))
(ntycon? a2)
(eq? (ntycon-tycon a2) (core-symbol "IOResult")))))))
(define (is-list-of? type con)
(and (ntycon? type)
(eq? (ntycon-tycon type) (core-symbol "List"))
(let ((arg (expand-ntype-synonym (car (ntycon-args type)))))
(and (ntycon? arg) (eq? (ntycon-tycon arg) con)))))
(define (apply-exec var)
(initialize-io-system)
(mlet (((_ sec)
(time-execution
(lambda ()
(let/cc x
(setf *runtime-abort* (lambda () (funcall x 'error)))
(let ((fn (eval (fullname var))))
(unless (var-strict? var)
(setf fn (force fn)))
(funcall fn (box 'state))))))))
(say "~%")
(when (memq 'time *printers*)
(say "Execution time: ~A seconds~%" sec)))
'done)
(define (eval-module mod)
(dolist (v (module-vars mod))
(when (io-type? v)
(when (not (string-starts? "temp_" (symbol->string (def-name v))))
(say/ne "~&Evaluating ~A.~%" v))
(apply-exec v))))
(define (run-program name)
(compile/load name)
(let ((main-mod (table-entry *modules* '|Main|)))
(if main-mod
(let ((main-var (table-entry (module-symbol-table main-mod) '|main|)))
(if main-var
(apply-exec main-var)
(error "Variable main missing")))
(error "module Main missing"))))
| false |
e24db1849df4578bfbf999345b848e056b8f24fb
|
00466b7744f0fa2fb42e76658d04387f3aa839d8
|
/sicp/chapter2/2.3/ex2.58.scm
|
758cd22059f53a077bc05bc3a3f35c0b1ffc461d
|
[
"WTFPL"
] |
permissive
|
najeex/stolzen
|
961da2b408bcead7850c922f675888b480f2df9d
|
bb13d0a7deea53b65253bb4b61aaf2abe4467f0d
|
refs/heads/master
| 2020-09-11T11:00:28.072686 | 2015-10-22T21:35:29 | 2015-10-22T21:35:29 | null | 0 | 0 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 4,249 |
scm
|
ex2.58.scm
|
#lang scheme
(require racket/trace)
(define (variable? expression)
(symbol? expression)
)
(define (same-variable? v1 v2)
(and (variable? v1) (variable? v2) (eq? v1 v2))
)
(define (operation? expression symbol)
(define (not-empty? seq)
(not (null? seq))
)
(define (contains? seq symbol)
(not-empty? (filter (lambda (x) (eq? x symbol)) seq))
)
(and
(pair? expression)
(contains? expression symbol))
)
(define (sum? expression)
(operation? expression '+)
)
(define (first-if-singleton seq)
(if (null? (cdr seq))
(car seq)
seq
)
)
(define (cut-before symbol expression)
(define (cut-before-inner expression)
(if (or (null? expression) (eq? (car expression) symbol))
null
(cons (car expression) (cut-before-inner (cdr expression)))
)
)
(first-if-singleton (cut-before-inner expression))
)
(= 1 (cut-before '+ '(1 + x * x)))
(equal? '(1 * 2) (cut-before '+ '(1 * 2 + x * x)))
(define (cut-after symbol expression)
(define (cut-after-inner expression)
(cond
((null? expression) null)
((eq? symbol (car expression)) (cdr expression))
(else
(cut-after-inner (cdr expression)))
)
)
(first-if-singleton (cut-after-inner expression))
)
(equal? '(x * x) (cut-after '+ '(1 + x * x)))
(define (addend expression)
(cut-before '+ expression)
)
(define (augend expression)
(cut-after '+ expression)
)
(define (=number? exp num)
(and (number? exp) (= exp num))
)
(define (make-sum addend augend)
(cond
((=number? addend 0) augend)
((=number? augend 0) addend)
((and (number? addend) (number? augend)) (+ addend augend))
(else
(list addend '+ augend))
)
)
(define (product? expression)
(operation? expression '*)
)
(define (multiplier expression)
(cut-before '* expression)
)
(define (multiplicand expression)
(cut-after '* expression)
)
(define (make-product m1 m2)
(cond
((or (=number? m1 0) (=number? m2 0)) 0)
((=number? m1 1) m2)
((=number? m2 1) m1)
((and (number? m1) (number? m2)) (* m1 m2))
(else
(list m1 '* m2))
)
)
(define (exponentiation? expression)
(and (pair? expression) (eq? (car expression) 'exp))
)
(define (base expression)
(cadr expression)
)
(define (exponent expression)
(caddr expression)
)
(define (make-exponentiation base exponent)
(cond
((=number? exponent 0) 1)
((=number? exponent 1) base)
((and (number? base) (number? exponent)) (exp base exponent))
(else
(list 'exp base exponent))
)
)
(define (deriv exp var)
(cond
((number? exp) 0)
((variable? exp)
(if (same-variable? exp var) 1 0))
((sum? exp)
(make-sum (deriv (addend exp) var)
(deriv (augend exp) var)))
((product? exp)
(make-sum
(make-product (multiplier exp)
(deriv (multiplicand exp) var))
(make-product (deriv (multiplier exp) var)
(multiplicand exp))
)
)
((exponentiation? exp)
(make-product
(exponent exp)
(make-product
(make-exponentiation (base exp) (- (exponent exp) 1))
(deriv (base exp) var)
)
)
)
(else
(error "unknown expression type -- DERIV" exp))
)
)
(trace deriv)
(= 2 (deriv '(x + x) 'x))
(= 1 (deriv '(x + 3) 'x))
(= 1 (deriv '(x + y) 'x))
(= 1 (deriv '(x + y) 'y))
(eq? 'x (deriv '(x * y) 'y))
(= 4 (deriv '(x + (3 * (x + (y + 2)))) 'x))
(= 4 (deriv '(x + 3 * (x + y + 2)) 'x))
(= 8 (deriv '(x * 3 + 5 * (x + y + 2)) 'x))
(equal? '(y + 5) (deriv '(x * y + 5 * (x + y + 2)) 'x))
| false |
4fd25877968b8a275df4446dcc001e6b105f9cd1
|
ac2a3544b88444eabf12b68a9bce08941cd62581
|
/gsc/tests/08-flprim/flfib.scm
|
99f95d99884ef63a82ce4976267d2bca078227b8
|
[
"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 | 251 |
scm
|
flfib.scm
|
(declare (extended-bindings) (not constant-fold) (not safe))
(define (fib n)
(define (fib n)
(if (##fl< n 2.0)
n
(##fl+ (fib (##fl- n 1.0))
(fib (##fl- n 2.0)))))
(fib n))
(println (##fl= 6765.0 (fib 20.0)))
| false |
ddc2cd3e84feafd857653dd556cc845a6bc55f57
|
b58f908118cbb7f5ce309e2e28d666118370322d
|
/src/37.scm
|
1f1bc7c29e6de755a9276e8206f2173b784956bd
|
[
"MIT"
] |
permissive
|
arucil/L99
|
a9e1b7ad2634850db357f7cc292fa2871997d93d
|
8b9a3a8e7fb63efb2d13fab62cab2c1254a066d9
|
refs/heads/master
| 2021-09-01T08:18:39.029308 | 2017-12-26T00:37:55 | 2017-12-26T00:37:55 | 114,847,976 | 1 | 0 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 319 |
scm
|
37.scm
|
(load "prelude.scm")
(load "36.scm")
;;; P37
(define (totient-phi-2 m)
(apply *
(map
(lambda (p)
(* (sub1 (car p))
(expt (car p) (sub1 (cadr p)))))
(prime-factors-mult m))))
(test (totient-phi-2 10) 4)
(test (totient-phi-2 13) 12)
(test (totient-phi-2 1) 1)
| false |
86f5d1230a4c84ecb79e8badd3b018a91ae3aac2
|
648776d3a0d9a8ca036acaf6f2f7a60dcdb45877
|
/queries/julia/indents.scm
|
142dee4736636c6cf979a50201c15fb18313076b
|
[
"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 | 582 |
scm
|
indents.scm
|
[
(struct_definition)
(macro_definition)
(function_definition)
(compound_statement)
(if_statement)
(try_statement)
(for_statement)
(while_statement)
(let_statement)
(quote_statement)
(do_clause)
(assignment)
(for_binding)
(binary_expression)
(call_expression)
(tuple_expression)
(comprehension_expression)
(matrix_expression)
(vector_expression)
] @indent.begin
[
"end"
"("
")"
"["
"]"
(else_clause)
(elseif_clause)
(catch_clause)
(finally_clause)
] @indent.branch
[
(line_comment)
(block_comment)
] @indent.ignore
| false |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.