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 |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
3d8a3726928f3c75b7fc51266a87499c008001cd | defeada37d39bca09ef76f66f38683754c0a6aa0 | /UnityEngine/unity-engine/events/persistent-call.sls | 4199f24d2b7951fccacbff993394ed45df4c853c | [] | no_license | futsuki/ironscheme-port | 2dbac82c0bda4f4ff509208f7f00a5211d1f7cd5 | 4e7a81b0fbeac9a47440464988e53fb118286c54 | refs/heads/master | 2016-09-06T17:13:11.462593 | 2015-09-26T18:20:40 | 2015-09-26T18:20:40 | 42,757,369 | 0 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 2,169 | sls | persistent-call.sls | (library (unity-engine events persistent-call)
(export new
is?
persistent-call?
is-valid?
register-persistent-listener
unregister-persistent-listener
get-runtime-call
target
method-name
mode-get
mode-set!
mode-update!
arguments
call-state-get
call-state-set!
call-state-update!)
(import (ironscheme-clr-port))
(define-syntax new
(lambda (e)
(syntax-case e ()
((_ a ...)
#'(clr-new UnityEngine.Events.PersistentCall a ...)))))
(define (is? a) (clr-is UnityEngine.Events.PersistentCall a))
(define (persistent-call? a)
(clr-is UnityEngine.Events.PersistentCall a))
(define-method-port
is-valid?
UnityEngine.Events.PersistentCall
IsValid
(System.Boolean))
(define-method-port
register-persistent-listener
UnityEngine.Events.PersistentCall
RegisterPersistentListener
(System.Void UnityEngine.Object System.String))
(define-method-port
unregister-persistent-listener
UnityEngine.Events.PersistentCall
UnregisterPersistentListener
(System.Void))
(define-method-port
get-runtime-call
UnityEngine.Events.PersistentCall
GetRuntimeCall
(UnityEngine.Events.BaseInvokableCall
UnityEngine.Events.UnityEventBase))
(define-field-port
target
#f
#f
(property:)
UnityEngine.Events.PersistentCall
target
UnityEngine.Object)
(define-field-port
method-name
#f
#f
(property:)
UnityEngine.Events.PersistentCall
methodName
System.String)
(define-field-port
mode-get
mode-set!
mode-update!
(property:)
UnityEngine.Events.PersistentCall
mode
UnityEngine.Events.PersistentListenerMode)
(define-field-port
arguments
#f
#f
(property:)
UnityEngine.Events.PersistentCall
arguments
UnityEngine.Events.ArgumentCache)
(define-field-port
call-state-get
call-state-set!
call-state-update!
(property:)
UnityEngine.Events.PersistentCall
callState
UnityEngine.Events.UnityEventCallState))
| true |
9d319830ac4c65ea2b309707a2788c4426599f6a | 3ecee09e72582189e8a4a48b3d85447c7927142f | /static/now/std__srfi__143.scm | 08c8910591f8af11a18d1bde496cfa2c85e5ec67 | [
"MIT"
] | permissive | drewc/gx-quasar | 6c745b9ec13c60ab6d1af8964a25ff14ceb4549b | 17513967f611d46cc2d5a44999c90a7891e5d2d0 | refs/heads/main | 2023-02-02T17:01:12.011714 | 2020-12-18T22:18:19 | 2020-12-18T22:18:19 | 310,720,698 | 1 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 8,636 | scm | std__srfi__143.scm | (declare (block) (standard-bindings) (extended-bindings))
(begin
(define std/srfi/143#fx-width ##fixnum-width)
(define std/srfi/143#fx-greatest ##max-fixnum)
(define std/srfi/143#fx-least ##min-fixnum)
(define std/srfi/143#fxneg (lambda (_x103068_) (fx- _x103068_)))
(define std/srfi/143#fxsqrt
(lambda (_x103066_)
(let () (declare (not safe)) (##integer-sqrt _x103066_))))
(define std/srfi/143#fxcopy-bit
(lambda (_index103062_ _to103063_ _bool103064_)
(if _bool103064_
(fxior _to103063_ (fxarithmetic-shift-left '1 _index103062_))
(fxand _to103063_
(fxnot (fxarithmetic-shift-left '1 _index103062_))))))
(define std/srfi/143#fxfirst-set-bit
(lambda (_i103060_)
(fx- (fxbit-count (fxxor _i103060_ (fx- _i103060_ '1))) '1)))
(define std/srfi/143#mask
(lambda (_start103057_ _end103058_)
(fxnot (fxarithmetic-shift-left '-1 (fx- _end103058_ _start103057_)))))
(define std/srfi/143#fxbit-field
(lambda (_n103053_ _start103054_ _end103055_)
(fxand (std/srfi/143#mask _start103054_ _end103055_)
(fxarithmetic-shift _n103053_ (fx- _start103054_)))))
(define std/srfi/143#fxbit-field-rotate
(lambda (_n103042_ _count103043_ _start103044_ _end103045_)
(letrec* ((_width103047_ (fx- _end103045_ _start103044_)))
(set! _count103043_ (fxmodulo _count103043_ _width103047_))
(let ((_mask103049_ (fxnot (fxarithmetic-shift '-1 _width103047_))))
(letrec* ((_zn103051_
(fxand _mask103049_
(fxarithmetic-shift
_n103042_
(fx- _start103044_)))))
(fxior (fxarithmetic-shift
(fxior (fxand _mask103049_
(fxarithmetic-shift
_zn103051_
_count103043_))
(fxarithmetic-shift
_zn103051_
(fx- _count103043_ _width103047_)))
_start103044_)
(fxand (fxnot (fxarithmetic-shift
_mask103049_
_start103044_))
_n103042_)))))))
(define std/srfi/143#fxreverse
(lambda (_k103032_ _n103033_)
(let _$loop103035_ ((_m103038_
(if (fxnegative? _n103033_)
(fxnot _n103033_)
_n103033_))
(_k103039_ (fx+ '-1 _k103032_))
(_rvs103040_ '0))
(if (fxnegative? _k103039_)
(if (fxnegative? _n103033_) (fxnot _rvs103040_) _rvs103040_)
(_$loop103035_
(fxarithmetic-shift-right _m103038_ '1)
(fx+ '-1 _k103039_)
(fxior (fxarithmetic-shift-left _rvs103040_ '1)
(fxand '1 _m103038_)))))))
(define std/srfi/143#fxbit-field-reverse
(lambda (_n103022_ _start103023_ _end103024_)
(letrec* ((_width103026_ (fx- _end103024_ _start103023_)))
(let ((_mask103028_
(fxnot (fxarithmetic-shift-left '-1 _width103026_))))
(letrec* ((_zn103030_
(fxand _mask103028_
(fxarithmetic-shift-right
_n103022_
_start103023_))))
(fxior (fxarithmetic-shift-left
(std/srfi/143#fxreverse _width103026_ _zn103030_)
_start103023_)
(fxand (fxnot (fxarithmetic-shift-left
_mask103028_
_start103023_))
_n103022_)))))))
(define std/srfi/143#exp-width (expt '2 std/srfi/143#fx-width))
(define std/srfi/143#fx+/carry
(lambda (_i103012_ _j103013_ _k103014_)
(let* ((_s103016_ (+ _i103012_ _j103013_ _k103014_))
(_g279235_
(std/srfi/143#balanced/ _s103016_ std/srfi/143#exp-width)))
(begin
(let ((_g279236_
(let ()
(declare (not safe))
(if (##values? _g279235_) (##vector-length _g279235_) 1))))
(if (not (let () (declare (not safe)) (##fx= _g279236_ 2)))
(error "Context expects 2 values" _g279236_)))
(let ((_q103018_
(let () (declare (not safe)) (##vector-ref _g279235_ 0)))
(_r103019_
(let () (declare (not safe)) (##vector-ref _g279235_ 1))))
(let () (values _r103019_ _q103018_)))))))
(define std/srfi/143#fx-/carry
(lambda (_i103002_ _j103003_ _k103004_)
(let* ((_d103006_ (- _i103002_ _j103003_ _k103004_))
(_g279237_
(std/srfi/143#balanced/ _d103006_ std/srfi/143#exp-width)))
(begin
(let ((_g279238_
(let ()
(declare (not safe))
(if (##values? _g279237_) (##vector-length _g279237_) 1))))
(if (not (let () (declare (not safe)) (##fx= _g279238_ 2)))
(error "Context expects 2 values" _g279238_)))
(let ((_q103008_
(let () (declare (not safe)) (##vector-ref _g279237_ 0)))
(_r103009_
(let () (declare (not safe)) (##vector-ref _g279237_ 1))))
(let () (values _r103009_ _q103008_)))))))
(define std/srfi/143#fx*/carry
(lambda (_i102992_ _j102993_ _k102994_)
(let* ((_s102996_ (+ (* _i102992_ _j102993_) _k102994_))
(_g279239_
(std/srfi/143#balanced/ _s102996_ std/srfi/143#exp-width)))
(begin
(let ((_g279240_
(let ()
(declare (not safe))
(if (##values? _g279239_) (##vector-length _g279239_) 1))))
(if (not (let () (declare (not safe)) (##fx= _g279240_ 2)))
(error "Context expects 2 values" _g279240_)))
(let ((_q102998_
(let () (declare (not safe)) (##vector-ref _g279239_ 0)))
(_r102999_
(let () (declare (not safe)) (##vector-ref _g279239_ 1))))
(let () (values _r102999_ _q102998_)))))))
(define std/srfi/143#floor-/+
(lambda (_n102984_ _d102985_)
(let ((_n102987_ (- '0 _n102984_)))
(let ((_q102989_ (quotient _n102987_ _d102985_))
(_r102990_ (remainder _n102987_ _d102985_)))
(if (zero? _r102990_)
(values (- '0 _q102989_) _r102990_)
(values (- (- '0 _q102989_) '1) (- _d102985_ _r102990_)))))))
(define std/srfi/143#ceiling-/-
(lambda (_n102975_ _d102976_)
(let ((_n102978_ (- '0 _n102975_)) (_d102979_ (- '0 _d102976_)))
(let ((_q102981_ (quotient _n102978_ _d102979_))
(_r102982_ (remainder _n102978_ _d102979_)))
(if (zero? _r102982_)
(values _q102981_ _r102982_)
(values (+ _q102981_ '1) (- _d102979_ _r102982_)))))))
(define std/srfi/143#euclidean/
(lambda (_n102968_ _d102969_)
(if (and (exact-integer? _n102968_) (exact-integer? _d102969_))
(if (and (negative? _n102968_) (negative? _d102969_))
(std/srfi/143#ceiling-/- _n102968_ _d102969_)
(if (negative? _n102968_)
(std/srfi/143#floor-/+ _n102968_ _d102969_)
(if (negative? _d102969_)
(let ((_d102971_ (- '0 _d102969_)))
(values (- '0 (quotient _n102968_ _d102971_))
(remainder _n102968_ _d102971_)))
(values (quotient _n102968_ _d102969_)
(remainder _n102968_ _d102969_)))))
(let ((_q102973_
(if (negative? _d102969_)
(ceiling (/ _n102968_ _d102969_))
(floor (/ _n102968_ _d102969_)))))
(values _q102973_ (- _n102968_ (* _d102969_ _q102973_)))))))
(define std/srfi/143#balanced/
(lambda (_x102961_ _y102962_)
(call-with-values
(lambda () (std/srfi/143#euclidean/ _x102961_ _y102962_))
(lambda (_q102965_ _r102966_)
(if (< _r102966_ (abs (/ _y102962_ '2)))
(values _q102965_ _r102966_)
(if (> _y102962_ '0)
(values (+ _q102965_ '1)
(- _x102961_ (* (+ _q102965_ '1) _y102962_)))
(values (- _q102965_ '1)
(- _x102961_ (* (- _q102965_ '1) _y102962_))))))))))
| false |
a8129d162aaab19cd8c968732296eabbfd2a1bea | 953f207e0416a8b686c36e0c5da46ef1f2154689 | /libarchive/writer.scm | 29a8f911cf53a5c31b2787b6691e332fea4eab25 | [
"MIT"
] | permissive | RhodiumToad/guile-libarchive | 1dbad4d2e8da87812d18cecfd9f06c5417d1a108 | d9da9e80e44a031e216928602d71f48202109447 | refs/heads/main | 2023-05-29T22:58:57.109694 | 2023-05-12T15:00:51 | 2023-05-12T15:00:51 | 418,401,643 | 1 | 1 | null | null | null | null | UTF-8 | Scheme | false | false | 4,844 | scm | writer.scm | ;; -*- mode: Scheme; tab-width: 4 -*-
(eval-when (expand load eval)
(read-set! keywords 'postfix))
(define-module (libarchive writer)
use-module: (oop goops)
use-module: (system foreign)
use-module: (srfi srfi-26)
use-module: (ice-9 match)
use-module: (ice-9 optargs)
use-module: (libarchive base)
use-module: (rnrs bytevectors)
export: (<archive-writer>
open-filename
set-format
add-filter
fail
write-data
write-header
)
re-export-and-replace: (close)
re-export: (free
free-entries
new-entry
warning-handler
with-libarchive-warning-handler
libarchive-warning?
libarchive-error?
libarchive-parameter-error?))
;;;
(define-libarchive-fn '* archive:write-new)
(define-class <archive-writer> (<archive-base>)
(allocator
allocation: #:class
init-value: archive:write-new))
(define-method (initialize (self <archive-writer>) initargs)
(let-keywords initargs #t ((format #f)
(filename #f)
(default-ext #f)
(filters '()))
(when (and (not (null? filters))
(not (or format filename default-ext)))
(archive-report-parameter-error "invalid keyword combination"
'initialize initargs))
(when (and format (not (symbol? format)))
(archive-report-parameter-error "invalid format parameter"
'initialize format))
(when (or (and filename (not (string? filename)))
(and default-ext (not (string? default-ext))))
(archive-report-parameter-error "invalid filename or ext"
'initialize initargs))
(next-method)
(cond
(format (set-format self format))
((or filename default-ext)
(set-format self (or filename "") (or default-ext ""))))
(for-each (cut add-filter self <>) filters)))
;; args should be one or two strings, or one or more symbols
(define-libarchive-fn int archive:write-set-format-filter-by-ext '* '*)
(define-libarchive-fn int archive:write-set-format-filter-by-ext-def '* '* '*)
(define-libarchive-fn int archive:write-set-format-by-name '* '*)
(define-libarchive-fn int archive:write-add-filter-by-name '* '*)
(define-method (set-format (self <archive-writer>)
(fn <string>))
(with-archive-ptr self
(archive-check-error self
(archive:write-set-format-filter-by-ext archive-ptr
(string->pointer fn)))))
(define-method (set-format (self <archive-writer>)
(fn <string>)
(def <string>))
(with-archive-ptr self
(archive-check-error self
(archive:write-set-format-filter-by-ext-def
archive-ptr
(string->pointer fn)
(string->pointer def)))))
(define-method (set-format (self <archive-writer>)
(fmt <symbol>)
. rest)
(with-archive-ptr self
(archive-check-error self
(archive:write-set-format-by-name
archive-ptr
(string->pointer (symbol->string fmt))))
(for-each (cut add-filter self <>) rest)))
(define-method (add-filter (self <archive-writer>)
(filt <symbol>))
(with-archive-ptr self
(archive-check-error self
(archive:write-add-filter-by-name
archive-ptr
(string->pointer (symbol->string filt))))))
(define-libarchive-fn int archive:write-close '*)
(define-method (close (self <archive-writer>))
(with-archive-ptr self
(archive-check-error self (archive:write-close archive-ptr))))
(define-libarchive-fn int archive:write-fail '*)
(define-method (fail (self <archive-writer>))
(with-archive-ptr self
(archive:write-fail archive-ptr)))
(define-libarchive-fn int archive:write-open-filename '* '*)
(define-method (open-filename (self <archive-writer>)
(filename <string>))
(with-archive-ptr self
(archive-check-error self
(archive:write-open-filename
archive-ptr
(string->pointer filename)))))
(define-libarchive-fn ssize_t archive:write-data '* '* size_t)
(define-method (write-data (self <archive-writer>)
(data <bytevector>)
(offset <integer>)
(len <integer>))
(with-archive-ptr self
(archive-check-offset-len 'write-data offset len (bytevector-length data))
(archive-check-result self (archive:write-data archive-ptr
(bytevector->pointer data offset)
len))))
(define-method (write-data (self <archive-writer>)
(data <bytevector>)
(offset <integer>))
(write-data self data offset (- (bytevector-length data) offset)))
(define-method (write-data (self <archive-writer>)
(data <bytevector>))
(write-data self data 0 (bytevector-length data)))
(define-libarchive-fn int archive:write-header '* '*)
(define-method (write-header (self <archive-writer>)
(header <archive-entry>))
(with-archive-ptr self
(with-entry-ptr header
(archive-check-error self
(archive:write-header archive-ptr entry-ptr)))))
;; end
| false |
5583eb1a383bc77e787ae0983d5445a93ef526b5 | 6138af219efc3a8f31060e30ebc532ffcbad1768 | /experiments/norman/quaestor/src/main/scm/util/lambda-contract.scm | a9e6aca5504f0b00073aec64cdee3e4bbb502427 | [
"AFL-3.0"
] | permissive | Javastro/astrogrid-legacy | dd794b7867a4ac650d1a84bdef05dfcd135b8bb6 | 51bdbec04bacfc3bcc3af6a896e8c7f603059cd5 | refs/heads/main | 2023-06-26T10:23:01.083788 | 2021-07-30T11:17:12 | 2021-07-30T11:17:12 | 391,028,616 | 0 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 9,008 | scm | lambda-contract.scm | ;; Specify lambdas with contracts:
;;
;; (lambda/contract (<argspec>*) body ...)
;; (lambda/contract (<argspec>* -> ensure?) body ...)
;; (define/contract (funcname <argspec>*) body ...)
;; (define/contract (funcname <argspec>* -> ensure?) body ...)
;;
;; <argspec>* is a list of zero or more <argspec>
;; <argspec> is either ARGUMENT or (ARGUMENT REQUIRE?) or (ARGUMENT (<expr>))
;; where <expr> is an expression involving ARGUMENT, which evaluates
;; to true or false
;;
;; REQUIRE? and ENSURE? are predicates.
;;
;; For example:
;;
;; (define/contract (my-sqrt x
;; (y positive?)
;; (z (> z 0))
;; -> positive?) (sqrt (+ x y z)))
;;
;; The ENSURE? predicate must, at present, be a procedure, and can't yet
;; be an expr.
;;
;; Code which uses these transformers may define the handler function
;; (VIOLATED-CONTRACT FMT . ARGS), which is called when a contract is
;; violated, and which takes a format and arguments and handles them
;; as appropriate. The default VIOLATED-CONTRACT function throws an ERROR.
;;
;; $Revision: 1.2 $
;; VIOLATED-CONTRACT is called with a format string and arguments when
;; a contract is violated
(define (violated-contract fmt . args)
(error (apply format `(#f ,fmt . ,args))))
;; syntax-error trick not used
;; (define-syntax syntax-error
;; (syntax-rules ()
;; ((syntax-error) (syntax-error "Bad use of syntax error!"))))
(define-syntax lambda/contract
(syntax-rules (->)
;; interface
((_ ((arg (req ...)) . args) form . forms)
(lambda/contract "gen" () args (arg)
((,(lambda (arg) (req ...)) ,arg (req ...) arg))
form . forms))
((_ ((arg req) . args) form . forms)
(lambda/contract "gen" () args (arg)
((,req ,arg req arg))
form . forms))
((_ (-> ensure?) form . forms)
(lambda/contract "gen" () (-> ensure?) () ()
form . forms))
((_ (arg . args) form . forms)
(lambda/contract "gen" () args (arg) ()
form . forms))
((_ () form . forms) ;normal lambda
(lambda () form . forms))
;; generate the final LAMBDA or DEFINE
;; ((_ "gen" funcname (-> (expr . exprs)) arglist reqlist form . forms)
;; (lambda arglist
;; (lambda/contract "dochecks" funcname reqlist)
;; (let ((result (let () form . forms)))
;; (if ((lambda (x) (expr . exprs)) result)
;; result
;; (violated-contract
;; "Func ~a failed: blame ~a: result ~a does not satisfy ~a"
;; (quote funcname) (quote funcname) result (expr . exprs))))))
;; No FUNCNAME => produce a LAMBDA
((_ "gen" () (-> ensure?) arglist reqlist form . forms)
(lambda arglist
(lambda/contract "dochecks" "<anonymous>" reqlist)
(let ((result (let () form . forms)))
(if (ensure? result)
result
(violated-contract
"Func <anonymous> failed: blame <anonymous>: result ~a does not satisfy ~a"
result (quote ensure?))))))
((_ "gen" () () arglist reqlist form . forms)
(lambda arglist
(lambda/contract "dochecks" "<anonymous>" reqlist)
(let ()
form . forms)))
;; Non-null FUNCNAME => produce a DEFINE
((_ "gen" funcname (-> ensure?) arglist reqlist form . forms)
(define (funcname . arglist)
(lambda/contract "dochecks" funcname reqlist)
(let ((result (let () form . forms)))
(if (ensure? result)
result
(violated-contract
"Func ~a failed: blame ~a: result ~a does not satisfy ~a"
(quote funcname) (quote funcname) result (quote ensure?))))))
((_ "gen" funcname () arglist reqlist form . forms)
(define (funcname . arglist)
(lambda/contract "dochecks" funcname reqlist)
(let ()
form . forms)))
;; "dochecks" produces the reqlist checks, if any
((_ "dochecks" funcname ())
#f)
((_ "dochecks" funcname reqlist)
(let loop ((checks (quasiquote reqlist)))
(or (null? checks)
(if ((caar checks) (cadar checks))
(loop (cdr checks))
(let ((c (car checks)))
(violated-contract
"Func ~a failed: blame caller: argument ~a=~a does not satisfy ~a"
(quote funcname)
(cadddr c)
(cadr c)
(caddr c)))))))
;; iterate through the arguments
((_ "gen" funcname ((arg (req ...)) . args) (arglist ...) reqlist
form . forms)
(lambda/contract "gen" funcname args (arglist ... arg)
((,(lambda (arg) (req ...)) ,arg (req ...) arg) . reqlist)
form . forms))
((_ "gen" funcname ((arg req) . args) (arglist ...) reqlist form . forms)
(lambda/contract "gen" funcname args (arglist ... arg) ((,req ,arg req arg) . reqlist) form . forms))
((_ "gen" funcname (arg . args) (arglist ...) reqlist form . forms)
(lambda/contract "gen" funcname args (arglist ... arg) reqlist form . forms))))
(define-syntax define/contract
(syntax-rules (->)
((_ (funcname (arg (req ...)) . args) form . forms)
(lambda/contract "gen" funcname args (arg)
((,(lambda (arg) (req ...)) ,arg (req ...) arg))
form . forms))
((_ (funcname (arg req) . args) form . forms)
(lambda/contract "gen" funcname args (arg)
((,req ,arg req arg))
form . forms))
((_ (funcname -> ensure?) form . forms)
(lambda/contract "gen" funcname (-> ensure?) () () form . forms))
((_ (funcname arg . args) form . forms)
(lambda/contract "gen" funcname args (arg) () form . forms))))
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ;;
;; ;; Following is test code
;; ;; setup
;; (define fails
;; (let ((count 0))
;; (lambda args
;; (if (null? args)
;; (begin (if (= count 0)
;; (display "All tests passed!")
;; (display (format #f "Total failures: ~a" count)))
;; (newline))
;; (begin (display (format #f "Test failure evaluating ~a~% produced: ~s~% expected: ~s~%"
;; (car args) (cadr args) (caddr args)))
;; (set! count (+ count 1)))))))
;; (define-syntax expect
;; (syntax-rules ()
;; ((_ expected body ...)
;; (let ((result (call-with-current-continuation
;; (lambda (escape)
;; (violated-contract escape)
;; ((lambda () body ...))))))
;; (if (not (eq? result expected))
;; (fails '(body ...) result expected))))))
;; ;; violated-contract escape-producedure -> undef
;; ;; violated-contract fmt . args -> (escape #f)
;; (define violated-contract
;; (let ((escape #f))
;; (lambda (arg1 . args)
;; (if (null? args)
;; (set! escape arg1)
;; (escape #f)))))
;; (define (positive? x) (and (real? x) (> x 0)))
;; (define (negative? x) (and (real? x) (< x 0)))
;; ;; tests
;; ;; lambda/contract
;; ;; degenerate case: no contract
;; (define f0 (lambda/contract (x) (* x x)))
;; (expect 4 (f0 2))
;; ;; simple one-arg case
;; (define f1 (lambda/contract ((x positive?)) (* x x)))
;; (expect 4 (f1 2))
;; (expect #f (f1 -2))
;; ;; multiple args and result checking
;; (define f2 (lambda/contract ((x positive?) (y negative?) -> positive?)
;; (- (* x y))))
;; (expect 6 (f2 2 -3))
;; (expect #f (f2 2 3))
;; ;; result fails check
;; (define f3 (lambda/contract (x -> negative?) (* x x)))
;; (expect #f (f3 2))
;; ;; procedure check
;; (define f4a (lambda/contract (x (y (> y 0))) (* x y)))
;; (expect 6 (f4a 2 3))
;; (expect #f (f4a 2 -3))
;; ;; same, but with check on first arg
;; (define f4b (lambda/contract ((x (> x 0)) (y (< y 0))) (* x y)))
;; (expect -6 (f4b 2 -3))
;; (expect #f (f4b 2 3))
;; ;; ;; procedure checks on result
;; ;; doesn't work
;; ;; (define f5 (lambda/contract (x y -> (> x 0)) (* x y))) (newline)
;; ;; (expect 6 (f5 2 3))
;; ;; (expect #f (f5 2 -3))
;; ;; define/contract
;; ;; degenerate case: no contract
;; (define/contract (f10 x y) (* x y))
;; (expect 6 (f10 2 3))
;; ;; simple case
;; (define/contract (f11 x -> positive?) (* x x))
;; (expect 4 (f11 2))
;; ;; no-arg case
;; (define/contract (f12 -> positive?) -2)
;; (expect #f (f12))
;; ;; multiple args and result checking, with define/contract
;; (define/contract (f13 (x positive?) (y negative?) -> positive?)
;; (- (* x y)))
;; (expect 6 (f13 2 -3))
;; (expect #f (f13 2 3))
;; ;; procedure checks
;; (define/contract (f14 (x (> x 0)) (y (< y 0))) (* x y))
;; (expect -6 (f14 2 -3))
;; (expect #f (f14 2 3))
;; ;; report number of failures
;; (fails)
| true |
4216fb296ca6e1b61c272d85efd09f12ba8bcd22 | 27b46612047e4f2b0a2d47b6c35a0078d4b16ee9 | /scheme-desugar.scm | fdb672468e02011b07ba6eceaaaf8e16e5f4ad7d | [
"BSD-2-Clause"
] | permissive | narslan/pgg | f709705861e3d6a6b46fd9519d3635d073fb2c28 | 620f6596e8791e4ea94103a5b8ace6a30aadc0a8 | refs/heads/master | 2023-06-10T15:01:42.934875 | 2012-12-31T15:09:37 | 2012-12-31T15:09:37 | null | 0 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 765 | scm | scheme-desugar.scm | ;;; scheme-desugar
(define *macro-source*
(file->list
(namestring "scheme-standard-macros.scm"
(file-name-directory (%file-name%))
#f)))
(define (desugar job-file/files)
(let* ((source-files
(if (string? job-file/files)
(map symbol->string (file->list job-file/files))
job-file/files))
(full-source
(cons `(BEGIN ,@*macro-source*)
(map (lambda (filename)
`(BEGIN ,@(file->list filename)))
source-files))))
(call-with-values
(lambda ()
(scheme-desugar full-source))
(lambda (d* rejected*)
(if (not (null? rejected*))
(begin
(display "Warning: desugar cannot resolve toplevel expressions")
(newline)
(display rejected*)
(newline)))
d*))))
| false |
afde76cd2d84a386b7671c5e70d5ca46a49f4568 | cda86fc9bb0192a76efe32873c18b5800b3429da | /tex-parser.sld | c9507b3d1781eb013412407cb258d679d6f1a78e | [
"MIT"
] | permissive | lassik/scheme | f822b3a16dfa436ff76e973c78a9622c56c1fd19 | 118dd55027ef014ea43e95c1655430725a53a0b0 | refs/heads/master | 2023-08-19T04:55:51.721642 | 2021-09-29T16:20:34 | 2021-09-29T16:20:34 | 222,323,133 | 2 | 1 | null | null | null | null | UTF-8 | Scheme | false | false | 200 | sld | tex-parser.sld | (define-library (lassik tex-parser)
(export read-tex-document)
(import (scheme base)
(scheme char)
(scheme file)
(lassik read-char-if))
(include "tex-parser.scm"))
| false |
20e6df3f4961b7cef18dfe931f308a6bb0d55602 | f5083e14d7e451225c8590cc6aabe68fac63ffbd | /cs/01-Programming/sicp/exercices/3.68.scm | 8776e888b4f9c385f130a91c6ea328d369a9dbb4 | [] | no_license | Phantas0s/playground | a362653a8feb7acd68a7637334068cde0fe9d32e | c84ec0410a43c84a63dc5093e1c214a0f102edae | refs/heads/master | 2022-05-09T06:33:25.625750 | 2022-04-19T14:57:28 | 2022-04-19T14:57:28 | 136,804,123 | 19 | 5 | null | 2021-03-04T14:21:07 | 2018-06-10T11:46:19 | Racket | UTF-8 | Scheme | false | false | 598 | scm | 3.68.scm | ; Louis Reasoner thinks that building a stream
; of pairs from three parts is unnecessarily complicated. In-
; stead of separating the pair (S 0 , T0 ) from the rest of the pairs
; in the first row, he proposes to work with the whole first
; row, as follows:
(define (pairs s t)
(interleave
(stream-map (lambda (x) (list (stream-car s) x)) t)
(pairs (stream-cdr s) (stream-cdr t))))
; Does this work? Consider what happens if we evaluate (pairs
; integers integers) using Louis’s definition of pairs.
; It will create an infinite loop: pairs will be called indefinitely.
; **GOOD**
| false |
2cb2f419d1c36115ca6fddb3ca6db025f280a0b8 | 4b2aeafb5610b008009b9f4037d42c6e98f8ea73 | /10.1/queue.scm | 0d321b77da9c19d566b04dd840e554814f5c2213 | [] | no_license | mrinalabrol/clrs | cd461d1a04e6278291f6555273d709f48e48de9c | f85a8f0036f0946c9e64dde3259a19acc62b74a1 | refs/heads/master | 2021-01-17T23:47:45.261326 | 2010-09-29T00:43:32 | 2010-09-29T00:43:32 | null | 0 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 1,011 | scm | queue.scm | (define-record-type :queue
(make-queue data head tail)
queue?
(data queue-data)
(head queue-head set-queue-head!)
(tail queue-tail set-queue-tail!))
(define (queue-empty? queue)
(= (queue-head queue) (queue-tail queue)))
(define (queue-full? queue)
(= (queue-head queue)
(modulo (+ (queue-tail queue) 1)
(vector-length (queue-data queue)))))
(define (enqueue! queue x)
(if (queue-full? queue)
(error "Queue full -- ENQUEUE!")
(let ((data (queue-data queue))
(tail (queue-tail queue)))
(vector-set! data tail x)
(set-queue-tail! queue
(modulo (+ tail 1) (vector-length data))))))
(define (dequeue! queue)
(if (queue-empty? queue)
(error "Queue empty -- DEQUEUE!")
(let ((data (queue-data queue))
(head (queue-head queue)))
(let ((x (vector-ref data head)))
(set-queue-head! queue
(modulo (+ head 1) (vector-length data)))
x))))
| false |
db538410fd04718d2d221c4274919ad8191cba0e | 056e32c41e03203c63d9fbc65dd87029daed001c | /tizoc/chibi/zmq.sld | 2e60dd32d656171a73a384ffe9bf248747f8e2ab | [] | no_license | jrmoya21/scheme-code | 1fb67f597f5c50f4dacb81003008f5eeced27caa | 1ddc2af56d2342cac837612f11d52d405f658fd6 | refs/heads/master | 2021-01-18T19:33:52.691297 | 2012-05-20T00:06:35 | 2012-05-20T00:06:35 | null | 0 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 1,355 | sld | zmq.sld | (define-library (tizoc chibi zmq)
(export
;; Socket types
zmq-socket-type/pair
zmq-socket-type/sub
zmq-socket-type/pub
zmq-socket-type/req
zmq-socket-type/rep
zmq-socket-type/xreq
zmq-socket-type/xrep
zmq-socket-type/push
zmq-socket-type/pull
zmq-socket-type/upstream
zmq-socket-type/downstream
;; Messaging flags
zmq-messaging-flag/sndmore
zmq-messaging-flag/rcvmore
zmq-messaging-flag/noblock
;; Socket options
zmq-socket-option/hwm
zmq-socket-option/swap
zmq-socket-option/affinity
zmq-socket-option/identity
zmq-socket-option/subscribe
zmq-socket-option/unsubscribe
zmq-socket-option/rate
zmq-socket-option/recovery-ivl
zmq-socket-option/mcast-loop
zmq-socket-option/sndbuf
zmq-socket-option/rcvbuf
;; Type predicates
socket?
context?
;; API calls
zmq-version
make-context
terminate-context
make-socket
close-socket
socket-option
socket-option-set!
bind-socket
connect-socket
send-message
receive-message
send-message/noblock
receive-message/noblock
;; Multiplexing
select
;; TODO: use exceptions?
zmq-errno
zmq-strerror
;; TODO socket-fd
;; Parameters
zmq-default-context
zmq-io-threads
)
(import (scheme) (srfi 39))
(include-shared "zmq/zmq")
(include "zmq/zmq.scm"))
| false |
076502a72e1b2f172377f76daf5bf620983a0f54 | 12fc725f8273ebfd9ece9ec19af748036823f495 | /daemon/variants/linux.var.ss | 53a988442faa467a7ed864b468e9093f5b088b0f | [] | no_license | contextlogger/contextlogger2 | 538e80c120f206553c4c88c5fc51546ae848785e | 8af400c3da088f25fd1420dd63889aff5feb1102 | refs/heads/master | 2020-05-05T05:03:47.896638 | 2011-10-05T23:50:14 | 2011-10-05T23:50:14 | 1,675,623 | 1 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 182 | ss | linux.var.ss | #lang scheme
#|
Sensible defaults for Linux builds.
|#
(require "base.ss")
(require common/usual-4)
(require konffaile/variant)
(define* (info)
(make-object linux-variant%))
| false |
372f4c25f1536cf499ccda2f90f7c7b90e4fd7f4 | a66514d577470329b9f0bf39e5c3a32a6d01a70d | /netstring.sls | c11350fc5d27e2a070ce3728ec1307a700291efa | [
"Apache-2.0"
] | permissive | ovenpasta/thunderchez | 2557819a41114423a4e664ead7c521608e7b6b42 | 268d0d7da87fdeb5f25bdcd5e62217398d958d59 | refs/heads/trunk | 2022-08-31T15:01:37.734079 | 2021-07-25T14:59:53 | 2022-08-18T09:33:35 | 62,828,147 | 149 | 29 | null | 2022-08-18T09:33:37 | 2016-07-07T18:07:23 | Common Lisp | UTF-8 | Scheme | false | false | 2,063 | sls | netstring.sls | ;;
;; Copyright 2016 Aldo Nicolas Bruno
;;
;; Licensed under the Apache License, Version 2.0 (the "License");
;; you may not use this file except in compliance with the License.
;; You may obtain a copy of the License at
;;
;; http://www.apache.org/licenses/LICENSE-2.0
;;
;; Unless required by applicable law or agreed to in writing, software
;; distributed under the License is distributed on an "AS IS" BASIS,
;; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
;; See the License for the specific language governing permissions and
;; limitations under the License.
(library (netstring)
(export read-netstring write-netstring read-netstring/string)
(import (chezscheme))
(define (read-netstring port)
(let loop ([len 0])
(let ([c (get-u8 port)] )
(when (eof-object? c)
(errorf 'read-netstring "unexpected end of file while reading header"))
(cond
[(<= #x30 c #x39)
(loop (fx+ (fx* 10 len) (fx- c #x30)))]
[(fx= c (char->integer #\:))
(let ([r (get-bytevector-n port len)])
(when (or (eof-object? r)
(< (bytevector-length r) len))
(errorf 'read-netstring "unexpected end of file while reading data"))
(unless (eqv? (get-u8 port) (char->integer #\,))
(errorf 'read-netstring "expected , at end of netstring" ))
r)]
[else
(errorf 'read-netstring "unexpected character while reading header #x~x" c)]))))
(define (read-netstring/string port)
(utf8->string (read-netstring port)))
(define (write-netstring port data)
(let ([data (if (string? data) (string->utf8 data) data)])
(put-bytevector port (string->utf8 (number->string (bytevector-length data))))
(put-u8 port (char->integer #\:))
(put-bytevector port data)
(put-u8 port (char->integer #\,)))))
#|
(define msg "abcdefghijkl")
(define-values (pt bv) (open-bytevector-output-port))
(write-netstring pt msg)
(define x (bv))
(if (equal? msg
(read-netstring/string (open-bytevector-input-port x)))
(printf "test OK~n")
(printf "test FAILED~n"))
|#
| false |
9d5c4ed16231669da54a3d4cf0514bb49a8950a7 | 4890b89d4e190ad152c26f5f1565d1157c0972e7 | /Compiler/discard-call-live.ss | 7580a560edd932a9ba78460910a67ed5e4b5541a | [] | no_license | haskellstudio/p-423-Compiler | e2791bae1b966cd1650575e39eef10b4c7205ca1 | 36be558647ecd5786b02df42865d0ffa2a57fa2f | refs/heads/master | 2021-01-25T13:11:49.825526 | 2017-11-09T03:48:00 | 2017-11-09T03:48:00 | null | 0 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 1,427 | ss | discard-call-live.ss | (library
(Compiler discard-call-live)
(export discard-call-live)
(import (chezscheme)
(Framework helpers)
(Framework match))
(define-who discard-call-live
(define Tail
(lambda (tail)
(match tail
[(begin ,[Effect -> ef*] ... ,[tail]) `(begin ,ef* ... ,tail)]
[(if ,[Pred -> test] ,[conseq] ,[altern]) `(if ,test ,conseq ,altern)]
[(,t ,etc* ...) `(,t)]
[,tail (error who "invalid Tail ~s" tail)])))
(define Pred
(lambda (pred)
(match pred
[(if ,[test] ,[conseq] ,[altern]) `(if ,test ,conseq ,altern)]
[(begin ,[Effect -> ef*] ... ,[pred]) `(begin ,ef* ... ,pred)]
[,x x])))
(define Effect
(lambda (eff)
(match eff
[(if ,[Pred -> test] ,[conseq] ,[altern]) `(if ,test ,conseq ,altern)]
[(begin ,[ef*] ... ,[eff]) `(begin ,ef* ... ,eff)]
[(return-point ,rp-label ,[Tail -> tail]) `(return-point ,rp-label ,tail)]
[,x x])))
(define Body
(lambda (bd)
(match bd
[(locate ([,uvar* ,loc*] ...) ,[Tail -> tail])
`(locate ([,uvar* ,loc*] ...) ,tail)]
[,bd (error who "invalid Body ~s" bd)])))
(lambda (x)
(match x
[(letrec ([,label* (lambda () ,[Body -> bd*])] ...) ,[Body -> bd])
`(letrec ([,label* (lambda () ,bd*)] ...) ,bd)]
[,x (error who "invalid Program ~s" x)])))
) | false |
24429c7c6f6307d1e85146fcd408b0a24bf7e59d | 08b21a94e7d29f08ca6452b148fcc873d71e2bae | /src/loki/util.sld | dcb2a5d80a073f6a9e9829dbb4bf97997c327b89 | [
"MIT"
] | permissive | rickbutton/loki | cbdd7ad13b27e275bb6e160e7380847d7fcf3b3a | 7addd2985de5cee206010043aaf112c77e21f475 | refs/heads/master | 2021-12-23T09:05:06.552835 | 2021-06-13T08:38:23 | 2021-06-13T08:38:23 | 200,152,485 | 21 | 1 | NOASSERTION | 2020-07-16T06:51:33 | 2019-08-02T02:42:39 | Scheme | UTF-8 | Scheme | false | false | 3,104 | sld | util.sld | (define-library
(loki util)
(import (scheme base))
(import (scheme eval))
(import (scheme write))
(cond-expand
(gauche (import (gauche base))))
(export
pretty
map-vector
fold-left
all-but-last
index
contains?
range
debug
make-anon-id
make-named-id
fluid-let
memp
for-all
write-to-string)
(begin
(define (map-vector fn vec)
(list->vector (map fn (vector->list vec))))
(define (fold-left f init seq)
(if (null? seq)
init
(fold-left f
(f (car seq) init)
(cdr seq))))
(define (all-but-last l) (reverse (cdr (reverse l))))
(define (index a b)
(let ((tail (member a (reverse b))))
(and tail (length (cdr tail)))))
(define (contains? l i)
(if (null? l) #f
(or (eq? (car l) i) (contains? (cdr l) i))))
(define (range start end step)
(reverse (range-reversed '() start end step)))
(define (range-reversed fold-var pos end step)
(if (if (>= step 0)
(< pos end)
(> pos end))
(range-reversed
(cons pos fold-var)
(+ pos step)
end
step)
fold-var))
(define (pretty v . args)
(let ((out (if (pair? args) (car args) (current-output-port))))
(cond-expand
(gauche (pprint v :port out :newline #f))
(else (display v out)))
(newline out)))
(define (debug . args)
(for-all (lambda (a)
(display a)
(display " ")) args)
(display "\n\n"))
(define (make-anon-id prefix)
(let ((count 0))
(lambda ()
(set! count (+ 1 count))
(string->symbol (string-append prefix (number->string count))))))
(define (make-named-id prefix)
(let ((count 0))
(lambda (name)
(set! count (+ 1 count))
(string->symbol (string-append prefix (number->string count) "_" (symbol->string name))))))
(define-syntax fluid-let
(syntax-rules ()
((fluid-let () be ...)
(begin be ...))
((fluid-let ((p0 e0) (p e) ...) be ...)
(let ((saved p0))
(set! p0 e0)
(call-with-values (lambda ()
(fluid-let ((p e) ...) be ...))
(lambda results
(set! p0 saved)
(apply values results)))))))
(define (memp proc ls)
(cond ((null? ls) #f)
((pair? ls) (if (proc (car ls))
ls
(memp proc (cdr ls))))
(else (error "memp: Invalid argument" ls))))
(define (for-all proc l . ls)
(or (null? l)
(and (apply proc (car l) (map car ls))
(apply for-all proc (cdr l) (map cdr ls)))))
(define (write-to-string obj)
(let ((port (open-output-string)))
(write obj port)
(get-output-string port)))
))
| true |
a135d582d2a13a2d24885b5b8696ea6848d080d8 | dae624fc36a9d8f4df26f2f787ddce942b030139 | /chapter-08/case.scm | 3880f07794d5cd414dd88a7969da900ae6d137ce | [
"MIT"
] | permissive | hshiozawa/gauche-book | 67dcd238c2edeeacb1032ce4b7345560b959b243 | 2f899be8a68aee64b6a9844f9cbe83eef324abb5 | refs/heads/master | 2020-05-30T20:58:40.752116 | 2019-10-01T08:11:59 | 2019-10-01T08:11:59 | 189,961,787 | 0 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 274 | scm | case.scm | (define (score card)
(case card
((A) 11)
((J Q K) 10)
((2 3 4 5 6 7 8 9 10) card)))
(define (draw-card) 4)
(define (score card)
(case (draw-card)
((A) 11)
((J Q K) 10)
((2 3 4 5 6 7 8 9 10) => (lambda (x) x))))
(score 4)
(score 'A)
(score 'K)
| false |
b3757f843dda290c49a0fbd12185e56c2ca56cc7 | a07eccf73366c0588f0694a26c1a55e27ead079d | /01-toyos-jit/os_tests.scm | 949b12553037aff7473049988d24b8f21e9fcddc | [] | no_license | namin/reflection-schemes | a98a83d88a75ba72a5b9445185ed68c0ab973f19 | f99d7d937938fcdd70d5854b6ea77e5260d7c8ba | refs/heads/master | 2022-06-09T13:22:04.929019 | 2022-05-20T09:31:17 | 2022-05-20T09:31:17 | 233,351,280 | 20 | 2 | null | 2020-01-14T06:28:23 | 2020-01-12T06:54:06 | Scheme | UTF-8 | Scheme | false | false | 1,119 | scm | os_tests.scm | (define (factorial-process n)
(full-copy
`((:exp
.
(begin
(if (= n 0)
(set! :done #t)
(begin
(set! result (* n result))
(set! n (- n 1))))
result))
(:env . ((result . 1) (n . ,n))))))
(define (double-process p)
(full-copy-but (list p)
`((:exp
.
(begin
(block p)
(set! result (* 2 (get (get p ':env) ':result #f)))
(set! :done #t)
result))
(:env . ((:result . #f) (p . ,p))))))
(eg
(run (factorial-process 6))
'((result . 6) (n . 5) (:result . 6) ))
(eg
(let ((f6 (factorial-process 6)))
(step* (list f6))
(get (get f6 ':env) ':result))
720)
(eg
(run-only (factorial-process 6))
720)
(eg
(let ((f6 (factorial-process 6))
(f5 (factorial-process 5)))
(step* (list f6 f5))
(list
(get (get f6 ':env) ':result)
(get (get f5 ':env) ':result)))
'(720 120))
(eg
(let ((d6 (double-process (factorial-process 6))))
(set! alive-processes (list d6))
(step*!)
(get (get d6 ':env) ':result))
1440)
(eg
(run-program-once '(* 1 2 3))
6)
| false |
82fd01444dc06fcb8a557d12c2428d1547206dd6 | 4f30ba37cfe5ec9f5defe52a29e879cf92f183ee | /src/tests/test-read.scm | ccd0886b694da1711dde7b6f133d7a4426c29966 | [
"MIT"
] | permissive | rtrusso/scp | e31ecae62adb372b0886909c8108d109407bcd62 | d647639ecb8e5a87c0a31a7c9d4b6a26208fbc53 | refs/heads/master | 2021-07-20T00:46:52.889648 | 2021-06-14T00:31:07 | 2021-06-14T00:31:07 | 167,993,024 | 8 | 1 | MIT | 2021-06-14T00:31:07 | 2019-01-28T16:17:18 | Scheme | UTF-8 | Scheme | false | false | 263 | scm | test-read.scm | (define o (current-output-port))
(define f (open-input-file "tests/test-read.scm"))
(if (input-port? f)
(let ((x (read-char f)))
(display x)
(newline)
(close-input-port f))
(begin (display 9999)
(newline)))
(write-char #\a o)
| false |
afa469d006ae4a79648287f80325ee3593386234 | 7666204be35fcbc664e29fd0742a18841a7b601d | /code/4-24.wrapper2.scm | 85ec999e0cc9eee192a17088953bc78a044dbe9e | [] | no_license | cosail/sicp | b8a78932e40bd1a54415e50312e911d558f893eb | 3ff79fd94eda81c315a1cee0165cec3c4dbcc43c | refs/heads/master | 2021-01-18T04:47:30.692237 | 2014-01-06T13:32:54 | 2014-01-06T13:32:54 | null | 0 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 180 | scm | 4-24.wrapper2.scm | (define dont-run-all 1)
(include "4.1.7.scm")
(define start (get-internal-real-time))
(driver-loop)
(define end (get-internal-real-time))
(display (/ (- end start) 1000000000.0))
| false |
23b9cb1c907aa9e9ee868d134ab0d18a30d069b7 | dafce3f01299ab8a1315908ec6ad0328189e4af5 | /instructions-test.scm | fffb5a0588dc72980f060128a7e9ea219ef251b8 | [] | no_license | yi-jiayu/CHIC-8 | c1020898ca745c92251447544c604045a6ff2c39 | 0eccf66d4fd10bb78e776b0b65353911937b1328 | refs/heads/master | 2020-05-21T05:34:59.713713 | 2019-05-12T12:12:17 | 2019-05-12T12:12:17 | 185,925,558 | 0 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 404 | scm | instructions-test.scm | (include-relative "instructions")
(import test)
(test-group "subroutine-call"
(let ((ip (new-interpreter)))
(subroutine-call! ip '(#x0A . #xBC))
(test "stack pointer should be incremented to 1" 1 (interpreter-sp ip))
(test "first element of stack should be previous pc" #x200 (vector-ref (interpreter-stack ip) 0))
(test "new pc should be 0xABC" #xABC (interpreter-pc ip))))
(test-exit)
| false |
a75ede8e3b5ab76cd75db02260f414a047dba4bd | 15b3f9425594407e43dd57411a458daae76d56f6 | /bin/compiler/test/letrec.scm | 44a6684efa86443b4f6d400a5ce377506eb48bd7 | [] | no_license | aa10000/scheme | ecc2d50b9d5500257ace9ebbbae44dfcc0a16917 | 47633d7fc4d82d739a62ceec75c111f6549b1650 | refs/heads/master | 2021-05-30T06:06:32.004446 | 2015-02-12T23:42:25 | 2015-02-12T23:42:25 | null | 0 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 40 | scm | letrec.scm | (display
(letrec ((a 1)
(b 2))
a)
)
| false |
b8e1d1e71282d7f1df938cedc3169a8c2f5f0e9c | bd59d4af87e34e6db598dbd098a1c89a486f85ef | /tests/x86disasm.sps | 9ec616d4d31d50d8fa4c7d3df4c98b2cd87d8638 | [
"MIT"
] | permissive | inspier/machine-code | 02951911e5448f50b72b363579c1a63584651afc | c392236f98c5279bc875e7e5f4d59379dc440464 | refs/heads/master | 2022-03-31T07:46:48.895240 | 2019-06-22T19:22:21 | 2019-06-22T19:47:48 | null | 0 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 29,731 | sps | x86disasm.sps | #!/usr/bin/env scheme-script
;; -*- mode: scheme; coding: utf-8 -*- !#
;; Copyright © 2008, 2009, 2010, 2012, 2013, 2016, 2017, 2018 Göran Weinholt <[email protected]>
;; SPDX-License-Identifier: MIT
#!r6rs
(import
(rnrs (6))
(machine-code tests check)
(machine-code disassembler x86))
(define (test mode input)
(let ((port (open-bytevector-input-port input))
(bytes-returned 0))
(let lp ((insrs '()))
(let ((i (get-instruction
port mode
(lambda (_ . bytes)
(set! bytes-returned
(+ (length bytes)
bytes-returned)))
#f)))
(cond ((eof-object? i)
(unless (port-eof? port)
(error 'test "After disassembly there are bytes unread."
(get-bytevector-all port)))
(unless (= bytes-returned (bytevector-length input))
(error 'test "There are bytes missing in the collector function."
bytes-returned (bytevector-length input)))
(reverse insrs))
(else
(lp (cons i insrs))))))))
(define-syntax test64
(lambda (x)
(syntax-case x ()
((_ bytes insrs ...)
#'(check (test 64 bytes) => (list insrs ...))))))
(define-syntax test32
(lambda (x)
(syntax-case x ()
((_ bytes insrs ...)
#'(check (test 32 bytes) => (list insrs ...))))))
(define-syntax test16
(lambda (x)
(syntax-case x ()
((_ bytes insrs ...)
#'(check (test 16 bytes) => (list insrs ...))))))
;;; Various
(test64 '#vu8(#x03 #x05 #x00 #x00 #x00 #x00)
'(add eax (mem32+ rip 0)))
(test32 '#vu8(#x03 #x05 #x00 #x00 #x00 #x00)
'(add eax (mem32+ 0)))
(test64 '#vu8(#x0F #x01 #xC3)
'(vmresume))
(test64 '#vu8(#x0F #xA4 #x05 #x00 #x00 #x00 #x00 #x03)
'(shld (mem32+ rip 0) eax 3))
(test64 '#vu8(#x66 #x0F #x3A #x0F #xC1 #x08)
'(palignr xmm0 xmm1 8))
(test64 '#vu8(#x66 #x90)
'(xchg ax ax))
(test64 '#vu8(#x90)
'(nop))
(test64 '#vu8(#x69 #x6c #x6c #x65 #x6e #x69 #x75 #x6d)
'(imul ebp (mem32+ rsp 101 (* rbp 2)) #x6d75696e))
(test64 '#vu8(#x0F #x01 #xF8)
'(swapgs))
(test64 '#vu8(#x0F #x01 #xF9)
'(rdtscp))
(test64 '#vu8(#x0F #x00 #xD8)
'(ltr ax))
(test64 '#vu8(#x0F #x01 #xDE #x0F #x01 #xC9)
'(skinit)
'(mwait))
(test64 '#vu8(#x66 #x41 #x0F #x38 #xDC #xC5)
'(aesenc xmm0 xmm13))
(test64 '#vu8(#x66 #x44 #x0F #x7C #xE9)
'(haddpd xmm13 xmm1))
(test64 '#vu8(#xC4 #xE3 #x79 #x05 #xF2 #x2A)
'(vpermilpd xmm6 xmm2 42))
(test64 '#vu8(#x41 #x8d #x44 #x24 #xff)
'(lea eax (mem+ r12 -1)))
(test64 '#vu8(#x41 #x8d #x54 #x24 #x20)
'(lea edx (mem+ r12 #x20)))
;;; Test the REP/REPE/REPNZ prefix
(test64 '#vu8(#xF3 #xAC
#xF3 #xAD
#xF3 #x48 #xAD)
'(rep.lods al (mem8+ rsi))
'(rep.lods eax (mem32+ rsi))
'(rep.lods rax (mem64+ rsi)))
(test64 '#vu8(#xF3 #x6E
#xF3 #x66 #x6F
#xF3 #x6F
#x6E
#x66 #x6F
#x6F)
'(rep.outs dx (mem8+ rsi))
'(rep.outs dx (mem16+ rsi))
'(rep.outs dx (mem32+ rsi))
'(outs dx (mem8+ rsi))
'(outs dx (mem16+ rsi))
'(outs dx (mem32+ rsi)))
(test64 '#vu8(#xF3 #xAA
#xF3 #x66 #xAB
#xF3 #xAB
#xF3 #x48 #xAB
#x66 #xAB)
'(rep.stos (mem8+ rdi) al)
'(rep.stos (mem16+ rdi) ax)
'(rep.stos (mem32+ rdi) eax)
'(rep.stos (mem64+ rdi) rax)
'(stos (mem16+ rdi) ax))
(test64 '#vu8(#xF3 #xA6
#xF2 #xA6
#xF3 #x48 #xA7
#xF2 #x66 #xA7
#xA6)
'(repz.cmps (mem8+ rsi) (mem8+ rdi))
'(repnz.cmps (mem8+ rsi) (mem8+ rdi))
'(repz.cmps (mem64+ rsi) (mem64+ rdi))
'(repnz.cmps (mem16+ rsi) (mem16+ rdi))
'(cmps (mem8+ rsi) (mem8+ rdi)))
(test64 '#vu8(#xF2 #x66 #xAF
#xF3 #xAE
#x48 #xAF)
'(repnz.scas ax (mem16+ rdi))
'(repz.scas al (mem8+ rdi))
'(scas rax (mem64+ rdi)))
(test64 '#vu8(#xf3 #xae
#xf3 #xaa
#xf3 #x6c
#xf3 #xa6
#xf3 #xa4
#xf3 #xac
#xf3 #x6e)
;;repz scas %es:(%rdi),%al
'(repz.scas al (mem8+ rdi))
;;rep stos %al,%es:(%rdi)
'(rep.stos (mem8+ rdi) al)
;;rep insb (%dx),%es:(%rdi)
'(rep.ins (mem8+ rdi) dx)
;;repz cmpsb %es:(%rdi),%ds:(%rsi)
'(repz.cmps (mem8+ rsi) (mem8+ rdi))
;;rep movsb %ds:(%rsi),%es:(%rdi)
'(rep.movs (mem8+ rdi) (mem8+ rsi))
;;rep lods %ds:(%rsi),%al
'(rep.lods al (mem8+ rsi))
;;rep outsb %ds:(%rsi),(%dx)
'(rep.outs dx (mem8+ rsi)))
;;; Test a bunch of ModR/M bytes
(test64 '#vu8(#x8D #x0
#x8D #x1
#x8D #x2
#x8D #x3
#x8D #x4
#x25 #x0 #x0 #x0 #x0
#x8D #x5 #xEB #xFF #xFF #xFF
#x8D #x6
#x8D #x7 #x41
#x8D #x0 #x41
#x8D #x1 #x41
#x8D #x2 #x41
#x8D #x3 #x41
#x8D #x4 #x25 #x0 #x0 #x0 #x0 #x41
#x8D #x5 #xCC #xFF #xFF #xFF #x41
#x8D #x6 #x41
#x8D #x7
#x8D #x40 #x7F
#x8D #x41 #x7F
#x8D #x42 #x7F
#x8D #x43 #x7F
#x8D #x44 #xC0 #x7F
#x8D #x45 #x7F
#x8D #x46 #x7F
#x8D #x47 #x7F
#x41 #x8D #x40 #x7F
#x41 #x8D #x41 #x7F
#x41 #x8D #x42 #x7F
#x41 #x8D #x43 #x7F
#x41 #x8D #x44 #x24 #x7F
#x41 #x8D #x44 #xC0 #x7F
#x41 #x8D #x45 #x7F
#x41 #x8D #x46 #x7F
#x41 #x8D #x47 #x7F
#x8D #x80 #x80 #x0 #x0 #x0
#x8D #x81 #x80 #x0 #x0 #x0
#x8D #x82 #x80 #x0 #x0 #x0
#x8D #x83 #x80 #x0 #x0 #x0
#x8D #x84 #xC0 #x80 #x0 #x0 #x0
#x8D #x85 #x80 #x0 #x0 #x0
#x8D #x86 #x80 #x0 #x0 #x0
#x8D #x87 #x80 #x0 #x0 #x0
#x41 #x8D #x80 #x80 #x0 #x0 #x0
#x41 #x8D #x81 #x80 #x0 #x0 #x0
#x41 #x8D #x82 #x80 #x0 #x0 #x0
#x41 #x8D #x83 #x80 #x0 #x0 #x0
#x41 #x8D #x84 #x24 #x80 #x0 #x0 #x0
#x41 #x8D #x84 #xC0 #x80 #x0 #x0 #x0
#x41 #x8D #x85 #x80 #x0 #x0 #x0
#x41 #x8D #x86 #x80 #x0 #x0 #x0
#x41 #x8D #x87 #x80 #x0 #x0 #x0
#x30 #xC0
#x30 #xC1
#x30 #xC2
#x30 #xC3
#x30 #xC4
#x30 #xC5
#x30 #xC6
#x30 #xC7
#x40 #x30 #xC0
#x40 #x30 #xC1
#x40 #x30 #xC2
#x40 #x30 #xC3
#x40 #x30 #xC4
#x40 #x30 #xC5
#x40 #x30 #xC6
#x40 #x30 #xC7
#x41 #x30 #xC0
#x41 #x30 #xC1
#x41 #x30 #xC2
#x41 #x30 #xC3
#x41 #x30 #xC4
#x41 #x30 #xC5
#x41 #x30 #xC6
#x41 #x30 #xC7
#x41 #x30 #xCF
#x41 #x30 #xD7
#x41 #x30 #xDF
#x41 #x30 #xE7
#x41 #x30 #xEF
#x41 #x30 #xF7
#x41 #x30 #xFF
#x45 #x30 #xC7
#x45 #x30 #xCF
#x45 #x30 #xD7
#x45 #x30 #xDF
#x45 #x30 #xE7
#x45 #x30 #xEF
#x45 #x30 #xF7
#x45 #x30 #xFF)
'(lea eax (mem+ rax))
'(lea eax (mem+ rcx))
'(lea eax (mem+ rdx))
'(lea eax (mem+ rbx))
'(lea eax (mem+ 0))
'(lea eax (mem+ rip -21))
'(lea eax (mem+ rsi))
'(lea eax (mem+ rdi))
'(lea eax (mem+ r8))
'(lea eax (mem+ r9))
'(lea eax (mem+ r10))
'(lea eax (mem+ r11))
'(lea eax (mem+ 0))
'(lea eax (mem+ rip -52))
'(lea eax (mem+ r14))
'(lea eax (mem+ r15))
'(lea eax (mem+ rax 127))
'(lea eax (mem+ rcx 127))
'(lea eax (mem+ rdx 127))
'(lea eax (mem+ rbx 127))
'(lea eax (mem+ rax 127 (* rax 8)))
'(lea eax (mem+ rbp 127))
'(lea eax (mem+ rsi 127))
'(lea eax (mem+ rdi 127))
'(lea eax (mem+ r8 127))
'(lea eax (mem+ r9 127))
'(lea eax (mem+ r10 127))
'(lea eax (mem+ r11 127))
'(lea eax (mem+ r12 127))
'(lea eax (mem+ r8 127 (* rax 8)))
'(lea eax (mem+ r13 127))
'(lea eax (mem+ r14 127))
'(lea eax (mem+ r15 127))
'(lea eax (mem+ rax 128))
'(lea eax (mem+ rcx 128))
'(lea eax (mem+ rdx 128))
'(lea eax (mem+ rbx 128))
'(lea eax (mem+ rax 128 (* rax 8)))
'(lea eax (mem+ rbp 128))
'(lea eax (mem+ rsi 128))
'(lea eax (mem+ rdi 128))
'(lea eax (mem+ r8 128))
'(lea eax (mem+ r9 128))
'(lea eax (mem+ r10 128))
'(lea eax (mem+ r11 128))
'(lea eax (mem+ r12 128))
'(lea eax (mem+ r8 128 (* rax 8)))
'(lea eax (mem+ r13 128))
'(lea eax (mem+ r14 128))
'(lea eax (mem+ r15 128))
'(xor al al)
'(xor cl al)
'(xor dl al)
'(xor bl al)
'(xor ah al)
'(xor ch al)
'(xor dh al)
'(xor bh al)
'(xor al al)
'(xor cl al)
'(xor dl al)
'(xor bl al)
'(xor spl al)
'(xor bpl al)
'(xor sil al)
'(xor dil al)
'(xor r8b al)
'(xor r9b al)
'(xor r10b al)
'(xor r11b al)
'(xor r12b al)
'(xor r13b al)
'(xor r14b al)
'(xor r15b al)
'(xor r15b cl)
'(xor r15b dl)
'(xor r15b bl)
'(xor r15b spl)
'(xor r15b bpl)
'(xor r15b sil)
'(xor r15b dil)
'(xor r15b r8b)
'(xor r15b r9b)
'(xor r15b r10b)
'(xor r15b r11b)
'(xor r15b r12b)
'(xor r15b r13b)
'(xor r15b r14b)
'(xor r15b r15b))
(test64 '#vu8(#x4c #x89 #x2c #xc5 #x00 #x40 #x23 #x00)
'(mov (mem64+ #x234000 (* rax 8)) r13))
;;; Test sign-extended immediates
(test64 '#vu8(#x24 #xF0
#x66 #x25 #xF0 #xFF
#x25 #xF0 #xFF #xFF #xFF
#x48 #x25 #xF0 #xFF #xFF #xFF
#x80 #x20 #xF0
#x66 #x81 #x20 #xF0 #xFF
#x81 #x20 #xF0 #xFF #xFF #xFF
#x48 #x81 #x20 #xF0 #xFF #xFF #xFF
#x66 #x83 #x20 #xF0
#x83 #x20 #xF0
#x48 #x83 #x20 #xF0)
'(and al #xF0)
'(and ax #xFFF0)
'(and eax #xFFFFFFF0)
'(and rax #xFFFFFFFFFFFFFFF0)
'(and (mem8+ rax) #xF0)
'(and (mem16+ rax) #xFFF0)
'(and (mem32+ rax) #xFFFFFFF0)
'(and (mem64+ rax) #xFFFFFFFFFFFFFFF0)
'(and (mem16+ rax) #xFFF0)
'(and (mem32+ rax) #xFFFFFFF0)
'(and (mem64+ rax) #xFFFFFFFFFFFFFFF0))
(test64 '#vu8(#x24 #xF
#x66 #x25 #xFF #xF
#x25 #xFF #xFF #xFF #xF
#x48 #x25 #xFF #xFF #xFF #xFF
#x80 #x20 #xF
#x66 #x81 #x20 #xFF #xF
#x81 #x20 #xFF #xFF #xFF #xF
#x48 #x81 #x20 #xFF #xFF #xFF #xFF
#x66 #x83 #x20 #xF
#x83 #x20 #xF
#x48 #x83 #x20 #xF)
'(and al #xF)
'(and ax #xFFF)
'(and eax #xFFFFFFF)
'(and rax #xFFFFFFFFFFFFFFFF)
'(and (mem8+ rax) #xF)
'(and (mem16+ rax) #xFFF)
'(and (mem32+ rax) #xFFFFFFF)
'(and (mem64+ rax) #xFFFFFFFFFFFFFFFF)
'(and (mem16+ rax) #xF)
'(and (mem32+ rax) #xF)
'(and (mem64+ rax) #xF))
(test64 '#vu8(#x24 #xf0
#x66 #x83 #xe0 #xf0
#x83 #xe0 #xf0
#x48 #x83 #xe0 #xf0
#x80 #x20 #xf0
#x66 #x83 #x20 #xf0
#x83 #x20 #xf0
#x48 #x83 #x20 #xf0)
'(and al #xF0)
'(and ax #xFFF0)
'(and eax #xFFFFFFF0)
'(and rax #xFFFFFFFFFFFFFFF0)
'(and (mem8+ rax) #xF0)
'(and (mem16+ rax) #xFFF0)
'(and (mem32+ rax) #xFFFFFFF0)
'(and (mem64+ rax) #xFFFFFFFFFFFFFFF0))
;;; AVX
(test64 '#vu8(#xC4 #xE2 #x69 #x2C #x00
#xC4 #xE2 #x69 #x2E #x18
#xC4 #xE2 #x69 #x2D #x00
#xC4 #xE2 #x69 #x2F #x18
#xC4 #xE3 #x71 #x48 #xC2 #x31
#xC4 #xE3 #x71 #x49 #xC2 #x31
#xC4 #xE3 #xF1 #x48 #x00 #x21
#xC4 #xE3 #x71 #x49 #x00 #x31
#xC4 #xE3 #x71 #x4A #x00 #x30)
'(vmaskmovps xmm0 xmm2 (mem128+ rax))
'(vmaskmovps (mem128+ rax) xmm2 xmm3)
'(vmaskmovpd xmm0 xmm2 (mem128+ rax))
'(vmaskmovpd (mem128+ rax) xmm2 xmm3)
'(vpermiltd2ps xmm0 xmm1 xmm2 xmm3)
'(vpermiltd2pd xmm0 xmm1 xmm2 xmm3)
'(vpermiltd2ps xmm0 xmm1 xmm2 (mem128+ rax))
'(vpermiltd2pd xmm0 xmm1 (mem128+ rax) xmm3)
'(vblendvps xmm0 xmm1 (mem128+ rax) xmm3))
;;; All available JMPs
(test16 '#vu8(#xEB #x20
#xE9 #x1D #x00
#x66 #xE9 #x17 #x00 #x00 #x00
#xFF #x21
#x66 #xFF #x21
#xEA #x34 #x12 #x42 #x00
#x66 #xEA #x78 #x56 #x34 #x12 #x42 #x00
#xFF #x29
#x66 #xFF #x29)
'(jmp (+ ip #x20))
'(jmp (+ ip #x1D))
'(jmp (+ ip #x17))
'(jmp (mem16+ bx di))
'(jmp (mem32+ bx di))
'(jmpf (far #x42 #x1234))
'(jmpf (far #x42 #x12345678))
'(jmpf (mem16:16+ bx di))
'(jmpf (mem16:32+ bx di)))
(test32 '#vu8(#xEB #x24
#x66 #xE9 #x20 #x00
#xE9 #x1B #x00 #x00 #x00
#x67 #x66 #xFF #x21
#x67 #xFF #x21
#xEA #x34 #x12 #x00 #x00 #x42 #x00
#xEA #x78 #x56 #x34 #x12 #x42 #x00
#x67 #xFF #x29
#x67 #xFF #x29)
'(jmp (+ eip #x24))
'(jmp (+ eip #x20))
'(jmp (+ eip #x1B))
'(jmp (mem16+ bx di))
'(jmp (mem32+ bx di))
'(jmpf (far #x42 #x1234))
'(jmpf (far #x42 #x12345678))
'(jmpf (mem16:32+ bx di))
'(jmpf (mem16:32+ bx di)))
(test64 '#vu8(#xEB #x0E
#xE9 #x09 #x00 #x00 #x00
#xFF #x20
#xFF #x28
#xFF #x28
#x48 #xFF #x28 )
'(jmp (+ rip #xE))
'(jmp (+ rip #x9))
'(jmp (mem64+ rax))
'(jmpf (mem16:32+ rax))
'(jmpf (mem16:32+ rax))
'(jmpf (mem16:64+ rax)))
(test64 '#vu8(#xEB #x17
#xE9 #x12 #x00 #x00 #x00
#xFF #x20
#xFF #x28
#xFF #x28
#x48 #xFF #x28
#x0F #xB8 #xEA #xFF #xFF #xFF
#x0F #x00 #x30)
'(jmp (+ rip #x17))
'(jmp (+ rip #x12))
'(jmp (mem64+ rax))
'(jmpf (mem16:32+ rax))
'(jmpf (mem16:32+ rax))
'(jmpf (mem16:64+ rax))
'(jmpe (+ rip #x-16))
'(jmpe (mem32+ rax)))
;;; Various
(test64 '#vu8(#x66 #x0F #xBE #xD0
#x0F #xBE #xD0
#x48 #x0F #xBE #xD0
#x0F #xBF #xD0
#x48 #x0F #xBF #xD0
#x48 #x63 #xC0
#x66 #x0F #xB6 #xD0
#x0F #xB6 #xD0
#x48 #x0F #xB6 #xD0
#x0F #xB7 #xD0
#x48 #x0F #xB7 #xD0)
'(movsx dx al)
'(movsx edx al)
'(movsx rdx al)
'(movsx edx ax)
'(movsx rdx ax)
'(movsxd rax eax)
'(movzx dx al)
'(movzx edx al)
'(movzx rdx al)
'(movzx edx ax)
'(movzx rdx ax))
(test64 '#vu8(#x0F #x23 #xC0
#x44 #x0F #x23 #xF8
#x0F #x21 #xC0
#x41 #x0F #x21 #xDF)
'(mov dr0 rax)
'(mov dr15 rax)
'(mov rax dr0)
'(mov r15 dr3))
(test64 '#vu8(#xA1 #x30 #x30 #x30 #x30 #x30 #x30 #x30 #x30
#xA0 #x30 #x30 #x30 #x30 #x30 #x30 #x30 #x30
#x48 #xA1 #x30 #x30 #x30 #x30 #x30 #x30 #x30 #x30
#x8B #x04 #x25 #x30 #x30 #x30 #x30)
'(mov eax (mem32+ #x3030303030303030))
'(mov al (mem8+ #x3030303030303030))
'(mov rax (mem64+ #x3030303030303030))
'(mov eax (mem32+ #x30303030)))
(test64 '#vu8(#x66 #x0F #x00 #xC0
#x0F #x00 #xC0
#x48 #x0F #x00 #xC0
#x0F #x00 #x04 #x25 #x00 #x00 #x00 #x00)
'(sldt ax)
'(sldt eax)
'(sldt rax)
'(sldt (mem16+ 0)))
(test64 '#vu8(#x0F #x38 #x00 #xC7
#x0F #x0F #xDC #x9E
#x0F #x0F #xDC #xBB)
'(pshufb mm0 mm7)
'(pfadd mm3 mm4)
'(pswapd mm3 mm4))
(test64 '#vu8(#xC4 #xE3 #x69 #x49 #xC #x25 #x0 #x0 #x0 #x0 #x4E
#xC4 #xE3 #xE9 #x49 #xC #x25 #x0 #x0 #x0 #x0 #x3D
#xC4 #xE3 #x6D #x49 #xC #x25 #x0 #x0 #x0 #x0 #x4C
#xC4 #xE3 #xED #x49 #xC #x25 #x0 #x0 #x0 #x0 #x3B)
'(vpermil2pd xmm1 xmm2 (mem128+ 0) xmm4 14)
'(vpermil2pd xmm1 xmm2 xmm3 (mem128+ 0) 13)
'(vpermil2pd ymm1 ymm2 (mem256+ 0) ymm4 12)
'(vpermil2pd ymm1 ymm2 ymm3 (mem256+ 0) 11))
(test64 '#vu8(#x66 #xF #x55 #xC #x25 #x0 #x0 #x0 #x0
#xC5 #xE9 #x55 #xC #x25 #x0 #x0 #x0 #x0
#xC5 #xED #x55 #xC #x25 #x0 #x0 #x0 #x0
#xC4 #xE2 #x79 #x18 #xC #x25 #x0 #x0 #x0 #x0
#xC4 #xE2 #x7D #x18 #x38
#xC4 #x62 #x7D #x19 #x40 #x42
#xC4 #x42 #x7D #x1A #x3F)
'(andnpd xmm1 (mem128+ 0))
'(vandnpd xmm1 xmm2 (mem128+ 0))
'(vandnpd ymm1 ymm2 (mem256+ 0))
'(vbroadcastss xmm1 (mem32+ 0))
'(vbroadcastss ymm7 (mem32+ rax))
'(vbroadcastsd ymm8 (mem64+ rax #x42))
'(vbroadcastf128 ymm15 (mem128+ r15)))
(test64 '#vu8(#xC4 #xE3 #x6D #x18 #xCB #x42
#xC4 #xE3 #x6D #x18 #xC #x25 #x0 #x0 #x0 #x0 #x42)
'(vinsertf128 ymm1 ymm2 xmm3 #x42)
'(vinsertf128 ymm1 ymm2 (mem128+ 0) #x42))
(test64 '#vu8(#xC4 #xE3 #x61 #x69 #x4 #x25 #x0 #x0 #x0 #x0 #x10
#xC4 #xE3 #xE9 #x69 #x4 #x25 #x0 #x0 #x0 #x0 #x10)
'(vfmaddpd xmm0 xmm1 (mem128+ 0) xmm3)
'(vfmaddpd xmm0 xmm1 xmm2 (mem128+ 0)))
(test64 '#vu8(#x67 #x8B #x00
#x8B #x00
#x67 #x48 #x8B #x00
#x48 #x8B #x00
#x67 #x45 #x8B #x3F
#x45 #x8B #x3F
#x67 #x4D #x8B #x3F
#x4D #x8B #x3F
#x67 #x8B #x40 #x01
#x67 #x8B #x44 #xD8 #x1)
'(mov eax (mem32+ eax))
'(mov eax (mem32+ rax))
'(mov rax (mem64+ eax))
'(mov rax (mem64+ rax))
'(mov r15d (mem32+ r15d))
'(mov r15d (mem32+ r15))
'(mov r15 (mem64+ r15d))
'(mov r15 (mem64+ r15))
'(mov eax (mem32+ eax #x1))
'(mov eax (mem32+ eax #x1 (* ebx #x8))))
(test64 '#vu8(#xC5 #xFE #xE6 #xC1
#xC4 #xE2 #x01 #x2F #x00
#xC4 #x62 #x7D #x2F #x38)
'(vcvtdq2pd ymm0 xmm1)
'(vmaskmovpd (mem128+ rax) xmm15 xmm0)
'(vmaskmovpd (mem256+ rax) ymm0 ymm15))
(test64 '#vu8(#xF #x12 #x1
#xF #x12 #xC1
#xF #x16 #x1
#xF #x16 #xC1
#xF #x13 #x1
#xF #x17 #x1
#xC5 #xF0 #x12 #x1
#xC5 #xF0 #x12 #xC2
#xC5 #xF0 #x16 #x1
#xC5 #xF0 #x16 #xC2
#xC5 #xF8 #x13 #x1
#xC5 #xF8 #x17 #x1)
'(movlps xmm0 (mem64+ rcx))
'(movhlps xmm0 xmm1)
'(movhps xmm0 (mem64+ rcx))
'(movlhps xmm0 xmm1)
'(movlps (mem64+ rcx) xmm0)
'(movhps (mem64+ rcx) xmm0)
'(vmovlps xmm0 xmm1 (mem64+ rcx))
'(vmovhlps xmm0 xmm1 xmm2)
'(vmovhps xmm0 xmm1 (mem64+ rcx))
'(vmovlhps xmm0 xmm1 xmm2)
'(vmovlps (mem64+ rcx) xmm0)
'(vmovhps (mem64+ rcx) xmm0))
(test64 '#vu8(#x2E #x75 #xFD
#x3E #x75 #xFA)
'(jnz.spnt (+ rip #x-3))
'(jnz.sptk (+ rip #x-6)))
(test64 '#vu8(#xF0 #x4C #x0F #xB1 #x63 #x07)
'(lock.cmpxchg (mem64+ rbx #x7) r12))
(test64 '#vu8(#xF3 #x0F #xA7 #xD8
#xF3 #x48 #xAB
#xF3 #xA7
#xF2 #x48 #xAF)
'(rep.xcryptctr)
'(rep.stos (mem64+ rdi) rax)
'(repz.cmps (mem32+ rsi) (mem32+ rdi))
'(repnz.scas rax (mem64+ rdi)))
(test64 #vu8(#x0F #x8F #x00 #x00 #x00 #x00)
'(jnle (+ rip 0)))
(test64 #vu8(#x0f #x01 #xca) '(clac))
(test64 #vu8(#x0f #x01 #xcb) '(stac))
;;; Test the special handling of NOP/PAUSE
(test16 '#vu8(#x90
#x66 #x90
#x48
#x90
#xF3 #x90
#x87 #xC0)
'(nop)
'(xchg eax eax)
'(dec ax)
'(nop)
'(pause)
'(xchg ax ax))
(test32 '#vu8(#x90
#x66 #x90
#x48
#x90
#xF3 #x90
#x87 #xC0)
'(nop)
'(xchg ax ax)
'(dec eax)
'(nop)
'(pause)
'(xchg eax eax))
(test64 '#vu8(#x90
#x66 #x90
#x48 #x90
#xF3 #x90
#x87 #xC0
#x41 #x90
#x66 #x41 #x90)
'(nop)
'(xchg ax ax)
'(xchg rax rax)
'(pause)
'(xchg eax eax)
'(xchg r8d eax)
'(xchg r8w ax))
;;; MOVBE/CRC32 is special
(test64 #vu8(#xF2 #x0F #x38 #xF0 #xC0) '(crc32 eax al))
(test64 #vu8(#xF2 #x48 #x0F #x38 #xF0 #xC0) '(crc32 rax al))
(test64 #vu8(#x66 #xF2 #x0F #x38 #xF1 #xC0) '(crc32 eax ax))
(test64 #vu8(#xF2 #x0F #x38 #xF1 #xC0) '(crc32 eax eax))
(test64 #vu8(#xF2 #x48 #x0F #x38 #xF1 #xC0) '(crc32 rax rax))
(test64 #vu8(#x66 #x0F #x38 #xF1 #x00) '(movbe (mem16+ rax) ax))
(test64 #vu8(#x0F #x38 #xF1 #x00) '(movbe (mem32+ rax) eax))
(test64 #vu8(#x48 #x0F #x38 #xF1 #x00) '(movbe (mem64+ rax) rax))
(test64 #vu8(#x48 #x0F #x38 #xF0 #x00) '(movbe rax (mem64+ rax)))
(test64 #vu8(#x0F #x38 #xF0 #x00) '(movbe eax (mem32+ rax)))
(test64 #vu8(#x66 #x0F #x38 #xF0 #x00) '(movbe ax (mem16+ rax)))
(test32 #vu8(#xF2 #x0F #x38 #xF0 #xC0) '(crc32 eax al))
(test32 #vu8(#x66 #xF2 #x0F #x38 #xF1 #xC0) '(crc32 eax ax))
(test32 #vu8(#xF2 #x0F #x38 #xF1 #xC0) '(crc32 eax eax))
(test32 #vu8(#x66 #x0F #x38 #xF1 #x00) '(movbe (mem16+ eax) ax))
(test32 #vu8(#x0F #x38 #xF1 #x00) '(movbe (mem32+ eax) eax))
(test32 #vu8(#x0F #x38 #xF0 #x00) '(movbe eax (mem32+ eax)))
(test32 #vu8(#x66 #x0F #x38 #xF0 #x00) '(movbe ax (mem16+ eax)))
(test16 #vu8(#xF2 #x0F #x38 #xF0 #xC0) '(crc32 eax al))
(test16 #vu8(#xF2 #x0F #x38 #xF1 #xC0) '(crc32 eax ax))
(test16 #vu8(#x66 #xF2 #x0F #x38 #xF1 #xC0) '(crc32 eax eax))
(test16 #vu8(#x0F #x38 #xF1 #x04) '(movbe (mem16+ si) ax))
(test16 #vu8(#x66 #x0F #x38 #xF1 #x04) '(movbe (mem32+ si) eax))
(test16 #vu8(#x66 #x0F #x38 #xF0 #x04) '(movbe eax (mem32+ si)))
(test16 #vu8(#x0F #x38 #xF0 #x04) '(movbe ax (mem16+ si)))
;;; Instruction encodings that are too long
(define (test/error mode input)
(let ((read 0)
(port (open-bytevector-input-port input)))
(let ((status
(guard (exn
((invalid-opcode? exn)
(condition-message exn))
(else exn))
(get-instruction port
mode
(lambda (tag . bytes)
(set! read (+ read (length bytes))))
#f))))
(let* ((bv (get-bytevector-all port))
(unread (if (eof-object? bv) 0 (bytevector-length bv))))
(cond ((not (= (bytevector-length input) (+ read unread)))
(list 'imbalance read unread))
((> read 15)
(list 'read-too-much read))
(else status))))))
(check (test/error 64 #vu8(#x36 #x36 #x36 #x36 #x36 #x36 #x36 #xf0
#x36))
=> "End of file inside instruction")
;; This one is #xa2, and if there was enough data, it would be longer
;; than 15 bytes anyway.
(check (test/error 64 #vu8(#x36 #x36 #x36 #x36 #x36 #x36 #x36 #xf0
#x36 #xa2))
=> "End of file inside oversized instruction")
(check (test/error 64 #vu8(#x36 #x36 #x36 #x36 #x36 #x36 #x36 #xf0
#x36 #xa2 #xff))
=> "End of file inside oversized instruction")
(check (test/error 64 #vu8(#x36 #x36 #x36 #x36 #x36 #x36 #x36 #xf0
#x36 #xa2 #xff #xff))
=> "End of file inside oversized instruction")
(check (test/error 64 #vu8(#x36 #x36 #x36 #x36 #x36 #x36 #x36 #xf0
#x36 #xa2 #xff #xff #xff))
=> "End of file inside oversized instruction")
(check (test/error 64 #vu8(#x36 #x36 #x36 #x36 #x36 #x36 #x36 #xf0
#x36 #xa2 #xff #xff #xff #xff))
=> "End of file inside oversized instruction")
(check (test/error 64 #vu8(#x36 #x36 #x36 #x36 #x36 #x36 #x36 #xf0
#x36 #xa2 #xff #xff #xff #xff #xff))
=> "Instruction too long")
(check (test/error 64 (make-bytevector 16 #x36))
=> "Instruction too long")
(check (test/error 64 (make-bytevector 15 #x36))
=> "Instruction too long")
(check (test/error 64 (make-bytevector 14 #x36))
=> "End of file inside instruction")
;;; RIP-relative addressing
;; See what happens with RIP-relative addressing and address size
;; override.
(check (test/error 64 #vu8(#x48 #x8B #x05 #xF8 #xFF #xFF #xFF))
=> '(mov rax (mem64+ rip -8)))
(check (test/error 64 #vu8(#x67 #x48 #x8B #x05 #xF8 #xFF #xFF #xFF))
=> '(mov rax (mem64+ eip -8)))
(check (test/error 16 #vu8(#x67 #x66 #x89 #x2D #x1C #x90 #x00 #x00))
=> '(mov (mem32+ #x901C) ebp))
;;; XOP
(check (test/error 64 #vu8(#x0F #x8F #x38 #x00 #x00 #x00))
=> '(jnle (+ rip 56)))
(check (test/error 64 #vu8(#x8F #xEA #xF8 #x12 #xC0 #x00 #x00 #x00 #x00))
=> '(lwpins rax eax #x0))
(check (test/error 64 #vu8(#x8F #xE9 #x68 #x90 #xC1))
=> '(vprotb xmm0 xmm1 xmm2))
(check (test/error 64 #vu8(#xC4 #xA1 #x7A #x11 #x84 #x23 #xAC #x05 #x00 #x00))
=> '(vmovss (mem64+ rbx #x5AC (* r12 #x1)) xmm0))
;;; Intel MPX
(check (test/error 64 #vu8(#x0f #x1a #x11))
=> '(bndldx bnd2 (mem+ rcx)))
(check (test/error 64 #vu8(#xf3 #x0f #x1a #x11))
=> '(bndcl bnd2 (mem64+ rcx)))
(check (test/error 64 #vu8(#x66 #x0f #x1a #x11))
=> '(bndmov bnd2 (mem128+ rcx)))
(check (test/error 64 #vu8(#xf2 #x0f #x1a #x11))
=> '(bndcu bnd2 (mem64+ rcx)))
(check (test/error 64 #vu8(#x0f #x1b #x19))
=> '(bndstx (mem+ rcx) bnd3))
(check (test/error 64 #vu8(#xf3 #x0f #x1b #x19))
=> '(bndmk bnd3 (mem64+ rcx)))
(check (test/error 64 #vu8(#x66 #x0f #x1b #x19))
=> '(bndmov (mem128+ rcx) bnd3))
(check (test/error 64 #vu8(#xf2 #x0f #x1b #x19))
=> '(bndcn bnd3 (mem64+ rcx)))
(check (test/error 64 #vu8(#xf3 #x0f #x1b #xd0))
=> '(nop))
(check (test/error 64 #vu8(#x0f #x1b #xd0))
=> '(nop))
(check (test/error 64 #vu8(#x0f #x1a #xd0))
=> '(nop))
(check (test/error 64 #vu8(#x48 #x0f #x1a
#x05 #xF8 #xFF #xFF #xFF))
=> "RIP-relative addressing")
(check (test/error 64 #vu8(#xf3 #x48 #x0f #x1b
#x05 #xF8 #xFF #xFF #xFF))
=> "RIP-relative addressing")
(check (test/error 64 #vu8(#x4a #x0f #x1a
#x54 #xa3 #x42))
=> '(bndldx bnd2 (mem+ rbx #x42 (* r12 1)))) ;scale=4 is ignored
(check (test/error 32 #vu8(#xf3 #x0f #x1b #x19))
=> '(bndmk bnd3 (mem32+ ecx)))
(check (test/error 16 #vu8(#x67 #xf3 #x0f #x1b #x19))
=> '(bndmk bnd3 (mem32+ ecx)))
(check (test/error 16 #vu8(#x0f #x1a #x10))
=> "16-bit addressing with MPX instruction")
(test64 '#vu8(#xf2 #xc3
#xf2 #xc2 #x02 #x00
#xf2 #x75 #xFA)
'(bnd.ret)
'(bnd.ret 2)
'(bnd.jnz (+ rip #x-6)))
(check-report)
(exit (if (check-passed? 114) 0 1))
| true |
65757779c70c0870c3044b98e4953b949672920c | 58381f6c0b3def1720ca7a14a7c6f0f350f89537 | /Chapter 3/3.5/Ex3.61.scm | 99267487ae6797d00e6dc3c2d312f6dd42a79b0e | [] | no_license | yaowenqiang/SICPBook | ef559bcd07301b40d92d8ad698d60923b868f992 | c8a0228ebf66d9c1ddc5ef1fcc1d05d8684f090a | refs/heads/master | 2020-04-19T04:03:15.888492 | 2015-11-02T15:35:46 | 2015-11-02T15:35:46 | null | 0 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 372 | scm | Ex3.61.scm | #lang racket
(define (mul-series s1 s2)
(cons-stream
(* (stream-first s1) (stream-first s2))
(add-streams (scale-stream (stream-rest s2) (stream-first s1))
(mul-series (stream-rest s1) s2))))
(define (invert-unit-series S)
(cons-stream 1
(mul-series
(scale-stream S -1)
(invert-unit-series S)))) | false |
1da11fe8e301b8ea3aaa1e75144b994242334c80 | defeada37d39bca09ef76f66f38683754c0a6aa0 | /mscorlib/system/security/policy/strong-name-membership-condition.sls | f1ab5a27b35b54cf63c855726c6968bdf4c6089b | [] | no_license | futsuki/ironscheme-port | 2dbac82c0bda4f4ff509208f7f00a5211d1f7cd5 | 4e7a81b0fbeac9a47440464988e53fb118286c54 | refs/heads/master | 2016-09-06T17:13:11.462593 | 2015-09-26T18:20:40 | 2015-09-26T18:20:40 | 42,757,369 | 0 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 2,660 | sls | strong-name-membership-condition.sls | (library (system security policy strong-name-membership-condition)
(export new
is?
strong-name-membership-condition?
get-hash-code
from-xml
check?
to-string
to-xml
copy
equals?
name-get
name-set!
name-update!
version-get
version-set!
version-update!
public-key-get
public-key-set!
public-key-update!)
(import (ironscheme-clr-port))
(define-syntax new
(lambda (e)
(syntax-case e ()
((_ a ...)
#'(clr-new
System.Security.Policy.StrongNameMembershipCondition
a
...)))))
(define (is? a)
(clr-is System.Security.Policy.StrongNameMembershipCondition a))
(define (strong-name-membership-condition? a)
(clr-is System.Security.Policy.StrongNameMembershipCondition a))
(define-method-port
get-hash-code
System.Security.Policy.StrongNameMembershipCondition
GetHashCode
(System.Int32))
(define-method-port
from-xml
System.Security.Policy.StrongNameMembershipCondition
FromXml
(System.Void
System.Security.SecurityElement
System.Security.Policy.PolicyLevel)
(System.Void System.Security.SecurityElement))
(define-method-port
check?
System.Security.Policy.StrongNameMembershipCondition
Check
(System.Boolean System.Security.Policy.Evidence))
(define-method-port
to-string
System.Security.Policy.StrongNameMembershipCondition
ToString
(System.String))
(define-method-port
to-xml
System.Security.Policy.StrongNameMembershipCondition
ToXml
(System.Security.SecurityElement System.Security.Policy.PolicyLevel)
(System.Security.SecurityElement))
(define-method-port
copy
System.Security.Policy.StrongNameMembershipCondition
Copy
(System.Security.Policy.IMembershipCondition))
(define-method-port
equals?
System.Security.Policy.StrongNameMembershipCondition
Equals
(System.Boolean System.Object))
(define-field-port
name-get
name-set!
name-update!
(property:)
System.Security.Policy.StrongNameMembershipCondition
Name
System.String)
(define-field-port
version-get
version-set!
version-update!
(property:)
System.Security.Policy.StrongNameMembershipCondition
Version
System.Version)
(define-field-port
public-key-get
public-key-set!
public-key-update!
(property:)
System.Security.Policy.StrongNameMembershipCondition
PublicKey
System.Security.Permissions.StrongNamePublicKeyBlob))
| true |
610fa8e2ce376e6657245dbfa4a87984818b4736 | e1ae4c8eba1c87b4224192dff6bfd9fad78c9fe5 | /live/check/check.scm | 276cbe3e300188654e9a304af4157e0c680e2047 | [] | no_license | hermetique/live | 1336106317d31fca04257fc1af661895451663eb | 2b1d808897def08ecbc028420ad8da2d28e668df | refs/heads/master | 2023-04-20T04:40:03.848247 | 2021-05-16T09:43:19 | 2021-05-16T09:43:19 | null | 0 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 377 | scm | check.scm | (library (live check check)
(export test-0
test-1
test-2
test-3
)
(import (chezscheme) (live check))
(define test-0
(check #t #t))
(define test-1
(check boolean=? #t #t))
(define test-2
(check-raise symbol? (raise 'oops)))
(define test-3
(check-values (values 0 1 2) (apply values (list 0 1 2))))
)
| false |
4e8a31a153ff3d98ad4fe14def8c8bb0b7b09527 | 7c7e1a9237182a1c45aa8729df1ec04abb9373f0 | /lib/heist/builtin/lib/vector.scm | f273ddea50d6ac56967e32fdfdca49ed95879f3f | [
"MIT"
] | permissive | coolsun/heist | ef12a65beb553cfd61d93a6691386f6850c9d065 | 3f372b2463407505dad7359c1e84bf4f32de3142 | refs/heads/master | 2020-04-21T15:17:08.505754 | 2012-06-29T07:18:49 | 2012-06-29T07:18:49 | null | 0 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 874 | scm | vector.scm | ; (vector object ...)
; Returns a newly allocated vector from its arguments
(define (vector . args) (list->vector args))
; (list->vector list)
; Returns a newly allocated vector from a list
(define (list->vector list)
(let* ((size (length list))
(new-vector (make-vector size)))
(do ((i 0 (+ i 1))
(pair list (cdr pair)))
((= i size) new-vector)
(vector-set! new-vector i (car pair)))))
; (vector->list vector)
; Returns a newly allocated proper list from a vector
(define (vector->list vector)
(do ((i (vector-length vector) (- i 1))
(pair '() (cons (vector-ref vector (- i 1)) pair)))
((zero? i) pair)))
; (vector-fill! vector fill)
; Sets every element of vector to fill
(define (vector-fill! vector fill)
(do ((i (vector-length vector) (- i 1)))
((zero? i) vector)
(vector-set! vector (- i 1) fill)))
| false |
3b46650a7c010551686cf5cfb1231304de304ef7 | 02dc91f3985e81cc9c17ae31bd09dacb7fd7c1d0 | /src/prototype1/matrices.scm | 6dcf760fc38250403f9480f083a0633d0b0d56c2 | [] | no_license | edechter/probprog | 1db3c49b545c032ec2a507179169ba35b6eb36d1 | 702f00022fcb73dcb80863b0a3cd66b59428e387 | refs/heads/master | 2021-01-10T21:19:48.446719 | 2013-05-20T18:07:58 | 2013-05-20T18:07:58 | 9,099,925 | 1 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 6,324 | scm | matrices.scm | (declare (usual-integrations))
(load "util")
(define matrix-type-tag '*matrix*)
(define (tag-matrix nrows ncols flovec)
(list matrix-type-tag (cons nrows ncols) flovec))
(define (m:num-rows matrix)
(caadr matrix))
(define (m:num-cols matrix)
(cdadr matrix))
(define (matrix->flovec matrix)
(caddr matrix))
; the next three functions set row-major order
(define (flatidx->rowidx flatidx nrows ncols)
(fix:quotient flatidx ncols))
(define (flatidx->colidx flatidx nrows ncols)
(fix:remainder flatidx ncols))
(define (rowcolidx->flatidx i j m)
(fix:+ (fix:* i (m:num-cols m)) j))
(define (matrix-ref m i j)
(flo:vector-ref (matrix->flovec m) (rowcolidx->flatidx i j m)))
(define (matrix-set! m i j v)
(flo:vector-set! (matrix->flovec m) (rowcolidx->flatidx i j m) v))
(define (m:generate nrows ncols proc)
(tag-matrix nrows ncols (flo:make-initialized-vector
(fix:* nrows ncols)
(lambda (flatidx)
(proc (flatidx->rowidx flatidx nrows ncols)
(flatidx->colidx flatidx nrows ncols))))))
(define (m:zeros nrows ncols)
(m:generate nrows ncols (lambda (i j) 0.)))
(define (m:ones nrows ncols)
(m:generate nrows ncols (lambda (i j) 1.)))
(define (m:eye n)
(m:generate n n (lambda (i j)
(if (fix:= i j)
1.
0.))))
(define (m:empty nrows ncols)
(tag-matrix nrows ncols (flo:vector-cons (fix:* nrows ncols))))
(define (matrix-by-rows . rows)
(matrix-by-row-list rows))
(define (matrix-by-row-list rows)
(let ((nrows (length rows)))
(let ((ncols (length (car rows))))
(m:generate nrows ncols
(lambda (i j)
(exact->inexact (list-ref (list-ref rows i) j)))))))
(define (matrix-by-cols . cols)
(matrix-by-col-list cols))
(define (matrix-by-col-list cols)
(let ((ncols (length cols)))
(let ((nrows (length (car cols))))
(m:generate nrows ncols
(lambda (i j)
(exact->inexact (list-ref (list-ref cols j) i)))))))
(define (col-matrix . args)
(m:generate (length args) 1 (lambda (i j)
(exact->inexact (list-ref args i)))))
(define (row-matrix . args)
(m:generate 1 (length args) (lambda (i j)
(exact->inexact (list-ref args j)))))
(define (diag . args)
(m:generate (length args) (length args)
(lambda (i j)
(if (fix:= i j)
(exact->inexact (list-ref args i))
0.))))
(define (m:transpose m)
(m:generate (m:num-cols m) (m:num-rows m)
(lambda (i j) (matrix-ref m j i))))
(define (matrix*matrix matrix1 matrix2)
(let ((m1r (m:num-rows matrix1))
(m1c (m:num-cols matrix1))
(m2c (m:num-cols matrix2)))
(let ((m1cm1 (fix:- m1c 1)))
(m:generate m1r m2c
(lambda (i j)
(flo:sigma
(lambda (k)
(flo:* (matrix-ref matrix1 i k)
(matrix-ref matrix2 k j)))
0
m1cm1))))))
(define (matrix-binary-componentwise binop matrix1 matrix2)
(let ((nrows (m:num-rows matrix1))
(ncols (m:num-cols matrix1)))
(m:generate nrows ncols
(lambda (i j)
(binop (matrix-ref matrix1 i j)
(matrix-ref matrix2 i j))))))
(define (matrix+matrix matrix1 matrix2)
(matrix-binary-componentwise flo:+ matrix1 matrix2))
(define (matrix-matrix matrix1 matrix2)
(matrix-binary-componentwise flo:- matrix1 matrix2))
(define (solve-psd m b)
(let ((chol (cholesky m)))
(solve-upper-trinagular (m:transpose chol)
(solve-lower-triangular chol b))))
(define (solve-lower-triangular L b)
(let ((nrows (m:num-rows b))
(ncols (m:num-cols b)))
(let ((result (m:empty nrows ncols)))
(let outerloop ((k 0)) ;; across columns of b
(if (fix:< k ncols)
(let lp1 ((i 0))
(if (fix:< i nrows)
(let ((thesum (flo:sigma (lambda (j) (flo:* (matrix-ref L i j)
(matrix-ref result j k)))
0 (fix:- i 1)))
(bi (matrix-ref b i k))
(lii (matrix-ref L i i)))
(matrix-set! result i k (flo:/ (flo:- bi thesum) lii))
(lp1 (fix:+ i 1))))
(outerloop (fix:+ k 1)))))
result)))
(define (solve-upper-triangular LT b)
(let ((nrows (m:num-rows b))
(ncols (m:num-cols b)))
(let ((result (m:empty nrows ncols)))
(let outerloop ((k 0)) ;; across columns of b
(if (fix:< k ncols)
(let lp1 ((i (fix:- nrows 1)))
(let ((thesum (flo:sigma (lambda (j) (flo:* (matrix-ref LT i j)
(matrix-ref result j k)))
(fix:+ i 1) (fix:- nrows 1)))
(bi (matrix-ref b i k))
(lii (matrix-ref LT i i)))
(matrix-set! result i k (flo:/ (flo:- bi thesum) lii))
(if (fix:> i 0) (lp1 (fix:- i 1)))))
(outerloop (fix:+ k 1))))
result)))
(define (cholesky A)
(let* ((n (m:num-rows A))
(L (m:empty n n)))
(let ilp ((i 0))
(if (fix:< i n)
(begin
(let ((thesum (flo:sigma (lambda (k) (flo:* (matrix-ref L i k)
(matrix-ref L i k)))
0 (fix:- i 1)))
(Aii (matrix-ref A i i)))
(matrix-set! L i i (flo:sqrt (flo:- Aii thesum))))
(let jlp ((j (fix:+ i 1)))
(if (fix:< j n)
(let ((thesum (flo:sigma (lambda (k) (flo:* (matrix-ref L i k)
(matrix-ref L j k)))
0 (fix:- i 1)))
(Aij (matrix-ref A i j))
(Lii (matrix-ref L i i)))
(matrix-set! L j i (flo:/ (flo:- Aij thesum) Lii))
(jlp (fix:+ j 1)))))
(ilp (fix:+ i 1)))))
L))
| false |
7ecce77c5f4efac3747658445e327f9b9bb3e19f | 99ea786a1d4553b7ee264843877aaee11eb37115 | /5-1/3.22.scm | f46b6ad6f5e13d7ce8513231a1d3558f1fbbf9ab | [] | no_license | tyage/pl | ef4f62d729aed1222367dcae0f9a547e5d528b06 | c707b9f5055c12f6aadda60fe89f9c3423e820b6 | refs/heads/master | 2016-09-06T05:24:56.565550 | 2013-07-23T22:25:19 | 2013-07-23T22:25:19 | null | 0 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 1,215 | scm | 3.22.scm | (define make-queue (lambda ()
(let ((front-ptr '())
(rear-ptr '()))
(define set-front-ptr! (lambda (item) (set! front-ptr item)))
(define set-rear-ptr! (lambda (item) (set! rear-ptr item)))
(define empty-queue? (lambda () (null? front-ptr)))
(define front-queue (lambda ()
(if (empty-queue?)
(error "FRONT called with an empty queue")
(car front-ptr)) ))
(define rear-queue (lambda ()
(if (empty-queue?)
(error "REAR called to on empty queue")
(car rear-ptr)) ))
(define insert-queue! (lambda (item)
(let ((new-pair (cons item '())))
(cond ((empty-queue?)
(set-front-ptr! new-pair)
(set-rear-ptr! new-pair)
front-ptr)
(else
(set-cdr! rear-ptr new-pair)
(set-rear-ptr! new-pair)
front-ptr) ) ) ))
(define delete-queue! (lambda ()
(cond ((empty-queue?)
(error "DELETE! called with an empty queue"))
(else
(set-front-ptr! (cdr front-ptr)) ) ) ))
(define dispatch (lambda (m)
(cond ((eq? m 'empty-queue?) empty-queue?)
((eq? m 'front-queue) front-queue)
((eq? m 'rear-queue) rear-queue)
((eq? m 'insert-queue!) insert-queue!)
((eq? m 'delete-queue!) delete-queue!)
(else (error "Unknown request -- MAKE-QUEUE")) ) ))
dispatch) )) | false |
5ffa33ee66d032f0c5cd20d7812852add80e4277 | 382770f6aec95f307497cc958d4a5f24439988e6 | /projecteuler/060/060.scm | ba16c2c4fadb3cad18d1c013f3c366224e42d2d4 | [
"Unlicense"
] | permissive | include-yy/awesome-scheme | 602a16bed2a1c94acbd4ade90729aecb04a8b656 | ebdf3786e54c5654166f841ba0248b3bc72a7c80 | refs/heads/master | 2023-07-12T19:04:48.879227 | 2021-08-24T04:31:46 | 2021-08-24T04:31:46 | 227,835,211 | 1 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 4,199 | scm | 060.scm | (define prime?
(lambda (n)
(cond
((<= n 0) #f)
((= n 1) #f)
((< n 4) #t)
((= (remainder n 2) 0) #f)
((< n 9) #t)
((= (remainder n 3) 0) #f)
(else
(let ([r (inexact->exact (floor (sqrt n)))])
(let f ([i 5])
(cond
((> i r) #t)
((= (remainder n i) 0) #f)
((= (remainder n (+ i 2)) 0) #f)
(else
(f (+ i 6))))))))))
(define eular-filter
(lambda (n)
(let-syntax ([v-ref (syntax-rules ()
[(_ vec i)
(vector-ref vec (- i 1))])]
[v-set! (syntax-rules ()
[(_ vec i j)
(vector-set! vec (- i 1) j)])])
(let ([vec (make-vector n 1)]
[half (quotient n 2)]
[prime-ls (list 2)])
(letrec ([add-tail! (let ([ptr prime-ls])
(lambda (new)
(set-cdr! ptr (list new))
(set! ptr (cdr ptr))))])
(v-set! vec 1 0)
(v-set! vec 4 0)
(let f ([i 3])
(cond
[(> i half) (let f ([j i])
(cond
[(> j n) (list->vector prime-ls)]
[(not (zero? (v-ref vec j)))
(add-tail! j)
(f (+ j 2))]
[else (f (+ j 2))]))]
[else
(let g ([ls prime-ls])
(cond
[(null? ls)
(when (not (zero? (v-ref vec i)))
(add-tail! i)
(if (<= (* i i) n) (v-set! vec (* i i) 0)))
(f (+ i 1))]
[else
(let ([now (car ls)])
(cond
[(> (* now i) n)
(if (not (zero? (v-ref vec i))) (add-tail! i))
(f (+ i 1))]
[(zero? (remainder i now))
(v-set! vec (* i now) 0)
(if (not (zero? (v-ref vec i))) (add-tail! i))
(f (+ i 1))]
[else
(v-set! vec (* now i) 0)
(g (cdr ls))]))]))])))))))
(begin
(define range 10000000)
(define sievebound (quotient (- range 1) 2))
(define crosslimit (quotient (- (exact (floor (sqrt range))) 1) 2))
(define prime (make-bytevector sievebound 1))
(define prime-ref
(lambda (pme i)
(bytevector-u8-ref pme (- i 1))))
(define prime-set!
(lambda (pme i arg)
(bytevector-u8-set! pme (- i 1) arg)))
(let filt ([i 1])
(cond
((> i sievebound))
((= (prime-ref prime i) 1)
(let f ([j (* 2 i (+ i 1))])
(cond
((> j sievebound) (filt (+ i 1)))
(else
(prime-set! prime j 0)
(f (+ j (+ (* i 2) 1)))))))
(else
(filt (+ i 1)))))
(define prime-r?
(lambda (n)
(cond
((<= n 0) #f)
((= n 1) #f)
((= n 2) #t)
((= (remainder n 2) 0) #f)
((= (prime-ref prime (/ (- n 1) 2)) 1) #t)
(else #f))))
)
(define prime-n?
(lambda (n)
(if (>= n 1000000000)
(prime? n)
(prime-r? n))))
(define prime-vec (eular-filter 100000))
(define prime-len (vector-length prime-vec))
(define isok
(lambda (a b)
(let ([str1 (number->string a)]
[str2 (number->string b)])
(if (prime? (string->number (string-append str1 str2)))
(prime? (string->number (string-append str2 str1)))
#f))))
(let f1 ([i1 1])
(cond
((= i1 1228) #f)
(else
(let ([one (vector-ref prime-vec i1)])
(let f2 ([i2 (+ i1 1)])
(let ([two (vector-ref prime-vec i2)])
(cond
((= i2 1229) (f1 (+ i1 1)))
((not (isok one two))
(f2 (+ i2 1)))
(else
(let f3 ([i3 (+ i2 1)])
(let ([three (vector-ref prime-vec i3)])
(cond
((= i3 1230) (f2 (+ i2 1)))
((or (not (isok one three))
(not (isok two three)))
(f3 (+ i3 1)))
(else
(let f4 ([i4 (+ i3 1)])
(let ([four (vector-ref prime-vec i4)])
(cond
((= i4 1231) (f3 (+ i3 1)))
((or (not (isok one four))
(not (isok two four))
(not (isok three four)))
(f4 (+ i4 1)))
(else
(let f5 ([i5 (+ i4 1)])
(let ([five (vector-ref prime-vec i5)])
(cond
((= i5 1232) (f4 (+ i4 1)))
((or (not (isok one five))
(not (isok two five))
(not (isok three five))
(not (isok four five)))
(f5 (+ i5 1)))
(else
(list one two three four five)))))))))))))))))))))
#|
(time (let f1 ...))
193 collections
1.156250000s elapsed cpu time, including 0.000000000s collecting
1.160015600s elapsed real time, including 0.008579800s collecting
812902880 bytes allocated, including 812787016 bytes reclaimed
(13 5197 5701 6733 8389)
|#
| false |
668e4d8b04f6077bd0c6f66b40e8d5295a13ebb6 | d074b9a2169d667227f0642c76d332c6d517f1ba | /sicp/ch_3/exercise.3.78.scm | bb88a65f32191a237b77c56ee8463ab8d8ab0922 | [] | no_license | zenspider/schemers | 4d0390553dda5f46bd486d146ad5eac0ba74cbb4 | 2939ca553ac79013a4c3aaaec812c1bad3933b16 | refs/heads/master | 2020-12-02T18:27:37.261206 | 2019-07-14T15:27:42 | 2019-07-14T15:27:42 | 26,163,837 | 7 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 766 | scm | exercise.3.78.scm | #lang racket/base
;;; Exercise 3.78
;; Consider the problem of designing a
;; signal-processing system to study the homogeneous second-order
;; linear differential equation
;;
;; d^2 y d y
;; ----- - a ----- - by = 0
;; d t^2 d t
;;
;; The output stream, modeling y, is generated by a network that
;; contains a loop. This is because the value of d^2y/dt^2 depends
;; upon the values of y and dy/dt and both of these are determined by
;; integrating d^2y/dt^2. The diagram we would like to encode is
;; shown in *Note Figure 3-35::. Write a procedure `solve-2nd' that
;; takes as arguments the constants a, b, and dt and the initial
;; values y_0 and dy_0 for y and dy/dt and generates the stream of
;; successive values of y.
| false |
bfa6b42226df99a962b8ae4fca5ef1028d8954c0 | ac2a3544b88444eabf12b68a9bce08941cd62581 | /tests/unit-tests/01-fixnum/fxfirst_bit_set.scm | 9f44ab02d1b31142ab61f42a697b111e3b6c1a52 | [
"Apache-2.0",
"LGPL-2.1-only"
] | permissive | tomelam/gambit | 2fd664cf6ea68859d4549fdda62d31a25b2d6c6f | d60fdeb136b2ed89b75da5bfa8011aa334b29020 | refs/heads/master | 2020-11-27T06:39:26.718179 | 2019-12-15T16:56:31 | 2019-12-15T16:56:31 | 229,341,552 | 1 | 0 | Apache-2.0 | 2019-12-20T21:52:26 | 2019-12-20T21:52:26 | null | UTF-8 | Scheme | false | false | 623 | scm | fxfirst_bit_set.scm | (include "#.scm")
(check-eqv? (##fxfirst-bit-set 1) 0)
(check-eqv? (##fxfirst-bit-set 100) 2)
(check-eqv? (##fxfirst-bit-set -1000) 3)
(check-eqv? (fxfirst-bit-set 1) 0)
(check-eqv? (fxfirst-bit-set 100) 2)
(check-eqv? (fxfirst-bit-set -1000) 3)
(check-tail-exn type-exception? (lambda () (fxfirst-bit-set 0.0)))
(check-tail-exn type-exception? (lambda () (fxfirst-bit-set 0.5)))
(check-tail-exn type-exception? (lambda () (fxfirst-bit-set 1/2)))
(check-tail-exn wrong-number-of-arguments-exception? (lambda () (fxfirst-bit-set)))
(check-tail-exn wrong-number-of-arguments-exception? (lambda () (fxfirst-bit-set 1 1)))
| false |
a583a975a3133bd1a4683475c4eaff0fde67d6f3 | c219749b5f9b92ef47d79aef75c73c376057b2a9 | /modules/freenect/freenect.ss | c8633dec29d35e8338473fcff8404bcba0b52507 | [] | no_license | roguegun/gabor-fluxus | 5802f1b16a29582766f3ab244d65a2bb1fab2e23 | c3d11e79808b479125f42d7d87c2c8820e843345 | refs/heads/master | 2021-01-10T04:23:29.110010 | 2013-04-24T21:48:28 | 2013-04-24T21:48:28 | 45,170,113 | 0 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 623 | ss | freenect.ss | #lang racket/base
(require fluxus-018/fluxus-freenect)
(provide
(except-out (all-from-out fluxus-018/fluxus-freenect)
freenect-grab-device
freenect-ungrab-device)
with-freenect-device)
;; StartFunctionDoc-en
;; with-freenect-device freenect-deviceid expression ...
;; Returns: result of last expression
;; Description:
;; Allows you to work with the specified freenect devices.
;; Example:
;; EndFunctionDoc
(define-syntax with-freenect-device
(syntax-rules ()
((_ a b ...)
(begin
(freenect-grab-device a)
(let ((r (begin b ...)))
(freenect-ungrab-device)
r)))))
| true |
1d87cd134deca3e8f6e3ce204b5d88f6d790736e | a23f41d6de12a268b129a6b5c2e932325fe674f6 | /src/swish/app-core.ss | 46ebce9b7890683e40f4d0aef77ba1ad26e444fa | [
"MIT",
"LicenseRef-scancode-public-domain"
] | permissive | becls/swish | 89ee48b783b6b67b7077e09a78b3005fb44a8c54 | 3165b6a40c33774b263941314a7975b08dddf0e2 | refs/heads/dev | 2022-11-05T01:55:29.530457 | 2022-10-14T20:49:18 | 2022-10-14T20:55:37 | 113,237,913 | 134 | 27 | MIT | 2022-10-17T13:04:13 | 2017-12-05T22:04:27 | Scheme | UTF-8 | Scheme | false | false | 8,214 | ss | app-core.ss | ;;; Copyright 2019 Beckman Coulter, Inc.
;;;
;;; Permission is hereby granted, free of charge, to any person
;;; obtaining a copy of this software and associated documentation
;;; files (the "Software"), to deal in the Software without
;;; restriction, including without limitation the rights to use, copy,
;;; modify, merge, publish, distribute, sublicense, and/or sell copies
;;; of the Software, and to permit persons to whom the Software is
;;; furnished to do so, subject to the following conditions:
;;;
;;; The above copyright notice and this permission notice shall be
;;; included in all copies or substantial portions of the Software.
;;;
;;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
;;; EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
;;; MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
;;; NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
;;; HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
;;; WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
;;; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
;;; DEALINGS IN THE SOFTWARE.
#!chezscheme
(library (swish app-core)
(export
$exit-process
$swish-start
app-exception-handler
app:name
app:path
application:shutdown
repl-level
)
(import
(chezscheme)
(swish erlang)
(swish errors)
(swish io)
(swish meta)
(swish osi))
(define application-exit-code 2)
(define app-identity #f)
(define pid1 #f)
;; intended to return short descriptive name of the application if known
(define app:name
(make-inherited-parameter #f
(lambda (x)
(unless (or (not x) (string? x))
(bad-arg 'app:name x))
(when (eq? self pid1) (set! app-identity x))
(and x (path-root (path-last x))))))
;; intended to return full path to the application script or executable, if known
(define app:path
(make-inherited-parameter #f
(lambda (x)
(unless (or (not x) (string? x))
(bad-arg 'app:path x))
(and x (get-real-path x)))))
(define repl-level
(make-process-parameter 0
(lambda (n)
(arg-check 'repl-level [n fixnum? nonnegative?])
n)))
(define (strip-prefix string prefix)
(define slen (string-length string))
(define plen (string-length prefix))
(and (> slen plen)
(string=? (substring string 0 plen) prefix)
(substring string plen slen)))
(define (claim-exception who c)
(define stderr (console-error-port))
(define os (open-output-string))
(when who (fprintf stderr "~a: " who))
(guard (_ [else (get-output-string os) (display-condition c os)])
(parameterize ([print-level 3] [print-length 6])
(cond
[(match c [`(catch ,_) #t] [,c (not (condition? c))])
(let ([text (exit-reason->english c)])
(unless who (display "Exception: " os))
(display text os))]
[(not who) (display (exit-reason->english c) os)]
[else
(display-condition (condition (make-who-condition #f) c) os)
(let ([text (get-output-string os)])
(display (or (strip-prefix text "Warning: ")
(strip-prefix text "Exception: ")
text)
os))])))
;; add final "." since display-condition does not and exit-reason->english may or may not
(let ([i (- (port-output-index os) 1)])
(when (and (> i 0) (not (char=? #\. (string-ref (port-output-buffer os) i))))
(display "." os)))
(display (get-output-string os) stderr)
(fresh-line stderr)
(unless (and (warning? c) (not (serious-condition? c)))
(when (and (> (repl-level) 0)
(interactive?)
(continuation-condition? (debug-condition)))
(display "Type (debug) to enter the debugger.\n" stderr))
(reset)))
(define (app-exception-handler c)
(debug-condition c)
(claim-exception (app:name)
(match c
[`(catch ,r) (if (condition? r) r c)]
[,_ c])))
(define (int32? x) (and (or (fixnum? x) (bignum? x)) (<= #x-7FFFFFFF x #x7FFFFFFF)))
(define (->exit-status exit-code)
(cond
[(int32? exit-code) exit-code]
[(eq? exit-code (void)) 0]
[else
(console-event-handler (format "application shutdown due to (exit ~s)" exit-code))
1]))
(profile-omit ;; profiler won't have a chance to save data for these due to osi_exit
(define (exit-process exit-code)
(trap-signals #f)
(catch (flush-output-port (console-output-port)))
(catch (flush-output-port (console-error-port)))
(let ([p (#%$top-level-value '$console-input-port)])
;; convince Chez Scheme to close console-input port
(#%$set-top-level-value! '$console-input-port #f)
(when (input-port? p)
(close-port p)))
(osi_exit (->exit-status exit-code)))
(define ($exit-process)
(exit-process application-exit-code)))
(define application:shutdown
(case-lambda
[() (application:shutdown 0)]
[(exit-code . _)
(cond
[(whereis 'application) =>
(lambda (p)
(set! application-exit-code exit-code)
(kill p 'shutdown))]
[else (exit-process exit-code)])]))
(define (quit)
;; Spawn a process to avoid deadlock when application:shutdown
;; calls exit-process.
(spawn application:shutdown))
(define (handle-signal signo)
(match signo
[,@SIGHUP
;; LSB 3.1.1: return 3 for unimplemented feature, e.g., SIGHUP to reload
(spawn (lambda () (application:shutdown 3)))]
[,_ (quit)]))
(define (trap-signals handler)
(meta-cond
[(memq (machine-type) '(i3nt ti3nt a6nt ta6nt))
(signal-handler SIGBREAK handler)
(signal-handler SIGHUP handler)
(signal-handler SIGINT handler)]
[else
(signal-handler SIGHUP handler)
(signal-handler SIGINT handler)
(signal-handler SIGTERM handler)]))
(define started? #f)
(define Charon #f)
(define ($swish-start stand-alone? args run)
(let ([who (osi_get_executable_path)])
(parameterize ([command-line (cons who args)]
[command-line-arguments args])
(cond
[started? (run)]
[else
(set! pid1 self)
(set! started? #t)
(base-exception-handler app-exception-handler)
(random-seed (+ (remainder (erlang:now) (- (ash 1 32) 1)) 1))
(hook-console-input)
(call/cc
(lambda (bail)
(exit-handler
(lambda args
(apply application:shutdown args)
(bail)))
(reset-handler
(lambda ()
(application:shutdown application-exit-code)
(bail)))
(when stand-alone?
(app:name who)
(app:path who))
(trap-signals handle-signal)
(set! Charon
(spawn
(let ([me self])
(lambda ()
(let ([m (monitor me)])
(receive
[`(DOWN ,@m ,_ normal) 'ok]
[`(DOWN ,@m ,_ ,reason ,e)
(app:name app-identity)
(on-exit (application:shutdown application-exit-code)
(app-exception-handler e))]))))))
(call-with-values run exit)))
(receive)]))))
;; External entry points are run from the event-loop process
(set-top-level-value! '$shutdown quit)
(set-top-level-value! '$suspend void)
(set-top-level-value! '$resume void)
)
#!eof mats
(load-this-exposing '(->exit-status))
(import
(swish app-core)
(swish mat)
(swish profile)
(swish testing)
)
(mat coverage ()
(match-let*
([27 (->exit-status 27)]
[#x7ffffff (->exit-status #x7ffffff)]
[0 (->exit-status (void))]
[,os (open-output-string)]
[1 (parameterize ([console-error-port os]) (->exit-status 'other))]
[,stderr (get-output-string os)])
(match-regexps '(seek "Event: \"application shutdown due to \\(exit other\\)\"")
(split stderr #\newline)))
)
| false |
be8f3140189c604ae9da427a203d6d07ccad91d7 | defeada37d39bca09ef76f66f38683754c0a6aa0 | /System.Data/mono/data/sql-expressions/bool-operation.sls | 6be83086b4a71af4d2dc7814891e7b60581a18b1 | [] | no_license | futsuki/ironscheme-port | 2dbac82c0bda4f4ff509208f7f00a5211d1f7cd5 | 4e7a81b0fbeac9a47440464988e53fb118286c54 | refs/heads/master | 2016-09-06T17:13:11.462593 | 2015-09-26T18:20:40 | 2015-09-26T18:20:40 | 42,757,369 | 0 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 709 | sls | bool-operation.sls | (library (mono data sql-expressions bool-operation)
(export new is? bool-operation? eval-boolean? eval)
(import (ironscheme-clr-port))
(define-syntax new
(lambda (e)
(syntax-case e ()
((_ a ...)
#'(clr-new Mono.Data.SqlExpressions.BoolOperation a ...)))))
(define (is? a) (clr-is Mono.Data.SqlExpressions.BoolOperation a))
(define (bool-operation? a)
(clr-is Mono.Data.SqlExpressions.BoolOperation a))
(define-method-port
eval-boolean?
Mono.Data.SqlExpressions.BoolOperation
EvalBoolean
(System.Boolean System.Data.DataRow))
(define-method-port
eval
Mono.Data.SqlExpressions.BoolOperation
Eval
(System.Object System.Data.DataRow)))
| true |
8ace569ef816684b37e12d32ce72082c340707f8 | eef5f68873f7d5658c7c500846ce7752a6f45f69 | /spheres/dataformat/tar.scm | a6e832c319fbd1d4966613d2b39baefc466ff5c4 | [
"MIT"
] | permissive | alvatar/spheres | c0601a157ddce270c06b7b58473b20b7417a08d9 | 568836f234a469ef70c69f4a2d9b56d41c3fc5bd | refs/heads/master | 2021-06-01T15:59:32.277602 | 2021-03-18T21:21:43 | 2021-03-18T21:21:43 | 25,094,121 | 13 | 3 | null | null | null | null | UTF-8 | Scheme | false | false | 21,903 | scm | tar.scm | ;;;============================================================================
;;; File: "tar.scm"
;;; Copyright (c) 2006-2014 by Marc Feeley, All Rights Reserved.
;;;============================================================================
;;; Contains procedures to pack and unpack tar files.
(declare
(standard-bindings)
(extended-bindings)
(block)
(fixnum)
(not safe))
(define-type tar-rec
id: tar-rec-1e4c3b06-1a6f-4765-9d77-c1093d1c15ee
implementer: implement-type-tar-rec
name
mode
uid
gid
mtime
type
linkname
uname
gname
devmajor
devminor
atime
ctime
content)
(implement-type-tar-rec)
;;;============================================================================
;;; System dependencies.
(define (ISO-8859-1-string->u8vector str)
(let* ((len (string-length str))
(u8vect (make-u8vector len)))
(let loop ((i (- len 1)))
(if (>= i 0)
(begin
(u8vector-set! u8vect i (char->integer (string-ref str i)))
(loop (- i 1)))
u8vect))))
(define (u8vector->ISO-8859-1-string u8vect)
(let* ((len (u8vector-length u8vect))
(str (make-string len)))
(let loop ((i (- len 1)))
(if (>= i 0)
(begin
(string-set! str i (integer->char (u8vector-ref u8vect i)))
(loop (- i 1)))
str))))
(define (make-tar-condition msg)
msg)
;;;----------------------------------------------------------------------------
(define-macro (header-size) 512)
;;;----------------------------------------------------------------------------
;; Packing tar files.
(define (tar-pack-genport tar-rec-list genport-out)
(define tar-format 'gnu) ;; can be gnu, ustar or v7
;; (define tar-format 'ustar)
;; (define tar-format 'v7)
(define use-blanks #f)
;; Error handling.
(define (tar-field-overflow)
(make-tar-condition "tar field overflow"))
(define (tar-illegal-field)
(make-tar-condition "tar illegal field"))
(define (write-pad n)
(genport-write-subu8vector
(make-u8vector n 0)
0
n
genport-out)
#f)
(define (write-header tr)
(let ((header (make-u8vector (header-size) 0)))
(define (string-field str max-length offset)
(let ((len (string-length str)))
(if (> len max-length)
(tar-field-overflow)
(let loop ((i 0))
(if (< i len)
(begin
(u8vector-set!
header
(+ offset i)
(char->integer (string-ref str i)))
(loop (+ i 1)))
#f)))))
(define (byte-field byte offset)
(u8vector-set! header offset byte)
#f)
(define (octal-field-aux n-str len offset)
(let ((n-str-len (string-length n-str)))
(if (> n-str-len len)
(tar-field-overflow)
(let ((pad (- len n-str-len)))
(let loop ((i 0))
(if (< i pad)
(begin
(u8vector-set! header
(+ offset i)
(if use-blanks 32 48))
(loop (+ i 1)))))
(subu8vector-move!
(ISO-8859-1-string->u8vector n-str)
0
n-str-len
header
(+ offset pad))
#f))))
(define (octal-field0 n-str len offset)
(if use-blanks
(u8vector-set! header (+ offset (- len 1)) 32))
(octal-field-aux n-str (- len 1) offset))
(define (octal-field1-bignum n len offset)
(octal-field1 n len offset))
(define (octal-field1 n len offset)
(octal-field0 (number->string n 8) len offset))
(define (octal-field2 n len offset)
(if use-blanks
(octal-field1 n (- len 1) offset)
(octal-field1 n len offset)))
(define (octal-field3 n len offset)
(u8vector-set! header (+ offset (- len 1)) 0)
(octal-field-aux (number->string n 8) (- len 1) offset))
(define (checksum)
(let loop ((i 0))
(if (< i 8)
(begin
(u8vector-set! header (+ 148 i) 32)
(loop (+ i 1)))))
(let loop ((sum 0) (i 0))
(if (< i (header-size))
(loop (+ sum (u8vector-ref header i))
(+ i 1))
sum)))
(let* ((name (tar-rec-name tr))
(mode (tar-rec-mode tr))
(uid (tar-rec-uid tr))
(gid (tar-rec-gid tr))
(mtime (tar-rec-mtime tr))
(type (tar-rec-type tr))
(linkname (tar-rec-linkname tr))
(uname (tar-rec-uname tr))
(gname (tar-rec-gname tr))
(devmajor (tar-rec-devmajor tr))
(devminor (tar-rec-devminor tr))
(atime (tar-rec-atime tr))
(ctime (tar-rec-ctime tr))
(content (tar-rec-content tr))
(size (u8vector-length content)))
(or (string-field
(if (eq? tar-format 'gnu)
name
(let ((len (string-length name)))
(substring name (- len (min 100 len)) len)))
100
0)
(octal-field2 mode 8 100)
(octal-field2 uid 8 108)
(octal-field2 gid 8 116)
(octal-field1-bignum size 12 124)
(octal-field1-bignum mtime 12 136)
(case type
((regular)
(byte-field (if (eq? tar-format 'v7) 0 48) 156))
((link)
(byte-field 49 156))
((symbolic-link)
(byte-field 50 156))
((character-special)
(byte-field 51 156))
((block-special)
(byte-field 52 156))
((directory)
(byte-field 53 156))
((fifo)
(byte-field 54 156))
(else
(tar-illegal-field)))
(string-field linkname 100 157)
(case tar-format
((gnu)
(string-field "ustar " 8 257))
((ustar)
(or (string-field "ustar" 6 257)
(string-field "00" 2 263)))
(else
#f))
(string-field uname 32 265)
(string-field gname 32 297)
(and devmajor (octal-field1 devmajor 8 329))
(and devminor (octal-field1 devminor 8 337))
(if (eq? tar-format 'gnu)
(or (and atime (octal-field1-bignum atime 12 345))
(and ctime (octal-field1-bignum ctime 12 357)))
(let ((len (string-length name)))
(string-field
(substring name 0 (- len (min 100 len)))
155
345)))
(octal-field3 (checksum) 7 148)
(begin
(genport-write-subu8vector header 0 (header-size) genport-out)
#f)))))
(define (write-content tr)
(let* ((content (tar-rec-content tr))
(size (u8vector-length content)))
(genport-write-subu8vector content 0 size genport-out)
(write-pad (modulo (- size) 512))))
(define (write-tar-rec tr)
(or (write-header tr)
(write-content tr)))
(define (write-tar-rec-list tar-rec-list)
(let loop ((lst tar-rec-list))
(if (pair? lst)
(let ((tr (car lst)))
(or (write-tar-rec tr)
(loop (cdr lst))))
#f)))
(let ((exc (write-tar-rec-list tar-rec-list)))
(if exc
(raise exc)
(write-pad (* 2 512)))))
(define (tar-pack-file tar-rec-list filename #!optional (compressed? #f))
(genport-write-file (tar-pack-u8vector tar-rec-list compressed?)
filename)
#f)
(define (tar-pack-u8vector tar-rec-list #!optional (compressed? #f))
(let ((genport-out (genport-open-output-u8vector)))
(tar-pack-genport tar-rec-list genport-out)
(let ((u8vect (genport-get-output-u8vector genport-out)))
(if compressed?
(gzip-u8vector u8vect)
u8vect))))
;;;----------------------------------------------------------------------------
;; Unpacking tar files.
(define (tar-unpack-genport genport-in)
;; Error handling.
(define (tar-file-truncated-error)
(make-tar-condition "tar file truncated"))
(define (tar-header-format-unrecognized-error)
(make-tar-condition "tar header format unrecognized"))
(define (tar-header-checksum-error)
(make-tar-condition "tar header checksum error"))
(let ((header (make-u8vector (header-size))))
(define (string-field max-length offset)
(string-field-aux
(let loop ((len 0))
(if (or (= len max-length)
(= (u8vector-ref header (+ offset len)) 0))
len
(loop (+ len 1))))
offset))
(define (string-field-aux len offset)
(let ((str (make-string len)))
(let loop ((i 0))
(if (< i len)
(begin
(string-set!
str
i
(integer->char (u8vector-ref header (+ offset i))))
(loop (+ i 1)))
str))))
(define (byte-field offset)
(u8vector-ref header offset))
(define (octal-field-extract len offset)
(let loop1 ((start 0))
(if (and (< start len)
(= 32 (u8vector-ref header (+ offset start))))
(loop1 (+ start 1))
(let loop2 ((end start))
(if (and (< end len)
(let ((x (u8vector-ref header (+ offset end))))
(and (>= x 48) (<= x 55))))
(loop2 (+ end 1))
(u8vector->ISO-8859-1-string
(subu8vector header
(+ offset start)
(+ offset end))))))))
(define (octal-field-bignum len offset)
(octal-field len offset))
(define (octal-field len offset)
(string->number (octal-field-extract len offset) 8))
(define (checksum)
(let loop ((i 0))
(if (< i 8)
(begin
(u8vector-set! header (+ 148 i) 32)
(loop (+ i 1)))))
(let loop ((sum 0) (i 0))
(if (< i (header-size))
(loop (+ sum (u8vector-ref header i))
(+ i 1))
sum)))
(define (read-header)
(let ((n (genport-read-subu8vector header 0 (header-size) genport-in)))
(cond ((not (= n (header-size)))
(tar-file-truncated-error))
((= (u8vector-ref header 0) 0)
(make-tar-rec
#f #f #f #f #f #f #f #f #f
#f #f #f #f #f))
(else
(let ((name (string-field 100 0))
(mode (octal-field 8 100))
(uid (octal-field 8 108))
(gid (octal-field 8 116))
(size (octal-field-bignum 12 124))
(mtime (octal-field-bignum 12 136))
(chksum (octal-field 8 148))
(typeflag (byte-field 156))
(linkname (string-field 100 157))
(magicver (string-field 8 257))
(magic (string-field 6 257))
(version (string-field 2 263)))
(let* ((tar-format
(cond ((string=? magicver "ustar ")
'gnu)
((and (string=? magic "ustar")
(string=? version "00"))
'ustar)
((and (string=? magic "")
(string=? version ""))
'v7)
(else
'unknown)))
(gnu?
(eq? tar-format 'gnu)))
(cond ((eq? tar-format 'unknown)
(tar-header-format-unrecognized-error))
((not (= chksum (checksum)))
(tar-header-checksum-error))
(else
(let ((uname (string-field 32 265))
(gname (string-field 32 297))
(devmajor (octal-field 8 329))
(devminor (octal-field 8 337))
(prefix
(if gnu? "" (string-field 155 345)))
(atime
(if gnu? (octal-field-bignum 12 345) #f))
(ctime
(if gnu? (octal-field-bignum 12 357) #f))
(type
(case typeflag
((0 48)
'regular)
((49)
'link)
((50)
'symbolic-link)
((51)
'character-special)
((52)
'block-special)
((53)
'directory)
((54)
'fifo)
(else
#f))))
(make-tar-rec
(string-append prefix name)
mode
uid
gid
mtime
type
linkname
uname
gname
devmajor
devminor
atime
ctime
size))))))))))
(define (read-tar-file)
(let loop ((rev-tar-rec-list '()))
(let ((tar-rec (read-header)))
(if (tar-rec? tar-rec)
(let ((name (tar-rec-name tar-rec)))
(if (not name)
(reverse rev-tar-rec-list)
(let* ((size-bignum (tar-rec-content tar-rec))
(size size-bignum)
(v (make-u8vector size))
(n (genport-read-subu8vector v 0 size genport-in)))
(if (or (not (= n size))
(let ((pad (modulo (- size) 512)))
(not (= pad
(genport-read-subu8vector
(make-u8vector pad)
0
pad
genport-in)))))
(tar-file-truncated-error)
(begin
(tar-rec-content-set! tar-rec v)
(loop (cons tar-rec rev-tar-rec-list)))))))
tar-rec))))
(let ((result (read-tar-file)))
(if (pair? result)
result
(raise result)))))
(define (tar-unpack-genport* genport-in #!optional (compressed? #f))
(let* ((genport-in2
(if compressed?
(gunzip-genport genport-in)
genport-in))
(result
(tar-unpack-genport genport-in2)))
(genport-close-input-port genport-in2)
result))
(define (tar-unpack-file filename #!optional (compressed? #f))
(tar-unpack-genport* (genport-open-input-file filename)
compressed?))
(define (tar-unpack-u8vector u8vect #!optional (compressed? #f))
(tar-unpack-genport* (genport-open-input-u8vector u8vect)
compressed?))
;;;----------------------------------------------------------------------------
(define (tar-read filename)
(define (seconds t)
(round (inexact->exact (time->seconds t))))
(define (read-file filename rev-tar-rec-list)
(let* ((type
(if (eq? (file-type filename) 'directory)
'directory
'regular))
(content
(if (eq? type 'regular)
(genport-read-file filename)
(make-u8vector 0)))
(mode
(if (eq? type 'directory) 493 420))
(mtime
(seconds (file-last-modification-time filename)))
(atime
(seconds (file-last-access-time filename)))
(ctime
(seconds (file-last-change-time filename)))
(tr
(make-tar-rec
(path-to-unix
(if (eq? type 'directory)
(path-expand "" filename)
filename))
mode ;; mode
0 ;; uid
0 ;; gid
mtime ;; mtime
type
"" ;; linkname
"root" ;; uname
"root" ;; gname
0 ;; devmajor
0 ;; devminor
atime ;; atime
ctime ;; ctime
content))
(new-rev-tar-rec-list
(cons tr rev-tar-rec-list)))
(if (eq? type 'directory)
(read-dir filename new-rev-tar-rec-list)
new-rev-tar-rec-list)))
(define (read-dir dir rev-tar-rec-list)
(let loop ((files (directory-files dir))
(rev-tar-rec-list rev-tar-rec-list))
(if (pair? files)
(let* ((name
(car files))
(filename
(path-expand name dir)))
(loop (cdr files)
(read-file filename rev-tar-rec-list)))
rev-tar-rec-list)))
(reverse (read-file filename '())))
(define (tar-write tar-rec-list)
(if (not (pair? tar-rec-list))
(raise "empty tar record list")
(let* ((root-tar-rec (car tar-rec-list))
(root-name (tar-rec-name root-tar-rec))
(root-type (tar-rec-type root-tar-rec)))
(if (not (and (string=? (path-directory root-name) root-name)
(not (string=? (path-expand root-name ".") root-name))
(eq? root-type 'directory)))
(raise "root must be a directory that is not absolute")
(begin
(for-each
(lambda (tr)
(let ((name (tar-rec-name tr)))
(if (not (and (>= (string-length name)
(string-length root-name))
(string=? (substring
name
0
(string-length root-name))
root-name)))
(begin
(pp (list name root-name))
(raise "all files must be included in root directory"))))
)
tar-rec-list)
(delete-file-recursive root-name)
(tar-write-unchecked tar-rec-list))))))
(define (tar-write-unchecked tar-rec-list)
(for-each
(lambda (tr)
(let* ((name (tar-rec-name tr))
(filename (path-expand name)))
(create-dir-recursive (path-directory filename))
(if (eq? (tar-rec-type tr) 'directory)
(create-dir-recursive filename)
(genport-write-file (tar-rec-content tr) filename))))
tar-rec-list))
(define (create-dir dir)
(with-exception-catcher
(lambda (e)
#f)
(lambda ()
(create-directory dir)
#t)))
(define (exists? path)
(##vector? (##os-file-info path #t)))
(define (create-dir-recursive dir)
(let ((d (path-strip-trailing-directory-separator dir)))
(if (and (not (string=? dir "")) (not (exists? d)))
(begin
(create-dir-recursive (path-directory d))
(create-dir d)))))
(define (delete-file-recursive path)
(let ((path2 (path-expand path)))
(if (exists? path2)
(let ((type (file-type path2)))
(if (eq? type 'directory)
(let ((files
(directory-files
(list path: path2
ignore-hidden: 'dot-and-dot-dot))))
(parameterize ((current-directory path2))
(for-each delete-file-recursive files))
(delete-directory path2))
(delete-file path2))))))
(define (path-to-unix path)
(define (p2u path parts)
(let* ((f (path-strip-directory path))
(x (cons f parts))
(d (path-directory path)))
(if (string=? d "")
x
(let ((y (cons "/" x))
(p (path-strip-trailing-directory-separator d)))
(if (string=? p "")
y
(p2u p y))))))
(append-strings (p2u (path-strip-volume path) '())))
;;;----------------------------------------------------------------------------
(define (tar-file filename-in filename-out #!optional (compressed? #f))
(tar-pack-file
(tar-read filename-in)
filename-out
compressed?))
(define (untar-file filename #!optional (compressed? #f))
(tar-write
(tar-unpack-file
filename
compressed?)))
;;;============================================================================
| false |
4c88c0547b39e8b06f91a37d01d3931e5a3d204e | d63c4c79d0bf83ae646d0ac023ee0528a0f4a879 | /cs444/macro.scm | b9ef2786f7a7135bd4bf09d2be7a5fcbccf88842 | [] | no_license | stratigoster/UW | 4dc31f08f7f1c9a958301105dcad481c39c5361f | 7a4bff4f1476607c43278c488f70d01077b1566b | refs/heads/master | 2021-07-07T04:52:01.543221 | 2011-08-15T05:08:48 | 2011-08-15T05:08:48 | 10,858,995 | 1 | 1 | null | null | null | null | UTF-8 | Scheme | false | false | 122 | scm | macro.scm | (define-syntax unless
(syntax-rules ()
((unless test stmt1 stmt2)
(if (not test)
stmt1
stmt2))))
| true |
3dcb8b1c68e6395fe2dc984d0187a7199ad15e9d | 2c291b7af5cd7679da3aa54fdc64dc006ee6ff9b | /ch3/exercise.3.23.scm | 8101beecb3d59efa87ffd24ba15c98b3fd34b6f6 | [] | no_license | etscrivner/sicp | caff1b3738e308c7f8165fc65a3f1bc252ce625a | 3b45aaf2b2846068dcec90ea0547fd72b28f8cdc | refs/heads/master | 2021-01-10T12:08:38.212403 | 2015-08-22T20:01:44 | 2015-08-22T20:01:44 | 36,813,957 | 1 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 2,918 | scm | exercise.3.23.scm | (define (make-deque) (cons '() '()))
(define (make-item item before after)
(cons (cons item before) after))
(define (before-item item)
(cdr (car item)))
(define (after-item item)
(cdr item))
(define (value-item item)
(car (car item)))
(define (set-before-item! item before)
(set-cdr! (car item) before))
(define (set-after-item! item after)
(set-cdr! item after))
(define (front-ptr deque) (car deque))
(define (rear-ptr deque) (cdr deque))
(define (set-front-ptr! deque item) (set-car! deque item))
(define (set-rear-ptr! deque item) (set-cdr! deque item))
(define (empty-deque? deque) (null? (front-ptr deque)))
(define (front-deque deque)
(if (empty-deque? deque)
(error "FRONT called on empty deque" deque)
(car (car (front-ptr deque)))))
(define (rear-deque deque)
(if (empty-deque? deque)
(error "REAR called on empty deque" deque)
(car (car (rear-ptr deque)))))
(define (front-insert-deque! deque item)
(let ((new-pair (make-item item '() '())))
(cond ((empty-deque? deque)
(set-front-ptr! deque new-pair)
(set-rear-ptr! deque new-pair)
deque)
(else
(set-after-item! new-pair (front-ptr deque))
(set-before-item! (front-ptr deque) new-pair)
(set-front-ptr! deque new-pair)
deque))))
(define (rear-insert-deque! deque item)
(let ((new-pair (make-item item '() '())))
(cond ((empty-deque? deque)
(set-front-ptr! deque new-pair)
(set-rear-ptr! deque new-pair)
deque)
(else
(set-before-item! new-pair (rear-ptr deque))
(set-after-item! (rear-ptr deque) new-pair)
(set-rear-ptr! deque new-pair)
deque))))
(define (rear-delete-deque! deque)
(if (empty-deque? deque)
(error "REAR-DELETE called on empty deque" deque)
(let ((new-rear-item (before-item (rear-ptr deque))))
(if (not (null? new-rear-item))
(set-after-item! new-rear-item '())
(set-front-ptr! deque new-rear-item))
(set-rear-ptr! deque new-rear-item)
deque)))
(define (front-delete-deque! deque)
(if (empty-deque? deque)
(error "FRONT-DELETE called on empty deque" deque)
(let ((new-front-item (after-item (front-ptr deque))))
(if (not (null? new-front-item))
(set-before-item! new-front-item '())
(set-rear-ptr! deque new-front-item))
(set-front-ptr! deque new-front-item)
deque)))
(define (print-deque deque)
(define (iter remaining)
(if (null? remaining)
(newline)
(begin
(display (value-item remaining))
(display " ")
(iter (after-item remaining)))))
(iter (front-ptr deque)))
(define d1 (make-deque))
(begin
(front-insert-deque! d1 'a)
(front-insert-deque! d1 'b)
(rear-insert-deque! d1 'c)
(rear-insert-deque! d1 'd)
'done)
| false |
51f09aefea48ebdcb1005aa63ade71a1c2fa352f | f0747cba9d52d5e82772fd5a1caefbc074237e77 | /fetch-test.scm | cbf0d276fd62e95d9dc8b87330a8876a01ff69f3 | [] | no_license | philhofer/distill | a3b024de260dca13d90e23ecbab4a8781fa47340 | 152cb447cf9eef3cabe18ccf7645eb597414f484 | refs/heads/master | 2023-08-27T21:44:28.214377 | 2023-04-20T03:20:55 | 2023-04-20T03:20:55 | 267,761,972 | 3 | 0 | null | 2021-10-13T19:06:55 | 2020-05-29T04:06:55 | Scheme | UTF-8 | Scheme | false | false | 843 | scm | fetch-test.scm | (import
scheme
(only (chicken io) write-string)
(only (chicken file) delete-file)
(distill fetch)
(distill hash)
(distill eprint))
(define my-content "here is a string!\n")
(define content-hash (hash-of my-content))
(define (my-hook hash)
(if (equal? hash content-hash)
(lambda (dst)
(with-output-to-file dst
(lambda ()
(write-string my-content))))
(error "unexpected hash passed to my-hook" hash)))
(let* ((on-fail (lambda ()
(error "called on-failure")))
(src "https://b2cdn.sunfi.sh/path/does/not/exist"))
(parameterize ((user-fetch-hook my-hook))
(fetch-artifact src "." content-hash on-fail)
(unless (equal? (hash-file content-hash) content-hash)
(error "unexpected content hash" (hash-file content-hash)))
(delete-file content-hash)))
| false |
a01d2a88a6eb1cec7196964ffaaaafedcb76698f | 04ebb7f53a45b45b627a7a1ee7e6b11e2542207e | /internal/alist-access.scm | 7bc4fb0b73a9495bc2e010c945818caef1602885 | [] | no_license | openlilylib/oll-core | 85bf15a802a29e7649b1b62f9fb556ba1debd6ca | 6362634d4115ee4d1ff4de79fc54278509e70b16 | refs/heads/master | 2022-10-08T21:15:50.717358 | 2022-09-21T10:30:37 | 2022-09-21T10:30:37 | 49,104,940 | 18 | 14 | null | 2023-09-01T05:07:52 | 2016-01-06T01:53:46 | Scheme | UTF-8 | Scheme | false | false | 5,275 | scm | alist-access.scm | ;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
;% %
;% This file is part of openLilyLib, %
;% =========== %
;% the community library project for GNU LilyPond %
;% (https://github.com/openlilylib/openlilylib %
;% ----------- %
;% %
;% openLilyLib is free software: you can redistribute it and/or modify %
;% it under the terms of the GNU General Public License as published by %
;% the Free Software Foundation, either version 3 of the License, or %
;% (at your option) any later version. %
;% %
;% openLilyLib 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 openLilyLib. If not, see <http://www.gnu.org/licenses/>. %
;% %
;% openLilyLib is maintained by Urs Liska, [email protected] %
;% and others. %
;% Copyright Urs Liska, 2015 %
;% %
;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
(define-module (oll-core internal alist-access))
(use-modules
(lily)
(ice-9 common-list))
;;
;; Functions for easier and robust access to nested association lists.
;; Typically useful for implementing option trees.
;;
;; Set key <key-name> in alist <alst> to value <val>
;; If <in-place> is #t the key is replaced in-place if already present.
;; Otherwise (<in-place> is #f and/or key is not set) it is appended.
(define-public (set-in-alist alst key-name val in-place)
(let* ((process-alist
(if in-place
alst
(assoc-remove! alst key-name)))
(where (assoc key-name process-alist)))
(if where
(begin (set-cdr! where val) alst)
(append alst (list (cons key-name val))))))
;; Retrieve entry <key-name> from alist <alst>.
;; If <return-pair> is #t then the function behaves like 'assoc',
;; that is it returns the key-value pair or #f.
;; Otherwise it returns only the value or #f without the chance of
;; discerning between a non-present key or a literal value #f.
(define-public (get-from-alist alst key-name return-pair)
(let ((intermediate (assoc key-name alst)))
(if return-pair
intermediate
(if (pair? intermediate)
(cdr intermediate)
#f))))
;; Set <path> in alist <tree> to value <val>.
;; <path> is a symbol list, with the last element being the actual key.
;; If any node or the final key is not present it is created implicitly.
;; If <in-place> is #t the key is modified in place if already present,
;; otherwise it will be appended.
;; Intermediate nodes are always updated in place if the already exist.
(define-public (set-in-atree tree path val in-place)
(let ((key-name (car path)))
(if (not (list? tree))
(begin
(ly:input-warning (*location*) "Not a list. Deleting '~A'" tree)
(set! tree '())))
(cond ((> (length path) 1)
(let ((subtree (assoc-get key-name tree '())))
(set-in-alist
tree
key-name
;; Intermediate nodes are always updated in-place
(set-in-atree subtree (cdr path) val #t)
in-place)))
(else
(set-in-alist tree key-name val in-place)))))
;; Recursively walk the nested alist <tree> over the symbol-list <path>
;; and return the value for the last leaf in <path> or #f if the chain
;; is broken at any point.
(define-public (get-from-tree tree path return-pair)
(let ((key-name (car path)))
(if (> (length path) 1)
(let ((subtree (assoc-get key-name tree #f)))
(if (list? subtree)
(get-from-tree subtree (cdr path) return-pair)
#f))
(get-from-alist tree (car path) return-pair))))
;; Takes the alist <tree> and removes the node <path>,
;; returns a new list.
(define-public (remove-value tree path)
(let* ((key-name (car path))
(subpath (cdr path))
(subtree (assoc-get key-name tree '())))
(cond
((> (length subpath) 1)
(set-in-alist tree key-name (remove-value subtree (cdr path)) #t))
(else
(set-in-alist tree key-name (assoc-remove! subtree (car subpath)) #t)))))
| false |
5d8cab94516b0d09ea4630ddd85bf12e32c2449c | a8216d80b80e4cb429086f0f9ac62f91e09498d3 | /lib/chibi/quoted-printable.scm | bcd50cda13354a509fbf80a7b1f86426aafd7b45 | [
"BSD-3-Clause"
] | permissive | ashinn/chibi-scheme | 3e03ee86c0af611f081a38edb12902e4245fb102 | 67fdb283b667c8f340a5dc7259eaf44825bc90bc | refs/heads/master | 2023-08-24T11:16:42.175821 | 2023-06-20T13:19:19 | 2023-06-20T13:19:19 | 32,322,244 | 1,290 | 223 | NOASSERTION | 2023-08-29T11:54:14 | 2015-03-16T12:05:57 | Scheme | UTF-8 | Scheme | false | false | 7,252 | scm | quoted-printable.scm | ;; quoted-printable.scm -- RFC2045 implementation
;; Copyright (c) 2005-2014 Alex Shinn. All rights reserved.
;; BSD-style license: http://synthcode.com/license.txt
;;> RFC 2045 quoted printable encoding and decoding utilities. This
;;> API is backwards compatible with the Gauche library
;;> rfc.quoted-printable.
;;> \schemeblock{
;;> (define (mime-encode-header header value charset)
;;> (let ((prefix (string-append header ": "))
;;> (str (ces-convert value "UTF8" charset)))
;;> (string-append
;;> prefix
;;> (quoted-printable-encode-header charset str (string-length prefix)))))
;;> }
(define *default-max-col* 76)
;; Allow for RFC1522 quoting for headers by always escaping ? and _
(define (qp-encode bv start-col max-col separator)
(define (hex i) (+ i (if (<= i 9) 48 55)))
(let ((end (bytevector-length bv))
(buf (make-bytevector max-col))
(out (open-output-bytevector)))
(let lp ((i 0) (col start-col))
(cond
((= i end)
(write-bytevector (bytevector-copy buf 0 col) out)
(get-output-bytevector out))
((>= col (- max-col 3))
(write-bytevector (bytevector-copy buf 0 col) out)
(lp i 0))
(else
(let ((c (bytevector-u8-ref bv i)))
(cond
((and (<= 33 c 126) (not (memq c '(61 63 95))))
(bytevector-u8-set! buf col c)
(lp (+ i 1) (+ col 1)))
(else
(bytevector-u8-set! buf col (char->integer #\=))
(bytevector-u8-set! buf (+ col 1) (hex (arithmetic-shift c -4)))
(bytevector-u8-set! buf (+ col 2) (hex (bitwise-and c #b1111)))
(lp (+ i 1) (+ col 3))))))))))
;;> Return a quoted-printable encoded representation of the input
;;> according to the official standard as described in RFC2045.
;;>
;;> ? and _ are always encoded for compatibility with RFC1522
;;> encoding, and soft newlines are inserted as necessary to keep each
;;> lines length less than \var{max-col} (default 76). The starting
;;> column may be overridden with \var{start-col} (default 0).
(define (quoted-printable-encode-string src . o)
(if (string? src)
(utf8->string
(apply quoted-printable-encode-bytevector
(string->utf8 src)
o))
(apply quoted-printable-encode-bytevector src o)))
(define (quoted-printable-encode-bytevector . o)
(let* ((src (if (pair? o) (car o) (current-input-port)))
(o (if (pair? o) (cdr o) '()))
(start-col (if (pair? o) (car o) 0))
(o (if (pair? o) (cdr o) '()))
(max-col (if (pair? o) (car o) *default-max-col*))
(o (if (pair? o) (cdr o) '()))
(sep (if (pair? o) (car o) (string->utf8 "=\r\n"))))
(qp-encode (if (bytevector? src) src (read-bytevector 1000000000 src))
start-col max-col sep)))
;;> Variation of the above to read and write to ports.
(define (quoted-printable-encode . o)
(write-string (apply quoted-printable-encode-string o)))
;;> Return a quoted-printable encoded representation of string as
;;> above, wrapped in =?ENC?Q?...?= as per RFC1522, split across
;;> multiple MIME-header lines as needed to keep each lines length
;;> less than \var{max-col}. The string is encoded as is, and the
;;> encoding \var{enc} is just used for the prefix, i.e. you are
;;> responsible for ensuring \var{str} is already encoded according to
;;> \var{enc}.
(define (quoted-printable-encode-header encoding . o)
(let* ((src (if (pair? o) (car o) (current-input-port)))
(o (if (pair? o) (cdr o) '()))
(start-col (if (pair? o) (car o) 0))
(o (if (pair? o) (cdr o) '()))
(max-col (if (pair? o) (car o) *default-max-col*))
(o (if (pair? o) (cdr o) '()))
(nl (if (pair? o) (car o) "\r\n")))
(let* ((prefix (string-append "=?" encoding "?Q?"))
(prefix-length (+ 2 (string-length prefix)))
(separator (string->utf8 (string-append "?=" nl "\t" prefix)))
(effective-max-col (- max-col prefix-length)))
(bytevector-append
(string->utf8 prefix)
(qp-encode (if (string? src) src (port->string src))
start-col effective-max-col separator)
(string->utf8 "?=")))))
;;> Return a quoted-printable decoded representation of \var{str}. If
;;> \var{mime-header?} is specified and true, _ will be decoded as as
;;> space in accordance with RFC1522. No errors will be raised on
;;> invalid input.
(define (quoted-printable-decode-string src . o)
(if (string? src)
(utf8->string
(apply quoted-printable-decode-bytevector
(string->utf8 src)
o))
(apply quoted-printable-decode-bytevector src o)))
(define (quoted-printable-decode-bytevector . o)
(define (hex? c)
(or (char<=? #\0 (integer->char c) #\9)
(char<=? #\A (integer->char c) #\F)))
(define (unhex1 i)
(if (>= i 65) (- i 55) (- i 48)))
(define (unhex c1 c2)
(+ (arithmetic-shift (unhex1 c1) 4) (unhex1 c2)))
(let ((src (if (pair? o) (car o) (current-input-port)))
(mime-header? (and (pair? o) (pair? (cdr o)) (car (cdr o)))))
(let* ((bv (if (bytevector? src) src (read-bytevector 1000000000 src)))
(end (bytevector-length bv))
(out (open-output-bytevector)))
(let lp ((i 0))
(cond
((>= i end)
(get-output-bytevector out))
(else
(let ((c (bytevector-u8-ref bv i)))
(case c
((61) ; = escapes
(cond
((< (+ i 2) end)
(let ((c2 (bytevector-u8-ref bv (+ i 1))))
(cond
((eq? c2 10) (lp (+ i 2)))
((eq? c2 13)
(lp (if (eq? 10 (bytevector-u8-ref bv (+ i 2)))
(+ i 3)
(+ i 2))))
((hex? c2)
(let ((c3 (bytevector-u8-ref bv (+ i 2))))
(if (hex? c3) (write-u8 (unhex c2 c3) out))
(lp (+ i 3))))
(else (lp (+ i 3))))))))
((95) ; maybe translate _ to space
(write-u8 (if mime-header? 32 c) out)
(lp (+ i 1)))
((32 9) ; strip trailing whitespace
(let lp2 ((j (+ i 1)))
(cond
((not (= j end))
(case (bytevector-u8-ref bv j)
((32 9) (lp2 (+ j 1)))
((10)
(lp (+ j 1)))
((13)
(let ((k (+ j 1)))
(lp (if (and (< k end)
(eq? 10 (bytevector-u8-ref bv k)))
(+ k 1) k))))
(else
(write-bytevector (bytevector-copy bv i j) out)
(lp j)))))))
(else ; a literal char
(write-u8 c out)
(lp (+ i 1)))))))))))
;;> Variation of the above to read and write to ports.
(define (quoted-printable-decode . o)
(write-string (apply quoted-printable-decode-string o)))
| false |
e9f1cbc5109c30af095942c0907804946f3cda1f | 0fb87930229b3bec24d7d6ad3dae79c715fd4c58 | /src/intepreter/src/lazy_test.scm | 512ce4c74c41d60784e1c74d5b9c8d75c188df02 | [
"BSD-2-Clause"
] | permissive | klose911/klose911.github.io | 76beb22570b8e483532e8f2521b2b6334b4f856e | 7d2407ff201af38d6c6178f93793b7d6cf59fbd8 | refs/heads/main | 2023-09-01T18:04:45.858325 | 2023-08-29T09:35:25 | 2023-08-29T09:35:25 | 73,625,857 | 3 | 2 | Apache-2.0 | 2020-09-17T08:27:56 | 2016-11-13T15:52:32 | HTML | UTF-8 | Scheme | false | false | 1,481 | scm | lazy_test.scm | (define (try a b)
(if (> a 0) 1 b))
;; (try 0 (/ 1 0)) ;Division by zero signalled by /.
(define (unless condition usual-value exceptional-value)
(if condition exceptional-value usual-value))
;; (define a 10)
;; (define b 2)
;; (unless (= b 0)
;; (/ a b)
;; (begin (display "exception: returning 0")
;; 0))
;; => exception: returning 0
;; Value: 5
;;; stream test
(define (list-ref items n)
(if (= n 0)
(car items)
(list-ref (cdr items) (- n 1))))
(define (map proc items)
(if (null? items)
'()
(cons (proc (car items))
(map proc (cdr items)))))
(define (scale-list items factor)
(map (lambda (x) (* x factor))
items))
(define (add-lists list1 list2)
(cond ((null? list1) list2)
((null? list2) list1)
(else (cons (+ (car list1) (car list2))
(add-lists (cdr list1) (cdr list2))))))
;; (define ones (cons 1 ones))
;; (define integers (cons 1 (add-lists ones integers)))
;;; L-Eval input:
;; (list-ref integers 17)
;;; L-Eval value:
;; 18
;;; integral test
;; (define (integral integrand initial-value dt)
;; (define int
;; (cons initial-value
;; (add-lists (scale-list integrand dt)
;; int)))
;; int)
;; (define (solve f y0 dt)
;; (define y (integral dy y0 dt))
;; (define dy (map f y))
;; y)
;;; L-Eval input:
;; (list-ref (solve (lambda (x) x) 1 0.001) 1000)
;;; L-Eval value:
;; 2.716923932235896
| false |
e95b8f3657f36bae70588d28b30985b64373602e | ea4e27735dd34917b1cf62dc6d8c887059dd95a9 | /section1_2_exercise1_23.scm | 6d7b345c5c72c5f1d612d38e672e420bfb69f646 | [
"MIT"
] | permissive | feliposz/sicp-solutions | 1f347d4a8f79fca69ef4d596884d07dc39d5d1ba | 5de85722b2a780e8c83d75bbdc90d654eb094272 | refs/heads/master | 2022-04-26T18:44:32.025903 | 2022-03-12T04:27:25 | 2022-03-12T04:27:25 | 36,837,364 | 1 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 2,021 | scm | section1_2_exercise1_23.scm | (define (smallest-divisor n)
(find-divisor n 2))
(define (next x)
(if (= x 2)
3
(+ x 1)))
(define (find-divisor n test-divisor)
(cond ((> (square test-divisor) n) n)
((divides? test-divisor n) test-divisor)
(else (find-divisor n (next test-divisor)))))
(define (divides? a b)
(= (remainder b a) 0))
(define (prime? n)
(= n (smallest-divisor n)))
(define (timed-prime-test n)
(newline)
(display n)
(start-prime-test n (runtime)))
(define (start-prime-test n start-time)
(if (prime? n)
(report-prime (- (runtime) start-time))))
(define (report-prime elapsed-time)
(display " *** ")
(display elapsed-time))
(define (timed-prime? n start-time)
(cond ((prime? n)
(newline)
(display n)
(report-prime (- (runtime) start-time)) #t)
(else #f)))
(define (search-for-primes n)
(define (search-loop n count)
(if (= count 0)
0
(search-loop (+ n 1) (if (timed-prime? n (runtime))
(- count 1)
count))))
(search-loop n 3))
;---------------------------------
; Old elapsed-time values for the procedure when testing for even numbers
;(search-for-primes 1000000000000)
;1000000000039 *** 7.612999999999943
;1000000000061 *** 8.627999999999929
;1000000000063 *** 11.169000000000096
;Value: 0
;(search-for-primes 10000000000000)
;10000000000037 *** 21.29499999999996
;10000000000051 *** 19.187000000000012
;10000000000099 *** 23.883000000000038
;Value: 0
;----------------------------
; New elapsed-time for function, now skipping even numbers
;(search-for-primes 1000000000000)
;1000000000039 *** 6.912000000000035
;1000000000061 *** 5.100999999999999
;1000000000063 *** 8.392999999999915
;Value: 0
;(search-for-primes 10000000000000)
;10000000000037 *** 37.81600000000003
;10000000000051 *** 23.760999999999967
;10000000000099 *** 20.701999999999998
;Value: 0
; Not much has changed. Apparently it's the same time.
; I guess that the added test inside the (next) procedure is taking the same
; time for the test that the even numbers would take. (???)
| false |
9a7b95384fb2b3f905721c937a337df392211c6d | 0a345b89eae9a12e18e8d30f24d592a724284a59 | /libmdal/md-command.scm | b1a7bc3efa7cd64f8b4f9d755afcc082c907828e | [
"MIT"
] | permissive | DeMOSic/bintracker | 7b26ecb3b8ad315727bb65f1051206b2dcac7123 | bed6356b7d177d969ea3873527a1698a00305acf | refs/heads/master | 2023-03-26T19:11:49.396339 | 2021-03-29T08:51:12 | 2021-03-29T08:51:12 | null | 0 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 6,486 | scm | md-command.scm | ;; This file is part of the libmdal library.
;; Copyright (c) utz/irrlicht project 2018-2020
;; See LICENSE for license details.
;; -----------------------------------------------------------------------------
;; MDCONF: COMMANDS
;; -----------------------------------------------------------------------------
;;; MDAL Command Configuration
(module md-command
(make-command
command-type
command-bits
command-default
command-reference-to
command-keys
command-flags
command-range
command-description
command-has-flag?
command-has-flags?
display-command
make-default-commands
make-modifier-commands
eval-command)
(import scheme (chicken base) (chicken string) (chicken io) (chicken format)
(chicken condition)
srfi-1 srfi-13 srfi-14 srfi-69 typed-records md-helpers)
;;; command config record type
(defstruct command
type ;;; one of `int uint key ukey reference string trigger label` or a
;;; user-defined type
(bits 0) ;;; number of bits in command
(default 0) ;;; default value
reference-to ;;; `#f` or an identifier
keys ;;; `#f` or a hash-map
(flags '()) ;;; list of command flags
range ;;; `#f` or a range object
description ;;; `#f` or a string
)
;;; check if the given command CMD has the given FLAG
(define (command-has-flag? cmd flag)
(and (memq flag (command-flags cmd)) #t))
;;; check if the given command CMD has any flags
(define (command-has-flags? cmd)
(not (null? (command-flags cmd))))
(define (display-command cmd)
(printf "#<command>\ntype: ~A\nbits: ~S\ndefault: ~A~!"
(command-type cmd)
(command-bits cmd)
(command-default cmd))
(when (command-reference-to cmd)
(printf "\nref: ~S" (command-reference-to cmd)))
(when (command-keys cmd)
(printf "\nkeys: ~S" (command-keys cmd)))
(when (command-has-flags? cmd)
(printf "\nflags: ~S" (command-flags cmd)))
(when (command-range cmd)
(printf "\nrange: ~S - ~S"
(range-min (command-range cmd))
(range-max (command-range cmd))))
(when (command-description cmd)
(printf "\ndescription:\n~A~!" (command-description cmd))))
;;; construct a hash table from a file containing key/value definitions
;; TODO currently unused, but should be useful
(define (mapfile->map filepath)
(alist->hash-table
(map (lambda (str)
(let ((entry (string-split (string-delete char-set:whitespace str)
"=")))
(list (car entry) (string->number (cadr entry)))))
(filter (lambda (x) (string-contains x "="))
(call-with-input-file filepath read-lines)))))
;;; Construct an alist containing the default commands AUTHOR, TITLE, and
;;; LICENSE
(define (make-default-commands)
`((AUTHOR . ,(make-command type: 'string default: "unknown"))
(TITLE . ,(make-command type: 'string default: "untitled"))
(LICENSE . ,(make-command type: 'string default: "All Rights Reserved"))))
;;; basic error checks for mdalconfig command specification
(define (check-command-spec id type bits default reference-to
keys range flags)
(unless (and id type (or default (eqv? type 'trigger)))
(mdal-abort "missing id, type, and/or default specifier"))
(when (and (memv type '(int uint key ukey reference modifier))
(not bits))
(mdal-abort "missing bits specifier"))
(unless (memv type '(int uint key ukey reference trigger string modifier))
(mdal-abort (string-append "unknown command type " (->string type))))
(when (and (memv type '(key ukey))
(not keys))
(mdal-abort "missing keys specifier"))
(when (and (memv type '(reference modifier))
(not reference-to))
(mdal-abort "missing reference-to specifier"))
(when (and range (not (memv type '(int uint modifier))))
(mdal-abort "range used on command not of type int, uint or modifier"))
(when (and (not (memv type '(key ukey)))
(memv 'enable-modifiers flags))
(mdal-abort (string-append
"Cannot create modifer for command of type "
(symbol->string type)))))
;;; Construct modifier commands for the alist of id, command pairs, as
;;; required by the `'enable-modifiers` flag.
(define (make-modifier-commands base-commands)
(map (lambda (cmd-spec)
(let ((source-id (car cmd-spec))
(source-command (cdr cmd-spec)))
(cons (symbol-append 'MOD_ source-id)
(make-command
type: 'modifier
bits: (command-bits source-command)
default: '0+
reference-to: source-id
flags: (filter (cute eqv? <> 'use-last-set)
(command-flags source-command))
range: (or (command-range source-command)
(bits->range (command-bits source-command) #f))
description: (string-append "Modifier for "
(symbol->string source-id))))))
(filter (lambda (x)
(command-has-flag? (cdr x) 'enable-modifiers))
base-commands)))
;;; Evaluate a MDCONF command definition expression. Returns a `command`
;;; object.
(define (eval-command path-prefix cpu-speed #!key id type bits default
reference-to keys (flags '()) range (description ""))
(handle-exceptions
exn
(if ((condition-predicate 'mdal) exn)
(mdal-abort (string-append
"Invalid command specification\n"
((condition-property-accessor 'mdal 'message) exn))
(string-append "command:"
(if id (->string id) "???")))
(abort exn))
(check-command-spec id type bits default reference-to keys range flags)
(cons id
(make-command
type: type
bits: (case type
((string) 0)
((trigger) 1)
(else bits))
default: default
reference-to: reference-to
keys: (and keys
(if (pair? (car keys))
(alist->hash-table keys)
(eval `(let ((make-dividers
(lambda (cycles bits rest
#!optional (shift 1))
(make-dividers ,cpu-speed cycles
bits rest shift)))
(make-inverse-dividers
(lambda (cycles bits rest
#!optional (shift 1))
(make-inverse-dividers
,cpu-speed cycles bits rest
shift))))
,keys))))
flags: flags
range: (or range
(and (memv type '(int uint))
(bits->range bits (eqv? type 'int))))
description: description))))
) ;; end module md-command
| false |
6036efe278913f29023446fab2af96be3310308a | bcfa2397f02d5afa93f4f53c0b0a98c204caafc1 | /scheme/chapter3/ex3_3.scm | 5ac42020f18415a53a51db24c6fe828dd842409b | [] | no_license | rahulkumar96/sicp-study | ec4aa6e1076b46c47dbc7a678ac88e757191c209 | 4dcd1e1eb607aa1e32277e1c232a321c5de9c0f0 | refs/heads/master | 2020-12-03T00:37:39.576611 | 2017-07-05T12:58:48 | 2017-07-05T12:58:48 | 96,050,670 | 0 | 0 | null | 2017-07-02T21:46:09 | 2017-07-02T21:46:09 | null | UTF-8 | Scheme | false | false | 1,160 | scm | ex3_3.scm | ;; SICP 3.3
;; Exercise 3.3. Modify the make-account procedure so that it creates
;; password-protected accounts. That is, make-account should take a
;; symbol as an additional argument, as in
;; (define acc (make-account 100 'secret-password))
;; The resulting account object should process a request only if it is
;; accompanied by the password with which the account was created, and
;; should otherwise return a complaint:
;; ((acc 'secret-password 'withdraw) 40)
;; 60
;; ((acc 'some-other-password 'deposit) 50)
;; "Incorrect password"
;; -------------------------------------------------------------------
(define (make-account actual-password balance)
(define (withdraw amount)
(cond ((> amount balance) "Insufficient funds")
(else (set! balance (- balance amount))
balance)))
(define (deposit amount)
(set! balance (+ balance amount))
balance)
(define (bad-password ignored)
"Incorrect password")
(lambda (password operation)
(cond ((not (equal? password actual-password)) bad-password)
((equal? operation 'withdraw) withdraw)
((equal? operation 'deposit) deposit))))
| false |
1d8061ac092bd8167ddf90ac9ed68d561e9989fa | 6f86602ac19983fcdfcb2710de6e95b60bfb0e02 | /input/skeleton-test.ss | 7c476e4cf18ad99417286282934e2e5ac30f6e9d | [
"MIT",
"CC-BY-SA-3.0"
] | permissive | exercism/scheme | a28bf9451b8c070d309be9be76f832110f2969a7 | d22a0f187cd3719d071240b1d5a5471e739fed81 | refs/heads/main | 2023-07-20T13:35:56.639056 | 2023-07-18T08:38:59 | 2023-07-18T08:38:59 | 30,056,632 | 34 | 37 | MIT | 2023-09-04T21:08:27 | 2015-01-30T04:46:03 | Scheme | UTF-8 | Scheme | false | false | 2,915 | ss | skeleton-test.ss | (define test-fields
'(input
output))
(define (test-run-solution solution input)
(if (procedure? solution)
(apply solution input)
solution))
(define (test-success description success-predicate procedure input output)
(call/cc
(lambda (k)
(let ((out (open-output-string)))
(with-exception-handler
(lambda (e)
(let ((result `(fail . ((description . ,description)
(input . ,input)
(output . ,output)
(stdout . ,(get-output-string out))))))
(close-output-port out)
(k result)))
(lambda ()
(let ((result (parameterize ((current-output-port out))
(test-run-solution procedure input))))
(unless (success-predicate result output)
(error 'exercism-test "test fails" description input result output)))
(let ((result `(pass . ((description . ,description)
(stdout . ,(get-output-string out))))))
(close-output-port out)
result)))))))
(define (test-error description procedure input)
(call/cc
(lambda (k)
(let ((out (open-output-string)))
(with-exception-handler
(lambda (e)
(let ((result `(pass . ((description . ,description)
(stdout . ,(get-output-string out))))))
(close-output-port out)
(k result)))
(lambda ()
(parameterize ((current-output-port out))
(test-run-solution procedure input))
(let ((result `(fail . ((description . ,description)
(input . ,input)
(output . error)
(stdout . ,(get-output-string out))))))
(close-output-port out)
result)))))))
(define (run-test-suite tests . query)
(for-each (lambda (field)
(unless (and (symbol? field) (memq field test-fields))
(error 'run-test-suite
(format #t "~a not in ~a" field test-fields))))
query)
(let-values (((passes failures)
(partition (lambda (result)
(eq? 'pass (car result)))
(map (lambda (test)
(test))
tests))))
(cond
((null? failures)
(format #t "~%Well done!~%~%"))
(else
(format #t "~%Passed ~a/~a tests.~%~%The following test cases failed:~%~%"
(length passes)
(length tests))
(for-each (lambda (failure)
(format #t "* ~a~%"
(cond ((assoc 'description (cdr failure))
=> cdr)
(else (cdr failure))))
(for-each (lambda (field)
(let ((info (assoc field (cdr failure))))
(display " - ")
(write (car info))
(display ": ")
(write (cdr info))
(newline)))
query))
failures)
(error 'test "incorrect solution")))))
(define (run-docker test-cases)
(write (map (lambda (test) (test)) test-cases)))
| false |
5db15831963554a4fa5ac92bef74e9d64a6a10b1 | dde6f1cc65c21d5b902da10388e5899c7860ce64 | /utilities/graph.sld | 22e9ace8a6097be74e2581b05f9e4488d129ff34 | [] | no_license | alaricsp/api.scheme.org | 2a37961035a057870ec52325a2046e56d862a1c9 | 97c48a93753ddd7dc3f5e17bb4f3854dd1f42e7f | refs/heads/master | 2023-01-31T10:44:52.845579 | 2020-12-18T12:32:28 | 2020-12-18T12:32:28 | null | 0 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 1,187 | sld | graph.sld | (define-library (utilities graph)
(export define-source-value
define-value)
(import (scheme base))
(begin
(define-record-type <source-value>
(make-source-value symbol schedule update)
source-value?
(symbol source-value-symbol)
(schedule source-value-schedule)
(update source-value-update))
(define-record-type <derived-value>
(make-derived-value symbol depends update)
derived-value?
(symbol derived-value-symbol)
(schedule derived-value-depends)
(update derived-value-update))
(define graph '())
(define (graph-add! value)
(set! graph (cons value graph)))
(define-syntax define-source-value
(syntax-rules ()
((_ symbol schedule update-expr)
(graph-add! (make-source-value
'symbol
'schedule
(lambda () update-expr))))))
(define-syntax define-value
(syntax-rules ()
((_ symbol (depends ...) update-expr)
(graph-add! (make-derived-value
'symbol
'(depends ...)
(lambda () update-expr))))))))
| true |
c118396ab32d95c8d5e664b28f06b0bce7653526 | beac83b9c75b88060f4af609498541cf84437fd3 | /site/content/centralized-people/ryan-culpepper.ss | 7af01306b1569e657fab050eaedb3a81308ab942 | [] | no_license | nuprl/prl-website | 272ce3b9edd5b3ada23798a694f6cb7c6d510776 | 31a321f629a62f945968c3e4c59d180de0f656f6 | refs/heads/master | 2021-05-16T02:06:38.847789 | 2016-09-16T14:41:22 | 2016-09-16T14:41:22 | 412,044 | 1 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 501 | ss | ryan-culpepper.ss | #lang scheme
(provide me)(define me (quote (person "Ryan Culpepper" (group "Alumni") (graduated 2010) (thesis "http://www.ccs.neu.edu/scheme/pubs/dissertation-culpepper.pdf") (picture "gallery/Ryan_Culpepper.jpg") (homepage "http://www.ccs.neu.edu/home/ryanc/") (bio " Born in Houston, TX, left, went back to go to Rice University. Interested in PL and compilers. I read during the summer and play table tennis during the winter. I'm still looking for someone up here who has heard of disc golf."))))
| false |
f08f0e973697a7ebcd3ea882f8f902bc9b19fc99 | fb93352482541f4269387c5872b9f1124a9182d3 | /chenhao/chapter01/1.44.scm | 3ab115432cf54af5cb04545fbe24b5b182162aae | [] | no_license | sicper/sicp-solutions | bfb5bd0f9f6eba0b396af88a4b5a2834ccfc5054 | b79c3d9f193fbec26b5302f03de6dabd473203cf | refs/heads/master | 2021-01-14T13:42:47.796733 | 2016-01-04T05:03:48 | 2016-01-04T05:03:48 | 38,525,815 | 1 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 183 | scm | 1.44.scm | (define dx 0.0001)
(define (smooth f)
(lambda (x) (/ (+ (f (- x dx)) (f x) (f (+ x dx))) 3.0)))
;(define (fun x)
;(if en)
;)
(load "1.43.scm")
(((repeat (smooth) 5) abs) 1.0)
| false |
152d45273dcbf6a3bbab13fa479bbe6fa19ec63c | 120324bbbf63c54de0b7f1ca48d5dcbbc5cfb193 | /packages/slib/repl.scm | 596f4d7b574889aed8ffda8f9c100bc7ef1e9c15 | [
"MIT"
] | permissive | evilbinary/scheme-lib | a6d42c7c4f37e684c123bff574816544132cb957 | 690352c118748413f9730838b001a03be9a6f18e | refs/heads/master | 2022-06-22T06:16:56.203827 | 2022-06-16T05:54:54 | 2022-06-16T05:54:54 | 76,329,726 | 609 | 71 | MIT | 2022-06-16T05:54:55 | 2016-12-13T06:27:36 | Scheme | UTF-8 | Scheme | false | false | 2,831 | scm | repl.scm | ; "repl.scm", read-eval-print-loop for Scheme
; Copyright (C) 1993, 2003 Aubrey Jaffer
;
;Permission to copy this software, to modify it, to redistribute it,
;to distribute modified versions, and to use it for any purpose is
;granted, subject to the following restrictions and understandings.
;
;1. Any copy made of this software must include this copyright notice
;in full.
;
;2. I have made no warranty or representation that the operation of
;this software will be error-free, and I am under no obligation to
;provide any services, by way of maintenance, update, or otherwise.
;
;3. In conjunction with products arising from the use of this
;material, there shall be no use of my name in any advertising,
;promotional, or sales literature without prior written consent in
;each case.
(require 'values)
(require 'dynamic-wind)
(require-if 'compiling 'qp)
(require-if 'compiling 'debug)
;@
(define (repl:quit) (slib:error "not in repl:repl"))
;@
(define (repl:top-level repl:eval)
(repl:repl (lambda () (display "> ")
(force-output (current-output-port))
(read))
repl:eval
(lambda objs
(cond ((null? objs))
(else
(write (car objs))
(for-each (lambda (obj)
(display " ;") (newline) (write obj))
(cdr objs))))
(newline))))
(define (repl:repl repl:read repl:eval repl:print)
(let* ((old-quit repl:quit)
(old-error slib:error)
(old-eval slib:eval)
(old-load load)
(repl:load (lambda (<pathname>)
(call-with-input-file <pathname>
(lambda (port)
(with-load-pathname <pathname>
(lambda ()
(do ((o (read port) (read port)))
((eof-object? o))
(repl:eval o))))))))
(repl:restart #f)
(has-char-ready? (provided? 'char-ready?))
(repl:error (lambda args (require 'debug) (apply qpn args)
(repl:restart #f))))
(dynamic-wind
(lambda ()
(set! load repl:load)
(set! slib:eval repl:eval)
(set! slib:error repl:error)
(set! repl:quit
(lambda () (let ((cont repl:restart))
(set! repl:restart #f)
(cont #t)))))
(lambda ()
(do () ((call-with-current-continuation
(lambda (cont)
(set! repl:restart cont)
(do ((obj (repl:read) (repl:read)))
((eof-object? obj) (repl:quit))
(cond
(has-char-ready?
(let loop ()
(cond ((char-ready?)
(let ((c (peek-char)))
(cond
((eof-object? c))
((char=? #\newline c) (read-char))
((char-whitespace? c)
(read-char) (loop))
(else (newline)))))))))
(call-with-values (lambda () (repl:eval obj))
repl:print)))))))
(lambda () (cond (repl:restart
(display ">>ERROR<<") (newline)
(repl:restart #f)))
(set! load old-load)
(set! slib:eval old-eval)
(set! slib:error old-error)
(set! repl:quit old-quit)))))
| false |
4ab4ddd69b0eb0ceabacdc3636778d6e0aa7063f | fc2c004cab11d3e400c8fca1dbcbf0aa35cdadd7 | /pthreads.scm | 6f8f9e8147653ddae08e3e6e02c153413729e485 | [
"BSD-3-Clause"
] | permissive | 0-8-15/pthreads | ced6a48f65e082505b5be7a9281bd87e35ae4e30 | 14f80c55350a37d52f333e0bccb725f0390f0116 | refs/heads/master | 2021-01-13T01:04:18.174115 | 2018-08-22T16:56:23 | 2018-08-22T16:56:23 | 49,767,583 | 0 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 9,317 | scm | pthreads.scm | ;; (C) 2010 Jörg F. Wittenberger
;;
;; Calling C functions in native threads and call back from PThreads
;; to Scheme.
;;
;; Now there is also an egg implementing the same. (Never touch a
;; running systems. I'll not try it any time soon.)
;; http://wiki.call-cc.org/eggref/4/concurrent-native-callbacks
(declare
;; optional
(disable-interrupts) ; checked
;; promises
;; (strict-types)
(unsafe)
(usual-integrations)
(fixnum-arithmetic)
(foreign-declare #<<EOF
#ifdef ___CHICKEN
typedef C_word obj;
#define FALSE_OBJ C_SCHEME_FALSE
#else
#include <rscheme/obj.h>
#endif
#include <stdio.h>
#include <stdlib.h>
#ifndef NO_THREAD_LOOP
#define THREAD_POOL_SIZE 5
#include <stdlib.h>
#include <pthread.h>
#include <errno.h>
typedef int (*C_pthread_request_function_t)(void *);
typedef struct _C_pthread_pool_entry {
C_pthread_request_function_t function;
void *data;
void *callback;
pthread_t thread;
} C_pthread_pool_entry_t;
struct C_pthread_pool {
pthread_mutex_t mutex;
pthread_cond_t has_job;
pthread_cond_t has_space;
unsigned short int total, next, free;
C_pthread_pool_entry_t *r;
};
static void *
worker_thread_loop(void *arg);
static void
C_pthread_pool_entry_init(struct C_pthread_pool * pool, C_pthread_pool_entry_t * r);
static int
C_pthread_pool_init(struct C_pthread_pool * pool)
{
int i;
pool->next = 0;
pool->total = pool->free = 50;
pthread_mutex_init(&pool->mutex, NULL);
pthread_cond_init(&pool->has_job, NULL);
pthread_cond_init(&pool->has_space, NULL);
pool->r = malloc(sizeof(C_pthread_pool_entry_t) * pool->total);
for (i = 0; i < pool->total; ++i) {
pool->r[i].function = NULL;
pool->r[i].data = NULL;
pool->r[i].callback = NULL;
}
for (i = 0; i < THREAD_POOL_SIZE; ++i) {
int e;
pthread_attr_t attr;
pthread_attr_init(&attr);
pthread_attr_setdetachstate(&attr, /* PTHREAD_CREATE_DETACHED */
PTHREAD_CREATE_JOINABLE);
e = pthread_create(&(pool->r[i].thread), &attr, worker_thread_loop, pool);
pthread_attr_destroy(&attr);
}
return 0;
}
static int
C_pthread_pool_send(struct C_pthread_pool * pool,
C_pthread_request_function_t function,
void *data,
void *callback)
{
C_pthread_pool_entry_t *result = NULL;
pthread_mutex_lock(&pool->mutex);
do {
if (pool->free) {
result = &pool->r[pool->next];
pool->next = (pool->next + 1) % pool->total;
--pool->free;
} else {
pthread_mutex_unlock(&pool->mutex);
return 1;
fprintf(stderr, "DANGER: chicken waiting on thread pool space\n");
pthread_cond_wait(&pool->has_space, &pool->mutex);
}
} while( result == NULL );
result->function = function;
result->data = data;
result->callback = callback;
pthread_mutex_unlock(&pool->mutex);
pthread_cond_signal(&pool->has_job);
return 0;
}
/* C_pthread_pool_put returns an entry into the queue (LI) and returns
* the result to rscheme. The latter is questionable, but we avoid to
* take yet another lock around the interpreter callback.
*/
static void
C_pthread_pool_receive(struct C_pthread_pool * pool,
C_pthread_request_function_t *function,
void **data,
void **callback)
{
C_pthread_pool_entry_t *result = NULL;
pthread_mutex_lock(&pool->mutex);
do {
if (pool->free != pool->total) {
unsigned short int target = (pool->next + pool->free) % pool->total;
result = &pool->r[target];
++pool->free;
*function = result->function;
*data = result->data;
*callback = result->callback;
} else {
pthread_cond_wait(&pool->has_job, &pool->mutex);
}
} while( result == NULL );
pthread_mutex_unlock(&pool->mutex);
pthread_cond_signal(&pool->has_space);
}
static struct C_pthread_pool *request_pool = NULL;
int
start_asynchronous_request(C_pthread_request_function_t function,
void *data, void *callback)
{
if( request_pool == NULL ) {
fprintf(stderr, "thread pool not initialised\n");
exit(1);
}
return C_pthread_pool_send(request_pool, function, data, callback);
}
static pthread_mutex_t callback_mutex;
static pthread_cond_t callback_free_cond;
#ifdef ___CHICKEN
static int the_interrupt_pipe[2] = {0, 0};
static void *the_callback = NULL;
static void *the_callback_result = NULL;
static C_word the_result = C_SCHEME_FALSE;
static void *integer_result = NULL;
void C_interrupt_call(void *callback, void *result, C_word value) {
static char buf[1] = { (char) 254 };
if( write(the_interrupt_pipe[1], buf, 1) < 0)
fprintf(stderr, "ERROR: sending interrupt to chicken failed\n");
pthread_mutex_lock(&callback_mutex);
while( the_callback != NULL ) {
#ifdef TRACE
fprintf(stderr, "wait for callback\n");
#endif
pthread_cond_wait(&callback_free_cond, &callback_mutex);
}
the_result = value;
the_callback_result = result;
the_callback = callback;
/* CHICKEN_interrupt(1); */
#ifdef TRACE
fprintf(stderr, "sig chick\n");
#endif
pthread_mutex_unlock(&callback_mutex);
pthread_cond_broadcast(&callback_free_cond);
}
static int C_chicken_interrupt_received()
{
the_callback = NULL;
#ifdef TRACE
fprintf(stderr, "chick sign\n");
#endif
pthread_mutex_unlock(&callback_mutex);
return pthread_cond_broadcast(&callback_free_cond);
}
static C_word C_receive_interrupt()
{
pthread_mutex_lock(&callback_mutex);
while( the_callback == NULL ) {
#ifdef TRACE
fprintf(stderr, "chicken wait for callback\n");
#endif
pthread_cond_wait(&callback_free_cond, &callback_mutex);
}
return CHICKEN_gc_root_ref(the_callback);
}
#endif
static void *
worker_thread_loop(void *arg)
{
struct C_pthread_pool *pool = arg;
C_pthread_request_function_t function = NULL;
void *data = NULL;
void *callback = NULL;
int result = 0;
// pthread_cleanup_push(worker_thread_unlock, ressources);
while (1) {
C_pthread_pool_receive(request_pool, &function, &data, &callback);
result = (*function)(data);
/* CHICKEN_interrupt(1); */
C_interrupt_call(callback, integer_result, result);
}
// pthread_cleanup_pop(1);
return NULL;
}
void
C_pthread_pre_init(void *intres)
{
pthread_mutex_init(&callback_mutex, NULL);
pthread_cond_init(&callback_free_cond, NULL);
request_pool = malloc(sizeof(struct C_pthread_pool));
C_pthread_pool_init(request_pool);
integer_result=intres;
#ifdef ___CHICKEN
if( pipe(the_interrupt_pipe) == -1 )
fprintf(stderr, "Failed to open interrupt pipe\n");
#endif
if(pthread_setschedprio(pthread_self(), sched_get_priority_max(sched_getscheduler(0)))) {
fprintf(stderr, "Failed to raise main thread priority.\n");
}
}
#else /* NO_THREAD_LOOP */
typedef int (*C_pthread_request_function_t)(void *);
int
start_asynchronous_request(C_pthread_request_function_t function,
void *data, void *callback){}
void
C_pthread_pre_init(void *intres)
{
fprintf(stderr, "thread pool not initialised\n");
}
#endif
/*
int
test_C_pthread_thread_sleep(void *data)
{
int time = (int) data;
sleep(time);
return time;
}
*/
EOF
)
)
(module
pthreads
(
pool-send!
external-wait ;; undocumented may be removed
)
(import scheme)
(cond-expand
(chicken-5
(import (chicken base)
(chicken foreign)
(chicken type)
(chicken fixnum)
srfi-18))
(else
(import chicken foreign)
(use srfi-18)))
(: pool-send! (pointer pointer pointer -> undefined))
;; procedure data callback-gc-root
(define pool-send!
(foreign-lambda
void "start_asynchronous_request"
nonnull-c-pointer nonnull-c-pointer nonnull-c-pointer))
;; (import (only atomic make-semaphore set-open-fd!))
(define-syntax set-open-fd! (syntax-rules () ((_ x y) #f)))
(define make-gc-root
(foreign-lambda*
c-pointer ((scheme-object obj))
"C_GC_ROOT *r=CHICKEN_new_gc_root();"
"CHICKEN_gc_root_set(r, obj);"
"return(r);"))
(define interrupt-callback (foreign-lambda scheme-object "C_receive_interrupt"))
(define callback-result (foreign-lambda* int ((c-pointer result)) "C_return(* (int *) result);"))
(define callback-result-root (make-gc-root callback-result))
((foreign-lambda* void ((c-pointer f)) "C_pthread_pre_init(f);")
callback-result-root)
(define (handle-callback)
(let ((cb (interrupt-callback)))
(if (procedure? cb)
(let ((converter
(foreign-value "CHICKEN_gc_root_ref(the_callback_result)" scheme-object)))
(if (procedure? converter)
(let ((rc (converter (foreign-value "&the_result" c-pointer))))
(foreign-code "C_chicken_interrupt_received();")
(thread-start! (make-thread (lambda () (cb rc)) 'handle-callback)))
(begin
(foreign-code "fprintf(stderr, \"Ignored callback no converter procedure -- does this mess up things?\\n\");exit(1);")
)))
(foreign-code "fprintf(stderr, \"Ignored callback -- does this mess up things?\\n\");"))) )
(define external-wait
(thread-start!
(make-thread
(lambda ()
(let ((fd ((foreign-lambda* int () "C_return(the_interrupt_pipe[0]);"))))
(set-open-fd! fd '(pipe input interrupt-pipe))
;;(##sys#file-nonblocking! fd)
(do ()
(#f)
(thread-wait-for-i/o! fd #:input)
(if (fx= ((foreign-lambda*
int ()
"static int buf[1]; int r = read(the_interrupt_pipe[0], buf, 1); return(r);"))
1)
(handle-callback)))))
"external-wait")))
) ;; module pthreads
| true |
681c8b767c250021d26fdbd40109e82c1beee4fd | 9face33c879099287ece1b2c75d1b462b9efe565 | /etc/aritmetica-com-listas.scm | c9a5098e7336ee3a89352bf2e6f3272e2111fddf | [] | no_license | ramalho/mac316 | ebf02aba99c67d58a1a23f8852e8c41d4b4fb101 | 4c925557064c788c4d29e3408a6b1d327386d98b | refs/heads/master | 2020-05-31T18:14:31.154370 | 2009-06-17T19:57:06 | 2009-06-17T19:57:06 | 156,354 | 2 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 1,099 | scm | aritmetica-com-listas.scm | ;; The first three lines of this file were inserted by DrScheme. They record metadata
;; about the language level of this file in a form that our tools can easily process.
#reader(lib "reader.ss" "plai" "lang")
(define zero '())
(define (incr n)
(cons #t n))
(define um (incr zero))
(define dois (incr um))
(define tres (incr dois))
(define cinco (incr (incr tres)))
(define (decr n)
(cdr n))
(define (+ a b)
(if (null? b)
a
(+ (incr a) (decr b))))
(define (- a b)
(if (null? b)
a
(- (decr a) (decr b))))
(define (* a b)
(if (null? b)
'()
(+ a (* a (decr b)))))
(define (^ a b)
(if (null? b)
um
(* a (^ a (decr b)))))
(define (exibir expr val)
(display expr)
(display " = ")
(display (length val))
(newline)
)
(exibir '(+ dois tres) (+ dois tres))
(exibir '(- cinco tres) (- cinco tres))
(exibir '(* tres dois) (* tres dois))
(exibir '(* cinco (* cinco (* cinco cinco))) (* cinco (* cinco (* cinco cinco))))
(exibir '(^ tres dois) (^ tres dois))
(exibir '(^ dois cinco) (^ dois cinco))
(exibir '(^ cinco um) (^ cinco um)) | false |
c3286bd3855b94df50214140b79d6dbef14edde6 | fae4190f90ada065bc9e5fe64aab0549d4d4638a | /typed-scheme-lti/private/base-env.ss | 4c243001b91e8c70efadb527b65706f12c12d977 | [] | no_license | ilya-klyuchnikov/old-typed-racket | f161481661a2ed5cfc60e268f5fcede728d22488 | fa7c1807231f447ff37497e89b25dcd7a9592f64 | refs/heads/master | 2021-12-08T04:19:59.894779 | 2008-04-13T10:54:34 | 2008-04-13T10:54:34 | null | 0 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 20,326 | ss | base-env.ss | (module base-env mzscheme
(require-for-template (only (lib "list.ss") foldl)
mzscheme
(prefix 660: (file "../optimize/csu660.ss"))
(file "../optimize/utils.ss")
#%paramz
#%more-scheme
#%qq-and-or
(lib "match-error.ss" "mzlib" "private" "match")
)
(require
"extra-procs.ss"
(all-except "type-rep.ss" make-arr)
(only (lib "list.ss") foldl)
"type-effect-convenience.ss"
(rename "type-effect-convenience.ss" make-arr make-arr*)
"union.ss"
(lib "match-error.ss" "mzlib" "private" "match")
"tc-structs.ss")
(require-for-syntax
"init-envs.ss"
(all-except "type-rep.ss" make-arr)
(only (lib "list.ss") foldl)
"type-effect-convenience.ss"
(rename "type-effect-convenience.ss" make-arr make-arr*)
"union.ss"
(lib "match-error.ss" "mzlib" "private" "match")
"tc-structs.ss")
(define-for-syntax (initialize-others)
(tc/builtin-struct #'date
#f
(list #'second #'minute #'hour #'day #'month #'year #'week-day #'year-day #'dst? #'time-zone-offset)
(list N N N N N N N N B N)
null)
(tc/builtin-struct #'exn
#f
(list #'message #'continuation-marks)
(list -String Univ)
null)
(tc/builtin-struct #'exn:fail
#'exn
null
null
(list -String Univ))
(tc/builtin-struct #'exn:fail:read
#'exn:fail
(list #'srclocs)
(list (-lst Univ))
(list -String Univ)))
(provide-for-syntax initial-env initialize-others)
(define-for-syntax initial-env
(let ([make-lst make-Listof]
[make-lst/elements -pair])
(make-env
(car (make-Poly (list 'a 'b) (cl-> [((-pair (-v a) (-v b))) (-v a)]
[((make-lst (-v a))) (-v a)])))
(cadr
(-poly (a b c)
(cl->
[((-pair a (-pair b c))) b]
[((-lst a)) a])))
(caddr (-poly (a) (-> (-lst a) a)))
(cadddr (-poly (a) (-> (-lst a) a)))
(cdr (make-Poly (list 'a 'b) (cl-> [((-pair (-v a) (-v b))) (-v b)]
[((make-lst (-v a))) (make-lst (-v a))])))
(cddr (make-Poly (list 'a) (-> (make-lst (-v a)) (make-lst (-v a)))))
(cdddr (make-Poly (list 'a) (-> (make-lst (-v a)) (make-lst (-v a)))))
(cons (-poly (a b)
(cl-> [(a (-lst a)) (-lst a)]
[(a b) (-pair a b)])))
(null? (make-pred-ty (-val null)))
(eof-object? (make-pred-ty (-val eof)))
[null (-val null)]
(number? (make-pred-ty N))
(boolean? (make-pred-ty B))
(add1 (-> N N))
(sub1 (-> N N))
(eq? (-> Univ Univ B))
(eqv? (-> Univ Univ B))
(equal? (-> Univ Univ B))
(even? (-> N B))
[assert (-poly (a) (-> (*Un a (-val #f)) a))]
[gensym (cl-> [(Sym) Sym]
[() Sym])]
[string-append (->* null -String -String)]
[open-input-string (-> -String -Input-Port)]
[open-output-file
(cl->
[(-Pathlike) -Port]
[(-Pathlike Sym) -Port])]
[read (cl->
[(-Port) -Sexp]
[() -Sexp])]
[ormap (-poly (a b) ((-> a b) (-lst a) . -> . b))]
[andmap (-poly (a b) ((-> a b) (-lst a) . -> . b))]
[newline (cl-> [() -Void]
[(-Port) -Void])]
[not (-> Univ B)]
[floor (-> N N)]
[cons? (make-pred-ty (-pair Univ Univ))]
[pair? (make-pred-ty (-pair Univ Univ)) #;(-poly (a b) (make-pred-ty (-pair a b)))]
[empty? (make-pred-ty (-val null))]
[empty (-val null)]
[string? (make-pred-ty -String)]
[symbol? (make-pred-ty Sym)]
[list? (make-pred-ty (-lst Univ))]
[list (-poly (a) (->* '() a (-lst a)))]
[procedure? (make-pred-ty (->* '() (Un) Univ))]
[map
(-poly (a b c d)
(cl-> [((-> a b) (-lst a)) (-lst b)]
[((-> a b c) (-lst a) (-lst b)) (-lst c)]
[((-> a b c d) (-lst a) (-lst b) (-lst c)) (-lst d)]))]
[for-each
(-poly (a b c)
(cl-> [((-> a b) (-lst a)) -Void]
[((-> a b c) (-lst a) (-lst b)) -Void]))]
[foldl (make-Poly '(a b)
(-> (-> (-v a) (-v b) (-v b)) (-v b) (make-lst (-v a)) (-v b)))]
[call-with-values (-poly (a b) (-> (-> a) (-> a b) b))]
(error
(make-Function (list
(make-arr null (Un))
(make-arr (list Sym -String) (Un) Univ)
(make-arr (list -String) (Un) Univ)
(make-arr (list Sym) (Un)))))
[integer? (Univ . -> . B)]
[namespace-variable-value
(cl->
[(Sym) Univ]
[(Sym B -Namespace (-> Univ)) Univ])]
(match:error (Univ . -> . (Un)))
(display
(cl->
[(Univ) -Void]
[(Univ -Port) -Void]))
[void (->* '() Univ -Void)]
[void? (make-pred-ty -Void)]
[printf (->* (list -String) Univ -Void)]
[fprintf (->* (list -Output-Port -String) Univ -Void)]
[format (->* (list -String) Univ -String)]
(fst (make-Poly (list 'a 'b) (-> (make-lst/elements (-v a) (-v b)) (-v a))))
(snd (make-Poly (list 'a 'b) (-> (make-lst/elements (-v a) (-v b)) (-v b))))
(= (->* (list N N) N B))
(>= (->* (list N N) N B))
(< (->* (list N N) N B))
(<= (->* (list N N) N B))
[> (->* (list N) N B)]
(zero? (N . -> . B))
(* (->* '() N N))
(/ (->* (list N) N N))
(+ (->* '() N N))
(- (->* (list N) N N))
(max (->* (list N) N N))
(min (->* (list N) N N))
[values (make-Poly '(a) (-> (-v a) (-v a)))]
[vector-ref
(make-Poly (list 'a) ((make-Vector (-v a)) N . -> . (-v a)))]
[build-vector (make-Poly (list 'a) (N (N . -> . (-v a)) . -> . (make-Vector (-v a))))]
[reverse (make-Poly '(a) (-> (make-lst (-v a)) (make-lst (-v a))))]
[append (-poly (a) (->* (list) (-lst a) (-lst a)))]
[length (make-Poly '(a) (-> (make-lst (-v a)) N))]
[memq (make-Poly (list 'a) (-> (-v a) (make-lst (-v a)) (-opt (make-lst (-v a)))))]
[memv (make-Poly (list 'a) (-> (-v a) (make-lst (-v a)) (-opt (make-lst (-v a)))))]
[member
(-poly (a) (a (-lst a) . -> . (-opt (-lst a))))]
[string<? (->* (list -String -String) -String B)]
[string>? (->* (list -String -String) -String B)]
[string=? (->* (list -String -String) -String B)]
[string<=? (->* (list -String -String) -String B)]
[string>=? (->* (list -String -String) -String B)]
[string-ci<? (->* (list -String -String) -String B)]
[string-ci>? (->* (list -String -String) -String B)]
[string-ci=? (->* (list -String -String) -String B)]
[string-ci<=? (->* (list -String -String) -String B)]
[string-ci>=? (->* (list -String -String) -String B)]
[string-upcase (-> -String -String)]
[string-downcase (-> -String -String)]
[string-titlecase (-> -String -String)]
[string-foldcase (-> -String -String)]
[string-normalize-nfd (-> -String -String)]
[string-normalize-nfkd (-> -String -String)]
[string-normalize-nfc (-> -String -String)]
[string-normalize-nfkc (-> -String -String)]
[assq (-poly (a) (-> Univ (-lst (-pair Univ a)) a))]
[build-path ((list -Pathlike*) -Pathlike* . ->* . -Path)]
[string->number (-> -String (-opt N))]
[with-input-from-file
(-poly (a)
(cl->
[(-Pathlike (-> a)) a]
[(-Pathlike (-> a) Sym) a]))]
[with-output-to-file
(-poly (a)
(cl->
[(-Pathlike (-> a)) a]
[(-Pathlike (-> a) Sym) a]))]
[random (cl->
[(N) N]
[() N])]
[assoc (-poly (a b) (a (-lst (-pair a b)) . -> . (-opt (-pair a b))))]
[list-ref (-poly (a) ((-lst a) N . -> . a))]
[positive? (-> N B)]
[negative? (-> N B)]
[odd? (-> N B)]
[even? (-> N B)]
[apply (-poly (a b) (((list) a . ->* . b) (-lst a) . -> . b))]
[call/cc (-poly (a b) (((a . -> . (Un)) . -> . b) . -> . (*Un a b)))]
[call/ec (-poly (a b) (((a . -> . (Un)) . -> . b) . -> . (*Un a b)))]
[quotient (N N . -> . N)]
[remainder (N N . -> . N)]
[quotient/remainder (N N . -> . (-values (list N N)))]
;; parameter stuff
[parameterization-key Sym]
[extend-parameterization (-poly (a b) (-> Univ (-Param a b) a Univ))]
[continuation-mark-set-first (-> (-opt -Cont-Mark-Set) Univ Univ)]
[make-parameter (-poly (a b) (cl-> [(a) (-Param a a)]
[(b (a . -> . b)) (-Param a b)]))]
[current-directory (-Param -Pathlike -Path)]
[current-namespace (-Param -Namespace -Namespace)]
[print-struct (-Param B B)]
[read-decimal-as-inexact (-Param B B)]
[current-command-line-arguments (-Param (make-Vector -String) (make-Vector -String))]
;; regexp stuff
[regexp-match
(cl->
[((*Un -String -Regexp) -String) (-opt (-lst (-opt -String)))]
[(-Pattern -String) (-opt (-lst (-opt (*Un -Bytes -String))))]
[(-Pattern -String N) (-opt (-lst (-opt (*Un -Bytes -String))))]
[(-Pattern -String N (-opt N)) (-opt (-lst (-opt (*Un -Bytes -String))))]
[(-Pattern -String N (-opt N) (-opt -Output-Port)) (-lst (-opt (*Un -Bytes -String)))]
[(-Pattern -String (-opt N) (-opt -Output-Port)) (-lst (-opt (*Un -Bytes -String)))]
[(-Pattern -String (-opt -Output-Port)) (-lst (-opt (*Un -Bytes -String)))]
[(-Pattern (*Un -Input-Port -Bytes)) (-opt (-lst (-opt -Bytes)))]
[(-Pattern (*Un -Input-Port -Bytes) N) (-opt (-lst (-opt -Bytes)))]
[(-Pattern (*Un -Input-Port -Bytes) N (-opt N)) (-opt (-lst (-opt -Bytes)))]
[(-Pattern (*Un -Input-Port -Bytes) (-opt N)) (-opt (-lst (-opt -Bytes)))]
[(-Pattern (*Un -Input-Port -Bytes) N (-opt N) (-opt -Output-Port)) (-lst (-opt -Bytes))])]
[number->string (N . -> . -String)]
[current-milliseconds (-> N)]
[modulo (N N . -> . N)]
;; errors
[raise-type-error
(cl->
[(Sym -String Univ) (Un)]
[(Sym -String N (-lst Univ)) (Un)])]
;; this is a hack
[match:error ((list) Univ . ->* . (Un))]
[vector-set! (-poly (a) (-> (make-Vector a) N a -Void))]
[vector->list (-poly (a) (-> (make-Vector a) (-lst a)))]
[list->vector (-poly (a) (-> (-lst a) (make-Vector a)))]
[exact? (N . -> . B)]
[inexact? (N . -> . B)]
[expt (N N . -> . N)]
[vector (-poly (a) (->* (list) a (make-Vector a)))]
[real? (Univ . -> . B)]
[real-part (N . -> . N)]
[imag-part (N . -> . N)]
[magnitude (N . -> . N)]
[angle (N . -> . N)]
[numerator (N . -> . N)]
[denominator (N . -> . N)]
[exact->inexact (N . -> . N)]
[inexact->exact (N . -> . N)]
[make-string
(cl->
[(N) -String]
[(N -Char) -String])]
[arithmetic-shift (N N . -> . N)]
[abs (N . -> . N)]
[substring (cl-> [(-String N) -String]
[(-String N N) -String])]
[string-length (-String . -> . N)]
[string-set! (-String N -Char . -> . -Void)]
[make-vector
(-poly (a)
(cl->
[(N) (make-Vector N)]
[(N a) (make-Vector a)]))]
[file-exists? (-Pathlike . -> . B)]
[string->symbol (-String . -> . Sym)]
[symbol->string (Sym . -> . -String)]
[vector-length (-poly (a) ((make-Vector a) . -> . N))]
[call-with-input-file (-poly (a)
(cl->
[(-String (-Port . -> . a)) a]
[(-String (-Port . -> . a) Sym) a]))]
[call-with-output-file (-poly (a)
(cl->
[(-String (-Port . -> . a)) a]
[(-String (-Port . -> . a) Sym) a]))]
[current-output-port (-Param -Output-Port -Output-Port)]
[current-error-port (-Param -Output-Port -Output-Port)]
[current-input-port (-Param -Input-Port -Input-Port)]
[round (N . -> . N)]
[seconds->date (N . -> . (make-Struct 'date #f (list N N N N N N N N B N) #f))]
[current-seconds (-> N)]
[sqrt (-> N N)]
[path->string (-> -Path -String)]
[link-exists? (-> -Pathlike B)]
[directory-exists? (-> -Pathlike B)]
[file-exists? (-> -Pathlike B)]
[directory-list (cl-> [() (-lst -Path)]
[(-Path) (-lst -Path)])]
[make-hash-table (let ([ht-opt (*Un (-val 'weak) (-val 'equal))])
(-poly (a b)
(cl-> [() (-HT a b)]
[(ht-opt) (-HT a b)]
[(ht-opt ht-opt) (-HT a b)])))]
[hash-table-put! (-poly (a b) ((-HT a b) a b . -> . -Void))]
[hash-table-map (-poly (a b c) ((-HT a b) (a b . -> . c) . -> . (-lst c)))]
[hash-table-get (-poly (a b c)
(cl->
(((-HT a b) a) b)
(((-HT a b) a (-> c)) (*Un b c))
(((-HT a b) a c) (*Un b c))))]
#;[hash-table-index (-poly (a b) ((-HT a b) a b . -> . -Void))]
[bytes (->* (list) N -Bytes)]
[bytes-ref (-> -Bytes N N)]
[bytes-append (->* (list -Bytes) -Bytes -Bytes)]
[subbytes (cl->
[(-Bytes N) -Bytes]
[(-Bytes N N) -Bytes])]
[bytes-length (-> -Bytes N)]
[open-input-file (-> -Pathlike -Input-Port)]
[close-input-port (-> -Input-Port -Void)]
[close-output-port (-> -Output-Port -Void)]
[read-line (cl->
[() -String]
[(-Input-Port) -String]
[(-Input-Port Sym) -String])]
[copy-file (-> -Pathlike -Pathlike -Void)]
[bytes->string/utf-8 (-> -Bytes -String)]
;; make-promise #;
[(cadr (syntax->list (expand #'(delay 3)))) (-poly (a) (-> (-> a) (-Promise a)))]
;; qq-append #;
[(cadr (syntax->list (expand #'`(,@'())))) (-poly (a b)
(cl->*
(-> (-lst a) (-val '()) (-lst a))
(-> (-lst a) (-lst b) (-lst (*Un a b)))))]
[force (-poly (a) (-> (-Promise a) a))]
[bytes<? (->* (list -Bytes) -Bytes B)]
[regexp-replace*
(cl->*
(-Pattern (*Un -Bytes -String) (*Un -Bytes -String) . -> . -Bytes)
(-Pattern -String -String . -> . -String))]
[peek-char
(cl->*
[-> -Char]
[-Input-Port . -> . -Char]
[-Input-Port N . -> . -Char]
[N . -> . -Char])]
[peek-byte
(cl->*
[-> -Byte]
[-Input-Port . -> . -Byte]
[-Input-Port N . -> . -Byte]
[N . -> . -Byte])]
[make-pipe
(cl->*
[-> (-values (list -Input-Port -Output-Port))]
[N . -> . (-values (list -Input-Port -Output-Port))])]
[open-output-bytes
(cl->*
[-> -Output-Port]
[Univ . -> . -Output-Port])]
[get-output-bytes
(cl->*
[-Output-Port . -> . -Bytes]
[-Output-Port Univ . -> . -Bytes]
[-Output-Port Univ N . -> . -Bytes]
[-Output-Port Univ N N . -> . -Bytes]
[-Output-Port N . -> . -Bytes]
[-Output-Port N N . -> . -Bytes])]
#;[exn:fail? (-> Univ B)]
#;[exn:fail:read? (-> Univ B)]
[write (-> -Sexp -Void)]
[open-output-string (-> -Output-Port)]
;; FIXME - wrong
[get-output-string (-> -Output-Port -String)]
[make-directory (-> -Path -Void)]
[hash-table-for-each (-poly (a b c)
(-> (-HT a b) (-> a b c) -Void))]
[delete-file (-> -Pathlike -Void)]
[make-namespace (cl->* (-> -Namespace)
(-> (*Un (-val 'empty) (-val 'initial)) -Namespace))]
[eval (-> -Sexp Univ)]
[exit (-> (Un))]
)))
(begin-for-syntax (initialize-type-env initial-env)
(initialize-others))
;; the initial type name environment - just the base types
(define-syntax (define-tname-env stx)
(syntax-case stx ()
[(_ var provider [nm ty] ...)
#`(begin
(define-syntax nm (lambda (stx) (raise-syntax-error 'type-check "type name used out of context" stx))) ...
(provide nm) ...
(define-syntax provider (lambda (stx) #'(begin (provide nm) ...)))
(provide provider)
(begin-for-syntax
(initialize-type-name-env
(list (list #'nm ty) ...))))]))
(define-syntax (define-other-types stx)
(syntax-case stx ()
[(_ provider requirer nm ...)
(with-syntax ([(nms ...) (generate-temporaries #'(nm ...))])
(let ([body-maker (lambda (stx)
(map (lambda (nm nms) (datum->syntax-object stx `(rename ,#'mod ,nm ,nms)))
(syntax->list #'(nm ...))
(syntax->list #'(nms ...))))])
#'(begin (define-syntax nms (lambda (stx) (raise-syntax-error 'type-check "type name used out of context" stx))) ...
(provide nms) ...
(define-syntax (requirer stx)
(syntax-case stx ()
[(_ mod)
(datum->syntax-object
stx
`(require . ,(map (lambda (nm* nms*) (datum->syntax-object stx `(rename ,#'mod ,nm* ,nms*)))
(list 'nm ...)
(list #'nms ...))))]))
(define-syntax provider (lambda (stx) #'(begin (provide (rename nms nm)) ...)))
(provide provider requirer))))]))
;; the initial set of available type names
(define-tname-env initial-type-names provide-tnames
[Number N]
[Void -Void]
[Boolean B]
[Symbol Sym]
[String -String]
[Any Univ]
[Port -Port]
[Path -Path]
[num-exp -NE]
[Regexp -Regexp]
[PRegexp -PRegexp]
[Char -Char]
[Option (-poly (a) (-opt a))]
[Sexp -Sexp]
[List (-lst Univ)]
[Listof -Listof]
[Namespace -Namespace]
[Input-Port -Input-Port]
[Output-Port -Output-Port]
[Bytes -Bytes]
[EOF (-val eof)]
[Keyword -Keyword]
[HashTable (-poly (a b) (-HT a b))]
[Promise (-poly (a) (-Promise a))]
[Pair (-poly (a b) (-pair a b))]
#;[Parameter -Param]
;; legacy abbreviations
[top Univ]
[str -String]
[number N]
[boolean B]
[symbol Sym]
[list-of -Listof]
)
(define-other-types
provide-extra-tnames
require-extra-tnames
-> U mu Un All Opaque Vectorof
Parameter Tuple
)
(provide-extra-tnames)
) | true |
333e7df9cad76e4ede4608829c6a937b8c86107d | 6b288a71553cf3d8701fe7179701d100c656a53c | /examples/template.ss | 5aa61616502b2ba14ad519d9cd0222f51a466813 | [
"Apache-2.0"
] | permissive | cisco/ChezScheme | 03e2edb655f8f686630f31ba2574f47f29853b6f | c048ad8423791de4bf650fca00519d5c2059d66e | refs/heads/main | 2023-08-26T16:11:15.338552 | 2023-08-25T14:17:54 | 2023-08-25T14:17:54 | 56,263,501 | 7,763 | 1,410 | Apache-2.0 | 2023-08-28T22:45:52 | 2016-04-14T19:10:25 | Scheme | UTF-8 | Scheme | false | false | 37,700 | ss | template.ss | #!chezscheme
;;; Copyright 1984-2017 Cisco Systems, Inc.
;;;
;;; Licensed under the Apache License, Version 2.0 (the "License");
;;; you may not use this file except in compliance with the License.
;;; You may obtain a copy of the License at
;;;
;;; http://www.apache.org/licenses/LICENSE-2.0
;;;
;;; Unless required by applicable law or agreed to in writing, software
;;; distributed under the License is distributed on an "AS IS" BASIS,
;;; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
;;; See the License for the specific language governing permissions and
;;; limitations under the License.
;;; include-template: a simple yet powerful extensible templating mechanism
;;;
;;; Authors: Andrew W. Keep and R. Kent Dybvig
;;;
;;; The syntax (include-template <filename>) expands into an expression whose
;;; value is a string containing the contents of the file named by <filename>,
;;; except each occurrence of @@ within the file is replaced by @, and each
;;; occurrence of @(<scheme expression>) is replaced with the value of
;;; <scheme expression>. <filename> must be a string literal, and the value
;;; of each <scheme expression> must be a string. The file named by <filename>
;;; must be present at expand time and need not be present at run time.
;;;
;;; The template system can also be extended using the syntax:
;;;
;;; (define-template-extension <template-pattern> <output-pattern>)
;;;
;;; where:
;;;
;;; <template-pattern> -> (<initial-pattern> <additional-pattern>*)
;;; | <non-template-pattern>
;;; <initial-pattern> -> <keyword> (<syntax-pattern>*) <template-id>
;;; | <keyword> <template-id>
;;; <additional-pattern> -> <initial-pattern>
;;; | (<keyword> (<syntax-pattern>*) <template-id>) ...
;;; | (<keyword> <template-id>) ...
;;; | (optional <keyword> (<syntax-pattern>*)
;;; <template-id>)
;;; | (optional <keyword> <template-id>)
;;; <non-template-pattern> -> <keyword> (<syntax-pattern>*)
;;; <keyword> -> <initial-kw-character> <kw-character>
;;; <initial-kw-character> -> a - z | A - Z | ! | $ | % | & | * | / | : | <
;;; | = | > | ? | ^ | _ | ~
;;; <kw-character> -> <initial-kw-character> | 0 - 9 | - | + | .
;;;
;;; <output-pattern> is treated as a quasisyntax template,
;;; <syntax-pattern> is a syntax-rules pattern and,
;;; <template-id> is any valid scheme identifier.
;;;
;;; For <template-patterns> using a <non-template-pattern> a new @<keyword>
;;; form is created and when the @<keyword>(<syntax-pattern>*) is encountered
;;; in a template, it is immediately replaced with the <output-pattern>.
;;;
;;; For instance an extension that converts numbers to strings can be
;;; implemented as:
;;;
;;; (define-template-extension (num (e)) (number->string e))
;;;
;;; When @num(10) is encountered in a template, the string "10" is generated.
;;;
;;; For <template-patterns> with an <inital-pattern> each <keyword> in the
;;; <template-pattern> the define-template-extension will create a new syntax
;;; form @<keyword> along with an @end<keyword> for the <keyword> from the
;;; <initial-pattern>. When include-template encounters an
;;; @<initial-keyword> ... @end<initial-keyword> pattern it will match the
;;; <syntax-pattern>* (when supplied) against the following scheme expression
;;; and match the template expressions found between the @<keywords> to the
;;; matching <template-id> bindings.
;;;
;;; For example, we can add a "for" loop extension as:
;;;
;;; (define-template-extension (for ([x e] [xs es] ...) tmpl)
;;; (let ([t e])
;;; (apply string-append (map (lambda (x xs ...) tmpl) t es ...))))
;;;
;;; (for (exprs ...) tmpl)
;;; =>
;;; @for (lambda (...)
;;; (let ([t (read-scheme k...)])
;;; (cons (incomplete-node @for t) ...)))
;;; @endfor (lambda (...)
;;; ---
;;; (let loop ([t '()] [tmpl '()] ...)
;;; (cond
;;; [(and (incomplete-node? (car stack)) (eq? (incomplete-node-kw (car stack)) '@for))
;;; (with-syntax (['([x e] [xs es] ...) (incomplete-node-stx (car stack))])
;;; '(let ([t e])
;;; (apply string-append (map (lambda (x xs ...) tmpl) t es ..))))
;;;
;;; In a template if: @for([x '("a" "b" "c")]) got @(t). @endfor
;;; is encountered, it will print the string " got a. got b. got c. " for
;;; this expression (which will be produced by the code:
;;; (apply string-append
;;; (map (lambda (x) (string-append " got " x ". ") '("a" "b" "c"))))
;;;
;;; For a more complex example see the @if/@elif/@else/@endif example at
;;; the end of the library.
;;;
;;; Additional examples are embedded within the tests below #!eof.
;;; The (template-helpers) library supplies scheme procedures that are used at
;;; macro-expansion time by both the include-template and
;;; define-template-extension macros.
(library (template-helpers)
(export
incomplete-node? make-incomplete-node
incomplete-node-type incomplete-node-e* incomplete-node-bfp
source-string source-error
read-scheme initial-id-char? id-char?
make-string-buffer extend-string-buffer! extract-string-and-reset!
open-positional-string-output-port
strip-blanks)
(import (chezscheme))
(define (source-string sfd bfp)
(call-with-values
(lambda () (locate-source sfd bfp))
(case-lambda
[() (format "at char position ~s of ~a" bfp
(source-file-descriptor-path sfd))]
[(path lp cp) (format "at line ~s, char ~s of ~a" lp cp
(source-file-descriptor-path sfd))])))
(define (source-error sfd bfp msg . args)
(errorf 'include-template "~? ~a" msg args (source-string sfd bfp)))
(define (read-scheme k ip sfd bfp)
(let-values ([(x new-bfp) (get-datum/annotations ip sfd bfp)])
(let ([x (if (annotation? x) (annotation-expression x) x)])
(values (datum->syntax k x) new-bfp))))
(define-record-type incomplete-node (nongenerative) (fields type e* bfp))
(define (initial-id-char? c)
(or (char<=? #\a c #\z) (char<=? #\A c #\Z)
(char=? c #\!) (char<=? #\$ c #\&)
(char=? c #\*) (char=? c #\/)
(char=? c #\:) (char<=? #\< c #\?)
(char=? c #\^) (char=? c #\_) (char=? c #\~)))
(define (id-char? c)
(or (initial-id-char? c) (char<=? #\0 c #\9)
(char=? c #\-) (char=? c #\+) (char=? c #\.)))
(define-record-type string-buffer (nongenerative)
(fields (mutable n) (mutable str))
(protocol (lambda (new) (lambda () (new 0 (make-string 16))))))
(define (get-buffer tb n required-capacity)
(let* ([str (string-buffer-str tb)] [len (string-length str)])
(if (fx< (fx- len n) required-capacity)
(let ([new-str (make-string (fx* 2 (fx+ len required-capacity)))])
(string-copy! str 0 new-str 0 n)
(string-buffer-str-set! tb new-str)
new-str)
str)))
(define (extend-string-buffer! tb c)
(let ([n (string-buffer-n tb)])
(string-set! (get-buffer tb n 1) n c)
(string-buffer-n-set! tb (fx+ n 1))))
(define (append-to-string-buffer! tb str)
(let ([n (string-buffer-n tb)] [len (string-length str)])
(string-copy! (get-buffer tb n len) n str 0 len)
(string-buffer-n-set! tb (fx+ n len))))
(define (extract-string-and-reset! tb)
(let ([str (substring (string-buffer-str tb) 0 (string-buffer-n tb))])
(string-buffer-n-set! tb 0)
str))
(define (open-positional-string-output-port)
(define-record-type position (nongenerative)
(fields (mutable line) (mutable column))
(protocol (lambda (new) (lambda () (new 1 1)))))
(let ([tb (make-string-buffer)] [pos (make-position)])
(define (w! str start cnt)
(let* ([n (string-buffer-n tb)]
[buf (get-buffer tb n cnt)]
[end (fx+ start cnt)])
(let loop! ([i start] [n n] [line (position-line pos)] [column (position-column pos)])
(if (fx= i end)
(begin
(position-line-set! pos line)
(position-column-set! pos column)
(string-buffer-n-set! tb n))
(let ([c (string-ref str i)])
(string-set! buf n c)
(if (char=? c #\newline)
(loop! (fx+ i 1) (fx+ n 1) (fx+ line 1) 1)
(loop! (fx+ i 1) (fx+ n 1) line (fx+ column 1)))))))
cnt)
(define (gp) (string-buffer-n tb))
(let ([op (make-custom-textual-output-port "positional-string-output-port" w! gp #f #f)])
(define (line) (flush-output-port op) (position-line pos))
(define (column) (flush-output-port op) (position-column pos))
(define (p) (flush-output-port op) (extract-string-and-reset! tb))
(values op p line column))))
;; scan forward for blanks, and if it leads you to a new-line, strip
;; the previous blanks back to the new line.
(define (finish-strip ip stack bfp start-bfp)
(let ([node-to-strip (car stack)])
(if (string? node-to-strip)
(let loop ([i (string-length node-to-strip)])
(if (fx= i 0)
(values (cdr stack) bfp)
(let ([i (fx- i 1)])
(let ([c (string-ref node-to-strip i)])
(cond
[(char=? c #\newline)
(values (cons (substring node-to-strip 0 (fx+ i 1)) (cdr stack)) bfp)]
[(char-whitespace? c) (loop i)]
[else (set-port-position! ip start-bfp) (values stack start-bfp)])))))
(begin (set-port-position! ip start-bfp) (values stack start-bfp)))))
(define (strip-blanks ip stack start-bfp)
(let gather-blanks ([bfp start-bfp])
(let ([c (read-char ip)])
(cond
[(eof-object? c) (finish-strip ip stack bfp start-bfp)]
[(char=? c #\newline) (finish-strip ip stack (fx+ bfp 1) start-bfp)]
[(char-whitespace? c) (gather-blanks (fx+ bfp 1))]
[else (set-port-position! ip start-bfp) (values stack start-bfp)])))))
(library (template)
(export include-template define-template-extension optional @if @elif @else @endif @for @endfor @num)
(import (chezscheme) (template-helpers))
(define-syntax optional (lambda (x) (syntax-violation #f "misplaced aux keyword" x)))
(define check-string-and-indent
(lambda (s at indent)
(unless (string? s)
(errorf 'include-template "unexpected non-string value ~s of expression ~s" s at))
(if (= indent 0)
s
(let ([ip (open-string-input-port s)])
(let ([first-line (get-line ip)])
(if (eof-object? first-line)
s
(let-values ([(op p) (open-string-output-port)])
(display first-line op)
(let ([indent (make-string indent #\space)])
(let loop ()
(let ([line (get-line ip)])
(if (eof-object? line)
(begin
(when (char=? (string-ref s (fx- (string-length s) 1)) #\newline) (newline op))
(p))
(begin
(newline op)
(display indent op)
(display line op)
(loop)))))))))))))
(define-syntax include-template
(lambda (x)
(define (process-template-file r fn k)
(let* ([bip (open-file-input-port fn)]
[sfd (make-source-file-descriptor fn bip #t)]
[ip (transcoded-port bip (native-transcoder))]
[tb (make-string-buffer)])
(define (s0 a bfp)
(let ([c (read-char ip)])
(cond
[(eof-object? c)
(close-input-port ip)
(reverse (cons (extract-string-and-reset! tb) a))]
[(char=? c #\@) (s1 a (+ bfp 1))]
[else (extend-string-buffer! tb c) (s0 a (+ bfp 1))])))
(define (s1 a bfp)
(let ([c (read-char ip)])
(cond
[(eof-object? c) (source-error sfd bfp "expected open paren or @ following @")]
[(eqv? c #\@) (extend-string-buffer! tb c) (s0 a (+ bfp 1))]
[(eqv? c #\()
(unread-char c ip)
(let-values ([(e* new-bfp) (read-scheme k ip sfd bfp)])
(syntax-case e* ()
[(e)
(s0
(cons*
#`(check-string-and-indent e #,(source-string sfd bfp) (fx- (column) 1))
(extract-string-and-reset! tb)
a)
new-bfp)]
[else (source-error sfd bfp "found more than one expression within @(---)")]))]
[(initial-id-char? c)
(let ([str (extract-string-and-reset! tb)])
(extend-string-buffer! tb #\@)
(extend-string-buffer! tb c)
(s2 (cons str a) (+ bfp 1) bfp))]
[else (source-error sfd bfp "expected open paren or @ following @")])))
(define (s2 a bfp token-start-bfp)
(let ([c (read-char ip)])
(cond
[(eof-object? c) (close-input-port ip) (finish-identifier a bfp token-start-bfp)]
[(id-char? c) (extend-string-buffer! tb c) (s2 a (+ bfp 1) token-start-bfp)]
[else (unread-char c ip) (finish-identifier a bfp token-start-bfp)])))
(define (finish-identifier a bfp token-bfp)
(let* ([token (extract-string-and-reset! tb)]
[@kw (datum->syntax k (string->symbol token))]
[p (r @kw)])
(unless p (source-error sfd token-bfp "unrecognized token ~a" token))
(call-with-values (lambda () (p k ip sfd a bfp token-bfp)) s0)))
(s0 '() 0)))
(syntax-case x ()
[(k fn)
(string? (datum fn))
(lambda (r)
(with-syntax ([(e ...) (process-template-file r (datum fn) #'k)])
#'(let ([filename fn])
(let-values ([(op p line column) (open-positional-string-output-port)])
(display e op) ...
(p)))))])))
(define-syntax define-template-extension
(lambda (x)
(define who 'define-template-extension)
(define (make-prefix-id prefix kw)
(datum->syntax kw
(string->symbol
(string-append prefix (symbol->string (syntax->datum kw))))))
(define build-matcher
(case-lambda
[(kw)
(with-syntax ([kw kw] [@kw (make-prefix-id "@" kw)])
#'[@kw (lambda (k ip sfd stack bfp token-bfp)
(let-values ([(stack bfp) (strip-blanks ip stack bfp)])
(values (cons (make-incomplete-node 'kw #f token-bfp) stack) bfp)))])]
[(kw expr)
(with-syntax ([kw kw] [@kw (make-prefix-id "@" kw)] [(expr ...) expr])
#'[@kw (lambda (k ip sfd stack bfp token-bfp)
(let-values ([(e* new-bfp) (read-scheme k ip sfd bfp)])
(syntax-case e* ()
[(expr ...)
(let-values ([(stack new-bfp) (strip-blanks ip stack new-bfp)])
(values (cons (make-incomplete-node 'kw e* token-bfp) stack) new-bfp))]
[_ (source-error sfd token-bfp "expected @~s~s syntax, but got @~s~s"
'kw '(expr ...) 'kw (syntax->datum e*))])))])]))
(define (check-id id)
(let* ([str (symbol->string (syntax->datum id))]
[len (string-length str)])
(unless (and (> len 0) (initial-id-char? (string-ref str 0))
(let loop ([len len])
(or (= len 0)
(let ([len (- len 1)])
(and (id-char? (string-ref str len)) (loop len))))))
(syntax-violation who "invalid template keyword" id))))
(define (check-unique! type ids)
(let loop ([ids ids])
(syntax-case ids ()
[(id rest ...)
(if (memq (datum id) (datum (rest ...)))
(syntax-violation who (format "one or more ~a used more than once" type) #'id #'(rest ...))
(loop #'(rest ...)))]
[() (void)])))
(define (check-syntax-unique! type maybe-expr*)
(check-unique! type
(let f ([stx maybe-expr*] [ids '()])
(syntax-case stx ()
[id (and (identifier? #'id) (not (memq (datum id) '(... unquote quote)))) (cons #'id ids)]
[(a . d) (f #'a (f #'d ids))]
[_ ids]))))
(define (build-check kw tmpl x)
#`(unless #,(if x #`(and #,x #,tmpl) tmpl)
(source-error sfd token-bfp "found ~s without required ~s" token '#,kw)))
(define (build-initial-values bindings list?*)
(fold-right (lambda (binding list? init-val**)
(cons
(if list?
(make-list (length binding) #''())
(make-list (length binding) #'#f))
init-val**))
'() bindings list?*))
(define (build-bodies list?* tmpls updates bindings)
(let f ([list?* list?*] [tmpls tmpls] [updates updates] [bindings bindings] [rbindings '()])
(if (null? list?*)
'()
(with-syntax ([(checks ...)
(if (car list?*)
'()
#`((when #,(car tmpls)
(source-error token-bfp "found more @~s than expected" type))))]
[((args ...) ...) (fold-left (lambda (args binding) (cons binding args))
(cons (car updates) (cdr bindings)) rbindings)])
(cons #'(begin checks ... (loop (cdr stack) '() args ... ...))
(f (cdr list?*) (cdr tmpls) (cdr updates) (cdr bindings) (cons (car bindings) rbindings)))))))
(define (process-template output pat)
(define (squawk type)
(syntax-violation who (format "extension cannot start with ~s keyword" type) pat))
(syntax-case pat (optional)
[((optional kw (expr ...) tmpl) . rest)
(and (identifier? #'kw) (identifier? #'tmpl))
(squawk 'optional)]
[((optional kw tmpl) . rest)
(and (identifier? #'kw) (identifier? #'tmpl))
(squawk 'optional)]
[((kw (expr ...) tmpl) dots . rest)
(and (eq? (datum dots) '...) (identifier? #'kw) (identifier? #'tmpl))
(squawk 'list)]
[((kw tmpl) dots . rest)
(and (eq? (datum dots) '...) (identifier? #'kw) (identifier? #'tmpl))
(squawk 'optional)]
[(kw (expr ...) tmpl . rest)
(and (identifier? #'kw) (identifier? #'tmpl))
(process-rest output #'kw #'rest
(list (build-matcher #'kw #'(expr ...)))
#'([tmpl #`(string-append #,@rstack)]
[(expr ...) (incomplete-node-e* item)]))]
[(kw tmpl . rest)
(and (identifier? #'kw) (identifier? #'tmpl))
(process-rest output #'kw #'rest (list (build-matcher #'kw))
#'([tmpl #`(string-append #,@rstack)]))]
[(kw (expr ...))
(with-syntax ([@kw (make-prefix-id "@" #'kw)] [output output])
#'([@kw (lambda (k ip sfd stack bfp token-bfp)
(let-values ([(e* new-bfp) (read-scheme k ip sfd bfp)])
(syntax-case e* ()
[(expr ...) (values (cons #`output stack) new-bfp)]
[_ (source-error sfd token-bfp "expected @~s~s syntax, but got @~s~s"
'kw '(expr ...) 'kw (syntax->datum e*))])))]))]
[(kw)
(with-syntax ([@kw (make-prefix-id "@" #'kw)] [output output])
#'([@kw (lambda (k ip sfd stack bfp indent token-bfp)
(values (cons #`output stack) bfp indent))]))]))
(define (process-rest output first-kw rest as* matches)
(let f ([pat rest]
[as* as*]
[checks '()]
[kws '()]
[tmpls '()]
[list?* '()]
[bindings '()]
[updates '()]
[exprs '()]
[matches matches])
(syntax-case pat (optional)
[((optional kw (expr ...) tmpl) . rest)
(and (identifier? #'kw) (identifier? #'tmpl))
(with-syntax ([(t) (generate-temporaries '(t))])
(f #'rest
(cons (build-matcher #'kw #'(expr ...)) as*) checks
(cons #'kw kws) (cons #'tmpl tmpls) (cons #f list?*)
(cons (list #'tmpl #'t) bindings)
(cons (list #'#`(string-append #,@rstack) #'(incomplete-node-e* item)) updates)
(cons #'(expr ...) exprs) (cons* #'[tmpl tmpl] #'[(expr ...) #'t] matches)))]
[((optional kw tmpl) . rest)
(and (identifier? #'kw) (identifier? #'tmpl))
(f #'rest
(cons (build-matcher #'kw) as*) checks
(cons #'kw kws) (cons #'tmpl tmpls) (cons #f list?*) (cons (list #'tmpl) bindings)
(cons (list #'#`(string-append #,@rstack)) updates)
(cons #f exprs) (cons #'[tmpl tmpl] matches))]
[((kw (expr ...) tmpl) dots . rest)
(and (eq? (datum dots) '...) (identifier? #'kw) (identifier? #'tmpl))
(with-syntax ([(t*) (generate-temporaries '(t*))])
(f #'rest
(cons (build-matcher #'kw #'(expr ...)) as*) checks
(cons #'kw kws) (cons #'tmpl tmpls) (cons #t list?*) (cons (list #'tmpl #'t*) bindings)
(cons (list #'(cons #`(string-append #,@rstack) tmpl) #'(cons (incomplete-node-e* item) t*)) updates)
(cons #'(expr ...) exprs) (cons* #'[(tmpl (... ...)) tmpl] #'[((expr ...) (... ...)) t*] matches)))]
[((kw tmpl) dots . rest)
(and (eq? (datum dots) '...) (identifier? #'kw) (identifier? #'tmpl))
(f #'rest
(cons (build-matcher #'kw) as*) checks
(cons #'kw kws) (cons #'tmpl tmpls) (cons #t list?*) (cons (list #'tmpl) bindings)
(cons (list #'(cons #`(string-append #,@rstack) tmpl)) updates)
(cons #f exprs) (cons* #'[(tmpl (... ...)) tmpl] matches))]
[(kw (expr ...) tmpl . rest)
(and (identifier? #'kw) (identifier? #'tmpl))
(with-syntax ([(t) (generate-temporaries '(t))])
(f #'rest
(cons (build-matcher #'kw #'(expr ...)) as*)
(cons (build-check #'kw #'tmpl #'t) checks)
(cons #'kw kws) (cons #'tmpl tmpls) (cons #f list?*) (cons (list #'tmpl #'t) bindings)
(cons (list #'#`(string-append #,@rstack) #'(incomplete-node-e* item)) updates)
(cons #'(expr ...) exprs) (cons* #'[tmpl tmpl] #'[(expr ...) #'t] matches)))]
[(kw tmpl . rest)
(and (identifier? #'kw) (identifier? #'tmpl))
(f #'rest
(cons (build-matcher #'kw) as*)
(cons (build-check #'kw #'tmpl #f) checks)
(cons #'kw kws) (cons #'tmpl tmpls) (cons #f list?*) (cons (list #'tmpl) bindings)
(cons (list #'#`(string-append #,@rstack)) updates)
(cons #f exprs) (cons #'[tmpl tmpl] matches))]
[()
(begin
(for-each check-id kws)
(check-unique! "keyword" kws)
(check-unique! "template bindings" tmpls)
(check-syntax-unique! "scheme syntax matching expressions" exprs)
(cons
(with-syntax ([startkw first-kw]
[endkw (make-prefix-id "end" first-kw)]
[@endkw (make-prefix-id "@end" first-kw)]
[output output]
[(matches ...) matches]
[(checks ...) checks]
[((x ...) ...) bindings]
[((init-val ...) ...) (build-initial-values bindings list?*)]
[(kw ...) kws]
[(body ...) (build-bodies list?* tmpls updates bindings)])
#'[@endkw (lambda (k ip sfd stack bfp token-bfp)
(let-values ([(stack bfp) (strip-blanks ip stack bfp)])
(let loop ([stack stack] [rstack '()] [x init-val] ... ...)
(if (null? stack)
(source-error sfd token-bfp "found @~s with no initial @~s" 'endkw 'startkw)
(let ([item (car stack)])
(if (incomplete-node? item)
(let ([type (incomplete-node-type item)])
(case type
[(startkw) checks ...
(with-syntax (matches ...)
(values (cons #`output (cdr stack)) bfp))]
[(kw) body] ...
[else (source-error sfd token-bfp
"found unexpected @~s (~a) instead of expected @~s before @~s"
type (source-string sfd (incomplete-node-bfp item)) 'startkw 'endkw)]))
(loop (cdr stack) (cons item rstack) x ... ...)))))))])
as*))]
[_ (syntax-violation who "unrecognized pattern" pat)])))
(syntax-case x ()
[(_ pat output)
(with-syntax ([([@kw proc] ...) (process-template #'output #'pat)])
#'(begin (define-syntax @kw (make-compile-time-value proc)) ...))])))
(define-template-extension (num (e)) (number->string e))
(define-template-extension (for ([binding e] [bindings es] ...) tmpl)
(with-output-to-string
(lambda ()
(for-each (lambda (binding bindings ...) (display tmpl)) e es ...))))
(define-template-extension (if (expr) tmpl (elif (exprs) tmpls) ... (optional else else-tmpl))
(if expr
tmpl
#,(let f ([exprs #'(exprs ...)] [tmpls #'(tmpls ...)])
(if (null? exprs)
(or #'else-tmpl #'"")
(with-syntax ([expr (car exprs)] [tmpl (car tmpls)] [else (f (cdr exprs) (cdr tmpls))])
#'(if expr
tmpl
else)))))))
#!eof
-------- saving remainder of file to /tmp/t and running /tmp/t should produce only "end of tests" --------
#!/bin/tcsh
cat >! /tmp/spam.h << END
extern void @(name)(void);
END
cat >! /tmp/spam.c << END
#include <stdio.h>
@((include-template "/tmp/spam.h"))
void @(name)() {
@(name)();
}
END
scheme -q << END
(import (template))
(unless (equal?
(let ([name "bob"]) (include-template "/tmp/spam.c"))
"#include <stdio.h>\n\nextern void bob(void);\n\n\nvoid bob() {\n bob();\n}\n")
(error #f "test 1 failed"))
END
cat >! /tmp/spam.c << END
(import (template))
(unless (equal?
(guard (c [else (with-output-to-string (lambda () (display-condition c)))])
(expand '(let ([name "bob"]) (include-template "/tmp/spam.c"))))
"Exception in get-datum/annotations: unexpected end-of-file reading list at line 6, char 4 of /tmp/spam.c")
(error #f "test 2 failed"))
END
cat >! /tmp/spam.c << END
#include <stdio.h>
@((include-template "/tmp/spam.h"))
void @(name)() {
@(name)();
@
}
END
scheme -q << END
(import (template))
(unless (equal?
(guard (c [else (with-output-to-string (lambda () (display-condition c)))])
(expand '(let ([name "bob"]) (include-template "/tmp/spam.c"))))
"Exception in include-template: expected open paren or @ following @ at line 7, char 4 of /tmp/spam.c")
(error #f "test 3 failed"))
END
cat >! /tmp/spam.c << END
#include <stdio.h>
@((include-template "/tmp/spam.h"))
void @(name)() {
@(name)();
}
END
echo -n "@" >> /tmp/spam.c
scheme -q << END
(import (template))
(unless (equal?
(guard (c [else (with-output-to-string (lambda () (display-condition c)))])
(expand '(let ([name "bob"]) (include-template "/tmp/spam.c"))))
"Exception in include-template: expected open paren or @ following @ at line 8, char 2 of /tmp/spam.c")
(error #f "test 4 failed"))
END
cat >! /tmp/spam.c << END
#include <stdio.h>
@((include-template #xGO! "/tmp/spam.h"))
void @(name)() {
@(name)();
}
END
echo -n "@" >> /tmp/spam.c
scheme -q << END
(import (template))
(unless (equal?
(guard (c [else (with-output-to-string (lambda () (display-condition c)))])
(expand '(let ([name "bob"]) (include-template "/tmp/spam.c"))))
"Exception in get-datum/annotations: invalid number syntax #xGO! at line 3, char 21 of /tmp/spam.c")
(error #f "test 5 failed"))
END
cat >! /tmp/spam.c << END
#include <stdio.h>
@((include-template))
void @(name)() {
@(name)();
}
END
scheme -q << END
(import (template))
(unless (equal?
(guard (c [else (with-output-to-string (lambda () (display-condition c)))])
(expand '(let ([name "bob"]) (include-template "/tmp/spam.c"))))
"Exception: invalid syntax (include-template) at line 3, char 3 of /tmp/spam.c")
(error #f "test 6 failed"))
END
cat >! /tmp/spam.c <<END
#include <stdio.h>
/* function: @(name)
*
* @@param: @(name)
*/
@((include-template "/tmp/spam.h"))
void @(name)() {
@(name)();
}
END
scheme -q << END
(import (template))
(unless (equal? (let ([name "bob"]) (include-template "/tmp/spam.c"))
"#include <stdio.h>\n\n/* function: bob\n *\n * @param: bob\n */\nextern void bob(void);\n\n\nvoid bob() {\n bob();\n}\n")
(error #f "test 7 failed"))
END
cat >! /tmp/rockets <<END
Test
@for([x xs])
@num(x) ...
@endfor
Blast off!
END
scheme -q << END
(import (template))
(unless (equal? (let ([xs '(3 2 1)]) (include-template "/tmp/rockets"))
"Test\n3 ...\n2 ...\n1 ...\nBlast off!\n")
(error #f "test 8 failed"))
END
cat >> /tmp/rockets <<END
@if((= y 0))
Again!
@elif((= y 1))
Rockets are awesome!
@elif((= y 2))
Explosions!
@else
That was fun.
@endif
END
scheme -q << END
(import (template))
(unless (equal? (let ([xs '(3 2 1)] [y 0]) (include-template "/tmp/rockets"))
"Test\n3 ...\n2 ...\n1 ...\nBlast off!\nAgain!\n")
(error #f "test 9 failed"))
END
scheme -q << END
(import (template))
(unless (equal? (let ([xs '(3 2 1)] [y 1]) (include-template "/tmp/rockets"))
"Test\n3 ...\n2 ...\n1 ...\nBlast off!\nRockets are awesome!\n")
(error #f "test 10 failed"))
END
scheme -q << END
(import (template))
(unless (equal? (let ([xs '(3 2 1)] [y 2]) (include-template "/tmp/rockets"))
"Test\n3 ...\n2 ...\n1 ...\nBlast off!\nExplosions!\n")
(error #f "test 11 failed"))
END
scheme -q << END
(import (template))
(unless (equal? (let ([xs '(3 2 1)] [y 3]) (include-template "/tmp/rockets"))
"Test\n3 ...\n2 ...\n1 ...\nBlast off!\nThat was fun.\n")
(error #f "test 12 failed"))
END
cat >> /tmp/rockets <<END
@join(" and " [a as])@(a)@endjoin
END
scheme -q << END
(import (template))
(define-template-extension (join (?str [binding ls-expr] [bindings ls-exprs] ...) tmpl)
#,(with-syntax ([(t ts ...) (generate-temporaries #'(binding bindings ...))])
#'(with-output-to-string
(lambda ()
(let ([str ?str] [t ls-expr] [ts ls-exprs] ...)
(if (null? t)
""
(let loop ([t t] [ts ts] ...)
(let ([binding (car t)] [bindings (car ts)] ... [t (cdr t)] [ts (cdr ts)] ...)
(display tmpl)
(unless (null? t)
(display str)
(loop t ts ...))))))))))
(unless (equal? (let ([xs '(3 2 1)] [y 3] [as '()]) (include-template "/tmp/rockets"))
"Test\n3 ...\n2 ...\n1 ...\nBlast off!\nThat was fun.\n")
(error #f "test 13 failed"))
END
scheme -q << END
(import (template))
(define-template-extension (join (?str [binding ls-expr] [bindings ls-exprs] ...) tmpl)
#,(with-syntax ([(t ts ...) (generate-temporaries #'(binding bindings ...))])
#'(with-output-to-string
(lambda ()
(let ([str ?str] [t ls-expr] [ts ls-exprs] ...)
(if (null? t)
""
(let loop ([t t] [ts ts] ...)
(let ([binding (car t)] [bindings (car ts)] ... [t (cdr t)] [ts (cdr ts)] ...)
(display tmpl)
(unless (null? t)
(display str)
(loop t ts ...))))))))))
(unless (equal? (let ([xs '(3 2 1)] [y 3] [as '("a")]) (include-template "/tmp/rockets"))
"Test\n3 ...\n2 ...\n1 ...\nBlast off!\nThat was fun.\na")
(error #f "test 14 failed"))
END
scheme -q << END
(import (template))
(define-template-extension (join (?str [binding ls-expr] [bindings ls-exprs] ...) tmpl)
#,(with-syntax ([(t ts ...) (generate-temporaries #'(binding bindings ...))])
#'(with-output-to-string
(lambda ()
(let ([str ?str] [t ls-expr] [ts ls-exprs] ...)
(if (null? t)
""
(let loop ([t t] [ts ts] ...)
(let ([binding (car t)] [bindings (car ts)] ... [t (cdr t)] [ts (cdr ts)] ...)
(display tmpl)
(unless (null? t)
(display str)
(loop t ts ...))))))))))
(unless (equal? (let ([xs '(3 2 1)] [y 3] [as '("a" "b")]) (include-template "/tmp/rockets"))
"Test\n3 ...\n2 ...\n1 ...\nBlast off!\nThat was fun.\na and b")
(error #f "test 15 failed"))
END
scheme -q << END
(import (template))
(define-template-extension (join (?str [binding ls-expr] [bindings ls-exprs] ...) tmpl)
#,(with-syntax ([(t ts ...) (generate-temporaries #'(binding bindings ...))])
#'(with-output-to-string
(lambda ()
(let ([str ?str] [t ls-expr] [ts ls-exprs] ...)
(if (null? t)
""
(let loop ([t t] [ts ts] ...)
(let ([binding (car t)] [bindings (car ts)] ... [t (cdr t)] [ts (cdr ts)] ...)
(display tmpl)
(unless (null? t)
(display str)
(loop t ts ...))))))))))
(unless (equal? (let ([xs '(3 2 1)] [y 3] [as '("a" "b" "c")]) (include-template "/tmp/rockets"))
"Test\n3 ...\n2 ...\n1 ...\nBlast off!\nThat was fun.\na and b and c")
(error #f "test 16 failed"))
END
cat >! /tmp/indent-test.c << END
#include <stdio.h>
int main(int argc, char *argv[]) {
@(body)
}
END
scheme -q << END
(import (template))
(unless (equal? (let ([body "printf(\"Hello, world!\\\\n\");\nprintf(\"So... uh, what's going on?\\\\n\");\nprintf(\"Well, goodbye then.\\\\n\");"])
(include-template "/tmp/indent-test.c"))
"#include <stdio.h>\n\nint main(int argc, char *argv[]) {\n printf(\"Hello, world!\\\\n\");\n printf(\"So... uh, what's going on?\\\\n\");\n printf(\"Well, goodbye then.\\\\n\");\n}\n")
(error #f "test 17 failed"))
END
cat >! /tmp/hygeine << END
Hygiene test:
@for([t i*])
got @(t) .
@endfor
@for([x j*])
got @(x) and t is @(t).
@endfor
@let([outer-t t])
@for([x i*] [t j*])
got @(x) and @(t) and @(outer-t).
@endfor
@endlet
END
scheme -q << END
(import (template))
(let ()
(define-template-extension (for ([x e] [xs es] ...) tmpl)
(let ([t e])
(apply string-append (map (lambda (x xs ...) tmpl) t es ...))))
(define-template-extension (let ([x e] [xs es] ...) tmpl)
(let ([x e] [xs es] ...) tmpl))
(unless (equal? (let ([t "10"] [i* '("1" "2" "3")] [j* '("a" "b" "c")])
(include-template "/tmp/hygeine"))
"Hygiene test:\n\n got 1 .\n got 2 .\n got 3 .\n\n got a and t is 10.\n got b and t is 10.\n got c and t is 10.\n\n got 1 and a and 10.\n got 2 and b and 10.\n got 3 and c and 10.\n")
(error #f "test 18 failed")))
END
cat >! /tmp/indent << END
This is to test indents:
simple indent: @(x)
nested indents: @(y) @(x)
END
scheme -q << END
(import (template))
(unless (equal? (let ([x "a\nb\nc\n"] [y "x\ny\nz"])
(include-template "/tmp/indent"))
"This is to test indents:\n simple indent: a\n b\n c\n\n\n nested indents: x\n y\n z a\n b\n c\n\n")
(error #f "test 19 failed"))
END
echo "end of tests"
| true |
c827ab4d5cdef159986f1971680403499a9020f6 | a23f41d6de12a268b129a6b5c2e932325fe674f6 | /src/swish/gen-server.ss | 01215634bb2e775e769e8d6defc21f141aac0056 | [
"MIT",
"LicenseRef-scancode-public-domain"
] | permissive | becls/swish | 89ee48b783b6b67b7077e09a78b3005fb44a8c54 | 3165b6a40c33774b263941314a7975b08dddf0e2 | refs/heads/dev | 2022-11-05T01:55:29.530457 | 2022-10-14T20:49:18 | 2022-10-14T20:55:37 | 113,237,913 | 134 | 27 | MIT | 2022-10-17T13:04:13 | 2017-12-05T22:04:27 | Scheme | UTF-8 | Scheme | false | false | 12,573 | ss | gen-server.ss | ;;; Copyright 2018 Beckman Coulter, Inc.
;;;
;;; Permission is hereby granted, free of charge, to any person
;;; obtaining a copy of this software and associated documentation
;;; files (the "Software"), to deal in the Software without
;;; restriction, including without limitation the rights to use, copy,
;;; modify, merge, publish, distribute, sublicense, and/or sell copies
;;; of the Software, and to permit persons to whom the Software is
;;; furnished to do so, subject to the following conditions:
;;;
;;; The above copyright notice and this permission notice shall be
;;; included in all copies or substantial portions of the Software.
;;;
;;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
;;; EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
;;; MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
;;; NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
;;; HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
;;; WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
;;; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
;;; DEALINGS IN THE SOFTWARE.
(library (swish gen-server)
(export
define-state-tuple
gen-server:call
gen-server:cast
gen-server:debug
gen-server:enter-loop
gen-server:reply
gen-server:start
gen-server:start&link
)
(import
(chezscheme)
(swish erlang)
(swish event-mgr-notify)
(swish events)
)
(define-tuple <gen-server-interface>
init handle-call handle-cast handle-info terminate debug)
(define-syntax (gen-server:start x)
(syntax-case x ()
[(k name arg ...)
(with-implicit (k init handle-call handle-cast handle-info terminate)
#'(start name
(<gen-server-interface> make
[init init]
[handle-call handle-call]
[handle-cast handle-cast]
[handle-info handle-info]
[terminate terminate]
[debug #f])
(list arg ...)))]))
(define-syntax (gen-server:start&link x)
(syntax-case x ()
[(k name arg ...)
(with-implicit (k init handle-call handle-cast handle-info terminate)
#'(start&link name
(<gen-server-interface> make
[init init]
[handle-call handle-call]
[handle-cast handle-cast]
[handle-info handle-info]
[terminate terminate]
[debug #f])
(list arg ...)))]))
(define-syntax (gen-server:enter-loop x)
(syntax-case x ()
[(k state)
#'(k state 'infinity)]
[(k state timeout)
(with-implicit (k handle-call handle-cast handle-info terminate)
#'($enter-loop
(<gen-server-interface> make
[init #f]
[handle-call handle-call]
[handle-cast handle-cast]
[handle-info handle-info]
[terminate terminate]
[debug #f])
state
timeout))]))
(define ($enter-loop iface state timeout)
(loop (process-parent) (process-name) iface state
(resolve-timeout timeout)))
(define (start name iface init-args)
(let* ([thunk (make-thunk self name (make-starter name iface init-args))]
[pid (spawn thunk)])
(let ([m (monitor pid)])
(receive
[#(ack ,@pid ,reply)
(demonitor&flush m)
reply]
[`(DOWN ,@m ,_ ,reason)
`#(error ,reason)]))))
(define (start&link name iface init-args)
(let* ([thunk (make-thunk self name (make-starter name iface init-args))]
[pid (spawn&link thunk)])
(receive
[#(ack ,@pid ,reply) reply]
[`(EXIT ,@pid ,reason)
(receive (until 0 (void))
[#(ack ,@pid ,reply) (void)])
`#(error ,reason)])))
(define (make-starter name iface init-args)
(lambda (reply parent)
(match (try (do-init iface init-args))
[#(ok ,state)
(reply `#(ok ,self))
(loop parent name iface state 'infinity)]
[#(ok ,state ,timeout)
(reply `#(ok ,self))
(loop parent name iface state (resolve-timeout timeout))]
[#(stop ,reason)
(reply `#(error ,reason))
(raise reason)]
[ignore
(reply 'ignore)
(raise 'normal)]
[`(catch ,reason ,e)
(reply `#(error ,reason))
;; throw is not useful here; it would merely add k from thunk->cont
(raise e)]
[,other
(let ([reason `#(bad-return-value ,other)])
(reply `#(error ,reason))
(raise reason))])))
(define (make-thunk parent name proc)
(lambda ()
(define (reply x)
(send parent `#(ack ,self ,x)))
(if (not name)
(proc reply parent)
(match (catch (register name self))
[#(EXIT ,reason) (reply `#(error ,reason))]
[#t (proc reply parent)]))))
(define (resolve-timeout x)
(if (and (fixnum? x) (fx<= 0 x 86400000)) ; one day
(+ (erlang:now) x)
x))
(define (loop parent name iface state timeout)
(handle-msg (receive (until timeout 'timeout) [,msg msg])
parent name iface state timeout))
(define (handle-msg msg parent name iface state timeout)
(match msg
[`(EXIT ,@parent ,reason ,e)
(terminate e name msg iface state)]
[#($gen-call ,from ,msg)
(match (try (do-handle-call iface msg from state))
[#(reply ,reply0 ,new-state)
(gen-server:reply from reply0)
(loop parent name iface new-state 'infinity)]
[#(reply ,reply0 ,new-state ,timeout)
(gen-server:reply from reply0)
(loop parent name iface new-state (resolve-timeout timeout))]
[#(stop ,reason ,reply0 ,new-state)
(let ([r (terminate-reason reason name msg iface new-state)])
(gen-server:reply from reply0)
(raise r))]
[,other
(handle-common-reply other parent name msg iface state)])]
[#($gen-cast ,msg)
(let ([reply (try (do-handle-cast iface msg state))])
(handle-common-reply reply parent name msg iface state))]
[#($gen-debug ,debug)
(loop parent name (<gen-server-interface> copy iface [debug debug])
state timeout)]
[,msg
(let ([reply (try (do-handle-info iface msg state))])
(handle-common-reply reply parent name msg iface state))]))
(define (handle-common-reply reply parent name msg iface state)
(match reply
[#(no-reply ,new-state)
(loop parent name iface new-state 'infinity)]
[#(no-reply ,new-state ,timeout)
(loop parent name iface new-state (resolve-timeout timeout))]
[#(stop ,reason ,new-state)
(terminate reason name msg iface new-state)]
[`(catch ,reason ,e)
(terminate e name msg iface state)]
[,_
(terminate `#(bad-return-value ,reply) name msg iface state)]))
(define (terminate reason name msg iface state)
;; throw is not useful here; it would merely add k from thunk->cont
(raise (terminate-reason reason name msg iface state)))
(define (terminate-reason reason name msg iface state)
(let-values ([(r e)
(match reason
[`(catch ,r ,e) (values r e)]
[,_ (values reason reason)])])
(match (try (do-terminate iface r state))
[`(catch ,r ,e)
(report-terminating r e name msg state)
e]
[,_
(report-terminating r e name msg state)
e])))
(define (report-terminating reason err name msg state)
(when (informative-exit-reason? err)
(let-values ([(reason details) (normalize-exit-reason reason err)])
(system-detail <gen-server-terminating>
[name name]
[pid self]
[last-message msg]
[state state]
[reason reason]
[details details]))))
(define gen-server:call
(case-lambda
[(server request)
(do-call server request 5000 #f)]
[(server request timeout)
(do-call server request timeout #t)]))
(define-syntax no-interrupts
(syntax-rules ()
[(_ body ...)
(let ([x (begin (disable-interrupts) body ...)])
(enable-interrupts)
x)]))
(define debug-table (make-weak-eq-hashtable))
(define (do-call server request timeout timeout?)
(define (failed-call reason e)
(let ([context (if timeout?
(list server request timeout)
(list server request))])
(throw `#(,reason #(gen-server call ,context)) e)))
(let* ([pid (if (symbol? server)
(or (whereis server) (failed-call 'no-process #f))
server)]
[m (monitor pid)]
[debug (no-interrupts (eq-hashtable-ref debug-table pid #f))]
[start (and debug (erlang:now))])
(send pid `#($gen-call #(,self ,m) ,request))
(receive
(after timeout
(demonitor&flush m)
(when debug
(debug-report 6 debug start self pid request #f 'timeout))
(failed-call 'timeout #f))
[#(,@m ,reply)
(demonitor&flush m)
(when debug
(debug-report 5 debug start self pid request #f reply))
(match reply
[`(catch ,reason ,e) (throw e)]
[,_ reply])]
[`(DOWN ,@m ,_ ,reason ,err)
(when debug
(debug-report 6 debug start self pid request #f reason))
(failed-call reason err)])))
(define (gen-server:cast server request)
(catch (send server `#($gen-cast ,request)))
'ok)
(define (gen-server:debug server server-options client-options)
(define (check-options options)
(unless (or (not options) (list? options))
(bad-arg 'gen-server:debug options)))
(let ([pid (if (symbol? server)
(or (whereis server) (raise 'no-process))
server)])
(check-options server-options)
(check-options client-options)
(send pid `#($gen-debug ,server-options))
(no-interrupts
(if client-options
(eq-hashtable-set! debug-table pid client-options)
(eq-hashtable-delete! debug-table pid)))
'ok))
(define (gen-server:reply client reply)
(match client
[#(,pid ,tag)
(send pid `#(,tag ,reply))
'ok]))
(define-syntax (define-state-tuple x)
(syntax-case x ()
[(k1 name field ...)
(with-implicit (k1 $state)
#'(begin
(define-tuple name field ...)
(define-syntax ($state x)
(syntax-case x ()
[(k2 op arg (... ...))
(with-implicit (k2 state)
#'(name op state arg (... ...)))]))))]))
(define (debug-report type debug start client server message state reply)
(system-detail <gen-server-debug>
[timestamp start]
[duration (- (erlang:now) start)]
[type type]
[client client]
[server server]
[message (and (memq 'message debug) message)]
[state (and (memq 'state debug) state)]
[reply (and (memq 'reply debug) reply)])
reply)
(define (do-init iface init-args)
(apply (<gen-server-interface> init iface) init-args))
(define (do-handle-call iface msg from state)
(match-let* ([`(<gen-server-interface> ,handle-call ,debug) iface])
(if debug
(let ([start (erlang:now)])
(debug-report 1 debug start (vector-ref from 0) self msg state
(handle-call msg from state)))
(handle-call msg from state))))
(define (do-handle-cast iface msg state)
(match-let* ([`(<gen-server-interface> ,handle-cast ,debug) iface])
(if debug
(let ([start (erlang:now)])
(debug-report 2 debug start #f self msg state
(handle-cast msg state)))
(handle-cast msg state))))
(define (do-handle-info iface msg state)
(match-let* ([`(<gen-server-interface> ,handle-info ,debug) iface])
(if debug
(let ([start (erlang:now)])
(debug-report 3 debug start #f self msg state
(handle-info msg state)))
(handle-info msg state))))
(define (do-terminate iface reason state)
(match-let* ([`(<gen-server-interface> ,terminate ,debug) iface])
(if debug
(let ([start (erlang:now)])
(debug-report 4 debug start #f self #f state
(terminate reason state)))
(terminate reason state))))
)
| true |
eb7e7005db3429ca577d026c889b64cba98f7090 | 7301b8e6fbd4ac510d5e8cb1a3dfe5be61762107 | /ex-2.57.scm | 6a76b6d4b6c4ae547d581d3d347320bd3adcd872 | [] | no_license | jiakai0419/sicp-1 | 75ec0c6c8fe39038d6f2f3c4c6dd647a39be6216 | 974391622443c07259ea13ec0c19b80ac04b2760 | refs/heads/master | 2021-01-12T02:48:12.327718 | 2017-01-11T12:54:38 | 2017-01-11T12:54:38 | 78,108,302 | 0 | 0 | null | 2017-01-05T11:44:44 | 2017-01-05T11:44:44 | null | UTF-8 | Scheme | false | false | 255 | scm | ex-2.57.scm | (load "./ex-2.56.scm")
(define (augend s)
(let ((rest (cddr s)))
(if (null? (cdr rest))
(car rest)
(cons '+ rest))))
(define (multiplicand p)
(let ((rest (cddr p)))
(if (null? (cdr rest))
(car rest)
(cons '* rest))))
| false |
78b84b565a82eaf8722fdd750994accccb2160c1 | a8216d80b80e4cb429086f0f9ac62f91e09498d3 | /tools/optimize-char-sets.scm | 8eebcfcc244e92e5d92a18e2731b72bc9716529c | [
"BSD-3-Clause"
] | permissive | ashinn/chibi-scheme | 3e03ee86c0af611f081a38edb12902e4245fb102 | 67fdb283b667c8f340a5dc7259eaf44825bc90bc | refs/heads/master | 2023-08-24T11:16:42.175821 | 2023-06-20T13:19:19 | 2023-06-20T13:19:19 | 32,322,244 | 1,290 | 223 | NOASSERTION | 2023-08-29T11:54:14 | 2015-03-16T12:05:57 | Scheme | UTF-8 | Scheme | false | false | 4,470 | scm | optimize-char-sets.scm | #!/usr/bin/env chibi-scheme
;; Simple tool to generate libraries of optimized char-sets.
;;
;; Usage:
;; optimize-char-sets.scm [--ascii] module.name > out
;;
;; Imports (module name) and writes optimized versions of all exported
;; char-sets to stdout.
(import (chibi) (srfi 1) (srfi 69)
(chibi io) (chibi string) (chibi modules)
(chibi char-set) (chibi iset) (chibi iset optimize)
(only (meta) load-module))
;; Use a hash table for speedup of huge sets instead of O(n^2)
;; srfi-1 implementation.
(define (lset-diff ls1 ls2)
(let ((ls2-tab (make-hash-table eq?)))
(for-each (lambda (i) (hash-table-set! ls2-tab i #t)) ls2)
(remove (lambda (i) (hash-table-exists? ls2-tab i)) ls1)))
(let ((args (command-line)))
(let lp ((ls (cdr args)) (ascii? #f) (predicate? #f))
(cond
((and (pair? ls) (not (equal? "" (car ls)))
(eqv? #\- (string-ref (car ls) 0)))
(cond
((member (car ls) '("-a" "--ascii"))
(lp (cdr ls) #t predicate?))
((member (car ls) '("-p" "--predicate"))
(lp (cdr ls) ascii? #t))
(else (error "unknown option" (car ls)))))
((or (null? ls) (pair? (cdr ls)))
(error "usage: optimize-char-sets.scm [--ascii] module.name"))
(else
(let ((mod (load-module
(map (lambda (x) (or (string->number x) (string->symbol x)))
(string-split (car ls) #\.)))))
(for-each
(lambda (exp)
(let ((value (module-ref mod exp)))
(cond
((char-set? value)
(display ";; ") (write exp) (newline)
(write `(optimize ,exp) (current-error-port)) (newline (current-error-port))
;; extremely slow conversion to lists as a sanity check
(display " verifying cursors\n" (current-error-port))
'(if (not (equal? (iset->list value)
(do ((cur (iset-cursor value)
(iset-cursor-next value cur))
(res '() (cons (iset-ref value cur) res)))
((end-of-iset? cur) (reverse res)))))
(error "error in iset cursors"))
(display " computing intersection\n" (current-error-port))
(let* ((iset1 (if ascii?
(iset-intersection char-set:ascii value)
value))
(_ (display " optimizing\n" (current-error-port)))
(iset-opt (iset-optimize iset1))
(_ (display " balancing\n" (current-error-port)))
(iset2 (iset-balance iset-opt)))
(display " comparing\n" (current-error-port))
(if (and (not ascii?) (not (iset= iset1 iset2)))
(begin
(display " different!\n" (current-error-port))
(let* ((ls1 (iset->list iset1))
(ls2 (iset->list iset2))
(diff1 (lset-diff ls1 ls2))
(diff2 (lset-diff ls2 ls1)))
(display " original: " (current-error-port))
(write (length ls1) (current-error-port))
(display " elements, missing: " (current-error-port))
(write diff1 (current-error-port))
(newline (current-error-port))
(display " optimized: " (current-error-port))
(write (length ls2) (current-error-port))
(display " elements, missing: " (current-error-port))
(write diff2 (current-error-port))
(newline (current-error-port))
(error "optimized iset is different"))))
(display " writing\n" (current-error-port))
(write
(if predicate?
`(define ,(string->symbol
(string-append (symbol->string exp) "?"))
,(iset->code/lambda iset2))
`(define ,exp
(immutable-char-set ,(iset->code iset2)))))
(newline)
(newline)
(display " done\n" (current-error-port)))))))
(module-exports mod)))))))
| false |
2ba85fc1d415a49c9ace717445e36b2b875decdc | bf1c9803ae38f9aad027fbe4569ccc6f85ba63ab | /chapter_3/3.1.Assignment.and.Local.State/ex_3.7.scm | f7b73191c18e8e1937ba447954628ade852ed61d | [] | no_license | mehese/sicp | 7fec8750d3b971dd2383c240798dbed339d0345a | 611b09280ab2f09cceb2479be98ccc5403428c6c | refs/heads/master | 2021-06-12T04:43:27.049197 | 2021-04-04T22:22:47 | 2021-04-04T22:23:12 | 161,924,666 | 0 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 1,181 | scm | ex_3.7.scm | #lang sicp
(define (make-account balance account-password)
(define (withdraw amount)
(if (>= balance amount)
(begin
(set! balance (- balance amount))
balance)
"Insufficient funds"))
(define (deposit amount)
(set! balance (+ balance amount))
balance)
(define (dispatch m)
(cond ((eq? m 'withdraw) withdraw)
((eq? m 'deposit) deposit)
(else (error "Unknown request: MAKE-ACCOUNT" m))))
(define (pre-empt-dispatch pw m)
(if (eq? pw account-password)
(dispatch m)
(lambda (m) "Incorrect password")))
pre-empt-dispatch)
(define (make-joint orig-acc orig-password new-password)
(define (alias-dispatch pw message)
(if (eq? pw new-password)
(orig-acc orig-password message)
(lambda (m) "Incorrect password!")))
alias-dispatch)
(define peter-acc
(make-account 100 'open-sesame))
(define paul-acc
(make-joint peter-acc 'open-sesame 'rosebud))
((peter-acc 'open-sesame 'withdraw) 40)
((peter-acc 'open-sesame 'deposit) 0) ; balance = 60 ✔
((paul-acc 'rosebud 'deposit) 1) ; balance = 61 ✔
((peter-acc 'open-sesame 'deposit) 0) ; balance = 61 ✔ | false |
5355f9692c14c4eb30ffcd19db6d3ff8d1dc2731 | 5a68949704e96b638ca3afe335edcfb65790ca20 | /quasiquote/expand.scm | 498abb2803b901eb8e4681f78dccdc3223fd15cf | [] | no_license | terryc321/lisp | 2194f011f577d6b941a0f59d3c9152d24db167b2 | 36ca95c957eb598facc5fb4f94a79ff63757c9e5 | refs/heads/master | 2021-01-19T04:43:29.122838 | 2017-05-24T11:53:06 | 2017-05-24T11:53:06 | 84,439,281 | 2 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 2,210 | scm | expand.scm | ;;
;; quasi quote implementation
;;
;; http://repository.readscheme.org/ftp/papers/pepm99/bawden.pdf
;;
;; Appendix A : Expansion Algorithm
;;
;; Assumed that some more primitive Lisp parser
;; has already read in the quasiquotation to be expanded.
;; and has somehow tagged all the quasiquotation markup.
;; This primitive parser must supply the following four functions
;;
;; tag-backquote?
;; this predicate should be true of the result of reading a backquote (`)
;; followed by an s expression
;;
;; tag-comma?
;; this predicate should be true of the result of reading a comma (,)
;; followed by an s expression
;;
;; tag-comma-atsign?
;; this predicate should be true of the result of reading a comma-atsign (,@)
;; followed by an s expression
;;
;; tag-data
;; this function should be applied to an object that
;; satisfies one of the previous three predicates
;; it will return the s expression that followed the quasiquotation markup
;;
;; The main entry point is the function qq-expand which should be applied to an
;; expression that immediately followed a backquote character.
;; ie the outermost backquote tag should be stripped off BEFORE qq-expand
;; is called.
;;
;; Code created by qq-expand and qq-expand-list performs all list construction
;; by using either append or list. It must NEVER use CONS. This is important
;; in order to make nested quasiquotations using splicing work properly.
;; The code generated here is correct but inefficient. In a real lisp
;; implementation some optimization would need to be done. Care must be taken not
;; to perform any optimizations that alter the behaviour of nested splicing.
;;
(define (qq-expand x)
(cond ((tag-comma? x)
(tag-data x))
((tag-comma-atsign? x)
(error "illegal"))
((tag-backquote? x)
(qq-expand
(qq-expand (tag-data x))))
((pair? x)
`(append
,(qq-expand-list (car x))
,(qq-expand (cdr x))))
(else `',x)))
(define (qq-expand-list x)
(cond ((tag-comma? x)
`(list ,(tag-data x)))
((tag-comma-atsign? x)
(tag-data x))
((tag-backquote? x)
(qq-expand-list
(qq-expand (tag-data x))))
((pair? x)
`(list
(append
,(qq-expand-list (car x))
,(qq-expand (cdr x)))))
(else `'(,x))))
| false |
b4ca2a69a5a985e821046a536569017eadf69083 | de5d387aa834f85a1df3bd47bc324b01130f21fb | /ps6/code/ambsch.scm | 9c57ad073768b6d59d8f30c9db667c54a87a1376 | [] | no_license | chuchao333/6.945 | 5ae15980a952bed5c868be03d1a71b1878ddd53d | c50bb28aadf0c3fcda3c8e56b4a61b9a2d582552 | refs/heads/master | 2020-05-30T20:23:23.501175 | 2013-05-05T19:59:53 | 2013-05-05T19:59:53 | 24,237,118 | 5 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 7,572 | scm | ambsch.scm | ;;;; Extension of Scheme for amb
;;; amb is the ambiguous operator of McCarthy.
;;; (load "stack-queue.scm")
(define-syntax amb
(sc-macro-transformer
(lambda (form uenv)
`(amb-list
(list ,@(map (lambda (arg)
`(lambda ()
,(close-syntax arg uenv)))
(cdr form)))))))
(define *number-of-calls-to-fail* 0) ;for metering.
(define (amb-list alternatives)
(if (null? alternatives)
(set! *number-of-calls-to-fail*
(+ *number-of-calls-to-fail* 1)))
(call-with-current-continuation
(lambda (k)
(add-to-search-schedule
(map (lambda (alternative)
(lambda ()
(within-continuation k alternative)))
alternatives))
(yield))))
;;; amb-set! is an assignment operator
;;; that gets undone on backtracking.
(define-syntax amb-set!
(sc-macro-transformer
(lambda (form uenv)
(compile-amb-set (cadr form) (caddr form) uenv))))
(define (compile-amb-set var val-expr uenv)
(let ((var (close-syntax var uenv))
(val (close-syntax val-expr uenv)))
`(let ((old-value ,var))
(effect-wrapper
(lambda ()
(set! ,var ,val))
(lambda ()
(set! ,var old-value))))))
;;; A general wrapper for undoable effects
(define (effect-wrapper doer undoer)
(force-next
(lambda () (undoer) (yield)))
(doer))
;;; Alternative search strategy wrappers
(define (with-depth-first-schedule thunk)
(call-with-current-continuation
(lambda (k)
(fluid-let ((add-to-search-schedule
add-to-depth-first-search-schedule)
(*search-schedule* (empty-search-schedule))
(*top-level* k))
(thunk)))))
(define (with-breadth-first-schedule thunk)
(call-with-current-continuation
(lambda (k)
(fluid-let ((add-to-search-schedule
add-to-breadth-first-search-schedule)
(*search-schedule* (empty-search-schedule))
(*top-level* k))
(thunk)))))
;;; Representation of the search schedule
(define *search-schedule*)
(define (empty-search-schedule)
(make-stack&queue))
(define (yield)
(if (stack&queue-empty? *search-schedule*)
(*top-level* #f)
((pop! *search-schedule*))))
(define (force-next thunk)
(push! *search-schedule* thunk))
;;; Alternative search strategies
(define (add-to-depth-first-search-schedule alternatives)
(for-each (lambda (alternative)
(push! *search-schedule* alternative))
(reverse alternatives)))
(define (add-to-breadth-first-search-schedule alternatives)
(for-each (lambda (alternative)
(add-to-end! *search-schedule* alternative))
alternatives))
;;; For incremental interactive experiments from REPL.
(define (init-amb)
(set! *search-schedule* (empty-search-schedule))
(set! *number-of-calls-to-fail* 0)
'done)
(define add-to-search-schedule ;; Default is depth 1st
add-to-depth-first-search-schedule)
(define *top-level*
(lambda (ignore)
(display ";No more alternatives\n")
(abort->top-level unspecific)))
(define (require p)
(if (not p) (amb)))
#|
;;; AX 1 - Elementary backtrack test.
(define elementary-backtrack-test
(lambda ()
(let ((x (amb 1 2 3)))
(pp (list x))
(let ((y (amb 'a 'b)))
(pp (list x y))
(let ((z (amb #t #f)))
(pp (list x y z)))))
(amb)))
#|
;; AX 1.d - Elementary backtrack test. [Depth First]
(with-depth-first-schedule elementary-backtrack-test)
(1)
(1 a)
(1 a #t)
(1 a #f)
(1 b)
(1 b #t)
(1 b #f)
(2)
(2 a)
(2 a #t)
(2 a #f)
(2 b)
(2 b #t)
(2 b #f)
(3)
(3 a)
(3 a #t)
(3 a #f)
(3 b)
(3 b #t)
(3 b #f)
;Value: #f
;; AX 1.b - Elementary backtrack test. [Breadth First]
(with-breadth-first-schedule elementary-backtrack-test)
(1)
(2)
(3)
(1 a)
(1 b)
(2 a)
(2 b)
(3 a)
(3 b)
(1 a #t)
(1 a #f)
(1 b #t)
(1 b #f)
(2 a #t)
(2 a #f)
(2 b #t)
(2 b #f)
(3 a #t)
(3 a #f)
(3 b #t)
(3 b #f)
;Value: #f
|#
;;; AX 2 - Testing undoable assignment.
(define testing-undoable-assignment
(lambda ()
(let ((x (amb 1 2 3)) (y 0) (z 0))
(pp `(before ,x ,y ,z))
(amb-set! y x)
(pp `(after ,x ,y ,z))
(amb-set! z (amb 3.14 2.718))
(pp `(zset ,x ,y ,z))
(amb-set! x (+ y z))
(pp `(xset ,x ,y ,z))
(amb))))
#|
;;; AX 2.d - Testing undoable assignment. [Depth First]
(with-depth-first-schedule testing-undoable-assignment)
(before 1 0 0)
(after 1 1 0)
(zset 1 1 3.14)
(xset 4.140000000000001 1 3.14)
(zset 1 1 2.718)
(xset 3.718 1 2.718)
(before 2 0 0)
(after 2 2 0)
(zset 2 2 3.14)
(xset 5.140000000000001 2 3.14)
(zset 2 2 2.718)
(xset 4.718 2 2.718)
(before 3 0 0)
(after 3 3 0)
(zset 3 3 3.14)
(xset 6.140000000000001 3 3.14)
(zset 3 3 2.718)
(xset 5.718 3 2.718)
;Value: #f
|#
;;; AX 3 - Pythagorean triples
;; In breadth-first we get useful results here.
;; None from depth-first.
;; AX 3.f - A Pythagorean triple from...
(define (a-pythagorean-triple-from low)
(let ((i (an-integer-from low)))
(let ((j (an-integer-from i)))
(let ((k (an-integer-from j)))
(require (= (+ (* i i) (* j j)) (* k k)))
(list i j k)))))
(define (require p)
(if (not p) (amb)))
(define (an-integer-from low)
(amb low (an-integer-from (+ low 1))))
#|
(with-breadth-first-schedule
(lambda ()
(pp (a-pythagorean-triple-from 1))
(amb)))
(3 4 5)
(6 8 10)
(5 12 13)
(9 12 15)
(8 15 17)
(12 16 20)
(7 24 25)
(15 20 25)
(10 24 26)
(20 21 29)
(18 24 30)
(16 30 34)
(21 28 35)
(12 35 37)
(15 36 39)
(24 32 40)
(9 40 41)
(27 36 45)
(14 48 50)
(30 40 50)
(24 45 51)
(20 48 52)
(28 45 53)
(33 44 55)
(40 42 58)
(36 48 60)
(11 60 61)
(16 63 65)
(25 60 65)
(33 56 65)
;Quit!
|#
;; AX 3.b - A Pythagorean triple between...
;; For example, for controlling search:
(define (a-pythagorean-triple-between low high)
(let ((i (an-integer-between low high)))
(let ((j (an-integer-between i high)))
(let ((k (an-integer-between j high)))
(require (= (+ (* i i) (* j j)) (* k k)))
(list i j k)))))
|#
(define (an-integer-between low high)
(require (<= low high))
(amb low
(an-integer-between (+ low 1) high)))
;; A useful device:
(define (amb-collect-values result-thunk #!optional limit)
(call-with-current-continuation
(lambda (k)
(let ((values '()) (count 0))
(fluid-let ((*top-level* (lambda (ignore) (k values)))
(*search-schedule* (empty-search-schedule)))
(let ((value (result-thunk)))
(set! values (cons value values))
(set! count (+ count 1))
(if (and (not (default-object? limit))
(>= count limit))
(k values))
(amb)))))))
#|
(with-depth-first-schedule
(lambda ()
(let ((mid (amb-collect-values
(lambda ()
(a-pythagorean-triple-between 1 20))
;; I want only 3, and
;; I don't want to backtrack into this.
3)))
(pp (list (a-pythagorean-triple-between 1 10)
mid
(a-pythagorean-triple-between 10 30)))
(amb))))
((3 4 5) ((6 8 10) (5 12 13) (3 4 5)) (10 24 26))
((6 8 10) ((6 8 10) (5 12 13) (3 4 5)) (10 24 26))
((3 4 5) ((6 8 10) (5 12 13) (3 4 5)) (12 16 20))
((6 8 10) ((6 8 10) (5 12 13) (3 4 5)) (12 16 20))
((3 4 5) ((6 8 10) (5 12 13) (3 4 5)) (15 20 25))
((6 8 10) ((6 8 10) (5 12 13) (3 4 5)) (15 20 25))
((3 4 5) ((6 8 10) (5 12 13) (3 4 5)) (18 24 30))
((6 8 10) ((6 8 10) (5 12 13) (3 4 5)) (18 24 30))
((3 4 5) ((6 8 10) (5 12 13) (3 4 5)) (20 21 29))
((6 8 10) ((6 8 10) (5 12 13) (3 4 5)) (20 21 29))
;Value: #f
|#
| true |
d1bf5e11e973764c629f9c038ad3cc812c554c47 | 185024f40e1ceed452781a1f3f57e6d16f57d799 | /for.ss | 78358d6b40c1132fbbc942a530c1e29583d54648 | [] | no_license | noelwelsh/numeric | b82cd4ca9e4afb18df0129ec2231fc03f9b66450 | ac4488cf8cc6f0558f74ca9b8faad0f198e76a84 | refs/heads/master | 2021-01-18T21:32:27.393991 | 2010-02-22T14:05:19 | 2010-02-22T14:05:19 | 275,898 | 1 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 325 | ss | for.ss | #lang scheme/base
(require (for-syntax scheme/base))
(define-syntax (for/sum stx)
(syntax-case stx ()
[(for/sum (for-clause ...) body0 body ...)
(syntax
(for/fold/derived stx
([sum 0])
(for-clause ...)
(+ sum
(begin body0 body ...))))]))
(provide for/sum)
| true |
966e4a1937732b9ef260b1573368a0d178af1b95 | 174072a16ff2cb2cd60a91153376eec6fe98e9d2 | /Chap-two/2-23.scm | db625c6ddfcc15f50c7e3426e05f49af6f754407 | [] | no_license | Wang-Yann/sicp | 0026d506ec192ac240c94a871e28ace7570b5196 | 245e48fc3ac7bfc00e586f4e928dd0d0c6c982ed | refs/heads/master | 2021-01-01T03:50:36.708313 | 2016-10-11T10:46:37 | 2016-10-11T10:46:37 | 57,060,897 | 1 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 154 | scm | 2-23.scm | (define (for-each proc lst)
(if (not (null? lst))
(begin (proc (car lst)) (for-each proc (cdr lst)))))
(define g (lambda (x) (newline) (display x)))
| false |
ed660dfaa2cafdda1a4a74caad5f92f290a9db5a | de82217869618b0a975e86918184ecfddf701172 | /reference/unicode/unicode0.sch | a7cb77344c98aa6ff42073e9af70471b99706a0d | [] | no_license | schemedoc/r6rs | 6b4ef7fd87d8883d6c4bcc422b38b37f588e20f7 | 0009085469e47df44068873f834a0d0282648750 | refs/heads/master | 2021-06-18T17:44:50.149253 | 2020-01-04T10:50:50 | 2020-01-04T10:50:50 | 178,081,881 | 5 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 3,569 | sch | unicode0.sch | ; Copyright 2006 William D Clinger.
;
; Permission to copy this software, in whole or in part, to use this
; software for any lawful purpose, and to redistribute this software
; is granted subject to the restriction that all copies made of this
; software must include this copyright notice in full.
;
; I also request that you send me a copy of any improvements that you
; make to this software so that they may be incorporated within it to
; the benefit of the Scheme community.
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; (proto-unicode0)
;
; This file contains a few auxiliary procedures that are used
; by the reference implementation of the (r6rs unicode) library.
; None of the definitions in this file are exported as part of
; (r6rs unicode).
;
; This file does not rely on any lexical syntax for
; non-Ascii characters and strings.
(library (proto-unicode0)
(export
binary-search-of-vector
binary-search
binary-search-16bit)
(import (r6rs base)
(r6rs bytevector))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; Help procedures (not part of R6RS)
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Given an exact integer key and a vector of exact integers
; in strictly increasing order, returns the largest i such
; that element i of the vector is less than or equal to key,
; or -1 if key is less than every element of the vector.
(define (binary-search-of-vector key vec)
; Loop invariants:
; 0 <= i < j <= (vector-length vec)
; vec[i] <= key
; if j < (vector-length vec), then key < vec[j]
(define (loop i j)
(let ((mid (quotient (+ i j) 2)))
(cond ((= i mid)
mid)
((<= (vector-ref vec mid) key)
(loop mid j))
(else
(loop i mid)))))
(let ((hi (vector-length vec)))
(if (or (= hi 0) (< key (vector-ref vec 0)))
-1
(loop 0 hi))))
; Given an exact integer key and a vector of exact integers
; in strictly increasing order, returns the index of key,
; or returns #f if the key is not within the vector.
(define (binary-search key vec)
; Loop invariants:
; 0 <= i < j <= (vector-length vec)
; vec[i] <= key
; if j < (vector-length vec), then key < vec[j]
(define (loop i j)
(let ((mid (quotient (+ i j) 2)))
(cond ((= i mid)
(if (= key (vector-ref vec mid))
mid
#f))
((<= (vector-ref vec mid) key)
(loop mid j))
(else
(loop i mid)))))
(let ((hi (vector-length vec)))
(if (or (= hi 0) (< key (vector-ref vec 0)))
#f
(loop 0 hi))))
; Given an exact integer key and a bytevector of 16-bit unsigned
; big-endian integers in strictly increasing order,
; returns i such that elements (* 2 i) and (+ (* 2 i) 1)
; are equal to the key, or returns #f if the key is not found.
(define (binary-search-16bit key bvec)
(define (bytevector-ref16 bvec i)
(let ((i2 (+ i i)))
(+ (* 256 (bytevector-u8-ref bvec i2))
(bytevector-u8-ref bvec (+ i2 1)))))
(define (loop i j)
(let ((mid (quotient (+ i j) 2)))
(cond ((= i mid)
(if (= (bytevector-ref16 bvec mid) key)
mid
#f))
((<= (bytevector-ref16 bvec mid) key)
(loop mid j))
(else
(loop i mid)))))
(let ((hi (quotient (bytevector-length bvec) 2)))
(if (or (= hi 0) (< key (bytevector-ref16 bvec 0)))
#f
(loop 0 hi))))
)
| false |
d777bb3083667f0a2a561dea6bf6b4efb5df3911 | ebf028b3a35ae1544bba1a1f9aa635135486ee6c | /sitelib/lunula/gettext.scm | 4e6757fdb54041d3057314a3475a6120f17f0827 | [
"BSD-2-Clause",
"BSD-3-Clause"
] | permissive | tabe/lunula | b4b666151874271211744cce1346e58e3a56fa79 | b7699a850b9c9a64c1d3a52d50ce20050bd17475 | refs/heads/master | 2021-01-01T20:04:43.571993 | 2010-05-06T15:39:31 | 2010-05-06T15:39:31 | 334,916 | 2 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 1,452 | scm | gettext.scm | (library (lunula gettext)
(export __
___
gettext
locale
localize)
(import (only (core) make-parameter parameterize)
(rnrs))
(define *default-locale* 'en)
(define *locale-table*
(let ((table (make-eq-hashtable 2)))
(hashtable-set! table 'en (make-eq-hashtable))
(hashtable-set! table 'ja (make-eq-hashtable))
table))
(define *locale* (make-parameter *default-locale*))
(define-syntax locale
(syntax-rules ()
((_ loc) (*locale* 'loc))
((_) (*locale*))))
(define (___ msgid)
(cond ((hashtable-ref *locale-table* (locale) #f)
=> (lambda (table)
(or (hashtable-ref table msgid #f)
(symbol->string msgid))))
(else (symbol->string msgid))))
(define-syntax __
(syntax-rules ()
((_ msgid)
(___ 'msgid))))
(define-syntax localize
(syntax-rules ()
((_ lang e0 e1 ...)
(let ((x lang))
(cond ((symbol? x)
(parameterize ((*locale* x))
e0 e1 ...))
(else e0 e1 ...))))))
(define-syntax gettext
(syntax-rules ()
((_ (msgid (loc msgstr) ...) clause ...)
(begin
(let ((table (hashtable-ref *locale-table* 'loc #f)))
(if (hashtable? table)
(hashtable-set! table 'msgid msgstr)))
...
(gettext clause ...)))
((_)
#f)))
)
| true |
57d3168110155e40170c483888663acefd6e649f | 4f17c70ae149426a60a9278c132d5be187329422 | /scheme/tests/racket-r6rs/arithmetic/bitwise.sls | 1611e405ffedf25263d46f73b1136ddd2f72c242 | [] | no_license | okuoku/yuni-core | 8da5e60b2538c79ae0f9d3836740c54d904e0da4 | c709d7967bcf856bdbfa637f771652feb1d92625 | refs/heads/master | 2020-04-05T23:41:09.435685 | 2011-01-12T15:54:23 | 2011-01-12T15:54:23 | 889,749 | 2 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 9,899 | sls | bitwise.sls | #!r6rs
(library (yuni scheme tests racket-r6rs arithmetic bitwise)
(export run-arithmetic-bitwise-tests)
(import (yuni scheme r6rs)
(yuni scheme tests racket-r6rs test))
;; Helpers originally from Ikarus test suite:
(define (ref ei)
(do ((result 0 (+ result 1))
(bits (if (negative? ei)
(bitwise-not ei)
ei)
(bitwise-arithmetic-shift bits -1)))
((zero? bits)
result)))
(define-syntax len-test
(syntax-rules ()
[(_ n) (test (bitwise-length n)
(ref n))]))
(define (pos-count-bits n)
(if (zero? n)
0
(let ([c (count-bits (bitwise-arithmetic-shift-right n 1))])
(if (even? n) c (+ c 1)))))
(define (count-bits n)
(if (>= n 0)
(pos-count-bits n)
(bitwise-not (pos-count-bits (bitwise-not n)))))
(define-syntax count-test
(syntax-rules ()
[(_ n)
(test (bitwise-bit-count n) (count-bits n))]))
(define (run-arithmetic-bitwise-tests)
(test (bitwise-first-bit-set 0) -1)
(test (bitwise-first-bit-set 1) 0)
(test (bitwise-first-bit-set -4) 2)
(test (bitwise-arithmetic-shift -6 -1) -3)
(test (bitwise-arithmetic-shift -5 -1) -3)
(test (bitwise-arithmetic-shift -4 -1) -2)
(test (bitwise-arithmetic-shift -3 -1) -2)
(test (bitwise-arithmetic-shift -2 -1) -1)
(test (bitwise-arithmetic-shift -1 -1) -1)
(test (bitwise-reverse-bit-field #b1010010 1 4) 88) ; #b1011000
;; Originally from Ikarus test suite:
(len-test #xF)
(len-test #xFF)
(len-test #xFFF)
(len-test #xFFFF)
(len-test #xFFFFF)
(len-test #xFFFFFF)
(len-test #xFFFFFFF)
(len-test #xFFFFFFFF)
(len-test #xFFFFFFFFF)
(len-test #xFFFFFFFFFF)
(len-test #xFFFFFFFFFFF)
(len-test #xFFFFFFFFFFFF)
(len-test #xFFFFFFFFFFFFF)
(len-test #xFFFFFFFFFFFFFF)
(len-test #xFFFFFFFFFFFFFFF)
(len-test #xFFFFFFFFFFFFFFFF)
(len-test #x-F)
(len-test #x-FF)
(len-test #x-FFF)
(len-test #x-FFFF)
(len-test #x-FFFFF)
(len-test #x-FFFFFF)
(len-test #x-FFFFFFF)
(len-test #x-FFFFFFFF)
(len-test #x-FFFFFFFFF)
(len-test #x-FFFFFFFFFF)
(len-test #x-FFFFFFFFFFF)
(len-test #x-FFFFFFFFFFFF)
(len-test #x-FFFFFFFFFFFFF)
(len-test #x-FFFFFFFFFFFFFF)
(len-test #x-FFFFFFFFFFFFFFF)
(len-test #x-FFFFFFFFFFFFFFFF)
(len-test #xE)
(len-test #xFE)
(len-test #xFFE)
(len-test #xFFFE)
(len-test #xFFFFE)
(len-test #xFFFFFE)
(len-test #xFFFFFFE)
(len-test #xFFFFFFFE)
(len-test #xFFFFFFFFE)
(len-test #xFFFFFFFFFE)
(len-test #xFFFFFFFFFFE)
(len-test #xFFFFFFFFFFFE)
(len-test #xFFFFFFFFFFFFE)
(len-test #xFFFFFFFFFFFFFE)
(len-test #xFFFFFFFFFFFFFFE)
(len-test #xFFFFFFFFFFFFFFFE)
(len-test #x-E)
(len-test #x-FE)
(len-test #x-FFE)
(len-test #x-FFFE)
(len-test #x-FFFFE)
(len-test #x-FFFFFE)
(len-test #x-FFFFFFE)
(len-test #x-FFFFFFFE)
(len-test #x-FFFFFFFFE)
(len-test #x-FFFFFFFFFE)
(len-test #x-FFFFFFFFFFE)
(len-test #x-FFFFFFFFFFFE)
(len-test #x-FFFFFFFFFFFFE)
(len-test #x-FFFFFFFFFFFFFE)
(len-test #x-FFFFFFFFFFFFFFE)
(len-test #x-FFFFFFFFFFFFFFFE)
(len-test #x1)
(len-test #x1F)
(len-test #x1FF)
(len-test #x1FFF)
(len-test #x1FFFF)
(len-test #x1FFFFF)
(len-test #x1FFFFFF)
(len-test #x1FFFFFFF)
(len-test #x1FFFFFFFF)
(len-test #x1FFFFFFFFF)
(len-test #x1FFFFFFFFFF)
(len-test #x1FFFFFFFFFFF)
(len-test #x1FFFFFFFFFFFF)
(len-test #x1FFFFFFFFFFFFF)
(len-test #x1FFFFFFFFFFFFFF)
(len-test #x1FFFFFFFFFFFFFFF)
(len-test #x-1)
(len-test #x-1F)
(len-test #x-1FF)
(len-test #x-1FFF)
(len-test #x-1FFFF)
(len-test #x-1FFFFF)
(len-test #x-1FFFFFF)
(len-test #x-1FFFFFFF)
(len-test #x-1FFFFFFFF)
(len-test #x-1FFFFFFFFF)
(len-test #x-1FFFFFFFFFF)
(len-test #x-1FFFFFFFFFFF)
(len-test #x-1FFFFFFFFFFFF)
(len-test #x-1FFFFFFFFFFFFF)
(len-test #x-1FFFFFFFFFFFFFF)
(len-test #x-1FFFFFFFFFFFFFFF)
(len-test #x1)
(len-test #x10)
(len-test #x100)
(len-test #x1000)
(len-test #x10000)
(len-test #x100000)
(len-test #x1000000)
(len-test #x10000000)
(len-test #x100000000)
(len-test #x1000000000)
(len-test #x10000000000)
(len-test #x100000000000)
(len-test #x1000000000000)
(len-test #x10000000000000)
(len-test #x100000000000000)
(len-test #x1000000000000000)
(len-test #x-1)
(len-test #x-10)
(len-test #x-100)
(len-test #x-1000)
(len-test #x-10000)
(len-test #x-100000)
(len-test #x-1000000)
(len-test #x-10000000)
(len-test #x-100000000)
(len-test #x-1000000000)
(len-test #x-10000000000)
(len-test #x-100000000000)
(len-test #x-1000000000000)
(len-test #x-10000000000000)
(len-test #x-100000000000000)
(len-test #x-1000000000000000)
(len-test #x1)
(len-test #x11)
(len-test #x101)
(len-test #x1001)
(len-test #x10001)
(len-test #x100001)
(len-test #x1000001)
(len-test #x10000001)
(len-test #x100000001)
(len-test #x1000000001)
(len-test #x10000000001)
(len-test #x100000000001)
(len-test #x1000000000001)
(len-test #x10000000000001)
(len-test #x100000000000001)
(len-test #x1000000000000001)
(len-test #x-1)
(len-test #x-11)
(len-test #x-101)
(len-test #x-1001)
(len-test #x-10001)
(len-test #x-100001)
(len-test #x-1000001)
(len-test #x-10000001)
(len-test #x-100000001)
(len-test #x-1000000001)
(len-test #x-10000000001)
(len-test #x-100000000001)
(len-test #x-1000000000001)
(len-test #x-10000000000001)
(len-test #x-100000000000001)
(len-test #x-1000000000000001)
(len-test (greatest-fixnum))
(len-test (least-fixnum))
(count-test 1)
(count-test 28472347823493290482390849023840928390482309480923840923840983)
(count-test -847234234903290482390849023840928390482309480923840923840983)
(count-test (greatest-fixnum))
(count-test (least-fixnum))
(test (bitwise-not 12) -13)
(test (bitwise-not -12) 11)
(test (bitwise-not -1) 0)
(test (bitwise-not 0) -1)
(test (least-fixnum) (bitwise-not (greatest-fixnum)))
(test (greatest-fixnum) (bitwise-not (least-fixnum)))
(test (bitwise-not 38947389478348937489374)
-38947389478348937489375)
(test (bitwise-not #xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)
-22300745198530623141535718272648361505980416)
(test (bitwise-not -38947389478348937489375)
38947389478348937489374)
(test (bitwise-not #x-FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)
22300745198530623141535718272648361505980414)
(test (bitwise-not #xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)
-340282366920938463463374607431768211456)
(test (bitwise-not #x-FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)
340282366920938463463374607431768211454)
(test (bitwise-not #x1000000000000000000000000)
-79228162514264337593543950337)
(test (bitwise-not #x-1000000000000000000000000)
79228162514264337593543950335)
;; ----------------------------------------
(test (bitwise-and (expt 2 100) 17) 0)
(test (bitwise-and (- (expt 2 100) 1) 17) 17)
(test (bitwise-and (- (expt 2 100) 1) (expt 2 90)) (expt 2 90))
(test (bitwise-xor (expt 2 100) 17) (bitwise-ior (expt 2 100) 17))
(test (bitwise-xor (- (expt 2 100) 1) 17) (- (expt 2 100) 18))
(test (bitwise-xor (- (expt 2 100) 1) (expt 2 90)) (- (expt 2 100) (expt 2 90) 1))
(test (bitwise-if (expt 2 100) -1 1) (+ (expt 2 100) 1))
(test (bitwise-if (expt 2 100) 1 1) 1)
(test (bitwise-if (expt 2 100) (- (expt 2 200) 1) 1) (+ (expt 2 100) 1))
(test (bitwise-bit-count (expt 2 300)) 1)
(test (bitwise-bit-count (- (expt 2 300) 1)) 300)
(test (bitwise-bit-count (- (expt 2 300))) -301)
(test (bitwise-length (expt 2 300)) 301)
(test (bitwise-length (- (expt 2 300) 1)) 300)
(test (bitwise-length (- (expt 2 300))) 300)
(test (bitwise-first-bit-set (expt 2 300)) 300)
(test (bitwise-first-bit-set (- (expt 2 300) 1)) 0)
(test (bitwise-bit-set? (expt 2 300) 300) #t)
(test (bitwise-bit-set? (expt 2 300) 0) #f)
(test (bitwise-bit-set? (- (expt 2 300) 1) 300) #f)
(test (bitwise-bit-set? (- (expt 2 300) 1) 299) #t)
(test (bitwise-bit-set? (- (expt 2 300) 1) 298) #t)
(test (bitwise-bit-set? (- (expt 2 300) 2) 0) #f)
(test (bitwise-bit-set? -1 300) #t)
(test (bitwise-bit-set? -1 0) #t)
(test (bitwise-bit-set? -2 0) #f)
(test (bitwise-copy-bit-field (expt 2 300) 300 302 0) 0)
(test (bitwise-copy-bit-field (expt 2 300) 300 302 1) (expt 2 300))
(test (bitwise-copy-bit-field (expt 2 300) 300 302 2) (expt 2 301))
(test (bitwise-copy-bit-field (expt 2 300) 300 302 3) (+ (expt 2 300)
(expt 2 301)))
(test (bitwise-arithmetic-shift (expt 2 300) 1) (expt 2 301))
(test (bitwise-arithmetic-shift (expt 2 300) -1) (expt 2 299))
(test (bitwise-arithmetic-shift (expt 2 300) 300) (expt 2 600))
(test (bitwise-arithmetic-shift (expt 2 300) -300) 1)
(test (bitwise-arithmetic-shift-left (expt 2 300) 1) (expt 2 301))
(test (bitwise-arithmetic-shift-right (expt 2 300) 1) (expt 2 299))
(test (bitwise-arithmetic-shift-left (expt 2 300) 300) (expt 2 600))
(test (bitwise-arithmetic-shift-right (expt 2 300) 300) 1)
(test (bitwise-rotate-bit-field (expt 2 300) 299 304 2) (expt 2 302))
(test (bitwise-rotate-bit-field (expt 2 300) 299 304 4) (expt 2 299))
(test (bitwise-reverse-bit-field (expt 2 300) 299 304) (expt 2 302))
;;
))
| true |
a90d74b074806fec9f42d3712ee021994189f084 | fc070119c083d67c632e3f377b0585f77053331e | /exercises/07/invert.scm | d1b678eb65c35afd01d01c7b0ae773f7894a4765 | [] | no_license | dimitaruzunov/fp-2018 | abcd90396e9e8b73efe4e2b8a0634866948269a8 | f75f0cd009cc7f41ce55a5ec71fb4b8eadafc4eb | refs/heads/master | 2020-03-31T11:01:55.426456 | 2019-01-08T20:22:16 | 2019-01-08T20:22:16 | 152,160,081 | 9 | 3 | null | null | null | null | UTF-8 | Scheme | false | false | 2,536 | scm | invert.scm | (require rackunit rackunit/text-ui)
(define (every? p l)
(or (null? l)
(and (p (car l))
(every? p (cdr l)))))
(define (flatmap fn l)
(apply append (map fn l)))
(define (search p l)
(and (not (null? l))
(or (p (car l))
(search p (cdr l)))))
(define (add-if-missing x l)
(if (member x l)
l
(cons x l)))
(define (make-alist fn keys)
(map (lambda (key) (cons key (fn key)))
keys))
(define (keys alist)
(map car alist))
(define (assoc key alist)
(search (lambda (key-value-pair)
(and (equal? (car key-value-pair) key)
key-value-pair))
alist))
(define (del-assoc key alist)
(filter (lambda (key-value-pair)
(not (equal? (car key-value-pair) key)))
alist))
(define (add-assoc key value alist)
(cons (cons key value)
(del-assoc key alist)))
(define (empty-graph) '())
(define (make-graph vs)
(make-alist (lambda (_) '())
vs))
(define vertices keys)
(define (children v g)
(cdr (assoc v g)))
(define (add-vertex v g)
(if (assoc v g)
g
(add-assoc v '() g)))
(define (add-edge u v g)
(let ((g-with-u-v (add-vertex v (add-vertex u g))))
(add-assoc u
(add-if-missing v (children u g-with-u-v))
g-with-u-v)))
(define (edges g)
(flatmap (lambda (vertex)
(map (lambda (child) (list vertex child))
(children vertex g)))
(vertices g)))
(define (invert g)
(foldl (lambda (edge g-inverted)
(add-edge (cadr edge) (car edge) g-inverted))
(make-graph (vertices g))
(edges g)))
(define graph
(add-vertex
'd
(add-edge
'c 'b
(add-edge
'b 'c
(add-edge
'a 'c
(add-edge
'a 'b
(empty-graph)))))))
(define graph-inverted
(add-vertex
'd
(add-edge
'b 'c
(add-edge
'c 'b
(add-edge
'c 'a
(add-edge
'b 'a
(empty-graph)))))))
(define (subset? s1 s2)
(every? (lambda (x) (member x s2))
s1))
(define (set-equal? s1 s2)
(and (subset? s1 s2)
(subset? s2 s1)))
(define (graphs-equal? g1 g2)
(define (vertices-equal? g1 g2)
(set-equal? (vertices g1) (vertices g2)))
(define (edges-equal? g1 g2)
(set-equal? (edges g1) (edges g2)))
(and (vertices-equal? g1 g2)
(edges-equal? g1 g2)))
(define invert-tests
(test-suite
"Tests for invert"
(check graphs-equal? (invert graph) graph-inverted)))
(run-tests invert-tests)
| false |
822275712a3152843eb4ec580f1f3fa57dc017df | 74d2f4ec77852839450ab8563971a5e0f615c019 | /chapter_02/exercise_2_32.scm | 2bfe103719eb914c7fc71f17de962348ae60b541 | [] | no_license | wangoasis/sicp | b56960a0c3202ce987f176507b1043ed632ed6b3 | 07eaf8d46f7b8eae5a46d338a4608d8e993d4568 | refs/heads/master | 2021-01-21T13:03:11.520829 | 2016-04-22T13:52:15 | 2016-04-22T13:52:15 | 53,835,426 | 0 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 271 | scm | exercise_2_32.scm | ( define x ( list 1 2 3 ) )
( define ( subsets s )
( if ( null? s )
( list '() )
( let ( ( rest ( subsets ( cdr s ) ) ) )
( append rest ( map
( lambda (x) ( cons ( car s ) x ) )
rest ) ) ) ) )
| false |
fe8ec5680c025076a35cffcc5b825ca4796dcf45 | e1fc47ba76cfc1881a5d096dc3d59ffe10d07be6 | /ch3/3.27.v2.scm | d6363c4f4723c29b529536009a24e96ca6439787 | [] | 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 | 254 | scm | 3.27.v2.scm | (load "3.27.memo.scm")
(define (fib n)
(cond
((= n 0) 0)
((= n 1) 1)
(else (+ (memo-fib (- n 1)) (memo-fib (- n 2))))
)
)
(define memo-fib (memorize fib))
(display (memo-fib 30))(newline)
; real 0m0.023s
; user 0m0.023s
; sys 0m0.000s
| false |
de23da9d78ea4d76f72fb0c1f643179b4da46ad1 | ea4e27735dd34917b1cf62dc6d8c887059dd95a9 | /section2_2_exercise2_19.scm | ab32f5254b4c5e2acbcced3ff270611ecb5c8c8c | [
"MIT"
] | permissive | feliposz/sicp-solutions | 1f347d4a8f79fca69ef4d596884d07dc39d5d1ba | 5de85722b2a780e8c83d75bbdc90d654eb094272 | refs/heads/master | 2022-04-26T18:44:32.025903 | 2022-03-12T04:27:25 | 2022-03-12T04:27:25 | 36,837,364 | 1 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 1,485 | scm | section2_2_exercise2_19.scm | ; A modified version of count-change using lists as parameters for the
; denomination of coin-values.
(define (count-change amount coin-values)
(cc amount coin-values))
(define (cc amount coin-values)
(cond ((= amount 0) 1)
((or (< amount 0) (no-more? coin-values)) 0)
(else (+ (cc amount
(except-first-denomination coin-values))
(cc (- amount (first-denomination coin-values))
coin-values)))))
(define first-denomination car)
(define except-first-denomination cdr)
(define no-more? null?)
(define us-coins (list 50 25 10 5 1))
(define uk-coins (list 100 50 20 10 5 2 1 0.5))
(count-change 11 us-coins) ;=> 4
(count-change 100 us-coins) ;=> 292
(count-change 11 uk-coins) ;=> 62
(count-change 20 uk-coins) ;=> 293
(count-change 30 uk-coins) ;=> 1022
(count-change 40 uk-coins) ;=> 2728
(count-change 50 uk-coins) ;=> 6149 (somewhat slow)
;(count-change 100 uk-coins) ;=> (takes a loooong time)
; Test for other orders in the list of coins
(count-change 11 (reverse us-coins)) ;=> 4
(count-change 100 (reverse us-coins)) ;=> 292
(count-change 11 (reverse uk-coins)) ;=> should be 62
(count-change 40 (reverse uk-coins)) ;=> should be 2728
; scrambled
(count-change 11 (list 50 1 5 10 25)) ;=> 4
; The order of elements in the coin-values list doesn't affect the result of
; computation because the procedure is designed to compute combinations regardless
; of the value of the coins and it's order, since every possible combination
; is tested anyway. | false |
9c5398f6f6721708335053bf08c2833d46df6ef2 | 2c01a6143d8630044e3629f2ca8adf1455f25801 | /xitomatl/R6RS-lexical-transformations.sls | e6670d14e22a1d626c2af92ba047dc104d03a50f | [
"X11-distribute-modifications-variant"
] | permissive | stuhlmueller/scheme-tools | e103fac13cfcb6d45e54e4f27e409adbc0125fe1 | 6e82e873d29b34b0de69b768c5a0317446867b3c | refs/heads/master | 2021-01-25T10:06:33.054510 | 2017-05-09T19:44:12 | 2017-05-09T19:44:12 | 1,092,490 | 5 | 1 | null | null | null | null | UTF-8 | Scheme | false | false | 6,579 | sls | R6RS-lexical-transformations.sls | #!r6rs
;; Copyright 2009 Derick Eddington. My MIT-style license is in the file named
;; LICENSE from the original collection this file is distributed with.
(library (xitomatl R6RS-lexical-transformations)
(export
#;delete-trailing-whitespace
brackets->parens
upcase-booleans
hashbang-r6rs-first
transform-file
transform-walk
append-lexemes)
(import
(rnrs)
(srfi :2 and-let*)
(only (xitomatl define) define/who)
(only (xitomatl ports) textual-input-port?)
(only (xitomatl records) record-type-accessors)
(only (xitomatl enumerators) fold)
(only (xitomatl predicates) not?)
(only (xitomatl file-system base) directory-walk)
(only (xitomatl file-system paths) path-join)
(only (xitomatl common) printf)
(only (xitomatl lexer) token-lexeme)
(xitomatl R6RS-lexer))
(define (append-lexemes tokens)
(apply string-append (map token-lexeme tokens)))
(define (make-transformation who proc)
(define (t x)
(define (lex p)
(and-let* ((l (t (R6RS-lexer x))))
(p l)))
(cond ((list? x)
(proc x))
((textual-input-port? x)
(lex (lambda (l) (open-string-input-port (append-lexemes l)))))
((string? x)
(lex append-lexemes))
(else
(assertion-violation who "invalid argument" x))))
t)
(define (get-fields x)
(map (lambda (a) (a x)) (record-type-accessors (record-rtd x))))
#;(define/who delete-trailing-whitespace
TODO)
(define/who brackets->parens
(make-transformation who
(lambda (tokens)
(let-values (((accum modified?)
(fold tokens
(lambda (t a m)
(define (trans make lexeme)
(apply make lexeme (cdr (get-fields t))))
(cond ((open-bracket-token? t)
(values #T
(cons (trans make-open-paren-token "(") a)
#T))
((close-bracket-token? t)
(values #T
(cons (trans make-close-paren-token ")") a)
#T))
(else (values #T (cons t a) m))))
'() #F)))
(and modified? (reverse accum))))))
(define/who upcase-booleans
(make-transformation who
(lambda (tokens)
(let-values (((accum modified?)
(fold tokens
(lambda (t a m)
(define (trans lexeme)
(apply make-boolean-token lexeme (cdr (get-fields t))))
(if (boolean-token? t)
(let ((l (token-lexeme t)))
(cond ((string=? "#t" l)
(values #T (cons (trans "#T") a) #T))
((string=? "#f" l)
(values #T (cons (trans "#F") a) #T))
(else (values #T (cons t a) m))))
(values #T (cons t a) m)))
'() #F)))
(and modified? (reverse accum))))))
(define/who hashbang-r6rs-first
(make-transformation who
(lambda (tokens)
(define (it? l)
(and (pair? l) (pair? (cdr l)) (pair? (cddr l))
(hashbang-comment-token? (car l))
#;(string=? "#!" (token-lexeme (car l)))
(identifier-token? (cadr l))
(string=? "r6rs" (token-lexeme (cadr l)))
(whitespace-token? (caddr l))
(char=? #\newline (string-ref (token-lexeme (caddr l)) 0))))
#;(define (adjust-counts l)
(R6RS-lexer (append-lexemes l)))
(define (invalidate-counts l)
(map (lambda (x)
#;(assert (R6RS-token? x))
((record-constructor
(make-record-constructor-descriptor (record-rtd x) #F #F))
(token-lexeme x) #F #F #F))
l))
(define (separate l)
(let loop ((l l) (pre '()))
(if (null? l)
(values #F #F)
(if (it? l)
(values (reverse pre)
(let ((s (token-lexeme (caddr l))))
(if (> (string-length s) 1)
(cons (make-whitespace-token
(substring s 1 (string-length s)) #F #F #F)
(cdddr l))
(cdddr l))))
(loop (cdr l) (cons (car l) pre))))))
(define (omit? l)
(and-let* ((l (memp (not? atmosphere-token?) l)))
(and (>= (length l) 2)
(open-paren-token? (car l))
(identifier-token? (cadr l))
(member (token-lexeme (cadr l)) '("library" "import")))))
(and (pair? tokens)
(not (it? tokens))
(cons* (make-hashbang-comment-token "#!" #F #F #F)
(make-identifier-token "r6rs" #F #F #F)
(make-whitespace-token "\n" #F #F #F)
(invalidate-counts
(let-values (((pre post) (separate tokens)))
(if (and post (omit? post))
(append pre post)
tokens))))))))
(define (transform-file file . transformers)
(define (output-port f)
(open-file-output-port f
(file-options no-fail) (buffer-mode block) (native-transcoder)))
(let loop ((tokens (call-with-input-file file R6RS-lexer))
(t transformers)
(mod #F))
(if (null? t)
(and mod
(call-with-port (output-port file)
(lambda (fop)
(for-each (lambda (tok) (put-string fop (token-lexeme tok)))
tokens)
#T)))
(let ((toks ((car t) tokens)))
(loop (or toks tokens)
(cdr t)
(if toks #T mod))))))
(define (transform-walk dir pred . transformers)
(directory-walk
(lambda (path dirs files syms)
(for-each
(lambda (f)
(let ((f (path-join path f)))
(when (pred f)
(printf "~a ... " f)
(if (apply transform-file f transformers)
(display "wrote new contents\n")
(display "not modified\n")))))
files))
dir))
)
| false |
060f2acf8c64087f74431fa378bd5e6f2153aa13 | 6aa3ae88e6f9e25163ceaedf5bb580b2cb8669bb | /dialects/string-ports.scm | 3fb662e9f3653dfa5b465b79a48255aa531da84e | [
"LicenseRef-scancode-warranty-disclaimer"
] | no_license | ds26gte/tex2page | fc0f4442a1718d0af9c2b6eaa03400e34f9e4242 | 66d04e93147b3e5dbf3774597217f79c4853ad0c | refs/heads/master | 2023-01-11T20:58:49.827831 | 2023-01-05T16:43:48 | 2023-01-05T16:43:48 | 23,206,061 | 28 | 3 | NOASSERTION | 2022-12-20T07:22:23 | 2014-08-21T23:15:29 | Racket | UTF-8 | Scheme | false | false | 992 | scm | string-ports.scm | ;string ports
(define *output-strings* '())
(define open-output-string
(let ((n 0))
(lambda ()
(let ((f (string-append *jobname* "-Z-SC-"
(number->string n) ".scm")))
(set! n (+ n 1))
(if (file-exists? f)
;try again
(open-output-string)
(let ((o (open-output-file f)))
(set! *output-strings*
(cons (cons o f) *output-strings*))
o))))))
(define get-output-string
(lambda (o)
(let ((o-f (assv o *output-strings*)))
(let ((o (car o-f))
(f (cdr o-f)))
(close-output-port o)
(let ((s (call-with-input-file f
(lambda (o)
(let loop ((r '()))
(let ((c (read-char o)))
(if (eof-object? c)
(list->string (reverse! r))
(loop (cons c r)))))))))
(delete-file f)
s)))))
| false |
a801642a4c90bd7715776e6bbf0aaff8f95f00d4 | 43612e5ed60c14068da312fd9d7081c1b2b7220d | /unit-tests/IFT3065/1/etape1-lt1.scm | 412235251aaf4b0edb9b525f8b0d4530a1c3064b | [
"BSD-3-Clause"
] | permissive | bsaleil/lc | b1794065183b8f5fca018d3ece2dffabda6dd9a8 | ee7867fd2bdbbe88924300e10b14ea717ee6434b | refs/heads/master | 2021-03-19T09:44:18.905063 | 2019-05-11T01:36:38 | 2019-05-11T01:36:38 | 41,703,251 | 27 | 1 | BSD-3-Clause | 2018-08-29T19:13:33 | 2015-08-31T22:13:05 | Scheme | UTF-8 | Scheme | false | false | 121 | scm | etape1-lt1.scm | (println (< 7 3))
(println (< -7 3))
(println (< 7 -3))
(println (< -7 -3))
(println (< 5 5))
;#f
;#t
;#f
;#t
;#f
| false |
bac631bf37c46b76e3d1fa68bbd756dc604fec79 | a8216d80b80e4cb429086f0f9ac62f91e09498d3 | /lib/srfi/160/f64.sld | 15e05bab4eac1d851e165bf2518f1b6019ef8e58 | [
"BSD-3-Clause"
] | permissive | ashinn/chibi-scheme | 3e03ee86c0af611f081a38edb12902e4245fb102 | 67fdb283b667c8f340a5dc7259eaf44825bc90bc | refs/heads/master | 2023-08-24T11:16:42.175821 | 2023-06-20T13:19:19 | 2023-06-20T13:19:19 | 32,322,244 | 1,290 | 223 | NOASSERTION | 2023-08-29T11:54:14 | 2015-03-16T12:05:57 | Scheme | UTF-8 | Scheme | false | false | 2,847 | sld | f64.sld |
(define-library (srfi 160 f64)
(export
make-f64vector
f64?
f64vector?
f64vector-ref
f64vector-set!
f64vector-length
(rename uvector-unfold f64vector-unfold)
(rename uvector-unfold-right f64vector-unfold-right)
(rename vector-copy f64vector-copy)
(rename vector-reverse-copy f64vector-reverse-copy)
(rename vector-append f64vector-append)
(rename vector-concatenate f64vector-concatenate)
(rename vector-append-subvectors f64vector-append-subvectors)
(rename vector-empty? f64vector-empty?)
(rename vector= f64vector=)
(rename vector-take f64vector-take)
(rename vector-take-right f64vector-take-right)
(rename vector-drop f64vector-drop)
(rename vector-drop-right f64vector-drop-right)
(rename vector-segment f64vector-segment)
(rename vector-fold f64vector-fold)
(rename vector-fold-right f64vector-fold-right)
(rename vector-map f64vector-map)
(rename vector-map! f64vector-map!)
(rename vector-for-each f64vector-for-each)
(rename vector-count f64vector-count)
(rename vector-cumulate f64vector-cumulate)
(rename vector-take-while f64vector-take-while)
(rename vector-take-while-right f64vector-take-while-right)
(rename vector-drop-while f64vector-drop-while)
(rename vector-drop-while-right f64vector-drop-while-right)
(rename vector-index f64vector-index)
(rename vector-index-right f64vector-index-right)
(rename vector-skip f64vector-skip)
(rename vector-skip-right f64vector-skip-right)
(rename vector-binary-search f64vector-binary-search)
(rename vector-any f64vector-any)
(rename vector-every f64vector-every)
(rename vector-partition f64vector-partition)
(rename vector-filter f64vector-filter)
(rename vector-remove f64vector-remove)
(rename vector-swap! f64vector-swap!)
(rename vector-fill! f64vector-fill!)
(rename vector-reverse! f64vector-reverse!)
(rename vector-copy! f64vector-copy!)
(rename vector-reverse-copy! f64vector-reverse-copy!)
(rename reverse-vector->list reverse-f64vector->list)
(rename reverse-list->vector reverse-list->f64vector)
(rename uvector->vector f64vector->vector)
(rename vector->uvector vector->f64vector)
(rename make-vector-generator make-f64vector-generator)
(rename write-vector write-f64vector))
(import (except (scheme base)
vector-append vector-copy vector-copy!
vector-map vector-for-each)
(scheme write)
(srfi 160 base))
(begin
(define uvector? f64vector?)
(define make-uvector make-f64vector)
(define vector f64vector)
(define uvector->list f64vector->list)
(define list->uvector list->f64vector)
(define uvector-length f64vector-length)
(define uvector-ref f64vector-ref)
(define uvector-set! f64vector-set!))
(include "uvector.scm"))
| false |
11c4b5cdc90c593e8c935fba8bacac919b5afa7b | 5f9ab576af62916ada4bdf01c836985ec8149794 | /ref-liv/derived-syntax.scm | 77d915d1289b31013e7bf3b7687521e44ffe6554 | [
"MIT"
] | permissive | niyarin/kallcc | 9cb51fd3f71a309dbbb774f983be2b9d4cfaf8b4 | e7c067ad3b5e59b86b1f0fa2eed9cc9a7c51ab87 | refs/heads/master | 2023-07-27T01:45:04.369655 | 2021-09-05T04:26:06 | 2021-09-05T04:26:06 | 221,103,789 | 2 | 1 | null | null | null | null | UTF-8 | Scheme | false | false | 255 | scm | derived-syntax.scm | (define-library (kallcc-core syntax1)
(import (onif-lib core))
(export let)
(begin
(define-syntax let;simple
(syntax-rules ()
((let ((variable init) ...) bodies ...)
((lambda (variable ...) bodies ...) init ...))))
))
| true |
3d004cd19505ae4ce9b300db97386f0d8f7777ae | f4cf5bf3fb3c06b127dda5b5d479c74cecec9ce9 | /Sources/LispKit/Resources/Libraries/lispkit/list/set.sld | 4ffdb8e48e581ab486c80c25c8465ef689158552 | [
"Apache-2.0"
] | permissive | objecthub/swift-lispkit | 62b907d35fe4f20ecbe022da70075b70a1d86881 | 90d78a4de3a20447db7fc33bdbeb544efea05dda | refs/heads/master | 2023-08-16T21:09:24.735239 | 2023-08-12T21:37:39 | 2023-08-12T21:37:39 | 57,930,217 | 356 | 17 | Apache-2.0 | 2023-06-04T12:11:51 | 2016-05-03T00:37:22 | Scheme | UTF-8 | Scheme | false | false | 7,057 | sld | set.sld | ;;; LISPKIT LIST SET
;;;
;;; Simple implementation of list-based sets.
;;;
;;; Portions of this code: SRFI 1 reference implementation
;;; Copyright © 1998, 1999 by Olin Shivers.
;;; You may do as you please with this code as long as you do not remove this copyright
;;; notice or hold me liable for its use. Please send bug reports to [email protected].
;;;
;;; Author: Matthias Zenger
;;; Copyright © 2023 Matthias Zenger. All rights reserved.
;;;
;;; Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
;;; except in compliance with the License. You may obtain a copy of the License at
;;;
;;; http://www.apache.org/licenses/LICENSE-2.0
;;;
;;; Unless required by applicable law or agreed to in writing, software distributed under the
;;; License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
;;; either express or implied. See the License for the specific language governing permissions
;;; and limitations under the License.
(define-library (lispkit list set)
(export lset
list->lset
lset<=?
lset=?
lset-contains?
lset-adjoin
lset-union
lset-intersection
lset-difference
lset-xor
lset-diff+intersection)
(import (lispkit base))
(begin
(define (list->lset = lst)
(cond ((eq? = eq?)
(list->lset/eq lst values))
((eq? = eqv?)
(list->lset/eqv lst values))
(else
(let rec ((lst lst)
(cont values))
(if (null? lst)
(cont '())
(let* ((x (car lst)))
(rec (delete x (cdr lst) =) (lambda (y) (cont (cons x y))))))))))
(define (list->lset/eq lst cont)
(if (null? lst)
(cont '())
(let* ((x (car lst)))
(list->lset/eq (delq x (cdr lst)) (lambda (y) (cont (cons x y)))))))
(define (list->lset/eqv lst cont)
(if (null? lst)
(cont '())
(let* ((x (car lst)))
(list->lset/eqv (delv x (cdr lst)) (lambda (y) (cont (cons x y)))))))
(define (lset = . elements)
(list->lset = elements))
(define (lset<=? = . lists)
(or (null? lists)
(let rec ((head (car lists))
(rest (cdr lists)))
(or (null? rest)
(let ((next (car rest)))
(and (or (eq? head next) (every? (lambda (x) (member x next =)) head))
(rec next (cdr rest))))))))
(define (lset=? = . lists)
(or (null? lists)
(let rec ((head (car lists))
(rest (cdr lists)))
(or (null? rest)
(let ((next (car rest)))
(and (or (eq? head next)
(and (every? (lambda (x) (member x next =)) head)
(every? (lambda (x) (member x head =)) next))
(rec next (cdr rest)))))))))
(define (lset-contains? = lst e)
(cond ((eq? = eq?)
(and (memq e lst) #t))
((eq? = eqv?)
(and (memv e lst) #t))
(else
(and (member e lst =) #t))))
(define (lset-adjoin = list . elts)
(cond ((eq? = eq?)
(lset-adjoin/eq list elts))
((eq? = eqv?)
(lset-adjoin/eqv list elts))
(else
(let rec ((list list)
(elts elts))
(if (null? elts)
list
(if (member (car elts) list =)
(rec list (cdr elts))
(rec (cons (car elts) list) (cdr elts))))))))
(define (lset-adjoin/eq list elts)
(if (null? elts)
list
(if (memq (car elts) list)
(lset-adjoin/eq list (cdr elts))
(lset-adjoin/eq (cons (car elts) list) (cdr elts)))))
(define (lset-adjoin/eqv list elts)
(if (null? elts)
list
(if (memv (car elts) list)
(lset-adjoin/eqv list (cdr elts))
(lset-adjoin/eqv (cons (car elts) list) (cdr elts)))))
(define (lset-union = . lists)
(if (null? lists)
lists
(let rec ((head (car lists))
(rest (cdr lists)))
(if (null? rest)
head
(let ((next (car rest)))
(if (eq? head next)
(rec head (cdr rest))
(rec (apply lset-adjoin = head next) (cdr rest))))))))
(define (lset-intersection = . lists)
(if (null? lists)
lists
(cond ((eq? = eq?)
(lset-intersection/eq (car lists) (cdr lists)))
((eq? = eqv?)
(lset-intersection/eqv (car lists) (cdr lists)))
(else
(let rec ((head (car lists))
(rest (cdr lists)))
(if (null? rest)
head
(let ((next (car rest)))
(if (eq? head next)
(rec head (cdr rest))
(rec (filter (lambda (x) (member x next =)) head)
(cdr rest))))))))))
(define (lset-intersection/eq head rest)
(if (null? rest)
head
(let ((next (car rest)))
(if (eq? head next)
(lset-intersection/eq head (cdr rest))
(lset-intersection/eq (filter (lambda (x) (memq x next)) head) (cdr rest))))))
(define (lset-intersection/eqv head rest)
(if (null? rest)
head
(let ((next (car rest)))
(if (eq? head next)
(lset-intersection/eqv head (cdr rest))
(lset-intersection/eqv (filter (lambda (x) (memv x next)) head) (cdr rest))))))
(define (lset-difference = list . lists)
(let rec ((head list)
(rest lists))
(if (null? rest)
head
(let ((next (car rest)))
(if (eq? head next)
'()
(rec (remove (lambda (x) (member x next =)) head) (cdr rest)))))))
(define (lset-xor = . lists)
(if (null? lists)
lists
(let rec ((head (car lists))
(rest (cdr lists)))
(if (null? rest)
head
(let ((next (car rest)))
(if (eq? head next)
'()
(rec (append (remove (lambda (x) (member x next =)) head)
(remove (lambda (x) (member x head =)) next))
(cdr rest))))))))
(define (lset-diff+intersection = list . lists)
(values (apply lset-difference = list lists)
(lset-intersection = list (apply lset-union lists))))
)
)
| false |
e0bca5e3adadf58acce16c820cf91dd286f7c0e5 | 5355071004ad420028a218457c14cb8f7aa52fe4 | /3.3/e-3.15.scm | dfcc7e44bfbfa1de14f5bad8fcabbf8461bff9df | [] | no_license | ivanjovanovic/sicp | edc8f114f9269a13298a76a544219d0188e3ad43 | 2694f5666c6a47300dadece631a9a21e6bc57496 | refs/heads/master | 2022-02-13T22:38:38.595205 | 2022-02-11T22:11:18 | 2022-02-11T22:11:18 | 2,471,121 | 376 | 90 | null | 2022-02-11T22:11:19 | 2011-09-27T22:11:25 | Scheme | UTF-8 | Scheme | false | false | 653 | scm | e-3.15.scm | ; Exercise 3.15. Draw box-and-pointer diagrams to explain the effect of
; set-to-wow! on the structures z1 and z2 above.
; ------------------------------------------------------------
; I will not draw them here, but I did them on paper. Could have scanned
; them if my handwriting is not destroyed by typing :)
; In case of z1, both car and cdr point to the same x and therefor
; when rendering output of z2 we wil see
; ((wow b) wow b)
;
; In case of z2 both car and cdr values point to the same symbo, but as
; soon as we change one, they will just point to the different symbols,
; but car and cdr pointers will still point ot different objects.
| false |
3d33450db2a17a8a3bd89ff8014250565e64b3ee | b43e36967e36167adcb4cc94f2f8adfb7281dbf1 | /sicp/ch3/exercises/3.59.scm | 09d109515c8a1397c8b1b790389cbfabfb2da94b | [] | no_license | ktosiu/snippets | 79c58416117fa646ae06a8fd590193c9dd89f414 | 08e0655361695ed90e1b901d75f184c52bb72f35 | refs/heads/master | 2021-01-17T08:13:34.067768 | 2016-01-29T15:42:14 | 2016-01-29T15:42:14 | 53,054,819 | 1 | 0 | null | 2016-03-03T14:06:53 | 2016-03-03T14:06:53 | null | UTF-8 | Scheme | false | false | 435 | scm | 3.59.scm | (define (integrate-series s)
(define (iter s n)
(cons-stream
(/ (stream-car s) n)
(iter (stream-cdr s)
(+ n 1))))
(iter s 1))
(define exp-series
(cons-stream 1 (integrate-series exp-series)))
(define sine-series
(cons-stream 0 (integrate-series cosine-series)))
(define cosine-series
(cons-stream 1
(scale-stream
(integrate-series sine-series)
-1)))
| false |
c94ad78e8fe40d154d50b4e1d4930c89dc8bb089 | a23f41d6de12a268b129a6b5c2e932325fe674f6 | /src/swish/json.ss | 65bd84613ed56cb5923609bfa16d070ae4b88e9f | [
"MIT",
"LicenseRef-scancode-public-domain"
] | permissive | becls/swish | 89ee48b783b6b67b7077e09a78b3005fb44a8c54 | 3165b6a40c33774b263941314a7975b08dddf0e2 | refs/heads/dev | 2022-11-05T01:55:29.530457 | 2022-10-14T20:49:18 | 2022-10-14T20:55:37 | 113,237,913 | 134 | 27 | MIT | 2022-10-17T13:04:13 | 2017-12-05T22:04:27 | Scheme | UTF-8 | Scheme | false | false | 19,924 | ss | json.ss | ;;; Copyright 2018 Beckman Coulter, Inc.
;;;
;;; Permission is hereby granted, free of charge, to any person
;;; obtaining a copy of this software and associated documentation
;;; files (the "Software"), to deal in the Software without
;;; restriction, including without limitation the rights to use, copy,
;;; modify, merge, publish, distribute, sublicense, and/or sell copies
;;; of the Software, and to permit persons to whom the Software is
;;; furnished to do so, subject to the following conditions:
;;;
;;; The above copyright notice and this permission notice shall be
;;; included in all copies or substantial portions of the Software.
;;;
;;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
;;; EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
;;; MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
;;; NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
;;; HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
;;; WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
;;; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
;;; DEALINGS IN THE SOFTWARE.
#!chezscheme
(library (swish json)
(export
json:bytevector->object
json:cells
json:delete!
json:extend-object
json:make-object
json:object->bytevector
json:object->string
json:object?
json:read
json:ref
json:set!
json:size
json:string->object
json:update!
json:write
json:write-object
json:write-structural-char
)
(import
(chezscheme)
(swish erlang)
(swish io)
)
(define-syntax extend-object-internal
(syntax-rules ()
[(_ x $ht (key val) ...)
(let ([ht $ht])
(hashtable-set! ht (parse-key key x) val)
...
ht)]))
(define-syntax (parse-key x)
(syntax-case x (unquote)
[(_ id form) (identifier? #'id) #'(quote id)]
[(_ (unquote e) form) #'e]
[(_ key form) (syntax-error #'form (format "invalid key ~s in" (datum key)))]))
(define-syntax (json:extend-object x)
(syntax-case x ()
[(_ $ht (key val) ...)
#`(extend-object-internal #,x $ht (key val) ...)]))
(define-syntax (json:make-object x)
(syntax-case x ()
[(_ (key val) ...)
#`(extend-object-internal #,x (make-hashtable symbol-hash json:key=?)
(key val) ...)]))
(define (json:key=? x y) (eq? x y))
(define (json:object? x)
(and (hashtable? x)
(eq? (#3%hashtable-equivalence-function x) json:key=?)))
(define (json:cells x)
(unless (json:object? x) (bad-arg 'json:cells x))
(#3%hashtable-cells x))
(define (walk-path who obj full-path extend? default found)
(unless (json:object? obj) (bad-arg who obj))
(when (null? full-path) (bad-arg who full-path))
(if (symbol? full-path)
(found obj full-path default)
(let lp ([obj obj] [path full-path])
(match path
[(,key)
(guard (symbol? key))
(found obj key default)]
[(,key1 . ,more)
(guard (symbol? key1))
(let ([hit (#3%symbol-hashtable-ref obj key1 #f)])
(cond
[(json:object? hit) (lp hit more)]
[extend?
(let ([new (json:make-object)])
(#3%symbol-hashtable-set! obj key1 new)
(lp new more))]
[else default]))]
[,_ (bad-arg who full-path)]))))
(define (json:ref obj path default)
(walk-path 'json:ref obj path #f default
(lambda (obj sym default)
(#3%symbol-hashtable-ref obj sym default))))
(define (json:set! obj path value)
(walk-path 'json:set! obj path #t value
(lambda (obj key value)
(#3%symbol-hashtable-set! obj key value))))
(define (json:update! obj path f default)
(unless (procedure? f) (bad-arg 'json:update! f))
(walk-path 'json:update! obj path #t default
(lambda (obj key default)
(#3%symbol-hashtable-update! obj key f default))))
(define (json:delete! obj path)
(walk-path 'json:delete! obj path #f (void)
(lambda (obj key default)
(#3%symbol-hashtable-delete! obj key))))
(define (json:size obj)
(unless (json:object? obj) (bad-arg 'json:size obj))
(#3%hashtable-size obj))
(define (unexpected-input c ip)
(if (eof-object? c)
(throw 'unexpected-eof)
(throw `#(unexpected-input ,c
,(and (port-has-port-position? ip)
(- (port-position ip) 1))))))
(define (next-char ip)
(let ([x (read-char ip)])
(if (eof-object? x)
(throw 'unexpected-eof)
x)))
(define (ws? x)
(memv x '(#\x20 #\x09 #\x0A #\x0D)))
(define (next-non-ws ip)
(let ([c (next-char ip)])
(if (ws? c)
(next-non-ws ip)
c)))
(define (seek-non-ws ip)
(let ([c (read-char ip)])
(cond
[(eof-object? c) c]
[(ws? c) (seek-non-ws ip)]
[else c])))
(define (read-string ip op)
(let ([c (next-char ip)])
(case c
[(#\") (get-output-string op)]
[(#\\)
(let ([c (next-char ip)])
(case c
[(#\" #\\ #\/) (write-char c op)]
[(#\b) (write-char #\x08 op)]
[(#\f) (write-char #\x0C op)]
[(#\n) (write-char #\x0A op)]
[(#\r) (write-char #\x0D op)]
[(#\t) (write-char #\x09 op)]
[(#\u)
(let ([x (read-4hexdig ip)])
(cond
[(<= #xD800 x #xDBFF) ;; high surrogate
(expect-char #\\ ip)
(expect-char #\u ip)
(let ([y (read-4hexdig ip)])
(unless (<= #xDC00 y #xDFFF)
(throw 'invalid-surrogate-pair))
(write-char
(integer->char
(+ (ash (bitwise-and x #x3FF) 10)
(bitwise-and y #x3FF)
#x10000))
op))]
[(<= #xDC00 x #xDFFF) (throw 'invalid-surrogate-pair)]
[else (write-char (integer->char x) op)]))]
[else (unexpected-input c ip)]))
(read-string ip op)]
[else (write-char c op) (read-string ip op)])))
(define (read-4hexdig ip)
(let* ([x (hex-digit ip)]
[x (+ (ash x 4) (hex-digit ip))]
[x (+ (ash x 4) (hex-digit ip))]
[x (+ (ash x 4) (hex-digit ip))])
x))
(define (expect-char expected ip)
(let ([c (next-char ip)])
(unless (char=? c expected)
(unexpected-input c ip))))
(define-syntax make-write-string
(syntax-rules ()
[(_ s op)
(lambda (s op)
(write-char #\" op)
(do ([i 0 (+ i 1)] [n (string-length s)]) [(= i n)]
(let ([c (string-ref s i)])
(cond
[(memv c '(#\" #\\)) (write-char #\\ op) (write-char c op)]
[(char<=? c #\x1F) (fprintf op "\\u~4,'0x" (char->integer c))]
[else (write-char c op)])))
(write-char #\" op))]))
(define write-string (make-write-string s op))
(define (hex-digit ip)
(let ([c (next-char ip)])
(cond
[(char<=? #\0 c #\9) (digit-value c)]
[(char<=? #\A c #\F) (- (char->integer c) (- (char->integer #\A) 10))]
[(char<=? #\a c #\f) (- (char->integer c) (- (char->integer #\a) 10))]
[else (unexpected-input c ip)])))
(define (digit-value c) (- (char->integer c) (char->integer #\0)))
(define (read-unsigned ip)
(let-values ([(mantissa n c) (read-digits ip 0 0)])
(cond
[(eqv? n 0) (unexpected-input c ip)]
[(eqv? c #\.)
(let-values ([(mantissa m c) (read-digits ip mantissa 0)])
(cond
[(eqv? m 0) (unexpected-input c ip)]
[(memv c '(#\e #\E)) (read-exp ip mantissa m)]
[else
(unless (eof-object? c)
(unread-char c ip))
(scale mantissa (- m))]))]
[(memv c '(#\e #\E)) (read-exp ip mantissa 0)]
[else
(unless (eof-object? c)
(unread-char c ip))
mantissa])))
(define (read-digits ip mantissa n)
(let ([c (read-char ip)])
(cond
[(eof-object? c) (values mantissa n c)]
[(char<=? #\0 c #\9)
(read-digits ip (+ (* mantissa 10) (digit-value c)) (+ n 1))]
[else
(values mantissa n c)])))
(define (read-exp ip mantissa m)
(let ([c (next-char ip)])
(case c
[(#\+) (scale mantissa (- (read-int ip) m))]
[(#\-) (scale mantissa (- (- (read-int ip)) m))]
[else (unread-char c ip) (scale mantissa (- (read-int ip) m))])))
(define (read-int ip)
(let-values ([(int n c) (read-digits ip 0 0)])
(cond
[(eqv? n 0) (unexpected-input c ip)]
[else
(unless (eof-object? c)
(unread-char c ip))
int])))
(define (scale mantissa exponent)
(if (>= exponent 0)
(inexact (* mantissa (expt 10 exponent)))
(inexact (/ mantissa (expt 10 (- exponent))))))
(define (string->key s)
(let ([len (string-length s)])
(or (and (fx>= len 6)
(char=? (string-ref s 0) #\#)
(char=? (string-ref s 1) #\{)
(char=? (string-ref s (fx- len 1)) #\})
(guard (c [else #f])
(read (open-input-string s))))
(string->symbol s))))
(define json:read
(case-lambda
[(ip) (json:read ip no-custom-inflate)]
[(ip custom-inflate)
(define buffer (open-output-string))
(define (rd ip)
(let ([c (next-non-ws ip)])
(cond
[(eqv? c #\t)
(expect-char #\r ip)
(expect-char #\u ip)
(expect-char #\e ip)
#t]
[(eqv? c #\f)
(expect-char #\a ip)
(expect-char #\l ip)
(expect-char #\s ip)
(expect-char #\e ip)
#f]
[(eqv? c #\n)
(expect-char #\u ip)
(expect-char #\l ip)
(expect-char #\l ip)
#\nul]
[(eqv? c #\") (read-string ip buffer)]
[(eqv? c #\[)
(let lp ([acc '()])
(let ([c (next-non-ws ip)])
(cond
[(and (eqv? c #\]) (null? acc)) '()]
[else
(unread-char c ip)
(let* ([acc (cons (rd ip) acc)]
[c (next-non-ws ip)])
(case c
[(#\,) (lp acc)]
[(#\]) (reverse acc)]
[else (unexpected-input c ip)]))])))]
[(eqv? c #\{)
(custom-inflate
(let lp ([obj (json:make-object)])
(let ([c (next-non-ws ip)])
(cond
[(eqv? c #\")
(let* ([key (string->key (read-string ip buffer))]
[c (next-non-ws ip)])
(unless (eqv? c #\:)
(unexpected-input c ip))
(#3%symbol-hashtable-set! obj key (rd ip)))
(let ([c (next-non-ws ip)])
(case c
[(#\,) (lp obj)]
[(#\}) obj]
[else (unexpected-input c ip)]))]
[(and (eqv? c #\}) (eqv? (#3%hashtable-size obj) 0)) obj]
[else (unexpected-input c ip)]))))]
[(eqv? c #\-) (- (read-unsigned ip))]
[else (unread-char c ip) (read-unsigned ip)])))
(let ([x (seek-non-ws ip)])
(cond
[(eof-object? x) x]
[else
(unread-char x ip)
(rd ip)]))]))
(define (newline-and-indent indent op)
(newline op)
(do ([i 0 (+ i 1)]) ((= i indent))
(write-char #\space op)))
(define (json:write-structural-char x indent op)
(if (not indent)
(begin
(write-char x op)
#f)
(match x
[#\[
(let ([indent (+ indent 2)])
(write-char #\[ op)
(newline-and-indent indent op)
indent)]
[#\]
(let ([indent (- indent 2)])
(newline-and-indent indent op)
(write-char #\] op)
indent)]
[#\{
(let ([indent (+ indent 2)])
(write-char #\{ op)
(newline-and-indent indent op)
indent)]
[#\}
(let ([indent (- indent 2)])
(newline-and-indent indent op)
(write-char #\} op)
indent)]
[#\:
(write-char #\: op)
(write-char #\space op)
indent]
[#\,
(write-char #\, op)
(newline-and-indent indent op)
indent])))
(define-syntax json-key->sort-key
(syntax-rules ()
[(_ expr)
(let ([x expr])
(if (gensym? x)
(gensym->unique-string x)
(symbol->string x)))]))
(define-syntax json-key->string
(syntax-rules ()
[(_ expr)
(let ([x expr])
(if (gensym? x)
(parameterize ([print-gensym #t]) (format "~s" x))
(symbol->string x)))]))
(define json:write
(case-lambda
[(op x) (json:write op x #f)]
[(op x indent) (json:write op x indent no-custom-write)]
[(op x indent custom-write)
(define (wr op x indent)
(cond
[(eq? x #t) (display-string "true" op)]
[(eq? x #f) (display-string "false" op)]
[(eqv? x #\nul) (display-string "null" op)]
[(string? x) (write-string x op)]
[(or (fixnum? x) (bignum? x) (and (flonum? x) (finite? x)))
(display-string (number->string x) op)]
[(custom-write op x indent wr)]
[(null? x) (display-string "[]" op)]
[(pair? x)
(let ([indent (json:write-structural-char #\[ indent op)])
(wr op (car x) indent)
(for-each
(lambda (x)
(json:write-structural-char #\, indent op)
(wr op x indent))
(cdr x))
(json:write-structural-char #\] indent op))]
[(json:object? x)
(if (zero? (#3%hashtable-size x))
(display-string "{}" op)
(let ([indent (json:write-structural-char #\{ indent op)])
(let ([v (#3%hashtable-cells x)])
(vector-sort!
(lambda (x y)
(string<? (json-key->sort-key (car x)) (json-key->sort-key (car y))))
v)
(do ([i 0 (fx+ i 1)]) ((fx= i (vector-length v)))
(when (fx> i 0)
(json:write-structural-char #\, indent op))
(let ([p (vector-ref v i)])
(write-string (json-key->string (car p)) op)
(json:write-structural-char #\: indent op)
(wr op (cdr p) indent))))
(json:write-structural-char #\} indent op)))]
[else (throw `#(invalid-datum ,x))]))
(when (and indent (or (not (fixnum? indent)) (negative? indent)))
(bad-arg 'json:write indent))
(wr op x indent)
(when (eqv? indent 0)
(newline op))]))
(define json:object->string
(case-lambda
[(x) (json:object->string x #f)]
[(x indent) (json:object->string x indent no-custom-write)]
[(x indent custom-write)
(let-values ([(op get) (open-string-output-port)])
(json:write op x indent custom-write)
(get))]))
(define json:string->object
(case-lambda
[(x) (json:string->object x no-custom-inflate)]
[(x custom-inflate)
(->object (open-string-input-port x) custom-inflate)]))
(define json:object->bytevector
(case-lambda
[(x) (json:object->bytevector x #f)]
[(x indent) (json:object->bytevector x indent no-custom-write)]
[(x indent custom-write)
(call-with-bytevector-output-port
(lambda (op) (json:write op x indent custom-write))
(make-utf8-transcoder))]))
(define json:bytevector->object
(case-lambda
[(x) (json:bytevector->object x no-custom-inflate)]
[(x custom-inflate)
(->object (open-bytevector-input-port x (make-utf8-transcoder))
custom-inflate)]))
(define (->object ip custom-inflate)
(let ([obj (json:read ip custom-inflate)])
;; Make sure there's nothing but whitespace left.
(let ([x (seek-non-ws ip)])
(if (eof-object? x)
obj
(unexpected-input x ip)))))
(define (no-custom-inflate x) x)
(define (no-custom-write op x indent wr) #f)
(define (write-key indent pre key whole op)
;; pre is a token
;; key is a pre-rendered string
;; whole is a pre-rendered string with prefix and trailer included.
(cond
[indent
(let ([indent (json:write-structural-char pre indent op)])
(display key op)
(json:write-structural-char #\: indent op))]
[else
(display whole op)
#f]))
(define-syntax json-write-kv
(let ()
(define write-string (make-write-string s op))
(define (get-preamble prefix k)
(let-values ([(op get) (open-string-output-port)])
(write-char prefix op)
(write-string (json-key->string k) op)
(write-char #\: op)
(get)))
(define (get-key k)
(let-values ([(op get) (open-string-output-port)])
(write-string (json-key->string k) op)
(get)))
(lambda (x)
(syntax-case x ()
[(_ op indent wr prefix k v #f)
(with-syntax ([whole (get-preamble (datum prefix) (datum k))]
[key (get-key (datum k))])
#'(let ([indent (write-key indent prefix key whole op)])
(wr op v indent)
indent))]
[(_ op indent wr prefix k v-expr cw-expr)
(with-syntax ([whole (get-preamble (datum prefix) (datum k))]
[key (get-key (datum k))])
#'(let* ([custom-writer cw-expr] [v v-expr]
[indent (write-key indent prefix key whole op)])
(if custom-writer
(custom-writer op v indent wr)
(wr op v indent))
indent))]))))
(define-syntax (json:write-object x)
(define (sort-key x)
(syntax-case x ()
[(key . rest) (json-key->sort-key (datum key))]))
(define (valid? keys)
(let ([novel (make-hashtable symbol-hash eq?)])
(define (ok? key)
(and (symbol? key)
(symbol-hashtable-ref novel key #t)
(begin (symbol-hashtable-set! novel key #f) #t)))
(andmap ok? keys)))
(define (parse-clause c)
(syntax-case c ()
[(key field) #'(key field #f)]
[(key field custom-write) c]
[_ (syntax-error c)]))
(syntax-case x ()
[(_ op-expr indent-expr wr-expr)
#'(let ([indent indent-expr] [op op-expr])
wr-expr
(display-string "{}" op)
(when (eqv? indent 0)
(newline op))
#t)]
[(_ op-expr indent-expr wr-expr [key . spec] ...)
(valid? (datum (key ...)))
(with-syntax ([([k0 f0 cw0] [k1 f1 cw1] ...)
(sort
(lambda (x y)
(string<? (sort-key x) (sort-key y)))
(map parse-clause #'([key . spec] ...)))])
#'(let ([op op-expr] [indent indent-expr] [wr wr-expr])
(let ([indent (json-write-kv op indent wr #\{ k0 f0 cw0)])
(json-write-kv op indent wr #\, k1 f1 cw1)
...
(json:write-structural-char #\} indent op))
(when (eqv? indent 0)
(newline op))
#t))]))
)
| true |
37b8ad84fed54f75c09bd24a2dbbb148dcb4989b | f4cf5bf3fb3c06b127dda5b5d479c74cecec9ce9 | /Sources/LispKit/Resources/Tests/SRFI-217.scm | 0641c94de1f201626460e4772ff4a9427cb6a174 | [
"Apache-2.0"
] | permissive | objecthub/swift-lispkit | 62b907d35fe4f20ecbe022da70075b70a1d86881 | 90d78a4de3a20447db7fc33bdbeb544efea05dda | refs/heads/master | 2023-08-16T21:09:24.735239 | 2023-08-12T21:37:39 | 2023-08-12T21:37:39 | 57,930,217 | 356 | 17 | Apache-2.0 | 2023-06-04T12:11:51 | 2016-05-03T00:37:22 | Scheme | UTF-8 | Scheme | false | false | 16,758 | scm | SRFI-217.scm | ;;; SRFI 217 REGRESSION TEST SUITE
;;;
;;; This is the test suite for SRFI 217.
;;;
;;; Copyright © 2020 Wolfgang Corcoran-Mathe. All rights reserved.
;;;
;;; Permission is hereby granted, free of charge, to any person
;;; obtaining a copy of this software and associated documentation
;;; files (the "Software"), to deal in the Software without restriction,
;;; including without limitation the rights to use, copy, modify, merge,
;;; publish, distribute, sublicense, and/or sell copies of the Software,
;;; and to permit persons to whom the Software is furnished to do so,
;;; subject to the following conditions:
;;;
;;; The above copyright notice and this permission notice shall be
;;; included in all copies or substantial portions of the Software.
;;;
;;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
;;; EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
;;; MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
;;; IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
;;; CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
;;; TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
;;; SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
;;;
;;; LispKit Port:
;;; Copyright © 2021 Matthias Zenger. All rights reserved.
(import (lispkit base)
(lispkit test)
(srfi 217)
(only (srfi 1) iota any every last take-while drop-while count
fold filter remove last partition))
;;; Utility
(define-syntax test-iset=?
(syntax-rules ()
((test-eqv ex tst)
(test-equal (write-to-string 'tst) ex tst iset=?))))
(define (init xs)
(if (null? (cdr xs))
'()
(cons (car xs) (init (cdr xs)))))
(define (constantly x)
(lambda (_) x))
(define pos-seq (iota 20 100 3))
(define neg-seq (iota 20 -100 3))
(define mixed-seq (iota 20 -10 3))
(define sparse-seq (iota 20 -10000 1003))
(define pos-set (list->iset pos-seq))
(define pos-set+ (iset-adjoin pos-set 9))
(define neg-set (list->iset neg-seq))
(define mixed-set (list->iset mixed-seq))
(define dense-set (make-range-iset 0 49))
(define sparse-set (list->iset sparse-seq))
(define all-test-sets
(list pos-set neg-set mixed-set dense-set sparse-set))
(test-begin "SRFI 217: Integer Sets")
;; Most other test groups use iset=?, so test this first.
(test-group "iset=?"
(test #t (iset=? (iset) (iset)))
(test #f (iset=? (iset 1) (iset)))
(test #f (iset=? (iset) (iset 1)))
(test #t (iset=? (iset 1 2 3 4) (iset 1 2 3 4)))
(test #t (iset=? (iset 1 2 3 4) (iset 2 1 4 3) (iset 3 2 1 4)))
(test #f (iset=? (iset 1 2 3 4) (iset 2 3 4)))
(test #f (iset=? pos-set neg-set)))
(test-group "Copying and conversion"
;;; iset-copy
(test-assert (not (eqv? (iset-copy pos-set) pos-set)))
(test-assert (every (lambda (set)
(iset-every? (lambda (n) (iset-contains? set n))
(iset-copy set)))
all-test-sets))
;;; iset->list
(test '() (iset->list (iset)))
(test pos-seq (iset->list pos-set))
(test neg-seq (iset->list neg-set))
(test mixed-seq (iset->list mixed-set))
(test sparse-seq (iset->list sparse-set))
(test-iset=? (iset 1) (list->iset! (iset) '(1)))
(test-iset=? (iset-adjoin pos-set 2 4 6)
(list->iset! (iset-copy pos-set) '(2 4 6))))
(test-group "Constructors"
(test-iset=? (list->iset (iota 10 0 4))
(iset-unfold (lambda (i) (> i 36))
values
(lambda (i) (+ i 4))
0))
(test-iset=? (list->iset (iota 20 -10))
(make-range-iset -10 10))
(test-iset=? (list->iset (iota 10 -10 2))
(make-range-iset -10 10 2)))
(test-group "Predicates"
(test-not (iset-contains? (iset) 1))
(test-assert (every (lambda (n) (iset-contains? pos-set n))
(iota 20 100 3)))
(test-assert (not (any (lambda (n) (iset-contains? pos-set n))
(iota 20 -100 3))))
(test-assert (iset-empty? (iset)))
(test-not (iset-empty? pos-set))
(test-assert (iset-disjoint? (iset) (iset)))
(test-assert (iset-disjoint? pos-set neg-set))
(test-assert (iset-disjoint? (iset) pos-set))
(test-not (iset-disjoint? dense-set sparse-set))
(test-not (iset-disjoint? (make-range-iset 20 30) (make-range-iset 29 39)))
)
(test-group "Accessors"
(test 103 (iset-member pos-set 103 #f))
(test 'z (iset-member pos-set 104 'z))
(test-not (iset-min (iset)))
(test 1 (iset-min (iset 1 2 3)))
(test (car pos-seq) (iset-min pos-set))
(test (car neg-seq) (iset-min neg-set))
(test (car mixed-seq) (iset-min mixed-set))
(test-not (iset-max (iset)))
(test 3 (iset-max (iset 1 2 3)))
(test (last pos-seq) (iset-max pos-set))
(test (last neg-seq) (iset-max neg-set))
(test (last mixed-seq) (iset-max mixed-set))
)
(test-group "Updaters"
(test '(1) (iset->list (iset-adjoin (iset) 1)))
(test-assert (iset-contains? (iset-adjoin neg-set 10) 10))
(test-assert (iset-contains? (iset-adjoin dense-set 100) 100))
(test-assert (iset-contains? (iset-adjoin sparse-set 100) 100))
(test-iset=? (list->iset (cons -3 (iota 20 100 3)))
(iset-adjoin pos-set -3))
(test '() (iset->list (iset-delete (iset 1) 1)))
(test-not (iset-contains? (iset-delete neg-set 10) 10))
(test-not (iset-contains? (iset-delete dense-set 1033) 1033))
(test-not (iset-contains? (iset-delete sparse-set 30) 30))
(test-iset=? (list->iset (cdr (iota 20 100 3)))
(iset-delete pos-set 100))
(test-assert (iset-empty? (iset-delete-all (iset) '())))
(test-iset=? pos-set (iset-delete-all pos-set '()))
(test-equal iset=?
(iset 100 103 106)
(iset-delete-all pos-set (iota 17 109 3)))
;; iset-search insertion
(test-assert
(call-with-values
(lambda ()
(iset-search mixed-set
1
(lambda (insert _) (insert #t))
(lambda (x update _) (update 1 #t))))
(lambda (set _) (iset=? (iset-adjoin mixed-set 1) set))))
;; iset-search ignore
(test-assert
(call-with-values
(lambda ()
(iset-search mixed-set
1
(lambda (_ ignore) (ignore #t))
(lambda (x _ remove) (remove #t))))
(lambda (set _) (iset=? mixed-set set))))
;; iset-search update with same element.
(test-assert
(call-with-values
(lambda ()
(iset-search mixed-set
2
(lambda (insert _) (insert #t))
(lambda (x update _) (update 2 #t))))
(lambda (set _) (iset=? mixed-set set))))
;; iset-search update with different element.
(test-assert
(call-with-values
(lambda ()
(iset-search mixed-set
2
(lambda (insert _) (insert #t))
(lambda (x update _) (update 3 #t))))
(lambda (set _)
(iset=? (iset-adjoin (iset-delete mixed-set 2) 3) set))))
;; iset-search remove
(test-assert
(call-with-values
(lambda ()
(iset-search mixed-set
2
(lambda (_ ignore) (ignore #t))
(lambda (x _ remove) (remove #t))))
(lambda (set _) (iset=? (iset-delete mixed-set 2) set))))
;;; iset-delete-min / -max
(test-values (values #t #t)
(let-values (((n mixed-set*) (iset-delete-min mixed-set)))
(values (= n (car mixed-seq))
(iset=? mixed-set* (list->iset (cdr mixed-seq))))))
(test-values (values #t #t)
(let-values (((n sparse-set*) (iset-delete-min sparse-set)))
(values (= n (car sparse-seq))
(iset=? sparse-set* (list->iset (cdr sparse-seq))))))
(test-values (values #t #t)
(let-values (((n mixed-set*) (iset-delete-max mixed-set)))
(values (= n (last mixed-seq))
(iset=? mixed-set* (list->iset (init mixed-seq))))))
(test-values (values #t #t)
(let-values (((n sparse-set*) (iset-delete-max sparse-set)))
(values (= n (last sparse-seq))
(iset=? sparse-set* (list->iset (init sparse-seq)))))))
(test-group "Whole set operations"
(test 0 (iset-size (iset)))
(test (length pos-seq) (iset-size pos-set))
(test (length mixed-seq) (iset-size mixed-set))
(test (length sparse-seq) (iset-size sparse-set))
(test 8 (iset-find even? (iset 1 3 5 7 8 9 10) (lambda () #f)))
(test 'z (iset-find negative? pos-set (lambda () 'z)))
(test #f (iset-any? even? (iset)))
(test-assert (iset-any? even? pos-set))
(test-not (iset-any? negative? pos-set))
(test-assert (iset-any? (lambda (n) (> n 100)) sparse-set))
(test-not (iset-any? (lambda (n) (> n 100)) dense-set))
(test #t (iset-every? even? (iset)))
(test-not (iset-every? even? pos-set))
(test-assert (iset-every? negative? neg-set))
(test-not (iset-every? (lambda (n) (> n 100)) sparse-set))
(test-assert (iset-every? (lambda (n) (< n 100)) dense-set))
(test 0 (iset-count even? (iset)))
(test (count even? pos-seq) (iset-count even? pos-set))
(test (count even? neg-seq) (iset-count even? neg-set))
(test (count even? sparse-seq) (iset-count even? sparse-set)))
(test-group "Iterators"
;;; folds
(test (fold + 0 pos-seq) (iset-fold + 0 pos-set))
(test (fold + 0 sparse-seq) (iset-fold + 0 sparse-set))
(test (iset-size neg-set) (iset-fold (lambda (_ c) (+ c 1)) 0 neg-set))
(test (reverse pos-seq) (iset-fold cons '() pos-set))
(test (reverse mixed-seq) (iset-fold cons '() mixed-set))
(test (fold + 0 pos-seq) (iset-fold-right + 0 pos-set))
(test (fold + 0 sparse-seq) (iset-fold-right + 0 sparse-set))
(test (iset-size neg-set) (iset-fold-right (lambda (_ c) (+ c 1)) 0 neg-set))
(test pos-seq (iset-fold-right cons '() pos-set))
(test mixed-seq (iset-fold-right cons '() mixed-set))
;;; iset-map
(test-assert (iset-empty? (iset-map values (iset))))
(test-iset=? pos-set (iset-map values pos-set))
(test-iset=? (list->iset (map (lambda (n) (* n 2)) mixed-seq))
(iset-map (lambda (n) (* n 2)) mixed-set))
(test-iset=? (iset 1) (iset-map (constantly 1) pos-set))
;;; iset-for-each
(test (iset-size mixed-set)
(let ((n 0))
(iset-for-each (lambda (_) (set! n (+ n 1))) mixed-set)
n))
(test (fold + 0 sparse-seq)
(let ((sum 0))
(iset-for-each (lambda (n) (set! sum (+ sum n))) sparse-set)
sum))
(test (reverse mixed-seq)
(let ((xs '()))
(iset-for-each (lambda (n) (set! xs (cons n xs))) mixed-set)
xs))
;;; filter, remove, & partition
(test-assert (iset-empty? (iset-filter (constantly #f) pos-set)))
(test-iset=? pos-set
(iset-filter (constantly #t) pos-set))
(test-iset=? (list->iset (filter even? mixed-seq))
(iset-filter even? mixed-set))
(test-assert (iset-empty? (iset-remove (constantly #t) pos-set)))
(test-iset=? pos-set
(iset-remove (constantly #f) pos-set))
(test-iset=? (list->iset (remove even? mixed-seq))
(iset-remove even? mixed-set))
(test-assert
(let-values (((in out) (iset-partition (constantly #f) pos-set)))
(and (iset-empty? in) (iset=? pos-set out))))
(test-assert
(let-values (((in out) (iset-partition (constantly #t) pos-set)))
(and (iset=? pos-set in) (iset-empty? out))))
(test-assert
(let-values (((in out) (iset-partition even? mixed-set))
((lin lout) (partition even? mixed-seq)))
(and (iset=? in (list->iset lin))
(iset=? out (list->iset lout)))))
)
(test-group "Comparison"
(test-assert (iset<? (iset) pos-set))
(test-assert (iset<? pos-set pos-set+))
(test-not (iset<? pos-set pos-set))
(test-not (iset<? pos-set+ pos-set))
(test-assert (iset<? (iset) pos-set pos-set+))
(test-not (iset<? (iset) pos-set pos-set))
(test-assert (iset<=? (iset) pos-set))
(test-assert (iset<=? pos-set pos-set+))
(test-assert (iset<=? pos-set pos-set))
(test-not (iset<=? pos-set+ pos-set))
(test-assert (iset<=? (iset) pos-set pos-set+))
(test-assert (iset<=? (iset) pos-set pos-set))
(test-not (iset>? (iset) pos-set))
(test-not (iset>? pos-set pos-set+))
(test-not (iset>? pos-set pos-set))
(test-assert (iset>? pos-set+ pos-set))
(test-assert (iset>? pos-set+ pos-set (iset)))
(test-not (iset>? pos-set+ pos-set pos-set))
(test-not (iset>=? (iset) pos-set))
(test-not (iset>=? pos-set pos-set+))
(test-assert (iset>=? pos-set pos-set))
(test-assert (iset>=? pos-set+ pos-set))
(test-assert (iset>=? pos-set+ pos-set (iset)))
(test-assert (iset>=? pos-set+ pos-set pos-set))
)
(test-group "Set theory"
(test-iset=? mixed-set (iset-union! (iset) mixed-set))
(test-iset=? (list->iset (append (iota 20 100 3) (iota 20 -100 3)))
(iset-union pos-set neg-set))
(test-iset=? pos-set (iset-union pos-set pos-set))
(test-iset=? (list->iset (iota 30 100 3))
(iset-union pos-set (list->iset (iota 20 130 3))))
(test-iset=? (list->iset (iota 10))
(iset-union (iset 0 1 2) (iset 3 5 8) (iset 4 6 7 9)))
;; iset-intersection
(test-assert (iset-empty? (iset-intersection (iset) mixed-set)))
(test-iset=? neg-set (iset-intersection neg-set neg-set))
(test-iset=? (iset -97) (iset-intersection (iset -97) neg-set))
(test-iset=? (iset) (iset-intersection pos-set neg-set))
(test-iset=? (list->iset (drop-while negative? mixed-seq))
(iset-intersection mixed-set dense-set))
(test-iset=? (iset 0 1)
(iset-intersection (iset 0 1 2) (iset 0 1 3 4) (iset 10 7 0 1)))
;; iset-difference
(test-assert (iset-empty? (iset-difference neg-set neg-set)))
(test-iset=? pos-set (iset-difference pos-set neg-set))
(test-iset=? pos-set (iset-difference pos-set neg-set))
(test-iset=? (iset 100)
(iset-difference pos-set (list->iset (cdr pos-seq))))
(test-iset=? (list->iset (take-while negative? mixed-seq))
(iset-difference mixed-set dense-set))
(test-iset=? (iset 0 1)
(iset-intersection (iset 0 1 2 5) (iset 0 1 3 4) (iset 10 7 0 1)))
;; iset-xor
(test-iset=? mixed-set (iset-xor (iset) mixed-set))
(test-iset=? (list->iset (append (iota 20 100 3) (iota 20 -100 3)))
(iset-xor pos-set neg-set))
(test-iset=? (iset) (iset-xor pos-set pos-set))
(test-iset=? (list->iset '(100 103 106))
(iset-xor pos-set (list->iset (iota 17 109 3)))))
(test-group "Subsets"
(test-assert (iset-empty? (iset-open-interval (iset) 0 10)))
(test-iset=? (iset 103 106)
(iset-open-interval pos-set 100 109))
(test-assert (iset-empty? (iset-open-interval neg-set 0 50)))
(test-assert (iset-empty? (iset-closed-interval (iset) 0 10)))
(test-iset=? (iset 100 103 106 109)
(iset-closed-interval pos-set 100 109))
(test-assert (iset-empty? (iset-closed-interval neg-set 0 50)))
(test-assert (iset-empty? (iset-open-closed-interval (iset) 0 10)))
(test-iset=? (iset 103 106 109)
(iset-open-closed-interval pos-set 100 109))
(test-assert (iset-empty? (iset-open-closed-interval neg-set 0 50)))
(test-assert (iset-empty? (iset-closed-open-interval (iset) 0 10)))
(test-iset=? (iset 100 103 106)
(iset-closed-open-interval pos-set 100 109))
(test-assert (iset-empty? (iset-closed-open-interval neg-set 0 50)))
;;; isubset*
(test-assert (iset-empty? (isubset= pos-set 90)))
(test-iset=? (iset 100) (isubset= pos-set 100))
(test-assert (iset-empty? (isubset< (iset) 10)))
(test-iset=? (iset 100 103 106)
(isubset< pos-set 109))
(test-iset=? (iset -10 -7)
(isubset< mixed-set -4))
(test-assert (iset-empty? (isubset< mixed-set -15)))
(test-assert (iset-empty? (isubset<= (iset) 10)))
(test-iset=? (iset 100 103 106 109)
(isubset<= pos-set 109))
(test-iset=? (iset -10 -7 -4)
(isubset<= mixed-set -4))
(test-assert (iset-empty? (isubset<= mixed-set -15)))
(test-assert (iset-empty? (isubset> (iset) 10)))
(test-iset=? (iset 151 154 157)
(isubset> pos-set 148))
(test-iset=? (iset 41 44 47)
(isubset> mixed-set 38))
(test-assert (iset-empty? (isubset> mixed-set 50)))
(test-assert (iset-empty? (isubset>= (iset) 10)))
(test-iset=? (iset 148 151 154 157)
(isubset>= pos-set 148))
(test-iset=? (iset 38 41 44 47)
(isubset>= mixed-set 38))
(test-assert (iset-empty? (isubset>= mixed-set 50))))
(test-end)
| true |
0b26a78910544af71b42c6ea4b5cf826c95aa6a1 | 1f48fb14898799bf9ee1118bf691586b430c5e9e | /325.scm | c455cda6b1bd118214e4643a8ee11ffd2993f6fc | [] | no_license | green-93-nope/sicp | 0fa79dd59414808a9cdcbfa18bd3a1c7f0b8191c | 59241b6c42621c2ef967efebdd281b845f98e923 | refs/heads/master | 2021-01-10T10:51:22.328123 | 2017-05-21T08:33:25 | 2017-05-21T08:33:25 | 48,210,972 | 0 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 2,352 | scm | 325.scm | (define (assoc key records)
(cond ((null? records) #f)
((equal? key (caar records)) (car records))
(else
(assoc key (cdr records)))))
(define (make-table)
(let ((local-table (list '*table*)))
(define (lookup keys)
(define (look-up-iter keys current-table)
(if (null? keys)
#f
(let ((find-table (assoc (car keys) (cdr current-table))))
(display find-table)
(newline)
(cond
((and (exist-records find-table) (null? (cdr keys)))
(cdr find-table))
(else
(if find-table
(look-up-iter (cdr keys) find-table)
#f))))))
(look-up-iter keys local-table))
(define (insert! keys value)
(define (insert-iter! keys value current-table)
(if (null? keys)
(error "ERROR INSERT! no key in the keys list" keys)
(let ((find-table (assoc (car keys) (cdr current-table))))
(cond
((null? (cdr keys))
(if find-table
(set-cdr! find-table value)
(set-cdr! find-table (cons (cons (car keys) value)
(cdr find-table)))))
(else
(if find-table
(insert-iter! (cdr keys) value (cdr current-table))
(set-cdr! current-table
(cons (make-key-table keys value)
(cdr current-table)))))))))
(insert-iter! keys value local-table))
(define (make-key-table keys value)
(cond ((null? keys)
(error "ERROR MAKE-KEY-TABLE no key in the keys list" keys))
((null? (cdr keys))
(cons (car keys) value))
(else
(list (car keys) (make-key-table (cdr keys) value)))))
(define (exist-records find-table)
(not (eq? find-table #f)))
(define (dispatch m)
(cond ((eq? m 'lookup-proc) lookup)
((eq? m 'insert-proc) insert!)
(else
(error "Unknown operation -- TABLE" m))))
dispatch))
(define many-keys-table (make-table))
(define get-many-keys-table (many-keys-table 'lookup-proc))
(define put-many-keys-table (many-keys-table 'insert-proc))
| false |
8c5a8935a66b8aa794fdf9365a1f4a7898ee8e74 | 120324bbbf63c54de0b7f1ca48d5dcbbc5cfb193 | /packages/surfage/s99/records/inspection.sls | 88c9a20a0988e4704f7ee0a1c8f4fbcf1053f28e | [
"X11-distribute-modifications-variant",
"MIT"
] | permissive | evilbinary/scheme-lib | a6d42c7c4f37e684c123bff574816544132cb957 | 690352c118748413f9730838b001a03be9a6f18e | refs/heads/master | 2022-06-22T06:16:56.203827 | 2022-06-16T05:54:54 | 2022-06-16T05:54:54 | 76,329,726 | 609 | 71 | MIT | 2022-06-16T05:54:55 | 2016-12-13T06:27:36 | Scheme | UTF-8 | Scheme | false | false | 2,596 | sls | inspection.sls | ;; Copyright (C) William D Clinger 2008. All Rights Reserved.
;;
;; Permission is hereby granted, free of charge, to any person obtaining a copy
;; of this software and associated documentation files (the "Software"), to deal
;; in the Software without restriction, including without limitation the rights
;; to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
;; copies of the Software, and to permit persons to whom the Software is
;; furnished to do so, subject to the following conditions:
;;
;; The above copyright notice and this permission notice shall be included in
;; all copies or substantial portions of the Software.
;;
;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
;; IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
;; FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. REMEMBER, THERE IS NO
;; SCHEME UNDERGROUND. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
;; LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
;; CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
;; SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#!r6rs
(library (surfage s99 records inspection)
(export record? record-rtd
rtd-name rtd-parent
rtd-field-names rtd-all-field-names rtd-field-mutable?)
(import (rnrs base)
(rnrs lists)
(rnrs records inspection)
(surfage s99 records helper))
; The record? predicate is already defined by (rnrs records inspection).
; The record-rtd procedure is already defined by (rnrs records inspection).
(define rtd-name record-type-name)
(define rtd-parent record-type-parent)
(define rtd-field-names record-type-field-names)
(define (rtd-all-field-names rtd)
(define (loop rtd othernames)
(let ((parent (rtd-parent rtd))
(names (append (vector->list
(rtd-field-names rtd))
othernames)))
(if parent
(loop parent names)
(list->vector names))))
(loop rtd '()))
(define (rtd-field-mutable? rtd0 fieldname)
(define (loop rtd)
(if (rtd? rtd)
(let* ((names (vector->list (rtd-field-names rtd)))
(probe (memq fieldname names)))
(if probe
(record-field-mutable? rtd (- (length names) (length probe)))
(loop (rtd-parent rtd))))
(assertion-violation 'rtd-field-mutable?
"illegal argument" rtd0 fieldname)))
(loop rtd0))
)
| false |
085f0ac3e8b67d4b173ef3395e121465616837d2 | 27e8f9a818527bd169c03c60ec54eec822780d47 | /lib/pfds/private/vectors.sls | 98a0143a055a45831db26ff7890e2099ad3d66a7 | [
"BSD-3-Clause"
] | permissive | jhidding/pfds | db0e875bb293b21de3160dd1279cddbbb3a9e23f | 9755ffc2c59df2a303aa5f0885ecfefae2c67097 | refs/heads/master | 2021-01-12T14:45:31.068141 | 2017-12-28T19:02:15 | 2017-12-28T19:02:15 | 72,078,412 | 5 | 0 | null | 2016-10-27T06:35:23 | 2016-10-27T06:35:22 | null | UTF-8 | Scheme | false | false | 1,939 | sls | vectors.sls | #!r6rs
;;; vectors.sls --- Vector Utilities
;; Copyright (C) 2014 Ian Price <[email protected]>
;; Author: Ian Price <[email protected]>
;; This program is free software, you can redistribute it and/or
;; modify it under the terms of the new-style BSD license.
;; You should have received a copy of the BSD license along with this
;; program. If not, see <http://www.debian.org/misc/bsd.license>.
(library (pfds private vectors)
(export vector-set
vector-insert
vector-remove
vector-copy
vector-copy!
vector-fold
)
(import (rnrs base)
(rnrs control))
(define (vector-set h i x)
(let ((v* (vector-copy h)))
(vector-set! v* i x)
v*))
(define (vector-remove v i)
(define len (vector-length v))
(assert (and (<= 0 i) (< i len)))
(let ((newvec (make-vector (- len 1))))
(vector-copy! v 0 newvec 0 i)
(vector-copy! v (+ i 1) newvec i (- len i 1))
newvec))
(define (vector-insert v i x)
(define len (vector-length v))
(assert (<= 0 i len))
(let* ((newvec (make-vector (+ len 1))))
(vector-set! newvec i x)
(vector-copy! v 0 newvec 0 i)
(vector-copy! v i newvec (+ 1 i) (- len i))
newvec))
(define (vector-copy! source source-start target target-start k)
;; TODO: assertions
;; guile has vector-move functions, but rnrs does not :(
(do ((i 0 (+ 1 i)))
((>= i k))
(vector-set! target
(+ target-start i)
(vector-ref source (+ source-start i)))))
(define (vector-copy vector)
(define len (vector-length vector))
(define v* (make-vector len))
(vector-copy! vector 0 v* 0 len)
v*)
;; vector-fold is left to right
(define (vector-fold combine initial vector)
(define len (vector-length vector))
(let loop ((index 0) (accum initial))
(if (>= index len)
accum
(loop (+ index 1)
(combine (vector-ref vector index) accum)))))
)
| false |
9c352ce93c13d5ee2abb25edf88af1e647b9faab | 2767601ac7d7cf999dfb407a5255c5d777b7b6d6 | /sandbox/examples/beep-volume.ss | 20ed1fb5ed3db39fbbe7e85f60eae4ece99d03f9 | [] | no_license | manbaum/moby-scheme | 7fa8143f3749dc048762db549f1bcec76b4a8744 | 67fdf9299e9cf573834269fdcb3627d204e402ab | refs/heads/master | 2021-01-18T09:17:10.335355 | 2011-11-08T01:07:46 | 2011-11-08T01:07:46 | null | 0 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 1,099 | ss | beep-volume.ss | #lang s-exp "../moby-lang.ss"
;; Small program to test setting of ringer volume.
;; The world doesn't contain anything interesting.
(define initial-world #f)
(define user-interface
(list (js-p '(("id" "aPara")))
(list (js-button! (lambda (w) w)
(lambda (w) (make-effect:beep)))
(list (js-text "Beep")))
(list (js-button! (lambda (w) w)
(lambda (w) (make-effect:set-beep-volume 0)))
(list (js-text "Mute beep volume")))
(list (js-button! (lambda (w) w)
(lambda (w) (make-effect:set-beep-volume 75)))
(list (js-text "Set beep volume to 75%")))))
;; draw: world -> DOM-sexp
;; The interface includes a button for beeping, a button
;; for muting the ringer, and a button for setting the
;; ringer to 75%.
(define (draw w) user-interface)
;; draw-css: world -> CSS-sexp
;; Style the dom so that the font size is large.
(define (draw-css w)
'(("aPara" ("font-size" "30px"))))
;; Finally, begin a big-bang.
(js-big-bang initial-world
'()
(on-draw draw draw-css))
| false |
da6d7f517c8a350351bafc3c61abe12942a77df4 | 88c274acc25d882506d332ca392daf24053f2aa6 | /glfw/parse-api/main.scm | 9be4f97868f1b0180480eb561651e5af56fb1532 | [
"Apache-2.0"
] | permissive | shakdwipeea/chez-glfw | 476564d9b6c8b4b33b38a18c3579df11414624ba | 08f2f14360d42b62ad05cd20a3503b71a6771676 | refs/heads/master | 2020-07-03T15:17:54.954675 | 2019-08-12T14:38:03 | 2019-08-12T14:38:03 | 201,950,375 | 0 | 0 | null | 2019-08-12T14:48:27 | 2019-08-12T14:48:26 | null | UTF-8 | Scheme | false | false | 4,785 | scm | main.scm | (import (rnrs (6))
(lyonesse parsing xml)
(lyonesse functional)
(glfw parse-api types)
(glfw parse-api enums)
(glfw parse-api commands)
(glfw parse-api features)
(srfi :48)
(only (chezscheme) pretty-print pretty-line-length
pretty-one-line-limit
mkdir file-directory?
path-parent))
(define registry (xml:read (cadr (command-line))))
(define (ensure-directory-exists path)
(if (not (file-directory? path))
(begin
(ensure-directory-exists (path-parent path))
(mkdir path))))
#| Patch the type definitions.
| The XML specs contain this entry for GLhandleARB:
| #ifdef __APPLE__
| typedef void *GLhandleARB;
| #else
| typedef unsigned int GLhandleARB;
| #endif
| IMNSHO this is insane. I'm not going to parse C precompiler stuff,
| especially not for a single entry or shitty Apple.
|#
(define (patch-types types)
(cons '("GLhandleARB" . unsigned-int)
(remp (compose ($ equal? "GLhandleARB" <>) car) types)))
(define (write-lines port . lines)
(for-each (lambda (l)
(cond
[(string? l) (format port "~a~%" l)]
[(list? l) (apply write-lines port l)]))
lines))
(define (raw-type type)
(case (type-category type)
[(unit) (type-name type)]
[(pointer) (case (type-name type)
[(char integer-8 unsigned-8) 'string]
[else 'uptr])]
[(pointer-to-pointer array) 'uptr]))
(define (command-typedef command)
`(define-ftype
,(string->symbol (string-append (command-name command) "-ftype"))
(function ,(map (compose raw-type cdr)
(command-arguments command))
,(raw-type (command-return-type command)))))
(define (command-definition command)
(let ([name (command-name command)]
[arguments (command-arguments command)]
[return-type (command-return-type command)])
`(define ,(string->symbol name)
(foreign-procedure ,name
,(map (compose raw-type cdr) arguments)
,(raw-type return-type)))))
(define (feature-version f)
(let* ([n (feature-number f)]
[major (exact (floor n))]
[minor (exact (* 10 (- n major)))])
(list major minor)))
(define (write-gl-loaders enums commands features)
(let loop ([features features]
[command-lst* '()]
[enum-lst* '()])
(unless (null? features)
(let* ([f (car features)]
[name (feature-name f)]
[command-lst (extend-commands command-lst* f)]
[enum-lst (extend-enums enum-lst* f)]
[port (open-file-output-port (format "glfw/gl/~a.scm" name)
(file-options no-fail)
'line (native-transcoder))])
(write-lines port
(format "(library (glfw gl ~a)" name)
" (export"
(map ($ format " ~a" <>) command-lst)
(map ($ format " ~a" <>) enum-lst)
" )"
""
" (import (rnrs base(6))"
" (only (chezscheme) foreign-procedure"
" load-shared-object))"
""
" (define libGL (load-shared-object \"libGL.so.1\"))"
""
(map (lambda (c)
(let* ([command (hashtable-ref commands c #f)]
[definition (command-definition command)])
(format " ~s" definition)))
command-lst)
""
(map (lambda (e)
(let* ([enum (hashtable-ref enums e #f)]
[name e] ; (enum-name enum)]
[value (and (enum? enum) (enum-value enum))])
(if value
(format " (define ~a #x~x)" name value)
(format " (define ~a #f) ;;; ENUM NOT FOUND" name))))
enum-lst)
")")
(close-port port)
(loop (cdr features) command-lst enum-lst)))))
(define nyi
'("glCreateSyncFromCLeventARB"
"glDebugMessageCallback"
"glDebugMessageCallbackAMD"
"glDebugMessageCallbackARB"
"glDebugMessageCallbackKHR"))
(let* ([types (get-types registry)]
[types* (patch-types types)]
[type-reg (let ([safe-cdr (lambda (p) (and (pair? p) (cdr p)))])
(compose safe-cdr ($ assoc <> types*)))]
[commands (get-commands registry type-reg)]
[enums (get-enums registry)]
[features (get-features registry)])
(ensure-directory-exists "glfw/gl")
(write-gl-loaders enums commands features)
)
| false |
77751bbe1434b9b6895ed9c6235e8ad910d19c5b | 33afad58fc9ee54adeca90c3e43dd39dfaa36f78 | /graph-gen.ss | 5d07f630a19f6635fc984e4e12d54d71ef6a90f2 | [] | no_license | jeapostrophe/mv | a632f7a7f8057e591571d1d3db4efdf12624947c | eb982350c6fd41681f90c7f255f0e72ab21c499a | refs/heads/master | 2021-01-19T07:37:49.682523 | 2013-10-31T01:21:57 | 2013-10-31T01:21:57 | null | 0 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 11,637 | ss | graph-gen.ss | #lang scheme
(require "amb.ss"
"../rl/lib/posn.ss"
"../rl/lib/random.ss"
"../rl/lib/matrix-posn.ss"
(planet jaymccarthy/batched-deque))
; XXX Expose the magic in an api
; XXX I should be able to push power ups away from each, not just the prev
;; Magic
(define how-many-powerups 20)
(define how-many-hidden (* 3 how-many-powerups))
(define (powerup-interval i)
(cond
[(zero? i)
(list 0.05 0.10)]
[(i . <= . (* 0.5 how-many-powerups))
(list 0.15 0.25)]
[(i . <= . (* 0.75 how-many-powerups))
(list 0.30 0.60)]
[else
(list 0.50 0.80)]))
;; Helpers
(define-struct node (t u l r d) #:prefab)
(define (interval-in? v i)
(<= (first i) v (second i)))
(define (posn-neighbors/m m p)
(match (matrix-ref/posn m p)
[(struct node (t u l r d))
(append (if u (list (posn-up p)) empty)
(if l (list (posn-left p)) empty)
(if r (list (posn-right p)) empty)
(if d (list (posn-down p)) empty))]))
(define (greedy-dfs-path m start end max-length bad?)
(define visited (make-hash))
(define (search p i)
(cond
; We don't want to loop, but we don't want to disallow coming
; from a shorter pre-path, so this always us through if the
; previous path was longer; which is never the case with a
; cycle
[(i . <= . (hash-ref visited p -inf.0))
#f]
; If we're at the end, stop
[(equal? p end)
(list p)]
; If we're out of juice, fail
[(i . <= . 0)
#f]
[(bad? p)
#f]
[else
; Remember how long it took to get here
(hash-set! visited p i)
; And continue...
(let ([inner
(for/or ([n (in-list (permute-list (posn-neighbors/m m p)))])
; Remember to take away some juice
(search n (sub1 i)))])
(if inner
(list* p inner)
#f))]))
(or (search start max-length)
(error 'greedy-dfs-path "Cannot find path!")))
(define (bfs-search m r lim f i)
(define visited (make-hash))
(let loop ([lim lim]
[q (deque-push r deque-empty)]
[acc i])
(cond
[(deque-empty? q)
acc]
[(<= lim 0)
acc]
[else
(let ([q (deque-shift q)]
[p (deque-first q)])
(cond
[(hash-has-key? visited p)
(loop lim q acc)]
[else
(hash-set! visited p #t)
(let-values ([(add? acc) (f p acc)])
(loop (sub1 lim)
(if add?
(for/fold ([q q])
([n (in-list (posn-neighbors/m m p))])
(deque-push n q))
q)
acc))]))])))
(define (add-edge src dst m [kind #t])
(matrix-update/posn
m src
(lambda (n)
(cond
[(equal? (posn-up src) dst)
(struct-copy node n [u kind])]
[(equal? (posn-down src) dst)
(struct-copy node n [d kind])]
[(equal? (posn-left src) dst)
(struct-copy node n [l kind])]
[(equal? (posn-right src) dst)
(struct-copy node n [r kind])]))))
(define (add-edge* src dst m [kind #t])
(add-edge src dst (add-edge dst src m kind) kind))
(define (fold-edges path m f)
(for/fold ([m m])
([src (in-list path)]
[dst (in-list (rest path))])
(f src dst m)))
(define (add-edges path m)
(fold-edges path m add-edge*))
(define (hash-set* ht l)
(for/fold ([ht ht])
([i (in-list l)])
(hash-set ht i #t)))
;; Generate Path
(define (generate-path rows cols random-posn/prop start-posn)
(define max-distance
(posn-distance
(make-posn 0 0)
(make-posn (sub1 rows) (sub1 cols))))
(define (abs-powerup-interval i)
(map
(curry * max-distance)
(powerup-interval i)))
(define m1
(build-matrix
rows cols
(lambda (ri ci)
(make-node #f
(not (= ri 0))
(not (= ci 0))
(not (= ci (sub1 cols)))
(not (= ri (sub1 rows)))))))
(define (okay-distance-to-powerup? i d)
(interval-in? d (abs-powerup-interval i)))
(define-values (_mid-posn goals paths on-path?-ht target-posn?-ht)
(for/fold ([start-posn start-posn]
[goals empty]
[paths empty]
[on-path?-ht (make-immutable-hasheq empty)]
[target-posn?-ht (make-immutable-hasheq empty)])
([which-powerup (in-range how-many-powerups)])
(define end-posn
(random-posn/prop
(lambda (p)
(and (not (hash-has-key? on-path?-ht p))
(okay-distance-to-powerup? which-powerup (posn-distance start-posn p))))))
; XXX Magic number on next line: Maximum allowed distance of path... always fulfillable but leads to less meandering
(define max-length (* 2.5 (posn-distance start-posn end-posn)))
(define new-path
; By starting at the end we encourage meandering there rather than at the beginning
(reverse (greedy-dfs-path m1 end-posn start-posn max-length
; Don't allow it to cross a power-up
(curry hash-has-key? target-posn?-ht))))
(define next-start
; XXX Magic number on next line: Where the new path starts along the old
(random-list-ref new-path 0.6 0.8))
(printf "\tDone with powerup ~a~n" which-powerup)
(values next-start
(cons end-posn goals)
(cons new-path paths)
(hash-set* on-path?-ht new-path)
(hash-set target-posn?-ht end-posn which-powerup))))
(values (reverse goals)
(reverse paths)
(lambda (p) (hash-has-key? on-path?-ht p))
(lambda (p) (hash-ref target-posn?-ht p #f))))
;; Trimming edges
(define (trim-edges rows cols paths)
(for/fold ([m
(build-matrix
rows cols
(lambda (ri ci)
(make-node #f #f #f #f #f)))])
([path (in-list paths)])
(add-edges path m)))
;; Normalizing regions
(define (mark-regions paths goals im)
(for/fold ([m im])
([g (in-list goals)]
[pth (in-list paths)]
[i (in-naturals)])
(bfs-search m g (length pth)
(lambda (np m)
(define n (matrix-ref/posn m np))
(if (node-t n)
(values #f m)
(values #t
(matrix-set/posn m np (struct-copy node n [t i])))))
m)))
;; Hidden Rooms
(define (add-hidden-rooms rows cols random-posn/prop on-path?/posn how-many-hidden im)
(define valid? (make-valid-posn? rows cols))
(define (posn-sq-neighbors* p)
(filter
valid?
(list (posn-up p)
(posn-down p)
(posn-left p)
(posn-right p))))
(define-values (m hiddens is-hidden?-ht)
(for/fold ([fm im]
[hiddens empty]
[is-hidden?-ht (make-immutable-hasheq empty)])
([i (in-range how-many-hidden)])
(define hidden-p
(random-posn/prop
(lambda (p)
(and
; Not used...
(not (hash-has-key? is-hidden?-ht p))
; Not on the path...
(not (on-path?/posn p))
; But a neighbor is
(ormap on-path?/posn
(posn-sq-neighbors* p))))))
(define connector
(random-element
(filter on-path?/posn
(posn-sq-neighbors* hidden-p))))
(values (add-edge* hidden-p connector fm 'hidden)
(list* hidden-p hiddens)
(hash-set is-hidden?-ht hidden-p #t))))
(values m hiddens
(lambda (p) (hash-has-key? is-hidden?-ht p))))
;; Cleaning up landlocked nodes
; The only nodes that are reachable on blank nodes are one color
(define (landlocked? m rp)
(define an-id #f)
(define visited (make-hash))
(define (visit p)
(cond
[(hash-has-key? visited p)
#t]
[else
(local [(define t (node-t (matrix-ref/posn m p)))]
(hash-set! visited p #t)
(if t
(if an-id
(= t an-id)
(begin (set! an-id t)
#t))
(for/and ([p (in-list (posn-neighbors/m m p))])
(visit p))))]))
(and (visit rp)
an-id))
(define (normalize-landlocked hiddens paths m)
(for*/fold ([m m])
([pth (in-list (list* hiddens paths))]
[p (in-list pth)])
(define n (matrix-ref/posn m p))
(cond
[(node-t n)
m]
[(landlocked? m p)
=> (lambda (c)
(matrix-set/posn m p (struct-copy node n [t c])))]
[else
m])))
;; Adding powerups
; Remember early edges to preserve solvability
(define (add-powerups-to-edges paths goals m)
(define earlier (make-hash))
(for/fold ([m m])
([pth (in-list paths)]
[goal (in-list goals)]
[i (in-naturals)])
(fold-edges
pth m
(lambda (src dst m)
(define to-edge (cons src dst))
(define from-edge (cons dst src))
(define goal? (equal? dst goal))
(begin0
(if (or (zero? i)
(hash-has-key? earlier to-edge)
(hash-has-key? earlier from-edge)
; XXX Magic number: How often an edge requires a power up
(and (not goal?)
(not (zero? (random 3)))))
m
(add-edge src dst m
(if goal?
(max 0 (sub1 i))
(random i))))
(hash-set! earlier to-edge #t))))))
;; Work
(define (generate-map rows cols)
(define (random-posn)
(make-posn (random rows) (random cols)))
(define (random-posn/prop p?)
(define p (random-posn))
(if (p? p) p (random-posn/prop p?)))
(define start-posn (random-posn))
#;(printf "Generating path...~n")
(define-values (goals paths on-path?/posn target-posn?/posn)
(generate-path rows cols random-posn/prop start-posn))
;; Now that we have the path... modify the graph to only allow it
#;(printf "Trimming edges...~n")
(define m2 (trim-edges rows cols paths))
;; Next add some hidden rooms
#;(printf "Adding hidden rooms~n")
(define-values (m3 hiddens is-hidden?/posn)
(add-hidden-rooms rows cols random-posn/prop on-path?/posn how-many-hidden m2))
#;(printf "Marking regions~n")
(define m4 (mark-regions paths goals m3))
#;(printf "Marking land-locked areas~n")
(define m5 (normalize-landlocked hiddens paths m4))
#;(printf "Annotating edges~n")
(define m6 (add-powerups-to-edges paths goals m5))
(values start-posn is-hidden?/posn on-path?/posn target-posn?/posn m6))
(provide/contract
; XXX Better / use objects
[generate-map (-> exact-nonnegative-integer? exact-nonnegative-integer?
(values posn?
(posn? . -> . boolean?)
(posn? . -> . (or/c boolean? exact-nonnegative-integer?))
(posn? . -> . (or/c boolean? exact-nonnegative-integer?))
matrix?))]
[struct node ([t (or/c false/c exact-nonnegative-integer?)]
[u (or/c #f #t 'hidden exact-nonnegative-integer?)]
[l (or/c #f #t 'hidden exact-nonnegative-integer?)]
[r (or/c #f #t 'hidden exact-nonnegative-integer?)]
[d (or/c #f #t 'hidden exact-nonnegative-integer?)])]) | false |
55603315eb37206cdb9a4e688fe9c93e8bd3082f | a2d8b4843847507b02085bb8adabd818f57dd09f | /scheme/sicp/test-framework.scm | f2c4d7ed4c539d709f55a82195e45f36bc41c522 | [] | no_license | tcharding/self_learning | df911b018fc86bd5f918394b79d2456bf51f35a8 | f6bb5c6f74092177aa1b71da2ce87ca1bfc5ef3c | refs/heads/master | 2022-05-13T05:09:32.284093 | 2022-05-02T08:25:18 | 2022-05-02T08:25:18 | 41,029,057 | 13 | 2 | null | null | null | null | UTF-8 | Scheme | false | false | 566 | scm | test-framework.scm | ;;;; Scheme Test Framework
(define test-section '())
(define (test-eq msg got exp)
(unless (equal? got exp)
(fail msg got exp)))
(define fudge 0.001)
(define (test-feq msg got exp)
"float equivalence"
(unless (< (abs (- got exp)) fudge)
(fail msg got exp)))
(define (fail msg got exp)
(display "Test Failed: ")
(display test-section)
(display msg)
(newline)
(display "got: ")
(display got)
(newline)
(display "exp: ")
(display exp)
(newline))
(define (set-test-section! label)
(set! test-section (string-append label ": ")))
| false |
a968e05a7b66eb0ff4e7e2f7956212c8be5e48d9 | 6b8bee118bda956d0e0616cff9ab99c4654f6073 | /suda-ex/srfi-25/utils.ss | b7cc7f7708eb964b907b9244de3562ed875033f3 | [] | no_license | skchoe/2012.Functional-GPU-Programming | b3456a92531a8654ae10cda622a035e65feb762d | 56efdf79842fc465770214ffb399e76a6bbb9d2a | refs/heads/master | 2016-09-05T23:42:36.784524 | 2014-05-26T17:53:34 | 2014-05-26T17:53:34 | 20,194,204 | 1 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 1,692 | ss | utils.ss | #lang scheme
(provide lst2lst->vals2vals vals2vals->lst2lst lst2any->vals2any)
;(define-syntax (list->values lststx)
; (syntax-case lststx (list)
; [(_ (list x ...)) #'(values x ...)]
; [(_ '(x ...)) #'(values x ...)]
; [(_ (x ...)) #'(values x ...)]
; [(_ _) #'(printf "list->values - else case\n")]))
(define (list->values lst)
(vector->values (list->vector lst)))
(define-syntax values->list
(syntax-rules ()
[(_ vals) (call-with-values (lambda () vals) list)]))
;; (list -> list) -> (values -> values)
(define (lst2lst->vals2vals f)
(lambda xs
(list->values (f xs))))
;; (values -> values) -> (list -> list)
(define (vals2vals->lst2lst g)
(lambda (lst)
(values->list (apply g lst))))
;; (list -> any) -> (values -> any)
(define (lst2any->vals2any h)
(lambda xs
(h xs)))
;
(define I (lambda xs (list->values xs))) ; Values -> Values
(I 1 2 3)
(define J (lambda (x) x))
(J (list 1 2 3))
(list->values (list 1 2 3))
((lst2lst->vals2vals J) 1 3 5)
;((vals2vals->lst2lst I) (list 1 3 5))
(define goo
(lambda (lst)
(length lst)))
((lst2any->vals2any goo) 1 2 3 4 5 6 7 8)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; examples
;; values -> values
(define (f-vv xs)
(list (first xs) (last xs)))
(define f-ll (lst2lst->vals2vals f-vv))
(f-ll (list 1 2 3))
(define f-vv0 (vals2vals->lst2lst f-ll))
(f-vv0 (list 9 8 7 6))
(let* ([a (list 1 2 3 4)])
(list->values a))
(list->values (list 4 5 6 7))
(list->values '(4 5 6 7))
(let* ([a (list 1 2 3)])
(list->values a))
(define (f-ll0 lst)
(list (first lst) (last lst)))
(f-ll0 '(-1 -2 -3 -4)) | true |
1bfa260c4cda3f19a9302e8f19e65ea52609f478 | 398496271fc1e4bc679f8520e2aa12d958c71059 | /A3/a3q2_lists.scm | cae29fb232a6d8ed22b1e6ccb1541538e2d3b6a4 | [] | no_license | guptamihir418/COMP-3007 | f1d113d7f5fdc717eed424b486af6327e4b79efe | 0d34a67658d9f7fab821cbaa922fa7b11889420a | refs/heads/main | 2023-04-22T14:38:19.381362 | 2021-05-05T15:26:44 | 2021-05-05T15:26:44 | 364,622,119 | 2 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 2,873 | scm | a3q2_lists.scm | ; Mihir Gupta
; 101172281
;1
(define (repeat x n)
(if (< n 1) '()
(cons x (repeat x (- n 1)))))
; Testing cases for part A
(display "Tesing for Part A\n\n")
(display "(repeat 'a 5) -> ")
(repeat 'a 5)
(display "(repeat 'abb 10) -> ")
(repeat 'abb 10)
(newline)
;2
(define (alternate list1 list2)
(cond ((null? list1) list2)
((null? list2) list1)
(else (cons (car list1)
(cons (car list2)
(alternate (cdr list1) (cdr list2)))))))
; Testing cases for part B
(display "Tesing for Part B\n\n")
(display "(alternate '(0 0 0 0) '(1 1 1 1 1 1)) -> ")
(alternate '(0 0 0 0) '(1 1 1 1 1 1))
(display "(alternate '(a a a a) '(b b b b)) -> ")
(alternate '(a a a a) '(b b b b))
(newline)
;3
(define (count x L)
(cond ((null? L) 0)
((equal? (car L) x) (+ 1 (count x (cdr L))))
(else (count x (cdr L)))))
;Testing for part C
(display "Tesing for Part C\n\n")
(display "(count 3 '(1 4 3 6 2 3 3 1 4 3 5 7)) -> ")
(count 3 '(1 4 3 6 2 3 3 1 4 3 5 7))
(display "(count 'b '(4 b a 3 2 c b 1 b d a)) -> ")
(count 'b '(4 b a 3 2 c b 1 b d a))
(newline)
;4
(define (mode L)
(define (helper1 A B x Final)
(cond ((null? A) Final) ; return the last stored val
((<= (car B) x) (helper1 (cdr A) (cdr B) x Final))
(else (helper1 (cdr A) (cdr B) (car B) (car A)) )))
(define (helper2 A B)
(if (= 0 (length A)) (list )
(cons (count (car A) B) (helper2 (cdr A) B))))
(helper1 L (helper2 L L) 0 0))
;Testing for part D
(display "Tesing for Part D\n\n")
(display "(mode '(a b b c a c c c c c b b)) -> ")
(mode '(a b b c a c c c c c b b))
(display "(mode '(a b a c a d d a b c a b)) -> ")
(mode '(a b a c a d d a b c a b))
(display "(mode '(2 b a 3 2 c b 1 2 d a)) -> ")
(mode '(2 b a 3 2 c b 1 2 d a))
(newline)
;5
(define (decreasing L)
(define (helper1_decreasing X L)
(cond ((eq? (length L) 0) '())
((< (car L) X) (cons (car L) (helper1_decreasing (car L) (cdr L))))
(else (helper1_decreasing X (list )))))
(define (helper2_decreasing L)
(cond ((= (length L) 0) '())
((<= (length (car L)) 1) (helper2_decreasing (cdr L)) )
(else (cons (car L) (helper2_decreasing (cdr L)) ))))
(define (helper3_decreasing L)
(cond ((eq? 0 (length L)) '())
(else (cons (helper1_decreasing (+ (car L) 1) L) (helper3_decreasing (cdr L))))))
(helper2_decreasing (helper3_decreasing L)))
;Testing for part E
(display "Tesing for Part E\n\n")
(display "(decreasing '(3 6 8 9 7 4 8 6 3)) -> ")
(decreasing '(3 6 8 9 7 4 8 6 3))
(display "(decreasing '(7 6 5 4 8 5 2 5 1 5 2 1)) -> ")
(decreasing '(7 6 5 4 8 5 2 5 1 5 2 1))
(display "(decreasing '(1 2 3 3 3 4 5)) -> ")
(decreasing '(1 2 3 3 3 4 5))
| false |
55bd29fcd5611f638ecc16dd0feb0a7e88fbd539 | 8ebb8dfb17ecafdb8becb6251c456eaf82a5f514 | /lib/main.scm | 920b210f67f8628589d0e91c7d5e7c9a314394fe | [
"MIT",
"Apache-2.0"
] | permissive | DemiMarie/rusty_scheme | cf5abd908000e21d191ba3be072157914415f900 | b1291b921de317eb29effe3062ae94c003370e2c | refs/heads/master | 2020-04-12T05:33:35.560463 | 2016-10-03T02:12:49 | 2016-10-03T02:12:49 | 62,069,176 | 27 | 2 | null | null | null | null | UTF-8 | Scheme | false | false | 1,651 | scm | main.scm | ;;; -*- scheme -*-
#;(import
(rnrs)
(only (srfi :43) vector-copy)
(tree-walk)
(environment)
(bytecode)
(assembler)
(only (guile) parameterize)
(ice-9 pretty-print))
(import (srfi :43))
(include "bytecode.scm")
(include "assembler.scm")
(include "environment.scm")
(include "tree-walk.scm")
(define (bound? sym) (symbol-bound? #f sym))
(define aset! vector-set!)
(define aref vector-ref)
(define (atom? obj) (not (pair? obj)))
(define (void) #t)
(define bco (create-bco))
(define env (env.new))
(define (compile-one-form)
(let ((res (read)))
(if (eof-object? res)
(values)
(begin
(compile-toplevel-form res env bco)
(compile-one-form)))))
(let ((tmp-bco (create-bco))
(tmp-env (env.new)))
(emit-constant tmp-bco 'alpha)
(emit-constant tmp-bco 'alpha)
(assert (= 1 (bco.consts-len tmp-bco))))
(define (compile-file filename)
(with-input-from-file filename compile-one-form))
(define (main args)
(for-each compile-file args)
(assert (bco? bco))
(assert (> (bco.len bco) 0))
(let ((instrs
(vector-copy (bco.instrs bco)
0
(bco.len bco)
#f)))
(display "----BEGIN INSTRS----\n")
(pretty-print instrs)
(newline)
#;(pretty-print
(vector
instrs
(vector-copy (bco.consts bco)
0
(bco.consts-len bco)
#f)))
(pretty-print (assemble-bytecode instrs))))
#;(pretty-print
(assemble-bytecode
(vector->list instrs)))
(fluid-set! read-eval? #t)
(pretty-print (main '("system.lsp")))
| false |
7ceab9491479e5b722eeb539b53901226947153d | ac2a3544b88444eabf12b68a9bce08941cd62581 | /gsc/tests/08-flprim/flpred.scm | b433cec8151f3eaffd8548159af9eec36c98a146 | [
"Apache-2.0",
"LGPL-2.1-only"
] | permissive | tomelam/gambit | 2fd664cf6ea68859d4549fdda62d31a25b2d6c6f | d60fdeb136b2ed89b75da5bfa8011aa334b29020 | refs/heads/master | 2020-11-27T06:39:26.718179 | 2019-12-15T16:56:31 | 2019-12-15T16:56:31 | 229,341,552 | 1 | 0 | Apache-2.0 | 2019-12-20T21:52:26 | 2019-12-20T21:52:26 | null | UTF-8 | Scheme | false | false | 491 | scm | flpred.scm | (declare (extended-bindings) (not constant-fold) (not safe))
(define (test1 x)
(println (##flinteger? x))
(println (##flzero? x))
(println (##flpositive? x))
(println (##flnegative? x))
(println (##flodd? x))
(println (##fleven? x))
(println (##flfinite? x))
(println (##flinfinite? x))
(println (##flnan? x))
(println ""))
(define (test2 n)
(println (##fixnum->flonum-exact? n)))
(test1 0.0)
(test1 -0.0)
(test1 13.0)
(test1 -90.0)
(test1 1.5)
(test2 12345)
| false |
c644008b79207bb716e9dab894373f53b9fb293a | defeada37d39bca09ef76f66f38683754c0a6aa0 | /System.Data/system/data/typed-data-set-generator.sls | b8158c68d9b934cddeb5b54ad42a84ba77094d0d | [] | no_license | futsuki/ironscheme-port | 2dbac82c0bda4f4ff509208f7f00a5211d1f7cd5 | 4e7a81b0fbeac9a47440464988e53fb118286c54 | refs/heads/master | 2016-09-06T17:13:11.462593 | 2015-09-26T18:20:40 | 2015-09-26T18:20:40 | 42,757,369 | 0 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 877 | sls | typed-data-set-generator.sls | (library (system data typed-data-set-generator)
(export new is? typed-data-set-generator? generate generate-id-name)
(import (ironscheme-clr-port))
(define-syntax new
(lambda (e)
(syntax-case e ()
((_ a ...)
#'(clr-new System.Data.TypedDataSetGenerator a ...)))))
(define (is? a) (clr-is System.Data.TypedDataSetGenerator a))
(define (typed-data-set-generator? a)
(clr-is System.Data.TypedDataSetGenerator a))
(define-method-port
generate
System.Data.TypedDataSetGenerator
Generate
(static:
System.Void
System.Data.DataSet
System.CodeDom.CodeNamespace
System.CodeDom.Compiler.ICodeGenerator))
(define-method-port
generate-id-name
System.Data.TypedDataSetGenerator
GenerateIdName
(static:
System.String
System.String
System.CodeDom.Compiler.ICodeGenerator)))
| true |
f2c86fc4251f5924fb865cfcbf6e7ff79cc1cd76 | a74932f6308722180c9b89c35fda4139333703b8 | /edwin48/window.scm | 339e177d62f0c8839d5dd64bb128209088777ded | [] | no_license | scheme/edwin48 | 16b5d865492db5e406085e8e78330dd029f1c269 | fbe3c7ca14f1418eafddebd35f78ad12e42ea851 | refs/heads/master | 2021-01-19T17:59:16.986415 | 2014-12-21T17:50:27 | 2014-12-21T17:50:27 | 1,035,285 | 39 | 10 | null | 2022-02-15T23:21:14 | 2010-10-29T16:08:55 | Scheme | UTF-8 | Scheme | false | false | 18,663 | scm | window.scm | #| -*-Scheme-*-
$Id: window.scm,v 1.166 2008/01/30 20:02:07 cph Exp $
Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994,
1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
2006, 2007, 2008 Massachusetts Institute of Technology
This file is part of MIT/GNU Scheme.
MIT/GNU Scheme 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.
MIT/GNU Scheme 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 MIT/GNU Scheme; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301,
USA.
|#
;;;; Window System
;;; Based on WINDOW-WIN, designed by RMS.
;;; See WINOPS.TXT for more information.
;;; The convention of using method names like :FOO is somewhat
;;; arbitrary. However, methods without the prefix ":" are intended
;;; to be internal (non-public) methods.
;;; Procedural covers are used as the ultimate outside interface to
;;; the window system, since that minimizes dependence on the
;;; syntactic details of the class/object system.
;;; It is assumed in several places that all windows keep the
;;; following instance variables updated: SUPERIOR, X-SIZE, and
;;; Y-SIZE. Thus these are normally accessed using procedure calls or
;;; instance variable references, rather than the more cumbersome
;;; method invocation. However, these instance variables are always
;;; set by a method defined on the window itself.
;;; It is assumed in several places that the methods to set a window's
;;; size are called with interrupts disabled.
;;;; Vanilla Window
(define-class vanilla-window #f
(superior x-size y-size redisplay-flags inferiors))
(define (window-initialize! window window*)
(%set-window-superior! window window*)
(set-window-inferiors! window '())
(%set-window-redisplay-flags!
window
(==> window* :inferior-redisplay-flags window)))
(define (window-kill! window)
(for-each-inferior-window window (lambda (window) (==> window :kill!))))
(define (window-superior window)
(with-instance-variables vanilla-window window (superior) superior))
(define (%set-window-superior! window window*)
(with-instance-variables vanilla-window window (superior)
(set! superior window*)))
(define (window-x-size window)
(with-instance-variables vanilla-window window (x-size) x-size))
(define (%set-window-x-size! window x)
(with-instance-variables vanilla-window window (x-size) (set! x-size x)))
(define (window-y-size window)
(with-instance-variables vanilla-window window (y-size) y-size))
(define (%set-window-y-size! window y)
(with-instance-variables vanilla-window window (y-size) (set! y-size y)))
(define (window-redisplay-flags window)
(with-instance-variables vanilla-window window (redisplay-flags) redisplay-flags))
(define (%set-window-redisplay-flags! window flags)
(with-instance-variables vanilla-window window (redisplay-flags)
(set! redisplay-flags flags)))
(define (window-inferiors window)
(with-instance-variables vanilla-window window (inferiors) inferiors))
(define (set-window-inferiors! window inferiors*)
(with-instance-variables vanilla-window window (inferiors)
(set! inferiors inferiors*)))
(define (window-root-window window)
(if (window-superior window)
(window-root-window (window-superior window))
window))
(define (set-window-superior! window window*)
(%set-window-superior! window window*)
(let ((flags (==> window* :inferior-redisplay-flags window)))
(%set-window-redisplay-flags! window flags)
(setup-redisplay-flags! flags)
(for-each-inferior window
(lambda (inferior)
(set-inferior-redisplay-flags! inferior (cons #f flags))
(==> (inferior-window inferior) :set-superior! window)))))
(define (window-size window receiver)
(receiver (window-x-size window) (window-y-size window)))
(define (set-window-x-size! window x)
(%set-window-x-size! window x)
(window-needs-redisplay! window))
(define (set-window-y-size! window y)
(%set-window-y-size! window y)
(window-needs-redisplay! window))
(define (set-window-size! window x y)
(%set-window-x-size! window x)
(%set-window-y-size! window y)
(window-needs-redisplay! window))
(define (window-needs-redisplay? window)
(car (window-redisplay-flags window)))
(define (window-needs-redisplay! window)
(if (not (car (window-redisplay-flags window)))
(setup-redisplay-flags! (window-redisplay-flags window))))
(define (window-inferior? window window*)
(find-inferior? (window-inferiors window) window*))
(define (window-inferior window window*)
(find-inferior (window-inferiors window) window*))
(define (for-each-inferior window procedure)
(let loop ((inferiors (window-inferiors window)))
(if (not (null? inferiors))
(begin
(procedure (car inferiors))
(loop (cdr inferiors))))))
(define (for-each-inferior-window window procedure)
(for-each-inferior window
(lambda (inferior)
(procedure (inferior-window inferior)))))
(define (make-inferior window class)
(let ((window* (make-object class)))
(let ((inferior
(%make-inferior window*
#f
#f
(cons #f (window-redisplay-flags window)))))
(set-window-inferiors! window (cons inferior (window-inferiors window)))
(==> window* :initialize! window)
inferior)))
(define (add-inferior! window window*)
(let ((inferior
(%make-inferior window*
#f
#f
(cons #f (window-redisplay-flags window)))))
(set-window-inferiors! window (cons inferior (window-inferiors window)))
(==> window* :set-superior! window)
inferior))
(define (delete-inferior! window window*)
(set-window-inferiors! window
(let ((inferiors (window-inferiors window)))
(delete! (find-inferior inferiors window*)
inferiors eq?))))
(define (replace-inferior! window old new)
(set-inferior-window! (find-inferior (window-inferiors window) old) new)
(==> new :set-superior! window))
;;; Returns #T if the redisplay finished, #F if aborted.
;;; Notice that the :UPDATE-DISPLAY! operation is assumed to return
;;; the same value. This is used to control the setting of the
;;; redisplay flags.
(define (window-update-display! window screen x-start y-start xl xu yl yu
display-style)
(update-inferiors! (window-inferiors window) screen x-start y-start
xl xu yl yu display-style
(lambda (window screen x-start y-start xl xu yl yu display-style)
(and (or (display-style/ignore-input? display-style)
(not ((editor-halt-update? current-editor))))
(==> window :update-display! screen x-start y-start xl xu yl yu
display-style)))))
(define (update-inferiors! inferiors screen x-start y-start xl xu yl yu
display-style updater)
(let loop ((inferiors inferiors))
(if (null? inferiors)
#t
(and (update-inferior! (car inferiors) screen x-start y-start
xl xu yl yu display-style updater)
(loop (cdr inferiors))))))
(define (update-inferior! inferior screen x-start y-start xl xu yl yu
display-style updater)
(or (not (or (display-style/ignore-redisplay-flags? display-style)
(inferior-needs-redisplay? inferior)))
(let ((window (inferior-window inferior))
(xi (inferior-x-start inferior))
(yi (inferior-y-start inferior)))
(and (or (not xi)
(clip-window-region-1 (fix:- xl xi)
(fix:- xu xi)
(window-x-size window)
(lambda (xl xu)
(clip-window-region-1 (fix:- yl yi)
(fix:- yu yi)
(window-y-size window)
(lambda (yl yu)
(updater window
screen (fix:+ x-start xi) (fix:+ y-start yi)
xl xu yl yu display-style))))))
(begin
(set-car! (inferior-redisplay-flags inferior) #f)
#t)))))
(define (clip-window-region-1 al au bs receiver)
(if (fix:< 0 al)
(if (fix:< au bs)
(if (fix:< al au) (receiver al au) #t)
(if (fix:< al bs) (receiver al bs) #t))
(if (fix:< au bs)
(if (fix:< 0 au) (receiver 0 au) #t)
(if (fix:< 0 bs) (receiver 0 bs) #t))))
(define (salvage-inferiors! window)
(for-each-inferior-window window (lambda (window) (==> window :salvage!))))
(define (display-style/discard-screen-contents? display-style)
(if (pair? display-style)
(memq 'DISCARD-SCREEN-CONTENTS display-style)
(and display-style (not (null? display-style)))))
(define (display-style/no-screen-output? display-style)
(and (pair? display-style)
(memq 'NO-SCREEN-OUTPUT display-style)))
(define (display-style/ignore-redisplay-flags? display-style)
(if (pair? display-style)
(memq 'IGNORE-REDISPLAY-FLAGS display-style)
(and display-style (not (null? display-style)))))
(define (display-style/ignore-input? display-style)
(if (pair? display-style)
(memq 'IGNORE-INPUT display-style)
(and display-style (not (null? display-style)))))
;;;; Standard Methods
;;; All windows support these operations
(define-method vanilla-window :initialize! window-initialize!)
(define-method vanilla-window :kill! window-kill!)
(define-method vanilla-window :superior window-superior)
(define-method vanilla-window :set-superior! set-window-superior!)
(define-method vanilla-window :x-size window-x-size)
(define-method vanilla-window :set-x-size! set-window-x-size!)
(define-method vanilla-window :y-size window-y-size)
(define-method vanilla-window :set-y-size! set-window-y-size!)
(define-method vanilla-window :size window-size)
(define-method vanilla-window :set-size! set-window-size!)
(define-method vanilla-window (:make-inferior window class)
(inferior-window (make-inferior window class)))
(define-method vanilla-window :add-inferior! add-inferior!)
(define-method vanilla-window :delete-inferior! delete-inferior!)
(define-method vanilla-window :replace-inferior! replace-inferior!)
(define-method vanilla-window :update-display! window-update-display!)
(define-method vanilla-window :salvage! salvage-inferiors!)
;;;; Operations on Inferiors
(define-method vanilla-window (:inferior-redisplay-flags window window*)
(let ((inferiors (window-inferiors window)))
(inferior-redisplay-flags (find-inferior inferiors window*))))
(define-method vanilla-window (:inferior-needs-redisplay! window window*)
(let ((inferiors (window-inferiors window)))
(inferior-needs-redisplay! (find-inferior inferiors window*))))
(define-method vanilla-window (:inferior-position window window*)
(let ((inferiors (window-inferiors window)))
(inferior-position (find-inferior inferiors window*))))
(define-method vanilla-window (:set-inferior-position! window window* position)
(let ((inferiors (window-inferiors window)))
(set-inferior-position! (find-inferior inferiors window*) position)))
(define-method vanilla-window (:inferior-x-start window window*)
(let ((inferiors (window-inferiors window)))
(inferior-x-start (find-inferior inferiors window*))))
(define-method vanilla-window (:set-inferior-x-start! window window* x-start)
(let ((inferiors (window-inferiors window)))
(set-inferior-x-start! (find-inferior inferiors window*) x-start)))
(define-method vanilla-window (:inferior-x-end window window*)
(let ((inferiors (window-inferiors window)))
(inferior-x-end (find-inferior inferiors window*))))
(define-method vanilla-window (:set-inferior-x-end! window window* x-end)
(let ((inferiors (window-inferiors window)))
(set-inferior-x-end! (find-inferior inferiors window*) x-end)))
(define-method vanilla-window (:inferior-y-start window window*)
(let ((inferiors (window-inferiors window)))
(inferior-y-start (find-inferior inferiors window*))))
(define-method vanilla-window (:set-inferior-y-start! window window* y-start)
(let ((inferiors (window-inferiors window)))
(set-inferior-y-start! (find-inferior inferiors window*) y-start)))
(define-method vanilla-window (:inferior-y-end window window*)
(let ((inferiors (window-inferiors window)))
(inferior-y-end (find-inferior inferiors window*))))
(define-method vanilla-window (:set-inferior-y-end! window window* y-end)
(let ((inferiors (window-inferiors window)))
(set-inferior-y-end! (find-inferior inferiors window*) y-end)))
(define-method vanilla-window (:inferior-start window window* receiver)
(let ((inferiors (window-inferiors window)))
(inferior-start (find-inferior inferiors window*) receiver)))
(define-method vanilla-window (:set-inferior-start! window window* x y)
(let ((inferiors (window-inferiors window)))
(set-inferior-start! (find-inferior inferiors window*) x y)))
;;;; Inferiors
(define %inferior-tag
"inferior")
(define (%make-inferior window x-start y-start redisplay-flags)
(vector %inferior-tag window x-start y-start redisplay-flags))
(define (inferior-window inferior)
(vector-ref inferior 1))
(define (set-inferior-window! inferior window)
(vector-set! inferior 1 window))
(define (inferior-x-start inferior)
(vector-ref inferior 2))
(define (%set-inferior-x-start! inferior x-start)
(vector-set! inferior 2 x-start))
(define (inferior-y-start inferior)
(vector-ref inferior 3))
(define (%set-inferior-y-start! inferior y-start)
(vector-set! inferior 3 y-start))
(define (inferior-redisplay-flags inferior)
(vector-ref inferior 4))
(define (set-inferior-redisplay-flags! inferior redisplay-flags)
(vector-set! inferior 4 redisplay-flags))
;; (unparser/set-tagged-vector-method! %inferior-tag
;; (unparser/standard-method 'INFERIOR
;; (lambda (state inferior)
;; (unparse-object state (inferior-window inferior))
;; (unparse-string state " x,y=(")
;; (unparse-object state (inferior-x-start inferior))
;; (unparse-string state ",")
;; (unparse-object state (inferior-y-start inferior))
;; (unparse-string state ")")
;; (if (inferior-needs-redisplay? inferior)
;; (unparse-string state " needs-redisplay")))))
(define (inferior-copy inferior)
(%make-inferior (inferior-window inferior)
(inferior-x-start inferior)
(inferior-y-start inferior)
(inferior-redisplay-flags inferior)))
(define (inferior-start inferior receiver)
(receiver (inferior-x-start inferior)
(inferior-y-start inferior)))
(define (%set-inferior-start! inferior x-start y-start)
(%set-inferior-x-start! inferior x-start)
(%set-inferior-y-start! inferior y-start))
(define (set-inferior-x-start! inferior x-start)
(%set-inferior-x-start! inferior x-start)
(inferior-needs-redisplay! inferior))
(define (set-inferior-y-start! inferior y-start)
(%set-inferior-y-start! inferior y-start)
(inferior-needs-redisplay! inferior))
(define (set-inferior-start! inferior x-start y-start)
(%set-inferior-start! inferior x-start y-start)
(inferior-needs-redisplay! inferior))
(define (%inferior-x-end inferior)
(fix:+ (inferior-x-start inferior) (inferior-x-size inferior)))
(define (%inferior-y-end inferior)
(fix:+ (inferior-y-start inferior) (inferior-y-size inferior)))
(define (inferior-x-end inferior)
(and (inferior-x-start inferior)
(%inferior-x-end inferior)))
(define (inferior-y-end inferior)
(and (inferior-y-start inferior)
(%inferior-y-end inferior)))
(define (set-inferior-x-end! inferior x-end)
(set-inferior-x-start! inferior (fix:- x-end (inferior-x-size inferior))))
(define (set-inferior-y-end! inferior y-end)
(set-inferior-y-start! inferior (fix:- y-end (inferior-y-size inferior))))
(define (inferior-position inferior)
(and (inferior-x-start inferior)
(cons (inferior-x-start inferior)
(inferior-y-start inferior))))
(define (set-inferior-position! inferior position)
(if (not position)
(set-inferior-start! inferior #f #f)
(set-inferior-start! inferior (car position) (cdr position))))
(define (inferior-needs-redisplay? inferior)
(car (inferior-redisplay-flags inferior)))
(define (inferior-needs-redisplay! inferior)
(if (and (inferior-x-start inferior) (inferior-y-start inferior))
(if (not (car (inferior-redisplay-flags inferior)))
(setup-redisplay-flags! (inferior-redisplay-flags inferior)))
(set-car! (inferior-redisplay-flags inferior) #f)))
(define (setup-redisplay-flags! flags)
(let loop ((flags flags))
(if (not (or (null? flags) (car flags)))
(begin
(set-car! flags #t)
(loop (cdr flags))))))
(define (inferior-x-size inferior)
(window-x-size (inferior-window inferior)))
(define (%set-inferior-x-size! inferior x)
(%set-window-x-size! (inferior-window inferior) x))
(define (set-inferior-x-size! inferior x)
(==> (inferior-window inferior) :set-x-size! x))
(define (inferior-y-size inferior)
(window-y-size (inferior-window inferior)))
(define (%set-inferior-y-size! inferior y)
(%set-window-y-size! (inferior-window inferior) y))
(define (set-inferior-y-size! inferior y)
(==> (inferior-window inferior) :set-y-size! y))
(define (inferior-size inferior receiver)
(window-size (inferior-window inferior) receiver))
(define (set-inferior-size! inferior x y)
(==> (inferior-window inferior) :set-size! x y))
(define (find-inferior? inferiors window)
(let loop ((inferiors inferiors))
(and (not (null? inferiors))
(if (eq? window (inferior-window (car inferiors)))
(car inferiors)
(loop (cdr inferiors))))))
(define (find-inferior inferiors window)
(let ((inferior (find-inferior? inferiors window)))
(if (not inferior)
(error "window not in inferiors" window))
inferior))
(define (inferior-containing-coordinates window x y stop-search?)
(let search ((window window) (x x) (y y))
(if (stop-search? window)
(values window x y)
(let loop ((inferiors (window-inferiors window)))
(if (null? inferiors)
(values #f #f #f)
(let ((inferior (car inferiors)))
(let ((x-start (inferior-x-start inferior))
(y-start (inferior-y-start inferior)))
(if (and x-start y-start)
(let ((x (fix:- x x-start))
(y (fix:- y y-start)))
(if (and (fix:<= 0 x)
(fix:< x (inferior-x-size inferior))
(fix:<= 0 y)
(fix:< y (inferior-y-size inferior)))
(search (inferior-window inferior) x y)
(loop (cdr inferiors))))
(loop (cdr inferiors))))))))))
;;
;; Local Variables:
;; eval: (put 'with-instance-variables 'scheme-indent-function 3)
;; End:
;; | false |
1ca6a36ddcc6f4c1d86498cdc838415792642e03 | 4f17c70ae149426a60a9278c132d5be187329422 | /scheme/tests/racket-r6rs/arithmetic/fixnums.sls | e9439e13237dd20aeb1844949aa4a5f38ee1e654 | [] | no_license | okuoku/yuni-core | 8da5e60b2538c79ae0f9d3836740c54d904e0da4 | c709d7967bcf856bdbfa637f771652feb1d92625 | refs/heads/master | 2020-04-05T23:41:09.435685 | 2011-01-12T15:54:23 | 2011-01-12T15:54:23 | 889,749 | 2 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 11,038 | sls | fixnums.sls | #!r6rs
(library (yuni scheme tests racket-r6rs arithmetic fixnums)
(export run-arithmetic-fixnums-tests)
(import (yuni scheme r6rs)
(yuni scheme tests racket-r6rs test))
;; Originally from Ikarus test suite:
(define (fx*/carry-reference fx1 fx2 fx3)
(let* ([s (+ (* fx1 fx2) fx3)]
[s0 (mod0 s (expt 2 (fixnum-width)))]
[s1 (div0 s (expt 2 (fixnum-width)))])
(values s0 s1)))
(define (fx+/carry-reference fx1 fx2 fx3)
(let* ([s (+ (+ fx1 fx2) fx3)]
[s0 (mod0 s (expt 2 (fixnum-width)))]
[s1 (div0 s (expt 2 (fixnum-width)))])
(values s0 s1)))
(define (fx-/carry-reference fx1 fx2 fx3)
(let* ([s (- (- fx1 fx2) fx3)]
[s0 (mod0 s (expt 2 (fixnum-width)))]
[s1 (div0 s (expt 2 (fixnum-width)))])
(values s0 s1)))
(define (vals->list f a b c)
(call-with-values (lambda () (f a b c)) list))
(define-syntax carry-test
(syntax-rules ()
[(_ fxop/carry fxop/carry-reference fx1 fx2 fx3)
(run-test `(fxop/carry ,fx1 ,fx2 ,fx3)
(vals->list fxop/carry fx1 fx2 fx3)
(vals->list fxop/carry-reference fx1 fx2 fx3))]))
(define (carry-tests l)
(for-each
(lambda (n)
(for-each
(lambda (m)
(for-each
(lambda (p)
(carry-test fx*/carry fx*/carry-reference n m p)
(carry-test fx+/carry fx+/carry-reference n m p)
(carry-test fx-/carry fx-/carry-reference n m p))
l))
l))
l))
(define (run-arithmetic-fixnums-tests)
(test (fxfirst-bit-set 0) -1)
(test (fxfirst-bit-set 1) 0)
(test (fxfirst-bit-set -4) 2)
(test (fxreverse-bit-field #b1010010 1 4) 88) ; #b1011000
;; ----------------------------------------
(test (least-fixnum) (- (expt 2 (- (fixnum-width) 1))))
(test (greatest-fixnum) (- (expt 2 (- (fixnum-width) 1)) 1))
(test (fixnum? 1.0) #f)
(test (fixnum? 1+1i) #f)
(test (fixnum? 0) #t)
(test (fixnum? 1) #t)
(test (fixnum? -1) #t)
(test (fixnum? (- (expt 2 23))) #t)
(test (fixnum? (- (expt 2 23) 1)) #t)
(test (fixnum? (least-fixnum)) #t)
(test (fixnum? (- (least-fixnum) 1)) #f)
(test (fixnum? (greatest-fixnum)) #t)
(test (fixnum? (+ 1 (greatest-fixnum))) #f)
(let ([test-ordered
(lambda (a b c)
(test (fx=? a a) #t)
(test (fx=? b b) #t)
(test (fx=? c c) #t)
(test (fx=? a b) #f)
(test (fx=? b a) #f)
(test (fx=? b c) #f)
(test (fx=? c b) #f)
(test (fx=? a c b) #f)
(test (fx=? a a b) #f)
(test (fx=? a b b) #f)
(let ([test-lt
(lambda (fx<? fx<=? a b c)
(test (fx<? a b) #t)
(test (fx<? b c) #t)
(test (fx<? a c) #t)
(test (fx<? a b c) #t)
(test (fx<? b a) #f)
(test (fx<? c b) #f)
(test (fx<? a c b) #f)
(test (fx<=? a a) #t)
(test (fx<=? a b) #t)
(test (fx<=? a c) #t)
(test (fx<=? b b) #t)
(test (fx<=? b c) #t)
(test (fx<=? c c) #t)
(test (fx<=? a c c) #t)
(test (fx<=? a b c) #t)
(test (fx<=? b b c) #t)
(test (fx<=? c a) #f)
(test (fx<=? b a) #f)
(test (fx<=? a c b) #f)
(test (fx<=? b c a) #f))])
(test-lt fx<? fx<=? a b c)
(test-lt fx>? fx>=? c b a))
;; Since b is between a and c, we can add or subtract 1:
(test (fx=? (+ b 1) (+ b 1)) #t)
(test (fx<? b (+ b 1)) #t)
(test (fx<=? b (+ b 1)) #t)
(test (fx>? b (+ b 1)) #f)
(test (fx>=? b (+ b 1)) #f)
(test (fx=? (- b 1) (- b 1)) #t)
(test (fx<? b (- b 1)) #f)
(test (fx<=? b (- b 1)) #f)
(test (fx>? b (- b 1)) #t)
(test (fx>=? b (- b 1)) #t)
;; Check min & max while we have ordered values:
(test (fxmin a b) a)
(test (fxmin b c) b)
(test (fxmin a c) a)
(test (fxmin b a c) a)
(test (fxmax a b) b)
(test (fxmax b c) c)
(test (fxmax a c) c)
(test (fxmax b c a) c))])
(test-ordered 1 2 3)
(test-ordered -1 0 1)
(test-ordered (least-fixnum) 1 (greatest-fixnum)))
(test (fxzero? 0) #t)
(test (fxzero? 1) #f)
(test (fxzero? (greatest-fixnum)) #f)
(test (fxzero? (least-fixnum)) #f)
(test (fxpositive? 0) #f)
(test (fxpositive? (least-fixnum)) #f)
(test (fxpositive? (greatest-fixnum)) #t)
(test (fxnegative? 0) #f)
(test (fxnegative? (least-fixnum)) #t)
(test (fxnegative? (greatest-fixnum)) #f)
(test (fxodd? 0) #f)
(test (fxodd? 2) #f)
(test (fxodd? 1) #t)
(test (fxodd? -1) #t)
(test (fxodd? (greatest-fixnum)) #t)
(test (fxodd? (least-fixnum)) #f)
(test (fxeven? 0) #t)
(test (fxeven? 2) #t)
(test (fxeven? 1) #f)
(test (fxeven? -1) #f)
(test (fxeven? (greatest-fixnum)) #f)
(test (fxeven? (least-fixnum)) #t)
(test (fx+ 3 17) 20)
(test (fx+ (greatest-fixnum) (least-fixnum)) -1)
(test (fx+ 0 (greatest-fixnum)) (greatest-fixnum))
(test (fx+ 0 (least-fixnum)) (least-fixnum))
(test/exn (fx+ (greatest-fixnum) 1) &implementation-restriction)
(test/exn (fx+ (least-fixnum) -1) &implementation-restriction)
(test (fx* 3 17) 51)
(test (fx* 1 (least-fixnum)) (least-fixnum))
(test (fx* 1 (greatest-fixnum)) (greatest-fixnum))
(test (fx* -1 (greatest-fixnum)) (+ (least-fixnum) 1))
(test/exn (fx* (greatest-fixnum) 2) &implementation-restriction)
(test/exn (fx* (least-fixnum) -1) &implementation-restriction)
(test (fx- 1) -1)
(test (fx- -1) 1)
(test (fx- 0) 0)
(test (fx- (greatest-fixnum)) (+ 1 (least-fixnum)))
(test (fx- (greatest-fixnum) 1) (- (greatest-fixnum) 1))
(test (fx- (greatest-fixnum) (greatest-fixnum)) 0)
(test (fx- (least-fixnum) (least-fixnum)) 0)
(test/exn (fx- (least-fixnum)) &implementation-restriction)
(test/exn (fx- (least-fixnum) 1) &implementation-restriction)
;; If you put N numbers here, it runs to O(N^3) tests!
(carry-tests (list 0 1 2 -1 -2 38734 -3843 2484598 -348732487
(greatest-fixnum) (least-fixnum)))
(test (fxdiv 123 10) 12)
(test (fxmod 123 10) 3)
(test (fxdiv 123 -10) -12)
(test (fxmod 123 -10) 3)
(test (fxdiv -123 10) -13)
(test (fxmod -123 10) 7)
(test (fxdiv -123 -10) 13)
(test (fxmod -123 -10) 7)
(test/values (fxdiv-and-mod -123 10) -13 7)
(test (fxdiv0 123 10) 12)
(test (fxmod0 123 10) 3)
(test (fxdiv0 123 -10) -12)
(test (fxmod0 123 -10) 3)
(test (fxdiv0 -123 10) -12)
(test (fxmod0 -123 10) -3)
(test (fxdiv0 -123 -10) 12)
(test (fxmod0 -123 -10) -3)
(test/values (fxdiv0-and-mod0 -123 10) -12 -3)
(test/exn (fxdiv 1 0) &assertion)
(test/exn (fxmod 1 0) &assertion)
(test/exn (fxdiv-and-mod 1 0) &assertion)
(test/exn (fxdiv0 1 0) &assertion)
(test/exn (fxmod0 1 0) &assertion)
(test/exn (fxdiv0-and-mod0 1 0) &assertion)
(test/exn (fxdiv (least-fixnum) -1) &implementation-restriction)
(test/exn (fxdiv-and-mod (least-fixnum) -1) &implementation-restriction)
(test/exn (fxdiv0 (least-fixnum) -1) &implementation-restriction)
(test/exn (fxdiv0-and-mod0 (least-fixnum) -1) &implementation-restriction)
(test (fxnot 0) -1)
(test (fxnot -2) 1)
(test (fxnot 1) -2)
(test (fxand 7) 7)
(test (fxand 7 0) 0)
(test (fxand 7 1) 1)
(test (fxand 7 5) 5)
(test (fxand 7 4 5) 4)
(test (fxand 7 5 4) 4)
(test (fxior 7) 7)
(test (fxior 7 0) 7)
(test (fxior 5 4) 5)
(test (fxior 5 3) 7)
(test (fxior 5 3 32) 39)
(test (fxxor 7) 7)
(test (fxxor 7 0) 7)
(test (fxxor 5 4) 1)
(test (fxxor 5 3) 6)
(test (fxxor 5 1 32) 36)
(test (fxif 5 15 0) 5)
(test (fxif 5 0 15) 10)
(test (fxif 5 0 1) 0)
(test (fxif 5 0 3) 2)
(test (fxif 5 3 0) 1)
(test (fxbit-count 5) 2)
(test (fxbit-count 6) 2)
(test (fxbit-count 7) 3)
(test (fxbit-count -7) -3)
(test (fxlength 1) 1)
(test (fxlength 255) 8)
(test (fxlength 0) 0)
(test (fxlength -2) 1)
(test (fxlength -255) 8)
(test (fxfirst-bit-set 0) -1)
(test (fxfirst-bit-set 1) 0)
(test (fxfirst-bit-set 16) 4)
(test (fxfirst-bit-set -2) 1)
(test (fxfirst-bit-set (expt 2 17)) 17)
(test (fxbit-set? 15 0) #t)
(test (fxbit-set? 14 0) #f)
(test (fxbit-set? 14 3) #t)
(test (fxbit-set? 14 10) #f)
(test (fxbit-set? -1 10) #t)
(test (fxcopy-bit 0 0 1) 1)
(test (fxcopy-bit 0 1 1) 2)
(test (fxcopy-bit 0 4 1) 16)
(test (fxcopy-bit 0 4 0) 0)
(test (fxcopy-bit 31 4 0) 15)
(test (fxbit-field 30 1 3) 3)
(test (fxbit-field 30 1 4) 7)
(test (fxbit-field 30 1 5) 15)
(test (fxbit-field 30 1 6) 15)
(test (fxbit-field 30 0 3) 6)
(test (fxcopy-bit-field 0 0 3 30) 6)
(test (fxcopy-bit-field 7 0 3 30) 6)
(test (fxcopy-bit-field 15 0 3 30) 14)
(test (fxcopy-bit-field 0 2 5 30) 24)
(test (fxcopy-bit-field 1 2 5 30) 25)
(test (fxcopy-bit-field 7 2 5 30) 27)
(test (fxcopy-bit-field 15 2 5 30) 27)
(test (fxcopy-bit-field 0 2 5 120) 0)
(test (fxcopy-bit-field 1 2 5 120) 1)
(test (fxarithmetic-shift 1 1) 2)
(test (fxarithmetic-shift 1 -1) 0)
(test (fxarithmetic-shift 10 2) 40)
(test (fxarithmetic-shift 40 -2) 10)
(test (fxarithmetic-shift -1 1) -2)
(test (fxarithmetic-shift -1 -1) -1)
(test (fxarithmetic-shift -10 2) -40)
(test (fxarithmetic-shift -40 -2) -10)
(test/exn (fxarithmetic-shift (greatest-fixnum) 1) &implementation-restriction)
(test (fxarithmetic-shift-left 1 1) 2)
(test (fxarithmetic-shift-right 1 1) 0)
(test (fxarithmetic-shift-left 10 2) 40)
(test (fxarithmetic-shift-right 40 2) 10)
(test (fxarithmetic-shift-left -1 1) -2)
(test (fxarithmetic-shift-right -1 1) -1)
(test (fxarithmetic-shift-left -10 2) -40)
(test (fxarithmetic-shift-right -40 2) -10)
(test/exn (fxarithmetic-shift-left (greatest-fixnum) 1) &implementation-restriction)
(test (fxrotate-bit-field 10 0 2 0) 10)
(test (fxrotate-bit-field 10 0 2 1) 9)
(test (fxrotate-bit-field 10 2 4 0) 10)
(test (fxrotate-bit-field 10 2 4 1) 6)
(test (fxrotate-bit-field 10 1 4 2) 12)
(test (fxrotate-bit-field 10 1 4 1) 6)
(test (fxrotate-bit-field 10 2 4 1) 6)
;;
))
| true |
f24e391bef7adc402bc41e93701781c7d3422c56 | 1ed47579ca9136f3f2b25bda1610c834ab12a386 | /sec1/q1.17.scm | 7c2c7f1c4327248ee2b0b5c6b7c51e6d51930c71 | [] | no_license | thash/sicp | 7e89cf020e2bf5ca50543d10fa89eb1440f700fb | 3fc7a87d06eccbe4dcd634406e3b400d9405e9c4 | refs/heads/master | 2021-05-28T16:29:26.617617 | 2014-09-15T21:19:23 | 2014-09-15T21:19:23 | 3,238,591 | 0 | 1 | null | null | null | null | UTF-8 | Scheme | false | false | 443 | scm | q1.17.scm | (define (double n)
(* n 2))
(define (halve n)
(/ n 2))
(define (even? n)
(= (remainder n 2) 0))
(define (* a b)
(if (= b 0)
0
(+ a (* a (- b 1)))))
;; use pencile to understand it
(define (fast-x a b)
(cond ((= b 1) a)
((even? b) #?=(fast-x (double a) (halve b)))
(else #?=(+ a (fast-x a (- b 1))))
)
)
(print (fast-x 3 4))
(print (fast-x 3 5))
(print (fast-x 1 99))
(print (fast-x 4 99))
| false |
24b25fd4d731928218a4fad721e55d1c1929e292 | 20301174b79a1ad6a3566c852fcb077e90133caa | /scheme/texinfo/private/nodal-tree.scm | fc3c7e5dfb74447591bd59345390593b3ecb9e16 | [] | no_license | rotty/texinfo | 4e6d12ec9e3047d0858614fd5a6851c89e7b7f62 | 362a147831ba3ae8926eea6af33b2708d79e05dd | refs/heads/master | 2020-12-24T13:29:22.753453 | 2011-07-28T21:10:04 | 2011-07-28T21:16:36 | 211,721 | 5 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 4,216 | scm | nodal-tree.scm | ;; (texinfo nodal-tree) -- rendering stexinfo to a nodal tree
;; Copyright (C) 2003,2004 Andy Wingo <wingo at pobox dot com>
;; 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 3 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, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;;
;;This module exports a procedure to chunk a stexi doument into pieces,
;;delimited by sectioning commands (@code{@@chapter},
;;@code{@@appendixsec}, etc.). Note that the sectioning commands must be
;;preceded by a @code{@@node}, a condition that the output of
;;@code{(sxml texinfo)} respects.
;;
;;The output is a nodal tree (see (container nodal-tree)), with the
;;following fields defined for each node:
;;
;;; Code:
(define-module (texinfo nodal-tree)
#:use-module (container nodal-tree)
#:use-module (sxml simple)
#:use-module (texinfo) ;; texi-command-depth
#:export (stexi->nodal-tree))
(define (node? elt)
(and (pair? elt) (eq? (car elt) 'node)))
(define (chunking-section? elt max-depth)
(and (pair? elt) (texi-command-depth (car elt) max-depth)))
(define (append-child! parent kid)
(if parent
(node-set! parent 'children
(append! (node-ref parent 'children) (list kid)))))
(define (find-parent node)
(or (and=> (node-ref node 'parent) find-parent) node))
;; There has to be a more functional way to do this! Probably involves
;; building up from the leaves, instead of building down from the root.
;; Thankfully, the ugliness of this code isn't exported.
(define (stexi->nodal-tree stexi max-depth)
"Break @var{stexi} into a nodal tree. Only break until sectioning
identifiers of depth @var{max-depth}. The following fields are defined
for each node:
@table @code
@item name
The name of the section.
@item value
The content of the section, as @code{stexi}. The containing element is
@code{texinfo}.
@item parent
A reference to the parent node.
@item children
A list of subnodes, corresponding to the subsections of the current
section.
@end table"
(define (make-node* parent tree-title)
(let ((node (make-node
'name (sxml->string tree-title)
'value #f
'parent parent
'children '())))
(append-child! parent node)
node))
(or (eq? (car stexi) 'texinfo) (error "Invalid stexi"))
(let lp ((in stexi)
(val '())
(node (make-node* #f (cadr stexi)))
(parent #f)
(depth 0))
(cond
((null? in)
(node-set! node 'value (reverse! val))
(find-parent node))
((or (chunking-section? (car in) max-depth)
(and (node? (car in)) (pair? in) (pair? (cdr in))
(chunking-section? (cadr in) max-depth)))
(node-set! node 'value (reverse! val))
(let* ((node-statement (if (node? (car in)) (car in) #f))
(in (if node-statement (cdr in) in))
(new-depth (texi-command-depth (caar in) max-depth)))
(let new-parent ((parent node) (diff (- new-depth depth)))
(cond
((not parent) (error "invalid stexi"))
((positive? diff)
(or (eq? diff 1)
(error "can only descend by one depth level at a time"
(car in)))
(lp (cdr in)
`(,(car in)
,@(if node-statement (list node-statement) '())
(% (title ,(sxml->string (car in)))) texinfo)
(make-node* parent (car in)) parent new-depth))
(else
(new-parent (node-ref parent 'parent) (1+ diff)))))))
(else
(lp (cdr in) (cons (car in) val) node parent depth)))))
;;; arch-tag: aff19153-493d-4755-ba6f-22cc7fb43c60
| false |
280e17fdaac434676abdbcfaa4d20b21f73eb001 | ab05b79ab17619f548d9762a46199dc9eed6b3e9 | /sitelib/gl.scm | da0c5d851085fb002994802c6f17f000ef5629dd | [
"BSD-2-Clause"
] | permissive | lambdaconservatory/ypsilon | 2dce9ff4b5a50453937340bc757697b9b4839dee | f154436db2b3c0629623eb2a53154ad3c50270a1 | refs/heads/master | 2021-02-28T17:44:05.571304 | 2017-12-17T12:29:00 | 2020-03-08T12:57:52 | 245,719,032 | 1 | 0 | NOASSERTION | 2020-03-07T23:08:26 | 2020-03-07T23:08:25 | null | UTF-8 | Scheme | false | false | 32,757 | scm | gl.scm | #!nobacktrace
(library (gl)
(export GL_2D
GL_2_BYTES
GL_3D
GL_3D_COLOR
GL_3D_COLOR_TEXTURE
GL_3_BYTES
GL_4D_COLOR_TEXTURE
GL_4_BYTES
GL_ACCUM
GL_ACCUM_ALPHA_BITS
GL_ACCUM_BLUE_BITS
GL_ACCUM_BUFFER_BIT
GL_ACCUM_CLEAR_VALUE
GL_ACCUM_GREEN_BITS
GL_ACCUM_RED_BITS
GL_ACTIVE_TEXTURE
GL_ACTIVE_TEXTURE_ARB
GL_ADD
GL_ADD_SIGNED
GL_ALIASED_LINE_WIDTH_RANGE
GL_ALIASED_POINT_SIZE_RANGE
GL_ALL_ATTRIB_BITS
GL_ALL_CLIENT_ATTRIB_BITS
GL_ALPHA
GL_ALPHA12
GL_ALPHA16
GL_ALPHA4
GL_ALPHA8
GL_ALPHA_BIAS
GL_ALPHA_BITS
GL_ALPHA_SCALE
GL_ALPHA_TEST
GL_ALPHA_TEST_FUNC
GL_ALPHA_TEST_REF
GL_ALWAYS
GL_AMBIENT
GL_AMBIENT_AND_DIFFUSE
GL_AND
GL_AND_INVERTED
GL_AND_REVERSE
GL_ATTRIB_STACK_DEPTH
GL_AUTO_NORMAL
GL_AUX0
GL_AUX1
GL_AUX2
GL_AUX3
GL_AUX_BUFFERS
GL_BACK
GL_BACK_LEFT
GL_BACK_RIGHT
GL_BGR
GL_BGRA
GL_BITMAP
GL_BITMAP_TOKEN
GL_BLEND
GL_BLEND_COLOR
GL_BLEND_DST
GL_BLEND_EQUATION
GL_BLEND_SRC
GL_BLUE
GL_BLUE_BIAS
GL_BLUE_BITS
GL_BLUE_SCALE
GL_BYTE
GL_C3F_V3F
GL_C4F_N3F_V3F
GL_C4UB_V2F
GL_C4UB_V3F
GL_CCW
GL_CLAMP
GL_CLAMP_TO_BORDER
GL_CLAMP_TO_EDGE
GL_CLEAR
GL_CLIENT_ACTIVE_TEXTURE
GL_CLIENT_ACTIVE_TEXTURE_ARB
GL_CLIENT_ALL_ATTRIB_BITS
GL_CLIENT_ATTRIB_STACK_DEPTH
GL_CLIENT_PIXEL_STORE_BIT
GL_CLIENT_VERTEX_ARRAY_BIT
GL_CLIP_PLANE0
GL_CLIP_PLANE1
GL_CLIP_PLANE2
GL_CLIP_PLANE3
GL_CLIP_PLANE4
GL_CLIP_PLANE5
GL_COEFF
GL_COLOR
GL_COLOR_ARRAY
GL_COLOR_ARRAY_POINTER
GL_COLOR_ARRAY_SIZE
GL_COLOR_ARRAY_STRIDE
GL_COLOR_ARRAY_TYPE
GL_COLOR_BUFFER_BIT
GL_COLOR_CLEAR_VALUE
GL_COLOR_INDEX
GL_COLOR_INDEXES
GL_COLOR_LOGIC_OP
GL_COLOR_MATERIAL
GL_COLOR_MATERIAL_FACE
GL_COLOR_MATERIAL_PARAMETER
GL_COLOR_MATRIX
GL_COLOR_MATRIX_STACK_DEPTH
GL_COLOR_TABLE
GL_COLOR_TABLE_ALPHA_SIZE
GL_COLOR_TABLE_BIAS
GL_COLOR_TABLE_BLUE_SIZE
GL_COLOR_TABLE_FORMAT
GL_COLOR_TABLE_GREEN_SIZE
GL_COLOR_TABLE_INTENSITY_SIZE
GL_COLOR_TABLE_LUMINANCE_SIZE
GL_COLOR_TABLE_RED_SIZE
GL_COLOR_TABLE_SCALE
GL_COLOR_TABLE_WIDTH
GL_COLOR_WRITEMASK
GL_COMBINE
GL_COMBINE_ALPHA
GL_COMBINE_RGB
GL_COMPILE
GL_COMPILE_AND_EXECUTE
GL_COMPRESSED_ALPHA
GL_COMPRESSED_INTENSITY
GL_COMPRESSED_LUMINANCE
GL_COMPRESSED_LUMINANCE_ALPHA
GL_COMPRESSED_RGB
GL_COMPRESSED_RGBA
GL_COMPRESSED_TEXTURE_FORMATS
GL_CONSTANT
GL_CONSTANT_ALPHA
GL_CONSTANT_ATTENUATION
GL_CONSTANT_BORDER
GL_CONSTANT_COLOR
GL_CONVOLUTION_1D
GL_CONVOLUTION_2D
GL_CONVOLUTION_BORDER_COLOR
GL_CONVOLUTION_BORDER_MODE
GL_CONVOLUTION_FILTER_BIAS
GL_CONVOLUTION_FILTER_SCALE
GL_CONVOLUTION_FORMAT
GL_CONVOLUTION_HEIGHT
GL_CONVOLUTION_WIDTH
GL_COPY
GL_COPY_INVERTED
GL_COPY_PIXEL_TOKEN
GL_CULL_FACE
GL_CULL_FACE_MODE
GL_CURRENT_BIT
GL_CURRENT_COLOR
GL_CURRENT_INDEX
GL_CURRENT_NORMAL
GL_CURRENT_RASTER_COLOR
GL_CURRENT_RASTER_DISTANCE
GL_CURRENT_RASTER_INDEX
GL_CURRENT_RASTER_POSITION
GL_CURRENT_RASTER_POSITION_VALID
GL_CURRENT_RASTER_TEXTURE_COORDS
GL_CURRENT_TEXTURE_COORDS
GL_CW
GL_DECAL
GL_DECR
GL_DEPTH
GL_DEPTH_BIAS
GL_DEPTH_BITS
GL_DEPTH_BUFFER_BIT
GL_DEPTH_CLEAR_VALUE
GL_DEPTH_COMPONENT
GL_DEPTH_FUNC
GL_DEPTH_RANGE
GL_DEPTH_SCALE
GL_DEPTH_TEST
GL_DEPTH_WRITEMASK
GL_DIFFUSE
GL_DITHER
GL_DOMAIN
GL_DONT_CARE
GL_DOT3_RGB
GL_DOT3_RGBA
GL_DOUBLE
GL_DOUBLEBUFFER
GL_DRAW_BUFFER
GL_DRAW_PIXEL_TOKEN
GL_DST_ALPHA
GL_DST_COLOR
GL_EDGE_FLAG
GL_EDGE_FLAG_ARRAY
GL_EDGE_FLAG_ARRAY_POINTER
GL_EDGE_FLAG_ARRAY_STRIDE
GL_EMISSION
GL_ENABLE_BIT
GL_EQUAL
GL_EQUIV
GL_EVAL_BIT
GL_EXP
GL_EXP2
GL_EXTENSIONS
GL_EYE_LINEAR
GL_EYE_PLANE
GL_FALSE
GL_FASTEST
GL_FEEDBACK
GL_FEEDBACK_BUFFER_POINTER
GL_FEEDBACK_BUFFER_SIZE
GL_FEEDBACK_BUFFER_TYPE
GL_FILL
GL_FLAT
GL_FLOAT
GL_FOG
GL_FOG_BIT
GL_FOG_COLOR
GL_FOG_DENSITY
GL_FOG_END
GL_FOG_HINT
GL_FOG_INDEX
GL_FOG_MODE
GL_FOG_START
GL_FRONT
GL_FRONT_AND_BACK
GL_FRONT_FACE
GL_FRONT_LEFT
GL_FRONT_RIGHT
GL_FUNC_ADD
GL_FUNC_REVERSE_SUBTRACT
GL_FUNC_SUBTRACT
GL_GEQUAL
GL_GREATER
GL_GREEN
GL_GREEN_BIAS
GL_GREEN_BITS
GL_GREEN_SCALE
GL_HINT_BIT
GL_HISTOGRAM
GL_HISTOGRAM_ALPHA_SIZE
GL_HISTOGRAM_BLUE_SIZE
GL_HISTOGRAM_FORMAT
GL_HISTOGRAM_GREEN_SIZE
GL_HISTOGRAM_LUMINANCE_SIZE
GL_HISTOGRAM_RED_SIZE
GL_HISTOGRAM_SINK
GL_HISTOGRAM_WIDTH
GL_INCR
GL_INDEX_ARRAY
GL_INDEX_ARRAY_POINTER
GL_INDEX_ARRAY_STRIDE
GL_INDEX_ARRAY_TYPE
GL_INDEX_BITS
GL_INDEX_CLEAR_VALUE
GL_INDEX_LOGIC_OP
GL_INDEX_MODE
GL_INDEX_OFFSET
GL_INDEX_SHIFT
GL_INDEX_WRITEMASK
GL_INT
GL_INTENSITY
GL_INTENSITY12
GL_INTENSITY16
GL_INTENSITY4
GL_INTENSITY8
GL_INTERPOLATE
GL_INVALID_ENUM
GL_INVALID_OPERATION
GL_INVALID_VALUE
GL_INVERT
GL_KEEP
GL_LEFT
GL_LEQUAL
GL_LESS
GL_LIGHT0
GL_LIGHT1
GL_LIGHT2
GL_LIGHT3
GL_LIGHT4
GL_LIGHT5
GL_LIGHT6
GL_LIGHT7
GL_LIGHTING
GL_LIGHTING_BIT
GL_LIGHT_MODEL_AMBIENT
GL_LIGHT_MODEL_COLOR_CONTROL
GL_LIGHT_MODEL_LOCAL_VIEWER
GL_LIGHT_MODEL_TWO_SIDE
GL_LINE
GL_LINEAR
GL_LINEAR_ATTENUATION
GL_LINEAR_MIPMAP_LINEAR
GL_LINEAR_MIPMAP_NEAREST
GL_LINES
GL_LINE_BIT
GL_LINE_LOOP
GL_LINE_RESET_TOKEN
GL_LINE_SMOOTH
GL_LINE_SMOOTH_HINT
GL_LINE_STIPPLE
GL_LINE_STIPPLE_PATTERN
GL_LINE_STIPPLE_REPEAT
GL_LINE_STRIP
GL_LINE_TOKEN
GL_LINE_WIDTH
GL_LINE_WIDTH_GRANULARITY
GL_LINE_WIDTH_RANGE
GL_LIST_BASE
GL_LIST_BIT
GL_LIST_INDEX
GL_LIST_MODE
GL_LOAD
GL_LOGIC_OP
GL_LOGIC_OP_MODE
GL_LUMINANCE
GL_LUMINANCE12
GL_LUMINANCE12_ALPHA12
GL_LUMINANCE12_ALPHA4
GL_LUMINANCE16
GL_LUMINANCE16_ALPHA16
GL_LUMINANCE4
GL_LUMINANCE4_ALPHA4
GL_LUMINANCE6_ALPHA2
GL_LUMINANCE8
GL_LUMINANCE8_ALPHA8
GL_LUMINANCE_ALPHA
GL_MAP1_COLOR_4
GL_MAP1_GRID_DOMAIN
GL_MAP1_GRID_SEGMENTS
GL_MAP1_INDEX
GL_MAP1_NORMAL
GL_MAP1_TEXTURE_COORD_1
GL_MAP1_TEXTURE_COORD_2
GL_MAP1_TEXTURE_COORD_3
GL_MAP1_TEXTURE_COORD_4
GL_MAP1_VERTEX_3
GL_MAP1_VERTEX_4
GL_MAP2_COLOR_4
GL_MAP2_GRID_DOMAIN
GL_MAP2_GRID_SEGMENTS
GL_MAP2_INDEX
GL_MAP2_NORMAL
GL_MAP2_TEXTURE_COORD_1
GL_MAP2_TEXTURE_COORD_2
GL_MAP2_TEXTURE_COORD_3
GL_MAP2_TEXTURE_COORD_4
GL_MAP2_VERTEX_3
GL_MAP2_VERTEX_4
GL_MAP_COLOR
GL_MAP_STENCIL
GL_MATRIX_MODE
GL_MAX
GL_MAX_3D_TEXTURE_SIZE
GL_MAX_ATTRIB_STACK_DEPTH
GL_MAX_CLIENT_ATTRIB_STACK_DEPTH
GL_MAX_CLIP_PLANES
GL_MAX_COLOR_MATRIX_STACK_DEPTH
GL_MAX_CONVOLUTION_HEIGHT
GL_MAX_CONVOLUTION_WIDTH
GL_MAX_CUBE_MAP_TEXTURE_SIZE
GL_MAX_ELEMENTS_INDICES
GL_MAX_ELEMENTS_VERTICES
GL_MAX_EVAL_ORDER
GL_MAX_LIGHTS
GL_MAX_LIST_NESTING
GL_MAX_MODELVIEW_STACK_DEPTH
GL_MAX_NAME_STACK_DEPTH
GL_MAX_PIXEL_MAP_TABLE
GL_MAX_PROJECTION_STACK_DEPTH
GL_MAX_TEXTURE_SIZE
GL_MAX_TEXTURE_STACK_DEPTH
GL_MAX_TEXTURE_UNITS
GL_MAX_TEXTURE_UNITS_ARB
GL_MAX_VIEWPORT_DIMS
GL_MIN
GL_MINMAX
GL_MINMAX_FORMAT
GL_MINMAX_SINK
GL_MODELVIEW
GL_MODELVIEW_MATRIX
GL_MODELVIEW_STACK_DEPTH
GL_MODULATE
GL_MULT
GL_MULTISAMPLE
GL_MULTISAMPLE_BIT
GL_N3F_V3F
GL_NAME_STACK_DEPTH
GL_NAND
GL_NEAREST
GL_NEAREST_MIPMAP_LINEAR
GL_NEAREST_MIPMAP_NEAREST
GL_NEVER
GL_NICEST
GL_NONE
GL_NOOP
GL_NOR
GL_NORMALIZE
GL_NORMAL_ARRAY
GL_NORMAL_ARRAY_POINTER
GL_NORMAL_ARRAY_STRIDE
GL_NORMAL_ARRAY_TYPE
GL_NORMAL_MAP
GL_NOTEQUAL
GL_NO_ERROR
GL_NUM_COMPRESSED_TEXTURE_FORMATS
GL_OBJECT_LINEAR
GL_OBJECT_PLANE
GL_ONE
GL_ONE_MINUS_CONSTANT_ALPHA
GL_ONE_MINUS_CONSTANT_COLOR
GL_ONE_MINUS_DST_ALPHA
GL_ONE_MINUS_DST_COLOR
GL_ONE_MINUS_SRC_ALPHA
GL_ONE_MINUS_SRC_COLOR
GL_OPERAND0_ALPHA
GL_OPERAND0_RGB
GL_OPERAND1_ALPHA
GL_OPERAND1_RGB
GL_OPERAND2_ALPHA
GL_OPERAND2_RGB
GL_OR
GL_ORDER
GL_OR_INVERTED
GL_OR_REVERSE
GL_OUT_OF_MEMORY
GL_PACK_ALIGNMENT
GL_PACK_IMAGE_HEIGHT
GL_PACK_LSB_FIRST
GL_PACK_ROW_LENGTH
GL_PACK_SKIP_IMAGES
GL_PACK_SKIP_PIXELS
GL_PACK_SKIP_ROWS
GL_PACK_SWAP_BYTES
GL_PASS_THROUGH_TOKEN
GL_PERSPECTIVE_CORRECTION_HINT
GL_PIXEL_MAP_A_TO_A
GL_PIXEL_MAP_A_TO_A_SIZE
GL_PIXEL_MAP_B_TO_B
GL_PIXEL_MAP_B_TO_B_SIZE
GL_PIXEL_MAP_G_TO_G
GL_PIXEL_MAP_G_TO_G_SIZE
GL_PIXEL_MAP_I_TO_A
GL_PIXEL_MAP_I_TO_A_SIZE
GL_PIXEL_MAP_I_TO_B
GL_PIXEL_MAP_I_TO_B_SIZE
GL_PIXEL_MAP_I_TO_G
GL_PIXEL_MAP_I_TO_G_SIZE
GL_PIXEL_MAP_I_TO_I
GL_PIXEL_MAP_I_TO_I_SIZE
GL_PIXEL_MAP_I_TO_R
GL_PIXEL_MAP_I_TO_R_SIZE
GL_PIXEL_MAP_R_TO_R
GL_PIXEL_MAP_R_TO_R_SIZE
GL_PIXEL_MAP_S_TO_S
GL_PIXEL_MAP_S_TO_S_SIZE
GL_PIXEL_MODE_BIT
GL_POINT
GL_POINTS
GL_POINT_BIT
GL_POINT_SIZE
GL_POINT_SIZE_GRANULARITY
GL_POINT_SIZE_RANGE
GL_POINT_SMOOTH
GL_POINT_SMOOTH_HINT
GL_POINT_TOKEN
GL_POLYGON
GL_POLYGON_BIT
GL_POLYGON_MODE
GL_POLYGON_OFFSET_FACTOR
GL_POLYGON_OFFSET_FILL
GL_POLYGON_OFFSET_LINE
GL_POLYGON_OFFSET_POINT
GL_POLYGON_OFFSET_UNITS
GL_POLYGON_SMOOTH
GL_POLYGON_SMOOTH_HINT
GL_POLYGON_STIPPLE
GL_POLYGON_STIPPLE_BIT
GL_POLYGON_TOKEN
GL_POSITION
GL_POST_COLOR_MATRIX_ALPHA_BIAS
GL_POST_COLOR_MATRIX_ALPHA_SCALE
GL_POST_COLOR_MATRIX_BLUE_BIAS
GL_POST_COLOR_MATRIX_BLUE_SCALE
GL_POST_COLOR_MATRIX_COLOR_TABLE
GL_POST_COLOR_MATRIX_GREEN_BIAS
GL_POST_COLOR_MATRIX_GREEN_SCALE
GL_POST_COLOR_MATRIX_RED_BIAS
GL_POST_COLOR_MATRIX_RED_SCALE
GL_POST_CONVOLUTION_ALPHA_BIAS
GL_POST_CONVOLUTION_ALPHA_SCALE
GL_POST_CONVOLUTION_BLUE_BIAS
GL_POST_CONVOLUTION_BLUE_SCALE
GL_POST_CONVOLUTION_COLOR_TABLE
GL_POST_CONVOLUTION_GREEN_BIAS
GL_POST_CONVOLUTION_GREEN_SCALE
GL_POST_CONVOLUTION_RED_BIAS
GL_POST_CONVOLUTION_RED_SCALE
GL_PREVIOUS
GL_PRIMARY_COLOR
GL_PROJECTION
GL_PROJECTION_MATRIX
GL_PROJECTION_STACK_DEPTH
GL_PROXY_COLOR_TABLE
GL_PROXY_HISTOGRAM
GL_PROXY_POST_COLOR_MATRIX_COLOR_TABLE
GL_PROXY_POST_CONVOLUTION_COLOR_TABLE
GL_PROXY_TEXTURE_1D
GL_PROXY_TEXTURE_2D
GL_PROXY_TEXTURE_3D
GL_PROXY_TEXTURE_CUBE_MAP
GL_Q
GL_QUADRATIC_ATTENUATION
GL_QUADS
GL_QUAD_STRIP
GL_R
GL_R3_G3_B2
GL_READ_BUFFER
GL_RED
GL_REDUCE
GL_RED_BIAS
GL_RED_BITS
GL_RED_SCALE
GL_REFLECTION_MAP
GL_RENDER
GL_RENDERER
GL_RENDER_MODE
GL_REPEAT
GL_REPLACE
GL_REPLICATE_BORDER
GL_RESCALE_NORMAL
GL_RETURN
GL_RGB
GL_RGB10
GL_RGB10_A2
GL_RGB12
GL_RGB16
GL_RGB4
GL_RGB5
GL_RGB5_A1
GL_RGB8
GL_RGBA
GL_RGBA12
GL_RGBA16
GL_RGBA2
GL_RGBA4
GL_RGBA8
GL_RGBA_MODE
GL_RGB_SCALE
GL_RIGHT
GL_S
GL_SAMPLES
GL_SAMPLE_ALPHA_TO_COVERAGE
GL_SAMPLE_ALPHA_TO_ONE
GL_SAMPLE_BUFFERS
GL_SAMPLE_COVERAGE
GL_SAMPLE_COVERAGE_INVERT
GL_SAMPLE_COVERAGE_VALUE
GL_SCISSOR_BIT
GL_SCISSOR_BOX
GL_SCISSOR_TEST
GL_SELECT
GL_SELECTION_BUFFER_POINTER
GL_SELECTION_BUFFER_SIZE
GL_SEPARABLE_2D
GL_SEPARATE_SPECULAR_COLOR
GL_SET
GL_SHADE_MODEL
GL_SHININESS
GL_SHORT
GL_SINGLE_COLOR
GL_SMOOTH
GL_SMOOTH_LINE_WIDTH_GRANULARITY
GL_SMOOTH_LINE_WIDTH_RANGE
GL_SMOOTH_POINT_SIZE_GRANULARITY
GL_SMOOTH_POINT_SIZE_RANGE
GL_SOURCE0_ALPHA
GL_SOURCE0_RGB
GL_SOURCE1_ALPHA
GL_SOURCE1_RGB
GL_SOURCE2_ALPHA
GL_SOURCE2_RGB
GL_SPECULAR
GL_SPHERE_MAP
GL_SPOT_CUTOFF
GL_SPOT_DIRECTION
GL_SPOT_EXPONENT
GL_SRC_ALPHA
GL_SRC_ALPHA_SATURATE
GL_SRC_COLOR
GL_STACK_OVERFLOW
GL_STACK_UNDERFLOW
GL_STENCIL
GL_STENCIL_BITS
GL_STENCIL_BUFFER_BIT
GL_STENCIL_CLEAR_VALUE
GL_STENCIL_FAIL
GL_STENCIL_FUNC
GL_STENCIL_INDEX
GL_STENCIL_PASS_DEPTH_FAIL
GL_STENCIL_PASS_DEPTH_PASS
GL_STENCIL_REF
GL_STENCIL_TEST
GL_STENCIL_VALUE_MASK
GL_STENCIL_WRITEMASK
GL_STEREO
GL_SUBPIXEL_BITS
GL_SUBTRACT
GL_T
GL_T2F_C3F_V3F
GL_T2F_C4F_N3F_V3F
GL_T2F_C4UB_V3F
GL_T2F_N3F_V3F
GL_T2F_V3F
GL_T4F_C4F_N3F_V4F
GL_T4F_V4F
GL_TABLE_TOO_LARGE
GL_TEXTURE
GL_TEXTURE0
GL_TEXTURE0_ARB
GL_TEXTURE1
GL_TEXTURE10
GL_TEXTURE10_ARB
GL_TEXTURE11
GL_TEXTURE11_ARB
GL_TEXTURE12
GL_TEXTURE12_ARB
GL_TEXTURE13
GL_TEXTURE13_ARB
GL_TEXTURE14
GL_TEXTURE14_ARB
GL_TEXTURE15
GL_TEXTURE15_ARB
GL_TEXTURE16
GL_TEXTURE16_ARB
GL_TEXTURE17
GL_TEXTURE17_ARB
GL_TEXTURE18
GL_TEXTURE18_ARB
GL_TEXTURE19
GL_TEXTURE19_ARB
GL_TEXTURE1_ARB
GL_TEXTURE2
GL_TEXTURE20
GL_TEXTURE20_ARB
GL_TEXTURE21
GL_TEXTURE21_ARB
GL_TEXTURE22
GL_TEXTURE22_ARB
GL_TEXTURE23
GL_TEXTURE23_ARB
GL_TEXTURE24
GL_TEXTURE24_ARB
GL_TEXTURE25
GL_TEXTURE25_ARB
GL_TEXTURE26
GL_TEXTURE26_ARB
GL_TEXTURE27
GL_TEXTURE27_ARB
GL_TEXTURE28
GL_TEXTURE28_ARB
GL_TEXTURE29
GL_TEXTURE29_ARB
GL_TEXTURE2_ARB
GL_TEXTURE3
GL_TEXTURE30
GL_TEXTURE30_ARB
GL_TEXTURE31
GL_TEXTURE31_ARB
GL_TEXTURE3_ARB
GL_TEXTURE4
GL_TEXTURE4_ARB
GL_TEXTURE5
GL_TEXTURE5_ARB
GL_TEXTURE6
GL_TEXTURE6_ARB
GL_TEXTURE7
GL_TEXTURE7_ARB
GL_TEXTURE8
GL_TEXTURE8_ARB
GL_TEXTURE9
GL_TEXTURE9_ARB
GL_TEXTURE_1D
GL_TEXTURE_2D
GL_TEXTURE_3D
GL_TEXTURE_ALPHA_SIZE
GL_TEXTURE_BASE_LEVEL
GL_TEXTURE_BINDING_1D
GL_TEXTURE_BINDING_2D
GL_TEXTURE_BINDING_3D
GL_TEXTURE_BINDING_CUBE_MAP
GL_TEXTURE_BIT
GL_TEXTURE_BLUE_SIZE
GL_TEXTURE_BORDER
GL_TEXTURE_BORDER_COLOR
GL_TEXTURE_COMPONENTS
GL_TEXTURE_COMPRESSED
GL_TEXTURE_COMPRESSED_IMAGE_SIZE
GL_TEXTURE_COMPRESSION_HINT
GL_TEXTURE_COORD_ARRAY
GL_TEXTURE_COORD_ARRAY_POINTER
GL_TEXTURE_COORD_ARRAY_SIZE
GL_TEXTURE_COORD_ARRAY_STRIDE
GL_TEXTURE_COORD_ARRAY_TYPE
GL_TEXTURE_CUBE_MAP
GL_TEXTURE_CUBE_MAP_NEGATIVE_X
GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
GL_TEXTURE_CUBE_MAP_POSITIVE_X
GL_TEXTURE_CUBE_MAP_POSITIVE_Y
GL_TEXTURE_CUBE_MAP_POSITIVE_Z
GL_TEXTURE_DEPTH
GL_TEXTURE_ENV
GL_TEXTURE_ENV_COLOR
GL_TEXTURE_ENV_MODE
GL_TEXTURE_GEN_MODE
GL_TEXTURE_GEN_Q
GL_TEXTURE_GEN_R
GL_TEXTURE_GEN_S
GL_TEXTURE_GEN_T
GL_TEXTURE_GREEN_SIZE
GL_TEXTURE_HEIGHT
GL_TEXTURE_INTENSITY_SIZE
GL_TEXTURE_INTERNAL_FORMAT
GL_TEXTURE_LUMINANCE_SIZE
GL_TEXTURE_MAG_FILTER
GL_TEXTURE_MATRIX
GL_TEXTURE_MAX_LEVEL
GL_TEXTURE_MAX_LOD
GL_TEXTURE_MIN_FILTER
GL_TEXTURE_MIN_LOD
GL_TEXTURE_PRIORITY
GL_TEXTURE_RED_SIZE
GL_TEXTURE_RESIDENT
GL_TEXTURE_STACK_DEPTH
GL_TEXTURE_WIDTH
GL_TEXTURE_WRAP_R
GL_TEXTURE_WRAP_S
GL_TEXTURE_WRAP_T
GL_TRANSFORM_BIT
GL_TRANSPOSE_COLOR_MATRIX
GL_TRANSPOSE_MODELVIEW_MATRIX
GL_TRANSPOSE_PROJECTION_MATRIX
GL_TRANSPOSE_TEXTURE_MATRIX
GL_TRIANGLES
GL_TRIANGLE_FAN
GL_TRIANGLE_STRIP
GL_TRUE
GL_UNPACK_ALIGNMENT
GL_UNPACK_IMAGE_HEIGHT
GL_UNPACK_LSB_FIRST
GL_UNPACK_ROW_LENGTH
GL_UNPACK_SKIP_IMAGES
GL_UNPACK_SKIP_PIXELS
GL_UNPACK_SKIP_ROWS
GL_UNPACK_SWAP_BYTES
GL_UNSIGNED_BYTE
GL_UNSIGNED_BYTE_2_3_3_REV
GL_UNSIGNED_BYTE_3_3_2
GL_UNSIGNED_INT
GL_UNSIGNED_INT_10_10_10_2
GL_UNSIGNED_INT_2_10_10_10_REV
GL_UNSIGNED_INT_8_8_8_8
GL_UNSIGNED_INT_8_8_8_8_REV
GL_UNSIGNED_SHORT
GL_UNSIGNED_SHORT_1_5_5_5_REV
GL_UNSIGNED_SHORT_4_4_4_4
GL_UNSIGNED_SHORT_4_4_4_4_REV
GL_UNSIGNED_SHORT_5_5_5_1
GL_UNSIGNED_SHORT_5_6_5
GL_UNSIGNED_SHORT_5_6_5_REV
GL_V2F
GL_V3F
GL_VENDOR
GL_VERSION
GL_VERTEX_ARRAY
GL_VERTEX_ARRAY_POINTER
GL_VERTEX_ARRAY_SIZE
GL_VERTEX_ARRAY_STRIDE
GL_VERTEX_ARRAY_TYPE
GL_VIEWPORT
GL_VIEWPORT_BIT
GL_XOR
GL_ZERO
GL_ZOOM_X
GL_ZOOM_Y
glAccum
glActiveTexture
glActiveTextureARB
glAlphaFunc
glAreTexturesResident
glArrayElement
glBegin
glBindTexture
glBitmap
glBlendColor
glBlendEquation
glBlendFunc
glCallList
glCallLists
glClear
glClearAccum
glClearColor
glClearDepth
glClearIndex
glClearStencil
glClientActiveTexture
glClientActiveTextureARB
glClipPlane
glColor3b
glColor3bv
glColor3d
glColor3dv
glColor3f
glColor3fv
glColor3i
glColor3iv
glColor3s
glColor3sv
glColor3ub
glColor3ubv
glColor3ui
glColor3uiv
glColor3us
glColor3usv
glColor4b
glColor4bv
glColor4d
glColor4dv
glColor4f
glColor4fv
glColor4i
glColor4iv
glColor4s
glColor4sv
glColor4ub
glColor4ubv
glColor4ui
glColor4uiv
glColor4us
glColor4usv
glColorMask
glColorMaterial
glColorPointer
glColorSubTable
glColorTable
glColorTableParameterfv
glColorTableParameteriv
glCompressedTexImage1D
glCompressedTexImage2D
glCompressedTexImage3D
glCompressedTexSubImage1D
glCompressedTexSubImage2D
glCompressedTexSubImage3D
glConvolutionFilter1D
glConvolutionFilter2D
glConvolutionParameterf
glConvolutionParameterfv
glConvolutionParameteri
glConvolutionParameteriv
glCopyColorSubTable
glCopyColorTable
glCopyConvolutionFilter1D
glCopyConvolutionFilter2D
glCopyPixels
glCopyTexImage1D
glCopyTexImage2D
glCopyTexSubImage1D
glCopyTexSubImage2D
glCopyTexSubImage3D
glCullFace
glDeleteLists
glDeleteTextures
glDepthFunc
glDepthMask
glDepthRange
glDisable
glDisableClientState
glDrawArrays
glDrawBuffer
glDrawElements
glDrawPixels
glDrawRangeElements
glEdgeFlag
glEdgeFlagPointer
glEdgeFlagv
glEnable
glEnableClientState
glEnd
glEndList
glEvalCoord1d
glEvalCoord1dv
glEvalCoord1f
glEvalCoord1fv
glEvalCoord2d
glEvalCoord2dv
glEvalCoord2f
glEvalCoord2fv
glEvalMesh1
glEvalMesh2
glEvalPoint1
glEvalPoint2
glFeedbackBuffer
glFinish
glFlush
glFogf
glFogfv
glFogi
glFogiv
glFrontFace
glFrustum
glGenLists
glGenTextures
glGetBooleanv
glGetClipPlane
glGetColorTable
glGetColorTableParameterfv
glGetColorTableParameteriv
glGetCompressedTexImage
glGetConvolutionFilter
glGetConvolutionParameterfv
glGetConvolutionParameteriv
glGetDoublev
glGetError
glGetFloatv
glGetHistogram
glGetHistogramParameterfv
glGetHistogramParameteriv
glGetIntegerv
glGetLightfv
glGetLightiv
glGetMapdv
glGetMapfv
glGetMapiv
glGetMaterialfv
glGetMaterialiv
glGetMinmax
glGetMinmaxParameterfv
glGetMinmaxParameteriv
glGetPixelMapfv
glGetPixelMapuiv
glGetPixelMapusv
glGetPointerv
glGetPolygonStipple
glGetSeparableFilter
glGetString
glGetTexEnvfv
glGetTexEnviv
glGetTexGendv
glGetTexGenfv
glGetTexGeniv
glGetTexImage
glGetTexLevelParameterfv
glGetTexLevelParameteriv
glGetTexParameterfv
glGetTexParameteriv
glHint
glHistogram
glIndexMask
glIndexPointer
glIndexd
glIndexdv
glIndexf
glIndexfv
glIndexi
glIndexiv
glIndexs
glIndexsv
glIndexub
glIndexubv
glInitNames
glInterleavedArrays
glIsEnabled
glIsList
glIsTexture
glLightModelf
glLightModelfv
glLightModeli
glLightModeliv
glLightf
glLightfv
glLighti
glLightiv
glLineStipple
glLineWidth
glListBase
glLoadIdentity
glLoadMatrixd
glLoadMatrixf
glLoadName
glLoadTransposeMatrixd
glLoadTransposeMatrixf
glLogicOp
glMap1d
glMap1f
glMap2d
glMap2f
glMapGrid1d
glMapGrid1f
glMapGrid2d
glMapGrid2f
glMaterialf
glMaterialfv
glMateriali
glMaterialiv
glMatrixMode
glMinmax
glMultMatrixd
glMultMatrixf
glMultTransposeMatrixd
glMultTransposeMatrixf
glMultiTexCoord1d
glMultiTexCoord1dARB
glMultiTexCoord1dv
glMultiTexCoord1dvARB
glMultiTexCoord1f
glMultiTexCoord1fARB
glMultiTexCoord1fv
glMultiTexCoord1fvARB
glMultiTexCoord1i
glMultiTexCoord1iARB
glMultiTexCoord1iv
glMultiTexCoord1ivARB
glMultiTexCoord1s
glMultiTexCoord1sARB
glMultiTexCoord1sv
glMultiTexCoord1svARB
glMultiTexCoord2d
glMultiTexCoord2dARB
glMultiTexCoord2dv
glMultiTexCoord2dvARB
glMultiTexCoord2f
glMultiTexCoord2fARB
glMultiTexCoord2fv
glMultiTexCoord2fvARB
glMultiTexCoord2i
glMultiTexCoord2iARB
glMultiTexCoord2iv
glMultiTexCoord2ivARB
glMultiTexCoord2s
glMultiTexCoord2sARB
glMultiTexCoord2sv
glMultiTexCoord2svARB
glMultiTexCoord3d
glMultiTexCoord3dARB
glMultiTexCoord3dv
glMultiTexCoord3dvARB
glMultiTexCoord3f
glMultiTexCoord3fARB
glMultiTexCoord3fv
glMultiTexCoord3fvARB
glMultiTexCoord3i
glMultiTexCoord3iARB
glMultiTexCoord3iv
glMultiTexCoord3ivARB
glMultiTexCoord3s
glMultiTexCoord3sARB
glMultiTexCoord3sv
glMultiTexCoord3svARB
glMultiTexCoord4d
glMultiTexCoord4dARB
glMultiTexCoord4dv
glMultiTexCoord4dvARB
glMultiTexCoord4f
glMultiTexCoord4fARB
glMultiTexCoord4fv
glMultiTexCoord4fvARB
glMultiTexCoord4i
glMultiTexCoord4iARB
glMultiTexCoord4iv
glMultiTexCoord4ivARB
glMultiTexCoord4s
glMultiTexCoord4sARB
glMultiTexCoord4sv
glMultiTexCoord4svARB
glNewList
glNormal3b
glNormal3bv
glNormal3d
glNormal3dv
glNormal3f
glNormal3fv
glNormal3i
glNormal3iv
glNormal3s
glNormal3sv
glNormalPointer
glOrtho
glPassThrough
glPixelMapfv
glPixelMapuiv
glPixelMapusv
glPixelStoref
glPixelStorei
glPixelTransferf
glPixelTransferi
glPixelZoom
glPointSize
glPolygonMode
glPolygonOffset
glPolygonStipple
glPopAttrib
glPopClientAttrib
glPopMatrix
glPopName
glPrioritizeTextures
glPushAttrib
glPushClientAttrib
glPushMatrix
glPushName
glRasterPos2d
glRasterPos2dv
glRasterPos2f
glRasterPos2fv
glRasterPos2i
glRasterPos2iv
glRasterPos2s
glRasterPos2sv
glRasterPos3d
glRasterPos3dv
glRasterPos3f
glRasterPos3fv
glRasterPos3i
glRasterPos3iv
glRasterPos3s
glRasterPos3sv
glRasterPos4d
glRasterPos4dv
glRasterPos4f
glRasterPos4fv
glRasterPos4i
glRasterPos4iv
glRasterPos4s
glRasterPos4sv
glReadBuffer
glReadPixels
glRectd
glRectdv
glRectf
glRectfv
glRecti
glRectiv
glRects
glRectsv
glRenderMode
glResetHistogram
glResetMinmax
glRotated
glRotatef
glSampleCoverage
glScaled
glScalef
glScissor
glSelectBuffer
glSeparableFilter2D
glShadeModel
glStencilFunc
glStencilMask
glStencilOp
glTexCoord1d
glTexCoord1dv
glTexCoord1f
glTexCoord1fv
glTexCoord1i
glTexCoord1iv
glTexCoord1s
glTexCoord1sv
glTexCoord2d
glTexCoord2dv
glTexCoord2f
glTexCoord2fv
glTexCoord2i
glTexCoord2iv
glTexCoord2s
glTexCoord2sv
glTexCoord3d
glTexCoord3dv
glTexCoord3f
glTexCoord3fv
glTexCoord3i
glTexCoord3iv
glTexCoord3s
glTexCoord3sv
glTexCoord4d
glTexCoord4dv
glTexCoord4f
glTexCoord4fv
glTexCoord4i
glTexCoord4iv
glTexCoord4s
glTexCoord4sv
glTexCoordPointer
glTexEnvf
glTexEnvfv
glTexEnvi
glTexEnviv
glTexGend
glTexGendv
glTexGenf
glTexGenfv
glTexGeni
glTexGeniv
glTexImage1D
glTexImage2D
glTexImage3D
glTexParameterf
glTexParameterfv
glTexParameteri
glTexParameteriv
glTexSubImage1D
glTexSubImage2D
glTexSubImage3D
glTranslated
glTranslatef
glVertex2d
glVertex2dv
glVertex2f
glVertex2fv
glVertex2i
glVertex2iv
glVertex2s
glVertex2sv
glVertex3d
glVertex3dv
glVertex3f
glVertex3fv
glVertex3i
glVertex3iv
glVertex3s
glVertex3sv
glVertex4d
glVertex4dv
glVertex4f
glVertex4fv
glVertex4i
glVertex4iv
glVertex4s
glVertex4sv
glVertexPointer
glViewport)
(import (ypsilon gl)))
| false |
c6e9b017424e9eedf175c9aa85a2ced643da36ec | 8f9b45f0ad99a668cf9b1e72830fe640e1105cc0 | /piclib/util/version.scm | 2351112dff84d1d1244685d0db9f6e6de508f11a | [] | no_license | picrin-scheme/sulfuric | 56bbb5a01056c232b6b96e93e0e63af866088e75 | 7318dddfdf26b72a2c810246b8511e7d1ff9b70d | refs/heads/master | 2016-09-05T16:46:22.849594 | 2015-01-20T17:28:46 | 2015-01-20T17:28:46 | 29,534,762 | 3 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 2,249 | scm | version.scm | (define-library (sulfuric util version)
(import (scheme base)
(scheme case-lambda)
(sulfuric util))
(begin
(define-record-type-with-accessors <version>
(make-version% major minor patch)
version?
major
minor
patch)
(define make-version
(case-lambda
((major)
(make-version% major 0 0))
((major minor)
(make-version% major minor 0))
((major minor patch)
(make-version% major minor patch))))
(define (string->version str)
(apply make-version (map string->number (string-split #\. str))))
(define (version->list v)
(list (major v) (minor v) (patch v)))
(define (version->string v)
(string-join "." (map number->string (version->list v))))
(define (make-version-comparator op include-equal?)
(lambda (v1 v2)
(let loop ((v1 (version->list v1))
(v2 (version->list v2)))
(if (null? v1)
include-equal?
(cond
((= (car v1) (car v2))
(loop (cdr v1) (cdr v2)))
((op (car v1) (car v2)) #t))))))
(define (/= x y) (not (= x y)))
(define (id x) x)
(define (version= v1 v2)
(always? id (map = (version->list v1) (version->list v2))))
(define version/=
(make-version-comparator /= #f))
(define version>
(make-version-comparator > #f))
(define version<
(make-version-comparator < #f))
(define version<=
(make-version-comparator <= #t))
(define version>=
(make-version-comparator >= #t))
(define (version~ v1 v2)
(and (= (major v1) (major v2))
(= (minor v1) (minor v2))))
(define (version<~ v1 v2)
(let ((upper (make-version (major v1) (+ (minor v1) 1))))
(and (version<= v1 v2)
(version< v2 upper))))
(define (version>~ v1 v2)
(let ((upper (make-version (major v2) (+ (minor v2) 1))))
(and (version>= v1 v2)
(version> upper v1)))))
(export
make-version
string->version
version->list
version->string
version=
version/=
version~
version<
version<=
version<~
version>
version>=
version>~))
| false |
5b4e099f715e17665fe63cb6bbfdc85827172336 | 8a0660bd8d588f94aa429050bb8d32c9cd4290d5 | /lib/core/inline.scm | 96d5cae9eaf14b70579e16386fa27e989890d8ba | [
"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 | 2,097 | scm | inline.scm | ;; part of Sagittarius Scheme
(library (core inline)
(export define-inliner
;; not export this for now.
;;define-raw-inliner
)
(import (core)
(core errors)
(core base)
(core syntax)
(sagittarius)
(sagittarius compiler)
(sagittarius compiler procedure)
(sagittarius compiler util)
(sagittarius vm))
;; trick to get pass1 from compiler
(define pass1 (let ((lib (find-library '(sagittarius compiler) #f)))
(gloc-ref (find-binding lib 'pass1 #f))))
(define-syntax define-raw-inliner
(lambda (x)
(syntax-case x ()
((k name library inliner)
(with-syntax ((debug-name (datum->syntax #'k
(string->symbol (format "inliner/~a"
(datum name))))))
#'(let* ((proc (find-procedure 'name 'library))
(orig (procedure-inliner proc))
(debug-name (lambda (form p1env)
(define (const-value expr)
(let ((iform (pass1 expr p1env)))
;; $CONST = #($CONST value)
(if (eqv? (vector-ref iform 0) $CONST)
(vector-ref iform 1)
(undefined))))
(let ((form2 (inliner form const-value)))
(if (undefined? form2)
(if orig
(orig form p1env)
;; return undefined so that compiler
;; just compiles to $call
form2)
;; must return iform
(pass1 form2 p1env))))))
(when (integer? orig)
(error 'name "Can't overwrite insn inliner"))
(procedure-inliner-set! proc debug-name)))))))
(define-syntax define-inliner
(lambda (x)
(define (parse patterns acc)
(syntax-case patterns ()
(((p f t) rest ...)
(parse (cdr patterns) (cons (list #'p #'f #'t) acc)))
(((p t) rest ...)
(parse (cdr patterns) (cons (list #'p #'#t #'t) acc)))
(() (reverse! acc))))
(syntax-case x ()
((_ name lib pattern* ...)
(with-syntax ((((pattern fender template) ...)
(parse #'(pattern* ...) '())))
#'(define-raw-inliner name lib
(lambda (form const-value)
(syntax-case form ()
(pattern fender (syntax template)) ...
(_ (undefined))))))))))
) | true |
8598854bf591e91dfa393e9982b3ac71f85445b6 | d6121a780f97ae1f3afb265812e9296d23574f78 | /primenocturne/scheme/C-02.scm | a8273372d79ddc0d4749ba7eebcb8136e336db0e | [] | no_license | phasetr/mathcodes | 6ac2efd6bffe719c1edf5eabc4b14487f3ad600a | e97261641d203ff3cca54742fd4a77390940eddb | refs/heads/master | 2022-10-19T13:24:26.473230 | 2022-10-05T12:05:26 | 2022-10-05T12:05:26 | 65,594,078 | 13 | 0 | null | 2021-06-02T12:01:59 | 2016-08-13T02:00:46 | Jupyter Notebook | UTF-8 | Scheme | false | false | 2,671 | scm | C-02.scm | "P.486"
"C.2 ループ不変表明"
(define plus (lambda (x y)
(if (zero? y) x
(+ 1 (plus x (- y 1))))))
(define mult (lambda (x y)
(if (zero? y) 0
(+ x (mult x (- y 1))))))
(define pows (lambda (x y)
(if (zero? y) 1
(* x (pows x (- y 1))))))
(plus 1 2)
(mult 1 2)
(mult 2 3)
(pows 2 3)
"C.2.1 末尾再帰"
"P.487"
"plus の場合"
(define plus-iter
(lambda (x y p)
(if (zero? y)
(+ x p)
(plus-iter x (- y 1) (+ p 1)))))
(plus-iter 2 3 0)
"P.488"
(define plus-tailrec
(lambda (x y)
(define plus-iter
(lambda (x y p)
(if (zero? y)
(+ x p)
(plus-iter x (- y 1) (+ p 1)))))
(plus-iter x y 0)))
"P.489"
"mult の場合"
(define mult-tailrec
(lambda (x y)
(define mult-iter
(lambda (x y p)
(if (zero? y)
p
(mult-iter x (- y 1) (+ x p)))))
(mult-iter x y 0)))
(mult-tailrec 0 1)
(mult-tailrec 3 4)
"pows の場合"
"P.490"
(define pows-tailrec
(lambda (x y)
(define pows-iter
(lambda (x y p)
(if (zero? y)
p
(pows-iter x (- y 1) (* x p)))))
(pows-iter x y 1)))
(pows-tailrec 1 0)
(pows-tailrec 2 3)
"C.2.2 逐次平方による冪乗計算"
"P.491"
(define sq**
(lambda (b n)
(define sq (lambda (x) (* x x)))
(cond ((zero? n) 1)
((even? n) (sq (sq** b (/ n 2))))
((odd? n) (* b (sq** b (- n 1)))))))
(sq** 2 2)
(sq** 2 4)
(sq** 3 43)
(sq** 82 43)
"末尾再帰への変換"
"P.493"
(define sq**-tailrec
(lambda (b n)
(define sq**-iter
(lambda (b n p)
(cond ((zero? n) p)
((even? n) (sq**-iter (* b b) (/ n 2) p))
((odd? n) (sq**-iter b (- n 1) (* b p))))))
(sq**-iter b n 1)))
(sq**-tailrec 2 2)
(sq**-tailrec 2 4)
(sq**-tailrec 3 43)
(sq**-tailrec 82 43)
"P.494"
"C.2.3 開錠の計算"
(define fact
(lambda (n)
(if (zero? n)
1
(* n (fact (- n 1))))))
(define fact-tailrec
(lambda (n)
(define fact-iter
(lambda (y p)
(if (zero? y)
p
(fact-iter (- y 1) (* y p)))))
(fact-iter n 1)))
(fact-tailrec 25)
"P.495"
"繰り返しの書法"
(define fact-let
(lambda (n)
(let countdown ((y n ) (p 1))
(if (zero? y)
p
(countdown (- y 1) (* y p))))))
(fact-let 6)
(define fact-let+
(lambda (n)
(let countup ((y 0) (p 1))
(if (= y n)
p
(countup (+ y 1) (* (+ y 1) p))))))
(fact-let+ 8)
(define fact-do
(lambda (n)
(do ((y n (- y 1)) (p 1 (* y p)))
((zero? y) p))))
(fact-do 5)
| false |
263485818ebb6efce9cfed6d204f884b75ff348d | dafce3f01299ab8a1315908ec6ad0328189e4af5 | /instructions.scm | b3639c83544a94aae0816b244ff3ad0ecbff5bae | [] | no_license | yi-jiayu/CHIC-8 | c1020898ca745c92251447544c604045a6ff2c39 | 0eccf66d4fd10bb78e776b0b65353911937b1328 | refs/heads/master | 2020-05-21T05:34:59.713713 | 2019-05-12T12:12:17 | 2019-05-12T12:12:17 | 185,925,558 | 0 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 541 | scm | instructions.scm | (include-relative "interpreter")
(include-relative "instruction")
(import interpreter
instruction)
(define (subroutine-return! ip instr)
(let ((sp (- (interpreter-sp ip) 1)))
(set! (interpreter-pc ip) (vector-ref (interpreter-stack ip) sp))
(set! (interpreter-sp ip) sp)))
(define (subroutine-call! ip instr)
(vector-set! (interpreter-stack ip)
(interpreter-sp ip)
(interpreter-pc ip))
(set! (interpreter-sp ip) (+ 1 (interpreter-sp ip)))
(set! (interpreter-pc ip) (instr-addr instr)))
| false |
9ea26651fe4988c9f5279e639775a36db70ca5ac | 5bbc152058cea0c50b84216be04650fa8837a94b | /pre-benchmark/htdp/base/Images/car.ss | ccef75865d0e4844330715908086db20f1ad05ce | [] | no_license | nuprl/gradual-typing-performance | 2abd696cc90b05f19ee0432fb47ca7fab4b65808 | 35442b3221299a9cadba6810573007736b0d65d4 | refs/heads/master | 2021-01-18T15:10:01.739413 | 2018-12-15T18:44:28 | 2018-12-15T18:44:28 | 27,730,565 | 11 | 3 | null | 2018-12-01T13:54:08 | 2014-12-08T19:15:22 | Racket | UTF-8 | Scheme | false | false | 1,032 | ss | car.ss | #lang scheme
(require 2htdp/universe)
(define wheel-radius 5)
(define wheel-y-posn wheel-radius)
(define wheel-2-left (- (* 2 wheel-radius)))
(define wheel-2right (* 2 wheel-radius))
(define lwid (* 8 wheel-radius))
(define lhgt (* 2 wheel-radius))
(define uwid (* 4 wheel-radius))
(define uhgt wheel-radius)
(define wheel (circle wheel-radius "solid" "black"))
(define lbody (rectangle lwid lhgt "solid" "red"))
(define ubody (rectangle uwid uhgt "solid" "red"))
(define ubody+wheels
(overlay/xy (overlay/xy lbody wheel-2-left wheel-y-posn wheel) wheel-2right wheel-y-posn wheel))
(define car (overlay/xy ubody 0 (* 3/2 uhgt) ubody+wheels))
(define tree
(overlay (circle 10 'solid 'green) (nw:rectangle 2 20 'solid 'brown)))
(define mt
(empty-scene 300 (+ wheel-radius (image-height car))))
(define y-car (+ (pinhole-y car) wheel-radius))
(define (render w)
(place-image car w y-car (place-image tree 77 10 mt)))
(big-bang 0
(on-tick add1)
(on-draw render))
(map render '(50 100 150 200))
| false |
bdda9e005fb1d08e27646267d0797c27f964afeb | 685d0fcfef3077b4327f2155b48207fd4809ee57 | /source/common/analysisbase.ss | 3721dd9019e49935300ae1ad7120633dc44092c7 | [
"Apache-2.0"
] | permissive | ChillMagic/ICM-Scheme | f172c6e4d393e97cc2553f837176ca9f42ef71f8 | 0bfe82067dcf6f639fc009f1b012ee9d2f727686 | refs/heads/master | 2021-01-19T03:56:38.399883 | 2017-04-06T16:21:27 | 2017-04-06T16:21:27 | 84,420,360 | 0 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 1,290 | ss | analysisbase.ss | ;; ICM on Scheme
;; analysisbase.ss
;; Author : Chill
(library (ICM-AnalysisBase)
(export do-eval do-execute pattern pattern-once)
(import (rnrs))
;; Do Execute
(define (do-execute sfmap-func code env)
(if (list? code)
(let ((f (car code)))
(if (symbol? f)
((sfmap-func f) (cdr code) env)
(begin (display "Syntax Error for ")
(display code)
(display ".\n")))) code))
(define do-eval do-execute) ; Will be deleted.
;; Pattern
(define (pattern code)
(pattern-base pattern code))
(define (pattern-once code)
(pattern-base pattern-base2 code))
(define (pattern-symbol code)
(cond ((symbol=? code 'list) 'list)
((symbol=? code ':) ':)
((symbol=? code '...) '...)
(else 'ident)))
(define (pattern-list fpattern code)
(let ((r '()))
(for-each
(lambda (e)
(set! r (append r (list (fpattern e))))) code) r))
(define (pattern-base fpattern code)
(cond ((symbol? code) (pattern-symbol code))
((list? code) (pattern-list fpattern code))
(else 'data)))
(define (pattern-base2 code)
(cond ((symbol? code) (pattern-symbol code))
((list? code) 'expr)
(else 'data)))
)
| false |
5e3316c5a83fab1a56417e586efacf48b0d789b5 | 140a499a12332fa8b77fb738463ef58de56f6cb9 | /worlds/core/verbcode/125/render-0.scm | 51e32221b144b0ae63fb37cde61eb48f4d25a524 | [
"MIT"
] | permissive | sid-code/nmoo | 2a5546621ee8c247d4f2610f9aa04d115aa41c5b | cf504f28ab473fd70f2c60cda4d109c33b600727 | refs/heads/master | 2023-08-19T09:16:37.488546 | 2023-08-15T16:57:39 | 2023-08-15T16:57:39 | 31,146,820 | 10 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 3,182 | scm | render-0.scm | (define plain-headers
(table ("Content-Type" "text/plain")))
(define html-headers
(table ("Content-Type" "text/html")))
(define page-header-frag #134)
(define page-header-html (verbcall page-header-frag "render-partial" args))
;; Generate HTML page describing `obj`
(define html-for-obj
(lambda (obj)
(cat "<!DOCTYPE HTML><html lang=\"en\"><head><meta charset=\"utf-8\"></head><body>"
page-header-html
"<h1>" ($webutils:escape-html ($ obj)) ": "
($webutils:escape-html (try (obj:name) (getprop obj "name" "(No name)"))) "</h1>"
"<p>Child of " ($webutils:html-fragment-for-data (parent obj))
" | Owned by " ($webutils:html-fragment-for-data obj.owner)
(let ((ps (#0:all-props obj)))
(if (= 0 (len ps)) "This object has no properties."
(cat
"<p>Properties:"
"<table>"
"<tr><td>Property name</td><td>Value</td></tr>"
(call cat
(map
(lambda (p)
(cat "<tr><td>" p "</td><td>"
($webutils:html-fragment-for-data (getprop obj p))
"</td></tr>"))
ps))
"</table>")))
(let ((vs (verbs obj)))
(if (= 0 (len vs)) "This object defines no verbs (but its parents may)"
(cat
"<p>Verbs:"
"<table>"
"<tr><td>Verb name</td><td>Owner</td><td>Permissions</td></tr>"
(call cat
(map
(lambda (vindex)
(let ((v (get vs vindex))
(srchref (cat "/obj/" (gsub ($ obj) "#" "") "/v/" vindex))
(verbinfo (getverbinfo obj v))
(owner (get verbinfo 0))
(perms (get verbinfo 1)))
(cat "<tr><td><a href=\"" srchref "\">" v "</a></td>"
"<td>" ($webutils:html-fragment-for-data owner) "</td>"
"<td>" perms "</td></tr>")))
(range 0 (- (len vs) 1))))
"</table>")))
"<p>Children:<ul>"
($strutils:join (map (lambda (o)
(cat "<li>" ($webutils:html-fragment-for-data o)))
(children obj))
"")
"</ul>"
"</body></html>")))
(call (lambda (method path headers body args)
(let ((authuser (tget headers "authuser" player))
(obj (object (get (get args 0 ()) 0 -1))))
(settaskperms authuser) ; prevent any monkey business
(if (not (valid obj))
(list 404 plain-headers
(cat "The object " obj " is invalid."))
(try
(list 200 html-headers
(html-for-obj obj))
(if (erristype error E_PERM)
(list 401 plain-headers "You are not permitted to view this.")
error))))) ; rethrow
args)
| false |
Subsets and Splits