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 |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
265247adca3a33793b853fe31e5563f907396bb8
|
d369542379a3304c109e63641c5e176c360a048f
|
/brice/Chapter2/exercise-2.6.scm
|
cee6a3b2720ab429a7d655bd037df80c5b70d089
|
[] |
no_license
|
StudyCodeOrg/sicp-brunches
|
e9e4ba0e8b2c1e5aa355ad3286ec0ca7ba4efdba
|
808bbf1d40723e98ce0f757fac39e8eb4e80a715
|
refs/heads/master
| 2021-01-12T03:03:37.621181 | 2017-03-25T15:37:02 | 2017-03-25T15:37:02 | 78,152,677 | 1 | 0 | null | 2017-03-25T15:37:03 | 2017-01-05T22:16:07 |
Scheme
|
UTF-8
|
Scheme
| false | false | 2,647 |
scm
|
exercise-2.6.scm
|
#lang racket
(require "../utils.scm")
(require "../meta.scm")
(title "Exercise 2.6")
; Exercise 2.6:
;
; In case representing pairs as procedures wasn’t
; mind-boggling enough, consider that, in a language
; that can manipulate procedures, we can get by
; without numbers (at least insofar as nonnegative
; integers are concerned) by implementing 0 and the
; operation of adding 1 as:
(define zero
(lambda (f)
(lambda (x) x)))
(define (add-1 n)
(lambda (f)
(lambda (x)
(f ((n f) x)))))
; This representation is known as Church numerals,
; after its inventor, Alonzo Church, the logician who
; invented the λ-calculus.
;
; Define one and two directly (not in terms of zero
; and add-1).
;
; Hint: Use substitution to evaluate (add-1 zero).
;
; Give a direct definition of the addition procedure +
; (not in terms of repeated application of add-1).
(define one
(lambda (f)
(lambda (x)
(f x))))
(define two
(lambda (f)
(lambda (x)
(f (f x)))))
(define three
(lambda (f)
(lambda (x)
(f (f (f x))))))
; turning church numerals into integers for testing
(define (cn-to-int cn)
((cn inc) 0))
(asserteq "Expect λf.λx.x to be 0" 0 (cn-to-int zero))
(asserteq "Expect λf.λx.fx to be 1" 1 (cn-to-int one))
(asserteq "Expect λf.λx.f(fx) to be 2" 2 (cn-to-int two))
(asserteq "Expect λf.λx.f(f(fx)) to be 3" 3 (cn-to-int three))
(define (int-to-cn i)
(lambda (f)
(lambda (x)
((repeated f i) x))))
(asserteq "We can convert ints to church numerals"
5 (cn-to-int (int-to-cn 5)))
(define (add-cn a b)
"λa.λb.λf.λx.(a f) ((b f) x)"
(lambda (f)
(lambda (x)
((a f) ((b f) x)))))
(asserteq "Adding 1 to 1 in church numeral yields 2"
2
(cn-to-int (add-cn one one)))
(asserteq "Adding 2 to 1 in church numeral yields 3"
3
(cn-to-int (add-cn two one)))
(asserteq "Adding 1 to 2 in church numeral yields 3"
3
(cn-to-int (add-cn one two)))
(asserteq "Adding 2 to 2 in church numeral yields 4"
4
(cn-to-int (add-cn two two)))
(define (expt-cn a b)
"λa.λb.b a"
(b a))
(asserteq "Exponentiation works for even exponents"
(expt 2 8)
(cn-to-int (expt-cn two (int-to-cn 8))))
(asserteq "Exponentiation works for odd exponents"
(expt 4 5)
(cn-to-int (expt-cn (int-to-cn 4) (int-to-cn 5))))
(define (mul-cn a b)
"λa.λb.λf.a (b f)"
(lambda (f)
(a (b f))))
(asserteq "Multiplication works for 2 x 2"
4
(cn-to-int (mul-cn two two)))
(asserteq "Multiplication works for 2 x 3"
6
(cn-to-int (mul-cn two three)))
(asserteq "Multiplication works for 123 x 87"
(* 123 87)
(cn-to-int (mul-cn (int-to-cn 123) (int-to-cn 87))))
; What about divide? Substract? Boolean logic?
| false |
a2aad4c0388986cdc6fa1c10faa40749b8f89937
|
bec9f0c739a30427f472afb90bd667d56b5d8d0c
|
/hw/test_10.ss
|
6094d4f2b5c925da7aaeea206fcbf2a450aec626
|
[] |
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 | 1,877 |
ss
|
test_10.ss
|
(define testDataGood '(
()
#t
#f
1
2
#()
#(1 2 3)
""
"abc"
(1 2)
(set! a b)
(if a x)
(if a x y)
(lambda () x)
(lambda () x y)
(lambda (x) x)
(lambda (x) x y)
(lambda x y)
(lambda x y z)
(lambda (a b c) d)
(lambda (a b c) d e)
(lambda (a b c . d) e)
(lambda (a b c . d) e f)
(let () x)
(let ((a #f)) a)
(let () x y)
(let ((a b)) c)
(let ((a b)) c d)
(let* () x)
(let* ((a #f)) a)
(let* () x y)
(let* ((a b)) c)
(let* ((a b)) c d)
(letrec () x)
(letrec ((a #f)) a)
(letrec () x y)
(letrec ((a b)) c)
(letrec ((a b)) c d)
(let name () x y)
(let name ((a #f)) a)
(let name ((x y)) x y)
(let name ((a c) (b d)) e f)
((lambda (x)
(if x 3 4))
5)
(lambda x (if (< x (* x 2)) #t "abc"))
))
(define testDataBad '(
(set!)
(set! a)
(set! a b c)
(if)
(if a b c d)
(lambda)
(lambda ())
(lambda (()))
(lambda ((x)))
(let)
(let x)
(let x y)
(let (x))
(let (x) y)
(let (x y) z)
(let (((x) y)) z)
(let (((x y))) z)
(let*)
(let* x)
(let* x y)
(let* (x))
(let* (x) y)
(let* (x y) z)
(let* (((x) y)) z)
(let* (((x y))) z)
(letrec)
(letrec x)
(letrec x y)
(letrec (x))
(letrec (x) y)
(letrec (x y) z)
(letrec (((x) y)) z)
(letrec (((x y))) z)
(let name)
(let name x)
(let name x y)
(let name (x))
(let name (x) y)
(let name (x y) z)
(let name (((x) y)) z)
(let name (((x y))) z)
(lambda (a b #f) x)
))
(define testGood
(lambda ()
(let ((tempData (map parse-exp testDataGood)))
(display (format "~s\n" tempData))
(display (format "~s\n" testDataGood))
(display (map unparse-exp tempData)))))
(define testBad
(lambda ()
(let ((tempData (map parse-exp testDataBad)))
(display (format "~s\n" tempData)))))
(define testGood2
(lambda ()
(andmap (lambda (x) (equal? (unparse-exp (parse-exp x)) x)) testDataGood)))
(define testBad2
(lambda()
(andmap null? (map parse-exp testDataBad))))
| false |
624e55b147891e2939ee4f127e8209d560493eba
|
78fcf60b775e60b958a13f7228e97ba32bc6d0a4
|
/runtime-library.scm
|
a6c02e47e3ad9323568f624a308dbcc51ec39593
|
[
"MIT"
] |
permissive
|
gregsgit/glos
|
1d8b8a388c15d70944b7a6cc1fd04ff5ae4765ee
|
5b50b079836a2576494b23b30417b52cd671d088
|
refs/heads/master
| 2021-01-25T07:39:56.631984 | 2014-02-02T21:06:09 | 2014-02-02T21:06:09 | 16,462,239 | 4 | 0 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 5,316 |
scm
|
runtime-library.scm
|
;; runtime-library.scm
;; "nonessential" functions for GLOS runtime
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; BUILT IN TYPES
;;
;; ***** !!!!! ***** !!!!! *****
;; It better be the case that if I declare type <x> to be
;; (and? <y> P), then the all values that satisfy P better be (isa? <y>)
;; define the following because some of the types (e.g. <complex>) are
;; subtypes (by being and-types). Thus the programmer knows that if s/he
;; uses the <typename> types, the expected subtyping rules will apply.
(define <boolean> boolean?)
(define <pair> pair?)
(define <symbol> symbol?)
(define <number> number?)
(define <char> char?)
(define <string> string?)
(define <vector> vector?)
(define <port> port?)
(define <procedure> procedure?)
;; TO DO: more/better order to list/pair/null hierarchy
;; Why <list> \not\le <pair>: '() is a list but not a pair.
(define <list> list?)
;; Why <null> \not\le <list>: car and cdr are defined on lists but not '().
;; However, the fact that (list? '()) => #t seems to take precedence.
;; (and the fact that traditionally lists are sum types of nonempty and empty)
(define <null> (and? <list> null?))
;; TO DO: more/better order to number hierarchy
(define <complex> (and? <number> complex?))
(define <real> (and? <complex> real?))
(define <rational> (and? <real> rational?))
(define <integer> (and? <rational> integer?))
(define <int> <integer>)
(define <cell> cell?)
;; CALLABLES
(define <callable> (or? generic? method? procedure?))
;; method-signature is a convenience function for those methods
;; that have signature-type method-types. The only methods for which we know
;; this to be the case are record-subtype constructor methods and slot
;; accessor methods.
(define (method-signature m)
(if (signature-type? (method-args-type m))
(method-args-type m)
(error "Method ~a does not have a signature-type as its method-args-type"
m)))
;; RECORDS
(define <record-type> glos-record-type?)
(define (new rt . args)
(assert (glos-record-type? rt)
"Must call new on a glos-record-type. Not ~a" rt)
;; (1) call make
(let ((new-obj (apply make rt args))) ; make is a generic function
;; (2) call initialize
(apply initialize new-obj args)
new-obj))
(defgeneric make
;; default method on make ignores args (they are passed to initialize by new)
(method ((rt <record-type>) :rest ignored-args)
((glos-record-type-constructor rt))))
(defgeneric initialize
;; default method treats args as a list of alternating names and values
(method (obj :rest args)
(apply set-by-name* obj args)))
(define (get-by-name name val)
(assert (instance? val) "Value ~a not an instance." val)
(let ((fspec (get-field-by-name! name (instance-type val))))
((field-spec-getter fspec) val)))
(define (set-by-name! name obj newval)
(let ((fspec (get-field-by-name! name (instance-type obj))))
((field-spec-setter fspec) obj newval)))
;; args is alternating list of fieldname, value, ...
(define (set-by-name* obj . args)
(assert (even? (length args))
"Invalid name,val,name,val, ... list to set-by-name* ~a" args)
(let loop ((args args))
(if (null? args)
obj
(begin
(set-by-name! (car args) obj (cadr args))
(loop (cddr args))))))
;; Whenever encounter a symbol in args, take it as a fieldname,
;; and invoke the relevant setter, if any, with the next value in args.
;; Does not complain if doesn't find matching field names.
(define (handle-relevant-keys rt obj args)
(let loop ((args args))
(if (> (length args) 1)
(if (symbol? (car args))
(cond ((find-field-with-name (car args) rt)
=> (lambda (field-spec)
((field-spec-setter field-spec) obj (cadr args))
(loop (cddr args)))))
(loop (cdr args))))))
;; allows 'sym to occur multipe times in args
(define (handle-key sym args handler)
(let loop ((args args))
(if (> (length args) 1)
(if (and (symbol? (car args))
(eq? sym (car args)))
(begin
(handler (cadr args))
(loop (cddr args)))
(loop (cdr args))))))
(define (describe-constructor rt)
(let ((arg-types
(signature-type-types
(method-signature
(glos-record-type-constructor rt))))
(arg-names (foldr (lambda (field names)
(if (field-spec-has-initial-value? field)
names
(cons (field-spec-name field) names)))
'()
(glos-record-type-fields rt))))
(foldr (lambda (name type l)
(cons (cons name type) l)) '() arg-names arg-types)))
(define (describe-fields rt)
(foldr (lambda (field l)
(cons (list (field-spec-name field)
(field-spec-type field)
(if (field-spec-has-initial-value? field)
(field-spec-initial-value field)
'no-initial-value))
l))
'()
(glos-record-type-fields rt)))
;; CLONE
(defmethod (clone (obj <object>))
(let* ((obj-type (instance-type obj))
(new-obj ((glos-record-type-constructor obj-type))))
(format #t "created, now setting.~%")
(for-each (lambda (field)
((field-spec-setter field) new-obj
((field-spec-getter field) obj)))
(glos-record-type-fields obj-type))
new-obj))
;; eof
; eof
| false |
a8a3f1fd5c7b6ab0d20b53d8b4a286144927f21c
|
29fdc68ecadc6665684dc478fc0b6637c1293ae2
|
/src/wiliki/pasttime.scm
|
ce3472e7a27c3448b64c68b869364213a8f8c87f
|
[
"MIT"
] |
permissive
|
shirok/WiLiKi
|
5f99f74551b2755cb4b8deb4f41a2a770138e9dc
|
f0c3169aabd2d8d410a90033d44acae548c65cae
|
refs/heads/master
| 2023-05-11T06:20:48.006068 | 2023-05-05T18:29:48 | 2023-05-05T18:30:12 | 9,766,292 | 20 | 6 |
MIT
| 2018-10-07T19:15:09 | 2013-04-30T07:40:21 |
Scheme
|
UTF-8
|
Scheme
| false | false | 2,439 |
scm
|
pasttime.scm
|
;;;
;;; wiliki/pasttime - how long has it been passed since ...?
;;;
;;; Copyright (c) 2000-2009 Shiro Kawai <[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.
;;;
(define-module wiliki.pasttime
(export how-long-since))
(select-module wiliki.pasttime)
;; Multilingualizaton of this module is tricky, as the rules of
;; forming plurals are different from language to language.
;; See GNU's gettext document for the problem.
;; For now, I only support English.
(define-constant secs-in-a-year 31557600)
(define-constant secs-in-a-month 2629800)
(define-constant secs-in-a-day 86400)
(define-constant secs-in-an-hour 3600)
(define-constant secs-in-a-minute 60)
(define (how-long-since time . opts)
(define (pl num unit)
(format "~a ~a~a" num unit (if (= num 1) "" "s")))
(let-optionals* opts ((now (sys-time)))
(let ((diff (- now time)))
(cond
((>= diff secs-in-a-year)
(pl (quotient diff secs-in-a-year) "year"))
((>= diff secs-in-a-month)
(pl (quotient diff secs-in-a-month) "month"))
((>= diff secs-in-a-day)
(pl (quotient diff secs-in-a-day) "day"))
((>= diff secs-in-an-hour)
(pl (quotient diff secs-in-an-hour) "hour"))
((>= diff secs-in-a-minute)
(pl (quotient diff secs-in-a-minute) "minute"))
(else
(pl diff "second")))
)))
| false |
a8763fc839981272594d7d1c8448cbd33dbdbc28
|
2fc7c18108fb060ad1f8d31f710bcfdd3abc27dc
|
/lib/random.scm
|
6d7e13ed17db07f6214a94a1936a1952832d2ef9
|
[
"LicenseRef-scancode-public-domain",
"LicenseRef-scancode-warranty-disclaimer",
"CC0-1.0"
] |
permissive
|
bakul/s9fes
|
97a529363f9a1614a85937a5ef9ed6685556507d
|
1d258c18dedaeb06ce33be24366932143002c89f
|
refs/heads/master
| 2023-01-24T09:40:47.434051 | 2022-10-08T02:11:12 | 2022-10-08T02:11:12 | 154,886,651 | 68 | 10 |
NOASSERTION
| 2023-01-25T17:32:54 | 2018-10-26T19:49:40 |
Scheme
|
UTF-8
|
Scheme
| false | false | 1,730 |
scm
|
random.scm
|
; Scheme 9 from Empty Space, Function Library
; By Nils M Holm, 2010, 2018
; In the public domain
;
; (random integer) ==> integer
; (random-state integer) ==> procedure
;
; (load-from-library "random.scm")
;
; RANDOM returns a random number in the range [0;INTEGER], where
; INTEGER may not be any larger than 2**19 = 524288.
;
; RANDOM-STATE returns a procedure that resembles RANDOM but uses
; a user-supplied seed instead of a default one. RANDOM can be passed
; a different seed by running:
;
; (set! random (random-state SEED))
;
; RANDOM-STATE uses a 19-bit linear feedback shift register. Hence
; its limited range.
;
; Example: (let* ((a (random 100))
; (b (random 100))
; (c (random 100)))
; (list a b c)) ==> (5 47 68)
(define (random-state . seed)
(let ((seed (if (not (null? seed))
(remainder (car seed) 524288)
#xdead))
(xor (lambda (x y)
(if (eqv? x y) #\0 #\1))))
(lambda (n)
(let* ((v seed)
(bits (number->string seed 2))
(bits (string-append
(make-string (- 19 (string-length bits)) #\0)
bits))
(b0 (string-ref bits 18))
(b1 (string-ref bits 17))
(b2 (string-ref bits 16))
(b3 (string-ref bits 13))
(rot (fold-right xor b3 (list b0 b1 b2)))
(next (string->number
(string-append (string rot)
(substring bits 0 18))
2)))
(set! seed (remainder (+ 1 next) 524288))
(remainder v n)))))
(define random (random-state))
| false |
e1cd1821cf3b8392a8253aad9c9ad571f1bbd526
|
1dfe3abdff4803aee6413c33810f5570d0061783
|
/.chezscheme_libs/spells/filesys/compat.mzscheme.sls
|
2218b64e42357c26d4c9c26279023efe3b759cdb
|
[] |
no_license
|
Saigut/chezscheme-libs
|
73cb315ed146ce2be6ae016b3f86cf3652a657fc
|
1fd12abbcf6414e4d50ac8f61489a73bbfc07b9d
|
refs/heads/master
| 2020-06-12T14:56:35.208313 | 2016-12-11T08:51:15 | 2016-12-11T08:51:15 | 75,801,338 | 6 | 2 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 6,647 |
sls
|
compat.mzscheme.sls
|
;;; compat.mzscheme.sls --- filesys compat library for MzScheme.
;; Copyright (C) 2009, 2010 Andreas Rottmann <[email protected]>
;; Author: Andreas Rottmann <[email protected]>
;; This program is free software, you can redistribute it and/or
;; modify it under the terms of the new-style BSD license.
;; You should have received a copy of the BSD license along with this
;; program. If not, see <http://www.debian.org/misc/bsd.license>.
;;; Commentary:
;;; Code:
#lang scheme/base
(provide (rename-out (spells:file-exists? file-exists?)
(spells:delete-file delete-file))
create-directory
create-symbolic-link
create-hard-link
rename-file
file-regular?
file-directory?
file-symbolic-link?
file-readable?
file-writable?
file-executable?
file-modification-time
file-size-in-bytes
directory-stream?
open-directory-stream
close-directory-stream
read-directory-stream
working-directory
with-working-directory
library-search-paths)
(require srfi/8
(lib "spells/pathname.sls")
(lib "spells/time-lib.sls")
scheme/foreign
(only-in scheme/mpair list->mlist)
(only-in rnrs/io/ports-6
make-i/o-filename-error
make-i/o-file-already-exists-error
make-i/o-file-does-not-exist-error
make-i/o-file-protection-error)
(only-in rnrs/base-6
assertion-violation)
rnrs/records/syntactic-6
rnrs/conditions-6)
(unsafe!)
(define ->fn ->namestring)
(define (spells:file-exists? pathname)
(let ((f (->fn pathname)))
(or (file-exists? f) (directory-exists? f)
(link-exists? f))))
(define (create-directory pathname)
(make-directory (->fn pathname)))
(define (make-link-wrapper who c-name)
(define (lose error-condition)
(raise (condition
(make-who-condition who)
(make-message-condition "OS failure")
error-condition)))
(lambda (old-pathname new-pathname)
(let ((link (get-ffi-obj
c-name
(ffi-lib #f)
(_fun #:save-errno 'posix _string/utf-8 _string/utf-8 -> _int)))
(old-filename (->fn old-pathname))
(new-filename (->fn new-pathname)))
(let ((rv (link old-filename new-filename)))
(unless (= 0 rv)
(case (errno->symbol (saved-errno))
((EACCES)
(lose (make-i/o-file-protection-error new-filename)))
((EEXIST)
(lose (make-i/o-file-already-exists-error new-filename)))
((ENOENT)
(lose (make-i/o-file-does-not-exist-error old-filename)))
(else
(lose (make-i/o-filename-error new-filename)))))))))
(define errno->symbol
(case (system-type 'os)
((unix)
;; This is actually for Linux
(lambda (errno)
(case errno
((13) 'EACCES)
((17) 'EEXIST)
((2) 'ENOENT)
(else #f))))
(else
(assertion-violation 'errno->symbol "unsupported operating system"))))
(define create-symbolic-link
(make-link-wrapper 'create-symbolic-link "symlink"))
(define create-hard-link
(make-link-wrapper 'create-hard-link "link"))
(define (spells:delete-file pathname)
(let ((filename (->fn pathname)))
(with-exn-converter 'delete-file make-i/o-filename-error filename
(lambda ()
(cond ((link-exists? filename)
(delete-file filename))
((directory-exists? filename)
(delete-directory filename))
((file-exists? filename)
(delete-file filename)))))))
(define (rename-file source-pathname target-pathname)
(rename-file-or-directory (->fn source-pathname) (->fn target-pathname) #t))
(define (file-regular? pathname)
(file-exists? (->fn pathname)))
(define (file-symbolic-link? pathname)
(link-exists? (->fn pathname)))
(define (file-directory? pathname)
(directory-exists? (->fn pathname)))
(define (make-file-check permission who)
(lambda (pathname)
(let ((fname (->fn pathname)))
(with-exn-converter who make-i/o-file-does-not-exist-error fname
(lambda ()
(and (memq permission (file-or-directory-permissions fname))
#t))))))
(define (with-exn-converter who error-constructor fname thunk)
(with-handlers
((exn:fail:filesystem?
(lambda (e)
(raise (condition
(make-error)
(make-who-condition who)
(error-constructor fname)
(make-message-condition (exn-message e)))))))
(thunk)))
(define-syntax define-file-check
(syntax-rules ()
((_ id pred)
(define id (make-file-check pred 'id)))))
(define-file-check file-readable? 'read)
(define-file-check file-writable? 'write)
(define-file-check file-executable? 'execute)
(define (file-modification-time pathname)
(let ((fname (->fn pathname)))
(with-exn-converter 'file-modification-time make-i/o-filename-error fname
(lambda ()
(posix-timestamp->time-utc
(file-or-directory-modify-seconds (->fn pathname)))))))
(define (file-size-in-bytes pathname)
(let ((fname (->fn pathname)))
(with-exn-converter 'file-size-in-bytes make-i/o-filename-error fname
(lambda ()
(file-size fname)))))
;; Emulate the stream with a list. TODO: file a wishlist bug on PLT to
;; support a stream API.
(define-record-type directory-stream
(fields (mutable entries)))
(define (open-directory-stream pathname)
(make-directory-stream
(map path->string (directory-list (->fn pathname)))))
(define (close-directory-stream stream)
(directory-stream-entries-set! stream #f))
(define (read-directory-stream stream)
(let ((entries (directory-stream-entries stream)))
(if (null? entries)
#f
(let ((filename (car entries)))
(directory-stream-entries-set! stream (cdr entries))
(if (or (string=? "." filename)
(string=? ".." filename))
(read-directory-stream stream)
filename)))))
(define (working-directory)
(->pathname (current-directory)))
(define (with-working-directory dir thunk)
(let ((wd (current-directory)))
(dynamic-wind
(lambda () (current-directory
(->fn (pathname-as-directory (->pathname dir)))))
thunk
(lambda () (current-directory wd)))))
(define (library-search-paths)
(list->mlist (current-library-collection-paths)))
| true |
144369317170f3fac071796bb0f2a83176a28062
|
6f7df1f0361204fb0ca039ccbff8f26335a45cd2
|
/scheme/ikarus/flonum-parser.sls
|
8f2688f6bff53681b1c4ec807e811db125ce8baa
|
[] |
no_license
|
LFY/bpm
|
f63c050d8a2080793cf270b03e6cf5661bf3599e
|
a3bce19d6258ad42dce6ffd4746570f0644a51b9
|
refs/heads/master
| 2021-01-18T13:04:03.191094 | 2012-09-25T10:31:25 | 2012-09-25T10:31:25 | 2,099,550 | 2 | 0 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 5,952 |
sls
|
flonum-parser.sls
|
;;; The code here is extracted from
;;; ``Printing Floating-Point Numbers Quickly and Accurately''
;;; http://www.cs.indiana.edu/~burger/FP-Printing-PLDI96.pdf
;;; It is believed to be in the public domain.
;;; The copyright below is for the R6RS implementation not part
;;; of the original work.
;;; Copyright (c) 2009 Abdulaziz Ghuloum
;;; Modified by Marco Maggi
;;;
;;; Permission is hereby granted, free of charge, to any person obtaining a
;;; copy of this software and associated documentation files (the "Software"),
;;; to deal in the Software without restriction, including without limitation
;;; the rights to use, copy, modify, merge, publish, distribute, sublicense,
;;; and/or sell copies of the Software, and to permit persons to whom the
;;; Software is furnished to do so, subject to the following conditions:
;;;
;;; The above copyright notice and this permission notice shall be included in
;;; all copies or substantial portions of the Software.
;;;
;;; 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.
;;; (parse-flonum <fl>
;;; (lambda (positive? digits:list-of-chars exponent:int)
;;; ---)
;;; (lambda (inf/nan:string)
;;; ---))
;;; calls one of the two procedures depending on whether the
;;; number has a real value or not.
(library (ikarus flonum-parser)
(export parse-flonum)
(import (rnrs))
(define fxsll fxarithmetic-shift-left)
(define fxsra fxarithmetic-shift-right)
(define (flonum-bytes f k)
(let ([bv (make-bytevector 8)])
(bytevector-ieee-double-set! bv 0 f (endianness big))
(k (bytevector-u8-ref bv 0)
(bytevector-u8-ref bv 1)
(bytevector-u8-ref bv 2)
(bytevector-u8-ref bv 3)
(bytevector-u8-ref bv 4)
(bytevector-u8-ref bv 5)
(bytevector-u8-ref bv 6)
(bytevector-u8-ref bv 7))))
(define (flonum-parts x)
(flonum-bytes x
(lambda (b0 b1 b2 b3 b4 b5 b6 b7)
(values
(zero? (fxand b0 128))
(+ (fxsll (fxand b0 127) 4)
(fxsra b1 4))
(+ (+ b7 (fxsll b6 8) (fxsll b5 16))
(* (+ b4
(fxsll b3 8)
(fxsll b2 16)
(fxsll (fxand b1 #b1111) 24))
(expt 2 24)))))))
(define flonum->digits
(lambda (f e min-e p b B)
;;; flonum v = f * b^e
;;; p = precision (p >= 1)
(let ([round? (even? f)])
(if (>= e 0)
(if (not (= f (expt b (- p 1))))
(let ([be (expt b e)])
(scale (* f be 2) 2 be be 0 B round? f e))
(let* ([be (expt b e)] [be1 (* be b)])
(scale (* f be1 2) (* b 2) be1 be 0 B round? f e)))
(if (or (= e min-e) (not (= f (expt b (- p 1)))))
(scale (* f 2) (* (expt b (- e)) 2) 1 1 0 B round? f e)
(scale (* f b 2) (* (expt b (- 1 e)) 2) b 1 0 B round? f e))))))
(define (len n)
(let f ([n n] [i 0])
(cond
[(zero? n) i]
[else (f (div n 2) (+ i 1))])))
(define scale
(lambda (r s m+ m- k B round? f e)
(let ([est (exact
(ceiling
(- (* (+ e (len f) -1) (invlog2of B))
1e-10)))])
(if (>= est 0)
(fixup r (* s (exptt B est)) m+ m- est B round?)
(let ([scale (exptt B (- est))])
(fixup (* r scale) s (* m+ scale) (* m- scale) est B round?))))))
(define fixup
(lambda (r s m+ m- k B round?)
(if ((if round? >= >) (+ r m+) s) ; too low?
(values (+ k 1) (generate r s m+ m- B round?))
(values k (generate (* r B) s (* m+ B) (* m- B) B round?)))))
(define (chr x)
(vector-ref '#(#\0 #\1 #\2 #\3 #\4 #\5 #\6 #\7 #\8 #\9) x))
(define generate
(lambda (r s m+ m- B round?)
(let-values ([(q r) (div-and-mod r s)])
(let ([tc1 ((if round? <= <) r m-)]
[tc2 ((if round? >= >) (+ r m+) s)])
(if (not tc1)
(if (not tc2)
(cons (chr q) (generate (* r B) s (* m+ B) (* m- B) B round?))
(list (chr (+ q 1))))
(if (not tc2)
(list (chr q))
(if (< (* r 2) s)
(list (chr q))
(list (chr (+ q 1))))))))))
(define invlog2of
(let ([table (make-vector 37)]
[log2 (log 2)])
(do ([B 2 (+ B 1)])
((= B 37))
(vector-set! table B (/ log2 (log B))))
(lambda (B)
(if (<= 2 B 36)
(vector-ref table B)
(/ log2 (log B))))))
(define exptt
(let ([table (make-vector 326)])
(do ([k 0 (+ k 1)] [v 1 (* v 10)])
((= k 326))
(vector-set! table k v))
(lambda (B k)
(if (and (= B 10) (<= 0 k 325))
(vector-ref table k)
(expt B k)))))
(define (convert-real-flonum pos? m e p k)
(let-values ([(expt digits) (flonum->digits m e 10 p 2 10)])
(k pos? digits expt)))
(define (parse-flonum x k0 k1)
(assert (flonum? x))
(assert (procedure? k0))
(assert (procedure? k1))
(let-values ([(pos? be m) (flonum-parts x)])
(cond
[(<= 1 be 2046) ; normalized flonum
(convert-real-flonum pos? (+ m (expt 2 52)) (- be 1075) 53 k0)]
[(= be 0)
(convert-real-flonum pos? m -1074 52 k0)]
[(= be 2047)
(k1 (if (= m 0) (if pos? "+inf.0" "-inf.0") "+nan.0"))]
[else (error 'flonum->string "cannot happen")]))))
| false |
58b35c3eb9c6164c0c205f13084dbb48f3bc316b
|
bdfa935097ef39f66c7f18856accef422ef39128
|
/parts/qa0/tree/scheme/qa0.ss
|
5bcbdf17fded3f107204eeb4c411f5cf421fcfe9
|
[
"MIT"
] |
permissive
|
djm2131/qlua
|
213f5ed4b692b1b03d2ff1a78d09ea9d2d9fe244
|
737bfe85228dac5e9ae9eaab2b5331630703ae73
|
refs/heads/master
| 2020-04-18T15:01:06.117689 | 2019-02-06T15:23:27 | 2019-02-06T15:23:27 | 162,349,914 | 0 | 0 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 6,012 |
ss
|
qa0.ss
|
;; QA0 driver
#fload "sfc.sf"
#fload "common.sf"
#fload "error.ss"
#fload "print.ss"
#fload "cheader.ss"
#fload "backend.ss"
#fload "parser.ss"
#fload "cfold.ss"
#fload "q2complex.ss"
#fload "c2real.ss"
#fload "cx2qh.ss"
#fload "qa0print.ss"
#fload "be-c99.ss"
#fload "be-c99-64.ss"
#fload "be-dry.ss"
#fload "be-bgq-xlc.ss"
;;
;; (provide qa0-driver)
;;
(define qa0-driver
(let ()
(define *version* "Version qit tree")
(define (do-help arg*)
(for-each (lambda (cdf) (q-print "\t~a\t~a~%" (car cdf) (cadr cdf)))
cmd*))
(define (la-compilier arg* machine front back)
(if (not (= (vector-length arg*) 4))
(s-error "bad arguments"))
(let* ([d/f (vector-ref arg* 1)]
[output (vector-ref arg* 2)]
[input (vector-ref arg* 3)]
[d/f (cond
[(string=? d/f "double") 'double]
[(string=? d/f "float") 'float]
[else (s-error "Unexpected value for d/f: ~a" d/f)])])
(define (run-me)
(q-print "/* automagically generated by qa0 ~a */~%" *version*)
(front input machine d/f back))
(if (string=? output "-")
(run-me)
(begin
(if (file-exists? output) (delete-file output))
(with-output-to-file output run-me)))))
(define (do-header arg*)
(la-compilier arg* machine-c99-32 qa0-compile c-header))
(define (do-cee arg*)
(la-compilier arg* machine-c99-32 qa0-real-compile emit-back-end))
(define (do-cee-64 arg*)
(la-compilier arg* machine-c99-64 qa0-real-compile emit-back-end))
(define (do-c99 arg*)
(la-compilier arg* machine-c99-32 qa0-compile emit-back-end))
(define (do-c99-64 arg*)
(la-compilier arg* machine-c99-64 qa0-compile emit-back-end))
(define (do-dry arg*)
(la-compilier arg* machine-dry qa0-compile emit-back-end))
(define (do-bgq/xlc arg*)
(la-compilier arg* machine-bgq/xlc qa0-compile emit-back-end))
(define (print-tree/env ast env) (print-tree ast))
(define (do-version arg*)
(q-print "qa0: ~a~%" *version*))
(define (do-macro arg*)
(la-compilier arg* machine-c99-32 qa0-macro print-tree/env))
(define (do-c-expand arg*)
(la-compilier arg* machine-c99-32 qa0-c-expand print-tree/env))
(define (do-r-expand arg*)
(la-compilier arg* machine-c99-32 qa0-r-expand print-tree/env))
(define (do-qhexpand arg*)
(la-compilier arg* machine-bgq/xlc qa0-qhexpand print-tree/env))
(define (qa0-macro name machine d/f back-end)
(let-values* ([ast (parse-qa0-file name)]
[(ast env) (fold-constants/env ast machine d/f)])
(back-end ast env)))
(define (qa0-c-expand name machine d/f back-end)
(qa0-macro name machine d/f
(lambda (ast env)
(let-values* ([(ast e-x) (qcd->complex ast env)])
(back-end ast env)))))
(define (qa0-r-expand name machine d/f back-end)
(qa0-macro name machine d/f
(lambda (ast env)
(let-values* ([(ast e-x) (qcd->complex ast env)]
[(ast e-x) (complex->real ast env)])
(back-end ast env)))))
(define (qa0-dhexpand name machine d/f back-end)
(qa0-c-expand name machine d/f
(lambda (ast env)
(let ([ast (complex->double-hummer ast)])
(back-end ast env)))))
(define (qa0-qhexpand name machine d/f back-end)
(qa0-c-expand name machine d/f
(lambda (ast env)
(let ([ast (complex->quad-hummer ast)])
(back-end ast env)))))
(define (qa0-compile name machine d/f back-end)
(qa0-c-expand name machine d/f
(lambda (ast env)
(let-values* ([(ast env) (complex->back-end ast env)])
(back-end ast env)))))
(define (qa0-real-compile name machine d/f back-end)
(qa0-c-expand name machine d/f
(lambda (ast env)
(let-values* ([(ast env) (complex->real ast env)]
[(ast env) (complex->back-end ast env)])
(back-end ast env)))))
(define cmd*
(list
(list "help" " print available commands" do-help)
(list "header" "d/f out in build .h file for double/float" do-header)
(list "cee-64" "d/f out in build .c file for double/float" do-cee-64)
(list "cee-32" "d/f out in build .c file for double/float" do-cee)
(list "cee" "d/f out in same as cee-32" do-cee)
(list "c99-64" "d/f out in build .c file for double/float" do-c99-64)
(list "c99-32" "d/f out in build .c file for double/float" do-c99)
(list "c99" "d/f out in same as c99-32" do-c99)
(list "dry" "d/f out in build .c file for dry version" do-dry)
(list "bgq/xlc" "d/f out in build .c file for XLC on BG/Q" do-bgq/xlc)
(list "macro" "d/f out in do constant folding only" do-macro)
(list "complex" "d/f out in convert to complex only" do-c-expand)
(list "real" "d/f out in convert to real only" do-r-expand)
(list "qhummer" "d/f out in convert to QH only" do-qhexpand)
(list "version" " print qa0 version" do-version)))
(define (dispatch name arg*)
(let loop ([cmd* cmd*])
(cond
[(null? cmd*) (q-print "qa0: Unknown command ~s. Try saying qa0 help~%"
name)]
[(string=? name (caar cmd*)) ((caddar cmd*) arg*)]
[else (loop (cdr cmd*))])))
(lambda (args)
(if (zero? (vector-length args))
(dispatch "help" '#("help"))
(dispatch (vector-ref args 0) args)))))
| false |
22ec6b7c5ecd4a45c56c935b1fb9e529d9a327a8
|
8d2197af6ab9abe4e7767b424499aeae2331e3f6
|
/examples/outputs/verydep/unerased.scm
|
f2a4387f4a2cfc931398e2eaadb43961c29e4ba6
|
[] |
permissive
|
ziman/ttstar
|
ade772d6dd2b31b40b736bd36bd9ef585bd0d389
|
4ac6e124bddfbeaa133713d829dccaa596626be6
|
refs/heads/master
| 2021-09-08T23:20:19.446353 | 2019-06-30T19:17:02 | 2019-06-30T19:17:02 | 35,721,993 | 19 | 1 |
BSD-3-Clause
| 2022-08-09T13:28:36 | 2015-05-16T11:58:56 |
Idris
|
UTF-8
|
Scheme
| false | false | 936 |
scm
|
unerased.scm
|
(import (chicken process-context))
(require-extension matchable)
(define Type '(Type))
(define (number->peano z s i) (if (= i 0) (list z) (list s (number->peano z s (- i 1)))))
(define (rts-arg-peano z s i) (number->peano z s (string->number (list-ref (command-line-arguments) i))))
(define (rts-arg-read i) (read (open-input-string (list-ref (command-line-arguments) i))))
(print
(letrec* (
(Void `(Void))
(Maybe (lambda (_x0)
`(Maybe ,_x0)))
(Just (lambda (a)
(lambda (x)
`(Just ,a ,x))))
(Nothing (lambda (a)
`(Nothing ,a)))
(Bool `(Bool))
(True `(True))
(False `(False))
(retTy (lambda (_e0)
(match (list _e0)
((('Just _ t))
Bool)
((('Nothing _))
Type))))
(f (lambda (_e0)
(match (list _e0)
((('Just _ b))
b)
((('Nothing _))
Bool))))
(main (f ((Just Bool) False)))
)
main))
| false |
4255182ba400bbf449fb286c57bb680a3c2281e3
|
0011048749c119b688ec878ec47dad7cd8dd00ec
|
/src/052/solution.scm
|
7f90093ddc584677b4a2e8a315d89824732d4220
|
[
"0BSD"
] |
permissive
|
turquoise-hexagon/euler
|
e1fb355a44d9d5f9aef168afdf6d7cd72bd5bfa5
|
852ae494770d1c70cd2621d51d6f1b8bd249413c
|
refs/heads/master
| 2023-08-08T21:01:01.408876 | 2023-07-28T21:30:54 | 2023-07-28T21:30:54 | 240,263,031 | 8 | 0 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 835 |
scm
|
solution.scm
|
(import
(chicken fixnum))
(define-syntax helper!
(syntax-rules ()
((_ n acc increment)
(let loop ((n n))
(unless (fx= n 0)
(let ((_ (fxmod n 10)))
(vector-set! acc _ (fx+ (vector-ref acc _) increment)))
(loop (fx/ n 10)))))))
(define (permutation? a b)
(let ((acc (make-vector 10 0)))
(helper! a acc +1)
(helper! b acc -1)
(let loop ((i 0))
(if (fx= i 10)
#t
(if (fx= (vector-ref acc i) 0)
(loop (fx+ i 1))
#f)))))
(define (valid? n l)
(let loop ((i 2) (s (fx+ n n)))
(if (fx> i l)
#t
(if (permutation? n s)
(loop (fx+ i 1) (fx+ s n))
#f))))
(define (solve l)
(let loop ((i 1))
(if (valid? i l)
i
(loop (fx+ i 1)))))
(let ((_ (solve 6)))
(print _) (assert (= _ 142857)))
| true |
abafce94077c9f38f640f042801bb5d78506420c
|
a3cdbdb1ca94558ae7412829a3fd61f00987e4dc
|
/examples/example.scm
|
a583c10420bee40cc0eeeb7229c9f06063464c93
|
[
"BSD-2-Clause"
] |
permissive
|
jyc/raisin-guile
|
f8322cd59ff60166733f2569e91b4efabf0804cc
|
0a6362b1999956367b1523f81940f80b62a1da92
|
refs/heads/master
| 2020-07-30T13:33:30.233902 | 2016-02-07T03:41:39 | 2016-02-07T03:41:39 | 210,251,389 | 0 | 0 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 1,277 |
scm
|
example.scm
|
(define-module (jyc raisin example))
(load "../raisin.scm")
(include "../debug.scm")
(use-modules
(jyc raisin)
(srfi srfi-18))
(define i (new-ivar))
(define d (ivar-read i))
(write (peek d))
(newline)
(ivar-fill! i "hi")
(write (peek d))
(newline)
(define (print . args)
(display (apply format #f args)))
(print "Starting...~%")
(>>= (after 1.5)
(lambda (_) (print "A (around 1.5 seconds after start)~%") (return "A"))
(lambda (x) (print "B (this should be A: ~A~%" x) (return '()))
(lambda (_) (after 3.5))
(lambda (_) (print "C (around 5 seconds after start!)~%") (return '())))
;(seq (after 1.5)
; x <* ((print "A (around 1.5 seconds after start)~%") "A")
; ** ((print "B (this should be A: ~A~%" x))
; (after 3.5)
; ** ((print "C (around 5 seconds after start!)~%")))
; Need to run this in a separate thread or Guile will run us in the same thread
; as the Raisin scheduler. The Raisin scheduler might be blocked on a
; condition, which it doesn't seem we can signal when we are on the same
; thread.
(call-with-new-thread
(lambda ()
(sigaction SIGINT
(lambda (sig)
(scheduler-stop!)))
(let loop ()
(sleep 1)
(loop))))
(scheduler-start! #:on-stop (lambda () (print "Stopped.~%")))
| false |
91fbc6baca055f3f4ccd381d3e33f1460a16d8ee
|
763ce7166523c52b12d92ad48150e6e29dae22f3
|
/motor.scm
|
9f1fd826abfa4a3c8a77dbc7f4d6278e9621fdbb
|
[] |
no_license
|
seandepagnier/cruisingplot
|
3cdbe87789267de0a1f8ca8354215167b334f51b
|
d3d83e7372e2c5ce1a8e8071286e30c2028088cf
|
refs/heads/master
| 2020-03-29T18:19:13.647065 | 2013-11-13T03:14:11 | 2013-11-13T03:14:11 | 5,801,818 | 6 | 2 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 6,146 |
scm
|
motor.scm
|
;; Copyright (C) 2011 Sean D'Epagnier <[email protected]>
;;
;; This Program is free software; you can redistribute it and/or
;; modify it under the terms of the GNU General Public
;; License as published by the Free Software Foundation; either
;; version 3 of the License, or (at your option) any later version.
; very simple motor control driver where ascii number is sent over a serial port
; command a motor for a specified number of milliseconds (+ or - for forward
; or backwards)
(declare (unit motor))
(define (create-motor-options)
(create-options
`(,(make-string-verifier 'motordevice "serial device of motor" "none")
,(make-baud-verifier 'serialbaud "serial baud rate to use" 9600)
,(make-number-verifier 'min-motor-duty "minimum duty cycle" 0 0 1)
,(make-number-verifier 'max-motor-duty "maximum duty cycle" .5 0 10)
)
"no examples" #f))
(define (motor-open motor-options motor-button)
(let-values (((motor-input motor-output)
(if (equal? (motor-options 'motordevice) "none")
(values #f #f)
(open-serial-device (motor-options 'motordevice) (motor-options 'serialbaud)))))
(let ((motor (list motor-input motor-output motor-options 'stopped default-motor-calibration)))
(motor-command motor 0) ; stop motor and flush buffer
(if motor-input
(make-line-reader motor-input
(lambda (line)
(cond ((eof-object? line)
(print "motor device closed unexpectedly")
(task-sleep 1)
(let ((new-motor (motor-open motor-options)))
(set-car! motor (car new-motor))
(set-cdr! motor (cdr new-motor))
(task-exit)))
((string= "o" line) (print "overflow in motor buffer"))
((string= "f" line) (print "overflow in duty cycle"))
((string= "u" line) (print "underflow in duty cycle"))
((string= "p" line) (motor-command 'port))
((string= "P" line) (motor-command 'port-long))
((string= "s" line) (motor-command 'starboard))
((string= "S" line) (motor-command 'starboard-long))
((string= "k" line) 'ok)
((string= "i" line) (print "invalid command to motor"))
((string= "e" line)
(print "motor reached end")
(motor-set-state! motor 'stopped))
(else
(print "got from motor unhandled message: " line))))))
motor)))
(define motor-input first)
(define motor-output second)
(define motor-options third)
(define motor-state fourth)
(define motor-calibration fifth)
; simrad hacked
;(define default-motor-calibration '(0 7.8824 0.8861 21.49))
(define default-motor-calibration '(0 1 0 0))
(define (motor-apply-calibration calibration velocity)
(+ (first calibration)
(* (second calibration) velocity)
(* (third calibration) (square velocity))
(* (fourth calibration) (cube velocity))))
(define (motor-set-state! motor state)
(set-car! (cdddr motor) state))
; state can be:
; 'moving - moving at last command
; 'stopped - reached the end
; command motor to turn at a given rate (or duty cycle)
(define (motor-command motor duty)
(let ((command (inexact->exact (round (* 100 duty)))))
(verbose "autopilot motor command: " command)
(cond ((motor-output motor)
(write command (motor-output motor))
(newline (motor-output motor))
(flush-output (motor-output motor))
(motor-set-state! motor (if (zero? duty) 'stopped 'moving))))))
; calibrated motor can be commanded in velocity
(define (motor-command-velocity motor velocity)
(motor-command motor
(let ((calduty (motor-apply-calibration (motor-calibration motor) velocity))
(minduty ((motor-options motor) 'min-motor-duty))
(maxduty ((motor-options motor) 'max-motor-duty)))
(cond ((> (abs calduty) maxduty) (* (/ calduty (abs calduty)) maxduty))
((< (abs calduty) minduty) 0)
(else calduty)))))
; run motor at various speeds to full stops
; alternating direction to build a lookup table
; to calibrate out linearities.
;
; distance / time = velocity
; normalized distance of 1
; velocity = 1 / time
; duty * cal[duty] = velocity
(define (calibrate-motor motor)
(let ((raw-points
(let ((duty-width (- ((motor-options motor) 'max-motor-duty)
((motor-options motor) 'min-motor-duty)))
(count 4))
(let each-speed ((index -1) (sign -1))
(cond ((< index count)
(let ((timer (start-timer)))
(let ((duty (if (negative? index) sign
(* sign (+ ((motor-options motor) 'min-motor-duty)
(* index (/ duty-width (- count 1))))))))
(motor-command motor duty)
(print "waiting until end for duty " duty)
(let wait-for-it ()
(cond ((eq? (motor-state motor) 'moving)
(task-sleep .01)
(wait-for-it))
(else
(cons (list (/ sign (timer)) duty)
(each-speed (+ index (if (negative? sign) 1 0)) (- sign)))))))))
(else '()))))))
; remove first point (getting in position negative index) and add zero point
(let ((points (cons '(0 0) (cdr raw-points))))
(print "points " points)
(polynomial-regression points 5))))
| false |
05f49dc74132c908389343f504f348c6ec89e91f
|
6f7df1f0361204fb0ca039ccbff8f26335a45cd2
|
/pyxml2prog/pyxml2prog/SSAX/sxpath-tests.scm
|
0b76946d0eb6d9bafceb397365a52e395358c517
|
[] |
no_license
|
LFY/bpm
|
f63c050d8a2080793cf270b03e6cf5661bf3599e
|
a3bce19d6258ad42dce6ffd4746570f0644a51b9
|
refs/heads/master
| 2021-01-18T13:04:03.191094 | 2012-09-25T10:31:25 | 2012-09-25T10:31:25 | 2,099,550 | 2 | 0 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 65 |
scm
|
sxpath-tests.scm
|
(pp ([sxpath '(doc)]
'(*TOP* (doc (title "Hello world")))))
| false |
d678678647da7cd7cd9b1d58e3474656c1964147
|
4be45ef698d2e842b222a537cdbb28cdbb036c5f
|
/game/game.scm
|
1513a487ff3be4ab30508ea6991fbab071a429bd
|
[] |
no_license
|
Orkie/schemup
|
c7a21d65561be99b7d215e88ab992b82111fd2ab
|
fbd36b8c56bd35e458b0eb9d39c40384305f248f
|
refs/heads/master
| 2020-07-26T00:54:51.105612 | 2014-01-12T20:02:35 | 2014-01-12T20:02:35 | 208,478,531 | 0 | 0 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 260 |
scm
|
game.scm
|
(define-module (game game)
#:export (make-game-initial-scene game-name))
(use-modules (stdlib print)
(game title))
(define game-name "Schemup")
;; create the initial scene for the game
(define (make-game-initial-scene)
(make-title-scene))
| false |
5b10593fed785423d99934a548d091bddfa6808f
|
cfa60b41f70f07dcb6e2d4b637c71593779088ca
|
/awful-blog.meta
|
be256393e3e09a4021e76d89e6c1d2a2f702d28b
|
[] |
no_license
|
hugoArregui/awful-blog
|
01b815ff2e898df271ed75781195900f40ef2aef
|
3ba5027ad22cd784208e6e6c5726077d4e5406c6
|
refs/heads/master
| 2021-03-12T19:21:36.522488 | 2016-08-28T23:35:24 | 2016-08-28T23:35:24 | 11,226,846 | 0 | 0 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 234 |
meta
|
awful-blog.meta
|
;; -*- scheme -*-
((license "BSD License")
(category web)
(needs awful matchable traversal lowdown html-parser)
(test-depends server-test test http-client)
(author "Hugo Arregui")
(synopsis "Blog tool for awful web framework"))
| false |
bd1c9e53c9526c2b55f28a2bb7947022ed208790
|
defeada37d39bca09ef76f66f38683754c0a6aa0
|
/System/system/code-dom/compiler/compiler-error.sls
|
032b70d4e987249d11ed732412b7e87f00a2f4ad
|
[] |
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,041 |
sls
|
compiler-error.sls
|
(library (system code-dom compiler compiler-error)
(export new
is?
compiler-error?
to-string
line-get
line-set!
line-update!
column-get
column-set!
column-update!
error-number-get
error-number-set!
error-number-update!
error-text-get
error-text-set!
error-text-update!
is-warning?-get
is-warning?-set!
is-warning?-update!
file-name-get
file-name-set!
file-name-update!)
(import (ironscheme-clr-port))
(define-syntax new
(lambda (e)
(syntax-case e ()
((_ a ...)
#'(clr-new System.CodeDom.Compiler.CompilerError a ...)))))
(define (is? a) (clr-is System.CodeDom.Compiler.CompilerError a))
(define (compiler-error? a)
(clr-is System.CodeDom.Compiler.CompilerError a))
(define-method-port
to-string
System.CodeDom.Compiler.CompilerError
ToString
(System.String))
(define-field-port
line-get
line-set!
line-update!
(property:)
System.CodeDom.Compiler.CompilerError
Line
System.Int32)
(define-field-port
column-get
column-set!
column-update!
(property:)
System.CodeDom.Compiler.CompilerError
Column
System.Int32)
(define-field-port
error-number-get
error-number-set!
error-number-update!
(property:)
System.CodeDom.Compiler.CompilerError
ErrorNumber
System.String)
(define-field-port
error-text-get
error-text-set!
error-text-update!
(property:)
System.CodeDom.Compiler.CompilerError
ErrorText
System.String)
(define-field-port
is-warning?-get
is-warning?-set!
is-warning?-update!
(property:)
System.CodeDom.Compiler.CompilerError
IsWarning
System.Boolean)
(define-field-port
file-name-get
file-name-set!
file-name-update!
(property:)
System.CodeDom.Compiler.CompilerError
FileName
System.String))
| true |
dd087ec6f4804512435a9a134bc4b5e659f8df7b
|
8a0660bd8d588f94aa429050bb8d32c9cd4290d5
|
/sitelib/rfc/x.509.scm
|
9d905f78d695007a76de295c321ec2a286f5cbdc
|
[
"BSD-2-Clause"
] |
permissive
|
david135/sagittarius-scheme
|
dbec76f6b227f79713169985fc16ce763c889472
|
2fbd9d153c82e2aa342bfddd59ed54d43c5a7506
|
refs/heads/master
| 2016-09-02T02:44:31.668025 | 2013-12-21T07:24:08 | 2013-12-21T07:24:08 | 32,497,456 | 0 | 0 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 24,578 |
scm
|
x.509.scm
|
;;; -*- mode:scheme; coding:utf-8; -*-
;;;
;;; rfc/x.509 - X.509 certificate utility library.
;;;
;;; Copyright (c) 2010-2013 Takashi Kato <[email protected]>
;;;
;;; Redistribution and use in source and binary forms, with or without
;;; modification, are permitted provided that the following conditions
;;; are met:
;;;
;;; 1. Redistributions of source code must retain the above copyright
;;; notice, this list of conditions and the following disclaimer.
;;;
;;; 2. Redistributions in binary form must reproduce the above copyright
;;; notice, this list of conditions and the following disclaimer in the
;;; documentation and/or other materials provided with the distribution.
;;;
;;; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
;;; "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
;;; LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
;;; A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
;;; OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
;;; SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
;;; TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
;;; PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
;;; LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
;;; NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
;;; SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
;;;
(library (rfc x.509)
(export make-x509-certificate
x509-certificate?
x509-certificate->bytevector
<x509-certificate>
x509-certificate-get-version
x509-certificate-get-serial-number
x509-certificate-get-issuer-dn
x509-certificate-get-subject-dn
x509-certificate-get-not-before
x509-certificate-get-not-after
x509-certificate-get-signature
x509-certificate-get-signature-algorithm
x509-certificate-get-public-key
verify
check-validity
;; certificate generation
make-x509-issuer
make-validity
make-x509-basic-certificate)
(import (rnrs)
(rnrs mutable-strings)
(clos user)
(sagittarius)
(sagittarius control)
(sagittarius object)
(rename (crypto) (verify crypto:verify))
(srfi :19 time)
(srfi :26 cut)
(math)
(asn.1))
;; these might be somewhere
(define-class <rdn> (<asn.1-encodable>)
((values :init-keyword :values)))
(define-method make-rdn ((s <asn.1-set>))
(make <rdn> :values s))
(define-method make-rdn ((oid <der-object-identifier>) (name <string>))
(let1 seq (make-der-sequence oid (make-der-printable-string name #t))
(make <rdn> :values (make-der-set seq))))
(define (rdn-get-types-and-values rdn)
(map (lambda (p)
(cons (asn.1-sequence-get p 0) (asn.1-sequence-get p 1)))
(~ rdn 'values 'set)))
(define (rdn-get-first rdn)
(let ((p (asn.1-set-get (~ rdn 'values) 0)))
(cons (asn.1-sequence-get p 0) (asn.1-sequence-get p 1))))
(define-method object-equal? ((a <rdn>) (b <rdn>))
;; unfortunately ASN.1 serise aren't implemented with object-equal?
;; so we need to compare encoded bytevector
(bytevector=? (encode (~ a 'values)) (encode (~ b 'values))))
(define *default-symbols*
`((,(make-der-object-identifier "2.5.4.6") . C)
(,(make-der-object-identifier "2.5.4.10") . O)
(,(make-der-object-identifier "2.5.4.11") . OU)
(,(make-der-object-identifier "2.5.4.3") . CN)
(,(make-der-object-identifier "2.5.4.7") . L)
(,(make-der-object-identifier "2.5.4.5") . SERIALNUMER)
(,(make-der-object-identifier "1.2.840.113549.1.9.1") . E)
(,(make-der-object-identifier "0.9.2342.19200300.100.1.25") . DC)
(,(make-der-object-identifier "0.9.2342.19200300.100.1.1") . UID)
(,(make-der-object-identifier "2.5.4.9") . STREET)
(,(make-der-object-identifier "2.5.4.4") . SURNAME)
(,(make-der-object-identifier "2.5.4.44") . GENERATION)
(,(make-der-object-identifier "2.5.4.26") . DN)
(,(make-der-object-identifier "2.5.4.42") . GIVENNAME)))
(define-class <x500-name> (<asn.1-encodable>)
((style :init-keyword :style :init-value #f)
(rdns :init-keyword :rdns)))
(define-method make-x500-name ((s <asn.1-sequence>))
(let* ((len (asn.1-sequence-size s))
(rdns (make-vector len)))
(dotimes (i len)
(vector-set! rdns i (make-rdn (asn.1-sequence-get s i))))
(make <x500-name> :rdns rdns)))
(define-method asn.1-encodable->asn.1-object ((o <x500-name>))
(apply make-der-sequence (vector->list (~ o 'rdns))))
(define-method write-object ((o <x500-name>) p)
(define (print-type-and-value p out)
(let ((type (car p))
(value (cdr p)))
(cond ((assoc type *default-symbols*) =>
(lambda (slot) (display (cdr slot) out)))
(else
(display (~ type 'identifier) out)))
(display #\= out)
(if (and (is-a? value <asn.1-string>)
(not (is-a? value <der-universal-string>)))
(display (asn.1-string->string value) out)
(display value out))))
(define (print-rdn rdn out)
(let* ((set (~ rdn 'values))
(len (asn.1-set-size set)))
(if (> len 1)
(let ((atv (rdn-get-types-and-values rdn)))
(unless (null? atv)
(print-type-and-value (car atv) out)
(for-each (lambda (at)
(display #\, out)
(print-type-and-value at out)) (cdr atv))))
(print-type-and-value (rdn-get-first rdn) out))))
(let ((buf (call-with-string-output-port
(lambda (out)
(let ((rdns (vector->list (~ o 'rdns))))
(unless (null? rdns)
(print-rdn (car rdns) out)
(for-each (lambda (rdn)
(display #\, out)
(print-rdn rdn out))
(cdr rdns))))))))
(display buf p)))
(define-method object-equal? ((a <x500-name>) (b <x500-name>))
(and (equal? (~ a 'style) (~ b 'style))
(equal? (~ a 'rdns) (~ b 'rdns))))
;; base on boucycasle's x509 package.
(define-class <algorithm-identifier> (<asn.1-encodable>)
((object-id :init-keyword :object-id)
(parameters :init-keyword :parameters :init-value #f)
(parameters-defined? :init-keyword :defined? :init-value #f)))
(define-method make-algorithm-identifier ((o <der-object-identifier>))
(make <algorithm-identifier> :object-id o))
(define-method make-algorithm-identifier ((s <asn.1-sequence>))
(let ((len (asn.1-sequence-size s)))
(unless (<= 1 len 2)
(assertion-violation 'make-algorithm-identifier
"bad sequence size" len))
(if (= len 2)
(make <algorithm-identifier>
:object-id (asn.1-sequence-get s 0)
:parameters (asn.1-sequence-get s 1)
:defined? #t)
(make <algorithm-identifier>
:object-id (asn.1-sequence-get s 0)))))
(define-method get-id ((id <algorithm-identifier>))
(~ id 'object-id 'identifier))
(define-method der-encode ((id <algorithm-identifier>) out)
(if (~ id 'parameters-defined?)
(der-encode (make-der-sequence (~ id 'object-id)
(~ id 'parameters)) out)
(der-encode (make-der-sequence (~ id 'object-id) (make-der-null)) out)))
(define-class <x509-principal> (<x500-name>) ())
(define-method make-x509-principal ((o <x500-name>))
(make <x509-principal> :rdns (~ o 'rdns)))
(define-class <x509-time> (<asn.1-encodable>)
((time :init-keyword :time)))
(define-method make-x509-time ((o <der-utc-time>))
(make <x509-time> :time o))
(define-method make-x509-time ((o <der-generalized-time>))
(make <x509-time> :time o))
(define-method x509-time->date ((o <x509-time>))
(der-time->date (~ o 'time)))
(define-class <x509-extension> (<asn.1-encodable>)
((critical :init-keyword :critical)
(value :init-keyword :value)))
(define-method make-x509-extension ((critical <der-boolean>)
(value <asn.1-octet-string>))
(make-x509-extension (der-boolean->boolean critical) value))
(define-method make-x509-extension ((critical <boolean>)
(value <asn.1-octet-string>))
(make <x509-extension> :critical critical :value value))
(define-class <x509-extensions> (<asn.1-encodable>)
((extensions :init-keyword :extensions)))
(define-method make-x509-extensions ((o <asn.1-tagged-object>))
(make-x509-extensions (der-encodable->der-object o)))
(define-method make-x509-extensions ((o <asn.1-sequence>))
(let ((extensions
(map (lambda (e)
(case (asn.1-sequence-size e)
((3)
(cons (asn.1-sequence-get e 0)
(make-x509-extension (asn.1-sequence-get e 1)
(asn.1-sequence-get e 2))))
((2)
(cons (asn.1-sequence-get e 0)
(make-x509-extension #f (asn.1-sequence-get e 1))))
(else
=> (lambda (size)
(assertion-violation 'make-x509-extensions
"bas sequense size" size)))))
(~ o 'sequence))))
(make <x509-extensions> :extensions extensions)))
(define-method get-x509-extension ((o <x509-extensions>)
(oid <der-object-identifier>))
(and-let* ((ext (assoc oid (~ o 'extensions))))
(cdr ext)))
(define-class <subject-public-key-info> (<asn.1-encodable>)
((algorithm-identifier :init-keyword :algorithm-identifier)
(key-data :init-keyword :key-data)))
(define-method make-subject-public-key-info ((s <asn.1-sequence>))
;; TODO check length
(make <subject-public-key-info>
:algorithm-identifier (make-algorithm-identifier (asn.1-sequence-get s 0))
:key-data (asn.1-sequence-get s 1)))
(define-class <tbs-certificate-structure> (<asn.1-encodable>)
((sequence :init-keyword :sequence) ;; original asn.1 object
(version :init-keyword :version)
(serial-number :init-keyword :serial-number)
(signature :init-keyword :signature)
(issuer :init-keyword :issuer)
(start-date :init-keyword :start-date)
(end-date :init-keyword :end-date)
(subject :init-keyword :subject)
(subject-public-key-info :init-keyword :public-key-info)
(issuer-unique-id :init-keyword :issuer-id)
(subject-unique-id :init-keyword :subject-id)
(extensions :init-keyword :extensions)))
(define-method make-tbs-certificate-structure ((s <asn.1-sequence>))
(let* ((start 0)
(version (cond ((is-a? (asn.1-sequence-get s 0) <der-tagged-object>)
(make-der-integer (asn.1-sequence-get s 0) #t))
(else
(set! start -1)
(make-der-integer 0))))
(serial-number (asn.1-sequence-get s (+ start 1)))
(signature (make-algorithm-identifier
(asn.1-sequence-get s (+ start 2))))
(issuer (make-x500-name (asn.1-sequence-get s (+ start 3))))
(dates (asn.1-sequence-get s (+ start 4)))
(start-date (make-x509-time (asn.1-sequence-get dates 0)))
(end-date (make-x509-time (asn.1-sequence-get dates 1)))
(subject (make-x500-name (asn.1-sequence-get s (+ start 5))))
(public-key (make-subject-public-key-info
(asn.1-sequence-get s (+ start 6))))
(issuer-id #f)
(subject-id #f)
(extensions #f))
(do ((extras (- (asn.1-sequence-size s) (+ start 6) 1) (- extras 1)))
((zero? extras))
(let ((extra (asn.1-sequence-get s (+ start 6 extras))))
;; assume tagged object
(case (~ extra 'tag-no)
((1) (set! issuer-id (make-der-bit-string extra #f)))
((2) (set! subject-id (make-der-bit-string extra #f)))
((3) (set! extensions (make-x509-extensions extra))))))
(make <tbs-certificate-structure>
:sequence s
:version version
:serial-number serial-number
:signature signature
:issuer issuer
:start-date start-date
:end-date end-date
:subject subject
:public-key-info public-key
:issuer-id issuer-id
:subject-id subject-id
:extensions extensions)))
(define-class <x509-certificate-structure> (<asn.1-encodable>)
((sequence :init-keyword :sequence) ;; original asn.1 object
(tbs-cert :init-keyword :tbs-cert)
(algorithm-identifier :init-keyword :algorithm-identifier)
(signature :init-keyword :signature)))
(define-method make-x509-certificate-structure ((s <asn.1-sequence>))
(make <x509-certificate-structure>
:sequence s
:tbs-cert (make-tbs-certificate-structure (asn.1-sequence-get s 0))
:algorithm-identifier (make-algorithm-identifier (asn.1-sequence-get s 1))
;; must be der bit string
:signature (asn.1-sequence-get s 2)))
(define-method der-encode ((o <x509-certificate-structure>) p)
(der-encode (~ o 'sequence) p))
(define-class <basic-constraints> (<asn.1-encodable>)
((ca :init-keyword :ca :init-form (make-der-boolean #f))
(path-length-constraint :init-keyword :path-length-constraint)))
(define-method make-basic-constrains ((s <asn.1-sequence>))
(case (asn.1-sequence-size s)
((0)
(make <basic-constraints> :ca #f :path-length-constraint #f))
(else
=> (lambda (size)
(let ((ca (asn.1-sequence-get s 0))
(path-len #f))
(unless (is-a? ca <der-boolean>)
(set! ca #f)
(set! path-len ca))
(when (> size 1)
(if ca
(set! path-len (asn.1-sequence-get s 1))
(assertion-violation 'make-basic-constrains
"wrong sequence in constructor")))
(make <basic-constraints>
:ca ca
:path-length-constraint path-len))))))
;; should we make <certificate>?
;; based on bouncy castle X509CertificateObject
(define-class <x509-certificate> ()
((c :init-keyword :c)
(basic-constraints :init-keyword :basic-constraints)
(key-usage :init-keyword :key-usage)))
(define-method make-x509-certificate ((bv <bytevector>))
(make-x509-certificate (open-bytevector-input-port bv)))
(define-method make-x509-certificate ((p <port>))
(make-x509-certificate (read-asn.1-object p)))
(define-method make-x509-certificate ((s <asn.1-sequence>))
;; TODO constrains and key usage
(define (get-extension-bytes c oid)
(let ((exts (~ c 'tbs-cert 'extensions)))
(if exts
(let ((ext (get-x509-extension
exts
(make-der-object-identifier oid))))
(if ext
(~ ext 'value 'string)
#f))
#f)))
(define (read-from-bytes bytes)
(if bytes
(read-asn.1-object (open-bytevector-input-port bytes))
#f))
(let* ((c (make-x509-certificate-structure s))
(constraints (cond
((read-from-bytes (get-extension-bytes c "2.5.29.19"))
=> make-basic-constrains)
(else #f)))
(key-usage (cond
((read-from-bytes (get-extension-bytes c "2.5.29.15"))
=> (lambda (obj)
;; obj must be der-bit-string
(let* ((bytes (~ obj 'data))
(len (- (* (bytevector-length bytes) 8)
(~ obj 'padding-bits)))
(ks (make-vector (if (< len 9) 9 len) #f)))
(dotimes (i len)
(let ((byte (bytevector-u8-ref bytes
(div i 8)))
(mask (bitwise-arithmetic-shift-right
#x80 (mod i 8))))
(vector-set!
ks
i
(not (zero?
(bitwise-and byte mask))))))
ks)
))
(else #f))))
(make <x509-certificate>
:c c
:basic-constraints constraints
:key-usage key-usage)))
(define (x509-certificate? o) (is-a? o <x509-certificate>))
(define (x509-certificate->bytevector o) (encode (~ o 'c)))
;; accessor
(define (x509-certificate-get-version cert)
(let ((c (~ cert 'c 'tbs-cert)))
(+ 1 (der-integer->integer (~ c 'version)))))
(define (x509-certificate-get-serial-number cert)
(let ((c (~ cert 'c 'tbs-cert)))
(der-integer->integer (~ c 'serial-number))))
(define (x509-certificate-get-issuer-dn cert)
(let ((c (~ cert 'c 'tbs-cert)))
(make-x509-principal (~ c 'issuer))))
(define (x509-certificate-get-subject-dn cert)
(let ((c (~ cert 'c 'tbs-cert)))
(make-x509-principal (~ c 'subject))))
(define (x509-certificate-get-not-before cert)
(let ((c (~ cert 'c 'tbs-cert)))
(x509-time->date (~ c 'start-date))))
(define (x509-certificate-get-not-after cert)
(let ((c (~ cert 'c 'tbs-cert)))
(x509-time->date (~ c 'end-date))))
(define (x509-certificate-get-signature cert)
(~ cert 'c 'signature 'data))
;; should return meaningful name, but for now we just return oid
(define (x509-certificate-get-signature-algorithm cert)
(~ cert 'c 'algorithm-identifier 'object-id 'identifier))
(define *rsa-oids*
`(,(make-der-object-identifier "1.2.840.113549.1.1.1")
,(make-der-object-identifier "1.2.840.113549.1.1.2")
,(make-der-object-identifier "1.2.840.113549.1.1.3")
,(make-der-object-identifier "1.2.840.113549.1.1.4")
,(make-der-object-identifier "1.2.840.113549.1.1.5")
,(make-der-object-identifier "1.2.840.113549.1.1.7")
,(make-der-object-identifier "1.2.840.113549.1.1.10")
,(make-der-object-identifier "1.2.840.113549.1.1.11")
,(make-der-object-identifier "2.5.8.1.1")
))
(define (x509-certificate-get-public-key cert)
(let* ((c (~ cert 'c 'tbs-cert))
(info (~ c 'subject-public-key-info))
(oid (~ info 'algorithm-identifier 'object-id)))
;; we only support RSA
(if (member oid *rsa-oids*)
(import-public-key RSA (open-bytevector-input-port
(~ info 'key-data 'data)))
(assertion-violation 'x509-certificate-get-public-key
"not supported public key oid"))))
(define-syntax ash (identifier-syntax bitwise-arithmetic-shift))
(define-method write-object ((o <x509-certificate>) (p <port>))
(define (bv->hex-string bv)
(define (->hex-char i) (string-ref "0123456789abcdef" i))
(let1 s (make-string (* (bytevector-length bv) 2))
(dotimes (i (bytevector-length bv))
(let1 u8 (bytevector-u8-ref bv i)
(string-set! s (* i 2) (->hex-char (ash u8 -4)))
(string-set! s (+ (* i 2) 1) (->hex-char (bitwise-and u8 #xF)))))
s))
(let ((buf (call-with-string-output-port
(lambda (out)
(format out "#<x509-certificate~%")
(format out " [0] Version: ~a~%"
(x509-certificate-get-version o))
(format out " SerialNumber: ~a~%"
(x509-certificate-get-serial-number o))
(format out " IssuerDN: ~a~%"
(x509-certificate-get-issuer-dn o))
(format out " Start Date: ~a~%"
(x509-certificate-get-not-before o))
(format out " Final Date: ~a~%"
(x509-certificate-get-not-after o))
(format out " SubjectDN: ~a~%"
(x509-certificate-get-subject-dn o))
(format out " Public Key: ~a~%"
(x509-certificate-get-public-key o))
(format out " Signature Algorithm: ~a~%"
(x509-certificate-get-signature-algorithm o))
(let* ((sig (bv->hex-string
(x509-certificate-get-signature o)))
(len (string-length sig)))
(format out " Signature: ~a~%"
(substring sig 0 40))
(do ((i 40 (+ i 40)))
((>= i len))
(if (< i (- len 40))
(format out " ~a~%"
(substring sig i (+ i 40)))
(format out " ~a~%"
(substring sig i len)))))
(let ((extensions (~ o 'c 'tbs-cert 'extensions)))
(when extensions
(let ((oids (map car (~ extensions 'extensions))))
(unless (null? oids)
(format out " Extensions: ~%")
(for-each
(lambda (oid)
(let* ((ext (get-x509-extension extensions oid))
;; do we need to check value if it's null?
(octs (asn.1-encodable->asn.1-object
(~ ext 'value))))
(format out " critical(~a)"
(~ ext 'critical))
;; for now we don't check known oids.
(format out "~a value = ~a~%"
(~ oid 'identifier)
(read-asn.1-object
(open-bytevector-input-port
(~ octs 'string))))))
oids)))))
(display ">" out)))))
(display buf p)))
;; TODO for now we only support RSA
;; currently user needs to do more task like choose hash algorithm
;; and verifier. this must be done by the process.
(define (verify cert message signature
:key (verify pkcs1-emsa-v1.5-verify)
(hash (hash-algorithm SHA-1)))
(let* ((public-key (x509-certificate-get-public-key cert))
(rsa-cipher (cipher RSA public-key)))
;; TODO check certificate encoder
(crypto:verify rsa-cipher message signature
:verify verify :hash hash)))
(define (check-validity cert :optional (date (current-date)))
(let ((time (date->time-utc date)))
(when (time>? time (date->time-utc (x509-certificate-get-not-after cert)))
(assertion-violation 'check-veridity
"certificate expored"
(x509-certificate-get-not-after cert)))
(when (time<? time
(date->time-utc (x509-certificate-get-not-before cert)))
(assertion-violation 'check-veridity
"certificate not valid yet"
(x509-certificate-get-not-before cert)))
#t))
#|
Reference: RFC 3280 http://www.ietf.org/rfc/rfc3280.txt
Section 4.1
Certificate ::= SEQUENCE {
tbsCertificate TBSCertificate,
signatureAlgorithm AlgorithmIdentifier,
signatureValue BIT STRING }
TBSCertificate ::= SEQUENCE {
version [0] EXPLICIT Version DEFAULT v1,
serialNumber CertificateSerialNumber,
signature AlgorithmIdentifier,
issuer Name,
validity Validity,
subject Name,
subjectPublicKeyInfo SubjectPublicKeyInfo,
issuerUniqueID [1] IMPLICIT UniqueIdentifier OPTIONAL,
-- If present, version MUST be v2 or v3
subjectUniqueID [2] IMPLICIT UniqueIdentifier OPTIONAL,
-- If present, version MUST be v2 or v3
extensions [3] EXPLICIT Extensions OPTIONAL
-- If present, version MUST be v3
}
Version ::= INTEGER { v1(0), v2(1), v3(2) }
CertificateSerialNumber ::= INTEGER
Validity ::= SEQUENCE {
notBefore Time,
notAfter Time }
Time ::= CHOICE {
utcTime UTCTime,
generalTime GeneralizedTime }
UniqueIdentifier ::= BIT STRING
SubjectPublicKeyInfo ::= SEQUENCE {
algorithm AlgorithmIdentifier,
subjectPublicKey BIT STRING }
NOTE: we don't support optional fields such as issuerUniqueID
|#
;; take alist of issuer info
;; for now we don't check the order or mandatory fields
(define (make-x509-issuer issuers)
(define (rdn oid string)
(make-der-set
(make-der-sequence oid (make-der-printable-string string #t))))
(define (gen-rdn issuer)
(or (and-let* ((slot (find (^s (eq? (cdr s) (car issuer)))
*default-symbols*)))
(rdn (car slot) (cdr issuer)))
(error 'make-x509-issuer "unknown parameter" issuer issuers)))
(apply make-der-sequence (map (cut gen-rdn <>) issuers)))
;; we don't check
(define (make-validity start end)
(make-der-sequence (make-der-utc-time start) (make-der-utc-time end)))
;; for now we only use sha1withRSAEncryption as signature algorithm
;; OID 1 2 840 113549 1 1 5
(define +sha1-with-rsa-encryption+
(make-der-object-identifier "1.2.840.113549.1.1.5"))
;; for now we only use rsaEncryption as subject public key info
;; OID 1 2 840 113549 1 1 1
(define +rsa-encryption+
(make-der-object-identifier "1.2.840.113549.1.1.1"))
(define (make-x509-basic-certificate keypair serial-number
issuer validity subject)
(define (make-algorithm-id oid) (make-der-sequence oid (make-der-null)))
(define (generate-signature-algorithm)
(make-algorithm-id +sha1-with-rsa-encryption+))
(define (generate-tbs)
(let1 tbs (make-der-sequence)
;; basic should be v1
;; serialnumber
(asn.1-sequence-add tbs (make-der-integer serial-number))
(asn.1-sequence-add tbs (generate-signature-algorithm))
;; CA certificate issuer
(asn.1-sequence-add tbs issuer)
(asn.1-sequence-add tbs validity)
(asn.1-sequence-add tbs subject)
;; public key
(let1 spki (make-der-sequence)
(asn.1-sequence-add spki (make-algorithm-id +rsa-encryption+))
(let1 pbkey (make-der-bit-string
(export-public-key RSA (keypair-public keypair)))
(asn.1-sequence-add spki pbkey)
(asn.1-sequence-add tbs spki)))
tbs))
(let* ((tbs (generate-tbs))
(cert (make-der-sequence tbs (generate-signature-algorithm)
(let1 signature (hash SHA-1 (encode tbs))
(make-der-bit-string signature)))))
(make-x509-certificate cert)))
)
| true |
b131cb5051b2f8ddf9554671b77d6b83eab8a521
|
6e359a216e1e435de5d39bc64e75998945940a8c
|
/ex4.68.scm
|
d3f9e0c3584cdae6f1de79ab339b2bb1778c542f
|
[] |
no_license
|
GuoDangLang/SICP
|
03a774dd4470624165010f65c27acc35d844a93d
|
f81b7281fa779a9d8ef03997214e47397af1a016
|
refs/heads/master
| 2021-01-19T04:48:22.891605 | 2016-09-24T15:26:57 | 2016-09-24T15:26:57 | 69,106,376 | 0 | 0 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 302 |
scm
|
ex4.68.scm
|
(rule (append-to-for '() ?y ?y))
(rule (append-to-from (?x . ?v) ?y (?x . ?u))
(append-to-form ?v ?y ?u))
(rule (reverse '() '()))
(rule (reverse (?x . ?u) ?z)
(append-to-form (reverse ?u ) ?x ?z))
(define (reverse x)
(if (null? x)
'()
(append (reverse (cdr x)) (list (car x)))))
| false |
005d7580bf5deac47c17383020453f013da15e1f
|
defeada37d39bca09ef76f66f38683754c0a6aa0
|
/mscorlib/system/runtime/compiler-services/has-copy-semantics-attribute.sls
|
5b71fe02418e22668dfb2060d3da48fdd517a0db
|
[] |
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 | 598 |
sls
|
has-copy-semantics-attribute.sls
|
(library (system runtime compiler-services has-copy-semantics-attribute)
(export new is? has-copy-semantics-attribute?)
(import (ironscheme-clr-port))
(define-syntax new
(lambda (e)
(syntax-case e ()
((_ a ...)
#'(clr-new
System.Runtime.CompilerServices.HasCopySemanticsAttribute
a
...)))))
(define (is? a)
(clr-is
System.Runtime.CompilerServices.HasCopySemanticsAttribute
a))
(define (has-copy-semantics-attribute? a)
(clr-is
System.Runtime.CompilerServices.HasCopySemanticsAttribute
a)))
| true |
2e0a5fae9cce0a9cb0fa919d40f1afc5c6f93502
|
33cdb89db34126ae07296f72bb173275cceaab23
|
/lib/_module.scm
|
70d87f35e3773fc71bff757bcf93af9ae5a3cac3
|
[
"LGPL-2.1-only",
"Apache-2.0"
] |
permissive
|
aminesami/gambit
|
c364bcd76a3835f069d19ac01bd0900913f541f7
|
d862f6cd2485871712cb4c3c6889311a864a2912
|
refs/heads/master
| 2020-05-07T14:56:51.062503 | 2019-05-31T18:23:31 | 2019-05-31T18:23:31 | 180,614,489 | 0 | 0 |
Apache-2.0
| 2019-04-10T15:49:29 | 2019-04-10T15:49:29 | null |
UTF-8
|
Scheme
| false | false | 20,283 |
scm
|
_module.scm
|
;;;============================================================================
;;; File: "_module.scm"
;;; Copyright (c) 1994-2019 by Marc Feeley, All Rights Reserved.
;;;============================================================================
(##include "_module#.scm")
(implement-type-modref)
;;;----------------------------------------------------------------------------
(define ##module-search-order (##os-module-search-order))
(define-prim (##module-search-order-set! x)
(set! ##module-search-order x))
;;;----------------------------------------------------------------------------
(define-prim (##modref->string modref #!optional (namespace? #f))
(let* ((rpath
(##reverse (macro-modref-path modref)))
(parts
(##append (##reverse (macro-modref-host modref))
(##cons (##car rpath)
(##append (##reverse (macro-modref-tag modref))
(##cdr rpath)))))
(name
(##append-strings
(##map (lambda (x)
(##string-append x "/"))
parts))))
(let ((len-1 (##fx- (##string-length name) 1)))
(if namespace?
(##string-set! name len-1 #\#)
(##string-shrink! name len-1)))
name))
(define-prim (##string->modref str)
(let ((x (##parse-module-ref str)))
(and x
(##fx= (##car x) 0)
(##cdr x))))
;;;----------------------------------------------------------------------------
(define-prim (##parse-module-ref str-or-src)
(define (valid-module-ref-part? x)
(or (##symbol? x)
(and (macro-exact-int? x) (##not (##negative? x)))))
(define (module-ref-part->string x)
(if (##symbol? x)
(##symbol->string x)
(##number->string x)))
(define (split-at-path-sep str rest)
(and rest
(##string-split-at str #\/ rest)))
(define (split-rest lst)
(if (##pair? lst)
(let ((x (##source-strip (##car lst))))
(and (valid-module-ref-part? x)
(split-at-path-sep (module-ref-part->string x)
(split-rest (##cdr lst)))))
(if (##null? lst)
'()
#f)))
(define (valid-component? str in-hostname?)
(let ((len (##string-length str)))
(and (##fx> len 0)
(or (##not in-hostname?)
(##not (or (##char=? (##string-ref str 0) #\-)
(##char=? (##string-ref str (##fx- len 1)) #\-))))
(let loop ((i (##fx- len 1)))
(if (##fx< i 0)
#t
(let ((c (##string-ref str i)))
(if (or (and (##char>=? c #\a) (##char<=? c #\z))
(and (##char>=? c #\A) (##char<=? c #\Z))
(and (##char>=? c #\0) (##char<=? c #\9))
(##char=? c #\-)
(and (##not in-hostname?)
(or (##char=? c #\_)
(##char=? c #\.))))
(loop (##fx- i 1)))))))))
(define (valid-components? lst in-hostname?)
(if (##pair? lst)
(and (valid-component? (##car lst) in-hostname?)
(valid-components? (##cdr lst) in-hostname?))
#t))
(define (valid-hostname? str)
(let ((x (##string-split-at str #\. '())))
(and (##pair? x)
(##pair? (##cdr x))
(valid-components? x #t))))
(define (parse-hosted hostname parts)
(and (##pair? parts)
(let ((username (##car parts))
(parts (##cdr parts)))
(and (##pair? parts)
(let ((repo (##car parts))
(parts (##cdr parts)))
(if (##pair? parts)
(let ((tree (##car parts))
(parts (##cdr parts)))
(and (##pair? parts)
(let ((tag (##car parts))
(parts (##cdr parts)))
(macro-make-modref
(##list username hostname)
(##list tag tree)
(##reverse (##cons repo parts))))))
(macro-make-modref
(##list username hostname)
'()
(##list repo))))))))
(define (validate-rest nb-dots parts)
(and (##pair? parts)
(valid-components? (##cdr parts) #f)
(let ((head (##car parts)))
(if (valid-hostname? head)
(let ((modref (parse-hosted head (##cdr parts))))
(and modref
(##cons nb-dots modref)))
(and (valid-component? head #f)
(##cons nb-dots
(macro-make-modref
'()
'()
(##reverse parts))))))))
(define (parse-head-rest head-str rest)
(let ((len-head-str (##string-length head-str)))
(let loop ((nb-dots 0))
(if (##fx< nb-dots len-head-str)
(if (##char=? (##string-ref head-str nb-dots) #\.)
(loop (##fx+ nb-dots 1))
(validate-rest
nb-dots
(split-at-path-sep
(##substring head-str nb-dots len-head-str)
(split-rest rest))))
(validate-rest
nb-dots
(split-rest rest))))))
(define (parse head rest)
(and (valid-module-ref-part? head)
(let ((head-str (module-ref-part->string head)))
(parse-head-rest head-str rest))))
(if (##string? str-or-src)
(parse-head-rest str-or-src '())
(let ((code (##source-strip str-or-src)))
(if (##pair? code)
(parse (##source-strip (##car code))
(##cdr code))
(parse code
'())))))
(define-prim (##string-split-at str sep #!optional (rest '()))
(let ((len (##string-length str)))
(let loop ((i (##fx- len 1)) (j len) (lst rest))
(if (##fx< i 0)
(##cons (##substring str 0 j) lst)
(let ((c (##string-ref str i)))
(if (##char=? c sep)
(loop (##fx- i 1)
i
(##cons (##substring str (##fx+ i 1) j) lst))
(loop (##fx- i 1)
j
lst)))))))
;;;----------------------------------------------------------------------------
(define-prim (##search-module-aux
modref
check-mod
#!optional
(search-order ##module-search-order))
(define (last lst)
(if (##pair? (##cdr lst))
(last (##cdr lst))
(##car lst)))
(define (butlast lst)
(if (##pair? (##cdr lst))
(##cons (##car lst) (butlast (##cdr lst)))
'()))
(define (join parts dir)
(if (##pair? parts)
(##path-expand (##car parts)
(join (##cdr parts) dir))
dir))
(define (search-dir dir)
(define (search dirs nested-dirs root check-mod)
(and (##pair? dirs)
(let ()
(define (check dirs2)
(check-mod (##car dirs) (join dirs2 root)))
(or (check nested-dirs)
(and (##pair? nested-dirs)
(check (##cdr nested-dirs)))))))
(let ((path (macro-modref-path modref)))
(if (and (##null? (macro-modref-host modref))
(##null? (macro-modref-tag modref)))
(search path
path
dir
check-mod)
(search path
(butlast path)
(join (macro-modref-tag modref)
(##path-expand (last path)
(join (macro-modref-host modref)
dir)))
check-mod))))
(let loop ((lst search-order))
(and (##pair? lst)
(let ((search-in (##car lst)))
(or (search-dir (##path-expand search-in))
(loop (##cdr lst)))))))
(define-prim (##search-module
modref
#!optional
(search-order ##module-search-order))
(define (try-opening-source-file path cont)
(if ##debug-modules? (pp (list 'try-opening-source-file path)));;;;;;;;;;;;;;
(##make-input-path-psettings
(##list 'path: path
'char-encoding: 'UTF-8
'eol-encoding: 'cr-lf)
(lambda ()
#f)
(lambda (psettings)
(let ((path (macro-psettings-path psettings)))
(##open-file-generic-from-psettings
psettings
#f ;; raise-os-exception?
cont
open-input-file
path
(macro-absent-obj))))))
(define (check-mod mod-filename-noext mod-dir)
(let ((mod-path-noext (##path-expand mod-filename-noext mod-dir)))
(define (check-source-with-ext ext)
(let ((mod-path (##string-append mod-path-noext (##car ext))))
(try-opening-source-file
mod-path
(lambda (port)
(and (##not (##fixnum? port))
(##vector mod-dir mod-filename-noext ext mod-path port))))))
(let loop ((exts ##scheme-file-extensions))
(and (##pair? exts)
(or (check-source-with-ext (##car exts))
(loop (##cdr exts)))))))
(##search-module-aux modref check-mod search-order))
(define-prim (##module-build-subdir-path mod-dir mod-filename-noext target)
(##path-expand (##module-build-subdir-name mod-filename-noext target)
mod-dir))
(define-prim (##module-build-subdir-name mod-filename-noext target)
(##string-append mod-filename-noext
"@gambit"
(##module-system-configuration-string target)))
(define-prim (##module-system-configuration-string target)
(##string-append (##number->string (##system-version))
"@"
(##symbol->string target)))
;;;----------------------------------------------------------------------------
(define (##compile-mod top-cte src module-ref)
(##compile-in-compilation-scope
top-cte
src
#f
(lambda (cte src tail?)
(##table-set! (##compilation-scope) '##module-ref module-ref)
(let ((tail? #f))
(##comp-top top-cte src tail?)))))
(define-prim (##get-module-from-file module-ref modref mod-info)
(define (err)
(##raise-module-not-found-exception
##get-module
module-ref))
(define (search-for-highest-object-file path-noext)
(let loop ((version 1)
(highest-object-file-path #f)
(highest-object-file-info #f))
(let* ((resolved-path
(##path-resolve
(##string-append path-noext
".o"
(##number->string version 10))))
(_ (if ##debug-modules? (pp (list '##file-info resolved-path))));;;;;;;;;;;;;
(resolved-info
(##file-info resolved-path))
(resolved-path-exists?
(##not (##fixnum? resolved-info))))
(if resolved-path-exists?
(loop (##fx+ version 1)
resolved-path
resolved-info)
highest-object-file-path))))
(let ((mod-dir (##vector-ref mod-info 0))
(mod-filename-noext (##vector-ref mod-info 1))
(ext (##vector-ref mod-info 2))
(mod-path (##vector-ref mod-info 3))
(port (##vector-ref mod-info 4)))
(define (get-from-source-file)
(let ((x
(##read-all-as-a-begin-expr-from-port
port
##main-readtable
##wrap-datum
##unwrap-datum
(##cdr ext) ;; start-syntax
#t ;; close-port?
'())))
(if (##fixnum? x)
(##raise-os-exception
#f
x
##get-module
module-ref)
(let* ((script-line
(##vector-ref x 0))
(src
(##vector-ref x 1))
(module-name
(##symbol->string module-ref))
(c
(##compile-mod
(##top-cte-clone ##interaction-cte)
(##sourcify src (##make-source #f #f))
module-ref))
(code
(##car c))
(comp-scope
(##cdr c))
(supply-modules
(##table-ref comp-scope '##supply-modules '()))
(demand-modules
(##table-ref comp-scope '##demand-modules '()))
(module-descr
(##vector (##list->vector
(if (##not (##memq module-ref supply-modules))
(##append supply-modules
(##list module-ref))
supply-modules))
(##list->vector demand-modules)
(if script-line
(##list (##cons 'script-line script-line))
'())
0
(lambda ()
(let ((rte #f))
(macro-code-run code)))
#f)))
(##register-module-descrs (##vector module-descr))
(or (##lookup-registered-module module-ref)
(err))))))
(define (get-from-object-file path)
(##close-port port)
(let* ((linker-name
(##path-strip-directory path))
(_ (if ##debug-modules? (pp (list '##os-load-object-file path linker-name))));;;;;;;;;;;;;
(result
(##os-load-object-file path linker-name)))
(define (raise-error code)
(if (##fixnum? code)
(##raise-os-exception #f code ##get-module module-ref)
(##raise-os-exception code #f ##get-module module-ref)))
(cond ((##not (##vector? result))
(raise-error result))
((##fx= 2 (##vector-length result))
(raise-error (##vector-ref result 0)))
(else
(let ((module-descrs (##vector-ref result 0)))
(##register-module-descrs module-descrs)
(or (##lookup-registered-module module-ref)
(err)))))))
(define (search-for-object-file mod-filename-noext dir)
(search-for-highest-object-file
(##path-expand mod-filename-noext dir)))
(let ((object-file-path
(or (search-for-object-file
mod-filename-noext
(##module-build-subdir-path mod-dir
mod-filename-noext
(macro-target)))
(search-for-object-file
mod-filename-noext
mod-dir))))
(if object-file-path
(get-from-object-file object-file-path)
(get-from-source-file)))))
(define-prim (##install-module modref)
(if ##debug-modules? (pp (list '##install-module modref)));;;;;;;;;;;;;;;;;
#f)
(define-prim (##install-module-set! x)
(set! ##install-module x))
(define-prim (##search-or-else-install-module modref)
(or (##search-module modref)
(##install-module modref)))
(##get-module-set!
(lambda (module-ref)
(define (err)
(##raise-module-not-found-exception
##get-module
module-ref))
(or (##lookup-registered-module module-ref)
(let ((modref (##string->modref (##symbol->string module-ref))))
(if (##not modref)
(err)
(let ((mod-info (##search-or-else-install-module modref)))
(if mod-info ;; found module?
(##get-module-from-file module-ref modref mod-info)
(err))))))))
(define-prim (##load-module-or-file mod-str script-callback)
(define (fallback)
(##load mod-str
script-callback
#t ;; clone-cte?
#t ;; raise-os-exception?
#f ;; linker-name
#f)) ;; quiet?
(if (##not (##string=? "" (##path-extension mod-str)))
(fallback)
(let ((modref (##string->modref mod-str)))
(if (##not modref)
(fallback)
(let ((module-ref (##string->symbol mod-str)))
(or (##lookup-registered-module module-ref)
(let ((mod-info (##search-module
modref
(##cons "" ##module-search-order))))
(if mod-info ;; found module?
(let* ((module
(##get-module-from-file module-ref
modref
mod-info))
(module-descr
(macro-module-module-descr module))
(meta-info
(macro-module-descr-meta-info module-descr))
(x
(##assq 'script-line meta-info)))
(if x
(script-callback (##cdr x)
(##vector-ref mod-info 3)))
(##load-module (macro-module-module-ref module)))
(fallback)))))))))
(define ##debug-modules? #f)
(define-prim (##debug-modules?-set! x)
(set! ##debug-modules? x))
;;;----------------------------------------------------------------------------
(define-runtime-syntax ##import
(lambda (src)
(##deconstruct-call
src
2
(lambda (arg-src)
(let ((x (##parse-module-ref arg-src)))
(if (or (##not x) (##not (##fx= (##car x) 0)))
(##raise-expression-parsing-exception
'ill-formed-special-form
src
(##source-strip (##car (##source-strip src))))
(let* ((modref (##cdr x))
(mod-info (##search-or-else-install-module modref)))
(if (##not mod-info)
(##raise-expression-parsing-exception
'module-not-found
src
(##desourcify arg-src))
(let ((path
(##path-normalize
(##path-expand (##string-append
(##vector-ref mod-info 1)
"#"
(##car (##vector-ref mod-info 2)))
(##vector-ref mod-info 0))
#f))
(port
(##vector-ref mod-info 4)))
(if port
(##close-port port))
`(##begin
,@(if (##file-exists? path)
`((##include ,path))
`())
(##demand-module ,arg-src)))))))))))
;;;----------------------------------------------------------------------------
(define (##gsi-option-update args)
((##eval '(let () (##import gambit/pkg) gsi-option-update)) args))
(define (##gsi-option-install args)
((##eval '(let () (##import gambit/pkg) gsi-option-install)) args))
(define (##gsi-option-uninstall args)
((##eval '(let () (##import gambit/pkg) gsi-option-uninstall)) args))
(define ##gsi-option-handlers
(##list (##cons 'update ##gsi-option-update)
(##cons 'uninstall ##gsi-option-uninstall)
(##cons 'install ##gsi-option-install)))
;;;============================================================================
| false |
1737bf13bd4291871369b55e10f8bff89ad92073
|
a74932f6308722180c9b89c35fda4139333703b8
|
/edwin48/os2.scm
|
e4fc245f4d5da6e0d248300c56784ef87dce3902
|
[] |
no_license
|
scheme/edwin48
|
16b5d865492db5e406085e8e78330dd029f1c269
|
fbe3c7ca14f1418eafddebd35f78ad12e42ea851
|
refs/heads/master
| 2021-01-19T17:59:16.986415 | 2014-12-21T17:50:27 | 2014-12-21T17:50:27 | 1,035,285 | 39 | 10 | null | 2022-02-15T23:21:14 | 2010-10-29T16:08:55 |
Scheme
|
UTF-8
|
Scheme
| false | false | 6,294 |
scm
|
os2.scm
|
#| -*-Scheme-*-
$Id: os2.scm,v 1.57 2008/01/30 20:02:04 cph Exp $
Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994,
1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
2006, 2007, 2008 Massachusetts Institute of Technology
This file is part of MIT/GNU Scheme.
MIT/GNU Scheme is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at
your option) any later version.
MIT/GNU Scheme is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with MIT/GNU Scheme; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301,
USA.
|#
;;;; OS/2 Customizations for Edwin
(define (os/set-file-modes-writeable! pathname)
(set-file-modes! pathname
(fix:andc (file-modes pathname) os2-file-mode/read-only)))
(define (os/restore-modes-to-updated-file! pathname modes)
(set-file-modes! pathname (fix:or modes os2-file-mode/archived)))
(define (os/scheme-can-quit?)
#f)
(define (os/quit dir)
dir
(error "Can't quit."))
(define (dos/read-dired-files file all-files?)
(let loop
((pathnames
(let ((pathnames (directory-read file #f)))
(if all-files?
pathnames
(filter
(let ((mask
(fix:or os2-file-mode/hidden os2-file-mode/system)))
(lambda (pathname)
(fix:= (fix:and (file-modes pathname) mask) 0)))
pathnames))))
(result '()))
(if (null? pathnames)
result
(loop (cdr pathnames)
(let ((attr (file-attributes (car pathnames))))
(if attr
(cons (cons (file-namestring (car pathnames)) attr) result)
result))))))
;;;; OS/2 Clipboard Interface
(define (os/interprogram-cut string context)
context
(os2-clipboard-write-text
(let ((string (convert-newline-to-crlf string)))
;; Some programs can't handle strings over 64k.
(if (fix:< (string-length string) #x10000) string ""))))
(define (os/interprogram-paste context)
context
(let ((text (os2-clipboard-read-text)))
(and text
(convert-crlf-to-newline text))))
(define (convert-newline-to-crlf string)
(let ((end (string-length string)))
(let ((n-newlines
(let loop ((start 0) (n-newlines 0))
(let ((newline
(string-index string #\newline start end)))
(if newline
(loop (fix:+ newline 1) (fix:+ n-newlines 1))
n-newlines)))))
(if (fix:= n-newlines 0)
string
(let ((copy (make-string (fix:+ end n-newlines))))
(let loop ((start 0) (cindex 0))
(let ((newline
(string-index string #\newline start end)))
(if newline
(begin
(%substring-move! string start newline copy cindex)
(let ((cindex (fix:+ cindex (fix:- newline start))))
(string-set! copy cindex #\return)
(string-set! copy (fix:+ cindex 1) #\newline)
(loop (fix:+ newline 1) (fix:+ cindex 2))))
(%substring-move! string start end copy cindex))))
copy)))))
(define (convert-crlf-to-newline string)
(let ((end (string-length string)))
(let ((n-crlfs
(let loop ((start 0) (n-crlfs 0))
(let ((cr
(string-index string #\return start end)))
(if (and cr
(not (fix:= (fix:+ cr 1) end))
(char=? (string-ref string (fix:+ cr 1)) #\linefeed))
(loop (fix:+ cr 2) (fix:+ n-crlfs 1))
n-crlfs)))))
(if (fix:= n-crlfs 0)
string
(let ((copy (make-string (fix:- end n-crlfs))))
(let loop ((start 0) (cindex 0))
(let ((cr
(string-index string #\return start end)))
(if (not cr)
(%substring-move! string start end copy cindex)
(let ((cr
(if (and (not (fix:= (fix:+ cr 1) end))
(char=? (string-ref string (fix:+ cr 1))
#\linefeed))
cr
(fix:+ cr 1))))
(%substring-move! string start cr copy cindex)
(loop (fix:+ cr 1) (fix:+ cindex (fix:- cr start)))))))
copy)))))
;;;; Mail Customization
(define (os/sendmail-program)
"sendmail")
(define (os/rmail-spool-directory)
(or (let ((etc (get-environment-variable "ETC")))
(and etc
(file-directory? etc)
(let ((mail
(merge-pathnames "mail/" (pathname-as-directory etc))))
(and (file-directory? mail)
(->namestring mail)))))
"c:\\mptn\\etc\\mail\\"))
(define (os/rmail-primary-inbox-list system-mailboxes)
system-mailboxes)
(define (os/rmail-pop-procedure)
(and (os/find-program "popclient" #f (ref-variable exec-path) #f)
(lambda (server user-name password directory)
(os2-pop-client server user-name password directory))))
(define (os2-pop-client server user-name password directory)
(let ((target
(->namestring
(merge-pathnames (if (dos/fs-long-filenames? directory)
".popmail"
"popmail.tmp")
directory))))
(let ((buffer (temporary-buffer "*popclient*")))
(cleanup-pop-up-buffers
(lambda ()
(pop-up-buffer buffer #f)
(let ((status.reason
(let ((args
(list "-u" user-name
"-p" (os2-pop-client-password password)
"-o" target
server)))
(apply run-synchronous-process
#f (cons (buffer-end buffer) #t) #f #f
"popclient"
"-3"
(if (ref-variable rmail-pop-delete)
args
(cons "-k" args))))))
(if (and (eq? 'EXITED (car status.reason))
(memv (cdr status.reason) '(0 1)))
(kill-pop-up-buffer buffer)
(begin
(keep-pop-up-buffer buffer)
(editor-error "Error getting mail from POP server.")))))))
target))
(define (os2-pop-client-password password)
(cond ((string? password)
password)
((and (pair? password) (eq? 'FILE (car password)))
(call-with-input-file (cadr password)
(lambda (port)
(read-string (char-set #\newline) port))))
(else
(error "Illegal password:" password))))
(define-variable rmail-pop-delete
"If true, messages are deleted from the POP server after being retrieved.
Otherwise, messages remain on the server and will be re-fetched later."
#t
boolean?)
| false |
e9ceab7d8dd85b97b3f7f7197f2ca0be34734ae6
|
72e555d63b0514768a8d905c3761c54e76e13429
|
/mark_wutka+scheme/sql.scm
|
eda186102d77d9414491c63bc6b68564a31e4606
|
[
"MIT"
] |
permissive
|
chaughawout/rdbms
|
d40c6ba591b5d4f1453923b0dcbe621c086de698
|
94228ce2f2a11f40a69ad612ecf99bc71858fefc
|
refs/heads/master
| 2020-04-28T13:08:37.560231 | 2019-03-13T01:19:14 | 2019-03-13T01:19:14 | 175,299,130 | 0 | 0 |
NOASSERTION
| 2019-03-12T21:29:51 | 2019-03-12T21:29:49 | null |
UTF-8
|
Scheme
| false | false | 15,006 |
scm
|
sql.scm
|
(require-extension utf8-srfi-13)
(require-extension extras)
(require-extension regex)
(require-extension csv)
(include "select-parser.scm")
(include "database.scm")
;; Prepares the query by converting from the output format of the parser
;; to the input format of the database engine, checking table and column
;; names along the way
(define (prepare-query parsed-query)
(let ((columns (second parsed-query))
(tables (fourth parsed-query))
(where (fifth parsed-query))
(order-by (sixth parsed-query)))
(check-tables columns tables where order-by)))
;; Check all the table names
(define (check-tables columns tables where orderby)
(let ((checked-tables (map check-table-with-alias (delete "," tables))))
(if (every identity checked-tables)
(check-select-columns columns checked-tables where orderby))))
;; Check to see if this table exists, allow case-independent matching,
;; then use the name of the table as it in in the database
(define (check-table-with-alias table)
(let* ((alias (if (equal? "" (second table)) (first table) (second table)))
(table-name (first table))
(checked-table (assoc table-name table-list string-ci=)))
(if checked-table (list alias (car checked-table))
(begin
(format #t "Invalid table name: ~A~%" table)
#f))))
;; Check the list of select columns
(define (check-select-columns columns checked-tables where order-by)
(if (equal? columns "*")
(check-columns-star checked-tables where order-by)
(if (equal? columns "count(*)")
(check-where '() checked-tables where order-by)
(let ((checked-columns
(append-map
(lambda (col) (check-select-column col checked-tables))
(delete "," columns))))
(if (every identity checked-columns)
(check-where checked-columns checked-tables where order-by)
#f)))))
;; If the column list is just * and there is one table, use all
;; the columns from that one table
(define (check-columns-star checked-tables where order-by)
(if (> (length checked-tables) 1)
(begin
(format #t "Unable to select * on more than one table~%")
(list #f))
(check-where (map (lambda (col) (cons (caar checked-tables) col))
(table-columns (cadar checked-tables))) checked-tables where order-by)))
(define (check-table-alias table-alias checked-tables)
(let ((table-spec (assoc table-alias checked-tables)))
(if table-spec table-spec
(begin
(format #t "Invalid table name: ~A~%:" table-alias)))))
(define (is-column-in-table column table-spec)
(find (lambda (col) (string-ci= column col)) (table-columns (cadr table-spec))))
(define (find-unique-column-table col-spec checked-tables)
(let ((matching-tables (filter (lambda (t) (is-column-in-table col-spec t)) checked-tables)))
(if matching-tables
(if (= (length matching-tables) 1) (car matching-tables)
(begin
(format #t "Unqualified column ~A is ambiguous~%" col-spec)
#f))
(begin
(format #t "Unqualified column ~A does not appear in any queried table~%" col-spec)
#f))))
;; if there is no table qualifier on the column, make sure there
;; is only one table in the select
(define (check-select-column column checked-tables)
(let ((table-spec (car column))
(col-spec (cadr column)))
(if (equal? table-spec "")
(let ((unique-table (find-unique-column-table col-spec checked-tables)))
(if unique-table (check-select-column-table col-spec unique-table)
(begin
(format #t "Column ~A must have a table specifier (multiple tables)~%" col-spec)
(list #f))))
(let ((checked-table-spec (check-table-alias (car table-spec) checked-tables)))
(if checked-table-spec (check-select-column-table col-spec checked-table-spec)
(list #f))))))
;; Make sure the column is in the table. If the column name is *,
;; insert all the columns for that table
(define (check-select-column-table column checked-table)
(if (equal? column "*")
(map (lambda (col) (cons (car checked-table) col))
(table-columns (cadr checked-table)))
(let ((checked-column (find (lambda (col) (string-ci= column col)) (table-columns (cadr checked-table)))))
(if checked-column (list (cons (car checked-table) checked-column))
(begin
(format #t "Invalid column ~A for table ~A~%" column checked-table)
(list #f))))))
;; If the where clause exists, process it as if it is a list of expressions
;; to be or-ed together since that's how the parser returns them
(define (check-where checked-columns checked-tables where order-by)
(if (equal? where "")
(check-order-by checked-columns checked-tables (lambda (r) #t) order-by)
(let ((checked-where
(check-where-or checked-tables (cadr where))))
(if checked-where
(check-order-by checked-columns checked-tables checked-where order-by)
#f))))
(define (check-where-or checked-tables where)
(let ((checked-where-and (map (lambda (w) (check-where-and checked-tables w)) (delete "or " where))))
(if (every identity checked-where-and)
(cons db-or checked-where-and)
#f)))
;; Check a subset of where expressions as if they are a list of and-ed
;; expressions, because that's how the parser returns them
(define (check-where-and checked-tables where)
(let ((checked-where-comps (map (lambda (w) (check-where-comp checked-tables w)) (delete "and " where))))
(if (every identity checked-where-comps)
(cons db-and checked-where-comps)
#f)))
;; Check each side of a where comparison and the operator
(define (check-where-comp checked-tables where)
(let ((first-expr (check-where-expr checked-tables (first where))))
(if (equal? (second where) "isnull")
(if first-expr
(make-comparison (get-string-op "=") "=" first-expr "")
#f)
(let ((second-expr (check-where-expr checked-tables (cadadr where)))
(comp-op (check-comp-op (caadr where))))
(if (and first-expr second-expr comp-op)
(make-comparison comp-op (caadr where) first-expr second-expr)
#f)))))
;; If the expression is a string, strip the quotes
(define (check-where-expr checked-tables expr)
(if (string? expr)
(if (= (string-prefix-length expr "'") 1)
(substring/shared expr 1 (- (string-length expr) 1))
expr)
(check-column expr checked-tables)))
;; A list of comparison operators and their equivalent functions
(define string-op-to-function
(list (cons "=" string=) (cons "!=" string<>) (cons "<" string<) (cons ">" string>)
(cons ">=" string>=) (cons "<=" string<=)))
(define (ne a b) (not (= a b)))
(define numeric-op-to-function
(list (cons "=" =) (cons "!=" ne) (cons "<" <) (cons ">" >)
(cons ">=" >=) (cons "<=" <=)))
(define (check-comp-op op)
(cdr (assoc op string-op-to-function)))
(define (get-string-op op)
(cdr (assoc op string-op-to-function)))
(define (get-numeric-op op)
(cdr (assoc op numeric-op-to-function)))
(define (make-comparison comp-op comp-op-name expr1 expr2)
(let ((string-op (get-string-op comp-op-name))
(numeric-op (get-numeric-op comp-op-name)))
(list (lambda (a b)
(if (and (is-number a) (is-number b))
(numeric-op (string->number a) (string->number b))
(string-op a b))) expr1 expr2)))
;; If the column has no table qualifier, there must be only one table
(define (check-column column checked-tables)
(let ((table-spec (car column))
(col-spec (cadr column)))
(if (equal? table-spec "")
(let ((unique-table (find-unique-column-table col-spec checked-tables)))
(if unique-table (check-column-table col-spec unique-table)
(begin
(format #t "Column ~A must have a table specifier (multiple tables)~%" col-spec)
#f)))
(let ((checked-table-spec (check-table-alias (car table-spec) checked-tables)))
(if checked-table-spec (check-column-table col-spec checked-table-spec)
#f)))))
;; Make sure the column is in the table
(define (check-column-table column checked-table)
(let ((checked-column (find (lambda (col) (string-ci= column col)) (table-columns (cadr checked-table)))))
(if checked-column (cons (car checked-table) checked-column)
(begin
(format #t "Invalid column ~A for table ~A~%" column checked-table)
#f))))
;; Check the column list in the order-by clause making sure they
;; are valid references
(define (check-order-by checked-columns checked-tables checked-where order-by)
(if (equal? order-by "") (list checked-columns checked-tables checked-where '())
(let ((checked-order-by (map (lambda (c) (check-column c checked-tables)) (delete "," (third order-by)))))
(if (every identity checked-order-by)
(list checked-columns checked-tables checked-where checked-order-by)
#f))))
;; -------------------------------------------------------------
;; Formatting
;; -------------------------------------------------------------
;; This section is for formatting the output of the queries.
;; Compute the max widths of each column, starting with a base set
;; (either empty, or the widths of the column headers), then go through
;; each row in the result and update the max width needed to display
;; the column, although limit the max to a pre-set value (see col-max)
(define (max-column-widths query-result old-widths)
(fold update-widths old-widths (map get-column-widths query-result)))
;; Compute each column width for a particular row
(define (get-column-widths row)
(map string-length row))
;; Return the maximum of two column widths, but then have a max value of 40
(define (col-max a b)
(min (max a b) 40))
;; Updates an existing list of max column widths with a set of values
;; from another row
(define (update-widths new-values old-values)
(if (null? old-values)
(if (null? new-values) '()
new-values)
(cons (col-max (car old-values) (car new-values))
(update-widths (cdr new-values) (cdr old-values)))))
;; Formats a column specifier into table.column
(define (format-column col)
(string-append (car col) "." (cdr col)))
;; Makes a list of dashes to create a separator between the column
;; heading and the data values
(define (make-dashes widths)
(map (lambda (w) (xsubstring "-" 0 w)) widths))
;; Displays the results of a query
(define (display-results columns query-result)
(if (= (length columns) 0) (begin (display (length query-result))(newline))
(let* ((formatted-columns (map format-column columns))
(col-widths (max-column-widths query-result (get-column-widths formatted-columns))))
(display-row formatted-columns col-widths)
(display-row (make-dashes col-widths) col-widths)
(map (lambda (r) (display-row r col-widths)) query-result))))
;; Displays a row, separating each column by a |
(define (display-row row widths)
(if (null? row) (begin (display "|")(newline))
(begin
(display "|")
(display (string-pad-right (car row) (car widths)))
(display-row (cdr row) (cdr widths)))))
;; Reads a query from the command-line and executes it
(define (read-loop)
(display "Query: ")
(let ((line (read-line)))
(if (equal? line #!eof) #t
(begin
(let ((parsed (parse-string line sql-parser)))
(if parsed
(let ((prepared (prepare-query parsed)))
(if prepared
(let ((results (apply do-query prepared)))
(display-results (car prepared) results))))))
(read-loop)))))
;; Reads a query from a file and executes it
(define (read-sql-file filename)
(let ((parsed (parse-file filename sql-parser)))
(if parsed
(let ((prepared (prepare-query parsed)))
(if prepared
(let ((results (apply do-query prepared)))
(display-results (car prepared) results)))))))
(define (load-file filename)
(with-input-from-file filename
(lambda () (read-lines))))
(define (look-for-md-query lines curr-query curr-answer)
(if (null? lines) (begin (format #t "Can't find ## Query~%") #f)
(if (string= (string-trim-both (car lines)) "## Query")
(read-md-query (cdr lines) curr-query curr-answer)
(look-for-md-query (cdr lines) curr-query curr-answer))))
(define (read-md-query lines curr-query curr-answer)
(if (null? lines) (begin (format #t "Can't find ## Answer~%") #f)
(if (string= (string-trim-both (car lines)) "## Answer")
(read-md-answer (cdr lines) curr-query curr-answer)
(read-md-query (cdr lines) (string-trim-both (string-join (list curr-query (string-trim-both (car lines))) " ")) curr-answer))))
(define (read-md-answer lines curr-query curr-answer)
(if (null? lines)
(let ((parser (csv-parser)))
(list curr-query (map (lambda (l) (csv-record->list (car (parser l)))) (reverse curr-answer))))
(let ((trimmed (string-trim-both (car lines))))
(if (> (string-length trimmed) 0)
(read-md-answer (cdr lines) curr-query (cons trimmed curr-answer))
(read-md-answer (cdr lines) curr-query curr-answer)))))
(define (load-md-file filename)
(let* ((lines (load-file filename)))
(look-for-md-query lines "" '())))
(define (string-list-compare l1 l2)
(if (null? l1) #t
(let ((l1str (car l1))
(l2str (car l2)))
(if (equal? l1 l2) (string-list-compare (cdr l1) (cdr l2))
(string< l1str l2str)))))
(define (check-md-results is-count has-order-by results-orig expected)
(let* ((results (if is-count (list (list (number->string (length results-orig)))) results-orig))
(comparison (if has-order-by
(equal? results expected)
(equal? (sort results string-list-compare) (sort expected string-list-compare)))))
(if comparison
(format #t "Passed.~%")
(begin (format #t "Failed.~%~%Expected:~%")
(map (lambda (l) (display l)(newline)) expected)
(format #t "~%Got:~%")
(map (lambda (l) (display l)(newline)) results)))))
;; Reads a .md file, runs the query and checks the answer
(define (read-md-file filename)
(let* ((md-query-data (load-md-file filename))
(md-query (first md-query-data))
(md-answer (second md-query-data))
(parsed (parse-string md-query sql-parser)))
(if parsed
(let ((prepared (prepare-query parsed)))
(if prepared
(let ((results (apply do-query prepared)))
(check-md-results (= (length (car prepared)) 0)
(> (length (fourth prepared)) 0)
results md-answer)))))))
(if (> (length (argv)) 1)
(let ((filename (second (argv))))
(if (= (string-suffix-length filename ".md") 3)
(read-md-file filename)
(read-sql-file filename)))
(read-loop))
| false |
6898cb8770dddf22fbf1ba51b17c7c607272c0ca
|
6c40779f174bb777371a2edccfc8cee39692895f
|
/matrico.sh
|
367aa0b46770cdcf39feba306afcf9be4244b8a8
|
[
"zlib-acknowledgement"
] |
permissive
|
gramian/matrico
|
7231ed4f14fc33d22d4680354ba44e1580c81386
|
04ca69c08dcc8349daa70452c2c5a587027d82f5
|
refs/heads/main
| 2023-06-08T06:41:03.377110 | 2023-06-05T21:22:54 | 2023-06-05T21:22:54 | 16,047,652 | 2 | 0 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 99 |
sh
|
matrico.sh
|
#! /bin/sh
#|
exec csi -R matrico -q "$0" "$@"
|#
(print "\033]0;matrico\007") ; set window title
| false |
2cb362483d37377cd16fa3ec15a370ea5a63cac5
|
77e86210b440964b84525e72f00419c0e24c6113
|
/5.5.7_Eval_n_Compile.scm
|
840adf86ced191369fee39d1464d723fbe3d9ab6
|
[] |
no_license
|
MShrimp4/SICP_Problems
|
742bc3e2c3b1aec8655f2c2e67e56b1b32f7e985
|
bbcb95ef7c2e4bdf11c975e45516139df6d808b4
|
refs/heads/master
| 2020-03-21T23:58:01.768384 | 2019-11-16T23:10:42 | 2019-11-16T23:10:42 | 139,216,281 | 7 | 1 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 32,530 |
scm
|
5.5.7_Eval_n_Compile.scm
|
;;;Register_Machine_Monitor.scm needed
(define true #t)
(define false #f)
(define (make-compiled-procedure entry env)
(list 'compiled-procedure entry env))
(define (compiled-procedure? proc)
(tagged-list? proc 'compiled-procedure))
(define (compiled-procedure-entry c-proc) (cadr c-proc))
(define (compiled-procedure-env c-proc) (caddr c-proc))
(define (compile exp target linkage)
(cond ((self-evaluating? exp)
(compile-self-evaluating exp target linkage))
((quoted? exp) (compile-quoted exp target linkage))
((variable? exp)
(compile-variable exp target linkage))
((assignment? exp)
(compile-assignment exp target linkage))
((definition? exp)
(compile-definition exp target linkage))
((if? exp) (compile-if exp target linkage))
((lambda? exp) (compile-lambda exp target linkage))
((begin? exp)
(compile-sequence (begin-actions exp)
target
linkage))
((cond? exp) (compile (cond->if exp) target linkage))
((let? exp) (compile (let->lambda exp) target linkage));added for 5.50
((application? exp)
(compile-application exp target linkage))
(else
(error "Unknown expression type -- COMPILE" exp))))
(define (let? exp) (tagged-list? exp 'let))
(define (let->lambda exp)
(cons
(make-lambda (let-vars exp) (let-procs exp))
(let-vals exp)))
(define (let-binds exp) (cadr exp))
(define (let-vars exp) (map car (let-binds exp)))
(define (let-vals exp) (map cadr (let-binds exp)))
(define (let-procs exp) (cddr exp))
(define (compile-linkage linkage)
(cond ((eq? linkage 'return)
(make-instruction-sequence '(continue) '()
'((goto (reg continue)))))
((eq? linkage 'next)
(empty-instruction-sequence))
(else
(make-instruction-sequence '() '()
`((goto (label ,linkage)))))))
(define (end-with-linkage linkage instruction-sequence)
(preserving '(continue)
instruction-sequence
(compile-linkage linkage)))
(define (compile-self-evaluating exp target linkage)
(end-with-linkage linkage
(make-instruction-sequence '() (list target)
`((assign ,target (const ,exp))))))
(define (compile-quoted exp target linkage)
(end-with-linkage linkage
(make-instruction-sequence '() (list target)
`((assign ,target (const ,(text-of-quotation exp)))))))
(define (compile-variable exp target linkage)
(end-with-linkage linkage
(make-instruction-sequence '(env) (list target)
`((assign ,target
(op lookup-variable-value)
(const ,exp)
(reg env))))))
(define (compile-assignment exp target linkage)
(let ((var (assignment-variable exp))
(get-value-code
(compile (assignment-value exp) 'val 'next)))
(end-with-linkage linkage
(preserving '(env)
get-value-code
(make-instruction-sequence '(env val) (list target)
`((perform (op set-variable-value!)
(const ,var)
(reg val)
(reg env))
(assign ,target (const ok))))))))
(define (compile-definition exp target linkage)
(let ((var (definition-variable exp))
(get-value-code
(compile (definition-value exp) 'val 'next)))
(end-with-linkage linkage
(preserving '(env)
get-value-code
(make-instruction-sequence '(env val) (list target)
`((perform (op define-variable!)
(const ,var)
(reg val)
(reg env))
(assign ,target (const ok))))))))
(define (compile-if exp target linkage)
(let ((t-branch (make-label 'true-branch))
(f-branch (make-label 'false-branch))
(after-if (make-label 'after-if)))
(let ((consequent-linkage
(if (eq? linkage 'next) after-if linkage)))
(let ((p-code (compile (if-predicate exp) 'val 'next))
(c-code
(compile
(if-consequent exp) target consequent-linkage))
(a-code
(compile (if-alternative exp) target linkage)))
(preserving '(env continue)
p-code
(append-instruction-sequences
(make-instruction-sequence '(val) '()
`((test (op false?) (reg val))
(branch (label ,f-branch))))
(parallel-instruction-sequences
(append-instruction-sequences t-branch c-code)
(append-instruction-sequences f-branch a-code))
after-if))))))
(define (compile-sequence seq target linkage)
(if (last-exp? seq)
(compile (first-exp seq) target linkage)
(preserving '(env continue)
(compile (first-exp seq) target 'next)
(compile-sequence (rest-exps seq) target linkage))))
(define (compile-lambda exp target linkage)
(let ((proc-entry (make-label 'entry))
(after-lambda (make-label 'after-lambda)))
(let ((lambda-linkage
(if (eq? linkage 'next) after-lambda linkage)))
(append-instruction-sequences
(tack-on-instruction-sequence
(end-with-linkage lambda-linkage
(make-instruction-sequence '(env) (list target)
`((assign ,target
(op make-compiled-procedure)
(label ,proc-entry)
(reg env)))))
(compile-lambda-body exp proc-entry))
after-lambda))))
(define (compile-lambda-body exp proc-entry)
(let ((formals (lambda-parameters exp)))
(append-instruction-sequences
(make-instruction-sequence '(env proc argl) '(env)
`(,proc-entry
(assign env (op compiled-procedure-env) (reg proc))
(assign env
(op extend-environment)
(const ,formals)
(reg argl)
(reg env))))
(compile-sequence (lambda-body exp) 'val 'return))))
(define (compile-application exp target linkage)
(let ((proc-code (compile (operator exp) 'proc 'next))
(operand-codes
(map (lambda (operand) (compile operand 'val 'next))
(operands exp))))
(preserving '(env continue)
proc-code
(preserving '(proc continue)
(construct-arglist operand-codes)
(compile-procedure-call target linkage)))))
(define (construct-arglist operand-codes)
(let ((operand-codes (reverse operand-codes)))
(if (null? operand-codes)
(make-instruction-sequence '() '(argl)
'((assign argl (const ()))))
(let ((code-to-get-last-arg
(append-instruction-sequences
(car operand-codes)
(make-instruction-sequence '(val) '(argl)
'((assign argl (op list) (reg val)))))))
(if (null? (cdr operand-codes))
code-to-get-last-arg
(preserving '(env)
code-to-get-last-arg
(code-to-get-rest-args
(cdr operand-codes))))))))
(define (code-to-get-rest-args operand-codes)
(let ((code-for-next-arg
(preserving '(argl)
(car operand-codes)
(make-instruction-sequence '(val argl) '(argl)
'((assign argl
(op cons) (reg val) (reg argl)))))))
(if (null? (cdr operand-codes))
code-for-next-arg
(preserving '(env)
code-for-next-arg
(code-to-get-rest-args (cdr operand-codes))))))
(define (compile-procedure-call target linkage)
(let ((primitive-branch (make-label 'primitive-branch))
(compiled-branch (make-label 'compiled-branch))
(compound-branch (make-label 'compound-branch))
(after-compapp (make-label 'after-compapp))
(after-call (make-label 'after-call)))
(let ((compiled-linkage
(if (eq? linkage 'next) after-call linkage)))
(append-instruction-sequences
(make-instruction-sequence '(proc) '()
`((test (op primitive-procedure?) (reg proc))
(branch (label ,primitive-branch))
(test (op compound-procedure?) (reg proc))
(branch (label ,compound-branch))))
(parallel-instruction-sequences
(append-instruction-sequences
compiled-branch
(compile-proc-appl target compiled-linkage))
(parallel-instruction-sequences
(append-instruction-sequences
compound-branch
(if (eq? target 'val)
(end-with-linkage
compiled-linkage
(make-instruction-sequence
'(proc argl) all-regs
`((assign continue (label ,after-call))
(goto (reg compapp)))))
(append-instruction-sequences
(make-instruction-sequence
'(proc argl) `(,target continue)
`((assign continue (label ,after-compapp))
(goto (reg compapp))))
after-compapp
(make-instruction-sequence
'(val) (list target)
`((assign ,target (reg val)))))))
(append-instruction-sequences
primitive-branch
(end-with-linkage linkage
(make-instruction-sequence
'(proc argl) (list target)
`((assign ,target
(op apply-primitive-procedure)
(reg proc)
(reg argl))))))))
after-call))))
(define all-regs '(env proc val argl continue))
(define (compile-proc-appl target linkage)
(cond ((and (eq? target 'val) (not (eq? linkage 'return)))
(make-instruction-sequence '(proc) all-regs
`((assign continue (label ,linkage))
(assign val (op compiled-procedure-entry)
(reg proc))
(goto (reg val)))))
((and (not (eq? target 'val))
(not (eq? linkage 'return)))
(let ((proc-return (make-label 'proc-return)))
(make-instruction-sequence '(proc) all-regs
`((assign continue (label ,proc-return))
(assign val (op compiled-procedure-entry)
(reg proc))
(goto (reg val))
,proc-return
(assign ,target (reg val))
(goto (label ,linkage))))))
((and (eq? target 'val) (eq? linkage 'return))
(make-instruction-sequence '(proc continue) all-regs
'((assign val (op compiled-procedure-entry)
(reg proc))
(goto (reg val)))))
((and (not (eq? target 'val)) (eq? linkage 'return))
(errorf 'compile-proc-appl
"return linkage, target not val - ~s"
target))))
(define (registers-needed s)
(if (symbol? s) '() (car s)))
(define (registers-modified s)
(if (symbol? s) '() (cadr s)))
(define (statements s)
(if (symbol? s) (list s) (caddr s)))
(define (needs-register? seq reg)
(memq reg (registers-needed seq)))
(define (modifies-register? seq reg)
(memq reg (registers-modified seq)))
(define (append-instruction-sequences . seqs)
(define (append-2-sequences seq1 seq2)
(make-instruction-sequence
(list-union (registers-needed seq1)
(list-difference (registers-needed seq2)
(registers-modified seq1)))
(list-union (registers-modified seq1)
(registers-modified seq2))
(append (statements seq1) (statements seq2))))
(define (append-seq-list seqs)
(if (null? seqs)
(empty-instruction-sequence)
(append-2-sequences (car seqs)
(append-seq-list (cdr seqs)))))
(append-seq-list seqs))
(define (list-union s1 s2)
(cond ((null? s1) s2)
((memq (car s1) s2) (list-union (cdr s1) s2))
(else (cons (car s1) (list-union (cdr s1) s2)))))
(define (list-difference s1 s2)
(cond ((null? s1) '())
((memq (car s1) s2) (list-difference (cdr s1) s2))
(else (cons (car s1)
(list-difference (cdr s1) s2)))))
(define (preserving regs seq1 seq2)
(if (null? regs)
(append-instruction-sequences seq1 seq2)
(let ((first-reg (car regs)))
(if (and (needs-register? seq2 first-reg)
(modifies-register? seq1 first-reg))
(preserving (cdr regs)
(make-instruction-sequence
(list-union (list first-reg)
(registers-needed seq1))
(list-difference (registers-modified seq1)
(list first-reg))
(append `((save ,first-reg))
(statements seq1)
`((restore ,first-reg))))
seq2)
(preserving (cdr regs) seq1 seq2)))))
(define (tack-on-instruction-sequence seq body-seq)
(make-instruction-sequence
(registers-needed seq)
(registers-modified seq)
(append (statements seq) (statements body-seq))))
(define (parallel-instruction-sequences seq1 seq2)
(make-instruction-sequence
(list-union (registers-needed seq1)
(registers-needed seq2))
(list-union (registers-modified seq1)
(registers-modified seq2))
(append (statements seq1) (statements seq2))))
(define label-counter 0)
(define (new-label-number)
(set! label-counter (+ 1 label-counter))
label-counter)
(define (make-label name)
(string->symbol
(string-append (symbol->string name)
(number->string (new-label-number)))))
(define (make-instruction-sequence needs modifies statements)
(list needs modifies statements))
(define (empty-instruction-sequence)
(make-instruction-sequence '() '() '()))
(define apply-in-underlying-scheme apply)
(define (self-evaluating? exp)
(cond ((number? exp) true)
((string? exp) true)
(else false)))
(define (variable? exp) (symbol? exp))
(define (quoted? exp)
(tagged-list? exp 'quote))
(define (text-of-quotation exp) (cadr exp))
(define (tagged-list? exp tag)
(if (pair? exp)
(eq? (car exp) tag)
false))
(define (assignment? exp)
(tagged-list? exp 'set!))
(define (assignment-variable exp) (cadr exp))
(define (assignment-value exp) (caddr exp))
(define (definition? exp)
(tagged-list? exp 'define))
(define (definition-variable exp)
(if (symbol? (cadr exp))
(cadr exp)
(caadr exp)))
(define (definition-value exp)
(if (symbol? (cadr exp))
(caddr exp)
(make-lambda (cdadr exp) ; formal parameters
(cddr exp)))) ; body
(define (lambda? exp) (tagged-list? exp 'lambda))
(define (lambda-parameters exp) (cadr exp))
(define (lambda-body exp) (cddr exp))
(define (make-lambda parameters body)
(cons 'lambda (cons parameters body)))
(define (if? exp) (tagged-list? exp 'if))
(define (if-predicate exp) (cadr exp))
(define (if-consequent exp) (caddr exp))
(define (if-alternative exp)
(if (not (null? (cdddr exp)))
(cadddr exp)
'false))
(define (make-if predicate consequent alternative)
(list 'if predicate consequent alternative))
(define (begin? exp) (tagged-list? exp 'begin))
(define (begin-actions exp) (cdr exp))
(define (last-exp? seq) (null? (cdr seq)))
(define (no-more-exps? seq) (null? seq))
(define (first-exp seq) (car seq))
(define (rest-exps seq) (cdr seq))
(define (sequence->exp seq)
(cond ((null? seq) seq)
((last-exp? seq) (first-exp seq))
(else (make-begin seq))))
(define (make-begin seq) (cons 'begin seq))
(define (application? exp) (pair? exp))
(define (operator exp) (car exp))
(define (operands exp) (cdr exp))
(define (no-operands? ops) (null? ops))
(define (first-operand ops) (car ops))
(define (rest-operands ops) (cdr ops))
(define (cond? exp) (tagged-list? exp 'cond))
(define (cond-clauses exp) (cdr exp))
(define (cond-else-clause? clause)
(eq? (cond-predicate clause) 'else))
(define (cond-predicate clause) (car clause))
(define (cond-actions clause) (cdr clause))
(define (cond->if exp)
(expand-clauses (cond-clauses exp)))
(define (expand-clauses clauses)
(if (null? clauses)
'false ; no else clause
(let ((first (car clauses))
(rest (cdr clauses)))
(if (cond-else-clause? first)
(if (null? rest)
(sequence->exp (cond-actions first))
(error "ELSE clause isn't last -- COND->IF"
clauses))
(make-if (cond-predicate first)
(sequence->exp (cond-actions first))
(expand-clauses rest))))))
(define true #t)
(define false #f)
(define (true? x)
(not (eq? x false)))
(define (false? x)
(eq? x false))
(define (make-procedure parameters body env)
(list 'procedure parameters body env))
(define (compound-procedure? p)
(tagged-list? p 'procedure))
(define (procedure-parameters p) (cadr p))
(define (procedure-body p) (caddr p))
(define (procedure-environment p) (cadddr p))
(define (enclosing-environment env) (cdr env))
(define (first-frame env) (car env))
(define the-empty-environment '())
(define (make-frame variables values)
(cons variables values))
(define (frame-variables frame) (car frame))
(define (frame-values frame) (cdr frame))
(define (add-binding-to-frame! var val frame)
(set-car! frame (cons var (car frame)))
(set-cdr! frame (cons val (cdr frame))))
(define (extend-environment vars vals base-env)
(if (= (length vars) (length vals))
(cons (make-frame vars vals) base-env)
(if (< (length vars) (length vals))
(error "Too many arguments supplied" vars vals)
(error "Too few arguments supplied" vars vals))))
(define (lookup-variable-value var env)
(define (env-loop env)
(define (scan vars vals)
(cond ((null? vars)
(env-loop (enclosing-environment env)))
((eq? var (car vars))
(car vals))
(else (scan (cdr vars) (cdr vals)))))
(if (eq? env the-empty-environment)
(error "Unbound variable" var)
(let ((frame (first-frame env)))
(scan (frame-variables frame)
(frame-values frame)))))
(env-loop env))
(define (set-variable-value! var val env)
(define (env-loop env)
(define (scan vars vals)
(cond ((null? vars)
(env-loop (enclosing-environment env)))
((eq? var (car vars))
(set-car! vals val))
(else (scan (cdr vars) (cdr vals)))))
(if (eq? env the-empty-environment)
(error "Unbound variable -- SET!" var)
(let ((frame (first-frame env)))
(scan (frame-variables frame)
(frame-values frame)))))
(env-loop env))
(define (define-variable! var val env)
(let ((frame (first-frame env)))
(define (scan vars vals)
(cond ((null? vars)
(add-binding-to-frame! var val frame))
((eq? var (car vars))
(set-car! vals val))
(else (scan (cdr vars) (cdr vals)))))
(scan (frame-variables frame)
(frame-values frame))))
(define (setup-environment)
(let ((initial-env
(extend-environment (primitive-procedure-names)
(primitive-procedure-objects)
the-empty-environment)))
(define-variable! 'true true initial-env)
(define-variable! 'false false initial-env)
initial-env))
(define (primitive-procedure? proc)
(tagged-list? proc 'primitive))
(define (primitive-implementation proc) (cadr proc))
(define (primitive-procedure-names)
(map car
primitive-procedures))
(define (primitive-procedure-objects)
(map (lambda (proc) (list 'primitive (cadr proc)))
primitive-procedures))
(define (apply-primitive-procedure proc args)
(apply-in-underlying-scheme
(primitive-implementation proc) args))
(define input-prompt ";;; M-Eval input:")
(define output-prompt ";;; M-Eval value:")
(define (prompt-for-input string)
(newline) (newline) (display string) (newline))
(define (announce-output string)
(newline) (display string) (newline))
(define (user-print object)
(cond ((compound-procedure? object)
(display (list 'compound-procedure
(procedure-parameters object)
(procedure-body object)
'<procedure-env>)))
((compiled-procedure? object) (display "<compiled-procedure>"))
(else (display object))))
(define the-global-environment (setup-environment))
(define (get-global-environment) the-global-environment)
(define (empty-arglist) '())
(define (adjoin-arg arg arglist)
(append arglist (list arg)))
(define (last-operand? ops)
(null? (cdr ops)))
(define (print-stack-statistics)
((eceval 'print-stack-statistics)))
(define eceval-operations
(list
(list 'set-car! set-car!)
(list 'set-cdr! set-cdr!)
(list 'length length)
(list 'compile-and-run? (lambda (x)
(tagged-list? x 'compile-and-run)))
(list 'asm-compile
(lambda (code)
(assemble (statements (compile (cadadr code) 'val 'return))
eceval)))
(list 'compile-raw
(lambda (code)
(assemble (statements (compile code 'val 'return))
eceval)))
(list 'apply ;for running meta-eval (Ex 5.50)
(lambda (proc args) (apply (cadr proc) args)))
(list 'false? (lambda (x) (not (true? x))))
(list 'true? true?)
(list 'print-stack-statistics print-stack-statistics)
(list 'first-exp first-exp)
(list 'rest-operands rest-operands)
(list 'adjoin-arg adjoin-arg)
(list 'prompt-for-input prompt-for-input)
(list 'read read)
(list 'get-global-environment get-global-environment)
(list 'announce-output announce-output)
(list 'user-print user-print)
(list 'self-evaluating? self-evaluating?)
(list 'variable? variable?)
(list 'quoted? quoted?)
(list 'assignment? assignment?)
(list 'definition? definition?)
(list 'if? if?)
(list 'lambda? lambda?)
(list 'begin? begin?)
(list 'application? application?)
(list 'lookup-variable-value lookup-variable-value)
(list 'text-of-quotation text-of-quotation)
(list 'lambda-parameters lambda-parameters)
(list 'lambda-body lambda-body)
(list 'make-procedure make-procedure)
(list 'operands operands)
(list 'operator operator)
(list 'empty-arglist empty-arglist)
(list 'no-operands? no-operands?)
(list 'first-operand first-operand)
(list 'last-operand? last-operand?)
(list 'primitive-procedure? primitive-procedure?)
(list 'compound-procedure? compound-procedure?)
(list 'compiled-procedure? compiled-procedure?)
(list 'compiled-procedure-entry compiled-procedure-entry)
(list 'compiled-procedure-env compiled-procedure-env)
(list 'make-compiled-procedure make-compiled-procedure)
(list 'apply-primitive-procedure apply-primitive-procedure)
(list 'procedure-parameters procedure-parameters)
(list 'procedure-environment procedure-environment)
(list 'extend-environment extend-environment)
(list 'procedure-body procedure-body)
(list 'begin-actions begin-actions)
(list 'last-exp? last-exp?)
(list 'rest-exps rest-exps)
(list 'if-predicate if-predicate)
(list 'true? true?)
(list 'if-alternative if-alternative)
(list 'if-consequent if-consequent)
(list 'assignment-variable assignment-variable)
(list 'assignment-value assignment-value)
(list 'set-variable-value! set-variable-value!)
(list 'definition-variable definition-variable)
(list 'definition-value definition-value)
(list 'define-variable! define-variable!)
(list 'no-more-exps? no-more-exps?)
(list 'list list)
(list 'cons cons)
(list 'car car)
(list 'cdr cdr)
(list '+ +)
(list '- -)
(list '* *)
(list '/ /)
(list '= =)
(list '< <)
(list '> >)
(list 'eq? eq?)
(list 'null? null?)
(list 'symbol? symbol?)
(list 'number? number?)
(list 'string? string?)
(list 'pair? pair?)
(list 'caar caar)
(list 'cadr cadr)
(list 'cdar cdar)
(list 'cddr cddr)
(list 'caddr caddr)
(list 'cdadr cdadr)
(list 'cadddr cadddr)
(list 'error errorf)
(list 'display display)
(list 'newline newline)))
(define primitive-procedures eceval-operations)
(define eceval
(make-machine #f
'(exp env val proc argl continue unev compapp)
eceval-operations
'(
(assign compapp (label compound-apply))
(branch (label external-entry))
(goto (label read-eval-print-loop))
external-entry
(perform (op initialize-stack))
(assign env (op get-global-environment))
(assign continue (label print-compile-result))
(goto (reg val))
read-eval-print-loop
(perform (op initialize-stack))
(perform (op prompt-for-input)
(const ";;; EC-Eval input:"))
(assign exp (op read))
(assign env (op get-global-environment))
(assign continue (label print-result))
(goto (label eval-dispatch))
print-result
(perform (op print-stack-statistics))
(perform (op announce-output)
(const ";;; EC-Eval value:"))
(perform (op user-print) (reg val))
(goto (label read-eval-print-loop))
print-compile-result
(perform (op print-stack-statistics))
(perform (op announce-output)
(const ";;; Compile-Execute value:"))
(perform (op user-print) (reg val))
(goto (label read-compile-execute-print))
read-compile-execute-print
(perform (op initialize-stack))
(perform (op prompt-for-input)
(const ";;; Compile-Execute input:"))
(assign exp (op read))
(assign env (op get-global-environment))
(assign continue (label print-compile-result))
(assign val (op compile-raw) (reg exp))
(goto (reg val))
eval-dispatch
(test (op compile-and-run?) (reg exp))
(branch (label ev-compile-and-run))
(test (op self-evaluating?) (reg exp))
(branch (label ev-self-eval))
(test (op variable?) (reg exp))
(branch (label ev-variable))
(test (op quoted?) (reg exp))
(branch (label ev-quoted))
(test (op assignment?) (reg exp))
(branch (label ev-assignment))
(test (op definition?) (reg exp))
(branch (label ev-definition))
(test (op if?) (reg exp))
(branch (label ev-if))
(test (op lambda?) (reg exp))
(branch (label ev-lambda))
(test (op begin?) (reg exp))
(branch (label ev-begin))
(test (op application?) (reg exp))
(branch (label ev-application))
(goto (label unknown-expression-type))
ev-compile-and-run
(assign continue (label print-result))
(assign val (op asm-compile) (reg exp))
(perform (op initialize-stack))
(goto (reg val))
ev-self-eval
(assign val (reg exp))
(goto (reg continue))
ev-variable
(assign val
(op lookup-variable-value)
(reg exp)
(reg env))
(goto (reg continue))
ev-quoted
(assign val
(op text-of-quotation)
(reg exp))
(goto (reg continue))
ev-lambda
(assign unev
(op lambda-parameters)
(reg exp))
(assign exp
(op lambda-body)
(reg exp))
(assign val
(op make-procedure)
(reg unev)
(reg exp)
(reg env))
(goto (reg continue))
ev-apply-appl
(save continue)
(save env)
(assign unev (op appl-operands) )
ev-application
(save continue)
(save env)
(assign unev (op operands) (reg exp))
(save unev)
(assign exp (op operator) (reg exp))
(assign
continue (label ev-appl-did-operator))
(goto (label eval-dispatch))
ev-appl-did-operator
(restore unev) ; the operands
(restore env)
(assign argl (op empty-arglist))
(assign proc (reg val)) ; the operator
(test (op no-operands?) (reg unev))
(branch (label apply-dispatch))
(save proc)
ev-appl-operand-loop
(save argl)
(assign exp
(op first-operand)
(reg unev))
(test (op last-operand?) (reg unev))
(branch (label ev-appl-last-arg))
(save env)
(save unev)
(assign continue
(label ev-appl-accumulate-arg))
(goto (label eval-dispatch))
ev-appl-accumulate-arg
(restore unev)
(restore env)
(restore argl)
(assign argl
(op adjoin-arg)
(reg val)
(reg argl))
(assign unev
(op rest-operands)
(reg unev))
(goto (label ev-appl-operand-loop))
ev-appl-last-arg
(assign continue
(label ev-appl-accum-last-arg))
(goto (label eval-dispatch))
ev-appl-accum-last-arg
(restore argl)
(assign argl
(op adjoin-arg)
(reg val)
(reg argl))
(restore proc)
(goto (label apply-dispatch))
apply-dispatch
(test (op primitive-procedure?) (reg proc))
(branch (label primitive-apply))
(test (op compound-procedure?) (reg proc))
(branch (label compound-apply))
(test (op compiled-procedure?) (reg proc))
(branch (label compiled-apply))
(goto (label unknown-procedure-type))
primitive-apply
(assign val (op apply-primitive-procedure)
(reg proc)
(reg argl))
(restore continue)
(goto (reg continue))
compiled-apply
(restore continue)
(assign val (op compiled-procedure-entry) (reg proc))
(goto (reg val))
compound-apply
(assign unev
(op procedure-parameters)
(reg proc))
(assign env
(op procedure-environment)
(reg proc))
(assign env
(op extend-environment)
(reg unev)
(reg argl)
(reg env))
(assign unev
(op procedure-body)
(reg proc))
(goto (label ev-sequence))
ev-begin
(assign unev
(op begin-actions)
(reg exp))
(save continue)
(goto (label ev-sequence))
ev-sequence
(assign exp (op first-exp) (reg unev))
(test (op last-exp?) (reg unev))
(branch (label ev-sequence-last-exp))
(save unev)
(save env)
(assign continue
(label ev-sequence-continue))
(goto (label eval-dispatch))
ev-sequence-continue
(restore env)
(restore unev)
(assign unev
(op rest-exps)
(reg unev))
(goto (label ev-sequence))
ev-sequence-last-exp
(restore continue)
(goto (label eval-dispatch))
;Non tail recursion ver
;ev-sequence
; (test (op no-more-exps?) (reg unev))
; (branch (label ev-sequence-end))
; (assign exp (op first-exp) (reg unev))
; (save unev)
; (save env)
; (assign continue
; (label ev-sequence-continue))
; (goto (label eval-dispatch))
;ev-sequence-continue
; (restore env)
; (restore unev)
; (assign unev (op rest-exps) (reg unev))
; (goto (label ev-sequence))
;ev-sequence-end
; (restore continue)
; (goto (reg continue))
ev-if
(save exp) ; save expression for later
(save env)
(save continue)
(assign continue (label ev-if-decide))
(assign exp (op if-predicate) (reg exp))
; evaluate the predicate:
(goto (label eval-dispatch))
ev-if-decide
(restore continue)
(restore env)
(restore exp)
(test (op true?) (reg val))
(branch (label ev-if-consequent))
ev-if-alternative
(assign exp (op if-alternative) (reg exp))
(goto (label eval-dispatch))
ev-if-consequent
(assign exp (op if-consequent) (reg exp))
(goto (label eval-dispatch))
ev-assignment
(assign unev
(op assignment-variable)
(reg exp))
(save unev) ; save variable for later
(assign exp
(op assignment-value)
(reg exp))
(save env)
(save continue)
(assign continue
(label ev-assignment-1))
; evaluate the assignment value:
(goto (label eval-dispatch))
ev-assignment-1
(restore continue)
(restore env)
(restore unev)
(perform (op set-variable-value!)
(reg unev)
(reg val)
(reg env))
(assign val
(const ok))
(goto (reg continue))
ev-definition
(assign unev
(op definition-variable)
(reg exp))
(save unev) ; save variable for later
(assign exp
(op definition-value)
(reg exp))
(save env)
(save continue)
(assign continue (label ev-definition-1))
; evaluate the definition value:
(goto (label eval-dispatch))
ev-definition-1
(restore continue)
(restore env)
(restore unev)
(perform (op define-variable!)
(reg unev)
(reg val)
(reg env))
(assign val (const ok))
(goto (reg continue))
unknown-expression-type
(assign
val
(const unknown-expression-type-error))
(goto (label signal-error))
unknown-procedure-type
; clean up stack (from apply-dispatch):
(restore continue)
(assign
val
(const unknown-procedure-type-error))
(goto (label signal-error))
signal-error
(perform (op user-print) (reg val))
(goto (label read-eval-print-loop))
)))
;(compile-run-eceval )
(define (compile-and-go expression)
(let ((instructions
(assemble (statements (compile expression 'val 'return))
eceval)))
(set! the-global-environment (setup-environment))
(set-register-contents! eceval 'val instructions)
(set-register-contents! eceval 'flag true)
(start eceval)))
(compile-and-go '(define (fib n)
(if (< n 2)
n
(+ (fib (- n 1)) (fib (- n 2))))))
(define (fib2 n)
(if (< n 2)
n
(+ (fib2 (- n 1)) (fib2 (- n 2)))))
| false |
51f7deb5286a895fab3ecb00a1836b62f67ac5eb
|
f64f5a8f22d6eae00d4d50d899fdecb65a8539dc
|
/srfi/69.sld
|
54375b4e23665c7b487c145ecde92071732a5369
|
[
"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 | 16,944 |
sld
|
69.sld
|
;; http://srfi.schemers.org/srfi-69/srfi-69.html
(define-library (srfi 69)
(export make-hash-table
hash-table?
hash-table-copy
hash-table-delete!
hash-table-merge!
hash-table-exists?
hash-table-walk
hash-table-ref
hash-table-ref/default
hash-table-set!
hash-table-update!
hash-table-update!/default
hash-table-keys
hash-table-values
hash-table->alist
alist->hash-table
hash-table-cons!
hash-table-size
)
(import (scheme base))
(cond-expand
(foment (import (scheme char)
(scheme cxr)
(scheme complex)))
(gauche
(import
(prefix (only (gauche base)
make-hash-table
hash-table?
hash-table-get
hash-table-exists?
hash-table-put!
hash-table-copy
hash-table-delete!
hash-table-update!
hash-table-keys
hash-table-values
hash-table->alist
alist->hash-table) gauche-)))
(sagittarius (import (rnrs)))
)
(begin
(cond-expand
(gauche
;; http://practical-scheme.net/gauche/man/gauche-refe_55.html
(define (make-hash-table . args)
(gauche-make-hash-table 'equal?))
(define hash-table? gauche-hash-table?)
(define hash-table-ref gauche-hash-table-get)
(define hash-table-ref/default gauche-hash-table-get)
(define hash-table-exists? gauche-hash-table-exists?)
(define hash-table-set! gauche-hash-table-put!)
(define hash-table-copy gauche-hash-table-copy)
(define hash-table-delete! gauche-hash-table-delete!)
(define hash-table-update! gauche-hash-table-update!)
(define hash-table-keys gauche-hash-table-keys)
(define hash-table-values gauche-hash-table-values)
(define hash-table->alist gauche-hash-table->alist)
(define alist->hash-table gauche-alist->hash-table)
)
(sagittarius
;; http://ktakashi.github.io/sagittarius-ref.html#rnrs.hashtables.6
(define (make-hash-table . args)
(let* ((args-len (length args))
(tester (if (> args-len 0) (list-ref args 0) equal?))
(hasher (if (> args-len 1) (list-ref args 1) equal-hash)))
(make-hashtable hasher tester)))
(define hash-table? hashtable?)
(define (hash-table-copy hash-table)
(hashtable-copy hash-table #t))
(define hash-table-ref hashtable-ref)
(define hash-table-ref/default hashtable-ref)
(define hash-table-set! hashtable-set!)
(define (hash-table-keys hash-table)
(vector->list (hashtable-keys hash-table)))
(define (hash-table-values hash-table)
(map (lambda (key)
(hash-table-ref hash-table key))
(hash-table-keys hash-table)))
(define hash-table-exists? hashtable-contains?)
(define hash-table-delete! hashtable-delete!)
(define (hash-table-update! hash-table key function)
(hash-table-set! hash-table key
(function (hash-table-ref hash-table key))))
(define hash-table-update!/default hashtable-update!))
(else
;; srfi-69 reference implementation
(define *default-bound* (- (expt 2 29) 3))
(define (%string-hash s ch-conv bound)
(let ((hash 31)
(len (string-length s)))
(do ((index 0 (+ index 1)))
((>= index len) (modulo hash bound))
(set! hash (modulo
(+ (* 37 hash)
(char->integer (ch-conv (string-ref s index))))
*default-bound*)))))
(define (string-hash s . maybe-bound)
(let ((bound (if (null? maybe-bound)
*default-bound*
(car maybe-bound))))
(%string-hash s (lambda (x) x) bound)))
(define (string-ci-hash s . maybe-bound)
(let ((bound (if (null? maybe-bound)
*default-bound*
(car maybe-bound))))
(%string-hash s char-downcase bound)))
(define (symbol-hash s . maybe-bound)
(let ((bound (if (null? maybe-bound)
*default-bound*
(car maybe-bound))))
(%string-hash (symbol->string s) (lambda (x) x) bound)))
(define (hash obj . maybe-bound)
(let ((bound (if (null? maybe-bound)
*default-bound*
(car maybe-bound))))
(cond ((integer? obj) (modulo obj bound))
((string? obj) (string-hash obj bound))
((symbol? obj) (symbol-hash obj bound))
((real? obj)
(modulo (+ (numerator obj) (denominator obj)) bound))
((number? obj)
(modulo (+ (hash (real-part obj))
(* 3 (hash (imag-part obj))))
bound))
((char? obj) (modulo (char->integer obj) bound))
((vector? obj) (vector-hash obj bound))
((pair? obj) (modulo (+ (hash (car obj))
(* 3 (hash (cdr obj))))
bound))
((null? obj) 0)
((not obj) 0)
((procedure? obj)
(error "hash: procedures cannot be hashed" obj))
(else 1))))
(define hash-by-identity hash)
(define (vector-hash v bound)
(let ((hashvalue 571)
(len (vector-length v)))
(do ((index 0 (+ index 1)))
((>= index len) (modulo hashvalue bound))
(set! hashvalue (modulo (+ (* 257 hashvalue)
(hash (vector-ref v index)))
*default-bound*)))))
(define %make-hash-node cons)
(define %hash-node-set-value! set-cdr!)
(define %hash-node-key car)
(define %hash-node-value cdr)
(define-record-type <srfi-hash-table>
(%make-hash-table size hash compare associate entries)
hash-table?
(size hash-table-size hash-table-set-size!)
(hash hash-table-hash-function)
(compare hash-table-equivalence-function)
(associate hash-table-association-function)
(entries hash-table-entries hash-table-set-entries!))
(define *default-table-size* 64)
(define (appropriate-hash-function-for comparison)
(or (and (eq? comparison eq?) hash-by-identity)
(and (eq? comparison string=?) string-hash)
(and (eq? comparison string-ci=?) string-ci-hash)
hash))
(define (make-hash-table . args)
(let* ((comparison (if (null? args) equal? (car args)))
(hash
(if (or (null? args) (null? (cdr args)))
(appropriate-hash-function-for comparison) (cadr args)))
(size
(if (or (null? args) (null? (cdr args)) (null? (cddr args)))
*default-table-size* (caddr args)))
(association
(or (and (eq? comparison eq?) assq)
(and (eq? comparison eqv?) assv)
(and (eq? comparison equal?) assoc)
(letrec
((associate
(lambda (val alist)
(cond ((null? alist) #f)
((comparison val (caar alist)) (car alist))
(else (associate val (cdr alist)))))))
associate))))
(%make-hash-table 0 hash comparison association
(make-vector size '()))))
(define (make-hash-table-maker comp hash)
(lambda args (apply make-hash-table (cons comp (cons hash args)))))
(define make-symbol-hash-table
(make-hash-table-maker eq? symbol-hash))
(define make-string-hash-table
(make-hash-table-maker string=? string-hash))
(define make-string-ci-hash-table
(make-hash-table-maker string-ci=? string-ci-hash))
(define make-integer-hash-table
(make-hash-table-maker = modulo))
(define (%hash-table-hash hash-table key)
((hash-table-hash-function hash-table)
key (vector-length (hash-table-entries hash-table))))
(define (%hash-table-find entries associate hash key)
(associate key (vector-ref entries hash)))
(define (%hash-table-add! entries hash key value)
(vector-set! entries hash
(cons (%make-hash-node key value)
(vector-ref entries hash))))
(define (%hash-table-delete! entries compare hash key)
(let ((entrylist (vector-ref entries hash)))
(cond ((null? entrylist) #f)
((compare key (caar entrylist))
(vector-set! entries hash (cdr entrylist)) #t)
(else
(let loop ((current (cdr entrylist)) (previous entrylist))
(cond ((null? current) #f)
((compare key (caar current))
(set-cdr! previous (cdr current)) #t)
(else (loop (cdr current) current))))))))
(define (%hash-table-walk proc entries)
(do ((index (- (vector-length entries) 1) (- index 1)))
((< index 0)) (for-each proc (vector-ref entries index))))
(define (%hash-table-maybe-resize! hash-table)
(let* ((old-entries (hash-table-entries hash-table))
(hash-length (vector-length old-entries)))
(if (> (hash-table-size hash-table) hash-length)
(let* ((new-length (* 2 hash-length))
(new-entries (make-vector new-length '()))
(hash (hash-table-hash-function hash-table)))
(%hash-table-walk
(lambda (node)
(%hash-table-add!
new-entries
(hash (%hash-node-key node) new-length)
(%hash-node-key node) (%hash-node-value node)))
old-entries)
(hash-table-set-entries! hash-table new-entries)))))
(define (hash-table-ref hash-table key . maybe-default)
(cond ((%hash-table-find (hash-table-entries hash-table)
(hash-table-association-function hash-table)
(%hash-table-hash hash-table key) key)
=> %hash-node-value)
((null? maybe-default)
(error "hash-table-ref: no value associated with" key))
(else ((car maybe-default)))))
(define (hash-table-ref/default hash-table key default)
(hash-table-ref hash-table key (lambda () default)))
(define (hash-table-set! hash-table key value)
(let ((hash (%hash-table-hash hash-table key))
(entries (hash-table-entries hash-table)))
(cond ((%hash-table-find entries
(hash-table-association-function hash-table)
hash key)
=> (lambda (node) (%hash-node-set-value! node value)))
(else (%hash-table-add! entries hash key value)
(hash-table-set-size! hash-table
(+ 1 (hash-table-size hash-table)))
(%hash-table-maybe-resize! hash-table)))))
(define (hash-table-update! hash-table key function . maybe-default)
(let ((hash (%hash-table-hash hash-table key))
(entries (hash-table-entries hash-table)))
(cond ((%hash-table-find entries
(hash-table-association-function hash-table)
hash key)
=> (lambda (node)
(%hash-node-set-value!
node (function (%hash-node-value node)))))
((null? maybe-default)
(error "hash-table-update!: no value exists for key" key))
(else (%hash-table-add! entries hash key
(function ((car maybe-default))))
(hash-table-set-size! hash-table
(+ 1 (hash-table-size hash-table)))
(%hash-table-maybe-resize! hash-table)))))
(define (hash-table-update!/default hash-table key function default)
(hash-table-update! hash-table key function (lambda () default)))
(define (hash-table-delete! hash-table key)
(if (%hash-table-delete! (hash-table-entries hash-table)
(hash-table-equivalence-function hash-table)
(%hash-table-hash hash-table key) key)
(hash-table-set-size! hash-table
(- (hash-table-size hash-table) 1))))
(define (hash-table-exists? hash-table key)
(and (%hash-table-find (hash-table-entries hash-table)
(hash-table-association-function hash-table)
(%hash-table-hash hash-table key) key) #t))
(define (hash-table-walk hash-table proc)
(%hash-table-walk
(lambda (node) (proc (%hash-node-key node) (%hash-node-value node)))
(hash-table-entries hash-table)))
(define (hash-table-fold hash-table f acc)
(hash-table-walk hash-table
(lambda (key value) (set! acc (f key value acc))))
acc)
(define (alist->hash-table alist . args)
(let* ((comparison (if (null? args) equal? (car args)))
(hash
(if (or (null? args) (null? (cdr args)))
(appropriate-hash-function-for comparison) (cadr args)))
(size
(if (or (null? args) (null? (cdr args)) (null? (cddr args)))
(max *default-table-size*
(* 2 (length alist))) (caddr args)))
(hash-table (make-hash-table comparison hash size)))
(for-each
(lambda (elem)
(hash-table-update!/default
hash-table (car elem) (lambda (x) x) (cdr elem)))
alist)
hash-table))
(define (hash-table->alist hash-table)
(hash-table-fold hash-table
(lambda (key val acc) (cons (cons key val) acc)) '()))
(define (hash-table-copy hash-table)
(let ((new (make-hash-table (hash-table-equivalence-function hash-table)
(hash-table-hash-function hash-table)
(max *default-table-size*
(* 2 (hash-table-size hash-table))))))
(hash-table-walk hash-table
(lambda (key value) (hash-table-set! new key value)))
new))
(define (hash-table-merge! hash-table1 hash-table2)
(hash-table-walk
hash-table2
(lambda (key value) (hash-table-set! hash-table1 key value)))
hash-table1)
(define (hash-table-keys hash-table)
(hash-table-fold hash-table (lambda (key val acc) (cons key acc)) '()))
(define (hash-table-values hash-table)
(hash-table-fold hash-table (lambda (key val acc) (cons val acc)) '()))
))
(cond-expand
((or gauche)
(define (hash-table-update!/default table key func default)
(hash-table-set!
table key
(func (hash-table-ref/default table key default)))))
(else))
(cond-expand
((or sagittarius)
(define (hash-table->alist table)
(map
(lambda (key) (cons key (hash-table-ref table key)))
(hash-table-keys table))))
(else))
(cond-expand
((or sagittarius)
(define (alist->hash-table alist)
(let ((table (make-hash-table)))
(for-each
(lambda (nv)
(hash-table-set! table (car nv) (cdr nv)))
alist)
table)))
(else))
(cond-expand
((or sagittarius gauche)
(define (hash-table-merge! dst-table src-table)
(for-each
(lambda (key)
(hash-table-set! dst-table key (hash-table-ref src-table)))
(hash-table-keys src-table))))
(else))
(define (hash-table-cons! ht key value)
(cond ((hash-table-exists? ht key)
(let ((previous (hash-table-ref ht key)))
(hash-table-set! ht key (cons value previous))))
(else
(hash-table-set! ht key (list value)))))
))
| false |
dfb27ff7515c4a993dd7f6f2589dbbcddfd7c0be
|
665da87f9fefd8678b0635e31df3f3ff28a1d48c
|
/tests/debug/compilation/simple.scm
|
9539e90d87ad242d09aae581a50544bfa10a5e0e
|
[
"MIT"
] |
permissive
|
justinethier/cyclone
|
eeb782c20a38f916138ac9a988dc53817eb56e79
|
cc24c6be6d2b7cc16d5e0ee91f0823d7a90a3273
|
refs/heads/master
| 2023-08-30T15:30:09.209833 | 2023-08-22T02:11:59 | 2023-08-22T02:11:59 | 31,150,535 | 862 | 64 |
MIT
| 2023-03-04T15:15:37 | 2015-02-22T03:08:21 |
Scheme
|
UTF-8
|
Scheme
| false | false | 389 |
scm
|
simple.scm
|
;; Experimenting with primitives and continuations.
;; There are several primitives that do not require conts. Can we
;; compile them in such as way that they are not wrapped in a cont?
;; idea is to reduce compiled code, and number of allocated closures.
(import
(scheme base)
(scheme write))
(define (test a b c)
(write
(cons
(+ a b c)
(- a b c))))
(test 1 2 3)
| false |
2c257bbcf46c069eae37ed49960ce13e73d70f09
|
2bcf33718a53f5a938fd82bd0d484a423ff308d3
|
/programming/sicp/ch1/ex-1.10.scm
|
f7d6d5817cb3c3a719bcd9e88ada60764f867e71
|
[] |
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 | 779 |
scm
|
ex-1.10.scm
|
;; https://mitpress.mit.edu/sites/default/files/sicp/full-text/book/book-Z-H-11.html#%_thm_1.10
;; Ackermann's function (seems to be a variant?)
(define (A x y)
(cond ((= y 0) 0)
((= x 0) (* 2 y))
((= y 1) 2)
(else (A (- x 1) (A x (- y 1))))))
(A 1 10)
;; (A 0 (A 1 9))
;; after much expansion
;; (A 0 (expt 2 9)) = 1024
(A 2 4)
;; (A 1 (A 1 4))
;; (A 1 (expt 2 4))
;; (A 1 16)
;; (A 0 (expt 2 15)) = 65536
(A 3 3)
;; (A 2 (A 3 2))
;; (A 2 (A 2 (A 3 1)))
;; (A 2 (A 2 2))
;; (A 2 (A 1 (A 2 1)))
;; (A 2 (A 1 2))
;; (A 2 (A 0 (A 1 1)))
;; (A 2 4) = 65536
(define (f n) (A 0 n))
;; 2n
(define (g n) (A 1 n))
;; 0 n = 0
;; 2^n n > 0
(define (h n) (A 2 n)) ;
;; 0 n = 0
;; 2 n = 1
;; 2^2^2^... n-1 times n > 1
| false |
9f97c90197f0a85f2e9374a8198a716afd114c7a
|
9ade40b4c752285122bc184fbd02b2280684c19b
|
/srfi-181-192/srfi/192.sld
|
b1395631db11496abf3317e1f6a34470473d8074
|
[
"MIT"
] |
permissive
|
scheme-requests-for-implementation/srfi-192
|
3aeea83718d5d178af8d8e3e2a586e355d75b38a
|
fcf61311582916a365ba4d81ca3c8af5a81814e0
|
refs/heads/master
| 2022-12-10T09:11:06.198672 | 2020-09-08T22:39:26 | 2020-09-08T22:39:26 | 255,795,036 | 0 | 3 | null | 2020-09-08T22:39:27 | 2020-04-15T03:31:17 |
Scheme
|
UTF-8
|
Scheme
| false | false | 450 |
sld
|
192.sld
|
(define-library (srfi 192)
(export port-has-port-position?
port-position
port-has-set-port-position!?
set-port-position!
i/o-invalid-position-error?
make-i/o-invalid-position-error)
(cond-expand
(gauche
(import (scheme base)
(gauche base))
(include "192.gauche.scm"))
(else
(import (scheme base)
(srfi 181 generic))
(include "192.impl.scm"))
))
| false |
a944461635d40ad6e3db582b23d26efe2ab0ba9d
|
4f30ba37cfe5ec9f5defe52a29e879cf92f183ee
|
/src/sasm/sasm-core.scm
|
e522072f56ef85b692903570c16d26b188e36836
|
[
"MIT"
] |
permissive
|
rtrusso/scp
|
e31ecae62adb372b0886909c8108d109407bcd62
|
d647639ecb8e5a87c0a31a7c9d4b6a26208fbc53
|
refs/heads/master
| 2021-07-20T00:46:52.889648 | 2021-06-14T00:31:07 | 2021-06-14T00:31:07 | 167,993,024 | 8 | 1 |
MIT
| 2021-06-14T00:31:07 | 2019-01-28T16:17:18 |
Scheme
|
UTF-8
|
Scheme
| false | false | 7,921 |
scm
|
sasm-core.scm
|
;; sasm-core.scm
;; SASM transform routines
(need pat/pat)
(need sasm/sasm-dataflow)
(need sasm/sasm-regalloc)
(need sasm/sasm-parse)
(need sasm/sasm-analyze)
(define *sasm-transform-function-count* 0)
(define *sasm-output-progress* #f)
(define (sasm-remove-directives sasm)
(filter (lambda (x) (not (equal? 'class-info (car x))))
sasm))
(define *sasm-transform-code-module-count* 0)
(define (sasm-transform-code sasm-program)
(define (get-module)
(let ((module
(string-append "module"
(number->string *sasm-transform-code-module-count*))))
(set! *sasm-transform-code-module-count* (+ 1 *sasm-transform-code-module-count*))
module))
(let ((ast (sasm-parse-program sasm-program)))
(if (not ast)
(error "SASM source parse error"))
(if (not (sasm-program-analyze-symbols! (get-module) ast))
(error "One or more SASM errors detected")))
(map sasm-transform-statement
(sasm-remove-directives sasm-program)))
(define (sasm-transform-port port)
(sasm-transform-code (sasm-read-port (sasm-assemble-interactive-context) port)))
(define (sasm-transform-file file-name)
(if *sasm-output-progress*
(begin (display ";; starting scan of input file "
(current-output-port))
(display file-name
(current-output-port))
(newline (current-output-port))))
(let ((code (sasm-read-file file-name)))
(if *sasm-output-progress*
(begin (display ";; finished scan of input file "
(current-output-port))
(display file-name
(current-output-port))
(newline (current-output-port))))
(sasm-transform-code (sasm-read-file file-name))))
(define (sasm-write-transform-port code port)
(error "Unexpected!")
(for-each (lambda (x) (write x port))
code))
(define (sasm-transform-statement sasm-code)
(case (car sasm-code)
((class entry global export extern)
(if *sasm-output-progress*
(begin (display ";; transform directive: "
(current-output-port))
(display (car sasm-code)
(current-output-port))
(newline (current-output-port))))
sasm-code)
((function)
(if *sasm-output-progress*
(begin
(display ";; starting function "
(current-output-port))
(display (+ *sasm-transform-function-count* 1)
(current-output-port))
(display ": "
(current-output-port))
(display (cadr (list-ref sasm-code 1))
(current-output-port))
(newline (current-output-port))))
(let ((func (sasm-transform-function sasm-code)))
(if *sasm-output-progress*
(begin
(display ";; finished function "
(current-output-port))
(set! *sasm-transform-function-count*
(+ *sasm-transform-function-count* 1))
(display *sasm-transform-function-count*
(current-output-port))
(display ": "
(current-output-port))
(display (cadr (list-ref sasm-code 1))
(current-output-port))
(newline (current-output-port)))
#f)
func))
((define-symconst)
(sasm-symconst-alist-append (cdr sasm-code))
sasm-code)
((include) (error "include directive is not allowed"))
(else
(error "Invalid SASM statement " sasm-code))))
(define (sasm-fix-locals n-locals sasm-code)
(map (lambda (stmt)
(if (and (equal? 'perform (list-ref stmt 0))
(equal? '(op reserve-locals) (list-ref stmt 1)))
`(perform (op reserve-locals) (const ,n-locals))
stmt))
sasm-code))
(define (sasm-temp-max sasm-code)
(let ((nums (filter-map (lambda (x)
(and (list? x)
(= 2 (length x))
(equal? 'temp (car x))
(number? (cadr x))
(cadr x)))
(apply append sasm-code))))
(if (null? nums)
0
(+ 1 (apply max nums)))))
(define (sasm-local-max sasm-code)
(let ((nums (filter-map (lambda (x)
(and (list? x)
(= 2 (length x))
(or (equal? 'local (car x))
(equal? 'n-locals (car x)))
(+ 1 (cadr x))))
(apply append sasm-code)))
(decl (apply max
0
(filter-map (lambda (x)
(and (equal? 'perform (car x))
(equal? '(op reserve-locals) (list-ref x 1))
(equal? 'const (car (list-ref x 2)))
(cadr (list-ref x 2))))
sasm-code))))
(apply max decl nums)))
(define (sasm-optimize-simple sasm-code)
(define (sasm-optimize-insn insn)
(if (pattern-match `(assign (? dest) (reg (? dest))) insn)
'()
(list insn)))
(apply append (map sasm-optimize-insn sasm-code)))
(define (sasm-optimize sasm-code)
(if *sasm-regalloc-cheap*
(sasm-regalloc-cheap sasm-code)
(if *sasm-enable-only-regalloc*
(sasm-regalloc-transform sasm-code)
(let ((opt-code (sasm-dataflow-optimize (sasm-optimize-simple sasm-code))))
(if *sasm-enable-regalloc*
(sasm-regalloc-transform opt-code)
opt-code)))))
(define (sasm-transform-function sasm-function)
(define (lookup attrib)
(case attrib
((name locals)
(cadr (assoc attrib (cdr sasm-function))))
((body)
(cdr (assoc 'body (cdr sasm-function))))
(else
(error "Invalid attribute -- SASM-TRANSFORM" attrib))))
(define (rewrite-stmts stmts level top result)
(if (null? stmts)
(let ((rewritten (reverse result)))
(let ((opt-code (sasm-optimize (sasm-symconst-preprocess-code (sasm-fix-locals (sasm-local-max rewritten)
rewritten)))))
`((locals ,(max top (sasm-local-max opt-code)))
(body ,@opt-code))))
(let ((stmt (car stmts)))
(define (as-reg x)
(cond ((symbol? x)
`(reg ,x))
((and (list? x)
(eqv? 'reg (car x))
(= 2 (length x))
(symbol? (list-ref x 1)))
x)
(else
(error "Invalid register " x stmt))))
(case (car stmt)
((save)
(rewrite-stmts (cdr stmts) (+ level 1) (max top (+ level 1))
(cons `(assign (local ,level)
,(as-reg (cadr stmt)))
result)))
((restore)
(rewrite-stmts (cdr stmts) (- level 1) top
(cons `(assign ,(as-reg (cadr stmt))
(local ,(- level 1)))
result)))
(else
(rewrite-stmts (cdr stmts) level top (cons stmt result)))))))
`(function (name ,(lookup 'name))
,@(rewrite-stmts (lookup 'body) (lookup 'locals) (lookup 'locals) '())))
| false |
9689b67c618eb3de4394bd6d8693a848e6622ff3
|
6f86602ac19983fcdfcb2710de6e95b60bfb0e02
|
/input/exercises/rna-transcription/test.ss
|
5aead9d40b07f033cfe829baaf660d3eee3fd521
|
[
"MIT",
"CC-BY-SA-3.0"
] |
permissive
|
exercism/scheme
|
a28bf9451b8c070d309be9be76f832110f2969a7
|
d22a0f187cd3719d071240b1d5a5471e739fed81
|
refs/heads/main
| 2023-07-20T13:35:56.639056 | 2023-07-18T08:38:59 | 2023-07-18T08:38:59 | 30,056,632 | 34 | 37 |
MIT
| 2023-09-04T21:08:27 | 2015-01-30T04:46:03 |
Scheme
|
UTF-8
|
Scheme
| false | false | 561 |
ss
|
test.ss
|
(define (parse-test test)
`(test-success ,(lookup 'description test)
equal?
dna->rna
'(,(cdar (lookup 'input test)))
,(lookup 'expected test)))
(let ((spec (get-test-specification 'rna-transcription)))
(put-problem!
'rna-transcription
`((test . ,(map parse-test (lookup 'cases spec)))
(stubs dna->rna)
(version . ,(lookup 'version spec))
(skeleton . "rna-transcription.scm")
(solution . "example.scm")
(markdown . ,(splice-exercism 'rna-transcription)))))
| false |
d57c4a42945c5447f2093992c38329e050988075
|
7666204be35fcbc664e29fd0742a18841a7b601d
|
/code/3-16.scm
|
8ceb1df4285f218447cf6548d9c10672c6461e79
|
[] |
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 | 1,051 |
scm
|
3-16.scm
|
(define (count-pairs x)
(if (not (pair? x))
0
(+ (count-pairs (car x))
(count-pairs (cdr x))
1)))
(define z1 (cons 'a 'b))
(define z2 (cons z1 z1))
(define z3 '(a b c))
(define z4 (cons 'a z2))
(define z7 (cons z2 z2))
(display (count-pairs z3)) (newline)
(display (count-pairs z4)) (newline)
(display (count-pairs z7 )) (newline)
(define c (list 'c))
(define b (cons 'b c))
(define a (cons 'a b))
(set-cdr! c a)
(display (count-pairs a)) (newline) ;loop forever or stack overflow
; 3:
; [a][+] (0+2+1)
; |
; +--> [b][+] (0+1+1)
; |
; +--> [c][/] (0+0+1)
;
; 4:
; [a][+] (0+3+1)
; |
; +--> [+][+] (1+1+1)
; | |
; +--+--> [b][/] (0+0+1)
;
; 7:
; [+][+] (3+3+1)
; | |
; +--+--> [+][+] (1+1+1)
; | |
; +--+--> [b][/] (0+0+1)
;
; dead loop:
; [a][+]
; ↑ |
; | +--> [b][+]
; | |
; | +--> [c][+]
; | |
; +--------------------+
| false |
35241473b4110564e93c7fb3b1f6d051d5f74be6
|
f6ebd0a442b29e3d8d57f0c0935fd3e104d4e867
|
/ch01/1.1/ex-1-1-seungwon0.scm
|
c4e44cc39631f3d315b56583cf45d35de9ebe04e
|
[] |
no_license
|
waytai/sicp-2
|
a8e375d43888f316a063d280eb16f4975b583bbf
|
4cdc1b1d858c6da7c9f4ec925ff4a724f36041cc
|
refs/heads/master
| 2021-01-15T14:36:22.995162 | 2012-01-24T12:21:30 | 2012-01-24T12:21:30 | 23,816,705 | 1 | 0 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 2,218 |
scm
|
ex-1-1-seungwon0.scm
|
;; ex-1.1
10 ;10
(+ 5 3 4) ;12
(- 9 1) ;8
(/ 6 2) ;3
(+ (* 2 4) (- 4 6)) ;6
(define a 3) ;a
(define b (+ a 1)) ;b
(+ a b (* a b)) ;19
(= a b) ;#f
(if (and (> b a) (< b (* a b)))
b
a) ;4
(cond ((= a 4) 6)
((= b 4) (+ 6 7 a))
(else 25)) ;16
(+ 2 (if (> b a) b a)) ;6
(* (cond ((> a b) a)
((< a b) b)
(else - 1))
(+ a 1)) ;16
;; ex-1.2
(/ (+ 5
4
(- 2
(- 3
(+ 6
(/ 4 5)))))
(* 3
(- 6 2)
(- 2 7))) ;-37/150
;; ex-1.3
(define (square x) (* x x))
(define (calc a b c)
(cond ((and (<= a b) (<= a c))
(+ (square b) (square c)))
((and (<= b a) (<= b c))
(+ (square a) (square c)))
(else
(+ (square a) (square b)))))
;; ex-1.4
(define (a-plus-abs-b a b)
((if (> b 0) + -) a b))
;; ex-1.5
(define (p) (p))
(define (test x y)
(if (= x 0)
0
y))
(test 0 (p))
;; ex-1.6
(define (new-if predicate then-clause else-clause)
(cond (predicate then-clause)
(else-clause)))
(new-if (= 2 3) 0 5)
(new-if (= 1 1) 0 5)
;; (define (sqrt-iter guess x)
;; (if (good-enough? guess x)
;; guess
;; (sqrt-iter (improve guess x)
;; x)))
(define (sqrt-iter guess x)
(new-if (good-enough? guess x)
guess
(sqrt-iter (improve guess x)
x)))
(define (improve guess x)
(average guess (/ x guess)))
(define (average x y)
(/ (+ x y) 2))
(define (good-enough? guess x)
(< (abs (- (square guess) x))
0.001))
(define (sqrt x)
(sqrt-iter 1.0 x))
;; ex-1.7
(sqrt 0.0001) ;.03230844833048122
(sqrt 9999999999999999) ;100000000.
(define (better? new-guess guess)
(> (abs (- new-guess guess))
(* new-guess 0.001)))
(define (sqrt-iter guess x)
(define new-guess (improve guess x))
(if (better? new-guess guess)
(sqrt-iter new-guess x)
guess))
;; ex-1.8
(define (cube-root x)
(cube-root-iter 1.0 x))
(define (cube-root-iter guess x)
(if (good-enough? guess x)
guess
(cube-root-iter (improve guess x)
x)))
(define (good-enough? guess x)
(< (abs (- (cube guess) x))
0.001))
(define (cube x)
(* x x x))
(define (improve guess x)
(/ (+ (/ x (square guess))
(* 2 guess))
3))
| false |
6eae51aac3adebffb3d417fa13d6f384cb7c2bc8
|
2c01a6143d8630044e3629f2ca8adf1455f25801
|
/xitomatl/tests/records-tests.sps
|
300447c15f3cdeef62b0c0721f4612ebd1db9b2f
|
[
"X11-distribute-modifications-variant"
] |
permissive
|
stuhlmueller/scheme-tools
|
e103fac13cfcb6d45e54e4f27e409adbc0125fe1
|
6e82e873d29b34b0de69b768c5a0317446867b3c
|
refs/heads/master
| 2021-01-25T10:06:33.054510 | 2017-05-09T19:44:12 | 2017-05-09T19:44:12 | 1,092,490 | 5 | 1 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 2,928 |
sps
|
records-tests.sps
|
#!r6rs
;; Copyright 2009 Derick Eddington. My MIT-style license is in the file named
;; LICENSE from the original collection this file is distributed with.
(import
(rnrs)
(xitomatl records)
(srfi :78 lightweight-testing))
(define-record-type A (fields a (mutable b) c))
(define-record-type B (parent A) (fields (mutable d) e))
(define-record-type C (parent B))
(define-record-type D (parent C) (fields f (mutable g) (mutable h)))
(define a (make-A 1 2 3))
(define b (make-B 1 2 3 4 5))
(define c (make-C 1 2 3 4 5))
(define d (make-D 1 2 3 4 5 6 7 8))
(check (record-type-fields (record-rtd a)) => '(a b c))
(check (record-type-fields (record-rtd b)) => '(a b c d e))
(check (record-type-fields (record-rtd c)) => '(a b c d e))
(check (record-type-fields (record-rtd d)) => '(a b c d e f g h))
(define A-accessors (record-type-accessors (record-rtd a)))
(define B-accessors (record-type-accessors (record-rtd b)))
(define C-accessors (record-type-accessors (record-rtd c)))
(define D-accessors (record-type-accessors (record-rtd d)))
(check (length A-accessors) => 3)
(check (for-all procedure? A-accessors) => #T)
(check (length B-accessors) => 5)
(check (for-all procedure? B-accessors) => #T)
(check (length C-accessors) => 5)
(check (for-all procedure? C-accessors) => #T)
(check (length D-accessors) => 8)
(check (for-all procedure? D-accessors) => #T)
(check (map (lambda (get) (get a)) A-accessors) => '(1 2 3))
(check (map (lambda (get) (get b)) B-accessors) => '(1 2 3 4 5))
(check (map (lambda (get) (get c)) C-accessors) => '(1 2 3 4 5))
(check (map (lambda (get) (get d)) D-accessors) => '(1 2 3 4 5 6 7 8))
(define A-mutators (record-type-mutators (record-rtd a)))
(define B-mutators (record-type-mutators (record-rtd b)))
(define C-mutators (record-type-mutators (record-rtd c)))
(define D-mutators (record-type-mutators (record-rtd d)))
(check (length A-mutators) => 3)
(check (length B-mutators) => 5)
(check (length C-mutators) => 5)
(check (length D-mutators) => 8)
(let ((what (lambda (m)
(cond ((procedure? m) 'p)
((not m) #F)
(else 'bad)))))
(check (map what A-mutators) => '(#F p #F))
(check (map what B-mutators) => '(#F p #F p #F))
(check (map what C-mutators) => '(#F p #F p #F))
(check (map what D-mutators) => '(#F p #F p #F #F p p)))
(for-each (lambda (setter!) (setter! a 'new)) (filter values A-mutators))
(check (map (lambda (get) (get a)) A-accessors) => '(1 new 3))
(for-each (lambda (setter!) (setter! b 'new)) (filter values B-mutators))
(check (map (lambda (get) (get b)) B-accessors) => '(1 new 3 new 5))
(for-each (lambda (setter!) (setter! c 'new)) (filter values C-mutators))
(check (map (lambda (get) (get c)) C-accessors) => '(1 new 3 new 5))
(for-each (lambda (setter!) (setter! d 'new)) (filter values D-mutators))
(check (map (lambda (get) (get d)) D-accessors) => '(1 new 3 new 5 6 new new))
(check-report)
| false |
ddc940075bfe5c16da7c52361d2ca84bff561256
|
ecfd9ed1908bdc4b099f034b121f6e1fff7d7e22
|
/compiler/derivative/regex.ss
|
903e7a2959319e2c1e98b3e243133ed064d62e85
|
[
"MIT"
] |
permissive
|
sKabYY/palestra
|
36d36fc3a03e69b411cba0bc2336c43b3550841c
|
06587df3c4d51961d928bd8dd64810c9da56abf4
|
refs/heads/master
| 2021-12-14T04:45:20.661697 | 2021-11-25T08:29:30 | 2021-11-25T08:29:30 | 12,856,067 | 6 | 3 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 1,415 |
ss
|
regex.ss
|
(load "match.ss")
(define (empty) '(empty))
(define (epsilon) '(epsilon))
(define (t value) `(t ,value))
(define (delta lang) `(delta ,lang))
; or
(define (u this that) `(u ,this ,that))
; cat
(define (o left right) `(o ,left ,right))
; star
(define (x lang) `(x ,lang))
(define (parse reg)
(match reg
[(: ,[r1] ,[r2]) (u r1 r2)]
[(: ,[r1] ,r2 ,r3 ...)
(u r1 (parse `(: ,r2 ,r3 ...)))]
[(* ,r1 ...) (x (parse `(,r1 ...)))]
[(,[r1]) r1]
[(,[r1] ,r2 ...)
(o r1 (parse `(,r2 ...)))]
[,x (t x)]))
(define (D c L)
(match L
[(empty) (empty)]
[(epsilon) (empty)]
[(delta ,_) (empty)]
[(t ,a) (if (eqv? a c) (epsilon) (empty))]
[(u ,L1 ,L2) (u (D c L1) (D c L2))]
[(x ,L1) (o (D c L1) L)]
[(o ,L1 ,L2) (u (o (delta L1) (D c L2))
(o (D c L1) L2))]))
(define (nullable? L)
(match L
[(empty) #f]
[(epsilon) #t]
[(t ,_) #f]
[(x ,_) #t]
[(delta ,L1) (nullable? L1)]
[(u ,L1 ,L2) (or (nullable? L1) (nullable? L2))]
[(o ,L1 ,L2) (and (nullable? L1) (nullable? L2))]))
(define (recognizes? w p)
(cond [(null? w) (nullable? p)]
[else (recognizes? (cdr w) (D (car w) p))]))
(define (test w p)
(let ([r (parse p)])
(printf "=~a w=~a p=~a~n" (recognizes? w r) w p)))
(test '(a a a) '(a (: a b) a))
(test '(a b a) '(a (: a b) a))
(test '(a) '(a (: a b) a))
(test '(x x x) '(* x))
(test '() '(* x))
| false |
ced74be40696a1230b88a6ee76d3031802647ffe
|
665da87f9fefd8678b0635e31df3f3ff28a1d48c
|
/srfi/sorting/sort.scm
|
3398816816e793b0d19b9a8b8b55e3e42952f2ca
|
[
"MIT"
] |
permissive
|
justinethier/cyclone
|
eeb782c20a38f916138ac9a988dc53817eb56e79
|
cc24c6be6d2b7cc16d5e0ee91f0823d7a90a3273
|
refs/heads/master
| 2023-08-30T15:30:09.209833 | 2023-08-22T02:11:59 | 2023-08-22T02:11:59 | 31,150,535 | 862 | 64 |
MIT
| 2023-03-04T15:15:37 | 2015-02-22T03:08:21 |
Scheme
|
UTF-8
|
Scheme
| false | false | 842 |
scm
|
sort.scm
|
;;; The sort package -- general sort & merge procedures
;;;
;;; Copyright (c) 1998 by Olin Shivers.
;;; You may do as you please with this code, as long as you do not delete this
;;; notice or hold me responsible for any outcome related to its use.
;;; Olin Shivers 10/98.
;;; This file just defines the general sort API in terms of some
;;; algorithm-specific calls.
(define (list-sort < l) ; Sort lists by converting to
(let ((v (list->vector l))) ; a vector and sorting that.
(vector-heap-sort! < v)
(vector->list v)))
(define list-sort! list-merge-sort!)
(define list-stable-sort list-merge-sort)
(define list-stable-sort! list-merge-sort!)
(define vector-sort vector-quick-sort)
(define vector-sort! vector-quick-sort!)
(define vector-stable-sort vector-merge-sort)
(define vector-stable-sort! vector-merge-sort!)
| false |
35496a281ac987b9bc3c94c2bfd5d2187d0c2cfb
|
a23f41d6de12a268b129a6b5c2e932325fe674f6
|
/src/swish/event-mgr-notify.ss
|
92c1d905b8af0ab5ea218cbd28158197647e6fb3
|
[
"MIT",
"LicenseRef-scancode-public-domain"
] |
permissive
|
becls/swish
|
89ee48b783b6b67b7077e09a78b3005fb44a8c54
|
3165b6a40c33774b263941314a7975b08dddf0e2
|
refs/heads/dev
| 2022-11-05T01:55:29.530457 | 2022-10-14T20:49:18 | 2022-10-14T20:55:37 | 113,237,913 | 134 | 27 |
MIT
| 2022-10-17T13:04:13 | 2017-12-05T22:04:27 |
Scheme
|
UTF-8
|
Scheme
| false | false | 2,853 |
ss
|
event-mgr-notify.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 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.
#!chezscheme
(library (swish event-mgr-notify)
(export
event-mgr:notify
informative-exit-reason?
normalize-exit-reason
system-detail
)
(import
(chezscheme)
(swish erlang)
(swish internal)
(swish meta)
)
($import-internal make-fault-condition &fault-condition)
(define (abnormal? reason)
(not (memq reason '(normal shutdown))))
(define normalize-exit-reason
(case-lambda
[(x)
(match x
[`(catch ,r ,e) (normalize-exit-reason r e)]
[,_ (normalize-exit-reason x x)])]
[(reason err)
(let ([err (or err reason)])
(if (condition? reason)
(values 'exception (if (informative-exit-reason? err) err reason))
(values reason
(and (informative-exit-reason? err)
;; If called via (match (catch e) [`(catch ,reason ,err) ...]),
;; make fault so coerce records exit-reason->english message.
(if (eq? err reason)
(make-fault-condition #f reason '())
err)))))]))
(define (informative-exit-reason? reason)
(and
(match reason
[`(&fault-condition ,reason ,k)
(or (#%$continuation? k) (abnormal? reason))]
[,_ (abnormal? reason)])
#t))
(define (event-mgr:notify event)
(cond
[(whereis 'event-mgr) => (lambda (pid) (send pid `#(notify ,event)))]
[else (console-event-handler event)])
'ok)
(define-syntax (system-detail x)
(syntax-case x ()
[(_ name [field value] ...)
#`(event-mgr:notify
(name make
#,@(add-if-absent #'timestamp #'(erlang:now)
#'([field value] ...))))]))
)
| true |
4bcefbc7f1b2bae412e82a7e047d36b6b3b64168
|
4b480cab3426c89e3e49554d05d1b36aad8aeef4
|
/chapter-04/ex4.09-test-comkid.scm
|
8bdcf468beef9988adf3134e4e9399828ba1a740
|
[] |
no_license
|
tuestudy/study-sicp
|
a5dc423719ca30a30ae685e1686534a2c9183b31
|
a2d5d65e711ac5fee3914e45be7d5c2a62bfc20f
|
refs/heads/master
| 2021-01-12T13:37:56.874455 | 2016-10-04T12:26:45 | 2016-10-04T12:26:45 | 69,962,129 | 0 | 0 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 613 |
scm
|
ex4.09-test-comkid.scm
|
(load "ch4-myeval-pkg-comkid.scm")
(load "../misc/scheme-test-r5rs.scm")
(define the-global-environment (setup-environment))
(define while-exp
'(while ((result 1) (n 5))
(lambda (x) (> x 1))
((* result n)
(- n 1))))
(define expected-exp
'(let iter ((result 1)
(n 5))
(if ((lambda (x) (> x 1)) n)
(iter (* result n) (- n 1))
result)))
(display "[ex4.09 - Tests]\n")
(run (make-testcase
'(assert-equal? expected-exp (while->named-let while-exp))
'(assert-equal? 120 (myeval expected-exp the-global-environment))
))
| false |
c02ce7d6fc56453b83dc01acefae90ef7f5cb65c
|
b13ba2793dbf455e2a6b5b50de6a1c253dd6b794
|
/spec/testbed.scm
|
f690d1b2d982c7f4f98598a8a490976b4bb199c6
|
[] |
no_license
|
jmax315/missbehave
|
ca924a7e9272948e54b73385a9d2206d39324cdc
|
5ceee8e0ef1b96362b4a28400b227cc1406a7fbb
|
refs/heads/master
| 2021-01-07T19:47:53.572758 | 2020-02-20T05:31:53 | 2020-02-20T05:31:53 | 241,802,990 | 0 | 0 | null | 2020-07-28T08:21:28 | 2020-02-20T05:40:07 |
Scheme
|
UTF-8
|
Scheme
| false | false | 1,134 |
scm
|
testbed.scm
|
;;
;; %%HEADER%%
;;
;;implicit contexts
(it "should be valid to start an it without a surrounding context"
(expect (eq? 2 3)))
;;implicit examples
(expect (eq? 5 5))
;;grouped expectations
(it "should be possible to group expectations "
(expect
((some-code) (be true))
(some-other (be false))))
;;tabular data
(it "should be possible to provide tabular data"
(for-every item in (list 1 2 2 4)
(expect (some-code item) (be true))))
;;shared contexts
(it "should be possible to have shared contexts"
(context "Some context" (shared "optional name")
(it "should pass and pass and pass"))
(context "Some other"
(it should behave-like "optional name")))
;; message-modifiers
(expect (eq? 2 3) message: "Well other message")
;;implicit matcher
;; (describe "Something" (meta ((reality . #t)))
;; (unfinished ((dictionary-set! (returns nothing))))
;;
;; (it "Should do this and that"
;; (expect (dictionary-set! 'dict 1) => 1)
;; Nice about the => is that it stands out and can be used to align
;; all expected results equally
(expect (eq? 2 3) (be 3))
(expect (eq? 2 3) => 2)
| false |
e7f83c6d55affffa60bf7cc5d91c6767d9e7be8a
|
78a81779e2a49f9cfa4163cbbbcd7d2c79ee2c1d
|
/cw2/tree-filter-cps.scm
|
b7d32a3aba17b72e9a85ab168b21aecbf121710e
|
[] |
no_license
|
tobyfielding1/Scheme-Exercises
|
bd17c17c0babac16b9863ce016edc95587af5cc7
|
01f62198bd267300d2435a2133d93e73f36879f5
|
refs/heads/master
| 2021-07-15T03:16:49.580461 | 2017-10-20T23:20:31 | 2017-10-20T23:20:31 | 107,734,701 | 0 | 0 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 773 |
scm
|
tree-filter-cps.scm
|
;;; 26747987 tf3g14 tobias fielding
(define tf1
(lambda (t2 pred2 c2)
(let ((l (if (pred2 (tree-labels t2) (lambda (bool) bool)) (tree-labels t2) '())))
(if (leaf? t2)
(c2 (make-leaf l))
(c2 (make-node l (tf1 (node-left t2) pred2 (lambda (tr)tr)) (tf1 (node-right t2) pred2 (lambda (tr)tr))))))))
(define tf2
(lambda (t2 pred2 c2)
(let ((l2 (if (pred2 (tree-labels t2) (lambda (bool) bool)) '() (tree-labels t2))))
(if (leaf? t2)
(c2 (make-leaf l2))
(c2 (make-node l2 (tf2 (node-left t2) pred2 (lambda (tr)tr)) (tf2 (node-right t2) pred2 (lambda (tr)tr))))))))
(define tree-filter-cps
(lambda (pred t c)
(c (tf1 t pred (lambda (r)r)) (tf2 t pred (lambda (r)r)))))
| false |
73cba2bceb8445136f374c30687ce11597b94411
|
d074b9a2169d667227f0642c76d332c6d517f1ba
|
/sicp/ch_4/exercise.4.47.scm
|
e99057f4b4598f74591dbab98b9bb2a6540d847f
|
[] |
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 | 642 |
scm
|
exercise.4.47.scm
|
#!/usr/bin/env csi -s
(require rackunit)
;;; Exercise 4.47
;; Louis Reasoner suggests that, since a verb phrase
;; is either a verb or a verb phrase followed by a prepositional
;; phrase, it would be much more straightforward to define the
;; procedure `parse-verb-phrase' as follows (and similarly for noun
;; phrases):
;;
;; (define (parse-verb-phrase)
;; (amb (parse-word verbs)
;; (list 'verb-phrase
;; (parse-verb-phrase)
;; (parse-prepositional-phrase))))
;;
;; Does this work? Does the program's behavior change if we
;; interchange the order of expressions in the `amb'
| false |
3497ffd1eaf69ebe75412cb5cba4eda6cbb89b8e
|
a97e1f9075df3f8eda040e0018eac5e2497f9e16
|
/examples/format-output.scm
|
09eb5b86149a93ce48f6d9c39412e9004d542254
|
[
"MIT",
"BSD-3-Clause",
"BSL-1.0"
] |
permissive
|
hvellyr/textbook
|
9eefeded45dce203a51419acaeb47864f7a73810
|
3b7b797c71384222d58b67bded24ee5b5cc6aa2a
|
refs/heads/master
| 2023-03-03T20:41:45.450236 | 2021-01-24T11:18:00 | 2021-01-24T11:18:32 | 31,146,671 | 0 | 1 | null | 2018-01-29T10:59:46 | 2015-02-22T00:17:16 |
C++
|
UTF-8
|
Scheme
| false | false | 62 |
scm
|
format-output.scm
|
(import (srfi 28))
(display (format "Hello, ~a~%" "World!"))
| false |
d6919c97b51c853d38cae1776e4a4edc1f15a79a
|
000dbfe5d1df2f18e29a76ea7e2a9556cff5e866
|
/sitelib/util/timer.scm
|
00dd9f537eca341a4eb76aa45ed176950059ffc6
|
[
"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 | 11,021 |
scm
|
timer.scm
|
;;; -*- mode:scheme; coding:utf-8 -*-
;;;
;;; util/timer.scm - Timer
;;;
;;; Copyright (c) 2010-2015 Takashi Kato <[email protected]>
;;;
;;; Redistribution and use in source and binary forms, with or without
;;; modification, are permitted provided that the following conditions
;;; are met:
;;;
;;; 1. Redistributions of source code must retain the above copyright
;;; notice, this list of conditions and the following disclaimer.
;;;
;;; 2. Redistributions in binary form must reproduce the above copyright
;;; notice, this list of conditions and the following disclaimer in the
;;; documentation and/or other materials provided with the distribution.
;;;
;;; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
;;; "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
;;; LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
;;; A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
;;; OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
;;; SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
;;; TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
;;; PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
;;; LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
;;; NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
;;; SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
;;;
(library (util timer)
(export make-timer timer? timer-state
timer-start! timer-stop! timer-cancel!
timer-schedule! timer-reschedule!
timer-remove! timer-exists?)
(import (rnrs)
(sagittarius) ;; for compare
(sagittarius control) ;; unwind-protect
(srfi :18)
(srfi :19)
(util heap))
(define-record-type (<timer-task> %make-timer-task timer-task?)
;; thunk, next (time object), period (integer)
(fields (immutable id timer-task-id)
(immutable thunk timer-task-thunk)
(mutable next timer-task-next timer-task-next-set!)
(mutable period timer-task-period timer-task-period-set!)
(mutable running timer-task-running? timer-task-running-set!))
(protocol (lambda (p)
(lambda (id thunk next period)
(p id thunk next period #f)))))
(define (task-compare a b)
(let ((r (compare (timer-task-next a) (timer-task-next b))))
(if (zero? r)
(compare (timer-task-id a) (timer-task-id b))
r)))
(define-record-type (<timer> %make-timer timer?)
(fields (immutable queue timer-queue)
;; stop, cancel or #f
(mutable state timer-state timer-state-set!)
(immutable lock timer-lock)
(immutable waiter timer-waiter)
;; worker thread
(mutable worker timer-worker %timer-worker-set!)
(mutable next-id timer-next-id timer-next-id-set!)
;; tiemrs table
(immutable active timer-active)
;; we can't share them... *sign*
(immutable stop-lock timer-stop-lock)
(immutable stop-waiter timer-stop-waiter)
)
(protocol (lambda (p)
(lambda ()
(p (make-heap task-compare) 'created
(make-mutex)
(make-condition-variable)
#f 1 (make-eqv-hashtable)
(make-mutex)
(make-condition-variable))))))
;; hmmmm, how many times I've written this type of macro...
(define-syntax wait-cv
(syntax-rules ()
((_ mutex cv)
(wait-cv mutex cv #f))
((_ mutex cv timeout)
(let ((m mutex)
(c cv)
(to timeout))
(when (mutex-unlock! m c to)
(mutex-lock! mutex))))))
(define (milliseconds->sec&nano msec)
(let ((sec (div msec 1000))
(nsec (* (mod msec 1000) 1000000)))
(values sec nsec)))
(define (make-timer :key (error-handler #f))
(define (timer-start! t)
(define (main-loop t)
(case (timer-state t)
((cancelling) (timer-state-set! t 'cancelled))
((cancelled)) ;; do nothing
((stopping)
(condition-variable-broadcast! (timer-waiter t))
;; otherwise other operation can't do anything...
(mutex-unlock! (timer-lock t))
(timer-state-set! t 'stopped)
;; it's stopped as long as mutex is locked
(mutex-unlock! (timer-stop-lock t) (timer-stop-waiter t) #f)
;; lock again
(mutex-lock! (timer-lock t))
(main-loop t))
(else
;; we may want to <mt-heap> for this purpose...
(let ((queue (timer-queue t)))
(if (heap-empty? queue)
(wait-cv (timer-lock t) (timer-waiter t))
(let* ((first (heap-entry-value (heap-min queue)))
(now (current-time))
(next (timer-task-next first)))
(if (time>=? now next)
(begin
;; set running
(timer-task-running-set! first #t)
;; then remove it from heap
;; this prevents raising an error during reschedule.
(heap-entry-value (heap-extract-min! queue))
(mutex-unlock! (timer-lock t))
(guard (e (error-handler (error-handler e))
(else (raise e)))
((timer-task-thunk first)))
(mutex-lock! (timer-lock t))
(if (timer-task-running? first)
(let ((p (timer-task-period first)))
(timer-task-running-set! first #f)
(if (and (time? p)
(or (positive? (time-nanosecond p))
(positive? (time-second p))))
(let ((next2 (add-duration next p)))
(timer-task-next-set! first next2)
(heap-set! queue first first))
(hashtable-delete! (timer-active t)
(timer-task-id first))))
(hashtable-delete! (timer-active t)
(timer-task-id first))))
(wait-cv (timer-lock t) (timer-waiter t)
(timer-task-next first))))))
(main-loop t))))
(lambda ()
(dynamic-wind
(lambda () (mutex-lock! (timer-lock t)))
(lambda () (main-loop t))
(lambda () (mutex-unlock! (timer-lock t))))))
(let ((t (%make-timer)))
(%timer-worker-set! t (make-thread (timer-start! t)))
t))
(define (timer-start! t)
(mutex-lock! (timer-lock t))
(case (timer-state t)
((stopped)
(condition-variable-broadcast! (timer-stop-waiter t))
(mutex-unlock! (timer-stop-lock t))
(condition-variable-broadcast! (timer-waiter t)))
((created) (thread-start! (timer-worker t)))
(else (assertion-violation 'timer-start! "already running" t)))
(timer-state-set! t 'running)
(mutex-unlock! (timer-lock t))
t)
(define (timer-stop! t)
(mutex-lock! (timer-lock t))
(timer-state-set! t 'stopping)
(mutex-lock! (timer-stop-lock t))
;; notify to queue
(condition-variable-broadcast! (timer-waiter t))
;; this should let the timer lock its lock
(mutex-unlock! (timer-lock t))
;; make sure timer lock is unlocked so that other process can modify
;; the timer.
(thread-yield!)
;; can't we do better?
(let loop ()
(unless (eq? (timer-state t) 'stopped)
(thread-yield!)
(thread-sleep! 0.1) ;; sleep a bit
(loop)))
t)
(define (timer-cancel! t)
(mutex-lock! (timer-lock t))
(let retry ((need-lock? #f))
(case (timer-state t)
((stopped)
(condition-variable-broadcast! (timer-stop-waiter t))
;; lock first to prevent to be locked by the timer
(when need-lock? (mutex-lock! (timer-lock t)))
;; ok unlock it
(mutex-unlock! (timer-stop-lock t)))
;; basically this pass never happens. since timer-stop! makes sure
;; the timer is stopped state.
((stopping)
;; make sure we don't do this twice, otherwise it'd wait
;; forever until someone unlock the lock (and in this case
;; nobody).
(unless need-lock?
(condition-variable-broadcast! (timer-waiter t))
(mutex-unlock! (timer-lock t)))
(thread-yield!) ;; wait a bit to give some chance
(retry #t))))
(timer-state-set! t 'cancelling)
(condition-variable-broadcast! (timer-waiter t))
(mutex-unlock! (timer-lock t))
(thread-join! (timer-worker t)))
(define (check-positive who v msg)
(when (negative? v) (error who msg v)))
(define (millisecond->time-duration msec)
(let-values (((sec nsec) (milliseconds->sec&nano msec)))
(make-time time-duration nsec sec)))
(define (current-time+millisecond msec)
(let ((t (current-time)))
(if (zero? msec)
t
(add-duration t (millisecond->time-duration msec)))))
(define (check-period who period)
(or (and (number? period) (check-positive who period "negative period"))
(and (time? period) (eq? (time-type period) time-duration))
(error who "positive or time-duration is required" period)))
(define (timer-schedule! timer thunk first :optional (period 0))
(define (allocate-timer-id timer)
(let ((c (timer-next-id timer)))
(timer-next-id-set! timer (+ c 1))
c))
(define (check v msg) (check-positive 'timer-schedule! v msg))
(unless (time? first) (check first "negative delay"))
(check-period 'timer-schedule! period)
(mutex-lock! (timer-lock timer))
(let* ((id (allocate-timer-id timer))
(first (if (time? first) first (current-time+millisecond first)))
(p (cond ((time? period) period)
((zero? period) period)
(else (millisecond->time-duration period))))
(task (%make-timer-task id thunk first p)))
(hashtable-set! (timer-active timer) id task)
(heap-set! (timer-queue timer) task task)
(condition-variable-broadcast! (timer-waiter timer))
(mutex-unlock! (timer-lock timer))
id))
(define (timer-reschedule! timer id first :optional (period 0))
(define (check v msg) (check-positive 'timer-reschedule! v msg))
(unless (time? first) (check first "negative delay"))
(check-period 'timer-reschedule! period)
(let ((lock (timer-lock timer)))
(mutex-lock! lock)
(let ((task (hashtable-ref (timer-active timer) id)))
;; task has next
(when task
(let ((old (timer-task-next task))
(next (if (time? first) first (current-time+millisecond first)))
(p (cond ((time? period) period)
((zero? period) period)
(else (millisecond->time-duration period))))
(queue (timer-queue timer)))
;; should be able to delete here...
(when (and (not (timer-task-running? task))
(heap-search queue task))
(heap-delete! queue task))
;; update period
(timer-task-period-set! task p)
(timer-task-next-set! task next)
;; now reschedule it
(heap-set! queue task task)
;; let them know
(condition-variable-broadcast! (timer-waiter timer))))
(mutex-unlock! lock)))
id)
(define (timer-remove! timer id)
(let ((lock (timer-lock timer)))
(mutex-lock! lock)
(let ((task (hashtable-ref (timer-active timer) id)))
(cond ((not task) (mutex-unlock! lock) #f)
(else
(if (timer-task-running? task)
(timer-task-running-set! task #f)
(heap-delete! (timer-queue timer) task))
(hashtable-delete! (timer-active timer) id)
(condition-variable-broadcast! (timer-waiter timer))
(mutex-unlock! lock)
#t)))))
(define (timer-exists? timer id)
(let ((lock (timer-lock timer)))
(mutex-lock! lock)
(let ((r (hashtable-contains? (timer-active timer) id)))
(mutex-unlock! lock)
r)))
)
| true |
089110904cf1a3b2162e8ed2630c630eb3c75432
|
ede19ddee7d2c88d7b6cb159bc00c2e0c950371d
|
/browser/browser.wat
|
f01ee1a6fb524f65a092d2d355da3a658b398c9a
|
[
"MIT"
] |
permissive
|
paddymahoney/wat-js
|
29a1a8441f531744e1d83ebbf14c5cab9eaab468
|
0045525ae01e5431178af56d243524ccb7a701a4
|
refs/heads/master
| 2020-12-24T09:07:53.259247 | 2012-10-16T22:15:46 | 2012-10-16T22:15:53 | null | 0 | 0 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 1,761 |
wat
|
browser.wat
|
;; -*- mode: scheme -*-
;; WAT ON THE WWW
(provide (read display)
(define *window* (js-global "window"))
(define *document* (js-global "document"))
(define *body* (js-prop *document* "body"))
(define getElementById
(let ((m (js-method "getElementById")))
(lambda (str) (m *document* (to-js str)))))
(define createElement
(let ((m (js-method "createElement")))
(lambda (name) (m *document* (to-js name)))))
(define createTextNode
(let ((m (js-method "createTextNode")))
(lambda (s) (m *document* (to-js s)))))
(define appendChild
(let ((m (js-method "appendChild")))
(lambda (e child) (m e child))))
(define scrollTo
(let ((m (js-method "scrollTo")))
(lambda (x y) (m *window* x y))))
(define (read-input)
(let* ((input (from-js (js-prop (getElementById "input") "value")))
(res (list* 'begin (read-from-string input))))
(display (strcat "USER> " input))
(js-set-prop! (getElementById "input") "value" (to-js ""))
res))
(provide (read input-callback)
(define *env* (current-environment))
(define *read-k* none)
(define (read)
(take-subcont *top-level* k
(set! *env* *read-k* (some k))))
(define (input-callback evt)
(if (num= (from-js (js-prop evt "keyCode")) 13)
(push-prompt *top-level*
(push-subcont (if-option (k *read-k*) k (fail "no continuation")) (read-input)))
#void))
)
(js-set-prop! (getElementById "input") "onkeypress" (js-callback input-callback))
(define (display msg)
(let ((div (createElement "div")))
(appendChild div (createTextNode (to-js msg)))
(appendChild (getElementById "output") div)
(scrollTo (to-js 0) (js-prop *body* "scrollHeight"))
msg))
((js-method "focus") (getElementById "input"))
) ; edivorp
| false |
00cd44c85abb31da172aa626e1b785c310404d6a
|
3f2f5dfa2f6211b6af96c78f130b0280abe267f3
|
/src/subst.scm
|
40611d5d3fc87598eb5d7ba766cd2420c2548448
|
[] |
no_license
|
E-Neo/notebook-of-eopl3
|
7e4cc98bb82c3ee1c4026944360fee088dcd669d
|
170f0b60f4e29689523c9a7ca1852ab3b91a71a3
|
refs/heads/master
| 2021-01-19T06:33:05.298855 | 2016-08-08T15:38:25 | 2016-08-08T15:38:25 | 64,475,372 | 0 | 0 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 493 |
scm
|
subst.scm
|
;;; subst : Sym * Sym * S-list -> S-list
;;; usage: (subst new old slist) returns a new list with all
;;; occurrences of old replaced by instances of new.
(define (subst new old slist)
;; subst-in-sexp : Sym * Sym * S-exp -> S-exp
(define (subst-in-sexp new old sexp)
(if (symbol? sexp)
(if (eqv? old sexp) new sexp)
(subst new old sexp)))
(if (null? slist)
'()
(cons (subst-in-sexp new old (car slist))
(subst new old (cdr slist)))))
| false |
84993c16adc484372de3ae1886a69296924c4906
|
4f91474d728deb305748dcb7550b6b7f1990e81e
|
/Chapter2/2-point-constructor.scm
|
b244864cf71203694a38012aaaa973883c1a422d
|
[] |
no_license
|
CanftIn/sicp
|
e686c2c87647c372d7a6a0418a5cdb89e19a75aa
|
92cbd363c143dc0fbf52a90135218f9c2bf3602d
|
refs/heads/master
| 2021-06-08T22:29:40.683514 | 2020-04-20T13:23:59 | 2020-04-20T13:23:59 | 85,084,486 | 2 | 0 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 38 |
scm
|
2-point-constructor.scm
|
(define (make-point x y)
(cons x y))
| false |
b4dce28a8d10ae628d8afc30204b14d42480d308
|
174072a16ff2cb2cd60a91153376eec6fe98e9d2
|
/Chap-two/settree.scm
|
1c92fa7bc40305e49fa1d411a0f7fc6305a0591b
|
[] |
no_license
|
Wang-Yann/sicp
|
0026d506ec192ac240c94a871e28ace7570b5196
|
245e48fc3ac7bfc00e586f4e928dd0d0c6c982ed
|
refs/heads/master
| 2021-01-01T03:50:36.708313 | 2016-10-11T10:46:37 | 2016-10-11T10:46:37 | 57,060,897 | 1 | 0 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 839 |
scm
|
settree.scm
|
(define (entry tree) (car tree))
(define (left-branch tree) (cadr tree))
(define (right-branch tree) (caddr tree))
(define (make-tree e l r) (list e l r))
(define (element-of-set? x set)
(cond ((null? set) #f)
((= x (entry set)) #t)
((> x (entry set)) (element-of-set? x (right-branch set)))
((< x (entry set)) (element-of-set? x (left-branch set)))
(else (error "wrong type"))))
(define (adjoin x set)
(cond ((null? set) (make-tree x '() '()))
((element-of-set? x set) set)
(else (let (( root (entry set)))
(if (< x root) (make-tree root (adjoin x (left-branch set)) (right-branch set))
(make-tree root (left-branch set) (adjoin x (right-branch set))))))))
(define d (make-tree 20 '() '()))
(define c (make-tree 7 '() '()))
(define a (make-tree 1 '() '()))
(define b (make-tree 5 a c))
(define e (make-tree 11 b d))
| false |
056a8a1b37056088be0dc74ceddd67c41788f930
|
370ebaf71b077579ebfc4d97309ce879f97335f7
|
/sicp/ch2/ch2.scm
|
cdaa782b6f25255c75ddb5406d633c310444b696
|
[] |
no_license
|
jgonis/sicp
|
7f14beb5b65890a86892a05ba9e7c59fc8bceb80
|
fd46c80b98c408e3fd18589072f02ba444d35f53
|
refs/heads/master
| 2023-08-17T11:52:23.344606 | 2023-08-13T22:20:42 | 2023-08-13T22:20:42 | 376,708,557 | 0 | 0 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 2,616 |
scm
|
ch2.scm
|
;;"/home/jeff.gonis/Code/gauche/bin/gosh -i -r7 -I /home/jeff.gonis/Code/sicp/sicp"
;; (import (gauche base)) to get access to debugging and profiling
;; functions
(define-library (ch2 ch2)
(export alt-cons
alt-car
alt-cdr
numeric-cons
numeric-car
numeric-cdr
last-pair
j-reverse
count-change
same-parity
square-list
alt-square-list
j-for-each)
(import (scheme base)
(scheme write)
(libs fp-compare)
(libs helpers))
(begin
(define (alt-cons x y)
(lambda (m) (m x y)))
(define (alt-car pair)
(pair (lambda (x y) x)))
(define (alt-cdr pair)
(pair (lambda (x y) y)))
(define (numeric-cons x y)
(* (expt 2 x) (expt 3 y)))
(define (numeric-car pair)
(define (iter num counter)
(cond ((even? num) counter)
(else (iter (/ num 2) (+ counter 1)))))
(iter pair 0))
(define (numeric-cdr pair)
(define (iter num counter)
(cond ((not (= 0 (remainder num 3))) counter)
(else (iter (/ num 3) (+ counter 1)))))
(iter pair 0))
(define (last-pair items)
(cond ((null? (cdr items)) items)
(else (last-pair (cdr items)))))
(define (j-reverse items)
(define (helper lst work-lst)
(cond ((null? lst) work-lst)
(else (helper (cdr lst) (cons (car lst) work-lst)))))
(helper items '()))
(define (count-change amount coin-values)
(define (cc amount coins)
(cond ((= amount 0) 1)
((or (< amount 0)
(no-more? coins)) 0)
(else (+ (cc amount
(except-first-denomination coins))
(cc (- amount
(first-denomination coins))
coins)))))
(define (except-first-denomination coins)
(cdr coins))
(define (first-denomination coins)
(car coins))
(define (no-more? coins)
(null? coins))
(cc amount coin-values))
(define (same-parity x . rest)
(define (helper lst test-func result)
(cond ((null? lst) (j-reverse result))
((test-func (car lst)) (helper (cdr lst)
test-func
(cons (car lst) result)))
(else (helper (cdr lst)
test-func
result))))
(cond ((even? x) (helper rest
even?
(list x)))
(else (helper rest
odd?
(list x)))))
(define (square-list items)
(if (null? items)
nil
(cons (square (car items))
(square-list (cdr items)))))
(define (alt-square-list items)
(map (lambda (n) (* n n)) items))
(define (j-for-each func lst)
(cond ((not (null? lst)) (func (car lst))
(j-for-each func (cdr lst)))))))
| false |
bf215943baa384c9b3cbdd647d031cf51bb734b4
|
47457420b9a1eddf69e2b2f426570567258f3afd
|
/1/3.scm
|
9af3d97f9764e373f902ada589f516e2cf241471
|
[] |
no_license
|
adromaryn/sicp
|
797496916620e85b8d85760dc3f5739c4cc63437
|
342b56d233cc309ffb59dd13b2d3cf9cd22af6c9
|
refs/heads/master
| 2021-08-30T06:55:04.560128 | 2021-08-29T12:47:28 | 2021-08-29T12:47:28 | 162,965,433 | 0 | 0 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 233 |
scm
|
3.scm
|
#lang sicp
(define (square x) (* x x))
(define (pif a b c)
(cond ((and (> a c) (> b c)) (+ (square a) (square b)))
((and (> a b) (> c b)) (+ (square a) (square c)))
(else (+ (square b) (square c)))))
(pif 10 9 7)
| false |
eb8eeef98818f18ea3ae6ee12f51bec0e743ebf1
|
e39069f51f6b8f40a7efe76d3bad4e3631e63a15
|
/stochastic-discrete.scm
|
a71fd392d541632c2185fcd727f5e659cde36d0a
|
[
"LicenseRef-scancode-philippe-de-muyter"
] |
permissive
|
abarbu/stochastic-discrete
|
8e08895c69bdb79ad3825a8bf0c83c57c05bc067
|
85b7f82434f379c44f13e7a8904341f6472cbe15
|
refs/heads/master
| 2016-09-06T01:46:42.000316 | 2013-03-09T00:00:14 | 2013-03-09T00:00:14 | null | 0 | 0 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 14,423 |
scm
|
stochastic-discrete.scm
|
(module stochastic-discrete *
(import chicken scheme extras)
(require-extension nondeterminism define-structure srfi-1 traversal condition-utils)
(define *gm-strategy* 'ac)
(define-syntax fold-distribution
(syntax-rules ()
((_ f i thunk) (fold-distribution-thunk f i (lambda () thunk)))))
(define-syntax support
(syntax-rules ()
((_ thunk) (support-thunk (lambda () thunk)))))
(define-syntax supportq
(syntax-rules ()
((_ thunk) (supportq-thunk (lambda () thunk)))))
(define-syntax supportv
(syntax-rules ()
((_ thunk) (supportv-thunk (lambda () thunk)))))
(define-syntax supportp
(syntax-rules ()
((_ thunk) (supportv-thunk (lambda () thunk)))))
(define-syntax probability
(syntax-rules ()
((_ thunk) (probability-thunk (lambda () thunk)))))
(define-syntax expected-value
(syntax-rules ()
((_ plus times zero thunk)
(expected-value-thunk plus times zero (lambda () thunk)))))
(define-syntax entropy
(syntax-rules ()
((_ thunk) (entropy-thunk (lambda () thunk)))))
(define-syntax distribution
(syntax-rules ()
((_ thunk) (distribution-thunk (lambda () thunk)))))
(define-syntax distributionq
(syntax-rules ()
((_ thunk) (distributionq-thunk (lambda () thunk)))))
(define-syntax distributionv
(syntax-rules ()
((_ thunk) (distributionv-thunk (lambda () thunk)))))
(define-syntax distributionp
(syntax-rules ()
((_ thunk) (distributionv-thunk (lambda () thunk)))))
;;; TODO mutual information, K-L divergence, mean, median, mode, variance
(define (top-level-flip alpha)
(abort (make-exn-condition+ 'flip "Top-level flip" (list alpha) 'stochastic-discrete)))
(define (top-level-bottom)
(abort (make-exn-condition+ 'bottom "Top-level bottom" '() 'stochastic-discrete)))
(define (top-level-current-probability)
(abort (make-exn-condition+ 'current-probability
"Top-level current-probability" '() 'stochastic-discrete)))
(define flip top-level-flip)
(define bottom top-level-bottom)
(define current-probability top-level-current-probability)
(define (forget-trail)
(set! flip top-level-flip)
(set! bottom top-level-bottom)
(set! current-probability top-level-current-probability)
#f)
(define (fold-distribution-thunk f i thunk)
(call-with-current-continuation
(lambda (c)
(let ((accumulation i) (p 1.0) (saved-flip flip)
(saved-bottom bottom) (saved-current-probability current-probability))
(set! current-probability (lambda () p))
(set! flip
(lambda (alpha)
(unless (<= 0 alpha (+ 1.0 flonum-epsilon))
(abort (make-exn-condition+ 'fold-distribution-thunk "alpha is not a probability" (list alpha) 'stochastic-discrete)))
(let ((alpha (min 1.0 alpha)))
(cond ((zero? alpha) #f)
((= alpha 1.0) #t)
(else (call-with-current-continuation
(lambda (c)
(let ((saved-p p) (saved-bottom bottom))
(set! p (* alpha p))
(set! bottom
(lambda ()
(set! p (* (- 1.0 alpha) saved-p))
(set! bottom saved-bottom)
(c #f)))
#t))))))))
(set! bottom
(lambda ()
(set! flip saved-flip)
(set! bottom saved-bottom)
(set! current-probability saved-current-probability)
(c accumulation)))
(let ((value (thunk))) (set! accumulation (f value p accumulation)))
(bottom)))))
(define (support-thunk thunk)
(fold-distribution-thunk
(lambda (value p accumulation)
(if (member value accumulation) accumulation (cons value accumulation)))
'()
thunk))
(define (supportq-thunk thunk)
(fold-distribution-thunk
(lambda (value p accumulation)
(if (memq value accumulation) accumulation (cons value accumulation)))
'()
thunk))
(define (supportv-thunk thunk)
(fold-distribution-thunk
(lambda (value p accumulation)
(if (memv value accumulation) accumulation (cons value accumulation)))
'()
thunk))
(define (supportp-thunk p? thunk)
(fold-distribution-thunk
(lambda (value p accumulation)
(if (memp p? value accumulation) accumulation (cons value accumulation)))
'()
thunk))
(define (probability-thunk thunk)
(fold-distribution-thunk (lambda (value p accumulation)
(if (eq? value #t) (+ p accumulation) accumulation))
0
thunk))
(define (expected-value-thunk plus times zero thunk)
(fold-distribution-thunk
(lambda (value p accumulation) (plus (times p value) accumulation))
zero
thunk))
(define (entropy-thunk thunk)
(- 0
(fold-distribution-thunk
(lambda (value p accumulation) (+ (* p (log p)) accumulation))
0
thunk)))
(define (distribution-thunk thunk)
(fold-distribution-thunk
(lambda (value p accumulation)
(let ((pair (assoc value accumulation)))
(if pair
(cons (cons value (+ p (cdr pair))) (removeq pair accumulation))
(cons (cons value p) accumulation))))
'()
thunk))
(define (distributionq-thunk thunk)
(fold-distribution-thunk
(lambda (value p accumulation)
(let ((pair (assq value accumulation)))
(if pair
(cons (cons value (+ p (cdr pair))) (removeq pair accumulation))
(cons (cons value p) accumulation))))
'()
thunk))
(define (distributionv-thunk thunk)
(fold-distribution-thunk
(lambda (value p accumulation)
(let ((pair (assv value accumulation)))
(if pair
(cons (cons value (+ p (cdr pair))) (removeq pair accumulation))
(cons (cons value p) accumulation))))
'()
thunk))
(define (distributionp-thunk p? thunk)
(fold-distribution-thunk
(lambda (value p accumulation)
(let ((pair (assp p? value accumulation)))
(if pair
(cons (cons value (+ p (cdr pair))) (removeq pair accumulation))
(cons (cons value p) accumulation))))
'()
thunk))
(define (most-likely-value distribution)
(car (fold (lambda (pair best) (if (> (cdr pair) (cdr best)) pair best))
distribution
`(#f . -inf.0))))
(define (most-likely-pair distribution)
(fold (lambda (pair best) (if (> (cdr pair) (cdr best)) pair best))
distribution
`(#f . -inf.0)))
(define (normalize-distribution distribution)
(let ((t (foldl + 0 (map cdr distribution))))
(map (lambda (pair) (cons (car pair) (/ (cdr pair) t))) distribution)))
(define (draw-pair distribution)
(define (min x1 x2) (if (< x1 x2) x1 x2))
(define (max x1 x2) (if (> x1 x2) x1 x2))
(let loop ((distribution distribution) (p 1.0))
(cond
((or (zero? p) (null? distribution)) (bottom))
((flip (min (/ (cdr (first distribution)) p) 1.0)) (first distribution))
(else
(loop (rest distribution) (max (- p (cdr (first distribution))) 0))))))
(define (draw distribution)
(let loop ((p 1.0)
(pairs
;; This is done not so much for efficiency but to prevent a
;; situation where the last pair has zero probability and roundoff
;; error is subtracting the earlier probabilities from one leads
;; to flip being called with a value slightly greater than one.
(remove-if (lambda (pair) (zero? (cdr pair))) distribution)))
(if (null? pairs)
(bottom)
(if (flip (/ (cdr (first pairs)) p))
(car (first pairs))
(loop (- p (cdr (first pairs))) (rest pairs))))))
;;; Graphical models
;;; domain -> distribution
;;; csp -> gm
;;; fail -> bottom
;;; This assume a model where there is no renormalization due to bottoms.
(define-structure distribution-variable distribution demons)
(define (upon-bottom-thunk thunk)
(let ((saved-bottom bottom))
(set! bottom (lambda () (thunk) (saved-bottom)))))
(define (create-distribution-variable distribution)
(let ((distribution
(remove-if (lambda (pair) (zero? (cdr pair))) distribution)))
(when (null? distribution) (bottom))
(make-distribution-variable distribution '())))
(define (restrict-distribution! x distribution)
(define (local-set-distribution-variable-distribution!
distribution-variable distribution)
(let ((distribution
(distribution-variable-distribution distribution-variable)))
(upon-bottom-thunk
(lambda ()
(set-distribution-variable-distribution!
distribution-variable distribution))))
(set-distribution-variable-distribution! distribution-variable distribution))
(when (null? distribution) (bottom))
(when (< (length distribution)
(length (distribution-variable-distribution x)))
(local-set-distribution-variable-distribution! x distribution)
(for-each (lambda (demon) (demon)) (distribution-variable-demons x))))
(define (gm-bound? x) (null? (rest (distribution-variable-distribution x))))
(define (gm-binding x) (car (first (distribution-variable-distribution x))))
(define (gm-solution ds)
(let loop ((ds ds) (xs '()))
(if (null? ds)
(reverse xs)
(let ((pair
(draw-pair (distribution-variable-distribution (first ds)))))
(restrict-distribution! (first ds) (list pair))
(loop (rest ds) (cons (first pair) xs))))))
(define (gm-bb-solution ds)
(let ((best 0))
(let loop ((ds ds) (xs '()))
(when (<= (current-probability) best) (bottom))
(cond
((null? ds)
(when (< best (current-probability)) (set! best (current-probability)))
(reverse xs))
(else
(let ((pair
(draw-pair (distribution-variable-distribution (first ds)))))
(restrict-distribution! (first ds) (list pair))
(loop (rest ds) (cons (first pair) xs))))))))
(define (gm-bb-predict-solution ds)
(let ((best 0))
(let loop ((ds ds) (xs '()))
(when (or (<= (current-probability) best)
(<= (foldl
(lambda (v d)
(* v
(map-reduce max
-inf.0
cdr
(distribution-variable-distribution d))))
ds
(current-probability))
best))
(bottom))
(cond
((null? ds)
(when (< best (current-probability)) (set! best (current-probability)))
(reverse xs))
(else
(let ((pair
(draw-pair (distribution-variable-distribution (first ds)))))
(restrict-distribution! (first ds) (list pair))
(loop (rest ds) (cons (first pair) xs))))))))
(define (gm-bb-predict-solution-with-start ds start)
(let ((best start))
(let loop ((ds ds) (xs '()))
(when (or (<= (current-probability) best)
(<= (foldl
(lambda (v d)
(* v
(map-reduce max
-inf.0
cdr
(distribution-variable-distribution d))))
ds
(current-probability))
best))
(bottom))
(cond
((null? ds)
(when (< best (current-probability)) (set! best (current-probability)))
(reverse xs))
(else
(let ((pair
(draw-pair (distribution-variable-distribution (first ds)))))
(restrict-distribution! (first ds) (list pair))
(loop (rest ds) (cons (first pair) xs))))))))
(define (some-element p x)
(some (lambda (x) (p (car x))) (distribution-variable-distribution x)))
(define (one-element p x)
(one (lambda (x) (p (car x))) (distribution-variable-distribution x)))
(define (the-element p x)
(list (find-if (lambda (x) (p (car x)))
(distribution-variable-distribution x))))
(define (the-elements p x)
(remove-if-not (lambda (x) (p (car x)))
(distribution-variable-distribution x)))
(define (attach-demon! demon x)
(define (local-set-distribution-variable-demons! distribution-variable demons)
(let ((demons (distribution-variable-demons distribution-variable)))
(upon-bottom-thunk
(lambda ()
(set-distribution-variable-demons! distribution-variable demons))))
(set-distribution-variable-demons! distribution-variable demons))
(local-set-distribution-variable-demons!
x (cons demon (distribution-variable-demons x)))
(demon))
(define (gm-assert-constraint-efd! constraint xs)
(for-each
(lambda (x)
(attach-demon! (lambda ()
(when (every gm-bound? xs)
(unless (apply constraint (map gm-binding xs)) (bottom))))
x))
xs))
(define (gm-assert-constraint-fc! constraint xs)
(for-each
(lambda (x)
(attach-demon!
(lambda ()
(when (one (lambda (x) (not (gm-bound? x))) xs)
(let* ((i (position-if (lambda (x) (not (gm-bound? x))) xs))
(x (list-ref xs i)))
(unless (some-element
(lambda (xe)
(apply
constraint
(map-indexed (lambda (x j) (if (= j i) xe (gm-binding x))) xs)))
x)
(bottom)))))
x))
xs))
(define (gm-assert-constraint-vp! constraint xs)
(for-each
(lambda (x)
(attach-demon!
(lambda ()
(when (one (lambda (x) (not (gm-bound? x))) xs)
(let* ((i (position-if (lambda (x) (not (gm-bound? x))) xs))
(x (list-ref xs i)))
(when (one-element
(lambda (xe)
(apply
constraint
(map-indexed (lambda (x j) (if (= j i) xe (gm-binding x))) xs)))
x)
(restrict-distribution!
x
(the-element
(lambda (xe)
(apply constraint
(map-indexed (lambda (x j) (if (= j i) xe (gm-binding x))) xs)))
x))))))
x))
xs))
(define (gm-assert-constraint-gfc! constraint xs)
(for-each
(lambda (x)
(attach-demon!
(lambda ()
(when (one (lambda (x) (not (gm-bound? x))) xs)
(let* ((i (position-if (lambda (x) (not (gm-bound? x))) xs))
(x (list-ref xs i)))
(restrict-distribution!
x
(the-elements
(lambda (xe)
(apply constraint
(map-indexed (lambda (x j) (if (= j i) xe (gm-binding x))) xs)))
x)))))
x))
xs))
(define (gm-assert-constraint-ac! constraint ds)
(for-each-indexed
(lambda (d k)
(attach-demon!
(lambda ()
(for-each-indexed
(lambda (d i)
(unless (= i k)
(restrict-distribution!
d
(the-elements
(lambda (x)
(let loop ((ds ds) (xs '()) (j 0))
(if (null? ds)
(apply constraint (reverse xs))
(if (= j i)
(loop (rest ds) (cons x xs) (+ j 1))
(some (lambda (pair)
(loop (rest ds) (cons (car pair) xs) (+ j 1)))
(distribution-variable-distribution (first ds)))))))
d))))
ds))
d))
ds))
(define (gm-assert-constraint! constraint . distribution-variables)
(case *gm-strategy*
((efd) (gm-assert-constraint-efd! constraint distribution-variables))
((fc) (gm-assert-constraint-fc! constraint distribution-variables))
((vp) (gm-assert-constraint-fc! constraint distribution-variables)
(gm-assert-constraint-vp! constraint distribution-variables))
((gfc) (gm-assert-constraint-gfc! constraint distribution-variables))
((ac) (gm-assert-constraint-ac! constraint distribution-variables))
(else (error "Unrecognized strategy"))))
)
| true |
bff15c98f8a21333362a5a9f37342bc7e79c8853
|
4b2aeafb5610b008009b9f4037d42c6e98f8ea73
|
/12.2/section.scm
|
d04c48b62e4fe96787559ef62fcf9cccf3ae134f
|
[] |
no_license
|
mrinalabrol/clrs
|
cd461d1a04e6278291f6555273d709f48e48de9c
|
f85a8f0036f0946c9e64dde3259a19acc62b74a1
|
refs/heads/master
| 2021-01-17T23:47:45.261326 | 2010-09-29T00:43:32 | 2010-09-29T00:43:32 | null | 0 | 0 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 430 |
scm
|
section.scm
|
(require-extension
syntax-case
(srfi 1 9))
(require '../12.1/section)
(module
section-12.2
(bt-search
bt-min
bt-max
bt-successor
bt-predecessor
figure-12.2/root
figure-12.2/13
figure-12.2/17)
(import* section-12.1
bt-node-right
bt-node-left
bt-node-parent
bt-node-key
make-bt-node
set-bt-node-left-right-parent!)
(include "../12.2/binary-tree.scm"))
| false |
ff5d5aab5dd75e58131fe60cb38370b54d5ec069
|
1d042bcd7bbc6bd323424f9302810f91c27e36d5
|
/l3.scm
|
39a6f4da0fd4bb7fddc8a8917ad64f837e1810ee
|
[] |
no_license
|
haoxianhan/yast-exercise
|
4940c85ef305b6237d7006c06dc4ce37875d2e4d
|
40288c2e15d8661b072d8291dd75cc42c2d1086d
|
refs/heads/main
| 2023-01-03T13:09:58.778556 | 2020-10-29T02:08:15 | 2020-10-29T02:08:15 | 303,937,893 | 0 | 0 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 2,021 |
scm
|
l3.scm
|
; Hello world as a variable
(define vhello "Hello world") ;1
; Hello world as a function
(define fhello (lambda () ;2
"Hello world"))
(define hello
(lambda (name)
(string-append "hello " name "!")))
(define sum3
(lambda (a b c)
(+ a b c)))
(define (hello1 name)
(string-append "hello " name "!"))
(define (sum31 a b c)
(+ a b c))
; 练习1
; 按照下面的要求编写函数。这些都非常简单但实用。
; 将参数加1的函数。
; 将参数减1的函数。
(define (add_one a)
(+ a 1))
(define (sub_one a)
(- a 1))
; 练习2
; 让我们按照下面的步骤编写一个用于计算飞行距离的函数。
; 编写一个将角的单位由度转换为弧度的函数。180度即π弧度。π可以通过下面的式子定义: (define pi (* 4 (atan 1.0)))。
(define pi (* 4 (atan 1.0)))
(define (trans2radian angle_degree)
(* pi (/ (remainder angle_degree 180) 180)))
; 编写一个用于计算按照一个常量速度(水平分速度)运动的物体,t秒内的位移的函数。
(define (dis speed time)
(* speed time)
; 编写一个用于计算物体落地前的飞行时间的函数,参数是垂直分速度。忽略空气阻力并取重力加速度g为9.8m/s^2。提示:设落地时瞬时竖直分速度为-Vy,有如下关系。2 * Vy = g * t此处t为落地时的时间。
(define (fall_time vy)
(/ (* 2 vy) 9.8))
; 使用问题1-3中定义的函数编写一个用于计算一个以初速度v和角度theta掷出的小球的飞行距离。
; 计算一个初速度为40m/s、与水平方向呈30°的小球飞行距离。这个差不多就是一个臂力强劲的职业棒球手的投掷距离。
; 提示:首先,将角度的单位转换为弧度(假定转换后的角度为theta1)。初始水平、竖直分速度分别表示为:v*cos(theta1)和v*sin(theta1)。落地时间可以通过问题3中定义的函数计算。由于水平分速度不会改变, 因此可以利用问题2中的函数计算距离。
| false |
cea21ae54fe54e709fa23eda14635193d4eab7ee
|
784dc416df1855cfc41e9efb69637c19a08dca68
|
/src/std/parser/lexer.ss
|
262583575c04cbb9859760e7bfa2e68badc9246b
|
[
"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 | 6,024 |
ss
|
lexer.ss
|
;;; -*- Gerbil -*-
;;; (C) vyzo
;;; std parser lexer and lexer generator
package: std/parser
(import :std/parser/base
:std/parser/stream
:std/parser/rlang)
(export lex lex-chars
token-stream?
token-stream-close
token-stream-get
token-stream-next
token-stream-unget
token-stream-peek
token-stream-loc
$ $? $$ $$?)
(defstruct token-stream (cs buf Ls Rs $$)
final: #t)
;; ignored token [eg whitespace, comments]
(def $ (make-token '$ #!void #f))
(def ($? obj)
(eq? $ obj))
;; end of input -- to signal the parser to stop
(def ($$ loc)
(make-token '$$ (eof-object) loc))
(def ($$? obj)
(match obj
((token '$$) #t)
((? eof-object?) #t)
(else #f)))
;; input: string, character-input-port, or char-stream
;; Ls: list of rlangs for each lexeme [see lex1]
;; Rs: list of reductions for each lexeme [see lex1]
;; => token-stream
(def (lex input Ls Rs)
(let (cs (lexer-input-stream input))
(make-token-stream cs [] Ls Rs #f)))
;; simples possible lexer: produces character tokens for every char in the stream
(def (lex-chars input)
(lex input [@dot] [(lambda (str loc) (make-token 'Char (string-ref str 0) loc))]))
(def (token-stream-close ts)
(char-stream-close
(token-stream-cs ts)))
(def (token-stream-get ts)
(with ((token-stream cs buf Ls Rs) ts)
(match buf
([tok . rest]
(set! (token-stream-buf ts)
rest)
tok)
(else
(let lp ()
(let (next (lex1 cs Ls Rs))
(if ($? next)
(lp)
next)))))))
;; get the next token, mapping eof to $$
(def (token-stream-next ts)
(let (next (token-stream-get ts))
(if (eof-object? next)
(cond
((token-stream-$$ ts) => values)
(else
(let (eof ($$ (char-stream-loc (token-stream-cs ts))))
(set! (token-stream-$$ ts)
eof)
eof)))
next)))
(def (token-stream-unget ts tok)
(unless (eof-object? tok)
(with ((token-stream _ buf) ts)
(set! (token-stream-buf ts)
(cons tok buf)))))
(def (token-stream-peek ts)
(with ((token-stream _ buf) ts)
(match buf
([tok . rest]
tok)
(else
(let (next (token-stream-get ts))
(unless (eof-object? next)
(set! (token-stream-buf ts)
[next]))
next)))))
(def (token-stream-loc ts)
(with ((token-stream cs buf) ts)
(match buf
([tok . rest]
(token-loc tok))
(else
(char-stream-loc cs)))))
(def (lexer-input-stream inp)
(cond
((input-port? inp)
(make-char-stream inp))
((string? inp)
(make-char-stream (open-input-string inp)))
((char-stream? inp) inp)
(else
(error "Bad input source; expected input-port, string or char-stream" inp))))
;; cs: char-stream
;; Ls: list of rlangs for each lexeme; matches longest, with ties resolved in order
;; Rs: list of reductions receiving lexeme text and location to construct a token
(def (lex1 cs Ls Rs)
(def (chars->string chars)
(list->string (reverse chars)))
(def (token-e t e start end)
(let (loc (location-delta start end))
(make-token t e loc)))
(def (raise-e chars start end)
(let (tok (token-e 'ERROR (chars->string chars) start end))
(raise-parse-error 'lex "No lexeme matching input" tok)))
(def (loop Ls chars start E)
(let (next (char-stream-getc cs))
(if (eof-object? next)
(if (null? chars)
;; we are not parsing any lexeme, this plain old eof
(eof-object)
;; check if any L is nullable, then it matches the lexeme
(let lp ((rest-Ls Ls) (rest-Rs Rs))
(match rest-Ls
([L . rest-Ls]
(match rest-Rs
([R . rest-Rs]
(if (delta L)
(let (end (char-stream-loc cs))
(R (chars->string chars) (location-delta start end)))
(lp rest-Ls rest-Rs)))))
(else
;; no match, fail with incomplete parse
(E chars)))))
(let* ((chars (cons next chars))
(Ls* (map (cut deriv <> next) Ls))
(deltas (map delta Ls*)))
(cond
((ormap values deltas)
;; some lexeme has matched
;; try for longer match with an E that returns the current lexeme
(let* ((end (char-stream-loc cs))
(E (lambda (xchars)
;; return extra chars to the stream
(let (count (##fx- (length xchars) (length chars)))
(let lp ((rest xchars) (k 0))
(when (##fx< k count)
(match rest
([char . rest]
(char-stream-ungetc cs char)
(lp rest (##fx+ k 1)))))))
;; find first match and apply rule
(let lp ((rest-deltas deltas) (rest-Rs Rs))
(match rest-deltas
([hd . rest-deltas]
(match rest-Rs
([R . rest-Rs]
(if hd
(R (chars->string chars) (location-delta start end))
(lp rest-deltas rest-Rs))))))))))
(loop Ls* chars start E)))
((ormap (? (not @nul?)) Ls*)
;; some lexeme is still matching, continue
(loop Ls* chars start E))
(else
;; no lexeme matches, continue with E
(E chars)))))))
(let* ((first (char-stream-getc cs)) ; get the right starting location!
(start (char-stream-loc cs))
(_ (char-stream-ungetc cs first))
(E (lambda (chars)
(let (end (char-stream-loc cs))
(raise-e chars start end)))))
(loop Ls [] start E)))
| false |
ac46e98dd54b940feaa9f3c7efc7003d8b7b80c2
|
00466b7744f0fa2fb42e76658d04387f3aa839d8
|
/sicp/chapter2/2.2/ex2.19.scm
|
6a961847da43051a07870ad9855092d0a37b6fec
|
[
"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 | 1,278 |
scm
|
ex2.19.scm
|
#lang scheme
; from 1.2.2
(define (count-change amount)
(define (cc amount kinds-of-coins)
(cond
((= amount 0) 1)
((or (< amount 0) (= kinds-of-coins 0)) 0)
(else
(+ (cc amount (- kinds-of-coins 1))
(cc (- amount (denomination kinds-of-coins))
kinds-of-coins
)
)
)
)
)
(define (denomination kinds-of-coins)
(cond
((= kinds-of-coins 1) 1)
((= kinds-of-coins 2) 5)
((= kinds-of-coins 3) 10)
((= kinds-of-coins 4) 25)
((= kinds-of-coins 5) 50)
)
)
(cc amount 5)
)
(count-change 100)
; 2.19
(define (count-change-list amount coins)
(define (cc amount coins)
(cond
((= amount 0) 1)
((or (< amount 0) (null? coins)) 0)
(else
(+ (cc (- amount (car coins)) coins)
(cc amount (cdr coins))))
)
)
(cc amount coins)
)
(define us-coins (list 1 5 10 25 50))
(define uk-coins (list 0.5 1 2 5 10 20 50 100))
(count-change-list 100 us-coins)
(count-change-list 100 uk-coins)
| false |
4ec55fdc5d49b175c92b9245c37e3f3f7d4230b5
|
b25f541b0768197fc819f1bb01688808b4a60b30
|
/s9/lib/simple-module.scm
|
7a42c09f5275f070bef6854ebf3a0ec1e955db65
|
[
"LicenseRef-scancode-warranty-disclaimer",
"LicenseRef-scancode-public-domain"
] |
permissive
|
public-domain/s9fes
|
327c95115c2ecb7fab976307ae7cbb1d4672f843
|
f3c3f783da7fd74daa8be7e15f1c31f827426985
|
refs/heads/master
| 2021-02-09T01:22:30.573860 | 2020-03-01T20:50:48 | 2020-03-01T20:50:48 | 244,221,631 | 0 | 0 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 1,666 |
scm
|
simple-module.scm
|
; Scheme 9 from Empty Space, Function Library
; By Nils M Holm, 2009
; Placed in the Public Domain
;
; (module <name> <definition> ...) ==> unspecific
; (import <name> (<name_i> ...) <expression> ...) ==> object
;
; (load-from-library "simple-module.scm")
;
; Simple modules. Inside of a MODULE expression, DEFINE defines
; a local object and DEFINE* defines a public object. <Name> names
; the module itself.
;
; Expressions inside of IMPORT may use all <name_i>'s that are
; being imported from the module <name>.
;
; Example: (begin ; Note: BEGIN is only needed for automatic testing
; (module math
; (define* (fact x)
; (if (= 0 x) 1 (* x (fact (- x 1))))))
; (import math (fact)
; (fact 5))) ==> 120
(load-from-library "syntax-rules.scm")
(define-syntax module
(syntax-rules (define define*)
((_ (m e))
(letrec e (list . m)))
((_ (m e) (define (n . a*) . body) . defs)
(module (m e) (define n (lambda a* . body)) . defs))
((_ (m e) (define n v) . defs)
(module (m ((n v) . e)) . defs))
((_ (m e) (define* (n . a*) . body) . defs)
(module (m e) (define* n (lambda a* . body)) . defs))
((_ (m e) (define* n v) . defs)
(module (((cons 'n v) . m) ((n v) . e)) . defs))
((_ n . defs)
(define n (module (() ()) . defs)))))
(define-syntax import
(syntax-rules ()
((_ (n e ()) . body)
(let e . body))
((_ (n e (i . r)) . body)
(import (n ((i (cdr (assq 'i n))) . e) r) . body))
((_ n (i . r) . body)
(import (n () (i . r)) . body))))
| true |
126e520971729cce31cb82c93148a5866acbde84
|
fb93352482541f4269387c5872b9f1124a9182d3
|
/ng/chapter01/sicp-1.23-1.ss
|
f9e68c781dc35b7b7f7f0069df6e5f35c12c3456
|
[] |
no_license
|
sicper/sicp-solutions
|
bfb5bd0f9f6eba0b396af88a4b5a2834ccfc5054
|
b79c3d9f193fbec26b5302f03de6dabd473203cf
|
refs/heads/master
| 2021-01-14T13:42:47.796733 | 2016-01-04T05:03:48 | 2016-01-04T05:03:48 | 38,525,815 | 1 | 0 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 1,086 |
ss
|
sicp-1.23-1.ss
|
(load "sicp-utils.ss")
(define (find-divisor-old n test-divisor)
(cond ((> (square test-divisor) n) n)
((divides? test-divisor n) test-divisor)
(else (find-divisor-old n (+ test-divisor 1)))))
(define (smallest-divisor-old n)
(find-divisor-old n 2))
(define (next n)
(if (= n 2)
3
(+ n 2)))
(define (find-divisor-new n test-divisor)
(cond ((> (square test-divisor) n) n)
((divides? test-divisor n) test-divisor)
(else (find-divisor-new n (next test-divisor)))))
(define (smallest-divisor-new n)
(find-divisor-new n 2))
(require racket/trace)
(trace find-divisor-old)
(trace find-divisor-new)
(define prime-1000 (list-primes-n 1000 10000 3))
(define prime-10000 (list-primes-n 10000 1000000 3))
(define prime-100000 (list-primes-n 100000 1000000 3))
(define prime-list (append prime-1000
prime-10000
prime-100000))
(for ([n (list-primes-n 100 1000 1)])
(display "process ")
(display n)
(newline)
(smallest-divisor-old n)
(smallest-divisor-new n)
(newline))
| false |
ca109626c68d9203d59d43aa8854c8081a1cb00a
|
a23edab8bc45f7a0ee3b4b7effbcf7572ef11951
|
/scheme/chicken/geiser/emacs.scm
|
cddf8da3452e6d9d8cf195f94547668ee9d8ffaa
|
[
"BSD-3-Clause"
] |
permissive
|
siccegge/geiser
|
cacc7f050acb6182a24eb66d8fda838ee975106d
|
24acd9f971afa36a9e9e11a48bcef6c699e497fa
|
refs/heads/master
| 2021-01-15T22:34:17.966479 | 2015-09-09T15:40:04 | 2015-09-09T15:40:04 | 42,188,316 | 1 | 0 | null | 2015-09-09T15:46:12 | 2015-09-09T15:46:12 | null |
UTF-8
|
Scheme
| false | false | 27,057 |
scm
|
emacs.scm
|
;; Copyright (C) 2015 Daniel J Leslie
;; This program is free software; you can redistribute it and/or
;; modify it under the terms of the Modified BSD License. You should
;; have received a copy of the license along with this program. If
;; not, see <http://www.xfree86.org/3.3.6/COPYRIGHT2.html#5>.
(module geiser
;; A bunch of these needn't be toplevel functions
(geiser-eval
geiser-no-values
geiser-newline
geiser-start-server
geiser-completions
geiser-autodoc
geiser-object-signature
geiser-symbol-location
geiser-symbol-documentation
geiser-find-file
geiser-add-to-load-path
geiser-load-file
geiser-compile-file
geiser-compile
geiser-module-exports
geiser-module-path
geiser-module-location
geiser-module-completions
geiser-macroexpand
make-geiser-toplevel-bindings)
;; Necessary built in units
(import chicken
scheme
extras
data-structures
ports
csi
irregex
srfi-1
posix
utils)
(use apropos
regex
chicken-doc
tcp
srfi-18)
(define use-debug-log #f)
(if use-debug-log
(use posix))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Symbol lists
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(define geiser-r4rs-symbols
(make-parameter
'(not boolean? eq? eqv? equal? pair? cons car cdr caar cadr cdar cddr
caaar caadr cadar caddr cdaar cdadr cddar cdddr caaaar caaadr caadar
caaddr cadaar cadadr caddar cadddr cdaaar cdaadr cdadar cdaddr cddaar
cddadr cdddar cddddr set-car! set-cdr! null? list? list length
list-tail list-ref append reverse memq memv member assq assv assoc
symbol? symbol->string string->symbol number? integer? exact? real?
complex? inexact? rational? zero? odd? even? positive? negative?
max min + - * / = > < >= <= quotient remainder modulo gcd lcm abs
floor ceiling truncate round exact->inexact inexact->exact exp log
expt sqrt sin cos tan asin acos atan number->string string->number
char? char=? char>? char<? char>=? char<=? char-ci=? char-ci<?
char-ci>? char-ci>=? char-ci<=? char-alphabetic? char-whitespace?
char-numeric? char-upper-case? char-lower-case? char-upcase
char-downcase char->integer integer->char string? string=? string>?
string<? string>=? string<=? string-ci=? string-ci<? string-ci>?
string-ci>=? string-ci<=? make-string string-length string-ref
string-set! string-append string-copy string->list list->string
substring string-fill! vector? make-vector vector-ref vector-set!
string vector vector-length vector->list list->vector vector-fill!
procedure? map for-each apply force call-with-current-continuation
input-port? output-port? current-input-port current-output-port
call-with-input-file call-with-output-file open-input-file
open-output-file close-input-port close-output-port load
read eof-object? read-char peek-char write display write-char
newline with-input-from-file with-output-to-file eval char-ready?
imag-part real-part magnitude numerator denominator
scheme-report-environment null-environment interaction-environment
else)))
(define geiser-r5rs-symbols
(make-parameter
'(abs acos and angle append apply asin assoc assq assv atan begin
boolean? caar cadr call-with-current-continuation
call-with-input-file call-with-output-file call-with-values
car case cdddar cddddr cdr ceiling char->integer char-alphabetic?
char-ci<=? char-ci<? char-ci=? char-ci>=? char-ci>? char-downcase
char-lower-case? char-numeric? char-ready? char-upcase
char-upper-case? char-whitespace? char<=? char<? char=? char>=?
char>? char? close-input-port close-output-port complex? cond cons
cos current-input-port current-output-port define define-syntax
delay denominator display do dynamic-wind else eof-object? eq?
equal? eqv? eval even? exact->inexact exact? exp expt floor
for-each force gcd if imag-part inexact->exact inexact? input-port?
integer->char integer? interaction-environment lambda lcm length
let let* let-syntax letrec letrec-syntax list list->string
list->vector list-ref list-tail list? load log magnitude make-polar
make-rectangular make-string make-vector map max member memq memv
min modulo negative? newline not null-environment null?
number->string number? numerator odd? open-input-file
open-output-file or output-port? pair? peek-char port? positive?
procedure? quasiquote quote quotient rational? rationalize read
read-char real-part real? remainder reverse round
scheme-report-environment set! set-car! set-cdr! setcar sin sqrt
string string->list string->number string->symbol string-append
string-ci<=? string-ci<? string-ci=? string-ci>=? string-ci>?
string-copy string-fill! string-length string-ref string-set!
string<=? string<? string=? string>=? string>? string? substring
symbol->string symbol? syntax-rules tan transcript-off transcript-on
truncate values vector vector->list vector-fill! vector-length
vector-ref vector-set! vector? with-input-from-file with-output-to-file
write write-char zero?)))
(define geiser-r7rs-small-symbols
(make-parameter
'(* + - ... / < <= = => > >= abs and append apply assoc assq
assv begin binary-port? boolean=? boolean? bytevector
bytevector-append bytevector-copy bytevector-copy! bytevector-length
bytevector-u8-ref bytevector-u8-set! bytevector? caar cadr
call-with-current-continuation call-with-port call-with-values call/cc
car case cdar cddr cdr ceiling char->integer char-ready? char<=?
char<? char=? char>=? char>? char? close-input-port
close-output-port close-port complex? cond cond-expand cons
current-error-port current-input-port current-output-port
define define-record-type define-syntax define-values denominator do
dynamic-wind else eof-object? equal? error error-object-message
even? exact-integer-sqrt exact? features floor floor-remainder
flush-output-port gcd get-output-string if include-ci inexact?
input-port? integer? lcm let let*-values let-values letrec* list
list->vector list-ref list-tail make-bytevector make-parameter
make-vector max memq min negative? not number->string numerator
open-input-bytevector open-output-bytevector or output-port?
parameterize peek-u8 positive? quasiquote quotient raise-continuable
rationalize read-bytevector! read-error? read-string real? reverse
set! set-cdr! string string->number string->utf8 string-append
eof-object eq? eqv? error-object-irritants error-object? exact
exact-integer? expt file-error? floor-quotient floor/ for-each
get-output-bytevector guard include inexact input-port-open?
integer->char lambda length let* let-syntax letrec letrec-syntax
list->string list-copy list-set! list? make-list make-string map
member memv modulo newline null? number? odd? open-input-string
open-output-string output-port-open? pair? peek-char port?
procedure? quote raise rational? read-bytevector read-char read-line
read-u8 remainder round set-car! square string->list string->symbol
string->vector string-copy string-copy! string-for-each string-map
string-set! string<? string>=? string? symbol->string symbol?
syntax-rules truncate truncate-remainder u8-ready? unquote
utf8->string vector vector->string vector-copy vector-fill!
vector-length vector-ref vector? with-exception-handler write-char
write-u8 string-fill! string-length string-ref string<=?
string=? string>? substring symbol=? syntax-error textual-port?
truncate-quotient truncate/ unless unquote-splicing values
vector->list vector-append vector-copy! vector-for-each vector-map
vector-set! when write-bytevector write-string zero?)))
(define geiser-chicken-builtin-symbols
(make-parameter
'(and-let* assume compiler-typecase cond-expand condition-case cut cute declare define-constant
define-inline define-interface define-record define-record-type define-specialization
define-syntax-rule define-type define-values dotimes ecase fluid-let foreign-lambda
foreign-lambda* foreign-primitive foreign-safe-lambda foreign-safe-lambda* functor
handle-exceptions import let*-values let-location let-optionals let-optionals*
let-values letrec* letrec-values match-letrec module parameterize regex-case
require-extension select set! unless use when with-input-from-pipe match
match-lambda match-lambda* match-let match-let* receive)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Utilities
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(define find-module ##sys#find-module)
(define current-module ##sys#current-module)
(define switch-module ##sys#switch-module)
(define module-name ##sys#module-name)
(define (list-modules) (map car ##sys#module-table))
(define (write-to-log form) #f)
(define debug-log (make-parameter #f))
(if use-debug-log
(begin
(define (write-to-log form)
(when (not (debug-log))
(debug-log (file-open "~/geiser-log.txt" (+ open/wronly open/append open/text open/creat)))
(set-file-position! (debug-log) 0 seek/end))
(file-write (debug-log) (with-all-output-to-string (lambda () (write form) (newline))))
(file-write (debug-log) "\n"))))
;; This really should be a chicken library function
(define (write-exception exn)
(define (write-call-entry call)
(let ((type (vector-ref call 0))
(line (vector-ref call 1)))
(cond
((equal? type "<syntax>")
(display (string-append type " ")) (write line) (newline))
((equal? type "<eval>")
(display (string-append type " ")) (write line) (newline)))))
(display (format "Error: (~s) ~s: ~s"
((condition-property-accessor 'exn 'location) exn)
((condition-property-accessor 'exn 'message) exn)
((condition-property-accessor 'exn 'arguments) exn)))
(newline)
(display "Call history: ") (newline)
(map write-call-entry ((condition-property-accessor 'exn 'call-chain) exn))
(newline))
;; And this should be a chicken library function as well
(define (with-all-output-to-string thunk)
(with-output-to-string
(lambda ()
(with-error-output-to-port
(current-output-port)
thunk))))
(define (maybe-call func val)
(if val (func val) #f))
(define (make-apropos-regex prefix)
(string-append "^([^#]+#)*" (regexp-escape prefix)))
(define (describe-symbol sym #!key (exact? #f))
(let* ((str (->string sym))
(found (apropos-information-list (regexp (make-apropos-regex str)) #:macros? #t)))
(delete-duplicates
(if exact?
(filter (lambda (v)
(equal? str (string-substitute ".*#([^#]+)" "\\1" (symbol->string (car v)))))
found)
found))))
;; Wraps output from geiser functions
(define (call-with-result module thunk)
(let* ((result (if #f #f))
(output (if #f #f))
(module (maybe-call (lambda (v) (find-module module)) module))
(original-module (current-module)))
(set! output
(handle-exceptions exn
(with-all-output-to-string
(lambda () (write-exception exn)))
(with-all-output-to-string
(lambda ()
(switch-module module)
(call-with-values thunk (lambda v (set! result v)))))))
(switch-module original-module)
(set! result
(cond
((list? result)
(map (lambda (v) (with-output-to-string (lambda () (pretty-print v)))) result))
((eq? result (if #f #t))
(list output))
(else
(list (with-output-to-string (lambda () (pretty-print result)))))))
(let ((out-form
`((result ,@result)
(output . ,output))))
(write out-form)
(write-to-log out-form))
(newline)))
(define geiser-toplevel-functions (make-parameter '()))
;; This macro aids in the creation of toplevel definitions for the interpreter which are also available to code
;; toplevel passes parameters via the current-input-port, and so in order to make the definition behave nicely
;; in both usage contexts I defined a (get-arg) function which iteratively pulls arguments either from the
;; input port or from the variable arguments, depending on context.
(define-syntax define-toplevel-for-geiser
(lambda (f r c)
(let* ((name (cadr f))
(body (cddr f)))
`(begin
(,(r 'define) (,name . !!args)
(,(r 'define) !!read-arg (null? !!args))
(,(r 'define) (get-arg)
(if !!read-arg
(read)
(let ((arg (car !!args)))
(set! !!args (cdr !!args))
arg)))
(begin ,@body))
(,(r 'geiser-toplevel-functions) (cons (cons ',name ,name) (geiser-toplevel-functions)))))))
(define (find-standards-with-symbol sym)
(append
(if (any (cut eq? <> sym) (geiser-r4rs-symbols))
'(r4rs)
'())
(if (any (cut eq? <> sym) (geiser-r5rs-symbols))
'(r5rs)
'())
(if (any (cut eq? <> sym) (geiser-r7rs-small-symbols))
'(r7rs)
'())
(if (any (cut eq? <> sym) (geiser-chicken-builtin-symbols))
'(chicken)
'())))
;; Locates any paths at which a particular symbol might be located
(define (find-library-paths sym types)
;; Removes the given sym from the node path
(define (remove-self sym path)
(cond
((not (list? path)) path)
((null? path) path)
((null? (cdr path))
(if (eq? (car path) sym)
'()
path))
(else
(cons (car path) (remove-self sym (cdr path))))))
(append
(map
(cut list <>)
(find-standards-with-symbol sym))
(map
(lambda (node)
(remove-self sym (node-path node)))
(filter
(lambda (n)
(let ((type (node-type n)))
(any (cut eq? type <>) types)))
(match-nodes sym)))))
;; Builds a signature list from an identifier
(define (find-signatures toplevel-module sym)
(define str (->string sym))
(define (make-module-list sym module-sym)
(if (null? module-sym)
(find-standards-with-symbol sym)
(cons module-sym (find-standards-with-symbol sym))))
(define (fmt node)
(let* ((entry-str (car node))
(module (cadr node))
(rest (cddr node))
(type (if (or (list? rest) (pair? rest)) (car rest) rest)))
(cond
((equal? 'macro type)
`(,entry-str ("args" (("required" <macro>)
("optional" ...)
("key")))
("module" ,@(make-module-list sym module))))
((or (equal? 'variable type)
(equal? 'constant type))
(if (null? module)
`(,entry-str ("value" . ,(eval sym)))
(let* ((original-module (current-module))
(desired-module (find-module (string->symbol module)))
(value (begin (switch-module desired-module)
(eval sym))))
(switch-module original-module)
`(,entry-str ("value" . ,value)
("module" ,@(make-module-list sym module))))))
(else
(let ((reqs '())
(opts '())
(keys '())
(args (if (or (list? rest) (pair? rest)) (cdr rest) '())))
(define (clean-arg arg)
(string->symbol (string-substitute "(.*[^0-9]+)[0-9]+" "\\1" (->string arg))))
(define (collect-args args #!key (reqs? #t) (opts? #f) (keys? #f))
(when (not (null? args))
(cond
((or (pair? args) (list? args))
(cond
((eq? '#!key (car args))
(collect-args (cdr args) reqs?: #f opts?: #f keys?: #t))
((eq? '#!optional (car args))
(collect-args (cdr args) reqs?: #f opts?: #t keys?: #f))
(else
(begin
(cond
(reqs?
(set! reqs (append reqs (list (clean-arg (car args))))))
(opts?
(set! opts (append opts (list (cons (clean-arg (caar args)) (cdar args))))))
(keys?
(set! keys (append keys (list (cons (clean-arg (caar args)) (cdar args)))))))
(collect-args (cdr args))))))
(else
(set! opts (list (clean-arg args) '...))))))
(collect-args args)
`(,entry-str ("args" (("required" ,@reqs)
("optional" ,@opts)
("key" ,@keys)))
("module" ,@(make-module-list sym module))))))))
(define (find sym)
(map
(lambda (s)
;; Remove egg name and add module
(let* ((str (symbol->string (car s)))
(name (string-substitute ".*#([^#]+)" "\\1" str))
(module
(if (string-search "#" str)
(string-substitute "^([^#]+)#[^#]+$" "\\1" str)
'())))
(cons name (cons module (cdr s)))))
(describe-symbol sym exact?: #t)))
(map fmt (find sym)))
;; Builds the documentation from Chicken Doc for a specific symbol
(define (make-doc symbol #!optional (filter-for-type #f))
(with-output-to-string
(lambda ()
(map (lambda (node)
(display (string-append "= Node: " (->string (node-id node)) " " " =\n"))
(describe node)
(display "\n\n"))
(filter
(lambda (n)
(or (not filter-for-type)
(eq? (node-type n) filter-for-type)))
(match-nodes symbol))))))
(define (make-geiser-toplevel-bindings)
(map
(lambda (pair)
(toplevel-command (car pair) (cdr pair)))
(geiser-toplevel-functions)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Geiser toplevel functions
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Basically all non-core functions pass through geiser-eval
(define-toplevel-for-geiser geiser-eval
;; We can't allow nested module definitions in Chicken
(define (form-has-module? form)
(let ((reg "\\( *module +|\\( *define-library +"))
(string-search reg form)))
;; Chicken doesn't support calling toplevel functions through eval,
;; So when we're in a module or calling into an environment we have
;; to first call from the toplevel environment and then switch
;; into the desired env.
(define (form-has-geiser? form)
(let ((reg "\\( *geiser-"))
(string-search reg form)))
;; All calls start at toplevel
(let* ((module (get-arg))
(form (get-arg))
(str-form (format "~s" form))
(is-module? (form-has-module? str-form))
(is-geiser? (form-has-geiser? str-form))
(host-module (and (not is-module?)
(not is-geiser?)
(any (cut equal? module <>) (list-modules))
module)))
(when (and module (not (symbol? module)))
(error "Module should be a symbol"))
;; Inject the desired module as the first parameter
(when is-geiser?
(let ((module (maybe-call (lambda (v) (symbol->string module)) module)))
(set! form (cons (car form) (cons module (cdr form))))))
(define (thunk)
(eval form))
(write-to-log form)
(call-with-result host-module thunk)))
;; Load a file
(define-toplevel-for-geiser geiser-load-file
(let* ((file (get-arg))
(file (if (symbol? file) (symbol->string file) file))
(found-file (geiser-find-file #f file)))
(call-with-result #f
(lambda ()
(when found-file
(load found-file))))))
;; The no-values identity
(define-toplevel-for-geiser geiser-no-values
(values))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Miscellaneous
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Invoke a newline
(define (geiser-newline . rest)
(newline))
;; Spawn a server for remote repl access
(define (geiser-start-server . rest)
(let* ((listener (tcp-listen 0))
(port (tcp-listener-port listener)))
(define (remote-repl)
(receive (in out) (tcp-accept listener)
(current-input-port in)
(current-output-port out)
(current-error-port out)
(repl)))
(thread-start! (make-thread remote-repl))
(write-to-log `(geiser-start-server . ,rest))
(write-to-log `(port ,port))
(write `(port ,port))
(newline)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Completions, Autodoc and Signature
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(define (geiser-completions toplevel-module prefix . rest)
;; We search both toplevel definitions and module definitions
(let* ((prefix (if (symbol? prefix) (symbol->string prefix) prefix))
(re (regexp (make-apropos-regex prefix))))
(sort! (map (lambda (sym)
;; Strip out everything before the prefix
(string-substitute (string-append ".*(" (regexp-escape prefix) ".*)") "\\1" (symbol->string sym)))
(append (apropos-list re #:macros? #t)
(geiser-module-completions toplevel-module prefix)))
string<?)))
(define (geiser-module-completions toplevel-module prefix . rest)
(let* ((match (string-append "^" (regexp-escape prefix))))
(filter (lambda (v) (string-search match (symbol->string v)))
(list-modules))))
(define (geiser-autodoc toplevel-module ids . rest)
(define (generate-details sym)
(find-signatures toplevel-module sym))
(if (list? ids)
(foldr append '()
(map generate-details ids))
'()))
(define (geiser-object-signature toplevel-module name object . rest)
(let* ((sig (geiser-autodoc toplevel-module `(,name))))
(if (null? sig) '() (car sig))))
;; TODO: Divine some way to support this functionality
(define (geiser-symbol-location toplevel-module symbol . rest)
'(("file") ("line")))
(define (geiser-symbol-documentation toplevel-module symbol . rest)
(let* ((sig (find-signatures toplevel-module symbol)))
`(("signature" ,@(car sig))
("docstring" . ,(make-doc symbol)))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; File and Buffer Operations
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(define geiser-load-paths (make-parameter '()))
(define (geiser-find-file toplevel-module file . rest)
(let ((paths (append '("" ".") (geiser-load-paths))))
(define (try-find file paths)
(cond
((null? paths) #f)
((file-exists? (string-append (car paths) file))
(string-append (car paths) file))
(else (try-find file (cdr paths)))))
(try-find file paths)))
(define (geiser-add-to-load-path toplevel-module directory . rest)
(let* ((directory (if (symbol? directory)
(symbol->string directory)
directory))
(directory (if (not (equal? #\/ (string-ref directory (- (string-length directory)))))
(string-append directory "/")
directory)))
(call-with-result #f
(lambda ()
(when (directory-exists? directory)
(geiser-load-paths (cons directory (geiser-load-paths))))))))
(define (geiser-compile-file toplevel-module file . rest)
(let* ((file (if (symbol? file) (symbol->string file) file))
(found-file (geiser-find-file toplevel-module file)))
(call-with-result #f
(lambda ()
(when found-file
(compile-file found-file))))))
;; TODO: Support compiling regions
(define (geiser-compile toplevel-module form module . rest)
(error "Chicken does not support compiling regions"))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Modules
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Should return:
;; '(("modules" . sub-modules) ("procs" . procedures) ("syntax" . macros) ("vars" . variables))
(define (geiser-module-exports toplevel-module module-name . rest)
(let* ((nodes (match-nodes module-name)))
(if (null? nodes)
'()
(let ((mod '())
(proc '())
(syn '())
(var '()))
(map
(lambda (node)
(let ((type (node-type node))
(name (node-id node))
(path (node-path node)))
(cond
((memq type '(unit egg))
(set! mod (cons name mod)))
((memq type '(procedure record setter class method))
(set! proc (cons name proc)))
((memq type '(read syntax))
(set! syn (cons name syn)))
((memq type '(parameter constant))
(set! var (cons name var))))))
nodes)
`(("modules" . ,mod)
("proces" . ,proc)
("syntax" . ,syn)
("vars" . ,var))))))
;; Returns the path for the file in which an egg or module was defined
(define (geiser-module-path toplevel-module module-name . rest)
#f)
;; Returns:
;; `(("file" . ,(module-path name)) ("line"))
(define (geiser-module-location toplevel-module name . rest)
#f)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Misc
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(define (geiser-macroexpand toplevel-module form . rest)
(with-output-to-string
(lambda ()
(pretty-print (expand form)))))
;; End module
)
(import geiser)
(make-geiser-toplevel-bindings)
| true |
41acfecf3f9a623cacbddafeb214558c658baad9
|
958488bc7f3c2044206e0358e56d7690b6ae696c
|
/scheme/evaluator/assignment.scm
|
68209055054afc1a8ec81d1b8c4f1e88f4aa4599
|
[] |
no_license
|
possientis/Prog
|
a08eec1c1b121c2fd6c70a8ae89e2fbef952adb4
|
d4b3debc37610a88e0dac3ac5914903604fd1d1f
|
refs/heads/master
| 2023-08-17T09:15:17.723600 | 2023-08-11T12:32:59 | 2023-08-11T12:32:59 | 40,361,602 | 3 | 0 | null | 2023-03-27T05:53:58 | 2015-08-07T13:24:19 |
Coq
|
UTF-8
|
Scheme
| false | false | 1,466 |
scm
|
assignment.scm
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; include guard ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(if (not (defined? included-assignment))
(begin
(define included-assignment #f)
(display "loading assignment")(newline)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; testing
(define (assignment? exp) (tagged-list? exp 'set!))
; destructuring
(define (assignment-variable exp) (cadr exp))
(define (assignment-expression exp) (caddr exp))
; strict eval
(define (strict-eval-assignment exp env)
(let ((var (assignment-variable exp))
(rhs (assignment-expression exp)))
(let ((val (strict-eval rhs env)))
((env 'set!) var val)
unspecified-value)))
; analyze
(define (analyze-assignment exp)
(let ((var (assignment-variable exp))
(rhs (assignment-expression exp)))
(let ((val (analyze rhs)))
(lambda (env) ((env 'set!) var (val env))
unspecified-value))))
; lazy eval
(define (lazy-eval-assignment exp env)
(let ((var (assignment-variable exp))
(rhs (assignment-expression exp)))
(let ((val (lazy-eval rhs env)))
((env 'set!) var val) ; val possibly a thunk
unspecified-value)))
; Note: the side effect resulting from a lazy assignment takes place immediately.
; In other words, the change in binding is not delayed. However, the assignment
; expression is only lazily evaluated. The variable is bound to a potential thunk.
)) ; include guard
| false |
f9b511378c248a7c74e72d9b51687af4aa41ea31
|
ae8b793a4edd1818c3c8b14a48ba0053ac5d160f
|
/gensym.scm
|
c263b9520577b24eea11f02b637e3210ac6318b4
|
[] |
no_license
|
experimentsin/telosis
|
e820d0752f1b20e2913f6f49c0e2a4023f5eda97
|
4b55140efa8fc732291d251f18f1056dc700442f
|
refs/heads/master
| 2020-04-19T08:32:05.037165 | 2013-07-13T18:59:36 | 2013-07-13T18:59:36 | 11,391,770 | 1 | 0 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 335 |
scm
|
gensym.scm
|
;; Portable gensym-ish code. Shouldn't cause problems in this lifetime
;; unless some other part of you application is using a hacked gensym
;; of its own...
(define gensym
(let ((count 9999))
(lambda args
(set! count (+ count 1))
(string->symbol
(string-append "G00" (number->string count 10))))))
;; eof
| false |
6c032c7b9e735609391df054c2652d6a834dadb2
|
0bb7631745a274104b084f6684671c3ee9a7b804
|
/tests/unit-tests/01-fixnum/fxeqv.scm
|
42144a1e0f4432ed2884f9921da1fb896d4a2f95
|
[
"Apache-2.0",
"LGPL-2.1-only",
"LicenseRef-scancode-free-unknown",
"GPL-3.0-or-later",
"LicenseRef-scancode-autoconf-simple-exception"
] |
permissive
|
feeley/gambit
|
f87fd33034403713ad8f6a16d3ef0290c57a77d5
|
7438e002c7a41a5b1de7f51e3254168b7d13e8ba
|
refs/heads/master
| 2023-03-17T06:19:15.652170 | 2022-09-05T14:31:53 | 2022-09-05T14:31:53 | 220,799,690 | 0 | 1 |
Apache-2.0
| 2019-11-10T15:09:28 | 2019-11-10T14:14:16 | null |
UTF-8
|
Scheme
| false | false | 468 |
scm
|
fxeqv.scm
|
(include "#.scm")
(check-eqv? (##fxeqv) -1)
(check-eqv? (##fxeqv 1) 1)
(check-eqv? (##fxeqv 85 204 240) 105)
(check-eqv? (##fxeqv ##min-fixnum ##max-fixnum) 0)
(check-eqv? (fxeqv) -1)
(check-eqv? (fxeqv 1) 1)
(check-eqv? (fxeqv 85 204 240) 105)
(check-eqv? (fxeqv ##min-fixnum ##max-fixnum) 0)
(check-tail-exn type-exception? (lambda () (fxeqv 0.0)))
(check-tail-exn type-exception? (lambda () (fxeqv 0.5)))
(check-tail-exn type-exception? (lambda () (fxeqv 1/2)))
| false |
102d707cfdde6c2b06d251a31edac915c7e1510a
|
000dbfe5d1df2f18e29a76ea7e2a9556cff5e866
|
/sitelib/sagittarius/misc.scm
|
2ca5a41b9af0a6081e76bd72bde981e58fbc8abc
|
[
"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 | 365 |
scm
|
misc.scm
|
;; -*- scheme -*-
(library (sagittarius misc)
(export output-port-width)
(import (core)
(core base)
(sagittarius))
(define *output-port-width* 79)
;; we don't provide specific port width from port.
(define (output-port-width port . width)
(if (null? width)
*output-port-width*
(set! *output-port-width* (car width))))
)
| false |
eb0fa6d67e1eb508acc02f605d834ae8fef90a0e
|
b43e36967e36167adcb4cc94f2f8adfb7281dbf1
|
/sicp/ch1/code/count-change.scm
|
bbca58864a86a6e9948a6beff453bd22b2e43938
|
[] |
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 | 398 |
scm
|
count-change.scm
|
(define (first-deno k)
(cond ((= k 1) 1)
((= k 2) 5)
((= k 3) 10)
((= k 4) 25)
((= k 5) 50)))
(define (cc amount k)
(cond ((= amount 0) 1)
((< amount 0) 0)
((= k 0) 0)
(else (+ (cc amount
(- k 1))
(cc (- amount (first-deno k)) k)))))
(define (count-change amount) (cc amount 5))
(count-change 10)
| false |
1df14a2baf072877249e82ec6e2dc786e2dc6633
|
bcfa2397f02d5afa93f4f53c0b0a98c204caafc1
|
/scheme/chapter1/ex1_31_test.scm
|
b4233992b2fa9f64c6aa78be8ca47296626d16c5
|
[] |
no_license
|
rahulkumar96/sicp-study
|
ec4aa6e1076b46c47dbc7a678ac88e757191c209
|
4dcd1e1eb607aa1e32277e1c232a321c5de9c0f0
|
refs/heads/master
| 2020-12-03T00:37:39.576611 | 2017-07-05T12:58:48 | 2017-07-05T12:58:48 | 96,050,670 | 0 | 0 | null | 2017-07-02T21:46:09 | 2017-07-02T21:46:09 | null |
UTF-8
|
Scheme
| false | false | 665 |
scm
|
ex1_31_test.scm
|
(test-case "Ex 1.31 Factorial via Product"
(assert-equal 1 (factorial 0))
(assert-equal 1 (factorial 1))
(assert-equal 2 (factorial 2))
(assert-equal 120 (factorial 5)))
(test-case "Ex 1.31 PI via product series"
(assert-in-delta 3.14 (pi-series 100) 0.1))
(test-case "Ex 1.31 Factorial via Recursive Product"
(assert-equal 1 (factorial-r 0))
(assert-equal 1 (factorial-r 1))
(assert-equal 2 (factorial-r 2))
(assert-equal 120 (factorial-r 5)))
(test-case "Ex 1.31 PI via recursive product series"
(assert-in-delta 3.14 (pi-series-r 100) 0.1))
| false |
329e5b93d1df09f46e04c29fd2865a149f3f1e6e
|
96694722260d44e4a1b5bcb4b8af8280a28ba113
|
/example/Piikafile
|
41365ac5b25d11922d2752197d3578e63b8a940e
|
[] |
no_license
|
mytoh/piika
|
e4ef9f88483beb862f008178b49a2aac7b102516
|
d690362215d18fc0ffbd0e583e014428e1ee68f3
|
refs/heads/master
| 2021-01-22T14:32:31.170362 | 2014-08-01T13:50:14 | 2014-08-01T13:50:14 | null | 0 | 0 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 255 |
Piikafile
|
;; -*- mode: scheme -*-
(import
(scheme base)
(scheme write)
(piika))
(define-task one ()
(display "one")
(newline))
(define-task two (one)
(display "two")
(newline))
(define-task three (two)
(display "three")
(newline))
(run-task)
| false |
|
c3e5b54daa9c88c55cb68c935a87b9dc7f756bd6
|
c7b8b37e2b6e05a12a387c1092c620b9d6de2ecb
|
/ex2.scm
|
4cbc84b08269dfc09d3f0fd985f0616cacc95c5d
|
[] |
no_license
|
willosborne/euler-scheme
|
a423054e74fe67ca8e91517ebcc08f78e93158d0
|
0616e107077b38a3be9daa3c65ed2bb3965d2b03
|
refs/heads/master
| 2020-03-25T14:44:17.296673 | 2018-08-09T14:35:25 | 2018-08-09T14:35:25 | 143,865,327 | 0 | 0 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 348 |
scm
|
ex2.scm
|
(load "utils.scm")
;; exercise 2: the sum of all even fibonacci numbers below n
(define (ex2 top)
(let loop ((a 0)
(b 1)
(acc 0))
(if (<= b top)
(loop b (+ a b) (if (divisible? b 2)
(begin
(+ acc b))
acc))
acc)))
| false |
3c9dccc44195a93244486c0743d9fbe805d4922a
|
9b2eb10c34176f47f7f490a4ce8412b7dd42cce7
|
/lib-compat/chicken-yuni/compat/ident.sls
|
93cc31c4b8252267c3954fd7f78f8b3deebaa05b
|
[
"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 | 142 |
sls
|
ident.sls
|
(library (chicken-yuni compat ident)
(export ident-impl)
(import (yuni scheme))
(define (ident-impl) 'chicken)
)
| false |
06ff4118411d6d3352de6b338b20f6b178c04670
|
defeada37d39bca09ef76f66f38683754c0a6aa0
|
/mscorlib/system/runtime/interop-services/registration-services.sls
|
497fd814c0fb81eee45407f9adb8af7ff6b72efb
|
[] |
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,673 |
sls
|
registration-services.sls
|
(library (system runtime interop-services registration-services)
(export new
is?
registration-services?
type-requires-registration?
get-prog-id-for-type
get-managed-category-guid
type-represents-com-type?
unregister-type-for-com-clients
register-type-for-com-clients
unregister-assembly?
register-assembly?
get-registrable-types-in-assembly)
(import (ironscheme-clr-port))
(define-syntax new
(lambda (e)
(syntax-case e ()
((_ a ...)
#'(clr-new
System.Runtime.InteropServices.RegistrationServices
a
...)))))
(define (is? a)
(clr-is System.Runtime.InteropServices.RegistrationServices a))
(define (registration-services? a)
(clr-is System.Runtime.InteropServices.RegistrationServices a))
(define-method-port
type-requires-registration?
System.Runtime.InteropServices.RegistrationServices
TypeRequiresRegistration
(System.Boolean System.Type))
(define-method-port
get-prog-id-for-type
System.Runtime.InteropServices.RegistrationServices
GetProgIdForType
(System.String System.Type))
(define-method-port
get-managed-category-guid
System.Runtime.InteropServices.RegistrationServices
GetManagedCategoryGuid
(System.Guid))
(define-method-port
type-represents-com-type?
System.Runtime.InteropServices.RegistrationServices
TypeRepresentsComType
(System.Boolean System.Type))
(define-method-port
unregister-type-for-com-clients
System.Runtime.InteropServices.RegistrationServices
UnregisterTypeForComClients
(System.Void System.Int32))
(define-method-port
register-type-for-com-clients
System.Runtime.InteropServices.RegistrationServices
RegisterTypeForComClients
(System.Int32
System.Type
System.Runtime.InteropServices.RegistrationClassContext
System.Runtime.InteropServices.RegistrationConnectionType)
(System.Void System.Type System.Guid&))
(define-method-port
unregister-assembly?
System.Runtime.InteropServices.RegistrationServices
UnregisterAssembly
(System.Boolean System.Reflection.Assembly))
(define-method-port
register-assembly?
System.Runtime.InteropServices.RegistrationServices
RegisterAssembly
(System.Boolean
System.Reflection.Assembly
System.Runtime.InteropServices.AssemblyRegistrationFlags))
(define-method-port
get-registrable-types-in-assembly
System.Runtime.InteropServices.RegistrationServices
GetRegistrableTypesInAssembly
(System.Type[] System.Reflection.Assembly)))
| true |
d853ba790f3cfb5c5a8e76091f838164ddd2967d
|
eef5f68873f7d5658c7c500846ce7752a6f45f69
|
/spheres/core/functional.sld
|
604db45de95026afb4f927a023811ac2d6af8dc4
|
[
"MIT"
] |
permissive
|
alvatar/spheres
|
c0601a157ddce270c06b7b58473b20b7417a08d9
|
568836f234a469ef70c69f4a2d9b56d41c3fc5bd
|
refs/heads/master
| 2021-06-01T15:59:32.277602 | 2021-03-18T21:21:43 | 2021-03-18T21:21:43 | 25,094,121 | 13 | 3 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 7,853 |
sld
|
functional.sld
|
;;!!! Functional programming procedures
;; .author Alvaro Castro-Castilla, 2012-2014. All rights reserved.
(define-library (spheres/core functional)
(export cut
cute
define-associative
curried
define-curried
define-memoized
;; functional combinators
U
Y
Y!
compose
recursive-compose
tail-recursive-compose
left-section
right-section
curry
uncurry
complement
reversed
andf
orf
arguments-chainf
arguments-eachf
arguments-allf
;; memoization
memoize/key-gen
memoize)
;;------------------------------------------------------------------------------
;;! SRFI-26 Notation for Specializing Parameters without Currying
;; [email protected], 5-Jun-2002.
;; adapted from the posting by Al Petrofsky <[email protected]>
;; placed in the public domain.
;; Modified by Álvaro Castro-Castilla 2012
;; Made internal syntaxes private with letrec
;; (srfi-26-internal-cut slot-names combination . se)
;; transformer used internally
;; slot-names : the internal names of the slots
;; combination : procedure being specialized, followed by its arguments
;; se : slots-or-exprs, the qualifiers of the macro
(define-syntax srfi-26-internal-cut
(syntax-rules (<> <...>)
;; construct fixed- or variable-arity procedure:
;; (begin proc) throws an error if proc is not an <expression>
((srfi-26-internal-cut (slot-name ...) (proc arg ...))
(lambda (slot-name ...) ((begin proc) arg ...)))
((srfi-26-internal-cut (slot-name ...) (proc arg ...) <...>)
(lambda (slot-name ... . rest-slot) (apply proc arg ... rest-slot)))
;; process one slot-or-expr
((srfi-26-internal-cut (slot-name ...) (position ...) <> . se)
(srfi-26-internal-cut (slot-name ... x) (position ... x) . se))
((srfi-26-internal-cut (slot-name ...) (position ...) nse . se)
(srfi-26-internal-cut (slot-name ...) (position ... nse) . se))))
;;! cut
(define-syntax cut
(syntax-rules ()
((cut . slots-or-exprs)
(srfi-26-internal-cut () () . slots-or-exprs))))
;; (srfi-26-internal-cute slot-names nse-bindings combination . se)
;; transformer used internally
;; slot-names : the internal names of the slots
;; nse-bindings : let-style bindings for the non-slot expressions.
;; combination : procedure being specialized, followed by its arguments
;; se : slots-or-exprs, the qualifiers of the macro
(define-syntax srfi-26-internal-cute
(syntax-rules (<> <...>)
;; If there are no slot-or-exprs to process, then:
;; construct a fixed-arity procedure,
((srfi-26-internal-cute
(slot-name ...) nse-bindings (proc arg ...))
(let nse-bindings (lambda (slot-name ...) (proc arg ...))))
;; or a variable-arity procedure
((srfi-26-internal-cute
(slot-name ...) nse-bindings (proc arg ...) <...>)
(let nse-bindings (lambda (slot-name ... . x) (apply proc arg ... x))))
;; otherwise, process one slot:
((srfi-26-internal-cute
(slot-name ...) nse-bindings (position ...) <> . se)
(srfi-26-internal-cute
(slot-name ... x) nse-bindings (position ... x) . se))
;; or one non-slot expression
((srfi-26-internal-cute
slot-names nse-bindings (position ...) nse . se)
(srfi-26-internal-cute
slot-names ((x nse) . nse-bindings) (position ... x) . se))))
;;! cute
(define-syntax cute
(syntax-rules ()
((cute . slots-or-exprs)
(srfi-26-internal-cute () () () . slots-or-exprs))))
;;------------------------------------------------------------------------------
;;!! Function generation
;;! Defines a function and its associated associative function (that will take
;; any number of arguments and apply it to the result of the two previous ones)
(define-syntax define-associative
(let-syntax ((define-associative-aux
(syntax-rules ()
((_ name f)
(define-syntax name
(syntax-rules ()
((_ arg1 arg2)
(f arg1 arg2))
((_ arg1 arg2 . rest)
(name (f arg1 arg2) . rest))))))))
(syntax-rules ()
((_ name (f arg1 arg2) body)
(begin
(define (f arg1 arg2) body)
(define-associative-aux name f))))))
;;! Define an automatically curryable function
;;
;; (define-curried (foo x y z) (+ x (/ y z))) ;; foo has arity 3
;; ((foo 3) 1 2) ;; (foo 3) is a procedure with arity 2
;; ((foo 3 1) 2) ;; (foo 3 2) is a procedure with arity 1
(define-syntax curried
(syntax-rules ()
((_ () body ...)
(lambda () body ...))
((_ (arg) body ...)
(lambda (arg) body ...))
((_ (arg args ...) body ...)
(lambda (arg . rest)
(let ((next (curried (args ...) body ...)))
(if (null? rest)
next
(apply next rest)))))))
(define-syntax define-curried
(syntax-rules ()
((_ (name args ...) body ...)
(define name (curried (args ...) body ...)))))
;; Curried lambda
;; (lambda-curried (x y z) (+ x y z)) =>
;; (lambda (x) (lambda (y) (lambda (z) (+ x y z))))
;; (map map (map (lambda-curried (a b) (* a b)) '(1 2 3)) '((4 5 6) (7 8 9) (10 11 12)))
;; (##define-macro (lambda-curried bindings . body)
;; (define (fold-right kons knil lis1)
;; (let recur ((lis lis1))
;; (if (null? lis) knil
;; (let ((head (car lis)))
;; (kons head (recur (cdr lis)))))))
;; (if (null? bindings) `(lambda () ,@body)
;; (fold-right (lambda (arg curr-body) `(lambda (,arg) ,curr-body))
;; (cons 'begin body) bindings)))
;;! Macro for memoized function definition (with default key generator)
(define-syntax define-memoized
(syntax-rules (lambda)
((_ (name args ...) body ...)
(define name
(letrec ((name (lambda (args ...) body ...)))
(memoize name))))
((_ name (lambda (args ...) body ...))
(define-memoized (name args ...) body ...))))
;;! Macro for memoized function definition (specifying a key generator)
;; (define-syntax define-memoized/key-gen
;; (syntax-rules ()
;; ((_ name
;; (lambda (args-for-key ...) body-for-key ...)
;; (lambda (args ...) body ...))
;; (define name
;; (letrec ((name (lambda (args ...) body ...)))
;; (memoize/key-gen
;; (lambda (args-for-key ...) body-for-key ...)
;; name))))))
;;TODO!!!
;; r2rs-style currying define.
;; (define-syntax define
;; (let-syntax ((old-define define))
;; (letrec-syntax
;; ((new-define
;; (syntax-rules ()
;; ((_ (var-or-prototype . args) . body)
;; (new-define var-or-prototype (lambda args . body)))
;; ((_ var expr) (old-define var expr)))))
;; new-define)))
;; (define-syntax define
;; (let-syntax ((old-define define))
;; (define-syntax new-define
;; (syntax-rules ()
;; ((_ (var-or-prototype . args) . body)
;; (new-define var-or-prototype (lambda args . body)))
;; ((_ var expr) (old-define var expr))))
;; new-define))
;; (let ((multiplier 2))
;; (define ((curried-* x) y) (* x y))
;; (map (curried-* multiplier) '(3 4 5)))
(include "functional.scm"))
| true |
e4215e1c3b417b86bf3c73edd4c25876029302ee
|
5bf673b5bd8de5c1a943b739b9c2e0426da85d7c
|
/awful.release-info
|
d13eb56acd0bc994bffcae05533e9cb4de881dfe
|
[
"BSD-2-Clause"
] |
permissive
|
mario-goulart/awful
|
dfe44157865d5b9b94004efc30ddb1dc4bf0e441
|
739f7b4c6b808db3d4c05bf43aa095dd6543252e
|
refs/heads/master
| 2023-04-14T08:34:19.377592 | 2023-04-10T09:17:29 | 2023-04-10T09:17:29 | 4,197,893 | 68 | 5 |
NOASSERTION
| 2023-02-12T09:18:16 | 2012-05-02T00:02:50 |
Scheme
|
UTF-8
|
Scheme
| false | false | 1,002 |
awful.release-info
|
;; -*- scheme -*-
(repo git "git://github.com/mario-goulart/{egg-name}.git")
(uri targz "https://github.com/mario-goulart/{egg-name}/tarball/{egg-release}")
(uri files-list "http://code.call-cc.org/files-list?egg={egg-name};egg-release={egg-release}" old-uri)
(release "0.17" old-uri)
(release "0.18" old-uri)
(release "0.19" old-uri)
(release "0.20" old-uri)
(release "0.21" old-uri)
(release "0.22" old-uri)
(release "0.23" old-uri)
(release "0.24" old-uri)
(release "0.25" old-uri)
(release "0.26" old-uri)
(release "0.27" old-uri)
(release "0.28" old-uri)
(release "0.29" old-uri)
(release "0.30" old-uri)
(release "0.31" old-uri)
(release "0.32" old-uri)
(release "0.33" old-uri)
(release "0.34" old-uri)
(release "0.35")
(release "0.36")
(release "0.37")
(release "0.38")
(release "0.38.1")
(release "0.38.2")
(release "0.39")
(release "0.39.1")
(release "0.39.2")
(release "0.40.0")
(release "0.41.0")
(release "0.42.0")
(release "1.0.0")
(release "1.0.1")
(release "1.0.2")
(release "1.0.3")
| false |
|
e66977e2538db5afe069db8b5caf6bdfb6c9f8f1
|
ffb05b145989e01da075e2a607fb291955251f46
|
/scheme/repeat.sls
|
b3c74855d1b5d1e44d6e46d68338da128c401e4b
|
[] |
no_license
|
micheles/papers
|
a5e7f2fa0cf305cd3f8face7c7ecc0db70ce7cc7
|
be9070f8b7e8192b84a102444b1238266bdc55a0
|
refs/heads/master
| 2023-06-07T16:46:46.306040 | 2018-07-14T04:17:51 | 2018-07-14T04:17:51 | 32,264,461 | 2 | 0 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 163 |
sls
|
repeat.sls
|
(library (repeat)
(export call)
(import (rnrs))
(define (call n proc . args)
(let loop ((i 0))
(when (< i n) (apply proc args) (loop (+ 1 i))))))
| false |
703d466dd2629822da3b8e1cc674592e839769ad
|
ace3ddb2cf0b44407d2fac3b6797f83f245ded26
|
/tmp.scm
|
cc69b4646aca572a8c5c331d0daddfeffc7ec56b
|
[] |
no_license
|
rbryan/ship-game
|
658757d022a29f9807fd3ff3e793e2fc199920ff
|
a998ebbf9a70702e4f393b580193bc98dea09482
|
refs/heads/master
| 2021-01-10T04:59:57.289045 | 2016-02-29T05:15:43 | 2016-02-29T05:15:43 | 52,751,725 | 0 | 0 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 2,519 |
scm
|
tmp.scm
|
(import
(misc)
(class javax.media.opengl
GLAutoDrawable
GL
GL2
GLProfile
GLCapabilities
GLEventListener)
(class javax.media.opengl.glu
GLU)
(class com.jogamp.opengl.util
FPSAnimator)
(class javax.media.opengl.awt
GLCanvas))
(define (rotMat ix1 ix2 rad)
(let ((s (sin rad))
(c (cos rad))
(v (make-vector 9 0)))
(vector-set! v (* 4 ix1) c)
(vector-set! v (* 4 ix2) c)
(vector-set! v (+ (* 3 ix1) ix2) s)
(vector-set! v (+ (* 3 ix2) ix1) (- s))
(vector-set! v (* 4 (- 3 ix1 ix2)) 1)
v))
(define (drawShip gl ::GL2 pos orientation)
(begin
(define vr vector-ref)
(define (mult vec mat . others)
(let ((passMe
(vector
(+ (* (vr vec 0) (vr mat 0))
(* (vr vec 1) (vr mat 1))
(* (vr vec 2) (vr mat 2)))
(+ (* (vr vec 0) (vr mat 3))
(* (vr vec 1) (vr mat 4))
(* (vr vec 2) (vr mat 5)))
(+ (* (vr vec 0) (vr mat 6))
(* (vr vec 1) (vr mat 7))
(* (vr vec 2) (vr mat 8))))))
(if (null? others) passMe
(mult passMe @others))))
(define (transform p)
(map + pos (mult p
(rotMat 0 1 (vr orientation 2))
(rotMat 2 1 (vr orientation 1))
(rotMat 0 2 (vr orientation 0)))))
(gl:glBegin GL:GL_TRIANGLES)
(gl:glColor3f 1.0 0 0)
(map (lambda (a) (gl:glVertex3f @(transform a)))
'(
;coordinates for the model
#(0.5 0 0)
#(-0.5 0 0)
#(0 0 1)
#(0 0 0)
#(0 0.5 0)
#(0 0 1)
))
(gl:glEnd)
))
(define glp (GLProfile:getDefault))
(define glcap (GLCapabilities glp))
(define glcan ::GLCanvas (GLCanvas glcap))
(define frame ::java.awt.Frame (java.awt.Frame "Banana"))
(define glu ::GLU (GLU))
(define ship '((4 0 0) #(0.5 0 0)))
(frame:setSize 500 500)
(frame:add glcan)
(frame:setVisible #t)
(define-class myclass (GLEventListener)
((init d ::GLAutoDrawable) ::void ())
((dispose d ::GLAutoDrawable) ::void ())
((reshape d ::GLAutoDrawable a ::int b ::int c ::int d ::int) ::void ())
((display d ::GLAutoDrawable) ::void
(define gl ::GL2 ((d:getGL):getGL2))
(gl:glMatrixMode gl:GL_PROJECTION)
(gl:glLoadIdentity)
(glu:gluPerspective 45 1 1 3)
(gl:glMatrixMode gl:GL_MODELVIEW)
(gl:glClear (bitwise-ior GL:GL_COLOR_BUFFER_BIT GL:GL_DEPTH_BUFFER_BIT))
;(drawShip gl (car ship) (cadr ship))
(gl:glBegin GL:GL_TRIANGLES)
(gl:glColor3f 1 0 0)
(gl:glVertex3f 0 0.5 2)
(gl:glVertex3f 0 -0.5 2)
(gl:glVertex3f 0.5 0 2)
(gl:glEnd)
))
(glcan:addGLEventListener (myclass))
((FPSAnimator glcan 30):start)
| false |
6ce2e8b8ba1a22517baef758edeb9e21d53b953f
|
1da0749eadcf5a39e1890195f96903d1ceb7f0ec
|
/a-d6/a-d/dynamic.ss
|
0a8dc239366c11e74dec70bfa7c2ecefc9630804
|
[] |
no_license
|
sebobrien/ALGO1
|
8ce02fb88b6db9e001d936356205a629b49b884d
|
50df6423fe45b99db9794ef13920cf03d532d69f
|
refs/heads/master
| 2020-04-08T20:08:16.986517 | 2018-12-03T06:48:07 | 2018-12-03T06:48:07 | 159,685,194 | 0 | 0 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 3,017 |
ss
|
dynamic.ss
|
#lang r6rs
(import (rnrs base) (rnrs io simple)
(a-d graph unweighted config)
(a-d graph examples directed-unweighted)
(a-d scheme-tools)
; (a-d graph-algorithms directed traclo-unweighted)
(a-d graph-algorithms directed basic))
(define s1 sedgewick172)
(define s2 (copy s1))
(define s3 (copy s1))
(define (print g)
(for-each-node
g
(lambda (from)
(for-each-edge
g
from
(lambda (to)
(display (list from "->" to))
(newline))))))
(define (dup c n) (if (= n 0) "" (string-append c (dup c (- n 1)))))
(define (traclo-recursive g)
(define n (- (order g) 1))
(define (rec from to via)
(display (list (dup " " (- n via)) from to "/" via))(newline)
(if (= -1 via)
(adjacent? g from to)
(or (rec from to (- via 1))
(and (rec from via (- via 1))
(rec via to (- via 1))))))
(define res (make-2D-vector (order g) (order g) #f))
(for-each-node
g
(lambda (from)
(for-each-node
g
(lambda (to)
(ij! res from to (rec from to n))))))
res)
(define (traclo-memoize g)
(define n (- (order g) 1))
(define (rec from to via)
(if (not (null? (ij? res from to)))
(ij? res from to)
(begin
(display (list (dup "_" (- n via)) from to "/" via))(newline)
(let ((tst (if (= -1 via)
(adjacent? g from to)
(or (rec from to (- via 1))
(and (rec from via (- via 1))
(rec via to (- via 1)))))))
(ij! res from to tst)
tst))))
(define res (make-2D-vector (order g) (order g) ()))
(for-each-node
g
(lambda (from)
(for-each-node
g
(lambda (to)
(ij! res from to (rec from to n))))))
res)
(define (traclo-warshall g)
(define res (make-2D-vector (order g) (order g) #f))
(for-each-node
g
(lambda (from)
(for-each-node
g
(lambda (to)
(if (adjacent? g from to)
(ij! res from to #t))))))
(for-each-node
g
(lambda (via)
(for-each-node
g
(lambda (from)
(for-each-node
g
(lambda (to)
(if (or (ij? res from to)
(and (ij? res from via)
(ij? res via to)))
(ij! res from to #t))))))))
res)
(define m1 (traclo-warshall s1))
(display "----------------------")(newline)
(define m2 (traclo-recursive s2))
(display "----------------------")(newline)
(define m3 (traclo-memoize s3))
(define (compare g1 g2)
(call-with-current-continuation
(lambda (exit)
(for-each-node
g1
(lambda (from)
(for-each-node
g1
(lambda (to)
(define a1 (adjacent? g1 from to))
(define a2 (adjacent? g2 from to))
(display (list from to))
(if (or (and a1 (not a2)) (and a2 (not a1)))
(exit #f))))))
#t)))
| false |
f9b26a110415a9c4e06ad06fb65dec956c20cc56
|
dd4cc30a2e4368c0d350ced7218295819e102fba
|
/vendored_parsers/vendor/highlights/yaml.scm
|
529bf49e6ab16f6bb4f73bf3a1f305ccbbc7513e
|
[
"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 | 1,012 |
scm
|
yaml.scm
|
;; Taken from nvim-treesitter, under Apache license.
;; Upstream URL:https://github.com/nvim-treesitter/nvim-treesitter/blob/master/queries/yaml/highlights.scm
(boolean_scalar) @boolean
(null_scalar) @constant.builtin
(double_quote_scalar) @string
(single_quote_scalar) @string
(block_scalar) @string
(string_scalar) @string
(escape_sequence) @string.escape
(integer_scalar) @number
(float_scalar) @number
(comment) @comment
(anchor_name) @type
(alias_name) @type
(tag) @type
(yaml_directive) @keyword
(ERROR) @error
(block_mapping_pair
key: (flow_node [(double_quote_scalar) (single_quote_scalar)] @field))
(block_mapping_pair
key: (flow_node (plain_scalar (string_scalar) @field)))
(flow_mapping
(_ key: (flow_node [(double_quote_scalar) (single_quote_scalar)] @field)))
(flow_mapping
(_ key: (flow_node (plain_scalar (string_scalar) @field))))
[
","
"-"
":"
">"
"?"
"|"
] @punctuation.delimiter
[
"["
"]"
"{"
"}"
] @punctuation.bracket
[
"*"
"&"
"---"
"..."
] @punctuation.special
| false |
683e8088d7835fc5c6e6f5389ff63bcfebf2e922
|
b1b1e288efe8621f2bf2c8bc3eea9e30fc251501
|
/functional_tests/test_enyalios.ss
|
406cd6fdbfa36a53ed5cbc28108e0580e11a80f6
|
[
"ISC"
] |
permissive
|
lojikil/hydra
|
37e32a43afc2443e29a73387fe796b559756a957
|
366cae2e155c6e4d5e27ad19d3183687a40c82a3
|
refs/heads/master
| 2020-05-30T08:41:19.374996 | 2014-11-13T03:10:22 | 2014-11-13T03:10:22 | 58,539,402 | 5 | 0 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 389 |
ss
|
test_enyalios.ss
|
#!/usr/bin/env vesta
(load "../enyalios.ss")
(define f (open "test.c" :write))
(il->c '((c-if (c-eq 3 4) (c-return 43)) (c-else (c-return 50))) 0 f)
(il->c '((c-if (c-eq 3 4) (c-return 43)) (c-elif (c-eq x 17) (c-return 47)) (c-else (c-return 50))) 0 f)
(il->c '(c-dec foo (x y z) ((c-if (c-eq 3 4) (c-return 43)) (c-elif (c-eq x 17) (c-return 47)) (c-else (c-return 50)))) 0 f)
(close f)
| false |
a5210b1849fe1f0c8797387948de18f3e04de716
|
58381f6c0b3def1720ca7a14a7c6f0f350f89537
|
/Chapter 1/1.3/Ex1.38.scm
|
0144a36528f2fbf5639a2fe7db64bfa4dd6ba090
|
[] |
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 | 761 |
scm
|
Ex1.38.scm
|
#lang planet neil/sicp
(define (cont-frac n d k)
(define (iter n d i)
(if (= k i)
(/ (n i) (d i))
(/ (n i) (+ (d i) (iter n d (+ i 1))))))
(iter n d 1))
(define (d i)
(if (zero? (remainder (+ 1 i) 3))
(* 2 (/ (+ i 1) 3))
1))
(define (e depth)
(+ 2 (cont-frac
(lambda (i) 1.0)
d
depth)))
(e 12)
;; The series is 1 2 1 1 4 1 1 6 1 1 8 1 1
;; The indices are 1 2 3 4 5 6 7 8 9 10 11 12 13
;; Offsetting the original series by adding one produces the new series below
;; Original series is 1 2 1 1 4 1 1 6 ...
;; Offset series 2 3 4 5 6 7 8 9 ...
;; The multiples of 3 are the non 1 values and can be gotten
;; by dividing the 'shifted' value by 3 and multiplying by 2
| false |
15a5630ab399319e89fc2bf3712d151ccb0c0ec7
|
db6f1095242eb0040bb5049d469cd3c92ad68b2c
|
/scheme/evil/utils.ss
|
39f790a38f9dae2534007fee3cdd20b260de3d0b
|
[] |
no_license
|
defin/jrm-code-project
|
1767523c7964a998c6035f67ed227c22518e0aeb
|
0716e271f449b52bfabe4c2fefe8fc5e62902f42
|
refs/heads/master
| 2021-01-16T19:00:05.028804 | 2014-08-23T23:20:49 | 2014-08-23T23:20:49 | 33,170,588 | 1 | 0 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 5,284 |
ss
|
utils.ss
|
#ci(module utils (lib "swindle.ss" "swindle")
;;; Evil utilities
(require (lib "list.ss"))
(define (any? procedure list)
(and (pair? list)
(or (procedure (car list))
(any? procedure (cdr list)))))
(define (not-any? procedure list)
(cond ((pair? list) (and (not (procedure (car list)))
(not-any? procedure (cdr list))))
((null? list) #t)
(else (error "Improper list."))))
(define (every? procedure list)
(cond ((pair? list) (and (procedure (car list))
(every? procedure (cdr list))))
((null? list) #t)
(else (error "Improper list."))))
(define (find thing list key)
(let ((probe (memf (lambda (item)
(eq? (key item) thing)) list)))
(if (pair? probe)
(car probe)
probe)))
(define-syntax multiple-value-bind
(syntax-rules ()
((multiple-value-bind bindings values-producer . body)
(CALL-WITH-VALUES
(LAMBDA () values-producer)
(LAMBDA bindings . body)))))
(define-syntax multiple-value-list
(syntax-rules ()
((multiple-value-list values-producer)
(CALL-WITH-VALUES (LAMBDA () values-producer) LIST))))
(define-syntax multiple-value-setq
(syntax-rules ()
;; no rule for 0 (pointless)
;; no rule for 1 (use setq)
((multiple-value-setq (var0 var1) values-producer)
(CALL-WITH-VALUES (LAMBDA () values-producer)
(LAMBDA (TEMP0 TEMP1)
(SET! var0 TEMP0)
(SET! var1 TEMP1))))
((multiple-value-setq (var0 var1 var2) values-producer)
(CALL-WITH-VALUES (LAMBDA () values-producer)
(LAMBDA (TEMP0 TEMP1 TEMP2)
(SET! var0 TEMP0)
(SET! var1 TEMP1)
(SET! var2 TEMP2))))
((multiple-value-setq (var0 var1 var2 var3) values-producer)
(CALL-WITH-VALUES (LAMBDA () values-producer)
(LAMBDA (TEMP0 TEMP1 TEMP2 TEMP3)
(SET! var0 TEMP0)
(SET! var1 TEMP1)
(SET! var2 TEMP2)
(SET! var3 TEMP3))))
((multiple-value-setq (var0 var1 var2 var3 var4) values-producer)
(CALL-WITH-VALUES (LAMBDA () values-producer)
(LAMBDA (TEMP0 TEMP1 TEMP2 TEMP3 TEMP4)
(SET! var0 TEMP0)
(SET! var1 TEMP1)
(SET! var2 TEMP2)
(SET! var3 TEMP3)
(SET! var4 TEMP4))))))
(define-syntax nth-value
(syntax-rules ()
((nth-value 0 values-producer)
(CALL-WITH-VALUES (LAMBDA () values-producer)
(LAMBDA (VALUE0 . OTHERS) VALUE0)))
((nth-value 1 values-producer)
(CALL-WITH-VALUES (LAMBDA () values-producer)
(LAMBDA (VALUE0 VALUE1 . OTHERS) VALUE1)))
((nth-value 2 values-producer)
(CALL-WITH-VALUES (LAMBDA () values-producer)
(LAMBDA (VALUE0 VALUE1 VALUE2 . OTHERS) VALUE2)))
((nth-value 3 values-producer)
(CALL-WITH-VALUES (LAMBDA () values-producer)
(LAMBDA (VALUE0 VALUE1 VALUE2 VALUE3 . OTHERS) VALUE3)))
((nth-value n values-producer)
(LIST-REF (MULTIPLE-VALUE-LIST values-producer) N))))
(define *evil-verbose* #t)
(define (evil-message text . objects)
(if *evil-verbose*
(begin
(newline)
(display "evil: ")
(display text)
(for-each (lambda (object)
(display " ")
(display object))
objects)
(flush-output))))
(define *evil-error-depth* (make-parameter 0))
(define (evil-error where . stuff)
(if (> (*evil-error-depth*) 5)
(begin (display "error too deep") #f)
(parameterize ((*evil-error-depth* (add1 (*evil-error-depth*))))
(apply evil-message (string-append (symbol->string where) ": ") stuff)
(newline)
(error "Evil error" (cons where stuff)))))
(define (warn text . stuff)
(apply evil-message "WARNING: " text stuff))
(define (convert-c-name string)
(string->symbol
(list->string
(let loop ((chars (string->list string))
(prev '())
(result '()))
(if (null? chars)
(reverse! result)
(loop (cdr chars)
(car chars)
(let ((c (car chars)))
(cond ((and (char-upper-case? c)
(char? prev)
(char-lower-case? prev))
(list* (char-downcase c) #\- result))
((char=? c #\_) (cons #\- result))
(else (cons (char-downcase c) result))))))))))
(define-syntax declare
(syntax-rules (usual-integrations)
((declare (usual-integrations)) '())))
(define (class-predicate class)
(lambda (instance)
(instance-of? instance class)))
(provide
*evil-verbose*
any?
class-predicate
convert-c-name
every?
evil-error
evil-message
find
multiple-value-bind
multiple-value-list
multiple-value-setq
nth-value
warn
declare
))
| true |
a0adcd70058b65277d89d9f8f2287a60165c807f
|
35f859a6933537955f878e97455cd45b312aa042
|
/example/example5.scm
|
1172d05d436b80c0821999364d544a5068afa137
|
[] |
no_license
|
podhmo/gauche-gl-processing
|
ebbbe2631830cb7d0e62b5e5aa0275bb176c7084
|
d57b9c055d2dfe199df5652e1afb0cfd1713257f
|
refs/heads/master
| 2021-01-23T08:38:44.547876 | 2010-10-13T08:40:19 | 2010-10-13T08:40:19 | null | 0 | 0 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 648 |
scm
|
example5.scm
|
;; draw pixels
(add-load-path "../")
(use gl.processing)
(use gl.simple-image)
(use util.match)
(define *image-file* "flower.rgb")
(define (load)
(unless (file-exists? *image-file*)
(print "Couldn't find image file: " *image-file*)
(exit 0))
(match-let1 (width height depth image)
(read-sgi-image *image-file*)
(values width height image)))
(define main
(receive (w h image) (load)
(print (class-of image))
(setup$
(lambda ()
(gl-pixel-store GL_UNPACK_ALIGNMENT 1)
(window w h "example5" 100 100))
:draw (draw-once$
(cut gl-draw-pixels w h GL_RGB GL_UNSIGNED_BYTE image)))))
| false |
4b335efbec08f1b51a1d52095c4cac31a0e21de3
|
b289ed2b933545e2756da8df8e0b3a60b81670f4
|
/stuff/stuff.scm
|
35897908b3d0068f7f92f8d074850c721e63fae4
|
[] |
no_license
|
abarbu/icfp2013
|
0065d4edcb4123da3fdd552baf151e1ff3815767
|
98872788e9ff7b7f8fe1e0cd3fb58abd93fecbd6
|
refs/heads/master
| 2020-05-30T12:25:04.449936 | 2013-08-12T00:05:57 | 2013-08-12T00:05:57 | null | 0 | 0 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 6,022 |
scm
|
stuff.scm
|
(module stuff *
(import chicken scheme srfi-1 extras data-structures ports files foreign)
;; program P ::= "(" "lambda" "(" id ")" e ")"
;; expression e ::= "0" | "1" | id
;; | "(" "if0" e e e ")"
;; | "(" "fold" e e "(" "lambda" "(" id id ")" e ")" ")"
;; | "(" op1 e ")"
;; | "(" op2 e e ")"
;; op1 ::= "not" | "shl1" | "shr1" | "shr4" | "shr16"
;; op2 ::= "and" | "or" | "xor" | "plus"
;; id ::= [a-z]+
;; A valid program P contains at most one occurrence of "fold".
;; The expression "(fold e0 e1 (lambda (x y) e2))" uses the lambda-term
;; to fold over each byte of e0 bound to x (starting from the least
;; significant), and with the accumulator y initially bound to e1.
;; For example, given P = (lambda (x) (fold x 0 (lambda (y z) (or y z)))),
;; P(0x1122334455667788)
;; reduces to
;; (or 0x0000000000000011
;; (or 0x0000000000000022
;; (or 0x0000000000000033
;; (or 0x0000000000000044
;; (or 0x0000000000000055
;; (or 0x0000000000000066
;; (or 0x0000000000000077
;; (or 0x0000000000000088
;; 0x0000000000000000))))))))
(define (deep-map p f tree)
(cond ((p tree) (f tree))
((list? tree) (map (lambda (subtree) (deep-map p f subtree)) tree))
(else tree)))
#>
#include <endian.h>
<#
(define wh#0 '#${0000000000000000})
(define wh#1 '#${0000000000000001})
(define wh#plus (foreign-primitive scheme-object
((blob a)
(blob b))
"C_word *r = C_alloc(16);"
"uint64_t u = htobe64(be64toh(*((uint64_t*)a)) + be64toh(*((uint64_t*)b)));"
"C_return(C_bytevector(&r, 8, (char*)&u));"))
(define wh#and (foreign-primitive scheme-object
((blob a)
(blob b))
"C_word *r = C_alloc(16);"
"uint64_t u = *((uint64_t*)a) & *((uint64_t*)b);"
"C_return(C_bytevector(&r, 8, (char*)&u));"))
(define wh#or (foreign-primitive scheme-object
((blob a)
(blob b))
"C_word *r = C_alloc(16);"
"uint64_t u = *((uint64_t*)a) | *((uint64_t*)b);"
"C_return(C_bytevector(&r, 8, (char*)&u));"))
(define wh#xor (foreign-primitive scheme-object
((blob a)
(blob b))
"C_word *r = C_alloc(16);"
"uint64_t u = *((uint64_t*)a) ^ *((uint64_t*)b);"
"C_return(C_bytevector(&r, 8, (char*)&u));"))
(define wh#not (foreign-primitive scheme-object
((blob a))
"C_word *r = C_alloc(16);"
"uint64_t u = ~*((uint64_t*)a);"
"C_return(C_bytevector(&r, 8, (char*)&u));"))
(define wh#shlN (foreign-primitive scheme-object
((blob a) (integer n))
"C_word *r = C_alloc(16);"
"uint64_t u = htobe64(be64toh(*((uint64_t*)a)) << n);"
"C_return(C_bytevector(&r, 8, (char*)&u));"))
(define wh#shl1 (foreign-primitive scheme-object
((blob a))
"C_word *r = C_alloc(16);"
"uint64_t u = htobe64(be64toh(*((uint64_t*)a)) << 1);"
"C_return(C_bytevector(&r, 8, (char*)&u));"))
(define wh#shl8 (foreign-primitive scheme-object
((blob a))
"C_word *r = C_alloc(16);"
"uint64_t u = htobe64(be64toh(*((uint64_t*)a)) << 8);"
"C_return(C_bytevector(&r, 8, (char*)&u));"))
(define wh#shrN (foreign-primitive scheme-object
((blob a) (integer n))
"C_word *r = C_alloc(16);"
"uint64_t u = htobe64(be64toh(*((uint64_t*)a)) >> n);"
"C_return(C_bytevector(&r, 8, (char*)&u));"))
(define wh#shr1 (foreign-primitive scheme-object
((blob a))
"C_word *r = C_alloc(16);"
"uint64_t u = htobe64(be64toh(*((uint64_t*)a)) >> 1);"
"C_return(C_bytevector(&r, 8, (char*)&u));"))
(define wh#shr4 (foreign-primitive scheme-object
((blob a))
"C_word *r = C_alloc(16);"
"uint64_t u = htobe64(be64toh(*((uint64_t*)a)) >> 4);"
"C_return(C_bytevector(&r, 8, (char*)&u));"))
(define wh#shr8 (foreign-primitive scheme-object
((blob a))
"C_word *r = C_alloc(16);"
"uint64_t u = htobe64(be64toh(*((uint64_t*)a)) >> 8);"
"C_return(C_bytevector(&r, 8, (char*)&u));"))
(define wh#shr16 (foreign-primitive scheme-object
((blob a))
"C_word *r = C_alloc(16);"
"uint64_t u = htobe64(be64toh(*((uint64_t*)a)) >> 16);"
"C_return(C_bytevector(&r, 8, (char*)&u));"))
(define wh#random (foreign-primitive scheme-object ()
"C_word *r = C_alloc(16);"
"uint64_t u = (((uint64_t)rand()) << 32 | (uint64_t)rand());"
"C_return(C_bytevector(&r, 8, (char*)&u));"))
(define (wh#if0 c t e) (if (equal? c wh#0) t e))
(define (wh#fold blob i f)
(let ((mask '#${00000000000000ff}))
(let loop ((blob blob) (o 0) (r i))
(if (= o 8)
r
(loop (wh#shr8 blob)
(+ o 1)
(f (wh#and mask blob) r))))))
)
| false |
c820a3b5575def8e279a5529ce02d378cda3fb02
|
a70301d352dcc9987daf2bf12919aecd66defbd8
|
/mredtalk2/text.ss
|
8e98bb0b2b7f1de3e29b36b49bda785322856780
|
[] |
no_license
|
mflatt/talks
|
45fbd97b1ca72addecf8f4b92053b85001ed540b
|
7abfdf9a9397d3d3d5d1b4c107ab6a62d0ac1265
|
refs/heads/master
| 2021-01-19T05:18:38.094408 | 2020-06-04T16:29:25 | 2020-06-04T16:29:25 | 87,425,078 | 2 | 2 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 1,814 |
ss
|
text.ss
|
(define esq-eventspace (current-eventspace))
(define (queue-output proc)
(parameterize ((current-eventspace
esq-eventspace))
(queue-callback proc #f)))
(define esq-text%
(class text%
(inherit insert last-position get-text erase)
(define prompt-pos 0)
(define locked? #t)
(augment*
(can-insert? (lambda (start len) (and (>= start prompt-pos) (not locked?))))
(can-delete? (lambda (start end) (and (>= start prompt-pos) (not locked?)))))
(override*
(on-char (lambda (c)
(super on-char c)
(when (and (eq? (send c get-key-code) #\return) (not locked?))
(set! locked? #t)
(evaluate (get-text prompt-pos (last-position)))))))
(public*
(new-prompt (lambda () (queue-output
(lambda ()
(set! locked? #f)
(insert "> ")
(set! prompt-pos (last-position))))))
(output (lambda (str) (queue-output
(lambda ()
(let ((was-locked? locked?))
(set! locked? #f)
(insert str)
(set! locked? was-locked?))))))
(reset (lambda ()
(set! locked? #f)
(set! prompt-pos 0)
(erase)
(new-prompt))))
(super-instantiate ())
(inherit get-style-list)
(let ([s (send (get-style-list) find-named-style "Standard")])
(when s
(let ([d (make-object style-delta% 'change-size 24)])
(send s set-delta d))))
(new-prompt)))
| false |
220a27214e97559dd042dd140a5184f4944dea70
|
4b480cab3426c89e3e49554d05d1b36aad8aeef4
|
/chapter-02/ex2.23-falsetru-test.scm
|
2058901330f418dd1fc23c3e39c42553ea0124d1
|
[] |
no_license
|
tuestudy/study-sicp
|
a5dc423719ca30a30ae685e1686534a2c9183b31
|
a2d5d65e711ac5fee3914e45be7d5c2a62bfc20f
|
refs/heads/master
| 2021-01-12T13:37:56.874455 | 2016-10-04T12:26:45 | 2016-10-04T12:26:45 | 69,962,129 | 0 | 0 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 120 |
scm
|
ex2.23-falsetru-test.scm
|
(load "ex2.23-falsetru.scm")
; how to test?
(for-each2 (lambda (x) (newline) (display x))
(list 57 321 88))
| false |
e20783c58f04689883907e622c3ac26f5f9dbfb9
|
120324bbbf63c54de0b7f1ca48d5dcbbc5cfb193
|
/apps/duck-calc.ss
|
6e6270b52e49810bea6e7475070a3c0ef0550600
|
[
"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 | 3,400 |
ss
|
duck-calc.ss
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;作者:evilbinary on 11/19/16.
;邮箱:[email protected]
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(import (scheme)
(glfw glfw)
(gui duck)
(gui draw)
(gui window)
(glut glut)
(gui widget))
(define (infix-prefix lst)
(if (list? lst)
(if (null? (cdr lst))
(car lst)
(list (cadr lst)
(infix-prefix (car lst))
(infix-prefix (cddr lst))))
lst))
(define exp-result 0)
(define exp "")
(define clear #t)
(define (app-calc)
(set! window (window-create 600 420 "鸭子gui"))
(let ((d (dialog 40.0 20.0 250.0 380.0 "计算器"))
(result (button 224.0 60.0 ""))
(cls (button 108.0 50.0 "清除"))
(percent (button 50.0 50.0 " % "))
(div (button 50.0 50.0 " / "))
(num7 (button 50.0 50.0 "7"))
(num8 (button 50.0 50.0 "8"))
(num9 (button 50.0 50.0 "9"))
(num6 (button 50.0 50.0 "6"))
(num5 (button 50.0 50.0 "5"))
(num4 (button 50.0 50.0 "4"))
(num3 (button 50.0 50.0 "3"))
(num2 (button 50.0 50.0 "2"))
(num1 (button 50.0 50.0 "1"))
(num0 (button 108.0 50.0 "0"))
(mul (button 50.0 50.0 " * "))
(sub (button 50.0 50.0 " - "))
(add (button 50.0 50.0 " + "))
(ret (button 50.0 50.0 " = "))
(dot (button 50.0 50.0 ".")))
(widget-set-attrs sub 'background #xfff79231)
(widget-set-attrs mul 'background #xfff79231)
(widget-set-attrs add 'background #xfff79231)
(widget-set-attrs ret 'background #xfff79231)
(widget-set-attrs div 'background #xfff79231)
(let loop ((btn (list result
cls percent div
num7 num8 num9 mul
num4 num5 num6 sub
num1 num2 num3 add
num0 dot ret)))
(if (pair? btn)
(begin
(widget-set-attrs (car btn) 'text-align 'center)
(widget-set-margin (car btn) 4.0 4.0 4.0 4.0)
(widget-set-attrs (car btn) 'font-size 24.0)
(widget-set-events
(car btn)
'click
(lambda (widget p type data)
(let ((text (widget-get-attr widget %text)))
(case text
[" = "
(if (and (> (string-length exp) 0) clear)
(begin
(printf "exp:~a\n" (format "(~a)" exp) )
(set! exp-result
(eval (infix-prefix
(read (open-input-string
(format "( ~a )" exp))))))
(set! exp (format "~a" exp-result ))
(widget-set-attr result %text exp)
(set! clear #f))
)]
["清除"
(set! exp "")
(set! exp-result "")
(set! clear #t)
(widget-set-attr result %text exp)
]
[else
(set! exp (string-append exp (format "~a" text) ))
(widget-set-attr result %text exp)
])
)))
(widget-add d (car btn))
(loop (cdr btn))
)))
(widget-set-attrs result 'text-align 'left)
(widget-set-attrs result 'background #x66cccccc)
(widget-set-attrs result 'font-size 50.0)
)
(window-loop window)
(window-destroy window))
(app-calc)
| false |
51d5918bb6d533bd036dfd9c34971b97156913da
|
b946259dec865fd015e98ad09212692dcd0ee073
|
/interpreter/stream.scm
|
cb3d7c4560f2d84ccbe1c79ecd168d602abe69b8
|
[
"MIT"
] |
permissive
|
TurtleKitty/Vaquero
|
5e5ce1419bcd0fe841d8cd3d791d1a9174bac022
|
d4c3823f7f7a88a67679ee774532d499ef1ac982
|
refs/heads/master
| 2021-06-09T14:45:54.658784 | 2021-05-28T04:31:09 | 2021-05-28T04:31:09 | 81,528,904 | 22 | 2 |
MIT
| 2020-02-06T01:50:16 | 2017-02-10T05:08:28 |
Scheme
|
UTF-8
|
Scheme
| false | false | 7,800 |
scm
|
stream.scm
|
(define vaquero-send-source-vtable #f)
(define vaquero-send-sink-vtable #f)
(let ()
(method view
(cont obj))
(method input?
(cont (input-port? obj)))
(method output?
(cont (output-port? obj)))
(method open?
(cont (not (port-closed? obj))))
(set! vaquero-send-source-vtable
(let ()
(define (if-alive obj msg cont err thunk)
(if (port-closed? obj)
(err (vaquero-error-object 'source-closed `(send ,obj ,msg) "Source closed.") cont)
(cont (thunk))))
(method answers?
(cont (lambda (msg) (hte? vaquero-send-source-vtable msg))))
(method autos
(cont '(view to-text to-bool to-list ready? input? output? open? read read-seq read-char peek-char read-line read-lines read-text)))
(method messages
(cont (htks vaquero-send-source-vtable)))
(method type
(cont '(source stream)))
(method ready?
(cont (char-ready? obj)))
(method stream-read
(if-alive obj msg cont err
(vaquero-wrap-user-facing-interpreter
(lambda ()
(vaquero-read obj)))))
(method read-seq
(if-alive obj msg cont err
(vaquero-wrap-user-facing-interpreter
(lambda ()
(vaquero-read-file obj)))))
(method stream-read-char
(if-alive obj msg cont err
(lambda ()
(string (read-char obj)))))
(method stream-peek-char
(if-alive obj msg cont err
(lambda ()
(string (peek-char obj)))))
(method stream-read-line
(if-alive obj msg cont err
(lambda ()
(read-line obj))))
(method stream-read-lines
(if-alive obj msg cont err
(lambda ()
(read-lines obj))))
(method stream-read-text
(if-alive obj msg cont err
(lambda ()
(read-string #f obj))))
(method read-n
(if-alive obj msg cont err
(lambda ()
(lambda (n)
(read-string n obj)))))
(method read-while
(if-alive obj msg cont err
(lambda ()
(lambda (s)
(define runes (string->list s))
(let loop ((tok (peek-char obj)) (acc '()))
(if (member tok runes)
(let ((t (read-char obj)))
(loop (peek-char obj) (cons t acc)))
(list->string (reverse acc))))))))
(method read-until
(if-alive obj msg cont err
(lambda ()
(lambda (s)
(define runes (string->list s))
(let loop ((tok (peek-char obj)) (acc '()))
(if (member tok runes)
(list->string (reverse acc))
(let ((t (read-char obj)))
(loop (peek-char obj) (cons t acc)))))))))
(method skip-n
(if-alive obj msg cont err
(lambda ()
(lambda (n)
(read-string n obj)
'null))))
(method skip-while
(if-alive obj msg cont err
(lambda ()
(lambda (s)
(define runes (string->list s))
(let loop ((tok (peek-char obj)))
(if (member tok runes)
(begin
(read-char obj)
(loop (peek-char obj)))
'null))))))
(method skip-until
(if-alive obj msg cont err
(lambda ()
(lambda (s)
(define runes (string->list s))
(let loop ((tok (peek-char obj)))
(if (member tok runes)
'null
(begin
(read-char obj)
(loop (peek-char obj)))))))))
(method close
(cont (close-input-port obj) (cont 'null)))
(alist->hash-table
`((answers? . ,answers?)
(autos . ,autos)
(messages . ,messages)
(to-bool . ,open?)
(to-text . ,stream-read-text)
(to-list . ,stream-read-lines)
(to-stream . ,view)
(type . ,type)
(view . ,view)
(input? . ,input?)
(output? . ,output?)
(open? . ,open?)
(ready? . ,ready?)
(read . ,stream-read)
(read-seq . ,read-seq)
(read-char . ,stream-read-char)
(peek-char . ,stream-peek-char)
(read-line . ,stream-read-line)
(read-lines . ,stream-read-lines)
(read-text . ,stream-read-text)
(read-n . ,read-n)
(read-while . ,read-while)
(read-until . ,read-until)
(skip-n . ,skip-n)
(skip-while . ,skip-while)
(skip-until . ,skip-until)
(close . ,close)
(default . ,idk)))))
(set! vaquero-send-sink-vtable
(let ()
(define (if-alive obj msg cont err thunk)
(if (port-closed? obj)
(err (vaquero-error-object 'sink-closed `(send ,obj ,msg) "Sink closed.") cont)
(cont (thunk))))
(method answers?
(cont (lambda (msg) (hte? vaquero-send-sink-vtable msg))))
(method autos
(cont '(view to-bool input? output? open? nl close)))
(method messages
(cont (htks vaquero-send-sink-vtable)))
(method type
(cont '(sink stream)))
(method stream-write
(if-alive obj msg cont err
(lambda ()
(lambda (x)
(vaquero-write x obj)
'null))))
(method stream-print
(if-alive obj msg cont err
(lambda ()
(lambda (x)
(vaquero-print x obj)
'null))))
(method stream-say
(if-alive obj msg cont err
(lambda ()
(lambda (x)
(vaquero-print x obj)
(newline obj)
'null))))
(method nl
(if-alive obj msg cont err
(lambda ()
(newline obj)
'null)))
(method flush
(flush-output obj) (cont 'null))
(method close
(close-output-port obj) (cont 'null))
(alist->hash-table
`((answers? . ,answers?)
(autos . ,autos)
(messages . ,messages)
(to-bool . ,open?)
(to-stream . ,view)
(type . ,type)
(view . ,view)
(input? . ,input?)
(output? . ,output?)
(open? . ,open?)
(write . ,stream-write)
(print . ,stream-print)
(say . ,stream-say)
(nl . ,nl)
(flush . ,flush)
(close . ,close)
(default . ,idk))))))
| false |
33100e5dae34e3dbde214eec5953c4ba39fe88e7
|
a09ad3e3cf64bc87282dea3902770afac90568a7
|
/4/59.scm
|
66f81b8d8b6dcb257231e8b5aa6d4c9fba1a93f3
|
[] |
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 | 552 |
scm
|
59.scm
|
(assert! (meeting accounting (monday 9)))
(assert! (meeting administration (monday 10)))
(assert! (meeting computer (wednesday 15)))
(assert! (meeting administration (friday 13)))
(assert! (meeting the-whole-company (wednesday 16)))
;; a
(meeting ?x (friday ?t))
;; b
(assert! (rule (meeting-time ?person ?day-and-time)
(or (meeting the-whole-company ?day-and-time)
(and (job ?person (?dept . ?rest))
(meeting ?dept ?day-and-time)))))
;; c
(meeting-time (Hacker Alyssa P) (wednesday ?time))
| false |
420dcc84d645ce036e819df14e1f51ce71c762c7
|
defeada37d39bca09ef76f66f38683754c0a6aa0
|
/UnityEngine/unity-engine/serialization/list-serialization-surrogate.sls
|
be7a7c57e2f03a1ac366def3434a17d3011e0748
|
[] |
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,409 |
sls
|
list-serialization-surrogate.sls
|
(library (unity-engine serialization list-serialization-surrogate)
(export new
is?
list-serialization-surrogate?
set-object-data
get-object-data
default)
(import (ironscheme-clr-port))
(define-syntax new
(lambda (e)
(syntax-case e ()
((_ a ...)
#'(clr-new
UnityEngine.Serialization.ListSerializationSurrogate
a
...)))))
(define (is? a)
(clr-is UnityEngine.Serialization.ListSerializationSurrogate a))
(define (list-serialization-surrogate? a)
(clr-is UnityEngine.Serialization.ListSerializationSurrogate a))
(define-method-port
set-object-data
UnityEngine.Serialization.ListSerializationSurrogate
SetObjectData
(System.Object
System.Object
System.Runtime.Serialization.SerializationInfo
System.Runtime.Serialization.StreamingContext
System.Runtime.Serialization.ISurrogateSelector))
(define-method-port
get-object-data
UnityEngine.Serialization.ListSerializationSurrogate
GetObjectData
(System.Void
System.Object
System.Runtime.Serialization.SerializationInfo
System.Runtime.Serialization.StreamingContext))
(define-field-port
default
#f
#f
(static:)
UnityEngine.Serialization.ListSerializationSurrogate
Default
System.Runtime.Serialization.ISerializationSurrogate))
| true |
d3674e8d75d97859624e51ac5b21adbe38cde219
|
ebf028b3a35ae1544bba1a1f9aa635135486ee6c
|
/sitelib/lunula/html.scm
|
643a6cca63106071be827a414e3d9aff14411def
|
[
"BSD-2-Clause",
"BSD-3-Clause"
] |
permissive
|
tabe/lunula
|
b4b666151874271211744cce1346e58e3a56fa79
|
b7699a850b9c9a64c1d3a52d50ce20050bd17475
|
refs/heads/master
| 2021-01-01T20:04:43.571993 | 2010-05-06T15:39:31 | 2010-05-06T15:39:31 | 334,916 | 2 | 0 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 2,267 |
scm
|
html.scm
|
(library (lunula html)
(export doctype
a
blockquote
body
br
code
dd
div
dl
dt
em
form
h1
h2
h3
h4
h5
h6
head
hr
html
img
input
label
li
link
meta
ol
option
p
pre
q
script
select
span
style
table
tbody
td
textarea
tfoot
th
title
tr
ul
escape
escape-char
escape-string)
(import (except (rnrs) div)
(only (srfi :1) lset-union)
(lunula xml))
(define-syntax doctype
(syntax-rules (strict transitional xhtml-1.0-strict xhtml-1.0-transitional xhtml-1.1)
((_ strict)
"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\"\n\t\"http://www.w3.org/TR/html4/strict.dtd\">\n")
((_ transitional)
"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"\n\t\"http://www.w3.org/TR/html4/loose.dtd\">\n")
((_ xhtml-1.0-strict)
"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"\n\t\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n")
((_ xhtml-1.0-transitional)
"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"\n\t\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n")
((_ xhtml-1.1)
"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\"\n\t\"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\">\n")))
(define-element
a
blockquote
body
br
code
dd
div
dl
dt
em
h1
h2
h3
h4
h5
h6
head
hr
html
img
input
li
link
meta
ol
p
pre
q
span
style
title
td
th
tr
ul)
(define-element/
form
label
option
script
select
textarea
table
tbody
tfoot)
(for-each
(lambda (k v)
(hashtable-set! default-attributes k v))
'(form
textarea)
'(((method . "POST"))
((rows . 5) (cols . 50))))
)
| true |
3660af86d8c3c89da25be46d079416924740d870
|
5add38e6841ff4ec253b32140178c425b319ef09
|
/%3a98/os-environment-variables.ironscheme.sls
|
5a83a3546a3fe67bf38d07a66e719180ceab653c
|
[
"X11-distribute-modifications-variant"
] |
permissive
|
arcfide/chez-srfi
|
8ca82bfed96ee1b7f102a4dcac96719de56ff53b
|
e056421dcf75d30e8638c8ce9bc6b23a54679a93
|
refs/heads/master
| 2023-03-09T00:46:09.220953 | 2023-02-22T06:18:26 | 2023-02-22T06:18:26 | 3,235,886 | 106 | 42 |
NOASSERTION
| 2023-02-22T06:18:27 | 2012-01-21T20:21:20 |
Scheme
|
UTF-8
|
Scheme
| false | false | 449 |
sls
|
os-environment-variables.ironscheme.sls
|
(library (srfi :98 os-environment-variables)
(export
get-environment-variables
get-environment-variable)
(import
(ironscheme)
(except (ironscheme environment) get-environment-variables)
(rename (ironscheme environment) (get-environment-variables get-env-vars)))
(define (get-environment-variables)
(let-values (((k v) (hashtable-entries (get-env-vars))))
(map cons (vector->list k) (vector->list v))))
)
| false |
47ed85e6568eb3940217fd0eb4e2af9c921c0919
|
d755de283154ca271ef6b3b130909c6463f3f553
|
/htdp-lib/teachpack/htdp/guess-gui.rkt
|
57381b3ec86b6ab9470c95220afca828f3cebac5
|
[
"Apache-2.0",
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] |
permissive
|
racket/htdp
|
2953ec7247b5797a4d4653130c26473525dd0d85
|
73ec2b90055f3ab66d30e54dc3463506b25e50b4
|
refs/heads/master
| 2023-08-19T08:11:32.889577 | 2023-08-12T15:28:33 | 2023-08-12T15:28:33 | 27,381,208 | 100 | 90 |
NOASSERTION
| 2023-07-08T02:13:49 | 2014-12-01T13:41:48 |
Racket
|
UTF-8
|
Scheme
| false | false | 83 |
rkt
|
guess-gui.rkt
|
#lang racket/base
(require htdp/guess-gui)
(provide (all-from-out htdp/guess-gui))
| false |
3f0d58a3754439ced5d9f36864ca6b0edf691bf6
|
784dc416df1855cfc41e9efb69637c19a08dca68
|
/src/bootstrap/gerbil/expander/stxcase__0.scm
|
05ed9d966233cf66f62fb9f95f32159592c5348b
|
[
"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 | 98,955 |
scm
|
stxcase__0.scm
|
(declare (block) (standard-bindings) (extended-bindings))
(begin
(define gx#syntax-pattern::t
(make-struct-type
'gx#syntax-pattern::t
gx#expander::t
'2
'syntax-pattern
'()
'#f
'(id depth)))
(define gx#syntax-pattern? (make-struct-predicate gx#syntax-pattern::t))
(define gx#make-syntax-pattern
(lambda _$args18374_
(apply make-struct-instance gx#syntax-pattern::t _$args18374_)))
(define gx#syntax-pattern-id
(make-struct-field-accessor gx#syntax-pattern::t '0))
(define gx#syntax-pattern-depth
(make-struct-field-accessor gx#syntax-pattern::t '1))
(define gx#syntax-pattern-id-set!
(make-struct-field-mutator gx#syntax-pattern::t '0))
(define gx#syntax-pattern-depth-set!
(make-struct-field-mutator gx#syntax-pattern::t '1))
(define gx#syntax-pattern::apply-macro-expander
(lambda (_self18371_ _stx18372_)
(gx#raise-syntax-error
'#f
'"Identifier used out of context"
_stx18372_)))
(bind-method!
gx#syntax-pattern::t
'apply-macro-expander
gx#syntax-pattern::apply-macro-expander
'#f)
(define gx#macro-expand-syntax
(lambda (_stx17853_)
(letrec ((_generate17855_
(lambda (_e18082_)
(letrec ((_BUG18084_
(lambda (_q18246_)
(error '"BUG: syntax; generate"
_stx17853_
_e18082_
_q18246_)))
(_local-pattern-e18085_
(lambda (_pat18244_)
(gx#syntax-local-rewrap
(##structure-ref
_pat18244_
'2
gx#syntax-pattern::t
'#f))))
(_getvar18086_
(lambda (_q18241_ _vars18242_)
(assgetq _q18241_ _vars18242_ _BUG18084_)))
(_getarg18087_
(lambda (_arg18207_ _vars18208_)
(let* ((_arg1820918216_ _arg18207_)
(_E1821118220_
(lambda ()
(error '"No clause matching"
_arg1820918216_)))
(_K1821218229_
(lambda (_e18223_ _tag18224_)
(let ((_$e18226_ _tag18224_))
(if (eq? 'ref _$e18226_)
(_getvar18086_
_e18223_
_vars18208_)
(if (eq? 'pattern _$e18226_)
(_local-pattern-e18085_
_e18223_)
(_BUG18084_ _arg18207_)))))))
(if (##pair? _arg1820918216_)
(let ((_hd1821318232_
(##car _arg1820918216_))
(_tl1821418234_
(##cdr _arg1820918216_)))
(let* ((_tag18237_ _hd1821318232_)
(_e18239_ _tl1821418234_))
(_K1821218229_ _e18239_ _tag18237_)))
(_E1821118220_))))))
(let _recur18089_ ((_e18091_ _e18082_) (_vars18092_ '()))
(let* ((_e1809318100_ _e18091_)
(_E1809518104_
(lambda ()
(error '"No clause matching" _e1809318100_)))
(_K1809618195_
(lambda (_body18107_ _tag18108_)
(let ((_$e18110_ _tag18108_))
(if (eq? 'datum _$e18110_)
(gx#core-list 'quote _body18107_)
(if (eq? 'term _$e18110_)
(let ((_id18113_
(gx#syntax-local-unwrap
_body18107_)))
(if (##structure-direct-instance-of?
_id18113_
'gx#identifier-wrap::t)
(let ((_marks18115_
(##direct-structure-ref
_id18113_
'3
gx#identifier-wrap::t
'#f)))
(if (null? _marks18115_)
(gx#core-list
'datum->syntax
'#f
(gx#core-list
'quote
_body18107_))
(gx#core-list
'datum->syntax
(gx#core-list
'quote-syntax
_body18107_)
(gx#core-list
'quote
_body18107_)
'#f
'#f)))
(if (##structure-direct-instance-of?
_id18113_
'gx#syntax-quote::t)
(gx#core-list
'quote-syntax
_body18107_)
(_BUG18084_ _e18091_))))
(if (eq? 'pattern _$e18110_)
(_local-pattern-e18085_
_body18107_)
(if (eq? 'ref _$e18110_)
(_getvar18086_
_body18107_
_vars18092_)
(if (eq? 'cons _$e18110_)
(gx#core-list
'cons
(_recur18089_
(car _body18107_)
_vars18092_)
(_recur18089_
(cdr _body18107_)
_vars18092_))
(if (eq? 'vector
_$e18110_)
(gx#core-list
'list->vector
(_recur18089_
_body18107_
_vars18092_))
(if (eq? 'box
;;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
_$e18110_)
(gx#core-list
'box
(_recur18089_ _body18107_ _vars18092_))
(if (eq? 'splice _$e18110_)
(let* ((_body1811618127_ _body18107_)
(_E1811818131_
(lambda ()
(error '"No clause matching"
_body1811618127_)))
(_K1811918169_
(lambda (_args18134_
_iv18135_
_hd18136_
_depth18137_)
(let* ((_targets18143_
(map (lambda (_g1813818140_)
(_getarg18087_
_g1813818140_
_vars18092_))
_args18134_))
(_fold-in18145_
(gx#gentemps _args18134_))
(_fold-out18147_ (gx#genident__0))
(_lambda-args18149_
(foldr1 cons
(cons _fold-out18147_ '())
_fold-in18145_))
(_lambda-body18166_
(if (fx> _depth18137_ '1)
(let ((_r-args18157_
(map (lambda (_arg18151_)
(cons 'ref
;;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
(cdr _arg18151_)))
_args18134_))
(_r-vars18158_
(foldr2 (lambda (_arg18153_ _var18154_ _r18155_)
(cons (cons (cdr _arg18153_) _var18154_) _r18155_))
_vars18092_
_args18134_
_fold-in18145_)))
;;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
(_recur18089_
(cons 'splice
(cons (fx- _depth18137_
;;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
'1)
(cons _hd18136_
(cons (cons 'var _fold-out18147_)
_r-args18157_))))
;;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
_r-vars18158_))
(let ((_hd-vars18164_
(foldr2 (lambda (_arg18160_
;;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
_var18161_
_r18162_)
(cons (cons (cdr _arg18160_) _var18161_) _r18162_))
_vars18092_
_args18134_
_fold-in18145_)))
;;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
(gx#core-list
'cons
(_recur18089_
_hd18136_
_hd-vars18164_)
_fold-out18147_)))))
(gx#core-list
'begin
(if (fx> (length _targets18143_) '1)
(gx#core-cons*
'syntax-check-splice-targets
_targets18143_)
'#!void)
(gx#core-cons*
'foldr
(gx#core-list
'lambda%
_lambda-args18149_
_lambda-body18166_)
(_recur18089_ _iv18135_ _vars18092_)
_targets18143_))))))
(if (##pair? _body1811618127_)
(let ((_hd1812018172_ (##car _body1811618127_))
(_tl1812118174_
(##cdr _body1811618127_)))
(let ((_depth18177_ _hd1812018172_))
(if (##pair? _tl1812118174_)
(let ((_hd1812218179_
(##car _tl1812118174_))
(_tl1812318181_
(##cdr _tl1812118174_)))
(let ((_hd18184_ _hd1812218179_))
(if (##pair? _tl1812318181_)
(let ((_hd1812418186_
(##car _tl1812318181_))
(_tl1812518188_
(##cdr _tl1812318181_)))
(let* ((_iv18191_
_hd1812418186_)
(_args18193_
_tl1812518188_))
(_K1811918169_
_args18193_
_iv18191_
_hd18184_
_depth18177_)))
(_E1811818131_))))
(_E1811818131_))))
(_E1811818131_)))
(if (eq? 'var _$e18110_)
_body18107_
(_BUG18084_ _e18091_))))))))))))))
;;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
(if (##pair? _e1809318100_)
(let ((_hd1809718198_ (##car _e1809318100_))
(_tl1809818200_ (##cdr _e1809318100_)))
(let* ((_tag18203_ _hd1809718198_)
(_body18205_ _tl1809818200_))
(_K1809618195_ _body18205_ _tag18203_)))
(_E1809518104_)))))))
(_parse17856_
(lambda (_e17897_)
(letrec ((_make-cons17899_
(lambda (_hd18074_ _tl18075_)
(let ((_g18376_ _hd18074_) (_g18378_ _tl18075_))
(begin
(let ((_g18377_
(if (##values? _g18376_)
(##vector-length _g18376_)
1)))
(if (not (##fx= _g18377_ 2))
(error "Context expects 2 values"
_g18377_)))
(let ((_g18379_
(if (##values? _g18378_)
(##vector-length _g18378_)
1)))
(if (not (##fx= _g18379_ 2))
(error "Context expects 2 values"
_g18379_)))
(let ((_hd-e18077_ (##vector-ref _g18376_ 0))
(_hd-vars18078_
(##vector-ref _g18376_ 1)))
(let ((_tl-e18079_
(##vector-ref _g18378_ 0))
(_tl-vars18080_
(##vector-ref _g18378_ 1)))
(values (cons 'cons
(cons _hd-e18077_
_tl-e18079_))
(append _hd-vars18078_
_tl-vars18080_))))))))
(_make-splice17900_
(lambda (_where18013_
_depth18014_
_hd18015_
_tl18016_)
(let ((_g18380_ _hd18015_) (_g18382_ _tl18016_))
(begin
(let ((_g18381_
(if (##values? _g18380_)
(##vector-length _g18380_)
1)))
(if (not (##fx= _g18381_ 2))
(error "Context expects 2 values"
_g18381_)))
(let ((_g18383_
(if (##values? _g18382_)
(##vector-length _g18382_)
1)))
(if (not (##fx= _g18383_ 2))
(error "Context expects 2 values"
_g18383_)))
(let ((_hd-e18018_ (##vector-ref _g18380_ 0))
(_hd-vars18019_
(##vector-ref _g18380_ 1)))
(let ((_tl-e18020_
(##vector-ref _g18382_ 0))
(_tl-vars18021_
(##vector-ref _g18382_ 1)))
(let _lp18023_ ((_rest18025_
_hd-vars18019_)
(_targets18026_ '())
(_vars18027_
_tl-vars18021_))
(let* ((_rest1802818038_ _rest18025_)
(_else1803018046_
(lambda ()
(if (null? _targets18026_)
(gx#raise-syntax-error
'#f
'"Misplaced ellipsis"
_stx17853_
_where18013_)
(values (cons 'splice
;;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
(cons _depth18014_
(cons _hd-e18018_
(cons _tl-e18020_ _targets18026_))))
_vars18027_))))
;;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
(_K1803218055_
(lambda (_rest18049_
_hd-pat18050_
_hd-depth*18051_)
(let ((_hd-depth18053_
(fx- _hd-depth*18051_
_depth18014_)))
(if (fxpositive?
_hd-depth18053_)
(_lp18023_
_rest18049_
(cons (cons 'ref
;;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
_hd-pat18050_)
_targets18026_)
(cons (cons _hd-depth18053_ _hd-pat18050_) _vars18027_))
(if (fxzero? _hd-depth18053_)
(_lp18023_
_rest18049_
(cons (cons 'pattern _hd-pat18050_) _targets18026_)
_vars18027_)
(gx#raise-syntax-error
'#f
'"Too many ellipses"
_stx17853_
_where18013_)))))))
;;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
(if (##pair? _rest1802818038_)
(let ((_hd1803318058_
(##car _rest1802818038_))
(_tl1803418060_
(##cdr _rest1802818038_)))
(if (##pair? _hd1803318058_)
(let ((_hd1803518063_
(##car _hd1803318058_))
(_tl1803618065_
(##cdr _hd1803318058_)))
(let* ((_hd-depth*18068_
_hd1803518063_)
(_hd-pat18070_
_tl1803618065_)
(_rest18072_
_tl1803418060_))
(_K1803218055_
_rest18072_
_hd-pat18070_
_hd-depth*18068_)))
(_else1803018046_)))
(_else1803018046_))))))))))
(_recur17901_
(lambda (_e17906_ _is-e?17907_)
(if (_is-e?17907_ _e17906_)
(gx#raise-syntax-error
'#f
'"Mislpaced ellipsis"
_stx17853_)
(if (gx#syntax-local-pattern? _e17906_)
(let* ((_pat17909_
(gx#syntax-local-e__0 _e17906_))
(_depth17911_
(##structure-ref
_pat17909_
'3
gx#syntax-pattern::t
'#f)))
(if (fxpositive? _depth17911_)
(values (cons 'ref _pat17909_)
(cons (cons _depth17911_
_pat17909_)
'()))
(values (cons 'pattern _pat17909_)
'())))
(if (gx#identifier? _e17906_)
(values (cons 'term _e17906_) '())
(if (gx#stx-pair? _e17906_)
(let* ((_e1791317920_ _e17906_)
(_E1791517924_
(lambda ()
(gx#raise-syntax-error
'#f
'"Bad syntax"
_e1791317920_)))
(_E1791418003_
(lambda ()
(if (gx#stx-pair?
_e1791317920_)
(let ((_e1791617928_
;;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
(gx#syntax-e _e1791317920_)))
(let ((_hd1791717931_ (##car _e1791617928_))
(_tl1791817933_ (##cdr _e1791617928_)))
(let* ((_hd17936_ _hd1791717931_)
(_rest17938_ _tl1791817933_))
(if '#t
(if (_is-e?17907_ _hd17936_)
(let* ((_e1793917946_ _rest17938_)
(_E1794117950_
(lambda ()
(gx#raise-syntax-error
'#f
'"Bad ellipsis syntax"
_stx17853_
_e17906_)))
(_E1794017964_
(lambda ()
(if (gx#stx-pair? _e1793917946_)
(let ((_e1794217954_
(gx#syntax-e
_e1793917946_)))
(let ((_hd1794317957_
(##car _e1794217954_))
(_tl1794417959_
(##cdr _e1794217954_)))
(let ((_rest17962_
_hd1794317957_))
(if (gx#stx-null?
_tl1794417959_)
(if '#t
(_recur17901_
_rest17962_
false)
(_E1794117950_))
(_E1794117950_)))))
(_E1794117950_)))))
(_E1794017964_))
(let _lp17968_ ((_rest17970_ _rest17938_)
(_depth17971_ '0))
(let* ((_e1797217979_ _rest17970_)
(_E1797417983_
(lambda ()
(if (fxpositive? _depth17971_)
(_make-splice17900_
_e17906_
_depth17971_
(_recur17901_
_hd17936_
_is-e?17907_)
(_recur17901_
_rest17970_
_is-e?17907_))
(_make-cons17899_
(_recur17901_
_hd17936_
_is-e?17907_)
(_recur17901_
_rest17970_
_is-e?17907_)))))
(_E1797317999_
(lambda ()
(if (gx#stx-pair? _e1797217979_)
(let ((_e1797517987_
(gx#syntax-e
_e1797217979_)))
(let ((_hd1797617990_
(##car _e1797517987_))
(_tl1797717992_
(##cdr _e1797517987_)))
(let* ((_rest-hd17995_
_hd1797617990_)
(_rest-tl17997_
_tl1797717992_))
(if '#t
(if (_is-e?17907_
;;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
_rest-hd17995_)
(_lp17968_ _rest-tl17997_ (fx+ _depth17971_ '1))
(if (fxpositive? _depth17971_)
(_make-splice17900_
_e17906_
_depth17971_
(_recur17901_ _hd17936_ _is-e?17907_)
(_recur17901_ _rest17970_ _is-e?17907_))
(_make-cons17899_
(_recur17901_ _hd17936_ _is-e?17907_)
(_recur17901_ _rest17970_ _is-e?17907_))))
(_E1797417983_)))))
;;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
(_E1797417983_)))))
(_E1797317999_))))
(_E1791517924_)))))
(_E1791517924_)))))
;;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
(_E1791418003_))
(if (gx#stx-vector? _e17906_)
(let ((_g18384_
(_recur17901_
(vector->list
(gx#stx-unwrap__0
_e17906_))
_is-e?17907_)))
(begin
(let ((_g18385_
(if (##values?
;;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
_g18384_)
(##vector-length _g18384_)
1)))
(if (not (##fx= _g18385_ 2))
(error "Context expects 2 values" _g18385_)))
(let ((_e18007_ (##vector-ref _g18384_ 0))
(_vars18008_ (##vector-ref _g18384_ 1)))
(values (cons 'vector _e18007_) _vars18008_))))
;;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
(if (gx#stx-box? _e17906_)
(let ((_g18386_
(_recur17901_
(unbox (gx#stx-unwrap__0
;;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
_e17906_))
_is-e?17907_)))
(begin
(let ((_g18387_
(if (##values? _g18386_)
(##vector-length _g18386_)
1)))
(if (not (##fx= _g18387_ 2))
(error "Context expects 2 values" _g18387_)))
(let ((_e18010_ (##vector-ref _g18386_ 0))
(_vars18011_ (##vector-ref _g18386_ 1)))
(values (cons 'box _e18010_) _vars18011_))))
(values (cons 'datum _e17906_) '()))))))))))
;;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
(let ((_g18388_ (_recur17901_ _e17897_ gx#ellipsis?)))
(begin
(let ((_g18389_
(if (##values? _g18388_)
(##vector-length _g18388_)
1)))
(if (not (##fx= _g18389_ 2))
(error "Context expects 2 values" _g18389_)))
(let ((_tree17903_ (##vector-ref _g18388_ 0))
(_vars17904_ (##vector-ref _g18388_ 1)))
(if (null? _vars17904_)
_tree17903_
(gx#raise-syntax-error
'#f
'"Missing ellipsis"
_stx17853_
_vars17904_)))))))))
(let* ((_e1785717867_ _stx17853_)
(_E1785917871_
(lambda ()
(gx#raise-syntax-error '#f '"Bad syntax" _stx17853_)))
(_E1785817893_
(lambda ()
(if (gx#stx-pair? _e1785717867_)
(let ((_e1786017875_ (gx#syntax-e _e1785717867_)))
(let ((_hd1786117878_ (##car _e1786017875_))
(_tl1786217880_ (##cdr _e1786017875_)))
(if (gx#stx-pair? _tl1786217880_)
(let ((_e1786317883_
(gx#syntax-e _tl1786217880_)))
(let ((_hd1786417886_ (##car _e1786317883_))
(_tl1786517888_ (##cdr _e1786317883_)))
(let ((_form17891_ _hd1786417886_))
(if (gx#stx-null? _tl1786517888_)
(if '#t
(gx#stx-wrap-source
(_generate17855_
(_parse17856_ _form17891_))
(gx#stx-source _stx17853_))
(_E1785917871_))
(_E1785917871_)))))
(_E1785917871_))))
(_E1785917871_)))))
(_E1785817893_)))))
(begin
(define gx#macro-expand-syntax-case__%
(lambda (_stx17117_ _identifier=?17118_ _unwrap-e17119_ _wrap-e17120_)
(letrec ((_generate-bindings17122_
(lambda (_target17717_
_ids17718_
_clauses17719_
_clause-ids17720_
_E17721_)
(letrec ((_generate117723_
(lambda (_clause17820_ _clause-id17821_ _E17822_)
(cons (cons _clause-id17821_ '())
(cons (gx#core-list
'lambda%
(cons _target17717_ '())
(_generate-clause17124_
_target17717_
_ids17718_
_clause17820_
_E17822_))
'())))))
(let _lp17725_ ((_rest17727_ _clauses17719_)
(_rest-ids17728_ _clause-ids17720_)
(_bindings17729_ '()))
(let* ((_rest1773017738_ _rest17727_)
(_else1773217746_ (lambda () _bindings17729_))
(_K1773417808_
(lambda (_rest17749_ _clause17750_)
(let* ((_rest-ids1775117758_ _rest-ids17728_)
(_E1775317762_
(lambda ()
(error '"No clause matching"
_rest-ids1775117758_)))
(_K1775417796_
(lambda (_rest-ids17765_
_clause-id17766_)
(let* ((_rest-ids1776717775_
_rest-ids17765_)
(_else1776917783_
(lambda ()
(cons (_generate117723_
_clause17750_
_clause-id17766_
_E17721_)
_bindings17729_)))
(_K1777117788_
(lambda (_next-clause-id17786_)
(_lp17725_
_rest17749_
_rest-ids17765_
(cons (_generate117723_
_clause17750_
_clause-id17766_
_next-clause-id17786_)
_bindings17729_)))))
(if (##pair? _rest-ids1776717775_)
(let* ((_hd1777217791_
(##car _rest-ids1776717775_))
(_next-clause-id17794_
_hd1777217791_))
(_K1777117788_
_next-clause-id17794_))
(_else1776917783_))))))
(if (##pair? _rest-ids1775117758_)
(let ((_hd1775517799_
(##car _rest-ids1775117758_))
(_tl1775617801_
(##cdr _rest-ids1775117758_)))
(let* ((_clause-id17804_
_hd1775517799_)
(_rest-ids17806_
_tl1775617801_))
(_K1775417796_
_rest-ids17806_
_clause-id17804_)))
(_E1775317762_))))))
(if (##pair? _rest1773017738_)
(let ((_hd1773517811_ (##car _rest1773017738_))
(_tl1773617813_ (##cdr _rest1773017738_)))
(let* ((_clause17816_ _hd1773517811_)
(_rest17818_ _tl1773617813_))
(_K1773417808_ _rest17818_ _clause17816_)))
(_else1773217746_)))))))
(_generate-body17123_
(lambda (_bindings17677_ _body17678_)
(let _recur17680_ ((_rest17682_ _bindings17677_))
(let* ((_rest1768317691_ _rest17682_)
(_else1768517699_ (lambda () _body17678_))
(_K1768717705_
(lambda (_rest17702_ _hd17703_)
(gx#core-list
'let-values
(cons _hd17703_ '())
(_recur17680_ _rest17702_)))))
(if (##pair? _rest1768317691_)
(let ((_hd1768817708_ (##car _rest1768317691_))
(_tl1768917710_ (##cdr _rest1768317691_)))
(let* ((_hd17713_ _hd1768817708_)
(_rest17715_ _tl1768917710_))
(_K1768717705_ _rest17715_ _hd17713_)))
(_else1768517699_))))))
(_generate-clause17124_
(lambda (_target17540_ _ids17541_ _clause17542_ _E17543_)
(letrec ((_generate117545_
(lambda (_hd17632_ _fender17633_ _body17634_)
(let ((_g18390_
(_parse-clause17126_
_hd17632_
_ids17541_)))
(begin
(let ((_g18391_
(if (##values? _g18390_)
(##vector-length _g18390_)
1)))
(if (not (##fx= _g18391_ 2))
(error "Context expects 2 values"
_g18391_)))
(let ((_e17636_ (##vector-ref _g18390_ 0))
(_mvars17637_
(##vector-ref _g18390_ 1)))
(let* ((_pvars17639_
(map gx#syntax-local-rewrap
(gx#gentemps _mvars17637_)))
(_E17641_
(cons _E17543_
(cons _target17540_ '())))
(_K17674_
(gx#core-list
'lambda%
_pvars17639_
(gx#core-list
'let-syntax
(map (lambda (_mvar17643_
_pvar17644_)
(let* ((_mvar1764517652_
_mvar17643_)
(_E1764717656_
(lambda ()
;;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
(error '"No clause matching" _mvar1764517652_)))
(_K1764817662_
(lambda (_depth17659_ _id17660_)
(cons _id17660_
(cons (gx#core-list
'make-syntax-pattern
(gx#core-list 'quote _id17660_)
(gx#core-list 'quote _pvar17644_)
_depth17659_)
'())))))
(if (##pair? _mvar1764517652_)
(let ((_hd1764917665_ (##car _mvar1764517652_))
(_tl1765017667_ (##cdr _mvar1764517652_)))
(let* ((_id17670_ _hd1764917665_)
(_depth17672_ _tl1765017667_))
(_K1764817662_ _depth17672_ _id17670_)))
(_E1764717656_))))
;;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
_mvars17637_
_pvars17639_)
(if (eq? _fender17633_ '#t)
_body17634_
(gx#core-list
'if
_fender17633_
_body17634_
_E17641_))))))
(_generate-match17125_
_hd17632_
_target17540_
_e17636_
_mvars17637_
_K17674_
_E17641_))))))))
(let* ((_e1754617566_ _clause17542_)
(_E1755517570_
(lambda ()
(gx#raise-syntax-error
'#f
'"Bad syntax"
_e1754617566_)))
(_E1754817604_
(lambda ()
(if (gx#stx-pair? _e1754617566_)
(let ((_e1755617574_
(gx#syntax-e _e1754617566_)))
(let ((_hd1755717577_
(##car _e1755617574_))
(_tl1755817579_
(##cdr _e1755617574_)))
(let ((_hd17582_ _hd1755717577_))
(if (gx#stx-pair? _tl1755817579_)
(let ((_e1755917584_
(gx#syntax-e
_tl1755817579_)))
(let ((_hd1756017587_
(##car _e1755917584_))
(_tl1756117589_
(##cdr _e1755917584_)))
(let ((_fender17592_
_hd1756017587_))
(if (gx#stx-pair?
_tl1756117589_)
(let ((_e1756217594_
(gx#syntax-e
_tl1756117589_)))
(let ((_hd1756317597_
;;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
(##car _e1756217594_))
(_tl1756417599_ (##cdr _e1756217594_)))
(let ((_body17602_ _hd1756317597_))
(if (gx#stx-null? _tl1756417599_)
(if '#t
(_generate117545_
_hd17582_
_fender17592_
_body17602_)
(_E1755517570_))
(_E1755517570_)))))
(_E1755517570_)))))
;;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
(_E1755517570_)))))
(_E1755517570_))))
(_E1754717628_
(lambda ()
(if (gx#stx-pair? _e1754617566_)
(let ((_e1754917608_
(gx#syntax-e _e1754617566_)))
(let ((_hd1755017611_
(##car _e1754917608_))
(_tl1755117613_
(##cdr _e1754917608_)))
(let ((_hd17616_ _hd1755017611_))
(if (gx#stx-pair? _tl1755117613_)
(let ((_e1755217618_
(gx#syntax-e
_tl1755117613_)))
(let ((_hd1755317621_
(##car _e1755217618_))
(_tl1755417623_
(##cdr _e1755217618_)))
(let ((_body17626_
_hd1755317621_))
(if (gx#stx-null?
_tl1755417623_)
(if '#t
(_generate117545_
_hd17616_
'#t
_body17626_)
(_E1754817604_))
(_E1754817604_)))))
(_E1754817604_)))))
(_E1754817604_)))))
(_E1754717628_)))))
(_generate-match17125_
(lambda (_where17289_
_target17290_
_hd17291_
_mvars17292_
_K17293_
_E17294_)
(letrec ((_BUG17296_
(lambda (_q17538_)
(error '"BUG: syntax-case; generate"
_stx17117_
_hd17291_
_q17538_)))
(_recur17297_
(lambda (_e17388_
_vars17389_
_target17390_
_E17391_
_k17392_)
(let* ((_e1739317400_ _e17388_)
(_E1739517404_
(lambda ()
(error '"No clause matching"
_e1739317400_)))
(_K1739617526_
(lambda (_body17407_ _tag17408_)
(let ((_$e17410_ _tag17408_))
(if (eq? 'any _$e17410_)
(_k17392_ _vars17389_)
(if (eq? 'id _$e17410_)
(gx#core-list
'if
(gx#core-list
'identifier?
_target17390_)
(gx#core-list
'if
(gx#core-list
_identifier=?17118_
(gx#core-list
_wrap-e17120_
_body17407_)
_target17390_)
(_k17392_ _vars17389_)
_E17391_)
_E17391_)
(if (eq? 'var _$e17410_)
(_k17392_
(cons (cons _body17407_
;;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
_target17390_)
_vars17389_))
(if (eq? 'cons _$e17410_)
(let ((_$e17413_ (gx#genident__1 'e))
(_$hd17414_ (gx#genident__1 'hd))
(_$tl17415_ (gx#genident__1 'tl)))
(gx#core-list
'if
(gx#core-list 'stx-pair? _target17390_)
(gx#core-list
'let-values
(cons (cons (cons _$e17413_ '())
(cons (gx#core-list
_unwrap-e17119_
_target17390_)
'()))
'())
(gx#core-list
'let-values
(cons (cons (cons _$hd17414_ '())
(cons (gx#core-list '##car _$e17413_)
'()))
(cons (cons (cons _$tl17415_ '())
(cons (gx#core-list
'##cdr
_$e17413_)
'()))
'()))
(let* ((_body1741617423_ _body17407_)
(_E1741817427_
(lambda ()
(error '"No clause matching"
_body1741617423_)))
(_K1741917435_
(lambda (_tl17430_ _hd17431_)
(_recur17297_
_hd17431_
_vars17389_
_$hd17414_
_E17391_
(lambda (_vars17433_)
(_recur17297_
_tl17430_
_vars17433_
_$tl17415_
_E17391_
_k17392_))))))
(if (##pair? _body1741617423_)
(let ((_hd1742017438_ (##car _body1741617423_))
(_tl1742117440_ (##cdr _body1741617423_)))
(let* ((_hd17443_ _hd1742017438_)
(_tl17445_ _tl1742117440_))
(_K1741917435_ _tl17445_ _hd17443_)))
(_E1741817427_)))))
_E17391_))
(if (eq? 'splice _$e17410_)
(let* ((_body1744617453_ _body17407_)
(_E1744817457_
(lambda ()
(error '"No clause matching"
_body1744617453_)))
(_K1744917508_
(lambda (_tl17460_ _hd17461_)
(let* ((_rlen17463_
(_splice-rlen17298_ _tl17460_))
(_$target17465_
(gx#genident__1 'target))
(_$hd17467_ (gx#genident__1 'hd))
(_$tl17469_ (gx#genident__1 'tl))
(_$lp17471_ (gx#genident__1 'loop))
(_$lp-e17473_ (gx#genident__1 'e))
(_$lp-hd17475_
(gx#genident__1 'lp-hd))
(_$lp-tl17477_
(gx#genident__1 'lp-tl))
(_svars17479_
(_splice-vars17299_ _hd17461_))
(_lvars17481_
(gx#gentemps _svars17479_))
(_tlvars17483_
(gx#gentemps _svars17479_))
(_linit17487_
(map (lambda (_var17485_)
(gx#core-list 'quote '()))
_lvars17481_)))
(letrec ((_make-loop17490_
(lambda (_vars17494_)
(gx#core-list
'letrec-values
(cons (cons (cons _$lp17471_
;;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
'())
(cons (gx#core-list
'lambda%
(cons _$hd17467_ _lvars17481_)
(gx#core-list
'if
(gx#core-list 'stx-pair? _$hd17467_)
(gx#core-list
'let-values
(cons (cons (cons _$lp-e17473_ '())
(cons (gx#core-list
_unwrap-e17119_
_$hd17467_)
'()))
'())
(gx#core-list
'let-values
(cons (cons (cons _$lp-hd17475_ '())
(cons (gx#core-list
'##car
_$lp-e17473_)
'()))
(cons (cons (cons _$lp-tl17477_ '())
(cons (gx#core-list
'##cdr
_$lp-e17473_)
'()))
'()))
(_recur17297_
_hd17461_
'()
_$lp-hd17475_
_E17391_
(lambda (_hdvars17496_)
(cons _$lp17471_
(cons _$lp-tl17477_
(map (lambda (_svar17498_
_lvar17499_)
(gx#core-list
'cons
(assgetq _svar17498_
_hdvars17496_
_BUG17296_)
_lvar17499_))
_svars17479_
_lvars17481_)))))))
(gx#core-list
'let-values
(map (lambda (_lvar17501_ _tlvar17502_)
(cons (cons _tlvar17502_ '())
(cons (gx#core-list
'reverse
_lvar17501_)
'())))
_lvars17481_
_tlvars17483_)
(_k17392_
(foldl2 (lambda (_svar17504_
_tlvar17505_
_r17506_)
(cons (cons _svar17504_ _tlvar17505_)
_r17506_))
_vars17494_
_svars17479_
_tlvars17483_)))))
'()))
'())
;;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
(cons _$lp17471_
(cons _$target17465_
_linit17487_))))))
(let ((_body17492_
(gx#core-list
'let-values
(cons (cons (cons _$target17465_
(cons _$tl17469_
;;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
'()))
(cons (gx#core-list
'syntax-split-splice
_target17390_
_rlen17463_)
'()))
;;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
'())
(_recur17297_
_tl17460_
_vars17389_
_$tl17469_
_E17391_
_make-loop17490_))))
(gx#core-list
'if
(gx#core-list
'stx-pair/null?
_target17390_)
(if (zero? _rlen17463_)
_body17492_
(gx#core-list
'if
(gx#core-list
'fx>=
(gx#core-list
'stx-length
_target17390_)
_rlen17463_)
_body17492_
_E17391_))
_E17391_)))))))
(if (##pair? _body1744617453_)
(let ((_hd1745017511_ (##car _body1744617453_))
(_tl1745117513_ (##cdr _body1744617453_)))
(let* ((_hd17516_ _hd1745017511_)
(_tl17518_ _tl1745117513_))
(_K1744917508_ _tl17518_ _hd17516_)))
(_E1744817457_)))
(if (eq? 'null _$e17410_)
(gx#core-list
'if
(gx#core-list 'stx-null? _target17390_)
(_k17392_ _vars17389_)
_E17391_)
(if (eq? 'vector _$e17410_)
(let ((_$e17520_ (gx#genident__1 'e)))
(gx#core-list
'if
(gx#core-list 'stx-vector? _target17390_)
(gx#core-list
'let-values
(cons (cons (cons _$e17520_ '())
(cons (gx#core-list
'vector->list
(gx#core-list
_unwrap-e17119_
_target17390_))
'()))
'())
(_recur17297_
_body17407_
_vars17389_
_$e17520_
_E17391_
_k17392_))
_E17391_))
(if (eq? 'box _$e17410_)
(let ((_$e17522_ (gx#genident__1 'e)))
(gx#core-list
'if
(gx#core-list 'stx-box? _target17390_)
(gx#core-list
'let-values
(cons (cons (cons _$e17522_ '())
(cons (gx#core-list
'unbox
(gx#core-list
_unwrap-e17119_
_target17390_))
'()))
'())
(_recur17297_
_body17407_
_vars17389_
_$e17522_
_E17391_
_k17392_))
_E17391_))
(if (eq? 'datum _$e17410_)
(let ((_$e17524_ (gx#genident__1 'e)))
(gx#core-list
'if
(gx#core-list
'stx-datum?
_target17390_)
(gx#core-list
'let-values
(cons (cons (cons _$e17524_ '())
(cons (gx#core-list
'stx-e
_target17390_)
'()))
'())
(gx#core-list
'if
(gx#core-list
'equal?
_$e17524_
_body17407_)
(_k17392_ _vars17389_)
_E17391_))
_E17391_))
(_BUG17296_ _e17388_))))))))))))))
;;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
(if (##pair? _e1739317400_)
(let ((_hd1739717529_
(##car _e1739317400_))
(_tl1739817531_
(##cdr _e1739317400_)))
(let* ((_tag17534_ _hd1739717529_)
(_body17536_ _tl1739817531_))
(_K1739617526_
_body17536_
_tag17534_)))
(_E1739517404_)))))
(_splice-rlen17298_
(lambda (_e17350_)
(let _lp17352_ ((_e17354_ _e17350_)
(_n17355_ '0))
(let* ((_e1735617363_ _e17354_)
(_E1735817367_
(lambda ()
(error '"No clause matching"
_e1735617363_)))
(_K1735917376_
(lambda (_body17370_ _tag17371_)
(let ((_$e17373_ _tag17371_))
(if (eq? 'splice _$e17373_)
(gx#raise-syntax-error
'#f
'"Ambiguous pattern"
_stx17117_
_where17289_)
(if (eq? 'cons _$e17373_)
(_lp17352_
(cdr _body17370_)
(fx+ _n17355_ '1))
_n17355_))))))
(if (##pair? _e1735617363_)
(let ((_hd1736017379_
(##car _e1735617363_))
(_tl1736117381_
(##cdr _e1735617363_)))
(let* ((_tag17384_ _hd1736017379_)
(_body17386_ _tl1736117381_))
(_K1735917376_
_body17386_
_tag17384_)))
(_E1735817367_))))))
(_splice-vars17299_
(lambda (_e17306_)
(let _recur17308_ ((_e17310_ _e17306_)
(_vars17311_ '()))
(let* ((_e1731217319_ _e17310_)
(_E1731417323_
(lambda ()
(error '"No clause matching"
_e1731217319_)))
(_K1731517338_
(lambda (_body17326_ _tag17327_)
(let ((_$e17329_ _tag17327_))
(if (eq? 'var _$e17329_)
(cons _body17326_
_vars17311_)
(if (let ((_$e17332_
(eq? 'cons
;;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
_$e17329_)))
(if _$e17332_ _$e17332_ (eq? 'splice _$e17329_)))
(_recur17308_
(cdr _body17326_)
(_recur17308_ (car _body17326_) _vars17311_))
(if (let ((_$e17335_ (eq? 'vector _$e17329_)))
(if _$e17335_ _$e17335_ (eq? 'box _$e17329_)))
(_recur17308_ _body17326_ _vars17311_)
_vars17311_)))))))
;;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
(if (##pair? _e1731217319_)
(let ((_hd1731617341_
(##car _e1731217319_))
(_tl1731717343_
(##cdr _e1731217319_)))
(let* ((_tag17346_ _hd1731617341_)
(_body17348_ _tl1731717343_))
(_K1731517338_
_body17348_
_tag17346_)))
(_E1731417323_))))))
(_make-body17300_
(lambda (_vars17302_)
(cons _K17293_
(map (lambda (_mvar17304_)
(assgetq (car _mvar17304_)
_vars17302_
_BUG17296_))
_mvars17292_)))))
(_recur17297_
_hd17291_
'()
_target17290_
_E17294_
_make-body17300_))))
(_parse-clause17126_
(lambda (_hd17195_ _ids17196_)
(let _recur17198_ ((_e17200_ _hd17195_)
(_vars17201_ '())
(_depth17202_ '0))
(if (gx#identifier? _e17200_)
(if (gx#underscore? _e17200_)
(values '(any) _vars17201_)
(if (gx#ellipsis? _e17200_)
(gx#raise-syntax-error
'#f
'"Misplaced ellipsis"
_stx17117_
_hd17195_)
(if (find (lambda (_id17204_)
(gx#bound-identifier=?
_e17200_
_id17204_))
_ids17196_)
(values (cons 'id _e17200_) _vars17201_)
(if (find (lambda (_var17206_)
(gx#bound-identifier=?
_e17200_
(car _var17206_)))
_vars17201_)
(gx#raise-syntax-error
'#f
'"Duplicate pattern variable"
_stx17117_
_e17200_)
(values (cons 'var _e17200_)
(cons (cons _e17200_
_depth17202_)
_vars17201_))))))
(if (gx#stx-pair? _e17200_)
(let* ((_e1720717214_ _e17200_)
(_E1720917218_
(lambda ()
(gx#raise-syntax-error
'#f
'"Bad syntax"
_e1720717214_)))
(_E1720817279_
(lambda ()
(if (gx#stx-pair? _e1720717214_)
(let ((_e1721017222_
(gx#syntax-e
_e1720717214_)))
(let ((_hd1721117225_
(##car _e1721017222_))
(_tl1721217227_
(##cdr _e1721017222_)))
(let* ((_hd17230_
_hd1721117225_)
(_rest17232_
_tl1721217227_))
(if '#t
(let* ((_make-pair17247_
(lambda (_tag17234_
;;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
_hd17235_
_tl17236_)
(let* ((_hd-depth17238_
(if (eq? _tag17234_ 'splice)
(fx+ _depth17202_ '1)
_depth17202_))
(_g18392_
(_recur17198_
_hd17235_
_vars17201_
_hd-depth17238_)))
(begin
(let ((_g18393_
(if (##values? _g18392_)
(##vector-length _g18392_)
1)))
(if (not (##fx= _g18393_ 2))
(error "Context expects 2 values" _g18393_)))
(let ((_hd17240_ (##vector-ref _g18392_ 0))
(_vars17241_ (##vector-ref _g18392_ 1)))
(let ((_g18394_
(_recur17198_
_tl17236_
_vars17241_
_depth17202_)))
(begin
(let ((_g18395_
(if (##values? _g18394_)
(##vector-length _g18394_)
1)))
(if (not (##fx= _g18395_ 2))
(error "Context expects 2 values"
_g18395_)))
(let ((_tl17243_ (##vector-ref _g18394_ 0))
(_vars17244_
(##vector-ref _g18394_ 1)))
(let ()
(values (cons _tag17234_
(cons _hd17240_ _tl17243_))
_vars17244_))))))))))
(_e1724817255_ _rest17232_)
(_E1725017259_
(lambda ()
(_make-pair17247_ 'cons _hd17230_ _rest17232_)))
(_E1724917275_
(lambda ()
(if (gx#stx-pair? _e1724817255_)
(let ((_e1725117263_ (gx#syntax-e _e1724817255_)))
(let ((_hd1725217266_ (##car _e1725117263_))
(_tl1725317268_ (##cdr _e1725117263_)))
(let* ((_rest-hd17271_ _hd1725217266_)
(_rest-tl17273_ _tl1725317268_))
(if '#t
(if (gx#ellipsis? _rest-hd17271_)
(_make-pair17247_
'splice
_hd17230_
_rest-tl17273_)
(_make-pair17247_
'cons
_hd17230_
_rest17232_))
(_E1725017259_)))))
(_E1725017259_)))))
(_E1724917275_))
(_E1720917218_)))))
;;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
(_E1720917218_)))))
(_E1720817279_))
(if (gx#stx-null? _e17200_)
(values '(null) _vars17201_)
(if (gx#stx-vector? _e17200_)
(let ((_g18396_
(_recur17198_
(vector->list
(gx#syntax-e _e17200_))
_vars17201_
_depth17202_)))
(begin
(let ((_g18397_
(if (##values? _g18396_)
(##vector-length _g18396_)
1)))
(if (not (##fx= _g18397_ 2))
(error "Context expects 2 values"
_g18397_)))
(let ((_e17283_
(##vector-ref _g18396_ 0))
(_vars17284_
(##vector-ref _g18396_ 1)))
(values (cons 'vector _e17283_)
_vars17284_))))
(if (gx#stx-box? _e17200_)
(let ((_g18398_
(_recur17198_
(unbox (gx#syntax-e
_e17200_))
_vars17201_
_depth17202_)))
(begin
(let ((_g18399_
(if (##values? _g18398_)
(##vector-length
_g18398_)
1)))
(if (not (##fx= _g18399_ 2))
(error "Context expects 2 values"
_g18399_)))
(let ((_e17286_
(##vector-ref _g18398_ 0))
(_vars17287_
(##vector-ref
_g18398_
1)))
(values (cons 'box _e17286_)
_vars17287_))))
(if (gx#stx-datum? _e17200_)
(values (cons 'datum
(gx#stx-e
_e17200_))
_vars17201_)
(gx#raise-syntax-error
'#f
'"Bad pattern"
_stx17117_
_e17200_)))))))))))
(let* ((_e1712717140_ _stx17117_)
(_E1712917144_
(lambda ()
(gx#raise-syntax-error '#f '"Bad syntax" _e1712717140_)))
(_E1712817191_
(lambda ()
(if (gx#stx-pair? _e1712717140_)
(let ((_e1713017148_ (gx#syntax-e _e1712717140_)))
(let ((_hd1713117151_ (##car _e1713017148_))
(_tl1713217153_ (##cdr _e1713017148_)))
(if (gx#stx-pair? _tl1713217153_)
(let ((_e1713317156_
(gx#syntax-e _tl1713217153_)))
(let ((_hd1713417159_ (##car _e1713317156_))
(_tl1713517161_ (##cdr _e1713317156_)))
(let ((_expr17164_ _hd1713417159_))
(if (gx#stx-pair? _tl1713517161_)
(let ((_e1713617166_
(gx#syntax-e _tl1713517161_)))
(let ((_hd1713717169_
(##car _e1713617166_))
(_tl1713817171_
(##cdr _e1713617166_)))
(let* ((_ids17174_
_hd1713717169_)
(_clauses17176_
_tl1713817171_))
(if '#t
(if (not (gx#identifier-list?
_ids17174_))
(gx#raise-syntax-error
'#f
'"Bad template identifier list"
_stx17117_
_ids17174_)
(if (not (gx#stx-list?
;;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
_clauses17176_))
(gx#raise-syntax-error '#f '"Bad syntax" _stx17117_)
(let* ((_ids17178_ (gx#syntax->list _ids17174_))
(_clauses17180_ (gx#syntax->list _clauses17176_))
(_clause-ids17182_ (gx#gentemps _clauses17180_))
(_E17184_ (gx#genident__0))
(_target17186_ (gx#genident__0))
(_first17188_
(if (null? _clauses17180_)
_E17184_
(car _clause-ids17182_))))
(gx#stx-wrap-source
(gx#core-list
'begin-annotation
'@syntax-case
(gx#stx-wrap-source
(gx#core-list
'let-values
(cons (cons (cons _E17184_ '())
(cons (gx#core-list
'lambda%
(cons _target17186_ '())
(gx#core-list
'raise-syntax-error
'#f
'"Bad syntax"
_target17186_))
'()))
'())
(_generate-body17123_
(_generate-bindings17122_
_target17186_
_ids17178_
_clauses17180_
_clause-ids17182_
_E17184_)
(cons _first17188_ (cons _expr17164_ '()))))
(gx#stx-source _stx17117_)))
(gx#stx-source _stx17117_)))))
;;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
(_E1712917144_)))))
(_E1712917144_)))))
(_E1712917144_))))
(_E1712917144_)))))
(_E1712817191_)))))
(begin
(define gx#macro-expand-syntax-case__0
(lambda (_stx17827_)
(let* ((_identifier=?17829_ 'free-identifier=?)
(_unwrap-e17831_ 'syntax-e)
(_wrap-e17833_ 'quote-syntax))
(gx#macro-expand-syntax-case__%
_stx17827_
_identifier=?17829_
_unwrap-e17831_
_wrap-e17833_))))
(define gx#macro-expand-syntax-case__1
(lambda (_stx17835_ _identifier=?17836_)
(let* ((_unwrap-e17838_ 'syntax-e) (_wrap-e17840_ 'quote-syntax))
(gx#macro-expand-syntax-case__%
_stx17835_
_identifier=?17836_
_unwrap-e17838_
_wrap-e17840_))))
(define gx#macro-expand-syntax-case__2
(lambda (_stx17842_ _identifier=?17843_ _unwrap-e17844_)
(let ((_wrap-e17846_ 'quote-syntax))
(gx#macro-expand-syntax-case__%
_stx17842_
_identifier=?17843_
_unwrap-e17844_
_wrap-e17846_))))
(define gx#macro-expand-syntax-case
(lambda _g18401_
(let ((_g18400_ (length _g18401_)))
(cond ((##fx= _g18400_ 1)
(apply gx#macro-expand-syntax-case__0 _g18401_))
((##fx= _g18400_ 2)
(apply gx#macro-expand-syntax-case__1 _g18401_))
((##fx= _g18400_ 3)
(apply gx#macro-expand-syntax-case__2 _g18401_))
((##fx= _g18400_ 4)
(apply gx#macro-expand-syntax-case__% _g18401_))
(else
(##raise-wrong-number-of-arguments-exception
gx#macro-expand-syntax-case
_g18401_))))))))
(define gx#syntax-local-pattern?
(lambda (_stx17114_)
(if (gx#identifier? _stx17114_)
(##structure-instance-of?
(gx#syntax-local-e__% _stx17114_ false)
'gx#syntax-pattern::t)
'#f)))
(define gx#syntax-check-splice-targets
(lambda (_hd17072_ . _rest17073_)
(let ((_len17075_ (length _hd17072_)))
(let _lp17077_ ((_rest17079_ _rest17073_))
(let* ((_rest1708017088_ _rest17079_)
(_else1708217096_ (lambda () '#!void))
(_K1708417102_
(lambda (_rest17099_ _hd17100_)
(if (fx= _len17075_ (length _hd17100_))
(_lp17077_ _rest17099_)
(gx#raise-syntax-error
'#f
'"Splice length mismatch"
_hd17100_)))))
(if (##pair? _rest1708017088_)
(let ((_hd1708517105_ (##car _rest1708017088_))
(_tl1708617107_ (##cdr _rest1708017088_)))
(let* ((_hd17110_ _hd1708517105_)
(_rest17112_ _tl1708617107_))
(_K1708417102_ _rest17112_ _hd17110_)))
(_else1708217096_)))))))
(define gx#syntax-split-splice
(lambda (_stx17030_ _n17031_)
(let _lp17033_ ((_rest17035_ _stx17030_) (_r17036_ '()))
(if (gx#stx-pair? _rest17035_)
(let* ((_g1703717044_ (gx#syntax-e _rest17035_))
(_E1703917048_
(lambda () (error '"No clause matching" _g1703717044_)))
(_K1704017054_
(lambda (_rest17051_ _hd17052_)
(_lp17033_ _rest17051_ (cons _hd17052_ _r17036_)))))
(if (##pair? _g1703717044_)
(let ((_hd1704117057_ (##car _g1703717044_))
(_tl1704217059_ (##cdr _g1703717044_)))
(let* ((_hd17062_ _hd1704117057_)
(_rest17064_ _tl1704217059_))
(_K1704017054_ _rest17064_ _hd17062_)))
(_E1703917048_)))
(let _lp17066_ ((_n17068_ _n17031_)
(_l17069_ _r17036_)
(_r17070_ _rest17035_))
(if (null? _l17069_)
(values _l17069_ _r17070_)
(if (fxpositive? _n17068_)
(_lp17066_
(fx- _n17068_ '1)
(cdr _l17069_)
(cons (car _l17069_) _r17070_))
(values (reverse _l17069_) _r17070_)))))))))
| false |
1ce6e1aeb49a1681a1cd37c21b905c6f079d4d3b
|
ab2b756cdeb5aa94b8586eeb8dd5948b7f0bba27
|
/old/lisp/first.scm
|
072abc8e804967f3b465bf05cad41ab4101d6505
|
[] |
no_license
|
stjordanis/chalang
|
48ff69d8bc31da1696eae043e66c628f41035b5a
|
a728e6bb9a60ac6eca189ee7d6873a891825fa9a
|
refs/heads/master
| 2021-07-31T22:26:45.299432 | 2021-03-09T13:06:56 | 2021-03-09T13:06:56 | 142,876,387 | 0 | 0 | null | 2018-07-30T13:03:00 | 2018-07-30T13:03:00 | null |
UTF-8
|
Scheme
| false | false | 85 |
scm
|
first.scm
|
(define Square (x) (* x x))
(define double (x) (+ x x))
(= (Square (double 5)) 100)
| false |
aa70410f757fd2f91fff6afe60397b2756d0a56f
|
ce567bbf766df9d98dc6a5e710a77870753c7d29
|
/base/chapter5/test-all.scm
|
56d43e60b73b7daad99af1a51922a1f25aad7af4
|
[] |
no_license
|
dott94/eopl
|
1cbe2d98c948689687f88e514579e66412236fc9
|
47fadf6f2aa6ca72c831d6e2e2eccbe673129113
|
refs/heads/master
| 2021-01-18T06:42:35.921839 | 2015-01-21T07:06:43 | 2015-01-21T07:06:43 | 30,055,972 | 1 | 0 | null | 2015-01-30T04:21:42 | 2015-01-30T04:21:42 | null |
UTF-8
|
Scheme
| false | false | 268 |
scm
|
test-all.scm
|
(module test-all scheme
;; loads each of the languages in this chapter and tests them.
; (require (prefix-in letrec "./letrec-lang/top.scm"))
(require (prefix-in letrec- "letrec-lang/top.scm"))
; (letrec-stop-after-first-error #t)
(letrec-run-all)
)
| false |
275bf5d1b39e18a58d9ddfc60e6fd50e569cb19d
|
63a1f38e64b0604377fbfa0d10d48545c609cc86
|
/icfp09-m/sl-tests.ss
|
9ff95af8a6d64cf4a9827d442aaf40ea200fdafb
|
[] |
no_license
|
jeapostrophe/redex
|
d02b96b441f27e3afa1ef92726741ec026160944
|
8e5810e452878a4ab5153d19725cfc4cf2b0bf46
|
refs/heads/master
| 2016-09-06T00:55:02.265152 | 2013-10-31T01:24:11 | 2013-10-31T01:24:11 | 618,062 | 2 | 1 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 6,742 |
ss
|
sl-tests.ss
|
#lang scheme
(require redex
scheme/package
"sl.ss"
"common.ss")
;; Tests
;;; Values
(test-->> -->_sl
'(/ mt (λ (x) x))
'(/ mt (λ (x) x)))
(test-->> -->_sl
'(/ mt ("nil"))
'(/ mt ("nil")))
(test-->> -->_sl
'(/ mt ("S" ("0")))
'(/ mt ("S" ("0"))))
(test-->> -->_sl
'(/ mt (! "x"))
'(/ mt (! "x")))
;;; Applications
(test-->> -->_sl
'(/ mt ((λ (x) x) ("nil")))
'(/ mt ("nil")))
;;; Store applications
(test-->> -->_sl
'(/ (snoc mt ["x" -> (λ (x) ("nil"))])
((! "x") ("0")))
'(/ (snoc mt ["x" -> (λ (x) ("nil"))])
("nil")))
;;; Letrec
(test-->> -->_sl
'(/ mt (letrec (["x" (λ (x) ("nil"))])
("foo")))
'(/ (snoc mt ["x" -> (λ (x) ("nil"))])
("foo")))
(test-->> -->_sl
'(/ mt (letrec (["x" (λ (x) ("nil"))])
((! "x") ("0"))))
'(/ (snoc mt ["x" -> (λ (x) ("nil"))])
("nil")))
;;; match
(test-->> -->_sl
'(/ mt (match ("S" ("0"))
[("S" n) => n]
[("0") => ("0")]))
'(/ mt ("0")))
(test-->> -->_sl
'(/ mt (match ("S" ("0"))
[("0") => ("0")]
[("S" n) => n]))
'(/ mt ("0")))
; Store match
(test-->> -->_sl
'(/ mt (letrec (["x" ("S" ("0"))])
(match (! "x")
[("S" n) => n]
[("0") => ("0")])))
'(/ (snoc mt ["x" -> ("S" ("0"))])
("0")))
;; wcm
(test-->> -->_sl
`(/ mt (wcm ([("k") ,(num 1)]) ,(num 2)))
`(/ mt ,(num 2)))
(test-->> -->_sl
`(/ mt (wcm ([("k") ,(num 1)]) (wcm ([("k") ,(num 3)]) ,(num 2))))
`(/ mt ,(num 2)))
(test-->> -->_sl
`(/ mt (wcm ([("k") ,(num 1)]) ((λ (x) x) ,(num 2))))
`(/ mt ,(num 2)))
;; c-c-m
(test-->> -->_sl
`(/ mt (c-c-m ("k")))
`(/ mt ("nil")))
(test-->> -->_sl
`(/ mt (wcm ([("k") ,(num 1)]) (c-c-m ("k"))))
`(/ mt ("cons" ("marks" ("some" ,(num 1))) ("nil"))))
(test-->> -->_sl
`(/ mt (wcm ([("k") ,(num 1)]) (wcm ([("k") ,(num 2)]) (c-c-m ("k")))))
`(/ mt ("cons" ("marks" ("some" ,(num 2))) ("nil"))))
(test-->> -->_sl
`(/ mt (wcm ([("k") ,(num 1)]) ((λ (x) x) (wcm ([("k") ,(num 2)]) (c-c-m ("k"))))))
`(/ mt ("cons" ("marks" ("some" ,(num 1))) ("cons" ("marks" ("some" ,(num 2))) ("nil")))))
(test-->> -->_sl
`(/ mt (wcm ([("k1") ,(num 1)]) (c-c-m ("k1") ("k2"))))
`(/ mt ("cons" ("marks" ("some" ,(num 1)) ("none")) ("nil"))))
(test-->> -->_sl
`(/ mt (wcm ([("k1") ,(num 1)]) (wcm ([("k2") ,(num 2)]) (c-c-m ("k1") ("k2")))))
`(/ mt ("cons" ("marks" ("some" ,(num 1)) ("some" ,(num 2))) ("nil"))))
;; abort
(test-->> -->_sl
`(/ mt (abort ,(num 2)))
`(/ mt ,(num 2)))
(test-->> -->_sl
`(/ mt ((λ (x) x) (abort ,(num 2))))
`(/ mt ,(num 2)))
;; arith
(test-->> -->_sl
`(/ mt ,(:let 'x (num 1) 'x))
`(/ mt ,(num 1)))
(test-->> -->_sl
`(/ mt ,(with-arith (num 1)))
`(/ ,arith-store ,(num 1)))
(test-->> -->_sl
`(/ mt ,(with-arith `((! "+") ,(num 1) ,(num 1))))
`(/ ,arith-store ,(num 2)))
(test-->> -->_sl
`(/ mt ,(with-arith `((! "*") ,(num 2) ,(num 2))))
`(/ ,arith-store ,(num 4)))
(test-->> -->_sl
`(/ mt ,(with-arith `((! "=") ,(num 2) ,(num 2))))
`(/ ,arith-store ("#t")))
(test-->> -->_sl
`(/ mt ,(with-arith `((! "=") ,(num 2) ,(num 3))))
`(/ ,arith-store ("#f")))
(test-->> -->_sl
`(/ mt ,(with-arith `((! "-") ,(num 3) ,(num 2))))
`(/ ,arith-store ,(num 1)))
(test-->> -->_sl
`(/ mt ,(with-arith (:if '("#t") (num 1) (num 2))))
`(/ ,arith-store ,(num 1)))
(test-->> -->_sl
`(/ mt ,(with-arith (:if '("#f") (num 1) (num 2))))
`(/ ,arith-store ,(num 2)))
;; fact
(package-begin
(define fact-impl
`(λ (n)
,(:if `((! "=") n ,(num 0))
(:let 'marks '(c-c-m ("fact"))
'(abort marks))
`(wcm ([("fact") n])
,(:let 'sub1-fact
(:let 'sub1 `((! "-") n ,(num 1))
`((! "fact") sub1))
`((! "*") n sub1-fact))))))
(define fact-tr-impl
`(λ (n a)
,(:if `((! "=") n ,(num 0))
(:let 'marks '(c-c-m ("fact"))
'(abort marks))
`(wcm ([("fact") n])
,(:let 'sub1 `((! "-") n ,(num 1))
(:let 'multa `((! "*") n a)
`((! "fact-tr") sub1 multa)))))))
(define (test-fact n)
(test-->> -->_sl
`(/ mt ,(with-arith
`(letrec (["fact" ,fact-impl])
((! "fact") ,(num n)))))
`(/ (snoc ,arith-store ["fact" -> ,fact-impl])
,(lst (build-list n (lambda (i) (term ("marks" ("some" ,(num (- n i)))))))))))
(define (test-fact-tr n)
(test-->> -->_sl
`(/ mt ,(with-arith
`(letrec (["fact-tr" ,fact-tr-impl])
((! "fact-tr") ,(num n) ,(num 1)))))
`(/ (snoc ,arith-store ["fact-tr" -> ,fact-tr-impl])
,(lst (list (term ("marks" ("some" ,(num 1)))))))))
(for ([i (in-range 1 4)]) (test-fact i))
(for ([i (in-range 1 4)]) (test-fact-tr i)))
;; call/cc
(test-->> -->_sl
`(/ mt (call/cc (λ (k) (k ("v")))))
`(/ mt ("v")))
(test-->> -->_sl
`(/ mt (call/cc (λ (k)
((λ (x) ("x"))
(k ("v"))))))
`(/ mt ("v")))
;; call/cc + wcm
(test-->> -->_sl
`(/ mt (wcm ([("k") ("v1")])
((λ (f) (f ("unit")))
(call/cc (λ (k)
(wcm ([("k") ("v2")])
(k (λ (x) (c-c-m ("k"))))))))))
`(/ mt ("cons" ("marks" ("some" ("v1"))) ("nil"))))
(test-->> -->_sl
`(/ mt (wcm ([("k") ("v1")])
((λ (f) (f ("unit")))
(call/cc (λ (k)
(wcm ([("k") ("v2")])
((λ (cms)
(k (λ (x) cms)))
(c-c-m ("k")))))))))
`(/ mt ("cons" ("marks" ("some" ("v1"))) ("cons" ("marks" ("some" ("v2"))) ("nil")))))
(test-results)
| false |
ee5282b18222c3e3a7e1334ae32182f7925f012b
|
174072a16ff2cb2cd60a91153376eec6fe98e9d2
|
/Chap-Three/3-58.scm
|
ec5b4d64e64bfc9ccdcb91e3bad62129105deacb
|
[] |
no_license
|
Wang-Yann/sicp
|
0026d506ec192ac240c94a871e28ace7570b5196
|
245e48fc3ac7bfc00e586f4e928dd0d0c6c982ed
|
refs/heads/master
| 2021-01-01T03:50:36.708313 | 2016-10-11T10:46:37 | 2016-10-11T10:46:37 | 57,060,897 | 1 | 0 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 226 |
scm
|
3-58.scm
|
(define (expand num den radix)
(cons-stream (quotient (* num radix) den)
(expand (remainder (* num radix) den) den radix)))
(define a (expand 1 7 10))
(define b (expand 3 8 10))
;(display-stream (stream-section a 0 10))
| false |
7a04c8c8efb2d60cc283a65d2774e4961925be23
|
b43e36967e36167adcb4cc94f2f8adfb7281dbf1
|
/sicp/ch1/exercises/1.33.scm
|
8deb3f1f066d4ab5aa917907e9707bc92e3b03ae
|
[] |
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 | 1,126 |
scm
|
1.33.scm
|
(define (filtered-accumulate combiner null-value term a next b predicate?)
(if (> a b)
null-value
(if (predicate? a)
(combiner (term a)
(filtered-accumulate combiner null-value term (next a) next b predicate?))
(filtered-accumulate combiner null-value term (next a) next b predicate?))))
(define (filtered-accumulate-iter combiner null-value term a next b predicate?)
(define (iter a result)
(if (> a b)
result
(if (predicate? a)
(iter (next a)
(combiner (term a)
result))
(iter (next a)
result))))
(iter a null-value))
(filtered-accumulate +
0
(lambda (x) x)
1
(lambda (x) (+ 1 x))
100
prime?)
(filtered-accumulate-iter +
0
(lambda (x) x)
1
(lambda (x) (+ 1 x))
100
prime?)
| false |
1365060ed71f57a4403b9dd6659eabd189743592
|
b9eb119317d72a6742dce6db5be8c1f78c7275ad
|
/random-scheme-stuff/filenames.scm
|
808712203eb1bad3ef99b9679e5104bc62fd6f1e
|
[] |
no_license
|
offby1/doodles
|
be811b1004b262f69365d645a9ae837d87d7f707
|
316c4a0dedb8e4fde2da351a8de98a5725367901
|
refs/heads/master
| 2023-02-21T05:07:52.295903 | 2022-05-15T18:08:58 | 2022-05-15T18:08:58 | 512,608 | 2 | 1 | null | 2023-02-14T22:19:40 | 2010-02-11T04:24:52 |
Scheme
|
UTF-8
|
Scheme
| false | false | 952 |
scm
|
filenames.scm
|
(define (sansextension input-file-name)
(let* ((file-name-non-directory-regexp (make-regexp "[^/]+\\.[a-zA-Z]+$" regexp/extended))
(sansdirectory (match:substring
(regexp-exec file-name-non-directory-regexp input-file-name)))
(file-name-non-extension-regexp (make-regexp "^[^.]+")))
(match:substring (regexp-exec file-name-non-extension-regexp sansdirectory))
))
(define (nuke-shell-specials filename)
(define (maybe-transform ch)
(if (memq ch '(#\space #\tab #\| #\& #\; #\< #\> #\( #\) #\' #\$))
#\_
ch))
(let ((result (make-string (string-length filename))))
(let loop ((chars-processed 0))
(if (= chars-processed (string-length filename))
result
(let ((this-char (string-ref filename chars-processed)))
(string-set! result chars-processed (maybe-transform this-char))
(loop (+ 1 chars-processed)))))))
(provide 'filenames)
| false |
287309af2e436551c36251d9c2f6bfd7c7628742
|
784dc416df1855cfc41e9efb69637c19a08dca68
|
/src/gerbil/compiler/base.ss
|
65671571e2994a313a6021134ec21e9296203595
|
[
"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 | 2,530 |
ss
|
base.ss
|
;;; -*- Gerbil -*-
;;; (C) vyzo at hackzen.org
;;; gerbil compiler basic env
package: gerbil/compiler
namespace: gxc
(import :gerbil/expander
<syntax-case>)
(export #t)
(defsyntax (ast-case stx)
(macro-expand-syntax-case stx 'stx-eq? 'stx-e 'quote))
(defsyntax (ast-rules stx)
(syntax-case stx ()
((_ ids clause ...)
(identifier-list? #'ids)
(with-syntax (((clause ...)
(stx-map (lambda (clause)
(syntax-case clause ()
((hd body)
#'(hd (syntax body)))
((hd fender body)
#'(hd fender (syntax body)))))
#'(clause ...))))
#'(lambda ($stx)
(ast-case $stx ids clause ...))))))
(def current-compile-symbol-table
(make-parameter #f))
(def current-compile-runtime-sections
(make-parameter #f))
(def current-compile-runtime-names
(make-parameter #f))
(def current-compile-output-dir
(make-parameter #f))
(def current-compile-invoke-gsc
(make-parameter #f))
(def current-compile-gsc-options
(make-parameter #f))
(def current-compile-keep-scm
(make-parameter #f))
(def current-compile-verbose
(make-parameter #f))
(def current-compile-optimize
(make-parameter #f))
(def current-compile-debug
(make-parameter #f))
(def current-compile-generate-ssxi
(make-parameter #f))
(def current-compile-static
(make-parameter #f))
(def current-compile-timestamp
(make-parameter #f))
(defstruct symbol-table (gensyms bindings)
id: gxc#symbol-table::t
constructor: :init!)
(defmethod {:init! symbol-table}
(lambda (self)
(struct-instance-init! self (make-hash-table-eq) (make-hash-table-eq))))
(def (raise-compile-error message stx . details)
(apply raise-syntax-error 'compile message stx details))
(def (verbose . args)
(when (current-compile-verbose)
(apply displayln args)))
;; these characters are restricted to avoid confusing shells and other tools
(def module-path-reserved-chars
":#<>&!?*;()[]{}|'`\"\\")
(def (module-id->path-string id)
(let* ((str (if (symbol? id) (symbol->string id) id))
(len (string-length str))
(res (make-string len)))
(let lp ((i 0))
(if (fx< i len)
(let* ((char (string-ref str i))
(xchar (if (string-index module-path-reserved-chars char)
#\_ char)))
(string-set! res i xchar)
(lp (fx1+ i)))
res))))
| false |
3238c03e51ffdd5fdcee984931aaa1c7533cdbf8
|
defeada37d39bca09ef76f66f38683754c0a6aa0
|
/mscorlib/system/threading/timeout.sls
|
4fdc60e17b54eeea4550c068e7bada2552cb1258
|
[] |
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 | 340 |
sls
|
timeout.sls
|
(library (system threading timeout)
(export is? timeout? infinite)
(import (ironscheme-clr-port))
(define (is? a) (clr-is System.Threading.Timeout a))
(define (timeout? a) (clr-is System.Threading.Timeout a))
(define-field-port
infinite
#f
#f
(static:)
System.Threading.Timeout
Infinite
System.Int32))
| false |
c3aa2a5e50dc2fe580fb1b5bdc485d59f6046077
|
018a7ce673c5be3cf3df61bd5c5036581d6646a7
|
/src/Feersum.Core/base.sld
|
7592d2f3d25eec168dcb3c236f33434649049a21
|
[
"MIT"
] |
permissive
|
iwillspeak/feersum
|
e857deec2b8683960f9ac6d1f395fb5f625204a8
|
1602e8333aa11c0335c9775c0ab49bf01389ba98
|
refs/heads/main
| 2023-08-07T17:15:19.843607 | 2023-06-20T06:28:28 | 2023-06-20T06:28:28 | 223,348,583 | 31 | 2 |
MIT
| 2023-06-10T21:29:11 | 2019-11-22T07:33:04 |
F#
|
UTF-8
|
Scheme
| false | false | 2,850 |
sld
|
base.sld
|
(define-library (scheme base)
;; Re-export Sherefa core items
(import (feersum serehfa arithmetics)
(feersum serehfa booleans)
(feersum serehfa core)
(feersum serehfa characters)
(feersum serehfa equivalence)
(feersum serehfa lists)
(feersum serehfa strings)
(feersum serehfa symbols)
(feersum serehfa read)
(feersum serehfa vectors)
(feersum serehfa bytevectors))
(begin
;;; List->vector conversion.
;;
;; Takes a scheme list and converts it into a sheme vector containing the
;; same elements in the same order. It is an error if the argument is not
;; a proper list.
(define (list->vector list)
(define (fill-rec vec offset list)
(if (null? list)
vec
(begin
(vector-set! vec offset (car list))
(fill-rec vec (+ 1 offset) (cdr list)))))
(fill-rec (make-vector (length list)) 0 list))
;;; Apply a function to arguments
;;
;; Taks a list of arguments and applies the given function with them. If
;; more than one argument is specified then they are combined as if by
;; `(append (list arg...argn) args)`. That is the final element must be
;; a list, and any other arguments are prepended to that in order.
(define (apply fun . args)
(define (flatten args)
(if (null? (cdr args))
(car args)
(cons (car args) (flatten (cdr args)))))
(core-apply-vec fun (list->vector (flatten args)))))
(export vector vector? vector-length vector-set! vector-ref make-vector
string=? string->number null? cons list make-list pair? list? car cdr
set-car! set-cdr! length symbol? symbol=? symbol->string string->symbol
eqv? eq? equal? bytevector? make-bytevector bytevector bytevector-length
bytevector-u8-set! bytevector-u8-ref not boolean? boolean=? zero? + - /
* = > < >= <= char? char=? char<? char>? char<=? char>=? char-ci=?
char-ci<? char-ci>? char-ci<=? char-ci>=? char-alphabetic? char-numeric?
char-whitespace? char-upper-case? char-lower-case? digit-value
char->integer integer->char char-upcase char-downcase char-foldcase
read-char peek-char read-line eof-object eof-object? char-ready?
read-string apply list->vector procedure?)
;; Re-export base items from other definitions in this assembly
(import (feersum core lists))
(export append reverse list-tail list-ref list-set! list-copy memq memv member
assv assq assoc)
;; Simple definitions
(export caar cadr cdar cddr)
(begin
(define (caar x) (car (car x)))
(define (cadr x) (car (cdr x)))
(define (cdar x) (cdr (car x)))
(define (cddr x) (cdr (cdr x)))))
| false |
213c3b8dd71001ffcba131be8f4790701a94b4a5
|
7e4eccee4ba976b6694cd944fea75e7835cd1a4b
|
/lua/lure/test2.sm
|
8fdebe0d921e624959fdbc4be562d75f9748e409
|
[
"CC0-1.0"
] |
permissive
|
zwizwa/uc_tools
|
fc16d39722d5f30164dad524cd86f1aec230f2f4
|
20df6f91a2082424b498e384583d7f403ff8bf16
|
refs/heads/master
| 2023-08-18T20:45:09.789340 | 2023-08-13T13:58:07 | 2023-08-13T13:58:07 | 54,667,633 | 6 | 0 |
NOASSERTION
| 2022-06-06T19:18:26 | 2016-03-24T19:11:14 |
C
|
UTF-8
|
Scheme
| false | false | 243 |
sm
|
test2.sm
|
#lang s-expr "sm.rkt" ;; -*- scheme -*-
(import lib)
(define (program)
(define (f a)
(yield a)
(g (add 1 a)))
(define (g a)
(f a))
f)
(define (start)
(let* ((t1 (make-task)))
(load-task! t1 (program))
(co t1 0)))
| false |
1194b0e90bb6df7a5debf1ada405534843d89192
|
6c6cf6e4b77640825c2457e54052a56d5de6f4d2
|
/ch2/2_69-generate-huffman-tree.scm
|
129acda1868ee843b01e11ae09d17d35cc41e875
|
[] |
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 | 364 |
scm
|
2_69-generate-huffman-tree.scm
|
;ex 2.69 generate-huffman-tree
(define (generate-huffman-tree pairs)
(successive-merge (make-leaf-set pairs)))
(define (successive-merge set)
(if (= 1 (length set))
(car set)
(let ((left (car set))
(right (cadr set))
(remaining-set (cddr set)))
(let ((node (make-code-tree left right)))
(successive-merge (adjoin-set node remaining-set))))))
| false |
095a3cd135ab6bce2ef479b935fbfc43adae5bd1
|
2e50e13dddf57917018ab042f3410a4256b02dcf
|
/t/override.scm
|
92d296f73bbe4beae9757c31be798b6970b0f608
|
[
"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 | 148 |
scm
|
override.scm
|
(import (picrin base)
(picrin test))
(test-begin)
(define orig-cons cons)
(set! symbol? list)
(test '(1)
(symbol? 1))
(test-end)
| false |
ef14ae4f748d735208713055720711a13e729ade
|
afc3bd22ea6bfe0e60396a84a837c82a0d836ea2
|
/Informatics Basics/Module 1/10-sets.scm
|
b99ce74b07f9474628e9d334ec18291aa2031ec9
|
[] |
no_license
|
BuDashka/BMSTU
|
c128c2b13065a25ec027c68bcc3bac119163a53f
|
069551c25bd11ea81e823b2195851f8563271b01
|
refs/heads/master
| 2021-04-15T15:22:12.324529 | 2017-10-19T00:59:25 | 2017-10-19T00:59:25 | 126,348,611 | 1 | 1 | null | 2018-03-22T14:35:04 | 2018-03-22T14:35:04 | null |
UTF-8
|
Scheme
| false | false | 1,900 |
scm
|
10-sets.scm
|
(define (list->set xs)
(if (not (null? xs))
(begin
(if (not (null? (cdr xs)))
(begin
(do ((x xs (cdr x)))
((not (or (null? (cdr x)) (equal? (car x) (car (cdr x))))) (cons (car x) (list->set (cdr x))))))
(cons (car xs) (list->set '()))))
xs))
(define (set? xs)
(if (not (null? xs))
(begin
(if (not (null? (cdr xs)))
(begin
(do ((x xs (cdr x)))
((or (null? (cdr x)) (equal? (car x) (car (cdr x))))
(if (null? (cdr x))
(= 1 1)
(= 1 2)))))
(= 1 1)))
(= 1 1)))
(define (union xs ys)
(cond ((null? xs) ys)
((null? ys) xs)
(else
(begin
(if (and (null? (cdr xs)) (not (memq (car xs) ys)))
(cons (car xs) ys)
(begin
(if (memq (car xs) ys)
(union (cdr xs) ys)
(cons (car xs) (union (cdr xs) ys)))))))))
(define (intersection xs ys)
(cond ((null? xs) '())
((memq (car xs) ys) (cons (car xs) (intersection (cdr xs) ys)))
(else (intersection (cdr xs) ys))))
(define (difference xs ys)
(if (null? xs)
'()
(begin
(if (and (null? (cdr xs)) (member (car xs) ys))
'()
(begin
(if (member (car xs) ys)
(difference (cdr xs) ys)
(cons (car xs) (difference (cdr xs) ys))))))))
(define (symmetric-difference xs ys)
(union (difference xs ys) (difference ys xs)))
(define (set-eq? xs ys)
(cond ((and (null? xs) (null? ys)) (= 1 1))
((null? ys) (= 1 2))
((null? xs) (= 1 2))
((equal? (car xs) (car ys)) (set-eq? (cdr xs) (cdr ys)))
((equal? (car xs) (car (reverse ys))) (set-eq? (cdr xs) (cdr (reverse ys))))
(else (= 1 2))))
| false |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.