blob_id
stringlengths
40
40
directory_id
stringlengths
40
40
path
stringlengths
3
171
content_id
stringlengths
40
40
detected_licenses
sequencelengths
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
6f0c4eb16f2e36c324b587219e104b1762ac5ecb
3508dcd12d0d69fec4d30c50334f8deb24f376eb
/v8/src/compiler/machines/i386/dassm2.scm
9dd6e98cadf4ed8e65fb3396a5327249d207d5c5
[]
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
9,330
scm
dassm2.scm
#| -*-Scheme-*- $MC68020-Header: /scheme/compiler/bobcat/RCS/dassm2.scm,v 4.18 1991/05/07 13:46:04 jinx Exp $ Copyright (c) 1992, 1999 Massachusetts Institute of Technology This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |# ;;;; Intel i386 Disassembler: Top Level ;;; package: (compiler disassembler) (declare (usual-integrations)) (define (disassembler/read-variable-cache block index) (let-syntax ((ucode-type (macro (name) (microcode-type name))) (ucode-primitive (macro (name arity) (make-primitive-procedure name arity)))) ((ucode-primitive primitive-object-set-type 2) (ucode-type quad) (system-vector-ref block index)))) (define (disassembler/read-procedure-cache block index) (fluid-let ((*block block)) (let* ((offset (compiled-code-block/index->offset index))) (let ((opcode (read-unsigned-integer (+ offset 3) 8)) (arity (read-unsigned-integer offset 16))) (case opcode ((#xe9) ; (JMP (@PCR label)) ;; This should learn how to decode the new trampolines. (vector 'COMPILED (read-procedure (+ offset 4)) arity)) (else (error "disassembler/read-procedure-cache: Unknown opcode" opcode block index))))))) (define (disassembler/instructions block start-offset end-offset symbol-table) (let loop ((offset start-offset) (state (disassembler/initial-state))) (if (and end-offset (< offset end-offset)) (disassemble-one-instruction block offset symbol-table state (lambda (offset* instruction state) (make-instruction offset instruction (lambda () (loop offset* state))))) '()))) (define-integrable (disassembler/instructions/null? obj) (null? obj)) (define (disassembler/instructions/read instruction-stream receiver) (receiver (instruction-offset instruction-stream) (instruction-instruction instruction-stream) (instruction-next instruction-stream))) (define-structure (instruction (type vector)) (offset false read-only true) (instruction false read-only true) (next false read-only true)) (define *block) (define *current-offset) (define *symbol-table) (define *valid?) (define (disassemble-one-instruction block offset symbol-table state receiver) (fluid-let ((*block block) (*current-offset offset) (*symbol-table symbol-table) (*valid? true)) (let ((start-offset *current-offset)) ;; External label markers come in two parts: ;; An entry type descriptor, and a gc offset. (cond ((eq? state 'EXTERNAL-LABEL-OFFSET) (let* ((word (next-unsigned-16-bit-word)) (label (find-label *current-offset))) (receiver *current-offset (if label `(BLOCK-OFFSET ,label) `(WORD U ,word)) 'INSTRUCTION))) ((external-label-marker? symbol-table offset state) (let ((word (next-unsigned-16-bit-word))) (receiver *current-offset `(WORD U ,word) 'EXTERNAL-LABEL-OFFSET))) (else (let ((instruction (disassemble-next-instruction))) (if (or *valid? (not (eq? 'BYTE (car instruction)))) (receiver *current-offset instruction (disassembler/next-state instruction state)) (let ((inst `(BYTE U ,(caddr instruction)))) (receiver (1+ start-offset) inst (disassembler/next-state inst state)))))))))) (define (disassembler/initial-state) 'INSTRUCTION-NEXT) (define (disassembler/next-state instruction state) state ; ignored (if (and disassembler/compiled-code-heuristics? (or (memq (car instruction) '(JMP RET)) (and (eq? (car instruction) 'CALL) (let ((operand (cadr instruction))) (or (and (pair? operand) (eq? (car operand) 'ENTRY)) (let ((entry (interpreter-register? operand))) (and entry (eq? (car entry) 'ENTRY)))))))) 'EXTERNAL-LABEL 'INSTRUCTION)) (define (disassembler/lookup-symbol symbol-table offset) (and symbol-table (let ((label (dbg-labels/find-offset symbol-table offset))) (and label (dbg-label/name label))))) (define (external-label-marker? symbol-table offset state) (define-integrable (offset-word->offset word) (fix:quotient (bit-string->unsigned-integer word) 2)) (if symbol-table (let ((label (dbg-labels/find-offset symbol-table (+ offset 4)))) (and label (dbg-label/external? label))) (and *block (not (eq? state 'INSTRUCTION)) (let loop ((offset (+ offset 4))) (let ((contents (read-bits (- offset 2) 16))) (if (bit-string-clear! contents 0) (let ((offset (- offset (offset-word->offset contents)))) (and (positive? offset) (loop offset))) (= offset (offset-word->offset contents)))))))) (define (read-procedure offset) (with-absolutely-no-interrupts (lambda () (let-syntax ((ucode-type (macro (name) (microcode-type name))) (ucode-primitive (macro (name arity) (make-primitive-procedure name arity)))) ((ucode-primitive primitive-object-set-type 2) (ucode-type compiled-entry) ((ucode-primitive make-non-pointer-object 1) (+ (read-signed-integer offset 32) (+ (if *block (object-datum *block) 0) (+ offset 4))))))))) (define (read-unsigned-integer offset size) (bit-string->unsigned-integer (read-bits offset size))) (define (read-signed-integer offset size) (bit-string->signed-integer (read-bits offset size))) (define (read-bits offset size-in-bits) (let ((word (bit-string-allocate size-in-bits)) (bit-offset (* offset addressing-granularity))) (with-absolutely-no-interrupts (lambda () (if *block (read-bits! *block bit-offset word) (read-bits! offset 0 word)))) word)) (define-integrable (make-unsigned-reader nbits) (let ((nbytes (fix:quotient nbits 8))) (lambda () (let ((offset *current-offset)) (let ((word (read-bits offset nbits))) (set! *current-offset (+ offset nbytes)) (bit-string->unsigned-integer word)))))) (define-integrable (make-signed-reader nbits) (let ((nbytes (fix:quotient nbits 8))) (lambda () (let ((offset *current-offset)) (let ((word (read-bits offset nbits))) (set! *current-offset (+ offset nbytes)) (bit-string->signed-integer word)))))) (define next-byte (make-signed-reader 8)) (define next-unsigned-byte (make-unsigned-reader 8)) (define next-16-bit-word (make-signed-reader 16)) (define next-unsigned-16-bit-word (make-unsigned-reader 16)) (define next-32-bit-word (make-signed-reader 32)) (define next-unsigned-32-bit-word (make-unsigned-reader 32)) (define (find-label offset) (and disassembler/symbolize-output? (disassembler/lookup-symbol *symbol-table offset))) (define (interpreter-register? operand) (define (regs-pointer? reg) (if (symbol? reg) (eq? reg 'ESI) (= reg 6))) (define (offset->register offset) (let ((place (assq offset interpreter-register-offsets))) (and place (cdr place)))) (and (pair? operand) (or (and (eq? (car operand) '@R) (regs-pointer? (cadr operand)) (offset->register 0)) (and (eq? (car operand) '@RO) (regs-pointer? (caddr operand)) (offset->register (cadddr operand)))))) (define interpreter-register-offsets (letrec ((make-entries (lambda (kind offset names) (if (null? names) '() (cons (cons offset `(,kind ,(car names))) (make-entries kind (+ offset 4) (cdr names))))))) (append (make-entries 'REGISTER 0 '(memtop stack-guard val env compiler-temp expr return-code lexpr-actuals primitive closure-free closure-space)) (make-entries 'ENTRY #x40 ; 16 * 4 '(scheme-to-interface scheme-to-interface/call trampoline-to-interface interrupt-procedure interrupt-continuation interrupt-closure interrupt-dlink primitive-apply primitive-lexpr-apply assignment-trap reference-trap safe-reference-trap link error primitive-error short-primitive-apply)) (make-entries 'ENTRY #x-80 '(&+ &- &* &/ &= &< &> 1+ -1+ zero? positive? negative? quotient remainder modulo shortcircuit-apply ; Used by rules3, for speed. shortcircuit-apply-size-1 ; Small frames, save time and space. shortcircuit-apply-size-2 shortcircuit-apply-size-3 shortcircuit-apply-size-4 shortcircuit-apply-size-5 shortcircuit-apply-size-6 shortcircuit-apply-size-7 shortcircuit-apply-size-8))))) ;; These are used by dassm1.scm (define compiled-code-block/procedure-cache-offset 1) (define compiled-code-block/objects-per-procedure-cache 2) (define compiled-code-block/objects-per-variable-cache 1) ;; global variable used by runtime/udata.scm -- Moby yuck! (set! compiled-code-block/bytes-per-object 4)
false
c93b3713328edc7b99e94ed3ef7f7864a79dc70a
b60cb8e39ec090137bef8c31ec9958a8b1c3e8a6
/test/R5RS/sigscheme/let-loop.scm
a1f2e37724c4921d167eff19235596e955220827
[]
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
126
scm
let-loop.scm
(define loop (lambda (i l) (let ((a 0) (b 1) (c 2)) (if (< i l) (loop (+ 1 i) l) l)))) (loop 0 20000)
false
224494ee89705097b4e306e1135b1f951b53807b
000dbfe5d1df2f18e29a76ea7e2a9556cff5e866
/boot/lib/program.scm
e12f5d61cd62f44627436f291d64f69d884a2d73
[ "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
4,581
scm
program.scm
;;; -*- mode: scheme; coding: utf-8; -*- ;;; ;;; core/program.scm - starting poinrt of Sagittarius kernel ;;; ;;; Copyright (c) 2010-2016 Takashi Kato <[email protected]> ;;; ;;; Redistribution and use in source and binary forms, with or without ;;; modification, are permitted provided that the following conditions ;;; are met: ;;; ;;; 1. Redistributions of source code must retain the above copyright ;;; notice, this list of conditions and the following disclaimer. ;;; ;;; 2. Redistributions in binary form must reproduce the above copyright ;;; notice, this list of conditions and the following disclaimer in the ;;; documentation and/or other materials provided with the distribution. ;;; ;;; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ;;; "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT ;;; LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR ;;; A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT ;;; OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, ;;; SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED ;;; TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR ;;; PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF ;;; LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING ;;; NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS ;;; SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ;;; (library (core program) (export start command-line) (import (core) (core base) (sagittarius) (sagittarius vm) (sagittarius fixnums)) (define command-line (make-core-parameter '())) (define *r6rs-read-context* (make-read-context-for-load)) (define (program-r6rs file/port) (let ((port (cond ((port? file/port) file/port) ((string? file/port) (open-file-input-port file/port #f 'block (*current-load-transcoder*))) (else (error 'progam "Strict R6RS mode doesn't have REPL"))))) (apply-directive! port 'r6rs *r6rs-read-context*) (let loop ((e (read port)) (r '())) (if (eof-object? e) (begin (eval `(program . ,(reverse! r)) (environment '(r6rs-script))) (exit)) (loop (read port) (cons e r)))))) (define (script file/port prompt opt) (define (import-it lib) (eval `(import ,lib) (current-library))) (define (repl) (define interactive (find-library '(sagittarius interactive) #f)) (if interactive (case prompt ((r7rs) (eval '(*import-libraries* '((scheme base))) interactive) (eval '(current-prompter (lambda () (display "sash[r7rs]> "))) interactive) (eval `(read-eval-print-loop) interactive)) (else (eval `(read-eval-print-loop) interactive))) (begin (display "(sagittarius interactive) is not located on the \ loadpath. Add -L option to indicate it" (current-error-port)) (newline (current-error-port)) (exit -1)))) (define (exit/repl exit-code) (if (assq :interactive? opt) (repl) (exit exit-code))) (define (load-r7rs file/port) (define (ensure-port file/port) (if (port? file/port) file/port (open-file-input-port file/port #f 'block (*current-load-transcoder*)))) (let ((in (ensure-port file/port))) (apply-directive! in 'r7rs *r6rs-read-context*) ;; put cond-expand into the environment (eval '(import (only (sagittarius) cond-expand)) #f) (load-from-port in))) (cond ((assq :preimports opt) => (lambda (preimports) (for-each import-it (cdr preimports))))) (cond ((assq :expressions opt) => (lambda (expr) (call-with-port (open-string-input-port (cdr expr)) load-from-port)))) (if file/port (let ((exit-code (cond ((eq? prompt 'r7rs) (load-r7rs file/port)) ((port? file/port) (load-from-port file/port)) (else (load file/port))))) (or (and-let* ((main? (assq :main? opt)) ( (cdr main?) ) (main (find-binding (current-library) 'main #f)) (r (eval `(main ',(command-line)) (current-library)))) (if (fixnum? r) (exit/repl r) (exit/repl exit-code))) (exit/repl exit-code))) (repl))) (define (start file/port args opt) (command-line args) (case (cond ((assq :standard opt) => cdr) (else #f)) ((6) (program-r6rs file/port)) ((7) (script file/port 'r7rs opt)) (else (script file/port #f opt)))) )
false
327172ad1318a176884b3f4334f051b54a414a01
495be054a7d58871a0a975ad90dcd3f9ad04ffe4
/ch3/ch3.3.3.scm
9f8e5453cd4f6b98e86bcf8b489a8058bb756c7f
[]
no_license
Galaxy21Yang/sicp
cd0b646aabc693f9bad46fac880ff2f50ac667ba
17990996ad4b8906ff3d27219d23033ca44753a0
refs/heads/master
2020-12-03T05:35:32.987780
2015-09-25T09:18:57
2015-09-25T09:18:57
43,195,037
13
5
null
2015-09-26T06:30:45
2015-09-26T06:30:45
null
UTF-8
Scheme
false
false
6,377
scm
ch3.3.3.scm
;;;; SICP Chapter 3.3.3 ;;;; Representing Tables ;;;; ;;;; Author @uents on twitter ;;;; #lang racket ;;; for mutable pairs and lists (require r5rs) (require "../misc.scm") ;;;; ex 3.24 ; 解答は省略。 ; ; make-table にテスト関数を引数で渡せるようにし、 ; assoc-tree 内の equal? の代わりにそのテスト関数を使えばよいだけ。 ;;;; ex 3.25 ;; record (define (make-record k v) (cons k v)) (define (key record) (car record)) (define (value record) (cdr record)) (define (set-key! record k) (set-car! record k)) (define (set-value! record v) (set-cdr! record v)) ;; tree (define (make-tree record next) (cons record next)) (define (record tree) (car tree)) (define (next tree) (cdr tree)) (define (set-record! tree record) (set-car! tree record)) (define (set-next! tree next) (set-cdr! tree next)) ;; tree operations (define (assoc-tree tree k) (cond ((null? tree) false) ((equal? k (key (record tree))) tree) (else (assoc-tree (next tree) k)))) (define (adjoin-tree! tree key-list v) (define (make-deep-record key-list) (if (null? (cdr key-list)) (make-record (car key-list) v) (make-record (car key-list) (make-tree (make-deep-record (cdr key-list)) nil)))) (set-next! tree (make-tree (make-deep-record key-list) (next tree)))) (define (make-table-tree) (make-tree (make-record '*table* nil) nil)) ;; table (define (make-table) (let ((the-tree (make-table-tree))) (define (lookup key-list) (define (iter tree key-list) ; (display (format "lookup t=~A k=~A ~%" tree key-list)) (if (null? key-list) false (let ((t (assoc-tree tree (car key-list)))) (if t (if (null? (cdr key-list)) (value (record t)) (iter (value (record t)) (cdr key-list))) false)))) (iter the-tree key-list)) (define (insert! key-list v) (define (iter tree key-list) ; (display (format "insert! t=~A k=~A v=~A ~%" tree key-list v)) (if (null? key-list) false (let ((t (assoc-tree tree (car key-list)))) (if t (if (null? (cdr key-list)) (set-value! (record t) v) (iter (value (record t)) (cdr key-list))) (adjoin-tree! tree key-list v))))) (iter the-tree key-list)) (define (print) (begin (display the-tree (current-error-port)) (newline (current-error-port)))) (define (dispatch m) (cond ((eq? m 'lookup-proc) lookup) ((eq? m 'insert-proc!) insert!) ((eq? m 'print-proc) print) (else (error "dispatch -- unknown operation" m)))) dispatch)) (define (lookup-table table key) ((table 'lookup-proc) key)) (define (insert-table! table key value) ((table 'insert-proc!) key value)) (define (print-table table) ((table 'print-proc))) ;;; test ;; racket@> (define tbl (make-table)) ;; racket@> (insert-table! tbl (list 1 2) "one two") ;; racket@> (insert-table! tbl (list 1 3) "one three") ;; racket@> (insert-table! tbl (list 2 3) "two three") ;; racket@> (insert-table! tbl (list 1 4) "one four") ;; racket@> (insert-table! tbl (list 2 4) "two four") ;; racket@> (print-table tbl) ;; ((*table*) (2 (3 . two three) (4 . two four)) (1 (2 . one two) (4 . one four) (3 . one three))) ;; racket@> (lookup-table tbl (list 1 2)) ;; "one two" ;; racket@> (lookup-table tbl (list 1 1)) ;; #f ;; racket@> (lookup-table tbl (list 2 1)) ;; #f ;; racket@> (lookup-table tbl (list 2 3)) ;; "two three" ;;;; ex 3.26 #| ;; tree (define (make-tree record left right) (list record left right)) (define (record tree) (car tree)) (define (left tree) (cadr tree)) (define (right tree) (caddr tree)) (define (set-record! tree record) (set-car! tree record)) (define (set-left! tree left) (set-car! (cdr tree) left)) (define (set-right! tree right) (set-car! (cddr tree) right)) ;; tree operations (define (assoc-tree tree k) (cond ((null? tree) false) ((equal? k (key (record tree))) tree) ((< k (key (record tree))) (assoc-tree (left tree) k)) (else (assoc-tree (right tree) k)))) (define (adjoin-tree! tree key-list v) (define (make-deep-tree key-list) (if (null? (cdr key-list)) (make-tree (make-record (car key-list) v) nil nil) (make-tree (make-record (car key-list) (make-deep-tree (cdr key-list))) nil nil))) (cond ((< (car key-list) (key (record tree))) (if (null? (left tree)) (set-left! tree (make-deep-tree key-list)) (adjoin-tree! (left tree) key-list v))) ((> (car key-list) (key (record tree))) (if (null? (right tree)) (set-right! tree (make-deep-tree key-list)) (adjoin-tree! (right tree) key-list v))) (else (error "adjoin-tree! -- tree key value" tree key-list v)))) (define (make-table-tree) (make-tree (make-record -inf.0 nil) nil nil)) |# ;;; test ;; racket@> (define tbl (make-table)) ;; racket@> (insert-table! tbl (list 1 2) "one two") ;; racket@> (insert-table! tbl (list 1 3) "one three") ;; racket@> (insert-table! tbl (list 2 3) "two three") ;; racket@> (insert-table! tbl (list 1 4) "one four") ;; racket@> (insert-table! tbl (list 2 4) "two four") ;; racket@> (print-table tbl) ;; ((-inf.0) () ((1 (2 . one two) () ((3 . one three) () ((4 . one four) () ()))) () ((2 (3 . two three) () ((4 . two four) () ())) () ()))) ;; racket@> (lookup-table tbl (list 1 2)) ;; "one two" ;; racket@> (lookup-table tbl (list 1 1)) ;; #f ;; racket@> (lookup-table tbl (list 2 1)) ;; #f ;; racket@> (lookup-table tbl (list 2 3)) ;; "two three" ;;;; ex 3.27 (define (memoize f) (let ((table (make-table))) (lambda (x) (let ((memo-result (lookup-table table (list x)))) (display (format "memo-ret ~A -> ~A ~%" x memo-result)) (or memo-result (let ((result (f x))) (insert-table! table (list x) result) result)))))) (define memo-fib (memoize (lambda (n) (cond ((= n 0) 0) ((= n 1) 1) (else (+ (memo-fib (- n 1)) (memo-fib (- n 2)))))))) ;;; test ; racket@> (memo-fib 3) ; memo-ret 3 -> #f ; memo-ret 2 -> #f ; memo-ret 1 -> #f ; memo-ret 0 -> #f ; memo-ret 1 -> 1 ; 2 ;; (define (fib n) ;; (cond ((= n 0) 0) ;; ((= n 1) 1) ;; (else (+ (fib (- n 1)) ;; (fib (- n 2)))))) ;; (define memo-fib ;; (memoize fib)) ;;; test ; racket@> (memo-fib 3) ; memo-ret 3 -> #f ; 2
false
a5817a2fa4dca2eed97d669b1db2480e33fe6810
e1fc47ba76cfc1881a5d096dc3d59ffe10d07be6
/ch1/1.39.scm
f87d77cb003466f94075a239d8b132d06eb76782
[]
no_license
lythesia/sicp-sol
e30918e1ebd799e479bae7e2a9bd4b4ed32ac075
169394cf3c3996d1865242a2a2773682f6f00a14
refs/heads/master
2021-01-18T14:31:34.469130
2019-10-08T03:34:36
2019-10-08T03:34:36
27,224,763
2
0
null
null
null
null
UTF-8
Scheme
false
false
275
scm
1.39.scm
(load "1.37.scm") (define (tan-cf x k) (define (square x) (* x x)) (define (ni i) (if (= i 1) x (- (square x))) ) (define (di i) (- (* 2 i) 1) ) (exact->inexact (cont-frac-iter ni di k)) ) (display (tan 10))(newline) (display (tan-cf 10 100))(newline)
false
ab42b030de10f83cd54e6c0f76632fd1146f63a3
657a95c82617af612da2a5fa410ac44a67a39feb
/sicp/02/2.2.ss
c6cd3ac13503fd5b1012cbe51d392254e72877b0
[]
no_license
wangjiezhe/sicp
ed16395576ac163f000b6dc59ef4928bfab3013f
635dad3bc6dacd07665c17eba2bbe4fcdbbb530f
refs/heads/master
2020-04-06T07:02:32.281885
2016-08-20T08:10:24
2016-08-20T08:10:24
57,348,685
0
0
null
null
null
null
UTF-8
Scheme
false
false
746
ss
2.2.ss
(define (make-segment p q) (cons p q)) (define (start-segment l) (car l)) (define (end-segment l) (cdr l)) (define (make-point x y) (cons x y)) (define (x-point p) (car p)) (define (y-point p) (cdr p)) (define (midpoint-segment l) (make-point (/ (+ (x-point (start-segment l)) (x-point (end-segment l))) 2) (/ (+ (y-point (start-segment l)) (y-point (end-segment l))) 2))) (define (print-point p) (newline) (display "(") (display (x-point p)) (display ",") (display (y-point p)) (display ")")) (define l1 (make-segment (make-point 1 2) (make-point 3 4))) (print-point (midpoint-segment l1)) ;;; => (2,3) (newline)
false
ffd0a6f1b4250df8c625711b5b0b20b11fcfb553
92b8d8f6274941543cf41c19bc40d0a41be44fe6
/kawa/lib/scheme/char.scm
a3cbfe0d7b4fd66d9c7e2a515ab119c7be96bc04
[ "MIT" ]
permissive
spurious/kawa-mirror
02a869242ae6a4379a3298f10a7a8e610cf78529
6abc1995da0a01f724b823a64c846088059cd82a
refs/heads/master
2020-04-04T06:23:40.471010
2017-01-16T16:54:58
2017-01-16T16:54:58
51,633,398
6
0
null
null
null
null
UTF-8
Scheme
false
false
142
scm
char.scm
(module-name (scheme char)) (require kawa.lib.characters) (require kawa.lib.strings) (require kawa.lib.rnrs.unicode) (include "char-exports")
false
1fdbb8d56de00f79af2685e3e534217345ecbdf4
a876b40e00cd9d760c1520f1d2371c9299598d7e
/tst/gnu/syntax.scm
e12cac27c7ff83f14d97d4fd007e536570d6ac0a
[]
no_license
mbakhterev/makenv
2b537cd64a0264761510eee71a5c96a79efe9fd8
3ec259db8e537d7fbb1f380814e2d2f14e71a2d7
refs/heads/master
2021-11-27T02:14:24.728719
2021-10-10T18:40:11
2021-10-10T18:40:11
116,967,790
0
0
null
null
null
null
UTF-8
Scheme
false
false
402
scm
syntax.scm
(define-syntax make-echo-2 (let ((rename (lambda (ns) (map (lambda (n) (string->symbol (string-append "echo-" (syntax->datum n)))) ns)))) (lambda (x) (syntax-case x () ((make-echo-2 j ...) (with-syntax (((fn ...) (datum->syntax x (rename (syntax (j ...)))))) (syntax (begin (define fn (lambda (target) (echo j target))) ...))))))))
true
fe1243875836702982b683d63865a53bde4efe71
afc3bd22ea6bfe0e60396a84a837c82a0d836ea2
/Informatics Basics/Module 1/06-areas-n-volumes.scm
8786485f36a0ad8bc5ee241e70293439817f83e8
[]
no_license
BuDashka/BMSTU
c128c2b13065a25ec027c68bcc3bac119163a53f
069551c25bd11ea81e823b2195851f8563271b01
refs/heads/master
2021-04-15T15:22:12.324529
2017-10-19T00:59:25
2017-10-19T00:59:25
126,348,611
1
1
null
2018-03-22T14:35:04
2018-03-22T14:35:04
null
UTF-8
Scheme
false
false
753
scm
06-areas-n-volumes.scm
(define pi (acos -1)) (define (area-and-volume figure . args) (cond ((equal? figure 'cube) (list (* 6 (car args) (car args)) (* (car args) (car args) (car args)))) ((equal? figure 'ball) (list (* 4 pi (car args) (car args)) (* (/ 4 3) pi (car args) (car args) (car args)))) ((equal? figure 'cylinder) (list (+ (* 2 pi (car args) (car args)) (* 2 pi (car args) (cadr args))) (* pi (car args) (car args) (cadr args)))) ((equal? figure 'cone) (list (* pi (car args) (+ (car args) (sqrt (+ (* (car args) (car args)) (* (cadr args) (cadr args)))))) (* (/ 1 3) pi (car args) (car args) (cadr args)))) (else (list))))
false
ce29a1b6d90d2798a2fc1137a36f9c43506932a2
c6b8d142caf06cccf400b8c6d0154050f7037bcf
/src/transformation.scm
4e61f15e9d4ef78a8e7c2b0eb3a5056eae3ad1d3
[ "Zlib" ]
permissive
skilldown/sphere-geometry
ee9c138407d7c250f47953c6a18cb722030e3f48
817a6e4b7ca20c1ea80036683aabbf302f9b924f
refs/heads/master
2020-04-05T18:29:28.406919
2013-06-05T22:45:30
2013-06-05T22:45:30
null
0
0
null
null
null
null
UTF-8
Scheme
false
false
4,374
scm
transformation.scm
;;; Copyright (c) 2012 by Álvaro Castro-Castilla, All Rights Reserved. ;;; Licensed under the GPLv3 license, see LICENSE file for full description. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; Transformations ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;------------------------------------------------------------------------------- ; Translation ;------------------------------------------------------------------------------- ;;; Point translation (define (translate.point p vec) (vect2:+vect2 p vec)) ;;; Line translation (define (translate.line line vec) (point&direction->line (translate.point (line:point line 0) vec) (line->direction line))) ;;; Ray translation (define (translate.ray pseq vec) (error "Not implemented")) ;;; Segment translation (define (translate.segment pseq vec) (error "Not implemented")) ;;; Pseq translation (define (translate.pseq pseq vec) (error "Not implemented")) ;------------------------------------------------------------------------------- ; Rotation ;------------------------------------------------------------------------------- ;;; Point rotation with the origin (define (rotate.point/O vec alpha) (make-point (- (* (point-x vec) (cos alpha)) (* (point-y vec) (sin alpha))) (+ (* (point-y vec) (cos alpha)) (* (point-x vec) (sin alpha))))) ;;; Point rotation with a reference (define (rotate.point/ref ref p alpha) (vect2:+vect2 ref (rotate.point/O (vect2:-vect2 p ref) alpha))) ;;; Direction rotation (define (rotate.direction d alpha) (error "Not implemented")) ;;; Line rotation (define (rotate.line l alpha) (error "Not implemented")) ;;; Ray rotation (define (rotate.ray r alpha) (error "Not implemented")) ;;; Segment rotation with the origin (define (rotate.segment/O s alpha) (error "Not implemented")) ;;; Segment rotation with a reference point (define (rotate.segment/ref ref s alpha) (error "Not implemented")) ;;; Pseq rotation with the origin (define (rotate.pseq/O pseq alpha) (error "Not implemented")) ;;; Pseq rotation with a reference point (define (rotate.pseq/ref ref pseq alpha) (error "Not implemented")) ;------------------------------------------------------------------------------- ; Scaling ;------------------------------------------------------------------------------- ;;; TODO: Merge /O and /ref, using an optional argument for reference ;;; Point scaling with the origin (define (scale.point/O p scale) (error "Not implemented")) ;;; Point scaling with a reference point (define (scale.point/ref p scale) (error "Not implemented")) ;;; Line scaling with the origin (define (scale.line/O l scale) (error "Not implemented")) ;;; Line scaling with a reference point (define (scale.line/ref l scale) (error "Not implemented")) ;;; Ray scaling with the origin (define (scale.ray/O r scale) (error "Not implemented")) ;;; Ray scaling with a reference point (define (scale.ray/ref ref r scale) (error "Not implemented")) ;;; Segment scaling with the origin (define (scale.segment/O r scale) (error "Not implemented")) ;;; Segment scaling with a refernce point (define (scale.segment/ref r scale) (error "Not implemented")) ;;; Segment scaling with the origin (define (scale.pseq/O r scale) (error "Not implemented")) ;;; Segment scaling with a reference point (define (scale.pseq/ref r scale) (error "Not implemented")) ;------------------------------------------------------------------------------- ; Translation along pseq ;------------------------------------------------------------------------------- ;;; Point translation along pseq (define (translate-along-pseq.point guide p x) (error "Not implemented")) ;;; Line translation along pseq (define (translate-along-pseq.line guide l x) (error "Not implemented")) ;;; Ray translation along pseq (define (translate-along-pseq.ray guide r x) (error "Not implemented")) ;;; Segment translation along pseq (define (translate-along-pseq.segment guide s x) (error "Not implemented")) ;;; Pseq translation along pseq (define (translate-along-pseq.pseq guide pseq x) (error "Not implemented"))
false
c9455e16744b1b6736d837d5a977f409a8f54d85
984b20c7a66129447883a52132ed1298479e4deb
/state.scm
997c081f902df18c3daae78968bc4bb04b432d5a
[]
no_license
TAEB/bridey
e4bf76f9e663e67f1c1a0a5758d2d849ca4d1886
c28f47e31c235dfdef83edc645dd301f41895338
refs/heads/master
2021-01-15T10:47:44.534210
2008-04-04T22:07:46
2008-04-04T22:07:46
null
0
0
null
null
null
null
UTF-8
Scheme
false
false
1,200
scm
state.scm
; debug (define *state* #f) (define (set-state state . ls) (let ((s (apply internal-set-state state ls))) (set! *state* s) s)) (define (internal-set-state state . ls) (if (or (null? ls) (null? (cdr ls))) state (let ((name (car ls)) (value (cadr ls))) (apply internal-set-state (assoc-replace (list name value) state) (cddr ls))))) (define (modify-state state . ls) (if (or (null? ls) (null? (cdr ls))) state (let ((name (car ls)) (f (cadr ls))) (modify-state (set-state state name (f (get-state state name))) (cddr ls))))) (define (cons-state state . ls) (if (or (null? ls) (null? (cdr ls))) state (let ((name (car ls)) (value (cadr ls))) (cons-state (modify-state state name (lambda (ls) (cons value (or ls '())))) (cddr ls))))) (define (get-state state name) (let ((w (assq name state))) (if #f;(not w) (begin (display "NO STATE: ") (write name) (newline))) (and w (cadr w)))) (define (has-state? state name) (assoc name state)) (define (delete-state state name) (let ((new (assoc-delete name state))) (set! *state* new) new))
false
b26ea1de70c7d340b84ee59bf89c1f7052b83f91
d8d4bcb61e4af58a86fd1a02503e608b03d8c89f
/sitelib/errata/query.scm
f2b45c071539acaefc0db27841dd623f37cf802c
[ "BSD-2-Clause" ]
permissive
tabe/errata
b81cbb66b86e3bc1aaae4814b32ef03bfc5ed52e
23b30c26b59d6b049a198788fbce37049ad02e3f
refs/heads/master
2020-05-03T01:45:39.955636
2010-08-19T02:32:49
2010-08-19T02:32:49
null
0
0
null
null
null
null
UTF-8
Scheme
false
false
5,849
scm
query.scm
(library (errata query) (export start query-image) (import (core) (rnrs) (only (srfi :19) current-date date->string) (only (ypsilon ffi) on-freebsd) (ypsilon socket) (prefix (uri) uri:) (prefix (http client) http:) (sxml ssax) (prefix (only (lunula hmac) sha-256) hmac:) (prefix (only (lunula log) info) log:) (only (errata configuration) aws-access-key-id aws-secret-access-key query-port-number)) (define *aws-authority* "ecs.amazonaws.jp") (define *aws-path* "/onca/xml") (define *aws-parameters* `((Service . "AWSECommerceService") (AWSAccessKeyId . ,aws-access-key-id) (Operation . "ItemLookup") ;;(ItemId . "9784756134141") ;;(ResponseGroup . "ItemAttributes,Offers,Images,Reviews") (ResponseGroup . "ItemAttributes,Images,Reviews") (IdType . "ISBN") (SearchIndex . "Books") (Version . "2009-07-01") )) (define (parameter<? x y) (string<? (symbol->string (car x)) (symbol->string (car y)))) (define (generate-query parameters) (call-with-string-output-port (lambda (port) (define (put-k=v kv) (put-datum port (car kv)) (display #\= port) (put-string port (uri:encode-string (cdr kv)))) (let loop ((rest (list-sort parameter<? parameters))) (case (length rest) ((0) #f) ((1) (put-k=v (car rest))) (else (put-k=v (car rest)) (display #\& port) (loop (cdr rest)))))))) (define (generate-signature isbn parameters) (let ((str (format "GET~%~a~%~a~%~a" *aws-authority* *aws-path* (generate-query (cons `(ItemId . ,isbn) parameters))))) (hmac:sha-256 aws-secret-access-key (string->utf8 str)))) ;; (let ((signature (generate-signature))) ;; (display signature) ;; (newline)) (define-syntax define-finder (syntax-rules () ((_ name proc) (define (name tree) (cond ((null? tree) #f) ((symbol? (car tree)) (if (eq? 'name (car tree)) (proc tree) (name (cdr tree)))) ((pair? (car tree)) (or (name (car tree)) (name (cdr tree)))) (else (name (cdr tree)))))))) (define-finder aws:MediumImage (lambda (tree) (cadr (cadr tree)))) (define-finder aws:Title (lambda (tree) (cadr tree))) (define-finder aws:ISBN (lambda (tree) (cadr tree))) (define-finder aws:EAN (lambda (tree) (cadr tree))) (define (get-image isbn proc) (let* ((parameters (cons `(Timestamp . ,(date->string (current-date 0) "~5Z")) *aws-parameters*)) (signature (generate-signature isbn parameters)) (url (format "http://~a~a?~a" *aws-authority* *aws-path* (generate-query `((ItemId . ,isbn) (Signature . ,signature) ,@parameters))))) (log:info "url: ~a~%" url) (call-with-values (lambda () (http:get url)) (lambda (status headers body) (case status ((200) (log:info "~a" (utf8->string body)) ;;body (call-with-port (open-string-input-port (utf8->string body)) (lambda (iport) (let ((tree (ssax:xml->sxml iport '((aws . "http://webservices.amazon.com/AWSECommerceService/2009-07-01"))))) (proc (aws:EAN tree) (aws:ISBN tree) (aws:Title tree) (aws:MediumImage tree))))) ) (else (proc #f #f #f #f))))))) (define (start) (let ((socket (make-server-socket (number->string query-port-number)))) (let loop ((client (socket-accept socket))) (call-with-port (socket-port client) (lambda (port) (let ((bv (get-bytevector-all port))) (cond ((eof-object? bv) (shutdown-output-port port)) (else (let ((isbn (utf8->string bv))) (get-image isbn (lambda (isbn13 isbn10 title url) (if (and isbn13 isbn10 title) (call-with-port (transcoded-port port (make-transcoder (utf-8-codec) (eol-style none))) (lambda (tport) (put-string tport isbn13) (newline tport) (put-string tport isbn10) (newline tport) (put-string tport title) (newline tport) (when url (put-string tport url) (newline tport)) (flush-output-port tport) (shutdown-output-port tport))) (shutdown-output-port port)))))))))) (usleep 1000000) (loop (socket-accept socket))))) (define (query-image isbn) (call-with-socket (make-client-socket "localhost" (number->string query-port-number) AF_INET SOCK_STREAM (if on-freebsd AI_ADDRCONFIG (+ AI_V4MAPPED AI_ADDRCONFIG))) ; workaround for FreeBSD 7.x, cf. http://lists.freebsd.org/pipermail/freebsd-bugs/2008-February/028260.html (lambda (socket) (call-with-port (transcoded-port (socket-port socket) (make-transcoder (utf-8-codec) (eol-style none))) (lambda (port) (put-string port isbn) (shutdown-output-port port) (get-string-all port)))))) )
true
ab31b219044ee40ef2b92c3619e5088bc4e44a93
5b599bf9bb42b938419adaa919293833ef8c7590
/rpi/gpiomem.sls
e9c00b15d53ee80a9d3c43cfd5a56b43b96b6d75
[]
no_license
akce/chez-rpi
f8c42463248b241599a741fd32a42ddcb19765f0
bdd194eaf41b7c2e85417aa10daf33f31720c05e
refs/heads/master
2020-07-22T05:30:14.368752
2019-09-28T11:47:12
2019-09-28T11:47:12
207,087,203
3
0
null
null
null
null
UTF-8
Scheme
false
false
6,313
sls
gpiomem.sls
;; Chez scheme Raspberry Pi GPIO library. ;; ;; Copyright (c) 2019 Akce. MIT licensed. ;; ;; NOTE: DEPRECATED! ;; NOTE: GPIO sysfs has been replaced by a GPIO character device interface. Use that instead. ;; ;; This is an attempt at a pure Chez implementation of GPIO control functions for a Raspberry Pi under a Raspbian based OS. ;; ;; Currently only BCM GPIO pin numbering is supported. ;; ;; Useful Raspberry Pi GPIO resources: ;; ;; https://www.raspberrypi.org/documentation/hardware/raspberrypi/gpio/README.md ;; ;; Raspberry Pi foundation GPIO homepage. It describes the GPIOs and contains a number of useful links. ;; ;; https://www.raspberrypi.org/documentation/hardware/raspberrypi/bcm2835/BCM2835-ARM-Peripherals.pdf ;; https://elinux.org/BCM2835_datasheet_errata ;; ;; BCM2835 Datasheet & Errata. ;; ;; https://elinux.org/RPi_Low-level_peripherals ;; https://elinux.org/RPi_GPIO_Code_Samples ;; ;; https://pypi.org/project/RPi.GPIO/ ;; For info on /dev/mem (and by extension /dev/gpiomem): ;; ;; $ man 4 mem ;; ;; https://github.com/raspberrypi/linux/pull/1112 ;; ;; Background for /dev/gpiomem (library (rpi gpiomem) (export gpio-open gpio-close gpio-function-select gpio-high! gpio-low! gpio-read ;; Low-level procs. Export for debugging. reg-read reg-set!) (import (chezscheme) (rpi ftypes-util)) (define load-libc (load-shared-object "libc.so.6")) (c_funcs ;; int open(const char* pathname, int flags); (open (string int) int) ;; int close(int fd); (close (int) int) ;; void* mmap(void* addr, size_t length, int prot, int flags, int fd, off_t offset); ;; NB: offset should be off_t but Chez ftypes doesn't define it. GLIBC's unistd.h in its description ;; of type sizes groups pointer and off_t together, as at 2019 anyway, so use pointer instead. (mmap (void* size_t int int int ptrdiff_t) void*) ;; int munmap(void* addr, size_t length); (munmap (void* size_t) int)) ;; internal: ftype pointer to our mmap'd memory. (define gpio-memory #f) ;; datasheet pg 90 specifies 41 x 32-bit registers for GPIO. (define-ftype register-map (array 41 unsigned-32)) (define BLOCK_SIZE (* 4 1024)) (define PAGE_SIZE (* 4 1024)) (define O_RDRW 2) (define O_SYNC #x101000) (define O_FLAGS (bitwise-ior O_RDRW O_SYNC)) (define PROT_READ 1) (define PROT_WRITE 2) (define PROT_FLAGS (bitwise-ior PROT_READ PROT_WRITE)) (define MAP_SHARED 1) ;; NB: This only works on linux kernels that have the Raspbian /dev/gpiomem extension. (define gpio-open (lambda () (let ([fd (open "/dev/gpiomem" O_FLAGS)]) (let ([mm (mmap 0 BLOCK_SIZE PROT_FLAGS MAP_SHARED fd 0)]) (close fd) (set! gpio-memory (make-ftype-pointer register-map mm)) gpio-memory)))) (define reg-set! (lambda (offset value) (ftype-set! register-map (offset) gpio-memory value))) (define reg-read (lambda (offset) (ftype-ref register-map (offset) gpio-memory))) (define gpio-close (lambda () (munmap (ftype-pointer-address gpio-memory) BLOCK_SIZE))) ;; GPIO Function Select Registers (GPFSELn) ;; See datasheet pg 91+. (define GPFSEL0 0) ;; FSELn lists the pin config value enumeration. (enum FSELn (FSEL_MASK #b111) (FSEL_INPUT #b000) (FSEL_OUTPUT #b001) (FSEL_ALTERNATE0 #b100) (FSEL_ALTERNATE1 #b101) (FSEL_ALTERNATE2 #b110) (FSEL_ALTERNATE3 #b111) (FSEL_ALTERNATE4 #b011) (FSEL_ALTERNATE5 #b010)) (define FSELn->symbol (lambda (x) (cond [(fx=? x FSEL_INPUT) 'INPUT] [(fx=? x FSEL_OUTPUT) 'OUTPUT] [(fx=? x FSEL_ALTERNATE0) 'ALTERNATE0] [(fx=? x FSEL_ALTERNATE1) 'ALTERNATE1] [(fx=? x FSEL_ALTERNATE2) 'ALTERNATE2] [(fx=? x FSEL_ALTERNATE3) 'ALTERNATE3] [(fx=? x FSEL_ALTERNATE4) 'ALTERNATE4] [(fx=? x FSEL_ALTERNATE5) 'ALTERNATE5] [else #f]))) (define symbol->FSELn (lambda (x) (case x [(INPUT) FSEL_INPUT] [(OUTPUT) FSEL_OUTPUT] [(ALTERNATE0) FSEL_ALTERNATE0] [(ALTERNATE1) FSEL_ALTERNATE1] [(ALTERNATE2) FSEL_ALTERNATE2] [(ALTERNATE3) FSEL_ALTERNATE3] [(ALTERNATE4) FSEL_ALTERNATE4] [(ALTERNATE5) FSEL_ALTERNATE5] [else #f]))) (define gpfsel-register-and-shift (lambda (gpio) ;; Each GPFSEL register can configure 10 GPIO pins @ 3 bits per GPIO (see FSELn). (let-values ([(register mod) (fxdiv-and-mod gpio 10)]) (values register (* 3 mod))))) (define gpio-function-select (case-lambda [(gpio) ; get (let-values ([(reg off) (gpfsel-register-and-shift gpio)]) (let ([data (reg-read reg)] [mask (bitwise-arithmetic-shift-left FSEL_MASK off)]) (FSELn->symbol (bitwise-arithmetic-shift-right (bitwise-and data mask) off))))] [(gpio function) ; set (let-values ([(reg off) (gpfsel-register-and-shift gpio)]) (let ([data (reg-read reg)] [mask (bitwise-not (bitwise-arithmetic-shift-left FSEL_MASK off))] [val (symbol->FSELn function)]) (if val (reg-set! reg (bitwise-ior (bitwise-and mask data) ; zero the old gpio bits (bitwise-arithmetic-shift-left val off))) (display "invalid value\n"))))])) ;; GPIO Pin Output Set Registers (GPSETn) ;; See datasheet pg 95. (define GPSET0 7) (define gpset-register-and-shift (lambda (gpio) (fxdiv-and-mod gpio 32))) (define gpio-high! (lambda (gpio) (let-values ([(reg off) (gpset-register-and-shift gpio)]) (reg-set! (+ GPSET0 reg) (bitwise-arithmetic-shift-left 1 off))))) ;; GPIO Pin Output Clear Registers (GPCLRn) ;; See datasheet pg 95-96. (define GPCLR0 10) (define gpio-low! (lambda (gpio) (let-values ([(reg off) (gpset-register-and-shift gpio)]) (reg-set! (+ GPCLR0 reg) (bitwise-arithmetic-shift-left 1 off))))) ;; GPIO Pin Level Registers (GPLEVn) ;; See datasheet pg 96. (define GPLEV0 13) (define gpio-read (lambda (gpio) (let-values ([(reg off) (gpset-register-and-shift gpio)]) (bitwise-and #x1 (bitwise-arithmetic-shift-right (reg-read (+ GPLEV0 reg)) off))))))
false
2b2682530f097d48c662fe185dc195689331d2ee
be9cdbb9f12ea91e50c9e234262e98ba34637a30
/config.scm
efe2577b0c8392e2775386edc47f15d18e1709e9
[]
no_license
xavierm02/guix-config
0bd944b222248fcd131f6a6a422a2cb1fbe8688f
6951532aa1fe6602848605ed281e3aebfa2156c7
refs/heads/master
2020-06-02T06:03:37.009319
2019-06-25T18:58:01
2019-06-25T18:58:01
191,062,824
0
0
null
null
null
null
UTF-8
Scheme
false
false
13,945
scm
config.scm
; TODO ; https://www.gnu.org/software/guix/manual/en/html_node/Miscellaneous-Services.html#Miscellaneous-Services ; iptables-service-type ; cups? ; Only enter decryption password once ; swap? ; redshift ; ibus ; brightnessctl? ; vm stuff? ; TODO duplicity for backup? ; diffoscope? ; fprintd fingerprint reader? ; autojump? ; interrobang ? ; stow for dotafiles? ; ungoogled-chromium ;; guix repl < ~/config/main.scm ;; ibus latex ;; youtube-dl ;; volumeicon (define (endcons l x) (append l (list x))) (add-to-load-path "/home/xavierm02/config") (define (assert b) (if (not b) (throw 'ASSERT-FAILURE))) ; TODO (define (maybe-warn b m) (if b (display m))) (define (partial-map f l) (map (lambda (x) (let ((result (f x))) (if (equal? result #f) x result))))) (define is_server #f) (define (impl x y) (or (not x) y)) (define (my-eval expr) (eval expr (interaction-environment))) (use-modules (gnu) (srfi srfi-1) (srfi srfi-9) (nongnu packages linux) (nongnu packages compression) ;(nonfree packages linux) ;(nonfree packages compression) (ice-9 pretty-print) (guix packages) (rnrs lists) (ice-9 popen) (ice-9 textual-ports) (srfi srfi-9 gnu) ;(system-with-type) ; TODO make system export <operating-system> (gnu services nix) (ice-9 match) (guix records) ) (use-service-modules avahi dbus desktop networking pm ; sddm sound ssh xorg ) (use-package-modules admin backup commencement compression cpio cryptsetup disk efi emacs file freedesktop gnome ; for nm-applet TODO remove? libusb linux llvm nano ocaml python readline shells suckless xdisorg xfce xorg version-control vim w3m wget wm ) (define <operating-system> (record-type-descriptor (operating-system (bootloader #f) (host-name #f) (file-systems #f) (timezone #f)))) (define (operating-system-firmware os) ((record-accessor <operating-system> 'firmware) os)) ;;;;;;;;;;;;;;;; ;; OS printer ;; ;;;;;;;;;;;;;;;; (define (package->specification pkg) (package-name pkg)) (define (package->sexpr pkg) `(specification->package ,(package->specification pkg))) (define (user->sexpr user) `(user-account (name ,(user-account-name user)))) (define (os->sexpr os) `(operating-system (kernel ,(package->sexpr (operating-system-kernel os))) (firmware (map specification->package (list ,@(map package->specification (operating-system-firmware os))))) (host-name ,(operating-system-host-name os)) (users (list ,@(map user->sexpr (operating-system-users os)))) (packages (map specification->package (list ,@(map package->specification (operating-system-packages os))))) (services (list ,@(map service-name (operating-system-services os)))) )) (define (append-warn l1 l2) (every (lambda (x2) (maybe-warn (any (lambda (x1) (equal? x1 x2)) l1) "WARN\r\n")) l2) (append l1 l2)) (define (partial-map-warn f l m) (maybe-warn (every (lambda (x) (equal? (f x) #f)) l) "WARN\r\n") (partial-map f l)) (define (filter-warn p l m) (maybe-warn (every p l) "WARN\r\n")) ;; Services (define (service-name srv) (service-type-name (service-kind srv))) (define (name->service-predicate srv name) (equal? (service-name srv) name)) (define (service->service-predicate p) (if (service-type? p) (lambda (srv) (equal? (service-kind srv) p)) p)) ;(remove ; (lambda (service) (eq? (service-kind service) gdm-service-type)) ; %desktop-services (define my-keyboard-layout (keyboard-layout "us" "altgr-intl") ) ;;;;;;;;;;;; ; Services ; ;;;;;;;;;;;; (define i3-service (simple-service 'i3-packages profile-service-type (list dmenu i3-wm i3lock i3status))) (define my-services (cons* (service nix-service-type) ;; Desktop i3-service (screen-locker-service i3lock) ;(sddm-service) ;(service xfce-desktop-service-type) ;; Screen lockers are a pretty useful thing and these are small. ;(screen-locker-service slock) ;(screen-locker-service xlockmore "xlock") ;; Network (service wpa-supplicant-service-type) (service network-manager-service-type) (simple-service 'network-manager-applet profile-service-type (list network-manager-applet) ) (service modem-manager-service-type) ;; Laptop (service tlp-service-type) ; Power saving ;; Add udev rules for MTP devices so that non-root users can access them. (simple-service 'mtp udev-service-type (list libmtp)) ;; The D-Bus clique. (service avahi-service-type) (udisks-service) (service upower-service-type) ; Battery (accountsservice-service) (service cups-pk-helper-service-type) (colord-service) (geoclue-service) ; Location (service polkit-service-type) (elogind-service) ; Button and lid events (dbus-service) (service ntp-service-type) x11-socket-directory-service (service alsa-service-type) (service thermald-service-type) (bluetooth-service) (set-xorg-configuration (xorg-configuration (keyboard-layout my-keyboard-layout) ) ) %base-services ) ) ;(display (map service-name my-services)) (define my-services-with-config (modify-services my-services (bluetooth-service-type config => (bluetooth-configuration (auto-enable? #f) ) ) (elogind-service-type config => (elogind-configuration (inherit config) ; Handle events (handle-power-key 'suspend) (handle-suspend-key 'suspend) (handle-hibernate-key 'hibernate) (handle-lid-switch 'suspend) (handle-lid-switch-docked 'ignore) ; Allow programs to prevent actions (power-key-ignore-inhibited? #f) (suspend-key-ignore-inhibited? #f) (hibernate-key-ignore-inhibited? #f) (lid-switch-ignore-inhibited? #f) ; Do nothing if idle (idle-action 'ignore) ) ) #|(sddm-service-type config => (sddm-configuration (inherit config) (numlock "on") (theme "elarun") ; TODO other theme? (remember-last-user? #t) (remember-last-session? #t) ) )|# (tlp-service-type config => (tlp-configuration (inherit config) (tlp-default-mode "BAT") (energy-perf-policy-on-ac "performance") (energy-perf-policy-on-bat "normal") (wifi-pwr-on-ac? #f) (wifi-pwr-on-bat? #f) (usb-autosuspend? #t) ) ) (upower-service-type config => (upower-configuration (inherit config) (poll-batteries? #t) (use-percentage-for-policy? #f) (time-low (* 60 60)) (time-critical (* 20 60)) (time-action (* 10 60)) (critical-power-action 'hibernate) ) ) ;(remove ; (lambda (service) (eq? (service-kind service) gdm-service-type)) ; %desktop-services ;) ) ) ;;;;;;;;;;;; ; Packages ; ;;;;;;;;;;;; (define my-base-packages (cons* (specification->package "nss-certs") %base-packages ) ) (define my-cli-packages ;; TODO specification->package (list ;; Shells fish ;; Editors emacs nano vim ;; Archives archivemount atool ; bzip2 already in %base-packages cpio ; gzip already in %base-packages p7zip ; tar already in %base-packages unrar unzip ; xz already in %base-packages zip ;; Admin daemontools dfc di dstat htop iftop inetutils progress tree ;; ?? TODO git wget ;; Web browsers ; elinks TODO w3m ;; ?? TODO gcc-toolchain ocaml ocamlbuild python ;; ?? TODO efitools ;; ?? TODO rlwrap ;; ?? TODO brightnessctl ;; ?? TODO hostapd dmidecode acpica pscircle ;; ?? solaar ;; Logitech Unifying Receiver ;; ?? cryptsetup llvm;? lvm2;dmsetup to decrypt files with gparted file mercurial ) ) (define my-desktop-packages (list ;; Xorg xinit ;; Window managers xfce ;xmonad ;; Freedesktop.org xdg-utils ;; open xdg-user-dirs ;; ?? TODO redshift ; TODO redshift-gtk xclip scrot ;unclutter? ;gparted ; TODO replace by something else ;; Screens arandr autorandr gedit xinit ) ) (define xavierm02-user-account (user-account (name "xavierm02") (comment "Xavier Montillet") (group "users") (home-directory "/home/xavierm02") (shell #~(string-append #$fish "/bin/fish")) (supplementary-groups (list "audio" "kvm" "netdev" "video" "wheel")))) (define (maybe-append l1 l2) (delete-duplicates (append l1 l2))) ;; TODO more efficient? (define my-packages (append my-base-packages my-cli-packages my-desktop-packages ) ) (define my-os (operating-system (locale "en_US.utf8") (timezone "Europe/Paris") (keyboard-layout my-keyboard-layout) (bootloader (bootloader-configuration (bootloader grub-efi-bootloader) (target "/boot/efi") (timeout 1) (keyboard-layout my-keyboard-layout) ) ) (mapped-devices (list (mapped-device (source (uuid "8400b3bd-798b-4464-ac93-da71be0c674f")) (target "cryptroot") (type luks-device-mapping) ) ) ) (file-systems (cons* (file-system (mount-point "/boot/efi") (device (uuid "D917-8239" 'fat32)) (type "vfat") ) (file-system (mount-point "/") (device "/dev/mapper/cryptroot") (type "ext4") (dependencies mapped-devices) ) %base-file-systems ) ) (users (append %base-user-accounts ) ) (host-name "GT") (services my-services) (packages my-packages) ) ) #| (define-syntax-rule (modify-os os mods ...) (match-record os <operating-system> (record-type-fields <operating-system>) (operating-system (inherit os) mods ...))) |# (define-syntax-rule (modify-os (key value) ...) (lambda (os) (operating-system (inherit os) (key (let ((key ((record-accessor <operating-system> 'key) os))) value)) ...))) (setvbuf (current-output-port) 'none) (define (maybe b t) (if b t 'None)) (define-record-type* <operating-system-modification> operating-system-modification make-operating-system-modification operating-system-modification? this-operating-system-modification (name operating-system-modification-name (default "<No name>")) (description operating-system-modification-description (default "<No description>")) (message-start operating-system-modification-message-start (default "<No start message>...")) (message-done operating-system-modification-message-done (default " Done.")) (message-skip operating-system-modification-message-skip (default "<No skip message>")) (condition operating-system-modification-condition (default (lambda (os) #t))) (modification operating-system-modification-modification)) (define (operating-system-modification->procedure mod) (lambda (os) (match-record mod <operating-system-modification> (name description message-start message-done message-skip condition modification) (if (condition os) (begin (display message-start) (let ((new-os (modification os))) (begin (display message-done) (newline) new-os))) (begin (display message-skip) (newline) os))))) (define my-modifications (list (operating-system-modification (name "iwlwifi") (description "If the Wi-Fi chip requires non-free software (detected by \"Intel Corporation Wireless\" being a substring of the result of lspci), replace the kernel by linux and add iwlwifi-firmware.") (message-start "Adding firmware-iwlwifi") (message-skip "Not adding firmware-iwlwifi.") (condition (lambda (os) (string-contains (system-str "lspci") "Intel Corporation Wireless"))) (modification (modify-os (kernel linux) (firmware (endcons firmware iwlwifi-firmware))))) (operating-system-modification (name "xavierm02") (message-start "Adding xavierm02") (modification (modify-os (users (append users (list xavierm02-user-account)))))) )) (define (system-str cmd) (let* ((port (open-input-pipe cmd)) (output (get-string-all port))) (begin (close-pipe port) output))) (define (compose-procedures procs) (lambda (x) (fold-right (lambda (f y) (f y)) x procs))) (define (os-apply-modifications mods os) ((compose-procedures (map operating-system-modification->procedure mods)) os)) (define my-os-result (os-apply-modifications my-modifications my-os)) (display (os->sexpr my-os-result)) (if (string-contains (string-join (command-line) " ") "guix system reconfigure") my-os-result)
true
371d7f96db2b928d095ae3a790e2be57f51ee94c
ec68462c2ecd1d4349b4873c76feecf6acac956b
/read.scm
f1e933ea8db8b0afea903543fc4835c069a15f13
[]
no_license
k16shikano/tef
0df88700b457986cdc44c573c176f2153d044617
152856a47ee5a386b62d176cd9084c2defd67cb8
refs/heads/master
2020-04-16T06:17:33.272981
2015-11-13T01:45:03
2015-11-13T01:45:03
200,700
2
0
null
null
null
null
UTF-8
Scheme
false
false
2,986
scm
read.scm
(define-module read (use srfi-1) (use srfi-13) (use tokenlist-utils) (export-all) ) (select-module read) ;; special category code ;; code < 0 : control sequence ;; code = -1 : terminated with a character or eof ;; others : TeX category code ;; string-port -> [(code . token)] (define (read-tex-token . iport) (define (in-ctrl-seq c seq p) (let ((x (peek-char p))) (cond ((or (eof-object? (peek-char p)) (char=? #\newline c)) (cons -1 seq)) ((char-set-contains? #[\s] x) (in-spaces x seq #t #f p)) ((and (char-set-contains? #[\W\d_] x) (char-set-contains? #[^@] x)) (cond ((string-null? seq) (cons -1 (string (read-char p)))) (else (cons -1 seq)))) (else (in-ctrl-seq (read-char p) (string+char seq x) p))))) (define (in-spaces c seq S? N? p) (cond ((or (eof-object? (peek-char p)) (char-set-contains? #[^\s] (peek-char p))) (cond ((not (string-null? seq)) (cons -1 seq)) (N? (cons -1 "par")) (S? (cons 5 #\newline)) (else (cons 10 #\space)))) (else (in-spaces (read-char p) seq S? N? p)))) (define (in-comment c p) (cond ((char=? #\newline (peek-char p)) (read-char p) (loop (peek-char p) p)) ; (cons 5 #\newline)) (else (in-comment (read-char p) p)))) (define (in-newlines c N? p) (cond ((eof-object? (peek-char p)) (peek-char p)) ((char-set-contains? #[\x0d\x0a] (peek-char p)) (in-spaces (read-char p) "" #t #t p)) ((char-set-contains? #[\s] (peek-char p)) (in-spaces (read-char p) "" #t #f p)) (else (cons 10 #\space)))) (define (loop c p) (cond ((eof-object? c) c) ((char=? #\\ c) (read-char p) ; spend a backslash (let ((x (peek-char p))) (cond ((char-set-contains? #[{}$&#^_%~] x) (cons 12 (read-char p))) (else (in-ctrl-seq x "" p))))) ((char=? #\{ c) (cons 1 (read-char p))) ((char=? #\} c) (cons 2 (read-char p))) ((char=? #\$ c) (cons 3 (read-char p))) ((char=? #\& c) (cons 4 (read-char p))) ((char-set-contains? #[\x0d\x0a] c) (in-newlines (read-char p) #f p)) ((char=? #\# c) (cons 6 (read-char p))) ((char=? #\^ c) (cons 7 (read-char p))) ((char=? #\_ c) (cons 8 (read-char p))) ((char=? #\null c) (cons 9 (read-char p))) ((char=? #\space c) (in-spaces (read-char p) "" #f #f p)) ((char-set-contains? #[a-zA-Z] c) (cons 11 (read-char p))) ((char=? #\~ c) (cons 13 (read-char p))) ((char=? #\% c) (in-comment (read-char p) p)) ((char=? #\delete c) (cons 15 (read-char p))) (else (cons 12 (read-char p))))) (let ((p (if (null? iport) (current-input-port) (car iport)))) (loop (peek-char p) p))) (define (string->tokenlist str) (with-input-from-string str (lambda () (port-map values read-tex-token)))) (define (port->tokenlist p) (port->list read-tex-token p)) (provide "read")
false
ec8e16d0293636321d4b9745daf19dc41ef5acf0
8a0660bd8d588f94aa429050bb8d32c9cd4290d5
/sitelib/srfi/%3a86/mu-and-nu.scm
69fd48ffa1bf5f1b020507a5f53ccba30e42256a
[ "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
41,067
scm
mu-and-nu.scm
;;; -*- mode:scheme; coding: utf-8; -*- ;;; ;;; mu-and-nu.scm - SRFI-86 library. ;;; ;;; Copyright (c) 2010-2012 Takashi Kato <[email protected]> ;;; ;;; Redistribution and use in source and binary forms, with or without ;;; modification, are permitted provided that the following conditions ;;; are met: ;;; ;;; 1. Redistributions of source code must retain the above copyright ;;; notice, this list of conditions and the following disclaimer. ;;; ;;; 2. Redistributions in binary form must reproduce the above copyright ;;; notice, this list of conditions and the following disclaimer in the ;;; documentation and/or other materials provided with the distribution. ;;; ;;; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ;;; "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT ;;; LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR ;;; A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT ;;; OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, ;;; SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED ;;; TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR ;;; PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF ;;; LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING ;;; NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS ;;; SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ;;; (library (srfi :86 mu-and-nu) (export mu nu alet alet*) (import (rnrs) (srfi :8 receive)) ;;; From SRFI-86 reference implementation ;;; mu & nu (define-syntax mu (syntax-rules () ((mu argument ...) (lambda (f) (f argument ...))))) (define-syntax nu (syntax-rules () ((nu argument ...) (lambda (f) (apply f argument ...))))) ;;; alet (define-syntax alet (syntax-rules () ((alet (bn ...) bd ...) (%alet () () (bn ...) bd ...)) ((alet var (bn ...) bd ...) (%alet (var) () (bn ...) bd ...)))) (define-syntax %alet (syntax-rules (opt cat key rec and values) ((%alet () ((n v) ...) () bd ...) ((lambda (n ...) bd ...) v ...)) ((%alet (var) ((n v) ...) () bd ...) ((letrec ((var (lambda (n ...) bd ...))) var) v ...)) ((%alet (var (p ...) (nv ...) (bn ...)) ((n v) ...) () bd ...) ((letrec ((t (lambda (v ...) (%alet (p ...) (nv ... (n v) ... (var t)) (bn ...) bd ...)))) t) v ...)) ((%alet (p ...) (nv ...) ((() a b ...) bn ...) bd ...) ((lambda () a b ... (%alet (p ...) (nv ...) (bn ...) bd ...)))) ((%alet (p ...) (nv ...) (((a) c) bn ...) bd ...) ((lambda (t) (%alet (p ...) (nv ... (a t)) (bn ...) bd ...)) c)) ((%alet (p ...) (nv ...) (((values a) c) bn ...) bd ...) ((lambda (t) (%alet (p ...) (nv ... (a t)) (bn ...) bd ...)) c)) ((%alet (p ...) (nv ...) (((values . b) c d ...) bn ...) bd ...) (%alet "dot" (p ...) (nv ...) (values) (b c d ...) (bn ...) bd ...)) ((%alet "dot" (p ...) (nv ...) (values t ...) ((a . b) c ...) (bn ...) bd ...) (%alet "dot" (p ...) (nv ... (a tn)) (values t ... tn) (b c ...) (bn ...) bd ...)) ((%alet "dot" (p ...) (nv ...) (values t ...) (() c) (bn ...) bd ...) (receive (t ...) c (%alet (p ...) (nv ...) (bn ...) bd ...))) ((%alet "dot" (p ...) (nv ...) (values t ...) (() c ...) (bn ...) bd ...) ((lambda (t ...) (%alet (p ...) (nv ...) (bn ...) bd ...)) c ...)) ((%alet "dot" (p ...) (nv ...) (values t ...) (b c) (bn ...) bd ...) (receive (t ... . tn) c (%alet (p ...) (nv ... (b tn)) (bn ...) bd ...))) ((%alet "dot" (p ...) (nv ...) (values t ...) (b c ...) (bn ...) bd ...) ((lambda (t ... . tn) (%alet (p ...) (nv ... (b tn)) (bn ...) bd ...)) c ...)) ((%alet (p ...) (nv ...) (((a . b) c d ...) bn ...) bd ...) (%alet "dot" (p ...) (nv ... (a t)) (t) (b c d ...) (bn ...) bd ...)) ((%alet "dot" (p ...) (nv ...) (t ...) ((a . b) c ...) (bn ...) bd ...) (%alet "dot" (p ...) (nv ... (a tn)) (t ... tn) (b c ...) (bn ...) bd ...)) ((%alet "dot" (p ...) (nv ...) (t ...) (() c) (bn ...) bd ...) (c (lambda (t ...) (%alet (p ...) (nv ...) (bn ...) bd ...)))) ((%alet "dot" (p ...) (nv ...) (t ...) (() c ...) (bn ...) bd ...) ((lambda (t ...) (%alet (p ...) (nv ...) (bn ...) bd ...)) c ...)) ((%alet "dot" (p ...) (nv ...) (t ...) (b c) (bn ...) bd ...) (c (lambda (t ... . tn) (%alet (p ...) (nv ... (b tn)) (bn ...) bd ...)))) ((%alet "dot" (p ...) (nv ...) (t ...) (b c ...) (bn ...) bd ...) ((lambda (t ... . tn) (%alet (p ...) (nv ... (b tn)) (bn ...) bd ...)) c ...)) ((%alet (p ...) (nv ...) ((and (n1 v1 t1 ...) (n2 v2 t2 ...) ...) bn ...) bd ...) (%alet "and" (p ...) (nv ...) ((n1 v1 t1 ...) (n2 v2 t2 ...) ...) (bn ...) bd ...)) ((%alet "and" (p ...) (nv ...) ((n v) nvt ...) (bn ...) bd ...) (let ((t v)) (and t (%alet "and" (p ...) (nv ... (n t)) (nvt ...) (bn ...) bd ...)))) ((%alet "and" (p ...) (nv ...) ((n v t) nvt ...) (bn ...) bd ...) (let ((tt v)) (and (let ((n tt)) t) (%alet "and" (p ...) (nv ... (n tt)) (nvt ...) (bn ...) bd ...)))) ((%alet "and" (p ...) (nv ...) () (bn ...) bd ...) (%alet (p ...) (nv ...) (bn ...) bd ...)) ((%alet (p ...) (nv ...) ((opt z a . e) bn ...) bd ...) (%alet "opt" (p ...) (nv ...) z (a . e) (bn ...) bd ...)) ((%alet "opt" (p ...) (nv ...) z ((n d t ...)) (bn ...) bd ...) (let ((x (if (null? z) d (if (null? (cdr z)) (wow-opt n (car z) t ...) (error "alet: too many arguments" (cdr z)))))) (%alet (p ...) (nv ... (n x)) (bn ...) bd ...))) ((%alet "opt" (p ...) (nv ...) z ((n d t ...) . e) (bn ...) bd ...) (let ((y (if (null? z) z (cdr z))) (x (if (null? z) d (wow-opt n (car z) t ...)))) (%alet "opt" (p ...) (nv ... (n x)) y e (bn ...) bd ...))) ((%alet "opt" (p ...) (nv ...) z e (bn ...) bd ...) (let ((te z)) (%alet (p ...) (nv ... (e te)) (bn ...) bd ...))) ((%alet (p ...) (nv ...) ((cat z a . e) bn ...) bd ...) (let ((y z)) (%alet "cat" (p ...) (nv ...) y (a . e) (bn ...) bd ...))) ((%alet "cat" (p ...) (nv ...) z ((n d t ...)) (bn ...) bd ...) (let ((x (if (null? z) d (if (null? (cdr z)) (wow-cat-end z n t ...) (error "alet: too many arguments" (cdr z)))))) (%alet (p ...) (nv ... (n x)) (bn ...) bd ...))) ((%alet "cat" (p ...) (nv ...) z ((n d t ...) . e) (bn ...) bd ...) (let ((x (if (null? z) d (wow-cat! z n d t ...)))) (%alet "cat" (p ...) (nv ... (n x)) z e (bn ...) bd ...))) ((%alet "cat" (p ...) (nv ...) z e (bn ...) bd ...) (let ((te z)) (%alet (p ...) (nv ... (e te)) (bn ...) bd ...))) ((%alet (p ...) (nv ...) ((key z a . e) bn ...) bd ...) (let ((y z)) (%alet "key" (p ...) (nv ...) y () () (a . e) () (bn ...) bd ...))) ((%alet "key" (p ...) (nv ...) z () (ndt ...) (((n k) d t ...) . e) (kk ...) (bn ...) bd ...) (%alet "key" (p ...) (nv ...) z () (ndt ... ((n k) d t ...)) e (kk ... k) (bn ...) bd ...)) ((%alet "key" (p ...) (nv ...) z () (ndt ...) ((n d t ...) . e) (kk ...) (bn ...) bd ...) (%alet "key" (p ...) (nv ...) z () (ndt ... ((n 'n) d t ...)) e (kk ... 'n) (bn ...) bd ...)) ((%alet "key" (p ...) (nv ...) z () (ndt nd ...) (#t . e) (kk k ...) (bn ...) bd ...) (%alet "key" (p ...) (nv ...) z (#t) (ndt nd ...) e (kk k ...) (bn ...) bd ...)) ((%alet "key" (p ...) (nv ...) z () (ndt nd ...) (#f . e) (kk k ...) (bn ...) bd ...) (%alet "key" (p ...) (nv ...) z (#f) (ndt nd ...) e (kk k ...) (bn ...) bd ...)) ((%alet "key" (p ...) (nv ...) z (o ...) (((n k) d t ...) ndt ...) e (kk ...) (bn ...) bd ...) (let ((x (if (null? z) d (wow-key! z (o ...) (kk ...) (n k) d t ...)))) (%alet "key" (p ...) (nv ... (n x)) z (o ...) (ndt ...) e (kk ...) (bn ...) bd ...))) ((%alet "key" (p ...) (nv ...) z (o ...) () () (kk ...) (bn ...) bd ...) (if (null? z) (%alet (p ...) (nv ...) (bn ...) bd ...) (error "alet: too many arguments" z))) ((%alet "key" (p ...) (nv ...) z (o ...) () e (kk ...) (bn ...) bd ...) (let ((te z)) (%alet (p ...) (nv ... (e te)) (bn ...) bd ...))) ((%alet (p ...) (nv ...) ((rec (n v) (nn vv) ...) bn ...) bd ...) (%alet "rec" (p ...) (nv ... (n t)) ((n v t)) ((nn vv) ...) (bn ...) bd ...)) ((%alet "rec" (p ...) (nv ...) (nvt ...) ((n v) (nn vv) ...) (bn ...) bd ...) (%alet "rec" (p ...) (nv ... (n t)) (nvt ... (n v t)) ((nn vv) ...) (bn ...) bd ...)) ((%alet "rec" (p ...) (nv ...) ((n v t) ...) () (bn ...) bd ...) ((let ((n '<undefined>) ...) (let ((t v) ...) (set! n t) ... (mu n ...))) (lambda (t ...) (%alet (p ...) (nv ...) (bn ...) bd ...)))) ((%alet (p ...) (nv ...) ((a b) bn ...) bd ...) ((lambda (t) (%alet (p ...) (nv ... (a t)) (bn ...) bd ...)) b)) ((%alet (p ...) (nv ...) ((values a c) bn ...) bd ...) ((lambda (t) (%alet (p ...) (nv ... (a t)) (bn ...) bd ...)) c)) ((%alet (p ...) (nv ...) ((values a b c ...) bn ...) bd ...) (%alet "not" (p ...) (nv ... (a t)) (values t) (b c ...) (bn ...) bd ...)) ((%alet "not" (p ...) (nv ...) (values t ...) (a b c ...) (bn ...) bd ...) (%alet "not" (p ...) (nv ... (a tn)) (values t ... tn) (b c ...) (bn ...) bd ...)) ((%alet "not" (p ...) (nv ...) (values t ...) (z) (bn ...) bd ...) (receive (t ...) z (%alet (p ...) (nv ...) (bn ...) bd ...))) ((%alet (p ...) (nv ...) ((a b c ...) bn ...) bd ...) (%alet "not" (p ...) (nv ... (a t)) (t) (b c ...) (bn ...) bd ...)) ((%alet "not" (p ...) (nv ...) (t ...) (a b c ...) (bn ...) bd ...) (%alet "not" (p ...) (nv ... (a tn)) (t ... tn) (b c ...) (bn ...) bd ...)) ((%alet "not" (p ...) (nv ...) (t ...) (z) (bn ...) bd ...) (z (lambda (t ...) (%alet (p ...) (nv ...) (bn ...) bd ...)))) ((%alet (p ...) (nv ...) ((a) bn ...) bd ...) (call-with-current-continuation (lambda (t) (%alet (p ...) (nv ... (a t)) (bn ...) bd ...)))) ((%alet (p ...) (nv ...) ((a . b) bn ...) bd ...) (%alet "rot" (p ...) (nv ...) (a) b (bn ...) bd ...)) ((%alet "rot" (p ...) (nv ...) (new-bn ...) (a . b) (bn ...) bd ...) (%alet "rot" (p ...) (nv ...) (new-bn ... a) b (bn ...) bd ...)) ((%alet "rot" (p ...) (nv ...) (()) b (bn ...) bd ...) (%alet (b (p ...) (nv ...) (bn ...)) () () bd ...)) ((%alet "rot" (p ...) (nv ...) (new-bn ...) b (bn ...) bd ...) (%alet (b (p ...) (nv ...) (bn ...)) () (new-bn ...) bd ...)) ((%alet (p ...) (nv ...) (a b bn ...) bd ...) (b (lambda t (%alet (p ...) (nv ... (a t)) (bn ...) bd ...)))))) ;;; alet* (define-syntax alet* (syntax-rules (opt cat key rec and values) ((alet* () bd ...) ((lambda () bd ...))) ((alet* ((() a b ...) bn ...) bd ...) ((lambda () a b ... (alet* (bn ...) bd ...)))) ((alet* (((a) c) bn ...) bd ...) ((lambda (a) (alet* (bn ...) bd ...)) c)) ((alet* (((values a) c) bn ...) bd ...) ((lambda (a) (alet* (bn ...) bd ...)) c)) ((alet* (((values . b) c) bn ...) bd ...) (call-with-values (lambda () c) (lambda* b (alet* (bn ...) bd ...)))) ((alet* (((values . b) c d ...) bn ...) bd ...) (alet* "dot" (b c d ...) (bn ...) bd ...)) ((alet* "dot" ((a . b) c d ...) (bn ...) bd ...) ((lambda (a) (alet* "dot" (b d ...) (bn ...) bd ...)) c)) ((alet* "dot" (()) (bn ...) bd ...) (alet* (bn ...) bd ...)) ((alet* "dot" (b c ...) (bn ...) bd ...) ((lambda b (alet* (bn ...) bd ...)) c ...)) ((alet* (((a . b) c) bn ...) bd ...) (c (lambda* (a . b) (alet* (bn ...) bd ...)))) ((alet* (((a . b) c d ...) bn ...) bd ...) ((lambda (a) (alet* "dot" (b d ...) (bn ...) bd ...)) c)) ((alet* ((and (n1 v1 t1 ...) (n2 v2 t2 ...) ...) bn ...) bd ...) (alet-and* ((n1 v1 t1 ...) (n2 v2 t2 ...) ...) (alet* (bn ...) bd ...))) ((alet* ((opt z a . e) bn ...) bd ...) (%alet-opt* z (a . e) (alet* (bn ...) bd ...))) ((alet* ((cat z a . e) bn ...) bd ...) (let ((y z)) (%alet-cat* y (a . e) (alet* (bn ...) bd ...)))) ((alet* ((key z a . e) bn ...) bd ...) (let ((y z)) (%alet-key* y () () (a . e) () (alet* (bn ...) bd ...)))) ((alet* ((rec (n1 v1) (n2 v2) ...) bn ...) bd ...) (alet-rec* ((n1 v1) (n2 v2) ...) (alet* (bn ...) bd ...))) ((alet* ((a b) bn ...) bd ...) ((lambda (a) (alet* (bn ...) bd ...)) b)) ((alet* ((values a c) bn ...) bd ...) ((lambda (a) (alet* (bn ...) bd ...)) c)) ((alet* ((values a b c ...) bn ...) bd ...) (alet* "not" (values a) (b c ...) (bn ...) bd ...)) ((alet* "not" (values r ...) (a b c ...) (bn ...) bd ...) (alet* "not" (values r ... a) (b c ...) (bn ...) bd ...)) ((alet* "not" (values r ...) (z) (bn ...) bd ...) (call-with-values (lambda () z) (lambda* (r ...) (alet* (bn ...) bd ...)))) ((alet* ((a b c ...) bn ...) bd ...) (alet* "not" (a) (b c ...) (bn ...) bd ...)) ((alet* "not" (r ...) (a b c ...) (bn ...) bd ...) (alet* "not" (r ... a) (b c ...) (bn ...) bd ...)) ((alet* "not" (r ...) (z) (bn ...) bd ...) (z (lambda* (r ...) (alet* (bn ...) bd ...)))) ((alet* ((a) bn ...) bd ...) (call-with-current-continuation (lambda (a) (alet* (bn ...) bd ...)))) ((alet* ((a . b) bn ...) bd ...) (%alet* () () ((a . b) bn ...) bd ...)) ((alet* (a b bn ...) bd ...) (b (lambda a (alet* (bn ...) bd ...)))) ((alet* var (bn ...) bd ...) (%alet* (var) () (bn ...) bd ...)))) (define-syntax %alet* (syntax-rules (opt cat key rec and values) ((%alet* (var) (n ...) () bd ...) ((letrec ((var (lambda* (n ...) bd ...))) var) n ...)) ((%alet* (var (bn ...)) (n ...) () bd ...) ((letrec ((var (lambda* (n ...) (alet* (bn ...) bd ...)))) var) n ...)) ((%alet* (var (p ...) (nn ...) (bn ...)) (n ...) () bd ...) ((letrec ((var (lambda* (n ...) (%alet* (p ...) (nn ... n ... var) (bn ...) bd ...)))) var) n ...)) ((%alet* (p ...) (n ...) ((() a b ...) bn ...) bd ...) ((lambda () a b ... (%alet* (p ...) (n ...) (bn ...) bd ...)))) ((%alet* (p ...) (n ...) (((a) c) bn ...) bd ...) ((lambda (a) (%alet* (p ...) (n ... a) (bn ...) bd ...)) c)) ((%alet* (p ...) (n ...) (((values a) c) bn ...) bd ...) ((lambda (a) (%alet* (p ...) (n ... a) (bn ...) bd ...)) c)) ((%alet* (p ...) (n ...) (((values . b) c) bn ...) bd ...) (%alet* "one" (p ...) (n ...) (values) (b c) (bn ...) bd ...)) ((%alet* "one" (p ...) (n ...) (values r ...) ((a . b) c) (bn ...) bd ...) (%alet* "one" (p ...) (n ... a) (values r ... a) (b c) (bn ...) bd ...)) ((%alet* "one" (p ...) (n ...) (values r ...) (() c) (bn ...) bd ...) (call-with-values (lambda () c) (lambda* (r ...) (%alet* (p ...) (n ...) (bn ...) bd ...)))) ((%alet* "one" (p ...) (n ...) (values r ...) (b c) (bn ...) bd ...) (call-with-values (lambda () c) (lambda* (r ... . b) (%alet* (p ...) (n ... b) (bn ...) bd ...)))) ((%alet* (p ...) (n ...) (((values . b) c d ...) bn ...) bd ...) (%alet* "dot" (p ...) (n ...) (b c d ...) (bn ...) bd ...)) ((%alet* (p ...) (n ...) (((a . b) c) bn ...) bd ...) (%alet* "one" (p ...) (n ... a) (a) (b c) (bn ...) bd ...)) ((%alet* "one" (p ...) (n ...) (r ...) ((a . b) c) (bn ...) bd ...) (%alet* "one" (p ...) (n ... a) (r ... a) (b c) (bn ...) bd ...)) ((%alet* "one" (p ...) (n ...) (r ...) (() c) (bn ...) bd ...) (c (lambda* (r ...) (%alet* (p ...) (n ...) (bn ...) bd ...)))) ((%alet* "one" (p ...) (n ...) (r ...) (b c) (bn ...) bd ...) (c (lambda* (r ... . b) (%alet* (p ...) (n ... b) (bn ...) bd ...)))) ((%alet* (p ...) (n ...) (((a . b) c d ...) bn ...) bd ...) ((lambda (a) (%alet* "dot" (p ...) (n ... a) (b d ...) (bn ...) bd ...)) c)) ((%alet* "dot" (p ...) (n ...) ((a . b) c d ...) (bn ...) bd ...) ((lambda (a) (%alet* "dot" (p ...) (n ... a) (b d ...) (bn ...) bd ...)) c)) ((%alet* "dot" (p ...) (n ...) (()) (bn ...) bd ...) (%alet* (p ...) (n ...) (bn ...) bd ...)) ((%alet* "dot" (p ...) (n ...) (b c ...) (bn ...) bd ...) ((lambda b (%alet* (p ...) (n ... b) (bn ...) bd ...)) c ...)) ((%alet* (p ...) (n ...) ((and (n1 v1 t1 ...) (n2 v2 t2 ...) ...) bn ...) bd ...) (alet-and* ((n1 v1 t1 ...) (n2 v2 t2 ...) ...) (%alet* (p ...) (n ... n1 n2 ...) (bn ...) bd ...))) ((%alet* (p ...) (n ...) ((opt z a . e) bn ...) bd ...) (%alet* "opt" (p ...) (n ...) z (a . e) (bn ...) bd ...)) ((%alet* "opt" (p ...) (nn ...) z ((n d t ...)) (bn ...) bd ...) (let ((n (if (null? z) d (if (null? (cdr z)) (wow-opt n (car z) t ...) (error "alet*: too many arguments" (cdr z)))))) (%alet* (p ...) (nn ... n) (bn ...) bd ...))) ((%alet* "opt" (p ...) (nn ...) z ((n d t ...) . e) (bn ...) bd ...) (let ((y (if (null? z) z (cdr z))) (n (if (null? z) d (wow-opt n (car z) t ...)))) (%alet* "opt" (p ...) (nn ... n) y e (bn ...) bd ...))) ((%alet* "opt" (p ...) (nn ...) z e (bn ...) bd ...) (let ((e z)) (%alet* (p ...) (nn ... e) (bn ...) bd ...))) ((%alet* (p ...) (nn ...) ((cat z a . e) bn ...) bd ...) (let ((y z)) (%alet* "cat" (p ...) (nn ...) y (a . e) (bn ...) bd ...))) ((%alet* "cat" (p ...) (nn ...) z ((n d t ...)) (bn ...) bd ...) (let ((n (if (null? z) d (if (null? (cdr z)) (wow-cat-end z n t ...) (error "alet*: too many arguments" (cdr z)))))) (%alet* (p ...) (nn ... n) (bn ...) bd ...))) ((%alet* "cat" (p ...) (nn ...) z ((n d t ...) . e) (bn ...) bd ...) (let ((n (if (null? z) d (wow-cat! z n d t ...)))) (%alet* "cat" (p ...) (nn ... n) z e (bn ...) bd ...))) ((%alet* "cat" (p ...) (nn ...) z e (bn ...) bd ...) (let ((e z)) (%alet* (p ...) (nn ... e) (bn ...) bd ...))) ((%alet* (p ...) (m ...) ((key z a . e) bn ...) bd ...) (let ((y z)) (%alet* "key" (p ...) (m ...) y () () (a . e) () (bn ...) bd ...))) ((%alet* "key" (p ...) (m ...) z () (ndt ...) (((n k) d t ...) . e) (kk ...) (bn ...) bd ...) (%alet* "key" (p ...) (m ...) z () (ndt ... ((n k) d t ...)) e (kk ... k) (bn ...) bd ...)) ((%alet* "key" (p ...) (m ...) z () (ndt ...) ((n d t ...) . e) (kk ...) (bn ...) bd ...) (%alet* "key" (p ...) (m ...) z () (ndt ... ((n 'n) d t ...)) e (kk ... 'n) (bn ...) bd ...)) ((%alet* "key" (p ...) (m ...) z () (ndt nd ...) (#t . e) (kk k ...) (bn ...) bd ...) (%alet* "key" (p ...) (m ...) z (#t) (ndt nd ...) e (kk k ...) (bn ...) bd ...)) ((%alet* "key" (p ...) (m ...) z () (ndt nd ...) (#f . e) (kk k ...) (bn ...) bd ...) (%alet* "key" (p ...) (m ...) z (#f) (ndt nd ...) e (kk k ...) (bn ...) bd ...)) ((%alet* "key" (p ...) (m ...) z (o ...) (((n k) d t ...) ndt ...) e (kk ...) (bn ...) bd ...) (let ((n (if (null? z) d (wow-key! z (o ...) (kk ...) (n k) d t ...)))) (%alet* "key" (p ...) (m ... n) z (o ...) (ndt ...) e (kk ...) (bn ...) bd ...))) ((%alet* "key" (p ...) (m ...) z (o ...) () () (kk ...) (bn ...) bd ...) (if (null? z) (%alet* (p ...) (m ...) (bn ...) bd ...) (error "alet*: too many arguments" z))) ((%alet* "key" (p ...) (m ...) z (o ...) () e (kk ...) (bn ...) bd ...) (let ((e z)) (%alet* (p ...) (m ... e) (bn ...) bd ...))) ((%alet* (p ...) (n ...) ((rec (n1 v1) (n2 v2) ...) bn ...) bd ...) (alet-rec* ((n1 v1) (n2 v2) ...) (%alet* (p ...) (n ... n1 n2 ...) (bn ...) bd ...))) ((%alet* (p ...) (n ...) ((a b) bn ...) bd ...) ((lambda (a) (%alet* (p ...) (n ... a) (bn ...) bd ...)) b)) ((%alet* (p ...) (n ...) ((values a c) bn ...) bd ...) ((lambda (a) (%alet* (p ...) (n ... a) (bn ...) bd ...)) c)) ((%alet* (p ...) (n ...) ((values a b c ...) bn ...) bd ...) (%alet* "not" (p ...) (n ... a) (values a) (b c ...) (bn ...) bd ...)) ((%alet* "not" (p ...) (n ...) (values r ...) (a b c ...) (bn ...) bd ...) (%alet* "not" (p ...) (n ... a) (values r ... a) (b c ...) (bn ...) bd ...)) ((%alet* "not" (p ...) (n ...) (values r ...) (z) (bn ...) bd ...) (call-with-values (lambda () z) (lambda* (r ...) (%alet* (p ...) (n ...) (bn ...) bd ...)))) ((%alet* (p ...) (n ...) ((a b c ...) bn ...) bd ...) (%alet* "not" (p ...) (n ... a) (a) (b c ...) (bn ...) bd ...)) ((%alet* "not" (p ...) (n ...) (r ...) (a b c ...) (bn ...) bd ...) (%alet* "not" (p ...) (n ... a) (r ... a) (b c ...) (bn ...) bd ...)) ((%alet* "not" (p ...) (n ...) (r ...) (z) (bn ...) bd ...) (z (lambda* (r ...) (%alet* (p ...) (n ...) (bn ...) bd ...)))) ((%alet* (p ...) (n ...) ((a) bn ...) bd ...) (call-with-current-continuation (lambda (a) (%alet* (p ...) (n ... a) (bn ...) bd ...)))) ((%alet* (p ...) (n ...) ((a . b) bn ...) bd ...) (%alet* "rot" (p ...) (n ...) (a) b (bn ...) bd ...)) ((%alet* "rot" (p ...) (n ...) (new-bn ...) (a . b) (bn ...) bd ...) (%alet* "rot" (p ...) (n ...) (new-bn ... a) b (bn ...) bd ...)) ((%alet* "rot" () () (()) b (bn ...) bd ...) (%alet* (b (bn ...)) () () bd ...)) ((%alet* "rot" (p ...) (n ...) (()) b (bn ...) bd ...) (%alet* (b (p ...) (n ...) (bn ...)) () () bd ...)) ((%alet* "rot" () () (new-bn ...) b (bn ...) bd ...) (%alet* (b (bn ...)) () (new-bn ...) bd ...)) ((%alet* "rot" (p ...) (n ...) (new-bn ...) b (bn ...) bd ...) (%alet* (b (p ...) (n ...) (bn ...)) () (new-bn ...) bd ...)) ((%alet* (p ...) (n ...) (a b bn ...) bd ...) (b (lambda a (%alet* (p ...) (n ... a) (bn ...) bd ...)))))) ;;; auxiliaries (define-syntax lambda* (syntax-rules () ((lambda* (a . e) bd ...) (lambda* "star" (ta) (a) e bd ...)) ((lambda* "star" (t ...) (n ...) (a . e) bd ...) (lambda* "star" (t ... ta) (n ... a) e bd ...)) ((lambda* "star" (t ...) (n ...) () bd ...) (lambda (t ...) (let* ((n t) ...) bd ...))) ((lambda* "star" (t ...) (n ...) e bd ...) (lambda (t ... . te) (let* ((n t) ... (e te)) bd ...))) ((lambda* e bd ...) (lambda e bd ...)))) (define-syntax alet-and (syntax-rules () ((alet-and ((n v t ...) ...) bd ...) (alet-and "and" () ((n v t ...) ...) bd ...)) ((alet-and "and" (nt ...) ((n v) nvt ...) bd ...) (let ((t v)) (and t (alet-and "and" (nt ... (n t)) (nvt ...) bd ...)))) ((alet-and "and" (nt ...) ((n v t) nvt ...) bd ...) (let ((tt v)) (and (let ((n tt)) t) (alet-and "and" (nt ... (n tt)) (nvt ...) bd ...)))) ((alet-and "and" ((n t) ...) () bd ...) ((lambda (n ...) bd ...) t ...)))) (define-syntax alet-and* (syntax-rules () ((alet-and* () bd ...) ((lambda () bd ...))) ((alet-and* ((n v) nvt ...) bd ...) (let ((n v)) (and n (alet-and* (nvt ...) bd ...)))) ((alet-and* ((n v t) nvt ...) bd ...) (let ((n v)) (and t (alet-and* (nvt ...) bd ...)))))) (define-syntax alet-rec (syntax-rules () ((alet-rec ((n v) ...) bd ...) (alet-rec "rec" () ((n v) ...) bd ...)) ((alet-rec "rec" (nvt ...) ((n v) nv ...) bd ...) (alet-rec "rec" (nvt ... (n v t)) (nv ...) bd ...)) ((alet-rec "rec" ((n v t) ...) () bd ...) (let ((n '<undefined>) ...) (let ((t v) ...) (set! n t) ... ;;(let () ;; bd ...)))))) bd ...))))) (define-syntax alet-rec* (syntax-rules () ((alet-rec* ((n v) ...) bd ...) (let* ((n '<undefined>) ...) (set! n v) ... ;;(let () ;; bd ...))))) bd ...)))) (define-syntax wow-opt (syntax-rules () ((wow-opt n v) v) ((wow-opt n v t) (let ((n v)) (if t n (error "alet[*]: bad argument" n 'n 't)))) ((wow-opt n v t ts) (let ((n v)) (if t ts (error "alet[*]: bad argument" n 'n 't)))) ((wow-opt n v t ts fs) (let ((n v)) (if t ts fs))))) (define-syntax wow-opt! (syntax-rules () ((wow-opt! z n) (let ((n (car z))) (set! z (cdr z)) n)) ((wow-opt! z n t) (let ((n (car z))) (if t (begin (set! z (cdr z)) n) (error "alet[*]: bad argument" n 'n 't)))) ((wow-opt! z n t ts) (let ((n (car z))) (if t (begin (set! z (cdr z)) ts) (error "alet[*]: bad argument" n 'n 't)))) ((wow-opt! z n t ts fs) (let ((n (car z))) (if t (begin (set! z (cdr z)) ts) (begin (set! z (cdr z)) fs)))))) (define-syntax wow-cat-end (syntax-rules () ((wow-cat-end z n) (car z)) ((wow-cat-end z n t) (let ((n (car z))) (if t n (error "alet[*]: too many argument" z)))) ((wow-cat-end z n t ts) (let ((n (car z))) (if t ts (error "alet[*]: too many argument" z)))) ((wow-cat-end z n t ts fs) (let ((n (car z))) (if t ts fs))))) (define-syntax wow-cat (syntax-rules () ((wow-cat z n d) z) ((wow-cat z n d t) (let ((n (car z))) (if t z (let lp ((head (list n)) (tail (cdr z))) (if (null? tail) (cons d z) (let ((n (car tail))) (if t (cons n (append (reverse head) (cdr tail))) (lp (cons n head) (cdr tail))))))))) ((wow-cat z n d t ts) (let ((n (car z))) (if t (cons ts (cdr z)) (let lp ((head (list n)) (tail (cdr z))) (if (null? tail) (cons d z) (let ((n (car tail))) (if t (cons ts (append (reverse head) (cdr tail))) (lp (cons n head) (cdr tail))))))))) ((wow-cat z n d t ts fs) (let ((n (car z))) (if t (cons ts (cdr z)) (cons fs (cdr z))))))) (define-syntax wow-cat! (syntax-rules () ((wow-cat! z n d) (let ((n (car z))) (set! z (cdr z)) n)) ((wow-cat! z n d t) (let ((n (car z))) (if t (begin (set! z (cdr z)) n) (let lp ((head (list n)) (tail (cdr z))) (if (null? tail) d (let ((n (car tail))) (if t (begin (set! z (append (reverse head) (cdr tail))) n) (lp (cons n head) (cdr tail))))))))) ((wow-cat! z n d t ts) (let ((n (car z))) (if t (begin (set! z (cdr z)) ts) (let lp ((head (list n)) (tail (cdr z))) (if (null? tail) d (let ((n (car tail))) (if t (begin (set! z (append (reverse head) (cdr tail))) ts) (lp (cons n head) (cdr tail))))))))) ((wow-cat! z n d t ts fs) (let ((n (car z))) (if t (begin (set! z (cdr z)) ts) (begin (set! z (cdr z)) fs)))))) (define-syntax wow-key! (syntax-rules () ((wow-key! z () (kk ...) (n key) d) (let ((x (car z)) (y (cdr z))) (if (null? y) d (if (equal? key x) (begin (set! z (cdr y)) (car y)) (let lp ((head (list (car y) x)) (tail (cdr y))) (if (null? tail) d (let ((x (car tail)) (y (cdr tail))) (if (null? y) d (if (equal? key x) (begin (set! z (append (reverse head) (cdr y))) (car y)) (lp (cons (car y) (cons x head)) (cdr y))))))))))) ((wow-key! z (#f) (kk ...) (n key) d) (let ((x (car z)) (y (cdr z))) (if (null? y) d (if (equal? key x) (begin (set! z (cdr y)) (car y)) (let ((lk (list kk ...))) (if (not (member x lk)) d (let lp ((head (list (car y) x)) (tail (cdr y))) (if (null? tail) d (let ((x (car tail)) (y (cdr tail))) (if (null? y) d (if (equal? key x) (begin (set! z (append (reverse head) (cdr y))) (car y)) (if (not (member x lk)) d (lp (cons (car y) (cons x head)) (cdr y)))))))))))))) ((wow-key! z (#t) (kk ...) (n key) d) (let ((x (car z)) (y (cdr z))) (if (null? y) d (if (equal? key x) (begin (set! z (cdr y)) (car y)) (let* ((lk (list kk ...)) (m (member x lk))) (let lp ((head (if m (list (car y) x) (list x))) (tail (if m (cdr y) y))) (if (null? tail) d (let ((x (car tail)) (y (cdr tail))) (if (null? y) d (if (equal? key x) (begin (set! z (append (reverse head) (cdr y))) (car y)) (let ((m (member x lk))) (lp (if m (cons (car y) (cons x head)) (cons x head)) (if m (cdr y) y))))))))))))) ((wow-key! z () (kk ...) (n key) d t) (let ((x (car z)) (y (cdr z))) (if (null? y) d (if (equal? key x) (let ((n (car y))) (if t (begin (set! z (cdr y)) n) (error "alet[*]: bad argument" n 'n 't))) (let lp ((head (list (car y) x)) (tail (cdr y))) (if (null? tail) d (let ((x (car tail)) (y (cdr tail))) (if (null? y) d (if (equal? key x) (let ((n (car y))) (if t (begin (set! z (append (reverse head) (cdr y))) n) (error "alet[*]: bad argument" n 'n 't))) (lp (cons (car y) (cons x head)) (cdr y))))))))))) ((wow-key! z (#f) (kk ...) (n key) d t) (let ((x (car z)) (y (cdr z))) (if (null? y) d (if (equal? key x) (let ((n (car y))) (if t (begin (set! z (cdr y)) n) (error "alet[*]: bad argument" n 'n 't))) (let ((lk (list kk ...))) (if (not (member x lk)) d (let lp ((head (list (car y) x)) (tail (cdr y))) (if (null? tail) d (let ((x (car tail)) (y (cdr tail))) (if (null? y) d (if (equal? key x) (let ((n (car y))) (if t (begin (set! z (append (reverse head) (cdr y))) n) (error "alet[*]: bad argument" n 'n 't))) (if (not (member x lk)) d (lp (cons (car y) (cons x head)) (cdr y)))))))))))))) ((wow-key! z (#t) (kk ...) (n key) d t) (let ((x (car z)) (y (cdr z))) (if (null? y) d (if (equal? key x) (let ((n (car y))) (if t (begin (set! z (cdr y)) n) (error "alet[*]: bad argument" n 'n 't))) (let* ((lk (list kk ...)) (m (member x lk))) (let lp ((head (if m (list (car y) x) (list x))) (tail (if m (cdr y) y))) (if (null? tail) d (let ((x (car tail)) (y (cdr tail))) (if (null? y) d (if (equal? key x) (let ((n (car y))) (if t (begin (set! z (append (reverse head) (cdr y))) n) (error "alet[*]: bad argument" n 'n 't))) (let ((m (member x lk))) (lp (if m (cons (car y) (cons x head)) (cons x head)) (if m (cdr y) y))))))))))))) ((wow-key! z () (kk ...) (n key) d t ts) (let ((x (car z)) (y (cdr z))) (if (null? y) d (if (equal? key x) (let ((n (car y))) (if t (begin (set! z (cdr y)) ts) (error "alet[*]: bad argument" n 'n 't))) (let lp ((head (list (car y) x)) (tail (cdr y))) (if (null? tail) d (let ((x (car tail)) (y (cdr tail))) (if (null? y) d (if (equal? key x) (let ((n (car y))) (if t (begin (set! z (append (reverse head) (cdr y))) ts) (error "alet[*]: bad argument" n 'n 't))) (lp (cons (car y) (cons x head)) (cdr y))))))))))) ((wow-key! z (#f) (kk ...) (n key) d t ts) (let ((x (car z)) (y (cdr z))) (if (null? y) d (if (equal? key x) (let ((n (car y))) (if t (begin (set! z (cdr y)) ts) (error "alet[*]: bad argument" n 'n 't))) (let ((lk (list kk ...))) (if (not (member x lk)) d (let lp ((head (list (car y) x)) (tail (cdr y))) (if (null? tail) d (let ((x (car tail)) (y (cdr tail))) (if (null? y) d (if (equal? key x) (let ((n (car y))) (if t (begin (set! z (append (reverse head) (cdr y))) ts) (error "alet[*]: bad argument" n 'n 't))) (if (not (member x lk)) d (lp (cons (car y) (cons x head)) (cdr y)))))))))))))) ((wow-key! z (#t) (kk ...) (n key) d t ts) (let ((x (car z)) (y (cdr z))) (if (null? y) d (if (equal? key x) (let ((n (car y))) (if t (begin (set! z (cdr y)) ts) (error "alet[*]: bad argument" n 'n 't))) (let* ((lk (list kk ...)) (m (member x lk))) (let lp ((head (if m (list (car y) x) (list x))) (tail (if m (cdr y) y))) (if (null? tail) d (let ((x (car tail)) (y (cdr tail))) (if (null? y) d (if (equal? key x) (let ((n (car y))) (if t (begin (set! z (append (reverse head) (cdr y))) ts) (error "alet[*]: bad argument" n 'n 't))) (let ((m (member x lk))) (lp (if m (cons (car y) (cons x head)) (cons x head)) (if m (cdr y) y))))))))))))) ((wow-key! z () (kk ...) (n key) d t ts fs) (let ((x (car z)) (y (cdr z))) (if (null? y) d (if (equal? key x) (let ((n (car y))) (if t (begin (set! z (cdr y)) ts) (begin (set! z (cdr y)) fs))) (let lp ((head (list (car y) x)) (tail (cdr y))) (if (null? tail) d (let ((x (car tail)) (y (cdr tail))) (if (null? y) d (if (equal? key x) (let ((n (car y))) (if t (begin (set! z (append (reverse head) (cdr y))) ts) (begin (set! z (append (reverse head) (cdr y))) fs))) (lp (cons (car y) (cons x head)) (cdr y))))))))))) ((wow-key! z (#f) (kk ...) (n key) d t ts fs) (let ((x (car z)) (y (cdr z))) (if (null? y) d (if (equal? key x) (let ((n (car y))) (if t (begin (set! z (cdr y)) ts) (begin (set! z (cdr y)) fs))) (let ((lk (list kk ...))) (if (not (member x lk)) d (let lp ((head (list (car y) x)) (tail (cdr y))) (if (null? tail) d (let ((x (car tail)) (y (cdr tail))) (if (null? y) d (if (equal? key x) (let ((n (car y))) (if t (begin (set! z (append (reverse head) (cdr y))) ts) (begin (set! z (append (reverse head) (cdr y))) fs))) (if (not (member x lk)) d (lp (cons (car y) (cons x head)) (cdr y)))))))))))))) ((wow-key! z (#t) (kk ...) (n key) d t ts fs) (let ((x (car z)) (y (cdr z))) (if (null? y) d (if (equal? key x) (let ((n (car y))) (if t (begin (set! z (cdr y)) ts) (begin (set! z (cdr y)) fs))) (let* ((lk (list kk ...)) (m (member x lk))) (let lp ((head (if m (list (car y) x) (list x))) (tail (if m (cdr y) y))) (if (null? tail) d (let ((x (car tail)) (y (cdr tail))) (if (null? y) d (if (equal? key x) (let ((n (car y))) (if t (begin (set! z (append (reverse head) (cdr y))) ts) (begin (set! z (append (reverse head) (cdr y))) fs))) (let ((m (member x lk))) (lp (if m (cons (car y) (cons x head)) (cons x head)) (if m (cdr y) y))))))))))))))) (define-syntax alet-opt* (syntax-rules () ((alet-opt* z (a . e) bd ...) (let ((y z)) (%alet-opt* y (a . e) bd ...))))) (define-syntax %alet-opt* (syntax-rules () ((%alet-opt* z ((n d t ...)) bd ...) (let ((n (if (null? z) d (if (null? (cdr z)) (wow-opt n (car z) t ...) (error "alet*: too many arguments" (cdr z)))))) bd ...)) ((%alet-opt* z ((n d t ...) . e) bd ...) (let ((y (if (null? z) z (cdr z))) (n (if (null? z) d (wow-opt n (car z) t ...)))) (%alet-opt* y e bd ...))) ((%alet-opt* z e bd ...) (let ((e z)) bd ...)))) ;; (define-syntax %alet-opt* ;; (syntax-rules () ;; ((%alet-opt* z ((n d t ...)) bd ...) ;; (let ((n (if (null? z) ;; d ;; (if (null? (cdr z)) ;; (wow-opt n (car z) t ...) ;; (error "alet*: too many arguments" (cdr z)))))) ;; bd ...)) ;; ((%alet-opt* z ((n d t ...) . e) bd ...) ;; (let ((n (if (null? z) ;; d ;; (wow-opt! z n t ...)))) ;; (%alet-opt* z e bd ...))) ;; ((%alet-opt* z e bd ...) ;; (let ((e z)) bd ...)))) ;; (define-syntax %alet-opt* ;; (syntax-rules () ;; ((%alet-opt* z (ndt ...) (a . e) bd ...) ;; (%alet-opt* z (ndt ... a) e bd ...)) ;; ((%alet-opt* z ((n d t ...) (nn dd tt ...) ...) () bd ...) ;; (if (null? z) ;; (let* ((n d) (nn dd) ...) bd ...) ;; (let ((y (cdr z)) ;; (n (wow-opt n (car z) t ...))) ;; (%alet-opt* y ((nn dd tt ...) ...) () bd ...)))) ;; ((%alet-opt* z () () bd ...) ;; (if (null? z) ;; (let () bd ...) ;; (error "alet*: too many arguments" z))) ;; ((%alet-opt* z ((n d t ...) (nn dd tt ...) ...) e bd ...) ;; (if (null? z) ;; (let* ((n d) (nn dd) ... (e z)) bd ...) ;; (let ((y (cdr z)) ;; (n (wow-opt n (car z) t ...))) ;; (%alet-opt* y ((nn dd tt ...) ...) e bd ...)))) ;; ((%alet-opt* z () e bd ...) ;; (let ((e z)) bd ...)))) (define-syntax alet-cat* (syntax-rules () ((alet-cat* z (a . e) bd ...) (let ((y z)) (%alet-cat* y (a . e) bd ...))))) ;; (define-syntax %alet-cat* ;; (syntax-rules () ;; ((%alet-cat* z ((n d t ...)) bd ...) ;; (let ((n (if (null? z) ;; d ;; (if (null? (cdr z)) ;; (wow-cat-end z n t ...) ;; (error "alet*: too many arguments" (cdr z)))))) ;; bd ...)) ;; ((%alet-cat* z ((n d t ...) . e) bd ...) ;; (let* ((w (if (null? z) ;; (cons d z) ;; (wow-cat z n d t ...))) ;; (n (car w)) ;; (y (cdr w))) ;; (%alet-cat* y e bd ...))) ;; ((%alet-cat* z e bd ...) ;; (let ((e z)) bd ...)))) (define-syntax %alet-cat* (syntax-rules () ((%alet-cat* z ((n d t ...)) bd ...) (let ((n (if (null? z) d (if (null? (cdr z)) (wow-cat-end z n t ...) (error "alet*: too many arguments" (cdr z)))))) bd ...)) ((%alet-cat* z ((n d t ...) . e) bd ...) (let ((n (if (null? z) d (wow-cat! z n d t ...)))) (%alet-cat* z e bd ...))) ((%alet-cat* z e bd ...) (let ((e z)) bd ...)))) ;; (define-syntax %alet-cat* ;; (syntax-rules () ;; ((%alet-cat* z (ndt ...) (a . e) bd ...) ;; (%alet-cat* z (ndt ... a) e bd ...)) ;; ((%alet-cat* z ((n d t ...) (nn dd tt ...) ...) () bd ...) ;; (if (null? z) ;; (let* ((n d) (nn dd) ...) bd ...) ;; (let* ((w (wow-cat z n d t ...)) ;; (n (car w)) ;; (y (cdr w))) ;; (%alet-cat* y ((nn dd tt ...) ...) () bd ...)))) ;; ((%alet-cat* z () () bd ...) ;; (if (null? z) ;; (let () bd ...) ;; (error "alet*: too many arguments" z))) ;; ((%alet-cat* z ((n d t ...) (nn dd tt ...) ...) e bd ...) ;; (if (null? z) ;; (let* ((n d) (nn dd) ... (e z)) bd ...) ;; (let* ((w (wow-cat z n d t ...)) ;; (n (car w)) ;; (y (cdr w))) ;; (%alet-cat* y ((nn dd tt ...) ...) e bd ...)))) ;; ((%alet-cat* z () e bd ...) ;; (let ((e z)) bd ...)))) (define-syntax alet-key* (syntax-rules () ((alet-key* z (a . e) bd ...) (let ((y z)) (%alet-key* y () () (a . e) () bd ...))))) (define-syntax %alet-key* (syntax-rules () ((%alet-key* z () (ndt ...) (((n k) d t ...) . e) (kk ...) bd ...) (%alet-key* z () (ndt ... ((n k) d t ...)) e (kk ... k) bd ...)) ((%alet-key* z () (ndt ...) ((n d t ...) . e) (kk ...) bd ...) (%alet-key* z () (ndt ... ((n 'n) d t ...)) e (kk ... 'n) bd ...)) ((%alet-key* z () (ndt nd ...) (#f . e) (kk k ...) bd ...) (%alet-key* z (#f) (ndt nd ...) e (kk k ...) bd ...)) ((%alet-key* z () (ndt nd ...) (#t . e) (kk k ...) bd ...) (%alet-key* z (#t) (ndt nd ...) e (kk k ...) bd ...)) ((%alet-key* z (o ...) (((n k) d t ...) ndt ...) e (kk ...) bd ...) (let ((n (if (null? z) d (wow-key! z (o ...) (kk ...) (n k) d t ...)))) (%alet-key* z (o ...) (ndt ...) e (kk ...) bd ...))) ((%alet-key* z (o ...) () () (kk ...) bd ...) (if (null? z) (let () bd ...) (error "alet*: too many arguments" z))) ((%alet-key* z (o ...) () e (kk ...) bd ...) (let ((e z)) bd ...)))))
true
8eb7e2b595886c685171e3ab08a4e5c9b8166686
bceb0768d0323a246bf02a88046102c374baaa7c
/json-rpc-server.scm
26baac61daddd76607af08204231612af9f948e2
[]
no_license
vulcanoio/chicken-egg-json-rpc
59b103445638a86e54b2398815cf0c67befad50a
1a689cb0976bb5bcc67d7aa4aeea794fc3ab5a8c
refs/heads/master
2020-07-22T03:57:14.996520
2013-05-16T18:25:07
2013-05-16T18:25:07
null
0
0
null
null
null
null
UTF-8
Scheme
false
false
2,423
scm
json-rpc-server.scm
(use tcp json srfi-18 utils) (include "common.scm") (tcp-buffer-size 2048) (define *remote-procedures* '()) (define-syntax define-json (syntax-rules () ((_ (name args ...) body ...) (set! *remote-procedures* (cons (cons 'name (lambda (args ...) body ...)) *remote-procedures*))))) (define (register-procedure name proc) (set! *remote-procedures* (cons (cons name proc) *remote-procedures*))) (define (call-procedure proc-name args id) (let ((proc (alist-ref proc-name *remote-procedures*))) (if proc (handle-exceptions exn (make-error-response -32603 "Internal error") (make-response (apply proc args) id)) (make-error-response -32601 "Method not found.")))) (define (json->string data) (with-output-to-string (lambda () (json-write data)))) (define (make-response data id) (json->string `#(("jsonrpc" . ,json-rpc-version) ("result" . ,data) ("id" . ,id)))) (define (make-error-response code message) (json->string `#(("jsonrpc" . ,json-rpc-version) ("error" . #(("code" . ,code) ("message" . ,message))) ("id" . "null")))) (define (dispatch-request req) (let* ((req (vector->list req)) (method (alist-ref "method" req equal?)) (params (alist-ref "params" req equal?)) (id (alist-ref "id" req equal?))) (if method (call-procedure (string->symbol method) (or params '()) id) (make-error-response -32601 "Method not found.")))) (define (start-json-rpc-server port) (let ((listener (tcp-listen port))) (let accept-next-connection () (receive (in out) (tcp-accept listener) (thread-start! (lambda () (let loop () (handle-exceptions e (begin (print-call-chain) (print-error-message e) (make-error-response -32603 "Internal error.")) (and-let* ((message (receive-message in)) (req (with-input-from-string message json-read)) (response (dispatch-request req))) (send-message-dup! "{\"jsonrpc\": \"2.0\", \"signal\": \"foo\"}" out) (send-message! response out) (loop)))))) (accept-next-connection)))))
true
a4eb6e500e458db4fbea8d3f832f33c98a018b86
3291c07b44c319b125ab1658d6efc56453872dd5
/tests/test1.scm
2250ffbf6059749d300047a90fd7292970eb4f96
[ "MIT" ]
permissive
hermetique/sly
dc2d2129eb2013122db856115a337b5714c69f7f
c46f94dfd6955f5923a5bcf59990395c3764fb9a
refs/heads/master
2021-05-27T19:31:04.922820
2011-02-14T13:05:15
2011-02-14T13:05:15
null
0
0
null
null
null
null
UTF-8
Scheme
false
false
780
scm
test1.scm
(define (proc1 a b c) (let ((d 15000000) (e (let ((z (+ 20 20))) (zero? (- (* 10 4) z))))) (set! d (+ a d)) (let ((x (let* ((m (* b (- b a))) (n (* c (- b a)))) (lambda (a b) (let ((i m) (k (lambda (m z) (set! b (+ m 1)) (+ (+ m (- n z)) b)))) (k a i))))) (y (call/cc (lambda (cont) (cons (cont 34) c))))) (cond ((not c) (integer->char c)) ((not e) (x a (cdr y))) (else (add1 c) (- c b) (and c (x (- d a) b))))))) (display (proc1 (char->integer #\A) (* 24 3) (add1 (sub1 (add1 1024))))) (newline)
false