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
0dfa4c9a46df148fa3f31ec806fd1211f3a2aace
38fcd70df648a497ee1271fcdbd30e391fb310e5
/prolog1.2/prolog1.2/prolog.ss
42b9372bcadd8a8348fe39c2b1b9d900a53a1d5f
[]
no_license
liutanyu/Useful
e9b3d3699dffa21bb1425dddff7d150ab7d7aee7
11a123126833e577a76ce32c22d8563c0f2bbd7d
refs/heads/master
2021-01-19T11:34:24.259506
2013-07-17T04:13:22
2013-07-17T04:13:22
null
0
0
null
null
null
null
UTF-8
Scheme
false
false
2,194
ss
prolog.ss
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; ;;; Prolog: top-level file, which loads the rest of the system. ;;; Interval arithmetic can be disabled. ;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; The following three definitions specify the locations of the various ;; parts of the Prolog interpreter, and are prepended to the names of ;; system files loaded: ;; prolog-source-prefix the Prolog interpreter (*.ss) ;; interval-source-prefix interval arithmetic (*.ss) ;; builtin-pred-prefix built-in predicates (*.pro) (define prolog-source-prefix "/home/srdg/dewar/prolog/scheme/R1.2/") (define interval-source-prefix (string-append prolog-source-prefix "Interval/")) (define builtin-pred-prefix prolog-source-prefix) (define debug? #f) (define user-debug? #f) (define (user-debug arg) (if user-debug? (begin (display arg) (newline)))) (define (load-prolog filename) (load (string-append prolog-source-prefix filename))) (load-prolog "compatibility.ss") (load-prolog "tables.ss") (load-prolog "clauses.ss") (load-prolog "predicates.ss") (load-prolog "goals.ss") (load-prolog "dlists.ss") (load-prolog "programs.ss") (load-prolog "compile.ss") (load-prolog "terms.ss") (load-prolog "search.ss") (load-prolog "schedule.ss") (load-prolog "flounder.ss") ;; To disable interval arithmetic, set intervals? to #f and comment out ;; the load line for interval.ss. (define intervals? #t) (load-prolog "interval.ss") (define (pro . file-name-list) (begin (newline) (display "A Prolog goal is an unquoted LIST of predicate calls.") (newline) (display "To toggle predicate tracing, type as a Prolog goal: ((debug))") (newline) (if intervals? (eval (append (list 'prolog (string-append builtin-pred-prefix "builtin.pro") (string-append builtin-pred-prefix "interval.pro")) file-name-list)) (eval (append (list 'prolog (string-append builtin-pred-prefix "builtin.pro")) file-name-list)) ) ) ) (define (greetings) (display "To start the Prolog interpreter, type: (pro <file-names>...)") (newline) ) (greetings)
false
48013b71bbdef32f8e71d7aae346ee4574b3a6da
86092887e6e28ebc92875339a38271319a87ea0d
/Ch3/3_44.scm
66776cbe1aefda7fe537d52af5bc1601cf8a2e1e
[]
no_license
a2lin/sicp
5637a172ae15cd1f27ffcfba79d460329ec52730
eeb8df9188f2a32f49695074a81a2c684fe6e0a1
refs/heads/master
2021-01-16T23:55:38.885463
2016-12-25T07:52:07
2016-12-25T07:52:07
57,107,602
1
0
null
null
null
null
UTF-8
Scheme
false
false
926
scm
3_44.scm
; in the exchange problem, the values of the accounts need to be accurate throughout the transaction ; since it's essentially two {withdraw, deposit} chunks together. ; in the transfer problem, the value of the account only needs to be accurate at the time of transaction. ; you'll still end up with the correct answer even if in the interim something happened to the account as long ; as the withdraw and deposit are synchronized. ; essentially, with exchange there's the possibility of the a1, a2, a1, a3 transfers causing a break between ; value identification and action. ; a1, a2 difference is calculated. a1, a3 difference is calculated. ; then all of them are applied. ; however with transfer there's essentially this: ; a1, a2, a1, a3 ; a1, a2 withdraw-operation (value is changed). ; a1, a3 withdraw-operation (value is changed again). ; all checks are accompanied by the value-change so we don't have a problem.
false
5b321c7f8f424bd78054f11f71f4958c72901acf
0f9909b1ea2b247aa9dec923d58e4d0975b618e6
/tests/test.scm
245495f7a895c669d26f7083593f717030f8ea2f
[]
no_license
suranap/sausage
9898ad418e2bdbb7e7a1ac798b52f17c589a4cb4
9a03ff3c52cd69278ea75733491e95362cc8765d
refs/heads/master
2016-09-10T19:31:11.990203
2013-05-01T14:48:50
2013-05-01T14:48:50
9,792,997
1
0
null
null
null
null
UTF-8
Scheme
false
false
2,612
scm
test.scm
;; improve functional maps (define (mark-variable name f) (match-lambda (($ Var N a) (=> fail) (if (equal? N name) (make-Var N (f a)) (fail))))) (define (mark-linear-map-type attribute) (attr (inherit attribute) (m:insert "linear-map" #t (synth attribute)))) (define functional-map-type-rule (match-lambda (($ Let V (and E ($ App ($ Var (or 'insert 'remove)) A*)) B a) (=> fail) (print "Trying: " V) (let ((s (synth a)) (Vstr (symbol->string (Var-name V)))) (if (or (and-let* ((sets (m:member "set" s))) (b:member Vstr sets)) ; no set! (and-let* ((uses (m:member "use" s)) (c (b:member Vstr uses))) (not (= c 1)))) ; V not used only 1 time (fail) (let ((new-B ((oncebu (debug-strategy (mark-variable (Var-name V) mark-linear-map-type))) B))) (if new-B ; this MUST be true (make-Let V E new-B a) (fail)))))))) (define linear-type? (match-lambda (($ Var N a) (m:member "linear-map" (synth a))))) (define functional-map-rule (match-lambda (($ App ($ Var 'insert a1) (and (Key Val (? linear-type? M)) A*) a2) (make-App (make-Var 'insert! a1) A* a2)) (($ App ($ Var 'remove a1) (and (Key (? linear-type? M)) A*) a2) (make-App (make-Var 'remove! a1) A* a2)))) ;; try to improve map and fold code ;; (map f l . ls) results in a new spine ;; (map f l), where l is a linear spine, is (map! f l) (define list-map-rule (match-lambda (($ Let V ($ App ($ Var 'map ma) F (? linear-spine? L)) B a) (make-Let V (make-App (make-Var 'map! ma) F L) B a)) (($ Let V (and A ($ App (and M ($ Var 'map)) F . A*)) B a) ;; tag V in B as a linear-spine type ))) (define (reverse l) (fold cons '() l)) (define (any pred l) (fold (lambda (e flag) (or (pred e) flag)) #f l)) (define (fold f i l) (let rec ((i i) (l l)) (if (null? l) i (rec (f (car l) i) (cdr l))))) ;; try to inline fold into any (let rec ((i #f) (l l)) (if (null? l) i (let ((e (car l)) (flag i)) (rec (f e flag) (cdr l))))) (define-syntax fold (syntax-rules () ((fold f i l) (let rec ((in i) (lst l)) (if (null? l) i (let ((e (car lst)) (flag in)) (rec (f e in) (cdr l)))))))) ;; any after normalization (letrec (rec|4 (lambda (i|5 l|5) (let (v_19 (null? i|5)) (if v_19 i|5 (let (e|8 (car l|5)) (let (v_23 (f e|8 i|5)) (let (v_25 (cdr l|5)) (rec|4 v_23 v_25)))))))) (rec|4 #f l)) (define (filter pred lis) (fold-right (lambda (e i) (if (pred e) (cons e lis) lis)) '() lis)) (define (append-map f l) (reduce-right append '() (map f l)))
true
bb9b908cd52918e33e4d8faca1f7aaf4f48e4917
99f659e747ddfa73d3d207efa88f1226492427ef
/datasets/srfi/srfi-150/srfi/150.scm
9f9cfb31ae34e44f928f28f5be3a80795c327530
[ "MIT" ]
permissive
michaelballantyne/n-grams-for-synthesis
241c76314527bc40b073b14e4052f2db695e6aa0
be3ec0cf6d069d681488027544270fa2fd85d05d
refs/heads/master
2020-03-21T06:22:22.374979
2018-06-21T19:56:37
2018-06-21T19:56:37
138,215,290
0
0
MIT
2018-06-21T19:51:45
2018-06-21T19:51:45
null
UTF-8
Scheme
false
false
5,958
scm
150.scm
;; Copyright (C) Marc Nieper-Wißkirchen (2017). All Rights Reserved. ;; Permission is hereby granted, free of charge, to any person ;; obtaining a copy of this software and associated documentation ;; files (the "Software"), to deal in the Software without ;; restriction, including without limitation the rights to use, copy, ;; modify, merge, publish, distribute, sublicense, and/or sell copies ;; of the Software, and to permit persons to whom the Software is ;; furnished to do so, subject to the following conditions: ;; The above copyright notice and this permission notice shall be ;; included in all copies or substantial portions of the Software. ;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, ;; EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF ;; MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ;; NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS ;; BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ;; ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN ;; CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE ;; SOFTWARE. ;;; Syntax ;; Syntactic keyword used to access the information stored in record-type descriptors (define-syntax :secret (syntax-rules ())) ;; The record-type definition keyword, which is exported from the library (define-syntax define-record-type/150 (em-syntax-rules () ((define-record-type/150 type-spec constructor-spec predicate-spec field-spec ...) ((parse-type-spec 'type-spec) => '(rtd-name parent-rtd)) ((parse-predicate-spec 'predicate-spec) => 'predicate-name) ((parent-rtd ':secret) => '(parent-size parent-make-subtype parent-fields)) ((parse-field-specs 'parent-size 'field-spec ...) => '(size (field-name accessor-name mutator-name index) ...)) ((parse-constructor-spec 'constructor-spec 'parent-fields '((field-name accessor-name mutator-name) ...)) => '(constructor-name mutators)) `(begin (define-values (type-accessor type-constructor type-predicate instance-accessor make-subtype) (parent-make-subtype #f)) (define predicate-name (make-predicate type-predicate)) (define accessor-name (make-accessor instance-accessor index)) ... (define mutator-name (make-mutator instance-accessor index)) ... (define constructor-name (make-constructor type-constructor size (list . mutators))) ,(define-rtd 'rtd-name 'size 'make-subtype (em-append (em-reverse '((field-name accessor-name mutator-name) ...)) 'parent-fields)))))) ;; Helper macros that set up the parameters of a record-type definition (define-syntax parse-type-spec (em-syntax-rules () ((parse-type-spec '(rtd parent-rtd)) '(rtd parent-rtd)) ((parse-type-spec '#f) '(rtd root-rtd)) ((parse-type-spec 'rtd) '(rtd root-rtd)))) (define-syntax parse-predicate-spec (em-syntax-rules () ((parse-predicate-spec '#f) 'predicate-name) ((parse-predicate-spec 'predicate-name) 'predicate-name))) (define-syntax parse-field-specs (em-syntax-rules () ((parse-field-specs 'index) '(index)) ((parse-field-specs 'index '(name accessor) 'field-specs ...) (parse-field-specs 'index '(name accessor mutator) 'field-specs ...)) ((parse-field-specs 'index '(name accessor mutator) 'field-specs ...) ((parse-field-specs '(+ 1 index) 'field-specs ...) => '(size fields ...)) '(size (name accessor mutator index) fields ...)))) (define-syntax parse-constructor-spec (em-syntax-rules () ((parse-constructor-spec '#f 'parent-fields 'fields) (parse-constructor-spec '(constructor-name) 'parent-fields 'fields)) ((parse-constructor-spec '(constructor-name field ...) 'parent-fields 'fields) `(constructor-name (,(get-mutator 'field 'parent-fields 'fields) ...))) ((parse-constructor-spec 'constructor-name '((parent-field-name parent-accessor parent-mutator) ...) '((field-name accessor mutator) ...)) `(constructor-name ,(em-append (em-reverse '(parent-mutator ...)) '(mutator ...)))))) ;; Locates the mutator of a field in a record-type or one of its ancestors (define-syntax get-mutator (em-syntax-rules () ((get-mutator 'field '((parent-field-name parent-accessor parent-mutator) ...) '((field-name accessor mutator) ...)) (em-cadr (em-or (em-assoc 'field '((field-name mutator) ...) em-equal?) (em-assoc 'field '((accessor mutator) ...) em-equal?) (em-assoc 'field '((parent-field-name parent-mutator) ...) em-equal?/free) (em-assoc 'field '((parent-accessor parent-mutator) ...) em-equal?/free) (em-error '"record field not found" 'field)))))) (define-syntax define-rtd (em-syntax-rules () ((define-rtd 'rtd 'size 'subtype-constructor 'fields) '(define-syntax rtd (em-syntax-rules ::: () ((rtd ':secret) '(size subtype-constructor fields)) ((rtd 'arg :::) (em-error "invalid use of record-type descriptor"))))))) ;; Root record-type descriptor (define-rtd 'root-rtd '0 'make-type '()) ;; Auxiliary composable macros ;; Like em-equal? but identifiers are compared using em-free-identifier=? (define-syntax em-equal?/free (em-syntax-rules () ((em-equal?/free 'a 'b) (em-if (em-and (em-symbol? 'a) (em-symbol? 'b)) (em-free-identifier=? 'a 'b) (em-equal? 'a 'b))))) ;;; Procedures (define (make-predicate type-predicate) type-predicate) (define (make-accessor type-accessor index) (lambda (record) (vector-ref (type-accessor record) index))) (define (make-mutator type-accessor index) (lambda (record value) (vector-set! (type-accessor record) index value))) (define (make-constructor type-constructor size mutators) (lambda args (let ((record (type-constructor (make-vector size)))) (for-each (lambda (arg mutator) (mutator record arg)) args mutators) record)))
true
fd8bbc75ce87a05e0afd023d2ef2ca2cd790964e
e1fc47ba76cfc1881a5d096dc3d59ffe10d07be6
/ch3/3.05.01.stream.scm
2ba9296a64b36a9112b6a9a44ef2d6f6f562d6b5
[]
no_license
lythesia/sicp-sol
e30918e1ebd799e479bae7e2a9bd4b4ed32ac075
169394cf3c3996d1865242a2a2773682f6f00a14
refs/heads/master
2021-01-18T14:31:34.469130
2019-10-08T03:34:36
2019-10-08T03:34:36
27,224,763
2
0
null
null
null
null
UTF-8
Scheme
false
false
2,395
scm
3.05.01.stream.scm
; pre ; in guile: ; (define-syntax delay ; (syntax-rules () ; [(delay expr) (cons 'promise (lambda () expr) )])) ; (define (force promise) ; (let* ; ((func (cdr promise)) ; (value (func))) ; (set-cdr! promise (lambda () value)) ; value)) ; (define-syntax delay (syntax-rules () [(delay expr) (lambda () expr)])) ; memorized (define-syntax delay (syntax-rules () [(delay expr) (memo-proc (lambda () expr))])) (define (force f) (f)) ; def ; (define (cons-stream a b) (cons a (delay b))) ; this not work (define-syntax cons-stream (syntax-rules () [(cons-stream a b) (cons a (delay b))])) (define (stream-car s) (car s)) (define (stream-cdr s) (force (cdr s))) (define the-empty-stream '()) (define empty-stream? null?) ; util ; access s[n] (define (stream-ref s n) (if (zero? n) (stream-car s) (stream-ref (stream-cdr s) (1- n))) ) ; 1-to-1 map (define (stream-map proc s) (if (empty-stream? s) the-empty-stream (cons-stream (proc (stream-car s)) (stream-map proc (stream-cdr s))) ) ) ; for-each (define (stream-for-each proc s) (if (empty-stream? s) 'done (begin (proc (stream-car s)) (stream-for-each proc (stream-cdr s))) ) ) (define (stream-iter-to proc s to) (if (or (empty-stream? s) (zero? to)) 'done (begin (proc (stream-car s)) (stream-iter-to proc (stream-cdr s) (1- to))) ) ) (define (stream-head s n) (if (empty-stream? s) 'done (begin (newline) (display (stream-car s)) (if (> n 1) (stream-head (stream-cdr s) (- n 1))) ) ) ) ; display (define (display-stream s) (stream-for-each display-line s) ) (define (display-stream-to s to) (stream-iter-to display-line s to) ) (define (display-line x) (newline)(display x)) ; gen interval (define (stream-enum-interval l h) (if (> l h) the-empty-stream (cons-stream l (stream-enum-interval (1+ l) h)) ) ) ; filter (define (stream-filter pred s) (cond ((empty-stream? s) the-empty-stream) ((pred (stream-car s)) (cons-stream (stream-car s) (stream-filter pred (stream-cdr s)))) (else (stream-filter pred (stream-cdr s))) ) ) ; memo (non-param proc) (define (memo-proc proc) (let ((already-run? #f) (result #f)) (lambda () (if (not already-run?) (begin (set! result (proc)) (set! already-run? #t) result ) result ) ) ) )
true
82045e5c5ce6297e9de76f0fc5eeb41fa395efc8
4f22045cb28e1444f81be3272301aa23c4d83238
/05/lambda-parser.yy.scm
e0e79d08d5463dae9f80a3ae7034ef4db5ae8cf1
[]
no_license
h8gi/TAPL
f28a9481d7cbc57f139f58d4436db35b8b4337ef
80259c4c4f5a0255421bce41b083aadd817d8c08
refs/heads/master
2021-01-12T02:31:04.575533
2017-01-10T02:11:26
2017-01-10T02:11:26
78,054,401
0
0
null
null
null
null
UTF-8
Scheme
false
false
2,487
scm
lambda-parser.yy.scm
(require-extension lalr-driver) (define lambda-parser (lr-driver '#(((*default* *error*) (NUMBER 4) (LAMBDA 3) (LPAREN 2) (VAR 1)) ((*default* -4)) ((*default* *error*) (NUMBER 4) (LAMBDA 3) (LPAREN 2) (VAR 1)) ((*default* *error*) (VAR 8)) ((*default* -5)) ((*default* -3)) ((*default* *error*) (*eoi* 9) (NUMBER 4) (LAMBDA 3) (LPAREN 2) (VAR 1)) ((*default* *error*) (NUMBER 4) (LAMBDA 3) (LPAREN 2) (RPAREN 11) (VAR 1)) ((*default* *error*) (DOT 12)) ((*default* -1) (*eoi* accept)) ((*default* -2)) ((*default* -7)) ((*default* *error*) (NUMBER 4) (LAMBDA 3) (LPAREN 2) (VAR 1)) ((*default* -6) (NUMBER 4) (LAMBDA 3) (LPAREN 2) (VAR 1))) (vector '((2 . 5) (1 . 6)) '() '((2 . 5) (1 . 7)) '() '() '() '((2 . 10)) '((2 . 10)) '() '() '() '() '((2 . 5) (1 . 13)) '((2 . 10))) (vector '() (lambda (___stack ___sp ___goto-table ___push yypushback) (let* (($2 (vector-ref ___stack (- ___sp 1))) ($1 (vector-ref ___stack (- ___sp 3)))) $1)) (lambda (___stack ___sp ___goto-table ___push yypushback) (let* (($2 (vector-ref ___stack (- ___sp 1))) ($1 (vector-ref ___stack (- ___sp 3)))) (___push 2 1 (list 'APPLY $1 $2)))) (lambda (___stack ___sp ___goto-table ___push yypushback) (let* (($1 (vector-ref ___stack (- ___sp 1)))) (___push 1 1 $1))) (lambda (___stack ___sp ___goto-table ___push yypushback) (let* (($1 (vector-ref ___stack (- ___sp 1)))) (___push 1 2 (list 'VAR $1)))) (lambda (___stack ___sp ___goto-table ___push yypushback) (let* (($1 (vector-ref ___stack (- ___sp 1)))) (___push 1 2 (list 'NUMBER $1)))) (lambda (___stack ___sp ___goto-table ___push yypushback) (let* (($4 (vector-ref ___stack (- ___sp 1))) ($3 (vector-ref ___stack (- ___sp 3))) ($2 (vector-ref ___stack (- ___sp 5))) ($1 (vector-ref ___stack (- ___sp 7)))) (___push 4 2 (list 'LAMBDA (list $2) $4)))) (lambda (___stack ___sp ___goto-table ___push yypushback) (let* (($3 (vector-ref ___stack (- ___sp 1))) ($2 (vector-ref ___stack (- ___sp 3))) ($1 (vector-ref ___stack (- ___sp 5)))) (___push 3 2 $2))))))
false
f0b179b77b7ab25e10ae9808b03dce97d1712466
1b1828426867c9ece3f232aaad1efbd2d59ebec7
/Chapter 3/sicp3-72.scm
3c224160c1336af7886d498159f4fd29138699ab
[]
no_license
vendryan/sicp
60c1338354f506e02c714a96f643275d35a7dc51
d42f0cc6f985aaf369f2760f962928381ca74332
refs/heads/main
2023-06-07T02:04:56.332591
2021-06-19T10:28:57
2021-06-19T10:28:57
369,958,898
0
0
null
null
null
null
UTF-8
Scheme
false
false
3,032
scm
sicp3-72.scm
(define (merge weight-proc s1 s2) (cond ((stream-null? s1) s2) ((stream-null? s2) s1) (else (let ((x1 (stream-car s1)) (x2 (stream-car s2))) (cond ((> (weight-proc x1) (weight-proc x2)) (cons-stream x2 (merge weight-proc s1 (stream-cdr s2)))) ((> (weight-proc x1) (weight-proc x2)) (cons-stream x1 (merge weight-proc (stream-cdr s1) s2))) (else (cons-stream x1 (merge weight-proc (stream-cdr s1) s2)))))))) (define (pairs s t weight) (cons-stream (list (stream-car s) (stream-car t)) (merge weight (stream-map (lambda (x) (list (stream-car s) x)) (stream-cdr t)) (pairs (stream-cdr s) (stream-cdr t) weight)))) ; Tweaked this so display what pair that fulfill ; not the value result (define (consecutive-value s weight times) (define (iter s val how-many accumulated) (cond ((stream-null? s) the-empty-stream) ((null? val) (iter (stream-cdr s) (weight (stream-car s)) (+ how-many 1) (cons (stream-car s) accumulated))) ((= how-many times) (cons-stream accumulated (iter (stream-cdr s) val 0 '()))) ((not (= val (weight (stream-car s)))) (iter (stream-cdr s) (weight (stream-car s)) 1 (cons (stream-car s) '()))) (else (iter (stream-cdr s) val (+ how-many 1) (cons (stream-car s) accumulated))))) (iter s '() 0 '())) (define (cube x) (* x x x)) (define (weight-proc x) (+ (cube (car x)) (cube (cadr x)))) (define (sum-square x) (+ (square (car x)) (square (cadr x)))) (define weighted-cube-pair (pairs integers integers weight-proc)) (define ramanujan-number (consecutive-value weighted-cube-pair weight-proc 2)) (define three-consecutive-sum-square (consecutive-value (pairs integers integers sum-square) sum-square 3)) (display-top10 three-consecutive-sum-square) ; ((10 15) (6 17) (1 18)) ; ((13 16) (8 19) (5 20)) ; ((17 19) (11 23) (5 25)) ; ((14 23) (10 25) (7 26)) ; ((19 22) (13 26) (2 29)) ; ((15 25) (11 27) (3 29)) ; ((21 22) (14 27) (5 30)) ; ((20 25) (8 31) (1 32)) ; ((12 31) (9 32) (4 33)) ; ((25 25) (17 31) (5 35))
false
a8ae7ee505985bb9ed9c7b85210090f423ea55d5
d369542379a3304c109e63641c5e176c360a048f
/brice/Chapter1/exercise-1.41.scm
632b7acc597a831b42221e3a814c389c1e600ffb
[]
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
924
scm
exercise-1.41.scm
#lang racket (require "../utils.scm") (require "../meta.scm") ; Exercise 1.41: ; ; Define a procedure double that takes a procedure ; of one argument as argument and returns a ; procedure that applies the original procedure twice. ; For example, if inc is a procedure that adds 1 to its ; argument, then (double inc) should be a procedure ; that adds 2. What value is returned by ; ; (((double (double double)) inc) 5) (define (double g) (lambda (x) (g (g x)))) ((double inc) 8) ;-> 10 (((double (double double)) inc) 5) ;-> Expecting 5+16=21 ; That's because double applies its argument twice, so by doubling double, ; the first application will apply g twice, while the second application will ; apply g twice twice (4 times) for one application of double. ; Hence, applying double again will apply the g twice twice twice twice (16 times) ; Thus (((double (double (double double))) inc) 0) ;-> 256
false
a2e4c4cade82fbc599d13e340e4eec0e49d1d154
4b480cab3426c89e3e49554d05d1b36aad8aeef4
/chapter-02/ex2.06-ashal.scm
26430eaca2143b0fc992e74fc83a7b4b138a2f9c
[]
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
936
scm
ex2.06-ashal.scm
(load "../misc/scheme-test.scm") (define zero (lambda (f) (lambda (x) x))) (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)))))) (define (add-1 n) (lambda (f) (lambda (x) (f ((n f) x))))) (define (add a b) (lambda (f) (lambda (x) ((a f) ((b f) x))))) (define (to-i x) ((x (lambda (n) (+ n 1))) 0)) (run (make-testcase '(assert-equal? 0 (to-i zero)) '(assert-equal? 1 (to-i one)) '(assert-equal? 2 (to-i two)) '(assert-equal? 3 (to-i three)) '(assert-equal? 0 (to-i (add zero zero))) '(assert-equal? 1 (to-i (add zero one))) '(assert-equal? 1 (to-i (add one zero))) '(assert-equal? 2 (to-i (add one one))) '(assert-equal? 3 (to-i (add one two))) '(assert-equal? 4 (to-i (add one three))) '(assert-equal? 5 (to-i (add two three))) ))
false
3c5da202ff1c0e843a519693b030f981a5d6b0e7
defeada37d39bca09ef76f66f38683754c0a6aa0
/mscorlib/system/security/permissions/publisher-identity-permission-attribute.sls
28b140b919230466ff16aca8c32bba324c702e90
[]
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,779
sls
publisher-identity-permission-attribute.sls
(library (system security permissions publisher-identity-permission-attribute) (export new is? publisher-identity-permission-attribute? create-permission cert-file-get cert-file-set! cert-file-update! signed-file-get signed-file-set! signed-file-update! x509-certificate-get x509-certificate-set! x509-certificate-update!) (import (ironscheme-clr-port)) (define-syntax new (lambda (e) (syntax-case e () ((_ a ...) #'(clr-new System.Security.Permissions.PublisherIdentityPermissionAttribute a ...))))) (define (is? a) (clr-is System.Security.Permissions.PublisherIdentityPermissionAttribute a)) (define (publisher-identity-permission-attribute? a) (clr-is System.Security.Permissions.PublisherIdentityPermissionAttribute a)) (define-method-port create-permission System.Security.Permissions.PublisherIdentityPermissionAttribute CreatePermission (System.Security.IPermission)) (define-field-port cert-file-get cert-file-set! cert-file-update! (property:) System.Security.Permissions.PublisherIdentityPermissionAttribute CertFile System.String) (define-field-port signed-file-get signed-file-set! signed-file-update! (property:) System.Security.Permissions.PublisherIdentityPermissionAttribute SignedFile System.String) (define-field-port x509-certificate-get x509-certificate-set! x509-certificate-update! (property:) System.Security.Permissions.PublisherIdentityPermissionAttribute X509Certificate System.String))
true
d8e94934c18b285bd08748707bf934a8c20149dc
58381f6c0b3def1720ca7a14a7c6f0f350f89537
/Chapter 4/4.4/4.68.scm
3fb9d8418aa8288f882cc14a68794606a27c879e
[]
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
165
scm
4.68.scm
#lang planet neil/sicp (rule (reverse (?a) (?a))) (rule (reverse (?x . ?y) ?z) (and (reverse ?y ?y-reversed) (append-to-form ?y-reversed (?x) ?z)))
false
16b75ba495f7c2e79f8514fc3dcea8f860c90fcc
50a78f57b78f19548b4eec2b9ba84b30376aedff
/mustache.scm
31276f5f1d5d4481205d0e42f77ade4fa5609c46
[]
no_license
jgarte/mustache-scheme
0a6f1945418b419bdb615c8c0e535dc1be7c16ab
4542993596d0020ea5a5f04f4d441ed38d585fd5
refs/heads/master
2023-03-16T03:01:30.804217
2012-02-12T04:40:57
2012-02-12T04:40:57
null
0
0
null
null
null
null
UTF-8
Scheme
false
false
14,838
scm
mustache.scm
(load "~~/lib/syntax-case") ; Higher order functions ;; Bind arguments to a function for delayed evaluation (define (curry f . c) (lambda x (apply f (append c x)))) ;; Reverse the order a function takes arguments (define (reverse-arguments f) (lambda a (apply f (reverse a)))) ;; Returns a function in which each function in fs is applied in reverse, with ;; the output chained to the next (define (apply-f f . fs) (lambda x (let loop ((rfs (cdr (reverse fs))) (current (apply (car (reverse fs)) x))) (if (null? rfs) (f current) (loop (cdr rfs) ((car rfs) current)))))) (define (filter f lst) (let recur ((lst lst) (acc '())) (cond ((null? lst) (reverse acc)) ((f (car lst)) (recur (cdr lst) (cons (car lst) acc))) (else (recur (cdr lst) acc))))) (define (any? f lst) (cond ((null? lst) #f) ((f (car lst)) #t) (else (any? f (cdr lst))))) (define (drop-while f lst) (if (or (null? lst) (not (f (car lst)))) lst (drop-while f (cdr lst)))) (define (take-while f lst) (let recur ((lst lst) (acc '())) (if (or (null? lst) (not (f (car lst)))) (reverse acc) (recur (cdr lst) (cons (car lst) acc))))) ;; Similar to any but operates on a list of truthy functions and one argument, ;; returning true if any of the functions evaluate true when given the argument (define (any-f? arg fs) (cond ((null? fs) #f) (((car fs) arg) #t) (else (any-f? arg (cdr fs))))) (define (all? f lst) (cond ((null? lst) #t) ((f (car lst)) (all? f (cdr lst))) (else #f))) (define (alist? lst) (all? pair? lst)) ; Macros ;; Case that uses procedures for truth instead of matching (define-syntax case-cond (syntax-rules (else) ((_ e (c r) ... (else d)) (cond ((c e) r) ... (else d))))) ;; Chain functions on an initial argument (define-syntax ->> (syntax-rules () ((_ s expr ...) (let-syntax ((expr-or-func (syntax-rules () ((_ (f default-arg (... ...))) (curry f default-arg (... ...))) ((_ f) f)))) (let loop ((current s) (rest (list (expr-or-func expr) ...))) (if (null? rest) current (loop ((car rest) current) (cdr rest)))))))) (define (truthy? term) (case-cond term (boolean? term) (null? #f) (else #t))) (define (falsy? term) (not (truthy? term))) ; Tag procedures (define opening-tag "{{") (define closing-tag "}}") (define section-delimiter #\#) (define partial-delimiter #\>) (define inverted-delimiter #\^) (define closing-delimiter #\/) (define comment-delimiter #\!) (define set-delimiter #\=) (define self-node '|.|) ; Creates function to check if two delimiters are the same ; ((matches-delimiter? #\#) #\#) -> #t (define (matches-delimiter? d) (lambda (t) (eq? d t))) ; Cases based on known delimiters (define section-delimiter? (matches-delimiter? section-delimiter)) (define partial-delimiter? (matches-delimiter? partial-delimiter)) (define inverted-delimiter? (matches-delimiter? inverted-delimiter)) (define closing-delimiter? (matches-delimiter? closing-delimiter)) (define comment-delimiter? (matches-delimiter? comment-delimiter)) (define set-delimiter? (matches-delimiter? set-delimiter)) ; Tag is a cons pair ( delimiter . label ) (define get-tag-delimiter car) (define get-tag-label cdr) ; Creates a function to check whether tag delimiters match, given a ; function derived from (matches-delimiter? ...) ; ((matches-tag? (matches-delimiter? #\#)) (cons #\# 'label)) -> #t (define (matches-tag? fn) (lambda (t) (and (pair? t) (fn (get-tag-delimiter t))))) (define section-tag? (matches-tag? section-delimiter?)) (define partial-tag? (matches-tag? partial-delimiter?)) (define inverted-tag? (matches-tag? inverted-delimiter?)) (define closing-tag? (matches-tag? closing-delimiter?)) (define comment-tag? (matches-tag? comment-delimiter?)) (define set-tag? (matches-tag? set-delimiter?)) ; Node is a cons pair ( tag . subtree ) ; Creates a function to check whether node tags match, given a ; function derived from (matches-tag? ...) ; ((matches-node? ; (matches-tag? ; (matches-delimiter? #\#))) ; (cons (cons #\# 'label) '("tree" "elements"))) -> #t (define get-node-tag car) (define get-node-tree cdr) (define (get-node-delimiter n) (get-tag-delimiter (get-node-tag n))) (define (get-node-label n) (get-tag-label (get-node-tag n))) (define (matches-node? fn) (lambda (n) (and (pair? n) (fn (get-node-tag n))))) (define section-node? (matches-node? section-tag?)) (define partial-node? (matches-node? partial-tag?)) (define inverted-node? (matches-node? inverted-tag?)) (define closing-node? (matches-node? closing-tag?)) (define comment-node? (matches-node? comment-tag?)) (define text-node? string?) (define self-node? (curry eq? self-node)) ; String procedures (define (strip-whitespace s) (->> s string->list (filter (apply-f not char-whitespace?)) list->string)) (define (strip-edge-f fn str) (->> str string->list (drop-while fn) reverse (drop-while fn) reverse list->string)) (define strip-edge-whitespace (curry strip-edge-f char-whitespace?)) ; Stream procedures (define (stream-ready? stream) (and (char-ready? stream) (not (eof-object? (peek-char stream))))) (define (read-until-string stream str) (let ((output (open-string)) (target (string->list str))) (let loop ((buf '())) (cond ((equal? buf target) (cons #t (get-output-string output))) ((not (stream-ready? stream)) (do ((tbuf buf (cdr tbuf))) ((null? tbuf) (cons #f (get-output-string output))) (write-char (car tbuf) output))) (else (if (< (length buf) (length target)) (loop (append buf (list (read-char stream)))) (begin (write-char (car buf) output) (loop (append (cdr buf) (list (read-char stream))))))))))) ; Parsing ;; Is a string surrounded in set delimiters? (define (set-delimiters? str) (let* ((stripped (strip-edge-whitespace str)) (stripped-list (string->list stripped))) (and (set-delimiter? (car stripped-list)) (set-delimiter? (car (reverse stripped-list))) (any? char-whitespace? stripped-list)))) ;; Parse new opening and closing tags from a set delimiter string (define (make-set-delimiters str) (let* ((stripped (strip-edge-f set-delimiter? (strip-edge-whitespace str))) (stripped-list (string->list stripped))) (cons (list->string (take-while (apply-f not char-whitespace?) stripped-list)) (list->string (reverse (take-while (apply-f not char-whitespace?) (reverse stripped-list))))))) ;; Create a tag pair from a tag string (define (classify-token token) (let ((tsymbol (string->symbol (strip-whitespace token))) (ctoken (strip-edge-whitespace token))) (if (> (string-length token) 0) (let ((first-char (->> ctoken string->list car)) (esymbol (->> ctoken string->list cdr list->string string->symbol))) (cond ((set-delimiters? ctoken) (cons first-char (make-set-delimiters ctoken))) ((any-f? first-char (list section-delimiter? partial-delimiter? inverted-delimiter? closing-delimiter? comment-delimiter?)) (cons first-char esymbol)) (else tsymbol))) tsymbol))) ;; Create a parse tree (define (parse-section openingd closingd stream key) (let recur ((openingd openingd) (closingd closingd) (tree '()) (at-tag #f)) (let ((parse-subsection (curry parse-section openingd closingd)) (next (curry recur openingd closingd))) (if (not (stream-ready? stream)) (if key (cons key (reverse tree)) (reverse tree)) (if at-tag (let* ((tag (read-until-string stream closingd)) (tag-status (car tag)) (tag-text (cdr tag))) (if tag-status (let ((token (classify-token tag-text))) (case-cond token (set-tag? (recur (cadr token) (cddr token) tree #f)) (comment-tag? (next tree #f)) (section-tag? (next (cons (parse-subsection stream token) tree) #f)) (inverted-tag? (next (cons (parse-subsection stream token) tree) #f)) (closing-tag? (if (eq? (get-tag-label token) (get-tag-label key)) (cons key (reverse tree)) (raise "Interpolated closing tags"))) (else (next (cons token tree) #f)))) (next (cons tag-text tree) #f))) (let* ((tag (read-until-string stream openingd)) (tag-status (car tag)) (tag-text (cdr tag))) (next (cons tag-text tree) tag-status))))))) (define (parse stream) (parse-section opening-tag closing-tag stream #f)) ; Procedures for dealing with contexts (define (make-list lst) (if (list? lst) lst `((,self-node ,lst)))) (define (get-alist-item fn alist) (and (list? alist) (pair? (car alist)) (fn (car alist)))) (define get-alist-key (curry get-alist-item car)) (define get-alist-value (curry get-alist-item cadr)) (define (get-alist-assoc fn key alist) (and (alist? alist) (pair? (assoc key alist)) (fn (assoc key alist)))) (define get-alist-avalue (curry get-alist-assoc cadr)) (define get-alist-arest (curry get-alist-assoc cdr)) (define (in-proc-context? context) (procedure? (get-alist-key context))) (define (create-proccontext context key) (let ((proc (get-alist-avalue key context))) (and (procedure? proc) (cons (list proc proc) context)))) (define (create-subcontext context key) (map (curry (reverse-arguments append) context) (map make-list (filter truthy? (or (get-alist-arest key context) '()))))) ; Render a tree with a given context (define (render tree context) (let loop ((elems tree) (rest '()) (current-context context)) (if (falsy? elems) (apply string-append (reverse rest)) (let ((node (car elems)) (remaining (cdr elems))) (cond ((text-node? node) (loop remaining (cons node rest) current-context)) ((self-node? node) (let ((self-value (get-alist-value current-context))) (if self-value (loop remaining (cons self-value rest) current-context) (loop remaining rest current-context)))) ((section-node? node) (let* ((node-label (get-node-label node)) (sub-elems (get-node-tree node)) (proc-context (create-proccontext current-context node-label))) (if (and node-label sub-elems) (if proc-context (loop remaining (cons (render sub-elems proc-context) rest) current-context) (loop remaining (append (reverse (map (curry loop sub-elems '()) (create-subcontext current-context node-label))) rest) current-context)) (loop remaining rest current-context)))) ((inverted-node? node) (let* ((node-label (get-node-label node)) (sub-elems (get-node-tree node)) (node-value (get-alist-avalue node-label current-context))) (if (not node-value) (loop remaining (cons (render sub-elems current-context) rest) current-context) (loop remaining rest current-context)))) ((partial-tag? node) (loop remaining (cons (render (eval (get-node-tree node)) current-context) rest) current-context)) (else (let ((node-value (get-alist-avalue node current-context))) (if node-value (loop remaining (cons (if (in-proc-context? current-context) ((get-alist-value current-context) node-value) node-value) rest) current-context) (loop remaining rest current-context))))))))) (define (render-file filename context) (render (parse (open-input-file filename)) context)) (define test-string (open-string "<html> <head> <title>{{ title }} {{ john }}</title> </head> <body> <h1>{{ title }}</h1> <ul> {{ #list }} <li> {{ !this-is-the-header }} {{ sectionheader }} {{ term }}: {{ description }} </li> {{ /list }} {{ ^lister }} Negated {{ /lister }} </ul> {{ #names }}{{ . }}, {{ /names }} </body> </html>")) (define tree (parse test-string)) (define context '((title "Fun languages") (sectionheader "Language") (list ((term "Scheme") (description "A great functional language")) ((term "Python") (description "A nice high level scripting language")) ((term "Lua") (description "A well thought out, fast, simple, embedded language"))) (names "Frank" "John" "Peter") )) (println (render tree context)) (define t3 (parse (open-string " hello {{ !ignore-this-please }} {{ #person }} {{ #reversed }} {{ name }} {{ /reversed }} {{ #friends }} {{ count }} {{ #person }} {{ . }} {{/person }} {{/friends }} {{/person }}"))) (define c3 `((person ((name "name a") (friends ((count "2") (person "friend a" "friend b")))) ((name "name b") (friends ((count "3") (person "friend c" "friend d" "friend e")))) ((name "name c") (friends ((count "1") (person "friend f"))))) (reversed ,(apply-f list->string reverse string->list)) )) (println (render t3 c3))
true
17153d4b745ddf3acf1a0c39208f01dbf74108c2
8def8726df4eb28d7b22d123c7e3a208d5577999
/old/download/version.ss
213130ced9b5574f0f9cbbf14d28e874a0131990
[]
no_license
racket/old-web
9e0afa241fe443ddb5e9fa083d58c978ed38b459
d7b670c23e570d398257fbc7b658b3948a5f3d81
refs/heads/master
2022-11-11T09:46:58.220698
2020-06-25T13:12:02
2020-06-25T13:12:02
274,562,458
1
1
null
null
null
null
UTF-8
Scheme
false
false
682
ss
version.ss
#reader"../common/html-script.ss" (import-from "bundle-information.ss" plt-version plt-stable-version) (define (run) (unless (testing?) (write-raw* "version" (format ";; ~a\n;; ~a\n~s\n" "This is for ancient (pre-v4) installations, the real" "information is in version.txt." `([recent "500"] [stable "500"]))) (write-raw* "version.txt" (format ";; ~a\n;; ~a\n~s\n" "This is for old (pre-racket) installations, the real" "information is at download.racket-lang.org." ;; `([recent ,plt-version] [stable ,plt-stable-version]) `([recent "5.0"] [stable "5.0"])))))
false
e70f612f8065202095ef7aff89f1a276fc427721
c1c3596f32d0802eacecf839e97b31a6d9ca76ed
/info.ss
3ce7e5ce9b2a1e47bd3e9a74d227dee6a4b9919b
[]
no_license
dyoo/version-case
6fa4d2fc1bfb5da292eab8f400bde4b3391d8731
e7a85d5a14ce0a2ebd4e7bc39dd8f763dee2c873
refs/heads/master
2021-01-10T18:26:19.375311
2011-08-15T21:36:33
2011-08-15T21:36:33
2,187,389
0
1
null
null
null
null
UTF-8
Scheme
false
false
429
ss
info.ss
(module info (lib "infotab.ss" "setup") (define name "version-case") (define blurb '("version-case: conditional code based on mzscheme version")) (define categories '(misc)) (define primary-file "main.rkt") (define release-notes '("Updated documentation so it should no longer generate Scribble warnings.")) (define version "1.9") (define repositories '("4.x")) (define scribblings '(("version-case.scrbl" ()))))
false
179e894c95186a7a388b11f93ebe00b6acd4ad81
41648be07e8803784690d9b4f6f08091e322b193
/core-thread-cell.ss
569fc7d21d9691b7f7f1be647827e0d659465365
[]
no_license
samth/not-a-box
dad25a9ea65debf318a14f2a5f5788b331b62a76
9fa61e07b278be52148612fb5a77f4058eca5a9f
refs/heads/master
2021-01-19T12:51:12.457049
2017-03-02T19:57:20
2017-03-03T19:59:37
82,343,642
0
0
null
2017-02-17T22:27:36
2017-02-17T22:27:36
null
UTF-8
Scheme
false
false
155
ss
core-thread-cell.ss
(define-record thread-cell (value)) (define (thread-cell-ref c) (thread-cell-value c)) (define (thread-cell-set! c v) (set-thread-cell-value! c v))
false
21243c10feb4a2d2b86dce4e93189cc2f522bfe8
648776d3a0d9a8ca036acaf6f2f7a60dcdb45877
/queries/rasi/highlights.scm
e2be63ffbe0e27b0536180546e3a37fcf8dfbbe7
[ "Apache-2.0" ]
permissive
nvim-treesitter/nvim-treesitter
4c3c55cbe6ff73debcfaecb9b7a0d42d984be3e6
f8c2825220bff70919b527ee68fe44e7b1dae4b2
refs/heads/master
2023-08-31T20:04:23.790698
2023-08-31T09:28:16
2023-08-31T18:19:23
256,786,531
7,890
980
Apache-2.0
2023-09-14T18:07:03
2020-04-18T15:24:10
Scheme
UTF-8
Scheme
false
false
1,562
scm
highlights.scm
(comment) @comment "@media" @keyword "@import" @include "@theme" @include (string_value) @string [ (integer_value) (float_value) "0" ] @number (boolean_value) @boolean [ (feature_name) (url_image_scale) (direction) (text_style_value) (line_style_value) (position_value) (orientation_value) (cursor_value) "inherit" ] @keyword (url_image "url" @function.builtin) (gradient_image "linear-gradient" @function.builtin) (distance_calc "calc" @function.builtin) (rgb_color ["rgb" "rgba"] @function.builtin) (hsl_color ["hsl" "hsla"] @function.builtin) (hwb_color ["hwb" "hwba"] @function.builtin) (cmyk_color "cmyk" @function.builtin) [ "(" ")" "{" "}" "[" "]" ] @punctuation.bracket (distance_op) @operator [ ";" "," ":" "." ] @punctuation.delimiter [ (angle_unit) (integer_distance_unit) (float_distance_unit) ] @type (percentage) @number (percentage "%" @type) [ (global_selector) (id_selector) ] @namespace (id_selector_view [ "normal" "selected" "alternate" ] @attribute) (id_selector_state [ "normal" "urgent" "active" ] @type.qualifier) (hex_color) @number (hex_color "#" @punctuation.special) (named_color (identifier) @string.special) (named_color "/" @operator) (reference_value "@" @punctuation.special (identifier) @variable) (reference_value "var" @function.builtin (identifier) @variable) (list_value (identifier) @variable) (environ_value "$" @punctuation.special (identifier) @variable) (environ_value "env" @function.builtin (identifier) @variable) (property_name) @variable (ERROR) @error
false
80e8eb698f64bc0819df3878ef664a8f4e1b0e48
8198fe9ada6f569a9ad9932b22f8e0a743221407
/lib/gtk/error-dialog.scm
2b5ac89f174ff748dda48be34947157e159264e2
[ "BSD-2-Clause" ]
permissive
shirok/Gauche-gtk2
56b17162d2a1a6cb814a6cfcfe48aed7293a857d
a90bdd15eafdfcff74eb1ca92b124aa9656a7079
refs/heads/master
2022-05-18T03:28:49.088852
2022-03-20T09:43:48
2022-03-20T09:43:48
684,933
8
2
NOASSERTION
2020-05-22T08:28:29
2010-05-25T10:29:50
C
UTF-8
Scheme
false
false
2,205
scm
error-dialog.scm
;;; ;;; gtk/error-dialog.scm - reports error via GUI dialog ;;; ;;; Copyright(C) 2002 by Shiro Kawai ([email protected]) ;;; ;;; Permission to use, copy, modify, distribute this software and ;;; accompanying documentation for any purpose is hereby granted, ;;; provided that existing copyright notices are retained in all ;;; copies and that this notice is included verbatim in all ;;; distributions. ;;; This software is provided as is, without express or implied ;;; warranty. In no circumstances the author(s) shall be liable ;;; for any damages arising out of the use of this software. ;;; ;; this file is to be autoloaded. ;; makes an error to be reported using gtk dialog. (define-module gtk.error-dialog (use gauche.mop.singleton) (use gauche.threads) (use gtk) (export gtk-scheme-enable-error-dialog <error-dialog>)) (select-module gtk.error-dialog) (define-class <error-dialog> (<singleton-mixin>) ((widget) (label) (parent :init-keyword :parent :init-value #f) (flags :init-keyword :flags :init-value 0) )) (define-method initialize ((self <error-dialog>) initargs) (next-method) (let* ([dialog (gtk-dialog-new-with-buttons "Error" (ref self 'parent) (ref self 'flags) GTK_STOCK_OK GTK_RESPONSE_ACCEPT)] [vbox (ref dialog 'vbox)] [label (gtk-label-new "")]) (g-signal-connect dialog "response" (lambda _ (gtk-widget-hide-all dialog))) (gtk-box-pack-start vbox label #t #t 10) (slot-set! self 'widget dialog) (slot-set! self 'label label) )) (define (gtk-report-error exc) (let ([self (instance-of <error-dialog>)] [mesg (if (is-a? exc <error>) #"*** ERROR: ~(ref exc 'message)" (x->string exc))]) (gtk-label-set-text (ref self 'label) mesg) (gtk-widget-show-all (ref self 'widget)))) (define (gtk-scheme-enable-error-dialog . maybe-parent) (make <error-dialog> :parent (get-optional maybe-parent #f)) (gtk-callback-error-handler gtk-report-error))
false
0e6534598081f866f8f466805e4e35f915807fad
f08220a13ec5095557a3132d563a152e718c412f
/logrotate/skel/usr/share/guile/2.0/ice-9/threads.scm
9f9e1bf8e90dd05f5c2eaba7f180ef0d19084bf1
[ "Apache-2.0" ]
permissive
sroettger/35c3ctf_chals
f9808c060da8bf2731e98b559babd4bf698244ac
3d64486e6adddb3a3f3d2c041242b88b50abdb8d
refs/heads/master
2020-04-16T07:02:50.739155
2020-01-15T13:50:29
2020-01-15T13:50:29
165,371,623
15
5
Apache-2.0
2020-01-18T11:19:05
2019-01-12T09:47:33
Python
UTF-8
Scheme
false
false
6,388
scm
threads.scm
;;;; Copyright (C) 1996, 1998, 2001, 2002, 2003, 2006, 2010, 2011, ;;;; 2012 Free Software Foundation, Inc. ;;;; ;;;; This library is free software; you can redistribute it and/or ;;;; modify it under the terms of the GNU Lesser General Public ;;;; License as published by the Free Software Foundation; either ;;;; version 3 of the License, or (at your option) any later version. ;;;; ;;;; This library is distributed in the hope that it will be useful, ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ;;;; Lesser General Public License for more details. ;;;; ;;;; You should have received a copy of the GNU Lesser General Public ;;;; License along with this library; if not, write to the Free Software ;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ;;;; ;;;; ---------------------------------------------------------------- ;;;; threads.scm -- User-level interface to Guile's thread system ;;;; 4 March 1996, Anthony Green <[email protected]> ;;;; Modified 5 October 1996, MDJ <[email protected]> ;;;; Modified 6 April 2001, ttn ;;;; ---------------------------------------------------------------- ;;;; ;;; Commentary: ;; This module is documented in the Guile Reference Manual. ;; Briefly, one procedure is exported: `%thread-handler'; ;; as well as four macros: `make-thread', `begin-thread', ;; `with-mutex' and `monitor'. ;;; Code: (define-module (ice-9 threads) #:use-module (ice-9 futures) #:use-module (ice-9 match) #:export (begin-thread parallel letpar make-thread with-mutex monitor par-map par-for-each n-par-map n-par-for-each n-for-each-par-map %thread-handler)) ;;; Macros first, so that the procedures expand correctly. (define-syntax-rule (begin-thread e0 e1 ...) (call-with-new-thread (lambda () e0 e1 ...) %thread-handler)) (define-syntax parallel (lambda (x) (syntax-case x () ((_ e0 ...) (with-syntax (((tmp0 ...) (generate-temporaries (syntax (e0 ...))))) #'(let ((tmp0 (future e0)) ...) (values (touch tmp0) ...))))))) (define-syntax-rule (letpar ((v e) ...) b0 b1 ...) (call-with-values (lambda () (parallel e ...)) (lambda (v ...) b0 b1 ...))) (define-syntax-rule (make-thread proc arg ...) (call-with-new-thread (lambda () (proc arg ...)) %thread-handler)) (define-syntax-rule (with-mutex m e0 e1 ...) (let ((x m)) (dynamic-wind (lambda () (lock-mutex x)) (lambda () (begin e0 e1 ...)) (lambda () (unlock-mutex x))))) (define-syntax-rule (monitor first rest ...) (with-mutex (make-mutex) first rest ...)) (define (par-mapper mapper cons) (lambda (proc . lists) (let loop ((lists lists)) (match lists (((heads tails ...) ...) (let ((tail (future (loop tails))) (head (apply proc heads))) (cons head (touch tail)))) (_ '()))))) (define par-map (par-mapper map cons)) (define par-for-each (par-mapper for-each (const *unspecified*))) (define (n-par-map n proc . arglists) (let* ((m (make-mutex)) (threads '()) (results (make-list (length (car arglists)))) (result results)) (do ((i 0 (+ 1 i))) ((= i n) (for-each join-thread threads) results) (set! threads (cons (begin-thread (let loop () (lock-mutex m) (if (null? result) (unlock-mutex m) (let ((args (map car arglists)) (my-result result)) (set! arglists (map cdr arglists)) (set! result (cdr result)) (unlock-mutex m) (set-car! my-result (apply proc args)) (loop))))) threads))))) (define (n-par-for-each n proc . arglists) (let ((m (make-mutex)) (threads '())) (do ((i 0 (+ 1 i))) ((= i n) (for-each join-thread threads)) (set! threads (cons (begin-thread (let loop () (lock-mutex m) (if (null? (car arglists)) (unlock-mutex m) (let ((args (map car arglists))) (set! arglists (map cdr arglists)) (unlock-mutex m) (apply proc args) (loop))))) threads))))) ;;; The following procedure is motivated by the common and important ;;; case where a lot of work should be done, (not too much) in parallel, ;;; but the results need to be handled serially (for example when ;;; writing them to a file). ;;; (define (n-for-each-par-map n s-proc p-proc . arglists) "Using N parallel processes, apply S-PROC in serial order on the results of applying P-PROC on ARGLISTS." (let* ((m (make-mutex)) (threads '()) (no-result '(no-value)) (results (make-list (length (car arglists)) no-result)) (result results)) (do ((i 0 (+ 1 i))) ((= i n) (for-each join-thread threads)) (set! threads (cons (begin-thread (let loop () (lock-mutex m) (cond ((null? results) (unlock-mutex m)) ((not (eq? (car results) no-result)) (let ((arg (car results))) ;; stop others from choosing to process results (set-car! results no-result) (unlock-mutex m) (s-proc arg) (lock-mutex m) (set! results (cdr results)) (unlock-mutex m) (loop))) ((null? result) (unlock-mutex m)) (else (let ((args (map car arglists)) (my-result result)) (set! arglists (map cdr arglists)) (set! result (cdr result)) (unlock-mutex m) (set-car! my-result (apply p-proc args)) (loop)))))) threads))))) (define (thread-handler tag . args) (let ((n (length args)) (p (current-error-port))) (display "In thread:" p) (newline p) (if (>= n 3) (display-error #f p (car args) (cadr args) (caddr args) (if (= n 4) (cadddr args) '())) (begin (display "uncaught throw to " p) (display tag p) (display ": " p) (display args p) (newline p))) #f)) ;;; Set system thread handler (define %thread-handler thread-handler) ;;; threads.scm ends here
true
bdb99c13d42aab9419c5be907adc582e7000ad3a
ab05b79ab17619f548d9762a46199dc9eed6b3e9
/sitelib/ypsilon/gdk/event.scm
9d67b4c6131a315224a0ce3b216bdeef6adb353b
[ "BSD-2-Clause" ]
permissive
lambdaconservatory/ypsilon
2dce9ff4b5a50453937340bc757697b9b4839dee
f154436db2b3c0629623eb2a53154ad3c50270a1
refs/heads/master
2021-02-28T17:44:05.571304
2017-12-17T12:29:00
2020-03-08T12:57:52
245,719,032
1
0
NOASSERTION
2020-03-07T23:08:26
2020-03-07T23:08:25
null
UTF-8
Scheme
false
false
4,325
scm
event.scm
#!nobacktrace ;;; Ypsilon Scheme System ;;; Copyright (c) 2004-2009 Y.FUJITA / LittleWing Company Limited. ;;; See license.txt for terms and conditions of use. (library (ypsilon gdk event) (export gdk_event_copy gdk_event_free gdk_event_get gdk_event_get_axis gdk_event_get_coords gdk_event_get_graphics_expose gdk_event_get_root_coords gdk_event_get_screen gdk_event_get_state gdk_event_get_time gdk_event_get_type gdk_event_handler_set gdk_event_mask_get_type gdk_event_new gdk_event_peek gdk_event_put gdk_event_request_motions gdk_event_send_client_message gdk_event_send_client_message_for_display gdk_event_send_clientmessage_toall gdk_event_set_screen gdk_event_type_get_type) (import (rnrs) (ypsilon ffi)) (define lib-name (cond (on-linux "libgdk-x11-2.0.so.0") (on-sunos "libgdk-x11-2.0.so.0") (on-freebsd "libgdk-x11-2.0.so.0") (on-openbsd "libgdk-x11-2.0.so.0") (on-darwin "Gtk.framework/Gtk") (on-windows "libgdk-win32-2.0-0.dll") (else (assertion-violation #f "can not locate GDK library, unknown operating system")))) (define lib (load-shared-object lib-name)) (define-syntax define-function (syntax-rules () ((_ ret name args) (define name (c-function lib lib-name ret name args))))) ;; GdkEvent* gdk_event_copy (const GdkEvent* event) (define-function void* gdk_event_copy (void*)) ;; void gdk_event_free (GdkEvent* event) (define-function void gdk_event_free (void*)) ;; GdkEvent* gdk_event_get (void) (define-function void* gdk_event_get ()) ;; gboolean gdk_event_get_axis (const GdkEvent* event, GdkAxisUse axis_use, gdouble* value) (define-function int gdk_event_get_axis (void* int void*)) ;; gboolean gdk_event_get_coords (const GdkEvent* event, gdouble* x_win, gdouble* y_win) (define-function int gdk_event_get_coords (void* void* void*)) ;; GdkEvent* gdk_event_get_graphics_expose (GdkWindow* window) (define-function void* gdk_event_get_graphics_expose (void*)) ;; gboolean gdk_event_get_root_coords (const GdkEvent* event, gdouble* x_root, gdouble* y_root) (define-function int gdk_event_get_root_coords (void* void* void*)) ;; GdkScreen* gdk_event_get_screen (const GdkEvent* event) (define-function void* gdk_event_get_screen (void*)) ;; gboolean gdk_event_get_state (const GdkEvent* event, GdkModifierType* state) (define-function int gdk_event_get_state (void* void*)) ;; guint32 gdk_event_get_time (const GdkEvent* event) (define-function uint32_t gdk_event_get_time (void*)) ;; GType gdk_event_get_type (void) (define-function unsigned-long gdk_event_get_type ()) ;; void gdk_event_handler_set (GdkEventFunc func, gpointer data, GDestroyNotify notify) (define-function void gdk_event_handler_set ((c-callback void (void* void*)) void* (c-callback void (void*)))) ;; GType gdk_event_mask_get_type (void) (define-function unsigned-long gdk_event_mask_get_type ()) ;; GdkEvent* gdk_event_new (GdkEventType type) (define-function void* gdk_event_new (int)) ;; GdkEvent* gdk_event_peek (void) (define-function void* gdk_event_peek ()) ;; void gdk_event_put (const GdkEvent* event) (define-function void gdk_event_put (void*)) ;; void gdk_event_request_motions (const GdkEventMotion* event) (define-function void gdk_event_request_motions (void*)) ;; gboolean gdk_event_send_client_message (GdkEvent* event, GdkNativeWindow winid) (define-function int gdk_event_send_client_message (void* uint32_t)) ;; gboolean gdk_event_send_client_message_for_display (GdkDisplay* display, GdkEvent* event, GdkNativeWindow winid) (define-function int gdk_event_send_client_message_for_display (void* void* uint32_t)) ;; void gdk_event_send_clientmessage_toall (GdkEvent* event) (define-function void gdk_event_send_clientmessage_toall (void*)) ;; void gdk_event_set_screen (GdkEvent* event, GdkScreen* screen) (define-function void gdk_event_set_screen (void* void*)) ;; GType gdk_event_type_get_type (void) (define-function unsigned-long gdk_event_type_get_type ()) ) ;[end]
true
89f043540c77bacde8ffb6a04fd6f8ea496f746d
fae4190f90ada065bc9e5fe64aab0549d4d4638a
/pre-effect/formalism/redex-model.ss
741ea8a4bf70fe2b4754ea83d5c1e59df6ba4ba9
[]
no_license
ilya-klyuchnikov/old-typed-racket
f161481661a2ed5cfc60e268f5fcede728d22488
fa7c1807231f447ff37497e89b25dcd7a9592f64
refs/heads/master
2021-12-08T04:19:59.894779
2008-04-13T10:54:34
2008-04-13T10:54:34
null
0
0
null
null
null
null
UTF-8
Scheme
false
false
12,068
ss
redex-model.ss
(module redex-model mzscheme (require (planet "reduction-semantics.ss" ("robby" "redex.plt" 2 6)) (planet "gui.ss" ("robby" "redex.plt" 2 6)) (planet "subst.ss" ("robby" "redex.plt" 2 6)) (lib "list.ss") (lib "trace.ss") (lib "match.ss")) (require (planet "environment.ss" ("cobbe" "environment.plt" 3 0))) (define occur-lang (language (e (e e) (if e e e) wrong x v) (E (E e) (v E) (if E e e) hole) (v (lambda (x : t) e) number boolean c) (boolean #t #f) (t any) (c add1 number? boolean? zero? not) (x (variable-except lambda add1 if number? boolean? zero? not)))) (define occur-subst (subst [`(lambda (,v : ,t) ,body) (all-vars (list v)) (build (lambda (vars body) `(lambda (,@vars : ,t) ,body))) (subterm (list v) body)] [`(if ,e1 ,e2 ,e3) (all-vars '()) (build (lambda (vars e1 e2 e3) `(if ,e1 ,e2 ,e3))) (subterm '() e1) (subterm '() e2) (subterm '() e3)] [(or (? boolean?) (? (lambda (x) (eq? x 'wrong))) (? number?)) (constant)] [(? symbol?) (variable)] [`(,fun ,arg) (all-vars '()) (build (lambda (vars fun arg) `(,fun ,arg))) (subterm '() fun) (subterm '() arg)])) (define occur? (language->predicate occur-lang 'e)) (define value? (language->predicate occur-lang 'v)) (define-syntax red/context (syntax-rules () [(_ nm . rest) (reduction/context/name nm occur-lang E . rest)])) ;; free-vars : e -> (listof x) (define free-vars (metafunction occur-lang [(e_1 e_2) ,(append (free-vars (term e_1)) (free-vars (term e_2)))] [x_1 ,(list (term x_1))] [(if e_1 e_2 e_3) ,(append (free-vars (term e_1)) (free-vars (term e_2)) (free-vars (term e_3)))] [(lambda (x_1) e_1) ,(remq* (term (x_1)) (free-vars (term e_1)))] [v_1 ,null])) (define delta (metafunction occur-lang [(add1 v_1) ,(if (number? (term v_1)) (add1 (term v_1)) (term wrong))] [(zero? v_1) ,(if (number? (term v_1)) (= 0 (term v_1)) (term wrong))] [(not v_1) ,(if (boolean? (term v_1)) (not (term v_1)) (term wrong))] [(number? v_1) ,(if (number? (term v_1)) (term #t) (term #f))] [(boolean? v_1) ,(if (boolean? (term v_1)) (term #t) (term #f))])) (define reductions (list (red/context "E-Beta" ((lambda (variable_1 : t_1) e_body) v_arg) (occur-subst (term variable_1) (term v_arg) (term e_body))) (red/context "E-IfTrue" (if #t e_2 e_3) (term e_2)) (red/context "E-IfFalse" (if #f e_2 e_3) (term e_3)) ;; for the purposes of the model, this collapes rules E-Delta and E-Wrong (reduction/name "E-Delta" occur-lang (in-hole (name E E) (c_op v_arg)) (let ([v (delta (term (c_op v_arg)))]) (if (equal? v (term wrong)) v (term (in-hole E ,v))))) )) (define enable-T-IfAnd (make-parameter #f)) (define enable-T-AbsPred (make-parameter #f)) (define enable-T-IfTrue (make-parameter #t)) (define enable-T-IfFalse (make-parameter #t)) (define-struct type () #f) (define-struct (top-type type) () #f) (define-struct (base-type type) (name) #f) (define-struct (proc-type type) (arg result latent) #f) (define-struct (union-type type) (elems) #f) (define-struct effect () #f) (define-struct (no-effect effect) () #f) (define-struct (latent-type-effect effect) (t) #f) (define-struct (type-effect effect) (t v) #f) (define-struct (true-effect effect) () #f) (define-struct (false-effect effect) () #f) (define-struct (var-effect effect) (v) #f) (define N (make-base-type 'Number)) (define B (make-base-type 'Boolean)) (define NE (make-no-effect)) (define Top (make-top-type)) (define-struct tc-result (type effect) #f) (define initial-env (symbol-env (number-var N) (boolean-var B))) ;; this does type intersection (define (type-restrict old restriction) (if (subtype restriction old) restriction (match old [($ union-type e) (apply Un (filter (lambda (x) (subtype x restriction)) e))] [_ restriction]))) ;; this is set minus on types (define (type-minus old remove) (if (subtype old remove) (Un) (match old [($ union-type e) (apply Un (map (lambda (x) (type-minus x remove)) e))] [_ old]))) (define (update-env env key f) (extend-env (list key) (list (f (lookup env key))) env)) (define ((envop f) env eff) (match eff [($ type-effect t v) (update-env env v (lambda (old) (f old t)))] [_ env])) (define env+ (envop type-restrict)) (define env- (envop type-minus)) (define ret (case-lambda [(a) (make-tc-result a NE)] [(a b) (make-tc-result a b)])) (define -> (case-lambda [(a b) (make-proc-type a b NE)] [(a b c) (make-proc-type a b (make-latent-type-effect c))])) (define (Un . elems) (cond [(= 1 (length elems)) (car elems)] [else (let* ([unions (filter union-type? elems)] [not-unions (filter (lambda (x) (not (union-type? x))) elems)] [lists (map union-type-elems unions)] [l (apply append lists)] [l* (append l not-unions)]) (if (= 1 (length l*)) (car l*) (make-union-type l*)))])) (define delta-t (metafunction occur-lang [add1 ,(ret (-> N N))] [not ,(ret (-> B B))] [zero? ,(ret (-> N B))] [number? ,(ret (-> Top B N))] [boolean? ,(ret (-> Top B B))])) (define-struct (exn:tc exn:fail) (stuff) #f) (define (fail! . args) (apply error "typechecking failed" args)) (define (parse-type t) (match t ['number N] ['boolean B] ['top Top] [(a '-> b '& c) (make-proc-type (parse-type a) (parse-type b) (parse-type c))] [('U e ...) (make-union-type (map parse-type e))])) (define (subtype a b) (match (list a b) [(a a) #t] [(_ ($ top-type)) #t] [(($ proc-type a b latent) ($ proc-type a* b* latent)) (and (subtype a* a) (subtype b b*))] [(($ union-type e) b) (andmap (lambda (x) (subtype x b)) e)] [(a ($ union-type e)) (ormap (lambda (x) (subtype a x)) e)] [_ #f])) ;(trace type-minus) ;(trace type-restrict) ;(trace env+) (define (null-intersect? a b) (match (list a b) [(a b) (=> unmatch) (not (or (subtype a b) (subtype b a) (unmatch)))] [((? base-type?) (? base-type?)) #t] [else #f] )) (define (typecheck e env) (define tc/local (metafunction occur-lang [number ,(ret N NE)] [boolean_1 ,(ret B (if (term boolean_1) (make-true-effect) (make-false-effect)))] [c_1 ,(delta-t (term c_1))] [x_1 ,(ret (lookup env (term x_1) (lambda (x) (fail! "lookup" x))) (make-var-effect (term x_1)))] [(if e_test e_then e_else) ,(match-let* ([($ tc-result test-ty test-eff) (tc/local (term e_test))]) (cond ;; this is slightly more aggressive in terms of the returned effect than the model ;; this is neccessary for typechecking tc7 [(and (enable-T-IfFalse) (false-effect? test-eff)) (tc/local (term e_else))] [(and (enable-T-IfTrue) (true-effect? test-eff)) (tc/local (term e_then))] [else (match-let* ([($ tc-result ty1 eff1) (typecheck (term e_then) (env+ env test-eff))] [($ tc-result ty2 eff2) (typecheck (term e_else) (env- env test-eff))] [new-eff (if (and (enable-T-IfAnd) (false-effect? eff2)) test-eff NE)]) (ret (Un ty1 ty2) new-eff))]))] [(lambda (x_1 : t_1) e_body) ,(match-let* ([in (parse-type (term t_1))] [($ tc-result out out-eff) (typecheck (term e_body) (extend-env (list (term x_1)) (list in) env))]) (match out-eff [(and (? (lambda _ enable-T-AbsPred)) ($ type-effect t v) (= type-effect-v (? (lambda (s) (eq? s (term x_1)))))) (printf "got here~n") (ret (-> in out t))] [_ (ret (-> in out))]))] [(e_1 e_2) ,(match-let* ([($ tc-result ($ proc-type in out latent) eff) (tc/local (term e_1))] [($ tc-result arg arg-eff) (tc/local (term e_2))] [res-eff (cond [(and (latent-type-effect? latent) (var-effect? arg-eff)) (make-type-effect (latent-type-effect-t latent) (var-effect-v arg-eff))] [(and (latent-type-effect? latent) (subtype arg (latent-type-effect-t latent))) (make-true-effect)] [(and (latent-type-effect? latent) (null-intersect? arg (latent-type-effect-t latent))) (make-false-effect)] [else NE])]) (if (subtype arg in) (ret out res-eff) (error "argument not subtype" arg in e)))] [e_1 ,(fail! "unknown expression" (term e_1))])) (tc/local e)) (define (tc e) (typecheck e initial-env)) (define (check e node) (let* ([parents (term-node-parents node)] [parent-exprs (map term-node-expr parents)]) (with-handlers ([exn:fail? (lambda _ #f)]) (match-let* ([(($ tc-result parent-types _) ...) ;; if the parents don't typecheck, just ignore them (with-handlers ([exn:fail? (lambda _ '())]) (map tc parent-exprs))] [($ tc-result cur-type _) (tc e)]) (andmap (lambda (t) (subtype cur-type t)) parent-types))))) (define (r t) (reduce reductions t)) (define (tr t) (traces/pred occur-lang reductions (list t) check)) (define t1 (term ((lambda (x : top) x) 3))) (define t2 (term ((lambda (x : number) (add1 x)) 3))) (define t3 (term ((lambda (x : top) (if (number? x) (add1 x) 0)) #t))) (define t4 (term ((lambda (x : (U number boolean)) (if (number? x) (add1 x) 0)) #t))) (define t5 (term ((lambda (x : (U number boolean)) (if (number? x) (zero? x) (not x))) #t))) ;; these use the experimental features ;; T-AbsPred (define t6 (term ((lambda (x : top) (if ((lambda (y : top) (number? y)) x) (add1 x) 0)) #t))) ;; T-IfAnd (define t7 (term ((lambda (x : top) (if (if (boolean? x) x #f) (not x) #t)) 0))) (define (trx t) (parameterize ([enable-T-IfAnd #t] [enable-T-AbsPred #t]) (tr t))) (print-struct #t) )
true
45e389250a3a4c2e5c806e559b6991a345fdd81f
6b675e55991fdcfc249da935e3ff15ba62e0f2ed
/info.ss
dea4d8742b7eea70f404b8804289445f5c32f5bc
[]
no_license
mrmathematica/MrMathematica
a0addbab10561e6edd1c14adf6c44fe51b8d9f03
801cd29e1e4ac57a71e86fa0f4b750a60068c75d
refs/heads/master
2021-06-22T09:56:52.409291
2020-12-30T11:46:02
2020-12-30T11:46:02
12,832,108
8
0
null
null
null
null
UTF-8
Scheme
false
false
488
ss
info.ss
#lang setup/infotab (define name "MrMathematica") (define blurb '("Union of Mathematica and Scheme.")) (define categories '(scientific devtools)) (define homepage "http://www.cs.utah.edu/~czhu/SchemeLink/mrmma.html") (define primary-file "main.ss") (define scribblings '(("mrmma.scrbl" () (interop)))) (define tools '(("tool.ss"))) (define tool-names '("MrMathematica")) (define tool-icons '("mathematica8.png")) (define tool-urls '("http://www.cs.utah.edu/~czhu/SchemeLink/mrmma.html"))
false
0f9a438c4c5d0e79fd7af24888611d340778ccb3
8f0ceb57d807ba1c92846ae899736b0418003e4f
/INF2810/practice for exam/exercises/1_3.scm
7acebca0eacdbc60cd45c742c8abcc270a391394
[]
no_license
hovdis/UiO
4549053188302af5202c8294a89124adb4eb981b
dcaa236314d5b0022e6be7c2cd0b48e88016475a
refs/heads/master
2020-09-16T04:04:22.283098
2020-02-26T08:21:21
2020-02-26T08:21:21
223,645,789
0
0
null
null
null
null
UTF-8
Scheme
false
false
377
scm
1_3.scm
(define (sum a b c) (if (and (> a b) (> c b)) (square a c) (if (and (> b a) (> c a)) (square b c) (if (and (> a c) (> b c)) (square a b))))) (define (square x y) (+ (* x x) (* y y))) (define (sum2 a b c) (cond ((and (> a b) (> c b)) (square a c)) ((and (> b a) (> c a)) (square b c)) (else (square a b))))
false
5faa62bd428e5ab1a9cbca8039442702bd4566cc
abc7bd420c9cc4dba4512b382baad54ba4d07aa8
/src/old/regiment_script.ss
0b67dfe1774122d869459d664f431c428fe6e962
[ "BSD-3-Clause" ]
permissive
rrnewton/WaveScript
2f008f76bf63707761b9f7c95a68bd3e6b9c32ca
1c9eff60970aefd2177d53723383b533ce370a6e
refs/heads/master
2021-01-19T05:53:23.252626
2014-10-08T15:00:41
2014-10-08T15:00:41
1,297,872
10
2
null
null
null
null
UTF-8
Scheme
false
false
614
ss
regiment_script.ss
#! /bin/sh #| if (which chez > /dev/null); then exec chez --script "$0" `pwd` ${1+"$@"}; elif (which petite > /dev/null); then exec petite --script "$0" `pwd` ${1+"$@"}; elif [ -f $REGIMENTD/depends/petite ]; then exec $REGIMENTD/depends/petite --script "$0" `pwd` ${1+"$@"}; else echo CHEZ SCHEME not found.; exit -1 fi |# ;;;; This script is just an executable wrapper script to regiment.ss ;; First argument is the directory ;(parameterize ([current-directory "~/cur"]) (parameterize ([current-directory (car (command-line-arguments))]) (load (string-append (getenv "REGIMENTD") "/src/regiment.ss")))
false
ccbb63f1484117999ad3f321eeb4124f488ea45b
6488db22a3d849f94d56797297b2469a61ad22bf
/synch/synch.scm
d12389391733cbe061ad9997f7a885de8f5280ea
[]
no_license
bazurbat/chicken-eggs
34d8707cecbbd4975a84ed9a0d7addb6e48899da
8e741148d6e0cd67a969513ce2a7fe23241df648
refs/heads/master
2020-05-18T05:06:02.090313
2015-11-18T16:07:12
2015-11-18T16:07:12
22,037,751
0
0
null
null
null
null
UTF-8
Scheme
false
false
20,479
scm
synch.scm
;;;; synch.scm ;;;; Kon Lovett, Mar '06 ;; Issues ;; ;; - syntax checking is minimal so expansion errors are cryptic (module synch (;export ;; synch synch-with call/synch call-with/synch apply/synch apply-with/synch let/synch set!/synch synch/lock synch/unlock object/synch record/synch record-synch/lock record-synch/unlock ;; %synch %synch-with %call/synch %call-with/synch %apply/synch %apply-with/synch %let/synch %set!/synch %synch/lock %synch/unlock %object/synch %record/synch %record-synch/lock %record-synch/unlock ;; make-object/synch object?/synch ;; define-constructor/synch define-predicate/synch (define-operation/synch check-mutex+object) define-operation/%synch) (import scheme (only chicken define-for-syntax optional void unless warning gensym dynamic-wind) (only data-structures any?) (only srfi-18 thread? make-mutex mutex? mutex-specific mutex-specific-set! mutex-lock! mutex-unlock! mutex-state) (only type-checks define-check+error-type) ) (import-for-syntax (only data-structures conc)) (require-library data-structures srfi-18 type-checks) ;;; (define-for-syntax (recmuxnam nam) (string->symbol (conc nam #\- 'mutex))) ;;; Protected (define-syntax synch (syntax-rules () ((_ (?mtx (?lock-arg0 ...) (?unlock-arg0 ...)) ?body ...) (let ((mtx ?mtx)) (dynamic-wind (lambda () (mutex-lock! mtx ?lock-arg0 ...)) (lambda () ?body ...) (lambda () (mutex-unlock! mtx ?unlock-arg0 ...)) ) ) ) ((_ (?mtx (?lock-arg0 ...)) ?body ...) (synch (?mtx (?lock-arg0 ...) ()) ?body ...) ) ((_ ?mtx ?body ...) (synch (?mtx () ()) ?body ...) ) ) ) (define-syntax synch-with (er-macro-transformer (lambda (frm rnm cmp) (##sys#check-syntax 'synch-with frm '(_ _ variable . #(_ 0))) (let ((_dynamic-wind (rnm 'dynamic-wind)) (_let (rnm 'let)) (_lambda (rnm 'lambda)) (_mutex-unlock! (rnm 'mutex-unlock!)) (_mutex-specific (rnm 'mutex-specific)) (_mutex-lock! (rnm 'mutex-lock!)) (mtxvar (rnm (gensym)))) (let ((?mtx (cadr frm)) (?var (caddr frm)) (?body (cdddr frm)) ) (call-with-values (lambda () (if (not (pair? ?mtx)) (values ?mtx '() '()) (let ((mtx (car ?mtx)) (lock-args (if (<= 2 (length ?mtx)) (cadr ?mtx) '())) (unlock-args (if (= 3 (length ?mtx)) (caddr ?mtx) '())) ) (values mtx lock-args unlock-args) ) ) ) (lambda (?mtx ?lock-args ?unlock-args) `(,_let ((,mtxvar ,?mtx)) (,_let ((,?var (,_mutex-specific ,mtxvar))) (,_dynamic-wind (,_lambda () (,_mutex-lock! ,mtxvar ,@?lock-args)) (,_lambda () ,@?body) (,_lambda () (,_mutex-unlock! ,mtxvar ,@?unlock-args)) ) ) ) ) ) ) ) ) ) ) (define-syntax call/synch (syntax-rules () ((_ (?mtx (?lock-arg0 ...) (?unlock-arg0 ...)) ?proc ?arg0 ...) (let ((mtx ?mtx)) (dynamic-wind (lambda () (mutex-lock! mtx ?lock-arg0 ...)) (lambda () (?proc ?arg0 ...)) (lambda () (mutex-unlock! mtx ?unlock-arg0 ...)) ) ) ) ((_ (?mtx (?lock-arg0 ...)) ?proc ?arg0 ...) (call/synch (?mtx (?lock-arg0 ...) ()) ?proc ?arg0 ...) ) ((_ ?mtx ?proc ?arg0 ...) (call/synch (?mtx () ()) ?proc ?arg0 ...) ) ) ) (define-syntax call-with/synch (syntax-rules () ((_ (?mtx (?lock-arg0 ...) (?unlock-arg0 ...)) ?proc ?arg0 ...) (let ((mtx ?mtx)) (dynamic-wind (lambda () (mutex-lock! mtx ?lock-arg0 ...)) (lambda () (?proc (mutex-specific mtx) ?arg0 ...)) (lambda () (mutex-unlock! mtx ?unlock-arg0 ...)) ) ) ) ((_ (?mtx (?lock-arg0 ...)) ?proc ?arg0 ...) (call-with/synch (?mtx (?lock-arg0 ...) ()) ?proc ?arg0 ...) ) ((_ ?mtx ?proc ?arg0 ...) (call-with/synch (?mtx () ()) ?proc ?arg0 ...) ) ) ) (define-syntax apply/synch (syntax-rules () ((_ (?mtx (?lock-arg0 ...) (?unlock-arg0 ...)) ?proc ?arg0 ...) (let ((mtx ?mtx)) (dynamic-wind (lambda () (mutex-lock! mtx ?lock-arg0 ...)) (lambda () (apply ?proc ?arg0 ...)) (lambda () (mutex-unlock! mtx ?unlock-arg0 ...)) ) ) ) ((_ (?mtx (?lock-arg0 ...)) ?proc ?arg0 ...) (apply/synch (?mtx (?lock-arg0 ...) ()) ?proc ?arg0 ...) ) ((_ ?mtx ?proc ?arg0 ...) (apply/synch (?mtx () ()) ?proc ?arg0 ...) ) ) ) (define-syntax apply-with/synch (syntax-rules () ((_ (?mtx (?lock-arg0 ...) (?unlock-arg0 ...)) ?proc ?arg0 ...) (let ((mtx ?mtx)) (dynamic-wind (lambda () (mutex-lock! mtx ?lock-arg0 ...)) (lambda () (apply ?proc (mutex-specific mtx) ?arg0 ...)) (lambda () (mutex-unlock! mtx ?unlock-arg0 ...)) ) ) ) ((_ (?mtx (?lock-arg0 ...)) ?proc ?arg0 ...) (apply-with/synch (?mtx (?lock-arg0 ...) ()) ?proc ?arg0 ...) ) ((_ ?mtx ?proc ?arg0 ...) (apply-with/synch (?mtx () ()) ?proc ?arg0 ...) ) ) ) (define-syntax let/synch (er-macro-transformer (lambda (frm rnm cmp) (##sys#check-syntax 'let/synch frm '(_ list . _)) (let ((_synch-with (rnm 'synch-with))) (let* ((?body (cddr frm)) (res (let loop ((bnds (cadr frm))) (if (null? bnds) ?body (let ((?bnd (car bnds))) (##sys#check-syntax 'let/synch ?bnd '(variable . _)) `((,_synch-with ,(cadr ?bnd) ,(car ?bnd) ,@(loop (cdr bnds)))) ) ) ) ) ) (car res) ) ) ) ) ) (define-syntax set!/synch (er-macro-transformer (lambda (frm rnm cmp) (##sys#check-syntax 'set!/synch frm '(_ pair . _)) (let ((_synch-with (rnm 'synch-with)) (_mutex-specific (rnm 'mutex-specific)) (_mutex-specific-set! (rnm 'mutex-specific-set!)) (_begin (rnm 'begin))) (let ((?bnd (cadr frm)) (?body (cddr frm))) (let ((?var (car ?bnd)) (?mtx (cadr ?bnd))) `(,_synch-with ,?mtx ,?var (,_mutex-specific-set! ,?mtx (,_begin ,@?body)) (,_mutex-specific ,?mtx) ) ) ) ) ) ) ) (define-syntax synch/lock (syntax-rules () ((_ (?mtx (?lock-arg0 ...)) ?body ...) (let ((mtx ?mtx) (ok? #f)) (mutex-lock! mtx) (dynamic-wind (lambda () (mutex-lock! mtx ?lock-arg0 ...)) (lambda () (let ((res (begin ?body ...))) (set! ok? #t) res)) (lambda () (unless ok? (mutex-unlock! mtx)))) ) ) ((_ ?mtx ?body ...) (synch/lock (?mtx ()) ?body ...) ) ) ) (define-syntax synch/unlock (syntax-rules () ((_ (?mtx (?unlock-arg0 ...)) ?body ...) (let ((mtx ?mtx)) (dynamic-wind (lambda () (unless (thread? (mutex-state mtx)) (warning 'synch/unlock "mutex is not locked - locking") (mutex-lock! mtx))) (lambda () ?body ...) (lambda () (mutex-unlock! mtx ?unlock-arg0 ...)) ) ) ) ((_ ?mtx ?body ...) (synch/unlock (?mtx ()) ?body ...) ) ) ) (define-syntax object/synch (er-macro-transformer (lambda (frm rnm cmp) (##sys#check-syntax 'object/synch frm '(_ _ . _)) (let ((_synch-with (rnm 'synch-with)) (_>< (rnm '><)) (var (rnm (gensym))) (mtx (cadr frm))) (let body-loop ((unparsed (cddr frm)) (parsed '())) (if (not (null? unparsed)) (let ((expr (car unparsed)) (next (cdr unparsed))) (let expr-loop ((rest expr) (parsedexpr '())) (cond ((null? rest) (body-loop next (cons (reverse parsedexpr) parsed))) ((pair? rest) (let ((arg (car rest)) (next (cdr rest))) (if (cmp _>< arg) (expr-loop next (cons var parsedexpr)) (expr-loop next (cons arg parsedexpr)) ) )) ((cmp _>< rest) (body-loop next (cons var parsed))) (else (body-loop next (cons rest parsed))) ) ) ) `(,_synch-with ,mtx ,var ,@(reverse parsed)) ) ) ) ) ) ) (define-syntax record/synch (er-macro-transformer (lambda (frm rnm cmp) (##sys#check-syntax 'record/synch frm '(_ symbol _ . _)) (let ((_synch (rnm 'synch))) (let ((?sym (cadr frm)) (?rec (caddr frm)) (?body (cdddr frm))) `(,_synch (,(recmuxnam ?sym) ,?rec) ,@?body) ) ) ) ) ) (define-syntax record-synch/lock (er-macro-transformer (lambda (frm rnm cmp) (##sys#check-syntax 'record-synch/lock frm '(_ symbol _ . _)) (let ((_synch/lock (rnm 'synch/lock))) (let ((?sym (cadr frm)) (?rec (caddr frm)) (?body (cdddr frm))) `(,_synch/lock (,(recmuxnam ?sym) ,?rec) ,@?body) ) ) ) ) ) (define-syntax record-synch/unlock (er-macro-transformer (lambda (frm rnm cmp) (##sys#check-syntax 'record-synch/unlock frm '(_ symbol _ . _)) (let ((_synch/unlock (rnm 'synch/unlock))) (let ((?sym (cadr frm)) (?rec (caddr frm)) (?body (cdddr frm))) `(,_synch/unlock (,(recmuxnam ?sym) ,?rec) ,@?body) ) ) ) ) ) ;;; Unprotected (define-syntax %*synch (syntax-rules () ((_ (?mtx (?lock-arg0 ...) (?unlock-arg0 ...)) ?body ...) (let ((mtx ?mtx)) (mutex-lock! mtx ?lock-arg0 ...) (call-with-values (lambda () ?body ...) (lambda ret (mutex-unlock! mtx ?unlock-arg0 ...) (apply values ret))) ) ) ((_ ?mtx ?body ...) (%*synch (?mtx () ()) ?body ...) ) ) ) (define-syntax %*synch-with (er-macro-transformer (lambda (frm rnm cmp) (##sys#check-syntax '%*synch-with frm '(_ _ variable . _)) (let ((_call-with-values (rnm 'call-with-values)) (_mutex-specific (rnm 'mutex-specific)) (_mutex-lock! (rnm 'mutex-lock!)) (_mutex-unlock! (rnm 'mutex-unlock!)) (_let (rnm 'let)) (_apply (rnm 'apply)) (_values (rnm 'values)) (_lambda (rnm 'lambda)) (_ret (rnm 'ret)) (mtxvar (rnm (gensym)))) (let ((?mtx (cadr frm)) (?var (caddr frm)) (?body (cdddr frm))) (call-with-values (lambda () (if (not (pair? ?mtx)) (values ?mtx '() '()) (let ((mtx (car ?mtx)) (lock-args (if (<= 2 (length ?mtx)) (cadr ?mtx) '())) (unlock-args (if (= 3 (length ?mtx)) (caddr ?mtx) '())) ) (values mtx lock-args unlock-args) ) ) ) (lambda (?mtx ?lock-args ?unlock-args) `(,_let ((,mtxvar ,?mtx)) (,_let ((,?var (,_mutex-specific ,mtxvar))) (,_mutex-lock! ,mtxvar ,@?lock-args) (,_call-with-values (,_lambda () ,@?body) (,_lambda ,_ret (,_mutex-unlock! ,mtxvar ,@?unlock-args) (,_apply ,_values ,_ret)) ) ) ) ) ) ) ) ) ) ) (define-syntax %synch (syntax-rules () ((_ ?mtx ?body ...) (%*synch ?mtx ?body ...) ) ) ) (define-syntax %synch-with (syntax-rules () ((_ ?mtx ?var ?body ...) (%*synch-with ?mtx ?var ?body ...) ) ) ) (define-syntax %call/synch (syntax-rules () ((_ ?mtx ?proc ?arg0 ...) (%*synch ?mtx (?proc ?arg0 ...)) ) ) ) (define-syntax %call-with/synch (syntax-rules () ((_ ?mtx ?proc ?arg0 ...) (%*synch-with ?mtx var (?proc var ?arg0 ...)) ) ) ) (define-syntax %apply/synch (syntax-rules () ((_ ?mtx ?proc ?arg0 ...) (%*synch ?mtx (apply ?proc ?arg0 ...)) ) ) ) (define-syntax %apply-with/synch (syntax-rules () ((_ ?mtx ?proc ?arg0 ...) (%*synch-with ?mtx var (apply ?proc var ?arg0 ...)) ) ) ) (define-syntax %let/synch (er-macro-transformer (lambda (frm rnm cmp) (##sys#check-syntax '%let/synch frm '(_ list . _)) (let ((_%synch-with (rnm '%synch-with))) (let ((?body (cddr frm))) (car (let loop ((?bnds (cadr frm))) (if (null? ?bnds) ?body (let ((bnd (car ?bnds))) (##sys#check-syntax '%let/synch bnd '(variable _)) `((,_%synch-with ,(cadr bnd) ,(car bnd) ,@(loop (cdr ?bnds)))) ) ) ) ) ) ) ) ) ) (define-syntax %set!/synch (er-macro-transformer (lambda (frm rnm cmp) (##sys#check-syntax '%set!/synch frm '(_ pair . _)) (let ((_%synch-with (rnm '%synch-with)) (_mutex-specific (rnm 'mutex-specific)) (_mutex-specific-set! (rnm 'mutex-specific-set!)) (_let (rnm 'let)) (_begin (rnm 'begin)) (mtxvar (rnm (gensym)))) (let ((?bnd (cadr frm)) (?body (cddr frm))) (let ((?var (car ?bnd)) (?mtx (cadr ?bnd))) `(,_let ((,mtxvar ,?mtx)) (,_%synch-with ,mtxvar ,?var (,_mutex-specific-set! ,mtxvar (,_begin ,@?body)) (,_mutex-specific ,mtxvar) ) ) ) ) ) ) ) ) (define-syntax %synch/lock (syntax-rules () ((_ (?mtx (?lock-arg0 ...)) ?body ...) (let ((mtx ?mtx) (ok? #f)) (mutex-lock! mtx ?lock-arg0 ...) (call-with-values (lambda () (let ((res (begin ?body ...))) (set! ok? #t) res)) (lambda ret (unless ok? (mutex-unlock! mtx)) (apply values ret))) ) ) ((_ ?mtx ?body ...) (%synch/lock (?mtx ()) ?body ...) ) ) ) (define-syntax %synch/unlock (syntax-rules () ((_ (?mtx (?unlock-arg0 ...)) ?body ...) (let ((mtx ?mtx)) (unless (thread? (mutex-state mtx)) (warning '%synch/unlock "mutex is not locked - locking") (mutex-lock! mtx)) (call-with-values (lambda () ?body ...) (lambda ret (mutex-unlock! mtx ?unlock-arg0 ...) (apply values ret)) ) ) ) ((_ ?mtx ?body ...) (%synch/unlock (?mtx ()) ?body ...) ) ) ) (define-syntax %object/synch (er-macro-transformer (lambda (frm rnm cmp) (##sys#check-syntax '%object/synch frm '(_ _ . _)) (let ((_%synch-with (rnm '%synch-with)) (_>< (rnm '><)) (var (rnm (gensym))) (mtx (cadr frm))) (let body-loop ((unparsed (cddr frm)) (parsed '())) (if (not (null? unparsed)) (let ((expr (car unparsed)) (next (cdr unparsed))) (let expr-loop ((rest expr) (parsedexpr '())) (cond ((null? rest) (body-loop next (cons (reverse parsedexpr) parsed))) ((pair? rest) (let ((arg (car rest)) (next (cdr rest))) (if (cmp _>< arg) (expr-loop next (cons var parsedexpr)) (expr-loop next (cons arg parsedexpr)) ) )) ((cmp _>< rest) (body-loop next (cons var parsed))) (else (body-loop next (cons rest parsed))) ) ) ) `(,_%synch-with ,mtx ,var ,@(reverse parsed)) ) ) ) ) ) ) (define-syntax %record/synch (er-macro-transformer (lambda (frm rnm cmp) (##sys#check-syntax '%record/synch frm '(_ symbol _ . _)) (let ((_%synch (rnm '%synch))) (let ((?sym (cadr frm)) (?rec (caddr frm)) (?body (cdddr frm))) `(,_%synch (,(recmuxnam ?sym) ,?rec) ,@?body) ) ) ) ) ) (define-syntax %record-synch/lock (er-macro-transformer (lambda (frm rnm cmp) (##sys#check-syntax '%record-synch/lock frm '(_ symbol _ . _)) (let ((_%synch/lock (rnm '%synch/lock))) (let ((?sym (cadr frm)) (?rec (caddr frm)) (?body (cdddr frm))) `(,_%synch/lock (,(recmuxnam ?sym) ,?rec) ,@?body) ) ) ) ) ) (define-syntax %record-synch/unlock (er-macro-transformer (lambda (frm rnm cmp) (##sys#check-syntax '%record-synch/unlock frm '(_ symbol _ . _)) (let ((_%synch/unlock (rnm '%synch/unlock))) (let ((?sym (cadr frm)) (?rec (caddr frm)) (?body (cdddr frm))) `(,_%synch/unlock (,(recmuxnam ?sym) ,?rec) ,@?body) ) ) ) ) ) ;;; Synch Object (define (mutex+object? obj) (and (mutex? obj) (not (eq? (void) (mutex-specific obj)))) ) (define-check+error-type mutex+object) ;; (define (make-object/synch obj #!optional (name '(object/synch-))) (let ((mutex (make-mutex (if (pair? name) (gensym (car name)) name)))) (mutex-specific-set! mutex obj) mutex) ) (define (object?/synch obj #!optional (pred any?)) (and (mutex+object? obj) (pred (mutex-specific obj))) ) ;; (define-for-syntax (synchsym sym) (string->symbol (string-append (symbol->string sym) "/synch")) ) ;; (define-syntax define-constructor/synch (er-macro-transformer (lambda (frm rnm cmp) (##sys#check-syntax 'define-constructor/synch frm '(_ symbol . _)) (let ((_define (rnm 'define)) (_apply (rnm 'apply)) (_args (rnm (gensym 'args))) (_make-object/synch (rnm 'make-object/synch)) ) (let* ((prcnam (cadr frm)) (id (if (not (null? (cddr frm))) `('(,(caddr frm))) '())) (newnam (synchsym prcnam)) ) `(,_define (,newnam . ,_args) (,_make-object/synch (,_apply ,prcnam ,_args) ,@id)) ) ) ) ) ) ;; (define-syntax define-predicate/synch (er-macro-transformer (lambda (frm rnm cmp) (##sys#check-syntax 'define-predicate/synch frm '(_ symbol)) (let ((_define (rnm 'define)) (_obj (rnm (gensym 'obj))) (_object?/synch (rnm 'object?/synch)) ) (let* ((prcnam (cadr frm)) (newnam (synchsym prcnam)) ) `(,_define (,newnam ,_obj) (,_object?/synch ,_obj ,prcnam)) ) ) ) ) ) ;; ;operand must be the 1st argument (define-syntax define-operation/synch (er-macro-transformer (lambda (frm rnm cmp) (##sys#check-syntax 'define-operation/synch frm '(_ symbol)) (let ((_define (rnm 'define)) (_apply (rnm 'apply)) (_let (rnm 'let)) (_car (rnm 'car)) (_cdr (rnm 'cdr)) (_if (rnm 'if)) (_pair? (rnm 'pair?)) (_synch-with (rnm 'synch-with)) (_check-mutex+object (rnm 'check-mutex+object)) (_mutex-specific (rnm 'mutex-specific)) (_mtx+obj (rnm (gensym 'mtx+obj))) (_args (rnm (gensym 'args))) (_obj (rnm (gensym 'obj))) (_mtx (rnm (gensym 'mtx))) ) (let* ((prcnam (cadr frm)) (newnam (synchsym prcnam)) ) `(,_define (,newnam ,_mtx+obj . ,_args) (,_let ((,_mtx (,_if (,_pair? ,_mtx+obj) (,_car ,_mtx+obj) ,_mtx+obj))) (,_check-mutex+object ',newnam ,_mtx 'object/synch) (,_synch-with ,_mtx+obj ,_obj (,_apply ,prcnam ,_obj ,_args))) ) ) ) ) ) ) ;; ;operand must be the 1st argument (define-syntax define-operation/%synch (er-macro-transformer (lambda (frm rnm cmp) (define (%synchsym sym) (string->symbol (string-append (symbol->string sym) "/%synch"))) (##sys#check-syntax 'define-operation/%synch frm '(_ symbol)) (let ((_define (rnm 'define)) (_apply (rnm 'apply)) (_let (rnm 'let)) (_car (rnm 'car)) (_cdr (rnm 'cdr)) (_if (rnm 'if)) (_pair? (rnm 'pair?)) (_%synch-with (rnm '%synch-with)) (_check-mutex+object (rnm 'check-mutex+object)) (_mtx+obj (rnm (gensym 'mtx+obj))) (_args (rnm (gensym 'args))) (_obj (rnm (gensym 'obj))) (_mtx (rnm (gensym 'mtx))) ) (let* ((prcnam (cadr frm)) (newnam (%synchsym prcnam)) ) `(,_define (,newnam ,_mtx+obj . ,_args) (,_let ((,_mtx (,_if (,_pair? ,_mtx+obj) (,_car ,_mtx+obj) ,_mtx+obj))) (,_check-mutex+object ',newnam ,_mtx 'object/synch) (,_%synch-with ,_mtx+obj ,_obj (,_apply ,prcnam ,_obj ,_args)) ) ) ) ) ) ) ) ) ;module synch
true
eca5dc8b1654ee5289090eac66c22fad86ac67f7
784dc416df1855cfc41e9efb69637c19a08dca68
/src/std/srfi/78.ss
f4ad94f043e7cb38b58c125f7c24856724614ea2
[ "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
258
ss
78.ss
;;; -*- Gerbil -*- ;;; (c) vyzo at hackzen.org ;;; SRFI-78: Lightweight testing package: std/srfi (import :std/srfi/42) (export check check-ec check-report check-set-mode! check-reset! check-passed?) (include "srfi-78.scm")
false
be96fc0dc3962c7c0270308c799bc4a7a2cc23ee
7ccc32420e7caead27a5a138a02e9c9e789301d0
/log.sls
3090805095356b8a1794fa0021244c04bba8bb0a
[ "Apache-2.0" ]
permissive
dharmatech/mpl
03d9c884a51c3aadc0f494e0d0cebf851f570684
36f3ea90ba5dfa0323de9aaffd5fd0f4c11643d7
refs/heads/master
2023-02-05T20:21:56.382533
2023-01-31T18:10:51
2023-01-31T18:10:51
280,353
63
8
Apache-2.0
2023-01-31T18:10:53
2009-08-17T21:02:35
Scheme
UTF-8
Scheme
false
false
425
sls
log.sls
#!r6rs (library (mpl log) (export log) (import (rename (rnrs) (log rnrs:log)) (mpl misc)) (define log (case-lambda ( (x) (cond ( (number? x) (rnrs:log x) ) ( (exp? x) (list-ref x 1) ) ( else `(log ,x) )) ) ( (x y) (cond ( (and (number? x) (number? y)) (rnrs:log x y) ) ( else `(log ,x ,y) )) ))))
false
f809475e35606dc189c0f604cb0972b384fe45e4
e1fc47ba76cfc1881a5d096dc3d59ffe10d07be6
/ch3/3.24.scm
475e72c7b0d16b8d1daf7c8d9512e6729033b80f
[]
no_license
lythesia/sicp-sol
e30918e1ebd799e479bae7e2a9bd4b4ed32ac075
169394cf3c3996d1865242a2a2773682f6f00a14
refs/heads/master
2021-01-18T14:31:34.469130
2019-10-08T03:34:36
2019-10-08T03:34:36
27,224,763
2
0
null
null
null
null
UTF-8
Scheme
false
false
1,311
scm
3.24.scm
(define (make-table same-key?) (let ((local-table (list '*table*))) ; fetch key-related record in records or false (define (assoc key records) (cond ((null? records) #f) ((same-key? key (caar records)) (car records)) (else (assoc key (cdr records))) ) ) ; fetch the content of record (define (lookup key-1 key-2) (let ((sub-table (assoc key-1 (cdr local-table)))) (if sub-table (let ((record (assoc key-2 (cdr sub-table)))) (if record (cdr record) #f) ) #f ) ) ) (define (insert! key-1 key-2 val) (let ((sub-table (assoc key-1 (cdr local-table)))) (if sub-table (let ((record (assoc key-2 (cdr sub-table)))) (if record (set-cdr! record val) ; modify (set-cdr! sub-table (cons (cons key-2 val) (cdr sub-table))) ; pre-append sub-table ) ) (set-cdr! local-table (cons (list key-1 (cons key-2 val)) (cdr local-table))) ; pre-append local-table ) ) 'ok ) (define (dispatch m) (cond ((eq? m 'lookup-proc) lookup) ((eq? m 'insert-proc!) insert!) (else (error "Unknown operation -- TABLE" m)) ) ) dispatch ) )
false
7bdf24cc01c36ad63eeadc88b4be9860e07660fc
a8216d80b80e4cb429086f0f9ac62f91e09498d3
/lib/chibi/show/c.sld
3cd3d19d79a6a7a28ab5ba5e4d72d7f384f6c6ec
[ "BSD-3-Clause" ]
permissive
ashinn/chibi-scheme
3e03ee86c0af611f081a38edb12902e4245fb102
67fdb283b667c8f340a5dc7259eaf44825bc90bc
refs/heads/master
2023-08-24T11:16:42.175821
2023-06-20T13:19:19
2023-06-20T13:19:19
32,322,244
1,290
223
NOASSERTION
2023-08-29T11:54:14
2015-03-16T12:05:57
Scheme
UTF-8
Scheme
false
false
1,103
sld
c.sld
(define-library (chibi show c) (export c-in-expr c-in-stmt c-in-test c-paren c-maybe-paren c-type c-literal? c-literal char->c-char c-struct c-union c-class c-enum c-typedef c-cast c-expr c-expr/sexp c-apply c-op c-indent c-indent-string c-wrap-stmt c-open-brace c-close-brace c-block c-braced-block c-begin c-fun c-var c-prototype c-param c-param-list c-while c-for c-if c-switch c-case c-case/fallthrough c-default c-break c-continue c-return c-goto c-label c-static c-const c-extern c-volatile c-auto c-restrict c-inline c++ c-- c+ c- c* c/ c% c& c^ c~ c! c&& c<< c>> c== c!= ; |c\|| |c\|\|| c< c> c<= c>= c= c+= c-= c*= c/= c%= c&= c^= c<<= c>>= ;++c --c ; |c\|=| c++/post c--/post c. c-> c-bit-or c-or c-bit-or= cpp-if cpp-ifdef cpp-ifndef cpp-elif cpp-endif cpp-undef cpp-include cpp-define cpp-wrap-header cpp-pragma cpp-line cpp-error cpp-warning cpp-stringify cpp-sym-cat c-comment c-block-comment c-attribute) (import (chibi) (chibi string) (chibi show) (chibi show pretty) (srfi 1) (scheme cxr)) (include "c.scm"))
false
28feba70dc7e938fb2d50a659fe9a94f64add03e
b2e11f6584aedd973c62a07ad12b7fad65a90cd5
/2.28.scm
47c26f63b7bbe94193701cb9768f9f3e68305cdc
[]
no_license
hoenigmann/sicp
355cca95c6f50caeb2896b2a276c9248a40e9f8b
cdccea510da569d7aa4272d6da11ddacd32edb14
refs/heads/master
2021-01-18T16:28:11.827549
2018-06-12T14:42:57
2018-06-12T14:42:57
2,852,716
1
0
null
null
null
null
UTF-8
Scheme
false
false
26
scm
2.28.scm
(define (fringe items) )
false
0941d420f74b392f16307d4db4c6cf8d888ea6f4
52c1192bbd3250af9222f953d0ef2ff49c7a26cc
/ilc2014.scrbl
8cd2d8b7d349339faec21101ac8334c86a8f5dfb
[]
no_license
ashok-khanna/asdf3-2013
7a557fa70f5162b22d8d0b4eec97f311f948f51e
6b4eff6b678a6832e55934cb5fb4e4f2408bb7e1
refs/heads/master
2021-12-14T16:23:55.102345
2017-05-13T16:57:33
2017-05-13T16:57:33
null
0
0
null
null
null
null
UTF-8
Scheme
false
false
3,079
scrbl
ilc2014.scrbl
#lang scribble/sigplan @; @nocopyright @preprint @;-*- Scheme -*- @(require scribble/base scriblib/autobib scriblib/footnote scribble/decode scribble/core scribble/manual-struct scribble/decode-struct scribble/html-properties scribble/tag (only-in scribble/core style) "utils.rkt" "bibliography.scrbl") @authorinfo["François-René Rideau" "Google" "[email protected]"] @conferenceinfo["ILC 2014" "August 15--17, Montréal, Québec, Canada."] @copyrightyear{2014} @title{LAMBDA the Ultimate Scripting Language @(linebreak) @smaller{or Goodbye Shell Scripts, Hello Common Lisp!}} @XXX{Keywords: Programming Languages Lisp Common Lisp Shell Modularity Deployment Division of labor } @abstract{ We will demonstrate how to use Common Lisp for all your shell scripting needs, by leveraging recent progress with asdf 3, cl-launch, inferior-shell, optima.ppcre, etc. Not only can Lisp handle all the text processing and subprocess management that you can do in scripting languages, its data structures, higher-order functions, conditions and object system provide for a much nicer experience than in the usual scripting languages — not to tell about the nice interactive debugger. No more @tt{#!/bin/sh} — use a real programming language: @tt{#!/usr/bin/cl}. } @section{Description} Common Lisp being a universal programming language, it was therefore always @emph{possible} to use it for the tasks traditionally associated with @q{scripting languages}; yet it only recently acquired some of the key features that make a programming language attractive for these "scripting" tasks: (1) low overhead in defining and invoking programs, (2) a modular deployment story for @q{Write Once, Run Most-anywhere}, and (3) easy access to system functionality including portable management of subprocesses. We have previously explained @~cite[ASDF3-2014 Lisp-Acceptable-Scripting-Language] why these recently implemented features were essential to enable the kind of division of labor that underlies @q{scripting}. Now we'll explain how to leverage this new ability to use Common Lisp for writing @q{scripts}; we will show not only how it can compete not just with Shell scripts, but also with writing scripts in Perl, Python, Ruby, and other @q{scripting} languages. The features that we will demonstrate include: @itemlist[ @item{ One-line script invocation. } @item{ One-line overhead to script definition. } @item{ Easy extraction of data from subprocesses. } @item{ Recursive data structures, not mere string manipulation. } @item{ Native read-write invariance, not manual serialization. } @item{ Higher-order functions, not just top-level functions. } @item{ Pattern-matching, not just regular expressions. } @item{ Interactive debugging, not just error (back)traces. } @item{ Condition handling, not just global traps } @item{ An advanced Object System, not just multiple inheritance. } @item{ Native code compilation, not just script interpreters. }] @(generate-bib)
false
c2c33f30c7a9dba649047cc67235a5b266e19cc2
7c7e1a9237182a1c45aa8729df1ec04abb9373f0
/spec/scheme_tests/numbers.scm
5c0166b129b6918a2bb0ac7b69e0cd5bdef80d86
[ "MIT" ]
permissive
coolsun/heist
ef12a65beb553cfd61d93a6691386f6850c9d065
3f372b2463407505dad7359c1e84bf4f32de3142
refs/heads/master
2020-04-21T15:17:08.505754
2012-06-29T07:18:49
2012-06-29T07:18:49
null
0
0
null
null
null
null
UTF-8
Scheme
false
false
1,116
scm
numbers.scm
(assert (= 42 42)) (assert (= 42 42.0)) (assert (number? 42)) (assert (not (number? #t))) (assert (complex? 2+3i)) (assert (not (real? 2+3i))) (assert (real? 3.1416)) (assert (real? 22/7)) (assert (real? 42)) (assert (not (rational? 2+3i))) (assert (not (rational? 3.1416))) (assert (rational? 22/7)) (assert (not (integer? 22/7))) (assert (integer? 42)) (assert (zero? 0)) (assert (not (zero? 1))) (assert (odd? 1)) (assert (not (odd? 2))) (assert (even? 6)) (assert (not (even? 7))) (assert (positive? 5)) (assert (not (positive? -4))) (assert (negative? -13)) (assert (not (negative? 0))) (assert-equal 9 (max 8 2 7 3 9 5)) (assert-equal 2 (min 8 2 7 3 9 5)) (assert (exact? 8)) (assert (exact? 4/3)) (assert (exact? 5+3i)) (assert (inexact? 8.5)) (assert (inexact? 8.5+4i)) (assert (rational? (/ 4 3))) (assert (rational? (/ 4))) (assert-equal 1 (make-polar 1 0)) (assert-equal 3 (rationalize 5.5 3)) (assert-equal 4 (rationalize 5.5 2)) (assert-equal 5 (rationalize 5.5 1)) (assert-equal 11/2 (rationalize 5.5 0.1)) (assert-equal 16/3 (rationalize 5.25 0.1)) (assert-equal 21/4 (rationalize 5.25 0.01))
false
38de721ff435c11da39edc99e2eec8623415d89f
92b8d8f6274941543cf41c19bc40d0a41be44fe6
/gnu/kawa/javafx/defs.scm
75bfbc9f2324b1f6fcea68f20a6af3cd3244fa7b
[ "MIT" ]
permissive
spurious/kawa-mirror
02a869242ae6a4379a3298f10a7a8e610cf78529
6abc1995da0a01f724b823a64c846088059cd82a
refs/heads/master
2020-04-04T06:23:40.471010
2017-01-16T16:54:58
2017-01-16T16:54:58
51,633,398
6
0
null
null
null
null
UTF-8
Scheme
false
false
3,339
scm
defs.scm
(define-alias KeyEvent javafx.scene.input.KeyEvent) (define-alias EventHandler javafx.event.EventHandler) (define-alias Button javafx.scene.control.Button) (define-alias Circle javafx.scene.shape.Circle) (define-alias Rectangle javafx.scene.shape.Rectangle) (define-alias Color javafx.scene.paint.Color) (define-alias Text javafx.scene.text.Text) (define-alias Cursor javafx.scene.Cursor) (define-alias Group javafx.scene.Group) (define-alias Node javafx.scene.Node) (define-alias ObservableList javafx.collections.ObservableList) (define-alias FXCollections javafx.collections.FXCollections) (define-alias Timeline javafx.animation.Timeline) (define-alias KeyFrame javafx.animation.KeyFrame) (define-alias KeyValue javafx.animation.KeyValue) (define-alias Path javafx.scene.shape.Path) (define-alias QuadCurveTo javafx.scene.shape.QuadCurveTo) (define-alias ArcTo javafx.scene.shape.ArcTo) (define-alias MoveTo javafx.scene.shape.MoveTo) (define-alias LineTo javafx.scene.shape.LineTo) (define-alias HLineTo javafx.scene.shape.HLineTo) (define-alias VLineTo javafx.scene.shape.VLineTo) (define-alias Duration javafx.util.Duration) (define-alias Rotate javafx.scene.transform.Rotate) (define-alias PerspectiveCamera javafx.scene.PerspectiveCamera) (define-alias HTMLEditor javafx.scene.web.HTMLEditor) (define-alias FlowPane javafx.scene.layout.FlowPane) (define-alias Insets javafx.geometry.Insets) (define-alias Orientation javafx.geometry.Orientation) (define-syntax-case javafx-application () ((javafx-application) #`(begin (module-extends KawaJavafxApplication) (define (#,(datum->syntax #'javafx-application 'javafx-stage))::javafx.stage.Stage ;; FIXME (this):*stage*)))) (require gnu.kawa.javafx.MakeScene) (define-syntax-case javafx-scene (javafx-stage) ((javafx-scene . args) #`(let* ((builder (MakeScene . args)) (stage (#,(datum->syntax #'javafx-scene 'javafx-stage))) (scene (builder:build)) (title builder:title)) (invoke (#,(datum->syntax #'javafx-scene 'javafx-stage)) 'setScene scene) (if (not (eq? title #!null)) (set! stage:title title)) (invoke stage 'show) scene))) (define-simple-class KawaJavafxApplication (javafx.application.Application java.lang.Runnable) (title ::java.lang.String) (*stage* ::javafx.stage.Stage) ((run-scene)::void #!void) ((run ctx::gnu.mapping.CallContext)::void #!abstract) ((run)::void (javafx.application.Application:launch ((this):getClass) gnu.expr.ApplicationMainSupport:commandLineArgArray)) ((runAsMain)::void (javafx.application.Application:launch ((this):getClass) gnu.expr.ApplicationMainSupport:commandLineArgArray)) ((start (stage ::javafx.stage.Stage))::void (set! *stage* stage) (let ((ctx (gnu.mapping.CallContext:getInstance))) ((this):run ctx) (ctx:runUntilDone)))) (define-constant {gnu.kawa.reflect/ObjectBuilder}:javafx.animation.Timeline "gnu.kawa.javafx.GroupObjectBuilder") (define-constant {gnu.kawa.reflect/ObjectBuilder}:javafx.scene.shape.Path "gnu.kawa.javafx.GroupObjectBuilder") (define-constant {gnu.kawa.reflect/ObjectBuilder}:javafx.scene.Group "gnu.kawa.javafx.GroupObjectBuilder") (define-constant {gnu.kawa.reflect/ObjectBuilder}:javafx.scene.layout.FlowPane "gnu.kawa.javafx.GroupObjectBuilder")
true
9e7b96248a09324d732b0a07ae5174d2f7f0e73d
569556b313e3066346007d69af8b763682de9833
/src/prelude.scm
70579b965bcd345e70ec7c235ed0a30700c62e36
[]
no_license
zbenjamin/vmscheme
b17aa1f2f6ab4ed62c968c148c4e11621da01c3f
a56f2139248049f94343199e0183746cf72c8a09
refs/heads/master
2021-01-23T13:29:49.135567
2010-11-13T21:35:42
2010-11-13T23:02:30
null
0
0
null
null
null
null
UTF-8
Scheme
false
false
2,205
scm
prelude.scm
(%define null? (lambda (x) (= (object-type x) 0))) (%define unspec%ific? (lambda (x) (= (object-type x) 1))) (%define boolean? (lambda (x) (= (object-type x) 2))) (%define integer? (lambda (x) (= (object-type x) 3))) (%define string? (lambda (x) (= (object-type x) 4))) (%define symbol? (lambda (x) (= (object-type x) 5))) (%define pair? (lambda (x) (= (object-type x) 6))) (%define procedure? (lambda (x) (= (object-type x) 7))) (%define primitive-procedure? (lambda (x) (= (object-type x) 8))) (%define environment? (lambda (x) (= (object-type x) 10))) (%define list? (lambda (x) (%if (null? x) #t (%if (pair? x) (list? (cdr x)) #f)))) (%define list (lambda x x)) (%define not (lambda (x) (%if (eq? x #f) #t #f))) (%define equal? (lambda (x y) (%if (pair? x) (%if (pair? y) (%if (eqv? (car x) (car y)) (equal? (cdr x) (cdr y)) #f) #f) #f))) (%define append (lambda (lst1 lst2) (%if (null? lst1) lst2 (cons (car lst1) (append (cdr lst1) lst2))))) (%define length (lambda (lst) (%define helper (lambda (lst result) (%if (null? lst) result (%if (not (pair? lst)) (error) (helper (cdr lst) (+ 1 result)))))) (helper lst 0))) (%define list-tail (lambda (lst k) (%if (= k 0) lst (list-tail (cdr lst) (- k 1))))) (%define map (lambda (func lst) (%define helper (lambda (lst result) (%if (null? lst) result (helper (cdr lst) (cons (func (car lst)) result))))) (reverse (helper lst '())))) ;; (%define initial-repl ;; (lambda () ;; (%define eval-each ;; (lambda (lst) ;; (%if (= (length lst) 1) ;; (eval (car lst) (the-global-environment)) ;; ((lambda () ;; (eval (car lst) (the-global-environment)) ;; (eval-each (cdr lst))))))) ;; (display "> ") ;; (display (eval-each (read))) ;; (display "\n") ;; (initial-repl)))
false
cfc7a6ab39b2c9b8fa456768887ffa46051553db
b39668eccdb1b003b6f98ea6e7a92c7bb2b5e951
/tenth-edition.bak
8be0a01068762056e50c311ba3053b7769e2cb94
[]
no_license
angryzor/magic-the-gathering-project
d9c1f99bfbb38a8f9850427140d72db8c691297c
a58993eae9a7b0130353735b2d09ae6c8b07b006
refs/heads/master
2021-01-01T17:17:16.742759
2013-01-12T17:32:04
2013-01-12T17:32:04
7,578,284
0
1
null
null
null
null
UTF-8
Scheme
false
false
2,163
bak
tenth-edition.bak
#!r6rs (library (tenth-edition) (export card-forest card-canopy-spider card-doomed-necromancer) (import (rnrs base (6)) (magic cards) (magic mana)) ; ======================= LANDS ================================== ; -------------------BASIC LANDS---------------------------------- (define (card-forest game player) (card-land "Forest" 'green game player "resources/bitmaps/cards/lands/card-forest.jpg")) (define (card-swamp game player) (card-land "Swamp" 'black game player "resources/bitmaps/cards/lands/card-swamp.jpg")) (define (card-mountain game player) (card-land "Forest" 'red game player "resources/bitmaps/cards/lands/card-mountain.jpg")) (define (card-plains game player) (card-land "Forest" 'white game player "resources/bitmaps/cards/lands/card-plains.jpg")) (define (card-island game player) (card-land "Forest" 'blue game player "resources/bitmaps/cards/lands/card-island.jpg")) ; ======================= CREATURES ============================== (define (card-canopy-spider game player) (card-creature "Canopy Spider" 'green (mana-list (mana-unit 'green) (mana-unit 'colorless)) game player 1 3 "resources/bitmaps/cards/creatures/card-canopy-spider.jpg" '(reach))) (define (card-doomed-necromancer game player) (card-creature "Doomed Necromancer" 'black (mana-list (mana-unit 'black) (mana-unit 'colorless) (mana-unit 'colorless)) game player 2 2 "resources/bitmaps/cards/creatures/card-doomed-necromancer.jpg" '())) )
false
3cf5cee3b87d23226a390b3b29ed4facaa63eb44
dd4cc30a2e4368c0d350ced7218295819e102fba
/vendored_parsers/vendor/highlights/lua.scm
6c4323b30d45e27b89b727f0173ac2cb520db915
[ "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
673
scm
lua.scm
;; Keywords [ "goto" "in" "local" "return" "and" "not" "or" "function" "if" "elseif" "else" "then" "for" "do" "end" "repeat" "until" "while" ] @keyword [ "+" "-" "*" "/" "%" "^" "#" "==" "~=" "<=" ">=" "<" ">" "=" "&" "~" "|" "<<" ">>" "//" ".." ] @operator ;; Variables (identifier) @variable ((identifier) @variable.builtin (#match? @variable.builtin "self")) ;; Constants ((identifier) @constant (#match? @constant "^[A-Z][A-Z_0-9]*$")) (nil) @constant.builtin [ (false) (true) ] @boolean ;; Others (comment) @comment (number) @number (string) @string ;; Error (ERROR) @error
false
016e73b25aed8aff19dbb57e7e150bbf443f1306
58381f6c0b3def1720ca7a14a7c6f0f350f89537
/Chapter 2/2.2/Ex2.41.scm
5fabc96724e8a72dcd124b834592fc18d3770339
[]
no_license
yaowenqiang/SICPBook
ef559bcd07301b40d92d8ad698d60923b868f992
c8a0228ebf66d9c1ddc5ef1fcc1d05d8684f090a
refs/heads/master
2020-04-19T04:03:15.888492
2015-11-02T15:35:46
2015-11-02T15:35:46
null
0
0
null
null
null
null
UTF-8
Scheme
false
false
1,332
scm
Ex2.41.scm
#lang planet neil/sicp ;;helpers (define (accumulate op initial sequence) (if (null? sequence) initial (op (car sequence) (accumulate op initial (cdr sequence))))) (define (flatmap proc seq) (accumulate append nil (map proc seq))) (define (sum-seq seq) (accumulate + 0 seq)) (define (filter predicate sequence) (cond ((null? sequence) nil) ((predicate (car sequence)) (cons (car sequence) (filter predicate (cdr sequence)))) (else (filter predicate (cdr sequence))))) (define (enumerate-interval low high) (if (> low high) nil (cons low (enumerate-interval (+ low 1) high)))) (define (triples n) (flatmap (lambda (x) (flatmap (lambda (y) (map (lambda (z) (list x y z)) (enumerate-interval 1 (- y 1)))) (enumerate-interval 1 (- x 1)))) (enumerate-interval 1 n))) (define (make-triple triple) (list (car triple) (cadr triple) (caddr triple) (sum-seq triple))) (define (ordered-triples n s) (map make-triple (filter (lambda (triple) (= (sum-seq triple) s)) (triples n)))) (ordered-triples 5 10)
false
d4aa1bba4d84e3caaf4d0ef9303e4f37385e7ab8
30c99bf023dad4dba127217f72d20d2cf72f365d
/examples/Tests/lambda-lift.scm
3da9aaabb69895913c11917be8596760f1775341
[]
no_license
peterthiemann/pgg
4154b9e2b79657db3c6b984ba462b7270e5d0dbf
556eac6ffddecd2ef5cfd67ebe2fc6be514b3372
refs/heads/master
2016-09-05T10:44:45.881487
2012-05-28T17:29:54
2012-05-28T17:29:54
null
0
0
null
null
null
null
UTF-8
Scheme
false
false
366
scm
lambda-lift.scm
(define (f1 x l) (if (= x 0) (+ 1 (f2 l)) (f3 (- x 1) l))) (define (f2 l) (define (g l q) (if (null? l) (f1 q '()) (+ (f3 q '()) (g (cdr l) q) 1))) (define (foo1) (g '(1 2 3) 0)) (define (foo2 l) (+ (g l 0) (foo1))) (if (null? l) 1 (foo2 l))) (define (f3 x l) (if (= x 0) 0 (+ (f1 (- x 1) l) (f2 l))))
false
52618f8f70dfdbf8dfc72d8d4344f46d8b429524
b14c18fa7a4067706bd19df10f846fce5a24c169
/Chapter4/4.21.scm
9ba78eeec719b44c24b858996a9efba5a3291040
[]
no_license
silvesthu/LearningSICP
eceed6267c349ff143506b28cf27c8be07e28ee9
b5738f7a22c9e7967a1c8f0b1b9a180210051397
refs/heads/master
2021-01-17T00:30:29.035210
2016-11-29T17:57:16
2016-11-29T17:57:16
19,287,764
3
0
null
null
null
null
UTF-8
Scheme
false
false
735
scm
4.21.scm
#lang scheme (include "header.scm") ; as the saying goes, "All problems in computer science can be solved by another level of indirection" ; a. some pseudo-code ;def A(n) ;{ ; def B(fact) ; { ; fact(fact, n) ; } ; def C(ft, k) ; { ; if (k == 1) ; return 1 ; else ; return k * ft(ft, k - 1) ; } ; B(C) => C(C, n) => C(C, n - 1) => ... ;} ;A(10) ; b. (define (f x) ((lambda (even? odd?) (even? even? odd? x)) (lambda (ev? od? n) (if (= n 0) true (od? ev? od? (- n 1)))) (lambda (ev? od? n) (if (= n 0) false (ev? ev? od? (- n 1)))))) (f 11) (f 100) ; pass down function explicitly to avoid naming problem... ; it is like take name-table from env then put those names into parameters
false
8a96b88cf0d0325d05aabdc58ff546617ae126f1
52b0b749db0b7fb7a4ec1a8b78c5b6a0208bf1b5
/spiffy-request-vars.setup
78c90e446faa1071b04c63e34c26bf2b20912706
[]
no_license
mario-goulart/spiffy-request-vars
9802c50847d391f1a1d79cbda012c4b6d5962ff7
659b7536f7f5ed3ead0e7c6e8b73926f7ad8afb5
refs/heads/master
2021-01-19T08:12:22.368118
2018-08-24T19:30:05
2018-08-24T19:30:05
9,183,358
1
0
null
null
null
null
UTF-8
Scheme
false
false
258
setup
spiffy-request-vars.setup
;; -*- scheme -*- (compile -s -O3 spiffy-request-vars.scm -j spiffy-request-vars) (compile -s -O3 spiffy-request-vars.import.scm) (install-extension 'spiffy-request-vars '("spiffy-request-vars.so" "spiffy-request-vars.import.so") `((version "0.19")))
false
59a26396f31005ed4f684c0bc8a6882551e3cfa1
6438e08dfc709754e64a4d8e962c422607e5ed3e
/scheme/event/key.scm
25a8b1bb964e6c7f3cee74dbd05f7213beb11dc6
[]
no_license
HugoNikanor/GuileGamesh
42043183167cdc9d45b4dc626266750aecbee4ff
77d1be4a20b3f5b9ff8f18086bf6394990017f23
refs/heads/master
2018-10-13T10:54:00.134522
2018-07-11T19:45:15
2018-07-11T19:45:15
110,285,413
0
0
null
null
null
null
UTF-8
Scheme
false
false
699
scm
key.scm
(define-module (event key) #:use-module (event) #:use-module (oop goops) :use-module (ice-9 hash-table) #:re-export (<keyboard-event> make-keyboard-event) #:export (scancodes scan-symbol keyup? keydown? ) ) ;;; TODO stop exporting scancodes, currently used for scene changed (define scancodes '((n . 15))) (define scancodes-hash (alist->hash-table '((79 . right) (80 . left) (81 . down) (82 . up) ))) (define (scan-symbol ev) (hash-ref scancodes-hash (slot-ref ev 'scancode) #f)) (define (keyup? ev) (eq? 'SDL_KEYUP (slot-ref ev 'type))) (define (keydown? ev) (eq? 'SDL_KEYDOWN (slot-ref ev 'type)))
false
8aebbbb3631160dcf93ceedbfc21a5a2d407fc6b
2bcf33718a53f5a938fd82bd0d484a423ff308d3
/programming/sicp/ch1/ex-1.35.scm
59b3dafee41395af0ec1e1c41f15ec1da88df214
[]
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
776
scm
ex-1.35.scm
;; https://mitpress.mit.edu/sites/default/files/sicp/full-text/book/book-Z-H-12.html#%_thm_1.35 ;; φ = (1 + sqrt 5) / 2 ;; x is a fixed point of f if f(x) = x, so fixed points of x -> 1 + 1/x are: ;; x = 1 + 1 / x, or x^2 = x + 1 ;; φ^2 = (1 + 2*sqrt 5 + 5)/4 = (6 + 2*sqrt 5)/4 = (1 + sqrt 5)/2 + 1 ;; thus φ is a fixed point of f(x) = 1 + 1/x (define tolerance 0.00001) (define (fixed-point f first-guess) (define (close-enough? v1 v2) (< (abs (- v1 v2)) tolerance)) ;; Successively apply f(x), f(f(x)), ... until successive values are close (define (try guess) (let ((next (f guess))) (if (close-enough? guess next) next (try next)))) (try first-guess)) (fixed-point (lambda (x) (+ 1 (/ 1 x))) 1.0) ;; => 1.618032786...
false
359bd98c21fccc45aebf663a3997d6697f96122c
82d8e8948f60e96ad378ba253776a93e97842891
/mesh.scm
1beae6454ca8a9318ef98fad3e24e652a560ed83
[]
no_license
indraniel/slilme
2af9b6956cbb5cd2bb7a96f60d2ed50d2c76532d
cdac7589813d46708cc3f1b6fb188a9edad5dd2d
refs/heads/master
2020-06-05T07:32:10.758855
2018-10-30T15:49:43
2018-10-30T15:49:43
192,361,112
0
0
null
null
null
null
UTF-8
Scheme
false
false
837
scm
mesh.scm
(define +attributes+ '((position . 0) (texcoord . 1))) (define +mesh+ (glu:make-mesh vertices: '(attributes: ((position #:float 4) (texcoord #:float 2)) initial-elements: ((position . (1 -1 0 1 1 1 0 1 -1 1 0 1 -1 -1 0 1)) (texcoord . (1 1 1 0 0 0 0 1)))) indices: '(type: #:ushort initial-elements: (0 1 2 0 2 3)))) (glu:mesh-make-vao! +mesh+ +attributes+)
false
03709214483ad4f2076e751680e24bfa57f74e35
4bd59493b25febc53ac9e62c259383fba410ec0e
/Scripts/Task/sorting-algorithms-bubble-sort/scheme/sorting-algorithms-bubble-sort-2.ss
d678ee91d0f9f88784462be5c9cda9cce62d32b2
[]
no_license
stefanos1316/Rosetta-Code-Research
160a64ea4be0b5dcce79b961793acb60c3e9696b
de36e40041021ba47eabd84ecd1796cf01607514
refs/heads/master
2021-03-24T10:18:49.444120
2017-08-28T11:21:42
2017-08-28T11:21:42
88,520,573
5
1
null
null
null
null
UTF-8
Scheme
false
false
84
ss
sorting-algorithms-bubble-sort-2.ss
(bubble-sort (list 1 3 5 9 8 6 4 2) >) (bubble-sort (string->list "Monkey") char<?)
false
192550df73236e4922b39606f070de6d0e01ebde
b62560d3387ed544da2bbe9b011ec5cd6403d440
/crates/steel-core/src/tests/failure/require_only_in_missing_identifier.scm
dcaaf766383405d5b242d30852bce9283f83dc80
[ "LicenseRef-scancode-unknown-license-reference", "MIT", "Apache-2.0" ]
permissive
mattwparas/steel
c6fb91b20c4e613e6a8db9d9310d1e1c72313df2
700144a5a1aeb33cbdb2f66440bbe38cf4152458
refs/heads/master
2023-09-04T03:41:35.352916
2023-09-01T03:26:01
2023-09-01T03:26:01
241,949,362
207
10
Apache-2.0
2023-09-06T04:31:21
2020-02-20T17:39:28
Rust
UTF-8
Scheme
false
false
259
scm
require_only_in_missing_identifier.scm
(require (only-in "steel/result" map-ok Ok Err)) (define my-result (Ok 10)) (assert! (equal? (map-ok my-result (lambda (x) (+ x 10))) (Ok 20))) (assert! (equal? (map-ok (Err 10) (lambda (x) (+ x 10))) (Err 10))) (assert! (equal? (unwrap-ok my-result) 10))
false
328ba1c9dac24668f54a4afa6a62f386fa2785dd
2767601ac7d7cf999dfb407a5255c5d777b7b6d6
/sandbox/tsrj/marble.ss
68ae0a54e7375606a9f32b9d9ba9d6ec02bca1aa
[]
no_license
manbaum/moby-scheme
7fa8143f3749dc048762db549f1bcec76b4a8744
67fdf9299e9cf573834269fdcb3627d204e402ab
refs/heads/master
2021-01-18T09:17:10.335355
2011-11-08T01:07:46
2011-11-08T01:07:46
null
0
0
null
null
null
null
UTF-8
Scheme
false
false
2,880
ss
marble.ss
;; The first three lines of this file were inserted by DrScheme. They record metadata ;; about the language level of this file in a form that our tools can easily process. #reader(lib "htdp-beginner-reader.ss" "lang")((modname marble) (read-case-sensitive #t) (teachpacks ()) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ()))) ;; Marble rolling program. Tilting the phone ;; will cause the marble to roll in that ;; direction. (define WIDTH 320) (define HEIGHT 480) (define MARBLE-WIDTH 20) (define MARBLE-HEIGHT 20) ;; A world is a posn and a vel. (define-struct world (posn vel)) ;; A velocity has an x and y component. (define-struct vel (x y)) ;; The initial world has the marble centered ;; with no velocity. (define initial-world (make-world (make-posn (quotient WIDTH 2) (quotient HEIGHT 2)) (make-vel 0 0))) ;; tick: world -> world ;; Every tick moves the ball by its velocity. (define (tick w) (make-world (posn+vel (world-posn w) (world-vel w)) (world-vel w))) ;; tilt: world number number number -> world ;; Adjusts velocity based on the pitch and roll ;; of the phone. (define (tilt w azimuth pitch roll) (make-world (world-posn w) (make-vel roll (- pitch)))) ;; draw: world -> dom-sexp ;; We draw a single marble on screen on ;; top of the background. (define (draw w) (list (js-div '(("id" "backgroundDiv"))) (list (js-div '(("id" "marble")))))) ;; draw-css: world -> css-sexp ;; The marble is styled to be at a position and ;; a certain color. (define (draw-css w) (list (cons "marble" (marble-styling (world-posn w))) (list "backgroundDiv" (list "background-color" "white") (list "width" (number->px WIDTH)) (list "height" (number->px HEIGHT))))) ;; marble-styling: posn -> (listof css-style) ;; Styles a marble with a color, a size, and a position. (define (marble-styling a-posn) (list (list "background-color" "red") (list "position" "absolute") (list "width" (number->px MARBLE-WIDTH)) (list "height" (number->px MARBLE-HEIGHT)) (list "top" (number->px (posn-y a-posn))) (list "left" (number->px (posn-x a-posn))))) ;; number->px: number -> string ;; Turns a number into a px string for css. (define (number->px a-num) (string-append (number->string a-num) "px")) ;; posn+vel: posn velocity -> posn ;; Adds a position to a velocity. (define (posn+vel a-posn a-vel) (make-posn (+ (posn-x a-posn) (vel-x a-vel)) (+ (posn-y a-posn) (vel-y a-vel)))) (js-big-bang initial-world '() (on-draw draw draw-css) (on-tick 1/20 tick) (on-tilt tilt))
false
b079d8ec196d7e63a9a3bd005ee14731a8b30c51
c74dcb1facbd920d762017345171f47f8e41d0c5
/chapter_2/2.18.scm
7e3ac7f722e44205e7087598b11d121f4705bc29
[]
no_license
akash-akya/sicp-exercises
5125c1118c7f0e4400cb823508797fb67c745592
c28f73719740c2c495b7bc38ee8b790219482b67
refs/heads/master
2021-06-15T19:12:47.679967
2019-08-03T14:03:20
2019-08-03T14:03:20
136,158,517
0
0
null
null
null
null
UTF-8
Scheme
false
false
556
scm
2.18.scm
#lang sicp (define (reverse list) (define (iter list acc) (if (null? list) acc (iter (cdr list) (cons (car list) acc)))) (iter list nil)) ;; Test (define (assert a b) (if (not (equal? a b)) (display "failed!") #f)) (define (test) (cond ((assert (reverse (list 1 2 3 4 5)) (list 5 4 3 2 1))) ((assert (reverse (list 1)) (list 1))) ((assert (list) (list))) (else (display "All tests pass"))) (newline))
false
246a509c34e77e422d6bf1be500dbc54ac3c25bb
223f8e07bd9fd7d43e4b8a6e7413e1d53c47ce4c
/lib/chibi/filesystem.sld
e3603a824b3506a0d70081c63b661ac2f7da35d7
[ "BSD-3-Clause" ]
permissive
norton-archive/chibi-scheme
d5092480d22396ad63aae96c58b6e8e0e99103ed
38b8a6056c0b935dc8eb0d80dd774dde871757ef
refs/heads/master
2021-06-14T22:34:12.096599
2016-09-28T14:31:06
2016-09-28T14:31:06
33,801,264
3
0
null
null
null
null
UTF-8
Scheme
false
false
1,943
sld
filesystem.sld
;;> Interface to the filesystem and file descriptor objects. ;;> Note that file descriptors are currently represented as ;;> integers, but may be replaced with opaque (and gc-managed) ;;> objects in a future release. (define-library (chibi filesystem) (export duplicate-file-descriptor duplicate-file-descriptor-to close-file-descriptor renumber-file-descriptor open-input-file-descriptor open-output-file-descriptor delete-file link-file symbolic-link-file rename-file directory-files directory-fold directory-fold-tree delete-file-hierarchy delete-directory create-directory create-directory* current-directory change-directory with-directory open open-pipe make-fifo read-link file-status file-link-status file-device file-inode file-mode file-num-links file-owner file-group file-represented-device file-size file-block-size file-num-blocks file-access-time file-change-time file-modification-time file-modification-time/safe file-regular? file-directory? file-character? file-block? file-fifo? file-link? file-socket? file-exists? get-file-descriptor-flags set-file-descriptor-flags! get-file-descriptor-status set-file-descriptor-status! open/read open/write open/read-write open/create open/exclusive open/truncate open/append open/non-block file-lock file-truncate file-is-readable? file-is-writable? file-is-executable? lock/shared lock/exclusive lock/non-blocking lock/unlock chmod is-a-tty?) (import (chibi) (chibi string)) (include-shared "filesystem") (include "filesystem.scm"))
false
956f031a2b65ab2a7191305333ac4c56c2047528
1cbb5c1d76d49ec840fdde524466446471149525
/tests/monads.scm
b8737473c182206b5fffd3906188fb0856707d34
[]
no_license
a-sassmannshausen/guile-monads
0109dd9a4c2de9a901c6e85947714ed9396f205d
c43059667c8079131714ac865711453cac85a68f
refs/heads/master
2021-01-10T14:41:33.728503
2016-01-26T09:25:31
2016-01-26T09:25:31
50,418,214
4
0
null
null
null
null
UTF-8
Scheme
false
false
6,761
scm
monads.scm
;;; Test Monads --- Monads in GNU Guile ;;; Copyright © 2013, 2014, 2015 Ludovic Courtès <[email protected]> ;;; Copyright © 2015 Alex Sassmannshausen <[email protected]> ;;; ;;; This file is part of Monads. ;;; ;;; Monads 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. ;;; ;;; Monads 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 glean; if not, contact: ;;; ;;; Free Software Foundation Voice: +1-617-542-5942 ;;; 59 Temple Place - Suite 330 Fax: +1-617-542-2652 ;;; Boston, MA 02111-1307, USA [email protected] (define-module (test-monads) #:use-module (monads) #:use-module (monads io) #:use-module (ice-9 match) #:use-module (rnrs io ports) #:use-module (srfi srfi-1) #:use-module (srfi srfi-26) #:use-module (srfi srfi-64)) ;; Test the (monads) module. (define %monads (list %identity-monad %state-monad %io-monad)) (define %monad-run (list identity (cut run-with-state <> '()) run-io)) (define-syntax-rule (values->list exp) (call-with-values (lambda () exp) list)) (test-begin "monads") (test-assert "monad?" (and (every monad? %monads) (every (compose procedure? monad-bind) %monads) (every (compose procedure? monad-return) %monads))) ;; The 3 "monad laws": <http://www.haskell.org/haskellwiki/Monad_laws>. (test-assert "left identity" (every (lambda (monad run) (let ((number (random 777))) (with-monad monad (define (f x) (return (* (1+ number) 2))) (= (run (>>= (return number) f)) (run (f number)))))) %monads %monad-run)) (test-assert "right identity" (every (lambda (monad run) (with-monad monad (let ((number (return (random 777)))) (= (run (>>= number return)) (run number))))) %monads %monad-run)) (test-assert "associativity" (every (lambda (monad run) (with-monad monad (define (f x) (return (+ 1 x))) (define (g x) (return (* 2 x))) (let ((number (return (random 777)))) (= (run (>>= (>>= number f) g)) (run (>>= number (lambda (x) (>>= (f x) g)))))))) %monads %monad-run)) (test-assert "lift" (every (lambda (monad run) (let ((f (lift1 1+ monad))) (with-monad monad (let ((number (random 777))) (= (run (>>= (return number) f)) (1+ number)))))) %monads %monad-run)) (test-assert ">>= with more than two arguments" (every (lambda (monad run) (let ((1+ (lift1 1+ monad)) (2* (lift1 (cut * 2 <>) monad))) (with-monad monad (let ((number (random 777))) (= (run (>>= (return number) 1+ 1+ 1+ 2* 2* 2*)) (* 8 (+ number 3))))))) %monads %monad-run)) (test-assert "mbegin" (every (lambda (monad run) (with-monad monad (let* ((been-there? #f) (number (mbegin monad (return 1) (begin (set! been-there? #t) (return 2)) (return 3)))) (and (= (run number) 3) been-there?)))) %monads %monad-run)) (test-assert "mapm" (every (lambda (monad run) (with-monad monad (equal? (run (mapm monad (lift1 1+ monad) (iota 10))) (map 1+ (iota 10))))) %monads %monad-run)) (test-assert "sequence" (every (lambda (monad run) (let* ((input (iota 100)) (order '())) (define (frob i) (mlet monad ((foo (return 'foo))) ;; The side effect here is used to keep track of the order in ;; which monadic values are bound. Perform the side effect ;; within a '>>=' so that it is performed when the return ;; value is actually bound. (set! order (cons i order)) (return i))) (and (equal? input (run (sequence monad (map frob input)))) ;; Make sure this is from left to right. (equal? order (reverse input))))) %monads %monad-run)) (test-assert "listm" (every (lambda (monad run) (run (with-monad monad (let ((lst (listm monad (return 1) (return 2) (return 3)))) (mlet monad ((lst lst)) (return (equal? '(1 2 3) lst))))))) %monads %monad-run)) (test-assert "anym" (every (lambda (monad run) (eq? (run (with-monad monad (anym monad (lift1 (lambda (x) (and (odd? x) 'odd!)) monad) (append (make-list 1000 0) (list 1 2))))) 'odd!)) %monads %monad-run)) (test-equal "set-current-state" (list '(a a d) 'd) (values->list (run-with-state (mlet* %state-monad ((init (current-state)) (init2 (set-current-state 'b))) (mbegin %state-monad (set-current-state 'c) (set-current-state 'd) (mlet %state-monad ((last (current-state))) (return (list init init2 last))))) 'a))) (test-equal "state-push etc." (list '((z . 2) (p . (1)) (a . (1))) '(2 1)) (values->list (run-with-state (mbegin %state-monad (state-push 1) ;(1) (state-push 2) ;(2 1) (mlet* %state-monad ((z (state-pop)) ;(1) (p (current-state)) (a (state-push z))) ;(2 1) (return `((z . ,z) (p . ,p) (a . ,a))))) '()))) (test-end "monads") ;;(exit (= (test-runner-fail-count (test-runner-current)) 0))
true
c24ad8fa3706331276ce2176fab48e51a59540aa
defeada37d39bca09ef76f66f38683754c0a6aa0
/System/system/net/network-information/ping-completed-event-args.sls
1ba1dc18c6805eae226a0e0715bd28b990169466
[]
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
520
sls
ping-completed-event-args.sls
(library (system net network-information ping-completed-event-args) (export is? ping-completed-event-args? reply) (import (ironscheme-clr-port)) (define (is? a) (clr-is System.Net.NetworkInformation.PingCompletedEventArgs a)) (define (ping-completed-event-args? a) (clr-is System.Net.NetworkInformation.PingCompletedEventArgs a)) (define-field-port reply #f #f (property:) System.Net.NetworkInformation.PingCompletedEventArgs Reply System.Net.NetworkInformation.PingReply))
false
b347807891e54c7875849ea4aba86bb9051eaf1f
3c9983e012653583841b51ddfd82879fe82706fb
/experiments/codegen/codegen.scm
80d5eaa381002272eda6d8459682332c1891b162
[]
no_license
spdegabrielle/smalltalk-tng
3c3d4cffa09541b75524fb1f102c7c543a84a807
545343190f556edd659f6050b98036266a270763
refs/heads/master
2020-04-16T17:06:51.884611
2018-08-07T16:18:20
2018-08-07T16:18:20
165,763,183
1
0
null
null
null
null
UTF-8
Scheme
false
false
20,560
scm
codegen.scm
(load "tinyscheme+cvs20090722/init.scm") (define (check-arg pred val caller) #t) (macro (:optional form) `(if (null? ,(cadr form)) ,(caddr form) (car ,(cadr form)))) (load "srfi-1.scm") (define (symbol-append . syms) (if (null? syms) (error "No symbols supplied to symbol-append") (string->symbol (fold-right (lambda (sym acc) (if (zero? (string-length acc)) (symbol->string sym) (string-append (symbol->string sym) acc))) "" syms)))) (macro (cheap-struct form) (let ((record-name (cadr form)) (field-names (caddr form))) (let ((maker-name (symbol-append 'make- record-name)) (predicate-name (symbol-append record-name '?))) `(begin (define (,maker-name ,@field-names) (vector ',record-name ,@field-names)) (define (,predicate-name x) (and (vector? x) (eq? (vector-ref x 0) ',record-name))) ,@(let loop ((field-names field-names) (counter 1)) (if (null? field-names) '() (cons `(define (,(symbol-append record-name '- (car field-names)) x) (vector-ref x ,counter)) (loop (cdr field-names) (+ counter 1))))))))) (define (filter-map-alist predicate transformer l) (filter-map (lambda (entry) (and (predicate (car entry)) (if transformer (transformer (car entry) (cdr entry)) entry))) l)) (cheap-struct relocation (target)) (cheap-struct label-reference (name is-8bit)) (cheap-struct label-anchor (name)) (define (flatten-and-pre-relocate instrs k) (define (walk instrs acc pos marks k) (if (null? instrs) (k acc pos marks) (let ((instr (car instrs)) (rest (cdr instrs))) (cond ((or (relocation? instr) (label-anchor? instr) (label-reference? instr)) (walk rest acc pos (cons (cons instr pos) marks) k)) ((list? instr) (walk instr acc pos marks (lambda (acc pos marks) (walk rest acc pos marks k)))) ((number? instr) (walk rest (cons instr acc) (+ pos 1) marks k)) ((string? instr) (walk rest (append (reverse (map char->integer (string->list instr))) acc) (+ pos (string-length instr)) marks k)) (else (error "Invalid instruction in stream" instr)))))) (walk instrs '() 0 '() (lambda (reversed-code final-length reversed-marks) (let* ((code (list->vector (reverse reversed-code))) (marks (reverse reversed-marks)) (relocations (filter-map-alist relocation? (lambda (r p) (cons (relocation-target r) p)) marks)) (anchors (filter-map-alist label-anchor? (lambda (a p) (cons (label-anchor-name a) p)) marks)) (refs (filter-map-alist label-reference? #f marks))) (define (anchor-pos name) (cond ((assq name anchors) => cdr) (else (error "Undefined label-anchor" name)))) (write `(code ,code))(newline) (write `(marks ,marks))(newline) (for-each (lambda (entry) (let ((name (label-reference-name (car entry))) (is-8bit (label-reference-is-8bit (car entry))) (pos (cdr entry))) (if is-8bit (let ((delta (- (anchor-pos name) (+ pos 1)))) (if (onebyte-immediate? delta) (vector-set! code pos delta) (error "Short jump out of range" entry))) (let ((v (list->vector (imm32* (- (anchor-pos name) (+ pos 4)))))) (vector-set! code (+ pos 0) (vector-ref v 0)) (vector-set! code (+ pos 1) (vector-ref v 1)) (vector-set! code (+ pos 2) (vector-ref v 2)) (vector-set! code (+ pos 3) (vector-ref v 3)))))) refs) (k code relocations))))) (define (*ret) #xC3) (define regs '((eax 0) (ecx 1) (edx 2) (ebx 3) (esp 4) (ebp 5) (esi 6) (edi 7))) (define (reg-num reg) (cond ((assq reg regs) => cadr) (else (error "Invalid register" reg)))) (define %eax 'eax) (define %ecx 'ecx) (define %edx 'edx) (define %ebx 'ebx) (define %esp 'esp) (define %ebp 'ebp) (define %esi 'esi) (define %edi 'edi) (define condition-codes '#((o) (no) (b nae) (nb ae) (e z) (ne nz) (be na) (nbe a) (s) (ns) (p pe) (np po) (l nge) (nl ge) (le ng) (nle g))) (define (condition-code-num code-sym) (let loop ((i 0)) (cond ((>= i 16) (error "Invalid condition-code" code-sym)) ((member code-sym (vector-ref condition-codes i)) i) (else (loop (+ i 1)))))) (define specials '((undefined 0) (true 1) (false 2) (nil 3))) (define (special-oop special-name) (cond ((assq special-name specials) => (lambda (entry) (let ((special-num (cadr entry))) (+ 3 (* special-num 8))))) (else (error "Invalid special name" special-name)))) (define (register=? x y) (eq? x y)) (define (register? x) (symbol? x)) (define (immediate? x) (or (number? x) (relocation? x) (label-reference? x))) (define (memory? x) (and (pair? x) (eq? (car x) '@) (pair? (cdr x)))) (define (@ base-reg . maybe-offset) (cond ((and (number? base-reg) (null? maybe-offset)) (list '@ base-reg)) ((and (register? base-reg) (pair? maybe-offset) (number? (car maybe-offset))) (list '@ base-reg (car maybe-offset))) (else (error "Invalid/unsupported memory reference" `(@ ,base-reg ,@maybe-offset))))) (define (memory-base-reg-or-absolute x) (cadr x)) (define (absolute-memory? x) (and (memory? x) (number? (memory-base-reg-or-absolute x)))) (define (bitfield . args) (define (loop acc args) ;;(write `(bitfield-loop ,acc ,args))(newline) (if (null? args) acc (let* ((width-parameter (car args)) (signed? (negative? width-parameter)) (width-in-bits (abs width-parameter)) (limit (inexact->exact (expt 2 width-in-bits)))) (let ((value (cadr args))) (if (if signed? (let ((half-limit (quotient limit 2))) (or (>= value half-limit) (< value (- half-limit)))) (or (>= value limit) (< value 0))) (error "Value exceeds bitfield width" (list width-parameter value)) (loop (+ (* acc limit) (modulo value limit)) (cddr args))))))) ;;(write `(bitfield ,@args))(newline) (loop 0 args)) ;; In 32-bit mode, #x66 is the 16-bit-operand override prefix (define (mod-r-m* mod reg rm) (bitfield 2 mod 3 reg 3 rm)) (define (onebyte-immediate? n) (and (number? n) (< n 128) (>= n -128))) (define (imm8 i) (modulo i 256)) (define (imm32* i) (list (modulo i 256) (modulo (shr i 8) 256) (modulo (shr i 16) 256) (modulo (shr i 24) 256))) (define (imm32 i) (if (or (relocation? i) (label-reference? i)) (list i 0 0 0 0) (imm32* i))) (define (imm32-if test-result i) (if test-result (imm32 i) (imm8 i))) ;; Mod values: ;; 00 - no displacement, [reg] ;; 01 - 8bit displacement, [reg + n] ;; 10 - 32bit displacement, [reg + n] ;; 11 - direct, reg (define (mod-r-m reg modrm) (let ((reg (cond ((number? reg) reg) ((register? reg) (reg-num reg)) (else (error "mod-r-m needs a number or a register for reg" reg))))) (cond ((register? modrm) (mod-r-m* 3 reg (reg-num modrm))) ((memory? modrm) (let ((base-reg (memory-base-reg-or-absolute modrm)) (offset (if (null? (cddr modrm)) 0 (caddr modrm)))) (if (absolute-memory? modrm) ;; raw absolute address, always 32 bits (list (mod-r-m* 0 reg 5) (imm32 base-reg)) (let ((mod (cond ((zero? offset) 0) ((onebyte-immediate? offset) 1) (else 2))) (offset-bytes (cond ((zero? offset) '()) ((onebyte-immediate? offset) (imm8 offset)) (else (imm32 offset))))) (if (register=? base-reg %esp) ;; can't directly use base reg, must use scaled indexing (list (mod-r-m* mod reg 4) #x24 offset-bytes) ;; normal (list (mod-r-m* mod reg (reg-num base-reg)) offset-bytes)))))) (else (error "mod-r-m needs a register or memory for modrm" modrm))))) (define (arithmetic-opcode opcode) (cond ((assq opcode '((add 0) (or 1) (adc 2) (sbb 3) (and 4) (sub 5) (xor 6) (cmp 7))) => cadr) (else (error "arithmetic-opcode: Invalid opcode" opcode)))) (define (*op opcode source target . maybe-8bit) (let ((opcode (arithmetic-opcode opcode)) (w-bit (if (null? maybe-8bit) 1 (if (car maybe-8bit) 0 1)))) (cond ((immediate? source) (let ((s-bit (if (and (= w-bit 1) (onebyte-immediate? source)) 1 0))) (if (register=? target %eax) (list (bitfield 2 0 3 opcode 2 2 1 w-bit) (imm32-if (= w-bit 1) source)) (list (bitfield 2 2 3 0 1 0 1 s-bit 1 w-bit) (mod-r-m opcode target) (imm32-if (and (= w-bit 1) (not (onebyte-immediate? source))) source))))) ((memory? source) (cond ((not (register? target)) (error "*op: Cannot have memory source and non-register target" (list opcode source target))) (else (list (bitfield 2 0 3 opcode 2 1 1 w-bit) (mod-r-m target source))))) ((register? source) (cond ((or (memory? target) (register? target)) (list (bitfield 2 0 3 opcode 2 0 1 w-bit) (mod-r-m source target))) (else (error "*op: Cannot have register source and non-mem, non-reg target" (list opcode source target))))) (else (error "*op: Invalid source" (list opcode source target)))))) (define (*mov source target . maybe-8bit) (let ((w-bit (if (null? maybe-8bit) 1 (if (car maybe-8bit) 0 1)))) (cond ((immediate? source) (if (register? target) ;; special alternate encoding (list (bitfield 4 #b1011 1 w-bit 3 (reg-num target)) (imm32-if (= w-bit 1) source)) (list (bitfield 2 3 3 0 2 3 1 w-bit) (mod-r-m 0 target) (imm32-if (= w-bit 1) source)))) ((memory? source) (cond ((and (absolute-memory? source) (register=? target %eax)) ;; special alternate encoding (list (bitfield 7 #b1010000 1 w-bit) (imm32 (memory-base-reg-or-absolute source)))) ((not (register? target)) (error "*mov: Cannot have memory source and non-register target" (list source target))) (else (list (bitfield 2 2 3 1 2 1 1 w-bit) (mod-r-m target source))))) ((register? source) (cond ((and (absolute-memory? target) (register=? source %eax)) ;; special alternate encoding (list (bitfield 7 #b1010001 1 w-bit) (imm32 (memory-base-reg-or-absolute target)))) ((or (memory? target) (register? target)) (list (bitfield 2 2 3 1 2 0 1 w-bit) (mod-r-m source target))) (else (error "*mov: Cannot have register source and non-mem, non-reg target" (list source target))))) (else (error "*mov: Invalid source" (list source target)))))) (define (*call-or-jmp-like immediate-opcode indirect-mod loc) (cond ((immediate? loc) (list immediate-opcode (imm32 loc))) ((or (register? loc) (memory? loc)) (list #xFF (mod-r-m indirect-mod loc))) (else (error "*call/*jmp: Invalid location" loc)))) (define (*call loc) (*call-or-jmp-like #xE8 2 loc)) (define (is-short-jump? loc) (and (label-reference? loc) (label-reference-is-8bit loc))) (define (*jmp loc) (if (is-short-jump? loc) (list #xEB loc 0) (*call-or-jmp-like #xE9 4 loc))) (define (*jmp-cc code loc) (write `(*jmp-cc ,code ,loc))(newline) (let ((tttn (condition-code-num code))) (if (is-short-jump? loc) (list (bitfield 4 7 4 tttn) loc 0) (list #x0F (bitfield 4 8 4 tttn) (imm32 loc))))) (define (push32 reg) (mod-r-m* 1 2 (reg-num reg))) (define (pop32 reg) (mod-r-m* 1 3 (reg-num reg))) (define (_CAR) (*mov (@ %eax 4) %eax)) (define (_CDR) (*mov (@ %eax 8) %eax)) (define (*getip reg) (list (*call 0) (pop32 reg))) (define (code->binary codevec) (list->string (map integer->char (vector->list codevec)))) (define (simple-function . instrs) (flatten-and-pre-relocate instrs (lambda (code relocs) (write `((code ,code) (relocs ,relocs))) (newline) (let ((bin (code->binary code))) (disassemble bin) (build-native-function bin relocs))))) (define (round-up-to-nearest n val) (let ((temp (+ val n -1))) (- temp (remainder temp n)))) (define (prelude-function locals-frame-size . instrs) (let* ((existing-unaccounted-for-padding 8) ;; eip and ebp, just before stack adjustment (total-required-space (+ existing-unaccounted-for-padding locals-frame-size)) (total-adjustment (- (round-up-to-nearest 16 total-required-space) existing-unaccounted-for-padding))) (simple-function (push32 %ebp) (*mov %esp %ebp) (*op 'sub total-adjustment %esp) instrs (*mov %ebp %esp) (pop32 %ebp) (*ret)))) (define x (simple-function (*mov (@ %esp 8) %eax) (_CAR) (*ret))) (define real-code (list #x55 #x89 #xe5 #x83 #xec #x08 #x8b #x45 #x0c #xc9 #xc3)) (define y (prelude-function 0 (*mov (@ %ebp 12) %eax) (_CAR))) (define mk_integer-addr (lookup-native-symbol "mk_integer")) (define get-native-function-addr (prelude-function 8 (*mov (@ %ebp 8) %ecx) (*mov (@ %ebp 12) %eax) (_CAR) (_CAR) ;; function pointer is in car slot (*mov %ecx (@ %esp 0)) (*mov %eax (@ %esp 4)) (*call (make-relocation mk_integer-addr)))) (define puts-addr (lookup-native-symbol "puts")) (define puts (prelude-function 4 (*mov (@ %ebp 12) %eax) (_CAR) (*mov (@ %eax 4) %eax) (*mov %eax (@ %esp 0)) ;(*mov puts-addr %eax) ;(*call %eax) (*call (make-relocation puts-addr)) (*mov (@ %ebp 12) %eax))) (puts "Hello world") (load "evaluator.scm") (define (make-parameter v) (lambda args (if (null? args) v (begin (set! v (car args)) v)))) (macro (parameterize form) (let ((bindings0 (cadr form)) (body (cddr form))) (let ((bindings (map (lambda (entry) (cons (gensym "p") entry)) bindings0)) (retval (gensym "prv"))) `(let ,(map (lambda (entry) `(,(car entry) (,(cadr entry)))) bindings) ,@(map (lambda (entry) `(,(cadr entry) ,(caddr entry))) bindings) (let ((,retval (begin ,@body))) ,@(map (lambda (entry) `(,(cadr entry) ,(car entry))) bindings) ,retval))))) (define-global! 'jit-compile (lambda (exp) (let ((env-accumulator #f) (continuation-depth (make-parameter 0)) (instruction-rev-acc (make-parameter '())) (frame-depth (make-parameter 0)) (frame-stack (make-parameter '()))) (define (dp term) (display (make-string (* 2 (length (frame-stack))) #\ )) (write term) (newline)) ;; -- Data types used to represent partial values (cheap-struct argument (number)) (cheap-struct literal (number)) (cheap-struct recursive-binding (number frame-depth)) ;; -- Interface to assembler (define (emit! . instrs) (dp `(emit! ,@instrs)) (instruction-rev-acc (cons instrs (instruction-rev-acc)))) (define (*mov-to-eax source) (if (and (register? source) (register=? source %eax)) '() (*mov source %eax))) (define (location-for-value v) (cond ((argument? v) (@ %esp (+ (frame-depth) (* (+ (argument-number v) 1) 4)))) ((literal? v) (literal-number v)) ((recursive-binding? v) (@ %esp (+ (- (frame-depth) (recursive-binding-frame-depth v)) (* (+ (recursive-binding-number v) 1) -4)))) ((or (register? v) (memory? v) (immediate? v)) v) (else (error "Invalid PE value" v)))) (define (move-esp-by! slot-count) (when (not (zero? slot-count)) (let ((nbytes (abs (* slot-count 4)))) (emit! (*op (if (positive? slot-count) 'add 'sub) nbytes %esp)) (frame-depth ((if (positive? slot-count) - +) (frame-depth) nbytes))))) (define (allocate! nwords) (let ((ok-label (gensym "allocok"))) (emit! (*mov %esi %eax) (*op 'add (* nwords 4) %esi) (*op 'cmp %esi %edi) (*jmp-cc 'ge (make-label-reference ok-label #t)) (*mov %eax %esi) (*mov (* nwords 4) %eax)) (trap! 0) (emit! (make-label-anchor ok-label)))) (define (push-frame* count) (dp `(push-frame* ,count (frame-stack ,(frame-stack)))) (when (positive? count) (move-esp-by! (- count))) (frame-stack (cons count (frame-stack)))) (define (pop-frame*) (dp `(pop-frame* (frame-stack ,(frame-stack)))) (let ((count (car (frame-stack)))) (when (positive? count) (move-esp-by! (car (frame-stack)))) (frame-stack (cdr (frame-stack))))) ;; -- Interpreter-core API ;;(define (error key val) ;;...?) (define (undefined) (special-oop 'undefined)) (define (begin-env is-recursive env) (dp `(begin-env ,is-recursive)) (set! env-accumulator (if is-recursive 0 #f)) env) (define (allocate-env name v) (dp `(allocate-env ,name ,v)) (if env-accumulator (let ((a (make-recursive-binding env-accumulator (frame-depth)))) (set! env-accumulator (+ env-accumulator 1)) a) (or v (undefined)))) (define (end-env is-recursive env) (dp `(end-env ,is-recursive (env-accumulator ,env-accumulator))) (when is-recursive (push-frame* env-accumulator) (set! env-accumulator #f)) env) (define (leave-env is-recursive v k) (dp `(leave-env ,is-recursive ,v)) (when is-recursive (pop-frame*)) (k v)) (define (update-env name old-annotation v) (dp `(update-env ,name ,old-annotation ,v)) v) (define (load-env name annotation v) (dp `(load-env ,name ,annotation ,v)) (let ((loc (location-for-value annotation))) (if (immediate? loc) loc (begin (emit! (*mov-to-eax loc)) %eax)))) (define (unbound-variable-read name) (dp `(load-implicit-global ,name)) (let ((symloc (load-literal name))) (emit! (*mov (@ %eax 8) %eax)) ;; symbol's value -- FIXME, guessing about future %eax)) (define (load-literal x) (dp `(load-literal ,x)) (let ((value (cond ((number? x) (+ 1 (* 4 x))) ((symbol? x) #x42424242) ((eq? x #t) (special-oop 'true)) ((eq? x #f) (special-oop 'false)) (else (error "Unsupported literal type" x))))) ;;(emit! (*mov-to-eax value)) ;;%eax value)) (define (load-closure formals f) (dp `(load-closure ,formals)) (parameterize ((continuation-depth 0) (instruction-rev-acc '()) (frame-depth 0) (frame-stack '())) (dp `=============================================) (f (do ((number 0 (+ number 0)) (acc '() (cons (make-argument number) acc)) (formals formals (cdr formals))) ((null? formals) (reverse acc))) (lambda (v) (dp `---------------------------------------------) (emit! (*mov-to-eax v) (*ret)) (get-native-function-addr (simple-function (reverse (instruction-rev-acc)))))))) (define (do-if v tg fg k) (let ((false-label (gensym "testfalse")) (done-label (gensym "testdone"))) (dp `(do-if ,v)) (emit! (*op 'cmp (special-oop 'false) v) (*jmp-cc 'e (make-label-reference false-label #f))) (dp `tg) (tg (lambda (true-v) (emit! (*mov-to-eax true-v) (*jmp (make-label-reference done-label #f)) (make-label-anchor false-label)) (dp `fg) (fg (lambda (false-v) (emit! (*mov-to-eax false-v) (make-label-anchor done-label)) (dp `done-if) (k %eax))))))) (define (push-frame count k) (dp `(push-frame ,count)) (push-frame* count) k) (define (update-frame index v) (dp `(update-frame ,index ,v)) (let ((loc (@ %esp (* index 4)))) (emit! (*mov v loc)) loc)) (define (do-primitive names vals expressions k) (dp `(%assemble ,names ,vals ,expressions)) (k 'primitive-result)) (define (do-call operator operands k) (dp `(do-call ,(if (= (continuation-depth) 0) 'tailcall 'normalcall) ,operator ,operands)) (let ((loc (location-for-value operator))) (if (immediate? loc) ;; Always absolute (emit! (*call (make-relocation loc))) (emit! (*call loc)))) (pop-frame*) (k %eax)) ;;;;;;'do-call-result)) (define (push-continuation k) (continuation-depth (+ (continuation-depth) 1)) ;;(dp `(push-continuation ,(continuation-depth))) (lambda (v) ;;(dp `(pop-continuation ,(continuation-depth) ,v)) (continuation-depth (- (continuation-depth) 1)) (k v))) ((make-eval error undefined begin-env allocate-env end-env leave-env update-env load-env unbound-variable-read load-literal load-closure do-if push-frame update-frame do-primitive do-call push-continuation) exp)))) (define (t1) (jit-compile '(lambda (num) (= num 0)))) (define (t2) (jit-compile '(lambda (num) (define (f n) (if (zero? n) 1 (* n (f (- n 1))))) (f num))))
false
f9fad75312b0c0db2419a8ee92aa6fc3fad7c7ea
d2bea435baf97fe65d916ea403c6eb83d4da3b22
/scheme/e054.scm
3c9587a366cad7dad416e259ec9e35adaa565f4c
[]
no_license
tgallant/euler
751a88ab43209f5fd3e089ae67634a6822ec93a2
caa1a1c87738ac55fb78b0628ea9203f72945072
refs/heads/master
2021-01-21T01:57:00.882913
2016-07-13T01:27:49
2016-07-13T01:27:49
11,758,025
0
0
null
null
null
null
UTF-8
Scheme
false
false
1,673
scm
e054.scm
(load "lib/helpers.scm") ;; e54 (define (get-hands) (read-lines "poker.txt")) (define (string->hand str) (map string->list (string-split str))) (define (royal-flush? c)) (define (straight-flush? c)) (define (four-of-a-kind? c)) (define (full-house? c)) (define (flush? c)) (define (straight? c)) (define (three-of-a-kind? c)) (define (two-pair? c)) (define (one-pair? c)) (define (classify-hand hand) (define (inner i suit same-suit values) (if (>= i (length hand)) (list same-suit values) (let ((card (list-ref hand i))) (if (eq? (list-ref card 1) suit) (inner (+ i 1) (list-ref card 1) same-suit (cons (list-ref card 0) values)) (inner (+ i 1) (list-ref card 1) #f (cons (list-ref card 0) values)))))) (let ((c (inner 0 0 #t '()))) (cond ((royal-flush? c) 9) ((straight-flush? c) 8) ((four-of-a-kind? c) 7) ((full-house? c) 6) ((flush? c) 5) ((straight? c) 4) ((three-of-a-kind? c) 3) ((two-pairs? c) 2) ((one-pair? c) 1) (else 0)))) (define (score p1 p2) (let ((p1-hand (classify-hand p1)) (p2-hand (classify-hand p2))) (cond ((> p1-hand p2-hand) #t) ((< p1-hand p2-hand) #f) (else (compare-hands p1-hand p2-hand))))) (define (e54) (let ((hands (get-hands))) (define (inner i wins) (if (> i (length hands)) wins (let ((p1 (string->hand (take 5 hands))) (p2 (string->hand (from 5 hands)))) (if (score p1 p2) (inner (+ i 1) (+ wins 1)) (inner (+ i 1) wins))))) (inner 0 0)))
false
44705a0d1fa507fe20d23a7de7d3c61aa0ccb12a
6b961ef37ff7018c8449d3fa05c04ffbda56582b
/bbn_cl/mach/zcomp/fgopt/blktyp.scm
95cc0e6f493a85ca22e8f9faa8f2f1f0ea7c3ee6
[]
no_license
tinysun212/bbn_cl
7589c5ac901fbec1b8a13f2bd60510b4b8a20263
89d88095fc2a71254e04e57cf499ae86abf98898
refs/heads/master
2021-01-10T02:35:18.357279
2015-05-26T02:44:00
2015-05-26T02:44:00
36,267,589
4
3
null
null
null
null
UTF-8
Scheme
false
false
5,297
scm
blktyp.scm
#| -*-Scheme-*- $Header: blktyp.scm,v 1.2 88/08/31 10:39:43 jinx Exp $ $MIT-Header: blktyp.scm,v 4.3 88/03/14 20:51:26 GMT jinx Exp $ Copyright (c) 1987 Massachusetts Institute of Technology This material was developed by the Scheme project at the Massachusetts Institute of Technology, Department of Electrical Engineering and Computer Science. Permission to copy this software, to redistribute it, and to use it for any purpose is granted, subject to the following restrictions and understandings. 1. Any copy made of this software must include this copyright notice in full. 2. Users of this software agree to make their best efforts (a) to return to the MIT Scheme project any improvements or extensions that they make, so that these may be included in future releases; and (b) to inform MIT of noteworthy uses of this software. 3. All materials developed as a consequence of the use of this software shall duly acknowledge such use, in accordance with the usual standards of acknowledging credit in academic research. 4. MIT has made no warrantee or representation that the operation of this software will be error-free, and MIT is under no obligation to provide any services, by way of maintenance, update, or otherwise. 5. In conjunction with products arising from the use of this material, there shall be no use of the name of the Massachusetts Institute of Technology nor of any adaptation thereof in any advertising, promotional, or sales literature without prior written consent from MIT in each case. |# ;;;; Environment Type Assignment (declare (usual-integrations)) (package (setup-block-types!) (define-export (setup-block-types! root-block) (define (loop block) (enumeration-case block-type (block-type block) ((PROCEDURE) (if (block-passed-out? block) (block-type! block block-type/ic) (begin (block-type! block block-type/stack) (maybe-close-procedure! block)))) ((CONTINUATION) (for-each loop (block-children block))) ((EXPRESSION) (if (not (block-passed-out? block)) (error "Expression block not passed out" block)) (block-type! block block-type/ic)) (else (error "Illegal block type" block)))) (define (block-type! block type) (set-block-type! block type) (for-each loop (block-children block))) (loop root-block)) (define (maybe-close-procedure! block) (if (close-procedure? (block-procedure block)) (close-procedure! block))) (define (close-procedure! block) (let ((procedure (block-procedure block)) (parent (block-parent block))) (set-procedure-closure-block! procedure parent) (((find-closure-bindings (lambda (closure-frame-block size) (set-block-parent! block closure-frame-block) (set-procedure-closure-size! procedure size))) parent) (list-transform-negative (block-free-variables block) (lambda (lvalue) (eq? (lvalue-known-value lvalue) procedure))) '()) (set-block-children! parent (delq! block (block-children parent))) (set-block-disowned-children! parent (cons block (block-disowned-children parent))))) (define (find-closure-bindings receiver) (define (find-internal block) (lambda (free-variables bound-variables) (if (or (not block) (ic-block? block)) (let ((grandparent (and (not (null? free-variables)) block))) (if (null? bound-variables) (receiver grandparent (if grandparent 1 0)) (make-closure-block receiver grandparent free-variables bound-variables (and block (block-procedure block))))) (transmit-values (filter-bound-variables (block-bound-variables block) free-variables bound-variables) (find-internal (block-parent block)))))) find-internal) (define (filter-bound-variables bindings free-variables bound-variables) (cond ((null? bindings) (return-2 free-variables bound-variables)) ((memq (car bindings) free-variables) (filter-bound-variables (cdr bindings) (delq! (car bindings) free-variables) (cons (car bindings) bound-variables))) (else (filter-bound-variables (cdr bindings) free-variables bound-variables)))) ;; Note: The use of closure-block-first-offset below implies that ;; closure frames are not shared between different closures. ;; This may have to change if we ever do simultaneous closing of multiple ;; procedures sharing structure. (define (make-closure-block recvr parent free-variables bound-variables frame) (let ((block (make-block parent 'CLOSURE)) (extra (if (and parent (ic-block/use-lookup? parent)) 1 0))) (set-block-free-variables! block free-variables) (set-block-bound-variables! block bound-variables) (set-block-frame! block (and frame (rvalue/procedure? frame) (procedure-name frame))) (let loop ((variables (block-bound-variables block)) (offset (+ closure-block-first-offset extra)) (table '()) (size extra)) (cond ((null? variables) (set-block-closure-offsets! block table) (recvr block size)) ((lvalue-integrated? (car variables)) (loop (cdr variables) offset table size)) (else (loop (cdr variables) (1+ offset) (cons (cons (car variables) offset) table) (1+ size))))))) )
false
5208ce8545fca034c3886a727331f258fa0bb7fa
6488db22a3d849f94d56797297b2469a61ad22bf
/blob-utils/blob-set-int.scm
72a879e5dd41a37dc5cd564c18a4e100876e5806
[]
no_license
bazurbat/chicken-eggs
34d8707cecbbd4975a84ed9a0d7addb6e48899da
8e741148d6e0cd67a969513ce2a7fe23241df648
refs/heads/master
2020-05-18T05:06:02.090313
2015-11-18T16:07:12
2015-11-18T16:07:12
22,037,751
0
0
null
null
null
null
UTF-8
Scheme
false
false
8,133
scm
blob-set-int.scm
;;;; blob-set-int.scm ;;;; Kon Lovett, Apr '12 ;; Issues ;; ;; - Chicken uses "signed integer" but treated here as "unsigned integer" (module blob-set-int (;export blob-set-u8! blob-set-u16-le! blob-set-u32-le! blob-set-u64-le! blob-set-u16-be! blob-set-u32-be! blob-set-u64-be! ; *blob-set-u8! *blob-set-u16-le! *blob-set-u32-le! *blob-set-u64-le! *blob-set-u16-be! *blob-set-u32-be! *blob-set-u64-be!) (import scheme chicken foreign (only type-checks check-natural-fixnum check-blob check-fixnum check-integer)) (require-library type-checks) (declare (type (*blob-set-u8! ((or blob string) number fixnum -> undefined)) (*blob-set-u16-le! ((or blob string) number fixnum -> undefined)) (*blob-set-u32-le! ((or blob string) number fixnum -> undefined)) (*blob-set-u64-le! ((or blob string) number fixnum -> undefined)) (*blob-set-u16-be! ((or blob string) number fixnum -> undefined)) (*blob-set-u32-be! ((or blob string) number fixnum -> undefined)) (*blob-set-u64-be! ((or blob string) number fixnum -> undefined)) (blob-set-u8! (blob fixnum #!optional fixnum -> undefined)) (blob-set-u16-le! (blob fixnum #!optional fixnum -> undefined)) (blob-set-u32-le! (blob number #!optional fixnum -> undefined)) (blob-set-u64-le! (blob number #!optional fixnum -> undefined)) (blob-set-u16-be! (blob fixnum #!optional fixnum -> undefined)) (blob-set-u32-be! (blob number #!optional fixnum -> undefined)) (blob-set-u64-be! (blob number #!optional fixnum -> undefined)) ) ) ;;; Only Blob Bytevector, No Argument Checking (define *blob-set-u8! (foreign-lambda* void ((nonnull-scheme-pointer bv) (unsigned-integer32 u32) (int off)) #<<EOS ((uint8_t *)bv)[off] = (uint8_t)(u32 & 0xff); EOS )) (define *blob-set-u16-le! (foreign-lambda* void ((nonnull-scheme-pointer bv) (unsigned-integer32 u32) (int off)) #<<EOS ((uint8_t *)bv)[off] = (uint8_t)(u32 & 0xff); ((uint8_t *)bv)[++off] = (uint8_t)((u32 >> 8) & 0xff); EOS )) (define *blob-set-u16-be! (foreign-lambda* void ((nonnull-scheme-pointer bv) (unsigned-integer32 u32) (int off)) #<<EOS ((uint8_t *)bv)[off] = (uint8_t)((u32 >> 8) & 0xff); ((uint8_t *)bv)[++off] = (uint8_t)(u32 & 0xff); EOS )) (define *blob-set-u32-le! (foreign-lambda* void ((nonnull-scheme-pointer bv) (unsigned-integer32 u32) (int off)) #<<EOS ((uint8_t *)bv)[off] = (uint8_t)(u32 & 0xff); ((uint8_t *)bv)[++off] = (uint8_t)((u32 >> 8) & 0xff); ((uint8_t *)bv)[++off] = (uint8_t)((u32 >> 16) & 0xff); ((uint8_t *)bv)[++off] = (uint8_t)((u32 >> 24) & 0xff); EOS )) (define *blob-set-u32-be! (foreign-lambda* void ((nonnull-scheme-pointer bv) (unsigned-integer32 u32) (int off)) #<<EOS ((uint8_t *)bv)[off] = (uint8_t)((u32 >> 24) & 0xff); ((uint8_t *)bv)[++off] = (uint8_t)((u32 >> 16) & 0xff); ((uint8_t *)bv)[++off] = (uint8_t)((u32 >> 8) & 0xff); ((uint8_t *)bv)[++off] = (uint8_t)(u32 & 0xff); EOS )) (define *blob-set-u64-le! (foreign-lambda* void ((nonnull-scheme-pointer bv) (unsigned-integer64 u64) (int off)) #<<EOS ((uint8_t *)bv)[off] = (uint8_t)(u64 & 0xff); ((uint8_t *)bv)[++off] = (uint8_t)((u64 >> 8) & 0xff); ((uint8_t *)bv)[++off] = (uint8_t)((u64 >> 16) & 0xff); ((uint8_t *)bv)[++off] = (uint8_t)((u64 >> 24) & 0xff); ((uint8_t *)bv)[++off] = (uint8_t)((u64 >> 32) & 0xff); ((uint8_t *)bv)[++off] = (uint8_t)((u64 >> 40) & 0xff); ((uint8_t *)bv)[++off] = (uint8_t)((u64 >> 48) & 0xff); ((uint8_t *)bv)[++off] = (uint8_t)((u64 >> 56) & 0xff); EOS )) (define *blob-set-u64-be! (foreign-lambda* void ((nonnull-scheme-pointer bv) (unsigned-integer64 u64) (int off)) #<<EOS ((uint8_t *)bv)[off] = (uint8_t)((u64 >> 56) & 0xff); ((uint8_t *)bv)[++off] = (uint8_t)((u64 >> 48) & 0xff); ((uint8_t *)bv)[++off] = (uint8_t)((u64 >> 40) & 0xff); ((uint8_t *)bv)[++off] = (uint8_t)((u64 >> 32) & 0xff); ((uint8_t *)bv)[++off] = (uint8_t)((u64 >> 24) & 0xff); ((uint8_t *)bv)[++off] = (uint8_t)((u64 >> 16) & 0xff); ((uint8_t *)bv)[++off] = (uint8_t)((u64 >> 8) & 0xff); ((uint8_t *)bv)[++off] = (uint8_t)(u64 & 0xff); EOS )) ;;; Only Blob Bytevector ;; 8 (define (blob-set-u8! blb uint #!optional (off 0)) (check-blob 'blob-set-u8! blb) (check-natural-fixnum 'blob-set-u8! off 'offset) (check-fixnum 'blob-set-u8! uint) (*blob-set-u8! blb uint off) ) ;; Little Endian 16, 32, & 64 (define (blob-set-u16-le! blb uint #!optional (off 0)) (check-blob 'blob-set-u16-le! blb) (check-natural-fixnum 'blob-set-u16-le! off 'offset) (check-fixnum 'blob-set-u16-le! uint) (*blob-set-u16-le! blb uint off) ) (define (blob-set-u32-le! blb uint #!optional (off 0)) (check-blob 'blob-set-u32-le! blb) (check-natural-fixnum 'blob-set-u32-le! off 'offset) (check-integer 'blob-set-u32-le! uint) (*blob-set-u32-le! blb uint off) ) (define (blob-set-u64-le! blb uint #!optional (off 0)) (check-blob 'blob-set-u64-le! blb) (check-natural-fixnum 'blob-set-u64-le! off 'offset) (check-integer 'blob-set-u64-le! uint) (*blob-set-u64-le! blb uint off) ) ;; Big Endian 16, 32, & 64 (define (blob-set-u16-be! blb uint #!optional (off 0)) (check-blob 'blob-set-u16-be! blb) (check-natural-fixnum 'blob-set-u16-be! off 'offset) (check-fixnum 'blob-set-u16-be! uint) (*blob-set-u16-be! blb uint off) ) (define (blob-set-u32-be! blb uint #!optional (off 0)) (check-blob 'blob-set-u32-be! blb) (check-natural-fixnum 'blob-set-u32-be! off 'offset) (check-integer 'blob-set-u32-be! uint) (*blob-set-u32-be! blb uint off) ) (define (blob-set-u64-be! blb uint #!optional (off 0)) (check-blob 'blob-set-u64-be! blb) (check-natural-fixnum 'blob-set-u64-be! off 'offset) (check-integer 'blob-set-u64-be! uint) (*blob-set-u64-be! blb uint off) ) #| ;Useful API? ;;; Blob, String, & U8Vector Bytevector ;; (define (get-bv-alias loc obj) (cond ((blob? obj) obj ) ((string? obj) obj ) ((u8vector? obj) (u8vector->blob/shared obj) ) (else (error-argument-type loc obj "blob, u8vector, or string" obj) ) ) ) #; ;Too Many options (define (get-byte-order loc obj) (case obj ((big-endian be big msb) 'big-endian ) ((little-endian le little lsb) 'little-endian ) (else (error-argument-type loc obj "symbol in {big-endian be big msb little-endian le little lsb}" obj) ) ) ) ;; 8 (define (set-u8! bv uint idx) (blob-set-u8! (get-bv-alias 'set-u8! bv) uint idx) ) ;; Little Endian 16, 32, & 64 (define (set-u16-le! bv uint #!optional (idx 0)) (blob-set-u16-le! (get-bv-alias 'set-u16-le! bv) uint idx) ) (define (set-u32-le! bv uint #!optional (idx 0)) (blob-set-u32-le! (get-bv-alias 'set-u32-le! bv) uint idx) ) (define (set-u64-le! bv uint #!optional (idx 0)) (blob-set-u64-le! (get-bv-alias 'set-u64-le! bv) uint idx) ) ;; Big Endian 16, 32, & 64 (define (set-u16-be! bv uint #!optional (idx 0)) (blob-set-u16-be! (get-bv-alias 'set-u16-be! bv) uint idx) ) (define (set-u32-be! bv uint #!optional (idx 0)) (blob-set-u32-be! (get-bv-alias 'set-u32-be! bv) uint idx) ) (define (set-u64-be! bv uint #!optional (idx 0)) (blob-set-u64-be! (get-bv-alias 'set-u64-be! bv) uint idx) ) ;; Both Endian 16, 32, & 64 (define (set-u16! bv uint #!optional (idx 0) (order (machine-byte-order))) (let ((bv (get-bv-alias 'set-u16! bv))) (case (get-byte-order 'set-u16! order) ((little-endian) (blob-set-u16-le! bv uint idx) ) ((big-endian) (blob-set-u16-be! bv uint idx) ) ) ) ) (define (set-u32! bv uint #!optional (idx 0) (order (machine-byte-order))) (let ((bv (get-bv-alias 'set-u32! bv))) (case (get-byte-order 'set-u32! order) ((little-endian) (blob-set-u32-le! bv uint idx) ) ((big-endian) (blob-set-u32-be! bv uint idx) ) ) ) ) (define (set-u64! bv uint #!optional (idx 0) (order (machine-byte-order))) (let ((bv (get-bv-alias 'set-u64! bv))) (case (get-byte-order 'set-u64! order) ((little-endian) (blob-set-u64-le! bv uint idx) ) ((big-endian) (blob-set-u64-be! bv uint idx) ) ) ) ) |# ) ;module blob-set-int
false
88750f0f604257a1e97edd9b899a7b70bc6e3a86
3ce85064b70d921e46ac77b621ceb72bf1d149c7
/generators/remote (deprecated)/base/src/main.scm
a9f4b6d0060f9b9402aa6c1271908776a74ae75f
[ "Zlib" ]
permissive
alvatar/sphere-fusion
674b5e22aa4e66573d819d983ccbd728bb44081a
f0bd78be9bbd42955677f3b8d73ccce167f7e486
refs/heads/master
2021-01-10T20:10:33.834908
2014-11-10T10:53:45
2014-11-10T10:53:45
4,388,080
1
0
null
2014-11-10T10:53:47
2012-05-20T22:59:54
C
UTF-8
Scheme
false
false
388
scm
main.scm
;;! Define function to be used for output interception in the server (cond-expand (android (define server-display (compose (c-lambda (char-string) void "input_from_scheme") string))) (host (define server-display pp)) (else (void))) ;;! Run or attach 'main' (cond-expand (android (c-define (c-scheme-main) '() void "scheme_main" "" (main))) (host (main)) (else (void)))
false
90ad3a612dee70244e52c13ccb85e28cca37002e
9d7417f187812a477793ca23da844b34ab2a139d
/Graphikos/Graphikos/lib/ironscheme/web/routing-helper.sls
c5c30f0844a35783e22eeb7e88758015963c72df
[ "MIT", "BSD-3-Clause" ]
permissive
simonmoriat/PLP
5ae19daba4925919b593b4a21dc91dec9de9a6ce
3d130acaa45239cdb289462a242a8c15836a39ca
refs/heads/master
2023-05-11T23:36:28.347462
2016-06-08T07:07:50
2016-06-08T07:07:50
null
0
0
null
null
null
null
UTF-8
Scheme
false
false
2,367
sls
routing-helper.sls
#| License Copyright (c) 2007-2015 Llewellyn Pritchard All rights reserved. This source code is subject to terms and conditions of the BSD License. See docs/license.txt. |# (library (ironscheme web routing-helper) (export match) (import (ironscheme) (ironscheme regex)) (define-syntax match (lambda (x) (define (get-ids tmp) (map (lambda (e) (let ((e* (syntax->datum e))) (cond [(and (symbol? e*) (not (memq e* '(_ ...)))) e] [(string? e*) (car (generate-temporaries #'(e)))] [else (syntax-case e () [(n v) (identifier? #'n) #'n] [_ (syntax-violation 'match "not a valid id, string or grouping" e)])]))) tmp)) (define (get-match tmp) (map (lambda (e) (syntax-case e () [(n v) #'n] [n #'n])) tmp)) (define (get-fender f tmp) #`(and #,@(remq #f (map (lambda (e) (syntax-case e () [(n v) (let ((v* (syntax->datum #'v))) (if (string? v*) #`(regex-match? n #,(string-append "^" v* "$")) (syntax-violation 'match "not a string" #'v e)))] [n #f])) tmp)) #,f )) (define (parse-clause e) (lambda (c) (with-syntax ((e e)) (syntax-case c () [((m ...) c) ((parse-clause #'e) #'((m ...) #t c))] [((m ...) f c) (with-syntax (((i ...) (get-ids #'(m ...))) ((m ...) (get-match #'(m ...))) (f (get-fender #'f #'(m ...)))) #'((m ...) (apply (lambda (i ...) f) e) (apply (lambda (i ...) c) e)))])))) (syntax-case x () [(_ e c ...) (with-syntax ((e* (car (generate-temporaries #'(e))))) (with-syntax (((c ...) (map (parse-clause #'e*) #'(c ...)))) #'(let ((e* e)) (syntax-case e* () c ... [_ #f]))))]))))
true
e461de8294d6a41d26bd99afa08271136fe07a95
defeada37d39bca09ef76f66f38683754c0a6aa0
/System.Data/system/data/data-relation-property-descriptor.sls
1115ba7aaac371eca509fc9486d5331ec1ba1e91
[]
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,156
sls
data-relation-property-descriptor.sls
(library (system data data-relation-property-descriptor) (export is? data-relation-property-descriptor? get-hash-code should-serialize-value? reset-value set-value get-value can-reset-value? equals? component-type is-read-only? property-type relation) (import (ironscheme-clr-port)) (define (is? a) (clr-is System.Data.DataRelationPropertyDescriptor a)) (define (data-relation-property-descriptor? a) (clr-is System.Data.DataRelationPropertyDescriptor a)) (define-method-port get-hash-code System.Data.DataRelationPropertyDescriptor GetHashCode (System.Int32)) (define-method-port should-serialize-value? System.Data.DataRelationPropertyDescriptor ShouldSerializeValue (System.Boolean System.Object)) (define-method-port reset-value System.Data.DataRelationPropertyDescriptor ResetValue (System.Void System.Object)) (define-method-port set-value System.Data.DataRelationPropertyDescriptor SetValue (System.Void System.Object System.Object)) (define-method-port get-value System.Data.DataRelationPropertyDescriptor GetValue (System.Object System.Object)) (define-method-port can-reset-value? System.Data.DataRelationPropertyDescriptor CanResetValue (System.Boolean System.Object)) (define-method-port equals? System.Data.DataRelationPropertyDescriptor Equals (System.Boolean System.Object)) (define-field-port component-type #f #f (property:) System.Data.DataRelationPropertyDescriptor ComponentType System.Type) (define-field-port is-read-only? #f #f (property:) System.Data.DataRelationPropertyDescriptor IsReadOnly System.Boolean) (define-field-port property-type #f #f (property:) System.Data.DataRelationPropertyDescriptor PropertyType System.Type) (define-field-port relation #f #f (property:) System.Data.DataRelationPropertyDescriptor Relation System.Data.DataRelation))
false
0b65eb9805d674a0992a90c66682d56ad3fb4c7e
d369542379a3304c109e63641c5e176c360a048f
/brice/Chapter2/exercise-2.75.scm
f5554897743d746d7e5df06dc40d52e3efa63c40
[]
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
1,765
scm
exercise-2.75.scm
#lang racket (require "../utils.scm") ; Exercise 2.75 ; ============= (define (make-from-real-imag x y) (define (dispatch op) (cond [(eq? op 'real-part) x] [(eq? op 'imag-part) y] [(eq? op 'magnitude) (sqrt (+ (square x) (square y)))] [(eq? op 'angle) (atan y x)] [else (error "Unknown op: MAKE-FROM-REAL-IMAG" op)])) dispatch) ; ; Implement the constructor make-from-mag-ang in message-passing style. ; This procedure should be analogous to the make-from-real-imag procedure ; given above. ; ; ------------------------------------------------------------------------ ; [Exercise 2.75]: http://sicp-book.com/book-Z-H-17.html#%_thm_2.75 ; 2.4.3 Data-Directed Programming and Additivity - p187 ; ------------------------------------------------------------------------ (define (make-from-mag-ang mag ang) (define (dispatch op) (cond [(eq? op 'real-part) (* mag (cos ang))] [(eq? op 'imag-part) (* mag (sin ang))] [(eq? op 'magnitude) mag] [(eq? op 'angle) ang] [else (error "Unknown op: MAKE-FROM-REAL-IMAG" op)])) dispatch) (module* main #f (title "Exercise 2.75") (let* [ [ang-1 (make-from-real-imag 1 1)] [ang-2 (make-from-mag-ang (sqrt 2) (* 0.25 π))]] (asserteq "Numbers (mag & angle) and (real & imag) have same magnitude" (ang-1 'magnitude) (ang-2 'magnitude)) (asserteq "Numbers (mag & angle) and (real & imag) have same angle" (ang-1 'angle) (ang-2 'angle)) (asserteq "Numbers (mag & angle) and (real & imag) have same real part" (ang-1 'real-part) (ang-2 'real-part)) (asserteq "Numbers (mag & angle) and (real & imag) have same imaginary part" (ang-1 'imag-part) (ang-2 'imag-part)) ) )
false
4d0ec3198d05dcd1f5d6a68347c17e8f77e28314
ae0d7be8827e8983c926f48a5304c897dc32bbdc
/nekoie/site/aml.tir.jp/htdocs/contents
d0e4376ce5aa759ed6cd3b4e9930c517ed258a3f
[]
no_license
ayamada/copy-of-svn.tir.jp
96c2176a0295f60928d4911ce3daee0439d0e0f4
101cd00d595ee7bb96348df54f49707295e9e263
refs/heads/master
2020-04-04T01:03:07.637225
2015-05-28T07:00:18
2015-05-28T07:00:18
1,085,533
3
2
null
2015-05-28T07:00:18
2010-11-16T15:56:30
Scheme
EUC-JP
Scheme
false
false
1,698
contents
#!/usr/local/gauche/bin/gosh ;;; coding: euc-jp ;;; -*- scheme -*- ;;; vim:set ft=scheme ts=8 sts=2 sw=2 et: ;;; $Id$ ;;; このスクリプトには、各種設定とkickstartコードのみを書く事 ;;; ToDo: SERVER_NAMEとSERVER_PORTを、CGIに渡す前にだけ書き換える ;;; apacheモジュールを探す。無いなら自分で作る事。 (add-load-path "/home/nekoie/nekoie/site/aml.tir.jp/lib") (use gauche.parameter) (use srfi-1) (use www.cgi) (use www.fastcgi) (use tir03.cgi) (use tcms01) ;;; ---- (define (main args) (with-fastcgi (lambda () (with-reverse-proxy "aml.tir.jp" 80 (lambda () ;; ToDo: あとでちゃんと作る (cgi-main/jp/path (lambda (params path-info-list) (use text.html-lite) (list (cgi-header :content-type "text/html; charset=EUC-JP") (html:html (html:head (html:link :rel "Stylesheet" :type "text/css" :href "http://css.tir.jp/tir.css")) (html:body (html:h1 "amlについて") (html:p ;"抽象化が鍵となるオンラインゲームです。" ;"メタなものが嫌いな人には向いていません。" "現在準備中。") (html:ul (html:li (html:a :href "/" "戻る"))))))) ;:on-error cgi-on-error/stack-trace ) )))) 0)
false
93f70bb08b86956d35d3f39f9043531b8290ea3a
f5083e14d7e451225c8590cc6aabe68fac63ffbd
/cs/01-Programming/cs61a/course/lectures/2.2/tree.scm
eec7e50d89243b1fb5ca62c3cdd0f073c2663ceb
[]
no_license
Phantas0s/playground
a362653a8feb7acd68a7637334068cde0fe9d32e
c84ec0410a43c84a63dc5093e1c214a0f102edae
refs/heads/master
2022-05-09T06:33:25.625750
2022-04-19T14:57:28
2022-04-19T14:57:28
136,804,123
19
5
null
2021-03-04T14:21:07
2018-06-10T11:46:19
Racket
UTF-8
Scheme
false
false
828
scm
tree.scm
;;; Implementation of tree ADT ;;; ;;; Data at leaves only; leaves are words. (define (make-tree datum children) (cond ((null? datum) children) ((not (null? children)) (error "datum at branch node!")) ((list? datum) (error "datum must be a word!")) (else datum))) (define (datum node) (if (list? node) '() node)) (define (children node) (if (list? node) node '() )) (define (leaf? node) (not (pair? node))) ;; or can do: ;; (define (leaf? node) ;; (null? (children node)) ) ;; Map a function over the data of a tree (define (treemap fn tree) (cond ((null? tree) '()) ((leaf? tree) (fn tree)) (else (make-tree '() (map (lambda (t) (treemap fn t)) (children tree))) ))) ;; Sample (define (square x) (* x x)) (define t1 '((1 2) 3 (4 (5 6)))) (treemap square t1)
false
5976c9fbc222585b8644d8338913abe26e647bce
7301b8e6fbd4ac510d5e8cb1a3dfe5be61762107
/ex-3.54.scm
947f202dea4a6234ff824d27bb8f7dfecd226435
[]
no_license
jiakai0419/sicp-1
75ec0c6c8fe39038d6f2f3c4c6dd647a39be6216
974391622443c07259ea13ec0c19b80ac04b2760
refs/heads/master
2021-01-12T02:48:12.327718
2017-01-11T12:54:38
2017-01-11T12:54:38
78,108,302
0
0
null
2017-01-05T11:44:44
2017-01-05T11:44:44
null
UTF-8
Scheme
false
false
908
scm
ex-3.54.scm
(load "./sec-3.5.scm") ;;; Exercise 3.54. Define a procedure mul-streams, analogous to add-streams, ;;; that produces the elementwise product of its two input streams. Use this ;;; together with the stream of integers to complete the following definition ;;; of the stream whose nth element (counting from 0) is n + 1 factorial: ;;; ;;; (define factorials (cons-stream 1 (mul-streams <??> <??>))) (define (mul-streams s1 s2) (if (or (stream-null? s1) (stream-null? s2)) the-empty-stream (cons-stream (* (stream-car s1) (stream-car s2)) (mul-streams (stream-cdr s1) (stream-cdr s2))))) (define factorials (cons-stream 1 (mul-streams factorials (stream-cdr integers)))) (print (stream-ref factorials 0)) (print (stream-ref factorials 1)) (print (stream-ref factorials 2)) (print (stream-ref factorials 3)) (print (stream-ref factorials 4)) (print (stream-ref factorials 5))
false
c8ddebedc189e85041d6ca29645becc0cc9c9c20
f5083e14d7e451225c8590cc6aabe68fac63ffbd
/cs/01-Programming/cs61a/course/lectures/non-bh/streamstate.scm
a514f9042011654a736502f4e7053498dc8338cc
[]
no_license
Phantas0s/playground
a362653a8feb7acd68a7637334068cde0fe9d32e
c84ec0410a43c84a63dc5093e1c214a0f102edae
refs/heads/master
2022-05-09T06:33:25.625750
2022-04-19T14:57:28
2022-04-19T14:57:28
136,804,123
19
5
null
2021-03-04T14:21:07
2018-06-10T11:46:19
Racket
UTF-8
Scheme
false
false
2,288
scm
streamstate.scm
(define (stream-withdraw balance amount-stream) (cons-stream balance (stream-withdraw (- balance (head amount-stream)) (tail amount-stream)))) ;; a withdrawal stream (define (wd-stream)(cons-stream (prompt)(wd-stream))) (define (prompt)(print "new withdrawal -->")(read)) (define mywd (wd-stream)) ;;; insert a few values by (tail(tail (tail mywd))) ;;; (stream-withdraw 100 mywd) (define (for-each-stream proc stream) (if (empty-stream? stream) 'done (sequence (proc (head stream)) (for-each-stream proc (tail stream))))) ;; print a (finite) stream. (define (print-stream s) (for-each-stream print s)) (define ps print-stream) (define (for-each-stream-count proc stream n) (if (or (= n 0) (empty-stream? stream)) 'done (sequence (proc (head stream)) (for-each-stream-count proc (tail stream) (+ n -1))))) (define (psn s n)(for-each-stream-count print s n)) ;;;;;;;;;;;;;;;; ;;; TAYLOR SERIES ;;; (we could use abstraction better here...) ;;; a term in a series looks like (a b) , a list ;;; signifying b*x^a ;; here is the number 1 = 1*x^0 (define unit-term (list 0 1)) ;; could be (make-term 0 1) (define (integrate-series series) (map integrate-term series)) ;;; to integrate b*x^a with respect to x, produce ;;; (b/(a+1)*x^(a+1) (define (integrate-term tt) (let ((new-order (1+ (car tt)))) ;; could use (order tt) instead of car (list new-order (/ (cadr tt) new-order)))) ;; make-term; coeff; (define exp-series (cons-stream unit-term (integrate-series exp-series))) ;; (- integrate sin) to get cos (also, cos(0) = 1) ;; cos x is 1 -x^2/2 + x^4/4! + .. ;; 1 -0.5 x^2 + 0.04166 x^4+ ... (define cos-series (cons-stream unit-term (neg-st (integrate-series sin-series)))) ;; we need to compute the negative of a "taylor series stream" (define (neg-st s)(if (empty-stream? s) s (cons-stream (list (car (head s))(- (cadr (head s)))) (neg-st (tail s))))) ;; integrate cos to get sin (define sin-series (integrate-series cos-series)) ;;; sin x = x -x^3/3!+ x^5/5! + ... ;;; x - 0.166 x^3 + 0.0083*x^5 + ... ;;(psn sin-series 5)
false
6b1941946e19065a9ae5c836b3fc8c1f11fe1565
893a879c6b61735ebbd213fbac7e916fcb77b341
/exam-final/problem-4/datatypes.ss
f2700e5bdffca0b3aa0fc65760a53fcddf7a7960
[]
no_license
trittimo/PLC-Assignments
e5353c9276e93bca711b684c955d6c1df7cc6c82
666c2521f1bfe1896281e06f0da9a7ca315579bb
refs/heads/master
2016-08-31T04:52:26.143152
2016-06-05T01:00:18
2016-06-05T01:00:18
54,284,286
0
0
null
null
null
null
UTF-8
Scheme
false
false
1,213
ss
datatypes.ss
;-------------------+ ; | ; DATATYPES | ; | ;-------------------+ (define-datatype expression expression? (continue-exp) (while-exp (test expression?) (bodies (list-of expression?))) (set!-exp (id symbol?) (assignment expression?)) (named-let-exp (id symbol?) (assigned list?) (bodies list?)) (let-exp (assigned list?) (bodies list?)) (empty-exp) (if-exp (comp expression?) (true expression?) (false expression?)) (lit-exp (num (lambda (x) (or (number? x) (boolean? x) (symbol? x) (string? x) (list? x) (vector? x))))) (var-exp (id symbol?)) (lambda-exp (los (lambda (x) (or (list? x) (pair? x) (symbol? x)))) (varargs (list-of symbol?)) (body list?)) (app-exp (rator expression?) (rand (lambda (x) (andmap expression? x))))) (define-datatype environment environment? (empty-env-record) (extended-env-record (syms (list-of scheme-value?)) (vals (list-of scheme-value?)) (env box?))) (define-datatype proc-val proc-val? (prim-proc (name symbol?)) (closure (params (list-of scheme-value?)) (varargs (list-of scheme-value?)) (bodies (list-of expression?)) (env box?)))
false
7d68ff7161c0d79612e4ca338c714fd62bdddba3
709e166c60d286ff0086b4e05535ce91d0ff52b4
/examples/subscriber.scm
07307f25987ba67071d4cfa11af216a35ab09635
[ "BSD-3-Clause" ]
permissive
judasnow/redis-client.egg
5bd9e77ae865b6664696c0c297ebe205e584c8ac
e8714d23929d9c73bfd4ebffda061c21bcadee4d
refs/heads/master
2021-01-14T11:25:24.034413
2014-03-08T22:49:13
2014-03-08T22:49:13
null
0
0
null
null
null
null
UTF-8
Scheme
false
false
316
scm
subscriber.scm
; Usage: ; csi -s subscriber.scm my-channel (use srfi-1 redis-client) (redis-connect "127.0.0.1" 6379) (redis-subscribe (last (command-line-arguments))) (define (run-loop thunk) (let loop () (thunk (redis-read-response (*redis-in-port*))) (loop))) (run-loop (lambda(r) (printf "->~S~%" r)))
false
cb6d4c43f9972b328cb6788804fc0153ee21c78f
174072a16ff2cb2cd60a91153376eec6fe98e9d2
/Chap-two/flatmap.scm
9c9aa53abf716555fa7f4a73583df3a8a0b96ef1
[]
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
462
scm
flatmap.scm
(define (flatmap proc seq) (acc append '() (map proc seq))) (define (acc op init seq) (if (null? seq) init (op (car seq) (acc op init (cdr seq))))) (define (enumerate-interval low upper) (if (> low upper) '() (cons low ( enumerate-interval (+ low 1) upper)))) (define (enumerate-tree tree) (cond((null? tree) '()) ((not(pair? tree)) (list tree)) (else (append (enumerate-tree (car tree)) (enumerate-tree (cdr tree))))))
false
41827cf0948253a373300f9974f580a65229ef66
2fc7c18108fb060ad1f8d31f710bcfdd3abc27dc
/lib/read-line.scm
fa1c51d5fbf064c7ff3011e98ace7625761256e6
[ "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
890
scm
read-line.scm
; Scheme 9 from Empty Space, Function Library ; By Nils M Holm, 2009 ; Placed in the Public Domain ; ; (read-line) ==> string ; (read-line input-port) ==> string ; ; Read a line from an input port. When no INPUT-PORT is specified, ; read the current input port. ; ; Example: (with-input-from-file "lib/read-line.scm" read-line) ; ==> "; Scheme 9 from Empty Space, Function Library" (define (read-line . port) (letrec ((collect-chars (lambda (c s) (cond ((eof-object? c) (if (null? s) c (list->string (reverse! s)))) ((char=? c #\newline) (list->string (reverse! s))) (else (collect-chars (apply read-char port) (cons c s))))))) (collect-chars (apply read-char port) '())))
false
d85f18a70bad35e2127f22293d4c3ca5ae3241fb
d35c3affb8cbf534655e6433db2ec2deacf9f230
/src/utils.scm
e535317db7f937966e695d32386ab5d55245fc3d
[ "MIT" ]
permissive
Idorobots/stream-rules
206a93151401d52e69bfc5af7759b47497f473bc
f857b316449cb58bb8ab5218b9b23931f3790d70
refs/heads/master
2020-06-07T08:55:51.680976
2019-07-06T14:16:09
2019-07-06T17:12:20
192,980,541
0
0
null
2019-06-20T20:16:26
2019-06-20T20:02:17
Scheme
UTF-8
Scheme
false
false
359
scm
utils.scm
;; Some utils. (define-syntax -> (syntax-rules () ((-> a (op args ...) rest ...) (-> (op a args ...) rest ...)) ((-> a) a))) (define-syntax ->> (syntax-rules () ((->> a (op args ...) rest ...) (->> (op args ... a) rest ...)) ((->> a) a))) (define ((constantly value) . _) value) (define ((flip f) a b) (f b a))
true
1012eaf09224d1d3cc19960cea31ac24600e0496
dae624fc36a9d8f4df26f2f787ddce942b030139
/chapter-17/set.scm
e29d46493fd3be55943e5ed15e6026968fe90264
[ "MIT" ]
permissive
hshiozawa/gauche-book
67dcd238c2edeeacb1032ce4b7345560b959b243
2f899be8a68aee64b6a9844f9cbe83eef324abb5
refs/heads/master
2020-05-30T20:58:40.752116
2019-10-01T08:11:59
2019-10-01T08:11:59
189,961,787
0
0
null
null
null
null
UTF-8
Scheme
false
false
83
scm
set.scm
(use gauche.sequence) (let ((lis (list 'a 'b 'c))) (set! (ref lis 0) 'z) lis)
false
9b1922f63e545336fd3a5d66aeed4d807a346ec3
784dc416df1855cfc41e9efb69637c19a08dca68
/src/std/iter.ss
bbe628d25b7ed1fa3c4b2e97a2c9709c020d750b
[ "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
10,535
ss
iter.ss
;;; -*- Gerbil -*- ;;; (C) vyzo ;;; Iterations and comprehensions package: std (import :gerbil/gambit/ports :gerbil/gambit/misc :std/generic :std/coroutine ) (export (struct-out iterator) :iter iter-end iter-end? iter-nil iter-nil? iter-start! iter-value iter-next! for for* for/collect for/fold in-range in-naturals in-hash-keys in-hash-values in-input-lines in-input-chars in-input-bytes iter-filter iter-map iter-filter-map yield ) (defstruct iterator (e start value next fini) constructor: :init! final: #t) (defmethod {:init! iterator} (lambda (self e start value next (fini void)) (struct-instance-init! self e start value next fini))) (defstruct :iter-end ()) (def iter-end (make-:iter-end)) (def (iter-end? obj) (eq? iter-end obj)) (defstruct :iter-nil ()) (def iter-nil (make-:iter-nil)) (def (iter-nil? obj) (eq? iter-nil obj)) (defgeneric :iter) (defmethod (:iter (iter iterator)) iter) (defmethod (:iter (obj <pair>)) (iter-list obj)) (defmethod (:iter (obj <null>)) (iter-list obj)) (defmethod (:iter (obj <vector>)) (iter-vector obj)) (defmethod (:iter (obj <string>)) (iter-string obj)) (defmethod (:iter (obj <hash-table>)) (iter-hash-table obj)) (defmethod (:iter (obj <procedure>)) (iter-coroutine obj)) (defmethod (:iter (obj <port>)) (if (input-port? obj) (iter-input-port obj) (error "Cannot iterate on port; not an input-port" obj))) (defmethod (:iter (obj <object>)) {:iter obj}) (def (iter-list lst) (def (value-e iter) (with ((iterator e) iter) (match e ([hd . rest] hd) (else iter-end)))) (def (next-e iter) (set! (iterator-e iter) (cdr (iterator-e iter)))) (make-iterator lst void value-e next-e)) (def (iter-vector vec (length-e vector-length) (ref-e vector-ref)) (def (value-e iter) (with ((iterator [vec . index]) iter) (if (##fx< index (length-e vec)) (ref-e vec index) iter-end))) (def (next-e iter) (with ((iterator e) iter) (set! (cdr e) (##fx+ (cdr e) 1)))) (make-iterator (cons vec 0) void value-e next-e)) (def (iter-string obj) (iter-vector obj string-length string-ref)) (def (iter-hash-table obj) (def (value-e iter) (with ((iterator lst) iter) (match lst ([[key . value] . rest] (values key value)) (else iter-end)))) (def (next-e iter) (set! (iterator-e iter) (cdr (iterator-e iter)))) (make-iterator (hash->list obj) void value-e next-e)) (def (iter-coroutine proc) (def (start-e iter) (with ((iterator proc) iter) (let (cort (coroutine (lambda () (proc) iter-end))) (set! (iterator-e iter) [cort . iter-nil])))) (def (value-e iter) (with ((iterator [cort . val]) iter) (if (iter-nil? val) (let (val (continue cort)) (set! (cdr (iterator-e iter)) val) val) val))) (def (next-e iter) (set! (cdr (iterator-e iter)) iter-nil)) (def (fini-e iter) (match (iterator-e iter) ([cort . _] (coroutine-stop! cort iter-end) (set! (iterator-e iter) #f)) (else (void)))) (let (iter (make-iterator proc start-e value-e next-e fini-e)) (make-will iter fini-e) iter)) (def (iter-input-port port (read-e read)) (def (value-e iter) (with ((iterator [port . val]) iter) (if (iter-nil? val) (let* ((e (read-e port)) (val (if (eof-object? e) iter-end e))) (set! (cdr (iterator-e iter)) val) val) val))) (def (next-e iter) (set! (cdr (iterator-e iter)) iter-nil)) (make-iterator [port . iter-nil] void value-e next-e)) (def (iter-in-range start count step) (def (value-e iter) (with ((iterator [value . count]) iter) (if (positive? count) value iter-end))) (def (next-e iter) (with ((iterator e) iter) (set! (car e) (+ (car e) step)) (set! (cdr e) (1- (cdr e))))) (make-iterator (cons start count) void value-e next-e)) (def* in-range ((count) (iter-in-range 0 count 1)) ((start count) (iter-in-range start count 1)) ((start count step) (iter-in-range start count step))) (def (in-naturals (start 1) (step 1)) (def (next-e iter) (set! (iterator-e iter) (+ (iterator-e iter) step))) (make-iterator start void iterator-e next-e)) (def (in-hash-keys ht) (iter-list (hash-keys ht))) (def (in-hash-values ht) (iter-list (hash-values ht))) (def (in-input-lines obj) (iter-input-port obj read-line)) (def (in-input-chars obj) (iter-input-port obj read-char)) (def (in-input-bytes obj) (iter-input-port obj read-u8)) (def (iter-start! iter) ((iterator-start iter) iter)) (def (iter-value iter) ((iterator-value iter) iter)) (def (iter-next! iter) ((iterator-next iter) iter)) (def (iter-fini! iter) ((iterator-fini iter) iter)) (def (iter-xform iter value-e) (def (start-e iter) (with ((iterator xiter) iter) (iter-start! xiter))) (def (next-e iter) (with ((iterator xiter) iter) (iter-next! xiter))) (def (fini-e iter) (with ((iterator xiter) iter) (iter-fini! xiter))) (make-iterator (:iter iter) start-e value-e next-e fini-e)) (def (iter-filter pred iter) (def (value-e iter) (with ((iterator xiter) iter) (let lp ((val (iter-value xiter))) (cond ((iter-end? val) iter-end) ((pred val) val) (else (iter-next! xiter) (lp (iter-value xiter))))))) (iter-xform iter value-e)) (def (iter-map mapf iter) (def (value-e iter) (with ((iterator xiter) iter) (let (val (iter-value xiter)) (if (iter-end? val) iter-end (mapf val))))) (iter-xform iter value-e)) (def (iter-filter-map mapf iter) (def (value-e iter) (with ((iterator xiter) iter) (let lp ((val (iter-value xiter))) (cond ((iter-end? val) iter-end) ((mapf val) => values) (else (iter-next! xiter) (lp (iter-value xiter))))))) (iter-xform iter value-e)) (begin-syntax (def (for-binding? bind) (syntax-case bind (when unless) ((pat expr) (match-pattern? #'pat)) ((pat expr when filter-expr) (match-pattern? #'pat)) ((pat expr unless filter-expr) (match-pattern? #'pat)) (_ #f))) (def (for-binding-expr binding) (syntax-case binding (when unless) ((bind bind-e) #'bind-e) ((bind bind-e when filter-e) #'(iter-filter (match <> (bind filter-e)) bind-e)) ((bind bind-e unless filter-e) #'(iter-filter (match <> (bind (not filter-e))) bind-e)))) (def (for-binding-bind binding) (syntax-case binding () ((bind bind-e . _) #'bind)))) (defsyntax (for stx) (def (generate-for bindings body) (with-syntax (((iter-id ...) (gentemps bindings)) ((iter-e ...) (stx-map for-binding-expr bindings)) ((bind-id ...) (gentemps bindings)) ((bind-e ...) (stx-map for-binding-bind bindings)) ((body ...) body)) #'(let ((iter-id (:iter iter-e)) ...) (iter-start! iter-id) ... (let lp () (let ((bind-id (iter-value iter-id)) ...) (unless (or (eq? iter-end bind-id) ...) (with ((bind-e bind-id) ...) body ... (iter-next! iter-id) ... (lp))))) (iter-fini! iter-id) ... (void)))) (syntax-case stx () ((_ bind body ...) (for-binding? #'bind) (generate-for [#'bind] #'(body ...))) ((_ (bind ...) body ...) (stx-andmap for-binding? #'(bind ...)) (generate-for #'(bind ...) #'(body ...))))) (defrules for* () ((recur (bind . rest) body ...) (for (bind) (recur rest body ...))) ((_ () body ...) (begin body ...))) (defsyntax (for/collect stx) (def (generate-for bindings body) (with-syntax ((value (genident 'value)) (rvalue (genident 'rvalue)) ((iter-id ...) (gentemps bindings)) ((iter-e ...) (stx-map for-binding-expr bindings)) ((bind-id ...) (gentemps bindings)) ((bind-e ...) (stx-map for-binding-bind bindings)) ((body ...) body)) #'(let ((iter-id (:iter iter-e)) ...) (iter-start! iter-id) ... (let lp ((rvalue [])) (let ((bind-id (iter-value iter-id)) ...) (if (or (eq? iter-end bind-id) ...) (begin (iter-fini! iter-id) ... (reverse rvalue)) (with ((bind-e bind-id) ...) (let (value (let () body ...)) (iter-next! iter-id) ... (lp (cons value rvalue)))))))))) (syntax-case stx () ((_ bind body ...) (for-binding? #'bind) (generate-for [#'bind] #'(body ...))) ((_ (bind ...) body ...) (stx-andmap for-binding? #'(bind ...)) (generate-for #'(bind ...) #'(body ...))))) (defsyntax (for/fold stx) (def (for/fold-bind? bind) (syntax-case bind () ((id expr) (identifier? #'id)) (else #f))) (def (generate-for fold-bind bindings body) (with-syntax ((value (genident 'value)) ((loop-id loop-e) fold-bind) ((iter-id ...) (gentemps bindings)) ((iter-e ...) (stx-map for-binding-expr bindings)) ((bind-id ...) (gentemps bindings)) ((bind-e ...) (stx-map for-binding-bind bindings)) ((body ...) body)) #'(let ((iter-id (:iter iter-e)) ...) (iter-start! iter-id) ... (let lp ((loop-id loop-e)) (let ((bind-id (iter-value iter-id)) ...) (if (or (eq? iter-end bind-id) ...) (begin (iter-fini! iter-id) ... loop-id) (with ((bind-e bind-id) ...) (let (value (let () body ...)) (iter-next! iter-id) ... (lp value))))))))) (syntax-case stx () ((_ fold-bind bind body ...) (and (for/fold-bind? #'fold-bind) (for-binding? #'bind)) (generate-for #'fold-bind [#'bind] #'(body ...))) ((_ fold-bind (bind ...) body ...) (and (for/fold-bind? #'fold-bind) (stx-andmap for-binding? #'(bind ...))) (generate-for #'fold-bind #'(bind ...) #'(body ...)))))
false
12142506ae7c82a689c3a827bf2afdbc669d040a
b2dc5cb7275421d81152cc0df41f09f7b1a0f742
/examples/plato/apps/logsearch/handler.scm
47e01f3020b8e23d0e78e23af9d75dfdc7a2e270
[]
no_license
ktakashi/sagittarius-paella
d330d6d0b7b19e395687d469e5fe6b81c6014563
9f4e6ee17d44cdd729d7f2ceccf99aac9d98da4c
refs/heads/master
2021-01-19T21:09:36.784683
2019-04-05T13:55:36
2019-04-05T13:55:36
37,460,489
7
0
null
null
null
null
UTF-8
Scheme
false
false
9,648
scm
handler.scm
;;; -*- mode:scheme; coding:utf-8; -*- ;;; ;;; Simple logsearch app ;;; ;;; Copyright (c) 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. ;;; #!read-macro=sagittarius/regex (library (plato webapp logsearch) (export entry-point support-methods mount-paths) (import (rnrs) (paella) (tapas) (plato) (cuberteria) (util file) (util concurrent) (util bytevector) (rename (binary io) (get-line binary:get-line)) (text json) (srfi :1 lists) (srfi :18 multithreading) (srfi :39 parameters) (clos user) (clos core) (sagittarius) (sagittarius io) (sagittarius time) (sagittarius control) (sagittarius regex)) (define-constant +config+ "config.scm") (define-constant +default-search-threads+ 10) (define-constant +default-timeout+ 3000) ;; 3000ms = 3s (define (bytevector->json bv) (parameterize ((*json-map-type* 'alist)) (json-read (open-string-input-port (utf8->string bv))))) (define-class <json-request> (<converter-mixin>) ((json :converter bytevector->json))) (define (json->response json) (cuberteria-map-object! (make <json-response>) json (lambda (p) (string->symbol (car p))) (lambda (s p) (cdr p)))) (define-class <json-response> (<converter-mixin>) (thread-id files regexp query done? next wait (next-query :converter json->response :json #t))) ;; FIXME: using global thread pool isn't a good idea (define search-thread-pool #f) (define search-thread-data #f) (define search-thread-timeout #f) (define %raw-timeout #f) (define (init-globals context) (unless search-thread-pool (let* ((pwd (plato-current-path context)) (config (call-with-input-file (build-path pwd +config+) read)) (count (cond ((assq 'threads config) => cdr) (else +default-search-threads+))) (timeout (cond ((assq 'timeout config) => cdr) (else +default-timeout+)))) (set! search-thread-pool (make-thread-pool count)) (set! search-thread-data (make-vector count #f)) (set! %raw-timeout timeout) (set! search-thread-timeout (make-time time-duration ;; milli -> nano (* timeout 1000000) 0))))) (define (logsearch-handler req) ;; load configuration into session (define context (*plato-current-context*)) (define pwd (plato-current-path context)) ;; if it's not there let it fail ;; TODO better error handling? (define config (call-with-input-file (build-path pwd +config+) read)) (and-let* ((log-glob (assq 'log-glob config)) (session (*plato-current-session*))) (plato-session-set! session "log-glob" (cdr log-glob))) (init-globals context) (call-with-input-file "main.html" html->tapas-component)) (define script-loader (cuberteria-resource-loader 'text/javascript ".")) (define style-loader (cuberteria-resource-loader 'text/css ".")) (define (list-file-handler req) (or (and-let* ((session (*plato-current-session*)) (log-glob (plato-session-ref session "log-glob"))) (values 200 'application/json (call-with-string-output-port (lambda (out) (json-write (glob log-glob) out))))) (values 200 'application/json "[]"))) (define (make-task json sq) (define context (plato-parent-context (*plato-current-context*))) (define pwd (plato-current-path context)) (define config (call-with-input-file (build-path* pwd +config+) read)) (define head (regex (string-append "^" (cdr (assq 'log-head config))))) (define-values (buffer get-buffer) (open-bytevector-output-port)) (define (read-block in) ;; we read 2 log blocks to make sure we handle a log line properly (let loop ((line (binary:get-line in))) (cond ((eof-object? line) line) ((head line) (put-bytevector buffer line) (let loop2 ((pos (port-position in))) (let ((line2 (binary:get-line in))) (cond ((eof-object? line2) (get-buffer)) ((head line2) (set-port-position! in pos) (get-buffer)) (else (put-bytevector buffer line2) (put-u8 buffer 10) (loop2 (port-position in))))))) ;; I don't know the format so ignore. (else (loop (binary:get-line in)))))) (define (search files pred) ;; reuse buffer (define buffer (make-bytevector 8096)) (dolist (file files) (let ((in #;(open-file-input-port file (file-options no-fail) (buffer-mode block)) (buffered-port (open-file-input-port file (file-options no-fail) (buffer-mode none)) (buffer-mode block) :buffer buffer))) (let loop () (let ((block (read-block in))) (unless (eof-object? block) (when (pred block) (let ((line (if (null? (cdr files)) (utf8->string block) (string-append file ":" (utf8->string block))))) (shared-queue-put! sq line))) (loop)))) (close-input-port in))) (shared-queue-put! sq #t)) (lambda () (let ((files (vector->list (slot-ref json 'files))) ;; TODO handle other encoding (text (slot-ref json 'query))) (if (slot-ref json 'regexp) (let ((p (regex text))) (search files (lambda (block) (p block)))) (let ((text (string->utf8 text))) (search files (lambda (block) (bytevector-contains block text)))))))) (define (search-handler req) (define uri (http-request-uri req)) (define session (*plato-current-session*)) (define (json->string json) (call-with-string-output-port (lambda (out) (json-write json out)))) (define (retrieve-results id sq) ;; emulates max timeout period (define timeout (add-duration (current-time) search-thread-timeout)) (if (or (not id) (thread-pool-thread-task-running? search-thread-pool id)) (let loop ((r '())) (let ((q (shared-queue-get! sq timeout))) (cond (q (loop (cons q r))) (else r)))) '(#t))) (define (response-it results next-query) ;; if the results contains #t in the first element then it's ended (let* ((done? (and (not (null? results)) (eqv? (car results) #t))) (texts (if (and done? (not (null? results))) (cdr results) results))) (parameterize ((*json-map-type* 'alist)) (values 200 'application/json (json->string `((result . ,(list->vector texts)) (done . ,done?) (next . ,uri) (wait . ,%raw-timeout) (next-query . ,(cuberteria-object->json next-query)))))))) (define (terminate-previous-process session) (and-let* ((id (plato-session-ref session "thread-id")) (thread (thread-pool-thread search-thread-pool id))) (when (equal? (thread-specific thread) (plato-session-name session)) (thread-pool-thread-terminate! search-thread-pool id)))) (init-globals (plato-parent-context (*plato-current-context*))) (or (and-let* ((json-request (cuberteria-map-http-request! (make <json-request>) req)) ( (slot-bound? json-request 'json) ) ;; in case (json (json->response (slot-ref json-request 'json)))) (cond ((slot-bound? json 'thread-id) (let* ((id (slot-ref json 'thread-id)) (sq (vector-ref search-thread-data id))) (response-it (retrieve-results id sq) json))) (else ;; terminate if there's already a session (terminate-previous-process session) (let* ((sq (make-shared-queue)) (id (thread-pool-push-task! search-thread-pool (make-task json sq))) (t (thread-pool-thread search-thread-pool id))) (thread-specific-set! t (plato-session-name session)) (plato-session-set! session "thread-id" id) (vector-set! search-thread-data id sq) (slot-set! json 'thread-id id) (response-it (retrieve-results #f sq) json))))) (values 500 'text/plain "Invalid parameter"))) (define (mount-paths) `( ((GET) #/scripts/ ,script-loader) ((GET) #/styles/ ,style-loader) ;; need session to find files ((GET) "/list_file" ,(plato-session-handler list-file-handler)) ((POST) "/search" ,(plato-session-handler search-handler)) )) (define (support-methods) '(GET)) (define entry-point (plato-session-handler (tapas-request-handler logsearch-handler))) )
false
1276585e5d21ee35e70a35d302961f5055eabd81
4b480cab3426c89e3e49554d05d1b36aad8aeef4
/chapter-03/stream-base-falsetru.scm
f04de694990870d859a95cd518d28137bf847808
[]
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
3,146
scm
stream-base-falsetru.scm
#lang racket ; Copy of stream-base-dgoon.scm (provide delay force the-empty-stream cons-stream stream-null? stream-car stream-cdr stream-ref stream-map stream-filter stream-take stream->list list->stream display-stream add-streams scale-stream partial-sums partial-stream integers-starting-from integers ) (define-syntax cons-stream (syntax-rules () ((cons-stream x y) (cons x (delay y))))) (define force (lambda (x) (x))) (define (memo-proc proc) (let ((already-run? false) (result false)) (lambda () (if (not already-run?) (begin (set! result (proc)) (set! already-run? true) result) result)))) ; memoized delay (define-syntax delay (syntax-rules () ((delay x) (memo-proc (lambda () x))))) ;(define-syntax delay ; (syntax-rules () ; ((delay x) ; (lambda () x)))) (define (stream-car stream) (car stream)) (define (stream-cdr stream) (force (cdr stream))) (define the-empty-stream '()) (define stream-null? null?) (define (stream-ref s n) (if (= n 0) (stream-car s) (stream-ref (stream-cdr s) (- n 1)))) ; code of stream-map in the book (define (stream-map proc . arguments) (if (stream-null? (car arguments)) the-empty-stream (cons-stream (apply proc (map stream-car arguments)) (apply stream-map (cons proc (map stream-cdr arguments)))))) (define (stream-filter pred stream) (cond ((stream-null? stream) the-empty-stream) ((pred (stream-car stream)) (cons-stream (stream-car stream) (stream-filter pred (stream-cdr stream)))) (else (stream-filter pred (stream-cdr stream))))) ; code of stream-for-each in the book (define (stream-for-each proc s) (if (stream-null? s) 'done (begin (proc (stream-car s)) (stream-for-each proc (stream-cdr s))))) (define (display-stream s) (stream-for-each display-line s)) (define (display-line x) (newline) (display x)) ; written by dgoon (define (partial-stream s n) (define (iter cur-stream cur) (if (> cur n) the-empty-stream (cons-stream (stream-car cur-stream) (iter (stream-cdr cur-stream) (+ cur 1))))) (iter s 0)) (define (stream-take s n) (define (iter cur-stream cur) (if (> cur n) '() (cons (stream-car cur-stream) (iter (stream-cdr cur-stream) (+ cur 1))))) (iter s 1)) (define (stream->list s) (if (stream-null? s) empty (cons (stream-car s) (stream->list (stream-cdr s))))) (define (list->stream xs) (if (empty? xs) the-empty-stream (cons-stream (car xs) (list->stream (cdr xs))))) (define (add-streams s1 s2) (stream-map + s1 s2)) (define (scale-stream s mul) (stream-map (lambda (x) (* x mul)) s)) (define (partial-sums s) (define result (cons-stream (stream-car s) (add-streams result (stream-cdr s)))) result) (define (integers-starting-from n) (cons-stream n (integers-starting-from (+ n 1)))) (define integers (integers-starting-from 1))
true
8c8bbac8a22738eabbaeb38924914e0fa82ff498
defeada37d39bca09ef76f66f38683754c0a6aa0
/mscorlib/system/threading/interlocked.sls
b779593546937f89f5aa97bf4b429e23b86be5d0
[]
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,914
sls
interlocked.sls
(library (system threading interlocked) (export is? interlocked? read exchange decrement increment add compare-exchange) (import (ironscheme-clr-port)) (define (is? a) (clr-is System.Threading.Interlocked a)) (define (interlocked? a) (clr-is System.Threading.Interlocked a)) (define-method-port read System.Threading.Interlocked Read (static: System.Int64 System.Int64&)) (define-method-port exchange System.Threading.Interlocked Exchange (static: System.Double System.Double& System.Double) (static: System.IntPtr System.IntPtr& System.IntPtr) (static: System.Int64 System.Int64& System.Int64) (static: System.Single System.Single& System.Single) (static: System.Object System.Object& System.Object) (static: System.Int32 System.Int32& System.Int32)) (define-method-port decrement System.Threading.Interlocked Decrement (static: System.Int64 System.Int64&) (static: System.Int32 System.Int32&)) (define-method-port increment System.Threading.Interlocked Increment (static: System.Int64 System.Int64&) (static: System.Int32 System.Int32&)) (define-method-port add System.Threading.Interlocked Add (static: System.Int64 System.Int64& System.Int64) (static: System.Int32 System.Int32& System.Int32)) (define-method-port compare-exchange System.Threading.Interlocked CompareExchange (static: System.Double System.Double& System.Double System.Double) (static: System.IntPtr System.IntPtr& System.IntPtr System.IntPtr) (static: System.Int64 System.Int64& System.Int64 System.Int64) (static: System.Single System.Single& System.Single System.Single) (static: System.Object System.Object& System.Object System.Object) (static: System.Int32 System.Int32& System.Int32 System.Int32)))
false
233d97b4d7e9a3d5525efc3cf9e446449c436689
de21ee2b90a109c443485ed2e25f84daf4327af3
/exercise/section3/3.18.scm
3afdbb2c3f70cc42e02699b4ac77854cd87a7dcc
[]
no_license
s-tajima/SICP
ab82518bdc0551bb4c99447ecd9551f8d3a2ea1d
9ceff8757269adab850d01f238225d871748d5dc
refs/heads/master
2020-12-18T08:56:31.032661
2016-11-10T11:37:52
2016-11-10T11:37:52
18,719,524
0
0
null
null
null
null
UTF-8
Scheme
false
false
1,480
scm
3.18.scm
;= Question ============================================================================= ; ; 問題 3.18 ; ; リストを調べ, そこに循環が含まれるか ; (つまりcdrを順にとってリストの終りを見つけようとするプログラムが無限ループに入るか) ; を決める手続きを書け. 問題3.13はそういうリストを構成した. ; ;= Prepared ============================================================================= (define (last-pair x) (if (null? (cdr x)) x (last-pair (cdr x)))) (define (make-cycle x) (set-cdr! (last-pair x) x) x) (define (element-of-set? x set) (cond ((null? set) #f) ((eq? x (car set)) #t) (else (element-of-set? x (cdr set))))) ;= Answer =============================================================================== (define (loop? items) (define walks '()) (define (has-circulate? x) (if (memq x walks) #t (begin (set! walks (cons x walks)) #f))) (define (circulate?-iter i) (if (not (pair? i)) #f (if (has-circulate? (car i)) #t (circulate?-iter (cdr i))))) (circulate?-iter items)) (define x (list 'a 'b)) (define z1 (cons x x)) (define z2 (make-cycle (list 'a 'b 'c))) (print (loop? z1)) (print (loop? z2)) ;= Test ================================================================================= (define x (cons 1 2)) (define z (cons x x)) (set-car! (cdr z) 17) (print (car x))
false
1ddf7fac7ef26b2a5c186c8b2d4ee0f66539fc51
4b2aeafb5610b008009b9f4037d42c6e98f8ea73
/12.3/delete-test.scm
1c8f77e2351856533de505a243caf3afa1c694a1
[]
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
820
scm
delete-test.scm
(require-extension syntax-case check) (require '../12.1/section) (require '../12.3/section) (import section-12.1) (import section-12.3) (let ((tree (figure-12.4))) (let ((root (figure-12.4/root tree)) (node (figure-12.4/13 tree))) (bt-delete! node) (check (bt-inorder-tree-map bt-node-datum root) => '(23 20 18 16 15 12 10 7 6 5 3)))) (let ((tree (figure-12.4))) (let ((root (figure-12.4/root tree)) (node (figure-12.4/16 tree))) (bt-delete! node) (check (bt-inorder-tree-map bt-node-datum root) => '(23 20 18 15 13 12 10 7 6 5 3)))) (let ((tree (figure-12.4))) (let ((root (figure-12.4/root tree)) (node (figure-12.4/5 tree))) (bt-delete! node) (check (bt-inorder-tree-map bt-node-datum root) => '(23 20 18 16 15 13 12 10 7 6 3))))
false
7e017ef7a05ac9a614b4bb0257da4f714997a2c9
b1e061ea9c3c30f279231258d319f9eb6d57769e
/run-compiler.scm
13ede9162d52f726bef4fefe78ef2cc4bbdfa67c
[]
no_license
wat-aro/SICP
6be59d4e69e838cd789750b2df9e0aafd365552e
df5369189cae95eb6f2004af17359a72791e0aad
refs/heads/master
2021-01-21T13:03:11.818682
2016-04-27T08:33:08
2016-04-27T08:33:08
52,417,381
0
0
null
null
null
null
UTF-8
Scheme
false
false
2,921
scm
run-compiler.scm
(load "./eval.scm") (load "./register-machine-simulator.scm") (load "./compiler.scm") (load "./eceval.scm") (define (rcepl) RCEPL) (define rcepl-proc (append eceval-procedure (list (list 'compile compile) (list 'assemble assemble) (list 'rcepl rcepl) (list 'statements statements)))) (define RCEPL (make-machine rcepl-proc '((assign machine (op rcepl)) ;直接RCEPLを指せないので read-compile-execute-print-loop (perform (op initialize-stack)) (perform (op prompt-for-input) (const ";;;EC-COMP input:")) (assign exp (op read)) (assign env (op get-global-environment)) (assign continue (label print-result)) (goto (label read-compile-execute)) print-result (perform (op print-stack-statistics)) (perform (op announce-output) (const ";;;EC-COMP value":)) (perform (op user-print) (reg val)) (goto (label read-compile-execute-print-loop)) read-compile-execute (assign val (op compile) (reg exp) (const val) (const return) (const ())) (assign exp (op statements) (reg val)) (assign val (op assemble) (reg exp) (reg machine)) (goto (reg val))))) (define primitive-procedures (list (list 'car car) (list 'cdr cdr) (list 'cons cons) (list 'null? null?) (list 'square (lambda (x) (* x x))) (list '= =) (list '< <) (list '<= <=) (list '> >) (list '>= >=) (list '+ +) (list '- -) (list '* *) (list '/ /) (list 'apply apply) ;; (list 'map map) (list 'let let) (list 'pair? pair?) (list 'eq? eq?) (list 'length length) (list 'set-car! set-car!) (list 'set-cdr! set-cdr!) (list 'display display) (list 'newline newline) (list 'read read) (list 'number? number?) (list 'string? string?) (list 'symbol? symbol?) (list 'caddr caddr) (list 'cdadr cdadr) (list 'cddr cddr) (list 'cadr cadr) (list 'cdddr cdddr) (list 'cadddr cadddr) (list 'caadr caadr) (list 'cadadr cadadr) (list 'not not) (list 'append append) (list 'list list) (list 'reverse reverse))) ;; (define primitive-procedures ;; (list (list 'car car) ;; (list 'cdr cdr) ;; (list 'cons cons) ;; (list 'null? null?) ;; (list '= =) ;; (list '- -) ;; (list '+ +) ;; (list '* *) ;; (list '/ /) ;; (list '> >) ;; (list '< <) ;; (list 'apply apply) ;; (list 'list list) ;; (list 'newline newline) ;; (list 'display display) ;; (list 'read read) ;; (list 'time time) ;; )) (define (start-rcepl) (set! the-global-environment (setup-environment)) (start RCEPL))
false
098d24b9520d0427bbeac48c619ca643a96acdb2
e26e24bec846e848630bf97512f8158d8040689c
/lib/chibi/zlib.scm
3baa0c7bf03b7c65754aee231a5f938aa3d2675b
[ "BSD-3-Clause" ]
permissive
traviscross/chibi-scheme
f989df49cb76512dc59f807aeb2426bd6fe1c553
97b81d31300945948bfafad8b8a7dbffdcd61ee3
refs/heads/master
2023-09-05T16:57:14.338631
2014-04-01T22:02:02
2014-04-01T22:02:02
18,473,315
2
0
null
null
null
null
UTF-8
Scheme
false
false
997
scm
zlib.scm
;; Temporary hack, need to rewrite in pure Scheme. ;;> Gzip compress a file in place, renaming with a .gz suffix. (define (gzip-file path) (system "gzip" path)) ;;> Gunzip decompress a file in place, removing any .gz suffix. (define (gunzip-file path) (system "gzip" "-d" path)) ;; Utility to filter a bytevector to a process and return the ;; accumulated output as a new bytevector. (define (process-pipe-bytevector cmd bvec) (call-with-process-io cmd (lambda (pid proc-in proc-out proc-err) ;; This could overflow the pipe. (write-bytevector bvec proc-in) (close-output-port proc-in) (let ((res (port->bytevector proc-out))) (waitpid pid 0) res)))) ;;> Gzip compress a string or bytevector in memory. (define (gzip x) (if (string? x) (gzip (string->utf8 x)) (process-pipe-bytevector '("gzip" "-c") x))) ;;> Gunzip decompress a bytevector in memory. (define (gunzip bvec) (process-pipe-bytevector '("gzip" "-c" "-d") bvec))
false
ede226961275204c9cbf84275297e3779ace62fd
42814fb3168a44672c8d69dbb56ac2e8898f042e
/tool.ss
ab659fe9160be1fe1c48286f06e2eb3e53ca1122
[]
no_license
dyoo/gui-world
520096c3e66b904a9b361fe852be3c5e2ab35e88
41e52a1c4686cc6ee4014bf7ded2fcbec337f6eb
refs/heads/master
2016-09-06T14:54:13.316419
2009-04-02T19:10:18
2009-04-02T19:10:18
159,708
1
0
null
null
null
null
UTF-8
Scheme
false
false
3,145
ss
tool.ss
#lang scheme/base (require drscheme/tool scheme/class scheme/unit scheme/gui/base scheme/runtime-path "private/snip.ss") (provide tool@) (define-runtime-path this-directory ".") (define-unit tool@ (import drscheme:tool^) (export drscheme:tool-exports^) (define drscheme-namespace (current-namespace)) (define (phase1) (drscheme:get/extend:extend-unit-frame frame-mixin) (drscheme:get/extend:extend-interactions-text interactions-text-mixin)) (define (phase2) (register-gui-world-sniptype! "posn -> posn" '(lib "graph-function-difference.ss" "gui-world" "examples" "graph-function")) (register-gui-world-sniptype! "number -> posn" '(lib "graph-function-time.ss" "gui-world" "examples" "graph-function")) (register-gui-world-sniptype! "posn event -> posn" '(lib "graph-function-event.ss" "gui-world" "examples" "graph-function")) (register-gui-world-sniptype! "posn -> boolean" '(lib "posn-to-boolean.ss" "gui-world" "examples" "graph-function")) (register-gui-world-sniptype! "number -> number (graph explorer)" '(lib "graph-explorer-snip.ss" "gui-world" "examples" "graph-explorer")) (register-gui-world-sniptype! "number -> posn (graph explorer)" '(lib "graph-explorer-2-snip.ss" "gui-world" "examples" "graph-explorer"))) (define (interactions-text-mixin super%) (class super% (inherit run-in-evaluation-thread) (define/override (evaluate-from-port port complete-program cleanup) (run-in-evaluation-thread (lambda () (void) ;; NOT WORKING YET #;(namespace-attach-module drscheme-namespace '(lib "gui-world.ss" "gui-world")))) (super evaluate-from-port port complete-program cleanup)) (super-new))) (define (frame-mixin super%) (class super% (inherit get-insert-menu get-edit-target-object) (super-new) (define tool-frame (new frame% [label "Function tables"])) (define radio-box (new radio-box% [label "What kind of function?"] [choices (get-registry-names)] [parent tool-frame])) (new button% [parent tool-frame] [label "Insert"] [callback (lambda (b e) (let ([choice (send radio-box get-item-plain-label (send radio-box get-selection))]) (when (get-edit-target-object) (send (get-edit-target-object) insert (make-gui-world-snip choice)))))]) (new menu-item% [parent (get-insert-menu)] [label "Insert Graph Function"] [callback (lambda (menu-item control-event) (send tool-frame show #t))]))))
false
10e46bcff1da0dfc00a6966f0ec277bbf72f3d55
0408ce7e2362217750e07f8bdb3a2849fdd26ec2
/examples/number-elements.scm
c7cd99ac5222bca08649929b1247d9f0aa217d61
[]
no_license
erhant/eopl-scheme
af8e0ae7b617b7e365ecf12af8993c6192c9b3b6
a1fe269153278b1b818eb2746610905244278ef4
refs/heads/master
2023-07-08T09:05:52.519276
2021-08-17T04:02:19
2021-08-17T04:02:19
265,209,851
0
0
null
null
null
null
UTF-8
Scheme
false
false
710
scm
number-elements.scm
#lang eopl ; number-elements-from: Listof(SchemeVal) x Int -> Listof(List(Int, SchemeVal)) ; usage: (number elements-from `(v_0 v_1 ... v_m) n) = ((n v_0) (n+1 v_1) ... (n+m v_m)) (define number-elements-from (lambda (lst n) ; parameters are a List and an Int (if (null? lst) '() ; If the list is empty just return empty (cons ; Otherwise, construct the (number element) pair (list n (car lst)) ; this is the construction (number-elements-from (cdr lst) (+ n 1)))))) ; the remaining pairs are appended to this guy ; this is the actual function. we needed the general version as we wrote above. (define number-elements (lambda (lst) (number-elements-from lst 0) ) )
false
3fcac8cbdd90c1742a925b99580d9919450e2be1
3323fb4391e76b853464a9b2fa478cd7429e9592
/simple-lib.ss
e6573ee60cf0495d71ca28b811821766e882c184
[]
no_license
simpleliangsl/hello-scheme
ceb203933fb056523f5288ce716569096a71ad97
31434fb810475ee0e8ec2e6816995a0041c47f44
refs/heads/master
2023-06-16T12:07:28.744188
2021-07-15T06:39:32
2021-07-15T06:39:32
386,197,304
0
0
null
null
null
null
UTF-8
Scheme
false
false
170
ss
simple-lib.ss
(library (simple-lib) (export empty-set) (import (rnrs)) (define empty-set '()) ) (library (doris-lib) (export doris) (import (rnrs)) (define doris "love") )
false
ba65ffc126ae1c4668783a5696a85c45f7d338f1
174072a16ff2cb2cd60a91153376eec6fe98e9d2
/Chap-Three/3-71.scm
b09b9cc96992a6458bc6c3cbcd038c03f6581ddf
[]
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
1,084
scm
3-71.scm
(load "3-70.scm") (define (cube x) (* x x x)) (define weight3 (lambda (x) (+ (cube (car x)) (cube (cadr x))))) (define (Ramanujan s) (define (stream-cadr s) (stream-car (stream-cdr s))) (define (stream-cddr s) (stream-cdr (stream-cdr s))) (let ((scar (stream-car s)) (scadr (stream-cadr s))) (if (= (weight3 scar) (weight3 scadr)) (cons-stream (list (weight3 scar) scar scadr) (Ramanujan (stream-cddr s))) (Ramanujan (stream-cdr s))))) ;(define (Ramanujan s) ; (let ( (scar (stream-car s)) ; (scadr (stream-car(stream-cdr s))) ) ; (if (= (weight3 scar) (weight3 scadr)) ; (cons-stream (list (weight3 scar) scar scadr) ; (Ramanujan (stream-cdr(stream-cdr s)))) ; (Ramanujan (stream-cdr s))))) ; (define Ramanujan-numbers (Ramanujan (weighted-pairs integers integers weight3))) ;(display-stream (stream-section Ramanujan-numbers 0 10))
false
de90b9697afef74c9a668e6d00c7d2e76215ba87
0855447c3321a493efa9861b3713209e37c03a4c
/scheme/exe1.ss
2a0dee68962cdee6e6b2992fdafdca86bd8588f3
[]
no_license
dasheng523/sicp
d04f30c50076f36928728ad2fe0da392dd0ae414
1c40c01e16853ad83b8b82130c2c95a5533875fe
refs/heads/master
2021-06-16T20:15:08.281249
2021-04-02T04:09:01
2021-04-02T04:09:01
190,505,284
0
0
null
null
null
null
UTF-8
Scheme
false
false
3,253
ss
exe1.ss
(define-syntax let* (syntax-rules () [(_ () e1 e2 ...) (let () e1 e2 ...)] [(_ ([a v1] [b v2] ...) e1 e2 ...) (let ([a v1]) (let* ([b v2] ...) e1 e2 ...))])) (let* ([a 5] [b (+ a a)] [c (+ a b)]) (list a b c)) (define-syntax mywhen (syntax-rules () [(_ test expr1 expr2 ...) (if test (begin expr1 expr2 ...) #f)])) (let ([x 3]) (unless (= x 0) (set! x (+ x 1))) (mywhen (= x 4) (set! x (* x 2))) x) (((call/cc (lambda (k) k)) (lambda (x) x)) "HEY!") (let ([x (call/cc (lambda (k) k))]) (x (lambda (ignore) "hi"))) (define retry #f) (define factorial (lambda (x) (if (= x 0) (call/cc (lambda (k) (set! retry k) 1)) (* x (factorial (- x 1)))))) (factorial 4) (retry 2) (call/cc (lambda (k) (* 5 4))) ;; 这个表达式就是一个很普通的表达式,它仅仅是运行它必须的逻辑。 (call/cc (lambda (k) k)) ;; 这个表达式指的是返回一个 continuation ,当给 continuation 一个值调用它的时候,它就是用这个值重新执行当前上下文的程序。 ;; lambda里面的表达式,只不过是原来的需要执行的内容,如果暴露出 continuation ,则意味着在调用函数的那个上下文被引用了。如下: (define factorial (lambda (x) (if (= x 0) (call/cc (lambda (k) (set! retry k) 1)) (* x (factorial (- x 1)))))) ;; retry关联的 continuation 就是调用(factorial 4)时创建的一个上下文环境,并以这个上下文环境作为lambda的body。 ;; 这里的call/cc意思是如果被调用了,那么就保存当前的上下文环境,以便 continuation 可以进一步运行。 (define n 0) (define print-n (lambda (pp) (display n) (newline) (set! n (+ n 1)) pp)) (define conut (lambda (k) k)) ((call/cc conut) (print-n (call/cc conut))) ;; 到底是如何想出来的呢? ;; 第一个 call/cc 是一个 continuation,它的定义是 (lambda (a1) (a1 (print-n (call/cc count)))) ;; 第二个call/cc是这样的定义 (lambda (a2) ((call/cc conut) (print-n a2))) ;; 执行print-n后,会打印一次n,然后返回第二个call/cc定义。 ((call/cc count) (lambda (a2) ((call/cc conut) (print-n a2)))) ;; 该表达式实际上转化之后 ((lambda (a1) (a1 (print-n (call/cc count)))) (lambda (a2) ((call/cc conut) (print-n a2)))) ;; 代换 ((lambda (a2) ((call/cc conut) (print-n a2))) (print-n (call/cc count))) ;; 此时执行(print-n (call/cc count))之后, continuation 的定义如下 (lambda (a3) ((lambda (a2) ((call/cc conut) (print-n a2))) (print-n a3))) ;; 应用于print-n后,打印一次n。 ;; 继续转换 ((lambda (a2) ((call/cc conut) (print-n a2))) (lambda (a3) ((lambda (a2) ((call/cc conut) (print-n a2))) (print-n a3)))) ;; 继续转换 ((call/cc conut) (print-n (lambda (a3) ((lambda (a2) ((call/cc conut) (print-n a2))) (print-n a3))))) ;; 转换 ((call/cc conut) (print-n (lambda (a3) ((call/cc conut) (print-n (print-n a3)))))) ;; 这样就跟上面的步骤循环了 (system "mkdir ss")
true
260a21e8690e60bda9bfb36beee51ffb202e215a
7b0df9640ae1b8e1172f0f90c5428b0802df8ed6
/dlna/root.scm
002016b78fca70d939a8ebc9206283108b235ac5
[]
no_license
erosness/sm-server
5954edfc441e773c605d2ac66df60bb983be01a3
cc302551e19f6d2b889a41ec28801004b0b28446
refs/heads/master
2020-08-31T13:23:03.670076
2016-02-18T19:10:55
2016-02-18T19:10:55
218,699,588
0
0
null
null
null
null
UTF-8
Scheme
false
false
3,072
scm
root.scm
(use ssax sxpath test clojurian-syntax) (include "sxml-common.scm") (define (%device element #!optional (end "/text()")) (conc "dev:root/dev:device/" element end)) (define device-type (sxpath/car (%device "dev:deviceType") ns)) (define friendly-name (sxpath/car (%device "dev:friendlyName") ns)) (define model-name (sxpath/car (%device "dev:modelName") ns)) (define services (sxpath "*//dev:serviceList/dev:service" ns)) (define service-type (sxpath/car "dev:serviceType/text()" ns)) (define control-url (sxpath/car "/dev:controlURL/text()" ns)) ;; if #f, use the same hostname as root-description: (define base-url (sxpath/car "*//dev:URLBase/text()" ns)) ;; returns url of content-directory or #f if service-type isn't a ;; ContentDirectory:1. (define (ContentDirectory:1 pair) (and (pair? pair) (eq? (car pair) 'urn:schemas-upnp-org:service:ContentDirectory:1) (cdr pair))) (define (string-maybe-drop-slash/right str) (if (string-suffix? "/" str) (string-drop-right str 1) str)) (test-group "string-maybe-drop-slash" (test "a" (string-maybe-drop-slash/right "a")) (test "a" (string-maybe-drop-slash/right "a/"))) (define (url->base-url base ctruri) (conc (string-maybe-drop-slash/right (uri->string (update-uri (uri-reference base) path: '() query: #f))) ctruri)) (define (media-server? doc) (equal? (device-type doc) "urn:schemas-upnp-org:device:MediaServer:1")) ;; control-url as an absolute url. (define (absolute-control-url baseurl sdoc) (and-let* ( ;; eg "/ctr/ContentDir or "http://10.0.0.89/ctr" (ctr-url (control-url sdoc))) (if (absolute-uri? (uri-reference ctr-url)) ctr-url (url->base-url baseurl ctr-url)))) (define (service-alist doc #!optional (baseurl (base-url doc))) (filter-map (lambda (s) (and-let* ((st (service-type s))) (cons (string->symbol st) (absolute-control-url baseurl s)))) (services doc))) (use http-client uri-common intarweb) ;; stolen from closing-http-client.scm. how should this be properly shared? (define (with-input-from-request* req writer reader) (let ((req (cond ((request? req) req) ((uri? req) (make-request uri: req)) ((string? req) (make-request uri: (uri-reference req)))))) (with-input-from-request (update-request req headers: (replace-header-contents 'connection '(#(close ())) (request-headers req))) writer reader))) ;; perform a HTTP request against uri, returning response as sxml (define (rootdesc-query uri) (define (read-sxml) (ssax:xml->sxml (current-input-port) '())) (values (condition-case (with-input-from-request* uri #f read-sxml) ;; quietly return #f on errors. more helpful error messages ;; should be logged elsewhere if needed: (e () #f)))) (include "root.test.scm")
false
8fd3f1c9cb174a5d95793582c40da895b1b43b64
958488bc7f3c2044206e0358e56d7690b6ae696c
/haskell/lisp/test.scm
0322a2861d067bda7869ce7f6645d1c2969d73d6
[]
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
112
scm
test.scm
(define c #\243) (display "c = '")(display c)(display "'")(newline) (display (eq? c #\243))(newline) (exit 0)
false
3f77a9a514e235c7d4ce53817d56a5188af86fdc
0bb7631745a274104b084f6684671c3ee9a7b804
/lib/srfi/27/test/test.scm
e44c1ce4987f4bd881009348da2f938977e185d3
[ "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
949
scm
test.scm
;;;============================================================================ ;;; File: "test.scm" ;;; Copyright (c) 1994-2020 by Marc Feeley, All Rights Reserved. ;;;============================================================================ ;;; SRFI 27, Sources of Random Bits (import (srfi 27)) (import (_test)) ;;;============================================================================ (test-eqv 0 (random-integer 1)) (define rand-ints (map (lambda (i) (random-integer 1000)) (iota 1000))) (test-assert (>= (apply min rand-ints) 0)) (test-assert (< (apply max rand-ints) 1000)) (define rand-reals (map (lambda (i) (random-real)) (iota 1000))) (test-assert (>= (apply min rand-reals) 0.0)) (test-assert (< (apply max rand-reals) 1.0)) (test-assert (random-source? default-random-source)) (test-assert (random-source? (make-random-source))) ;;;============================================================================
false
5054895ad8e9e0f6ebe17bf027f4c4e038e9d717
a0c856484b0cafd1d7c428fb271a820dd19be577
/lab6/interp-e.ss
64d55ff0d1c23dfe3f95795f387298552b05975d
[]
no_license
ctreatma/scheme_exercises
b13ba7743dfd28af894eb54429297bad67c14ffa
94b4e8886b2500a7b645e6dc795c0d239bf2a3bb
refs/heads/master
2020-05-19T07:30:58.538798
2012-12-03T23:12:22
2012-12-03T23:12:22
null
0
0
null
null
null
null
UTF-8
Scheme
false
false
1,822
ss
interp-e.ss
;; interp-e.ss ;; Interpreter for Mini-Scheme-E (require (lib "eopl.ss" "eopl")) (define eval-exp (lambda (exp) (cases exp-e exp (exp-e-lit (datum) datum) (exp-e-varref (var) (apply-env init-env var)) (exp-e-app (rator rands) (let ([proc (eval-exp rator)] [args (eval-rands rands)]) (apply-proc proc args))) (else (error 'eval-exp "Invalid abstract syntax: ~s" exp))))) (define eval-rands (lambda (rands) (map eval-exp rands))) (define apply-prim-op (lambda (prim-op args) (case prim-op [(+) (+ (car args) (cadr args))] [(-) (- (car args) (cadr args))] [(*) (* (car args) (cadr args))] [(add1) (+ (car args) 1)] [(sub1) (- (car args) 1)] [(minus) (- 0 (car args))] [(list) (cons (car args) (cdr args))] [(build) (cons (car args) (cadr args))] [(first) (caar args)] [(rest) (cdar args)] [else (error 'apply-prim-op "Invalid prim-op name: ~s" prim-op)]))) ; primop definitions (same as interp-b) (define-datatype prim prim? (prim-proc (prim-op proc-symbol?))) (define proc-symbol? (lambda (sym) (member sym '(+ - * / add1 sub1 minus list build first rest)))) (define prim-op-names '(+ - * add1 sub1 minus list build first rest)) (define init-env (extend-env '(nil) '(()) (extend-env prim-op-names (map prim-proc prim-op-names) the-empty-env))) ; apply-proc (define apply-proc (lambda (proc args) (cases prim proc (prim-proc (prim-op) (apply-prim-op prim-op args)) (else (error 'apply-proc "Invalid procedure: ~s" proc)))))
false
6652d64bbb0838e618dedb17a808a435901d6221
f4cf5bf3fb3c06b127dda5b5d479c74cecec9ce9
/Sources/LispKit/Resources/Libraries/lispkit/math/matrix.sld
ae0e96c65038f690f1581028fba7a69bb9f72633
[ "Apache-2.0" ]
permissive
objecthub/swift-lispkit
62b907d35fe4f20ecbe022da70075b70a1d86881
90d78a4de3a20447db7fc33bdbeb544efea05dda
refs/heads/master
2023-08-16T21:09:24.735239
2023-08-12T21:37:39
2023-08-12T21:37:39
57,930,217
356
17
Apache-2.0
2023-06-04T12:11:51
2016-05-03T00:37:22
Scheme
UTF-8
Scheme
false
false
23,404
sld
matrix.sld
;;; LISPKIT MATH MATRIX ;;; ;;; This library provides abstractions for representing vectors, matrices and ;;; for performing vector and matrix arithmetics. A matrix is a rectangular ;;; array of numbers. The library supports commong matrix operations such as ;;; matrix addition, subtraction, and multiplication. There are operations to ;;; create matrices and to manipulate matrix objects. Furthermore, there is ;;; support to compute matrix determinants and to transpose and invert matrices. ;;; Matrices can be transformed into reduced row echelon form and matrix ranks ;;; can be computed. ;;; ;;; Author: Matthias Zenger ;;; Copyright © 2022 Matthias Zenger. All rights reserved. ;;; ;;; Licensed under the Apache License, Version 2.0 (the "License"); you may not ;;; use this file except in compliance with the License. You may obtain a copy ;;; of the License at ;;; ;;; http://www.apache.org/licenses/LICENSE-2.0 ;;; ;;; Unless required by applicable law or agreed to in writing, software ;;; distributed under the License is distributed on an "AS IS" BASIS, WITHOUT ;;; WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the ;;; License for the specific language governing permissions and limitations ;;; under the License. (define-library (lispkit math matrix) (export matrix-type-tag make-matrix matrix identity-matrix matrix-copy matrix-eliminate matrix? matrix-vector? matrix-zero? matrix-square? matrix-identity? matrix-symmetric? matrix-dimensions? matrix=? matrix-size matrix-rows matrix-columns matrix-ref matrix-set! matrix-row  matrix-column matrix-row-swap! matrix-column-swap! matrix->vector matrix-row->list matrix-column->list matrix->list matrix-transpose matrix-sum! matrix-difference! matrix-add matrix-subtract matrix-mult matrix-minor matrix-cofactor matrix-determinant matrix-normalize matrix-inverse matrix-row-echelon! matrix-rank matrix-for-each matrix-fold matrix->string) (import (lispkit base)) (begin ;; Matrix type. (define-values (matrix-type-tag new-matrix matrix? matrix-repr make-matrix-subtype) (make-type 'matrix)) ;; Returns a new matrix with `m` rows and `n` columns. (define (make-matrix m n) (assert (fxpositive? m) (fxpositive? n)) (let ((mrepr (make-vector (fx+ (fx* m n) 2) 0))) (vector-set! mrepr 0 m) (vector-set! mrepr 1 n) (new-matrix mrepr))) ;; Returns a new matrix consisting of the rows ms, args ... Rows can be specified ;; either as a list or a vector. (define (matrix ms . args) (if (null? args) (cond ((pair? ms) (if (pair? (car ms)) (let* ((m (length ms)) (n (length (car ms))) (res (make-matrix m n)) (rrepr (matrix-repr res))) (assert (every? (lambda (r) (fx= (length r) n)) (cdr ms))) (do ((x 2 (fx1+ x)) (r (car ms) (if (pair? (cdr r)) (cdr r) (if (pair? rs) (car rs) '()))) (rs (cdr ms) (if (pair? (cdr r)) rs (if (pair? rs) (cdr rs) '())))) ((and (null? r) (null? rs)) res) (vector-set! rrepr x (car r)))) (matrix (list ms)))) ((vector? ms) (if (vector? (vector-ref ms 0)) (let* ((m (vector-length ms)) (n (vector-length (vector-ref ms 0))) (i 0) (res (make-matrix m n)) (rrepr (matrix-repr res))) (vector-for-each (lambda (r) (assert (fx= (vector-length r) n)) (vector-copy! rrepr (fx+ 2 (fx* i n)) r) (set! i (fx1+ i))) ms) res) (matrix (vector ms)))) (else (matrix (list (list ms))))) (if (pair? ms) (matrix (cons ms args)) (matrix (list->vector (cons ms args)))))) ;; Returns a new identity matrix with `n` rows and columns. (define (identity-matrix n) (assert (fxpositive? n)) (let ((mrepr (make-vector (fx+ (fx* n n) 2) 0))) (vector-set! mrepr 0 n) (vector-set! mrepr 1 n) (do ((i 0 (fx1+ i))) ((fx= i n)) (vector-set! mrepr (matrix-repr-index mrepr i i) 1)) (new-matrix mrepr))) ;; Returns a copy of `matrix`. (define (matrix-copy matrix) (let ((mrepr (matrix-repr matrix))) (new-matrix (vector-copy mrepr #t)))) ;; Returns a copy of `matrix` with row `i` and column `j` removed. (define (matrix-eliminate matrix i j) (let* ((mrepr (matrix-repr matrix)) (m (matrix-rows matrix)) (n (matrix-columns matrix)) (temp (make-matrix (fx1- m) (fx1- n))) (trepr (matrix-repr temp))) (assert (fx> m i -1) (fx> n j -1)) (do ((x 2 (fx1+ x)) (y 2)) ((fx= x (vector-length mrepr)) temp) (if (not (or (fx= (fx/ (fx- x 2) n) i) (fx= (fxremainder (fx- x 2) n) j))) (begin (vector-set! trepr y (vector-ref mrepr x)) (set! y (fx1+ y))))))) ;; Returns `#t` if `v` is a vector of numbers (define (matrix-vector? v) (and (vector? v) (fxpositive? (vector-length v)) (do ((i (fx1- (vector-length v)) (fx1- i))) ((or (fxnegative? i) (not (number? (vector-ref v i)))) (fxnegative? i))))) ;; Returns `#t` if `matrix` is a zero matrix, i.e. all its elements are zero. (define (matrix-zero? matrix) (matrix-fold (lambda (z i j x) (and z (zero? x))) #t matrix)) ;; Returns `#t` if `matrix` is a square matrix. (define (matrix-square? matrix) (fx= (matrix-rows matrix) (matrix-columns matrix))) ;; Returns `#t` if `matrix` is a identity matrix. (define (matrix-identity? matrix) (and (matrix-square? matrix) (matrix-fold (lambda (z i j x) (and z (if (fx= i j) (= x 1) (= x 0)))) #t matrix))) ;; Returns `#t` if `matrix` is symmetric, i.e. `matrix` is equal to its ;; transposed matrix. (define (matrix-symmetric? matrix) (and (matrix-square? matrix) (matrix-fold (lambda (z i j x) (and z (= x (matrix-ref matrix j i)))) #t matrix))) ;; Returns `#t` if the given object is a matrix of the given dimensions (define (matrix-dimensions? obj m n) (and (matrix? obj) (fx= (matrix-rows obj) m) (fx= (matrix-columns obj) n))) ;; Returns `#t` if all matrices in list `args` are equal to `matrix`. (define (matrix=? matrix . args) (let ((mrepr (matrix-repr matrix))) (fold-left (lambda (z m) (and z (vector= = mrepr (matrix-repr m)))) #t args))) ;; Returns the size of the matrix as a pair whose car is the number of rows and cdr ;; is the number of columns. (define (matrix-size matrix) (cons (vector-ref (matrix-repr matrix) 0) (vector-ref (matrix-repr matrix) 1))) ;; Returns the number of rows in a matrix. (define (matrix-rows matrix) (vector-ref (matrix-repr matrix) 0)) ;; Returns the number of columns in a matrix. (define (matrix-columns matrix) (vector-ref (matrix-repr matrix) 1)) (define (matrix-repr-index mrepr i j) (fx+ (fx* (vector-ref mrepr 1) i) j 2)) (define (matrix-repr-ref mrepr i j) (vector-ref mrepr (fx+ (fx* (vector-ref mrepr 1) i) j 2))) ;; Returns the j-th element of the i-th row. (define (matrix-ref matrix i j) (let ((mrepr (matrix-repr matrix))) (assert (fx> (vector-ref mrepr 0) i -1) (fx> (vector-ref mrepr 1) j -1)) (matrix-repr-ref mrepr i j))) ;; Sets the j-th element of the i-th row to x (define (matrix-set! matrix i j x) (let ((mrepr (matrix-repr matrix))) (assert (fx> (vector-ref mrepr 0) i -1) (fx> (vector-ref mrepr 1) j -1)) (vector-set! mrepr (matrix-repr-index mrepr i j) x))) ;; Returns row `i` of `matrix` as a vector. (define (matrix-row matrix i) (let* ((mrepr (matrix-repr matrix)) (res (make-vector (vector-ref mrepr 1)))) (assert (fx> (vector-ref mrepr 0) i -1)) (do ((j (fx1- (vector-ref mrepr 1)) (fx1- j))) ((fxnegative? j) res) (vector-set! res j (vector-ref mrepr (matrix-repr-index mrepr i j)))))) ;; Returns column `i` of `matrix` as a vector. (define (matrix-column matrix j) (let* ((mrepr (matrix-repr matrix)) (res (make-vector (vector-ref mrepr 0)))) (assert (fx> (vector-ref mrepr 1) j -1)) (do ((i (fx1- (vector-ref mrepr 0)) (fx1- i))) ((fxnegative? i) res) (vector-set! res i (vector-ref mrepr (matrix-repr-index mrepr i j)))))) ;; Returns `matrix` as a vector of vectors. (define (matrix->vector matrix) (do ((i (fx1- (matrix-rows matrix)) (fx1- i)) (res (make-vector (matrix-rows matrix)))) ((fxnegative? i) res) (vector-set! res i (matrix-row matrix i)))) ;; Returns row `i` of `matrix` as a list (define (matrix-row->list matrix i) (let ((mrepr (matrix-repr matrix))) (assert (fx> (vector-ref mrepr 0) i -1)) (do ((j (fx1- (vector-ref mrepr 1)) (fx1- j)) (row '() (cons (vector-ref mrepr (matrix-repr-index mrepr i j)) row))) ((fxnegative? j) row)))) ;; Returns column `j` of `matrix` as a list (define (matrix-column->list matrix j) (let ((mrepr (matrix-repr matrix))) (assert (fx> (vector-ref mrepr 1) j -1)) (do ((i (fx1- (vector-ref mrepr 0)) (fx1- i)) (col '() (cons (vector-ref mrepr (matrix-repr-index mrepr i j)) col))) ((fxnegative? i) col)))) ;; Returns `matrix` as a list of lists (define (matrix->list matrix) (do ((i (fx1- (matrix-rows matrix)) (fx1- i)) (res '() (cons (matrix-row->list matrix i) res))) ((fxnegative? i) res))) ;; Invokes `f` for every element of `matrix`. `f` is a function taking three ;; arguments: the row, the column, and the element at this position. The traversal ;; order is by row from left to right. (define (matrix-for-each f matrix) (let ((m (matrix-rows matrix)) (n (matrix-columns matrix))) (do ((i 0 (if (= j (fx1- n)) (fx1+ i) i)) (j 0 (if (= j (fx1- n)) 0 (fx1+ j)))) ((= i m)) (f i j (matrix-ref matrix i j))))) ;; Folds the matrix elements row by row from left to right, invoking `f` with ;; the accumulator, the row, the column and the element at this position. (define (matrix-fold f z matrix) (let ((m (matrix-rows matrix)) (n (matrix-columns matrix))) (do ((i 0 (if (= j (fx1- n)) (fx1+ i) i)) (j 0 (if (= j (fx1- n)) 0 (fx1+ j)))) ((= i m) z) (set! z (f z i j (matrix-ref matrix i j)))))) ;; Returns `matrix` in transposed form. (define (matrix-transpose matrix) (let ((res (make-matrix (matrix-columns matrix) (matrix-rows matrix)))) (matrix-for-each (lambda (i j x) (matrix-set! res j i x)) matrix) res)) ;; Sums up `matrix` and all matrices in `args` storing the result in `matrix`. (define (matrix-sum! matrix . args) (do ((m (matrix-rows matrix)) (n (matrix-columns matrix)) (ms args (cdr ms))) ((null? ms)) (assert (matrix-dimensions? (car ms) m n)) (matrix-for-each (lambda (i j x) (matrix-set! matrix i j (+ (matrix-ref matrix i j) x))) (car ms)))) ;; Subtracts the matrices from list `args` from `matrix`, storing the result ;; in `matrix`. (define (matrix-difference! matrix . args) (do ((m (matrix-rows matrix)) (n (matrix-columns matrix)) (ms args (cdr ms))) ((null? ms)) (assert (matrix-dimensions? (car ms) m n)) (matrix-for-each (lambda (i j x) (matrix-set! matrix i j (- (matrix-ref matrix i j) x))) (car ms)))) ;; Returns the sum of `matrix` and all matrices in list `args`. This procedure ;; also supports vector addition. (define (matrix-add matrix . args) (let ((m (matrix-normalize matrix))) (cond ((matrix? m) (let ((res (matrix-copy m))) (apply matrix-sum! res args) res)) ((vector? m) (let ((res (vector-copy m #t))) (for-each (lambda (v) (vector-for-each/index (lambda (i x) (vector-set! res i (+ (vector-ref res i) x))) (matrix-normalize v))) args) res)) (else (apply + m args))))) ;; Returns the difference of `matrix` and the matrices in list `args`. This procedure ;; also supports vector differences. (define (matrix-subtract matrix . args) (let ((m (matrix-normalize matrix))) (cond ((matrix? m) (let ((res (matrix-copy m))) (apply matrix-difference! res args) res)) ((vector? m) (let ((res (vector-copy m #t))) (for-each (lambda (v) (vector-for-each/index (lambda (i x) (vector-set! res i (- (vector-ref res i) x))) (matrix-normalize v))) args) res)) (else (apply - m args))))) ;; Returns a normalized version of `x`, representing 1*1 matrices as a number and ;; m*1 and 1*n matrices as a vector. (define (matrix-normalize x) (cond ((matrix? x) (cond ((fx= (matrix-rows x) 1) (if (fx= (matrix-columns x) 1) (matrix-ref x 0 0) (matrix-row x 0))) ((fx= (matrix-columns x) 1) (matrix-column x 0)) (else x))) ((vector? x) (if (fx= (vector-length x) 1) (vector-ref x 0) x)) (else x))) (define (dot-prod v1 v2) (assert (fx= (vector-length v1) (vector-length v2))) (do ((i (fx1- (vector-length v1)) (fx1- i)) (acc 0 (+ acc (* (vector-ref v1 i) (vector-ref v2 i))))) ((fxnegative? i) acc))) (define (sca-mult m x) (let* ((nr (matrix-rows m)) (nc (matrix-columns m)) (res (make-matrix nr nc))) (do ((i 0 (fx1+ i))) ((fx= i nr) res) (do ((j 0 (fx1+ j))) ((fx= j nc)) (matrix-set! res i j (* x (matrix-ref m i j))))))) (define (mat-mult m1 m2) (let* ((m (matrix-rows m1)) (n (matrix-rows m2)) (o (matrix-columns m2)) (res (make-matrix m o))) (assert (= (matrix-columns m1) n)) (do ((i 0 (fx1+ i))) ((fx= i m) res) (do ((j 0 (fx1+ j))) ((fx= j o)) (do ((k 0 (fx1+ k)) (acc 0 (+ acc (* (matrix-ref m1 i k) (matrix-ref m2 k j))))) ((fx= k n) (matrix-set! res i j acc))))))) (define (mult x y) (cond ((matrix? x) (cond ((matrix? y) (mat-mult x y)) ((vector? y) (mat-mult x (matrix-transpose (matrix y)))) (else (sca-mult x y)))) ((vector? x) (cond ((matrix? y) (mat-mult (matrix x) y)) ((vector? y) (dot-prod x y)) (else (vector-map (lambda (z) (* z y)) x)))) (else (cond ((matrix? y) (sca-mult y x)) ((vector? y) (vector-map (lambda (z) (* z x)) y)) (else (* x y)))))) ;; Returns the matrix product of `x` and the matrices in `args`. Can also be used ;; to compute the dot product of vectors. (define (matrix-mult x . args) (do ((ms args (cdr ms)) (res (matrix-normalize x) (matrix-normalize (mult res (matrix-normalize (car ms)))))) ((null? ms) res))) ;; Returns a minor of `matrix` by removing row `i` and column `j` and computing ;; the determinant of the remaining matrix. `matrix` needs to be a square matrix. (define (matrix-minor matrix i j) (matrix-determinant (matrix-eliminate matrix i j))) ;; Returns a minor of `matrix` by removing row `i` and column `j` and computing ;; the determinant of the remaining matrix. The result is negative if the sum ;; of `i` and `j` is odd. `matrix` needs to be a square matrix. (define (matrix-cofactor matrix i j) (* (if (fxodd? (fx+ i j)) -1 1) (matrix-minor matrix i j))) ;; Returns the determinant of `matrix`. `matrix` needs to be a square matrix. (define (matrix-determinant matrix) (let ((n (matrix-columns matrix))) (assert (fx= (matrix-rows matrix) n)) (case n ((1) (matrix-ref matrix 0 0)) ((2) (- (* (matrix-ref matrix 0 0) (matrix-ref matrix 1 1)) (* (matrix-ref matrix 0 1) (matrix-ref matrix 1 0)))) (else (do ((j 0 (fx1+ j)) (acc 0 (+ acc (* (matrix-ref matrix 0 j) (matrix-cofactor matrix 0 j))))) ((fx= j n) acc)))))) ;; Returns the inverse of `matrix` if it exists. If it does not exist, `#f` is ;; being returned. `matrix` needs to be a square matrix. (define (matrix-inverse matrix) (let* ((m (matrix-rows matrix)) (n (matrix-columns matrix)) (cfm (make-matrix m n))) (assert (fx= m n)) (matrix-for-each (lambda (i j x) (matrix-set! cfm i j (matrix-cofactor matrix i j))) matrix) (let ((res (matrix-transpose cfm)) (det (do ((j 0 (fx1+ j)) (acc 0 (+ acc (* (matrix-ref matrix 0 j) (matrix-ref cfm 0 j))))) ((fx= j n) acc)))) (if (zero? det) #f (matrix-mult res (/ 1 det)))))) ;; Swaps columns `j` and `k` of `matrix`. (define (matrix-column-swap! matrix j k) (assert (fx> (matrix-columns matrix) j -1) (fx> (matrix-columns matrix) k -1)) (do ((mrepr (matrix-repr matrix)) (i (fx1- (matrix-rows matrix)) (fx1- i))) ((fxnegative? i)) (vector-swap! mrepr (matrix-repr-index mrepr i j) (matrix-repr-index mrepr i k)))) ;; Swaps rows `i` and `k` of `matrix`. (define (matrix-row-swap! matrix i k) (assert (fx> (matrix-rows matrix) i -1) (fx> (matrix-rows matrix) k -1)) (do ((mrepr (matrix-repr matrix)) (j (fx1- (matrix-columns matrix)) (fx1- j))) ((fxnegative? j)) (vector-swap! mrepr (matrix-repr-index mrepr i j) (matrix-repr-index mrepr k j)))) ;; Returns the reduced row echelon matrix of `matrix`. (define (matrix-row-echelon! matrix) (let ((m (matrix-rows matrix)) (n (matrix-columns matrix))) (do ((i 0 (fx1+ i)) (k (fx1- m))) ((fx> i k) (set! m (fx1+ k))) (cond ((do ((j (fx1- n) (fx1- j))) ((or (fxnegative? j) (not (zero? (matrix-ref matrix i j)))) (fxnegative? j))) (matrix-row-swap! matrix i k) (set! k (fx1- k))))) (do ((p 0 (fx1+ p))) ((or (fx>= p m) (fx>= p n))) (do ((r 1 (fx1+ r))) ((or (not (zero? (matrix-ref matrix p p))) (fx>= (fx+ p r) m)) (if (not (zero? (matrix-ref matrix p p))) (do ((i 0 (fx1+ i))) ((fx>= i m)) (cond ((fx= i p) (do ((x (/ 1 (matrix-ref matrix p p))) (c p (fx1+ c))) ((fx>= c n)) (matrix-set! matrix i c (* (matrix-ref matrix p c) x)))) ((not (zero? (matrix-ref matrix i p))) (do ((x (- (/ (matrix-ref matrix i p) (matrix-ref matrix p p)))) (c p (fx1+ c))) ((fx>= c n)) (matrix-set! matrix i c (+ (* (matrix-ref matrix p c) x) (matrix-ref matrix i c))))))))) (matrix-row-swap! matrix p (fx+ p r)))))) ;; Returns the rank of `matrix`. (define (matrix-rank matrix) (let ((m (matrix-copy matrix))) (matrix-row-echelon! m) (do ((i (fx1- (matrix-rows m)) (fx1- i)) (res 0 (fx+ res (do ((j (fx1- (matrix-columns m)) (fx1- j))) ((or (fxnegative? j) (not (zero? (matrix-ref m i j)))) (if (fxnegative? j) 0 1)))))) ((fxnegative? i) res)))) ;; Returns a multi-line string representation of `matrix`. The elements of `matrix` ;; are converted into a string by invocing `(number->string x clen prec noexp)`. (define (matrix->string matrix . args) (let-optionals args ((clen 1) (prec #f) (noexp #t)) (let* ((m (matrix-rows matrix)) (n (matrix-columns matrix)) (lens (make-vector n 0)) (strs (make-vector (fx* n m)))) (matrix-for-each (lambda (i j x) (let* ((str (number->string x 10 clen prec noexp)) (len (string-length str))) (if (fx> len (vector-ref lens j)) (vector-set! lens j len)) (vector-set! strs (fx+ (fx* n i) j) str))) matrix) (do ((i 0 (if (fx= j (fx1- n)) (fx1+ i) i)) (j 0 (if (fx= j (fx1- n)) 0 (fx1+ j))) (s (make-string 0))) ((fx= i m) s) (string-append! s (cond ((fx> j 0) " ") ((fx= n 1) "(") ((fx= i 0) "⎛") ((fx= i (fx1- m)) "⎝") (else "⎜")) (string-pad-left (vector-ref strs (fx+ (fx* n i) j)) #\space (vector-ref lens j)) (cond ((fx< j (fx1- n)) "") ((fx= n 1) ")\n") ((fx= i 0) "⎞\n") ((fx= i (fx1- m)) "⎠\n") (else "⎟\n"))))))) ) )
false
261475cffe1c59004d4df90210b2cc1bda76e6f1
f04768e1564b225dc8ffa58c37fe0213235efe5d
/Assignment5/5.ss
bc4371e4b01d8971aaf285946302cc05b66d9421
[]
no_license
FrancisMengx/PLC
9b4e507092a94c636d784917ec5e994c322c9099
e3ca99cc25bd6d6ece85163705b321aa122f7305
refs/heads/master
2021-01-01T05:37:43.849357
2014-09-09T23:27:08
2014-09-09T23:27:08
23,853,636
1
0
null
null
null
null
UTF-8
Scheme
false
false
4,803
ss
5.ss
;Francis Meng Assignment 4 ;Question 1 Return a minimized interval of the given set of intervals (define (minimize-interval-list ls) (if (or (equal? ls '()) (equal? (cdr ls) '())) ls (get-min-set '() ls)) ) (define (get-min-set curMinSet li) (if (equal? li '()) curMinSet (get-min-set (get-single-min-set curMinSet (car li)) (cdr li))) ) (define (get-single-min-set curMinSet li) (if (equal? curMinSet '()) (cons li '()) (if (equal? (cdr (minimize-two-intervals (car curMinSet) li)) '()) (cons (car (minimize-two-intervals (car curMinSet) li)) (cdr curMinSet)) (cons (car curMinSet) (get-single-min-set (cdr curMinSet) li)))) ) (define (minimize-two-intervals ls1 ls2) (if (< (car ls1) (car ls2)) (if (< (car (cdr ls1)) (car ls2)) (cons ls1 (cons ls2 '())) (if (< (car (cdr ls1)) (car (cdr ls2))) (cons (cons (car ls1) (cdr ls2)) '()) (cons ls1 '()))) (if (< (car (cdr ls2)) (car ls1)) (cons ls2 (cons ls1 '())) (if (< (car (cdr ls2)) (car (cdr ls1))) (cons (cons (car ls2) (cdr ls1)) '()) (cons ls2 '()))))) ;Question 2 Check if there is at list one element in the list is applicable to the pred (define (exists? pred li) (if (equal? li '()) #f (if (pred (car li)) #t (exists pred (cdr li))))) ;Question 3 Give the first index of the element that satisfy the pred (define (list-index pred li) (if (equal? li '()) #f (if (pred (car li)) '0 (if (number? (list-index pred (cdr li))) (+ 1 (list-index pred (cdr li))) #f))) ) ;Question 4 return the pascal-triangle with given layer number (define (pascal-triangle n) (if (< n 0) '() (cons (getButtomLevel n n) (pascal-triangle (- n 1)))) ) (define (getButtomLevel n m) (if (equal? m 0) (cons 1 '()) (cons (choose n m) (getButtomLevel n (- m 1)))) ) (define choose (lambda (n m) (/ (fact n) (* (fact m) (fact (- n m)))) ) ) (define fact (lambda (n) (if (= n 0) 1 (if (= n 1) 1 (* n (fact (- n 1))) ) ) ) ) ;Question 5 return the cartesian product of two sets (define (product set1 set2) (if (equal? set1 '()) '() (union (map (lambda (x) (cons (car set1) (cons x '()))) set2) (product (cdr set1) set2))) ) (define (union s1 s2) (if (equal? s2 '()) s1 (if (member (car s2) s1) (union s1 (cdr s2)) (cons (car s2) (union s1 (cdr s2))))) ) ;Question 6 return the number of edges that given vertices can form (define (max-edges n) (if (< n 2) 0 (choose n 2))) ;Question 7 check if the given graph is complete (define (complete? g) (if (equal? g '()) #t (if (checkComplete (domain g) (car g)) (complete? (cdr g)) #f)) ) (define (checkComplete dom g) (if (equal? dom '()) #t (if (member (car dom) (car (cdr g))) (checkComplete (cdr dom) g) (if (equal? (car dom) (car g)) (checkComplete (cdr dom) g) #f))) ) (define (domain r) (if (equal? r '()) '() (if (member (car (car r)) (domain (cdr r))) (domain (cdr r)) (cons (car (car r)) (domain (cdr r))))) ) ;Question 8 construct complete graph with given vertices; (define (complete ls) (if (equal? ls '()) '() (constructGraph ls ls)) ) (define (constructGraph curPos ls) (if (equal? curPos '()) '() (cons (cons (car curPos) (cons (constructDestiList (car curPos) ls) '())) (constructGraph (cdr curPos) ls))) ) (define (constructDestiList curPos ls) (if (equal? ls '()) '() (if (equal? curPos (car ls)) (constructDestiList curPos (cdr ls)) (cons (car ls) (constructDestiList curPos (cdr ls)))))) ;Question 9 replace the first given data with the second given data in the given list (define (replace old new ls) (if (equal? ls '()) '() (if (equal? (car ls) old) (cons new (replace old new (cdr ls))) (cons (car ls) (replace old new (cdr ls))))) ) ;Question 10 delete first appeared element in the list (define (remove-first element ls) (if (equal? ls '()) '() (if (equal? element (car ls)) (cdr ls) (cons (car ls) (remove-first element (cdr ls))))) ) ;Question 11 delete last appeared element in the list (define (remove-last element ls) (if (equal? ls '()) '() (if (equal? element (car ls)) (if (last? element (cdr ls)) (cdr ls) (cons (car ls) (remove-last element (cdr ls)))) (cons (car ls) (remove-last element (cdr ls)))))) (define (last? element ls) (if (equal? ls '()) #t (if (equal? element (car ls)) #f (last? element (cdr ls)))))
false
1df1050736a14f250808741c041a805586b12397
b8034221175e02a02307ef3efef129badecda527
/tests/chart-example.scm
5b69d9647a5c07c8a6a6cbd85e0143c928a3dc4e
[]
no_license
nobody246/xlsxWriterScm
ded2410db122dfbe8bbb5e9059239704ee9a5b32
d02ed10c3e8c514cc1b6a9eaf793a2cde34c4c47
refs/heads/master
2022-04-27T23:29:45.258892
2022-04-15T22:04:02
2022-04-15T22:04:02
153,357,109
0
1
null
null
null
null
UTF-8
Scheme
false
false
775
scm
chart-example.scm
(use xlsxwriterscm) (create-workbook "chart-example.xlsx") (add-worksheet "") (define (write-worksheet-data) (let ((d `((1 2 3) (2 4 6) (3 6 9) (4 8 12) (5 10 15))) (row 0)) (for-each (lambda(x) (set-pos row 0) (worksheet-write-number (car x)) (set-col 1) (worksheet-write-number (cadr x)) (set-col 2) (worksheet-write-number (caddr x)) (set! row (add1 row))) d))) (write-worksheet-data) (create-chart ($chart-type 'column)) (create-chart-series "" "Sheet1!$A$1:$A$5") (create-chart-series "" "Sheet1!$B$1:$B$5") (create-chart-series "" "Sheet1!$C$1:$C$5") (set-pos 6 1) (worksheet-insert-chart) (close-workbook) (exit)
false
9673febb46b39dee2c47f75f565750d39c477703
59d5121573c9397e5da52d630558f4187f80b25e
/A04testcode.ss
aeb1965a966cc17e98fb4bb22a725d5ddb7bd328
[ "MIT" ]
permissive
haskellstudio/CSSE304
dc900af2102b6e8bffca38f7be7d5236007c1a5d
698ceabf026cb847754fc2bc01c16641b2f2c2af
refs/heads/master
2021-04-03T05:16:05.177891
2018-02-13T21:35:01
2018-02-13T21:35:01
null
0
0
null
null
null
null
UTF-8
Scheme
false
false
2,419
ss
A04testcode.ss
(define (test-lex) (let ([correct '(((lambda (var 0)) (const 5)) (lambda (lambda (if (zero? (var 0)) (const 1) (* (var 0) ((var 1) (sub1 (var 0))))))) (let (lambda (lambda (if (zero? (var 0)) (const 1) (* (var 0) (((var 1) (var 1)) (sub1 (var 0))))))) (((var 0) (var 0)) (const 5))))] [answers (list (lex '((lambda (x) x) 5) '()) (lex '(lambda (!) (lambda (n) (if (zero? n) 1 (* n (! (sub1 n)))))) '()) (lex '(let ((! (lambda (!) (lambda (n) (if (zero? n) 1 (* n ((! !) (sub1 n)))))))) ((! !) 5)) '()))]) (display-results correct answers equal?))) (define (test-value-of-dynamic) (let ([correct '(5 120 120 ((1 1 2 3) (2 2 3) (3 3)))] [answers (list (value-of-dynamic '(let ([x 2]) (let ([f (lambda (e) x)]) (let ([x 5]) (f 0)))) (empty-env)) (value-of-dynamic '(let ([! (lambda (n) (if (zero? n) 1 (* n (! (sub1 n)))))]) (! 5)) (empty-env)) (value-of-dynamic '((lambda (!) (! 5)) (lambda (n) (if (zero? n) 1 (* n (! (sub1 n)))))) (empty-env)) (value-of-dynamic '(let ([f (lambda (x) (cons x l))]) (let ([cmap (lambda (f) (lambda (l) (if (null? l) '() (cons (f (car l)) ((cmap f) (cdr l))))))]) ((cmap f) (cons 1 (cons 2 (cons 3 '())))))) (empty-env)))]) (display-results correct answers equal?))) ;;----------------------------------------------- (define display-results (lambda (correct results test-procedure?) (display ": ") (pretty-print (if (andmap test-procedure? correct results) 'All-correct `(correct: ,correct yours: ,results))))) (define set-equals? ; are these list-of-symbols equal when (lambda (s1 s2) ; treated as sets? (if (or (not (list? s1)) (not (list? s2))) #f (not (not (and (is-a-subset? s1 s2) (is-a-subset? s2 s1))))))) (define is-a-subset? (lambda (s1 s2) (andmap (lambda (x) (member x s2)) s1))) ;; You can run the tests individually, or run them all ;; by loading this file (and your solution) and typing (r) (define (run-all) (display 'test-lex) (test-lex) (display 'test-value-of-dynamic) (test-value-of-dynamic)) (define r run-all)
false
6849e69b2c2998a25c887b0ab3f9bf15a7a3280a
085fc922af345f9b56c55975e7db891f4ff5c642
/the-cpser.ss
74b09dce86401f6eb9725ce78b6dfbac83feb94b
[]
no_license
hgztheyoung/CasuallyWrittenCode
f0b2e8f6af547f7ea86809b95e191f403f0f4bbc
7193b57baead7166ba1f4c0a080292d356c57b33
refs/heads/master
2021-06-21T07:16:30.241035
2020-12-23T09:57:10
2020-12-23T09:57:10
134,129,199
1
1
null
null
null
null
UTF-8
Scheme
false
false
7,725
ss
the-cpser.ss
(import (Framework match)) (import (Framework helpers)) (case-sensitive #t) (optimize-level 2) (print-gensym 'pretty) (load "mk.scm") (define-syntax λ (syntax-rules () [(_ (x ...) body ...) (lambda (x ...) body ...)])) (define (cps1 program k) (match program [,s (guard (symbol? s)) (k s)] [(λ (,x) ,body) (guard (symbol? x)) (k `(λ (,x k) ,(cps1 body (λ (x) `(k ,x)))))] [(,app ,rator) (cps1 app (λ (acode) (cps1 rator (λ (rcode) (let ([sym (gensym)]) `(,acode ,rcode (λ (,sym) ,(k sym))))))))])) (define (subst o n s-exp) (match s-exp [() '()] [,a (guard (symbol? a)) (if (eq? a o) n a)] [(,[a] . ,[d]) `(,a . ,d)])) (define (substᵒ o n s-exp out) (conde [(== s-exp '()) (== '() out)] [(symbolo s-exp) (conde [(== s-exp o) (== n out)] [(=/= s-exp o) (== s-exp out)])] [(fresh (a d ares dres) (== `(,ares . ,dres) out) (== `(,a . ,d) s-exp) (substᵒ o n a ares) (substᵒ o n d dres))])) (define (cps-i cpsed-program k) (match cpsed-program [,s (guard (symbol? s)) (k s)] [(λ (,x k) ,body) (guard (symbol? x)) (cps-i body (λ (rbody) (k `(λ (,x) ,rbody))))] [(k ,sth) (k (cps-i sth k))] [(,app ,rator (λ (,ressymbol) ,body)) (cps-i app (λ (rapp) (cps-i rator (λ (rrator) (let* ([body-res (cps-i body k)]) (subst ressymbol `(,rapp ,rrator) body-res))))))])) ; defunc cps-i ;we treat subst as atomic here to save some strength (define (cps-i-defunc cpsed-program k) (match cpsed-program [,s (guard (symbol? s)) (apply-cps-i-defunc k s)] [(λ (,x k) ,body) (guard (symbol? x)) (cps-i-defunc body `(K-λ-final ,x ,k))] [(k ,sth) (cps-i-defunc sth k)] [(,app ,rator (λ (,sym) ,body)) (cps-i-defunc app `(K-app-rator ,rator ,sym ,body ,k))])) (define (apply-cps-i-defunc k-struct code) (match k-struct [K-id code] [(K-λ-final ,x ,k) (apply-cps-i-defunc k `(λ (,x) ,code))] [(K-app-rator ,rator ,sym ,body ,k) (cps-i-defunc rator `(K-app-body ,code ,sym ,body ,k))] [(K-app-body ,rapp ,sym ,body ,k) (cps-i-defunc body `(K-app-final ,rapp ,code ,sym ,k))] [(K-app-final ,rapp ,rrator ,sym ,k) (apply-cps-i-defunc k (subst sym `(,rapp ,rrator) code))])) (define-syntax display-expr (syntax-rules () [(_ expr) (begin (display expr) (display "\n") expr)])) (define (decent-λ p bound-l) (match p [,sym (guard (member sym bound-l)) sym] [(λ (,x) ,body) (guard (symbol? x)) `(λ (,x) ,(decent-λ body (cons x bound-l)))] [(,[app] ,[rator]) `(,app ,rator)])) (define (consᵒ a d p) (== p `(,a . ,d))) (define (carᵒ l a) (fresh (d) (consᵒ a d l))) (define (cdrᵒ l d) (fresh (a) (consᵒ a d l))) (define (pairᵒ p) (fresh (a d) (consᵒ a d p))) (define (listᵒ l) (conde [(== l '())] [(pairᵒ l) (fresh (d) (cdrᵒ l d) (listᵒ d))])) (define (proper-memberᵒ x l) (conde [(carᵒ l x) (fresh (d) (cdrᵒ l d) (listᵒ d))] [(fresh (d) (cdrᵒ l d) (proper-memberᵒ x d))])) (define (decent-λᵒ bound-syms out) (conde [(symbolo out) (proper-memberᵒ out bound-syms)] [(fresh (x body nm) (== out `(λ (,x) ,body)) (symbolo x) (consᵒ x bound-syms nm) (decent-λᵒ nm body))] [(fresh (app rator) (== out `(,app ,rator)) (decent-λᵒ bound-syms app) (decent-λᵒ bound-syms rator))])) (define (decent-λ p bound-l) (match p [,sym (guard (member sym bound-l)) sym] [(λ (,x) ,body) (guard (symbol? x)) `(λ (,x) ,(decent-λ body (cons x bound-l)))] [(,[app] ,[rator]) `(,app ,rator)])) (define (cpsᵒ p k out) (conde [(symbolo p) (apply-kᵒ k p out)] [(fresh (x body bout) (== p `(λ (,x) ,body)) (cpsᵒ body 'K-k0 bout) (apply-kᵒ k `(λ (,x k) ,bout) out))] [(fresh (app rator) (== p `(,app ,rator)) (cpsᵒ app `(K-app-1 ,k ,rator) out))])) (define (apply-kᵒ k-strcut code out) (conde [(== k-strcut 'K-id) (== code out)] [(== k-strcut 'K-k0) (== `(k ,code) out)] [(fresh (k rator) (== k-strcut `(K-app-1 ,k ,rator)) (cpsᵒ rator `(K-app-0 ,k ,code) out))] [(fresh (k acode) (== k-strcut `(K-app-0 ,k ,acode)) (conda [(== k 'K-k0) (== `(,acode ,code k) out)] [(fresh (sym appout) (symbolo sym) (apply-kᵒ k sym appout) (== `(,acode ,code (λ (,sym) ,appout)) out))]))])) (define (decent-cpsedᵒ p) (fresh (raw) (decent-λᵒ '() raw) (cpsᵒ raw 'K-id p))) (define (id x) x) ;now,ready to create cps-iᵒ (define (cps-iᵒ program k out) (decent-cpsedᵒ program) (conde [(symbolo program) (apply-cps-iᵒ k program out)] [(fresh (x body) (== program `(λ (,x k) ,body)) (symbolo x) (cps-iᵒ body `(K-λ-final ,x ,k) out))] [(fresh (sth) (== program `(k ,sth)) (cps-iᵒ sth k out))] [(fresh (app rator sym body) (== program `(,app ,rator (λ (,sym) ,body))) (cps-iᵒ app `(K-app-rator ,rator ,sym ,body ,k) out))])) (define (apply-cps-iᵒ k-struct code out) (conde [(== k-struct 'K-id) (== code out)] [(fresh (x k) (== k-struct `(K-λ-final ,x ,k)) (apply-cps-iᵒ k `(λ (,x) ,code) out))] [(fresh (rator sym body k) (== k-struct `(K-app-rator ,rator ,sym ,body ,k)) (cps-iᵒ rator `(K-app-body ,code ,sym ,body ,k) out))] [(fresh (rapp sym body k) (== k-struct `(K-app-body ,rapp ,sym ,body ,k)) (cps-iᵒ body `(K-app-final ,rapp ,code ,sym ,k) out))] [(fresh (rapp rrator sym k subst-res) (== k-struct `(K-app-final ,rapp ,rrator ,sym ,k)) (substᵒ sym `(,rapp ,rrator) code subst-res) (apply-cps-iᵒ k subst-res out))])) #!eof (load "the-cpser.ss") (run 40 (res) (decent-cpsedᵒ res)) (define bound-λs (map car (run 400 (res) (decent-λᵒ res '() res)))) (map (λ (p) (cps1 p id)) bound-λs) (trace decent-λ) (decent-λ '((λ (x) (λ (y) x)) (λ (z) z)) '()) (cps1 '(λ (x) (λ (y) x)) id) (run 40 (res) (cps-iᵒ res 'K-id 'x)) (run* (out) (cps-iᵒ '(p (λ (x k) (k z)) (λ (g0) (g0 q (λ (g1) g1)))) 'K-id out)) (run 1 (out) (cps-iᵒ '(p (λ (x k) (k z)) (λ (g0) (g0 q (λ (g1) g1)))) out '(((p (λ (x) z)) q)))) (cps-i '(λ (x k) (k x)) (λ (x) x)) (cps-i '(p (λ (x k) (k z)) (λ (g4) (g4 q (λ (g5) g5)))) (λ (x) x)) (cps-i-defunc '(p (λ (x k) (k z)) (λ (g4) (g4 q (λ (g5) g5)))) 'K-id) (run* (q) (substᵒ 'x 'y '(x y z) q)) (run 1 (out) (cps-iᵒ '(p (λ (x k) (k z)) (λ (g4) (g4 q (λ (g5) g5)))) 'K-id out)) (run 10 (out) (cps-iᵒ out 'K-id '(λ (x) x))) (run* (out) (cps-iᵒ '(λ (x k) (k x)) 'K-id out)) (run* (out) (cps-iᵒ '(p q (λ (x) x)) 'K-id out)) (run* (out) (cps-iᵒ '(p (λ (x k) (k z)) (λ (g0) (g0 q (λ (g1) g1)))) 'K-id out)) (cps1 `((p (λ (x) z)) q) (λ (x) x)) (define-syntax display-expr (syntax-rules () [(_ expr) (begin (display expr) (display "\n") expr)]))
true
a1310424c3b6a67389effd8e6dcbbfa8dfdfdaaf
b43e36967e36167adcb4cc94f2f8adfb7281dbf1
/sicp/ch3/exercises/3.4.scm
353e00a83d6a69eb3f9b4f0b41aa5ba7fc2f15d8
[]
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,273
scm
3.4.scm
(define (make-account init-balance init-password) (define password init-password) (define balance init-balance) (define wrong-tries 0) (define (withdraw pass amount) (if (eq? pass password) (begin (set! wrong-tries 0) (if (>= balance amount) (begin (set! balance (- balance amount)) balance) "Insufficient funds")) (begin (set! wrong-tries (+ wrong-tries 1)) (if (>= wrong-tries 7) "call-the-cops" "Incorrect password")))) (define (deposit pass amount) (if (eq? pass password) (begin (set! balance (+ balance amount)) balance) (begin (set! wrong-tries (+ wrong-tries 1)) (if (>= wrong-tries 7) "call-the-cops" "Incorrect password")))) (define (dispatch m1 m2) (cond ((eq? m2 'withdraw) (lambda (amount) (withdraw m1 amount))) ((eq? m2 'deposit) (lambda (amount) (deposit m1 amount))) (else (error "Unknown message received" m2)))) dispatch) (define acc (make-account 100 'password)) ((acc 'password 'withdraw) 10) ((acc 'wrong-password 'withdraw) 10) ((acc 'password 'deposit) 1000) ((acc 'wrong-password 'deposit) 1000)
false
0c031c9ce0c7603aac72a70030407d28114b451f
757b4590bf0dd48a8d6131c1c2247d9c01946233
/transformation-from-direct-mk/2-alt/tests.scm
b6b0d9792fd5f8844dffab5cdc656224052c995c
[]
no_license
localchart/relational-cesk
f9f52872050280f941a471ce2746c536539be08c
c2c7d27bc85bb7ca403c9f6d80d07d7cb00a3a77
refs/heads/master
2020-12-26T00:07:54.263812
2013-07-15T21:45:01
2013-07-15T21:45:01
null
0
0
null
null
null
null
UTF-8
Scheme
false
false
3,599
scm
tests.scm
(load "interp.scm") (define-syntax test-check (syntax-rules () ((_ title tested-expression expected-result) (begin (printf "Testing ~s\n" title) (let* ((expected expected-result) (produced tested-expression)) (or (equal? expected produced) (errorf 'test-check "Failed: ~a~%Expected: ~a~%Computed: ~a~%" 'tested-expression expected produced))))))) (define quinec '((lambda (x) (list x (list (quote quote) x))) (quote (lambda (x) (list x (list (quote quote) x)))))) (define replace* (lambda (al x) (cond [(null? x) '()] [(symbol? x) (cond [(assq x al) => cdr] [else x])] [(pair? x) (cons (replace* al (car x)) (replace* al (cdr x)))] [(boolean? x) x] [(string? x) x] [else (error 'replace* (format "unknown expression type: ~a\n" x))]))) (define replace-respect-quote* (lambda (al x) (cond [(null? x) '()] [(symbol? x) (cond [(assq x al) => cdr] [else x])] [(pair? x) (if (eq? (car x) 'quote) x (cons (replace-respect-quote* al (car x)) (replace-respect-quote* al (cdr x))))] [(boolean? x) x] [(string? x) x] [else (error 'replace-respect-quote* (format "unknown expression type: ~a\n" x))]))) (test-check "var-1" (run* (q) (fresh (val store) (eval-expo 'y '((y . 5)) '((5 . (closure z z ()))) val store) (== `(,val ,store) q))) '(((closure z z ()) ((5 closure z z ()))))) (test-check "lambda-1" (run* (q) (fresh (val store) (eval-expo '(lambda (x) x) '() '() val store) (== `(,val ,store) q))) '(((closure x x ()) ()))) (test-check "lambda-2" (run* (q) (fresh (val store) (eval-expo '(lambda (x) (lambda (y) (x y))) '() '() val store) (== `(,val ,store) q))) '(((closure x (lambda (y) (x y)) ()) ()))) (test-check "quote-1" (run* (q) (fresh (val store) (eval-expo '(quote (lambda (x) x)) '() '() val store) (== `(,val ,store) q))) '(((lambda (x) x) ()))) (test-check "app-1" (run* (q) (fresh (val store) (eval-expo '((lambda (x) x) (lambda (y) y)) '() '() val store) (== `(,val ,store) q))) '((((closure y y ()) ((_.0 closure y y ()))) (=/= ((_.0 ())))))) (test-check "extend-3" (run* (q) (fresh (val store) (eval-expo '((lambda (quote) (quote (lambda (x) x))) (lambda (y) y)) '() '() val store) (== `(,val ,store) q))) '((((closure x x ((quote . _.0))) ((_.1 closure x x ((quote . _.0))) (_.0 closure y y ()))) (=/= ((_.0 ())) ((_.1 (()))) ((_.1 ((_.0 closure y y ())))) ((_.1 closure)) ((_.1 y)) ((_.1 (_.0 closure y y ()))) ((_.1 (closure y y ()))) ((_.1 (y ()))) ((_.1 (y y ()))) ((_.1 ()))) (absento (_.1 _.0))))) (test-check "quinec" (run* (q) (fresh (val store) (eval-expo quinec '() '() val store) (== `(,val ,store) q))) '(((((lambda (x) (list x (list 'quote x))) '(lambda (x) (list x (list 'quote x)))) ((_.0 lambda (x) (list x (list 'quote x))))) (=/= ((_.0 ())))))) (test-check "intro-2" ;;; appears to diverge, due to lookupo (run 1 (q) (fresh (val store) (eval-expo val '() '() val store) (== `(,val ,store) q))) '(((((lambda (_.0) (list _.0 (list 'quote _.0))) '(lambda (_.0) (list _.0 (list 'quote _.0)))) ((_.1 lambda (_.0) (list _.0 (list 'quote _.0))))) (=/= ((_.0 closure)) ((_.0 list)) ((_.0 quote)) ((_.1 ()))) (sym _.0))) )
true
ef0047bf7ed69510b65cf2de88014d7d2d771b27
3508dcd12d0d69fec4d30c50334f8deb24f376eb
/v8/src/compiler/machines/i386/insmac.scm
b047187a12c4fea8aa566fb18e6eb8e1b5870167
[]
no_license
barak/mit-scheme
be625081e92c2c74590f6b5502f5ae6bc95aa492
56e1a12439628e4424b8c3ce2a3118449db509ab
refs/heads/master
2023-01-24T11:03:23.447076
2022-09-11T06:10:46
2022-09-11T06:10:46
12,487,054
12
1
null
null
null
null
UTF-8
Scheme
false
false
5,721
scm
insmac.scm
#| -*-Scheme-*- $Vax-Header: insmac.scm,v 1.12 89/05/17 20:29:15 GMT jinx Exp $ Copyright (c) 1992, 1999 Massachusetts Institute of Technology This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |# ;;;; Intel 386 Instruction Set Macros (declare (usual-integrations)) ;;;; Effective addressing (define ea-database-name 'EA-DATABASE) (syntax-table-define assembler-syntax-table 'DEFINE-EA-DATABASE (macro rules `(DEFINE ,ea-database-name ,(compile-database rules (lambda (pattern actions) (let ((keyword (car pattern)) (categories (car actions)) (mode (cadr actions)) (register (caddr actions)) (tail (cdddr actions))) (declare (integrate keyword value)) `(MAKE-EFFECTIVE-ADDRESS ',keyword ',categories ,(integer-syntaxer mode 'UNSIGNED 2) ,(integer-syntaxer register 'UNSIGNED 3) ,(process-tail tail false)))))))) (define (process-tail tail early?) (if (null? tail) `() (process-fields tail early?))) ;; This one is necessary to distinguish between r/mW mW, etc. (syntax-table-define assembler-syntax-table 'DEFINE-EA-TRANSFORMER (macro (name #!optional restriction) (if (default-object? restriction) `(define (,name expression) (let ((match-result (pattern-lookup ,ea-database-name expression))) (and match-result (match-result)))) `(define (,name expression) (let ((match-result (pattern-lookup ,ea-database-name expression))) (and match-result (let ((ea (match-result))) (and (memq ',restriction (ea/categories ea)) ea)))))))) ;; *** We can't really handle switching these right now. *** (define-integrable *ADDRESS-SIZE* 32) (define-integrable *OPERAND-SIZE* 32) (define (parse-instruction opcode tail early?) (process-fields (cons opcode tail) early?)) (define (process-fields fields early?) (if (and (null? (cdr fields)) (eq? (caar fields) 'VARIABLE-WIDTH)) (expand-variable-width (car fields) early?) (expand-fields fields early? (lambda (code size) (if (not (zero? (remainder size 8))) (error "process-fields: bad syllable size" size)) code)))) (define (expand-variable-width field early?) (let ((binding (cadr field)) (clauses (cddr field))) `(LIST ,(variable-width-expression-syntaxer (car binding) ; name (cadr binding) ; expression (map (lambda (clause) (expand-fields (cdr clause) early? (lambda (code size) (if (not (zero? (remainder size 8))) (error "expand-variable-width: bad clause size" size)) `(,code ,size ,@(car clause))))) clauses))))) (define (collect-byte components tail receiver) (define (inner components receiver) (if (null? components) (receiver tail 0) (inner (cdr components) (lambda (byte-tail byte-size) (let ((size (caar components)) (expression (cadar components)) (type (if (null? (cddar components)) 'UNSIGNED (caddar components)))) (receiver `(CONS-SYNTAX ,(integer-syntaxer expression type size) ,byte-tail) (+ size byte-size))))))) (inner components receiver)) (define (expand-fields fields early? receiver) (if (null? fields) (receiver ''() 0) (expand-fields (cdr fields) early? (lambda (tail tail-size) (case (caar fields) ;; For opcodes and fixed fields of the instruction ((BYTE) ;; (BYTE (8 #xff)) ;; (BYTE (16 (+ foo #x23) SIGNED)) (collect-byte (cdar fields) tail (lambda (code size) (receiver code (+ size tail-size))))) ((ModR/M) ;; (ModR/M 2 source) = /2 r/m(source) ;; (ModR/M r target) = /r r/m(target) (if early? (error "No early support for ModR/M -- Fix i386/insmac.scm") (let ((field (car fields))) (let ((digit-or-reg (cadr field)) (r/m (caddr field))) (receiver `(CONS-SYNTAX (EA/REGISTER ,r/m) (CONS-SYNTAX ,(integer-syntaxer digit-or-reg 'UNSIGNED 3) (CONS-SYNTAX (EA/MODE ,r/m) (APPEND-SYNTAX! (EA/EXTRA ,r/m) ,tail)))) (+ 8 tail-size)))))) ;; For immediate operands whose size depends on the operand ;; size for the instruction (halfword vs. longword) ((IMMEDIATE) (receiver (let ((field (car fields))) (let ((value (cadr field)) (mode (if (null? (cddr field)) 'OPERAND (caddr field))) (domain (if (or (null? (cddr field)) (null? (cdddr field))) 'SIGNED (cadddr field)))) `(CONS-SYNTAX #| (COERCE-TO-TYPE ,value ,(case mode ((OPERAND) `*OPERAND-SIZE*) ((ADDRESS) `*ADDRESS-SIZE*) (else (error "Unknown IMMEDIATE mode" mode))) ,domain) |# ,(integer-syntaxer value domain (case mode ((OPERAND) *operand-size*) ((ADDRESS) *address-size*) (else (error "Unknown IMMEDIATE mode" mode)))) ,tail))) tail-size)) (else (error "expand-fields: Unknown field kind" (caar fields))))))))
false
306fdfaf54f1a5681786a3223ff92c80918de03b
0768e217ef0b48b149e5c9b87f41d772cd9917f1
/bench/gambit-benchmarks/conform.scm
ea0c704cf943afea507616b59e303589fec2999d
[ "LicenseRef-scancode-unknown-license-reference", "BSD-2-Clause" ]
permissive
fujita-y/ypsilon
e45c897436e333cf1a1009e13bfef72c3fb3cbe9
62e73643a4fe87458ae100e170bf4721d7a6dd16
refs/heads/master
2023-09-05T00:06:06.525714
2023-01-25T03:56:13
2023-01-25T04:02:59
41,003,666
45
7
BSD-2-Clause
2022-06-25T05:44:49
2015-08-19T00:05:35
Scheme
UTF-8
Scheme
false
false
16,733
scm
conform.scm
;;; CONFORM -- Type checker, written by Jim Miller. ;;; Functional and unstable (define (sort-list obj pred) (define (loop l) (if (and (pair? l) (pair? (cdr l))) (split-list l '() '()) l)) (define (split-list l one two) (if (pair? l) (split-list (cdr l) two (cons (car l) one)) (merge (loop one) (loop two)))) (define (merge one two) (cond ((null? one) two) ((pred (car two) (car one)) (cons (car two) (merge (cdr two) one))) (else (cons (car one) (merge (cdr one) two))))) (loop obj)) ;; SET OPERATIONS ; (representation as lists with distinct elements) (define (adjoin element set) (if (memq element set) set (cons element set))) (define (eliminate element set) (cond ((null? set) set) ((eq? element (car set)) (cdr set)) (else (cons (car set) (eliminate element (cdr set)))))) (define (intersect list1 list2) (let loop ((l list1)) (cond ((null? l) '()) ((memq (car l) list2) (cons (car l) (loop (cdr l)))) (else (loop (cdr l)))))) (define (union list1 list2) (if (null? list1) list2 (union (cdr list1) (adjoin (car list1) list2)))) ;; GRAPH NODES (define make-internal-node vector) (define (internal-node-name node) (vector-ref node 0)) (define (internal-node-green-edges node) (vector-ref node 1)) (define (internal-node-red-edges node) (vector-ref node 2)) (define (internal-node-blue-edges node) (vector-ref node 3)) (define (set-internal-node-name! node name) (vector-set! node 0 name)) (define (set-internal-node-green-edges! node edges) (vector-set! node 1 edges)) (define (set-internal-node-red-edges! node edges) (vector-set! node 2 edges)) (define (set-internal-node-blue-edges! node edges) (vector-set! node 3 edges)) (define (make-node name . blue-edges) ; User's constructor (let ((name (if (symbol? name) (symbol->string name) name)) (blue-edges (if (null? blue-edges) 'NOT-A-NODE-YET (car blue-edges)))) (make-internal-node name '() '() blue-edges))) (define (copy-node node) (make-internal-node (name node) '() '() (blue-edges node))) ; Selectors (define name internal-node-name) (define (make-edge-getter selector) (lambda (node) (if (or (none-node? node) (any-node? node)) (fatal-error "Can't get edges from the ANY or NONE nodes") (selector node)))) (define red-edges (make-edge-getter internal-node-red-edges)) (define green-edges (make-edge-getter internal-node-green-edges)) (define blue-edges (make-edge-getter internal-node-blue-edges)) ; Mutators (define (make-edge-setter mutator!) (lambda (node value) (cond ((any-node? node) (fatal-error "Can't set edges from the ANY node")) ((none-node? node) 'OK) (else (mutator! node value))))) (define set-red-edges! (make-edge-setter set-internal-node-red-edges!)) (define set-green-edges! (make-edge-setter set-internal-node-green-edges!)) (define set-blue-edges! (make-edge-setter set-internal-node-blue-edges!)) ;; BLUE EDGES (define make-blue-edge vector) (define (blue-edge-operation edge) (vector-ref edge 0)) (define (blue-edge-arg-node edge) (vector-ref edge 1)) (define (blue-edge-res-node edge) (vector-ref edge 2)) (define (set-blue-edge-operation! edge value) (vector-set! edge 0 value)) (define (set-blue-edge-arg-node! edge value) (vector-set! edge 1 value)) (define (set-blue-edge-res-node! edge value) (vector-set! edge 2 value)) ; Selectors (define operation blue-edge-operation) (define arg-node blue-edge-arg-node) (define res-node blue-edge-res-node) ; Mutators (define set-arg-node! set-blue-edge-arg-node!) (define set-res-node! set-blue-edge-res-node!) ; Higher level operations on blue edges (define (lookup-op op node) (let loop ((edges (blue-edges node))) (cond ((null? edges) '()) ((eq? op (operation (car edges))) (car edges)) (else (loop (cdr edges)))))) (define (has-op? op node) (not (null? (lookup-op op node)))) ;; GRAPHS (define make-internal-graph vector) (define (internal-graph-nodes graph) (vector-ref graph 0)) (define (internal-graph-already-met graph) (vector-ref graph 1)) (define (internal-graph-already-joined graph) (vector-ref graph 2)) (define (set-internal-graph-nodes! graph nodes) (vector-set! graph 0 nodes)) ; Constructor (define (make-graph . nodes) (make-internal-graph nodes (make-empty-table) (make-empty-table))) ; Selectors (define graph-nodes internal-graph-nodes) (define already-met internal-graph-already-met) (define already-joined internal-graph-already-joined) ; Higher level functions on graphs (define (add-graph-nodes! graph nodes) (set-internal-graph-nodes! graph (cons nodes (graph-nodes graph)))) (define (copy-graph g) (define (copy-list l) (vector->list (list->vector l))) (make-internal-graph (copy-list (graph-nodes g)) (already-met g) (already-joined g))) (define (clean-graph g) (define (clean-node node) (if (not (or (any-node? node) (none-node? node))) (begin (set-green-edges! node '()) (set-red-edges! node '())))) (for-each clean-node (graph-nodes g)) g) (define (canonicalize-graph graph classes) (define (fix node) (define (fix-set object selector mutator) (mutator object (map (lambda (node) (find-canonical-representative node classes)) (selector object)))) (if (not (or (none-node? node) (any-node? node))) (begin (fix-set node green-edges set-green-edges!) (fix-set node red-edges set-red-edges!) (for-each (lambda (blue-edge) (set-arg-node! blue-edge (find-canonical-representative (arg-node blue-edge) classes)) (set-res-node! blue-edge (find-canonical-representative (res-node blue-edge) classes))) (blue-edges node)))) node) (define (fix-table table) (define (canonical? node) (eq? node (find-canonical-representative node classes))) (define (filter-and-fix predicate-fn update-fn list) (let loop ((list list)) (cond ((null? list) '()) ((predicate-fn (car list)) (cons (update-fn (car list)) (loop (cdr list)))) (else (loop (cdr list)))))) (define (fix-line line) (filter-and-fix (lambda (entry) (canonical? (car entry))) (lambda (entry) (cons (car entry) (find-canonical-representative (cdr entry) classes))) line)) (if (null? table) '() (cons (car table) (filter-and-fix (lambda (entry) (canonical? (car entry))) (lambda (entry) (cons (car entry) (fix-line (cdr entry)))) (cdr table))))) (make-internal-graph (map (lambda (class) (fix (car class))) classes) (fix-table (already-met graph)) (fix-table (already-joined graph)))) ;; USEFUL NODES (define none-node (make-node 'none #t)) (define (none-node? node) (eq? node none-node)) (define any-node (make-node 'any '())) (define (any-node? node) (eq? node any-node)) ;; COLORED EDGE TESTS (define (green-edge? from-node to-node) (cond ((any-node? from-node) #f) ((none-node? from-node) #t) ((memq to-node (green-edges from-node)) #t) (else #f))) (define (red-edge? from-node to-node) (cond ((any-node? from-node) #f) ((none-node? from-node) #t) ((memq to-node (red-edges from-node)) #t) (else #f))) ;; SIGNATURE ; Return signature (i.e. <arg, res>) given an operation and a node (define sig (let ((none-comma-any (cons none-node any-node))) (lambda (op node) ; Returns (arg, res) (let ((the-edge (lookup-op op node))) (if (not (null? the-edge)) (cons (arg-node the-edge) (res-node the-edge)) none-comma-any))))) ; Selectors from signature (define (arg pair) (car pair)) (define (res pair) (cdr pair)) ;; CONFORMITY (define (conforms? t1 t2) (define nodes-with-red-edges-out '()) (define (add-red-edge! from-node to-node) (set-red-edges! from-node (adjoin to-node (red-edges from-node))) (set! nodes-with-red-edges-out (adjoin from-node nodes-with-red-edges-out))) (define (greenify-red-edges! from-node) (set-green-edges! from-node (append (red-edges from-node) (green-edges from-node))) (set-red-edges! from-node '())) (define (delete-red-edges! from-node) (set-red-edges! from-node '())) (define (does-conform t1 t2) (cond ((or (none-node? t1) (any-node? t2)) #t) ((or (any-node? t1) (none-node? t2)) #f) ((green-edge? t1 t2) #t) ((red-edge? t1 t2) #t) (else (add-red-edge! t1 t2) (let loop ((blues (blue-edges t2))) (if (null? blues) #t (let* ((current-edge (car blues)) (phi (operation current-edge))) (and (has-op? phi t1) (does-conform (res (sig phi t1)) (res (sig phi t2))) (does-conform (arg (sig phi t2)) (arg (sig phi t1))) (loop (cdr blues))))))))) (let ((result (does-conform t1 t2))) (for-each (if result greenify-red-edges! delete-red-edges!) nodes-with-red-edges-out) result)) (define (equivalent? a b) (and (conforms? a b) (conforms? b a))) ;; EQUIVALENCE CLASSIFICATION ; Given a list of nodes, return a list of equivalence classes (define (classify nodes) (let node-loop ((classes '()) (nodes nodes)) (if (null? nodes) (map (lambda (class) (sort-list class (lambda (node1 node2) (< (string-length (name node1)) (string-length (name node2)))))) classes) (let ((this-node (car nodes))) (define (add-node classes) (cond ((null? classes) (list (list this-node))) ((equivalent? this-node (caar classes)) (cons (cons this-node (car classes)) (cdr classes))) (else (cons (car classes) (add-node (cdr classes)))))) (node-loop (add-node classes) (cdr nodes)))))) ; Given a node N and a classified set of nodes, ; find the canonical member corresponding to N (define (find-canonical-representative element classification) (let loop ((classes classification)) (cond ((null? classes) (fatal-error "Can't classify" element)) ((memq element (car classes)) (car (car classes))) (else (loop (cdr classes)))))) ; Reduce a graph by taking only one member of each equivalence ; class and canonicalizing all outbound pointers (define (reduce graph) (let ((classes (classify (graph-nodes graph)))) (canonicalize-graph graph classes))) ;; TWO DIMENSIONAL TABLES (define (make-empty-table) (list 'TABLE)) (define (lookup table x y) (let ((one (assq x (cdr table)))) (if one (let ((two (assq y (cdr one)))) (if two (cdr two) #f)) #f))) (define (insert! table x y value) (define (make-singleton-table x y) (list (cons x y))) (let ((one (assq x (cdr table)))) (if one (set-cdr! one (cons (cons y value) (cdr one))) (set-cdr! table (cons (cons x (make-singleton-table y value)) (cdr table)))))) ;; MEET/JOIN ; These update the graph when computing the node for node1*node2 (define (blue-edge-operate arg-fn res-fn graph op sig1 sig2) (make-blue-edge op (arg-fn graph (arg sig1) (arg sig2)) (res-fn graph (res sig1) (res sig2)))) (define (meet graph node1 node2) (cond ((eq? node1 node2) node1) ((or (any-node? node1) (any-node? node2)) any-node) ; canonicalize ((none-node? node1) node2) ((none-node? node2) node1) ((lookup (already-met graph) node1 node2)) ; return it if found ((conforms? node1 node2) node2) ((conforms? node2 node1) node1) (else (let ((result (make-node (string-append "(" (name node1) " ^ " (name node2) ")")))) (add-graph-nodes! graph result) (insert! (already-met graph) node1 node2 result) (set-blue-edges! result (map (lambda (op) (blue-edge-operate join meet graph op (sig op node1) (sig op node2))) (intersect (map operation (blue-edges node1)) (map operation (blue-edges node2))))) result)))) (define (join graph node1 node2) (cond ((eq? node1 node2) node1) ((any-node? node1) node2) ((any-node? node2) node1) ((or (none-node? node1) (none-node? node2)) none-node) ; canonicalize ((lookup (already-joined graph) node1 node2)) ; return it if found ((conforms? node1 node2) node1) ((conforms? node2 node1) node2) (else (let ((result (make-node (string-append "(" (name node1) " v " (name node2) ")")))) (add-graph-nodes! graph result) (insert! (already-joined graph) node1 node2 result) (set-blue-edges! result (map (lambda (op) (blue-edge-operate meet join graph op (sig op node1) (sig op node2))) (union (map operation (blue-edges node1)) (map operation (blue-edges node2))))) result)))) ;; MAKE A LATTICE FROM A GRAPH (define (make-lattice g print?) (define (step g) (let* ((copy (copy-graph g)) (nodes (graph-nodes copy))) (for-each (lambda (first) (for-each (lambda (second) (meet copy first second) (join copy first second)) nodes)) nodes) copy)) (define (loop g count) (if print? (display count)) (let ((lattice (step g))) (if print? (begin (display " -> ") (display (length (graph-nodes lattice))))) (let* ((new-g (reduce lattice)) (new-count (length (graph-nodes new-g)))) (if (= new-count count) (begin (if print? (newline)) new-g) (begin (if print? (begin (display " -> ") (display new-count) (newline))) (loop new-g new-count)))))) (let ((graph (apply make-graph (adjoin any-node (adjoin none-node (graph-nodes (clean-graph g))))))) (loop graph (length (graph-nodes graph))))) ;; DEBUG and TEST (define a '()) (define b '()) (define c '()) (define d '()) (define (setup) (set! a (make-node 'a)) (set! b (make-node 'b)) (set-blue-edges! a (list (make-blue-edge 'phi any-node b))) (set-blue-edges! b (list (make-blue-edge 'phi any-node a) (make-blue-edge 'theta any-node b))) (set! c (make-node "c")) (set! d (make-node "d")) (set-blue-edges! c (list (make-blue-edge 'theta any-node b))) (set-blue-edges! d (list (make-blue-edge 'phi any-node c) (make-blue-edge 'theta any-node d))) '(made a b c d)) (define (test) (setup) (map name (graph-nodes (make-lattice (make-graph a b c d any-node none-node) #f)))) (define (main . args) (run-benchmark "conform" conform-iters (lambda (result) (equal? (map (lambda (s) (list->string (map char-downcase (string->list s)))) result) '("(((b v d) ^ a) v c)" "(c ^ d)" "(b v (a ^ d))" "((a v d) ^ b)" "(b v d)" "(b ^ (a v c))" "(a v (c ^ d))" "((b v d) ^ a)" "(c v (a v d))" "(a v c)" "(d v (b ^ (a v c)))" "(d ^ (a v c))" "((a ^ d) v c)" "((a ^ b) v d)" "(((a v d) ^ b) v (a ^ d))" "(b ^ d)" "(b v (a v d))" "(a ^ c)" "(b ^ (c v d))" "(a ^ b)" "(a v b)" "((a ^ d) ^ b)" "(a ^ d)" "(a v d)" "d" "(c v d)" "a" "b" "c" "any" "none"))) (lambda () (lambda () (test)))))
false
3f01118ffe387fd8d06accaf060931c19c774374
beac83b9c75b88060f4af609498541cf84437fd3
/site/content/centralized-people/ahmed-abdelmeged.ss
4a34345cfb92d25a58be4b2030c68059dade15f2
[]
no_license
nuprl/prl-website
272ce3b9edd5b3ada23798a694f6cb7c6d510776
31a321f629a62f945968c3e4c59d180de0f656f6
refs/heads/master
2021-05-16T02:06:38.847789
2016-09-16T14:41:22
2016-09-16T14:41:22
412,044
1
0
null
null
null
null
UTF-8
Scheme
false
false
179
ss
ahmed-abdelmeged.ss
#lang scheme (provide me) (define me (quote (person "Ahmed Abdelmeged" (group "Students") (homepage "http://www.ccs.neu.edu/home/mohsen/"))))
false
3717a18e05f01f10c5da43a9211d86ecebaf62de
06d73af66d0c8450e2c9cb20757774c61c813ee6
/miu-puzzle.ss
f458f03202d32c5f3cbfb274ddd39376b0ff4bc2
[]
no_license
logicshan/lc-with-redex
ce5dc164abc6550bb431b2a7fa20c98f5c024037
63aa4cbf1f0acf0553c545686ba00a1699f003f8
refs/heads/master
2020-12-29T01:42:06.026750
2014-04-29T05:23:37
2014-04-29T05:23:37
null
0
0
null
null
null
null
UTF-8
Scheme
false
false
643
ss
miu-puzzle.ss
#lang scheme (require redex) ; File miu-puzzle.ss (provide MIU-rules traces) (define-language MIU-language ; Grammar (‹sentence› (‹symbol› ...)) ; ‹sentence› is a sentence of the language. (‹symbol› M I U)) ; ‹symbol› is one of the symbols M, I or U. (define MIU-rules ; Semantics (reduction-relation MIU-language (--> (‹symbol› ... I) (‹symbol› ... I U) "rule 1") (--> (M ‹symbol› ...) (M ‹symbol› ... ‹symbol› ...) "rule 2") (--> (‹symbol›_0 ... I I I ‹symbol›_1 ...) (‹symbol›_0 ... U ‹symbol›_1 ...) "rule 3")))
false
627dcde86dc1d5e47f99554d74dd170ae40f628e
370ebaf71b077579ebfc4d97309ce879f97335f7
/seasonedSchemer/tests.sld
0407a421a655ab513106b497bf1e1c303c261bf1
[]
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
753
sld
tests.sld
(include "testsCh11.sld") (include "testsCh12.sld") (include "testsCh13.sld") (include "testsCh14.sld") (define-library (seasoned-schemer tests all) (export run-tests) (import (scheme base) (scheme write) (srfi 78) (seasoned-schemer tests ch11) (seasoned-schemer tests ch12) (seasoned-schemer tests ch13) (seasoned-schemer tests ch14) (seasoned-schemer tests ch16)) (begin (define run-tests (lambda () (check-reset!) (check-set-mode! 'report-failed) (run-tests-ch11) (run-tests-ch12) (run-tests-ch13) (run-tests-ch14) (run-tests-ch16) (check-report) (check-reset!)))))
false
c008c95f9490db10bb4946bd2eca26c178122dd4
f5083e14d7e451225c8590cc6aabe68fac63ffbd
/cs/01-Programming/cs61a/course/lectures/3.2/prev6.scm
cb7b0b430fd3fa61a2f28fc935a0cbc3219091b8
[]
no_license
Phantas0s/playground
a362653a8feb7acd68a7637334068cde0fe9d32e
c84ec0410a43c84a63dc5093e1c214a0f102edae
refs/heads/master
2022-05-09T06:33:25.625750
2022-04-19T14:57:28
2022-04-19T14:57:28
136,804,123
19
5
null
2021-03-04T14:21:07
2018-06-10T11:46:19
Racket
UTF-8
Scheme
false
false
262
scm
prev6.scm
(define-class (previous) (class-vars (glob 'first-time)) (locals (old 'first-time)) (method (local arg) (let ((result old)) (set! old arg) result) ) (method (global arg) (let ((result glob)) (set! glob arg) result) ) )
false
efe2d890312ba9002c67e094d81cd4b15f99649e
d369542379a3304c109e63641c5e176c360a048f
/brice/Chapter2/exercise-274/division-a.scm
2dea886746e98877c434e71de28e992fa89f5383
[]
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
539
scm
division-a.scm
#lang racket (provide (all-defined-out)) (define (get-record name records) (if (empty? records) #f (let* [ [record (first records)] [record-name (first record)] [record-body (second record)] ] (if (equal? name record-name) record-body (get-record name (rest records)))))) (define (get-salary record) (if (empty? record) #f (let* [ [row (first record)] [type (first row)] [data (second row)]] (if (equal? type 'salary) data (get-salary (rest record))))))
false
597e9dd702932daf9e1c6144b9d507dfe8692a18
0a345b89eae9a12e18e8d30f24d592a724284a59
/plugins/prng/prng.scm
cfdd60831947ba7c053b88643f0d4a7c0aadbb38
[ "0BSD", "MIT" ]
permissive
DeMOSic/bintracker
7b26ecb3b8ad315727bb65f1051206b2dcac7123
bed6356b7d177d969ea3873527a1698a00305acf
refs/heads/master
2023-03-26T19:11:49.396339
2021-03-29T08:51:12
2021-03-29T08:51:12
null
0
0
null
null
null
null
UTF-8
Scheme
false
false
207
scm
prng.scm
(bintracker-plugin id: "prng" version: "0.0.1" author: "utz" license: "MIT" description: "A collection of pseudo-random number generators." body: ((load "plugins/prng/prng-impl.scm") (import prng)))
false
ec187f3c77c021a210031055912f1c0d3e50d340
382770f6aec95f307497cc958d4a5f24439988e6
/projecteuler/095/095.scm
bb8a1cb28f9c43244d3da309e8b0c7118d779c79
[ "Unlicense" ]
permissive
include-yy/awesome-scheme
602a16bed2a1c94acbd4ade90729aecb04a8b656
ebdf3786e54c5654166f841ba0248b3bc72a7c80
refs/heads/master
2023-07-12T19:04:48.879227
2021-08-24T04:31:46
2021-08-24T04:31:46
227,835,211
1
0
null
null
null
null
UTF-8
Scheme
false
false
2,572
scm
095.scm
(define eular-filter (lambda (n) (let-syntax ([v-ref (syntax-rules () [(_ vec i) (vector-ref vec (- i 1))])] [v-set! (syntax-rules () [(_ vec i j) (vector-set! vec (- i 1) j)])]) (let ([vec (make-vector n 1)] [half (quotient n 2)] [prime-ls (list 2)]) (letrec ([add-tail! (let ([ptr prime-ls]) (lambda (new) (set-cdr! ptr (list new)) (set! ptr (cdr ptr))))]) (v-set! vec 1 0) (v-set! vec 4 0) (let f ([i 3]) (cond [(> i half) (let f ([j i]) (cond [(> j n) (list->vector prime-ls)] [(not (zero? (v-ref vec j))) (add-tail! j) (f (+ j 2))] [else (f (+ j 2))]))] [else (let g ([ls prime-ls]) (cond [(null? ls) (when (not (zero? (v-ref vec i))) (add-tail! i) (if (<= (* i i) n) (v-set! vec (* i i) 0))) (f (+ i 1))] [else (let ([now (car ls)]) (cond [(> (* now i) n) (if (not (zero? (v-ref vec i))) (add-tail! i)) (f (+ i 1))] [(zero? (remainder i now)) (v-set! vec (* i now) 0) (if (not (zero? (v-ref vec i))) (add-tail! i)) (f (+ i 1))] [else (v-set! vec (* now i) 0) (g (cdr ls))]))]))]))))))) (define one-bi 1000000) (define prime-vec (eular-filter one-bi)) (define sod (lambda (n) (cond ((= n 1) 0) ((= n 0) 0) (else (let loop ([i 0] [ne n] [sum 1]) (let ([now (vector-ref prime-vec i)]) (cond ((and (<= (* now now) n) (> ne 1)) (cond ((zero? (remainder n now)) (let f ([p (* now now)] [num (/ ne now)]) (cond ((zero? (remainder num now)) (f (* p now) (/ num now))) (else (loop (+ i 1) num (/ (* sum (- p 1)) (- now 1))))))) (else (loop (+ i 1) ne sum)))) (else (if (= ne 1) (- sum n) (- (* (+ ne 1) sum) n)))))))))) (define find-chain (lambda (n) (let f ([ne n] [sum (list n)]) (let ([now (sod ne)]) (cond ((> now one-bi) 0) ((= now n) (length sum)) ((memq now sum) 0) (else (f now (cons now sum)))))))) (let pro ([i 1] [res (cons 1 0)]) (cond ((> i 1000000) res) (else (let ([now (find-chain i)]) (cond ((> now (cdr res)) (pro (+ i 1) (cons i now))) (else (pro (+ i 1) res))))))) #| (time (let pro ...)) 23 collections 5.968750000s elapsed cpu time, including 0.000000000s collecting 5.960049800s elapsed real time, including 0.000956500s collecting 97766920 bytes allocated, including 96822824 bytes reclaimed (14316 . 28) |#
false