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 |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
b44fbe93cb85c03faea17c50c6bb86a45f692429
|
74d2f4ec77852839450ab8563971a5e0f615c019
|
/chapter_03/chapter_3_3_1/exercise_3_13.scm
|
a379e4bf62178c3827654f1060f0124579491072
|
[] |
no_license
|
wangoasis/sicp
|
b56960a0c3202ce987f176507b1043ed632ed6b3
|
07eaf8d46f7b8eae5a46d338a4608d8e993d4568
|
refs/heads/master
| 2021-01-21T13:03:11.520829 | 2016-04-22T13:52:15 | 2016-04-22T13:52:15 | 53,835,426 | 0 | 0 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 163 |
scm
|
exercise_3_13.scm
|
( define ( make-cycle x )
( set-cdr! ( last-pair x ) x )
x )
( define ( last-pair x )
( if ( null? ( cdr x ) )
x
( last-pair ( cdr x ) ) ) )
| false |
37253f3eb2ea6afba4e278c6361cf812cbd660fb
|
0bc4163b3571382861380e47eef4aa1afc862024
|
/scripts_sdf/demo_parametric_materials.scm
|
74def7a4ea715bd3574fabd04bd27071531bec1b
|
[] |
no_license
|
mjgordon/fluxcadd
|
49f7c633d4430d98cfa0f24485bfc737fac1a321
|
afedf70e8a9b43563bb3fe5fdc2265260f4a981b
|
refs/heads/master
| 2023-07-21T10:19:36.544424 | 2023-07-08T00:19:06 | 2023-07-08T00:19:06 | 84,756,384 | 0 | 0 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 579 |
scm
|
demo_parametric_materials.scm
|
(let* ((material-ground (MaterialDiffuse. (Color. "444455") 0))
(material-cube (MaterialSimplex. (Color. "FF0000") 0.0
(Color. "0000FF") 0.0
0.1)))
(set-camera-position 25.0 37.0 3.0)
(set-camera-target 6.5 8.0 14.1)
(set-sun-position 105.0 205.0 300.0)
(set-scene-sdf (SDFPrimitiveGroundPlane. 0 material-ground))
(set-scene-sdf (SDFBoolUnion. scene-sdf (SDFPrimitiveCube. (Vector3d. 0.0 0.0 20.0) 30.0 material-cube)))
(set-scene-sdf (SDFBoolDifference. scene-sdf (SDFOpSubtract. (SDFPrimitiveSimplex. material-cube 0.1) 0.5)))
)
| false |
bb56ae62db8e0aac7bd189b2929c2941fa1dd8a1
|
ecc64f06b59d01680c312066af53b3e79e1b1f7a
|
/tools/tmisc.scm
|
0f11e707c387167030ab5d926cf0e62e2f811ba1
|
[
"0BSD"
] |
permissive
|
SourceReviver/s7-scheme
|
fd27942e9c16f48d7e7e968f122a0eb64f898e2e
|
a3d4824bac4f85a09710ad26075294a12c34b700
|
refs/heads/master
| 2023-08-18T19:52:49.400284 | 2021-09-26T09:32:15 | 2021-09-26T09:32:15 | 410,752,737 | 0 | 0 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 11,129 |
scm
|
tmisc.scm
|
(set! (*s7* 'heap-size) (* 2 1024000))
;;; -------- for-each and map --------
(define (fe-test size)
(let ((str (make-string size #\a)))
(for-each char-alphabetic? str)
(for-each (lambda (c) (char-alphabetic? c)) str))
(let ((byt (make-byte-vector size 10)))
(for-each abs byt)
(for-each (lambda (b) (abs b)) byt))
(let ((byt (make-int-vector size 10)))
(for-each abs byt)
(for-each (lambda (b) (abs b)) byt))
(let ((byt (make-float-vector size 10)))
(for-each abs byt)
(for-each (lambda (b) (abs b)) byt))
(let ((byt (make-vector size 10)))
(for-each abs byt)
(for-each (lambda (b) (abs b)) byt))
(let ((lst (make-list size 10)))
(for-each abs lst)
(for-each (lambda (b) (abs b)) lst))
(when (defined? 'make-block)
(let ((byt (make-block size 10)))
(for-each abs byt)
(for-each (lambda (b) (abs b)) byt)))
)
(fe-test 3000000)
(define (map-test size)
(let* ((str (make-string size #\a))
(result (apply string (map (lambda (c) #\b) str))))
(unless (string=? result (make-string size #\b))
(format *stderr* "map string failed\n")))
(let* ((str (make-byte-vector size 10))
(result (apply byte-vector (map (lambda (c) 11) str))))
(unless (equal? result (make-byte-vector size 11))
(format *stderr* "map byte-vector failed\n")))
(let* ((str (make-int-vector size 10))
(result (apply int-vector (map (lambda (c) 11) str))))
(unless (equal? result (make-int-vector size 11))
(format *stderr* "map int-vector failed\n")))
(let* ((str (make-float-vector size 10))
(result (apply float-vector (map (lambda (c) 11) str))))
(unless (equal? result (make-float-vector size 11))
(format *stderr* "map float-vector failed\n")))
(let* ((str (make-vector size 10))
(result (apply vector (map (lambda (c) 11) str))))
(unless (equal? result (make-vector size 11))
(format *stderr* "map vector failed\n"))))
(map-test 500000)
(define size 500000)
;;; -------- let-temporarily --------
(define (w1 x)
(let ((y x))
(do ((j 0 (+ j 1)))
((= j 1))
(do ((i 0 (+ i 1)))
((= i size))
(let-temporarily ((y 32))
(unless (= y 32)
(format *stderr* "temp y: ~A~%" y)))
(unless (= y x)
(format *stderr* "y: ~A~%" y))))))
(define-constant (w2)
(let ((x 1))
(let ((y (let-temporarily ((x 32))
(+ x 1))))
(+ x y))))
(define-constant (w3)
(let ((x 1)
(y 2))
(let ((z (let-temporarily ((x 6) (y 7))
(+ x y))))
(+ x y z))))
(define (w4)
(let ((y (let-temporarily (((*s7* 'print-length) 32))
(*s7* 'print-length))))
(+ y 1)))
(define (wtest)
(w1 3)
(unless (= (w2) 34) (format *stderr* "w2 got ~S~%" (w2)))
(unless (= (w3) 16) (format *stderr* "w3 got ~S~%" (w3)))
(do ((i 0 (+ i 1)))
((= i size))
(w2)
(w3)))
;;; -------- implicit/generalized set! --------
(define (fs1)
(let-temporarily (((*s7* 'print-length) 8))
123))
(define (fs2)
(let ((x 32))
(set! ((curlet) 'x) 3)
x))
(define (fs3)
(set! (with-let (curlet) (*s7* 'print-length)) 16)
(*s7* 'print-length))
(define (fs4)
(let ((e (inlet :v (vector 1 2))))
(set! (with-let e (v 0)) 'a)
(e 'v)))
(define (fs5)
(let ((v (vector (inlet 'a 0))))
(set! (v 0 'a) 32)
((v 0) 'a)))
(define (fs6)
(let ((e (inlet 'x (inlet 'b 2))))
(set! (e 'x 'b) 32)
((e 'x) 'b)))
(define (fs7)
(let ((L (list (list 1 2))))
(set! (L 0 0) 3)
L))
(define (fs8)
(let ((H (hash-table 'a (hash-table 'b 2))))
(set! (H 'a 'b) 32)
((H 'a) 'b)))
(define (fs9)
(let ((v (vector 1 2)))
(let-temporarily (((v 1) 32))
(v 1))))
(define fs10
(let ((val 0))
(let ((fs (dilambda (lambda () val) (lambda (v) (set! val v)))))
(lambda ()
(set! (fs) 32)
(fs)))))
(define (tf)
(do ((i 0 (+ i 1)))
((= i 150000))
(fs1)
(fs2)
(fs3)
(fs4)
(fs5)
(fs6)
(fs7)
(fs8)
(fs9)
(fs10)
))
(tf)
;;; -------- => --------
(define-constant (f1)
(cond (-2 => abs)))
(define-constant (x+1 x)
(+ x 1))
(define-constant (f2)
(cond (32 => x+1)))
(define* (x+y x (y 2))
(+ x y))
(define-constant (f3 z)
(cond ((if z 1 3) => x+y)))
(define-constant (f4)
(cond ((random 1) => "asdf")))
(define (xs)
(values 1 2 3))
(define-constant (f5)
(do ((i 0 (+ i 1))) ((xs) => +)))
(define-constant (f6 x)
(case x ((1) 2) (else => abs)))
(define (ftest)
(unless (= (f1) 2) (format *stderr* "f1 got ~S~%" (f1)))
(unless (= (f2) 33) (format *stderr* "f2 got ~S~%" (f2)))
(unless (= (f3 #t) 3) (format *stderr* "(f3 #t) got ~S~%" (f3 #t)))
(unless (= (f3 #f) 5) (format *stderr* "(f3 #f) got ~S~%" (f3 #f)))
(unless (char=? (f4) #\a) (format *stderr* "(f4) got ~S~%" (f4)))
(unless (= (f5) 6) (format *stderr* "(f5) got ~S~%" (f5)))
(unless (= (f6 -2) 2) (format *stderr* "(f6 -2) got ~S~%" (f6 -2)))
(do ((i 0 (+ i 1)))
((= i size))
(f1)
(f2)
(f3 #t)
(f4)
(f5)
(f6 -2)))
(ftest)
(wtest)
;;; -------- multiple values --------
(define (mv1)
(+ (values 1 2 3)))
(define (mv2)
(+ 1 (values 2 3)))
(define (mv3)
(+ (values 1 2) 3))
(define (mv4 x)
(+ x (values x x)))
(define (mv5 x)
(+ (values x x) x))
(define (mv-clo1 x y)
(+ x y))
(define (mv6 x)
(mv-clo1 (values x 1)))
(define (mv-clo2 . args)
(apply + args))
(define (mv7 x)
(mv-clo2 (values x 1)))
(define (mv8)
(+ (values 1 2 3) (values 3 -2 -1)))
(define (mv9)
(+ (abs -1) (values 2 3 4) -4))
(define (mv10)
(+ (values 1 2 3)))
(define (mv11)
(+ (abs -1) (values -1 2 4)))
(define (mv12 x y)
(+ x y (values 2 3 4)))
;;; pair_sym: (mv-clo (values x 1)), h_c_aa: (values x 1), splice_eval_args2 ([i] 1), eval_arg2->apply mv-clo! (loop below is safe_dotimes_step_p
;;; not enough args for mv-clo1?
;;; mv-clo2: closure_s_p -> pair_sym ->h_c_aa etc as above!
;;; perhaps apply_[safe_]closure?
(define (mvtest)
(unless (= (mv1) 6) (format *stderr* "mv1: ~S~%" (mv1)))
(unless (= (mv2) 6) (format *stderr* "mv2: ~S~%" (mv2)))
(unless (= (mv3) 6) (format *stderr* "mv3: ~S~%" (mv3)))
(unless (= (mv4 2) 6) (format *stderr* "(mv4 2): ~S~%" (mv4 2)))
(unless (= (mv5 2) 6) (format *stderr* "(mv5 2): ~S~%" (mv5 2)))
(unless (= (mv6 5) 6) (format *stderr* "(mv6 5): ~S~%" (mv6 5)))
(unless (= (mv7 5) 6) (format *stderr* "(mv7 5): ~S~%" (mv7 5)))
(unless (= (mv8) 6) (format *stderr* "mv8: ~S~%" (mv8)))
(unless (= (mv9) 6) (format *stderr* "mv9: ~S~%" (mv9)))
(unless (= (mv10) 6) (format *stderr* "mv10: ~S~%" (mv10)))
(unless (= (mv11) 6) (format *stderr* "mv11: ~S~%" (mv11)))
(unless (= (mv12 -1 -2) 6) (format *stderr* "(mv12 -1 -2): ~S~%" (mv12 -1 -2)))
(do ((i 0 (+ i 1)))
((= i 50000))
(mv1)
(mv2)
(mv3)
(mv4 i)
(mv5 i)
(mv6 i)
(mv7 i)
(mv8)
(mv9)
(mv10)
(mv11)
(mv12 -2 -1)
))
(mvtest)
(when (> (*s7* 'profile) 0)
(show-profile 200))
;;; -------- typers --------
(let ()
(define (10-or-12? val)
(and (integer? val) ; hmmm -- this is faster than (memv val '(10 12))
(or (= val 10)
(= val 12))))
(define (symbol-or-integer? key)
(or (symbol? key)
(integer? key)))
(define (a? k1 k2) (eq? k1 k2))
(define (a->int key) 0)
(define h0 (make-hash-table 8 #f (cons #t integer?)))
(define h1 (make-hash-table 8 #f (cons #t 10-or-12?)))
(define h2 (make-hash-table 8 #f (cons symbol? integer?)))
(define h3 (make-hash-table 8 #f (cons symbol-or-integer? 10-or-12?)))
(define h4 (make-hash-table 8 (cons a? a->int) (cons symbol? integer?)))
(define h5 (make-hash-table 8 char=? (cons char? integer?)))
(define v0 (make-vector 3 'x symbol?))
(define v1 (make-vector 3 10 10-or-12?))
(define e0 (let ((a 10))
(set! (setter 'a) integer?)
(curlet)))
(define e1 (let ((a 10))
(set! (setter 'a) (lambda (s v)
(if (10-or-12? v)
v
(error 'wrong-type-arg "~S is not 10 or 12?" v))))
(curlet)))
(define (test tests)
(do ((i 0 (+ i 1)))
((= i tests))
(set! (h0 'a) 123)
(set! (h1 'a) 10)
(set! (h2 'a) 123)
(set! (h3 'a) 12)
(set! (h4 'a) 0)
(set! (h5 #\a) 123)
(set! (v0 0) 'a)
(set! (v1 0) 12)
(set! (e0 'a) 12)
(set! (e1 'a) 12)))
(test 100000))
;;; -------- built-ins via #_ --------
(define (u0)
(do ((i 0 (+ i 1)))
((= i 100000) (#_list))
(#_list)))
(unless (null? (u0)) (format *stderr* "u0: ~S~%" (u0)))
(define (u1)
(do ((i 0 (+ i 1)))
((= i 1000000) (#_length "asdfghjklijk"))
(#_length "asdfghjklijk")))
(unless (eqv? (u1) 12) (format *stderr* "u1: ~S~%" (u1)))
(define (u2)
(let ((str "asdfghjklijk"))
(do ((i 0 (+ i 1)))
((= i 100000) (#_char-position #\h str))
(#_char-position #\h str))))
(unless (eqv? (u2) 5) (format *stderr* "u2: ~S~%" (u2)))
(define (u3)
(do ((i 0 (+ i 1)))
((= i 1000000) (#_+ i (* -2 i) i))
(#_+ i (* -2 i) i)))
(unless (eqv? (u3) 0) (format *stderr* "u3: ~S~%" (u3)))
;;; -------- methods --------
(define (m5)
(let ((L (openlet (inlet :length (lambda (str) (+ 2 (#_string-length "asdfghjklijk")))))))
(do ((i 0 (+ i 1)))
((= i 1000000) (length L))
(length L))))
(unless (eqv? (m5) 14) (format *stderr* "m5: ~S~%" (m5)))
(define (m6)
(let ((L (openlet (inlet :length (lambda (str) (+ 2 (#_string-length str)))))))
(do ((i 0 (+ i 1)))
((= i 1000000) (with-let L (length "asdfghjklijk")))
(with-let L
(length "asdfghjklijk")))))
(unless (eqv? (m6) 14) (format *stderr* "m6: ~S~%" (m6)))
(define (m7)
(let ((L (openlet (inlet :+ (lambda (x y) (#_+ x y 1))))))
(do ((i 0 (+ i 1)))
((= i 500000) ((L :+) 2 3))
((L :+) 2 3))))
(unless (eqv? (m7) 6) (format *stderr* "m7: ~S~%" (m7)))
(define (m8)
(let ((L (openlet (inlet :+ (lambda args (apply #_+ 1 args))))))
(do ((i 0 (+ i 1)))
((= i 500000) (with-let L (+ 2 3)))
(with-let L (+ 2 3)))))
(unless (eqv? (m8) 6) (format *stderr* "m8: ~S~%" (m8)))
;;; -------- unlet --------
;;; incrementally set all globals to 42 -- check that unlet exprs return the same results
(when (zero? (*s7* 'profile))
(let* ((syms (symbol-table))
(num-syms (length syms))
(orig-x (*s7* 'print-length)))
(define (unlet-test i)
(with-let (unlet)
(catch #t
(lambda ()
(eval `(define ,(syms i) 42))
(when (procedure? (symbol->value (syms i) (rootlet)))
(with-let (unlet)
(eval `(set! ,(syms i) 42) (rootlet)))))
(lambda (type info)
#f)))
(with-let (unlet)
(do ((k 0 (+ k 1)))
((= k 1000))
(catch #t
(lambda ()
(let ((x (+ k (*s7* 'print-length))))
(unless (eqv? x (+ k orig-x))
(format *stderr* "sym: ~S, x: ~S, orig: ~S~%" (syms i) x (+ k orig-x)))))
(lambda (type info)
(format *stderr* "sym: ~S, error: ~S~%" (syms i) (apply format #f info)))))))
(do ((i 0 (#_+ i 1))) ; "do" is not a procedure (see above) so it's not in danger here
((#_= i num-syms))
(unlet-test i))))
(#_exit) ; we just clobbered exit above
| false |
2b090c8811ff38704075287fafac0eac2bd4529f
|
9686fd1d8c004ec241c14bbbfd8e4dfc06452a9c
|
/modules/stay-alive/player.scm
|
3f4b8baabb5b987278976acad05f9ad1739a763e
|
[] |
no_license
|
mwitmer/StayAlive
|
edd5e5cb55cc698d033eafca1df7bbd379410d80
|
137b15ac06414adaeca0ff01750a779c89d871e0
|
refs/heads/master
| 2021-01-23T03:54:04.289089 | 2012-11-09T17:22:02 | 2012-11-09T17:22:02 | 5,642,903 | 7 | 1 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 7,356 |
scm
|
player.scm
|
(define-module (stay-alive player)
#:use-module (srfi srfi-1)
#:use-module (srfi srfi-2)
#:use-module (stay-alive util)
#:use-module (ice-9 receive)
#:use-module (shelf shelf)
#:use-module (stay-alive ncurses-interface)
#:use-module (stay-alive shared)
#:use-module (stay-alive lang)
#:use-module (stay-alive square)
#:use-module (stay-alive agent)
#:use-module (stay-alive game)
#:export (Player Memory))
(define (player-examine-level agent level)
(level 'describe agent (player-select-square level (agent 'location) "select square")))
(define process-player-command
(lambda (level player command)
(let* ((saved-command (player #:def #f 'saved-command))
(count (player #:def #f 'count))
(can-repeat-command?
(lambda (command)
(case (if (list? command) (car command) command)
((down up left right drop use up-left up-right down-left down-right) #t)
((update-count terminal inventory pick-up quit reset-count) #f))))
(result
(if (list? command)
(case (car command)
((down up left right up-left up-right down-left down-right)
(if (eq? (cadr command) 'long) (move-agent-direction-long level player (car command))))
((update-count)
(let* ((count (player #:def #f 'count))
(new-count (string->number
(if (not count) (cadr command)
(string-append (number->string count) (cadr command))))))
(message (format #f "repeat count: ~a" new-count))
(set! (player 'count) new-count) #f)))
(case command
((down up left right up-left up-right down-left down-right)
(or
(move-agent-direction level player command)
(let ((melee-target (level 'agent-at (make-new-location (player 'location) command))))
(if melee-target
(player 'melee-attack melee-target level)))))
((terminal) (terminal the-game-module))
((reset-count) (if count (begin (message "repeat count reset") (set! (player 'count) #f))) #f)
((unknown) (message "I don't know what that means") #f)
((follow-up-command) (player #:def #f 'follow-up-command))
((wait) #t)
((close-door)
(let ((door-direction (player-select-direction)))
(if (not (eq? door-direction 'none))
(let ((door-location (make-new-location (player 'location) door-direction)))
(if ((level (list 'squares door-location)) #:def #f 'open-door?)
(if (level 'contains-agent? door-location)
(begin (message (format #f "~a is in the way!"
(capitalize
((level 'agent-at door-location) 'describe)))) #f)
(begin
(message "You shut the door.")
(level 'set-square!
(car door-location)
(cadr door-location)
(instance ClosedDoor))
(level 'remember (car door-location) (cadr door-location))
#t))
(begin
(message "There's no door there!")
#f)))
(begin (message "never mind") #f))))
((save) (set! (player 'status) 'saving) #t)
((throw) (player 'throw level))
((look) (player-examine-level player level) #f)
((down-stairs) ((level `(squares (,(player 'row) ,(player 'col)))) 'go-down player level))
((up-stairs) ((level `(squares (,(player 'row) ,(player 'col)))) 'go-up player level))
((pick-up) (player 'pick-up level))
((drop) (player 'drop level))
((use) (player 'use-something level))
((inventory)
(display-items (player 'items) "inventory:" "inventory empty" player-confirm-callback))
((quit) (set! (player 'status) 'quitting) #t)))))
(if (and count (can-repeat-command? command))
(if saved-command
(if (= count 1)
(begin (set! (player 'count) #f)
(set! (player 'saved-command) #f))
(set! (player 'count) (- count 1)))
(set! (player 'saved-command) command)))
result)))
(define-object Memory
(items #f)
(description #f)
(square #f))
(define-object Player
(initialize!
(method (#:optional inventory)
(super 'initialize!)
(for-each (lambda (item) (this 'add-item! item)) inventory)))
(player? #t)
(describe "you")
(describe-definite "you")
(describe-possessive "your")
(name "You")
(can-open-doors? #t)
(throw
(method (level)
(let ((item (player-select-item (this 'items) "throw what?" "nothing to throw"))
(item-in-flight
(lambda (item location finish)
(set! (item 'row) (car location))
(set! (item 'col) (cadr location))
(level 'prepare-for! (level 'get-player))
(refresh-level-view level this)
finish)))
(if item
(and-let*
((target (player-select-square level (this 'location) "choose target")))
(this 'remove-item! item)
(level 'add-item! item)
(clear-message)
(message (format #f "you throw ~a" (item 'describe-short)))
(line-for-each
(this 'location)
target
(lambda (current previous distance)
(let ((agent (level 'agent-at current)))
(cond
((and agent (item 'hit-agent level this agent distance)) (item-in-flight item current #t))
(((level `(squares (,@current))) 'stops-projectiles?) (item-in-flight item previous #t))
((equal? current target) (item-in-flight item current #t))
(else (item-in-flight item current #f)))))))))))
(base-hp (method () (+ 10 (d 1 4))))
(rarity 'never)
(gender 'male)
(describe-long (method ()
(string-append "a "
(if (eq? (this 'gender) 'male)
"dapper little fellow"
"charming little lady")
" who seems to have fallen in with the wrong dungeon")))
(use-something (method (level)
(let ((item (player-select-item (this 'items) "use what?" "nothing to use")))
(if item (item 'use level this)))))
(square-interact (method (level location)
(let ((items (level 'items-at location)))
(if (= (length items) 1)
(message ((car items) 'describe-short))
(if (> (length items) 1) (message "Multiple items here"))))))
(drop (method (level)
(let ((item (player-select-item (this 'items) "drop what?" "nothing to drop")))
(if (and item (level 'add-item! item))
(begin
(set! (item 'location) (this 'location))
(this 'remove-item! item level this)
#t)
#f))))
(pick-up (method (level)
(let ((item (player-select-item
(filter
(lambda (item)
(receive (row col)
(location-values (item 'location))
(and (= row (this 'row)) (= col (this 'col))))) (level 'items))
"pick up what?"
"no items here")))
(if (and item (this 'add-item! item))
(begin
(message (format #f "picked up ~a (~a)" (item 'describe-short) (item 'letter)))
(level 'remove-item! item)
#t)
#f))))
(take-turn (method (paths-to-player player level)
(if (this 'interrupted?)
(begin
(set! (this 'count) #f)
(set! (this 'saved-command) #f)))
(let ((command (or (this #:def #f 'saved-command) (get-command))))
(clear-message)
(process-player-command level this command))))
(symbol 'at))
(extend Humanoid (list Player))
| false |
eab1f734964f891f44c707a062d5e56d3e888b3f
|
defeada37d39bca09ef76f66f38683754c0a6aa0
|
/mscorlib/system/missing-field-exception.sls
|
c275bbb5629f5a96b765e374e8c9baba0e4d4cb6
|
[] |
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 | 529 |
sls
|
missing-field-exception.sls
|
(library (system missing-field-exception)
(export new is? missing-field-exception? message)
(import (ironscheme-clr-port))
(define-syntax new
(lambda (e)
(syntax-case e ()
((_ a ...) #'(clr-new System.MissingFieldException a ...)))))
(define (is? a) (clr-is System.MissingFieldException a))
(define (missing-field-exception? a)
(clr-is System.MissingFieldException a))
(define-field-port
message
#f
#f
(property:)
System.MissingFieldException
Message
System.String))
| true |
9923d35fbfcd0967c1ffbf8cad7abda49a7a2ab8
|
defeada37d39bca09ef76f66f38683754c0a6aa0
|
/mscorlib/system/null-reference-exception.sls
|
88c359b155f5574e91a5186335aa97152d84378b
|
[] |
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 | 400 |
sls
|
null-reference-exception.sls
|
(library (system null-reference-exception)
(export new is? null-reference-exception?)
(import (ironscheme-clr-port))
(define-syntax new
(lambda (e)
(syntax-case e ()
((_ a ...) #'(clr-new System.NullReferenceException a ...)))))
(define (is? a) (clr-is System.NullReferenceException a))
(define (null-reference-exception? a)
(clr-is System.NullReferenceException a)))
| true |
675edc579cdd7e0c105b6ff9206ce228aa1546c0
|
2e50e13dddf57917018ab042f3410a4256b02dcf
|
/t/issue/257.scm
|
8872be724baaf2886c776a4f453830f57dabf44c
|
[
"MIT"
] |
permissive
|
koba-e964/picrin
|
c0ca2596b98a96bcad4da9ec77cf52ce04870482
|
0f17caae6c112de763f4e18c0aebaa73a958d4f6
|
refs/heads/master
| 2021-01-22T12:44:29.137052 | 2016-07-10T16:12:36 | 2016-07-10T16:12:36 | 17,021,900 | 0 | 0 |
MIT
| 2019-05-17T03:46:41 | 2014-02-20T13:55:33 |
Scheme
|
UTF-8
|
Scheme
| false | false | 54 |
scm
|
257.scm
|
(import (scheme base)
(picrin test))
(map +)
| false |
f27307abc2287532cd4cedde785d481f22a5130b
|
d51c8c57288cacf9be97d41079acc7c9381ed95a
|
/scsh/test/file-system-tests.scm
|
515693861fa212e3da49280b1083a45ae9e66a0f
|
[] |
no_license
|
yarec/svm
|
f926315fa5906bd7670ef77f60b7ef8083b87860
|
d99fa4d3d8ecee1353b1a6e9245d40b60f98db2d
|
refs/heads/master
| 2020-12-13T08:48:13.540156 | 2020-05-04T06:42:04 | 2020-05-04T06:42:04 | 19,306,837 | 2 | 0 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 16,334 |
scm
|
file-system-tests.scm
|
;;; Tests for the function in section 3.3 of the scsh-manual "File system"
;;; Author: David Frese
; file-type: don't know how to test block-special, char-special
; socket should be tested in section "Networking"!!
; file-device: ??
; file-inode: only tested for overflow
;
; sync-file: Test is not very stable, I guess??
;
; glob: hard work ??
; temp-file-iterate: could it be ignored?? create-temp-file uses it anyway??
; temp-file-channel: ??
(define create-temp-dir
(let ((temp-dir "/tmp/scsh-test/"))
(lambda ()
(if (file-not-exists? temp-dir)
(create-directory temp-dir))
temp-dir)))
(define (file-perms fname/fd/port)
(bitwise-and (file-mode fname/fd/port)
#o777))
(define (mask fixnum)
(bitwise-and fixnum
(bitwise-not (umask))))
(define (create-file fname)
(close-output-port (open-output-file fname)))
(define (open/create-file fname flags)
(if (file-not-exists? fname)
(create-file fname))
(open-file fname flags))
(define (symbol-append symbol string)
(string->symbol (string-append
(symbol->string symbol)
string)))
;; --- Create-Directory ---
(add-test! 'create-directory-1 'file-system
(lambda (name)
(with-cwd (create-temp-dir)
(create-directory name)
(let ((result (file-directory? name)))
(delete-filesys-object name)
result)))
"dir")
(add-test! 'create-directory-2 'file-system
(lambda (name perms)
(with-cwd (create-temp-dir)
(create-directory name perms)
(let ((result (and (file-directory? name)
(= (file-perms name)
(mask perms)))))
(delete-filesys-object name)
result)))
"dir" #o700)
;; --- Create FIFO ---
(add-test! 'create-fifo-1 'file-system
(lambda (name)
(with-cwd (create-temp-dir)
(create-fifo name)
(let ((result (eq? (file-type name)
'fifo)))
(delete-filesys-object name)
result)))
"fifo")
(add-test! 'create-fifo-2 'file-system
(lambda (name perms)
(with-cwd (create-temp-dir)
(create-fifo name perms)
(let ((result (and (eq? (file-type name)
'fifo)
(= (file-perms name)
(mask perms)))))
(delete-filesys-object name)
result)))
"fifo" #o700)
;; --- Create-hard-link ---
(add-test! 'create-hard-link 'file-system
(lambda (fname linkname)
(with-cwd (create-temp-dir)
(close-output-port (open-output-file fname))
(create-hard-link fname linkname)
(let ((result (file-exists? linkname)))
(delete-filesys-object fname)
(delete-filesys-object linkname)
result)))
"file" "hard-link")
;; --- Create-symlink ---
(add-test! 'create-symlink 'file-system
(lambda (fname linkname)
(with-cwd (create-temp-dir)
(create-file fname)
(create-symlink fname linkname)
(let ((result (and (file-exists? linkname)
(eq? (file-type linkname #f)
'symlink)
(eq? (file-type linkname #t)
'regular))))
(delete-filesys-object fname)
(delete-filesys-object linkname)
result)))
"file" "symlink")
;; --- Delete-Directory ---
(add-test! 'delete-directory 'file-system
(lambda (name)
(with-cwd (create-temp-dir)
(create-directory name)
(delete-directory name)
(file-not-exists? name)))
"dir")
;; --- Delete-File ---
(add-test! 'delete-file 'file-system
(lambda (name)
(with-cwd (create-temp-dir)
(create-file name)
(delete-file name)
(file-not-exists? name)))
"file")
(add-test! 'delete-filesys-object 'file-system
(lambda (name)
(with-cwd (create-temp-dir)
(create-file name)
(delete-filesys-object name)
(and (file-not-exists? name)
;; even now, it shouldn't signal an error
(delete-filesys-object name))))
"file")
;; --- Read-Symlink ---
(add-test! 'read-symlink 'file-system
(lambda (fname linkname)
(with-cwd (create-temp-dir)
(create-file fname)
(create-symlink fname linkname)
(let ((result (equal? fname
(read-symlink linkname))))
(delete-filesys-object fname)
(delete-filesys-object linkname)
result)))
"file" "symlink")
;; --- Rename-File ---
(add-test! 'rename-file 'file-system
(lambda (name1 name2)
(with-cwd (create-temp-dir)
(create-file name1)
(rename-file name1 name2)
(let ((result (and (file-exists? name2)
(file-not-exists? name1))))
(delete-filesys-object name2)
result)))
"file-1" "file-2")
;; --- Little Abstraction for funcs with fname/fd/port ---
;; uses add-test-multiple!
(define (add-test/fname/fd/port! name before-func func result-func . input-lists)
(let ((name-1 (string->symbol (string-append (symbol->string name)
"/fname")))
(name-2 (string->symbol (string-append (symbol->string name)
"/fd")))
(name-3 (string->symbol (string-append (symbol->string name)
"/port"))))
;; Test as a filename
(apply add-test-multiple!
name-1 'file-system
(lambda (fname . params)
(with-cwd (create-temp-dir)
(let ((port (open/create-file fname (file-options write-only))))
(if before-func (before-func port))
(let ((result (apply func (cons fname params))))
(close port)
(delete-filesys-object fname)
(if result-func
(apply result-func result params)
result)))))
input-lists)
;; Test as a fdes
(apply add-test-multiple!
name-2 'file-system
(lambda (fname . params)
(with-cwd (create-temp-dir)
(let ((port (open/create-file fname (file-options write-only))))
(if before-func (before-func port))
(let ((result (apply func (cons (port->fd port)
params))))
(close port)
(delete-filesys-object fname)
(if result-func
(apply result-func result params)
result)))))
input-lists)
;; Test as a port
(apply add-test-multiple!
name-3 'file-system
(lambda (fname . params)
(with-cwd (create-temp-dir)
(let ((port (open/create-file fname (file-options write-only))))
(if before-func (before-func port))
(let ((result (apply func (cons port params))))
(close port)
(delete-filesys-object fname)
(if result-func
(apply result-func result params)
result)))))
input-lists)
))
;; --- Set-file-mode ---
(add-test/fname/fd/port! 'set-file-mode
#f
(lambda (fname/fd/port mode)
(set-file-mode fname/fd/port mode)
(file-perms fname/fd/port))
=
'("file") '(#o754))
;; --- Set-file-owner ---
(add-test/fname/fd/port! 'set-file-owner
#f
(lambda (fname/fd/port uid)
(set-file-owner fname/fd/port uid)
(file-owner fname/fd/port))
equal?
'("file") (list (user-uid)))
;; --- Set-file-group ---
(add-test/fname/fd/port! 'set-file-group
#f
(lambda (fname/fd/port gid)
(set-file-group fname/fd/port gid)
(file-group fname/fd/port))
equal?
'("file") (list (user-gid)))
;; --- set-file-times ---
(add-test! 'set-file-times-1 'file-system
(lambda (fname time-1)
(with-cwd (create-temp-dir)
(create-file fname)
(set-file-times fname time-1 0)
(let ((result (file-last-access fname)))
(delete-filesys-object fname)
(= result time-1))))
"file" 10000)
(add-test! 'set-file-times-2 'file-system
(lambda (fname time-2)
(with-cwd (create-temp-dir)
(create-file fname)
(set-file-times fname 0 time-2)
(let ((result (file-last-mod fname)))
(delete-filesys-object fname)
(= result time-2))))
"file" 10000)
;; --- sync-file ---
(add-test! 'sync-file 'file-system
(lambda (fname)
(with-cwd (create-temp-dir)
(create-file fname)
(let ((port (open-file fname (file-options write-only))))
(write-string "1" port)
(let ((res-1 (file-size fname)))
(sync-file port)
(let ((res-2 (file-size fname)))
(close port)
(delete-filesys-object fname)
(and (= res-1 0) (> res-2 0)))))))
"file")
;; --- truncate-file ---
(add-test/fname/fd/port! 'truncate-file
(lambda (port)
(write (make-string 100 #\*) port))
(lambda (fname/fd/port len)
(truncate-file fname/fd/port len)
(file-size fname/fd/port))
=
'("file") '(10))
;; --- file-info stuff ---
;; --- file-type ---
(add-test! 'file-type-dir 'file-system
(lambda (fname)
(with-cwd (create-temp-dir)
(create-directory fname)
(let ((result (file-type fname)))
(delete-filesys-object fname)
(equal? result 'directory))))
"dir")
(add-test! 'file-type-fifo 'file-system
(lambda (fname)
(with-cwd (create-temp-dir)
(create-fifo fname)
(let ((result (file-type fname)))
(delete-filesys-object fname)
(equal? result 'fifo))))
"fifo")
(add-test! 'file-type-regular 'file-system
(lambda (fname)
(with-cwd (create-temp-dir)
(create-file fname)
(let ((result (file-type fname)))
(delete-filesys-object fname)
(equal? result 'regular))))
"file")
;(add-test! 'file-type-socket 'file-system
; (lambda (fname)
; (let* ((pathname (string-append (create-temp-dir)
; fname))
; (socket (create-socket protocol-family/unix
; socket-type/raw))
; (addr (unix-address->socket-address
; pathname)))
; (bind-socket socket addr)
; ;; now fname should be a socket
; (let ((result (file-info pathname)))
; (delete-filesys-object pathname)
; (equal? result 'socket))))
; "socket")
;; --- file-inode ---
;; only check for overrun (problem on AFS according to Martin)
(add-test/fname/fd/port! 'file-inode
#f
(lambda (fname/fd/port)
(> 0 (file-inode fname/fd/port)))
'("file"))
;; --- file-mode ---
(add-test/fname/fd/port! 'file-mode
#f
(lambda (fname/fd/port mode)
(set-file-mode fname/fd/port mode)
(bitwise-and (file-mode fname/fd/port)
#o777))
=
'("file") (list #o754))
;; --- file-nlinks ---
(add-test/fname/fd/port! 'file-nlinks
#f
(lambda (fname/fd/port fname1 fname2)
(create-hard-link fname1 fname2)
(let ((result (file-nlinks fname/fd/port)))
(delete-filesys-object fname2)
(= result 2)))
#f
'("file-1") '("file-1") '("file-2"))
;; --- file-owner ---
(add-test/fname/fd/port! 'file-owner
#f
(lambda (fname/fd/port uid)
(set-file-owner fname/fd/port uid)
(file-owner fname/fd/port))
equal?
'("file") (list (user-uid)))
;; --- file-group ---
(add-test/fname/fd/port! 'file-group
#f
(lambda (fname/fd/port gid)
(set-file-group fname/fd/port gid)
(file-group fname/fd/port))
equal?
'("file") (list (user-gid)))
;; --- file-size ---
(add-test/fname/fd/port! 'file-size
(lambda (port)
(write-string "0123456789" port)
(sync-file port))
file-size
(lambda (res) (= res 10))
'("file"))
;; --- file-last-access ---
(add-test/fname/fd/port! 'file-last-access
#f
(lambda (fname/fd/port fname atime)
(set-file-times fname atime 0)
(file-last-access fname/fd/port))
(lambda (restime fname mtime)
(= restime mtime))
'("file") '("file") '(10000))
;; --- file-last-mod ---
(add-test/fname/fd/port! 'file-last-mod
#f
(lambda (fname/fd/port fname mtime)
(set-file-times fname 0 mtime)
(file-last-mod fname/fd/port))
(lambda (restime fname mtime)
(= restime mtime))
'("file") '("file") '(10000))
;; -- file-last-status-change ---
(add-test/fname/fd/port! 'file-last-status-change
#f
(lambda (fname/fd/port)
(let ((before (file-last-status-change
fname/fd/port)))
;; do anything
(set-file-mode fname/fd/port #o777)
(let ((after (file-last-status-change
fname/fd/port)))
(> after before) ;; how much??
)))
'("file"))
;; --- file-not-read/write/exec-able ---
(define (add-file-not-?-able func name perms)
;; normal function
(add-test! (symbol-append name "-normal") 'file-system
(lambda (fname)
(with-cwd (create-temp-dir)
(create-file fname)
(set-file-mode fname perms)
(let ((result (not (func fname))))
(delete-filesys-object fname)
result)))
"file")
;; search-denied
(add-test! (symbol-append name "-search-denied") 'file-system
(lambda (fname dirname)
(with-cwd (create-temp-dir)
(create-directory dirname)
(create-file (string-append dirname fname))
(set-file-mode dirname 0) ;; or 666 ??
(let ((result (func (string-append dirname fname))))
(set-file-mode dirname #o777)
(delete-filesys-object (string-append dirname fname))
(delete-filesys-object dirname)
(equal? result 'search-denied))))
"file" "dir/")
;; permission denied
(add-test! (symbol-append name "-permission") 'file-system
(lambda (fname)
(with-cwd (create-temp-dir)
(create-file fname)
(set-file-mode fname
(bitwise-xor perms #o777))
(let ((result (func fname)))
(delete-filesys-object fname)
(equal? result 'permission))))
"file")
;; not-directory
(add-test! (symbol-append name "-no-directory") 'file-system
(lambda (fname fname2)
(with-cwd (create-temp-dir)
(create-file fname2)
(let ((result (func (string-append
fname2 "/" fname))))
(delete-filesys-object fname2)
(equal? result 'no-directory))))
"file" "file2")
;; nonexistent
(add-test! (symbol-append name "-nonexistent") 'file-system
(lambda (fname)
(with-cwd (create-temp-dir)
(delete-filesys-object fname)
(let ((result (func fname)))
(or (equal? result 'nonexistent)
(and (not result)
(eq? func file-not-writable?))))))
"file"))
(add-file-not-?-able file-not-readable? 'file-not-readable? #o444)
(add-file-not-?-able file-not-writable? 'file-not-writable? #o222)
(add-file-not-?-able file-not-executable? 'file-not-executable? #o111)
;; --- file-(not)-exists? --
(add-test! 'file-not-exists-1? 'file-system
(lambda (fname)
(with-cwd (create-temp-dir)
(delete-filesys-object fname)
(let ((res-1 (file-not-exists? fname)))
(create-file fname)
(let ((res-2 (file-exists? fname)))
(delete-filesys-object fname)
(and res-1 res-2)))))
"file")
(add-test! 'file-not-exists-2? 'file-system
(lambda (fname dirname)
(with-cwd (create-temp-dir)
(create-directory dirname)
(create-file (string-append dirname fname))
(set-file-mode dirname 0)
(let ((result (file-not-exists? (string-append
dirname fname))))
(set-file-mode dirname #o777)
(delete-filesys-object (string-append dirname fname))
(delete-filesys-object dirname)
(equal? result 'search-denied))))
"file" "dir/")
;; --- directory-files ---
(add-test-multiple! 'directory-files 'file-system
(lambda (fname dotfiles?)
(with-cwd (create-temp-dir)
(create-file fname)
(or (and (string-ref fname 0) (not dotfiles?))
(member fname (directory-files (cwd) dotfiles?)))))
'("file" ".file") '(#t #f))
;; --- create-temp-file ---
(add-test! 'create-temp-file 'file-system
(lambda ()
(let ((temp-dir (create-temp-dir)))
(let ((file-1 (create-temp-file temp-dir))
(file-2 (create-temp-file temp-dir)))
(let ((result (and (not (equal? file-1 file-2))
(file-exists? file-1)
(file-exists? file-2))))
(delete-filesys-object file-1)
(delete-filesys-object file-2)
result)))))
(add-test! 'file-type-symlink 'file-system
(lambda (fname linkname)
(create-file fname)
(create-symlink fname linkname)
(let ((result (file-type linkname #f))
(result-2 (file-type linkname #t)))
(delete-filesys-object linkname)
(delete-filesys-object fname)
(and (equal? result 'symlink)
(equal? result-2 'regular))))
"file" "symlink")
| false |
b5d1958ee465fbe4c9d10488848b0e42d4c608d9
|
665da87f9fefd8678b0635e31df3f3ff28a1d48c
|
/tests/when.scm
|
8d044155775c2a119a638700f0edb1fe34c0a7f8
|
[
"MIT"
] |
permissive
|
justinethier/cyclone
|
eeb782c20a38f916138ac9a988dc53817eb56e79
|
cc24c6be6d2b7cc16d5e0ee91f0823d7a90a3273
|
refs/heads/master
| 2023-08-30T15:30:09.209833 | 2023-08-22T02:11:59 | 2023-08-22T02:11:59 | 31,150,535 | 862 | 64 |
MIT
| 2023-03-04T15:15:37 | 2015-02-22T03:08:21 |
Scheme
|
UTF-8
|
Scheme
| false | false | 3,108 |
scm
|
when.scm
|
(import (scheme base) (scheme write))
;(define-syntax my-when
; (syntax-rules ()
; ((my-when test result1 result2 ...)
; (if test
; (begin result1 result2 ...)))))
(define-syntax my-when2
(syntax-rules ()
((my-when test result1 result2 ...)
(list result2 ...))))
(write
(my-when2 #t 1))
;
; (define my-when2*
; (lambda (expr$28 rename$29 compare$30)
; (car ((lambda (tmp$42)
; (if tmp$42
; tmp$42
; (cons (error "no expansion for" expr$28) #f)))
; ((lambda (v.1$36)
; (if (pair? v.1$36)
; ((lambda (v.2$37)
; ((lambda (test)
; ((lambda (v.3$38)
; (if (pair? v.3$38)
; ((lambda (v.4$39)
; ((lambda (result1)
; ((lambda (v.5$40)
; (if (list? v.5$40)
; ((lambda (result2)
; (cons (cons-source
; (rename$29 'list)
; (cons-source test '() '(test))
; '(list test))
; #f))
; v.5$40)
; #f))
; (cdr v.3$38)))
; v.4$39))
; (car v.3$38))
; #f))
; (cdr v.1$36)))
; v.2$37))
; (car v.1$36))
; #f))
; (cdr expr$28))))))
;; TODO: seems broken
;(define-syntax my-when4
; (syntax-rules ()
; ((my-when test result1 result2 ...)
; (let-syntax
; ((second
; (syntax-rules ()
; ((second a b c)
; b))))
; (second 33 44 55)))))
;(write
; (my-when4 't 1 2 3))
;; The symbol?? macro from oleg:
;; http://okmij.org/ftp/Scheme/macros.html#macro-symbol-p
(define-syntax symbol??
(syntax-rules ()
((symbol?? (x . y) kt kf) kf) ; It's a pair, not a symbol
((symbol?? #(x ...) kt kf) kf) ; It's a vector, not a symbol
((symbol?? maybe-symbol kt kf)
(let-syntax
((test
(syntax-rules ()
((test maybe-symbol t f) t)
((test x t f) f))))
(test abracadabra kt kf)))))
(write (symbol?? a #t #f))
(write (symbol?? "a" #t #f))
(write
(let-syntax
((second
(syntax-rules ()
((second a b c)
b))))
(second 33 44 55)))
(write
(my-when2
't
1
(let-syntax
((my-when3
(syntax-rules ()
((my-when3 test result1 result2 ...)
(list result2 ...)))))
(my-when3 33 44 55))
2
3))
;(write
; (my-when2 '(my-when2 't 1 2 3) (lambda (a) a) (lambda X #f)))
;(write
; (my-when2 '(my-when2 "testing" 1) (lambda (a) a) (lambda X #f)))
| true |
8d5e923062bee5c03d1f8e234e6101d453ebb2ad
|
4b2aeafb5610b008009b9f4037d42c6e98f8ea73
|
/23.2/set.scm
|
d699aad059c943d9d9ba9745cfdfadfdebafe94c
|
[] |
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 | 1,256 |
scm
|
set.scm
|
(define-record-type :set
(make-set head tail)
set?
(head set-head set-set-head!)
(tail set-tail set-set-tail!))
(define-record-type :set-member
(make-set-member datum representative next)
set-member?
(datum set-member-datum)
(representative set-member-representative set-set-member-representative!)
(next set-member-next set-set-member-next!))
(define (set-for-each proc set)
(let iter ((member (set-head set)))
(if member
(begin
(proc member)
(iter (set-member-next member))))))
(define (set-map proc set)
(let iter ((member (set-head set)))
;;; (debug (if member (set-member-datum member)))
(if (not member)
'()
(cons (proc member) (iter (set-member-next member))))))
(define (make-set/datum datum)
(let* ((member (make-set-member datum #f #f))
(set (make-set member member)))
(set-set-member-representative! member member)
set))
(define (set-union! x y)
(let ((representative (set-member-representative (set-head y))))
(set-for-each
(lambda (member)
(set-set-member-representative! member representative))
x))
(set-set-member-next! (set-tail y) (set-head x))
(set-set-tail! y (set-tail x))
(set-set-head! x (set-head y)))
| false |
c8e8e5d69edc1938636e144e289c498a6421b22b
|
220acd342ded87198721d0e793c83be4711f7311
|
/src/function/r6rs/number.scm
|
17b51300fb29ccd4711ff126bd19e4457b2f698c
|
[
"MIT"
] |
permissive
|
yoo2001818/r6rs
|
65c4f0bc33bce2ab234d7d91bb1c807e289cad49
|
11dd18e451f7ccde6fbe31da7eac1825e3e9a439
|
refs/heads/master
| 2020-04-09T22:56:29.218850 | 2016-08-26T15:32:17 | 2016-08-26T15:32:17 | 61,253,960 | 4 | 0 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 405 |
scm
|
number.scm
|
; module.exports = `
(define real-valued? real?)
(define rational-valued? rational?)
(define integer-valued? integer?)
(define (div-and-mod x y) (list (div x y) (mod x y)))
(define (div0-and-mod0 x y) (list (div0 x y) (mod0 x y)))
(define-syntax number->string (syntax-rules ()
((_ a) (number->string a 10))
))
(define-syntax string->number (syntax-rules ()
((_ a) (string->number a 10))
))
; `;
| true |
e596429aef0c2928c228cf3cb5d77e2047f0e446
|
c38f6404e86123560ae8c9b38f7de6b66e30f1c4
|
/slatex/dialects/petite-slatex-src.scm
|
37583d34a50afcc90854022d34c6b1d56ca2fadc
|
[
"CC-BY-4.0",
"LicenseRef-scancode-warranty-disclaimer"
] |
permissive
|
webyrd/dissertation-single-spaced
|
efeff4346d0c0e506e671c07bfc54820ed95a307
|
577b8d925b4216a23837547c47fb4d695fcd5a55
|
refs/heads/master
| 2023-08-05T22:58:25.105388 | 2018-12-30T02:11:58 | 2018-12-30T02:11:58 | 26,194,521 | 57 | 4 | null | 2018-08-09T09:21:03 | 2014-11-05T00:00:40 |
TeX
|
UTF-8
|
Scheme
| false | false | 42 |
scm
|
petite-slatex-src.scm
|
(scmxlate-include "chez-slatex-src.scm")
| false |
e9950812bbe67f3020a051144c7b0f4814cd59df
|
fba55a7038615b7967256306ee800f2a055df92f
|
/vvalkyrie/2.3/ex-2-67-70.scm
|
d5820b936ce6fff3d02c30e49af6580ff1a9ab6f
|
[] |
no_license
|
lisp-korea/sicp2014
|
7e8ccc17fc85b64a1c66154b440acd133544c0dc
|
9e60f70cb84ad2ad5987a71aebe1069db288b680
|
refs/heads/master
| 2016-09-07T19:09:28.818346 | 2015-10-17T01:41:13 | 2015-10-17T01:41:13 | 26,661,049 | 2 | 3 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 4,579 |
scm
|
ex-2-67-70.scm
|
; ex 2.67 - 2.70
; expressions
(define (make-leaf symbol weight)
(list 'leaf symbol weight))
(define (leaf? object)
(eq? (car object) 'leaf))
(define (symbol-leaf x) (cadr x))
(define (weight-leaf x) (caddr x))
(define (symbols tree)
(if (leaf? tree)
(list (symbol-leaf tree))
(caddr tree)))
(define (weight tree)
(if (leaf? tree)
(weight-leaf tree)
(cadddr tree)))
(define (make-code-tree left right)
(list left
right
(append (symbols left) (symbols right))
(+ (weight left) (weight right))))
(define (left-branch tree) (car tree))
(define (right-branch tree) (cadr tree))
; decoding
(define (choose-branch bit branch)
(cond ((= bit 0) (left-branch branch))
((= bit 1) (right-branch branch))
(else (error "bad bit -- CHOOSE-BRANCH" bit))))
(define (decode bits tree)
(define (decode-1 bits current-branch)
(if (null? bits)
'()
(let ((next-branch
(choose-branch (car bits) current-branch)))
(if (leaf? next-branch)
(cons (symbol-leaf next-branch)
(decode-1 (cdr bits) tree))
(decode-1 (cdr bits) next-branch)))))
(decode-1 bits tree))
; set
(define (adjoin-set x set)
(cond ((null? set) (list x))
((< (weight x) (weight (car set))) (cons x set))
(else (cons (car set)
(adjoin-set x (cdr set))))))
(define (make-leaf-set pairs)
(if (null? pairs)
'()
(let ((pair (car pairs)))
(adjoin-set (make-leaf (car pair)
(cadr pair))
(make-leaf-set (cdr pairs))))))
; ex 2.67
(define sample-tree
(make-code-tree (make-leaf 'A 4)
(make-code-tree
(make-leaf 'B 2)
(make-code-tree (make-leaf 'D 1)
(make-leaf 'C 1)))))
;;=> ((leaf A 4) ((leaf B 2) ((leaf D 1) (leaf C 1) (D C) 2) (B D C) 4) (A B D C) 8)
(define sample-message '(0 1 1 0 0 1 0 1 0 1 1 1 0))
(decode sample-message sample-tree)
;;=> (A D A B B C A)
; ex 2.68
(define (element-of-set? x set)
(cond ((null? set) #f)
((equal? x (car set)) #t)
(else (element-of-set? x (cdr set)))))
(define (is-there? x set)
(if (leaf? set)
(eq? x (symbol-leaf set))
(element-of-set? x (symbols set))))
(define (encode-symbol x tree)
(cond ((is-there? x (left-branch tree))
(if (leaf? (left-branch tree))
(list 0)
(cons 0 (encode-symbol x (left-branch tree)))))
((is-there? x (right-branch tree))
(if (leaf? (right-branch tree))
(list 1)
(cons 1 (encode-symbol x (right-branch tree)))))
(else (error "bad symbol -- ENCODE-SYMBOL" x))))
(define (encode message tree)
(if (null? message)
'()
(append (encode-symbol (car message) tree)
(encode (cdr message) tree))))
(encode '(A D A B B C A) sample-tree)
;;=> (0 1 1 0 0 1 0 1 0 1 1 1 0)
; ex 2.69
(define (successive-merge set)
(if (null? (cdr set))
(car set)
(successive-merge
(adjoin-set ;; <!!>
(make-code-tree (car set) (cadr set))
(cdr (cdr set))))))
(define (generate-huffman-tree pairs)
(successive-merge (make-leaf-set pairs)))
(successive-merge (make-leaf-set '((D 1) (C 1) (A 4) (B 2))))
;;=> ((leaf A 4) ((leaf B 2) ((leaf C 1) (leaf D 1) (D C) 2) (B D C) 4) (A B D C) 8)
; ex 2.70
(define rock-words
'((a 2) (boom 1) (get 2) (job 2) (na 16) (sha 3) (yip 9) (wah 1)))
(define rock-words-tree
(generate-huffman-tree rock-words))
;;=> ((leaf na 16) ((leaf yip 9) (((leaf a 2) ((leaf wah 1) (leaf boom 1) (wah boom) 2) (a wah boom) 4) ((leaf sha 3) ((leaf job 2) (leaf get 2) (job get) 4) (sha job get) 7) (a wah boom sha job get) 11) (yip a wah boom sha job get) 20) (na yip a wah boom sha job get) 36)
(define rock-lyrics
'(get a job
sha na na na na na na na na
get a job
sha na na na na na na na na
wah yip yip yip yip yip yip yip yip yip
sha boom))
(encode rock-lyrics rock-words-tree)
;;=> (1 1 1 1 1 1 1 0 0 1 1 1 1 0 1 1 1 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 0 0 1 1 1 1 0 1 1 1 0 0 0 0 0 0 0 0 0 1 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 1 1 0 1 1 0 1 1)
;; (84 bits)
;; in the case of encoding with fixed-length code,
;; each word requires 3-bit.
;; rock-lyrics has 36 words, so 3 x 36 = 108 bits required minimally.
(decode (encode rock-lyrics rock-words-tree) rock-words-tree)
;;=> (get a job sha na na na na na na na na get a job sha na na na na na na na na wah yip yip yip yip yip yip yip yip yip sha boom)
| false |
cab071f2dafbe679aa1c48e9b2e2b4c6a54f4aa7
|
0e98dc0001054c35654c10b8abf50941bec64e06
|
/src/sasm/arch/x64.sls
|
36588b2c32a0223f1721bf409f20443bc9dcc4b6
|
[] |
no_license
|
ktakashi/sasm
|
1719669da73716d0056d9d808ec28fc1e6bb29fc
|
1f0e67432d89cd6d449b7716f716712a3d37428b
|
refs/heads/master
| 2021-01-22T21:32:34.397596 | 2016-02-01T12:48:39 | 2016-02-01T12:48:39 | 35,038,615 | 6 | 0 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 3,901 |
sls
|
x64.sls
|
;;; -*- mode:scheme; coding: utf-8; -*-
;;;
;;; sasm/arch/x64.sls - X64 assembler
;;;
;;; 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.
;;;
#!r6rs
(library (sasm arch x64)
(export sasm-assemble)
(import (rnrs)
(sasm arch output)
(sasm arch conditions)
(sasm arch x64 framework)
(sasm arch x64 registers)
(sasm arch x64 mnemonics))
;;; Syntax
;; The syntax of assembly is similar with sassy.
;;
;; toplevel ::= section* | implicit-section*
;; section ::= (section "name" code-vector*)
;; implicit-section ::= code-vector*
;; code-vector ::= label | operation
;; label ::= (label "name")
;; operation ::= (mnemonic operand*)
;;
;; TODO macro
(define (sasm-assemble expr)
(define output (make-sasm-output))
(for-each (lambda (e) (sasm-assemble1 output #f e)) expr)
output)
;; output = SASM output
;; section = #f or section, where #f is implicit section (.text)
;; expr = expression
(define (sasm-assemble1 output section expr)
(define (ensure-section section)
(or section
(sasm-output-create-section! output ".text")))
(define (immeidate/register e)
(cond ((pair? e)
(case (car e)
((&) (apply & (cdr e)))
((rel) (apply rel (cdr e)))
(else (assembler-error 'sasm-assemble e
"unknown operand" (car e)))))
((lookup-register e))
(else e)))
(case (car expr)
((section)
(when section
(assembler-error 'sasm-assemble expr "nested section is not allowed"))
(unless (string? (cadr expr))
(assembler-error 'sasm-assemble expr "section name must be string"))
(let ((s (sasm-output-create-section! output (cadr expr))))
(for-each (lambda (e) (sasm-assemble1 output s e)) (cddr expr))))
((label)
(when section
(assembler-error 'sasm-assemble expr "nested label is not allowed"))
(unless (symbol? (cadr expr))
(assembler-error 'sasm-assemble expr "label must be symbol"))
(let ((l (sasm-output-create-label! output (cadr expr))))
(for-each (lambda (e) (sasm-assemble1 output l e)) (cddr expr))))
;; TODO more special case (e.g. macro)
(else
(cond ((lookup-mnemonic (car expr)) =>
(lambda (m)
(let-values (((code label?)
(apply m (map immeidate/register (cdr expr)))))
(when label?
(sasm-output-add-referencing-label! output label? code))
(sasm-section-push-code! (ensure-section section) code))))
(else
(assembler-error 'sasm-assemble1 expr
"unknown mnemonic" (car expr)))))))
)
| false |
3e0341283f137ec015d12a6e746dc0189c03e630
|
f59b3ca0463fed14792de2445de7eaaf66138946
|
/section-4/4_43.scm
|
02b4bfb8926946c83cd35fef170811f6cfa46896
|
[] |
no_license
|
uryu1994/sicp
|
f903db275f6f8c2da0a6c0d9a90c0c1cf8b1e718
|
b14c728bc3351814ff99ace3b8312a651f788e6c
|
refs/heads/master
| 2020-04-12T01:34:28.289074 | 2018-06-26T15:17:06 | 2018-06-26T15:17:06 | 58,478,460 | 0 | 1 | null | 2018-06-20T11:32:33 | 2016-05-10T16:53:00 |
Scheme
|
UTF-8
|
Scheme
| false | false | 1,485 |
scm
|
4_43.scm
|
(load "./amb")
;;
;; Moore: Mary Lorna
;; Downing: Melissa
;; Hall: Rosalind
;; Barnacle: Melissa Gabrielle
;; Packer: Mary
(for-each simple-ambeval
'((define (filter pred lst)
(if (null? lst)
'()
(if (pred (car lst))
(cons (car lst) (filter pred (cdr lst)))
(filter pred (cdr lst)))))
(define (map proc items)
(if (null? items)
'()
(cons (proc (car items))
(map proc (cdr items)))))
(define (yacht-owner)
(let ((moore (cons 'mary 'lorna))
(downing (cons (amb 'lorna 'rosalind 'gabrielle) 'mellisa))
(hall (cons (amb 'lorna 'gabrielle) 'rosalind))
(barnacle (cons 'mellisa 'gabrielle))
(packer (cons (amb 'lorna 'rosalind 'gabrielle) 'mary)))
(let ((father-list (list moore downing hall barnacle packer)))
(require (distinct? (map car father-list)))
(require (eq? (cdr (car (filter (lambda (n) (eq? (car n) 'gabrielle)) father-list)))
(car packer)))
(list (list 'moore moore)
(list 'downing downing)
(list 'hall hall)
(list 'barnacle barnacle)
(list 'packer packer)))))
))
(driver-loop)
(yacht-owner)
;;; Starting a new problem
;;; Amb-Eval value:
((moore (mary . lorna)) (downing (lorna . mellisa)) (hall (gabrielle . rosalind)) (barnacle (mellisa . gabrielle)) (packer (rosalind . mary)))
;;; Amb-Eval input:
try-again
;;; There are no more values of
(yacht-owner)
;; -> lornaの父はdowning
| false |
f2016ea436408ce3e1943dec8c42502b49755c95
|
3b599e0f15d1b7ce3e42789b2e5c6d477b6a572b
|
/Lisp/sicp/complex.ss
|
c13323288311d282f5ca5a23f023927b2798b634
|
[] |
no_license
|
iacxc/MyProjects
|
1b2ccc80fca2c0935e1a91c98a7555b880745297
|
6998c87012273726bb290f5268ba1f8a9fd37381
|
refs/heads/master
| 2021-01-15T15:45:01.742263 | 2018-03-05T10:41:32 | 2018-03-05T10:41:32 | 25,804,036 | 0 | 0 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 542 |
ss
|
complex.ss
|
(load "../common/common.ss")
(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" op) )))
dispatch)
(define c1 (make-from-real-imag 2 3))
(display (c1 'real-part)) (newline)
(display (c1 'magnitude)) (newline)
(display (c1 'angle)) (newline)
(exit)
| false |
50ce75462ded49f90130f3bd38646ce25dab41c6
|
cb8cccd92c0832e056be608063bbec8fff4e4265
|
/chapter1/Exercises/1.12.scm
|
55a680ba7872af82df494658486c55fbff62c796
|
[] |
no_license
|
JoseLGF/SICP
|
6814999c5fb15256401acb9a53bd8aac75054a14
|
43f7a8e6130095e732c6fc883501164a48ab2229
|
refs/heads/main
| 2023-07-21T03:56:35.984943 | 2021-09-08T05:19:38 | 2021-09-08T05:19:38 | null | 0 | 0 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 538 |
scm
|
1.12.scm
|
#lang scheme
; Ex 1.29
(define (even i)
(if (= i 0)
#t
(not (even (- i 1)))))
(define (simpson-coefficient i n)
(cond ((= i n) 1)
((= i 1) 1)
((even i) 4)
(else 2)))
#|
; test
(simpson-coefficient 1 10)
(simpson-coefficient 2 10)
(simpson-coefficient 3 10)
(simpson-coefficient 4 10)
(simpson-coefficient 5 10)
(simpson-coefficient 6 10)
(simpson-coefficient 7 10)
(simpson-coefficient 8 10)
(simpson-coefficient 9 10)
(simpson-coefficient 10 10)
|#
(define (simpson-integral f a b n)
(TODO))
| false |
cd181a85e2fb937cdc50c1db2ff992cae340abc2
|
35d4b26f34243adacc41eadc985f9bd6f0739140
|
/src/testffi.scm
|
1a7d52d57a76294f7b0a6d2f8d9da7844c78e1af
|
[] |
no_license
|
holdenk/wanderinghobos
|
f6234856c69a44dcd984fc114c4a8fe80d4f7ba2
|
506087dda0063ec0dd15c5a2d0419a952ff14bed
|
refs/heads/master
| 2021-01-10T19:03:25.920021 | 2012-07-16T10:24:00 | 2012-07-16T10:24:00 | 5,061,209 | 1 | 0 | null | 2012-07-16T02:23:33 | 2012-07-15T23:59:11 |
Scheme
|
UTF-8
|
Scheme
| false | false | 832 |
scm
|
testffi.scm
|
;; -*- indent-tabs-mode: nil -*- ;;
(declare (uses parse-input simulate heuristic search failsafe mario))
(use sequences vector-lib posix test)
(display "making point")
;;Make a point
(define 1x2 (make-point 1 2))
(test-group "point"
(test 1 (point-x 1x2))
(test 2 (point-y 1x2))
)
;;Make a board
(define test-board (world-board (file->world "tests/contest1.map")))
(define test-cboard
(make-board-fuck (board-width test-board) (board-height test-board) (board->c_board test-board)))
(test-group "board"
(test (board-width test-board) (cboard-width test-cboard))
(test (board-height test-board) (cboard-height test-cboard))
(test "#######. *R## \\.##\\ * #L .\\#######" (cboard-board test-cboard))
(test test-board (c_board->board (cboard-board test-cboard) 6 4))
)
(display "yay")
| false |
e769723ee4c3dbcd64825e0686cc75638110337b
|
defeada37d39bca09ef76f66f38683754c0a6aa0
|
/System.Data/system/data/common/record-cache.sls
|
15d0d1acc78c3c5f58ff20e17e06047f4309bf15
|
[] |
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 | 238 |
sls
|
record-cache.sls
|
(library (system data common record-cache)
(export is? record-cache?)
(import (ironscheme-clr-port))
(define (is? a) (clr-is System.Data.Common.RecordCache a))
(define (record-cache? a) (clr-is System.Data.Common.RecordCache a)))
| false |
9915152984d35f23746538e084dbb6c91c9224f2
|
9c811b91d38d6c2250df1f6612cd115745da031b
|
/reify-copyo-tests.scm
|
60073351151859a348c2e0c590282f963a49db00
|
[
"MIT"
] |
permissive
|
webyrd/copyo
|
1a7ba6226fb08acf9b7fc4544b75fcd404796e14
|
d5bf684cdf30eff8ec637ee79f0de55cd7311289
|
refs/heads/master
| 2021-01-01T19:46:49.185864 | 2014-01-02T03:07:24 | 2014-01-02T03:07:24 | 15,574,496 | 1 | 0 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 15,853 |
scm
|
reify-copyo-tests.scm
|
(load "mk.scm")
(load "test-check.scm")
(test "rv-1"
(let ((x (var 'x))
(y (var 'y)))
(replace-vars `(5 (,x) #t (,y (,x)) ,y)))
'(5 (#(z_0)) #t (#(z_1) (#(z_0))) #(z_1)))
(test "0" (run* (q) (copyo 5 5)) '(_.0))
(test "1" (run* (q) (copyo q q)) '(_.0))
(test "2" (run* (q) (copyo 5 q)) '(5))
(test "a"
(run* (x y) (copyo x y))
'(((_.0 _.1) (copy (_.0 _.1)))))
(test "b"
(run* (x y z)
(copyo x y)
(copyo x z))
;; is there a more succinct way to express the reified constraint?
;; I'm not sure there is.
'(((_.0 _.1 _.2) (copy (_.0 _.1) (_.0 _.2)))))
(test "c"
(run* (x y z a1 d1 a2 d2)
(== `(,a1 . ,d1) y)
(== `(,a2 . ,d2) z)
(copyo x y)
(copyo x z))
;; is there a more succinct way to express the reified constraint?
;; I'm not sure there is.
'(((_.0 (_.1 . _.2) (_.3 . _.4) _.1 _.2 _.3 _.4)
(copy (_.0 (_.1 . _.2)) (_.0 (_.3 . _.4))))))
(test "d-b"
(run* (x y) (copyo x y) (== x 5))
'((5 5)))
(test "d-a"
(run* (x y) (== x 5) (copyo x y))
'((5 5)))
(test "3"
(run* (q)
(copyo q 5)
(copyo q 6))
;; Interesting: in this case, _.0 must remain fresh.
;;
;; Could reify as
;;
;; ((_.0 (copy (_.0 _.1))))
;;
;; old busted answer
;;
;; ((_.0 (copy (_.0 5) (_.0 6))))
'((_.0 (copy (_.0 f.1)))))
(test "4a"
(run* (q)
(fresh (x y)
(copyo q 5)
(== `(,x ,y) q)))
'())
(test "5b"
(run* (q)
(fresh (x y)
(== q `(,x . ,y))
(copyo q `(1 2))
(copyo q `(3 4 5 6 7))))
;; Interesting: in this case, _.0 must remain fresh.
;; _.1 can become a (z0 . z1)
;;
;; Could reify as
;;
;; (((_.0 . _.1) (copy (_.0 _.2) (_.1 (_.3 . _.4)))))
;;
;; old busted answer
;;
;; (((_.0 . _.1) (copy (_.0 1) (_.0 3) (_.1 (2)) (_.1 (4 5 6 7)))))
'(((_.0 . _.1) (copy (_.0 f.2) (_.1 (f.3 . f.4))))))
(test "5a"
(run* (q)
(fresh (x y)
(copyo q `(1 2))
(copyo q `(3 4 5 6 7))
(== q `(,x . ,y))))
'(((_.0 . _.1) (copy (_.0 f.2) (_.1 (f.3 . f.4))))))
(test "6a"
(run* (q)
(fresh (x y)
(copyo q `(1 2))
(copyo q `(3 4 5 6 7))
(== q 5)))
'())
(test "7a"
(run* (q)
(fresh (x y)
(copyo q `(1 2))
(copyo q `(3 4))))
;; Interesting: in this case, _.0 must remain fresh, or can be
;; instantiated to a list of 2 fresh variables.
;;
;; Could reify as
;;
;; ((_.0 (copy (_.0 (_.1 _.2)))))
;;
;; old busted answer:
;;
;; ((_.0 (copy (_.0 (1 2)) (_.0 (3 4)))))
'((_.0 (copy (_.0 (f.1 f.2))))))
(test "8a"
(run* (q)
(fresh (x y z)
(copyo x y)
(copyo y z)
(copyo z x)
(== q `(,x ,y ,z))))
;; old busted answer:
;;
;; (((_.0 _.1 _.2) (copy (_.0 _.1) (_.1 _.2) (_.2 _.0))))
'((_.0 _.0 _.0)))
(test "8-2a"
(run* (q)
(fresh (x y)
(copyo x y)
(copyo y x)
(== q `(,x ,y))))
;; old busted answer:
;;
;; (((_.0 _.1) (copy (_.0 _.1) (_.1 _.0))))
'((_.0 _.0)))
(test "9a" (run* (q) (copyo `(,q) q)) '())
(test "10"
(run* (q) (fresh (x) (copyo `(,x ,x) q)))
'((_.0 _.0)))
(test "11*"
(run* (q) (fresh (x y) (copyo `((,x) (,x)) y) (== q `(,x ,y))))
'(((_.0 ((_.1) (_.1))) (copy (_.0 _.1)))))
(test "11-easier-to-read*"
(run* (q) (fresh (t x y) (== `((,x) (,x)) t) (copyo t y) (== q `(,t ,y))))
'(((((_.0) (_.0)) ((_.1) (_.1))) (copy (_.0 _.1)))))
(test "12"
(run 1 (q) (fresh (x y) (copyo `(lambda (,x) (,y ,x)) q)))
'((lambda (_.0) (_.1 _.0))))
(test "13*"
(run* (q)
(fresh (x y a b)
(== x y)
(copyo `(,x ,y) `(,a ,b))
(== q `(,x ,y ,a ,b))))
'(((_.0 _.0 _.1 _.1) (copy (_.0 _.1)))))
(test "14a*"
(run* (q)
(fresh (x y a b)
(copyo `(,x ,y) `(,a ,b))
(== x y)
(== q `(,x ,y ,a ,b))))
;; old, busted answer:
;; (((_.0 _.0 _.1 _.2) (copy (_.0 _.1) (_.0 _.2))))
'(((_.0 _.0 _.1 _.1) (copy (_.0 _.1)))))
(test "15"
(run* (q)
(fresh (x g g^ t t^)
(copyo `(,t ,t) `(,t ,t^))
(== `(,t ,t^) q)))
'((_.0 _.0)))
(test "17"
(run* (x y) (copyo x y))
'(((_.0 _.1) (copy (_.0 _.1)))))
(test "18a"
(run* (x y z) (=/= y z) (copyo `(,x ,x) `(,y ,z)))
'())
(test "19a"
(run* (x y z t) (== `(,x ,x) t) (=/= y z) (copyo t `(,y ,z)))
'())
(test "20a"
(run* (x y z t) (== `(,x ,x) t) (symbolo y) (numbero z) (copyo t `(,y ,z)))
'())
(test "21a"
(run* (x y z t) (== `(,x ,x) t) (absento y z) (copyo t `(,y ,z)))
'())
(test "22a"
(run* (x y z t) (== `(,x (,x)) t) (absento y z) (copyo t `(,y ,z)))
'())
(test "23a*"
(run* (x y z t) (== `(,x (,x)) t) (copyo t `(,y ,z)))
'(((_.0 _.1 (_.1) (_.0 (_.0))) (copy (_.0 _.1)))))
(test "24a"
(run* (x y z t1 t2) (=/= y z) (== `(,x ,x) t1) (copyo t1 t2) (copyo t2 `(,y ,z)))
'())
(test "25a"
(run* (x y z t1 t2 t3) (=/= y z) (== `(,x ,x) t1) (copyo t1 t2) (copyo t2 t3) (copyo t3 `(,y ,z)))
'())
(test "26a"
(run* (q)
(fresh (x y)
(== q 5)
(copyo q `(1 2))
(copyo q `(3 4))))
'())
(test "26a"
(run* (q)
(fresh (x y z)
(== x 5)
(copyo x y)
(copyo y z)
(copyo z x)
(== q `(,x ,y ,z))))
'((5 5 5)))
(test "27a"
(run* (q)
(fresh (x y z)
(== x 5)
(== y 6)
(copyo x y)
(copyo y z)
(copyo z x)
(== q `(,x ,y ,z))))
'())
(test "28a"
(run* (a b c d)
(copyo a b)
(copyo c d))
'(((_.0 _.1 _.2 _.3) (copy (_.0 _.1) (_.2 _.3)))))
(test "30a"
(run* (q)
(fresh (g g^ t t^)
(== `(,t) g^)
(copyo `((,t) ,t) `(,g^ ,t^))
(== `(,t ,t^) q)))
'((_.0 _.0)))
(test "31a"
(run* (q)
(fresh (g g^ t t^)
(== `(,t) g)
(== g g^)
(== `(,t ,t^) q)
(copyo `(,g ,t) `(,g^ ,t^))))
'((_.0 _.0)))
(test "32a"
(run* (q)
(fresh (g t t^)
(== `(,t) g)
(copyo `(,g ,t) `(,g ,t^))
(== `(,t ,t^) q)))
'((_.0 _.0)))
(test "33a*"
(run* (q)
(fresh (g g^ t t^ t1 t2)
(== g g^)
(== `(-> ,t1 ,t2) t)
(== `((,t1)) g)
(== `(,t ,t^) q)
(copyo `(,g ,t) `(,g^ ,t^))))
'((((-> _.0 _.1) (-> _.0 _.2)) (copy (_.1 _.2)))))
(test "34a"
(run* (q)
(fresh (s t t^)
(== `(,t) s)
(== `(,t ,t^) q)
(copyo `(,s ,t) `(,s ,t^))))
'((_.0 _.0)))
(test "35a*"
(run* (q)
(fresh (x g g^ t t^ t1 t2)
(== g g^)
(== `(-> ,t1 ,t2) t)
(== `((x ,t1)) g)
(== `(,x ,t ,t1 ,t2 ,t^ ,g ,g^) q)
(copyo `(,g ,t) `(,g^ ,t^))))
'(((_.0 (-> _.1 _.2) _.1 _.2 (-> _.1 _.3) ((x _.1)) ((x _.1))) (copy (_.2 _.3)))))
(test "36a"
(run* (q)
(fresh (x y)
(copyo q `(1 2 8))
(copyo q `(3 4 5 6 7))
(== q `(,x . ,y))))
;; Interesting: in this case, _.0 must remain fresh.
;; _.1 can become a (z0 z1 . z2)
;;
;; Could reify as
;;
;; (((_.0 . _.1) (copy (_.0 _.2) (_.1 (_.3 _.4 . _.5)))))
;;
;; old busted answer
;;
;; (((_.0 . _.1) (copy (_.0 1) (_.0 3) (_.1 (2 8)) (_.1 (4 5 6 7)))))
'(((_.0 . _.1) (copy (_.0 f.2) (_.1 (f.3 f.4 . f.5))))))
(test "37a"
(run* (q)
(copyo q `(1 4))
(copyo q `(3 4)))
;; old busted answer:
;;
;; ((_.0 (copy (_.0 (1 4)) (_.0 (3 4)))))
'((_.0 (copy (_.0 (f.1 4))))))
(test "37b"
(run* (q)
(copyo q `(3 4))
(copyo q `(1 4)))
;; old busted answer:
;;
;; ((_.0 (copy (_.0 (1 4)) (_.0 (3 4)))))
'((_.0 (copy (_.0 (f.1 4))))))
(test "38a"
(run* (x y z)
(copyo x `(,y 3 5))
(copyo x `(,z 4 5)))
;; can we do better than this answer?
;; maybe not
;;
;; *** important point ***
;;
;; It is tempting tp produce an answer like:
;;
;; ((((_.0 . _.1) _.2 _.3) (copy (_.0 _.2) (_.0 _.3) (_.1 (_.4 5)))))
;;
;; However, this would force x to be a pair, which isn't right:
;; x can remain a fresh variable, and remain at least as general as
;; either copy of x.
;;
;; Seems like the right-hand-sides need to be ground before
;; using the lgg of those sides is legitimate
'(((_.0 _.1 _.2) (copy (_.0 (_.1 3 5)) (_.0 (_.2 4 5))))))
(test "39a"
(run* (x y)
(copyo x `(,y 3 5))
(copyo x `(,y 4 5)))
;; old busted answer:
;;
;; (((_.0 _.1) (copy (_.0 (_.1 3 5)) (_.0 (_.1 4 5)))))
'(((_.0 _.1) (copy (_.0 (_.1 f.2 5))))))
(test "39b"
(run* (x y)
(copyo x `(,y 4 5))
(copyo x `(,y 3 5)))
;; old busted answer:
;;
;; (((_.0 _.1) (copy (_.0 (_.1 3 5)) (_.0 (_.1 4 5)))))
'(((_.0 _.1) (copy (_.0 (_.1 f.2 5))))))
(test "39-2a"
(run* (x y z)
(copyo x `(,y 3 5 ,z))
(copyo x `(,y 4 5 ,z)))
;; old busted answer:
;;
;; (((_.0 _.1 _.2) (copy (_.0 (_.1 3 5 _.2)) (_.0 (_.1 4 5 _.2)))))
'(((_.0 _.1 _.2) (copy (_.0 (_.1 f.3 5 _.2))))))
(test "39-2b"
(run* (x y z)
(copyo x `(,y 4 5 ,z))
(copyo x `(,y 3 5 ,z)))
;; old busted answer:
;;
;; (((_.0 _.1 _.2) (copy (_.0 (_.1 3 5 _.2)) (_.0 (_.1 4 5 _.2)))))
'(((_.0 _.1 _.2) (copy (_.0 (_.1 f.3 5 _.2))))))
(test "39-3a"
(run* (x y z)
(copyo x `(,y 3 5 ,z))
(copyo x `(,z 4 5 ,y)))
'(((_.0 _.1 _.2) (copy (_.0 (_.1 3 5 _.2)) (_.0 (_.2 4 5 _.1))))))
(test "39-4a"
(run* (x y z)
(== y 7)
(copyo x `(,y 3 5 ,z))
(copyo x `(,z 4 5 ,y)))
'(((_.0 7 _.1) (copy (_.0 (7 3 5 _.1)) (_.0 (_.1 4 5 7))))))
(test "39-5a"
(run* (x y z)
(== y 7)
(== z 8)
(copyo x `(,y 3 5 ,z))
(copyo x `(,z 4 5 ,y)))
'(((_.0 7 8) (copy (_.0 (f.1 f.2 5 f.3))))))
(test "39-5b"
(run* (x y z)
(copyo x `(,y 3 5 ,z))
(copyo x `(,z 4 5 ,y))
(== y 7)
(== z 8))
'(((_.0 7 8) (copy (_.0 (f.1 f.2 5 f.3))))))
(test "39-6a"
(run* (x)
(copyo x `(7 3 5 8))
(copyo x `(8 4 5 7)))
'((_.0 (copy (_.0 (f.1 f.2 5 f.3))))))
(test "40a"
(run* (x)
(copyo x `(3 5))
(copyo x `(4 5)))
;; old busted answer:
;;
;; ((_.0 (copy (_.0 (3 5)) (_.0 (4 5)))))
'((_.0 (copy (_.0 (f.1 5))))))
(test "41a"
(run* (x y)
(copyo x 3)
(copyo x y))
;; *** important point ***
;; can we produce a better answer?
;;
;; maybe not. Can't produce
;;
;; (((_.0 _.1) (copy (_.0 3))))
;;
;; since this would mean that,even if _.0 becomes instantiated to 3,
;; _.1 can be anything, which would be incorrect
'(((_.0 _.1) (copy (_.0 3) (_.0 _.1)))))
(test "42a"
(run* (x y z)
(copyo x `(,y ,z))
(copyo x `(,z ,y)))
;; can we do better with answer?
;;
;; I don't think so
'(((_.0 _.1 _.2) (copy (_.0 (_.1 _.2)) (_.0 (_.2 _.1))))))
(test "43a"
(run* (x y z)
(== 5 y)
(copyo x `(,y ,z))
(copyo x `(,z ,y)))
;; can we do better with answer?
;;
;; I don't think so
'(((_.0 5 _.1) (copy (_.0 (5 _.1)) (_.0 (_.1 5))))))
(test "44a"
(run* (x y z)
(== 5 y)
(== 5 x)
(copyo x `(,y ,z))
(copyo x `(,z ,y)))
'())
(test "44a"
(run* (x a d y z)
(== 5 y)
(== `(,a . ,d) x)
(copyo x `(,y ,z))
(copyo x `(,z ,y)))
'((((_.0 . _.1) _.0 _.1 5 _.2)
(copy (_.0 5) (_.0 _.2) (_.1 (5)) (_.1 (_.2))))))
(test "45a"
(run* (x a d y z)
(== 5 y)
(== `(5 . ,d) x)
(copyo x `(,y ,z))
(copyo x `(,z ,y)))
'((((5 . _.0) _.1 _.0 5 5) (copy (_.0 (5))))))
(test "45b"
(run* (x a d y z)
(== 5 y)
(== `(5 . ,d) x)
(copyo x `(,z ,y))
(copyo x `(,y ,z)))
'((((5 . _.0) _.1 _.0 5 5) (copy (_.0 (5))))))
(test "45c"
(run* (x a d y z)
(== 5 y)
(copyo x `(,z ,y))
(copyo x `(,y ,z))
(== `(5 . ,d) x))
'((((5 . _.0) _.1 _.0 5 5) (copy (_.0 (5))))))
(test "45d"
(run* (x a d y z)
(copyo x `(,z ,y))
(copyo x `(,y ,z))
(== 5 y)
(== `(5 . ,d) x))
'((((5 . _.0) _.1 _.0 5 5) (copy (_.0 (5))))))
(test "46a"
(run* (x a b y z)
(== 5 y)
(== `(,a ,b) x)
(copyo x `(,y ,z))
(copyo x `(,z ,y)))
'((((_.0 _.1) _.0 _.1 5 _.2)
(copy (_.0 5) (_.0 _.2) (_.1 5) (_.1 _.2)))))
(test "47a"
(run* (x a b y z)
(== 5 y)
(== `(5 ,b) x)
(copyo x `(,y ,z))
(copyo x `(,z ,y)))
'((((5 _.0) _.1 _.0 5 5) (copy (_.0 5)))))
(test "48a"
(run* (x a b y z)
(== 5 y)
(== `(,a 5) x)
(copyo x `(,y ,z))
(copyo x `(,z ,y)))
'((((_.0 5) _.0 _.1 5 5) (copy (_.0 5)))))
(test "49a"
(run* (x y z)
(== 5 y)
(== 6 z)
(copyo x `(,y ,z))
(copyo x `(,z ,y)))
'(((_.0 5 6) (copy (_.0 (f.1 f.2))))))
(test "50a"
(run* (x y z)
(== `(5) x)
(copyo x `(,y . ,z))
(copyo x `(,z . ,y)))
'())
(test "51a"
(run* (x a y z)
(== `(,a 5) x)
(copyo x `(,y ,z))
(copyo x `(,z ,y)))
'((((_.0 5) _.0 5 5) (copy (_.0 5)))))
(test "51b"
(run* (x a y z)
(== `(,a 5) x)
(copyo x `(,z ,y))
(copyo x `(,y ,z)))
'((((_.0 5) _.0 5 5) (copy (_.0 5)))))
(test "51c"
(run* (x a y z)
(copyo x `(,z ,y))
(copyo x `(,y ,z))
(== `(,a 5) x))
'((((_.0 5) _.0 5 5) (copy (_.0 5)))))
(test "51d"
(run* (x a y z)
(copyo x `(,y ,z))
(copyo x `(,z ,y))
(== `(,a 5) x))
'((((_.0 5) _.0 5 5) (copy (_.0 5)))))
(test "51e"
(run* (x a y z)
(copyo x `(,y ,z))
(== `(,a 5) x)
(copyo x `(,z ,y)))
'((((_.0 5) _.0 5 5) (copy (_.0 5)))))
(test "52a"
(run* (x y z)
(== `(5 5) x)
(copyo x `(,y ,z))
(copyo x `(,z ,y)))
'(((5 5) 5 5)))
(test "52b"
(run* (x y z)
(copyo x `(,y ,z))
(== `(5 5) x)
(copyo x `(,z ,y)))
'(((5 5) 5 5)))
(test "52c"
(run* (x y z)
(copyo x `(,y ,z))
(copyo x `(,z ,y))
(== `(5 5) x))
'(((5 5) 5 5)))
(test "52d"
(run* (x y z)
(copyo x `(,z ,y))
(copyo x `(,y ,z))
(== `(5 5) x))
'(((5 5) 5 5)))
(test "53a"
(run* (x a y z)
(== `(,a 5) x)
(copyo x `(,y ,z)))
'((((_.0 5) _.0 _.1 5) (copy (_.0 _.1)))))
(test "53b"
(run* (x a y z)
(copyo x `(,y ,z))
(== `(,a 5) x))
'((((_.0 5) _.0 _.1 5) (copy (_.0 _.1)))))
(test "54a"
(run* (b a y z)
(== `(,a 5) b)
(copyo b `(,y ,z)))
'((((_.0 5) _.0 _.1 5) (copy (_.0 _.1)))))
(test "54b"
(run* (b a y z)
(copyo b `(,y ,z))
(== `(,a 5) b))
'((((_.0 5) _.0 _.1 5) (copy (_.0 _.1)))))
(test "55a"
(run* (b y z)
(== `(5 6) b)
(copyo b `(,y ,z)))
'(((5 6) 5 6)))
(test "55b"
(run* (b y z)
(copyo b `(,y ,z))
(== `(5 6) b))
'(((5 6) 5 6)))
(test "56a"
(run* (a y z)
(copyo `(,a 5) `(,y ,z))
(copyo `(,a 5) `(,z ,y)))
'(((_.0 5 5) (copy (_.0 5)))))
(test "56b"
(run* (a y z)
(copyo `(,a 5) `(,z ,y))
(copyo `(,a 5) `(,y ,z)))
'(((_.0 5 5) (copy (_.0 5)))))
(test "57a"
(run* (a y z)
(copyo a y)
(copyo a z)
(copyo 5 a))
'((5 5 5)))
(test "57b"
(run* (a y z)
(copyo a y)
(copyo 5 a)
(copyo a z))
'((5 5 5)))
(test "57c"
(run* (a y z)
(copyo 5 a)
(copyo a y)
(copyo a z))
'((5 5 5)))
(test "58a"
(run* (a y z)
(copyo a y)
(copyo a z)
(== 5 a))
'((5 5 5)))
(test "58b"
(run* (a y z)
(copyo a z)
(copyo a y)
(== 5 a))
'((5 5 5)))
(test "58c"
(run* (a y z)
(== 5 a)
(copyo a z)
(copyo a y))
'((5 5 5)))
(test "59a"
(run* (a x y z)
(copyo `(,a 5) `(,x ,y))
(copyo `(,a 5) `(,y ,z))
(copyo `(,a 5) `(,z ,x)))
'(((_.0 5 5 5) (copy (_.0 5)))))
(test "59b"
(run* (a x y z)
(copyo `(,a 5) `(,x ,y))
(copyo `(,a 5) `(,z ,x))
(copyo `(,a 5) `(,y ,z)))
'(((_.0 5 5 5) (copy (_.0 5)))))
(test "60a"
(run* (x a b c d e f)
(copyo `(,x 5) `(,a ,b))
(copyo `(,x 5) `(,b ,c))
(copyo `(,x 5) `(,c ,d))
(copyo `(,x 5) `(,d ,e))
(copyo `(,x 5) `(,e ,f))
(copyo `(,x 5) `(,f ,a)))
'(((_.0 5 5 5 5 5 5) (copy (_.0 5)))))
(test "61a"
(run* (x a b c d e f)
(copyo `(,x 5) `(,a ,b))
(copyo `(,x 5) `(,b ,c))
(copyo `(,x 5) `(,c ,d))
(copyo `(,x 5) `(,d ,e))
(copyo `(,x 5) `(,e ,f)))
'(((_.0 _.1 5 5 5 5 5) (copy (_.0 5) (_.0 _.1)))))
(test "61b"
(run* (x a b c d e f)
(copyo `(,x 5) `(,e ,f))
(copyo `(,x 5) `(,d ,e))
(copyo `(,x 5) `(,a ,b))
(copyo `(,x 5) `(,b ,c))
(copyo `(,x 5) `(,c ,d)))
'(((_.0 _.1 5 5 5 5 5) (copy (_.0 5) (_.0 _.1)))))
| false |
749350cac05f6fad21dea98178f98fa8cc82dd06
|
660d4aad58a5dd8a304ead443a4f915b0047a579
|
/eval-utils.scm
|
56d981019c4390a3b7b423c1de6b169e02540b96
|
[] |
no_license
|
prophet-on-that/sicp
|
d9642ceebb8e885d85053ceba930282f30100879
|
cdb742646464f21a3c1c27c753d35f20cf0e754d
|
refs/heads/master
| 2021-07-05T12:53:14.263137 | 2020-08-21T08:20:27 | 2020-08-21T08:20:27 | 162,593,828 | 0 | 0 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 219 |
scm
|
eval-utils.scm
|
(define-module (sicp eval-utils))
(define-public (prompt-for-input string)
(newline)
(newline)
(display string)
(newline))
(define-public (tagged-list? p symbol)
(and (pair? p)
(eq? (car p) symbol)))
| false |
958128ae722a7ab5dce05f7c667b868c0cee7a6e
|
26aaec3506b19559a353c3d316eb68f32f29458e
|
/modules/fft/fft.scm
|
df5ccbab138fa062cd47dbd0d1aa2d2159f07dfe
|
[
"BSD-3-Clause"
] |
permissive
|
mdtsandman/lambdanative
|
f5dc42372bc8a37e4229556b55c9b605287270cd
|
584739cb50e7f1c944cb5253966c6d02cd718736
|
refs/heads/master
| 2022-12-18T06:24:29.877728 | 2020-09-20T18:47:22 | 2020-09-20T18:47:22 | 295,607,831 | 1 | 0 |
NOASSERTION
| 2020-09-15T03:48:04 | 2020-09-15T03:48:03 | null |
UTF-8
|
Scheme
| false | false | 5,136 |
scm
|
fft.scm
|
#|
LambdaNative - a cross-platform Scheme framework
Copyright (c) 2009-2014, University of British Columbia
All rights reserved.
Redistribution and use in source and binary forms, with or
without modification, are permitted provided that the
following conditions are met:
* Redistributions of source code must retain the above
copyright notice, this list of conditions and the following
disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials
provided with the distribution.
* Neither the name of the University of British Columbia nor
the names of its contributors may be used to endorse or
promote products derived from this software without specific
prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 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.
|#
;; bindings for The Fastest Fourier Transform in the South (FFTS) library
(include "fft-tests.scm")
(c-declare #<<end-of-c-declare
#include <string.h>
#include "ffts/ffts.h"
int fft_sign(float *data, float *data_out, int n, int sign){
ffts_plan_t *fft = ffts_init_1d(n, sign);
if(!fft) return 0;
float *in = malloc(sizeof(float)*n*2);
float *out = malloc(sizeof(float)*n*2);
memcpy(in, data, sizeof(float)*n*2);
memcpy(out, data_out, sizeof(float)*n*2);
ffts_execute(fft, in, out);
memcpy(data_out, out, sizeof(float)*n*2);
ffts_free(fft);
free(in);
free(out);
if (sign == 1){
int i;
for (i=0;i<n*2;i++){
data_out[i]/=n;
}
}
return 1;
}
int fft2_sign(float *data, float *data_out, size_t n, size_t n2, int sign){
ffts_plan_t *fft = ffts_init_2d(n, n2, sign);
if(!fft) return 0;
float *in = malloc(sizeof(float)*n*n2*2);
float *out = malloc(sizeof(float)*n*n2*2);
memcpy(in, data, sizeof(float)*n*n2*2);
memcpy(out, data_out, sizeof(float)*n*n2*2);
ffts_execute(fft, in, out);
memcpy(data_out, out, sizeof(float)*n*n2*2);
ffts_free(fft);
free(in);
free(out);
if (sign == 1){
int i;
for (i=0;i<n*2;i++){
data_out[i]/=n*n2;
}
}
return 1;
}
int fftn_sign(float *data, float *data_out, int rank, size_t *Ns, int sign){
ffts_plan_t *fft = ffts_init_nd(rank, Ns, sign);
if(!fft) return 0;
ffts_execute(fft, data, data_out);
ffts_free(fft);
return 1;
}
end-of-c-declare
)
(define (fft_sign lst sign)
(let* ((infl (list->f32vector (apply append (map (lambda (c) (list (flo (real-part c)) (flo (imag-part c)))) lst))))
(outfl (make-f32vector (f32vector-length infl) 0.)))
(if ((c-lambda (scheme-object scheme-object int int) bool
"___result=fft_sign(___CAST(float*,___BODY_AS(___arg1,___tSUBTYPED)),
___CAST(float*,___BODY_AS(___arg2,___tSUBTYPED)),
___arg3,___arg4);")
infl outfl (length lst) sign)
(let loop ((lst (f32vector->list outfl)) (ret (list)))
(if (null? lst)
ret
(loop (cddr lst) (append ret (list (+ (car lst) (* (cadr lst) +i)))))
))
#f
)
))
(define (fft lst) (fft_sign lst -1))
(define (ifft lst) (fft_sign lst 1))
(define (fft2_sign lstlst sign)
(let* ((rows (length lstlst))
(cols (length (car lstlst)))
(infl (list->f32vector (apply append (map (lambda (c)
(list (flo (real-part c)) (flo (imag-part c)))) (listlist-flatten lstlst)))))
(outfl (make-f32vector (f32vector-length infl) 0.)))
(if ((c-lambda (scheme-object scheme-object int int int) bool
"___result=fft2_sign(___CAST(float*,___BODY_AS(___arg1,___tSUBTYPED)),
___CAST(float*,___BODY_AS(___arg2,___tSUBTYPED)),
___arg3,___arg4,___arg5);")
infl outfl rows cols sign)
(let loop ((lst (f32vector->list outfl)) (ret (list)))
(if (null? lst)
(let loopr ((r 0) (retm '()))
(if (fx= r rows)
retm
(loopr (fx+ r 1) (append retm (list
(let loopc ((c 0) (reti '()))
(if (fx= c cols)
reti
(loopc (fx+ c 1) (append reti (list (list-ref ret (+ (* r cols) c)))))
)
)
)))
))
(loop (cddr lst) (append ret (list (+ (car lst) (* (cadr lst) +i)))))
))
#f
)
))
(define (fft2 lstlst) (fft2_sign lstlst -1))
(define (ifft2 lstlst) (fft2_sign lstlst 1))
;; eof
| false |
6b6efd34aff2411816a69a123b442f933e4893f0
|
c39d4eda6c001b3aa98789232f9ce422369ece8e
|
/staged-regexp.scm
|
9133a094b16d02a28c0a8a1bde32e528e90c25de
|
[] |
no_license
|
namin/staged-miniKanren
|
43477369ab2150a6f26222b1b50ab008fb64f15a
|
af986fd3e8facf83d21db41826e4609b0d45e32d
|
refs/heads/master
| 2023-08-31T23:45:51.352139 | 2022-02-27T18:35:35 | 2022-02-27T18:35:35 | 109,611,513 | 115 | 16 | null | 2021-07-08T18:05:27 | 2017-11-05T19:59:39 |
Scheme
|
UTF-8
|
Scheme
| false | false | 3,924 |
scm
|
staged-regexp.scm
|
;; inspired by https://github.com/webyrd/relational-parsing-with-derivatives
(define regexp-NULL #f) ; -- the empty set
(define regexp-BLANK #t) ; -- the empty string
(define (valid-seqo exp)
(fresh (pat1 pat2)
(== `(seq ,pat1 ,pat2) exp)
(=/= regexp-NULL pat1)
(=/= regexp-BLANK pat1)
(=/= regexp-NULL pat2)
(=/= regexp-BLANK pat2)))
(define (seqo pat1 pat2 out)
(conde
[(== regexp-NULL pat1) (== regexp-NULL out)]
[(== regexp-NULL pat2) (== regexp-NULL out) (=/= regexp-NULL pat1)]
[(== regexp-BLANK pat1) (== pat2 out) (=/= regexp-NULL pat2)]
[(== regexp-BLANK pat2) (== pat1 out) (=/= regexp-NULL pat1) (=/= regexp-BLANK pat1)]
[(=/= regexp-NULL pat1) (=/= regexp-BLANK pat1) (=/= regexp-NULL pat2) (=/= regexp-BLANK pat2) (== `(seq ,pat1 ,pat2) out)]))
(define (valid-alto exp)
(fresh (pat1 pat2)
(== `(alt ,pat1 ,pat2) exp)
(=/= regexp-NULL pat1)
(=/= regexp-NULL pat2)
(=/= pat1 pat2)))
(define (alto pat1 pat2 out)
(conde
[(== pat1 pat2) (== pat1 out)]
[(=/= pat1 pat2)
(conde
[(== regexp-NULL pat1) (== pat2 out)]
[(== regexp-NULL pat2) (== pat1 out) (=/= regexp-NULL pat1)]
[(=/= regexp-NULL pat1) (=/= regexp-NULL pat2) (== `(alt ,pat1 ,pat2) out)])]))
(define (valid-repo exp)
(fresh (pat)
(== `(rep ,pat) exp)
(=/= regexp-BLANK pat)
(=/= regexp-NULL pat)
(fresh (re1 re2)
(conde
((symbolo pat))
((== `(seq ,re1 ,re2) pat))
((== `(alt ,re1 ,re2) pat))))))
(define (repo pat out)
(conde
[(== regexp-BLANK out)
(conde
[(== regexp-NULL pat)]
[(== regexp-BLANK pat)])]
[(conde
((symbolo pat) (== `(rep ,pat) out))
((fresh (re1 re2)
(conde
((== `(rep ,re1) pat)
; remove nested reps
(== pat out))
((== `(seq ,re1 ,re2) pat)
(== `(rep ,pat) out))
((== `(alt ,re1 ,re2) pat)
(== `(rep ,pat) out))))))]))
(define (regexp-matcho pattern data out)
(conde
((== '() data) (deltao pattern out))
((fresh (a d res)
(== (cons a d) data)
(derivo pattern a res)
(regexp-matcho res d out)))))
(define (deltao re out)
(conde
[(== regexp-BLANK re) (== #t out)]
[(== regexp-NULL re) (== #f out)]
[(symbolo re) (== #f out)]
[(fresh (re1)
(== `(rep ,re1) re)
(== #t out)
(valid-repo re))]
[(fresh (re1 re2 res1 res2)
(== `(seq ,re1 ,re2) re)
(valid-seqo re)
(conde
((== #f res1) (== #f out))
((== #t res1) (== #f res2) (== #f out))
((== #t res1) (== #t res2) (== #t out)))
(deltao re1 res1)
(deltao re2 res2))]
[(fresh (re1 re2 res1 res2)
(== `(alt ,re1 ,re2) re)
(valid-alto re)
(conde
((== #t res1) (== #t out))
((== #f res1) (== #t res2) (== #t out))
((== #f res1) (== #f res2) (== #f out)))
(deltao re1 res1)
(deltao re2 res2))]))
(define (derivo re c out)
(fresh ()
(symbolo c)
(conde
[(== regexp-BLANK re) (== regexp-NULL out)]
[(== regexp-NULL re) (== regexp-NULL out)]
[(symbolo re)
(conde
[(l== c re) (== regexp-BLANK out)]
[(=/= c re) (== regexp-NULL out)])]
[(fresh (re1 res1)
(== `(rep ,re1) re)
(valid-repo re)
(seqo res1 re out)
(derivo re1 c res1))]
[(fresh (re1 re2 res1 res2)
(== `(alt ,re1 ,re2) re)
(valid-alto re)
(derivo re1 c res1)
(derivo re2 c res2)
(alto res1 res2 out))]
[(fresh (re1 re2 res1 res2 res3 res4 res5)
(== `(seq ,re1 ,re2) re)
(valid-seqo re)
(derivo re1 c res1)
(deltao re1 res3)
(derivo re2 c res4)
(seqo res1 re2 res2)
(seqo res3 res4 res5)
(alto res2 res5 out))])))
| false |
2fe7098225479e46822416c36e9dc57080b94e1c
|
49ce71db04085d8a3ce90a9b3b8925fb36cc865d
|
/test-all.scm
|
bee62a24051f45d25f2f1233b8ac5fdba6b60bb2
|
[] |
no_license
|
fedeinthemix/chez-irregex
|
f3e0eb8cf85cef90dffd5a5484724038cd1b9826
|
0492ffefd660dea03401d013ad6d484eb3d7d8db
|
refs/heads/master
| 2021-01-09T20:11:13.163733 | 2016-06-13T12:32:55 | 2016-06-13T12:32:55 | 61,034,245 | 6 | 1 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 360 |
scm
|
test-all.scm
|
#!/usr/local/bin/csi -script
;; just run this file as "csi -script test-all.scm" to run the full
;; test suite
(use test extras utils irregex)
(test-begin)
(load "test-cset.scm")
(load "test-irregex.scm")
(load "test-irregex-gauche.scm")
(load "test-irregex-scsh.scm")
(load "test-irregex-pcre.scm")
(load "test-irregex-utf8.scm")
(test-end)
(test-exit)
| false |
7cb5e194f8ea51bf58391304f0cdc9f99570e08d
|
320a615ef54449a39e2ca9e59847106e30cc8d7a
|
/test/cavity.scm
|
189482baded1185622c764185c89b6b9a0ecea16
|
[] |
no_license
|
alexei-matveev/bgy3d
|
5cf08ea24a5c0f7b0d6e1d572effdeef8232f173
|
0facadd04c6143679033202d18017ae2a533b453
|
refs/heads/master
| 2021-01-01T17:47:22.766959 | 2015-07-10T09:21:49 | 2015-07-10T09:21:49 | 38,872,299 | 2 | 1 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 3,620 |
scm
|
cavity.scm
|
;;;
;;; Copyright (c) 2014 Alexei Matveev
;;;
;;; The default solver may not converge, see snes-solver in settings.
;;;
;;; ../bgy3d -L ../ -s ./cavity.scm
;;;
(use-modules
(guile bgy3d) ; rism-solute, hnc3d-run-solute
(guile molecule) ; find-molecule
(guile utils) ; numbers->strings
(ice-9 match)
(ice-9 pretty-print)
(ice-9 format))
;;;
;;; Make a hard-sphere potential if any of the sites is named "HS",
;;; otherwise return #f telling to use the default recepie:
;;;
(define (make-ff a b)
(define (hs a b)
(and (equal? (site-name a) "HS")
(let ((d (site-sigma a)))
(lambda (rab)
(if (> rab d)
0.0
+inf.0)))))
(or (hs a b)
(hs b a)))
(define *settings*
`((L . 320.0)
(N . 16384)
(rho . 0.0333295)
(beta . 1.6889)
;; (dielectric . 78.4)
(norm-tol . 1.0e-14)
(max-iter . 1500)
(damp-start . 1.0)
(lambda . 0.02)
(bond-length-thresh . 2.0)
(derivatives . #f)
(closure . HNC)
(snes-solver . "trial")
(force-field-short . ,make-ff)
(verbosity . 0)))
(define *solvent*
(find-molecule "OW"))
;;; Precompute solvent susceptibility. Pure solvent run here:
(define *properties* (rism-solvent *solvent* *settings*))
(define chi (assoc-ref *properties* 'susceptibility))
(define kappa (assoc-ref *properties* 'compressibility))
(define kappa-error (assoc-ref *properties* 'compressibility-error))
(define beta (assoc-ref *settings* 'beta))
(define rho (assoc-ref *settings* 'rho))
;;;
;;; -1 3 -3
;;; 1 - β/ρκ, β in kcal , κ in A / kcal, ρ in A
;;;
(format #t "beta = ~A kcal^-1\n" beta)
(format #t "rho = ~A A^-3\n" rho)
(format #t "mu = ~A kcal\n" (assoc-ref *properties* 'free-energy))
(format #t "kappa = ~A A^3/kcal, error = ~A A^3/kcal (1)\n" kappa kappa-error)
(define excess-coordination (assoc-ref *properties* 'excess-coordination))
(define excess-coordination-error (assoc-ref *properties* 'excess-coordination-error))
(define kappa (/ (* beta (+ 1 excess-coordination)) rho))
(define kappa-error (/ (* beta excess-coordination-error) rho))
(format #t "kappa = ~A A^3/kcal, error = ~A A^3/kcal (2)\n" kappa kappa-error)
(format #t "rho * kappa = ~A kcal^-1\n" (* rho kappa))
(format #t "beta / (rho * kappa) = ~A\n" (/ beta (* rho kappa)))
(define nc0 (- 1 (/ beta (* rho kappa))))
(format #t "rho * c(0) = 1 - beta / (rho * kappa) = ~A\n" nc0)
;;;
;;; A = -2.99 kcal (HNC) or -4.19 kcal (KH):
;;;
(define A (/ nc0 beta 2))
(format #t "A = kT * rho * c(0) / 2 = ~A kcal\n" A)
;;; With sigma = 3.16 it should give mu = 6.44 kcal (KH):
(define (make-solute sigma)
`("HS" (("HS" (0.0 0.0 0.0) ,sigma .59210136775415951210 0.0)))) ; 0.1549
;;;
;;; Call sequence for 1D RISM:
;;;
;;; (set! *settings* (env-set 'verbosity 2 *settings*))
(define (run-1d sigma)
(let* ((solute (make-solute sigma))
(alist (rism-solute solute *solvent* *settings* chi))
(free-energy (assoc-ref alist 'free-energy))
(excess-coordination (assoc-ref alist 'excess-coordination)))
(pretty-print alist)
(list sigma
free-energy
excess-coordination
(+ free-energy (* A (- excess-coordination))))))
;; (run-1d 3.16)
;; (exit 1)
(define *grid*
(list
0.125 0.25 0.5 1. 2. 3.0 3.16 4. 5. 6. 7. 8. 9. 10.
20. 40.
60. 80.
))
(define *results*
(map run-1d *grid*))
(pretty-print *results*)
(for-each
(lambda (row)
(match row
((s mu n e)
(format #t "~A ~A ~A ~A\n" s mu n e))))
*results*)
| false |
4020ce390cd03bdd7ddba3c66caf9014a12475aa
|
fca62d08480d0db43627f51449b9caea48295601
|
/sources/foreign-interfaces/b64.scm
|
113e420d03fb79f27b68349f29a207ef72912b6d
|
[
"MIT"
] |
permissive
|
alxbnct/Schemings
|
aa4783cca04b4a393972ead754cd3e2ce89bf193
|
a7c322ee37bf9f43b696c52fc290488aa2dcc238
|
refs/heads/master
| 2023-06-01T02:06:38.441543 | 2021-06-12T15:27:28 | 2021-06-12T15:27:28 | null | 0 | 0 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 2,490 |
scm
|
b64.scm
|
(declare (unit b64))
(foreign-declare "
#include <cencode.h>
#include <cdecode.h>
// allocates a base64_encodestate
base64_encodestate* malloc_base64_encodestate()
{
base64_encodestate* state = malloc(sizeof(base64_encodestate));
return state;
}
// frees a base64_encodestate
void free_base64_encodestate(base64_encodestate* state)
{
free(state);
}
// allocates a base64_decodestate
base64_decodestate* malloc_base64_decodestate()
{
base64_decodestate* state = malloc(sizeof(base64_decodestate));
return state;
}
// frees a base64_decodestate
void free_base64_decodestate(base64_decodestate* state)
{
free(state);
}
// wraps the base64_encode_block function
char* base64_encode_block_wrapped(
unsigned char* plaintext_in, int length_in,
base64_encodestate* state_in)
{
char* encoded = malloc(((length_in * 2) + 16) * sizeof(char));
if (encoded == NULL)
{
return NULL;
}
char* encoded_to = encoded + base64_encode_block((char*)plaintext_in, length_in, encoded, state_in);
encoded_to += base64_encode_blockend(encoded_to, state_in);
*encoded_to = 0;
return encoded;
}
")
;; base64-encodestate pointers definitions
(define-foreign-type base64-encodestate "base64_encodestate")
(define-foreign-type base64-encodestate* (c-pointer base64-encodestate))
;; base64-encodestate pointers memory management
(define malloc-base64-encodestate (foreign-lambda base64-encodestate* "malloc_base64_encodestate"))
(define free-base64-encodestate (foreign-lambda void "free_base64_encodestate" base64-encodestate*))
;; base64-decodestate pointers definitions
(define-foreign-type base64-decodestate "base64_decodestate")
(define-foreign-type base64-decodestate* (c-pointer base64-decodestate))
;; base64-decodestate pointers memory management
(define malloc-base64-decodestate (foreign-lambda base64-decodestate* "malloc_base64_decodestate"))
(define free-base64-decodestate (foreign-lambda void "free_base64_decodestate" base64-decodestate*))
;; initializes the states
(define base64-init-encodestate (foreign-lambda void "base64_init_encodestate" base64-encodestate*))
(define base64-init-decodestate (foreign-lambda void "base64_init_decodestate" base64-decodestate*))
;; encodes a block
(define base64-encode-block
(foreign-lambda c-string* "base64_encode_block_wrapped"
u8vector int base64-encodestate*))
;; decodes a block
(define base64-decode-block
(foreign-lambda int "base64_decode_block"
u8vector int u8vector base64-decodestate*))
| false |
5e12551700da01ae88b93b2354a689186987da18
|
fb9a1b8f80516373ac709e2328dd50621b18aa1a
|
/ch2/2-5_system_with_generic_operations.scm
|
e6269bd05acc02b46e385c885e94ca91d06fb9b3
|
[] |
no_license
|
da1/sicp
|
a7eacd10d25e5a1a034c57247755d531335ff8c7
|
0c408ace7af48ef3256330c8965a2b23ba948007
|
refs/heads/master
| 2021-01-20T11:57:47.202301 | 2014-02-16T08:57:55 | 2014-02-16T08:57:55 | null | 0 | 0 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 5,871 |
scm
|
2-5_system_with_generic_operations.scm
|
;; 2.5 汎用演算のシステム
;2.5.1 汎用算術演算
; 汎用算術演算の設計作業は,汎用複素数演算の背系に似ている
; 汎用のaddは,通常の数については基本の加算 + のように,有理数に対してはadd-ratのように,複素数に対してはadd-complexのように働いてほしい
(load "./ch2/2-4_Multiple_Representations_for_Abstract_Data.scm")
(define (add x y) (apply-generic 'add x y))
(define (sub x y) (apply-generic 'sub x y))
(define (mul x y) (apply-generic 'mul x y))
(define (div x y) (apply-generic 'div x y))
(define (equ? x y) (apply-generic 'equ? x y))
(define (zero? x) (apply-generic 'zero? x))
;;問題2.81用
(define (exp x y) (apply-generic 'exp x y))
(define (install-scheme-number-package)
(define (tag x)
(attach-tag 'scheme-number x))
(put 'add '(scheme-number scheme-number)
(lambda (x y) (tag (+ x y))))
(put 'sub '(scheme-number scheme-number)
(lambda (x y) (tag (- x y))))
(put 'mul '(scheme-number scheme-number)
(lambda (x y) (tag (* x y))))
(put 'div '(scheme-number scheme-number)
(lambda (x y) (tag (/ x y))))
(put 'equ? '(scheme-number scheme-number)
(lambda (x y) (= x y)))
(put 'zero? '(scheme-number)
(lambda (x) (= x 0)))
;; 問題2.81
(put 'exp '(scheme-number scheme-number)
(lambda (x y) (tag (expt x y))))
;; 2.83
(put 'raise '(scheme-number)
(lambda (x)
(make-rational (contents x) 1)))
(put 'make 'scheme-number
(lambda (x) (tag x)))
'done)
(install-scheme-number-package)
(define (make-scheme-number n)
((get 'make 'scheme-number) n))
;;sample
(define n (make-scheme-number 10))
(define m (make-scheme-number 5))
(add n m)
(sub n m)
(mul n m)
(div n m)
;; 有理数算術演算のパッケージ
(define (install-rational-package)
;; 内部手続き
(define (numer x) (car x))
(define (denom x) (cdr x))
(define (make-rat n d)
(let ((g (gcd n d)))
(cons (/ n g) (/ d g))))
(define (add-rat x y)
(make-rat (+ (* (numer x) (denom y))
(* (numer y) (denom x)))
(* (denom x) (denom y))))
(define (sub-rat x y)
(make-rat (- (* (numer x) (denom y))
(* (numer y) (denom x)))
(* (denom x) (denom y))))
(define (mul-rat x y)
(make-rat (* (numer x) (numer y))
(* (denom x) (denom y))))
(define (div-rat x y)
(make-rat (* (numer x) (denom y))
(* (denom x) (numer y))))
;; システムの他の部分へのインタフェース
(define (tag x) (attach-tag 'rational x))
(put 'add '(rational rational)
(lambda (x y) (tag (add-rat x y))))
(put 'sub '(rational rational)
(lambda (x y) (tag (sub-rat x y))))
(put 'mul '(rational rational)
(lambda (x y) (tag (mul-rat x y))))
(put 'div '(rational rational)
(lambda (x y) (tag (div-rat x y))))
(put 'equ? '(rational rational)
(lambda (x y) (equal? x y)))
(put 'zero? '(rational)
(lambda (x) (= 0 (numer x))))
;; 2.83
;;;複素数への強制型変換
(put 'raise '(rational)
(lambda (x)
(make-complex-from-real-imag (round (/ (numer x) (denom x))) 0)))
(put 'make 'rational
(lambda (n d) (tag (make-rat n d))))
'done)
(install-rational-package)
(define (make-rational n d)
((get 'make 'rational) n d))
(define r1 (make-rational 2 5))
(define r2 (make-rational 1 4))
(add r1 r2)
(sub r1 r2)
(mul r1 r2)
(div r1 r2)
;; 複素数のパッケージ
(define (install-complex-package)
;; imported procedures from rectangular and polar packages
(define (make-from-real-imag x y)
((get 'make-from-real-imag 'rectangular) x y))
(define (make-from-mag-ang r a)
((get 'make-from-mag-ang 'polar) r a))
;; internal procedures
(define (add-complex z1 z2)
(make-from-real-imag (+ (real-part z1) (real-part z2))
(+ (imag-part z1) (imag-part z2))))
(define (sub-complex z1 z2)
(make-from-real-imag (- (real-part z1) (real-part z2))
(- (imag-part z1) (imag-part z2))))
(define (mul-complex z1 z2)
(make-from-mag-ang (* (magnitude z1) (magnitude z2))
(+ (angle z1) (angle z2))))
(define (div-complex z1 z2)
(make-from-mag-ang (/ (magnitude z1) (magnitude z2))
(- (angle z1) (angle z2))))
(define (=zero-complex? z1)
(and (= (real-part z1) 0)
(= (imag-part z1) 0)))
;; interface to rest of the system
(define (tag z) (attach-tag 'complex z))
(put 'add '(complex complex)
(lambda (z1 z2) (tag (add-complex z1 z2))))
(put 'sub '(complex complex)
(lambda (z1 z2) (tag (sub-complex z1 z2))))
(put 'mul '(complex complex)
(lambda (z1 z2) (tag (mul-complex z1 z2))))
(put 'div '(complex complex)
(lambda (z1 z2) (tag (div-complex z1 z2))))
(put 'make-from-real-imag 'complex
(lambda (x y) (tag (make-from-real-imag x y))))
(put 'make-from-mag-ang 'complex
(lambda (x y) (tag (make-from-mag-ang x y))))
(put 'real-part '(complex) real-part)
(put 'imag-part '(complex) imag-part)
(put 'magnitude '(complex) magnitude)
(put 'angle '(complex) angle)
(put 'equ? '(complex complex)
(lambda (x y) (equal? x y)))
(put 'zero? '(complex)
(lambda (x) (=zero-complex? x)))
'done)
(install-complex-package)
(define (make-complex-from-real-imag x y)
((get 'make-from-real-imag 'complex) x y))
(define (make-complex-from-mag-ang x y)
((get 'make-from-mag-ang 'complex) x y))
(define ri1 (make-complex-from-real-imag 3 4))
(define ri2 (make-complex-from-real-imag -1 2))
(add ri1 ri2)
(sub ri1 ri2)
(mul ri1 ri2)
(div ri1 ri2)
(define ma1 (make-complex-from-mag-ang 2 3.14))
(define ma2 (make-complex-from-mag-ang 1 1.57))
(add ma1 ma2)
(sub ma1 ma2)
(mul ma1 ma2)
(div ma1 ma2)
| false |
4b10a902b2e3c6d9eeca2080bcce0bd52edba691
|
be9a74515b2f0357cb882f061abe7f1c830fa186
|
/test-genv.scm
|
6b963426624b73ab72f073aa6aeb69a95ad1ebb9
|
[
"MIT"
] |
permissive
|
shirok/Gauche-lisp15
|
994155d69dd72fd70c903d683a349f7c3905a5f6
|
9e171cc80a987e21e237e0a1ac654a9c7dba2c03
|
refs/heads/master
| 2022-11-11T07:46:22.195831 | 2022-11-05T18:29:41 | 2022-11-05T18:29:41 | 169,337,732 | 21 | 3 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 1,230 |
scm
|
test-genv.scm
|
(use gauche.test)
(use gauche.parameter)
(use file.util)
(test-start "genv")
(test-section "LISP1.5.runtime")
(use LISP1.5.runtime)
(test-module 'LISP1.5.runtime)
(test* "Loading genv" #t (load "mx/genv.mx"))
(define-syntax evaltest
(syntax-rules ()
[(evaltest output input env)
(test* (x->string input) output
($lisp->scheme (EVAL ($scheme->lisp input)
($scheme->lisp env))))]))
(evaltest 'A '(QUOTE A) '())
(evaltest '(X . Y) '(CONS (QUOTE X) (QUOTE Y)) '())
(evaltest 'NIL 'NIL '())
(evaltest 'NIL 'F '())
(evaltest 'T 'T '())
(evaltest 'ORANGE 'APPLE '((APPLE . ORANGE)))
(evaltest '(G F E D C B A)
'(REVERSE (QUOTE (A B C D E F G)))
'((REVERSE . (LAMBDA (XS)
(COND ((NULL XS) NIL)
(T (APPEND (REVERSE (CDR XS))
(CONS (CAR XS) NIL))))))))
(evaltest '(G F E D C B A)
'#,(m-expr "reverse[(A B C D E F G)]")
'((REVERSE . #,(m-expr "lambda[[xs];\
[null[xs] -> NIL;\
T -> append[reverse[cdr[xs]];cons[car[xs];NIL]]]]"))))
(test-end)
| true |
d5ee7ed279a2f0a07b1bc69acecf92332c81286b
|
de82217869618b0a975e86918184ecfddf701172
|
/reference/unicode/parseUCD.sch
|
eed103622fd9e7f9af7c59045cfd9e0f28058712
|
[] |
no_license
|
schemedoc/r6rs
|
6b4ef7fd87d8883d6c4bcc422b38b37f588e20f7
|
0009085469e47df44068873f834a0d0282648750
|
refs/heads/master
| 2021-06-18T17:44:50.149253 | 2020-01-04T10:50:50 | 2020-01-04T10:50:50 | 178,081,881 | 5 | 0 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 57,601 |
sch
|
parseUCD.sch
|
; Copyright 2006 William D Clinger.
;
; Permission to copy this software, in whole or in part, to use this
; software for any lawful purpose, and to redistribute this software
; is granted subject to the restriction that all copies made of this
; software must include this copyright notice in full.
;
; I also request that you send me a copy of any improvements that you
; make to this software so that they may be incorporated within it to
; the benefit of the Scheme community.
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; Parsers for UCD File Format.
;
; Typical usage:
; (read-unicode-files)
; (write-unicode-tables "temp.sch")
;
; Uses filter, and perhaps a few more non-R5RS procedures.
; Assumes the target system has bytevector operations.
;
; The Unicode files that are needed are:
; UnicodeData.txt
; SpecialCasing.txt
; CompositionExclusions.txt
; PropList.txt
; auxiliary/GraphemeBreakProperty.txt
; auxiliary/WordBreakProperty.txt
; These files can be found at http://www.unicode.org/Public/UNIDATA/
;
; The Larceny format for a line of parsed data is
; a vector
; whose element 0 is an exact integer or pair of exact integers
; specifying a code point or range (inclusive)
; whose remaining elements are strings of ASCII characters
; Given a string naming a file that is in UCD File Format,
; returns a list of the Larceny format for the lines of parsed data
; in the file.
(define (parseUCD-file filename)
(display "Parsing ")
(display filename)
(display "...")
(newline)
(call-with-input-file
filename
parseUCD-port))
; Given an input port for UCD File Format,
; reads and parses the lines of data in the port,
; returning a list of the Larceny format for the lines of parsed data.
(define (parseUCD-port in)
(let loop ((lines '()))
(let ((x (parseUCD-line in)))
(if (eof-object? x)
(reverse lines)
(loop (cons x lines))))))
; Reads and parses a single line from the given input port.
; Returns an end-of-file object or
; a vector of parsed data in the Larceny format described above.
(define (parseUCD-line in)
(consume-whitespace! in)
(let ((code-point (parseUCD-field in)))
(cond ((eof-object? code-point)
code-point)
((not code-point)
(parseUCD-line in))
(else
(let loop ((fields '()))
(let ((x (parseUCD-field in)))
(if x
(loop (cons x fields))
(let ((result (apply vector
(parse-code-point code-point)
(reverse fields))))
; hack for parsing ranges in UnicodeData.txt
(if (and (> (vector-length result) 1)
(let* ((name (vector-ref result 1))
(n (string-length name)))
(and (> n 8)
(string-ci=? (substring name (- n 8) n)
", First>")
(string=? (substring name 0 1) "<"))))
(let* ((name (vector-ref result 1))
(n (string-length name))
(result2 (parseUCD-line in)))
(if (and (> (vector-length result2) 1)
(let* ((name2 (vector-ref result2 1))
(n2 (string-length name2)))
(and (> n2 7)
(= (- n 1) n2)
(string=?
(substring name 0 (- n 8))
(substring name2 0 (- n 8)))
(string-ci=?
(substring name2 (- n 8) n2)
", Last>"))))
(let ((cp1 (vector-ref result 0))
(cp2 (vector-ref result2 0)))
(vector-set! result 0 (list cp1 cp2))
result)
(error "Bad UnicodeData.txt range syntax: "
name (vector-ref result2 1))))
result)))))))))
; Reads and parses a single field from the given input port.
; Returns an end-of-file object, #f, or a string of ASCII characters.
(define (parseUCD-field in)
(consume-whitespace! in)
(let loop ((chars '()))
(let ((c (peek-char in)))
(cond ((eof-object? c)
(if (null? chars)
c
(canonical-string (list->string (reverse chars)))))
((char=? c #\;)
(read-char in)
(canonical-string (list->string (reverse chars))))
((char=? c #\newline)
(if (null? chars)
(begin (read-char in) #f)
(canonical-string (list->string (reverse chars)))))
; ((char-whitespace? c)
; (consume-whitespace! in)
; (if (null? chars)
; #f
; (canonical-string (list->string (reverse chars)))))
(else
(read-char in)
(loop (cons c chars)))))))
; Given a string specifying a code point or range of code points,
; returns an exact integer or pair of exact integers or #f.
(define (parse-code-point str)
;(display str)
;(newline)
(let* ((chars (string->list str))
(range (memv #\. chars))
(spaces (memv #\space chars)))
(if range
(list (parse-code-point
(substring str 0 (- (string-length str) (length range))))
(parse-code-point
(list->string (cddr range))))
(if (and spaces (not (eq? chars spaces)))
(parse-code-point
(substring str 0 (- (string-length str) (length spaces))))
(string->number str 16)))))
; Returns the canonical string equal to the given string.
(define (canonical-string str)
(let ((probe (member str canonical-canonical-strings)))
(if probe
(car probe)
str)))
(define canonical-canonical-strings
'("Lu" "Ll" "Lt" "Lm" "Lo"
"Mn" "Mc" "Me"
"Nd" "Nl" "No"
"Pc" "Pd" "Ps" "Pe" "Pi" "Pf" "Po"
"Sm" "Sc" "Sk" "So"
"Zs" "Zl" "Zp"
"Cc" "Cf" "Cs" "Co" "Cn"))
; Consumes whitespace from the given input port.
; Does not consume the #\newline at the end of a comment line.
(define (consume-whitespace! in)
(let ((c (peek-char in)))
(cond ((eof-object? c)
#f)
((char=? c #\newline)
#f)
((char-whitespace? c)
(read-char in)
(consume-whitespace! in))
((char=? c #\#)
(consume-line! in))
(else #f))))
; Consumes the current line from the given input port.
(define (consume-line! in)
(let ((c (peek-char in)))
(cond ((eof-object? c)
#f)
((char=? c #\newline)
#f)
(else
(read-char in)
(consume-line! in)))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; Reads the standard file from a specified directory,
; which defaults to the current working directory.
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(define unicode-data '()) ; 17710 entries (Unicode 5.0.0)
(define case-folding '()) ; 1039 entries
(define special-casing '()) ; 119 entries
(define composition-exclusions '()) ; 81 entries
(define prop-list '()) ; 896 entries
(define graphem-break-property '()) ;
(define word-break-property '()) ; 468 entries
(define (read-unicode-files . rest)
(if (null? rest)
(read-unicode-files "")
(let ((dir (car rest)))
(set! unicode-data
(parseUCD-file (string-append dir "UnicodeData.txt")))
'
(set! case-folding
(parseUCD-file (string-append dir "CaseFolding.txt")))
(set! special-casing
(parseUCD-file (string-append dir "SpecialCasing.txt")))
(set! composition-exclusions
(parseUCD-file (string-append dir "CompositionExclusions.txt")))
(set! prop-list
(parseUCD-file (string-append dir "PropList.txt")))
(set! grapheme-break-property
(parseUCD-file (string-append dir "GraphemeBreakProperty.txt")))
(set! word-break-property
(parseUCD-file (string-append dir "WordBreakProperty.txt")))
#t)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; The proposed R6RS procedures that require Unicode information
; are:
;
; char-upcase
; char-downcase
; char-titlecase
; char-foldcase
;
; char-general-category
; char-alphabetic?
; char-numberic?
; char-whitespace?
; char-upper-case?
; char-lower-case?
; char-title-case?
;
; string-upcase
; string-downcase
; string-titlecase
; string-foldcase
;
; string-normalize-nfd
; string-normalize-nfkd
; string-normalize-nfc
; string-normalize-nfkc
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Given the Larceny format for a line of parsed data
; taken from UnicodeData.txt,
; returns the Unicode general category as a symbol.
(define (extract-general-category data)
(if (> (vector-length data) 2)
(string->symbol (vector-ref data 2))
(error "Bad data to extract-general-category" data)))
; Given an exact integer that corresponds to a Unicode scalar value,
; returns its Unicode general category as a symbol.
(define (get-general-category n)
(define (data-scalar-value data)
(let ((sv (vector-ref data 0)))
(if (pair? sv) (car sv) sv)))
(let loop ((previous (car unicode-data))
(rest (cdr unicode-data)))
(cond ((null? rest)
(extract-general-category previous))
((>= n (data-scalar-value (car rest)))
(loop (car rest) (cdr rest)))
(else
(extract-general-category previous)))))
; Given the Larceny format for a line of parsed data
; taken from UnicodeData.txt,
; returns the simple uppercase mapping as a string.
(define (extract-simple-uppercase-mapping data)
(if (> (vector-length data) 12)
(vector-ref data 12)
""))
; Given the Larceny format for a line of parsed data
; taken from UnicodeData.txt,
; returns the simple lowercase mapping as a string.
(define (extract-simple-lowercase-mapping data)
(if (> (vector-length data) 13)
(vector-ref data 13)
""))
; Given the Larceny format for a line of parsed data
; taken from UnicodeData.txt,
; returns the simple titlecase mapping as a string.
(define (extract-simple-titlecase-mapping data)
(if (> (vector-length data) 14)
(vector-ref data 14)
""))
; Returns a list of lists of the form (code-point category)
; where code-point is an exact integer, category is a string,
; and all code-points from this one to the next share the
; same Unicode general category.
(define (general-category-intervals)
(define unassigned-category (string->symbol "Cn"))
(let loop ((n 0)
(prior-cp -1) ; previous code point
(previous unassigned-category) ; previous category
(data unicode-data)
(intervals '()))
(cond ((null? data)
(reverse (cons (list (+ prior-cp 1) unassigned-category)
intervals)))
((pair? (vector-ref (car data) 0))
(cond ((and (not (= (+ prior-cp 1) (car (vector-ref (car data) 0))))
(not (eq? previous unassigned-category)))
; We have a gap in the code points.
(loop (+ n 1)
(+ prior-cp 1)
unassigned-category
data
(cons (list (+ prior-cp 1) unassigned-category)
intervals)))
((eq? previous (extract-general-category (car data)))
(let* ((datum-as-list (vector->list (car data)))
(cp1 (cadr (car datum-as-list))))
(loop n
(- cp1 1)
previous
(cons (list->vector (cons cp1 (cdr datum-as-list)))
(cdr data))
intervals)))
(else
(let* ((datum (car data))
(datum-as-list (vector->list datum))
(cp1 (car (car datum-as-list)))
(cp2 (cadr (car datum-as-list)))
(datum1 (list->vector (cons cp1
(cdr datum-as-list))))
(datum2 (list->vector (cons (list (+ cp1 1) cp2)
(cdr datum-as-list)))))
(loop n
prior-cp
previous
(cons datum1 (cons datum2 (cdr data)))
intervals)))))
((and (not (= (+ prior-cp 1) (vector-ref (car data) 0)))
(not (eq? previous unassigned-category)))
; We have a gap in the code points.
(loop (+ n 1)
(+ prior-cp 1)
unassigned-category
data
(cons (list (+ prior-cp 1) unassigned-category)
intervals)))
((eq? previous (extract-general-category (car data)))
(loop n (vector-ref (car data) 0) previous (cdr data) intervals))
(else
(let ((code-point (vector-ref (car data) 0)))
;(display (number->string code-point 16))
;(display " ")
(let ((category (extract-general-category (car data))))
;(write category)
;(newline)
(loop (+ n 1)
(vector-ref (car data) 0)
category
(cdr data)
(cons (list code-point category) intervals))))))))
; Given the Larceny format for a line of parsed data
; taken from UnicodeData.txt,
; returns the Decomposition_Type and Decomposition_Mapping
; as a string.
(define (extract-decomposition-type data)
(if (> (vector-length data) 5)
(vector-ref data 5)
""))
; Given the Larceny format for a line of parsed data
; taken from UnicodeData.txt,
; returns the Canonical_Combining_Class
; as a string.
(define (extract-combining-class data)
(if (> (vector-length data) 3)
(vector-ref data 3)
""))
; Given the Larceny format for a line of parsed data
; taken from UnicodeData.txt,
; returns the numeric value as a string.
(define (extract-numeric-value data)
(if (> (vector-length data) 8)
(vector-ref data 8)
""))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Returns a list of lists of the form (code-point0 code-point1)
; where both code-point0 and code-point1 are strings of hex digits
; representing a Unicode scalar value,
; and code-point1 is f applied to the Larceny format
; for a line of parsed data.
(define (extract-from-unicode f)
(let* ((x (filter (lambda (data)
(> (string-length (f data)) 0))
unicode-data)))
(map (lambda (data)
(let ((cp (vector-ref data 0)))
(if (pair? cp)
(list (map (lambda (cp) (number->string cp 16))
cp)
(f data))
(list (number->string (vector-ref data 0) 16)
(f data)))))
x)))
; Returns a list of lists of the form (code-point0 code-point1)
; where both code-point0 and code-point1 are strings of hex digits
; representing a Unicode scalar value, and code-point1 is
; the simple uppercase mapping of code-point0,
; the simple lowercase mapping of code-point0,
; the simple titlecase mapping of code-point0,
; the decomposition type, or
; the combining class.
(define (extract-simple-uppercase-mappings)
(extract-from-unicode extract-simple-uppercase-mapping))
(define (extract-simple-lowercase-mappings)
(extract-from-unicode extract-simple-lowercase-mapping))
(define (extract-simple-titlecase-mappings)
(extract-from-unicode extract-simple-titlecase-mapping))
(define (extract-decomposition-types)
(extract-from-unicode extract-decomposition-type))
(define (extract-combining-classes)
(filter (lambda (x)
(not (string=? (cadr x) "0")))
(extract-from-unicode extract-combining-class)))
(define (extract-canonical-compositions)
(define excluded
(map (lambda (x) (vector-ref x 0))
composition-exclusions))
(filter (lambda (x)
(and (not (char=? #\< (string-ref (cadr x) 0)))
(> (string-length (cadr x)) 5)
(not (memv (string->number (string-append "#x" (car x)))
excluded))))
(extract-decomposition-types)))
(define (extract-numeric-values)
(extract-from-unicode extract-numeric-value))
; Returns a list whose elements are of the forms
; code-point0
; (code-point0 code-point1)
; where both code-point0 and code-point1 are strings of hex digits
; representing a Unicode scalar value that has the named property
; according to the specified database (prop-list or word-break-property).
(define (extract-from-database database propname)
(let* ((n (string-length propname))
(x (filter (lambda (data)
(let ((s (vector-ref data 1)))
(and (<= n (string-length s))
(string=? propname (substring s 0 n)))))
database)))
(map (lambda (data)
(let ((cp (vector-ref data 0)))
(if (pair? cp)
(map (lambda (cp) (number->string cp 16))
cp)
(number->string (vector-ref data 0) 16))))
x)))
(define (extract-other-alphabetic)
(extract-from-database prop-list "Other_Alphabetic"))
(define (extract-white-space)
(extract-from-database prop-list "White_Space"))
(define (extract-control)
(extract-from-database grapheme-break-property "Control"))
(define (extract-extend)
(extract-from-database grapheme-break-property "Extend"))
(define (extract-format)
(extract-from-database word-break-property "Format"))
(define (extract-katakana)
(extract-from-database word-break-property "Katakana"))
(define (extract-aletter)
(extract-from-database word-break-property "ALetter"))
(define (extract-midletter)
(extract-from-database word-break-property "MidLetter"))
(define (extract-midnum)
(extract-from-database word-break-property "MidNum"))
(define (extract-numeric)
(extract-from-database word-break-property "Numeric"))
(define (extract-extendnumlet)
(extract-from-database word-break-property "ExtendNumLet"))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; Output of tables for unicode.sch and normalization.sch
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Given a file name, writes the tables to a file of that name.
(define (write-unicode-tables filename)
(call-with-output-file
filename
(lambda (out)
(define (block-comment)
(display (make-string 64 #\;) out)
(newline out)
(display ";" out)
(newline out)
(display "; The following tables were generated from" out)
(newline out)
(display "; UnicodeData.txt, SpecialCasing.txt," out)
(newline out)
(display "; PropList.txt, WordBreakProperty.txt," out)
(newline out)
(display "; and CompositionExclusions.txt." out)
(newline out)
(display "; Use parseUCD.sch and parseUCDpart2.sch" out)
(newline out)
(display "; to regenerate these tables." out)
(newline out)
(display ";" out)
(newline out)
(display (make-string 64 #\;) out)
(newline out)
(newline out))
(block-comment)
(write-category-tables out)
(write-casing-tables out)
(block-comment)
(write-special-casing-tables out)
(block-comment)
(write-normalization-tables out))))
(define (write-category-tables out)
(define c1
"; The following vector contains the general category for")
(define c2
"; characters whose Unicode scalar value is less than ")
(define s1
"; The following array of bytes, together with the vector below it,")
(define s2
"; implements an indirect mapping from all Unicode scalar values to")
(define s3
"; indices into the above vector.")
(define t1
"; The following vector of exact integers represents the")
(define t2
"; Unicode scalar values whose Unicode general category")
(define t3
"; is different from the Unicode scalar value immediately")
(define t4
"; less than it.")
(define number-of-common-characters 256)
(display c1 out)
(newline out)
(display c2 out)
(write number-of-common-characters out)
(display "." out)
(newline out)
(display ";" out)
(newline out)
(display "; This table contains " out)
(display number-of-common-characters out)
(display " entries." out)
(newline out)
(newline out)
(display "(define general-category-indices-for-common-characters" out)
(newline out)
(display " (list->bytevector" out)
(newline out)
(display " (map" out)
(newline out)
(display " general-category-symbol->index" out)
(newline out)
(display " '(" out)
(do ((n 0 (+ n 1)))
((>= n number-of-common-characters))
(if (zero? (modulo n 16))
(begin (newline out) (display " " out)))
(display (get-general-category n) out)
(display " " out))
(display "))))" out)
(newline out)
(newline out)
(let* ((intervals (general-category-intervals))
(code-points (map car intervals))
(categories (map cadr intervals)))
(display s1 out)
(newline out)
(display s2 out)
(newline out)
(display s3 out)
(newline out)
(display ";" out)
(newline out)
(display "; This table contains " out)
(display (length categories) out)
(display " entries." out)
(newline out)
(newline out)
(display "(define general-category-indices-for-all-characters" out)
(newline out)
(display " (list->bytevector" out)
(newline out)
(display " (map" out)
(newline out)
(display " general-category-symbol->index" out)
(newline out)
(display " '(" out)
(do ((categories categories (cdr categories))
(n 0 (+ n 1)))
((null? categories))
(if (zero? (modulo n 16))
(begin (newline out) (display " " out)))
(display (car categories) out)
(display " " out))
(display "))))" out)
(newline out)
(newline out)
(display t1 out)
(newline out)
(display t2 out)
(newline out)
(display t3 out)
(newline out)
(display t4 out)
(newline out)
(display ";" out)
(newline out)
(display "; This table contains " out)
(display (length code-points) out)
(display " entries." out)
(newline out)
(newline out)
(display "(define vector-of-code-points-with-same-category" out)
(newline out)
(display " '#(" out)
(do ((code-points code-points
(cdr code-points))
(n 0 (+ n 1)))
((null? code-points))
(if (zero? (modulo n 8))
(begin (newline out) (display " " out)))
(display "#x" out)
(display (number->string (car code-points) 16) out)
(display " " out))
(display "))" out)
(newline out)
(newline out)
(display "; The following array of bytes implements a direct mapping" out)
(newline out)
(display "; from small code points to indices into the above vector." out)
(newline out)
(display ";" out)
(newline out)
(display "; This table contains " out)
(display number-of-common-characters out)
(display " entries." out)
(newline out)
(newline out)
(display "(define general-category-indices-for-common-characters" out)
(newline out)
(display " (do ((i 0 (+ i 1))" out)
(newline out)
(display " (bv (make-bytevector " out)
(display number-of-common-characters out)
(display ")))" out)
(newline out)
(display " ((= i " out)
(display number-of-common-characters out)
(display ")" out)
(newline out)
(display " bv)" out)
(newline out)
(display " (bytevector-set! bv" out)
(newline out)
(display " i" out)
(newline out)
(display " (general-category-symbol->index" out)
(newline out)
(display " (char-general-category" out)
(newline out)
(display " (integer->char i))))))" out)
(newline out)
(newline out)))
; Just a simple insertion sort on lists.
(define (mysort <= xs)
(define (insert x xs)
(if (or (null? xs)
(<= x (car xs)))
(cons x xs)
(cons (car xs)
(insert x (cdr xs)))))
(define (sort xs)
(if (null? xs)
'()
(insert (car xs)
(sort (cdr xs)))))
(sort xs))
(define (write-casing-tables out)
(let* ((simple-upcase-mappings (extract-simple-uppercase-mappings))
(simple-downcase-mappings (extract-simple-lowercase-mappings))
(adjustments '())
(is16bit? (lambda (mapping) (< (string-length (car mapping)) 5)))
(not16bit? (lambda (mapping) (>= (string-length (car mapping)) 5)))
(simple-upcase-mappings-16bit
(filter is16bit? simple-upcase-mappings))
(simple-downcase-mappings-16bit
(filter is16bit? simple-downcase-mappings))
(simple-upcase-mappings-morebits
(filter not16bit? simple-upcase-mappings))
(simple-downcase-mappings-morebits
(filter not16bit? simple-downcase-mappings))
(special-case-mappings
(mysort
(lambda (x y) (<= (vector-ref x 0) (vector-ref y 0)))
(filter (lambda (x)
(or (< (vector-length x) 5)
(string-ci=? (vector-ref x 4) "Final_Sigma")
(string-ci=? (vector-ref x 4) "Not_Final_Sigma")))
(cons
; This is commented out within SpecialCasing.txt,
; but treating it as a special case simplifies the
; common case for string-downcase.
'#(#x03C3 "03C2" "03A3" "03A3" "Final_Sigma")
special-casing)))))
; Given a list of pairs of exact integers that map
; code points to code points, adds the difference
; between the two code points to the list of adjustments
; if it isn't there already.
(define (compute-distinct-adjustments! mappings)
(for-each (lambda (mapping)
(let ((adjustment (- (string->number
(string-append "#x" (cadr mapping)))
(string->number
(string-append "#x" (car mapping))))))
(if (not (memv adjustment adjustments))
(set! adjustments
(cons adjustment adjustments)))))
mappings))
; Given a 16-bit exact integer code point, returns its low 8 bits.
(define (lo-bits k) (remainder k 256))
; Given a 16-bit exact integer code point, returns its high 8 bits.
(define (hi-bits k) (quotient k 256))
; Display definition of the str procedure, which is used to
; initialize the tables for special case mappings.
(define (display-str)
(display " (let ((str (lambda args" out)
(newline out)
(display " (if (= 1 (length args))" out)
(newline out)
(display " (integer->char (car args))" out)
(newline out)
(display " (apply string (map integer->char args))))))"
out)
(newline out))
; Compute all adjustments that are used for simple case mappings.
(compute-distinct-adjustments! simple-downcase-mappings)
(set! adjustments (map - adjustments))
(compute-distinct-adjustments! simple-upcase-mappings)
; Make sure we can represent an adjustment by a single byte.
(if (>= (length adjustments) 256)
(error "Too many simple case adjustments."))
(set! adjustments (mysort <= adjustments))
(set! adjustments-vector (list->vector adjustments))
(display "; This vector contains the numerical adjustments to make" out)
(newline out)
(display "; when converting a character from one case to another." out)
(newline out)
(display "; For conversions to uppercase or titlecase, add the" out)
(newline out)
(display "; adjustment contained in this vector." out)
(newline out)
(display "; For conversions to lowercase, subtract the adjustment" out)
(newline out)
(display "; contained in this vector." out)
(newline out)
(display ";" out)
(newline out)
(display "; This table contains " out)
(display (length adjustments) out)
(display " elements." out)
(newline out)
(newline out)
(display "(define simple-case-adjustments" out)
(newline out)
(display " '#(" out)
(do ((adjustments adjustments (cdr adjustments))
(n 0 (+ n 1)))
((null? adjustments))
(if (zero? (modulo n 8))
(begin (newline out) (display " " out)))
(display "#x" out)
(display (number->string (car adjustments) 16) out)
(display " " out))
(display "))" out)
(newline out)
(newline out)
(display "; This bytevector uses two bytes per code point" out)
(newline out)
(display "; to list all 16-bit code points, in increasing order," out)
(newline out)
(display "; that have a simple uppercase mapping." out)
(newline out)
(display ";" out)
(newline out)
(display "; This table contains " out)
(display (* 2 (length simple-upcase-mappings-16bit)) out)
(display " elements." out)
(newline out)
(newline out)
(display "(define simple-upcase-chars-16bit" out)
(newline out)
(display " '#vu8(" out)
(do ((mappings simple-upcase-mappings-16bit
(cdr mappings))
(n 0 (+ n 1)))
((null? mappings))
(if (zero? (modulo n 4))
(begin (newline out) (display " " out)))
(let* ((cp0 (string->number (string-append "#x" (car (car mappings)))))
(cp0-hi (number->string (hi-bits cp0) 16))
(cp0-lo (number->string (lo-bits cp0) 16)))
(display "#x" out)
(display cp0-hi out)
(display " #x" out)
(display cp0-lo out)
(display " " out)))
(display "))" out)
(newline out)
(newline out)
(display "; This vector contains all other code points," out)
(newline out)
(display "; in increasing order, that have a simple" out)
(newline out)
(display "; uppercase mapping." out)
(newline out)
(display ";" out)
(newline out)
(display "; This table contains " out)
(display (length simple-upcase-mappings-morebits) out)
(display " elements." out)
(newline out)
(newline out)
(display "(define simple-upcase-chars-morebits" out)
(newline out)
(display " '#(" out)
(do ((mappings simple-upcase-mappings-morebits
(cdr mappings))
(n 0 (+ n 1)))
((null? mappings))
(if (zero? (modulo n 8))
(begin (newline out) (display " " out)))
(display "#x" out)
(display (car (car mappings)) out)
(display " " out))
(display "))" out)
(newline out)
(newline out)
(display "; This bytevector uses two bytes per code point" out)
(newline out)
(display "; to list all 16-bit code points, in increasing order," out)
(newline out)
(display "; that have a simple lowercase mapping." out)
(newline out)
(display ";" out)
(newline out)
(display "; This table contains " out)
(display (* 2 (length simple-downcase-mappings-16bit)) out)
(display " elements." out)
(newline out)
(newline out)
(display "(define simple-downcase-chars-16bit" out)
(newline out)
(display " '#vu8(" out)
(do ((mappings simple-downcase-mappings-16bit
(cdr mappings))
(n 0 (+ n 1)))
((null? mappings))
(if (zero? (modulo n 4))
(begin (newline out) (display " " out)))
(let* ((cp0 (string->number (string-append "#x" (car (car mappings)))))
(cp0-hi (number->string (hi-bits cp0) 16))
(cp0-lo (number->string (lo-bits cp0) 16)))
(display "#x" out)
(display cp0-hi out)
(display " #x" out)
(display cp0-lo out)
(display " " out)))
(display "))" out)
(newline out)
(newline out)
(display "; This vector contains all other code points," out)
(newline out)
(display "; in increasing order, that have a simple" out)
(newline out)
(display "; lowercase mapping." out)
(newline out)
(display ";" out)
(newline out)
(display "; This table contains " out)
(display (length simple-downcase-mappings-morebits) out)
(display " elements." out)
(newline out)
(newline out)
(display "(define simple-downcase-chars-morebits" out)
(newline out)
(display " '#(" out)
(do ((mappings simple-downcase-mappings-morebits
(cdr mappings))
(n 0 (+ n 1)))
((null? mappings))
(if (zero? (modulo n 8))
(begin (newline out) (display " " out)))
(display "#x" out)
(display (car (car mappings)) out)
(display " " out))
(display "))" out)
(newline out)
(newline out)
(display "; The bytes of this bytevector are indexes into" out)
(newline out)
(display "; the simple-case-adjustments vector, and correspond" out)
(newline out)
(display "; to the code points in simple-upcase-chars-16bit" out)
(newline out)
(display "; followed by those in simple-upcase-chars-morebits." out)
(newline out)
(display ";" out)
(newline out)
(display "; This table contains " out)
(display (length simple-upcase-mappings) out)
(display " elements." out)
(newline out)
(newline out)
(display "(define simple-upcase-adjustments" out)
(newline out)
(display " '#vu8(" out)
(do ((mappings simple-upcase-mappings
(cdr mappings))
(n 0 (+ n 1)))
((null? mappings))
(if (zero? (modulo n 8))
(begin (newline out) (display " " out)))
(let* ((mapping (car mappings))
(cp0 (string->number (string-append "#x" (car mapping))))
(cp1 (string->number (string-append "#x" (cadr mapping))))
(i (binary-search-of-vector (- cp1 cp0) adjustments-vector)))
(display "#x" out)
(display (number->string i 16) out)
(display " " out)))
(display "))" out)
(newline out)
(newline out)
(display "; The bytes of this bytevector are indexes into" out)
(newline out)
(display "; the simple-case-adjustments vector, and correspond" out)
(newline out)
(display "; to the code points in simple-downcase-chars-16bit" out)
(newline out)
(display "; followed by those in simple-downcase-chars-morebits." out)
(newline out)
(display ";" out)
(newline out)
(display "; This table contains " out)
(display (length simple-downcase-mappings) out)
(display " elements." out)
(newline out)
(newline out)
(display "(define simple-downcase-adjustments" out)
(newline out)
(display " '#vu8(" out)
(do ((mappings simple-downcase-mappings
(cdr mappings))
(n 0 (+ n 1)))
((null? mappings))
(if (zero? (modulo n 8))
(begin (newline out) (display " " out)))
(let* ((mapping (car mappings))
(cp0 (string->number (string-append "#x" (car mapping))))
(cp1 (string->number (string-append "#x" (cadr mapping))))
(i (binary-search-of-vector (- cp0 cp1) adjustments-vector)))
(display "#x" out)
(display (number->string i 16) out)
(display " " out)))
(display "))" out)
(newline out)
(newline out)))
(define (write-special-casing-tables out)
(let* ((special-case-mappings
(mysort
(lambda (x y) (<= (vector-ref x 0) (vector-ref y 0)))
(filter (lambda (x)
(or (< (vector-length x) 5)
(string-ci=? (vector-ref x 4) "Final_Sigma")
(string-ci=? (vector-ref x 4) "Not_Final_Sigma")))
(cons
; This is commented out within SpecialCasing.txt,
; but treating it as a special case simplifies the
; common case for string-downcase.
'#(#x03C3 "03C2" "03A3" "03A3" "Final_Sigma")
special-casing)))))
(display "; This bytevector uses two bytes per code point" out)
(newline out)
(display "; to list 16-bit code points, in increasing order," out)
(newline out)
(display "; that have anything other than a simple case mapping." out)
(newline out)
(display ";" out)
(newline out)
(display "; The locale-dependent mappings are not in this table." out)
(newline out)
(display ";" out)
(newline out)
(display "; This table contains " out)
(display (* 2 (length special-case-mappings)) out)
(display " elements." out)
(newline out)
(newline out)
(display "(define special-case-chars" out)
(newline out)
(display " '#vu8(" out)
(do ((mappings special-case-mappings
(cdr mappings))
(n 0 (+ n 1)))
((null? mappings))
(if (zero? (modulo n 4))
(begin (newline out) (display " " out)))
(let* ((cp0 (vector-ref (car mappings) 0))
(cp0-hi (number->string (hi-bits cp0) 16))
(cp0-lo (number->string (lo-bits cp0) 16)))
(display "#x" out)
(display cp0-hi out)
(display " #x" out)
(display cp0-lo out)
(display " " out)))
(display "))" out)
(newline out)
(newline out)
(display "; Each code point in special-case-chars maps to the" out)
(newline out)
(display "; character or string contained in the following tables." out)
(newline out)
(display ";" out)
(newline out)
(display "; Each of these tables contains " out)
(display (length special-case-mappings) out)
(display " elements, not counting" out)
(newline out)
(display "; the strings that are the elements themselves." out)
(newline out)
(newline out)
(display "(define special-lowercase-mapping" out)
(newline out)
(display-str)
(display " (vector" out)
(newline out)
(for-each (lambda (mapping)
(let ((code-points
(parse-code-points (vector-ref mapping 1))))
(display " (str" out)
(for-each (lambda (cp)
(display " #x" out)
(display (number->string cp 16) out))
code-points)
(display ")" out)
(newline out)))
special-case-mappings)
(display ")))" out)
(newline out)
(newline out)
(display "(define special-titlecase-mapping" out)
(newline out)
(display-str)
(display " (vector" out)
(newline out)
(for-each (lambda (mapping)
(let ((code-points
(parse-code-points (vector-ref mapping 2))))
(display " (str" out)
(for-each (lambda (cp)
(display " #x" out)
(display (number->string cp 16) out))
code-points)
(display ")" out)
(newline out)))
special-case-mappings)
(display ")))" out)
(newline out)
(newline out)
(display "(define special-uppercase-mapping" out)
(newline out)
(display-str)
(display " (vector" out)
(newline out)
(for-each (lambda (mapping)
(let ((code-points
(parse-code-points (vector-ref mapping 3))))
(display " (str" out)
(for-each (lambda (cp)
(display " #x" out)
(display (number->string cp 16) out))
code-points)
(display ")" out)
(newline out)))
special-case-mappings)
(display ")))" out)
(newline out)
(newline out)
(unspecified)))
(define (write-normalization-tables out)
; Just a simple insertion sort on lists.
(define (mysort <= xs)
(define (insert x xs)
(if (or (null? xs)
(<= x (car xs)))
(cons x xs)
(cons (car xs)
(insert x (cdr xs)))))
(define (sort xs)
(if (null? xs)
'()
(insert (car xs)
(sort (cdr xs)))))
(sort xs))
(let* ((combining-class-mappings (extract-combining-classes))
(decomposition-mappings (extract-decomposition-types))
(decomposition-mappings-16bit
(filter (lambda (mapping)
(< (string-length (car mapping)) 5))
decomposition-mappings))
(decomposition-mappings-morebits
(filter (lambda (mapping)
(>= (string-length (car mapping)) 5))
decomposition-mappings))
(decomposition-mappings-sequences
(apply append
(map parse-code-points-maybe-tagged
(map cadr decomposition-mappings))))
(canonical-compositions (extract-canonical-compositions))
(hex2num (lambda (s) (string->number (string-append "#x" s))))
(compositions
(map (lambda (composition)
(list (hex2num (car composition))
(list (hex2num (substring (cadr composition) 0 4))
(hex2num (substring (cadr composition) 5 9)))))
canonical-compositions))
(mappings (map (lambda (x) (list (cadr x) (car x))) compositions))
(ignored
(for-each (lambda (mapping)
(if (or (not (= 2 (length (car mapping))))
(not (<= 0 (caar mapping) 65536))
(not (<= 0 (cadar mapping) 65536))
(not (<= 0 (cadr mapping) 65536)))
(error "Unexpectedly complex canonical composition: "
mapping)))
mappings))
(modifiers (mysort >= (map cadar mappings)))
(modifiers (do ((modifiers modifiers (cdr modifiers))
(unique '()
(if (and (not (null? (cdr modifiers)))
(= (car modifiers) (cadr modifiers)))
unique
(cons (car modifiers) unique))))
((null? modifiers)
unique)))
(two-level (map (lambda (modifier)
(filter (lambda (mapping)
(= modifier (cadar mapping)))
mappings))
modifiers)))
; Given a 16-bit exact integer code point, returns its low 8 bits.
(define (lo-bits k) (remainder k 256))
; Given a 16-bit exact integer code point, returns its high 8 bits.
(define (hi-bits k) (quotient k 256))
(display "; This vector contains all code points," out)
(newline out)
(display "; in increasing order, that have a nonzero" out)
(newline out)
(display "; combining class." out)
(newline out)
(display ";" out)
(newline out)
(display "; This table contains " out)
(display (length combining-class-mappings) out)
(display " elements." out)
(newline out)
(newline out)
(display "(define combining-class-is-nonzero" out)
(newline out)
(display " '#(" out)
(do ((mappings combining-class-mappings
(cdr mappings))
(n 0 (+ n 1)))
((null? mappings))
(if (zero? (modulo n 8))
(begin (newline out) (display " " out)))
(display "#x" out)
(display (car (car mappings)) out)
(display " " out))
(display "))" out)
(newline out)
(newline out)
(display "; This bytevector contains the combining classes" out)
(newline out)
(display "; for the code points in the above vector." out)
(newline out)
(display ";" out)
(newline out)
(display "; This table contains " out)
(display (length combining-class-mappings) out)
(display " elements." out)
(newline out)
(newline out)
(display "(define combining-class-values" out)
(newline out)
(display " '#vu8(" out)
(do ((mappings combining-class-mappings
(cdr mappings))
(n 0 (+ n 1)))
((null? mappings))
(if (zero? (modulo n 8))
(begin (newline out) (display " " out)))
(display (cadr (car mappings)) out)
(display " " out))
(display "))" out)
(newline out)
(newline out)
(display "; This bytevector uses two bytes per code point" out)
(newline out)
(display "; to list 16-bit code points, in increasing order," out)
(newline out)
(display "; that have a canonical or compatibility decomposition." out)
(newline out)
(display ";" out)
(newline out)
(display "; This table contains " out)
(display (* 2 (length decomposition-mappings-16bit)) out)
(display " elements." out)
(newline out)
(newline out)
(display "(define decomposition-chars-16bit" out)
(newline out)
(display " '#vu8(" out)
(do ((mappings decomposition-mappings-16bit
(cdr mappings))
(n 0 (+ n 1)))
((null? mappings))
(if (zero? (modulo n 4))
(begin (newline out) (display " " out)))
(let* ((cp0 (string->number (string-append "#x" (car (car mappings)))))
(cp0-hi (number->string (hi-bits cp0) 16))
(cp0-lo (number->string (lo-bits cp0) 16)))
(display "#x" out)
(display cp0-hi out)
(display " #x" out)
(display cp0-lo out)
(display " " out)))
(display "))" out)
(newline out)
(newline out)
(display "; This vector contains all other code points," out)
(newline out)
(display "; in increasing order, that have a canonical" out)
(newline out)
(display "; or compatibility decomposition." out)
(newline out)
(display ";" out)
(newline out)
(display "; This table contains " out)
(display (length decomposition-mappings-morebits) out)
(display " elements." out)
(newline out)
(newline out)
(display "(define decomposition-chars-morebits" out)
(newline out)
(display " '#(" out)
(do ((mappings decomposition-mappings-morebits
(cdr mappings))
(n 0 (+ n 1)))
((null? mappings))
(if (zero? (modulo n 8))
(begin (newline out) (display " " out)))
(display "#x" out)
(display (car (car mappings)) out)
(display " " out))
(display "))" out)
(newline out)
(newline out)
(display "; This bytevector uses two bytes per index to list" out)
(newline out)
(display "; the starting indexes into decomposition-sequences" out)
(newline out)
(display "; of the canonical or compatibility decompositions" out)
(newline out)
(display "; for the code points in the above two tables." out)
(newline out)
(display "; If the index is for a compatibility decomposition," out)
(newline out)
(display "; then the high-order bit of the high-order (first)" out)
(newline out)
(display "; byte is set." out)
(newline out)
(display ";" out)
(newline out)
(display "; This table contains " out)
(display (* 2 (+ 1 (length decomposition-mappings))) out)
(display " elements." out)
(newline out)
(newline out)
(display "(define decomposition-indexes" out)
(newline out)
(display " '#vu8(" out)
(do ((mappings decomposition-mappings
(cdr mappings))
(n 0 (+ n 1))
(i 0 (+ i (length (parse-code-points-maybe-tagged
(cadr (car mappings)))))))
((null? mappings))
(if (zero? (modulo n 4))
(begin (newline out) (display " " out)))
(let* ((code-points-as-string (cadr (car mappings)))
(index (if (char=? #\< (string-ref code-points-as-string 0))
(+ i 32768)
i))
(index-hi (number->string (hi-bits index) 16))
(index-lo (number->string (lo-bits index) 16)))
(display "#x" out)
(display index-hi out)
(display " #x" out)
(display index-lo out)
(display " " out)))
(let* ((index (length decomposition-mappings-sequences))
(index-hi (number->string (hi-bits index) 16))
(index-lo (number->string (lo-bits index) 16)))
(display "#x" out)
(display index-hi out)
(display " #x" out)
(display index-lo out))
(display "))" out)
(newline out)
(newline out)
(display "; This vector contains sequences of code points" out)
(newline out)
(display "; for canonical and compatibility decompositions." out)
(newline out)
(display ";" out)
(newline out)
(display "; This table contains " out)
(display (length decomposition-mappings-sequences) out)
(display " elements." out)
(newline out)
(newline out)
(display "(define decomposition-sequences" out)
(newline out)
(display " '#(" out)
(do ((mappings decomposition-mappings-sequences
(cdr mappings))
(n 0 (+ n 1)))
((null? mappings))
(if (zero? (modulo n 8))
(begin (newline out) (display " " out)))
(display "#x" out)
(display (number->string (car mappings) 16) out)
(display " " out))
(display "))" out)
(newline out)
(newline out)
(display "; This bytevector contains all Unicode scalar values" out)
(newline out)
(display "; (with two bytes per scalar value, big-endian)" out)
(newline out)
(display "; that can compose with a previous scalar value" out)
(newline out)
(display "; under canonical composition." out)
(newline out)
(display ";" out)
(newline out)
(display "; This table contains " out)
(display (* 2 (length modifiers)) out)
(display " elements." out)
(newline out)
(newline out)
(display "(define composition-modifiers" out)
(newline out)
(display " '#vu8(" out)
(do ((mappings modifiers
(cdr mappings))
(n 0 (+ n 1)))
((null? mappings))
(if (zero? (modulo n 4))
(begin (newline out) (display " " out)))
(let* ((cp (car mappings))
(hi (number->string (hi-bits cp) 16))
(lo (number->string (lo-bits cp) 16)))
(display "#x" out)
(display hi out)
(display " #x" out)
(display lo out)
(display " " out)))
(display "))" out)
(newline out)
(newline out)
(display "; This vector encodes all canonical compositions." out)
(newline out)
(display "; Each element corresponds to the corresponding" out)
(newline out)
(display "; element of composition-modifiers, and consists" out)
(newline out)
(display "; of a list of two bytevectors." out)
(newline out)
(display "; The first bytevector contains the scalar values" out)
(newline out)
(display "; that, when followed by the corresponding modifier," out)
(newline out)
(display "; compose to form the corresponding scalar value" out)
(newline out)
(display "; in the second bytevector." out)
(newline out)
(display ";" out)
(newline out)
(display "; This table contains " out)
(display (length modifiers) out)
(display " elements." out)
(newline out)
(display "; The bytevectors within it contain " out)
(display (* 4 (length mappings)) out)
(display " elements." out)
(newline out)
(newline out)
(display "(define canonical-compositions" out)
(newline out)
(display " '#(" out)
(newline out)
(for-each (lambda (mappings0)
(define mappings
(mysort (lambda (mapping1 mapping2)
(<= (caar mapping1) (caar mapping2)))
mappings0))
(display " (#vu8(" out)
(do ((mappings (map caar mappings)
(cdr mappings))
(n 0 (+ n 1)))
((null? mappings))
(if (zero? (modulo n 4))
(begin (newline out) (display " " out)))
(let* ((cp (car mappings))
(hi (number->string (hi-bits cp) 16))
(lo (number->string (lo-bits cp) 16)))
(display "#x" out)
(display hi out)
(display " #x" out)
(display lo out)
(display " " out)))
(display ")" out)
(newline out)
(display " #vu8(" out)
(do ((mappings (map cadr mappings)
(cdr mappings))
(n 0 (+ n 1)))
((null? mappings))
(if (zero? (modulo n 4))
(begin (newline out) (display " " out)))
(let* ((cp (car mappings))
(hi (number->string (hi-bits cp) 16))
(lo (number->string (lo-bits cp) 16)))
(display "#x" out)
(display hi out)
(display " #x" out)
(display lo out)
(display " " out)))
(display "))" out)
(newline out))
two-level)
(display "))" out)
(newline out)
(newline out)
(unspecified)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; Utilities.
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Given an exact integer key and a vector of exact integers
; in strictly increasing order, returns the largest i such
; that element i of the vector is less than or equal to key,
; or -1 if key is less than every element of the vector.
(define (binary-search-of-vector key vec)
; Loop invariants:
; 0 <= i < j <= (vector-length vec)
; vec[i] <= key
; if j < (vector-length vec), then key < vec[j]
(define (loop i j)
(let ((mid (quotient (+ i j) 2)))
(cond ((= i mid)
mid)
((<= (vector-ref vec mid) key)
(loop mid j))
(else
(loop i mid)))))
(let ((hi (vector-length vec)))
(if (or (= hi 0) (< key (vector-ref vec 0)))
-1
(loop 0 hi))))
; Given a string of code points, in hex, separated by spaces,
; returns a list of code points as integers.
(define (parse-code-points s)
(let ((n (string-length s)))
; Returns a list of the code points at index i and following.
(define (loop i)
(cond ((= i n) '())
((char=? (string-ref s i) #\space)
(loop (+ i 1)))
(else
(let* ((j (next-terminator i))
(digits (substring s i j))
(cp (string->number (string-append "#x" digits))))
(cons cp (loop j))))))
; Returns the index of the next space, or end of string.
(define (next-terminator i)
(cond ((= i n) i)
((char=? (string-ref s i) #\space)
i)
(else
(next-terminator (+ i 1)))))
(loop 0)))
; Given a string of code points, in hex, separated by spaces,
; and possibly preceded by a tag within angle brackets,
; returns a list of code points as integers.
(define (parse-code-points-maybe-tagged s)
(if (or (zero? (string-length s))
(not (char=? #\< (string-ref s 0))))
(parse-code-points s)
(parse-code-points
(list->string (cdr (memv #\> (string->list s)))))))
| false |
289b8a3ff83268e7b990ddf1bada500bc4f2f578
|
f04768e1564b225dc8ffa58c37fe0213235efe5d
|
/Assignment3/3.ss
|
78b696670eefcde873168134b2e1ad558405f97a
|
[] |
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 | 2,864 |
ss
|
3.ss
|
;Francis Meng Assignment 3
;Question 1 Calculate the cross product of two vectors
(define cross-product
(lambda (v1 v2)
(cons (- (* (car (cdr v1)) (car (cddr v2)))
(* (car (cdr v2)) (car (cddr v1))))
(cons (- (* (car (cddr v1)) (car v2))
(* (car (cddr v2)) (car v1)))
(cons (- (* (car v1) (car (cdr v2)))
(* (car v2) (car (cdr v1)))) '()))
)
)
)
;Question 2 check if two given vectors are parallel
(define parallel?
(lambda (v1 v2)
(let ((factor (/ (car v2) (car v1))))
(if (equal? (* factor (car (cdr v1))) (car (cdr v2)))
(if (equal? (* factor (car (cddr v1))) (car (cddr v2))) #t #f)
#f
)
)
)
)
;Question 3 check if three given points are collinear
(define (collinear? p1 p2 p3)
(let ((v1 (make-vec-from-points p1 p2))
(v2 (make-vec-from-points p1 p3)))
(parallel? v1 v2))
)
(define make-vec-from-points
(lambda (p1 p2)
(if (equal? p1 '()) '()
(cons (- (car p2) (car p1)) (make-vec-from-points (cdr p1) (cdr p2)))
)
)
)
;Question 4 find the nearest point in the list to the given point
(define (nearest-point p list-of-points)
(if (equal? (cdr list-of-points) '())
(car list-of-points)
(if (> (distance p (car list-of-points)) (distance p (car (cdr list-of-points))))
(nearest-point p (cdr list-of-points))
(nearest-point p (cons (car list-of-points) (cddr list-of-points))))))
(define distance
(lambda (p1 p2)
(if (equal? p1 p2) 0 (vec-length (make-vec-from-points p1 p2)))
)
)
(define vec-length
(lambda (v) (sqrt (sum-of-squares v)))
)
(define sum-of-squares
(lambda (lon)
(if (equal? lon '()) 0 (+ (* (car lon) (car lon)) (sum-of-squares (cdr lon))))
)
)
;Question 5 find the intersection of two set
(define (intersection s1 s2)
(if (equal? s1 '())
'()
(if (member (car s1) s2)
(cons (car s1) (intersection (cdr s1) s2))
(intersection (cdr s1) s2)))
)
;Question 6 determine if the first set is a subset of the second set
(define (subset? s1 s2)
(if (equal? s1 '())
#t
(if (member (car s1) s2)
(subset? (cdr s1) s2)
#f)))
;Question 7 determine if the given set is a relation;
(define (relation? obj)
(if (set? obj)
(checkRelation obj)
#f)
)
(define (checkRelation obj)
(if (equal? obj '())
#t
(if (list? (car obj))
(if (equal? (length (car obj)) 2)
(checkRelation (cdr obj))
#f)
#f)
)
)
(define set?
(lambda (li)
(if (list? li)
(if (equal? li '()) #t
(if (equal? (cdr li) '()) #t
(if (member (car li) (cdr li)) #f (set? (cdr li)))
)
)
#f)
)
)
;Question 8 determine the domain of the given relation
(define (domain r)
(if (equal? r '())
'()
(if (member (car (car r)) (domain (cdr r)))
(domain (cdr r))
(cons (car (car r)) (domain (cdr r)))))
)
| false |
e409d8ef19df67312b7412efbfd080d2ddc366db
|
98867a6625fc664d0dafa0668dc8f1d507a071e2
|
/scheme/shooter/level.scm
|
cf205c5f86456eb3b3da4bf98fb99af4c2ecf2b8
|
[
"ISC"
] |
permissive
|
tekktonic/programming
|
4b81efc115108bfdfc4a70a0d3b9157c1b91c8c0
|
139959ab9934912d4c531e5ee8b1f39094a6823c
|
refs/heads/master
| 2021-05-11T03:24:47.507478 | 2018-01-18T01:16:38 | 2018-01-18T01:16:38 | 80,262,894 | 0 | 0 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 94 |
scm
|
level.scm
|
(require entity)
(define load-level (lambda (level)
(load (string-append level ".lvl"))))
| false |
05bcba5a84cdc4a336d2e3e22712dc5515ac355c
|
011403dac0afe1b4b143c6c5c39d12f1cbe10c97
|
/ag-test.scm
|
7b895cb236050ec0053114cf0791d781d453c093
|
[
"X11",
"MIT"
] |
permissive
|
rene-schoene/racr-mquat
|
7494b9a0c3c2715a6806c34e21cb9ea4931c9896
|
5f985816cadd556d7636a74bea0a5d5b1d95f9ee
|
refs/heads/master
| 2021-01-19T03:14:17.996513 | 2016-07-21T17:31:06 | 2016-07-21T17:31:06 | 53,142,033 | 0 | 0 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 653 |
scm
|
ag-test.scm
|
#!r6rs
; This program and the accompanying materials are made available under the
; terms of the MIT license (X11 license) which accompanies this distribution.
; Author: R. Schöne
(library
(mquat ag-test)
(export do-it)
(import (rnrs) (racr core) (racr testing)
(mquat utils) (mquat ilp) (mquat join) (mquat basic-ag) (mquat ast)
(mquat constants) (mquat ast-generation) (mquat ui))
;; Testing printing whole asts
;; num-pe=10, num-pe-subs=0, num-comp=3, impl-per-comp=4, mode-per-impl=5
(define (do-it . args)
(let ([ast (create-system 10 0 3 4 5)])
(display-ast ast 'remote-unit 'remote-container 'remote-impls))))
| false |
f1e267f5d2a7748d9278c2b6731e56f3ae089839
|
454658b48dc3695aeffa16d6330a444e5a6cd30d
|
/utils/jsonrpc.ss
|
c841a6b6885a3c0110371d9ce4f4ac7a5b13efb7
|
[
"MIT"
] |
permissive
|
Chream/chream-utils
|
2cd4cb31fc5f1876759d6a5f44a46e86b0401054
|
40320e5601cff0d26c9a37179fc8dc36de1adbef
|
refs/heads/master
| 2020-03-09T14:02:11.052386 | 2018-07-17T16:12:51 | 2018-07-17T16:12:51 | 128,825,406 | 1 | 0 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 1,854 |
ss
|
jsonrpc.ss
|
(import :gerbil/gambit/hash
"text/json"
"misc/repr"
"map/hash")
(export #t)
;; jsonrpc interface.
(defclass (jsonrpc-request jsonable) (id method params))
(defclass (jsonrpc-response jsonable) (id result error))
(defclass (jsonrpc-notification jsonable) (method params))
(defclass (jsonrpc-error jsonable) (code msg data))
(def error-codes
(let (table (make-hash-table))
;; Defined by JSON RPC
(hash-add! table 'parse-error -32700)
(hash-add! table 'InvalidRequest -32600)
(hash-add! table 'MethodNotFound -32601)
(hash-add! table 'InvalidParams -32602)
(hash-add! table 'InternalError -32603)
(hash-add! table 'serverErrorStart -32099)
(hash-add! table 'serverErrorEnd -32000)
(hash-add! table 'ServerNotInitialized -32002)
(hash-add! table 'UnknownErrorCode -32001)
table))
(defmethod {init! jsonrpc-error}
(lambda (self datum msg (data #f))
(jsonrpc-error-code-set! self (hash-get error-codes datum))
(jsonrpc-error-msg-set! self msg)
(jsonrpc-error-data-set! self data)))
(def (read-req port)
"Read a jsonrpc request from char port.
Return '`jsonrpc-request' object."
(let ((json (read-json port)))
(make-jsonrpc-request (json-get json 'id)
(json-get json 'method)
(json-get json 'params))))
(def (write-resp resp port)
"Write a jsonrpc response to char port.
Return positive integer of charactors written.
It will also pad the message with the jsonrpc
version."
(let* ((slots-plist (cddr (object->list resp)))
(slots-alist
(map (match <>
([k v] [k . v])
([] [jsonrpc: . "2.0"]) ; add version number
(v (error "Invalid plist." slots-plist)))
slots-plist)))
(write-json slots-alist port)))
| false |
234c1f9a9bcbad33fa58b24733e7eef325847eae
|
1b771524ff0a6fb71a8f1af8c7555e528a004b5e
|
/ex420.scm
|
8998e690590ab2f83450733ca606ac0624c817ff
|
[] |
no_license
|
yujiorama/sicp
|
6872f3e7ec4cf18ae62bb41f169dae50a2550972
|
d106005648b2710469067def5fefd44dae53ad58
|
refs/heads/master
| 2020-05-31T00:36:06.294314 | 2011-05-04T14:35:52 | 2011-05-04T14:35:52 | 315,072 | 0 | 0 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 1,368 |
scm
|
ex420.scm
|
;; letrec
;; (define (f x)
;; (letrec ((even?
;; (lambda (n)
;; (if (= n 0)
;; #t
;; (odd? (- n 1)))))
;; (odd?
;; (lambda (n)
;; (if (= n 0)
;; #f
;; (even? (- n 1)))))))
;; <f の本体の残り>)
;; (letrec ((<var1> <exp1>) ... (<varn> <expn>))
;; <body>)
;; (letrec ((fact
;; (lambda (n)
;; (if (= n 1)
;; 1
;; (* n (fact (- n 1)))))))
;; (fact 10))
;; a. letrec を let 式に変換する実装
(define (letrec->let exp)
(let ((vars (map car (cadr exp)))
(exps (map cdr (cadr exp)))
(body (cddr exp)))
(if (null? vars)
body
(append
(list 'let
(map (lambda (name) (list name '*unassigned*)) vars))
(append
(map (lambda (name body) (list 'set! name body)) vars exps)
body)))))
;; b. Louis の理解(手続きの内部で define が使いたくなければ let を使うことができる) は足りない。
;; f について、 (f 5) の評価の途中で <fの本体の残り> が評価される環境を示す環境ダイアグラムを描いて示せ。
;; 同じ評価で f の定義の letrec が let になった場合の環境ダイアグラムを描け。
| false |
f2946fb76e992dd11cb5846b20f3ef949215c4d1
|
4b5dddfd00099e79cff58fcc05465b2243161094
|
/chapter_4/exercise_4_69.scm
|
31b88a7411e6206010ee9b250fcc1de7181fc99a
|
[
"MIT"
] |
permissive
|
hjcapple/reading-sicp
|
c9b4ef99d75cc85b3758c269b246328122964edc
|
f54d54e4fc1448a8c52f0e4e07a7ff7356fc0bf0
|
refs/heads/master
| 2023-05-27T08:34:05.882703 | 2023-05-14T04:33:04 | 2023-05-14T04:33:04 | 198,552,668 | 269 | 41 |
MIT
| 2022-12-20T10:08:59 | 2019-07-24T03:37:47 |
Scheme
|
UTF-8
|
Scheme
| false | false | 1,546 |
scm
|
exercise_4_69.scm
|
#lang sicp
;; P324 - [练习 4.69]
(#%require "queryeval.scm")
(initialize-data-base
'(
(son Adam Cain) ; 表示 Adam 的儿子是 Cain
(son Cain Enoch)
(son Enoch Irad)
(son Irad Mehujael)
(son Mehujael Methushael)
(son Methushael Lamech)
(wife Lamech Ada)
(son Ada Jabal)
(son Ada Jubal)
(rule (grandson ?G ?S)
(and (son ?G ?F)
(son ?F ?S)))
(rule (son ?man ?son)
(and (wife ?man ?woman)
(son ?woman ?son)))
(rule (end-in-grandson (grandson)))
(rule (end-in-grandson (?x . ?rest))
(end-in-grandson ?rest))
(rule ((great grandson) ?x ?y)
(and (son ?x ?z)
(grandson ?z ?y)))
(rule ((great . ?rel) ?x ?y)
(and (son ?x ?z)
(?rel ?z ?y)
(end-in-grandson ?rel)))
))
(easy-qeval '((great grandson) ?g ?ggs))
;; ((great grandson) Mehujael Jubal)
;; ((great grandson) Irad Lamech)
;; ((great grandson) Mehujael Jabal)
;; ((great grandson) Enoch Methushael)
;; ((great grandson) Cain Mehujael)
;; ((great grandson) Adam Irad)
(easy-qeval '((great great grandson) ?g ?ggs))
;; ((great great grandson) Irad Jubal)
;; ((great great grandson) Enoch Lamech)
;; ((great great grandson) Irad Jabal)
;; ((great great grandson) Cain Methushael)
;; ((great great grandson) Adam Mehujael)
(easy-qeval '(?relationship Adam Irad))
;; ((great grandson) Adam Irad)
(easy-qeval '(?relationship Adam Jabal))
;; ((great great great great great grandson) Adam Jabal)
| false |
389f642dacef9c39bf1d7689f8a8b81a64045c7e
|
f4cf5bf3fb3c06b127dda5b5d479c74cecec9ce9
|
/Sources/LispKit/Resources/Libraries/srfi/227.sld
|
7d8b3db7d445b1448b3c93375715ca56b2390371
|
[
"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 | 1,589 |
sld
|
227.sld
|
;;; SRFI 227
;;; Optional Arguments
;;;
;;; This SRFI specifies the `opt-lambda` syntax, which generalizes `lambda`. An
;;; `opt-lambda` expression evaluates to a procedure that takes a number of
;;; required and a number of optional (positional) arguments whose default values
;;; are determined by evaluating corresponding expressions when the procedure is
;;; called. This SRFI also specifies a variation `opt*-lambda`, which is to
;;; `opt-lambda` as `let*` is to `let` and the related binding constructs
;;; `let-optionals` and `let-optionals*`. Finally, for those who prefer less explicit
;;; procedure definitions, `define-optionals` and `define-optionals*` are provided.
;;;
;;; Author of spec: Marc Nieper-Wißkirchen
;;;
;;; Copyright © 2021 Matthias Zenger. All rights reserved.
;;;
;;; Licensed under the Apache License, Version 2.0 (the "License"); you may not use
;;; this file except in compliance with the License. You may obtain a copy of the
;;; License at
;;;
;;; http://www.apache.org/licenses/LICENSE-2.0
;;;
;;; Unless required by applicable law or agreed to in writing, software distributed
;;; under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
;;; CONDITIONS OF ANY KIND, either express or implied. See the License for the
;;; specific language governing permissions and limitations under the License.
(define-library (srfi 227)
(export (rename let*-optionals let-optionals*)
let-optionals
opt-lambda
opt*-lambda
define-optionals
define-optionals*)
(import (lispkit base))
)
| false |
bceccb7ab720fd1fa0e513fb5849d0c222f19b30
|
c763eaf97ffd7226a70d2f9a77465cbeae8937a8
|
/scheme/contexts.scm
|
5767cabe6273559f18671892ebc5ba65cb03f912
|
[] |
no_license
|
jhidding/crossword
|
66907f12e87593a0b72f234ebfabbd2fb56dae9c
|
b3084b6b1046eb0a996143db1a144fd32379916f
|
refs/heads/master
| 2020-12-02T19:33:08.677722 | 2017-08-21T21:07:43 | 2017-08-21T21:07:43 | 96,357,240 | 1 | 0 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 2,140 |
scm
|
contexts.scm
|
(library (contexts)
(export with *enter* *exit* define-context)
(import (rnrs (6))
(gen-id)
(oop goops))
(define-generic *enter*)
(define-generic *exit*)
(define-method (*enter* (obj <top>))
obj)
(define-method (*exit* (obj <top>) (error <top>))
#f)
(define-syntax with
(syntax-rules ()
((_ (<name> <obj>) <body> ...)
(let* ((<name> <obj>))
(*enter* <name>)
(guard (x ((error? x) (*exit* <name> x)))
<body> ...
(*exit* <name> #f))))))
(define-syntax define-context
(lambda (x)
(syntax-case x (fields)
[(define-context <name> (fields <f> ...) <args> ...)
(with-syntax ([with-record (gen-id #'<name> "with-" #'<name>)]
[update-record (gen-id #'<name> "update-" #'<name>)]
[make-record (gen-id #'<name> "make-" #'<name>)]
; Define the names of member access functions.
[(access ...) (map (lambda (x)
(gen-id x #'<name> "-" x))
#'(<f> ...))])
#'(begin
(define-record-type <name> (fields <f> ...) <args> ...)
(define-syntax with-record
(lambda (x)
(syntax-case x ()
[(with-record <r> <expr> (... ...))
(with-syntax ([<f> (datum->syntax #'with-record '<f>)]
...)
#'(let ([<f> (access <r>)] ...)
<expr> (... ...)))])))
(define-syntax update-record
(lambda (x)
(syntax-case x ()
[(update-record <r> <bindings> (... ...))
(with-syntax ([<f> (datum->syntax #'update-record '<f>)]
...)
#'(let ([<f> (access <r>)] ...)
(let (<bindings> (... ...))
(make-record <f> ...))))])))
))])))
)
| true |
655d28e917a9eb32cca32df96fa032192e07f28d
|
defeada37d39bca09ef76f66f38683754c0a6aa0
|
/mscorlib/system/reflection/emit/dynamic-ilinfo.sls
|
a67eefa2104f5c7db32de3155ad540acb1db5e0d
|
[] |
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,548 |
sls
|
dynamic-ilinfo.sls
|
(library (system reflection emit dynamic-ilinfo)
(export is?
dynamic-ilinfo?
set-exceptions
get-token-for
set-local-signature
set-code
dynamic-method)
(import (ironscheme-clr-port))
(define (is? a) (clr-is System.Reflection.Emit.DynamicILInfo a))
(define (dynamic-ilinfo? a)
(clr-is System.Reflection.Emit.DynamicILInfo a))
(define-method-port
set-exceptions
System.Reflection.Emit.DynamicILInfo
SetExceptions
(System.Void System.Byte* System.Int32)
(System.Void System.Byte[]))
(define-method-port
get-token-for
System.Reflection.Emit.DynamicILInfo
GetTokenFor
(System.Int32 System.RuntimeMethodHandle System.RuntimeTypeHandle)
(System.Int32 System.String)
(System.Int32 System.RuntimeTypeHandle)
(System.Int32 System.RuntimeMethodHandle)
(System.Int32 System.RuntimeFieldHandle)
(System.Int32 System.Reflection.Emit.DynamicMethod)
(System.Int32 System.Byte[]))
(define-method-port
set-local-signature
System.Reflection.Emit.DynamicILInfo
SetLocalSignature
(System.Void System.Byte* System.Int32)
(System.Void System.Byte[]))
(define-method-port
set-code
System.Reflection.Emit.DynamicILInfo
SetCode
(System.Void System.Byte* System.Int32 System.Int32)
(System.Void System.Byte[] System.Int32))
(define-field-port
dynamic-method
#f
#f
(property:)
System.Reflection.Emit.DynamicILInfo
DynamicMethod
System.Reflection.Emit.DynamicMethod))
| false |
5473563d455c060084fb17116424750d07c33563
|
660d4aad58a5dd8a304ead443a4f915b0047a579
|
/repl.scm
|
ebab760e46b61e58c1fdfb46e59363223519ec96
|
[] |
no_license
|
prophet-on-that/sicp
|
d9642ceebb8e885d85053ceba930282f30100879
|
cdb742646464f21a3c1c27c753d35f20cf0e754d
|
refs/heads/master
| 2021-07-05T12:53:14.263137 | 2020-08-21T08:20:27 | 2020-08-21T08:20:27 | 162,593,828 | 0 | 0 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 925 |
scm
|
repl.scm
|
(define-module (sicp repl))
(use-modules (sicp interpreter)
(sicp eval-utils))
(define input-prompt ";;; L-Eval input:")
(define output-prompt ";;; L-Eval value:")
(define* (driver-loop #:key (force-print? #t) (max-print-depth user-render-default-max-depth))
(define (helper)
(prompt-for-input input-prompt)
(let ((input (read)))
(let ((output (actual-value input the-global-environment)))
(announce-output output-prompt)
(display (user-render output #:force? force-print? #:max-depth max-print-depth))))
(helper))
(helper))
(define (announce-output string)
(newline)
(display string)
(newline))
(define the-global-environment (setup-environment))
(map (lambda (exp)
(eval exp the-global-environment))
'((define (null? l)
(eq? l '()))
(define (length l)
(if (null? l)
0
(+ 1 (length (cdr l)))))))
| false |
e29f08803c14b5e8f44667662b1227bfbe9761b1
|
ee232691dcbaededacb0778247f895af992442dd
|
/kirjasto/lib/kaava/emacs.scm
|
be0d4e1ee1d98055fc795ef415d2061aa2a2d4c6
|
[] |
no_license
|
mytoh/panna
|
c68ac6c6ef6a6fe79559e568d7a8262a7d626f9f
|
c6a193085117d12a2ddf26090cacb1c434e3ebf9
|
refs/heads/master
| 2020-05-17T02:45:56.542815 | 2013-02-13T19:18:38 | 2013-02-13T19:18:38 | null | 0 | 0 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 454 |
scm
|
emacs.scm
|
;; -*- coding: utf-8 -*-
(use panna.kaava)
(kaava "emacs")
(homepage "gnu.org/s/emacs")
(repository "git://git.savannah.gnu.org/emacs.git")
(define (install tynnyri)
(system
'("./autogen.sh")
`("./configure" "-with-x-toolkit=gtk3" "--without-selinux" "--with-x" "--without-xaw3d" "--without-compress-info" "-with-wide-int" ,(string-append "--prefix=" tynnyri))
'(gmake -j4)
'(gmake install)
'(gmake clean)
'(gmake distclean)
))
| false |
9f9c5c16adc2478726de7ba6e940a337951c2085
|
e8e2b3f22c7e1921e99f44593fc0ba5e5e44eebb
|
/PortableApps/GnuCashPortable/App/GnuCash/share/gnucash/scm/gnucash/report/standard-reports/budget-flow.scm
|
fab3b28f0d2e54b02fbbb1468aa899644e4cc849
|
[] |
no_license
|
314pi/PortableOffice
|
da262df5eaca240a00921e8348d366efa426ae57
|
08a5e828b35ff3cade7c56d101d7f6712b19a308
|
refs/heads/master
| 2022-11-25T19:20:33.942725 | 2018-05-11T07:49:35 | 2018-05-11T07:49:35 | 132,839,264 | 1 | 2 | null | 2022-11-02T22:19:00 | 2018-05-10T02:42:46 |
Python
|
UTF-8
|
Scheme
| false | false | 11,601 |
scm
|
budget-flow.scm
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; budget.scm: budget report
;;
;; (C) 2005 by Chris Shoemaker <[email protected]>
;;
;; based on cash-flow.scm by:
;; Herbert Thoma <[email protected]>
;;
;; This program is free software; you can redistribute it and/or
;; modify it under the terms of the GNU General Public License as
;; published by the Free Software Foundation; either version 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, contact:
;;
;; Free Software Foundation Voice: +1-617-542-5942
;; 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652
;; Boston, MA 02110-1301, USA [email protected]
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(define-module (gnucash report standard-reports budget-flow))
(use-modules (gnucash main)) ;; FIXME: delete after we finish modularizing.
(use-modules (gnucash gnc-module))
(use-modules (gnucash gettext))
(use-modules (gnucash printf))
(gnc:module-load "gnucash/report/report-system" 0)
(gnc:module-load "gnucash/gnome-utils" 0) ;for gnc-build-url
(define reportname (N_ "Budget Flow"))
;; define all option's names so that they are properly defined
;; in *one* place.
(define optname-accounts (N_ "Account"))
(define optname-price-source (N_ "Price Source"))
(define optname-budget (N_ "Budget"))
(define optname-periods (N_ "Period"))
(define optname-report-currency (N_ "Report's currency"))
;; options generator
(define (budget-report-options-generator)
(let ((options (gnc:new-options)))
;; Option to select Budget
(gnc:register-option
options
(gnc:make-budget-option
gnc:pagename-general optname-budget
"a" (N_ "Budget to use.")))
;; Option to select Period of selected Budget
(gnc:register-option
options
(gnc:make-number-range-option
gnc:pagename-general optname-periods
;; FIXME: It would be nice if the max number of budget periods (60) was
;; defined globally somewhere so we could reference it here. However, it
;; only appears to be defined currently in
;; src/gnome/gtkbuilder/gnc-plugin-page-budget.glade.
;; FIXME: It would be even nicer if the max number of budget
;; periods was determined by the number of periods in the
;; currently selected budget
"b" (N_ "Period number.") 1 1 60 0 1))
;; Option to select the currency the report will be shown in
(gnc:options-add-currency!
options gnc:pagename-general
optname-report-currency "d")
;; Option to select the price source used in currency conversion
(gnc:options-add-price-source!
options gnc:pagename-general optname-price-source "c" 'pricedb-latest)
;;Option to select the accounts to that will be displayed
(gnc:register-option
options
(gnc:make-account-list-option
gnc:pagename-accounts optname-accounts
(string-append "a" "c")
(N_ "Report on these accounts.")
(lambda ()
(gnc-account-get-descendants-sorted (gnc-get-current-root-account)))
#f #t))
;; Set the general page as default option tab
(gnc:options-set-default-section options gnc:pagename-general)
options
))
;; Append a row to html-table with markup and values
(define (gnc:html-table-add-budget-row!
html-table markup text total1 total2)
;; Cell order is text, budgeted, actual
(gnc:html-table-append-row/markup! html-table "normal-row"
(list
(gnc:make-html-table-cell/markup "text-cell" text)
(gnc:make-html-table-cell/markup markup total1)
(gnc:make-html-table-cell/markup markup total2)
)))
;; For each account in acct-table:
;; Retrieve the budgeted and actual amount
;; Display the row
;;
;; Display the grand total for acct-table
;;
;; Return: (list budgeted-grand-total actual-grand-total)
;;
(define (gnc:html-table-add-budget-accounts!
html-table acct-table budget period exchange-fn report-currency)
(let* (
;; Used to sum up the budgeted and actual totals
(bgt-total (gnc:make-commodity-collector))
(act-total (gnc:make-commodity-collector))
)
;; Loop though each account
;;
;; FIXME: because gnc:budget-get-account-period-actual-value
;; sums the total for a parent and all child accounts displaying
;; and summing a parent account cause the totals to be off.
;; so we do not display parent accounts
;;
(for-each (lambda (acct)
;; If acct has children do nto display (see above)
(if (null? (gnc-account-get-children acct))
(let* (
;; Retrieve the budgeted and actual amount and convert to <gnc:monetary>
(comm (xaccAccountGetCommodity acct))
(bgt-numeric (gnc-budget-get-account-period-value budget acct (- period 1)))
(bgt-monetary (gnc:make-gnc-monetary comm bgt-numeric))
(act-numeric (gnc-budget-get-account-period-actual-value budget acct (- period 1)))
(act-monetary (gnc:make-gnc-monetary comm act-numeric))
)
;; Add amounts to collectors
(bgt-total 'add comm bgt-numeric)
(act-total 'add comm act-numeric)
;; Display row
(gnc:html-table-add-budget-row! html-table "number-cell"
(gnc:make-html-text (gnc:html-markup-anchor (gnc:account-anchor-text acct) (gnc-account-get-full-name acct)))
bgt-monetary
act-monetary
))))
acct-table
)
;; Total collectors and display
(let* (
(bgt-total-numeric (gnc:sum-collector-commodity bgt-total report-currency exchange-fn))
(act-total-numeric (gnc:sum-collector-commodity act-total report-currency exchange-fn))
)
(gnc:html-table-add-budget-row! html-table "total-number-cell" (string-append (_ "Total") ":") bgt-total-numeric act-total-numeric)
;; Display hr FIXME: kind of a hack
(gnc:html-table-append-row! html-table "<tr><td colspan='3'><hr></td></tr>")
;; Return (list budgeted-total actual-total)
(list bgt-total-numeric act-total-numeric)
))) ;; end of define
;; Displays account types
;;
;; acct-table: a list from gnc:decompose-accountlist
;;
;; Return: a assoc list of (type (budgeted-grand-total actual-grand-total))
;;
(define (gnc:html-table-add-budget-types!
html-table acct-table budget period exchange-fn report-currency)
;;Account totals is the assoc list that is returned
(let* ((accounts-totals '()))
;;Display each account type
(for-each (lambda (pair)
;; key - type
;; value - list of accounts
(let* ((key (car pair)) (value (cdr pair)))
;; Display and add totals
(set! accounts-totals (assoc-set! accounts-totals key
(gnc:html-table-add-budget-accounts! html-table value budget period exchange-fn report-currency)
))
))
acct-table
)
;; Reutrn assoc list
accounts-totals
))
;; Displays type-totals
;;
;; type-totals: a list of (type (budget-total actual-total))
;;
(define (gnc:html-table-add-budget-totals!
html-table type-totals exchange-fn report-currency)
(let* (
;; Collector of grand totals
(bgt-total-collector (gnc:make-commodity-collector))
(act-total-collector (gnc:make-commodity-collector))
)
;; Loop though each pair
(for-each (lambda (pair)
(let* (
;; tuple is (type (budgeted actual))
(key (car pair))
(value (cdr pair))
(bgt-total (car value))
(act-total (cadr value))
)
;; Add to collectors
(bgt-total-collector 'add (gnc:gnc-monetary-commodity bgt-total) (gnc:gnc-monetary-amount bgt-total))
(act-total-collector 'add (gnc:gnc-monetary-commodity act-total) (gnc:gnc-monetary-amount act-total))
;; Display row
(gnc:html-table-add-budget-row! html-table "number-cell" (gnc:account-get-type-string-plural key) bgt-total act-total)
))
type-totals
)
(let* (
;; Sum collectors
(bgt-total-numeric (gnc:sum-collector-commodity bgt-total-collector report-currency exchange-fn))
(act-total-numeric (gnc:sum-collector-commodity act-total-collector report-currency exchange-fn))
)
;; Display Grand Total
(gnc:html-table-add-budget-row! html-table "total-number-cell" (string-append (_ "Total") ":") bgt-total-numeric act-total-numeric)
)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; budget-renderer
;; set up the document and add the table
;;;;;;;;;;;;;;;;;;;;;;;;;;;
(define (budget-renderer report-obj)
;; Helper function retrieves options
(define (get-option pagename optname)
(gnc:option-value
(gnc:lookup-option
(gnc:report-options report-obj) pagename optname)))
;; Update progress bar
(gnc:report-starting reportname)
;; get all option's values
(let* (
(budget (get-option gnc:pagename-general optname-budget))
(budget-valid? (and budget (not (null? budget))))
(accounts (get-option gnc:pagename-accounts optname-accounts))
(period (inexact->exact (get-option gnc:pagename-general
optname-periods)))
(report-currency (get-option gnc:pagename-general
optname-report-currency))
(price-source (get-option gnc:pagename-general
optname-price-source))
;; calculate the exchange rates
(exchange-fn (gnc:case-exchange-fn
price-source report-currency #f))
;; The HTML document
(doc (gnc:make-html-document))
)
(cond
((null? accounts)
;; No accounts selected
(gnc:html-document-add-object!
doc
(gnc:html-make-no-account-warning
report-title (gnc:report-id report-obj))))
((not budget-valid?)
;; No budget selected.
(gnc:html-document-add-object!
doc (gnc:html-make-generic-budget-warning reportname)))
(else (begin
(let* (
(html-table (gnc:make-html-table))
(report-name (get-option gnc:pagename-general
gnc:optname-reportname))
;; decompose the account list
(split-up-accounts (gnc:decompose-accountlist accounts))
(accounts-totals '())
)
;; Display Title Name - Budget - Period
(gnc:html-document-set-title!
doc (sprintf #f (_ "%s: %s - %s")
report-name (gnc-budget-get-name budget)
(gnc-print-date (gnc-budget-get-period-start-date budget (- period 1)))))
;; Display accounts and totals
(set! accounts-totals (gnc:html-table-add-budget-types! html-table split-up-accounts budget period exchange-fn report-currency))
(gnc:html-table-add-budget-totals! html-table accounts-totals exchange-fn report-currency)
;; Display table
(gnc:html-document-add-object! doc html-table)))))
;; Update progress bar
(gnc:report-finished)
doc))
(gnc:define-report
'version 1
'name reportname
'report-guid "e6e34fa3b6e748debde3cb3bc76d3e53"
'menu-path (list gnc:menuname-budget)
'options-generator budget-report-options-generator
'renderer budget-renderer)
| false |
6d2f64af734908f2a41e7489bf5b684b5b343615
|
51d30de9d65cc3d5079f050de33d574584183039
|
/graph/identifier.scm
|
6a1ab2142f5a3a073a9af9b696d910582d41e045
|
[
"BSD-2-Clause",
"BSD-3-Clause"
] |
permissive
|
langmartin/ykk
|
30feb00265d603ef765b5c664d2f759be34b7b89
|
dd6e441dddd5b6363ee9adbbdd0f346c1522ffcf
|
refs/heads/master
| 2016-09-05T20:01:19.353224 | 2009-12-10T16:25:55 | 2009-12-10T16:25:55 | 408,478 | 0 | 1 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 429 |
scm
|
identifier.scm
|
;;; ; Identifiers
;; Identifiers are represented as symbols.
(define (uuidgen)
(concatenate-symbol
'u (uuidgen-v1->hex-string)))
(define (identifier foo)
(cond ((string? foo) (string->symbol foo))
((symbol? foo) foo)
(else (error 'bad-identifier
"an identifier must be a string or a symbol"
foo))))
(define identifier? symbol?)
(define new-identifier uuidgen)
| false |
0f2feaaee5b7368f566cac7e19e666ca5f0795ac
|
d8bdd07d7fff442a028ca9edbb4d66660621442d
|
/scam/tests/10-scheme/00-base/let/errors.scm
|
9c317962da5e8711ec1ac614b85e6fa236c1aaaa
|
[] |
no_license
|
xprime480/scam
|
0257dc2eae4aede8594b3a3adf0a109e230aae7d
|
a567d7a3a981979d929be53fce0a5fb5669ab294
|
refs/heads/master
| 2020-03-31T23:03:19.143250 | 2020-02-10T20:58:59 | 2020-02-10T20:58:59 | 152,641,151 | 0 | 0 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 607 |
scm
|
errors.scm
|
(import (test narc))
(narc-label "Let Errors")
(define-syntax master
(syntax-rules ()
((master f)
(narc-catch
(:args (f let))
(:args (f let*))
(:args (f letrec))))))
(define-syntax bad1
(syntax-rules ()
((test sym)
(sym x 2))))
(define-syntax bad2
(syntax-rules ()
((test sym)
(sym (3 2) "foo"))))
(define-syntax bad3
(syntax-rules ()
((test sym)
(sym ((3 2)) "foo"))))
(define-syntax bad4
(syntax-rules ()
((test sym)
(sym ((x)) "foo"))))
(master bad1)
(master bad2)
(master bad3)
(master bad4)
(narc-report)
| true |
71d5710902b66c8e45753a3ebdb54750e3ac98d2
|
557c51d080c302a65e6ef37beae7d9b2262d7f53
|
/workspace/comp-tester/tests2.ss
|
48afc7fe2d59be28bf00215c85b65a3a1637c76e
|
[] |
no_license
|
esaliya/SchemeStack
|
286a18a39d589773d33e628f81a23bcdd0fc667b
|
dcfa1bbfa63b928a7ea3fc244f305369763678ad
|
refs/heads/master
| 2020-12-24T16:24:08.591437 | 2016-03-08T15:30:37 | 2016-03-08T15:30:37 | 28,023,003 | 3 | 4 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 14,855 |
ss
|
tests2.ss
|
(define invalid-tests
'(3
(begin rax 5)
(letrec ()
(set! rax 5))
(letrec ()
(set! rax 5)
(r15))
(letrec ()
(begin
(set! rax 5.5)
(r15)))
(letrec (["hello$55" (lambda () (r15))])
(begin
(set! rax 5)
(r15)))
(letrec ([double$1 (lambda ()
(begin
(set! rax (+ rax rax))
(r15)))]
[double$1 (lambda ()
(begin
(set! rdx (+ rdx rdx))
(set! rax rdx)
(r15)))])
(begin
(set! rax 10)
(double$1)))
(letrec ([double$1 (lambda ()
(begin
(set! rax (+ rax rax))
(sqr$1)))]
[sqr$1 (lambda ()
(begin
(set! rax (* rax rax))
(r15)))])
(begin
(set! rax 2)
(double$1)))
(letrec ()
(begin
(set! fv0 5)
(set! fv0 (* fv0 5))
(set! rax fv0)
(r15)))
(letrec ([f$1 (lambda ()
(begin
(set! rax 5)
(r15)))])
(begin
(set! fv0 f$1)
(fv0)))
(letrec ([foo (lambda ()
(begin
(set! rax 5)
(r15)))])
(foo))
(letrec ([f$5 (lambda (rax)
(begin
(set! rax (+ rax 20))
(r15)))])
(set! rax 10)
(f$5))
(letrec ([f$6 (lambda ()
(begin
(set! rax (* rax 100))
(r15)))])
(f$6 5))
(letrec ([f$7 (lambda (rdi)
(begin
(set! fv0 rdi)
(set! fv0 (+ fv0 10))
(set! rax fv0)
(r15)))])
(f$7 6))
(letrec ([foo$0 (lambda ()
(begin
(set! rax 5)
(r15)))])
(bar$1))
(letrec ([test-double$1 (lambda ()
(begin
(set! rdi 5)
(double$2)
(set! rax rdi)
(r15)))]
[double$2 (lambda ()
(begin
(set! rdi (+ rdi rdi))
(r15)))])
(test-double$1))
(letrec ()
(begin
(set! x 5)
(r15)))
(letrec ()
(begin
(set! rax 9223372036854775808)
(r15)))
(letrec ()
(begin
(set! rax -9223372036854775809)
(r15)))
(letrec ()
(begin
(set! rax (+ rax 2147483648))
(r15)))
(letrec ()
(begin
(set! rax (+ rax -2147483649))
(r15)))
(letrec ()
(begin
(set! fv0 2147483648)
(r15)))
(letrec ()
(begin
(set! fv0 -2147483649)
(r15)))
(letrec ()
(begin
(set! fv0 12.5)
(r15)))
(letrec ()
(letrec ()
(begin
(set! rax 5)
(r15))))
(letrec ()
(begin
(set! x 5)
(r15)))
(letrec ()
(begin
(set! rax 5)
(set! rax (sra rax -1))
(r15)))
(letrec
(begin
(set! rax 5)
(r15)))
(letrec ()
(begin
(set! rax (sra rax 64))
(r15)))
(letrec ()
(begin
(set! rax (/ rax 5))
(r15)))
(letrec ()
(begin
(set! rdx (+ fv0 rdx))
(r15)))
(letrec ()
(begin
(set! fv0 1)
(set! fv1 2)
(set! fv0 (+ fv0 fv1))))
(letrec ()
(begin
(set! fv0 1)
(set! fv1 fv0)
(r15)))
(letrec ()
(begin
(set! fv0 1)
(set! fv1 rax)))))
(define tests
'((letrec ()
(begin
(set! rax 5)
(r15)))
(letrec ()
(begin
(set! rax 5)
(set! rax (+ rax 5))
(r15)))
(letrec ()
(begin
(set! rax 10)
(set! rbx rax)
(set! rax (- rax rbx))
(r15)))
(letrec ()
(begin
(set! r11 5)
(set! rax r11)
(r15)))
(letrec ()
(begin
(set! r11 10)
(set! rax -10)
(set! rax (* rax r11))
(r15)))
(letrec ()
(begin
(set! r11 10)
(set! r11 (* r11 -10))
(set! rax r11)
(r15)))
(letrec ()
(begin
(set! rax 5)
(set! rax (+ rax 10))
(r15)))
(letrec ()
(begin
(set! r8 5)
(set! rax 10)
(set! rax (+ rax r8))
(r15)))
(letrec ()
(begin
(set! rax 7)
(set! rax (+ rax 4))
(r15)))
(letrec ()
(begin
(set! rax 7)
(set! rax (- rax 4))
(r15)))
(letrec ()
(begin
(set! rax 7)
(set! rax (* rax 4))
(r15)))
(letrec ()
(begin
(set! rax 5)
(set! rbx -11)
(set! rax (+ rax rbx))
(r15)))
(letrec ()
(begin
(set! rax 5)
(set! rbx -11)
(set! rax (- rax rbx))
(r15)))
(letrec ()
(begin
(set! rax 5)
(set! rbx -11)
(set! rax (* rax rbx))
(r15)))
;; some tests dealing with overflow
(letrec ()
(begin
(set! rax -9223372036854775808)
(set! rax (- rax 5))
(r15)))
(letrec ()
(begin
(set! rax 9223372036854775807)
(set! rax (+ rax 5))
(r15)))
(letrec ()
(begin
(set! rax 1000000000000000000)
(set! rax (* rax rax))
(r15)))
(letrec ()
(begin
(set! rax 1000000000000000000)
(set! rbx -1)
(set! rbx (* rbx rax))
(set! rax (* rax rbx))
(r15)))
;; Factorial 5 - the long way.
(letrec ()
(begin
(set! rax 5)
(set! rbx 1)
(set! rbx (* rbx rax))
(set! rax (- rax 1))
(set! rbx (* rbx rax))
(set! rax (- rax 1))
(set! rbx (* rbx rax))
(set! rax (- rax 1))
(set! rbx (* rbx rax))
(set! rax rbx)
(r15)))
;; Factorial 5 - the long way, nested begins
(letrec ()
(begin
(set! rax 5)
(begin
(set! rbx 1)
(begin
(set! rbx (* rbx rax))
(begin
(set! rax (- rax 1))
(begin
(set! rbx (* rbx rax))
(begin
(set! rax (- rax 1))
(begin
(set! rbx (* rbx rax))
(begin
(set! rax (- rax 1))
(begin
(set! rbx (* rbx rax))
(begin
(set! rax rbx)
(r15))))))))))))
(letrec ([double$0 (lambda ()
(begin
(set! rax (+ rax rax))
(r15)))])
(begin
(set! rax 10)
(double$0)))
(letrec ([double$1 (lambda ()
(begin
(set! rax fv0)
(set! rax (* rax 2))
(set! fv0 rax)
(r15)))])
(begin
(set! fv0 5)
(double$1)))
(letrec ([div$0 (lambda ()
(begin
(set! fv2 (sra fv2 1))
(div$1)))]
[div$1 (lambda ()
(begin
(set! rax fv2)
(fv0)))])
(begin
(set! fv0 r15)
(set! rax div$0)
(set! fv1 rax)
(set! fv2 64)
(fv1)))
(letrec ([return$1 (lambda ()
(begin
(set! rax fv0)
(fv1)))]
[setbit3$0 (lambda ()
(begin
(set! fv0 (logor fv0 8))
(return$1)))])
(begin
(set! fv0 1)
(set! fv1 r15)
(setbit3$0)))
(letrec ([zero?$0 (lambda ()
(begin
(set! rdx 0)
(set! rdx (- rdx rax))
(set! rdx (sra rdx 63))
(set! rdx (logand rdx 1))
(return$1)))]
[return$1 (lambda ()
(begin
(set! rax rdx)
(r15)))])
(begin
(set! rax 5)
(zero?$0)))
(letrec ([sqr-double$0 (lambda ()
(begin
(set! rdi (* rdi rdi))
(set! fv0 rdi)
(double$1)))]
[double$1 (lambda ()
(begin
(set! rsi fv0)
(set! rsi (+ rsi fv0))
(return$3)))]
[return$3 (lambda ()
(begin
(set! rax rsi)
(r15)))])
(begin
(set! rdi 5)
(sqr-double$0)))
(letrec ([main$1 (lambda ()
(begin
(set! rax 5)
(r15)))])
(main$1))
(letrec ([fact$0 (lambda ()
(begin
; no if, so use a computed goto
; put address of fact$1 at bfp[0]
(set! rcx fact$1)
(set! fv0 rcx)
; put address of fact$2 at bfp[8]
(set! rcx fact$2)
(set! fv1 rcx)
; if x == 0 set rcx to 8, else set rcx to 0
(set! rdx 0)
(set! rdx (- rdx rax))
(set! rdx (sra rdx 63))
(set! rdx (logand rdx 8))
; point bfp at stored address of fact$1 or fact$2
(set! rbp (+ rbp rdx))
; grab whichever and reset bfp
(set! rcx fv0)
(set! rbp (- rbp rdx))
; tail call (jump to) fact$1 or fact$2
(rcx)))]
[fact$1 (lambda ()
(begin
; get here if rax is zero, so return 1
(set! rax 1)
(r15)))]
[fact$2 (lambda ()
(begin
; get here if rax is nonzero, so save return
; address and eax, then call fact$0 recursively
; with eax - 1, setting fact$3 as return point
(set! fv0 r15)
(set! fv1 rax)
(set! rax (- rax 1))
(set! r15 fact$3)
; bump rbp by 16 (two 64-bit words) so that
; recursive call doesn't wipe out our saved
; eax and return address
(set! rbp (+ rbp 16))
(fact$0)))]
[fact$3 (lambda ()
(begin
; restore rbp to original value
(set! rbp (- rbp 16))
; eax holds value of recursive call, multiply
; by saved value at fv1 and return to saved
; return address at fv0
(set! rax (* rax fv1))
(fv0)))])
(begin
(set! rax 10)
(fact$0)))
;------------------------------------------------------------------------
; My test of Fibonacci calculator
;------------------------------------------------------------------------
; Calculates Fib(n), where n is set in rcx in the body of letrec.
;
; The original fv0 holds the address referred by label loop$1,
; fv1 holds the return address given by r15.
; Controller performs a computed goto based on the value
; of rcx. The rule is if rcx is positive or zero jump to loop$1.
; If negative jump to exit (return). The trick here is to
; shift/reduce rbp based on a computer value of 0 or 8.
; Controller reduces rcx each time it is called to guarantee
; the jump to exit. The register rax will hold the final answer.
;------------------------------------------------------------------------
(letrec ([loop$1 (lambda () (begin
(set! rax (+ rax rbx))
(set! rbx r11)
(set! r11 rax)
(controller$2)))]
[controller$2 (lambda () (begin
(set! rdx rcx)
; shift rdx righ by 63
; output of this is (in 2's comp.)
; 0 if rdx is zero or positive
; else -1.
(set! rdx (sra rdx 63))
; this will result either 0 or 8
; 8 if rdx was negative
(set! rdx (logand rdx 8))
(set! rbp (+ rbp rdx))
; fv0 may either be the original fv0
; or original fv1 (if rdx was neg.).
; original fv1 has the exit address.
(set! r15 fv0)
; reset rbp
(set! rbp (- rbp rdx))
; reduce rcx by 1
(set! rcx (- rcx 1))
(r15)))])
(begin
; set initial values
(set! rax 1)
(set! rbx 0)
(set! r11 0)
; keep the address referred by label loop$1 in fv0
(set! rdx loop$1)
(set! fv0 rdx)
; keep the return address in fv1
(set! rdx r15)
(set! fv1 rdx)
; the number we are interested in (e.g.Fib(10))
(set! rcx 10)
; jump to the controller
(controller$2)))))
| false |
f628cabdfed726864afff5e099c0a46bdd1d585c
|
000dbfe5d1df2f18e29a76ea7e2a9556cff5e866
|
/sitelib/srfi/%3a38.scm
|
c97983ea6d7e0072de6ae63f3f0a1151ea1d73bd
|
[
"BSD-3-Clause",
"LicenseRef-scancode-other-permissive",
"MIT",
"BSD-2-Clause"
] |
permissive
|
ktakashi/sagittarius-scheme
|
0a6d23a9004e8775792ebe27a395366457daba81
|
285e84f7c48b65d6594ff4fbbe47a1b499c9fec0
|
refs/heads/master
| 2023-09-01T23:45:52.702741 | 2023-08-31T10:36:08 | 2023-08-31T10:36:08 | 41,153,733 | 48 | 7 |
NOASSERTION
| 2022-07-13T18:04:42 | 2015-08-21T12:07:54 |
Scheme
|
UTF-8
|
Scheme
| false | false | 124 |
scm
|
%3a38.scm
|
;; -*- mode: scheme; coding: utf-8 -*-
(library (srfi :38)
(export :all)
(import (srfi :38 with-shared-structure))
)
| false |
cb72ba52ae023cbfc7b6e023ef3b0b9b22b35166
|
26aaec3506b19559a353c3d316eb68f32f29458e
|
/modules/cdb/cdb.scm
|
95f8141a7257a5ea5362e4fa768b27300b3610a0
|
[
"BSD-3-Clause"
] |
permissive
|
mdtsandman/lambdanative
|
f5dc42372bc8a37e4229556b55c9b605287270cd
|
584739cb50e7f1c944cb5253966c6d02cd718736
|
refs/heads/master
| 2022-12-18T06:24:29.877728 | 2020-09-20T18:47:22 | 2020-09-20T18:47:22 | 295,607,831 | 1 | 0 |
NOASSERTION
| 2020-09-15T03:48:04 | 2020-09-15T03:48:03 | null |
UTF-8
|
Scheme
| false | false | 12,034 |
scm
|
cdb.scm
|
#|
LambdaNative - a cross-platform Scheme framework
Copyright (c) 2009-2015, University of British Columbia
All rights reserved.
Redistribution and use in source and binary forms, with or
without modification, are permitted provided that the
following conditions are met:
* Redistributions of source code must retain the above
copyright notice, this list of conditions and the following
disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials
provided with the distribution.
* Neither the name of the University of British Columbia nor
the names of its contributors may be used to endorse or
promote products derived from this software without specific
prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 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.
|#
;; wrapper for CDB, a very fast constant database
;; both keys and values can be arbitrary scheme code
(define cdb:debuglevel 0)
(define (cdb:log level . x)
(if (>= cdb:debuglevel level) (apply log-system (append (list "cdb: ") x))))
(c-declare #<<c-declare-end
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <cdb.h>
struct cdb_make *_make_cdb(char *fname)
{
#ifdef WIN32
FILE *f = fopen(fname, "w+b");
int fd = fileno(f);
#else
int fd = open(fname,O_RDWR|O_CREAT,0666);
#endif
if (fd<0) return 0;
struct cdb_make *cdbm = (struct cdb_make *)malloc(sizeof(struct cdb_make));
if (cdbm) cdb_make_start(cdbm, fd);
return cdbm;
}
int _cdb_make_merge(struct cdb_make *cdbm, char *fname)
{
int tmpfd = open(fname,O_RDONLY);
if (!tmpfd) return 0;
struct cdb tmpcdb;
if (cdb_init(&tmpcdb, tmpfd)<0) return 0;
unsigned int cpos;
cdb_seqinit(&cpos,&tmpcdb);
while (cdb_seqnext(&cpos,&tmpcdb)>0) {
unsigned int klen = cdb_keylen(&tmpcdb);
char *key = (char*)malloc(klen);
cdb_read(&tmpcdb, key, klen, cdb_keypos(&tmpcdb));
unsigned int vlen = cdb_datalen(&tmpcdb);
char *val = (char*)malloc(vlen);
cdb_read(&tmpcdb, val, vlen, cdb_datapos(&tmpcdb));
cdb_make_add(cdbm,key,klen,val,vlen);
free(key);
free(val);
}
cdb_free(&tmpcdb);
close(tmpfd);
return 1;
}
int _cdb_make_finish(struct cdb_make *cdbm)
{
int fd = cdbm->cdb_fd;
int res = cdb_make_finish(cdbm);
if (fd) close(fd);
return res;
}
struct cdb *_init_cdb(char *fname)
{
int fd = open(fname,O_RDONLY);
if (fd<0) return 0;
struct cdb *cdb = (struct cdb *)malloc(sizeof(struct cdb));
if (cdb) {
int res = cdb_init(cdb,fd);
if (res<0) { free(cdb); return 0; } else return cdb;
} else {
return 0;
}
}
void _cdb_finish(struct cdb *cdb)
{
int fd = cdb->cdb_fd;
cdb_free(cdb);
if (fd) close(fd);
}
static struct cdb_find cdbf;
c-declare-end
)
;; encode/decode
(define cdb:makectx rabbit-make)
(define cdb:destroyctx rabbit-destroy)
(define (cdb:encoder keyctx)
(lambda (obj) (rabbit-encode keyctx (object->u8vector obj))))
(define (cdb:decoder keyctx)
(lambda (u8v) (with-exception-catcher (lambda (e)
(log-error "cdb:decoder: failed to deserialize: " (exception->string e)) #f)
(lambda () (u8vector->object (rabbit-decode keyctx u8v))))))
;; create interface
(define CDB_PUT_ADD ((c-lambda () int "___result=CDB_PUT_ADD;")))
(define CDB_PUT_REPLACE ((c-lambda () int "___result=CDB_PUT_REPLACE;")))
(define CDB_PUT_INSERT ((c-lambda () int "___result=CDB_PUT_INSERT;")))
(define (make-cdb fname . key)
(let ((ctx (if (null? key) #f (cdb:makectx (car key)))))
(list ((c-lambda (char-string) (pointer void) "_make_cdb") fname)
(if (not ctx) object->u8vector (cdb:encoder ctx)) ctx
)))
(define (cdb-make-add cdb key val)
(cdb:log 2 "cdb-make-add " cdb " " key " " val)
(let* ((cdb:ptr (car cdb))
(cdb:encode (cadr cdb))
(u8key (cdb:encode key))
(u8val (cdb:encode val)))
(fx= 0 ((c-lambda ((pointer void) scheme-object int scheme-object int) int
"___result=cdb_make_add(___arg1,
___CAST(void*,___BODY_AS(___arg2,___tSUBTYPED)), ___arg3,
___CAST(void*,___BODY_AS(___arg4,___tSUBTYPED)), ___arg5);")
cdb:ptr u8key (u8vector-length u8key) u8val (u8vector-length u8val)))))
(define (cdb-make-put cdb key val flag)
(cdb:log 2 "cdb-make-put " cdb " " key " " val " " flag)
(let* ((cdb:ptr (car cdb))
(cdb:encode (cadr cdb))
(u8key (cdb:encode key))
(u8val (cdb:encode val)))
(fx= 0 ((c-lambda ((pointer void) scheme-object int scheme-object int int) int
"___result=cdb_make_put(___arg1,
___CAST(void*,___BODY_AS(___arg2,___tSUBTYPED)), ___arg3,
___CAST(void*,___BODY_AS(___arg4,___tSUBTYPED)), ___arg5, ___arg6);")
cdb:ptr u8key (u8vector-length u8key) u8val (u8vector-length u8val) flag))))
(define (cdb-make-exists cdb key)
(cdb:log 2 "cdb-make-exists " cdb " " key)
(let* ((cdb:ptr (car cdb))
(cdb:encode (cadr cdb))
(u8key (cdb:encode key)))
(not (fx= ((c-lambda ((pointer void) scheme-object int) int
"___result=cdb_make_exists(___arg1, ___CAST(void*,___BODY_AS(___arg2,___tSUBTYPED)), ___arg3);")
cdb:ptr u8key (u8vector-length u8key)) 0))))
(define (cdb-make-merge cdb file)
(cdb:log 2 "cdb-make-merge " cdb " " file)
(fx= 1 ((c-lambda ((pointer void) char-string) int "_cdb_make_merge") (car cdb) file)))
(define (cdb-make-finish cdb)
(let ((ctx (caddr cdb))
(res ((c-lambda ((pointer void)) int "_cdb_make_finish") (car cdb))))
(if ctx (cdb:destroyctx ctx))
res
))
;; query interface
(define (init-cdb fname . key)
(let ((ctx (if (null? key) #f (cdb:makectx (car key)))))
(list ((c-lambda (char-string) (pointer void) "_init_cdb") fname)
(if (not ctx) object->u8vector (cdb:encoder ctx))
(if (not ctx) u8vector->object (cdb:decoder ctx))
ctx
)))
(define cdb:find (c-lambda ((pointer void) scheme-object int) int
"___result=cdb_find(___arg1, ___CAST(char*,___BODY_AS(___arg2,___tSUBTYPED)), ___arg3);"))
(define cdb:findinit (c-lambda ((pointer void) scheme-object int) int
"___result=cdb_findinit(&cdbf,___arg1, ___CAST(void*,___BODY_AS(___arg2,___tSUBTYPED)), ___arg3);"))
(define cdb:findnext (c-lambda () int "___result=cdb_findnext(&cdbf);"))
(define cdb:datapos (c-lambda ((pointer void)) unsigned-int "___result=cdb_datapos((struct cdb*)___arg1);"))
(define cdb:datalen (c-lambda ((pointer void)) unsigned-int "___result=cdb_datalen((struct cdb*)___arg1);"))
(define cdb:keypos (c-lambda ((pointer void)) unsigned-int "___result=cdb_keypos((struct cdb*)___arg1);"))
(define cdb:keylen (c-lambda ((pointer void)) unsigned-int "___result=cdb_keylen((struct cdb*)___arg1);"))
(define cdb:read (c-lambda ((pointer void) scheme-object int unsigned-int) int
"___result=cdb_read(___arg1, ___CAST(char*,___BODY_AS(___arg2,___tSUBTYPED)), ___arg3, ___arg4);"))
(define (cdb-find cdb key)
(cdb:log 2 "cdb-find" cdb " " key)
(let* ((cdb:ptr (car cdb))
(cdb:encode (cadr cdb))
(cdb:decode (caddr cdb))
(u8key (cdb:encode key))
(res (begin (cdb:findinit cdb:ptr u8key (u8vector-length u8key)) (cdb:findnext)))
(vpos (if (> res 0) (cdb:datapos cdb:ptr) #f))
(vlen (if (> res 0) (cdb:datalen cdb:ptr) #f))
(u8val (if vlen (make-u8vector vlen) #f)))
(if u8val (begin (cdb:read cdb:ptr u8val vlen vpos) (cdb:decode u8val)) #f)))
(define (cdb-findnext cdb)
(cdb:log 2 "cdb-findnext" cdb)
(let* ((cdb:ptr (car cdb))
(cdb:decode (caddr cdb))
(res (cdb:findnext))
(vpos (if (> res 0) (cdb:datapos cdb:ptr) #f))
(vlen (if (> res 0) (cdb:datalen cdb:ptr) #f))
(u8val (if vlen (make-u8vector vlen) #f)))
(if u8val (begin (cdb:read cdb:ptr u8val vlen vpos) (cdb:decode u8val)) #f)))
(define cdb:seqinit (c-lambda (scheme-object (pointer void)) int
"___result=cdb_seqinit(___CAST(unsigned*,___BODY_AS(___arg1,___tSUBTYPED)), ___arg2);"))
(define cdb:seqnext (c-lambda (scheme-object (pointer void)) int
"___result=cdb_seqnext(___CAST(unsigned*,___BODY_AS(___arg1,___tSUBTYPED)), ___arg2);"))
(define (cdb-index cdb)
(cdb:log 2 "cdb-index " cdb)
(let* ((cdb:ptr (car cdb))
(cdb:decode (caddr cdb))
(tmp (u32vector 0)))
(cdb:seqinit tmp cdb:ptr)
(let loop ((idx '()))
(let* ((res (cdb:seqnext tmp cdb:ptr))
(kpos (if (> res 0) (cdb:keypos cdb:ptr) #f))
(klen (if (> res 0) (cdb:keylen cdb:ptr) #f))
(u8key (if klen (make-u8vector klen) #f)))
(if (= res 0) idx
(loop (append idx (list
(begin (cdb:read cdb:ptr u8key klen kpos) (cdb:decode u8key))))))))
))
(define (cdb->table cdbfile . key)
(cdb:log 2 "cdb->table " cdbfile " " key)
(if (not (file-exists? cdbfile)) #f
(let* ((cdb (apply init-cdb (append (list cdbfile) key)))
(cdb:ptr (car cdb))
(cdb:decode (caddr cdb))
(tmp (u32vector 0))
(t (make-table)))
(if cdb:ptr (begin
(cdb:seqinit tmp cdb:ptr)
(let ((fnl (let loop ()
(let* ((res (cdb:seqnext tmp cdb:ptr))
(kpos (if (> res 0) (cdb:keypos cdb:ptr) #f))
(klen (if (> res 0) (cdb:keylen cdb:ptr) #f))
(vpos (if (> res 0) (cdb:datapos cdb:ptr) #f))
(vlen (if (> res 0) (cdb:datalen cdb:ptr) #f))
(u8val (if vlen (make-u8vector vlen) #f))
(u8key (if klen (make-u8vector klen) #f)))
(if (= res 0) t (begin
(cdb:read cdb:ptr u8key klen kpos)
(cdb:read cdb:ptr u8val vlen vpos)
(table-set! t (cdb:decode u8key) (cdb:decode u8val))
(loop)))))))
(cdb-finish cdb) fnl
)) #f)
)))
(define (table->cdb t cdbfile . key)
(cdb:log 2 "table->cdb " t " " cdbfile " " key)
(let ((cdbm (apply make-cdb (append (list cdbfile) key))))
(table-for-each (lambda (k v) (cdb-make-add cdbm k v)) t)
(cdb-make-finish cdbm) #t))
(define (cdb-finish cdb)
(let ((ctx (cadddr cdb)))
((c-lambda ((pointer void)) void "_cdb_finish") (car cdb))
(if ctx (cdb:destroyctx ctx))))
;; unit test
(unit-test "cdb" "constant database creation and lookup"
(lambda ()
(let* ((fname (string-append (system-directory) (system-pathseparator) "unittest.cdb")))
(if (file-exists? fname) (delete-file fname))
(let* ((keys (list "a" 'a '(test) (lambda (x) x) 1 0.5 1/2))
(values (list '1 2 "three" 'four 5. '(six) (lambda (seven) 1)))
(cryptokey (random-u8vector 24))
(cdbm (make-cdb fname cryptokey)))
(let loop ((ks keys)(vs values))
(if (> (length ks) 0) (begin
(cdb-make-add cdbm (car ks) (car vs))
(loop (cdr ks) (cdr vs)))))
(cdb-make-finish cdbm)
(let* ((cdb (init-cdb fname cryptokey))
(res (let loop ((ks keys)(vs values))
(if (fx= (length ks) 0) #t
(if (not (equal? (car vs) (cdb-find cdb (car ks)))) #f
(loop (cdr ks) (cdr vs)))))))
(cdb-finish cdb)
(if (file-exists? fname) (delete-file fname))
res)))))
;; eof
| false |
8d119db3459bc6bda43f0a8cc3954f89301ec126
|
953be597c6ee4fe8783ae31d0c863b5fb0633896
|
/src/kawa/battle/ui.scm
|
95dcafdda81e9af0aa20a5658809c9b69ad30e3c
|
[] |
no_license
|
bitsai/orc-battle
|
aeb259b9b679bc8707880207e72d877f68f8039f
|
fd11c277912529c3217a25f4154692ec5cf761a7
|
refs/heads/master
| 2021-01-18T14:38:13.051840 | 2011-12-15T04:47:07 | 2011-12-15T04:47:07 | 1,471,053 | 1 | 2 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 1,132 |
scm
|
ui.scm
|
(require 'android-defs)
(require "orc-battle.scm")
(require "util.scm")
(define *scroll-view* ::android.widget.ScrollView #!null)
(define *text-view* ::android.widget.TextView #!null)
(define *monster-btn* ::android.widget.Button #!null)
(activity
ui
(on-create
((this):setContentView kawa.battle.R$layout:main)
(set! *scroll-view* ((this):findViewById kawa.battle.R$id:scroll_view))
(set! *text-view* ((this):findViewById kawa.battle.R$id:text_view))
(set! *monster-btn* ((this):findViewById kawa.battle.R$id:monster_btn))
(new-game))
((onClick v ::android.view.View)
(process-input (read-string (as android.widget.Button v):text)))
((onNextMonster v ::android.view.View)
(change-monster inc))
((onPrevMonster v ::android.view.View)
(change-monster dec)))
(define (change-monster f)
(let ((x (string->number *monster-btn*:text)))
(*monster-btn*:setText (number->string (f x)))))
(define (output . xs)
(*text-view*:append (string-append (apply str xs) "\n"))
(*scroll-view*:post
(lambda ()
(*scroll-view*:fullScroll android.widget.ScrollView:FOCUS_DOWN))))
| false |
26f1045ef71631645b385412082970e639ea5b91
|
f08220a13ec5095557a3132d563a152e718c412f
|
/logrotate/skel/usr/share/guile/2.0/ice-9/and-let-star.scm
|
2d53ff384669d48dde865c3023a8173368f41b6b
|
[
"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 | 2,593 |
scm
|
and-let-star.scm
|
;;;; and-let-star.scm --- and-let* syntactic form (SRFI-2) for Guile
;;;;
;;;; Copyright (C) 1999, 2001, 2004, 2006, 2013,
;;;; 2015 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
(define-module (ice-9 and-let-star)
:export-syntax (and-let*))
(define-syntax %and-let*
(lambda (form)
(syntax-case form ()
;; Handle zero-clauses special-case.
((_ orig-form () . body)
#'(begin #t . body))
;; Reduce clauses down to one regardless of body.
((_ orig-form ((var expr) rest . rest*) . body)
(identifier? #'var)
#'(let ((var expr))
(and var (%and-let* orig-form (rest . rest*) . body))))
((_ orig-form ((expr) rest . rest*) . body)
#'(and expr (%and-let* orig-form (rest . rest*) . body)))
((_ orig-form (var rest . rest*) . body)
(identifier? #'var)
#'(and var (%and-let* orig-form (rest . rest*) . body)))
;; Handle 1-clause cases without a body.
((_ orig-form ((var expr)))
(identifier? #'var)
#'expr)
((_ orig-form ((expr)))
#'expr)
((_ orig-form (var))
(identifier? #'var)
#'var)
;; Handle 1-clause cases with a body.
((_ orig-form ((var expr)) . body)
(identifier? #'var)
#'(let ((var expr))
(and var (begin . body))))
((_ orig-form ((expr)) . body)
#'(and expr (begin . body)))
((_ orig-form (var) . body)
(identifier? #'var)
#'(and var (begin . body)))
;; Handle bad clauses.
((_ orig-form (bad-clause . rest) . body)
(syntax-violation 'and-let* "Bad clause" #'orig-form #'bad-clause)))))
(define-syntax and-let*
(lambda (form)
(syntax-case form ()
((_ (c ...) body ...)
#`(%and-let* #,form (c ...) body ...)))))
(cond-expand-provide (current-module) '(srfi-2))
| true |
b6b9d05084f2d8c638fc1416f43bf1af84304d24
|
d6ba773f1c822a5003692c47a6d2b645e47c0907
|
/lib/postgresql/buffer.sld
|
1796aa5cc555c42a42a5e16a7c0a9cb14ad8ce1b
|
[
"BSD-2-Clause",
"BSD-3-Clause"
] |
permissive
|
ktakashi/r7rs-postgresql
|
a2d93e39cd95c0cf659e8336f5aaf62ad61f4f75
|
94fdaeccee6caa5e9562a8f231329e59ce15aae7
|
refs/heads/master
| 2020-04-06T13:13:50.481891 | 2017-12-11T20:09:43 | 2017-12-11T20:09:43 | 26,015,242 | 23 | 3 | null | 2015-02-04T19:40:18 | 2014-10-31T12:26:02 |
Scheme
|
UTF-8
|
Scheme
| false | false | 5,205 |
sld
|
buffer.sld
|
;;; -*- mode:scheme; coding:utf-8; -*-
;;;
;;; postgresql/buffer.sld - PostgreSQL message buffer
;;;
;;; Copyright (c) 2014-2016 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.
;;;
;; explicit buffering layer.
;; This library provides buffering of socket port.
;; (NB: implmented atop custom port would be cleaner if we could use.)
(define-library (postgresql buffer)
(export postgresql-send-ssl-request
postgresql-send-startup-message
postgresql-send-password-message
postgresql-send-terminate-message
postgresql-send-sync-message
postgresql-send-flush-message
postgresql-send-query-message
postgresql-send-parse-message
postgresql-send-bind-message
postgresql-send-describe-message
postgresql-send-execute-message
postgresql-send-close-message
postgresql-send-copy-data-message
postgresql-send-copy-fail-message
postgresql-send-copy-done-message
postgresql-read-response
make-postgresql-out-buffer
)
(import (scheme base)
(scheme write)
(prefix (postgresql messages) m:))
(begin
(define-record-type postgresql-out-buffer
(%make-postgresql-out-buffer sock-out buffer)
postgresql-out-buffer?
(sock-out %bo)
;; R7RS doesn't have any manner to truncate the output-bytevector
;; so not sure if this actually improves the performance.
;; (Needs to be measured)
(buffer %bb %bb!))
(define (make-postgresql-out-buffer sock-out)
(%make-postgresql-out-buffer sock-out (open-output-bytevector)))
(define-syntax define-forward
(syntax-rules ()
((_ name real) (define-forward name real (buffer)))
((_ name real (buffer args ...))
(define (name buffer args ...)
(real (%bo buffer) args ...)))))
(define-syntax define-buffering
(syntax-rules ()
((_ name real) (define-buffering name real (buffer)))
((_ name real (buffer args ...))
(define (name buffer args ...)
(real (%bb buffer) args ...)))))
(define-forward postgresql-send-ssl-request
m:postgresql-send-ssl-request
(out))
(define-forward postgresql-send-startup-message
m:postgresql-send-startup-message
(out messages))
(define-forward postgresql-send-password-message
m:postgresql-send-password-message
(out password))
(define-forward postgresql-send-terminate-message
m:postgresql-send-terminate-message)
(define-forward postgresql-send-sync-message
m:postgresql-send-sync-message)
(define (postgresql-send-flush-message out)
(write-bytevector (get-output-bytevector (%bb out)) (%bo out))
(close-output-port (%bb out))
(%bb! out (open-output-bytevector))
(m:postgresql-send-flush-message (%bo out)))
(define-buffering postgresql-send-query-message
m:postgresql-send-query-message
(out sql))
(define-buffering postgresql-send-parse-message
m:postgresql-send-parse-message
(out name sql types))
(define-buffering postgresql-send-bind-message
m:postgresql-send-bind-message
(out portal prepared params formats))
(define-buffering postgresql-send-describe-message
m:postgresql-send-describe-message
(out name type))
(define-buffering postgresql-send-execute-message
m:postgresql-send-execute-message
(out name maxnum))
(define-buffering postgresql-send-close-message
m:postgresql-send-close-message
(out type name))
(define-buffering postgresql-send-copy-data-message
m:postgresql-send-copy-data-message
(out date))
(define-buffering postgresql-send-copy-fail-message
m:postgresql-send-copy-fail-message
(out msg))
(define-buffering postgresql-send-copy-done-message
m:postgresql-send-copy-done-message)
(define postgresql-read-response m:postgresql-read-response)
)
)
| true |
180894c6e9e0b8b694fabddebc48345aa820b763
|
80c8c43dd7956bb78a0c586ea193e3114de31046
|
/practice-4.scm
|
3ac3c8cd3fafa07146515abb8bfa04550698c5a7
|
[] |
no_license
|
UeharaYou/Learning-SICP
|
78b9d29e6a84a0890ec9788073160c3f7fd8a231
|
3a6cf413a313d7249e121bdd1515e374d2a369ea
|
refs/heads/master
| 2021-04-05T14:00:36.752016 | 2020-03-19T17:27:39 | 2020-03-19T17:27:39 | 248,564,129 | 0 | 0 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 2,858 |
scm
|
practice-4.scm
|
;; SICP Practice: 4
;; (protocol <dict> '(<entry> ...))
;; (protocol <closure> '('closure <list> <exp> <env>))
;; (protocol <env> '(<dict> . <env>))
(define make-dict
(lambda (k v)
(define make-entries
(lambda (key-l val-l old-dict)
(cond ((and (null? key-l) (null? val-l)) '())
((and (not (null? key-l)) (null? val-l)) (raise 'too-few-vals))
((and (null? key-l) (not (null? val-l))) (raise 'too-few-keys))
(else (cond ((pair? key-l) (cons (cons (car key-l) (car val-l)) (make-entries (cdr key-l) (cdr val-l))))
(else (list (cons key-l val-l))))))))
(define make-entries-2
(lambda (key-p val-p)
(define translate-pair
(lambda (key-r val-r)
(cond ((atom? key-r) (cons (list key-r) (list val-r)))
(else (let ((result (translate-pair (cdr key-r) (cdr val-r))))
(cons (cons (car key-r) (car result))
(cons (car val-r) (cdr result))))))))
(cond ((and (list? key-p) (list? val-p))
(map (lambda (x y) (cons x y))
key-p
val-p))
((and (pair? key-p) (pair? val-p)) (let ((trans (translate-pair key-p val-p))) (make-entries-2 (car trans) (cdr trans))))
(else (raise 'type-error)))))
(let ((content (make-entries-2 k v)))
(define merge '())
(define lookup
(lambda (key)
(map cdr
(filter (lambda (x) (eq? (car x) key))
content))))
(define update!
(lambda (key new-val)
(set! content (map (lambda (x) (if (eq? (car x) key) (cons key new-val) x))
content))))
(define add! update!)
(define dict-dispatch
(lambda (message)
(cond ((eq? message 'lookup) lookup)
((eq? message 'update!) update!)
(else (raise-continuable 'unknown-message)))))
dict-dispatch)))
(define make-env
(lambda (dict ref-super-env)
(let ((content (cons dict ref-super-env)))
(define env-dispatch
(lambda (message)
(cond ((eq? message 'add!) (lambda (dict) (add-dict! dict (car content))))
((eq? message 'update!) (lambda (dict) (update-dict! dict (car content))))
(else (raise-continuable 'unknown-message)))))
env-dispatch)))
| false |
d6bf243fae0e8fd25fa58ff74c5b4402f33820f1
|
a4d6eeda1e8e80653fb874bd04883c212f19a9fb
|
/tests.ss
|
3a45eee6da9059726d03b3078ef1dbde48c0462a
|
[] |
no_license
|
mml/incr
|
a199ff01f41238775730fceb75db41d86045017a
|
5b9657dcecc9474ee88c2b78369374f2dc0bcd38
|
refs/heads/master
| 2023-01-01T12:32:36.980967 | 2020-10-27T11:17:13 | 2020-10-27T11:17:13 | 282,290,358 | 0 | 0 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 20,522 |
ss
|
tests.ss
|
(module tests racket
(require "test-driver.ss")
(define (runtests)
(test-cases "vectors"
(test-case (make-vector 0 0) "#()")
(test-case (make-vector 1 0) "#(0)")
(test-case (make-vector 10 0) "#(0 0 0 0 0 0 0 0 0 0)")
(test-case
(vector-length (make-vector 500 1))
"500")
(test-case
(let ([v (make-vector 5 0)])
(vector-set! v 1 20)
v)
"#(0 20 0 0 0)")
(test-case
(let ([v (make-vector 5 0)])
(vector-set! v 0 0)
(vector-set! v 1 1)
(vector-set! v 2 2)
(vector-set! v 3 3)
(vector-set! v 4 4)
v)
"#(0 1 2 3 4)")
(test-case
(let ([v (make-vector 5 0)])
(letrec
([uv (lambda (v n)
(cond
[(< n 0) v]
[else
(vector-set! v n n)
(uv v (sub1 n))]))])
(uv v 4)))
"#(0 1 2 3 4)")
(test-case
(letrec
([size 40]
[v (make-vector size #f)]
[init (lambda (n)
(cond
[(< n 0)]
[else
(letrec
([vv (make-vector size #f)]
[setup (lambda (m)
(cond
[(< m 0) v]
[else
(vector-set! vv m (* m n))
(setup (sub1 m))]))])
(vector-set! v n vv)
(setup (sub1 size)))
(init (sub1 n))]))])
(init (sub1 size))
(letrec
([check (lambda (m n)
(if (< m 0)
#t
(and (= (* m n) (vector-ref (vector-ref v m) n))
(= (* m n) (vector-ref (vector-ref v n) m))
(check (sub1 m) n))))]
[check* (lambda (n)
(if (< n 0)
#t
(and (check (sub1 size) n)
(check* (sub1 n)))))])
(check* (sub1 size))))
"#t")
; Something that takes long enough to be a speed test.
(test-case
(let ([size 10000])
(letrec
([v (make-vector size 1)]
[f (lambda (n acc)
(cond
[(< n 0) acc]
[else (f (sub1 n) (+ acc (vector-ref v n)))]))]
[g (lambda (n acc)
(cond
[(zero? n) acc]
[else (g
(sub1 n)
(+ acc
(bitwise-arithmetic-shift-right
(f (sub1 size) 0) 4)))]))])
(g 10000 0)))
"6250000")
)
(test-cases "macro expansion"
(test-case (and) "#t")
(test-case (and 1) "1")
(test-case (and 1 2) "2")
(test-case (and 1 2 3) "3")
(test-case (and 1 2 3 #f) "#f")
(test-case (or) "#f")
(test-case (or 1) "1")
(test-case (or #f 2) "2")
(test-case (or #f 2 3) "2")
(test-case (or #f #f 3) "3")
(test-case (or #f #f #f 4) "4")
(test-case
(let ([sum (lambda (x y sum)
(cond
[(zero? x) y]
[(zero? y) x]
[(< y x) (sum (add1 x) (sub1 y) sum)]
[(< x y) (sum (add1 y) (sub1 x) sum)]
[else (* 2 x)]))])
(cons (sum 10 0 sum)
(cons (sum 0 10 sum)
(cons (sum 8 2 sum)
(cons (sum 2 8 sum)
(cons (sum 5 5 sum) '()))))))
"(10 10 10 10 10)")
(test-case
(list 1 2 3 4 5 6 7 8 9 10)
"(1 2 3 4 5 6 7 8 9 10)")
(test-case
(let ([=q-helper
(lambda (x alist =q-helper)
(cond
[(null? alist)
#f]
[(= (car (car alist)) x)
(car alist)]
[else (=q-helper x (cdr alist))]))])
(let ([=q (lambda (x alist) (=q-helper x alist =q-helper))]
[al (cons (cons 1 2) (cons (cons 3 4) '()))])
(let ([val (lambda (x)
(cond
[(=q x al) => (lambda (as) (cdr as))]
[else #f]))])
(cons (val 1)
(cons (val 3)
(cons (val 5) '()))))))
"(2 4 #f)")
(test-case
(letrec ([len (lambda (l)
(cond
[(null? l) 0]
[else (add1 (len (cdr l)))]))])
(len (list 1 2 3 4 5 6)))
"6")
;;; Letrec bug
#;(test-case
(letrec ([size 10000]
[v (make-vector size 1)])
(vector-length v))
"10000")
(test-case
(let* ([a 10]
[b (+ a 20)]
[c (* b b)])
c)
"900")
)
(test-cases "assignment"
(test-case
((((lambda (x)
(let ([r #f])
(lambda (y)
(lambda (z)
(set! r (+ x (+ y z)))
r))))
10) 20) 30)
"60")
(test-case
((((lambda (x)
(let ([r 0])
(set! r (+ r x))
(lambda (y)
(set! r (+ r y))
(lambda (z)
(set! r (+ r z))
r))))
10) 20) 30)
"60")
(test-case
(let ([make-acc (lambda ()
(let ([v 0])
(lambda (cmd arg)
(if (= cmd 0)
v
(if (= cmd 1)
(set! v arg)
(if (= cmd 2)
(set! v (arg v))
#f))))))]
[acc-get (lambda (a) (a 0 '()))]
[acc-set! (lambda (a n) (a 1 n))]
[acc-apply! (lambda (a f) (a 2 f))])
(let ([acc-add! (lambda (a n) (acc-apply! a (lambda (v) (+ v n))))]
[acc-sub! (lambda (a n) (acc-apply! a (lambda (v) (- v n))))])
(let ([a (make-acc)]
[b (make-acc)])
(acc-add! a 10)
(acc-add! b 100)
(acc-sub! b (acc-get a))
(acc-set! a 40)
(- (acc-get b) (acc-get a)))))
"50")
(test-case
(let ([a 10] [b 20])
(set! a (begin
(set! b 1)
2))
(+ a b))
"3")
)
(test-cases "parsing challenges"
(test-case ((lambda (lambda) (lambda lambda)) (lambda (let) 20))
"20")
)
(test-cases "begin"
(test-case (begin 0) "0")
(test-case (begin 0 10) "10"))
(test-cases "Integer immediates"
; ARM cases
; Easy #1: 8 bit values
(test-case 0 "0")
(test-case 1 "1")
(test-case 42 "42")
(test-case 255 "255")
; Easy #2: powers of two
(test-case 256 "256")
(test-case 512 "512")
(test-case 65536 "65536")
; 2^28
(test-case 268435456 "268435456")
; Easy #3: n << m where n <= 255 and 0 <= m <= 15
; 42 << 15
(test-case 1376256 "1376256")
; 255 << 14
(test-case 4177920 "4177920")
; ; 255 << 15
(test-case 8355840 "8355840")
(test-case 257 "257")
(test-case 4095 "4095")
(test-case 65535 "65535")
(test-case -1 "-1"))
(test-cases "Non-integer immediates"
; booleans
(test-case #t "#t")
(test-case #f "#f")
; characters
(test-case #\A "#\\A")
; null
(test-case '() "()"))
(test-cases "Unary primitives"
;;; unary primitives
; add1
(test-case (add1 0) "1")
(test-case (add1 (add1 0)) "2")
(test-case (add1 (add1 -2)) "0")
; sub1
(test-case (sub1 0) "-1")
(test-case (sub1 (sub1 0)) "-2")
(test-case (sub1 (sub1 2)) "0")
; zero?
(test-case (zero? 0) "#t")
(test-case (zero? 1) "#f")
(test-case (zero? -1) "#f")
(test-case (zero? #\t) "#f")
(test-case (zero? #\f) "#f")
; not
(test-case (not #f) "#t")
(test-case (not #t) "#f")
(test-case (not 0) "#f")
; null?
(test-case (null? '()) "#t")
(test-case (null? #f) "#f")
(test-case (sub1 (add1 0)) "0")
(test-case (add1 (sub1 0)) "0")
(test-case (sub1 (add1 123456789)) "123456789")
(test-case (add1 (sub1 123456789)) "123456789")
;; integer<->char
(test-case (integer->char 65) "#\\A")
(test-case (char->integer #\A) "65")
(test-case (integer->char (add1 (char->integer #\l))) "#\\m")
)
(test-cases "Binary primitives"
; +
(test-case (+ 2 2) "4")
(test-case (+ 0 0) "0")
(test-case (+ -1000 1000) "0")
(test-case (+ 2048 2048) "4096")
(test-case (+ (+ (+ 1 2)
(+ 3 4))
(+ (+ 5 6)
(+ 7 8))) "36")
; -
(test-case (- 4 2) "2")
(test-case (- 0 0) "0")
(test-case (- 0 1000) "-1000")
(test-case (- 4096 2048) "2048")
(test-case (- (- (- 2048 1024)
(- 1024 512))
(- (- 512 256)
(- 256 128))) "384")
(test-case (+ (- 4 2) (- 8 6)) "4")
(test-case (- (+ 100 100) (+ 10 10)) "180")
; =
(test-case (= 1 1) "#t")
(test-case (= 1 2) "#f")
(test-case (not (= 1 2)) "#t")
(test-case (= (+ 5 5) (+ 9 1)) "#t")
(test-case (= (- 30 10) (- 105 85)) "#t")
; <
(test-case (< 0 1) "#t")
(test-case (< 1 0) "#f")
(test-case (< 0 0) "#f")
; *
(test-case (* 1 0) "0")
(test-case (* 0 1) "0")
(test-case (* 1 1) "1")
(test-case (* 10 47) "470")
(test-case (* 47 10) "470")
(test-case (* -10 47) "-470")
(test-case (* -47 10) "-470")
(test-case (* (* (* 10 9)
(* 8 7))
(* (* 6 5)
(* 4 3))) "1814400")
(test-case (* (+ 30 70) (+ 35 65)) "10000")
(test-case (* (- 70 30) (- 90 50)) "1600")
(test-case (= (* (+ 10 20) (+ 30 40))
(+ (* 10 (+ 30 40))
(* 20 (+ 30 40))))
"#t")
;; bit shifting
(test-case (bitwise-arithmetic-shift 1 10) "1024")
(test-case (bitwise-arithmetic-shift-left 1 10) "1024")
(test-case (bitwise-arithmetic-shift-right 1 -10) "1024")
(test-case (bitwise-arithmetic-shift 65536 -6) "1024")
(test-case (bitwise-arithmetic-shift-left 65536 -6) "1024")
(test-case (bitwise-arithmetic-shift-right 65536 6) "1024")
(test-case (bitwise-arithmetic-shift-right 1 1) "0")
(test-case (bitwise-arithmetic-shift -1 10) "-1024")
(test-case (bitwise-arithmetic-shift-left -1 10) "-1024")
(test-case (bitwise-arithmetic-shift-right -1 -10) "-1024")
(test-case (bitwise-arithmetic-shift -65536 -6) "-1024")
(test-case (bitwise-arithmetic-shift-left -65536 -6) "-1024")
(test-case (bitwise-arithmetic-shift-right -65536 6) "-1024")
(test-case (bitwise-arithmetic-shift-right -1 1) "-1")
(test-case (bitwise-arithmetic-shift -65536 -15) "-2")
(test-case (bitwise-arithmetic-shift -65536 -16) "-1")
(test-case (bitwise-arithmetic-shift -65536 -17) "-1")
(test-case (bitwise-arithmetic-shift -65536 -30) "-1")
(test-case (bitwise-arithmetic-shift -65536 -32) "-1")
)
(test-cases "let"
(test-case (let ([b 10]) b) "10")
(test-case (let ([b 10])
(let ([b (+ b b)])
b))
"20")
(test-case (let ([a 10]
[b 20])
(let ([b a]
[a b])
(- a b)))
"10")
(test-case (let () 10 20) "20"))
(test-cases "if"
(test-case (if #t 20 30) "20")
(test-case (if (< 0 1) 1 0) "1")
(test-case (if (< 66 (char->integer #\A)) 9 5) "5")
(test-case (if (< 66 (char->integer #\B)) 9 5) "5")
(test-case (if (< 66 (char->integer #\C)) 9 5) "9")
(test-case (let ([a (* (+ 30 70) (+ 35 65))])
(let ([b (if (< 9000 a)
(* (* (* 10 9)
(* 8 7))
(* (* 6 5)
(* 4 3)))
(= (* (+ 10 20) (+ 30 40))
(+ (* 10 (+ 30 40))
(* 20 (+ 30 40)))))])
(* b 2)))
"3628800")
(test-case (let ([a (* (+ 300 70) (+ 350 65))])
(let ([b (if (< 9000 a)
(* (* (* 10 9)
(* 8 7))
(* (* 6 5)
(* 4 3)))
(= (* (+ 10 20) (+ 30 40))
(+ (* 10 (+ 30 40))
(* 20 (+ 30 40)))))])
(not (not (not (not b))))))
"#t"))
(test-cases "cons"
(test-case (car (cons 10 20)) "10")
(test-case (cdr (cons 10 20)) "20")
(test-case (car (cons 10 (cons 15 20))) "10")
(test-case (cadr (cons 10 (cons 15 20))) "15")
(test-case (cddr (cons 10 (cons 15 20))) "20")
(test-case (let ([l (cons 1 (cons 2 (cons 3 ( cons 4 (cons 5 '())))))])
(car l))
"1")
(test-case (let ([l (cons 1 (cons 2 (cons 3 ( cons 4 (cons 5 '())))))])
(car (cdr l))) "2")
(test-case (let ([l (cons 1 (cons 2 (cons 3 ( cons 4 (cons 5 '())))))])
(caddr l)) "3")
(test-case (let ([l (cons 1 (cons 2 (cons 3 ( cons 4 (cons 5 '())))))])
(cadr (cddr l))) "4")
(test-case (let ([l (cons 1 (cons 2 (cons 3 ( cons 4 (cons 5 '())))))])
(caddr (cddr l))) "5")
(test-case (let ([l (cons 1 (cons 2 (cons 3 ( cons 4 (cons 5 '())))))])
(null? (cdr (cddr (cddr l))))) "#t")
(test-case (cons 10 20)
"(10 . 20)")
(test-case (cons
(cons 10 (cons 20 '()))
(cons
(cons 30 (cons 40 '()))
'()))
"((10 20) (30 40))"))
(test-cases "procedures"
(test-case
(let ([ten (lambda () 10)])
(ten))
"10")
(test-case
(let ([eleven (lambda () (add1 10))])
(eleven))
"11")
(test-case
(let ([double (lambda (x) (* x 2))])
(double 10))
"20")
(test-case
(let ([double (lambda (x) (* x 2))])
(double (double 10)))
"40")
(test-case
(let ([double (lambda (x) (* x 2))]
[triple (lambda (x) (* x 3))])
(= (double (triple #xff0000))
(triple (double #xff0000))))
"#t")
(test-case
(let ([add (lambda (a b) (+ a b))])
(add 20 20))
"40")
(test-case
(let ([g (lambda (f) (f 20 20))]
[add (lambda (a b) (+ a b))])
(g add))
"40")
(test-case (let ([add (lambda (x y) (+ x y))]
[mul (lambda (x y) (* x y))])
(mul
(add 10 15)
(add 20 25)))
"1125")
(test-case (let ([fxid (lambda (n self) (if (zero? n) n (add1 (self (sub1 n) self))))])
(fxid 0 fxid))
"0")
(test-case (let ([fxid (lambda (n self) (if (zero? n) n (add1 (self (sub1 n) self))))])
(fxid 1 fxid))
"1")
(test-case (let ([fxid (lambda (n self) (if (zero? n) n (add1 (self (sub1 n) self))))])
(fxid 2 fxid))
"2")
(test-case (let ([len (lambda (l len) (if (null? l) 0 (+ 1 (len (cdr l) len))))])
(len '() len))
"0")
(test-case (let ([mkl (lambda (n self) (if (zero? n) '() (cons #f (self (sub1 n) self))))])
(mkl 5 mkl))
"(#f #f #f #f #f)")
(test-case
(let ([mkl (lambda (n self) (if (zero? n) '() (cons #f (self (sub1 n) self))))]
[len (lambda (l self) (if (null? l) 0 (add1 (self (cdr l) self))))])
(len (mkl 5 mkl) len))
"5")
(test-case
(let ([fib (lambda (n self)
(if (zero? n) 1
(if (= 1 n) 1
(+ (self (- n 1) self)
(self (- n 2) self)))))])
(fib 33 fib))
"5702887")
(test-case
(let ([add (lambda (a b) (+ a b))])
(let ([c 10] [d 20] [e 30] [f 40] [g 50] [h 60] [i 70] [j 80])
(* (add (add (add c d) e) f)
(add (add (add g h) i) j))))
"26000")
)
(test-cases "tail calls"
; this one does no allocation, so it just pressures stack frames
(test-case
(let ([fxid-helper
(lambda (n acc self)
(if (zero? n)
acc
(self (sub1 n) (add1 acc) self)))])
(let ([fxid (lambda (n helper)
(helper n 0 helper))])
(fxid 5000000 fxid-helper)))
"5000000")
(test-case
(let ([add (lambda (a b) (+ a b))])
(let ([f (lambda (add)
(let ([c 10] [d 20] [e 30] [f 40] [g 50] [h 60] [i 70] [j 80])
(* (add (add (add c d) e) f)
(add (add (add g h) i) j))))])
(f add)))
"26000")
)
(test-cases "closures"
; This closes over variables but it has no recursion and no tail calls.
(test-case
(let ([incr (lambda (x) (add1 x))])
(let ([id (lambda (x) (sub1 (incr x)))])
(id 10)))
"10")
; Close over distant variables
(test-case
((((lambda (x)
(lambda (y)
(lambda (z)
(+ z (+ x y)))))
10) 20) 30)
"60")
; Confuse me with names
(test-case
((let ([ten 10])
(lambda (x) (+ ten x)))
20)
"30")
; This one has recursion, but not in tail position.
(test-case
(let ([id-helper (lambda (in out self)
(if (zero? in)
out
(if (= 1 in)
(add1 out)
(add1 (self
(- in 2)
(+ out 1)
self)))))])
(let ([id (lambda (x)
(id-helper x 0 id-helper))])
(id 10)))
"10")
; This has only non-recursive tail calls
(test-case
(let ([incr (lambda (x c) (c (add1 x)))])
(let ([id (lambda (x)
(incr x (lambda (x) (sub1 x))))])
(id 10)))
"10")
; Attempt to clobber closed-over variables.
(test-case
(let ([a 10] [b 100])
(let ([*a (lambda (x c) (c (* a x)))]
[*b (lambda (x c) (c (* b x)))])
(let ([f (lambda ()
(*b 7 (lambda (hundreds)
(*a 2 (lambda (tens)
(+ hundreds tens))))))])
(f))))
"720")
)
)
(module+ main
(runtests)))
| false |
0c0bcbf155d6aba531c46c004d19c919cf2f65d6
|
1a64a1cff5ce40644dc27c2d951cd0ce6fcb6442
|
/testing/test-mixin-accumulator.scm
|
45650e9de06d37b8c3e85909980d274aa0417846
|
[] |
no_license
|
skchoe/2007.rviz-objects
|
bd56135b6d02387e024713a9f4a8a7e46c6e354b
|
03c7e05e85682d43ab72713bdd811ad1bbb9f6a8
|
refs/heads/master
| 2021-01-15T23:01:58.789250 | 2014-05-26T17:35:32 | 2014-05-26T17:35:32 | null | 0 | 0 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 4,653 |
scm
|
test-mixin-accumulator.scm
|
(module test-mixin-accumulator scheme
(require (lib "class.ss")
(lib "list.ss")
mzlib/etc
)
(define computing-interface<%>
(interface ()
object->renderer
convert-struct
))
;; domain data 1
(define obj-color-fish%
(class* object% (computing-interface<%>)
(super-new)
;...
(define/public (object->renderer num)
(printf "(to renderer) ~s \n" (+ num 100))
(+ num 100))
(define (process-elt elt)
(if (list? elt)
(if (empty? elt)
empty
(begin
(let* ((a (car elt))
(r (cdr elt)))
(append (process-elt a)
(process-elt r)))))
(when (number? elt)
(list (object->renderer elt)))))
(define/public (convert-struct root new-root)
(when (empty? new-root)
(set! new-root (build-list 0 identity)))
(if (not (empty? root))
(let* ([a (car root)]
[r (cdr root)])
(convert-struct r (append new-root (process-elt a))))
new-root))
))
identity
;; domain data 2
(define obj-file-fish%
(class* object% (computing-interface<%>)
(super-new)
(define/public object->renderer
(lambda (num)
(printf "(to renderer) ~s\n" (* num 100))
(* num 100)))
(define/public (convert-struct root new-root)
(printf "(file-fish)convert-struct\n")
(map (lambda (x) (object->renderer x)) root))
))
; structures
(define simple-tree (list 0 (list 1 2 3) (list 4 5 (list 6 7))))
(define simple-list (list 0 1 2 3 4 5 6))
; object testing
(define color-fish-obj (new obj-color-fish% ))
(define obj-file-fish-obj (new obj-file-fish%))
;; example mixin
(define (to-scene-graph-mixin %)
(unless (implementation? % computing-interface<%>)
(error "render-mixin:the class doesn't implement computing interface\n"))
(class* % ()
(super-new)
)
)
(printf "1.-----------------------------\n")
; (define (is-render? o) (is-a? o render-interface))
(define sg-color-fish% (to-scene-graph-mixin obj-color-fish%))
(define sg-obj-fish% (to-scene-graph-mixin obj-file-fish%))
; derived class -> 2 different object by 2 different parents
(define color-child-obj (new sg-color-fish%))
(define obj-child-obj (new sg-obj-fish%))
(define sg-color (send color-child-obj convert-struct simple-tree null))
(define sg-obj-file (send obj-child-obj convert-struct simple-list null))
sg-color
sg-obj-file
(printf "2.-----------------------------\n")
(define object-mixin->sg
(lambda (mxn stc)
(let* ([mxn-obj (new mxn)])
(send mxn-obj convert-struct stc null))))
(define tree->sg
(lambda (tree-class% tree)
(object-mixin->sg (to-scene-graph-mixin tree-class%) tree)))
(define list->sg
(lambda (list-class% list)
(object-mixin->sg (to-scene-graph-mixin list-class%) list)))
(define sg-color-1 (tree->sg obj-color-fish% simple-tree))
(define sg-obj-file-1 (list->sg obj-file-fish% simple-list))
sg-color-1
sg-obj-file-1
;; check for arbitray object->render function can be handled in mixin.
;; input: domain-dependent mixin w/ object->renderer
; ;; testing accumulator:
; (define decrease-vector
; (lambda (v)
; (let* ([size (vector-length v)]
; [v1 (for/fold ([out-list empty])
; ([i (build-list (- size 1) (lambda (x) x))])
; (cons (vector-ref v i) out-list))])
; (list->vector (reverse-list v1)))));(vector->list v1))))))
;
; (define reverse-list
; (lambda (lst)
; (for/fold ([out-list empty])
; ([i (build-list (length lst) (lambda (x) x))])
; (cons (list-ref lst i) out-list))))
;
;
; (define convert-struct-test
; (lambda (vect lst)
;
; (when (null? lst)
; (set! lst empty))
;
; (if (equal? 0 (vector-length vect))
; lst
; (let* ([elt (vector-ref vect (- (vector-length vect) 1))]
; [new-V (decrease-vector vect)]
; [new-L (cons elt lst)])
; (convert-struct-test new-V new-L)
; ))))
;
; (define initial-struct (vector 1 2 3 4 5 6))
; (convert-struct-test initial-struct null)
;
; (decrease-vector (vector 1 2 3 4))
; (reverse-list (list 1 2 3 4 5 6 7))
)
| false |
c4acb37ad145fe7ae5aa3e55bc5fbf8cb36f8650
|
19d8cf4dec462332df4a8889aff5d5c1cd07e1f5
|
/exercises/software-engineering/08/stream.scm
|
610c62b1ba84b14883cdf7abe88d4e4b724b1b38
|
[
"MIT"
] |
permissive
|
gabrinka/fp-2019-20
|
b3da19fdbb5196738d241de18f0513ceb4c463ed
|
c6b83cf1e0ea4cabb7dbd7897214aa3894ea1713
|
refs/heads/master
| 2020-09-23T23:34:19.045854 | 2019-12-03T11:54:35 | 2019-12-03T11:55:42 | null | 0 | 0 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 257 |
scm
|
stream.scm
|
(define empty-stream '())
(define-syntax cons-stream
(syntax-rules ()
((cons-stream h t)
(cons h (delay t)))))
(define (empty-stream? s)
(equal? s empty-stream))
(define head car)
(define (tail s)
(force (cdr s)))
| true |
f2e4a29eaab4f51bb457e38b27f7a4061de99305
|
a8216d80b80e4cb429086f0f9ac62f91e09498d3
|
/lib/chibi/iset/base.sld
|
fc7f60993b9b1bbed312c5228da9486564eb88cc
|
[
"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 | 577 |
sld
|
base.sld
|
(define-library (chibi iset base)
(cond-expand
(chibi (import (chibi) (srfi 9)))
(else (import (scheme base))))
(cond-expand
((library (srfi 151)) (import (srfi 151)))
((library (srfi 33)) (import (srfi 33)))
(else (import (srfi 60))))
(include "base.scm")
(cond-expand ;; workaround for #1342
(chicken (begin (define Integer-Set #f)))
(else))
(export
%make-iset make-iset iset? iset-contains? Integer-Set
iset-start iset-end iset-bits iset-left iset-right
iset-start-set! iset-end-set! iset-bits-set! iset-left-set! iset-right-set!))
| false |
6466abb7cc472d80734b9dd9e55e4470a922e3fe
|
a8216d80b80e4cb429086f0f9ac62f91e09498d3
|
/lib/chibi/parse-test.sld
|
f39aeffffa1068ee651795378c2893981630862a
|
[
"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 | 5,618 |
sld
|
parse-test.sld
|
(define-library (chibi parse-test)
(export run-tests)
(import (scheme base) (scheme char)
(chibi test) (chibi parse) (chibi parse common))
(cond-expand
(chibi (import (chibi char-set) (chibi char-set ascii)))
(else (import (srfi 14))))
(begin
(define (run-tests)
(test-begin "parse")
;; basic
(test-assert (parse parse-epsilon ""))
(test-assert (parse-fully parse-epsilon ""))
(test-error (parse-fully parse-epsilon "a"))
(test-not (parse parse-anything ""))
(test-assert (parse-fully parse-anything "a"))
(test-error (parse-fully parse-anything "ab"))
(test-not (parse parse-nothing ""))
(test-not (parse parse-nothing "a"))
(test-error (parse-fully parse-nothing ""))
(test-not (parse (parse-char #\a) ""))
(test-assert (parse-fully (parse-char #\a) "a"))
(test-not (parse (parse-char #\a) "b"))
(test-error (parse-fully (parse-char #\a) "ab"))
(let ((f (parse-seq (parse-char #\a) (parse-char #\b))))
(test-not (parse f "a"))
(test-not (parse f "b"))
(test-assert (parse f "ab"))
(test-error (parse-fully f "abc")))
(let ((f (parse-or (parse-char #\a) (parse-char #\b))))
(test-not (parse f ""))
(test-assert (parse f "a"))
(test-assert (parse f "b"))
(test-error (parse-fully f "ab")))
(let ((f (parse-not (parse-char #\a))))
(test-assert (parse f ""))
(test-error (parse-fully f "a"))
(test-assert (parse f "b")))
(let ((f (parse-repeat (parse-char #\a))))
(test-assert (parse-fully f ""))
(test-assert (parse-fully f "a"))
(test-assert (parse-fully f "aa"))
(test-assert (parse-fully f "aaa"))
(test-assert (parse f "b"))
(test-assert (parse f "aab"))
(test-error (parse-fully f "aab")))
(let ((f (parse-seq (parse-char #\a)
(parse-ignore (parse-char #\b)))))
(test '(#\a) (parse f "ab")))
(let ((f (parse-seq (parse-char #\a)
(parse-ignore (parse-char #\b))
(parse-char #\c))))
(test '(#\a #\c) (parse f "abc")))
;; grammars
(let ()
(define-grammar calc
(space ((* ,char-set:whitespace)))
(number ((=> n (+ ,char-set:digit))
(string->number (list->string n))))
(simple ((=> n ,number) n)
((: "(" (=> e1 ,term) ")") e1))
(term-op ("*" *)
("/" /)
("%" modulo))
(term ((: (=> e1 ,simple) ,space (=> op ,term-op)
,space (=> e2 ,term))
(op e1 e2))
((=> e1 ,simple)
e1)))
(test 88 (parse term "4*22"))
(test 42 (parse term "42"))
;; partial match (grammar isn't checking end)
(test 42 (parse term "42*")))
(let ()
(define calculator
(grammar expr
(space ((: ,char-set:whitespace ,space))
(() #f))
(digit ((=> d ,char-set:digit) d))
(number ((=> n (+ ,digit))
(string->number (list->string n))))
(simple ((=> n ,number) n)
((: "(" (=> e1 ,expr) ")") e1))
(term-op ("*" *)
("/" /)
("%" modulo))
(term ((: (=> e1 ,simple) ,space (=> op ,term-op) ,space
(=> e2 ,term))
(op e1 e2))
((=> e1 ,simple)
e1))
(expr-op ("+" +) ("-" -))
(expr ((: ,space (=> e1 ,term) ,space (=> op ,expr-op) ,space
(=> e2 ,expr))
(op e1 e2))
((: ,space (=> e1 ,term))
e1))))
(test 42 (parse calculator "42"))
(test 4 (parse calculator "2 + 2"))
(test 23 (parse calculator "2 + 2*10 + 1"))
(test 25 (parse calculator "2+2 * 10+1 * 3"))
(test 41 (parse calculator "(2 + 2) * 10 + 1")))
(let ()
(define prec-calc
(grammar expr
(simple (,(parse-integer))
((: "(" (=> e1 ,expr) ")") e1))
(op
("+" '+) ("-" '-) ("*" '*) ("/" '/) ("^" '^))
(expr
(,(parse-binary-op op
`((+ 5) (- 5) (* 3) (/ 3) (^ 1 right))
simple)))))
(test 42 (parse prec-calc "42"))
(test '(+ 2 2) (parse prec-calc "2 + 2"))
(test '(+ (+ 2 2) 2) (parse prec-calc "2 + 2 + 2"))
(test '(+ (+ 2 (* 2 10)) 1) (parse prec-calc "2 + 2*10 + 1"))
(test '(+ (+ 2 (* 2 10)) (* 1 3)) (parse prec-calc "2+2 * 10+1 * 3"))
(test '(+ (* (+ 2 2) 10) 1) (parse prec-calc "(2 + 2) * 10 + 1"))
(test '(^ 2 (^ 2 2)) (parse prec-calc "2 ^ 2 ^ 2"))
(test '(+ (+ (+ 1 (* (* 2 (^ 3 (^ 4 5))) 6)) (^ 7 8)) 9)
(parse prec-calc "1 + 2 * 3 ^ 4 ^ 5 * 6 + 7 ^ 8 + 9")))
;; this takes exponential time without memoization
(let ()
(define explode
(grammar start
(start ((: ,S eos) #t))
(S ((+ ,A) #t))
(A ((: "a" ,S "b") #t)
((: "a" ,S "c") #t)
((: "a") #t))))
(test-assert (parse explode "aaabb"))
(test-not (parse explode "bbaa"))
(test-assert
(parse explode
(string-append (make-string 10 #\a) (make-string 8 #\c)))))
(test-end))))
| false |
f3ce572ac8f389966cedb78280b0d3028c300773
|
6b288a71553cf3d8701fe7179701d100c656a53c
|
/s/pdhtml.ss
|
7b583844d8ce6432373f2b210804fdd7f5af18b9
|
[
"Apache-2.0"
] |
permissive
|
cisco/ChezScheme
|
03e2edb655f8f686630f31ba2574f47f29853b6f
|
c048ad8423791de4bf650fca00519d5c2059d66e
|
refs/heads/main
| 2023-08-26T16:11:15.338552 | 2023-08-25T14:17:54 | 2023-08-25T14:17:54 | 56,263,501 | 7,763 | 1,410 |
Apache-2.0
| 2023-08-28T22:45:52 | 2016-04-14T19:10:25 |
Scheme
|
UTF-8
|
Scheme
| false | false | 70,304 |
ss
|
pdhtml.ss
|
;;; pdhtml.ss
;;; Copyright 1984-2017 Cisco Systems, Inc.
;;;
;;; Licensed under the Apache License, Version 2.0 (the "License");
;;; you may not use this file except in compliance with the License.
;;; You may obtain a copy of the License at
;;;
;;; http://www.apache.org/licenses/LICENSE-2.0
;;;
;;; Unless required by applicable law or agreed to in writing, software
;;; distributed under the License is distributed on an "AS IS" BASIS,
;;; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
;;; See the License for the specific language governing permissions and
;;; limitations under the License.
;;; NOTES:
;;; - fixed bug in define-tags: moved (void) end of text ... to start
;;;
;;; - to change palette to use white background with colorized text:
;;; (profile-palette
;;; (vector-map
;;; (lambda (p) (cons "white" (car p)))
;;; (profile-palette)))
;;; profile-dump-html suggestions from Oscar:
;;;
;;; We could probably build a table mapping source regions to procedure names
;;; in enough cases to actually be useful. If so, showing procedure name instead
;;; of line/char position would help the user get a high-level perspective on the
;;; profile results. Right now the user has to synthesize that perspective by
;;; remembering where each link led.
;;;
;;; Within the file view window, it would be nice to have a way to scan quickly
;;; through the hot spots within that file (we have some obscenely large source
;;; files at work). Perhaps you could reprise the profile spectrum horizontally
;;; in a short frame at the top of the window and rig it so that dragging, scroll
;;; wheel, or clicking on a color cycles through the regions tagged with that col>
;;;
;;; With a large range of profile counts to compress into a fairly small
;;; spectrum, it might be nice if there were a way to zoom into a range by
;;; clicking on the legend, either in the overview window or the file window.
;;; Reallocating the color map could be confusing with multiple windows open,
;;; but perhaps there's some javascript way to rig all the other colors to
;;; desaturate when you zoom into a range in one window. Perhaps intensity
;;; could be used to show the sub-ranges in varying shades of the main legend
;;; color.
;;;
;;; I notice that the profile annotations on the when expressions start at the te>
;;; expression rather than the start of the when. Yet the if expression annotati>
;;; starts at the beginning of the if expression and extends to the closing paren.
;;; Not sure if that made any sense, basically I'm trying to say that the "(when"
;;; itself (and closing paren) isn't colored the same as the test part.
;;; I don't remember exactly how we handled source annotations during wrapping and
;;; unwrapping, but it seems offhand that it might make sense to wrap the input
;;; source annotation around the transformer output so that the source info for t>
;;; when expression is transferred to the generated if expression.
(begin
(let ()
(include "types.ss")
(module (make-tracker tracker-profile-ct)
(define-record-type tracker
(nongenerative)
(fields profile-ct)))
(define-record-type cc
(nongenerative)
(fields (mutable cookie) (mutable total) (mutable current) (mutable preceding)))
(define-record-type (source-table $make-source-table $source-table?)
(nongenerative)
(sealed #t)
(opaque #t)
(fields ht)
(protocol
(lambda (new)
(lambda ()
(define sfd-hash
(lambda (sfd)
(source-file-descriptor-crc sfd)))
(define sfd=?
(lambda (sfd1 sfd2)
(and (fx= (source-file-descriptor-crc sfd1) (source-file-descriptor-crc sfd2))
(= (source-file-descriptor-length sfd1) (source-file-descriptor-length sfd2))
(string=? (source-file-descriptor-name sfd1) (source-file-descriptor-name sfd2)))))
(new (make-hashtable sfd-hash sfd=?))))))
(define *local-profile-trackers* '())
(define op+ car)
(define op- cdr)
(define count+ (constant-case ptr-bits [(32) +] [(64) fx+]))
(define count- (constant-case ptr-bits [(32) -] [(64) fx-]))
(define count< (constant-case ptr-bits [(32) <] [(64) fx<]))
(define get-counter-list (foreign-procedure "(cs)s_profile_counters" () ptr))
(define release-counters (foreign-procedure "(cs)s_profile_release_counters" () ptr))
(define rblock-count
(lambda (rblock)
(let sum ((op (rblock-op rblock)))
(if (profile-counter? op)
(profile-counter-count op)
; using #3%fold-left in case the #2% versions are profiled
(#3%fold-left
(lambda (a op) (count- a (sum op)))
(#3%fold-left (lambda (a op) (count+ a (sum op))) 0 (op+ op))
(op- op))))))
(define profile-counts
; like profile-dump but returns ((count . (src ...)) ...)
(case-lambda
[() (profile-counts (get-counter-list))]
[(counter*)
; disabling interrupts so we don't sum part of the counters for a block before
; an interrupt and the remaining counters after the interrupt, which can lead
; to inaccurate (and possibly negative) counts. we could disable interrupts just
; around the body of rblock-count to shorten the windows during which interrupts
; are disabled, but doing it here incurs less overhead
(with-interrupts-disabled
(fold-left
(lambda (r x)
(fold-left
(lambda (r rblock)
(cons (cons (rblock-count rblock) (rblock-srecs rblock)) r))
r (cdr x)))
'() counter*))]))
(define (snapshot who uncleared-count* cleared-count*)
(lambda (tracker)
(define cookie (cons 'vanilla 'wafer))
; set current corresponding to each src to a total of its counts
(let ([incr-current
(lambda (count.src*)
(let ([count (car count.src*)])
(for-each
(lambda (src)
(let ([a ($source-table-cell (tracker-profile-ct tracker) src #f)])
(when (count< count 0) (errorf who "negative profile count ~s for ~s" count src))
(let ([cc (cdr a)])
(if cc
(if (eq? (cc-cookie cc) cookie)
(cc-current-set! cc (count+ (cc-current cc) count))
(begin
(cc-cookie-set! cc cookie)
(cc-current-set! cc count)))
(set-cdr! a (make-cc cookie 0 count 0))))))
(cdr count.src*))))])
(for-each incr-current uncleared-count*)
(for-each incr-current cleared-count*))
; then increment total of each affected cc by the delta between current and preceding
(source-table-for-each
(lambda (src cc)
(when (eq? (cc-cookie cc) cookie)
(let ([current (cc-current cc)])
(let ([delta (count- current (cc-preceding cc))])
(unless (eqv? delta 0)
(when (count< delta 0) (errorf who "total profile count for ~s dropped from ~s to ~s" src (cc-preceding cc) current))
(cc-total-set! cc (count+ (cc-total cc) delta))
(cc-preceding-set! cc current))))))
(tracker-profile-ct tracker))
; then reduce preceding by cleared counts
(for-each
(lambda (count.src*)
(let ([count (car count.src*)])
(for-each
(lambda (src)
(let ([a ($source-table-cell (tracker-profile-ct tracker) src #f)])
(let ([cc (cdr a)])
(if cc
(cc-preceding-set! cc (count- (cc-preceding cc) count))
(set-cdr! a (make-cc cookie 0 0 0))))))
(cdr count.src*))))
cleared-count*)))
(define adjust-trackers!
(lambda (who uncleared-counter* cleared-counter*)
(let ([local-tracker* *local-profile-trackers*])
(unless (null? local-tracker*)
(let ([uncleared-count* (profile-counts uncleared-counter*)]
[cleared-count* (profile-counts cleared-counter*)])
(let ([snapshot (snapshot who uncleared-count* cleared-count*)])
(for-each snapshot local-tracker*)))))))
(define $source-table-contains?
(lambda (st src)
(let ([src-ht (hashtable-ref (source-table-ht st) (source-sfd src) #f)])
(and src-ht (hashtable-contains? src-ht src)))))
(define $source-table-ref
(lambda (st src default)
(let ([src-ht (hashtable-ref (source-table-ht st) (source-sfd src) #f)])
(if src-ht (hashtable-ref src-ht src default) default))))
(define $source-table-cell
(lambda (st src default)
(define same-sfd-src-hash
(lambda (src)
(source-bfp src)))
(define same-sfd-src=?
(lambda (src1 src2)
(and (= (source-bfp src1) (source-bfp src2))
(= (source-efp src1) (source-efp src2)))))
(let ([src-ht (let ([a (hashtable-cell (source-table-ht st) (source-sfd src) #f)])
(or (cdr a)
(let ([src-ht (make-hashtable same-sfd-src-hash same-sfd-src=?)])
(set-cdr! a src-ht)
src-ht)))])
(hashtable-cell src-ht src default))))
(define $source-table-delete!
(lambda (st src)
(let ([ht (source-table-ht st)] [sfd (source-sfd src)])
(let ([src-ht (hashtable-ref ht sfd #f)])
(when src-ht
(hashtable-delete! src-ht src)
(when (fx= (hashtable-size src-ht) 0)
(hashtable-delete! ht sfd)))))))
(define source-table-for-each
(lambda (p st)
(vector-for-each
(lambda (src-ht)
(let-values ([(vsrc vcount) (hashtable-entries src-ht)])
(vector-for-each p vsrc vcount)))
(hashtable-values (source-table-ht st)))))
(set-who! profile-clear
(lambda ()
(define clear-links
(lambda (op)
(if (profile-counter? op)
(profile-counter-count-set! op 0)
(begin
(for-each clear-links (op+ op))
(for-each clear-links (op- op))))))
(let ([counter* (get-counter-list)])
(adjust-trackers! who '() counter*)
(for-each
(lambda (x)
(for-each
(lambda (node) (clear-links (rblock-op node)))
(cdr x)))
counter*))))
(set-who! profile-release-counters
(lambda ()
; release-counters prunes out (and hands back) the released counters
(let* ([dropped-counter* (release-counters)]
[kept-counter* (get-counter-list)])
(adjust-trackers! who kept-counter* dropped-counter*))))
(set-who! profile-dump
; like profile-counts but returns ((src . count) ...), which requires more allocation
; profile-dump could use profile-counts but that would require even more allocation
(lambda ()
; could disable interrupts just around each call to rblock-count, but doing it here incurs less overhead
(with-interrupts-disabled
(fold-left
(lambda (r x)
(fold-left
(lambda (r rblock)
(let ([count (rblock-count rblock)])
(fold-left
(lambda (r src)
(cons (cons src count) r))
r (rblock-srecs rblock))))
r (cdr x)))
'() (get-counter-list)))))
(set-who! make-source-table
(lambda ()
($make-source-table)))
(set-who! source-table?
(lambda (x)
($source-table? x)))
(set-who! source-table-size
(lambda (st)
(unless ($source-table? st) ($oops who "~s is not a source table" st))
(let ([vsrc-ht (hashtable-values (source-table-ht st))])
(let ([n (vector-length vsrc-ht)])
(do ([i 0 (fx+ i 1)] [size 0 (fx+ size (hashtable-size (vector-ref vsrc-ht i)))])
((fx= i n) size))))))
(set-who! source-table-contains?
(lambda (st src)
(unless ($source-table? st) ($oops who "~s is not a source table" st))
(unless (source? src) ($oops who "~s is not a source object" src))
($source-table-contains? st src)))
(set-who! source-table-ref
(lambda (st src default)
(unless ($source-table? st) ($oops who "~s is not a source table" st))
(unless (source? src) ($oops who "~s is not a source object" src))
($source-table-ref st src default)))
(set-who! source-table-set!
(lambda (st src val)
(unless ($source-table? st) ($oops who "~s is not a source table" st))
(unless (source? src) ($oops who "~s is not a source object" src))
(set-cdr! ($source-table-cell st src #f) val)))
(set-who! source-table-delete!
(lambda (st src)
(unless ($source-table? st) ($oops who "~s is not a source table" st))
(unless (source? src) ($oops who "~s is not a source object" src))
($source-table-delete! st src)))
(set-who! source-table-cell
(lambda (st src default)
(unless ($source-table? st) ($oops who "~s is not a source table" st))
(unless (source? src) ($oops who "~s is not a source object" src))
($source-table-cell st src default)))
(set-who! source-table-dump
(lambda (st)
(unless ($source-table? st) ($oops who "~s is not a source table" st))
(let* ([vsrc-ht (hashtable-values (source-table-ht st))]
[n (vector-length vsrc-ht)])
(do ([i 0 (fx+ i 1)]
[dumpit* '()
(let-values ([(vsrc vcount) (hashtable-entries (vector-ref vsrc-ht i))])
(let ([n (vector-length vsrc)])
(do ([i 0 (fx+ i 1)]
[dumpit* dumpit*
(cons (cons (vector-ref vsrc i) (vector-ref vcount i)) dumpit*)])
((fx= i n) dumpit*))))])
((fx= i n) dumpit*)))))
(set-who! put-source-table
(lambda (op st)
(unless (and (output-port? op) (textual-port? op)) ($oops who "~s is not a textual output port" op))
(unless ($source-table? st) ($oops who "~s is not a source table" st))
(fprintf op "(source-table")
(let-values ([(vsfd vsrc-ht) (hashtable-entries (source-table-ht st))])
(vector-for-each
(lambda (sfd src-ht)
(let-values ([(vsrc vval) (hashtable-entries src-ht)])
(let ([n (vector-length vsrc)])
(unless (fx= n 0)
(fprintf op "\n (file ~s ~s"
(source-file-descriptor-name sfd)
(source-file-descriptor-checksum sfd))
(let ([v (vector-sort (lambda (x1 x2) (< (vector-ref x1 0) (vector-ref x2 0)))
(vector-map (lambda (src val) (vector (source-bfp src) (source-efp src) val)) vsrc vval))])
(let loop ([i 0] [last-bfp 0])
(unless (fx= i n)
(let ([x (vector-ref v i)])
(let ([bfp (vector-ref x 0)] [efp (vector-ref x 1)] [val (vector-ref x 2)])
(let ([offset (- bfp last-bfp)] [len (- efp bfp)])
(fprintf op " (~s ~s ~s)" offset len val))
(loop (fx+ i 1) bfp))))))
(fprintf op ")")))))
vsfd vsrc-ht))
(fprintf op ")\n")))
(set-who! get-source-table!
(rec get-source-table!
(case-lambda
[(ip st) (get-source-table! ip st #f)]
[(ip st combine)
(define (nnint? x) (and (integer? x) (exact? x) (nonnegative? x)))
(define (token-oops what bfp)
(if bfp
($oops who "expected ~a at file position ~s of ~s" what bfp ip)
($oops who "malformed source table reading from ~a" ip)))
(define (next-token expected-type expected-value? what)
(let-values ([(type val bfp efp) (read-token ip)])
(unless (and (eq? type expected-type) (expected-value? val)) (token-oops what bfp))
val))
(unless (and (input-port? ip) (textual-port? ip)) ($oops who "~s is not a textual input port" ip))
(unless ($source-table? st) ($oops who "~s is not a source table" st))
(unless (or (not combine) (procedure? combine)) ($oops who "~s is not a procedure" combine))
(next-token 'lparen not "open parenthesis")
(next-token 'atomic (lambda (x) (eq? x 'source-table)) "identifier 'source-table'")
(let file-loop ()
(let-values ([(type val bfp efp) (read-token ip)])
(unless (eq? type 'rparen)
(unless (eq? type 'lparen) (token-oops "open parenthesis" bfp))
(next-token 'atomic (lambda (x) (eq? x 'file)) "identifier 'file'")
(let* ([path (next-token 'atomic string? "string")]
[checksum (next-token 'atomic nnint? "checksum")])
(let ([sfd (#%source-file-descriptor path checksum)])
(let entry-loop ([last-bfp 0])
(let-values ([(type val bfp efp) (read-token ip)])
(unless (eq? type 'rparen)
(unless (eq? type 'lparen) (token-oops "open parenthesis" bfp))
(let* ([bfp (+ last-bfp (next-token 'atomic nnint? "file position"))]
[efp (+ bfp (next-token 'atomic nnint? "file position"))]
[val (get-datum ip)])
(next-token 'rparen not "close parenthesis")
(let ([a ($source-table-cell st (make-source-object sfd bfp efp) #f)])
(set-cdr! a
(if (and (cdr a) combine)
(combine (cdr a) val)
val)))
(entry-loop bfp)))))))
(file-loop))))])))
(set-who! with-profile-tracker
(rec with-profile-tracker
(case-lambda
[(thunk) (with-profile-tracker #f thunk)]
[(include-existing-counts? thunk)
(define extract-covered-entries
(lambda (profile-ct)
(let ([covered-ct ($make-source-table)])
(source-table-for-each
(lambda (src cc)
(let ([count (cc-total cc)])
(unless (eqv? count 0)
($source-table-cell covered-ct src count))))
profile-ct)
covered-ct)))
(unless (procedure? thunk) ($oops who "~s is not a procedure" thunk))
(let* ([profile-ct ($make-source-table)]
[tracker (make-tracker profile-ct)])
(unless include-existing-counts?
; set preceding corresponding to each src to a total of its dumpit counts
; set total to zero, since we don't want to count anything from before
(for-each
(lambda (count.src*)
(let ([count (car count.src*)])
(for-each
(lambda (src)
(let ([a ($source-table-cell profile-ct src #f)])
(let ([cc (cdr a)])
(if cc
(cc-preceding-set! cc (count+ (cc-preceding cc) count))
(set-cdr! a (make-cc #f 0 0 count))))))
(cdr count.src*))))
(profile-counts)))
; register for possible adjustment by profile-clear and profile-release-counters
(let-values ([v* (fluid-let ([*local-profile-trackers* (cons tracker *local-profile-trackers*)]) (thunk))])
; increment the recorded counts by the now current counts.
((snapshot who (profile-counts) '()) tracker)
(apply values (extract-covered-entries profile-ct) v*)))]))))
(let ()
(include "types.ss")
(define check-dump
(lambda (who x)
(unless (and (list? x)
(andmap (lambda (x)
(and (pair? x)
(source-object? (car x))
(let ([x (cdr x)])
(and (integer? x) (exact? x)))))
x))
($oops who "invalid dump ~s" x))))
(define-record-type filedata
(fields
(immutable sfd)
(immutable ip)
(mutable entry*)
; remaining fields are ignored by profile-dump-list
(mutable max-count)
(mutable ci)
(mutable htmlpath)
(mutable htmlfn)
(mutable winid))
(nongenerative)
(sealed #t)
(protocol
(lambda (new)
(lambda (sfd ip)
(new sfd ip '() #f #f #f #f #f)))))
(define-record-type entrydata
(fields
(immutable fdata)
(immutable bfp)
(immutable efp)
(mutable count)
(mutable line)
(mutable char)
; ci is ignored by profile-dump-list
(mutable ci))
(nongenerative)
(sealed #t)
(protocol
(lambda (new)
(lambda (fdata bfp efp count)
(new fdata bfp efp count #f #f #f)))))
(define (gather-filedata who warn? dumpit*)
; returns list of fdata records, each holding a list of entries
; the entries are sorted based on their (unique) bfps
(let ([fdata-ht (make-hashtable
(lambda (x) (source-file-descriptor-crc x))
(lambda (x y)
; there's no way to make this foolproof, so we identify paths with
; same crc, length, and last component. this can cause problems
; only if two copies of the same file are loaded and used.
(or (eq? x y)
(and (= (source-file-descriptor-crc x)
(source-file-descriptor-crc y))
(= (source-file-descriptor-length x)
(source-file-descriptor-length y))
(string=?
(path-last (source-file-descriptor-name x))
(path-last (source-file-descriptor-name y)))))))])
(define (open-source sfd)
(cond
[(hashtable-ref fdata-ht sfd #f)]
[($open-source-file sfd) =>
(lambda (ip)
(let ([fdata (make-filedata sfd ip)])
(hashtable-set! fdata-ht sfd fdata)
fdata))]
[else
(when warn?
(warningf who
"unmodified source file ~s not found in source directories"
(source-file-descriptor-name sfd)))
(let ([fdata (make-filedata sfd #f)])
(hashtable-set! fdata-ht sfd fdata)
fdata)]))
(for-each
(lambda (dumpit)
(let ([source (car dumpit)])
(assert (source? source))
(let ([bfp (source-bfp source)])
(when (>= bfp 0) ; weed out block-profiling entries, whose bfps are negative
(let ([fdata (open-source (source-sfd source))])
(filedata-entry*-set! fdata
(cons (make-entrydata fdata bfp (source-efp source) (cdr dumpit))
(filedata-entry* fdata))))))))
dumpit*)
(let ([fdatav (hashtable-values fdata-ht)])
(vector-for-each
(lambda (fdata)
(let ([entry* (sort (lambda (x y)
(or (> (entrydata-bfp x) (entrydata-bfp y))
(and (= (entrydata-bfp x) (entrydata-bfp y))
(< (entrydata-efp x) (entrydata-efp y)))))
(filedata-entry* fdata))])
#;(assert (not (null? entry*)))
(let loop ([entry (car entry*)] [entry* (cdr entry*)] [new-entry* '()])
(if (null? entry*)
(filedata-entry*-set! fdata (cons entry new-entry*))
(if (and (= (entrydata-bfp (car entry*)) (entrydata-bfp entry))
(= (entrydata-efp (car entry*)) (entrydata-efp entry)))
(begin
(entrydata-count-set! entry
(+ (entrydata-count entry)
(entrydata-count (car entry*))))
(loop entry (cdr entry*) new-entry*))
(loop (car entry*) (cdr entry*) (cons entry new-entry*)))))))
fdatav)
(vector->list fdatav))))
(let ()
(define (scan-file fdata)
(let ([ip (filedata-ip fdata)] [line 1] [char 1])
(define (read-until bfp next)
(let loop ([bfp bfp])
(unless (= bfp next)
(cond
[(eqv? (read-char ip) #\newline)
(set! line (+ line 1))
(set! char 1)]
[else (set! char (+ char 1))])
(loop (+ bfp 1)))))
(let ([entry* (filedata-entry* fdata)]) ; already sorted by gather-filedata
(let f ([bfp 0] [entry* entry*])
(unless (null? entry*)
(let ([entry (car entry*)] [entry* (cdr entry*)])
(let ([next (entrydata-bfp entry)])
(read-until bfp next)
(entrydata-line-set! entry line)
(entrydata-char-set! entry char)
(f next entry*))))))))
(set-who! profile-dump-list
; return list of lists of:
; - count
; - path ; current if line and char are not #f
; - bfp
; - efp
; - line ; may be #f
; - char ; may be #f
(rec profile-dump-list
(case-lambda
[() (profile-dump-list #t)]
[(warn?) (profile-dump-list warn? (profile-dump))]
[(warn? dumpit*)
(check-dump who dumpit*)
(let ([fdata* (gather-filedata who warn? dumpit*)])
(for-each scan-file (remp (lambda (x) (not (filedata-ip x))) fdata*))
(let ([ls (map (lambda (entry)
(let ([fdata (entrydata-fdata entry)])
(list
(entrydata-count entry)
(cond
[(filedata-ip fdata) => port-name]
[else (source-file-descriptor-name
(filedata-sfd fdata))])
(entrydata-bfp entry)
(entrydata-efp entry)
(entrydata-line entry)
(entrydata-char entry))))
(sort
(lambda (x y) (> (entrydata-count x) (entrydata-count y)))
(apply append (map filedata-entry* fdata*))))])
(for-each
(lambda (fdata) (cond [(filedata-ip fdata) => close-input-port]))
fdata*)
ls))]))))
(let ()
(define-record-type profilit
(nongenerative #{profilit iw9f7z5ovg4jjetsvw5m0-2})
(sealed #t)
(fields sfd bfp efp weight))
(define make-profile-database
(lambda ()
(make-hashtable
source-file-descriptor-crc
(lambda (x y)
(or (eq? x y)
(and (= (source-file-descriptor-crc x)
(source-file-descriptor-crc y))
(= (source-file-descriptor-length x)
(source-file-descriptor-length y))
(string=?
(path-last (source-file-descriptor-name x))
(path-last (source-file-descriptor-name y)))))))))
(define profile-database #f)
(define profile-source-data? #f)
(define profile-block-data? #f)
(define update-sfd!
(lambda (cell sfd)
; if the recorded sfd is the same but not eq, it's likely from an earlier session.
; overwrite so remaining hashtable equality-procedure checks are more likely to
; succeed at the eq? check
(unless (eq? (car cell) sfd)
(set-car! cell sfd))))
(set-who! profile-clear-database
(lambda ()
(set! profile-database #f)))
(set-who! profile-dump-data
(rec profile-dump-data
(case-lambda
[(ofn) (profile-dump-data ofn (profile-dump))]
[(ofn dumpit*)
(check-dump who dumpit*)
(let ([op ($open-file-output-port who ofn (file-options replace))])
(on-reset (delete-file ofn #f)
(on-reset (close-port op)
(let* ([dump dumpit*] [max-count (inexact (fold-left max 1 (map cdr dump)))])
(for-each
(lambda (dumpit)
(let ([source (car dumpit)] [count (cdr dumpit)])
(fasl-write
(make-profilit (source-sfd source) (source-bfp source) (source-efp source)
; compute weight as % of max count
(fl/ (inexact count) max-count))
op)))
dump)))
(close-port op)))])))
(set! $profile-source-data? (lambda () profile-source-data?))
(set! $profile-block-data? (lambda () profile-block-data?))
(set-who! profile-load-data
(lambda ifn*
(define populate!
(lambda (x)
(unless (profilit? x) ($oops who "invalid profile data element ~s" x))
(unless profile-database (set! profile-database (make-profile-database)))
(let ([ht (let* ([sfd (profilit-sfd x)]
[cell (hashtable-cell profile-database sfd #f)])
(update-sfd! cell sfd)
(or (cdr cell)
(let ([ht (make-hashtable values =)])
(set-cdr! cell ht)
ht)))])
; each ht entry is an alist mapping efp -> (weight . n) where n is
; the number of contributing entries so far for this sfd, bfp, and efp.
; n is used to compute the average weight of the contributing entries.
(let ([bfp.alist (hashtable-cell ht (profilit-bfp x) '())])
(cond
[(assv (profilit-efp x) (cdr bfp.alist)) =>
(lambda (a)
(let ([weight.n (cdr a)])
(let ([weight (car weight.n)] [n (cdr weight.n)])
(let ([new-n (fl+ n 1.0)])
(set-car! weight.n (fl/ (fl+ (* weight n) (profilit-weight x)) new-n))
(set-cdr! weight.n new-n)))))]
[else (set-cdr! bfp.alist (cons (cons* (profilit-efp x) (profilit-weight x) 1.0) (cdr bfp.alist)))])))
(if (fxnegative? (profilit-bfp x))
(set! profile-block-data? #t)
(set! profile-source-data? #t))))
(define (load-file ifn)
(let ([ip ($open-file-input-port who ifn)])
(on-reset (close-port ip)
(let f ()
(let ([x (fasl-read ip)])
(unless (eof-object? x)
(with-tc-mutex (populate! x))
(f)))))
(close-port ip)))
(for-each
(lambda (ifn)
(unless (string? ifn) ($oops who "~s is not a string" ifn)))
ifn*)
(for-each load-file ifn*)))
(set! $profile-show-database
(lambda ()
(when profile-database
(let-values ([(sfd* ht*) (hashtable-entries profile-database)])
(vector-for-each
(lambda (sfd ht)
(printf "~a:\n" (source-file-descriptor-name sfd))
(let-values ([(bfp* alist*) (hashtable-entries ht)])
(vector-for-each
(lambda (bfp alist)
(for-each
(lambda (a) (printf " ~s, ~s: ~s\n" bfp (car a) (cadr a)))
alist))
bfp* alist*)))
sfd* ht*)))))
(set! profile-query-weight
(lambda (x)
(define src->weight
(lambda (src)
(cond
[(and profile-database
(let* ([sfd (source-object-sfd src)]
[ht (hashtable-ref profile-database sfd #f)])
(and ht
(begin
; could do just one lookup if we had a nondestructive variant of
; hashtable-cell to call above
(update-sfd! (hashtable-cell profile-database sfd #f) sfd)
ht)))) =>
(lambda (ht)
(let ([alist (hashtable-ref ht (source-object-bfp src) '())])
(cond
[(assv (source-object-efp src) alist) => cadr]
[(and (fxnegative? (source-object-bfp src)) (not (null? alist)))
($oops #f "block-profiling info is out-of-date for ~s"
(source-file-descriptor-name (source-object-sfd src)))]
; no info for given bfp, efp...assume dead code and return 0
[else 0.0])))]
; no info for given sfd...assume not profiled and return #f
[else #f])))
(if (source? x)
(src->weight x)
(let ([x (syntax->annotation x)])
(if (annotation? x)
(src->weight (annotation-source x))
#f))))))
(let ()
;;; The following copyright notice goes with the %html module.
;;; Copyright (c) 2005 R. Kent Dybvig
;;; 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.
(module %html ((<html> <*> attribute $tag)
(<head> <*> attribute $tag)
(<body> <*> attribute $tag)
(<script> <*> attribute $tag)
(<style> <*> attribute $tag)
(<title> <*> attribute $tag)
(<base> <*> attribute $tag)
(<link> <*> attribute $tag)
(<meta> <*> attribute $tag)
(<address> <*> attribute $tag)
(<blockquote> <*> attribute $tag)
(<del> <*> attribute $tag)
(<div> <*> attribute $tag)
(<h1> <*> attribute $tag)
(<h2> <*> attribute $tag)
(<h3> <*> attribute $tag)
(<h4> <*> attribute $tag)
(<h5> <*> attribute $tag)
(<h6> <*> attribute $tag)
(<ins> <*> attribute $tag)
(<noscript> <*> attribute $tag)
(<p> <*> attribute $tag)
(<pre> <*> attribute $tag)
(<hr> <*> attribute $tag)
(<dd> <*> attribute $tag)
(<dl> <*> attribute $tag)
(<dt> <*> attribute $tag)
(<li> <*> attribute $tag)
(<ol> <*> attribute $tag)
(<ul> <*> attribute $tag)
(<table> <*> attribute $tag)
(<caption> <*> attribute $tag)
(<colgroup> <*> attribute $tag)
(<thead> <*> attribute $tag)
(<tfoot> <*> attribute $tag)
(<tbody> <*> attribute $tag)
(<tr> <*> attribute $tag)
(<td> <*> attribute $tag)
(<th> <*> attribute $tag)
(<col> <*> attribute $tag)
(<form> <*> attribute $tag)
(<button> <*> attribute $tag)
(<fieldset> <*> attribute $tag)
(<legend> <*> attribute $tag)
(<label> <*> attribute $tag)
(<select> <*> attribute $tag)
(<optgroup> <*> attribute $tag)
(<option> <*> attribute $tag)
(<textarea> <*> attribute $tag)
(<input> <*> attribute $tag)
(<a> <*> attribute $tag)
(<bdo> <*> attribute $tag)
(<map> <*> attribute $tag)
(<object> <*> attribute $tag)
(<q> <*> attribute $tag)
(<span> <*> attribute $tag)
(<sub> <*> attribute $tag)
(<sup> <*> attribute $tag)
(<br> <*> attribute $tag)
(<img> <*> attribute $tag)
(<area> <*> attribute $tag)
(<param> <*> attribute $tag)
(<abbr> <*> attribute $tag)
(<acronym> <*> attribute $tag)
(<cite> <*> attribute $tag)
(<code> <*> attribute $tag)
(<dfn> <*> attribute $tag)
(<em> <*> attribute $tag)
(<kbd> <*> attribute $tag)
(<samp> <*> attribute $tag)
(<strong> <*> attribute $tag)
(<var> <*> attribute $tag)
(<b> <*> attribute $tag)
(<big> <*> attribute $tag)
(<i> <*> attribute $tag)
(<small> <*> attribute $tag)
(<tt> <*> attribute $tag)
<doctype>
html-text nbsp encode-url-parameter flush-html-output)
(define $tag
(lambda (tag attributes text end-tag)
(define (simple-value? s)
(define (simple-char? c)
(or (char<=? #\0 c #\9)
(char<=? #\a c #\z)
(char<=? #\A c #\Z)
(char=? c #\-)
(char=? c #\.)))
(let ([n (string-length s)])
(and (fx> n 0)
(let f ([i (fx- n 1)])
(and (simple-char? (string-ref s i))
(or (fx= i 0) (f (fx- i 1))))))))
(printf "<~a" tag)
(for-each
(lambda (a)
(if (pair? a)
(let ([value (let ([s (cdr a)])
(if (string? s)
s
(format "~a" (cdr a))))])
(if (simple-value? value)
(printf " ~a=~a" (car a) value)
(let ([n (string-length value)])
(printf " ~a=\"" (car a))
(do ([i 0 (fx+ i 1)])
((fx= i n) (write-char #\"))
(display
(let ([c (string-ref value i)])
(if (char=? c #\")
"""
(html-text-char c))))))))
(printf " ~a" a)))
attributes)
(printf ">")
(cond
[end-tag (let-values ([v* (text)])
(printf "</~a>" tag)
(apply values v*))]
[else (text)])))
(meta define <*>
(lambda (id)
(datum->syntax-object id
(string->symbol
(string-append "<" (symbol->string (syntax-object->datum id)) ">")))))
(meta define (attribute x)
(syntax-case x ()
[(a v) (identifier? #'a) #'(cons 'a v)]
[a (identifier? #'a) #''a]
[else (syntax-error x "improper attribute")]))
(define-syntax define-tags
(lambda (x)
(syntax-case x ()
[(_ tag ...)
(with-syntax ([(<tag> ...) (map <*> (syntax->list #'(tag ...)))])
#'(begin
(define-syntax <tag>
(lambda (x)
(syntax-case x ()
[(_ (attr (... ...)) text (... ...))
(with-syntax ([(attr (... ...))
(map attribute
(syntax->list #'(attr (... ...))))])
#'($tag 'tag (list attr (... ...))
(lambda () (void) text (... ...)) #t))])))
...))])))
(define-syntax define-endless-tags
(lambda (x)
(syntax-case x ()
[(_ tag ...)
(with-syntax ([(<tag> ...) (map <*> (syntax->list #'(tag ...)))])
#'(begin
(define-syntax <tag>
(lambda (x)
(syntax-case x ()
[(_) #'($tag 'tag '() (lambda () "") #f)]
[(_ (attr (... ...)))
(with-syntax ([(attr (... ...))
(map attribute
(syntax->list #'(attr (... ...))))])
#'($tag 'tag (list attr (... ...))
(lambda () "") #f))])))
...))])))
; top-level
(define-tags html head body)
; head
(define-tags script style title) ; script also special inline
(define-endless-tags base link meta)
; block-level generic
; del and ins are also phrase
(define-tags address blockquote del div h1 h2 h3 h4 h5 h6 ins noscript p pre)
(define-endless-tags hr)
; lists
(define-tags dd dl dt li ol ul)
; tables
(define-tags table caption colgroup thead tfoot tbody tr td th)
(define-endless-tags col)
; forms
(define-tags form button fieldset legend label select optgroup option textarea)
(define-endless-tags input)
; special inline
(define-tags a bdo map object q span sub sup)
(define-endless-tags br img area param)
; phrase
(define-tags abbr acronym cite code dfn em kbd samp strong var)
; font-style
(define-tags b big i small tt)
; pseudo tags
(define (<doctype>)
(printf "<!DOCTYPE html>\n"))
;;; other helpers
(define (html-text-char c)
(case c
[(#\<) "<"]
[(#\>) ">"]
[(#\&) "&"]
[(#\return) ""]
[else c]))
(define (html-text fmt . args)
(let ([s (apply format fmt args)])
(let ([n (string-length s)])
(do ([i 0 (fx+ i 1)])
((fx= i n))
(display (html-text-char (string-ref s i)))))))
(define (nbsp) (display-string " "))
(define encode-url-parameter
(let ()
(define get-encoding
(let ([encoding (make-vector 256)])
(do ([i 0 (fx+ i 1)])
((fx= i 256))
(let ([c (integer->char i)])
(cond
[(or (char<=? #\a c #\z)
(char<=? #\A c #\Z)
(char<=? #\0 c #\9)
(memv c '(#\$ #\- #\_ #\. #\+ #\! #\* #\' #\( #\) #\,)))
(vector-set! encoding i c)]
[(char=? c #\space) (vector-set! encoding i #\+)]
[else (vector-set! encoding i (format "%~(~2,'0x~)" i))])))
(lambda (c)
(let ([n (char->integer c)])
(if (fx< n 256)
(vector-ref encoding c)
($oops 'encode-url-parameter "cannot encode non-latin-1 character ~s" c))))))
(lambda (s)
(define (string-insert! s1 i1 s2 n2)
(do ([i2 0 (fx+ i2 1)] [i1 i1 (fx+ i1 1)])
((fx= i2 n2))
(string-set! s1 i1 (string-ref s2 i2))))
(let ([n (string-length s)])
(let f ([i 0] [j 0])
(if (fx= i n)
(make-string j)
(let ([x (get-encoding (string-ref s i))])
(if (char? x)
(let ([s (f (fx+ i 1) (fx+ j 1))])
(string-set! s j x)
s)
(let ([xn (string-length x)])
(let ([s (f (fx+ i 1) (fx+ j xn))])
(string-insert! s j x xn)
s))))))))))
(define (flush-html-output) (flush-output-port))
)
(import %html)
(define (assign-colors ncolors fdata*)
; assign highest color to entries whose counts are within X% of maximum
; count, where X = 100/ncolors, then recur without assigned color or
; entries to which it is assigned
; NB: color 0 is for unprofiled code, and color 1 is for unexecuted code
(let loop ([entry* (sort (lambda (x y)
(> (entrydata-count x) (entrydata-count y)))
(apply append (map filedata-entry* fdata*)))]
[ci (- ncolors 1)])
(unless (null? entry*)
(let ([limit (if (= ci 1)
-1
(let ([max-count (entrydata-count (car entry*))])
(truncate (* max-count (- 1 (/ 1 (- ci 1)))))))])
(let loop2 ([entry* entry*])
(unless (null? entry*)
(let ([entry (car entry*)])
(if (<= (entrydata-count entry) limit)
(loop entry* (- ci 1))
(let ([fdata (entrydata-fdata entry)])
(unless (filedata-ci fdata)
(filedata-ci-set! fdata ci))
(entrydata-ci-set! entry ci)
(loop2 (cdr entry*)))))))))))
(define-syntax with-html-file
(syntax-rules ()
[(_ who palette ?path title body1 body2 ...)
(let ([path ?path])
(let ([op ($open-file-output-port who path
(file-options replace)
(buffer-mode block)
(current-transcoder))])
(on-reset (delete-file path #f)
(on-reset (close-port op)
(parameterize ([current-output-port op])
(<doctype>)
(<html> ()
(newline)
(<head> ()
(newline)
(<meta> ([http-equiv "Content-Type"]
[content "text/html;charset=utf-8"]))
(newline)
(<title> () (html-text "~a" title))
(newline)
(display-style-with-palette palette)
(newline))
(newline)
(let () body1 body2 ...)
(newline))))
(close-port op))))]))
(define (display-file who palette fdata)
(let ([ip (filedata-ip fdata)] [line 1] [char 1])
(define (copy-all)
(html-text "~a"
(with-output-to-string
(rec f
(lambda ()
(let ([c (read-char ip)])
(unless (eof-object? c)
(write-char c)
(f))))))))
(define (read-space imax)
(with-output-to-string
(lambda ()
(let f ([imax imax])
(unless (= imax 0)
(let ([c (peek-char ip)])
(when (memv c '(#\space #\tab))
(read-char ip)
(set! char (+ char 1))
(write-char c)
(f (- imax 1)))))))))
(define (read-to-eol imax)
(with-output-to-string
(lambda ()
(let f ([imax imax])
(unless (= imax 0)
(let ([c (peek-char ip)])
(unless (or (eof-object? c) (char=? c #\newline))
(read-char ip)
(set! char (+ char 1))
(write-char c)
(f (- imax 1)))))))))
(define (copy-until bfp next ci title)
(let loop ([bfp bfp])
(unless (= bfp next)
(let ([s (read-to-eol (- next bfp))])
(let ([n (string-length s)])
(when (> n 0)
(if ci
(<span> ([class (color-class ci)] [title title])
(html-text "~a" s))
(html-text "~a" s)))
(let ([bfp (+ bfp n)])
(unless (= bfp next)
; next character must be newline, if not eof
(when (eof-object? (read-char ip))
($oops who
"unexpected end-of-file on ~s"
ip))
(let ([bfp (+ bfp 1)])
(newline)
(set! line (+ line 1))
(set! char 1)
(let ([s (read-space (- next bfp))])
(let ([n (string-length s)])
(when (> n 0) (display s))
(loop (+ bfp n))))))))))))
(define-syntax with-line-numbers
(syntax-rules ()
[(_ e1 e2 ...)
(let ([th (lambda () e1 e2 ...)])
(cond
[(profile-line-number-color) =>
(lambda (color)
(define line-count
(let loop ([n 0] [bol? #t])
(let ([c (read-char ip)])
(if (eof-object? c)
(begin (set-port-position! ip 0) n)
(loop (if bol? (+ n 1) n) (char=? c #\newline))))))
(<table> ()
(<tr> ()
(<td> ([style (format "color: ~a; font-weight: bold; padding-right: 1rem; text-align: right" color)])
(<pre> ()
(unless (fx= line-count 0)
(newline)
(let loop ([i 1])
(<span> ([id (format "line~d" i)]) (html-text "~s\n" i))
(unless (fx= i line-count) (loop (fx+ i 1)))))))
(<td> () (th)))))]
[else (th)]))]))
(with-html-file who palette (filedata-htmlpath fdata) (port-name ip)
(<body> ([class (color-class 0)])
(newline)
(<h1> ([style "margin-bottom: 1rem"])
(html-text "~a" (port-name ip)) (<span> ([style "opacity: 0.5"]) (html-text " on ~a" (date-and-time))))
(newline)
(with-line-numbers
(<pre> ()
(newline)
(let ([entry* (filedata-entry* fdata)]) ; already sorted by gather-filedata
(let f ([bfp 0] [entry* entry*] [efp #f] [ci #f] [title ""])
(cond
[(and (null? entry*) (not efp)) (copy-all)]
[(and (not (null? entry*))
(or (not efp) (< (entrydata-bfp (car entry*)) efp)))
(let ([entry (car entry*)] [entry* (cdr entry*)])
(let ([next (entrydata-bfp entry)])
(copy-until bfp next ci title)
(entrydata-line-set! entry line)
(entrydata-char-set! entry char)
(let-values ([(bfp entry*)
(f next entry*
(entrydata-efp entry)
(entrydata-ci entry)
(format "line ~d char ~d count ~:d" line char (entrydata-count entry)))])
(f bfp entry* efp ci title))))]
[else
(copy-until bfp efp ci title)
(values efp entry*)])))))
(newline)))))
(define color-class
(lambda (ci)
(format "pc~s" ci)))
(define (display-style-with-palette palette)
(<style> ([type "text/css"])
(newline)
;; CSS Reset Styling
;; See https://perishablepress.com/a-killer-collection-of-global-css-reset-styles/ for an overview
;; of CSS resets.
;;
;; See http://code.stephenmorley.org/html-and-css/fixing-browsers-broken-monospace-font-handling/
;; for an explanation of "font-family: monospace, monospace;" and the following "font-size: 1rem;".
;;
(printf "* {")
(printf " border: 0;")
(printf " margin: 0;")
(printf " outline: 0;")
(printf " padding: 0;")
(printf " vertical-align: baseline;")
(printf " }\n")
(printf "code, kbd, pre, samp {")
(printf " font-family: monospace, monospace;")
(printf " font-size: 1rem;")
(printf " }\n")
(printf "html {")
(printf " -moz-osx-font-smoothing: grayscale;")
(printf " -webkit-font-smoothing: antialiased;")
(printf " }\n")
(printf "table {")
(printf " border-collapse: collapse;")
(printf " border-spacing: 0;")
(printf " }\n")
;; CSS Base Styling
(printf "body {")
(printf " padding: 1rem;")
(printf " }\n")
(printf "h1, h2, h3, h4 {")
(printf " line-height: 1.25;")
(printf " margin-bottom: 0.5rem;")
(printf " }\n")
(printf "h1 {")
(printf " font-size: 1.296rem;")
(printf " }\n")
(printf "h2 {")
(printf " font-size: 1.215rem;")
(printf " }\n")
(printf "h3 {")
(printf " font-size: 1.138rem;")
(printf " }\n")
(printf "h4 {")
(printf " font-size: 1.067rem;")
(printf " }\n")
(printf "html {")
(printf " font-family: monospace, monospace;")
(printf " font-size: 1rem;")
(printf " }\n")
(printf "p {")
(printf " margin-bottom: 1.25rem;")
(printf " }\n")
;; CSS Profile Styling
(do ([ci 0 (fx+ ci 1)])
((fx= ci (vector-length palette)))
(let ([color (vector-ref palette ci)])
(printf ".~a { background-color: ~a; color: ~a; white-space: nowrap; }\n"
(color-class ci) (car color) (cdr color))))))
(define (safe-prefix name name*)
(define (prefix? prefix str)
(let ([n (string-length prefix)])
(and (fx<= n (string-length str))
(string=? prefix (substring str 0 n)))))
(define (digit+? s i n)
(and (fx< i n)
(let ([n (fx- n 1)])
(let loop ([i i])
(and (char-numeric? (string-ref s i))
(or (fx= i n) (loop (fx+ i 1))))))))
(define (okay? prefix)
(let loop ([name* name*])
(or (null? name*)
(let ([next-name (car name*)])
(or (not (prefix? name next-name))
(and (or (not (prefix? prefix next-name))
(not (digit+? next-name
(string-length prefix)
(string-length next-name))))
(loop (cdr name*))))))))
(let try ([prefix name])
(let ([prefix (format "~a-" prefix)])
(if (okay? prefix)
prefix
(try prefix)))))
(define (readable-number n)
(cond
[(>= n 1000000000) (format "~~~sB" (quotient n 1000000000))]
[(>= n 1000000) (format "~~~sM" (quotient n 1000000))]
[(>= n 1000) (format "~~~sK" (quotient n 1000))]
[else (format "~a" n)]))
(set-who! profile-dump-html
(rec profile-dump-html
(case-lambda
[() (profile-dump-html "")]
[(path-prefix) (profile-dump-html path-prefix (profile-dump))]
[(path-prefix dumpit*)
(unless (string? path-prefix)
($oops who "~s is not a string" path-prefix))
(check-dump who dumpit*)
(let ([palette (profile-palette)])
(let ([fdata* (gather-filedata who #f dumpit*)])
(when (null? fdata*)
($oops who "no profiled code found"))
(for-each
(lambda (fdata)
(filedata-max-count-set! fdata
(apply max
(map entrydata-count
(filedata-entry* fdata)))))
fdata*)
; assign unique html pathnames to fdatas with ips
(let ([fdata*
(sort
(lambda (x y)
(let ([xpath (path-last (port-name (filedata-ip x)))]
[ypath (path-last (port-name (filedata-ip y)))])
(or (string<? xpath ypath)
(and (string=? xpath ypath)
(< (source-file-descriptor-crc (filedata-sfd x))
(source-file-descriptor-crc (filedata-sfd x)))))))
(remp (lambda (x) (not (filedata-ip x))) fdata*))])
(for-each
(lambda (fdata i htmlpath)
(filedata-htmlpath-set! fdata htmlpath)
(filedata-htmlfn-set! fdata (path-last htmlpath))
(filedata-winid-set! fdata (format "win~s" i)))
fdata*
(enumerate fdata*)
(let f ([name* (map (lambda (fdata)
(path-last (port-name (filedata-ip fdata))))
fdata*)]
[last-name #f])
(if (null? name*)
'()
(let ([name (car name*)])
(if (equal? name last-name)
(let ([prefix (safe-prefix name name*)])
(let g ([name* (cdr name*)] [i 0])
(cons (format "~a~a~s.html" path-prefix prefix i)
(if (and (not (null? name*))
(string=? (car name*) name))
(g (cdr name*) (+ i 1))
(f name* name)))))
(cons (format "~a~a.html" path-prefix name)
(f (cdr name*) name))))))))
(assign-colors (vector-length palette) fdata*)
(with-html-file who palette (format "~aprofile.html" path-prefix) "Profile Output"
(<body> ([class (color-class 0)])
(newline)
(<h1> ([style "margin-bottom: 1rem"])
(html-text "Profile Output") (<span> ([style "opacity: 0.5"]) (html-text " on ~a" (date-and-time))))
(newline)
(<table> ()
(<tr> ()
(newline)
(<td> ([style "vertical-align: top"])
(<h2> ([style "margin-bottom: 0.25rem"])
(html-text "Legend"))
(newline)
(<table> ([style "margin-bottom: 1rem"])
(newline)
(let* ([n (vector-length palette)] [v (make-vector n #f)])
(for-each
(lambda (fdata)
(for-each
(lambda (entry)
(let ([ci (entrydata-ci entry)]
[count (entrydata-count entry)])
(vector-set! v ci
(let ([p (vector-ref v ci)])
(if p
(cons (min (car p) count)
(max (cdr p) count))
(cons count count))))))
(filedata-entry* fdata)))
fdata*)
(do ([ci (- n 1) (- ci 1)])
((= ci 0))
(let ([p (vector-ref v ci)])
(when p
(<tr> ()
(<td> ([class (color-class ci)]
[style "padding: 0.5rem"])
(let ([smin (readable-number (car p))]
[smax (readable-number (cdr p))])
(if (string=? smin smax)
(html-text "executed ~a time~p"
smin (car p))
(html-text "executed ~a-~a times"
smin smax)))))
(newline))))))
(newline)
(<h2> ([style "margin-bottom: 0.25rem"])
(html-text "Files"))
(newline)
(<table> ([style "margin-bottom: 1rem"])
(newline)
(for-each
(lambda (fdata)
(let ([ip (filedata-ip fdata)])
(<tr> ()
(<td> ([class (color-class (filedata-ci fdata))]
[style "padding: 0.5rem"])
(if ip
(<a> ([href (filedata-htmlfn fdata)]
[target (filedata-winid fdata)]
[class (color-class (filedata-ci fdata))])
(html-text "~a" (port-name (filedata-ip fdata))))
(html-text "~a"
(source-file-descriptor-name (filedata-sfd fdata))))))
(newline)
(when ip (display-file who palette fdata))))
(sort
(lambda (x y)
(> (filedata-max-count x)
(filedata-max-count y)))
fdata*))))
(newline)
(<td> ([style "width: 10rem"]))
(newline)
(<td> ([style "vertical-align: top"])
(<h2> ([style "margin-bottom: 0.25rem"])
(html-text "Hot Spots"))
(newline)
(<table> ([style "margin-bottom: 1rem"])
(newline)
(let loop ([entry*
(sort
(lambda (x y)
(or (> (entrydata-count x) (entrydata-count y))
(and (= (entrydata-count x) (entrydata-count y))
(let ([fn1 (filedata-htmlfn (entrydata-fdata x))]
[fn2 (filedata-htmlfn (entrydata-fdata y))])
(and fn1 fn2
(or (string<? fn1 fn2)
(and (string=? fn1 fn2)
(let ([line1 (entrydata-line x)]
[line2 (entrydata-line y)])
(and line1 line2 (< line1 line2))))))))))
(apply append (map filedata-entry* fdata*)))]
[last-htmlfn #f]
[last-count #f]
[last-line #f])
(unless (or (null? entry*) (= (entrydata-count (car entry*)) 0))
(let* ([entry (car entry*)]
[count (entrydata-count entry)]
[line (entrydata-line entry)]
[fdata (entrydata-fdata entry)]
[htmlfn (filedata-htmlfn fdata)])
(unless (and htmlfn last-htmlfn
(string=? htmlfn last-htmlfn)
(= count last-count)
(= line last-line))
(<tr> ()
(<td> ([class (color-class (entrydata-ci entry))]
[style "padding: 0.5rem"])
(cond
[(filedata-ip fdata) =>
(lambda (ip)
(let ([url (format "~a#line~d"
(filedata-htmlfn fdata)
line)])
(<a> ([href url]
[target (filedata-winid fdata)]
[style "text-decoration: underline"]
[class (color-class (entrydata-ci entry))])
(html-text "~a line ~s (~:d)"
(port-name ip) (entrydata-line entry)
(entrydata-count entry)))))]
[else
(html-text "~a char ~s (~:d)"
(source-file-descriptor-name (filedata-sfd fdata))
(entrydata-bfp entry)
(entrydata-count entry))])))
(newline))
(loop (cdr entry*) htmlfn count line)))))
(newline))
(newline)))
(newline)))
(for-each
(lambda (fdata) (cond [(filedata-ip fdata) => close-input-port]))
fdata*)))]))))
(set-who! profile-palette
(make-parameter
; color background with appropriate white or black foreground
'#(("#111111" . "white") ; black (for unprofiled code)
("#607D8B" . "white") ; gray (for unexecuted code)
("#9C27B0" . "black") ; purple
("#673AB7" . "white") ; dark purple
("#3F51B5" . "white") ; dark blue
("#2196F3" . "black") ; medium blue
("#00BCD4" . "black") ; aqua
("#4CAF50" . "black") ; green
("#CDDC39" . "black") ; yellow green
("#FFEB3B" . "black") ; yellow
("#FFC107" . "black") ; dark yellow
("#FF9800" . "black") ; orange
("#F44336" . "white")) ; red
(lambda (palette)
(unless (and (vector? palette)
(andmap
(lambda (x)
(and (pair? x) (string? (car x)) (string? (cdr x))))
(vector->list palette)))
($oops who "invalid palette ~s" palette))
(unless (fx> (vector-length palette) 2)
($oops who "palette ~s has too few entries" palette))
palette)))
(set-who! profile-line-number-color
(make-parameter "#666666"
(lambda (color)
(unless (or (eq? color #f) (string? color)) ($oops who "~s is not a string or #f" color))
color)))
)
)
| true |
50179d99b3327bbf8427859ce94c9c01e51db38a
|
4b480cab3426c89e3e49554d05d1b36aad8aeef4
|
/chapter-04/ex4.25-test-gsong.scm
|
42ad2d55c681d1ef1de2d71fadbd452cd0c8d4ba
|
[] |
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 | 519 |
scm
|
ex4.25-test-gsong.scm
|
(define (factorial n)
(unless (= n 1)
(* n (factorial (- n 1)))
1))
(define (unless condition usual-value exceptional-value)
(if condition exceptional-value usual-value))
; Infinite loop!!
;(factorial 3)
;
;(unless (= 3 1) (* 3 (factorial (- 3 1))) 1)
;(unless #f (* 3 (factorial 2)) 1)
;(unless #f (* 3 (unless (= 2 1) (* 2 (factorial (- 2 1))) 1)))
;(unless #f (* 3 (unless #f (* 2 (factorial 1)) 1)))
;(unless #f (* 3 (unless #f (* 2 (unles (= 1 1) (* 1 (factorial (- 1 1))) 1)) 1)) 1)
| false |
589360914cc433f5acf1df5c4084d00b1c83371b
|
296dfef11631624a5b2f59601bc7656e499425a4
|
/snow/index.scm
|
bb062bfa38df60b4d3e15d74266206711b132b48
|
[] |
no_license
|
sethalves/snow2-packages
|
f4dc7d746cbf06eb22c69c8521ec38791ae32235
|
4cc1a33d994bfeeb26c49f8a02c76bc99dc5dcda
|
refs/heads/master
| 2021-01-22T16:37:51.427423 | 2019-06-10T01:51:42 | 2019-06-10T01:51:42 | 17,272,935 | 1 | 1 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 14,950 |
scm
|
index.scm
|
(repository
(url "http://snow-repository.s3-website-us-east-1.amazonaws.com/index.scm")
(name "Snow Repository")
(sibling
(name "r7rs srfis")
(url "http://r7rs-srfis.s3-website-us-east-1.amazonaws.com/index.scm")
(trust 1.0))
(package
(name (snow hello))
(version "1.0")
(url "hello.tgz")
(size 6144)
(checksum (md5 "09bd4752bb942a2ad9296b40019e9f0c"))
(library
(name (snow hello))
(path "snow/hello.sld")
(version "1.0.1")
(homepage "http://snow.iro.umontreal.ca")
(manual)
(maintainers "Scheme Now! <snow at iro.umontreal.ca>")
(authors "Marc Feeley <feeley at iro.umontreal.ca>")
(description "Display \"let it snow\" and pi." example snow)
(license lgpl/v2.1)
(depends (snow pi))
(use-for final))
(library
(name (snow hello tests))
(path "snow/hello/tests.sld")
(version "1.0")
(homepage "https://github.com/sethalves")
(manual)
(maintainers "Seth Alves <[email protected]>")
(authors "Seth Alves <[email protected]>")
(description "tests for hello")
(license bsd)
(depends (snow hello))
(use-for test)))
(package
(name ())
(version "1.0")
(url "tar.tgz")
(size 27648)
(checksum (md5 "a0e6affc3f532c4ba296cec373bf6b9f"))
(library
(name (snow tar))
(path "snow/tar.sld")
(version "1.0.1")
(homepage "http://snow.iro.umontreal.ca")
(manual)
(maintainers "Scheme Now! <snow at iro.umontreal.ca>")
(authors "Marc Feeley <feeley at iro.umontreal.ca>")
(description "TAR file format packing and unpacking." conv snow)
(license lgpl/v2.1)
(depends
(snow bytevector)
(srfi 60)
(snow bignum)
(snow genport)
(snow filesys))
(use-for final))
(library
(name (snow tar tests))
(path "snow/tar/tests.sld")
(version "1.0")
(homepage "https://github.com/sethalves")
(manual)
(maintainers "Seth Alves <[email protected]>")
(authors "Seth Alves <[email protected]>")
(description "tests for tar")
(license bsd)
(depends (snow tar))
(use-for test)))
(package
(name ())
(version "1.0")
(url "bignum.tgz")
(size 44544)
(checksum (md5 "406a4293bf1226cf6e04d2983220e656"))
(library
(name (snow bignum))
(path "snow/bignum.sld")
(version "1.0.1")
(homepage "http://snow.iro.umontreal.ca")
(manual)
(maintainers "Scheme Now! <snow at iro.umontreal.ca>")
(authors "Marc Feeley <feeley at iro.umontreal.ca>")
(description "Operations on large integers." math snow)
(license lgpl/v2.1)
(depends (snow bytevector))
(use-for final))
(library
(name (snow bignum tests))
(path "snow/bignum/tests.sld")
(version "1.0")
(homepage "https://github.com/sethalves")
(manual)
(maintainers "Seth Alves <[email protected]>")
(authors "Seth Alves <[email protected]>")
(description "tests for bignum")
(license bsd)
(depends (snow bignum))
(use-for test)))
(package
(name ())
(version "1.0")
(url "processio.tgz")
(size 15872)
(checksum (md5 "ceb519289d6e13d5bba5c52c35cc0c30"))
(library
(name (snow processio))
(path "snow/processio.sld")
(version "1.0.0")
(homepage "http://snow.iro.umontreal.ca")
(manual)
(maintainers "Seth Alves <[email protected]")
(authors
"Nils M Holm <nmh at t3x.org>"
"Marc Feeley <feeley at iro.umontreal.ca>")
(description "I/O to operating system subprocesses." i/o os)
(license bsdl)
(depends (snow filesys) (snow extio))
(use-for final))
(library
(name (snow processio tests))
(path "snow/processio/tests.sld")
(version "1.0")
(homepage "https://github.com/sethalves")
(manual)
(maintainers "Seth Alves <[email protected]>")
(authors "Seth Alves <[email protected]>")
(description "tests for processio")
(license bsd)
(depends
(snow bytevector)
(snow filesys)
(snow extio)
(snow assert)
(snow binio)
(snow processio))
(use-for test)))
(package
(name ())
(version "1.0")
(url "genport.tgz")
(size 16384)
(checksum (md5 "19831b32aedb072f9e44ef661b03b99e"))
(library
(name (snow genport))
(path "snow/genport.sld")
(version "1.0.1")
(homepage "http://snow.iro.umontreal.ca")
(manual)
(maintainers "Scheme Now! <snow at iro.umontreal.ca>")
(authors "Marc Feeley <feeley at iro.umontreal.ca>")
(description "Generic ports." i/o snow)
(license lgpl/v2.1)
(depends (snow bytevector) (snow binio))
(use-for final))
(library
(name (snow genport tests))
(path "snow/genport/tests.sld")
(version "1.0")
(homepage "https://github.com/sethalves")
(manual)
(maintainers "Seth Alves <[email protected]>")
(authors "Seth Alves <[email protected]>")
(description "tests for genport")
(license bsd)
(depends (snow genport))
(use-for test)))
(package
(name ())
(version "1.0")
(url "filesys.tgz")
(size 23552)
(checksum (md5 "3b5e7965ae0b83a8982640bba2a2efa1"))
(library
(name (snow filesys))
(path "snow/filesys.sld")
(version "1.0.4")
(homepage "http://snow.iro.umontreal.ca")
(manual)
(maintainers "Scheme Now! <snow at iro.umontreal.ca>")
(authors "Marc Feeley <feeley at iro.umontreal.ca>")
(description "File system access." os snow)
(license lgpl/v2.1)
(depends (srfi 13) (chibi char-set) (srfi 1) (srfi 14))
(use-for final))
(library
(name (snow filesys tests))
(path "snow/filesys/tests.sld")
(version "1.0")
(homepage "https://github.com/sethalves")
(manual)
(maintainers "Seth Alves <[email protected]>")
(authors "Seth Alves <[email protected]>")
(description "tests for filesys")
(license bsd)
(depends (srfi 1) (snow filesys) (srfi 78))
(use-for test)))
(package
(name ())
(version "1.0")
(url "pi.tgz")
(size 7680)
(checksum (md5 "278d9053743e59e16e752ec4e71bbc39"))
(library
(name (snow pi))
(path "snow/pi.sld")
(version "1.0.1")
(homepage "http://snow.iro.umontreal.ca")
(manual)
(maintainers "Scheme Now! <snow at iro.umontreal.ca>")
(authors "Marc Feeley <feeley at iro.umontreal.ca>")
(description "Computes the digits of pi." example snow)
(license lgpl/v2.1)
(depends (snow bignum))
(use-for final))
(library
(name (snow pi tests))
(path "snow/pi/tests.sld")
(version "1.0")
(homepage "https://github.com/sethalves")
(manual)
(maintainers "Seth Alves <[email protected]>")
(authors "Seth Alves <[email protected]>")
(description "tests for pi")
(license bsd)
(depends (snow pi))
(use-for test)))
(package
(name ())
(version "1.0")
(url "extio.tgz")
(size 50176)
(checksum (md5 "df567f0bb5120b12697f378532c462df"))
(library
(name (snow extio))
(path "snow/extio.sld")
(version "1.0.3")
(homepage "http://snow.iro.umontreal.ca")
(manual)
(maintainers "Seth Alves <[email protected]>")
(authors "Marc Feeley <feeley at iro.umontreal.ca>")
(description "Extended I/O." i/o snow)
(license lgpl/v2.1)
(depends (snow bytevector) (srfi 60) (srfi 13))
(use-for final))
(library
(name (snow extio tests))
(path "snow/extio/tests.sld")
(version "1.0")
(homepage "https://github.com/sethalves")
(manual)
(maintainers "Seth Alves <[email protected]>")
(authors "Seth Alves <[email protected]>")
(description "tests for extio")
(license bsd)
(depends (snow bytevector) (snow extio))
(use-for test)))
(package
(name ())
(version "1.0")
(url "zlib.tgz")
(size 48640)
(checksum (md5 "5c640caca662e41d9cdd41b6dfc93559"))
(library
(name (snow zlib))
(path "snow/zlib.sld")
(version "1.0.1")
(homepage "http://snow.iro.umontreal.ca")
(manual)
(maintainers "Scheme Now! <snow at iro.umontreal.ca>")
(authors
"Marc Feeley <feeley at iro.umontreal.ca>"
"Manuel Serrano <Manuel.Serrano at sophia.inria.fr>")
(description
"Compression and decompression of deflate and gzip formats."
conv
i/o
snow)
(license lgpl/v2.1)
(depends (snow bytevector) (snow digest) (srfi 60) (snow genport))
(use-for final))
(library
(name (snow zlib tests))
(path "snow/zlib/tests.sld")
(version "1.0")
(homepage "https://github.com/sethalves")
(manual)
(maintainers "Seth Alves <[email protected]>")
(authors "Seth Alves <[email protected]>")
(description "tests for zlib")
(license bsd)
(depends (snow binio) (snow genport) (snow zlib))
(use-for test)))
(package
(name ())
(version "1.0")
(url "random.tgz")
(size 8192)
(checksum (md5 "27a5a7590bdffc3c45569013e348de15"))
(library
(name (snow random))
(path "snow/random.sld")
(version "1.0.1")
(homepage "http://snow.iro.umontreal.ca")
(manual)
(maintainers "Scheme Now! <snow at iro.umontreal.ca>")
(authors "Marc Feeley <feeley at iro.umontreal.ca>")
(description "High-quality random number generation." snow)
(license lgpl/v2.1)
(depends (srfi 27) (snow bytevector) (snow binio) (snow bignum))
(use-for final))
(library
(name (snow random tests))
(path "snow/random/tests.sld")
(version "1.0")
(homepage "https://github.com/sethalves")
(manual)
(maintainers "Seth Alves <[email protected]>")
(authors "Seth Alves <[email protected]>")
(description "tests for random")
(license bsd)
(depends (snow random))
(use-for test)))
(package
(name ())
(version "1.0")
(url "bytevector.tgz")
(size 17408)
(checksum (md5 "ef49a76943296980e53a51d642133e11"))
(library
(name (snow bytevector))
(path "snow/bytevector.sld")
(version "1.0")
(homepage "https://github.com/sethalves")
(manual)
(maintainers "Seth Alves <[email protected]>")
(authors "Seth Alves <[email protected]>")
(description "bytevector compatibility layer")
(license bsd)
(depends (srfi 1))
(use-for final))
(library
(name (snow bytevector tests))
(path "snow/bytevector/tests.sld")
(version "1.0")
(homepage "https://github.com/sethalves")
(manual)
(maintainers "Seth Alves <[email protected]>")
(authors "Seth Alves <[email protected]>")
(description "bytevector")
(license bsd)
(depends (snow bytevector))
(use-for test)))
(package
(name ())
(version "1.0")
(url "input-parse.tgz")
(size 15360)
(checksum (md5 "74128424167947c595b18ce1a45c212a"))
(library
(name (snow input-parse))
(path "snow/input-parse.sld")
(version "1.0.1")
(homepage "http://snow.iro.umontreal.ca")
(manual)
(maintainers "Scheme Now! <snow at iro.umontreal.ca>")
(authors "Marc Feeley <feeley at iro.umontreal.ca>")
(description
"inspired and compatible with Oleg Kiselyov's input parsing library")
(license public-domain)
(depends (srfi 1) (srfi 13))
(use-for final))
(library
(name (snow input-parse tests))
(path "snow/input-parse/tests.sld")
(version "1.0")
(homepage "https://github.com/sethalves")
(manual)
(maintainers "Seth Alves <[email protected]>")
(authors "Seth Alves <[email protected]>")
(description "tests for input-parse")
(license bsd)
(depends (snow input-parse))
(use-for test)))
(package
(name ())
(version "1.0")
(url "binio.tgz")
(size 11264)
(checksum (md5 "837afd3756d04dd8e85f5b1cc68006f8"))
(library
(name (snow binio))
(path "snow/binio.sld")
(version "1.0.2")
(homepage "http://snow.iro.umontreal.ca")
(manual)
(maintainers "Scheme Now! <snow at iro.umontreal.ca>")
(authors "Marc Feeley <feeley at iro.umontreal.ca>")
(description "Binary I/O." i/o snow)
(license lgpl/v2.1)
(depends (snow bytevector))
(use-for final))
(library
(name (snow binio tests))
(path "snow/binio/tests.sld")
(version "1.0")
(homepage "https://github.com/sethalves")
(manual)
(maintainers "Seth Alves <[email protected]>")
(authors "Seth Alves <[email protected]>")
(description "tests for binio")
(license bsd)
(depends (snow binio))
(use-for test)))
(package
(name ())
(version "1.0")
(url "assert.tgz")
(size 5632)
(checksum (md5 "c2f0f9fd3ce46081e0ca226945624b96"))
(library
(name (snow assert))
(path "snow/assert.sld")
(version "1.0")
(homepage "https://github.com/sethalves")
(manual)
(maintainers "Seth Alves <[email protected]>")
(authors "Seth Alves <[email protected]>")
(description "assert")
(license bsd)
(depends)
(use-for final))
(library
(name (snow assert tests))
(path "snow/assert/tests.sld")
(version "1.0")
(homepage "https://github.com/sethalves")
(manual)
(maintainers "Seth Alves <[email protected]>")
(authors "Seth Alves <[email protected]>")
(description "tests for assert")
(license bsd)
(depends (snow assert))
(use-for test)))
(package
(name ())
(version "1.0")
(url "digest.tgz")
(size 59392)
(checksum (md5 "79e88817de4b2a6970b17a99eb6eb2d0"))
(library
(name (snow digest))
(path "snow/digest.sld")
(version "1.0.1")
(homepage "http://snow.iro.umontreal.ca")
(manual)
(maintainers "Scheme Now! <snow at iro.umontreal.ca>")
(authors "Marc Feeley <feeley at iro.umontreal.ca>")
(description
"Computation of message digests (CRC32, MD5, SHA-1, ...)."
hash
conv
snow)
(license lgpl/v2.1)
(depends (srfi 60) (snow binio) (snow bytevector))
(use-for final))
(library
(name (snow digest tests))
(path "snow/digest/tests.sld")
(version "1.0")
(homepage "https://github.com/sethalves")
(manual)
(maintainers "Seth Alves <[email protected]>")
(authors "Marc Feeley <feeley at iro.umontreal.ca>")
(description "tests for digest")
(license lgpl/v2.1)
(depends (snow bytevector) (snow digest))
(use-for test))))
| false |
32e269f17c127d239fdac1a9d34b84253ce486fa
|
f4cf5bf3fb3c06b127dda5b5d479c74cecec9ce9
|
/Sources/LispKit/Resources/Libraries/srfi/112.sld
|
2c4802698d8185fcc59ea50ba3275be78223bdaa
|
[
"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 | 1,783 |
sld
|
112.sld
|
;;; SRFI 112
;;; Environment Inquiry
;;;
;;; This is a library supporting environment inquiry, providing human-readable information
;;; at run time about the hardware and software configuration on which a Scheme program is
;;; being executed. They are mostly based on Common Lisp, with additions from the Posix
;;; `uname()` system call.
;;;
;;; Copyright © 2013 John Cowan. All rights reserved.
;;;
;;; Permission is hereby granted, free of charge, to any person obtaining a copy of this
;;; software and associated documentation files (the "Software"), to deal in the Software
;;; without restriction, including without limitation the rights to use, copy, modify, merge,
;;; publish, distribute, sublicense, and/or sell copies of the Software, and to permit
;;; persons to whom the Software is furnished to do so, subject to the following conditions:
;;;
;;; The above copyright notice and this permission notice shall be included in all copies or
;;; substantial portions of the Software.
;;;
;;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
;;; INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
;;; PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
;;; FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
;;; OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
;;; DEALINGS IN THE SOFTWARE.
;;;
;;; Adaptation to LispKit
;;; Copyright © 2018 Matthias Zenger. All rights reserved.
(define-library (srfi 112)
(export implementation-name
implementation-version
cpu-architecture
machine-name
os-type
os-version)
(import (lispkit base))
)
| false |
f3c6809f5214085fe4f0abee6653ce594a18bff6
|
99ea786a1d4553b7ee264843877aaee11eb37115
|
/6-12/test/4.11.scm
|
f4b18403f3d85cabc58ceb4b92978c6044f05973
|
[] |
no_license
|
tyage/pl
|
ef4f62d729aed1222367dcae0f9a547e5d528b06
|
c707b9f5055c12f6aadda60fe89f9c3423e820b6
|
refs/heads/master
| 2016-09-06T05:24:56.565550 | 2013-07-23T22:25:19 | 2013-07-23T22:25:19 | null | 0 | 0 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 924 |
scm
|
4.11.scm
|
(use gauche.test)
(add-load-path ".")
(test-start "4.11")
(load "4.11")
(define frame (make-frame '(key0) '(0)))
(define env (list frame))
(test-section "frame test")
(test* "(frame-variables frame)" (frame-variables frame) '(key0))
(test* "(frame-values frame)" (frame-values frame) '(0))
(add-binding-to-frame! 'key1 1 frame)
(add-binding-to-frame! 'key2 2 frame)
(test* "(frame-variables frame)" (frame-variables frame) '(key0 key1 key2))
(test* "(frame-values frame)" (frame-values frame) '(0 1 2))
(test-section "env test")
(test* "(lookup-variable-value 'key0 env)" (lookup-variable-value 'key0 env) 0)
(test* "(lookup-variable-value 'key1 env)" (lookup-variable-value 'key1 env) 1)
(set-variable-value! 'key2 3 env)
(test* "(lookup-variable-value 'key2 env)"
(lookup-variable-value 'key2 env) 3)
(define-variable! 'key3 4 env)
(test* "(lookup-variable-value 'key3 env)"
(lookup-variable-value 'key3 env) 4)
| false |
f78f36b2de8f9a50c8fbbf90a7def12224e9b9d3
|
db0567d04297eb710cd4ffb7af094d82b2f66662
|
/scheme/ikarus.apropos.ss
|
c9de9f26ec8c9cc9c7df58d976877cf9d2bd2250
|
[] |
no_license
|
xieyuheng/ikarus-linux
|
3899e99991fd192de53c485cf429bfd208e7506a
|
941b627e64f30af60a25530a943323ed5c78fe1b
|
refs/heads/master
| 2021-01-10T01:19:05.250392 | 2016-02-13T22:21:24 | 2016-02-13T22:21:24 | 51,668,773 | 0 | 0 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 2,062 |
ss
|
ikarus.apropos.ss
|
(library (ikarus.apropos)
(export apropos)
(import
(except (ikarus) apropos)
(only (psyntax library-manager) library-subst library-name))
(define (compose f g)
(lambda (x) (f (g x))))
(define (match-maker s1)
(let ([n1 (string-length s1)])
(lambda (s2)
(let ([m (fx- (string-length s2) n1)])
(let f ([i2 0])
(and (fx<=? i2 m)
(or (let g ([i1 0] [i2 i2])
(or (fx= i1 n1)
(and (char=? (string-ref s1 i1)
(string-ref s2 i2))
(g (fx+ i1 1) (fx+ i2 1)))))
(f (fx+ i2 1)))))))))
(define ($apropos-list name who)
(let ([name
(cond
[(string? name) name]
[(symbol? name) (symbol->string name)]
[else
(die who "not a string or symbol" name)])])
(define matcher
(compose (match-maker name)
(compose symbol->string car)))
(fold-right
(lambda (lib rest)
(define (symbol<? s1 s2)
(string<? (symbol->string s1) (symbol->string s2)))
(let ([ls (filter matcher (library-subst lib))])
(if (null? ls)
rest
(let ([ls (list-sort symbol<? (map car ls))])
(cons (cons (library-name lib) ls) rest)))))
'()
(list-sort
(lambda (lib1 lib2)
(let f ([ls1 (library-name lib1)] [ls2 (library-name lib2)])
(and (pair? ls2)
(or (null? ls1)
(let ([s1 (symbol->string (car ls1))]
[s2 (symbol->string (car ls2))])
(or (string<? s1 s2)
(and (string=? s1 s2)
(f (cdr ls1) (cdr ls2)))))))))
(installed-libraries)))))
(define (apropos name)
(for-each
(lambda (x) (printf "~a:\n ~a\n" (car x) (cdr x)))
($apropos-list name 'apropos))))
| false |
c8eeb5cee8289e4666191d13ebfa11e7b27d7f6b
|
2d1029e750a1cd71a650cceea8b7e02ae854ec01
|
/various-prologs-exp/prolog-first-pass/prolog_staged5/serialize.pr.ss
|
934fc5ca6d017cf98ab1829f12873b851420eff5
|
[] |
no_license
|
chinacat/unsorted
|
97f5ce41d228b70452861df707ceff9d503a0a89
|
46696319d2585c723bbc5bdff3a03743b1425243
|
refs/heads/master
| 2018-12-28T22:05:34.628279 | 2013-08-09T06:36:07 | 2013-08-09T06:36:07 | null | 0 | 0 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 1,041 |
ss
|
serialize.pr.ss
|
#lang scheme
(require "prolog.ss")
(<- (main) (serialize "able was i ere i saw elba" ?x))
(<- (serialize ?l ?r)
(pairlists ?l ?r ?a)
(arrange ?a ?t)
(numbered ?t 1 ?n))
(<- (pairlists (?x . ?l) (?y . ?r) ((pair ?x ?y) . ?a))
(pairlists ?l ?r ?a))
(<- (pairlists () () ()))
(<- (arrange (?x . ?l) (tree ?t1 ?x ?t2))
(split ?l ?x ?l1 ?l2)
(arrange ?l1 ?t1)
(arrange ?l2 ?t2))
(<- (arrange () void))
(<- (split (?x . ?l) ?x ?l1 ?l2)
!
(split ?l ?x ?l1 ?l2))
(<- (split (?x . ?l) ?y (?x . ?l1) ?l2)
(before ?x ?y) !
(split ?l ?y ?l1 ?l2))
(<- (split (?x . ?l) ?y ?l1 (?x . ?l2))
(before ?y ?x) !
(split ?l ?y ?l1 ?l2))
(<- (split () ? () ()))
(<- (before (pair ?x1 ?y1) (pair ?x2 ?y2))
(< ?x1 ?x2))
(<- (numbered (tree ?t1 (pair ?x ?n1) ?t2) ?n0 ?n)
(numbered ?t1 ?n0 ?n1)
(is ?n2 (+ ?n1 1))
(numbered ?t2 ?n2 ?n))
(<- (numbered void ?n ?n))
(time (with-input-from-string ";\n"
(lambda ()
(?- (main)))))
| false |
031b52a6e10c2d2627a6a8becfcddec87c58f101
|
8a831980fc09820ce2ae31ee99882b0b2a855e71
|
/anagma.scm
|
5b815c60b08255ab859d7df186270d62599fea27
|
[] |
no_license
|
h8gi/ANAGMA
|
cc16d4fea3862c88d036c5d30e64d7a3de50a51f
|
123c9791c58ec7bb50124e71a404615da3dfec41
|
refs/heads/master
| 2021-01-23T19:38:25.223437 | 2015-02-03T09:28:13 | 2015-02-03T09:28:13 | 30,233,901 | 0 | 0 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 6,762 |
scm
|
anagma.scm
|
;;; anagma.scm
;;; 2014/8/19
;;; yagi hiroki
;; ローターはとりあえず3つ
;; I EKMFLGDQVZNTOWYHXUSPAIBRCJ 1930 Enigma I
;; II AJDKSIRUXBLHWTMCQGZNPYFVOE 1930 Enigma I
;; III BDFHJLCPRTXVZNYEIWGAKMUSQO 1930 Enigma I
;; ローターの持つべき属性は上に示した変換規則と針の位置
;; 針のが上に来る度に次のローターが一文字分回転する
;; リフレクターがどうなってるのか
;; Contacts = ABCDEFGHIJKLMNOPQRSTUVWXYZ
;; ||||||||||||||||||||||||||
;; Reflector B = YRUHQSLDPXNGOKMIEBFZCWVJAT
;; Reflector C = FVPJIAOYEDRZXWGCTKUQSBNMHL
;;; connectsは変換規則
;;; needleは針の位置(数字1文字 0ならばAとBの間、ZならばZとAのあいだ)
;;; headingは数字1文字 入力された文字数にどれだけずれて対応するか
;;; もうこれでいい
(use coops srfi-13 regex easy-args extras utils)
;;; ローターの変換規則
(define upper-set "ABCDEFGHIJKLMNOPQRSTUVWXYZ")
(define *length* (string-length upper-set))
(define 1st-set "EKMFLGDQVZNTOWYHXUSPAIBRCJ")
(define 2nd-set "AJDKSIRUXBLHWTMCQGZNPYFVOE")
(define 3rd-set "BDFHJLCPRTXVZNYEIWGAKMUSQO")
;;; リフレクターの変換規則
(define refB-set "YRUHQSLDPXNGOKMIEBFZCWVJAT")
(define refC-set "FVPJIAOYEDRZXWGCTKUQSBNMHL")
;;; クラス定義
(define-class <converter> ()
((connects initform: upper-set)))
(define-class <rotor> (<converter>)
((needle initform: 0
accessor: get-needle)
(heading initform: 0
accessor: get-heading)))
(define-class <enigma> ()
((plag-board initform: plag-board
reader: plag-of)
(fast initform: 1st-rotor
reader: fast-of)
(middle initform: 2nd-rotor
reader: middle-of)
(slow initform: 3rd-rotor
reader: slow-of)
(reflector initform: reflector
reader: reflector-of)))
(define-generic (input a <converter>))
(define-generic (input a <rotor>))
(define-generic (input a <enigma>))
(define-generic (output a <rotor>))
(define-method (get-heading (r <rotor>)) (slot-value r 'heading))
(define-method ((setter get-heading) (r <rotor>) val) (set! (slot-value r 'heading) val))
(define-method (get-needle (r <rotor>)) (slot-value r 'needle))
(define-method ((setter get-needle) (r <rotor>) val) (set! (slot-value r 'needle) val))
(define-method (input (a #t) (c <converter>))
(let ((set (slot-value c 'connects))
(num (string-index upper-set a)))
(string-ref set num)))
(define-method (input (a #t) (r <rotor>))
(let ((set (slot-value r 'connects))
(head (slot-value r 'heading))
(num (string-index upper-set a)))
(string-ref set (modulo (- num head) *length*))))
(define-method (output (a #t) (r <rotor>))
(let ((num (string-index (slot-value r 'connects) a)))
(string-ref upper-set (modulo (+ num (get-heading r)) *length*))))
(define-method (plag-of (e <enigma>)) (slot-value e 'plag-board))
(define-method (fast-of (e <enigma>)) (slot-value e 'fast))
(define-method (middle-of (e <enigma>)) (slot-value e 'middle))
(define-method (slow-of (e <enigma>)) (slot-value e 'slow))
(define-method (reflector-of (e <enigma>)) (slot-value e 'reflector))
(define-method (input (a #t) (e <enigma>))
(let ((a1 (input a (plag-of e)))
(f (fast-of e))
(m (middle-of e))
(s (slow-of e))
(flag1 #t)
(flag2 #t))
(set! (get-heading f) (modulo (add1 (get-heading f)) *length*))
(let ((a2 (input a1 f)))
(cond ((= (get-heading f) (get-needle f))
(when flag1
(set! (get-heading m) (modulo (add1 (get-heading m)) *length*))
(set! flag1 #f)))
(else (set! flag1 #t)))
(let ((a3 (input a2 m)))
(cond ((= (get-heading m) (get-needle m))
(when flag2
(set! (get-heading s) (modulo (add1 (get-heading s)) *length*))
(set! flag2 #f)))
(else (set! flag2 #t)))
(output (output (output (input (input a3 s) (reflector-of e))
s)
m)
f)))))
;;; dirty
(define-syntax initialize-enigma
(syntax-rules ()
((_ lst)
(begin
(define heading-list lst)
(define plag-board (make <converter> 'connects upper-set))
(define 1st-rotor (make <rotor>
'connects 1st-set
'heading (first heading-list)))
(define 2nd-rotor (make <rotor>
'connects 2nd-set
'heading (second heading-list)))
(define 3rd-rotor (make <rotor>
'connects 3rd-set
'heading (third heading-list)))
(define reflector (make <converter> 'connects refB-set))
(define enigma (make <enigma>))))
((_)
(initialize-enigma (list (random *length*) (random *length*) (random *length*))))))
(define-syntax reset-enigma
(syntax-rules ()
((_)
(begin
(set! (get-heading (fast-of enigma)) (first heading-list))
(set! (get-heading (middle-of enigma)) (second heading-list))
(set! (get-heading (slow-of enigma)) (third heading-list))))))
(define (input-string str)
(display
(string-map (lambda (c) (input c enigma))
(string-upcase (string-substitute* str '(("[^a-zA-Z]" . ""))))))
(newline)
(reset-enigma))
;; (define (enigma-loop)
;; (display "anagma> ")
;; (input-string (read-line))
;; (enigma-loop))
(define (enigma-loop)
(display "anagma> ")
(let ((str (read-line)))
(if (eof-object? str)
(exit 0)
(input-string str)))
(enigma-loop))
(define (usage)
(printf "anagma, version 1.2\n")
(printf "usage: anagma [OPTION ...] [FILENAME | STRING]\n")
(printf "-e, --exec string : string passed in\n")
(printf "-f, --file file : filename passed in\n")
(printf "-h, --help : print this help message\n")
(printf "-k, --keys keys : keys is init string of 3 rotors\n")
(printf "-r, --repl : start anagma repl\n")
(printf "-v, --version : print the anagma version\n"))
;;; main exec----------------------------------------------
(define-arguments
((exec e) "")
((file f) "")
((help h))
((keys k) "")
((repl r))
((version v)))
(let ((lst (map string->number (string-split (keys)))))
(if (null? lst) (initialize-enigma)
(initialize-enigma lst)))
(cond ((help) (usage))
((repl) (enigma-loop))
((not (zero? (string-length (file))))
(input-string (read-all (file))))
((not (zero? (string-length (exec))))
(input-string (exec)))
((version)
(printf "anagma, version 1.0\n"))
(else (usage)))
| true |
f7a4bc73d8569debf299f3e8c424f0045f0d4a33
|
defeada37d39bca09ef76f66f38683754c0a6aa0
|
/UnityEngine/unity-engine/compute-buffer.sls
|
d7ca3a5d93b6c7f1c6e341dd6841562fbedbbc89
|
[] |
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,353 |
sls
|
compute-buffer.sls
|
(library (unity-engine compute-buffer)
(export new
is?
compute-buffer?
set-data
dispose
get-data
release
copy-count
count
stride)
(import (ironscheme-clr-port))
(define-syntax new
(lambda (e)
(syntax-case e ()
((_ a ...) #'(clr-new UnityEngine.ComputeBuffer a ...)))))
(define (is? a) (clr-is UnityEngine.ComputeBuffer a))
(define (compute-buffer? a) (clr-is UnityEngine.ComputeBuffer a))
(define-method-port
set-data
UnityEngine.ComputeBuffer
SetData
(System.Void System.Array))
(define-method-port
dispose
UnityEngine.ComputeBuffer
Dispose
(System.Void))
(define-method-port
get-data
UnityEngine.ComputeBuffer
GetData
(System.Void System.Array))
(define-method-port
release
UnityEngine.ComputeBuffer
Release
(System.Void))
(define-method-port
copy-count
UnityEngine.ComputeBuffer
CopyCount
(static:
System.Void
UnityEngine.ComputeBuffer
UnityEngine.ComputeBuffer
System.Int32))
(define-field-port
count
#f
#f
(property:)
UnityEngine.ComputeBuffer
count
System.Int32)
(define-field-port
stride
#f
#f
(property:)
UnityEngine.ComputeBuffer
stride
System.Int32))
| true |
4bcefc70b189dd6c048d3731dba127d1417ec2af
|
0f9909b1ea2b247aa9dec923d58e4d0975b618e6
|
/tests/df2.scm
|
9a2ed61f557aa2cc7e0a933ee71701ceb9c8de92
|
[] |
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 | 415 |
scm
|
df2.scm
|
;; Dataflow Library (second attempt)
;; @ Introdution
;; Attributes should be stored in functional data structures.
;; Attributes are either inherited (top-down) or synthesized (bottom-up).
(define attr cons)
(define inherit car)
(define synth cdr)
;; Attributes are stored in a map, but the value is user-defined.
(define empty-attr
(let ((m (m:new (m:new-order string=? string<?)))) (attr m m)))
| false |
6f026fefbb64328127462780974b277a0fa3414b
|
a178d245493d36d43fdb51eaad2df32df4d1bc8b
|
/scripts/compile_grammars.ss
|
a073c2f15092de37a2a895f98cc53d8515e5f0d7
|
[] |
no_license
|
iomeone/testscheme
|
cfc560f4b3a774064f22dd37ab0735fbfe694e76
|
6ddf5ec8c099fa4776f88a50eda78cd62f3a4e77
|
refs/heads/master
| 2020-12-10T10:52:40.767444 | 2020-01-15T08:40:07 | 2020-01-15T08:40:07 | 233,573,451 | 0 | 0 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 542 |
ss
|
compile_grammars.ss
|
#!/usr/bin/scheme-script
(import (GrammarCompiler main))
(define source-grammar-file
(lambda ()
(let ((args (command-line-arguments)))
(if (not (= (length args) 1))
(errorf 'compile-grammars (usage args))
(car args)))))
(define usage
(lambda (a)
(printf "Invalid arguments: ~a\n" a)
(printf "Usage:\n")
(printf " scheme --script compile_grammars.ss <src_file>\n\n")))
(compile-grammars (source-grammar-file)
(scheme-path "Framework/GenGrammars")
(haskell-path "FrameworkHs/GenGrammars"))
| false |
7f5c28a2cb63752b8bba56f4d7a8dc3eaf11e0f4
|
defeada37d39bca09ef76f66f38683754c0a6aa0
|
/mscorlib/system/runtime/remoting/proxies/proxy-attribute.sls
|
83122cf9646d7546021272df5e7a5244d8f975fc
|
[] |
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,537 |
sls
|
proxy-attribute.sls
|
(library (system runtime remoting proxies proxy-attribute)
(export new
is?
proxy-attribute?
is-context-ok?
get-properties-for-new-context
create-proxy
create-instance)
(import (ironscheme-clr-port))
(define-syntax new
(lambda (e)
(syntax-case e ()
((_ a ...)
#'(clr-new
System.Runtime.Remoting.Proxies.ProxyAttribute
a
...)))))
(define (is? a)
(clr-is System.Runtime.Remoting.Proxies.ProxyAttribute a))
(define (proxy-attribute? a)
(clr-is System.Runtime.Remoting.Proxies.ProxyAttribute a))
(define-method-port
is-context-ok?
System.Runtime.Remoting.Proxies.ProxyAttribute
IsContextOK
(System.Boolean
System.Runtime.Remoting.Contexts.Context
System.Runtime.Remoting.Activation.IConstructionCallMessage))
(define-method-port
get-properties-for-new-context
System.Runtime.Remoting.Proxies.ProxyAttribute
GetPropertiesForNewContext
(System.Void
System.Runtime.Remoting.Activation.IConstructionCallMessage))
(define-method-port
create-proxy
System.Runtime.Remoting.Proxies.ProxyAttribute
CreateProxy
(System.Runtime.Remoting.Proxies.RealProxy
System.Runtime.Remoting.ObjRef
System.Type
System.Object
System.Runtime.Remoting.Contexts.Context))
(define-method-port
create-instance
System.Runtime.Remoting.Proxies.ProxyAttribute
CreateInstance
(System.MarshalByRefObject System.Type)))
| true |
416d453520c0291abfa7c041f0b4ec1f16824a85
|
4fd95c081ccef6afc8845c94fedbe19699b115b6
|
/chapter_2/2.76.scm
|
d7bb172e3bad62ff4e3d6e273c732904eb0915dc
|
[
"MIT"
] |
permissive
|
ceoro9/sicp
|
61ff130e655e705bafb39b4d336057bd3996195d
|
7c0000f4ec4adc713f399dc12a0596c770bd2783
|
refs/heads/master
| 2020-05-03T09:41:04.531521 | 2019-08-08T12:14:35 | 2019-08-08T12:14:35 | 178,560,765 | 1 | 0 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 744 |
scm
|
2.76.scm
|
; General description:
; Explicit dispath:
; adding new type - pain, need to add conditions to all genetic methods
; adding new operation - easy, just one condition
; Main advatange: easy and straight-foward to code
; Message-passing
; addding new type - easy breezy
; adding new operation - pain, need to change all the old code
; Main advantage: easy to maintain
; Data-directed:
; adding new type - not such easy as message-passing
; adding new operation - easy
; Main advantage: scalability
; Which organization would be most appropriate for a system in which new types must often be added?
; answer: Data-directed
; Which would be most appropriate for a system in which new operations must often be added?
; answer: Message-passing
| false |
b4aee4ee2259667a12896fa4d8b6828d1ebbcf1e
|
2c1b9940ae78fcdb50e728cadc8954c45e7da135
|
/rtmama.scm
|
abb1e95dc13a0ad116eb6a7cfc3421bcc784b018
|
[
"MIT"
] |
permissive
|
ursetto/zbguide
|
2e9bac1033297d8359ac59426ce7ba692efcc0d3
|
5ef0241b44ed676d9ebdd673ab094caf5645845b
|
refs/heads/master
| 2018-12-28T03:33:50.219317 | 2011-07-20T06:05:59 | 2011-07-20T06:05:59 | 2,050,495 | 1 | 0 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 2,350 |
scm
|
rtmama.scm
|
;;
;; Custom routing Router to Mama (ROUTER to REQ)
;;
;; While this example runs in a single process, that is just to make
;; it easier to start and stop the example. Each thread has its own
;; context and conceptually acts as a separate process.
;;
(use zmq random-bsd data-structures)
(include "zhelpers.scm")
(define +num-workers+ 10)
;;; task
(define (worker-task)
(let* ((ctx (make-context 1))
(worker (make-socket 'req ctx)))
;; We set the socket identity to a random string as in the original;
;; but we can safely send and receive NULs so it's not required.
(randomize-socket-identity! worker)
(connect-socket worker "ipc://routing.ipc")
(let loop ((total 0))
(send-message worker "ready")
(let ((workload (receive-message* worker)))
(if (string=? workload "END")
(print "Processed: " total " tasks")
(begin (thread-millisleep! (+ 1 (random 1000)))
(loop (+ total 1))))))
(close-socket worker)
(terminate-context ctx)))
;;; main
(define client (make-socket 'xrep)) ;; FIXME: router
(bind-socket client "ipc://routing.ipc")
(define workers
(list-tabulate +num-workers+
(lambda (i) (make-thread worker-task
(conc "worker" i)))))
(for-each thread-start! workers)
(dotimes (i (* 10 +num-workers+))
;; LRU worker is next waiting in queue
(let ((address (receive-message* client)))
(receive-message* client) ;; discard empty frame
(receive-message* client) ;; discard ready message
;; (print "sending to address " address)
(send-multipart-message* client address ""
"This is the workload")))
;; Now ask mamas to shut down and report their results
(dotimes (i +num-workers+)
(let ((address (receive-message* client)))
(receive-message* client)
(receive-message* client)
(send-multipart-message* client address ""
"END")))
(close-socket client)
(terminate-context (zmq-default-context))
(for-each thread-join! workers) ;; wait for workers
#|
Processed: 10 tasks
Processed: 13 tasks
Processed: 9 tasks
Processed: 14 tasks
Processed: 9 tasks
Processed: 10 tasks
Processed: 9 tasks
Processed: 10 tasks
Processed: 7 tasks
Processed: 9 tasks
real 0m5.078s
|#
| false |
da26bab2cebddc0a94e281746920f1b5600b138d
|
afc89799bda289c12d6d7153d7643379434e6a52
|
/nabs/tools.scm
|
a605e1690b1db8dfaa765ff781f27e917241be7a
|
[
"MIT"
] |
permissive
|
PlumpMath/nabs
|
b72763467de6ff076fb40efddc54f6432f35065f
|
9459fdfd316c862ec263525ecb2197a4afdd5a26
|
refs/heads/master
| 2021-01-18T22:15:27.314873 | 2014-05-21T14:52:47 | 2014-05-21T14:52:47 | null | 0 | 0 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 1,521 |
scm
|
tools.scm
|
(define-module (nabs tools)
:use-module (ice-9 readline)
)
(define-public (print . args) (for-each display args))
(define-public (concat . args) (string-concatenate args))
(define-public (print-alternatives index alternatives)
(cond ((not (null? alternatives))
(begin (print "[" index "] " (car alternatives) "\n")
(print-alternatives (+ 1 index) (cdr alternatives))))
(#t index)))
(define (pick index alternatives) (if (< index 2) (car alternatives) (pick (- index 1) (cdr alternatives))))
(define (user-choice what alternatives)
(let* ((header (print "Multiple versions of " what " found.\n"))
(count (print-alternatives 1 alternatives))
(input (readline (concat "Which one do you want to use? ")))
(value (if input (string->number input) 0)))
(if (or (< value 1) (> value count))
(user-choice what alternatives)
(pick value alternatives))))
(define-public (pick-unique what alternatives)
(cond ((null? alternatives)
(readline (concat "Couldn't find a suitable version of " what ".\n Please input the path to use: ")))
((null? (cdr alternatives)) (car alternatives))
(#t (user-choice what alternatives))))
(define-public (in-list? needle haystack) (cond ((null? haystack) #f) ((equal? needle (car haystack)) #t) (#t (in-list? needle (cdr haystack)))))
(define-public (append-list listlist)
(if (null? listlist) '() (append (car listlist) (append-list (cdr listlist)))))
| false |
6922b46d5365959e9fe966ccec37aaba2469392c
|
dd4cc30a2e4368c0d350ced7218295819e102fba
|
/vendored_parsers/vendor/tree-sitter-elisp/queries/tags.scm
|
7abcb9a4d6ce42992e8452bf7af9c6e70bf45108
|
[
"MIT",
"LicenseRef-scancode-unknown-license-reference",
"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 | 206 |
scm
|
tags.scm
|
;; defun/defsubst
(function_definition name: (symbol) @name) @definition.function
;; Treat macros as function definitions for the sake of TAGS.
(macro_definition name: (symbol) @name) @definition.function
| false |
456945fe55d4d41c0adf3cbe3f31ed07327e243f
|
026beb778c2dd835189fa131c0770df49b8a7868
|
/emul/scheme/syntax/core.sls
|
d84a02d9885d1793d582219b2daeda21d3e00e99
|
[] |
no_license
|
okuoku/r7c
|
8c51a19fba483aa3127136cbbc4fbedb8ea0798a
|
6c8522ac556e7e5c8e94b4deb29bbedb8aad4a84
|
refs/heads/master
| 2021-01-22T23:43:27.004617 | 2013-07-20T10:53:29 | 2013-07-20T10:53:29 | 11,394,673 | 2 | 0 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 1,575 |
sls
|
core.sls
|
(library (emul scheme syntax core)
(export
else
=>
let-syntax
letrec-syntax
syntax-rules _ ...
lambda
define
let/core
if
begin
quote
set!
)
(import
(emul heap type booleans)
(emul heap type specials)
(emul helper export)
(emul helper bridge)
(except (rename (emul vm core)
(define core-define)
(let let/core))
if)
;; FIXME: how do we handle them?
(only (rnrs)
else
=>
set!
begin
let-syntax
letrec-syntax)
(prefix (only (rnrs)
lambda
quote) rnrs-))
(define-syntax lambda
(syntax-rules ()
((_ var body ...)
(bridge/out (rnrs-lambda var body ...)))))
(define-syntax define
(syntax-rules ()
((_ (nam var ...) body ...)
(core-define nam (lambda (var ...) body ...)))
((_ (nam var . last) body ...)
(core-define nam (lambda (var . last) body ...)))
((_ (nam) body ...)
(core-define nam (lambda () body ...)))
((_ nam dat)
(core-define nam dat))))
(define-syntax quote
(syntax-rules ()
((_ obj)
(export (rnrs-quote obj)))))
(define-syntax if
(syntax-rules ()
((_ e a)
(if e a (unspecified)))
((_ e a b)
(%if e a b))))
)
| true |
8a7bd7196013df07648c98336778c97ad94ced6d
|
2fc7c18108fb060ad1f8d31f710bcfdd3abc27dc
|
/lib/combine.scm
|
1a76f1617f2c61ec3aa4fee2acc4b93fcf8966e2
|
[
"LicenseRef-scancode-public-domain",
"LicenseRef-scancode-warranty-disclaimer",
"CC0-1.0"
] |
permissive
|
bakul/s9fes
|
97a529363f9a1614a85937a5ef9ed6685556507d
|
1d258c18dedaeb06ce33be24366932143002c89f
|
refs/heads/master
| 2023-01-24T09:40:47.434051 | 2022-10-08T02:11:12 | 2022-10-08T02:11:12 | 154,886,651 | 68 | 10 |
NOASSERTION
| 2023-01-25T17:32:54 | 2018-10-26T19:49:40 |
Scheme
|
UTF-8
|
Scheme
| false | false | 1,421 |
scm
|
combine.scm
|
; Scheme 9 from Empty Space, Function Library
; By Nils M Holm, 2009
; Placed in the Public Domain
;
; (combine integer list) ==> list
; (combine* integer list) ==> list
; (load-from-library "combine.scm")
;
; Create k-combinations of the elements of the given list. K (the
; size of the combinations) is specified in the integer argument.
; COMBINE creates combinations without repetition, and COMBINE*
; creates combinations with repetition.
;
; Example: (combine 2 '(a b c)) ==> ((a b) (a c) (b c))
; (combine* 2 '(a b c)) ==> ((a a) (a b) (a c)
; (b b) (b c) (c c))
(define (combine3 n set rest)
(letrec
((tails-of
(lambda (set)
(cond ((null? set)
'())
(else
(cons set (tails-of (cdr set)))))))
(combinations
(lambda (n set)
(cond
((zero? n)
'())
((= 1 n)
(map list set))
(else
(apply append
(map (lambda (tail)
(map (lambda (sub)
(cons (car tail) sub))
(combinations (- n 1) (rest tail))))
(tails-of set))))))))
(combinations n set)))
(define (combine n set)
(combine3 n set cdr))
(define (combine* n set)
(combine3 n set (lambda (x) x)))
| false |
00bd17dd0c759ebc1a9af5e1a9d22e9bd3fb7a38
|
aa0102609ec43e4bd4319b90b65a3125e5c2162a
|
/interpreter/all - ref.ss
|
505d3783d39f55d033b49ffa9435f4d0e4bce67b
|
[] |
no_license
|
Joycexuy2/Code
|
9d91dfb9a745d0b9ec51428444e6a4e4491470ec
|
ed82f0a2cc7b6acf7787e86906f9e2bc5b0142f2
|
refs/heads/master
| 2021-05-03T18:19:42.294545 | 2016-10-25T22:28:35 | 2016-10-25T22:28:35 | 71,944,295 | 0 | 0 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 30,764 |
ss
|
all - ref.ss
|
;: Single-file version of the interpreter.
;; Easier to submit to server, probably harder to use in the development process
(load "chez-init.ss")
;-------------------+
; |
; DATATYPES |
; |
;-------------------+
(define lambda-var?
(lambda (x)
(or (symbol? x)
(null? x)
(pair? x))))
; parsed expression
(define-datatype expression expression?
[var-exp
(id symbol?)]
[lit-exp
(id
(lambda (x)
(or (boolean? x)
(number? x)
(string? x)
(vector? x)
(symbol? x)
(pair? x)
(null? x))))]
[lambda-exp
(var (lambda (y) (andmap (lambda (x)
(or (symbol? x)
(pair? x))) y)))
(body (check-eles-in-list expression?))]
[lambda-symbol-exp
(var symbol?)
(body (check-eles-in-list expression?))]
[lambda-improper-exp
(var improper?)
(body (check-eles-in-list expression?))]
[let-exp
(var (list-of symbol?))
(val (list-of expression?))
(body (check-eles-in-list expression?))]
[let*-exp
(var (list-of symbol?))
(val (list-of expression?))
(body (check-eles-in-list expression?))]
[letrec-exp
(names (list-of symbol?))
(idss (lambda (x) (ormap (lambda (y) (or ((list-of symbol?) y)
((list-of improper?) y))) x)))
(bodies (list-of expression?))
(letrec-body (check-eles-in-list expression?))]
[named-let-exp
(name symbol?)
(var (list-of symbol?))
(val (list-of expression?))
(body (check-eles-in-list expression?))]
[if-else-exp
(test-exp expression?)
(true-exp expression?)
(false-exp expression?)]
[if-without-else-exp
(test-exp expression?)
(true-exp expression?)]
[set!-exp
(var symbol?)
(body expression?)]
[app-exp
(rand expression?)
(rator (lambda (x) (map expression? x)))]
[or-exp
(var (list-of expression?))]
[and-exp
(var (list-of expression?))]
[cond-exp
(tests (list-of expression?))
(bodies (list-of expression?))]
[begin-exp
(bodies (list-of expression?))]
[case-exp
(test expression?)
(comparators (list-of expression?))
(bodies (list-of expression?))]
[while-exp
(test expression?)
(bodies (list-of expression?))]
[define-exp
(var symbol?)
(body expression?)]
)
;; environment type definitions
(define scheme-value?
(lambda (x) #t))
(define list-of
(lambda (pred)
(lambda (ls)
(if (list? ls)
(andmap pred ls)
#f))))
(define-datatype environment environment?
[empty-env-record]
[extended-env-record
(syms (lambda (y) (andmap (lambda (x)
(or (symbol? x)
(pair? x)
(improper? x))) y)))
(vals (list-of scheme-value?))
(env environment?)]
[recursively-extended-env-record
(proc-names (list-of symbol?))
(idss (lambda (x) (ormap (lambda (y) (or ((list-of symbol?) y)
((list-of improper?) y))) x)))
(bodies (list-of expression?))
(env environment?)])
; datatype for procedures. At first there is only one
; kind of procedure, but more kinds will be added later.
(define-datatype proc-val proc-val?
[prim-proc
(name symbol?)]
[closure
(params (lambda (y) (andmap (lambda (x)
(or (symbol? x)
(pair? x))) y)))
(bodies (list-of expression?))
(env environment?)]
[closure-imp
(params improper?)
(bodies (list-of expression?))
(env environment?)]
[closure-sym
(params symbol?)
(bodies (list-of expression?))
(env environment?)])
;-------------------+
; |
; PARSER |
; |
;-------------------+
(define 1st car)
(define 2nd cadr)
(define 3rd caddr)
(define 4th cadddr)
(define 2-lists?
(lambda (lst)
(if (null? lst)
#t
(if (and (list? (car lst)) (eq? (length (car lst)) 2))
(2-lists? (cdr lst))
#f))))
(define check-eles-in-list
(lambda (pred)
(lambda (val)
(or (null? val)
(and (list? val) (pred (car val)) ((check-eles-in-list pred) (cdr val)))))))
(define check-eles-in-set
(lambda (exp)
(lambda (datum)
(and ((check-eles-in-list exp) datum)
(let loop ([datum datum])
(if (null? datum)
#t
(if (member (car datum) (cdr datum))
#f
(loop (cdr datum)))))))))
(define split-list
(lambda(ls)
(list (parse-exp (car ls))(parse-exp (cadr ls)))))
(define unsplit-list
(lambda(ls)
(list (unparse-exp (car ls))(unparse-exp (cadr ls)))))
(define improper?
(lambda (ls)
(let check ([rest ls])
(cond [(null? rest) #t]
[(symbol? rest) #t]
[else (and (symbol? (car rest)) (check (cdr rest)))]))))
(define map-ordered
(lambda (proc exp)
(let helper ([e exp])
(if (null? e)
(list)
(cons (proc (car e)) (helper (cdr exp)))))))
(define expand-let
[lambda (ls newls)
(if [null? (cdr ls)]
(list 'let ls newls)
(list 'let (list (car ls)) (expand-let (cdr ls) newls)))])
(define let*->let
[lambda (ls)
(expand-let (cadr ls) (caddr ls))])
(define parse-exp
(lambda (datum)
(cond
[(symbol? datum)
(if (eq? 'else datum)
(lit-exp datum)
(var-exp datum))]
[(or (number? datum) (boolean? datum) (string? datum) (vector? datum) (null? datum) (null? datum) (symbol? datum)
(and (list? datum) (list? (cdr datum)) (eqv? 'quote (1st datum))))
(if (and (list? datum) (list? (cdr datum)) (eqv? 'quote (1st datum)))
(lit-exp (2nd datum))
(lit-exp datum))]
[(and (pair? datum) (not (list? datum)))
(eopl:error 'parse-exp "bad expression: ~s" datum)]
[(pair? datum)
(cond
;cond
;[(eq? 'ref (car datum))
; (ref-exp (cadr datum))]
[(eq? 'cond (car datum))
(cond
[(or (null? (cdr datum))(andmap (lambda (x) (not (pair? x))) (cdr datum))
(ormap null? (map cdr (cdr datum))))
(eopl:error 'parse-exp "Found empty cond expression: ~s" datum)]
[else
(let ([test-exps (map car (cdr datum))]
[list-of-bodies ((lambda (x) (map parse-exp x)) (map cadr (cdr datum)))])
(if (= (or (list-index (lambda (e) (eq? e 'else)) test-exps) (- (length list-of-bodies) 1)) (- (length list-of-bodies) 1))
(cond-exp (map parse-exp test-exps) list-of-bodies)
(eopl:error 'parse-exp "Found an else not at the end of a cond expression: ~s" datum)))])]
[(eq? 'case (car datum))
(cond
[(or (null? (cdr datum))(andmap (lambda (x) (not (pair? x))) (cdr datum))
(andmap (lambda (x) (not (pair? x))) (cddr datum))
(ormap null? (map cdr (cdr datum))))
(eopl:error 'parse-exp "Found empty case expression: ~s" datum)]
[else
(let ([test-exps (cadr datum)]
[comps (map car (cddr datum))]
[list-of-bodies ((lambda (x) (map parse-exp x)) (map cadr (cddr datum)))])
(if (= (or (list-index (lambda (e) (eq? e 'else)) comps) (- (length list-of-bodies) 1)) (- (length list-of-bodies) 1))
(case-exp (parse-exp test-exps) (map parse-exp comps) list-of-bodies)
(eopl:error 'parse-exp "Found an else not at the end of a case expression: ~s" datum)))])]
[(eq? 'begin (car datum))
(cond
[(null? (cdr datum))
(eopl:error 'parse-exp "found an empty begin: ~s" datum)]
[else
(begin-exp (map parse-exp (cdr datum)))])]
[(eq? 'and (car datum)) (if (null? (cdr datum))
(and-exp (list (lit-exp #t)))
(and-exp (map parse-exp (cdr datum))))]
[(eq? 'or (car datum))
(if (null? (cdr datum))
(or-exp (list (lit-exp #f)))
(or-exp (map parse-exp (cdr datum))))]
[(eq? 'while (car datum))
(cond
[(or (null? (cdr datum)) (null? (cddr datum)))
(eopl:error 'parse-exp "No test/body expressions found in a while expression: ~s" datum)]
[else
(while-exp (parse-exp (2nd datum)) (map parse-exp (cddr datum)))])]
[(eq? (1st datum) 'lambda);lambda
(if (< (length (cdr datum)) 2)
(eopl:error 'parse-exp "Error in parse-exp: lambda: incorrect length: " datum)
(cond
[(and (list? (2nd datum)))
; ((check-eles-in-set symbol?) (2nd datum)))
(lambda-exp (2nd datum) (map parse-exp (cddr datum)))]
[(symbol? (2nd datum))
(lambda-symbol-exp (2nd datum) (map parse-exp (cddr datum)))]
[(improper? (2nd datum))
(lambda-improper-exp (2nd datum) (map parse-exp (cddr datum)))]
[(not(list? (2nd datum)))
(lambda-exp (2nd datum) (map parse-exp (cddr datum)))]
[else
(eopl:error 'parse-exp "Error in parse-exp: lambda argument list: formals must be symbols: " datum)]))]
[(eq? (1st datum) 'letrec)
(if (not (> (length datum) 1))
(eopl:error 'parse-exp "Error in parse-exp: letrec: incorrect length: " datum)
(cond
[(and (list? (2nd datum))
((check-eles-in-set symbol?) (map car (2nd datum))))
(letrec-exp (map car (2nd datum))(map cadadr (2nd datum))
(map parse-exp (map car (map cddadr (2nd datum)))) (map parse-exp (cddr datum)))]
[else
(eopl:error 'parse-exp "Error in parse-exp: letrec:" datum)]))]
[(and (eq? (1st datum) 'let);named-let
(symbol? (2nd datum)))
(if (not (> (length datum) 1))
(eopl:error 'parse-exp "Error in parse-exp: named-let: incorrect length: " datum)
(cond
[(and (andmap list? (3rd datum))
((check-eles-in-set symbol?) (map car (3rd datum))))
(named-let-exp (2nd datum)
(map car (3rd datum))
(map parse-exp (map cadr (3rd datum)))
(map parse-exp (cdddr datum)))]
[else
(eopl:error 'parse-exp "Error in parse-exp: named-let:" datum)]))]
[(or (and (eq? (1st datum) 'let) (list? (2nd datum))));let
(if (not (> (length datum) 2))
(eopl:error 'parse-exp "Error in parse-exp: let/let*/letrec: incorrect length: " datum)
(cond
[(and (list? (2nd datum))
(2-lists? (2nd datum))
((check-eles-in-set symbol?) (map car (2nd datum))))
(let-exp (map car (2nd datum)) (map parse-exp (map cadr (2nd datum)))
(map parse-exp (cddr datum)))]
[else
(eopl:error 'parse-exp "Error in parse-exp: let argument list: formals must be symbols:" datum)]))]
[(eq? (1st datum) 'let*) ;let*
(if (not (> (length datum) 2))
(eopl:error 'parse-exp "Error in parse-exp: let/let*/letrec: incorrect length: " datum)
(cond
[(and (list? (2nd datum))
(2-lists? (2nd datum))
((check-eles-in-set symbol?) (map car (2nd datum))))
(let*-exp (map car (2nd datum)) (map parse-exp (map cadr (2nd datum)))
(map parse-exp (cddr datum)))]
[else
(eopl:error 'parse-exp "Error in parse-exp: let argument list: formals must be symbols:" datum)]))]
[(eq? (1st datum) 'if);if
(cond
[(eq? (length (cdr datum)) 3);if-else
(if-else-exp (parse-exp (2nd datum))
(parse-exp (3rd datum))
(parse-exp (4th datum)))]
[(eq? (length (cdr datum)) 2);if-without-else
(if-without-else-exp (parse-exp (2nd datum))
(parse-exp (3rd datum)))]
[else
(eopl:error 'parse-exp "Error in parse-exp: if: missing then and else parts: " datum)])]
[(eq? (1st datum) 'set!)
(cond
[(> (length datum) 3)
(eopl:error 'parse-exp "Error in parse-exp: set!: Too many parts: " datum)]
[(< (length datum) 2)
(eopl:error 'parse-exp "Error in parse-exp: set!: missing parts: " datum)]
[(and (eq? (length datum) 3)
(symbol? (2nd datum)))
(set!-exp (2nd datum)
(parse-exp (3rd datum)))]
[else
(eopl:error 'parse-exp "Error in parse-exp: set!: " datum)])]
[(eq? (1st datum) 'define)
(cond
[(> (length datum) 3)
(eopl:error 'parse-exp "Error in parse-exp: define!: Too many parts: " datum)]
[(< (length datum) 2)
(eopl:error 'parse-exp "Error in parse-exp: define!: missing parts: " datum)]
[(and (eq? (length datum) 3)
(symbol? (2nd datum)))
(define-exp (2nd datum) (parse-exp (3rd datum)))]
[else
(eopl:error 'parse-exp "Error in parse-exp: define!: " datum)])]
[else
(app-exp (parse-exp (1st datum))
(map parse-exp (cdr datum)))])]
[else (eopl:error 'parse-exp "bad expression: ~s" datum)])))
(define unparse-exp
(lambda (exp)
(cases expression exp
[var-exp (id) id]
[lit-exp (id) id]
[lambda-exp (var body)
(append (list 'lambda var)
(map unparse-exp body))]
[let-exp (var val body)
(append (list var (unparse-exp val))
(map unparse-exp body))]
[named-let-exp (name val body)
(append (list 'let name (unparse-exp assign))
(map unparse-exp body))]
[if-else-exp (test-exp true-exp false-exp)
(list 'if
(unparse-exp test-exp)
(unparse-exp true-exp)
(unparse-exp false-exp))]
[if-without-else-exp (test-exp true-exp)
(list 'if
(unparse-exp test-exp)
(unparse-exp true-exp))]
[set!-exp (var body)
(list 'set!
var
(unparse-exp body))]
[app-exp (rand rator)
(cons (unparse-exp rand)
(map unparse-exp rator))])))
;-------------------+
; |
; ENVIRONMENTS |
; |
;-------------------+
; Environment definitions for CSSE 304 Scheme interpreter. Based on EoPL section 2.3
(define empty-env
(lambda ()
(empty-env-record)))
(define extend-env
(lambda (syms vals env)
(extended-env-record syms (map (lambda (x) (if (box? x) x (box x))) vals) env)))
(define extend-env-recursively
(lambda (proc-names idss bodies old-env)
(recursively-extended-env-record
proc-names idss bodies old-env)))
(define list-find-position
(lambda (sym los)
(list-index (lambda (xsym) (eqv? sym xsym)) los)))
(define list-index
(lambda (pred ls)
(cond
((null? ls) #f)
((pred (car ls)) 0)
(else (let ((list-index-r (list-index pred (cdr ls))))
(if (number? list-index-r)
(+ 1 list-index-r)
#f))))))
;(define-datatype cell cell?
; (lambda (v) (list v 'a-cell)))
;
;(define cell-ref car)
;(define cell-set! set-car!)
(define cell? box?)
(define deref unbox)
(define set-ref! set-box!)
(define apply-env
(lambda (env sym succeed fail) ; succeed and fail are procedures applied if the var is or isn't found, respectively.
(deref (apply-env-ref env sym succeed fail))))
(define apply-env-ref
(lambda (env sym succeed fail) ; succeed and fail are procedures applied if the var is or isn't found, respectively.
(cases environment env
[empty-env-record ()
(fail)]
[extended-env-record (syms vals env)
(let ((pos (list-find-position sym syms)))
(if (number? pos)
(succeed (list-ref vals pos))
(apply-env-ref env sym succeed fail)))]
[recursively-extended-env-record
(procnames idss bodies old-env)
(let ([pos (list-find-position sym procnames)])
(if (number? pos)
(cond [((list-of symbol?)(list-ref idss pos))
(closure (list-ref idss pos)
(list(list-ref bodies pos))
env)]
[else (closure-imp (list-ref idss pos) (list (list-ref bodies pos)) env)])
(apply-env-ref old-env sym succeed fail)))])))
;-----------------------+
; |
; SYNTAX EXPANSION |
; |
;-----------------------+
; To be added later
(define syntax-expand
(lambda (exp)
(cases expression exp
[if-without-else-exp (test-exp true-exp)
(if-without-else-exp (syntax-expand test-exp) (syntax-expand true-exp))]
[if-else-exp (test-exp true-exp false-exp)
(if-else-exp (syntax-expand test-exp) (syntax-expand true-exp) (syntax-expand false-exp))]
[lambda-exp (var body)
(lambda-exp var (map syntax-expand body))]
[lambda-symbol-exp (var body)
(lambda-symbol-exp var (map syntax-expand body))]
[lambda-improper-exp (var body)
(lambda-improper-exp var (map syntax-expand body))]
[let-exp (var val body)
(app-exp (lambda-exp var (map syntax-expand body)) (map syntax-expand val))]
[let*-exp (var val body)
(syntax-expand
(let helper ([var var] [val val])
(cond [(and (null? (cdr var)) (null? (cdr val)))
(let-exp var (list (syntax-expand (car val))) (map syntax-expand body))]
[else (let-exp (list (car var))
(list (syntax-expand (car val)))
(list (helper (cdr var) (cdr val))))])))]
[letrec-exp (names idss bodies letrec-body)
(letrec-exp names idss (map syntax-expand bodies) (map syntax-expand letrec-body))]
[named-let-exp (name var val body)
(letrec-exp (list name) (list var) (map syntax-expand body) (list (app-exp (var-exp name) val)))]
;previously we just passed"body", but it should be syntax expanded
;before we passed it to the letrec-exp. That was my fault. I already submited
;to the server.
[set!-exp (var body)
(set!-exp var (syntax-expand body))]
[app-exp (rand rator)
(app-exp (syntax-expand rand) (map syntax-expand rator))]
[or-exp (var)
(let help ([val var])
(cond [(null? val) (lit-exp #f)]
[(null? (cdr val)) (syntax-expand (car val))]
[else
(app-exp
(lambda-exp
(list 'x)
(list
(if-else-exp
(var-exp 'x)
(var-exp 'x)
(help (cdr val)))))
(list (syntax-expand (1st val))))]))]
[and-exp (var)
(let help ([val var])
(cond [(null? val) (lit-exp #t)]
[(null? (cdr val)) (syntax-expand (car val))]
[else
(app-exp
(lambda-exp
(list 'x)
(list
(if-else-exp
(var-exp 'x)
(help (cdr val))
(var-exp 'x))))
(list (syntax-expand (1st val))))]))]
[cond-exp (tests bodies)
(let help ([tes tests][val bodies])
(cond
[(null? tes) (parse-exp '(void))]
[(eq? (car tes) '(else)) (syntax-expand (car val))]
[else(app-exp
(lambda-exp
(list 'x)
(list
(if-else-exp
(var-exp 'x)
(syntax-expand (car val))
(help (cdr tes) (cdr val)))))
(list (syntax-expand (1st tes))))]))]
[case-exp (tests comparators bodies)
(let help ([tes tests][comp comparators][val bodies])
(cond
[(null? comp) (app-exp (lit-exp '(void)))]
[(eq? (car comp) '(else)) (syntax-expand (car val))]
[else(app-exp
(lambda-exp
(list 'x)
(list
(if-without-else-exp
(lit-exp (and (list? (member (var-exp 'x) (syntax-expand (car comp))))))
(syntax-expand (car val))
(help tes (cdr comp) (cdr val)))))
(list (syntax-expand tes)))]))]
[while-exp (test bodies)
(while-exp (syntax-expand test) (map syntax-expand bodies))]
[begin-exp (bodies)
(app-exp (lambda-exp '() (map syntax-expand bodies)) (list))]
[define-exp (var body)
(define-exp var (syntax-expand body))]
;[ref-exp (id)
; (ref-exp (box id))]
[else exp])))
;-------------------+
; |
; INTERPRETER |
; |
;-------------------+
(define *prim-proc-names* '(+ - * / not add1 sub1 zero? not < > >= <= = cons car cdr caar cadr cdar cddr caaar caadr cadar caddr cdaar cdadr cddar cdddr list null? assq eq? equal?
atom? length list->vector list? pair? procedure? vector->list vector
make-vector vector-ref vector? number? symbol? set-car! set-cdr!
vector-set! display newline quote apply map quotient eqv? list-tail append))
(define init-env ; for now, our initial global environment only contains
(extend-env ; procedure names. Recall that an environment associates
*prim-proc-names* ; a value (not an expression) with an identifier.
(map prim-proc
*prim-proc-names*)
(empty-env)))
(define global-env init-env)
(define reset-global-env
(lambda () (set! global-env init-env)))
; top-level-eval evaluates a form in the global environment
(define eval-bodies
(lambda (bodies env)
(let loop ([bodies bodies])
(if (null? (cdr bodies))
(eval-exp (car bodies) env)
(begin
(eval-exp (car bodies) env)
(loop (cdr bodies)))))))
(define top-level-eval
(lambda (form)
; later we may add things that are not expressions.
(eval-exp form (empty-env))))
(define get-refs
(lambda (rands env)
(map
(lambda (x)
(if (eqv? 'var-exp (1st x))
(apply-env-ref env (2nd x)
(lambda (x) x)
(lambda ()
(apply-env-ref global-env (2nd x)
(lambda (x) x)
(lambda ()
(eopl:error 'get-refs
"variable not found in environment: ~s" (2nd x))))))
(void)))
rands)))
; eval-exp is the main component of the interpreter
(define eval-exp
(let ([identity-proc (lambda (x) x)])
(lambda (exp env)
(cases expression exp
[lit-exp (datum) datum]
[if-without-else-exp (test-exp true-exp)
(if (eval-exp test-exp env)
(eval-exp true-exp env))]
[if-else-exp (test-exp true-exp false-exp)
(if (eval-exp test-exp env)
(eval-exp true-exp env)
(eval-exp false-exp env))]
[lambda-exp (var body) (closure var body env)]
[lambda-symbol-exp (var body) (closure-sym var body env)]
[lambda-improper-exp (var body) (closure-imp var body env)]
[while-exp (test bodies)
(letrec ([helper (lambda ()
(if (eval-exp test env)
(begin (eval-bodies bodies env)
(helper))))])
(helper))]
[var-exp (id)
(apply-env-ref env id ; look up its value.
(lambda (x) (deref x)) ; procedure to call if id is in the environment
(lambda ()
(apply-env-ref global-env
id
(lambda (x) (deref x))
(lambda ()
(eopl:error 'apply-env ; procedure to call if id not in env
"variable not found in environment: ~s"
id)))))]
;add or and case cond
[app-exp (rator rands)
(let ([proc-value (eval-exp rator env)]
[args (eval-rands-vars rands env)]
[refs (get-refs rands env)])
(apply-proc proc-value args refs))]
[letrec-exp (name idss bodies letrec-body)
(eval-bodies letrec-body (extend-env-recursively name idss bodies env))]
[set!-exp (var body)
(let ([ref (apply-env-ref env var (lambda (x) x) (lambda ()
(apply-env-ref init-env var (lambda (x) x) (lambda () '#f))))])
(if ref
(set-ref! ref (eval-exp body env))
(set! global-env (extend-env (list var) (list (eval-exp body env)) global-env))))]
[define-exp (var body)
(set! global-env (extend-env (list var) (list (eval-exp body env)) global-env))]
[else (eopl:error 'eval-exp "Bad abstract syntax: ~a" exp)]))))
; evaluate the list of operands, putting results into a list
(define eval-rands
(lambda (rands env)
(map (lambda (x) (eval-exp x env)) rands)))
(define eval-rands-vars
(lambda (rands env)
(map (lambda (exp) (cases expression exp
[var-exp (var) (apply-env-ref env var (lambda (x) (deref x))
(lambda ()
(apply-env-ref global-env var (lambda (x) (deref x))
(lambda ()
(eopl:error 'apply-env "Reference not found")))))]
[else
(eval-exp exp env)])) rands)))
; Apply a procedure to its arguments.
; At this point, we only have primitive procedures.
; User-defined procedures will be added later.
(define apply-proc
(lambda (proc-value args refs)
(cases proc-val proc-value
[prim-proc (op) (apply-prim-proc op args)]
;closure
[closure (params bodies env)
(let* ([id-ls (map (lambda (x) (if (list? x)
(2nd x)
x))
params)]
[new-env (extend-env id-ls args env)]
[result (eval-bodies bodies new-env)])
(let helper ([rest params] [index 0])
(cond [(null? rest) (void)]
[(list? (car rest))
(set-ref! (list-ref refs index)
(apply-env-ref new-env (2nd (car rest))
(lambda (x) (deref x))
(lambda ()
(eopl:error 'apply-proc
"variable not found in environment: ~s" (2nd (car rest))))))
(helper (cdr rest) (+ 1 index))]
[else (helper (cdr rest) (+ 1 index))]))
result)]
[closure-imp (params bodies env)
(let* ( [id-ls (map (lambda (x) (if (list? x)
(cadr x)
x))
params)]
[new-env ((package-imp-args params (total-imp-params params 1)) (package-imp-args args (total-imp-params params 1)) env)]
[result (eval-bodies bodies new-env)])
(let helper ([rest params] [index 0])
(cond [(null? rest) (void)]
[(list? (car rest))
(set-ref! (list-ref refs index)
((apply-env-ref new-env (2nd (car rest))
(lambda (x) (deref x))
(lambda ()
(eopl:error 'apply-proc
"variable not found in environment: ~s" (2nd (car rest)))))))
(helper (cdr rest) (+ 1 index))]
[else (helper (cdr rest) (+ 1 index))]))
result)]
[closure-sym (params bodies env)
(eval-bodies bodies
(extend-env (list params) (list args) env))]
[else (eopl:error 'apply-proc
"Attempt to apply bad procedure: ~s"
proc-value)])))
(define total-imp-params
(lambda (ls acc)
(if (or (null? (cdr ls))(symbol? (cdr ls)))
acc
(total-imp-params (cdr ls) (+ acc 1)))))
(define package-imp-args
(lambda (ls num)
(if (>= num 1)
(cons (car ls) (package-imp-args (cdr ls) (- num 1)))
(list ls))))
; Usually an interpreter must define each
; built-in procedure individually. We are "cheating" a little bit.
(define apply-prim-proc
(lambda (prim-proc args)
(case prim-proc
[(+) (apply + args)]
[(-) (apply - args)]
[(*) (apply * args)]
[(/) (apply / args)]
[(zero?) (zero? (1st args))]
[(not) (not (1st args))]
[(add1) (+ (1st args) 1)]
[(sub1) (- (1st args) 1)]
[(cons) (cons (1st args) (2nd args))]
[(=) (apply = args)]
[(>) (apply > args)]
[(<) (apply < args)]
[(>=) (apply >= args)]
[(<=) (apply <= args)]
[(list) args]
[(null?) (null? (1st args))]
[(assq) (assq (1st args) (2nd args))]
[(eq?) (eq? (1st args) (2nd args))]
[(equal?) (equal? (1st args) (2nd args))]
[(atom?) (atom? (1st args))]
[(length) (length (1st args))]
[(list->vector) (list->vector (1st args))]
[(list?) (list? (1st args))]
[(pair?) (pair? (1st args))]
[(procedure?) (proc-val? (1st args))]
[(vector->list) (vector->list (1st args))]
[(vector) (apply vector args)]
[(make-vector) (if (null?(cdr args))
(make-vector (1st args))
(make-vector (1st args) (2nd args)))]
[(vector-ref) (vector-ref (1st args) (2nd args))]
[(vector?) (vector? (1st args))]
[(number?)(number? (1st args))]
[(symbol?) (symbol? (1st args))]
[(set-car!)(set-car! (1st args) (2nd args))]
[(set-cdr!)(set-cdr! (1st args) (2nd args))]
[(vector-set!)(vector-set! (1st args) (2nd args) (3rd args))]
[(display) (display (1st args))]
[(newline) (newline (1st args))]
[(car) (car (1st args))]
[(cdr) (cdr (1st args))]
[(caar) (caar (1st args))]
[(cadr) (cadr (1st args))]
[(cdar) (cdar (1st args))]
[(cddr) (cddr (1st args))]
[(caaar) (caaar (1st args))]
[(caadr) (caadr (1st args))]
[(cadar) (cadar (1st args))]
[(caddr) (caddr (1st args))]
[(cdaar) (cdaar (1st args))]
[(cdadr) (cdadr (1st args))]
[(cddar) (cddar (1st args))]
[(cdddr) (cdddr (1st args))]
[(quote) (1st args)]
[(apply) (let ([args-ls
(let apply-helper ([args (cdr args)])
(cond [(null? args) (eopl: 'apply "argument incorrect length")]
[(list? (1st args)) (1st args)]
[else (cons (1st args) (apply-helper (cdr args)))]))])
(apply-proc (1st args) args-ls (list)))]
[(map) (let helper ([rest (cdr args)])
(cond [(ormap null? rest)
(if (andmap null? rest)
(list)
(eopl: 'map "arguments have inequal length"))]
[else (cons (apply-proc (1st args) (map car rest) (list))
(helper (map cdr rest)))]))]
[(quotient) (quotient (1st args) (2nd args))]
[(eqv?) (eqv? (1st args) (2nd args))]
[(list-tail) (list-tail (1st args) (2nd args))]
[(append) (append (1st args) (2nd args))]
[else (error 'apply-prim-proc
"Bad primitive procedure name: ~s"
prim-proc)])))
(define rep ; "read-eval-print" loop.
(lambda ()
(display "--> ")
;; notice that we don't save changes to the environment...
(let ([answer (top-level-eval (parse-exp (read)))])
;; TODO: are there answers that should display differently?
(eopl:pretty-print answer) (newline)
(rep)))) ; tail-recursive, so stack doesn't grow.
(define eval-one-exp
(lambda (x) (top-level-eval (syntax-expand (parse-exp x)))))
| false |
6a4337b3c3a0af58f07c0895b56c9d11175d25cd
|
120324bbbf63c54de0b7f1ca48d5dcbbc5cfb193
|
/packages/srfi/%3a37/srfi-37-reference.scm
|
383fb4c3310db44e3df011acdbfa4e3c9cfad32d
|
[
"X11-distribute-modifications-variant",
"MIT"
] |
permissive
|
evilbinary/scheme-lib
|
a6d42c7c4f37e684c123bff574816544132cb957
|
690352c118748413f9730838b001a03be9a6f18e
|
refs/heads/master
| 2022-06-22T06:16:56.203827 | 2022-06-16T05:54:54 | 2022-06-16T05:54:54 | 76,329,726 | 609 | 71 |
MIT
| 2022-06-16T05:54:55 | 2016-12-13T06:27:36 |
Scheme
|
UTF-8
|
Scheme
| false | false | 10,125 |
scm
|
srfi-37-reference.scm
|
;;; args-fold.scm - a program argument processor
;;;
;;; Copyright (c) 2002 Anthony Carrico
;;;
;;; All rights reserved.
;;;
;;; Redistribution and use in source and binary forms, with or without
;;; modification, are permitted provided that the following conditions
;;; are met:
;;; 1. Redistributions of source code must retain the above copyright
;;; notice, this list of conditions and the following disclaimer.
;;; 2. Redistributions in binary form must reproduce the above copyright
;;; notice, this list of conditions and the following disclaimer in the
;;; documentation and/or other materials provided with the distribution.
;;; 3. The name of the authors may not be used to endorse or promote products
;;; derived from this software without specific prior written permission.
;;;
;;; THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``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 AUTHORS 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.
;;; NOTE: This implementation uses the following SRFIs:
;;; "SRFI 9: Defining Record Types"
;;; "SRFI 11: Syntax for receiving multiple values"
;;;
;;; NOTE: The scsh-utils and Chicken implementations use regular
;;; expressions. These might be easier to read and understand.
#|
(define option #f)
(define option-names #f)
(define option-required-arg? #f)
(define option-optional-arg? #f)
(define option-processor #f)
(define option? #f)
(let ()
(define-record-type option-type
($option names required-arg? optional-arg? processor)
$option?
(names $option-names)
(required-arg? $option-required-arg?)
(optional-arg? $option-optional-arg?)
(processor $option-processor))
(set! option $option)
(set! option-names $option-names)
(set! option-required-arg? $option-required-arg?)
(set! option-optional-arg? $option-optional-arg?)
(set! option-processor $option-processor)
(set! option? $option?))
|#
(define args-fold
(lambda (args
options
unrecognized-option-proc
operand-proc
. seeds)
(letrec
((find
(lambda (l ?)
(cond ((null? l) #f)
((? (car l)) (car l))
(else (find (cdr l) ?)))))
(find-option
;; ISSUE: This is a brute force search. Could use a table.
(lambda (name)
(find
options
(lambda (option)
(find
(option-names option)
(lambda (test-name)
(equal? name test-name)))))))
(scan-short-options
(lambda (index shorts args seeds)
(if (= index (string-length shorts))
(scan-args args seeds)
(let* ((name (string-ref shorts index))
(option (or (find-option name)
(option (list name)
#f
#f
unrecognized-option-proc))))
(cond ((and (< (+ index 1) (string-length shorts))
(or (option-required-arg? option)
(option-optional-arg? option)))
(let-values
((seeds (apply (option-processor option)
option
name
(substring
shorts
(+ index 1)
(string-length shorts))
seeds)))
(scan-args args seeds)))
((and (option-required-arg? option)
(pair? args))
(let-values
((seeds (apply (option-processor option)
option
name
(car args)
seeds)))
(scan-args (cdr args) seeds)))
(else
(let-values
((seeds (apply (option-processor option)
option
name
#f
seeds)))
(scan-short-options
(+ index 1)
shorts
args
seeds))))))))
(scan-operands
(lambda (operands seeds)
(if (null? operands)
(apply values seeds)
(let-values ((seeds (apply operand-proc
(car operands)
seeds)))
(scan-operands (cdr operands) seeds)))))
(scan-args
(lambda (args seeds)
(if (null? args)
(apply values seeds)
(let ((arg (car args))
(args (cdr args)))
;; NOTE: This string matching code would be simpler
;; using a regular expression matcher.
(cond
(;; (rx bos "--" eos)
(string=? "--" arg)
;; End option scanning:
(scan-operands args seeds))
(;;(rx bos
;; "--"
;; (submatch (+ (~ "=")))
;; "="
;; (submatch (* any)))
(and (> (string-length arg) 4)
(char=? #\- (string-ref arg 0))
(char=? #\- (string-ref arg 1))
(not (char=? #\= (string-ref arg 2)))
(let loop ((index 3))
(cond ((= index (string-length arg))
#f)
((char=? #\= (string-ref arg index))
index)
(else
(loop (+ 1 index))))))
;; Found long option with arg:
=> (lambda (=-index)
(let*-values
(((name)
(substring arg 2 =-index))
((option-arg)
(substring arg
(+ =-index 1)
(string-length arg)))
((option)
(or (find-option name)
(option (list name)
#t
#f
unrecognized-option-proc)))
(seeds
(apply (option-processor option)
option
name
option-arg
seeds)))
(scan-args args seeds))))
(;;(rx bos "--" (submatch (+ any)))
(and (> (string-length arg) 3)
(char=? #\- (string-ref arg 0))
(char=? #\- (string-ref arg 1)))
;; Found long option:
(let* ((name (substring arg 2 (string-length arg)))
(option (or (find-option name)
(option
(list name)
#f
#f
unrecognized-option-proc))))
(if (and (option-required-arg? option)
(pair? args))
(let-values
((seeds (apply (option-processor option)
option
name
(car args)
seeds)))
(scan-args (cdr args) seeds))
(let-values
((seeds (apply (option-processor option)
option
name
#f
seeds)))
(scan-args args seeds)))))
(;; (rx bos "-" (submatch (+ any)))
(and (> (string-length arg) 1)
(char=? #\- (string-ref arg 0)))
;; Found short options
(let ((shorts (substring arg 1 (string-length arg))))
(scan-short-options 0 shorts args seeds)))
(else
(let-values ((seeds (apply operand-proc arg seeds)))
(scan-args args seeds)))))))))
(scan-args args seeds))))
| false |
185044127c5d5b42469ed23518971f67fd9fe67f
|
bf6fad8f5227d0b0ef78598065c83b89b8f74bbc
|
/chapter03/ex3_1_1.ss
|
1807592001782fed9c257b0d3fb695ffbd918436
|
[] |
no_license
|
e5pe0n/tspl
|
931d1245611280457094bd000e20b1790c3e2499
|
bc76cac2307fe9c5a3be2cea36ead986ca94be43
|
refs/heads/main
| 2023-08-18T08:21:29.222335 | 2021-09-28T11:04:54 | 2021-09-28T11:04:54 | 393,668,056 | 0 | 0 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 422 |
ss
|
ex3_1_1.ss
|
(define print
(lambda (x)
(for-each display `(,x "\n"))
)
)
(define f
(lambda (ls)
(let ([x (memv 'a ls)])
(and x (memv 'b x))
)
)
)
(define expanded-f
(lambda (ls)
((lambda (x)
(if x (memv 'b x) #f)
) (memv 'a ls))
)
)
(define ls1 `(a b c))
(define ls2 `(1 2 3))
(print (f ls1)) ; (b c)
(print (f ls2)) ; #f
(print (expanded-f ls1)) ; (b c)
(print (expanded-f ls2)) ; #f
| false |
83340e4be03c09d936d612b51cbdf8d60ed6f264
|
f4cf5bf3fb3c06b127dda5b5d479c74cecec9ce9
|
/Tests/LispKitTests/Code/Datatypes.scm
|
1dbd410977df02d3822385228e3d90c2b1d2f2ba
|
[
"Apache-2.0"
] |
permissive
|
objecthub/swift-lispkit
|
62b907d35fe4f20ecbe022da70075b70a1d86881
|
90d78a4de3a20447db7fc33bdbeb544efea05dda
|
refs/heads/master
| 2023-08-16T21:09:24.735239 | 2023-08-12T21:37:39 | 2023-08-12T21:37:39 | 57,930,217 | 356 | 17 |
Apache-2.0
| 2023-06-04T12:11:51 | 2016-05-03T00:37:22 |
Scheme
|
UTF-8
|
Scheme
| false | false | 2,057 |
scm
|
Datatypes.scm
|
;;; Datatypes.scm
;;; Regression test data
;;;
;;; Author: Matthias Zenger
;;; Copyright © 2017 ObjectHub. 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.
(
"Binary tree type"
(1700 3 60)
(import (lispkit datatype))
(define-datatype binary-tree
(leaf val)
(node left right))
(define bt1 (leaf 17))
(define bt2 (node (node (leaf 1) (leaf 2)) (leaf 3)))
(define bt3 (node (node (leaf 1) (node (leaf 2) (leaf 4))) (leaf 5)))
(define (match-bt bt)
(match bt
((node (node (leaf x) (leaf y)) _) (+ x y))
((node (node (leaf x) _) (leaf y)) (* (+ x y) 10))
((leaf x) (* x 100))
(else 0)))
(list (match-bt bt1)
(match-bt bt2)
(match-bt bt3))
)
(
"List type"
(0 2 5 50 1000)
(define-datatype my-list my-list?
(nil)
(chain a b))
(define ml1 (nil))
(define ml2 (chain 2 (nil)))
(define ml3 (chain 2 (chain 3 (nil))))
(define ml4 (chain 2 (chain 3 (chain 4 (nil)))))
(define (match-ml ml)
(match ml
((nil) 0)
((chain a (nil)) a)
((chain a (chain b (nil))) (+ a b))
((chain a (chain b _)) (* (+ a b) 10))
(else 1000)))
(list (match-ml ml1)
(match-ml ml2)
(match-ml ml3)
(match-ml ml4)
(match-ml bt2))
)
(
"Datatype predicates"
(#t #t #f #f #f #f)
(list (my-list? ml1) (my-list? ml4) (my-list? bt1) (my-list? bt3) (my-list? 12) (my-list? '(a)))
)
| false |
a0ca2cf332724c34f0ead71b5fcddf3bc481dc9b
|
ab05b79ab17619f548d9762a46199dc9eed6b3e9
|
/sitelib/ypsilon/gdk/test.scm
|
129c77c47e6166b01ab2ec517983d4132a3baeef
|
[
"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 | 1,496 |
scm
|
test.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 test)
(export gdk_test_render_sync
gdk_test_simulate_button
gdk_test_simulate_key)
(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)))))
;; void gdk_test_render_sync (GdkWindow* window)
(define-function void gdk_test_render_sync (void*))
;; gboolean gdk_test_simulate_button (GdkWindow* window, gint x, gint y, guint button, GdkModifierType modifiers, GdkEventType button_pressrelease)
(define-function int gdk_test_simulate_button (void* int int unsigned-int int int))
;; gboolean gdk_test_simulate_key (GdkWindow* window, gint x, gint y, guint keyval, GdkModifierType modifiers, GdkEventType key_pressrelease)
(define-function int gdk_test_simulate_key (void* int int unsigned-int int int))
) ;[end]
| true |
dbdb148b98602cd8fefb919578035f1337d7f12d
|
7053803109172ee3fe36594257fb9f323f860c9a
|
/chapters/2/2.6.scm
|
56c3aa0cf161fec6b94dd82c11e3f7d2e6cb9840
|
[] |
no_license
|
david-davidson/SICP
|
0c7c38a11b11ef70146f4a511e4ac8d7c0651b82
|
393932a507afdc35cb99451ef53a059e72f71eb1
|
refs/heads/main
| 2021-06-14T00:36:59.503919 | 2021-05-28T01:54:39 | 2021-05-28T01:55:42 | 195,283,241 | 0 | 0 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 2,816 |
scm
|
2.6.scm
|
; --------------------------------------------------------------------------------------------------
; To get things started, SICP provides the following two definitions:
; --------------------------------------------------------------------------------------------------
(define zero (lambda (f)
(lambda (x) x)))
#|
Note how this works:
* `(n f)` returns a lambda that expects a simple input, like `x`.
* `((n f) x)` invokes that lambda, calling `f` `n` times under the hood.
* `(f ((n f) x))` feeds the result into `f` one more time, adding one more function call.
|#
(define (add-one n)
(lambda (f)
(lambda (x)
(f ((n f) x)))))
; --------------------------------------------------------------------------------------------------
; From there, we're asked to define `one` and `two` directly (not in terms of `zero` and`add-one`).
; (I find it helpful to think of Church numerals as adverbs, not nouns: "once," not "one.")
; --------------------------------------------------------------------------------------------------
; Both can be defined in terms of repeated execution of `f`
(define one (lambda (f)
(lambda (x)
(f x)))) ; One invocation
(define two (lambda (f)
(lambda (x)
(f (f x))))) ; Two invocations
; --------------------------------------------------------------------------------------------------
; We're also asked to define a generic `add`:
; --------------------------------------------------------------------------------------------------
#|
Note the signature here: `num -> num -> f -> x -> any` (not the more intuitive
`(num, num) -> f -> x -> any`). That's because we're choosing to follow the
constraints of the lambda calculus, where functions take just a single argument.
This works a lot like `add-one`:
* Here, we feed the results of `((n f) x)` into `(m f)`, not `f`.
* `(m f)`, just like `(n f)`, builds a lambda that calls `f` `m` times.
* So, we invoke `f` `n` times as we evalute `((n f) x)`, then call it `m` _more_ times as we pass
that result into `(m f)`.
|#
(define (add n)
(lambda (m)
(lambda (f)
(lambda (x)
((m f) ((n f) x))))))
#|
For testing, here's a helper to show that these numbers are really doing the right thing. We call
the Church numeral with 1.) an `f` that increments its input and 2.) an initial value of `0`,
basically mapping from the Church numeral right back to a familiar number.
Should work in the REPL:
* `(to-number two)` => 2
* `(to-number ((add one) two))` => 3
* etc.
|#
(define (to-number n)
((n (lambda (x) (+ x 1))) 0))
#|
I wanted to keep playing with this stuff outside of the book's exercises --
see ./more-lambda-arithmetic.scm for multiplication and subtraction, and
./more-lambda-booleans.scm for booleans and control flow.
|#
| false |
ed87b25ee6e72c92102a94375d9965be1076a654
|
ae4938300d7eea07cbcb32ea4a7b0ead9ac18e82
|
/proc/compare.ss
|
5ac9795d08030baec08f08ef76474b6d6f6d74e3
|
[] |
no_license
|
keenbug/imi-libs
|
05eb294190be6f612d5020d510e194392e268421
|
b78a238f03f31e10420ea27c3ea67c077ea951bc
|
refs/heads/master
| 2021-01-01T19:19:45.036035 | 2012-03-04T21:46:28 | 2012-03-04T21:46:28 | 1,900,111 | 0 | 1 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 559 |
ss
|
compare.ss
|
#!r6rs
(library (imi proc compare)
(export make-comparer-by<
make-comparer-by>
make-comparer-by</>)
(import (rnrs))
;;; DRAFT
; other names?
(define (make-comparer-by< <)
(lambda (x y)
(cond
[(< x y) '<]
[(< y x) '>]
[else '=])))
(define (make-comparer-by> >)
(lambda (x y)
(cond
[(> x y) '>]
[(> y x) '<]
[else '=])))
(define (make-comparer-by</> < >)
(lambda (x y)
(cond
[(< x y) '<]
[(> x y) '>]
[else '=])))
)
| false |
288bc2dc654f7161f15de9271ef3ac36a614ff20
|
9b0c653f79bc8d0dc87526f05bdc7c9482a2e277
|
/2/2-38.ss
|
6454d25be4cadd16064e5b6f0090a66765d5e3d3
|
[] |
no_license
|
ndNovaDev/sicp-magic
|
798b0df3e1426feb24333658f2313730ae49fb11
|
9715a0d0bb1cc2215d3b0bb87c076e8cb30c4286
|
refs/heads/master
| 2021-05-18T00:36:57.434247 | 2020-06-04T13:19:34 | 2020-06-04T13:19:34 | 251,026,570 | 0 | 0 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 1,370 |
ss
|
2-38.ss
|
(define (dn x)
(display x)
(newline))
(define nil '())
(define (fold-right op initial sequence)
(if (null? sequence)
initial
(op (car sequence)
(fold-right op initial (cdr sequence)))))
; (define (fold-left op initial sequence)
; (if (null? sequence)
; initial
; (fold-left op
; (op initial (car sequence))
; (cdr sequence))))
(define (fold-left op initial sequence)
(define (iter result rest)
(if (null? rest)
result
(iter (op result (car rest))
(cdr rest))))
(iter initial sequence))
; ****************************
(dn (fold-right / 1 (list 1 2 3)))
; 3/2
(dn (fold-left / 1 (list 1 2 3)))
; 1/6
(dn (fold-right list nil (list 1 2 3)))
; (1 (2 (3 ())))
(dn (fold-left list nil (list 1 2 3)))
; (((() 1) 2) 3)
; 因为 fold-left 和 fold-right 生成的计算序列不同,要让它们的计算产生同样的结果,一个办法就是要求 op 参数,也即是传入的操作函数必须符合结合律(monoid)。
; 比如说, \ 和 list 函数都不符合结合律,所以将它们应用到 fold-left 和 fold-right 会产生不同的计算结果。
; 另一方面,像 + 、 * 、 or 和 and 那样的函数,就是符合结合律的函数,使用这些函数可以让 fold-left 和 fold-right 计算出同样的结果:
(exit)
| false |
f8bbcb54685c9d399bc05234dd63ebabdb533c5f
|
ece1c4300b543df96cd22f63f55c09143989549c
|
/Chapter4/user.scm
|
ac923cf46059343fdaf630631a0561a9b940b544
|
[] |
no_license
|
candlc/SICP
|
e23a38359bdb9f43d30715345fca4cb83a545267
|
1c6cbf5ecf6397eaeb990738a938d48c193af1bb
|
refs/heads/master
| 2022-03-04T02:55:33.594888 | 2019-11-04T09:11:34 | 2019-11-04T09:11:34 | null | 0 | 0 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 1,286 |
scm
|
user.scm
|
; Exercise 4.41: Write an ordinary Scheme program to solve the multiple dwelling puzzle.
(define (filter predicate sequence)
(cond ((null? sequence) nil)
((predicate (car sequence))
(cons (car sequence)
(filter predicate
(cdr sequence))))
(else (filter predicate
(cdr sequence)))))
(define (multiple-dwelling)
(let ((baker (list 1 2 3 4 5))
(cooper (list 1 2 3 4 5))
(fletcher (list 1 2 3 4 5))
(miller (list 1 2 3 4 5))
(smith (list 1 2 3 4 5)))
(set!
baker
(filter
(lambda (baker)
(not (= baker 5)))
baker))
(set!
cooper
(filter
(lambda (cooper)
(not (= cooper 1)))
cooper))
(set!
fletcher
(filter
(lambda (fletcher)
(not (or (= fletcher 1) (= fletcher 5))))
fletcher))
(define m&c (list))
(for-each
(lambda (c)
(for-each
(lambda (m)
(if (> m c)
(set! m&c (cons (list m c) m&c))
))
miller))
cooper)
m&c
))
(display (multiple-dwelling))
| false |
c4006e30d43ad88563b40962603e3d3a8ff1b623
|
ee8d866a11b6f484bc470558d222ed6be9e31d21
|
/example/test/fib.scm
|
e3112c92d3148cb16269bce8e38e0408a4097e0c
|
[
"MIT"
] |
permissive
|
corona10/gvmt
|
e00c6f351ea61d7b1b85c13dd376d5845c84bbb1
|
566eac01724b687bc5e11317e44230faab15f895
|
refs/heads/master
| 2021-12-08T05:12:08.378130 | 2011-11-14T17:49:18 | 2011-11-14T17:49:18 | null | 0 | 0 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 127 |
scm
|
fib.scm
|
(define (fib x)
(if (<= x 1)
1
(+ (fib (- x 2)) (fib (- x 1)))))
(display (fib 33.0))
(newline)
| false |
9d1937d4d8a38ab6290e727a1397c90eb45b5348
|
ee672a7d0e1e833a369316f5d0441f38b7fb7efb
|
/Implementation/continuations.scm
|
112c67f7a5942ddf7ee1c36ac4b0c9b93d7efdff
|
[] |
no_license
|
mvdcamme/WODA15
|
f2c558567519c1a5d6df3c50810e368c554a2b88
|
54f6258a7db73b8d3b96faff6fb70cf774924744
|
refs/heads/master
| 2021-01-16T21:23:14.456335 | 2015-11-05T10:08:43 | 2015-11-05T10:08:43 | 42,398,539 | 0 | 0 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 729 |
scm
|
continuations.scm
|
(module continuations racket
(provide (all-defined-out)
(struct-out closure-guard-failedk))
;
; Continuations
;
(struct andk (es) #:transparent)
(struct applicationk (debug) #:transparent)
(struct closure-guard-failedk (i) #:transparent)
(struct condk (pes es) #:transparent)
(struct definevk (x) #:transparent)
(struct haltk () #:transparent)
(struct ifk (e1 e2) #:transparent)
(struct letk (x es) #:transparent)
(struct let*k (x bds es) #:transparent)
(struct letreck (x bds es) #:transparent)
(struct ork (es) #:transparent)
(struct randk (e es i) #:transparent)
(struct ratork (i) #:transparent)
(struct seqk (es) #:transparent)
(struct setk (x) #:transparent)
)
| false |
7f973cef3dcb768da8407b0c5dac6eed9315bf17
|
ede19ddee7d2c88d7b6cb159bc00c2e0c950371d
|
/test.wat
|
1235b8ebffb3149563c57945002237ccb35af5ed
|
[
"MIT"
] |
permissive
|
paddymahoney/wat-js
|
29a1a8441f531744e1d83ebbf14c5cab9eaab468
|
0045525ae01e5431178af56d243524ccb7a701a4
|
refs/heads/master
| 2020-12-24T09:07:53.259247 | 2012-10-16T22:15:46 | 2012-10-16T22:15:53 | null | 0 | 0 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 5,299 |
wat
|
test.wat
|
;; -*- mode: scheme -*-
;;;;; Test Core Language
;; DEF
(provide ()
(def (x y) (list #t #f))
(assert (eq? x #t))
(assert (eq? y #f))
(assert (eq? (def #ign #t) #t)))
;; IF
(provide ()
(assert (eq? #t (if #t #t #f)))
(assert (eq? #f (if #f #t #f))))
;; VAU
(provide ()
(def env (current-environment))
(eq? #t ((vau x #ign x) #t))
(eq? #t ((vau (x . #ign) #ign x) (list #t)))
(eq? env ((vau #ign e e))))
;; EVAL
(provide ()
(def env (current-environment))
(eval (list def (quote x) #t) env)
(assert (eq? x #t))
(assert (eq? (eval #t env) #t)))
;; WRAP
(provide ()
(assert (eq? #t ((wrap (vau (x) #ign x)) (not #f)))))
;; UNWRAP
(provide ()
(assert (eq? list (unwrap (wrap list)))))
;; EQ?
(provide ()
(assert (eq? #t #t))
(assert (not (eq? #t #f)))
(assert (not (eq? (list 1) (list 1)))))
;; CONS
(provide ()
(assert (eq? #t (car (cons #t #f))))
(assert (eq? #f (cdr (cons #t #f)))))
;; MAKE-ENVIRONMENT
(provide ()
(def e1 (make-environment))
(eval (list def (quote x) #t) e1)
(eval (list def (quote y) #t) e1)
(assert (eq? #t (eval (quote x) e1)))
(assert (eq? #t (eval (quote y) e1)))
(def e2 (make-environment e1))
(assert (eq? #t (eval (quote x) e2)))
(assert (eq? #t (eval (quote y) e2)))
(eval (list def (quote y) #f) e2)
(assert (eq? #f (eval (quote y) e2)))
(assert (eq? #t (eval (quote y) e1))))
;; MAKE-TYPE
(provide ()
(def (type tagger untagger) (make-type))
(assert (eq? (type-of type) (type-of (type-of #t))))
(let ((x (list #void)))
(eq? type (type-of (tagger x)))
(eq? x (untagger (tagger x)))))
;; TYPE-OF
(provide ()
(assert (not (eq? (type-of () #void))))
(assert (eq? (type-of 0) (type-of 1))))
;; VECTOR, VECTOR-REF
(provide ()
(def (a b c) (list 1 2 3))
(def v (vector a b c))
(assert (eq? (vector-ref v 0) a))
(assert (eq? (vector-ref v 1) b))
(assert (eq? (vector-ref v 2) c)))
;; Quotation
(provide ()
(assert (symbol? 'x))
(assert (pair? '(a . b))))
;;;;; Test Crust Language
;; NULL?
(provide ()
(assert (null? ()))
(assert (not (null? 12))))
;; BEGIN
(provide ()
(assert (eq? #void (begin)))
(assert (eq? #t (begin (eq? #t #t))))
(assert (eq? #t (begin #f (eq? #t #t)))))
;; IDENTITY-HASH-CODE
(provide ()
(assert (not (eq? (identity-hash-code "foo") (identity-hash-code "bar")))))
;; DEFINE-RECORD-TYPE
(provide ()
(define-record-type pare
(kons kar kdr)
pare?
(kar kar set-kar!)
(kdr kdr set-kdr!))
(define p (kons 1 2))
(assert (num= 1 (kar p)))
(assert (num= 2 (kdr p)))
(set-kar! p 3)
(set-kdr! p 4)
(assert (num= 3 (kar p)))
(assert (num= 4 (kdr p)))
(assert (pare? p))
(assert (eq? #f (pare? 12))))
;; DEFINED?
(provide ()
(assert (eq? #f (defined? 'x (current-environment))))
(assert (eq? #f (defined? 'y (current-environment))))
(define x 1)
(assert (eq? #t (defined? 'x (current-environment))))
(assert (eq? #f (defined? 'y (current-environment))))
)
;; Delimited Control
(define-syntax test-check
(vau (#ign expr res) env
(assert (num= (eval expr env) (eval res env)))))
(define new-prompt make-prompt)
(test-check 'test2
(let ((p (new-prompt)))
(+ (push-prompt p (push-prompt p 5))
4))
9)
(test-check 'test3-1
(let ((p (new-prompt)))
(+ (push-prompt p (push-prompt p (+ (take-subcont p #ign 5) 6)))
4))
9)
(test-check 'test3-2
(let ((p (new-prompt)))
(let ((v (push-prompt p
(let* ((v1 (push-prompt p (+ (take-subcont p #ign 5) 6)))
(v1 (take-subcont p #ign 7)))
(+ v1 10)))))
(+ v 20)))
27)
(test-check 'test4
(let ((p (make-prompt)))
(+ (push-prompt p
(+ (take-subcont p sk (push-subcont sk 5))
7))
20))
32)
(test-check 'test6
(let ((p1 (new-prompt))
(p2 (new-prompt))
(push-twice (lambda (sk)
(push-subcont sk (push-subcont sk 3)))))
(+ 10
(push-prompt p1 (+ 1
(push-prompt p2 (take-subcont p1 sk (push-twice sk)))))))
15)
(test-check 'test7
(let* ((p1 (new-prompt))
(p2 (new-prompt))
(p3 (new-prompt))
(push-twice
(lambda (sk)
(push-subcont sk (push-subcont sk
(take-subcont p2 sk2
(push-subcont sk2
(push-subcont sk2 3))))))))
(+ 100
(push-prompt p1
(+ 1
(push-prompt p2
(+ 10
(push-prompt p3 (take-subcont p1 sk (push-twice sk)))))))))
135)
(test-check 'monadic-paper
(let ((p (make-prompt)))
(+ 2 (push-prompt p
(if (take-subcont p k
(+ (push-subcont k #f)
(push-subcont k #t)))
3
4))))
9)
(test-check 'ddb-1
(let ((dv (dnew #void)))
(dlet dv 12 (dref dv)))
12)
(test-check 'ddb-2
(let ((dv (dnew #void)))
(dlet dv 12 (dlet dv 14 (dref dv))))
14)
(test-check 'ddb-3
(let ((dv (dnew #void)) (p (make-prompt)))
(dlet dv 1
(push-prompt p
(dlet dv 3
(take-subcont p k (dref dv))))))
1)
(test-check 'ddb-4
(let ((dv (dnew #void)) (p (make-prompt)))
(dlet dv 1
(push-prompt p
(dlet dv 3
(take-subcont p k
(push-subcont k
(dref dv)))))))
3)
| true |
b2551b0f09146a6bb7c1dc18dd5dbdf0eecc0142
|
174072a16ff2cb2cd60a91153376eec6fe98e9d2
|
/Chap-Three/3-47-a.scm
|
ed9218914a35e81ff5a2e5f7c32d4cdcdd472ebf
|
[] |
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 | 481 |
scm
|
3-47-a.scm
|
(load "make-serializer.scm")
(define (make-semaphore n)
(let ((mutex (make-mutex)))
(define (acquire)
(mutex 'acquire)
(if ( > n 0) (begin (set! n (- n 1)) (mutex 'release) 'ok)
(begin (mutex 'release) (acquire))))
(define (release)
(mutex 'acquire)
(set! n (+ n 1))
(mutex 'release)
'ok)
(define (dispatch m)
(cond ((eq? m 'acquire) (acquire))
((eq? m 'release) (release))
(else (error "Unknown-mode make semaphore"))))
dispatch))
| false |
d8fd17ecd04dca797cdc047ccfd1fb27b2e62c9c
|
a2d8b4843847507b02085bb8adabd818f57dd09f
|
/scheme/test.scm
|
5b833e3b47d7ba69f3b8e4b4b39b2f17c93af1bb
|
[] |
no_license
|
tcharding/self_learning
|
df911b018fc86bd5f918394b79d2456bf51f35a8
|
f6bb5c6f74092177aa1b71da2ce87ca1bfc5ef3c
|
refs/heads/master
| 2022-05-13T05:09:32.284093 | 2022-05-02T08:25:18 | 2022-05-02T08:25:18 | 41,029,057 | 13 | 2 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 28 |
scm
|
test.scm
|
(define (test x)
(+ x 1))
| false |
81c85b99b2136c51fa37409247f17204693d7215
|
b83ef8d27287a1a6655a2e8e6f37ca2daf5820b7
|
/testsuite/attr-test.scm
|
c41d5fb2aff324fda93aed45984ff5e083e1a370
|
[
"MIT"
] |
permissive
|
Hamayama/c-wrapper-mg
|
5fd8360bb83bbf6a3452c46666bd549a3042da1f
|
d011d99dbed06f2b25c016352f41f8b29badcb1a
|
refs/heads/master
| 2021-01-18T22:43:46.179694 | 2020-11-10T12:05:38 | 2020-11-10T12:37:30 | 23,728,504 | 2 | 0 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 1,730 |
scm
|
attr-test.scm
|
;;;
;;; Test parse-attribute
;;;
(use gauche.test)
(test-start "parse-attribute")
(use c-wrapper)
(test-module 'c-wrapper.c-lex)
(define-macro (test-attribute desc expected source)
`(test ,desc ,expected
(lambda ()
(with-module c-wrapper.c-parser
(with-parse-context
(lambda ()
(set-input-string! ,source)
((with-module c-wrapper.c-lex parse-attribute))
(parser-attribute)))))))
(test-attribute "an attribute without args" '((always_inline)) "((always_inline))")
(test-attribute "an attribute is equals to C keyword" '((const)) "((const))")
(test-attribute "an attribute with a string arg" '((alias "__f")) "((alias(\"__f\")))")
(test-attribute "an attribute with numerical args" '((format printf 2 3)) "((format(printf, 2, 3)))")
(test-attribute "attribute list" '((weak) (alias "__f")) "((weak, alias(\"__f\")))")
(test-attribute "multiple attributes" '((weak) (alias "__f") (format printf 2 3)) "((weak, alias(\"__f\"))) __attribute__((format(printf, 2, 3)))")
(test "check token list"
'((UNION LCBRA UNSIGNED (IDENTIFIER . __l) SEMICOLON (TYPENAME . double) (IDENTIFIER . __d) SEMICOLON RCBRA *eoi*)
((__mode__ __DI__)))
(lambda ()
(with-module c-wrapper.c-parser
(with-parse-context
(lambda ()
(set-input-string! "union { unsigned __l __attribute__((__mode__(__DI__))); double __d; }")
(let ((token-list (do ((lst (list (c-scan)) (cons (c-scan) lst)))
((eq? (car lst) '*eoi*)
(reverse lst)))))
(list token-list (parser-attribute))))))))
;; epilogue
(test-end)
| false |
aaf08ada301d13d378d4f3c3b8029533d0ac1060
|
5a68949704e96b638ca3afe335edcfb65790ca20
|
/compiler/step026/lisp.scm
|
d80d7115eb86565f5be84f6c1fb805f547fdf7cf
|
[] |
no_license
|
terryc321/lisp
|
2194f011f577d6b941a0f59d3c9152d24db167b2
|
36ca95c957eb598facc5fb4f94a79ff63757c9e5
|
refs/heads/master
| 2021-01-19T04:43:29.122838 | 2017-05-24T11:53:06 | 2017-05-24T11:53:06 | 84,439,281 | 2 | 0 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 5,606 |
scm
|
lisp.scm
|
;; Libraries
;;; mit specific stuff
;;(define (gensym args) (cons 'gensym args)) ;;generate-uninterned-symbol)
;;(define gensym generate-uninterned-symbol)
;;quasiquotation
(load "/home/terry/lisp/quasiquote/quasiquote.scm")
;; non hygienic macro expander
(load "/home/terry/lisp/macro-expander/macro-expander.scm")
;; quasiquote expander
(load "/home/terry/lisp/macros/quasiquote.scm")
;; cond is nested ifs
(load "/home/terry/lisp/macros/cond.scm")
;; let is just applied lambda, but visual appearances easier keep as let
;;(load "/home/terry/lisp/macros/let.scm")
;; letrec requires lets and sets
(load "/home/terry/lisp/macros/letrec.scm")
;; let* are sequential lets
(load "/home/terry/lisp/macros/let-star.scm")
;; when is just conditional with sequencing
(load "/home/terry/lisp/macros/when.scm")
;; dont know if we need lambda expander ,
(load "/home/terry/lisp/macros/lambda.scm")
;; conjunction
(load "/home/terry/lisp/macros/and.scm")
;; disjunction
(load "/home/terry/lisp/macros/or.scm")
;; define
(load "/home/terry/lisp/macros/define.scm")
;; begin simplifier
(load "/home/terry/lisp/macros/begin.scm")
;; alpha conversion
(load "/home/terry/lisp/alpha-conversion/alpha.scm")
;; free variable analysis
(load "/home/terry/lisp/free-variables/freevar.scm")
;; the rudimentary compiler
(load "comp.scm")
;; read all the forms from a target expression
;; p is PORT
(define (read-file filename)
(let ((forms
(call-with-input-file filename
(lambda (p)
(let f ((x (read p)))
(if (eof-object? x)
'()
(cons x (f (read p)))))))))
forms))
;; (define f x) definition
;; (f x y z) ;; application
;; (if x y z) ;; conditional
;; (let ((x ..)(y ...)(z ...)) ...)
;; (set! x y) ;; not implemented assignment this yet.
(define (stage-1 forms)
(let ((me (macro-expand forms)))
(newline)
(display "stage-1: macro-expanded:")
(newline)
(display me)
(newline)
(let ((ac (alpha-convert me)))
(newline)
(display "stage-1: alpha-converted:")
(newline)
(display ac)
(newline)
ac)))
(define (toplevel-definitions forms)
(define (toplevel-helper forms defs non-defs)
(newline)
(display "FORMS = ")
(display forms)
(newline)
(cond
((null? forms) (append (reverse defs) (reverse non-defs)))
((pair? (car forms))
(let ((form (car forms)))
(newline)
(display "FORM = ")
(display form)
(newline)
(if (and (pair? form)
(eq? 'define (car form))
(symbol? (car (cdr form))))
(begin ;; its a toplevel definition
(toplevel-helper (cdr forms) (cons form defs) non-defs))
(begin ;; its not a toplevel definition
(toplevel-helper (cdr forms) defs (cons form non-defs))))))
(else (toplevel-helper (cdr forms) defs (cons (car forms) non-defs)))))
(toplevel-helper forms '() '()))
;; collect toplevel procedure arities
;; form = [define f [lambda X ...]]
;; | |
;; car cadr caddr
;;
(define (toplevel-procedures forms)
(cond
((null? forms) '())
((pair? (car forms))
(let ((form (car forms)))
(if (and (pair? form)
(eq? 'define (car form))
(symbol? (car (cdr form)))
(pair? (car (cdr (cdr form))))
(eq? 'lambda (car (car (cdr (cdr form))))))
(cons (list (car (cdr form))
(length (car (cdr (car (cdr (cdr form)))))))
(toplevel-procedures (cdr forms)))
(toplevel-procedures (cdr forms)))))
(else (toplevel-procedures (cdr forms)))))
(define (stage-2 forms)
(toplevel-procedures (stage-1 forms)))
;;(pretty-print (stage-2 (read-file "/home/terry/lisp/demo/tak/tak.scm")))
;;(pretty-print (stage-1 (read-file "/home/terry/lisp/demo/tak/tak.scm")))
(define (stage-3 forms)
(toplevel-definitions (stage-1 forms)))
;; arities and definitions listed first
;; compile definitions
;; compile expressions
(define (stage-4 infile outfile)
(let ((forms (stage-1 (read-file infile))))
(stage-4b forms outfile)))
(define (stage-4b forms outfile)
(let ((arity (toplevel-procedures forms))
(ordered-forms (toplevel-definitions forms)))
(newline)
(display "stage-4b: ordered-forms:")
(newline)
(map (lambda (of) (display of) (newline)) ordered-forms)
(newline)
(call-with-output-file outfile
(lambda (p)
(set-emit-output-port! p)
(emit "")
(emit "extern debug_stack")
(emit "global scheme_entry")
;; here compile the expression
;; initial stack index is negative wordsize
;; as [ esp - 4 ] , since esp holds return address.
(let ((initial-environment '())
(stack-index (- *wordsize*)))
;;(comp-tak-def #f stack-index initial-environment)
;; (comp-fib-def #f stack-index initial-environment)
;; (comp-fac-def #f stack-index initial-environment)
;; (comp-f3x-def #f stack-index initial-environment)
;; (comp-f3y-def #f stack-index initial-environment)
;; (comp-f3z-def #f stack-index initial-environment)
(emit "scheme_entry: nop ")
;; HEAP is passed as 1st argument
(emit "mov dword esi , [ esp + 4 ] ")
(emit "scheme_heap_in_esi: nop")
(map (lambda (expr)
(begin
(display "compiling expr => ")
(display expr)
(newline)
(comp expr stack-index initial-environment)))
ordered-forms)
;; final return
(emit "ret"))))))
;;
;;(stage-4 "/home/terry/lisp/demo/tak/tak.scm" "entry.asm")
| false |
78cabac9a2ac5db41af8770d7f08b4e0e50232a5
|
5355071004ad420028a218457c14cb8f7aa52fe4
|
/1.3/e-1.33.scm
|
70ae2a3d9a0e62d787ed0c5b067690520ad7eb29
|
[] |
no_license
|
ivanjovanovic/sicp
|
edc8f114f9269a13298a76a544219d0188e3ad43
|
2694f5666c6a47300dadece631a9a21e6bc57496
|
refs/heads/master
| 2022-02-13T22:38:38.595205 | 2022-02-11T22:11:18 | 2022-02-11T22:11:18 | 2,471,121 | 376 | 90 | null | 2022-02-11T22:11:19 | 2011-09-27T22:11:25 |
Scheme
|
UTF-8
|
Scheme
| false | false | 1,735 |
scm
|
e-1.33.scm
|
; Exercise 1.33.
;
; You can obtain an even more general version of accumulate (exercise 1.32)
; by introducing the notion of a filter on the terms to be combined. That is,
; combine only those terms derived from values in the range that satisfy a
; specified condition. The resulting filtered-accumulate abstraction takes
; the same arguments as accumulate, together with an additional predicate of
; one argument that specifies the filter. Write filtered-accumulate as a procedure.
; Show how to express the following using filtered-accumulate:
; a. the sum of the squares of the prime numbers in the interval a to b
; (assuming that you have a prime? predicate already written)
; b. the product of all the positive integers less than n that are relatively prime
; to n (i.e., all positive integers i < n such that GCD(i,n) = 1).
;
; ----------------------------------------------------------------------------
(load "../1.2/1.2.scm")
(load "../1.2/1.20.scm")
(load "../common.scm")
(define (filtered-accumulate combiner null-value filter term a next b)
(if (> a b)
null-value
(combiner
(if (filter a) (term a) null-value)
(filtered-accumulate combiner null-value filter term (next a) next b))))
; Solution to a)
(define (next x) (+ x 1))
(define (sum-prime-squares a b)
(filtered-accumulate + 0 prime? square a next b))
; (display (sum-prime-squares 1 10)) ; 88
; (newline)
; Solution to b)
(define (sum-relative-primes n)
(define (relative-prime? x)
(= (gcd x n) 1))
(filtered-accumulate * 1 relative-prime? identity 1 next n))
; Didn't check if this is real result. A bit bored with repeating
; all of these similar examples
; (display (sum-relative-primes 10)) ; 189
; (newline)
| false |
63e937e1a55090c2ecad4d995c5f6a247e9be9dc
|
08b21a94e7d29f08ca6452b148fcc873d71e2bae
|
/src/loki/compiler/util.sld
|
1200aa79db9925c32f088eacb1ed5c065a966532
|
[
"MIT"
] |
permissive
|
rickbutton/loki
|
cbdd7ad13b27e275bb6e160e7380847d7fcf3b3a
|
7addd2985de5cee206010043aaf112c77e21f475
|
refs/heads/master
| 2021-12-23T09:05:06.552835 | 2021-06-13T08:38:23 | 2021-06-13T08:38:23 | 200,152,485 | 21 | 1 |
NOASSERTION
| 2020-07-16T06:51:33 | 2019-08-02T02:42:39 |
Scheme
|
UTF-8
|
Scheme
| false | false | 4,913 |
sld
|
util.sld
|
(define-library (loki compiler util)
(import (scheme base))
(import (scheme time))
(import (scheme write))
(import (srfi 1))
(import (loki util))
(import (loki core syntax))
(export for-all
map-while
flatten
dotted-memp
dotted-map
dotted-length
dotted-butlast
dotted-last
check-set?
unionv
drop-tail
join
compose
generate-guid
check
call-with-string-output-port)
(begin
(define (map-while f lst k)
(cond ((null? lst) (k '() '()))
((pair? lst)
(let ((head (f (car lst))))
(if head
(map-while f
(cdr lst)
(lambda (answer rest)
(k (cons head answer)
rest)))
(k '() lst))))
(else (k '() lst))))
(define (flatten l)
(cond ((null? l) l)
((pair? l) (cons (car l)
(flatten (cdr l))))
(else (list l))))
(define (dotted-memp proc ls)
(cond ((null? ls) #f)
((pair? ls) (if (proc (car ls))
ls
(dotted-memp proc (cdr ls))))
(else (and (proc ls)
ls))))
(define (dotted-map f lst)
(cond ((null? lst) '())
((pair? lst) (cons (f (car lst))
(dotted-map f (cdr lst))))
(else (f lst))))
;; Returns 0 also for non-list a la SRFI-1 protest.
(define (dotted-length dl)
(cond ((null? dl) 0)
((pair? dl) (+ 1 (dotted-length (cdr dl))))
(else 0)))
(define (dotted-butlast ls n)
(let recurse ((ls ls)
(length-left (dotted-length ls)))
(cond ((< length-left n) (error "dotted-butlast: List too short" ls n))
((= length-left n) '())
(else
(cons (car ls)
(recurse (cdr ls)
(- length-left 1)))))))
(define (dotted-last ls n)
(let recurse ((ls ls)
(length-left (dotted-length ls)))
(cond ((< length-left n) (error "dotted-last: List too short" ls n))
((= length-left n) ls)
(else
(recurse (cdr ls)
(- length-left 1))))))
(define (check-set? ls = fail)
(or (null? ls)
(if (memp (lambda (x)
(= x (car ls)))
(cdr ls))
(fail (car ls))
(check-set? (cdr ls) = fail))))
(define (unionv . sets)
(cond ((null? sets) '())
((null? (car sets))
(apply unionv (cdr sets)))
(else
(let ((rest (apply unionv
(cdr (car sets))
(cdr sets))))
(if (memv (car (car sets)) rest)
rest
(cons (car (car sets)) rest))))))
(define (drop-tail list tail)
(cond ((null? list) '())
((eq? list tail) '())
(else
(cons (car list)
(drop-tail (cdr list) tail)))))
(define (join e separator)
(define (tostring x)
(cond ((symbol? x)
(symbol->string x))
((number? x)
(number->string x))
(else
(error "join: Invalid argument." e))))
(if (null? e)
""
(string-append
(tostring (car e))
(apply string-append
(map (lambda (x)
(string-append separator (tostring x)))
(cdr e))))))
(define (compose f g)
(lambda (x) (f (g x))))
;; Generate-guid returns a fresh symbol that has a globally
;; unique external representation and is read-write invariant.
;; Your local gensym will probably not satisfy both conditions.
;; Prefix makes it disjoint from all builtins.
;; Uniqueness is important for incremental and separate expansion.
(define guid-prefix "&")
(define (unique-token)
(number->string (current-jiffy) 32))
(define generate-guid
(let ((token (unique-token))
(ticks 0))
(lambda (symbol)
(set! ticks (+ ticks 1))
(string->symbol
(string-append guid-prefix
(symbol->string symbol)
"~"
token
"~"
(number->string ticks))))))
(define (check x p? from)
(or (p? x)
(syntax-violation from "Invalid argument" x)))
(define (call-with-string-output-port proc)
(define port (open-output-string))
(proc port)
(get-output-string port))
))
| false |
975950f0f0e9a305b7c284e1a0531d65c72f483c
|
3a4bf3fd60fd8aeb979f3f90ed848ccfd1c184e7
|
/srfi/r7rs-to-r6rs.scm
|
edaa3692230feba4726e305fdfe03dff3f76e4c7
|
[] |
no_license
|
scheme-requests-for-implementation/srfi-175
|
6459334a9f1ceba7fb55ba18d48b8c3381b52fc1
|
178ab2f6cda6e555f28b17563afbe11c261eedf6
|
refs/heads/master
| 2021-07-13T18:38:47.577780 | 2021-07-02T21:16:33 | 2021-07-02T21:16:33 | 209,425,660 | 0 | 2 | null | 2020-07-09T17:30:06 | 2019-09-19T00:08:00 |
HTML
|
UTF-8
|
Scheme
| false | false | 2,227 |
scm
|
r7rs-to-r6rs.scm
|
(import (scheme base) (scheme file) (scheme read) (scheme write) (srfi 1))
(cond-expand (chibi (import (chibi show) (chibi show pretty)))
(else))
(define substitutions
'((= . fx=?) (< . fx<?) (<= . fx<=?) (> . fx>?) (>= . fx>=?)
(+ . fx+) (- . fx-) (modulo . fxmod) (exact-integer? . fixnum?)
(open-binary-input-file . open-file-input-port)
(open-input-string . open-string-input-port)
(read-u8 . get-u8)))
(define (substitute form)
(if (pair? form)
(cons (substitute (car form))
(substitute (cdr form)))
(let ((sub (assoc form substitutions)))
(if sub (cdr sub) form))))
(define (displayln x)
(display x)
(newline))
(define (pretty-print form)
(cond-expand
(chibi (show (current-output-port) (pretty form)))
(else (write form) (newline))))
(define (read-all port)
(let loop ((forms '()))
(let ((form (read port)))
(if (eof-object? form) forms (loop (append forms (list form)))))))
(define (r7rs->r6rs filename)
(substitute
(remove (lambda (form) (eqv? 'import (car form)))
(call-with-input-file filename read-all))))
(define (write-r6rs-file filename . forms)
(with-output-to-file filename
(lambda ()
(displayln "#!r6rs")
(displayln ";; Automatically generated")
(displayln ";; Copyright 2019 Lassi Kortela")
(displayln ";; SPDX-License-Identifier: MIT")
(for-each (lambda (form) (pretty-print form)) forms))))
(define (write-r6rs-library filename libname exports body)
(write-r6rs-file
filename `(library ,libname (export ,@exports) (import (rnrs)) ,@body)))
(define (translate-source-file r7rs-filename r6rs-filename)
(apply write-r6rs-file r6rs-filename
(cons '(import (rnrs) (srfi :175))
(r7rs->r6rs r7rs-filename))))
(define (main)
(let* ((lib (call-with-input-file "175.sld" read))
(exports (cdr (assoc 'export (cddr lib))))
(body (r7rs->r6rs "175.scm")))
(write-r6rs-library "175.sls" '(srfi :175) exports body)
(write-r6rs-library "srfi-175.sls" '(srfi srfi-175) exports body) ; Guile
(translate-source-file "examples.scm" "examples.sps")
(translate-source-file "tests.scm" "tests.sps")))
(main)
| false |
1ab6406075e44504e91459a81b56e4b8ba301b91
|
d9cb7af1bdc28925fd749260d5d643925185b084
|
/test/2.60.scm
|
1627d626691555f7bb3f94a82042f873db34d274
|
[] |
no_license
|
akerber47/sicp
|
19e0629df360e40fd2ea9ba34bf7bd92be562c3e
|
9e3d72b3923777e2a66091d4d3f3bfa96f1536e0
|
refs/heads/master
| 2021-07-16T19:36:31.635537 | 2020-07-19T21:10:54 | 2020-07-19T21:10:54 | 14,405,303 | 0 | 0 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 801 |
scm
|
2.60.scm
|
; for =zero?
(include "src/2.59.scm")
(define p
(make-polynomial
'x
(adjoin-term
(make-term 3 4)
(adjoin-term
(make-term 2 10)
(adjoin-term
(make-term 0 6)
(the-empty-termlist))))))
(define q
(make-polynomial
'x
(adjoin-term
(make-term 3 2)
(adjoin-term
(make-term 2 5)
(adjoin-term
(make-term 0 3)
(the-empty-termlist))))))
(define z
(make-polynomial
'x
(adjoin-term
(make-term 3 0)
(adjoin-term
(make-term 2 0)
(adjoin-term
(make-term 0 0)
(the-empty-termlist))))))
(define (run)
(let ()
(assert (equal? (sub p q) q))
(assert (equal? (sub p z) p))
(assert (=zero? (sub p p)))
"All tests passed!"
)
)
| false |
c06effd45700ac8120d139ad6017fc56efe7b15f
|
c799c024264e85ac3ae64e7e1e377f13a700f45e
|
/bin/turing.scm
|
92892252d625dc197e1a0047ab1dc94ba72b9ce4
|
[] |
no_license
|
kzfm1024/misc
|
ba6841d3c25f09b0ebec00586d1603b9936b5101
|
643a66921cac122ee6384ebe855e1d2874e63208
|
refs/heads/master
| 2021-07-16T12:14:42.444431 | 2020-05-24T12:43:55 | 2020-05-24T12:43:55 | 924,345 | 0 | 0 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 333 |
scm
|
turing.scm
|
(use util.stream)
(define (divisible? x y) (= (remainder x y) 0))
(define (sieve stream)
(stream-cons
(stream-car stream)
(sieve (stream-filter
(lambda (x)
(not (divisible? x (stream-car stream))))
(stream-cdr stream)))))
(define primes (sieve (stream-iota -1 2 1)))
(stream->list (stream-take primes 100))
| false |
5c6bd6c1cfff8d4e8b1b04a9d7d801e02af0f8b7
|
a8216d80b80e4cb429086f0f9ac62f91e09498d3
|
/lib/srfi/69/test.sld
|
f7afe46a7a09e10a500959f5b06db897ce2018b8
|
[
"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 | 7,955 |
sld
|
test.sld
|
(define-library (srfi 69 test)
(export run-tests)
(import (chibi) (srfi 1) (srfi 69) (chibi test))
(begin
(define (run-tests)
(define-syntax test-lset-eq?
(syntax-rules ()
((test-lset= . args)
(test-equal (lambda (a b) (lset= eq? a b)) . args))))
(define-syntax test-lset-equal?
(syntax-rules ()
((test-lset-equal? . args)
(test-equal (lambda (a b) (lset= equal? a b)) . args))))
(test-begin "srfi-69: hash-tables")
(let ((ht (make-hash-table eq?)))
;; 3 initial elements
(test 0 (hash-table-size ht))
(hash-table-set! ht 'cat 'black)
(hash-table-set! ht 'dog 'white)
(hash-table-set! ht 'elephant 'pink)
(test 3 (hash-table-size ht))
(test-assert (hash-table-exists? ht 'dog))
(test-assert (hash-table-exists? ht 'cat))
(test-assert (hash-table-exists? ht 'elephant))
(test-not (hash-table-exists? ht 'goose))
(test 'white (hash-table-ref ht 'dog))
(test 'black (hash-table-ref ht 'cat))
(test 'pink (hash-table-ref ht 'elephant))
(test-error (hash-table-ref ht 'goose))
(test 'grey (hash-table-ref ht 'goose (lambda () 'grey)))
(test 'grey (hash-table-ref/default ht 'goose 'grey))
(test-lset-eq? '(cat dog elephant) (hash-table-keys ht))
(test-lset-eq? '(black white pink) (hash-table-values ht))
(test-lset-equal? '((cat . black) (dog . white) (elephant . pink))
(hash-table->alist ht))
;; remove an element
(hash-table-delete! ht 'dog)
(test 2 (hash-table-size ht))
(test-not (hash-table-exists? ht 'dog))
(test-assert (hash-table-exists? ht 'cat))
(test-assert (hash-table-exists? ht 'elephant))
(test-error (hash-table-ref ht 'dog))
(test 'black (hash-table-ref ht 'cat))
(test 'pink (hash-table-ref ht 'elephant))
(test-lset-eq? '(cat elephant) (hash-table-keys ht))
(test-lset-eq? '(black pink) (hash-table-values ht))
(test-lset-equal? '((cat . black) (elephant . pink)) (hash-table->alist ht))
;; remove a non-existing element
(hash-table-delete! ht 'dog)
(test 2 (hash-table-size ht))
(test-not (hash-table-exists? ht 'dog))
;; overwrite an existing element
(hash-table-set! ht 'cat 'calico)
(test 2 (hash-table-size ht))
(test-not (hash-table-exists? ht 'dog))
(test-assert (hash-table-exists? ht 'cat))
(test-assert (hash-table-exists? ht 'elephant))
(test-error (hash-table-ref ht 'dog))
(test 'calico (hash-table-ref ht 'cat))
(test 'pink (hash-table-ref ht 'elephant))
(test-lset-eq? '(cat elephant) (hash-table-keys ht))
(test-lset-eq? '(calico pink) (hash-table-values ht))
(test-lset-equal? '((cat . calico) (elephant . pink)) (hash-table->alist ht))
;; walk and fold
(test-lset-equal?
'((cat . calico) (elephant . pink))
(let ((a '()))
(hash-table-walk ht (lambda (k v) (set! a (cons (cons k v) a))))
a))
(test-lset-equal? '((cat . calico) (elephant . pink))
(hash-table-fold ht (lambda (k v a) (cons (cons k v) a)) '()))
;; copy
(let ((ht2 (hash-table-copy ht)))
(test 2 (hash-table-size ht2))
(test-not (hash-table-exists? ht2 'dog))
(test-assert (hash-table-exists? ht2 'cat))
(test-assert (hash-table-exists? ht2 'elephant))
(test-error (hash-table-ref ht2 'dog))
(test 'calico (hash-table-ref ht2 'cat))
(test 'pink (hash-table-ref ht2 'elephant))
(test-lset-eq? '(cat elephant) (hash-table-keys ht2))
(test-lset-eq? '(calico pink) (hash-table-values ht2))
(test-lset-equal? '((cat . calico) (elephant . pink))
(hash-table->alist ht2)))
;; merge
(let ((ht2 (make-hash-table eq?)))
(hash-table-set! ht2 'bear 'brown)
(test 1 (hash-table-size ht2))
(test-not (hash-table-exists? ht2 'dog))
(test-assert (hash-table-exists? ht2 'bear))
(hash-table-merge! ht2 ht)
(test 3 (hash-table-size ht2))
(test-assert (hash-table-exists? ht2 'bear))
(test-assert (hash-table-exists? ht2 'cat))
(test-assert (hash-table-exists? ht2 'elephant))
(test-not (hash-table-exists? ht2 'goose))
(test 'brown (hash-table-ref ht2 'bear))
(test 'calico (hash-table-ref ht2 'cat))
(test 'pink (hash-table-ref ht2 'elephant))
(test-error (hash-table-ref ht2 'goose))
(test 'grey (hash-table-ref/default ht2 'goose 'grey))
(test-lset-eq? '(bear cat elephant) (hash-table-keys ht2))
(test-lset-eq? '(brown calico pink) (hash-table-values ht2))
(test-lset-equal? '((cat . calico) (bear . brown) (elephant . pink))
(hash-table->alist ht2)))
;; alist->hash-table
(test-lset-equal? (hash-table->alist ht)
(hash-table->alist
(alist->hash-table
'((cat . calico) (elephant . pink))))))
;; update
(let ((ht (make-hash-table eq?))
(add1 (lambda (x) (+ x 1))))
(hash-table-set! ht 'sheep 0)
(hash-table-update! ht 'sheep add1)
(hash-table-update! ht 'sheep add1)
(test 2 (hash-table-ref ht 'sheep))
(hash-table-update!/default ht 'crows add1 0)
(hash-table-update!/default ht 'crows add1 0)
(hash-table-update!/default ht 'crows add1 0)
(test 3 (hash-table-ref ht 'crows)))
;; string keys
(let ((ht (make-hash-table equal?)))
(hash-table-set! ht "cat" 'black)
(hash-table-set! ht "dog" 'white)
(hash-table-set! ht "elephant" 'pink)
(hash-table-ref/default ht "dog" #f)
(test 'white (hash-table-ref ht "dog"))
(test 'black (hash-table-ref ht "cat"))
(test 'pink (hash-table-ref ht "elephant"))
(test-error (hash-table-ref ht "goose"))
(test 'grey (hash-table-ref/default ht "goose" 'grey))
(test-lset-equal? '("cat" "dog" "elephant") (hash-table-keys ht))
(test-lset-equal? '(black white pink) (hash-table-values ht))
(test-lset-equal?
'(("cat" . black) ("dog" . white) ("elephant" . pink))
(hash-table->alist ht)))
;; string-ci keys
(let ((ht (make-hash-table string-ci=? string-ci-hash)))
(hash-table-set! ht "cat" 'black)
(hash-table-set! ht "dog" 'white)
(hash-table-set! ht "elephant" 'pink)
(hash-table-ref/default ht "DOG" #f)
(test 'white (hash-table-ref ht "DOG"))
(test 'black (hash-table-ref ht "Cat"))
(test 'pink (hash-table-ref ht "eLePhAnT"))
(test-error (hash-table-ref ht "goose"))
(test-lset-equal? '("cat" "dog" "elephant") (hash-table-keys ht))
(test-lset-equal? '(black white pink) (hash-table-values ht))
(test-lset-equal?
'(("cat" . black) ("dog" . white) ("elephant" . pink))
(hash-table->alist ht)))
;; Exception values - this works because the return value from the
;; primitives is a cell, and we use the cdr opcode to retrieve the
;; cell value. Thus there is no FFI issue with storing exceptions.
(let ((ht (make-hash-table)))
(hash-table-set! ht 'boom (make-exception 'my-exn-type "boom!" '() #f #f))
(test 'my-exn-type (exception-kind (hash-table-ref ht 'boom))))
;; stress test
(test 625
(let ((ht (make-hash-table)))
(do ((i 0 (+ i 1))) ((= i 1000))
(hash-table-set! ht i (* i i)))
(hash-table-ref/default ht 25 #f)))
(test-end))))
| true |
efd78dd0a20986600b03df86bc56f47ebf3dee78
|
1384f71796ddb9d11c34c6d988c09a442b2fc8b2
|
/scheme/documentation/module/constants.scm
|
1795bd1cbc30954b983b7d626b0607ef56a86cda
|
[] |
no_license
|
ft/xmms2-guile
|
94c2479eec427a370603425fc9e757611a796254
|
29670e586bf440c20366478462f425d5252b953c
|
refs/heads/master
| 2021-07-08T07:58:15.066996 | 2020-10-12T01:24:04 | 2020-10-12T01:24:04 | 74,858,831 | 1 | 2 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 7,031 |
scm
|
constants.scm
|
;; Copyright (c) 2017 xmms2-guile workers, All rights reserved.
;;
;; Terms for redistribution and use can be found in doc/LICENCE.
;; TODO: There is a lot of redundancy in here, that should be removed.
(define-module (documentation module constants)
#:use-module (ice-9 format)
#:use-module (srfi srfi-1)
#:use-module (genipc utilities)
#:use-module (xmms2 types)
#:export (expand-constants-integer
expand-constants-xref
expand-constants-xref-meta))
(define (expand-constants-integer mod name value)
(list name 'integer
(cond ((symbol-prefix? 'CMD- name)
(format #f "Identifier for the ‘~a’ command of the ‘~a’ object."
(substring (string-downcase (symbol->string name)) 4)
(last mod)))
(else 'undocumented))))
(define (xref-example name key value)
(cat (format #f " (assq-ref ~a ~d)~%" name key)
(format #f " → ~a~%" value)))
(define (xref-cmd-docstring name object key value)
(cat (format #f "This is a cross-reference list for command IDs of the ")
(format #f "‘~a’ object. This allows users to decode numeric " object)
(format #f "values to symbols. For example:~%~%")
(xref-example name key value)))
(define (xref-action-docstring name object action key value)
(cat (format #f "This is a cross-reference list for ‘~a’ action IDs within "
action)
(format #f "the ‘~a’ object. This allows users to decode numeric " object)
(format #f "values to symbols. For example:~%~%")
(xref-example name key value)))
(define (xref-mode-docstring name object mode key value)
(cat (format #f "This is a cross-reference list for ‘~a’ mode IDs within "
mode)
(format #f "the ‘~a’ object. This allows users to decode numeric " object)
(format #f "values to symbols. For example:~%~%")
(xref-example name key value)))
(define (xref-policy-docstring name object policy key value)
(cat (format #f "This is a cross-reference list for ‘~a’ policy IDs within "
policy)
(format #f "the ‘~a’ object. This allows users to decode numeric " object)
(format #f "values to symbols. For example:~%~%")
(xref-example name key value)))
(define (xref-types-docstring name object key value)
(cat (format #f "This is a cross-reference list for type IDs of the ")
(format #f "‘~a’ object. This allows users to decode numeric " object)
(format #f "values to symbols. For example:~%~%")
(xref-example name key value)))
(define (xref-statuses-docstring name object key value)
(cat (format #f "This is a cross-reference list for status IDs of the ")
(format #f "‘~a’ object. This allows users to decode numeric " object)
(format #f "values to symbols. For example:~%~%")
(xref-example name key value)))
(define (expand-constants-xref mod name value)
(list name 'xref-list
(cond ((and (symbol-prefix? 'xref- name)
(symbol-suffix? '-cmds name))
(let* ((str (symbol->string name))
(object (substring str 5 (- (string-length str) 5))))
(xref-cmd-docstring name object (caar value) (cdar value))))
((and (symbol-prefix? 'xref- name)
(symbol-suffix? '-actions name))
(let* ((str (symbol->string name))
(action (substring str 5 (- (string-length str) 8))))
(xref-action-docstring name (last mod) action
(caar value) (cdar value))))
((and (symbol-prefix? 'xref- name)
(symbol-suffix? '-modes name))
(let* ((str (symbol->string name))
(mode (substring str 5 (- (string-length str) 6))))
(xref-mode-docstring name (last mod) mode
(caar value) (cdar value))))
((and (symbol-prefix? 'xref- name)
(symbol-suffix? '-policies name))
(let* ((str (symbol->string name))
(policy (substring str 5 (- (string-length str) 9))))
(xref-policy-docstring name (last mod) policy
(caar value) (cdar value))))
((and (symbol-prefix? 'xref- name)
(symbol-suffix? '-types name)
(not (equal? mod '(xmms2 constants))))
(let* ((str (symbol->string name))
(object (substring str 5 (- (string-length str) 6))))
(xref-types-docstring name object (caar value) (cdar value))))
((and (symbol-prefix? 'xref- name)
(symbol-suffix? '-statuses name))
(let* ((str (symbol->string name))
(object (substring str 5 (- (string-length str) 9))))
(xref-statuses-docstring name object (caar value) (cdar value))))
(else 'undocumented))))
(define (expand-constants-xref-meta mod name value)
(list name 'xref-list
(cond ((eq? name 'xref-broadcasts-and-signals)
(cat "This is a cross-reference list that maps numeric "
"IDs to symbols for IPC broadcasts and signals. "
(format #f "For example:~%~%")
(xref-example name (caar value) (cdar value))))
((eq? name 'xref-ipc-command-signals)
(cat "This is a cross-reference list that maps numeric "
"IDs to symbols for IPC command signals. "
(format #f "For example:~%~%")
(xref-example name (caar value) (cdar value))))
((eq? name 'xref-ipc-command-specials)
(cat "This is a cross-reference list that maps numeric "
"IDs to symbols for IPC command specials. "
(format #f "For example:~%~%")
(xref-example name (caar value) (cdar value))))
((eq? name 'xref-log-levels)
(cat "This is a cross-reference list that maps numeric "
"IDs to symbols for logging levels. "
(format #f "For example:~%~%")
(xref-example name (caar value) (cdar value))))
((eq? name 'xref-objects)
(cat "This is a cross-reference list that maps numeric "
"IDs to symbols for the XMMS2 server's objects. "
(format #f "For example:~%~%")
(xref-example name (caar value) (cdar value))))
((eq? name 'xref-plugin-types)
(cat "This is a cross-reference list that maps numeric "
"IDs to symbols for plugin-types. "
(format #f "For example:~%~%")
(xref-example name (caar value) (cdar value))))
(else 'undocumented))))
| false |
a0990fada15e5d66b522c314177f35b27eecfdb1
|
12fc725f8273ebfd9ece9ec19af748036823f495
|
/tools/schemelib/konffaile/writer.ss
|
2db84f6d8938dfe713117edcda21eb64fe2121e4
|
[] |
no_license
|
contextlogger/contextlogger2
|
538e80c120f206553c4c88c5fc51546ae848785e
|
8af400c3da088f25fd1420dd63889aff5feb1102
|
refs/heads/master
| 2020-05-05T05:03:47.896638 | 2011-10-05T23:50:14 | 2011-10-05T23:50:14 | 1,675,623 | 1 | 0 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 9,726 |
ss
|
writer.ss
|
#lang scheme
(require common/usual-4)
(require "class-attr.ss")
(require "component.ss")
(require "variant.ss") ;; some data types
;; --------------------------------------------------
;; generic utilities
;; --------------------------------------------------
(define-syntax on-fail
(syntax-rules ()
((_ fail-expr expr)
(with-handlers
((exn:fail?
(lambda (e) fail-expr)))
expr))))
(define (file-read file)
(call-with-input-file*
file
(lambda (in)
(port->string in))))
;; Checks whether a file either does not exist or has been changed.
(define (file-changed? file s)
;; Would there be a good way to write a function for comparing two
;; input streams? Then we could handle large files as well. ((nin
;; (open-input-string s))) and then compare to file input.
(on-fail #t (not (equal? (file-read file) s))))
;;(write-nl (file-changed? configure-script (file-read configure-script)))
(define* (write-changed-file file s)
(when (file-changed? file s)
(call-with-output-file*
file
(lambda (out)
(display s out))
#:exists 'truncate/replace)
(display-nl file)))
(define (capture-output f)
(let ((output (open-output-string)))
(parameterize ((current-output-port output))
(f))
(get-output-string output)))
(define-syntax* capture
(syntax-rules ()
((_ body ...)
(capture-output (lambda () body ...)))))
(define* (space-join l)
(string-join l " "))
(define (for-each-sep elemact sepact lst)
(define first #t)
(for-each
(lambda (elem)
(if first
(set! first #f)
(when sepact (sepact)))
(when elemact (elemact elem)))
lst))
;; --------------------------------------------------
;; local utilities
;; --------------------------------------------------
(define (disp . args)
(display (apply format args)))
(define (disp-nl . args)
(apply disp args) (newline))
;; --------------------------------------------------
;; pretty printing
;; --------------------------------------------------
(define* (display-generated-notice pfx)
(display pfx)
(display-nl " generated -- do not edit"))
(define* (write-scheme-symlink file target)
(write-changed-file
file
(capture
(display-generated-notice ";;")
(display-nl "#lang scheme")
(disp-nl "(require ~s)" target)
(disp-nl "(provide (all-from-out ~s))" target))))
(define path-censor-re #rx"[-.]")
(define* (path-h-ifdefy p)
(string-append
"__"
(string-downcase
(regexp-replace* path-censor-re (path->string (path-basename p)) "_"))
"__"))
(define ident-censor-re #rx"[-]")
(define* (name-to-c sym)
(string->symbol
(string-append
"__"
(string-upcase
(regexp-replace* ident-censor-re (symbol->string sym) "_"))
"__")))
(define* (name-to-ruby sym)
(string->symbol
(string-append
"$"
(string-upcase
(regexp-replace* ident-censor-re (symbol->string sym) "_"))
)))
(define* (name-to-gmake sym)
(string->symbol
(string-append
(string-upcase
(regexp-replace* ident-censor-re (symbol->string sym) "_"))
)))
(define* (name-to-gmake/negate sym)
(string->symbol
(string-append
"NOT__"
(string-upcase
(regexp-replace* ident-censor-re (symbol->string sym) "_"))
)))
(define (bool-attr? attr)
(boolean? (second attr)))
;; Returns a list of symbols.
(define (bool-attrs-to-gmake-list attrs)
(map
(lambda (entry)
(let ((name (first entry))
(value (second entry)))
((if value name-to-gmake name-to-gmake/negate) name)))
(filter bool-attr? attrs)))
(define* (display/c value)
(cond
((or (attr-defined? value) (eqv? value #t))
(display "1"))
((eqv? value #f)
(display "0"))
((number? value)
(write value))
((hexnum? value)
(display (format "0x~a" (number->string (hexnum-num value) 16))))
((string? value)
(write value))
((symbol? value)
(display/c (symbol->string value)))
((list? value)
(begin
(display "{")
(for-each-sep display/c (thunk (display ", ")) value)
(display "}")))
(else
(error "cannot display as C" value))
))
(define* (display-attr/c name value)
(cond
((attr-undefined? value)
(void))
(else
(begin
(disp "#define ~a " (name-to-c name))
(display/c value)
(newline)))
))
(define* (display/ruby value)
(cond
((or (attr-defined? value) (eqv? value #t))
(display "true"))
((eqv? value #f)
(display "false"))
((number? value)
(write value))
((hexnum? value)
(disp "0x~a" (number->string (hexnum-num value) 16)))
((string? value)
(write value))
((symbol? value)
(display/ruby (symbol->string value)))
((list? value)
(begin
(display "[")
(for-each-sep display/c (thunk (display ", ")) value)
(display "]")))
(else
(error "cannot display as Ruby" value))
))
(define* (display-attr/ruby name value)
(cond
((attr-undefined? value)
(void))
(else
(begin
(display (name-to-ruby name))
(display " = ")
(display/ruby value)
(newline)))
))
(define* (display/gmake value)
(cond
((or (attr-defined? value) (eqv? value #t))
(display "true"))
((number? value)
(write value))
((string? value)
(display value))
((symbol? value)
(display/gmake (symbol->string value)))
((list? value)
(for-each-sep display/gmake (thunk (display " ")) value))
(else
(error "cannot display as GNU Make" value))
))
(define* (display-attr/gmake name value)
(set! name (name-to-gmake name))
(cond
((attr-undefined? value)
(void))
((eqv? value #t)
(begin (disp-nl "~a := true" name)
(disp-nl "NOT__~a :=" name)))
((eqv? value #f)
(begin (disp-nl "~a :=" name)
(disp-nl "NOT__~a := true" name)))
((hexnum? value)
(begin
(disp-nl "~a__DEC := ~s" name (hexnum-num value))
(disp-nl "~a__HEX := ~a"
name (number->string (hexnum-num value) 16))))
(else
(begin
(display name)
(display " := ")
(display/gmake value)
(newline)))
))
(define* (display-attr/qmake name value)
(set! name (name-to-gmake name))
(cond
((attr-undefined? value)
(void))
((eqv? value #t)
(begin (disp-nl "~a = true" name)
(disp-nl "NOT__~a =" name)))
((eqv? value #f)
(begin (disp-nl "~a =" name)
(disp-nl "NOT__~a = true" name)))
((hexnum? value)
(begin
(disp-nl "~a__DEC = ~s" name (hexnum-num value))
(disp-nl "~a__HEX = ~a"
name (number->string (hexnum-num value) 16))))
(else
(begin
(display name)
(display " = ")
(display/gmake value)
(newline)))
))
(define* (write-c-file file attrs)
(let ((harness-name (path-h-ifdefy file)))
(write-changed-file
file
(capture
(display-generated-notice "//")
(disp-nl "#ifndef ~a" harness-name)
(disp-nl "#define ~a" harness-name)
(for-each
(lambda (entry)
(let ((name (first entry))
(value (second entry)))
(display-attr/c name value)
))
attrs)
(disp-nl "#endif // ~a" harness-name)
))))
(define* (write-ruby-file file attrs)
(begin
(write-changed-file
file
(capture
(display-generated-notice "#")
(for-each
(lambda (entry)
(let ((name (first entry))
(value (second entry)))
(display-attr/ruby name value)
))
attrs)
))))
(define* (write-gmake-file file attrs)
(begin
(write-changed-file
file
(capture
(display-generated-notice "#")
(for-each
(lambda (entry)
(let ((name (first entry))
(value (second entry)))
(display-attr/gmake name value)
))
attrs)
))))
(define* (write-qmake-file file attrs)
(begin
(write-changed-file
file
(capture
(display-generated-notice "#")
(for-each
(lambda (entry)
(let ((name (first entry))
(value (second entry)))
(display-attr/qmake name value)
))
attrs)
;; For convenience, we add all boolean variables (or their
;; negations) to the CONFIG variable with the += operator.
(begin
(display "CONFIG += ")
(for-each-sep display (thunk (display " "))
(bool-attrs-to-gmake-list attrs))
(newline))
))))
#|
Copyright 2009 Helsinki Institute for Information Technology (HIIT)
and the authors. All rights reserved.
Authors: Tero Hasu <[email protected]>
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation files
(the "Software"), to deal in the Software without restriction,
including without limitation the rights to use, copy, modify, merge,
publish, distribute, sublicense, and/or sell copies of the Software,
and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
|#
| true |
afb1704f97001e23b6c785e82eeec44839af1411
|
26aaec3506b19559a353c3d316eb68f32f29458e
|
/apps/DemoSensors/main.scm
|
62949692b10c5ec41c7257862f2dca981c8e0384
|
[
"BSD-3-Clause"
] |
permissive
|
mdtsandman/lambdanative
|
f5dc42372bc8a37e4229556b55c9b605287270cd
|
584739cb50e7f1c944cb5253966c6d02cd718736
|
refs/heads/master
| 2022-12-18T06:24:29.877728 | 2020-09-20T18:47:22 | 2020-09-20T18:47:22 | 295,607,831 | 1 | 0 |
NOASSERTION
| 2020-09-15T03:48:04 | 2020-09-15T03:48:03 | null |
UTF-8
|
Scheme
| false | false | 4,154 |
scm
|
main.scm
|
#|
LambdaNative - a cross-platform Scheme framework
Copyright (c) 2009-2013, University of British Columbia
All rights reserved.
Redistribution and use in source and binary forms, with or
without modification, are permitted provided that the
following conditions are met:
* Redistributions of source code must retain the above
copyright notice, this list of conditions and the following
disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials
provided with the distribution.
* Neither the name of the University of British Columbia nor
the names of its contributors may be used to endorse or
promote products derived from this software without specific
prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 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.
|#
;; Primitive sensor demonstrator for android and ios devices
(define gui #f)
(define xyzlabel #f)
(define gyrolabel #f)
(define gpslabel #f)
(main
;; initialization
(lambda (w0 h0)
(make-window 320 480)
(glgui-orientation-set! GUI_PORTRAIT)
(set! gui (make-glgui))
(let* ((w (glgui-width-get))
(h (glgui-height-get))
(h2 (/ h 2.))
(w2 (/ w 2.))
(bw 150) (bh 50)
(bx (/ (- w bw) 2.))
(by (/ (- (/ h2 2.) bh) 2.)))
(glgui-image gui 0 (+ h2 (/ h2 2)) w (/ h2 2) artwork.img White)
(let ((wgt (glgui-label gui 0 (+ (/ h 2.) 50 30) w 16 "Accelerometer [X:Y:Z]" ascii_12.fnt White)))
(glgui-widget-set! gui wgt 'align GUI_ALIGNCENTER))
(set! xyzlabel (glgui-label gui 0 (+ (/ h 2.) 50) w 30 "::" ascii_30.fnt White))
(glgui-widget-set! gui xyzlabel 'align GUI_ALIGNCENTER)
(let ((wgt (glgui-label gui 0 (+ (/ h 2.) 0 30) w 16 "Gyroscope [Y:P:R]" ascii_12.fnt White)))
(glgui-widget-set! gui wgt 'align GUI_ALIGNCENTER))
(set! gyrolabel (glgui-label gui 0 (- (/ h 2.) 0.) w 30 ":" ascii_30.fnt White))
(glgui-widget-set! gui gyrolabel 'align GUI_ALIGNCENTER)
(let ((wgt (glgui-label gui 0 (+ (/ h 2.) -50 30) w 16 "GPS [LAT:LNG]" ascii_12.fnt White)))
(glgui-widget-set! gui wgt 'align GUI_ALIGNCENTER))
(set! gpslabel (glgui-label gui 0 (- (/ h 2.) 50 ) w 30 ":" ascii_30.fnt White))
(glgui-widget-set! gui gpslabel 'align GUI_ALIGNCENTER)
(glgui-button gui bx by bw bh exit.img (lambda (x . y) (force-terminate)))
)
)
;; events
(lambda (t x y)
(let ((curx (accel-x)) (cury (accel-y))(curz (accel-z))
(curyaw (gyro-yaw)) (curpitch (gyro-pitch)) (curroll (gyro-roll))
(curlng (gps-longitude)) (curlat (gps-latitude)))
(glgui-widget-set! gui xyzlabel 'label
(string-append (float->choppedstring curx 6) ":"
(float->choppedstring cury 6) ":" (float->choppedstring curz 6)))
(glgui-widget-set! gui gyrolabel 'label
(string-append (float->choppedstring curyaw 6) ":"
(float->choppedstring curpitch 6) ":" (float->choppedstring curroll 6)))
(glgui-widget-set! gui gpslabel 'label
(string-append (float->choppedstring curlat 8) ":"
(float->choppedstring curlng 8)))
(if (= t EVENT_KEYPRESS) (begin
(if (= x EVENT_KEYESCAPE) (terminate))))
(glgui-event gui t x y)))
;; termination
(lambda () #t)
;; suspend
(lambda () (glgui-suspend))
;; resume
(lambda () (glgui-resume))
)
;; eof
| false |
89fc1f0cba239ff24028cac7bfbcbe6c4b9d0b33
|
9998f6f6940dc91a99e0e2acb4bc4e918f49eef0
|
/src/compiler/mzscheme-vm/compile.ss
|
17e2c982150db3bf7090f3e067427534fec18be3
|
[] |
no_license
|
JessamynT/wescheme-compiler2012
|
326d66df382f3d2acbc2bbf70fdc6b6549beb514
|
a8587f9d316b3cb66d8a01bab3cf16f415d039e5
|
refs/heads/master
| 2020-05-30T07:16:45.185272 | 2016-03-19T07:14:34 | 2016-03-19T07:14:34 | 70,086,162 | 0 | 0 | null | 2016-10-05T18:09:51 | 2016-10-05T18:09:51 | null |
UTF-8
|
Scheme
| false | false | 2,350 |
ss
|
compile.ss
|
#lang scheme/base
(require scheme/contract
"mzscheme-vm.ss"
"collections-module-resolver.ss"
"../pinfo.ss"
(only-in "../helpers.ss" program?)
"../modules.ss"
"../../compile-helpers.ss"
"../../../js-runtime/src/bytecode-compiler.ss"
"../../../js-runtime/src/sexp.ss"
"../../../js-runtime/src/jsexp.ss")
(define default-base-pinfo (pinfo-update-module-resolver
(pinfo-update-allow-redefinition?
(get-base-pinfo 'moby) #f)
(extend-module-resolver-with-collections
default-module-resolver)))
;; compile: input-port output-port name string -> pinfo
(define (compile/port in out
#:name name
#:pinfo (pinfo default-base-pinfo)
#:runtime-version [runtime-version #f])
(let ([stxs (read-syntaxes in #:name name)])
(compile/program stxs out
#:name name
#:pinfo pinfo
#:runtime-version runtime-version)))
;; compile/program: program output-port name string -> pinfo
(define (compile/program a-program out
#:name name
#:pinfo (a-pinfo default-base-pinfo)
#:runtime-version [runtime-version #f])
(let*-values ([(a-compilation-top a-pinfo)
(compile-compilation-top a-program
a-pinfo
#:name name)]
[(a-jsexp)
(cond [runtime-version
(make-cmt (format "runtime-version: ~a" runtime-version)
(compile-top a-compilation-top))]
[else
(compile-top a-compilation-top)])])
(display (jsexp->js a-jsexp)
out)
a-pinfo))
;; port-name: port -> string
(define (port-name a-port)
(format "~s" (object-name a-port)))
(provide/contract
[default-base-pinfo pinfo?]
[compile/port ((input-port? output-port? #:name symbol?) (#:runtime-version string? #:pinfo pinfo?) . ->* . any)]
[compile/program ((program? output-port? #:name symbol?) (#:runtime-version string? #:pinfo pinfo?) . ->* . any)])
| false |
e06595df1b2dcdc9adf713aee9903d8068319609
|
a09ad3e3cf64bc87282dea3902770afac90568a7
|
/4/2.scm
|
810fa0fde21ceb0a81674a75561640d01ed81c47
|
[] |
no_license
|
lockie/sicp-exercises
|
aae07378034505bf2e825c96c56cf8eb2d8a06ae
|
011b37387fddb02e59e05a70fa3946335a0b5b1d
|
refs/heads/master
| 2021-01-01T10:35:59.759525 | 2018-11-30T09:35:35 | 2018-11-30T09:35:35 | 35,365,351 | 0 | 0 | null | null | null | null |
UTF-8
|
Scheme
| false | false | 232 |
scm
|
2.scm
|
#lang sicp
(define (tagged-list? exp tag)
(if (pair? exp)
(eq? (car exp) tag)
false))
(define (application? exp) (tagged-list? exp 'call))
(define (operator exp) (cadr exp))
(define (operands exp) (cddr exp))
| false |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.