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 |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
bea50ed1a9f37b6578a1a8ad99636e4219f8526a | 51d30de9d65cc3d5079f050de33d574584183039 | /ssax-5.1/packages.scm | 8e0817769cd99d896eb22da53e3c3519ad00b77c | [
"BSD-2-Clause",
"BSD-3-Clause"
]
| permissive | langmartin/ykk | 30feb00265d603ef765b5c664d2f759be34b7b89 | dd6e441dddd5b6363ee9adbbdd0f346c1522ffcf | refs/heads/master | 2016-09-05T20:01:19.353224 | 2009-12-10T16:25:55 | 2009-12-10T16:25:55 | 408,478 | 0 | 1 | null | null | null | null | UTF-8 | Scheme | false | false | 9,342 | scm | packages.scm | (define-structure scsh-compat
(export
file-size
open-output-string
open-input-string
get-output-string
error)
(open scheme
simple-signals
posix
extended-ports)
(begin
(define (file-size name)
(file-info-size (get-file-info name)))
(define open-output-string make-string-output-port)
(define (get-output-string port)
(let ((r (string-output-port-output port)))
(close-output-port port)
r))
(define open-input-string make-string-input-port)))
(define-interface htmlprag-interface
(export
html->sxml
html->shtml
write-shtml-as-html
shtml->html))
(define-structure htmlprag
htmlprag-interface
(open scheme
scsh-compat)
(files htmlprag))
;; Interface definitions first
;; Utilities
(define-interface parser-errors-interface
(export parser-error))
(define-interface input-parses-interface
(export peek-next-char
assert-curr-char
skip-until skip-while
next-token next-token-of
read-text-line
read-string
parser-error))
(define-interface ssax-warnings-interface
(export ssax:warn))
(define-interface assertions-interface
(export ((assert assure) :syntax)))
(define-interface coutputs-interface
(export cout cerr nl))
(define-interface ppretty-prints-interface
(export pp))
(define-interface crementing-interface
(export inc dec))
(define-interface oleg-utils-interface
(export any?
list-intersperse list-intersperse!
list-tail-diff
string-rindex
substring?
string->integer
string-split
make-char-quotator))
(define-interface control-flows-interface
(export (when :syntax)
(begin0 :syntax)))
(define-interface find-strings-interface
(export find-string-from-port?))
(define-interface catch-errors-interface
(export (failed? :syntax)))
(define-interface char-encodings-interface
(export ucscode->char
char-return
char-tab
char-newline))
;; The Meat
(define-interface sxml-tree-trans-interface
(export SRV:send-reply
post-order pre-post-order replace-range))
(define-interface sxml-to-html-interface
(export SXML->HTML
enattr
entag
string->goodHTML))
(define-interface sxml-to-html-ext-interface
(export make-header
make-navbar
make-footer
universal-conversion-rules
universal-protected-rules
alist-conv-rules))
(define-interface ssax-interface
(export xml-token? xml-token-kind xml-token-head
make-empty-attlist attlist-add
attlist-null?
attlist-remove-top
attlist->alist attlist-fold
ssax:uri-string->symbol
ssax:skip-internal-dtd
ssax:read-pi-body-as-string
ssax:reverse-collect-str-drop-ws
ssax:read-markup-token
ssax:read-cdata-body
ssax:read-char-ref
ssax:read-attributes
ssax:complete-start-tag
ssax:read-external-id
ssax:read-char-data
((ssax:make-parser ssax:make-pi-parser ssax:make-elem-parser) :syntax)
ssax:xml->sxml))
(define-interface sxpath-interface
(export nodeset?
map-union
sxpath
txpath))
;; this list was made by quick glances at
;; sxml-tools.scm. it is not complete
(define-interface sxml-basic-tools-interface
(export sxml:attr-list-node
sxml:attr-as-list
sxml:attr-list-u
sxml:aux-list-node
sxml:aux-as-list
sxml:empty-element?
sxml:shallow-normalized?
sxml:normalized?
sxml:shallow-minimized?
sxml:minimized?
sxml:content
sxml:text
sxml:content-raw
sxml:name
sxml:node-name
sxml:attr
sxml:attr-from-list
sxml:num-attr
sxml:change-content!
sxml:change-content
sxml:change-attrlist
sxml:change-attrlist!
sxml:change-name!
sxml:change-name
sxml:add-attr!
sxml:add-attr
sxml:change-attr!
sxml:change-attr
sxml:set-attr!
sxml:set-attr
sxml:add-aux!
sxml:add-aux
sxml:squeeze!
sxml:squeeze
sxml:clean
sxml:node-parent
sxml:add-parents
sxml:lookup))
;; Structures
;; Utilities
(define-structure define-opt (export (define-opt :syntax))
(open scheme
srfi-23)
(files define-opt))
(define-structure parser-errors-vanilla parser-errors-interface
(open scheme signals)
(begin
(define (parser-error port message . rest)
(apply error message rest))))
(define (make-input-parses parser-errors-structure)
(structure input-parses-interface
(open scheme
ascii
(subset srfi-13 (string-concatenate-reverse))
define-opt
crementing
char-encodings
parser-errors-structure)
(files input-parse)))
(define input-parses-vanilla (make-input-parses parser-errors-vanilla))
(define-structure assertions assertions-interface
(open scheme
big-util)
(files assert))
(define-structure coutputs coutputs-interface
(open scheme i/o)
(files output))
(define-structure ppretty-prints ppretty-prints-interface
(open scheme pp)
(begin
(define pp p)))
(define-structure crementing crementing-interface
(open scheme)
(begin
(define (inc n) (+ n 1))
(define (dec n) (- n 1))))
(define-structure oleg-utils oleg-utils-interface
(open scheme
(subset srfi-13 (string-index-right string-contains string-null?))
srfi-23
crementing)
(files util))
(define-structure char-encodings char-encodings-interface
(open scheme
ascii)
(begin
(define ucscode->char ascii->char)
(define char-return (ascii->char 13))
(define char-tab (ascii->char 9))
(define char-newline (ascii->char 10))))
(define-structure oleg-string-ports (export with-output-to-string
call-with-input-string
with-input-from-string)
(open scheme extended-ports i/o-internal)
(begin
(define (with-output-to-string thunk)
(call-with-string-output-port
(lambda (port)
(call-with-current-output-port port thunk))))
(define (call-with-input-string string proc)
(proc (make-string-input-port string)))
(define with-input-from-string call-with-input-string)))
(define-structure control-flows control-flows-interface
(open scheme)
(files control))
(define-structure find-strings find-strings-interface
(open scheme
crementing)
(files look-for-str))
(define-structure catch-errors catch-errors-interface
(open scheme handle)
(begin
(define-syntax failed?
(syntax-rules ()
((failed? stmts ...)
(thunk-failed? (lambda () stmts ...)))))
(define (thunk-failed? thunk)
(call-with-current-continuation
(lambda (return)
(with-handler
(lambda (condition more)
(return #t))
(lambda ()
(thunk)
#f)))))))
;; The Meat
(define-structure sxml-tree-trans sxml-tree-trans-interface
(open scheme
assertions
srfi-11 ; LET*-VALUES
srfi-23) ; ERROR
(files "SXML-tree-trans.scm"))
(define-structure sxml-to-html sxml-to-html-interface
(open scheme
coutputs assertions
oleg-utils
sxml-tree-trans)
(files "SXML-to-HTML.scm"))
(define-structure sxml-to-html-ext sxml-to-html-ext-interface
(open scheme
scsh-compat
(subset srfi-13 (string-split))
srfi-23
oleg-utils
coutputs
assertions
crementing
sxml-to-html
sxml-tree-trans)
(begin
(define OS:file-length file-size))
(files "SXML-to-HTML-ext.scm"))
(define (make-ssax input-parses-structure ssax-warnings-structure)
(structure ssax-interface
(open scheme
oleg-utils control-flows find-strings
ascii
assertions
coutputs catch-errors
oleg-string-ports
input-parses-structure
ssax-warnings-structure
char-encodings
crementing
(subset srfi-1 (cons*))
srfi-6 ; OPEN-INPUT-STRING
srfi-11 ; LET-VALUES
(subset srfi-13 (string-index
string-null?
string-concatenate-reverse/shared
string-concatenate/shared))
srfi-23
ppretty-prints)
(files "SSAX-code.scm")))
(define-structure ssax-warnings-vanilla ssax-warnings-interface
(open scheme
coutputs)
(files ssax-warn-vanilla))
(define ssax-vanilla (make-ssax input-parses-vanilla
ssax-warnings-vanilla))
(define-structure sxml-basic-tools
(compound-interface sxml-basic-tools-interface
sxpath-interface)
(open scheme
assertions
coutputs
simple-signals
oleg-utils
crementing
srfi-1
srfi-2
extended-ports
srfi-13
pp)
(begin
(define pp p)
(define (call-with-input-string str proc)
(proc (make-string-input-port str)))
(define-syntax define-macro
(lambda (e r c)
(let* ((pattern (cadr e))
(name (if (pair? pattern)
(car pattern)
pattern))
(lamb (if (pair? pattern)
(cons 'lambda (cons (cdr pattern) (cddr e)))
(caddr e))))
`(define-syntax ,name
(lambda (e r c)
(let ((args (cdr e)))
(apply ,lamb args))))))))
(files "sxml-tools/sxpathlib.scm"
"sxml-tools/xpath-parser.scm"
"sxml-tools/sxml-tools.scm"
"sxml-tools/sxpath-ext.scm"
"sxml-tools/sxpath.scm"
"sxml-tools/txpath.scm"))
| true |
3177e1eab487a36fd25b45e7293f94c17bb9abc4 | f08220a13ec5095557a3132d563a152e718c412f | /logrotate/skel/usr/share/guile/2.0/system/xref.scm | 922d17fa911fe21b11a0b53836bc3ce380287cf3 | [
"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 | 14,602 | scm | xref.scm | ;;;; Copyright (C) 2009, 2010 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 2.1 of the License, or (at your option) any later version.
;;;;
;;;; This library is distributed in the hope that it will be useful,
;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
;;;; Lesser General Public License for more details.
;;;;
;;;; You should have received a copy of the GNU Lesser General Public
;;;; License along with this library; if not, write to the Free Software
;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
;;;;
(define-module (system xref)
#:use-module (system base pmatch)
#:use-module (system base compile)
#:use-module (system vm program)
#:use-module (srfi srfi-1)
#:export (*xref-ignored-modules*
procedure-callees
procedure-callers
source-closures
source-procedures))
;;;
;;; The cross-reference database: who calls whom.
;;;
(define (program-callee-rev-vars prog)
(define (cons-uniq x y)
(if (memq x y) y (cons x y)))
(cond
((program-objects prog)
=> (lambda (objects)
(let ((n (vector-length objects))
(progv (make-vector (vector-length objects) #f))
(asm (decompile (program-objcode prog) #:to 'assembly)))
(pmatch asm
((load-program ,labels ,len . ,body)
(for-each
(lambda (x)
(pmatch x
((toplevel-ref ,n) (vector-set! progv n #t))
((toplevel-set ,n) (vector-set! progv n #t))))
body)))
(let lp ((i 0) (out '()))
(cond
((= i n) out)
((program? (vector-ref objects i))
(lp (1+ i)
(fold cons-uniq out
(program-callee-rev-vars (vector-ref objects i)))))
((vector-ref progv i)
(let ((obj (vector-ref objects i)))
(if (variable? obj)
(lp (1+ i) (cons-uniq obj out))
;; otherwise it's an unmemoized binding
(pmatch obj
(,sym (guard (symbol? sym))
(let ((v (module-variable (or (program-module prog)
the-root-module)
sym)))
(lp (1+ i) (if v (cons-uniq v out) out))))
((,mod ,sym ,public?)
;; hm, hacky.
(let* ((m (nested-ref-module (resolve-module '() #f)
mod))
(v (and m
(module-variable
(if public?
(module-public-interface m)
m)
sym))))
(lp (1+ i)
(if v (cons-uniq v out) out))))))))
(else (lp (1+ i) out)))))))
(else '())))
(define (procedure-callee-rev-vars proc)
(cond
((program? proc) (program-callee-rev-vars proc))
(else '())))
(define (procedure-callees prog)
"Evaluates to a list of the given program callees."
(let lp ((in (procedure-callee-rev-vars prog)) (out '()))
(cond ((null? in) out)
((variable-bound? (car in))
(lp (cdr in) (cons (variable-ref (car in)) out)))
(else (lp (cdr in) out)))))
;; var -> ((module-name caller ...) ...)
(define *callers-db* #f)
;; module-name -> (callee ...)
(define *module-callees-db* (make-hash-table))
;; (module-name ...)
(define *tainted-modules* '())
(define *xref-ignored-modules* '((value-history)))
(define (on-module-modified m)
(let ((name (module-name m)))
(if (and (not (member name *xref-ignored-modules*))
(not (member name *tainted-modules*))
(pair? name))
(set! *tainted-modules* (cons name *tainted-modules*)))))
(define (add-caller callee caller mod-name)
(let ((all-callers (hashq-ref *callers-db* callee)))
(if (not all-callers)
(hashq-set! *callers-db* callee `((,mod-name ,caller)))
(let ((callers (assoc mod-name all-callers)))
(if callers
(if (not (member caller callers))
(set-cdr! callers (cons caller (cdr callers))))
(hashq-set! *callers-db* callee
(cons `(,mod-name ,caller) all-callers)))))))
(define (forget-callers callee mod-name)
(hashq-set! *callers-db* callee
(assoc-remove! (hashq-ref *callers-db* callee '()) mod-name)))
(define (add-callees callees mod-name)
(hash-set! *module-callees-db* mod-name
(append callees (hash-ref *module-callees-db* mod-name '()))))
(define (untaint-modules)
(define (untaint m)
(for-each (lambda (callee) (forget-callers callee m))
(hash-ref *module-callees-db* m '()))
(ensure-callers-db m))
(ensure-callers-db #f)
(for-each untaint *tainted-modules*)
(set! *tainted-modules* '()))
(define (ensure-callers-db mod-name)
(let ((mod (and mod-name (resolve-module mod-name)))
(visited #f))
(define (visit-variable var mod-name)
(if (variable-bound? var)
(let ((x (variable-ref var)))
(cond
((and visited (hashq-ref visited x)))
((procedure? x)
(if visited (hashq-set! visited x #t))
(let ((callees (filter variable-bound?
(procedure-callee-rev-vars x))))
(for-each (lambda (callee)
(add-caller callee x mod-name))
callees)
(add-callees callees mod-name)))))))
(define (visit-module mod)
(if visited (hashq-set! visited mod #t))
(if (not (memq on-module-modified (module-observers mod)))
(module-observe mod on-module-modified))
(let ((name (module-name mod)))
(module-for-each (lambda (sym var)
(visit-variable var name))
mod)))
(define (visit-submodules mod)
(hash-for-each
(lambda (name sub)
(if (not (and visited (hashq-ref visited sub)))
(begin
(visit-module sub)
(visit-submodules sub))))
(module-submodules mod)))
(cond ((and (not mod-name) (not *callers-db*))
(set! *callers-db* (make-hash-table 1000))
(set! visited (make-hash-table 1000))
(visit-submodules (resolve-module '() #f)))
(mod-name (visit-module mod)))))
(define (procedure-callers var)
"Returns an association list, keyed by module name, of known callers
of the given procedure. The latter can specified directly as a
variable, a symbol (which gets resolved in the current module) or a
pair of the form (module-name . variable-name), "
(let ((v (cond ((variable? var) var)
((symbol? var) (module-variable (current-module) var))
(else
(pmatch var
((,modname . ,sym)
(module-variable (resolve-module modname) sym))
(else
(error "expected a variable, symbol, or (modname . sym)" var)))))))
(untaint-modules)
(hashq-ref *callers-db* v '())))
;;;
;;; The source database: procedures defined at a given source location.
;;;
;; FIXME: refactor to share code with the xref database.
;; ((ip file line . col) ...)
(define (procedure-sources proc)
(cond
((program? proc) (program-sources proc))
(else '())))
;; file -> line -> (proc ...)
(define *closure-sources-db* #f)
;; file -> line -> (proc ...)
(define *sources-db* #f)
;; module-name -> proc -> sources
(define *module-sources-db* (make-hash-table))
;; (module-name ...)
(define *tainted-sources* '())
(define (on-source-modified m)
(let ((name (module-name m)))
(if (and (not (member name *xref-ignored-modules*))
(not (member name *tainted-sources*))
(pair? name))
(set! *tainted-sources* (cons name *tainted-sources*)))))
(define (add-source proc file line db)
(let ((file-table (or (hash-ref db file)
(let ((table (make-hash-table)))
(hash-set! db file table)
table))))
(hashv-set! file-table
line
(cons proc (hashv-ref file-table line '())))))
(define (forget-source proc file line db)
(let ((file-table (hash-ref db file)))
(if file-table
(let ((procs (delq proc (hashv-ref file-table line '()))))
(if (pair? procs)
(hashv-set! file-table line procs)
(hashv-remove! file-table line))))))
(define (add-sources proc mod-name db)
(let ((sources (procedure-sources proc)))
(if (pair? sources)
(begin
;; Add proc to *module-sources-db*, for book-keeping.
(hashq-set! (or (hash-ref *module-sources-db* mod-name)
(let ((table (make-hash-table)))
(hash-set! *module-sources-db* mod-name table)
table))
proc
sources)
;; Actually add the source entries.
(for-each (lambda (source)
(pmatch source
((,ip ,file ,line . ,col)
(add-source proc file line db))
(else (error "unexpected source format" source))))
sources)))
;; Add source entries for nested procedures.
(for-each (lambda (obj)
(if (procedure? obj)
(add-sources obj mod-name *closure-sources-db*)))
(or (and (program? proc)
(and=> (program-objects proc) vector->list))
'()))))
(define (forget-sources proc mod-name db)
(let ((mod-table (hash-ref *module-sources-db* mod-name)))
(if mod-table
(begin
;; Forget source entries.
(for-each (lambda (source)
(pmatch source
((,ip ,file ,line . ,col)
(forget-source proc file line db))
(else (error "unexpected source format" source))))
(hashq-ref mod-table proc '()))
;; Forget the proc.
(hashq-remove! mod-table proc)
;; Forget source entries for nested procedures.
(for-each (lambda (obj)
(if (procedure? obj)
(forget-sources obj mod-name *closure-sources-db*)))
(or (and (program? proc)
(and=> (program-objects proc) vector->list))
'()))))))
(define (untaint-sources)
(define (untaint m)
(for-each (lambda (proc) (forget-sources proc m *sources-db*))
(cond
((hash-ref *module-sources-db* m)
=> (lambda (table)
(hash-for-each (lambda (proc sources) proc) table)))
(else '())))
(ensure-sources-db m))
(ensure-sources-db #f)
(for-each untaint *tainted-sources*)
(set! *tainted-sources* '()))
(define (ensure-sources-db mod-name)
(define (visit-module mod)
(if (not (memq on-source-modified (module-observers mod)))
(module-observe mod on-source-modified))
(let ((name (module-name mod)))
(module-for-each
(lambda (sym var)
(if (variable-bound? var)
(let ((x (variable-ref var)))
(if (procedure? x)
(add-sources x name *sources-db*)))))
mod)))
(define visit-submodules
(let ((visited #f))
(lambda (mod)
(if (not visited)
(set! visited (make-hash-table)))
(hash-for-each
(lambda (name sub)
(if (not (hashq-ref visited sub))
(begin
(hashq-set! visited sub #t)
(visit-module sub)
(visit-submodules sub))))
(module-submodules mod)))))
(cond ((and (not mod-name) (not *sources-db*) (not *closure-sources-db*))
(set! *closure-sources-db* (make-hash-table 1000))
(set! *sources-db* (make-hash-table 1000))
(visit-submodules (resolve-module '() #f)))
(mod-name (visit-module (resolve-module mod-name)))))
(define (lines->ranges file-table)
(let ((ranges (make-hash-table)))
(hash-for-each
(lambda (line procs)
(for-each
(lambda (proc)
(cond
((hashq-ref ranges proc)
=> (lambda (pair)
(if (< line (car pair))
(set-car! pair line))
(if (> line (cdr pair))
(set-cdr! pair line))))
(else
(hashq-set! ranges proc (cons line line)))))
procs))
file-table)
(sort! (hash-map->list cons ranges)
(lambda (x y) (< (cadr x) (cadr y))))))
(define* (lookup-source-procedures canon-file line db)
(let ((file-table (hash-ref db canon-file)))
(let lp ((ranges (if file-table (lines->ranges file-table) '()))
(procs '()))
(cond
((null? ranges) (reverse procs))
((<= (cadar ranges) line (cddar ranges))
(lp (cdr ranges) (cons (caar ranges) procs)))
(else
(lp (cdr ranges) procs))))))
(define* (source-closures file line #:key (canonicalization 'relative))
(ensure-sources-db #f)
(let* ((port (with-fluids ((%file-port-name-canonicalization canonicalization))
(false-if-exception (open-input-file file))))
(file (if port (port-filename port) file)))
(lookup-source-procedures file line *closure-sources-db*)))
(define* (source-procedures file line #:key (canonicalization 'relative))
(ensure-sources-db #f)
(let* ((port (with-fluids ((%file-port-name-canonicalization canonicalization))
(false-if-exception (open-input-file file))))
(file (if port (port-filename port) file)))
(lookup-source-procedures file line *sources-db*)))
| false |
e41ddae949a338e94eaf62a96e6acec7dbcfd865 | 58381f6c0b3def1720ca7a14a7c6f0f350f89537 | /Chapter 1/1.3/Ex1.34.scm | c93a2b55ae0a79bfc46d68ee2a13402796f7f499 | []
| no_license | yaowenqiang/SICPBook | ef559bcd07301b40d92d8ad698d60923b868f992 | c8a0228ebf66d9c1ddc5ef1fcc1d05d8684f090a | refs/heads/master | 2020-04-19T04:03:15.888492 | 2015-11-02T15:35:46 | 2015-11-02T15:35:46 | null | 0 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 348 | scm | Ex1.34.scm | #lang planet neil/sicp
(define (f g) (g 2))
(f (lambda (z) (* z (+ z 1))))
;6
(f f)
;; This will resolve to (2 2) which will give
;; an error since 2 is not an operator
;; Execution channel is shown below
;; (f f)
;; -> (f 2)
;; -> (2 2)
;; This resembles partial application too and
;; trying to partially-apply a non-function value fails. | false |
c03e816eb5fd7cb96dcad159a8ed39b16ad74799 | d074b9a2169d667227f0642c76d332c6d517f1ba | /sicp/ch_5/exercise.5.44.scm | 7e24505cb32f9428bf99a298fa31d91151f67d09 | []
| no_license | zenspider/schemers | 4d0390553dda5f46bd486d146ad5eac0ba74cbb4 | 2939ca553ac79013a4c3aaaec812c1bad3933b16 | refs/heads/master | 2020-12-02T18:27:37.261206 | 2019-07-14T15:27:42 | 2019-07-14T15:27:42 | 26,163,837 | 7 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 1,256 | scm | exercise.5.44.scm | #!/usr/bin/env csi -s
(require rackunit)
;;; Exercise 5.44
;; In this section we have focused on the use of the compile-time
;; environment to produce lexical addresses. But there are other uses
;; for compile-time environments. For instance, in *Note Exercise
;; 5-38:: we increased the efficiency of compiled code by open-coding
;; primitive procedures. Our implementation treated the names of
;; open-coded procedures as reserved words. If a program were to
;; rebind such a name, the mechanism described in *Note Exercise
;; 5-38:: would still open-code it as a primitive, ignoring the new
;; binding. For example, consider the procedure
;;
;; (lambda (+ * a b x y)
;; (+ (* a x) (* b y)))
;;
;; which computes a linear combination of `x' and `y'. We might call
;; it with arguments `+matrix', `*matrix', and four matrices, but the
;; open-coding compiler would still open-code the `+' and the `*' in
;; `(+ (* a x) (* b y))' as primitive `+' and `*'. Modify the
;; open-coding compiler to consult the compile-time environment in
;; order to compile the correct code for expressions involving the
;; names of primitive procedures. (The code will work correctly as
;; long as the program does not `define' or `set!' these names.)
;; TODO | false |
73b9b029ecc4f1e0f44a859372c2839512d16aec | 7ccc32420e7caead27a5a138a02e9c9e789301d0 | /tan.sls | f7df9e734f0850d8f3d248b68f2dffbd5be4cffe | [
"Apache-2.0"
]
| permissive | dharmatech/mpl | 03d9c884a51c3aadc0f494e0d0cebf851f570684 | 36f3ea90ba5dfa0323de9aaffd5fd0f4c11643d7 | refs/heads/master | 2023-02-05T20:21:56.382533 | 2023-01-31T18:10:51 | 2023-01-31T18:10:51 | 280,353 | 63 | 8 | Apache-2.0 | 2023-01-31T18:10:53 | 2009-08-17T21:02:35 | Scheme | UTF-8 | Scheme | false | false | 580 | sls | tan.sls | #!r6rs
(library (mpl tan)
(export tan)
(import (mpl rnrs-sans)
(mpl match)
(mpl arithmetic))
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(define (simplify-tan u)
(match u
( (and ('tan ('* n . elts))
(? (lambda (_)
(and (number? n)
(negative? n)))))
(- (tan (apply * (append (list -1 n) elts)))) )
( else u )))
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(define (tan x)
(simplify-tan `(tan ,x)))
)
| false |
be4df0154d14e7589bc442c93cd0c918b630c21b | c74dcb1facbd920d762017345171f47f8e41d0c5 | /chapter_3/3.22.scm | f85268a2c35da6267eaf59ff78130749224fec2e | []
| no_license | akash-akya/sicp-exercises | 5125c1118c7f0e4400cb823508797fb67c745592 | c28f73719740c2c495b7bc38ee8b790219482b67 | refs/heads/master | 2021-06-15T19:12:47.679967 | 2019-08-03T14:03:20 | 2019-08-03T14:03:20 | 136,158,517 | 0 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 2,225 | scm | 3.22.scm | #lang sicp
(#%require "utils.scm")
;; Exercise 3.22: Instead of representing a queue as a pair of
;; pointers, we can build a queue as a procedure with local state. The
;; local state will consist of pointers to the beginning and the end
;; of an ordinary list. Thus, the make-queue procedure will have the
;; form
;; (define (make-queue)
;; (let ((front-ptr … )
;; (rear-ptr … ))
;; ⟨definitions of internal procedures⟩
;; (define (dispatch m) …)
;; dispatch))
;; Complete the definition of make-queue and provide implementations
;; of the queue operations using this representation.
(define (make-queue)
(let ((front-ptr nil)
(rear-ptr nil))
(define (set-front-ptr! item)
(set! front-ptr item))
(define (set-rear-ptr! item)
(set! rear-ptr item))
(define (empty-queue?)
(null? front-ptr))
(define (insert-queue! item)
(let ((new-pair (cons item '())))
(cond ((empty-queue?)
(set-front-ptr! new-pair)
(set-rear-ptr! new-pair))
(else (set-cdr! rear-ptr new-pair)
(set-rear-ptr! new-pair)))))
(define (delete-queue!)
(cond ((empty-queue?)
(error "DELETE! called with
an empty queue"))
(else
(set-front-ptr! (cdr front-ptr)))))
(define (print-queue)
(define (iter list)
(cond ((null? list)
(newline))
(else
(display (car list))
(display " ")
(iter (cdr list)))))
(newline)
(iter front-ptr))
(define (dispatch m)
(cond ((eq? 'insert m) insert-queue!)
((eq? 'delete m) delete-queue!)
((eq? 'print m) print-queue)
(else
(error "Invalid option!" m))))
dispatch))
(define (delete-queue! q)
((q 'delete)))
(define (insert-queue! q item)
((q 'insert) item))
(define (print-queue q)
((q 'print)))
;; test
(define (test)
(define q1 (make-queue))
(insert-queue! q1 'a)
(insert-queue! q1 'b)
(insert-queue! q1 'c)
(print-queue q1)
(delete-queue! q1)
(print-queue q1)
(delete-queue! q1)
(print-queue q1))
(test)
| false |
80dc4f1c0e9ac6899c353884579bbe9a0b1dca93 | defeada37d39bca09ef76f66f38683754c0a6aa0 | /System.Xml/system/xml/xml-text-reader.sls | 6249c55ae691d266c1cc4b4b2e46e5032e88a2af | []
| 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 | 9,672 | sls | xml-text-reader.sls | (library (system xml xml-text-reader)
(export new
is?
xml-text-reader?
read?
move-to-next-attribute?
reset-state
lookup-namespace
read-content-as-bin-hex
read-element-content-as-bin-hex
get-remainder
read-base64
move-to-first-attribute?
read-string
get-attribute
skip
has-line-info?
resolve-entity
read-attribute-value?
read-chars
read-content-as-base64
move-to-attribute
get-namespaces-in-scope
read-bin-hex
read-element-content-as-base64
move-to-element?
close
attribute-count
base-uri
can-read-binary-content?
can-read-value-chunk?
can-resolve-entity?
depth
eof?
has-value?
is-default?
is-empty-element?
local-name
name
namespace-uri
name-table
node-type
prefix
quote-char
read-state
settings
value
xml-lang
xml-space
encoding
entity-handling-get
entity-handling-set!
entity-handling-update!
line-number
line-position
namespaces?-get
namespaces?-set!
namespaces?-update!
normalization?-get
normalization?-set!
normalization?-update!
prohibit-dtd?-get
prohibit-dtd?-set!
prohibit-dtd?-update!
whitespace-handling-get
whitespace-handling-set!
whitespace-handling-update!
xml-resolver)
(import (ironscheme-clr-port))
(define-syntax new
(lambda (e)
(syntax-case e ()
((_ a ...) #'(clr-new System.Xml.XmlTextReader a ...)))))
(define (is? a) (clr-is System.Xml.XmlTextReader a))
(define (xml-text-reader? a) (clr-is System.Xml.XmlTextReader a))
(define-method-port
read?
System.Xml.XmlTextReader
Read
(System.Boolean))
(define-method-port
move-to-next-attribute?
System.Xml.XmlTextReader
MoveToNextAttribute
(System.Boolean))
(define-method-port
reset-state
System.Xml.XmlTextReader
ResetState
(System.Void))
(define-method-port
lookup-namespace
System.Xml.XmlTextReader
LookupNamespace
(System.String System.String))
(define-method-port
read-content-as-bin-hex
System.Xml.XmlTextReader
ReadContentAsBinHex
(System.Int32 System.Byte[] System.Int32 System.Int32))
(define-method-port
read-element-content-as-bin-hex
System.Xml.XmlTextReader
ReadElementContentAsBinHex
(System.Int32 System.Byte[] System.Int32 System.Int32))
(define-method-port
get-remainder
System.Xml.XmlTextReader
GetRemainder
(System.IO.TextReader))
(define-method-port
read-base64
System.Xml.XmlTextReader
ReadBase64
(System.Int32 System.Byte[] System.Int32 System.Int32))
(define-method-port
move-to-first-attribute?
System.Xml.XmlTextReader
MoveToFirstAttribute
(System.Boolean))
(define-method-port
read-string
System.Xml.XmlTextReader
ReadString
(System.String))
(define-method-port
get-attribute
System.Xml.XmlTextReader
GetAttribute
(System.String System.String System.String)
(System.String System.String)
(System.String System.Int32))
(define-method-port skip System.Xml.XmlTextReader Skip (System.Void))
(define-method-port
has-line-info?
System.Xml.XmlTextReader
HasLineInfo
(System.Boolean))
(define-method-port
resolve-entity
System.Xml.XmlTextReader
ResolveEntity
(System.Void))
(define-method-port
read-attribute-value?
System.Xml.XmlTextReader
ReadAttributeValue
(System.Boolean))
(define-method-port
read-chars
System.Xml.XmlTextReader
ReadChars
(System.Int32 System.Char[] System.Int32 System.Int32))
(define-method-port
read-content-as-base64
System.Xml.XmlTextReader
ReadContentAsBase64
(System.Int32 System.Byte[] System.Int32 System.Int32))
(define-method-port
move-to-attribute
System.Xml.XmlTextReader
MoveToAttribute
(System.Boolean System.String System.String)
(System.Boolean System.String)
(System.Void System.Int32))
(define-method-port
get-namespaces-in-scope
System.Xml.XmlTextReader
GetNamespacesInScope
("System.Collections.Generic.IDictionary`2[[System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]"
System.Xml.XmlNamespaceScope))
(define-method-port
read-bin-hex
System.Xml.XmlTextReader
ReadBinHex
(System.Int32 System.Byte[] System.Int32 System.Int32))
(define-method-port
read-element-content-as-base64
System.Xml.XmlTextReader
ReadElementContentAsBase64
(System.Int32 System.Byte[] System.Int32 System.Int32))
(define-method-port
move-to-element?
System.Xml.XmlTextReader
MoveToElement
(System.Boolean))
(define-method-port
close
System.Xml.XmlTextReader
Close
(System.Void))
(define-field-port
attribute-count
#f
#f
(property:)
System.Xml.XmlTextReader
AttributeCount
System.Int32)
(define-field-port
base-uri
#f
#f
(property:)
System.Xml.XmlTextReader
BaseURI
System.String)
(define-field-port
can-read-binary-content?
#f
#f
(property:)
System.Xml.XmlTextReader
CanReadBinaryContent
System.Boolean)
(define-field-port
can-read-value-chunk?
#f
#f
(property:)
System.Xml.XmlTextReader
CanReadValueChunk
System.Boolean)
(define-field-port
can-resolve-entity?
#f
#f
(property:)
System.Xml.XmlTextReader
CanResolveEntity
System.Boolean)
(define-field-port
depth
#f
#f
(property:)
System.Xml.XmlTextReader
Depth
System.Int32)
(define-field-port
eof?
#f
#f
(property:)
System.Xml.XmlTextReader
EOF
System.Boolean)
(define-field-port
has-value?
#f
#f
(property:)
System.Xml.XmlTextReader
HasValue
System.Boolean)
(define-field-port
is-default?
#f
#f
(property:)
System.Xml.XmlTextReader
IsDefault
System.Boolean)
(define-field-port
is-empty-element?
#f
#f
(property:)
System.Xml.XmlTextReader
IsEmptyElement
System.Boolean)
(define-field-port
local-name
#f
#f
(property:)
System.Xml.XmlTextReader
LocalName
System.String)
(define-field-port
name
#f
#f
(property:)
System.Xml.XmlTextReader
Name
System.String)
(define-field-port
namespace-uri
#f
#f
(property:)
System.Xml.XmlTextReader
NamespaceURI
System.String)
(define-field-port
name-table
#f
#f
(property:)
System.Xml.XmlTextReader
NameTable
System.Xml.XmlNameTable)
(define-field-port
node-type
#f
#f
(property:)
System.Xml.XmlTextReader
NodeType
System.Xml.XmlNodeType)
(define-field-port
prefix
#f
#f
(property:)
System.Xml.XmlTextReader
Prefix
System.String)
(define-field-port
quote-char
#f
#f
(property:)
System.Xml.XmlTextReader
QuoteChar
System.Char)
(define-field-port
read-state
#f
#f
(property:)
System.Xml.XmlTextReader
ReadState
System.Xml.ReadState)
(define-field-port
settings
#f
#f
(property:)
System.Xml.XmlTextReader
Settings
System.Xml.XmlReaderSettings)
(define-field-port
value
#f
#f
(property:)
System.Xml.XmlTextReader
Value
System.String)
(define-field-port
xml-lang
#f
#f
(property:)
System.Xml.XmlTextReader
XmlLang
System.String)
(define-field-port
xml-space
#f
#f
(property:)
System.Xml.XmlTextReader
XmlSpace
System.Xml.XmlSpace)
(define-field-port
encoding
#f
#f
(property:)
System.Xml.XmlTextReader
Encoding
System.Text.Encoding)
(define-field-port
entity-handling-get
entity-handling-set!
entity-handling-update!
(property:)
System.Xml.XmlTextReader
EntityHandling
System.Xml.EntityHandling)
(define-field-port
line-number
#f
#f
(property:)
System.Xml.XmlTextReader
LineNumber
System.Int32)
(define-field-port
line-position
#f
#f
(property:)
System.Xml.XmlTextReader
LinePosition
System.Int32)
(define-field-port
namespaces?-get
namespaces?-set!
namespaces?-update!
(property:)
System.Xml.XmlTextReader
Namespaces
System.Boolean)
(define-field-port
normalization?-get
normalization?-set!
normalization?-update!
(property:)
System.Xml.XmlTextReader
Normalization
System.Boolean)
(define-field-port
prohibit-dtd?-get
prohibit-dtd?-set!
prohibit-dtd?-update!
(property:)
System.Xml.XmlTextReader
ProhibitDtd
System.Boolean)
(define-field-port
whitespace-handling-get
whitespace-handling-set!
whitespace-handling-update!
(property:)
System.Xml.XmlTextReader
WhitespaceHandling
System.Xml.WhitespaceHandling)
(define-field-port
#f
xml-resolver
#f
(property:)
System.Xml.XmlTextReader
XmlResolver
System.Xml.XmlResolver))
| true |
b09f127a3285e38ba308f04c961298d99235add6 | 4b480cab3426c89e3e49554d05d1b36aad8aeef4 | /chapter-02/ex2.12-falsetru-test.scm | 583debdb8c69e3b1fd0cf0b1e33d30968560fc58 | []
| no_license | tuestudy/study-sicp | a5dc423719ca30a30ae685e1686534a2c9183b31 | a2d5d65e711ac5fee3914e45be7d5c2a62bfc20f | refs/heads/master | 2021-01-12T13:37:56.874455 | 2016-10-04T12:26:45 | 2016-10-04T12:26:45 | 69,962,129 | 0 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 570 | scm | ex2.12-falsetru-test.scm | (require (planet schematics/schemeunit:3))
(require (planet schematics/schemeunit:3/text-ui))
(load "ex2.12-falsetru.scm")
(define ex2.12-falsetru-tests
(test-suite
"Test for ex2.12-falsetru"
(test-case
"make-center-percent"
(define c 6.8)
(define p 10.0)
(define r (make-center-percent c p))
(check-= (lower-bound r) 6.12 0.000001)
(check-= (upper-bound r) 7.48 0.000001)
(check-= (center r) c 0.000001)
(check-= (percent r) p 0.000001)
)
))
(exit
(cond
((= (run-tests ex2.12-falsetru-tests) 0))
(else 1)))
| false |
19b79dcf79cd30a7304ba2eaf82083ca4ffb40be | f08220a13ec5095557a3132d563a152e718c412f | /logrotate/skel/usr/share/guile/2.0/ice-9/getopt-long.scm | 14eaf8e23bf0d03e1734876e6fb3a051e355cc61 | [
"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 | 16,888 | scm | getopt-long.scm | ;;; Copyright (C) 1998, 2001, 2006, 2009, 2011 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
;;; Author: Russ McManus (rewritten by Thien-Thi Nguyen)
;;; Commentary:
;;; This module implements some complex command line option parsing, in
;;; the spirit of the GNU C library function `getopt_long'. Both long
;;; and short options are supported.
;;;
;;; The theory is that people should be able to constrain the set of
;;; options they want to process using a grammar, rather than some arbitrary
;;; structure. The grammar makes the option descriptions easy to read.
;;;
;;; `getopt-long' is a procedure for parsing command-line arguments in a
;;; manner consistent with other GNU programs. `option-ref' is a procedure
;;; that facilitates processing of the `getopt-long' return value.
;;; (getopt-long ARGS GRAMMAR)
;;; Parse the arguments ARGS according to the argument list grammar GRAMMAR.
;;;
;;; ARGS should be a list of strings. Its first element should be the
;;; name of the program; subsequent elements should be the arguments
;;; that were passed to the program on the command line. The
;;; `program-arguments' procedure returns a list of this form.
;;;
;;; GRAMMAR is a list of the form:
;;; ((OPTION (PROPERTY VALUE) ...) ...)
;;;
;;; Each OPTION should be a symbol. `getopt-long' will accept a
;;; command-line option named `--OPTION'.
;;; Each option can have the following (PROPERTY VALUE) pairs:
;;;
;;; (single-char CHAR) --- Accept `-CHAR' as a single-character
;;; equivalent to `--OPTION'. This is how to specify traditional
;;; Unix-style flags.
;;; (required? BOOL) --- If BOOL is true, the option is required.
;;; getopt-long will raise an error if it is not found in ARGS.
;;; (value BOOL) --- If BOOL is #t, the option accepts a value; if
;;; it is #f, it does not; and if it is the symbol
;;; `optional', the option may appear in ARGS with or
;;; without a value.
;;; (predicate FUNC) --- If the option accepts a value (i.e. you
;;; specified `(value #t)' for this option), then getopt
;;; will apply FUNC to the value, and throw an exception
;;; if it returns #f. FUNC should be a procedure which
;;; accepts a string and returns a boolean value; you may
;;; need to use quasiquotes to get it into GRAMMAR.
;;;
;;; The (PROPERTY VALUE) pairs may occur in any order, but each
;;; property may occur only once. By default, options do not have
;;; single-character equivalents, are not required, and do not take
;;; values.
;;;
;;; In ARGS, single-character options may be combined, in the usual
;;; Unix fashion: ("-x" "-y") is equivalent to ("-xy"). If an option
;;; accepts values, then it must be the last option in the
;;; combination; the value is the next argument. So, for example, using
;;; the following grammar:
;;; ((apples (single-char #\a))
;;; (blimps (single-char #\b) (value #t))
;;; (catalexis (single-char #\c) (value #t)))
;;; the following argument lists would be acceptable:
;;; ("-a" "-b" "bang" "-c" "couth") ("bang" and "couth" are the values
;;; for "blimps" and "catalexis")
;;; ("-ab" "bang" "-c" "couth") (same)
;;; ("-ac" "couth" "-b" "bang") (same)
;;; ("-abc" "couth" "bang") (an error, since `-b' is not the
;;; last option in its combination)
;;;
;;; If an option's value is optional, then `getopt-long' decides
;;; whether it has a value by looking at what follows it in ARGS. If
;;; the next element is does not appear to be an option itself, then
;;; that element is the option's value.
;;;
;;; The value of a long option can appear as the next element in ARGS,
;;; or it can follow the option name, separated by an `=' character.
;;; Thus, using the same grammar as above, the following argument lists
;;; are equivalent:
;;; ("--apples" "Braeburn" "--blimps" "Goodyear")
;;; ("--apples=Braeburn" "--blimps" "Goodyear")
;;; ("--blimps" "Goodyear" "--apples=Braeburn")
;;;
;;; If the option "--" appears in ARGS, argument parsing stops there;
;;; subsequent arguments are returned as ordinary arguments, even if
;;; they resemble options. So, in the argument list:
;;; ("--apples" "Granny Smith" "--" "--blimp" "Goodyear")
;;; `getopt-long' will recognize the `apples' option as having the
;;; value "Granny Smith", but it will not recognize the `blimp'
;;; option; it will return the strings "--blimp" and "Goodyear" as
;;; ordinary argument strings.
;;;
;;; The `getopt-long' function returns the parsed argument list as an
;;; assocation list, mapping option names --- the symbols from GRAMMAR
;;; --- onto their values, or #t if the option does not accept a value.
;;; Unused options do not appear in the alist.
;;;
;;; All arguments that are not the value of any option are returned
;;; as a list, associated with the empty list.
;;;
;;; `getopt-long' throws an exception if:
;;; - it finds an unrecognized property in GRAMMAR
;;; - the value of the `single-char' property is not a character
;;; - it finds an unrecognized option in ARGS
;;; - a required option is omitted
;;; - an option that requires an argument doesn't get one
;;; - an option that doesn't accept an argument does get one (this can
;;; only happen using the long option `--opt=value' syntax)
;;; - an option predicate fails
;;;
;;; So, for example:
;;;
;;; (define grammar
;;; `((lockfile-dir (required? #t)
;;; (value #t)
;;; (single-char #\k)
;;; (predicate ,file-is-directory?))
;;; (verbose (required? #f)
;;; (single-char #\v)
;;; (value #f))
;;; (x-includes (single-char #\x))
;;; (rnet-server (single-char #\y)
;;; (predicate ,string?))))
;;;
;;; (getopt-long '("my-prog" "-vk" "/tmp" "foo1" "--x-includes=/usr/include"
;;; "--rnet-server=lamprod" "--" "-fred" "foo2" "foo3")
;;; grammar)
;;; => ((() "foo1" "-fred" "foo2" "foo3")
;;; (rnet-server . "lamprod")
;;; (x-includes . "/usr/include")
;;; (lockfile-dir . "/tmp")
;;; (verbose . #t))
;;; (option-ref OPTIONS KEY DEFAULT)
;;; Return value in alist OPTIONS using KEY, a symbol; or DEFAULT if not
;;; found. The value is either a string or `#t'.
;;;
;;; For example, using the `getopt-long' return value from above:
;;;
;;; (option-ref (getopt-long ...) 'x-includes 42) => "/usr/include"
;;; (option-ref (getopt-long ...) 'not-a-key! 31) => 31
;;; Code:
(define-module (ice-9 getopt-long)
#:use-module ((ice-9 common-list) #:select (remove-if-not))
#:use-module (srfi srfi-9)
#:use-module (ice-9 match)
#:use-module (ice-9 regex)
#:use-module (ice-9 optargs)
#:export (getopt-long option-ref))
(define %program-name (make-fluid "guile"))
(define (program-name)
(fluid-ref %program-name))
(define (fatal-error fmt . args)
(format (current-error-port) "~a: " (program-name))
(apply format (current-error-port) fmt args)
(newline (current-error-port))
(exit 1))
(define-record-type option-spec
(%make-option-spec name required? option-spec->single-char predicate value-policy)
option-spec?
(name
option-spec->name set-option-spec-name!)
(required?
option-spec->required? set-option-spec-required?!)
(option-spec->single-char
option-spec->single-char set-option-spec-single-char!)
(predicate
option-spec->predicate set-option-spec-predicate!)
(value-policy
option-spec->value-policy set-option-spec-value-policy!))
(define (make-option-spec name)
(%make-option-spec name #f #f #f #f))
(define (parse-option-spec desc)
(let ((spec (make-option-spec (symbol->string (car desc)))))
(for-each (match-lambda
(('required? val)
(set-option-spec-required?! spec val))
(('value val)
(set-option-spec-value-policy! spec val))
(('single-char val)
(or (char? val)
(error "`single-char' value must be a char!"))
(set-option-spec-single-char! spec val))
(('predicate pred)
(set-option-spec-predicate!
spec (lambda (name val)
(or (not val)
(pred val)
(fatal-error "option predicate failed: --~a"
name)))))
((prop val)
(error "invalid getopt-long option property:" prop)))
(cdr desc))
spec))
(define (split-arg-list argument-list)
;; Scan ARGUMENT-LIST for "--" and return (BEFORE-LS . AFTER-LS).
;; Discard the "--". If no "--" is found, AFTER-LS is empty.
(let loop ((yes '()) (no argument-list))
(cond ((null? no) (cons (reverse yes) no))
((string=? "--" (car no)) (cons (reverse yes) (cdr no)))
(else (loop (cons (car no) yes) (cdr no))))))
(define short-opt-rx (make-regexp "^-([a-zA-Z]+)(.*)"))
(define long-opt-no-value-rx (make-regexp "^--([^=]+)$"))
(define long-opt-with-value-rx (make-regexp "^--([^=]+)=(.*)"))
(define (looks-like-an-option string)
(or (regexp-exec short-opt-rx string)
(regexp-exec long-opt-with-value-rx string)
(regexp-exec long-opt-no-value-rx string)))
(define (process-options specs argument-ls stop-at-first-non-option)
;; Use SPECS to scan ARGUMENT-LS; return (FOUND . ETC).
;; FOUND is an unordered list of option specs for found options, while ETC
;; is an order-maintained list of elements in ARGUMENT-LS that are neither
;; options nor their values.
(let ((idx (map (lambda (spec)
(cons (option-spec->name spec) spec))
specs))
(sc-idx (map (lambda (spec)
(cons (make-string 1 (option-spec->single-char spec))
spec))
(remove-if-not option-spec->single-char specs))))
(let loop ((unclumped 0) (argument-ls argument-ls) (found '()) (etc '()))
(define (eat! spec ls)
(cond
((eq? 'optional (option-spec->value-policy spec))
(if (or (null? ls)
(looks-like-an-option (car ls)))
(loop (- unclumped 1) ls (acons spec #t found) etc)
(loop (- unclumped 2) (cdr ls) (acons spec (car ls) found) etc)))
((eq? #t (option-spec->value-policy spec))
(if (or (null? ls)
(looks-like-an-option (car ls)))
(fatal-error "option must be specified with argument: --~a"
(option-spec->name spec))
(loop (- unclumped 2) (cdr ls) (acons spec (car ls) found) etc)))
(else
(loop (- unclumped 1) ls (acons spec #t found) etc))))
(match argument-ls
(()
(cons found (reverse etc)))
((opt . rest)
(cond
((regexp-exec short-opt-rx opt)
=> (lambda (match)
(if (> unclumped 0)
;; Next option is known not to be clumped.
(let* ((c (match:substring match 1))
(spec (or (assoc-ref sc-idx c)
(fatal-error "no such option: -~a" c))))
(eat! spec rest))
;; Expand a clumped group of short options.
(let* ((extra (match:substring match 2))
(unclumped-opts
(append (map (lambda (c)
(string-append "-" (make-string 1 c)))
(string->list
(match:substring match 1)))
(if (string=? "" extra) '() (list extra)))))
(loop (length unclumped-opts)
(append unclumped-opts rest)
found
etc)))))
((regexp-exec long-opt-no-value-rx opt)
=> (lambda (match)
(let* ((opt (match:substring match 1))
(spec (or (assoc-ref idx opt)
(fatal-error "no such option: --~a" opt))))
(eat! spec rest))))
((regexp-exec long-opt-with-value-rx opt)
=> (lambda (match)
(let* ((opt (match:substring match 1))
(spec (or (assoc-ref idx opt)
(fatal-error "no such option: --~a" opt))))
(if (option-spec->value-policy spec)
(eat! spec (cons (match:substring match 2) rest))
(fatal-error "option does not support argument: --~a"
opt)))))
((and stop-at-first-non-option
(<= unclumped 0))
(cons found (append (reverse etc) argument-ls)))
(else
(loop (- unclumped 1) rest found (cons opt etc)))))))))
(define* (getopt-long program-arguments option-desc-list
#:key stop-at-first-non-option)
"Process options, handling both long and short options, similar to
the glibc function 'getopt_long'. PROGRAM-ARGUMENTS should be a value
similar to what (program-arguments) returns. OPTION-DESC-LIST is a
list of option descriptions. Each option description must satisfy the
following grammar:
<option-spec> :: (<name> . <attribute-ls>)
<attribute-ls> :: (<attribute> . <attribute-ls>)
| ()
<attribute> :: <required-attribute>
| <arg-required-attribute>
| <single-char-attribute>
| <predicate-attribute>
| <value-attribute>
<required-attribute> :: (required? <boolean>)
<single-char-attribute> :: (single-char <char>)
<value-attribute> :: (value #t)
(value #f)
(value optional)
<predicate-attribute> :: (predicate <1-ary-function>)
The procedure returns an alist of option names and values. Each
option name is a symbol. The option value will be '#t' if no value
was specified. There is a special item in the returned alist with a
key of the empty list, (): the list of arguments that are not options
or option values.
By default, options are not required, and option values are not
required. By default, single character equivalents are not supported;
if you want to allow the user to use single character options, you need
to add a `single-char' clause to the option description."
(with-fluids ((%program-name (car program-arguments)))
(let* ((specifications (map parse-option-spec option-desc-list))
(pair (split-arg-list (cdr program-arguments)))
(split-ls (car pair))
(non-split-ls (cdr pair))
(found/etc (process-options specifications split-ls
stop-at-first-non-option))
(found (car found/etc))
(rest-ls (append (cdr found/etc) non-split-ls)))
(for-each (lambda (spec)
(let ((name (option-spec->name spec))
(val (assq-ref found spec)))
(and (option-spec->required? spec)
(or val
(fatal-error "option must be specified: --~a"
name)))
(let ((pred (option-spec->predicate spec)))
(and pred (pred name val)))))
specifications)
(for-each (lambda (spec+val)
(set-car! spec+val
(string->symbol (option-spec->name (car spec+val)))))
found)
(cons (cons '() rest-ls) found))))
(define (option-ref options key default)
"Return value in alist OPTIONS using KEY, a symbol; or DEFAULT if not found.
The value is either a string or `#t'."
(or (assq-ref options key) default))
;;; getopt-long.scm ends here
| false |
7ba6e5774030b5619a209a4f24add8a3c7b6c972 | ece1c4300b543df96cd22f63f55c09143989549c | /Chapter1/Exercise 1.09.scm | a5727964703a4eff184764b8f7fcc2c7eb521b32 | []
| no_license | candlc/SICP | e23a38359bdb9f43d30715345fca4cb83a545267 | 1c6cbf5ecf6397eaeb990738a938d48c193af1bb | refs/heads/master | 2022-03-04T02:55:33.594888 | 2019-11-04T09:11:34 | 2019-11-04T09:11:34 | null | 0 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 693 | scm | Exercise 1.09.scm | #lang planet neil/sicp
; Each of the following two procedures defines a method for adding two positive
; integers in terms of the procedures inc, which increments its argument by 1,
; and dec, which decrements its argument by 1.
(define (+ a b)
(if (= a 0)
b
(inc (+ (dec a) b))))
(define (+ a b)
(if (= a 0)
b
(+ (dec a) (inc b))))
; Using the substitution model, illustrate the process generated by each procedure in evaluating (+ 4 5). Are these processes iterative or recursive?
the first one is recursive, because the status of in each evaluating is not given, because you need to do a inc on the containing (+) procedure result.
where as the second one is | false |
c3480fbc7f78997f0e1d7a02f600b81a4e672efe | 6b675e55991fdcfc249da935e3ff15ba62e0f2ed | /light.ss | 647208b261c98d661aa0677e72bc22bbac70046e | []
| no_license | mrmathematica/MrMathematica | a0addbab10561e6edd1c14adf6c44fe51b8d9f03 | 801cd29e1e4ac57a71e86fa0f4b750a60068c75d | refs/heads/master | 2021-06-22T09:56:52.409291 | 2020-12-30T11:46:02 | 2020-12-30T11:46:02 | 12,832,108 | 8 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 5,613 | ss | light.ss | #lang racket/base
(require "mathlink.ss"
"translation.ss"
racket/contract
ffi/unsafe/custodian)
(provide/contract (MathKernel
(-> string? ... MathLink?))
(MathEval
(->* ((flat-rec-contract Mexp
number? boolean? symbol? string? void? eof-object?
(vectorof Mexp #:flat? #t)
(cons/c Mexp (listof Mexp))))
(MathLink?)
any))
(MathExit
(->* () (MathLink?) any))
(current-mathlink
(parameter/c (or/c false/c MathLink?))))
(provide MathLink?
(struct-out exn:fail:mathlink))
(define current-mathlink
(make-parameter #f))
(define flush-input
(let ([buf (make-bytes 64)])
(lambda ()
(do ()
((zero? (read-bytes-avail!* buf)))))))
(define (MLPutSymbol lp sym)
(let* ((str (symbol->string sym))
(lst (string->list str)))
(if (and (not (null? lst))
(or (char-alphabetic? (car lst))
(char=? (car lst) #\$))
(andmap (lambda (c)
(or (char-alphabetic? c)
(char=? c #\$)
(char-numeric? c)))
(cdr lst)))
(MLPutNext lp 35)
(MLPutFunction lp #"Symbol" 1))
(MLPutString lp str)))
(define (MLPutNumber lp num)
(if (real? num)
(if (exact? num)
(if (integer? num)
(and (MLPutNext lp 43)
(MLPutString lp (number->string num)))
(and (MLPutFunction lp #"Rational" 2)
(MLPutNumber lp (numerator num))
(MLPutNumber lp (denominator num))))
(MLPutReal lp num))
(and (MLPutFunction lp #"Complex" 2)
(MLPutNumber lp (real-part num))
(MLPutNumber lp (imag-part num)))))
(define (MLGetReal lp)
(string->number
(regexp-replace #rx"\\*|\\^"
(regexp-replace #rx"(\nul|\\`)[^(e|\\^)]*"
(MLGetString lp)
"")
"e")))
(define (MLPut lp exp)
(cond ((boolean? exp)
(MLPutSymbol lp (if exp 'True 'False)))
((number? exp)
(MLPutNumber lp exp))
((symbol? exp)
(MLPutSymbol lp exp))
((string? exp)
(MLPutString lp exp))
((void? exp)
(MLPutSymbol lp 'Null))
((eof-object? exp)
(MLPutSymbol lp 'EndOfFile))
((vector? exp)
(MLPutFunction lp #"List" (vector-length exp))
(andmap (lambda (arg) (MLPut lp arg)) (vector->list exp)))
(else
(let ((mexp (Scheme->Mathematica exp)))
(MLPutNext lp 70)
(MLPutArgCount lp (sub1 (length mexp)))
(andmap (lambda (arg) (MLPut lp arg)) mexp)))))
(define (MLGet lp)
(with-handlers ((exn:break?
(lambda _ (MLPutMessage lp 3))))
(MLWait lp))
(unless (zero? (MLError lp))
(mathlink-error (MLErrorMessage lp)))
(case (MLNextPacket lp)
((0)
(unless (MLClearError lp)
(mathlink-error "MathEval: MathLink fatal error"))
(MLNewPacket lp)
(MLGet lp))
((1)
(display (MLGetString lp))
(flush-input)
(MLPut lp (read))
(MLGet lp))
((2)
(display (MLGetString lp))
(MLNewPacket lp)
(MLGet lp))
((3)
(MLGetExp lp))
((5)
(MLNewPacket lp)
(MLNextPacket lp)
(displayln (MLGetString lp) (current-error-port))
(MLNewPacket lp)
(MLGet lp))
((21)
(display (MLGetString lp))
(flush-input)
(MLPut lp (read-line))
(MLNewPacket lp)
(MLGet lp))
(else
(MLNewPacket lp)
(MLGet lp))))
(define (MLGetExp lp)
(case (MLGetNext lp)
((35)
(let ((sym (string->symbol (MLGetString lp))))
(case sym
((True) #t)
((False) #f)
((Null) (void))
((Indeterminate) +nan.0)
((EndOfFile) eof)
(else sym))))
((34)
(MLGetString lp))
((43)
(string->number (MLGetString lp)))
((42)
(MLGetReal lp))
((70)
(Mathematica->Scheme
(build-list (add1 (MLGetArgCount lp))
(lambda _ (MLGetExp lp)))))))
(define MathKernel
(case-lambda
(()
(MathKernel "-linkname"
(case (system-type 'os)
((unix)
"math -mathlink")
((windows)
"MathKernel -mathlink")
((macosx)
"/Applications/Mathematica.app/Contents/MacOS/MathKernel -mathlink"))))
(arg
(let ((link (apply MLOpen arg)))
(register-finalizer-and-custodian-shutdown link MLClose #:at-exit? #t)
(current-mathlink link)
link))))
(define (MathEval exp (link (or (current-mathlink) (MathKernel))))
(call-with-semaphore (MathLink-sema link)
(lambda ()
(let ((lp (MathLink-lp link)))
(unless lp
(mathlink-error "MathEval: MathLink is closed"))
(MLPutFunction lp #"EvaluatePacket" 1)
(MLPut lp exp)
(MLEndPacket lp)
(MLGet lp)))))
(define MathExit
(case-lambda
(()
(cond ((current-mathlink) => MathExit)))
((link)
(when (eq? link (current-mathlink))
(current-mathlink #f))
(MLClose link))))
| false |
9d160a03100beec53d318bdfcc67d86269766d89 | bf1c9803ae38f9aad027fbe4569ccc6f85ba63ab | /chapter_2/2.3.Symbolic.Data/ex_2.61.scm | 692935248ef1bb3af42cea8e810d8b3ad74d3d0c | []
| 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 | 559 | scm | ex_2.61.scm | #lang sicp
;; Imports
(define (element-of-set? x set)
(cond ((null? set) false)
((= x (car set)) true)
((< x (car set)) false)
(else (element-of-set? x (cdr set)))))
;; Implementation
(define (adjoin-set x set)
(cond
((null? set) (list x))
((= (car set) x) set)
((> (car set) x) (cons x set))
(else
(cons (car set) (adjoin-set x (cdr set)))
)))
(adjoin-set 1 '()) ; ✔
(adjoin-set 1 '(1 2 3 4)) ; ✔
(adjoin-set 1 '(2 3 4)) ; ✔
(adjoin-set 9 '(1 2 3)) ; ✔
(adjoin-set 4 '(1 2 3 5 6)) ; ✔
| false |
7878d45edecff9037165686339226f601175d504 | 8e15d5c1ed79e956f5f3a780daf64e57ba8fa0cb | /math/operators.scm | ffe0a26dffe4c59279cfa615245fa4facf4b5de3 | [
"Zlib"
]
| permissive | pbui/omg | 10602d73dab66cb69f4c24a543f3ffd91cb707e3 | b7e9011643c301eb5eaae560b980ffe5b764e173 | refs/heads/master | 2020-07-06T06:10:16.247249 | 2016-11-17T18:34:38 | 2016-11-17T18:34:38 | 74,056,007 | 0 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 2,577 | scm | operators.scm | ;------------------------------------------------------------------------------
; $Id: operators.scm,v 1.1 2005/08/10 19:06:09 pbui Exp pbui $
;------------------------------------------------------------------------------
#|
Copyright (c) Peter Bui. All Rights Reserved.
For specific licensing information, please consult the COPYING file that comes
with the software distribution. If it is missing, please contact the author at
[email protected].
|#
;------------------------------------------------------------------------------
(define-module omg.math.operators
(export-all))
(select-module omg.math.operators)
;------------------------------------------------------------------------------
; Math Operators
;------------------------------------------------------------------------------
#|
Function: inc number &optional delta
This increments the number by specified delta. The default delta is 1.
Example:
(use omg.math.operators)
(inc 0) => 1
(inc 0 5) => 5
|#
(define (inc number . opts)
(let-optionals* opts ((delta 1))
(+ number delta)))
;------------------------------------------------------------------------------
#|
Function: dec number &optional delta
This decrements the number by specified delta. The default delta is 1.
Example:
(use omg.math.operators)
(dec 0) => -1
(dec 0 5) => -5
|#
(define (dec number . opts)
(let-optionals* opts ((delta 1))
(- number delta)))
;------------------------------------------------------------------------------
#|
Function: double number
This doubles the number.
Example:
(use omg.math.operators)
(double 1) => 2
|#
(define (double number)
(* number 2))
;------------------------------------------------------------------------------
#|
Function: triple number
This triples the number.
Example:
(use omg.math.operators)
(triple 1) => 3
|#
(define (triple number)
(* number 3))
;------------------------------------------------------------------------------
#|
Function: half number
This halves the number.
Example:
(use omg.math.operators)
(half 1) => 1/2
|#
(define (half number)
(/ number 2))
;------------------------------------------------------------------------------
#|
Function: neg number
This negates the number.
Example:
(use omg.math.operators)
(neg 1) => -1
|#
(define (neg number)
(* number -1))
;------------------------------------------------------------------------------
(provide "omg/math/operators")
;------------------------------------------------------------------------------
| false |
77432ff18c282fbc190fa571ea99b2bdd8874af1 | 67deea161869ba3cf87d6ce272cd8435fe0476d3 | /srfi-197.scm | 440b07f1d06e34fd40ed97f5d5d9e83fbff8ba43 | [
"MIT"
]
| permissive | ar-nelson/srfi-197 | a421bce6fb75d010a39138f1c625cf29a5aa3851 | 78ced23a1af519ee2969939138b3ffff442f339a | refs/heads/master | 2022-12-10T20:20:42.911518 | 2020-09-06T20:40:47 | 2020-09-06T20:58:22 | 270,520,963 | 8 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 9,583 | scm | srfi-197.scm |
(define-syntax chain
(syntax-rules …₁ ()
((_ initial-value) initial-value)
((_ initial-value (step …₁) …₁)
(chain initial-value _ ... (step …₁) …₁))
((_ initial-value placeholder (step …₁) …₁)
(chain initial-value placeholder ... (step …₁) …₁))
((_ initial-value placeholder ellipsis (first-step …₁) (next-step …₁) …₁)
(let ()
(define-syntax %chain
(syntax-rules …₂ (placeholder ellipsis)
; (_ in-step out-step in-vars out-vars in-steps out-steps)
((_ () () () ((var) …₂) () (step …₂ last-step))
(let* ((var step) …₂) last-step))
((_ () () () (vars …₂) () (step …₂ last-step))
(let*-values ((vars step) …₂) last-step))
((_ () () () out-vars (step . in-steps) out-steps)
(%chain step () () out-vars in-steps out-steps))
((_ () step () (out-vars …₂) in-steps (out-steps …₂))
(%chain () () () (out-vars …₂ ignored) in-steps (out-steps …₂ step)))
((_ () step vars (out-vars …₂) in-steps (out-steps …₂))
(%chain () () () (out-vars …₂ vars) in-steps (out-steps …₂ step)))
((_ (placeholder ellipsis) (step …₂) () (out-vars …₂) in-steps (out-steps …₂))
(%chain () () () (out-vars …₂ chain-rest-var) in-steps (out-steps …₂ (apply step …₂ chain-rest-var))))
((_ (placeholder ellipsis) (step …₂) (vars …₂) (out-vars …₂) in-steps (out-steps …₂))
(%chain () () () (out-vars …₂ (vars …₂ . chain-rest-var)) in-steps (out-steps …₂ (apply step …₂ chain-rest-var))))
((_ (placeholder ellipsis . rest) . _)
(syntax-error "_ ... can only be used as a final argument"))
((_ (placeholder . in-step) (out-step …₂) (vars …₂) . rest)
(%chain in-step (out-step …₂ chain-var) (vars …₂ chain-var) . rest))
((_ (x . in-step) (out-step …₂) . rest)
(%chain in-step (out-step …₂ x) . rest))))
(%chain (first-step …₁) () () () ((next-step …₁) …₁) (initial-value))))))
(define-syntax chain-and
(syntax-rules …₁ ()
((_ initial-value) initial-value)
((_ initial-value (step …₁) …₁) (chain-and initial-value _ (step …₁) …₁))
((_ initial-value placeholder (first-step …₁) (next-step …₁) …₁)
(let ()
(define-syntax %chain-and
(syntax-rules …₂ (placeholder)
; (_ in-step out-step in-vars out-vars in-steps out-steps)
((_ () () () (var …₂) () (step …₂ last-step))
(and-let* ((var step) …₂) last-step))
((_ () () () out-vars (step . in-steps) out-steps)
(%chain-and step () () out-vars in-steps out-steps))
((_ () step () (out-vars …₂) in-steps (out-steps …₂))
(%chain-and () () () (out-vars …₂ ignored) in-steps (out-steps …₂ step)))
((_ () step (var) (out-vars …₂) in-steps (out-steps …₂))
(%chain-and () () () (out-vars …₂ var) in-steps (out-steps …₂ step)))
((_ (placeholder . in-step) (out-step …₂) () . rest)
(%chain-and in-step (out-step …₂ chain-var) (chain-var) . rest))
((_ (placeholder . excess) . rest)
(syntax-error "chain-and does not support multiple _ in a single step"))
((_ (x . in-step) (out-step …₂) . rest)
(%chain-and in-step (out-step …₂ x) . rest))))
(%chain-and (first-step …₁) () () () ((next-step …₁) …₁) (initial-value))))))
(define-syntax chain-when
(syntax-rules …₁ ()
((_ initial-value) initial-value)
((_ initial-value (guard? (step …₁)) …₁)
(chain-when initial-value _ (guard? (step …₁)) …₁))
((_ initial-value placeholder (first-guard? (first-step …₁)) (next-guard? (next-step …₁)) …₁)
(let ()
(define-syntax %chain-when
(syntax-rules …₂ (placeholder)
; (_ in-step out-step guard? chain-var in-steps out-expr)
((_ () () _1 _2 () out-expr) out-expr)
((_ () () _1 _2 ((guard? step) . in-steps) out-expr)
(%chain-when step () guard? #f in-steps out-expr))
((_ () step guard? #f in-steps out-expr)
(%chain-when () () #f #f in-steps
(let ((chain-var out-expr))
(if guard? step chain-var))))
((_ () step guard? chain-var in-steps out-expr)
(%chain-when () () #f #f in-steps
(let ((chain-var out-expr))
(if guard? step chain-var))))
((_ (placeholder . in-step) (out-step …₂) guard? #f . rest)
(%chain-when in-step (out-step …₂ chain-var) guard? chain-var . rest))
((_ (placeholder . excess) . rest)
(syntax-error "chain-when does not support multiple _ in a single step"))
((_ (x . in-step) (out-step …₂) . rest)
(%chain-when in-step (out-step …₂ x) . rest))))
(%chain-when (first-step …₁) () first-guard? #f ((next-guard? (next-step …₁)) …₁) initial-value)))))
(define-syntax chain-lambda
(syntax-rules …₁ ()
((_ (step …₁) …₁) (chain-lambda _ ... (step …₁) …₁))
((_ placeholder (step …₁) …₁) (chain-lambda placeholder ... (step …₁) …₁))
((_ placeholder ellipsis (first-step …₁) (next-step …₁) …₁)
(let ()
(define-syntax %chain-lambda
(syntax-rules …₂ (placeholder ellipsis)
; (_ in-step out-step args rest-of-steps)
((_ () step args ())
(lambda args step))
((_ () step args steps)
(lambda args
(chain step placeholder ellipsis . steps)))
((_ (placeholder ellipsis) (step …₂) () ())
(lambda chain-rest-var (apply step …₂ chain-rest-var)))
((_ (placeholder ellipsis) (step …₂) () steps)
(lambda chain-rest-var
(chain (apply step …₂ chain-rest-var) placeholder ellipsis . steps)))
((_ (placeholder ellipsis) (step …₂) (args …₂) ())
(lambda (args …₂ . chain-rest-var) (apply step …₂ chain-rest-var)))
((_ (placeholder ellipsis) (step …₂) (args …₂) steps)
(lambda (args …₂ . chain-rest-var)
(chain (apply step …₂ chain-rest-var) placeholder ellipsis . steps)))
((_ (placeholder ellipsis . excess) . rest)
(syntax-error "_ ... can only be used as a final argument"))
((_ (placeholder . in-step) (out-step …₂) (args …₂) . rest)
(%chain-lambda in-step (out-step …₂ chain-var) (args …₂ chain-var) . rest))
((_ (x . in-step) (out-step …₂) . rest)
(%chain-lambda in-step (out-step …₂ x) . rest))))
(%chain-lambda (first-step …₁) () () ((next-step …₁) …₁))))))
(define-syntax nest
(syntax-rules …₁ (_)
((nest last) last)
((nest (step …₁) …₁ last) (nest _ (step …₁) …₁ last))
((nest placeholder (extra-step …₁) …₁ (first-step …₁) last)
(let ()
; let-syntax is buggy in some Schemes, define-syntax is more reliable
(define-syntax %nest
(syntax-rules …₂ (placeholder)
((%nest result () placeholder ()) result)
((%nest result () placeholder (rest …₂ step))
(%nest () step result (rest …₂)))
((%nest result () accum steps)
(syntax-error "nest: step must contain _"))
((%nest result (placeholder . rest) placeholder steps)
(syntax-error "nest: only one _ allowed per step"))
((%nest (result …₂) (placeholder . rest) accum steps)
(%nest (result …₂ accum) rest placeholder steps))
((%nest (result …₂) (element . rest) accum steps)
(%nest (result …₂ element) rest accum steps))))
(%nest () (first-step …₁) last ((extra-step …₁) …₁))))
((nest placeholder last) last)))
(define-syntax nest-reverse
(syntax-rules …₁ (_)
((nest-reverse first) first)
((nest-reverse first (step …₁) …₁) (nest-reverse first _ (step …₁) …₁))
((nest-reverse first placeholder (first-step …₁) (extra-step …₁) …₁)
(let ()
(define-syntax %nest
(syntax-rules …₂ (placeholder)
((%nest result () placeholder ()) result)
((%nest result () placeholder (step . rest))
(%nest () step result rest))
((%nest result () accum steps)
(syntax-error "nest-reverse: step must contain _"))
((%nest result (placeholder . rest) placeholder steps)
(syntax-error "nest-reverse: only one _ allowed per step"))
((%nest (result …₂) (placeholder . rest) accum steps)
(%nest (result …₂ accum) rest placeholder steps))
((%nest (result …₂) (element . rest) accum steps)
(%nest (result …₂ element) rest accum steps))))
(%nest () (first-step …₁) first ((extra-step …₁) …₁))))
((nest-reverse first placeholder) first)))
| true |
a319eca0860ccf7c14baeb08541a1adc1065fbb7 | 000dbfe5d1df2f18e29a76ea7e2a9556cff5e866 | /ext/crypto/sagittarius/crypto/mac/hmac.scm | acbdc64bc4e8dc114f76ae0ca94f2d2dfc0be555 | [
"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,006 | scm | hmac.scm | ;;; -*- mode:scheme; coding:utf-8; -*-
;;;
;;; sagittarius/crypto/mac/hmac.scm - HMAC
;;;
;;; 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.
;;;
#!nounbound
(library (sagittarius crypto mac hmac)
(export *mac:hmac*
hmac-oid->digest-oid
digest-oid->hmac-oid
*oid-hmac/md5*
*oid-hmac/tiger*
*oid-hmac/ripemd-160*
*oid-hmac/sha1*
*oid-hmac/sha224*
*oid-hmac/sha256*
*oid-hmac/sha384*
*oid-hmac/sha512*
*oid-hmac/sha512/224*
*oid-hmac/sha512/256*
*oid-hmac/sha3-224*
*oid-hmac/sha3-256*
*oid-hmac/sha3-384*
*oid-hmac/sha3-512*)
(import (rnrs)
(clos user)
(sagittarius crypto mac types)
(rename (sagittarius crypto digests descriptors)
(tc-digest-descriptor? builtin-digest-descriptor?))
(prefix (sagittarius crypto tomcrypt) tc:))
(define *mac:hmac* :hmac)
(define-method mac-state-initializer ((m (eql *mac:hmac*)) (key <bytevector>)
:key ((digest builtin-digest-descriptor?) #f)
:allow-other-keys)
(values (lambda () (tc:hmac-init (tc-digest-descriptor-digest digest) key))
(digest-descriptor-digest-size digest)
(digest-oid->hmac-oid (digest-descriptor-oid digest))))
(define-method mac-state-processor ((s (eql *mac:hmac*))) tc:hmac-process!)
(define-method mac-state-finalizer ((s (eql *mac:hmac*))) tc:hmac-done!)
(define *oid-hmac/md5* "1.3.6.1.5.5.8.1.1")
(define *oid-hmac/tiger* "1.2.840.113549.2.3")
(define *oid-hmac/ripemd-160* "1.3.6.1.5.5.8.1.4")
(define *oid-hmac/sha1* "1.2.840.113549.2.7")
(define *oid-hmac/sha224* "1.2.840.113549.2.8")
(define *oid-hmac/sha256* "1.2.840.113549.2.9")
(define *oid-hmac/sha384* "1.2.840.113549.2.10")
(define *oid-hmac/sha512* "1.2.840.113549.2.11")
(define *oid-hmac/sha512/224* "1.2.840.113549.2.12")
(define *oid-hmac/sha512/256* "1.2.840.113549.2.13")
(define *oid-hmac/sha3-224* "2.16.840.1.101.3.4.2.13")
(define *oid-hmac/sha3-256* "2.16.840.1.101.3.4.2.14")
(define *oid-hmac/sha3-384* "2.16.840.1.101.3.4.2.15")
(define *oid-hmac/sha3-512* "2.16.840.1.101.3.4.2.16")
(define *digest-oid->hmac-oid-map*
`((,(digest-descriptor-oid *digest:md5*) . ,*oid-hmac/md5*)
;; This is old
;; (,(digest-descriptor-oid *digest:sha-1*) . "1.3.6.1.5.5.8.1.2")
(,(digest-descriptor-oid *digest:tiger-192*) . ,*oid-hmac/tiger*)
(,(digest-descriptor-oid *digest:ripemd-160*) . ,*oid-hmac/ripemd-160*)
;; PKCS#5 HMAC OIDs
(,(digest-descriptor-oid *digest:sha-1*) . ,*oid-hmac/sha1*)
(,(digest-descriptor-oid *digest:sha-224*) . ,*oid-hmac/sha224*)
(,(digest-descriptor-oid *digest:sha-256*) . ,*oid-hmac/sha256*)
(,(digest-descriptor-oid *digest:sha-384*) . ,*oid-hmac/sha384*)
(,(digest-descriptor-oid *digest:sha-512*) . ,*oid-hmac/sha512*)
(,(digest-descriptor-oid *digest:sha-512/224*) . ,*oid-hmac/sha512/224*)
(,(digest-descriptor-oid *digest:sha-512/256*) . ,*oid-hmac/sha512/256*)
(,(digest-descriptor-oid *digest:sha3-224*) . ,*oid-hmac/sha3-224*)
(,(digest-descriptor-oid *digest:sha3-256*) . ,*oid-hmac/sha3-256*)
(,(digest-descriptor-oid *digest:sha3-384*) . ,*oid-hmac/sha3-384*)
(,(digest-descriptor-oid *digest:sha3-512*) . ,*oid-hmac/sha3-512*)
))
(define *hmac-oid->digest-oid-map*
(map (lambda (a) (cons (cdr a) (car a))) *digest-oid->hmac-oid-map*))
(define (digest-oid->hmac-oid oid)
(cond ((assoc oid *digest-oid->hmac-oid-map*) => cdr)
(else #f)))
(define (hmac-oid->digest-oid oid)
(cond ((assoc oid *hmac-oid->digest-oid-map*) => cdr)
(else #f)))
)
| false |
36da1f774f58d19af050d87e12a25be633134a43 | a70301d352dcc9987daf2bf12919aecd66defbd8 | /mredtalk3/accounting.ss | f8fd877f0d830ddf83599ac9644940146379d716 | []
| no_license | mflatt/talks | 45fbd97b1ca72addecf8f4b92053b85001ed540b | 7abfdf9a9397d3d3d5d1b4c107ab6a62d0ac1265 | refs/heads/master | 2021-01-19T05:18:38.094408 | 2020-06-04T16:29:25 | 2020-06-04T16:29:25 | 87,425,078 | 2 | 2 | null | null | null | null | UTF-8 | Scheme | false | false | 8,625 | ss | accounting.ss | (module accounting (lib "slideshow.ss" "slideshow")
(require (lib "balloon.ss" "texpict")
"../mredtalk2/angel-sequence.ss")
(provide make-basic-picture)
(define (lblt s)
(scale/improve-new-text (t s) 0.8))
(define (make-custodian-pict name)
(let ([box (inset
(color-round-frame
(inset (if (= 1 (string-length name))
(hbl-append (lblt "custodian ")
(bt name))
(bt name))
7)
0.25 "Red" 5)
2)])
(refocus
(hc-append (scale (scheme-angel-file) 0.5) (bt "= ") box)
box)))
(define (make-thread-pict name)
(inset
(color-round-frame
(inset (hbl-append (lblt "thread ") (bt name)) 7)
10 "Blue" 5)
2))
(define ((find-xx xp yp) p sub)
(let-values ([(x y) (find-lt p sub)])
(values (+ x (* xp (pict-width sub)))
(- y (* yp (pict-height sub))))))
(define find-above (find-xx 0.6 0.1))
(define find-below (find-xx 0.6 0.9))
(define (make-object-pict name first?)
(letrec ([force-full (lambda (name)
(cond
[(symbol? name) (list "" (symbol->string name)
first?)]
[(null? (cddr name)) (list (car name) (cadr name)
first?)]
[else name]))]
[object-description->name (lambda (name)
(cadr (force-full name)))]
[object-description->set (lambda (name)
(car (force-full name)))]
[object-description->display-bubble? (lambda (name)
(not (or (symbol? name)
(null?
(cddr name)))))]
[object-description->header? (lambda (name)
(and (not (symbol? name))
(null? (cddr name))))]
[object-description->above? (lambda (name)
(caddr (force-full name)))])
(let* ([str (object-description->name name)]
[set (object-description->set name)]
[display-bubble? (object-description->display-bubble? name)]
[above? (object-description->above? name)]
[header? (object-description->header? name)]
[obj ((if (string=? "_" str) ghost values)
(let ([p (bt str)])
(cc-superimpose
(cloud (+ 40 (pict-width p)) (+ 40 (pict-height p)) "forest green")
(colorize p "white"))))])
(cond
[display-bubble?
(values (if (string? str) (string->symbol str) str) obj
(place-balloon
(wrap-balloon (bt set)
(if above? 'sw 'nw)
-10
((if above? + -) 0)
balloon-color 15)
obj obj (if above? find-above find-below)))]
[header? (let* ([setp (inset (text set '() 24) 7)]
[strp (inset (text (format " ~a " str) '() 24) 7)]
[box (hc-append 0 setp strp)]
[box/line (add-line box setp find-rt setp find-rb
2 "Black")]
[all (color-round-frame box/line 0 "Purple" 5)])
(values (if (string? str) (string->symbol str) str)
all all))]
[else (values (if (string? str) (string->symbol str) str) obj obj)]))))
(define (process-object-info objs)
(let loop ([ls objs] [pictacc '()] [lookupacc '()])
(cond
[(null? ls) (values (reverse pictacc) (reverse lookupacc))]
[else (let-values ([(name obj pict) (make-object-pict (car ls)
(null? pictacc))])
(loop (cdr ls) (cons pict pictacc)
(cons (cons name obj) lookupacc)))])))
(define (process-object-info* objs)
(cond
[(null? objs) (values '() '())]
[else
(let-values ([(opicts1 lookupo1) (process-object-info (car objs))]
[(opicts2 lookupo2) (process-object-info* (cdr objs))])
(values (cons opicts1 opicts2) (append lookupo1 lookupo2)))]))
(define arrow-color "dark gray")
(define weak-arrow-color "orange")
(define (check-weak-color l)
(if (null? (cddr l))
arrow-color
weak-arrow-color))
(define (make-basic-picture custodians threads objects connections)
(let ([cpicts (map make-custodian-pict (map symbol->string custodians))]
[tpicts (map make-thread-pict (map number->string threads))])
(let-values ([(opicts lookupo) (process-object-info* objects)])
(let ([call (apply vc-append (cons 100 cpicts))]
[tall (apply vc-append (cons 100 tpicts))]
[oall (apply hc-append (cons 100 (map (lambda (x)
(apply vc-append
(cons 35 x)))
opicts)))]
[lookupc (map cons custodians cpicts)]
[lookupto (append (map cons threads tpicts) lookupo)]
[offhi (lambda (find)
(lambda (pict pict-path)
(let-values ([(dx dy) (find pict pict-path)])
(values dx (- dy 10)))))]
[offlow (lambda (find)
(lambda (pict pict-path)
(let-values ([(dx dy) (find pict pict-path)])
(values dx (+ dy 10)))))])
(let* ([all (hc-append 100 call tall oall)]
[arrows
(let loop ((ls connections) (all (ghost all)))
(cond
[(null? ls) all]
;; links from custodian to thread
[(and (member (caar ls) custodians) (member (cadar ls) threads))
(loop (cdr ls)
(add-arrow-line 10 all (cdr (assq (caar ls) lookupc)) find-rc
(cdr (assq (cadar ls) lookupto)) find-lc 2 arrow-color))]
;; links from custodian to custodian
[(and (member (caar ls) custodians)
(member (cadar ls) custodians))
(loop (cdr ls)
(add-arrow-line 10 all (cdr (assq (cadar ls) lookupc)) find-cb
(cdr (assq (caar ls) lookupc)) find-ct 2 arrow-color))]
;; links from thread to custodian
[(and (member (caar ls) threads) (member (cadar ls) custodians))
(loop (cdr ls)
(add-arrow-line 10 all (cdr (assq (caar ls) lookupto)) find-cb
(cdr (assq (cadar ls) lookupc)) find-ct 2 arrow-color))]
;; links between threads and threads
[(and (member (caar ls) threads) (member (cadar ls) threads))
(loop (cdr ls)
(add-arrow-line 10 all (cdr (assq (caar ls) lookupto)) find-cb
(cdr (assq (cadar ls) lookupto)) find-ct 2 arrow-color))]
;; links between other things
[(member (cddar ls) '(() (!)))
(loop (cdr ls)
(let ([from (assq (caar ls) lookupto)]
[to (assq (cadar ls) lookupto)])
(if (and to from)
(add-arrow-line 10 all (cdr from) find-rc
(cdr to) find-lc 2 (check-weak-color (car ls)))
all)))]
[else
(let ([all (add-arrow-line 10 all
(cdr (assq (caar ls) lookupto)) (offhi find-rc)
(cdr (assq (cadar ls) lookupto)) (offhi find-lc)
2
(if (member (cddar ls) '((~)))
weak-arrow-color
arrow-color))])
(loop (cdr ls)
(add-arrow-line 10 all (cdr (assq (cadar ls) lookupto))
(offlow find-lc) (cdr (assq (caar ls) lookupto))
(offlow find-rc) 2 arrow-color)))]))])
(cc-superimpose arrows all)))))))
| false |
877e9522051ec37287e8546863f4ecaf4bdd4b19 | f4cf5bf3fb3c06b127dda5b5d479c74cecec9ce9 | /Sources/LispKit/Resources/Libraries/srfi/167/memory.sld | facb1009b1d8d22f4a8dd02b375eb338d7c60d27 | [
"Apache-2.0"
]
| permissive | objecthub/swift-lispkit | 62b907d35fe4f20ecbe022da70075b70a1d86881 | 90d78a4de3a20447db7fc33bdbeb544efea05dda | refs/heads/master | 2023-08-16T21:09:24.735239 | 2023-08-12T21:37:39 | 2023-08-12T21:37:39 | 57,930,217 | 356 | 17 | Apache-2.0 | 2023-06-04T12:11:51 | 2016-05-03T00:37:22 | Scheme | UTF-8 | Scheme | false | false | 12,138 | sld | memory.sld | ;;; SRFI 167 MEMORY
;;; Ordered Key Value Store
;;;
;;; This library describes an interface for an ordered key-value store that is suitable
;;; for implementing a storage engine for the generic tuple-store SRFI. It maps cleanly
;;; to existing ordered key-value databases that may or may not provide transactions.
;;;
;;; Copyright © 2019 Amirouche Boubekki. All rights reserved.
;;;
;;; Permission is hereby granted, free of charge, to any person obtaining a copy of this
;;; software and associated documentation files (the "Software"), to deal in the Software
;;; without restriction, including without limitation the rights to use, copy, modify, merge,
;;; publish, distribute, sublicense, and/or sell copies of the Software, and to permit
;;; persons to whom the Software is furnished to do so, subject to the following conditions:
;;;
;;; The above copyright notice and this permission notice shall be included in all copies or
;;; substantial portions of the Software.
;;;
;;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
;;; INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
;;; PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
;;; HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
;;; CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
;;; OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
;;;
;;; LispKit Port:
;;; Copyright © 2019 Matthias Zenger. All rights reserved.
(define-library (srfi 167 memory)
(export okvs-open
okvs?
okvs-close
make-default-state
okvs-transaction?
okvs-transaction-state
okvs-in-transaction
okvs-ref
okvs-set!
okvs-delete!
okvs-range-remove!
okvs-range
okvs-prefix-range
okvs-hook-on-transaction-begin
okvs-hook-on-transaction-commit
make-default-engine)
(import (except (lispkit base) string-hash string-ci-hash symbol-hash equal-hash eq-hash)
(srfi 1)
(srfi 125)
(except (srfi 128) string-hash string-ci-hash symbol-hash equal-hash eq-hash)
(srfi 145)
(srfi 146)
(srfi 158)
(srfi 173)
(srfi 167 pack)
(srfi 167 engine))
(begin
;; helpers
(define (const v)
(lambda ()
v))
(define (u8-list->bytevector lst)
(apply bytevector lst))
(define (bytevector->u8-list bv)
(let loop ((index 0)
(out '()))
(if (= index (bytevector-length bv))
(reverse out)
(loop (+ index 1)
(cons (bytevector-u8-ref bv index) out)))))
;;
;; This a memory based okvs implementation backed by the r7rs
;; library (scheme mapping). Roll-back operation is supported.
;;
(define-record-type <okvs>
(make-okvs store hook-on-transaction-begin hook-on-transaction-commit)
okvs?
(store okvs-store okvs-store!)
(hook-on-transaction-begin okvs-hook-on-transaction-begin)
(hook-on-transaction-commit okvs-hook-on-transaction-commit))
(define (lexicographic-compare bytevector other)
;; Return -1 if BYTEVECTOR is before OTHER, 0 if equal
;; and otherwise 1
(let ((end (min (bytevector-length bytevector)
(bytevector-length other))))
(let loop ((index 0))
(if (zero? (- end index))
(if (= (bytevector-length bytevector)
(bytevector-length other))
0
(if (< (bytevector-length bytevector)
(bytevector-length other))
-1
1))
(let ((delta (- (bytevector-u8-ref bytevector index)
(bytevector-u8-ref other index))))
(if (zero? delta)
(loop (+ 1 index))
(if (negative? delta)
-1
1)))))))
(define (lexicographic<? bytevector other)
(negative? (lexicographic-compare bytevector other)))
(define vector-hash
(comparator-hash-function
(make-vector-comparator (make-default-comparator)
bytevector?
bytevector-length
bytevector-u8-ref)))
(define (make-lexicographic-comparator)
(make-comparator bytevector? bytevector=? lexicographic<? vector-hash))
(define (okvs-open home . args)
(assume (null? args))
(assume (not home))
(make-okvs (mapping (make-lexicographic-comparator))
(make-hook 1)
(make-hook 1)))
(define (okvs-close okvs . args)
(assume (null? args))
(void))
(define-record-type <okvs-transaction>
(make-okvs-transaction database store state)
okvs-transaction?
(database okvs-transaction-database okvs-transaction-database!)
(store okvs-transaction-store okvs-transaction-store!)
(state okvs-transaction-state))
(define (okvs-transaction-begin database make-state . args)
(let ((transaction (make-okvs-transaction database
(okvs-store database)
(make-state))))
(hook-run (okvs-hook-on-transaction-begin database) transaction)
transaction))
(define (okvs-transaction-commit transaction . args)
(hook-run (okvs-hook-on-transaction-commit (okvs-transaction-database transaction))
transaction)
(okvs-store! (okvs-transaction-database transaction)
(okvs-transaction-store transaction)))
(define (okvs-transaction-roll-back transaction . args)
(void))
(define (%okvs-in-transaction okvs proc failure success make-state config)
(assume (null? config))
(let ((transaction (okvs-transaction-begin okvs make-state config)))
(guard (ex (else (okvs-transaction-roll-back transaction)
(failure ex)))
(call-with-values (lambda () (proc transaction))
(lambda out
(okvs-transaction-commit transaction)
(apply success out))))))
(define (make-default-state)
(make-hash-table (make-default-comparator)))
(define okvs-in-transaction
(case-lambda
((okvs proc)
(okvs-in-transaction okvs proc raise values make-default-state '()))
((okvs proc failure)
(okvs-in-transaction okvs proc failure values make-default-state '()))
((okvs proc failure success)
(%okvs-in-transaction okvs proc failure success make-default-state '()))
((okvs proc failure success make-state)
(%okvs-in-transaction okvs proc failure success make-state '()))
((okvs proc failure success make-state config)
(%okvs-in-transaction okvs proc failure success make-state config))))
(define (okvs-ref okvs-or-transaction key)
(if (okvs-transaction? okvs-or-transaction)
(mapping-ref/default (okvs-transaction-store okvs-or-transaction) key #f)
(mapping-ref/default (okvs-store okvs-or-transaction) key #f)))
(define (okvs-set! okvs-or-transaction key value)
(if (okvs-transaction? okvs-or-transaction)
(okvs-transaction-store!
okvs-or-transaction
(mapping-set (okvs-transaction-store okvs-or-transaction) key value))
(okvs-store!
okvs-or-transaction
(mapping-set (okvs-store okvs-or-transaction) key value))))
(define (okvs-delete! okvs-or-transaction key)
(if (okvs-transaction? okvs-or-transaction)
(okvs-transaction-store!
okvs-or-transaction
(mapping-delete (okvs-transaction-store okvs-or-transaction) key))
(okvs-set! okvs-or-transaction (mapping-delete (okvs-store okvs-or-transaction) key))))
(define (okvs-range-remove! okvs-or-transaction start-key start-include? end-key end-include?)
(let ((generator (okvs-range okvs-or-transaction start-key
start-include?
end-key
end-include?)))
(let loop ((pair (generator)))
(unless (eof-object? pair)
(let ((key (car pair)))
(okvs-delete! okvs-or-transaction key)
(loop (generator)))))))
(define (okvs-range-init store key)
(let ((value (mapping-ref/default store key #f)))
(if value
(list (cons key value))
'())))
(define (explode config)
(if (null? config)
(values #f #f #f)
(let ((limit #f)
(reverse? #f)
(offset #f))
(let loop ((config (car config)))
(if (null? config)
(values limit reverse? offset)
(case (caar config)
((limit)
(set! limit (cdar config))
(loop (cdr config)))
((reverse?)
(set! reverse? (cdar config))
(loop (cdr config)))
((offset)
(set! offset (cdar config))
(loop (cdr config)))
(else (error 'okvs "Unkown configuration key" (caar config)))))))))
(define (massage config lst)
(call-with-values (lambda () (explode config))
(lambda (limit reverse? offset)
(unless reverse?
(set! lst (reverse lst)))
(when offset
(set! lst (drop lst offset)))
(when limit
(set! lst (take lst limit)))
lst)))
(define (okvs-range okvs-or-transaction start-key start-include? end-key end-include? . config)
(let* ((store (okvs-transaction-store okvs-or-transaction)))
(let loop ((key (mapping-key-successor store start-key (const #f)))
(out (if start-include?
(okvs-range-init store start-key)
'())))
(if (not key)
(list->generator (massage config out))
(case (lexicographic-compare key end-key)
((-1)
(loop (mapping-key-successor store key (const #f))
(cons (cons key (mapping-ref/default store key #f)) out)))
((0)
(if end-include?
(loop #f (cons (cons key (mapping-ref/default store key #f)) out))
(loop #f out)))
((1) (loop #f out)))))))
(define (strinc bytevector)
"Return the first bytevector that is not prefix of BYTEVECTOR"
;; See https://git.io/fj34F, TODO: OPTIMIZE
(let ((bytes (reverse (bytevector->u8-list bytevector))))
;; strip #xFF
(let loop ((out bytes))
(when (null? out)
(error 'okvs "Key must contain at least one byte not equal to #xFF." bytevector))
(if (= (car out) #xFF)
(loop (cdr out))
(set! bytes out)))
;; increment first byte, reverse and return the bytevector
(u8-list->bytevector (reverse (cons (+ 1 (car bytes)) (cdr bytes))))))
(define (okvs-prefix-range okvs-or-transaction prefix . config)
(apply okvs-range okvs-or-transaction prefix #t (strinc prefix) #f config))
(define (make-default-engine)
(make-engine okvs-open
okvs-close
okvs-in-transaction
okvs-ref
okvs-set!
okvs-delete!
okvs-range-remove!
okvs-range
okvs-prefix-range
okvs-hook-on-transaction-begin
okvs-hook-on-transaction-commit
pack
unpack))
)
)
| false |
b87a927b40f0088125fc4807c7b7fbf132ed1e75 | 9b2eb10c34176f47f7f490a4ce8412b7dd42cce7 | /lib-r6rs/r7b-impl/process-context.sls | 3f9e6cd1bb5e4f4bb28e3d394fc06fb6d02da024 | [
"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 | 230 | sls | process-context.sls | (library (r7b-impl process-context)
(export
;; from R7RS draft 7
command-line emergency-exit exit
get-environment-variable get-environment-variables
)
(import (rnrs) (r7b-compat i98) (r7b-util emergency-exit)))
| false |
2f338023d1a0ef85f33d0c96f2d6ba37b1c68f19 | 26aaec3506b19559a353c3d316eb68f32f29458e | /apps/scmgraph/main.scm | 4e83ab5d4bd14d7f8bae3c63ed8714280a1de98d | [
"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 | 3,453 | scm | main.scm | #|
LambdaNative - a cross-platform Scheme framework
Copyright (c) 2009-2016, 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.
|#
;; Scientific Vector Graphs in Scheme
(define scmgraph:debuglevel 10)
(define (scmgraph:log level . x)
(if (>= scmgraph:debuglevel level)
(for-each display (append (list "LOG: ") x (list "\n")))))
(define (scmgraph:error . x) (apply scmgraph:log (append (list 0 "**ERROR: ") x)) (exit))
(define (usage)
(for-each display (list
"Scheme Graph\n"
"usage: scmgraph [svg|pdf] <scheme graph specification>\n"
))
(exit))
(define args (let loop ((n 0)(res '()))
(if (= n (system-cmdargc)) res (loop (+ n 1) (append res (list (system-cmdargv n)))))))
(if (< (length args) 2) (usage))
(define use-pdf (member "pdf" args))
(define use-svg (member "svg" args))
(define use-repl (member "repl" args))
(set! sourcefile (car (reverse args)))
(if (not (file-exists? sourcefile)) (scmgraph:error sourcefile " not found"))
(if (or (< (string-length sourcefile) 5)
(not (string=? (substring sourcefile
(- (string-length sourcefile) 3) (string-length sourcefile)) "scm"))
)
(scmgraph:error sourcefile " invalid file extension (not .scm)"))
(let* ((strlen (string-length sourcefile))
(basename (substring sourcefile 0 (- strlen 4))))
(set! targetfile (string-append basename
(if use-svg ".svg" ".pdf")))
)
(scmgraph:log 1 "Scheme Graph")
(scmgraph:log 1 "Loading source graph from " sourcefile "..")
(define graph (eval (with-input-from-file sourcefile (lambda () (read)))))
(define graph-type (cond
(use-pdf 'GRAPH_PDF)
(use-svg 'GRAPH_SVG)
(else 'GRAPH_PDF)))
(scmgraph:log 1 "Rendering graph to " targetfile "..")
(graph-output graph graph-type targetfile)
(if use-repl (begin
(scmgraph:log 1 "Entering debug repl..")
(let loop ()
(with-exception-catcher (lambda (e)
(for-each display (list (exception->string e) "\n")) #f)
(lambda () (##repl-debug)))
(loop))
))
(scmgraph:log 1 "Done.")
;; eof
| false |
923ab104785237486ebfc700644a20cbd4f40019 | ffd6cdc49ba0aa09366cf3091d2a657461d388cf | /11a.ss | bfe656dda15555722f6035991c1b7e965a8311c7 | []
| no_license | hernanre/csse304-ProgrammingLanguageConcept | cba83977be2eff7dbf39da8eec483801ce939930 | 14cbbd604cd7cdb421d39741e96a7fd003b2579b | refs/heads/master | 2022-01-26T13:20:51.590843 | 2018-10-02T23:04:35 | 2018-10-02T23:04:35 | null | 0 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 9,711 | ss | 11a.ss | (load "chez-init.ss")
(define-datatype bintree bintree?
(leaf-node
(num integer?))
(interior-node
(key symbol?)
(left-tree bintree?)
(right-tree bintree?)))
;Linjie Zha A11a
;Problem1
;a
(define-syntax my-let
(syntax-rules ()
[(_ ([x e] ...) e1 e2 ...)
((lambda (x ...)
e1 e2 ...)
e ...)]
[(_ n ([x e] ...) e1 e2 ...)
(letrec ([n
(lambda (x ...)
e1 e2 ...)])
(n e ...))]))
;b
(define-syntax my-or
(syntax-rules ()
[(_) #f]
[(_ e) e]
[(_ e1 e2 ...)
(let ([x e1])
(if x
x
(my-or e2 ...)))]))
;c
(define-syntax +=
(syntax-rules ()
[(_ x y)
(begin (set! x (+ x y))
x)]))
;d
(define-syntax return-first
(syntax-rules ()
[(_ e1 e2 ...)
(let ([first e1])
(begin e2 ...)
first)]))
;Problem2
(define bintree-to-list
(lambda (t)
(cases bintree t
[leaf-node (datun)
(list 'leaf-node datun)]
[interior-node (key left right)
(list 'interior-node key (bintree-to-list left) (bintree-to-list right))])))
;Problem3
(define max-interior
(lambda (tree)
(letrec ([helper
(lambda (tree)
(cases bintree tree
[leaf-node (datum) datum]
[interior-node (key left right)
(let ([left-ls (helper left)]
[right-ls (helper right)])
(cond
[(and (number? left-ls) (number? right-ls))
(list key (+ left-ls right-ls) key (+ left-ls right-ls))]
[(and (number? left-ls) (list? right-ls))
(let ([rkey (car right-ls)]
[r-max (cadr right-ls)]
[r-cur (cadddr right-ls)])
(if (> r-max (+ left-ls r-cur))
(list rkey r-max key (+ left-ls r-cur))
(list key (+ left-ls r-cur) key (+ left-ls r-cur))))]
[(and (number? right-ls) (list? left-ls))
(let ([lkey (car left-ls)]
[l-max (cadr left-ls)]
[l-cur (cadddr left-ls)])
(if (< l-max (+ right-ls l-cur))
(list key (+ right-ls l-cur) key (+ right-ls l-cur))
(list lkey l-max key (+ right-ls l-cur))))]
[else
(let ([lkey (car left-ls)]
[rkey (car right-ls)]
[cur-max (+ (cadddr left-ls) (cadddr right-ls))]
[l-max (cadr left-ls)]
[r-max (cadr right-ls)])
(if (>= l-max r-max)
(if (> l-max cur-max)
(list lkey l-max key cur-max)
(list key cur-max key cur-max))
(if (< r-max cur-max)
(list key cur-max key cur-max)
(list rkey r-max key cur-max))))]))]))])
(car (helper tree)))))
(define-datatype expression expression?
[var-exp
(id symbol?)]
[lit-exp
(lit (lambda (x) #t))]
[lambda-exp
(id (lambda (v) (or (symbol? v) (list-of expression?))))
(body (list-of expression?))]
[let-exp
(vars (list-of (list-of expression?)))
(body (list-of expression?))]
[letrec-exp
(vars (list-of (list-of expression?)))
(body (list-of expression?))]
[let*-exp
(vars (list-of (list-of expression?)))
(body (list-of expression?))]
[set!-exp
(id symbol?)
(body expression?)]
[if-exp
(test expression?)
(result expression?)]
[if-else-exp
(test expression?)
(thencase expression?)
(elsecase expression?)]
[app-exp
(rator expression?)
(rand (list-of expression?))])
; Procedures to make the parser a little bit saner.
(define 1st car)
(define 2nd cadr)
(define 3rd caddr)
(define 4th cadddr)
(define parse-exp
(lambda (datum)
(cond
[(symbol? datum) (var-exp datum)]
[(number? datum) (lit-exp datum)]
[(string? datum) (lit-exp datum)]
[(vector? datum) (lit-exp datum)]
[(boolean? datum) (lit-exp datum)]
[(pair? datum)
(cond
[(not (list? datum))
(eopl:error 'parse-exp "not a proper list: ~s" datum)]
[(eqv? (1st datum) 'lambda)
(cond
[(not (> (length datum) 2))
(eopl:error 'parse-exp "incorrect length:" datum)]
[(symbol? (2nd datum))
(lambda-exp (parse-exp (2nd datum)) (map parse-exp (cddr datum)))]
[(not (andmap symbol? (2nd datum)))
(eopl:error 'parse-exp "invalid arguement " datum)]
[else
(lambda-exp (map parse-exp (2nd datum)) (map parse-exp (cddr datum)))])]
[(eqv? (1st datum) 'let)
(cond
[(< (length datum) 3)
(eopl:error 'parse-exp "incorrect length: ~s" datum)]
[(not (list? (2nd datum)))
(eopl:error 'parse-exp "not all proper list: ~s" (2nd datum))]
[(not (andmap list? (2nd datum)))
(eopl:error 'parse-exp "not a proper list: ~s" (2nd datum))]
[(not (andmap (lambda (x) (= 2 (length x))) (2nd datum)))
(eopl:error 'parse-exp "not all length 2: ~s" (2nd datum))]
[(not (andmap symbol? (map 1st (2nd datum))))
(eopl:error 'parse-exp "first members must be symbols: ~s" datum)]
[else
(let-exp (map list (map parse-exp (map car (2nd datum))) (map parse-exp (map 2nd (2nd datum)))) (map parse-exp (cddr datum)))])]
[(eqv? (1st datum) 'letrec)
(cond
[(< (length datum) 3)
(eopl:error 'parse-exp "incorrect length: ~s" datum)]
[(not (list? (2nd datum)))
(eopl:error 'parse-exp "not all proper list: ~s" (2nd datum))]
[(not (andmap list? (2nd datum)))
(eopl:error 'parse-exp "not a proper list: ~s" (2nd datum))]
[(not (andmap (lambda (x) (= 2 (length x))) (2nd datum)))
(eopl:error 'parse-exp "not all length 2: ~s" (2nd datum))]
[(not (andmap symbol? (map 1st (2nd datum))))
(eopl:error 'parse-exp "first members must be symbols: ~s" datum)]
[else
(letrec-exp (map list (map parse-exp (map car (2nd datum))) (map parse-exp (map 2nd (2nd datum)))) (map parse-exp (cddr datum)))])]
[(eqv? (1st datum) 'let*)
(cond
[(< (length datum) 3)
(eopl:error 'parse-exp "incorrect length: ~s" datum)]
[(not (list? (2nd datum)))
(eopl:error 'parse-exp "not all proper list: ~s" (2nd datum))]
[(not (andmap list? (2nd datum)))
(eopl:error 'parse-exp "not a proper list: ~s" (2nd datum))]
[(not (andmap (lambda (x) (= 2 (length x))) (2nd datum)))
(eopl:error 'parse-exp "not all length 2: ~s" (2nd datum))]
[(not (andmap symbol? (map 1st (2nd datum))))
(eopl:error 'parse-exp "first members must be symbols: ~s" datum)]
[else
(let*-exp (map list (map parse-exp (map car (2nd datum))) (map parse-exp (map 2nd (2nd datum)))) (map parse-exp (cddr datum)))])]
[(eqv? (1st datum) 'set!)
(cond
[(< (length datum) 3)
(eopl:error 'parse-exp "missing expression: ~s" datum)]
[(> (length datum) 3)
(eopl:error 'parse-exp "too many parts: ~s" datum)]
[else
(set!-exp (2nd datum) (parse-exp (3rd datum)))])]
[(eqv? (1st datum) 'if)
(cond
[(= 2 (length datum))
(eopl:error 'parse-exp "missing then or else clauses: ~s" datum)]
[(= 3 (length datum))
(if-exp (parse-exp (2nd datum)) (parse-exp (3rd datum)))]
[(> (length datum) 4)
(eopl:error 'parse-exp "too many parts: ~s" datum)]
[else
(if-else-exp (parse-exp (2nd datum))
(parse-exp (3rd datum))
(parse-exp (4th datum)))])]
[else (app-exp (parse-exp (1st datum))
(map parse-exp (cdr datum)))])]
[else (eopl:error 'parse-exp "bad expression: ~s" datum)])))
(define unparse-exp
(lambda (exp)
(cases expression exp
[var-exp (id) id]
[lit-exp (id) id]
[lambda-exp (id body)
(cond
[(null? id)
(cons 'lambda (cons (map unparse-exp id) (map unparse-exp body)))]
[(symbol? (car id))
(cons 'lambda (cons (unparse-exp id) (map unparse-exp body)))]
[else
(cons 'lambda (cons (map unparse-exp id) (map unparse-exp body)))])]
[let-exp (vars body)
(cons 'let (cons
(map list (map unparse-exp (map 1st vars)) (map unparse-exp (map 2nd vars)))
(map unparse-exp body)))]
[letrec-exp (vars body)
(cons 'letrec (cons (map list (map unparse-exp (map 1st vars)) (map unparse-exp (map 2nd vars))) (map unparse-exp body)))]
[let*-exp (vars body)
(cons 'let* (cons (map list (map unparse-exp (map 1st vars)) (map unparse-exp (map 2nd vars))) (map unparse-exp body)))]
[set!-exp (id body)
(list 'set! (unparse-exp id) (unparse-exp body))]
[if-exp (test result)
(list 'if (unparse-exp test) (unparse-exp result))]
[if-else-exp (test thencase elsecase)
(list 'if (unparse-exp test) (unparse-exp thencase) (unparse-exp elsecase))]
[app-exp (rator rand)
(cons (unparse-exp rator)
(map unparse-exp rand))]))) | true |
8b2654fd45fbf14c9fcaab53104a99ff162e1ac2 | 27e8f9a818527bd169c03c60ec54eec822780d47 | /pkg-list.scm | 477d53ee37bfc00c00ea1b22ef4411d78b661066 | [
"BSD-3-Clause"
]
| permissive | jhidding/pfds | db0e875bb293b21de3160dd1279cddbbb3a9e23f | 9755ffc2c59df2a303aa5f0885ecfefae2c67097 | refs/heads/master | 2021-01-12T14:45:31.068141 | 2017-12-28T19:02:15 | 2017-12-28T19:02:15 | 72,078,412 | 5 | 0 | null | 2016-10-27T06:35:23 | 2016-10-27T06:35:22 | null | UTF-8 | Scheme | false | false | 608 | scm | pkg-list.scm | (package (pfds (0 3))
(depends (wak-trc-testing))
(synopsis "Purely Functional Data Structures")
(description
"A library of data structures for functional programmers."
"It contains implementations of:"
"- queues"
"- deques"
"- bbtrees"
"- sets"
"- dlists"
"- priority search queues"
"- heaps"
"- hamts"
"- finger trees"
"- sequences")
(homepage "http://github.com/ijp/pfds")
(documentation
"README.org"
"LICENSE")
(libraries
(sls -> "pfds")
("queues" -> ("pdfs" "queues"))
("deques" -> ("pdfs" "deques"))
("private" -> ("pfds" "private"))))
| false |
38a9d69d545c1e8667a7ba009cb823b553bdd893 | 7cc14e6ab8e064fa967251e3249863e2cfbcc920 | /chapter-2/e-2-19.scm | c114a246e84d61ee13a9fbe698ca1d3cc1216961 | []
| no_license | xueeinstein/sicp-code | 0bec79419286705f58175067d474169afd6ba5fe | 49602b0b13cb9c338b6af089f989c17890ba6085 | refs/heads/master | 2021-01-10T01:20:03.089038 | 2015-11-24T03:25:54 | 2015-11-24T03:25:54 | 43,536,317 | 0 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 793 | scm | e-2-19.scm | ;;; Bill Xue
;;; 2015-10-09
;;; Count Change with self customized denominations
(define (count-change amount)
(define (cc a coin-values)
(cond ((= a 0) 1) ; amount = 0, only 1 way to change
((or (< a 0) (no-more? coin-values)) 0)
(else (+ (cc a
(except-first-denomination coin-values))
(cc (- a
(first-denomination coin-values))
coin-values))))) ; end of cc
; supplementary procedure
(define (first-denomination coin-values)
(car coin-values))
(define (except-first-denomination coin-values)
(cdr coin-values))
(define no-more? null?)
; main
(define us-coins (list 50 25 10 5 1))
(define uk-coins (list 100 50 20 10 5 2 1 0.5))
(cc amount us-coins))
| false |
87e105f5ce8752e43a89247c508020e726f3e0f6 | 09e309c8c7dd86d201f965a12f4f174fd2bf8cf5 | /scheme/read-from-string.scm | 2f6bd90b27ca59e42385f0ba13f593f429286eb6 | []
| no_license | googol-lab/lang | f21076846b2364ee08875530ab7a6680de61f55c | 38cae455f85464a7f918d1a5a481a577ed5549fe | refs/heads/master | 2020-03-29T13:32:29.159544 | 2010-05-24T03:09:54 | 2010-05-24T03:09:54 | null | 0 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 100 | scm | read-from-string.scm | (define (my-read-from-string str)
(call-with-input-string str
(lambda (in)
(read in))))
| false |
83834b3f9cb2de9ab17b75f9db7b06cd907a1ad3 | bcfa2397f02d5afa93f4f53c0b0a98c204caafc1 | /scheme/chapter2/ex2_05_test.scm | 4d1dd216447caaf7c6948fa87a7d4f210c2777ce | []
| no_license | rahulkumar96/sicp-study | ec4aa6e1076b46c47dbc7a678ac88e757191c209 | 4dcd1e1eb607aa1e32277e1c232a321c5de9c0f0 | refs/heads/master | 2020-12-03T00:37:39.576611 | 2017-07-05T12:58:48 | 2017-07-05T12:58:48 | 96,050,670 | 0 | 0 | null | 2017-07-02T21:46:09 | 2017-07-02T21:46:09 | null | UTF-8 | Scheme | false | false | 148 | scm | ex2_05_test.scm | ;; SICP 2.5 tests
(test-case "Ex 2.4 Numeric Pairs"
(assert-equal 5 (icar (icons 5 6)))
(assert-equal 6 (icdr (icons 5 6))))
| false |
1dab09ecdd9345da47ff528d751e280c334c7cb7 | fc896dc9041dede967237ce1b8bf6ac0a27e050b | /pdf-font.scm | e3de7178680a6a5fbac3305f73c326c40304d60d | []
| no_license | r1b/pdf | d619a9a3360b1f80d392d2ef9a9c2636dd970df9 | 09a806e35cdd841f35acd5562cde7f1c8f005b59 | refs/heads/master | 2020-06-20T09:50:40.598398 | 2019-07-15T23:08:30 | 2019-07-15T23:10:06 | 197,084,165 | 2 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 23,949 | scm | pdf-font.scm | ;;
;; utilities for extracting interesting font information from Adobe Font Metrics files
;;
(module pdf-font
( add-font-info-from-file
get-char-width
get-string-width)
(cond-expand
(chicken-5 (import (chicken base)
(chicken io)
(chicken format)
scheme
srfi-13
srfi-69))
(else (begin (import scheme chicken)
(use srfi-13 srfi-69 extras))))
(define-record font-info name first-char width-vector)
(define font-info-table (make-hash-table equal?))
; transform each line in file to a list of strings
(define (parenthesize file out-port)
(with-input-from-file file
(lambda ()
(let loop ((line (read-line)))
(if (not (eof-object? line))
(begin
;(fprintf out-port "~v~n" (pregexp-split " +" line))
(fprintf out-port "~S~%" (string-tokenize " +" line))
(loop (read-line))))))))
; transform parenthesized lists into an s-expr
(define (listify file)
(let ((output-port (open-output-string)))
(fprintf output-port "(~%")
(parenthesize file output-port)
(fprintf output-port ")")
(let ((str (get-output-string output-port)))
(read (open-input-string str)))))
; look for interesting information in .afm file
(define (extract-font-info name file)
(let ((l (listify file))
(first-char #f)
(width-vect #f))
(for-each
(let ((i 0))
(lambda (x)
(if (pair? x)
(cond ((string-ci=? (car x) "StartCharMetrics")
(set! width-vect (make-vector (string->number (cadr x)))))
((string-ci=? (car x) "C")
(if (zero? i)
(set! first-char (string->number (cadr x))))
(vector-set! width-vect i
(string->number (cadr (cdddr x))))
(set! i (+ 1 i)))))))
l)
(list name first-char width-vect)))
; stuff name, width info into font-info-table table from file
(define (add-font-info-from-file name file)
(let ((lst (extract-font-info name file)))
(add-font-info (make-font-info (car lst) (cadr lst) (caddr lst)))))
;;
;; utilities to access font information
;;
(define (add-font-info font-info)
;(hash-table-put! font-info-table (font-info-name font-info) font-info))
(hash-table-set! font-info-table (font-info-name font-info) font-info))
(define (get-font-info font-name)
;(hash-table-get font-info-table font-name))
(hash-table-ref font-info-table font-name))
;; get character width in user-space (point) units
(define (get-char-width font-name point-size ch)
(let* ((font-info (get-font-info font-name))
(width-vector (font-info-width-vector font-info))
(index (- (char->integer ch) (font-info-first-char font-info))))
(if (and (>= index 0)
(< index (vector-length width-vector)))
(* (/ point-size 1000) (vector-ref width-vector index))
0)))
;; get string width in user-space (point) units
(define (get-string-width font-name point-size str)
(let* ((font-info (get-font-info font-name))
(first-char (font-info-first-char font-info))
(width-vector (font-info-width-vector font-info)))
(do ((i 0 (+ i 1))
(max (string-length str))
(width 0))
((= i max) (* (/ point-size 1000) width))
(set! width (+ width
(vector-ref width-vector
(- (char->integer (string-ref str i)) first-char)))))))
;; some handy predefined font info
(define courier-info
;'("Courier" 32 #260(600)))
`("Courier" 32 ,(make-vector 260 600)))
(define courier-bold-info
;'("Courier-Bold" 32 #260(600)))
`("Courier-Bold" 32 ,(make-vector 260 600)))
(define courier-boldoblique-info
;'("Courier-BoldOblique" 32 #260(600)))
`("Courier-BoldOblique" 32 ,(make-vector 260 600)))
(define courier-oblique-info
;'("Courier-Oblique" 32 #260(600)))
`("Courier-Oblique" 32 ,(make-vector 260 600)))
(define helvetica-info
;'("Helvetica" 32 #228(278 278 355 556 556 889 667 222 333 333 389 584 278 333 278 278 556 556 556 556 556 556 556 556 556 556 278 278 584 584 584 556 1015 667 667 722 722 667 611 778 722 278 500 667 556 833 722 778 667 778 722 667 611 722 667 944 667 667 611 278 278 278 469 556 222 556 556 500 556 556 278 556 556 222 222 500 222 833 556 556 556 556 333 500 278 556 500 722 500 500 500 334 260 334 584 333 556 556 167 556 556 556 556 191 333 556 333 333 500 500 556 556 556 278 537 350 222 333 333 556 1000 1000 611 333 333 333 333 333 333 333 333 333 333 333 333 333 1000 1000 370 556 778 1000 365 889 278 222 611 944 611 667 667 667 667 667 667 722 667 667 667 667 722 278 278 278 278 722 778 778 778 778 778 667 667 722 722 722 722 667 667 611 556 556 556 556 556 556 260 500 737 400 584 556 556 556 556 556 278 278 278 278 584 584 556 584 556 556 556 556 556 834 834 333 556 584 737 500 556 834 333 1000 333 556 556 556 556 500)))
'("Helvetica" 32 #(278 278 355 556 556 889 667 222 333 333 389 584 278 333 278 278 556 556 556 556 556 556 556 556 556 556 278 278 584 584 584 556 1015 667 667 722 722 667 611 778 722 278 500 667 556 833 722 778 667 778 722 667 611 722 667 944 667 667 611 278 278 278 469 556 222 556 556 500 556 556 278 556 556 222 222 500 222 833 556 556 556 556 333 500 278 556 500 722 500 500 500 334 260 334 584 333 556 556 167 556 556 556 556 191 333 556 333 333 500 500 556 556 556 278 537 350 222 333 333 556 1000 1000 611 333 333 333 333 333 333 333 333 333 333 333 333 333 1000 1000 370 556 778 1000 365 889 278 222 611 944 611 667 667 667 667 667 667 722 667 667 667 667 722 278 278 278 278 722 778 778 778 778 778 667 667 722 722 722 722 667 667 611 556 556 556 556 556 556 260 500 737 400 584 556 556 556 556 556 278 278 278 278 584 584 556 584 556 556 556 556 556 834 834 333 556 584 737 500 556 834 333 1000 333 556 556 556 556 500)))
(define helvetica-bold-info
;'("Helvetica-Bold" 32 #228(278 333 474 556 556 889 722 278 333 333 389 584 278 333 278 278 556 556 556 556 556 556 556 556 556 556 333 333 584 584 584 611 975 722 722 722 722 667 611 778 722 278 556 722 611 833 722 778 667 778 722 667 611 722 667 944 667 667 611 333 278 333 584 556 278 556 611 556 611 556 333 611 611 278 278 556 278 889 611 611 611 611 389 556 333 611 556 778 556 556 500 389 280 389 584 333 556 556 167 556 556 556 556 238 500 556 333 333 611 611 556 556 556 278 556 350 278 500 500 556 1000 1000 611 333 333 333 333 333 333 333 333 333 333 333 333 333 1000 1000 370 611 778 1000 365 889 278 278 611 944 611 722 722 722 722 722 722 722 667 667 667 667 722 278 278 278 278 722 778 778 778 778 778 667 667 722 722 722 722 667 667 611 556 556 556 556 556 556 280 556 737 400 584 556 556 556 556 611 278 278 278 278 584 584 611 584 611 611 611 611 611 834 834 333 611 584 737 556 611 834 333 1000 333 611 611 611 611 556 556 500)))
'("Helvetica-Bold" 32 #(278 333 474 556 556 889 722 278 333 333 389 584 278 333 278 278 556 556 556 556 556 556 556 556 556 556 333 333 584 584 584 611 975 722 722 722 722 667 611 778 722 278 556 722 611 833 722 778 667 778 722 667 611 722 667 944 667 667 611 333 278 333 584 556 278 556 611 556 611 556 333 611 611 278 278 556 278 889 611 611 611 611 389 556 333 611 556 778 556 556 500 389 280 389 584 333 556 556 167 556 556 556 556 238 500 556 333 333 611 611 556 556 556 278 556 350 278 500 500 556 1000 1000 611 333 333 333 333 333 333 333 333 333 333 333 333 333 1000 1000 370 611 778 1000 365 889 278 278 611 944 611 722 722 722 722 722 722 722 667 667 667 667 722 278 278 278 278 722 778 778 778 778 778 667 667 722 722 722 722 667 667 611 556 556 556 556 556 556 280 556 737 400 584 556 556 556 556 611 278 278 278 278 584 584 611 584 611 611 611 611 611 834 834 333 611 584 737 556 611 834 333 1000 333 611 611 611 611 556 556 500)))
(define helvetica-boldoblique-info
;'("Helvetica-BoldOblique" 32 #228(278 333 474 556 556 889 722 278 333 333 389 584 278 333 278 278 556 556 556 556 556 556 556 556 556 556 333 333 584 584 584 611 975 722 722 722 722 667 611 778 722 278 556 722 611 833 722 778 667 778 722 667 611 722 667 944 667 667 611 333 278 333 584 556 278 556 611 556 611 556 333 611 611 278 278 556 278 889 611 611 611 611 389 556 333 611 556 778 556 556 500 389 280 389 584 333 556 556 167 556 556 556 556 238 500 556 333 333 611 611 556 556 556 278 556 350 278 500 500 556 1000 1000 611 333 333 333 333 333 333 333 333 333 333 333 333 333 1000 1000 370 611 778 1000 365 889 278 278 611 944 611 722 722 722 722 722 722 722 667 667 667 667 722 278 278 278 278 722 778 778 778 778 778 667 667 722 722 722 722 667 667 611 556 556 556 556 556 556 280 556 737 400 584 556 556 556 556 611 278 278 278 278 584 584 611 584 611 611 611 611 611 834 834 333 611 584 737 556 611 834 333 1000 333 611 611 611 611 556 556 500)))
'("Helvetica-BoldOblique" 32 #(278 333 474 556 556 889 722 278 333 333 389 584 278 333 278 278 556 556 556 556 556 556 556 556 556 556 333 333 584 584 584 611 975 722 722 722 722 667 611 778 722 278 556 722 611 833 722 778 667 778 722 667 611 722 667 944 667 667 611 333 278 333 584 556 278 556 611 556 611 556 333 611 611 278 278 556 278 889 611 611 611 611 389 556 333 611 556 778 556 556 500 389 280 389 584 333 556 556 167 556 556 556 556 238 500 556 333 333 611 611 556 556 556 278 556 350 278 500 500 556 1000 1000 611 333 333 333 333 333 333 333 333 333 333 333 333 333 1000 1000 370 611 778 1000 365 889 278 278 611 944 611 722 722 722 722 722 722 722 667 667 667 667 722 278 278 278 278 722 778 778 778 778 778 667 667 722 722 722 722 667 667 611 556 556 556 556 556 556 280 556 737 400 584 556 556 556 556 611 278 278 278 278 584 584 611 584 611 611 611 611 611 834 834 333 611 584 737 556 611 834 333 1000 333 611 611 611 611 556 556 500)))
(define helvetica-oblique-info
;'("Helvetica-Oblique" 32 #228(278 278 355 556 556 889 667 222 333 333 389 584 278 333 278 278 556 556 556 556 556 556 556 556 556 556 278 278 584 584 584 556 1015 667 667 722 722 667 611 778 722 278 500 667 556 833 722 778 667 778 722 667 611 722 667 944 667 667 611 278 278 278 469 556 222 556 556 500 556 556 278 556 556 222 222 500 222 833 556 556 556 556 333 500 278 556 500 722 500 500 500 334 260 334 584 333 556 556 167 556 556 556 556 191 333 556 333 333 500 500 556 556 556 278 537 350 222 333 333 556 1000 1000 611 333 333 333 333 333 333 333 333 333 333 333 333 333 1000 1000 370 556 778 1000 365 889 278 222 611 944 611 667 667 667 667 667 667 722 667 667 667 667 722 278 278 278 278 722 778 778 778 778 778 667 667 722 722 722 722 667 667 611 556 556 556 556 556 556 260 500 737 400 584 556 556 556 556 556 278 278 278 278 584 584 556 584 556 556 556 556 556 834 834 333 556 584 737 500 556 834 333 1000 333 556 556 556 556 500)))
'("Helvetica-Oblique" 32 #(278 278 355 556 556 889 667 222 333 333 389 584 278 333 278 278 556 556 556 556 556 556 556 556 556 556 278 278 584 584 584 556 1015 667 667 722 722 667 611 778 722 278 500 667 556 833 722 778 667 778 722 667 611 722 667 944 667 667 611 278 278 278 469 556 222 556 556 500 556 556 278 556 556 222 222 500 222 833 556 556 556 556 333 500 278 556 500 722 500 500 500 334 260 334 584 333 556 556 167 556 556 556 556 191 333 556 333 333 500 500 556 556 556 278 537 350 222 333 333 556 1000 1000 611 333 333 333 333 333 333 333 333 333 333 333 333 333 1000 1000 370 556 778 1000 365 889 278 222 611 944 611 667 667 667 667 667 667 722 667 667 667 667 722 278 278 278 278 722 778 778 778 778 778 667 667 722 722 722 722 667 667 611 556 556 556 556 556 556 260 500 737 400 584 556 556 556 556 556 278 278 278 278 584 584 556 584 556 556 556 556 556 834 834 333 556 584 737 500 556 834 333 1000 333 556 556 556 556 500)))
(define times-info
;'("Times-Roman" 32 #228(250 333 408 500 500 833 778 333 333 333 500 564 250 333 250 278 500 500 500 500 500 500 500 500 500 500 278 278 564 564 564 444 921 722 667 667 722 611 556 722 722 333 389 722 611 889 722 722 556 722 667 556 611 722 722 944 722 722 611 333 278 333 469 500 333 444 500 444 500 444 333 500 500 278 278 500 278 778 500 500 500 500 333 389 278 500 500 722 500 500 444 480 200 480 541 333 500 500 167 500 500 500 500 180 444 500 333 333 556 556 500 500 500 250 453 350 333 444 444 500 1000 1000 444 333 333 333 333 333 333 333 333 333 333 333 333 333 1000 889 276 611 722 889 310 667 278 278 500 722 500 722 722 722 722 722 722 667 611 611 611 611 722 333 333 333 333 722 722 722 722 722 722 556 556 722 722 722 722 722 722 611 444 444 444 444 444 444 200 444 760 400 564 444 444 444 444 500 278 278 278 278 564 564 500 564 500 500 500 500 500 750 750 300 500 564 760 389 500 750 300 980 300 500 500 500 500 500 500 444)))
'("Times-Roman" 32 #(250 333 408 500 500 833 778 333 333 333 500 564 250 333 250 278 500 500 500 500 500 500 500 500 500 500 278 278 564 564 564 444 921 722 667 667 722 611 556 722 722 333 389 722 611 889 722 722 556 722 667 556 611 722 722 944 722 722 611 333 278 333 469 500 333 444 500 444 500 444 333 500 500 278 278 500 278 778 500 500 500 500 333 389 278 500 500 722 500 500 444 480 200 480 541 333 500 500 167 500 500 500 500 180 444 500 333 333 556 556 500 500 500 250 453 350 333 444 444 500 1000 1000 444 333 333 333 333 333 333 333 333 333 333 333 333 333 1000 889 276 611 722 889 310 667 278 278 500 722 500 722 722 722 722 722 722 667 611 611 611 611 722 333 333 333 333 722 722 722 722 722 722 556 556 722 722 722 722 722 722 611 444 444 444 444 444 444 200 444 760 400 564 444 444 444 444 500 278 278 278 278 564 564 500 564 500 500 500 500 500 750 750 300 500 564 760 389 500 750 300 980 300 500 500 500 500 500 500 444)))
(define times-bold-info
;'("Times-Bold" 32 #228(250 333 555 500 500 1000 833 333 333 333 500 570 250 333 250 278 500 500 500 500 500 500 500 500 500 500 333 333 570 570 570 500 930 722 667 722 722 667 611 778 778 389 500 778 667 944 722 778 611 778 722 556 667 722 722 1000 722 722 667 333 278 333 581 500 333 500 556 444 556 444 333 500 556 278 333 556 278 833 556 500 556 556 444 389 333 556 500 722 500 500 444 394 220 394 520 333 500 500 167 500 500 500 500 278 500 500 333 333 556 556 500 500 500 250 540 350 333 500 500 500 1000 1000 500 333 333 333 333 333 333 333 333 333 333 333 333 333 1000 1000 300 667 778 1000 330 722 278 278 500 722 556 722 722 722 722 722 722 722 667 667 667 667 722 389 389 389 389 722 778 778 778 778 778 556 611 722 722 722 722 722 722 667 500 500 500 500 500 500 220 444 747 400 570 444 444 444 444 500 278 278 278 278 570 570 556 570 556 500 500 500 500 750 750 300 500 570 747 389 556 750 300 1000 300 556 556 556 556 500 500 444)))
'("Times-Bold" 32 #(250 333 555 500 500 1000 833 333 333 333 500 570 250 333 250 278 500 500 500 500 500 500 500 500 500 500 333 333 570 570 570 500 930 722 667 722 722 667 611 778 778 389 500 778 667 944 722 778 611 778 722 556 667 722 722 1000 722 722 667 333 278 333 581 500 333 500 556 444 556 444 333 500 556 278 333 556 278 833 556 500 556 556 444 389 333 556 500 722 500 500 444 394 220 394 520 333 500 500 167 500 500 500 500 278 500 500 333 333 556 556 500 500 500 250 540 350 333 500 500 500 1000 1000 500 333 333 333 333 333 333 333 333 333 333 333 333 333 1000 1000 300 667 778 1000 330 722 278 278 500 722 556 722 722 722 722 722 722 722 667 667 667 667 722 389 389 389 389 722 778 778 778 778 778 556 611 722 722 722 722 722 722 667 500 500 500 500 500 500 220 444 747 400 570 444 444 444 444 500 278 278 278 278 570 570 556 570 556 500 500 500 500 750 750 300 500 570 747 389 556 750 300 1000 300 556 556 556 556 500 500 444)))
(define times-bolditalic-info
;'("Times-BoldItalic" 32 #228(250 389 555 500 500 833 778 333 333 333 500 570 250 333 250 278 500 500 500 500 500 500 500 500 500 500 333 333 570 570 570 500 832 667 667 667 722 667 667 722 778 389 500 667 611 889 722 722 611 722 667 556 611 722 667 889 667 611 611 333 278 333 570 500 333 500 500 444 500 444 333 500 556 278 278 500 278 778 556 500 500 500 389 389 278 556 444 667 500 444 389 348 220 348 570 389 500 500 167 500 500 500 500 278 500 500 333 333 556 556 500 500 500 250 500 350 333 500 500 500 1000 1000 500 333 333 333 333 333 333 333 333 333 333 333 333 333 1000 944 266 611 722 944 300 722 278 278 500 722 500 667 667 667 667 667 667 667 667 667 667 667 722 389 389 389 389 722 722 722 722 722 722 556 611 722 722 722 722 611 611 611 500 500 500 500 500 500 220 444 747 400 570 444 444 444 444 500 278 278 278 278 606 606 576 570 556 500 500 500 500 750 750 300 500 570 747 389 500 750 300 1000 300 556 556 556 556 444 444 389)))
'("Times-BoldItalic" 32 #(250 389 555 500 500 833 778 333 333 333 500 570 250 333 250 278 500 500 500 500 500 500 500 500 500 500 333 333 570 570 570 500 832 667 667 667 722 667 667 722 778 389 500 667 611 889 722 722 611 722 667 556 611 722 667 889 667 611 611 333 278 333 570 500 333 500 500 444 500 444 333 500 556 278 278 500 278 778 556 500 500 500 389 389 278 556 444 667 500 444 389 348 220 348 570 389 500 500 167 500 500 500 500 278 500 500 333 333 556 556 500 500 500 250 500 350 333 500 500 500 1000 1000 500 333 333 333 333 333 333 333 333 333 333 333 333 333 1000 944 266 611 722 944 300 722 278 278 500 722 500 667 667 667 667 667 667 667 667 667 667 667 722 389 389 389 389 722 722 722 722 722 722 556 611 722 722 722 722 611 611 611 500 500 500 500 500 500 220 444 747 400 570 444 444 444 444 500 278 278 278 278 606 606 576 570 556 500 500 500 500 750 750 300 500 570 747 389 500 750 300 1000 300 556 556 556 556 444 444 389)))
(define times-italic-info
;'("Times-Italic" 32 #228(250 333 420 500 500 833 778 333 333 333 500 675 250 333 250 278 500 500 500 500 500 500 500 500 500 500 333 333 675 675 675 500 920 611 611 667 722 611 611 722 722 333 444 667 556 833 667 722 611 722 611 500 556 722 611 833 611 556 556 389 278 389 422 500 333 500 500 444 500 444 278 500 500 278 278 444 278 722 500 500 500 500 389 389 278 500 444 667 444 444 389 400 275 400 541 389 500 500 167 500 500 500 500 214 556 500 333 333 500 500 500 500 500 250 523 350 333 556 556 500 889 1000 500 333 333 333 333 333 333 333 333 333 333 333 333 333 889 889 276 556 722 944 310 667 278 278 500 667 500 611 611 611 611 611 611 667 611 611 611 611 722 333 333 333 333 667 722 722 722 722 722 500 611 722 722 722 722 556 556 556 500 500 500 500 500 500 275 444 760 400 675 444 444 444 444 500 278 278 278 278 675 675 500 675 500 500 500 500 500 750 750 300 500 675 760 389 500 750 300 980 300 500 500 500 500 444 444 389)))
'("Times-Italic" 32 #(250 333 420 500 500 833 778 333 333 333 500 675 250 333 250 278 500 500 500 500 500 500 500 500 500 500 333 333 675 675 675 500 920 611 611 667 722 611 611 722 722 333 444 667 556 833 667 722 611 722 611 500 556 722 611 833 611 556 556 389 278 389 422 500 333 500 500 444 500 444 278 500 500 278 278 444 278 722 500 500 500 500 389 389 278 500 444 667 444 444 389 400 275 400 541 389 500 500 167 500 500 500 500 214 556 500 333 333 500 500 500 500 500 250 523 350 333 556 556 500 889 1000 500 333 333 333 333 333 333 333 333 333 333 333 333 333 889 889 276 556 722 944 310 667 278 278 500 667 500 611 611 611 611 611 611 667 611 611 611 611 722 333 333 333 333 667 722 722 722 722 722 500 611 722 722 722 722 556 556 556 500 500 500 500 500 500 275 444 760 400 675 444 444 444 444 500 278 278 278 278 675 675 500 675 500 500 500 500 500 750 750 300 500 675 760 389 500 750 300 980 300 500 500 500 500 444 444 389)))
(define symbol-info
;'("Symbol" 32 #189(250 333 713 500 549 833 778 439 333 333 500 549 250 549 250 278 500 500 500 500 500 500 500 500 500 500 278 278 549 549 549 444 549 722 667 722 612 611 763 603 722 333 631 722 686 889 722 722 768 741 556 592 611 690 439 768 645 795 611 333 863 333 658 500 500 631 549 549 494 439 521 411 603 329 603 549 549 576 521 549 549 521 549 603 439 576 713 686 493 686 494 480 200 480 549 620 247 549 167 713 500 753 753 753 753 1042 987 603 987 603 400 549 411 549 549 713 494 460 549 549 549 549 1000 603 1000 658 823 686 795 987 768 768 823 768 768 713 713 713 713 713 713 713 768 713 790 790 890 823 549 250 713 603 603 1042 987 603 987 603 494 329 790 790 786 713 384 384 384 384 384 384 494 494 494 494 329 274 686 686 686 384 384 384 384 384 384 494 494 494 790)))
'("Symbol" 32 #(250 333 713 500 549 833 778 439 333 333 500 549 250 549 250 278 500 500 500 500 500 500 500 500 500 500 278 278 549 549 549 444 549 722 667 722 612 611 763 603 722 333 631 722 686 889 722 722 768 741 556 592 611 690 439 768 645 795 611 333 863 333 658 500 500 631 549 549 494 439 521 411 603 329 603 549 549 576 521 549 549 521 549 603 439 576 713 686 493 686 494 480 200 480 549 620 247 549 167 713 500 753 753 753 753 1042 987 603 987 603 400 549 411 549 549 713 494 460 549 549 549 549 1000 603 1000 658 823 686 795 987 768 768 823 768 768 713 713 713 713 713 713 713 768 713 790 790 890 823 549 250 713 603 603 1042 987 603 987 603 494 329 790 790 786 713 384 384 384 384 384 384 494 494 494 494 329 274 686 686 686 384 384 384 384 384 384 494 494 494 790)))
(define zapfdingbats-info
;'("ZapfDingbats" 32 #202(278 974 961 974 980 719 789 790 791 690 960 939 549 855 911 933 911 945 974 755 846 762 761 571 677 763 760 759 754 494 552 537 577 692 786 788 788 790 793 794 816 823 789 841 823 833 816 831 923 744 723 749 790 792 695 776 768 792 759 707 708 682 701 826 815 789 789 707 687 696 689 786 787 713 791 785 791 873 761 762 762 759 759 892 892 788 784 438 138 277 415 392 392 668 668 732 544 544 910 667 760 760 776 595 694 626 788 788 788 788 788 788 788 788 788 788 788 788 788 788 788 788 788 788 788 788 788 788 788 788 788 788 788 788 788 788 788 788 788 788 788 788 788 788 788 788 894 838 1016 458 748 924 748 918 927 928 928 834 873 828 924 924 917 930 931 463 883 836 836 867 867 696 696 874 874 760 946 771 865 771 888 967 888 831 873 927 970 918 410 509 334 509 390 234 276 390 410 317 317 276 334 234)))
'("ZapfDingbats" 32 #(278 974 961 974 980 719 789 790 791 690 960 939 549 855 911 933 911 945 974 755 846 762 761 571 677 763 760 759 754 494 552 537 577 692 786 788 788 790 793 794 816 823 789 841 823 833 816 831 923 744 723 749 790 792 695 776 768 792 759 707 708 682 701 826 815 789 789 707 687 696 689 786 787 713 791 785 791 873 761 762 762 759 759 892 892 788 784 438 138 277 415 392 392 668 668 732 544 544 910 667 760 760 776 595 694 626 788 788 788 788 788 788 788 788 788 788 788 788 788 788 788 788 788 788 788 788 788 788 788 788 788 788 788 788 788 788 788 788 788 788 788 788 788 788 788 788 894 838 1016 458 748 924 748 918 927 928 928 834 873 828 924 924 917 930 931 463 883 836 836 867 867 696 696 874 874 760 946 771 865 771 888 967 888 831 873 927 970 918 410 509 334 509 390 234 276 390 410 317 317 276 334 234)))
(define (add-predefined-font-info lst)
(let ((font-info (make-font-info (car lst) (cadr lst) (caddr lst))))
(add-font-info font-info)))
(define (init-predefined-fonts)
(add-predefined-font-info courier-info)
(add-predefined-font-info courier-bold-info)
(add-predefined-font-info courier-boldoblique-info)
(add-predefined-font-info courier-oblique-info)
(add-predefined-font-info helvetica-info)
(add-predefined-font-info helvetica-bold-info)
(add-predefined-font-info helvetica-boldoblique-info)
(add-predefined-font-info helvetica-oblique-info)
(add-predefined-font-info times-info)
(add-predefined-font-info times-bold-info)
(add-predefined-font-info times-bolditalic-info)
(add-predefined-font-info times-italic-info)
(add-predefined-font-info symbol-info)
(add-predefined-font-info zapfdingbats-info))
(init-predefined-fonts))
| false |
936266f3ea524faef0710d9bdf2d6f25be7754ad | b60cb8e39ec090137bef8c31ec9958a8b1c3e8a6 | /test/concurrentScheme/futures/variations/indexer3.scm | d62d7853c28b39ef97eb43111416ee03b57ce30e | []
| 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 | 1,074 | scm | indexer3.scm | ;; Example taken from Dynamic Partial Order Reduction, Figure 1
;; Expected result: #t
(let* ((size 128)
(max 4)
(table (atom (make-vector size 0)))
(thread (lambda (tid)
(letrec ((hash (lambda (w) (modulo (* w 7) size)))
(process (lambda (m)
(if (< m max)
(letrec ((w (+ (* 11 (+ m 1)) tid))
(update (lambda (h)
(if (swap! table (lambda (v) (vector-set! v h w)))
#t
(update (modulo (+ h 1) size))))))
(update (hash w))
(process (+ m 1)))
#t))))
(process 0))))
(t1 (future (thread 1)))
(t2 (future (thread 2)))
(t3 (future (thread 3))))
(and
(deref t1)
(deref t2)
(deref t3)))
| false |
20f2d30dbf12aa40ba20e74c6a5cd5a2089aa1f0 | d8bdd07d7fff442a028ca9edbb4d66660621442d | /scam/tests/10-scheme/00-base/pred/eqivalance/eq-special.scm | 1ca0cb7a51262d939cdd48ef58f308f213fedb4c | []
| 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 | 168 | scm | eq-special.scm | (import (only (scheme base) eq?)
(test narc))
(narc-label "Eq? Special")
(narc-catch
(:args (eq?))
(:args (eq? #t))
(:args (eq? #t #t #t)))
(narc-report)
| false |
ef75906afe57c2954be6cc9303a0df0bd6de0c4f | 176c0402e114158d171599293f9711445b812111 | /examples/3_classes.scm | c571319813f90a4c8ada5313bebb2554f7e7e843 | []
| no_license | ttu-fpclub/kawa-chess | ad1b215780c5af0605f2370d384cd1cf99a49fa5 | f1d2dcc707a1ef19dc159e2eaee5aecc8a41d7a8 | refs/heads/master | 2021-01-12T17:05:54.407585 | 2016-10-20T21:40:45 | 2016-10-20T21:40:45 | 71,502,061 | 2 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 1,361 | scm | 3_classes.scm |
; This is a genuine Java class and can be treated as such
(define-simple-class Person ()
; In true Lisp spirit, fields are public by default
(name init: "John Smith")
; Restricted access fields are available, however
(ssn init: '123-45-6789 access: 'private)
; Constructors follow the same rules as in Java; if none are specified, a default one exists
((*init* pname pssn)
; You can just "pretend" the instance variables are in scope, like you can in Java and C++
(set! name pname)
(set! ssn pssn))
; Getters are easy to write in Scheme's concise function syntax
((getSSN)
ssn)
; Overriding methods is equally easy
((toString)
((string-append "[Person " (name:toString) " " ((getOccupation):toString) "]"):toString))
; Lisp types and Java types can be pretty freely mixed
((getOccupation)
'none))
; Subclassing works just the way you'd expect
(define-simple-class Student (Person)
; Need constructor since Person has no default one
((*init* name ssn)
(invoke-special Person (this) '*init* name ssn))
; Overriding parent method
((getOccupation)
'student))
; Constructors are called simply using the class name as the function name
(let ((per (Person "Steve" '111-11-1111))
(stu (Student "Jack" '222-22-2222)))
(display per)
(display stu)
(display "\n"))
| false |
6f45063ee080673336721eede5a482fe60c68f00 | defeada37d39bca09ef76f66f38683754c0a6aa0 | /UnityEngine/unity-engine/guilayout-group.sls | 6a5e0de02462fd869e6d07f23c45c71be6e5cd51 | []
| 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 | 3,760 | sls | guilayout-group.sls | (library (unity-engine guilayout-group)
(export new
is?
guilayout-group?
add
reset-cursor
set-vertical
set-horizontal
calc-height
peek-next
apply-options
calc-width
get-next
get-last
to-string
entries-get
entries-set!
entries-update!
is-vertical?-get
is-vertical?-set!
is-vertical?-update!
reset-coords?-get
reset-coords?-set!
reset-coords?-update!
spacing-get
spacing-set!
spacing-update!
same-size?-get
same-size?-set!
same-size?-update!
is-window?-get
is-window?-set!
is-window?-update!
window-id-get
window-id-set!
window-id-update!
margin)
(import (ironscheme-clr-port))
(define-syntax new
(lambda (e)
(syntax-case e ()
((_ a ...) #'(clr-new UnityEngine.GUILayoutGroup a ...)))))
(define (is? a) (clr-is UnityEngine.GUILayoutGroup a))
(define (guilayout-group? a) (clr-is UnityEngine.GUILayoutGroup a))
(define-method-port
add
UnityEngine.GUILayoutGroup
Add
(System.Void UnityEngine.GUILayoutEntry))
(define-method-port
reset-cursor
UnityEngine.GUILayoutGroup
ResetCursor
(System.Void))
(define-method-port
set-vertical
UnityEngine.GUILayoutGroup
SetVertical
(System.Void System.Single System.Single))
(define-method-port
set-horizontal
UnityEngine.GUILayoutGroup
SetHorizontal
(System.Void System.Single System.Single))
(define-method-port
calc-height
UnityEngine.GUILayoutGroup
CalcHeight
(System.Void))
(define-method-port
peek-next
UnityEngine.GUILayoutGroup
PeekNext
(UnityEngine.Rect))
(define-method-port
apply-options
UnityEngine.GUILayoutGroup
ApplyOptions
(System.Void UnityEngine.GUILayoutOption[]))
(define-method-port
calc-width
UnityEngine.GUILayoutGroup
CalcWidth
(System.Void))
(define-method-port
get-next
UnityEngine.GUILayoutGroup
GetNext
(UnityEngine.GUILayoutEntry))
(define-method-port
get-last
UnityEngine.GUILayoutGroup
GetLast
(UnityEngine.Rect))
(define-method-port
to-string
UnityEngine.GUILayoutGroup
ToString
(System.String))
(define-field-port
entries-get
entries-set!
entries-update!
()
UnityEngine.GUILayoutGroup
entries
"System.Collections.Generic.List`1[[UnityEngine.GUILayoutEntry, UnityEngine, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null]]")
(define-field-port
is-vertical?-get
is-vertical?-set!
is-vertical?-update!
()
UnityEngine.GUILayoutGroup
isVertical
System.Boolean)
(define-field-port
reset-coords?-get
reset-coords?-set!
reset-coords?-update!
()
UnityEngine.GUILayoutGroup
resetCoords
System.Boolean)
(define-field-port
spacing-get
spacing-set!
spacing-update!
()
UnityEngine.GUILayoutGroup
spacing
System.Single)
(define-field-port
same-size?-get
same-size?-set!
same-size?-update!
()
UnityEngine.GUILayoutGroup
sameSize
System.Boolean)
(define-field-port
is-window?-get
is-window?-set!
is-window?-update!
()
UnityEngine.GUILayoutGroup
isWindow
System.Boolean)
(define-field-port
window-id-get
window-id-set!
window-id-update!
()
UnityEngine.GUILayoutGroup
windowID
System.Int32)
(define-field-port
margin
#f
#f
(property:)
UnityEngine.GUILayoutGroup
margin
UnityEngine.RectOffset))
| true |
e5f54211d755310fb62f918ede49979bbad76361 | 23a00b9f5709b38169e0514cd3965d8b6f1f3863 | /lib/compiler/utils/regex/misc.scm | 73b5c021822a95b433b4a64e863c9ed0d5a4a923 | []
| no_license | uson-compiladores/r7rs-scheme | cd80812ed335fa24e78522005df95ccdfbb544c4 | dd88b31b260687aa9c702b659d54a7a3f60c7047 | refs/heads/master | 2021-01-10T02:09:16.711983 | 2015-12-01T01:04:56 | 2015-12-01T01:04:56 | 45,621,985 | 0 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 63 | scm | misc.scm | (define (compound? x)
(and (pair? x) (not (null? (cdr x)))))
| false |
bfab42ee755b65dfe7fdccef26a5d0424e187dc3 | 73b5d880fa06943c20ff0a9aee9d0c1d1eeebe10 | /tinyos-2.x-contrib/sensorscheme/scripts/emptybase/emptybase.scm | 6ccca4d880e4a1f013a533fadba9adcd8bff467a | []
| no_license | x3ro/tinyos-legacy | 101d19f9e639f5a9d59d3edd4ed04b1f53221e63 | cdc0e7ba1cac505fcace33b974b2e0aca1ccc56a | refs/heads/master | 2021-01-16T19:20:21.744228 | 2015-06-30T20:23:05 | 2015-06-30T20:23:05 | 38,358,728 | 0 | 1 | null | null | null | null | UTF-8 | Scheme | false | false | 423 | scm | emptybase.scm | (ssmodule emptybase
(require (lib std) (lib network))
(include send-local null? cdr car recv-local/ack)
(define (blink0 t ls)
(call-at-time (+ t 16) (lambda (t) (blink0 t (cons t ls))))
(let ([m (msg blink1 t ls)])
#;(print m)
(when (= id 0)
(send-local/ack (+ id 1) m))))
(define-handler (blink1 t ls)
(print t ls)
(blink (/ t 16)))
(blink0 (+ (now) 64) ())
) | false |
c2ba3187d2e45697f1e11cc1471f6e8878ded529 | 46244bb6af145cb393846505f37bf576a8396aa0 | /sicp/3_7.scm | 5f9ae80dc3a425dd2bde631e457361005731fa07 | []
| 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 | 2,054 | scm | 3_7.scm | #lang racket
; Exercise 3.7. Consider the bank account objects created by make-account,
; with the password modification described in exercise 3.3.
; Suppose that our banking system requires the ability to make joint accounts.
; Define a procedure make-joint that accomplishes this. Make-joint should take three
; arguments. The first is a password-protected account. The second argument must match
; the password with which the account was defined in order for the make-joint operation to proceed.
; The third argument is a new password. Make-joint is to create an additional access to
; the original account using the new password. For example,
; if peter-acc is a bank account with password open-sesame, then
; (define paul-acc
; (make-joint peter-acc 'open-sesame 'rosebud))
(define (make-account balance pwd)
(define (withdraw amount)
(if (>= balance amount)
(begin (set! balance (- balance amount))
balance)
"Insufficient funds"))
(define (deposit amount)
(set! balance (+ balance amount))
balance)
(define (dispatch pwd-input m)
; add the universal password check before dispatch
(if (eq? pwd pwd-input)
(cond ((eq? m 'withdraw) withdraw)
((eq? m 'deposit) deposit)
(else (error "Unknown request -- MAKE-ACCOUNT"
m)))
(error "Incorrect pasword")))
dispatch)
(define (make-joint acc ori-pwd new-pwd)
((acc ori-pwd 'withdraw) 0)
(define (dispatch pwd-input m)
(if (eq? new-pwd pwd-input)
(acc ori-pwd m)
(error "incorrect password")))
dispatch)
(define acc (make-account 100 'secret-password))
((acc 'secret-password 'withdraw) 40)
((acc 'secret-password 'withdraw) 40)
; ((acc 'some-other-password 'deposit) 50)
(define acc1 (make-account 100 'secret-password))
(define jacc (make-joint acc1 'secret-password 'jpassword))
((jacc 'jpassword 'withdraw) 40)
((jacc 'jpassword 'withdraw) 40)
((jacc 'jpassword 'deposit) 50)
(define invalid-acc (make-joint acc1 'wrong-password 'jpassword)) | false |
2f9f975833c4b33a3d88d789adc5a4b9ff5058bd | f5083e14d7e451225c8590cc6aabe68fac63ffbd | /cs/01-Programming/cs61a/exercises/15_week_11.scm | 841c8850ccc851ec339a01f8e91cadbdaf5a9043 | []
| no_license | Phantas0s/playground | a362653a8feb7acd68a7637334068cde0fe9d32e | c84ec0410a43c84a63dc5093e1c214a0f102edae | refs/heads/master | 2022-05-09T06:33:25.625750 | 2022-04-19T14:57:28 | 2022-04-19T14:57:28 | 136,804,123 | 19 | 5 | null | 2021-03-04T14:21:07 | 2018-06-10T11:46:19 | Racket | UTF-8 | Scheme | false | false | 1,102 | scm | 15_week_11.scm | ; Write and test two functions to manipulate nonnegative proper fractions. The first
; function, fract-stream, will take as its argument a list of two nonnegative integers, the
; numerator and the denominator, in which the numerator is less than the denominator. It
; will return an infinite stream of decimal digits representing the decimal expansion of the
; fraction. The second function, approximation, will take two arguments: a fraction stream
; and a nonnegative integer numdigits. It will return a list (not a stream) containing the
; first numdigits digits of the decimal expansion.
; (fract-stream (1 7)) should return the stream representing the decimal expansion of
; 1/7, which is 0.142857142857142857...
; (stream-car (fract-stream '(1 7))) should return 1.
; (stream-car (stream-cdr (stream-cdr (fract-stream '(1 7))))) should return 2.
; (approximation (fract-stream '(1 7)) 4) should return (1 4 2 8)
; (approximation (fract-stream '(1 2)) 4) should return (5 0 0 0)
; It's a pain to load eveything in scheme... especially the div part
; I'll come back to that later...
; **WRONG**
| false |
988c0110d0cdee53c7522cad2c1b376679872a74 | b1b1e288efe8621f2bf2c8bc3eea9e30fc251501 | /experiments/tconcappend/tconc.ss | bda25e4364d758ca439f3ee6ce1f3c3f41ad8eb2 | [
"ISC"
]
| permissive | lojikil/hydra | 37e32a43afc2443e29a73387fe796b559756a957 | 366cae2e155c6e4d5e27ad19d3183687a40c82a3 | refs/heads/master | 2020-05-30T08:41:19.374996 | 2014-11-13T03:10:22 | 2014-11-13T03:10:22 | 58,539,402 | 5 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 485 | ss | tconc.ss | (load 'base.ss)
;(define (foo x) (display "in foo\n") (tconc-splice! x (base-iota 10)))
;; there's a bug in how Vesta implements tconc_splice; need to fix that first
;; before this can be used to test... well, just about anything.
(define (tconc-test x y)
(if (>= x 0)
(begin
;(foo y)
(tconc-splice! y (make-tconc (base-iota x)))
(tconc-test (- x 1) y))
(tconc->pair y)))
(write (tconc-test 1000 (make-tconc '())))
(newline)
| false |
864196349d71e62f00fe182d402ffbd1f912fd6c | 8a0660bd8d588f94aa429050bb8d32c9cd4290d5 | /sitelib/scheme/time.scm | a7bc1f915751e1f1d855dad1017c98e64c180c08 | [
"BSD-2-Clause"
]
| permissive | david135/sagittarius-scheme | dbec76f6b227f79713169985fc16ce763c889472 | 2fbd9d153c82e2aa342bfddd59ed54d43c5a7506 | refs/heads/master | 2016-09-02T02:44:31.668025 | 2013-12-21T07:24:08 | 2013-12-21T07:24:08 | 32,497,456 | 0 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 448 | scm | time.scm | ;; -*- mode:scheme; coding: utf-8; -*-
#!compatible
(library (scheme time)
(export current-jiffy current-second jiffies-per-second)
(import (rnrs)
(srfi :19))
(define scale 1000000000)
(define (jiffies-per-second) scale)
(define (current-jiffy) (exact (round (* (current-second) scale))))
(define (current-second)
(let ((t (current-time time-tai)))
(inexact (+ (/ (time-nanosecond t) scale) (time-second t)))))
)
| false |
153a19668e816d41500b00d7b03598333a2c3586 | 91be92b9d8667a0c5b0b3534c78851d5683aecec | /recordsub-tests.scm | 272534a9cd6001aaebe1736c1fab610eff79c893 | []
| no_license | namin/clpset-miniKanren | ed16d3b0308e7cb49618d5fb792fb313eb7fdbc7 | c0cf0342431b36467cf217555a63a3d0477bd477 | refs/heads/master | 2023-08-14T20:40:07.306798 | 2018-01-30T18:55:39 | 2018-01-30T18:55:39 | 9,198,184 | 6 | 1 | null | null | null | null | UTF-8 | Scheme | false | false | 2,271 | scm | recordsub-tests.scm | (load "recordsub.scm")
(load "test-check.scm")
(test-check "sub-reflexivity-1"
(run 1 (q) (sub `(rcd ,(set ∅ `(a (rcd ,∅)))) `(rcd ,(set ∅ `(a (rcd ,∅))))))
'(_.0))
(test-check "sub-1"
(run 1 (q) (sub `(rcd ,(set ∅ `(a (rcd ,∅)) `(b (rcd ,∅)))) `(rcd ,(set ∅ `(a (rcd ,∅))))))
'(_.0))
(test-check "sub-empty-x-is-empty"
(run* (q)
(sub `(rcd ,∅) q))
'((rcd ∅)))
(test-check "sub-rcd-empty-x-is-empty"
(run* (q)
(sub-rcd ∅ q))
'(∅))
(test-check "sub-1-x-is"
(run* (q)
(sub `(rcd ,(set ∅ `(a (rcd ,∅)))) q))
'((rcd (set ∅ (a (rcd ∅)))) (rcd ∅)))
(test-check "fail-sub-1"
(run* (q) (sub `(rcd ,(set ∅ `(a (rcd ,∅)))) `(rcd ,(set ∅ `(a (rcd ,∅)) `(b (rcd ,∅))))))
'())
(test-check "tc-id"
(run* (q) (tc `(lambda (x) x) ∅ q))
`((arr _.0 _.0)))
(test-check "tc-lam-2"
(run* (q) (tc `(lambda (x) (lambda (y) x)) ∅ q))
'((arr _.0 (arr _.1 _.0))))
(test-check "tc-lam-3"
(run* (q) (tc `(lambda (x) (lambda (y) y)) ∅ q))
'((arr _.0 (arr _.1 _.1))))
(test-check "tc-app-1"
(run* (q) (tc `(lambda (f) (lambda (x) (app f x))) ∅ q))
'((arr (arr _.0 _.1) (arr _.0 _.1))))
(test-check "tc-new-0"
(run* (q) (tc `(new ,∅) ∅ q))
'((rcd ∅)))
(test-check "tc-new-1"
(run* (q) (tc `(new ,(set ∅ `(foo (lambda (x) x)))) ∅ q))
'((rcd (set ∅ (foo (arr _.0 _.0))))))
(test-check "tc-new-2"
(car (run* (q) (tc `(new ,(set ∅ `(foo (lambda (x) x)) `(bar (lambda (x) x)))) ∅ q)))
'(rcd (set ∅ (bar (arr _.0 _.0)) (foo (arr _.1 _.1)))))
(test-check "tc-rcd-2"
(car (run* (q) (tc-rcd (set ∅ `(foo (lambda (x) x)) `(bar (lambda (x) x))) ∅ q)))
'(set ∅ (bar (arr _.0 _.0)) (foo (arr _.1 _.1))))
(test-check "tc-sel-1"
(run* (q) (tc `(sel (new ,(set ∅ `(foo (lambda (x) x)))) foo) ∅ q))
'((arr _.0 _.0)))
(test-check "tc-sel-2"
(run* (q) (tc `(app (lambda (x) (sel x foo)) (new ,(set ∅ `(foo (lambda (x) x))))) ∅ q))
'((arr _.0 _.0)))
(test-check "tc-sel-3"
(car (run* (q) (tc `(app (lambda (x) (sel x foo)) (new ,(set ∅ `(foo (lambda (x) x)) `(bar (lambda (x) x))))) ∅ q)))
'(arr _.0 _.0))
(test-check "tc-sel-4"
(run* (q) (tc `(lambda (x) (sel x foo)) ∅ q))
'(((arr (rcd (set _.0 (foo _.1))) _.1) : (set _.0))))
| false |
6cffff9ebd2fdb621601fb162f17da6af030fb35 | 4b480cab3426c89e3e49554d05d1b36aad8aeef4 | /chapter-04/ch4-myeval-pkg-gsong.scm | 1291e385ed96e795a67c9e000f3ed38b25b4a576 | []
| no_license | tuestudy/study-sicp | a5dc423719ca30a30ae685e1686534a2c9183b31 | a2d5d65e711ac5fee3914e45be7d5c2a62bfc20f | refs/heads/master | 2021-01-12T13:37:56.874455 | 2016-10-04T12:26:45 | 2016-10-04T12:26:45 | 69,962,129 | 0 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 2,456 | scm | ch4-myeval-pkg-gsong.scm | (load "../misc/myeval-helper.scm")
(load "../misc/local-table.scm")
(load "ex4.04-comkid2.scm")
(load "ex4.05-comkid.scm")
(load "ex4.06-comkid.scm")
(load "ex4.07-comkid.scm")
(load "ex4.08-gsong.scm")
(load "ex4.09-gsong.scm")
(load "ex4.11-gsong.scm")
(load "ex4.12-gsong.scm")
(load "ex4.13-gsong.scm")
(load "ex4.14-gsong.scm")
(load "ex4.16-gsong.scm")
(load "ex4.20-gsong.scm")
;
; myeval-package
;
(define (install-myeval-package)
(define (text-of-quotation_ exp env) (text-of-quotation exp))
(define (make-procedure_ exp env)
(make-procedure
(lambda-parameters exp)
(lambda-body exp)
env))
(define (eval-begin exp env)
(eval-sequence (begin-actions exp) env))
(define (eval-let exp env)
(myeval (let->combination exp) env))
(define (eval-let* exp env)
(myeval (let*->nested-lets exp) env))
(define (eval-while exp env)
(myeval (while->named-let exp) env))
(put 'quote 'eval text-of-quotation_)
(put 'set! 'eval eval-assignment)
(put 'define 'eval eval-definition)
(put 'if 'eval eval-if)
(put 'lambda 'eval make-procedure_)
(put 'begin 'eval eval-begin)
(put 'cond 'eval eval-cond)
(put 'and 'eval eval-and)
(put 'or 'eval eval-or)
(put 'let 'eval eval-let)
(put 'let* 'eval eval-let*)
(put 'while 'eval eval-while)
'done)
(install-myeval-package)
;
; myapply
;
(define (myapply procedure arguments)
(cond ((primitive-procedure? procedure)
(apply-primitive-procedure procedure arguments))
((compound-procedure? procedure)
(eval-sequence
(procedure-body procedure)
(extend-environment
(procedure-parameters procedure)
arguments
(procedure-environment procedure))))
(else
(error
"Unknown procedure type -- APPLY" procedure))))
;
; myeval
;
(define (variable? exp)
(if (eq? exp 'let) #f
(symbol? exp)))
(define (myeval exp env)
(define (operator exp) (car exp))
(define (operands exp) (cdr exp))
(cond
((null? exp) (display "MYEVAL NULL EXPRESSION") (newline) '())
((self-evaluating? exp) exp)
((variable? exp) (lookup-variable-value exp env))
(else
(let ((op (get (operator exp) 'eval)))
(if op
(op exp env)
(myapply (myeval (operator exp) env)
(list-of-values (operands exp) env)))))))
| false |
d8357af80a1e8cb116351f4dff77a040978e2907 | cc1b70c61dc6ed659ce2ba06aa9e04bf5dfb47e8 | /interface.scm | 9901ed0b638cd32c6faed5c39ec6f0309045590c | []
| no_license | philhofer/srcc | a99a6c496ad77706fe4a07e4b2d9f27d11ad69a5 | fd78a8c8987df2ec4b034c202bcb00bdb951be23 | refs/heads/master | 2023-08-27T21:38:59.031046 | 2019-06-06T01:10:54 | 2019-06-06T01:10:54 | 190,252,580 | 0 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 8,964 | scm | interface.scm | (module
interface
(;export
bundle
flatten1
loopback
wireless
ether
bridge
l3-static
net-longrun
l3-auto
l2-auto
hotplug
coldplug)
(import
scheme
srfi-1
list-utils
(chicken format)
(chicken base)
(chicken module))
;; interfaces are represented as alists
;; that have at least the following fields:
;;
;; name: the name of the interface
;; type: the type of the interface
;; l1, l2, l3: if present, functions like (fn name options)
;; that produce s6-rc service definitions for
;; each layer of the network stack
;;
;; join a series of lines together for an execline
;; script such that all but the last line are wrapped
;; with 'if { line }'
(define (execline-join lines)
(cons "#!/bin/execlineb -P"
(if (string? lines)
(list lines)
(let loop ([out '()]
[rest lines])
(cond
[(null? rest) out]
[(null? (cdr rest)) (reverse (cons (car rest) out))]
[else (loop (cons (format "if { ~a }" (car rest)) out)
(cdr rest))])))))
;; (ifopt sym alist expr)
;; produces either (cdr (assq sym alist))
;; lazily computes the value of 'expr'
;; when there is no associated alist entry
;; (analagous to alist-ref with a lazily-evaulated default)
(define-syntax ifopt
(syntax-rules ()
((_ sym opts otherwise)
(let ([val (assq sym opts)])
(if val (cdr val) otherwise)))))
(define (ifopt/null sym opts)
(ifopt sym opts '()))
(define (l2-oneshot up-fn down-fn)
(lambda (name options)
`((type . oneshot)
(up . ,(execline-join (up-fn name options)))
(down . ,(execline-join (down-fn name options)))
(dependencies . ,(flatten
(format "~a.l1" name)
(ifopt/null 'l2-depends options))))))
;; generate the tail of a config given
;; default values for the l{1,2,3} services
(define (config-from name options l1 l2 l3)
`((l1 . ,((ifopt 'l1-config options l1) name options))
(l2 . ,((ifopt 'l2-config options l2) name options))
(l3 . ,((ifopt 'l3-config options l3) name options))))
;; accepted options:
;; (route . (<prefix> . <spec>)...)
;; e.g.
;; (route . (default . "via 192.168.0.1 metric 50")
;; ("192.168.3.0/24" . "via 192.168.3.1"))
(define (l3-with-options up down name options)
;; TODO: support more options than just 'route
(let ([routes (ifopt 'route options #f)]
[uptail (up name options)]
[downtail (down name options)])
(values
(flatten ; up
(if routes
(map
(lambda (rt) (format "ip route add ~a dev ~a ~a" (car rt) name (cdr rt)))
routes)
'())
uptail)
(flatten ; down
(if routes
(map
(lambda (rt) (format "ip route del ~a dev ~a" (car rt) name))
routes)
'())
downtail))))
(define (l3-oneshot up-fn down-fn)
(lambda (name options)
(let-values ([(upln downln)
(l3-with-options up-fn down-fn name options)])
`((type . oneshot)
(up . ,(execline-join upln))
(down . ,(execline-join downln))
(dependencies . ,(cons
(format "~a.l2" name)
(ifopt 'l3-depends options '())))))))
;; l3-static returns an l3 function that
;; applies a list of static addresses to an interface
(define (l3-static . addrs)
(l3-oneshot
(lambda (name options)
(map (cut format "ip addr replace ~a dev ~a valid_lft forever" <> name) addrs))
(lambda (name options)
(map (cut format "ip addr del ~a dev ~a" <> name) addrs))))
;; l2-auto just calls 'ip link set dev ... {up,down}'
(define l2-auto
(l2-oneshot
(lambda (name options)
(format "ip link set dev ~a up" name))
(lambda (name options)
(format "ip link set dev ~a down" name))))
;; coldplugged devices get a placeholder service
;; that fails to come up if the device doesn't coldplug
(define (coldplug name options)
`((type . oneshot)
(up . ,(format "test -d /sys/class/net/~a" name))
(down . "/bin/true")))
(define (hotplug name options)
;; FIXME: implement hot-plug detection
`((type . oneshot)
(up . (format "test -d /sys/class/net/~a" name))
(down . "/bin/true")))
(define (loopback . options)
(net->services
(let ([name (ifopt 'name options "lo")])
`((name . ,name)
(type . loopback)
,@(config-from
name
options
coldplug
l2-auto
(l3-static "127.0.0.1/8 scope host" "::1/128 scope host"))))))
(define (net-longrun level up-fn down-fn)
(lambda (name options)
`((type . longrun)
(run . ,(execline-join (up-fn name options)))
(finish . ,(execline-join (down-fn name options)))
(dependencies . ,(case level
[(l1) (ifopt 'l1-depends options '())]
[(l2) (cons (format "~a.l1" name)
(ifopt 'l2-depends options '()))]
[(l3) (cons (format "~a.l2" name)
(ifopt 'l3-depends options '()))])))))
(define empty-script (lambda (name options) '()))
(define l2-default-wpa
;; TODO: think about not hard-coding the path
;; to the config file here; could get it from options...
(net-longrun
'l2
(lambda (name options)
(list
"fdmove -c 2 1"
(format "wpa_supplicant -c /etc/wpa_supplicant/wpa_supplicant.conf -i ~a" name)))
empty-script))
;; 'automatic' level 3 configuration
;; (use dhcpcd for dhcpv4+slaac)
(define l3-auto
(net-longrun
'l3
(lambda (name options)
(list
"fdmove -c 2 1"
(format "dhcpcd -B ~a" name)))
(lambda (name options)
(format "ip addr flush dev ~a scope global" name))))
;; wireless creates a managed wireless interface
;; (presently, using wpa_supplicant and dhcpcd)
(define (wireless name . options)
(net->services
`((name . ,name)
(type . wireless)
,@(config-from
name
options
coldplug
l2-default-wpa
l3-auto))))
;; ether creates a managed wired interface
(define (ether name . options)
(net->services
`((name . ,name)
(type . hwether)
,@(config-from
name
options
coldplug
l2-auto
l3-auto))))
(define (iface-name iface)
(ifopt 'name iface (error "interface has no name?")))
;; emit all the services for an interface
(define (net->services iface)
(let ([name (iface-name iface)]
[inner (net->level-services iface)])
(cons
`(,name . ((type . bundle)
(contents . ,(if (null? inner) '() (car (car inner))))))
inner)))
;; for an interface, emit the iface.l1, iface.l2, and iface.l3 services
(define (net->level-services iface)
(let* ([name (iface-name iface)]
[stages '(l1 l2 l3)]
[stage-name (lambda (stage)
(format "~a.~a" name (symbol->string stage)))])
(foldl (lambda (lst stage)
(let ([v (assq stage iface)])
(if (or (not v) (not (cdr v)))
lst
(cons (cons (stage-name stage) (cdr v)) lst))))
'()
stages)))
(define (l1-oneshot up-fn down-fn)
(lambda (name options)
`((type . oneshot)
(up . ,(execline-join (up-fn name options)))
(down . ,(execline-join (down-fn name options)))
(dependencies . ,(ifopt 'l1-depends options '())))))
;; l1 service for software-defined interface types
;; (bridge, bond, vlan, vxlan, vether ...)
(define (l1-soft type)
(l1-oneshot
(lambda (name options)
(format "ip link add name ~a type ~a" name type))
(lambda (name options)
(format "ip link del ~a" name))))
;; auto-bridge creates a bridge interface
;;
;; for example:
;; (bridge "br0" '("eth0" "wlan0") l3-auto)
;; bridges "eth0" and "wlan0" and assigns
;; IP addresses using dhcp
;;
;; the bridge interface will automatically
;; depend on the bridged interfaces
;;
;; FIXME: bridges can have interfaces added
;; and removed dynamically; for hotplug depencendies,
;; generate an intermediate service that does the
;; appropriate 'ip link set dev ... master ...'
;;
(define (bridge name interfaces l3-config . options)
(net->services
`((name . ,name)
(type . bridge)
,@(config-from
name
(cons options
;; automatically inserts '<iface>.l2' as a depencency
;; TODO: this could perhaps be <iface>.l1, but the behavior
;; under those circumstances is less clear
(cons 'l2-depends (map (cut format "~a.l2" <>) interfaces)))
(l1-soft "bridge")
(l2-oneshot
(lambda (name options)
(append
(map (lambda (sub)
(format "ip link set dev ~a master ~a" sub name))
interfaces)
(format "ip link set dev ~a up" name)))
(lambda (name options)
(map (lambda (sub)
(format "ip link set dev ~a nomaster" sub))
interfaces)
(format "ip link set dev ~a down" name)))
l3-config))))
(define (bundle name . contents)
`((,name (type . bundle)
(contents . ,contents))))
(define (flatten1 . args)
(let loop ([lst args])
(if (null? lst)
'()
(let ([head (car lst)]
[rest (loop (cdr lst))])
(if (list? head)
(append head rest)
(cons head rest))))))
)
| true |
755a7f93d8ea448494d873fd100bd512ab4ace6f | ec5b4a92882f80b3f62eac8cbd059fb1f000cfd9 | /wcp-functional/!tests/union.ss | 413de6f6308de7819b6740e8ec1dce4e15139729 | []
| 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 | 356 | ss | union.ss | ;;;
;;;
;;;
(define (union set1 set2)
(if (null? set1)
set2
(let ([rr (union (cdr set1) set2)])
(if (member? (car set1) set2)
rr
(cons (car set1) rr)))))
(define (member? item ls)
(if (null? ls)
#f
(if (eq? item (car ls))
#t
(member? item (cdr ls)))))
'(union (make-list size 'unknown) (make-list size 'unknown))
| false |
93ddbd390bf1fda1d192ce9c229dc1f399519c4b | 120324bbbf63c54de0b7f1ca48d5dcbbc5cfb193 | /packages/termios/termios-ffi.ss | adeeb6936ebdfc339a8c2bebca9b0fc36ae3c7f9 | [
"MIT"
]
| permissive | evilbinary/scheme-lib | a6d42c7c4f37e684c123bff574816544132cb957 | 690352c118748413f9730838b001a03be9a6f18e | refs/heads/master | 2022-06-22T06:16:56.203827 | 2022-06-16T05:54:54 | 2022-06-16T05:54:54 | 76,329,726 | 609 | 71 | MIT | 2022-06-16T05:54:55 | 2016-12-13T06:27:36 | Scheme | UTF-8 | Scheme | false | false | 1,632 | ss | termios-ffi.ss | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;作者:evilbinary on 2017-12-06 23:06:57.
;;邮箱:[email protected]
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(library (termios termios )
(export cfgetospeed
cfgetispeed
cfsetospeed
cfsetispeed
tcgetattr
tcsetattr
tcsendbreak
tcdrain
tcflush
tcflow)
(import (scheme) (utils libutil) (cffi cffi) )
(load-librarys "libtermios" )
;;speed_t cfgetospeed(struct termios* __termios_p)
(def-function cfgetospeed
"cfgetospeed" (void*) int)
;;speed_t cfgetispeed(struct termios* __termios_p)
(def-function cfgetispeed
"cfgetispeed" (void*) int)
;;int cfsetospeed(struct termios* __termios_p ,speed_t __speed)
(def-function cfsetospeed
"cfsetospeed" (void* int) int)
;;int cfsetispeed(struct termios* __termios_p ,speed_t __speed)
(def-function cfsetispeed
"cfsetispeed" (void* int) int)
;;int tcgetattr(int __fd ,struct termios* __termios_p)
(def-function tcgetattr
"tcgetattr" (int void*) int)
;;int tcsetattr(int __fd ,int __optional_actions ,struct termios* __termios_p)
(def-function tcsetattr
"tcsetattr" (int int void*) int)
;;int tcsendbreak(int __fd ,int __duration)
(def-function tcsendbreak
"tcsendbreak" (int int) int)
;;int tcdrain(int __fd)
(def-function tcdrain
"tcdrain" (int) int)
;;int tcflush(int __fd ,int __queue_selector)
(def-function tcflush
"tcflush" (int int) int)
;;int tcflow(int __fd ,int __action)
(def-function tcflow
"tcflow" (int int) int)
)
| false |
ce65ada9820c04da87285cc46ec87bd5b5dd8250 | 9ba99213d2aac208dcd1bc86dddeed97a4d2577e | /xlib/keysym.sls | 9dcd094340d3d2c0527332d178dfff312aec2eba | []
| no_license | sahwar/psilab | 19df7449389c8b545a0f1323e2bd6ca5be3e8592 | 16b60e4ae63e3405d74117a50cd9ea313c179b33 | refs/heads/master | 2020-04-19T15:17:47.154624 | 2010-06-10T17:39:35 | 2010-06-10T17:39:35 | 168,269,500 | 1 | 0 | null | 2019-01-30T03:00:41 | 2019-01-30T03:00:41 | null | UTF-8 | Scheme | false | false | 37,879 | sls | keysym.sls |
(library (psilab xlib keysym)
(export XK_VoidSymbol
XK_BackSpace
XK_Tab
XK_Linefeed
XK_Clear
XK_Return
XK_Pause
XK_Scroll_Lock
XK_Sys_Req
XK_Escape
XK_Delete
XK_Multi_key
XK_Codeinput
XK_SingleCandidate
XK_MultipleCandidate
XK_PreviousCandidate
XK_Kanji
XK_Muhenkan
XK_Henkan_Mode
XK_Henkan
XK_Romaji
XK_Hiragana
XK_Katakana
XK_Hiragana_Katakana
XK_Zenkaku
XK_Hankaku
XK_Zenkaku_Hankaku
XK_Touroku
XK_Massyo
XK_Kana_Lock
XK_Kana_Shift
XK_Eisu_Shift
XK_Eisu_toggle
XK_Kanji_Bangou
XK_Zen_Koho
XK_Mae_Koho
XK_Home
XK_Left
XK_Up
XK_Right
XK_Down
XK_Prior
XK_Page_Up
XK_Next
XK_Page_Down
XK_End
XK_Begin
XK_Select
XK_Print
XK_Execute
XK_Insert
XK_Undo
XK_Redo
XK_Menu
XK_Find
XK_Cancel
XK_Help
XK_Break
XK_Mode_switch
XK_script_switch
XK_Num_Lock
XK_KP_Space
XK_KP_Tab
XK_KP_Enter
XK_KP_F1
XK_KP_F2
XK_KP_F3
XK_KP_F4
XK_KP_Home
XK_KP_Left
XK_KP_Up
XK_KP_Right
XK_KP_Down
XK_KP_Prior
XK_KP_Page_Up
XK_KP_Next
XK_KP_Page_Down
XK_KP_End
XK_KP_Begin
XK_KP_Insert
XK_KP_Delete
XK_KP_Equal
XK_KP_Multiply
XK_KP_Add
XK_KP_Separator
XK_KP_Subtract
XK_KP_Decimal
XK_KP_Divide
XK_KP_0
XK_KP_1
XK_KP_2
XK_KP_3
XK_KP_4
XK_KP_5
XK_KP_6
XK_KP_7
XK_KP_8
XK_KP_9
XK_F1
XK_F2
XK_F3
XK_F4
XK_F5
XK_F6
XK_F7
XK_F8
XK_F9
XK_F10
XK_F11
XK_L1
XK_F12
XK_L2
XK_F13
XK_L3
XK_F14
XK_L4
XK_F15
XK_L5
XK_F16
XK_L6
XK_F17
XK_L7
XK_F18
XK_L8
XK_F19
XK_L9
XK_F20
XK_L10
XK_F21
XK_R1
XK_F22
XK_R2
XK_F23
XK_R3
XK_F24
XK_R4
XK_F25
XK_R5
XK_F26
XK_R6
XK_F27
XK_R7
XK_F28
XK_R8
XK_F29
XK_R9
XK_F30
XK_R10
XK_F31
XK_R11
XK_F32
XK_R12
XK_F33
XK_R13
XK_F34
XK_R14
XK_F35
XK_R15
XK_Shift_L
XK_Shift_R
XK_Control_L
XK_Control_R
XK_Caps_Lock
XK_Shift_Lock
XK_Meta_L
XK_Meta_R
XK_Alt_L
XK_Alt_R
XK_Super_L
XK_Super_R
XK_Hyper_L
XK_Hyper_R
XK_ISO_Lock
XK_ISO_Level2_Latch
XK_ISO_Level3_Shift
XK_ISO_Level3_Latch
XK_ISO_Level3_Lock
XK_ISO_Level5_Shift
XK_ISO_Level5_Latch
XK_ISO_Level5_Lock
XK_ISO_Group_Shift
XK_ISO_Group_Latch
XK_ISO_Group_Lock
XK_ISO_Next_Group
XK_ISO_Next_Group_Lock
XK_ISO_Prev_Group
XK_ISO_Prev_Group_Lock
XK_ISO_First_Group
XK_ISO_First_Group_Lock
XK_ISO_Last_Group
XK_ISO_Last_Group_Lock
XK_ISO_Left_Tab
XK_ISO_Move_Line_Up
XK_ISO_Move_Line_Down
XK_ISO_Partial_Line_Up
XK_ISO_Partial_Line_Down
XK_ISO_Partial_Space_Left
XK_ISO_Partial_Space_Right
XK_ISO_Set_Margin_Left
XK_ISO_Set_Margin_Right
XK_ISO_Release_Margin_Left
XK_ISO_Release_Margin_Right
XK_ISO_Release_Both_Margins
XK_ISO_Fast_Cursor_Left
XK_ISO_Fast_Cursor_Right
XK_ISO_Fast_Cursor_Up
XK_ISO_Fast_Cursor_Down
XK_ISO_Continuous_Underline
XK_ISO_Discontinuous_Underline
XK_ISO_Emphasize
XK_ISO_Center_Object
XK_ISO_Enter
XK_dead_grave
XK_dead_acute
XK_dead_circumflex
XK_dead_tilde
XK_dead_macron
XK_dead_breve
XK_dead_abovedot
XK_dead_diaeresis
XK_dead_abovering
XK_dead_doubleacute
XK_dead_caron
XK_dead_cedilla
XK_dead_ogonek
XK_dead_iota
XK_dead_voiced_sound
XK_dead_semivoiced_sound
XK_dead_belowdot
XK_dead_hook
XK_dead_horn
XK_dead_stroke
XK_dead_abovecomma
XK_dead_psili
XK_dead_abovereversedcomma
XK_dead_dasia
XK_First_Virtual_Screen
XK_Prev_Virtual_Screen
XK_Next_Virtual_Screen
XK_Last_Virtual_Screen
XK_Terminate_Server
XK_AccessX_Enable
XK_AccessX_Feedback_Enable
XK_RepeatKeys_Enable
XK_SlowKeys_Enable
XK_BounceKeys_Enable
XK_StickyKeys_Enable
XK_MouseKeys_Enable
XK_MouseKeys_Accel_Enable
XK_Overlay1_Enable
XK_Overlay2_Enable
XK_AudibleBell_Enable
XK_Pointer_Left
XK_Pointer_Right
XK_Pointer_Up
XK_Pointer_Down
XK_Pointer_UpLeft
XK_Pointer_UpRight
XK_Pointer_DownLeft
XK_Pointer_DownRight
XK_Pointer_Button_Dflt
XK_Pointer_Button1
XK_Pointer_Button2
XK_Pointer_Button3
XK_Pointer_Button4
XK_Pointer_Button5
XK_Pointer_DblClick_Dflt
XK_Pointer_DblClick1
XK_Pointer_DblClick2
XK_Pointer_DblClick3
XK_Pointer_DblClick4
XK_Pointer_DblClick5
XK_Pointer_Drag_Dflt
XK_Pointer_Drag1
XK_Pointer_Drag2
XK_Pointer_Drag3
XK_Pointer_Drag4
XK_Pointer_Drag5
XK_Pointer_EnableKeys
XK_Pointer_Accelerate
XK_Pointer_DfltBtnNext
XK_Pointer_DfltBtnPrev
XK_3270_Duplicate
XK_3270_FieldMark
XK_3270_Right2
XK_3270_Left2
XK_3270_BackTab
XK_3270_EraseEOF
XK_3270_EraseInput
XK_3270_Reset
XK_3270_Quit
XK_3270_PA1
XK_3270_PA2
XK_3270_PA3
XK_3270_Test
XK_3270_Attn
XK_3270_CursorBlink
XK_3270_AltCursor
XK_3270_KeyClick
XK_3270_Jump
XK_3270_Ident
XK_3270_Rule
XK_3270_Copy
XK_3270_Play
XK_3270_Setup
XK_3270_Record
XK_3270_ChangeScreen
XK_3270_DeleteWord
XK_3270_ExSelect
XK_3270_CursorSelect
XK_3270_PrintScreen
XK_3270_Enter
XK_space
XK_exclam
XK_quotedbl
XK_numbersign
XK_dollar
XK_percent
XK_ampersand
XK_apostrophe
XK_quoteright
XK_parenleft
XK_parenright
XK_asterisk
XK_plus
XK_comma
XK_minus
XK_period
XK_slash
XK_0
XK_1
XK_2
XK_3
XK_4
XK_5
XK_6
XK_7
XK_8
XK_9
XK_colon
XK_semicolon
XK_less
XK_equal
XK_greater
XK_question
XK_at
XK_A
XK_B
XK_C
XK_D
XK_E
XK_F
XK_G
XK_H
XK_I
XK_J
XK_K
XK_L
XK_M
XK_N
XK_O
XK_P
XK_Q
XK_R
XK_S
XK_T
XK_U
XK_V
XK_W
XK_X
XK_Y
XK_Z
XK_bracketleft
XK_backslash
XK_bracketright
XK_asciicircum
XK_underscore
XK_grave
XK_quoteleft
XK_a
XK_b
XK_c
XK_d
XK_e
XK_f
XK_g
XK_h
XK_i
XK_j
XK_k
XK_l
XK_m
XK_n
XK_o
XK_p
XK_q
XK_r
XK_s
XK_t
XK_u
XK_v
XK_w
XK_x
XK_y
XK_z
XK_braceleft
XK_bar
XK_braceright
XK_asciitilde
XK_nobreakspace
XK_exclamdown
XK_cent
XK_sterling
XK_currency
XK_yen
XK_brokenbar
XK_section
XK_diaeresis
XK_copyright
XK_ordfeminine
XK_guillemotleft
XK_notsign
XK_hyphen
XK_registered
XK_macron
XK_degree
XK_plusminus
XK_twosuperior
XK_threesuperior
XK_acute
XK_mu
XK_paragraph
XK_periodcentered
XK_cedilla
XK_onesuperior
XK_masculine
XK_guillemotright
XK_onequarter
XK_onehalf
XK_threequarters
XK_questiondown
XK_Agrave
XK_Aacute
XK_Acircumflex
XK_Atilde
XK_Adiaeresis
XK_Aring
XK_AE
XK_Ccedilla
XK_Egrave
XK_Eacute
XK_Ecircumflex
XK_Ediaeresis
XK_Igrave
XK_Iacute
XK_Icircumflex
XK_Idiaeresis
XK_ETH
XK_Eth
XK_Ntilde
XK_Ograve
XK_Oacute
XK_Ocircumflex
XK_Otilde
XK_Odiaeresis
XK_multiply
XK_Oslash
XK_Ooblique
XK_Ugrave
XK_Uacute
XK_Ucircumflex
XK_Udiaeresis
XK_Yacute
XK_THORN
XK_Thorn
XK_ssharp
XK_agrave
XK_aacute
XK_acircumflex
XK_atilde
XK_adiaeresis
XK_aring
XK_ae
XK_ccedilla
XK_egrave
XK_eacute
XK_ecircumflex
XK_ediaeresis
XK_igrave
XK_iacute
XK_icircumflex
XK_idiaeresis
XK_eth
XK_ntilde
XK_ograve
XK_oacute
XK_ocircumflex
XK_otilde
XK_odiaeresis
XK_division
XK_oslash
XK_ooblique
XK_ugrave
XK_uacute
XK_ucircumflex
XK_udiaeresis
XK_yacute
XK_thorn
XK_ydiaeresis)
(import (rnrs))
(define XK_VoidSymbol #xffffff)
(define XK_BackSpace #xff08)
(define XK_Tab #xff09)
(define XK_Linefeed #xff0a)
(define XK_Clear #xff0b)
(define XK_Return #xff0d)
(define XK_Pause #xff13)
(define XK_Scroll_Lock #xff14)
(define XK_Sys_Req #xff15)
(define XK_Escape #xff1b)
(define XK_Delete #xffff)
(define XK_Multi_key #xff20)
(define XK_Codeinput #xff37)
(define XK_SingleCandidate #xff3c)
(define XK_MultipleCandidate #xff3d)
(define XK_PreviousCandidate #xff3e)
(define XK_Kanji #xff21)
(define XK_Muhenkan #xff22)
(define XK_Henkan_Mode #xff23)
(define XK_Henkan #xff23)
(define XK_Romaji #xff24)
(define XK_Hiragana #xff25)
(define XK_Katakana #xff26)
(define XK_Hiragana_Katakana #xff27)
(define XK_Zenkaku #xff28)
(define XK_Hankaku #xff29)
(define XK_Zenkaku_Hankaku #xff2a)
(define XK_Touroku #xff2b)
(define XK_Massyo #xff2c)
(define XK_Kana_Lock #xff2d)
(define XK_Kana_Shift #xff2e)
(define XK_Eisu_Shift #xff2f)
(define XK_Eisu_toggle #xff30)
(define XK_Kanji_Bangou #xff37)
(define XK_Zen_Koho #xff3d)
(define XK_Mae_Koho #xff3e)
(define XK_Home #xff50)
(define XK_Left #xff51)
(define XK_Up #xff52)
(define XK_Right #xff53)
(define XK_Down #xff54)
(define XK_Prior #xff55)
(define XK_Page_Up #xff55)
(define XK_Next #xff56)
(define XK_Page_Down #xff56)
(define XK_End #xff57)
(define XK_Begin #xff58)
(define XK_Select #xff60)
(define XK_Print #xff61)
(define XK_Execute #xff62)
(define XK_Insert #xff63)
(define XK_Undo #xff65)
(define XK_Redo #xff66)
(define XK_Menu #xff67)
(define XK_Find #xff68)
(define XK_Cancel #xff69)
(define XK_Help #xff6a)
(define XK_Break #xff6b)
(define XK_Mode_switch #xff7e)
(define XK_script_switch #xff7e)
(define XK_Num_Lock #xff7f)
(define XK_KP_Space #xff80)
(define XK_KP_Tab #xff89)
(define XK_KP_Enter #xff8d)
(define XK_KP_F1 #xff91)
(define XK_KP_F2 #xff92)
(define XK_KP_F3 #xff93)
(define XK_KP_F4 #xff94)
(define XK_KP_Home #xff95)
(define XK_KP_Left #xff96)
(define XK_KP_Up #xff97)
(define XK_KP_Right #xff98)
(define XK_KP_Down #xff99)
(define XK_KP_Prior #xff9a)
(define XK_KP_Page_Up #xff9a)
(define XK_KP_Next #xff9b)
(define XK_KP_Page_Down #xff9b)
(define XK_KP_End #xff9c)
(define XK_KP_Begin #xff9d)
(define XK_KP_Insert #xff9e)
(define XK_KP_Delete #xff9f)
(define XK_KP_Equal #xffbd)
(define XK_KP_Multiply #xffaa)
(define XK_KP_Add #xffab)
(define XK_KP_Separator #xffac)
(define XK_KP_Subtract #xffad)
(define XK_KP_Decimal #xffae)
(define XK_KP_Divide #xffaf)
(define XK_KP_0 #xffb0)
(define XK_KP_1 #xffb1)
(define XK_KP_2 #xffb2)
(define XK_KP_3 #xffb3)
(define XK_KP_4 #xffb4)
(define XK_KP_5 #xffb5)
(define XK_KP_6 #xffb6)
(define XK_KP_7 #xffb7)
(define XK_KP_8 #xffb8)
(define XK_KP_9 #xffb9)
(define XK_F1 #xffbe)
(define XK_F2 #xffbf)
(define XK_F3 #xffc0)
(define XK_F4 #xffc1)
(define XK_F5 #xffc2)
(define XK_F6 #xffc3)
(define XK_F7 #xffc4)
(define XK_F8 #xffc5)
(define XK_F9 #xffc6)
(define XK_F10 #xffc7)
(define XK_F11 #xffc8)
(define XK_L1 #xffc8)
(define XK_F12 #xffc9)
(define XK_L2 #xffc9)
(define XK_F13 #xffca)
(define XK_L3 #xffca)
(define XK_F14 #xffcb)
(define XK_L4 #xffcb)
(define XK_F15 #xffcc)
(define XK_L5 #xffcc)
(define XK_F16 #xffcd)
(define XK_L6 #xffcd)
(define XK_F17 #xffce)
(define XK_L7 #xffce)
(define XK_F18 #xffcf)
(define XK_L8 #xffcf)
(define XK_F19 #xffd0)
(define XK_L9 #xffd0)
(define XK_F20 #xffd1)
(define XK_L10 #xffd1)
(define XK_F21 #xffd2)
(define XK_R1 #xffd2)
(define XK_F22 #xffd3)
(define XK_R2 #xffd3)
(define XK_F23 #xffd4)
(define XK_R3 #xffd4)
(define XK_F24 #xffd5)
(define XK_R4 #xffd5)
(define XK_F25 #xffd6)
(define XK_R5 #xffd6)
(define XK_F26 #xffd7)
(define XK_R6 #xffd7)
(define XK_F27 #xffd8)
(define XK_R7 #xffd8)
(define XK_F28 #xffd9)
(define XK_R8 #xffd9)
(define XK_F29 #xffda)
(define XK_R9 #xffda)
(define XK_F30 #xffdb)
(define XK_R10 #xffdb)
(define XK_F31 #xffdc)
(define XK_R11 #xffdc)
(define XK_F32 #xffdd)
(define XK_R12 #xffdd)
(define XK_F33 #xffde)
(define XK_R13 #xffde)
(define XK_F34 #xffdf)
(define XK_R14 #xffdf)
(define XK_F35 #xffe0)
(define XK_R15 #xffe0)
(define XK_Shift_L #xffe1)
(define XK_Shift_R #xffe2)
(define XK_Control_L #xffe3)
(define XK_Control_R #xffe4)
(define XK_Caps_Lock #xffe5)
(define XK_Shift_Lock #xffe6)
(define XK_Meta_L #xffe7)
(define XK_Meta_R #xffe8)
(define XK_Alt_L #xffe9)
(define XK_Alt_R #xffea)
(define XK_Super_L #xffeb)
(define XK_Super_R #xffec)
(define XK_Hyper_L #xffed)
(define XK_Hyper_R #xffee)
(define XK_ISO_Lock #xfe01)
(define XK_ISO_Level2_Latch #xfe02)
(define XK_ISO_Level3_Shift #xfe03)
(define XK_ISO_Level3_Latch #xfe04)
(define XK_ISO_Level3_Lock #xfe05)
(define XK_ISO_Level5_Shift #xfe11)
(define XK_ISO_Level5_Latch #xfe12)
(define XK_ISO_Level5_Lock #xfe13)
(define XK_ISO_Group_Shift #xff7e)
(define XK_ISO_Group_Latch #xfe06)
(define XK_ISO_Group_Lock #xfe07)
(define XK_ISO_Next_Group #xfe08)
(define XK_ISO_Next_Group_Lock #xfe09)
(define XK_ISO_Prev_Group #xfe0a)
(define XK_ISO_Prev_Group_Lock #xfe0b)
(define XK_ISO_First_Group #xfe0c)
(define XK_ISO_First_Group_Lock #xfe0d)
(define XK_ISO_Last_Group #xfe0e)
(define XK_ISO_Last_Group_Lock #xfe0f)
(define XK_ISO_Left_Tab #xfe20)
(define XK_ISO_Move_Line_Up #xfe21)
(define XK_ISO_Move_Line_Down #xfe22)
(define XK_ISO_Partial_Line_Up #xfe23)
(define XK_ISO_Partial_Line_Down #xfe24)
(define XK_ISO_Partial_Space_Left #xfe25)
(define XK_ISO_Partial_Space_Right #xfe26)
(define XK_ISO_Set_Margin_Left #xfe27)
(define XK_ISO_Set_Margin_Right #xfe28)
(define XK_ISO_Release_Margin_Left #xfe29)
(define XK_ISO_Release_Margin_Right #xfe2a)
(define XK_ISO_Release_Both_Margins #xfe2b)
(define XK_ISO_Fast_Cursor_Left #xfe2c)
(define XK_ISO_Fast_Cursor_Right #xfe2d)
(define XK_ISO_Fast_Cursor_Up #xfe2e)
(define XK_ISO_Fast_Cursor_Down #xfe2f)
(define XK_ISO_Continuous_Underline #xfe30)
(define XK_ISO_Discontinuous_Underline #xfe31)
(define XK_ISO_Emphasize #xfe32)
(define XK_ISO_Center_Object #xfe33)
(define XK_ISO_Enter #xfe34)
(define XK_dead_grave #xfe50)
(define XK_dead_acute #xfe51)
(define XK_dead_circumflex #xfe52)
(define XK_dead_tilde #xfe53)
(define XK_dead_macron #xfe54)
(define XK_dead_breve #xfe55)
(define XK_dead_abovedot #xfe56)
(define XK_dead_diaeresis #xfe57)
(define XK_dead_abovering #xfe58)
(define XK_dead_doubleacute #xfe59)
(define XK_dead_caron #xfe5a)
(define XK_dead_cedilla #xfe5b)
(define XK_dead_ogonek #xfe5c)
(define XK_dead_iota #xfe5d)
(define XK_dead_voiced_sound #xfe5e)
(define XK_dead_semivoiced_sound #xfe5f)
(define XK_dead_belowdot #xfe60)
(define XK_dead_hook #xfe61)
(define XK_dead_horn #xfe62)
(define XK_dead_stroke #xfe63)
(define XK_dead_abovecomma #xfe64)
(define XK_dead_psili #xfe64)
(define XK_dead_abovereversedcomma #xfe65)
(define XK_dead_dasia #xfe66)
(define XK_First_Virtual_Screen #xfed0)
(define XK_Prev_Virtual_Screen #xfed1)
(define XK_Next_Virtual_Screen #xfed2)
(define XK_Last_Virtual_Screen #xfed4)
(define XK_Terminate_Server #xfed5)
(define XK_AccessX_Enable #xfe70)
(define XK_AccessX_Feedback_Enable #xfe71)
(define XK_RepeatKeys_Enable #xfe72)
(define XK_SlowKeys_Enable #xfe73)
(define XK_BounceKeys_Enable #xfe74)
(define XK_StickyKeys_Enable #xfe75)
(define XK_MouseKeys_Enable #xfe76)
(define XK_MouseKeys_Accel_Enable #xfe77)
(define XK_Overlay1_Enable #xfe78)
(define XK_Overlay2_Enable #xfe79)
(define XK_AudibleBell_Enable #xfe7a)
(define XK_Pointer_Left #xfee0)
(define XK_Pointer_Right #xfee1)
(define XK_Pointer_Up #xfee2)
(define XK_Pointer_Down #xfee3)
(define XK_Pointer_UpLeft #xfee4)
(define XK_Pointer_UpRight #xfee5)
(define XK_Pointer_DownLeft #xfee6)
(define XK_Pointer_DownRight #xfee7)
(define XK_Pointer_Button_Dflt #xfee8)
(define XK_Pointer_Button1 #xfee9)
(define XK_Pointer_Button2 #xfeea)
(define XK_Pointer_Button3 #xfeeb)
(define XK_Pointer_Button4 #xfeec)
(define XK_Pointer_Button5 #xfeed)
(define XK_Pointer_DblClick_Dflt #xfeee)
(define XK_Pointer_DblClick1 #xfeef)
(define XK_Pointer_DblClick2 #xfef0)
(define XK_Pointer_DblClick3 #xfef1)
(define XK_Pointer_DblClick4 #xfef2)
(define XK_Pointer_DblClick5 #xfef3)
(define XK_Pointer_Drag_Dflt #xfef4)
(define XK_Pointer_Drag1 #xfef5)
(define XK_Pointer_Drag2 #xfef6)
(define XK_Pointer_Drag3 #xfef7)
(define XK_Pointer_Drag4 #xfef8)
(define XK_Pointer_Drag5 #xfefd)
(define XK_Pointer_EnableKeys #xfef9)
(define XK_Pointer_Accelerate #xfefa)
(define XK_Pointer_DfltBtnNext #xfefb)
(define XK_Pointer_DfltBtnPrev #xfefc)
(define XK_3270_Duplicate #xfd01)
(define XK_3270_FieldMark #xfd02)
(define XK_3270_Right2 #xfd03)
(define XK_3270_Left2 #xfd04)
(define XK_3270_BackTab #xfd05)
(define XK_3270_EraseEOF #xfd06)
(define XK_3270_EraseInput #xfd07)
(define XK_3270_Reset #xfd08)
(define XK_3270_Quit #xfd09)
(define XK_3270_PA1 #xfd0a)
(define XK_3270_PA2 #xfd0b)
(define XK_3270_PA3 #xfd0c)
(define XK_3270_Test #xfd0d)
(define XK_3270_Attn #xfd0e)
(define XK_3270_CursorBlink #xfd0f)
(define XK_3270_AltCursor #xfd10)
(define XK_3270_KeyClick #xfd11)
(define XK_3270_Jump #xfd12)
(define XK_3270_Ident #xfd13)
(define XK_3270_Rule #xfd14)
(define XK_3270_Copy #xfd15)
(define XK_3270_Play #xfd16)
(define XK_3270_Setup #xfd17)
(define XK_3270_Record #xfd18)
(define XK_3270_ChangeScreen #xfd19)
(define XK_3270_DeleteWord #xfd1a)
(define XK_3270_ExSelect #xfd1b)
(define XK_3270_CursorSelect #xfd1c)
(define XK_3270_PrintScreen #xfd1d)
(define XK_3270_Enter #xfd1e)
(define XK_space #x0020)
(define XK_exclam #x0021)
(define XK_quotedbl #x0022)
(define XK_numbersign #x0023)
(define XK_dollar #x0024)
(define XK_percent #x0025)
(define XK_ampersand #x0026)
(define XK_apostrophe #x0027)
(define XK_quoteright #x0027)
(define XK_parenleft #x0028)
(define XK_parenright #x0029)
(define XK_asterisk #x002a)
(define XK_plus #x002b)
(define XK_comma #x002c)
(define XK_minus #x002d)
(define XK_period #x002e)
(define XK_slash #x002f)
(define XK_0 #x0030)
(define XK_1 #x0031)
(define XK_2 #x0032)
(define XK_3 #x0033)
(define XK_4 #x0034)
(define XK_5 #x0035)
(define XK_6 #x0036)
(define XK_7 #x0037)
(define XK_8 #x0038)
(define XK_9 #x0039)
(define XK_colon #x003a)
(define XK_semicolon #x003b)
(define XK_less #x003c)
(define XK_equal #x003d)
(define XK_greater #x003e)
(define XK_question #x003f)
(define XK_at #x0040)
(define XK_A #x0041)
(define XK_B #x0042)
(define XK_C #x0043)
(define XK_D #x0044)
(define XK_E #x0045)
(define XK_F #x0046)
(define XK_G #x0047)
(define XK_H #x0048)
(define XK_I #x0049)
(define XK_J #x004a)
(define XK_K #x004b)
(define XK_L #x004c)
(define XK_M #x004d)
(define XK_N #x004e)
(define XK_O #x004f)
(define XK_P #x0050)
(define XK_Q #x0051)
(define XK_R #x0052)
(define XK_S #x0053)
(define XK_T #x0054)
(define XK_U #x0055)
(define XK_V #x0056)
(define XK_W #x0057)
(define XK_X #x0058)
(define XK_Y #x0059)
(define XK_Z #x005a)
(define XK_bracketleft #x005b)
(define XK_backslash #x005c)
(define XK_bracketright #x005d)
(define XK_asciicircum #x005e)
(define XK_underscore #x005f)
(define XK_grave #x0060)
(define XK_quoteleft #x0060)
(define XK_a #x0061)
(define XK_b #x0062)
(define XK_c #x0063)
(define XK_d #x0064)
(define XK_e #x0065)
(define XK_f #x0066)
(define XK_g #x0067)
(define XK_h #x0068)
(define XK_i #x0069)
(define XK_j #x006a)
(define XK_k #x006b)
(define XK_l #x006c)
(define XK_m #x006d)
(define XK_n #x006e)
(define XK_o #x006f)
(define XK_p #x0070)
(define XK_q #x0071)
(define XK_r #x0072)
(define XK_s #x0073)
(define XK_t #x0074)
(define XK_u #x0075)
(define XK_v #x0076)
(define XK_w #x0077)
(define XK_x #x0078)
(define XK_y #x0079)
(define XK_z #x007a)
(define XK_braceleft #x007b)
(define XK_bar #x007c)
(define XK_braceright #x007d)
(define XK_asciitilde #x007e)
(define XK_nobreakspace #x00a0)
(define XK_exclamdown #x00a1)
(define XK_cent #x00a2)
(define XK_sterling #x00a3)
(define XK_currency #x00a4)
(define XK_yen #x00a5)
(define XK_brokenbar #x00a6)
(define XK_section #x00a7)
(define XK_diaeresis #x00a8)
(define XK_copyright #x00a9)
(define XK_ordfeminine #x00aa)
(define XK_guillemotleft #x00ab)
(define XK_notsign #x00ac)
(define XK_hyphen #x00ad)
(define XK_registered #x00ae)
(define XK_macron #x00af)
(define XK_degree #x00b0)
(define XK_plusminus #x00b1)
(define XK_twosuperior #x00b2)
(define XK_threesuperior #x00b3)
(define XK_acute #x00b4)
(define XK_mu #x00b5)
(define XK_paragraph #x00b6)
(define XK_periodcentered #x00b7)
(define XK_cedilla #x00b8)
(define XK_onesuperior #x00b9)
(define XK_masculine #x00ba)
(define XK_guillemotright #x00bb)
(define XK_onequarter #x00bc)
(define XK_onehalf #x00bd)
(define XK_threequarters #x00be)
(define XK_questiondown #x00bf)
(define XK_Agrave #x00c0)
(define XK_Aacute #x00c1)
(define XK_Acircumflex #x00c2)
(define XK_Atilde #x00c3)
(define XK_Adiaeresis #x00c4)
(define XK_Aring #x00c5)
(define XK_AE #x00c6)
(define XK_Ccedilla #x00c7)
(define XK_Egrave #x00c8)
(define XK_Eacute #x00c9)
(define XK_Ecircumflex #x00ca)
(define XK_Ediaeresis #x00cb)
(define XK_Igrave #x00cc)
(define XK_Iacute #x00cd)
(define XK_Icircumflex #x00ce)
(define XK_Idiaeresis #x00cf)
(define XK_ETH #x00d0)
(define XK_Eth #x00d0)
(define XK_Ntilde #x00d1)
(define XK_Ograve #x00d2)
(define XK_Oacute #x00d3)
(define XK_Ocircumflex #x00d4)
(define XK_Otilde #x00d5)
(define XK_Odiaeresis #x00d6)
(define XK_multiply #x00d7)
(define XK_Oslash #x00d8)
(define XK_Ooblique #x00d8)
(define XK_Ugrave #x00d9)
(define XK_Uacute #x00da)
(define XK_Ucircumflex #x00db)
(define XK_Udiaeresis #x00dc)
(define XK_Yacute #x00dd)
(define XK_THORN #x00de)
(define XK_Thorn #x00de)
(define XK_ssharp #x00df)
(define XK_agrave #x00e0)
(define XK_aacute #x00e1)
(define XK_acircumflex #x00e2)
(define XK_atilde #x00e3)
(define XK_adiaeresis #x00e4)
(define XK_aring #x00e5)
(define XK_ae #x00e6)
(define XK_ccedilla #x00e7)
(define XK_egrave #x00e8)
(define XK_eacute #x00e9)
(define XK_ecircumflex #x00ea)
(define XK_ediaeresis #x00eb)
(define XK_igrave #x00ec)
(define XK_iacute #x00ed)
(define XK_icircumflex #x00ee)
(define XK_idiaeresis #x00ef)
(define XK_eth #x00f0)
(define XK_ntilde #x00f1)
(define XK_ograve #x00f2)
(define XK_oacute #x00f3)
(define XK_ocircumflex #x00f4)
(define XK_otilde #x00f5)
(define XK_odiaeresis #x00f6)
(define XK_division #x00f7)
(define XK_oslash #x00f8)
(define XK_ooblique #x00f8)
(define XK_ugrave #x00f9)
(define XK_uacute #x00fa)
(define XK_ucircumflex #x00fb)
(define XK_udiaeresis #x00fc)
(define XK_yacute #x00fd)
(define XK_thorn #x00fe)
(define XK_ydiaeresis #x00ff)
) | false |
f477b8b634b7d722b975f4c953e8f6f793530de3 | d696b5c5cc0ee7032ab13b6ed486d6158646f828 | /sicp.scm | 33637042562fe513cf8e2fafbeed622ab44f8efa | []
| 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 | 34,155 | scm | sicp.scm | Exercise 1.2:
(/ (+ 5 4 (- 2 (- 3 (+ 6 (/ 4 5))))) (* 3 (- 6 2) (- 2 7)))
Exercise 1.3:
(define (f x y z)
(cond ((and (< x y) (< x z)) (sum-of-squares y z))
((and (< y x) (< y z)) (sum-of-squares x z))
((and (< z x) (< z y)) (sum-of-squares x y))
(else (sum-of-squares x y))
)
)
(define (sum-of-squares x y)
(+ (square x) (square y))
)
(define (square x) (* x x))
(define (max x y)
(if (> x y)
x
y)
)
Exercise 1.9
first: recuisive
second: iterative
Exercise 1.10
(A 1 10) => 1024
(A 2 4) => 65536
Exercise 1.11
recursive:
(define (f n)
(if (< n 3)
n
(+ (f (- n 1)) (* 2 (f (- n 2))) (* 3 (f (- n 3)) ))
)
)
iterative:
(define (f n)
(f-iter 0 1 2 n)
)
(define (f-iter a b c count)
(if (< count 3)
c
(f-iter b c (+ (* 3 a) (* 2 b) c) (- count 1))
)
)
Exercise 1.12
(define (f a b)
(cond ((or (= a b) (= b 1)) 1)
(else
(+ (f (- a 1) (- b 1)) (f (- a 1) b))
)
)
)
Exercise 1.15
a: 2^5 + 1 = 33
Exercise 1.16
(define (fast-expt b n) (fast-expt-iter b 1 n)
)
(define (fast-expt-iter b a n)
(cond ((or (= n 0) (= n 1)) a)
((iseven n) (fast-expt-iter b (* a (square b)) (/ n 2)))
(else (fast-expt-iter b (* a b) (- n 1)))
)
)
(define (square x)
(* x x)
)
(define (iseven n)
(= (remainder n 2) 0))
Exercise 1.17
(define (iseven n)
(= (remainder n 2) 0))
(define (double x) (+ x x))
(define (halve x) (/ x 2))
(define (* a b)
(cond ((or (= b 0) (= a 0)) 0)
((= b 1) a)
((iseven b) (* (double a) (halve b) ))
(else (+ a (* (double a) (halve (- b 1)))))
)
)
Exercise 1.29
(define (integral f a b n)
(define h (/ (- b a) n))
(define (addx x)
(+ x h h)
)
(* (sum f a addx b)
(/ h 3)
)
)
(define (sum term a next b)
(if (> a b)
0
(+ (term a) (* 4 (term (/ (+ (next a) a) 2))) (term (next a))
(sum term (next a) next b)
)
)
)
(define (cube x) (* x x x))
(integral cube 0 1 100)
Exercise 1.30
(define (sum term a next b)
(define (iter a result)
(if (> a b)
result
(iter (next a) (+ result (term a))
)
)
(iter a 0)
)
Exercise 1.31
iterative:
(define (product term a next b)
(define (iter a result)
(if (> a b)
result
(iter (next a) (* result (term a)))
)
)
(iter a 1)
)
recursive:
(define (product term a next b)
(if (> a b)
1
(* (term a)
(product term (next a) next b)
)
)
)
factorial:
(define (fac n)
(product f 1 inc n)
)
(define (f x) x)
(define (inc x) (+ x 1))
computing π:
(define (f n)
(/ (* 4 n (+ n 1))
(square (+ 1 (* n 2)))
)
)
(define (square x) (* x x))
(define (inc x) (+ x 1))
(define (pi n)
(exact->inexact(* 4 (product f 1 inc n)))
)
Exercise 1.32
iterative accumulate:
(define (accumulate combiner null-value term a next b)
(
(define (iter a result)
(if (> a b)
result
(iter (next a) (combiner ( result (term a))))
)
)
(iter a null-value)
)
)
// define product procedure
(define (product term a next b)
(accumulate * 1 term a next b)
)
recuisive accumulate:
(define (accumulate combiner null-value term a next b)
(if (> a b)
null-value
(combiner (term a) (accumulate combiner null-value term (next a) next b ))
)
)
Exercise 1.33
recuisive filtered accumulate:
(define (filtered-accumulate combiner null-value term a next b filter)
(if (> a b)
null-value
(combiner
(filter (term a))
(filter (accumulate combiner null-value term (next a) next b filter))
)
)
)
iterative filtered accumulate:
(define (filtered-accumulate combiner null-value term a next b filter)
(
(define (iter a result)
(if (> a b)
result
(iter
(next a)
(combiner
(filter (result))
(filter (term a))
)
)
)
)
(iter a null-value)
)
)
Exercise 1.35
(define tolerance 0.000000000001)
(define (fixed-point f first-guess)
(define (close-enough? v1 v2)
(< (abs (- v1 v2)) tolerance)
)
(define (try guess)
(let ((next (f guess)))
(if (close-enough? guess next)
next
(try next)
)
)
)
(try first-guess)
)
(define (goldratio)
(exact->inexact(fixed-point (lambda (x) (+ 1 (/ 1 x))) 1))
)
Exercise 1.36
(define tolerance 0.00001)
(define (fixed-point f first-guess)
(define (close-enough? v1 v2)
(< (abs (- v1 v2)) tolerance)
)
(define (try guess)
(let ((next (f guess)))
(cond ((close-enough? guess next)
next)
(else
(newline)
(display next)
(try next)
)
)
)
)
(try first-guess)
)
(define (nthroot)
(exact->inexact(fixed-point (lambda (x) (/ (log 1000) (log x))) 2))
)
Exercise 1.37
// get the continued fraction value of k by iterative.
// (cont-frac (lambda (i) 1.0) (lambda (i) 1.0) k)
(define (cont-frac N D k)
(define (iter result i)
(if (= i 0)
result
(iter (/ (N i) (+ (D i) result)) (- i 1))
)
)
(iter (/ (N k) (D k) ) (- k 1) )
)
recursive:
(define (cont-frac N D k)
(define (cf i)
(if (= i k)
(/ (N i) (D i))
(/ (N i) (+ (D i) (cf (+ i 1))) )
)
)
(cf 1)
)
(define (iter result i)
(if (= i 0)
result
(iter (/ (N i) (+ (D i) result)) (- i 1))
)
)
(iter (/ (N k) (D k) ) (- k 1) )
)
// the continued fraction is decrement, guess the k from 1.
(define (getappk)
(define (close-enough? v1 v2)
(< (abs (- v1 v2)) tolerance)
)
(define (try guess)
(let ((next (f guess)))
(cond ((close-enough? (/ 1 (phi)) next)
next)
(else
(newline)
(display next)
(try (+ 1 guss))
)
)
)
)
(try 1)
)
// below functioins get the golden ratio with tolerance 0.00001
(define (phi) (/ (+ 1 (sqrt 5) 2)))
(define (sqrt x)
(fixed-point (lambda (y) (average y (/ x y)))
1))
(define (average x y)
(/ (+ x y) 2)
)
Exercise 1.38:
(define (D i)
(if (= (remainder (- i 2) 3) 0)
(+ 2.0 (* 2 (/ (- i 2) 3)))
1.0
)
)
(define (cont-frac N D k)
(define (iter result i)
(if (= i 0)
result
(iter (/ (N i) (+ (D i) result)) (- i 1))
)
)
(iter (/ (N k) (D k) ) (- k 1) )
)
(define (getE)
( + 2.0 (cont-frac (lambda (i) 1.0) D 1000))
)
Exercise 1.39:
(define (tan-cf x k)
(define (N i)
(if (= i 1)
x
(* (- x) x)
)
)
(define (D i)
(- (* 2 i) 1)
)
(cont-frac N D k)
)
(define (cont-frac N D k)
(define (iter result i)
(if (= i 0)
result
(iter (/ (N i) (+ (D i) result)) (- i 1))
)
)
(iter (/ (N k) (D k) ) (- k 1) )
)
Exercise 1.40:
// (newtons-method (cubic a b c) 1)
(newtons-method (cubic 1 1 1) 1)
(define (newtons-method g guess)
(fixed-point (newton-transform g) guess)
)
(define (newton-transform g)
(lambda (x) (- x (/ (g x) ((deriv g) x))))
)
(define (deriv g)
(define dx 0.00001)
(lambda (x) (/ (- (g (+ x dx)) (g x)) dx))
)
(define (cubic a b c)
(lambda (x) (+ (* x x x) (* a (* x x)) (* b x) c))
)
(define tolerance 0.00001)
(define (fixed-point f first-guess)
(define (close-enough? v1 v2)
(< (abs (- v1 v2)) tolerance)
)
(define (try guess)
(let ((next (f guess)))
(cond ((close-enough? guess next)
next)
(else
(newline)
(display next)
(try next)
)
)
)
)
(try first-guess)
)
Exercise 1.41:
(define (inc a)
(+ a 1)
)
(define (double f)
(lambda (x) (f (f x)) )
)
((double inc) 1)
( ((double double) inc) 5)
Exercise 1.42:
(define (compose f g)
(lambda (x) (f (g x)) )
)
(define (square x) (* x x))
(define (inc a)
(+ a 1)
)
((compose square inc) 6)
Exercise 1.43:
(define (repeated f n)
(define (itera i result)
( if (= i n)
result
(itera (+ i 1) (compose f result))
)
)
(itera 1 f)
)
(define (compose f g)
(lambda (x) (f (g x)) )
)
(define (square x) (* x x))
((repeated square 2) 5)
Exercise 1.44:
(define (smooth f)
(define dx 0.00001)
(lambda (x) (/ (+ (f (+ x dx)) (f x) (f (- x dx))) 3))
)
(define (n-fold-smoothed f n)
((repeated smooth n) f)
)
Exercise 1.45:
(define (average-damp f)
(lambda (x) (average x (f x)))
)
(define (average x y)
(/ (+ x y) 2)
)
(define (cubert x)
(define (func x) (lambda (y) (/ x (cube y))))
(define (n-fold-average-damp n f)
((repeated average-damp n) f)
)
(fixed-point (n-fold-average-damp 3 (func x))
1.0))
(define (fixed-point f first-guess)
(define (close-enough? v1 v2)
(< (abs (- v1 v2)) tolerance)
)
(define tolerance 0.00001)
(define (try guess)
(let ((next (f guess)))
(cond ((close-enough? guess next)
next)
(else
(newline)
(display next)
(try next)
)
)
)
)
(try first-guess)
)
(define (cube x) (* x x x x x x x))
(define (repeated f n)
(define (itera i result)
( if (= i n)
result
(itera (+ i 1) (compose f result))
)
)
(itera 1 f)
)
(define (compose f g)
(lambda (x) (f (g x)) )
)
// 4th => fold twice average-damp
// 5th => fold twice average-damp
// 6th => fold twice average-damp
// 7th => fold twice average-damp 128
// 8th => fold 3th average-damp 256
y →x/y^n-1
Exercise 2.1
(define (gcd a b)
(if (= b 0)
a
(gcd b (remainder a b))))
(define (print-rat x)
(newline)
(display (numer x))
(display "/")
(display (denom x)))
(define (numer x) (car x))
(define (denom x) (cdr x))
(define (abs x)
(cond ((> x 0) x)
((= x 0) 0)
((< x 0) (- x))))
(define (make-rat n d)
(let ((g (gcd n d)))
(cond ((> (* n d) 0) (cons (abs(/ n g) ) (abs (/ d g))))
((< (* n d) 0) (cons (* -1 (/ n g)) (abs (/ d g)))
))
))
(define one-half (make-rat -1 -2))
(print-rat one-half)
Exercise 2.2:
(define (make-segment startP endP)
(cons startP endP))
(define (start-segment segment)
(car segment))
(define (end-segment segment)
(cdr segment))
(define (make-point x y)
(cons x y))
(define (x-point p)
(car p))
(define (y-point p)
(cdr p))
(define (print-point p)
(newline)
(display "(")
(display (x-point p))
(display ",")
(display (y-point p))
(display ")"))
(define (midpoint-segment segment)
(make-point
(average (x-point (start-segment segment)) (x-point (end-segment segment)))
(average (y-point (start-segment segment)) (y-point (end-segment segment)))
))
(define (length-segment segment)
(sqrt (+ (square (- (x-point (start-segment segment)) (x-point (end-segment segment)))) (square (- (y-point (start-segment segment)) (- (y-point (end-segment segment))))))))
(define (average x y)
(/ (+ x y) 2))
// test
(define startp (make-point 2 2))
(define endp (make-point 4 4))
(define line1 (make-segment startp endp))
(print-point (midpoint-segment line1))
Exercise 2.3:
(define (make-rect width height)
(cons width height))
(define (width-rect rect)
(car rect))
(define (heigth-rect rect)
(cdr rect))
(define (perimeter-rect rect)
(* 2 (+ (length-segment (width-rect rect)) (length-segment (heigth-rect rect)))))
(define (area-rect rect)
(* (length-segment (width-rect rect)) (length-segment (heigth-rect rect))))
Exercise 2.5:
(define (log3 x) (/ (log x) (log 3)))
(define (log2 x) (/ (log x) (log 2)))
(define (cons a b) (* (expt 2 a) (expt 3 b)))
(define (car x) (log2 (reduce x 3)))
(define (cdr x) (log3 (reduce x 2)))
(define (reduce n x)
(define (iter n)
(cond ((= 1 n) n)
((< 0 (remainder n x)) n)
(else (iter (/ n x))))
)
(iter n)
)
//test
(define n (cons 2 3))
(car n)
(cdr n)
Exercise 2.7:
(define (lower-bound interval)
(car interval))
(define (upper-bound interval)
(cdr interval))
Exercise 2.8:
(define (sub-interval x y)
(make-interval
(- (lower-bound x) (upper-bound y))
(- (upper-bound x) (lower-bound))))
Exercise 2.10:
(define (div-interval x y)
(if (or (0 = (upper-bound y)) (0 = (lower-bound y)))
(error "zero is not allowed in y" (upper-bound y) (lower-bound y))
(mul-interval
x
(make-interval (/ 1.0 (upper-bound y))
(/ 1.0 (lower-bound y))))))
Exercise 2.11:
(define (mul-interval x y)
(let ((p1 (* (lower-bound x) (lower-bound y)))
(p2 (* (lower-bound x) (upper-bound y)))
(p3 (* (upper-bound x) (lower-bound y)))
(p4 (* (upper-bound x) (upper-bound y))))
)
Exercise 2.12:
(define (make-center-percent c p)
(make-interval (- c (* c p)) (+ c (* c p))))
(define (percent i)
(/ (width i) (center i)))
(define (center i)
(/ (+ (lower-bound i) (upper-bound i)) 2))
Exercise 2.17:
(define (last-pair list)
(define (iter list)
(if (null? (cdr list))
(car list)
(iter (cdr list))
)
)
(iter list)
)
Exercise 2.18:
(define (reverse list1)
(define (iter listx result)
(if (null? listx)
result
(iter (cdr listx) (cons (car listx) result))
)
)
(iter list1 (list ))
)
Exercise 2.19:
(define (except-first-denomination coin-values)
(cdr coin-values)
)
(define (first-denomination coin-values)
(car coin-values)
)
(define (no-more? coin-values)
(null? coin-values)
)
Exercise 2.20:
(define (same-parity . listx)
(define (iter a)
(cond ((null? a) (list ))
((= (remainder (car listx) 2) (remainder (car a) 2)) (cons (car a) (iter (cdr a))))
(else (iter (cdr a)))
)
)
(iter listx)
)
Exercise 2.21:
(define (square-list items)
(if (null? items)
(list )
(cons (square (car items)) (square-list (cdr items)))))
(define (square-list items)
(map square items))
(define (map proc items)
(if (null? items)
(list )
(cons (proc (car items)) (map proc (cdr items)))
)
)
Exercise 2.23:
(define (for-each proc items)
(cond
(
(not(null? items))
(proc (car items))
(for-each proc (cdr items))
)
)
)
(for-each (lambda (x) (newline)
(display x))
(list 57 321 88))
Exercise 2.25:
(define (count-leaves x)
(cond (
(null? x) 0)
((and(not (pair? x)) (= x 7)) (display x))
(else (count-leaves (car x))
(count-leaves (cdr x))
)
)
)
(count-leaves (1 3 (5 7) 9))
Exercise 2.27:
(define (deep-reverse x)
(define a (reverse x))
(map (lambda (x) (
cond ((pair? x) (reverse x))
(else x)
)) a)
)
; test:
; (define a (list 1 2 (list 3 4 5)))
; (define b (list 1 2))
; (deep-reverse a)
; (deep-reverse b)
Exercise 2.28:
(define (fringe x)
(cond ((null? x) ())
((not (pair? x)) (list x))
(else (append () (fringe (car x))
(fringe (cdr x))))))
; test:
; (define a (list 1 (list 1 2) 3 (list 4 5 6) 7))
Exercise 2.29:
(define (left-branch mobile)
(car mobile)
)
(define (right-branch mobile)
(cadr mobile)
)
(define (branch-length branch)
(car branch)
)
(define (branch-structure branch)
(cadr branch)
)
(define (total-weight mobile)
(cond ((null? mobile) 0)
((not (pair? mobile)) mobile)
(else (+ (total-weight (branch-structure (left-branch mobile)))
(total-weight (branch-structure (right-branch mobile)))
))
)
(define (blanced? mobile)
(= (* (total-weight (left-branch mobile)) (branch-length (left-branch mobile)))
(* (total-weight (right-branch mobile)) (branch-length (right-branch mobile)))))
)
Exercise 2.30:
using map:
(define (square-tree tree )
(map
(lambda (sub-tree) (
if (pair? sub-tree)
(square-tree sub-tree)
(square sub-tree))
)
tree
)
)
using recursive:
(define (square-tree tree )
(cond ((null? tree) (list ))
((not(pair? tree)) (square tree))
(else (cons (square-tree (car tree)) (square-tree (cdr tree))))
)
)
Exercise 2.31:
(define (tree-map proc tree)
(define (iter tree)
(map
(lambda (sub-tree) (
if (pair? sub-tree)
(iter sub-tree)
(proc sub-tree))
)
tree
)
)
(iter tree)
)
Exercise 2.32:
(lambda (x)
(append (list (car s)) x)
)
(define (subsets s)
(if (null? s)
(list ())
(let ((rest (subsets (cdr s))))
(append rest (map (lambda (x)
(append (list (car s)) x)
) rest)
))
)
)
; (subsets (list 1 2 3))
Exercise 2.33:
(define (map p sequence)
(accumulate (lambda (x y) (cons (p x) y)) nil sequence))
(define (append seq1 seq2) (accumulate cons seq2 seq1))
(define (length sequence) (accumulate (lambda (x y) (+ 1 y)) 0 sequence))
Exercise 2.34:
(define (horner-eval x coefficient-sequence)
(accumulate
(lambda (this-coeff higher-terms)
(+ this-coeff (* x higher-terms))
)
0
coefficient-sequence
)
)
Exercise 2.35:
(define (count-leaves t)
(accumulate
+
0
(map
(lambda (x)
(cond ((pair? x) (count-leaves x))
(else 1)
)
)
t
)
)
)
Exercise 2.36:
(define (accumulate-n op init seqs)
(if (null? (car seqs))
nil
(cons
(accumulate op init (map (lambda (x) (car x)) seqs))
(accumulate-n op init (map (lambda (x) (cdr x)) seqs))
)
)
)
Exercise 2.37:
(define (matrix-*-vector m v)
(map (lambda (x) (dot-product v x)) m)
)
(define (transpose mat)
(accumulate-n cons nil mat)
)
(define (matrix-*-matrix m n)
(
let ((cols (transpose n)))
(map (lambda (v) (matrix-*-vector cols v)) m)
)
)
; test:
(define a (list (list 1 2) (list 3 4)))
(define c (list (list 1 2 3) (list 4 5 6) (list 7 8 9)))
(define v (list 1 2))
(define (dot-product v w)
(accumulate + 0 (map * v w)))
(matrix-*-vector a v)
Exercise 2.39:
(define (reverse sequence)
(fold-right
(lambda (x y)
(cons y x)
)
nil sequence))
(define (reverse sequence)
(fold-left (lambda (x y) (cons y x)) nil sequence))
Exercise 2.40:
(define (unique-pairs n)
(accumulate append nil
(map (lambda(i) (map (lambda (j) (list j i)) (enumerate-interval 1 (- i 1) ))) (enumerate-interval 1 n))
)
)
Exercise 2.41:
(define (triples n)
(accumulate append nil
(map (lambda (x)
(accumulate append nil
(map (lambda (y) (
map (lambda (z)
(list z y x)
) (enumerate-interval 1 (- y 1))
)) (enumerate-interval 1 (- x 1))
)
)
)
(enumerate-interval 1 n)
)
)
)
(define (func241 n s)
(accumulate append nil
(map (lambda (i)
(if (= (sum i) s)
i
nil
)
)
(triples n)
)
)
)
(define (sum items)
(accumulate + 0 items)
)
Exercise 2.42:
(define (queens board-size)
(define (queen-cols k)
(if (= k 0)
(list empty-board)
(filter
(lambda (positions) (safe? k positions))
(flatmap
(lambda (rest-of-queens) ;((1 1))
(map (lambda (new-row)
(adjoin-position new-row k rest-of-queens)
)
(enumerate-interval 1 board-size)
)
)
(queen-cols (- k 1)) ; (((1 1)))
)
)
)
)
(queen-cols board-size)
)
(define (adjoin-position new-row k rest-of-queens)
(append rest-of-queens (list(list k new-row)) )
)
(define empty-board nil)
(define (flatmap proc seq)
(accumulate append nil (map proc seq)))
(define (filter predicate sequence)
(cond ((null? sequence) nil)
((predicate (car sequence))
(cons (car sequence)
(filter predicate (cdr sequence))))
(else (filter predicate (cdr sequence)))))
(define (safe? k positions)
(if (null? positions) #t
(and (safe-p-ps? (car positions) (cdr positions))
(safe? k (cdr positions))
)
)
)
; (
; ((1 1) (2 1))
; ((1 1) (2 2))
; ((1 2) (2 1))
; ((1 2) (2 2))
; )
(define (safe-2p? positionA positionB)
(define x1 (car positionA))
(define y1 (cadr positionA))
(define x2 (car positionB))
(define y2 (cadr positionb))
(not(or (= x1 x2)
(= y1 y2)
(= (abs(- x1 x2)) (abs(- y1 y2)))
))
)
(define (safe-p-ps? position positions)
(if (null? positions) #t
(if (safe-2p? position (car positions))
(safe-p-ps? position (cdr positions))
#f
)
)
)
;
(define x (list (list 1 1) (list 2 3)))
(define p (list 1 2))
Exercise 2.43:
reason: (queen-cols (- k 1)) excuted in every (enumerate-interval 1 board-size) iterative
Exercise 2.44:
(define (up-split painter n)
(if (= n 0)
painter
(let ((smaller (up-split painter (- n 1))))
(below painter (beside smaller smaller)))))
(define (corner-split painter n)
(if (= n 0)
painter
(let (
(up (up-split painter (- n 1)))
(right (right-split painter (- n 1)))
)
(let (
(top-left (beside up up))
(bottom-right (below right right))
(corner (corner-split painter (- n 1)))
)
(beside (below painter top-left)
(below bottom-right corner))
)
)
)
)
(define (frame-coord-map frame)
(lambda (v)
(add-vect
(origin-frame frame)
(add-vect (scale-vect (xcor-vect v) (edge1-frame frame))
(scale-vect (ycor-vect v) (edge2-frame frame))
)
)
)
)
Exercise 2.46:
(define (make-vect x y) (list x y))
(define (xcor-vect v) (car v))
(define (ycor-vect v) (cadr v))
(define (add-vect v1 v2)
(list (+ (xcor-vect v1) (xcor-vect v2)) (+ (ycor-vect v1) (ycor-vect v2)))
)
(define (sub-vect v1 v2)
(list (- (xcor-vect v1) (xcor-vect v2)) (- (ycor-vect v1) (ycor-vect v2)))
)
(define (scale-vect s v)
(list (* s (xcor-vect v)) (* s (ycor-vect v)))
)
//frame selector
(define (make-frame origin edge1 edge2) (list origin edge1 edge2))
(define (origin-frame frame)
(car frame))
(define (edge1-frame frame)
(cadr frame)
)
(define (edge2-frame frame)
(caddr frame)
)
(define (segments->painter segment-list) (lambda (frame)
(for-each
(lambda (segment)
(draw-line
((frame-coord-map frame)
(start-segment segment))
((frame-coord-map frame)
(end-segment segment)))
)
segment-list))
)
Exercise 2.48:
(define (make-segment v1 v2) (list v1 v2))
(define (start-segment segment) (car segment))
(define (end-segment segment) (cadr segment))
Exercise 2.49:
a:
(
((0 0) (0 1))
((0 1) (1 1))
((1 1) (1 0))
((1 0) (0 0))
)
b:
(
((0 0) (0.5 0.5))
((0.5 0.5) (0 1))
((0 1) (0.5 0.5))
((0.5 0.5) (1 1))
((1 1) (0.5 0.5))
((0.5 0.5) (1 0))
)
Exercise 2.50:
(define (flip-horiz painter)
(transform-painter painter
(make-vect 1.0 0.0) ; new origin
(make-vect 0.0 0.0) ; new end of edge1
(make-vect 1.0 1.0))) ; new end of edge2
Exercise 2.51:
plan A:
(define (below painter1 painter2)
(let ((split-point (make-vect 0.0 0.5)))
(let ((paint-below (transform-painter
painter1
(make-vect 0.0 0.0)
(make-vect 0.0 1.0)
split-point))
(paint-top
(transform-painter
painter2
split-point
(make-vect 1.0 0.0)
(make-vect 0.0 1.0))))
(lambda (frame) (paint-below frame) (paint-top frame)))))
plan B:
(define (below painter1 painter2)
(let ((new-painter (beside (clockwise90 painter1) (clockwise90 painter2))))
(let ((rotated-painter (rotate90 new-painter)))
(lambda (frame) (rotated-painter frame))
)
)
)
(define (clockwise90 painter)
(transform-painter painter
(make-vect 0.0 1.0)
(make-vect 0.0 0.0)
(make-vect 1.0 1.0)))
Exercise 2.54:
(define (equal? list1 list2)
(cond ((and (null? list1) (null? list2)) #t)
((or (null? list1) (null? list2)) #f)
(else
(and (eq? (car list1) (car list2)) (equal? (cdr list1) (cdr list2))))
)
)
Exercise 2.56:
(define (exponentiation? x) (and (pair? x) (eq? (car x) '**)))
(define (base s) (cadr x))
(define (exponent s) (caddr x))
(define (make-exponentiation base exponent)
(cond ((=number? exponent 0) 1)
((=number? exponent 1) base)
((and (number? base) (number? exponent)) (expt base exponent))
(else (list '** base exponent))
)
)
(define (=number? a num) (and (number? a) (= num a)))
Exercise 2.57:
(define (augend p)
(accumulate make-sum 0 (cddr p))
)
(define (multiplicand p)
(accumulate make-product 1 (cddr p))
)
(define (accumulate op initial sequence)
(if (null? sequence)
initial
(op (car sequence)
(accumulate op initial (cdr sequence)))))
Exercise 2.58:
a:
(x + (3 * (x + (y + 2))))
1. change sum procedure:
(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 (addend s) (car s))
(define (augend s) (caddr s))
(define (sum? x) (and (pair? x) (eq? (cadr x) '+)))
2.change multiple procedure:
(define (make-product m1 m2)
(cond ((or (=number? m1 0) (=number? m2 0)) 0)
((=number? m1 1) m2)
((=number? m2 1) m1)
((and (number? m1) (number? m2)) (* m1 m2))
(else (list m1 '* m2))))
(define (multiplier p) (car p))
(define (multiplicand p) (caddr p))
(define (product? x) (and (pair? x) (eq? (cadr x) '*)))
Exercise 2.59:
(define (union-set set1 set2)
(cond ((null? set1) set2)
((null? set2) set1)
((element-of-set? (car set1) set2)
(union-set (cdr set1) set2))
(else (cons (car set1) (union-set (cdr set1) set2)))))
Exercise 2.61:
(define (addjoin-set x set)
(cond ((null? set) (cons x set))
((< x (car set)) (cons x set))
((= x (car set)) set)
((> x (car set)) (cons (car set) (addjoin-set x (cdr set))))
)
)
Exercise 2.68:
(define (exist-in x items) ;only for symbols
(cond ((null? items) #f)
((eq? x (car items)) #t)
(else (exist-in x (cdr items)))
)
)
(define (encode-symbol letter tree)
(cond ((and (leaf? tree) (eq? (symbol-leaf tree) letter)) '())
((exist-in letter (symbols (left-branch tree))) (append '(0) (encode-symbol letter (left-branch tree)) ))
((exist-in letter (symbols (right-branch tree))) (append '(1) (encode-symbol letter (right-branch tree)) ))
(else (error "bad letter" letter))
)
)
Exercise 2.69:
(define (successive-merge leaf-pairs)
(define (a leaf-pairs)
(cond ((null? (cdr leaf-pairs)) leaf-pairs)
(else
(a
(adjoin-set
(make-code-tree (car leaf-pairs) (cadr leaf-pairs))
(cddr leaf-pairs)
)
)
)
)
)
(car (a leaf-pairs))
)
(((leaf a 1) ((leaf b 1) ((leaf d 1) (leaf c 1) (d c) 2) (b d c) 4) (a b d c) 8))
Exercise 2.70:
(define pairs2 '((A 2) (GET 2) (SHA 3) (WAH 1) (BOOM 1) (JOB 2) (NA 16) (YIP 9)))
(define tree2 (generate-huffman-tree pairs2))
Exercise 2.71:
(define pairs271 '((a 1) (b 2) (c 4) (d 8) (e 16)))
(define tree271 (generate-huffman-tree pairs271))
(define (real-part x))
(define (imag-part x))
(define (magnitude x))
(define (angle x))
(define (make-from-real-imag ))
(define (make-from-mag-ang ))
(define (install-drive)
(define (sum operands var)
(make-sum (deriv (addend operands) var)
(deriv (augend operands) var)
)
)
(define (product operands var)
(make-sum (make-product
(multiplier operands)
(deriv (multiplicand operands) var))
(make-product
(deriv (multiplier operands) var)
(multiplicand operands)))
)
(put 'deriv '(+) sum)
(put 'deriv '(*) product)
)
Exercise 2.75
(define (make-from-mag-ang r a)
(lambda (op)
(cond ((eq? op 'real-part) (* r (cos a)))
((eq? op 'imag-part) (* r (sin a)))
((eq? op 'magnitute) r)
((eq? op 'angle) a)
(else (error "unknow op:make-from-mag-ang" op))
)
)
)
;test
(define z (make-from-mag-ang 1 0.785398))
(z 'angle)
Exercise 2.83:
(define (integer->rational n)
(make-rational n 1)
)
(define (rational->real n)
(make-scheme-number n)
)
(define (scheme-number->complex n)
(make-complex-from-real-imag (contents n) 0)
)
(put-coercion 'raise
'integer
integer->rational
)
(put-coercion 'raise
'rational
rational->real
)
(put-coercion 'raise
'scheme-number
scheme-number->complex
)
(define types-tower (list 'integer 'rational 'scheme-number 'complex))
(define (height type1 )
(index type1 types-tower)
)
(define (successive-rais arg1 arg2)
(let ( (type1 (type-tag arg1))
(type2 (type-tag arg2))
)
(cond ((= (height type1) (height type2))
(list arg1 arg2))
((> (height type1) (height type2))
(successive-rais arg1 ((get-coercion 'raise type2) arg2))
((< (height type1) (height type2))
(successive-rais ((get 'raise type1) arg1) type2))
)
)
)
(define (index x items)
(define (recuisive x items result)
(if (eq? x (car items))
result
(recuisive x (cdr items) (+ result 1))
)
)
(recuisive x items 0)
)
Exercise 2.84:
(define (apply-generic op . args)
(let ((type-tags (map type-tag args)))
(let ((proc (get op type-tags)))
(if proc
(apply proc (map contents args))
(if (= (length args) 2)
(let ((type1 (car type-tags))
(type2 (cadr type-tags))
(a1 (car args))
(a2 (cadr args)))
(if (equal? type1 type2) ; 新增
(error "No method for these types" (list op type-tags)) ;
(let ((same-type-args ((successive-rais a1 a2)))
(a1 (car same-type-args))
(a2 (cadr same-type-args)))
(apply-generic op a1 a2)
)))
(error "No method for these types"
(list op type-tags)))))))
Exercise 2.85:
(put-samplify 'drop
'complex
drop-complex
)
(define (drop-comlex n)
(cond ((= (imag-part n) 0) (make-rational (real-part n) 1))
(else #f)
)
)
(put-samplify 'drop
'real
drop-real
)
(define (drop-real n)
)
(put-samplify 'drop
'rational
drop-rational
)
(define (drop-rational n)
(cond ((= n (round n)) (make-scheme-number n))
(else #f)
)
)
(put-samplify 'drop
'scheme-number
drop-scheme-number
)
(define (drop-scheme-number n)
#f
)
(define (drop x)
(let (
(lower ((get 'drop (type-tag x)) x))
)
if(lower
(drop lower)
x
)
)
)
Exercise 2.87:
(define (zero? x)
((get 'zero? (type-tag x)) x)
)
(define (install-zero?-number)
(define (tag x) (attach-tag 'number x))
(put 'zero? 'number
(tag (lambda (x) (= 0 x)))
)
)
(define (install-zero?-rational)
(define (tag x) (attach-tag 'rational x))
(put 'zero? 'rational
(tag (lambda (x) (= 0 x)))
)
)
(define (install-zero?-real)
(define (tag x) (attach-tag 'real x))
(put 'zero? 'real
(tag (lambda (x) (= 0 x)))
)
)
(define (install-zero?-complex)
(define (tag x) (attach-tag 'complex x))
(put 'zero? 'complex
(tag (lambda (x) (and (= 0 (real-part x)) (0 = (imag-part x)))))
)
)
(define (install-zero?-polynomial)
(define (tag x) (attach-tag 'polynomial x))
(put 'zero? 'polynomial
(tag (lambda (x) (null? x)))
)
)
Exercise 2.88:
(define (negation x)
((get 'negation (type-tag x)) x)
)
(define (install-negation-number)
(define (tag x) (attach-tag 'number x))
(put 'negation 'number
(tag (lambda (x) -x))
)
)
(define (install-negation-rational)
(define (tag x) (attach-tag 'rational x))
(put 'negation 'rational
(tag (lambda (x) -x))
)
)
(define (install-negation-real)
(define (tag x) (attach-tag 'real x))
(put 'negation 'real
(tag (lambda (x) -x))
)
)
(define (install-negation-complex)
(define (tag x) (attach-tag 'complex x))
(put 'negation 'complex
(tag (lambda (x)
(make-complex-from-real-imag
(negation (real-part x))
(negation (imag-part x)))))
)
)
(define (install-negation-polynomial)
(define (tag x) (attach-tag 'polynomial x))
(put 'negation 'polynomial
(tag (lambda (x)
(let ((terms (term-list x)))
(make-polynomial (variable x) (map negation terms))
)
))
)
)
(define (sub-poly p1 p2)
(add-poly p1 (negation p2))
)
Exercise 2.89:
(define (intall-polynomial-dense)
(define (adjoin-term term term-list)
(if (=zero? (coeff term))
term-list
(cons term term-list)
)
)
(define (make-term order coeff)
coeff
)
(define (order term)
(length (cdr term-list))
)
(define (coeff term)
term
)
(define (tag x) (attach-tag 'dense x))
(put 'adjoin-term
'dense
adjoin-term
)
(put 'make-term
'dense
make-term
)
(put 'order
'dense
order
)
(put 'coeff
'dense
coeff
)
)
Exercise 2.90:
(define (div-terms L1 L2)
(if (empty-termlist? L1)
(list (the-empty-termlist) (the-empty-termlist))
(let ((t1 (first-term L1))
(t2 (first-term L2)))
(if (> (order t2) (order t1))
(list (the-empty-termlist) L1)
(let ((new-c (div (coeff t1) (coeff t2)))
(new-o (- (order t1) (order t2))))
(let ((new-term (make-term new-o new-c)))
(let ((rest-of-result (div-terms (sub-terms L1 (mul-term-by-all-terms new-term L2)) L2)))
(list (adjoin-term new-term (car rest-of-result)) (cadr rest-of-result))
)
)
)
)
)
)
)
(define term-list1 (list (list 5 1) (list 0 -1)))
(define term-list2 (list (list 2 1) (list 0 -1)))
(define term-list3 (list (list 1 1) (list 0 1)))
~/wangshaosen/codes/demo
| false |
f6d104ad54b7cb1bc480180ee5372d395b7b7320 | 195b14175649b777509d54956780c084f1bc0ea0 | /example/button.scm | a2c394ee8266fe1c8102694f24caa95521affc20 | []
| no_license | ktakashi/sagittarius-turquoise | 4ebeb920375e171a9ade05bd813e39416dbe75fd | f88e67789d7b0257c59b6942406aa93fbbcc76f8 | refs/heads/master | 2021-01-02T22:31:40.023461 | 2015-12-15T19:42:15 | 2015-12-15T19:42:15 | 10,245,087 | 0 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 453 | scm | button.scm | (import (clos user) (turquoise)
(sagittarius object))
;; default size for all buttons
(define-method slot-unbound ((c <class>) (b <button>) (s (eqv? 'width))) 100)
(define-method slot-unbound ((c <class>) (b <button>) (s (eqv? 'height))) 27)
(let ((window (make <frame> :name "One Button Window"))
(button (make <button> :name "Button")))
(add! window button)
(add! button (lambda (button event)
(print (~ event 'action))))
(window)) | false |
8d2ce26163e5297aee892bafb389d5969386da5b | 982919bd7728330f3bb6568f22dfd0d4e348affa | /continuation/utility/eval.ss | 0147d47aa94274d4072d4a7628ee37482237e049 | []
| no_license | thzt/scheme-interpreter | 9fb389ea9146e2a5a8d7fa6ef2808d4c25c035d3 | 267dc29aec2e02df8f7de4b1072466d12a97248d | refs/heads/master | 2021-01-19T17:13:10.368468 | 2015-10-30T09:40:40 | 2015-10-30T09:40:40 | 39,499,402 | 8 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 3,082 | ss | eval.ss | (library (utility eval)
(export eval-exp *env* *cont*)
(import (rnrs) (utility tool) (utility datatype))
(define *env* `(,(create-frame)))
(define *cont* (lambda (v)
(display v)))
(define (eval-exp exp env cont)
(handle-decision-tree
`((,is-symbol? ,eval-symbol)
(,is-self-eval-exp? ,eval-self-eval-exp)
(,is-continuation? ,eval-continuation)
(,is-list?
((,is-lambda? ,eval-lambda)
(,is-call/cc? ,eval-call/cc)
(,is-continuation-call? ,eval-continuation-call)
(,is-function-call-list? ,eval-function-call-list))))
exp env cont))
(define (is-symbol? exp env cont)
(display "is-symbol?\n")
(cont (symbol? exp)))
(define (eval-symbol exp env cont)
(display "eval-symbol\n")
(cont (get-symbol-value env exp)))
(define (is-self-eval-exp? exp env cont)
(display "is-self-eval-exp?\n")
(cont (number? exp)))
(define (eval-self-eval-exp exp env cont)
(display "eval-self-eval-exp\n")
(cont exp))
(define (is-continuation? exp env cont)
(display "is-continuation?\n")
(cont (continuation? exp)))
(define (eval-continuation exp env cont)
(display "eval-continuation\n")
(cont exp))
(define (is-list? exp env cont)
(display "is-list?\n")
(cont (list? exp)))
(define (is-lambda? exp env cont)
(display "is-lambda?\n")
(cont (eq? (car exp) 'lambda)))
(define (eval-lambda exp env cont)
(display "eval-lambda\n")
(let ((param (caadr exp))
(body (caddr exp)))
(cont (make-closure param body env))))
(define (is-call/cc? exp env cont)
(display "is-call/cc?\n")
(cont (eq? (car exp) 'call/cc)))
(define (eval-call/cc exp env cont)
(display "eval-call/cc\n")
(let ((fn (cadr exp))
(continuation (make-continuation cont)))
(eval-function-call-list `(,fn ,continuation) env cont)))
(define (is-continuation-call? exp env cont)
(display "is-continuation-call?\n")
(eval-exp (car exp) env
(lambda (value)
(cont (continuation? value)))))
(define (eval-continuation-call exp env cont)
(display "eval-continuation-call\n")
(eval-exp (car exp) env
(lambda (continuation)
(let ((wrapped-cont (continuation-cont continuation)))
(eval-exp (cadr exp) env
(lambda (arg)
(wrapped-cont arg)))))))
(define (is-function-call-list? exp env cont)
(display "is-function-call-list?\n")
(cont #t))
(define (eval-function-call-list exp env cont)
(display "eval-function-call-list\n")
(eval-exp (car exp) env
(lambda (closure)
(eval-exp (cadr exp) env
(lambda (arg)
(let ((body (closure-body closure))
(lexical-env (closure-env closure))
(param (closure-param closure))
(frame (create-frame)))
(extend-frame frame param arg)
(let ((executing-env (extend-env lexical-env frame)))
(eval-exp body executing-env cont))))))))
)
| false |
6fe612ef2184ba24202d69f8fcdd3ff77a6173d1 | 1b1828426867c9ece3f232aaad1efbd2d59ebec7 | /Chapter 3/sicp3-58.scm | c1f7cb59e4a55269746e68845d4e822a7f8a3464 | []
| no_license | vendryan/sicp | 60c1338354f506e02c714a96f643275d35a7dc51 | d42f0cc6f985aaf369f2760f962928381ca74332 | refs/heads/main | 2023-06-07T02:04:56.332591 | 2021-06-19T10:28:57 | 2021-06-19T10:28:57 | 369,958,898 | 0 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 1,008 | scm | sicp3-58.scm | (define (expand num den radix)
(cons-stream
(quotient (* num radix) den)
(expand (remainder (* num radix) den) den radix)))
(expand 1 7 10)
; The evolution of (expand 1 7 10)
; (cons-stream 1 (expand 3 7 10))
; (cons-stream 1
; (cons-stream 4 (expand 2 7 10)))
; (cons-stream 1
; (cons-stream 4
; (cons-stream 2
; (expand 6 7 10))))
; (cons-stream 1
; (cons-stream 4
; (cons-stream 2
; (cons-stream 8
; (expand 4 7 10)))))
; 1, 4, 2, 8, 5 (expand 5 7 10)
; 1, 4, 2, 8, 5, 7 (expand 1 7 10) (alternate again)
;
; The num will alternate from 1 to den - 1
; And the quotient also is alternating
; (expand 3 8 10)
; 3, (expand 6 8 10)
; 3, 7 (expand 4 8 10)
; 3, 7, 5 (expand 0 8 10)
; 3, 7, 5, 0 (expand 0 8 10) ...
; And also when the remainder is 0, it will produce 0 endlessly
| false |
b291128c11dd0c334f6136e6d7cc7b2f2b2b0b81 | 736e7201d8133f7b5262bbe3f313441c70367a3d | /misc/internal/windows/TeXmacs/progs/ice-9/session.scm | a03edcc7ee84de7000195ba49c2d2a0a4cbfd361 | []
| no_license | KarlHegbloom/texmacs | 32eea6e344fd27ff02ff6a8027c065b32ff2b976 | ddc05600d3d15a0fbc72a50cb657e6c8ebe7d638 | refs/heads/master | 2021-01-16T23:52:33.776123 | 2018-06-08T07:47:26 | 2018-06-08T07:47:26 | 57,338,153 | 24 | 4 | null | 2017-07-17T05:47:17 | 2016-04-28T22:37:14 | Tcl | UTF-8 | Scheme | false | false | 10,428 | scm | session.scm | ;;;; Copyright (C) 1997, 2000 Free Software Foundation, Inc.
;;;;
;;;; This program is free software; you can redistribute it and/or modify
;;;; it under the terms of the GNU General Public License as published by
;;;; the Free Software Foundation; either version 2, or (at your option)
;;;; any later version.
;;;;
;;;; This program is distributed in the hope that it will be useful,
;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;;;; GNU General Public License for more details.
;;;;
;;;; You should have received a copy of the GNU General Public License
;;;; along with this software; see the file COPYING. If not, write to
;;;; the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
;;;; Boston, MA 02111-1307 USA
;;;;
(define-module (ice-9 session)
:use-module (ice-9 documentation)
:use-module (ice-9 regex)
)
;;; Documentation
;;;
(define-public help
(procedure->syntax
(lambda (exp env)
"(help [NAME])
Prints useful information. Try `(help)'."
(cond ((not (= (length exp) 2))
(help-usage))
((not (feature? 'regex))
(display "`help' depends on the `regex' feature.
You don't seem to have regular expressions installed.\n"))
(else
(let ((name (cadr exp)))
(cond ((symbol? name)
(help-doc name
(string-append "^"
(regexp-quote
(symbol->string name))
"$")))
((string? name)
(help-doc name name))
((and (list? name)
(= (length name) 2)
(eq? (car name) 'unquote))
(let ((doc (object-documentation (local-eval (cadr name)
env))))
(if (not doc)
(simple-format #t "No documentation found for ~S\n"
(cadr name))
(write-line doc))))
(else
(help-usage)))
*unspecified*))))))
(define (help-doc term regexp)
(let ((entries (apropos-fold (lambda (module name object data)
(cons (list module
name
(object-documentation object))
data))
'()
regexp
apropos-fold-exported))
(module car)
(name cadr)
(doc caddr))
(if (null? entries)
;; no matches
(begin
(display "Did not find any object ")
(simple-format #t
(if (symbol? term)
"named `~A'\n"
"matching regexp \"~A\"\n")
term))
(let ((first? #t))
(if (or-map doc entries)
;; entries with documentation
(for-each (lambda (entry)
;; *fixme*: Use `describe' when we have GOOPS?
(if (doc entry)
(begin
(if first?
(set! first? #f)
(newline))
(simple-format #t "~S: ~S\n~A\n"
(module-name (module entry))
(name entry)
(doc entry)))))
entries))
(if (or-map (lambda (x) (not (doc x))) entries)
;; entries without documentation
(begin
(if (not first?)
(display "\nNo documentation found for:\n"))
(for-each (lambda (entry)
(if (not (doc entry))
(simple-format #t "~S: ~S\n"
(module-name (module entry))
(name entry))))
entries)))))))
(define (help-usage)
(display "Usage: (help NAME) gives documentation about objects named NAME (a symbol)
(help REGEXP) ditto for objects with names matching REGEXP (a string)
(help ,EXPR) gives documentation for object returned by EXPR
(help) gives this text
`help' searches among bindings exported from loaded modules, while
`apropos' searches among bindings visible from the \"current\" module.
Examples: (help help)
(help cons)
(help \"output-string\")
Other useful sources of helpful information:
(apropos STRING)
(arity PROCEDURE)
(name PROCEDURE-OR-MACRO)
(source PROCEDURE-OR-MACRO)
Tools:
(backtrace) ;show backtrace from last error
(debug) ;enter the debugger
(trace [PROCEDURE]) ;trace procedure (no arg => show)
(untrace [PROCEDURE]) ;untrace (no arg => untrace all)
(OPTIONSET-options 'full) ;display option information
(OPTIONSET-enable 'OPTION)
(OPTIONSET-disable 'OPTION)
(OPTIONSET-set! OPTION VALUE)
where OPTIONSET is one of debug, read, eval, print
"))
;;; {Apropos}
;;;
;;; Author: Roland Orre <[email protected]>
;;;
(define (id x) x)
(define-public (apropos rgx . options)
"Search for bindings: apropos regexp {options= 'full 'shadow 'value}"
(if (zero? (string-length rgx))
"Empty string not allowed"
(let* ((match (make-regexp rgx))
(modules (cons (current-module)
(module-uses (current-module))))
(separator #\tab)
(shadow (member 'shadow options))
(value (member 'value options)))
(cond ((member 'full options)
(set! shadow #t)
(set! value #t)))
(for-each
(lambda (module)
(let* ((builtin (or (eq? module the-scm-module)
(eq? module the-root-module)))
(name (module-name module))
(obarrays (if builtin
(list (builtin-weak-bindings)
(builtin-bindings))
(list (module-obarray module))))
(get-refs (if builtin
(list id id)
(list variable-ref)))
)
(for-each
(lambda (obarray get-ref)
(array-for-each
(lambda (oblist)
(for-each
(lambda (x)
(cond ((regexp-exec match (car x))
(display name)
(display ": ")
(display (car x))
(cond ((procedure? (get-ref (cdr x)))
(display separator)
(display (get-ref (cdr x))))
(value
(display separator)
(display (get-ref (cdr x)))))
(if (and shadow
(not (eq? (module-ref module
(car x))
(module-ref (current-module)
(car x)))))
(display " shadowed"))
(newline)
)))
oblist))
obarray))
obarrays get-refs)))
modules))))
(define-public (apropos-internal rgx)
"Return a list of accessible variable names."
(apropos-fold (lambda (module name var data)
(cons name data))
'()
rgx
(apropos-fold-accessible (current-module))))
(define-public (apropos-fold proc init rgx folder)
"Folds PROCEDURE over bindings matching third arg REGEXP.
Result is
(PROCEDURE MODULE1 NAME1 VALUE1
(PROCEDURE MODULE2 NAME2 VALUE2
...
(PROCEDURE MODULEn NAMEn VALUEn INIT)))
where INIT is the second arg to `apropos-fold'.
Fourth arg FOLDER is one of
(apropos-fold-accessible MODULE) ;fold over bindings accessible in MODULE
apropos-fold-exported ;fold over all exported bindings
apropos-fold-all ;fold over all bindings"
(let ((match (make-regexp rgx))
(recorded (make-vector 61 '())))
(let ((fold-module
(lambda (module data)
(let* ((obarray-filter
(lambda (name val data)
(if (and (regexp-exec match name)
(not (hashq-get-handle recorded name)))
(begin
(hashq-set! recorded name #t)
(proc module name val data))
data)))
(module-filter
(lambda (name var data)
(obarray-filter name (variable-ref var) data))))
(cond ((or (eq? module the-scm-module)
(eq? module the-root-module))
(hash-fold obarray-filter
(hash-fold obarray-filter
data
(builtin-bindings))
(builtin-weak-bindings)))
(module (hash-fold module-filter
data
(module-obarray module)))
(else data))))))
(folder fold-module init))))
(define (make-fold-modules init-thunk traverse extract)
"Return procedure capable of traversing a forest of modules.
The forest traversed is the image of the forest generated by root
modules returned by INIT-THUNK and the generator TRAVERSE.
It is an image under the mapping EXTRACT."
(lambda (fold-module init)
(let* ((table (make-hash-table 31))
(first? (lambda (obj)
(let* ((handle (hash-create-handle! table obj #t))
(first? (cdr handle)))
(set-cdr! handle #f)
first?))))
(let rec ((data init)
(modules (init-thunk)))
(do ((modules modules (cdr modules))
(data data (if (first? (car modules))
(rec (fold-module (extract (car modules)) data)
(traverse (car modules)))
data)))
((null? modules) data))))))
(define-public (apropos-fold-accessible module)
(make-fold-modules (lambda () (list module))
module-uses
(lambda (x) x)))
(define (root-modules)
(cons the-root-module
(submodules (nested-ref the-root-module '(app modules)))))
(define (submodules m)
(hash-fold (lambda (name var data)
(let ((obj (variable-ref var)))
(if (and (module? obj)
(eq? (module-kind obj) 'directory))
(cons obj data)
data)))
'()
(module-obarray m)))
(define-public apropos-fold-exported
(make-fold-modules root-modules submodules module-public-interface))
(define-public apropos-fold-all
(make-fold-modules root-modules submodules (lambda (x) x)))
(define-public (source obj)
(cond ((procedure? obj) (procedure-source obj))
((macro? obj) (procedure-source (macro-transformer obj)))
(else #f)))
(define-public (arity obj)
(let ((arity (procedure-property obj 'arity)))
(display (car arity))
(cond ((caddr arity)
(display " or more"))
((not (zero? (cadr arity)))
(display " required and ")
(display (cadr arity))
(display " optional")))
(if (and (not (caddr arity))
(= (car arity) 1)
(<= (cadr arity) 1))
(display " argument")
(display " arguments"))
(if (closure? obj)
(let ((formals (cadr (procedure-source obj))))
(if (pair? formals)
(begin
(display ": `")
(display (car formals))
(let loop ((ls (cdr formals)))
(cond ((null? ls)
(display #\'))
((not (pair? ls))
(display "', the rest in `")
(display ls)
(display #\'))
(else
(if (pair? (cdr ls))
(display "', `")
(display "' and `"))
(display (car ls))
(loop (cdr ls))))))
(begin
(display " in `")
(display formals)
(display #\')))))
(display ".\n")))
(define-public system-module
(procedure->syntax
(lambda (exp env)
(let* ((m (nested-ref the-root-module
(append '(app modules) (cadr exp)))))
(if (not m)
(error "Couldn't find any module named" (cadr exp)))
(let ((s (not (procedure-property (module-eval-closure m)
'system-module))))
(set-system-module! m s)
(string-append "Module " (symbol->string (module-name m))
" is now a " (if s "system" "user") " module."))))))
| false |
1e794c459820e890ae154ddb19f7e3904278f41a | 863be632226fd9cdf31e26a26bc2433e1b4c196a | /benchmarks/CM.sch | e5453f07fdb00d37e064aa5aea1505b40391844b | []
| no_license | dvanhorn/oaam | 6902a03a70f19367960e389eeb277d9684dc9ca2 | 79bc68ecb79fef45474a948deec1de90d255f307 | refs/heads/master | 2021-01-20T08:48:50.237382 | 2017-04-06T17:17:35 | 2017-04-06T17:17:35 | 6,099,975 | 24 | 2 | null | 2017-04-06T17:17:36 | 2012-10-06T05:03:44 | Racket | UTF-8 | Scheme | false | false | 215 | sch | CM.sch | #;#;
(define (UserFn sys) (sys UserFn))
(define (SystemFn user) (user SystemFn))
(define (RAUserFn sys)
(frame (A) (sys RAUserFn)))
(define (RSSystemFn user)
(frame (S) (user RSSystemFn)))
(RAUserFn RSSystemFn) | false |
56a5573b731acccb6a0c13ed9c912e5d309dc704 | 9d7417f187812a477793ca23da844b34ab2a139d | /Graphikos/GraphikosTests/lib/ironscheme/contracts-helper.sls | 2c0ea022462dcdfd914b336974fae63dc645393b | [
"MIT",
"BSD-3-Clause"
]
| permissive | simonmoriat/PLP | 5ae19daba4925919b593b4a21dc91dec9de9a6ce | 3d130acaa45239cdb289462a242a8c15836a39ca | refs/heads/master | 2023-05-11T23:36:28.347462 | 2016-06-08T07:07:50 | 2016-06-08T07:07:50 | null | 0 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 3,203 | sls | contracts-helper.sls | #| License
Copyright (c) 2007-2015 Llewellyn Pritchard
All rights reserved.
This source code is subject to terms and conditions of the BSD License.
See docs/license.txt. |#
(library (ironscheme contracts-helper)
(export
parse-body)
(import
(ironscheme)
(only (ironscheme unsafe) $car $cdr)
(ironscheme clr))
(define (string-split str . del)
(clr-call String (Split String[] StringSplitOptions) str (list->vector del) 'None))
(define (parse-body loc x)
(define (get-name/type name)
(let ((tokens (string-split
(symbol->string (syntax->datum name))
":")))
(when (zero? (string-length (vector-ref tokens 0)))
(syntax-violation 'get-name/type "length of argument > 0" name))
(if (= 1 (vector-length tokens))
(cons
(datum->syntax name
(string->symbol (vector-ref tokens 0))) #f)
(cons*
(datum->syntax name
(string->symbol (vector-ref tokens 0)))
(datum->syntax name
(string->symbol
(string-append (vector-ref tokens 1) "?")))
(vector-ref tokens 1)))))
(define (make-guard ai)
(with-syntax ((n (car ai))
(g (cadr ai))
(l loc)
(s (string-append "not " (cddr ai))))
#'(unless (g n)
(assertion-violation 'l s n))))
(define (make-list-guard ai)
(with-syntax ((n (car ai))
(g (cadr ai))
(l loc)
(s (string-append "not " (cddr ai))))
; the compiler generates stupid code for this, but still faster than using for-all
#'(let loop ((n n))
(unless (null? n)
(unless (g ($car n)) (assertion-violation 'l s ($car n)))
(loop ($cdr n))))))
(syntax-case x ()
[((a ...) body body* ...)
(for-all identifier? #'(a ...))
(let ((ai (map get-name/type #'(a ...))))
(with-syntax (((a ...) (map car ai))
((g ...) (map make-guard (filter cdr ai))))
#'((a ...)
g ...
(let ((a a) ...) body body* ...))))]
[((a a* ... . rest) body body* ...)
(and (for-all identifier? #'(a a* ...)) (identifier? #'rest))
(let ((ai (map get-name/type #'(a a* ...)))
(ri (get-name/type #'rest)))
(with-syntax (((a ...) (map car ai))
((g ...) (map make-guard (filter cdr ai)))
(rest (car ri))
(h (if (cdr ri) (make-list-guard ri) #'#f)))
#'((a ... . rest)
g ...
h
(let ((a a) ... (rest rest)) body body* ...))))]
[(formals body body* ...)
(identifier? #'formals)
(let ((ri (get-name/type #'formals)))
(with-syntax ((formals (car ri))
(h (if (cdr ri) (make-list-guard ri) #'#f)))
#'(formals
h
(let ((formals formals)) body body* ...))))])))
| false |
54dba1903e2ed22a6a17ffb07c92a8f3bd494ad0 | 000dbfe5d1df2f18e29a76ea7e2a9556cff5e866 | /lib/core/record/procedural.scm | a3cb93f8345f64326830c02b633866e00ee5ed44 | [
"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 | 12,006 | scm | procedural.scm | ;; -*- scheme -*-
#!core
(library (core record procedural)
(export make-record-type-descriptor
record-type-descriptor?
make-record-constructor-descriptor
record-constructor
record-predicate
record-accessor
record-mutator
make-record-type
;; for inspection
record?
record-rtd
record-type-name
record-type-parent
record-type-uid
record-type-generative?
record-type-sealed?
record-type-opaque?
record-type-field-names
record-field-mutable?
;; for convenient and compatibility
search-kth-slot
record-type-rcd
record-type-rtd
<record-type-descriptor>
<record-constructor-descriptor>
default-protocol)
(import (core)
(core base)
(core errors)
(core syntax)
(sagittarius)
(clos user) ;; we can use it here
(clos core)
(sagittarius clos)) ;; for <record-type-meta>
;; TODO how should we make this thread safe?
(define nongenerative-record-types (make-eq-hashtable))
(define-class <record-type-descriptor> ()
((name :init-keyword :name :reader record-type-name)
(parent :init-keyword :parent :reader record-type-parent)
(uid :init-keyword :uid :reader record-type-uid)
(sealed? :init-keyword :sealed? :reader record-type-sealed?)
(opaque? :init-keyword :opaque? :reader record-type-opaque?)
(fields :init-keyword :fields :reader rtd-fields)
;; instanciate class
(class :init-keyword :class :reader rtd-class)))
(define-class <record-constructor-descriptor> ()
((rtd :init-keyword :rtd :reader rcd-rtd)
(protocol :init-keyword :protocol :reader rcd-protocol)
(has-protocol? :init-keyword :has-protocol? :reader rcd-has-protocol?)
(parent :init-keyword :parent :reader rcd-parent)))
(define-method compute-getter-and-setter ((c <record-type-meta>) slot)
(let ((mutability (slot-definition-option slot :mutable #f))
(accessors (call-next-method)))
(if mutability
accessors
(list (car accessors)
(lambda (o v) (error 'record-accessor
"field is immutable"
(slot-definition-name slot) o))
(caddr accessors)))))
(define (make-record-type-descriptor name parent uid sealed? opaque? fields)
(define (make-rtd name parent uid sealed? opaque? fields type)
(define (make-it)
(make <record-type-descriptor>
:name name :parent parent :uid uid
:sealed? sealed? :opaque? opaque?
:fields fields :class type))
(cond ((not uid) (make-it))
((hashtable-ref nongenerative-record-types uid #f)
=> (lambda (current)
(if (and (eqv? uid (record-type-uid current))
(eqv? parent (record-type-parent current))
(equal? fields (rtd-fields current)))
current
(assertion-violation
'make-record-type-descriptor
"mismatched subsequent call for nongenerative record-type"
(list name parent uid sealed? opaque? fields)))))
(else
;; TODO thread safety...
(let ((new (make-it)))
(hashtable-set! nongenerative-record-types uid new)
new))))
(define (process-fields fields)
;; -> slot form
(map (lambda (field)
(if (pair? field)
(let ((mutability (car field))
(name (cadr field)))
;; TODO check mutability keyword
(list name :mutable (eq? mutability 'mutable)
:init-keyword (make-keyword name)))
(error 'make-record-type-descriptor "invalid field")))
(vector->list fields)))
(or (symbol? name)
(assertion-violation 'make-record-type-descriptor
(wrong-type-argument-message "symbol" name 1)
(list name parent uid sealed? opaque? fields)))
(or (vector? fields)
(assertion-violation 'make-record-type-descriptor
(wrong-type-argument-message "vector" fields 6)
(list name parent uid sealed? opaque? fields)))
(and parent
(or (record-type-descriptor? parent)
(assertion-violation 'make-record-type-descriptor
(wrong-type-argument-message "record-type descriptor or #f"
parent 2)
(list name parent uid sealed? opaque? fields)))
(and (record-type-sealed? parent)
(assertion-violation 'make-record-type-descriptor
"attempt to extend a sealed record-type"
parent)))
(let* ((p (and parent (slot-ref parent 'class)))
(opaque? (or opaque? (and parent (record-type-opaque? parent))))
(type (make <record-type-meta>
:definition-name name
:direct-supers (or (and p (list p)) '())
:direct-slots (process-fields fields)
:defined-library (current-library)))
(rtd (make-rtd name parent uid sealed? opaque? fields type)))
(slot-set! type 'rtd rtd)
rtd))
(define (record-type-descriptor? o) (is-a? o <record-type-descriptor>))
(define (make-record-constructor-descriptor rtd parent protocol)
(unless (record-type-descriptor? rtd)
(assertion-violation 'make-record-constructor-descriptor
(wrong-type-argument-message "record-type-descriptor" rtd 1)
(list rtd parent protocol)))
(and parent
(or (record-constructor-descriptor? parent)
(assertion-violation 'make-record-constructor-descriptor
(wrong-type-argument-message "record-constructor-descriptor or #f"
parent 2)
(list rtd parent protocol))))
(and protocol
(or (procedure? protocol)
(assertion-violation
'make-record-constructor-descriptor
(wrong-type-argument-message "procedure or #f" protocol 3)
(list rtd parent protocol))))
(and parent
(or (record-type-parent rtd)
(assertion-violation
'make-record-constructor-descriptor
"mismatch between rtd and parent constructor descriptor"
rtd parent protocol)))
(and parent
(record-type-parent rtd)
(or (eq? (rcd-rtd parent) (record-type-parent rtd))
(assertion-violation
'make-record-constructor-descriptor
"mismatch between rtd and parent constructor descriptor"
rtd parent protocol)))
(and protocol
(record-type-parent rtd)
(or parent
(assertion-violation
'make-record-constructor-descriptor
"expected #f for protocol since no parent constructor descriptor is provided"
rtd parent protocol)))
(and parent
(rcd-has-protocol? parent)
(or protocol
(assertion-violation
'make-record-constructor-descriptor
"expected procedure for protocol since parent constructor descriptor have custom one"
rtd parent protocol)))
(make <record-constructor-descriptor>
:rtd rtd
:parent (or parent
(cond ((record-type-parent rtd)
=> (lambda (rtd)
(make-record-constructor-descriptor
rtd #f #f)))
(else #f)))
:protocol (or protocol (default-protocol rtd))
:has-protocol? (if protocol #t #f)))
(define (record-constructor-descriptor? o)
(is-a? o <record-constructor-descriptor>))
;; this is internal procedure used from define-record-type
;; thus we don't expect to be used anywhere else but there.
;; so we can set the rcd to rtd safely (i guess).
(define (make-record-type name rtd rcd)
(slot-set! (slot-ref rtd 'class) 'rcd rcd)
(slot-ref rtd 'class))
(define (rtd-total-field-count rtd)
(length (class-slots (slot-ref rtd 'class))))
(define (record-type-rtd type) (slot-ref type 'rtd))
(define (record-type-rcd type) (slot-ref type 'rcd))
(define (record-constructor rcd)
(unless (record-constructor-descriptor? rcd)
(assertion-violation 'record-constructor
(format "record-constructor-descriptor required but got ~s" rcd)
rcd))
(let ((rtd (rcd-rtd rcd)))
(if (rcd-parent rcd)
(let ((class (slot-ref rtd 'class)))
(make-nested-conser rcd rtd (slot-ref class 'nfields)))
(make-simple-conser rcd rtd (vector-length (rtd-fields rtd))))))
(define (%make-record rtd field-values)
(let* ((class (slot-ref rtd 'class))
;; TODO create (kw v) list to make mutable/immutable thing
(tuple (make class)))
(for-each (lambda (acc value)
(slot-set-using-accessor! tuple acc value))
(slot-ref class 'getters-n-setters) field-values)
tuple))
(define (make-nested-conser desc rtd argc)
((rcd-protocol desc)
((let loop ((desc desc))
(cond ((rcd-parent desc)
=> (lambda (parent)
(lambda extra-field-values
(lambda protocol-args
(lambda this-field-values
(apply ((rcd-protocol parent)
(apply (loop parent)
(append this-field-values
extra-field-values)))
protocol-args))))))
(else
(lambda extra-field-values
(lambda this-field-values
(let ((field-values (append this-field-values
extra-field-values)))
(if (= (length field-values) argc)
(%make-record rtd field-values)
(assertion-violation "record constructor"
(format "wrong number of arguments, required ~d but got ~d"
argc (length field-values))
field-values)))))))))))
(define (make-simple-conser desc rtd argc)
((rcd-protocol desc)
(lambda field-values
(if (= (length field-values) argc)
(%make-record rtd field-values)
(assertion-violation "record constructor"
(format "wrong number of arguments, required ~d but got ~d"
argc (length field-values))
field-values)))))
(define (default-protocol rtd)
(let ((parent (record-type-parent rtd)))
(if parent
(let ((parent-field-count (rtd-total-field-count parent)))
(lambda (p)
(lambda field-values
(receive (parent-field-values this-field-values)
(split-at field-values parent-field-count)
(let ((n (apply p parent-field-values)))
(apply n this-field-values))))))
(lambda (p)
(lambda field-values
(apply p field-values))))))
(define (record-predicate rtd) (lambda (o) (is-a? o (slot-ref rtd 'class))))
;; TODO better error handling
(define (search-kth-slot class k)
(let ((oslots (class-direct-slots class)))
(do ((i 0 (+ i 1)) (slots oslots (cdr slots)))
((= i k)
(values (- (+ k (slot-ref class 'nfields)) (length oslots))
(slot-definition-name (car slots)))))))
(define (record-accessor rtd k)
(let ((class (slot-ref rtd 'class)))
(let-values (((i name) (search-kth-slot class k)))
(let ((acc (%make-slot-accessor class name i #f #f #f)))
(make-record-accessor-from-slot-accessor acc)
#;(lambda (o)
(unless (is-a? o class)
(assertion-violation 'record-accessor
(format "object is not a record type of ~a"
(record-type-name rtd)) o))
(slot-ref-using-accessor o acc))))))
(define (record-mutator rtd k)
(let ((class (slot-ref rtd 'class)))
(let-values (((i name) (search-kth-slot class k)))
(let ((acc (%make-slot-accessor class name i #f #f #f)))
(make-record-mutator-from-slot-accessor acc)
#;(lambda (o v)
(unless (is-a? o class)
(assertion-violation 'record-mutator
(format "object is not a record type of ~a"
(record-type-name rtd)) o))
(slot-set-using-accessor! o acc v))))))
(define (record? o)
(and-let* (( (%record? o) )
(rtd (record-type-rtd (class-of o))))
(not (record-type-opaque? rtd))))
(define (record-rtd o)
(unless (record? o)
(assertion-violation 'record-rtd
(format "record required but got ~s" o) o))
(record-type-rtd (class-of o)))
(define (record-type-generative? rtd) (not (record-type-uid rtd)))
;; TODO check type
(define (record-type-field-names rtd) (vector-map cadr (rtd-fields rtd)))
(define (record-field-mutable? rtd k)
(let ((fields (rtd-fields rtd)))
(eq? (car (vector-ref fields k)) 'mutable)))
)
| false |
906e053047261995251df972e9c024e3b6347350 | 464f876b034b518d8cf8a0b77ea4851f05148916 | /Chapter1/ex1_17.scm | 159c6cb9b424cb48bfa89f3d0b6321bb429e01ba | []
| no_license | billy1kaplan/sicp | 3302e6772af205fa8d1ac77c2d203cb329f5958b | 71d3f93921e32567ae2becec3c9659cfdf013287 | refs/heads/master | 2021-03-22T01:01:15.409369 | 2019-02-10T04:13:56 | 2019-02-10T04:13:56 | 98,474,397 | 0 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 406 | scm | ex1_17.scm | ;( define ( * a b )
; ( if ( = b 0 )
; 0
; ( + a ( * a ( - b 1 )))))
( define ( double n )
( + n n ))
( define ( halve n )
( / n 2 ))
( define ( even? n )
( = ( remainder n 2 ) 0 ))
( define ( * a b )
( cond (( = b 0 ) 0 )
(( even? b ) ( double ( * a ( halve b ))))
( else ( + a ( * a ( - b 1 ))))))
| false |
12325b51e1bd6a715b375b70125e5c0eaf98d1c4 | ab05b79ab17619f548d9762a46199dc9eed6b3e9 | /sitelib/ypsilon/gtk/target.scm | 06f0e974a5b728ffcec51111cc90fdd6867824cb | [
"BSD-2-Clause",
"LicenseRef-scancode-unknown-license-reference"
]
| 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 | 3,817 | scm | target.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 gtk target)
(export gtk_target_flags_get_type
gtk_target_list_add
gtk_target_list_add_image_targets
gtk_target_list_add_rich_text_targets
gtk_target_list_add_table
gtk_target_list_add_text_targets
gtk_target_list_add_uri_targets
gtk_target_list_find
gtk_target_list_get_type
gtk_target_list_new
gtk_target_list_ref
gtk_target_list_remove
gtk_target_list_unref
gtk_target_table_free
gtk_target_table_new_from_list)
(import (rnrs) (ypsilon ffi))
(define lib-name
(cond (on-linux "libgtk-x11-2.0.so.0")
(on-sunos "libgtk-x11-2.0.so.0")
(on-freebsd "libgtk-x11-2.0.so.0")
(on-openbsd "libgtk-x11-2.0.so.0")
(on-darwin "Gtk.framework/Gtk")
(on-windows "libgtk-win32-2.0-0.dll")
(else
(assertion-violation #f "can not locate GTK 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)))))
(define-syntax define-function/va_list
(syntax-rules ()
((_ ret name args)
(define name (lambda x (assertion-violation 'name "va_list argument not supported"))))))
;; GType gtk_target_flags_get_type (void)
(define-function unsigned-long gtk_target_flags_get_type ())
;; void gtk_target_list_add (GtkTargetList* list, GdkAtom target, guint flags, guint info)
(define-function void gtk_target_list_add (void* void* unsigned-int unsigned-int))
;; void gtk_target_list_add_image_targets (GtkTargetList* list, guint info, gboolean writable)
(define-function void gtk_target_list_add_image_targets (void* unsigned-int int))
;; void gtk_target_list_add_rich_text_targets (GtkTargetList* list, guint info, gboolean deserializable, GtkTextBuffer* buffer)
(define-function void gtk_target_list_add_rich_text_targets (void* unsigned-int int void*))
;; void gtk_target_list_add_table (GtkTargetList* list, const GtkTargetEntry* targets, guint ntargets)
(define-function void gtk_target_list_add_table (void* void* unsigned-int))
;; void gtk_target_list_add_text_targets (GtkTargetList* list, guint info)
(define-function void gtk_target_list_add_text_targets (void* unsigned-int))
;; void gtk_target_list_add_uri_targets (GtkTargetList* list, guint info)
(define-function void gtk_target_list_add_uri_targets (void* unsigned-int))
;; gboolean gtk_target_list_find (GtkTargetList* list, GdkAtom target, guint* info)
(define-function int gtk_target_list_find (void* void* void*))
;; GType gtk_target_list_get_type (void)
(define-function unsigned-long gtk_target_list_get_type ())
;; GtkTargetList* gtk_target_list_new (const GtkTargetEntry* targets, guint ntargets)
(define-function void* gtk_target_list_new (void* unsigned-int))
;; GtkTargetList* gtk_target_list_ref (GtkTargetList* list)
(define-function void* gtk_target_list_ref (void*))
;; void gtk_target_list_remove (GtkTargetList* list, GdkAtom target)
(define-function void gtk_target_list_remove (void* void*))
;; void gtk_target_list_unref (GtkTargetList* list)
(define-function void gtk_target_list_unref (void*))
;; void gtk_target_table_free (GtkTargetEntry* targets, gint n_targets)
(define-function void gtk_target_table_free (void* int))
;; GtkTargetEntry* gtk_target_table_new_from_list (GtkTargetList* list, gint* n_targets)
(define-function void* gtk_target_table_new_from_list (void* void*))
) ;[end]
| true |
df1e216dad119bd953ed30725f10c642c5e5c4fe | 3323fb4391e76b853464a9b2fa478cd7429e9592 | /counter.ss | 416b2016643406417c47643dcf55a48e7fb94a87 | []
| no_license | simpleliangsl/hello-scheme | ceb203933fb056523f5288ce716569096a71ad97 | 31434fb810475ee0e8ec2e6816995a0041c47f44 | refs/heads/master | 2023-06-16T12:07:28.744188 | 2021-07-15T06:39:32 | 2021-07-15T06:39:32 | 386,197,304 | 0 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 394 | ss | counter.ss | (define (make-counter n)
(define (increment)
(set! n (+ n 1))
)
(define (tally) n)
(define (dispatch message)
(cond ((equal? message 'increment) increment)
((equal? message 'tally) tally)
)
)
dispatch
)
(define (counter-increment counter)
((counter 'increment))
)
(define (counter-tally counter)
((counter 'tally))
) | false |
eeff7ad030cf97755d9216128fda0c24b12159b4 | 011403dac0afe1b4b143c6c5c39d12f1cbe10c97 | /constants.scm | 62ded7e3fd979bc982d808bf3619e9e1418aef1b | [
"X11",
"MIT"
]
| permissive | rene-schoene/racr-mquat | 7494b9a0c3c2715a6806c34e21cb9ea4931c9896 | 5f985816cadd556d7636a74bea0a5d5b1d95f9ee | refs/heads/master | 2021-01-19T03:14:17.996513 | 2016-07-21T17:31:06 | 2016-07-21T17:31:06 | 53,142,033 | 0 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 1,816 | scm | constants.scm | #!r6rs
; This program and the accompanying materials are made available under the
; terms of the MIT license (X11 license) which accompanies this distribution.
; Author: R. Schöne
(library
(mquat constants)
(export pn-energy agg-max agg-sum offline online booting halting error-state
comp-min-eq comp-max-eq comp-eq f-comp-max-diff-eq
comp->f comp->string comp->rev-string comp->name)
(import (rnrs base) (rnrs lists))
(define pn-energy "energy-consumption") ; Name of the property energy-consumption and as default objective function property name
(define agg-max 1) (define agg-sum 2) ; Used in agg of property to describe how to aggregate the property
; Status of resources
(define offline 'offline) (define online 'online) (define booting 'booting) (define halting 'halting) (define error-state 'error)
(define comp-min-eq 'min-eq)
(define comp-max-eq 'max-eq)
(define comp-eq 'eq)
(define f-comp-max-diff-eq (lambda (diff) (lambda (req act) (<= (- req act) diff))))
; 1st = lookup-symbol
; 2nd = op: property op forumla
; 3rd = rev-op: formula rev-op property
; 4th = name as string
(define comparators (list (list comp-eq (lambda (req act) (= req act)) '= '=)
(list comp-min-eq (lambda (req act) (<= req act)) '<= '>=)
(list comp-max-eq (lambda (req act) (>= req act)) '>= '<=)))
(define comp->X (lambda (comp picker default) (let ([entry (assq comp comparators)]) (if entry (picker entry) default))))
(define comp->f (lambda (comp) (comp->X comp cadr (lambda _ (error 'comparators "No function found" comp)))))
(define comp->string (lambda (comp) (comp->X comp caddr '?~)))
(define comp->rev-string (lambda (comp) (comp->X comp cadddr '~?)))
(define comp->name (lambda (comp) (symbol->string comp))))
| false |
ea832e33e7d2f6da864e1917fa387f1f985ba594 | 710bd922d612840b3dc64bd7c64d4eefe62d50f0 | /scheme/scheme-compiler/assembler.scm | 9f24e17a0aea83ad48f1c42fb0cf5d5908a007d7 | [
"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 | 11,201 | scm | assembler.scm | ;;; assembler.scm -- bytecode assembler
;;; Assembler
;;; DEBUG Format consists of:
;;
;; NAME -> debug-name of the code (string)
;; ENVs -> environements consists of an list of (offset . names)
;; PARAMS -> parameter lists, e.g (num num)
;; DOC -> documentation string or #f
;; FILE -> filename where code is defined
(define (make-empty-debug)
(vector #f '() #f #f #f))
(define (debug-env debug) (vector-ref debug 1))
(define (debug-bind! debug offset name)
(vector-set! debug
1
(cons (cons offset name) (debug-env debug))))
(define (debug-name-set! debug name)
(vector-set! debug 0 name))
(define (debug-parameters-set! debug params)
(vector-set! debug 2 params))
(define (debug-doc-set! debug doc)
(vector-set! debug 3 doc))
(define (debug-file-set! debug file-name)
(vector-set! debug 4 file-name))
(define (assembler asm-code module)
;; main entry point of assembler
(compute-labels asm-code 0
(lambda (labels size)
(let ((bvec (make-bvec size)))
(assemble asm-code labels bvec module
(lambda (code literals debug)
(vector code literals debug)))))))
(define (compute-labels asm-code pos k)
(if (null? asm-code)
(k '() 0)
(let ((instr (car asm-code)))
(compute-labels (cdr asm-code) (if (symbol? instr)
pos
(+ pos (instr-length instr)))
(lambda (labels size)
(if (symbol? instr)
(k (cons (cons instr pos) labels)
size)
(k labels (+ size (instr-length instr)))))))))
(define (assemble asm-code labels bvec module k)
(let loop ((i 0)
(literals '())
(asm asm-code)
(debug (make-empty-debug)))
(if (null? asm)
(k bvec (list->vector literals) debug)
(let ((instr (car asm)))
(if (symbol? instr)
(loop i literals (cdr asm) debug)
(assemble-one instr bvec i literals labels module
debug
(lambda (new-literals new-i)
(loop new-i new-literals
(cdr asm) debug))))))))
(define (append-lit lit lits)
(if (memq lit lits)
lits
(append lits (list lit))))
(define (instr-length instr)
; (display instr)
(cond ((and (pair? instr)
(or (eq? 'iffalse (car instr))
(eq? 'jump (car instr))))
3)
((and (pair? instr)
(eq? 'debug (car instr))) 0)
(else (length instr))))
(define *assemblers* (make-hashtable))
(define (define-assembler opcode coder)
(hash-set! *assemblers* opcode coder))
(define-assembler 'lit
(lambda (instr bvec i literals labels module debug k)
(bvec-set! bvec i 0)
(let ((lits (append literals (list (cadr instr)))))
(bvec-set! bvec (+ i 1) (pos (cadr instr) lits))
(k lits (+ i 2)))))
(define-assembler 'args
(lambda (instr bvec i literals labels module debug k)
(bvec-set! bvec i 1)
(bvec-set! bvec (+ i 1) (cadr instr))
(k literals (+ i 2))))
(define-assembler 'global
(lambda (instr bvec i literals labels module debug k)
(bvec-set! bvec i 2)
(if (cdadr instr)
(let* ((module (lookup-module (cdadr instr)))
(ref (lookup/create-ref (caadr instr) module))
(lits (append-lit ref literals)))
(bvec-set! bvec (+ i 1) (pos ref lits))
(k lits (+ i 2)))
(let* ((ref (lookup/create-ref (caadr instr) module))
(lits (append-lit ref literals)))
(bvec-set! bvec (+ i 1) (pos ref lits))
(k lits (+ i 2))))))
(define-assembler 'set-global
(lambda (instr bvec i literals labels module debug k)
(bvec-set! bvec i 3)
(if (cdadr instr)
(let* ((module (lookup-module (cdadr instr)))
(arg (cadr instr))
(ref (lookup/create-ref (car arg) module))
(lits (append-lit ref literals)))
(bvec-set! bvec (+ i 1) (pos ref lits))
(k lits (+ i 2)))
(let* ((arg (cadr instr))
(ref (lookup/create-ref (car arg) module))
(lits (append-lit ref literals)))
(bvec-set! bvec (+ i 1) (pos ref lits))
(k lits (+ i 2))))))
(define-assembler 'local
(lambda (instr bvec i literals labels module debug k)
(bvec-set! bvec i 4)
(bvec-set! bvec (+ i 1) (cadr instr))
(bvec-set! bvec (+ i 2) (caddr instr))
(k literals (+ i 3))))
(define-assembler 'set-local
(lambda (instr bvec i literals labels module debug k)
(bvec-set! bvec i 5)
(bvec-set! bvec (+ i 1) (cadr instr))
(bvec-set! bvec (+ i 2) (caddr instr))
(k literals (+ i 3))))
(define-assembler 'call
(lambda (instr bvec i literals labels module debug k)
(bvec-set! bvec i 6)
(bvec-set! bvec (+ i 1) (cadr instr))
(k literals (+ i 2))))
(define-assembler 'tail
(lambda (instr bvec i literals labels module debug k)
(bvec-set! bvec i 7)
(bvec-set! bvec (+ i 1) (cadr instr))
(k literals (+ i 2))))
(define-assembler 'iffalse
(lambda (instr bvec i literals labels module debug k)
(let ((pc (cdr (assq (cadr instr) labels))))
(bvec-set! bvec i 8)
(bvec-set! bvec (+ i 1) (quotient pc 256))
(bvec-set! bvec (+ i 2) (modulo pc 256))
(k literals (+ i 3)))))
(define-assembler 'jump
(lambda (instr bvec i literals labels module debug k)
(let ((pc (cdr (assq (cadr instr) labels))))
(bvec-set! bvec i 9)
(bvec-set! bvec (+ i 1) (quotient pc 256))
(bvec-set! bvec (+ i 2) (modulo pc 256))
(k literals (+ i 3)))))
(define-assembler 'return
(lambda (instr bvec i literals labels module debug k)
(bvec-set! bvec i 10)
(k literals (+ i 1))))
(define-assembler 'push
(lambda (instr bvec i literals labels module debug k)
(bvec-set! bvec i 11)
(k literals (+ i 1))))
(define-assembler 'closure
(lambda (instr bvec i literals labels module debug k)
(bvec-set! bvec i 12)
(let* ((template (assembler (cadr instr) module))
(lits (append literals (list template))))
(bvec-set! bvec (+ i 1) (pos template lits))
(k lits (+ i 2)))))
(define-assembler 'leave
(lambda (instr bvec i literals labels module debug k)
(bvec-set! bvec i 13)
(k literals (+ i 1))))
(define-assembler 'args>=
(lambda (instr bvec i literals labels module debug k)
(bvec-set! bvec i 14)
(bvec-set! bvec (+ i 1) (cadr instr))
(k literals (+ i 2))))
(define-assembler 'undef
(lambda (instr bvec i literals labels module debug k)
(bvec-set! bvec i 15)
(bvec-set! bvec (+ i 1) (cadr instr))
(k literals (+ i 2))))
(define-assembler 'env
(lambda (instr bvec i literals labels module debug k)
(bvec-set! bvec i 16)
(bvec-set! bvec (+ i 1) (cadr instr))
(k literals (+ i 2))))
(define-assembler 'debug
(lambda (instr bvec i literals labels module debug k)
(let* ((op (cadr instr))
(op-name (car op)))
(cond ((eq? op-name 'name)
(debug-name-set! debug (cadr op))
(k literals i))
((eq? op-name 'env)
(let ((env (cadr op)))
(debug-bind! debug i env)
(k literals i)))
((eq? op-name 'parameters)
(debug-parameters-set! debug (cadr op))
(k literals i))
((eq? op-name 'doc)
(debug-doc-set! debug (cadr op))
(k literals i))
((eq? op-name 'file)
(debug-file-set! debug (cadr op))
(k literals i))
(else (error "Unknown debug instruction ~a" op-name))))))
(define *primitives*
(let ((hash (make-hashtable)))
(let loop
((opcode
'(+ - quotient remainder modulo * < <= = > >= symbol? eq? %fixnum? pair?
make-pair
car cdr set-car! set-cdr! null? vector? make-vector
vector-length vector-ref vector-set! make-string string-length
string-ref string-set! make-channel write-channel
read-channel eof-object?
channel-number channel? open-input-channel open-output-channel char->number
number->char symbol->string string->symbol apply make-stob stob-ref
stob-set! stob-class stob?
stob-length suspend-cc resume-cc make-bvec bvec?
bvec-ref bvec-set! bvec-length save-image string->keyword keyword->string make-procedure
procedure? procedure-set! procedure-ref procedure-length
char? close-channel
peek-channel string? make-ref ref? ref-name ref-value ref-module
set-ref-name! set-ref-value! set-ref-module! set-stob-class!
%xdraw-arc %xdraw-text %xopen-font
%xclose-font %xread-event
bit-or bit-and bit-xor bit-ash bit-not object-hash
keyword? / a a a a a a
posix-open posix-close posix-read posix-write posix-chdir posix-access
posix-mkdir posix-stat posix-time posix-localtime posix-gmtime
posix-seek posix-sync posix-rmdir posix-unlink posix-rename
posix-chmod
posix-chgrp posix-chown posix-getenv posix-setenv posix-fork posix-exec
posix-dirfiles posix-recv posix-send posix-socket posix-bind posix-listen
posix-accept posix-connect posix-select
posix-mknod posix-tempnam
posix-getpwnam posix-getgrnam posix-utime posix-umask posix-getpid
posix-getppid posix-getsid posix-setsid posix-getuid posix-geteuid
posix-getgid posix-getegid posix-setuid posix-setegid
posix-seteuid posix-setgid
posix-exit posix-waitpid posix-getcwd posix-pipe posix-dup2
%ffi-open %ffi-error %ffi-sym %ffi-close %ffi-apply
%ffi-mem-ref %ffi-string-ref %ffi-mem-set! %ffi-mirror
%ffi-deref %ffi-malloc %ffi-free
%ffi-u8-ref %ffi-u16-ref %ffi-u32-ref %ffi-u64-ref %ffi-double-ref
posix-kill posix-openpty a a a a a a
a a a a %posix-uname
posix-setsockopt posix-getsockopt
posix-unix-address posix-inet-address
%posix-block-signal!
%assq %record-ref %record-set!
%test+set! %real->string %string->real
%fixnum->real %real? %round %truncate %ceiling %floor
%rationalize %exp %log %sin %cos %tan %asin %acos %atan %atan2
%sqrt %expt %native-call %channel-flush
%host-error %error=? %set-timer %posix-symlink %posix-readlink
%random %class-of %set-classes %instance? %subtype? a a))
(p 0))
(if (null? opcode)
hash
(let ((op (car opcode)))
(hash-set! hash op p)
(loop (cdr opcode) (+ p 1)))))))
(define (assemble-one instr bvec i literals labels module debug k)
(let* ((opcode (car instr))
(encoder (hash-ref *assemblers* opcode)))
(if encoder
(encoder instr bvec i literals labels module debug k)
(let ((prim (hash-ref *primitives* opcode)))
(if prim
(begin
(bvec-set! bvec i (+ 32 prim))
; (if (eq? opcode 'make-procedure)
; (bvec-set! bvec (+ i 1) (cadr instr)))
(k literals (+ i (instr-length instr))))
(error "unknown opcode ~a" opcode))))))
| false |
f4e70c6a8c5d36228e89c90e238bfeac80b2ec43 | e358b0cf94ace3520adff8d078a37aef260bb130 | /symderiv/2.58.scm | 25e3c48e32f0d0e21c6f63cb2791d5b0e33e52c6 | []
| no_license | dzhus/sicp | 784766047402db3fad4884f7c2490b4f78ad09f8 | 090fa3228d58737d3558f2af5a8b5937862a1c75 | refs/heads/master | 2021-01-18T17:28:02.847772 | 2020-05-24T19:15:57 | 2020-05-24T20:56:00 | 22,468,805 | 0 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 2,786 | scm | 2.58.scm | (define (variable? x) (symbol? x))
(define (same-variable? v1 v2)
(and (variable? v1) (variable? v2) (eq? v1 v2)))
(define (=number? exp number)
(and (number? exp) (= exp number)))
(define (make-sum a b)
(cond ((=number? a 0) b)
((=number? b 0) a)
((and (number? a) (number? b)) (+ a b))
(else (list a '+ b))))
(define (sum? x)
(and (pair? x) (eq? (cadr x) '+)))
(define (addend s) (car s))
(define (augend s) (caddr s))
(define (make-subtraction a b)
(make-sum a (make-product b -1)))
(define (make-product a b)
(cond ((=number? a 1) b)
((=number? b 1) a)
((or (=number? a 0) (=number? b 0)) 0)
((and (number? a) (number? b)) (* a b))
(else (list a '* b))))
(define (product? x)
(and (pair? x) (eq? (cadr x) '*)))
(define (multiplier p) (car p))
(define (multiplicand p) (caddr p))
(define (make-division a b)
(cond ((=number? b 1) a)
((=number? b 0) (error "Division by zero"))
((and (number? a) (number? b))
(/ a b))
(else (list a '/ b))))
(define (division? x)
(and (pair? x) (eq? (cadr x) '/)))
(define (divident x) (car x))
(define (divisor x) (caddr x))
(define (make-exponentiation base exponent)
(cond ((or (=number? exponent 0) (=number? base 1)) 1)
((=number? base 0) 0)
((=number? exponent 1) base)
((and (number? base) (number? exponent))
(expt base exponent))
(else (list base '^ exponent))))
(define (exponentiation? x)
(and (pair? x) (eq? (cadr x) '^)))
(define (base e) (car e))
(define (exponent e) (caddr e))
(define (deriv exp var)
(cond ((number? exp) 0)
((variable? exp)
(if (same-variable? exp var) 1 0))
;;@ $(u+v)' = u' + v'$
((sum? exp)
(make-sum (deriv (addend exp) var)
(deriv (augend exp) var)))
;;@ $(uv)' = u'v + uv'$
((product? exp)
(make-sum
(make-product (multiplier exp)
(deriv (multiplicand exp) var))
(make-product (deriv (multiplier exp) var)
(multiplicand exp))))
;;@ $\left ( \frac{u}{v} \right )' = \frac{u'v - vu'}{v^2}$
((division? exp)
(make-division
(make-subtraction
(make-product (deriv (divident exp) var) (divisor exp))
(make-product (deriv (divisor exp) var) (divident exp)))
(make-exponentiation (divisor exp) 2)))
;;@ $(u^n)' = nu^{n-1}u'$
((exponentiation? exp)
(make-product
(make-product (exponent exp)
(make-exponentiation
(base exp) (- (exponent exp) 1)))
(deriv (base exp) var)))
(else
(error "Unknown expression type")))) | false |
8df7e1d989f145d0758bf00f6af3efe7ad22fc5d | 165a4ff581651cdad1bc512ec1c82cebc0ac575a | /src/SICP/3/parallel.ss | c45cd8dd52e5dad353dbb6ec84ace6c0af49d14a | []
| no_license | haruyama/yami | 5028e416a2caa40a0193d46018fe4be81d7820dc | 32997caecc18d9d82a28b88fabe5b414a55e0e18 | refs/heads/master | 2020-12-25T09:47:04.240216 | 2018-06-16T08:28:41 | 2018-06-16T08:28:41 | 898,824 | 1 | 1 | null | null | null | null | UTF-8 | Scheme | false | false | 9,335 | ss | parallel.ss | ;ex3.38
(define true #t)
(define false #f)
;a
(define balance 100)
(define (peter) (set! balance (+ balance 10)))
(define (paul) (set! balance (- balance 20)))
(define (mary) (set! balance (- balance (/ balance 2))))
(define balance 100)
(peter) (paul) (mary)
(newline)
;45
(define balance 100)
(peter) (mary) (paul)
(newline)
;35
(define balance 100)
(paul) (peter) (mary)
(newline)
;45
(define balance 100)
(paul) (mary) (peter)
(newline)
;50
(define balance 100)
(mary) (peter) (paul)
(newline)
;40
(define balance 100)
(mary) (paul) (peter)
(newline)
;40
;35 40 45 50
;b
;30 55 60 70 80 90 110
(use gauche.threads)
(define (parallel-execute . procs)
(let ((threads (map make-thread procs)))
(map thread-start! threads)
(map thread-join! threads)))
;(define (parallel-execute . args)
; "each arg is a thunk, to be run in a separate thread"
; (let ((threads ()))
; (dolist (thunk args)
; (push! threads (thread-start! (make-thread thunk))))
; (map thread-join! threads)))
(define (make-serializer/no-dw)
(let ((mutex (make-mutex)))
(lambda (p)
(define (serialized-p . args)
(mutex-lock! mutex)
(let ((val (apply p args)))
(mutex-unlock! mutex)
val))
serialized-p)))
;; same using dynamic-wind
;; note: this function returns a function A which takes a function B
;; and returns a new function C that is a sync'd variant of function B.
(define (make-serializer)
(let ((mutex (make-mutex)))
(lambda (proc)
(lambda args
(dynamic-wind
(lambda () (mutex-lock! mutex))
(lambda () (apply proc args))
(lambda () (mutex-unlock! mutex)))))))
(define x 10)
(parallel-execute (lambda () (set! x (* x x)))
(lambda () (set! x (+ x 1)))
)
;(parallel-execute (lambda () (set! x (+ x 1)))
; (lambda () (set! x (* x x)))
; )
(display x)
(define x 10)
(define s (make-serializer))
(parallel-execute (s (lambda () (set! x (* x x))))
(s (lambda () (set! x (+ x 1))))
)
;(parallel-execute (s (lambda () (set! x (+ x 1))))
; (s (lambda () (set! x (* x x))))
; )
(display x)
(use srfi-1)
(list-tabulate 100
(lambda (i)
(let ((x 10)
(s (make-serializer)))
(parallel-execute (s (lambda () (set! x (* x x))))
(s (lambda () (set! x (+ x 1)))))
x)))
(list-tabulate 100
(lambda (i)
(let ((x 10))
(parallel-execute (lambda () (set! x (* x x)))
(lambda () (set! x (+ x 1))))
x)))
(define (make-account balance)
(define (withdraw amount)
(if (>= balance amount)
(begin (set! balance (- balance amount))
balance)
"Insufficient funds"))
(define (deposit amount)
(set! balance (+ balance amount))
balance)
(let ((protected (make-serializer)))
(define (dispatch m)
(cond ((eq? m 'withdraw) (protected withdraw))
((eq? m 'deposit) (protected deposit))
((eq? m 'balance) balance)
(else (error "Unknown request -- MAKE-ACCOUNT" m))))
dispatch))
;ex3.39
(define x 10)
(define s (make-serializer))
(parallel-execute (lambda () (set! x ((s (lambda () (* x x))))))
(s (lambda () (set! x (+ x 1)))))
(display x)
; 11 100 101 121
;ex3.40
;(* 100 100 100) = 1000000
;(* 1000 1000) = 1000000
;(* 10 10 10) = 1000
;(* 10 10 100) = 10000
;(* 10 100 100) = 100000
;(* 10 10) = 100
;(* 10 1000) = 10000
;ex3.41
; 意味はない
;ex3.42
; 安全で違いはない (この問題の版のほうが効率がよい)
(define (exchange account1 account2)
(let ((difference (- (account1 'balance)
(account2 'balance))))
((account1 'withdraw) difference)
((account2 'deposit) difference)))
(define (make-account-and-serializer balance)
(define (withdraw amount)
(if (>= balance amount)
(begin (set! balance (- balance amount))
balance)
"Insufficient funds"))
(define (deposit amount)
(set! balance (+ balance amount))
balance)
(let ((balance-serializer (make-serializer)))
(define (dispatch m)
(cond ((eq? m 'withdraw) (protected withdraw))
((eq? m 'deposit) (protected deposit))
((eq? m 'balance) balance)
((eq? m 'serializer) balance-serializer)
(else (error "Unknown request -- MAKE-ACCOUNT" m))))
dispatch))
(define (deposit account amountt)
(let ((s (account 'serializer))
(d (account 'deposit)))
((s d) amountt)))
(define (serialized-exchange account1 account2)
(let ((serializer1 (account1 'serializer))
(serializer2 (account2 'serializer)))
((serializer1 (serializer2 exchange))
account1 account2)))
(define (make-serializer)
(let ((mutex (make-mutex)))
(lambda (p)
(define (serialized-p . args)
(mutex 'acquire)
(let ((val (apply p args)))
(mutex 'release)
val))
serialized-p)))
(define (make-mutex)
(let ((cell (list false)))
(define (the-mutex m)
(cond ((eq? m 'acquire)
(if (test-and-set! cell)
(the-mutex 'acquire)))
((eq? m 'release) (clear! cell))))
the-mutex))
(define (test-and-set! cell)
(if (car cell)
true
(begin (set-car! cell true)
false)))
(define (clear! cell)
(set-car! cell false))
;ex3.47
(define (make-semaphore n)
(let ((mutex (make-mutex))
(semaphore 0))
(define (dispatch m)
(cond ((eq? m 'acquire)
(mutex 'acquire)
(if (< semaphore n)
(begin
(set! semaphore (+ 1 semaphore))
(mutex 'release)
true)
(begin
(mutex 'release)
(dispatch 'acquire))
))
((eq? m 'release)
(mutex 'acquire)
(if (= semaphore 0)
(begin
(mutex 'release)
false)
(begin
(set! semaphore (- semaphore 1))
(mutex 'release)
true)
))))
dispatch))
(define semaphore (make-semaphore 2))
(semaphore 'acquire)
(semaphore 'acquire)
;(semaphore 'acquire)
(semaphore 'release)
(semaphore 'release)
(semaphore 'release)
(define (make-semaphore2 n)
(let ((semaphore 0)
(cell (list false)))
(define (dispatch m)
(cond ((eq? m 'acquire)
(if (test-and-set! cell)
(dispatch 'acquire)
(if (< semaphore n)
(begin
(set! semaphore (+ 1 semaphore))
(clear! cell)
true)
(begin
(clear! cell)
(dispatch 'acquire))
)))
((eq? m 'release)
(if (test-and-set! cell)
(dispatch 'release)
(if (= semaphore 0)
(begin
(clear! cell)
false)
(begin
(set! semaphore (- semaphore 1))
(clear! cell)
true)
)))))
dispatch))
(define semaphore2 (make-semaphore2 2))
(semaphore2 'acquire)
(semaphore2 'acquire)
;(semaphore2 'acquire)
(semaphore2 'release)
(semaphore2 'release)
(semaphore2 'release)
;ex3.48
(define (make-sequence)
(let ((sequence 0)
(mutex (make-mutex)))
(define (gen)
(mutex 'acquire)
(set! sequence (+ sequence 1))
(mutex 'release)
sequence)
gen))
(define sequence (make-sequence))
(define (make-account-with-number balance)
(define (withdraw amount)
(if (>= balance amount)
(begin (set! balance (- balance amount))
balance)
"Insufficient funds"))
(define (deposit amount)
(set! balance (+ balance amount))
balance)
(let ((balance-serializer (make-serializer))
(number (sequence)))
(define (dispatch m)
(cond ((eq? m 'withdraw) (protected withdraw))
((eq? m 'deposit) (protected deposit))
((eq? m 'balance) balance)
((eq? m 'number) sequence)
((eq? m 'serializer) balance-serializer)
(else (error "Unknown request -- MAKE-ACCOUNT" m))))
dispatch))
(define (deposit account amountt)
(let ((s (account 'serializer))
(d (account 'deposit)))
((s d) amountt)))
(define (serialized-exchange-with-number account1 account2)
(let ((number1 (account1 'number1))
(number2 (account2 'number2))
(serializer1 (account1 'serializer))
(serializer2 (account2 'serializer))
)
(cond ((= number1 number2) (error "ERROR"))
((< number1 number2)
(serializer2 (serializer1 exchange))
account1 account2)
(else
(serializer1 (serializer2 exchange))
account1 account2))))
| false |
47427c00a30ac31024cc5108ab72bc9403fa7844 | ba4ad8a778c69640c9cca8e5dcaeb40d4a10fa10 | /racket/population.scm | a764db4c2b8ee13f21167af5cfbd67bfc6ffef6a | []
| no_license | tangentstorm/tangentlabs | 390ac60618bd913b567d20933dab70b84aac7151 | 137adbba6e7c35f8bb54b0786ada6c8c2ff6bc72 | refs/heads/master | 2023-08-31T20:36:53.127938 | 2023-08-18T01:30:10 | 2023-08-18T01:30:10 | 7,815,356 | 33 | 22 | null | 2015-06-06T12:15:35 | 2013-01-25T07:03:01 | Visual Basic | UTF-8 | Scheme | false | false | 422 | scm | population.scm | ;
; population simulation
;
(define (random-gender)
(if (= 0 (random 2)) 'm 'f))
; just using list for now so i can display more easily
(define-struct creature (age health gender dna))
(define (new-creature)
(list 0 100 (random-gender) ()))
(define (build-population n)
(cond ((= n 0) ())
(else (cons (new-creature)
(build-population (- n 1))))))
;-- run it ---
(display (build-population 5))
(newline)
| false |
f83cb98d0d0f271cb07ce1c7e64b2e256afd002f | defeada37d39bca09ef76f66f38683754c0a6aa0 | /mscorlib/system/security/permissions/key-container-permission-access-entry-collection.sls | 5820366f6082ac74568751908897c2474526b6ae | []
| no_license | futsuki/ironscheme-port | 2dbac82c0bda4f4ff509208f7f00a5211d1f7cd5 | 4e7a81b0fbeac9a47440464988e53fb118286c54 | refs/heads/master | 2016-09-06T17:13:11.462593 | 2015-09-26T18:20:40 | 2015-09-26T18:20:40 | 42,757,369 | 0 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 2,633 | sls | key-container-permission-access-entry-collection.sls | (library (system
security
permissions
key-container-permission-access-entry-collection)
(export is?
key-container-permission-access-entry-collection?
copy-to
index-of
get-enumerator
add
remove
clear
count
is-synchronized?
item
sync-root)
(import (ironscheme-clr-port))
(define (is? a)
(clr-is
System.Security.Permissions.KeyContainerPermissionAccessEntryCollection
a))
(define (key-container-permission-access-entry-collection? a)
(clr-is
System.Security.Permissions.KeyContainerPermissionAccessEntryCollection
a))
(define-method-port
copy-to
System.Security.Permissions.KeyContainerPermissionAccessEntryCollection
CopyTo
(System.Void
System.Security.Permissions.KeyContainerPermissionAccessEntry[]
System.Int32))
(define-method-port
index-of
System.Security.Permissions.KeyContainerPermissionAccessEntryCollection
IndexOf
(System.Int32
System.Security.Permissions.KeyContainerPermissionAccessEntry))
(define-method-port
get-enumerator
System.Security.Permissions.KeyContainerPermissionAccessEntryCollection
GetEnumerator
(System.Security.Permissions.KeyContainerPermissionAccessEntryEnumerator))
(define-method-port
add
System.Security.Permissions.KeyContainerPermissionAccessEntryCollection
Add
(System.Int32
System.Security.Permissions.KeyContainerPermissionAccessEntry))
(define-method-port
remove
System.Security.Permissions.KeyContainerPermissionAccessEntryCollection
Remove
(System.Void
System.Security.Permissions.KeyContainerPermissionAccessEntry))
(define-method-port
clear
System.Security.Permissions.KeyContainerPermissionAccessEntryCollection
Clear
(System.Void))
(define-field-port
count
#f
#f
(property:)
System.Security.Permissions.KeyContainerPermissionAccessEntryCollection
Count
System.Int32)
(define-field-port
is-synchronized?
#f
#f
(property:)
System.Security.Permissions.KeyContainerPermissionAccessEntryCollection
IsSynchronized
System.Boolean)
(define-field-port
item
#f
#f
(property:)
System.Security.Permissions.KeyContainerPermissionAccessEntryCollection
Item
System.Security.Permissions.KeyContainerPermissionAccessEntry)
(define-field-port
sync-root
#f
#f
(property:)
System.Security.Permissions.KeyContainerPermissionAccessEntryCollection
SyncRoot
System.Object))
| false |
57145ac3ebc327cea585782f1e49dd2aabdec60e | 18e69f3b8697cebeccdcd7585fcfc50a57671e21 | /scheme/map.scm | e05c14580b53f89b125463c95ea4d07c2764ee45 | []
| no_license | ashikawa/scripts | 694528ccfd0b84edaa980d6cde156cfe394fe98a | c54463b736c6c01781a0bfe00472acd32f668550 | refs/heads/master | 2021-01-25T04:01:34.073018 | 2013-12-02T03:33:29 | 2013-12-02T03:33:29 | null | 0 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 538 | scm | map.scm | (load "./inc/std.scm")
;ちなみにmapもある。
(define (map proc items)
(if (null? items)
'()
(cons (proc (car items))
(map proc (cdr items)))))
(define in (list -10 6 -3 1 7))
(display (map abs in))
(newline)
(display (map (lambda (x) (* x x)) in))
(newline)
;あるじゃん(怒
(for-each (lambda (x) (newline) (display x)) in)
(newline)
(define (foreach proc items)
(if (null? items)
'()
(begin (proc (car items)) (foreach proc (cdr items)))))
(foreach (lambda (x) (newline) (display x)) in)
(newline)
| false |
b443000cde9a0abe8a1f34bf7466b8fc441fafad | 4a2ca15958520085fe693dca8a2000a8f2156a43 | /galton.scm | 67f2b3851e16718ccb256de1c9876bafa76a702a | []
| no_license | bshimanuki/6.945 | 97b2a0ee4200979eaec149dcbc7f87368ebeeb4d | 7988f8e33f601888657f7cea3fa2d7b8901e5c29 | refs/heads/master | 2020-12-31T04:55:32.174748 | 2016-05-11T15:28:25 | 2016-05-11T15:28:25 | 56,881,169 | 0 | 1 | null | null | null | null | UTF-8 | Scheme | false | false | 1,684 | scm | galton.scm | ;;;; A demonstration of a Galton box using the graph library
;;; Infinite Galton box graph
(define-memoized (galton x y)
(make-vertex
(edges (galton x y)
((galton (-1+ x) (1+ y)))
((galton (1+ x) (1+ y))))
(list x y)))
;;; Perform random walk on Galton box
(define (galton-box) (galton 0 0))
(traverse-random (galton-box) 10)
;Value 26: #[vertex 26 (2 10)]
;;; Draw an integer between -n and n from an approximate
;;; gaussian distribution using the Galton box, for large
;;; n.
(define (Gaussian-distribution n)
(/ (car (vertex-name (traverse-random (galton-box) (* 2 n)))) 2))
;;; Perform many runs of the Galton box
(define (run-galton-box runs n)
(let loop ((results (make-eq-hash-table))
(runs-left runs))
(if (= runs-left 0)
results
(let ((result (Gaussian-distribution n)))
(hash-table/put! results
result
(+ 1 (hash-table/get results result 0)))
(loop results (- runs-left 1))))))
#|
;;; Run 10000 trials on a box 100 deep
(let ((results (run-galton-box 10000 100)))
(let loop ((i -25))
(if (<= i 25)
(begin
(display i) (display ": ") (display (hash-table/get results i 0))
(newline)
(loop (+ i 1))))))
|#
#|
-25: 0
-24: 0
-23: 5
-22: 1
-21: 12
-20: 8
-19: 7
-18: 20
-17: 30
-16: 41
-15: 47
-14: 72
-13: 97
-12: 129
-11: 167
-10: 207
-9: 234
-8: 326
-7: 372
-6: 394
-5: 448
-4: 483
-3: 510
-2: 529
-1: 513
0: 526
1: 552
2: 560
3: 524
4: 519
5: 416
6: 441
7: 367
8: 297
9: 235
10: 212
11: 165
12: 162
13: 107
14: 65
15: 61
16: 42
17: 38
18: 18
19: 15
20: 12
21: 10
22: 3
23: 0
24: 1
25: 0
|#
| false |
d6779818236f33bc2b0e107835e72a27daa95d86 | 66ea6176c39f1378136626261718a5bbb4cfd8b4 | /midi/user2.ss | 0587b5d7da3edbf0be1be894cca76a31c52236e9 | []
| no_license | jmphilli/phillips-thesis | 47d70bd0d4b0933efdb26b7b5d5eefa91b3f16db | f1498c7383936f6a5a65fa190f73c03a47daa9d5 | refs/heads/master | 2020-04-19T22:43:05.887938 | 2010-12-03T22:28:23 | 2010-12-03T22:28:23 | 519,460 | 0 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 9,401 | ss | user2.ss | #lang scheme
(require "midi-layer.ss")
;pitch is just modeled as a number, not a pitch class and an octave
(define-struct nnote (pitch ;; (number or #f for rest)
duration
velocity
channel
time)) ;; in ms
;; an event is (cons/c abstime command), where abstime is the wall-clock
;; milliseconds at which the event should occur, and command is a midi-command
#;(define-struct: nnote ([pitch : Integer]
[duration : Number]
[velocity : Integer]
[channel : Integer]))
#;(define-struct: rest ([duration : Number]))
#|
;jmp
(define (play-music music)
(play-notes (music->notes music)))
;; play a bunch of notes, using a new midi handle.
(define (play-notes notes)
(with-midi-handle midi-handle
(define evts (notes->events notes #;(flatten notes)
(+ 10 (current-milliseconds))))
(define time (current-milliseconds))
(for ([evt (in-list evts)])
;; (printf "comparing ~s > ~s => ~s\n" time (car evt) (time . > . (car evt)))
(when (time . < . (car evt))
;; (printf "sleeping ~s\n" (* 1/1000 (- (car evt) time)))
(sleep (* 1/1000 (- (car evt) time)))
(set! time (current-milliseconds)))
(send-midi-command midi-handle (cdr evt)))
;; let the notes stop ringing:
(sleep 0.5)))
|#
;; this stuff turns it into midi -- give it a new module?
(define ((note->midi-on/off maker) note)
(and (nnote-pitch note)
(maker
(nnote-channel note)
(nnote-pitch note)
(nnote-velocity note))))
;; note->on-event : number? -> note? -> (list/c number? number? number?)
(define ((note->on-event time0) note)
(cons (+ time0 (nnote-time note))
((note->midi-on/off make-midi-note-on) note)))
;; note->on-event : number? -> note? -> (list/c number? number? number?)
(define ((note->off-event time0) note)
(cons (+ time0 (nnote-time note) (nnote-duration note))
((note->midi-on/off make-midi-note-off) note)))
;; each note becomes two events, a note-on and a note-off
;; (listof note?) number? -> (list event?)
(define (notes->events notes time0)
(sort (filter cdr (append (map (note->on-event time0) notes)
(map (note->off-event time0) notes)))
(lambda (n1 n2)
(let ([d (- (car n1) (car n2))])
(cond [(positive? d) #f]
[(negative? d) #t]
;; off events precede on events
[else n1])))))
(define ((delay-note t) n)
(match n
[(struct nnote (pitch duration velocity channel time))
(make-nnote pitch duration velocity channel (+ time t))]))
(define (delay-notes t ns)
(map (delay-note t) ns))
;; okay, this comes from haskore:
#|
data Music = Note Pitch Dur [NoteAttribute] -- a note \ atomic
| Rest Dur -- a rest / objects
| Music :+: Music -- sequential composition
| Music :=: Music -- parallel composition
| Tempo (Ratio Int) Music -- scale the tempo
| Trans Int Music -- transposition
| Instr IName Music -- instrument label
| Player PName Music -- player label
| Phrase [PhraseAttribute] Music -- phrase attributes
type Dur = Ratio Int -- in whole notes
|#
;; let's code this up just using sexps for now.
;; a notename is one of 'Cf 'C 'Cs 'Df 'D 'Ds ... 'Bf 'B 'Bs
;; a pitch is `(,notename ,octave)
;; a music is one of
;; `(note ,pitch ,dur)
;; `(rest ,dur)
;; `(:+: ,music ...)
;; `(:=: ,music ...)
;; ...
#|Decided to leave out player/instrument/phrase.|#
(define (note p d) `(note ,p ,d))
(define (rest d) `(rest ,d))
(define (:+: . args) (cons ':+: args))
(define (:=: . args) (cons ':=: args))
(define (tempo n m) `(tempo ,n ,m))
;; jmp
(define (trans half-steps m) `(trans ,half-steps ,m))
(define line :+:)
(define chord :=:)
(define (pitch-class->offset pitch-class)
(match pitch-class
['Cf -1]
['C 00]
['Cs 01]
['Df 01]
['D 02]
['Ds 03]
['Ef 03]
['E 04]
['Es 05]
['Ff 04]
['F 05]
['Fs 06]
['Gf 06]
['G 07]
['Gs 08]
['Af 08]
['A 09]
['As 10]
['Bf 10]
['B 11]
['Bs 12]))
(define (offset->pitch-class offset)
(list-ref '(C Cs D Ds E F Fs G Gs A As B) offset))
(define (key-offset->pitch-class key-offset)
(list-ref '(C D E F G A B) key-offset))
;; map a pitch to its MIDI note number
#;(define (pitch->pitch-num pitch)
(match pitch
[(list pitch-class octave) (+ (pitch-class->offset pitch-class) (* 12 octave) 12)]))
;; justin bug fix MIDI
(define (pitch->pitch-num pitch)
(match pitch
[(list pitch-class octave) (+ (pitch-class->offset pitch-class) (* 12 octave))]))
(define (pitch-num->pitch num)
(list (offset->pitch-class (modulo num 12)) (floor (/ num 12))))
(define (key-pitch-num->pitch num)
(list (key-offset->pitch-class (modulo num 7)) (floor (/ num 7))))
#;(define base-tempo 120)
#;(define whole-note-len (* 1000 (/ 240 base-tempo))) ;; in milliseconds
(define (music-duration music)
(match music
[`(note ,p ,d) d]
[`(rest ,d) d]
[`(:+: ,ms ...) (apply + (map music-duration ms))]
[`(:=: ,ms ...) (apply max (map music-duration ms))]
[`(tempo ,n ,m) (/ (music-duration m) n)]
;jmp
[`(trans ,half-steps ,m) (music-duration m)]))
(define (music->notes music whole-note-len)
(match music
[`(note ,p ,d) (list (make-nnote (pitch->pitch-num p) (* d whole-note-len) 80 0 0))]
[`(rest ,d) (list)]
[`(:+: ,ms ...) (music-append-loop ms)]
[`(:=: ,ms ...) (apply append (map music->notes ms))]
[`(tempo ,n ,m) (music->notes (scale-music (/ 1 n) m))]
;jmp this seems really lame as i create a whole new struct for every existing one, but i couldn't find a setter..
[`(trans ,half-steps ,m) (map (lambda (x) (make-nnote (+ (nnote-pitch x) half-steps)
(nnote-duration x)
(nnote-velocity x)
(nnote-channel x)
(nnote-time x))) (music->notes m))]
[else (if (not (empty? music))
(if (nnote? (first music))
(music->notes (rest music))
(raise 'bad-input))
'())]))
;changes the duration of the music
(define (scale-music scale-by music)
(let recur ([music music])
(match music
[`(note ,p ,d) `(note ,p ,(* d scale-by))]
[`(rest ,d) `(rest ,(* d scale-by))]
[`(:+: ,ms ...) `(:+: ,@(map recur ms))]
[`(:=: ,ms ...) `(:=: ,@(map recur ms))]
[`(tempo ,n ,m) `(tempo ,n ,(recur m))]
[`(trans ,half-steps ,m) `(trans ,half-steps ,(recur m))])))
(define (music-append-loop musics whole-note-len)
(apply
append
(let loop ([musics musics] [delay 0])
(match musics
[`() null]
[(cons f r) (cons (map (delay-note (* delay whole-note-len)) (music->notes f))
(loop r (+ delay (music-duration f))))]))))
(define (key-pitch-num->music n) (note (key-pitch-num->pitch n) 1/4))
(define (key-pitch-nums->music ns) (apply :+: (map key-pitch-num->music ns)))
#|jmp|#
(define (absPitch p-class oct)
(+ (pitch-class->offset p-class) (* 12 oct)))
;pitch is not necessary since pitch is modeled as a number, not a pitch-class and octave
;nor is trans that works solely on pitch, just add.
#|(define (line m)
(foldr cons ':+: m))
(define cMaj '((note '(C 5) 1) (note '(E 5) 1) (note '(G 5) 1)))|#
#| delay handled by delay-notes and music->notes func
(define m (:=: (note '(C 5) 1) (note '(E 5) 1) (note '(G 5) 1)))
(play-music (:=: m (delay 1 m)))
(play-music (:=: m (delay-notes 500 (music->notes (trans 7 m)))));; doesn't work as i'd hoped
|#
;; tested, works
(define (nnote->note n whole-note-len)
(let* ([pitch (pitch-num->pitch (nnote-pitch n))]
[duration (/ (nnote-duration n) whole-note-len)])
`(note ',pitch ,duration)))
#;(define (retro m)
(replace-notes-in-music m (map nnote->note (reverse (music->notes m)))))
;should only be used on single note melodic lines for correct functionality
; works
(define (retro-strict m)
(map nnote->note (reverse (music->notes m))))
(define (invert-intervals old-ns new-ns)
(if (empty? (cdr old-ns))
new-ns
(let ([new-note (make-nnote (+ (nnote-pitch (last new-ns)) (- 0 (- (nnote-pitch (second old-ns)) (nnote-pitch (first old-ns)))))
(nnote-duration (second old-ns)) 80 0 0)])
(invert-intervals (cdr old-ns) (append new-ns (list new-note))))))
;inversion, if music goes a a# then inversion goes a ab
(define (invert-strict m)
(let ([m-lst (music->notes m)])
(map nnote->note (invert-intervals m-lst (list (first m-lst))))))
;; todo, retro and invert take only notes as for simple melodic lines, not chords and such...
;;justin added
(provide make-nnote
nnote-pitch
music->notes
:=:
:+:
note
rest
pitch-num->pitch
(struct-out midi-note-off)
(struct-out midi-note-on)
(struct-out midi-aftertouch))
; TODO :
; lineToList, retro...
; upgrade tempo for triplets???
| false |
9c73af970cbc4cd5cd76de7d5f2575145a3c4f0f | e5b2478b8cd1d86152b404488faea88872d4be35 | /2.9.1.ss | 7d694eb0537b07c754d80b36049c67bfcb3a9bae | []
| no_license | xiaq/tspl4-ans | e6d7dde3148b086c623140c1c74e8937653cf296 | da0f4cb56d0da63d57a739e4c8a578eee650d8ca | refs/heads/master | 2020-04-03T06:25:14.087276 | 2018-11-03T18:49:01 | 2018-11-03T18:49:01 | 155,074,083 | 0 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 160 | ss | 2.9.1.ss | (define make-counter
(lambda (init step)
(let ([next init])
(lambda ()
(let ([v next])
(set! next (+ next step))
v)))))
| false |
6e491b9d32eb22a1f30f18897142972ac2e73008 | 120324bbbf63c54de0b7f1ca48d5dcbbc5cfb193 | /packages/surfage/tests/and-let.sps | 47b9297c682cc30195f003e9b0b0a16d417f5dfb | [
"X11-distribute-modifications-variant",
"MIT"
]
| permissive | evilbinary/scheme-lib | a6d42c7c4f37e684c123bff574816544132cb957 | 690352c118748413f9730838b001a03be9a6f18e | refs/heads/master | 2022-06-22T06:16:56.203827 | 2022-06-16T05:54:54 | 2022-06-16T05:54:54 | 76,329,726 | 609 | 71 | MIT | 2022-06-16T05:54:55 | 2016-12-13T06:27:36 | Scheme | UTF-8 | Scheme | false | false | 2,595 | sps | and-let.sps | ;; Copyright (c) 2009 Derick Eddington. All rights reserved. Licensed under an
;; MIT-style license. My license is in the file named LICENSE from the original
;; collection this file is distributed with. If this file is redistributed with
;; some other collection, my license must also be included.
#!r6rs
(import
(rnrs)
(rnrs eval)
(surfage s2 and-let)
(surfage s78 lightweight-testing))
(define-syntax expect
(syntax-rules ()
[(_ expr result)
(check expr => result)]))
(define-syntax must-be-a-syntax-error
(syntax-rules ()
[(_ expr)
(check
(guard (ex [#t (syntax-violation? ex)])
(eval 'expr (environment '(rnrs) '(surfage s2 and-let))))
=> #t)]))
;; Taken straight from the reference implementation tests
(expect (and-let* () 1) 1)
(expect (and-let* () 1 2) 2)
(expect (and-let* () ) #t)
(expect (let ((x #f)) (and-let* (x))) #f)
(expect (let ((x 1)) (and-let* (x))) 1)
(expect (and-let* ((x #f)) ) #f)
(expect (and-let* ((x 1)) ) 1)
(must-be-a-syntax-error (and-let* ( #f (x 1))) )
(expect (and-let* ( (#f) (x 1)) ) #f)
(must-be-a-syntax-error (and-let* (2 (x 1))) )
(expect (and-let* ( (2) (x 1)) ) 1)
(expect (and-let* ( (x 1) (2)) ) 2)
(expect (let ((x #f)) (and-let* (x) x)) #f)
(expect (let ((x "")) (and-let* (x) x)) "")
(expect (let ((x "")) (and-let* (x) )) "")
(expect (let ((x 1)) (and-let* (x) (+ x 1))) 2)
(expect (let ((x #f)) (and-let* (x) (+ x 1))) #f)
(expect (let ((x 1)) (and-let* (((positive? x))) (+ x 1))) 2)
(expect (let ((x 1)) (and-let* (((positive? x))) )) #t)
(expect (let ((x 0)) (and-let* (((positive? x))) (+ x 1))) #f)
(expect (let ((x 1)) (and-let* (((positive? x)) (x (+ x 1))) (+ x 1))) 3)
;; This next one is from the reference implementation tests
;; but I can't see how it "must be a syntax-error".
#;(must-be-a-syntax-error
(let ((x 1)) (and-let* (((positive? x)) (x (+ x 1)) (x (+ x 1))) (+ x 1))))
(expect (let ((x 1)) (and-let* (x ((positive? x))) (+ x 1))) 2)
(expect (let ((x 1)) (and-let* ( ((begin x)) ((positive? x))) (+ x 1))) 2)
(expect (let ((x 0)) (and-let* (x ((positive? x))) (+ x 1))) #f)
(expect (let ((x #f)) (and-let* (x ((positive? x))) (+ x 1))) #f)
(expect (let ((x #f)) (and-let* ( ((begin x)) ((positive? x))) (+ x 1))) #f)
(expect (let ((x 1)) (and-let* (x (y (- x 1)) ((positive? y))) (/ x y))) #f)
(expect (let ((x 0)) (and-let* (x (y (- x 1)) ((positive? y))) (/ x y))) #f)
(expect (let ((x #f)) (and-let* (x (y (- x 1)) ((positive? y))) (/ x y))) #f)
(expect (let ((x 3)) (and-let* (x (y (- x 1)) ((positive? y))) (/ x y))) 3/2)
(check-report)
| true |
9e6cc7c248490c352b8af5eae30279b62e63c3bb | a07eccf73366c0588f0694a26c1a55e27ead079d | /01-toyos-jit/imp_reflection_tests.scm | 4fda502504c807de4f7aaecad6021efa54e70ad5 | []
| no_license | namin/reflection-schemes | a98a83d88a75ba72a5b9445185ed68c0ab973f19 | f99d7d937938fcdd70d5854b6ea77e5260d7c8ba | refs/heads/master | 2022-06-09T13:22:04.929019 | 2022-05-20T09:31:17 | 2022-05-20T09:31:17 | 233,351,280 | 20 | 2 | null | 2020-01-14T06:28:23 | 2020-01-12T06:54:06 | Scheme | UTF-8 | Scheme | false | false | 292 | scm | imp_reflection_tests.scm | (eg
(run-program-once
'(begin
(set! say 'hello)
(meta
(display :env)
(newline))
say))
'hello
)
(eg
(run-program-once
'(begin
(set! say 'hello)
(meta
(display :env)
(newline)
(update! :env 'say 'goodbye))
say))
'goodbye
)
| false |
f8000f8a7bc988a65447e2cfa8b7df898262eef3 | 0b0b7987be5b118121b0d991bdcf8d573a3273c1 | /ESSLLI2006/resources/italian.scm | 0a3f55e7bcf6b507d8062125a03286c9e888064b | [
"Apache-2.0"
]
| permissive | dcavar/dcavar.github.io | d0a85ca7025b8e0fa190e0a9f0966ab115f3dbbb | af1a2ceefc5e46559a7e74f96230bf4dccf24344 | refs/heads/master | 2023-08-30T10:05:20.825342 | 2023-08-17T19:07:43 | 2023-08-17T19:07:43 | 87,249,109 | 4 | 1 | Apache-2.0 | 2021-09-28T00:18:17 | 2017-04-05T00:44:19 | HTML | UTF-8 | Scheme | false | false | 2,242 | scm | italian.scm | (define stopwords-italian '("a" "abbia" "abbiamo" "abbiano" "abbiate" "ad" "agl" "agli" "ai" "al" "all" "alla" "alle" "allo" "anche" "avemmo" "avendo" "avesse" "avessero" "avessi" "avessimo" "aveste" "avesti" "avete" "aveva" "avevamo" "avevano" "avevate" "avevi" "avevo" "avrai" "avranno" "avrebbe" "avrebbero" "avrei" "avremmo" "avremo" "avreste" "avresti" "avrete" "avrà" "avrò" "avuta" "avute" "avuti" "avuto" "c" "che" "chi" "ci" "coi" "col" "come" "con" "contro" "cui" "da" "dagl" "dagli" "dai" "dal" "dall" "dalla" "dalle" "dallo" "degl" "degli" "dei" "del" "dell" "della" "delle" "dello" "di" "dov" "dove" "e" "ebbe" "ebbero" "ebbi" "ed" "era" "erano" "eravamo" "eravate" "eri" "ero" "essendo" "faccia" "facciamo" "facciano" "facciate" "faccio" "facemmo" "facendo" "facesse" "facessero" "facessi" "facessimo" "faceste" "facesti" "faceva" "facevamo" "facevano" "facevate" "facevi" "facevo" "fai" "fanno" "farai" "faranno" "farebbe" "farebbero" "farei" "faremmo" "faremo" "fareste" "faresti" "farete" "farà" "farò" "fece" "fecero" "feci" "fosse" "fossero" "fossi" "fossimo" "foste" "fosti" "fu" "fui" "fummo" "furono" "gli" "ha" "hai" "hanno" "ho" "i" "il" "in" "io" "l" "la" "le" "lei" "li" "lo" "loro" "lui" "ma" "mi" "mia" "mie" "miei" "mio" "ne" "negl" "negli" "nei" "nel" "nell" "nella" "nelle" "nello" "noi" "non" "nostra" "nostre" "nostri" "nostro" "o" "per" "perché" "più" "quale" "quanta" "quante" "quanti" "quanto" "quella" "quelle" "quelli" "quello" "questa" "queste" "questi" "questo" "sarai" "saranno" "sarebbe" "sarebbero" "sarei" "saremmo" "saremo" "sareste" "saresti" "sarete" "sarà" "sarò" "se" "sei" "si" "sia" "siamo" "siano" "siate" "siete" "sono" "sta" "stai" "stando" "stanno" "starai" "staranno" "starebbe" "starebbero" "starei" "staremmo" "staremo" "stareste" "staresti" "starete" "starà" "starò" "stava" "stavamo" "stavano" "stavate" "stavi" "stavo" "stemmo" "stesse" "stessero" "stessi" "stessimo" "steste" "stesti" "stette" "stettero" "stetti" "stia" "stiamo" "stiano" "stiate" "sto" "su" "sua" "sue" "sugl" "sugli" "sui" "sul" "sull" "sulla" "sulle" "sullo" "suo" "suoi" "ti" "tra" "tu" "tua" "tue" "tuo" "tuoi" "tutti" "tutto" "un" "una" "uno" "vi" "voi" "vostra" "vostre" "vostri" "vostro" "è"))
| false |
284fc5dbc81d0124f356ef0bd6f0e652781b2e34 | e8e2b3f22c7e1921e99f44593fc0ba5e5e44eebb | /PortableApps/GnuCashPortable/App/GnuCash/share/gnucash/ui/osx_accel_map | 91826212f3d653eedbfbb8eeee6f1068b393dce6 | []
| no_license | 314pi/PortableOffice | da262df5eaca240a00921e8348d366efa426ae57 | 08a5e828b35ff3cade7c56d101d7f6712b19a308 | refs/heads/master | 2022-11-25T19:20:33.942725 | 2018-05-11T07:49:35 | 2018-05-11T07:49:35 | 132,839,264 | 1 | 2 | null | 2022-11-02T22:19:00 | 2018-05-10T02:42:46 | Python | UTF-8 | Scheme | false | false | 18,213 | osx_accel_map | ; gnucash GtkAccelMap rc-file -*- scheme -*-
; this file is an automated accelerator map dump
;
; (gtk_accel_path "<Actions>/MenuAdditions/BudgetReportAction" "")
; (gtk_accel_path "<Actions>/GncPluginPageRegisterActions/UnvoidTransactionAction" "")
; (gtk_accel_path "<Actions>/MenuAdditions/IncomevsDayofWeekAction" "")
; (gtk_accel_path "<Actions>/MenuAdditions/BudgetBalanceSheetAction" "")
; (gtk_accel_path "<Actions>/MenuAdditions/AverageBalanceAction" "")
; (gtk_accel_path "<Actions>/gnc-plugin-aqbanking-actions/DtausImportAction" "")
; (gtk_accel_path "<Actions>/gnc-plugin-file-history-actions/RecentFile8Action" "")
; (gtk_accel_path "<Actions>/gnc-plugin-budget-actions/OpenBudgetAction" "")
; (gtk_accel_path "<Actions>/MainWindowActions/ViewSummaryAction" "")
; (gtk_accel_path "<Actions>/gnc-plugin-business-actions/EmployeeProcessPaymentAction" "")
; (gtk_accel_path "<Actions>/MainWindowActions/FileOpenMenuAction" "")
; (gtk_accel_path "<Actions>/gnc-plugin-business-actions/BusinessAction" "")
; (gtk_accel_path "<Actions>/MenuAdditions/BalanceSheetAction" "")
(gtk_accel_path "<Actions>/gnc-plugin-basic-commands-actions/FileOpenAction" "<Meta>o")
(gtk_accel_path "<Actions>/gnc-plugin-basic-commands-actions/FileSaveAction" "<Meta>s")
; (gtk_accel_path "<Actions>/MainWindowActions/ActionsRenamePageAction" "")
; (gtk_accel_path "<Actions>/MenuAdditions/InvestmentPortfolioAction" "")
; (gtk_accel_path "<Actions>/gnc-plugin-basic-commands-actions/FileExportAccountsAction" "")
; (gtk_accel_path "<Actions>/gnc-plugin-business-actions/BusinessTestReloadInvoiceAction" "")
; (gtk_accel_path "<Actions>/MenuAdditions/ExpensesvsDayofWeekAction" "")
; (gtk_accel_path "<Actions>/gnc-plugin-csv-actions/CsvImportAction" "")
; (gtk_accel_path "<Actions>/MainWindowActions/FilePropertiesAction" "<Alt>Return")
; (gtk_accel_path "<Actions>/gnc-plugin-basic-commands-actions/EditTaxOptionsAction" "")
; (gtk_accel_path "<Actions>/MainWindowActions/FileNewMenuAction" "")
; (gtk_accel_path "<Actions>/gnc-plugin-business-actions/CustomerProcessPaymentAction" "")
; (gtk_accel_path "<Actions>/MenuAdditions/TrialBalanceAction" "")
; (gtk_accel_path "<Actions>/MainWindowActions/ActionsAction" "")
; (gtk_accel_path "<Actions>/MenuAdditions/AccountSummaryAction" "")
; (gtk_accel_path "<Actions>/MainWindowActions/HelpAction" "")
; (gtk_accel_path "<Actions>/gnc-plugin-business-actions/BusinessTestReloadReceivableAction" "")
; (gtk_accel_path "<Actions>/MenuAdditions/SampleCustomAction" "")
; (gtk_accel_path "<Actions>/gnc-plugin-business-actions/EmployeeNewEmployeeOpenAction" "")
; (gtk_accel_path "<Actions>/GncPluginPageAccountTreeActions/ScrubAllAction" "")
; (gtk_accel_path "<Actions>/GncPluginPageRegisterActions/ScheduleTransactionAction" "")
; (gtk_accel_path "<Actions>/gnc-plugin-aqbanking-actions/ABIssueIntTransAction" "")
; (gtk_accel_path "<Actions>/MenuAdditions/ProfitLossAction" "")
; (gtk_accel_path "<Actions>/gnc-plugin-log-replay-actions/LogReplayAction" "")
; (gtk_accel_path "<Actions>/gnc-plugin-business-actions/CustomerNewJobOpenAction" "")
; (gtk_accel_path "<Actions>/MenuAdditions/PayableAgingAction" "")
; (gtk_accel_path "<Actions>/MenuAdditions/GeneralLedgerAction" "")
(gtk_accel_path "<Actions>/MainWindowActions/HelpTutorialAction" "")
; (gtk_accel_path "<Actions>/gnc-plugin-basic-commands-actions/ActionsSinceLastRunAction" "")
; (gtk_accel_path "<Actions>/gnc-plugin-business-actions/BusinessTestReloadOwnerAction" "")
; (gtk_accel_path "<Actions>/MenuAdditions/ReceivableAgingAction" "")
; (gtk_accel_path "<Actions>/gnc-plugin-basic-commands-actions/ToolsPriceEditorAction" "")
; (gtk_accel_path "<Actions>/gnc-plugin-business-actions/VendorFindJobOpenAction" "")
(gtk_accel_path "<Actions>/gnc-plugin-basic-commands-actions/FileNewAction" "<Meta>n")
; (gtk_accel_path "<Actions>/gnc-plugin-aqbanking-actions/ABSetupAction" "")
; (gtk_accel_path "<Actions>/MenuAdditions/BalanceSheetusingeguilegncAction" "")
; (gtk_accel_path "<Actions>/MainWindowActions/ScrubMenuAction" "")
; (gtk_accel_path "<Actions>/GncPluginPageRegisterActions/CancelTransactionAction" "")
; (gtk_accel_path "<Actions>/GncPluginPageRegisterActions/ReverseTransactionAction" "")
(gtk_accel_path "<Actions>/GncPluginPageRegisterActions/CutTransactionAction" "<Control><Meta>x")
; (gtk_accel_path "<Actions>/MenuAdditions/JobReportAction" "")
; (gtk_accel_path "<Actions>/gnc-plugin-business-actions/VendorNewJobOpenAction" "")
; (gtk_accel_path "<Actions>/gnc-plugin-file-history-actions/RecentFile5Action" "")
(gtk_accel_path "<Actions>/GncPluginPageRegisterActions/EditFindTransactionsAction" "<Meta>f")
(gtk_accel_path "<Actions>/GncPluginPageAccountTreeActions/EditEditAccountAction" "<Meta>e")
; (gtk_accel_path "<Actions>/GncPluginPageRegisterActions/EditExchangeRateAction" "")
; (gtk_accel_path "<Actions>/gnc-plugin-budget-actions/NewBudgetAction" "")
; (gtk_accel_path "<Actions>/MenuAdditions/BudgetIncomeStatementAction" "")
(gtk_accel_path "<Actions>/GncPluginPageRegisterActions/ActionsTransferAction" "<Meta>t")
; (gtk_accel_path "<Actions>/MenuAdditions/IncomeExpenseChartAction" "")
; (gtk_accel_path "<Actions>/MenuAdditions/LiabilityPiechartAction" "")
; (gtk_accel_path "<Actions>/gnc-plugin-business-actions/EmployeeMenuAction" "")
(gtk_accel_path "<Actions>/GncPluginPageAccountTreeActions/ActionsTransferAction" "<Meta>t")
; (gtk_accel_path "<Actions>/gnc-plugin-business-actions/BillsDueReminderOpenAction" "")
; (gtk_accel_path "<Actions>/MainWindowActions/ActionsForgetWarningsAction" "")
(gtk_accel_path "<Actions>/MainWindowActions/FilePrintAction" "<Meta>p")
; (gtk_accel_path "<Actions>/gnc-plugin-business-actions/BillingTermsOpenAction" "")
; (gtk_accel_path "<Actions>/MenuAdditions/BusinessAction" "")
; (gtk_accel_path "<Actions>/MainWindowActions/FileAction" "")
; (gtk_accel_path "<Actions>/gnc-plugin-business-actions/VendorNewVendorOpenAction" "")
; (gtk_accel_path "<Actions>/GncPluginPageRegisterActions/ActionsLotsAction" "")
; (gtk_accel_path "<Actions>/MenuAdditions/CustomerReportAction" "")
; (gtk_accel_path "<Actions>/GncPluginPageAccountTreeActions/ActionsReconcileAction" "")
; (gtk_accel_path "<Actions>/MenuAdditions/CustomReportsAction" "")
; (gtk_accel_path "<Actions>/gnc-plugin-aqbanking-actions/ABIssueTransAction" "")
; (gtk_accel_path "<Actions>/MenuAdditions/IncomeExpenseAction" "")
; (gtk_accel_path "<Actions>/MenuAdditions/IncomePiechartAction" "")
; (gtk_accel_path "<Actions>/MainWindowActions/ReportsAction" "")
; (gtk_accel_path "<Actions>/MainWindowActions/TransactionAction" "")
; (gtk_accel_path "<Actions>/GncPluginPageRegisterActions/ViewStyleAutoSplitAction" "")
; (gtk_accel_path "<Actions>/GncPluginPageRegisterActions/ActionsStockSplitAction" "")
; (gtk_accel_path "<Actions>/gnc-plugin-business-actions/VendorFindVendorOpenAction" "")
; (gtk_accel_path "<Actions>/GncPluginPageAccountTreeActions/ScrubAction" "")
(gtk_accel_path "<Actions>/MainWindowActions/EditCutAction" "<Meta>x")
; (gtk_accel_path "<Actions>/gnc-plugin-aqbanking-actions/OnlineActionsAction" "")
; (gtk_accel_path "<Actions>/GncPluginPageRegisterActions/ActionsReconcileAction" "")
; (gtk_accel_path "<Actions>/gnc-plugin-basic-commands-actions/ToolsFinancialCalculatorAction" "")
(gtk_accel_path "<Actions>/MainWindowActions/FilePageSetupAction" "<Shift><Meta>p")
(gtk_accel_path "<Actions>/MainWindowActions/FileCloseAction" "<Meta>w")
; (gtk_accel_path "<Actions>/MenuAdditions/TransactionReportAction" "")
; (gtk_accel_path "<Actions>/MenuAdditions/BudgetProfitLossAction" "")
; (gtk_accel_path "<Actions>/GncPluginPageRegisterActions/ScrubAllAction" "")
; (gtk_accel_path "<Actions>/gnc-plugin-basic-commands-actions/ActionsMortgageLoanAction" "")
; (gtk_accel_path "<Actions>/gnc-plugin-register-actions/ToolsGeneralLedgerAction" "")
; (gtk_accel_path "<Actions>/GncPluginPageAccountTreeActions/EditDeleteAccountAction" "Delete")
; (gtk_accel_path "<Actions>/MenuAdditions/VendorReportAction" "")
; (gtk_accel_path "<Actions>/gnc-plugin-business-actions/CustomerFindCustomerOpenAction" "")
; (gtk_accel_path "<Actions>/gnc-plugin-file-history-actions/RecentFile2Action" "")
; (gtk_accel_path "<Actions>/gnc-plugin-qif-import-actions/QIFImportAction" "")
; (gtk_accel_path "<Actions>/GncPluginPageRegisterActions/RecordTransactionAction" "")
; (gtk_accel_path "<Actions>/gnc-plugin-file-history-actions/RecentFile4Action" "")
; (gtk_accel_path "<Actions>/MenuAdditions/BudgetFlowAction" "")
; (gtk_accel_path "<Actions>/gnc-plugin-business-actions/VendorFindBillOpenAction" "")
; (gtk_accel_path "<Actions>/GncPluginPageRegisterActions/ViewStyleJournalAction" "")
; (gtk_accel_path "<Actions>/gnc-plugin-basic-commands-actions/ActionsScheduledTransactionsAction" "")
; (gtk_accel_path "<Actions>/gnc-plugin-business-actions/EmployeeFindEmployeeOpenAction" "")
; (gtk_accel_path "<Actions>/GncPluginPageRegisterActions/JumpTransactionAction" "")
(gtk_accel_path "<Actions>/GncPluginPageRegisterActions/PasteTransactionAction" "<Control><Meta>v")
; (gtk_accel_path "<Actions>/gnc-plugin-business-actions/BusinessTestInitDataAction" "")
; (gtk_accel_path "<Actions>/MainWindowActions/WindowMovePageAction" "")
; (gtk_accel_path "<Actions>/gnc-plugin-aqbanking-actions/ABGetTransAction" "")
; (gtk_accel_path "<Actions>/gnc-plugin-business-actions/EmployeeFindExpenseVoucherOpenAction" "")
; (gtk_accel_path "<Actions>/MainWindowActions/HelpContentsAction" "F1")
; (gtk_accel_path "<Actions>/MenuAdditions/CustomMulticolumnReportAction" "")
; (gtk_accel_path "<Actions>/MenuAdditions/WelcomeSampleReportAction" "")
(gtk_accel_path "<Actions>/GncPluginPageRegisterActions/EditCutAction" "<Meta>x")
; (gtk_accel_path "<Actions>/GncPluginPageRegisterActions/ViewStyleDoubleLineAction" "")
; (gtk_accel_path "<Actions>/GncPluginPageRegisterActions/ScrubCurrentAction" "")
; (gtk_accel_path "<Actions>/MainWindowActions/ViewAction" "")
; (gtk_accel_path "<Actions>/MenuAdditions/AdvancedPortfolioAction" "")
; (gtk_accel_path "<Actions>/gnc-plugin-basic-commands-actions/HelpTipsOfTheDayAction" "")
; (gtk_accel_path "<Actions>/MenuAdditions/BudgetAction" "")
; (gtk_accel_path "<Actions>/gnc-plugin-business-actions/CustomerFindInvoiceOpenAction" "")
; (gtk_accel_path "<Actions>/gnc-plugin-business-actions/CustomerFindJobOpenAction" "")
(gtk_accel_path "<Actions>/MainWindowActions/EditCopyAction" "<Meta>c")
; (gtk_accel_path "<Actions>/gnc-plugin-business-actions/BusinessTestSearchAction" "")
; (gtk_accel_path "<Actions>/gnc-plugin-aqbanking-actions/Mt940ImportAction" "")
; (gtk_accel_path "<Actions>/MenuAdditions/IncomeBarchartAction" "")
; (gtk_accel_path "<Actions>/GncPluginPageAccountTreeActions/ActionsLotsAction" "")
; (gtk_accel_path "<Actions>/GncPluginPageRegisterActions/ViewFilterByAction" "")
; (gtk_accel_path "<Actions>/GncPluginPageAccountTreeActions/EditRenumberSubaccountsAction" "")
(gtk_accel_path "<Actions>/GncPluginPageRegisterActions/CopyTransactionAction" "<Control><Meta>c")
; (gtk_accel_path "<Actions>/MainWindowActions/ToolsAction" "")
; (gtk_accel_path "<Actions>/MenuAdditions/ExpensePiechartAction" "")
; (gtk_accel_path "<Actions>/GncPluginPageAccountTreeActions/FileOpenSubaccountsAction" "")
; (gtk_accel_path "<Actions>/MainWindowActions/WindowsAction" "")
; (gtk_accel_path "<Actions>/gnc-plugin-ofx-actions/OfxImportAction" "")
; (gtk_accel_path "<Actions>/gnc-plugin-business-actions/BusinessTestAction" "")
(gtk_accel_path "<Actions>/gnc-plugin-basic-commands-actions/EditFindTransactionsAction" "<Meta>f")
; (gtk_accel_path "<Actions>/MenuAdditions/ExpenseBarchartAction" "")
; (gtk_accel_path "<Actions>/MenuAdditions/BudgetBarchartAction" "")
; (gtk_accel_path "<Actions>/GncPluginPageRegisterActions/DeleteTransactionAction" "")
; (gtk_accel_path "<Actions>/MenuAdditions/IncomeStatementAction" "")
; (gtk_accel_path "<Actions>/gnc-plugin-aqbanking-actions/Mt942ImportAction" "")
; (gtk_accel_path "<Actions>/gnc-plugin-basic-commands-actions/ActionsScheduledTransactionEditorAction" "")
; (gtk_accel_path "<Actions>/GncPluginPageRegisterActions/RemoveTransactionSplitsAction" "")
; (gtk_accel_path "<Actions>/GncPluginPageAccountTreeActions/ScrubSubAction" "")
; (gtk_accel_path "<Actions>/gnc-plugin-file-history-actions/RecentFile1Action" "")
(gtk_accel_path "<Actions>/GncPluginPageRegisterActions/FilePrintAction" "<Meta>p")
; (gtk_accel_path "<Actions>/GncPluginPageAccountTreeActions/FileNewAccountAction" "")
; (gtk_accel_path "<Actions>/gnc-plugin-file-history-actions/RecentFile3Action" "")
(gtk_accel_path "<Actions>/GncPluginPageRegisterActions/EditEditAccountAction" "<Meta>e")
;(gtk_accel_path "<Actions>/MainWindowActions/EditPreferencesAction" "<alt>,")
; (gtk_accel_path "<Actions>/GncPluginPageAccountTreeActions/ActionsStockSplitAction" "")
; (gtk_accel_path "<Actions>/MainWindowActions/HelpAboutAction" "")
; (gtk_accel_path "<Actions>/MainWindowActions/ViewFilterByAction" "")
; (gtk_accel_path "<Actions>/GncPluginPageRegisterActions/ReportsAccountReportAction" "")
; (gtk_accel_path "<Actions>/MainWindowActions/ViewToolbarAction" "")
; (gtk_accel_path "<Actions>/gnc-plugin-file-history-actions/RecentFile7Action" "")
; (gtk_accel_path "<Actions>/gnc-plugin-aqbanking-actions/ABGetBalanceAction" "")
; (gtk_accel_path "<Actions>/GncPluginPageAccountTreeActions/FileAddAccountHierarchyAssistantAction" "")
; (gtk_accel_path "<Actions>/MainWindowActions/WindowNewAction" "")
; (gtk_accel_path "<Actions>/gnc-plugin-file-history-actions/RecentFile9Action" "")
; (gtk_accel_path "<Actions>/MainWindowActions/ViewSortByAction" "")
; (gtk_accel_path "<Actions>/MainWindowActions/EditAction" "")
; (gtk_accel_path "<Actions>/gnc-plugin-business-actions/CustomerNewInvoiceOpenAction" "")
; (gtk_accel_path "<Actions>/GncPluginPageRegisterActions/DuplicateTransactionAction" "")
; (gtk_accel_path "<Actions>/GncPluginPageRegisterActions/SplitTransactionAction" "")
; (gtk_accel_path "<Actions>/MenuAdditions/LiabilityBarchartAction" "")
; (gtk_accel_path "<Actions>/GncPluginPageRegisterActions/BlankTransactionAction" "")
; (gtk_accel_path "<Actions>/GncPluginPageRegisterActions/ViewSortByAction" "")
; (gtk_accel_path "<Actions>/gnc-plugin-business-actions/EmployeeNewExpenseVoucherOpenAction" "")
; (gtk_accel_path "<Actions>/GncPluginPageAccountTreeActions/ViewFilterByAction" "")
; (gtk_accel_path "<Actions>/MenuAdditions/EmployeeReportAction" "")
; (gtk_accel_path "<Actions>/MenuAdditions/FancyInvoiceAction" "")
(gtk_accel_path "<Actions>/GncPluginPageRegisterActions/EditPasteAction" "<Meta>v")
; (gtk_accel_path "<Actions>/gnc-plugin-aqbanking-actions/ABIssueDirectDebitAction" "")
(gtk_accel_path "<Actions>/gnc-plugin-basic-commands-actions/FileSaveAsAction" "<Shift><Meta>s")
; (gtk_accel_path "<Actions>/MenuAdditions/AssetsLiabilitiesAction" "")
; (gtk_accel_path "<Actions>/MenuAdditions/PrintableInvoiceAction" "")
; (gtk_accel_path "<Actions>/MenuAdditions/EasyInvoiceAction" "")
; (gtk_accel_path "<Actions>/MenuAdditions/TaxInvoiceAction" "")
; (gtk_accel_path "<Actions>/GncPluginPageRegisterActions/ViewStyleBasicAction" "")
; (gtk_accel_path "<Actions>/MenuAdditions/EquityStatementAction" "")
; (gtk_accel_path "<Actions>/gnc-plugin-business-actions/VendorNewBillOpenAction" "")
; (gtk_accel_path "<Actions>/MenuAdditions/PriceScatterplotAction" "")
(gtk_accel_path "<Actions>/MainWindowActions/ViewRefreshAction" "<Meta>r")
; (gtk_accel_path "<Actions>/gnc-plugin-aqbanking-actions/DtausImportSendAction" "")
; (gtk_accel_path "<Actions>/GncPluginPageRegisterActions/VoidTransactionAction" "")
; (gtk_accel_path "<Actions>/gnc-plugin-business-actions/VendorProcessPaymentAction" "")
; (gtk_accel_path "<Actions>/GncPluginPageAccountTreeActions/ActionsAutoClearAction" "")
; (gtk_accel_path "<Actions>/MenuAdditions/NetWorthBarchartAction" "")
; (gtk_accel_path "<Actions>/GncPluginPageRegisterActions/ReportsAcctTransReportAction" "")
; (gtk_accel_path "<Actions>/GncPluginPageAccountTreeActions/FileOpenAccountAction" "")
; (gtk_accel_path "<Actions>/gnc-plugin-business-actions/CustomerMenuAction" "")
; (gtk_accel_path "<Actions>/gnc-plugin-basic-commands-actions/ToolsBookCloseAction" "")
; (gtk_accel_path "<Actions>/MenuAdditions/TaxScheduleReportTXFExportAction" "")
; (gtk_accel_path "<Actions>/MainWindowActions/ViewStatusbarAction" "")
; (gtk_accel_path "<Actions>/gnc-plugin-basic-commands-actions/ToolsCommodityEditorAction" "")
(gtk_accel_path "<Actions>/MainWindowActions/EditPasteAction" "<Meta>v")
; (gtk_accel_path "<Actions>/gnc-plugin-business-actions/VendorMenuAction" "")
; (gtk_accel_path "<Actions>/MainWindowActions/ExtensionsAction" "")
; (gtk_accel_path "<Actions>/gnc-plugin-file-history-actions/RecentFile0Action" "")
(gtk_accel_path "<Actions>/GncPluginPageRegisterActions/EditCopyAction" "<Meta>c")
; (gtk_accel_path "<Actions>/MenuAdditions/CashFlowAction" "")
; (gtk_accel_path "<Actions>/MainWindowActions/FileImportAction" "")
; (gtk_accel_path "<Actions>/gnc-plugin-business-actions/CustomerNewCustomerOpenAction" "")
(gtk_accel_path "<Actions>/MainWindowActions/FileQuitAction" "<Meta>q")
; (gtk_accel_path "<Actions>/gnc-plugin-business-actions/TaxTablesOpenAction" "")
; (gtk_accel_path "<Actions>/MenuAdditions/AssetPiechartAction" "")
; (gtk_accel_path "<Actions>/MenuAdditions/SampleReportwithExamplesAction" "")
; (gtk_accel_path "<Actions>/MenuAdditions/GeneralJournalAction" "")
; (gtk_accel_path "<Actions>/MenuAdditions/AssetBarchartAction" "")
; (gtk_accel_path "<Actions>/gnc-plugin-stylesheets-actions/EditStyleSheetsAction" "")
; (gtk_accel_path "<Actions>/gnc-plugin-account-tree-actions/ViewAccountTreeAction" "")
; (gtk_accel_path "<Actions>/MainWindowActions/FileExportAction" "")
; (gtk_accel_path "<Actions>/gnc-plugin-file-history-actions/RecentFile6Action" "")
(gtk_accel_path "<Actions>/GncPluginPageReportActions/FilePrintAction" "<Meta>p")
(gtk_accel_path "<Actions>/GncPluginPageReportActions/EditCutAction" "<Meta>x")
(gtk_accel_path "<Actions>/GncPluginPageReportActions/EditPasteAction" "<Meta>v")
(gtk_accel_path "<Actions>/GncPluginPageReportActions/ViewRefreshAction" "<Meta>r")
(gtk_accel_path "<Actions>/GncPluginPageReportActions/EditCopyAction" "<Meta>c")
| false |
|
6c0a3b46b9b3b55b141cbbc74c4c882a7941adc2 | 4a1ff5a0f674ff41bd384301ab82b3197f5ca0c8 | /problems/0011/main.scm | 98229ca56e9d26865dc718a24b776489fae2dbb2 | []
| no_license | MiyamonY/yukicoder | e0a323d68c4d3b41bdb42fb3ed6ab105619ca7e9 | 1bb8882ac76cc302428ab0417f90cfa94f7380c8 | refs/heads/master | 2020-05-09T12:13:31.627382 | 2019-10-06T17:01:45 | 2019-10-06T17:01:45 | 181,105,911 | 0 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 638 | scm | main.scm | (define (read-number)
(string->number (read-line)))
(let ((w (read-number))
(h (read-number))
(n (read-number)))
(let-values (((marks nums)
(let loop ((in (read-line))
(marks '())
(nums '()))
(cond ((eof-object? in)
(values (length (delete-duplicates marks))
(length (delete-duplicates nums))))
(else
(let* ((in (open-input-string in))
(s (read in))
(k (read in)))
(loop (read-line) (cons s marks) (cons k nums))))))))
(print (- (+ (* marks h) (* nums w)) (* marks nums) n))))
| false |
ffbe81c4b15856c378905a51c117d04a84e0b74a | d9cb7af1bdc28925fd749260d5d643925185b084 | /test/2.56.scm | 411b02d06f8aa361b7bceea53e269c8dc52391dc | []
| no_license | akerber47/sicp | 19e0629df360e40fd2ea9ba34bf7bd92be562c3e | 9e3d72b3923777e2a66091d4d3f3bfa96f1536e0 | refs/heads/master | 2021-07-16T19:36:31.635537 | 2020-07-19T21:10:54 | 2020-07-19T21:10:54 | 14,405,303 | 0 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 316 | scm | 2.56.scm | (define z (make-complex (make-rectangular 5 0)))
(define p (make-rational (make-rat 5 1)))
(define (run)
(let ()
(assert (equ? (add p 3) 8))
(assert (equ? (add z 3) (make-complex (make-rectangular 8 0))))
(assert (equ? (add z p) (make-complex (make-rectangular 10 0))))
"All tests passed!"
)
)
| false |
864a72e8f32d11b459a6e59f83b737912e2341de | 295dbd430419a7c36df8d2fd033f8e9afdc308c3 | /Metalinguistic_Abstraction/amb/ex_4_39.scm | 57ad69c34882efe8231a69eb6add12873267787b | []
| no_license | ojima-h/sicp | f76b38a46a4f413d6a33f1ba0df4f6af28208fa1 | 4bbcd6a011076aef6fe36071958b76e05f653c75 | refs/heads/master | 2016-09-05T17:36:32.319932 | 2014-06-09T00:30:37 | 2014-06-09T00:30:37 | null | 0 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 3,036 | scm | ex_4_39.scm | (load "../amb/main.scm")
(batch-exec
(define (distinct? lst)
(if (null? lst)
true
(let ((x (car lst)))
(and (every (lambda (y) (not (= x y))) (cdr lst))
(distinct? (cdr lst))))))
;; original
(define (multiple-dwelling-original)
(let ((baker (amb 1 2 3 4 5))
(cooper (amb 1 2 3 4 5))
(fletcher (amb 1 2 3 4 5))
(miller (amb 1 2 3 4 5))
(smith (amb 1 2 3 4 5)))
(require
(distinct? (list baker cooper fletcher miller smith)))
(require (not (= baker 5)))
(require (not (= cooper 1)))
(require (not (= fletcher 5)))
(require (not (= fletcher 1)))
(require (> miller cooper))
(require (not (= (abs (- smith fletcher)) 1)))
(require (not (= (abs (- fletcher cooper)) 1)))
(list (list 'baker baker)
(list 'cooper cooper)
(list 'fletcher fletcher)
(list 'miller miller)
(list 'smith smith))))
;; reordered
(define (multiple-dwelling-reordered)
(let ((baker (amb 1 2 3 4 5))
(cooper (amb 1 2 3 4 5))
(fletcher (amb 1 2 3 4 5))
(miller (amb 1 2 3 4 5))
(smith (amb 1 2 3 4 5)))
(require (not (= baker 5)))
(require (not (= cooper 1)))
(require (not (= fletcher 5)))
(require (not (= fletcher 1)))
(require (not (= (abs (- fletcher cooper)) 1)))
(require (> miller cooper))
(require
(distinct? (list baker cooper fletcher miller smith)))
(require (not (= (abs (- smith fletcher)) 1)))
(list (list 'baker baker)
(list 'cooper cooper)
(list 'fletcher fletcher)
(list 'miller miller)
(list 'smith smith))))
;; faster
(define (multiple-dwelling-faster)
(let ((baker (amb 1 2 3 4 5)))
(require (not (= baker 5)))
(let ((cooper (amb 1 2 3 4 5)))
(require (not (= cooper 1)))
(let ((fletcher (amb 1 2 3 4 5)))
(require (not (= fletcher 5)))
(require (not (= fletcher 1)))
(require (not (= (abs (- fletcher cooper)) 1)))
(let ((miller (amb 1 2 3 4 5)))
(require (> miller cooper))
(let ((smith (amb 1 2 3 4 5)))
(require
(distinct? (list baker cooper fletcher miller smith)))
(require (not (= (abs (- smith fletcher)) 1)))
(list (list 'baker baker)
(list 'cooper cooper)
(list 'fletcher fletcher)
(list 'miller miller)
(list 'smith smith)))))))))
(set! backtrack-count 0)
(batch-exec
(multiple-dwelling-original))
(newline) (display ";;;;;;;;;;;;;;;;;;;;;;")
(newline) (display ";;;;;; original ;;;;;;")
(newline) (display ";;;;;;;;;;;;;;;;;;;;;;")
(newline) (display backtrack-count)
(set! backtrack-count 0)
(batch-exec
(multiple-dwelling-reordered))
(newline) (display ";;;;;;;;;;;;;;;;;;;;;;")
(newline) (display ";;;;;; reordered ;;;;;")
(newline) (display ";;;;;;;;;;;;;;;;;;;;;;")
(newline) (display backtrack-count)
(set! backtrack-count 0)
(batch-exec
(multiple-dwelling-faster))
(newline) (display ";;;;;;;;;;;;;;;;;;;;;;")
(newline) (display ";;;;;; faster ;;;;;;;;")
(newline) (display ";;;;;;;;;;;;;;;;;;;;;;")
(newline) (display backtrack-count)
| false |
de18b7f8965589003a9a2c4990714c4cb41f6154 | defeada37d39bca09ef76f66f38683754c0a6aa0 | /mscorlib/system/deployment/internal/internal-application-identity-helper.sls | 7c73d0a999036c0c0edd840315bec79a77a65307 | []
| 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 | 908 | sls | internal-application-identity-helper.sls | (library (system
deployment
internal
internal-application-identity-helper)
(export is?
internal-application-identity-helper?
get-activation-context-data
get-internal-app-id)
(import (ironscheme-clr-port))
(define (is? a)
(clr-is
System.Deployment.Internal.InternalApplicationIdentityHelper
a))
(define (internal-application-identity-helper? a)
(clr-is
System.Deployment.Internal.InternalApplicationIdentityHelper
a))
(define-method-port
get-activation-context-data
System.Deployment.Internal.InternalApplicationIdentityHelper
GetActivationContextData
(static: System.Object System.ActivationContext))
(define-method-port
get-internal-app-id
System.Deployment.Internal.InternalApplicationIdentityHelper
GetInternalAppId
(static: System.Object System.ApplicationIdentity)))
| false |
a179c1b8f1bd4e0133f10ade2b98e3d32230b3fe | 471a04fa9301455c51a890b8936cc60324a51f27 | /srfi-lib/srfi/32/vector-util.scm | 5ee3cd8d8c93222f902d4b392f1882a2f899db8d | [
"LicenseRef-scancode-unknown-license-reference",
"Apache-2.0",
"MIT"
]
| permissive | racket/srfi | e79e012fda6d6bba1a9445bcef461930bc27fde8 | 25eb1c0e1ab8a1fa227750aa7f0689a2c531f8c8 | refs/heads/master | 2023-08-16T11:10:38.100847 | 2023-02-16T01:18:44 | 2023-02-16T12:34:27 | 27,413,027 | 10 | 10 | NOASSERTION | 2023-09-14T14:40:51 | 2014-12-02T03:22:45 | HTML | UTF-8 | Scheme | false | false | 1,974 | scm | vector-util.scm | (module vector-util mzscheme
(provide (all-defined))
(define (vector-portion-copy vec start end)
(let* ((len (vector-length vec))
(new-len (- end start))
(new (make-vector new-len)))
(do ((i start (+ i 1))
(j 0 (+ j 1)))
((= i end) new)
(vector-set! new j (vector-ref vec i)))))
(define (vector-copy vec)
(vector-portion-copy vec 0 (vector-length vec)))
(define (vector-portion-copy! target src start end)
(let ((len (- end start)))
(do ((i (- len 1) (- i 1))
(j (- end 1) (- j 1)))
((< i 0))
(vector-set! target i (vector-ref src j)))))
(define (has-element list index)
(cond
((zero? index)
(if (pair? list)
(values #t (car list))
(values #f #f)))
((null? list)
(values #f #f))
(else
(has-element (cdr list) (- index 1)))))
(define (list-ref-or-default list index default)
(call-with-values
(lambda () (has-element list index))
(lambda (has? maybe)
(if has?
maybe
default))))
(define (vector-start+end vector maybe-start+end)
(let ((start (list-ref-or-default maybe-start+end
0 0))
(end (list-ref-or-default maybe-start+end
1 (vector-length vector))))
(values start end)))
(define (vectors-start+end-2 vector-1 vector-2 maybe-start+end)
(let ((start-1 (list-ref-or-default maybe-start+end
0 0))
(end-1 (list-ref-or-default maybe-start+end
1 (vector-length vector-1)))
(start-2 (list-ref-or-default maybe-start+end
2 0))
(end-2 (list-ref-or-default maybe-start+end
3 (vector-length vector-2))))
(values start-1 end-1
start-2 end-2)))
)
| false |
d2fc6abcd450fa88eec78da416ab5b804307fb8b | 665da87f9fefd8678b0635e31df3f3ff28a1d48c | /examples/threading/parameters.scm | d1ae62f3d08efe3d518ec6ab7700d78c8d1b2a88 | [
"MIT"
]
| permissive | justinethier/cyclone | eeb782c20a38f916138ac9a988dc53817eb56e79 | cc24c6be6d2b7cc16d5e0ee91f0823d7a90a3273 | refs/heads/master | 2023-08-30T15:30:09.209833 | 2023-08-22T02:11:59 | 2023-08-22T02:11:59 | 31,150,535 | 862 | 64 | MIT | 2023-03-04T15:15:37 | 2015-02-22T03:08:21 | Scheme | UTF-8 | Scheme | false | false | 797 | scm | parameters.scm | ;; A simple program demonstrating how parameter objects interact with threads
;;
;; Note this is poor code as it uses timing via sleeps instead of proper
;; thread synchronization!!!
;;
(import (scheme base)
(scheme read)
(scheme write)
(srfi 18)
)
(thread-start!
(make-thread
(lambda ()
(thread-sleep! 1.2)
(display "started thread, this should be written to console")
(newline)
(display "thread done")
(newline)
(flush-output-port (current-output-port)))))
(thread-sleep! 1) ;; Prevent race condition replacing stdout before thread is spawned
(write `(1 2 3))
(define fp (open-output-file "tmp.txt"))
(parameterize
((current-output-port fp))
(write `(4 5 6))
(thread-sleep! 3)
)
(close-port fp)
(write `(7 8 9))
| false |
e7de6adbdc9d952247c05e0fc1b9afe705d2f15b | 958488bc7f3c2044206e0358e56d7690b6ae696c | /scheme/expt.scm | 9fe3546b63eb541983d46eca1e90756d614a57e2 | []
| 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 | 452 | scm | expt.scm | (define (fast-expt b n)
(cond ((= n 0) 1)
((even? n) (fast-expt (* b b) (/ n 2)))
((odd? n) (* b (fast-expt b (- n 1))))
(else (display "fast-expt: unexpected argument\n"))))
(define (fast-expt2 b n)
(let loop ((b b) (n n) (prod 1))
(cond ((= n 0) prod)
((even? n) (loop (* b b) (/ n 2) prod))
((odd? n) (loop b (- n 1) (* b prod)))
(else (display "fast-expt: unexpected argument\n")))))
| false |
645eba3d787837186634a8fad48b2d7f34191e04 | 435ca18a711b537aead4a73807b206ff99f57785 | /tests/ffi.scm | 2f65e106403c2b40d5e470536a3ccd50e40c7463 | []
| no_license | mushrom/schemecc | 59c961dc8ae85a4ea8089e62d6a1e1272fe487a9 | cb3c7a48a9feaf134b297dcb9ae181909f4e1451 | refs/heads/master | 2021-01-01T05:17:44.911566 | 2016-05-18T02:58:16 | 2016-05-18T02:58:16 | 57,012,633 | 0 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 256 | scm | ffi.scm | (import (scheme base))
(import (scheme write))
(let ((thing
(lambda (x y)
(foreign-call "s_write_char" x)
(foreign-call "s_write_char" y))))
(write (cons 1 (cons 2 (cons 3 (quote ())))))
(newline)
(thing #\A #\newline))
| false |
7eca187b7a016251253dc4b6355e014a3656b0c2 | 710bd922d612840b3dc64bd7c64d4eefe62d50f0 | /scheme/scheme-runtime/base.scm | 80c515eeb5cdd9f4aa95c296962018883725e870 | [
"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 | 27,560 | scm | base.scm | ;; base.scm -- standard pairs procedure as defined in rnrs, along with syntax !!!
;;; NUMERICAL
; (define-syntax +
; (syntax-rules ()
; (+ eta-+)
; ((+ a) a)
; ((+ a b) (+ a b))
; ((+ a b bs ...) (+ a (+ b bs ...)))))
; (define-syntax -
; (syntax-rules ()
; (- eta--)
; ((- a) (- 0 a))
; ((- a b) (- a b))))
; (define-syntax *
; (syntax-rules ()
; (* eta-*)
; ((* a b) (* a b))
; ((* a b bs ...) (* a (* b bs ...)))))
;;;
;; Predicate returning #t if the `obj` is a number
(define (number? obj) (%fixnum? obj))
;;;
;; Make a pair containing the two arguments `h` and `t`
(define (cons h t) (make-pair h t))
;;;
;; This fonction is the composition of `car` and `car`
(define (caar x) (car (car x)))
(define (cadr x) (car (cdr x)))
(define (cdar x) (cdr (car x)))
(define (cddr x) (cdr (cdr x)))
(define (caaar x) (car (car (car x))))
(define (caadr x) (car (car (cdr x))))
(define (cadar x) (car (cdr (car x))))
(define (caddr x) (car (cdr (cdr x))))
(define (cdaar x) (cdr (car (car x))))
(define (cdadr x) (cdr (car (cdr x))))
(define (cddar x) (cdr (cdr (car x))))
(define (cdddr x) (cdr (cdr (cdr x))))
(define (caaaar x) (car (car (car (car x)))))
(define (caaadr x) (car (car (car (cdr x)))))
(define (caadar x) (car (car (cdr (car x)))))
(define (caaddr x) (car (car (cdr (cdr x)))))
(define (cadaar x) (car (cdr (car (car x)))))
(define (cadadr x) (car (cdr (car (cdr x)))))
(define (caddar x) (car (cdr (cdr (car x)))))
(define (cadddr x) (car (cdr (cdr (cdr x)))))
(define (cdaaar x) (cdr (car (car (car x)))))
(define (cdaadr x) (cdr (car (car (cdr x)))))
(define (cdadar x) (cdr (car (cdr (car x)))))
(define (cdaddr x) (cdr (car (cdr (cdr x)))))
(define (cddaar x) (cdr (cdr (car (car x)))))
(define (cddadr x) (cdr (cdr (car (cdr x)))))
(define (cdddar x) (cdr (cdr (cdr (car x)))))
(define (cddddr x) (cdr (cdr (cdr (cdr x)))))
;;;
;; List predicate returning #t if `l` is a proper list, i.e does not
;; contain cycle and is terminated by `'()`
(define (list? l)
(let loop ((slow l)
(fast l))
(if (null? fast)
#t
(and (pair? fast)
(if (null? (cdr fast))
#t
(and (pair? (cdr fast))
(not (eq? slow (cdr fast)))
(loop (cdr slow) (cddr fast))))))))
;;;
;; Constructs a list of all the arguments of the procedure.
(define (list . l) l)
;;;
;; Computes the length of `l`. Note that it works only on proper list
(define (length l)
(if (null? l)
0
(+ 1 (length (cdr l)))))
;;;
;; Append all the lists (arguments) into one big list. Note that it
;; only works if the lists are proper, otherwise this procedure never
;; returns.
(define (append . l)
(if (null? l)
l
(let loop ((l l))
(if (null? (cdr l))
(car l)
(let loop2 ((l2 (car l)))
(if (null? l2)
(loop (cdr l))
(cons (car l2) (loop2 (cdr l2)))))))))
;;;
;; Reverse the list `l`, i.e returns a list whose elements are the
;; same as the one from `l` but in reverse order.
(define (reverse l)
(let loop ((l l)
(rest '()))
(if (null? l)
rest
(loop (cdr l) (cons (car l) rest)))))
;;;
;; Return the `k` pair of the list `l`. Note that this only works if
;; the length of `l` ist bigger than `k`. Otherwise a
;; `primitive-error` is raised.
(define (list-tail l k)
(if (zero? k)
l
(list-tail (cdr l) (- k 1))))
;;;
;; Return the `k` element of the list `l`. The indexes start from
;; 0. Note that this only works if the length of the list is at least
;; `k`. Otherwise a `primitive-error` is raised.
(define (list-ref l k)
(if (zero? k)
(car l)
(list-ref (cdr l) (- k 1))))
;;;
;; Return the pair whose car-cell is equal, in the meaning of `eq?`,
;; to `obj` if `obj` is a member of the list. Otherwise #f is
;; returned.
(define (memq obj l)
(if (null? l)
#f
(if (eq? obj (car l))
l
(memq obj (cdr l)))))
;;;
;; Return the pair whose car-cell is equal, in the meaning of `eqv?`,
;; to `obj` if `obj` is a member of the list. Otherwise #f is
;; returned.
(define (memv obj l)
(if (null? l)
#f
(if (eqv? obj (car l))
l
(memv obj (cdr l)))))
;;;
;; Return the pair whose car-cell is equal, in the meaning of `equal?`,
;; to `obj` if `obj` is a member of the list. Otherwise #f is
;; returned.
(define (member obj l)
(if (null? l)
#f
(if (equal? obj (car l))
l
(member obj (cdr l)))))
;; (define (assq obj alist)
;; (if (null? alist)
;; #f
;; (if (eq? obj (car (car alist)))
;; (car alist)
;; (assq obj (cdr alist)))))
;;;
;; Given an association list, returns the entry whose key is equal to
;; `obj`, equal in the sense of `eq?`.
(define (assq obj alist)
(%assq obj alist))
;;;
;; Given an association list, returns the entry whose key is equal to
;; `obj`, equal in the sense of `eqv?`.
(define (assv obj alist)
(if (null? alist)
#f
(if (eqv? obj (car (car alist)))
(car alist)
(assv obj (cdr alist)))))
;;;
;; Given an association list, returns the entry whose key is equal to
;; `obj`, equal in the sense of `equal?`.
(define (assoc obj alist)
(if (null? alist)
#f
(if (equal? obj (car (car alist)))
(car alist)
(assoc obj (cdr alist)))))
;;;
;; == String procedures
;;
;; Strings are basically a sequence of characters indexed by numbers
;; starting at 0.
;;;
;; Constructs a string of length `k` containing only the characters
;; `char`. If `char` is not given, it defaults to the `#\space`
;; character.
(define (make-string k . char)
(if (null? char)
(make-string k #\space)
(if (char? (car char))
(make-string k (car char))
(error "make-string: initializer is not a char"))))
;;;
;; Constructs a string whose characters are `chars`.
(define (string . chars)
(list->string chars))
;;;
;; Return if the two strings `string1` and `string2` contains the same
;; sequence of characters. If any of the argument `string1` or
;; `string2` are not strings, a `primitive-error` is signalled.
(define (string=? string1 string2)
(let ((length1 (string-length string1))
(length2 (string-length string2)))
(if (= length1 length2)
(let check ((i 0))
(if (= i length1)
#t
(if (char=? (string-ref string1 i)
(string-ref string2 i))
(check (+ i 1))
#f)))
#f)))
;;;
;; Return if the two strings `string1` and `string2` contains the same
;; sequence of characters without regards to case sensitivity. If any
;; of the argument `string1` or `string2` are not strings, a
;; `primitive-error` is signalled.
(define (string-ci=? string1 string2)
(let ((length1 (string-length string1))
(length2 (string-length string2)))
(if (= length1 length2)
(let check ((i 0))
(if (= i length1)
#t
(if (char-ci=? (string-ref string1 i)
(string-ref string2 i))
(check (+ i 1))
#f)))
#f)))
;;;
;; Return if `string1` is lexically smaller than `string2`. If any of
;; the argument `string1` or `string2` are not strings, a
;; `primitive-error` is signalled.
(define (string<? string1 string2)
(let ((length1 (string-length string1))
(length2 (string-length string2)))
(let check ((i 0))
(cond ((and (= i length1) (= i length2)) #f)
((= i length1) #t)
((= i length2) #f)
(else
(if (char=? (string-ref string1 i)
(string-ref string2 i))
(check (+ i 1))
(char<? (string-ref string1 i)
(string-ref string2 i))))))))
;;;
;; Return if `string1` is lexically greater than `string2`. If any of
;; the argument `string1` or `string2` are not strings, a
;; `primitive-error` is signalled.
(define (string>? string1 string2)
(let ((length1 (string-length string1))
(length2 (string-length string2)))
(let check ((i 0))
(cond ((and (= i length1) (= i length2)) #f)
((= i length1) #f)
((= i length2) #t)
(else
(if (char=? (string-ref string1 i)
(string-ref string2 i))
(check (+ i 1))
(char>? (string-ref string1 i)
(string-ref string2 i))))))))
;;;
;; Return if `string1` is lexically smaller or equal to `string2`. If
;; any of the argument `string1` or `string2` are not strings, a
;; `primitive-error` is signalled.
(define (string<=? string1 string2)
(let ((length1 (string-length string1))
(length2 (string-length string2)))
(let check ((i 0))
(cond ((and (= i length1) (= i length2)) #t)
((= i length1) #t)
((= i length2) #f)
(else
(if (char=? (string-ref string1 i)
(string-ref string2 i))
(check (+ i 1))
(char<? (string-ref string1 i)
(string-ref string2 i))))))))
;;;
;; Return if `string1` is lexically greater or equal to `string2`. If
;; any of the argument `string1` or `string2` are not strings, a
;; `primitive-error` is signalled.
(define (string>=? string1 string2)
(let ((length1 (string-length string1))
(length2 (string-length string2)))
(let check ((i 0))
(cond ((and (= i length1) (= i length2)) #t)
((= i length1) #f)
((= i length2) #t)
(else
(if (char=? (string-ref string1 i)
(string-ref string2 i))
(check (+ i 1))
(char>? (string-ref string1 i)
(string-ref string2 i))))))))
;;;
;; Return if `string1` is lexically smaller than `string2` without
;; regards to the case of the character. If any of the argument
;; `string1` or `string2` are not strings, a `primitive-error` is
;; signalled.
(define (string-ci<? string1 string2)
(let ((length1 (string-length string1))
(length2 (string-length string2)))
(let check ((i 0))
(cond ((and (= i length1) (= i length2)) #f)
((= i length1) #t)
((= i length2) #f)
(else
(if (char-ci=? (string-ref string1 i)
(string-ref string2 i))
(check (+ i 1))
(char-ci<? (string-ref string1 i)
(string-ref string2 i))))))))
;;;
;; Return if `string1` is greater than `string2` without regards to
;; the case of the character. If any of the argument `string1` or
;; `string2` are not strings, a `primitive-error` is signalled.
(define (string-ci>? string1 string2)
(let ((length1 (string-length string1))
(length2 (string-length string2)))
(let check ((i 0))
(cond ((and (= i length1) (= i length2)) #f)
((= i length1) #f)
((= i length2) #t)
(else
(if (char-ci=? (string-ref string1 i)
(string-ref string2 i))
(check (+ i 1))
(char-ci>? (string-ref string1 i)
(string-ref string2 i))))))))
;;;
;; Return if `string1` is lexically smaller or equal to `string2`
;; without regards to the case of the character. If any of the
;; argument `string1` or `string2` are not strings, a
;; `primitive-error` is signalled.
(define (string-ci<=? string1 string2)
(let ((length1 (string-length string1))
(length2 (string-length string2)))
(let check ((i 0))
(cond ((and (= i length1) (= i length2)) #t)
((= i length1) #t)
((= i length2) #f)
(else
(if (char-ci=? (string-ref string1 i)
(string-ref string2 i))
(check (+ i 1))
(char-ci<? (string-ref string1 i)
(string-ref string2 i))))))))
;;;
;; Return if `string1` is lexically greater or equal to `string2`
;; without regards to the case of the character. If any of the
;; argument `string1` or `string2` are not strings, a
;; `primitive-error` is signalled.
(define (string-ci>=? string1 string2)
(let ((length1 (string-length string1))
(length2 (string-length string2)))
(let check ((i 0))
(cond ((and (= i length1) (= i length2)) #t)
((= i length1) #f)
((= i length2) #t)
(else
(if (char-ci=? (string-ref string1 i)
(string-ref string2 i))
(check (+ i 1))
(char-ci>? (string-ref string1 i)
(string-ref string2 i))))))))
;;;
;; computes the substring of `string` between the index `start` and
;; `end`. Note that `start` and `end` should already be ordered and
;; `string` should be a string.
(define (substring string start end)
(if (>= start 0)
(if (<= end (string-length string))
(let ((new-string (make-string (- end start) #\1)))
(let copy ((i start))
(if (< i end)
(begin
(string-set! new-string (- i start) (string-ref string i))
(copy (+ i 1)))
new-string)))
(error "SUBSTRING: END value longer than string" string start end))
(error "SUBSTRING: START value before the beginning" string start end)))
;;;
;; Convert the number is string representation and return the integer
;; having the same value. The base of the represenation can be
;; specified with the optional argument `base`. The default value is 10.
(define (string->number str . base)
(let* ((base (if (null? base) 10 (car base)))
(negative? (char=? #\- (string-ref str 0))))
(let loop ((i (if negative? 1 0))
(n 0))
(if (< i (string-length str))
(let ((c (string-ref str i)))
(if (char-numeric? c)
(loop (+ i 1) (+ (* base n)
(- (char->integer c) (char->integer #\0))))
n))
n))))
;;;
;; Return the concatenation of `strings`.
(define (string-append . strings)
(let ((length (let loop ((s strings))
(if (null? s)
0
(+ (string-length (car s))
(loop (cdr s)))))))
(if (= length 0)
(make-string 0 #\1)
(let ((new-string (make-string length #\1)))
(let loop ((current (car strings))
(rest (cdr strings))
(i 0)
(j 0)
(upto (string-length (car strings))))
(if (< i length)
(if (< j upto)
(begin
(string-set! new-string i (string-ref current j))
(loop current rest (+ i 1) (+ j 1) upto))
(loop (car rest)
(cdr rest) i 0
(string-length (car rest))))))
new-string))))
;;;
;; Return the list of the characters contained in `string`.
(define (string->list string)
(let ((length (string-length string)))
(let loop ((i 0))
(if (< i length)
(cons (string-ref string i)
(loop (+ i 1)))
'()))))
;;;
;; Return the string containing all the characters in the list `l` in
;; the same order. Note that a `primitive-error` is signalled if the
;; list is not made of characters.
(define (list->string l)
(let ((new-string (make-string (length l) #\1)))
(let loop ((l l)
(i 0))
(if (null? l)
new-string
(begin
(string-set! new-string i (car l))
(loop (cdr l) (+ i 1)))))))
;;;
;; Return a copy of the string `string` passed as argument.
(define (string-copy string)
(let ((length (string-length string)))
(let ((new-string (make-string length #\1)))
(let copy ((i 0))
(if (< i length)
(begin
(string-set! new-string i (string-ref string i))
(copy (+ i 1)))
new-string)))))
;;;
;; Fill `string` with the character `char`. Note that it is
;; destructive operation for `string`.
(define (string-fill! string char)
(let ((length (string-length string)))
(let fill ((i 0))
(if (< i length)
(begin
(string-set! string i char)
(fill (+ i 1)))))))
;;;
;; Convert the integer `number` to a string. If `number` is not a
;; number the string ##NaN is returned.
(define $digits "0123456789abcdefghijklmnopqrstuvwxyz")
(define (number->string number . base)
(let ((base (if (null? base)
10
(car base))))
(cond ((%fixnum? number)
(list->string
(let ((digits
(reverse
(let loop ((n (if (< number 0) (- 0 number) number)))
(if (< n base)
(list (string-ref $digits n))
(let ((this (string-ref $digits (modulo n base)))
(rest (loop (quotient n base))))
(cons this rest)))))))
(if (< number 0) (cons #\- digits) digits))))
((%real? number) (%real->string number))
(else (error "Bad argument ~a to NUMBER->STRING, expected a number")))))
;;;
;; == Character procedures
;;
;; Characters are taken from the ISO-8859-1 set of characters and are
;; coded on 8-bit.
;;;
;; Return #t if the characters `char1` and `char2` are the same.
(define (char=? char1 char2)
(and (char? char1)
(char? char2)
(eq? char1 char2)))
;;;
;; Return #t if character `char1` is lexically smaller than
;; `char2`. If either `char1` or `char2` are not characters, a
;; `primitive-error` is signalled.
(define (char<? char1 char2)
(< (char->integer char1) (char->integer char2)))
;;;
;; Return #t if character `char1` is lexically greater than
;; `char2`. If either `char1` or `char2` are not characters, a
;; `primitive-error` is signalled.
(define (char>? char1 char2)
(> (char->integer char1) (char->integer char2)))
;;;
;; Return #t if character `char1` is lexically smaller or equal to
;; `char2`. If either `char1` or `char2` are not characters, a
;; `primitive-error` is signalled.
(define (char<=? char1 char2)
(<= (char->integer char1) (char->integer char2)))
;;;
;; Return #t if character `char1` is lexically greater or equal to
;; `char2`. If either `char1` or `char2` are not characters, a
;; `primitive-error` is signalled.
(define (char>=? char1 char2)
(>= (char->integer char1) (char->integer char2)))
;;;
;; Return #t if character `char1` and `char2` are the same without
;; regards to their case. If either `char1` or `char2` are not
;; characters, a `primitive-error` is signalled.
(define (char-ci=? char1 char2)
(char=? (char-downcase char1)
(char-downcase char2)))
;;;
;; Return #t if character `char1` is lexically smaller than `char2`
;; without regards to their case. If either `char1` or `char2` are not
;; characters, a `primitive-error` is signalled.
(define (char-ci<? char1 char2)
(char<? (char-downcase char1)
(char-downcase char2)))
;;;
;; Return #t if character `char1` is lexically greater than `char2`
;; without regards to their case. If either `char1` or `char2` are not
;; characters, a `primitive-error` is signalled.
(define (char-ci>? char1 char2)
(char>? (char-downcase char1)
(char-downcase char2)))
;;;
;; Return #t if character `char1` is lexically smaller or equal to
;; `char2` without regards to their case. If either `char1` or `char2`
;; are not characters, a `primitive-error` is signalled.
(define (char-ci<=? char1 char2)
(char<=? (char-downcase char1)
(char-downcase char2)))
;;;
;; Return #t if character `char1` is lexically greater or equal to
;; `char2` without regards to their case. If either `char1` or `char2`
;; are not characters, a `primitive-error` is signalled.
(define (char-ci>=? char1 char2)
(char>=? (char-downcase char1)
(char-downcase char2)))
;;;
;; Return #t if `char` is an alphabetical character that is in the
;; range #\a to #\z or the range #\A to #\Z. If `char` is not a
;; character, #f is returned.
(define (char-alphabetic? char)
(and (char? char)
(or (and (char<=? #\a char)
(char<=? char #\z))
(and (char<=? #\A char)
(char<=? char #\Z)))))
;;;
;; Return #t if `char` is a numeric character that is in the range of
;; #\0 to #\9. If `char` is not a charater, #f is returned.
(define (char-numeric? char)
(and (char? char)
(char<=? #\0 char)
(char<=? char #\9)))
(define $tab (number->char 9))
(define $linefeed (number->char 10))
(define $vtab (number->char 11))
(define $formfeed (number->char 12))
(define $newline (number->char 13))
;;;
;; Return #t if `char` is a white space character. White space
;; characters are #\space, #\tab, #\linefeed, #\formfeed or
;; #\newline. Note that if `char` is not a character, a
;; `primitive-error` is signalled.
(define (char-whitespace? char)
(or (char=? char #\space)
(char=? char $tab)
(char=? char $linefeed)
(char=? char $formfeed)
(char=? char $newline)))
;;;
;; Return #t if `letter` is an upper case character, that is in the
;; range #\A to #\Z. If `letter` is not a character, a
;; `primitive-error` is signalled.
(define (char-upper-case? letter)
(and (char<=? #\A letter)
(char<=? letter #\Z)))
;;;
;; Return #t if `letter` is an upper case character, that is in the
;; range #\a to #\z. If `letter` is not a character, a
;; `primitive-error` is signalled.
(define (char-lower-case? letter)
(and (char<=? #\a letter)
(char<=? letter #\z)))
;;;
;; Return the character code of `char` in the ISO-8859-1 encoding.
(define (char->integer char)
(char->number char))
;;;
;; Return the character associated with the character code `n` in the
;; ISO-8859-1 encoding.
(define (integer->char n)
(number->char n))
;;;
;; Return the the upper case character of `char` if it is a lower case
;; letter. Otherwise return `char`.
(define (char-upcase char)
(if (char-lower-case? char)
(let ((delta (- (char->integer #\A) (char->integer #\a))))
(integer->char (+ delta (char->integer char))))
char))
;;;
;; Return the the lower case character of `char` if it is an upper case
;; letter. Otherwise return `char`.
(define (char-downcase char)
(if (char-upper-case? char)
(let ((delta (- (char->integer #\a) (char->integer #\A))))
(integer->char (+ delta (char->integer char))))
char))
;;;
;; The equivalent predicate `eqv?`
(define eqv?
(lambda (o1 o2)
(eq? o1 o2)))
;;;
;; Return if `x` and `y` are equal structurally speaking.
(define (equal? x y)
(cond
((eqv? x y) #t)
((pair? x) (and (pair? y) (equal? (car x) (car y)) (equal? (cdr x) (cdr y))))
((string? x) (and (string? y) (string=? x y)))
((vector? x)
(and (vector? y)
(= (vector-length x) (vector-length y))
(let loop ((i (- (vector-length x) 1)))
(if (< i 0)
#t
(and (equal? (vector-ref x i) (vector-ref y i))
(loop (- i 1)))))))
((bvec? x)
(and (bvec? y) (= x y)))
(else #f)))
;;;
;; Return the boolean complement of `obj`.
(define (not obj)
(if obj #f #t))
;;;
;; Return #t if `obj` is a boolean value, that is either #t or #f.
(define (boolean? obj)
(or (eq? obj #t)
(eq? obj #f)))
;(define (apply proc . args)
; (declare (primitive apply))
; (apply proc args)
;(define (all-car . l)
; (let loop ((l l))
; (if (null? l)
; '()
; (cons (caar l) (loop (cdr l))))))
;(define (all-cdr . l)
; (let loop ((l l))
; (if (null? l)
; '()
; (cons (cdar l) (loop (cdr l))))))
;(define (map proc . lists)
; (let loop ((lists lists))
; (if (null? (car lists))
; '()
; (cons (apply proc (all-car lists))
; (loop (all-cdr lists))))))
;;;
;; Constucts the list whose elements are composed of the application of the
;; procedure `proc` to the elements of `l`.
(define (map proc l)
(if (null? l)
l
(cons (proc (car l)) (map proc (cdr l)))))
;(define (for-each proc . lists)
; (let loop ((lists lists))
; (if (null? (car lists))
; '()
; (begin
; (apply proc (all-car lists))
; (loop (all-cdr lists))))))
;;;
;; Calls the procedure `proc` to each of the element of `l` in their
;; order of appearence in `l`.
(define (for-each proc l)
(if (null? l)
'done
(begin
(proc (car l))
(for-each proc (cdr l)))))
;(define (force promise)
; #f)
;(define (call-with-current-continuation proc)
; #f)
;;;
;; == Vector procedures
;;
;; Vectors are a sequence of objects indexed by integer starting from
;; 0. Note that the elements are accessed in O(1) time.
;;;
;; Return the vector containing all the `objs` elements.
(define (vector . objs)
(list->vector objs))
;;;
;; Compute the list containing the same elements of `vector` in the
;; same order.
(define (vector->list vector)
(let ((length (vector-length vector)))
(let loop ((i 0))
(if (< i length)
(cons (vector-ref vector i)
(loop (+ i 1)))
'()))))
;;;
;; Compute the vector containing the same elements of `l` in the same
;; order.
(define (list->vector l)
(let ((new-vector (make-vector (length l) 1)))
(let loop ((i 0)
(l l))
(if (null? l)
new-vector
(begin
(vector-set! new-vector i (car l))
(loop (+ i 1) (cdr l)))))))
;;;
;; Fill the vector `vector` with the element `fill`.
(define (vector-fill! vector fill)
(let ((length (vector-length vector)))
(let fill ((i 0))
(if (< i length)
(begin
(vector-set! vector i fill)
(fill (+ i 1)))))))
;;;
;; == Specific predefined values
;;;
;; Return the unbound object.
(define (unbound-object) 'the-unbound-object)
;;;
;; Return #t if `o` is the unbound object.
(define (unbound-object? o) (eq? o (unbound-object)))
;;;
;; Return the unspecific object.
(define (unspecific-object) 'the-unspecific-object)
;;;
;; Return #t if `o` is the unspecific object.
(define (unspecific-object? o) (eq? o (unspecific-object)))
;;;
;; == Environment procedures
;;;
;; Return an environment compatible with the revision `n` of the Scheme
;; report.
(define (rnrs-environment n)
(if (= n 5)
(lookup-module 'scheme-runtime)
(error "RnRS ~a environment does not exists" n)))
(define *eval* (lambda (exp env) (error "Eval not available")))
;;;
;; Evaluates the Scheme expression according to the environment `env`.
(define (eval exp env)
(with-current-module env
(lambda () (*eval* exp env))))
;;;
;; Sets `proc` as the evaluation procedure to use. `proc` should be a
;; procedure of two arguments. The first is the expression that should
;; be evaluated. The second is the environment in which to evaluate
;; the expression.
(define (set-eval-procedure proc)
(set! *eval* proc))
(define *source-location* #f)
(define (current-source-location) *source-location*)
(define (with-source-location location thunk)
(let ((old *source-location*))
(set! *source-location* location)
(let ((value (thunk)))
(set! *source-location* old)
value)))
| true |
7dc94d05fdb36f6fec2d355c0c99b728378d7595 | ac2a3544b88444eabf12b68a9bce08941cd62581 | /contrib/GambitREPL/help#.scm | adc9477ffcb75dba8c44a1a33baef641b4af5716 | [
"Apache-2.0",
"LGPL-2.1-only"
]
| permissive | tomelam/gambit | 2fd664cf6ea68859d4549fdda62d31a25b2d6c6f | d60fdeb136b2ed89b75da5bfa8011aa334b29020 | refs/heads/master | 2020-11-27T06:39:26.718179 | 2019-12-15T16:56:31 | 2019-12-15T16:56:31 | 229,341,552 | 1 | 0 | Apache-2.0 | 2019-12-20T21:52:26 | 2019-12-20T21:52:26 | null | UTF-8 | Scheme | false | false | 413 | scm | help#.scm | ;;;============================================================================
;;; File: "help#.scm"
;;; Copyright (c) 2011 by Marc Feeley, All Rights Reserved.
;;;============================================================================
(##namespace ("help#"
main-help-document
r5rs-help-document
gambit-help-document
))
;;;============================================================================
| false |
8a8b56e7a30bf4a53cd4690ff695527549ec7955 | 6f86602ac19983fcdfcb2710de6e95b60bfb0e02 | /exercises/practice/difference-of-squares/test.scm | f99b159eab4e8c0dbb87a9abb7e90a42ec684db4 | [
"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 | 775 | scm | test.scm | (load "test-util.ss")
(define test-cases
`((test-success "square of sum 1" = square-of-sum '(1) 1) (test-success "square of sum 5" = square-of-sum '(5) 225)
(test-success "square of sum 100" = square-of-sum '(100)
25502500)
(test-success "sum of squares 1" = sum-of-squares '(1) 1)
(test-success "sum of squares 5" = sum-of-squares '(5) 55)
(test-success "sum of squares 100" = sum-of-squares '(100)
338350)
(test-success "difference of squares 1" =
difference-of-squares '(1) 0)
(test-success "difference of squares 5" =
difference-of-squares '(5) 170)
(test-success "difference of squares 100" =
difference-of-squares '(100) 25164150)))
(run-with-cli "difference-of-squares.scm" (list test-cases))
| false |
c01ac3b3875d8a101454fbb65013eb315eb7c2d1 | b0c1935baa1e3a0b29d1ff52a4676cda482d790e | /tests/libs/pattern-match-lambda.sld | c85810e5636ca3fc6b7adde6ddf5252b53ead161 | [
"MIT"
]
| permissive | justinethier/husk-scheme | 35ceb8f763a10fbf986340cb9b641cfb7c110509 | 1bf5880b2686731e0870e82eb60529a8dadfead1 | refs/heads/master | 2023-08-23T14:45:42.338605 | 2023-05-17T00:30:56 | 2023-05-17T00:30:56 | 687,620 | 239 | 28 | MIT | 2023-05-17T00:30:07 | 2010-05-26T17:02:56 | Haskell | UTF-8 | Scheme | false | false | 5,100 | sld | pattern-match-lambda.sld | (define-library (libs pattern-match-lambda)
(export pattern-match-lambda)
;TODO: should not need this, but seems to break unit tests without it: (export-all) ; pattern-match-lambda)
(import (scheme base))
(begin
(define-syntax if-identifier
(syntax-rules ()
((_ condition seq alt)
(let-syntax ((foo (syntax-rules () ((_) seq))))
(let-syntax ((test (syntax-rules ()
((_ condition) (foo))
((_ foo) alt))))
(test foo))))))
(define-syntax if-literal
(syntax-rules ()
((_ p (literals ...) seq alt)
(let-syntax ((bar (syntax-rules () ((_) seq))))
(let-syntax ((foo (syntax-rules (literals ...)
((_ literals) (bar)) ...
((_ bar) alt))))
(foo p))))))
(define-syntax if-placeholder
(syntax-rules (_) ;; Literals cannot include underbar in R6RS.
((_ _ seq alt) seq)
((_ p seq alt) alt)))
(define-syntax %if-match-vector
(syntax-rules ()
((_ (literals ...) #() ind e seq alt) seq)
((_ (literals ...) #(p r ...) ind e seq alt)
(%if-match (literals ...) p (vector-ref e ind)
(let ((i ind))
(%if-match-vector (literals ...) #(r ...) (+ i 1) e seq alt))
alt))))
(define-syntax %if-match
(syntax-rules ()
((_ (literals ...) #(p ...) e seq alt)
(if (and (vector? e) (= (vector-length '#(p ...)) (vector-length e)))
(%if-match-vector (literals ...) #(p ...) 0 e seq alt)
(alt)))
((_ (literals ...) (p . r) e seq alt)
(let ((temp e))
(if (pair? temp)
(%if-match (literals ...) p (car temp)
(%if-match (literals ...) r (cdr temp) seq alt)
alt)
(alt))))
((_ (literals ...) () e seq alt)
(if (null? e) seq (alt)))
((_ (literals ...) p e seq alt)
(if-identifier p
(if-literal p (literals ...)
(if (equal? 'p e) seq (alt))
(if-placeholder p
seq
(let ((p e)) seq)))
(if (equal? p e) seq (alt))))))
(define-syntax %duplicate-check
(syntax-rules ()
((_) #f)
((_ p r ...)
(letrec-syntax
((bar (syntax-rules ()
((_) (syntax-error "duplicate pattern variable in pattern-match-lambda" p ))))
(foo (syntax-rules (r ...)
((_ r) (bar))
...
((_ x) (%duplicate-check r ...)))))
;JAE - broken in husk (non-standard?): ((_ x) (syntax-rules () ((_) (%duplicate-check r ...)))))))
(foo p)))))
(define-syntax duplicate-check
(syntax-rules ()
((_ (pvar ...) (literals ...) #(p ...))
(duplicate-check (pvar ...) (literals ...) (p ...)))
((_ (pvar ...) (literals ...) ((p) . r))
(duplicate-check (pvar ...) (literals ...) (p . r)))
((_ (pvar ...) (literals ...) ((p0 . p1) . r))
(duplicate-check (pvar ...) (literals ...) (p0 p1 . r)))
((_ (pvar ...) (literals ...) (#(p ...) . r))
(duplicate-check (pvar ...) (literals ...) (p ... . r)))
((_ (pvar ...) (literals ...) (p . r))
(if-identifier p
(if-literal p (literals ...)
(duplicate-check (pvar ...) (literals ...) r)
(if-placeholder p
(duplicate-check (pvar ...) (literals ...) r)
(duplicate-check (pvar ... p) (literals ...) r)))
(duplicate-check (pvar ...) (literals ...) r)))
((_ (pvar ...) (literals ...) ())
(%duplicate-check pvar ...))
((_ (pvar ...) (literals ...) p)
(if-identifier p
(if-literal p (literals ...)
(duplicate-check (pvar ...) (literals ...) ())
(if-placeholder p
(duplicate-check (pvar ...) (literals ...) ())
(duplicate-check (pvar ... p) (literals ...) ())))
(duplicate-check (pvar ...) (literals ...) ())))))
(define-syntax if-match
(syntax-rules ()
((_ (literals ...) pattern lst seq alt)
(let ((alt-thunk (lambda() alt)))
(begin (duplicate-check () (literals ...) pattern)
(%if-match (literals ...) pattern lst seq alt-thunk))))))
(define-syntax %pattern-match-lambda
(syntax-rules (else)
((_ (literals ...) lst) (if #f #t))
((_ (literals ...) lst (else expr))
expr)
((_ (literals ...) lst (pattern expr) (rest-pattern rest-expr) ...)
(if-match (literals ...) pattern lst
expr
(%pattern-match-lambda (literals ...) lst
(rest-pattern rest-expr) ...)))
((_ (literals ...) lst (pattern fender expr) (rest-pattern rest-expr) ...)
(let ((next
(lambda() (%pattern-match-lambda (literals ...) lst
(rest-pattern rest-expr) ...))))
(if-match (literals ...) pattern lst
(if fender expr (next))
(next))))))
(define-syntax pattern-match-lambda
(syntax-rules ()
((_ (literals ...) clause ...)
(lambda lst
(%pattern-match-lambda (literals ...) lst clause ...)))))
))
| true |
ff390b51326f18d8f72a466ed9bd2fe7b56d27a7 | abc7bd420c9cc4dba4512b382baad54ba4d07aa8 | /src/ws/passes/normalize_query/lift-letrec.sls | c83e2e8c547d9fbd034b1842757ec903fbaeca90 | [
"BSD-3-Clause"
]
| permissive | rrnewton/WaveScript | 2f008f76bf63707761b9f7c95a68bd3e6b9c32ca | 1c9eff60970aefd2177d53723383b533ce370a6e | refs/heads/master | 2021-01-19T05:53:23.252626 | 2014-10-08T15:00:41 | 2014-10-08T15:00:41 | 1,297,872 | 10 | 2 | null | null | null | null | UTF-8 | Scheme | false | false | 4,024 | sls | lift-letrec.sls | #!r6rs
;;;; .title Lift letrec
;;;; [2004.04.24] RESURECTED: Now this pass serves a different
;;;; function. Convert closure hasn't been run (lambda's may still
;;;; have free-vars) so it just sucks all those letrec bindings up
;;;; to the top of the local lambda *but no further*. <br><br>
;;;; [2006.02.18] Update. <br>
;;;; This pass now sucks letrec bindings as far upward as their
;;;; free-vars will allow.
;;;; <br><br>
;;;; ALSO: <br>
;;;; The pass outputs *lazy-letrec* instead of letrec, because now
;;;; things have been scrambled and the lazy semantics of my language
;;;; can no longer be ignored. (Other passes should have this
;;;; too.. I'm just being really, umm, lazy right now, as my test
;;;; programs don't depend on argument evaluation model... ) <br>
;;;; Output Language <br><br>
;;; OLD OLD OLD:
;;; <Pgm> ::= (<language-name> (quote (program <Let>))) <br>
;;; <Let> ::= (lazy-letrec (<Decl>*) <Exp>) <br>
;;; <Decl> ::= (<var> <Exp>) <br>
;;; <Exp> ::= <br>
;;; (quote <imm>) <br>
;;; | <var> <br>
;;; | (if <Exp> <Exp> <Exp>) <br>
;;; | (lambda <Formalexp> <Let>) <br>
;;; | (<primitive> <Exp>*) <br>
;;; <Formalexp> ::= (<var>*) <br>
(library (ws passes normalize_query lift-letrec)
(export lift-letrec)
(import (except (rnrs (6)) error) (ws common)
)
;(define lift-letrec-grammar ...)
;; NOTE: DEPENDS ON LAZINESS.
;; WILL LIFT AN EXPRESSION OUT OF A CONDITIONAL!
(define lift-letrec
(let ()
;; .returns expression & bindings
(define process-expr
(lambda (expr)
(match expr
[(quote ,imm) (values `(quote ,imm) '())]
[,var (guard (symbol? var)) (values var '())]
[(if ,[test test-decl*] ,[conseq conseq-decl*] ,[altern altern-decl*])
(values
`(if ,test ,conseq ,altern)
(append test-decl* conseq-decl* altern-decl*))]
[(tuple ,[args args-decls] ...)
(values `(tuple ,args ...)
(apply append args-decls))]
[(tupref ,n ,m ,[x decls]) (values `(tupref ,n ,m ,x) decls)]
[(lambda ,formalexp ,types (free ,free ,[body body-decl]))
; (if (not (null? (difference free formalexp)))
; (error 'lift-letrec "free was supposed to be null for now! ~a" free))
;; This version lifts to the top of each lambda:
(values `(lambda ,formalexp ,types (lazy-letrec ,body-decl ,body)) '())
;; This version lifts all the way to the top.
;(values `(lambda ,formalexp ,types (lazy-letrec () ,body)) body-decl)
]
[(free ,_ ,[e decls]) (values e decls)]
[(begin ,[e* decls*] ...) (values `(begin ,e* ...) (apply append decls*))]
[(for (,i ,[s sdecl] ,[e edecl]) ,[bod bdecl])
(values `(for (,i ,s ,e) ,bod) (append sdecl edecl bdecl))]
[(set! ,v ,[e decls]) (values `(set! ,v ,e) decls)]
[(letrec ([,lhs* ,type* ,[rhs* rhs-decl*]] ...) ,[body body-decl])
(values body
(append (apply append rhs-decl*)
(map list lhs* type* rhs*)
body-decl))]
[(,prim ,[rand* rand-decl*] ...)
(guard (regiment-primitive? prim))
(values
`(,prim ,rand* ...)
(apply append rand-decl*))]
[,unmatched
(error 'lift-letrec "invalid expression: ~s"
unmatched)])))
(lambda (prog)
(match prog
[(,input-language (quote (program ,body ,meta* ... ,type)))
(mvlet ([(body body-fn) (process-expr body)])
`(lift-letrec-language
'(program (lazy-letrec ,body-fn ,body) ,meta* ... ,type)
))]))
))
) ; End module
| false |
f1bb14d504e5062808d316322d917f9ca4b258e2 | 6bd63be924173b3cf53a903f182e50a1150b60a8 | /chapter_1/1.40.scm | 0af1c97e2148d4342eb59d677e96e67273062c48 | []
| 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 | 628 | scm | 1.40.scm | ; 1.40
(define (fixed-point f first-guess)
(display first-guess) ; update here
(newline) ; and there
(define (close-enough? a b)
(< (abs (- a b)) 0.0001))
(if (close-enough? (f first-guess) first-guess)
first-guess
(fixed-point f (f first-guess))))
(define (deriv g)
(lambda (x) (/ (- (g (+ x dx)) (g x)) dx)))
(define dx 0.00001)
(define (newtons-transform g)
(lambda (x) (- x (/ (g x) ((deriv g) x)))))
(define (newtons-method g guess)
(fixed-point (newtons-transform g) guess))
(define (cubic a b c)
(lambda (x) (+ (* x x x) (* a x x) (* b x) c)))
| false |
f32d60f3de481f4b2ec69dbe39cc14612f05a4b6 | bf1c9803ae38f9aad027fbe4569ccc6f85ba63ab | /chapter_2/2.2.Hierarchical.Data.and.the.Closure.Property/ex_2.32.scm | 169f7259840f95043cf43592bfc978c2262635d9 | []
| 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 | 680 | scm | ex_2.32.scm | #lang sicp
(define (subsets s)
;; The function assumes that it's being passed a set
(if (null? s)
(list nil) ;; when given just one element we need to append the empty list
(let ((rest (subsets (cdr s))))
;; append bubbles up a one list structure rather than a nested one
;; the set of all sets is
;; - the set of all subsets excluding the first number
;; - the set of all subsets excluding the first number with the first number inserted
(append rest (map ( ;; concatenate the first element of the list
lambda (x) (cons (car s) x)
) rest)))))
(subsets (list 1 2 3)) | false |
3578b732e1b76155dda7b67c2c271900af9d2af5 | 7aeb920de21547a1d9c714b029bbf3a9e7df449e | /scheme/documentation/module/generic.scm | c84a74bac2cd26ac84e9f5a87d6eb50dc77f9562 | [
"BSD-2-Clause"
]
| permissive | ft/chip-remote | f8ac5a2d7597d24f44ac287836be3422a32283d4 | 2a64df611214f7e3eb55d4ead76e270351158cdb | refs/heads/master | 2023-04-30T08:38:16.483240 | 2023-01-05T04:01:44 | 2023-01-05T04:01:44 | 117,028,633 | 2 | 1 | null | null | null | null | UTF-8 | Scheme | false | false | 971 | scm | generic.scm | ;; Copyright (c) 2018-2021 chip-remote workers, All rights reserved.
;;
;; Terms for redistribution and use can be found in doc/LICENCE.
(define-module (documentation module generic)
#:use-module (ice-9 session)
#:use-module (documentation more)
#:export (expand-procedure
expand-macro
expand-integer))
(define (expand-procedure mod name value)
(list name 'procedure
(or (procedure-documentation value) 'undocumented)
(procedure-arguments value)
(procedure-minimum-arity value)))
(define (expand-macro mod name value)
(let ((tf (macro-transformer value))
(inlined (inlinable? mod name)))
(list name (if inlined 'procedure 'macro)
(or (procedure-documentation tf) 'undocumented)
(procedure-arguments (or inlined tf))
(procedure-minimum-arity (or inlined tf)))))
(define (expand-integer mod name value)
(list name 'integer
(variable-documentation mod name)))
| false |
3930686333e38f3d793764e32280539a36254b82 | 4b2aeafb5610b008009b9f4037d42c6e98f8ea73 | /2.1/section.scm | bd27f23bfe1c9f342a253c4e8f28d24460feea67 | []
| 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 | 147 | scm | section.scm | (require-extension
syntax-case
(srfi 1))
(module
section-2.1
(insertion-sort-general
insertion-sort)
(include "../2.1/insertion-sort.scm"))
| false |
e43d9a7d1b877c375fbbaf53c98f1196989de8c2 | 4b570eebce894b4373cba292f09883932834e543 | /ch2/backup/rational.scm~ | 016037db1093ecdbf404b175ca7ebf574fcab678 | []
| no_license | Pulkit12083/sicp | ffabc406c66019e5305ad701fbc022509319e4b1 | 8ea6c57d2b0be947026dd01513ded25991e5c94f | refs/heads/master | 2021-06-17T13:44:06.381879 | 2021-05-14T16:52:30 | 2021-05-14T16:52:30 | 197,695,022 | 0 | 0 | null | 2021-04-14T17:04:01 | 2019-07-19T03:25:41 | Scheme | UTF-8 | Scheme | false | false | 35 | rational.scm~ | (define (make-rat x y) (cons x y))
| false |
|
900c7291a238ed78956ee5caf0de4b6c0e3bf3c0 | 3508dcd12d0d69fec4d30c50334f8deb24f376eb | /v8/src/compiler/base/cfg1.scm | e83b3fafa5c608aedacc6f5c55fc85b7aaa320df | []
| no_license | barak/mit-scheme | be625081e92c2c74590f6b5502f5ae6bc95aa492 | 56e1a12439628e4424b8c3ce2a3118449db509ab | refs/heads/master | 2023-01-24T11:03:23.447076 | 2022-09-11T06:10:46 | 2022-09-11T06:10:46 | 12,487,054 | 12 | 1 | null | null | null | null | UTF-8 | Scheme | false | false | 5,238 | scm | cfg1.scm | #| -*-Scheme-*-
Copyright (c) 1987, 1989, 1999 Massachusetts Institute of Technology
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at
your option) any later version.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|#
;;;; Control Flow Graph Abstraction
(declare (usual-integrations))
;;;; Node Datatypes
(define cfg-node-tag (make-vector-tag false 'CFG-NODE false))
(define cfg-node? (tagged-vector/subclass-predicate cfg-node-tag))
(define-vector-slots node 1 generation alist previous-edges)
(set-vector-tag-description!
cfg-node-tag
(lambda (node)
(descriptor-list node generation alist previous-edges)))
(define snode-tag (make-vector-tag cfg-node-tag 'SNODE false))
(define snode? (tagged-vector/subclass-predicate snode-tag))
(define-vector-slots snode 4 next-edge)
;;; converted to a macro.
;;; (define (make-snode tag . extra)
;;; (list->vector (cons* tag false '() '() false extra)))
(set-vector-tag-description!
snode-tag
(lambda (snode)
(append! ((vector-tag-description (vector-tag-parent snode-tag)) snode)
(descriptor-list snode next-edge))))
(define pnode-tag (make-vector-tag cfg-node-tag 'PNODE false))
(define pnode? (tagged-vector/subclass-predicate pnode-tag))
(define-vector-slots pnode 4 consequent-edge alternative-edge)
;;; converted to a macro.
;;; (define (make-pnode tag . extra)
;;; (list->vector (cons* tag false '() '() false false extra)))
(set-vector-tag-description!
pnode-tag
(lambda (pnode)
(append! ((vector-tag-description (vector-tag-parent pnode-tag)) pnode)
(descriptor-list pnode consequent-edge alternative-edge))))
(define (add-node-previous-edge! node edge)
(set-node-previous-edges! node (cons edge (node-previous-edges node))))
(define (delete-node-previous-edge! node edge)
(set-node-previous-edges! node (delq! edge (node-previous-edges node))))
(define-integrable (snode-next snode)
(edge-next-node (snode-next-edge snode)))
(define-integrable (pnode-consequent pnode)
(edge-next-node (pnode-consequent-edge pnode)))
(define-integrable (pnode-alternative pnode)
(edge-next-node (pnode-alternative-edge pnode)))
(define (cfg-node-get node key)
(let ((entry (assq key (node-alist node))))
(and entry
(cdr entry))))
(define (cfg-node-put! node key item)
(let ((entry (assq key (node-alist node))))
(if entry
(set-cdr! entry item)
(set-node-alist! node (cons (cons key item) (node-alist node))))))
(define (cfg-node-remove! node key)
(set-node-alist! node (del-assq! key (node-alist node))))
;;;; Edge Datatype
(define-structure (edge (type vector))
left-node
left-connect
right-node)
(define (create-edge! left-node left-connect right-node)
(let ((edge (make-edge left-node left-connect right-node)))
(if left-node
(left-connect left-node edge))
(if right-node
(add-node-previous-edge! right-node edge))
edge))
(define-integrable (node->edge node)
(create-edge! false false node))
(define (edge-next-node edge)
(and edge (edge-right-node edge)))
(define (edge-connect-left! edge left-node left-connect)
(if (edge-left-node edge)
(error "Attempt to doubly connect left node of edge" edge))
(if left-node
(begin
(set-edge-left-node! edge left-node)
(set-edge-left-connect! edge left-connect)
(left-connect left-node edge))))
(define (edge-connect-right! edge right-node)
(if (edge-right-node edge)
(error "Attempt to doubly connect right node of edge" edge))
(if right-node
(begin
(set-edge-right-node! edge right-node)
(add-node-previous-edge! right-node edge))))
(define (edge-disconnect-left! edge)
(let ((left-node (edge-left-node edge))
(left-connect (edge-left-connect edge)))
(if left-node
(begin
(set-edge-left-node! edge false)
(set-edge-left-connect! edge false)
(left-connect left-node false)))))
(define (edge-disconnect-right! edge)
(let ((right-node (edge-right-node edge)))
(if right-node
(begin
(set-edge-right-node! edge false)
(delete-node-previous-edge! right-node edge)))))
(define (edge-disconnect! edge)
(edge-disconnect-left! edge)
(edge-disconnect-right! edge))
(define (edge-replace-left! edge left-node left-connect)
(edge-disconnect-left! edge)
(edge-connect-left! edge left-node left-connect))
(define (edge-replace-right! edge right-node)
(edge-disconnect-right! edge)
(edge-connect-right! edge right-node))
(define (edges-connect-right! edges right-node)
(for-each (lambda (edge) (edge-connect-right! edge right-node)) edges))
(define (edges-disconnect-right! edges)
(for-each edge-disconnect-right! edges))
(define (edges-replace-right! edges right-node)
(for-each (lambda (edge) (edge-replace-right! edge right-node)) edges)) | false |
52ffd20e09a3b100ba799a5e6b0e9277e3b5831e | 185024f40e1ceed452781a1f3f57e6d16f57d799 | /iteration-api.ss | 34b445d4fff545af884fea81bec8a1d9d5daa75c | []
| no_license | noelwelsh/numeric | b82cd4ca9e4afb18df0129ec2231fc03f9b66450 | ac4488cf8cc6f0558f74ca9b8faad0f198e76a84 | refs/heads/master | 2021-01-18T21:32:27.393991 | 2010-02-22T14:05:19 | 2010-02-22T14:05:19 | 275,898 | 1 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 1,037 | ss | iteration-api.ss | #lang scheme/base
(require "unet.ss")
(define-unet define-iterators
(import for/fold/vector
for/vector
in-vector
vector-length)
(export vector-map vector-mapi
vector-fold vector-foldi)
(define vector-map
(case-lambda
[(fn v)
(for/vector ([i (vector-length v)]
[x (in-vector v)])
(fn x))]
[(fn v1 v2)
(for/vector ([i (vector-length v1)]
[x1 (in-vector v1)]
[x2 (in-vector v2)])
(fn x1 x2))]))
(define (vector-mapi fn v)
(for/vector ([i (vector-length v)]
[x (in-vector v)])
(fn i x)))
(define (vector-fold fn seed v)
(for/fold ([seed seed])
([x (in-vector v)])
(fn x seed)))
(define (vector-foldi fn seed v)
(for/fold ([seed seed])
([i (in-range (vector-length v))]
[x (in-vector v)])
(fn i x seed))))
(provide define-iterators) | false |
70175f01ca22ea839d6f81fc8e8dd23e6f355993 | 86092887e6e28ebc92875339a38271319a87ea0d | /Ch3/3_32.scm | 85d06a684b149ac5948c90c37422dd6f32a35832 | []
| 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 | 409 | scm | 3_32.scm | ; evidently lifo != fifo
; since the 'actions' are SETs on the final wire value, we have
; the following:
; start with (0, 1)
; next step -> first wire goes to 1.
; 1&1 = 1, so put 1 into the agenda for t->and-delay
; step after that -> second wire goes to 0.
; we have 1&0 -> second wire goes to 0, so put 0 into the agenda for t->and-delay.
; if we do lifo, we will see 1.
; if we do fifo, we will see 0.
| false |
82282617dec84f923f32908ce1a276b1acdcade0 | ea4e27735dd34917b1cf62dc6d8c887059dd95a9 | /section2_2_exercise2_28.scm | 6acbdd190ca3594e8979e64f885b63be926cfb25 | [
"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 | 569 | scm | section2_2_exercise2_28.scm | (define (fringe tree)
(cond ((null? tree) nil)
((not (pair? tree)) (list tree))
(else (append (fringe (car tree))
(fringe (cdr tree))))))
(define x (list (list 1 2) (list 3 4)))
(fringe x)
(fringe (list x x))
(define animals (list "tiger" "wolf" "eagle"))
(define vegetables (list "tree" "grass" "flower"))
(define metals (list "iron" "gold" "silver"))
(define minerals (list "granite" "diamond" "coal"))
(define organics (list animals vegetables))
(define inorganics (list metals minerals))
(define things (list organics inorganics))
(fringe things)
| false |
083d44e94c21698e5920834b1e1c7dbf43824e5d | 4286dd0755b6083ddd06a0d610476b7b6fe62063 | /srfi-196.scm | 4513b62ac14e7f6138993873160736c0a1261530 | [
"MIT"
]
| permissive | diamond-lizard/srfi-196 | f4cf087553f818d0aa15e2c8b2f8f8a44bd33d03 | 1b3a88877d6103179cb16205299d30d383f28c82 | refs/heads/main | 2023-01-11T15:36:02.062469 | 2020-11-18T22:57:14 | 2020-11-18T22:57:14 | 311,495,561 | 0 | 1 | null | null | null | null | UTF-8 | Scheme | false | false | 1,432 | scm | srfi-196.scm | (module (srfi 196)
(range numeric-range vector-range string-range range-append
iota-range range? range=? range-length range-ref range-first
range-last subrange range-segment range-split-at range-take
range-take-right range-drop range-drop-right range-count
range-map->list range-for-each range-fold range-fold-right
range-any range-every range-filter->list range-remove->list
range-reverse range-map range-map->vector range-filter
range-remove range-filter-map range-filter-map->list
range-index range-index-right range-take-while
range-drop-while range-take-while-right
range-drop-while-right vector->range range->string
range->list range->generator range->vector)
(import (scheme)
(chicken base)
(only (srfi 1) reduce unfold xcons every concatenate)
(only (srfi 133) vector-copy string->vector)
(srfi 145))
(import (chicken platform))
(register-feature! 'srfi-196)
;; "seedless" unfold/tabulate.
(define (vector-unfold f len)
(let ((res (make-vector len)))
(let lp ((i 0))
(cond ((= i len) res)
(else (vector-set! res i (f i))
(lp (+ i 1)))))))
(define eof-object
(let ((*eof-object* (read (open-input-string ""))))
(lambda () *eof-object*)))
(define exact inexact->exact)
(include "srfi/196.scm"))
| false |
73b9cf787f85390cc616a6424023e6eb4945540d | 746e3020868df770371fe7aa6a4e3fca99c014f8 | /atcoder/practice1-2.scm | 5735cce2be8623d1fc97c9b5e73a282e45ea0461 | []
| no_license | hiy0ki/gauche-practice | 32c8586739c485e2b301f6c4fbe555ae8bfab20b | 3dbeab66cda405825149d14f057bf9bc60d3c27a | refs/heads/master | 2022-05-06T00:18:40.045511 | 2022-04-07T21:20:22 | 2022-04-07T21:20:22 | 133,526,619 | 0 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 100 | scm | practice1-2.scm | (let* ((a (read))
(b (read))
(c (read))
(s (read)))
(print (+ a b c) " " s))
| false |
598a4ee20ca8e65c32089dcfe4ee1821cc1cab1f | 6b961ef37ff7018c8449d3fa05c04ffbda56582b | /bbn_cl/mach/runtime/parse1.scm | 10390cf94d0435055fd158bf1248681f8a00f2b2 | []
| 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,034 | scm | parse1.scm | ;;; -*-Scheme-*-
;;;
;;;
;;; 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.
;;;
;;;; Scheme Parser
(declare (usual-integrations))
(define *parser-radix* #d10)
(define *parser-table*)
(define parser-package
(make-environment
))
;;;; Parser Tables
(define (parser-table-copy table)
(cons (cons (vector-copy (caar table))
(vector-copy (cdar table)))
(cons (vector-copy (cadr table))
(vector-copy (cddr table)))))
(define parser-table-entry)
(define set-parser-table-entry!)
(let ()
(define (decode-parser-char table char receiver)
(cond ((char? char)
(receiver (car table) (char->ascii char)))
((string? char)
(cond ((= (string-length char) 1)
(receiver (car table) (char->ascii (string-ref char 0))))
((and (= (string-length char) 2)
(char=? #\# (string-ref char 0)))
(receiver (cdr table) (char->ascii (string-ref char 1))))
(else
(error "Bad character" 'DECODE-PARSER-CHAR char))))
(else
(error "Bad character" 'DECODE-PARSER-CHAR char))))
(define (ptable-ref table index)
(cons (vector-ref (car table) index)
(vector-ref (cdr table) index)))
(define (ptable-set! table index value)
(vector-set! (car table) index (car value))
(vector-set! (cdr table) index (cdr value)))
(set! parser-table-entry
(named-lambda (parser-table-entry table char)
(decode-parser-char table char ptable-ref)))
(set! set-parser-table-entry!
(named-lambda (set-parser-table-entry! table char entry)
(decode-parser-char table char
(lambda (sub-table index)
(ptable-set! sub-table index entry)))))
)
| false |
3c7818c4afa7b911ff544b3077960abaedfdcfdc | defeada37d39bca09ef76f66f38683754c0a6aa0 | /System/system/component-model/design/serialization/context-stack.sls | 5daaffa34d0ee8f5bec6a7d89c79fe9e03864591 | []
| 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,407 | sls | context-stack.sls | (library (system component-model design serialization context-stack)
(export new is? context-stack? append push pop current item item)
(import (ironscheme-clr-port))
(define-syntax new
(lambda (e)
(syntax-case e ()
((_ a ...)
#'(clr-new
System.ComponentModel.Design.Serialization.ContextStack
a
...)))))
(define (is? a)
(clr-is System.ComponentModel.Design.Serialization.ContextStack a))
(define (context-stack? a)
(clr-is System.ComponentModel.Design.Serialization.ContextStack a))
(define-method-port
append
System.ComponentModel.Design.Serialization.ContextStack
Append
(System.Void System.Object))
(define-method-port
push
System.ComponentModel.Design.Serialization.ContextStack
Push
(System.Void System.Object))
(define-method-port
pop
System.ComponentModel.Design.Serialization.ContextStack
Pop
(System.Object))
(define-field-port
current
#f
#f
(property:)
System.ComponentModel.Design.Serialization.ContextStack
Current
System.Object)
(define-field-port
item
#f
#f
(property:)
System.ComponentModel.Design.Serialization.ContextStack
Item
System.Object)
(define-field-port
item
#f
#f
(property:)
System.ComponentModel.Design.Serialization.ContextStack
Item
System.Object))
| true |
6449c59e475f1c1b89026c984e37b19a2481a793 | 2bcf33718a53f5a938fd82bd0d484a423ff308d3 | /programming/sicp/ch1/ex-1.29.scm | 828eec69ff4650399e5c5637b5bd792261a7bfaf | []
| 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 | 873 | scm | ex-1.29.scm | ;; https://mitpress.mit.edu/sites/default/files/sicp/full-text/book/book-Z-H-12.html#%_thm_1.29
;; Sum of (f a) + (f (next a)) + ... + (f b)
(define (sum term a next b)
(if (> a b)
0
(+ (term a)
(sum term (next a) next b))))
;; Simpson's Rule: the integral of a function f between a and b is approximated
;; by:
;; (h/3(y_0 4y_1 + 2y_2 + 4y_3 + 2y_4 + ... + y_n)), where
;; h = (b-a)/n
;; y_k = f(a + kh)
;; n is an even integer
(define (simpsons-rule f a b n)
;; must use let* because y depends on the h defined in this let block
(let* ((h (/ (- b a) n))
(y (lambda (k) (f (+ a (* k h))))))
(define (term k)
(* (y k)
;; coefficient for y_k
(cond ((or (equal? k 0) (equal? k n)) 1)
((even? k) 2)
(else 4))))
(* h 1/3 (sum term 0 (lambda (x) (+ 1 x)) n))))
| false |
432fdc508fd5238208eee8fd144c3567d66c65b3 | 6b961ef37ff7018c8449d3fa05c04ffbda56582b | /bbn_cl/mach/zcomp/base/blocks.scm | 833c30d160509fb4a82ade05759091345500bd48 | []
| 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 | 9,007 | scm | blocks.scm | #| -*-Scheme-*-
$Header: blocks.scm,v 1.2 88/08/31 10:33:34 jinx Exp $
$MIT-Header: blocks.scm,v 4.2 87/12/30 06:57:42 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. |#
;;;; Environment model data structures
(declare (usual-integrations))
#|
Interpreter compatible (hereafter, IC) blocks are vectors with an
implementation dependent number of reserved slots at the beginning,
followed by the variable bindings for that frame, in the usual order.
The parent of such a frame is always an IC block or a global block,
but extracting a pointer to that parent from the frame is again
implementation dependent and possibly a complex operation. During the
execution of an IC procedure, the block pointer is kept in the ENV
register.
Perfect closure blocks are vectors whose slots contain the values for
the free variables in a closure procedure. The ordering of these
slots is arbitrary.
Imperfect closure blocks are similar, except that the first slot of
the vector points to the parent, which is always an IC block.
Stack blocks are contiguous regions of the stack. A stack block
pointer is the address of that portion of the block which is nearest
to the top of the stack (on the 68000, the most negative address in
the block.)
In closure and stack blocks, variables which the analyzer can
guarantee will not be modified have their values stored directly in
the block. For all other variables, the binding slot in the block
contains a pointer to a cell which contains the value.
Note that blocks of type CONTINUATION never have any children. This
is because the body of a continuation is always generated separately
from the continuation, and then "glued" into place afterwards.
|#
(define-rvalue block
type ;block type (see below)
parent ;lexically enclosing parent
children ;lexically enclosed children
disowned-children ;children whose `parent' used to be this block
frame-size ;for stack-allocated frames, size in words
procedure ;procedure for which this is invocation block, if any
bound-variables ;list of variables bound by this block
free-variables ;list of variables free in this block
declarations ;list of declarations
applications ;list of applications lexically within this block
interned-variables ;alist of interned SCode variable objects
closure-offsets ;for closure block, alist of bound variable offsets
frame ;debugging information (???)
stack-link ;for internal block, adjacent block on stack
)
(define *blocks*)
(define (make-block parent type)
(let ((block
(make-rvalue block-tag (enumeration/name->index block-types type)
parent '() '() false false '() '() '() '() '() '() false
false 'UNKNOWN)))
(if parent
(set-block-children! parent (cons block (block-children parent))))
(set! *blocks* (cons block *blocks*))
block))
(define-vector-tag-unparser block-tag
(lambda (block)
(write-string "BLOCK")
(let ((procedure (block-procedure block)))
(if (and procedure (rvalue/procedure? procedure))
(begin (write-string " ")
(write (procedure-label procedure)))))))
(define-integrable (rvalue/block? rvalue)
(eq? (tagged-vector/tag rvalue) block-tag))
(define (add-block-application! block application)
(set-block-applications! block
(cons application (block-applications block))))
(define (intern-scode-variable! block name)
(let ((entry (assq name (block-interned-variables block))))
(if entry
(cdr entry)
(let ((variable (scode/make-variable name)))
(set-block-interned-variables!
block
(cons (cons name variable) (block-interned-variables block)))
variable))))
(define block-passed-out?
rvalue-%passed-out?)
;;;; Block Type
(define-enumeration block-type
(closure ;heap-allocated closing frame, compiler format
continuation ;continuation invocation frame
expression ;execution frame for expression (indeterminate type)
ic ;interpreter compatible heap-allocated frame
procedure ;invocation frame for procedure (indeterminate type)
stack ;invocation frame for procedure, stack-allocated
))
(define-integrable (ic-block? block)
(eq? (block-type block) block-type/ic))
(define-integrable (closure-block? block)
(eq? (block-type block) block-type/closure))
(define-integrable (stack-block? block)
(eq? (block-type block) block-type/stack))
(define-integrable (continuation-block? block)
(eq? (block-type block) block-type/continuation))
(define (block/external? block)
(and (stack-block? block)
(not (stack-parent? block))))
(define (block/internal? block)
(and (stack-block? block)
(stack-parent? block)))
(define (stack-parent? block)
(and (block-parent block)
(stack-block? (block-parent block))))
(define-integrable (ic-block/use-lookup? block)
(or (rvalue/procedure? (block-procedure block))
(not compiler:cache-free-variables?)))
;;;; Block Inheritance
(define (block-ancestor-or-self? block block*)
(or (eq? block block*)
(block-ancestor? block block*)))
(define (block-ancestor? block block*)
(define (loop block)
(and block
(or (eq? block block*)
(loop (block-parent block)))))
(loop (block-parent block)))
(define-integrable (block-child? block block*)
(eq? block (block-parent block*)))
(define-integrable (block-sibling? block block*)
;; Assumes that at least one block has a parent.
(eq? (block-parent block) (block-parent block*)))
(define (block-nearest-common-ancestor block block*)
(let loop
((join false)
(ancestry (block-ancestry block '()))
(ancestry* (block-ancestry block* '())))
(if (and (not (null? ancestry))
(not (null? ancestry*))
(eq? (car ancestry) (car ancestry*)))
(loop (car ancestry) (cdr ancestry) (cdr ancestry*))
join)))
(define (block-farthest-uncommon-ancestor block block*)
(let loop
((ancestry (block-ancestry block '()))
(ancestry* (block-ancestry block* '())))
(and (not (null? ancestry))
(if (and (not (null? ancestry*))
(eq? (car ancestry) (car ancestry*)))
(loop (cdr ancestry) (cdr ancestry*))
(car ancestry)))))
(define (block-ancestry block path)
(if (block-parent block)
(block-ancestry (block-parent block) (cons block path))
(cons block path)))
(define (stack-block/external-ancestor block)
(let ((parent (block-parent block)))
(if (and parent (stack-block? parent))
(stack-block/external-ancestor parent)
block)))
(define (block/external-ancestor block)
(if (stack-block? block)
(stack-block/external-ancestor block)
block))
(define (stack-block/ancestor-distance block offset join)
(let loop ((block block) (n offset))
(if (eq? block join)
n
(loop (block-parent block)
(+ n (block-frame-size block))))))
(define (for-each-block-descendent! block procedure)
(let loop ((block block))
(procedure block)
(for-each loop (block-children block))))
(define-integrable (internal-block/parent-known? block)
(block-stack-link block))
(define (stack-block/static-link? block)
(and (block-parent block)
(or (not (stack-block? (block-parent block)))
(not (internal-block/parent-known? block)))))
(define-integrable (stack-block/continuation-lvalue block)
(procedure-continuation-lvalue (block-procedure block)))
(define (block/dynamic-link? block)
(and (stack-block? block)
(stack-block/dynamic-link? block)))
(define (stack-block/dynamic-link? block)
(and (stack-parent? block)
(internal-block/dynamic-link? block)))
(define-integrable (internal-block/dynamic-link? block)
(not (variable-popping-limit (stack-block/continuation-lvalue block))))
| false |
a6b683d0bc258db9dc0a53b783ed9cb7888f279a | a66514d577470329b9f0bf39e5c3a32a6d01a70d | /sdl2/scancode-types.ss | c8c81e0db81f7b98510e5fcc990d982475eb5198 | [
"Apache-2.0"
]
| permissive | ovenpasta/thunderchez | 2557819a41114423a4e664ead7c521608e7b6b42 | 268d0d7da87fdeb5f25bdcd5e62217398d958d59 | refs/heads/trunk | 2022-08-31T15:01:37.734079 | 2021-07-25T14:59:53 | 2022-08-18T09:33:35 | 62,828,147 | 149 | 29 | null | 2022-08-18T09:33:37 | 2016-07-07T18:07:23 | Common Lisp | UTF-8 | Scheme | false | false | 10,794 | ss | scancode-types.ss | ;;
;; Copyright 2016 Aldo Nicolas Bruno
;;
;; Licensed under the Apache License, Version 2.0 (the "License");
;; you may not use this file except in compliance with the License.
;; You may obtain a copy of the License at
;;
;; http://www.apache.org/licenses/LICENSE-2.0
;;
;; Unless required by applicable law or agreed to in writing, software
;; distributed under the License is distributed on an "AS IS" BASIS,
;; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
;; See the License for the specific language governing permissions and
;; limitations under the License.
(define-flags sdl-scancode
(unknown 0)
;; /**
;; * \name usage page 0x07
;; *
;; * these values are from usage page 0x07 (usb keyboard page).
;; */
;; /* @{ */
(a 4)
(b 5)
(c 6)
(d 7)
(e 8)
(f 9)
(g 10)
(h 11)
(i 12)
(j 13)
(k 14)
(l 15)
(m 16)
(n 17)
(o 18)
(p 19)
(q 20)
(r 21)
(s 22)
(t 23)
(u 24)
(v 25)
(w 26)
(x 27)
(y 28)
(z 29)
(1 30)
(2 31)
(3 32)
(4 33)
(5 34)
(6 35)
(7 36)
(8 37)
(9 38)
(0 39)
(return 40)
(escape 41)
(backspace 42)
(tab 43)
(space 44)
(minus 45)
(equals 46)
(leftbracket 47)
(rightbracket 48)
(backslash 49) ;; /**< located at the lower left of the return
;; * key on iso keyboards and at the right end
;; * of the qwerty row on ansi keyboards.
;; * produces reverse solidus (backslash) and
;; * vertical line in a us layout, reverse
;; * solidus and vertical line in a uk mac
;; * layout, number sign and tilde in a uk
;; * windows layout, dollar sign and pound sign
;; * in a swiss german layout, number sign and
;; * apostrophe in a german layout, grave
;; * accent and pound sign in a french mac
;; * layout, and asterisk and micro sign in a
;; * french windows layout.
;; */
(nonushash 50) ;; /**< iso usb keyboards actually use this code
;; * instead of 49 for the same key, but all
;; * oses i've seen treat the two codes
;; * identically. so, as an implementor, unless
;; * your keyboard generates both of those
;; * codes and your os treats them differently,
;; * you should generate sdl-scancode-backslash
;; * instead of this code. as a user, you
;; * should not rely on this code because sdl
;; * will never generate it with most (all?)
;; * keyboards.
;; */
(semicolon 51)
(apostrophe 52)
(grave 53) ;; /**< located in the top left corner (on both ansi
;; * and iso keyboards). produces grave accent and
;; * tilde in a us windows layout and in us and uk
;; * mac layouts on ansi keyboards, grave accent
;; * and not sign in a uk windows layout, section
;; * sign and plus-minus sign in us and uk mac
;; * layouts on iso keyboards, section sign and
;; * degree sign in a swiss german layout (mac:
;; * only on iso keyboards), circumflex accent and
;; * degree sign in a german layout (mac: only on
;; * iso keyboards), superscript two and tilde in a
;; * french windows layout, commercial at and
;; * number sign in a french mac layout on iso
;; * keyboards, and less-than sign and greater-than
;; * sign in a swiss german, german, or french mac
;; * layout on ansi keyboards.
;; */
(comma 54)
(period 55)
(slash 56)
(capslock 57)
(f1 58)
(f2 59)
(f3 60)
(f4 61)
(f5 62)
(f6 63)
(f7 64)
(f8 65)
(f9 66)
(f10 67)
(f11 68)
(f12 69)
(printscreen 70)
(scrolllock 71)
(pause 72)
(insert 73); /**< insert on pc, help on some mac keyboards (but
; does send code 73, not 117) */
(home 74)
(pageup 75)
(delete 76)
(end 77)
(pagedown 78)
(right 79)
(left 80)
(down 81)
(up 82)
(numlockclear 83) ;/**< num lock on pc, clear on mac keyboards
; */
(kp-divide 84)
(kp-multiply 85)
(kp-minus 86)
(kp-plus 87)
(kp-enter 88)
(kp-1 89)
(kp-2 90)
(kp-3 91)
(kp-4 92)
(kp-5 93)
(kp-6 94)
(kp-7 95)
(kp-8 96)
(kp-9 97)
(kp-0 98)
(kp-period 99)
(nonusbackslash 100) ;/**< this is the additional key that iso
;; * keyboards have over ansi ones,
;; * located between left shift and y.
;; * produces grave accent and tilde in a
;; * us or uk mac layout, reverse solidus
;; * (backslash) and vertical line in a
;; * us or uk windows layout, and
;; * less-than sign and greater-than sign
;; * in a swiss german, german, or french
;; * layout. */
(application 101); /**< windows contextual menu, compose */
(power 102) ;/**< the usb document says this is a status flag,
; * not a physical key - but some mac keyboards
; * do have a power key. */
(kp-equals 103)
(f13 104)
(f14 105)
(f15 106)
(f16 107)
(f17 108)
(f18 109)
(f19 110)
(f20 111)
(f21 112)
(f22 113)
(f23 114)
(f24 115)
(execute 116)
(help 117)
(menu 118)
(select 119)
(stop 120)
(again 121) ; /**< redo */
(undo 122)
(cut 123)
(copy 124)
(paste 125)
(find 126)
(mute 127)
(volumeup 128)
(volumedown 129)
;/* not sure whether there's a reason to enable these */
;/* (lockingcapslock 130, */
;/* (lockingnumlock 131, */
;/* (lockingscrolllock 132, */
(kp-comma 133)
(kp-equalsas400 134)
(international1 135) ;/**< used on asian keyboards, see
;footnotes in usb doc */
(international2 136)
(international3 137) ;/**< yen */
(international4 138)
(international5 139)
(international6 140)
(international7 141)
(international8 142)
(international9 143)
(lang1 144) ;/**< hangul/english toggle */
(lang2 145) ;/**< hanja conversion */
(lang3 146) ;/**< katakana */
(lang4 147) ;/**< hiragana */
(lang5 148) ;/**< zenkaku/hankaku */
(lang6 149) ;/**< reserved */
(lang7 150) ;/**< reserved */
(lang8 151) ;/**< reserved */
(lang9 152) ;/**< reserved */
(alterase 153) ;/**< erase-eaze */
(sysreq 154)
(cancel 155)
(clear 156)
(prior 157)
(return2 158)
(separator 159)
(out 160)
(oper 161)
(clearagain 162)
(crsel 163)
(exsel 164)
(kp-00 176)
(kp-000 177)
(thousandsseparator 178)
(decimalseparator 179)
(currencyunit 180)
(currencysubunit 181)
(kp-leftparen 182)
(kp-rightparen 183)
(kp-leftbrace 184)
(kp-rightbrace 185)
(kp-tab 186)
(kp-backspace 187)
(kp-a 188)
(kp-b 189)
(kp-c 190)
(kp-d 191)
(kp-e 192)
(kp-f 193)
(kp-xor 194)
(kp-power 195)
(kp-percent 196)
(kp-less 197)
(kp-greater 198)
(kp-ampersand 199)
(kp-dblampersand 200)
(kp-verticalbar 201)
(kp-dblverticalbar 202)
(kp-colon 203)
(kp-hash 204)
(kp-space 205)
(kp-at 206)
(kp-exclam 207)
(kp-memstore 208)
(kp-memrecall 209)
(kp-memclear 210)
(kp-memadd 211)
(kp-memsubtract 212)
(kp-memmultiply 213)
(kp-memdivide 214)
(kp-plusminus 215)
(kp-clear 216)
(kp-clearentry 217)
(kp-binary 218)
(kp-octal 219)
(kp-decimal 220)
(kp-hexadecimal 221)
(lctrl 224)
(lshift 225)
(lalt 226) ; /**< alt, option */
(lgui 227) ;/**< windows, command (apple)) meta */
(rctrl 228)
(rshift 229)
(ralt 230) ; /**< alt gr, option */
(rgui 231) ; /**< windows, command (apple), meta */
(mode 257) ;; /**< i'm not sure if this is really not covered
;; * by any of the above, but since there's a
;; * special kmod-mode for it i'm adding it here
;; */
;; /* @} *//* usage page 0x07 */
;; /**
;; * \name usage page 0x0c
;; *
;; * these values are mapped from usage page 0x0c (usb consumer page).
;; */
;; /* @{ */
(audionext 258)
(audioprev 259)
(audiostop 260)
(audioplay 261)
(audiomute 262)
(mediaselect 263)
(www 264)
(mail 265)
(calculator 266)
(computer 267)
(ac-search 268)
(ac-home 269)
(ac-back 270)
(ac-forward 271)
(ac-stop 272)
(ac-refresh 273)
(ac-bookmarks 274)
;; /* @} *//* usage page 0x0c */
;; /**
;; * \name walther keys
;; *
;; * these are values that christian walther added (for mac keyboard?).
;; */
;; /* @{ */
(brightnessdown 275)
(brightnessup 276)
(displayswitch 277) ;; /**< display mirroring/dual display
;; switch, video mode switch */
(kbdillumtoggle 278)
(kbdillumdown 279)
(kbdillumup 280)
(eject 281)
(sleep 282)
(app1 283)
(app2 284)
;; /* @} *//* walther keys */
;; /* add any other keys here. */
(sdl-num-scancodes 512) ;; /**< not a key, just marks the number of scancodes
;; for array bounds */
) ; sdl-scancode
| false |
7dcdf1c9de06a2440a1eaad867128a491013237c | 492b4d445abfe46847f81ae9fcac0d4eb94b3194 | /app/controllers/demo-api.sld | 57ad7de4f4569ca8709f5f175bee8b9927a0456c | []
| no_license | cyclone-scheme/cloudburst | cf4a5a3e869768a07016d9de6726505c985cd05e | 6f18af7a38ad9b17136bad8142d9abc8b556a64a | refs/heads/master | 2023-02-25T03:26:01.928363 | 2021-01-25T23:43:12 | 2021-01-25T23:43:12 | 309,513,111 | 0 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 1,353 | sld | demo-api.sld | (define-library (app controllers demo-api)
(import
(scheme base)
(scheme write)
(srfi 69)
(lib json)
(lib uri)
(prefix (lib request) req:)
(prefix (app models demo) demo-model:)
)
(export
;; Sample REST API for "key-value" entities
get:key-values
post:key-value
put:key-value
delete:key-value
)
(begin
(define (get:key-values)
;; For REST functions we return sexp to the framwork and
;; let it do the JSON (or whatever) conversion
(demo-model:get-all))
(define (post:key-value)
(let* ((vars (decode-form (req:body)))
(key (form vars "key"))
(value (form vars "value"))
)
;; This returns 404 if no key
(when key
(demo-model:insert! key value)
`(Inserted ,key ,value))))
(define (put:key-value)
(let* ((vars (decode-form (req:body)))
(key (form vars "key"))
(value (form vars "value"))
)
;; Return 404 if no key
(when key
(demo-model:update! key value)
`(Updated ,key ,value))))
(define (delete:key-value)
(let* ((vars (decode-form (req:body)))
(key (form vars "key"))
)
;; Return 404 if no key
(when key
(demo-model:delete! key)
`(Deleted ,key))))
))
| false |
9b6f503be3543e7f1289a6f103ac2f4192ff6e71 | 982919bd7728330f3bb6568f22dfd0d4e348affa | /hygienic-macro/utility/datatype.ss | b162a0a14e68ea8723a13466b9dc6ef8e428fc04 | []
| no_license | thzt/scheme-interpreter | 9fb389ea9146e2a5a8d7fa6ef2808d4c25c035d3 | 267dc29aec2e02df8f7de4b1072466d12a97248d | refs/heads/master | 2021-01-19T17:13:10.368468 | 2015-10-30T09:40:40 | 2015-10-30T09:40:40 | 39,499,402 | 8 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 503 | ss | datatype.ss | (library (utility datatype)
(export make-closure
closure?
closure-param
closure-body
closure-env
make-macro
macro?
macro-param
macro-body
macro-env
make-macro-binding
macro-binding?
macro-binding-value
macro-binding-eval-env)
(import (rnrs))
(define-record-type closure
(fields param body env))
(define-record-type macro
(fields param body env))
(define-record-type macro-binding
(fields value eval-env))
)
| false |
bee1916853d3d0751dd211973e5f160279f36e2f | 2163cd08beac073044187423727f84510a1dbc34 | /appendices-y/src-chicken/y-combinator-strict.scm | 2849e4aa2ad9b82b73d3bd5865618e0d3eb05cb6 | []
| no_license | radiganm/sicp | b40995ad4d681e2950698295df1bbe3a75565528 | 32a7dcdf5678bb54d07ee3ee8a824842907489f0 | refs/heads/master | 2021-01-19T10:48:52.579235 | 2016-12-12T10:47:18 | 2016-12-12T10:47:18 | 63,052,284 | 3 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 702 | scm | y-combinator-strict.scm | #!/usr/bin/csi -s
;; y-combinator-struct.scm
;; Mac Radigan
;;
;; copied from http://mvanier.livejournal.com/2897.html
(load "../library/util.scm")
(import util)
;;; The strict (applicative-order) Y combinator
(define Y
(lambda (f)
((lambda (x) (x x))
(lambda (x) (f (lambda (y) ((x x) y)))))))
(define almost-factorial
(lambda (f)
(lambda (n)
(if (= n 0)
1
(* n (f (- n 1)))))))
(define (part-factorial self)
(let ((f (lambda (y) ((self self) y))))
(lambda (n)
(if (= n 0)
1
(* n (f (- n 1)))))))
(define factorial (Y almost-factorial))
(prn (factorial 6)) ; 720
;; *EOF*
| false |
a686598d91d861d570a4b5c0ef874edd28b56bf0 | ea4e27735dd34917b1cf62dc6d8c887059dd95a9 | /oop-spacewars(tutor version).scm | 3f418c0e32cb3a25c98429a8981bc532d7389412 | [
"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 | 3,174 | scm | oop-spacewars(tutor version).scm | (define nil '())
(define (make-vect x y) (list x y))
(define (vect-x vec) (car vec))
(define (vect-y vec) (cadr vec))
(define (add-vect u v)
(make-vect (+ (vect-x u) (vect-x v))
(+ (vect-y u) (vect-y v))))
(define (make-ship position velocity num-torps)
(define (move)
(set! position (add-vect position velocity))
'done)
(define (fire-torp)
(cond ((> num-torps 0)
(set! num-torps (- num-torps 1))
(let ((torp (make-torpedo position
(add-vect velocity velocity))))
(add-to-universe torp)
'torp-fired))
(else 'out-of-torpedoes!)))
(define (explode ship)
(newline)
(display "Ouch. That hurt.")
(remove-from-universe ship))
(lambda (msg . args)
(cond ((eq? msg 'position) position)
((eq? msg 'velocity) velocity)
((eq? msg 'move) (move))
((eq? msg 'attack) (fire-torp))
((eq? msg 'explode) (explode (car args)))
((eq? msg 'clock-tick) (move) (fire-torp))
((eq? msg 'display)
(newline)
(display "ship at ")
(display position))
(else (error "ship can't" msg)))))
(define (make-station position)
(define (explode station)
(newline)
(display "a small crack starts tearing the station apart ..."))
(lambda (msg . args)
(cond ((eq? msg 'position) position)
((eq? msg 'clock-tick) 'done)
((eq? msg 'explode) (explode (car args)))
((eq? msg 'display)
(newline)
(display "station at ")
(display position))
(else (error "station can't " msg)))))
(define *universe* nil)
(define (add-to-universe thing)
(set! *universe* (cons thing *universe*)))
(define (remove-from-universe thing)
(set! *universe* (delq thing *universe*)))
(define (clock)
(for-each (lambda (x) (x 'clock-tick)) *universe*)
(for-each (lambda (x) (x 'display)) *universe*)
(let ((collisions (find-collisions *universe*)))
(for-each (lambda (x) (x 'explode x))
collisions)))
(define (run-clock n)
(cond ((= n 0) 'done)
(else (clock)
(run-clock (- n 1)))))
(define (square x) (* x x))
(define (find-distance a b)
(sqrt (+ (square (- (vect-x a) (vect-x b)))
(square (- (vect-y a) (vect-y b))))))
(define (find-collisions lst)
(define (test current rest)
(cond ((null? rest) nil)
((< (find-distance ((car rest) 'position)
(current 'position))
1)
(cons (car rest) (test current (cdr rest))))
(else (test current (cdr rest)))))
(cond ((null? lst) nil)
(else (let ((new (test (car lst) (cdr lst))))
(if new ; there are some
(append (cons (car lst) new)
(find-collisions (cdr lst)))
(find-collisions (cdr lst)))))))
(define (make-torpedo position velocity)
(define (explode torp)
(newline)
(display "torpedo goes off!")
(remove-from-universe torp))
(define (move)
(set! position (add-vect position velocity)))
(lambda (msg . args)
(cond ((eq? msg 'position) position)
((eq? msg 'velocity) velocity)
((eq? msg 'move) (move))
((eq? msg 'clock-tick) (move))
((eq? msg 'explode) (explode (car args)))
((eq? msg 'display)
(newline)
(display "torpedo at ")
(display position))
(else (error "no method" msg)))))
| false |
d79c147dcb20c8c8b28edb3ed2b146b89f843299 | c39b3eb88dbb1c159577149548d3d42a942fe344 | /project/libs/testing/macro.sld | 9b2a60dc6f39693f21f1ee59967984d79bc75137 | []
| no_license | mbillingr/lisp-in-small-pieces | 26694220205818a03efc4039e5a9e1ce7b67ff5c | dcb98bc847c803e65859e4a5c9801d752eb1f8fa | refs/heads/master | 2022-06-17T20:46:30.461955 | 2022-06-08T17:50:46 | 2022-06-08T17:50:46 | 201,653,143 | 13 | 3 | null | 2022-06-08T17:50:47 | 2019-08-10T16:09:21 | Scheme | UTF-8 | Scheme | false | false | 912 | sld | macro.sld | (define-library (testing macro)
(export delay force or mul
(rename add add_many))
(import (sunny core))
(begin
(define-syntax delay
(syntax-rules ()
((delay x) (lambda () x))))
(define-syntax force
(syntax-rules ()
((force x) (x))))
(define-syntax or
(syntax-rules ()
((or) #f)
((or a) a)
((or a b) (let ((temp a)) (if temp temp b)))
((or a b ...) (let ((temp a)) (if temp temp (or b ...))))))
(define-syntax add
(syntax-rules ()
((add) 0)
((add z) z)
((add z1 z2 ...) (+ z1 (add z2 ...)))))
(define-syntax mul
(syntax-rules ()
((mul) 1)
((mul z) z)
((mul z1 z2 ...) (* z1 (mul z2 ...)))))))
| true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.