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 |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
dd538581b33db6657c8ba23715547ef04518e71b | b62560d3387ed544da2bbe9b011ec5cd6403d440 | /steel-examples/result.scm | dda09a4f812e848001a3619b58504b0fa745346f | [
"LicenseRef-scancode-unknown-license-reference",
"MIT",
"Apache-2.0"
]
| permissive | mattwparas/steel | c6fb91b20c4e613e6a8db9d9310d1e1c72313df2 | 700144a5a1aeb33cbdb2f66440bbe38cf4152458 | refs/heads/master | 2023-09-04T03:41:35.352916 | 2023-09-01T03:26:01 | 2023-09-01T03:26:01 | 241,949,362 | 207 | 10 | Apache-2.0 | 2023-09-06T04:31:21 | 2020-02-20T17:39:28 | Rust | UTF-8 | Scheme | false | false | 965 | scm | result.scm | (struct Ok (value))
(struct Err (value))
(define (Result? value)
(or (Ok? value) (Err? value)))
;; Contracts for Result
(define (Result/c ok-pred err-pred)
(make/c (fn (x)
(cond [(Ok? x) (ok-pred (Ok-value x))]
[(Err? x) (err-pred (Err-value x))]
[else #f]))
'Result/c))
(define (map-option option func)
(cond [(Some? option) (Some (func (Some-value option)))]
[(None? option) (None)]))
;; (->/c Ok? any/c)
(define (unwrap-ok result)
(Ok-value result))
;; (->/c Err? any/c)
(define (unwrap-err result)
(Err-value result))
;; (->/c Result? (->/c any/c any/c) Result?)
(define (map-ok result func)
(cond [(Ok? result) (Ok (func (Ok-value result)))]
[(Err? result) result]))
;; (->/c Result? (->/c any/c any/c Result?))
(define (map-err result func)
(cond [(Ok? result) result]
[(Err? result) (Err (func (Err-value result)))]))
| false |
0dd4bc9d5dff9d9578a5214d44420d82c6c5ef31 | ca39b0bad8cf2fb9bc5699720c1ef86a34ab096a | /bench/sum1.scm | c0ed4a69055f10e02f96eed124a15edc490b51d7 | [
"MIT"
]
| permissive | janm31415/skiwi | 9f40c2120f14dd895cd875087ee941ec6a155b2d | 8234d18fd95a971e947f28477b6173c3c7ef30da | refs/heads/master | 2022-09-23T23:52:09.637174 | 2022-08-31T21:34:50 | 2022-08-31T21:34:50 | 252,686,866 | 4 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 714 | scm | sum1.scm | ;;; SUM1 -- One of the Kernighan and Van Wyk benchmarks.
(load "run-benchmark.scm")
(define inport #f)
(define (sumport port sum-so-far)
(let ((x (read port)))
(if (eof-object? x)
sum-so-far
(sumport port (+ x sum-so-far)))))
(define (sum port)
(sumport port 0.0))
(define (go)
(set! inport (open-input-file "rn100"))
(let ((result (sum inport)))
(close-input-port inport)
result))
(define (main . args)
(run-benchmark
"sum1"
sum1-iters
(lambda (result)
(display result)
(newline)
(and (>= result 15794.974999999)
(<= result 15794.975000001)))
(lambda () (lambda () (go)))))
| false |
7ea06c75326ec296464931a07818f5548757dc4b | bf1c9803ae38f9aad027fbe4569ccc6f85ba63ab | /chapter_2/2.2.Hierarchical.Data.and.the.Closure.Property/ex_2.35.scm | e52beec973de6d1c9a459d01dc568bfb0c15b4c4 | []
| no_license | mehese/sicp | 7fec8750d3b971dd2383c240798dbed339d0345a | 611b09280ab2f09cceb2479be98ccc5403428c6c | refs/heads/master | 2021-06-12T04:43:27.049197 | 2021-04-04T22:22:47 | 2021-04-04T22:23:12 | 161,924,666 | 0 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 807 | scm | ex_2.35.scm | #lang sicp
(define (accumulate op initial sequence)
(if (null? sequence)
initial
(op (car sequence)
(accumulate op
initial
(cdr sequence)))))
(define (enumerate-tree tree)
(cond ((null? tree) nil)
((not (pair? tree)) (list tree))
(else (append
(enumerate-tree (car tree))
(enumerate-tree (cdr tree))))))
(define (count-leaves t)
(accumulate
+ ; sum everything
0
(map
(lambda (sub-tree) ; pop a 1 out for every leaf
(if (pair? sub-tree)
(count-leaves sub-tree)
1))
t)))
(define x (cons (list 1 2) (list 3 4)))
(count-leaves x)
(count-leaves (list x x))
(count-leaves (list 1
(list 2 (list 3 4) 5)
(list 6 7))) | false |
1c91808826527a94219073b08cbb2e4902da5b5d | ae0d7be8827e8983c926f48a5304c897dc32bbdc | /nekoie/misc/bindows-test/scm2xml.scm | 05ec5c854e2c4ed15959c1898f955dfe5b153de1 | []
| no_license | ayamada/copy-of-svn.tir.jp | 96c2176a0295f60928d4911ce3daee0439d0e0f4 | 101cd00d595ee7bb96348df54f49707295e9e263 | refs/heads/master | 2020-04-04T01:03:07.637225 | 2015-05-28T07:00:18 | 2015-05-28T07:00:18 | 1,085,533 | 3 | 2 | null | 2015-05-28T07:00:18 | 2010-11-16T15:56:30 | Scheme | EUC-JP | Scheme | false | false | 1,580 | scm | scm2xml.scm | #!/usr/bin/env gosh
;;; coding: euc-jp
;;; -*- scheme -*-
;;; vim:set ft=scheme ts=8 sts=2 sw=2 et:
;;; $Id$
;;; sxml2xml.scm との違いは、file全体をschemeスクリプトとしてevalしてから、
;;; その一番最後の結果をsxmlのtreeとして扱い、
;;; それをxmlに整形して出力する、という点。
;;; note: evalするschemeスクリプトが出力するsxmlには、
;;; *TOP*や*PI*は含めないようにする事。
;;; これらはsxml2xml.scmが自動的に付加する。
;;; ToDo: encoding指定/変換
;(use gauche.charconv)
(use sxml.ssax)
(use sxml.tools)
(use file.util)
(use text.tree)
;;; ----
(define (usage&exit)
(format (standard-error-port)
"usage: ~a FILENAME\n"
(sys-basename *program-name*))
(sys-exit 2))
(define (write-xml-tree xml-tree)
;; 今のところ、encoding指定は無し
(print "<?xml version=\"1.0\"?>")
(write-tree xml-tree)
(newline))
(define (main args)
(with-error-handler
(lambda (e)
;(report-error e)
(format (standard-error-port) "~a\n" (ref e 'message))
(usage&exit))
(lambda ()
(when (null? (cdr args))
(usage&exit))
(let* ((filename (cadr args))
(sexp-list (file->sexp-list filename))
)
(let loop ((left sexp-list))
(let ((result (eval (car left) (interaction-environment)))
(next (cdr left)))
(if (null? next)
(write-xml-tree
(sxml:sxml->xml result))
(loop next)))))))
0)
| false |
034830dd24b880ce7370951de4558a45b0969ca6 | 26aaec3506b19559a353c3d316eb68f32f29458e | /modules/graph/examples/ex-minimal.scm | d86b235eec6399fa6e9b090bdc3a4610f0fca0f7 | [
"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 | 477 | scm | ex-minimal.scm | ;; Translated from CGraph example by Izumi Ohzawa.
(define g (graph-new 216 216))
(graph-aorigin g 1.5 1.5)
(let loop ((i 0))
(if (<= i 200)
(let* ((angle (* 3.14 i 0.01))
(x (* 1.2 (cos (* 3. angle))))
(y (* 1.2 (sin (* 5. angle)))))
(if (= i 0) (graph-moveto g x y) (graph-lineto g x y))
(loop (+ i 1)))))
(graph-closepathstroke g)
(graph-output g 'GRAPH_PDF "ex-minimal.pdf")
(graph-output g 'GRAPH_SVG "ex-minimal.svg")
;;eof
| false |
ddaeb2b1dfad0c0dd14b5c7a3cc77480950f8e3f | 4b2aeafb5610b008009b9f4037d42c6e98f8ea73 | /5.4/randomize-in-place.scm | 86013c7a7d6c0bae61516b59b5de834e7c2cff00 | []
| 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,391 | scm | randomize-in-place.scm | (define (randomize-in-place urlist)
(let iter ((list urlist))
(if (null? list)
urlist
(let ((swap-with (random-integer (length list))))
(swap-first! list swap-with)
(iter (cdr list))))))
(define (randomize-in-place-marceau urlist)
(if (null? urlist)
urlist
(let ((initial-swap (random-integer (length urlist))))
(swap-first! urlist initial-swap)
(let iter ((list (cdr urlist)))
(if (null? list)
urlist
(randomize-in-place list)))
(values))))
(define (randomize-in-place-kelp urlist)
(let iter ((list urlist))
(if (null? list)
urlist
(if (= (length list) 1)
urlist
(let ((swap-with (+ (random-integer (- (length list) 1)) 1)))
(swap-first! list swap-with)
(iter (cdr list)))))))
(define (randomize-in-place-cyclic urlist)
(let ((length-urlist (length urlist)))
(let ((destination (make-list length-urlist #f))
(offset (random-integer length-urlist)))
(let iter ((list urlist)
(index 0))
(if (null? list)
destination
(let ((destination-ref (modulo (+ index offset) length-urlist)))
(set-car! (drop destination destination-ref)
(car list))
(iter (cdr list) (+ index 1))))))))
| false |
853815e9fad383f00399873b7ba4f8739dcfc4af | 648776d3a0d9a8ca036acaf6f2f7a60dcdb45877 | /queries/awk/highlights.scm | 4faf496e62a18b352f7b774462df92e6dd5a762b | [
"Apache-2.0"
]
| permissive | nvim-treesitter/nvim-treesitter | 4c3c55cbe6ff73debcfaecb9b7a0d42d984be3e6 | f8c2825220bff70919b527ee68fe44e7b1dae4b2 | refs/heads/master | 2023-08-31T20:04:23.790698 | 2023-08-31T09:28:16 | 2023-08-31T18:19:23 | 256,786,531 | 7,890 | 980 | Apache-2.0 | 2023-09-14T18:07:03 | 2020-04-18T15:24:10 | Scheme | UTF-8 | Scheme | false | false | 2,637 | scm | highlights.scm | ; adapted from https://github.com/Beaglefoot/tree-sitter-awk
[
(identifier)
(field_ref)
] @variable
(field_ref (_) @variable)
; https://www.gnu.org/software/gawk/manual/html_node/Auto_002dset.html
((identifier) @constant.builtin
(#any-of? @constant.builtin
"ARGC"
"ARGV"
"ARGIND"
"ENVIRON"
"ERRNO"
"FILENAME"
"FNR"
"NF"
"FUNCTAB"
"NR"
"PROCINFO"
"RLENGTH"
"RSTART"
"RT"
"SYMTAB"))
; https://www.gnu.org/software/gawk/manual/html_node/User_002dmodified.html
((identifier) @variable.builtin
(#any-of? @variable.builtin
"BINMODE"
"CONVFMT"
"FIELDWIDTHS"
"FPAT"
"FS"
"IGNORECASE"
"LINT"
"OFMT"
"OFS"
"ORS"
"PREC"
"ROUNDMODE"
"RS"
"SUBSEP"
"TEXTDOMAIN"))
(number) @number
(string) @string
(regex) @string.regex
(escape_sequence) @string.escape
(comment) @comment @spell
((program . (comment) @preproc)
(#lua-match? @preproc "^#!/"))
(ns_qualified_name (namespace) @namespace)
(ns_qualified_name "::" @punctuation.delimiter)
(func_def name: (_ (identifier) @function) @function)
(func_call name: (_ (identifier) @function) @function)
(func_def (param_list (identifier) @parameter))
[
"print"
"printf"
"getline"
] @function.builtin
[
(delete_statement)
(break_statement)
(continue_statement)
(next_statement)
(nextfile_statement)
] @keyword
[
"func"
"function"
] @keyword.function
[
"return"
"exit"
] @keyword.return
[
"do"
"while"
"for"
"in"
] @repeat
[
"if"
"else"
"switch"
"case"
"default"
] @conditional
[
"@include"
"@load"
] @include
"@namespace" @preproc
[
"BEGIN"
"END"
"BEGINFILE"
"ENDFILE"
] @label
(binary_exp [
"^"
"**"
"*"
"/"
"%"
"+"
"-"
"<"
">"
"<="
">="
"=="
"!="
"~"
"!~"
"in"
"&&"
"||"
] @operator)
(unary_exp [
"!"
"+"
"-"
] @operator)
(assignment_exp [
"="
"+="
"-="
"*="
"/="
"%="
"^="
] @operator)
(ternary_exp [
"?"
":"
] @conditional.ternary)
(update_exp [
"++"
"--"
] @operator)
(redirected_io_statement [
">"
">>"
] @operator)
(piped_io_statement [
"|"
"|&"
] @operator)
(piped_io_exp [
"|"
"|&"
] @operator)
(field_ref "$" @punctuation.delimiter)
(regex "/" @punctuation.delimiter)
(regex_constant "@" @punctuation.delimiter)
[ ";" "," ] @punctuation.delimiter
[
"("
")"
"["
"]"
"{"
"}"
] @punctuation.bracket
| false |
27ded7307fb54acb65551484c179b801c6a06833 | 917429e3eb6bcf2db8c71197f88b979d998b1b7e | /progs/general/kernwyk-cat.scm | b934fb7afc160a491948115ac55a107f1fcb8c22 | []
| no_license | mario-goulart/chicken-benchmarks | 554ca8421631211a891cc497f84dfe62b8f9c8e5 | ea00fe51ec33496de7c9b07fa0ec481fe59989fa | refs/heads/master | 2021-11-20T21:40:55.198252 | 2021-10-09T18:52:48 | 2021-10-09T18:52:48 | 4,427,587 | 1 | 5 | null | 2019-01-27T07:59:38 | 2012-05-24T01:59:23 | Scheme | UTF-8 | Scheme | false | false | 707 | scm | kernwyk-cat.scm | ;;; CAT -- One of the Kernighan and Van Wyk benchmarks.
;;; http://cm.bell-labs.com/cm/cs/who/bwk/interps/pap.html
;;; Rewritten by Will Clinger into more idiomatic Scheme.
(cond-expand (chicken-5 (import (chicken file)))
(else))
(define (catport in out)
(let ((x (read-char in)))
(if (not (eof-object? x))
(begin
(write-char x out)
(catport in out)))))
(define (go input-file output-file)
(if (file-exists? output-file)
(delete-file output-file))
(call-with-input-file
input-file
(lambda (in)
(call-with-output-file
output-file
(lambda (out)
(catport in out))))))
(time (go "inputs/fp-numbers.data" "fp-numbers.data.out"))
| false |
f995d67ec6517d636d513f58c41adadc2c992b9b | 75efeba493b8ddf9b3d084962d7d9edf492a26cd | /test/signal.scm | f6782886c936593c8a4d3d07403e1efb7f09eeb7 | []
| no_license | wehu/nao | 63566553ce01fd7668b85cb04fbff2d01d894a99 | ca6b0c76719e533e5a2a9561ee77e54fd7dc662a | refs/heads/master | 2021-04-26T07:29:01.015941 | 2012-11-07T02:39:24 | 2012-11-07T02:39:24 | 6,457,247 | 0 | 1 | null | null | null | null | UTF-8 | Scheme | false | false | 128 | scm | signal.scm | (import nao)
(define s (make-sig "s"))
(always@ (s)
(info (<! s)))
(initial
(!> s "123")
(nexttick
(!> s "456")))
| false |
198d956ed16e1f40931f213f8a650acbd793b8a1 | bef204d0a01f4f918333ce8f55a9e8c369c26811 | /src/tspl-7-Input-and-Output/7.2-OpeningFiles.ss | 419fd2ed1a85be8b4b4742ad87eb0170c13c5519 | [
"MIT"
]
| permissive | ZRiemann/ChezSchemeNote | 56afb20d9ba2dd5d5efb5bfe40410a5f7bb4e053 | 70b3dca5d084b5da8c7457033f1f0525fa6d41d0 | refs/heads/master | 2022-11-25T17:27:23.299427 | 2022-11-15T07:32:34 | 2022-11-15T07:32:34 | 118,701,405 | 5 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 326 | ss | 7.2-OpeningFiles.ss | #!/usr/bin/scheme --script
(display "
================================================================================
Section 7.2.OpeningFiles
")
(buffer-mode? 'block) ;; #t
(buffer-mode? 'line) ;; #t
(buffer-mode? 'none) ;; #t
(buffer-mode? 'something-else) ;; #f
(define buffer-mode-universe-list
(enum-set->list
))
| false |
f129b199245354c0bc0cf0495802308ac1999a0a | 6ac5c268b4d11421993d6ee22325643219eebf98 | /Example--Assn/Test Files/After Generating Tests/test.0/in/2/options.ss | 7c0edc2b9e922d37f861be17daefd09ca65256c0 | []
| no_license | trsong/AutotestGenerator | ee5f1f1a55a481dac3ffd8a0c637b8c81466598e | 7fb6566de32455e8f773c0e4262595bffca20906 | refs/heads/master | 2021-01-11T10:50:06.170051 | 2016-12-11T14:34:08 | 2016-12-11T14:34:08 | 76,160,341 | 0 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 23 | ss | options.ss |
(loadcode "sum2.rkt" ) | false |
1aa4a408700c6a7dc9e22a92a17dbf941d6702df | bdcc255b5af12d070214fb288112c48bf343c7f6 | /scheme/load.sls | 1ef02ac515c388515b526e1df3963c084001f595 | []
| no_license | xaengceilbiths/chez-lib | 089af4ab1d7580ed86fc224af137f24d91d81fa4 | b7c825f18b9ada589ce52bf5b5c7c42ac7009872 | refs/heads/master | 2021-08-14T10:36:51.315630 | 2017-11-15T11:43:57 | 2017-11-15T11:43:57 | 109,713,952 | 5 | 1 | null | null | null | null | UTF-8 | Scheme | false | false | 94 | sls | load.sls | #!chezscheme
(library (scheme load)
(export load)
(import (r7b-impl load)))
| false |
75bb6db7b6772ee3206d90ec1831a6494005a486 | db0f911e83225f45e0bbc50fba9b2182f447ee09 | /the-scheme-programming-language/3.1-syntactic-extension/examples/or.scm | fdcb72daaec98f8391d9626e2bbb2f03dd4cb1fa | []
| no_license | ZhengHe-MD/learn-scheme | 258941950302b4a55a1d5d04ca4e6090a9539a7b | 761ad13e6ee4f880f3cd9c6183ab088ede1aed9d | refs/heads/master | 2021-01-20T00:02:38.410640 | 2017-05-03T09:48:18 | 2017-05-03T09:48:18 | 89,069,898 | 0 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 145 | scm | or.scm | (define-syntax or
(syntax-rules ()
[(_) #f]
[(_ e) e]
[(_ e1 e2 e3 ...)
(let ([t e1])
(if t t (or e2 e3 ...)))]))
| true |
fab9e38a371397c34f32da23f302687c8c7136b9 | 012bec538a3ff0d3c331ba0b62e8b4bfe592d981 | /life.ss | f2cabb25f2d2294c1ce8c6b097a1ba50e63e7ba8 | []
| no_license | nymacro/chez-scheme-fun | 852d3b7f56a6fb411db5644952b97906bfbbd429 | 46c1f6a05617d006485ab5f9ebeb6001afab2702 | refs/heads/master | 2020-05-02T05:37:07.630163 | 2020-03-07T23:46:10 | 2020-03-07T23:46:10 | 177,775,692 | 0 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 13,872 | ss | life.ss | #!/usr/bin/env scheme
;;;; Game of Life
;;;;
;;;; Notes:
;;;; * Requires Chez Scheme 9.5.3+ for foreign pass-by-struct.
;;;; * Uses modified Thunderchez SDL2 FFI bindings to use pass-by-struct
;;;; rather than similarly sized integer types. Doing so removes the
;;;; need for any pointer-deref shims.
(library-directories "~/thunderchez")
(import (sdl2))
(import (sdl2 image))
(import (chezscheme))
(sdl-library-init)
(sdl-image-library-init)
;;;; helpers
(define (make-interval interval init-time action)
(let ((last-time init-time))
(lambda (current-time)
(when (fx> current-time (fx+ last-time interval))
(action)
(set! last-time (fx+ last-time interval))))))
(define displayln
(case-lambda
((str port)
(display str port)(newline port))
((str)
(display str)(newline))))
(define-syntax for
(syntax-rules ()
((for (var init end) stmt ...)
(let ((var init))
(let loop ()
(when (< var end)
(begin
stmt ...)
(set! var (1+ var))
(loop)))))))
;; TODO fix precision of limiting
(define (make-frame-limiter frame-max initial-time)
(let ((last-time initial-time)
(max-delay (fx/ 1000 frame-max)))
(lambda (current-time)
(let* ((since (fx- current-time last-time))
(delay-time (if (fx<= since 1)
0
(fx/ 1000 since))))
(set! last-time current-time)
(min delay-time max-delay)))))
(define (make-frame-counter initial-time)
(let ((next-time (fx+ initial-time 1000))
(fps 0)
(counter 0))
(lambda (current-time)
(set! counter (fx1+ counter))
(when (fx>= current-time next-time)
(set! fps counter)
(set! counter 0)
(set! next-time (fx+ next-time 1000)))
fps)))
(define make-ftype-guardian (make-guardian))
(define (make-ftype-guardian-collect)
(let loop ()
(let ([x (make-ftype-guardian)])
(when x
(display "freeing ")
(display x)(newline)
(foreign-free (ftype-pointer-address x))
(loop)))))
(define-syntax make-ftype
(syntax-rules ()
((_ type)
(let ((ptr (make-ftype-pointer type
(foreign-alloc (ftype-sizeof type)))))
(make-ftype-guardian-collect)
(make-ftype-guardian ptr)
ptr))))
(define-syntax literal-color
(syntax-rules ()
((_ red green blue)
(let ([fptr (make-ftype sdl-color-t)])
(ftype-set! sdl-color-t (r) fptr red)
(ftype-set! sdl-color-t (g) fptr green)
(ftype-set! sdl-color-t (b) fptr blue)
fptr))))
(define color-white (literal-color 255 255 255))
(define color-cyan (literal-color 255 0 255))
(define color-black (literal-color 0 0 0))
(define-syntax make-rect
(syntax-rules ()
((_ x* y* w* h*)
(let ([fptr (make-ftype sdl-rect-t)])
(ftype-set! sdl-rect-t (x) fptr x*)
(ftype-set! sdl-rect-t (y) fptr y*)
(ftype-set! sdl-rect-t (w) fptr w*)
(ftype-set! sdl-rect-t (h) fptr h*)
fptr))))
;; FIXME thread-safety
(define make-temp-rect
(let ([fptr (make-rect 0 0 0 0)])
(lambda (x y w h)
(ftype-set! sdl-rect-t (x) fptr x)
(ftype-set! sdl-rect-t (y) fptr y)
(ftype-set! sdl-rect-t (w) fptr w)
(ftype-set! sdl-rect-t (h) fptr h)
fptr)))
(define (make-temp-surface-rect surface)
(make-temp-rect 0
0
(1- (ftype-ref sdl-surface-t (w) surface))
(1- (ftype-ref sdl-surface-t (h) surface))))
(define (get-surface-rect surface)
(make-rect 0
0
(1- (ftype-ref sdl-surface-t (w) surface))
(1- (ftype-ref sdl-surface-t (h) surface))))
;;;; setup
(define window-width 800)
(define window-height 600)
(define block-width 8)
(define block-height 8)
(define (draw-block x y renderer intensity)
(sdl-set-render-draw-color renderer intensity 0 0 255)
(sdl-render-fill-rect renderer (make-temp-rect x y block-width block-height)))
(define arena-width (fx/ window-width block-width))
(define arena-height (fx/ window-height block-height))
(define (make-arena)
(make-vector (fx* arena-width arena-height) #f))
;; cache of "arenas" to swap between for reuse
(define (make-arena-buffered)
(let ((arenas (list (make-arena) (make-arena)))
(index 0))
(define (next-arena)
(set! index (fxmodulo (fx1+ index) 2))
(list-ref arenas index))
next-arena))
(define get-next-arena (make-arena-buffered))
(define (arena-idx* x y)
(let ((xx (if (fx< x 0)
(fx+ x arena-width)
x))
(yy (if (fx< y 0)
(fx+ y arena-height)
y)))
(fx+ (fx* (fxmodulo yy arena-height) arena-width)
(fxmodulo xx arena-width))))
(define-syntax life-alive-p
(syntax-rules ()
((_ x)
(fx= x 255))))
(define-syntax life-drain
(syntax-rules ()
((_ x)
(cond
((fx> x 0) (max 0 (fx- x 16)))
(else 0)))))
(define-syntax for-arena
(syntax-rules ()
((for-arena (x y) stmt stmts ...)
(for (y 0 arena-height)
(for (x 0 arena-width)
stmt
stmts ...)))))
(define (arena-ref arena x y)
(vector-ref arena (arena-idx* x y)))
(define (arena-set! arena x y v)
(vector-set! arena (arena-idx* x y) v))
(define (arena-randomize! arena)
(for-arena (x y)
(let* ((random-value (random 2))
(value (if (fx= 0 (modulo random-value 2))
0
255)))
(arena-set! arena x y value))))
(define (arena-clear! arena)
(for-arena (x y)
(arena-set! arena x y #f)))
(define (arena-render arena renderer)
(for-arena (x y)
(draw-block (fx* block-width x) (fx* block-height y) renderer (arena-ref arena x y))))
(define (arena-display arena)
(for (y 0 arena-height)
(for (x 0 arena-width)
(if (arena-ref arena x y)
(display "X")
(display ".")))
(newline)))
;;;; Conway's Game of Life
;;;;
;;;; Events happen simultaneously
;;;; 1. Alive cells with fewer than 2 neighbours die.
;;;; 2. Alive cells with 2-3 neighbours lives.
;;;; 3. Alive cells with greater than 3 neighbours die.
;;;; 4. Dead cells with exacly three live neighbours comes to life.
(define (life-tick-state alive neighbours)
(let ((alivep (life-alive-p alive)))
(cond
((and alivep (< neighbours 2)) (life-drain alive))
((and alivep (> neighbours 3)) (life-drain alive))
((and (not alivep) (= neighbours 3)) 255)
(else
(if (life-alive-p alive)
alive
(life-drain alive))))))
(define (life-tick-inner arena x y)
(let* ((alive (arena-ref arena x y))
(neighbours (arena-surrounds-alive arena x y)))
(life-tick-state alive neighbours)))
(define (life-tick arena)
(let ((new-arena (get-next-arena)))
(for-arena (x y)
(arena-set! new-arena x y (life-tick-inner arena x y)))
new-arena))
(define (life-tick-pause arena)
(let ((new-arena (get-next-arena)))
(for-arena (x y)
(let ((alive (arena-ref arena x y)))
(arena-set! new-arena x y (if (life-alive-p alive)
alive
(life-drain alive)))))
new-arena))
;; return number of alive neighbours for a cell
(define (arena-surrounds-alive arena x y)
(let ((alive 0))
(for (yy 0 3)
(for (xx 0 3)
(let* ((get-x (1- (fx+ x xx)))
(get-y (1- (fx+ y yy)))
(self (and (= get-x x) (= get-y y)))
(alivep (life-alive-p (arena-ref arena get-x get-y))))
(when (and alivep (not self))
(set! alive (1+ alive))))))
alive))
(define (arena-surrounds-display arena x y)
(let ((surrounds (arena-surrounds arena x y)))
(for (y 0 3)
(for (x 0 3)
(if (vector-ref surrounds (fx+ x (fx* y 3)))
(display "X")
(display ".")))
(newline))))
(define arena (get-next-arena))
(arena-randomize! arena)
(let* ((window (sdl-create-window "Game of Life" 0 0 window-width window-height 0))
(fullscreen #f)
(toggle-fullscreen (lambda ()
(set! fullscreen (not fullscreen))
(sdl-set-window-fullscreen window
(if fullscreen
(sdl-window-flags 'fullscreen-desktop)
0))))
(renderer (sdl-create-renderer window -1 (sdl-renderer-flags 'accelerated)))
(event (make-ftype sdl-event-t))
(running #t)
(current-time (sdl-get-ticks))
(frame-limiter (make-frame-limiter 60 current-time))
(frame-counter (make-frame-counter current-time))
(event (make-ftype sdl-event-t))
(frame-rate 0)
(pause #f)
(mtx (make-mutex))
(life-action (lambda ()
(let* ((current-time (sdl-get-ticks))
(life-counter (make-frame-counter current-time))
(life-limiter (make-frame-limiter 60 current-time))
(last-rate 0))
(let loop ()
(let* ((current-time (sdl-get-ticks))
(count (life-counter current-time))
(delay-time (life-limiter current-time)))
(when (not (fx= last-rate count))
(displayln (format "life: ~a" count))
(set! last-rate count))
(sdl-delay delay-time)
(with-mutex mtx
(if pause
(set! arena (life-tick-pause arena))
(set! arena (life-tick arena)))))
(when running
(loop))))))
(life-interval (fork-thread life-action))
(redisplay-interval (make-interval 0 current-time
(lambda ()
(with-mutex mtx
(arena-render arena renderer))
(sdl-render-present renderer))))
(gc-stats-interval (make-interval 5000 current-time
(lambda ()
(display-statistics)))))
(let loop ()
(let* ([current-time (sdl-get-ticks)]
[delay-time (frame-limiter current-time)])
(sdl-delay delay-time)
;; only display FPS on rate change
(let ((new-frame-rate (frame-counter current-time)))
(when (not (fx= frame-rate new-frame-rate))
(displayln (format "fps: ~a" new-frame-rate))
(set! frame-rate new-frame-rate)))
;; run simulation and redraw
(redisplay-interval current-time)
(gc-stats-interval current-time)
(let event-loop ()
(let ((e (sdl-poll-event event)))
(when (> e 0)
(let ((event-type (ftype-ref sdl-event-t (type) event)))
(cond
((fx= event-type (sdl-event-type 'quit))
(set! running #f))
((fx= event-type (sdl-event-type 'mousebuttondown))
(let* ((button-event (ftype-&ref sdl-event-t (button) event))
(button (ftype-ref sdl-mouse-button-event-t (button) button-event))
(x (ftype-ref sdl-mouse-button-event-t (x) button-event))
(y (ftype-ref sdl-mouse-button-event-t (y) button-event))
(block-x (fx/ x block-width))
(block-y (fx/ y block-height)))
(arena-set! arena block-x block-y
(if (life-alive-p (arena-ref arena block-x block-y))
0
255))))
((fx= event-type (sdl-event-type 'keydown))
(let* ((keyboard-event (ftype-&ref sdl-event-t (key) event))
(keysym (ftype-&ref sdl-keyboard-event-t (keysym) keyboard-event))
(key-code (ftype-ref sdl-keysym-t (sym) keysym)))
(cond
((fx= key-code (sdl-keycode 'c))
(with-mutex mtx
(arena-clear! arena)))
((fx= key-code (sdl-keycode 'escape))
(set! running #f))
((fx= key-code (sdl-keycode 'f))
(toggle-fullscreen))
((fx= key-code (sdl-keycode 'return))
(with-mutex mtx
(arena-randomize! arena)))
((fx= key-code (sdl-keycode 'space))
(set! pause (not pause))
(if pause
(displayln "Paused. Press space to unpause.")
(displayln "Unpaused. Press space to pause.")))
(else
(displayln (format "Unhandled keycode: ~a"
(if (< key-code 256)
(begin
(let ((key-char (integer->char key-code)))
(if (or (char-alphabetic? key-char)
(char-numeric? key-char))
key-char
key-code)))
key-code)))))))))
(event-loop))))
(when running (loop))))
(sdl-destroy-window window))
;; (sdl-quit)
(displayln "Goodbye :(")
;(exit)
| true |
c16a8e37472188845840680517b09377132a5c5a | 6bd63be924173b3cf53a903f182e50a1150b60a8 | /chapter_1/1.43.scm | 2908a6dac84be2ce81299ed83df8b5649c4a7ef9 | []
| no_license | lf2013/SICP-answer | d29ee3095f0d018de1d30507e66b12ff890907a5 | 2712b67edc6df8ccef3156f4ef08a2b58dcfdf81 | refs/heads/master | 2020-04-06T13:13:51.086818 | 2019-09-11T11:39:45 | 2019-09-11T11:39:45 | 8,695,137 | 0 | 1 | null | 2016-03-17T13:19:21 | 2013-03-11T02:24:41 | Scheme | UTF-8 | Scheme | false | false | 661 | scm | 1.43.scm | ; 1.43
; whether the count = 1 or connt > 1
; the function should return a callable object
; so when count > 1, we should return a callable object.
; the workflow was call f on the result of previous (count-1) times result.
; another idea about the problem was that:
; parameters for f were numbers
; parameters for repeated were functions
; such a great problem, impress me so much
(define (repeated f count)
(if (= count 1)
(lambda (x) (f x))
(lambda (x) (f ((repeated f (- count 1)) x)))))
(define (square x) (* x x))
(define (inc x) (+ 1 x))
(define (try)
((repeated inc 10) 0))
(define (try2)
((repeated square 2) 5))
| false |
b7c278eefb69899be7c4da0a39e76cde55045ebf | 2fc7c18108fb060ad1f8d31f710bcfdd3abc27dc | /ext/sys-unix/search-path.scm | 1417e52eb277f6ca9908efc2338922aa8396348c | [
"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,009 | scm | search-path.scm | ; Scheme 9 from Empty Space, Unix Function Library
; By Nils M Holm, 2010
; Placed in the Public Domain
;
; (search-path string1 string2) ==> string | #f
;
; Search the Unix search path STRING2 for the executable STRING1. Return
; the full path of the first executable found or #F if not executable
; named STRING1 can be found in the given path.
; STRING2 is a colon-separated list of paths, e.g.:
;
; "/bin:/usr/bin:/usr/local/bin"
;
; SEARCH-PATH uses ACCESS with mode ACCESS-X-OK to check whether a
; file is executable.
;
; (Example): (search-path "vi" "/bin:/usr/bin") ==> "/usr/bin/vi"
(require-extension sys-unix)
(load-from-library "string-split.scm")
(define (search-path file path)
(let loop ((path (string-split #\: path)))
(cond ((null? path)
#f)
((let ((loc (string-append (car path) "/" file)))
(and (sys:access loc sys:access-x-ok)
loc))
=> (lambda (x) x))
(else
(loop (cdr path))))))
| false |
c10a4a5a0f77af6da565b135b99bcd5de9c8f2dd | ea4e27735dd34917b1cf62dc6d8c887059dd95a9 | /section1_2_exercise1_18.scm | ba70e3109995b9f932a5883c8b78d5f0c565f792 | [
"MIT"
]
| permissive | feliposz/sicp-solutions | 1f347d4a8f79fca69ef4d596884d07dc39d5d1ba | 5de85722b2a780e8c83d75bbdc90d654eb094272 | refs/heads/master | 2022-04-26T18:44:32.025903 | 2022-03-12T04:27:25 | 2022-03-12T04:27:25 | 36,837,364 | 1 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 762 | scm | section1_2_exercise1_18.scm | ; linear recusive multiplication
; This is known as the ancient Egyptian method of multiplication!!!
; space / time = O(n)
(define (mult a b)
(if (= b 0)
0
(+ a (* a (- b 1)))))
(mult 3 7)
; ------------------
(define (double x)
(+ x x))
(define (halve x)
(/ x 2))
(define (even? x)
(= (remainder x 2) 0))
(define (fast-mult-i a b)
(fast-mult-iter a b 0))
(define (fast-mult-iter a b x)
(cond ((= b 0) x)
((even? b) (fast-mult-iter (double a) (halve b) x))
(else (fast-mult-iter a (- b 1) (+ x a)))))
(fast-mult-i 10 15)
(fast-mult-i 2 3)
(fast-mult-i 7 7)
(fast-mult-i 0 3)
(fast-mult-i 3 0)
(fast-mult-i 20 30)
; a iterative multiplication method with logarithmic time and constant space
; time = O(log n)
; space = O(1)
| false |
4e7fcf09a270d50580bef243e3673a00850137af | bdeb8973603dd2ce97faaf59164f45fd322234c8 | /exercise-1-5-every-second-element.scm | 5e34d6d13df07091ec2dbed392ba229844ef78ed | []
| no_license | emilbaekdahl/pp-exercises | 782e080c5ab0a96210cec765699f0071a4ab558b | ce9e93d03357f2aec46f648b33d18205529f775d | refs/heads/master | 2020-07-28T00:50:05.001308 | 2019-11-13T21:44:15 | 2019-11-13T21:46:00 | 209,260,169 | 0 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 551 | scm | exercise-1-5-every-second-element.scm | ; Exercise 1.5: Every second element of a list
; Returns a list of every `n`th element in `lst`.
;
; Examples:
; >>> (every-nth-element 3 '(1 2 3 4 5 6))
; >>> '(1 4)
(define (every-nth-element n lst)
(if (null? lst)
'()
(cons (car lst)
(if (< (length (cdr lst)) n)
'()
(every-nth-element n (list-tail lst n))))))
; Returns every second element in `lst`.
;
; Examples:
; >>> (every-nth-element '(1 2 3 4))
; >>> '(1 3)
(define (every-second-element lst)
(every-nth-element 2 lst))
| false |
35b95ad0e8f45be68280d1606b2e31a2a7e3c2fb | 08b21a94e7d29f08ca6452b148fcc873d71e2bae | /src/loki/core/reflect.sld | 2ac723417113dc99822f769adcedf02505752013 | [
"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 | 1,028 | sld | reflect.sld | (define-library (loki core reflect)
(import (scheme base))
(import (srfi 1))
(export is-a? slot-ref)
(cond-expand
(gauche
(import (only (gauche base) is-a?))
(import (rename (gauche base) (slot-ref gauche:slot-ref)
(slot-bound? gauche:slot-bound?)
(slot-set! gauche:slot-set!)))
(begin
(define (slot-ref type value slot)
(let ((slot (if (number? slot)
(list-ref (map slot-definition-name (class-slots type)) slot)
slot)))
(if (gauche:slot-bound? value slot)
(gauche:slot-ref value slot)
#f)))
#;(define (slot-set! type value slot)
(gauche:slot-set! value))))
(loki
(import (loki core records))
(begin
(define (is-a? value type)
(and (record? value)
(eq? (record-type value) type)))
(define (slot-ref type value slot)
(if (number? slot)
(record-ref value (+ slot 1))
((record-accessor type 'slot) value)))))))
| false |
bf37c7af5be630b43628730709a424f5c1aa0c31 | ec5b4a92882f80b3f62eac8cbd059fb1f000cfd9 | /wcp-functional/proplist.ss | 38876ffa502534c0cb8749a0e56c3a83d30862d0 | []
| no_license | ggem/alpa | ee35ffc91d9f4b1d540ce8b2207595813e488e5f | 4f53b888b5a5b4ffebd220c6e0458442325fbff2 | refs/heads/master | 2019-01-02T03:12:17.899768 | 2005-01-04T03:43:12 | 2005-01-04T03:43:12 | 42,612,681 | 0 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 2,896 | ss | proplist.ss | ; File: "proplist.scm" (c) 1991, Marc Feeley
; Generalized 'put' and 'get' in Scheme.
;
; Hash tables are used for efficiency.
(define (make-1d-table . opt)
(make-vector (if (null? opt) 4003 (car opt)) '()))
(define (1d-table-get table index)
(let ((h (hash-object index (vector-length table))))
(assq index (vector-ref table h))))
(define (1d-table-put table index value)
(let ((h (hash-object index (vector-length table))))
(let ((x (assq index (vector-ref table h))))
(if x
(begin
(set-cdr! x value)
x)
(let ((y (cons index value)))
(vector-set! table h (cons y (vector-ref table h)))
y)))))
(define (make-2d-table . opt)
(vector (if (or (null? opt) (null? (cdr opt))) 19 (cadr opt))
(if (null? opt) (make-1d-table) (make-1d-table (car opt)))))
(define (2d-table-get table index1 index2)
(let ((1d-table (vector-ref table 1)))
(let ((x (1d-table-get 1d-table index1)))
(and x (1d-table-get (cdr x) index2)))))
(define (2d-table-put table index1 index2 value)
(let ((table-size (vector-ref table 0))
(1d-table (vector-ref table 1)))
(let ((x (1d-table-get 1d-table index1)))
(if x
(1d-table-put (cdr x) index2 value)
(let ((y (if table-size (make-1d-table table-size) (make-1d-table))))
(1d-table-put 1d-table index1 y)
(1d-table-put y index2 value))))))
(define (hash-object obj n)
(define (hash-symbol sym n)
(hash-string (symbol->string sym) n))
(define (hash-string str n)
(let ((len (string-length str)))
(let loop ((h 0) (i (- len 1)))
(if (>= i 0)
(let ((x (+ (* h 256) (char->integer (string-ref str i)))))
(loop (modulo x n) (- i 1)))
h))))
(define (hash-number num n)
(modulo
(inexact->exact
(floor
(cond ((integer? num) num)
((rational? num) (+ (numerator num) (denominator num)))
((real? num) num)
(else (+ (real-part num) (imag-part num))))))
n))
(define (hash-char chr n)
(modulo (char->integer chr) n))
(define (hash-vector vec n)
(modulo (vector-length vec) n))
(cond ((symbol? obj) (hash-symbol obj n))
((string? obj) (hash-string obj n))
((number? obj) (hash-number obj n))
((char? obj) (hash-char obj n))
((vector? obj) (hash-vector obj n))
((pair? obj) 0)
(else (modulo 1 n))))
; 'get' and 'put' procedures. Indexes can be arbitrary objects and are
; considered the same when they are eq?.
(define (get index1 index2)
(let ((x (2d-table-get *property-table* index1 index2)))
(and x (cdr x))))
(define (put index1 index2 value)
(2d-table-put *property-table* index1 index2 value))
(define *property-table* (make-2d-table))
| false |
84be250538b2a3865d3d3ad747d46aecebd5dd23 | 961ccc58c2ed4ed1d84a78614bedf0d57a2f2174 | /scheme/chapter3/make-accumulator.scm | 651ef4e0109e1d827d4366c6ee31973051fd8710 | []
| no_license | huangjs/mostly-lisp-code | 96483b566b8fa72ab0b73bf0e21f48cdb80dab0d | 9fe862dbb64f2a28be62bb1bd996238de018f549 | refs/heads/master | 2021-01-10T10:11:50.121705 | 2015-11-01T08:53:22 | 2015-11-01T08:53:22 | 45,328,850 | 0 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 118 | scm | make-accumulator.scm | (define (make-accumulator addend)
(lambda (augend)
(begin (set! addend (+ addend augend))
addend)))
| false |
718463f1981b889813e9568b108664657e54e664 | f08220a13ec5095557a3132d563a152e718c412f | /logrotate/skel/usr/share/guile/2.0/ice-9/expect.scm | ffc2e174221eaecfac4d5936aca39e781391abf8 | [
"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 | 5,628 | scm | expect.scm | ;;;; Copyright (C) 1996, 1998, 1999, 2001, 2006 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
;;;;
;;; Commentary:
;; This module is documented in the Guile Reference Manual.
;; Briefly, these are exported:
;; procedures: expect-select, expect-regexec
;; variables: expect-port, expect-timeout, expect-timeout-proc,
;; expect-eof-proc, expect-char-proc,
;; expect-strings-compile-flags, expect-strings-exec-flags,
;; macros: expect, expect-strings
;;; Code:
(define-module (ice-9 expect)
:use-module (ice-9 regex)
:export-syntax (expect expect-strings)
:export (expect-port expect-timeout expect-timeout-proc
expect-eof-proc expect-char-proc expect-strings-compile-flags
expect-strings-exec-flags expect-select expect-regexec))
;;; Expect: a macro for selecting actions based on what it reads from a port.
;;; The idea is from Don Libes' expect based on Tcl.
;;; This version by Gary Houston incorporating ideas from Aubrey Jaffer.
(define expect-port #f)
(define expect-timeout #f)
(define expect-timeout-proc #f)
(define expect-eof-proc #f)
(define expect-char-proc #f)
;;; expect: each test is a procedure which is applied to the accumulating
;;; string.
(defmacro expect clauses
(let ((s (gensym))
(c (gensym))
(port (gensym))
(timeout (gensym)))
`(let ((,s "")
(,port (or expect-port (current-input-port)))
;; when timeout occurs, in floating point seconds.
(,timeout (if expect-timeout
(let* ((secs-usecs (gettimeofday)))
(+ (car secs-usecs)
expect-timeout
(/ (cdr secs-usecs)
1000000))) ; one million.
#f)))
(let next-char ()
(if (and expect-timeout
(not (expect-select ,port ,timeout)))
(if expect-timeout-proc
(expect-timeout-proc ,s)
#f)
(let ((,c (read-char ,port)))
(if expect-char-proc
(expect-char-proc ,c))
(if (not (eof-object? ,c))
(set! ,s (string-append ,s (string ,c))))
(cond
;; this expands to clauses where the car invokes the
;; match proc and the cdr is the return value from expect
;; if the proc matched.
,@(let next-expr ((tests (map car clauses))
(exprs (map cdr clauses))
(body '()))
(cond
((null? tests)
(reverse body))
(else
(next-expr
(cdr tests)
(cdr exprs)
(cons
`((,(car tests) ,s (eof-object? ,c))
,@(cond ((null? (car exprs))
'())
((eq? (caar exprs) '=>)
(if (not (= (length (car exprs))
2))
(scm-error 'misc-error
"expect"
"bad recipient: ~S"
(list (car exprs))
#f)
`((apply ,(cadar exprs)
(,(car tests) ,s ,port)))))
(else
(car exprs))))
body)))))
;; if none of the clauses matched the current string.
(else (cond ((eof-object? ,c)
(if expect-eof-proc
(expect-eof-proc ,s)
#f))
(else
(next-char)))))))))))
(define expect-strings-compile-flags regexp/newline)
(define expect-strings-exec-flags regexp/noteol)
;;; the regexec front-end to expect:
;;; each test must evaluate to a regular expression.
(defmacro expect-strings clauses
`(let ,@(let next-test ((tests (map car clauses))
(exprs (map cdr clauses))
(defs '())
(body '()))
(cond ((null? tests)
(list (reverse defs) `(expect ,@(reverse body))))
(else
(let ((rxname (gensym)))
(next-test (cdr tests)
(cdr exprs)
(cons `(,rxname (make-regexp
,(car tests)
expect-strings-compile-flags))
defs)
(cons `((lambda (s eof?)
(expect-regexec ,rxname s eof?))
,@(car exprs))
body))))))))
;;; simplified select: returns #t if input is waiting or #f if timed out or
;;; select was interrupted by a signal.
;;; timeout is an absolute time in floating point seconds.
(define (expect-select port timeout)
(let* ((secs-usecs (gettimeofday))
(relative (- timeout
(car secs-usecs)
(/ (cdr secs-usecs)
1000000)))) ; one million.
(and (> relative 0)
(pair? (car (select (list port) '() '()
relative))))))
;;; match a string against a regexp, returning a list of strings (required
;;; by the => syntax) or #f. called once each time a character is added
;;; to s (eof? will be #f), and once when eof is reached (with eof? #t).
(define (expect-regexec rx s eof?)
;; if expect-strings-exec-flags contains regexp/noteol,
;; remove it for the eof test.
(let* ((flags (if (and eof?
(logand expect-strings-exec-flags regexp/noteol))
(logxor expect-strings-exec-flags regexp/noteol)
expect-strings-exec-flags))
(match (regexp-exec rx s 0 flags)))
(if match
(do ((i (- (match:count match) 1) (- i 1))
(result '() (cons (match:substring match i) result)))
((< i 0) result))
#f)))
;;; expect.scm ends here
| false |
0f9dbfc0369215a6e12c4126e1a9493829d1c383 | 6b961ef37ff7018c8449d3fa05c04ffbda56582b | /bbn_cl/mach/zcomp/rtlbase/rtline.scm | 71b19c05c8e76330a7aa724f76392d5298087662 | []
| no_license | tinysun212/bbn_cl | 7589c5ac901fbec1b8a13f2bd60510b4b8a20263 | 89d88095fc2a71254e04e57cf499ae86abf98898 | refs/heads/master | 2021-01-10T02:35:18.357279 | 2015-05-26T02:44:00 | 2015-05-26T02:44:00 | 36,267,589 | 4 | 3 | null | null | null | null | UTF-8 | Scheme | false | false | 3,681 | scm | rtline.scm | #| -*-Scheme-*-
$Header: rtline.scm,v 1.2 88/08/31 10:42:27 jinx Exp $
$MIT-Header: rtline.scm,v 4.2 87/12/30 07:07:37 GMT cph Exp $
Copyright (c) 1987 Massachusetts Institute of Technology
This material was developed by the Scheme project at the Massachusetts
Institute of Technology, Department of Electrical Engineering and
Computer Science. Permission to copy this software, to redistribute
it, and to use it for any purpose is granted, subject to the following
restrictions and understandings.
1. Any copy made of this software must include this copyright notice
in full.
2. Users of this software agree to make their best efforts (a) to
return to the MIT Scheme project any improvements or extensions that
they make, so that these may be included in future releases; and (b)
to inform MIT of noteworthy uses of this software.
3. All materials developed as a consequence of the use of this
software shall duly acknowledge such use, in accordance with the usual
standards of acknowledging credit in academic research.
4. MIT has made no warrantee or representation that the operation of
this software will be error-free, and MIT is under no obligation to
provide any services, by way of maintenance, update, or otherwise.
5. In conjunction with products arising from the use of this material,
there shall be no use of the name of the Massachusetts Institute of
Technology nor of any adaptation thereof in any advertising,
promotional, or sales literature without prior written consent from
MIT in each case. |#
;;;; RTL linearizer
(declare (usual-integrations))
;;; The linearizer attaches labels to nodes under two conditions. The
;;; first is that the node in question has more than one previous
;;; neighboring node. The other is when a conditional branch requires
;;; such a label. It is assumed that if one encounters a node that
;;; has already been linearized, that it has a label, since this
;;; implies that it has more than one previous neighbor.
(package (bblock-linearize-rtl)
(define-export (bblock-linearize-rtl bblock)
(node-mark! bblock)
(if (and (not (bblock-label bblock))
(node-previous>1? bblock))
(bblock-label! bblock))
(let ((kernel
(lambda ()
(let loop ((rinst (bblock-instructions bblock)))
(cond ((rinst-next rinst)
(cons (rinst-rtl rinst)
(loop (rinst-next rinst))))
((sblock? bblock)
(cons (rinst-rtl rinst)
(linearize-sblock-next (snode-next bblock))))
(else
(linearize-pblock bblock
(rinst-rtl rinst)
(pnode-consequent bblock)
(pnode-alternative bblock))))))))
(if (bblock-label bblock)
`(,(rtl:make-label-statement (bblock-label bblock)) ,@(kernel))
(kernel))))
(define (linearize-sblock-next bblock)
(cond ((not bblock) '())
((node-marked? bblock)
`(,(rtl:make-jump-statement (bblock-label! bblock))))
(else (bblock-linearize-rtl bblock))))
(define (linearize-pblock pblock predicate cn an)
(if (node-marked? cn)
(if (node-marked? an)
`(,(rtl:make-jumpc-statement predicate (bblock-label! cn))
,(rtl:make-jump-statement (bblock-label! an)))
`(,(rtl:make-jumpc-statement predicate (bblock-label! cn))
,@(bblock-linearize-rtl an)))
(if (node-marked? an)
`(,(rtl:make-jumpc-statement (rtl:negate-predicate predicate)
(bblock-label! an))
,@(bblock-linearize-rtl cn))
(let ((label (bblock-label! cn))
(alternative (bblock-linearize-rtl an)))
`(,(rtl:make-jumpc-statement predicate label)
,@alternative
,@(if (node-marked? cn)
'()
(bblock-linearize-rtl cn)))))))
)
(define linearize-rtl
(make-linearizer mapcan bblock-linearize-rtl))
| false |
189995ba57ee54e303e678f7d0bc5f259a379e20 | 86092887e6e28ebc92875339a38271319a87ea0d | /Ch3/3_75.scm | 52048f8329917e3fa381965e47049120ab574415 | []
| no_license | a2lin/sicp | 5637a172ae15cd1f27ffcfba79d460329ec52730 | eeb8df9188f2a32f49695074a81a2c684fe6e0a1 | refs/heads/master | 2021-01-16T23:55:38.885463 | 2016-12-25T07:52:07 | 2016-12-25T07:52:07 | 57,107,602 | 1 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 427 | scm | 3_75.scm | (define (make-zero-crossings input-stream old-avpt last-value)
(let ((avpt (/ (+ (stream-car input-stream)
last-value)
2)))
(cons-stream
(sign-change-detector avpt old-avpt)
(make-zero-crossings
(stream-cdr input-stream) avpt (stream-car input-stream)))))
; zero-crossings -> problem is that the last-value becomes the avpt, so we need
; keep the old avpt around
| false |
a1810fe042552d82f7204d8f290e99fe0adcb998 | defeada37d39bca09ef76f66f38683754c0a6aa0 | /System.Xml/system/xml/serialization/xml-array-item-attributes.sls | 65c36ce085119be428d48a5dd5d94a67a8d64bf8 | []
| 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,940 | sls | xml-array-item-attributes.sls | (library (system xml serialization xml-array-item-attributes)
(export new
is?
xml-array-item-attributes?
insert
index-of
add
contains?
remove
copy-to
item-get
item-set!
item-update!)
(import (ironscheme-clr-port))
(define-syntax new
(lambda (e)
(syntax-case e ()
((_ a ...)
#'(clr-new
System.Xml.Serialization.XmlArrayItemAttributes
a
...)))))
(define (is? a)
(clr-is System.Xml.Serialization.XmlArrayItemAttributes a))
(define (xml-array-item-attributes? a)
(clr-is System.Xml.Serialization.XmlArrayItemAttributes a))
(define-method-port
insert
System.Xml.Serialization.XmlArrayItemAttributes
Insert
(System.Void
System.Int32
System.Xml.Serialization.XmlArrayItemAttribute))
(define-method-port
index-of
System.Xml.Serialization.XmlArrayItemAttributes
IndexOf
(System.Int32 System.Xml.Serialization.XmlArrayItemAttribute))
(define-method-port
add
System.Xml.Serialization.XmlArrayItemAttributes
Add
(System.Int32 System.Xml.Serialization.XmlArrayItemAttribute))
(define-method-port
contains?
System.Xml.Serialization.XmlArrayItemAttributes
Contains
(System.Boolean System.Xml.Serialization.XmlArrayItemAttribute))
(define-method-port
remove
System.Xml.Serialization.XmlArrayItemAttributes
Remove
(System.Void System.Xml.Serialization.XmlArrayItemAttribute))
(define-method-port
copy-to
System.Xml.Serialization.XmlArrayItemAttributes
CopyTo
(System.Void
System.Xml.Serialization.XmlArrayItemAttribute[]
System.Int32))
(define-field-port
item-get
item-set!
item-update!
(property:)
System.Xml.Serialization.XmlArrayItemAttributes
Item
System.Xml.Serialization.XmlArrayItemAttribute))
| true |
120bec6bebc534abc3333d69aade1208b9146218 | defeada37d39bca09ef76f66f38683754c0a6aa0 | /UnityEngine.Networking/unity-engine/networking/network-system/add-player-message.sls | ca1c876748d06d0f594ace46bd481145c923ff20 | []
| 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,261 | sls | add-player-message.sls | (library (unity-engine networking network-system add-player-message)
(export new
is?
add-player-message?
deserialize
serialize
player-controller-id-get
player-controller-id-set!
player-controller-id-update!)
(import (ironscheme-clr-port))
(define-syntax new
(lambda (e)
(syntax-case e ()
((_ a ...)
#'(clr-new
UnityEngine.Networking.NetworkSystem.AddPlayerMessage
a
...)))))
(define (is? a)
(clr-is UnityEngine.Networking.NetworkSystem.AddPlayerMessage a))
(define (add-player-message? a)
(clr-is UnityEngine.Networking.NetworkSystem.AddPlayerMessage a))
(define-method-port
deserialize
UnityEngine.Networking.NetworkSystem.AddPlayerMessage
Deserialize
(System.Void UnityEngine.Networking.NetworkReader))
(define-method-port
serialize
UnityEngine.Networking.NetworkSystem.AddPlayerMessage
Serialize
(System.Void UnityEngine.Networking.NetworkWriter))
(define-field-port
player-controller-id-get
player-controller-id-set!
player-controller-id-update!
()
UnityEngine.Networking.NetworkSystem.AddPlayerMessage
playerControllerId
System.Int16))
| true |
e13c47ee1dd585188d2277dc90964844ac5faf11 | 29fdc68ecadc6665684dc478fc0b6637c1293ae2 | /src/wiliki/format.scm | fdf30ef336804484a63610914395104dcf5d256e | [
"MIT"
]
| permissive | shirok/WiLiKi | 5f99f74551b2755cb4b8deb4f41a2a770138e9dc | f0c3169aabd2d8d410a90033d44acae548c65cae | refs/heads/master | 2023-05-11T06:20:48.006068 | 2023-05-05T18:29:48 | 2023-05-05T18:30:12 | 9,766,292 | 20 | 6 | MIT | 2018-10-07T19:15:09 | 2013-04-30T07:40:21 | Scheme | UTF-8 | Scheme | false | false | 12,851 | scm | format.scm | ;;;
;;; wiliki/format.scm - format wiki pages (backward compatibility module)
;;;
;;; Copyright (c) 2003-2009 Shiro Kawai <[email protected]>
;;;
;;; Permission is hereby granted, free of charge, to any person
;;; obtaining a copy of this software and associated documentation
;;; files (the "Software"), to deal in the Software without restriction,
;;; including without limitation the rights to use, copy, modify,
;;; merge, publish, distribute, sublicense, and/or sell copies of
;;; the Software, and to permit persons to whom the Software is
;;; furnished to do so, subject to the following conditions:
;;;
;;; The above copyright notice and this permission notice shall be
;;; included in all copies or substantial portions of the Software.
;;;
;;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
;;; EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
;;; OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
;;; NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
;;; BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
;;; AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
;;; OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
;;; IN THE SOFTWARE.
;;;
(define-module wiliki.format
(use gauche.charconv)
(use gauche.sequence)
(use rfc.uri)
(use scheme.list)
(use srfi.13)
(use sxml.tools)
(use text.html-lite)
(use text.tr)
(use text.tree)
(use util.match)
(use util.queue)
(use wiliki.page)
(use wiliki.parse)
(export <wiliki-formatter-base>
wiliki:persistent-page?
wiliki:transient-page?
wiliki:format-wikiname
wiliki:format-macro
wiliki:format-time
wiliki:format-content
wiliki:formatter
wiliki:format-page-header
wiliki:format-page-content
wiliki:format-page-footer
wiliki:format-page-body
wiliki:format-head-elements
wiliki:format-head-title
wiliki:format-page
wiliki:format-line-plainly
wiliki:calculate-heading-id
wiliki:sxml->stree
wiliki:format-diff-pre
wiliki:format-diff-line
)
)
(select-module wiliki.format)
;; This module provides a base class <wiliki-formatter-base> as an anchor
;; point of customizing various formatting functions.
;;
;; The base class and methods only implements minimum functionalities, that
;; do not depend on persistent database. Subclass this class and specialize
;; method if you're writing a formatter for non-web targets (e.g. formatting
;; for a plain text).
;;
;; The <wiliki-formatter> class in wiliki.scm provides a full feature of
;; to generate HTML page. If you're customizing webpage formatting, use
;; that class as a starting point.
(define-class <wiliki-formatter-base> ()
(;; The following slots are only for compatibility to the code
;; written with WiLiKi-0.5_pre2.
;; They won't be supported officially in future versions; use
;; subclassing & methods instead.
(bracket :init-keyword :bracket
:init-value (^[name] (list #"[[~|name|]]")))
(macro :init-keyword :macro
:init-value (^[expr context] `("##" ,(write-to-string expr))))
(time :init-keyword :time
:init-value (^[time] (x->string time)))
(body :init-keyword :body
:init-value (^[page opts] (fmt-body page opts)))
(header :init-keyword :header
:init-value (^[page opts] '()))
(footer :init-keyword :footer
:init-value (^[page opts] '()))
(content :init-keyword :content
:init-value (^[page opts] (wiliki:format-content page)))
(head-elements :init-keyword :head-elements
:init-value (^[page opts] '()))
))
;; Global context and the default formatter
(define the-formatter
(make-parameter (make <wiliki-formatter-base>)))
;; similar to sxml:sxml->xml, but deals with stree node, which
;; embeds a string tree.
(define (wiliki:sxml->stree sxml)
(define (sxml-node type body)
(define (attr lis r)
(cond [(null? lis) (reverse! r)]
[(not (= (length+ (car lis)) 2))
(error "bad attribute in node: " (cons type body))]
[else
(attr (cdr lis)
(cons `(" " ,(html-escape-string (x->string (caar lis)))
"=\"" ,(html-escape-string (x->string (cadar lis)))
"\"")
r))]))
(define (rest type lis)
(if (and (null? lis)
(memq type '(br area link img param hr input col base meta)))
'(" />")
(list* ">" (reverse! (fold node '() lis)) "</" type "\n>")))
(if (and (pair? body)
(pair? (car body))
(eq? (caar body) '@))
(list* "<" type (attr (cdar body) '()) (rest type (cdr body)))
(list* "<" type (rest type body)))
)
(define (node n r)
(cond
[(string? n) (cons (html-escape-string n) r)]
[(and (pair? n) (symbol? (car n)))
(if (eq? (car n) 'stree)
(cons (cdr n) r)
(cons (sxml-node (car n) (cdr n)) r))]
[else
;; badly formed node. we show it for debugging ease.
(cons (list "<span class=\"wiliki-alert\">"
(html-escape-string (format "~,,,,50:s" n))
"</span\n>")
r)]))
(node sxml '()))
;;=================================================
;; Formatting: Wiki -> SXML
;;
;; Utility to generate a (mostly) unique id for the headings.
;; Passes a list of heading string stack.
(define (wiliki:calculate-heading-id headings)
(string-append "H-" (number->string (hash headings) 36)))
;; Backward compatibility
(define wiliki:format-line-plainly wiliki-remove-markup)
;; Page ======================================================
(define (wiliki:format-content page)
(define (do-fmt content)
(expand-page (wiliki-parse-string content)))
(cond [(string? page) (do-fmt page)]
[(is-a? page <wiliki-page>)
(if (wiliki-page-circular? page)
;; loop in $$include chain detected
`(p ">>>$$include loop detected<<<")
(parameterize ([wiliki-page-stack (cons page (wiliki-page-stack))])
(if (string? (ref page 'content))
(rlet1 sxml (do-fmt (ref page 'content))
(set! (ref page'content) sxml))
(ref page 'content))))]
[else page]))
;; [SXML] -> [SXML], expanding wiki-name and wiki-macro nodes.
;;
(define (expand-page sxmls)
(let rec ([sxmls sxmls]
[hctx '()]) ;;headings context
(match sxmls
[() '()]
[(('wiki-name name) . rest)
(append (wiliki:format-wikiname (the-formatter) name)
(rec rest hctx))]
[(('wiki-macro . expr) . rest)
(append (wiliki:format-macro (the-formatter) expr 'inline)
(rec rest hctx))]
[((and ((or 'h2 'h3 'h4 'h5 'h6) . _) sxml) . rest)
;; extract heading hierarchy to calculate heading id
(let* ([hn (sxml:name sxml)]
[hkey (assq 'hkey (sxml:aux-list-u sxml))]
[hctx2 (extend-headings-context hctx hn hkey)])
(cons `(,hn ,@(cond-list [hkey `(@ (id ,(heading-id hctx2)))])
,@(rec (sxml:content sxml) hctx))
(rec rest hctx2)))]
[((and (name . _) sxml) . rest);; generic node
(cons `(,name ,@(cond-list [(sxml:attr-list-node sxml)])
,@(rec (sxml:content sxml) hctx))
(rec rest hctx))]
[(other . rest)
(cons other (rec rest hctx))])))
(define (hn->level hn)
(find-index (cut eq? hn <>) '(h2 h3 h4 h5 h6)))
(define (extend-headings-context hctx hn hkey)
(if (not hkey)
hctx
(let* ([level (hn->level hn)]
[up (drop-while (^x (>= (hn->level (car x)) level)) hctx)])
(acons hn (cadr hkey) up))))
(define (heading-id hctx)
(wiliki:calculate-heading-id (map cdr hctx)))
;; default page body formatter
(define (fmt-body page opts)
`(,@(wiliki:format-page-header page opts)
,@(wiliki:format-page-content page opts)
,@(wiliki:format-page-footer page opts)))
;;;
;;; Exported functions
;;;
(define wiliki:formatter the-formatter)
;; Default formatting methods.
;; Methods are supposed to return SXML nodeset.
;; NB: It is _temporary_ that these methods calling the slot value
;; of the formatter, just to keep the backward compatibility to 0.5_pre2.
;; Do not count on this implementation. The next release will remove
;; all the closure slots of <wiliki-formatter-base> and the default behavior
;; will directly be embedded in these methods.
(define-method wiliki:format-wikiname ((fmt <wiliki-formatter-base>) name)
((~ fmt 'bracket) name))
(define-method wiliki:format-wikiname ((name <string>))
(wiliki:format-wikiname (the-formatter) name))
(define-method wiliki:format-macro ((fmt <wiliki-formatter-base>) expr context)
((~ fmt 'macro) expr context))
(define-method wiliki:format-macro (expr context)
(wiliki:format-macro (the-formatter) expr context))
(define-method wiliki:format-time ((fmt <wiliki-formatter-base>) time)
((~ fmt 'time) time))
(define-method wiliki:format-time (time)
(wiliki:format-time (the-formatter) time))
(define-method wiliki:format-page-content ((fmt <wiliki-formatter-base>)
page ;; may be a string
. options)
((~ fmt 'content) page options))
(define-method wiliki:format-page-content (page . opts)
(apply wiliki:format-page-content (the-formatter) page opts))
(define-method wiliki:format-page-body ((fmt <wiliki-formatter-base>)
(page <wiliki-page>)
. opts)
`(,@(apply wiliki:format-page-header page opts)
,@(apply wiliki:format-page-content page opts)
,@(apply wiliki:format-page-footer page opts)))
(define-method wiliki:format-page-body ((page <wiliki-page>) . opts)
(apply wiliki:format-page-body (the-formatter) page opts))
(define-method wiliki:format-page-header ((fmt <wiliki-formatter-base>)
(page <wiliki-page>)
. options)
((~ fmt 'header) page options))
(define-method wiliki:format-page-header ((page <wiliki-page>) . opts)
(apply wiliki:format-page-header (the-formatter) page opts))
(define-method wiliki:format-page-footer ((fmt <wiliki-formatter-base>)
(page <wiliki-page>)
. options)
((~ fmt 'footer) page options))
(define-method wiliki:format-page-footer ((page <wiliki-page>) . opts)
(apply wiliki:format-page-footer (the-formatter) page opts))
(define-method wiliki:format-head-elements ((fmt <wiliki-formatter-base>)
(page <wiliki-page>)
. options)
(append
((~ fmt 'head-elements) page options)
(ref page 'extra-head-elements)))
(define-method wiliki:format-head-elements ((page <wiliki-page>) . opts)
(apply wiliki:format-head-elements (the-formatter) page opts))
(define-method wiliki:format-head-title ((fmt <wiliki-formatter-base>)
(page <wiliki-page>) . options)
(~ page'title))
(define-method wiliki:format-page ((fmt <wiliki-formatter-base>)
(page <wiliki-page>)
. opts)
`(html
(head ,@(apply wiliki:format-head-elements fmt page opts))
(body ,@(apply wiliki:format-page-body fmt page opts))))
(define-method wiliki:format-page ((page <wiliki-page>) . opts)
(apply wiliki:format-page (the-formatter) page opts))
(define (wiliki:persistent-page? page)
(not (wiliki:transient-page? page)))
(define (wiliki:transient-page? page)
(not (ref page 'key)))
;; NB: these should also be a generics.
(define (wiliki:format-diff-pre difflines)
`(pre (@ (class "diff")
(style "background-color:#ffffff; color:#000000; margin:0"))
,@(map wiliki:format-diff-line difflines)))
(define (wiliki:format-diff-line line)
(define (aline . c)
`(span (@ (class "diff_added")
(style "background-color:#ffffff; color: #4444ff"))
,@c))
(define (dline . c)
`(span (@ (class "diff_deleted")
(style "background-color:#ffffff; color: #ff4444"))
,@c))
(cond [(string? line) `(span " " ,line "\n")]
[(eq? (car line) '+) (aline "+ " (cdr line) "\n")]
[(eq? (car line) '-) (dline "- " (cdr line) "\n")]
[else "???"]))
| false |
25ffbbddf9ec2b12951c1a9f61fcea7750792f6f | 923209816d56305004079b706d042d2fe5636b5a | /test/http/product-token.scm | 7f9ba106e020d2b97e1ffc85a8ca33a71ccbf369 | [
"BSD-3-Clause",
"BSD-2-Clause"
]
| permissive | tabe/http | 4144cb13451dc4d8b5790c42f285d5451c82f97a | ab01c6e9b4e17db9356161415263c5a8791444cf | refs/heads/master | 2021-01-23T21:33:47.859949 | 2010-06-10T03:36:44 | 2010-06-10T03:36:44 | 674,308 | 1 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 636 | scm | product-token.scm | #!r6rs
(import (rnrs (6))
(http product-token)
(http assertion)
(xunit))
(assert-parsing-successfully product
"CERN-LineMode/2.15"
`(,(string->list "CERN-LineMode") ((#\/ ,(string->list "2.15")))))
(assert-parsing-successfully product
"libwww/2.17b3"
`(,(string->list "libwww") ((#\/ ,(string->list "2.17b3")))))
(assert-parsing-successfully product
"Apache/0.8.4"
`(,(string->list "Apache") ((#\/ ,(string->list "0.8.4")))))
(report)
| false |
7b7772647d64614a3b6917a393d73d5aeb58b635 | 5bbc152058cea0c50b84216be04650fa8837a94b | /pre-benchmark/ecoop/rudybot/freenode-main.rkt | c1f0e80940b428f9546b4c504cfabac0200a4255 | []
| no_license | nuprl/gradual-typing-performance | 2abd696cc90b05f19ee0432fb47ca7fab4b65808 | 35442b3221299a9cadba6810573007736b0d65d4 | refs/heads/master | 2021-01-18T15:10:01.739413 | 2018-12-15T18:44:28 | 2018-12-15T18:44:28 | 27,730,565 | 11 | 3 | null | 2018-12-01T13:54:08 | 2014-12-08T19:15:22 | Racket | UTF-8 | Scheme | false | false | 1,581 | rkt | freenode-main.rkt | #! /bin/sh
#| Hey Emacs, this is -*-scheme-*- code!
exec racket --require "$0" --main -- ${1+"$@"}
|#
#lang racket
(require "loop.rkt"
(except-in "vars.rkt" log)
"git-version.rkt"
"clearenv.rkt"
(only-in "servers.rkt" real-server)
(only-in "userinfo.rkt" *userinfo-database-directory-name*)
(only-in "iserver.rkt" make-incubot-server)
version/utils)
(define (main . args)
(let ([required-version "5.2.900.1"])
(when (not (>= (version->integer (version))
(version->integer required-version)))
(error 'freenode-main "You need at least version ~a of racket, to avoid a memory leak in sqlite" required-version)))
(clearenv)
(command-line
#:program "rudybot"
#:once-each)
;; TODO -- the equivalent of "echo -17 > /proc/self/oom_adj", to
;; immunize this process from being killed by the dreaded oom_killer
;; (it happened once). See http://linux-mm.org/OOM_Killer
(log "Main starting: ~a" (git-version))
;; (parameterize ([current-namespace (module->namespace "freenode-main.rkt")])
;; (read-eval-print-loop))
(parameterize* ([*irc-server-hostname* "chat.freenode.org"]
[*irc-server-port* 6667]
[*userinfo-database-directory-name* "userinfo.db"]
[*incubot-logger* log]
[*incubot-server* (make-incubot-server)])
(if (*nickserv-password*)
(connect-and-run real-server)
(error 'freenode-main "You didn't specify a NickServ password"))))
(provide (all-defined-out))
| false |
5c482a1f5051d219f306ec4157a1096a20d6c27a | 9b2eb10c34176f47f7f490a4ce8412b7dd42cce7 | /lib-runtime/generic/libmgr-file.scm | c77e40ebe57e4cb699a4d7d03e7b8e189d324559 | [
"LicenseRef-scancode-public-domain",
"CC0-1.0"
]
| permissive | okuoku/yuni | 8be584a574c0597375f023c70b17a5a689fd6918 | 1859077a3c855f3a3912a71a5283e08488e76661 | refs/heads/master | 2023-07-21T11:30:14.824239 | 2023-06-11T13:16:01 | 2023-07-18T16:25:22 | 17,772,480 | 36 | 6 | CC0-1.0 | 2020-03-29T08:16:00 | 2014-03-15T09:53:13 | Scheme | UTF-8 | Scheme | false | false | 2,491 | scm | libmgr-file.scm | ;;
;; yuni library manager: File-based library provider
;;
; Globals
;; Directory list for library
(define *yuni/library-import-dirs* '())
;; Possible overrider for a library
(define *yuni/library-override-prefixes* '())
(define *yuni/library-override-paths* '())
; Procedures
;; Generate library path for a library name
(define (yuni/make-library-path base nam)
(if (pair? nam)
(yuni/make-library-path (string-append (string-append base "/")
(symbol->string (car nam)))
(cdr nam))
(string-append base ".sls")))
;; Try to lookup library
(define (yuni/library-name->path/core exists? prefix* name) ;; => path | #f
(define (itr rest)
(and (pair? rest)
(or (let ((name (yuni/make-library-path (car rest) name)))
(PCK 'TRYING: name)
(and (exists? name)
name))
(itr (cdr rest)))))
(PCK 'LOOKUP: name)
(itr prefix*))
(define (yuni/library-name->path0 name)
(yuni/library-name->path/core file-exists? *yuni/library-import-dirs* name))
(define (yuni/library-name->path/override name)
(define (override? fn)
(define (itr cur)
(and (pair? cur)
(or (string=? (car cur) fn)
(itr (cdr cur)))))
(itr *yuni/library-override-paths*))
(let ((a (car name))
(d (cdr name)))
(let ((m (assoc a *yuni/libalias*)))
(or (and m
(let ((aliasname (cons (cdr m) d)))
(yuni/library-name->path/core
override?
*yuni/library-override-prefixes*
aliasname)))
(yuni/library-name->path/core
override?
*yuni/library-override-prefixes*
name)))))
(define (yuni/library-name->path name)
(if (null? *yuni/library-override-paths*)
(yuni/library-name->path0 name)
(if (null? *yuni/library-override-prefixes*)
(error "????")
(or (yuni/library-name->path/override name)
(yuni/library-name->path0 name)))))
(define (yuni/add-library-import-dir! dir)
(set! *yuni/library-import-dirs*
(cons dir
*yuni/library-import-dirs*)))
(define (yuni/add-library-override-path! pth)
(set! *yuni/library-override-paths*
(cons pth
*yuni/library-override-paths*)))
(define (yuni/add-library-override-prefix! prefix)
(set! *yuni/library-override-prefixes*
(cons prefix
*yuni/library-override-prefixes*)))
| false |
e6e3c92402f212d981ee14311db6919fb166375c | e1fc47ba76cfc1881a5d096dc3d59ffe10d07be6 | /ch2/2.85.scm | d60b1d23cef72a1b44435a2791d3a05ec68619f9 | []
| no_license | lythesia/sicp-sol | e30918e1ebd799e479bae7e2a9bd4b4ed32ac075 | 169394cf3c3996d1865242a2a2773682f6f00a14 | refs/heads/master | 2021-01-18T14:31:34.469130 | 2019-10-08T03:34:36 | 2019-10-08T03:34:36 | 27,224,763 | 2 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 9,930 | scm | 2.85.scm | (load "util.scm") ; for make-table
(define operation-table (make-table))
(define get (operation-table 'lookup-proc))
(define put (operation-table 'insert-proc!))
;; generic
(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 (real-part z) (apply-generic 'real-part z))
(define (imag-part z) (apply-generic 'imag-part z))
(define (magnitude z) (apply-generic 'magnitude z))
(define (angle z) (apply-generic 'angle z))
(define (equ? x y) (apply-generic 'equ? x y))
(define (zero? x) (apply-generic 'zero? x))
(define (raise x) (apply-generic 'raise x))
(define (project x) (apply-generic 'project x))
; drop to proper type
(define (drop x)
(let ((t (type-tag x)) (ct (contents x)))
(if (and (eq? t 'scheme-number) (exact-integer? ct))
x ; int no drop
(let ((proj-x (project x)))
(if (equ? (raise proj-x) x) (drop proj-x) x)
)
)
)
)
; 0: scheme-number int
; 1: rational
; 2: scheme-number real
; 3: complex
(define (type-level x)
(let ((type (type-tag x)))
(cond
((eq? type 'rational) 1)
((eq? type 'complex) 3)
(else
(let ((val (contents x)))
(if (exact-integer? val) 0 2)
)
)
)
)
)
; raise lv types
(define (raise-up lv x)
(if (= lv 0) x
(raise-up (1- lv) (raise x))
)
)
(define (apply-generic op . args)
(let*
((type-tags (map type-tag args))
(proc (get op type-tags))
)
(if proc
; drop result as proper as possible
(let ((to-drop (or
(eq? op 'add)
(eq? op 'sub)
(eq? op 'mul)
(eq? op 'div)
)))
(if to-drop
(drop (apply proc (map contents args)))
(apply proc (map contents args))
)
)
; type promotion
(if (= (length args) 2)
(let* ((a1 (car args)) (a2 (cadr args)) (l1 (type-level a1)) (l2 (type-level a2)))
(cond
((< l1 l2) (apply-generic op (raise-up (- l2 l1) a1) a2))
(else (apply-generic op a1 (raise-up (- l1 l2) a2)))
)
)
(error "# arg more than 2 -- APPLY-GENERIC" (list op type-tags))
)
)
)
)
(define (attach-tag type-tag contents)
(if (number? contents)
contents
(cons type-tag contents)
)
)
(define (type-tag o)
(cond
((number? o) 'scheme-number)
((pair? o) (car o))
(else (error "Bad tagged datnum -- TYPE-TAG" o))
)
)
(define (contents o)
(cond
((number? o) o)
((pair? o) (cdr o))
(else (error "Bad tagged datnum -- CONTENTS" o))
)
)
;; scheme-number
(define (install-scheme-number-package)
; <num>
(define (tag x) (attach-tag 'scheme-number x))
(let ((t 'scheme-number))
(put 'add (list t t) (lambda (x y) (tag (+ x y))))
(put 'sub (list t t) (lambda (x y) (tag (- x y))))
(put 'mul (list t t) (lambda (x y) (tag (* x y))))
(put 'div (list t t) (lambda (x y) (tag (/ x y))))
(put 'equ? (list t t) =)
(put 'zero? (list t) (lambda (x) (= x 0)))
(put 'make t (lambda (x) (tag x)))
; int -> rat; float -> complex
(put 'raise (list t) (lambda (x) (if (exact-integer? x) (make-rat x 1) (make-complex-from-real-imag x 0))))
; project real->rat(round numer/denom)
(put 'project (list t)
(lambda (x)
(define eps 0.001)
(define (try-rat nd)
(let ((n (car nd)) (d (cadr nd)))
(if (< (abs (/ (- n (round n)) n)) eps)
(list (inexact->exact (round n)) d)
(try-rat (list (* 10 n) (* 10 d)))
)
)
)
(cond
((exact-integer? x) x)
((= x 0) (make-rat 0 1))
(else (let ((nd (try-rat (list x 1)))) (make-rat (car nd) (cadr nd))))
)
)
)
)
'done
)
;; rational
(define (install-rational-package)
; (<tag> . (<numer> . <denom>))
; internal procedures
(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))
; export
(let ((t 'rational))
(put 'add (list t t) (lambda (x y) (tag (add-rat x y))))
(put 'sub (list t t) (lambda (x y) (tag (sub-rat x y))))
(put 'mul (list t t) (lambda (x y) (tag (mul-rat x y))))
(put 'div (list t t) (lambda (x y) (tag (div-rat x y))))
(put 'equ? (list t t) (lambda (x y) (and (equ? (numer x) (numer y)) (equ? (denom x) (denom y)))))
(put 'zero? (list t) (lambda (x) (zero? (numer x))))
(put 'make t (lambda (n d) (tag (make-rat n d))))
; rat -> real
(put 'raise (list t) (lambda (x) (make-scheme-number (exact->inexact (/ (numer x) (denom x))))))
; rat -> int
(put 'project (list t) (lambda (x) (make-scheme-number (round (/ (numer x) (denom x))))))
)
'done
)
; complex
; rectangular
(define (install-rectangualr-package)
; (<r> . <i>)
; internal procedures
(define (real-part z) (car z))
(define (imag-part z) (cdr z))
(define (make-from-real-imag r i) (cons r i))
(define (make-from-mag-ang r a) (cons (* r (cos a)) (* r (sin a))))
(define (magnitude z)
(sqrt (+ (square (real-part z)) (square (imag-part z))))
)
(define (angle z) (atan (imag-part z) (real-part z)))
(define (tag x) (attach-tag 'rectangular x))
; export
(let ((t 'rectangular))
(put 'real-part (list t) real-part)
(put 'imag-part (list t) imag-part)
(put 'magnitude (list t) magnitude)
(put 'angle (list t) angle)
(put 'make-from-real-imag t (lambda (r i) (tag (make-from-real-imag r i))))
(put 'make-from-mag-ang t (lambda (r a) (tag (make-from-mag-ang r a))))
(put 'equ? (list t t) (lambda (x y) (and (equ? (real-part x) (real-part y)) (equ? (imag-part x) (imag-part y)))))
(put 'zero? (list t) (lambda (x) (and (zero? (real-part x)) (zero? (imag-part x)))))
)
'done
)
; polar
(define (install-polar-package)
; (<r> . <a>)
; internal procedures
(define (magnitude z) (car z))
(define (angle z) (cdr z))
(define (real-part z) (* (magnitude z) (cos (angle z))))
(define (imag-part z) (* (magnitude z) (sin (angle z))))
(define (make-from-real-imag r i)
(cons (sqrt (+ (square r) (square i))) (atan i r))
)
(define (make-from-mag-ang r a) (cons r a))
(define (tag x) (attach-tag 'polar x))
; export
(let ((t 'polar))
(put 'real-part (list t) real-part)
(put 'imag-part (list t) imag-part)
(put 'magnitude (list t) magnitude)
(put 'angle (list t) angle)
(put 'make-from-real-imag t (lambda (r i) (tag (make-from-real-imag r i))))
(put 'make-from-mag-ang t (lambda (r a) (tag (make-from-mag-ang r a))))
(put 'equ? (list t t) (lambda (x y) (and (equ? (magnitude x) (magnitude y)) (equ? (angle x) (angle y)))))
(put 'zero? (list t) (lambda (x) (zero? (magnitude x))))
)
'done
)
(define (install-complex-package)
; internal procedures
(define (make-from-real-imag r i)
((get 'make-from-real-imag 'rectangular) r i)
)
(define (make-from-mag-ang r a)
((get 'make-from-mag-ang 'polar) r a)
)
(define (add-complex x y)
(make-from-real-imag
(+ (real-part x) (real-part y))
(+ (imag-part x) (imag-part y))
)
)
(define (sub-complex x y)
(make-from-real-imag
(- (real-part x) (real-part y))
(- (imag-part x) (imag-part y))
)
)
(define (mul-complex x y)
(make-from-mag-ang
(* (magnitude x) (magnitude y))
(+ (angle x) (angle y))
)
)
(define (div-complex x y)
(make-from-mag-ang
(/ (magnitude x) (magnitude y))
(- (angle x) (angle y))
)
)
(define (tag x) (attach-tag 'complex x))
(let ((t 'complex))
(put 'add (list t t) (lambda (x y) (tag (add-complex x y))))
(put 'sub (list t t) (lambda (x y) (tag (sub-complex x y))))
(put 'mul (list t t) (lambda (x y) (tag (mul-complex x y))))
(put 'div (list t t) (lambda (x y) (tag (div-complex x y))))
(put 'make-from-real-imag t (lambda (r i) (tag (make-from-real-imag r i))))
(put 'make-from-mag-ang t (lambda (r i) (tag (make-from-mag-ang r i))))
(put 'real-part (list t) real-part)
(put 'imag-part (list t) imag-part)
(put 'magnitude (list t) magnitude)
(put 'angle (list t) angle)
(put 'equ? (list t t) equ?)
(put 'zero? (list t) zero?)
; complex -> real
(put 'project (list t) (lambda (z) (make-scheme-number (exact->inexact (real-part z)))))
)
'done
)
; test
(install-scheme-number-package)
(install-rational-package)
(install-rectangualr-package)
(install-polar-package)
(install-complex-package)
; later export or will be #f
(define make-scheme-number (get 'make 'scheme-number))
(define (make-rat n d) ((get 'make 'rational) n d))
(define (make-complex-from-real-imag r i) ((get 'make-from-real-imag 'complex) r i))
(define (make-complex-from-mag-ang r a) ((get 'make-from-mag-ang 'complex) r a))
; (display (raise (make-scheme-number 3)))(newline)
; (display (raise (make-scheme-number 3.14)))(newline)
; (display (raise (make-rat 3 4)))(newline)
; (display (raise (make-rat 6 3)))(newline)
; (define irat (make-rat 8 2))
; (display irat)(newline)
; (display (drop irat))(newline)
; (define icpx-a (make-complex-from-real-imag 2.5 0))
; (define icpx-b (make-complex-from-real-imag 3.5 0))
; (display (add icpx-a icpx-b))(newline)
| false |
e314f4c264be735d8e26605f344caaf0c27cdb95 | 120324bbbf63c54de0b7f1ca48d5dcbbc5cfb193 | /packages/srfi/%3a61.sls | 7182a768370bb5b5ef918010c66501a33cf0d90a | [
"MIT",
"X11-distribute-modifications-variant"
]
| 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 | 141 | sls | %3a61.sls | #!r6rs
;; Automatically generated by private/make-aliased-libraries.sps
(library (srfi :61)
(export
cond)
(import (srfi :61 cond))
)
| false |
332844bafd5746e4f5943e68edb3a99672357f56 | 53923a0517253c435bf6be5c7f49fc49693884ba | /src/redex/doti_tests.ss | d3f1fb3048f1d2874c7c1e33efc4e8f91328308f | []
| no_license | smarter/dot | e59788352730e5adb5eebdaa443e1ef4a8a6cf2a | 99dcdbda7031121b7e03f59fcaef90ead30c1d87 | refs/heads/master | 2021-01-17T05:33:17.975458 | 2014-10-06T15:14:43 | 2014-10-06T15:14:43 | null | 0 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 22,682 | ss | doti_tests.ss | #lang racket
(require redex)
(require "doti.ss")
(define-metafunction dot
valnew : (x c) e -> e
[(valnew (x c) e) (val x = new c in e)])
;(require rackunit)
; redefining these so that redex includes them in the summary
(define (check-true e)
(test-equal e #t))
(define (check-false e)
(test-equal e #f))
(define (check-not-false e)
(test-equal (not (not e)) #t))
;; grammar
(check-true (redex-match? dot e (term (val u = new (Top) in u))))
(check-true (redex-match? dot e (term (val u = new ((rfn Top self (: (cv l) Top)) [(cv l) u]) in (sel u (cv l))))))
;; substitution
(check-true (redex-match? dot
(val x_1 = new ((rfn Top self (: (cm f) Top Top)) [(cm f) x_2 x_2]) in x_1)
(term (subst (val u = new ((rfn Top self (: (cm f) Top Top)) [(cm f) x x]) in u) x y))))
(check-true (redex-match? dot
(val x_1 = new ((rfn Top self (: (cm f) Top Top)) [(cm f) (side-condition x_2 (not (equal? 'y (term x_2)))) y]) in x_1)
(term (subst (valnew (u ((rfn Top self (: (cm f) Top Top)) [(cm f) y x])) u) x y))))
(check-true (redex-match? dot
(val x_1 = new ((rfn Top self (: (cm f) Top Top)) [(cm f) (side-condition x_2 (not (equal? 'y (term x_2)))) y]) in x_1)
(term (subst (valnew (u ((rfn Top self (: (cm f) Top Top)) [(cm f) z x])) u) x y))))
(check-true (redex-match? dot
(val x_1 = new (Top) in y)
(term (subst (valnew (u (Top)) x) x y))))
(check-true (redex-match? dot
(val (side-condition x_1 (not (equal? 'u (term x_1)))) = new (Top) in u)
(term (subst (valnew (u (Top)) x) x u))))
(check-true (redex-match? dot
(val x_1 = new ((rfn Top self (: (cm mt) Top Top)) [(cm mt) x_2 x_1]) in (sel x_1 (cm mt) x_1))
(term (subst (valnew (u ((rfn Top self (: (cm mt) Top Top)) [(cm mt) y u])) (sel u (cm mt) u)) mt x))))
;; reduction
;(trace-dot (term (valnew (u ((rfn Top self (: (cv l) Top)) [(cv l) u])) (sel u (cv l)))))
;; evaluation
(check-not-false (term (ev () (valnew (u (Top)) u))))
(check-not-false (term (ev () (valnew (u ((rfn Top self (: (cm f) Top Top)) [(cm l) x x])) (sel u (cm l) u)))))
(check-not-false (term (ev () (valnew (u ((rfn Top self (: (cm l) Top Top)) [(cm l) x u])) (sel u (cm l) u)))))
;; type-checking
(test-equal (typecheck (term (() ())) (term (valnew (u (Top)) u)))
'Top)
(test-equal (typecheck (term (() ())) (term (valnew (o (Top)) (valnew (o (Top)) o))))
'Top)
(test-equal (typecheck (term (() ())) (term (valnew (u ((rfn Top u (: (cm f) Top Top)) [(cm f) x x])) u)))
(term (rfn Top u (: (cm f) Top Top))))
(test-equal (typecheck (term (() ())) (term (valnew (u ((rfn Top u (: (cm f) Top Top)) [(cm f) x x])) (sel u (cm f) u))))
'Top)
(test-equal (typecheck (term (() ())) (term (valnew (u ((rfn Top u (: (cm l) Top Top)) [(cm l) x u])) (sel u (cm l) u))))
'Top)
(test-equal (typecheck (term (() ())) (term (valnew (u ((rfn Top u (: (ca l) Top Top)))) u)))
(term (rfn Top u (: (ca l) Top Top))))
(test-equal (typecheck (term (() ())) (term (valnew (u ((rfn Top u (: (ca l) Top Top))))
(valnew (w ((rfn Top w (: (cm f) (sel u (ca l)) Top))
[(cm f) x x]))
(sel w (cm f) u)))))
'Top)
(test-equal (typecheck (term (() ())) (term (valnew (u ((rfn Top u (: (ca l) Top Top) (: (cm f) (sel u (ca l)) Top))
[(cm f) x x]))
(sel u (cm f) u))))
'Top)
(test-equal (typecheck (term (() ())) (term (valnew (u ((rfn Top u
(: (ca l) Top Top)
(: (cm f) (sel u (ca l)) (rfn Top z (: (ca l) Top Top))))
[(cm f) x u]))
(sel u (cm f) u))))
(term (rfn Top z (: (ca l) Top Top))))
;; sugar
(test-equal (typecheck (term (() ())) (term (fun x Top Top x)))
(term (rfn Top f (: (cm apply) Top Top))))
(test-equal (typecheck (term (() ())) (term (valnew (d (Top)) (fun x Top Top x))))
(term (rfn Top f (: (cm apply) Top Top))))
(test-equal (typecheck (term (() ())) (term (valnew (d (Top)) (app (fun x Top Top x) d))))
'Top)
;(test-equal (typecheck (term (() ())) (dotExample)) 'Top)
;; soundness
(test-predicate preservation (term (valnew (u (Top)) u)))
(test-predicate preservation (term (app (fun x Top Top x) (fun x Top Top x))))
(test-predicate preservation (term (valnew (u ((rfn Top u (: (cm l) Top Top)) [(cm l) x u])) (sel u (cm l) u))))
(test-predicate preservation (term (valnew (u ((rfn Top u (: (ca l) Top Top)))) (app (fun x (sel u (ca l)) Top u) u))))
;(test-predicate preservation (dotExample))
(test-predicate big-step-preservation (term (valnew (u (Top)) u)))
(test-predicate big-step-preservation (term (app (fun x Top Top x) (fun x Top Top x))))
(test-predicate big-step-preservation (term (valnew (u ((rfn Top u (: (cm l) Top Top)) [(cm l) x u])) (sel u (cm l) u))))
(test-predicate big-step-preservation (term (valnew (u ((rfn Top u (: (ca l) Top Top)))) (app (fun x (sel u (ca l)) Top u) u))))
;(test-predicate big-step-preservation (dotExample))
(test-predicate type-safety (term (valnew (u (Top)) u)))
(test-predicate type-safety (term (app (fun x Top Top x) (fun x Top Top x))))
(test-predicate type-safety (term (valnew (u ((rfn Top u (: (cm l) Top Top)) [(cm l) x u])) (sel u (cm l) u))))
(test-predicate type-safety (term (valnew (u ((rfn Top u (: (ca l) Top Top)))) (app (fun x (sel u (ca l)) Top u) u))))
;(test-predicate type-safety (dotExample))
(check-true (subtyping-transitive (term (([x (rfn Top self (: (cc L) Bot (sel self (cc L))))]) ())) (term (sel x (cc L))) (term Top) (term (rfn Top z))))
(test-predicate preservation (term (valnew (u ((rfn Top self (: (cc L) Bot (sel self (cc L)))))) (fun x Top Top x))))
(check-false
(typecheck (term (() ())) (term (valnew (u ((rfn Top self (: (cc L) Bot (sel self (cc L)))))) (cast Top
(cast (arrow (sel u (cc L)) (rfn Top z))
(cast (arrow (sel u (cc L)) Top)
(fun x (sel u (cc L)) (sel u (cc L)) x)))
))))
)
(check-false
(typecheck (term (() ())) (term (valnew (u ((rfn Top self
(: (ca L1) Bot (sel self (ca L1)))
(: (ca L2) Bot (rfn Top z (: (ca L3) Bot Top)))
(: (ca L4) ((sel self (ca L2)) ∧ (sel self (ca L1))) (sel self (ca L2))))))
(cast Top
(cast (arrow ((sel u (ca L2)) ∧ (sel u (ca L1))) (rfn Top z (: (ca L3) Bot Top)))
(cast (arrow ((sel u (ca L2)) ∧ (sel u (ca L1))) (sel u (ca L4)))
(fun x ((sel u (ca L2)) ∧ (sel u (ca L1)))
((sel u (ca L2)) ∧ (sel u (ca L1)))
x)))
))))
)
(check-true
(let ([env (term (([u (rfn Top self
(: (ca Bad) Bot (sel self (ca Bad)))
(: (ca BadBounds) Top (sel self (ca Bad)))
(: (ca Mix) (sel self (ca BadBounds)) Top))])
()))]
[s (term (sel u (ca BadBounds)))]
[t (term (sel u (ca Mix)))]
[u (term (rfn (sel u (ca Mix)) z))])
(subtyping-transitive env s t u))
)
(check-true
(let ([env (term (([u (rfn Top self
(: (ca Bad) Bot (sel self (ca Bad)))
(: (ca Good) (rfn Top z (: (ca L) Bot Top)) (rfn Top z (: (ca L) Bot Top)))
(: (ca Lower) ((sel self (ca Bad)) ∧ (sel self (ca Good))) (sel self (ca Good)))
(: (ca Upper) (sel self (ca Good)) ((sel self (ca Bad)) ∨ (sel self (ca Good))))
(: (ca X) (sel self (ca Lower)) (sel self (ca Upper))))])
()))]
[s (term ((sel u (ca Bad)) ∧ (sel u (ca Good))))]
[t (term (sel u (ca Lower)))]
[u (term (rfn (sel u (ca X)) z (: (ca L) Bot Top)))])
(subtyping-transitive env s t u))
)
(check-true
(let ([Tc (term (rfn Top self
(: (ca Bad) Bot (sel self (ca Bad)))
(: (ca Good) (rfn Top z (: (ca L) Bot Top)) (rfn Top z (: (ca L) Bot Top)))
(: (ca Lower) ((sel self (ca Bad)) ∧ (sel self (ca Good))) (sel self (ca Good)))
(: (ca Upper) (sel self (ca Good)) ((sel self (ca Bad)) ∨ (sel self (ca Good))))
(: (ca X) (sel self (ca Lower)) (sel self (ca Upper)))))]
[s (term ((sel u (ca Bad)) ∧ (sel u (ca Good))))]
[t (term (sel u (ca Lower)))]
[u (term (rfn (sel u (ca X)) z (: (ca L) Bot Top)))])
(preservation (term (valnew (u (,Tc)) (cast Top
(cast (arrow ,s ,u)
(cast (arrow ,s ,t)
(cast (arrow ,s ,s)
(fun x ,s ,s x)))))))))
)
(test-equal
(typecheck (term (() ())) (term (valnew (u ((rfn Top self
(: (cc Bar) Bot (rfn Top self (: (cc T) Bot Top)))
(: (cc Foo) Bot (rfn (sel self (cc Bar)) z (: (cc T) Bot (sel self (cc Foo)))))
(: (cm foo) Top (arrow Top (sel self (cc Foo)))))
((cm foo) dummy (fun x Top (sel u (cc Foo)) (valnew (foo ((sel u (cc Foo)))) foo)))))
(as Top (sel u (cm foo) (as Top u))))))
'Top)
(test-equal
(typecheck (term (() ())) (term (valnew (u ((rfn Top self
(: (cc Bar) Bot (rfn Top self (: (ca T) Bot Top) (: (cm some) Top (sel self (ca T)))))
(: (cc Foo) Bot (rfn (sel self (cc Bar)) z (: (ca T) (sel self (cc Foo)) Top)))
(: (cm foo) Top (arrow Top (sel self (cc Foo)))))
((cm foo) dummy (fun x Top (sel u (cc Foo)) (valnew (foo ((sel u (cc Foo)) ((cm some) dummy (as (sel foo (ca T)) foo)))) foo)))))
(cast Top (sel u (cm foo) (as Top u))))))
'Top)
#;
(let ((w (term (rfn Top b
(: (cc T) Bot (sel (sel b (cv x)) (cc T)))
(: (cv x) (sel u (cc C)))))))
(judgment-holds
(expansion (((u (rfn Top a
(: (cc C) Bot ,w)))
(w ,w))
())
z
(sel w (cc T))
((DLt ...) (Dl ...) (Dm ...)))
((DLt ...) (Dl ...) (Dm ...))))
(check-not-false
(typecheck (term (() ())) (term (fun x Bot Top (fun z (sel x (cc Lt)) (sel x (cc Lt)) z))))
)
(check-not-false
(let ((typeX (term (rfn Top z
(: (ca A) Top Top)
(: (cm l) Top (sel z (ca A))))))
(typeY (term (rfn Top z
(: (cm l) Top Top)))))
(type-safety
(term
(valnew
(u (,typeX ((cm l) dummy (as (sel u (ca A)) u))))
(sel (app (fun y (arrow Top ,typeY) ,typeY (app y (as Top u))) (as (arrow Top ,typeY) (fun d Top ,typeX (cast ,typeX u)))) (cm l) (as Top u))))))
)
(check-not-false
(type-safety
(term
(app (fun p (rfn Top p (: (ca X) (rfn Top a (: (ca A) Top Top ) (: (cv l) Top)) (rfn Top a (: (ca A) Top Top ) (: (cv l) Top)))) Top
(val a = new ((rfn Top a (: (ca A) Top Top ) (: (cv l) (sel a (ca A)))) ((cv l) a)) in
(val b = new ((rfn Top b (: (cv l) (sel p (ca X)))) ((cv l) a)) in
(sel (sel b (cv l)) (cv l)))))
(val p = new ((rfn Top p (: (ca X) (rfn Top a (: (ca A) Top Top ) (: (cv l) (sel a (ca A)))) (rfn Top a (: (ca A) Top Top ) (: (cv l) (sel a (ca A))))))) in p))))
)
(check-not-false
(let ((typeX (term (rfn Top z
(: (ca A) Top Top)
(: (cm l) Top (sel z (ca A))))))
(typeY (term (rfn Top z
(: (cm l) Top Top)))))
(big-step-preservation
(term
(valnew
(u (,typeX ((cm l) dummy (as (sel u (ca A)) u)))) (cast Top
(app (fun y (arrow- f ((: (ca Y) ,typeX ,typeY)) Top (sel f (ca Y)))
(arrow Top Top)
(fun d Top Top (sel (cast (sel y (ca Y)) (app y (as Top u))) (cm l) (as Top u))))
(as (arrow- f ((: (ca Y) ,typeX ,typeY)) Top (sel f (ca Y)))
(fun- f ((: (ca Y) ,typeX ,typeX)) (d Top) (sel f (ca Y)) (as (sel f (ca Y)) u)))))))))
)
(test-predicate type-safety
(term
(valnew
(b ((rfn Top z
(: (ca X) Top Top)
(: (cv l) (sel z (ca X))))
((cv l) b)))
(valnew
(a ((rfn Top z
(: (cv i) (rfn Top z
(: (ca X) Bot Top)
(: (cv l) (sel z (ca X))))))
((cv i) b)))
(cast Top
(cast (sel (sel a (cv i)) (ca X))
(sel (sel a (cv i)) (cv l))))))))
(test-predicate big-step-preservation
(term
(valnew
(b ((rfn Top z
(: (ca X) Top Top)
(: (cv l) (sel z (ca X))))
((cv l) b)))
(valnew
(a ((rfn Top z
(: (cv i) (rfn Top z
(: (ca X) Bot Top)
(: (cv l) (sel z (ca X))))))
((cv i) b)))
(cast Top
(app (fun x (sel (sel a (cv i)) (ca X))
(arrow Top Top)
(fun d Top (sel (sel a (cv i)) (ca X)) x))
(sel (sel a (cv i)) (cv l))))))))
(test-predicate type-safety
(term
(valnew
(b ((rfn Top z
(: (ca X) Top Top)
(: (cv l) (sel z (ca X))))
((cv l) b)))
(valnew
(a ((rfn Top z
(: (cv i) (rfn Top z
(: (ca X) Bot Top)
(: (cv l) (sel z (ca X))))))
((cv i) b)))
(cast Top
(cast (sel (sel a (cv i)) (ca X))
(sel (sel a (cv i)) (cv l))))))))
(test-predicate big-step-preservation
(term
(valnew
(b ((rfn Top z
(: (ca X) Top Top)
(: (cv l) (sel z (ca X))))
((cv l) b)))
(valnew
(a ((rfn Top z
(: (cv i) (rfn Top z
(: (ca X) Bot Top)
(: (cv l) (sel z (ca X))))))
((cv i) b)))
(cast Top
(app (fun x (sel (sel a (cv i)) (ca X))
(arrow Top (sel (sel a (cv i)) (ca X)))
(fun d Top (sel (sel a (cv i)) (ca X)) x))
(sel (sel a (cv i)) (cv l))))))))
(check-true
(let* ([typeX (term (rfn Top z
(: (ca A) Top Top)
(: (ca B) Top Top)
(: (ca C) Bot (sel z (ca B)))))]
[typeY (term (rfn Top z
(: (ca A) Bot Top)
(: (ca B) Bot Top)
(: (ca C) Bot (sel z (ca A)))))]
[typeZ (term (rfn ,typeX z
(: (ca A) Bot Bot)
(: (ca B) Bot Bot)))])
(subtyping-transitive (term (() ())) typeZ typeX typeY))
)
(test-predicate preservation
(term
(valnew (v ((rfn Top z (: (cc L) Bot (rfn Top z (: (ca A) Top Bot))))))
(app (fun x (rfn Top z (: (cc L) Bot (rfn Top z (: (ca A) Bot Top))))
Top
(valnew (z ((sel x (cc L)))) (cast Top z)))
v))))
(test-predicate type-safety
(term
(valnew (v ((rfn Top z (: (ca L) Bot (rfn Top z (: (ca A) Bot Top) (: (ca B) Bot (sel z (ca A))))))))
(app (fun x (rfn Top z (: (ca L) Bot (rfn Top z (: (ca A) Bot Top) (: (ca B) Bot Top)))) Top
(valnew (z ((rfn Top z (: (cm l)
((sel x (ca L))
∧
(rfn Top z (: (ca A) Bot (sel z (ca B))) (: (ca B) Bot Top)))
Top))
((cm l) y
(as Top (fun a (sel y (ca A)) Top a)))))
(cast Top z)))
(as (rfn Top z (: (ca L) Bot (rfn Top z (: (ca A) Bot Top) (: (ca B) Bot Top)))) v)))))
#;
(test-predicate type-safety
(term
(valnew (x00 ((rfn Top z (: (ca L) Bot
(rfn Top self
(: (ca A) Bot Top)
(: (ca B) Bot Top)
(: (cc Lc2) Bot (sel self (ca A))))))))
(valnew (x0 ((rfn Top z (: (cc Lc1) Bot (rfn Top z (: (ca L) Bot (sel x00 (ca L))))))))
(valnew (x1 ((rfn (sel x0 (cc Lc1)) z (: (ca L) Bot
(rfn (sel x00 (ca L)) self
(: (ca A) Bot (sel self (ca B))))))))
(valnew (x2 ((rfn (sel x0 (cc Lc1)) z (: (ca L) Bot
(rfn (sel x00 (ca L)) self
(: (ca B) Bot (sel self (ca A))))))))
(app (fun x (sel x0 (cc Lc1)) Top
(fun z0 ((sel x (ca L)) ∧ (sel x2 (ca L))) Top
(valnew (z ((sel z0 (cc Lc2))))
(cast Top z))))
(as (sel x0 (cc Lc1)) x1))))))))
(test-predicate type-safety
(term
(valnew (v ((rfn Top z (: (ca L) Bot (rfn Top z (: (ca A) Bot Top) (: (ca B) (sel z (ca A)) Top))))))
(app (fun x (rfn Top z (: (ca L) Bot (rfn Top z (: (ca A) Bot Top) (: (ca B) Bot Top)))) Top
(valnew (z ((rfn Top z (: (cm l)
((sel x (ca L))
∧
(rfn Top z (: (ca A) (sel z (ca B)) Top) (: (ca B) Bot Top)))
Top))
((cm l) y
(as Top (fun a (sel y (ca A)) Top a)))))
(cast Top z)))
(as (rfn Top z (: (ca L) Bot (rfn Top z (: (ca A) Bot Top) (: (ca B) Bot Top)))) v)))))
(test-predicate preservation
(term
(valnew (v ((rfn Top z (: (ca L) Bot Top) (: (cv l) (rfn Top z (: (ca L) Bot Top))))
((cv l) v)))
(app (fun x Top Top x)
(sel (as (rfn Top z (: (cv l) Top)) v) (cv l))))))
(test-predicate preservation
(term
(valnew (v ((rfn Top z (: (cm m) Top Top))
((cm m) x x)))
(app (fun x Top Top x)
(sel (as (rfn Top z (: (cm m) (rfn Top z (: (cm m) Top Top)) Top)) v)
(cm m)
v)))))
(test-predicate preservation
(term
(valnew (v ((rfn Top z
(: (ca A) Top Top)
(: (cm m) (rfn Top z (: (ca A) Top Top)) (rfn Top z (: (ca A) Top Top))))
((cm m) x x)))
(app (fun x Top Top x)
(sel (as (rfn Top z (: (cm m) (rfn Top z (: (ca A) Top Top)) Top)) v)
(cm m)
(as (rfn Top z (: (ca A) Top Top)) v))))))
(test-predicate preservation
(term
(valnew (v ((rfn Top z
(: (ca A) Top Top)
(: (ca B) Bot Top)
(: (cm m) (rfn Top z (: (ca A) Top Top)) (rfn Top z (: (ca A) Top Top))))
((cm m) x x)))
(app (fun x Top Top x)
(sel (as (rfn Top z (: (cm m) (rfn Top z (: (ca A) Top Top) (: (ca B) Bot Top)) Top)) v)
(cm m)
(as (rfn Top z (: (ca A) Top Top) (: (ca B) Bot Top)) v))))))
(test-predicate type-safety
(term
(valnew (v ((rfn Top z (: (ca L) Bot (rfn Top z (: (ca A) Bot Top) (: (ca B) Bot (sel z (ca A))))))))
(app (as (arrow (rfn Top z (: (ca L) Bot (rfn Top z (: (ca A) Bot Top) (: (ca B) Bot (sel z (ca A)))))) Top)
(fun x (rfn Top z (: (ca L) Bot (rfn Top z (: (ca A) Bot Top) (: (ca B) Bot Top)))) Top
(valnew (z ((rfn Top z (: (cm l)
((sel x (ca L))
∧
(rfn Top z (: (ca A) Bot (sel z (ca B))) (: (ca B) Bot Top)))
Top))
((cm l) y (as Top (fun a (sel y (ca A)) Top a)))))
(cast Top z))))
v))))
(check-not-false
(let ((Tc (term (rfn Top z
(: (ca A) (rfn Top z (: (cm m) Bot Top)) Top)
(: (ca B) Top Top)
(: (cm m) (sel z (ca A)) Top))))
(T (term (rfn Top z
(: (ca A) (rfn Top z (: (cm m) Bot Top)) Top)
(: (ca B) Top Top)
(: (cm m) (rfn (sel z (ca A)) z (: (ca B) Top Top)) Top)))))
(preservation
(term
(valnew (v (,Tc ((cm m) x (as Top x))))
(as Top
(sel (as ,T v)
(cm m)
v))))))
)
#;
(test-predicate preservation
(term
(valnew (a ((rfn Top z
(: (cc C) Bot (rfn Top z
(: (cc D) Bot (sel z (ca X)))
(: (ca X) Bot Top))))))
(valnew (b ((rfn (sel a (cc C)) z
(: (ca X) Bot Bot))))
(valnew (c ((sel a (cc C))))
(app (fun x (sel a (cc C)) Top
(valnew (d ((sel x (cc D))))
(app (fun x Bot Bot (sel x (cv foo)))
d)))
b))))))
(check-not-false
(let ((Tc (term (rfn Top z
(: (ca A) (rfn Top z (: (cm m) Bot Top)) Top)
(: (ca B) Top Top)
(: (cm m) (sel z (ca A)) Top))))
(T (term (rfn Top z
(: (ca A) (rfn Top z (: (cm m) Bot Top)) Top)
(: (ca B) Top Top)
(: (cm m) (rfn (sel z (ca A)) z (: (ca B) Top Top)) Top)))))
(preservation
(term
(valnew (v (,Tc ((cm m) x x)))
(valnew (u ((rfn Top z (: (cv v) ,Tc))
((cv v) v)))
(as Top
(sel (as ,T (sel u (cv v)))
(cm m)
(app (fun h ,T Top (as (rfn (sel h (ca A)) z (: (ca B) Top Top)) v))
(sel u (cv v))))))))))
)
(test-equal
(judgment-holds
(expansion (()())
self
(intersection (rfn Top a (: (cv l) Top))
(rfn Top b (: (cv l) Top)))
((DLt ...) (Dl ...) (Dm ...)))
((DLt ...) (Dl ...) (Dm ...)))
'((() ((: (cv l) Top)) ())))
(test-equal
(judgment-holds
(expansion (()())
self
(intersection (rfn Top a (: (cv l1) Top) (: (cv l3) Top))
(rfn Top b (: (cv l2) Top) (: (cv l3) Bot)))
((DLt ...) (Dl ...) (Dm ...)))
((DLt ...) (Dl ...) (Dm ...)))
'((() ((: (cv l1) Top) (: (cv l2) Top) (: (cv l3) Bot)) ())))
(test-results)
| false |
c0b67693d8c428442dd24c3abc99d1eaebb935c2 | 46244bb6af145cb393846505f37bf576a8396aa0 | /eopl/ch1/exercise-1.22.scm | 9654e8374dfe1597c4a140e272921abe61794aea | []
| no_license | aoeuidht/homework | c4fabfb5f45dbef0874e9732c7d026a7f00e13dc | 49fb2a2f8a78227589da3e5ec82ea7844b36e0e7 | refs/heads/master | 2022-10-28T06:42:04.343618 | 2022-10-15T15:52:06 | 2022-10-15T15:52:06 | 18,726,877 | 4 | 3 | null | null | null | null | UTF-8 | Scheme | false | false | 573 | scm | exercise-1.22.scm | #lang racket
#|
(filter-in pred lst) returns the list of those elements in lst that satisfy the predicate pred.
> (filter-in number? ’(a 2 (1 3) b 7))
(2 7)
> (filter-in symbol? ’(a (b c) 17 foo))
(a foo)
|#
; filter-in lambda X List --> List
(define (filter-in pred lst)
(if (null? lst)
'()
(if (pred (car lst))
(cons (car lst)
(filter-in pred (cdr lst)))
(filter-in pred (cdr lst)))))
(display (filter-in number? '(a 2 (1 3) b 7)))
(newline)
(display (filter-in symbol? '(a (b c) 17 foo)))
| false |
e4c44db38a1f07a579a4b3b4c3cee492b1e6aa30 | eef5f68873f7d5658c7c500846ce7752a6f45f69 | /spheres/io/ttyui.scm | 7c003ffc771436bfbcba1c2421a4df5e982bc21f | [
"MIT"
]
| permissive | alvatar/spheres | c0601a157ddce270c06b7b58473b20b7417a08d9 | 568836f234a469ef70c69f4a2d9b56d41c3fc5bd | refs/heads/master | 2021-06-01T15:59:32.277602 | 2021-03-18T21:21:43 | 2021-03-18T21:21:43 | 25,094,121 | 13 | 3 | null | null | null | null | UTF-8 | Scheme | false | false | 2,803 | scm | ttyui.scm | ;; File: "ttyui.scm", Time-stamp: <2007-04-05 00:54:59 feeley>
;; Modifications (REPL support), Alvaro Castro-Castilla, 2015
;;
;; Copyright (c) 2006-2007 by Marc Feeley, All Rights Reserved.
(define (flush-console-input port)
(input-port-timeout-set! port 0.001)
(let loop () (if (not (eof-object? (read-line port))) (loop)))
(input-port-timeout-set! port +inf.0))
(define (read-line-from-console)
(let ((port (console-port)))
(flush-console-input port)
(read-line port)))
(define (tty-read-line-ascii)
(let ((port (console-port)))
(flush-console-input port)
(let loop ((lst '()))
(let ((c (read-char port)))
(if (and (char? c)
(not (char=? c #\newline)))
(if (or (char<? c #\space) (char>? c #\~))
(loop lst)
(loop (cons c lst)))
(list->string (reverse lst)))))))
(define (tty-read-line-ascii-no-echo)
;; TODO: turn off echo!
(tty-read-line-ascii))
(define* (enter-y-or-n (prompt "y/n? "))
(let loop ()
(println prompt)
(let ((s (tty-read-line-ascii)))
(cond ((or (string=? s "n") (string=? s "N"))
#f)
((or (string=? s "y") (string=? s "Y"))
#t)
(else
(println "You must enter y or n. Please try again.")
(loop))))))
(define* (enter-line-ascii (prompt #f))
(if prompt (print prompt))
(tty-read-line-ascii))
(define* (enter-password (prompt "Password: "))
(print prompt)
(tty-read-line-ascii-no-echo))
(define (strong-password? password)
(let ((classes
(map (lambda (c)
(cond ((char-alphabetic? c) 'alphabetic)
((char-numeric? c) 'numeric)
(else 'special)))
(string->list password))))
(and (>= (string-length password) 8)
(memq 'alphabetic classes)
(memq 'numeric classes)
(memq 'special classes))))
(define* (enter-new-password (prompt "Password: "))
(let loop ()
(let ((password (enter-password prompt)))
(cond ((string=? password "")
#f)
((not (strong-password? password))
(print
"Password is weak.\n"
"Please enter a password with at least 8 characters, and which includes\n"
"a combination of letters, numerals and special characters.\n")
(loop))
(else
(println "Please retype for confirmation.")
(if (not (string=? password (enter-password prompt)))
(begin
(println "Password is not the same. Please try again.")
(loop))
password))))))
;;;=============================================================================
| false |
da0cc0733ea1a8dfb39e31ac5847f64f31bdad5b | f35a9a7a8437de2567c2d624638b85f45cb820c6 | /info/clojure/f/src/f/guile.scm | 1f6c303e336d4f55711de43af7f857988a619ecb | []
| no_license | pimgeek/f | 4566a6226d1d737edd6525cb52080a0c801e5f8a | 85f1de5f1db10e0200d116a7fac4a6e55a6f7226 | refs/heads/master | 2020-05-20T07:19:36.520914 | 2015-12-27T02:15:37 | 2015-12-27T02:15:37 | 6,584,817 | 0 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 301 | scm | guile.scm | #!/usr/bin/guile
!#
(define atom?
(lambda (x)
(and (not (pair? x)) (not (null? x)))))
(define lat?
(lambda (l)
(cond
((null? l) #t)
((atom? (car l)) (lat? (cdr l)))
(else #f))))
(atom? 'a)
(atom? '())
(atom? '(a b))
; (lat? 'a)
(lat? '())
(lat? '(a b))
(lat? '(a (b)))
| false |
f059910ed90115ebf987bdc757559c6400cbd35c | f08220a13ec5095557a3132d563a152e718c412f | /logrotate/skel/usr/share/guile/2.0/texinfo/docbook.scm | f3f993db85417f71d383f9c4dc9c996d8ff5a80d | [
"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 | 8,621 | scm | docbook.scm | ;;;; (texinfo docbook) -- translating sdocbook into stexinfo
;;;;
;;;; Copyright (C) 2009, 2010, 2012 Free Software Foundation, Inc.
;;;; Copyright (C) 2007, 2009 Andy Wingo <wingo at pobox dot com>
;;;;
;;;; 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
;;;;
;;; Commentary:
;;
;; @c
;; This module exports procedures for transforming a limited subset of
;; the SXML representation of docbook into stexi. It is not complete by
;; any means. The intention is to gather a number of routines and
;; stylesheets so that external modules can parse specific subsets of
;; docbook, for example that set generated by certain tools.
;;
;;; Code:
(define-module (texinfo docbook)
#:use-module (sxml fold)
#:use-module ((srfi srfi-1) #:select (fold))
#:export (*sdocbook->stexi-rules*
*sdocbook-block-commands*
sdocbook-flatten
filter-empty-elements
replace-titles))
(define (identity . args)
args)
(define (identity-deattr tag . body)
`(,tag ,@(if (and (pair? body) (pair? (car body))
(eq? (caar body) '@))
(cdr body)
body)))
(define (detag-one tag body)
body)
(define tag-replacements
'((parameter var)
(replaceable var)
(type code)
(function code)
(literal samp)
(emphasis emph)
(simpara para)
(programlisting example)
(firstterm dfn)
(filename file)
(quote cite)
(application cite)
(symbol code)
(note cartouche)
(envar env)))
(define ignore-list '())
(define (stringify exp)
(with-output-to-string (lambda () (write exp))))
(define *sdocbook->stexi-rules*
#;
"A stylesheet for use with SSAX's @code{pre-post-order}, which defines
a number of generic rules for transforming docbook into texinfo."
`((@ *preorder* . ,identity)
(% *preorder* . ,identity)
(para . ,identity-deattr)
(orderedlist ((listitem
. ,(lambda (tag . body)
`(item ,@body))))
. ,(lambda (tag . body)
`(enumerate ,@body)))
(itemizedlist ((listitem
. ,(lambda (tag . body)
`(item ,@body))))
. ,(lambda (tag . body)
`(itemize ,@body)))
(acronym . ,(lambda (tag . body)
`(acronym (% (acronym . ,body)))))
(term . ,detag-one)
(informalexample . ,detag-one)
(section . ,identity)
(subsection . ,identity)
(subsubsection . ,identity)
(ulink . ,(lambda (tag attrs . body)
(cond
((assq 'url (cdr attrs))
=> (lambda (url)
`(uref (% ,url (title ,@body)))))
(else
(car body)))))
(*text* . ,detag-one)
(*default* . ,(lambda (tag . body)
(let ((subst (assq tag tag-replacements)))
(cond
(subst
(if (and (pair? body) (pair? (car body)) (eq? (caar body) '@))
(begin
(warn "Ignoring" tag "attributes" (car body))
(append (cdr subst) (cdr body)))
(append (cdr subst) body)))
((memq tag ignore-list) #f)
(else
(warn "Don't know how to convert" tag "to stexi")
`(c (% (all ,(stringify (cons tag body))))))))))))
;; (variablelist
;; ((varlistentry
;; . ,(lambda (tag term . body)
;; `(entry (% (heading ,@(cdr term))) ,@body)))
;; (listitem
;; . ,(lambda (tag simpara)
;; simpara)))
;; . ,(lambda (tag attrs . body)
;; `(table (% (formatter (var))) ,@body)))
(define *sdocbook-block-commands*
#;
"The set of sdocbook element tags that should not be nested inside
each other. @xref{texinfo docbook sdocbook-flatten,,sdocbook-flatten},
for more information."
'(para programlisting informalexample indexterm variablelist
orderedlist refsect1 refsect2 refsect3 refsect4 title example
note itemizedlist informaltable))
(define (inline-command? command)
(not (memq command *sdocbook-block-commands*)))
(define (sdocbook-flatten sdocbook)
"\"Flatten\" a fragment of sdocbook so that block elements do not nest
inside each other.
Docbook is a nested format, where e.g. a @code{refsect2} normally
appears inside a @code{refsect1}. Logical divisions in the document are
represented via the tree topology; a @code{refsect2} element
@emph{contains} all of the elements in its section.
On the contrary, texinfo is a flat format, in which sections are marked
off by standalone section headers like @code{@@chapter}, and block
elements do not nest inside each other.
This function takes a nested sdocbook fragment @var{sdocbook} and
flattens all of the sections, such that e.g.
@example
(refsect1 (refsect2 (para \"Hello\")))
@end example
becomes
@example
((refsect1) (refsect2) (para \"Hello\"))
@end example
Oftentimes (always?) sectioning elements have @code{<title>} as their
first element child; users interested in processing the @code{refsect*}
elements into proper sectioning elements like @code{chapter} might be
interested in @code{replace-titles} and @code{filter-empty-elements}.
@xref{texinfo docbook replace-titles,,replace-titles}, and @ref{texinfo
docbook filter-empty-elements,,filter-empty-elements}.
Returns a nodeset, as described in @ref{sxml xpath}. That is to say,
this function returns an untagged list of stexi elements."
(define (fhere str accum block cont)
(values (cons str accum)
block
cont))
(define (fdown node accum block cont)
(let ((command (car node))
(attrs (and (pair? (cdr node)) (pair? (cadr node))
(eq? (caadr node) '%)
(cadr node))))
(values (if attrs (cddr node) (cdr node))
'()
'()
(lambda (accum block)
(values
`(,command ,@(if attrs (list attrs) '())
,@(reverse accum))
block)))))
(define (fup node paccum pblock pcont kaccum kblock kcont)
(call-with-values (lambda () (kcont kaccum kblock))
(lambda (ret block)
(if (inline-command? (car ret))
(values (cons ret paccum) (append kblock pblock) pcont)
(values paccum (append kblock (cons ret pblock)) pcont)))))
(call-with-values
(lambda () (foldts*-values fdown fup fhere sdocbook '() '() #f))
(lambda (accum block cont)
(reverse block))))
(define (filter-empty-elements sdocbook)
"Filters out empty elements in an sdocbook nodeset. Mostly useful
after running @code{sdocbook-flatten}."
(reverse
(fold
(lambda (x rest)
(if (and (pair? x) (null? (cdr x)))
rest
(cons x rest)))
'()
sdocbook)))
(define (replace-titles sdocbook-fragment)
"Iterate over the sdocbook nodeset @var{sdocbook-fragment},
transforming contiguous @code{refsect} and @code{title} elements into
the appropriate texinfo sectioning command. Most useful after having run
@code{sdocbook-flatten}.
For example:
@example
(replace-titles '((refsect1) (title \"Foo\") (para \"Bar.\")))
@result{} '((chapter \"Foo\") (para \"Bar.\"))
@end example
"
(define sections '((refsect1 . chapter)
(refsect2 . section)
(refsect3 . subsection)
(refsect4 . subsubsection)))
(let lp ((in sdocbook-fragment) (out '()))
(cond
((null? in)
(reverse out))
((and (pair? (car in)) (assq (caar in) sections))
;; pull out the title
=> (lambda (pair)
(lp (cddr in) (cons `(,(cdr pair) ,@(cdadr in)) out))))
(else
(lp (cdr in) (cons (car in) out))))))
| false |
2e4f2f1bfbb404a967b737c3851d991491148d68 | db0567d04297eb710cd4ffb7af094d82b2f66662 | /scheme/ikarus.bytevectors.ss | 5c0b24ccf33d592942443ed766706660aa4cfaef | []
| 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 | 48,989 | ss | ikarus.bytevectors.ss | (library (ikarus bytevectors)
(export
make-bytevector bytevector-length bytevector-s8-ref
bytevector-u8-ref bytevector-u8-set! bytevector-s8-set!
bytevector-copy! u8-list->bytevector bytevector->u8-list
bytevector-u16-native-ref bytevector-u16-native-set!
bytevector-s16-native-ref bytevector-s16-native-set!
bytevector-u32-native-ref bytevector-u32-native-set!
bytevector-s32-native-ref bytevector-s32-native-set!
bytevector-u64-native-ref bytevector-u64-native-set!
bytevector-s64-native-ref bytevector-s64-native-set!
bytevector-u16-ref bytevector-u16-set!
bytevector-s16-ref bytevector-s16-set!
bytevector-u32-ref bytevector-u32-set!
bytevector-s32-ref bytevector-s32-set!
bytevector-u64-ref bytevector-u64-set!
bytevector-s64-ref bytevector-s64-set!
bytevector-fill! bytevector-copy bytevector=?
bytevector-uint-ref bytevector-sint-ref
bytevector-uint-set! bytevector-sint-set!
bytevector->uint-list bytevector->sint-list
uint-list->bytevector sint-list->bytevector
bytevector-ieee-double-native-ref bytevector-ieee-double-native-set!
bytevector-ieee-single-native-ref bytevector-ieee-single-native-set!
bytevector-ieee-double-ref bytevector-ieee-double-set!
bytevector-ieee-single-ref bytevector-ieee-single-set!
native-endianness)
(import
(except (ikarus)
make-bytevector bytevector-length bytevector-s8-ref
bytevector-u8-ref bytevector-u8-set! bytevector-s8-set!
bytevector-copy! u8-list->bytevector bytevector->u8-list
bytevector-u16-native-ref bytevector-u16-native-set!
bytevector-s16-native-ref bytevector-s16-native-set!
bytevector-u32-native-ref bytevector-u32-native-set!
bytevector-s32-native-ref bytevector-s32-native-set!
bytevector-u64-native-ref bytevector-u64-native-set!
bytevector-s64-native-ref bytevector-s64-native-set!
bytevector-u16-ref bytevector-u16-set!
bytevector-s16-ref bytevector-s16-set!
bytevector-u32-ref bytevector-u32-set!
bytevector-s32-ref bytevector-s32-set!
bytevector-u64-ref bytevector-u64-set!
bytevector-s64-ref bytevector-s64-set!
bytevector-fill! bytevector-copy bytevector=?
bytevector-uint-ref bytevector-sint-ref
bytevector-uint-set! bytevector-sint-set!
bytevector->uint-list bytevector->sint-list
uint-list->bytevector sint-list->bytevector
bytevector-ieee-double-native-ref bytevector-ieee-double-native-set!
bytevector-ieee-double-ref bytevector-ieee-double-set!
bytevector-ieee-single-native-ref bytevector-ieee-single-native-set!
bytevector-ieee-single-ref bytevector-ieee-single-set!
native-endianness)
(ikarus system $fx)
(ikarus system $bignums)
(ikarus system $pairs)
(ikarus system $bytevectors))
(define (native-endianness) 'little) ;;; HARDCODED
(define ($bytevector-fill x i j fill)
(cond
[($fx= i j) x]
[else
($bytevector-set! x i fill)
($bytevector-fill x ($fxadd1 i) j fill)]))
(define make-bytevector
(case-lambda
[(k)
(if (and (fixnum? k) ($fx>= k 0))
($make-bytevector k)
(die 'make-bytevector "not a valid size" k))]
[(k fill)
(if (and (fixnum? fill) ($fx<= -128 fill) ($fx<= fill 255))
($bytevector-fill (make-bytevector k) 0 k fill)
(die 'make-bytevector "not a valid fill" fill))]))
(define bytevector-fill!
(lambda (x fill)
(unless (bytevector? x)
(die 'bytevector-fill! "not a bytevector" x))
(unless (and (fixnum? fill) ($fx<= -128 fill) ($fx<= fill 255))
(die 'bytevector-fill! "not a valid fill" fill))
($bytevector-fill x 0 ($bytevector-length x) fill)))
(define bytevector-length
(lambda (x)
(if (bytevector? x)
($bytevector-length x)
(die 'bytevector-length "not a bytevector" x))))
(define bytevector-s8-ref
(lambda (x i)
(if (bytevector? x)
(if (and (fixnum? i) ($fx<= 0 i) ($fx< i ($bytevector-length x)))
($bytevector-s8-ref x i)
(die 'bytevector-s8-ref "invalid index" i x))
(die 'bytevector-s8-ref "not a bytevector" x))))
(define bytevector-u8-ref
(lambda (x i)
(if (bytevector? x)
(if (and (fixnum? i) ($fx<= 0 i) ($fx< i ($bytevector-length x)))
($bytevector-u8-ref x i)
(die 'bytevector-u8-ref "invalid index" i x))
(die 'bytevector-u8-ref "not a bytevector" x))))
(define bytevector-s8-set!
(lambda (x i v)
(if (bytevector? x)
(if (and (fixnum? i) ($fx<= 0 i) ($fx< i ($bytevector-length x)))
(if (and (fixnum? v) ($fx<= -128 v) ($fx<= v 127))
($bytevector-set! x i v)
(die 'bytevector-s8-set! "not a byte" v))
(die 'bytevector-s8-set! "invalid index" i x))
(die 'bytevector-s8-set! "not a bytevector" x))))
(define bytevector-u8-set!
(lambda (x i v)
(if (bytevector? x)
(if (and (fixnum? i) ($fx<= 0 i) ($fx< i ($bytevector-length x)))
(if (and (fixnum? v) ($fx<= 0 v) ($fx<= v 255))
($bytevector-set! x i v)
(die 'bytevector-u8-set! "not an octet" v))
(die 'bytevector-u8-set! "invalid index" i x))
(die 'bytevector-u8-set! "not a bytevector" x))))
(define bytevector-u16-native-ref ;;; HARDCODED
(lambda (x i)
(if (bytevector? x)
(if (and (fixnum? i)
($fx<= 0 i)
($fx< i ($fxsub1 ($bytevector-length x)))
($fxzero? ($fxlogand i 1)))
($fxlogor ;;; little
($bytevector-u8-ref x i)
($fxsll ($bytevector-u8-ref x ($fxadd1 i)) 8))
(die 'bytevector-u16-native-ref "invalid index" i))
(die 'bytevector-u16-native-ref "not a bytevector" x))))
(define bytevector-u16-native-set! ;;; HARDCODED
(lambda (x i n)
(if (bytevector? x)
(if (and (fixnum? n)
($fx<= 0 n)
($fx<= n #xFFFF))
(if (and (fixnum? i)
($fx<= 0 i)
($fx< i ($fxsub1 ($bytevector-length x)))
($fxzero? ($fxlogand i 1)))
(begin ;;; little
($bytevector-set! x i n)
($bytevector-set! x ($fxadd1 i) ($fxsra n 8)))
(die 'bytevector-u16-native-set! "invalid index" i))
(die 'bytevector-u16-native-set! "invalid value" n))
(die 'bytevector-u16-native-set! "not a bytevector" x))))
(define bytevector-s16-native-set! ;;; HARDCODED
(lambda (x i n)
(if (bytevector? x)
(if (and (fixnum? n)
($fx<= #x-8000 n)
($fx<= n #x7FFF))
(if (and (fixnum? i)
($fx<= 0 i)
($fx< i ($fxsub1 ($bytevector-length x)))
($fxzero? ($fxlogand i 1)))
(begin ;;; little
($bytevector-set! x i n)
($bytevector-set! x ($fxadd1 i) ($fxsra n 8)))
(die 'bytevector-s16-native-set! "invalid index" i))
(die 'bytevector-s16-native-set! "invalid value" n))
(die 'bytevector-s16-native-set! "not a bytevector" x))))
(define bytevector-s16-native-ref ;;; HARDCODED
(lambda (x i)
(if (bytevector? x)
(if (and (fixnum? i)
($fx<= 0 i)
($fx< i ($fxsub1 ($bytevector-length x)))
($fxzero? ($fxlogand i 1)))
($fxlogor ;;; little
($bytevector-u8-ref x i)
($fxsll ($bytevector-s8-ref x ($fxadd1 i)) 8))
(die 'bytevector-s16-native-ref "invalid index" i))
(die 'bytevector-s16-native-ref "not a bytevector" x))))
(define bytevector-u16-ref
(lambda (x i end)
(if (bytevector? x)
(if (and (fixnum? i)
($fx<= 0 i)
($fx< i ($fxsub1 ($bytevector-length x))))
(case end
[(big)
($fxlogor
($fxsll ($bytevector-u8-ref x i) 8)
($bytevector-u8-ref x ($fxadd1 i)))]
[(little)
($fxlogor
($fxsll ($bytevector-u8-ref x (fxadd1 i)) 8)
($bytevector-u8-ref x i))]
[else (die 'bytevector-u16-ref "invalid endianness" end)])
(die 'bytevector-u16-ref "invalid index" i))
(die 'bytevector-u16-ref "not a bytevector" x))))
(define bytevector-u32-ref
(lambda (x i end)
(if (bytevector? x)
(if (and (fixnum? i)
($fx<= 0 i)
($fx< i ($fx- ($bytevector-length x) 3)))
(case end
[(big)
(+ (sll ($bytevector-u8-ref x i) 24)
($fxlogor
($fxsll ($bytevector-u8-ref x ($fx+ i 1)) 16)
($fxlogor
($fxsll ($bytevector-u8-ref x ($fx+ i 2)) 8)
($bytevector-u8-ref x ($fx+ i 3)))))]
[(little)
(+ (sll ($bytevector-u8-ref x ($fx+ i 3)) 24)
($fxlogor
($fxsll ($bytevector-u8-ref x ($fx+ i 2)) 16)
($fxlogor
($fxsll ($bytevector-u8-ref x ($fx+ i 1)) 8)
($bytevector-u8-ref x i))))]
[else (die 'bytevector-u32-ref "invalid endianness" end)])
(die 'bytevector-u32-ref "invalid index" i))
(die 'bytevector-u32-ref "not a bytevector" x))))
(define bytevector-u32-native-ref
(lambda (x i)
(if (bytevector? x)
(if (and (fixnum? i)
($fx<= 0 i)
($fx= 0 ($fxlogand i 3))
($fx< i ($fx- ($bytevector-length x) 3)))
(+ (sll ($bytevector-u8-ref x ($fx+ i 3)) 24)
($fxlogor
($fxsll ($bytevector-u8-ref x ($fx+ i 2)) 16)
($fxlogor
($fxsll ($bytevector-u8-ref x ($fx+ i 1)) 8)
($bytevector-u8-ref x i))))
(die 'bytevector-u32-native-ref "invalid index" i))
(die 'bytevector-u32-native-ref "not a bytevector" x))))
(define bytevector-s32-ref
(lambda (x i end)
(if (bytevector? x)
(if (and (fixnum? i)
($fx<= 0 i)
($fx< i ($fx- ($bytevector-length x) 3)))
(case end
[(big)
(+ (sll ($bytevector-s8-ref x i) 24)
($fxlogor
($fxsll ($bytevector-u8-ref x ($fx+ i 1)) 16)
($fxlogor
($fxsll ($bytevector-u8-ref x ($fx+ i 2)) 8)
($bytevector-u8-ref x ($fx+ i 3)))))]
[(little)
(+ (sll ($bytevector-s8-ref x ($fx+ i 3)) 24)
($fxlogor
($fxsll ($bytevector-u8-ref x ($fx+ i 2)) 16)
($fxlogor
($fxsll ($bytevector-u8-ref x ($fx+ i 1)) 8)
($bytevector-u8-ref x i))))]
[else (die 'bytevector-s32-ref "invalid endianness" end)])
(die 'bytevector-s32-ref "invalid index" i))
(die 'bytevector-s32-ref "not a bytevector" x))))
(define bytevector-s32-native-ref
(lambda (x i)
(if (bytevector? x)
(if (and (fixnum? i)
($fx<= 0 i)
($fx= 0 ($fxlogand i 3))
($fx< i ($fx- ($bytevector-length x) 3)))
(+ (sll ($bytevector-s8-ref x ($fx+ i 3)) 24)
($fxlogor
($fxsll ($bytevector-u8-ref x ($fx+ i 2)) 16)
($fxlogor
($fxsll ($bytevector-u8-ref x ($fx+ i 1)) 8)
($bytevector-u8-ref x i))))
(die 'bytevector-s32-native-ref "invalid index" i))
(die 'bytevector-s32-native-ref "not a bytevector" x))))
(define bytevector-u16-set!
(lambda (x i n end)
(if (bytevector? x)
(if (and (fixnum? n)
($fx<= 0 n)
($fx<= n #xFFFF))
(if (and (fixnum? i)
($fx<= 0 i)
($fx< i ($fxsub1 ($bytevector-length x))))
(case end
[(big)
($bytevector-set! x i ($fxsra n 8))
($bytevector-set! x ($fxadd1 i) n)]
[(little)
($bytevector-set! x i n)
($bytevector-set! x ($fxadd1 i) (fxsra n 8))]
[else (die 'bytevector-u16-ref "invalid endianness" end)])
(die 'bytevector-u16-set! "invalid index" i))
(die 'bytevector-u16-set! "invalid value" n))
(die 'bytevector-u16-set! "not a bytevector" x))))
(define bytevector-u32-set!
(lambda (x i n end)
(if (bytevector? x)
(if (if (fixnum? n)
($fx>= n 0)
(if (bignum? n)
(<= 0 n #xFFFFFFFF)
#f))
(if (and (fixnum? i)
($fx<= 0 i)
($fx< i ($fx- ($bytevector-length x) 3)))
(case end
[(big)
(let ([b (sra n 16)])
($bytevector-set! x i ($fxsra b 8))
($bytevector-set! x ($fx+ i 1) b))
(let ([b (bitwise-and n #xFFFF)])
($bytevector-set! x ($fx+ i 2) ($fxsra b 8))
($bytevector-set! x ($fx+ i 3) b))]
[(little)
(let ([b (sra n 16)])
($bytevector-set! x ($fx+ i 3) ($fxsra b 8))
($bytevector-set! x ($fx+ i 2) b))
(let ([b (bitwise-and n #xFFFF)])
($bytevector-set! x ($fx+ i 1) ($fxsra b 8))
($bytevector-set! x i b))]
[else (die 'bytevector-u32-ref "invalid endianness" end)])
(die 'bytevector-u32-set! "invalid index" i))
(die 'bytevector-u32-set! "invalid value" n))
(die 'bytevector-u32-set! "not a bytevector" x))))
(define bytevector-u32-native-set!
(lambda (x i n)
(if (bytevector? x)
(if (if (fixnum? n)
($fx>= n 0)
(if (bignum? n)
(<= 0 n #xFFFFFFFF)
#f))
(if (and (fixnum? i)
($fx<= 0 i)
($fx= 0 ($fxlogand i 3))
($fx< i ($fx- ($bytevector-length x) 3)))
(begin
(let ([b (sra n 16)])
($bytevector-set! x ($fx+ i 3) ($fxsra b 8))
($bytevector-set! x ($fx+ i 2) b))
(let ([b (bitwise-and n #xFFFF)])
($bytevector-set! x ($fx+ i 1) ($fxsra b 8))
($bytevector-set! x i b)))
(die 'bytevector-u32-native-set! "invalid index" i))
(die 'bytevector-u32-native-set! "invalid value" n))
(die 'bytevector-u32-native-set! "not a bytevector" x))))
(define bytevector-s32-native-set!
(lambda (x i n)
(if (bytevector? x)
(if (if (fixnum? n)
#t
(if (bignum? n)
(<= #x-80000000 n #x7FFFFFFF)
#f))
(if (and (fixnum? i)
($fx<= 0 i)
($fx= 0 ($fxlogand i 3))
($fx< i ($fx- ($bytevector-length x) 3)))
(begin
(let ([b (sra n 16)])
($bytevector-set! x ($fx+ i 3) ($fxsra b 8))
($bytevector-set! x ($fx+ i 2) b))
(let ([b (bitwise-and n #xFFFF)])
($bytevector-set! x ($fx+ i 1) ($fxsra b 8))
($bytevector-set! x i b)))
(die 'bytevector-s32-native-set! "invalid index" i))
(die 'bytevector-s32-native-set! "invalid value" n))
(die 'bytevector-s32-native-set! "not a bytevector" x))))
(define bytevector-s32-set!
(lambda (x i n end)
(if (bytevector? x)
(if (if (fixnum? n)
#t
(if (bignum? n)
(<= #x-80000000 n #x7FFFFFFF)
#f))
(if (and (fixnum? i)
($fx<= 0 i)
($fx< i ($fx- ($bytevector-length x) 3)))
(case end
[(big)
(let ([b (sra n 16)])
($bytevector-set! x i ($fxsra b 8))
($bytevector-set! x ($fx+ i 1) b))
(let ([b (bitwise-and n #xFFFF)])
($bytevector-set! x ($fx+ i 2) ($fxsra b 8))
($bytevector-set! x ($fx+ i 3) b))]
[(little)
(let ([b (sra n 16)])
($bytevector-set! x ($fx+ i 3) ($fxsra b 8))
($bytevector-set! x ($fx+ i 2) b))
(let ([b (bitwise-and n #xFFFF)])
($bytevector-set! x ($fx+ i 1) ($fxsra b 8))
($bytevector-set! x i b))]
[else (die 'bytevector-s32-ref "invalid endianness" end)])
(die 'bytevector-s32-set! "invalid index" i))
(die 'bytevector-s32-set! "invalid value" n))
(die 'bytevector-s32-set! "not a bytevector" x))))
(define bytevector-s16-ref
(lambda (x i end)
(if (bytevector? x)
(if (and (fixnum? i)
($fx<= 0 i)
($fx< i ($fxsub1 ($bytevector-length x))))
(case end
[(big)
($fxlogor
($fxsll ($bytevector-s8-ref x i) 8)
($bytevector-u8-ref x ($fxadd1 i)))]
[(little)
($fxlogor
($fxsll ($bytevector-s8-ref x (fxadd1 i)) 8)
($bytevector-u8-ref x i))]
[else (die 'bytevector-s16-ref "invalid endianness" end)])
(die 'bytevector-s16-ref "invalid index" i))
(die 'bytevector-s16-ref "not a bytevector" x))))
(define bytevector-s16-set!
(lambda (x i n end)
(if (bytevector? x)
(if (and (fixnum? n)
($fx<= #x-8000 n)
($fx<= n #x7FFF))
(if (and (fixnum? i)
($fx<= 0 i)
($fx< i ($fxsub1 ($bytevector-length x))))
(case end
[(big)
($bytevector-set! x i ($fxsra n 8))
($bytevector-set! x ($fxadd1 i) n)]
[(little)
($bytevector-set! x i n)
($bytevector-set! x ($fxadd1 i) (fxsra n 8))]
[else (die 'bytevector-s16-ref "invalid endianness" end)])
(die 'bytevector-s16-set! "invalid index" i))
(die 'bytevector-s16-set! "invalid value" n))
(die 'bytevector-s16-set! "not a bytevector" x))))
(define bytevector->u8-list
(lambda (x)
(unless (bytevector? x)
(die 'bytevector->u8-list "not a bytevector" x))
(let f ([x x] [i ($bytevector-length x)] [ac '()])
(cond
[($fx= i 0) ac]
[else
(let ([i ($fxsub1 i)])
(f x i (cons ($bytevector-u8-ref x i) ac)))]))))
(define u8-list->bytevector
(letrec ([race
(lambda (h t ls n)
(if (pair? h)
(let ([h ($cdr h)])
(if (pair? h)
(if (not (eq? h t))
(race ($cdr h) ($cdr t) ls ($fx+ n 2))
(die 'u8-list->bytevector "circular list" ls))
(if (null? h)
($fx+ n 1)
(die 'u8-list->bytevector "not a proper list" ls))))
(if (null? h)
n
(die 'u8-list->bytevector "not a proper list" ls))))]
[fill
(lambda (s i ls)
(cond
[(null? ls) s]
[else
(let ([c ($car ls)])
(unless (and (fixnum? c) ($fx<= 0 c) ($fx<= c 255))
(die 'u8-list->bytevector "not an octet" c))
($bytevector-set! s i c)
(fill s ($fxadd1 i) (cdr ls)))]))])
(lambda (ls)
(let ([n (race ls ls ls 0)])
(let ([s ($make-bytevector n)])
(fill s 0 ls))))))
(define bytevector-copy
(lambda (src)
(unless (bytevector? src)
(die 'bytevector-copy "not a bytevector" src))
(let ([n ($bytevector-length src)])
(let f ([src src] [dst ($make-bytevector n)] [i 0] [n n])
(cond
[($fx= i n) dst]
[else
($bytevector-set! dst i ($bytevector-u8-ref src i))
(f src dst ($fxadd1 i) n)])))))
(define bytevector=?
(lambda (x y)
(unless (bytevector? x)
(die 'bytevector=? "not a bytevector" x))
(unless (bytevector? y)
(die 'bytevector=? "not a bytevector" y))
(let ([n ($bytevector-length x)])
(and ($fx= n ($bytevector-length y))
(let f ([x x] [y y] [i 0] [n n])
(or ($fx= i n)
(and ($fx= ($bytevector-u8-ref x i)
($bytevector-u8-ref y i))
(f x y ($fxadd1 i) n))))))))
(define bytevector-copy!
(lambda (src src-start dst dst-start k)
(cond
[(or (not (fixnum? src-start)) ($fx< src-start 0))
(die 'bytevector-copy! "not a valid starting index" src-start)]
[(or (not (fixnum? dst-start)) ($fx< dst-start 0))
(die 'bytevector-copy! "not a valid starting index" dst-start)]
[(or (not (fixnum? k)) ($fx< k 0))
(die 'bytevector-copy! "not a valid length" k)]
[(not (bytevector? src))
(die 'bytevector-copy! "not a bytevector" src)]
[(not (bytevector? dst))
(die 'bytevector-copy! "not a bytevector" dst)]
[(let ([n ($fx+ src-start k)])
(or ($fx< n 0) ($fx> n ($bytevector-length src))))
(die 'bytevector-copy! "out of range" src-start k)]
[(let ([n ($fx+ dst-start k)])
(or ($fx< n 0) ($fx> n ($bytevector-length dst))))
(die 'bytevector-copy! "out of range" dst-start k)]
[(eq? src dst)
(cond
[($fx< dst-start src-start)
(let f ([src src] [si src-start] [di dst-start] [sj ($fx+ src-start k)])
(unless ($fx= si sj)
($bytevector-set! src di ($bytevector-u8-ref src si))
(f src ($fxadd1 si) ($fxadd1 di) sj)))]
[($fx< src-start dst-start)
(let f ([src src] [si ($fx+ src-start k)] [di ($fx+ dst-start k)] [sj src-start])
(unless ($fx= si sj)
(let ([si ($fxsub1 si)] [di ($fxsub1 di)])
($bytevector-set! src di ($bytevector-u8-ref src si))
(f src si di sj))))]
[else (void)])]
[else
(let f ([src src] [si src-start] [dst dst] [di dst-start] [sj ($fx+ src-start k)])
(unless ($fx= si sj)
($bytevector-set! dst di ($bytevector-u8-ref src si))
(f src ($fxadd1 si) dst ($fxadd1 di) sj)))])))
(module (bytevector-uint-ref bytevector-sint-ref
bytevector->uint-list bytevector->sint-list)
(define (uref-big x ib il) ;; ib included, il excluded
(cond
[($fx= il ib) 0]
[else
(let ([b ($bytevector-u8-ref x ib)])
(cond
[($fx= b 0) (uref-big x ($fxadd1 ib) il)]
[else
(case ($fx- il ib)
[(1) b]
[(2) ($fx+ ($fxsll b 8)
($bytevector-u8-ref x ($fxsub1 il)))]
[(3)
($fx+ ($fxsll ($fx+ ($fxsll b 8)
($bytevector-u8-ref x ($fxadd1 ib)))
8)
($bytevector-u8-ref x ($fxsub1 il)))]
[else
(let ([im ($fxsra ($fx+ il ib) 1)])
(+ (uref-big x im il)
(* (uref-big x ib im)
(expt 256 ($fx- il im)))))])]))]))
(define (uref-little x il ib) ;; il included, ib excluded
(cond
[($fx= il ib) 0]
[else
(let ([ib^ ($fxsub1 ib)])
(let ([b ($bytevector-u8-ref x ib^)])
(cond
[($fx= b 0) (uref-little x il ib^)]
[else
(case ($fx- ib il)
[(1) b]
[(2) ($fx+ ($fxsll b 8) ($bytevector-u8-ref x il))]
[(3)
($fx+ ($fxsll ($fx+ ($fxsll b 8)
($bytevector-u8-ref x ($fxadd1 il)))
8)
($bytevector-u8-ref x il))]
[else
(let ([im ($fxsra ($fx+ il ib) 1)])
(+ (uref-little x il im)
(* (uref-little x im ib)
(expt 256 ($fx- im il)))))])])))]))
(define (sref-big x ib il) ;; ib included, il excluded
(cond
[($fx= il ib) -1]
[else
(let ([b ($bytevector-u8-ref x ib)])
(cond
[($fx= b 0) (uref-big x ($fxadd1 ib) il)]
[($fx= b 255) (sref-big-neg x ($fxadd1 ib) il)]
[($fx< b 128) (uref-big x ib il)]
[else (- (uref-big x ib il) (expt 256 ($fx- il ib)))]))]))
(define (sref-big-neg x ib il) ;; ib included, il excluded
(cond
[($fx= il ib) -1]
[else
(let ([b ($bytevector-u8-ref x ib)])
(cond
[($fx= b 255) (sref-big-neg x ($fxadd1 ib) il)]
[else (- (uref-big x ib il) (expt 256 ($fx- il ib)))]))]))
(define (sref-little x il ib) ;; il included, ib excluded
(cond
[($fx= il ib) -1]
[else
(let ([ib^ ($fxsub1 ib)])
(let ([b ($bytevector-u8-ref x ib^)])
(cond
[($fx= b 0) (uref-little x il ib^)]
[($fx= b 255) (sref-little-neg x il ib^)]
[($fx< b 128) (uref-little x il ib)]
[else (- (uref-little x il ib) (expt 256 ($fx- ib il)))])))]))
(define (sref-little-neg x il ib) ;; il included, ib excluded
(cond
[($fx= il ib) -1]
[else
(let ([ib^ ($fxsub1 ib)])
(let ([b ($bytevector-u8-ref x ib^)])
(cond
[($fx= b 255) (sref-little-neg x il ib^)]
[else (- (uref-little x il ib) (expt 256 ($fx- ib il)))])))]))
(define bytevector-sint-ref
(lambda (x k endianness size)
(define who 'bytevector-sint-ref)
(unless (bytevector? x) (die who "not a bytevector" x))
(unless (and (fixnum? k) ($fx>= k 0)) (die who "invalid index" k))
(unless (and (fixnum? size) ($fx>= size 1)) (die who "invalid size" size))
(let ([n ($bytevector-length x)])
(unless ($fx< k n) (die who "index is out of range" k))
(let ([end ($fx+ k size)])
(unless (and ($fx>= end 0) ($fx<= end n))
(die who "out of range" k size))
(case endianness
[(little) (sref-little x k end)]
[(big) (sref-big x k end)]
[else (die who "invalid endianness" endianness)])))))
(define bytevector-uint-ref
(lambda (x k endianness size)
(define who 'bytevector-uint-ref)
(unless (bytevector? x) (die who "not a bytevector" x))
(unless (and (fixnum? k) ($fx>= k 0)) (die who "invalid index" k))
(unless (and (fixnum? size) ($fx>= size 1)) (die who "invalid size" size))
(let ([n ($bytevector-length x)])
(unless ($fx< k n) (die who "index is out of range" k))
(let ([end ($fx+ k size)])
(unless (and ($fx>= end 0) ($fx<= end n))
(die who "out of range" k size))
(case endianness
[(little) (uref-little x k end)]
[(big) (uref-big x k end)]
[else (die who "invalid endianness" endianness)])))))
(define (bytevector->some-list x k n ls proc who)
(cond
[($fx= n 0) ls]
[else
(let ([i ($fx- n k)])
(cond
[($fx>= i 0)
(bytevector->some-list x k i (cons (proc x i n) ls) proc who)]
[else
(die who "invalid size" k)]))]))
(define bytevector->uint-list
(lambda (x endianness size)
(define who 'bytevector->uint-list)
(unless (bytevector? x) (die who "not a bytevector" x))
(unless (and (fixnum? size) ($fx>= size 1)) (die who "invalid size" size))
(case endianness
[(little) (bytevector->some-list x size ($bytevector-length x)
'() uref-little 'bytevector->uint-list)]
[(big) (bytevector->some-list x size ($bytevector-length x)
'() uref-big 'bytevector->uint-list)]
[else (die who "invalid endianness" endianness)])))
(define bytevector->sint-list
(lambda (x endianness size)
(define who 'bytevector->sint-list)
(unless (bytevector? x) (die who "not a bytevector" x))
(unless (and (fixnum? size) ($fx>= size 1)) (die who "invalid size" size))
(case endianness
[(little) (bytevector->some-list x size ($bytevector-length x)
'() sref-little 'bytevector->sint-list)]
[(big) (bytevector->some-list x size ($bytevector-length x)
'() sref-big 'bytevector->sint-list)]
[else (die who "invalid endianness" endianness)]))))
(define (bytevector-uint-set! bv i0 n endianness size)
(define who 'bytevector-uint-set!)
(bytevector-uint-set!/who bv i0 n endianness size who))
(define (bytevector-uint-set!/who bv i0 n endianness size who)
(unless (bytevector? bv)
(die who "not a bytevector" bv))
(unless (or (fixnum? n) (bignum? n))
(die who "not an exact number" n))
(unless (>= n 0)
(die who "number must be positive" n))
(let ([bvsize ($bytevector-length bv)])
(unless (and (fixnum? i0)
($fx>= i0 0)
($fx< i0 bvsize))
(die who "invalid index" i0))
(unless (and (fixnum? size)
($fx> size 0)
($fx<= i0 ($fx- bvsize size)))
(die who "invalid size" size)))
(let ([nsize (bitwise-length n)])
(when (< (* size 8) nsize)
(die who
(format "number does not fit in ~a byte~a" size (if (= size 1) "" "s"))
n)))
(case endianness
[(little)
(let f ([bv bv] [i0 i0] [i1 (fx+ i0 size)] [n n])
(unless ($fx= i0 i1)
($bytevector-set! bv i0 (bitwise-and n 255))
(f bv ($fx+ i0 1) i1 (sra n 8))))]
[(big)
(let f ([bv bv] [i0 i0] [i1 (fx+ i0 size)] [n n])
(unless ($fx= i0 i1)
(let ([i1 ($fx- i1 1)])
($bytevector-set! bv i1 (bitwise-and n 255))
(f bv i0 i1 (sra n 8)))))]
[else (die who "invalid endianness" endianness)]))
(define (bytevector-sint-set! bv i0 n endianness size)
(define who 'bytevector-sint-set!)
(bytevector-sint-set!/who bv i0 n endianness size who))
(define (bytevector-sint-set!/who bv i0 n endianness size who)
(unless (bytevector? bv)
(die who "not a bytevector" bv))
(unless (or (fixnum? n) (bignum? n))
(die who "not an exact number" n))
(let ([bvsize ($bytevector-length bv)])
(unless (and (fixnum? i0)
($fx>= i0 0)
($fx< i0 bvsize))
(die who "invalid index" i0))
(unless (and (fixnum? size)
($fx> size 0)
($fx<= i0 ($fx- bvsize size)))
(die who "invalid size" size)))
(let ([nsize (+ (bitwise-length n) 1)])
(when (< (* size 8) nsize)
(die who "number does not fit" n)))
(case endianness
[(little)
(let f ([bv bv] [i0 i0] [i1 (fx+ i0 size)] [n n])
(unless ($fx= i0 i1)
($bytevector-set! bv i0 (bitwise-and n 255))
(f bv ($fx+ i0 1) i1 (sra n 8))))]
[(big)
(let f ([bv bv] [i0 i0] [i1 (fx+ i0 size)] [n n])
(unless ($fx= i0 i1)
(let ([i1 ($fx- i1 1)])
($bytevector-set! bv i1 (bitwise-and n 255))
(f bv i0 i1 (sra n 8)))))]
[else (die who "invalid endianness" endianness)]))
(module (uint-list->bytevector sint-list->bytevector)
(define (make-xint-list->bytevector who bv-set!)
(define (race h t ls idx endianness size)
(if (pair? h)
(let ([h ($cdr h)] [a ($car h)])
(if (pair? h)
(if (not (eq? h t))
(let ([bv (race ($cdr h) ($cdr t) ls
($fx+ idx ($fx+ size size))
endianness size)])
(bv-set! bv idx a endianness size who)
(bv-set! bv ($fx+ idx size) ($car h) endianness size who)
bv)
(die who "circular list" ls))
(if (null? h)
(let ([bv (make-bytevector ($fx+ idx size))])
(bv-set! bv idx a endianness size who)
bv)
(die who "not a proper list" ls))))
(if (null? h)
(make-bytevector idx)
(die who "not a proper list" ls))))
(lambda (ls endianness size)
(if (and (fixnum? size) (fx> size 0))
(race ls ls ls 0 endianness size)
(die who "size must be a positive integer" size))))
(define uint-list->bytevector
(make-xint-list->bytevector
'uint-list->bytevector bytevector-uint-set!/who))
(define sint-list->bytevector
(make-xint-list->bytevector
'sint-list->bytevector bytevector-sint-set!/who)))
(define (bytevector-ieee-double-native-ref bv i)
(if (bytevector? bv)
(if (and (fixnum? i)
($fx>= i 0)
($fxzero? ($fxlogand i 7))
($fx< i ($bytevector-length bv)))
($bytevector-ieee-double-native-ref bv i)
(die 'bytevector-ieee-double-native-ref "invalid index" i))
(die 'bytevector-ieee-double-native-ref "not a bytevector" bv)))
(define (bytevector-ieee-single-native-ref bv i)
(if (bytevector? bv)
(if (and (fixnum? i)
($fx>= i 0)
($fxzero? ($fxlogand i 3))
($fx< i ($bytevector-length bv)))
($bytevector-ieee-single-native-ref bv i)
(die 'bytevector-ieee-single-native-ref "invalid index" i))
(die 'bytevector-ieee-single-native-ref "not a bytevector" bv)))
(define (bytevector-ieee-double-native-set! bv i x)
(if (bytevector? bv)
(if (and (fixnum? i)
($fx>= i 0)
($fxzero? ($fxlogand i 7))
($fx< i ($bytevector-length bv)))
(if (flonum? x)
($bytevector-ieee-double-native-set! bv i x)
(die 'bytevector-ieee-double-native-set! "not a flonum" x))
(die 'bytevector-ieee-double-native-set! "invalid index" i))
(die 'bytevector-ieee-double-native-set! "not a bytevector" bv)))
(define (bytevector-ieee-single-native-set! bv i x)
(if (bytevector? bv)
(if (and (fixnum? i)
($fx>= i 0)
($fxzero? ($fxlogand i 3))
($fx< i ($bytevector-length bv)))
(if (flonum? x)
($bytevector-ieee-single-native-set! bv i x)
(die 'bytevector-ieee-single-native-set! "not a flonum" x))
(die 'bytevector-ieee-single-native-set! "invalid index" i))
(die 'bytevector-ieee-single-native-set! "not a bytevector" bv)))
(define ($bytevector-ieee-double-ref/big x i)
(import (ikarus system $flonums))
(let ([y ($make-flonum)])
($flonum-set! y 0 ($bytevector-u8-ref x i))
($flonum-set! y 1 ($bytevector-u8-ref x ($fx+ i 1)))
($flonum-set! y 2 ($bytevector-u8-ref x ($fx+ i 2)))
($flonum-set! y 3 ($bytevector-u8-ref x ($fx+ i 3)))
($flonum-set! y 4 ($bytevector-u8-ref x ($fx+ i 4)))
($flonum-set! y 5 ($bytevector-u8-ref x ($fx+ i 5)))
($flonum-set! y 6 ($bytevector-u8-ref x ($fx+ i 6)))
($flonum-set! y 7 ($bytevector-u8-ref x ($fx+ i 7)))
y))
(define ($bytevector-ieee-double-set!/big x i y)
(import (ikarus system $flonums))
($bytevector-set! x i ($flonum-u8-ref y 0))
($bytevector-set! x ($fx+ i 1) ($flonum-u8-ref y 1))
($bytevector-set! x ($fx+ i 2) ($flonum-u8-ref y 2))
($bytevector-set! x ($fx+ i 3) ($flonum-u8-ref y 3))
($bytevector-set! x ($fx+ i 4) ($flonum-u8-ref y 4))
($bytevector-set! x ($fx+ i 5) ($flonum-u8-ref y 5))
($bytevector-set! x ($fx+ i 6) ($flonum-u8-ref y 6))
($bytevector-set! x ($fx+ i 7) ($flonum-u8-ref y 7)))
(define ($bytevector-ieee-double-ref/little x i)
(import (ikarus system $flonums))
(let ([y ($make-flonum)])
($flonum-set! y 7 ($bytevector-u8-ref x i))
($flonum-set! y 6 ($bytevector-u8-ref x ($fx+ i 1)))
($flonum-set! y 5 ($bytevector-u8-ref x ($fx+ i 2)))
($flonum-set! y 4 ($bytevector-u8-ref x ($fx+ i 3)))
($flonum-set! y 3 ($bytevector-u8-ref x ($fx+ i 4)))
($flonum-set! y 2 ($bytevector-u8-ref x ($fx+ i 5)))
($flonum-set! y 1 ($bytevector-u8-ref x ($fx+ i 6)))
($flonum-set! y 0 ($bytevector-u8-ref x ($fx+ i 7)))
y))
(define ($bytevector-ieee-double-set!/little x i y)
(import (ikarus system $flonums))
($bytevector-set! x i ($flonum-u8-ref y 7))
($bytevector-set! x ($fx+ i 1) ($flonum-u8-ref y 6))
($bytevector-set! x ($fx+ i 2) ($flonum-u8-ref y 5))
($bytevector-set! x ($fx+ i 3) ($flonum-u8-ref y 4))
($bytevector-set! x ($fx+ i 4) ($flonum-u8-ref y 3))
($bytevector-set! x ($fx+ i 5) ($flonum-u8-ref y 2))
($bytevector-set! x ($fx+ i 6) ($flonum-u8-ref y 1))
($bytevector-set! x ($fx+ i 7) ($flonum-u8-ref y 0)))
(define ($bytevector-ieee-single-ref/little x i)
(let ([bv (make-bytevector 4)])
($bytevector-set! bv 0 ($bytevector-u8-ref x i))
($bytevector-set! bv 1 ($bytevector-u8-ref x ($fx+ i 1)))
($bytevector-set! bv 2 ($bytevector-u8-ref x ($fx+ i 2)))
($bytevector-set! bv 3 ($bytevector-u8-ref x ($fx+ i 3)))
($bytevector-ieee-single-native-ref bv 0)))
(define ($bytevector-ieee-single-ref/big x i)
(let ([bv (make-bytevector 4)])
($bytevector-set! bv 3 ($bytevector-u8-ref x i))
($bytevector-set! bv 2 ($bytevector-u8-ref x ($fx+ i 1)))
($bytevector-set! bv 1 ($bytevector-u8-ref x ($fx+ i 2)))
($bytevector-set! bv 0 ($bytevector-u8-ref x ($fx+ i 3)))
($bytevector-ieee-single-native-ref bv 0)))
(define ($bytevector-ieee-single-set!/little x i v)
(let ([bv (make-bytevector 4)])
($bytevector-ieee-single-native-set! bv 0 v)
($bytevector-set! x i ($bytevector-u8-ref bv 0))
($bytevector-set! x ($fx+ i 1) ($bytevector-u8-ref bv 1))
($bytevector-set! x ($fx+ i 2) ($bytevector-u8-ref bv 2))
($bytevector-set! x ($fx+ i 3) ($bytevector-u8-ref bv 3))))
(define ($bytevector-ieee-single-set!/big x i v)
(let ([bv (make-bytevector 4)])
($bytevector-ieee-single-native-set! bv 0 v)
($bytevector-set! x i ($bytevector-u8-ref bv 3))
($bytevector-set! x ($fx+ i 1) ($bytevector-u8-ref bv 2))
($bytevector-set! x ($fx+ i 2) ($bytevector-u8-ref bv 1))
($bytevector-set! x ($fx+ i 3) ($bytevector-u8-ref bv 0))))
(define (bytevector-ieee-double-ref bv i endianness)
(define who 'bytevector-ieee-double-ref)
(if (bytevector? bv)
(if (and (fixnum? i) ($fx>= i 0))
(let ([len ($bytevector-length bv)])
(if (and ($fxzero? ($fxlogand i 7)) ($fx< i len))
(case endianness
[(little) ($bytevector-ieee-double-native-ref bv i)]
[(big) ($bytevector-ieee-double-nonnative-ref bv i)]
[else (die who "invalid endianness" endianness)])
(if ($fx<= i ($fx- len 8))
(case endianness
[(little)
($bytevector-ieee-double-ref/little bv i)]
[(big)
($bytevector-ieee-double-ref/big bv i)]
[else (die who "invalid endianness" endianness)])
(die who "invalid index" i))))
(die who "invalid index" i))
(die who "not a bytevector" bv)))
(define (bytevector-ieee-single-ref bv i endianness)
(define who 'bytevector-ieee-single-ref)
(if (bytevector? bv)
(if (and (fixnum? i) ($fx>= i 0))
(let ([len ($bytevector-length bv)])
(if (and ($fxzero? ($fxlogand i 3)) ($fx< i len))
(case endianness
[(little) ($bytevector-ieee-single-native-ref bv i)]
[(big) ($bytevector-ieee-single-nonnative-ref bv i)]
[else (die who "invalid endianness" endianness)])
(if ($fx<= i ($fx- len 4))
(case endianness
[(little)
($bytevector-ieee-single-ref/little bv i)]
[(big)
($bytevector-ieee-single-ref/big bv i)]
[else (die who "invalid endianness" endianness)])
(die who "invalid index" i))))
(die who "invalid index" i))
(die who "not a bytevector" bv)))
(define (bytevector-ieee-double-set! bv i x endianness)
(define who 'bytevector-ieee-double-set!)
(if (bytevector? bv)
(if (flonum? x)
(if (and (fixnum? i) ($fx>= i 0))
(let ([len ($bytevector-length bv)])
(if (and ($fxzero? ($fxlogand i 7)) ($fx< i len))
(case endianness
[(little) ($bytevector-ieee-double-native-set! bv i x)]
[(big) ($bytevector-ieee-double-nonnative-set! bv i x)]
[else
(die who "invalid endianness" endianness)])
(if ($fx<= i ($fx- len 8))
(case endianness
[(little)
($bytevector-ieee-double-set!/little bv i x)]
[(big)
($bytevector-ieee-double-set!/big bv i x)]
[else
(die who "invalid endianness" endianness)])
(die who "invalid index" i))))
(die who "invalid index" i))
(die who "not a flonum" x))
(die who "not a bytevector" bv)))
(define (bytevector-ieee-single-set! bv i x endianness)
(define who 'bytevector-ieee-single-set!)
(if (bytevector? bv)
(if (flonum? x)
(if (and (fixnum? i) ($fx>= i 0))
(let ([len ($bytevector-length bv)])
(if (and ($fxzero? ($fxlogand i 3)) ($fx< i len))
(case endianness
[(little) ($bytevector-ieee-single-native-set! bv i x)]
[(big) ($bytevector-ieee-single-nonnative-set! bv i x)]
[else
(die who "invalid endianness" endianness)])
(if ($fx<= i ($fx- len 4))
(case endianness
[(little)
($bytevector-ieee-single-set!/little bv i x)]
[(big)
($bytevector-ieee-single-set!/big bv i x)]
[else
(die who "invalid endianness" endianness)])
(die who "invalid index" i))))
(die who "invalid index" i))
(die who "not a flonum" x))
(die who "not a bytevector" bv)))
(define ($bytevector-ref/64/aligned bv i who decoder endianness)
(if (bytevector? bv)
(if (and (fixnum? i)
($fx>= i 0)
($fxzero? ($fxlogand i 7))
($fx< i ($bytevector-length bv)))
(case endianness
[(little big)
(decoder bv i endianness 8)]
[else (die who "invalid endianness" endianness)])
(die who "invalid index" i))
(die who "not a bytevector" bv)))
(define ($bytevector-ref/64 bv i who decoder endianness)
(if (bytevector? bv)
(if (and (fixnum? i)
($fx>= i 0)
($fx< i ($fx- ($bytevector-length bv) 7)))
(case endianness
[(little big)
(decoder bv i endianness 8)]
[else (die who "invalid endianness" endianness)])
(die who "invalid index" i))
(die who "not a bytevector" bv)))
(define (bytevector-u64-native-ref bv i)
($bytevector-ref/64/aligned bv i 'bytevector-u64-native-ref
bytevector-uint-ref 'little))
(define (bytevector-s64-native-ref bv i)
($bytevector-ref/64/aligned bv i 'bytevector-s64-native-ref
bytevector-sint-ref 'little))
(define (bytevector-u64-ref bv i endianness)
($bytevector-ref/64 bv i 'bytevector-u64-ref
bytevector-uint-ref endianness))
(define (bytevector-s64-ref bv i endianness)
($bytevector-ref/64 bv i 'bytevector-s64-ref
bytevector-sint-ref endianness))
(define ($bytevector-set/64/align bv i n lo hi who setter endianness)
(if (bytevector? bv)
(if (and (fixnum? i)
($fx>= i 0)
($fxzero? ($fxlogand i 7))
($fx< i ($bytevector-length bv)))
(case endianness
[(little big)
(unless (or (fixnum? n) (bignum? n))
(die who "number is not an exact number" n))
(unless (and (<= lo n) (< n hi))
(die who "number out of range" n))
(setter bv i n endianness 8)]
[else (die who "invalid endianness" endianness)])
(die who "invalid index" i))
(die who "not a bytevector" bv)))
(define ($bytevector-set/64 bv i n lo hi who setter endianness)
(if (bytevector? bv)
(if (and (fixnum? i)
($fx>= i 0)
($fx< i ($fx- ($bytevector-length bv) 7)))
(case endianness
[(little big)
(unless (or (fixnum? n) (bignum? n))
(die who "number is not exact number" n))
(unless (and (<= lo n) (< n hi))
(die who "number out of range" n))
(setter bv i n endianness 8)]
[else (die who "invalid endianness" endianness)])
(die who "invalid index" i))
(die who "not a bytevector" bv)))
(define (bytevector-u64-native-set! bv i n)
($bytevector-set/64/align bv i n 0 (expt 2 64)
'bytevector-u64-native-set! bytevector-uint-set! 'little))
(define (bytevector-s64-native-set! bv i n)
($bytevector-set/64/align bv i n (- (expt 2 63)) (expt 2 63)
'bytevector-s64-native-set! bytevector-sint-set! 'little))
(define (bytevector-u64-set! bv i n endianness)
($bytevector-set/64 bv i n 0 (expt 2 64)
'bytevector-u64-set! bytevector-uint-set! endianness))
(define (bytevector-s64-set! bv i n endianness)
($bytevector-set/64 bv i n (- (expt 2 63)) (expt 2 63)
'bytevector-s64-set! bytevector-sint-set! endianness))
)
(library (ikarus system bytevectors)
(export $bytevector-u8-ref $bytevector-length $make-bytevector)
(import (ikarus))
(define $bytevector-u8-ref bytevector-u8-ref)
(define $bytevector-length bytevector-length)
(define $make-bytevector make-bytevector))
| false |
d92d123298fecfe3bbff7f96e7759d439d5b27e9 | 6f86602ac19983fcdfcb2710de6e95b60bfb0e02 | /input/exercises/hello-world/example.scm | e3816997051c30044845b829038d321a969e9952 | [
"MIT",
"CC-BY-SA-3.0"
]
| permissive | exercism/scheme | a28bf9451b8c070d309be9be76f832110f2969a7 | d22a0f187cd3719d071240b1d5a5471e739fed81 | refs/heads/main | 2023-07-20T13:35:56.639056 | 2023-07-18T08:38:59 | 2023-07-18T08:38:59 | 30,056,632 | 34 | 37 | MIT | 2023-09-04T21:08:27 | 2015-01-30T04:46:03 | Scheme | UTF-8 | Scheme | false | false | 57 | scm | example.scm | (import (rnrs))
(define hello-world
"Hello, World!")
| false |
be23bab6b18fd24df30349f38bca3190b92dca2d | c157305e3b08b76c2f4b0ac4f9c04b435097d0dc | /eopl2e/code/interps/1.scm | 0c351fc7e024bd972e391594e461a8080a99b820 | []
| no_license | rstewart2702/scheme_programs | a5e91bd0e1587eac3859058da18dd9271a497721 | 767d019d84896569f2fc02de95925b05a38cac4d | refs/heads/master | 2021-05-02T02:01:01.964797 | 2014-03-31T19:02:36 | 2014-03-31T19:02:36 | 13,077,035 | 0 | 1 | null | null | null | null | UTF-8 | Scheme | false | false | 3,152 | scm | 1.scm | (let ((time-stamp "Time-stamp: <2001-05-10 05:30:06 dfried>"))
(eopl:printf "1.scm: code for chapter 1 ~a~%" (substring time-stamp 13 29)))
(define count-nodes
(lambda (s)
(if (number? s)
1
(+ (count-nodes (cadr s))
(count-nodes (caddr s))
1))))
(define list-of-numbers?
(lambda (lst)
(if (null? lst)
#t
(and ;\new3
(number? (car lst))
(list-of-numbers? (cdr lst))))))
(define nth-elt
(lambda (lst n)
(if (null? lst)
(eopl:error 'nth-elt
"List too short by ~s elements.~%" (+ n 1))
(if (zero? n)
(car lst)
(nth-elt (cdr lst) (- n 1))))))
(define remove
(lambda (s los)
(if (null? los)
'()
(if (eqv? (car los) s)
(remove s (cdr los)) ;\new1
(cons (car los) (remove s (cdr los)))))))
(define subst
(lambda (new old slist)
(if (null? slist)
'()
(cons ;\new3
(subst-in-symbol-expression new old (car slist))
(subst new old (cdr slist))))))
(define subst-in-symbol-expression
(lambda (new old se)
(if (symbol? se) ;\new3
(if (eqv? se old) new se)
(subst new old se))))
(define notate-depth
(lambda (slist)
(notate-depth-in-s-list slist 0)))
(define notate-depth-in-s-list
(lambda (slist d)
(if (null? slist) ;\new5
'()
(cons
(notate-depth-in-symbol-expression (car slist) d)
(notate-depth-in-s-list (cdr slist) d)))))
(define notate-depth-in-symbol-expression
(lambda (se d)
(if (symbol? se)
(list se d)
(notate-depth-in-s-list se (+ d 1)))))
(define list-sum
(lambda (lon)
(if (null? lon)
0
(+ (car lon)
(list-sum (cdr lon))))))
(define partial-vector-sum
(lambda (von n)
(if (zero? n)
0
(+ (vector-ref von (- n 1))
(partial-vector-sum von (- n 1))))))
;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; This one will be in the text. ;
;;; (define vector-sum ;
;;; (lambda (von) ;
;;; (partial-vector-sum von (vector-length von)))) ;
;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(define vector-sum
(lambda (von)
(letrec
((partial-sum
(lambda (n)
(if (zero? n)
0
(+ (vector-ref von (- n 1))
(partial-sum (- n 1)))))))
(partial-sum (vector-length von)))))
(define occurs-free?
(lambda (var exp)
(cond
((symbol? exp) (eqv? var exp))
((eqv? (car exp) 'lambda)
(and (not (eqv? (caadr exp) var))
(occurs-free? var (caddr exp))))
(else (or (occurs-free? var (car exp))
(occurs-free? var (cadr exp)))))))
(define occurs-bound?
(lambda (var exp)
(cond
((symbol? exp) #f)
((eqv? (car exp) 'lambda)
(or (occurs-bound? var (caddr exp))
(and (eqv? (caadr exp) var)
(occurs-free? var (caddr exp)))))
(else (or (occurs-bound? var (car exp))
(occurs-bound? var (cadr exp)))))))
| false |
e49fa06dc8b3811a575a425dec58b2879562c023 | 92d1f9df75d93f3125b07b9830541577248723fa | /the_littles_scheme/example.ss | 88ffc019d9f0666328b334fbe007098abf8e516a | []
| no_license | liangxingguang/schemelearn | 94a8f804194ba554fd4f6fbc4959533daf08194e | 71e32238149fb50a8e78466dcdb4d652af846a9e | refs/heads/master | 2021-03-12T23:08:57.212246 | 2014-04-30T18:09:08 | 2014-04-30T18:09:08 | null | 0 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 6,607 | ss | example.ss | #lang racket
(define atom?
(lambda (x)
(and (not (pair? x))
(not (null? x)))))
;;;;;;;;;;
(define lat?
(lambda(l)
(cond
((null? l) #t)
((atom? (car l)) (lat? (cdr l)))
(else #f))))
;;test the function
(lat? (list 'a 'b 'c))
(lat? '((a b) c d))
;;;;;;;;;;;;;;;;;;;;;;;;;
(define member?
(lambda (a lat)
(cond
((null? lat) #f)
(else (or (eq? (car lat) a)
(member? a (cdr lat)))))))
(member? 'meat '(meat abc def dkg))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(define rember
(lambda (a lat)
(cond
((null? lat) (quote ()))
(else
(cond
((eq? (car lat) a) (cdr lat))
(else
(cons (car lat)
(rember a (cdr lat)))))))))
(rember 'a '(a b c d a d))
;;simplify from rember
(define rember_s
(lambda (a lat)
(cond
((null? lat) (quote ()))
((eq? (car lat) a) (cdr lat))
(else
(cons (car lat)
(rember a (cdr lat)))))))
(rember_s 'a '(a b c d a d))
;;;;;;;;;;;;;;;;;;;
(define firsts
(lambda (l)
(cond
((null? l) '())
(else
(cons (car (car l))
(firsts (cdr l)))))))
(firsts '((a b) (c d) (e f)))
(define firsts*
(lambda (l)
(cond
((null? l) '())
(else
(cond
((atom? (car l)) (cons (car l) (firsts* (cdr l))))
(else
(cons (car (car l)) (firsts* (cdr l)))))))))
(firsts* '(((g a) b) (c d) (e f) a))
(define firsts**
(lambda (l)
(define getthefirst
(lambda(n)
(cond
((null? n) '())
((atom? (car n)) (car n))
(else
(getthefirst (car n)))
)))
(cond
((null? l) '())
((atom? (car l)) (cons (car l) (firsts** ( cdr l))))
(else
(cons (getthefirst (car l)) (firsts** (cdr l)))))))
(firsts** '(((((g d) d) a) b) (c d) (e f) a))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(define replace
(lambda (new old lat)
(cond
((null? lat) (quote ()))
(else
(cond
((eq? (car lat) old)
(cons new (cdr lat)))
(else
(cons (car lat)
(replace new old (cdr lat)))))))))
(replace 'ab 'd '(a b c d e f))
(define replace*
(lambda (new old lat)
(cond
((null? lat) (quote ()))
((eq? (car lat) old)
(cons new (replace* new old (cdr lat))))
(else
(cons (car lat) (replace* new old (cdr lat)))))))
(replace* 'ab 'd '(a b c d e f))
(replace* 'ab 'd '(a b c d e d f d g))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(define insertR
(lambda (new old lat)
(cond
((null? lat) (quote ()))
((eq? (car lat) old)
(cons old (cons new (cdr lat))))
(else
(cons (car lat) (insertR new old (cdr lat)))))))
(insertR 'ab 'b '(a b c d b e))
(define insertL
(lambda (new old lat)
(cond
((null? lat) (quote ()))
((eq? old (car lat)) (cons new (cons old (cdr lat))))
(else
(cons (car lat) (insertL new old (cdr lat)))))))
(insertL 'ab 'd '(a b c d b e))
(define insertR*
(lambda (new old lat)
(cond
((null? lat) (quote ()))
(else
(cond
((eq? old (car lat))
(cons old (cons new (insertR* new old (cdr lat)))))
(else
(cons (car lat) (insertR* new old (cdr lat)))))))))
(insertR* 'ab 'b '(a b c d b e))
(define insertL*
(lambda (new old lat)
(cond
((null? lat) (quote ()))
(else
(cond
((eq? old (car lat))
(cons new (cons old (insertL* new old (cdr lat)))))
(else
(cons (car lat) (insertL* new old (cdr lat)))))))))
(insertL* 'ab 'b '(a b c d b e))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(define subst2
(lambda (new o1 o2 lat)
(cond
((null? lat) (quote ()))
(else
(cond
((or (eq? (car lat) o1) (eq? (car lat) o2))
(cons new (cdr lat)))
(else
(cons (car lat)
(subst2 new o1 o2 (cdr lat)))))))))
(subst2 'vanilla 'with 'banana
'(banana ice cream with chocolate topping))
(define subst2*
(lambda (new o1 o2 lat)
(cond
((null? lat) (quote ()))
(else
(cond
((or (eq? (car lat) o1) (eq? (car lat) o2))
(cons new (subst2* new o1 o2 (cdr lat))))
(else
(cons (car lat) (subst2* new o1 o2 (cdr lat)))))))))
(subst2* 'vanilla 'with 'banana
'(banana ice cream with chocolate topping))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(define multirember
(lambda (a lat)
(cond
((null? lat) (quote ()))
(else
(cond
((eq? (car lat) a)
(multirember a (cdr lat)))
(else
(cons (car lat)
(multirember a
(cdr lat)))))))))
(multirember 'a '(a b a c d a e g))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(define multisubst
(lambda (new old lat)
(cond
((null? lat) (quote()))
(else (cond
((eq? (car lat) old)
(cons new (multisubst new old
(cdr lat))))
(else (cons (car lat)
(multisubst new old (cdr lat)))))))))
(multisubst 'd3 'b '(a b d b c d e f))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(define add1
(lambda (n)
(+ n 1)))
(add1 3)
(define sub1
(lambda (n)
(- n 1)))
(define add
(lambda (n m)
(cond
((zero? m) n)
(else
(add1 (add n (sub1 m)))))))
(add 3 4)
(define sub
(lambda (n m)
(cond
((zero? m) n)
(else
(sub1 (sub n (sub1 m)))))))
(sub 3 4)
(define multiply
(lambda (n m)
(cond
((zero? m) 0)
(else
(add n (multiply n (sub1 m)))))))
(multiply 3 4)
(define tup+
(lambda (tup1 tup2)
(cond
( (null? tup1) tup2)
[(null? tup2) tup1]
(else
(cons (add (car tup1) (car tup2))
(tup+ (cdr tup1) (cdr tup2)))))))
(tup+ '(1 2 3) '(4 5 6))
;(tup+ '(a b c) '(d e f))
(define more
(lambda (n m)
(cond
[(zero? n) #f]
[(zero? m) #t]
(else
(more (sub1 n) (sub1 m))))))
(more 3 4)
(define less
(lambda (n m)
(cond
[(zero? m) #f]
[(zero? n) #t]
(else
(less (sub1 n) (sub1 m))))))
(less 3 4)
(define eq
(lambda ( n m)
(cond
[(zero? m) (zero? n)]
[(zero? n) #f]
[else
(eq (sub1 n) (sub1 m))])))
(eq 3 3)
(eq 3 4)
(define eq1
(lambda ( n m )
(cond
[(more n m) #f]
[(less n m) #f]
(else #t))))
(eq1 3 3)
(eq1 3 5)
| false |
48d1fb2662b4710dcbbc42f8f1d146e19595913f | b5783aa5c2b23c870b8729af3ba55b5718d1aa43 | /symbolic/simplify-div-vector.sls | 6424b1147bf6a380761d14260a82c825d4dabdc1 | []
| no_license | dharmatech/numero | 562a4a91d17d41f7e553a1295aa6b73316316e8c | d69357e1d8840511e167103d6eb46080ede46d72 | refs/heads/master | 2020-04-01T13:40:31.194701 | 2009-08-02T20:29:33 | 2009-08-02T20:29:33 | 252,486 | 2 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 680 | sls | simplify-div-vector.sls |
(library (numero symbolic simplify-div-vector)
(export simplify-div-vector)
(import (rnrs)
(xitomatl AS-match)
(numero symbolic simplify-parameters))
(define (simplify-div-vector expr)
(match expr
(('/ (? vector? a) (? vector? b))
(vector-map (lambda (elt-a elt-b) `(/ ,elt-a ,elt-b))
a
b))
(('/ (? vector? a) (? number? n))
(vector-map (lambda (elt-a) `(/ ,elt-a ,n)) a))
(('/ (? number? n) (? vector? a))
(vector-map (lambda (elt-a) `(/ ,n ,elt-a)) a))
(('/ (? vector? a) x)
(vector-map (lambda (elt-a) `(/ ,elt-a ,x)) a))
(else expr)))
) | false |
d3f064342031849f0852fca4c7666d6bc9a679de | a0c856484b0cafd1d7c428fb271a820dd19be577 | /lab6/interp-b.ss | 08426f61507e78758c559f3f41d1e54858c28a31 | []
| no_license | ctreatma/scheme_exercises | b13ba7743dfd28af894eb54429297bad67c14ffa | 94b4e8886b2500a7b645e6dc795c0d239bf2a3bb | refs/heads/master | 2020-05-19T07:30:58.538798 | 2012-12-03T23:12:22 | 2012-12-03T23:12:22 | null | 0 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 660 | ss | interp-b.ss | ;; interp-b.ss
;; Interpreter for Mini-Scheme-B
(require (lib "eopl.ss" "eopl"))
(define eval-exp
(lambda (exp)
(cases exp-b exp
(exp-b-lit (datum) datum)
(exp-b-varref (var) (apply-env init-env var))
(else (error 'eval-exp
"Invalid abstract syntax: ~s"
exp)))))
; primop definitions
(define-datatype prim prim?
(prim-proc (prim-op proc-symbol?)))
(define proc-symbol? (lambda (sym) (member sym '(+ - * /))))
(define prim-op-names '(+ - *))
(define init-env
(extend-env
prim-op-names
(map prim-proc prim-op-names)
the-empty-env))
| false |
ff027a13415b4bcff3c8d118e5350aae591ef9be | b9eb119317d72a6742dce6db5be8c1f78c7275ad | /random-scheme-stuff/triumph.scm | 84b93c5863ffc60b79ceb7a74fd8123109166bd8 | []
| no_license | offby1/doodles | be811b1004b262f69365d645a9ae837d87d7f707 | 316c4a0dedb8e4fde2da351a8de98a5725367901 | refs/heads/master | 2023-02-21T05:07:52.295903 | 2022-05-15T18:08:58 | 2022-05-15T18:08:58 | 512,608 | 2 | 1 | null | 2023-02-14T22:19:40 | 2010-02-11T04:24:52 | Scheme | UTF-8 | Scheme | false | false | 5,310 | scm | triumph.scm | ;; This code solves a problem I had long ago, when I worked for a
;; small software company.
;; The problem was putting our product onto floppy disks for
;; distribution to customers. The product consisted of about 3000
;; files of various sizes, adding up to about ten megabytes. We
;; wanted to distribute the product on the fewest floppies, to save
;; money. It was easy to figure out how many floppies we'd need for
;; one copy of the product: just take the total size of all the files,
;; divide by the capacity of one floppy, and round up to the next
;; largest integer.
;; The real problem was that there'd be some unused space on each
;; floppy, and I wanted that unused space distributed as evenly as
;; possible over all the floppies (so that if we needed to add another
;; file at the last minute, we'd be able to put it on any floppy we
;; liked, since each would have some free space). I thought for a
;; while, and decided that to "load" the floppies evenly, I'd sort a
;; list of all the files, in decreasing order by their size, and then
;; I'd take the top item on the list and add it to the emptiest
;; floppy. So I wanted a computer program that would read the list of
;; items, and return a list of the floppies, each containing a list of
;; the items that were to be stored on it.
;; I wrote some Emacs Lisp code to do this. As I recall, it took me a
;; few hours to write it. And now I've written it again, this time in
;; Scheme; it took me a few hours to write this, too.
;; Instead of dealing with "floppies" and "files", this code deals
;; with "containers" and "items". Same difference, though.
;; An "item" is either a number, or a two-element list, the first of
;; which is a symbol (which could be the name of the file), and the
;; second of which is a number (which could be the size of the file).
;; Perhaps I should use dotted pairs instead of lists.
;; Given a bunch of items, and a bunch of containers, put the items
;; into the containers in such a way as to fill the containers
;; evenly.
;; Here's what a bunch of items might look like:
;; '((bob 200) (fred 75) (sally 12) (znorf 66) 44)
;; That is, a bunch of items is a list; each element of the list is
;; either a number, or a two-element list, whose car is a symbol and
;; whos cadr is a number. The number represents the "size" of the
;; item; the symbol represents its name. A number by itself is an
;; item without a name.
;; A bunch of containers is just a list of symbols. This code will
;; return a list of lists; one list for each symbol. Each such list
;; will have as its car the symbol, and as its remaining elements,
;; some items. For example, given the items above, and the list
;; '(container-1 container-2)
;; we'd get back
;; '((container-1 (bob 200)) (container-2 (fred 75) (znorf 66) 44 (sally 12)))
;; Each item will appear on exactly one of the returned lists.
(require 'sort)
(require 'random)
;; normally-distributed random number, or at least something that
;; vaguely looks like one.
(define normal
(let ((pi (* 4 (atan 1))))
(lambda ()
(tan (* pi (- (random 1.0) 1/2))))))
(define (prompted-read prompt)
(display prompt)
(read))
(define (interactive)
(distribute-evenly
(prompted-read "Enter an unquoted list of items: ")
(prompted-read "Enter an unquoted list of container names: ")))
;; This simply builds a list of containers from the list of symbols,
;; then modifies that list of containers by calling
;; evenly-distribute!, then returns the modified list.
(define (distribute-evenly items containers)
(evenly-distribute!
(sort items
(lambda (item1 item2)
(> (item:weight item1)
(item:weight item2))))
(map list containers)))
;; This does the real work. It modifies each list in `containers' by
;; adding items to it.
(define (evenly-distribute! item-list containers)
(cond
((null? item-list)
containers)
(else
(container:add-item! (container:emptiest containers)
(car item-list))
(evenly-distribute! (cdr item-list)
containers))))
(define (container:emptiest containers)
(if (= (length containers) 1)
(car containers)
(let ((cdr-emptiest (container:emptiest (cdr containers))))
(cond
((<
(container:weight (car containers))
(container:weight cdr-emptiest))
(car containers))
(else
cdr-emptiest)))))
(define (container:weight container)
(apply + (map item:weight (cdr container))))
(define (container:add-item! container item)
(set-cdr! container (cons item (cdr container)))
container)
(define (item:weight item)
(cond
((number? item)
item)
(else
(cadr item))))
(define (container:simpler-equivalent cont)
(if (null? cont)
'()
(list (car cont)
(container:weight cont))))
;; Use this to examine the output from distribute-evenly, to see just
;; how evenly things got distributed.
(define (container-list:weights lis)
(if (null? lis)
'()
(cons (container:simpler-equivalent (car lis))
(container-list:weights (cdr lis)))))
(require 'pretty-print)
(pretty-print (distribute-evenly
;; This generates some input data.
(let loop ((count 100))
(if (= count 0)
'()
(cons (inexact->exact (round (expt (* 10 (normal)) 2)))
(loop (- count 1)))))
'(one two three)))
| false |
e86e250b92ec30e9d44a792fc6eb37533a1b825c | b60cb8e39ec090137bef8c31ec9958a8b1c3e8a6 | /test/concurrentScheme/actors/stack.scm | 906d2562db5d4a5971ecef21843f2a8ea236d47b | []
| no_license | acieroid/scala-am | eff387480d3baaa2f3238a378a6b330212a81042 | 13ef3befbfc664b77f31f56847c30d60f4ee7dfe | refs/heads/master | 2021-01-17T02:21:41.692568 | 2021-01-15T07:51:20 | 2021-01-15T07:51:20 | 28,140,080 | 32 | 16 | null | 2020-04-14T08:53:20 | 2014-12-17T14:14:02 | Scheme | UTF-8 | Scheme | false | false | 950 | scm | stack.scm | ;; From Agha 1986, p. 52
(letrec ((stack-node (actor "stack-node" (content link)
(pop (customer)
(if link
(begin
(send customer message content)
(link))
(begin
(error "popping an empty stack")
(terminate))))
(push (v)
(become stack-node v (lambda () (become stack-node content link))))))
(display-actor (actor "display" ()
(message (v) (display v) (become display-actor))))
(disp (create display-actor))
(act (create stack-node #f #f)))
(send act push (random 42))
(send act push (bool-top))
(send act push 3)
(send act pop disp))
| false |
ab6a48c3831a3f5d928a79db79398e84046cc5a1 | 370b378f48cb3ddd94297240ceb49ff4506bc122 | /2.6.scm | 640c1b6bf3fd558ad7f4acdb738610440709e825 | []
| no_license | valvallow/PAIP | 7c0c0702b8c601f4e706b02eea9615d8fdeb7131 | ee0a0bd445ef52c5fe38488533fd59a3eed287f0 | refs/heads/master | 2021-01-20T06:56:48.999920 | 2010-11-26T08:09:00 | 2010-11-26T08:09:00 | 798,236 | 0 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 4,378 | scm | 2.6.scm | (define (generate-tree phrase)
(if (list? phrase)
(map generate-tree phrase)
(if-let1 choices (rewrites phrase)
(cons phrase
(generate-tree (random-elt choices)))
(list phrase))))
(set! *grammar* *simple-grammar*)
(generate-tree 'sentene)
#|
(sentene (noun-phrase (article the)
(noun ball))
(verb-phrase (verb hit)
(noun-phrase (article a)
(noun ball))))
|#
(define (generate-all phrase)
(cond ((null? phrase)(list '()))
((list? phrase)
(combine-all (generate-all (car phrase))
(generate-all (cdr phrase))))
((rewrites phrase)
=> (pa$ mappend generate-all))
(else (list (list phrase)))))
(define (combine-all xlis ylis)
(mappend (lambda (y)
(map (lambda (x)
(append x y)) xlis))
ylis))
(print (combine-all (map list '(a b c))(map list '(1 2 3))))
;; ((a 1) (b 1) (c 1) (a 2) (b 2) (c 2) (a 3) (b 3) (c 3))
(generate-all 'article)
;; ((the) (a))
(generate-all 'noun)
;; ((man) (ball) (woman) (table))
(print (generate-all 'noun-phrase))
;; ((the man) (a man) (the ball) (a ball) (the woman) (a woman) (the table) (a table))
;; --------------------------------------------------------------------
;; PAIP 2.6 P.41
(define (combine-all xlis ylis)
(mappend (lambda (y)
(map (lambda (x)
(append x y)) xlis))
ylis))
(print (combine-all (map list '(a b c))(map list '(1 2 3))))
;; ((a 1) (b 1) (c 1) (a 2) (b 2) (c 2) (a 3) (b 3) (c 3))
;; (cross-combine '(1 2 3)'(a b c))
;; ((1 a) (2 a) (3 a) (1 b) (2 b) (3 b) (1 c) (2 c) (3 c))
(define (cross-combine xlis ylis)
(mappend (lambda (y)
(map (lambda (x)
(list x y)) xlis))
ylis))
;; (add-combine-elements (cross-combine '(1 2 3)'(a b c))
;; '(100 200 300))
;; ((1 a 100) (2 a 100) (3 a 100) (1 b 100) (2 b 100) (3 b 100) (1 c 100) (2 c 100) (3 c 100) (1 a 200) (2 a 200) (3 a 200) (1 b 200) (2 b 200) (3 b 200) (1 c 200) (2 c 200) (3 c 200) (1 a 300) (2 a 300) (3 a 300) (1 b 300) (2 b 300) (3 b 300) (1 c 300) (2 c 300) (3 c 300))
(define (add-combine-elements comb elements)
(mappend (lambda (c)
(map (lambda (e)
(append e (list c))) comb))
elements))
(define (cross-combine xls yls . opt)
(let-optionals* opt ((kons list))
(mappend (lambda (y)
(map (lambda (x)
(kons x y)) xls))
yls)))
(define (add-combine-elements comb elements)
(cross-combine comb elements (lambda (e c)
(append e (list c)))))
(define (cross-combines ls1 ls2 . lss)
(let rec ((lss lss)(comb (cross-combine ls1 ls2)))
(if (null? lss)
comb
(rec (cdr lss)
(add-combine-elements comb (car lss))))))
;; (print (combine-all (map list '(a b c))(map list '(1 2 3))))
;; ((a 1) (b 1) (c 1) (a 2) (b 2) (c 2) (a 3) (b 3) (c 3))
(define (combine-all xlis ylis)
(cross-combine xlis ylis append))
(print (cross-combines '(a b c)'(1 2 3)'(100 200 300)))
;; ((a 1 100) (b 1 100) (c 1 100)
;; (a 2 100) (b 2 100) (c 2 100)
;; (a 3 100) (b 3 100) (c 3 100)
;; (a 1 200) (b 1 200) (c 1 200)
;; (a 2 200) (b 2 200) (c 2 200)
;; (a 3 200) (b 3 200) (c 3 200)
;; (a 1 300) (b 1 300) (c 1 300)
;; (a 2 300) (b 2 300) (c 2 300)
;; (a 3 300) (b 3 300) (c 3 300))
(print (cross-combines '(a b c)'(#f #t)'(1 2 3)'(100 200 300)))
;; ((a #f 1 100) (b #f 1 100) (c #f 1 100)
;; (a #t 1 100) (b #t 1 100) (c #t 1 100)
;; (a #f 2 100) (b #f 2 100) (c #f 2 100)
;; (a #t 2 100) (b #t 2 100) (c #t 2 100)
;; (a #f 3 100) (b #f 3 100) (c #f 3 100)
;; (a #t 3 100) (b #t 3 100) (c #t 3 100)
;; (a #f 1 200) (b #f 1 200) (c #f 1 200)
;; (a #t 1 200) (b #t 1 200) (c #t 1 200)
;; (a #f 2 200) (b #f 2 200) (c #f 2 200)
;; (a #t 2 200) (b #t 2 200) (c #t 2 200)
;; (a #f 3 200) (b #f 3 200) (c #f 3 200)
;; (a #t 3 200) (b #t 3 200) (c #t 3 200)
;; (a #f 1 300) (b #f 1 300) (c #f 1 300)
;; (a #t 1 300) (b #t 1 300) (c #t 1 300)
;; (a #f 2 300) (b #f 2 300) (c #f 2 300)
;; (a #t 2 300) (b #t 2 300) (c #t 2 300)
;; (a #f 3 300) (b #f 3 300) (c #f 3 300)
;; (a #t 3 300) (b #t 3 300) (c #t 3 300))
| false |
6d6c68bd52faa772f4b40896df1bc42ed7792b83 | 88c274acc25d882506d332ca392daf24053f2aa6 | /examples/boing.scm | b9a4281c3cb623349bf533439635e8a1ef5f1db8 | [
"Apache-2.0"
]
| permissive | shakdwipeea/chez-glfw | 476564d9b6c8b4b33b38a18c3579df11414624ba | 08f2f14360d42b62ad05cd20a3503b71a6771676 | refs/heads/master | 2020-07-03T15:17:54.954675 | 2019-08-12T14:38:03 | 2019-08-12T14:38:03 | 201,950,375 | 0 | 0 | null | 2019-08-12T14:48:27 | 2019-08-12T14:48:26 | null | UTF-8 | Scheme | false | false | 12,777 | scm | boing.scm | (import (rnrs (6))
(srfi :48)
(glfw basic)
(glfw constants)
(glfw gl GL_VERSION_3_0)
(glfw gl support)
(glfw polygons)
(glfw linmath)
(lyonesse record-with-context)
(lyonesse functional)
(lyonesse match)
(lyonesse ranges)
(lyonesse munsch f32array)
(lyonesse munsch linear-algebra)
(lyonesse munsch geometry)
(lyonesse foreign-data)
(lyonesse strings)
(pfds queues)
(pfds psqs)
(only (chezscheme) box unbox set-box! random))
#|================================================================|
| Library routines |
|================================================================|#
(define (spherical->cartesian r u v)
(g:. (* r (sin u) (cos v))
(* r (sin u) (sin v))
(* r (cos u))))
(define (sign x)
(cond [(< x 0) -1] [(> x 0) +1] [else 0]))
(define (clip x a b)
(cond
((< a x) a)
((> x b) b)
(else x)))
(define (random-uniform-real)
(random 1.0))
#|================================================================|
| Constants |
|================================================================|#
(define RADIUS 70.0)
(define M-BANDS 8)
(define N-BANDS 16)
(define DIST-BALL (* 2.1 RADIUS))
(define VIEW-SCENE-DIST (+ 200.0 (* 3 DIST-BALL)))
(define GRID-SIZE (* 4.5 RADIUS))
(define BOUNCE-HEIGHT (* 2.1 RADIUS))
(define BOUNCE-WIDTH (* 2.1 RADIUS))
(define SHADOW-OFFSET (list -20.0 10.0 0.0))
(define WALL-L-OFFSET 0.0)
(define WALL-R-OFFSET 5.0)
(define ANIMATION-SPEED 50.0)
(define pi 3.1415926539)
#|================================================================|
| World definition |
|================================================================|#
(define-record-with-context world
(fields window window-geometry ball cursor))
(define-record-with-context window-geometry
(fields width height))
(define-record-with-context ball
(fields x y x-inc y-inc rot-y rot-y-inc))
(define-record-with-context cursor
(fields x y))
(define (set-ball-pos world x y)
(with-world world
(with-window-geometry window-geometry
(let ([new-ball (make-ball (- (/ width 2) x)
(- y (/ height 2)))])
(update-world world (ball new-ball))))))
(define (bounce-ball ball dt)
(with-ball ball
(let* ([bounce-right? (> x (+ (* BOUNCE-WIDTH 1/2) WALL-R-OFFSET))]
[bounce-left? (< x (- (* BOUNCE-WIDTH -1/2) WALL-L-OFFSET))]
[bounce-floor? (> y (* BOUNCE-HEIGHT 1/2))]
[bounce-roof? (< y (* BOUNCE-HEIGHT -19/40))]
[x-inc* (cond
[bounce-right? (- -1/2 (* 3/4 (random-uniform-real)))]
[bounce-left? (+ 1/2 (* 3/4 (random-uniform-real)))]
[else x-inc])]
[y-inc* (cond
[bounce-floor? (- -3/4 (random-uniform-real))]
[bounce-roof? (+ 3/4 (random-uniform-real))]
[else y-inc])]
[rot-y-inc* (if (or bounce-right? bounce-left?)
(- rot-y-inc) rot-y-inc)]
[rot-y* (+ rot-y rot-y-inc*)]
[deg (clip (* (+ y (* BOUNCE-HEIGHT 1/2)) (/ 90 BOUNCE-HEIGHT))
10 80)])
(make-ball (+ x (* x-inc dt ANIMATION-SPEED))
(+ y (* y-inc dt ANIMATION-SPEED))
x-inc*
(* (sign y-inc*) 4 (sin (* deg pi 1/180)))
rot-y* rot-y-inc*))))
#|================================================================|
| Event queue |
|================================================================|#
(define-record-type event
(fields type time))
(define-record-type mouse-button-event
(parent event) (fields button action)
(protocol
(lambda (new)
(lambda (time button action)
((new 'mouse-button time) button action)))))
(define-record-type mouse-move-event
(parent event) (fields x y)
(protocol
(lambda (new)
(lambda (time x y)
((new 'mouse-move time) x y)))))
(define (mouse-button-callback event-queue)
(lambda (window button action mods)
(let ([action* (case action
[(GLFW_PRESS) 'press]
[(GLFW_RELEASE) 'release]
[else 'other])]
[button* (case button
[(GLFW_MOUSE_BUTTON_LEFT) 'left]
[(GLFW_MOUSE_BUTTON_RIGHT) 'right]
[(GLFW_MOUSE_BUTTON_MIDDLE) 'middle]
[else 'other])])
(set-box! event-queue
(enqueue (unbox event-queue)
(make-mouse-button-event (glfw-get-time) button* action*))))))
(define (cursor-position-callback event-queue)
(lambda (window x y)
(set-box! event-queue
(enqueue (unbox event-queue)
(make-mouse-move-event (glfw-get-time) x y)))))
(define (reshape-callback event-queue)
(lambda (window w h)
(let* ([projection (l:4x4:perspective (* 2 (atan RADIUS 200))
(/ w h) 1 VIEW-SCENE-DIST)]
[eye (g:. 0 0 VIEW-SCENE-DIST)]
[center (g:. 0 0 0)]
[up (g:> 0 -1 0)]
[view (l:4x4:look-at eye center up)])
(gl:check glViewport 0 0 w h)
(gl:check glMatrixMode GL_PROJECTION)
(gl:check glLoadMatrixf (l:matrix-data projection))
(gl:check glMatrixMode GL_MODELVIEW)
(gl:check glLoadMatrixf (l:matrix-data view)))))
(define (key-callback event-queue)
(lambda (window key scancode action mods)
(when (= action GLFW_PRESS)
(cond
[(and (= key GLFW_KEY_ESCAPE) (zero? mods))
(glfw-set-window-should-close window GLFW_TRUE)]
[(or (and (= key GLFW_KEY_ENTER) (= mods GLFW_MOD_ALT))
(and (= key GLFW_KEY_F11) (= mods GLFW_MOD_ALT)))
(format #t "Full-screen mode is not yet implemented.")]))))
#|================================================================|
| Drawing the ball |
|================================================================|#
(define (generate-uv-sphere r m n)
(let ([v (lambda (i j)
(spherical->cartesian
r (* (/ i m) pi) (* (/ j n) 2 pi)))])
(apply append
(map-range (lambda (i)
(map-range (lambda (j)
(let ([c (odd? (+ i j))])
(make-polygon
(list (v i j) (v i (inc j))
(v (inc i) (inc j)) (v (inc i) j)) c)))
n))
m))))
(define (draw-boing-ball ball layer)
(gl:check glPushMatrix)
(gl:check glMatrixMode GL_MODELVIEW)
(gl:check glTranslatef 0.0 0.0 DIST-BALL)
(with-ball ball
(gl:check glTranslatef x y 0.0))
(when (eq? layer 'shadow)
(apply glTranslatef SHADOW-OFFSET))
(with-ball ball
(gl:check glRotatef -20.0 0.0 0.0 1.0)
(gl:check glRotatef rot-y 0.0 1.0 0.0))
(gl:check glCullFace GL_FRONT)
(gl:check glEnable GL_CULL_FACE)
(gl:check glEnable GL_NORMALIZE)
(let ([sphere (generate-uv-sphere RADIUS M-BANDS N-BANDS)])
(if (eq? layer 'shadow)
(begin
(gl:check glColor3f 0.35 0.35 0.35)
(for-each gl:draw-polygon sphere))
(for-each
(lambda (p)
(if (polygon-info p)
(gl:check glColor3f 0.80 0.10 0.10)
(gl:check glColor3f 0.95 0.95 0.95))
(gl:draw-polygon p))
sphere)))
(gl:check glPopMatrix))
#|================================================================|
| Draw grid |
|================================================================|#
(define (demo:draw-grid)
(gl:check glPushMatrix)
(gl:check glDisable GL_CULL_FACE)
(gl:check glTranslatef 0.0 0.0 DIST-BALL)
(for-range (lambda (col)
(let* ([xl (* (- (/ col 12) 1/2) GRID-SIZE)]
[xr (+ xl 2)]
[yt (* 1/2 GRID-SIZE)]
[yb (- (* -1/2 GRID-SIZE) 2)]
[z -40])
(glColor3f 0.6 0.1 0.6)
(gl:draw-polygon
(make-polygon (list (g:. xr yt z) (g:. xl yt z)
(g:. xl yb z) (g:. xr yb z))))))
13)
(for-range (lambda (row)
(let* ([yt (* (- 1/2 (/ row 12)) GRID-SIZE)]
[yb (- yt 2)]
[xl (* -1/2 GRID-SIZE)]
[xr (+ (* 1/2 GRID-SIZE) 2)]
[z -40])
(glColor3f 0.6 0.1 0.6)
(gl:draw-polygon
(make-polygon (list (g:. xr yt z) (g:. xl yt z)
(g:. xl yb z) (g:. xr yb z))))))
13)
(gl:check glPopMatrix))
#|================================================================|
| Main program |
|================================================================|#
(define (demo:init)
(glClearColor 0.55 0.55 0.55 0.0)
(glShadeModel GL_FLAT))
(define (demo:display world)
(gl:check glClear (bitwise-ior GL_COLOR_BUFFER_BIT GL_DEPTH_BUFFER_BIT))
(gl:check glPushMatrix)
(with-world world
(draw-boing-ball ball 'shadow)
(demo:draw-grid)
(draw-boing-ball ball 'ball))
(gl:check glPopMatrix)
(gl:check glFlush))
(define (demo:handle-events event-queue*)
(let loop ([event-queue (unbox event-queue*)]
[code id])
(if (queue-empty? event-queue)
(begin (set-box! event-queue* event-queue)
code)
(receive (value event-queue) (dequeue event-queue)
(loop event-queue code)))))
(define (demo:main-loop program world event-queue)
(display "Entering main loop.") (newline)
(let loop ([program program]
[world world])
(with-world world
(when (glfw-window-should-close window)
(display "Ordered to close.") (newline)
(exit))
(when (psq-empty? program)
(display "Reached end of program.") (newline) (exit))
;;; find the scheduled time of the next event in the queue
(let* ([time (glfw-get-time)]
[due (psq-min-priority program)]
[wait (- due time)])
;;; if the wait is long enough, wait for an external event, loop
(if (> wait 1e-4)
(begin
(glfw-wait-events-timeout wait)
(loop ((demo:handle-events event-queue) program) world))
;;; else handle the event, loop
(receive (moment program) (psq-pop program)
(receive (code world) (moment world due)
(loop (code program) world))))))))
(define (schedule code moment time)
(lambda (program)
(code (psq-set program moment time))))
(define (demo:moment world due)
(with-world world
(demo:display world)
(glfw-swap-buffers window)
(values
(schedule id demo:moment (+ due 1/25))
(update-world world (ball (bounce-ball ball 1/25))))))
(define (demo:setup init main-loop)
(unless (glfw-init)
(exit))
(format #t "Initialised GLFW: ~a\n" (glfw-get-version-string))
(glfw-set-error-callback (lambda (errc msg)
(format #t "ERROR ~a: ~a" errc msg)))
(let ((window (glfw-create-window
400 400 "Boing (classic Amiga demo)" 0 0))
(event-queue (box (make-queue))))
(unless window
(glfw-terminate)
(exit))
(glfw-set-window-aspect-ratio window 1 1)
;;; Set callback functions
(glfw-set-window-close-callback window
(lambda (w) (format #t "Goodbye!\n")))
(glfw-set-framebuffer-size-callback
window (reshape-callback event-queue))
(glfw-set-key-callback
window (key-callback event-queue))
(glfw-set-mouse-button-callback
window (mouse-button-callback event-queue))
(glfw-set-cursor-pos-callback
window (cursor-position-callback event-queue))
(format #t "Initialised OpenGL context.\n")
(glfw-set-input-mode window GLFW_STICKY_KEYS GLFW_FALSE)
(glfw-make-context-current window)
(glfw-swap-interval 1)
(receive (width height) (glfw-get-framebuffer-size window)
((reshape-callback event-queue) window width height))
(glfw-set-time 0.0)
(init)
(main-loop
((schedule id demo:moment 0.0) (make-psq (on < equal-hash) <))
(make-world
window
(make-window-geometry 400 400)
(make-ball (- RADIUS) (- RADIUS) 1.0 2.0 0.0 5.0)
(make-cursor 0 0))
event-queue)
(glfw-terminate)))
(demo:setup demo:init demo:main-loop)
| false |
6d256d60ef0ff459a3e5dcf9bf81b18592cb9b88 | 000dbfe5d1df2f18e29a76ea7e2a9556cff5e866 | /ext/crypto/crypto/spi.scm | 9af919a4169180e7041d14a9d82d5f7c76d6dc8f | [
"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 | 5,903 | scm | spi.scm | ;;; -*- mode:scheme; coding:utf-8; -*-
;;;
;;; crypto/spi.scm - Cipher SPI
;;;
;;; Copyright (c) 2022 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.
;;;
;; just for backward compatible
#!deprecated
#!nounbound
(library (crypto spi)
(export <legacy-crypto>
legacy-cipher-spi? <legacy-cipher-spi>
legacy-builtin-cipher-spi?
cipher-spi-name cipher-spi-key cipher-spi-encrypt
cipher-spi-decrypt cipher-spi-padder cipher-spi-signer
cipher-spi-verifier cipher-spi-keysize cipher-spi-data
cipher-spi-blocksize cipher-spi-iv cipher-spi-update-aad
cipher-spi-tag cipher-spi-tagsize
make-builtin-cipher-spi
cipher-spi-descriptor
legacy-cipher? <legacy-cipher>
cipher-spi
cipher-blocksize
lookup-cipher-spi
register-spi
)
(import (rnrs)
(clos user)
(sagittarius crypto descriptors)
(sagittarius crypto parameters)
(sagittarius crypto ciphers symmetric))
(define-class <legacy-crypto> () ())
(define-class <legacy-cipher-spi> (<legacy-crypto>)
((name :init-keyword :name :reader cipher-spi-name)
(key :init-keyword :key :reader cipher-spi-key :init-value #f)
(encrypt :init-keyword :encrypt :reader cipher-spi-encrypt)
(decrypt :init-keyword :decrypt :reader cipher-spi-decrypt)
(padder :init-keyword :padder :reader cipher-spi-padder)
(signer :init-keyword :signer :reader cipher-spi-signer)
(verifier :init-keyword :verifier :reader cipher-spi-verifier)
(keysize :init-keyword :keysize :reader cipher-spi-keysize)
(data :init-keyword :data :reader cipher-spi-data)
(blocksize :init-keyword :data :reader cipher-spi-blocksize)
(iv :init-keyword :iv :reader cipher-spi-iv)
(update-aad :init-keyword :update-aad :reader cipher-spi-update-aad)
(tag :init-keyword :tag :reader cipher-spi-tag)
(tagsize :init-keyword :tagsize :reader cipher-spi-tagsize)))
(define (legacy-cipher-spi? o) (is-a? o <legacy-cipher-spi>))
(define-class <legacy-builtin-cipher-spi> (<legacy-cipher-spi>)
((descriptor :init-keyword :descriptor :reader cipher-spi-descriptor)))
(define (legacy-builtin-cipher-spi? o) (is-a? o <legacy-builtin-cipher-spi>))
(define-class <legacy-cipher> (<legacy-crypto>)
((spi :init-keyword :spi :reader cipher-spi)))
(define (legacy-cipher? o) (is-a? o <legacy-cipher>))
(define-generic cipher-blocksize)
(define-method cipher-blocksize ((d <block-cipher-descriptor>))
(block-cipher-descriptor-block-length d))
(define-method cipher-blocksize ((c <legacy-builtin-cipher-spi>))
(block-cipher-descriptor-block-length (cipher-spi-descriptor c)))
(define-method cipher-blocksize ((c <legacy-cipher>))
(cipher-blocksize (cipher-spi c)))
(define-generic lookup-cipher-spi)
(define-method lookup-cipher-spi (o) #f)
(define (make-builtin-cipher-spi desc mode key iv rounds padder ctr-mode)
(let ((cipher (make-block-cipher desc mode padder))
(parameter (apply make-cipher-parameter
(filter values (list (and iv (make-iv-parameter iv))
(make-counter-mode-parameter ctr-mode)
(make-round-parameter rounds))))))
;; dummy direction... another reason why we must replace this
;; legacy
(block-cipher-init! cipher (cipher-direction encrypt) key parameter)
(make <legacy-builtin-cipher-spi>
:descriptor desc
:name (cipher-descriptor-name desc)
:key key
:iv iv ;; fake
:encrypt (block-encrypt cipher parameter)
:decrypt (block-decrypt cipher parameter)
:signer (lambda ignore
(error 'cipher-signature
"Symmetric cipher doesn't not support signing"))
:verifier (lambda ignore
(error 'cipher-verify
"Symmetric cipher doesn't not support verify"))
:keysize (lambda (ignore)
(block-cipher-descriptor-suggested-key-length desc))
:data #f
:block-size (block-cipher-descriptor-block-length desc)
:update-aad (lambda (aad . opts)
(apply block-cipher-update-aad! cipher aad opts))
:tag (lambda (tag) (block-cipher-done/tag! cipher tag))
:tagsize (block-cipher-max-tag-length cipher))))
(define ((block-encrypt cipher parameter) bv len key)
(slot-set! cipher 'direction (cipher-direction encrypt))
(block-cipher-encrypt-last-block cipher bv))
(define ((block-decrypt cipher parameter) bv len key)
(slot-set! cipher 'direction (cipher-direction decrypt))
(block-cipher-decrypt-last-block cipher bv))
(define-syntax register-spi
(syntax-rules ()
((_ name class)
(define-method lookup-cipher-spi ((m (eql name))) class))))
)
| true |
108a1ccf878772136ca53ff96165194ede97b98f | 958488bc7f3c2044206e0358e56d7690b6ae696c | /scheme/digital/wire.scm | 0f689f3bcb0ee05b131505fe5510e483aba7f36c | []
| no_license | possientis/Prog | a08eec1c1b121c2fd6c70a8ae89e2fbef952adb4 | d4b3debc37610a88e0dac3ac5914903604fd1d1f | refs/heads/master | 2023-08-17T09:15:17.723600 | 2023-08-11T12:32:59 | 2023-08-11T12:32:59 | 40,361,602 | 3 | 0 | null | 2023-03-27T05:53:58 | 2015-08-07T13:24:19 | Coq | UTF-8 | Scheme | false | false | 6,482 | scm | wire.scm | (load "global.scm")
(define wire
;; should be called 'make-wire'. This is a constructor procedure returning
;; object via its message passing interface.
;; wire object has three possible states. The current state is encoded by
;; the value of 'signal' which can be '(), #f or #t.
;; the variable 'owner' is '() if and only if 'signal' is '().
;; the variable 'owner' represents the part of the circuit which imposes
;; the value of 'signal' to be #t or #f.
;;
;; private static members
;;
;; The procedure will be called on a wire's actions list after change of state
(letrec ((call-each
(lambda (procs)
(if (null? procs)
'done
(begin
((car procs)) ; exexcuting first procedure in list
(call-each (cdr procs))))))
;;
(show-tag
(lambda (source)
(cond ((eq? source '()) '())
((symbol? source) source)
(else (source 'get-tag)))))
;; used in debuggin mode
(dump
(lambda (wire value source)
(if (and (not (global 'unit-test?)) (global 'debug?))
(begin
(display "Time: ")
(display (global 'now))
(display "\t ")
(display "Wire: ")
(display (wire 'get-tag))
(display "\t")
(display "Current: ")
(display (wire 'get-signal))
(display "\t")
(display "Owner: ")
(display (wire 'owner-tag))
(display "\t")
(display "Attempt: ")
(display value)
(display "\t")
(display "By: ")
(display (show-tag source))
(newline))))))
;;
;; Using construct (define wire .. (let[rec] ...(lambda () ...
;; rather than the more readable (define (wire) (define ...
;; so as to allow the definition of static members, i.e.
;; procedures which are common to all instances of wires
(lambda()
;;
;; private data
(define signal '()) ; three possible values: '() (not set), #f or #t
(define owner '()) ; '() unless signal is set to #f ot #t
(define actions '()) ; list of procedures to be executed on change of state
(define tag '?) ; tag used mainly for debugging purposes
(define loop-count 0)
;;
;; public interface
(define (dispatch m)
(cond ((eq? m 'get-signal) signal)
((eq? m 'set-signal!) set-signal!)
((eq? m 'add-action!) add-action!)
((eq? m 'set-tag!) set-tag!) ; setting tag allows better debugging
((eq? m 'get-tag) tag) ; mainly used for debugging
((eq? m 'probe!) (probe!)) ; ensures notification of change of state
((eq? m 'owner-tag) (show-tag owner))
((eq? m 'actions) actions)
(else (display "wire: unknown operation error\n"))))
;;
;; private members
;;
;; add action to the wire's actions list, the effect of which is to notify
;; user whenever a change of state occurs.
(define (probe!)
(let ((action (lambda ()
(display "===========> ")
(display "Time: ") (display (global 'now)) (display ", ")
(display "wire-") (display tag) (display ": ")
(display signal)
(display ", owner: ") (display (show-tag owner))
(newline))))
(add-action! action)))
;;
;; add-action!
(define (add-action! proc)
(set! actions (cons proc actions))
(proc)) ; new action is executed when added to list
;;
;; set-tag!
(define (set-tag! t)
(set! tag t))
;;
;; set-signal!
;; Request for a change of state to 'value' from authority 'source'
;; No action is taken unless request actually constitutes a change of state.
;; Request is granted if wire not set, and new ownership is set
;; Request is granted if coming from source which holds ownership
;; Ownership is relinquished if requested signal is '() (unset)
;; Granted requests are followed by running all of wire's actions
;; which typically notify connected wires of its change of state
;; and may also notify user (if the 'probe!' method has been called prior)
;; Request from third party is ignored if attempting to set '()
;; Request from third party is rejected if attempting to set #f or #t.
;; Since such a request constitutes a change of state to #f or #t from
;; a current state of #f or #t, it constitutes a contradiction.
(define (set-signal! value source)
(dump dispatch value source) ; comment out to remove debugging
(if (not (eq? signal value)) ; no action taken unless state changes
(cond ((eq? owner '()) ; case 1: wire not currently constrained
;; This should never happen
(if(not(eq? signal '()))(display "wire: inconsistent state error\n"))
;; signal must be '() while value must be #f or #t at this point
(set! signal value) ; accepting new signal value
(set! owner source) ; new owner
(set! loop-count 0)
(call-each actions))
((eq? owner source) ; case 2: change of state requested by owner
;; This should never happen
(if (eq? signal '())(display "wire: inconsistent state error\n"))
;; signal cannot be '() while value may be anything except signal
(set! signal value) ; accepting new signal value
(if (eq? value '()) (set! owner '())); constraint relinquished if '()
(set! loop-count 0)
(call-each actions))
(else ; case 3: change of state requested by third party
;; This should never happen since owner exists
(if (eq? signal '()) (display "wire: inconsistent state error\n"))
;; Attempting to set conflicting value is an error
(if (not(eq? value '()))
((global 'error!) "===========> wire: short circuit error\n")
;; experimental line just added
(begin (set! loop-count (+ 1 loop-count))
(if (< loop-count 2) (call-each actions))))))))
;)))))
;;
;; returning public interface
dispatch)))
| false |
8b96c0a971bb82a57ef5d29af9453f1843990cd8 | f59b3ca0463fed14792de2445de7eaaf66138946 | /section-5/5_27.scm | fb0b095621b7e3c14e31cb9f3f493766d8783262 | []
| 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 | 386 | scm | 5_27.scm | (load "./eceval")
(define (factorial n)
(if (= n 1)
1
(* (factorial (- n 1)) n)))
;; n = 1 -> p = 16 m = 8
;; n = 2 -> p = 48 m = 13
;; n = 3 -> p = 80 m = 18
;; n = 4 -> p = 112 m = 23
;; n = 5 -> p = 144 m = 28
;; 再帰的階乗
;; 最大深さ: (5 * n) + 3 プッシュ回数: (32 * n) - 16
;; 反復的階乗
;; 最大深さ: 10 プッシュ回数: (35 * n) + 34
| false |
780aabb2ba1fa45ae977815c93742ac533ffe8ae | defeada37d39bca09ef76f66f38683754c0a6aa0 | /UnityEngine/unity-engine/header-attribute.sls | e3ade70aa759ee9f2481ec712f45ffba369ced19 | []
| 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 | 494 | sls | header-attribute.sls | (library (unity-engine header-attribute)
(export new is? header-attribute? header)
(import (ironscheme-clr-port))
(define-syntax new
(lambda (e)
(syntax-case e ()
((_ a ...) #'(clr-new UnityEngine.HeaderAttribute a ...)))))
(define (is? a) (clr-is UnityEngine.HeaderAttribute a))
(define (header-attribute? a) (clr-is UnityEngine.HeaderAttribute a))
(define-field-port
header
#f
#f
()
UnityEngine.HeaderAttribute
header
System.String))
| true |
bebef359c3781a546d4c1b010d24e57d0f517d79 | 0e98dc0001054c35654c10b8abf50941bec64e06 | /src/sasm/arch/x86/framework.sls | 2861476dc1b010cd76e6e25d39c0604a54205a70 | []
| 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 | 15,795 | sls | framework.sls | ;;; -*- mode:scheme; coding: utf-8; -*-
;;;
;;; sasm/arch/x86/framework - Framework for x86
;;;
;;; 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
;; references:
;; - Intel® 64 and IA-32 Architectures Software Developer’s Manual
;; Volume 2 (2A, 2B & 2C): Instruction Set Reference, A-Z
;; - http://www.c-jump.com/CIS77/CPU/x86/lecture.html
(library (sasm arch x86 framework)
(export define-x86-mnemonic
define-mnemonic ;; needed for x64 framework
define-register
register?
register-bits
register-name
register-index
register+displacement?
make-relocation-address ;; for x64 framework
relocation-address?
;; addressing
&
rel
)
(import (rnrs)
(rnrs mutable-pairs)
(sasm arch conditions))
(define-syntax define-x86-mnemonic
(syntax-rules ()
((_ name opcodes ...)
(define-mnemonic name x86 opcodes ...))))
;; TODO
(define (x86 opcodes operands args) '())
(define-syntax define-mnemonic
(syntax-rules ()
((_ "parse" name prefixer
((prefix op pf op2 extop s d ds modrm? immds ext (operands ...))
rest ...)
(defs ...))
(define-mnemonic "parse" name prefixer (rest ...)
;; (type applicable? encode)
(((lambda () 'ext)
'(operands ...)
(lambda (args)
(mnemonic-encode (lambda (oc opr a) (prefixer 'name oc opr a))
'(prefix
op
pf
op2)
s d
'ds
extop
modrm?
'immds
'(operands ...) args)))
defs ...)))
((_ "parse" name prefixer () ((type operands encoder) ...))
;; TODO how to check type?
(define name
(let ((procs (list (cons operands encoder) ...)))
(lambda args
(let ((applicables (find-applicable procs args)))
(if (null? applicables)
(mnemonic-error 'name 'name "invalid operands" args)
(let ((sorted (sort-applicable applicables)))
((cdar sorted) args))))))))
((_ name prefixer opcodes ...)
(define-mnemonic "parse" name prefixer (opcodes ...) ()))))
(define-record-type register
(fields name ;; for debug
kind index bits)
(protocol
(lambda (p)
(lambda (name kind index bits ext8bit?)
;; bits must be power of 2
(assert (zero? (bitwise-and bits (- bits 1))))
(p name kind (bitwise-ior index (if ext8bit? #x80 0)) bits)))))
(define-record-type register+displacement
(fields displacement
offset ;; pair of offset register+scalar multiplier or #f
)
(parent register)
(protocol
(lambda (p)
(lambda (reg displacement offset)
(assert (integer? displacement))
(let ((n (p (register-name reg) (register-kind reg)
(register-index reg) (register-bits reg) #f)))
(n displacement offset))))))
(define-record-type address
(fields address))
(define-record-type relocation-address
(fields type ;; v/q. v: 32 bit, q: 64 bit (may not be needed)
label)
(parent address)
(protocol
(lambda (p)
(lambda (type label)
;; set address 0 for my convenience.
;; this value will be used to emit address displacement
((p 0) type label)))))
;; this is for 32 bit
(define (rel label) (make-relocation-address 'v label))
(define &
(case-lambda
((reg) (if (register? reg) (& reg 0) (make-address reg)))
((reg disp) (& reg disp #f))
((reg disp offset) (& reg disp offset 0))
((reg disp offset multiplier)
(make-register+displacement reg disp
(if offset (cons offset multiplier) #f)))))
(define-syntax define-register
(syntax-rules ()
((_ name kind index bit)
(define-register name kind index bit #f))
((_ name kind index bit ext8bit?)
(define name (make-register 'name 'kind index bit ext8bit?)))))
;; FIXME we are using too much definition from
;; http://ref.x86asm.net/
;; gen-instr.scm should convert them to more understandable
;; values.
(define (find-applicable procs args)
(let loop ((procs procs) (r '()))
(cond ((null? procs) r)
((mnemonic-applicable? (caar procs) args)
(loop (cdr procs) (cons (car procs) r)))
(else (loop (cdr procs) r)))))
(define (sort-applicable procs)
;; TODO support properly
(define *immediate-size*
'((b . 1) (bs . 1) (bss . 1) (w . 2) (d . 4) (ds . 4) (q . 8)
(v . 4) (vs . 4) (vds . 4) (vqp . 8)
;; dummy for specific register one
(#f . 100)))
;;(display procs) (newline)
;; by operand size
(list-sort (lambda (a b)
(let ((ao (car a))
(bo (car b)))
(< (fold-left + 0
(map (lambda (o)
(cdr (assq (cadr o) *immediate-size*)))
ao))
(fold-left + 0
(map (lambda (o)
(cdr (assq (cadr o) *immediate-size*)))
bo)))))
procs))
(define (mnemonic-applicable? operands args)
(define (check-operand operand arg)
(define (check-type operand arg)
(case (cadr operand)
((b) ;; byte
(cond ((register? arg) (= (register-bits arg) 8))
((integer? arg) (or (<= 0 arg 255)))
(else #f)))
((bs) ;; byte
(cond ((register? arg) (= (register-bits arg) 8))
((integer? arg) (or (<= -128 arg 127)))
(else #f)))
((vds)
(cond ((register? arg) (<= (register-bits arg) 32))
;; depending on the other operand (register) ...
((integer? arg) (<= #x-80000000 arg #x7FFFFFFF))
((symbol? arg)) ;; near jump/call
(else #f)))
((vqp) ;; FIXME
(cond ((register? arg))
;; depending on the other operand (register) ...
((integer? arg)) ;; FIXME
((address? arg)) ;; address?
(else #f)))
;; ((v) (address? arg)) ;; TODO support this properly
((q)
;; TODO address thing
(cond ((register? arg) (= (register-bits arg) 64))
((integer? arg) (<= arg #xFFFFFFFFFFFFFFFF))
((address? arg))
((symbol? arg)) ;; far label
(else #f)))
((#f) #t) ;; no type specified thus a specific register.
(else #f)))
(define (check-address operand arg)
(case (car operand)
((E) ;; general purpose register or address
;; TODO memory address
;; symbol: label
;; integer: direct address?
(or (and (register? arg) (eq? (register-kind arg) 'reg))
(address? arg) ;; address
(symbol? arg)))
((G Z)
(and (and (register? arg) (not (register+displacement? arg)))
(eq? (register-kind arg) 'reg)))
;; special registers
((AL) ;; al register...
(and (register? arg)
(eq? (register-kind arg) 'reg)
(= (register-bits arg) 8)
(= (register-index arg) 0)))
((rAX) ;; AX, EAX and RAX
(and (register? arg)
(eq? (register-kind arg) 'reg)
(> (register-bits arg) 8) ;; more than 8bit
(= (register-index arg) 0)))
((I) (integer? arg)) ;; immediate
;; label (no body can know relative offset from assembly!)
((J) (symbol? arg))
(else #f)))
(and (check-address operand arg)
(check-type operand arg)))
(define (check-operands operands args)
(let loop ((operands operands) (args args))
(or (null? operands)
(and (check-operand (car operands) (car args))
(loop (cdr operands) (cdr args))))))
(and (= (length operands) (length args))
(check-operands operands args))
)
;; Returns 2 values
;; - bytevector: code
;; - symbol: label (if there is otherwise #f)
;; opcodes contains u8 and #f including prefix to secondary opcode
;; TODO refactor it
(define (mnemonic-encode prefixer
opcodes s d ds extop modrm? immds operands args)
(define (parse-operands operands args)
(let loop ((operands operands)
(args args)
(rex '()))
(if (null? operands)
(values (reverse rex))
(let ((operand (car operands)) (arg (car args)))
;; TODO this might not be enough
(cond ((and (register? arg) (= (register-bits arg) 64)
(memq (cadr operand) '(dqp vqp ptp)))
(loop (cdr operands) (cdr args) (cons arg rex)))
(else (loop (cdr operands) (cdr args) rex)))))))
(define (compose-rex rex modrm sib args)
(if (null? rex)
#f
(let ((r/m (if (and d (= d 1)) (cadr args) (car args))))
(bitwise-ior #x48
(if (exists (lambda (reg)
(> (register-index reg) 8)) rex)
#x4
#x0)
(if (and sib
(register+displacement? r/m)
(register+displacement-offset r/m)
(>= (register-index
(car (register+displacement-offset
r/m))) 8))
#x2
#x0)
(if (and (or sib modrm)
(register? r/m)
(>= (register-index r/m) 8))
#x1
#x0)))))
(define (imm->disp imm)
(cond ((zero? imm) #x00)
((< imm #xFF) #x40)
((< imm #xFFFFFFFF) #x80)
(else #x00))) ;; mod.disp32?
(define (compose-modrm operands args extop)
;; TODO can we assume the args has at least 2 elements?
;; we also need to consider direction here. fxxk!!!
(let ((r/m (if (and d (= d 1))
(and (pair? (cdr args)) (cadr args))
(car args)))
(reg (if (and d (= d 1))
(car args)
(and (pair? (cdr args)) (cadr args)))))
(bitwise-ior (cond ((register+displacement? r/m)
(imm->disp
(register+displacement-displacement r/m)))
((register? r/m) #xc0)
((integer? reg) (imm->disp reg))
((address? r/m) #x00) ;; addressing mode
;; must be an integer, then
(else (imm->disp r/m)))
(cond (extop (bitwise-arithmetic-shift-left extop 3))
((register? reg)
(bitwise-arithmetic-shift-left (register-index reg)
3))
(else 0))
(cond ((and (register+displacement? r/m)
(register+displacement-offset r/m))
;; SIB
#x04)
((register? r/m)
(bitwise-and (register-index r/m) #x07))
((address? r/m)
(if (relocation-address? r/m)
#x05 ;; disp+rip (64 bit)
#x04)) ;; displacement only
(else 0)))))
(define (compose-sib operands args)
(let ((r/m (if (and d (= d 1)) (cadr args) (car args))))
(if (register+displacement? r/m)
(let* ((offset (register+displacement-offset r/m))
(reg (car offset))
(multiplier (cdr offset)))
(bitwise-ior (case multiplier
((1) #x00)
((2) #x40)
((4) #x80)
((8) #xc0)
(else (mnemonic-error 'SIB 'SIB
"invalid multiplier for SIB"
multiplier)))
(bitwise-arithmetic-shift-left
(bitwise-and (register-index reg) #x07) 3)
(bitwise-and (register-index r/m) #x07)))
;; address
;; scale = 00
;; index = 100 (invalid)
;; base = 101 (displacement only)
#b00100101
)))
(define (->u8-list m count)
(define (ensure-integer m)
(if (address? m)
(address-address m)
m))
(let loop ((m (ensure-integer m)) (r '()) (i 0))
(if (= i count)
(reverse r)
(loop (bitwise-arithmetic-shift-right m 8)
(cons (bitwise-and m #xff) r)
(+ i 1)))))
(define (displacement operands args size)
;; For now, assume the second argument has displacement
(if size
(let ((arg (if (null? (cdr args)) (car args) (cadr args))))
(cond ((register+displacement? arg)
(->u8-list (register+displacement-displacement arg) size))
((address? arg) (->u8-list (address-address arg) size))
;; assume integer
(else (->u8-list arg size))))
'()))
(define (immediate r64? operands args)
;; I beleive there is only one immediate value in operands
(let loop ((operands operands) (args args))
(if (null? operands)
'()
(case (caar operands)
((I)
(case (cadar operands)
((b bs) (->u8-list (car args) 1))
((w) (->u8-list (car args) 2))
((l vds) (->u8-list (car args) 4))
((q) (->u8-list (car args) 8))
((vqp)
(if r64?
(->u8-list (car args) 8)
(->u8-list (car args) 4)))
(else (assert #f))))
((J)
;; near jump/call will be fixup by bin format
(case (cadar operands)
((vds) '(0 0 0 0))
((q) '(0 0 0 0 0 0 0 0))
(else (assert #f))))
(else (loop (cdr operands) (cdr args)))))))
(define (merge-reg-if-needed opcodes operands args)
(define (last-pair p)
(let loop ((p p))
(cond ((null? p) '())
((null? (cdr p)) p)
(else (loop (cdr p))))))
(let loop ((operands operands) (args args))
(if (null? operands)
opcodes
(case (caar operands)
((Z)
(let ((p (last-pair opcodes)))
(set-car! p (bitwise-ior (car p) (register-index (car args))))
opcodes))
(else (loop (cdr operands) (cdr args)))))))
;; Intel 64 and IA32 Architectures Software Developer's Manual
;; Volume 2, Table 2-2.
;; TODO should we also support 16bit addressing mode?
(define (sib/disp? modrm)
(if modrm
(let ((mod (bitwise-arithmetic-shift-right modrm 6))
(rm (bitwise-and modrm #x07)))
(case mod
((#x00) (case rm
((#x04) (values #t #f))
((#x05) (values #f 4)) ;; disp32
(else (values #f #f))))
((#x01) (case rm
((#x04) (values #t #f))
(else (values #f 1))))
((#x02) (case rm
((#x04) (values #t #f))
(else (values #f 4))))
(else (values #f #f))))
(values #f #f)))
(define (find-disp-size modrm sib)
(and sib
(case (bitwise-and sib #x07)
((#x05)
(case (bitwise-arithmetic-shift-right modrm 6)
((#x00) 4)
((#x01) 1)
((#x02) 4)
(else #f)))
(else #f))))
(define (find-label operands args)
;; for now very simple
(let ((labels (filter (lambda (s) (or (symbol? s)
(relocation-address? s)))
args)))
;; I don't think there would multiple labels but for
;; my convenience.
(and (not (null? labels))
labels)))
(let ((rex (parse-operands operands args))
(opcode (merge-reg-if-needed (filter values opcodes) operands args))
(modrm (and modrm? (compose-modrm operands args extop))))
(let*-values (((has-sib? disp-size) (sib/disp? modrm))
((sib) (and has-sib?
(compose-sib operands args)))
((rex.prefix) (compose-rex rex modrm sib args)))
(values (u8-list->bytevector
`(,@(prefixer opcodes operands args)
,@(if rex.prefix (list rex.prefix) '())
,@opcode
,@(if modrm (list modrm) '())
,@(if sib (list sib) '())
,@(displacement operands args
(or disp-size (find-disp-size modrm sib)))
,@(immediate rex.prefix operands args)))
(find-label operands args)))))
)
| true |
fc76cb54033d03a99466745cbbc096037fa2e498 | e274a2d8e7c094faa086f1f0a2a0530fc1113b90 | /ch02/exercise/2.58.scm | 7816c3c850a1a89c8bc9acaec91131001f0fc940 | [
"MIT"
]
| permissive | happyo/sicp | 9b4def6f235ff287fd29dc9b42b0f0fea142bdc1 | baeca9f87560daac58dacd1d548adfec7eaab260 | refs/heads/master | 2021-06-24T15:20:53.986908 | 2020-09-25T07:10:46 | 2020-09-25T07:10:46 | 131,562,767 | 0 | 1 | null | null | null | null | UTF-8 | Scheme | false | false | 474 | scm | 2.58.scm | ;; a,修改constructors 和 selectors 就可以了
(define (make-sum a1 a2)
(cond ((=number? a1 0)
a2)
((=number? a2 0)
a1)
((and (number? a1) (number? a2))
(+ a1 a2))
(else
(list a1 '+ a2))))
(define (sum? x)
(and (pair? x)
(eq? (cadr x) '+)))
(define (addend s)
(car s))
(define (augend s)
(caddr s))
;; 乘法的和加法类似
;; b, 这个改起来很麻烦,答案又没有,所以空着
| false |
39639a7f10ec0437372d798719526671548e880d | 2f88dd127122c2444597a65d8b7a23926aebbac1 | /st-error-obj.scm | fb07a63fc09d795a6d604cf08810717535690bbd | [
"BSD-2-Clause"
]
| permissive | KenDickey/Crosstalk | 6f980b7188c1cc6bd176a8e0cd10b032f768b4e6 | b449fb7c711ad287f9b49e7167d8cedd514f5d81 | refs/heads/master | 2023-05-26T10:07:12.674162 | 2023-05-21T22:59:26 | 2023-05-21T22:59:26 | 58,777,987 | 11 | 1 | null | null | null | null | UTF-8 | Scheme | false | false | 27,492 | scm | st-error-obj.scm | ;;; FILE: "st-error-obj.scm"
;;; IMPLEMENTS: Exception, ExceptionSet, UnhandledError,
;;; Error, Notification, Warning,
;;; Message, MessageSend, MessageNotUnderstood.
;;; See also "st-blockClosure.scm" for exception handling code.
;;; See "st-conditions.scm" for #asException
;;; AUTHOR: Ken Dickey
;;; DATE: 08 February 2017
(define ExceptionSet
(newSubclassName:iVars:cVars:
Object
'ExceptionSet '(exceptions) '())
)
(define Exception
(newSubclassName:iVars:cVars:
Object
'Exception
'(receiver messageText myTag
signalContext resignalContext signalExn
handlerContext retryContext blockSetter
conditionDict)
'())
)
; receiver -- nil or the receiver
; signalContext -- Continuation captured at point of #signal
; handlerContext -- Continuation captured at handler invocation in #on:do:
; See "st-blockClosure.scm"
; conditionDict -- nil or an IdentityDictionary/eqHashtable of condition values
;;; Exception>>doesNotUnderstand:
; Allow conditionDict identifiers as selectors to Exceptions
(addSelector:withMethod:
Exception
'doesNotUnderstand:
(lambda (self aMessageSend)
(let ( (condDict ($ self 'conditionDict))
(selector ($ aMessageSend 'selector))
)
(if (and (hashtable? condDict)
(hashtable-contains? condDict selector))
(hashtable-ref condDict selector st-nil)
(@: self 'doesNotUnderstand: aMessageSend)))) ;; super send
)
(define Error
(newSubclassName:iVars:cVars:
Exception
'Error '() '())
)
(define Notification
(newSubclassName:iVars:cVars:
Exception
'Notification '() '())
)
(define Warning
(newSubclassName:iVars:cVars:
Notification
'Warning '() '())
)
(define ArithmeticError
(newSubclassName:iVars:cVars:
Error
'ArithmeticError '() '())
)
(define ZeroDivide
(newSubclassName:iVars:cVars:
ArithmeticError
'ZeroDivide '(dividend) '())
)
(addSelector:withMethod:
(class ZeroDivide)
'dividend:
(lambda (self dvdnd)
(let ( (ex ($ ZeroDivide 'new)) )
($: ex 'receiver: dvdnd)
($: ex 'dividend: dvdnd)
($: ex 'messageText: (format #f "ZeroDivide: ~a / 0" dvdnd))
ex)))
(addSelector:withMethod:
(class ZeroDivide)
'signalWithDividend:
(lambda (self dvdnd)
($ ($: self 'dividend: dvdnd) 'signal)))
(addSelector:withMethod: ;; REDEFINE
Number
'|/|
(lambda (self aNumber)
(when (zero? aNumber)
($: ZeroDivide 'signalWithDividend: self))
(/ self aNumber)))
(define UnhandledError
(newSubclassName:iVars:cVars:
Exception
'UnhandledError '(exception) '())
)
(define IllegalResumeAttempt ;; internal/private
(newSubclassName:iVars:cVars:
Exception
'IllegalResumeAttempt '() '())
)
(define MessageNotUnderstood
(newSubclassName:iVars:cVars:
Error
'MessageNotUnderstood
'(message reachedDefaultHandler)
'())
)
(define MessageSend
(newSubclassName:iVars:cVars:
Object
'MessageSend
'(receiver selector arguments)
'())
)
(define Halt
(newSubclassName:iVars:cVars:
Exception
'Halt '() '())
)
(define AssertionFailure
(newSubclassName:iVars:cVars:
Halt
'AssertionFailure '() '())
)
(set! st-messageSend-behavior ($ MessageSend 'methodDict))
(define Message
(newSubclassName:iVars:cVars:
Object
'Message
'(selector args lookupClass)
'())
)
;;; categoriy:
(perform:with:
ExceptionSet
'category: '|Exceptions Kernel|)
(perform:with:
Exception
'category: '|Exceptions Kernel|)
(perform:with:
Error
'category: '|Exceptions Kernel|)
(perform:with:
Notification
'category: '|Exceptions Kernel|)
(perform:with:
Warning
'category: '|Exceptions Kernel|)
(perform:with:
UnhandledError
'category: '|Exceptions Kernel|)
(perform:with:
IllegalResumeAttempt
'category: '|Exceptions Kernel|)
(perform:with:
MessageNotUnderstood
'category: '|Exceptions Kernel|)
(perform:with:
Halt
'category: '|Exceptions Extensions|)
(perform:with:
AssertionFailure
'category: '|Exceptions Extensions|)
(perform:with:
MessageSend
'category: '|Kernel-Objects|) ;; N.B.
(perform:with:
Message
'category: '|Kernel-Methods|) ;;N.B.
;;; comment:
(perform:with:
ExceptionSet
'comment:
"An ExceptionSet is a grouping of exception handlers
which acts as a guard for a single handler.
Within the group, the most recently added handler
will be the last handler found during a handler search
(in the case where more than one handler in the group
is capable of handling a given exception). ")
(perform:with:
Exception
'comment:
"This is the main class used to implement the exception handling system (EHS).
It plays two distinct roles: that of the exception, and that of the exception handler.
More specifically, it implements the bulk of the protocols laid out in the ANSI
specification - those protocol names are reflected in the message categories.
Exception is an abstract class. Instances should neither be created nor trapped.
In most cases, subclasses should inherit from Error or Notification rather than
directly from Exception.")
(perform:with:
Error
'comment: ;; ANSI
"This protocol describes the behavior of instances of class Error.
These are used to represent error conditions that prevent the
normal continuation of processing.
Actual error exceptions used by an application may be subclasses of this class.
As Error is explicitly specified to be subclassable, conforming implementations
must implement its behavior in a non-fragile manner."
)
(perform:with:
Notification
'comment:
"A Notification is an indication that something interesting has occurred.
If it is not handled, it will pass by without effect.")
(perform:with:
Warning
'comment:
"A Warning is a Notification which by default should be brought
to the attention of the user.")
(perform:with:
UnhandledError
'comment:
"This exception represents an error exception that has gone unhandled.
Unhandled error conditions are fundamentally different from error exceptions,
because error exceptions may have default handlers that address the error
condition (by e.g. retrying the operation).
The job of unhandled errors is to report the original problem.
This reporting can be done in a variety of ways.
For example, in everyday practice, unhandled errors open the debugger.
Note the common practice of \"catching all errors\" with code such as this:
[some code]
on: Error
do: [:ex | ex return]
is doubly problematic.
First, there is no specificity to the expected exceptions arising from the protected block.
Second, the handler block will prevent the exception's default handler from running,
which may resolve or otherwise react to the error condition.
If one really wants to catch unhandled errors, the code should read like this instead:
[some code]
on: UnhandledError
do: [:ex | ex return]"
)
(perform:with:
MessageNotUnderstood
'comment:
"This exception is provided to support Object>>doesNotUnderstand:.")
(perform:with:
MessageSend
'comment:
"Instances of MessageSend encapsulate message sends to objects.
Arguments can be either predefined or supplied when the
message send is performed.
MessageSends are used to implement the #when:send:to: event system.
Use #value to perform a message send with its predefined arguments
and #valueWithArguments: if additonal arguments have to supplied.
Structure:
receiver Object -- object receiving the message send
selector Symbol -- message selector
arguments Array -- bound arguments"
)
(perform:with:
Message
'comment:
"I represent a selector and its argument values.
Generally, the system does not use instances of Message for efficiency reasons.
However, when a message is not understood by its receiver, the runtime system
will make up an instance of me in order to capture the information
involved in an actual message transmission.
This instance is sent it as an argument with the message doesNotUnderstand:
to the receiver."
)
(perform:with:
Halt
'comment:
"Halt is provided to support Object>>halt."
)
(perform:with:
AssertionFailure
'comment:
"AssertionFailure is the exception signaled from Object>>assert:
when the assertion block evaluates to false."
)
(perform:with:
IllegalResumeAttempt
'comment:
"This class is private to the exception implementation.
An instance of it is signaled whenever an attempt is made
to resume from an exception which answers false to #isResumable.")
(addSelector:withMethod:
(class Class)
'handles: ;; base case
(lambda (self anException) st-false))
(addSelector:withMethod:
Object
'handles: ;; base case
(lambda (self anException) st-false))
;;; ExceptionSet
(addSelector:withMethod:
(class ExceptionSet)
'with:with:
(lambda (self exClass1 exClass2)
(let ( (newInst ($ self 'new)) )
($: newInst 'exceptions: (vector exClass1 exClass2))
newInst)))
(addSelector:withMethod:
ExceptionSet
'initialize
(lambda (self)
($: self 'exceptions: '#())
self))
(addSelector:withMethod:
ExceptionSet
'|,|
(lambda (self anExceptionClass)
($: self 'add: anExceptionClass)
self))
(addSelector:withMethod:
ExceptionSet
'add:
(lambda (self anExceptionClass)
($: self
'exceptions:
(vector-append ($ self exceptions) (vector anExceptionClass)))
self))
(addSelector:withMethod:
ExceptionSet
'handles:
(lambda (self anException)
($: ($ self 'exceptions)
'detect:
(lambda (ec) ($: ec 'handles: anException)))))
(addSelector:withMethod:
ExceptionSet
'printOn:
(lambda (self aStream)
($: aStream 'nextPutAll: (className: self))
($: aStream 'nextPutAll: "( " )
($: ($ self 'exceptions)
'do:
(lambda (elt) (format aStream "[~a] " (className: elt))))
($: aStream 'nextPut: #\) ))
)
;;; Exception
(addSelector:withMethod:
(class Exception)
'handles:
(lambda (self anException)
(isKindOf: anException self)))
(addSelector:withMethod:
Exception
'asException
(lambda (self) self))
;; See BlockClosure>>on:do: in "st-blockClosure.scm"
(addSelector:withMethod:
Object
'asException
(lambda (self)
(let ( (ex ($ Error 'new)) )
($: ex 'receiver: self)
($: ex 'messageText: "Huh?: non-exception object #asException")
ex)))
(addSelector:withMethod:
Exception
'isResumable
(lambda (self) st-true))
(addSelector:withMethod:
Exception
'resume:
(lambda (self resumptionValue)
;; "Return resumptionValue as the value of the signal message."
(when (not ($ self 'isResumable))
($ IllegalResumeAttempt 'signal)
($ self 'resumeUnchecked: resumptionValue))))
(addSelector:withMethod:
Exception
'resumeUnchecked:
(lambda (self resumptionValue)
;;##DEBUG{
(when (debug-st-runtime)
(format #t
"~%~a>>resumeUnchecked ~a"
($ self 'printString)
resumptionValue))
;;@@DEBUG}
(($ self 'signalContext) resumptionValue)))
(addSelector:withMethod:
Exception
'resignalAs:
(lambda (self newException)
(let ( (newEx
(if (class? newException)
($ newException 'new)
newException))
)
;;@@@DEBUG{
;;(display-ivars self)
;;@@@DEBUG}
($: newEx 'handlerContext: ($ self 'handlerContext))
($: newEx 'signalContext: ($ self 'signalContext))
($: newEx 'resignalContext: ($ self 'resignalContext))
;; ($: newEx 'conditionDict: ($ self 'conditionDict))
;; ($: newEx 'messageText: ($ self 'messageText))
;;@@@DEBUG{
;;(display-ivars newEx)
;;@@@DEBUG}
($: self 'signalExn: newEx)
( ($ self 'resignalContext) 'resignalAs )
) ) )
(addSelector:withMethod:
Exception
'signal
(lambda (self)
($: self 'signalExn: self)
(call/cc
(lambda (resignal)
($: self 'resignalContext: resignal)))
(call/cc
(lambda (returnToSignal)
($: ($ self 'signalExn) 'signalContext: returnToSignal)
;;@@@DEBUG{
(when (debug-st-runtime)
(format #t "~a" ($ ($ self 'signalExn) 'printString)))
;;@@@DEBUG}
(raise-continuable ($ self 'signalExn))
)))
)
(addSelector:withMethod:
Exception
'signal:
(lambda (self aMessage)
($: self 'messageText: aMessage)
($ self 'signal)))
(addSelector:withMethod:
(class Exception)
'signal
(lambda (self)
($ ($ self 'new) 'signal)))
(addSelector:withMethod:
(class Exception)
'signal:
(lambda (self aMessage)
($: ($ self 'new) 'signal: aMessage)))
(addSelector:withMethod:
(class Exception)
'|,|
(lambda (self exceptionClass)
($:: ExceptionSet 'with:with: self exceptionClass)))
(addSelector:withMethod:
Exception
'tag:
(lambda (self aMessage)
($: self 'myTag: aMessage)
self))
(addSelector:withMethod:
Exception
'tag
(lambda (self)
(let ( (tag ($ self 'myTag)) )
(if (not (st-nil? tag))
tag
($: self 'messageText)))))
(addSelector:withMethod:
Exception
'description
(lambda (self)
(let ( (msg ($ self 'messageText))
(name ($ (className: self) 'asString))
)
(if (st-nil? msg)
name
(string-append name ": " msg)))))
(addSelector:withMethod:
Exception
'defaultAction
(lambda (self)
(make-subclassResponsibility 'defaultAction)))
(addSelector:withMethod:
Exception
'defaultResumeValue
(lambda (self) st-nil))
(addSelector:withMethod:
Exception
'return
(lambda (self)
( ($ self 'handlerContext) st-nil )))
(addSelector:withMethod:
Exception
'return:
(lambda (self aValue)
( ($ self 'handlerContext) aValue )))
(addSelector:withMethod:
Exception
'resume
(lambda (self)
( ($ self 'signalContext) st-nil )))
(addSelector:withMethod:
Exception
'resume:
(lambda (self aValue)
( ($ self 'signalContext) aValue )))
(addSelector:withMethod:
Exception
'retry
(lambda (self)
( ($ self 'retryContext) 'retry ) )) ;; arg ignored
(addSelector:withMethod:
Exception
'retryUsing:
(lambda (self newProtectedBlock)
( ($ self 'blockSetter) newProtectedBlock )
( ($ self 'retryContext) 'retryUsing: ))) ;; arg ignored
(addSelector:withMethod:
Exception
'pass ;; re-raise
(lambda (self)
(raise-continuable self)))
(addSelector:withMethod:
Exception
'outer ;; re-raise, but come back here
(lambda (self)
(let ( (oldSignalContext ($ self 'signalContext)) )
(call/cc
(lambda (return-here)
($: self 'signalContext: return-here)
(raise-continuable self)
($: self 'signalContext: oldSignalContext)))))
)
(addSelector:withMethod:
Exception
'is:
(lambda (self symbol)
(or (eq? symbol 'Exception)
(superPerform:with: self 'is: symbol))))
(addSelector:withMethod:
Exception
'=
(lambda (self other)
(and
(eq? ($ self 'species ) ($ other 'species))
(eq? ($ self 'receiver) ($ other 'receiver))
(eq? ($ self 'selector) ($ other 'selector))
(eqv? ($ self 'arguments) ($ other 'arguments)))))
(addSelector:withMethod:
Exception
'hash
(lambda (self)
(bitwise-xor ($ ($ self 'receiver) 'hash)
($ ($ self 'selector) 'hash))))
(addSelector:withMethod:
Exception
'noHandler
;; "No one has handled this error, but now give them a chance
;; to decide how to debug it.
;; If none handle this either then open debugger (see UnhandedError-defaultAction)"
(lambda (self)
;;@@DEBUG{
(when (debug-st-runtime)
(format #t "~%Exception>>noHandler for ~a~%" ($ self 'description)))
;;@@DEBUG}
($: UnhandledError 'signalForException: self)))
;;; Error
(addSelector:withMethod:
Error
'defaultAction
(lambda (self)
;;@@@DEBUG{
(when (debug-st-runtime)
(format #t "Error defaultAction: noHandler: ~a"
($ self 'printString)))
;;@@@DEBUG}
($ self 'noHandler)))
(addSelector:withMethod:
Error
'isResumable
(lambda (self) st-false))
;;; Notification
(addSelector:withMethod:
Notification
'defaultAction
;; "No action is taken. The value nil is returned as the value
;; of the message that signaled the exception."
(lambda (self)
($: self 'resume: st-nil)))
(addSelector:withMethod:
Notification
'isResumable
(lambda (self) st-true))
;;; Warning
(addSelector:withMethod:
Warning
'defaultAction
(lambda (self)
(format #f "~%Warning: ~a" ($ self 'messageText))
($ self 'resume))
)
;;; UnhandledError
(addSelector:withMethod:
(class UnhandledError)
'signalForException:
(lambda (self anException)
($ ($: ($ self 'new) 'exception: anException) 'signal)))
(addSelector:withMethod:
UnhandledError
'defaultAction
(lambda (self)
;;(when (debug-st-runtime)
(format #t "~%UnhandledError>>defaultAction ~a ~%" self)
(format #t "~%@@FIXME: Log Backtrace OR Open a Debugger @@@")
;; log to file or open debugger
(%%escape%% ($ self 'description)))) ;; open Scheme debugger
(addSelector:withMethod:
UnhandledError
'isResumable
(lambda (self) st-false))
;;; MessageNotUnderstood
(addSelector:withMethod:
MessageNotUnderstood
'initialize
(lambda (self)
(superPerform: self 'initialize)
($: self 'reachedDefaultHandler: st-false)
self))
(addSelector:withMethod:
MessageNotUnderstood
'defaultAction
(lambda (self)
($: self 'reachedDefaultHandler: st-true)
;;@@DEBUG{
(when (debug-st-runtime)
(format #t "~%MessageNotUnderstood defaultAction"))
;;@@DEBUG}
(superPerform: self 'defaultAction)))
(addSelector:withMethod:
MessageNotUnderstood
'isResumable
(lambda (self) st-true))
(addSelector:withMethod:
MessageNotUnderstood
'messageText
(lambda (self)
(let ( (myMessage ($ self 'message)) )
(if (not (null? myMessage))
(format #f
"~a doesNotUnderstand: #~a"
(safer-printString ($ myMessage 'receiver))
($ myMessage 'selector))
(let ( (inherited-msg (superPerform: self 'messageText)) )
(if (null? inherited-msg)
(format #f
"~%~a doesNotUnderstand: <something>"
(safer-printString ($ self 'receiver)) )
inherited-msg)))))
)
;;;; redefine Object>>doesNotUnderstand:
(addSelector:withMethod:
Object
'doesNotUnderstand:
(lambda (self aMessageSend) ;; NB: class == MessageSend
;;@@DEBUG{
(when (debug-st-runtime)
(format #t "~%doesNotUnderstand: ~a ~%" aMessageSend))
;;(safer-printString aMessageSend))
;;@@DEBUG}
(let ( (ex ($ MessageNotUnderstood 'new)) )
($: ex 'message: aMessageSend)
($: ex 'receiver: self)
($: ex 'reachedDefaultHandler: st-false)
(let ( (resumeValue ($ ex 'signal)) )
;;@@DEBUG{
(when (debug-st-runtime)
(format #t "~%doesNotUnderstand>>signal returned: ~a " resumeValue)
(format #t "~%doesNotUnderstand>>reachedDefaultHandler: ~a ~%"
($ ex 'reachedDefaultHandler)))
;;@@DEBUG}
(if ($ ex 'reachedDefaultHandler)
(%%escape%% (format #f
"~a doesNotUnderstand: ~a ~a"
($ ($ aMessageSend 'receiver) 'printString)
($ aMessageSend 'selector)
($ aMessageSend 'arguments)))
;;($: aMessageSend 'sendTo: self) ;; retry
resumeValue)))))
;;;; redefine Object>>error:
(addSelector:withMethod:
Object
'error:
(lambda (self aString)
(let ( (err ($ Error 'new)) )
($: err 'receiver: self)
($: err 'signal: aString))))
;;; MessageSend
(addSelector:withMethod:
(class MessageSend)
'receiver:selector:arguments:
(lambda (self rcvr aSymbol anArray)
(let ( (newInst ($ self 'new)) )
($: newInst 'receiver: rcvr)
($: newInst 'selector: aSymbol)
($: newInst 'arguments: anArray)
newInst)))
(addSelector:withMethod:
(class MessageSend)
'receiver:selector:argument:
(lambda (self rcvr aSymbol anArg)
($::: self
'receiver:selector:arguments:
rcvr
aSymbol
(vector anArg))))
(addSelector:withMethod:
(class MessageSend)
'receiver:selector:
(lambda (self rcvr aSymbol)
($::: self
'receiver:selector:arguments:
rcvr
aSymbol
'#())))
(addSelector:withMethod:
MessageSend
'collectArguments: ;; PRIVATE
;; Answer Array with first N args substituted from new
(lambda (self newArgArray)
(let* ( (origArgArray ($ self 'arguments))
(origArgsLen (vector-length origArgArray))
(newArgsLen (vector-length newArgArray))
)
(cond
((= origArgsLen newArgsLen)
newArgArray
)
((> origArgsLen newArgsLen) ;; drop
(vector-copy newArgArray 0 origArgsLen))
(else ;; (> origArgsLen newArgsLen)
(vector-append newArgArray ;; augment
(vector-copy origArgArray
newArgsLen
origArgsLen)))))))
(addSelector:withMethod:
MessageSend
'resend
(lambda (self)
($:: ($ self 'recevier)
'perform:withArguments:
($ self 'selector)
($ self 'args))))
(addSelector:withMethod:
MessageSend
'sendTo:
(lambda (self newReceiver)
;;@@DEBUG{
(when (debug-st-runtime)
(format #t
"~%** ~a sentTo: ~a"
(safer-printString self)
(safer-printString newReceiver)))
;;@@DEBUG}
($:: newReceiver
'perform:withArguments:
($ self 'selector)
($ self 'args)))
)
(addSelector:withMethod:
MessageSend
'value ;; resend
(lambda (self)
(if (zero? (vector-length ($ self 'arguments)))
(perform: ($ self 'receiver) ($ self 'selector))
(perform:withArguments:
($ self 'recevier)
($ self 'selector)
($: self 'collectArguments: ($ self 'arguments))))))
(addSelector:withMethod:
MessageSend
'value:withArguments: ;; resend with new arguments
(lambda (self anArray)
(perform:withArguments:
($ self 'recevier)
($ self 'selector)
($: self 'collectArguments: anArray))))
(addSelector:withMethod:
MessageSend
'printOn:
(lambda (self aStream)
(format aStream
"~%~a( ~a -> ~a )"
(className: self)
($ self 'selector)
(if (isKindOf: ($ self 'receiver) MessageSend)
"a MessageSend" ;; avoid recursion
($ ($ self 'receiver) 'printString))))
)
(addSelector:withMethod:
MessageSend
'is:
(lambda (self symbol)
(or (eq? symbol 'MessageSend)
(superPerform:with: self 'is: symbol))))
;;; Message
(addSelector:withMethod:
(class Message)
'selector:arguments:
(lambda (self selector argsArray)
(let ( (newInst ($ self 'new)) )
($: newInst 'selector: selector)
($: newInst 'args: argsArray)
newInst)))
(addSelector:withMethod:
(class Message)
'lookupClass:selector:arguments:
(lambda (self aClass aSelector argsArray)
(let ( (newInst ($ self 'new)) )
($: newInst 'lookupClass: aClass)
($: newInst 'selector: aSelector)
($: newInst 'args: argsArray)
newInst)))
(addSelector:withMethod:
Message
'is:
(lambda (self symbol)
(or (eq? symbol 'Message)
(superPerform:with: self 'is: symbol))))
(addSelector:withMethod:
Message
'sendTo:
(lambda (self receiver)
; "answer the result of sending this message to receiver"
(let ( (someClass ($ self 'lookupClass)) )
(if (null? someClass)
($:: receiver
'perform:withArguments:
($ self 'args))
($::: ($ self receiver)
'perform:withArguments:inSuperclass:
($ self 'args)
someClass))))
)
;;; HALT
(addSelector:withMethod:
Halt
'isResumable
(lambda (self) st-true))
(addSelector:withMethod:
Halt
'defaultAction
(lambda (self) ($ self 'noHandler)))
(addSelector:withMethod:
Object
'halt
(lambda (self)
($ Halt 'signal)))
(addSelector:withMethod:
Object
'halt:
(lambda (self aMessage)
($: Halt 'signal: aMessage)))
;;; ASSERT
(addSelector:withMethod:
Object
'assert:
(lambda (self aBlock)
; "Throw an assertion error if aBlock does not evaluates to true."
(when (st-false? (aBlock)) ;; aBlock value == false
($: AssertionFailure 'signal: "Assertion failed"))))
(addSelector:withMethod:
BlockClosure
'assert
(lambda (self)
($: self 'assert: self)))
;;; IllegalResumeAttempt
(addSelector:withMethod:
IllegalResumeAttempt
'defaultAction
(lambda (self) ($ self 'noHandler)))
(addSelector:withMethod:
IllegalResumeAttempt
'isResumable
(lambda (self) st-false))
;;; send-failed
(define in-send-failed? (make-parameter #f))
(set! send-failed ;; def'ed in "st-kernel.scm"
(lambda (rcvr selector rest-args)
(let ( (receiver
(if (condition? rcvr)
($ rcvr 'asException)
rcvr))
)
;;@@DEBUG{
(when (debug-st-runtime)
(format #t
"~%send failed: ~a >> ~a ~a~%"
receiver selector (list->vector rest-args)))
;;@@DEBUG}
(cond
((in-send-failed?)
(let ( (msg
(format #f
"~%send-failed recursion: ~a >> ~a"
($ receiver 'printString)
selector))
)
(error msg receiver selector rest-args)
(%%escape%% msg)
))
((unspecified? receiver)
(%%escape%% (format #f "~%Unspecified reciever for #~a" selector))
)
(else
(parameterize ( (in-send-failed? #t) )
($: receiver
'doesNotUnderstand:
($::: MessageSend
'receiver:selector:arguments:
receiver
selector
(list->vector rest-args)))
))
) )
))
;; (provide 'st-error-obj)
;;; --- E O F --- ;;;
| false |
7159275e9e226e9994d2be0eb8df17cb018fa66d | 2bcf33718a53f5a938fd82bd0d484a423ff308d3 | /programming/sicp/ch1/ex-1.14.scm | 41a88bbd7ac71205098a71db48adfa9ed94dddb7 | []
| no_license | prurph/teach-yourself-cs | 50e598a0c781d79ff294434db0430f7f2c12ff53 | 4ce98ebab5a905ea1808b8785949ecb52eee0736 | refs/heads/main | 2023-08-30T06:28:22.247659 | 2021-10-17T18:27:26 | 2021-10-17T18:27:26 | 345,412,092 | 0 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 1,008 | scm | ex-1.14.scm | ;; https://mitpress.mit.edu/sites/default/files/sicp/full-text/book/book-Z-H-11.html#%_thm_1.14
;; Evaluation of (count-change 11)
(cc 11 5) ; 5 for use 5 denominations of coins
(+ (cc 11 4)
(cc (- 11 (first-denomination 5)) 5))
;; ... the second part keeps decrementing and
;; adding zeros until we get to a dime
(+ (cc 11 2)
(cc (- 11 (first-denomination 3)) 3))
(+ (cc 11 2)
(cc 10 3))
(+ (cc 11 1)
(+ (cc 10 2)
(cc 0 3)))
(+ (cc 11 1)
(+ ((+ (cc 10 1)
(cc 6 2))
1)))
;; Ultimately:
;; 1 way to make 11 with 3 coins (cc 11 3):
;; 1 dime 1 penny
;; 2 ways to make 11 with 2 coins (cc 11 2):
;; 1 nickel 6 pennies
;; 2 nickels 1 penny
;; 1 way to make 11 with 1 coins:
;; 11 pennies
;; 4 total ways to make 11 cents
;; Space complexity: O(n)
;; max depth is for pennies, and this increases with n
;; Time complexity: O(n^k) for k denominations
;; each additional denomination adds on the order of n steps
| false |
42b41da8428639c3985459a7fc20471acc197454 | c2e2ffee9e12a078bc59ed32dfe441e5d018807c | /bench/nqueens.scheme.scm | 5f7e09c831b851d7957489c5ebc6eadf9943a3a4 | [
"BSD-2-Clause"
]
| permissive | fujita-y/digamma | 3fb3bdb8d24b05b6e809863c17cf2a3cb1aac53c | fbab05bdcb7019ff005ee84ed8f737ff3d44b38e | refs/heads/master | 2022-06-03T01:29:22.084440 | 2022-03-15T03:30:35 | 2022-03-15T03:30:35 | 59,635,079 | 32 | 3 | BSD-2-Clause | 2020-02-10T23:40:16 | 2016-05-25T05:58:28 | C++ | UTF-8 | Scheme | false | false | 1,071 | scm | nqueens.scheme.scm | (import (digamma time))
;; nqueens from Gambit benchmark
(define (nqueens n)
(define (|1-to| n) (let loop ((i n) (l '())) (if (= i 0) l (loop (- i 1) (cons i l)))))
(define (my-try x y z)
(if (null? x)
(if (null? y) 1 0)
(+
(if (ok? (car x) 1 z) (my-try (append (cdr x) y) '() (cons (car x) z)) 0)
(my-try (cdr x) (cons (car x) y) z))))
(define (ok? row dist placed)
(if (null? placed)
#t
(and (not (= (car placed) (+ row dist)))
(not (= (car placed) (- row dist)))
(ok? row (+ dist 1) (cdr placed)))))
(my-try (|1-to| n) '() '()))
(define wait-codegen-idle
(lambda ()
(let loop ()
(usleep 100000)
(cond ((= (codegen-queue-count) 0))
(else (loop))))))
;; warmup and wait for codegen queue empty
(nqueens 8) (collect) (wait-codegen-idle)
(time (nqueens 12))
;; interpreted => 1.110873 real 1.146198 user 0.000000 sys (#define ENABLE_LLVM_JIT 0)
;; jit enabled => 0.515772 real 0.881979 user 0.008091 sys (#define ENABLE_LLVM_JIT 1)
| false |
bf685444b7bce2671995761a11810f1113cf7c74 | 784dc416df1855cfc41e9efb69637c19a08dca68 | /src/std/misc/shuffle.ss | cc00392ea1f718f935be436687d7e37fe6e65160 | [
"LGPL-2.1-only",
"Apache-2.0",
"LGPL-2.1-or-later"
]
| permissive | danielsz/gerbil | 3597284aa0905b35fe17f105cde04cbb79f1eec1 | e20e839e22746175f0473e7414135cec927e10b2 | refs/heads/master | 2021-01-25T09:44:28.876814 | 2018-03-26T21:59:32 | 2018-03-26T21:59:32 | 123,315,616 | 0 | 0 | Apache-2.0 | 2018-02-28T17:02:28 | 2018-02-28T17:02:28 | null | UTF-8 | Scheme | false | false | 635 | ss | shuffle.ss | ;;; -*- Gerbil -*-
;;; (C) vyzo at hackzen.org
;;; shuffling
package: std/misc
(export shuffle vector-shuffle vector-shuffle!)
(import (only-in :gerbil/gambit/random random-integer))
(def (shuffle lst)
(vector->list
(vector-shuffle!
(list->vector lst))))
(def (vector-shuffle vec)
(vector-shuffle! (vector-copy vec)))
(def (vector-shuffle! vec)
(let (len (vector-length vec))
(do ((i 0 (##fx+ i 1)))
((##fx= i len) vec)
(let* ((j (##fx+ i (random-integer (##fx- len i))))
(iv (##vector-ref vec i)))
(##vector-set! vec i (##vector-ref vec j))
(##vector-set! vec j iv)))))
| false |
2a4a89c48bf5dac44acc13efcbfb7c131f35ad9d | 575efd9d408a79f5681454b3a07c7bc3f294b05f | /mackages/arith/basic.scm | 7f4af3d491f8352827c8fa159ea38c5b03b76f3e | []
| no_license | DeathKing/miniMaxima | 2d12c47ff64430b96211308598c2c00378eccd8e | 7ed73abc2e55c4a8556bbeed6cb9f275d3b5c3d5 | refs/heads/master | 2020-04-14T12:54:43.754996 | 2016-11-10T01:33:49 | 2016-11-10T01:33:49 | 32,081,631 | 3 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 3,068 | scm | basic.scm | ;;; BasicArith.scm
;;;
;;; Simple and basic arithmetic system.
(define TagExpr/New list)
(define (TagExpr/Tag expr) (list-ref expr 0))
(define (Expr/IsTagExpr? expr)
(and (pair? expr) (> (length expr) 1) (symbol? (car expr))))
(define (Expr/TaggedExpr? expr tag)
(and (Expr/IsTagExpr) (eq? (car expr) tag)))
(define (Expr/IsAtom? expr)
(and (not (pair? expr)) (not (null? expr))))
(define (AddExpr/New a b) (TagExpr/New 'add a b))
(define (SubExpr/New a b) (TagExpr/New 'sub a b))
(define (MulExpr/New a b) (TagExpr/New 'mul a b))
(define (DivExpr/New a b) (TagExpr/New 'div a b))
(define (ExptExpr/New a b) (TagExpr/New 'expt a b))
(define (FuncExpr/New f a) (TagExpr/New 'func a))
(define (TagExpr/AddExpr? expr) (Expr/TaggedExpr? expr 'add))
(define (TagExpr/SubExpr? expr) (Expr/TaggedExpr? expr 'sub))
(define (TagExpr/MulExpr? expr) (Expr/TaggedExpr? expr 'mul))
(define (TagExpr/DivExpr? expr) (Expr/TaggedExpr? expr 'div))
(define (TagExpr/ExptExpr? expr) (Expr/TaggedExpr? expr 'expt))
(define (TagExpr/FuncExpr? expr) (Expr/TaggedExpr? expr 'func))
; TODO: MakeSumExpr should better be a syntax
(define (MakeSumExpr . args)
(cond ((= 1 (length args)) args)
((= 2 (length args)) (AddExpr/New (car args) (cadr args)))
(else
(apply SumExpr/New
(cons (AddExpr/New (car args) (cadr args)) (cddr args))))))
(define (AddExpr/LHS expr) (list-ref expr 1))
(define (AddExpr/RHS expr) (list-ref expr 2))
(define (SubExpr/LHS expr) (list-ref expr 1))
(define (SubExpr/RHS expr) (list-ref expr 2))
(define (MulExpr/LHS expr) (list-ref expr 1))
(define (MulExpr/RHS expr) (list-ref expr 2))
(define (DivExpr/LHS expr) (list-ref expr 1))
(define (DivExpr/RHS expr) (list-ref expr 2))
(define (ExptExpr/Base expr) (list-ref expr 1))
(define (ExptExpr/Exponent expr) (list-ref expr 2))
(define (FuncExpr/Fx expr) (list-ref expr 1))
(define (FuncExpr/Args expr) (list-ref expr 2))
(define (TagExpr/SexprToExpr sexpr)
(cond ((or (null? sexpr) (symbol? sexpr) (number? sexpr))
sexpr)
((and (= (length sexpr) 3) (eq? (car sexpr) '+))
(AddExpr/New (TagExpr/SexprToExpr (cadr sexpr))
(TagExpr/SexprToExpr (caddr sexpr))))
((and (= (length sexpr) 3) (eq? (car sexpr) '-))
(SubExpr/New (TagExpr/SexprToExpr (cadr sexpr))
(TagExpr/SexprToExpr (caddr sexpr))))
((and (= (length sexpr) 3) (eq? (car sexpr) '*))
(MulExpr/New (TagExpr/SexprToExpr (cadr sexpr))
(TagExpr/SexprToExpr (caddr sexpr))))
((and (= (length sexpr) 3) (eq? (car sexpr) '/))
(DivExpr/New (TagExpr/SexprToExpr (cadr sexpr))
(TagExpr/SexprToExpr (caddr sexpr))))
((and (= (length sexpr) 3) (eq? (car sexpr) '^))
(ExptExpr/New (TagExpr/SexprToExpr (cadr sexpr))
(TagExpr/SexprToExpr (caddr sexpr))))
(else
(FuncExpr/New (TagExpr/SexprToExpr (car sexpr))
(TagExpr/SexprToExpr (cadr sexpr))))))
| false |
0e3a8a5944ba1974a0704d62226f2a09dca3a431 | e1800c520db4f4ff153802d92025c83dcdbfd1f1 | /little-schemer/tests-chapter06.scm | 98db0847c400cd0ffccf45e5499e811c35f639af | []
| no_license | nfschmidt/Little-Schemer | 7026aea3efc40a4dc84072f48466e00c6c029167 | 80ace0433fa270c80ca6a43e64f299a604c817f0 | refs/heads/master | 2020-04-10T03:30:06.055242 | 2015-08-27T18:13:52 | 2015-08-27T18:13:52 | null | 0 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 1,572 | scm | tests-chapter06.scm | (load "testing.scm")
(load "chapter06.scm")
(print-tests-results (new-test "numbered? of (3 + (4 ^ 5)) is #t"
(numbered? '(3 + (4 ^ 5))))
(new-test "numbered? of (2 X sausage) is #f"
(not (numbered? '(2 x sausage))))
(new-test "value of 13 is 13"
(= 13 (value 13)))
(new-test "value of (1 + 3) is 4"
(= 4 (value '(1 + 3))))
(new-test "value of (1 + (3 ^ 4)) is 82"
(= 82 (value '(1 + (3 ^ 4)))))
(new-test "1st-sub-exp of (+ 1 2) is 1"
(= 1 (1st-sub-exp '(+ 1 2))))
(new-test "2nd-sub-exp of (+ 1 2) is 2"
(= 2 (2nd-sub-exp '(+ 1 2))))
(new-test "operator of (+ 1 2) is +"
(eq? '+ (operator '(+ 1 2))))
(new-test "value-2 of 13 is 13"
(= 13 (value-2 13)))
(new-test "value-2 of (+ 1 3) is 4"
(= 4 (value-2 '(+ 1 3))))
(new-test "value-2 of (+ 1 (^ 3 4)) is 82"
(= 82 (value-2 '(+ 1 (^ 3 4)))))
(new-test "sero? of () is #t"
(sero? '()))
(new-test "sero? of (()) is #f"
(not (sero? '(()))))
(new-test "edd1 of () is (())"
(equal? '(()) (edd1 '())))
(new-test "edd1 of (()) is (() ())"
(equal? '(() ()) (edd1 '(()))))
(new-test "zub1 of (()) is ()"
(equal? '() (zub1 '(()))))
(new-test "zub1 of (() ()) is (())"
(equal? '(()) (zub1 '(() ()))))
(new-test "oo+ of (()) (() ()) is (() () ())"
(equal? '(() () ()) (oo+ '(()) '(() ()))))
)
| false |
fe6e3aad773eaffebca172e02d86cbdeb29c0205 | b14c18fa7a4067706bd19df10f846fce5a24c169 | /Chapter2/2.10.scm | 22a816efcca8ad5caad6b4ea6d0d63af6bfe3268 | []
| no_license | silvesthu/LearningSICP | eceed6267c349ff143506b28cf27c8be07e28ee9 | b5738f7a22c9e7967a1c8f0b1b9a180210051397 | refs/heads/master | 2021-01-17T00:30:29.035210 | 2016-11-29T17:57:16 | 2016-11-29T17:57:16 | 19,287,764 | 3 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 96 | scm | 2.10.scm | #lang scheme
(include "interval.scm")
(div-interval (make-interval 1 1) (make-interval 0 1)) | false |
10a6f640baea02465ddf804880a238118fbe4602 | 928e706795455cddbacba32cf039aa04e1576963 | /compiler/tests/p00_string2tokens.test.sld | 9ef72f453b00fba935284ca15e3ec30a07053ac9 | [
"MIT"
]
| permissive | zaoqi-clone/loki | a26931aa773df35601099e59695a145a8cacf66c | a0edd3933a1d845d712b977a47504c8751a6201f | refs/heads/master | 2020-07-01T21:52:28.446404 | 2019-08-08T02:31:46 | 2019-08-08T02:31:46 | null | 0 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 7,395 | sld | p00_string2tokens.test.sld | (define-library
(p00_string2tokens.test)
(import (scheme base))
(import (scheme write))
(import (srfi 159))
(import (unit))
(import (shared))
(import (p00_string2tokens))
(export test_p00_string2tokens)
(begin
(define-syntax check-with-name
(syntax-rules ()
((check name in out)
(test-equal name out (p00_string2tokens (open-input-string in))))))
(define-syntax check
(syntax-rules ()
((check in out)
(test-equal in out (p00_string2tokens (open-input-string in))))))
(define-syntax check-error
(syntax-rules ()
((check-error in)
(test-error in (p00_string2tokens (open-input-string in))))))
(define (t string type value)
(make-token string type value (make-source-location 1 1 0)))
(define (tl string type line col offset value)
(make-token string type value (make-source-location line col offset)))
(define (test_p00_string2tokens)
(test-group "p00_string2tokens"
(check-with-name "lf" "123\n456" (list (t "123" 'number 123) (tl "456" 'number 2 1 4 456)))
(check-with-name "cr" "123\r456" (list (t "123" 'number 123) (tl "456" 'number 2 1 4 456)))
(check-with-name "crlf" "123\r\n456" (list (t "123" 'number 123) (tl "456" 'number 2 1 5 456)))
(check-with-name "lfcr" "123\n\r456" (list (t "123" 'number 123) (tl "456" 'number 3 1 5 456)))
(check-with-name "crcr" "123\r\r456" (list (t "123" 'number 123) (tl "456" 'number 3 1 5 456)))
(check-with-name "lflf" "123\n\n456" (list (t "123" 'number 123) (tl "456" 'number 3 1 5 456)))
(check-with-name "lfcrlf" "123\n\r\n456" (list (t "123" 'number 123) (tl "456" 'number 3 1 6 456)))
(check-with-name "crlflf" "123\r\n\n456" (list (t "123" 'number 123) (tl "456" 'number 3 1 6 456)))
(check "identifier" (list (t "identifier" 'id 'identifier)))
(check "!id" (list (t "!id" 'id '!id)))
(check "+" (list (t "+" 'id '+)))
(check "+id" (list (t "+id" 'id '+id)))
(check "+.id" (list (t "+.id" 'id '+.id)))
(check "+..id" (list (t "+..id" 'id '+..id)))
(check "|+0id|" (list (t "|+0id|" 'id '|+0id|)))
(check-error "0id")
(check-error "+0id")
(map
(lambda (in value)
(let ((with-prefix (string-append "#d" in)))
(check in (list (t in 'number value)))
(check with-prefix
(list (t with-prefix 'number value)))))
'("123" "#i123" "#e123" "123+456i" "-123+456i"
"123-456i" "-123-456i" "123+i" "123-i" "123-inf.0i" "123+inf.0i" "+123i" "-123i")
'(123 #i123 #e123 123+456i -123+456i
123-456i -123-456i 123+i 123-i 123-inf.0i 123+inf.0i +123i -123i))
(map
(lambda (in value) (check in (list (t in 'number value))))
'("#b01" "#o01234567" "#x01234567890abcdefABCDEF" "#xDEADBEEF")
'(#b01 #o01234567 #x01234567890abcdefABCDEF #xDEADBEEF))
(map
(lambda (in value) (check in (list (t in 'number value))))
'("+inf.0" "-inf.0" "+nan.0" "-nan.0" "+inf.0i" "-inf.0i" "+i" "-i")
'(+inf.0 -inf.0 +nan.0 -nan.0 +inf.0i -inf.0i +i -i))
(map
(lambda (in) (check-error in))
'("#b1012" "#b2" "#b456"
"#o8" "#o9" "#oA"
"#dDEAD #ddead"
"#xZZZ"))
(check "(" (list (t "(" 'lparen #f)))
(check ")" (list (t ")" 'rparen #f)))
(check "()"
(list (t "(" 'lparen #f)
(tl ")" 'rparen 1 2 1 #f)))
(check "#t" (list (t "#t" 'boolean #t)))
(check "#true" (list (t "#true" 'boolean #t)))
(check "#f" (list (t "#f" 'boolean #f)))
(check "#false" (list (t "#false" 'boolean #f)))
(check "#t #f #true #false"
(list
(tl "#t" 'boolean 1 1 0 #t)
(tl "#f" 'boolean 1 4 3 #f)
(tl "#true" 'boolean 1 7 6 #t)
(tl "#false" 'boolean 1 13 12 #f)))
(check-error "#a")
(check-error "#ture")
(check-error "#truea")
(check-error "#fasle")
(check-error "#falsea")
(check "#\\a" (list (t "#\\a" 'char #\a)))
(map (lambda (name value)
(check name (list (t name 'char value))))
'("#\\alarm" "#\\backspace" "#\\delete" "#\\escape" "#\\newline" "#\\null" "#\\return" "#\\space" "#\\tab")
'(#\alarm #\backspace #\delete #\escape #\newline #\null #\return #\space #\tab))
(check-error "#\\fake")
(check-error "#\\alarma")
(check-error "#\\spacet")
(check "#\\x123" (list (t "#\\x123" 'char #\x123)))
(check "#\\xABC" (list (t "#\\xABC" 'char #\xABC)))
(check "#\\xabc" (list (t "#\\xabc" 'char #\xabc)))
(check-error "#\\xaq")
(check "\"this is a test\"" (list (t "\"this is a test\"" 'string "this is a test")))
(check-error "\"this is a test")
(check "(#f)"
(list
(tl "(" 'lparen 1 1 0 #f)
(tl "#f" 'boolean 1 2 1 #f)
(tl ")" 'rparen 1 4 3 #f)))
(check "( #f )"
(list
(tl "(" 'lparen 1 1 0 #f)
(tl "#f" 'boolean 1 3 2 #f)
(tl ")" 'rparen 1 6 5 #f)))
(check "(one . two)"
(list
(tl "(" 'lparen 1 1 0 #f)
(tl "one" 'id 1 2 1 'one)
(tl "." 'dot 1 6 5 #f)
(tl "two" 'id 1 8 7 'two)
(tl ")" 'rparen 1 11 10 #f)))
(check "#()"
(list
(tl "#(" 'lvector 1 1 0 #f)
(tl ")" 'rparen 1 3 2 #f)))
(check "#u8()"
(list
(tl "#u8(" 'lbytevector 1 1 0 #f)
(tl ")" 'rparen 1 5 4 #f)))
(check "'" (list (t "'" 'quote #f)))
(check "'123" (list
(tl "'" 'quote 1 1 0 #f)
(tl "123" 'number 1 2 1 123)))
(check "'(123)" (list
(tl "'" 'quote 1 1 0 #f)
(tl "(" 'lparen 1 2 1 #f)
(tl "123" 'number 1 3 2 123)
(tl ")" 'rparen 1 6 5 #f)))
(check "'#(123)" (list
(tl "'" 'quote 1 1 0 #f)
(tl "#(" 'lvector 1 2 1 #f)
(tl "123" 'number 1 4 3 123)
(tl ")" 'rparen 1 7 6 #f)))
(check "'#u8(123)" (list
(tl "'" 'quote 1 1 0 #f)
(tl "#u8(" 'lbytevector 1 2 1 #f)
(tl "123" 'number 1 6 5 123)
(tl ")" 'rparen 1 9 8 #f)))
(check "`(+ ,one ,two)" (list
(tl "`" 'quasiquote 1 1 0 #f)
(tl "(" 'lparen 1 2 1 #f)
(tl "+" 'id 1 3 2 '+)
(tl "," 'unquote 1 5 4 #f)
(tl "one" 'id 1 6 5 'one)
(tl "," 'unquote 1 10 9 #f)
(tl "two" 'id 1 11 10 'two)
(tl ")" 'rparen 1 14 13 #f)))
(check "`(+ ,@one ,two)" (list
(tl "`" 'quasiquote 1 1 0 #f)
(tl "(" 'lparen 1 2 1 #f)
(tl "+" 'id 1 3 2 '+)
(tl ",@" 'unquote-splicing 1 5 4 #f)
(tl "one" 'id 1 7 6 'one)
(tl "," 'unquote 1 11 10 #f)
(tl "two" 'id 1 12 11 'two)
(tl ")" 'rparen 1 15 14 #f)))
))
)) | true |
0fede8e2a9fbe0a6c6503bd916e2ab381dcdbe2c | 9998f6f6940dc91a99e0e2acb4bc4e918f49eef0 | /src/test/sample-moby-programs/shake-to-ring.ss | 9f088a5649a19816df0893c0ead2d38b46668d67 | []
| 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 | 1,940 | ss | shake-to-ring.ss | ;; The first three lines of this file were inserted by DrScheme. They record metadata
;; about the language level of this file in a form that our tools can easily process.
#reader(lib "htdp-beginner-reader.ss" "lang")((modname shake-to-ring) (read-case-sensitive #t) (teachpacks ()) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ())))
(define WIDTH 320)
(define HEIGHT 480)
(define THRESHOLD 20)
;; The world records the acceleration vector.
(define-struct world (x y z))
(define initial-world (make-world 0 0 -9))
;; update: world number number number -> world
(define (update a-world new-x new-y new-z)
(make-world new-x new-y new-z))
;; maybe-ring: world number number number -> effect
;; Maybe produce a ring, if the old world and the new world
;; have a significant distance difference.
(define (maybe-ring a-world new-x new-y new-z)
(cond [(> (distance a-world (update a-world new-x new-y new-z))
THRESHOLD)
(make-effect:beep)]
[else
(make-effect:none)]))
;; distance: world world -> boolean
;; Returns the "distance" between two worlds.
(define (distance w1 w2)
(sqrt (+ (sqr (- (world-x w1)
(world-x w2)))
(sqr (- (world-y w1)
(world-y w2)))
(sqr (- (world-z w1)
(world-z w2))))))
;; render: world -> scene
(define (render w)
(place-image (text (string-append (number->string (world-x w))
" "
(number->string (world-y w))
" "
(number->string (world-z w)))
10
"black")
50
50
(empty-scene WIDTH HEIGHT)))
(big-bang WIDTH HEIGHT initial-world
(on-redraw render)
(on-acceleration* update maybe-ring))
| false |
b8ba683bc6187fdd1ba191a59c631be61d5734c7 | d696b5c5cc0ee7032ab13b6ed486d6158646f828 | /Exercise3-25.scm | 35e16154236ce65619bc0988df2c5042e4e9a75d | []
| no_license | senwong/SICPExercises | 4f96b1480fa30031b1fe8f44757702c0d7102d2b | 1206705162f0d18892fc70ccb7376a425b6f6534 | refs/heads/master | 2021-09-03T01:31:38.882431 | 2018-01-04T15:45:37 | 2018-01-04T15:45:37 | null | 0 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 1,504 | scm | Exercise3-25.scm | (define (iter-create-table keys value)
(if (null? (cdr keys))
(cons (car keys) value)
(cons (car keys)
(cons (iter-create-table (cdr keys) value) '())
)
)
)
(define (lookup-recursive keys table)
(let ((record (assoc (car keys) (cdr table))))
(if record
(cdr record)
false)))
(define (make-table same-key?)
(define (assoc key records)
(cond ((null? records) false)
((same-key? key (caar records)) (car records)) ;replace equal? with same-key?
(else (assoc key (cdr records)))))
(let ((local-table (list '*table*)))
(define (lookup keys)
(let ((subtable (lookup-recursive keys local-table)))
(if subtable
(lookup-recursive (cdr keys) subtable)
false)))
(define (insert! keys value)
(let ((subtable (assoc (car keys) (cdr local-table))))
(if subtable
(set-cdr! subtable
(cons (iter-create-table (cdr keys) value)
(cdr subtable)))
(set-cdr! local-table
(cons (iter-create-table (cdr keys) value)
(cdr local-table))))
'ok))
(define (dispatch m)
(cond ((eq? m 'lookup-proc) lookup)
((eq? m 'insert-proc!) insert!)
(else (error "Unknown operation: TABLE" m))))
dispatch))
(define (same-key? x y)
(cond ((symbol? x) (lambda (x y) (eq? x y)))
((number? x) (lambda (x y) (= x y)))
)
) | false |
80f2b703655ec724328e23020e6b1594dd760e90 | 11b227f71ec01f2e497680cc5f9090c984e9f48e | /sources/infrastructure/json/json-parse.scm | 375bf9f6bc82e782080619ca26fa784a1fd4fb84 | [
"MIT"
]
| permissive | Mathieu-Desrochers/Scheme-Experimentations | 30dd336abf40c422f6d9c2d49f31b3665b7a8f17 | 9879e811865fbef170681a7748784a525d950088 | refs/heads/master | 2020-03-30T22:55:35.004425 | 2015-04-23T20:08:33 | 2015-04-23T20:08:33 | 6,216,231 | 14 | 1 | null | null | null | null | UTF-8 | Scheme | false | false | 2,309 | scm | json-parse.scm |
(declare (unit json-parse))
(declare (uses exceptions))
(declare (uses json))
;; parses a value
(define (json-parse-value json-object property-name)
(let ((json-object-property (json-object-property json-object property-name)))
(if json-object-property
(json-object-value json-object-property)
#f)))
;; parses a value list
(define (json-parse-value-list json-object property-name)
(let ((json-object-property (json-object-property json-object property-name)))
(if json-object-property
(if (json-object-type-array? json-object-property)
(let ((json-object-array-elements (json-object-array-elements json-object-property)))
(map
json-object-value
json-object-array-elements))
(json-object-value
json-object-property))
#f)))
;; parses a subrequest
(define (json-parse-subrequest json-object property-name json-parse-subrequest-procedure)
(let ((json-object-property (json-object-property json-object property-name)))
(if json-object-property
(if (json-object-type-object? json-object-property)
(json-parse-subrequest-procedure
json-object-property)
(json-object-value
json-object-property))
#f)))
;; parses a subrequest list
(define (json-parse-subrequest-list json-object property-name json-parse-subrequest-procedure)
(let ((json-object-property (json-object-property json-object property-name)))
(if json-object-property
(if (json-object-type-array? json-object-property)
(let ((json-object-array-elements (json-object-array-elements json-object-property)))
(map
(lambda (json-object-array-element)
(if (json-object-type-object? json-object-array-element)
(json-parse-subrequest-procedure
json-object-array-element)
(json-object-value
json-object-array-element)))
json-object-array-elements))
(json-object-value
json-object-property))
#f)))
;; parses a request
(define (json-parse-request string json-parse-request-procedure)
(with-exception-hiding
(lambda ()
(with-parsed-json-object string
(lambda (json-object)
(json-parse-request-procedure json-object))))))
| false |
d9506c7d43ff32d35861f979da323bc23ea430c5 | 5cd6095d176a28c482fc66e4b5e0e877b2122d50 | /srfi/210/test.sld | b15ac2b945732b0efcc10e20b8ab72dc508d9ce0 | []
| no_license | Zipheir/srfi-210 | 8cad4715696fb6cfb337990fa53aeb3c313e5b2c | 5c18b7ec42b76e19d3cc43ab56778d2b23e1c6ac | refs/heads/master | 2022-12-08T06:59:40.865332 | 2020-08-31T10:57:54 | 2020-08-31T10:57:54 | null | 0 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 2,485 | sld | test.sld | ;; Copyright © Marc Nieper-Wißkirchen (2020).
;; Permission is hereby granted, free of charge, to any person
;; obtaining a copy of this software and associated documentation
;; files (the "Software"), to deal in the Software without
;; restriction, including without limitation the rights to use, copy,
;; modify, merge, publish, distribute, sublicense, and/or sell copies
;; of the Software, and to permit persons to whom the Software is
;; furnished to do so, subject to the following conditions:
;; The above copyright notice and this permission notice shall be
;; included in all copies or substantial portions of the Software.
;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
;; EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
;; MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
;; NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
;; BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
;; ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
;; CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
;; SOFTWARE.
(define-library (srfi 210 test)
(export run-tests)
(import (scheme base)
(srfi 210)
(srfi 64))
(begin
(define-syntax test-values
(syntax-rules ()
((test-values (expected ...) test-expr)
(test-equal (list expected ...) (list/mv test-expr)))
((test-values test-name (expected ...) test-expr)
(test-equal test-name (list expected ...) (list/mv test-expr)))))
(define (run-tests)
(test-begin "SRFI 210")
(test-equal "abc" (apply/mv string #\a (values #\b #\c)))
(test-equal "abcd" (call/mv string (values #\a #\b) (values #\c #\d)))
(test-equal '(a b c) (list/mv 'a (values 'b 'c)))
(test-equal #(a b c) (vector/mv 'a (values 'b 'c)))
(test-equal 'b (value/mv 1 'a (values 'b 'c)))
(test-equal 3 (arity (values 'a 'b 'c)))
(test-equal '(a (b))
(let ((x #f) (y #f))
(set!-values (x . y) (values 'a 'b))
(list x y)))
(test-equal 5
(with-values (values 4 5)
(lambda (a b) b)))
(test-equal '(a (b))
(case-receive (values 'a 'b)
((x) #f)
((x . y) (list x y))))
(test-values ('a 'b 'c)
(list-values '(a b c)))
(test-values ('a 'b 'c)
(vector-values #(a b c)))
(test-equal 'b (value 1 'a 'b 'c))
(test-end))))
| true |
aba6906e59fe3be4b0186311cb98076bec17ff1f | da2114279d57b3428cec5d43f191fac50aaa3053 | /yast-cn/chapter 15/ex2.ss | eade73f6a062b1fc7bcb78c51a1f708a5831b111 | []
| no_license | ntzyz/scheme-exercise | 7ac05d6ac55f756376b272d817c21c1254a1d588 | c845dd27c6fc0c93027ac1b7d62aa8f8204dd677 | refs/heads/master | 2020-04-09T07:51:08.212584 | 2019-03-11T09:21:45 | 2019-03-11T09:21:45 | 160,173,089 | 2 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 318 | ss | ex2.ss | ; 编写用于从变量中减去一个数的宏decf。如果减量省略了,则从变量中减1。
(define-syntax decf!
(syntax-rules ()
((_ i) (begin (set! i (- i 1)) i))
((_ i n) (begin (set! i (- i n)) i))))
(begin
(define n 5)
(decf! n) (display n) (newline)
(decf! n 10) (display n) (newline)) | true |
2adc54e685410d8c656dc8e8bdf467f7dfa53d1d | 5fa722a5991bfeacffb1d13458efe15082c1ee78 | /src/c3_19.scm | ee838b43e610161eb8cf3894c037c6ee2b1b7210 | []
| no_license | seckcoder/sicp | f1d9ccb032a4a12c7c51049d773c808c28851c28 | ad804cfb828356256221180d15b59bcb2760900a | refs/heads/master | 2023-07-10T06:29:59.310553 | 2013-10-14T08:06:01 | 2013-10-14T08:06:01 | 11,309,733 | 3 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 610 | scm | c3_19.scm | (define (cycle? lst)
(define (catch-up fast slow)
(cond ((or (null? fast)
(null? slow)) #f)
((eq? fast slow) #t)
(else (catch-up (list-walk 2 fast)
(list-walk 1 slow)))))
(catch-up (list-walk 2 lst)
(list-walk 1 lst)))
; let the list walk for `step` num steps
(define (list-walk step lst)
(cond ((null? lst) '())
((= step 0) lst)
(else (list-walk (sub1 step)
(cdr lst)))))
(define cycle '(1 2 3))
(set-cdr! (last-pair cycle) cycle)
(display (cycle? cycle))
(display (cycle? '(1 2 3)))
| false |
d8b06abcd1b6e80807174da1097be3ef41be3a33 | 669b06943e802449ed812bfafec9eec2c50647da | /deps/share/guile/site/2.2/chickadee/config.scm | 8dcb3c0cc18d5048acf754df859eabe6807b81ab | []
| no_license | bananaoomarang/chickadee-game | f9dcdb8b2e2b3b1909d30af52c1e6a7c16b27194 | 8733941202243956252b19a1a3ceb35a84b61e56 | refs/heads/master | 2020-06-04T17:35:32.420313 | 2019-06-24T22:59:04 | 2019-06-24T22:59:04 | 192,126,835 | 1 | 1 | null | null | null | null | UTF-8 | Scheme | false | false | 1,188 | scm | config.scm | ;;; Chickadee Game Toolkit
;;; Copyright © 2016 David Thompson <[email protected]>
;;;
;;; Chickadee 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.
;;;
;;; Chickadee is distributed in the hope that it will be useful, but WITHOUT
;;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
;;; or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
;;; Public License for more details.
;;;
;;; You should have received a copy of the GNU Lesser General Public
;;; License along with this program. If not, see
;;; <http://www.gnu.org/licenses/>.
;;; Commentary:
;;
;; Build time configuration.
;;
;;; Code:
(define-module (chickadee config)
#:export (%datadir
%chickadee-version
scope-datadir))
(define %datadir
(or (getenv "CHICKADEE_DATADIR") "/home/milo/guile-prefix/share/chickadee"))
(define %chickadee-version "0.4.0")
(define (scope-datadir file)
"Append the Chickadee data directory to FILE."
(string-append %datadir "/" file))
| false |
ede7f6ca4a36b69e136ba87731e9f771fc351655 | 710bd922d612840b3dc64bd7c64d4eefe62d50f0 | /scheme/scheme-environment/io.scm | cb63014d7ded25e555f892d43204e40ea4558948 | [
"MIT"
]
| permissive | prefics/scheme | 66c74b93852f2dfafd4a95e04cf5ec6b06057e16 | ae615dffa7646c75eaa644258225913e567ff4fb | refs/heads/master | 2023-08-23T07:27:02.254472 | 2023-08-12T06:47:59 | 2023-08-12T06:47:59 | 149,110,586 | 0 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 4,511 | scm | io.scm | ;;; io.scm -- input/output of library
(define (ensure-import-loaded library)
(for-each (lambda (name)
(let ((def (lookup-library-definition name)))
(if def
(load-library-definition def)
(load-library name))))
(module/open library)))
(define (ensure-library-defined def)
(let* ((lib (->library-definition def))
(module (lookup-module (library-definition-name lib))))
(if module
(update-module-from-library-definition! module lib)
(let ((module (make-module (library-definition-name lib)
(library-definition-export lib)
(library-definition-import lib)
(library-definition-doc lib)
'()
(library-definition-name lib))))
(bind-module! (library-definition-name lib) module)
module))))
(define (load-library name)
(or (lookup-module name)
(let ((fasl-file-name (locate-library name)))
(if fasl-file-name
(load-fasl-file fasl-file-name)))
(error "cannot locate library ~a in path" name)))
(define (load-file file-name module)
(if (file-readable? file-name)
(with-cwd* (file-name-directory file-name)
(lambda ()
(with-input-from-file file-name
(lambda ()
(let loop ((exp (read)))
(if (eof-object? exp)
module
(let ((value (eval exp module)))
(loop (read)))))))))
(error "File ~a is not readable" file-name)))
(define (load-fasl-file filename)
(if (file-readable? filename)
(with-cwd* (file-name-directory filename)
(lambda ()
(call-with-input-file filename
(lambda (port)
(let loop ((type (read-type port))
(module #f))
(cond ((eof-object? type) module)
((= type type/define)
(let* ((fasl (read-fasl port))
(proc (make-procedure 2)))
(procedure-set! proc 0 (vector 'undefined))
(procedure-set! proc 1 fasl)
(proc)
(loop (read-type port) module)))
((= type type/syntax)
(if module
(let* ((symbol (read-fasl port))
(fasl (read-fasl port))
(proc (make-procedure 2)))
(procedure-set! proc 0 (vector 'undefined))
(procedure-set! proc 1 fasl)
; (display ".")
(bind-syntax! symbol
(make-syntax (proc)
(module/syntax module))
module)
; (display "*")
(loop (read-type port) module))
(error "no module definition before this syntax definition")))
((= type type/expr)
(let* ((fasl (read-fasl port))
(proc (make-procedure 2)))
(procedure-set! proc 0 (vector 'undefined))
(procedure-set! proc 1 fasl)
(proc)
(loop (read-type port) module)))
((= type type/module)
(let* ((name (read-fasl port))
(export (read-fasl port))
(open (read-fasl port))
(doc (read-fasl port))
(mod (make-module name export open doc
'() name)))
(for-each ensure-library-loaded open)
(bind-module! name mod)
(loop (read-type port) mod)))
(else (error "bad fasl type code ~a" type))))))))
(error "library fasl file name ~a not readable" filename)))
(define (ensure-library-loaded name)
;; Make sure MODULE-NAME is loaded into the image. If it is not
;; already in memory, then locate the FASL file from where it could
;; be loaded and load it.
(let ((library (lookup-module name)))
(or library
(let ((filename (locate-library name)))
(if filename
(load-fasl-file filename)
(error "No Module ~a could be located" name))))))
(define (string-split char string)
(let loop ((start 0)
(i 0))
(if (< i (string-length string))
(if (char=? (string-ref string i) char)
(cons (substring string start i) (loop (+ i 1) (+ i 1)))
(loop start (+ i 1)))
(list (substring string start i)))))
(define (locate-library module-name)
;; Locate the filename where MODULE-NAME and return the filename or #f if
;; the module cannot be found.
(let ((module-path (getenv "SCHEMY_MODULE_PATH")))
(if module-path
(let loop ((paths (string-split #\: module-path)))
(if (null? paths)
#f
(let* ((path (car paths))
(filename (string-append (file-name-as-directory path)
(symbol->string module-name)
".fasl")))
(if (file-readable? filename)
filename
(loop (cdr paths))))))
#f)))
| false |
b332f4ed9e3544a842637550ee71b284ce872ef1 | 047126255588c7b6cb13e1a478603d80dacfd08d | /sopt/data.scm | 4dc21bf46bd131a5897a32859dcab65e6ce67b94 | []
| no_license | khaki3/sopt | b25d67bb5a110d7e2b5af70eec376c006954ff83 | c4f1cef840de8f46b0156a754ce91361fdeb51e2 | refs/heads/master | 2023-07-13T14:07:47.884652 | 2016-09-15T09:47:40 | 2016-09-15T09:47:40 | null | 0 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 6,406 | scm | data.scm | (define-module sopt.data
(use util.match)
(use gauche.record)
(use gauche.parameter)
(export-all))
(select-module sopt.data)
(define SOPT_GENSYM_COUNT 0)
(define (sopt-gensym :optional (prefix #f))
(begin0
(string->symbol
(string-append
(if prefix (x->string prefix) "")
(if prefix "--" "")
"sopt--"
(number->string SOPT_GENSYM_COUNT)))
(inc! SOPT_GENSYM_COUNT)))
;;;
;;; sopt-args
;;;
(define-constant SOPT_UNDEF (gensym))
(define (undef? x)
(eq? SOPT_UNDEF x))
;; list as sopt-args
(define-syntax make-sopt-args
(syntax-rules ()
[(_ arg ...) (list arg ...)]))
(define (string->sopt-args str)
(let ([lst (read-from-string str)])
(unless (list? lst)
(error #"Invalid sopt-args from command-line: ~str"))
(map
(lambda (x)
(cond [(eq? x '@undef) SOPT_UNDEF]
[(symbol? x) x] ; sopt-var
[else (make-sopt-literal x)]))
lst)))
;;;
;;; sopt-env, sopt-trace
;;;
;;
;; sopt-env ::= alist(var -> sopt-trace)
;;
;; sopt-trace ::= (<parameter>-of-var-name . <parameter>-of-value)
;;
;; <parameter>-of-var-name indicates the var which remains in source code.
;;
(define-method make-sopt-env () (list))
(define (make-sopt-trace var val)
(cons (make-parameter var) (make-parameter val)))
(define (add-trace env var trace)
(acons var trace env))
;; env -> var -> trace
(define (sopt-env-ref env var)
(assoc-ref env var))
;;;
;;; sopt-cxt
;;;
;; sopt-cxt is a wrapper of <hash-table>, containing `sopt-def`s
(define-record-type sopt-cxt #t #t ht)
(define (port->sopt-cxt iport)
(make-sopt-cxt
(alist->hash-table
(port->list
(compose
(lambda (x)
(if (eof-object? x) x
(let1 def (sopt-parse x)
(cons (sopt-def-name def) def))))
read)
iport))))
(define (write-sopt-cxt cxt oport)
(hash-table-for-each (sopt-cxt-ht cxt)
(lambda (name def)
(display (sopt-deparse def) oport)
(newline oport))))
(define (sopt-cxt-ref cxt name)
(ref (sopt-cxt-ht cxt) name #f))
;;;
;;; syntax
;;;
;;;;;;;;;;;;
;;
;; cxt ::= hashtable(name -> def)
;;
;; def ::= (define (name args ...) terms ...)
;;
;; var ::= symbol
;;
;; literal ::= symbol | ... // Gauche-objects
;;
;; term ::= var [var]
;; | literal
;; | (quote literal) [literal]
;; | (if test-term
;; then-term
;; else-term) [if]
;; | (let
;; ((var1 term1)
;; ...
;; (varN-1 termN-1))
;; terms ...) [let]
;; | (apply term lst) [apply]
;; | (lambda args terms ...) [lambda]
;; | (call/cc term) [call/cc]
;; | (set! var term) [set!]
;; | (term1 ...) [call]
;;
;;;;;;;;;;;;
(define-record-type sopt-def #t #f name args terms)
(define-record-type sopt-literal #t #t value)
(define-record-type sopt-if #t #t test then else)
(define-record-type sopt-let #t #t bindings terms)
(define-record-type sopt-apply #t #t proc list)
(define-record-type sopt-call/cc #t #t proc)
(define-record-type sopt-lambda %make-sopt-lambda #t args terms (data))
(define-record-type sopt-call #t #t proc args)
(define-record-type sopt-set! #t #t var term)
(define (make-sopt-lambda args terms)
(rlet1 lmd (%make-sopt-lambda args terms #f)
(sopt-lambda-data-set! lmd (sopt-deparse-lambda lmd))))
(define (sopt-parse def)
(match def
[(or ('define (name . args) . terms)
('define name ('lambda args . terms)))
(make-sopt-def name args (map sopt-parse-term terms))]))
(define-syntax sopt-var?
(syntax-rules ()
[(_ t) (symbol? t)]))
(define (sopt-parse-term term)
(match term
[('quote literal)
(make-sopt-literal literal)]
[('if test-term then-term else-term)
(make-sopt-if
(sopt-parse-term test-term)
(sopt-parse-term then-term)
(sopt-parse-term else-term))]
[('if test-term then-term)
(make-sopt-if
(sopt-parse-term test-term)
(sopt-parse-term then-term)
(make-sopt-literal #f))]
[('let bindings . terms)
;; use alist as bindings
(make-sopt-let
(map
(lambda (b)
(let ((b-var (car b)) (b-term (cadr b)))
(cons b-var (sopt-parse-term b-term))))
bindings)
(map sopt-parse-term terms))]
[('apply t1 t2)
(make-sopt-apply (sopt-parse-term t1) (sopt-parse-term t2))]
[(or ('call/cc t) ('call-with-current-continuation t))
(make-sopt-call/cc (sopt-parse-term t))]
[('lambda args . terms)
(make-sopt-lambda args (map sopt-parse-term terms))]
[('set! var t)
(make-sopt-set! var (sopt-parse-term t))]
[(proc-term . args-term)
(make-sopt-call
(sopt-parse-term proc-term)
(map sopt-parse-term args-term))]
[else
(if (symbol? term) term (make-sopt-literal term))]))
(define (sopt-deparse def)
`(define (,(sopt-def-name def) . ,(sopt-def-args def))
. ,(map sopt-deparse-term (sopt-def-terms def))))
(define (sopt-deparse-lambda term)
`(lambda ,(sopt-lambda-args term)
. ,(map sopt-deparse-term (sopt-lambda-terms term))))
(define (sopt-deparse-term term)
(cond
[(sopt-literal? term)
`(quote ,(sopt-literal-value term))]
[(sopt-if? term)
`(if ,(sopt-deparse-term (sopt-if-test term))
,(sopt-deparse-term (sopt-if-then term))
,(sopt-deparse-term (sopt-if-else term)))]
[(sopt-let? term)
`(let
,(map
(lambda (b)
(list (car b) (sopt-deparse-term (cdr b))))
(sopt-let-bindings term))
. ,(map sopt-deparse-term (sopt-let-terms term)))]
[(sopt-apply? term)
`(apply ,(sopt-deparse-term (sopt-apply-proc term))
,(sopt-deparse-term (sopt-apply-list term)))]
[(sopt-call/cc? term)
`(call/cc ,(sopt-deparse-term (sopt-call/cc-proc term)))]
[(sopt-lambda? term)
(sopt-lambda-data term)]
[(sopt-set!? term)
`(set! ,(sopt-set!-var term) ,(sopt-deparse-term (sopt-set!-term term)))]
[(sopt-call? term)
`(,(sopt-deparse-term (sopt-call-proc term))
. ,(map sopt-deparse-term (sopt-call-args term)))]
[(sopt-var? term) term]
[else (error #"Invalid term: ~term")]))
| true |
d3f5f5f1a0764907b051021a07d8155c3fe56bd4 | 26aaec3506b19559a353c3d316eb68f32f29458e | /modules/ln_core/file-compress.scm | 9dfa62d6028a8c1c8a51c176015758415f00f63e | [
"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 | 2,757 | scm | file-compress.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.
|#
;; FastLZ based compression for files
;; It allows for very fast compression and decompression but files are about 33% larger than zip.
(define (compress:helper src dst compress?)
(if (file-exists? src)
(let* ((filesize (file-info-size (file-info src)))
(data (let ((content (if filesize (make-u8vector filesize) #f)))
(if content
(begin
(with-input-from-file src (lambda () (read-subu8vector content 0 filesize)))
content
)
(u8vector)))))
(let ((datacomp ((if compress? u8vector-compress u8vector-decompress) data)))
(with-output-to-file dst (lambda () (write-subu8vector datacomp 0 (u8vector-length datacomp))))
)
)))
(define (compress-file src dst)
(compress:helper src dst #t)
)
(define (decompress-file src dst)
(compress:helper src dst #f)
)
(define (quick-compress src)
(compress-file src (string-append src ".flz"))
(if (file-exists? (string-append src ".flz")) (delete-file src)))
(define (quick-decompress src)
(decompress-file (string-append src ".flz") src)
(if (file-exists? src) (delete-file (string-append src ".flz"))))
| false |
dc421b287d2e982b6ae539efc5662c6cdd343f02 | c24a946b86dbe91a078dd97536a6488eb52f6b77 | /t/issue/string-copy.scm | 2e22c0eef78194b6afbbe79b82ce358a8d86b450 | [
"MIT"
]
| permissive | picrin-scheme/picrin | 16090d88733e8c7b6e4a571dec0a5b65b3c02a7c | 05a21b650c9083b67692599db1a50b640f73ae39 | refs/heads/master | 2023-08-04T23:21:14.814662 | 2023-01-12T06:11:19 | 2023-01-12T06:12:23 | 13,706,205 | 380 | 43 | null | 2017-08-06T02:43:44 | 2013-10-19T18:16:47 | Scheme | UTF-8 | Scheme | false | false | 129 | scm | string-copy.scm | (import (scheme base)
(picrin test))
(test-begin)
(test "456" (string-copy (string-copy "1234567" 3) 0 3))
(test-end)
| false |
ee32f1cd0c5fd08e97e797eee2a6e2bd96066d63 | 296dfef11631624a5b2f59601bc7656e499425a4 | /snow/snow/binio/test-foment.scm | 9c4a5e21f421b2b04c99ddda15fb21f86d606059 | []
| 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 | 129 | scm | test-foment.scm | #! /usr/bin/env foment
(import (scheme base)
(scheme write)
(snow binio tests))
(display (run-tests))
(newline)
| false |
f14ae1979d4ff99f73f0c660c3c93f32aa46b8d3 | 696a4954b2dba8cdb090d55fc51b16a34072889e | /scheme/libtcod/map-functions.scm | 3b503e410159cd23efd93c631688d1cb30422cf7 | []
| no_license | thesnarky1/7DRL | 0da6d224431f163cdc55ab0d41e6a09875483167 | 3e364312631c5771128e3585723dd1b51f5d36d0 | refs/heads/master | 2016-09-06T19:53:17.572610 | 2010-02-25T03:06:25 | 2010-02-25T03:06:25 | 515,962 | 1 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 1,983 | scm | map-functions.scm | ;;Functions for our maps
;;Function to prepare our overall map object
(define create-tile-set
(lambda (map)
(list->vector (create-map-vector map 0))))
;;Function that creates the entire map vector
(define create-map-vector
(lambda (source y)
(let ((curr-row (car source)))
(if (= (length source) 1)
(cons (list->vector (create-tiles-from-string (string->list curr-row)
y
0))
'())
(cons (list->vector (create-tiles-from-string (string->list curr-row)
y
0))
(create-map-vector (cdr source) (+ y 1)))))))
;;Function that creates a Tile vector given a string
(define create-tiles-from-string
(lambda (char-list y x)
(let ((curr-char (car char-list)))
(if (= (length char-list) 1)
(cons (tile-from-char curr-char y x) '())
(cons (tile-from-char curr-char y x)
(create-tiles-from-string (cdr char-list)
y
(+ x 1)))))))
;;Function to create a tile given a characetr
(define tile-from-char
(lambda (char y x)
(let ((new-tile (tile-obj char x y 0
(lambda () #t)
(lambda () #t)
(lambda () #f)
'()
'())))
(if (member char IMPASSABLE-TILES)
(send-message new-tile set-passable (lambda () #f)))
(if (member char VISION-BLOCKING-TILES)
(send-message new-tile set-blocks-vision (lambda () #t)))
new-tile)))
| false |
c99e3ab4425f387301d782571471087fe0142acb | 58f60306f9f5638fbb23ec8b6ff896c191da48d4 | /3rd_party/s7/libutf8proc.scm | f12740c3c53f46535eb7b71be4d7697a01dc2dc4 | [
"MIT"
]
| permissive | mojmir-svoboda/BlackBoxTT | 650cd9da608a9909da32dc88a362affe3df50320 | 0c87b989827107695538e1bf1266c08b083dda44 | refs/heads/master | 2021-01-23T22:00:11.999135 | 2018-01-04T20:54:42 | 2018-01-04T20:54:42 | 58,350,784 | 11 | 3 | null | null | null | null | UTF-8 | Scheme | false | false | 10,907 | scm | libutf8proc.scm | ;;; utf8proc.scm
;;;
;;; tie the utf8proc library into the *utf8proc* environment
(require cload.scm)
(provide 'libutf8proc.scm)
;; if loading from a different directory, pass that info to C
(let ((current-file (port-filename (current-input-port))))
(let ((directory (and (or (char=? (current-file 0) #\/)
(char=? (current-file 0) #\~))
(substring current-file 0 (- (length current-file) 9)))))
(when (and directory (not (member directory *load-path*)))
(set! *load-path* (cons directory *load-path*)))
(with-let (rootlet)
(require cload.scm))
(when (and directory (not (string-position directory *cload-cflags*)))
(set! *cload-cflags* (string-append "-I" directory " " *cload-cflags*)))))
(if (not (defined? '*libutf8proc*))
(define *libutf8proc*
(with-let (unlet)
(set! *libraries* (cons (cons "libutf8proc.scm" (curlet)) *libraries*))
(c-define
'((C-macro (int (UTF8PROC_VERSION_MAJOR UTF8PROC_VERSION_MINOR UTF8PROC_VERSION_PATCH)))
(int (UTF8PROC_NULLTERM UTF8PROC_STABLE UTF8PROC_COMPAT UTF8PROC_COMPOSE UTF8PROC_DECOMPOSE
UTF8PROC_IGNORE UTF8PROC_REJECTNA UTF8PROC_NLF2LS UTF8PROC_NLF2PS UTF8PROC_NLF2LF
UTF8PROC_STRIPCC UTF8PROC_CASEFOLD UTF8PROC_CHARBOUND UTF8PROC_LUMP UTF8PROC_STRIPMARK))
(C-macro (int (UTF8PROC_ERROR_NOMEM UTF8PROC_ERROR_OVERFLOW UTF8PROC_ERROR_INVALIDUTF8 UTF8PROC_ERROR_NOTASSIGNED UTF8PROC_ERROR_INVALIDOPTS)))
(int (UTF8PROC_CATEGORY_CN UTF8PROC_CATEGORY_LU UTF8PROC_CATEGORY_LL UTF8PROC_CATEGORY_LT UTF8PROC_CATEGORY_LM
UTF8PROC_CATEGORY_LO UTF8PROC_CATEGORY_MN UTF8PROC_CATEGORY_MC UTF8PROC_CATEGORY_ME UTF8PROC_CATEGORY_ND
UTF8PROC_CATEGORY_NL UTF8PROC_CATEGORY_NO UTF8PROC_CATEGORY_PC UTF8PROC_CATEGORY_PD UTF8PROC_CATEGORY_PS
UTF8PROC_CATEGORY_PE UTF8PROC_CATEGORY_PI UTF8PROC_CATEGORY_PF UTF8PROC_CATEGORY_PO UTF8PROC_CATEGORY_SM
UTF8PROC_CATEGORY_SC UTF8PROC_CATEGORY_SK UTF8PROC_CATEGORY_SO UTF8PROC_CATEGORY_ZS UTF8PROC_CATEGORY_ZL
UTF8PROC_CATEGORY_ZP UTF8PROC_CATEGORY_CC UTF8PROC_CATEGORY_CF UTF8PROC_CATEGORY_CS UTF8PROC_CATEGORY_CO))
(int (UTF8PROC_BIDI_CLASS_L UTF8PROC_BIDI_CLASS_LRE UTF8PROC_BIDI_CLASS_LRO UTF8PROC_BIDI_CLASS_R UTF8PROC_BIDI_CLASS_AL
UTF8PROC_BIDI_CLASS_RLE UTF8PROC_BIDI_CLASS_RLO UTF8PROC_BIDI_CLASS_PDF UTF8PROC_BIDI_CLASS_EN UTF8PROC_BIDI_CLASS_ES
UTF8PROC_BIDI_CLASS_ET UTF8PROC_BIDI_CLASS_AN UTF8PROC_BIDI_CLASS_CS UTF8PROC_BIDI_CLASS_NSM UTF8PROC_BIDI_CLASS_BN
UTF8PROC_BIDI_CLASS_B UTF8PROC_BIDI_CLASS_S UTF8PROC_BIDI_CLASS_WS UTF8PROC_BIDI_CLASS_ON UTF8PROC_BIDI_CLASS_LRI
UTF8PROC_BIDI_CLASS_RLI UTF8PROC_BIDI_CLASS_FSI UTF8PROC_BIDI_CLASS_PDI))
(int (UTF8PROC_DECOMP_TYPE_FONT UTF8PROC_DECOMP_TYPE_NOBREAK UTF8PROC_DECOMP_TYPE_INITIAL UTF8PROC_DECOMP_TYPE_MEDIAL
UTF8PROC_DECOMP_TYPE_FINAL UTF8PROC_DECOMP_TYPE_ISOLATED UTF8PROC_DECOMP_TYPE_CIRCLE UTF8PROC_DECOMP_TYPE_SUPER
UTF8PROC_DECOMP_TYPE_SUB UTF8PROC_DECOMP_TYPE_VERTICAL UTF8PROC_DECOMP_TYPE_WIDE UTF8PROC_DECOMP_TYPE_NARROW
UTF8PROC_DECOMP_TYPE_SMALL UTF8PROC_DECOMP_TYPE_SQUARE UTF8PROC_DECOMP_TYPE_FRACTION UTF8PROC_DECOMP_TYPE_COMPAT))
(int (UTF8PROC_BOUNDCLASS_START UTF8PROC_BOUNDCLASS_OTHER UTF8PROC_BOUNDCLASS_CR UTF8PROC_BOUNDCLASS_LF
UTF8PROC_BOUNDCLASS_CONTROL UTF8PROC_BOUNDCLASS_EXTEND UTF8PROC_BOUNDCLASS_L UTF8PROC_BOUNDCLASS_V
UTF8PROC_BOUNDCLASS_T UTF8PROC_BOUNDCLASS_LV UTF8PROC_BOUNDCLASS_LVT UTF8PROC_BOUNDCLASS_REGIONAL_INDICATOR
UTF8PROC_BOUNDCLASS_SPACINGMARK))
(char* utf8proc_version (void))
(char* utf8proc_errmsg (int))
(int utf8proc_tolower ((utf8proc_int32_t int)))
(int utf8proc_toupper ((utf8proc_int32_t int)))
(int utf8proc_charwidth ((utf8proc_int32_t int)))
(int utf8proc_category ((utf8proc_int32_t int)))
(char* utf8proc_category_string ((utf8proc_int32_t int)))
(bool utf8proc_codepoint_valid ((utf8proc_int32_t int)))
(bool utf8proc_grapheme_break ((utf8proc_int32_t int) (utf8proc_int32_t int)))
(char* utf8proc_NFD (char*))
(char* utf8proc_NFC (char*))
(char* utf8proc_NFKD (char*))
(char* utf8proc_NFKC (char*))
(in-C "static s7_pointer g_utf8proc_iterate(s7_scheme *sc, s7_pointer args)
{
utf8proc_int32_t code_ref = 0;
int len, res;
char *str;
str = (char *)s7_string(s7_car(args));
len = s7_string_length(s7_car(args));
res = utf8proc_iterate(str, len, &code_ref);
return(s7_list(sc, 2, s7_make_integer(sc, code_ref), s7_make_integer(sc, res)));
}")
(C-function ("utf8proc_iterate" g_utf8proc_iterate "" 1))
(in-C "static s7_pointer g_utf8proc_encode_char(s7_scheme *sc, s7_pointer args)
{
ssize_t res;
utf8proc_uint8_t buf[8];
res = utf8proc_encode_char((utf8proc_int32_t)s7_integer(s7_car(args)), buf);
return(s7_list(sc, 2, s7_make_string_with_length(sc, buf, res), s7_make_integer(sc, res)));
}")
(C-function ("utf8proc_encode_char" g_utf8proc_encode_char "" 1))
(in-C "static s7_pointer g_utf8proc_reencode(s7_scheme *sc, s7_pointer args)
{
s7_pointer buffer, codepoints, options;
ssize_t res;
buffer = s7_car(args);
codepoints = s7_cadr(args);
options = s7_caddr(args);
res = utf8proc_reencode((utf8proc_int32_t *)s7_string(buffer),
(utf8proc_ssize_t)s7_integer(codepoints),
(utf8proc_option_t)s7_integer(options));
return(s7_make_integer(sc, res));
}")
(C-function ("utf8proc_reencode" g_utf8proc_reencode "" 1))
#|
(in-C "static s7_pointer g_utf8proc_utf8class(s7_scheme *sc, s7_pointer args)
{
return(s7_make_string_with_length(sc, (char *)utf8proc_utf8class, 256));
}")
(C-function ("utf8proc_utf8class" g_utf8proc_utf8class "" 0))
|#
(in-C "static s7_pointer g_utf8proc_get_property(s7_scheme *sc, s7_pointer args)
{
const utf8proc_property_t *info;
info = utf8proc_get_property((utf8proc_int32_t)s7_integer(s7_car(args)));
return(s7_inlet(sc, s7_list(sc, 30,
s7_make_symbol(sc, \"category\"), s7_make_integer(sc, info->category),
s7_make_symbol(sc, \"combining_class\"), s7_make_integer(sc, info->combining_class),
s7_make_symbol(sc, \"bidi_class\"), s7_make_integer(sc, info->bidi_class),
s7_make_symbol(sc, \"decomp_type\"), s7_make_integer(sc, info->decomp_type),
s7_make_symbol(sc, \"uppercase_mapping\"), s7_make_integer(sc, info->uppercase_mapping),
s7_make_symbol(sc, \"lowercase_mapping\"), s7_make_integer(sc, info->lowercase_mapping),
s7_make_symbol(sc, \"titlecase_mapping\"), s7_make_integer(sc, info->titlecase_mapping),
s7_make_symbol(sc, \"comb1st_index\"), s7_make_integer(sc, info->comb1st_index),
s7_make_symbol(sc, \"comb2nd_index\"), s7_make_integer(sc, info->comb2nd_index),
s7_make_symbol(sc, \"bidi_mirrored\"), s7_make_integer(sc, info->bidi_mirrored),
s7_make_symbol(sc, \"comp_exclusion\"), s7_make_integer(sc, info->comp_exclusion),
s7_make_symbol(sc, \"ignorable\"), s7_make_integer(sc, info->ignorable),
s7_make_symbol(sc, \"control_boundary\"), s7_make_integer(sc, info->control_boundary),
s7_make_symbol(sc, \"boundclass\"), s7_make_integer(sc, info->boundclass),
s7_make_symbol(sc, \"charwidth\"), s7_make_integer(sc, info->charwidth))));
}")
(C-function ("utf8proc_get_property" g_utf8proc_get_property "" 1))
(in-C "static s7_pointer g_utf8proc_decompose_char(s7_scheme *sc, s7_pointer args)
{
s7_pointer code, opt, str;
int last_boundclass;
utf8proc_ssize_t size;
utf8proc_int32_t *dst;
ssize_t res;
code = s7_car(args);
str = s7_cadr(args);
opt = s7_caddr(args);
dst = (utf8proc_int32_t *)s7_string(str);
size = (utf8proc_ssize_t)s7_string_length(str);
res = utf8proc_decompose_char((utf8proc_int32_t)s7_integer(code), dst, size, (utf8proc_option_t)s7_integer(opt), &last_boundclass);
return(s7_make_integer(sc, res));
}")
(C-function ("utf8proc_decompose_char" g_utf8proc_decompose_char "" 3))
(in-C "static s7_pointer g_utf8proc_map(s7_scheme *sc, s7_pointer args)
{
s7_pointer opt, str;
ssize_t res;
utf8proc_uint8_t *dst;
str = s7_car(args);
opt = s7_cadr(args);
res = utf8proc_map((utf8proc_uint8_t *)s7_string(str), s7_string_length(str), &dst, (utf8proc_option_t)s7_integer(opt));
if (res < 0) return(s7_make_integer(sc, res));
return(s7_make_string_with_length(sc, dst, res));
}")
(C-function ("utf8proc_map" g_utf8proc_map "" 2))
(in-C "static s7_pointer g_utf8proc_decompose(s7_scheme *sc, s7_pointer args)
{
s7_pointer opt, str;
int len;
ssize_t res;
utf8proc_int32_t *dst;
str = s7_car(args);
opt = s7_cadr(args);
len = s7_string_length(str);
dst = (utf8proc_int32_t *)malloc(len * 4);
res = utf8proc_decompose((const utf8proc_uint8_t *)s7_string(str), len, dst, len, (utf8proc_option_t)s7_integer(opt));
if (res < 0) return(s7_make_integer(sc, res));
return(s7_make_string_with_length(sc, (char *)dst, res));
}")
(C-function ("utf8proc_decompose" g_utf8proc_decompose "" 2))
)
"" "utf8proc.h" "" "-lutf8proc" "utf8proc_s7")
(curlet))))
*libutf8proc*
| false |
f6b8ddb502816e27d8e5e4bfbdb894b36e72bad3 | defeada37d39bca09ef76f66f38683754c0a6aa0 | /mscorlib/system/security/policy/mono-trust-manager.sls | a98749cd9bf2e20c4da3c6655d5bc66d6dc52c77 | []
| 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,054 | sls | mono-trust-manager.sls | (library (system security policy mono-trust-manager)
(export new
is?
mono-trust-manager?
from-xml
to-xml
determine-application-trust)
(import (ironscheme-clr-port))
(define-syntax new
(lambda (e)
(syntax-case e ()
((_ a ...)
#'(clr-new System.Security.Policy.MonoTrustManager a ...)))))
(define (is? a) (clr-is System.Security.Policy.MonoTrustManager a))
(define (mono-trust-manager? a)
(clr-is System.Security.Policy.MonoTrustManager a))
(define-method-port
from-xml
System.Security.Policy.MonoTrustManager
FromXml
(System.Void System.Security.SecurityElement))
(define-method-port
to-xml
System.Security.Policy.MonoTrustManager
ToXml
(System.Security.SecurityElement))
(define-method-port
determine-application-trust
System.Security.Policy.MonoTrustManager
DetermineApplicationTrust
(System.Security.Policy.ApplicationTrust
System.ActivationContext
System.Security.Policy.TrustManagerContext)))
| true |
39eea783b9a758b8e03f6960142d578825271f4a | ab05b79ab17619f548d9762a46199dc9eed6b3e9 | /sitelib/ypsilon/gobject/signal.scm | 8c07ef0172d71c5bedbf21ab82088a1dc4e552c2 | [
"BSD-2-Clause"
]
| permissive | lambdaconservatory/ypsilon | 2dce9ff4b5a50453937340bc757697b9b4839dee | f154436db2b3c0629623eb2a53154ad3c50270a1 | refs/heads/master | 2021-02-28T17:44:05.571304 | 2017-12-17T12:29:00 | 2020-03-08T12:57:52 | 245,719,032 | 1 | 0 | NOASSERTION | 2020-03-07T23:08:26 | 2020-03-07T23:08:25 | null | UTF-8 | Scheme | false | false | 4,505 | scm | signal.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 gobject signal)
(export signal-callback
g_signal_connect
g_signal_connect_after
g_signal_connect_swapped
g_signal_handler_block
g_signal_handler_disconnect
g_signal_handler_is_connected
g_signal_handler_unblock)
(import (rnrs) (ypsilon ffi) (only (core) string-contains))
(define lib-name
(cond (on-linux "libgobject-2.0.so.0")
(on-sunos "libgobject-2.0.so.0")
(on-freebsd "libgobject-2.0.so")
(on-openbsd "libgobject-2.0.so")
(on-darwin "GLib.framework/GLib")
(on-windows "libgobject-2.0-0.dll")
(else
(assertion-violation #f "can not locate GObject 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)))))
;; gulong g_signal_connect_data (gpointer instance, const gchar* detailed_signal, GCallback c_handler, gpointer data, GClosureNotify destroy_data, GConnectFlags connect_flags)
(define-function unsigned-long g_signal_connect_data (void* char* void* void* void* int))
;; gulong g_signal_connect_object (gpointer instance, const gchar* detailed_signal, GCallback c_handler, gpointer gobject, GConnectFlags connect_flags)
(define-function unsigned-long g_signal_connect_object (void* char* (c-callback int (void*)) void* int))
;; void g_signal_handler_block (gpointer instance, gulong handler_id)
(define-function void g_signal_handler_block (void* unsigned-long))
;; void g_signal_handler_disconnect (gpointer instance, gulong handler_id)
(define-function void g_signal_handler_disconnect (void* unsigned-long))
;; gboolean g_signal_handler_is_connected (gpointer instance, gulong handler_id)
(define-function int g_signal_handler_is_connected (void* unsigned-long))
;; void g_signal_handler_unblock (gpointer instance, gulong handler_id)
(define-function void g_signal_handler_unblock (void* unsigned-long))
(define g_signal_connect
(lambda (instance detailed_signal c_handler data)
(g_signal_connect_data instance detailed_signal c_handler data 0 0)))
(define g_signal_connect_after
(lambda (instance detailed_signal c_handler data)
(g_signal_connect_data instance detailed_signal c_handler data 0 1)))
(define g_signal_connect_swapped
(lambda (instance detailed_signal c_handler data)
(g_signal_connect_object instance detailed_signal c_handler data 2)))
(define-syntax signal-callback
(lambda (x)
(define marshal
(lambda (type)
(let ((name (symbol->string type)))
(cond ((or (eq? (string-contains name "Gtk") 0)
(eq? (string-contains name "Gdk") 0))
(if (string-contains name "*") 'void* 'int))
((assq type
'((gboolean . int)
(gpointer . void*)
(gconstpointer . void*)
(gchar . int8_t)
(guchar . uint8_t)
(gint . int)
(guint . unsigned-int)
(gshort . short)
(gushort . unsigned-short)
(glong . long)
(gulong . unsigned-long)
(gint8 . int8_t)
(guint8 . uint8_t)
(gint16 . int16_t)
(guint16 . uint16_t)
(gint32 . int32_t)
(guint32 . uint32_t)
(gint64 . int64_t)
(guint64 . uint64_t)
(gfloat . float)
(gdouble . double)
(gsize . unsigned-long)
(gssize . long))) => cdr)
(else type)))))
(syntax-case x ()
((_ ret args body)
(with-syntax
((ret (datum->syntax #'k (marshal (syntax->datum #'ret))))
(args (datum->syntax #'k (map marshal (syntax->datum #'args)))))
#'(make-cdecl-callback 'ret 'args body))))))
) ;[end]
| true |
24f8a4b77fccb361bf9737d2e698e408193e975b | 87482c1b1d5dd031a8afa84242e08baad756a829 | /build.ss | b597a5463abcb1591119f6a5976bad80d2d00ef9 | []
| no_license | arcfide/descot | 504d97860c82fb93a1f98fd8781ed2bfc68947d6 | 0b6a5b7422829519bd3a5db8b0aae4bc58fa0ade | refs/heads/master | 2021-01-20T11:04:45.955794 | 2012-01-21T20:23:26 | 2012-01-21T20:23:26 | 3,235,812 | 0 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 717 | ss | build.ss | #! /usr/bin/scheme --program
(import (chezscheme) (riastradh foof-loop) (arcfide building) (arcfide ffi-bind parameters))
(unless (<= 3 (length (command-line-arguments)))
(printf "~a : <output-program> <build-dir> <files> ... ~%" (car (command-line)))
(exit 1))
(define (read-inputs-from-file infile)
(collect-list (for lib (in-file infile read)) lib))
(define out-file (car (command-line-arguments)))
(define build-dir (cadr (command-line-arguments)))
(define inputs (read-inputs-from-file (caddr (command-line-arguments))))
(unless (file-exists? build-dir) (mkdir build-dir))
(ffi-build-path build-dir)
(library-extensions '(".chezscheme.sls" ".sls" ""))
(build-program out-file build-dir inputs)
(exit 0)
| false |
a159d0cdca70bc505ae516b1cdc4cee00005f1a4 | dd4cc30a2e4368c0d350ced7218295819e102fba | /vendored_parsers/tree-sitter-nix/queries/locals.scm | bb148696813317f49146b67edb1346b1c51aa08f | [
"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 | 1,220 | scm | locals.scm | ;; when using @local.reference, tree-sitter seems to
;; apply the scope from the identifier it has looked up,
;; which makes sense for most languages.
;; however, we want to highlight things as function based on their call-site,
;; not their definition; therefore using TS's support for tracking locals
;; impedes our ability to get the highlighting we want.
;;
;; also, TS doesn't seem to support scoping as implemented in languages
;; with lazy let bindings, which results in syntax highlighting/goto-reference
;; results that depend on the order of definitions, which is counter to the
;; semantics of Nix.
;;
;; so for now we'll opt for not having any locals queries.
;;
;; see: https://github.com/tree-sitter/tree-sitter/issues/918
;(function_expression
; universal: (identifier)? @local.definition
; formals: (formals (formal name: (identifier) @local.definition)*)
; universal: (identifier)? @local.definition
; ) @local.scope
;
;(rec_attrset_expression
; bind: (binding
; attrpath: (attrpath . (attr_identifier) @local.definition))
;) @local.scope
;
;(let_expression
; bind: (binding
; attrpath: (attrpath . (attr_identifier) @local.definition))
;) @local.scope
;
;(identifier) @local.reference
| false |
f15fb8b43911e9d4aadc48329b5f2b721c39424a | 82d771f9c7a77fc0c084f6c5fca5d5b7480aa883 | /core/keyword.ss | e1584d018da69433defe357759fe9a243f8d4a1a | []
| no_license | localchart/not-a-box | d45725722c0bfa6d07cf37ef4c33a5358b1dd987 | b6c1af4fb0eb877610a3a20b5265a8c8d2dd28e9 | refs/heads/master | 2021-01-20T10:10:14.034524 | 2017-05-04T21:54:41 | 2017-05-04T21:54:41 | null | 0 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 461 | ss | keyword.ss |
(define-record keyword (symbol))
(define (string->keyword s)
(define sym (string->symbol s))
(or (getprop sym 'keyword #f)
(let ([kw (make-keyword sym)])
(putprop sym 'keyword kw)
kw)))
(define (keyword->string kw)
(symbol->string (keyword-symbol kw)))
(define (keyword<? a b)
(symbol<? (keyword-symbol a)
(keyword-symbol b)))
(define (symbol<? a b)
(string<? (symbol->string a)
(symbol->string b)))
| false |
7ad90ddf96a7c5105d440640dd1d43586028788a | 2c01a6143d8630044e3629f2ca8adf1455f25801 | /xitomatl/ports.sls | 75dad758b2610694f18e82d0b613abceb0638a76 | [
"X11-distribute-modifications-variant"
]
| permissive | stuhlmueller/scheme-tools | e103fac13cfcb6d45e54e4f27e409adbc0125fe1 | 6e82e873d29b34b0de69b768c5a0317446867b3c | refs/heads/master | 2021-01-25T10:06:33.054510 | 2017-05-09T19:44:12 | 2017-05-09T19:44:12 | 1,092,490 | 5 | 1 | null | null | null | null | UTF-8 | Scheme | false | false | 11,527 | sls | ports.sls | #!r6rs
;; Copyright 2009 Derick Eddington. My MIT-style license is in the file named
;; LICENSE from the original collection this file is distributed with.
(library (xitomatl ports)
(export
binary-input-port? binary-output-port?
textual-input-port? textual-output-port?
port-closed? ;; from (xitomatl ports compat)
read-all get-lines-all
port-for-each port-map
input-port-enumerator ;; from (xitomatl enumerators)
open-binary-compound-input-port open-textual-compound-input-port
#|open-binary-pipe-ports open-textual-pipe-ports|#)
(import
(rnrs)
(only (xitomatl define) define/AV)
(only (xitomatl control) begin0)
#|(only (xitomatl bytevectors) subbytevector)
(only (xitomatl strings) string-copy!)
(xitomatl queue)|#
(only (xitomatl enumerators) fold/enumerator input-port-enumerator)
(xitomatl ports compat))
(define (binary-input-port? x)
(and (input-port? x)
(binary-port? x)))
(define (binary-output-port? x)
(and (output-port? x)
(binary-port? x)))
(define (textual-input-port? x)
(and (input-port? x)
(textual-port? x)))
(define (textual-output-port? x)
(and (output-port? x)
(textual-port? x)))
(define read-all
(case-lambda
((port)
(port-map values read port))
(()
(read-all (current-input-port)))))
(define get-lines-all
(case-lambda
((port)
(port-map values get-line port))
(()
(get-lines-all (current-input-port)))))
(define port-for-each
(case-lambda
((proc reader port)
(fold/enumerator
(input-port-enumerator reader)
port
(lambda (x) (proc x) #T)))
((proc reader)
(port-for-each proc reader (current-input-port)))))
(define port-map
(case-lambda
((proc reader port)
(reverse
(fold/enumerator
(input-port-enumerator reader)
port
(lambda (x a) (values #T (cons (proc x) a)))
'())))
((proc reader)
(port-map proc reader (current-input-port)))))
(define/AV (open-compound-input-port list-or-proc maybe-transcoder)
;; A compound input port is a custom port which represents the logical
;; concatenation of other input ports. It starts out with an ordered
;; collection of input ports and reads from the first one until end of file
;; is reached, whereupon it reads from the second one, and so on, until end
;; of file is reached on the last of the contained input ports, and then
;; subsequent reads from the compound input port will return end of file.
;; After each component port is exhausted, it is closed. Closing a compound
;; input port closes all remaining component ports. get-position and
;; set-position! are not supported.
;;
;; The first argument to open-compound-input-port must be either a list of
;; components or a zero-argument procedure which returns components. If it
;; is a procedure, it is called each time the next component port is needed
;; and it must return the next component or #F to indicate there are no
;; more. The second argument must be either a transcoder or #F. If it is a
;; transcoder, the compound input port will be textual and the acceptable
;; values for components are textual input ports, binary input ports,
;; strings, and bytevectors; otherwise the compound input port will be
;; binary and the acceptable values are binary input ports and bytevectors.
;; For a textual compound input port, binary input port components are
;; transcoded, bytevector components are used as the source of transcoded
;; bytevector input ports, textual input ports are used directly and their
;; transcoder may be different than the compound input port's, and string
;; components are used as the source of string input ports. For a binary
;; compound input port, binary input port components are used directly and
;; bytevector components are used as the source of raw bytevector input
;; ports.
(define (make-handler prefix)
;; Returns a function which maps the allowable types into input-ports.
(define (invalid suffix x)
(AV (string-append prefix " " suffix) x))
(if maybe-transcoder
(lambda (n)
(cond ((input-port? n)
(if (textual-port? n) n (transcoded-port n maybe-transcoder)))
((string? n)
(open-string-input-port n))
((bytevector? n)
(open-bytevector-input-port n maybe-transcoder))
(else
(invalid "Not an input port or string or bytevector." n))))
(lambda (n)
(cond ((and (input-port? n) (binary-port? n))
n)
((bytevector? n)
(open-bytevector-input-port n))
(else
(invalid "Not a binary input port or bytevector." n))))))
(define next
;; Returns the next input-port, or #F if there are no more.
(cond
((or (pair? list-or-proc) (null? list-or-proc))
(let ((l list-or-proc)
(handle (make-handler "Invalid value in supplied list.")))
(lambda ()
(cond ((pair? l) (begin0 (handle (car l))
(set! l (cdr l))))
((null? l) #F)
(else (AV "not a proper list" list-or-proc))))))
((procedure? list-or-proc)
(let ((handle
(make-handler "Invalid value returned from supplied procedure.")))
(lambda ()
(let ((n (list-or-proc)))
(and n (handle n))))))
(else
(AV "not a list or procedure" list-or-proc))))
(define (make-compound-port make-custom id get-n! current)
(make-custom id
(letrec ((read! (lambda (str-or-bv start count)
(if current
(let ((x (get-n! current str-or-bv start count)))
(cond ((eof-object? x)
(close-port current)
(set! current (next))
(read! str-or-bv start count))
(else
x)))
0 #| EOF for this compound port |#))))
read!)
#F #F ;; get-position and set-position! not supported
(lambda ()
;; This `when' also prevents a finished `next'
;; from being called more than once.
(when current
(close-port current)
(set! current #F) ;; shouldn't be necessary, but just in case
(let loop ((n (next)))
(when n
(close-port n)
(loop (next))))))))
(let ((current (next)))
(if maybe-transcoder
(make-compound-port
make-custom-textual-input-port
"<textual-compound-input-port>"
get-string-n!
current)
(make-compound-port
make-custom-binary-input-port
"<binary-compound-input-port>"
get-bytevector-n!
current))))
(define (open-binary-compound-input-port list-or-proc)
(open-compound-input-port list-or-proc #F))
(define/AV open-textual-compound-input-port
(case-lambda
((list-or-proc)
(open-compound-input-port list-or-proc (native-transcoder)))
((list-or-proc transcoder)
(unless transcoder
(AV "transcoder cannot be #F"))
(open-compound-input-port list-or-proc transcoder))))
#|
(define (make-open-pipe-ports mcop opid mcip ipid sub copy! len)
;; TODO: Need a mutex for each pipe so that it can be made safe for a
;; thread to use one of a pipe's ports and another thread to use the
;; other port. Need a way for the input port to block until there
;; is something ready to be read.
(begin ;; Just for superficial non-threaded testing
(define (make-mutex) #F)
(define (acquire-mutex m) (values))
(define (release-mutex m) (values))
(define-syntax synchronized (syntax-rules () ((_ _ expr ...) (begin expr ...))))
(define (block-until-something-enqueued) (values)))
;; NOTE: The safety of concurrent use of the same port is not the
;; responsibility of this pipes implementation.
(lambda ()
(let ((mutex (make-mutex))
(q (make-empty-queue))
(closed #F))
(values
(mcop opid
(lambda (bv-or-str start count)
(let ((x (if (positive? count)
(sub bv-or-str start (+ start count))
(eof-object))))
(synchronized mutex
(when closed
(assertion-violation opid "input end closed"))
(enqueue! q x)))
count)
#F #F ;; get-position and set-position! not supported
(lambda ()
(synchronized mutex
(set! closed #T))))
(let ((current #F) (pos #F))
(mcip ipid
(letrec ((read!
(lambda (bv-or-str start count)
(if current
(let* ((curlen (- (len current) pos))
(copylen (min count curlen)))
(copy! current pos bv-or-str start copylen)
(if (= curlen copylen)
(begin
(set! current #F)
(set! pos #F))
(set! pos (+ pos copylen)))
copylen)
(if (begin (acquire-mutex mutex)
(positive? (queue-length q)))
(let ((x (dequeue! q)))
(release-mutex mutex)
(if (eof-object? x)
0 ;; EOF, but still possible to read again
(begin (set! current x)
(set! pos 0)
(read! bv-or-str start count))))
(if (begin0 closed
(release-mutex mutex))
0 ;; return EOF from now on
(begin (block-until-something-enqueued)
(read! bv-or-str start count))))))))
read!)
#F #F ;; get-position and set-position! not supported
(lambda ()
(synchronized mutex
(set! q #F)
(set! closed #T))
(set! current #F))))))))
(define open-binary-pipe-ports
(make-open-pipe-ports
make-custom-binary-output-port "<binary-pipe-output-port>"
make-custom-binary-input-port "<binary-pipe-input-port>"
subbytevector
bytevector-copy!
bytevector-length))
(define open-textual-pipe-ports
(make-open-pipe-ports
make-custom-textual-output-port "<textual-pipe-output-port>"
make-custom-textual-input-port "<textual-pipe-input-port>"
substring
string-copy!
string-length))
|#
;; TODO: Pushback ports
;; TODO?: Filter ports
;; TODO?: Line counting ports
)
| true |
e5001c95328640487ab55683d384bdb8a391cb6c | a09ad3e3cf64bc87282dea3902770afac90568a7 | /1/12.scm | 1351cd98718fb17f7b2deb8aa81fa577d13de72b | []
| 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 | 426 | scm | 12.scm | #lang sicp
(define (pascal-triangle row col)
(cond ((= row 1) 1)
((= row 2) 1)
((= col 1) 1)
((= col row) 1)
(else (+
(pascal-triangle (- row 1) (- col 1))
(pascal-triangle (- row 1) col)
)
)
)
)
(pascal-triangle 3 2)
(pascal-triangle 5 1)
(pascal-triangle 5 2)
(pascal-triangle 5 3)
(pascal-triangle 5 4)
(pascal-triangle 5 5)
| false |
f129bcac68984474a43fef224a69440756cba025 | b43e36967e36167adcb4cc94f2f8adfb7281dbf1 | /sicp/ch2/exercises/2.3.scm | 82da4400f7c8a897c9252bbfff1cd42e679f0bf9 | []
| no_license | ktosiu/snippets | 79c58416117fa646ae06a8fd590193c9dd89f414 | 08e0655361695ed90e1b901d75f184c52bb72f35 | refs/heads/master | 2021-01-17T08:13:34.067768 | 2016-01-29T15:42:14 | 2016-01-29T15:42:14 | 53,054,819 | 1 | 0 | null | 2016-03-03T14:06:53 | 2016-03-03T14:06:53 | null | UTF-8 | Scheme | false | false | 335 | scm | 2.3.scm | (define (make-rect w h)
(cons w h))
(define (width rect)
(car rect))
(define (height rect)
(cdr rect))
(define (area rect)
(* (width rect)
(height rect)))
(define (perimeter rect)
(+ (* 2 (width rect))
(* 2 (height rect))))
(define (make-rect a b c d)
(cons (make-segement a b)
(make-segement a c)))
| false |
22402df86774942702a95f9a3cbfd57a1961e548 | 4f30ba37cfe5ec9f5defe52a29e879cf92f183ee | /src/regex/nfa.scm | 41879b07d96e653f23da2ab9eb695f9fbde8fe85 | [
"MIT"
]
| permissive | rtrusso/scp | e31ecae62adb372b0886909c8108d109407bcd62 | d647639ecb8e5a87c0a31a7c9d4b6a26208fbc53 | refs/heads/master | 2021-07-20T00:46:52.889648 | 2021-06-14T00:31:07 | 2021-06-14T00:31:07 | 167,993,024 | 8 | 1 | MIT | 2021-06-14T00:31:07 | 2019-01-28T16:17:18 | Scheme | UTF-8 | Scheme | false | false | 11,188 | scm | nfa.scm | (need util/list)
(need util/string)
(need regex/fsm)
(need regex/dfa)
;; NFA Rule interface ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(define (nfa-rule from value to)
(vector from value to))
(define (nfa-lambda-rule from to)
(vector from to))
(define (nfa-rule.lambda? nfa-rule)
(and (vector? nfa-rule) (= 2 (vector-length nfa-rule))))
(define (nfa-rule.from nfa-rule)
(vector-ref nfa-rule 0))
(define (nfa-rule.from? nfa-rule s)
(state=? s (nfa-rule.from nfa-rule)))
(define (nfa-rule.to nfa-rule)
(cond ((nfa-rule.lambda? nfa-rule) (vector-ref nfa-rule 1))
(else (vector-ref nfa-rule 2))))
(define (nfa-rule.value nfa-rule)
(if (nfa-rule.lambda? nfa-rule)
(error "Lambda (empty-string) rule has no value -- NFA-RULE.VALUE"
nfa-rule))
(vector-ref nfa-rule 1))
(define (nfa-rule.value? nfa-rule value)
(or (equal? (nfa-rule.value nfa-rule) value)
(and (string? (nfa-rule.value nfa-rule))
(char? value)
(strchr (nfa-rule.value nfa-rule) value))))
(define (nfa-rule-filter p? nfa-rules)
(remove-duplicate-states (map nfa-rule.to (filter p? nfa-rules))))
;; NFA interface ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(define (nfa? obj)
(tagged? 'nfa obj))
(define (nfa.current-states nfa)
((safe-contents 'nfa nfa) 'get-current))
(define (nfa.emit-rule-set nfa)
((safe-contents 'nfa nfa) 'get-emit-rules))
(define (nfa.current-emitted-values nfa)
(let ((result '()))
((safe-contents 'nfa nfa) 'emit
(lambda (x) (set! result (cons x result))))
result))
(define (nfa.get-emitted-values-for-states nfa states)
(let ((result '())
(rules (nfa.emit-rule-set nfa)))
(for-each (lambda (state)
(let ((item (assoc state rules)))
(if (and item
(not (member item result)))
(set! result (cons (cdr item) result)))))
states)
result))
(define (nfa.initial-state nfa)
((safe-contents 'nfa nfa) 'get-initial))
(define (nfa.final-states nfa)
((safe-contents 'nfa nfa) 'get-final))
(define (nfa.rule-set nfa)
((safe-contents 'nfa nfa) 'get-rules))
(define (nfa.input! nfa obj)
((safe-contents 'nfa nfa) 'input obj))
(define (nfa.reset! nfa)
((safe-contents 'nfa nfa) 'reset))
(define (nfa.failed? nfa)
(null? (nfa.current-states nfa)))
(define (nfa.done? nfa)
(and (not (nfa.failed? nfa))
(let ((isect
(intersect-lists state=?
(nfa.current-states nfa)
(nfa.final-states nfa))))
(and (not (null? isect)) isect))))
;; Advanced NFA routines ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(define (nfa.reachable-states nfa)
(depth-first-search state=?
(nfa.initial-state nfa)
(lambda (state)
(map nfa-rule.to
(filter (lambda (rule)
(nfa-rule.from? rule state))
(nfa.rule-set nfa))))))
(define (nfa.referenced-states nfa)
(remove-duplicate-states
(append (cons (nfa.initial-state nfa)
(nfa.final-states nfa))
(map nfa-rule.from (nfa.rule-set nfa))
(map nfa-rule.to (nfa.rule-set nfa)))))
(define (nfa:possible-transitions nfa state)
(remove-duplicates
equal?
(append-map
(lambda (rule)
(let ((val (nfa-rule.value rule)))
(cond ((string? val)
(string->list val))
((char? val)
(list val))
(else
(error "Unrecognized NFA rule value: " val)))))
(filter (lambda (rule)
(and (not (nfa-rule.lambda? rule))
(nfa-rule.from? rule state)))
(nfa.rule-set nfa)))))
(define (nfa:possible-transitions* nfa statelist)
(remove-duplicates
equal?
(append-map (lambda (state) (nfa:possible-transitions nfa state))
statelist)))
(define (nfa:lambda-closure nfa state)
(depth-first-search state=?
state
(lambda (state)
(remove-duplicate-states
(nfa-rule-filter (lambda (rule)
(and (nfa-rule.lambda? rule)
(nfa-rule.from? rule state)))
(nfa.rule-set nfa))))))
(define (nfa:next nfa state obj)
(define (matching-rule? rule)
(and (nfa-rule.from? rule state)
(not (nfa-rule.lambda? rule))
(nfa-rule.value? rule obj)))
(remove-duplicate-states
(append-map (lambda (state) (nfa:lambda-closure nfa state))
(nfa-rule-filter matching-rule? (nfa.rule-set nfa)))))
(define (nfa:next* nfa states obj)
(remove-duplicate-states
(append-map (lambda (state) (nfa:lambda-closure nfa state))
(append-map (lambda (state) (nfa:next nfa state obj))
states))))
;; NFA constructor ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(define (build-nfa initial-state final-states rules emit-rules)
(define (lambda-closure state)
(depth-first-search state=?
state
(lambda (state)
(remove-duplicate-states
(nfa-rule-filter (lambda (rule)
(and (nfa-rule.lambda? rule)
(nfa-rule.from? rule state)))
rules)))))
(let ((cur (lambda-closure initial-state)))
(define (get-current)
cur)
(define (reset)
(set! cur (lambda-closure initial-state)))
(define (input obj)
(define (next state)
(define (matching-rule? rule)
(and (nfa-rule.from? rule state)
(not (nfa-rule.lambda? rule))
(nfa-rule.value? rule obj)))
(nfa-rule-filter matching-rule? rules))
(set! cur
(remove-duplicate-states
(append-map lambda-closure (append-map next cur))))
cur)
(define (get-initial)
initial-state)
(define (get-final)
final-states)
(define (get-rules)
rules)
(define (get-emit-rules)
emit-rules)
(define (emit receive-result)
(for-each (lambda (state)
(let ((result (assoc state emit-rules)))
(if result
(receive-result (cdr result)))))
(get-current)))
(define (nfa-dispatch sym . args)
(apply (case sym
((get-current) get-current)
((get-initial) get-initial)
((get-final) get-final)
((input) input)
((reset) reset)
((emit) emit)
((get-emit-rules) get-emit-rules)
((get-rules) get-rules))
args))
(tag 'nfa nfa-dispatch)))
;; NFA transforms ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(define (nfa->dfa nfa)
(define unique-state (let ((s -1)) (lambda () (set! s (+ s 1)) s)))
(define (possible-transitions* states)
(nfa:possible-transitions* nfa states))
(define (dfa-transformer nfa-states)
(lambda (state) (index-of state
(list-set-comparator equal?)
nfa-states)))
(define (compute-final-states statelists)
(remove-duplicates
(list-set-comparator state=?)
(filter (lambda (statelist)
(not (null? (intersect-lists state=?
statelist
(nfa.final-states nfa)))))
statelists)))
(define (create-dfa visited rules)
(dfa-transform
(build-dfa (nfa:lambda-closure nfa (nfa.initial-state nfa))
(compute-final-states visited)
rules
(filter-map
(lambda (statelist)
(let ((emit
(nfa.get-emitted-values-for-states nfa statelist)))
(and (not (null? emit))
(cons statelist emit))))
visited))
(dfa-transformer visited))
)
(define (iter queue visited rules)
(define (statelists-to-queue cur-statelist)
(map (lambda (obj)
(nfa:next* nfa cur-statelist obj))
(possible-transitions* cur-statelist)))
(define (new-rules cur-statelist)
(map
(lambda (obj)
(nfa-rule cur-statelist obj (nfa:next* nfa cur-statelist obj)))
(possible-transitions* cur-statelist)))
(define (visited? statelist)
(list-contains? (list-set-comparator state=?)
statelist
visited))
(define (queue-statelists list-of-statelists)
(union-lists (list-set-comparator state=?)
(subtract-lists (list-set-comparator state=?)
list-of-statelists
visited)
(cdr queue)))
(define (queue-rules new-rules)
(append new-rules rules))
(if (null? queue)
(create-dfa visited rules)
(let ((cur-statelist (car queue)))
;(display "Current: ") (write cur-statelist) (newline)
;(display "Queue: ") (write queue) (newline)
;(display "Visited: ") (write visited) (newline)
;(display "Rules: ") (write rules) (newline)
;(newline)
;(newline)
;(newline)
(iter (queue-statelists (statelists-to-queue cur-statelist))
(cons cur-statelist visited)
(queue-rules (new-rules cur-statelist))))))
(iter (list (nfa:lambda-closure nfa (nfa.initial-state nfa)))
'()
'()))
;; (define
;; nex (build-nfa #\a (list #\b)
;; (list (nfa-rule #\a 3 #\b)
;; (nfa-rule #\a 3 #\c)
;; (nfa-lambda-rule #\a #\b))
;; '((#\a . 0)
;; (#\b . 1))))
;; NFA graphviz integration ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(define (nfa.graphviz nfa)
(display "digraph nondeterministic_finite_automaton {\n")
(display " rankdir=LR;\n")
(begin (display " node [shape = doublecircle]; ")
(display (nfa.initial-state nfa))
(display ";\n"))
(display " node [shape = circle];\n")
(for-each (lambda (rule)
(display " ")
(display (nfa-rule.from rule))
(display " -> ")
(display (nfa-rule.to rule))
(display " [ label = ")
(if (nfa-rule.lambda? rule)
(write "***")
(cond ((char? (nfa-rule.value rule))
(display #\")
(write (nfa-rule.value rule))
(display #\"))
(else
(write (nfa-rule.value rule)))))
(display " ];\n"))
(nfa.rule-set nfa))
(display "}\n"))
;; Generic Procedure setup ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(genproc-install 'fsm? '(nfa) nfa?)
(genproc-install 'fsm.input! '(nfa <character>) nfa.input!)
(genproc-install 'fsm.reset! '(nfa) nfa.reset!)
(genproc-install 'fsm.done? '(nfa) nfa.done?)
(genproc-install 'fsm.failed? '(nfa) nfa.failed?)
| false |
9cb843b81072eb09e7926c6410ab8b11cc31a223 | 000dbfe5d1df2f18e29a76ea7e2a9556cff5e866 | /ext/crypto/tests/testvectors/hmac/hmac_sha3_384_test.scm | 0f12d21156ff4e3257e117a18bb59e31ce095cad | [
"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 | 74,322 | scm | hmac_sha3_384_test.scm | (test-hmac
"hmac_sha3_384_test"
:algorithm
"HMACSHA3-384"
:key-size
384
:tag-size
384
:tests
'(#(1
"empty message"
#vu8(238 141 240 103 133 125 242 48 15 167 26 16 195 9 151 23 139 179 121 97 39 181 236 229 242 204 193 112 147 43 224 231 142 169 176 165 147 108 9 21 126 103 28 231 236 159 197 16)
#vu8()
#vu8(124 135 227 191 42 99 66 140 32 5 168 44 30 240 224 21 37 55 206 122 111 73 52 79 58 133 39 71 36 224 117 249 200 51 182 178 230 221 37 126 96 34 46 113 38 49 36 38)
#t
())
#(2
"short message"
#vu8(151 102 150 192 220 151 24 44 167 113 151 92 57 40 255 145 104 239 137 205 116 12 210 41 40 88 253 145 96 104 167 2 188 29 247 198 205 142 225 240 210 94 97 212 197 20 204 93)
#vu8(43)
#vu8(185 199 127 120 212 231 146 130 25 16 91 31 166 77 36 169 138 129 129 108 160 199 20 213 66 77 8 130 206 123 183 190 4 181 187 74 194 160 9 43 79 92 224 111 4 200 101 74)
#t
())
#(3
"short message"
#vu8(197 94 164 198 74 10 99 226 209 74 212 37 89 186 124 129 107 136 36 210 99 194 204 106 1 87 97 181 63 104 30 81 67 105 240 223 186 92 222 22 83 32 238 16 169 110 177 252)
#vu8(90 189)
#vu8(210 104 131 210 51 173 90 38 37 127 94 187 8 142 222 90 145 85 137 79 211 49 167 159 137 211 49 254 7 210 186 171 210 243 115 91 149 154 212 138 210 144 211 134 100 208 248 235)
#t
())
#(4
"short message"
#vu8(41 40 212 101 217 47 164 0 114 202 157 103 118 27 230 110 73 23 85 228 52 153 0 60 16 87 211 190 200 112 242 85 18 108 54 88 208 216 160 199 210 7 223 135 16 3 124 167)
#vu8(196 5 174)
#vu8(28 153 15 144 233 14 101 191 238 98 84 152 87 187 16 69 82 0 244 37 162 27 163 244 177 38 54 100 124 57 29 86 180 126 99 224 193 17 176 120 237 169 3 36 121 157 235 58)
#t
())
#(5
"short message"
#vu8(104 106 55 48 8 92 201 68 252 235 20 22 40 65 152 24 230 98 254 33 229 43 234 39 72 243 183 4 248 12 232 1 8 109 177 227 6 137 23 178 66 230 43 77 110 110 214 133)
#vu8(102 1 198 131)
#vu8(153 17 212 229 243 1 103 236 56 43 127 123 57 67 16 167 234 94 205 3 148 237 222 169 67 130 240 90 138 249 83 59 11 114 2 71 17 24 10 221 96 125 41 14 95 70 2 220)
#t
())
#(6
"short message"
#vu8(242 45 134 123 151 43 35 46 63 68 74 72 141 215 148 209 112 128 124 112 235 101 15 149 43 97 119 89 111 118 197 88 165 216 96 214 247 190 11 233 230 102 249 189 83 115 47 141)
#vu8(21 178 147 119 224)
#vu8(174 196 111 176 58 40 212 250 85 165 73 41 48 209 203 55 49 197 232 11 176 201 31 124 30 148 134 128 170 102 106 16 240 188 245 56 146 121 97 239 48 250 36 103 62 159 250 248)
#t
())
#(7
"short message"
#vu8(58 201 171 213 61 189 15 187 137 31 155 94 22 221 69 223 153 78 82 131 82 120 50 112 113 56 252 39 18 186 217 227 71 97 231 217 198 208 93 70 242 200 50 61 219 14 254 153)
#vu8(90 52 21 91 17 21)
#vu8(255 83 145 48 30 16 93 15 24 184 37 106 168 229 192 63 76 87 243 65 224 246 17 73 203 98 192 210 54 104 38 184 97 139 75 162 137 77 226 53 183 35 117 92 28 188 122 69)
#t
())
#(8
"short message"
#vu8(174 58 169 79 221 53 226 190 244 4 114 210 155 218 211 164 9 132 14 164 65 195 215 2 92 215 47 62 129 255 86 218 96 33 97 216 75 35 209 99 64 97 56 91 227 12 91 189)
#vu8(138 20 13 120 30 113 145)
#vu8(185 145 129 185 110 109 173 205 191 32 60 57 42 59 250 209 1 48 85 88 55 238 100 122 50 12 162 183 35 116 122 95 64 188 72 3 234 221 144 145 65 128 65 233 143 241 6 88)
#t
())
#(9
"short message"
#vu8(68 183 152 82 202 188 243 254 147 210 255 245 93 42 254 106 70 195 91 122 209 149 76 224 136 141 231 180 89 185 130 114 47 175 139 73 14 107 0 231 188 171 189 54 241 132 67 245)
#vu8(147 152 205 37 29 234 254 139)
#vu8(137 104 213 224 243 209 112 192 209 151 124 125 246 122 62 192 187 99 123 25 238 115 21 15 132 211 92 141 169 221 2 253 191 86 60 87 55 131 78 223 121 7 101 186 43 71 142 240)
#t
())
#(10
"short message"
#vu8(3 254 210 245 121 163 235 222 206 207 177 132 235 226 152 72 118 17 51 153 196 165 147 217 139 95 94 96 109 211 48 251 57 76 40 93 158 173 96 23 72 37 155 73 51 53 248 229)
#vu8(24 216 121 177 246 61 243 172 122)
#vu8(199 57 172 122 1 135 119 76 182 204 248 16 105 247 94 205 181 224 147 49 40 22 65 128 158 0 51 77 187 197 69 82 192 29 176 126 175 173 252 194 60 219 108 163 36 226 197 219)
#t
())
#(11
"short message"
#vu8(244 239 72 191 64 86 211 157 187 164 21 64 24 198 59 223 41 66 11 153 145 234 89 79 240 94 60 193 203 2 225 118 213 75 160 56 166 183 134 146 81 157 103 136 228 149 187 171)
#vu8(10 93 225 60 217 186 49 201 68 134)
#vu8(207 33 197 199 181 106 224 255 95 149 235 194 199 198 185 249 84 32 178 73 18 31 154 151 217 1 251 108 100 150 158 201 190 130 254 46 51 108 102 253 218 60 227 6 253 66 42 110)
#t
())
#(12
"short message"
#vu8(252 119 31 124 205 73 154 30 214 51 216 104 118 215 7 181 241 213 60 107 205 242 26 162 144 119 102 171 60 167 250 108 221 106 155 152 27 26 132 165 40 232 20 68 48 63 16 87)
#vu8(3 186 17 243 243 23 59 133 34 107 37)
#vu8(115 148 37 86 237 15 41 76 86 116 68 72 0 201 62 186 66 0 96 131 188 203 215 187 212 134 165 255 213 154 43 224 216 103 67 205 205 191 111 118 63 247 99 220 161 147 203 12)
#t
())
#(13
"short message"
#vu8(179 153 157 230 128 177 21 80 225 134 49 200 25 159 126 184 167 78 33 189 201 217 127 120 18 69 194 175 25 248 84 151 217 243 139 37 10 86 78 72 101 15 208 11 227 101 241 85)
#vu8(156 101 140 181 230 1 216 93 195 133 120 99)
#vu8(201 76 8 0 129 69 34 209 252 4 45 5 196 191 30 240 189 115 198 27 200 71 191 220 243 250 72 134 117 19 129 94 206 69 147 175 93 208 59 37 110 19 47 95 121 137 69 101)
#t
())
#(14
"short message"
#vu8(136 0 90 98 134 78 166 153 225 80 150 22 236 72 3 62 132 210 226 161 59 139 194 232 167 111 46 204 189 178 7 169 90 200 226 245 181 167 3 178 42 11 87 30 138 204 89 154)
#vu8(90 148 248 69 65 167 148 191 35 215 45 177 109)
#vu8(16 163 131 157 240 134 84 110 191 231 213 219 162 141 21 234 76 39 195 244 241 238 64 45 30 15 99 68 57 6 197 227 74 150 59 86 144 9 52 132 128 44 34 141 210 108 27 214)
#t
())
#(15
"short message"
#vu8(177 203 218 44 154 18 249 35 21 165 16 26 239 49 30 153 214 219 0 43 14 4 251 83 197 1 6 170 77 40 233 163 70 105 123 169 112 132 87 46 234 86 204 252 74 215 229 114)
#vu8(206 18 192 199 142 63 107 39 106 197 110 215 67 94)
#vu8(160 84 58 55 31 1 155 193 159 47 190 222 52 206 78 253 228 57 132 160 197 111 69 63 146 62 21 42 191 145 76 68 18 244 107 100 191 98 111 34 195 9 219 64 63 203 119 83)
#t
())
#(16
"short message"
#vu8(8 81 126 128 20 224 13 181 195 127 42 32 249 135 234 46 197 46 121 56 222 1 138 214 190 37 107 162 35 104 4 20 74 210 161 188 194 66 115 136 98 180 6 71 0 126 10 44)
#vu8(33 226 160 161 103 120 154 107 114 45 23 55 217 47 139)
#vu8(187 116 51 121 64 204 16 127 12 187 241 25 75 246 231 132 217 172 209 212 146 241 18 231 246 214 86 238 202 136 30 9 197 159 214 218 232 138 157 174 202 109 19 200 235 151 130 209)
#t
())
#(17
""
#vu8(80 61 116 120 167 115 182 148 214 229 82 201 112 60 200 188 86 253 73 250 252 154 23 202 184 176 51 45 202 141 73 51 111 167 233 236 43 203 86 37 63 229 187 80 78 62 127 127)
#vu8(217 110 111 237 137 58 221 253 146 55 200 28 79 78 52 27)
#vu8(134 81 222 84 140 81 16 254 1 18 210 108 126 10 47 36 79 132 174 255 107 175 82 103 207 211 175 219 84 75 176 165 193 178 158 155 120 162 233 73 158 44 79 98 192 241 110 74)
#t
())
#(18
""
#vu8(65 52 27 171 144 46 118 125 77 25 100 192 172 254 207 70 239 241 176 43 100 85 188 178 9 125 233 193 84 190 31 102 127 33 190 7 109 225 140 210 193 92 0 88 150 252 168 127)
#vu8(76 67 172 125 227 99 28 200 111 77 167 47 230 182 165 82 241)
#vu8(59 196 117 114 17 83 42 108 106 233 100 8 126 201 152 95 137 208 43 57 37 217 16 100 205 9 230 243 158 91 234 106 228 81 161 244 167 35 171 242 201 148 214 63 181 184 7 114)
#t
())
#(19
""
#vu8(194 248 59 225 172 206 123 137 165 249 233 234 126 76 79 139 15 67 25 152 111 190 71 159 163 180 163 194 152 22 131 98 57 59 86 234 3 181 206 247 127 72 229 167 42 190 109 8)
#vu8(141 208 205 120 108 216 0 255 235 236 9 135 40 146 61 105 36 157 50 35 196 197 149 203)
#vu8(85 47 53 249 67 28 183 247 111 206 48 199 93 26 109 34 64 56 89 226 87 246 70 254 82 178 220 156 124 252 127 80 103 15 191 123 187 98 249 85 21 246 170 224 177 212 87 146)
#t
())
#(20
""
#vu8(107 210 174 233 221 152 214 182 96 159 206 130 24 27 16 194 11 186 134 29 166 138 21 144 88 111 171 8 197 233 233 15 245 132 4 125 180 118 8 40 100 63 234 56 8 113 96 228)
#vu8(51 35 106 157 230 3 193 228 245 225 17 100 34 71 64 98 125 16 246 0 142 183 62 194 100 35 33 191 11 130 213 121)
#vu8(212 81 116 223 50 65 221 177 160 137 1 120 250 74 165 69 35 105 155 35 190 97 169 97 102 51 99 26 78 245 227 155 210 216 143 66 189 80 22 170 139 193 20 128 86 216 82 124)
#t
())
#(21
"long message"
#vu8(47 152 186 44 234 173 197 186 8 136 10 53 203 0 128 220 135 10 87 52 167 130 235 227 28 75 171 16 15 248 120 109 204 59 230 222 24 72 46 165 209 179 191 20 174 171 180 112)
#vu8(45 116 166 109 172 241 46 219 133 239 48 115 254 175 209 34 136 156 182 52 173 208 15 240 57 93 34 75 79 248 181 213 214 124 166 65 155 104 38 171 255 219 65 186 180 39 213)
#vu8(0 221 53 241 14 127 199 241 100 109 37 10 189 244 55 137 63 82 56 157 247 97 253 242 120 64 170 19 116 219 120 106 34 54 91 229 163 62 9 173 170 255 238 25 81 81 115 213)
#t
())
#(22
"long message"
#vu8(94 95 96 228 13 132 199 202 38 8 175 59 204 110 4 171 197 248 183 202 115 10 120 175 127 111 3 46 90 21 1 105 91 217 31 59 235 178 133 144 175 29 185 13 131 144 202 88)
#vu8(46 254 106 20 234 141 103 158 98 219 206 223 53 230 24 82 39 140 131 197 74 219 225 241 199 44 177 167 70 177 28 255 140 180 252 58 44 58 205 68 37 93 81 192 32 202 109 71)
#vu8(240 60 115 49 232 199 8 162 87 231 85 7 24 217 100 192 247 225 172 123 245 46 157 182 171 111 5 86 179 165 117 253 166 241 103 134 8 246 230 60 163 242 235 141 55 27 7 222)
#t
())
#(23
"long message"
#vu8(188 49 11 195 145 61 159 229 158 32 18 160 88 201 225 80 83 77 37 97 30 54 32 108 240 124 202 239 225 83 243 142 176 234 173 153 65 182 136 61 251 206 1 188 181 25 96 65)
#vu8(159 7 71 215 57 107 251 224 28 243 232 83 97 229 0 133 224 169 26 116 144 185 148 3 29 129 133 27 114 80 101 153 63 69 218 208 214 13 121 74 237 236 123 165 217 214 219 190 228)
#vu8(170 254 61 85 63 3 63 77 231 58 172 76 103 102 88 61 91 42 250 101 208 55 88 97 80 102 48 139 197 174 38 237 147 242 141 254 109 237 84 16 78 173 252 212 60 22 178 132)
#t
())
#(24
"long message"
#vu8(220 119 12 100 208 13 21 110 67 203 116 151 14 58 26 42 210 139 109 158 198 178 182 229 172 62 53 106 153 248 121 203 98 15 0 52 12 4 76 193 243 27 220 207 160 219 209 119)
#vu8(64 63 216 227 239 81 182 83 157 182 88 168 148 190 133 181 143 188 132 136 30 97 197 224 203 19 174 66 26 9 211 29 120 6 3 37 109 57 14 221 5 109 25 8 86 190 0 173 32 167 4 143 12 103 65 111 232 224 40 132 8 97 85 244 38 50 98 232 193 39 85 4 212 249 31 39 81 211 195 220 205 68 9 255 43 69 228 29 233 63 123 16 77 88 246 225 91 172 182 42 206 151 0 97 94 204 27 48 160 204 27 53)
#vu8(52 112 108 211 89 120 96 115 59 94 101 31 153 211 80 227 8 245 150 221 181 43 1 225 133 187 56 161 129 59 189 145 230 228 198 76 79 166 131 212 128 60 135 143 197 180 32 82)
#t
())
#(25
"long message"
#vu8(204 169 41 156 123 220 38 164 181 149 5 92 153 202 35 190 200 237 17 181 222 237 169 31 131 226 54 94 115 64 57 92 238 244 232 110 92 217 31 37 147 188 254 196 152 166 127 201)
#vu8(160 91 64 184 211 167 188 123 117 176 233 115 9 201 189 28 157 135 85 193 255 82 69 239 99 8 166 165 202 211 236 251 203 99 100 180 28 166 243 210 75 190 232 68 214 32 77 16 38 171 227 69 175 123 222 193 20 163 115 177 9 170 87 36 183 56 213 10 183 168 38 194 104 232 115 112 159 139 53 19 90 135 0 69 213 251 157 170 130 211 194 69 181 51 137 23 53 78 114 179 5 140 154 75 128 113 23 70 82 23 215 209 79 54 248 168 212 233 123 195 185 53 135 201 38 65 231)
#vu8(83 125 249 196 72 235 229 173 66 225 86 135 169 254 159 215 108 59 140 216 84 72 16 144 17 140 99 229 230 226 188 193 161 248 220 109 120 36 238 171 72 35 195 171 77 229 94 221)
#t
())
#(26
"long message"
#vu8(199 40 230 94 8 217 41 111 227 205 242 222 219 73 200 26 48 182 3 166 37 105 238 206 78 229 208 30 154 50 174 59 203 78 193 99 228 85 228 82 88 36 84 206 239 239 192 70)
#vu8(230 198 186 200 124 23 226 105 164 113 67 76 169 86 132 1 69 29 120 194 68 74 157 110 220 218 60 218 181 28 91 237 28 25 234 243 67 38 88 15 216 90 229 35 106 213 27 197 218 227 134 179 97 1 245 70 149 197 149 238 237 205 208 24 42 74 17 127 128 147 244 244 129 46 3 219 57 110 222 152 73 209 147 231 114 32 129 174 236 75 230 196 202 246 201 121 211 110 173 86 99 74 33 190 33 22 46 162 50 222 201 207 253 189 36 116 36 88 120 220 163 105 232 20 253 2 131 3)
#vu8(13 91 207 241 182 80 194 172 112 38 46 30 246 183 77 204 220 91 49 236 252 50 226 227 168 98 221 97 232 230 54 67 14 98 59 253 98 10 142 42 170 152 193 56 137 149 96 218)
#t
())
#(27
"long message"
#vu8(144 196 33 93 195 242 55 67 80 71 254 253 216 99 141 51 154 63 198 111 202 6 197 6 62 172 189 160 2 171 51 94 98 22 5 246 114 243 218 159 100 31 174 17 10 252 62 123)
#vu8(30 188 34 195 3 27 100 97 94 182 241 160 105 110 51 183 223 19 154 75 137 29 62 103 33 204 38 192 93 85 222 121 13 202 98 54 104 193 3 8 72 93 56 233 94 196 118 159 164 67 12 163 235 194 93 169 245 211 28 151 38 116 81 125 154 34 34 230 185 125 141 239 101 18 175 9 108 109 20 128 216 58 34 156 132 183 242 140 128 24 75 107 235 243 244 239 245 252 78 92 108 254 164 248 235 169 169 87 247 145 59 32 168 138 209 115 79 124 56 84 126 147 77 29 191 45 115 219 214 30 49 251 21 131 199 182 87 122 23 30 125 2 241 144 69 18 106 194 151 61 133 91 193 141 52 211 35 38 209 226 22 218 88 54 106 96 3 52 80 9 17 40 174 38 164 121 6 155 186 123 145 178 171 127 60 95 188 222 57 29 227 202 17 75 149 29 104 82 249 39 149 248 2 61 122 41 167 244 206 97 233 36 27 79 35 93 33 232 153 8 113 103 171 63 58 14 147 33 199 148 43 22 81 120 120 141 244 141 59 16 107 32 62 193 224 29 41 189 164 26 153 172 13 44 0)
#vu8(225 73 18 164 208 163 221 127 238 84 190 128 85 247 143 20 167 47 29 72 190 178 66 38 56 12 239 209 239 199 51 170 209 41 229 4 190 186 217 141 31 247 252 48 55 80 7 58)
#t
())
#(28
"Flipped bit 0 in tag"
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47)
#vu8()
#vu8(209 12 232 157 82 53 178 42 175 73 218 224 120 192 200 194 159 195 171 105 157 137 131 126 29 26 155 68 58 112 201 168 108 253 224 166 144 205 67 119 190 13 145 172 240 63 200 110)
#f
())
#(29
"Flipped bit 0 in tag"
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47)
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15)
#vu8(102 84 254 68 84 43 63 28 208 177 71 40 230 155 191 96 131 240 44 175 216 204 196 22 82 95 228 1 63 124 122 81 168 56 77 71 175 239 161 253 213 40 211 251 98 88 187 212)
#f
())
#(30
"Flipped bit 1 in tag"
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47)
#vu8()
#vu8(210 12 232 157 82 53 178 42 175 73 218 224 120 192 200 194 159 195 171 105 157 137 131 126 29 26 155 68 58 112 201 168 108 253 224 166 144 205 67 119 190 13 145 172 240 63 200 110)
#f
())
#(31
"Flipped bit 1 in tag"
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47)
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15)
#vu8(101 84 254 68 84 43 63 28 208 177 71 40 230 155 191 96 131 240 44 175 216 204 196 22 82 95 228 1 63 124 122 81 168 56 77 71 175 239 161 253 213 40 211 251 98 88 187 212)
#f
())
#(32
"Flipped bit 7 in tag"
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47)
#vu8()
#vu8(80 12 232 157 82 53 178 42 175 73 218 224 120 192 200 194 159 195 171 105 157 137 131 126 29 26 155 68 58 112 201 168 108 253 224 166 144 205 67 119 190 13 145 172 240 63 200 110)
#f
())
#(33
"Flipped bit 7 in tag"
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47)
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15)
#vu8(231 84 254 68 84 43 63 28 208 177 71 40 230 155 191 96 131 240 44 175 216 204 196 22 82 95 228 1 63 124 122 81 168 56 77 71 175 239 161 253 213 40 211 251 98 88 187 212)
#f
())
#(34
"Flipped bit 8 in tag"
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47)
#vu8()
#vu8(208 13 232 157 82 53 178 42 175 73 218 224 120 192 200 194 159 195 171 105 157 137 131 126 29 26 155 68 58 112 201 168 108 253 224 166 144 205 67 119 190 13 145 172 240 63 200 110)
#f
())
#(35
"Flipped bit 8 in tag"
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47)
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15)
#vu8(103 85 254 68 84 43 63 28 208 177 71 40 230 155 191 96 131 240 44 175 216 204 196 22 82 95 228 1 63 124 122 81 168 56 77 71 175 239 161 253 213 40 211 251 98 88 187 212)
#f
())
#(36
"Flipped bit 31 in tag"
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47)
#vu8()
#vu8(208 12 232 29 82 53 178 42 175 73 218 224 120 192 200 194 159 195 171 105 157 137 131 126 29 26 155 68 58 112 201 168 108 253 224 166 144 205 67 119 190 13 145 172 240 63 200 110)
#f
())
#(37
"Flipped bit 31 in tag"
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47)
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15)
#vu8(103 84 254 196 84 43 63 28 208 177 71 40 230 155 191 96 131 240 44 175 216 204 196 22 82 95 228 1 63 124 122 81 168 56 77 71 175 239 161 253 213 40 211 251 98 88 187 212)
#f
())
#(38
"Flipped bit 32 in tag"
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47)
#vu8()
#vu8(208 12 232 157 83 53 178 42 175 73 218 224 120 192 200 194 159 195 171 105 157 137 131 126 29 26 155 68 58 112 201 168 108 253 224 166 144 205 67 119 190 13 145 172 240 63 200 110)
#f
())
#(39
"Flipped bit 32 in tag"
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47)
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15)
#vu8(103 84 254 68 85 43 63 28 208 177 71 40 230 155 191 96 131 240 44 175 216 204 196 22 82 95 228 1 63 124 122 81 168 56 77 71 175 239 161 253 213 40 211 251 98 88 187 212)
#f
())
#(40
"Flipped bit 33 in tag"
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47)
#vu8()
#vu8(208 12 232 157 80 53 178 42 175 73 218 224 120 192 200 194 159 195 171 105 157 137 131 126 29 26 155 68 58 112 201 168 108 253 224 166 144 205 67 119 190 13 145 172 240 63 200 110)
#f
())
#(41
"Flipped bit 33 in tag"
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47)
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15)
#vu8(103 84 254 68 86 43 63 28 208 177 71 40 230 155 191 96 131 240 44 175 216 204 196 22 82 95 228 1 63 124 122 81 168 56 77 71 175 239 161 253 213 40 211 251 98 88 187 212)
#f
())
#(42
"Flipped bit 63 in tag"
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47)
#vu8()
#vu8(208 12 232 157 82 53 178 170 175 73 218 224 120 192 200 194 159 195 171 105 157 137 131 126 29 26 155 68 58 112 201 168 108 253 224 166 144 205 67 119 190 13 145 172 240 63 200 110)
#f
())
#(43
"Flipped bit 63 in tag"
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47)
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15)
#vu8(103 84 254 68 84 43 63 156 208 177 71 40 230 155 191 96 131 240 44 175 216 204 196 22 82 95 228 1 63 124 122 81 168 56 77 71 175 239 161 253 213 40 211 251 98 88 187 212)
#f
())
#(44
"Flipped bit 64 in tag"
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47)
#vu8()
#vu8(208 12 232 157 82 53 178 42 174 73 218 224 120 192 200 194 159 195 171 105 157 137 131 126 29 26 155 68 58 112 201 168 108 253 224 166 144 205 67 119 190 13 145 172 240 63 200 110)
#f
())
#(45
"Flipped bit 64 in tag"
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47)
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15)
#vu8(103 84 254 68 84 43 63 28 209 177 71 40 230 155 191 96 131 240 44 175 216 204 196 22 82 95 228 1 63 124 122 81 168 56 77 71 175 239 161 253 213 40 211 251 98 88 187 212)
#f
())
#(46
"Flipped bit 71 in tag"
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47)
#vu8()
#vu8(208 12 232 157 82 53 178 42 47 73 218 224 120 192 200 194 159 195 171 105 157 137 131 126 29 26 155 68 58 112 201 168 108 253 224 166 144 205 67 119 190 13 145 172 240 63 200 110)
#f
())
#(47
"Flipped bit 71 in tag"
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47)
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15)
#vu8(103 84 254 68 84 43 63 28 80 177 71 40 230 155 191 96 131 240 44 175 216 204 196 22 82 95 228 1 63 124 122 81 168 56 77 71 175 239 161 253 213 40 211 251 98 88 187 212)
#f
())
#(48
"Flipped bit 77 in tag"
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47)
#vu8()
#vu8(208 12 232 157 82 53 178 42 175 105 218 224 120 192 200 194 159 195 171 105 157 137 131 126 29 26 155 68 58 112 201 168 108 253 224 166 144 205 67 119 190 13 145 172 240 63 200 110)
#f
())
#(49
"Flipped bit 77 in tag"
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47)
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15)
#vu8(103 84 254 68 84 43 63 28 208 145 71 40 230 155 191 96 131 240 44 175 216 204 196 22 82 95 228 1 63 124 122 81 168 56 77 71 175 239 161 253 213 40 211 251 98 88 187 212)
#f
())
#(50
"Flipped bit 80 in tag"
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47)
#vu8()
#vu8(208 12 232 157 82 53 178 42 175 73 219 224 120 192 200 194 159 195 171 105 157 137 131 126 29 26 155 68 58 112 201 168 108 253 224 166 144 205 67 119 190 13 145 172 240 63 200 110)
#f
())
#(51
"Flipped bit 80 in tag"
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47)
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15)
#vu8(103 84 254 68 84 43 63 28 208 177 70 40 230 155 191 96 131 240 44 175 216 204 196 22 82 95 228 1 63 124 122 81 168 56 77 71 175 239 161 253 213 40 211 251 98 88 187 212)
#f
())
#(52
"Flipped bit 96 in tag"
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47)
#vu8()
#vu8(208 12 232 157 82 53 178 42 175 73 218 224 121 192 200 194 159 195 171 105 157 137 131 126 29 26 155 68 58 112 201 168 108 253 224 166 144 205 67 119 190 13 145 172 240 63 200 110)
#f
())
#(53
"Flipped bit 96 in tag"
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47)
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15)
#vu8(103 84 254 68 84 43 63 28 208 177 71 40 231 155 191 96 131 240 44 175 216 204 196 22 82 95 228 1 63 124 122 81 168 56 77 71 175 239 161 253 213 40 211 251 98 88 187 212)
#f
())
#(54
"Flipped bit 97 in tag"
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47)
#vu8()
#vu8(208 12 232 157 82 53 178 42 175 73 218 224 122 192 200 194 159 195 171 105 157 137 131 126 29 26 155 68 58 112 201 168 108 253 224 166 144 205 67 119 190 13 145 172 240 63 200 110)
#f
())
#(55
"Flipped bit 97 in tag"
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47)
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15)
#vu8(103 84 254 68 84 43 63 28 208 177 71 40 228 155 191 96 131 240 44 175 216 204 196 22 82 95 228 1 63 124 122 81 168 56 77 71 175 239 161 253 213 40 211 251 98 88 187 212)
#f
())
#(56
"Flipped bit 103 in tag"
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47)
#vu8()
#vu8(208 12 232 157 82 53 178 42 175 73 218 224 248 192 200 194 159 195 171 105 157 137 131 126 29 26 155 68 58 112 201 168 108 253 224 166 144 205 67 119 190 13 145 172 240 63 200 110)
#f
())
#(57
"Flipped bit 103 in tag"
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47)
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15)
#vu8(103 84 254 68 84 43 63 28 208 177 71 40 102 155 191 96 131 240 44 175 216 204 196 22 82 95 228 1 63 124 122 81 168 56 77 71 175 239 161 253 213 40 211 251 98 88 187 212)
#f
())
#(58
"Flipped bit 376 in tag"
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47)
#vu8()
#vu8(208 12 232 157 82 53 178 42 175 73 218 224 120 192 200 194 159 195 171 105 157 137 131 126 29 26 155 68 58 112 201 168 108 253 224 166 144 205 67 119 190 13 145 172 240 63 200 111)
#f
())
#(59
"Flipped bit 376 in tag"
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47)
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15)
#vu8(103 84 254 68 84 43 63 28 208 177 71 40 230 155 191 96 131 240 44 175 216 204 196 22 82 95 228 1 63 124 122 81 168 56 77 71 175 239 161 253 213 40 211 251 98 88 187 213)
#f
())
#(60
"Flipped bit 377 in tag"
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47)
#vu8()
#vu8(208 12 232 157 82 53 178 42 175 73 218 224 120 192 200 194 159 195 171 105 157 137 131 126 29 26 155 68 58 112 201 168 108 253 224 166 144 205 67 119 190 13 145 172 240 63 200 108)
#f
())
#(61
"Flipped bit 377 in tag"
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47)
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15)
#vu8(103 84 254 68 84 43 63 28 208 177 71 40 230 155 191 96 131 240 44 175 216 204 196 22 82 95 228 1 63 124 122 81 168 56 77 71 175 239 161 253 213 40 211 251 98 88 187 214)
#f
())
#(62
"Flipped bit 382 in tag"
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47)
#vu8()
#vu8(208 12 232 157 82 53 178 42 175 73 218 224 120 192 200 194 159 195 171 105 157 137 131 126 29 26 155 68 58 112 201 168 108 253 224 166 144 205 67 119 190 13 145 172 240 63 200 46)
#f
())
#(63
"Flipped bit 382 in tag"
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47)
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15)
#vu8(103 84 254 68 84 43 63 28 208 177 71 40 230 155 191 96 131 240 44 175 216 204 196 22 82 95 228 1 63 124 122 81 168 56 77 71 175 239 161 253 213 40 211 251 98 88 187 148)
#f
())
#(64
"Flipped bit 383 in tag"
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47)
#vu8()
#vu8(208 12 232 157 82 53 178 42 175 73 218 224 120 192 200 194 159 195 171 105 157 137 131 126 29 26 155 68 58 112 201 168 108 253 224 166 144 205 67 119 190 13 145 172 240 63 200 238)
#f
())
#(65
"Flipped bit 383 in tag"
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47)
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15)
#vu8(103 84 254 68 84 43 63 28 208 177 71 40 230 155 191 96 131 240 44 175 216 204 196 22 82 95 228 1 63 124 122 81 168 56 77 71 175 239 161 253 213 40 211 251 98 88 187 84)
#f
())
#(66
"Flipped bits 0 and 64 in tag"
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47)
#vu8()
#vu8(209 12 232 157 82 53 178 42 174 73 218 224 120 192 200 194 159 195 171 105 157 137 131 126 29 26 155 68 58 112 201 168 108 253 224 166 144 205 67 119 190 13 145 172 240 63 200 110)
#f
())
#(67
"Flipped bits 0 and 64 in tag"
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47)
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15)
#vu8(102 84 254 68 84 43 63 28 209 177 71 40 230 155 191 96 131 240 44 175 216 204 196 22 82 95 228 1 63 124 122 81 168 56 77 71 175 239 161 253 213 40 211 251 98 88 187 212)
#f
())
#(68
"Flipped bits 31 and 63 in tag"
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47)
#vu8()
#vu8(208 12 232 29 82 53 178 170 175 73 218 224 120 192 200 194 159 195 171 105 157 137 131 126 29 26 155 68 58 112 201 168 108 253 224 166 144 205 67 119 190 13 145 172 240 63 200 110)
#f
())
#(69
"Flipped bits 31 and 63 in tag"
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47)
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15)
#vu8(103 84 254 196 84 43 63 156 208 177 71 40 230 155 191 96 131 240 44 175 216 204 196 22 82 95 228 1 63 124 122 81 168 56 77 71 175 239 161 253 213 40 211 251 98 88 187 212)
#f
())
#(70
"Flipped bits 63 and 127 in tag"
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47)
#vu8()
#vu8(208 12 232 157 82 53 178 170 175 73 218 224 120 192 200 66 159 195 171 105 157 137 131 126 29 26 155 68 58 112 201 168 108 253 224 166 144 205 67 119 190 13 145 172 240 63 200 110)
#f
())
#(71
"Flipped bits 63 and 127 in tag"
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47)
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15)
#vu8(103 84 254 68 84 43 63 156 208 177 71 40 230 155 191 224 131 240 44 175 216 204 196 22 82 95 228 1 63 124 122 81 168 56 77 71 175 239 161 253 213 40 211 251 98 88 187 212)
#f
())
#(72
"all bits of tag flipped"
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47)
#vu8()
#vu8(47 243 23 98 173 202 77 213 80 182 37 31 135 63 55 61 96 60 84 150 98 118 124 129 226 229 100 187 197 143 54 87 147 2 31 89 111 50 188 136 65 242 110 83 15 192 55 145)
#f
())
#(73
"all bits of tag flipped"
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47)
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15)
#vu8(152 171 1 187 171 212 192 227 47 78 184 215 25 100 64 159 124 15 211 80 39 51 59 233 173 160 27 254 192 131 133 174 87 199 178 184 80 16 94 2 42 215 44 4 157 167 68 43)
#f
())
#(74
"Tag changed to all zero"
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47)
#vu8()
#vu8(0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0)
#f
())
#(75
"Tag changed to all zero"
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47)
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15)
#vu8(0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0)
#f
())
#(76
"tag changed to all 1"
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47)
#vu8()
#vu8(255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255)
#f
())
#(77
"tag changed to all 1"
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47)
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15)
#vu8(255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255)
#f
())
#(78
"msbs changed in tag"
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47)
#vu8()
#vu8(80 140 104 29 210 181 50 170 47 201 90 96 248 64 72 66 31 67 43 233 29 9 3 254 157 154 27 196 186 240 73 40 236 125 96 38 16 77 195 247 62 141 17 44 112 191 72 238)
#f
())
#(79
"msbs changed in tag"
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47)
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15)
#vu8(231 212 126 196 212 171 191 156 80 49 199 168 102 27 63 224 3 112 172 47 88 76 68 150 210 223 100 129 191 252 250 209 40 184 205 199 47 111 33 125 85 168 83 123 226 216 59 84)
#f
())
#(80
"lsbs changed in tag"
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47)
#vu8()
#vu8(209 13 233 156 83 52 179 43 174 72 219 225 121 193 201 195 158 194 170 104 156 136 130 127 28 27 154 69 59 113 200 169 109 252 225 167 145 204 66 118 191 12 144 173 241 62 201 111)
#f
())
#(81
"lsbs changed in tag"
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47)
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15)
#vu8(102 85 255 69 85 42 62 29 209 176 70 41 231 154 190 97 130 241 45 174 217 205 197 23 83 94 229 0 62 125 123 80 169 57 76 70 174 238 160 252 212 41 210 250 99 89 186 213)
#f
())))
(test-hmac
"hmac_sha3_384_test"
:algorithm
"HMACSHA3-384"
:key-size
384
:tag-size
192
:tests
'(#(82
"empty message"
#vu8(28 103 130 103 190 19 172 180 100 147 156 40 150 201 233 206 29 235 91 48 131 59 221 156 160 3 112 136 155 132 65 7 130 173 82 175 226 93 193 10 183 236 92 245 243 71 147 183)
#vu8()
#vu8(177 187 182 42 61 46 51 171 140 220 13 160 48 145 187 131 239 187 226 196 132 185 238 139)
#t
())
#(83
"short message"
#vu8(0 177 132 194 192 164 145 215 100 162 111 139 46 86 169 101 34 43 54 33 59 221 16 106 231 130 48 92 80 248 146 105 144 36 118 229 223 63 165 142 14 207 174 130 169 96 124 142)
#vu8(159)
#vu8(66 77 122 211 251 122 221 208 148 136 222 139 94 89 81 133 62 217 21 166 98 9 206 2)
#t
())
#(84
"short message"
#vu8(5 91 103 237 182 89 226 156 16 227 233 205 37 170 28 213 171 240 136 14 32 38 237 132 54 227 155 6 75 115 21 118 12 215 169 41 78 226 61 71 80 150 156 200 181 219 174 215)
#vu8(64 71)
#vu8(222 179 96 74 190 52 6 73 50 48 248 113 173 187 16 148 83 113 199 37 215 127 240 1)
#t
())
#(85
"short message"
#vu8(158 60 25 142 147 147 15 7 107 3 92 95 168 241 13 154 101 233 140 102 207 179 102 51 227 203 51 39 156 223 87 104 143 16 183 71 45 31 201 217 98 206 105 84 81 155 251 246)
#vu8(136 207 171)
#vu8(137 82 200 139 226 157 90 122 213 194 82 25 122 103 211 175 117 18 175 15 50 13 94 251)
#t
())
#(86
"short message"
#vu8(245 245 150 43 218 37 123 56 178 162 49 137 41 18 27 46 174 247 146 213 198 169 88 94 72 184 12 245 53 123 41 195 149 27 120 126 211 224 62 56 91 5 184 255 230 134 29 195)
#vu8(217 57 119 83)
#vu8(58 253 165 232 42 58 11 1 246 222 5 102 51 52 139 255 44 89 131 143 193 4 118 175)
#t
())
#(87
"short message"
#vu8(246 40 32 237 95 152 51 253 34 222 231 189 73 226 201 177 159 201 102 136 151 194 195 62 108 124 31 165 194 119 195 185 245 129 250 239 61 220 102 75 165 55 151 93 138 250 167 7)
#vu8(155 108 199 202 164)
#vu8(14 189 197 98 211 181 223 19 241 55 10 10 85 95 48 229 215 123 146 167 28 136 88 132)
#t
())
#(88
"short message"
#vu8(242 34 161 218 191 50 42 255 132 99 172 238 100 68 147 147 49 33 43 227 225 157 49 244 183 63 220 201 126 41 37 54 94 163 60 152 82 130 128 92 131 220 216 251 66 160 226 20)
#vu8(200 90 215 135 43 118)
#vu8(79 200 180 79 37 216 122 50 246 224 219 183 217 133 20 130 52 77 74 245 191 215 120 69)
#t
())
#(89
"short message"
#vu8(86 232 15 56 153 233 69 49 10 157 155 239 61 50 9 31 41 193 87 221 70 178 212 57 173 137 214 62 20 178 194 67 144 247 77 180 217 5 246 189 3 247 92 50 233 18 37 254)
#vu8(128 186 37 241 194 118 80)
#vu8(241 104 109 124 10 128 138 228 238 44 77 137 18 179 246 229 190 161 65 222 123 128 181 134)
#t
())
#(90
"short message"
#vu8(108 182 38 26 86 162 27 44 60 19 69 60 21 131 100 170 250 120 245 129 114 169 174 62 235 50 138 195 136 8 181 198 140 17 17 151 163 3 236 54 132 124 154 49 90 197 235 91)
#vu8(121 67 13 229 29 104 207 52)
#vu8(124 249 59 64 12 197 43 81 111 18 228 34 112 242 89 30 44 185 182 249 128 22 254 44)
#t
())
#(91
"short message"
#vu8(68 202 30 203 73 4 112 168 76 126 19 225 241 198 157 162 31 72 195 59 111 5 15 72 247 242 68 240 253 168 179 200 85 144 78 208 97 46 45 175 165 16 92 189 127 100 73 235)
#vu8(135 11 152 28 138 253 159 174 27)
#vu8(181 30 254 34 132 156 172 105 130 31 153 89 6 240 2 197 59 251 113 234 219 144 46 26)
#t
())
#(92
"short message"
#vu8(170 202 104 136 44 250 114 80 152 138 36 123 150 207 179 35 45 101 103 55 143 143 167 231 170 172 161 195 134 225 174 21 229 73 87 210 43 255 241 229 10 231 242 27 238 161 151 165)
#vu8(166 243 27 130 46 194 77 161 177 233)
#vu8(117 92 99 15 0 56 230 27 13 246 53 168 105 144 160 239 206 99 190 93 250 68 140 104)
#t
())
#(93
"short message"
#vu8(27 50 249 182 55 137 52 165 2 221 116 216 183 74 70 6 213 178 201 168 88 127 171 28 250 144 215 80 7 115 77 43 139 223 230 52 129 82 67 82 110 188 15 51 192 77 13 5)
#vu8(85 54 124 101 124 121 38 16 239 220 192)
#vu8(235 22 178 151 64 170 65 206 147 36 214 162 155 239 232 72 16 156 139 225 137 152 59 43)
#t
())
#(94
"short message"
#vu8(9 217 27 47 162 46 104 181 51 93 71 130 53 170 78 21 116 53 201 172 254 215 114 33 154 223 161 233 221 114 243 62 26 33 131 160 32 58 16 79 128 230 67 205 242 158 90 255)
#vu8(179 30 37 73 87 219 107 27 112 160 108 226)
#vu8(171 43 102 126 31 138 62 95 237 196 218 98 171 133 196 34 40 14 253 210 85 0 84 145)
#t
())
#(95
"short message"
#vu8(211 17 168 10 200 1 227 99 155 145 133 96 138 244 168 94 65 34 226 155 92 35 240 82 52 195 13 146 213 154 209 60 184 3 144 229 250 14 164 165 72 83 34 139 53 102 137 245)
#vu8(230 180 67 219 160 218 179 93 67 202 93 108 230)
#vu8(236 62 157 44 32 141 87 57 216 80 154 214 232 142 168 101 56 61 159 3 76 63 128 165)
#t
())
#(96
"short message"
#vu8(6 41 126 108 70 85 139 155 15 195 108 39 43 74 231 230 93 213 54 204 29 19 172 191 168 49 250 85 116 179 79 153 224 154 223 183 242 3 33 242 3 7 95 210 110 210 226 157)
#vu8(48 155 149 229 241 236 38 247 7 134 231 77 128 109)
#vu8(142 179 125 236 170 248 55 110 169 75 130 118 122 244 196 190 120 203 96 125 153 48 162 143)
#t
())
#(97
"short message"
#vu8(232 182 58 37 205 133 173 79 57 227 192 233 88 78 172 185 77 106 227 63 152 77 162 89 170 83 61 77 40 174 179 65 207 63 254 73 192 41 228 175 106 72 5 247 96 243 95 44)
#vu8(210 37 194 119 149 248 9 69 75 178 197 29 33 243 172)
#vu8(113 148 198 153 40 235 195 56 214 195 74 181 170 85 6 210 252 6 151 67 215 102 12 123)
#t
())
#(98
""
#vu8(216 58 104 90 206 159 160 192 170 71 240 199 180 240 240 7 23 97 154 130 226 238 255 135 245 31 103 216 20 213 29 217 228 202 215 87 138 78 73 182 114 181 175 131 148 60 37 131)
#vu8(171 250 127 89 120 247 81 232 126 139 90 21 166 232 159 79)
#vu8(144 36 125 41 51 248 244 166 86 74 215 210 114 114 31 246 231 111 212 192 227 168 250 188)
#t
())
#(99
""
#vu8(91 234 244 6 166 98 126 170 252 173 182 222 164 226 123 164 253 135 159 211 229 191 216 126 163 200 213 224 172 251 189 162 198 191 0 107 234 245 163 3 18 230 144 114 76 71 68 163)
#vu8(188 87 212 103 169 162 175 100 173 94 20 183 188 8 152 220 99)
#vu8(124 250 174 25 70 228 98 236 224 78 194 253 232 254 241 166 233 229 165 165 22 87 225 78)
#t
())
#(100
""
#vu8(118 179 108 195 184 202 151 87 8 238 75 50 189 190 64 202 19 249 206 56 76 82 196 182 96 43 127 217 33 100 241 253 132 50 112 108 25 102 246 72 191 72 48 244 222 179 71 149)
#vu8(177 208 34 198 83 111 64 29 20 125 252 13 125 78 96 11 183 83 239 14 159 36 59 195)
#vu8(244 25 71 239 104 107 185 164 170 53 85 247 43 179 32 218 181 119 18 63 143 123 138 221)
#t
())
#(101
""
#vu8(32 86 154 22 244 83 221 60 52 223 152 21 82 134 177 202 138 57 46 161 100 201 25 49 31 13 249 211 157 151 96 98 244 249 146 185 109 239 56 81 136 110 98 149 242 97 80 100)
#vu8(84 2 196 230 131 209 164 49 134 138 213 40 175 191 65 40 176 177 12 239 148 125 6 59 52 211 118 211 68 183 147 178)
#vu8(174 17 249 184 56 15 251 57 106 238 90 100 61 205 141 28 201 21 68 171 24 32 26 236)
#t
())
#(102
"long message"
#vu8(158 246 165 95 138 155 107 158 241 248 41 97 103 49 144 120 22 55 6 174 91 96 137 124 45 214 227 64 182 126 213 213 119 251 84 197 84 124 213 242 72 240 110 112 130 255 184 38)
#vu8(106 13 22 39 105 65 216 240 78 172 46 199 35 250 83 185 214 177 109 167 227 14 127 45 154 216 152 231 203 183 27 211 221 35 78 226 40 54 255 74 198 1 27 111 18 189 58)
#vu8(87 213 138 180 203 200 213 62 108 24 206 85 106 250 45 155 207 34 193 244 72 110 69 156)
#t
())
#(103
"long message"
#vu8(251 86 187 188 109 117 27 116 77 140 27 87 204 39 161 210 194 244 227 142 52 145 245 68 72 207 207 185 56 155 127 99 253 13 65 146 9 104 239 97 37 16 98 95 38 55 210 141)
#vu8(207 23 145 81 126 245 166 28 13 182 90 102 139 238 38 253 188 151 93 121 155 38 35 204 15 62 69 96 232 12 112 20 250 156 2 213 104 201 140 134 56 94 0 15 230 119 107 183)
#vu8(196 170 25 244 36 54 69 250 87 49 224 55 104 209 109 85 34 90 222 35 238 127 55 27)
#t
())
#(104
"long message"
#vu8(208 65 226 78 89 179 77 122 24 18 138 66 216 167 165 45 203 165 215 158 94 213 133 181 92 124 158 73 70 229 204 175 126 89 223 15 61 169 140 125 5 35 228 204 143 157 125 164)
#vu8(82 121 97 143 27 65 83 73 16 57 90 120 222 217 104 174 227 67 16 133 181 153 196 245 94 181 255 138 46 135 155 196 66 145 217 35 222 49 0 157 177 185 247 248 16 149 175 179 234)
#vu8(238 63 41 70 170 4 230 11 127 75 127 87 238 21 222 197 167 252 248 209 20 235 193 77)
#t
())
#(105
"long message"
#vu8(225 206 72 132 253 116 160 225 151 198 138 206 59 41 181 82 49 58 248 228 81 233 141 154 184 208 232 248 238 116 20 62 143 203 100 70 33 124 15 49 35 164 38 184 171 111 98 203)
#vu8(113 21 75 154 101 123 144 95 136 75 165 20 13 94 123 146 67 254 195 224 63 187 219 179 96 200 25 73 99 174 67 23 123 85 2 205 32 245 89 238 239 248 99 141 2 140 80 25 38 235 199 237 221 19 44 206 162 158 173 122 208 201 90 48 185 211 37 149 44 175 176 234 94 201 217 214 253 235 99 149 13 93 105 200 187 190 167 2 174 209 212 68 218 40 104 7 255 214 179 108 180 153 2 203 167 171 249 189 161 181 119 198)
#vu8(146 138 193 79 24 216 123 142 30 238 117 155 79 254 227 193 122 41 19 201 20 216 151 77)
#t
())
#(106
"long message"
#vu8(138 36 44 34 209 181 76 226 22 202 3 200 132 85 190 177 40 33 26 159 53 175 35 67 112 154 247 197 244 58 104 20 81 234 83 163 109 226 229 4 142 180 74 81 104 28 97 32)
#vu8(171 94 238 107 131 134 145 25 240 13 211 204 102 221 231 92 181 112 5 53 169 14 155 62 50 179 20 52 194 151 239 83 249 70 89 215 217 177 19 35 22 27 46 102 198 185 201 173 32 227 19 48 63 129 232 142 71 23 134 200 233 54 1 31 120 18 30 57 99 11 46 8 4 252 151 206 92 179 163 79 38 148 148 57 254 83 10 220 234 110 151 199 139 4 46 8 23 37 59 247 93 213 67 53 88 65 34 245 237 210 16 52 27 109 147 245 138 161 180 222 42 173 118 254 206 196 79)
#vu8(32 204 244 242 34 209 57 212 171 118 35 179 163 140 145 84 52 105 39 0 86 255 140 128)
#t
())
#(107
"long message"
#vu8(49 28 75 238 124 242 87 183 128 19 90 46 74 100 19 230 138 129 111 93 132 98 81 93 203 28 114 73 75 99 53 88 26 155 96 162 23 185 255 28 117 231 118 129 72 248 223 70)
#vu8(99 204 195 132 156 76 50 60 182 206 146 104 119 150 144 72 184 73 238 74 241 142 113 238 245 47 233 242 116 168 103 133 96 249 165 212 117 16 195 201 140 138 8 237 76 1 160 30 10 54 99 239 12 198 195 205 202 98 118 217 30 153 176 212 20 38 52 152 251 100 173 116 184 32 171 82 179 122 222 175 39 203 68 84 94 219 143 9 9 73 146 131 123 141 58 11 170 42 16 26 73 89 46 184 137 220 139 172 228 199 30 62 252 185 212 20 155 214 112 206 47 119 77 115 193 47 42 69)
#vu8(218 230 90 140 55 197 69 143 1 119 112 253 191 194 2 50 145 224 33 189 223 118 37 196)
#t
())
#(108
"long message"
#vu8(251 121 40 103 200 146 143 5 3 170 36 71 124 235 244 46 11 1 131 70 227 97 151 112 185 232 245 9 121 69 226 226 117 173 6 240 193 33 82 54 106 192 110 39 140 148 9 10)
#vu8(10 99 230 217 29 122 106 24 219 173 135 159 184 226 58 227 81 146 3 145 235 64 254 173 108 186 132 103 104 162 198 121 127 243 71 180 48 19 39 176 154 252 65 247 184 3 175 107 97 246 217 184 24 224 221 204 2 83 109 5 67 219 241 168 127 44 94 2 15 100 89 9 67 68 183 37 150 213 72 67 92 49 53 68 233 44 37 77 84 167 10 29 111 110 221 47 130 84 10 30 162 232 33 37 176 113 95 160 248 144 187 43 228 186 0 101 210 186 1 68 133 70 130 174 208 65 193 3 89 150 100 142 46 214 113 183 37 59 165 103 255 185 153 217 31 216 231 255 206 92 109 196 121 7 50 173 174 68 52 53 164 84 254 108 42 124 103 8 217 213 178 235 146 146 214 251 229 224 38 214 83 50 179 140 121 37 239 249 190 184 144 99 202 182 63 190 203 42 192 225 187 97 165 177 229 17 249 73 196 58 52 238 38 241 21 110 151 121 61 169 123 207 91 92 103 100 19 132 242 104 19 27 41 120 87 215 25 238 182 202 250 61 190 155 141 13 165 92 152 101 111 32 229 179 155)
#vu8(146 123 253 186 78 225 29 143 21 132 145 118 72 64 253 100 255 100 1 64 21 67 181 57)
#t
())
#(109
"Flipped bit 0 in tag"
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47)
#vu8()
#vu8(209 12 232 157 82 53 178 42 175 73 218 224 120 192 200 194 159 195 171 105 157 137 131 126)
#f
())
#(110
"Flipped bit 0 in tag"
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47)
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15)
#vu8(102 84 254 68 84 43 63 28 208 177 71 40 230 155 191 96 131 240 44 175 216 204 196 22)
#f
())
#(111
"Flipped bit 1 in tag"
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47)
#vu8()
#vu8(210 12 232 157 82 53 178 42 175 73 218 224 120 192 200 194 159 195 171 105 157 137 131 126)
#f
())
#(112
"Flipped bit 1 in tag"
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47)
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15)
#vu8(101 84 254 68 84 43 63 28 208 177 71 40 230 155 191 96 131 240 44 175 216 204 196 22)
#f
())
#(113
"Flipped bit 7 in tag"
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47)
#vu8()
#vu8(80 12 232 157 82 53 178 42 175 73 218 224 120 192 200 194 159 195 171 105 157 137 131 126)
#f
())
#(114
"Flipped bit 7 in tag"
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47)
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15)
#vu8(231 84 254 68 84 43 63 28 208 177 71 40 230 155 191 96 131 240 44 175 216 204 196 22)
#f
())
#(115
"Flipped bit 8 in tag"
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47)
#vu8()
#vu8(208 13 232 157 82 53 178 42 175 73 218 224 120 192 200 194 159 195 171 105 157 137 131 126)
#f
())
#(116
"Flipped bit 8 in tag"
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47)
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15)
#vu8(103 85 254 68 84 43 63 28 208 177 71 40 230 155 191 96 131 240 44 175 216 204 196 22)
#f
())
#(117
"Flipped bit 31 in tag"
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47)
#vu8()
#vu8(208 12 232 29 82 53 178 42 175 73 218 224 120 192 200 194 159 195 171 105 157 137 131 126)
#f
())
#(118
"Flipped bit 31 in tag"
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47)
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15)
#vu8(103 84 254 196 84 43 63 28 208 177 71 40 230 155 191 96 131 240 44 175 216 204 196 22)
#f
())
#(119
"Flipped bit 32 in tag"
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47)
#vu8()
#vu8(208 12 232 157 83 53 178 42 175 73 218 224 120 192 200 194 159 195 171 105 157 137 131 126)
#f
())
#(120
"Flipped bit 32 in tag"
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47)
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15)
#vu8(103 84 254 68 85 43 63 28 208 177 71 40 230 155 191 96 131 240 44 175 216 204 196 22)
#f
())
#(121
"Flipped bit 33 in tag"
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47)
#vu8()
#vu8(208 12 232 157 80 53 178 42 175 73 218 224 120 192 200 194 159 195 171 105 157 137 131 126)
#f
())
#(122
"Flipped bit 33 in tag"
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47)
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15)
#vu8(103 84 254 68 86 43 63 28 208 177 71 40 230 155 191 96 131 240 44 175 216 204 196 22)
#f
())
#(123
"Flipped bit 63 in tag"
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47)
#vu8()
#vu8(208 12 232 157 82 53 178 170 175 73 218 224 120 192 200 194 159 195 171 105 157 137 131 126)
#f
())
#(124
"Flipped bit 63 in tag"
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47)
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15)
#vu8(103 84 254 68 84 43 63 156 208 177 71 40 230 155 191 96 131 240 44 175 216 204 196 22)
#f
())
#(125
"Flipped bit 64 in tag"
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47)
#vu8()
#vu8(208 12 232 157 82 53 178 42 174 73 218 224 120 192 200 194 159 195 171 105 157 137 131 126)
#f
())
#(126
"Flipped bit 64 in tag"
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47)
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15)
#vu8(103 84 254 68 84 43 63 28 209 177 71 40 230 155 191 96 131 240 44 175 216 204 196 22)
#f
())
#(127
"Flipped bit 71 in tag"
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47)
#vu8()
#vu8(208 12 232 157 82 53 178 42 47 73 218 224 120 192 200 194 159 195 171 105 157 137 131 126)
#f
())
#(128
"Flipped bit 71 in tag"
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47)
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15)
#vu8(103 84 254 68 84 43 63 28 80 177 71 40 230 155 191 96 131 240 44 175 216 204 196 22)
#f
())
#(129
"Flipped bit 77 in tag"
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47)
#vu8()
#vu8(208 12 232 157 82 53 178 42 175 105 218 224 120 192 200 194 159 195 171 105 157 137 131 126)
#f
())
#(130
"Flipped bit 77 in tag"
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47)
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15)
#vu8(103 84 254 68 84 43 63 28 208 145 71 40 230 155 191 96 131 240 44 175 216 204 196 22)
#f
())
#(131
"Flipped bit 80 in tag"
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47)
#vu8()
#vu8(208 12 232 157 82 53 178 42 175 73 219 224 120 192 200 194 159 195 171 105 157 137 131 126)
#f
())
#(132
"Flipped bit 80 in tag"
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47)
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15)
#vu8(103 84 254 68 84 43 63 28 208 177 70 40 230 155 191 96 131 240 44 175 216 204 196 22)
#f
())
#(133
"Flipped bit 96 in tag"
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47)
#vu8()
#vu8(208 12 232 157 82 53 178 42 175 73 218 224 121 192 200 194 159 195 171 105 157 137 131 126)
#f
())
#(134
"Flipped bit 96 in tag"
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47)
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15)
#vu8(103 84 254 68 84 43 63 28 208 177 71 40 231 155 191 96 131 240 44 175 216 204 196 22)
#f
())
#(135
"Flipped bit 97 in tag"
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47)
#vu8()
#vu8(208 12 232 157 82 53 178 42 175 73 218 224 122 192 200 194 159 195 171 105 157 137 131 126)
#f
())
#(136
"Flipped bit 97 in tag"
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47)
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15)
#vu8(103 84 254 68 84 43 63 28 208 177 71 40 228 155 191 96 131 240 44 175 216 204 196 22)
#f
())
#(137
"Flipped bit 103 in tag"
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47)
#vu8()
#vu8(208 12 232 157 82 53 178 42 175 73 218 224 248 192 200 194 159 195 171 105 157 137 131 126)
#f
())
#(138
"Flipped bit 103 in tag"
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47)
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15)
#vu8(103 84 254 68 84 43 63 28 208 177 71 40 102 155 191 96 131 240 44 175 216 204 196 22)
#f
())
#(139
"Flipped bit 184 in tag"
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47)
#vu8()
#vu8(208 12 232 157 82 53 178 42 175 73 218 224 120 192 200 194 159 195 171 105 157 137 131 127)
#f
())
#(140
"Flipped bit 184 in tag"
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47)
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15)
#vu8(103 84 254 68 84 43 63 28 208 177 71 40 230 155 191 96 131 240 44 175 216 204 196 23)
#f
())
#(141
"Flipped bit 185 in tag"
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47)
#vu8()
#vu8(208 12 232 157 82 53 178 42 175 73 218 224 120 192 200 194 159 195 171 105 157 137 131 124)
#f
())
#(142
"Flipped bit 185 in tag"
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47)
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15)
#vu8(103 84 254 68 84 43 63 28 208 177 71 40 230 155 191 96 131 240 44 175 216 204 196 20)
#f
())
#(143
"Flipped bit 190 in tag"
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47)
#vu8()
#vu8(208 12 232 157 82 53 178 42 175 73 218 224 120 192 200 194 159 195 171 105 157 137 131 62)
#f
())
#(144
"Flipped bit 190 in tag"
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47)
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15)
#vu8(103 84 254 68 84 43 63 28 208 177 71 40 230 155 191 96 131 240 44 175 216 204 196 86)
#f
())
#(145
"Flipped bit 191 in tag"
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47)
#vu8()
#vu8(208 12 232 157 82 53 178 42 175 73 218 224 120 192 200 194 159 195 171 105 157 137 131 254)
#f
())
#(146
"Flipped bit 191 in tag"
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47)
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15)
#vu8(103 84 254 68 84 43 63 28 208 177 71 40 230 155 191 96 131 240 44 175 216 204 196 150)
#f
())
#(147
"Flipped bits 0 and 64 in tag"
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47)
#vu8()
#vu8(209 12 232 157 82 53 178 42 174 73 218 224 120 192 200 194 159 195 171 105 157 137 131 126)
#f
())
#(148
"Flipped bits 0 and 64 in tag"
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47)
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15)
#vu8(102 84 254 68 84 43 63 28 209 177 71 40 230 155 191 96 131 240 44 175 216 204 196 22)
#f
())
#(149
"Flipped bits 31 and 63 in tag"
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47)
#vu8()
#vu8(208 12 232 29 82 53 178 170 175 73 218 224 120 192 200 194 159 195 171 105 157 137 131 126)
#f
())
#(150
"Flipped bits 31 and 63 in tag"
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47)
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15)
#vu8(103 84 254 196 84 43 63 156 208 177 71 40 230 155 191 96 131 240 44 175 216 204 196 22)
#f
())
#(151
"Flipped bits 63 and 127 in tag"
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47)
#vu8()
#vu8(208 12 232 157 82 53 178 170 175 73 218 224 120 192 200 66 159 195 171 105 157 137 131 126)
#f
())
#(152
"Flipped bits 63 and 127 in tag"
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47)
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15)
#vu8(103 84 254 68 84 43 63 156 208 177 71 40 230 155 191 224 131 240 44 175 216 204 196 22)
#f
())
#(153
"all bits of tag flipped"
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47)
#vu8()
#vu8(47 243 23 98 173 202 77 213 80 182 37 31 135 63 55 61 96 60 84 150 98 118 124 129)
#f
())
#(154
"all bits of tag flipped"
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47)
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15)
#vu8(152 171 1 187 171 212 192 227 47 78 184 215 25 100 64 159 124 15 211 80 39 51 59 233)
#f
())
#(155
"Tag changed to all zero"
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47)
#vu8()
#vu8(0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0)
#f
())
#(156
"Tag changed to all zero"
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47)
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15)
#vu8(0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0)
#f
())
#(157
"tag changed to all 1"
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47)
#vu8()
#vu8(255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255)
#f
())
#(158
"tag changed to all 1"
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47)
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15)
#vu8(255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255)
#f
())
#(159
"msbs changed in tag"
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47)
#vu8()
#vu8(80 140 104 29 210 181 50 170 47 201 90 96 248 64 72 66 31 67 43 233 29 9 3 254)
#f
())
#(160
"msbs changed in tag"
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47)
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15)
#vu8(231 212 126 196 212 171 191 156 80 49 199 168 102 27 63 224 3 112 172 47 88 76 68 150)
#f
())
#(161
"lsbs changed in tag"
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47)
#vu8()
#vu8(209 13 233 156 83 52 179 43 174 72 219 225 121 193 201 195 158 194 170 104 156 136 130 127)
#f
())
#(162
"lsbs changed in tag"
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47)
#vu8(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15)
#vu8(102 85 255 69 85 42 62 29 209 176 70 41 231 154 190 97 130 241 45 174 217 205 197 23)
#f
())))
(test-hmac
"hmac_sha3_384_test"
:algorithm
"HMACSHA3-384"
:key-size
192
:tag-size
384
:tests
'(#(163
"short key"
#vu8(8 71 110 157 73 73 156 95 82 227 127 128 236 230 245 164 84 89 148 136 6 180 130 65)
#vu8()
#vu8(252 81 67 112 157 96 246 101 94 0 154 207 234 112 22 56 99 80 89 54 34 229 144 86 12 71 232 70 163 250 232 246 237 195 228 51 27 131 5 131 76 174 36 157 186 158 38 159)
#t
())
#(164
"short key"
#vu8(33 59 68 216 225 250 186 255 131 126 243 14 226 84 47 154 184 46 215 4 17 218 231 143)
#vu8(238 11 244 133 133 193 134 255 153 27 77 134 7 129 124 156)
#vu8(185 37 90 31 152 192 111 246 4 135 96 161 178 45 99 192 232 167 71 156 93 69 54 100 166 0 40 81 45 100 225 61 121 247 227 158 140 181 57 157 133 159 28 139 228 118 17 114)
#t
())
#(165
"short key"
#vu8(180 175 169 218 170 140 148 77 115 163 136 31 50 33 228 43 52 239 78 53 241 132 232 120)
#vu8(207 96 127 106 14 180 78 203 202 129 182 209 253 181 149 206 227 95 35 83 218 2 232 46 40 225 51 185 222 205 143 187)
#vu8(181 102 65 169 214 81 75 17 140 112 243 10 97 192 142 126 122 101 10 226 207 185 215 61 99 60 60 196 2 160 185 255 117 201 34 74 148 97 8 97 50 34 37 186 49 217 243 173)
#t
())))
(test-hmac
"hmac_sha3_384_test"
:algorithm
"HMACSHA3-384"
:key-size
192
:tag-size
192
:tests
'(#(166
"short key"
#vu8(137 228 107 102 32 149 72 200 11 12 131 6 98 34 59 73 176 227 184 149 235 48 226 252)
#vu8()
#vu8(238 235 225 130 63 176 66 204 124 86 179 23 72 175 106 19 68 88 234 182 47 162 224 167)
#t
())
#(167
"short key"
#vu8(242 193 12 232 203 28 243 179 99 53 68 115 176 39 193 229 61 236 206 240 50 51 190 12)
#vu8(225 250 16 184 227 1 224 52 132 5 119 11 195 250 252 177)
#vu8(159 14 157 155 231 12 130 82 95 138 221 125 209 93 146 91 147 152 215 253 190 31 33 16)
#t
())
#(168
"short key"
#vu8(146 224 116 68 44 196 197 158 114 38 8 8 216 13 142 123 133 198 51 80 104 145 123 131)
#vu8(52 234 226 116 37 172 225 119 113 225 100 203 182 52 48 111 53 46 220 156 55 191 96 139 232 167 85 251 148 20 129 131)
#vu8(183 137 164 55 31 10 162 246 103 167 173 225 197 60 152 181 58 57 255 101 223 190 125 40)
#t
())))
(test-hmac
"hmac_sha3_384_test"
:algorithm
"HMACSHA3-384"
:key-size
520
:tag-size
384
:tests
'(#(169
"long key"
#vu8(219 111 153 86 195 244 202 110 65 241 247 241 70 41 212 76 121 224 53 62 219 243 227 16 230 133 139 188 69 167 205 87 119 138 144 83 186 34 161 65 191 88 191 212 52 173 8 100 140 112 65 162 36 185 122 13 23 224 237 249 79 212 11 65 10)
#vu8()
#vu8(37 83 160 68 27 218 137 254 120 168 254 249 211 52 249 34 36 195 253 71 183 235 143 24 189 107 163 231 194 221 195 131 171 146 100 245 14 237 125 9 245 228 10 16 229 207 82 113)
#t
())
#(170
"long key"
#vu8(240 52 4 189 179 224 143 83 13 76 58 95 22 93 35 96 18 164 196 92 208 99 227 228 72 61 160 136 236 10 253 178 78 150 57 252 202 187 145 249 138 73 220 41 114 226 152 20 38 87 62 207 230 156 0 196 58 45 153 163 16 124 239 58 112)
#vu8(115 237 159 162 172 244 157 108 152 191 199 214 197 173 156 86)
#vu8(195 69 167 47 244 220 90 98 200 254 249 18 197 31 125 149 129 74 59 89 41 29 243 243 141 162 20 164 100 35 175 137 164 15 142 55 4 116 3 201 73 151 104 179 23 26 85 194)
#t
())
#(171
"long key"
#vu8(238 121 158 37 237 177 177 132 82 229 237 23 75 198 178 24 90 103 84 65 125 108 192 93 115 109 43 169 239 200 54 126 75 5 186 10 46 229 37 206 234 183 79 152 4 168 71 145 48 195 40 214 113 227 64 112 207 23 74 0 58 29 251 89 148)
#vu8(172 62 125 167 229 120 185 180 220 36 36 3 4 70 199 246 174 188 196 113 68 90 158 14 110 101 9 156 174 236 91 47)
#vu8(149 109 51 221 201 107 172 220 180 224 5 140 22 26 232 18 215 157 129 217 240 245 151 226 3 170 109 174 13 170 178 122 217 60 81 113 245 100 82 95 185 25 38 223 207 186 160 157)
#t
())))
(test-hmac
"hmac_sha3_384_test"
:algorithm
"HMACSHA3-384"
:key-size
520
:tag-size
192
:tests
'(#(172
"long key"
#vu8(6 61 110 18 230 112 9 138 218 190 104 25 32 35 182 55 187 109 141 113 63 200 67 97 136 196 236 6 253 208 132 206 109 25 63 38 200 106 149 96 225 171 194 125 129 63 206 43 62 172 1 112 253 28 183 46 25 48 162 119 107 200 77 108 17)
#vu8()
#vu8(36 169 133 47 118 255 161 186 58 96 67 205 52 143 23 190 3 103 85 22 33 49 37 154)
#t
())
#(173
"long key"
#vu8(53 147 24 230 198 39 155 169 235 203 22 117 245 169 129 149 187 245 216 149 218 156 23 184 50 144 56 190 133 125 195 149 177 42 233 26 85 89 136 118 89 60 28 32 188 1 114 207 21 18 107 122 107 240 162 56 237 163 50 93 109 214 6 0 239)
#vu8(122 208 201 9 142 161 14 97 91 182 114 181 44 150 84 45)
#vu8(179 222 42 221 213 252 233 49 34 240 242 243 32 198 7 250 250 194 59 40 8 152 6 142)
#t
())
#(174
"long key"
#vu8(208 28 216 152 8 157 138 30 235 0 53 176 211 50 218 128 251 211 87 27 145 146 219 16 250 111 85 246 101 171 25 45 112 80 202 182 67 153 110 153 37 77 149 115 224 207 78 234 166 58 252 205 239 216 22 20 254 123 131 223 227 14 59 161 159)
#vu8(214 124 119 205 208 175 93 16 232 202 232 135 229 166 9 187 118 169 229 89 118 83 119 60 48 59 130 185 24 253 197 159)
#vu8(246 146 218 57 197 146 104 40 139 15 8 26 123 96 222 97 17 206 247 36 161 79 137 58)
#t
())))
| false |
3cb20cb4913a61f7d7d73f02f949d352f4a06260 | 354ae3428451a81e5a6e07d282edb9bd79ff0e3f | /info.ss | e9f35bdec63472f48822cde34906feb0b617b159 | []
| no_license | jeapostrophe/datalog | 385a478dc18a904a35cbe36ebc7b1a7ec0a26478 | a5d59e455b49d091f3c5348e4c1f0071a1bc0134 | refs/heads/master | 2021-01-18T13:42:51.827415 | 2013-10-31T01:32:07 | 2013-10-31T01:32:07 | null | 0 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 352 | ss | info.ss | #lang setup/infotab
(define name "Datalog")
(define blurb
(list "An implementation of Datalog as a Racket language."))
(define scribblings '(["scribblings/datalog.scrbl" (multi-page)]))
(define categories '(devtools))
(define primary-file "main.ss")
(define compile-omit-paths '("tests"))
(define release-notes (list))
(define repositories '("4.x"))
| false |
2bd5cc6082d9dc98efd367c870043ad8b3980733 | defeada37d39bca09ef76f66f38683754c0a6aa0 | /mscorlib/system/runtime/serialization/base-fixup-record.sls | 7733e8ba5a059e89f45aea32761408838483b020 | []
| 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,410 | sls | base-fixup-record.sls | (library (system runtime serialization base-fixup-record)
(export new
is?
base-fixup-record?
do-fixup?
next-same-container-get
next-same-container-set!
next-same-container-update!
next-same-required-get
next-same-required-set!
next-same-required-update!)
(import (ironscheme-clr-port))
(define-syntax new
(lambda (e)
(syntax-case e ()
((_ a ...)
#'(clr-new
System.Runtime.Serialization.BaseFixupRecord
a
...)))))
(define (is? a)
(clr-is System.Runtime.Serialization.BaseFixupRecord a))
(define (base-fixup-record? a)
(clr-is System.Runtime.Serialization.BaseFixupRecord a))
(define-method-port
do-fixup?
System.Runtime.Serialization.BaseFixupRecord
DoFixup
(System.Boolean
System.Runtime.Serialization.ObjectManager
System.Boolean))
(define-field-port
next-same-container-get
next-same-container-set!
next-same-container-update!
()
System.Runtime.Serialization.BaseFixupRecord
NextSameContainer
System.Runtime.Serialization.BaseFixupRecord)
(define-field-port
next-same-required-get
next-same-required-set!
next-same-required-update!
()
System.Runtime.Serialization.BaseFixupRecord
NextSameRequired
System.Runtime.Serialization.BaseFixupRecord))
| true |
81c2dbb456bef58b0a6d2eb9383f7939f5119813 | a8e69b82efa3125947b3af219d8f14335e52d057 | /infer-expert-ml-curried.scm | 8b1cdb43fce4cd560f475cee133496b17cc91995 | [
"MIT"
]
| permissive | ArunGant8/n-grams-for-synthesis | ad3f14bb082c1220fcea5cfb69029953a2501508 | b53b071e53445337d3fe20db0249363aeb9f3e51 | refs/heads/master | 2023-04-06T05:51:47.903781 | 2020-05-26T17:09:14 | 2020-05-26T17:09:14 | null | 0 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 651 | scm | infer-expert-ml-curried.scm | (define (!-o expr gamma type context)
; for debugging build-and-run-code
#|
(conde
((nil . ,nil-!-o)
(num . ,num-!-o)
(bool . ,bool-!-o)
(var . ,var-!-o)
(lambda . ,lambda-!-o)
(app . ,app-!-o)
(car . ,car-!-o)
(cdr . ,cdr-!-o)
(null? . ,null?-!-o)
(cons . ,cons-!-o)
(pair . ,pair-!-o)
(if . ,if-!-o)
(equal? . ,equal?-!-o)
(and . ,and-!-o)
(or . ,or-!-o)
(symbol? . ,symbol?-!-o)
(not . ,not-!-o)
(letrec . ,letrec-!-o)))
|#
(build-and-run-conde-ml-infer expr gamma type
expert-ordering-ml-infer
))
| false |
c46b814737535fbcfdaabe6f1a78f9bf7ac48749 | bef204d0a01f4f918333ce8f55a9e8c369c26811 | /tspl/c3-going-further.ss | 0d92b37bb2e290654a1ae15269ec225a380169c1 | [
"MIT"
]
| permissive | ZRiemann/ChezSchemeNote | 56afb20d9ba2dd5d5efb5bfe40410a5f7bb4e053 | 70b3dca5d084b5da8c7457033f1f0525fa6d41d0 | refs/heads/master | 2022-11-25T17:27:23.299427 | 2022-11-15T07:32:34 | 2022-11-15T07:32:34 | 118,701,405 | 5 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 3,863 | ss | c3-going-further.ss | ;;; Syntactic extensions are defined with define-syntax. define-syntax is similar to define,
;;; except that define-syntax associates a syntactic transformation procedure, or transformer,
;;; with a keyword (such as let), rather than associating a value with a variable.
(define-syntax zlet #;(The identifier appearing after define-syntax is the name, or keyword, of the syntactic extension being defined)
(syntax-rules () ;The syntax-rules form is an expression that evaluates to a transformer.
; auxiliary keywords is nearly always (). An example of an auxiliary keyword is the else of cond.
; a sequence of one or more rules, or pattern/template pairs.
[(_ ((x e) ...) b1 b2 ...) ; partten pattern/template pairs
; The pattern should always be a structured expression whose first element is an underscore ( _ ).
; x,e,b1,b2: Pattern variables match any substructure and are bound to that substructure within the corresponding template.
; The notation pat ... in the pattern allows for zero or more expressions matching the ellipsis prototype pat in the input.
((lambda (x ...) b1 b2 ...) e ...)])) ; template
(define-syntax zletx
(syntax-rules ()
[(_ ((x e) ...) b ...)
((lambda (x ...) b ...) e ...)]))
(zletx ([x 1])
(+ 3 x))
(define-syntax zand
(syntax-rules ()
[(_) #t]
[(_ e) e]
[(_ e1 e2 e3 ...)
(if e1 (zand e2 e3 ...) #f)]))
(let ([x 3])(and (not (= x 0)) (/ 1 x)))
; => 1/3
(define-syntax zand-incorrect ; incorrect!
(syntax-rules ()
[(_) #t]
[(_ e1 e2 ...)
(if e1 (zand-incorrect e2 ...) #f)]))
; => #t
;;; Section 3.3.Continuations
(call/cc
(lambda (k)
(* 5 4)))
(define lwp-list '())
(define lwp
(lambda (thunk)
(set! lwp-list (append lwp-list (list thunk)))))
(define start
(lambda ()
(let ([p (car lwp-list)])
(set! lwp-list (cdr lwp-list))
(p))))
(define pause
(lambda ()
(call/cc
(lambda (k)
(lwp (lambda () (k)))
(start)))))
(lwp (lambda () (let f () (pause) (display "h") (f))))
(lwp (lambda () (let f () (pause) (display "e") (f))))
(lwp (lambda () (let f () (pause) (display "y") (f))))
(lwp (lambda () (let f () (pause) (display "!") (f))))
(lwp (lambda () (let f () (pause) (newline) (f))))
(start)
(let ([x '(0 1)])
(call/cc
(lambda (k)
(if (null? x)
(quote ())
(k (cdr x))
)
)
)
k
)
(let ([k.n (call/cc (lambda (k) (cons k 0)))])
(let ([k (car k.n)] [n (cdr k.n)])
(write n)
(newline)
(if (= n 10)
'done
(k (cons k (+ n 1))))))
;;; Section 3.6. Libraries
(library (grades)
(export gpa->grade gpa)
(import (rnrs))
(define in-range?
(lambda (x n y)
(and (>= n x) (< n y))))
(define-syntax range-case
(syntax-rules (- else)
[(_ expr ((x - y) e1 e2 ...) ... [else ee1 ee2 ...])
(let ([tmp expr])
(cond
[(in-range? x tmp y) e1 e2 ...]
...
[else ee1 ee2 ...]))]
[(_ expr ((x - y) e1 e2 ...) ...)
(let ([tmp expr])
(cond
[(in-range? x tmp y) e1 e2 ...]
...))]))
(define letter->number
(lambda (x)
(case x
[(a) 4.0]
[(b) 3.0]
[(c) 2.0]
[(d) 1.0]
[(f) 0.0]
[else (assertion-violation 'grade "invalid letter grade" x)])))
(define gpa->grade
(lambda (x)
(range-case x
[(0.0 - 0.5) 'f]
[(0.5 - 1.5) 'd]
[(1.5 - 2.5) 'c]
[(2.5 - 3.5) 'b]
[else 'a])))
(define-syntax gpa
(syntax-rules ()
[(_ g1 g2 ...)
(let ([ls (map letter->number '(g1 g2 ...))])
(/ (apply + ls) (length ls)))])))
(import (grades))
(gpa c a c b b)
(gpa->grade 2.8)
| true |
f2fc9a67da765a379d3bb38151926115437b2aae | 958488bc7f3c2044206e0358e56d7690b6ae696c | /scheme/flatten.scm | f54642318395b3f06cd55b9ccf220e4a74097c71 | []
| no_license | possientis/Prog | a08eec1c1b121c2fd6c70a8ae89e2fbef952adb4 | d4b3debc37610a88e0dac3ac5914903604fd1d1f | refs/heads/master | 2023-08-17T09:15:17.723600 | 2023-08-11T12:32:59 | 2023-08-11T12:32:59 | 40,361,602 | 3 | 0 | null | 2023-03-27T05:53:58 | 2015-08-07T13:24:19 | Coq | UTF-8 | Scheme | false | false | 616 | scm | flatten.scm | (define (flatten l)
(if (not (list? l))
(display "flatten: argument is not a list error\n")
(cond ((null? l) '())
((list? (car l))
(append (flatten (car l)) (flatten (cdr l))))
(else (cons (car l) (flatten (cdr l)))))))
(define (sorted? l)
(cond ((null? l) #t)
((null? (cdr l)) #t)
(else
(and (<= (car l) (cadr l))
(sorted? (cdr l))))))
(define (flatten2 l)
(if (not (list? l))
(list l)
(apply append (map flatten2 l))))
(define (translate seq delta)
(let ((shift (lambda (x) (+ x delta))))
(map shift seq)))
| false |
29f78b8244414e5ff67604ec8145f294e0910969 | 9eca699bfafd7bcc3329d5cd85a06b61393a4f60 | /hygiene.scm | 164d296867511aafd5fe135cb9d39f2e0e9d72b5 | []
| no_license | kbob/kbscheme | 9ee2a29ba27e8adce10879ba4f5301b82ea0a767 | 55cf5e90fa4b54cab5f725c7a1da2c3793b77ba8 | refs/heads/master | 2021-01-22T09:47:46.741618 | 2010-01-10T00:35:39 | 2010-01-10T00:35:39 | 318,105 | 6 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 131 | scm | hygiene.scm | (define-syntax or2
(syntax-rules ()
((_ e1 e2)
(let ((t e1)) (if t t e2)))))
(define t 42)
(let ((if #f)) (or2 if t))
| true |
f2d39a3ca7abe090fa7f1f89d6c810a6aaef5f04 | 68c4bab1f5d5228078d603066b6c6cea87fdbc7a | /lab/frozen/just-born/rifle/src/mzscheme/rifle/nivel0/nivel0a.ss | b537f1edf4d95e6cac053b35f061d522280136ac | []
| no_license | felipelalli/micaroni | afab919dab304e21ba916aa6310dca102b1a04a5 | 741b628754b7c7085d3e68009a621242c2a1534e | refs/heads/master | 2023-08-03T06:25:15.405861 | 2023-07-25T14:44:56 | 2023-07-25T14:44:56 | 537,536 | 2 | 1 | null | null | null | null | UTF-8 | Scheme | false | false | 461 | ss | nivel0a.ss | (load "../../little-type/little-type.ss")
(define-syntax nivel0a?
(syntax-rules ()
((nivel0a? obj)
(little-object obj is? 'nivel0a))))
(define-syntax string->nivel0a
(syntax-rules ()
((string->nivel0a str)
(if (not (string? str))
#f (make-little-object 'nivel0a str)))))
(define-syntax nivel0a->string
(syntax-rules ()
((nivel0a->string obj)
(if (not (nivel0a? obj))
#f (content-of obj))))) | true |
5307ef3d12848f415604f9be7d65814c8eeb4ddd | d8bdd07d7fff442a028ca9edbb4d66660621442d | /scam/tests/20-scam/00-base/distinct.scm | afe3862524afdedede65320d0183cdaeb95c674c | []
| 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 | 276 | scm | distinct.scm | (import (only (scheme base) list)
(only (scam base) distinct?)
(test narc))
(narc-label "Distinct?")
(narc-expect
(#t (distinct? (list)))
(#t (distinct? (list 1)))
(#t (distinct? (list 1 5 #f 'cat)))
(#f (distinct? (list 1 5 #f 'cat 5))))
(narc-report)
| false |
5a0b24caf538d1dfa365fc2c0b086f947a7a53f3 | 000dbfe5d1df2f18e29a76ea7e2a9556cff5e866 | /sitelib/rfc/hmac.scm | 05ce58041989cb6c38a509eecd24ace50109a083 | [
"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 | 3,062 | scm | hmac.scm | ;;; -*- mode:scheme; coding:utf-8; -*-
;;;
;;; hmac.scm - Keyed-Hashing for Message Authentication code library.
;;;
;;; Copyright (c) 2010-2013 Takashi Kato <[email protected]>
;;;
;;; Redistribution and use in source and binary forms, with or without
;;; modification, are permitted provided that the following conditions
;;; are met:
;;;
;;; 1. Redistributions of source code must retain the above copyright
;;; notice, this list of conditions and the following disclaimer.
;;;
;;; 2. Redistributions in binary form must reproduce the above copyright
;;; notice, this list of conditions and the following disclaimer in the
;;; documentation and/or other materials provided with the distribution.
;;;
;;; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
;;; "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
;;; LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
;;; A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
;;; OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
;;; SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
;;; TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
;;; PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
;;; LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
;;; NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
;;; SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
;;;
;; I need a deprecation annotation for procedures...
#!nounbound
(library (rfc hmac)
(export make-hmac mac? generate-mac generate-mac!
mac-init! mac-process! mac-done!
;; for backward compatibility
(rename (*mac:hmac* HMAC))
<hmac>
verify-mac)
(import (rnrs)
(sagittarius)
(sagittarius crypto mac)
(sagittarius crypto digests)
;; damn...
(math hash)
(clos user)
(crypto mac))
(define (make-hmac key . opts) (apply make-mac *mac:hmac* key opts))
;; Below are deprecated
(define-class <hmac> (<mac>) ()) ;; dummy
(define-method initialize ((o <hmac>) initargs)
(call-next-method)
(let-keywords* initargs
((key (make-bytevector 0))
(hash *digest:sha-1*))
(let* ((digest (if (digest-descriptor? hash)
hash
(hash-algorithm->digest-descriptor hash)))
(mac (make-hmac key :digest digest)))
(slot-set! o 'hash digest)
(slot-set! o 'init (lambda (me) (mac-init! mac) me))
(slot-set! o 'process (lambda (me in start end)
(mac-process! mac in start (- end start))))
(slot-set! o 'done (lambda (me out start end)
(mac-done! mac out start (- end start))))
(slot-set! o 'block-size (digest-descriptor-block-size digest))
(slot-set! o 'hash-size (mac-mac-size mac))
(slot-set! o 'oid (mac-oid mac)))))
(define-method write-object ((o <hmac>) out)
(format out "#<hmac ~a>" (slot-ref o 'hash)))
(register-hash *mac:hmac* <hmac>)
)
| false |
3b92d5188515c74f6b35456adb48138eabb6a49e | a19495f48bfa93002aaad09c6967d7f77fc31ea8 | /src/kanren/kanren/mini/test-condw.scm | af4787fa00060ab56efc8aac8277edb36053a679 | [
"Zlib"
]
| permissive | alvatar/sphere-logic | 4d4496270f00a45ce7a8cb163b5f282f5473197c | ccfbfd00057dc03ff33a0fd4f9d758fae68ec21e | refs/heads/master | 2020-04-06T04:38:41.994107 | 2014-02-02T16:43:15 | 2014-02-02T16:43:15 | null | 0 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 5,520 | scm | test-condw.scm | ;(load "scheduling.scm")
(load "book-si.scm")
(define-syntax test-check
(syntax-rules ()
((_ title tested-expression expected-result)
(begin
(printf "Testing ~s~n" title)
(let* ((expected expected-result)
(produced tested-expression))
(or (equal? expected produced)
(error 'test-check
"Failed: ~a~%Expected: ~a~%Computed: ~a"
'tested-expression expected produced)))))))
'(define-syntax allw
(syntax-rules ()
((_ arg ...) (all arg ...))))
(define-syntax allw
(syntax-rules ()
((_ arg ...) (all succeed (begin (yield) arg) ...))))
'(define-syntax anyw
(syntax-rules ()
((_ arg ...) (conde (arg) ...))))
(define-syntax anyw
(syntax-rules ()
((_ arg ...) (conde (fail) ((begin (yield) arg)) ...))))
(define any*
(lambda (g)
(anyw
(allw g succeed)
(any* g))))
(define always (any* succeed))
(define never (any* fail))
;;------------------------------------------------------------------------
(define nullo
(lambda (x)
(== '() x)))
(define caro
(lambda (ls a)
(fresh (d)
(== (cons a d) ls))))
(define cdro
(lambda (ls d)
(fresh (a)
(== (cons a d) ls))))
(define conso
(lambda (a d ls)
(== (cons a d) ls)))
(define appendw
(lambda (l1 l2 out)
(anyw
(allw (nullo l1) (== l2 out))
(fresh (a d res)
(allw
(allw
(conso a d l1)
(conso a res out))
(appendw d l2 res))))))
(define appendo
(lambda (l1 l2 out)
(any
(all (nullo l1) (== l2 out))
(fresh (a d res)
(all
(all
(conso a d l1)
(conso a res out))
(appendo d l2 res))))))
(define swappendw
(lambda (l1 l2 out)
(anyw
(fresh (a d res)
(allw
(allw
(conso a d l1)
(conso a res out))
(swappendw d l2 res)))
(allw (nullo l1) (== l2 out)))))
(define foo
(lambda (x)
(allw
(== 5 x)
(foo x))))
(define bar
(lambda (x)
(allw
(bar x)
(== 5 x))))
(define baz
(lambda (x)
(anyw
(== 5 x)
(baz x))))
(define bat
(lambda (x)
(anyw
(bat x)
(== 5 x))))
(define quux
(lambda (x)
(allw
(== 5 x)
(allw
(quux x)
(quux x)))))
(define quuux
(lambda (x)
(allw
(quuux x)
(allw
(quuux x)
(== 5 x)))))
(define blat
(lambda (x)
(allw
(allw
(blat x)
(blat x))
(== 5 x))))
(define blaz
(lambda (x)
(anyw
(== 5 x)
(anyw
(blaz x)
(blaz x)))))
(define flaz
(lambda (x)
(anyw
(flaz x)
(anyw
(flaz x)
(== 5 x)))))
(define glaz
(lambda (x)
(anyw
(anyw
(glaz x)
(glaz x))
(== 5 x))))
;;; anyw/allw tests
(test-check "allw-2"
(run* (q) (allw fail always))
'())
(test-check "allw-3"
(run* (q) (allw (== q 3) (== q 3)))
'(3))
(test-check "allw-4"
(run* (q) (allw (== q 3) (== q 4)))
'())
(test-check "anyw-1"
(run 1 (q) (anyw never succeed))
'(_.0))
(test-check "anyw-2"
(run 1 (q) (anyw succeed never))
'(_.0))
(test-check "appendw-1"
(run* (q)
(appendw '(a b c) '(d e) q))
'((a b c d e)))
(test-check "swappendw-1"
(run* (q)
(swappendw '(a b c) '(d e) q))
'((a b c d e)))
(test-check "baz-1"
(run 1 (q)
(baz q))
'(5))
;!!!!
(test-check "bat-1"
(run 1 (q)
(bat q))
'(5))
(test-check "foo-1"
(run 1 (q)
(foo 6))
'())
(test-check "foo-2"
(run* (q)
(foo 6))
'())
;!!!
'(test-check "bar-1"
(run 1 (q)
(bar 6))
'())
;!!!
'(test-check "bar-2"
(run* (q)
(bar 6))
'())
(test-check "quux-1"
(run* (q)
(quux 6))
'())
;!!!
'(test-check "quuux-1"
(run* (q)
(quuux 6))
'())
;!!!
'(test-check "blat-1"
(run* (q)
(blat 6))
'())
(test-check "blaz-1"
(run 1 (q)
(blaz q))
'(5))
(test-check "blaz-2"
(run 5 (q)
(blaz q))
'(5 5 5 5 5))
;!!!
(test-check "glaz-1"
(run 1 (q)
(glaz q))
'(5))
;!!!
(test-check "glaz-2"
(run 5 (q)
(glaz q))
'(5 5 5 5 5))
;!!!
(test-check "flaz-1"
(run 1 (q)
(flaz q))
'(5))
;!!!
; it passes if the queue size is set to 10
(test-check "flaz-2"
(run 5 (q)
(flaz q))
'(5 5 5 5 5))
(test-check "appendw-1"
(run 5 (x)
(fresh (y z)
(appendw x y z)))
'(()
(_.0)
(_.0 _.1)
(_.0 _.1 _.2)
(_.0 _.1 _.2 _.3)))
(test-check "appendw-2"
(run 5 (q)
(fresh (x y z)
(appendw x y z)
(== `(,x ,y ,z) q)))
'((() _.0 _.0)
((_.0) _.1 (_.0 . _.1))
((_.0 _.1) _.2 (_.0 _.1 . _.2))
((_.0 _.1 _.2) _.3 (_.0 _.1 _.2 . _.3))
((_.0 _.1 _.2 _.3) _.4 (_.0 _.1 _.2 _.3 . _.4))))
(test-check "swappendw-1"
(run 5 (x)
(fresh (y z)
(swappendw x y z)))
'(()
(_.0)
(_.0 _.1)
(_.0 _.1 _.2)
(_.0 _.1 _.2 _.3)))
;;; Might give answers back in a different order.
(test-check "swappendw-2"
(run 5 (q)
(fresh (x y z)
(swappendw x y z)
(== `(,x ,y ,z) q)))
'((() _.0 _.0)
((_.0) _.1 (_.0 . _.1))
((_.0 _.1) _.2 (_.0 _.1 . _.2))
((_.0 _.1 _.2) _.3 (_.0 _.1 _.2 . _.3))
((_.0 _.1 _.2 _.3) _.4 (_.0 _.1 _.2 _.3 . _.4))))
| true |
a4ed84431bb44daed7017ebe9eef990681b286e9 | 1ed47579ca9136f3f2b25bda1610c834ab12a386 | /sec3/q3.73.scm | adc62eee824a70baba7f68fd9d3e8c3ce49d4f08 | []
| no_license | thash/sicp | 7e89cf020e2bf5ca50543d10fa89eb1440f700fb | 3fc7a87d06eccbe4dcd634406e3b400d9405e9c4 | refs/heads/master | 2021-05-28T16:29:26.617617 | 2014-09-15T21:19:23 | 2014-09-15T21:19:23 | 3,238,591 | 0 | 1 | null | null | null | null | UTF-8 | Scheme | false | false | 744 | scm | q3.73.scm | ;; 時系列での電流/電圧の値を表現するためにstreamを使ってモデル化できる.
;; 抵抗Rと容量Cが直列になったRC回路を考える。
;; 注入電流iに対する回路の電圧応答vの関係.
(load "./sec3.5.3")
(define (RC R C dt)
(lambda (i-stream v0) (add-streams
(integral (scale-stream i-stream (/ 1 C)) v0 dt)
(scale-stream i-stream R))))
;; usage
(define RC1 (RC 5 1 0.5))
; (define ones (cons-stream 1 ones))
; (define integers (cons-stream 1 (add-streams ones integers)))
;
; (display-stream-n (RC1 integers 1) 20)
; 6, 11.5, 17.5, 24.0, 31.0, 38.5, 46.5, 55.0, 64.0, 73.5, 83.5, 94.0, 105.0, 116.5, 128.5, 141.0, 154.0, 167.5, 181.5, done
| false |
4ea443d46cb241b3330f913e5344cc527bd5e0c0 | b4e3e2194fcb5722ff6b0022831348ef5d36daeb | /seasoned-1.scm | b69e00d66a79a3831b2c92615bcb6f8c4231ce15 | []
| no_license | nyaago/my-scheme-learning | 3adf46cf99c8579d05f483851e30732912b2faa2 | e1ccca44f577ba26a3a85532ba171ad7a4669425 | refs/heads/master | 2021-01-10T05:47:09.311306 | 2015-06-05T15:42:59 | 2015-06-05T15:42:59 | 36,940,789 | 0 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 1,910 | scm | seasoned-1.scm | (define is-first?
(lambda (a lat)
(cond
((null? lat) #f)
(else (eq? (car lat) a)))))
(define two-in-a-row?
(lambda (lat)
(cond
((null? lat) #f)
(else
(or (is-first? (car lat) (cdr lat))
(two-in-a-row? (cdr lat)))))))
(define two-in-a-row?
(lambda (lat)
(cond
((null? lat) #f)
(else
(is-first-b? (car lat) (cdr lat))))))
(define is-first-b?
(lambda (a lat)
(cond
((null? lat) #f)
(else
(or (eq? (car lat) a)
(two-in-a-row? lat))))))
(define two-in-a-row-b?
(lambda (preceding lat)
(cond
((null? lat) #f)
(else
(or (eq? preceding (car lat))
(two-in-a-row-b? (car lat) (cdr lat)))))))
(define two-in-a-row?
(lambda (lat)
(cond
((null? lat) #f)
(else
(two-in-a-row-b? (car lat) (cdr lat))))))
; 結果リストの1つ前の数と入力リストの現在の数を足したリストを結果とする。
(define sum-of-prefixes-b
(lambda (sum tup)
(cond
((null? tup) '())
(else
(cons (+ sum (car tup))
(sum-of-prefixes-b (+ sum (car tup))
(cdr tup) ))))))
(define sum-of-prefixes
(lambda (tup)
(cond
((null? tup) '())
(else
(sum-of-prefixes-b 0 tup)))))
; ;;;;
; 数のリストをとり、
; それぞれの数だけさかのぼった位置にある数のリストを返す
(define pick
(lambda (n lat)
(cond
((eq? n 1) (car lat))
(else
(pick (- n 1) (cdr lat))))))
(define scramble-b
(lambda (tup rev-pre)
(cond
((null? tup) '())
(else
(cons (pick (car tup) (cons (car tup) rev-pre))
(scramble-b (cdr tup)
(cons (car tup) rev-pre)))))))
(define scramble
(lambda (tup)
(cond
((null? tup) '())
(else
(scramble-b tup '()))))) | false |
ed60dbd179c9f18ab7374fb61fd345068ba6ca67 | e92f708d2ca39757df4cf7e7d0d8f4ebb8bab0eb | /scheme-transforms-master/scheme-transforms-master/transforms/redex.ss | 61a54d3926621d548b0f0781b82e7766ffb34b30 | []
| no_license | orthometa/304final | 503d67345820cb769abedbc49c7029e90874f5b9 | 114eb45edeaf1a876f4c0a55f6d24213a589f35e | refs/heads/master | 2020-03-18T12:57:52.580186 | 2018-05-24T18:23:08 | 2018-05-24T18:23:08 | 134,753,121 | 0 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 1,272 | ss | redex.ss | #!r6rs
;; eliminate unnecessary redexes introduced by cps transform
;; input language:
;; tag | top-level-begin-define | self-eval | primitive | lambda | if | (A B) | apply | let
;; output language:
;; tag | top-level-begin-define | self-eval | primitive | lambda | if | (A B) | apply | let
(library
(transforms redex)
(export redex-transform)
(import (rnrs)
(scheme-tools srfi-compat :1)
(only (scheme-tools) all)
(transforms common)
(transforms syntax)
(transforms utils))
(define n 0)
(define (redex-transform e)
(set! n 0)
(let ([e* (redex-convert e)])
(if (= n 0)
e*
(redex-transform e*))))
(define (redex-convert e)
(cond [(lambda? e) (redex-lambda e)]
[(list? e) (map redex-transform e)]
[else e]))
(define (variable-symbol? e)
(and (symbol? e)
(not (contains '(if let let* lambda define begin set! letrec) e))))
;; (lambda (a1 a2) (foo a1 a2))
;; =>
;; foo
(define (redex-lambda e)
(let ([args (lambda->args e)]
[body (lambda->body e)])
(if (and (list? body)
(all variable-symbol? body)
(equal? (rest body) args))
(first body)
`(lambda ,args ,(redex-convert body)))))
) | false |
3e28cfe9909cf7b246bc35f4d65243275560f6c4 | eef5f68873f7d5658c7c500846ce7752a6f45f69 | /spheres/markup/internal/sxpath-ext.scm | 1bdf8a721e1e1634669ab378da3be4be4f105c1b | [
"MIT"
]
| permissive | alvatar/spheres | c0601a157ddce270c06b7b58473b20b7417a08d9 | 568836f234a469ef70c69f4a2d9b56d41c3fc5bd | refs/heads/master | 2021-06-01T15:59:32.277602 | 2021-03-18T21:21:43 | 2021-03-18T21:21:43 | 25,094,121 | 13 | 3 | null | null | null | null | UTF-8 | Scheme | false | false | 25,351 | scm | sxpath-ext.scm | ;;!!! W3C compliant extensions to SXPathlib
;; $Id: sxpath-ext.scm,v 1.1.2.1 2010/07/19 15:29:27 mbenelli-cvs Exp $:
;;
;; This software is in Public Domain.
;; IT IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND.
;;
;; Please send bug reports and comments to:
;; [email protected] Kirill Lisovsky
;; [email protected] Dmitry Lizorkin
(cond-expand
(gambit (declare (fixnum)))
(else (void)))
;;-------------------------------------------------------------------------------
;;!! SXML counterparts to W3C XPath Core Functions Library
;;! The counterpart to XPath 'string' function (section 4.2 XPath Rec.)
;; Converts a given object to a string
;; NOTE:
;; 1. When converting a nodeset - a document order is not preserved
;; 2. number->string function returns the result in a form which is slightly
;; different from XPath Rec. specification
(define (sxml:string object)
(cond
((string? object) object)
((nodeset? object) (if (null? object)
""
(sxml:string-value (car object))))
((number? object)
(if (and (rational? object) (not (integer? object))) ; like 1/2
(number->string (exact->inexact object))
(number->string object)))
((boolean? object) (if object "true" "false"))
;; Unknown type -> empty string.
;; Option: write its value to string port?
(else "")))
;;! The counterpart to XPath 'boolean' function (section 4.3 XPath Rec.)
;; Converts its argument to a boolean
(define (sxml:boolean object)
(cond
((boolean? object) object)
((number? object) (not (= object 0)))
((string? object) (> (string-length object) 0))
((nodeset? object) (not (null? object)))
(else #f))) ; Not specified in XPath Rec.
;;! The counterpart to XPath 'number' function (section 4.4 XPath Rec.)
;; Converts its argument to a number
;; NOTE:
;; 1. The argument is not optional (yet?)
;; 2. string->number conversion is not IEEE 754 round-to-nearest
;; 3. NaN is represented as 0
(define (sxml:number obj)
(cond
((number? obj) obj)
((string? obj)
(let ((nmb (call-with-input-string obj read)))
(if (number? nmb)
nmb
0))) ; NaN
((boolean? obj) (if obj 1 0))
((nodeset? obj) (sxml:number (sxml:string obj)))
(else 0))) ; unknown datatype
;;! Returns a string value for a given node in accordance to
;; XPath Rec. 5.1 - 5.7
(define (sxml:string-value node)
(cond
((not (pair? node)) ; a text node or data node
(sxml:string node))
((null? (cdr node))
"")
(else
(apply string-append ; a list of arguments is always non-null
(map
(lambda (node)
(if (sxml:node? node) ; not annot-attr node or aux list node
(sxml:string-value node) ""))
(cdr node))))))
;;! Select SXML element by its unique IDs
;; XPath Rec. 4.1
;; object - a nodeset or a datatype which can be converted to a string by means
;; of a 'string' function
;; id-index = ( (id-value . element) (id-value . element) ... )
;; This index is used for selection of an element by its unique ID.
;; The result is a nodeset
(define (sxml:id id-index)
(lambda(object)
(if (nodeset? object)
(let loop ((str-lst (map sxml:string-value object))
(res '()))
(if (null? str-lst)
(reverse res)
(let ((node (sxml:lookup (car str-lst) id-index)))
(if (not node) ; no such element
(loop (cdr str-lst) res)
(loop (cdr str-lst) (cons node res))))))
(let rpt ((lst (string->list (sxml:string object)))
(tmp '())
(res '()))
(cond
((null? lst)
(if (null? tmp)
(reverse res)
(let ((node (sxml:lookup (list->string (reverse tmp)) id-index)))
(if (not node)
(reverse res)
(reverse (cons node res))))))
((member (car lst) '(#\space #\return #\newline #\tab))
(if (null? tmp)
(rpt (cdr lst) tmp res)
(let ((node (sxml:lookup (list->string (reverse tmp)) id-index)))
(if (not node)
(rpt (cdr lst) '() res)
(rpt (cdr lst) '() (cons node res))))))
(else (rpt (cdr lst) (cons (car lst) tmp) res)))))))
;;-------------------------------------------------------------------------------
;;!! Comparators for XPath objects
;;! Implements XPath equality comparison in a straightforward nested loop manner
(define (sxml:nested-loop-join string-set1 string-set2 string-op)
(let first ((str-set1 string-set1)
(str-set2 string-set2))
(cond
((null? str-set1) #f)
((let second ((elem (car str-set1))
(set2 str-set2))
(cond
((null? set2) #f)
((string-op elem (car set2)) #t)
(else (second elem (cdr set2))))) #t)
(else
(first (cdr str-set1) str-set2)))))
;;-------------------------------------------------------------------------------
;;!! Merge-sort for speeding up equality comparison of two nodesets
;;! Similar to R5RS 'list-tail' but returns the new list consisting of the first
;; 'k' members of 'lst'
(define (sxml:list-head lst k)
(if (or (null? lst) (zero? k))
'()
(cons (car lst) (sxml:list-head (cdr lst) (- k 1)))))
;;! Implements merge-sort of the given lst
;; Returns the sorted list, the smallest member first
;; less-than?-pred ::= (lambda (obj1 obj2) ...)
;; less-than?-pred returns #t if obj1<obj2 with respect to the given ordering
(define (sxml:merge-sort less-than?-pred lst)
(letrec
((merge-sorted-lists
; Merges 2 sorted lists into one sorted list
(lambda (lst1 lst2)
(cond
((null? lst1) lst2)
((null? lst2) lst1)
; both lists are non-null here
((less-than?-pred (car lst1) (car lst2))
(cons (car lst1)
(merge-sorted-lists (cdr lst1) lst2)))
(else
(cons (car lst2)
(merge-sorted-lists lst1 (cdr lst2))))))))
(if
(or (null? lst) (null? (cdr lst))) ; already sorted
lst
(let ((middle (inexact->exact (round (/ (length lst) 2)))))
(merge-sorted-lists
(sxml:merge-sort less-than?-pred (sxml:list-head lst middle))
(sxml:merge-sort less-than?-pred (list-tail lst middle)))))))
;;! Implementation of XPath equality comparison for 2 string-sets with
;; merge-sort join algorithm
(define (sxml:merge-sort-join string-set1 string-set2 string-op)
(let loop ((str-set1 (sxml:merge-sort string<? string-set1))
(str-set2 (sxml:merge-sort string<? string-set2)))
(cond
((or (null? str-set1) (null? str-set2))
#f)
((string-op (car str-set1) (car str-set2))
; comparison condition fulfilled for a pair of nodes
#t)
((string<? (car str-set1) (car str-set2))
; we can remove (car str-set1) from our further consideration
(loop (cdr str-set1) str-set2))
(else ; vice versa
(loop str-set1 (cdr str-set2))))))
;;-------------------------------------------------------------------------------
;;!! Radix-sort join for equality comparison of 2 nodesets
;; The running time of the algorithm is proportional to the nodeset size and
;; to node string-value length
;;
;; Since each nodeset contains O(n) nodes and string-value for each node is
;; O(n) in length, radix-sort join algorithm evaluates in O(n^2) time. By
;; comparison, nested loop join requires O(n^3) time, merge-sort join
;; implemented above requires O(n^2*log(n)).
;;
;; On the other hand, radix-sort join is time-ineffective for relatively small
;; nodesets being joined. For small nodesets, the above implemented sort-merge
;; join runs more effectively. Radix-sort join is promising for large nodesets.
;;! Represents a list of chars as a branch in the string-tree
;; The list of chars must be non-empty
(define (sxml:charlst->branch lst)
(if (null? (cdr lst)) ; this is the last character in the lst
`(,(car lst) #t)
`(,(car lst) #f ,(sxml:charlst->branch (cdr lst)))))
;;! Converts a string to a string-tree
(define (sxml:string->tree str)
(let ((lst (string->list str)))
(if (null? lst) ; an empty string is given
'(*top* #t)
`(*top* #f ,(sxml:charlst->branch lst)))))
;;! Adds a new string to string-tree
;; In a special case, tree257 may be #f. The function than creates a new tree,
;; which contains just the representation for str
(define (sxml:add-string-to-tree str tree)
(letrec
((add-lst-to-tree ; adds the list of chars to tree
(lambda (lst tree)
(if
(null? lst) ; the lst is over
(if
(cadr tree) ; whether it is already in the tree
tree
(cons (car tree)
(cons #t (cddr tree))))
(let ((curr-char (car lst)))
(let iter-alist ((alist (cddr tree))
(res (list (cadr tree) (car tree))))
(cond
((null? alist) ; branch not in a tree
(reverse
(cons
(sxml:charlst->branch lst)
res)))
((char=? (caar alist) curr-char) ; entry found
(if
(null? (cdr alist)) ; nothing more in the alist
(reverse
(cons
(add-lst-to-tree (cdr lst) (car alist))
res))
(append
(reverse
(cons
(add-lst-to-tree (cdr lst) (car alist))
res))
(cdr alist))))
((char>? (caar alist) curr-char)
(if
(null? (cdr alist)) ; nothing more in the alist
(reverse
(cons (car alist)
(cons (sxml:charlst->branch lst) res)))
(append
(reverse
(cons
(sxml:charlst->branch lst)
res))
alist)))
(else
(iter-alist (cdr alist)
(cons (car alist) res))))))))))
(add-lst-to-tree (string->list str) tree)))
;;! Whether a given string is presented in the string-tree
(define (sxml:string-in-tree? str tree)
(let loop ((lst (string->list str))
(tree tree))
(cond
((null? lst) ; the string is over
(cadr tree))
((assv (car lst) (cddr tree))
=> (lambda (new-tree)
(loop (cdr lst) new-tree)))
(else #f))))
;;! XPath equality comparison for 2 string-sets
;; bool-op - comparison function for 2 boolean values
(define (sxml:radix-sort-join string-set1 string-set2 bool-op)
(if
(null? string-set1) ; always #f
#f
(let ((tree
(let iter-1 ((set1 (cdr string-set1))
(tree (sxml:string->tree (car string-set1))))
(if (null? set1)
tree
(iter-1 (cdr set1)
(sxml:add-string-to-tree (car set1) tree))))))
(let iter-2 ((set2 string-set2))
(cond
((null? set2) ; equality not found
#f)
((bool-op (sxml:string-in-tree? (car set2) tree) #t)
#t)
(else
(iter-2 (cdr set2))))))))
;;-------------------------------------------------------------------------------
;;!! Equality comparison
;;! A helper for XPath equality operations: = , !=
;; 'bool-op', 'number-op' and 'string-op' are comparison operations for
;; a pair of booleans, numbers and strings respectively
(define (sxml:equality-cmp bool-op number-op string-op)
(lambda (obj1 obj2)
(cond
((and (not (nodeset? obj1)) (not (nodeset? obj2)))
; neither object is a nodeset
(cond
((boolean? obj1) (bool-op obj1 (sxml:boolean obj2)))
((boolean? obj2) (bool-op (sxml:boolean obj1) obj2))
((number? obj1) (number-op obj1 (sxml:number obj2)))
((number? obj2) (number-op (sxml:number obj1) obj2))
(else ; both objects are strings
(string-op obj1 obj2))))
((and (nodeset? obj1) (nodeset? obj2)) ; both objects are nodesets
(let ((lng1 (length obj1))
(lng2 (length obj2)))
(cond
((and (< lng1 100000) (< lng2 100000))
((if ; either nodeset is a short one
(or (<= lng1 2) (<= lng2 2))
sxml:nested-loop-join
sxml:merge-sort-join)
(map sxml:string-value obj1)
(map sxml:string-value obj2)
string-op))
((< lng1 lng2)
(sxml:radix-sort-join (map sxml:string-value obj1)
(map sxml:string-value obj2)
bool-op))
(else ; lng2 < lng1
(sxml:radix-sort-join (map sxml:string-value obj2)
(map sxml:string-value obj1)
bool-op)))))
(else ; one of the objects is a nodeset, another is not
(call-with-values
(lambda () ; Equality operations are commutative
(if (nodeset? obj1) (values obj1 obj2) (values obj2 obj1)))
(lambda (nset elem)
(cond
((boolean? elem) (bool-op elem (sxml:boolean nset)))
((number? elem)
(let loop ((nset
(map
(lambda (node) (sxml:number (sxml:string-value node)))
nset)))
(cond
((null? nset) #f)
((number-op elem (car nset)) #t)
(else (loop (cdr nset))))))
((string? elem)
(let loop ((nset (map sxml:string-value nset)))
(cond
((null? nset) #f)
((string-op elem (car nset)) #t)
(else (loop (cdr nset))))))
(else ; unknown datatype
(display (string-append "Unknown datatype: " (object->string elem))
(current-error-port))
#f))))))))
(define sxml:equal? (sxml:equality-cmp eq? = string=?))
(define sxml:not-equal?
(sxml:equality-cmp
(lambda (bool1 bool2) (not (eq? bool1 bool2)))
(lambda (num1 num2) (not (= num1 num2)))
(lambda (str1 str2) (not (string=? str1 str2)))))
;;-------------------------------------------------------------------------------
;;!! Relational comparison
;;! Relational operation ( < , > , <= , >= ) for two XPath objects
;; op is comparison procedure: < , > , <= or >=
(define (sxml:relational-cmp op)
(lambda (obj1 obj2)
(cond
((not (or (nodeset? obj1) (nodeset? obj2))) ; neither obj is a nodeset
(op (sxml:number obj1) (sxml:number obj2)))
((boolean? obj1) ; 'obj1' is a boolean, 'obj2' is a nodeset
(op (sxml:number obj1) (sxml:number (sxml:boolean obj2))))
((boolean? obj2) ; 'obj1' is a nodeset, 'obj2' is a boolean
(op (sxml:number (sxml:boolean obj1)) (sxml:number obj2)))
((or (null? obj1) (null? obj2)) ; one of the objects is an empty nodeset
#f)
(else ; at least one object is a nodeset
(op
(cond
((nodeset? obj1) ; 'obj1' is a (non-empty) nodeset
(let ((nset1 (map
(lambda (node) (sxml:number (sxml:string-value node)))
obj1)))
(let first ((num1 (car nset1))
(nset1 (cdr nset1)))
(cond
((null? nset1) num1)
((op num1 (car nset1)) (first num1 (cdr nset1)))
(else (first (car nset1) (cdr nset1)))))))
((string? obj1) (sxml:number obj1))
(else ; 'obj1' is a number
obj1))
(cond
((nodeset? obj2) ; 'obj2' is a (non-empty) nodeset
(let ((nset2 (map
(lambda (node) (sxml:number (sxml:string-value node)))
obj2)))
(let second ((num2 (car nset2))
(nset2 (cdr nset2)))
(cond
((null? nset2) num2)
((op num2 (car nset2)) (second (car nset2) (cdr nset2)))
(else (second num2 (cdr nset2)))))))
((string? obj2) (sxml:number obj2))
(else ; 'obj2' is a number
obj2)))))))
;;-------------------------------------------------------------------------------
;;!! XPath axes
;; An order in resulting nodeset is preserved
;;! Ancestor axis
(define (sxml:ancestor test-pred?)
(lambda (root-node) ; node or nodeset
(lambda (node) ; node or nodeset
(if (nodeset? node)
(map-union ((sxml:ancestor test-pred?) root-node) node)
(let rpt ((paths (if (nodeset? root-node)
(map list root-node)
(list (list root-node)))))
(if (null? paths)
'()
(let ((path (car paths)))
(if (eq? (car path) node)
((sxml:filter test-pred?) (cdr path))
(rpt (append
(map
(lambda (arg) (cons arg path))
(append
((sxml:attribute (ntype?? '*)) (car path))
((sxml:child sxml:node?) (car path))))
(cdr paths)))))))))))
;;! Ancestor-or-self axis
(define (sxml:ancestor-or-self test-pred?)
(lambda (root-node) ; node or nodeset
(lambda (node) ; node or nodeset
(if (nodeset? node)
(map-union ((sxml:ancestor-or-self test-pred?) root-node) node)
(let rpt ((paths (if (nodeset? root-node)
(map list root-node)
(list (list root-node)))))
(if (null? paths)
((sxml:filter test-pred?) (list node))
(let ((path (car paths)))
(if (eq? (car path) node)
((sxml:filter test-pred?) path)
(rpt (append
(map
(lambda (arg) (cons arg path))
(append
((sxml:attribute (ntype?? '*)) (car path))
((sxml:child sxml:node?) (car path))))
(cdr paths)))))))))))
;;! Descendant axis
;; It's similar to original 'node-closure' a resulting nodeset is
;; in depth-first order rather than breadth-first
;; Fix: din't descend in non-element nodes!
(define (sxml:descendant test-pred?)
(lambda (node) ; node or nodeset
(if (nodeset? node)
(map-union (sxml:descendant test-pred?) node)
(let rpt ((res '())
(more ((sxml:child sxml:node?) node)))
(if (null? more)
(reverse res)
(rpt (if (test-pred? (car more))
(cons (car more) res)
res)
(append ((sxml:child sxml:node?) (car more))
(cdr more))))))))
;;! Descendant-or-self axis
(define (sxml:descendant-or-self test-pred?)
(lambda (node) ; node or nodeset
(if (nodeset? node)
(map-union (sxml:descendant-or-self test-pred?) node)
(let rpt ((res '())
(more (list node)))
(if (null? more)
(reverse res)
(rpt (if (test-pred? (car more))
(cons (car more) res)
res)
(append ((sxml:child sxml:node?) (car more))
; sxml:node?
(cdr more))))))))
;;! Following axis
(define (sxml:following test-pred?)
(lambda (root-node) ; node or nodeset
(lambda (node) ; node or nodeset
(if (nodeset? node)
(map-union ((sxml:following test-pred?) root-node) node)
(let loop ((seq (if (nodeset? root-node)
(list root-node)
(list (list root-node)))))
(cond
((null? seq) '())
((null? (car seq)) (loop (cdr seq)))
((eq? (caar seq) node)
(let rpt ((seq (cdr (apply append seq)))
(res '()))
(if (null? seq)
res
(rpt (cdr seq)
(append
res
((sxml:descendant-or-self test-pred?) (car seq)))))))
((and (sxml:element? (caar seq))
(memq node (sxml:attr-list (caar seq))))
(let rpt ((sq (cdr (apply append seq)))
(res ((sxml:descendant test-pred?) (caar seq))))
(if (null? sq)
res
(rpt (cdr sq)
(append res
((sxml:descendant-or-self test-pred?) (car sq)))))))
(else
(loop (cons
((sxml:child sxml:node?) (caar seq))
(cons (cdar seq) (cdr seq)))))))))))
;;! Following-sibling axis
(define (sxml:following-sibling test-pred?)
(lambda (root-node) ; node or nodeset
(lambda (node) ; node or nodeset
(if (nodeset? node)
(map-union ((sxml:following-sibling test-pred?) root-node) node)
(let loop ((seqs (if (nodeset? root-node)
(list root-node)
(list (list root-node)))))
(if (null? seqs)
'()
(let rpt ((seq (car seqs)))
(cond
((null? seq)
(loop (append
(map (sxml:child sxml:node?)
(car seqs))
(cdr seqs))))
((eq? (car seq) node) ((sxml:filter test-pred?) (cdr seq)))
(else (rpt (cdr seq)))))))))))
;;! Namespace axis
(define (sxml:namespace test-pred?)
(lambda (node) ; node or nodeset
((sxml:filter test-pred?)
(sxml:ns-list node))))
;;! Preceding axis
(define (sxml:preceding test-pred?)
(lambda (root-node) ; node or nodeset
(lambda (node) ; node or nodeset
(if (nodeset? node)
(map-union ((sxml:preceding test-pred?) root-node) node)
(let loop ((seq (if (nodeset? root-node)
(list (reverse root-node))
(list (list root-node)))))
(cond
((null? seq) '())
((null? (car seq)) (loop (cdr seq)))
((or (eq? (caar seq) node)
(not (null? ((sxml:attribute
(lambda (n)
(eq? n node)))
(caar seq)))))
(let rpt ((seq (cdr (apply append seq)))
(res '()))
(if (null? seq)
res
(rpt (cdr seq)
(append res
(reverse ((sxml:descendant-or-self test-pred?)
(car seq))))))))
(else (loop (cons (reverse ((sxml:child sxml:node?) (caar seq)))
(cons (cdar seq) (cdr seq)))))))))))
;;! Preceding-sibling axis
(define (sxml:preceding-sibling test-pred?)
(lambda (root-node) ; node or nodeset
(lambda (node) ; node or nodeset
(if(nodeset? node)
(map-union ((sxml:preceding-sibling test-pred?) root-node) node)
(let loop ((seqs (if (nodeset? root-node)
(list root-node)
(list (list root-node)))))
(if (null? seqs)
'()
(let rpt ((seq (car seqs)))
(cond
((null? seq)
(loop (append
(map
(lambda (n)
(reverse ((sxml:child sxml:node?) n)))
(car seqs))
(cdr seqs))))
((eq? (car seq) node) ((sxml:filter test-pred?) (cdr seq)))
(else (rpt (cdr seq)))))))))))
| false |
3cf7665c157bdc5264b11a9a8e9f4aad7864591d | ae0d7be8827e8983c926f48a5304c897dc32bbdc | /nekoie/okurairi/gauche-old01/cgi-client.cgi | cab7250a2f8f91dabbd6f759af29210b9ce01f47 | []
| no_license | ayamada/copy-of-svn.tir.jp | 96c2176a0295f60928d4911ce3daee0439d0e0f4 | 101cd00d595ee7bb96348df54f49707295e9e263 | refs/heads/master | 2020-04-04T01:03:07.637225 | 2015-05-28T07:00:18 | 2015-05-28T07:00:18 | 1,085,533 | 3 | 2 | null | 2015-05-28T07:00:18 | 2010-11-16T15:56:30 | Scheme | UTF-8 | Scheme | false | false | 385 | cgi | cgi-client.cgi | #!/usr/local/bin/gosh
;;; coding: euc-jp
;;; -*- scheme -*-
;;; vim:set ft=scheme ts=8 sts=2 sw=2 et:
;;; $Id$
(add-load-path "/home/nekoie/Gauche-tir/trunk")
(add-load-path "/home/nekoie/nekoie/tmp/scheme")
(add-load-path ".")
(use cgi-client)
(define *cgi-client*
(make <cgi-client>
:session-dbm-path "./hoge"
))
(define (main args)
(cgi-client-main *cgi-client*))
| false |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.