blob_id
stringlengths 40
40
| directory_id
stringlengths 40
40
| path
stringlengths 3
171
| content_id
stringlengths 40
40
| detected_licenses
listlengths 0
8
| license_type
stringclasses 2
values | repo_name
stringlengths 6
82
| snapshot_id
stringlengths 40
40
| revision_id
stringlengths 40
40
| branch_name
stringclasses 13
values | visit_date
timestamp[ns] | revision_date
timestamp[ns] | committer_date
timestamp[ns] | github_id
int64 1.59k
594M
⌀ | star_events_count
int64 0
77.1k
| fork_events_count
int64 0
33.7k
| gha_license_id
stringclasses 12
values | gha_event_created_at
timestamp[ns] | gha_created_at
timestamp[ns] | gha_language
stringclasses 46
values | src_encoding
stringclasses 14
values | language
stringclasses 2
values | is_vendor
bool 2
classes | is_generated
bool 1
class | length_bytes
int64 4
7.87M
| extension
stringclasses 101
values | filename
stringlengths 2
149
| content
stringlengths 4
7.87M
| has_macro_def
bool 2
classes |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
a2698205397a1b55a694de3eb42e139a48828174 | defeada37d39bca09ef76f66f38683754c0a6aa0 | /mscorlib/system/mono-list-item.sls | 3ce5ac9c9960c7eadb1b2934cf912f9bd75fb079 | []
| 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 | 336 | sls | mono-list-item.sls | (library (system mono-list-item)
(export new is? mono-list-item?)
(import (ironscheme-clr-port))
(define-syntax new
(lambda (e)
(syntax-case e ()
((_ a ...) #'(clr-new System.MonoListItem a ...)))))
(define (is? a) (clr-is System.MonoListItem a))
(define (mono-list-item? a) (clr-is System.MonoListItem a)))
| true |
6c016329f640bde6d650d161de57b5da8ed55551 | 2e50e13dddf57917018ab042f3410a4256b02dcf | /etc/R7RS/src/dderiv.sch | c46484450b7e31181c90cd9817cf96e48ceb419e | [
"MIT",
"LicenseRef-scancode-other-copyleft",
"LicenseRef-scancode-other-permissive",
"GPL-2.0-or-later",
"LGPL-2.0-or-later",
"BSD-2-Clause",
"LGPL-2.1-or-later",
"GPL-1.0-or-later"
]
| permissive | koba-e964/picrin | c0ca2596b98a96bcad4da9ec77cf52ce04870482 | 0f17caae6c112de763f4e18c0aebaa73a958d4f6 | refs/heads/master | 2021-01-22T12:44:29.137052 | 2016-07-10T16:12:36 | 2016-07-10T16:12:36 | 17,021,900 | 0 | 0 | MIT | 2019-05-17T03:46:41 | 2014-02-20T13:55:33 | Scheme | UTF-8 | Scheme | false | false | 2,082 | sch | dderiv.sch | ;;; DDERIV -- Table-driven symbolic derivation.
;;; Returns the wrong answer for quotients.
;;; Fortunately these aren't used in the benchmark.
(import (rnrs base)
(rnrs io simple)
(rnrs hashtables)
(rnrs mutable-pairs))
(define (lookup key table)
(let loop ((x table))
(if (null? x)
#f
(let ((pair (car x)))
(if (eq? (car pair) key)
pair
(loop (cdr x)))))))
(define properties (make-hashtable symbol-hash eq?))
(define (get key1 key2)
(let ((x (hashtable-ref properties key1 #f)))
(if x
(let ((y (lookup key2 x)))
(if y
(cdr y)
#f))
#f)))
(define (put key1 key2 val)
(let ((x (hashtable-ref properties key1 #f)))
(if x
(let ((y (lookup key2 x)))
(if y
(set-cdr! y val)
(set-cdr! x (cons (cons key2 val) (cdr x)))))
(hashtable-set! properties key1 (list (cons key2 val))))))
(define (my+dderiv a)
(cons '+
(map dderiv (cdr a))))
(define (my-dderiv a)
(cons '-
(map dderiv (cdr a))))
(define (*dderiv a)
(list '*
a
(cons '+
(map (lambda (a) (list '/ (dderiv a) a)) (cdr a)))))
(define (/dderiv a)
(list '-
(list '/
(dderiv (cadr a))
(caddr a))
(list '/
(cadr a)
(list '*
(caddr a)
(caddr a)
(dderiv (caddr a))))))
(put '+ 'dderiv my+dderiv)
(put '- 'dderiv my-dderiv)
(put '* 'dderiv *dderiv)
(put '/ 'dderiv /dderiv)
(define (dderiv a)
(if (not (pair? a))
(if (eq? a 'x) 1 0)
(let ((f (get (car a) 'dderiv)))
(if f
(f a)
(error #f "No derivation method available")))))
(define (main)
(let* ((count (read))
(input1 (read))
(output (read))
(s (number->string count))
(name "dderiv"))
(run-r6rs-benchmark
(string-append name ":" s)
count
(lambda () (dderiv (hide count input1)))
(lambda (result) (equal? result output)))))
| false |
540507c0eb34bc3814f75f0948709f24629ea601 | 6b8bee118bda956d0e0616cff9ab99c4654f6073 | /suda-ex/scm2c-untyped/scm2c-definitions.ss | 9ccf48a8170acd9adf9c6357cb601bd9c56ba046 | []
| 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 | 639 | ss | scm2c-definitions.ss | (module scm2c-definitions scheme
(provide (all-defined-out))
(define CONTLINE -80)
;; prepare the calling convention
(define EXTERN 'extern)
;; for 'use' in process-exp
(define BOOL 'BOOL)
(define VAL 'VAL)
(define LONG 'long)
(define VOID 'void)
(define COND 'cond)
(define LAMBDA 'lambda)
(define QUOTE 'quote)
(define BEGIN 'begin)
;; These are types and type-modifiers
(define INT 'int)
;; for 'termin' in process-exp
(define RETURN "return")
(define NONE "")
(define COMMA ", ")
(define SEMI ";")
(define SUBSCRIPT "]")
(define-struct port-set (in out-h out-cu))
)
| false |
d148708a3f256ffe254b654ae41455cdd6746155 | 784dc416df1855cfc41e9efb69637c19a08dca68 | /src/std/db/conpool.ss | d6a6b936921decd34219911716784f540e961c71 | [
"LGPL-2.1-only",
"Apache-2.0",
"LGPL-2.1-or-later"
]
| permissive | danielsz/gerbil | 3597284aa0905b35fe17f105cde04cbb79f1eec1 | e20e839e22746175f0473e7414135cec927e10b2 | refs/heads/master | 2021-01-25T09:44:28.876814 | 2018-03-26T21:59:32 | 2018-03-26T21:59:32 | 123,315,616 | 0 | 0 | Apache-2.0 | 2018-02-28T17:02:28 | 2018-02-28T17:02:28 | null | UTF-8 | Scheme | false | false | 2,247 | ss | conpool.ss | ;;; -*- Gerbil -*-
;;; (C) vyzo
;;; Generic database connection pool
package: std/db
(import :gerbil/gambit/threads
:std/sugar
:std/error
:std/logger)
(export make-conpool conpool?
conpool-get conpool-put conpool-release conpool-close)
(defstruct conpool (e mx cv conns out max)
constructor: :init!
final: #t)
(defmethod {:init! conpool}
(lambda (self connect (max #f))
(struct-instance-init! self connect
(make-mutex) (make-condition-variable)
[] [] max)))
(def (conpool-get cp (timeo absent-obj))
(with ((conpool connect mx cv _ out max) cp)
(let lp ()
(mutex-lock! mx)
(match (conpool-conns cp)
([conn . rest]
(set! (conpool-conns cp)
rest)
(set! (conpool-out cp)
(cons conn out))
(mutex-unlock! mx)
conn)
(else
(if (or (not max) (fx< (length out) max))
(let (conn
(try
(connect)
(catch (e)
(mutex-unlock! mx)
(raise e))))
(set! (conpool-out cp)
(cons conn out))
(mutex-unlock! mx)
conn)
(let (res (mutex-unlock! mx cv timeo))
(if res
(lp)
(raise-timeout 'conpool-get "Error getting connection; timeout")))))))))
(def (conpool-put cp conn)
(with ((conpool _ mx cv conns out) cp)
(mutex-lock! mx)
(set! (conpool-conns cp)
(cons conn conns))
(set! (conpool-out cp)
(remq conn out))
(condition-variable-signal! cv)
(mutex-unlock! mx)))
(def (conpool-release cp conn)
(with ((conpool _ mx cv conns out) cp)
(mutex-lock! mx)
(set! (conpool-out cp)
(remq conn out))
(mutex-unlock! mx)
{destroy conn}))
(def (conpool-close cp)
(def (close conn)
(try
{destroy conn}
(catch (e)
(log-error "error closing connection" e))))
(with ((conpool _ mx cv conns out) cp)
(mutex-lock! mx)
(for-each close conns)
(for-each close out)
(set! (conpool-e cp)
(cut error "Connection pool is closed"))
(set! (conpool-conns cp) [])
(set! (conpool-out cp) [])
(mutex-unlock! mx)))
| false |
5d33134f07b596720fed1ddca44566279662992b | defeada37d39bca09ef76f66f38683754c0a6aa0 | /mscorlib/system/globalization/ccfixed.sls | f65bd3a55908d5d836de4970f1e24f9ea2df82fe | []
| no_license | futsuki/ironscheme-port | 2dbac82c0bda4f4ff509208f7f00a5211d1f7cd5 | 4e7a81b0fbeac9a47440464988e53fb118286c54 | refs/heads/master | 2016-09-06T17:13:11.462593 | 2015-09-26T18:20:40 | 2015-09-26T18:20:40 | 42,757,369 | 0 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 1,818 | sls | ccfixed.sls | (library (system globalization ccfixed)
(export new
is?
ccfixed?
kd-nearest
to-date-time
kday-on-or-after
kday-before
from-date-time
day-of-week
kday-after
kday-on-or-before)
(import (ironscheme-clr-port))
(define-syntax new
(lambda (e)
(syntax-case e ()
((_ a ...) #'(clr-new System.Globalization.CCFixed a ...)))))
(define (is? a) (clr-is System.Globalization.CCFixed a))
(define (ccfixed? a) (clr-is System.Globalization.CCFixed a))
(define-method-port
kd-nearest
System.Globalization.CCFixed
kd_nearest
(static: System.Int32 System.Int32 System.Int32))
(define-method-port
to-date-time
System.Globalization.CCFixed
ToDateTime
(static:
System.DateTime
System.Int32
System.Int32
System.Int32
System.Int32
System.Double)
(static: System.DateTime System.Int32))
(define-method-port
kday-on-or-after
System.Globalization.CCFixed
kday_on_or_after
(static: System.Int32 System.Int32 System.Int32))
(define-method-port
kday-before
System.Globalization.CCFixed
kday_before
(static: System.Int32 System.Int32 System.Int32))
(define-method-port
from-date-time
System.Globalization.CCFixed
FromDateTime
(static: System.Int32 System.DateTime))
(define-method-port
day-of-week
System.Globalization.CCFixed
day_of_week
(static: System.DayOfWeek System.Int32))
(define-method-port
kday-after
System.Globalization.CCFixed
kday_after
(static: System.Int32 System.Int32 System.Int32))
(define-method-port
kday-on-or-before
System.Globalization.CCFixed
kday_on_or_before
(static: System.Int32 System.Int32 System.Int32)))
| true |
3c4917b4014e562a2ab1b8008e44fdaf0e0cfa27 | c763eaf97ffd7226a70d2f9a77465cbeae8937a8 | /scheme/tree-builder.scm | 2b8acc4556b0d4abab6ec914eaeb3cacfc6b0347 | []
| no_license | jhidding/crossword | 66907f12e87593a0b72f234ebfabbd2fb56dae9c | b3084b6b1046eb0a996143db1a144fd32379916f | refs/heads/master | 2020-12-02T19:33:08.677722 | 2017-08-21T21:07:43 | 2017-08-21T21:07:43 | 96,357,240 | 1 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 2,252 | scm | tree-builder.scm | (library (tree-builder)
#|! The simple interface builds an S-expression by composing functions in
| continuation passing style. At each point during the process of building
| the S-expr the builder state is a function of one argument, placing its
| argument in the current position in the S-expr. The returned value may be
| another state function or the resulting nested list.
|
| > (tb:close (tb:start))
| -> ()
|
| > (tb:close (tb:add 4 (tb:add 5 (tb:start))))
| -> (5 4)
|
| > ((compose tb:close
| (tb:add 4)
| tb:close
| (tb:add 3)
| (tb:add 2)
| tb:new-list
| (tb:add 1)
| tb:start))
| -> (1 (2 3) 4)
|
| > ((compose tb:close tb:close
| (tb:add #\o)
| (tb:add #\l)
| (tb:add #\l)
| (tb:add #\e)
| (tb:add #\h)
| tb:new-string
| tb:start))
| -> ("hello")
|
| > ((compose tb:close tb:close
| (tb:add #\a)
| (tb:add #\d)
| (tb:add #\b)
| (tb:add #\m)
| (tb:add #\a)
| (tb:add #\l)
| tb:new-symbol
| tb:start))
| -> (lambda)
|#
(export tb:start tb:new tb:add tb:close tb:close-all
tb:new-symbol tb:new-string tb:new-list tb:new-datum)
(import (rnrs base (6))
(rnrs io ports (6))
(functional)
(rename (cut) (cut $)))
(define (tb:start)
(lambda (x) x))
(define (tb:new f state)
(lambda (x)
(lambda (y)
(state (cons (f x) y)))))
(define tb:new-list
($ tb:new id <>))
(define tb:new-string
($ tb:new list->string <>))
(define tb:new-symbol
($ tb:new (compose string->symbol list->string) <>))
(define (tb:close state)
(state '()))
(define (tb:close-all state)
(if (procedure? state)
(tb:close-all (state '()))
state))
(define tb:new-datum
($ tb:new (compose get-datum open-string-input-port list->string) <>))
(define (tb:add item)
(lambda (state)
(lambda (x)
(state (cons item x)))))
)
| false |
41f7ce253a39cbc912a964ad5bb9ba61b90aebd6 | ac2a3544b88444eabf12b68a9bce08941cd62581 | /gsc/tests/69-params/optional.scm | 4d9b46ace691e1f2843244acc2727bd1e79e0e6d | [
"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 | 303 | scm | optional.scm | (define (optional #!optional a b c)
(println a)
(println b)
(println c))
(optional)
(optional 1)
(optional 1 2 3)
(define (default-values #!optional (a 10) (b 20) (c 30))
(println a)
(println b)
(println c))
(default-values)
(default-values 1)
(default-values 1 2)
(default-values 1 2 3)
| false |
c3404916f619fbb6d45e20e654f6937ebd50a454 | 3323fb4391e76b853464a9b2fa478cd7429e9592 | /exercise-2.62.ss | fba40921e32567299659dd63eab82841455c2ff6 | []
| no_license | simpleliangsl/hello-scheme | ceb203933fb056523f5288ce716569096a71ad97 | 31434fb810475ee0e8ec2e6816995a0041c47f44 | refs/heads/master | 2023-06-16T12:07:28.744188 | 2021-07-15T06:39:32 | 2021-07-15T06:39:32 | 386,197,304 | 0 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 238 | ss | exercise-2.62.ss | (top-level-program (import (rnrs) (ordered-set))
(define set1 '(1 3 5 7 9 11 13 15))
(define set2 '(2 4 5 6 9 10 12 14))
(assert (equal? '(1 2 3 4 5 6 7 9 10 11 12 13 14 15) (union-set set1 set2)))
(display "PASSED!")
) | false |
b0c6aa044bc0b1b9864b3cb812fb60aa3fee4ee3 | fae4190f90ada065bc9e5fe64aab0549d4d4638a | /typed-scheme-lti/tests/barland.ss | 625bb43da53f17b3e1400fea07ed3c76590091a1 | []
| 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 | 967 | ss | barland.ss | #reader (planet "typed-reader.ss" ("plt" "typed-scheme.plt"))
(module barland (planet "typed-scheme.ss" ("plt" "typed-scheme.plt"))
(define-type-alias set (top -> top))
(define: (autos [elt : top]) : top (memq elt '(vw saab bmw audi)))
(define: (element-of? [elt : top] [s : set]) : top (s elt))
(define: (evens [elt : top]) : top (and (number? elt) (even? elt)))
(define-typed-struct pr ([fst : top] [snd : top]))
#;(define: (length=2? [any : top]) : boolean
(and (pair? any)
(pair? (cdr any))
(empty? (cdr (cdr any)))))
(define: (cartesian-product [A : set] [B : set]) : set
(lambda: ([elt : top])
(and (pr? elt)
(element-of? (pr-fst elt) A)
(element-of? (pr-snd elt) B))))
(define: evenEuroCars : set (cartesian-product evens autos))
#;(display (element-of? (make-pr 4 'bmw) evenEuroCars)) ; = #t
#;(display (element-of? (make-pr 'bmw 4) evenEuroCars)) ; = #f
) | false |
729547a637d5ee31dee9f610f779ca1552626974 | 2cc6d9594b4c13b8b917adb47d6c5f92e70b561a | /interpreter/env.scm | 8e97facb3d2fb2b6c86a6def06406d31bc3547a9 | [
"MIT"
]
| permissive | qyqx/Sexy | ca84a55457a6fc98727200f238cd3fd34260ed0b | 70eed74d21835fc7a2bdff7df28d368b299ad74a | refs/heads/master | 2021-01-24T03:56:59.128511 | 2015-08-10T23:40:38 | 2015-08-10T23:40:38 | null | 0 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 13,417 | scm | env.scm |
(define (local-env)
(sexy-environment #f))
(define (cli-env)
(define lenv (local-env))
(extend lenv
'(opt rest sys)
(list
(cdr global-arg-pair)
(car global-arg-pair)
sys)
top-cont
top-err))
(define (symbols-env)
(define expanded (read-expand-cache-prog sexy-use-symbols (local-env)))
(define compiled (sexy-seq-subcontractor (cdr expanded) #t))
(define the-env (local-env))
(compiled the-env top-cont top-err)
(set! load-symbols-env the-env))
(define (global-env)
(define (make-new)
(define prelude (local-env))
(define preset! (sexy-send-atomic prelude 'def!))
(define (fill-prelude fs)
(define (setem! p)
(preset! (car p) (cdr p)))
(map setem! fs))
(define primitives
(list
(cons 'is? eq?)
(cons '+ +)
(cons '- -)
(cons '* *)
(cons '/ /)
(cons '= sexy-equal?)
(cons '> sexy->)
(cons '< sexy-<)
(cons 'div quotient)
(cons 'rem remainder)
(cons 'mod modulo)
(cons 'num? number?)
(cons 'int? integer?)
(cons 'nint?
(lambda (x)
(and (number? x) (not (integer? x)))))
(cons 'rune? char?)
(cons 'pair cons)
(cons 'pair? pair?)
(cons 'list list)
(cons 'list? list?)
(cons 'vector
(sexy-proc
'primitive-function
'global
(lambda (args opts cont err)
(define size ((sexy-send-atomic opts 'get) 'size))
(define init ((sexy-send-atomic opts 'get) 'init))
(cont
(if (integer? size)
(let ((v (make-vector size init)))
(vector-map (lambda (i x) (vector-set! v i x)) (list->vector args))
v)
(apply vector args))))))
(cons 'vector? vector?)
(cons 'text
(sexy-proc
'primitive-function
'global
(lambda (args opts cont err)
(define size ((sexy-send-atomic opts 'get) 'size))
(define init ((sexy-send-atomic opts 'get) 'init))
(cont
(if (integer? size)
(let ((s (make-string size (if (char? init) init #\space))))
(vector-map (lambda (i x) (string-set! s i x)) (list->vector args))
s)
(apply string args))))))
(cons 'text? string?)
(cons 'rand random)
(cons 'record
(sexy-proc
'primitive-function
'global
(lambda (args opts cont err)
(cont (apply sexy-record args)))))
(cons 'object
(sexy-proc
'primitive-function
'global
(lambda (args opts cont err)
(define autos (sexy-send-atomic opts 'auto))
(define rsend (sexy-send-atomic opts 'resend))
(define default (sexy-send-atomic opts 'default))
(if (eq? autos 'null) (set! autos #f) #f)
(if (eq? rsend 'null) (set! rsend #f) #f)
(if (eq? default 'null) (set! default #f) #f)
(cont (sexy-object args autos rsend default)))))
(cons 'send
(sexy-proc
'primitive-function
'global
(lambda (args opts cont err)
(define l (length args))
(if (< l 2)
(err (list 'arity "send requires two arguments: an object and a message.") cont)
(sexy-send (car args) (cadr args) cont err)))))
(cons 'fetch
(lambda (uri)
(define got (get-uri uri))
(if (eq? got not-found)
'null
got)))
(cons 'math
(sexy-object
(list
'e 2.718281828459045
'phi 1.618033988749895
'pi 3.141592653589793
'tau 6.283185307179587
'root-2 1.414213562373095
'max max
'min min
'sum (lambda (xs) (apply + xs))
'product (lambda (xs) (apply * xs))
'pow (lambda (x y) (expt x y))
'sqrt sqrt
'log log
'sin sin
'cos cos
'tan tan
)
#f
#f
#f))
(cons 'json
(sexy-object
(list
'parse
(lambda (json-str)
(define schemified (read-json json-str))
(define (revise obj)
(cond
((vector? obj)
(vector-map
(lambda (i x) (revise x))
obj))
((list? obj)
(let ((rec (sexy-record)))
(hts! rec 'vars
(alist->hash-table
(map
(lambda (x) (cons (car x) (revise (cdr x))))
obj)))
rec))
(else obj)))
(revise schemified))
'stringify
(lambda (obj)
(define (revise x)
(cond
((char? x) (string x))
((list? x) (revise (list->vector x)))
((vector? x)
(vector-map
(lambda (i y) (revise y))
x))
((hash-table? x)
(let ((t (htr x 'type)))
(if (eq? t 'record)
(let ((pairs (hash-table->alist (htr x 'vars))))
(map
(lambda (x) (cons (revise (car x)) (revise (cdr x))))
pairs))
(error "json.stringify: I don't know how to stringify this object!" x))))
(else x)))
(json->string (revise obj)))
)
#f
#f
#f))
(cons 'gensym sexy-gensym)
(cons 'uuid uuid-v4)
(cons 'cat
(sexy-proc
'primitive-function
'global
(lambda (args opts cont err)
(define l (length args))
(define strings (map (lambda (x) (sexy-send-atomic x 'to-text)) args))
(define joiner
(let ((j (sexy-send-atomic opts 'with)))
(if (string? j)
j
"")))
(cont
(if (< l 1)
""
(string-join strings joiner))))))
(cons 'FILE_NOT_FOUND 'neither-true-nor-false)
(cons 'T_PAAMAYIM_NEKUDOTAYIM (quote ::))))
(fill-prelude primitives)
prelude)
(if genv
genv
(let ((noob (make-new)))
(set! genv noob)
(set! g-has? (sexy-send-env noob 'has? top-cont top-err))
(set! g-get (sexy-send-env noob 'get top-cont top-err))
noob)))
(define-syntax import-global-prelude
(ir-macro-transformer
(lambda (expr inject compare)
(define global-prelude-file "global.sex")
(define text
(with-input-from-file global-prelude-file read-string))
`(define ,(inject 'global-prelude-text) ,text))))
(import-global-prelude)
(define-syntax import-default-symbols.sex
(ir-macro-transformer
(lambda (expr inject compare)
(define symbols-file "symbols.sex")
(define text
(with-input-from-file symbols-file read-string))
`(define ,(inject 'symbols.sex) ,text))))
(import-default-symbols.sex)
(define (add-global-prelude)
(define cpath "~/.sexy/global.sex")
(define is-cached (file-exists? cpath))
(define expanded-prelude
(if is-cached
(with-input-from-file
cpath
(lambda ()
(read)))
(let ((expanded
(sexy-expand
(sexy-read-file
(open-input-string global-prelude-text))
(local-env))))
(with-output-to-file
cpath
(lambda ()
(write expanded)))
expanded)))
(define prelude-c
(sexy-seq-subcontractor expanded-prelude #t))
(define full
(prelude-c
genv
top-cont
top-err))
'null)
(define (sexy-global? x)
(not (eq? not-found (glookup x))))
(define (lookup env x cont err)
(sexy-send-env
env
'has?
(lambda (has?)
(if (has? x)
(sexy-send-env
env
'get
(lambda (getter)
(cont (getter x)))
err)
(sexy-send-env
env
'mama
(lambda (mom)
(if (and mom (not (eq? mom 'null)))
(lookup mom x cont err)
(cont not-found)))
err)))
err))
(define (extend env names vals cont err)
(define noob (sexy-environment env))
(define args
(let loop ((ns names) (vs vals) (yargs '()))
(if (eq? '() ns)
yargs
(loop (cdr ns) (cdr vs) (cons (car ns) (cons (car vs) yargs))))))
(define params
(append
(list
noob
(lambda (null) (cont noob))
err)
args))
(apply mutate! params))
(define (mutate! env cont err . args)
(sexy-send-env
env
'def!
(lambda (def!)
(apply def! args)
(cont 'null))
err))
(define (update! env k v cont err)
(sexy-send-env
env
'has?
(lambda (has?)
(if (has? k)
(sexy-send-env
env
'def!
(lambda (def!)
(cont (def! k v)))
err)
(sexy-send-env
env
'mama
(lambda (mom)
(if (and mom (not (eq? mom 'null)))
(update! mom k v cont err)
(cont not-found)))
err)))
err))
(define (glookup x)
(if (g-has? x)
(g-get x)
not-found))
| true |
2eae76cb840f32910be5af27091abc78e4faa530 | ae4938300d7eea07cbcb32ea4a7b0ead9ac18e82 | /stream/utils.sls | 08aafd57f6a88279fe5041bd446fc152d9a2bf46 | []
| no_license | keenbug/imi-libs | 05eb294190be6f612d5020d510e194392e268421 | b78a238f03f31e10420ea27c3ea67c077ea951bc | refs/heads/master | 2021-01-01T19:19:45.036035 | 2012-03-04T21:46:28 | 2012-03-04T21:46:28 | 1,900,111 | 0 | 1 | null | null | null | null | UTF-8 | Scheme | false | false | 758 | sls | utils.sls | #!r6rs
(library (imi stream utils)
(export stream-group)
(import (rnrs)
(imi sugar receive)
(imi stream))
(define (stream-group len strm)
(and strm
(lambda ()
(let loop ([n 0]
[ls '()]
[strm strm])
(cond
[(= n len)
(values (reverse ls)
(stream-group len strm))]
[strm
(receive (val rest) (strm)
(loop (+ 1 n)
(cons val ls)
rest))]
[else
(error 'stream-group
"length of stream is not a multiple of len"
len)])))))
)
| false |
6e3b3514bc1114d5edf42615a59c83ec4e083761 | 8eb21733f83949941fadcb268dd4f0efab594b7f | /100/srfi-101/srfi/%3A101/random-access-lists/syntax/ra-datum.sls | 0d6106e614142100b02cd366d069a7ea07a9a2fe | []
| no_license | srfi-explorations/final-srfis | d0994d215490333062a43241c57d0c2391224527 | bc8e7251d5b52bf7b11d9e8ed8b6544a5d973690 | refs/heads/master | 2020-05-02T07:29:24.865266 | 2019-03-26T19:02:18 | 2019-03-26T19:02:18 | 177,819,656 | 1 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 793 | sls | ra-datum.sls | #!r6rs
;; SRFI 101: Purely Functional Random-Access Pairs and Lists
;; Copyright (c) David Van Horn 2009. All Rights Reserved.
(library (srfi :101 random-access-lists syntax ra-datum)
(export datum->ra-datum)
(import (rnrs base)
(rnrs bytevectors)
(prefix (srfi :101 random-access-lists procedures) ra:))
(define (datum->ra-datum d)
(cond ((boolean? d) d)
((number? d) d)
((char? d) d)
((string? d) d)
((symbol? d) d)
((bytevector? d) d)
((null? d) d)
((vector? d)
(vector-map datum->ra-datum d))
((pair? d)
(ra:cons (datum->ra-datum (car d))
(datum->ra-datum (cdr d))))
(else
(error "Unkown datum" d)))))
| false |
f88aa38ae7754aa5aeb8a29f9c033e97ca31247f | b43e36967e36167adcb4cc94f2f8adfb7281dbf1 | /scheme/swl1.3/src/swl/eventloop.ss | 8d405952d82bf0f49a6ca4d0b40d8f6ff0910bde | [
"SWL",
"TCL"
]
| permissive | 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 | 1,536 | ss | eventloop.ss | ;; Copyright (c) 1996 Oscar Waddell
;;
;; See the file "Notice" for information on usage and redistribution
;; of this file, and for a DISCLAIMER OF ALL WARRANTIES.
;; when using the Tk file-event-handler the Tk side indicates a read is ready
;; by indicating callback 1 should be invoked
;;
;; By allocating this callback here and retaining it so its slot isn't reclaimed
;; we ensure that it's id is 1. A bit gross, but we don't plan to use the non-
;; threaded eventloop much longer anyway.
(define read-proc (swl:callback-lambda () (printf "not called~n")))
(define read-proc-id 1)
(define bob-prompt-and-read
(rec wpar
(lambda (n)
(display "swl" (console-output-port))
(do ((n n (- n 1)))
((= n 0)
(write-char #\space (console-output-port))
(flush-output-port (console-output-port)))
(display ">" (console-output-port)))
(let event-loop ()
(call-with-values
(lambda () (wait-for-event))
(lambda (fallback-id args)
(if (not fallback-id)
(wpar n)
(if (fx= fallback-id read-proc-id)
(read (console-input-port))
(begin
(swl:apply-callback-proc (swl:lookup-callback fallback-id) args)
(event-loop))))))))))
(define single-threaded-bob
(lambda (args)
(waiter-prompt-and-read bob-prompt-and-read)
(for-each load args)
(new-cafe)
(when (root-window) (send (root-window) destroy))
(exit)))
| false |
e2f086eb990d6814529bec385afc35d8d637518c | 382706a62fae6f24855ab689b8b2d87c6a059fb6 | /0.3/interpreter/src/apply.scm | 1c6885add235e9405c3e5b979aa2c9d0b1a0fa34 | [
"Apache-2.0"
]
| permissive | mstram/bard | ddb1e72a78059617403bea1842840bb9e979198e | 340d6919603a30c7944fb66e04df0562180bc0bb | refs/heads/master | 2021-01-21T00:12:27.174597 | 2014-07-10T13:20:39 | 2014-07-10T13:20:39 | null | 0 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 1,362 | scm | apply.scm | ;;;; ***********************************************************************
;;;; FILE IDENTIFICATION
;;;;
;;;; Name: apply.scm
;;;; Project: Bard
;;;; Purpose: the apply function
;;;; Author: mikel evins
;;;; Copyright: 2012 by mikel evins
;;;;
;;;; ***********************************************************************
(declare (extended-bindings))
(define (%apply op args)
(cond
((function? op)(apply (function-proc op) args))
((interpreted-method-instance? op)(apply (interpreted-method-proc op) args))
((primitive-instance? op)(apply (primitive-proc op) args))
((procedure? op)(apply op args))
((list? op)(if (< -1 args (length op))
(list-ref op args)
'()))
((pair? op)(let ((key args))
(cond ((eq? key 'left)(car op))
((eq? key 'right)(cdr op))
(else (error (str "invalid pair key: " (%as-string key)))))))
((string? op)(if (< -1 args (string-length op))
(string-ref op args)
'()))
((alist-table-instance? op)(alist-table-get op args))
((record-instance? op)(record-ref op args))
((tuple-instance? op)(tuple-ref op args))
(else (error (str "not an applicable object: " op "; args: " args)))))
(define %funcall (lambda (fn . args)(%apply fn args)))
| false |
3eb0df74c4358ead40adc35a9c9ded4df9e13b14 | 120324bbbf63c54de0b7f1ca48d5dcbbc5cfb193 | /packages/srfi/private/registry.sls | c73cf255e78950a69e686ab0226339339bd53098 | [
"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 | 3,281 | sls | registry.sls | #!r6rs
;; Copyright 2010 Derick Eddington. My MIT-style license is in the file named
;; LICENSE from the original collection this file is distributed with.
(library (srfi private registry)
(export
expand-time-features
run-time-features
available-features)
(import
(rnrs)
(for (prefix (srfi private platform-features) platform-)
run expand))
(define-syntax make-expand-time-features
(lambda (_)
(define SRFIs
'((0 cond-expand)
(1 lists)
(2 and-let*)
#;(5 let)
(6 basic-string-ports)
(8 receive)
(9 records)
(11 let-values)
(13 strings)
(14 char-sets)
(16 case-lambda)
#;(17 generalized-set!)
#;(18 multithreading)
(19 time)
#;(21 real-time-multithreading)
(23 error)
(25 multi-dimensional-arrays)
(26 cut)
(27 random-bits)
#;(28 basic-format-strings)
#;(29 localization)
(31 rec)
(37 args-fold)
(38 with-shared-structure)
(39 parameters)
(41 streams)
(42 eager-comprehensions)
(43 vectors)
#;(44 collections)
(45 lazy)
#;(46 syntax-rules)
#;(47 arrays)
(48 intermediate-format-strings)
#;(51 rest-values)
#;(54 cat)
#;(57 records)
#;(59 vicinities)
#;(60 integer-bits)
(61 cond)
#;(63 arrays)
(64 testing)
#;(66 octet-vectors)
(67 compare-procedures)
(69 basic-hash-tables)
#;(71 let)
#;(74 blobs)
(78 lightweight-testing)
#;(86 mu-and-nu)
#;(87 case)
#;(95 sorting-and-merging)
(98 os-environment-variables)
(99 records)))
(define (SRFI-names x)
(define number car)
(define mnemonic cdr)
(define (make-symbol . args)
(string->symbol (apply string-append
(map (lambda (a)
(if (symbol? a) (symbol->string a) a))
args))))
(let* ((n-str (number->string (number x)))
(colon-n (make-symbol ":" n-str))
(srfi-n (make-symbol "srfi-" n-str))
(srfi-n-m (apply make-symbol srfi-n
(map (lambda (m) (make-symbol "-" m))
(mnemonic x)))))
;; The first two are recommended by SRFI-97.
;; The last two are the two types of SRFI-97 library name.
(list srfi-n
srfi-n-m
`(srfi ,colon-n)
`(srfi ,colon-n . ,(mnemonic x)))))
(let ((s (apply append (map SRFI-names SRFIs)))
(h (platform-expand-time-features))
(o '(r6rs)))
#`(quote #,(datum->syntax #'ignored (append s h o))))))
(define expand-time-features (make-expand-time-features))
(define run-time-features (platform-run-time-features))
(define available-features (append run-time-features expand-time-features))
)
| true |
22054cb36dc9450991a39e40985ff21de2a85de2 | f97599978922ae5201189b923ed51e8a1f8e4e29 | /tests/monitors.scm | ab8586e3bbc3d2cce381efd6653fbc7810b108dc | []
| no_license | kdltr/hardwood | 972140864198ab23732744406f03fa216c915138 | af0de71d77d53415f2ab76ba30e36170a1564ffc | refs/heads/master | 2021-01-20T18:15:48.525101 | 2018-01-17T00:07:03 | 2018-01-17T03:36:03 | 61,128,105 | 0 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 808 | scm | monitors.scm | (test-group "Monitors"
(define (monitors-test)
(recv
('crash (abort 'some-condition))
('exit (void))))
(define pid1 (spawn monitors-test))
(define pid2 (spawn monitors-test))
(define pid3 (spawn monitors-test))
(define ref1 (monitor pid1))
(define ref2 (monitor pid2))
(define ref3 (monitor pid3))
; Normal exit
(! pid1 'exit)
(test "normal exit"
(list 'DOWN ref1 pid1 'exited)
(? 1 #f))
; Excptional exit
(! pid2 'crash)
(test "exit with condition"
(list 'DOWN ref2 pid2 (list 'condition 'some-condition))
(? 1 #f))
; Demonitoring
(demonitor ref3)
(! pid3 'exit)
(test "demonitoring"
#t
(? 0.2 #t))
; Dead process
(define ref4 (monitor pid1))
(test "dead process"
(list 'DOWN ref4 pid1 'no-process)
(? 1 #f)))
| false |
14fa7fad85b29759559d912695f2f296bab57ad8 | c3077b381e1de73805bc0d6d3ba0467b80643548 | /vm/machine-state.scm | 6b2911080402cef4c698f6832c3f05bd3d90744b | [
"MIT"
]
| permissive | aemoncannon/woof | 1aa99c0028e28564de1709bdcc0167db0ff1f667 | a03d1bf0a186d4538c556e1d347605cdaa49f427 | refs/heads/master | 2020-07-08T03:02:13.712852 | 2008-03-01T03:09:32 | 2008-03-01T03:09:32 | 52,326 | 4 | 1 | null | null | null | null | UTF-8 | Scheme | false | false | 11,099 | scm | machine-state.scm |
(define-structure machine-state
active-context globals)
(define-structure woof-globals
functions classes misc)
(define new-woof-globals
(lambda ()
(make-woof-globals
(make-table test: string=?)
(make-table test: string=?)
(make-table test: string=?))))
(define new-machine-state
(lambda ()
(let* ((globals (new-woof-globals))
(state (make-machine-state
#f
globals))
(nil (make-woof-object
#f
#f
(make-table test: string=?)))
(nil-prim-data (make-woof-class-prim-data
nil
(list nil)
"nil"))
(metaclass (make-woof-object
#f
#f
(make-table test: string=?)))
(metaclass-prim-data (make-woof-class-prim-data
nil
'(nil)
"MetaClass")))
(woof-object-prim-data-set! nil nil-prim-data)
(woof-object-class-set! nil nil)
(install-class! state nil)
(install-global! state nil "nil")
(woof-object-prim-data-set! metaclass metaclass-prim-data)
(woof-object-class-set! metaclass metaclass)
(install-class! state metaclass)
(install-class! state (woof-class-instance state "Class" nil))
(install-class! state (woof-class-instance state "Object" nil))
;;Set MetaObject's super to Class
(woof-class-super-set!
(woof-object-class (class-by-name state "Object"))
(class-by-name state "Class"))
(install-class! state (woof-class-instance state "String" (class-by-name state "Object" )))
(install-class! state (woof-class-instance state "Integer" (class-by-name state "Object" )))
(install-class! state (woof-class-instance state "List" (class-by-name state "Object" )))
(install-class! state (woof-class-instance state "Function" (class-by-name state "Object" )))
(install-class! state (woof-class-instance state "Block" (class-by-name state "Object" )))
(install-class! state (woof-class-instance state "BlockContext" (class-by-name state "Object" )))
(install-class! state (woof-class-instance state "Continuation" (class-by-name state "Object" )))
(install-class! state (woof-class-instance state "Exception" (class-by-name state "Object" )))
(install-class! state (woof-class-instance state "NoApplicableFunctionException"
(class-by-name state "Exception" )))
(install-class! state (woof-class-instance state "ExceptionHandler" (class-by-name state "Object" )))
(install-class! state (woof-class-instance state "Boolean" (class-by-name state "Object" )))
(install-class! state (woof-class-instance state "True" (class-by-name state "Boolean" )))
(install-class! state (woof-class-instance state "False" (class-by-name state "Boolean" )))
(install-global! state (woof-instance state (class-by-name state "False")) "false")
(install-global! state (woof-instance state (class-by-name state "True")) "true")
(install-class! state (woof-class-instance state "Maybe" (class-by-name state "Object" )))
(install-class! state (woof-class-instance state "Just" (class-by-name state "Maybe" )))
(install-class! state (woof-class-instance state "Nothing" (class-by-name state "Maybe" )))
(install-class! state (woof-class-instance state "Port" (class-by-name state "Object" )))
(install-class! state (woof-class-instance state "OutputPort" (class-by-name state "Port" )))
(let ((stdout (woof-instance state (class-by-name state "OutputPort"))))
(woof-object-prim-data-set! stdout (make-woof-output-port-prim-data (current-output-port)))
(install-global! state stdout "STDOUT"))
(install-function! state (woof-function-instance
state
"define:over:as:"
(list (class-by-name state "String")
(class-by-name state "List")
(class-by-name state "Block"))
(woof-block-instance
state
'((LVAR 0 0)
(LVAR 0 1)
(LVAR 0 2)
(CRFN)
(GETC "nil")
(RETURN)
)
0)
))
(install-function! state (woof-function-instance
state
"require:"
(list (class-by-name state "String"))
(woof-block-instance
state
'((LVAR 0 0)
(PRIM load_block_from_file)
(CALLJ 0)
(GETC "nil")
(RETURN)
)
0)
))
state
)))
(define with-new-machine-state
(lambda (func)
(func (new-machine-state))))
(define ready-machine-state-for-code!
(lambda (state code)
(let* ((context (new-top-level-context-for-block
state
(new-top-level-block
state
code))))
(machine-state-active-context-set! state context)
state
)))
(define new-top-level-block
(lambda (state code)
(woof-block-instance
state
code
0
)))
;; Create activation context for block..
(define new-top-level-context-for-block
(lambda (state block)
(let* ((globals (machine-state-globals state))
(tmps (make-vector 0))
(new-context (woof-block-context-instance
state
(woof-block-code-pc block) ;pc
block ;block
'() ;stack
(woof-nil state) ;sender
(woof-nil state) ;home
tmps ;tmps
'() ;env
'() ;exception handlers
)))
(woof-block-home-set! block new-context)
(block-context-env-set! new-context (list new-context))
new-context)))
(define new-context-for-block
(lambda (state block args)
(let* ((num-args (length args))
(home (woof-block-home block))
(tmps (let ((tmps (make-vector num-args)))
(do ((i 0 (+ i 1)))
((= i num-args))
(vector-set! tmps i (list-ref args i)))
tmps
))
(new-context (woof-block-context-instance
state
(woof-block-code-pc block)
block
'()
(machine-state-active-context state)
home
tmps
'()
'()
)))
(if (nil? state home)
(block-context-env-set! new-context
(list new-context))
(block-context-env-set! new-context
(cons new-context (block-context-env home))))
new-context)))
(define install-global!
(lambda (state obj name)
(let ((globals (machine-state-globals state)))
(table-set! (woof-globals-misc globals)
name
obj))))
(define install-class!
(lambda (state class)
(let ((globals (machine-state-globals state)))
(install-global! state class (woof-class-name class)))))
(define install-function!
(lambda (state w-func)
(let ((globals (machine-state-globals state)))
(let* ((sig (woof-function-sig w-func))
(new-group (append (list w-func)
(table-ref
(woof-globals-functions globals)
sig
'()))))
(table-set! (woof-globals-functions globals) sig new-group)))))
(define global-by-name
(lambda (state name)
(let ((globals (machine-state-globals state)))
(table-ref (woof-globals-misc globals) name))))
(define class-by-name
(lambda (state name)
(global-by-name state name)))
(define activate-block-context!
(lambda (state context)
(machine-state-active-context-set! state context)))
(define top-of-stack
(lambda (state)
(first (machine-state-stack state))))
(define tos top-of-stack)
(define top-n-of-stack
(lambda (state n)
(take (machine-state-stack state) n)))
(define pop-n-of-stack!
(lambda (state n)
(let ((result (take (machine-state-stack state) n)))
(do ((i 0 (+ i 1)))
((= i n))
(pop-stack! state))
result)))
(define push-stack!
(lambda (state val)
(let* ((context (machine-state-active-context state))
(stack (block-context-stack context)))
(block-context-stack-set! context (cons val stack)))))
(define pop-stack!
(lambda (state)
(let* ((context (machine-state-active-context state))
(stack (block-context-stack context))
(val (first stack)))
(block-context-stack-set! context (cdr stack))
val)))
(define inc-pc!
(lambda (state)
(let* ((context (machine-state-active-context state))
(pc (block-context-pc context)))
(block-context-pc-set! context (+ 1 pc)))))
(define current-instr
(lambda (state)
(instr-at (machine-state-code state)
(machine-state-pc state))))
(define opcode
(lambda (instr)
(first instr)))
(define arg1
(lambda (instr)
(second instr)))
(define arg2
(lambda (instr)
(third instr)))
(define instr-at
(lambda (code i)
(list-ref code i)))
(define env-var-set!
(lambda (state i j obj)
(let* ((context (machine-state-active-context state))
(env (block-context-env context))
(target-context (list-ref env i))
(target-frame (block-context-tmps target-context)))
(if (>= j (vector-length target-frame))
(block-context-tmps-set! target-context (vector-append
target-frame
'#(0 0 0 0 0 0 0))))
(vector-set! (block-context-tmps target-context) j obj))))
(define env-get-var
(lambda (state i j)
(let* ((context (machine-state-active-context state))
(env (block-context-env context))
(target-context (list-ref env i))
(target-frame (block-context-tmps target-context)))
(vector-ref target-frame j))))
(define machine-state-env
(lambda (state)
(block-context-env (machine-state-active-context state))))
(define add-block-context-exception-handler!
(lambda (state handler context)
(block-context-exception-handlers-set!
context
(cons handler (block-context-exception-handlers context)))))
(define print-env
(lambda (state)
(let ((env (machine-state-env state)))
(map (lambda (ea) (begin (display "(")
(vector-for-each
(lambda (var)
(if (woof-object? var)
(print-woof-object var)))
(block-context-tmps ea))
(display ")")))
env))))
(define machine-state-stack
(lambda (state)
(block-context-stack (machine-state-active-context state))))
(define machine-state-pc
(lambda (state)
(block-context-pc (machine-state-active-context state))))
(define machine-state-pc-set!
(lambda (state pc)
(let ((context (machine-state-active-context state)))
(block-context-pc-set! context pc))))
(define machine-state-code
(lambda (state)
(woof-block-code
(block-context-block
(machine-state-active-context state)))))
(define run-machine-state-tests
(lambda ()
(run-tests
(list
(lambda ()
(with-new-machine-state
(lambda (state)
(let* ((obj (woof-nil state)))
(assert-true (is-a? obj (global-by-name state "nil"))
msg: "nil should be of class nil")))))
(lambda ()
(with-new-machine-state
(lambda (state)
(let* ((obj (woof-boolean-instance state #t)))
(assert-true (is-a? obj (global-by-name state "True"))
msg: "true should be of class True")))))
(lambda ()
(with-new-machine-state
(lambda (state)
(let* ((obj (woof-boolean-instance state #f)))
(assert-true (is-a? obj (global-by-name state "False"))
msg: "false should be of class False")))))
)))) | false |
58d5ac98a6bbd343d66b4a51b65adf44117a53c7 | 6e359a216e1e435de5d39bc64e75998945940a8c | /ex3.79.scm | 7c7b2bfeaa7555d0dfde0d3cf1048fc0549c5c3c | []
| no_license | GuoDangLang/SICP | 03a774dd4470624165010f65c27acc35d844a93d | f81b7281fa779a9d8ef03997214e47397af1a016 | refs/heads/master | 2021-01-19T04:48:22.891605 | 2016-09-24T15:26:57 | 2016-09-24T15:26:57 | 69,106,376 | 0 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 169 | scm | ex3.79.scm | (load "ex3.78.scm")
(define (solve-2nd-general f y0 dy0 dt)
(define d (integral (delay dd) dy0 dt))
(define y (integral (delay d) y0 dt))
(define dd (f d y))
y)
| false |
14ce124fa0ab7e5ab6c2db2aa34407e92ad9458c | 000dbfe5d1df2f18e29a76ea7e2a9556cff5e866 | /ext/termios/termios_stub.stub | 7931f3fa6f5a6e9ffb115566ade6dd531546bafe | [
"BSD-3-Clause",
"LicenseRef-scancode-other-permissive",
"MIT",
"BSD-2-Clause"
]
| permissive | ktakashi/sagittarius-scheme | 0a6d23a9004e8775792ebe27a395366457daba81 | 285e84f7c48b65d6594ff4fbbe47a1b499c9fec0 | refs/heads/master | 2023-09-01T23:45:52.702741 | 2023-08-31T10:36:08 | 2023-08-31T10:36:08 | 41,153,733 | 48 | 7 | NOASSERTION | 2022-07-13T18:04:42 | 2015-08-21T12:07:54 | Scheme | UTF-8 | Scheme | false | false | 2,138 | stub | termios_stub.stub | ;; -*- mode:scheme; coding: utf-8 -*-
(decl-code
(.include <sagittarius.h>)
(.define "LIBSAGITTARIUS_EXT_BODY")
(.include <sagittarius/extend.h>
<sagittarius-termios.h>
<errno.h>))
(decl-code
(.if "_WIN32" (.include <windows.h>))
(.if "_WIN32" (.include <fcntl.h>))
(.if "_WIN32" (.include <io.h>)))
(define-type <termios> "SgTermios*")
(define-c-proc make-termios () Sg_MakeTermios)
(define-c-proc termios? (o) ::<boolean> SG_TERMIOSP)
(define-c-proc sys-cfgetispeed (tios::<termios>) ::<fixnum>
(result (cfgetispeed (SG_TERMIOS_TERMIOS tios))))
(define-c-proc sys-cfgetospeed (tios::<termios>) ::<fixnum>
(result (cfgetospeed (SG_TERMIOS_TERMIOS tios))))
(define-cise-stmt $result
((_ who expr)
`(let ((r::int ,expr))
(result (SG_MAKE_BOOL (== r 0))))))
(define-c-proc sys-cfsetispeed (tios::<termios> ispeed::<fixnum>)
($result sys-cfsetispeed (cfsetispeed (SG_TERMIOS_TERMIOS tios) ispeed)))
(define-c-proc sys-cfsetospeed (tios::<termios> ospeed::<fixnum>)
($result sys-cfsetospeed (cfsetospeed (SG_TERMIOS_TERMIOS tios) ospeed)))
(define-cfn port->fd (p::SgPort*) ::int :static
(let ((file (Sg_PortFile p)))
(.if "_WIN32"
(let ((h::intptr_t (Sg_FileFD file)))
;; TODO is this correct?
(return (_open_osfhandle h (logior _O_APPEND _O_RDONLY))))
(return (cast int (Sg_FileFD file))))))
(define-c-proc sys-tcdrain (port::<port>)
($result sys-tcdrain (tcdrain (port->fd port))))
(define-c-proc sys-tcflow (port::<port> action::<fixnum>)
($result sys-tcflow (tcflow (port->fd port) action)))
(define-c-proc sys-tcflush (port::<port> queue-selector::<fixnum>)
($result sys-tcflush (tcflush (port->fd port) queue-selector)))
(define-c-proc sys-tcgetattr! (port::<port> tios::<termios>)
($result sys-tcgetattr (tcgetattr (port->fd port) (SG_TERMIOS_TERMIOS tios))))
(define-c-proc sys-tcsendbreak (port::<port> duration::<fixnum>)
($result sys-tcsendbreak (tcsendbreak (port->fd port) duration)))
(define-c-proc sys-tcsetattr! (port::<port> action::<fixnum> tios::<termios>)
($result sys-tcsetattr
(tcsetattr (port->fd port) action (SG_TERMIOS_TERMIOS tios))))
| false |
226274b0622e0910b44c3ffbabb432f883ff1d2a | 2b0dc0760baad4405f64b424345381f688173281 | /compiler/src/test/scheme/libraries/test/singleexpr.scm | a75988cd963f5188cdc78d78dae0e742533dd8e9 | [
"Apache-2.0"
]
| permissive | abduld/llambda | f2e7daf0c9a302dafa29a2d4067bfae6d1ec8317 | 17e53a5ec15f2b09f2eb3304151af3dbbcfd7f32 | refs/heads/master | 2023-04-12T23:59:17.462698 | 2015-10-24T04:51:25 | 2015-10-24T04:51:25 | 45,697,748 | 0 | 0 | NOASSERTION | 2023-04-04T01:11:51 | 2015-11-06T17:50:04 | Scala | UTF-8 | Scheme | false | false | 113 | scm | singleexpr.scm | (define-library (test singleexpr)
(import (llambda internal primitives))
(export a)
(begin
(define a 1)))
| false |
186720c3e49e6232124305702598ab4da4a52914 | b9eb119317d72a6742dce6db5be8c1f78c7275ad | /random-scheme-stuff/pascal.scm | 8cc2258b508d548f95c0ac28964147fc849651dd | []
| no_license | offby1/doodles | be811b1004b262f69365d645a9ae837d87d7f707 | 316c4a0dedb8e4fde2da351a8de98a5725367901 | refs/heads/master | 2023-02-21T05:07:52.295903 | 2022-05-15T18:08:58 | 2022-05-15T18:08:58 | 512,608 | 2 | 1 | null | 2023-02-14T22:19:40 | 2010-02-11T04:24:52 | Scheme | UTF-8 | Scheme | false | false | 913 | scm | pascal.scm | #lang scheme
; To make a pascal's triangle of order 0, return ((1)) .
; To make a pascal's triangle of order n > 0, return pascal's triangle
; of order n-1, plus a new row which contains the sums of the
; interstices of the previous row.
(define (pascal order)
(define (new-row old-row)
(let loop ((result (list (car old-row)))
(old-row old-row))
(cond ((null? old-row)
result)
((= (length old-row)
1)
(append result (list (car old-row))))
(#t (loop (append result (list (+ (car old-row) (cadr old-row))))
(cdr old-row))))))
(define (last list)
(if (null? (cdr list))
(car list)
(last (cdr list))))
(if (>= 0 order)
'((1))
(let ((smaller-triangle (pascal (- order 1))))
(append smaller-triangle
(list (new-row (last smaller-triangle)))))))
| false |
7fc8b0447ecad9b50b69d676a2e1281b5f1ed590 | 9345867d5616f00e9add07095db49e97fcc1cf02 | /t/util.t | 1a34f94d3bc2dc0d279f942c662612d2a223a34c | [
"MIT"
]
| permissive | kana/vim-xire | 91eb2cf417d68b9e598f992c6b5442f72a928594 | e4e97d8926fcdf1488d3e59a85a4af0253a5de01 | refs/heads/master | 2016-09-06T06:17:05.007579 | 2011-12-07T12:46:17 | 2011-12-07T12:46:17 | 588,299 | 1 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 5,530 | t | util.t | #!/usr/bin/env gosh
(add-load-path ".")
(add-load-path "./gauche-test-gasmine")
(use test.gasmine)
(use text.tree)
(use vim.xire.util)
(describe "convert-identifier-conventions"
(it "should return the same spell if ordinary identifier is given"
(expect (convert-identifier-conventions "foo") equal? "foo")
(expect (convert-identifier-conventions "bar123") equal? "bar123")
(expect (convert-identifier-conventions "s:local") equal? "s:local")
)
(it "should convert 'x?' convention"
(expect (convert-identifier-conventions "foo?") equal? "foo_p")
(expect (convert-identifier-conventions "foo?bar") equal? "foo?bar")
)
(it "should convert 'x!' convention"
(expect (convert-identifier-conventions "foo!") equal? "foo_x")
(expect (convert-identifier-conventions "foo!bar") equal? "foo!bar")
)
(it "should convert 'x->y' convention"
(expect (convert-identifier-conventions "foo->bar") equal? "foo_to_bar")
(expect (convert-identifier-conventions "x->y->z") equal? "x_to_y_to_z")
)
(it "should convert 'x-y-z' convention"
(expect (convert-identifier-conventions "x-y-z") equal? "x_y_z")
(expect (convert-identifier-conventions "strange-") equal? "strange_")
)
(it "should convert '%x' convention"
(expect (convert-identifier-conventions "%internal") equal? "_internal")
(expect (convert-identifier-conventions "w%i%r%e%d") equal? "w_i_r_e_d")
)
)
(describe "convert-key-sequence-conventions"
(it "should translate key sequence string properly"
(expect (convert-key-sequence-conventions "foo")
equal? "\"foo\"")
(expect (convert-key-sequence-conventions "\"*p")
equal? "\"\\\"*p\"")
(expect (convert-key-sequence-conventions "bar<BS>z")
equal? "\"bar\\<BS>z\"")
)
)
(describe "convert-regexp-conventions"
(it "should convert given Scheme regexp into Vim script string"
(expect (convert-regexp-conventions #/foo/) equal? "'foo'")
(expect (convert-regexp-conventions #/\(x\|y\)/) equal? "'\\(x\\|y\\)'")
(expect (convert-regexp-conventions #/'/) equal? "''''")
)
)
(describe "convert-string-conventions"
(it "should convert given Scheme string into Vim script string"
(expect (convert-string-conventions "foo") equal? "\"foo\"")
(expect (convert-string-conventions "f\"oo") equal? "\"f\\\"oo\"")
(expect (convert-string-conventions "f'oo") equal? "\"f'oo\"")
(expect (convert-string-conventions "-\x1f-") equal? "\"-\\x1f-\"")
)
)
(describe "scheme-object->vim-script-notation"
(it "should convert given Scheme boolean into equivalent one in Vim script"
(expect (scheme-object->vim-script-notation #f) equal? 0)
(expect (scheme-object->vim-script-notation #t) equal? 1)
)
(it "should convert given Scheme number into equivalent one in Vim script"
(expect (scheme-object->vim-script-notation 0) equal? 0)
(expect (scheme-object->vim-script-notation 123) equal? 123)
(expect (scheme-object->vim-script-notation -123) equal? -123)
(expect (scheme-object->vim-script-notation (- (ash 1 31) 1)) equal? (- (ash 1 31) 1))
(expect (scheme-object->vim-script-notation (ash -1 31)) equal? (ash -1 31))
(expect (scheme-object->vim-script-notation (ash 1 31)) raise?)
(expect (scheme-object->vim-script-notation (ash -1 32)) raise?)
(expect (scheme-object->vim-script-notation 0.123) raise?)
(expect (scheme-object->vim-script-notation #i123) raise?)
(expect (scheme-object->vim-script-notation 1+2i) raise?)
)
(it "should convert given Scheme regexp into equivalent one in Vim script"
(expect (scheme-object->vim-script-notation #/\(foo\|bar\)/) equal? "'\\(foo\\|bar\\)'")
)
(it "should convert given Scheme string into equivalent one in Vim script"
(expect (scheme-object->vim-script-notation "f\"oo") equal? "\"f\\\"oo\"")
)
(it "should convert given Scheme symbol into equivalent one in Vim script"
(expect (scheme-object->vim-script-notation 'foo!) equal? "foo_x")
)
(it "should fail for other Scheme objects"
(expect (scheme-object->vim-script-notation '()) raise?)
(expect (scheme-object->vim-script-notation '(x y z)) raise?)
(expect (scheme-object->vim-script-notation (lambda () '())) raise?)
)
)
(describe "<lvar>"
(define (make-a-lvar)
(make <lvar>
:src-name 'foo
:new-name 'bar
:init-expr '($const #f)))
(it "should be made with valid initial values"
(define lvar (make-a-lvar))
(expect (lvar-src-name lvar) eq? 'foo)
(expect (lvar-new-name lvar) eq? 'bar)
(expect (lvar-arg-name lvar) eq? #f)
(expect (lvar-init-expr lvar) equal? '($const #f))
(expect (lvar-ref-count lvar) eqv? 0)
(expect (lvar-set-count lvar) eqv? 0)
)
(it "should be counted through API"
(define lvar (make-a-lvar))
(begin
(expect (lvar-ref-count lvar) eqv? 0)
(expect (lvar-set-count lvar) eqv? 0))
(begin
(lvar-ref++! lvar)
(expect (lvar-ref-count lvar) eqv? 1)
(expect (lvar-set-count lvar) eqv? 0))
(begin
(lvar-set++! lvar)
(expect (lvar-ref-count lvar) eqv? 1)
(expect (lvar-set-count lvar) eqv? 1))
(begin
(lvar-ref--! lvar)
(expect (lvar-ref-count lvar) eqv? 0)
(expect (lvar-set-count lvar) eqv? 1))
(begin
(lvar-set--! lvar)
(expect (lvar-ref-count lvar) eqv? 0)
(expect (lvar-set-count lvar) eqv? 0))
)
)
(run-suites)
; __END__
; vim: filetype=scheme
| false |
d4148e5c20f0affff3d7518d8293e48c7e6b4e72 | ac2a3544b88444eabf12b68a9bce08941cd62581 | /gsc/tests/08-flprim/flilogb.scm | fbe96aec5b0b3b1692a180ded856cc16b73ffecf | [
"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 | 735 | scm | flilogb.scm | (declare (extended-bindings) (not constant-fold) (not safe))
(define (test a b)
(let* ((x (##flilogb a)))
(println (##fx= x b))))
(test 2.0 1)
(test 4.0 2)
(test 5.0 2)
(test 5.2 2)
(test 7.999999 2)
(test 123456.789 16)
(test -2.0 1)
(test -4.0 2)
(test -5.0 2)
(test -5.2 2)
(test -7.999999 2)
(test -123456.789 16)
(let ((max-f64 (##fl* (##flexpt 2.0 1023.0) (##fl- 2.0 (##flexpt 2.0 -52.0))))
(min-positive-f64 (##flexpt 2.0 -1074.0)))
(test max-f64 1023)
(test min-positive-f64 -1074))
(test 0.50 -1)
(test 0.25 -2)
(test 0.35 -2)
(test 0.0625 -4)
(test 0.0624 -5)
(test 0.01 -7)
(test -0.50 -1)
(test -0.25 -2)
(test -0.35 -2)
(test -0.0625 -4)
(test -0.0624 -5)
(test -0.01 -7)
| false |
c1c82813189e200c476452d2d7241388364b4068 | 0011048749c119b688ec878ec47dad7cd8dd00ec | /src/003/solution.scm | 15e8b6698c3c81f747a388d0647d773fb6879962 | [
"0BSD"
]
| permissive | turquoise-hexagon/euler | e1fb355a44d9d5f9aef168afdf6d7cd72bd5bfa5 | 852ae494770d1c70cd2621d51d6f1b8bd249413c | refs/heads/master | 2023-08-08T21:01:01.408876 | 2023-07-28T21:30:54 | 2023-07-28T21:30:54 | 240,263,031 | 8 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 131 | scm | solution.scm | (import
(euler))
(define (solve n)
(apply max (factors n)))
(let ((_ (solve 600851475143)))
(print _) (assert (= _ 6857)))
| false |
285f74d29e4029651a6c89208168c89f033f2a5a | b62560d3387ed544da2bbe9b011ec5cd6403d440 | /steel-examples/dependent.scm | e25fd5ec485a7e8e683dab155df189d46d5d4117 | [
"LicenseRef-scancode-unknown-license-reference",
"MIT",
"Apache-2.0"
]
| permissive | mattwparas/steel | c6fb91b20c4e613e6a8db9d9310d1e1c72313df2 | 700144a5a1aeb33cbdb2f66440bbe38cf4152458 | refs/heads/master | 2023-09-04T03:41:35.352916 | 2023-09-01T03:26:01 | 2023-09-01T03:26:01 | 241,949,362 | 207 | 10 | Apache-2.0 | 2023-09-06T04:31:21 | 2020-02-20T17:39:28 | Rust | UTF-8 | Scheme | false | false | 10,491 | scm | dependent.scm | ; #lang racket
;; the symbols that each of the conditions accepts must be validated
;; there should be a map of symbol to argument as well
;; i.e. x -> 1st, y -> 2nd
;; Then (x y) -> 1st and 2nd
;; This map needs to be validated by the input function in some capacity
;;
;; this also needs to be a macro to create a function with the operand
;; i.e. (>=/c x) -> (lambda (x) (>=/c x)) ;; -> in the run time, this needs to be
;; applied twice, once for the dependencies, once for the argument
;;
;; Each argument should only be evaluated once, and the result should be captured
; (foo 1 2)
; (x) (>=/c x) -> (lambda (x) (>=/c x))
(define-syntax contract-wrap
(syntax-rules ()
[(contract-wrap args pat)
(lambda (args) pat)]))
;; Takes a precondition, and returns a list to be consumed by a built-in
;; returns a list of the identifier for the argument, the list of arguments to the input function,
;; and the thunk that returns the function for the contract
(define-syntax dependent-condition
(syntax-rules ()
[(dependent-condition (ident func))
(list 'ident '() (lambda () (make/c func 'func )) 'func )]
[(dependent-condition (ident (arg) func))
(list 'ident '(arg) (lambda (arg) (make/c func 'func )) 'func )]
[(dependent-condition (ident (args ...) func))
(list 'ident '(args ...) (lambda (args ...) (make/c func 'func )) 'func )]))
(define-syntax ->i
(syntax-rules ()
[(->i r) ;; alias ->i to ->/c
(->/c r)]
[(->i (a) b)
(make-dependent-function/c (dependent-condition a) (dependent-condition b))]
[(->i (a b) c)
(make-dependent-function/c (dependent-condition a) (dependent-condition b) (dependent-condition c))]
; [(->/i a b c d)
; (make-function/c (make/c a 'a) (make/c b 'b)
; (make/c c 'c) (make/c d 'd))]
; [(->/i a b c d e)
; (make-function/c (make/c a 'a) (make/c b 'b) (make/c c 'c)
; (make/c d 'd) (make/c e 'e))]
; [(->/i a b c d e f)
; (make-function/c (make/c a 'a) (make/c b 'b) (make/c c 'c)
; (make/c d 'd) (make/c e 'e) (make/c f 'f))]
; [(->/i a b c d e f g)
; (make-function/c (make/c a 'a) (make/c b 'b) (make/c c 'c)
; (make/c d 'd) (make/c e 'e) (make/c f 'f)
; (make/c g 'g))]
; [(->/i a b c d e f g h)
; (make-function/c (make/c a 'a) (make/c b 'b) (make/c c 'c)
; (make/c d 'd) (make/c e 'e) (make/c f 'f)
; (make/c g 'g) (make/c h 'h))]
; [(->/i a b c d e f g h i)
; (make-function/c (make/c a 'a) (make/c b 'b) (make/c c 'c)
; (make/c d 'd) (make/c e 'e) (make/c f 'f)
; (make/c g 'g) (make/c h 'h) (make/c i 'i))]
))
; (define/contract (foo x y)
; (->/c (>=/c 10) (>=/c 20) (>=/c 30))
; (+ x y))
; (displayln (foo 5 20))
;; - make-dependent/c
;; - each precondition should have (list of args, contract, name)
;; - the postcondition should have
; (define (make-dependent/c ))
(define/contract (foo x y)
(->i ([x number?]
[y (x) (>=/c x)])
[lolol (x y) (and/c number? (>=/c (+ x y)))])
(+ x y 1))
; (foo 1 2)
(define (all func lst)
(if (null? lst)
#t
(if (func (car lst))
(all func (cdr lst))
#f)))
(define (all/c func lst)
(make/c (all func lst) (list 'all func lst)))
(define string?/c (make/c string? 'string?/c))
(define symbol?/c (make/c symbol? 'symbol?/c))
(define integer?/c (make/c integer? 'integer?/c))
(define float?/c (make/c float? 'float/c))
; (define )
(define (lst-func-loop funcs args)
(if (empty? funcs)
#t
(let ((result ((car funcs) (car args))))
(if result
(lst-func-loop (cdr funcs) (cdr args))
#f))))
;; Get the contract that uniquely identifies this predicate
;; Down to the predicate - we want to match the predicates along the way
;; Doesn't need to explicitly match this way - could do it other ways but this way works nicely
(define (make-identity-pred obj)
(cond [(string? obj) string?/c]
[(symbol? obj) symbol?/c]
[(integer? obj) integer?/c]
[(float? obj) float?/c]
;; If its a struct, get the contracts for all of the children fields as well
;; creating an exact copy of the shape of the struct on the way back up
[(struct? obj)
(make/c
(let ((struct-list (struct->list obj)))
(lambda (input)
; (let ((struct-list (struct->list obj)))
; (displayln obj)
; (displayln struct-list)
; (displayln input)
(if (struct? input)
(let ((input-list-struct (struct->list input)))
;; If the structs match the name/type, check the children
(and (equal? (car struct-list) (car input-list-struct))
(let ((children (map make-identity-pred (cdr struct-list))))
; (displayln children)
; (displayln input-list-struct)
(lst-func-loop
(map make-identity-pred (cdr struct-list))
(cdr input-list-struct)))))
#f))) 'struct-contract)]))
; (define (make-identity-pred obj)
; ; (newline)
; ; (display-color "CALLING WITH OBJECT " 'red)
; ; (display-color obj 'red)
; ; (newline)
; (cond [(string? obj) string?/c]
; [(symbol? obj) symbol?/c]
; [(integer? obj) integer?/c]
; [(float? obj) float?/c]
; ;; If its a struct, get the contracts for all of the children fields as well
; ;; creating an exact copy of the shape of the struct on the way back up
; [(struct? obj)
; (make/c
; ; TODO uncomment this and comment below, works
; ; (test-let ((struct-list (struct->list obj)))
; ; (newline)
; ; (display-color obj 'green)
; ; (newline)
; (lambda (input)
; ; (newline)
; ; (display-color "CAPTURED OBJ: " 'blue)
; ; (display-color obj 'blue)
; ; (newline)
; (test-let ((struct-list (struct->list obj)))
; (if (struct? input)
; (test-let ((input-list-struct (struct->list input)))
; ; (struct-list (struct->list obj)))
; ;; If the structs match the name/type, check the children
; (display-color "CALLING MAP" 'red)
; (newline)
; (and (equal? (car struct-list) (car input-list-struct))
; ; (display-color "CALLING MAP" 'red)
; ; (newline)
; (test-let ((children (map make-identity-pred (cdr struct-list))))
; (lst-func-loop
; ; (map make-identity-pred (cdr struct-list))
; children
; (cdr input-list-struct)))))
; #f))) 'struct-contract)]))
(struct Applesauce (a b c))
(struct Bananas (foo bar baz))
(define identity-contract (make-identity-pred (Applesauce "test" 'hello (Bananas 1 2 3))))
; (define identity-contract (make-identity-pred (Applesauce (Bananas 1 2 3) 'hello 10)))
; (displayln (identity-contract (Applesauce "blagh" 'test (Bananas 3 4 5))))
(displayln (identity-contract (Applesauce "blagh" 'test (Bananas 1 2 3))))
; (identity-contract (Applesauce "blagh" 'test (Bananas 3 4 5)))
;; Identity contract
;; Get the predicate that satisfies the most limited type information for a given func
;; Returns the contract that satisfies a given type most succinctly?
(struct Some (value))
(struct None ())
;; Contracts for option
(define (Option/c pred)
(make/c (fn (x)
(cond [(Some? x) (pred (Some-value x))]
[(None? x) #t]
[else #f]))
'Option/c))
(define (Option? value)
(or (Some? value) (None? value)))
(define (inner-value-contract option)
(cond [(Some? option) (make-identity-pred (unwrap-some option))]
[(None? option) any/c]
[else any/c]))
;; Map - explore dynamic dispatch with contracts?
(define/contract (map-option option func)
(->i ([option Option?]
[func (option) (->/c (inner-value-contract option) any/c)])
[result Option?])
(cond [(Some? option) (Some (func (Some-value option)))]
[(None? option) (None)]))
;; Get the inner value of the option - contract checking along the way
;; Figure out how to turn off contracts on OptLevel3 regardless -
;; this would speed up performance a lot - also figure out how to map this to compile time options in Rust
(define (unwrap-some option)
(Some-value option))
(define test (Some 10))
; (define/contract (add10 word)
; (->/c string? string?)
; word)
; (displayln (map-option test (lambda (x) (string->int x))))
; (contract/out o-map (->/c (t : predicate?) (Option/c t) (->/c t Option?) Option?))
; (define (map-option option func)
; (cond [(Some? option) (Some (func (Some-value option)))]
; [(None? option) option]))
;; Define a generic that is then bound and enforced to be equivalent for each of the fields
;; For instance:
; (->t [(K : predicate?)
; (V : predicate?)]
; (Option/c t)
; (->i ([option Option?]
; [func (option) (and/c (->/c _ Option?) )]
; ))
;; Implement generics as well
;; dependent contracts could take an optional parameter that must be unified - i.e. the same
; (->i ([x number?]
; [y (x) (>=/c x)])
; [lolol (x y) (and/c number? (>=/c (+ x y)))]) | true |
230687d3dd9e69cb5b678e70440d45f024e353be | c369eb130ec92b2f313c55e62c30c68c7e6710ae | /src/ru/mik/tenorequal/main.scm | 6519b609226bf44c9262818d5e77b0e9187087a7 | []
| no_license | VyacheslavMik/10-or-equal | 80d1e307512e1ed4dbe20011850d79fbd61a022d | adf63d3ddc39c154c3d10b885ea6f72777da0041 | refs/heads/master | 2020-03-18T11:20:23.717377 | 2018-05-24T05:31:07 | 2018-05-24T05:31:07 | 134,665,037 | 0 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 2,625 | scm | main.scm | (require 'android-defs)
(require ru.mik.tenorequal.renderer)
(define-alias activity-manager android.app.ActivityManager)
;; (define-alias context android.content.Context)
(define-alias configuration-info android.content.pm.ConfigurationInfo)
(define-alias gl-surface-view android.opengl.GLSurfaceView)
(define-alias bundle android.os.Bundle)
(define-alias toast android.widget.Toast)
(define-simple-class game-gl-surface-view (gl-surface-view)
(m-renderer ::open-gl-renderer)
(m-prev-y ::float)
(m-prev-action)
((*init* (ctx ::context))
(invoke-special android.opengl.GLSurfaceView (this) '*init* ctx))
((onPause)
(m-renderer:save-settings))
((onResume)
(m-renderer:restore-settings))
((onTouchEvent (event ::android.view.MotionEvent)) ::boolean
(unless (eq? event #!null)
(let ((x (event:getX)) (y (event:getY)) (action (event:getAction)))
(cond
((or (and (eq? action android.view.MotionEvent:ACTION_UP)
(eq? m-prev-action android.view.MotionEvent:ACTION_DOWN))
(and (eq? action android.view.MotionEvent:ACTION_UP)
(eq? m-prev-action android.view.MotionEvent:ACTION_MOVE)
(< (abs (- m-prev-y y)) 5)))
(m-renderer:touch-down x y))
((eq? action android.view.MotionEvent:ACTION_MOVE)
(m-renderer:move (- m-prev-y y))))
(set! m-prev-y y)
(set! m-prev-action action)))
;; (invoke-special android.view.View (this) 'onTouchEvent event)
#t)
((set-renderer (renderer ::open-gl-renderer)) ::void
(set! m-renderer renderer)
(invoke-special android.opengl.GLSurfaceView (this) 'setRenderer renderer)))
(define support-es2
(lambda (activity :: android.app.Activity)
(let* ((activity-manager :: activity-manager (activity:getSystemService context:ACTIVITY_SERVICE))
(configuration-info :: configuration-info (activity-manager:getDeviceConfigurationInfo)))
(>= configuration-info:reqGlEsVersion #x20000))))
(activity main
(gl-surface ::game-gl-surface-view)
(on-create
(if (not (support-es2 (this)))
((toast:makeText (this) "OpenGL ES 2.0 is not supported" toast:LENGTH_LONG):show)
(begin
(set! gl-surface (game-gl-surface-view (this)))
(gl-surface:setEGLContextClientVersion 2)
(gl-surface:set-renderer (open-gl-renderer (this)))
(setContentView gl-surface))))
((onPause) ::void
(invoke-special <android.app.Activity> (this) 'onPause)
(gl-surface:onPause))
((onResume) :: void
(invoke-special <android.app.Activity> (this) 'onResume)
(gl-surface:onResume)))
| false |
1833f944cee362a136450bae22a3b13ecca0a09a | 140a499a12332fa8b77fb738463ef58de56f6cb9 | /worlds/core/verbcode/47/add-dumped-verb-8.scm | 5fea4779a5900c258214e521409a3ecd5a23f232 | [
"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 | 290 | scm | add-dumped-verb-8.scm | (let ((obj (get args 0))
(dump (get args 1))
(info (get dump 0))
(args (get dump 1))
(code (get dump 2))
(vname (get info 2)))
(do
(addverb obj vname)
(setverbinfo obj vname info)
(setverbargs obj vname args)
(setverbcode obj vname code)))
| false |
afa4c854017e9c46c0a05feb141d037ee890c85d | ae4938300d7eea07cbcb32ea4a7b0ead9ac18e82 | /labs/playground/LiSP-4-3.ss | 22cda47c113c48fdd16437bb2d197fbe22ce7a22 | []
| no_license | keenbug/imi-libs | 05eb294190be6f612d5020d510e194392e268421 | b78a238f03f31e10420ea27c3ea67c077ea951bc | refs/heads/master | 2021-01-01T19:19:45.036035 | 2012-03-04T21:46:28 | 2012-03-04T21:46:28 | 1,900,111 | 0 | 1 | null | null | null | null | UTF-8 | Scheme | false | false | 9,038 | ss | LiSP-4-3.ss | (import (rnrs))
(define (evaluate e r s k)
(if (atom? e)
(if (symbol? e)
(evaluate-variable e r s k)
(evaluate-quote e r s k))
(case (car e)
[(quote) (evaluate-quote (cadr e) r s k)]
[(if) (evaluate-if (cadr e) (caddr e) (cadddr e) r s k)]
[(begin) (evaluate-begin (cdr e) r s k)]
[(set!) (evaluate-set! (cadr e) (caddr e) r s k)]
[(lambda) (evaluate-lambda (cadr e) (cddr e) r s k)]
[else (evaluate-application (car e) (cdr e) r s k)])))
(define (atom? e) (not (pair? e)))
(define (evaluate-if ec et ef r s k)
(evaluate ec r s
(lambda (v ss)
(evaluate ((v 'boolify) et ef) r ss k))))
(define (evaluate-begin e* r s k)
(if (pair? e*)
(evaluate (car e*) r s
(lambda (void ss)
(evaluate-begin (cdr e*) r ss k)))
(evaluate e* r s k)))
(define (r.init id)
(error 'r.init "No binding for" id))
(define (update s a v)
(lambda (aa)
(if (eqv? aa a) v (s aa))))
(define (update* s a* v*)
(if (pair? a*)
(update* (update s (car a*) (car v*)) (cdr a*) (cdr v*))
s))
(define (evaluate-variable n r s k)
(k (s (r n)) s))
(define (evaluate-set! n e r s k)
(evaluate e r s
(lambda (v ss)
(k v (update ss (r n) v)))))
(define (evaluate-application e e* r s k)
(define (evaluate-arguments e* r s k)
(if (pair? e*)
(evaluate (car e*) r s
(lambda (v ss)
(evaluate-arguments (cdr e*) r ss
(lambda (v* sss)
(k (cons v v*) sss)))))
(k '() s)))
(evaluate e r s
(lambda (f ss)
(evaluate-arguments e* r ss
(lambda (v* sss)
(if (eq? (f 'type) 'function)
((f 'behavior) v* sss k)
(error 'evaluate-application "Not a function" f)))))))
(define (evaluate-lambda n* e* r s k)
(allocate 1 s
(lambda (a* ss)
(k (create-function
(car a*)
(lambda (v* s k)
(if (= (length n*) (length v*))
(allocate (length n*) s
(lambda (a* ss)
(evaluate-begin e*
(update* r n* a*)
(update* ss a* v*)
k)))
(error 'lambda "Incorrect arity" n* v*))))
ss))))
(define (allocate n s q)
(if (> n 0)
(let ([a (new-location s)])
(allocate (- n 1)
(expand-store a s)
(lambda (a* ss)
(q (cons a a*) ss))))
(q '() s)))
(define (expand-store high-location s)
(update s 0 high-location))
(define (new-location s)
(+ 1 (s 0)))
(define s.init
(expand-store 0 (lambda (a) (error 's.init "No such address allocated" a))))
(define (bool.true x y) x)
(define (bool.false x y) y)
(define (invalid-msg msg)
(error 'value "Invalid message" msg))
(define (getq x ls)
(cond
[(null? ls) (error 'getq "no such name" x)]
[(eq? x (car ls))
(cadr ls)]
[else
(getq x (cddr ls))]))
(define (make-value type bool . restmsgs)
(lambda (msg)
(case msg
[(type) type]
[(boolify) bool]
[else (getq msg restmsgs)])))
(define the-empty-list
(make-value 'null bool.true))
(define (create-boolean value)
(let ([combinator (if value bool.true bool.false)])
(make-value 'boolean combinator)))
(define (create-symbol n)
(make-value 'symbol
bool.true
'name n))
(define (create-number num)
(make-value 'number
bool.true
'value num))
(define (create-function tag behavior)
(make-value 'function
bool.true
'tag tag
'behavior behavior))
(define (allocate-list v* s q)
(define (consify v* q)
(if (pair? v*)
(consify (cdr v*) (lambda (v ss)
(allocate-pair (car v*) v ss q)))
(q the-empty-list s)))
(consify v* q))
(define (allocate-pair a d s q)
(allocate 2 s
(lambda (a* ss)
(q (create-pair (car a*) (cadr a*))
(update (update ss (car a*) a) (cadr a*) d)))))
(define (create-pair a d)
(make-value 'pair
bool.true
'set-car (lambda (s v) (update s a v))
'set-cdr (lambda (s v) (update s d v))
'car a
'cdr d))
(define (evaluate-quote v r s k)
(cond
[(null? v) (k the-empty-list s)]
[(number? v) (k (create-number v) s)]
[(symbol? v) (k (create-symbol v) s)]
[(pair? v) (evaluate-quote-pair (car v) (cdr v) r s k)]
[else (error 'evaluate-quote "Invalid input - cannot convert" v)]))
(define (evaluate-quote-pair a d r s k)
(evaluate-quote a r s
(lambda (va ss)
(evaluate-quote d r ss
(lambda (vd sss)
(allocate-pair va vd sss k))))))
(define s.global s.init)
(define r.global r.init)
(define-syntax definitial
(syntax-rules ()
[(definitial name value)
(allocate 1 s.global
(lambda (a* ss)
(set! r.global (update r.global 'name (car a*)))
(set! s.global (update ss (car a*) value))))]))
(define-syntax defprimitive
(syntax-rules ()
[(defprimitive name value arity)
(definitial name
(allocate 1 s.global
(lambda (a* ss)
(set! s.global (expand-store (car a*) ss))
(create-function
(car a*)
(lambda (v* s k)
(if (= arity (length v*))
(value v* s k)
(error 'name "Incorrect arity" arity v*)))))))]))
(define-syntax defpredicate
(syntax-rules ()
[(defpredicate name predtype)
(defprimitive name
(lambda (v* s k)
(k (create-boolean (eq? ((car v*) 'type) 'predtype)) s))
1)]))
(define-syntax defprimnum
(syntax-rules ()
[(defprimnumtest name result-type)
(defprimitive name
(lambda (v* s k)
(if (and (eq? ((car v*) 'type) 'number)
(eq? ((cadr v*) 'type) 'number))
(k (result-type (name ((car v*) 'value)
((cadr v*) 'value)))
s)
(error 'name "requires numbers" v*)))
2)]))
(definitial t (create-boolean #t))
(definitial f (create-boolean #f))
(definitial nil the-empty-list)
(defprimnum = create-boolean)
(defprimnum < create-boolean)
(defprimnum > create-boolean)
(defprimnum <= create-boolean)
(defprimnum >= create-boolean)
(defprimnum + create-number)
(defprimnum - create-number)
(defprimnum * create-number)
(defprimnum / create-number)
(defprimitive cons
(lambda (v* s k)
(allocate-pair (car v*) (cadr v*) s k))
2)
(defprimitive car
(lambda (v* s k)
(if (eq? ((car v*) 'type) 'pair)
(k (s ((car v*) 'car)) s)
(error 'car "not a pair" (car v*))))
1)
(defprimitive cdr
(lambda (v* s k)
(if (eq? ((car v*) 'type) 'pair)
(k (s ((car v*) 'cdr)) s)
(error 'cdr "not a pair" (car v*))))
1)
(defprimitive set-car!
(lambda (v* s k)
(if (eq? ((car v*) 'type) 'pair)
(let ([pair (car v*)])
(k pair ((pair 'set-car) s (cadr v*))))
(error 'set-car! "not a pair" (car v*))))
2)
(defprimitive set-cdr!
(lambda (v* s k)
(if (eq? ((car v*) 'type) 'pair)
(let ([pair (car v*)])
(k pair ((pair 'set-cdr) s (cadr v*))))
(error 'set-cdr! "not a pair" (car v*))))
2)
(defpredicate pair? pair)
(defprimitive eqv?
(lambda (v* s k)
(k (create-boolean
(and (eq? ((car v*) 'type)
((cadr v*) 'type))
(case ((car v*) 'type)
[(null) #t]
[(boolean)
(((car v*) 'boolify)
(((cadr v*) 'boolify) #t #f)
(((cadr v*) 'boolify) #f #t))]
[(symbol?)
(eq? ((car v*) 'name) ((cadr v*) 'name))]
[(number)
(= ((car v*) 'value) ((cadr v*) 'value))]
[(pair)
(and (= ((car v*) 'car) ((cadr v*) 'car))
(= ((car v*) 'cdr) ((cadr v*) 'cdr)))]
[(function)
(= ((car v*) 'tag) ((cadr v*) 'tag))]
[else #f])))
s))
2)
(define (interpreter)
(define (toplevel s)
(display ">> ")
(evaluate (read)
r.global
s
(lambda (v ss)
(write (transcode-back v ss))
(display " - ")
(display (v 'type))
(newline)
(toplevel ss))))
(toplevel s.global))
(define (transcode-back v s)
(case (v 'type)
[(null) '()]
[(boolean) ((v 'boolify) #t #f)]
[(symbol) (v 'name)]
[(string) (v 'chars)]
[(number) (v 'value)]
[(pair) (cons (transcode-back (s (v 'car)) s)
(transcode-back (s (v 'cdr)) s))]
[(function) v]
[else (error 'transcode-back "Unkown type" (v 'type))]))
| true |
4e0aeea08bba964895336444aefd9b100384f100 | dae624fc36a9d8f4df26f2f787ddce942b030139 | /chapter-05/comments.scm | 7d4549e8c8ab70c5176590a7ed2d4a34b2dff85a | [
"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 | 217 | scm | comments.scm | ;; コメント
(print "Hello, world.") ; コメント
#|
#|
これはコメント
ネストも可能です。
|#
|#
;; これは S 式コメント
#; (begin (display "Hello,")
(display "world"))
| false |
d86b1bc1c96a1e3330a87dd185ab56bf928d8d55 | 599ae17c05a4f803a1f58a67ba75c2a0e285a5c7 | /glfw3.setup | 998af54059edbd151c54f1231c62ac45bf6bea90 | [
"BSD-2-Clause"
]
| permissive | rincewind/glfw3-chicken | e2c1cabb585c7f6f242049a50dd413bb610828a5 | 885a4e9f6811a30075e9a7b43012c50db06deee8 | refs/heads/master | 2020-04-05T19:00:32.875460 | 2014-04-14T18:55:58 | 2014-04-14T18:55:58 | null | 0 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 274 | setup | glfw3.setup | ;; glfw3.setup -*- scheme -*-
(if (feature? unix:)
(compile -d0 -O2 -J -s -l:libglfw.so.3 glfw3.scm)
(compile -d0 -O2 -J -s -lglfw glfw3.scm))
(compile -d0 -O2 -s glfw3.import.scm)
(install-extension
'glfw3
'("glfw3.so" "glfw3.import.so")
'((version "0.2.0")))
| false |
b22d552b032c5033d2c323631ae37933bf71b49a | 404799b4b2d5f83ee5304392826a69defc25da77 | /3.5.scm | b061074872061ca6771b70a3f82eb0c7aa19fe80 | []
| no_license | WuzhangFang/SICP-exercise | 38ae650c63e74bb7c6639bf984285e06743db925 | d9977009ec3e32a74edb13b4f13f6ebbbc44ab32 | refs/heads/master | 2020-04-16T16:01:18.058287 | 2019-10-01T21:52:40 | 2019-10-01T21:52:40 | 165,722,260 | 0 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 2,154 | scm | 3.5.scm | ;; 3.5 Streams
(define the-empty-stream '())
(define stream-null? null?)
(define (stream-car stream)
(car stream))
(define (stream-cdr stream)
(force (cdr stream)))
(define-syntax cons-stream
(syntax-rules ()
((_ <a> <b>)
(cons <a> (delay <b>)))))
(define (stream-ref s n)
(if (= n 0)
(stream-car s)
(stream-ref (stream-cdr s) (- n 1))))
(define (stream-map proc . argstreams)
(if (stream-null? (car argstreams))
the-empty-stream
(cons-stream
(apply proc (map stream-car argstreams))
(apply stream-map
(cons proc
(map stream-cdr argstreams))))))
(define (stream-for-each proc s)
(if (stream-null? s)
'done
(begin (proc (stream-car s))
(stream-for-each proc (stream-cdr s)))))
(define (display-stream s)
(stream-for-each display-line s))
(define (display-line x)
(newline)
(display x))
(define (stream-enumerate-interval low high)
(if (> low high)
the-empty-stream
(cons-stream
low
(stream-enumerate-interval (+ low 1) high))))
(define (stream-filter pred stream)
(cond ((stream-null? stream)
the-empty-stream)
((pred (stream-car stream))
(cons-stream (stream-car stream)
(stream-filter
pred
(stream-cdr stream))))
(else (stream-filter
pred
(stream-cdr stream)))))
(define (add-streams s1 s2)
(stream-map + s1 s2))
(define ones (cons-stream 1 ones))
(define integers
(cons-stream 1 (add-streams ones integers)))
(define (scale-stream stream factor)
(stream-map
(lambda (x) (* x factor)) stream))
;; display first n terms of an infinite stream
(define (show-stream s n)
(if (zero? n)
(display-line "done")
(begin (display-line (stream-car s))
(show-stream (stream-cdr s) (- n 1)))))
;; integral procedure: required delayed integrand
(define (integral delayed-integrand initial-value dt)
(define int
(cons-stream
initial-value
(let ((integrand
(force delayed-integrand)))
(add-streams
(scale-stream integrand dt)
int))))
int)
| true |
0f3b9d3175c6c08f6cc76de4c50dac87a3fb1240 | a8216d80b80e4cb429086f0f9ac62f91e09498d3 | /lib/chibi/emscripten.sld | cbfbbde356f63eae98848e5094da11c1e863cec4 | [
"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 | 269 | sld | emscripten.sld | (define-library (chibi emscripten)
(cond-expand
(emscripten
(import (chibi) (chibi ast))
(export eval-script! integer-eval-script string-eval-script
wait-on-event!)
(include "emscripten.scm")
(include-shared "emscripten"))))
| false |
e9f82ca6ac7e4ca076b9ca5d225e507d372767c2 | 73be7a6914f3976da6106f6f13202c97f6530868 | /scheme/assembler.scm | 76266a31bd66339590b964c148573114efc2740f | []
| no_license | ahanikel/playground | 69e4201bfbc3a7eeb270dc22c697fc23e92b1b01 | fdee79b8f19d43eb6e2bb3e0457ccefa594b0b3f | refs/heads/master | 2020-07-08T00:40:45.353716 | 2014-05-01T17:32:44 | 2014-05-01T17:32:44 | null | 0 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 6,724 | scm | assembler.scm | '(load "/opt/local/lib/gambit-c/syntax-case.scm")
(define (integer->hex n) (number->string n 16))
(define out-pos 0)
(define (emit-byte-to-file)
(let ((p (open-output-file "bootsector.bin")))
(lambda (n)
(if (char? n) (set! n (char->integer n)))
(cond ((> n 255) '(error out-of-range))
((< n 0)
(close-output-port p)
'closed)
(else (display (integer->char n) p)
(set! out-pos (+ out-pos 1)) )))))
(define (emit-byte-to-screen)
(lambda (n)
(if (char? n) (set! n (char->integer n)))
(cond ((> n 255) '(error out-of-range))
((< n 0) 'closed)
(else (if (< n 16) (display "0"))
(display (integer->hex n))
(display " ")
(set! out-pos (+ out-pos 1)) ))))
(define emit-byte (emit-byte-to-screen))
(define (emit-bytes list-of-bytes)
(map emit-byte list-of-bytes))
(define (word->bytes n)
(let ((hi (quotient n 256))
(lo (remainder n 256)))
(list lo hi)))
(define (dword->bytes n)
(let* ((hi (quotient n 16777216))
(hirest (remainder n 16777216))
(lo (quotient hirest 65536))
(lorest (remainder hirest 65536)))
(append (word->bytes lorest) (list lo hi))))
(define (emit-word n)
(emit-bytes (word->bytes n)))
(define (emit-dword n)
(emit-bytes (dword->bytes n)))
(define (org pos) (set! out-pos pos))
(define (until pos data)
(cond ((> pos out-pos)
(emit-byte data)
(until pos data))
((< pos out-pos)
'(error "pos is smaller than current pos"))
(else #t) ))
(define (assemble opcode . args)
(define registers '(al cl dl bl ah ch dh bh ax cx dx bx sp bp si di eax ecx edx ebx esp ebp esi edi))
(define (get-register-cardinality reg)
(define (loop regs count)
(if (eq? (car regs) 'eax) (set! count (- count 8)))
(cond ((eq? reg (car regs)) count)
(else (loop (cdr regs) (+ count 1)))))
(loop registers 0))
(define control-registers '(cr0 cr2 cr3))
(define segment-registers '(es cs ss ds fs gs))
(define (get-segment-register-cardinality reg)
(define (loop regs count)
(cond ((eq? reg (car regs)) count)
(else (loop (cdr regs) (+ count 1))) ))
(* 8 (loop segment-registers 0)))
(define (register? r) (memq r registers))
(define (control-register? r) (memq r control-registers))
(define (segment-register? r) (memq r segment-registers))
(define (immediate? n) (or (number? n) (char? n)))
(define (get-argument-type arg)
(cond ((immediate? arg) 'immediate)
((address? arg) 'address)
((register? arg) arg)))
(define ops (list
(cons 'mov (lambda (args)
(cond ((and (register? (car args))
(control-register? (cadr args)))
(emit-byte #x0f)
(emit-byte #x20)
(emit-byte #xc0))
((and (control-register? (car args))
(register? (cadr args)))
(emit-byte #x0f)
(emit-byte #x22)
(emit-byte #xc0))
((and (register? (car args))
(immediate? (cadr args)))
(emit-byte (+ #xb0 (get-register-cardinality (car args))))
(cond ((< (get-register-cardinality (car args)) 8) (emit-byte (cadr args)))
((< (cadr args) 65536) (emit-word (cadr args)))
(else (emit-dword (cadr args)))))
((and (segment-register? (car args))
(register? (cadr args)))
(emit-byte #x8e)
(emit-byte (+ #xc0
(get-segment-register-cardinality (car args))
(- (get-register-cardinality (cadr args)) 8) )))
(else
(display 'todo)))))
(cons 'pusha (lambda (args)
(emit-byte #x60)))
(cons 'popa (lambda (args)
(emit-byte #x61)))
(cons 'int (lambda (args)
(emit-byte #xcd)
(emit-byte (car args))))
(cons 'ret (lambda (args)
(emit-byte #xc3)))
(cons 'jmp (lambda (args)
(emit-byte #xe9)
(emit-dword (- (car args) out-pos))))
(cons 'or (lambda (args)
(cond ((and (register? (car args))
(immediate? (cadr args)))
(emit-byte #x66)
(emit-byte #x0d)
(emit-dword (cadr args)))
(else
(display 'todo)))))))
(if (assq opcode ops)
(begin
((cdr (assq opcode ops)) args))))
(define-syntax asm
(syntax-rules ()
((_ (opcode . args) ...)
(begin (apply assemble (cons (quote opcode) (quote args))) ...) )))
(define (protected-mode)
(asm
(mov eax cr0) '(0f 20 c0)
(or eax 1) '(66 0d 01 00 00 00)
(mov cr0 eax) '(0f 22 c0)
(jmp #x01000000))) '(e9 fb 4b 84)
(define (clear-screen)
(asm
(pusha) '(60)
(mov ax #x600) '("Scroll up window") '(b8 00 60)
(mov cx 0) '("Upper left corner") '(b9 00 00)
(mov dx #x184f) '("Lower right corner") '(ba 4f 18)
(mov bh 7) '("Normal attributes") '(b7 07)
(int #x10) '(cd 10)
(mov ah 2) '("Locate cursor at 0,0") '(b4 02)
(mov bh 0) '("Video page 0") '(b7 00)
(mov dx 0) '("Row 0, Col 0") '(ba 00 00)
(int #x10) '(cd 10)
(popa) '(61) '(c3)
(ret)))
(define (write-bang)
(asm
(mov ah #xe)
(mov al #\!)
(int #x10)))
(define (bootloader)
(write-bang)
(asm
(mov ah 2) '(read sectors from drive)
(mov al 1) '(sector count)
(mov ch 0) '(track, cylinder)
(mov dh 0) '(head)
(mov cl 1) '(sector)
(mov dl #x80) '(hd0)
(mov bx #x0100)
(mov es bx) '(8e c3)
(mov bx 0)
(int #x13)))
(define (stageone)
(asm
(org #x01000000)
(mov ah #xe)
(mov al #\1)
(int #x10)))
(define (make-mbr)
(org #x7bb400)
(bootloader)
(protected-mode)
(until (+ #x7bb400 #x1b8) 64)
(until (+ #x7bb400 #x1bc) 65)
(until (+ #x7bb400 #x1be) 0)
(until (+ #x7bb400 #x1fe) 255) '(partition table)
(emit-byte #x55) (emit-byte #xaa) '(MBR signature))
(make-mbr)
(stageone)
(emit-byte -1) '(close file)
(newline)
| true |
4c88c76ada7d67b1402e7e83953831a817b28d9b | d074b9a2169d667227f0642c76d332c6d517f1ba | /sicp/ch_3/exercise.3.30.scm | bf6e417e21d77ff8074db458a5611c2fd42aef08 | []
| 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 | 3,886 | scm | exercise.3.30.scm | #lang racket/base
(require "../lib/queue.scm")
(require "../lib/circuits.scm")
(require "../lib/test.rkt")
(require (only-in srfi/1 fold))
;;; Exercise 3.30
;; *Note Figure 3-27:: shows a "ripple-carry adder"
;; formed by stringing together n full-adders. This is the simplest
;; form of parallel adder for adding two n-bit binary numbers. The
;; inputs A_1, A_2, A_3, ..., A_n and B_1, B_2, B_3, ..., B_n are the
;; two binary numbers to be added (each A_k and B_k is a 0 or a 1).
;; The circuit generates S_1, S_2, S_3, ..., S_n, the n bits of the
;; sum, and C, the carry from the addition. Write a procedure
;; `ripple-carry-adder' that generates this circuit. The procedure
;; should take as arguments three lists of n wires each--the A_k, the
;; B_k, and the S_k--and also another wire C. The major drawback of
;; the ripple-carry adder is the need to wait for the carry signals
;; to propagate.
;;
;; *Figure 3.27:* A ripple-carry adder for n-bit numbers.
;;
;; : : :
;; : A_1 B_1 C_1 A_2 B_2 C_2 A_3 B_3 C_3: : A_n B_n C_n=0
;; : | | +---+ | | +---+ | | +----- : | | +-
;; | | | | | | | | | | | | : : | | |
;; : ++---+---++ | ++---+---++ | ++---+---++ : : ++---+---++
;; : | FA | | | FA | | | FA | : : | FA |
;; : +--+---+--+ | +--+---+--+ | +--+---+--+ : : +--+---+--+
;; : | | | | | | | | : : | |
;; C ------+ | +-----+ | +-----+ | : ------+ |
;; : | C_1 | C_2 | : :C_(n-1) |
;; : | | | : : |
;; S_1 S_2 S_3 S_n
;; in ruby:
;;
;; a_s.zip(b_s, s_s).inject(c) { |c_in, (a, b, s)|
;; c_out = make_wire
;; full_adder(a, b, c_in, s, c_out)
;; c_out
;; }
(define (ripple-carry-adder a-s b-s s-s c)
(fold (lambda (a b s c-in)
(let ((c-out (make-wire)))
(full-adder a c-in b s c-out)
c-out))
c a-s b-s s-s))
;; What is the delay needed to obtain the complete output from an
;; n-bit ripple-carry adder, expressed in terms of the delays for
;; and-gates, or-gates, and inverters?
;; A: full adder cost is 2 * half adder + or
;; half adder is (max and or) + not + and
;; so ripple would be: n * (2 * ((max and or) + not + and) + or)
;; or 2n * (max and or) + 2n * not + 2n * and + n * or
(test-group "3.3.0"
(define a1 (make-wire))
(define a2 (make-wire))
(define b1 (make-wire))
(define b2 (make-wire))
(define s1 (make-wire))
(define s2 (make-wire))
(define c (make-wire))
(define A (list a1 a2))
(define B (list b1 b2))
(define S (list s1 s2))
(set-signal! (ripple-carry-adder A B S c) 0)
(test-group "01 + 00 = 001"
(set-signal! a1 1)
(propagate)
(test 1 (get-signal s1))
(test 0 (get-signal s2))
(test 0 (get-signal c)))
(test-group "11 + 00 = 011"
(set-signal! a2 1)
(propagate)
(test 1 (get-signal s1))
(test 1 (get-signal s2))
(test 0 (get-signal c)))
(test-group "11 + 11 = 110"
(set-signal! b1 1)
(set-signal! b2 1)
(propagate)
(test 0 (get-signal s1))
(test 1 (get-signal s2))
(test 1 (get-signal c))))
| false |
a5a93ff8fd10c655755584a728a5df75f12c6e8e | 648776d3a0d9a8ca036acaf6f2f7a60dcdb45877 | /queries/rust/highlights.scm | 82fb966f7955ab9eb3129f368b140c115c80929a | [
"Apache-2.0"
]
| permissive | nvim-treesitter/nvim-treesitter | 4c3c55cbe6ff73debcfaecb9b7a0d42d984be3e6 | f8c2825220bff70919b527ee68fe44e7b1dae4b2 | refs/heads/master | 2023-08-31T20:04:23.790698 | 2023-08-31T09:28:16 | 2023-08-31T18:19:23 | 256,786,531 | 7,890 | 980 | Apache-2.0 | 2023-09-14T18:07:03 | 2020-04-18T15:24:10 | Scheme | UTF-8 | Scheme | false | false | 6,702 | scm | highlights.scm | ; Forked from https://github.com/tree-sitter/tree-sitter-rust
; Copyright (c) 2017 Maxim Sokolov
; Licensed under the MIT license.
; Identifier conventions
(identifier) @variable
((identifier) @type
(#lua-match? @type "^[A-Z]"))
(const_item
name: (identifier) @constant)
; Assume all-caps names are constants
((identifier) @constant
(#lua-match? @constant "^[A-Z][A-Z%d_]*$"))
; Other identifiers
(type_identifier) @type
(primitive_type) @type.builtin
(field_identifier) @field
(shorthand_field_initializer (identifier) @field)
(mod_item
name: (identifier) @namespace)
(self) @variable.builtin
(loop_label ["'" (identifier)] @label)
; Function definitions
(function_item (identifier) @function)
(function_signature_item (identifier) @function)
(parameter (identifier) @parameter)
(closure_parameters (_) @parameter)
; Function calls
(call_expression
function: (identifier) @function.call)
(call_expression
function: (scoped_identifier
(identifier) @function.call .))
(call_expression
function: (field_expression
field: (field_identifier) @function.call))
(generic_function
function: (identifier) @function.call)
(generic_function
function: (scoped_identifier
name: (identifier) @function.call))
(generic_function
function: (field_expression
field: (field_identifier) @function.call))
; Assume other uppercase names are enum constructors
((field_identifier) @constant
(#lua-match? @constant "^[A-Z]"))
(enum_variant
name: (identifier) @constant)
; Assume that uppercase names in paths are types
(scoped_identifier
path: (identifier) @namespace)
(scoped_identifier
(scoped_identifier
name: (identifier) @namespace))
(scoped_type_identifier
path: (identifier) @namespace)
(scoped_type_identifier
path: (identifier) @type
(#lua-match? @type "^[A-Z]"))
(scoped_type_identifier
(scoped_identifier
name: (identifier) @namespace))
((scoped_identifier
path: (identifier) @type)
(#lua-match? @type "^[A-Z]"))
((scoped_identifier
name: (identifier) @type)
(#lua-match? @type "^[A-Z]"))
((scoped_identifier
name: (identifier) @constant)
(#lua-match? @constant "^[A-Z][A-Z%d_]*$"))
((scoped_identifier
path: (identifier) @type
name: (identifier) @constant)
(#lua-match? @type "^[A-Z]")
(#lua-match? @constant "^[A-Z]"))
((scoped_type_identifier
path: (identifier) @type
name: (type_identifier) @constant)
(#lua-match? @type "^[A-Z]")
(#lua-match? @constant "^[A-Z]"))
[
(crate)
(super)
] @namespace
(scoped_use_list
path: (identifier) @namespace)
(scoped_use_list
path: (scoped_identifier
(identifier) @namespace))
(use_list (scoped_identifier (identifier) @namespace . (_)))
(use_list (identifier) @type (#lua-match? @type "^[A-Z]"))
(use_as_clause alias: (identifier) @type (#lua-match? @type "^[A-Z]"))
; Correct enum constructors
(call_expression
function: (scoped_identifier
"::"
name: (identifier) @constant)
(#lua-match? @constant "^[A-Z]"))
; Assume uppercase names in a match arm are constants.
((match_arm
pattern: (match_pattern (identifier) @constant))
(#lua-match? @constant "^[A-Z]"))
((match_arm
pattern: (match_pattern
(scoped_identifier
name: (identifier) @constant)))
(#lua-match? @constant "^[A-Z]"))
((identifier) @constant.builtin
(#any-of? @constant.builtin "Some" "None" "Ok" "Err"))
; Macro definitions
"$" @function.macro
(metavariable) @function.macro
(macro_definition "macro_rules!" @function.macro)
; Attribute macros
(attribute_item (attribute (identifier) @function.macro))
(attribute (scoped_identifier (identifier) @function.macro .))
; Derive macros (assume all arguments are types)
; (attribute
; (identifier) @_name
; arguments: (attribute (attribute (identifier) @type))
; (#eq? @_name "derive"))
; Function-like macros
(macro_invocation
macro: (identifier) @function.macro)
(macro_invocation
macro: (scoped_identifier
(identifier) @function.macro .))
; Literals
[
(line_comment)
(block_comment)
] @comment @spell
((line_comment) @comment.documentation
(#lua-match? @comment.documentation "^///[^/]"))
((line_comment) @comment.documentation
(#lua-match? @comment.documentation "^///$"))
((line_comment) @comment.documentation
(#lua-match? @comment.documentation "^//!"))
((block_comment) @comment.documentation
(#lua-match? @comment.documentation "^/[*][*][^*].*[*]/$"))
((block_comment) @comment.documentation
(#lua-match? @comment.documentation "^/[*][!]"))
(boolean_literal) @boolean
(integer_literal) @number
(float_literal) @float
[
(raw_string_literal)
(string_literal)
] @string
(escape_sequence) @string.escape
(char_literal) @character
; Keywords
[
"use"
"mod"
] @include
(use_as_clause "as" @include)
[
"default"
"enum"
"impl"
"let"
"move"
"pub"
"struct"
"trait"
"type"
"union"
"unsafe"
"where"
] @keyword
[
"async"
"await"
] @keyword.coroutine
[
"ref"
(mutable_specifier)
] @type.qualifier
[
"const"
"static"
"dyn"
"extern"
] @storageclass
(lifetime ["'" (identifier)] @storageclass.lifetime)
"fn" @keyword.function
[
"return"
"yield"
] @keyword.return
(type_cast_expression "as" @keyword.operator)
(qualified_type "as" @keyword.operator)
(use_list (self) @namespace)
(scoped_use_list (self) @namespace)
(scoped_identifier [(crate) (super) (self)] @namespace)
(visibility_modifier [(crate) (super) (self)] @namespace)
[
"if"
"else"
"match"
] @conditional
[
"break"
"continue"
"in"
"loop"
"while"
] @repeat
"for" @keyword
(for_expression "for" @repeat)
; Operators
[
"!"
"!="
"%"
"%="
"&"
"&&"
"&="
"*"
"*="
"+"
"+="
"-"
"-="
".."
"..="
"/"
"/="
"<"
"<<"
"<<="
"<="
"="
"=="
">"
">="
">>"
">>="
"?"
"@"
"^"
"^="
"|"
"|="
"||"
] @operator
; Punctuation
["(" ")" "[" "]" "{" "}"] @punctuation.bracket
(closure_parameters "|" @punctuation.bracket)
(type_arguments ["<" ">"] @punctuation.bracket)
(type_parameters ["<" ">"] @punctuation.bracket)
(bracketed_type ["<" ">"] @punctuation.bracket)
(for_lifetimes ["<" ">"] @punctuation.bracket)
["," "." ":" "::" ";" "->" "=>"] @punctuation.delimiter
(attribute_item "#" @punctuation.special)
(inner_attribute_item ["!" "#"] @punctuation.special)
(macro_invocation "!" @function.macro)
(empty_type "!" @type.builtin)
(macro_invocation
macro: (identifier) @exception
"!" @exception
(#eq? @exception "panic"))
(macro_invocation
macro: (identifier) @exception
"!" @exception
(#contains? @exception "assert"))
(macro_invocation
macro: (identifier) @debug
"!" @debug
(#eq? @debug "dbg"))
| false |
e61ba81bbfb4db34ff0cd8d3ad057af6612a7946 | a2c4df92ef1d8877d7476ee40a73f8b3da08cf81 | /ch19-2.scm | 0342624a8e6e3ff21390e1c9ab66ec534b7bab56 | []
| no_license | naoyat/reading-paip | 959d0ec42b86bc01fe81dcc3589e3182e92a05d9 | 739fde75073af36567fcbdf3ee97e221b0f87c8a | refs/heads/master | 2020-05-20T04:56:17.375890 | 2009-04-21T20:01:01 | 2009-04-21T20:01:01 | 176,530 | 1 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 844 | scm | ch19-2.scm | (require "./ch19-1")
(define *grammar4*
'((S -> (NP VP))
(NP -> (D N))
(NP -> (D A+ N))
(NP -> (NP PP))
(NP -> (Pro))
(NP -> (Name))
(VP -> (V NP))
(VP -> (V))
(VP -> (VP PP))
(PP -> (P NP))
(A+ -> (A))
(A+ -> (A A+))
(Pro -> I) (Pro -> you) (Pro -> he) (Pro -> she)
(Pro -> it) (Pro -> me) (Pro -> him) (Pro -> her)
(Name -> John) (Name -> Mary)
(A -> big) (A -> little) (A -> old) (A -> young)
(A -> blue) (A -> green) (A -> orange) (A -> perspicuous)
(D -> the) (D -> a) (D -> an)
(N -> man) (N -> ball) (N -> woman) (N -> table) (N -> orange)
(N -> saw) (N -> saws) (N -> noun) (N -> verb)
(P -> with) (P -> for) (P -> at) (P -> on) (P -> by) (P -> of) (P -> in)
(V -> hit) (V -> took) (V -> saw) (V -> liked) (V -> saws)))
(set! *grammar* *grammar4*)
| false |
e730259ad6e1a0e3fcb0abb823a60b9b3a5be151 | dd4cc30a2e4368c0d350ced7218295819e102fba | /vendored_parsers/tree-sitter-typescript/queries/tags.scm | ccae934e715937a053ec317b133a1e57237de5ae | [
"MIT",
"LicenseRef-scancode-unknown-license-reference",
"Apache-2.0"
]
| permissive | Wilfred/difftastic | 49c87b4feea6ef1b5ab97abdfa823aff6aa7f354 | a4ee2cf99e760562c3ffbd016a996ff50ef99442 | refs/heads/master | 2023-08-28T17:28:55.097192 | 2023-08-27T04:41:41 | 2023-08-27T04:41:41 | 162,276,894 | 14,748 | 287 | MIT | 2023-08-26T15:44:44 | 2018-12-18T11:19:45 | Rust | UTF-8 | Scheme | false | false | 573 | scm | tags.scm | (function_signature
name: (identifier) @name) @definition.function
(method_signature
name: (property_identifier) @name) @definition.method
(abstract_method_signature
name: (property_identifier) @name) @definition.method
(abstract_class_declaration
name: (type_identifier) @name) @definition.class
(module
name: (identifier) @name) @definition.module
(interface_declaration
name: (type_identifier) @name) @definition.interface
(type_annotation
(type_identifier) @name) @reference.type
(new_expression
constructor: (identifier) @name) @reference.class
| false |
3ffe8cb5574121c42b8f9411883c0568ae23fba6 | fae4190f90ada065bc9e5fe64aab0549d4d4638a | /pre-effect/tests/batched-queue.scm | d660ed961b545a5dfbe00f251a65c987116e919b | []
| 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 | 3,164 | scm | batched-queue.scm | #reader (planet "typed-reader.ss" ("plt" "typed-scheme.plt"))
(module batched-queue (planet "typed-scheme.ss" ("plt" "typed-scheme.plt"))
;; CHANGES
;; added annotations on all bound variables and structs
;; require typed foldl
;; made empty into a nullary function
;; added annotations on empty lists
;; added annotation on use of polymorphic functions in higher-order contexts
;; fixme -- how do we require polymorphic functions?
#;(require (only (lib "list.ss") foldl))
(require (only "typed-list.ss" foldl))
(define-typed-struct (a) queue ([front : (list-of a)] [rear : (list-of a)]))
; Invariants
; 1. q empty <=> (null? (queue-front q))
; 2. elements of q = (append (queue-front q) (reverse (queue-rear q)))
;; fixme -- shouldn't have to be a function
(pdefine: (a) (empty) : (queue a) (make-queue #{'() : (list-of a)} #{'() : (list-of a)}))
(pdefine: (a) (empty? [q : (queue a)]) : boolean
(null? (queue-front q)))
(pdefine: (a) (insert-last [x : a] [q : (queue a)]) : (queue a)
(let ([front (queue-front q)])
(if (null? front)
(make-queue #{(cons x front) :: (Listof a)} #{'() :: (Listof a)})
(make-queue #{front :: (Listof a)} #{(cons x (queue-rear q)) :: (Listof a)}))))
(define: insert : (All (a) (a (queue a) -> (queue a))) insert-last)
(pdefine: (a) (insert* [xs : (list-of a)] [q : (queue a)]) : (queue a)
;; fixme - annoying annotation
(foldl #{insert :: (a (queue a) -> (queue a))} q xs))
(pdefine: (a) (remove-first [q : (queue a)]) : (queue a)
(let ([front (queue-front q)])
(if (null? front)
(error 'remove-first "can't remove element from empty queue; given " q)
(if (null? (cdr front))
(make-queue (reverse (queue-rear q)) #{'() : (list-of a)})
(make-queue #{(cdr front) :: (Listof a)} (queue-rear q))))))
(pdefine: (a) (first+remove [q : (queue a)]) : (values a (queue a))
(let ([front (queue-front q)])
(if (null? front)
(error 'remove-first "can't remove element from empty queue; given " q)
(values (car front)
(if (null? (cdr front))
(make-queue (reverse (queue-rear q)) #{'() : (list-of a)})
(make-queue #{(cdr front) :: (Listof a)} (queue-rear q)))))))
(define: remove : (All (a) ((queue a) -> (queue a))) remove-first)
(pdefine: (a) (first [q : (queue a)]) : a
(if (empty? q)
(error 'first "There is no first element in an empty queue; given " q))
(car (queue-front q)))
(pdefine: (a) (elements: [q : (queue a)]) : (list-of a)
(append (queue-front q)
(reverse (queue-rear q))))
(pdefine: (a b) (fold [f : (a b -> b)] [init : b] [q : (queue a)]) : b
(foldl f
(foldl f init (queue-front q))
(reverse (queue-rear q))))
(pdefine: (a) (size [q : (queue a)]) : number
; NOTE: T(size) = O(n)
(+ (length (queue-front q))
(length (queue-rear q))))
;; 12 definitions checked
;; generators removed
;; TESTS
(= 0 (size (empty)))
) | false |
65a23d580755108eed76e95fb35602aa2dcbebb2 | 11f8c62565512010ec8bd59d929a35063be7bb2a | /compiler/src/test/scheme/functional/SampleProgramSuite.scm | e51d5caa9e716a3e73fb403d7e79cb9807e19021 | [
"Apache-2.0"
]
| permissive | etaoins/llambda | 97b986e40d8aa6871a5ab1946b53c2898313776b | a2a5c212ebb56701fa28649c377d0ddd8b67da0b | refs/heads/master | 2020-05-26T18:43:11.776115 | 2018-01-03T07:40:49 | 2018-01-03T07:40:49 | 9,960,891 | 71 | 7 | null | null | null | null | UTF-8 | Scheme | false | false | 10,672 | scm | SampleProgramSuite.scm | ; Taken from R7RS
(define-test "R7RS factorial" (expect 479001600
#|
The FACT procedure computes the factorial
of a non-negative integer.
|#
(define fact
(lambda (n)
(if (= n 0)
#;(= n 1)
1 ;Base case: return 1
(* n (fact (- n 1))))))
(fact 12)))
; Taken from http://rosettacode.org/wiki/Sieve_of_Eratosthenes#Scheme
(define-test "simple sieve of Eratosthenes" (expect (2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97)
(import (llambda flonum))
(define (iota start stop stride)
(if (> start stop)
(list)
(cons start (iota (+ start stride) stop stride))))
(define (strike lst start stride)
(cond ((null? lst) lst)
((= (car lst) start) (strike (cdr lst) (+ start stride) stride))
((> (car lst) start) (strike lst (+ start stride) stride))
(else (cons (car lst) (strike (cdr lst) start stride)))))
(define (primes limit)
(let ((stop (sqrt limit)))
(define (sieve lst)
(let ((p (car lst)))
(if (> p stop)
lst
(cons p (sieve (strike (cdr lst) (* p p) p))))))
(sieve (iota 2 limit 1))))
(primes 100)))
(define-test "wheel-of-2 sieve of Eratosthenes" (expect (2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97)
(import (llambda flonum))
(define (iota start stop stride)
(if (> start stop)
(list)
(cons start (iota (+ start stride) stop stride))))
(define (strike lst start stride)
(cond ((null? lst) lst)
((= (car lst) start) (strike (cdr lst) (+ start stride) stride))
((> (car lst) start) (strike lst (+ start stride) stride))
(else (cons (car lst) (strike (cdr lst) start stride)))))
(define (primes-wheel-2 limit)
(let ((stop (sqrt limit)))
(define (sieve lst)
(let ((p (car lst)))
(if (> p stop)
lst
(cons p (sieve (strike (cdr lst) (* p p) (* 2 p)))))))
(cons 2 (sieve (iota 3 limit 2)))))
(primes-wheel-2 100)))
; Taken from http://rosettacode.org/wiki/Sieve_of_Eratosthenes#Scheme
(define-test "vector sieve of Eratosthenes" (expect (2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97)
(import (llambda flonum))
; initialize v to vector of sequential integers
(define (initialize! v)
(define (iter v n) (if (>= n (vector-length v))
#!unit
(begin (vector-set! v n n) (iter v (+ n 1)))))
(iter v 0))
; set every nth element of vector v to 0,
; starting with element m
(define (strike! v m n)
(cond ((>= m (vector-length v)) #!unit)
(else (begin
(vector-set! v m 0)
(strike! v (+ m n) n)))))
; lowest non-zero index of vector v >= n
(define (nextprime v n)
(if (zero? (vector-ref v n))
(nextprime v (+ n 1))
(vector-ref v n)))
; remove elements satisfying pred? from list lst
(define (remove pred? lst)
(cond
((null? lst) '())
((pred? (car lst))(remove pred? (cdr lst)))
(else (cons (car lst) (remove pred? (cdr lst))))))
; the sieve itself
(define (sieve n)
(define stop (sqrt n))
(define (iter v p)
(cond
((> p stop) v)
(else
(begin
(strike! v (* p p) p)
(iter v (nextprime v (+ p 1)))))))
(let ((v (make-vector (+ n 1))))
(initialize! v)
(vector-set! v 1 0) ; 1 is not a prime
(remove zero? (vector->list (iter v 2)))))
(sieve 100)))
; Taken from http://rosettacode.org/wiki/Sieve_of_Eratosthenes#Scheme
(define-test "stream sieve of Eratosthenes" (expect (13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97)
;;;; Stream Implementation
(define (head s) (car s))
(define (tail s) ((cdr s)))
(define-syntax s-cons
(syntax-rules () ((s-cons h t) (cons h (lambda () t)))))
;;;; Stream Utility Functions
(define (from-By x s)
(s-cons x (from-By (+ x s) s)))
(define (take n s)
(cond
((> n 1) (cons (head s) (take (- n 1) (tail s))))
((= n 1) (list (head s))) ;; don't force it too soon!!
(else '()))) ;; so (take 4 (s-map / (from-By 4 -1))) works
(define (drop n s)
(cond
((> n 0) (drop (- n 1) (tail s)))
(else s)))
(define (s-map f s)
(s-cons (f (head s)) (s-map f (tail s))))
(define (s-diff s1 s2)
(let ((h1 (head s1)) (h2 (head s2)))
(cond
((< h1 h2) (s-cons h1 (s-diff (tail s1) s2 )))
((< h2 h1) (s-diff s1 (tail s2)))
(else (s-diff (tail s1) (tail s2))))))
(define (s-union s1 s2)
(let ((h1 (head s1)) (h2 (head s2)))
(cond
((< h1 h2) (s-cons h1 (s-union (tail s1) s2 )))
((< h2 h1) (s-cons h2 (s-union s1 (tail s2))))
(else (s-cons h1 (s-union (tail s1) (tail s2)))))))
;;;; join an ordered stream of streams (here, of primes' multiples)
;;;; into one ordered stream, via an infinite right-deepening tree
(define (s-tree-join sts) ;; sts -> s
(define (join-With of-Tail sts) ;; sts -> s
(s-cons (head (head sts))
(s-union (tail (head sts)) (of-Tail (tail sts)))))
(define (pairs sts) ;; sts -> sts
(s-cons (join-With head sts) (pairs (tail (tail sts)))))
(join-With (lambda (t) (s-tree-join (pairs t))) sts))
;;;; all primes' multiples are removed, merged through a tree of unions
;;;; runs in ~ n^1.15 run time in producing n = 100K .. 1M primes
(define (primes-stream)
(define (mults p) (from-By (* p p) (* 2 p)))
(define (no-mults-From from)
(s-diff (from-By from 2)
(s-tree-join (s-map mults odd-primes))))
(define odd-primes
(s-cons 3 (no-mults-From 5)))
(s-cons 2 (no-mults-From 3)))
(take 20 (drop 5 (primes-stream)))))
; Based on http://rosettacode.org/wiki/Factors_of_an_integer#Scheme
(define-test "integer factorization" (expect (1 239 4649 1111111)
(import (llambda typed))
(: factors (-> <integer> <list-element>))
(define (factors n)
(: *factors (-> <integer> <list-element>))
(define (*factors d)
(cond ((> d n) (list))
((= (truncate-remainder n d) 0) (cons d (*factors (+ d 1))))
(else (*factors (+ d 1)))))
(*factors 1))
(factors 1111111)))
; Taken from http://rosettacode.org/wiki/Fibonacci_sequence#Scheme
(define-test "iterative fibonacci" (expect 144
(define (fib-iter n)
(do ((num 2 (+ num 1))
(fib-prev 1 fib)
(fib 1 (+ fib fib-prev)))
((>= num n) fib)))
(fib-iter 12)))
; Based on http://rosettacode.org/wiki/Fibonacci_sequence#Scheme
(define-test "recursive fibonacci" (expect 144
(import (llambda typed))
(: fib-rec (-> <integer> <integer>))
(define (fib-rec n)
(if (< n 2)
n
(+ (fib-rec (- n 1))
(fib-rec (- n 2)))))
(fib-rec 12)))
; Based on http://rosettacode.org/wiki/Fibonacci_sequence#Scheme
(define-test "Dijkstra fibonacci" (expect 144
(import (llambda typed))
(: fib (-> <integer> <integer>))
(define (fib n)
(: fib-aux (-> <integer> <integer> <integer> <integer> <integer> <integer>))
(define (fib-aux a b p q count)
(cond ((= count 0) b)
((even? count)
(fib-aux a
b
(+ (* p p) (* q q))
(+ (* q q) (* 2 p q))
(integer (/ count 2))))
(else
(fib-aux (+ (* b q) (* a q) (* a p))
(+ (* b p) (* a q))
p
q
(- count 1)))))
(fib-aux 1 0 0 1 n))
(fib 12)))
; Taken from http://rosettacode.org/wiki/Flatten_a_list#Scheme
(define-test "flatten a list" (expect (1 2 3 4 5 6 7 8)
(define (flatten x)
(cond ((null? x) '())
((not (pair? x)) (list x))
(else (append (flatten (car x))
(flatten (cdr x))))))
(flatten '((1) 2 ((3 4) 5) ((())) (((6))) 7 8 ()))))
; Taken from http://rosettacode.org/wiki/Longest_increasing_subsequence#Scheme
(define-test "patience sorting" (expect-success
(define (lis less? lst)
(define pile-tops (make-vector (length lst)))
(define (bsearch-piles x len)
(let aux ((lo 0)
(hi (- len 1)))
(if (> lo hi)
lo
(let ((mid (truncate-quotient (+ lo hi) 2)))
(if (less? (car (vector-ref pile-tops mid)) x)
(aux (+ mid 1) hi)
(aux lo (- mid 1)))))))
(let aux ((len 0)
(lst lst))
(if (null? lst)
(reverse (vector-ref pile-tops (- len 1)))
(let* ((x (car lst))
(i (bsearch-piles x len)))
(vector-set! pile-tops i (cons x (if (= i 0)
'()
(vector-ref pile-tops (- i 1)))))
(aux (if (= i len) (+ len 1) len) (cdr lst))))))
(assert-equal '(2 4 5) (lis < '(3 2 6 4 5 1)))
(assert-equal '(0 2 6 9 11 15) (lis < '(0 8 4 12 2 10 6 14 1 9 5 13 3 11 7 15)))))
; Based on http://rosettacode.org/wiki/Levenshtein_distance#SchemeGG
(define-test "levenshtein distance" (expect 3
(import (llambda typed))
(: levenshtein (-> <string> <string> <integer>))
(define (levenshtein s t)
(: %levenshtein (-> (Listof <char>) <integer> (Listof <char>) <integer> <integer>))
(define (%levenshtein s sl t tl)
(cond ((zero? sl) tl)
((zero? tl) sl)
(else
(min (+ (%levenshtein (cdr s) (- sl 1) t tl) 1)
(+ (%levenshtein s sl (cdr t) (- tl 1)) 1)
(+ (%levenshtein (cdr s) (- sl 1) (cdr t) (- tl 1))
(if (char=? (car s) (car t)) 0 1))))))
(%levenshtein (string->list s)
(string-length s)
(string->list t)
(string-length t)))
(levenshtein "kitten" "sitting")))
; Taken from http://rosettacode.org/wiki/Permutations#Scheme
(define-test "permutations" (expect ((1 2 3) (1 3 2) (2 1 3) (2 3 1) (3 2 1) (3 1 2))
(define (perm s)
(cond ((null? s) '())
((null? (cdr s)) (list s))
(else ;; extract each item in list in turn and perm the rest
(let splice ((l '()) (m (car s)) (r (cdr s)))
(append
(map (lambda (x) (cons m x)) (perm (append l r)))
(if (null? r) '()
(splice (cons m l) (car r) (cdr r))))))))
(perm '(1 2 3))))
| true |
1982a6f882d6d0f998c7c91cc0e759901a444bad | d92f46cb360af3e0bdbdcaca6046842899673619 | /test-scripts/close-define.scm | 2e396c63b633ce757a2ffb8bf39540adfc34b1cc | []
| no_license | martlin2cz/heroc | d8702313bccbcc33a499d16aaeda590f2ec4f54e | ef1168536283714f6168200996c41b59badcbe44 | refs/heads/master | 2021-01-17T19:21:27.773035 | 2016-08-05T22:47:56 | 2016-08-05T22:47:56 | 57,255,099 | 0 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 110 | scm | close-define.scm | ;;;;;;;;;;;;;;;;;
;;
;; define-program.scm goes here
;; and here the generated stackode
)
;;;;;;;;;;;;;;;;;
| false |
2e8072578d01296e21a1c3639e8ef1e7a05ff5fa | b0c0c6f6475346de069454ce893efb83d31e66cd | /scripts/moon-bugs/example3.ss | 85cd1eeb5cd767c62ee321db646e6c4a8894b8cc | [
"LicenseRef-scancode-scintilla",
"MIT",
"Apache-2.0",
"BSD-2-Clause"
]
| permissive | linatude/scheme-windows-tiled-shell | dbd08f5deb91469ac603d3922dad8d195254ee41 | de08f77f08acea5808010b45921a2ea9f710f799 | refs/heads/main | 2023-05-04T20:55:48.702456 | 2021-05-23T13:18:07 | 2021-05-23T13:18:07 | 367,598,668 | 0 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 5,014 | ss | example3.ss | ;; moon-bugs - example 3
;; example 3 - enemy list - render mode 2
(define frames 0)
(define h-x 400.0)
(define h-xn 0.0 )
(define enemies '())
(define missiles '())
(define hits '())
(define load-all-sprites
(lambda ()
(load-sprites "images/bg1.jpg" 0)
(load-sprites "images/h1.png" 1)
(load-sprites "images/laser-18.png" 18)
(load-sprites "images/D-14.png" 20)
(load-sprites "images/D-16.png" 21)
(load-sprites "images/C-14.png" 22)
(load-sprites "images/D-01.png" 23) ))
(define clear-scene
(lambda ()
(add-clear-image 0.0 0.0 0.0 1.0)
(add-draw-sprite 0 0.0 10.0 )))
(define new-enemy
(lambda (x y xn yn s)
(list (list (list x y) (list xn yn) s))))
(define enemy-wave-one
(lambda ()
(for y from -840.0 to -3800.0 step -840.0
(set! enemies
(append enemies
(new-enemy 330.0 y 0.0 0.8 23))) )
(for y from 0.0 to -3850.0 step -124.0
(set! enemies
(append enemies
(new-enemy 20.0 y 0.0 0.8 20)))
(set! enemies
(append enemies
(new-enemy 120.0 y 0.0 0.9 21)))
(set! enemies
(append enemies
(new-enemy 220.0 y 0.0 0.8 22)))
(set! enemies
(append enemies
(new-enemy 530.0 y 0.0 0.8 22)))
(set! enemies
(append enemies
(new-enemy 630.0 y 0.0 0.9 21)))
(set! enemies
(append enemies
(new-enemy 730.0 y 0.0 0.8 20))) )))
(define new-missile
(lambda (x y)
(list (list x y))))
(define fire-missiles
(lambda ()
(set! missiles
(append missiles (new-missile (+ h-x 05.0) 510.0)))
(set! missiles
(append missiles (new-missile (+ h-x 35.0) 510.0)))))
(define draw-missiles
(lambda ()
(map
(lambda (m)
(add-draw-sprite 18 (car m) (cadr m)))
missiles)))
(define clean-missiles
(lambda ()
(set! missiles
(filter (lambda (a) (< -100 (cadr a))) missiles))))
(define move-missiles
(lambda ()
(set! missiles
(map
(lambda (m)
(list (car m) (- (cadr m) 10.0)))
missiles) )))
(define draw-invaders
(lambda ()
(map (lambda (e)
(apply
add-scaled-rotated-sprite
(list (caddr e) (caar e) (cadar e) 0.0 0.45)))
enemies)))
(define move-enemy
(lambda (e)
(let* ([xy (car e)]
[xn (cadr e)]
[newxy (map (lambda (x y) (+ x y)) xy xn)]
[s (caddr e)])
(list newxy xn s))))
(define move-enemies
(lambda ()
(set! enemies
(map (lambda (e)
(move-enemy e)) enemies))))
(define clean-enemies
(lambda ()
(set! enemies
(filter (lambda (a) (> 1200.0 (caar a))) enemies ))))
(define collisions
(lambda ()
(when (and (> (length missiles) 0) (> (length enemies)))
(set! hits
(filter
(lambda (h) (not (null? h)))
(map (lambda (m)
(filter
(lambda (e)
(and (> (+ (car m) 40.0) (caar e))
(< (- (car m) 40.0) (caar e))
(< (- (cadr m) 40.0) (cadar e))
(> (+ (cadr m) 40.0) (cadar e))))
enemies))
missiles))))))
(define draw-hits
(lambda ()
(when (> (length hits) 0)
(add-line-colour 1.0 0.0 1.0 0.4)
(add-pen-width 2.5)
(map
(lambda (e)
(when (and (not (null? e))
(not (null? (caaar e)))
(not (null? (cadaar e))))
(add-draw-ellipse
(+ 20 (caaar e)) (+ 20(cadaar e))
40.0 40.0))) hits))))
(define draw-hero
(lambda (x)
(add-scaled-rotated-sprite 1 x 510.0 0.0 0.65)))
(define move-hero
(lambda ()
(set! h-x (+ h-x h-xn))))
(define check-hx
(lambda ()
(when (< h-x 1.0) (set! h-x 1.0))
(when (> h-x 713.0) (set! h-x 713.0))
(when (> h-xn 0.0) (set! h-xn (- h-xn 0.2)))
(when (< h-xn 0.0) (set! h-xn (+ h-xn 0.2))
(when (< (abs h-xn) 0.4) (set! h-xn 0.0)))))
(define draw-scene
(lambda ( hx )
(clear-scene)
(draw-invaders)
(draw-missiles)
(draw-hero hx)
(draw-hits)))
(define check-keys
(lambda (keys)
(when (and (< (cdr (assq 'recent keys)) 50)
(cdr (assq 'ctrl keys))
(< (length missiles) 8))
(fire-missiles))
(when (and (< (cdr (assq 'recent keys)) 50)
(cdr (assq 'left keys)))
(set! h-xn (- h-xn 2.0)))
(when (and (< (cdr (assq 'recent keys)) 50)
(cdr (assq 'right keys)))
(set! h-xn (+ h-xn 2.0)))))
(load-all-sprites)
(enemy-wave-one)
(define game-step
(lambda ()
(set! frames (+ frames 1))
(check-keys (graphics-keys))
(check-hx)
(move-enemies)
(move-missiles)
(move-hero)
(collisions)
(clean-missiles)
(clean-enemies)
(draw-scene h-x)))
(keyboard-delay 100)
(set-every-function 1000 16 2
(lambda ()
(safely game-step)))
| false |
7d7200244c789c8d6039085c2e5c0faea5b34936 | 6c6cf6e4b77640825c2457e54052a56d5de6f4d2 | /ch3/s3_5-add-streams.scm | 4ece5c90a9d6c388d83fb07745251649965a5daa | []
| no_license | leonacwa/sicp | a469c7bc96e0c47e4658dccd7c5309350090a746 | d880b482d8027b7111678eff8d1c848e156d5374 | refs/heads/master | 2018-12-28T07:20:30.118868 | 2015-02-07T16:40:10 | 2015-02-07T16:40:10 | 11,738,761 | 0 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 85 | scm | s3_5-add-streams.scm | ;sector 3.5 stream
;add-stream
(define (add-streams s1 s2)
(stream-map + s1 s2))
| false |
9147f84c3f2ce5dafe1f42fa0527cffbd862085a | ce567bbf766df9d98dc6a5e710a77870753c7d29 | /ch5/base/scheduler.scm | a5d09c186e83e9d2bdca2fb9d8aa9fcac2b8895c | []
| no_license | dott94/eopl | 1cbe2d98c948689687f88e514579e66412236fc9 | 47fadf6f2aa6ca72c831d6e2e2eccbe673129113 | refs/heads/master | 2021-01-18T06:42:35.921839 | 2015-01-21T07:06:43 | 2015-01-21T07:06:43 | 30,055,972 | 1 | 0 | null | 2015-01-30T04:21:42 | 2015-01-30T04:21:42 | null | UTF-8 | Scheme | false | false | 1,370 | scm | scheduler.scm | (define the-ready-queue 'uninitialized)
(define the-final-answer 'uninitialized)
(define the-max-time-slice 'uninitialized)
(define the-time-remaining 'uninitialized)
;; initialize-scheduler! : Int -> Unspecified
(define initialize-scheduler!
(lambda (ticks)
(set! the-ready-queue (empty-queue))
(set! the-final-answer 'uninitialized)
(set! the-max-time-slice ticks)
(set! the-time-remaining the-max-time-slice)
))
;;;;;;;;;;;;;;;; the final answer ;;;;;;;;;;;;;;;;
;; place-on-ready-queue! : Thread -> Unspecified
(define place-on-ready-queue!
(lambda (th)
(set! the-ready-queue
(enqueue the-ready-queue th))))
;; run-next-thread : () -> FinalAnswer
(define run-next-thread
(lambda ()
(if (empty? the-ready-queue)
the-final-answer
(dequeue the-ready-queue
(lambda (first-ready-thread other-ready-threads)
(set! the-ready-queue other-ready-threads)
(set! the-time-remaining the-max-time-slice)
(first-ready-thread)
)))))
;; set-final-answer! : ExpVal -> Unspecified
(define set-final-answer!
(lambda (val)
(set! the-final-answer val)))
;; time-expired? : () -> Bool
(define time-expired?
(lambda ()
(zero? the-time-remaining)))
;; decrement-timer! : () -> Unspecified
(define decrement-timer!
(lambda ()
(set! the-time-remaining (- the-time-remaining 1))))
| false |
96cb1658a0fd60597dc09533204405ee52543301 | 0768e217ef0b48b149e5c9b87f41d772cd9917f1 | /sitelib/srfi/srfi-42.scm | 91be2f730cf90cbded7d0201e3b6a9280b9d0737 | [
"LicenseRef-scancode-unknown-license-reference",
"BSD-2-Clause"
]
| permissive | fujita-y/ypsilon | e45c897436e333cf1a1009e13bfef72c3fb3cbe9 | 62e73643a4fe87458ae100e170bf4721d7a6dd16 | refs/heads/master | 2023-09-05T00:06:06.525714 | 2023-01-25T03:56:13 | 2023-01-25T04:02:59 | 41,003,666 | 45 | 7 | BSD-2-Clause | 2022-06-25T05:44:49 | 2015-08-19T00:05:35 | Scheme | UTF-8 | Scheme | false | false | 389 | scm | srfi-42.scm | #!nobacktrace
(define-library (srfi srfi-42)
(import (srfi 42))
(export do-ec list-ec append-ec string-ec string-append-ec vector-ec vector-of-length-ec
sum-ec product-ec min-ec max-ec any?-ec every?-ec first-ec last-ec fold-ec fold3-ec
:list :string :vector :integers :range :real-range :char-range :port :dispatched :do
:let :parallel :while :until :))
| false |
6719eadba11584301604b43517400df2358b776a | 9b0c653f79bc8d0dc87526f05bdc7c9482a2e277 | /1/1-13TODO.ss | b20d653479b85cd736e2b36a631dbadfb840a057 | []
| no_license | ndNovaDev/sicp-magic | 798b0df3e1426feb24333658f2313730ae49fb11 | 9715a0d0bb1cc2215d3b0bb87c076e8cb30c4286 | refs/heads/master | 2021-05-18T00:36:57.434247 | 2020-06-04T13:19:34 | 2020-06-04T13:19:34 | 251,026,570 | 0 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 21 | ss | 1-13TODO.ss | ; TODO:完全不懂
| false |
8ee2b58d03804f35cc26ddd86c5492c6dbb26ac4 | 11f8c62565512010ec8bd59d929a35063be7bb2a | /compiler/src/test/scheme/functional/LazySuite.scm | 9c0c85e7cf130e7e83a57cfd9be5c7553cfed86a | [
"Apache-2.0"
]
| permissive | etaoins/llambda | 97b986e40d8aa6871a5ab1946b53c2898313776b | a2a5c212ebb56701fa28649c377d0ddd8b67da0b | refs/heads/master | 2020-05-26T18:43:11.776115 | 2018-01-03T07:40:49 | 2018-01-03T07:40:49 | 9,960,891 | 71 | 7 | null | null | null | null | UTF-8 | Scheme | false | false | 4,996 | scm | LazySuite.scm | (define-test "trivial immediate (force)" (expect 3
(import (llambda lazy))
(define p (delay (+ 1 2)))
(assert-true (promise? p))
(force p)))
(define-test "trivial (make-promise)" (expect 3
(import (llambda lazy))
(define p (make-promise 3))
(assert-true (promise? p))
(force p)))
(define-test "trivial (delay-force)" (expect 3
(import (llambda lazy))
(define p (delay-force (delay (+ 1 2))))
(assert-true (promise? p))
(force p)))
(define-test "(force)ing twice produces the same value" (expect (3 3)
(import (llambda lazy))
(let ((p (delay (+ 1 2))))
(list (force p) (force p)))))
(define-test "recursive promises and streaming" (expect-success
(import (llambda lazy))
(define integers
(letrec ((next
(lambda (n)
(delay (cons n (next (+ n 1)))))))
(next 0)))
(define head
(lambda (stream) (car (force stream))))
(define tail
(lambda (stream) (cdr (force stream))))
(assert-equal 2 (head (tail (tail integers))))
(define (stream-filter p? s)
(delay-force
(if (null? (force s))
(delay '())
(let ((h (car (force s)))
(t (cdr (force s))))
(if (p? h)
(delay (cons h (stream-filter p? t)))
(stream-filter p? t))))))
(assert-equal 5 (head (tail (tail (stream-filter odd? integers)))))))
(define-test "(force) only computes a value once" (expect-success
(import (llambda lazy))
(define count 0)
(define x 5)
(define p
(delay (begin (set! count (+ count 1))
(if (> count x)
count
(force p)))))
(assert-true (promise? p))
(assert-equal 6 (force p))
(assert-true (promise? p))
(assert-equal 6
(begin (set! x 10)
(force p)))))
(define-test "(llambda lazy) provides <promise> type" (expect-success
(import (llambda lazy))
(import (llambda typed))
(define p (delay (+ 1 2)))
(assert-true ((make-predicate <promise>) p))))
(define-test "SRFI-45 memoization test 1" (expect-output (hello)
(import (llambda lazy))
(import (llambda write))
(define s (delay (begin (write 'hello) 1)))
(force s)
(force s)))
(define-test "SRFI-45 memoization test 2" (expect-output (bonjour)
(import (llambda lazy))
(import (llambda write))
(let ((s (delay (begin (display 'bonjour) 2))))
(+ (force s) (force s)))))
(define-test "SRFI-45 memoization test 3" (expect-output (hi)
(import (llambda lazy))
(import (llambda write))
(define r (delay (begin (display 'hi) 1)))
(define s (delay-force r))
(define t (delay-force s))
(force t)
(force r)))
; SRFI-45 reentry test 1 is essentially the same as "(force) only computes a value once"
(define-test "SRFI-45 reentrancy test 2" (expect-success
(import (llambda lazy))
(import (llambda write))
(define f
(let ((first? #t))
(delay
(if first?
(begin
(set! first? #f)
(force f))
'second))))
(assert-equal 'second (force f))))
(define-test "SRFI-45 reentrancy test 3" (expect-success
(import (llambda lazy))
(import (llambda write))
(define q
(let ((count 5))
(define (get-count) count)
(define p (delay (if (<= count 0)
count
(begin (set! count (- count 1))
(force p)
(set! count (+ count 2))
count))))
(list get-count p)))
(define get-count (car q))
(define p (cadr q))
(assert-equal 5 (get-count))
(assert-equal 0 (force p))
(assert-equal 10 (get-count))))
(define-test "SRFI-45 example procedures" (expect-success
(import (llambda lazy))
(define-syntax match
(syntax-rules ()
((match exp
(() exp1)
((h . t) exp2))
(let ((lst exp))
(cond ((null? lst) exp1)
((pair? lst) (let ((h (car lst))
(t (cdr lst)))
exp2))
(else 'match-error))))))
(define (from n)
(delay (cons n (from (+ n 1)))))
(define (stream-filter p? s)
(delay-force (match (force s)
(() (delay '()))
((h . t) (if (p? h)
(delay (cons h (stream-filter p? t)))
(stream-filter p? t))))))
(define (stream-ref s index)
(delay-force
(match (force s)
(() 'error)
((h . t) (if (zero? index)
(delay h)
(stream-ref t (- index 1)))))))
; Check that evenness is correctly implemented - should terminate:
(assert-equal 0 (force (stream-ref (stream-filter zero? (from 0)) 0)))
(define s (stream-ref (from 0) 6))
(assert-true (promise? s))
(assert-equal 6 (force s))))
| true |
20caede8756cefb9a801416f013f3459f3810a67 | e26e24bec846e848630bf97512f8158d8040689c | /lib/chibi/log.sld | 08f7b11bcd2c3c3cc90495dcdf4d3087aa08017f | [
"BSD-3-Clause"
]
| permissive | traviscross/chibi-scheme | f989df49cb76512dc59f807aeb2426bd6fe1c553 | 97b81d31300945948bfafad8b8a7dbffdcd61ee3 | refs/heads/master | 2023-09-05T16:57:14.338631 | 2014-04-01T22:02:02 | 2014-04-01T22:02:02 | 18,473,315 | 2 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 968 | sld | log.sld |
(define-library (chibi log)
(export
;; Logger record
Logger logger?
logger-levels logger-levels-set!
logger-level-abbrevs logger-level-abbrevs-set!
logger-current-level logger-current-level-set!
logger-prefix logger-prefix-set!
logger-counts logger-counts-set!
logger-file logger-file-set!
logger-port logger-port-set!
logger-locked? logger-locked?-set!
logger-zipped? logger-zipped?-set!
;; syntax
define-logger with-logged-errors with-logged-and-reraised-errors
;; procedural interface
log-open log-close log-show log-show-every-n log-compile-prefix
;; levels introspection
log-level-index log-level-name log-level-abbrev
;; the default logger
default-logger log-emergency log-alert log-critical log-error
log-warn log-notice log-info log-debug)
(import (chibi) (srfi 9) (chibi time) (chibi process) (chibi system)
(chibi filesystem) (chibi string) (chibi show base))
(include "log.scm"))
| false |
132e62123de7d187be444f926f7f6ac21d5d5e04 | eef5f68873f7d5658c7c500846ce7752a6f45f69 | /spheres/net/sack/overload-protection.sld | f2fefe029ca95912653268239c9b74aa6aa5993c | [
"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 | 106 | sld | overload-protection.sld | (define-library (spheres/net/sack overload-protection)
(export)
(include "overload-protection.scm"))
| false |
7523f308bdca516bbc3e713f2f42c19e3c6169cd | 000dbfe5d1df2f18e29a76ea7e2a9556cff5e866 | /ext/time/sagittarius/time-util.scm | 76499fa3bbed849fd22fafb94ada96359eae920e | [
"BSD-3-Clause",
"LicenseRef-scancode-other-permissive",
"MIT",
"BSD-2-Clause"
]
| permissive | ktakashi/sagittarius-scheme | 0a6d23a9004e8775792ebe27a395366457daba81 | 285e84f7c48b65d6594ff4fbbe47a1b499c9fec0 | refs/heads/master | 2023-09-01T23:45:52.702741 | 2023-08-31T10:36:08 | 2023-08-31T10:36:08 | 41,153,733 | 48 | 7 | NOASSERTION | 2022-07-13T18:04:42 | 2015-08-21T12:07:54 | Scheme | UTF-8 | Scheme | false | false | 3,637 | scm | time-util.scm | ;;; -*- mode:scheme; coding:utf-8; -*-
;;;
;;; sagittarius/time-util.scm - common procedures between time and timezone
;;;
;;; Copyright (c) 2010-2015 Takashi Kato <[email protected]>
;;;
;;; Redistribution and use in source and binary forms, with or without
;;; modification, are permitted provided that the following conditions
;;; are met:
;;;
;;; 1. Redistributions of source code must retain the above copyright
;;; notice, this list of conditions and the following disclaimer.
;;;
;;; 2. Redistributions in binary form must reproduce the above copyright
;;; notice, this list of conditions and the following disclaimer in the
;;; documentation and/or other materials provided with the distribution.
;;;
;;; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
;;; "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
;;; LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
;;; A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
;;; OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
;;; SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
;;; TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
;;; PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
;;; LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
;;; NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
;;; SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
;;;
(library (sagittarius time-util)
(export tm:time->julian-day-number
tm:decode-julian-day-number
tm:encode-julian-day-number
tm:sihd tm:sid tm:nano
tm:tai-epoch-in-jd
time-duration
time-utc
time-tai
time-monotonic
time-thread
time-process
)
(import (core) (sagittarius))
(define-constant time-duration 'time-duration)
(define-constant time-utc 'time-utc)
(define-constant time-tai 'time-tai)
(define-constant time-monotonic 'time-monotonic)
(define-constant time-thread 'time-thread)
(define-constant time-process 'time-process)
;; moved from time.scm to share with timezone.scm
(define-constant tm:sid 86400) ; seconds in a day
(define-constant tm:sihd 43200) ; seconds in a half day
;; julian day number for 'the epoch'
(define-constant tm:tai-epoch-in-jd 4881175/2)
(define-constant tm:nano (expt 10 9))
;; gives the seconds/date/month/year
(define (tm:decode-julian-day-number jdn)
(let* ((days (truncate jdn))
(a (+ days 32044))
(b (quotient (+ (* 4 a) 3) 146097))
(c (- a (quotient (* 146097 b) 4)))
(d (quotient (+ (* 4 c) 3) 1461))
(e (- c (quotient (* 1461 d) 4)))
(m (quotient (+ (* 5 e) 2) 153))
(y (+ (* 100 b) d -4800 (quotient m 10))))
(values ; seconds date month year
(* (- jdn days) tm:sid)
(+ e (- (quotient (+ (* 153 m) 2) 5)) 1)
(+ m 3 (* -12 (quotient m 10)))
(if (>= 0 y) (- y 1) y))
))
(define (tm:time->julian-day-number seconds tz-offset)
(+ (/ (+ seconds tz-offset tm:sihd) tm:sid)
tm:tai-epoch-in-jd))
(define (tm:encode-julian-day-number day month year)
(let* ((a (quotient (- 14 month) 12))
(y (- (- (+ year 4800) a) (if (negative? year) -1 0)))
(m (- (+ month (* 12 a)) 3)))
(+ day
(quotient (+ (* 153 m) 2) 5)
(* 365 y)
(quotient y 4)
(- (quotient y 100))
(quotient y 400)
-32045)))
)
| false |
3bdebaba1ae7e2e3d943acd58f2c4e64a65ffdc8 | defeada37d39bca09ef76f66f38683754c0a6aa0 | /mscorlib/system/security/cryptography/shaconstants.sls | 1cf2d0b5ac0f6c748e3b63b90e955d779de07bea | []
| 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 | 540 | sls | shaconstants.sls | (library (system security cryptography shaconstants)
(export is? shaconstants? k1 k2)
(import (ironscheme-clr-port))
(define (is? a) (clr-is System.Security.Cryptography.SHAConstants a))
(define (shaconstants? a)
(clr-is System.Security.Cryptography.SHAConstants a))
(define-field-port
k1
#f
#f
(static:)
System.Security.Cryptography.SHAConstants
K1
System.UInt32[])
(define-field-port
k2
#f
#f
(static:)
System.Security.Cryptography.SHAConstants
K2
System.UInt64[]))
| false |
d48c1b25404f6569e406f098860e6ccc62740128 | eb8a233b8800e69b2cfb69cff5db7215ef118297 | /adbmal-rules.scm | e6d20d6ebb5dafa20e9fa0a6a1422d2d4e5edc93 | []
| no_license | scheme-requests-for-implementation/srfi-182 | 42553bd669bdb635350cbadbdab2bbc422ed3258 | 9dee87f526459879271f506a72e759e1f42516bc | refs/heads/master | 2021-01-09T05:00:59.301509 | 2020-11-29T17:06:13 | 2020-11-29T17:06:13 | 242,253,239 | 0 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 26,393 | scm | adbmal-rules.scm | ;;; adbmal adbmals adbmal* alet alet* --- define-syntax
(define-syntax adbmal
(syntax-rules ()
((adbmal . arg) (lambda (f) (f . arg)))))
(define-syntax adbmals
(syntax-rules ()
((adbmals . arg) (lambda (f) (apply f . arg)))))
(define (adbmal* . args) (lambda (f) (apply f args)))
(define-syntax alet-and
(syntax-rules ()
((alet-and (nvt ...) bd ...)
(alet-and "and" () (nvt ...) bd ...))
((alet-and "and" (nt ...) ((n v) nvt ...) bd ...)
(let ((t v))
(and t (alet-and "and" (nt ... (n t)) (nvt ...) bd ...))))
((alet-and "and" (nt ...) ((n v t) nvt ...) bd ...)
(let ((tt v))
(and (let ((n tt)) t)
(alet-and "and" (nt ... (n tt)) (nvt ...) bd ...))))
((alet-and "and" ((n t) ...) () bd ...)
((lambda (n ...) bd ...) t ...))))
(define-syntax alet-and*
(syntax-rules ()
((alet-and* () bd ...)
((lambda () bd ...)))
((alet-and* ((n v) nvt ...) bd ...)
(let ((n v))
(and n (alet-and* (nvt ...) bd ...))))
((alet-and* ((n v t) nvt ...) bd ...)
(let ((n v))
(and t (alet-and* (nvt ...) bd ...))))))
(define-syntax alet-rec ;r6rs letrec
(syntax-rules ()
((alet-rec ((n v) ...) bd ...)
(alet-rec "rec" () ((n v) ...) bd ...))
((alet-rec "rec" (nvt ...) ((n v) nv ...) bd ...)
(alet-rec "rec" (nvt ... (n v t)) (nv ...) bd ...))
((alet-rec "rec" ((n v t) ...) () bd ...)
(let ((n '<undefined>) ...)
(let ((t v) ...)
(set! n t) ...
(begin bd ...))))))
(define-syntax alet-rec* ;r6rs letrec* sequential
(syntax-rules ()
((alet-rec* ((n v) ...) bd ...)
;; (let* ((n '<undefined>) ...) ;This can invoke an infinite loop.
(let ((n '<undefined>) ...)
(set! n v) ...
(begin bd ...)))))
(define-syntax *lambda*
(syntax-rules ()
((*lambda* (a . e) bd ...)
(*lambda* "*" (ta) (a) e bd ...))
((*lambda* "*" (t ...) (n ...) (a . e) bd ...)
(*lambda* "*" (t ... ta) (n ... a) e bd ...))
((*lambda* "*" (t ...) (n ...) () bd ...)
(lambda (t ...)
(let* ((n t) ...) bd ...)))
((*lambda* "*" (t ...) (n ...) e bd ...)
(lambda (t ... . te)
(let* ((n t) ... (e te)) bd ...)))
((*lambda* e bd ...)
(lambda e bd ...))))
(define-syntax wow-opt
(syntax-rules ()
((wow-opt n v) v)
((wow-opt n v t)
(wow-opt n v t n))
((wow-opt n v t ts)
(let ((n v)) (if t ts (error 'alet* "bad argument" n 'n 't))))
((wow-opt n v t ts fs)
(let ((n v)) (if t ts fs)))))
(define-syntax wow-cat-last
(syntax-rules ()
((wow-cat-last z n d)
(if (null? (cdr z))
(car z)
(error 'alet* "too many arguments" z)))
((wow-cat-last z n d t)
(wow-cat-last z n d t n))
((wow-cat-last z n d t ts)
(if (null? (cdr z))
(let ((n (car z)))
(if t ts (error 'alet* "too many argument" z)))
(error 'alet* "too many arguments" z)))
((wow-cat-last z n d t ts fs)
(if (null? (cdr z))
(let ((n (car z)))
(if t ts fs))
(error 'alet* "too many arguments" z)))))
(define-syntax wow-cat!
(syntax-rules ()
((wow-cat! z n d)
(let ((n (car z)))
(set! z (cdr z))
n))
((wow-cat! z n d t)
(wow-cat! z n d t n))
((wow-cat! z n d t ts)
(let ((n (car z)))
(if t
(begin (set! z (cdr z)) ts)
(let lp ((head (list n)) (tail (cdr z)))
(if (null? tail)
d
(let ((n (car tail)))
(if t
(begin (set! z (append (reverse head) (cdr tail))) ts)
(lp (cons n head) (cdr tail)))))))))
((wow-cat! z n d t ts fs)
(let ((n (car z)))
(set! z (cdr z))
(if t ts fs)))))
(define (wow-key z k d)
(let ((x (car z))
(y (cdr z)))
(if (null? y)
(cons d z)
(if (eq? k x)
y
(let lp ((head (list x (car y))) (tail (cdr y)))
(if (null? tail)
(cons d z)
(let ((x (car tail))
(y (cdr tail)))
(if (null? y)
(cons d z)
(if (eq? k x)
(cons (car y) (append head (cdr y)))
(lp (cons x (cons (car y) head)) (cdr y)))))))))))
(define-syntax wow-key!
(syntax-rules ()
((wow-key! z m (n k) d)
(wow-key! z m (n k eq?) d))
((wow-key! z 2 (n k f) d)
;; two at a time: k1 1 k2 2 (k3 3) k4 4 k5 5 -> k2 2 k1 1 k4 4 k5 5
(let ((x (car z))
(y (cdr z)))
(if (null? y)
d
(if (f k x)
(begin (set! z (cdr y)) (car y))
(let lp ((head (list x (car y))) (tail (cdr y)))
(if (null? tail)
d
(let ((x (car tail))
(y (cdr tail)))
(if (null? y)
d
(if (f k x)
(begin (set! z (append head (cdr y)))
(car y))
(lp (cons x (cons (car y) head)) (cdr y)))))))))))
((wow-key! z 1 (n k f) d)
;; one at a time: 1 2 3 4 (5 6) 7 8 -> 1 2 3 4 7 8
(let ((x (car z))
(y (cdr z)))
(if (null? y)
d
(if (f k x)
(begin (set! z (cdr y)) (car y))
(let lp ((head (list x)) (tail y))
(let ((x (car tail))
(y (cdr tail)))
(if (null? y)
d
(if (f k x)
(begin (set! z (append (reverse head) (cdr y)))
(car y))
(lp (cons x head) y)))))))))
((wow-key! z m (n k) d t)
(wow-key! z m (n k eq?) d t n))
((wow-key! z m (n k f) d t)
(wow-key! z m (n k f) d t n))
((wow-key! z m (n k) d t ts)
(wow-key! z m (n k eq?) d t ts))
((wow-key! z m (n k f) d t ts)
(wow-key! z m (n k f) d t ts (error 'alet* "bad argument" n 'n 't)))
((wow-key! z m (n k) d t ts fs)
(wow-key! z m (n k eq?) d t ts fs))
((wow-key! z 2 (n k f) d t ts fs)
;; two at a time: k1 1 k2 2 (k3 3) k4 4 k5 5 -> k2 2 k1 1 k4 4 k5 5
(let ((x (car z))
(y (cdr z)))
(if (null? y)
d
(if (f k x)
(let ((n (car y)))
(set! z (cdr y))
(if t ts fs))
(let lp ((head (list x (car y))) (tail (cdr y)))
(if (null? tail)
d
(let ((x (car tail))
(y (cdr tail)))
(if (null? y)
d
(if (f k x)
(let ((n (car y)))
(set! z (append head (cdr y)))
(if t ts fs))
(lp (cons x (cons (car y) head)) (cdr y)))))))))))
((wow-key! z 1 (n k f) d t ts fs)
;; one at a time: 1 2 3 4 (5 6) 7 8 -> 1 2 3 4 7 8
(let ((x (car z))
(y (cdr z)))
(if (null? y)
d
(if (f k x)
(let ((n (car y)))
(set! z (cdr y))
(if t ts fs))
(let lp ((head (list x)) (tail y))
(let ((x (car tail))
(y (cdr tail)))
(if (null? y)
d
(if (f k x)
(let ((n (car y)))
(set! z (append (reverse head) (cdr y)))
(if t ts fs))
(lp (cons x head) y)))))))))))
(define-syntax %alet
(syntax-rules (adbmal values cons rec and quote quasiquote unquote)
((%alet () ((n v) ...) () bd ...)
((lambda (n ...) bd ...) v ...))
((%alet (var) ((n v) ...) () bd ...)
((letrec ((var (lambda (n ...) bd ...)))
var) v ...))
((%alet (var (p ...) (nv ...) (bn ...)) ((n v) ...) () bd ...)
((letrec ((t (lambda (v ...)
(%alet (p ...) (nv ... (n v) ... (var t)) (bn ...) bd ...))))
t) v ...))
((%alet (p ...) (nv ...) (((a) b) bn ...) bd ...)
((lambda (t) (%alet (p ...) (nv ... (a t)) (bn ...) bd ...)) b))
((%alet (p ...) (nv ...) (((f) z . e) bn ...) bd ...)
(let ((y z))
(%alet "opt" (p ...) (nv ...) f y e (bn ...) bd ...)))
((%alet (p ...) (nv ...) ((() z . e) bn ...) bd ...)
(let ((y z))
(%alet "opt" (p ...) (nv ...) #f y e (bn ...) bd ...)))
((%alet "opt" (p ...) (nv ...) f z ((('n k ...) d t ...) . e) (bn ...) bd ...)
(let ((v (if (null? z) d (wow-key! z 2 (n k ...) d t ...))))
(%alet "opt" (p ...) (nv ... (n v)) f z e (bn ...) bd ...)))
((%alet "opt" (p ...) (nv ...) f z (((`n k ...) d t ...) . e) (bn ...) bd ...)
(let ((v (if (null? z) d (wow-key! z 1 (n k ...) d t ...))))
(%alet "opt" (p ...) (nv ... (n v)) f z e (bn ...) bd ...)))
((%alet "opt" (p ...) (nv ...) f z ((('n k ...)) . e) (bn ...) bd ...)
(let ((v (if (null? z) f (wow-key! z 2 (n k ...) f))))
(%alet "opt" (p ...) (nv ... (n v)) f z e (bn ...) bd ...)))
((%alet "opt" (p ...) (nv ...) f z (((`n k ...)) . e) (bn ...) bd ...)
(let ((v (if (null? z) f (wow-key! z 1 (n k ...) f))))
(%alet "opt" (p ...) (nv ... (n v)) f z e (bn ...) bd ...)))
((%alet "opt" (p ...) (nv ...) f z (('n d t ...) . e) (bn ...) bd ...)
(let ((v (if (null? z) d (wow-key! z 2 (n 'n eq?) d t ...))))
(%alet "opt" (p ...) (nv ... (n v)) f z e (bn ...) bd ...)))
((%alet "opt" (p ...) (nv ...) f z ((`n d t ...) . e) (bn ...) bd ...)
(let ((v (if (null? z) d (wow-key! z 1 (n `n eq?) d t ...))))
(%alet "opt" (p ...) (nv ... (n v)) f z e (bn ...) bd ...)))
((%alet "opt" (p ...) (nv ...) f z ((,n d t ...)) (bn ...) bd ...)
(let ((v (if (null? z) d (wow-cat-last z n d t ...))))
(%alet (p ...) (nv ... (n v)) (bn ...) bd ...)))
((%alet "opt" (p ...) (nv ...) f z ((,n d t ...) . e) (bn ...) bd ...)
(let ((v (if (null? z) d (wow-cat! z n d t ...))))
(%alet "opt" (p ...) (nv ... (n v)) f z e (bn ...) bd ...)))
((%alet "opt" (p ...) (nv ...) f z (((n k) d) . e) (bn ...) bd ...)
(let* ((z (if (null? z) (cons d z) (wow-key z k d)))
(t (car z))
(z (cdr z)))
(%alet "opt" (p ...) (nv ... (n t)) f z e (bn ...) bd ...)))
((%alet "opt" (p ...) (nv ...) f z ('n . e) (bn ...) bd ...)
(let ((v (if (null? z) f (wow-key! z 2 (n 'n eq?) f))))
(%alet "opt" (p ...) (nv ... (n v)) f z e (bn ...) bd ...)))
((%alet "opt" (p ...) (nv ...) f z (`n . e) (bn ...) bd ...)
(let ((v (if (null? z) f (wow-key! z 1 (n `n eq?) f))))
(%alet "opt" (p ...) (nv ... (n v)) f z e (bn ...) bd ...)))
((%alet "opt" (p ...) (nv ...) f z (,n . e) (bn ...) bd ...)
(let ((v (if (null? z) f (wow-cat! z n f))))
(%alet "opt" (p ...) (nv ... (n v)) f z e (bn ...) bd ...)))
((%alet "opt" (p ...) (nv ...) f z ((n d) . e) (bn ...) bd ...)
(let ((y (if (null? z) z (cdr z)))
(v (if (null? z) d (car z))))
(%alet "opt" (p ...) (nv ... (n v)) f y e (bn ...) bd ...)))
((%alet "opt" (p ...) (nv ...) f z ((n d t ...) . e) (bn ...) bd ...)
(let ((y (if (null? z) z (cdr z)))
(v (if (null? z) d (wow-opt n (car z) t ...))))
(%alet "opt" (p ...) (nv ... (n v)) f y e (bn ...) bd ...)))
((%alet "opt" (p ...) (nv ...) f z (n . e) (bn ...) bd ...)
(let ((y (if (null? z) z (cdr z)))
(v (if (null? z) f (car z))))
(%alet "opt" (p ...) (nv ... (n v)) f y e (bn ...) bd ...)))
((%alet "opt" (p ...) (nv ...) f z () (bn ...) bd ...)
(if (null? z)
(%alet (p ...) (nv ...) (bn ...) bd ...)
(error 'alet* "too many arguments" z)))
((%alet "opt" (p ...) (nv ...) f z e (bn ...) bd ...)
(let ((v z))
(%alet (p ...) (nv ... (e v)) (bn ...) bd ...)))
((%alet (p ...) (nv ...) (((adbmal . b) c) bn ...) bd ...)
(%alet "one" (p ...) (nv ...) (adbmal) (b c) (bn ...) bd ...))
((%alet (p ...) (nv ...) (((values . b) c) bn ...) bd ...)
(%alet "one" (p ...) (nv ...) (values) (b c) (bn ...) bd ...))
((%alet (p ...) (nv ...) (((cons a b) c) bn ...) bd ...)
(let ((z c)) ;should be exist!
((lambda (ta tb) (%alet (p ...) (nv ... (a ta) (b tb)) (bn ...) bd ...)) (car z) (cdr z))))
((%alet (p ...) (nv ...) (((a . b) c) bn ...) bd ...)
(%alet "one" (p ...) (nv ... (a t)) (t) (b c) (bn ...) bd ...))
((%alet "one" (p ...) (nv ...) (t ...) ((a . b) c) (bn ...) bd ...)
(%alet "one" (p ...) (nv ... (a tn)) (t ... tn) (b c) (bn ...) bd ...))
((%alet "one" (p ...) (nv ...) (adbmal t ...) (() c) (bn ...) bd ...)
(c (lambda (t ...) (%alet (p ...) (nv ...) (bn ...) bd ...))))
((%alet "one" (p ...) (nv ...) (values t ...) (() c) (bn ...) bd ...)
;; (receive (t ...) c (%alet (p ...) (nv ...) (bn ...) bd ...)))
(call-with-values (lambda () c)
(lambda (t ...) (%alet (p ...) (nv ...) (bn ...) bd ...))))
((%alet "one" (p ...) (nv ...) (t ...) (() c) (bn ...) bd ...)
(apply (lambda (t ...) (%alet (p ...) (nv ...) (bn ...) bd ...)) c))
((%alet "one" (p ...) (nv ...) (adbmal t ...) (b c) (bn ...) bd ...)
(c (lambda (t ... . tn) (%alet (p ...) (nv ... (b tn)) (bn ...) bd ...))))
((%alet "one" (p ...) (nv ...) (values t ...) (b c) (bn ...) bd ...)
;; (receive (t ... . tn) c (%alet (p ...) (nv ... (b tn)) (bn ...) bd ...)))
(call-with-values (lambda () c)
(lambda (t ... . tn) (%alet (p ...) (nv ... (b tn)) (bn ...) bd ...))))
((%alet "one" (p ...) (nv ...) (t ...) (b c) (bn ...) bd ...)
(apply (lambda (t ... . tn) (%alet (p ...) (nv ... (b tn)) (bn ...) bd ...)) c))
((%alet (p ...) (nv ...) (((a . b) c d ...) bn ...) bd ...)
(%alet "dot" (p ...) (nv ... (a t)) (t) (b c d ...) (bn ...) bd ...))
((%alet "dot" (p ...) (nv ...) (t ...) ((a . b) c d ...) (bn ...) bd ...)
(%alet "dot" (p ...) (nv ... (a tn)) (t ... tn) (b c d ...) (bn ...) bd ...))
((%alet "dot" (p ...) (nv ...) (t ...) (() c d ...) (bn ...) bd ...)
((lambda (t ...) (%alet (p ...) (nv ...) (bn ...) bd ...)) c d ...))
((%alet "dot" (p ...) (nv ...) (t ...) (b c d ...) (bn ...) bd ...)
((lambda (t ... . tn)
(%alet (p ...) (nv ... (b tn)) (bn ...) bd ...)) c d ...))
((%alet (p ...) (nv ...) ((and (n v t ...) nvt ...) bn ...) bd ...)
(%alet "and" (p ...) (nv ...) ((n v t ...) nvt ...) (bn ...) bd ...))
((%alet "and" (p ...) (nv ...) ((n v) nvt ...) (bn ...) bd ...)
(let ((t v))
(and t (%alet "and" (p ...) (nv ... (n t)) (nvt ...) (bn ...) bd ...))))
((%alet "and" (p ...) (nv ...) ((n v t) nvt ...) (bn ...) bd ...)
(let ((tt v))
(and (let ((n tt)) t)
(%alet "and" (p ...) (nv ... (n tt)) (nvt ...) (bn ...) bd ...))))
((%alet "and" (p ...) (nv ...) () (bn ...) bd ...)
(%alet (p ...) (nv ...) (bn ...) bd ...))
;; You can choose the one of the following three.
((%alet (p ...) (nv ...) ((rec (n v) mv ...) bn ...) bd ...)
(%alet "rec" (p ...) (nv ...) () ((n v) mv ...) (bn ...) bd ...))
((%alet "rec" (p ...) (nv ...) (nvt ...) ((n v) mv ...) (bn ...) bd ...)
(%alet "rec" (p ...) (nv ... (n t)) (nvt ... (n v t)) (mv ...) (bn ...) bd ...))
((%alet "rec" (p ...) (nv ...) ((n v t) ...) () (bn ...) bd ...)
((letrec ((n v) ...) (adbmal n ...))
(lambda (t ...) (%alet (p ...) (nv ...) (bn ...) bd ...))))
;; ((%alet (p ...) (nv ...) ((rec (n v) mv ...) bn ...) bd ...)
;; (%alet "rec" (p ...) (nv ...) () ((n v) mv ...) (bn ...) bd ...))
;; ((%alet "rec" (p ...) (nv ...) (nvt ...) ((n v) mv ...) (bn ...) bd ...)
;; (%alet "rec" (p ...) (nv ... (n (begin (set! n t) n))) (nvt ... (n v t)) (mv ...) (bn ...) bd ...))
;; ((%alet "rec" (p ...) (nv ...) ((n v t) ...) () (bn ...) bd ...)
;; (let ((n '<undefined>) ...)
;; (let ((t v) ...)
;; (%alet (p ...) (nv ...) (bn ...) bd ...))))
;; ((%alet (p ...) (nv ...) ((rec (n1 v1) (n2 v2) ...) bn ...) bd ...)
;; (let ((n1 '<undefined>) (n2 '<undefined>) ...)
;; (%alet (p ...) (nv ... (n1 (begin (set! n1 v1) n1)) (n2 (begin (set! n2 v2) n2)) ...) (bn ...) bd ...)))
((%alet (p ...) (nv ...) ((a b) bn ...) bd ...)
((lambda (t) (%alet (p ...) (nv ... (a t)) (bn ...) bd ...)) b))
((%alet (p ...) (nv ...) ((adbmal a b c ...) bn ...) bd ...)
(%alet "not" (p ...) (nv ... (a t)) (adbmal t) (b c ...) (bn ...) bd ...))
((%alet (p ...) (nv ...) ((values a b c ...) bn ...) bd ...)
(%alet "not" (p ...) (nv ... (a t)) (values t) (b c ...) (bn ...) bd ...))
((%alet (p ...) (nv ...) ((cons a b c) bn ...) bd ...)
(let ((z c)) ;should be exist!
((lambda (ta tb) (%alet (p ...) (nv ... (a ta) (b tb)) (bn ...) bd ...)) (car z) (cdr z))))
((%alet (p ...) (nv ...) ((a b c ...) bn ...) bd ...)
(%alet "not" (p ...) (nv ... (a t)) (t) (b c ...) (bn ...) bd ...))
((%alet "not" (p ...) (nv ...) (t ...) (a b c ...) (bn ...) bd ...)
(%alet "not" (p ...) (nv ... (a tn)) (t ... tn) (b c ...) (bn ...) bd ...))
((%alet "not" (p ...) (nv ...) (adbmal t ...) (z) (bn ...) bd ...)
(z (lambda (t ...) (%alet (p ...) (nv ...) (bn ...) bd ...))))
((%alet "not" (p ...) (nv ...) (values t ...) (z) (bn ...) bd ...)
;; (receive (t ...) z (%alet (p ...) (nv ...) (bn ...) bd ...)))
(call-with-values (lambda () z)
(lambda (t ...) (%alet (p ...) (nv ...) (bn ...) bd ...))))
((%alet "not" (p ...) (nv ...) (t ...) (z) (bn ...) bd ...)
(apply (lambda (t ...) (%alet (p ...) (nv ...) (bn ...) bd ...)) z))
((%alet (p ...) (nv ...) ((a) bn ...) bd ...)
(call-with-current-continuation
(lambda (t) (%alet (p ...) (nv ... (a t)) (bn ...) bd ...))))
((%alet (p ...) (nv ...) (a bn ...) bd ...)
(%alet "rot" (p ...) (nv ...) () a (bn ...) bd ...))
((%alet "rot" (p ...) (nv ...) (new-bn ...) (a . b) (bn ...) bd ...)
(%alet "rot" (p ...) (nv ...) (new-bn ... a) b (bn ...) bd ...))
((%alet "rot" (p ...) (nv ...) (new-bn ...) b (bn ...) bd ...)
(%alet (b (p ...) (nv ...) (bn ...)) () (new-bn ...) bd ...))))
(define-syntax alet
(syntax-rules ()
((alet (bn ...) bd ...)
(%alet () () (bn ...) bd ...))
((alet var (bn ...) bd ...)
(%alet (var) () (bn ...) bd ...))))
(define-syntax %alet*
(syntax-rules (adbmal values cons rec and quote quasiquote unquote)
((%alet* () (n ...) () bd ...)
((lambda () bd ...)))
((%alet* (var) (n ...) () bd ...)
((letrec ((var (*lambda* (n ...) bd ...))) ;for duplication
var) n ...))
((%alet* (var (p ...) (nn ...) (bn ...)) (n ...) () bd ...)
((letrec ((var (lambda (n ...)
(%alet* (p ...) (nn ... n ... var) (bn ...) bd ...))))
var) n ...))
((%alet* (p ...) (n ...) (((a) b) bn ...) bd ...)
((lambda (a) (%alet* (p ...) (n ... a) (bn ...) bd ...)) b))
((%alet* (p ...) (m ...) (((f) z . e) bn ...) bd ...)
(let ((y z))
(%alet* "opt" (p ...) (m ...) f y e (bn ...) bd ...)))
((%alet* (p ...) (m ...) ((() z . e) bn ...) bd ...)
(let ((y z))
(%alet* "opt" (p ...) (m ...) #f y e (bn ...) bd ...)))
((%alet* "opt" (p ...) (m ...) f z ((('n k ...) d t ...) . e) (bn ...) bd ...)
(let ((n (if (null? z) d (wow-key! z 2 (n k ...) d t ...))))
(%alet* "opt" (p ...) (m ... n) f z e (bn ...) bd ...)))
((%alet* "opt" (p ...) (m ...) f z (((`n k ...) d t ...) . e) (bn ...) bd ...)
(let ((n (if (null? z) d (wow-key! z 1 (n k ...) d t ...))))
(%alet* "opt" (p ...) (m ... n) f z e (bn ...) bd ...)))
((%alet* "opt" (p ...) (m ...) f z ((('n k ...)) . e) (bn ...) bd ...)
(let ((n (if (null? z) f (wow-key! z 2 (n k ...) f))))
(%alet* "opt" (p ...) (m ... n) f z e (bn ...) bd ...)))
((%alet* "opt" (p ...) (m ...) f z (((`n k ...)) . e) (bn ...) bd ...)
(let ((n (if (null? z) f (wow-key! z 1 (n k ...) f))))
(%alet* "opt" (p ...) (m ... n) f z e (bn ...) bd ...)))
((%alet* "opt" (p ...) (m ...) f z (('n d t ...) . e) (bn ...) bd ...)
(let ((n (if (null? z) d (wow-key! z 2 (n 'n eq?) d t ...))))
(%alet* "opt" (p ...) (m ... n) f z e (bn ...) bd ...)))
((%alet* "opt" (p ...) (m ...) f z ((`n d t ...) . e) (bn ...) bd ...)
(let ((n (if (null? z) d (wow-key! z 1 (n `n eq?) d t ...))))
(%alet* "opt" (p ...) (m ... n) f z e (bn ...) bd ...)))
((%alet* "opt" (p ...) (m ...) f z ((,n d t ...)) (bn ...) bd ...)
(let ((n (if (null? z) d (wow-cat-last z n d t ...))))
(%alet* (p ...) (m ... n) (bn ...) bd ...)))
((%alet* "opt" (p ...) (m ...) f z ((,n d t ...) . e) (bn ...) bd ...)
(let ((n (if (null? z) d (wow-cat! z n d t ...))))
(%alet* "opt" (p ...) (m ... n) f z e (bn ...) bd ...)))
((%alet* "opt" (p ...) (m ...) f z (((n k) d) . e) (bn ...) bd ...)
(let* ((z (if (null? z) (cons d z) (wow-key z k d)))
(n (car z))
(z (cdr z)))
(%alet* "opt" (p ...) (m ... n) f z e (bn ...) bd ...)))
((%alet* "opt" (p ...) (m ...) f z ('n . e) (bn ...) bd ...)
(let ((n (if (null? z) f (wow-key! z 2 (n 'n eq?) f))))
(%alet* "opt" (p ...) (m ... n) f z e (bn ...) bd ...)))
((%alet* "opt" (p ...) (m ...) f z (`n . e) (bn ...) bd ...)
(let ((n (if (null? z) f (wow-key! z 1 (n `n eq?) f))))
(%alet* "opt" (p ...) (m ... n) f z e (bn ...) bd ...)))
((%alet* "opt" (p ...) (m ...) f z (,n . e) (bn ...) bd ...)
(let ((n (if (null? z) f (wow-cat! z n f))))
(%alet* "opt" (p ...) (m ... n) f z e (bn ...) bd ...)))
((%alet* "opt" (p ...) (m ...) f z ((n d) . e) (bn ...) bd ...)
(let ((y (if (null? z) z (cdr z)))
(n (if (null? z) d (car z))))
(%alet* "opt" (p ...) (m ... n) f y e (bn ...) bd ...)))
((%alet* "opt" (p ...) (m ...) f z ((n d t ...) . e) (bn ...) bd ...)
(let ((y (if (null? z) z (cdr z)))
(n (if (null? z) d (wow-opt n (car z) t ...))))
(%alet* "opt" (p ...) (m ... n) f y e (bn ...) bd ...)))
((%alet* "opt" (p ...) (m ...) f z (n . e) (bn ...) bd ...)
(let ((y (if (null? z) z (cdr z)))
(n (if (null? z) f (car z))))
(%alet* "opt" (p ...) (m ... n) f y e (bn ...) bd ...)))
((%alet* "opt" (p ...) (m ...) f z () (bn ...) bd ...)
(if (null? z)
(%alet* (p ...) (m ...) (bn ...) bd ...)
(error 'alet* "too many arguments" z)))
((%alet* "opt" (p ...) (m ...) f z e (bn ...) bd ...)
(let ((e z))
(%alet* (p ...) (m ... e) (bn ...) bd ...)))
((%alet* (p ...) (n ...) (((adbmal . b) c) bn ...) bd ...)
(%alet* "one" (p ...) (n ...) (adbmal) (b c) (bn ...) bd ...))
((%alet* (p ...) (n ...) (((values . b) c) bn ...) bd ...)
(%alet* "one" (p ...) (n ...) (values) (b c) (bn ...) bd ...))
((%alet* (p ...) (n ...) (((cons a b) c) bn ...) bd ...)
(let ((z c)) ;should be exist!
((lambda (a b) (%alet* (p ...) (n ... a b) (bn ...) bd ...)) (car z) (cdr z))))
((%alet* (p ...) (n ...) (((a . b) c) bn ...) bd ...)
(%alet* "one" (p ...) (n ... a) (a) (b c) (bn ...) bd ...))
((%alet* "one" (p ...) (n ...) (r ...) ((a . b) c) (bn ...) bd ...)
(%alet* "one" (p ...) (n ... a) (r ... a) (b c) (bn ...) bd ...))
((%alet* "one" (p ...) (n ...) (adbmal r ...) (() c) (bn ...) bd ...)
(c (lambda (r ...) (%alet* (p ...) (n ...) (bn ...) bd ...))))
((%alet* "one" (p ...) (n ...) (values r ...) (() c) (bn ...) bd ...)
;; (receive (r ...) c (%alet* (p ...) (n ...) (bn ...) bd ...)))
(call-with-values (lambda () c)
(lambda (r ...) (%alet* (p ...) (n ...) (bn ...) bd ...))))
((%alet* "one" (p ...) (n ...) (r ...) (() c) (bn ...) bd ...)
(apply (lambda (r ...) (%alet* (p ...) (n ...) (bn ...) bd ...)) c))
((%alet* "one" (p ...) (n ...) (adbmal r ...) (b c) (bn ...) bd ...)
(c (lambda (r ... . b) (%alet* (p ...) (n ... b) (bn ...) bd ...))))
((%alet* "one" (p ...) (n ...) (values r ...) (b c) (bn ...) bd ...)
;; (receive (r ... . b) c (%alet* (p ...) (n ... b) (bn ...) bd ...)))
(call-with-values (lambda () c)
(lambda (r ... . b) (%alet* (p ...) (n ... b) (bn ...) bd ...))))
((%alet* "one" (p ...) (n ...) (r ...) (b c) (bn ...) bd ...)
(apply (lambda (r ... . b) (%alet* (p ...) (n ... b) (bn ...) bd ...)) c))
((%alet* (p ...) (n ...) (((a . b) c d ...) bn ...) bd ...)
(%alet* "dot" (p ...) (n ... a) (a) (b c d ...) (bn ...) bd ...))
((%alet* "dot" (p ...) (n ...) (r ...) ((a . b) c d ...) (bn ...) bd ...)
(%alet* "dot" (p ...) (n ... a) (r ... a) (b c d ...) (bn ...) bd ...))
((%alet* "dot" (p ...) (n ...) (r ...) (() c d ...) (bn ...) bd ...)
((lambda (r ...) (%alet* (p ...) (n ...) (bn ...) bd ...)) c d ...))
((%alet* "dot" (p ...) (n ...) (r ...) (b c d ...) (bn ...) bd ...)
((lambda (r ... . b) (%alet* (p ...) (n ... b) (bn ...) bd ...)) c d ...))
((%alet* (p ...) (n ...) ((and (n1 v1 t1 ...) (n2 v2 t2 ...) ...) bn ...) bd ...)
(alet-and* ((n1 v1 t1 ...) (n2 v2 t2 ...) ...)
(%alet* (p ...) (n ... n1 n2 ...) (bn ...) bd ...)))
((%alet* (p ...) (n ...) ((rec (n1 v1) (n2 v2) ...) bn ...) bd ...)
(letrec* ((n1 v1) (n2 v2) ...)
(%alet* (p ...) (n ... n1 n2 ...) (bn ...) bd ...)))
((%alet* (p ...) (n ...) ((a b) bn ...) bd ...)
((lambda (a) (%alet* (p ...) (n ... a) (bn ...) bd ...)) b))
((%alet* (p ...) (n ...) ((adbmal a b c ...) bn ...) bd ...)
(%alet* "not" (p ...) (n ... a) (adbmal a) (b c ...) (bn ...) bd ...))
((%alet* (p ...) (n ...) ((values a b c ...) bn ...) bd ...)
(%alet* "not" (p ...) (n ... a) (values a) (b c ...) (bn ...) bd ...))
((%alet* (p ...) (n ...) ((cons a b c) bn ...) bd ...)
(let ((z c)) ;should be exist!
((lambda (a b) (%alet* (p ...) (n ... a b) (bn ...) bd ...)) (car z) (cdr z))))
((%alet* (p ...) (n ...) ((a b c ...) bn ...) bd ...)
(%alet* "not" (p ...) (n ... a) (a) (b c ...) (bn ...) bd ...))
((%alet* "not" (p ...) (n ...) (r ...) (a b c ...) (bn ...) bd ...)
(%alet* "not" (p ...) (n ... a) (r ... a) (b c ...) (bn ...) bd ...))
((%alet* "not" (p ...) (n ...) (adbmal r ...) (z) (bn ...) bd ...)
(z (lambda (r ...) (%alet* (p ...) (n ...) (bn ...) bd ...))))
((%alet* "not" (p ...) (n ...) (values r ...) (z) (bn ...) bd ...)
;; (receive (r ...) z (%alet* (p ...) (n ...) (bn ...) bd ...)))
(call-with-values (lambda () z)
(lambda (r ...) (%alet* (p ...) (n ...) (bn ...) bd ...))))
((%alet* "not" (p ...) (n ...) (r ...) (z) (bn ...) bd ...)
(apply (lambda (r ...) (%alet* (p ...) (n ...) (bn ...) bd ...)) z))
((%alet* (p ...) (n ...) ((a) bn ...) bd ...)
(call-with-current-continuation
(lambda (a) (%alet* (p ...) (n ... a) (bn ...) bd ...))))
((%alet* (p ...) (n ...) (a bn ...) bd ...)
(%alet* "rot" (p ...) (n ...) () a (bn ...) bd ...))
((%alet* "rot" (p ...) (n ...) (new-bn ...) (a . b) (bn ...) bd ...)
(%alet* "rot" (p ...) (n ...) (new-bn ... a) b (bn ...) bd ...))
((%alet* "rot" (p ...) (n ...) (new-bn ...) b (bn ...) bd ...)
(%alet* (b (p ...) (n ...) (bn ...)) () (new-bn ...) bd ...))))
(define-syntax alet*
(syntax-rules ()
((alet* (bn ...) bd ...)
(%alet* () () (bn ...) bd ...))
((alet* var (bn ...) bd ...)
(%alet* (var) () (bn ...) bd ...))))
;;; eof
| true |
da272bd2bf1866ca8afc6758d17a2ca3fd026fa5 | e565c8e8d16935673647ecfbb7f1c674a260cb00 | /lib/chibi/json.sld | d5043a9386f010722283cc47d84a84adc04aee88 | [
"BSD-3-Clause"
]
| permissive | tomelam/chibi-scheme | 2997c9d53e2166ebf485934696b1661c37c19f9c | 6f28159667212fffc9df4383dc773ea129f106d0 | refs/heads/master | 2020-12-01T19:05:39.952425 | 2019-12-28T14:48:44 | 2019-12-28T14:48:44 | 230,738,272 | 1 | 0 | NOASSERTION | 2019-12-29T11:03:00 | 2019-12-29T11:02:59 | null | UTF-8 | Scheme | false | false | 104 | sld | json.sld |
(define-library (chibi json)
(import (scheme base))
(export parse-json)
(include-shared "json"))
| false |
1a7d96ebeb0bb9f93d4c3f47d548cfa944ce371f | 6b961ef37ff7018c8449d3fa05c04ffbda56582b | /bbn_cl/mach/runtime/bitstr.scm | 17e33fcfcf9e4a84f71145cd3575e82021cc23ef | []
| no_license | tinysun212/bbn_cl | 7589c5ac901fbec1b8a13f2bd60510b4b8a20263 | 89d88095fc2a71254e04e57cf499ae86abf98898 | refs/heads/master | 2021-01-10T02:35:18.357279 | 2015-05-26T02:44:00 | 2015-05-26T02:44:00 | 36,267,589 | 4 | 3 | null | null | null | null | UTF-8 | Scheme | false | false | 3,420 | scm | bitstr.scm | ;;; -*-Scheme-*-
;;;
;;;
;;; Copyright (c) 1987 Massachusetts Institute of Technology
;;;
;;; This material was developed by the Scheme project at the
;;; Massachusetts Institute of Technology, Department of
;;; Electrical Engineering and Computer Science. Permission to
;;; copy this software, to redistribute it, and to use it for any
;;; purpose is granted, subject to the following restrictions and
;;; understandings.
;;;
;;; 1. Any copy made of this software must include this copyright
;;; notice in full.
;;;
;;; 2. Users of this software agree to make their best efforts (a)
;;; to return to the MIT Scheme project any improvements or
;;; extensions that they make, so that these may be included in
;;; future releases; and (b) to inform MIT of noteworthy uses of
;;; this software.
;;;
;;; 3. All materials developed as a consequence of the use of
;;; this software shall duly acknowledge such use, in accordance
;;; with the usual standards of acknowledging credit in academic
;;; research.
;;;
;;; 4. MIT has made no warrantee or representation that the
;;; operation of this software will be error-free, and MIT is
;;; under no obligation to provide any services, by way of
;;; maintenance, update, or otherwise.
;;;
;;; 5. In conjunction with products arising from the use of this
;;; material, there shall be no use of the name of the
;;; Massachusetts Institute of Technology nor of any adaptation
;;; thereof in any advertising, promotional, or sales literature
;;; without prior written consent from MIT in each case.
;;;
;;;; Bit String Primitives
(declare (usual-integrations))
(let-syntax ((define-primitives
(macro names
`(BEGIN ,@(map (lambda (name)
`(LOCAL-ASSIGNMENT
SYSTEM-GLOBAL-ENVIRONMENT
',name
,(make-primitive-procedure name)))
names)))))
(define-primitives
bit-string-allocate make-bit-string bit-string?
bit-string-length bit-string-ref bit-string-clear! bit-string-set!
bit-string-zero? bit-string=?
bit-string-fill! bit-string-move! bit-string-movec!
bit-string-or! bit-string-and! bit-string-andc!
bit-string-xor! bit-substring-move-right!
bit-string->unsigned-integer unsigned-integer->bit-string
read-bits! write-bits!
bit-substring-find-next-set-bit))
(define (bit-string-append x y)
(declare (integrate x y))
(let ((x-length (bit-string-length x))
(y-length (bit-string-length y)))
(let ((result (bit-string-allocate (+ x-length y-length))))
(bit-substring-move-right! x 0 x-length result 0)
(bit-substring-move-right! y 0 y-length result x-length)
result)))
(define (bit-string-append-reversed x y)
(declare (integrate bit-string-append))
(bit-string-append y x))
(define (bit-substring bit-string start end)
(let ((result (bit-string-allocate (- end start))))
(bit-substring-move-right! bit-string start end result 0)
result))
(define (signed-integer->bit-string nbits number)
(unsigned-integer->bit-string
nbits
(cond ((negative? number) (+ number (expt 2 nbits)))
((< number (expt 2 (-1+ nbits))) number)
(else (error "Integer too large to be encoded" number)))))
(define (bit-string->signed-integer bit-string)
(let ((unsigned-result (bit-string->unsigned-integer bit-string))
(nbits (bit-string-length bit-string)))
(if (bit-string-ref bit-string (-1+ nbits)) ;Sign bit.
(- unsigned-result (expt 2 nbits))
unsigned-result)))
| false |
d9f1130487ec161565102903af728e524059427e | defeada37d39bca09ef76f66f38683754c0a6aa0 | /mscorlib/mono/security/x509/extensions/key-usage-extension.sls | 7c0c41dabfe341007c6c5324134a2d7b2cd14801 | []
| no_license | futsuki/ironscheme-port | 2dbac82c0bda4f4ff509208f7f00a5211d1f7cd5 | 4e7a81b0fbeac9a47440464988e53fb118286c54 | refs/heads/master | 2016-09-06T17:13:11.462593 | 2015-09-26T18:20:40 | 2015-09-26T18:20:40 | 42,757,369 | 0 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 1,294 | sls | key-usage-extension.sls | (library (mono security x509 extensions key-usage-extension)
(export new
is?
key-usage-extension?
support?
to-string
key-usage-get
key-usage-set!
key-usage-update!
name)
(import (ironscheme-clr-port))
(define-syntax new
(lambda (e)
(syntax-case e ()
((_ a ...)
#'(clr-new
Mono.Security.X509.Extensions.KeyUsageExtension
a
...)))))
(define (is? a)
(clr-is Mono.Security.X509.Extensions.KeyUsageExtension a))
(define (key-usage-extension? a)
(clr-is Mono.Security.X509.Extensions.KeyUsageExtension a))
(define-method-port
support?
Mono.Security.X509.Extensions.KeyUsageExtension
Support
(System.Boolean Mono.Security.X509.Extensions.KeyUsages))
(define-method-port
to-string
Mono.Security.X509.Extensions.KeyUsageExtension
ToString
(System.String))
(define-field-port
key-usage-get
key-usage-set!
key-usage-update!
(property:)
Mono.Security.X509.Extensions.KeyUsageExtension
KeyUsage
Mono.Security.X509.Extensions.KeyUsages)
(define-field-port
name
#f
#f
(property:)
Mono.Security.X509.Extensions.KeyUsageExtension
Name
System.String))
| true |
0e2c54842eb066b5b44651400f0375dc78703ede | 3453419571c01ee4e96cc30e8ff256a0bb2a4f5e | /km.scm | 907a1b87fde38ea872b1e89ba04f8ae398d2a8a7 | []
| no_license | pbaille/parsing-combinators | bac66451f5c49df903223c7d7f6cbf3342acb740 | 98aa5dfdc3fd9b6cdc823d50cfdb096e9848f73e | refs/heads/master | 2020-03-18T13:04:34.401334 | 2018-05-25T07:53:51 | 2018-05-25T07:53:51 | 134,759,804 | 0 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 1,386 | scm | km.scm | (load-relative "utils.scm")
(define (kmentry? x)
(and (pair? x)
(symbol? (car x))))
(define (km? x)
(or (null? x)
(and (kmentry? (car x))
(km? (cdr x)))))
(define (kmjoin a b)
(cond
((null? a) b)
((null? b) a)
((km? b)
(let ((fst (car b)))
(kmjoin
(alist-update (car fst) (cdr fst) a)
(cdr b))))))
(define (km . xs)
(cond
((null? xs) '())
((symbol? (car xs))
(cons (cons (car xs) (cadr xs))
(apply km (cddr xs))))
((km? (car xs))
(kmjoin (car xs) (apply km (cdr xs))))))
(define (kmget target req)
(cond
((null? req) target)
((symbol? req)
(let ((e (assq req target)))
(and e (cdr e))))
((km? req)
(map (λ (x)
(cons (car x)
((cdr x)
(kmget target (car x)))))
req))
((and (pair? req)
(symbol? (car req)))
(if (null? (cdr req))
(km (car req)
(kmget target (car req)))
(km (car req)
(kmget target (car req))
(kmget target (cdr req)))))))
(define (kmget> target . reqs)
(reduce kmget target reqs))
(begin
(km? (km 'a 1))
(km? (km 'a 1 'b 2))
(km? (km 'c 5 (km 'a 1 'b 2)))
(let ((k (km 'a 1 'b 2 'c 3)))
(list
(kmget k 'a)
(kmget k '())
(kmget k (km 'a identity 'b (λ (x) (+ x 1))))
(kmget k '(a b))
)))
| false |
1d65cfd864d3231977668090aa81a40dfa0c74bf | a8248e8fe006b2bea3c2f04b1339ddb8407654f8 | /S4/HLIN402 - Logique/TPs/logique.scm | c5214cf2f5280dedf3d7e20457b570a12ddaa448 | [
"MIT"
]
| permissive | AzhiD/licence-info | 4bd05904aba3810f0dcd9a4c73aaff5fc4b1e087 | 64acdb5b0b3bdd541c758249731f89d3a90b6330 | refs/heads/master | 2022-12-08T11:13:51.476004 | 2020-08-26T12:42:34 | 2020-08-26T12:42:34 | null | 0 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 11,558 | scm | logique.scm | #lang scheme
;TP de Logique 1
;1)Representation des propositions
;Q1:
(define F1 '(<-> (^ a b) (v (! a) b)))
(define F2 '(v (! (^ a (! b))) (! (-> a b))))
(define F3 '(^ (! (-> a (v a b))) (! (! (^ a (v b (! c)))))))
(define F4 '(^ (v (! a) (v b d)) (^ (v (! d) c) (^ (v c a) (^ (v (! c) b) (^ (v (! c) (! b)) (v (! b) d)))))))
;Q2
(define (neg? f) (eq? f '!))
(define (and? f) (eq? f '^))
(define (or? f) (eq? f 'v))
(define (imp? f) (eq? f '->))
(define (equ? f) (eq? f '<->))
(define (top? f) (eq? f 'T))
(define (bot? f) (eq? f 'B))
(define (symbLog? f) (or (top? f) (bot? f) (and? f) (or? f) (neg? f) (imp? f) (equ? f)))
(define (symbProp? f) (and (symbol? f) (not (symbLog? f))))
(define (atomicFbf? f) (or (symbProp? f) (top? f) (bot? f)))
(define (conBin? f) (or (and? f) (or? f) (imp? f) (equ? f)))
(define (fbf? f)
(cond ((atomicFbf? f) #t)
((list? f) (cond ((and (= (length f) 2) (neg? (car f))) (fbf? (cadr f)))
((and (= (length f) 3) (conBin? (car f))) (and (fbf? (cadr f)) (fbf? (caddr f))))
(else #f)))
(else #f)))
;2)Syntaxe des propositions
(define (conRac f) (car f)) ; retourne le connecteur racine d’une fbf non atomique
(define (fils f) (cadr f)) ; retourne le fils d’une fbf dont la racine est un connecteur unaire
(define (filsG f) (cadr f)) ; retourne le fils gauche d’une fbf dont la racine est un connecteur binaire
(define (filsD f) (caddr f)) ; retourne le fils droit d’une fbf dont la racine est un connecteur binaire
(define (negFbf? f) ; teste si une fbf a une négation comme connecteur racine
(and (not (atomicFbf? f))
(neg? (conRac f))))
;Q3:
(define (nbc f)
(cond ((atomicFbf? f) 0)
((negFbf? f) (+ 1 (nbc (fils f))))
((conBin? (conRac f)) (+ 1 (nbc (filsG f)) (nbc (filsD f))))
(else (display "nbc : mauvais argument"))))
;Q4:
(define (prof f)
(cond ((atomicFbf? f) 0)
((negFbf? f) (+ 1 (prof (fils f))))
((conBin? (conRac f)) (+ 1 (max (prof (filsG f)) (prof (filsD f)))))
(else (display "prof : mauvais argument"))))
;Q5:
(define remove-duplicated
(lambda (L)
(if (null? L) '()
(if (member (car L) (cdr L))
(remove-duplicated (cdr L))
(cons (car L) (remove-duplicated (cdr L)))))))
(define ensSP
(lambda (f)
(cond ((and (atomicFbf? f) (not (or (top? f) (bot? f)))) (list f))
((or (top? f) (bot? f)) '())
((negFbf? f) (remove-duplicated (ensSP (fils f))))
((conBin? (conRac f)) (remove-duplicated (append (ensSP (filsG f)) (ensSP (filsD f)))))
(else (display "ensSP: mauvais argument")))))
;Q6:
(define affiche
(lambda (f)
(display f)))
;3)Sémantique des propositions
;Q7:
(define I1 (list (cons 'a 1) (cons 'b 0) (cons 'c 1)))
(define I2 (list (cons 'a 0) (cons 'b 0) (cons 'c 0)))
(define I3 (list (cons 'a 1) (cons 'b 1) (cons 'c 1)))
;Q8:
(define intSymb
(lambda (s I)
(cond ((null? I) (display "intSymb: Ce symbole propositionel n'est pas défini dans l'interpretation"))
((eq? s (caar I)) (cdar I))
(else (intSymb s (cdr I))))))
;Q9:
(define intNeg
(lambda (a)
(if (= a 0) 1 0)))
(define intAnd
(lambda (a b)
(if (and (= a 1) (= b 1)) 1 0)))
(define intOr
(lambda (a b)
(if (or (= a 1) (= b 1)) 1 0)))
(define intImp
(lambda (a b)
(if (or (not (= a 1)) (= b 1)) 1 0)))
(define intEqu
(lambda (a b)
(if (and (= (intImp a b) 1) (= (intImp b a) 1)) 1 0)))
(define (intTop)
1)
(define (intBot)
0)
;Q10:
(define valV
(lambda (f I)
(if (fbf? f)
(cond ((top? f) (intTop))
((bot? f) (intBot))
((atomicFbf? f) (intSymb f I))
((neg? (conRac f)) (intNeg (valV (fils f) I)))
((and? (conRac f)) (intAnd (valV (filsG f) I) (valV (filsD f) I)))
((or? (conRac f)) (intOr (valV (filsG f) I) (valV (filsD f) I)))
((imp? (conRac f)) (intImp (valV (filsG f) I) (valV (filsD f) I)))
((equ? (conRac f)) (intEqu (valV (filsG f) I) (valV (filsD f) I)))
(else (display "valV : cas imprevu")))
(display "valV : formule mal formée"))))
;Q11:
(define modele?
(lambda (f I)
(= (valV f I) 1)))
;4)Satisfabilité et validité d'une proposition
;Q12:
(define IPQ (list (list (cons 'p 0) (cons 'q 0))
(list (cons 'p 0) (cons 'q 1))
(list (cons 'p 1) (cons 'q 0))
(list (cons 'p 1) (cons 'q 1))))
;Q13
;number->binList : Converti un nombre <n> en une liste binaire
(define number->binList
(lambda (n)
(if (or (= n 1) (= n 0)) (list n) (append (number->binList (floor (/ n 2))) (list (modulo n 2))))))
;addZeros : Ajoute <nb> zeros à une liste <L>
(define addZeros
(lambda (nb L)
(if (= 0 nb) L (cons 0 (addZeros (- nb 1) L)))))
;bin-format : Formate une liste binaire <bin> de longueur <binlength> sur un nombre de bits <bitNumber>
(define bin-format
(lambda (bin binLength bitNumber)
(cond ((= bitNumber binLength) bin)
((> bitNumber binLength) (addZeros (- bitNumber binLength) bin))
(else (bin-format (cdr bin) (- binLength 1) bitNumber)))))
;number->binListF : Converti un nombre <n> en une liste binaire formatée sur <bitNumber> bits
(define number->binListF
(lambda (n bitNumber)
(let ((bin (number->binList n)))
(bin-format bin (length bin) bitNumber))))
;binToInt : Creer une interpretation à partir d'une liste de symbol prop <LS> et un liste binaire <LBin> de même taille.
;Ex: (binToInt '(a b c) '(0 1 0)) -> ((a . 0) (b . 1) (c . 0))
(define binToInt
(lambda (LS LBin)
(map cons LS LBin)))
;ensInt-acc : Associe avec un binToInt l'ensemble des symbol prop <E> avec toutes les Liste binaire crée avec les valeurs <n> à <nMax>
; formatée sur <nbBit> bits et stock ce resultat dans acc.
(define ensInt-acc
(lambda (E n nMax nbBit acc)
(cond ((null? E) '(()))
((= n nMax) (append acc (list (binToInt E (number->binListF n nbBit)))))
(else (ensInt-acc E (+ n 1) nMax nbBit (append acc (list (binToInt E (number->binListF n nbBit)))))))))
;ensInt : Fonction qui génère l'ensemble des interpretations d'un ensemble de symbol <E>, garantie 100% efficace !
(define ensInt
(lambda (E)
(let ((l (length E)))
(ensInt-acc E 0 (- (expt 2 l) 1) l '()))))
;Q14:
(define satisfiable?
(lambda (fbf)
(ormap (lambda (I) (modele? fbf I)) (ensInt (ensSP fbf)))))
;Q15:
(define valide?
(lambda (fbf)
(andmap (lambda (I) (modele? fbf I)) (ensInt (ensSP fbf)))))
;Q16:
(define insatisfiable?
(lambda (fbf)
(null? (filter (lambda (I) (modele? fbf I)) (ensInt (ensSP fbf))))))
;5)Equivalence et consequence logique
;Q17:
(define equivalent1?
(lambda (fbf1 fbf2)
(letrec ((ensI1 (ensInt (ensSP fbf1))) (ensI2 (ensInt (ensSP fbf2))))
(if (= (length (ensSP fbf1)) (length (ensSP fbf2)))
(andmap eq? (map (lambda (I) (modele? fbf1 I)) ensI1)
(map (lambda (I) (modele? fbf2 I)) ensI2)) #f))))
;Q18:
;Creer une nouvelle fbf avec le connecteur ET et deux fbf.
(define consAnd
(lambda (fbf1 fbf2)
(list '^ fbf1 fbf2)))
;Creer une nouvelle fbf avec le connecteur NON et une fbf.
(define consNeg
(lambda (fbf)
(list '! fbf)))
(define consequence2?
(lambda (F1 F2)
(insatisfiable? (consAnd F1 (consNeg F2)))))
;Q19:
(define ensSPallFbf
(lambda (E)
(if (null? E) '() (remove-duplicated (append (ensSP (car E)) (ensSPallFbf (cdr E)))))))
;Q20:
(define modeleCommun?
(lambda (EnsFbf Int)
(andmap (lambda (fbf) (modele? fbf Int)) EnsFbf)))
;Q21:
(define contradictoire?-int
(lambda (EnsFbf Int)
(cond ((null? Int) #t)
((modeleCommun? EnsFbf (car Int)) #f)
(else (contradictoire?-int EnsFbf (cdr Int))))))
(define contradictoire?
(lambda (EnsFbf)
(contradictoire?-int EnsFbf (ensInt (ensSPallFbf EnsFbf)))))
;Q22:
;Q23:
(define conjonction
(lambda (EnsFbf)
(cond ((null? EnsFbf) '())
((null? (cdr EnsFbf)) (car EnsFbf))
(else (consAnd (car EnsFbf) (conjonction (cdr EnsFbf)))))))
;Q24:
(define consequenceI?
(lambda (EnsFbf fbf)
(consequence2? (conjonction EnsFbf) fbf)))
;6)Mise en forme conjonctive
;Q25:
(define oteEqu
(lambda (f)
(cond ((atomicFbf? f) f)
((negFbf? f) (list (conRac f) (oteEqu (fils f))))
((conBin? (conRac f))
(if (equ? (conRac f))
(list '^ (list '-> (oteEqu (filsG f)) (oteEqu (filsD f))) (list '-> (oteEqu (filsD f)) (oteEqu (filsG f))))
(list (conRac f) (oteEqu (filsG f)) (oteEqu (filsD f)))))
(else (display "Erreur mauvais argument")))))
;Q26:
(define oteImp
(lambda (f)
(cond ((atomicFbf? f) f)
((negFbf? f) (list (conRac f) (oteImp (fils f))))
((conBin? (conRac f))
(if (imp? (conRac f))
(list 'v (list '! (oteImp (filsG f))) (oteImp (filsD f)))
(list (conRac f) (oteImp (filsG f)) (oteImp (filsD f)))))
(else (display "Erreur mauvais argument")))))
;Q27:
(define oteCste
(lambda (f)
(cond ((atomicFbf? f)
(cond ((top? f) (list 'v (list '! 'p) 'p))
((bot? f) (list '^ (list '! 'p) 'p))
(else f)))
((negFbf? f) (list (conRac f) (oteCste (fils f))))
((conBin? (conRac f)) (list (car f) (oteCste (filsG f)) (oteCste (filsD f))))
(else (display "Erreur mauvais argument")))))
;Q28:
(define redNeg
(lambda (f)
(cond ((atomicFbf? f) f)
((negFbf? f)
(cond ((atomicFbf? (fils f)) (list '! (redNeg (fils f))))
((negFbf? (fils f)) (redNeg (fils (fils f))))
((conBin? (conRac (fils f)))
(list (conRac (fils f)) (redNeg (list '! (redNeg (filsG (fils f))))) (redNeg (list '! (redNeg (filsD (fils f)))))))
(else (list (redNeg (fils f))))))
((conBin? (conRac f)) (list (conRac f) (redNeg (filsG f)) (redNeg (filsD f))))
(else (display "Erreur mauvais argument")))))
;Q29:
(define consFbfBinaire
(lambda (s fbf1 fbf2)
(list s fbf1 fbf2)))
(define distOu
(lambda (f)
(cond ((or (symbProp? f) (negFbf? f)) f)
((and? (conRac f)) (consFbfBinaire '^ (distOu (filsG f)) (distOu (filsD f))))
(else (let ((Gprime (distOu (filsG f))) (Hprime (distOu (filsD f))))
(cond ((and(not(atomicFbf? Gprime)) (and?(conRac Gprime)))
(consFbfBinaire '^ (distOu (consFbfBinaire 'v (filsG Gprime) Hprime))
(distOu (consFbfBinaire 'v (filsD Gprime) Hprime))))
((and(not(atomicFbf? Hprime)) (and?(conRac Hprime)))
(consFbfBinaire '^ (distOu (consFbfBinaire 'v (filsG Hprime) Gprime))
(distOu (consFbfBinaire 'v (filsD Hprime) Gprime))))
(else (consFbfBinaire (conRac f) (distOu Gprime) (distOu Hprime)))))))))
;Q30:
(define formeConj
(lambda (f)
(distOu (redNeg (oteCste (oteImp (oteEqu f)))))))
;7)Forme clausale
;Q31:
(define C1 '(^ (^ a (^ (v (! c) a) (v c b))) (^ (v d a) (v d b))))
(define transClause
(lambda (f)
(cond ((atomicFbf? f) (list f))
((negFbf? f) (list (list (conRac f) (car (transClause (fils f))))))
((conBin? (conRac f)) (remove-duplicated (append (transClause (filsG f)) (transClause (filsD f))))))))
;Q32:
| false |
5a732b789cb51ed05bfb23d0ae4af1a52d9b6254 | 4b480cab3426c89e3e49554d05d1b36aad8aeef4 | /chapter-02/ex2.66-falsetru.scm | 9ef637d6d46f6b1274aaa24c7c8ae6489d310d36 | []
| no_license | tuestudy/study-sicp | a5dc423719ca30a30ae685e1686534a2c9183b31 | a2d5d65e711ac5fee3914e45be7d5c2a62bfc20f | refs/heads/master | 2021-01-12T13:37:56.874455 | 2016-10-04T12:26:45 | 2016-10-04T12:26:45 | 69,962,129 | 0 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 363 | scm | ex2.66-falsetru.scm | (load "ex2.63-falsetru.scm")
(define (key x) x)
(define (lookup given-key tree)
(cond ((null? tree) false)
((equal? given-key (key (entry tree)))
(entry tree))
((< given-key (key (entry tree)))
(lookup given-key (left-branch tree)))
((> given-key (key (entry tree)))
(lookup given-key (right-branch tree)))))
| false |
fe25c967aeb68ff9ed648f1a17f117e09f2ec1bb | 41f780f7b029ff51bea4a4901130bbd0e177508b | /demos/ca-spirals.sps | ac9e172f3c37512a830eb587c5013d32f5e287b6 | []
| no_license | atog/agave | 9becafd1828763c8f216ad27a318c5c991c8ff86 | 1dd11938e3b5fae30b3db5163bd7564a51908dec | refs/heads/master | 2020-12-25T08:59:26.336223 | 2010-03-25T16:57:55 | 2010-03-25T16:57:55 | null | 0 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 121 | sps | ca-spirals.sps |
(import (agave demos ca-gen))
(ca-gen (width 100)
(height 100)
(S 2)
(B 2 3 4)
(C 5))
| false |
61a6ebb196b0f004ee1b54606d1be94f59e932ac | 751ddc7cb3baf75bccc8e04d9e83750a3af9fabd | /asg1/Examples/blowstack.scm | 9fd498c11a4078ef73ecd34a80023eab4cb4c8c7 | []
| no_license | BrightSun95/CMPS112 | 961bd2ec30207b74147a2419822123f871f4fedf | d427e31c4d4880cdc479d8d7d80e55b7dd594976 | refs/heads/master | 2021-07-20T00:03:10.588349 | 2017-10-24T16:59:07 | 2017-10-24T16:59:07 | 107,214,925 | 0 | 2 | null | null | null | null | UTF-8 | Scheme | false | false | 530 | scm | blowstack.scm | #!/afs/cats.ucsc.edu/courses/cmps112-wm/usr/racket/bin/mzscheme -qr
;; $Id: blowstack.scm,v 1.4 2017-10-05 15:44:50-07 - - $
;;
;; Blow the stack by infinite recursion. This function is not
;; a tail call.
;;
(define modulus 1000000)
(define (memory-use)
(truncate (/ (current-memory-use) (* 1024 1024))))
(define (recur count)
(when (= (remainder count modulus) 0)
(printf "count = ~a, memory = ~a M~n"
count (memory-use)))
(+ 1 (recur (+ 1 count))))
(recur 0)
| false |
0120d079af2bca2a118da3c5694683f1f2c8c5b9 | 4b2aeafb5610b008009b9f4037d42c6e98f8ea73 | /23.2/figure-23.4-prim.scm | 99f0107bec2d46815550258a13caded9ac85a576 | []
| 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 | 351 | scm | figure-23.4-prim.scm | (require-extension check (srfi 1))
(require 'section)
(require '../util/util)
(import section-23.2)
(import util)
(let* ((graph (figure-23.1))
(root (find (lambda (node) (eq? 'a (node-label node)))
(graph-nodes graph))))
;;; (debug (map node-label (adjacent-nodes graph root)))
(minimum-spanning-tree/prim graph root)
)
| false |
b86fb4516d5b3d8da2ec0d782ceb18ba57378626 | 9998f6f6940dc91a99e0e2acb4bc4e918f49eef0 | /src/collects/moby/runtime/error-struct.ss | 7bf415bfb15936acd56a1fa672450e522367ae82 | []
| no_license | JessamynT/wescheme-compiler2012 | 326d66df382f3d2acbc2bbf70fdc6b6549beb514 | a8587f9d316b3cb66d8a01bab3cf16f415d039e5 | refs/heads/master | 2020-05-30T07:16:45.185272 | 2016-03-19T07:14:34 | 2016-03-19T07:14:34 | 70,086,162 | 0 | 0 | null | 2016-10-05T18:09:51 | 2016-10-05T18:09:51 | null | UTF-8 | Scheme | false | false | 15,481 | ss | error-struct.ss | #lang s-exp "../../../private/restricted-runtime-scheme.ss"
(require "stx.ss")
(require "arity-struct.ss")
(define-struct moby-error (location error-type))
;; The following provides colored message support. A Message is a kind of moby-error-type.
(define-struct Message (parts))
(define-struct ColoredPart (text loc))
(define-struct GradientPart (parts)) ;; (listof ColoredPart)
(define-struct MultiPart (text locs solid))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; The parser errors:
;; A lexical token hasn't been closed (e.g. a string literal without closing quote)
(define-struct moby-error-type:unclosed-lexical-token (type opener closer))
;; A lexical token has been seen that we don't know how to lex.
(define-struct moby-error-type:unrecognized-lexical-token (token))
;; A lexical token has been seen that we don't support (e.g. dotted pairs)
(define-struct moby-error-type:unsupported-lexical-token (token))
;; An unsupported expression form has shown up
(define-struct moby-error-type:unsupported-expression-form (expr))
;; e.g. "("
(define-struct moby-error-type:unclosed-parentheses (opener closer))
;; e.g. ")",
(define-struct moby-error-type:closing-parenthesis-before-opener (closer))
;; If the parentheses are closed by a paren of unexpected shape, we raise
;; unbalanced-parentheses.
;; e.g. "( ]"
(define-struct moby-error-type:unbalanced-parentheses (opener closer observed other-location))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(define-struct moby-error-type:syntax-not-applied (keyword example))
(define-struct moby-error-type:duplicate-identifier (id second-location))
(define-struct moby-error-type:expected-identifier (observed))
(define-struct moby-error-type:expected-list-of-identifiers (who observed))
(define-struct moby-error-type:undefined-identifier (id))
(define-struct moby-error-type:structure-identifier-not-expression (id))
(define-struct moby-error-type:provided-name-not-defined (id))
(define-struct moby-error-type:provided-structure-not-structure (id))
(define-struct moby-error-type:unknown-module (path))
(define-struct moby-error-type:redefinition-not-allowed (id))
(define-struct moby-error-type:conditional-missing-question-answer ())
(define-struct moby-error-type:conditional-malformed-clause ())
(define-struct moby-error-type:conditional-clause-too-few-elements ())
(define-struct moby-error-type:conditional-clause-too-many-elements ())
(define-struct moby-error-type:conditional-exhausted ())
(define-struct moby-error-type:branch-value-not-boolean (observed))
(define-struct moby-error-type:if-too-few-elements ())
(define-struct moby-error-type:if-too-many-elements ())
(define-struct moby-error-type:missing-expression-following-quote (quote-stx)) ;; e.g. (list hello ')
(define-struct moby-error-type:quote-too-few-elements ())
(define-struct moby-error-type:quote-too-many-elements ())
(define-struct moby-error-type:quasiquote-too-few-elements ())
(define-struct moby-error-type:quasiquote-too-many-elements ())
(define-struct moby-error-type:unquote-too-few-elements ())
(define-struct moby-error-type:unquote-too-many-elements ())
(define-struct moby-error-type:unquote-splicing-too-few-elements ())
(define-struct moby-error-type:unquote-splicing-too-many-elements ())
(define-struct moby-error-type:begin-body-empty ())
(define-struct moby-error-type:boolean-chain-too-few-elements (id))
(define-struct moby-error-type:lambda-too-few-elements ())
(define-struct moby-error-type:lambda-too-many-elements ())
(define-struct moby-error-type:when-no-body ())
(define-struct moby-error-type:unless-no-body ())
(define-struct moby-error-type:check-expect (expected observed))
(define-struct moby-error-type:check-within (expected observed within))
(define-struct moby-error-type:check-error (expected observed))
(define-struct moby-error-type:check-error-no-error (expected observed))
(define-struct moby-error-type:application-arity (who expected observed))
(define-struct moby-error-type:application-operator-not-a-function (who val))
(define-struct moby-error-type:type-mismatch (who position expected observed))
(define-struct moby-error-type:index-out-of-bounds (minimum maximum observed))
(define-struct moby-error-type:generic-runtime-error (reason))
;; FIXME: the generic-syntactic-error class should die as soon as I fully enumerate
;; the errors.
(define-struct moby-error-type:generic-syntactic-error (reason other-locations))
(define-struct moby-error-type:generic-read-error (message locations))
;; moby-error-type: any -> boolean
;; Produces true if x is a moby-error-type.
(define (moby-error-type? x)
(or (Message? x)
(moby-error-type:unclosed-lexical-token? x)
(moby-error-type:unrecognized-lexical-token? x)
(moby-error-type:unsupported-lexical-token? x)
(moby-error-type:unsupported-expression-form? x)
(moby-error-type:unclosed-parentheses? x)
(moby-error-type:unbalanced-parentheses? x)
(moby-error-type:syntax-not-applied? x)
(moby-error-type:closing-parenthesis-before-opener? x)
(moby-error-type:duplicate-identifier? x)
(moby-error-type:expected-identifier? x)
(moby-error-type:expected-list-of-identifiers? x)
(moby-error-type:undefined-identifier? x)
(moby-error-type:structure-identifier-not-expression? x)
(moby-error-type:provided-name-not-defined? x)
(moby-error-type:provided-structure-not-structure? x)
(moby-error-type:unknown-module? x)
(moby-error-type:redefinition-not-allowed? x)
(moby-error-type:conditional-missing-question-answer? x)
(moby-error-type:conditional-exhausted? x)
(moby-error-type:conditional-missing-question-answer? x)
(moby-error-type:conditional-malformed-clause? x)
(moby-error-type:conditional-clause-too-few-elements? x)
(moby-error-type:conditional-clause-too-many-elements? x)
(moby-error-type:branch-value-not-boolean? x)
(moby-error-type:if-too-few-elements? x)
(moby-error-type:if-too-many-elements? x)
(moby-error-type:boolean-chain-too-few-elements? x)
(moby-error-type:begin-body-empty? x)
(moby-error-type:lambda-too-many-elements? x)
(moby-error-type:lambda-too-few-elements? x)
(moby-error-type:missing-expression-following-quote? x)
(moby-error-type:quote-too-few-elements? x)
(moby-error-type:quote-too-many-elements? x)
(moby-error-type:quasiquote-too-few-elements? x)
(moby-error-type:quasiquote-too-many-elements? x)
(moby-error-type:unquote-too-few-elements? x)
(moby-error-type:unquote-too-many-elements? x)
(moby-error-type:unquote-splicing-too-few-elements? x)
(moby-error-type:unquote-splicing-too-many-elements? x)
(moby-error-type:when-no-body? x)
(moby-error-type:unless-no-body? x)
(moby-error-type:check-expect? x)
(moby-error-type:check-within? x)
(moby-error-type:check-error? x)
(moby-error-type:check-error-no-error? x)
(moby-error-type:application-arity? x)
(moby-error-type:application-operator-not-a-function? x)
(moby-error-type:type-mismatch? x)
(moby-error-type:index-out-of-bounds? x)
(moby-error-type:generic-runtime-error? x)
(moby-error-type:generic-syntactic-error? x)
(moby-error-type:generic-read-error? x)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(define-struct moby-expected:string ())
(define-struct moby-expected:integer ())
(define-struct moby-expected:natural ())
(define-struct moby-expected:rational ())
(define-struct moby-expected:real ())
(define-struct moby-expected:complex ())
(define-struct moby-expected:number ())
(define-struct moby-expected:boolean ())
(define-struct moby-expected:char ())
(define-struct moby-expected:symbol ())
(define-struct moby-expected:list ())
(define-struct moby-expected:listof (thing))
(define-struct moby-expected:vector ())
(define-struct moby-expected:struct ())
(define-struct moby-expected:box ())
(define-struct moby-expected:hash ())
(define-struct moby-expected:function ())
(define-struct moby-expected:something (description))
;; moby-expected?: any -> boolean
;; Produces true if x is an expected value.
(define (moby-expected? x)
(ormap (lambda (pred?)
(pred? x))
(list
moby-expected:string?
moby-expected:integer?
moby-expected:natural?
moby-expected:rational?
moby-expected:real?
moby-expected:complex?
moby-expected:number?
moby-expected:boolean?
moby-expected:char?
moby-expected:symbol?
moby-expected:list?
moby-expected:vector?
moby-expected:struct?
moby-expected:box?
moby-expected:hash?
moby-expected:function?
moby-expected:something?)))
(define (-make-Message . args)
(make-Message args))
(provide [rename-out [-make-Message make-Message]]
Message? Message-parts
[struct-out ColoredPart]
[struct-out GradientPart])
(provide/contract
[struct MultiPart ([text string?]
[locs (non-empty-listof Loc?)]
[solid boolean?])])
(provide/contract
[struct moby-error ([location Loc?]
[error-type moby-error-type?])]
[moby-error-type? (any/c . -> . boolean?)]
[struct moby-error-type:unclosed-lexical-token ([type string?]
[opener symbol?]
[closer symbol?])]
[struct moby-error-type:unrecognized-lexical-token ([token symbol?])]
[struct moby-error-type:unsupported-lexical-token ([token symbol?])]
[struct moby-error-type:unsupported-expression-form ([expr stx?])]
[struct moby-error-type:unclosed-parentheses ([opener symbol?]
[closer symbol?])]
[struct moby-error-type:unbalanced-parentheses ([opener symbol?]
[closer symbol?]
[observed symbol?]
[other-location Loc?])]
[struct moby-error-type:closing-parenthesis-before-opener ([closer symbol?])]
[struct moby-error-type:syntax-not-applied ([keyword stx?]
[example any/c])]
[struct moby-error-type:duplicate-identifier ([id symbol?]
[second-location Loc?])]
[struct moby-error-type:expected-identifier ([observed stx?])]
[struct moby-error-type:expected-list-of-identifiers ([who stx?]
[observed stx?])]
[struct moby-error-type:undefined-identifier ([id symbol?])]
[struct moby-error-type:structure-identifier-not-expression ([id symbol?])]
[struct moby-error-type:provided-name-not-defined ([id symbol?])]
[struct moby-error-type:provided-structure-not-structure ([id symbol?])]
[struct moby-error-type:unknown-module ([path module-path?])]
[struct moby-error-type:redefinition-not-allowed ([id symbol?])]
[struct moby-error-type:conditional-missing-question-answer ()] ;; missing clauses
[struct moby-error-type:conditional-malformed-clause ()] ;; a clause which isn't an [question answer]
[struct moby-error-type:conditional-clause-too-few-elements ()] ;; a clause without a question or an answer
;; a clause with too many answer values. stx stx
[struct moby-error-type:conditional-clause-too-many-elements ()]
[struct moby-error-type:conditional-exhausted ()] ;; runtime: no answer was true
[struct moby-error-type:branch-value-not-boolean ([observed any/c])]
[struct moby-error-type:if-too-few-elements ()] ;; e.g. (if x)
[struct moby-error-type:if-too-many-elements ()] ;; (if x y z w)
[struct moby-error-type:begin-body-empty ()] ;; e.g. (begin)
[struct moby-error-type:boolean-chain-too-few-elements ([id symbol?])]
[struct moby-error-type:lambda-too-many-elements ()]
[struct moby-error-type:lambda-too-few-elements ()]
[struct moby-error-type:missing-expression-following-quote ([quote-stx stx?])]
[struct moby-error-type:quote-too-few-elements ()]
[struct moby-error-type:quote-too-many-elements ()]
[struct moby-error-type:quasiquote-too-few-elements ()]
[struct moby-error-type:quasiquote-too-many-elements ()]
[struct moby-error-type:unquote-too-few-elements ()]
[struct moby-error-type:unquote-too-many-elements ()]
[struct moby-error-type:unquote-splicing-too-few-elements ()]
[struct moby-error-type:unquote-splicing-too-many-elements ()]
[struct moby-error-type:when-no-body ()]
[struct moby-error-type:unless-no-body ()]
[struct moby-error-type:check-expect ([expected any/c]
[observed any/c])]
[struct moby-error-type:check-within ([expected any/c]
[observed any/c]
[within any/c])]
[struct moby-error-type:check-error ([expected string?] ;; the expected string of the error message
[observed string?])] ;; the observed string
[struct moby-error-type:check-error-no-error ([expected string?]
[observed any/c])]
[struct moby-error-type:application-arity ([who any/c]
[expected arity?]
[observed any/c])]
[struct moby-error-type:application-operator-not-a-function ([who any/c] ;; who is the operator
[val any/c] ;; what value
;; did the operator produce?
)]
[struct moby-error-type:type-mismatch ([who any/c]
[position number?]
[expected any/c]
[observed any/c])]
[struct moby-error-type:index-out-of-bounds ([minimum number?]
[maximum number?]
[observed number?])]
[struct moby-error-type:generic-runtime-error ([reason string?])]
[struct moby-error-type:generic-syntactic-error ([reason string?]
[other-locations (listof Loc?)])]
[struct moby-error-type:generic-read-error ([message string?]
[locations (listof Loc?)])]
[moby-expected? (any/c . -> . boolean?)]
[struct moby-expected:string ()]
[struct moby-expected:integer ()]
[struct moby-expected:natural ()]
[struct moby-expected:rational ()]
[struct moby-expected:real ()]
[struct moby-expected:complex ()]
[struct moby-expected:number ()]
[struct moby-expected:boolean ()]
[struct moby-expected:char ()]
[struct moby-expected:symbol ()]
[struct moby-expected:list ()]
[struct moby-expected:listof ([thing moby-expected?])]
[struct moby-expected:vector ()]
[struct moby-expected:struct ()]
[struct moby-expected:box ()]
[struct moby-expected:hash ()]
[struct moby-expected:function ()]
[struct moby-expected:something ([description string?])])
| false |
983d8932bd6e1425264ece6b6d01b901c9e3fbf2 | ccd36329266324496e5ee15a51d87971a4ad2295 | /kawa_jogl/asteroids2d/asteroids2d.scm | 5a108294e32049a1392dd9578f87a349431b94a1 | []
| no_license | aweinstock314/lisp-stuff | 5b15366836190fbde37227d3ec77cdc08e026091 | ef132d54907a3ee152c91e776f08689dae7243f6 | refs/heads/master | 2021-01-22T09:18:02.485208 | 2014-12-09T21:45:50 | 2014-12-09T21:45:50 | 20,958,912 | 1 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 30,176 | scm | asteroids2d.scm | (require <scheme_util_general>)
(require <scheme_util_math>)
(require <asteroids_util_opengl>)
(define +multiplayer-mode+ #f)
(define *constant-buffer* '())
(define (make-constant-polygon poly::polygon) (inplace-polybuffer-append! *constant-buffer* poly))
(define *show-extra-debugging-views* #f)
(define-constant +cs-per-frame+ (/ 100 30)) ; centiseconds
(define-constant +score-fmtstr+ "Score: %s")
(define-constant +lives-fmtstr+ "Lives: %s")
(define-constant +level-fmtstr+ "Level: %s")
(set-variables-from-cmdline
(
((#\h #\? "help") (svfc-display-all-options) (java.lang.System:exit 0))
(("multiplayer") (set! +multiplayer-mode+ #t))
)
;; GUI settings
(+screen-width+ 640 ("screen-width") Integer:parseInt)
(+screen-height+ 480 ("screen-height") Integer:parseInt)
; the real values are double this, since these are used as plus/minus
(+logical-width+ 4 ("arena-width") parse-double)
(+logical-height+ 4 ("arena-height") parse-double)
(+viewport-width+ 3 ())
(+viewport-height+ 3 ())
(+background-intensity+ .5 ("background-intensity") () parse-double)
(+initial-score+ 0 ("initial-score") () Integer:parseInt)
(+initial-lives+ 3 ("initial-lives") () Integer:parseInt)
(+initial-level+ 1 ("initial-level") () Integer:parseInt)
;; Gameplay settings
(+shot-color+ '(1 1 1) ())
(+shot-speed+ (/ .2 +cs-per-frame+) ("shot-speed") parse-double)
(+shot-size+ .01 ("shot-size") parse-double)
(+shot-momentum-factor+ 2.5 ("shot-momentum") parse-double)
(+shot-duration+ (* (/ 45 2) +cs-per-frame+) ("shot-duration") parse-double)
(+shot-collision-granularity+ 10 () Integer:parseInt)
(+centiseconds-between-shots+ (* 10 +cs-per-frame+) ("shot-delay") parse-double)
(+min-ship-speed+ (/ -0.09 +cs-per-frame+) ("min-ship-speed") parse-double)
(+max-ship-speed+ (/ 0.10 +cs-per-frame+) ("max-ship-speed") parse-double)
(+min-asteroid-size+ .1 ("min-asteroid-size") parse-double)
(+max-asteroid-size+ .5 ("max-asteroid-size") parse-double)
(+min-asteroid-ivel+ (/ .01 +cs-per-frame+) ("min-initial-asteroid-speed") parse-double)
(+max-asteroid-ivel+ (/ .05 +cs-per-frame+) ("max-initial-asteroid-speed") parse-double)
(+asteroid-speed-multiplier+ 1 ("asteroid-speed-multiplier") parse-double)
(+asteroids-per-level+ 5 ("asteroids-per-level") Integer:parseInt)
; these have to do with input sensitivity, not sure if they belong here or in GUI constants section
(+rotation-delta+ (/ (/ tau 64) +cs-per-frame+) ("rotation-sensitivity") parse-double)
(+velocity-delta+ (/ .01 (* 2 +cs-per-frame+)) ("acceleration-sensitivity") parse-double)
) ; end of set-variables-from-cmdline
(define-constant background (make-constant-polygon
;(calc-poly
; (/ tau 8) (constantly (sqrt (* 2 (square +logical-width+)))) 4
(make-rectangle +logical-width+ +logical-height+
(lambda (i) (case i
((0) (values +background-intensity+ +background-intensity+ 0))
((1) (values 0 +background-intensity+ +background-intensity+))
((2) (values 0 0 +background-intensity+))
((3) (values 0 +background-intensity+ 0))
))
)))
(define-constant +respawn-box-vertidx+ (make-constant-polygon (calc-poly (/ tau 8) (constantly (sqrt 2)) 4 (constantly (values 0 .25 .25)))))
(define-constant white-bg (make-constant-polygon (calc-poly 0 (constantly 20) 4 (constantly (values 1 1 1)))))
(define-constant black-dot (make-constant-polygon (calc-poly 0 (constantly .01) 10 (constantly (values 0 0 0)))))
(define-constant blue-dot (make-constant-polygon (calc-poly 0 (constantly .01) 10 (constantly (values 0 0 1)))))
(define-constant +shot-vertidx+ (make-constant-polygon (calc-poly 0 (constantly +shot-size+) 10 (constantly (apply values +shot-color+)))))
(define +window-width+ (if +multiplayer-mode+ (* 2 +screen-width+) +screen-width+))
(define +window-height+ (if *show-extra-debugging-views* (* 1.5 +screen-height+) +screen-height+))
(define-constant +label-dimensions+ (java.awt.Dimension 128 32))
(define-simple-class UnselectableTextField (javax.swing.JFormattedTextField)
((processMouseEvent ev::java.awt.event.MouseEvent)::void access: 'protected
#!void
)
)
(define (initialize-label c::java.awt.Container label::UnselectableTextField x y)
(label:setPreferredSize +label-dimensions+)
(c:add label)
(label:setBounds x y (+label-dimensions+:getWidth) (+label-dimensions+:getHeight))
)
(define (update-label label::UnselectableTextField fmt::String val::String)
(label:setValue (String:format fmt val))
)
;; Game objects
(define-simple-class drawer () interface: #t
((draw gl2::GL2 is::interface-state) #!abstract)
)
(define-simple-class shot (drawer)
(x::double 0) (y::double 0)
(rot::double 0)
(velocity::double 0)
(centiseconds-until-decay::int +shot-duration+)
(play::player) ; originating player, used for scoring
((*init* p::player ix iy irot ivel)
(set! play p)
(set! x ix)
(set! y iy)
(set! rot irot)
(set! velocity (+ ivel +shot-speed+)) ; shots start off with the ship's velocity added to the constant
)
((updatePosition!)
(inc! centiseconds-until-decay -1)
(set-values! (x y) (apply-polar-movement x y velocity rot))
(inplace! (wrap (- +logical-width+) +logical-width+) x)
(inplace! (wrap (- +logical-height+) +logical-height+) y)
)
((expired?) (< centiseconds-until-decay 0))
((draw gl2 is) (drawPolygon gl2 is:cbuf x y rot +shot-vertidx+))
)
(define-simple-class ship (drawer)
(x::double 0) (y::double 0)
(rot::double (/ tau 4))
(velocity::double 0)
(size .1)
(color '(1 .5 0))
(shooting-cooldown::int 0)
(spawnx::double) (spawny::double)
(shield-active::boolean #t)
(playernumber::integer 1)
((constructor-helper is::interface-state) access: 'private
(recalcVerts! is)
(set! rot (/ tau 4))
)
((*init* is::interface-state) (constructor-helper is))
((*init* is::interface-state num r g b) (set!* (playernumber color) (num (list r g b))) (constructor-helper is))
(vertidx)
((recalcVerts! is::interface-state) (set! vertidx (is:add-ship-poly (calc-poly 0 (lambda (i) (if (= i 0) (* 2 size) size)) 3 (constantly (apply values color)))))) ; isosceles triangle
((rotate delta::double) (inc! rot delta))
((getVertidx) vertidx)
((updatePosition!)
(if (> shooting-cooldown 0) (inc! shooting-cooldown -1))
(set-values! (x y) (apply-polar-movement x y velocity rot))
(inplace! (wrap (- +logical-width+) +logical-width+) x)
(inplace! (wrap (- +logical-height+) +logical-height+) y)
)
((draw gl2 is) (drawPolygon gl2 is:cbuf x y rot vertidx))
((shoot! gs::game-state)
(gs:active-shots:add (shot (invoke gs:players 'get playernumber) x y rot velocity))
(set! shooting-cooldown +centiseconds-between-shots+)
)
((resetPosition&Momentum!)
(set!* (x y rot velocity) (spawnx spawny (/ tau 4) 0))
)
)
(define-alias HashSet java.util.HashSet)
(define-simple-class input-controls ()
(rotate-left::symbol) (rotate-right::symbol)
(accelerate::symbol) (decelerate::symbol)
(shoot::symbol)
((*init* rl rr a d s) (set!* (rotate-left rotate-right accelerate decelerate shoot) (rl rr a d s)))
((process currently-held-keys::HashSet shp::ship gs::game-state)
(define-macro (key-held? key) `(invoke currently-held-keys 'contains (static-field KeyEvent ,key)))
(if (key-held? rotate-left) (shp:rotate +rotation-delta+))
(if (key-held? rotate-right) (shp:rotate (- +rotation-delta+)))
(if (key-held? accelerate) (inc! shp:velocity +velocity-delta+))
(if (key-held? decelerate) (inc! shp:velocity (- +velocity-delta+)))
(if (and (key-held? shoot) (= shp:shooting-cooldown 0)) (shp:shoot! gs))
(if (or (key-held? rotate-left) (key-held? rotate-right) (key-held? accelerate) (key-held? decelerate) (key-held? shoot))
(set! shp:shield-active #f)
)
)
)
(define-simple-class asteroid (drawer)
(x::double (random-range (- +logical-width+) +logical-width+))
(y::double (random-range (- +logical-height+) +logical-height+))
(rot::double (random tau))
(velocity::double (random-range +min-asteroid-ivel+ +max-asteroid-ivel+))
(size (random-range +min-asteroid-size+ +max-asteroid-size+))
(vertidx #!null)
(children::ArrayList[asteroid] #!null)
(dx::double 0) (dy::double 0) ; deltas from center of generated polygon, for children
((constructor-helper is::interface-state poly::polygon) access: 'private
(set! vertidx (is:add-asteroid-poly poly))
(set! children (ArrayList-map (cut asteroid is <>) (divide-poly poly)))
(receive (xs ys) (ArrayList-foldl
(lambda (acc v::vertex) (receive (xs ys) acc (values (cons v:x xs) (cons v:y ys))))
poly:verts
(values '() '())
)
(set!* (dx dy) ((apply average xs) (apply average ys)))
)
)
((*init* is::interface-state)
(constructor-helper is (calc-poly (random tau) (constantly size) (random-range 3 9) (thunk (values (random-range .25 .65) 0 0))))
)
((*init* is::interface-state poly::polygon) (constructor-helper is poly))
((draw gl2 is) (drawPolygon gl2 is:cbuf x y rot vertidx))
((updatePosition!)
(set-values! (x y) (apply-polar-movement x y (* +asteroid-speed-multiplier+ velocity) rot))
(inplace! (wrap (- +logical-width+) +logical-width+) x)
(inplace! (wrap (- +logical-height+) +logical-height+) y)
)
((split gs::game-state s::shot r v) ; takes rotation and velocity of incoming shot, for momentum calculation
;(printf "splitting asteroid at (%f, %f), %d children\n" x y (children:size))
(inc! (field s:play 'score) 1)
(java-iterate children c
(set!* (c:x c:y) (x y))
; maybe add some factor based on child centers, instead of the random factor?
(define randfactor (random-range (/ (- tau) 16) (/ tau 16)))
(define c1 (polar->cart (values (* v +shot-momentum-factor+ +shot-size+) r)))
(define c2 (polar->cart (values (* velocity size) rot)))
(receive (m t) (cart->polar (cart+ c1 c2))
(set!* (c:velocity c:rot) ((/ m size) (ensure-proper-angle (+ randfactor t))))
)
((field gs 'active-asteroids):add c)
)
)
)
(define-simple-class player ()
(shp::ship)
(score +initial-score+)
(lives +initial-lives+)
(scorelabel (UnselectableTextField))
(liveslabel (UnselectableTextField))
((*init* s::ship) (set! shp s))
)
(define-simple-class game-state ()
((*init* is::interface-state)
(set! interface is)
(let ((ship1 (ship interface)))
(active-ships:add ship1)
(players:put ship1:playernumber (player ship1))
(if +multiplayer-mode+
(player-controls:put ship1 (input-controls 'VK_A 'VK_D 'VK_W 'VK_S 'VK_1))
(player-controls:put ship1 (input-controls 'VK_LEFT 'VK_RIGHT 'VK_UP 'VK_DOWN 'VK_SPACE))
)
)
(if +multiplayer-mode+ (let ((ship2 (ship interface 2 0 0 1)))
(active-ships:add ship2)
(set!* (ship2:spawnx ship2:spawny) (2 0))
(ship2:resetPosition&Momentum!)
(players:put ship2:playernumber (player ship2))
(player-controls:put ship2 (input-controls 'VK_LEFT 'VK_RIGHT 'VK_UP 'VK_DOWN 'VK_SPACE))
))
)
(interface::interface-state #!null)
(player-controls::HashMap[ship input-controls] (HashMap))
(players::HashMap[integer player] (HashMap))
(active-ships::ArrayList[ship] (ArrayList))
(active-shots::ArrayList[shot] (ArrayList))
(active-asteroids::ArrayList[asteroid] (ArrayList))
(level +initial-level+)
(levellabel (UnselectableTextField))
(buffer-needs-reset #f)
(eventloop-render-mutex (java.lang.Object))
((spawn-asteroids! amount::integer)
(dotimes (i amount) (active-asteroids:add (asteroid interface)))
)
((player-death! p::player iter::java.util.Iterator[player])
(define shp p:shp)
(shp:resetPosition&Momentum!)
(set! shp:shield-active #t)
(inc! p:lives -1)
(if (< p:lives 0)
(begin
(printf "Game over for player %s.\nTheir score was %s.\n" shp:playernumber p:score)
(iter:remove)
(player-controls:remove shp)
;(if (= (active-ships:size) 0) (java.lang.System:exit 0))
)
(printf "Lives remaining for player %s: %s\n" shp:playernumber p:lives)
)
)
((level-cleared!)
(printf "Level %s cleared! Making %s new asteroids!\n" level (* level +asteroids-per-level+))
(inc! level 1)
(active-shots:clear)
(java-iterate active-ships (shp ship)
(set! shp:shield-active #t)
(shp:resetPosition&Momentum!)
)
(set! interface:asteroids-polybuf '())
(spawn-asteroids! (* level +asteroids-per-level+))
(set! buffer-needs-reset #t)
)
)
;(install-sharpdot-reader)
(define-simple-class interface-state ()
(displayed-victory-message #f)
(currently-held-keys::HashSet (HashSet))
(shader-program ::int 0)
(whole-area-matrix::PMVMatrix #!null)
(whole-area-dims::int[] #!null)
(recent-mouse-obj-coords (values 0 0))
(cbuf::concatenated-buffer)
(ships-polybuf '())
(asteroids-polybuf '())
((add-ship-poly p::polygon) (inplace-polybuffer-append! ships-polybuf p))
((add-asteroid-poly p::polygon) (inplace-polybuffer-append! asteroids-polybuf p))
((reset-polygons-buffer! gl2::GL2)
(set! cbuf (concatenate-buffers (append *constant-buffer* ships-polybuf asteroids-polybuf)))
(set-polygons-buffer gl2 cbuf)
;(set! shader-program (make-shader-program gl2 #.(slurp-file "identityshader.vert") #.(slurp-file "identityshader.frag")))
(set! shader-program (make-shader-program gl2 (file-as-string-constant "identityshader.vert") (file-as-string-constant "identityshader.frag")))
(define pos-attrib ::int (gl2:glGetAttribLocation shader-program "position"))
(gl2:glVertexAttribPointer pos-attrib 3 gl2:GL_FLOAT #f 24 0)
(gl2:glEnableVertexAttribArray pos-attrib)
(define color-attrib ::int (gl2:glGetAttribLocation shader-program "color"))
(gl2:glVertexAttribPointer color-attrib 3 gl2:GL_FLOAT #f 24 12)
(gl2:glEnableVertexAttribArray color-attrib)
(gl2:glUseProgram shader-program)
)
((mousecoords->objcoords x y)
(if (or (equal? #!null whole-area-matrix)
(equal? #!null whole-area-dims))
(values 0 0)
(begin
(define output (float[] length: 3))
; the subtraction is because AWT has the origin at the upper-left, OpenGL has it at bottom-left
(whole-area-matrix:gluUnProject x (- +window-height+ y) 0 whole-area-dims 0 output 0)
(values (output 0) (output 1))
)
)
)
)
(define (closest-asteroid-to-point asteroids x y)::asteroid
(define (sqr-dist a::asteroid)
(define dx (- (- a:x a:dx) x))
(define dy (- (- a:y a:dy) y))
(define sd (+ (* dx dx) (* dy dy))) ; workaround for "java.lang.Double cannot be cast to gnu.math.Quantity"
;(printf "squaredist between (%s, %s) and (%s, %s) is %s\n" x y a:x a:y sd)
(cons a sd)
)
; this type of transform is probably rather inefficient without deforestation and inlining, revise later
(car (ArrayList-foldl (lambda (acc elem) (if (< (cdr acc) (cdr elem)) acc elem))
(ArrayList-map sqr-dist asteroids)
(cons #!null Integer:MAX_VALUE)
)
)
)
;(define (asteroids-near-point asteroids::ArrayList[asteroid] x y thresh)
; (define (sqr-dist a::asteroid)
; (define dx (- a:x x))
; (define dy (- a:y y))
; (+ (* dx dx) (* dy dy))
; )
; (define sqrthresh (* thresh thresh))
; (with-list-collector col
; (java-iterate asteroids (a asteroid)
; (if (< (sqr-dist a) sqrthresh) (col a))
; )
; )
;)
(define-macro (with-asteroids-near-point asteroids x y thresh . body)
(define sqrthresh (* thresh thresh))
(define-gensyms xtmp ytmp)
`(let* (
(,xtmp ,x)
(,ytmp ,y)
(sqr-dist (lambda (a::asteroid)
(define dx (- a:x ,xtmp))
(define dy (- a:y ,ytmp))
(+ (* dx dx) (* dy dy))
))
)
(java-iterate ,asteroids (a asteroid)
(if (< (sqr-dist a) ,sqrthresh) ,@body)
)
)
)
(define (split-if-closest-asteroid-overlaps-point! gs::game-state is::interface-state x y rot vel)
(define a (closest-asteroid-to-point gs:active-asteroids x y))
(if (equal? a #!null) #f
(if (inside-poly? is:cbuf a:vertidx a:x a:y a:rot x y)
(begin
(a:split gs #!null rot vel)
(gs:active-asteroids:remove a)
#t
)
#f
)
)
)
(define (split-if-nearby-asteroid-overlaps-point! gs::game-state is::interface-state s::shot)
(call-with-current-continuation (lambda (break)
(dotimes (i +shot-collision-granularity+)
(define step-fraction (/ i +shot-collision-granularity+))
;(for-each (lambda (a::asteroid)
(with-asteroids-near-point gs:active-asteroids s:x s:y .5
(receive (x y) (apply-polar-movement s:x s:y (* s:velocity step-fraction) s:rot)
(when (inside-poly? is:cbuf a:vertidx a:x a:y a:rot x y)
(a:split gs s s:rot s:velocity)
(invoke gs:active-asteroids 'remove a)
(break #t)
)
)
)
;) (asteroids-near-point gs:active-asteroids s:x s:y .5))
)
(break #f)
))
)
(define (event-loop gs::game-state is::interface-state)
(unless (equal? is:cbuf #!null)
(java-iterate gs:active-ships (shp ship)
(aif/nn (invoke gs:player-controls 'get shp) (begin
(invoke it 'process is:currently-held-keys shp gs)
(inplace! (clamp +min-ship-speed+ +max-ship-speed+) shp:velocity)
(shp:updatePosition!)
))
)
(java-iterate gs:active-shots (s shot iter)
(s:updatePosition!)
(if (or (split-if-nearby-asteroid-overlaps-point! gs is s) (s:expired?))
(iter:remove)
)
)
(java-iterate gs:active-asteroids (a asteroid)
(a:updatePosition!)
(java-iterate gs:active-ships (shp ship)
(when shp:shield-active
(define respawn-pusher (push-outside (- shp:spawnx 1) (- shp:spawny 1) 2 2)) ; probably optimize by moving this to a field on ship/player later
(set-values! (a:x a:y) (respawn-pusher a:x a:y))
)
)
(java-iterate gs:active-ships (shp ship iter)
(if (inside-poly? is:cbuf a:vertidx a:x a:y a:rot shp:x shp:y)
(gs:player-death! (invoke gs:players 'get shp:playernumber) iter)
)
)
)
(when (and (gs:active-asteroids:isEmpty) (not is:displayed-victory-message))
(printf "All asteroids have been cleared!\n")
(gs:level-cleared!)
)
(java-iterate (invoke gs:players 'values) (p player)
(update-label p:scorelabel +score-fmtstr+ p:score)
(if (>= p:lives 0)
(update-label p:liveslabel +lives-fmtstr+ p:lives)
(update-label p:liveslabel "%s" "Game over.")
)
)
(update-label gs:levellabel +level-fmtstr+ gs:level)
)
)
(define (render gl2::GL2 gs::game-state is::interface-state width::integer height::integer)
(when gs:buffer-needs-reset
(is:reset-polygons-buffer! gl2)
(set! gs:buffer-needs-reset #f)
)
(gl2:glClear gl2:GL_COLOR_BUFFER_BIT)
(define-constant (set-projection gl2::GL2 width::double height::double)
(gl2:glMatrixMode gl2:GL_PROJECTION)
(gl2:glLoadIdentity)
(gl2:glOrtho (- width) width
(- height) height
1 -1)
; (define proj-matrix (int[] length: 16))
; (gl2:glGetIntegerv gl2:GL_PROJECTION_MATRIX proj-matrix 0)
; (display proj-matrix) (newline)
)
(define-constant (prepare-frame gl2::GL2 cx cy ox oy) ; center and offset
(gl2:glMatrixMode gl2:GL_MODELVIEW)
(gl2:glLoadIdentity)
(gl2:glTranslated (- cx) (- cy) 0)
(gl2:glTranslated (- ox) (- oy) 0)
)
(define-constant (draw-background gl2::GL2)
(drawPolygon gl2 is:cbuf 0 0 0 background)
)
(define-constant (draw-foreground gl2 cx cy)
(java-iterate gs:active-ships (shp ship)
(if shp:shield-active (drawPolygon gl2 is:cbuf shp:spawnx shp:spawny 0 +respawn-box-vertidx+))
)
(java-iterate gs:active-ships (shp ship) (shp:draw gl2 is))
(define-macro (draw-if-within-bounds x)
`(when (and (< (abs (- (field ,x 'x) cx)) +viewport-width+)
(< (abs (- (field ,x 'y) cy)) +viewport-height+))
;(printf "drawing something at (%s, %s)\n" (field ,x 'x) (field ,x 'y))
(invoke ,x 'draw gl2 is)
)
)
;(printf "\n-----\n")
(java-iterate gs:active-shots (s shot) (draw-if-within-bounds s))
(java-iterate gs:active-asteroids (a asteroid) (draw-if-within-bounds a))
)
(define-constant (draw-whole-area gl2 x y w h)
(gl2:glViewport x y w h)
(set-projection gl2 +logical-width+ +logical-height+)
(prepare-frame gl2 0 0 0 0)
(draw-background gl2)
(draw-foreground gl2 0 0)
(if (equal? is:whole-area-dims #!null)
(set! is:whole-area-dims (int[] x y w h))
)
(if (equal? is:whole-area-matrix #!null)
(set! is:whole-area-matrix (getPMVMatrix gl2))
)
)
(define-constant (draw-shipview gl2 shp::ship x y w h)
(gl2:glViewport x y w h)
(set-projection gl2 +viewport-width+ +viewport-height+)
; display 4 copies (in positions based on the quadrant of the ship) to ensure that objects on the wrapped sides appear properly
(define px shp:x)
(define py shp:y)
(define min-x (if (> px 0) -1 0))
(define max-x (+ (if (> px 0) 0 1) 1))
(define min-y (if (> py 0) -1 0))
(define max-y (+ (if (> py 0) 0 1) 1))
;(printf "(%s, %s) -> (%s, %s), (%s, %s)\n" shp:x shp:y min-x min-y max-x max-y)
(pascal-for (i min-x max-x 1) (pascal-for (j min-y max-y 1)
(let ((ox (* 2 i +logical-width+)) (oy (* 2 j +logical-height+)))
(prepare-frame gl2 px py ox oy)
(draw-background gl2)
)
))
(pascal-for (i min-x max-x 1) (pascal-for (j min-y max-y 1)
(let ((ox (* 2 i +logical-width+)) (oy (* 2 j +logical-height+)))
(prepare-frame gl2 px py ox oy)
(draw-foreground gl2 (+ px ox) (+ py oy))
)
))
)
(define-constant (draw-debugging-poly gl2 x y w h)
(gl2:glViewport x y w h)
(set-projection gl2 1 1)
(drawPolygon gl2 is:cbuf 0 0 0 white-bg)
(receive (px py) is:recent-mouse-obj-coords
;(printf "recent mouse coords (%s, %s)\n" px py)
(define a (closest-asteroid-to-point gs:active-asteroids px py))
(unless (equal? a #!null)
;(printf "asteroid loc (%s, %s)\n" a:x a:y)
(drawPolygon gl2 is:cbuf 0 0 0 a:vertidx)
(define xy (untranslate/rotate a:x a:y a:rot px py))
;(printf "translated pt (%s, %s)\n" (xy 0) (xy 1))
(drawPolygon gl2 is:cbuf (xy 0) (xy 1) 0 black-dot)
(define (getter vertidx offset)
(is:cbuf:buf:position (* (is:cbuf:offset vertidx) 6))
(is:cbuf:buf:position (+ (is:cbuf:buf:position) offset))
(is:cbuf:buf:get)
)
(draw-dotted-line gl2 is:cbuf blue-dot 0 0 (getter a:vertidx 0) (getter a:vertidx 1))
)
)
)
(if *show-extra-debugging-views*
(begin
(draw-whole-area gl2 0 (- +window-height+ +screen-height+) +screen-width+ +screen-height+)
(draw-debugging-poly gl2 (/ +screen-width+ 2) 0 (/ +screen-width+ 2) (/ +screen-height+ 2))
(draw-shipview gl2 (invoke gs:players 'get 1):shp 0 0 (/ +screen-width+ 2) (/ +screen-height+ 2))
)
(begin
(draw-shipview gl2 (invoke gs:players 'get 1):shp 0 (- +window-height+ +screen-height+) +screen-width+ +screen-height+)
(if +multiplayer-mode+
(draw-shipview gl2 (invoke gs:players 'get 2):shp +screen-width+ (- +window-height+ +screen-height+) +screen-width+ +screen-height+)
)
)
)
)
(define-simple-class asteroids-panel (javax.swing.JPanel javax.media.opengl.GLEventListener java.awt.event.KeyListener java.awt.event.MouseListener java.awt.event.MouseMotionListener java.awt.event.MouseWheelListener)
(gamestate::game-state)
(interfacestate::interface-state)
; GLEventListener
((display drawable) (synchronized gamestate:eventloop-render-mutex (print-exceptions (render ((drawable:getGL):getGL2) gamestate interfacestate (getWidth) (getHeight)))))
((init drawable)
(let ((gl (javax.media.opengl.DebugGL2 ((drawable:getGL):getGL2))))
;(gl:glEnableClientState gl:GL_VERTEX_ARRAY)
(interfacestate:reset-polygons-buffer! gl)
)
)
((dispose drawable) #!void)
((reshape drawable x y w h) #!void)
; KeyListener
((keyPressed ev)
;; ; split a random asteroid, for testing purposes, when 's' is pressed
;; (when (equal? (ev:getKeyCode) KeyEvent:VK_S)
;; (define a (*active-asteroids* (random (*active-asteroids*:size))))
;; (a:split 0 0)
;; (*active-asteroids*:remove a)
;; )
;; (when (equal? (ev:getKeyCode) KeyEvent:VK_Q) (inc! +asteroid-speed-multiplier+ -0.1))
;; (when (equal? (ev:getKeyCode) KeyEvent:VK_W) (inc! +asteroid-speed-multiplier+ 0.1))
;; (inplace! (clamp 0 1) +asteroid-speed-multiplier+)
(interfacestate:currently-held-keys:add (ev:getKeyCode))
)
((keyReleased ev)
(interfacestate:currently-held-keys:remove (ev:getKeyCode))
)
((keyTyped ev) #!void)
; MouseListener
((mouseClicked ev)
(unless (equal? interfacestate:whole-area-matrix #!null)
(receive (x y) (interfacestate:mousecoords->objcoords (ev:getX) (ev:getY))
(printf "mouse clicked at (%s, %s) window coords (%s, %s) object coords\n" (ev:getX) (ev:getY) x y)
(split-if-closest-asteroid-overlaps-point! gamestate interfacestate x y 0 0)
)
)
)
; consider making a macro that generates these stubs for all methods of an interface, except for ones written
((mouseEntered ev) #!void)
((mouseExited ev) #!void)
((mousePressed ev) #!void)
((mouseReleased ev) #!void)
; MouseMotionListener
((mouseMoved ev)
(set! interfacestate:recent-mouse-obj-coords (interfacestate:mousecoords->objcoords (ev:getX) (ev:getY)))
;(display *recent-mouse-obj-coords*) (newline)
)
((mouseDragged ev) #!void)
; MouseWheelListener
((mouseWheelMoved ev)
(define delta (* .5 (ev:getWheelRotation)))
(inc! +viewport-width+ delta)
(inc! +viewport-height+ delta)
(inplace! (cut max .5 <>) +viewport-width+)
(inplace! (cut max .5 <>) +viewport-height+)
;(printf "(%s, %s)\n" +viewport-width+ +viewport-height+)
)
(glcanv::GLCanvas #!null)
(anim::FPSAnimator #!null)
((*init* w::integer h::integer) #!void
(set! interfacestate (interface-state))
(set! gamestate (game-state interfacestate))
(gamestate:spawn-asteroids! +asteroids-per-level+)
(setLayout #!null)
(initialize-label (this) (invoke gamestate:players 'get 1):scorelabel 0 0) ; the "'get 1" is a hack, fix later
(initialize-label (this) (invoke gamestate:players 'get 1):liveslabel (- +screen-width+ (+label-dimensions+:getWidth)) 0)
(when +multiplayer-mode+
(initialize-label (this) (invoke gamestate:players 'get 2):scorelabel +screen-width+ 0)
(initialize-label (this) (invoke gamestate:players 'get 2):liveslabel (- w (+label-dimensions+:getWidth)) 0)
)
(initialize-label (this) gamestate:levellabel (- w (+label-dimensions+:getWidth)) (+label-dimensions+:getHeight))
; according to gnu.bytecode.dump, this doesn't get unrolled (a PairWithPosition literal is consed up at module init, and the code that uses that literal cdrs through it, and uses gnu.kawa.reflect.Invoke to execute the symbols)
(set! glcanv (GLCanvas))
(for-each (lambda (method) (invoke glcanv method (this)))
'(addGLEventListener addKeyListener addMouseListener addMouseMotionListener addMouseWheelListener))
(add glcanv)
(glcanv:setBounds 0 0 w h)
(setBounds 0 0 w h)
)
((post-visible-initialization!)
(glcanv:requestFocus)
(set! anim (FPSAnimator glcanv 30))
(anim:start)
(future (with-min-ms-per-iteration 10 (synchronized gamestate:eventloop-render-mutex (print-exceptions (event-loop gamestate interfacestate)))))
)
)
(define jf (javax.swing.JFrame))
(define *asteroids-panel*::asteroids-panel (asteroids-panel +window-width+ +window-height+))
(jf:setSize +window-width+ +window-height+)
(jf:setResizable #f)
(jf:setDefaultCloseOperation javax.swing.JFrame:EXIT_ON_CLOSE)
(jf:setLayout #!null)
(jf:add *asteroids-panel*)
(jf:setVisible #t)
(*asteroids-panel*:post-visible-initialization!)
| false |
21e59a2d20d7c70bcf3aa62bf597de73c6e83f74 | 26aaec3506b19559a353c3d316eb68f32f29458e | /modules/config/config.scm | 01642fc2cdf1eff61d3812ff4909a199bec63f05 | [
"BSD-3-Clause"
]
| permissive | mdtsandman/lambdanative | f5dc42372bc8a37e4229556b55c9b605287270cd | 584739cb50e7f1c944cb5253966c6d02cd718736 | refs/heads/master | 2022-12-18T06:24:29.877728 | 2020-09-20T18:47:22 | 2020-09-20T18:47:22 | 295,607,831 | 1 | 0 | NOASSERTION | 2020-09-15T03:48:04 | 2020-09-15T03:48:03 | null | UTF-8 | Scheme | false | false | 3,474 | scm | config.scm | #|
LambdaNative - a cross-platform Scheme framework
Copyright (c) 2009-2015, University of British Columbia
All rights reserved.
Redistribution and use in source and binary forms, with or
without modification, are permitted provided that the
following conditions are met:
* Redistributions of source code must retain the above
copyright notice, this list of conditions and the following
disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials
provided with the distribution.
* Neither the name of the University of British Columbia nor
the names of its contributors may be used to endorse or
promote products derived from this software without specific
prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|#
;; init.scm
;; this is the glue between the native launcher and the portable code
(define-macro (define-cond-expand-feature-value v)
(let ((v (eval v)))
`(define-cond-expand-feature ,v)))
(define-cond-expand-feature-value
(if (>= (system-version) 409002)
'heartbeat-interval-2019
'heartbeat-interval-legacy))
(cond-expand
(heartbeat-interval-2019 (if (string=? (system-platform) "android") (##set-heartbeat-interval! -1.)))
(else (if (string=? (system-platform) "android") (##heartbeat-interval-set! -1.))))
(c-declare #<<end-of-c-declare
#include "LNCONFIG.h"
#include "lambdanative.h"
void force_terminate()
{
___cleanup();
exit(0);
}
end-of-c-declare
)
(define ##now 0.)
(define (system-pathseparator)
(string ((c-lambda () char "system_pathseparator"))))
(define (system-directory) ((c-lambda () char-string "system_dir")))
(define (system-appdirectory) ((c-lambda () char-string "system_appdir")))
(define (system-platform) ((c-lambda () char-string "system_platform")))
(define (system-appname) ((c-lambda () char-string "system_appname")))
(define (system-appversion) ((c-lambda () char-string "system_appversion")))
(define (system-buildhash) ((c-lambda () char-string "system_buildhash")))
(define (system-buildepoch) ((c-lambda () unsigned-int "system_buildepoch")))
(define (system-builddate) (seconds->string (system-buildepoch) "%Y-%m-%d"))
(define (system-builddatetime) (seconds->string (system-buildepoch) "%Y-%m-%d %H:%M:%S"))
(define system-cmdargv (c-lambda (int) char-string "system_cmdargv"))
(define system-cmdargc (c-lambda () int "system_cmdargc"))
(define (system-cmdarg) (system-cmdargv 1)) ;; backwards compatibility
(define force-terminate (c-lambda () void "force_terminate"))
(if (not (file-exists? (system-directory)))
(with-exception-catcher (lambda (e) #f)
(lambda () (create-directory (system-directory)))))
;; eof
| false |
0384b544ad8eb5335f0f3ac1c622f71214a05c42 | ae4938300d7eea07cbcb32ea4a7b0ead9ac18e82 | /labs/playground/interp.ss | e4d8ba04349f7e093732d708f008f12380a8ffab | []
| no_license | keenbug/imi-libs | 05eb294190be6f612d5020d510e194392e268421 | b78a238f03f31e10420ea27c3ea67c077ea951bc | refs/heads/master | 2021-01-01T19:19:45.036035 | 2012-03-04T21:46:28 | 2012-03-04T21:46:28 | 1,900,111 | 0 | 1 | null | null | null | null | UTF-8 | Scheme | false | false | 11,932 | ss | interp.ss | (import (rnrs))
;;; e - expression
;;; v - value
;;; n - identifier (name)
;;; r - environment
;;; s - memory (store)
;;; sr - frame (store environment)
;;; a - address
;;; k - continuation
(define (meaning e r)
(if (atom? e)
(if (symbol? e) (meaning-reference e r)
(meaning-quotation e r))
(case (car e)
[(quote) (meaning-quotation (cadr e) r)]
[(begin) (meaning-sequence (cdr e) r)]
[(set!) (meaning-set! (cadr e) (caddr e) r)]
[(if) (meaning-alternative (cadr e) (caddr e) (cadddr e) r)]
[(lambda) (meaning-abstraction (cadr e) (cddr e) r)]
[else (meaning-application (car e) (cdr e) r)])))
(define (atom? e) (not (pair? e)))
(define (meaning-reference e r)
(let ([ar (lookup e r)])
(lambda (s sr k)
(let ([x (get s (ref sr ar))])
(if (eq? x 0)
(error e "undefined value")
(k x s))))))
(define (meaning-quotation e r)
(lambda (s sr k)
(allocate-value e s sr r k)))
(define (meaning-sequence e* r)
(cond
[(null? e*)
(error 'meaning-sequence
"empty sequence"
e*)]
[(null? (cdr e*))
(meaning (car e*) r)]
[else
(let ([m (meaning (car e*) r)]
[m* (meaning-sequence (cdr e*) r)])
(lambda (s sr k)
(m s sr (lambda (v s1)
(m* s1 sr k)))))]))
(define (meaning-set! n e r)
(let ([m (meaning e r)]
[ar (lookup n r)])
(lambda (s sr k)
(m s sr (lambda (a s1)
(k a (set s1 (ref sr ar) a)))))))
(define (meaning-alternative ec et ef r)
(let ([mc (meaning ec r)]
[mt (meaning et r)]
[mf (meaning ef r)])
(lambda (s sr k)
(mc s sr (lambda (ac s1)
(if (not (eq? 'false (car ac)))
(mt s1 sr k)
(mf s1 sr k)))))))
(define (meaning-abstraction n* e* r)
(let* ([rr (extend r n*)]
[arity (length n*)]
[m* (meaning-sequence e* rr)])
(lambda (s sr.lexical k)
(create-abstraction
(lambda (a* s1 k1)
(if (= arity (length a*))
(allocate-frame s1 sr.lexical r a*
(lambda (sr.abstraction s2)
(m* s2 sr.abstraction k1)))
(error 'abstraction
"incorrect arity"
a* n*)))
s
sr.lexical
r
k))))
(define (meaning-application e e* r)
(let ([mf (meaning e r)]
[m* (meaning* e* r)])
(lambda (s sr k)
(mf s sr
(lambda (af s1)
(if (eq? 'abstraction (car af))
(let ([f (get s1 (cdr af))])
(if (procedure? f)
(m* s1 sr (lambda (a* s2)
(f a* s2 k)))
(error 'application
"not a procedure"
e f)))
(error 'application
"not an abstraction"
af)))))))
(define (meaning* e* r)
(if (null? e*)
(lambda (s sr k)
(k '() s))
(let ([m (meaning (car e*) r)]
[m* (meaning* (cdr e*) r)])
(lambda (s sr k)
(m* s sr (lambda (a* s1)
(m s1 sr (lambda (a s2)
(k (cons a a*) s2)))))))))
(define (allocate-frame s sr r a* q)
(allocate s sr r (length a*)
(lambda (a.base s1)
(q (cons sr a.base)
(set* s1 (range a.base (length a*))
a*)))))
(define (range start len)
(if (zero? len)
'()
(cons start (range (+ start 1)
(- len 1)))))
(define (extend r n*)
(cons r n*))
(define (ref sr ar)
(let layer ([level (car ar)]
[sr sr])
(if (= 0 level)
(+ (cdr sr) (cdr ar))
(layer (- level 1)
(car sr)))))
(define (lookup n r)
(let lookframe ([r r]
[level 0])
(if (null? r)
(error 'lookup
"unbound identifier"
n)
(let inframe ([n* (cdr r)]
[x 0])
(cond
[(null? n*)
(lookframe (car r) (+ 1 level))]
[(eq? n (car n*))
(cons level x)]
[else
(inframe (cdr n*)
(+ 1 x))])))))
(define (get s a)
(let ([x (assq a (cdr s))])
(if x (cdr x)
(error 'get "invalid memory address" a s))))
(define (set s a v)
(cons
(car s)
(let loop ([s (cdr s)])
(if (eq? a (caar s))
(cons (cons (caar s)
v)
(cdr s))
(cons (car s)
(loop (cdr s)))))))
(define (set* s a* v*)
(if (and (pair? a*)
(pair? v*))
(set* (set s (car a*) (car v*))
(cdr a*)
(cdr v*))
s))
(define (allocate-value v s sr r k)
(cond
[(number? v)
(create-number v s sr r k)]
[(pair? v)
(allocate-value (car v) s sr r
(lambda (aa s1)
(allocate-value (cdr v) s1 sr r
(lambda (ad s2)
(create-pair aa ad s2 sr r k)))))]
[(null? v)
(create-null s sr r k)]
[(boolean? v)
((if v create-true
create-false)
s sr r k)]
[(procedure? v)
(create-abstraction v s sr r k)]
[else
(error 'allocate-value
"invalid type"
v)]))
(define (allocate s sr r size q)
(if (and sr r
(> (+ size (length s))
*max-alloc*))
(allocate (gc s sr r)
sr r size q)
(case size
[(0) (q -1 s)]
[(1) (let ([a (car s)])
(q a
(cons* (+ 1 a)
(cons a 0)
(cdr s))))]
[else
(let ([a (car s)])
(allocate
(cons* (+ 1 a)
(cons a 0)
(cdr s))
sr r
(- size 1)
(lambda (aa ss)
(q a ss))))])))
(define *max-alloc* 500)
(define (gc s sr r)
(display "collecting ...") (newline)
(let ([needed (gc-collect sr r)])
(display "need ") (write needed) (newline)
(display "before ") (write (length s))
(let ([s.collected
(cons
(car s)
(fold-left (lambda (ss need)
(let ([ptr (assq need (cdr s))])
(merge (merge ss ptr)
(assq (cddr ptr)
(cdr s)))))
'()
needed))])
(display " after ") (write (length s.collected))
(newline)
s.collected)))
(define (gc-collect sr r)
(if (null? sr)
'()
(append (range (cdr sr) (length (cdr r)))
(gc-collect (car sr) (car r)))))
(define (merge s v)
(if (assq v s)
s
(cons v s)))
(define (create-number v s sr r k)
(allocate s sr r 1
(lambda (a s1)
(k (cons 'number a)
(set s1 a v)))))
(define (create-pair a d s sr r k)
(allocate s sr r 2
(lambda (ap s1)
(k (cons 'pair ap)
(set* s1 (list ap (+ ap 1))
(list a d))))))
(define (create-null s sr r k)
(allocate s sr r 0
(lambda (a s1)
(k (cons 'null a)
s1))))
(define (create-true s sr r k)
(allocate s sr r 0
(lambda (a s1)
(k (cons 'true a)
s1))))
(define (create-false s sr r k)
(allocate s sr r 0
(lambda (a s1)
(k (cons 'false a)
s1))))
(define (create-abstraction v s sr r k)
(allocate s sr r 1
(lambda (a s1)
(k (cons 'abstraction a)
(set s1 a v)))))
(define (mfxop fxop)
(lambda (a* s k)
(if (for-all (lambda (a)
(eq? 'number (car a)))
a*)
(allocate-value
(apply fxop (map (lambda (a)
(get s (cdr a)))
a*))
s #f #f
(lambda (a s1)
(k a s1)))
(error fxop
"arguments have to be numbers"
a*))))
(define (mcheck type)
(lambda (a* s sr k)
(if (= 1 (length a*))
(allocate-value
(eq? type (car (car a*)))
s #f #f k)
(error type
"incorrect arity"
a*))))
(define m+ (mfxop +))
(define m- (mfxop -))
(define m* (mfxop *))
(define m/ (mfxop /))
(define m= (mfxop =))
(define m< (mfxop <))
(define m> (mfxop >))
(define mnumber? (mcheck 'number))
(define mpair? (mcheck 'pair))
(define (mcons a* s k)
(if (= 2 (length a*))
(create-pair (car a*)
(cadr a*)
s #f #f k)
(error 'cons
"incorrect arity"
a*)))
(define (mcar a* s k)
(cond
[(not (= 1 (length a*)))
(error 'car "incorrect arity" a*)]
[(not (eq? 'pair (car (car a*))))
(error 'car "not a pair" (car a*))]
[else
(k (get s (cdr (car a*))) s)]))
(define (mcdr a* s k)
(cond
[(not (= 1 (length a*)))
(error 'cdr "incorrect arity" a*)]
[(not (eq? 'pair (car (car a*))))
(error 'cdr "not a pair" (car a*))]
[else
(k (get s (+ 1 (cdr (car a*)))) s)]))
(define mnull? (mcheck 'null))
(define (mdebug a* s k)
(display "Arguments:")
(for-each (lambda (arg)
(display " ")
(write arg))
a*)
(newline)
(display "Memory:") (newline)
(display " Size: ") (write (car s)) (newline)
(display " Contents:") (newline)
(for-each (lambda (mem)
(display " ")
(write mem)
(newline))
(cdr s))
(create-number (car s) s #f #f k))
(define (create-store defs q)
(if (null? defs)
(q '() '() (cons 0 '()))
(create-store (cddr defs)
(lambda (n* a* s)
(allocate-value (cadr defs)
s #f #f
(lambda (a s1)
(q (cons (car defs) n*)
(cons a a*)
s1)))))))
(define s.init #f)
(define r.global #f)
(define sr.global #f)
;#;
(create-store
`(+ ,m+
- ,m-
* ,m*
/ ,m/
= ,m=
> ,m>
< ,m<
number? ,mnumber?
pair? ,mpair?
cons ,mcons
car ,mcar
cdr ,mcdr
debug ,mdebug
)
(lambda (n* a* s)
(allocate-frame s '() '() a*
(lambda (sr s1)
(set! sr.global sr)
(set! r.global (extend '() n*))
(set! s.init s1)))))
(define (transcribe a s)
(case (car a)
[(number) (get s (cdr a))]
[(null) '()]
[(pair) (cons (transcribe (get s (cdr a)) s)
(transcribe (get s (+ 1 (cdr a))) s))]
[(abstraction) (get s (cdr a))]
[else (error 'transcribe
"invalid transcription input"
a)]))
(define (definition name body s sr r k)
(if (pair? name)
(definition (car name)
`((lambda ,(cdr name) ,@body))
s sr r k)
(let* ([rr (extend r (list name))]
[m (meaning (car body) rr)])
(allocate-frame s sr rr '(0)
(lambda (sr1 s1)
(m s1 sr1
(lambda (a s2)
(k (set s2 (cdr sr1) a)
sr1
rr))))))))
(define (toplevel)
(let loop ([s s.init]
[sr sr.global]
[r r.global])
(display ">> ")
(let ([in (read)])
(if (and (pair? in)
(eq? 'define (car in)))
(definition (cadr in) (cddr in) s sr r loop)
(let ([m (meaning in r)])
(m s sr
(lambda (a ss)
(write (transcribe a ss))
(newline)
(loop ss sr r))))))))
| false |
c25cd996cc62e5debf076cf28e37a2bb526ce626 | 179247401758c67082cc87da3e59ac728a779da9 | /example/guess.scm | 2b6947eb1885912cf31ae65dca6bb27bb1de4be3 | [
"MIT"
]
| permissive | KnairdA/Telebot | e8ee5af2a8c1f28e4f3cfe5361b14854802d7f7b | 778ea87cb71e98af3fd899bdd7d6fb189f0d7acd | refs/heads/master | 2021-08-19T15:33:34.078889 | 2021-01-12T18:33:51 | 2021-01-12T18:33:51 | 53,610,324 | 13 | 8 | MIT | 2021-01-12T18:31:42 | 2016-03-10T19:15:25 | Scheme | UTF-8 | Scheme | false | false | 1,396 | scm | guess.scm | (import (prefix telebot telebot:)
(chicken process-context)
(chicken random))
(define (make-sender token chat_id)
(lambda (text)
(print chat_id " <- \"" text "\"")
(telebot:send-message token
chat_id: chat_id
text: text)))
(define (make-conversation token chat_id)
(let* ((chat_id chat_id)
(send (make-sender token chat_id))
(answer (pseudo-random-integer 100)))
(send "Hi there! I just generated a random number for you to guess!")
(lambda (update)
(let* ((text (telebot:resolve-query '(message text) update))
(guess (string->number text)))
(print chat_id " -> \"" text "\"")
(if (number? guess)
(cond ((= guess answer)
(begin (send "Correct! Feel free to guess the next number.")
(set! answer (pseudo-random-integer 100))))
((< guess answer) (send "Too small. Try again."))
((> guess answer) (send "Too large. Try again.")))
(send "This is not a number - please provide your guess in base 10."))))))
(let* ((token (cadr (command-line-arguments)))
(converse (telebot:make-conversation-manager token
make-conversation)))
(set-pseudo-random-seed! (random-bytes))
(telebot:poll-updates token converse))
| false |
6909020c7244ba901840ed4ad7b585cf51582fbc | 3508dcd12d0d69fec4d30c50334f8deb24f376eb | /tests/runtime/test-library-data/dependencies.scm | f2d7ccfeecc0b3b8adc2bfd26c56ab0e42deb854 | []
| no_license | barak/mit-scheme | be625081e92c2c74590f6b5502f5ae6bc95aa492 | 56e1a12439628e4424b8c3ce2a3118449db509ab | refs/heads/master | 2023-01-24T11:03:23.447076 | 2022-09-11T06:10:46 | 2022-09-11T06:10:46 | 12,487,054 | 12 | 1 | null | null | null | null | UTF-8 | Scheme | false | false | 1,003 | scm | dependencies.scm | (define-library (foo mumble)
(import (scheme base))
(export foo-mumble?
make-foo-mumble
foo-mumble-a
foo-mumble-b)
(begin
(define-record-type <foo-mumble>
(make-foo-mumble a b)
foo-mumble?
(a foo-mumble-a)
(b foo-mumble-b))))
(define-library (foo bletch)
(import (scheme base))
(export foo-bletch?
make-foo-bletch
foo-bletch-thing)
(begin
(define-record-type <foo-bletch>
(make-foo-bletch thing)
foo-bletch?
(thing foo-bletch-thing))))
(define-library (foo grumble)
(import (scheme base))
(export foo-grumble?
make-foo-grumble
foo-grumble-a
foo-grumble-b)
(begin
(define-record-type <foo-grumble>
(make-foo-grumble a b)
foo-grumble?
(a foo-grumble-a)
(b foo-grumble-b))))
(define-library (foo quux)
(import (scheme base))
(export foo-quux?
make-foo-quux
foo-quux-a
foo-quux-b)
(begin
(define-record-type <foo-quux>
(make-foo-quux a b)
foo-quux?
(a foo-quux-a)
(b foo-quux-b)))) | false |
c09906d3bdec610d3a5d4485cdbbc8caf7918fa2 | dff2c294370bb448c874da42b332357c98f14a61 | /window.scm | 1151a714b88317480df0b295ed9b4dac4436f248 | [
"BSD-2-Clause"
]
| permissive | kdltr/hypergiant | caf14bbeac38b9d5b5713a19982b226082f3daad | ffaf76d378cc1d9911ad4de41f1d7219e878371e | refs/heads/master | 2021-01-01T01:43:09.756174 | 2019-04-04T12:38:25 | 2019-04-04T12:38:25 | 239,126,881 | 0 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 6,379 | scm | window.scm | ;;;; window.scm
;;;; Window management for Hypergiant
(module hypergiant-window
(start
stop
get-window-size
get-framebuffer-size
get-window-position
set-window-position
ui
*pixel-density-ratio*
resize-hooks
frame-rate
get-clipboard-string
set-clipboard-string
make-camera)
(import scheme (chicken base) (chicken bitwise) (chicken foreign) (chicken format) (chicken gc) (chicken keyword) (chicken module) (chicken platform)
(prefix glfw3 %) (prefix glfw3-bindings %%)
(prefix epoxy gl:) (prefix glls glls:)
gl-math gl-utils (prefix hyperscene scene:) gl-type
srfi-1 srfi-4 srfi-18 srfi-99 miscmacros)
(include "input")
(define *last-render-time* 0)
(define ui #f)
(define *ui-camera* #f)
(define *pixel-density-ratio* #f)
(define (render pre-render post-render)
(gl:clear (bitwise-ior gl:+color-buffer-bit+ gl:+depth-buffer-bit+))
(pre-render)
(scene:activate-camera *ui-camera*) ; always draw UI last
(scene:render-cameras)
(scene:deactivate-camera *ui-camera*)
(post-render)
(%swap-buffers (%window)))
(define (move-ui-camera w h)
(scene:set-camera-position! *ui-camera*
(make-point (/ w 2) (/ h -2) 1)))
(define resize-hooks (make-parameter (list move-ui-camera)))
(define (resize _ w h)
(let-values (((w h) (get-framebuffer-size)))
(gl:viewport 0 0 w h))
(for-each (cut <> w h) (resize-hooks))
(scene:resize-cameras w h))
(define (set-pixel-density-ratio)
(receive (window-w _) (get-window-size)
(receive (framebuffer-w _) (get-framebuffer-size)
(set! *pixel-density-ratio*
(/ framebuffer-w window-w)))))
(define (start* width height title . args)
(%init)
(%window-size-callback resize)
(%mouse-button-callback mouse-click)
(apply %make-window width height title
(append (cond-expand
(macosx (list samples: 4
context-version-major: 3
context-version-minor: 2
opengl-forward-compat: #t
opengl-profile: %+opengl-core-profile+))
(gles '())
(else (list samples: 4
context-version-major: 3
context-version-minor: 3)))
args))
(%%set-cursor-pos-callback (%window) #$hpgCursorPositionCallback)
(%%set-scroll-callback (%window) #$hpgScrollCallback)
(%%set-key-callback (%window) #$hpgKeyCallback)
(%%set-char-callback (%window) #$hpgCharCallback)
(gl:enable gl:+depth-test+)
(gl:enable gl:+blend+)
(gl:blend-func gl:+src-alpha+ gl:+one-minus-src-alpha+)
(cond-expand
((not gles) (gl:enable gl:+multisample+))
(else))
(set! ui (scene:make-scene))
(set! *ui-camera* (scene:make-camera #:ortho #:position ui))
(scene:deactivate-camera *ui-camera*)
(resize #f width height)
(set-pixel-density-ratio)
(pixel-density-ratio (ceiling *pixel-density-ratio*))
(gl:get-error) ;; silence error caused by GLEW
(glls:compile-pipelines)
((get-keyword init: args (lambda () (lambda () #f))))
(gc)
(set! *last-render-time* (%get-time))
(let ((update (get-keyword update: args (lambda () (lambda (delta) #f))))
(pre-render (get-keyword pre-render: args (lambda () (lambda () #f))))
(post-render (get-keyword post-render: args (lambda () (lambda () #f)))))
(let loop ()
(let* ((time (%get-time))
(delta (- time *last-render-time*)))
(add-frame-time time)
(update delta)
(scene:update-scenes)
(scene:activate-camera *ui-camera*)
(scene:update-cameras)
(scene:deactivate-camera *ui-camera*)
(render pre-render post-render)
(check-error)
(set! *last-render-time* time)
(thread-yield!)
(%poll-events))
(unless (%window-should-close? (%window))
(loop))))
((get-keyword cleanup: args (lambda () (lambda () #f))))
(gc)
(%destroy-window (%window))
(%terminate))
(define (start width height title . args)
(define start** (lambda () (apply start* width height title args)))
(if (feature? csi:)
(thread-start! start**)
(start**)))
(define (stop)
(%set-window-should-close (%window) #t))
(define (get-window-size)
(%get-window-size (%window)))
(define (get-framebuffer-size)
(%get-framebuffer-size (%window)))
(define (get-window-position)
(%get-window-position (%window)))
(define (set-window-position x y)
(%set-window-position (%window) x y))
(define (get-clipboard-string)
(%get-clipboard-string (%window)))
(define (set-clipboard-string string)
(%set-clipboard-string (%window) string))
(define (make-camera type style scene #!key (near 1) (far 10000) (angle 70)
width height
(viewport-width-ratio 1.0) (viewport-height-ratio 1.0)
static-viewport?)
(when (or (not width) (not height))
(receive (w h) (get-window-size)
(set! width w)
(set! height h)))
(scene:make-camera type style scene near: near far: far angle: angle
width: width height: height
viewport-width-ratio: viewport-width-ratio
viewport-height-ratio: viewport-height-ratio
static-viewport?: static-viewport?))
;; Frame rate calculation
;; We use a circular buffer to track subsequent frame times
;; Frame rate is calculated averaging the total time between the most recent frame and oldest frame
(define n-frames-1 20) ; number of frame times we keep, minus one, because that's more useful
(define frame-times (make-list (add1 n-frames-1) 0)) ; circular buffer
(define frame-times-counter 0) ; where are we in the frame-times list?
;; Call every frame
(define (add-frame-time time)
(set! frame-times-counter
(if (= frame-times-counter n-frames-1)
0
(add1 frame-times-counter)))
(set! (list-ref frame-times frame-times-counter) time))
(define (frame-rate)
(let ((oldest-frame (list-ref frame-times frame-times-counter))
(newest-frame (list-ref frame-times (if (= frame-times-counter n-frames-1)
0
(add1 frame-times-counter)))))
(/ n-frames-1 (- oldest-frame newest-frame))))
) ; end module hypergiant-window
| false |
dff38809383199b0d31009c90aed5543e8911847 | 3629e5c33ebbc3acbaa660fb324c26357098147c | /examples/glbook/example13-6.scm | fad91b0cd751b9638ebefdf05bd6bd5693f86bb0 | [
"LicenseRef-scancode-x11-sg",
"MIT"
]
| permissive | shirok/Gauche-gl | f31a62ce4c2d91795f972b668861a77626b02cb5 | a569e3009314f81bc513827064e05869220c6a9d | refs/heads/master | 2023-06-07T15:56:17.514969 | 2023-06-01T06:56:48 | 2023-06-01T06:56:48 | 9,487,174 | 4 | 5 | MIT | 2018-09-24T21:39:18 | 2013-04-17T02:13:32 | C | UTF-8 | Scheme | false | false | 2,791 | scm | example13-6.scm | ;; Example 13-6 Picking with Depth Values
(use gl)
(use gl.glut)
(use gauche.uvector)
(use gauche.array)
(define (init)
(gl-clear-color 0.0 0.0 0.0 0.0)
(gl-enable GL_DEPTH_TEST)
(gl-shade-model GL_FLAT)
(gl-depth-range 0.0 1.0))
(define (draw-rects mode)
(when (= mode GL_SELECT) (gl-load-name 1))
(gl-begin* GL_QUADS
(gl-color 1.0 1.0 0.0)
(gl-vertex 2 0 0) (gl-vertex 2 6 0) (gl-vertex 6 6 0) (gl-vertex 6 0 0)
)
(when (= mode GL_SELECT) (gl-load-name 2))
(gl-begin* GL_QUADS
(gl-color 0.0 1.0 1.0)
(gl-vertex 3 2 -1) (gl-vertex 3 8 -1) (gl-vertex 8 8 -1) (gl-vertex 8 2 -1)
)
(when (= mode GL_SELECT) (gl-load-name 3))
(gl-begin* GL_QUADS
(gl-color 1.0 0.0 1.0)
(gl-vertex 0 2 -2) (gl-vertex 0 7 -2) (gl-vertex 5 7 -2) (gl-vertex 5 2 -2)
)
(gl-flush)
)
(define (process-hits hits vec)
(print #`"hits = ,hits")
(let ((ptr 0)
(ii 0)
(jj 0))
(dotimes (i hits)
(let1 names (ref vec ptr)
(print #`" number of names for hit = ,names")
(inc! ptr)
(print #`" z1 is ,(/ (ref vec ptr) #x7fffffff);"
#`" z2 is ,(/ (ref vec (+ ptr 1)) #x7fffffff)")
(inc! ptr 2)
(display " the name is ")
(dotimes (j names)
(display #`",(ref vec ptr) ")
(inc! ptr))
(print)
))))
(define-constant BUFSIZE 512)
(define (pick-rects button state x y)
(let1 select-buf (make-u32vector BUFSIZE 0)
(when (and (= button GLUT_LEFT_BUTTON) (= state GLUT_DOWN))
(let1 viewport (gl-get-integer GL_VIEWPORT)
(gl-select-buffer select-buf)
(gl-render-mode GL_SELECT)
(gl-init-names)
(gl-push-name 0)
(gl-matrix-mode GL_PROJECTION)
(gl-push-matrix)
(gl-load-identity)
(glu-pick-matrix x (- (ref viewport 3) y) 5.0 5.0 viewport)
(gl-ortho 0.0 8.0 0.0 8.0 -0.5 2.5)
(draw-rects GL_SELECT)
(gl-pop-matrix)
(gl-flush)
(process-hits (gl-render-mode GL_RENDER) select-buf)
))))
(define (disp)
(gl-clear (logior GL_COLOR_BUFFER_BIT GL_DEPTH_BUFFER_BIT))
(draw-rects GL_RENDER)
(gl-flush))
(define (reshape w h)
(gl-viewport 0 0 w h)
(gl-matrix-mode GL_PROJECTION)
(gl-load-identity)
(gl-ortho 0.0 8.0 0.0 8.0 -0.5 2.5)
(gl-matrix-mode GL_MODELVIEW)
(gl-load-identity))
(define (keyboard key x y)
(when (= key 27) (exit 0)))
(define (main args)
(glut-init args)
(glut-init-display-mode (logior GLUT_SINGLE GLUT_RGB GLUT_DEPTH))
(glut-init-window-size 200 200)
(glut-init-window-position 100 100)
(glut-create-window (car args))
(init)
(glut-reshape-func reshape)
(glut-display-func disp)
(glut-mouse-func pick-rects)
(glut-keyboard-func keyboard)
(glut-main-loop)
0)
| false |
ad7d7e32c8ef0f765fa83d718e702a23288d5066 | 0011048749c119b688ec878ec47dad7cd8dd00ec | /src/spoilers/131/solution.scm | f89f7951333f9fb99e63052b017a3f8024467ac6 | [
"0BSD"
]
| permissive | turquoise-hexagon/euler | e1fb355a44d9d5f9aef168afdf6d7cd72bd5bfa5 | 852ae494770d1c70cd2621d51d6f1b8bd249413c | refs/heads/master | 2023-08-08T21:01:01.408876 | 2023-07-28T21:30:54 | 2023-07-28T21:30:54 | 240,263,031 | 8 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 322 | scm | solution.scm | (import
(euler))
(define (solve n)
(let loop ((i 0) (acc 0))
(let* ((tmp (- (expt (+ i 1) 3) (expt i 3)))
(acc (if (prime? tmp)
(+ acc 1)
acc)))
(if (> tmp n)
acc
(loop (+ i 1) acc)))))
(let ((_ (solve #e1e6)))
(print _) (assert (= _ 173)))
| false |
ef0b641b1288c1abeb772c667bd4b65f8f978903 | 7ccc32420e7caead27a5a138a02e9c9e789301d0 | /div.sls | ed2d7c5b40f9fc22111a31284fe57f191e1c8db1 | [
"Apache-2.0"
]
| permissive | dharmatech/mpl | 03d9c884a51c3aadc0f494e0d0cebf851f570684 | 36f3ea90ba5dfa0323de9aaffd5fd0f4c11643d7 | refs/heads/master | 2023-02-05T20:21:56.382533 | 2023-01-31T18:10:51 | 2023-01-31T18:10:51 | 280,353 | 63 | 8 | Apache-2.0 | 2023-01-31T18:10:53 | 2009-08-17T21:02:35 | Scheme | UTF-8 | Scheme | false | false | 300 | sls | div.sls | #!r6rs
(library (mpl div)
(export / simplify-quotient)
(import (except (rnrs) + - * /)
(mpl match)
(mpl sum-product-power))
(define (simplify-quotient u)
(match u
( ('/ x y)
(* x (^ y -1)) )))
(define (/ u v)
(simplify-quotient `(/ ,u ,v)))
) | false |
f816c6d54611473f92751b79b3cd26b916b89c0c | 12fc725f8273ebfd9ece9ec19af748036823f495 | /tools/schemelib/konffaile/util.ss | 40fecae36640469755db1ffd43f701dd4e040dd1 | []
| 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 | 1,549 | ss | util.ss | #lang scheme
(require common/usual-4)
(define* (symbol<? s1 s2)
(string<? (symbol->string s1) (symbol->string s2)))
;; --------------------------------------------------
;; set
;; --------------------------------------------------
(define* (new-Set) (make-hasheq))
(define* (Set-put! s e) (hash-set! s e e))
(define* (Set-values s) (hash-map s (lambda (k v) v)))
#|
Copyright 2009 Helsinki Institute for Information Technology (HIIT)
and the authors. All rights reserved.
Authors: Tero Hasu <[email protected]>
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation files
(the "Software"), to deal in the Software without restriction,
including without limitation the rights to use, copy, modify, merge,
publish, distribute, sublicense, and/or sell copies of the Software,
and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
|#
| false |
09e01e91aba49d13bdecddac2f66e63eff5a0958 | 923209816d56305004079b706d042d2fe5636b5a | /sitelib/http/content-coding.scm | ee28bb0e9b9d92b5d7a86e03c379210e2e819e49 | [
"BSD-3-Clause",
"BSD-2-Clause"
]
| permissive | tabe/http | 4144cb13451dc4d8b5790c42f285d5451c82f97a | ab01c6e9b4e17db9356161415263c5a8791444cf | refs/heads/master | 2021-01-23T21:33:47.859949 | 2010-06-10T03:36:44 | 2010-06-10T03:36:44 | 674,308 | 1 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 366 | scm | content-coding.scm | (library (http content-coding)
(export content-coding)
(import (rnrs (6))
(http basic-rule))
;;; 3.5 Content Codings
(define content-coding token)
;; The Internet Assigned Numbers Authority (IANA) acts as a registry for
;; content-coding value tokens.
;;; http://www.iana.org/assignments/http-parameters
;;; (last updated 2009-09-02)
)
| false |
ca7b1bdb060bd3245f6dc0719887b512537c7f9f | 99f659e747ddfa73d3d207efa88f1226492427ef | /datasets/srfi/srfi-157/lib/inferior/environment.scm | 165ffe22869be6b8e288ed8de2bbaa1efa985d0c | [
"MIT"
]
| permissive | michaelballantyne/n-grams-for-synthesis | 241c76314527bc40b073b14e4052f2db695e6aa0 | be3ec0cf6d069d681488027544270fa2fd85d05d | refs/heads/master | 2020-03-21T06:22:22.374979 | 2018-06-21T19:56:37 | 2018-06-21T19:56:37 | 138,215,290 | 0 | 0 | MIT | 2018-06-21T19:51:45 | 2018-06-21T19:51:45 | null | UTF-8 | Scheme | false | false | 3,027 | scm | environment.scm | ;; Copyright (C) Marc Nieper-Wißkirchen (2017). 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.
;;; Bindings
(define (make-binding identifier denotation)
(cons identifier denotation))
(define (binding-identifier binding)
(car binding))
(define (binding-denotation binding)
(cdr binding))
(define (lookup-binding identifier bindings)
(assq identifier bindings))
;;; Frames
(define (make-frame identifiers denotations)
(map make-binding identifiers denotations))
(define (frame-add-binding frame identifier denotation)
(cons (make-binding identifier denotation)
frame))
(define (frame-lookup frame identifier)
(cond
((assq identifier frame) => cdr)
(else
#f)))
(define (frame-map-bindings proc frame)
(map (lambda (binding)
(proc (binding-identifier binding)
(binding-denotation binding)))
frame))
;;; Environments
(define-record-type <environment>
(%make-environment parent frame)
environment?
(parent enclosing-environment)
(frame first-frame set-first-frame!))
(define (make-environment)
(%make-environment #f (make-frame '() '())))
(define (environment-extend environment identifiers denotations)
(%make-environment environment (make-frame identifiers denotations)))
(define (environment-add-binding! environment identifier denotation)
(set-first-frame! environment (frame-add-binding (first-frame environment) identifier denotation)))
(define (environment-lookup environment identifier)
(or (lookup-identifier identifier environment)
(and (alias? identifier)
(environment-lookup (alias-environment identifier)
(alias-identifier identifier)))))
(define (lookup-identifier identifier environment)
(let loop ((environment environment))
(and environment
(or (frame-lookup (first-frame environment) identifier)
(loop (enclosing-environment environment))))))
(define (environment-map-bindings proc environment)
(frame-map-bindings proc (first-frame environment)))
| false |
3d3e4704539c5b93cd3404132a33e8bb1018eb19 | 7053803109172ee3fe36594257fb9f323f860c9a | /chapters/1/1.31.scm | 7363b89fddc6f2809035e39c3ce4e26e9cc34051 | []
| no_license | david-davidson/SICP | 0c7c38a11b11ef70146f4a511e4ac8d7c0651b82 | 393932a507afdc35cb99451ef53a059e72f71eb1 | refs/heads/main | 2021-06-14T00:36:59.503919 | 2021-05-28T01:54:39 | 2021-05-28T01:55:42 | 195,283,241 | 0 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 2,479 | scm | 1.31.scm | ;---------------------------------------------------------------------------------------------------
; Write a function called `product` (in the spirit of the book's example `sum`) that returns the
; product of the values of a function at points over a given range.
;---------------------------------------------------------------------------------------------------
(define (product a b term next)
(if (> a b)
1
(* (term a)
(product (next a)
b
term
next))))
;---------------------------------------------------------------------------------------------------
; Next, define `factorial` in terms of `product`:
;---------------------------------------------------------------------------------------------------
(define (inc x) (+ x 1)) ; Also used by `pi-approx`
(define (factorial n)
(define (id x) x)
(product 1 n id inc))
;---------------------------------------------------------------------------------------------------
; Next, use `product` to compute an approximation of pi, using this formula:
; π/4 = 2 * 4 * 4 * 6 * 6 * 8...
; ------------------------
; 3 * 3 * 5 * 5 * 7 * 7...
;
; I struggled with this one, first trying to compute the series `2 * 4 * 4...` and `3 * 3 * 5 ...`
; separately, and next (closer!) trying to get the product of the series `2/3 * 4/3 * 4/5...`. The
; latter would work _except_ that `product` relies on a simple `a > b` check to terminate, and if
; `a` is a fraction, that check gets messy.
; After referencing someone's answer online, ended up with this solution, where the series itself
; is made up of integers (supporting the `a > b` check), but `term` maps the integer to the right
; fraction.
;---------------------------------------------------------------------------------------------------
(define (pi-approx n)
(define (term n)
(if (even? n)
(/ (+ 2 n) (+ 3 n))
(/ (+ 3 n) (+ 2 n))))
(* 4.0 (product 0 n term inc)))
;---------------------------------------------------------------------------------------------------
; Finally, rewrite `product` iteratively.
;---------------------------------------------------------------------------------------------------
(define (product-iter a b term next)
(define (iter-helper a sum)
(if (> a b)
sum
(iter-helper (next a)
(* sum (term a)))))
(iter-helper a 1))
| false |
7bd985139c79a8e24cbc41bb944296de3c267fe6 | 736e7201d8133f7b5262bbe3f313441c70367a3d | /misc/internal/windows/TeXmacs/progs/ice-9/and-let.scm | 1aa204334ac32aa8fa9ae69a0e0a9f65806e2430 | []
| no_license | KarlHegbloom/texmacs | 32eea6e344fd27ff02ff6a8027c065b32ff2b976 | ddc05600d3d15a0fbc72a50cb657e6c8ebe7d638 | refs/heads/master | 2021-01-16T23:52:33.776123 | 2018-06-08T07:47:26 | 2018-06-08T07:47:26 | 57,338,153 | 24 | 4 | null | 2017-07-17T05:47:17 | 2016-04-28T22:37:14 | Tcl | UTF-8 | Scheme | false | false | 1,619 | scm | and-let.scm | ;;;; and-let*.scm --- and-let* syntactic form (draft SRFI-2) for Guile
;;;; written by Michael Livshin <[email protected]>
;;;;
;;;; Copyright (C) 1999 Free Software Foundation, Inc.
;;;;
;;;; This program is free software; you can redistribute it and/or modify
;;;; it under the terms of the GNU General Public License as published by
;;;; the Free Software Foundation; either version 2, or (at your option)
;;;; any later version.
;;;;
;;;; This program is distributed in the hope that it will be useful,
;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;;;; GNU General Public License for more details.
;;;;
;;;; You should have received a copy of the GNU General Public License
;;;; along with this software; see the file COPYING. If not, write to
;;;; the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
;;;; Boston, MA 02111-1307 USA
(define-module (ice-9 and-let*))
(defmacro and-let* (vars . body)
(define (expand vars body)
(cond
((null? vars)
`(begin ,@body))
((pair? vars)
(let ((exp (car vars)))
(cond
((pair? exp)
(cond
((null? (cdr exp))
`(and ,(car exp) ,(expand (cdr vars) body)))
(else
(let ((var (car exp))
(val (cadr exp)))
`(let (,exp)
(and ,var ,(expand (cdr vars) body)))))))
(else
`(and ,exp ,(expand (cdr vars) body))))))
(else
(error "not a proper list" vars))))
(expand vars body))
(export-syntax and-let*)
| false |
bb5620f41895e6f1983e855bc4bd84e40592079e | fca0221e2352708d385b790c665abab64e92a314 | /redaction/benchmarks/MeroonV3-2008Mar01/interm.scm | 89baf3d5d01e1813d648417263de8c7d9f1f6d1c | [
"LicenseRef-scancode-warranty-disclaimer"
]
| no_license | sthilaid/memoire | a32fdb1f9add0cc0d97c095d11de0c52ae2ed2e2 | 9b26b0c76fddd5affaf06cf8aad2592b87f68069 | refs/heads/master | 2020-05-18T04:19:46.976457 | 2010-01-26T01:18:56 | 2010-01-26T01:18:56 | 141,195 | 1 | 2 | null | null | null | null | UTF-8 | Scheme | false | false | 4,601 | scm | interm.scm | ;;; $Id: interm.scm,v 1.1 2005/02/25 22:19:37 lucier Exp $
;;; Copyright (c) 1990-97 by Christian Queinnec. All rights reserved.
;;; ***********************************************
;;; Small, Efficient and Innovative Class System
;;; Meroon
;;; Christian Queinnec
;;; Ecole Polytechnique & INRIA--Rocquencourt
;;; ************************************************
;;; These functions are needed for the bootstrap.They will be
;;; superseded by Basics.scm and Coercers.scm files.
;;;=========================================================== predicates
(define (Class? o)
(and (Object? o) (Class-is-a? o Class-class)) )
(define (Handy-Class? o)
(and (Object? o) (Class-is-a? o Handy-Class-class)) )
(define (MeroonV2-Class? o)
(and (Object? o) (Class-is-a? o MeroonV2-Class-class)) )
(define (Generic? o)
(and (Object? o) (Class-is-a? o Generic-class)) )
(define (Field? o)
(and (Object? o) (Class-is-a? o Field-class)) )
(define (Mono-Field? o)
(and (Object? o) (Class-is-a? o Mono-Field-class)) )
(define (Poly-Field? o)
(and (Object? o) (Class-is-a? o Poly-Field-class)) )
(define (Dispatcher? o)
(and (Object? o) (Class-is-a? o Dispatcher-class)) )
(define (Immediate-Dispatcher? o)
(and (Object? o) (Class-is-a? o Immediate-Dispatcher-class)) )
(define (Subclass-Dispatcher? o)
(and (Object? o) (Class-is-a? o Subclass-Dispatcher-class)) )
(define (Indexed-Dispatcher? o)
(and (Object? o) (Class-is-a? o Indexed-Dispatcher-class)) )
(define (Global-Dispatcher? o)
(and (Object? o) (Class-is-a? o Global-Dispatcher-class)) )
(define (Virtual-Field? o)
(and (Object? o) (Class-is-a? o Virtual-Field-class)) )
;;;======================================================= temporary accessors:
(define (Field-name f)
(instance-ref f 0) )
(define (Field-initialized? f)
(instance-ref f 3) )
(define (Field-path-length f)
(instance-ref f 5) )
(define (Field-path f i)
(instance-ref f (fx+ 5 (fx+ 1 i))) )
(define (make-Mono-Field . content)
(allocate-full-instance (Class-number Mono-Field-class) content) )
(define (Field-immutable? f)
(instance-ref f 0) )
(define (make-Poly-Field . content)
(allocate-full-instance (Class-number Poly-Field-class) content) )
(define (Class-name c)
(instance-ref c 0) )
(define (Class-number c)
(instance-ref c 1) )
(define (set-Class-number! c cn)
(instance-set! c 1 cn) )
(define (Class-fields c)
(instance-ref c 2) )
(define (Class-super-number c)
(instance-ref c 4) )
(define (set-Class-super-number! c cn)
(instance-set! c 4 cn) )
(define (Class-subclass-numbers c)
(instance-ref c 5) )
(define (set-Class-subclass-numbers! c cns)
(instance-set! c 5 cns) )
(define (Class-allocator c)
(instance-ref c 7) )
(define (Generic-name g)
(instance-ref g 0) )
(define (Generic-variables g)
(instance-ref g 2) )
(define (Generic-dispatcher g)
(instance-ref g 3) )
(define (set-Generic-dispatcher! g d)
(instance-set! g 3 d) )
(define (Generic-top-classes g)
(instance-ref g 4) )
(define (Immediate-Dispatcher-method d)
(instance-ref d 1) )
(define (Indexed-Dispatcher-class-number o)
(instance-ref o 1) )
(define (Indexed-Dispatcher-class-depth o)
(instance-ref o 2) )
(define (set-Indexed-Dispatcher-no! d no)
(instance-set! d 3 no) )
(define (Indexed-Dispatcher-method-length o)
(instance-ref o 4) )
(define (set-Indexed-Dispatcher-method! o i v)
(instance-set! o (fx+ 5 i) v) )
(define (Subclass-Dispatcher-class-number d)
(instance-ref d 1) )
(define (Subclass-Dispatcher-class-depth d)
(instance-ref d 2) )
(define (Subclass-Dispatcher-no d)
(instance-ref d 3) )
(define (set-Subclass-Dispatcher-no! d v)
(instance-set! d 3 v) )
(define (Subclass-Dispatcher-yes d)
(instance-ref d 4) )
(define (set-Subclass-Dispatcher-yes! d v)
(instance-set! d 4 v) )
;;;======================================================== Makers
(define (make-Generic-1 name default variables dispatcher top-classes)
(instance
original-Generic-1-class-number
name default variables dispatcher top-classes ) )
(define (make-Immediate-Dispatcher method-finder method)
(instance
original-Immediate-Dispatcher-class-number
method-finder method ) )
(define (make-Subclass-Dispatcher method-finder class-number class-depth no yes)
(instance
original-Subclass-Dispatcher-class-number
method-finder class-number class-depth no yes) )
(define (make-Object)
(instance original-Object-class-number) )
;;; end of interm.scm
| false |
ee9d238eee6f45e6e9c526905ac679e22f1c12f8 | 360ea1a4b5c638df02f7be578ada6c0f2ca8708f | /eval.scm | 188ef823f122b4b64811ff185d50966c780c4cc3 | [
"ISC"
]
| permissive | alanpost/genturfahi | cde9757f34f98841115775d22f8fc3a98510f8f0 | 44692683e7f45d4755cf6628fdab78e8ee46ebbc | refs/heads/master | 2020-03-26T16:34:11.354328 | 2012-10-19T13:45:06 | 2012-10-19T13:45:06 | null | 0 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 2,480 | scm | eval.scm | ;;;;
;;;; genturfahi - lo la .ckim. ke pe'a jajgau ratcu ke'e genturfa'i
;;;; `-> A Scheme packrat parser.
;;;;
;;;; Copyright (c) 2010 ".alyn.post." <[email protected]>
;;;;
;;;; Permission to use, copy, modify, and/or distribute this software for any
;;;; purpose with or without fee is hereby granted, provided that the above
;;;; copyright notice and this permission notice appear in all copies.
;;;;
;;;; THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
;;;; WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
;;;; MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
;;;; ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
;;;; WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
;;;; ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
;;;; OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
;;;;
;;;
;;; This environment is used to evaluate header code in .peg files.
;;;
(define genturfahi-env
(make-safe-environment parent: default-safe-environment))
;; extend the regular safe environment with genturfa'i parameters.
;;
(safe-environment-set!
genturfahi-env
'start-production
secuxna-start-production)
(safe-environment-set!
genturfahi-env
'define-name
secuxna-define-name)
(safe-environment-set!
genturfahi-env
'define-toplevel
secuxna-define-toplevel)
(safe-environment-set!
genturfahi-env
'output-file
(lambda (file)
(call-with-output-file file current-output-port)))
(safe-environment-set!
genturfahi-env
'debug-file
secuxna-debug-file)
(safe-environment-set!
genturfahi-env
'profile-file
secuxna-profile-file)
(safe-environment-set!
genturfahi-env
'debug
secuxna-debug)
(safe-environment-set!
genturfahi-env
'profile
secuxna-profile)
(safe-environment-set!
genturfahi-env
'no-memoize
secuxna-no-memoize)
(safe-environment-set!
genturfahi-env
'sentinel
secuxna-sentinel)
(safe-environment-set!
genturfahi-env
'empty-list
secuxna-empty-list)
(safe-environment-set!
genturfahi-env
'empty-string
secuxna-empty-string)
(safe-environment-set!
genturfahi-env
'?-default
secuxna-?-default)
(safe-environment-set!
genturfahi-env
'*-default
secuxna-*-default)
(safe-environment-set!
genturfahi-env
'nonmatch-token
secuxna-nonmatch-token)
(safe-environment-set!
genturfahi-env
'ignore
'secuxna-nastura)
| false |
d3bf22f746b8cc41562c7e4644dbaf33e092bb1b | 7a99d26da1b0d9fd47afa7381dd3578962b6b348 | /syntax.sls | 84242786f1194b19c820498545b8205a018f0d26 | [
"BSD-3-Clause"
]
| permissive | localchart/ijputils | 142a090dcf104d059d147d6b82cdab5b46883e10 | 78dc951b3618f07d1f4484445f98144128afaf22 | refs/heads/master | 2021-01-18T11:37:26.235053 | 2014-07-13T05:59:17 | 2014-07-13T05:59:17 | null | 0 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 2,286 | sls | syntax.sls | #!r6rs
(library (ijputils syntax)
;; These should probably be exported at levels 0 and 1 as we most
;; likely want to use them in a syntax-case macro
;; TODO: find out a way to write `syntax?'
(export syntax->list
syntax->dotted-list
syntax-e
gensym
make-id
with-syntax*
)
(import (rnrs base)
(rnrs syntax-case)
(only (srfi :1) dotted-list? cons*)
(ijputils symbols)
)
(define (map-if predicate mapper list) ;from (familiars lists)
(map (lambda (x)
(if (predicate x)
(mapper x)
x))
list))
(define (syntax->list stxobj)
(define (inner stx)
(syntax-case stx ()
[() '()]
[(x . rest)
(cons #'x (inner #'rest))]))
(assert (list? (syntax->datum stxobj)))
(inner stxobj))
(define (syntax->dotted-list dlist)
(define (inner stx)
(syntax-case stx ()
[(x . rest)
(cons #'x (inner #'rest))]
[x #'x]))
(assert (dotted-list? (syntax->datum dlist)))
(inner dlist))
(define (syntax-e obj)
(syntax-case obj ()
[(x ...)
(apply list #'(x ...))]
[#(value ...)
(apply vector #'(value ...))]
[a (syntax->dotted-list #'a)]))
;; Other ideas,
;; with-syntax*
;; like with-syntax but nested
;; syntax-map
;; like (syntax-map f l) => (map f (syntax->list l))
(define (syntax-map proc l)
(assert (list? (syntax->datum l)))
(let loop ((stx-list l) (return-list '()))
(syntax-case stx-list ()
[() (reverse return-list)]
[(first . rest)
(loop #'rest (cons (proc #'first) return-list))])))
;; block
;; allows interleaving of definitions and expressions
;; syntax-parameters
(define (gensym)
(syntax->datum (car (generate-temporaries (list 'g)))))
;; may come in handy
(define (make-id stx . syms&ids)
(datum->syntax stx
(apply symbol-append
(map-if identifier? syntax->datum syms&ids))))
(define-syntax with-syntax*
(syntax-rules ()
[(with-syntax* () body rest ...)
(with-syntax () body rest ...)]
[(with-syntax* (one) body rest ...)
(with-syntax (one) body rest ...)]
[(with-syntax* (car . cdr) body rest ...)
(with-syntax (car)
(with-syntax* cdr body rest ...))]))
)
| true |
d94a6319409ab9acd45224abf9037359fae69bda | 06d73af66d0c8450e2c9cb20757774c61c813ee6 | /pairs.ss | b86ce0a5666f73889861f19a30dd27126761a6d0 | []
| no_license | logicshan/lc-with-redex | ce5dc164abc6550bb431b2a7fa20c98f5c024037 | 63aa4cbf1f0acf0553c545686ba00a1699f003f8 | refs/heads/master | 2020-12-29T01:42:06.026750 | 2014-04-29T05:23:37 | 2014-04-29T05:23:37 | null | 0 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 174 | ss | pairs.ss | #lang scheme ; file pairs.ss
(require "booleans.ss" "lazy-evaluator.ss")
(def Cons (λ (x y z) (If z x y)))
(def Car (λ (x) (x True)))
(def Cdr (λ (x) (x False)))
| false |
8b73f75afcc38f68d562e4a2464328b81f2d7d93 | d8bdd07d7fff442a028ca9edbb4d66660621442d | /scam/tests/10-scheme/char/equal-ci.scm | b9f2e28857de74f2785bb125d0399f21cf91319a | []
| no_license | xprime480/scam | 0257dc2eae4aede8594b3a3adf0a109e230aae7d | a567d7a3a981979d929be53fce0a5fb5669ab294 | refs/heads/master | 2020-03-31T23:03:19.143250 | 2020-02-10T20:58:59 | 2020-02-10T20:58:59 | 152,641,151 | 0 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 440 | scm | equal-ci.scm | (import (scheme char)
(test narc))
(narc-label "(CI) String Equality")
(define err :not-a-string)
(define s1 "")
(define s2 "boy")
(define s3 "BoY")
(define s4 "girl")
(narc-expect
(#f (string-ci=? s1 s2))
(#t (string-ci=? s2 s2))
(#f (string-ci=? s2 s4))
(#t (string-ci=? s2 s3))
(#t (string-ci=? s2 s3 s3 s2)))
(narc-catch
(:args (string-ci=? s1 s2 err))
(:args (string-ci=?))
(:args (string-ci=? s1)))
(narc-report)
| false |
973ba958c1ae12af0bf6f8a1f63a02ef03845d5e | 688feb2eac8bc384583c4f0960cfbc86c3470d91 | /chicken/sinatra/rack.scm | bdd7c4d626d709148950a6539a58868a0e14d50e | []
| no_license | halida/code_example | 7d2873e92707b4bab673046ff3d0c742e1984b4c | 5c882a24b93696c2122a78425ef6b3775adc80fa | refs/heads/master | 2023-06-08T15:51:23.150728 | 2022-03-27T09:57:43 | 2022-03-27T09:57:43 | 2,458,466 | 2 | 1 | null | 2023-06-06T02:07:28 | 2011-09-26T06:01:29 | Ruby | UTF-8 | Scheme | false | false | 502 | scm | rack.scm | ;; (use 'http-server)
;; (define (rack-run server)
;; todo
;; )
(use spiffy regex)
(define (rack-run server)
(define (handler continue)
(let* ((response (server (current-request)))
(code (car response))
(body (cadr response))
(headers '((content-type text/html)))
)
(send-response code: code body: body headers: headers)
(continue)
)
)
(vhost-map
`(
(,(glob->regexp "*") . ,handler)
))
(start-server)
)
| false |
98b487a5521a5a91e7967facdb28d18c96024474 | e42c980538d5315b9cca17460c90d9179cc6fd3a | /scm/format.scm | fc61aee6a0b7035e8b6ab38086c5126fc2d6d398 | []
| no_license | KenDickey/Scheme2Smalltalk-Translator | c4415f2053932a2c83b59ac9a554097836c55873 | 9ccd4e45fb386f99d2e62fc769f78241fbe29c77 | refs/heads/master | 2020-12-24T19:46:30.348021 | 2016-05-13T23:12:06 | 2016-05-13T23:12:06 | 58,775,118 | 1 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 9,830 | scm | format.scm | ; FILE: "format.scm"
; IMPLEMENTS: Format function {Scheme} -- see documentation below.
; AUTHOR: Ken Dickey
; DATE: 1988
; LAST UPDATE: 1993 September 13 -- do without string ports
; 1992 January 8 -- now implements ~& option
; 1991 November 25 -- now uses string ports
; NOTES: Imports PRETTY-PRINT (~g) and OBJECT->STRING
; Pretty print and various other code is available via ftp
; from the Scheme Repository on nexus.yorku.ca [130.63.9.1]
; under pub/scheme. Contact: Ozan Yigit: [email protected].
;
;; ========
;; FUNCTION: (FORMAT <port> <format-string> . <args>)
;; ========
;; RESULT: returns unconsumed <args> or a string; has side effect of
;; printing according to <format-string>. If <port> is #t the output is
;; to the current output port. If <port> is #f, a formatted string is
;; returned as the result of the call. Otherwise <port> must be an
;; output port. <format-string> must be a string. Characters are output
;; as if the string were output by the DISPLAY function with the
;; exception of those prefixed by a tilde (~) as follows [note that options
;; which take arguments remove them from the argument list (they are said to
;; be `consumed')]:
;;
;;option mnemonic: description
;;------ ------------------------
;; ~a any: display the argument (as for humans).
;; ~s slashified: write the argument (as for parsers).
;; ~d decimal: the integer argument is output in decimal format.
;; ~x hexadecimal: the integer argument is output in hexadecimal format.
;; ~o octal: the integer argument is output in octal format.
;; ~b binary: the integer argument is output in binary format.
;; ~p plural: if the argument is > than 1, a lower case 's' is printed.
;; ~c character: the next argument is displayed as a character.
;; ~_ space: output a space character.
;; ~% newline: output a newline character.
;; ~& freshline: unless at the beginning of a line, same as ~%, else ignored
;; ~~ tilde: output a tilde.
;; ~t tab: output a tab charcter. **implemented, but system dependent**
;; ~g glorify: pretty print the argument (typically an s-expression).
;; ~| page seperator: output a page seperator.
;; ~? indirection: take the next argument as a format string and consume
;; further arguments as appropriate, then continue to process the current
;; format string.
;;
;----- IMPLEMENTATION SPECIFIC OPTIMIZATIONS
;; (##declare (standard-bindings) (fixnum)) ;; GAMBIT (v1.71)
;---------- FORMAT
(define FORMAT
(let ( (LAST-WAS-NEWLINE #f)
; state shared between invocations
(ASCII-TAB (integer->char 9))
(ASCII-FF (integer->char 12))
(DONT-PRINT (string->symbol "")) ;; a zero character symbol
)
(lambda (<output-port> <format-string> . <args>)
(letrec ( (PORT
(cond ((output-port? <output-port>) <output-port>)
((eq? <output-port> #t) (current-output-port))
((eq? <output-port> #f) (open-output-string))
(else (error "format: bad port -> " <output-port>))
) )
(RETURN-VALUE
(if (eq? <output-port> #f) ;; format to a string
(lambda () (get-output-string port))
(lambda () dont-print))
)
)
(define (FORMAT-HELP format-strg arglyst)
(letrec (
(LENGTH-OF-FORMAT-STRING (string-length format-strg))
(ANYCHAR-DISPATCH
(lambda (pos arglist last-char-was-nl)
(if (>= pos length-of-format-string)
(begin
(set! last-was-newline last-char-was-nl)
arglist ; used for ~? continuance
)
(let ( (char (string-ref format-strg pos)) )
(cond
((eq? char #\~)
(tilde-dispatch (+ pos 1) arglist last-char-was-nl))
(else
(write-char char port)
(anychar-dispatch (+ pos 1) arglist #f)
))
))
)) ; end anychar-dispatch
(TILDE-DISPATCH
(lambda (pos arglist last-char-was-nl)
(cond
((>= pos length-of-format-string)
(write-char #\~ port) ; tilde at end of string is just output
(set! last-was-newline last-char-was-nl)
arglist ; used for ~? continuance
)
(else
(case (char-upcase (string-ref format-strg pos))
((#\A) ; Any -- for humans
(display (car arglist) port)
(anychar-dispatch (+ pos 1) (cdr arglist) #f)
)
((#\S) ; Slashified -- for parsers
(write (car arglist) port)
(anychar-dispatch (+ pos 1) (cdr arglist) #f)
)
((#\D) ; Decimal
(display (number->string (car arglist) 10) port)
(anychar-dispatch (+ pos 1) (cdr arglist) #f)
)
((#\X) ; Hexadecimal
(display (number->string (car arglist) 16) port)
(anychar-dispatch (+ pos 1) (cdr arglist) #f)
)
((#\O) ; Octal
(display (number->string (car arglist) 8) port)
(anychar-dispatch (+ pos 1) (cdr arglist) #f)
)
((#\B) ; Binary
(display (number->string (car arglist) 2) port)
(anychar-dispatch (+ pos 1) (cdr arglist) #f)
)
((#\C) ; Character
(write-char (car arglist) port)
(anychar-dispatch (+ pos 1) (cdr arglist) #f)
)
((#\P) ; Plural
(if (= (car arglist) 1)
#f ; no action
(write-char #\s port))
(anychar-dispatch (+ pos 1) (cdr arglist) #f)
)
((#\~) ; Tilde
(write-char #\~ port)
(anychar-dispatch (+ pos 1) arglist #f)
)
((#\%) ; Newline
(newline port)
(anychar-dispatch (+ pos 1) arglist #t)
)
((#\_) ; Space
(write-char #\space port)
(anychar-dispatch (+ pos 1) arglist #f)
)
((#\&) ; Freshline
(if (not last-char-was-nl)
(newline port))
(anychar-dispatch (+ pos 1) arglist #t)
)
((#\T) ; Tab -- Implementation dependent
(write-char ASCII-TAB port)
(anychar-dispatch (+ pos 1) arglist #f)
)
((#\|) ; Page Seperator -- Implementation dependent
(write-char ascii-ff port) ;; use form-feed char
(anychar-dispatch (+ pos 1) arglist #t) ; counts as newline
)
((#\G) ; Pretty-print {T}
(if (eq? port #f)
(display (pretty-print-to-string (car arglist)) port)
(pretty-print (car arglist) port))
(anychar-dispatch (+ pos 1) (cdr arglist) #t) ; check this!
)
;; {"~?" in Common Lisp is "~K" in T}
((#\?) ; indirection -- take next arg as format string
(set! last-was-newline last-char-was-nl)
(anychar-dispatch
(+ pos 1)
(format-help (car arglist) (cdr arglist))
last-was-newline)
; Note: format-help returns unused args
)
(else
(error "FORMAT: unknown tilde escape"
(string-ref format-strg pos)))
)))
)) ; end tilde-dispatch
)
; FORMAT-HELP MAIN
(anychar-dispatch 0 arglyst last-was-newline)
)) ; end format-help
; FORMAT MAIN
(format-help <format-string> <args>)
(return-value)
) ; end let
))) ; end format
;;---------------------------------E-O-F---------------------------------;; | false |
4275fe753ef4e4ca61cb4e177da31eb007c2a6df | 120324bbbf63c54de0b7f1ca48d5dcbbc5cfb193 | /packages/slib/comparse.scm | 3dacf50a2754971650ad72042aa8e04dc7136941 | [
"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 | 6,464 | scm | comparse.scm | ;;; "comparse.scm" Break command line into arguments.
;Copyright (C) 1995, 1997, 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.
;;;; This is a simple command-line reader. It could be made fancier
;;; to handle lots of `shell' syntaxes.
;;; Albert L. Ting points out that a similar process can be used for
;;; reading files of options -- therefore READ-OPTIONS-FILE.
(require 'string-port)
;;@code{(require 'read-command)}
;;@ftindex read-command
(define (read-command-from-port port nl-term?)
(define argv '())
(define obj "")
(define chars '())
(define readc (lambda () (read-char port)))
(define peekc (lambda () (peek-char port)))
(define s-expression
(lambda ()
(splice-arg (call-with-output-string
(lambda (p) (display (slib:eval (read port)) p))))))
(define backslash
(lambda (goto)
(readc)
(let ((c (readc)))
(cond ((eqv? #\newline c) (goto (peekc)))
((and (char-whitespace? c) (eqv? #\newline (peekc))
(eqv? 13 (char->integer c)))
(readc) (goto (peekc)))
(else (set! chars (cons c chars)) (build-token (peekc)))))))
(define loop
(lambda (c)
(case c
((#\\) (backslash loop))
((#\") (splice-arg (read port)))
((#\( #\') (s-expression))
((#\#) (do ((c (readc) (readc)))
((or (eof-object? c) (eqv? #\newline c))
(if nl-term? c (loop (peekc))))))
((#\;) (readc))
((#\newline) (readc) (and (not nl-term?) (loop (peekc))))
(else (cond ((eof-object? c) c)
((char-whitespace? c) (readc) (loop (peekc)))
(else (build-token c)))))))
(define splice-arg
(lambda (arg)
(set! obj (string-append obj (list->string (reverse chars)) arg))
(set! chars '())
(build-token (peekc))))
(define buildit
(lambda ()
(readc)
(set! argv (cons (string-append obj (list->string (reverse chars)))
argv))))
(define build-token
(lambda (c)
(case c
((#\") (splice-arg (read port)))
((#\() (s-expression))
((#\\) (backslash build-token))
((#\;) (buildit))
(else (cond ((or (eof-object? c) (char-whitespace? c))
(buildit)
(cond ((not (and nl-term? (eqv? c #\newline)))
(set! obj "")
(set! chars '())
(loop (peekc)))))
(else (set! chars (cons (readc) chars))
(build-token (peekc))))))))
(let ((c (loop (peekc))))
(cond ((and (null? argv) (eof-object? c)) c)
(else (reverse argv)))))
;;@args port
;;@args
;;@code{read-command} converts a @dfn{command line} into a list of strings
;;@cindex command line
;;suitable for parsing by @code{getopt}. The syntax of command lines
;;supported resembles that of popular @dfn{shell}s. @code{read-command}
;;updates @var{port} to point to the first character past the command
;;delimiter.
;;
;;If an end of file is encountered in the input before any characters are
;;found that can begin an object or comment, then an end of file object is
;;returned.
;;
;;The @var{port} argument may be omitted, in which case it defaults to the
;;value returned by @code{current-input-port}.
;;
;;The fields into which the command line is split are delimited by
;;whitespace as defined by @code{char-whitespace?}. The end of a command
;;is delimited by end-of-file or unescaped semicolon (@key{;}) or
;;@key{newline}. Any character can be literally included in a field by
;;escaping it with a backslach (@key{\}).
;;
;;The initial character and types of fields recognized are:
;;@table @asis
;;@item @samp{\}
;;The next character has is taken literally and not interpreted as a field
;;delimiter. If @key{\} is the last character before a @key{newline},
;;that @key{newline} is just ignored. Processing continues from the
;;characters after the @key{newline} as though the backslash and
;;@key{newline} were not there.
;;@item @samp{"}
;;The characters up to the next unescaped @key{"} are taken literally,
;;according to [R4RS] rules for literal strings
;;(@pxref{Strings, , ,r4rs, Revised(4) Scheme}).
;;@item @samp{(}, @samp{%'}
;;One scheme expression is @code{read} starting with this character. The
;;@code{read} expression is evaluated, converted to a string
;;(using @code{display}), and replaces the expression in the returned
;;field.
;;@item @samp{;}
;;Semicolon delimits a command. Using semicolons more than one command
;;can appear on a line. Escaped semicolons and semicolons inside strings
;;do not delimit commands.
;;@end table
;;
;;@noindent
;;The comment field differs from the previous fields in that it must be
;;the first character of a command or appear after whitespace in order to
;;be recognized. @key{#} can be part of fields if these conditions are
;;not met. For instance, @code{ab#c} is just the field ab#c.
;;
;;@table @samp
;;@item #
;;Introduces a comment. The comment continues to the end of the line on
;;which the semicolon appears. Comments are treated as whitespace by
;;@code{read-dommand-line} and backslashes before @key{newline}s in
;;comments are also ignored.
;;@end table
(define (read-command . port)
(read-command-from-port (cond ((null? port) (current-input-port))
((= 1 (length port)) (car port))
(else
(slib:error 'read-command
"Wrong Number of ARGs:" port)))
#t))
;;@body
;;@code{read-options-file} converts an @dfn{options file} into a list of
;;@cindex options file
;;strings suitable for parsing by @code{getopt}. The syntax of options
;;files is the same as the syntax for command
;;lines, except that @key{newline}s do not terminate reading (only @key{;}
;;or end of file).
;;
;;If an end of file is encountered before any characters are found that
;;can begin an object or comment, then an end of file object is returned.
(define (read-options-file filename)
(call-with-input-file filename
(lambda (port) (read-command-from-port port #f))))
| false |
9601600124cb0b30e689923ad7ba0f848f85b497 | eef5f68873f7d5658c7c500846ce7752a6f45f69 | /spheres/algorithm/shuffle/merge.sld | 9eea633c7ef05e881d93edd3987d91820ca62f27 | [
"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 | 229 | sld | merge.sld | ;;!!! Shuffle algorithms
;; .author Taylor Campbell
;; .author Alvaro Castro-Castilla, 2014
(define-library (spheres/algorithm/shuffle merge)
(export merge-shuffle-list
merge-shuffle-list!)
(include "merge.scm"))
| false |
74892070c6663dc956b77c63ea267b1269a54579 | defeada37d39bca09ef76f66f38683754c0a6aa0 | /System.Xml/mono/xml/xsl/xml-writer-emitter.sls | a5fcd78c0e6e44cfa9aebfa0097d866d2b50a956 | []
| 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,739 | sls | xml-writer-emitter.sls | (library (mono xml xsl xml-writer-emitter)
(export new
is?
xml-writer-emitter?
write-start-element
write-processing-instruction
write-comment
write-start-document
write-attribute-string
write-cdata-section
write-full-end-element
write-raw
write-doc-type
write-string
write-end-document
write-end-element
done
write-whitespace)
(import (ironscheme-clr-port))
(define-syntax new
(lambda (e)
(syntax-case e ()
((_ a ...) #'(clr-new Mono.Xml.Xsl.XmlWriterEmitter a ...)))))
(define (is? a) (clr-is Mono.Xml.Xsl.XmlWriterEmitter a))
(define (xml-writer-emitter? a)
(clr-is Mono.Xml.Xsl.XmlWriterEmitter a))
(define-method-port
write-start-element
Mono.Xml.Xsl.XmlWriterEmitter
WriteStartElement
(System.Void System.String System.String System.String))
(define-method-port
write-processing-instruction
Mono.Xml.Xsl.XmlWriterEmitter
WriteProcessingInstruction
(System.Void System.String System.String))
(define-method-port
write-comment
Mono.Xml.Xsl.XmlWriterEmitter
WriteComment
(System.Void System.String))
(define-method-port
write-start-document
Mono.Xml.Xsl.XmlWriterEmitter
WriteStartDocument
(System.Void System.Text.Encoding Mono.Xml.Xsl.StandaloneType))
(define-method-port
write-attribute-string
Mono.Xml.Xsl.XmlWriterEmitter
WriteAttributeString
(System.Void
System.String
System.String
System.String
System.String))
(define-method-port
write-cdata-section
Mono.Xml.Xsl.XmlWriterEmitter
WriteCDataSection
(System.Void System.String))
(define-method-port
write-full-end-element
Mono.Xml.Xsl.XmlWriterEmitter
WriteFullEndElement
(System.Void))
(define-method-port
write-raw
Mono.Xml.Xsl.XmlWriterEmitter
WriteRaw
(System.Void System.String))
(define-method-port
write-doc-type
Mono.Xml.Xsl.XmlWriterEmitter
WriteDocType
(System.Void System.String System.String System.String))
(define-method-port
write-string
Mono.Xml.Xsl.XmlWriterEmitter
WriteString
(System.Void System.String))
(define-method-port
write-end-document
Mono.Xml.Xsl.XmlWriterEmitter
WriteEndDocument
(System.Void))
(define-method-port
write-end-element
Mono.Xml.Xsl.XmlWriterEmitter
WriteEndElement
(System.Void))
(define-method-port
done
Mono.Xml.Xsl.XmlWriterEmitter
Done
(System.Void))
(define-method-port
write-whitespace
Mono.Xml.Xsl.XmlWriterEmitter
WriteWhitespace
(System.Void System.String)))
| true |
4cd7b490c1a2e6c16843a411e4c155ced959136f | b26941aa4aa8da67b4a7596cc037b92981621902 | /codingForFun/age_of_empire.scm | ad5774e0f2471f0755912a5da680bbc4be3fc1c2 | []
| no_license | Alaya-in-Matrix/scheme | a1878ec0f21315d5077ca1c254c3b9eb4c594c10 | bdcfcf3367b664896e8a7c6dfa0257622493e184 | refs/heads/master | 2021-01-01T19:42:32.633019 | 2015-01-31T08:24:02 | 2015-01-31T08:24:02 | 22,753,765 | 0 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 245 | scm | age_of_empire.scm | ;;implementing syntax of the script for game AGE OF EMPIRES
(define-syntax define-rules
(syntax-rules (=>)
((define-rules condition => action ... )
(if condition
(begin action ...)))))
| true |
de8bdc385e0309b0d9ce597ba6a544c6a6ec2e37 | acc632afe0d8d8b94b781beb1442bbf3b1488d22 | /deps/sdl2/lib/sdl2/texture.scm | f3e800c7ba705dcda3791d55b3194938a50ab957 | [
"BSD-2-Clause",
"BSD-3-Clause"
]
| permissive | kdltr/life-is-so-pretty | 6cc6e6c6e590dda30c40fdbfd42a5a3a23644794 | 5edccf86702a543d78f8c7e0f6ae544a1b9870cd | refs/heads/master | 2021-01-20T21:12:00.963219 | 2016-05-13T12:19:02 | 2016-05-13T12:19:02 | 61,128,206 | 1 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 11,694 | scm | texture.scm | ;;
;; chicken-sdl2: CHICKEN Scheme bindings to Simple DirectMedia Layer 2
;;
;; Copyright © 2013, 2015-2016 John Croisant.
;; All rights reserved.
;;
;; Redistribution and use in source and binary forms, with or without
;; modification, are permitted provided that the following conditions
;; are met:
;;
;; - Redistributions of source code must retain the above copyright
;; notice, this list of conditions and the following disclaimer.
;;
;; - Redistributions in binary form must reproduce the above copyright
;; notice, this list of conditions and the following disclaimer in
;; the documentation and/or other materials provided with the
;; distribution.
;;
;; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
;; "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
;; LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
;; FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
;; COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
;; INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
;; (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
;; SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
;; HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
;; STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
;; ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
;; OF THE POSSIBILITY OF SUCH DAMAGE.
(export create-texture
create-texture*
create-texture-from-surface
create-texture-from-surface*
destroy-texture!
query-texture
query-texture-raw
texture-format
texture-access
texture-w
texture-h
lock-texture-raw!
unlock-texture!
update-texture-raw!
update-yuv-texture-raw! ;; SDL >= 2.0.1
texture-alpha-mod texture-alpha-mod-set!
texture-blend-mode texture-blend-mode-set!
texture-color-mod texture-color-mod-set!
texture-colour-mod texture-colour-mod-set!
)
(: create-texture
(sdl2:renderer* enum enum fixnum fixnum
-> sdl2:texture))
(define (create-texture renderer format access w h)
(set-finalizer! (create-texture* renderer format access w h)
destroy-texture!))
(: create-texture*
(sdl2:renderer* enum enum fixnum fixnum
-> sdl2:texture))
(define (create-texture* renderer format access w h)
(let* ((format-int (if (integer? format)
format
(symbol->pixel-format-enum format)))
(access-int (if (integer? access)
access
(symbol->texture-access access)))
(texture (SDL_CreateTexture
renderer format-int access-int w h)))
(if (and (texture? texture) (not (struct-null? texture)))
texture
(abort (sdl-failure "SDL_CreateTexture" #f)))))
(: create-texture-from-surface
(sdl2:renderer* sdl2:surface* -> sdl2:texture))
(define (create-texture-from-surface renderer surface)
(set-finalizer! (create-texture-from-surface* renderer surface)
destroy-texture!))
(: create-texture-from-surface*
(sdl2:renderer* sdl2:surface* -> sdl2:texture))
(define (create-texture-from-surface* renderer surface)
(let ((texture (SDL_CreateTextureFromSurface renderer surface)))
(if (and (texture? texture) (not (struct-null? texture)))
texture
(abort (sdl-failure "SDL_CreateTextureFromSurface" #f)))))
(: destroy-texture!
(sdl2:texture* -> void))
(define (destroy-texture! texture)
(unless (struct-null? texture)
(SDL_DestroyTexture texture)))
(: query-texture
(sdl2:texture* -> symbol symbol fixnum fixnum))
(define (query-texture texture)
(receive (format-int access-int w h) (query-texture-raw texture)
(values (pixel-format-enum->symbol format-int)
(texture-access->symbol access-int)
w
h)))
(: query-texture-raw
(sdl2:texture* -> fixnum fixnum fixnum fixnum))
(define (query-texture-raw texture)
(with-temp-mem ((format-out (%allocate-Uint32))
(access-out (%allocate-Sint32))
(w-out (%allocate-Sint32))
(h-out (%allocate-Sint32)))
(let ((ret-code (SDL_QueryTexture
texture format-out access-out w-out h-out)))
(if (zero? ret-code)
(values (pointer-u32-ref format-out)
(pointer-s32-ref access-out)
(pointer-s32-ref w-out)
(pointer-s32-ref h-out))
(begin
(free format-out)
(free access-out)
(free w-out)
(free h-out)
(abort (sdl-failure "SDL_QueryTexture" ret-code)))))))
(: texture-format
(sdl2:texture* -> symbol))
(define (texture-format texture)
(with-temp-mem ((format-out (%allocate-Sint32)))
(let ((ret-code (SDL_QueryTexture texture format-out #f #f #f)))
(if (zero? ret-code)
(pixel-format-enum->symbol (pointer-s32-ref format-out))
(begin
(free format-out)
(abort (sdl-failure "SDL_QueryTexture" ret-code)))))))
(: texture-access
(sdl2:texture* -> symbol))
(define (texture-access texture)
(with-temp-mem ((access-out (%allocate-Sint32)))
(let ((ret-code (SDL_QueryTexture texture #f access-out #f #f)))
(if (zero? ret-code)
(texture-access->symbol (pointer-s32-ref access-out))
(begin
(free access-out)
(abort (sdl-failure "SDL_QueryTexture" ret-code)))))))
(: texture-w
(sdl2:texture* -> fixnum))
(define (texture-w texture)
(with-temp-mem ((w-out (%allocate-Sint32)))
(let ((ret-code (SDL_QueryTexture texture #f #f w-out #f)))
(if (zero? ret-code)
(pointer-s32-ref w-out)
(begin
(free w-out)
(abort (sdl-failure "SDL_QueryTexture" ret-code)))))))
(: texture-h
(sdl2:texture* -> fixnum))
(define (texture-h texture)
(with-temp-mem ((h-out (%allocate-Sint32)))
(let ((ret-code (SDL_QueryTexture texture #f #f #f h-out)))
(if (zero? ret-code)
(pointer-s32-ref h-out)
(begin
(free h-out)
(abort (sdl-failure "SDL_QueryTexture" ret-code)))))))
(: lock-texture-raw!
(sdl2:texture* (or sdl2:rect* boolean) -> pointer fixnum))
(define (lock-texture-raw! texture rect)
(with-temp-mem ((pitch-out (%allocate-Sint32)))
(let* ((pixels** (make-pointer-vector 1))
(ret-code (SDL_LockTexture
texture rect pixels** pitch-out)))
(if (zero? ret-code)
(values (pointer-vector-ref pixels** 0)
(pointer-s32-ref pitch-out))
(begin
(free pitch-out)
(abort (sdl-failure "SDL_LockTexture" #f)))))))
(: unlock-texture!
(sdl2:texture* -> void))
(define (unlock-texture! texture)
(SDL_UnlockTexture texture))
(: update-texture-raw!
(sdl2:texture* (or sdl2:rect* boolean) (or pointer locative) fixnum
-> void))
(define (update-texture-raw! texture rect pixels pitch)
(let ((ret-code (SDL_UpdateTexture texture rect pixels pitch)))
(unless (zero? ret-code)
(abort (sdl-failure "SDL_UpdateTexture" ret-code)))))
(: update-yuv-texture-raw!
(sdl2:texture*
(or sdl2:rect* boolean)
(or pointer locative) fixnum
(or pointer locative) fixnum
(or pointer locative) fixnum
-> void))
(define-versioned (update-yuv-texture-raw!
texture rect y-plane y-pitch
u-plane u-pitch v-plane v-pitch)
libSDL-2.0.1+
(let ((ret-code (SDL_UpdateYUVTexture
texture rect y-plane y-pitch
u-plane u-pitch v-plane v-pitch)))
(unless (zero? ret-code)
(abort (sdl-failure "SDL_UpdateYUVTexture" ret-code)))))
(: texture-alpha-mod
(sdl2:texture* -> fixnum))
(define (texture-alpha-mod texture)
(with-temp-mem ((alpha-out (%allocate-Uint8)))
(let ((ret-code (SDL_GetTextureAlphaMod texture alpha-out)))
(if (zero? ret-code)
(pointer-u8-ref alpha-out)
(begin
(free alpha-out)
(abort (sdl-failure "SDL_GetTextureAlphaMod" ret-code)))))))
(: texture-alpha-mod-set!
(sdl2:texture* fixnum -> void))
(define (texture-alpha-mod-set! texture alpha)
(let ((ret-code (SDL_SetTextureAlphaMod texture alpha)))
(unless (zero? ret-code)
(abort (sdl-failure "SDL_SetTextureAlphaMod" ret-code)))))
(set! (setter texture-alpha-mod) texture-alpha-mod-set!)
(: texture-blend-mode
(sdl2:texture* -> symbol))
(define (texture-blend-mode texture)
(with-temp-mem ((mode-out (%allocate-Uint8)))
(let ((ret-code (SDL_GetTextureBlendMode texture mode-out)))
(if (zero? ret-code)
(blend-mode->symbol (pointer-u8-ref mode-out))
(begin
(free mode-out)
(abort (sdl-failure "SDL_GetTextureBlendMode" ret-code)))))))
(: texture-blend-mode-raw
(sdl2:texture* -> fixnum))
(define (texture-blend-mode-raw texture)
(with-temp-mem ((mode-out (%allocate-Uint8)))
(let ((ret-code (SDL_GetTextureBlendMode texture mode-out)))
(if (zero? ret-code)
(pointer-u8-ref mode-out)
(begin
(free mode-out)
(abort (sdl-failure "SDL_GetTextureBlendMode" ret-code)))))))
(: texture-blend-mode-set!
(sdl2:texture* enum -> void))
(define (texture-blend-mode-set! texture blend-mode)
(define (bad-mode-err x)
(error 'texture-blend-mode-set!
"Invalid texture blend mode" x))
(let* ((mode-int (cond ((integer? blend-mode)
blend-mode)
(else
(symbol->blend-mode
blend-mode bad-mode-err))))
(ret-code (SDL_SetTextureBlendMode texture mode-int)))
(unless (zero? ret-code)
(abort (sdl-failure "SDL_SetTextureBlendMode" ret-code)))))
(set! (setter texture-blend-mode) texture-blend-mode-set!)
(set! (setter texture-blend-mode-raw) texture-blend-mode-set!)
(: texture-color-mod
(sdl2:texture* -> fixnum fixnum fixnum))
(define (texture-color-mod texture)
(with-temp-mem ((r-out (%allocate-Uint8))
(g-out (%allocate-Uint8))
(b-out (%allocate-Uint8)))
(let ((ret-code (SDL_GetTextureColorMod
texture r-out g-out b-out)))
(if (zero? ret-code)
(values (pointer-u8-ref r-out)
(pointer-u8-ref g-out)
(pointer-u8-ref b-out))
(begin
(free r-out)
(free g-out)
(free b-out)
(abort (sdl-failure "SDL_GetTextureColorMod" ret-code)))))))
(: texture-color-mod-set!
(sdl2:texture* (or (list-of fixnum) sdl2:color) -> void))
(define (texture-color-mod-set! texture rgb-or-color)
(assert (or (list? rgb-or-color) (color? rgb-or-color)))
(receive (r g b) (if (list? rgb-or-color)
(values (list-ref rgb-or-color 0)
(list-ref rgb-or-color 1)
(list-ref rgb-or-color 2))
(values (color-r rgb-or-color)
(color-g rgb-or-color)
(color-b rgb-or-color)))
(let ((ret-code (SDL_SetTextureColorMod texture r g b)))
(unless (zero? ret-code)
(abort (sdl-failure "SDL_SetTextureColorMod" ret-code))))))
(set! (setter texture-color-mod) texture-color-mod-set!)
(define texture-colour-mod-set! texture-color-mod-set!)
(define texture-colour-mod texture-color-mod)
| false |
07f731e1ea767f434928ad0c535dd77b1bcae50f | 6b961ef37ff7018c8449d3fa05c04ffbda56582b | /bbn_cl/mach/cl/query.scm | 9bf280db998458122eab950576038c507b7ea4d1 | []
| no_license | tinysun212/bbn_cl | 7589c5ac901fbec1b8a13f2bd60510b4b8a20263 | 89d88095fc2a71254e04e57cf499ae86abf98898 | refs/heads/master | 2021-01-10T02:35:18.357279 | 2015-05-26T02:44:00 | 2015-05-26T02:44:00 | 36,267,589 | 4 | 3 | null | null | null | null | UTF-8 | Scheme | false | false | 2,740 | scm | query.scm | ;;; ********
;;;
;;; Copyright 1992 by BBN Systems and Technologies, A division of Bolt,
;;; Beranek and Newman Inc.
;;;
;;; Permission to use, copy, modify and distribute this software and its
;;; documentation is hereby granted without fee, provided that the above
;;; copyright notice and this permission appear in all copies and in
;;; supporting documentation, and that the name Bolt, Beranek and Newman
;;; Inc. not be used in advertising or publicity pertaining to distribution
;;; of the software without specific, written prior permission. In
;;; addition, BBN makes no respresentation about the suitability of this
;;; software for any purposes. It is provided "AS IS" without express or
;;; implied warranties including (but not limited to) all implied warranties
;;; of merchantability and fitness. In no event shall BBN be liable for any
;;; special, indirect or consequential damages whatsoever resulting from
;;; loss of use, data or profits, whether in an action of contract,
;;; negligence or other tortuous action, arising out of or in connection
;;; with the use or performance of this software.
;;;
;;; ********
;;;
;;;
;;; Y-OR-N-P prints the message, if any, and reads characters from
;;; *QUERY-IO* until any of "y", "Y", or <newline> are seen as an
;;; affirmative, or either "n" or "N" is seen as a negative answer.
;;; It ignores preceding whitespace and asks again if other characters
;;; are seen.
;;; YES-OR-NO-P is similar, except that it clears the input buffer,
;;; beeps, and uses READ-LINE to get "YES" or "NO".
(export '(y-or-n-p yes-or-no-p))
(defun query-readline ()
(string-trim " " (read-line *query-io*)))
(defun y-or-n-p (&optional format-string &rest arguments)
(when format-string
(fresh-line *query-io*)
(apply #'format *query-io* format-string arguments))
(do ((ans (query-readline) (query-readline)))
(())
(case (unless (zerop (length ans)) (char ans 0))
((#\y #\Y) (return t))
((#\n #\N) (return nil))
(t
(write-line "Type \"y\" for yes or \"n\" for no. " *query-io*)
(when format-string
(apply #'format *query-io* format-string arguments))))))
(defun yes-or-no-p (&optional format-string &rest arguments)
(clear-input *query-io*)
(beep)
(when format-string
(fresh-line *query-io*)
(apply #'format *query-io* format-string arguments))
(do ((ans (query-readline) (query-readline)))
(())
(cond ((string-equal ans "YES") (return t))
((string-equal ans "NO") (return nil))
(t
(write-line "Type \"yes\" for yes or \"no\" for no. " *query-io*)
(when format-string
(apply #'format *query-io* format-string arguments))))))
| false |
c78ab9d24a36ed3e19ef67c21e718c128485cd7d | 657a95c82617af612da2a5fa410ac44a67a39feb | /sicp/01/1.40.ss | f64e819eeaad8a8ee0e9a902d094e0a9b7b9fb02 | []
| no_license | wangjiezhe/sicp | ed16395576ac163f000b6dc59ef4928bfab3013f | 635dad3bc6dacd07665c17eba2bbe4fcdbbb530f | refs/heads/master | 2020-04-06T07:02:32.281885 | 2016-08-20T08:10:24 | 2016-08-20T08:10:24 | 57,348,685 | 0 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 228 | ss | 1.40.ss | (load "../helper.ss")
(load "1.3.3.ss")
(load "1.3.4.ss")
(define (cubic a b c)
(lambda (x)
(+ (cube x)
(* a (square x))
(* b x )
c)))
(define (cubic-root a b c)
(newton-method (cubic a b c) 1.0))
| false |
42563eed8222bc4648b2b20b926eb8736720b9b3 | eb32c279a34737c769d4e2c498a62c761750aeb5 | /lyonesse/foreign-data.scm | c4cafd26a0d408ddbb889b94daa43dd07148a90a | [
"Apache-2.0"
]
| permissive | theschemer/lyonesse | baaf340be710f68b84c1969befc6ddbd2be3739b | 9d9624e3141ea3acaa670526cbe52c2d6546beef | refs/heads/master | 2021-06-10T02:58:28.040995 | 2016-11-29T21:28:11 | 2016-11-29T21:28:11 | null | 0 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 1,102 | scm | foreign-data.scm | (library (lyonesse foreign-data)
(export deref string->char* get-value-by-ref)
(import (rnrs base (6))
(rnrs bytevectors (6))
(lyonesse malloc)
(lyonesse functional)
(only (chezscheme) foreign-ref foreign-set! foreign-sizeof unbox
foreign-free foreign-alloc))
(define (new type)
(malloc (foreign-sizeof type)))
(define (deref type obj)
(let ([data (new type)])
(foreign-set! type (unbox data) 0 (unbox obj))
data))
(define (string->char* s)
(let* ([bv (string->utf8 s)]
[n (bytevector-length bv)]
[fm (malloc (+ n 1))])
(for-each (lambda (i)
(foreign-set! 'unsigned-8 (unbox fm) i
(bytevector-u8-ref bv i)))
(iota (bytevector-length bv)))
(foreign-set! 'unsigned-8 (unbox fm) n 0)
fm))
(define (get-value-by-ref type proc)
(let ([x (foreign-alloc (foreign-sizeof type))])
(proc x)
(let ([value (foreign-ref type x 0)])
(foreign-free x)
value)))
)
| false |
66aad67e720711cf0bd1d394e4a9b62a25b63ec1 | a2d8b4843847507b02085bb8adabd818f57dd09f | /scheme/sicp/ch_2/tst-mobile.scm | ef5fc85dd6f2c7f83b8687d58afaa2ca5f8cde36 | []
| 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 | 2,396 | scm | tst-mobile.scm | ;;;; tests for mobile.scm
(load "../test-framework.scm")
(load "mobile.scm")
;;; test constructors
(define b1 (make-branch 1 2))
(define b2 (make-branch 4 8))
(define b3 (make-branch 16 32))
(define sub (make-mobile b2 b3))
(define root (make-mobile b1 (make-branch 2 sub)))
;;; test Selectors
(test-eq "left-branch" (left-branch sub) b2)
(test-eq "right-branch" (right-branch sub) b3)
(test-eq "branch-payload" (branch-payload (left-branch sub)) 8)
(test-eq "branch-payload" (branch-payload (right-branch sub)) 32)
(test-eq "branch-length" (branch-length b1) 1)
(test-eq "branch-length" (branch-length b2) 4)
(test-eq "branch-length" (branch-length (right-branch root)) 2)
;;; test Equality
(test-eq "branch-eq?" (branch-eq? b1 b1) #t)
(test-eq "branch-eq?" (branch-eq? b1 b2) #f)
(test-eq "mobile-eq?" (mobile-eq? sub sub) #t)
(test-eq "mobile-eq?" (mobile-eq? sub root) #f)
(test-eq "mobile-eq?" (mobile-eq? root root) #t)
;;; test weight related procedures
(test-eq "weight?" (weight? (branch-payload b1)) #t)
(test-eq "weight?" (weight? (branch-payload b2)) #t)
(test-eq "holds-weight?" (holds-weight? (left-branch sub)) #t)
(test-eq "holds-weight?" (holds-weight? (right-branch sub)) #t)
(test-eq "holds-weight?" (holds-weight? (left-branch root)) #t)
(test-eq "holds-weight?" (holds-weight? (right-branch root)) #f)
(test-eq "branch-weight" (branch-weight b1) 2)
(test-eq "branch-weight" (branch-weight b2) 8)
(test-eq "branch-weight" (branch-weight b3) 32)
(test-eq "total weight" (total-weight sub) 40)
(test-eq "total weight" (total-weight root) 42)
(define (test-output)
"test print routines"
(let ((b1 (make-branch 1 2))
(b2 (make-branch 4 8))
(b3 (make-branch 16 32)))
(define sub (make-mobile b2 b3))
(define root (make-mobile b1 sub))
(d "sub: ")
(dnl sub)
(print-mobile sub)
(d "root: ")
(dnl root)
(print-mobile root)))
;(test-output)
(define b1 (make-branch 2 4)) ; torque 8
(define b2 (make-branch 1 8)) ; torque 8
(define b3 (make-branch 4 9)) ; torque 36
(define sub (make-mobile b1 b2)) ; total weight 12
(define balanced (make-mobile b3 (make-branch 3 sub)))
(define un-balanced (make-mobile b2 (make-branch 2 sub)))
(test-eq "balanced" (mobile-balanced? balanced) #t)
(test-eq "un-balanced" (mobile-balanced? un-balanced) #f)
| false |
f934c95ea06f121d74485bd1fa6ede15e74d4ecd | 9c1c7a727e2218e0e5ccf88f379edeb82fa71ec0 | /kawa/lib/rnrs/programs.scm | bfa59458db2a9d82b1351fe992f0bb49c5929ebf | [
"MIT"
]
| permissive | uaiim/ai2-kawa | c73def804c74639477e4284e3ffa0090e5289732 | f009546d8a693b16ed2c5f5eece0377cc617285e | refs/heads/master | 2023-03-22T13:31:33.710666 | 2018-03-09T02:38:15 | 2018-03-09T02:38:15 | null | 0 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 507 | scm | programs.scm | (module-name <kawa.lib.rnrs.programs>)
(module-export command-line exit)
(require <kawa.lib.prim_syntax>)
(define (command-line) :: list
(let ((arg0 "kawa")) ;; FIXME
(cons arg0 (gnu.lists.LList:makeList gnu.expr.ApplicationMainSupport:commandLineArgArray 0))))
(define (exit #!optional (code 0)) :: #!void
(invoke-static <output-port> 'runCleanups)
(let ((status :: int
(cond ((integer? code) code)
(code 0)
(else -1))))
(invoke-static <java.lang.System> 'exit status)))
| false |
7c6248937c01fa3000e48f16f0354a84dfb20d09 | 657a95c82617af612da2a5fa410ac44a67a39feb | /tyscheme/helper.ss | 9704e98af82d9ce872120914170b7e6779a8bf88 | []
| no_license | wangjiezhe/sicp | ed16395576ac163f000b6dc59ef4928bfab3013f | 635dad3bc6dacd07665c17eba2bbe4fcdbbb530f | refs/heads/master | 2020-04-06T07:02:32.281885 | 2016-08-20T08:10:24 | 2016-08-20T08:10:24 | 57,348,685 | 0 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 113 | ss | helper.ss | (define (print . vs)
(for-each (lambda (x)
(display x)
(newline))
vs))
| false |
7aac2254ee26732e7720f7b8fae658810ff5792b | b9eb119317d72a6742dce6db5be8c1f78c7275ad | /random-scheme-stuff/life.scm | d0f2c277b392e9c1221f02f381d9ff48bd8344d4 | []
| no_license | offby1/doodles | be811b1004b262f69365d645a9ae837d87d7f707 | 316c4a0dedb8e4fde2da351a8de98a5725367901 | refs/heads/master | 2023-02-21T05:07:52.295903 | 2022-05-15T18:08:58 | 2022-05-15T18:08:58 | 512,608 | 2 | 1 | null | 2023-02-14T22:19:40 | 2010-02-11T04:24:52 | Scheme | UTF-8 | Scheme | false | false | 6,315 | scm | life.scm | (require 'array)
(require 'common-list-functions)
(define (nrows a) (car (array-dimensions a)))
(define (ncols a) (cadr (array-dimensions a)))
(define get-row car)
(define get-column cdr)
(define (make-point row col)
(if (or
(not (integer? row))
(not (integer? col)))
(error "make-point needs two integers")
(cons row col)))
(define (array-for-each proc a)
(let loop ((rows-to-do (nrows a)))
(if (> rows-to-do 0)
(begin
(let loop ((cols-to-do (ncols a)))
(if (> cols-to-do 0)
(begin
(proc
a
(array-ref a (- rows-to-do 1) (- cols-to-do 1))
(- rows-to-do 1)
(- cols-to-do 1))
(loop (- cols-to-do 1)))))
(loop (- rows-to-do 1))))))
(define (array->string a)
(let ((string ""))
(array-for-each
(let ((invocations 0))
(lambda (array cell row column)
(set! string (string-append string (if (eq? (car cell) 'empty)
" "
".")))
(set! invocations (+ 1 invocations))
(if (= 0 (remainder invocations (ncols array)))
(set! string (string-append string "|\n")))))
a)
string))
;; Each entry is a pair, the car of which is the cell's present state,
;; and the cdr of which is the cell's future state.
(define the-universe
;; We initialize each entry to #f, then go back and set each entry
;; to be a pair.
(let ((temp (make-array #f 20 16)))
;; Replace each entry with a new pair.
(array-for-each
(lambda (array cell row column)
(array-2d-set! array (cons 'empty 'unknown)
row column))
temp)
;; Create an interesting initial pattern.
(let ()
(define (fill-cells offset-point coordinate-list)
(for-each
(lambda (pair)
(array-set! temp (list 'full)
(+ (get-row offset-point) (get-row pair))
(+ (get-column offset-point) (get-column pair))))
coordinate-list))
(define (normalize points)
(define (center points)
(define (average p1 p2)
(define (arith-average x y)
(quotient (+ x y)
2))
(make-point
(arith-average (get-row p1)
(get-row p2))
(arith-average (get-column p1)
(get-column p2))))
(define (point-reduce fn lst)
(make-point
(reduce fn (map get-row points))
(reduce fn (map get-column points))))
(if (null? points)
'()
(average (point-reduce min points) (point-reduce max points) )))
(define (point-subtract a b)
(make-point (- (get-row a) (get-row b))
(- (get-column a) (get-column b))))
(map (let ((c (center points)))
(lambda (p)
(point-subtract p c)))
points))
(define glider (list '(0 . 0)
'(1 . 0)
'(2 . 0)
'(2 . 1)
'(1 . 2)))
(define r-pentomino (list '(0 . 0)
'(1 . 0)
'(2 . 0)
'(1 . -1)
'(2 . 1)))
(define beehive (list '(0 . 0)
'(1 . 1)
'(1 . 2)
'(0 . 3)
'(-1 . 2)
'(-1 . 1)))
(define long-line (map (lambda (n)
(cons n 0))
(list 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19)))
(fill-cells (make-point 0 0)
long-line)
(fill-cells (make-point (quotient (nrows temp) 2) (quotient (ncols temp) 2)) (normalize glider))
)
temp))
(begin
(newline)
(display (array->string the-universe)))
;; Advance the universe by one generation.
(define (x)
(define (new-generation)
(define (coordinates-of-neighbors row column)
(define (add-pairs p1 p2)
(make-point (+ (get-row p1)
(get-row p2))
(+ (get-column p1)
(get-column p2))))
(map
(let ((my-coords (make-point row column)))
(lambda (offset-pair)
(add-pairs offset-pair my-coords)))
'((-1 . -1)
(-1 . 0)
(-1 . 1)
( 0 . -1)
( 0 . 1)
( 1 . -1)
( 1 . 0)
( 1 . 1))))
(define (safe-array-2d-ref a row col)
(array-ref a
(modulo row (nrows a))
(modulo col (ncols a))))
(begin
(array-for-each
(lambda (array cell-value row column)
(set-cdr! cell-value 'empty)
;; count the number of non-empty neighbors.
(case (apply +
(map
(lambda (cell-value)
(if (eq? (car cell-value)
'full)
1
0))
(map (lambda (pair)
(safe-array-2d-ref
array
(get-row pair)
(get-column pair)))
(coordinates-of-neighbors row column))))
;; if it's 3, set future state to full.
((3) (set-cdr! cell-value 'full))
;; if it's 2, and current state is full, set future state to full.
((2) (if (eq? (car cell-value) 'full)
(set-cdr! cell-value 'full)))))
the-universe)
(array-for-each
(lambda (array cell-value row column)
;; set the current state to the future state
(set-car! cell-value (cdr cell-value))
;; set the future state to unknown
(set-cdr! cell-value 'unknown))
the-universe)))
(new-generation)
(newline)
(display (array->string the-universe)))
| false |
6c6adb473ad115fd3a1ccc9c1481b905f9d2ccad | 6eaa87ed57fab28bb4b3b95a1aa721978947f3ec | /spec/lib/logic-spec.scm | 0f5405c687b11badd283e0110c14ab8bb7b8c6c2 | [
"MIT"
]
| permissive | seven1m/scheme-vm | d8b28d79faf400e260c445c2e72aaf2a78182c92 | 00cdee125690429c16b1e5b71b180a6899ac6a58 | refs/heads/master | 2021-01-21T16:53:03.742073 | 2018-04-17T01:06:45 | 2018-04-17T01:06:45 | 27,324,674 | 9 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 300 | scm | logic-spec.scm | (import (scheme base)
(assert))
(assert (eq? #t (and)))
(assert (eq? #t (and #t)))
(assert (eq? 1 (and 1)))
(assert (eq? 2 (and 1 2)))
(assert (eq? #f (and #f 2)))
(assert (eq? #f (or)))
(assert (eq? #t (or #t)))
(assert (eq? 1 (or 1)))
(assert (eq? 1 (or 1 2)))
(assert (eq? 2 (or #f 2)))
| false |
739101957529d8e38258a68840b15f1b70c4dd10 | eaa28dbef6926d67307a4dc8bae385f78acf70f9 | /lib/pikkukivi/command/verkko/konachan.sld | ee8293fa7326054333610789e314e9bed9f87746 | [
"Unlicense"
]
| permissive | mytoh/pikkukivi | d792a3c20db4738d99d5cee0530401a144027f1f | d3d77df71f4267b9629c3fc21a49be77940bf8ad | refs/heads/master | 2016-09-01T18:42:53.979557 | 2015-09-04T08:32:08 | 2015-09-04T08:32:08 | 5,688,224 | 0 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 2,173 | sld | konachan.sld |
(define-library (pikkukivi command verkko konachan)
(export
konachan
)
(import
(scheme base)
(gauche base)
(text html-lite)
(sxml ssax)
(sxml sxpath)
(gauche parseopt)
(gauche collection)
(srfi 1)
(rfc http)
(kirjasto komento työkalu)
(clojure))
(begin
(define (get-image-url html)
(let ((parse (lambda (s)
(rxmatch #/http\:\/\/konachan\.com\/\(image|jpeg\)\/[^"]+/ s))))
(list (rxmatch-substring (parse html))
(rxmatch-after (parse html)))))
(define (get-image-urls html)
(let loop ((url (car (get-image-url html)))
(match-after (cadr (get-image-url html))))
(if (not url)
'()
(cons url (loop (car (get-image-url match-after))
(cadr (get-image-url match-after)))))))
(define (get-images page-number tag)
(for-each
swget
(delete-duplicates
(get-image-urls (last (find-all-tags "ul" (get-tags-page (+ page-number 1) tag)))))))
(define (parse-last-page-number s)
(if-let1 pagination (rxmatch->string #/<div class\=\"pagination\">.*?<\/div>/
s)
(let ((page (call-with-input-string pagination (lambda (in)
(ssax:xml->sxml in ())))))
(caddr (find-max
((node-closure (ntype-names?? '(a))) page)
:key (lambda (e) (x->number (caddr e))))))
1))
(define (get-tags-page page-number tag)
(receive (status head body)
(http-get "konachan.com" (str "/post?page=" (number->string page-number) "&tags=" tag))
body))
(define (get-tags-pages tag)
(let ((last (x->number (parse-last-page-number (get-tags-page 1 tag)))))
(dotimes (num last)
(print (str (colour-string 99 "getting page ") (colour-string 33 (number->string (+ num 1)))))
(get-images num tag))))
(define (konachan args)
(let-args args
((tag "t|tag=s")
. rest)
(mkdir tag)
(cd tag)
(get-tags-pages tag)
(cd "..")))
))
| false |
aa9a66736fe98719337e954eb8085ae87ba3dd1f | 6c69f4c35bcecb0ab4642d75e01183d2ee4de8b9 | /src/main/common.scm | 8fd8a7dd87d4b921f1bc93b1dbb5db0555dd6c92 | [
"MIT"
]
| permissive | Lattay/chicken-meta-rpc | 2c488928e7f288eef9bb30acc303b379e4ad24b8 | a633b9870af384bc7926334156632a26159af624 | refs/heads/master | 2020-07-12T21:56:48.065087 | 2019-11-26T21:18:50 | 2019-11-26T21:18:50 | 204,916,209 | 0 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 548 | scm | common.scm | (import scheme
chicken.base
chicken.condition)
(import srfi-18)
(define log-port (make-parameter (current-error-port)))
(define (logger context . args)
(display (string-append "[" context "] ") (log-port))
(let loop ((rest args))
(if (null? rest)
(newline (log-port))
(begin
(display (car rest) (log-port))
(display " " (log-port))
(loop (cdr rest))))))
(define get-exn-msg (condition-property-accessor 'exn 'message))
(define (time-stamp)
(time->seconds (current-time)))
| false |
0192cd4d468d64847d7242c460d92b8a3cb1db91 | 665da87f9fefd8678b0635e31df3f3ff28a1d48c | /tests/debug/kons.scm | 7cfc462a95d3ac27eaab32578613207bd9dbc92e | [
"MIT"
]
| permissive | justinethier/cyclone | eeb782c20a38f916138ac9a988dc53817eb56e79 | cc24c6be6d2b7cc16d5e0ee91f0823d7a90a3273 | refs/heads/master | 2023-08-30T15:30:09.209833 | 2023-08-22T02:11:59 | 2023-08-22T02:11:59 | 31,150,535 | 862 | 64 | MIT | 2023-03-04T15:15:37 | 2015-02-22T03:08:21 | Scheme | UTF-8 | Scheme | false | false | 1,565 | scm | kons.scm | ;; A temporary test file
(import (scheme base)
(scheme write)
;(srfi 9)
)
;; TODO: seems begins are not spliced when part of an applied lambda??
;;((lambda ()
(define-record-type <pare>
(kons x y)
pare?
(x kar set-kar!)
(y kdr))
(write
(list
(pare? (kons 1 2)) ; =. #t
(pare? (cons 1 2)) ; =. #f
(kar (kons 1 2)) ; =. 1
(kdr (kons 1 2)) ; =. 2
(let ((k (kons 1 2)))
(set-kar! k 3)
(kar k)) ;=. 3
(record? (kons 1 2))
(record? (cons 1 2))
))
;(define <pare> (register-simple-type <pare> #f (quote (x y))))
;(define pare? (make-type-predicate pare? <pare>))
;(define kons
; ((lambda (%make)
; (lambda (x y)
; ((lambda (res)
; (slot-set! <pare> res (type-slot-offset <pare> (quote y)) y)
; (slot-set! <pare> res (type-slot-offset <pare> (quote x)) x)
; res)
; (%make))))
; (make-constructor "kons" <pare>)))
;(write
; (list
; (kons 1 2)
; (pare? (kons 1 2))
; (pare? (cons 1 4))
;))
;;))
;(((lambda ()
;(define <pare> (register-simple-type <pare> #f (quote (x y))))
;(define pare? (make-type-predicate pare? <pare>))
;(define kons ((lambda (%make) (lambda (x y) ((lambda (res) (slot-set! <pare> res (type-slot-offset <pare> (quote y)) y) (slot-set! <pare> res (type-slot-offset <pare> (quote x)) x) res) (%make)))) (make-constructor "kons" <pare>))) (write (list (pare? (kons 1 2)) (pare? (cons 1 2)))))))
;(define (make-lambda)
; (lambda (a b c) (write (+ a b c))))
;(define test (make-lambda))
;(test 1 2 3)
| false |
75d5c97ec7a862015bae306219e54296fa9dcfe9 | 575540faca84ddab9d113bd3b1edc01f901faca0 | /mllang/mlscheme/compile.scm | 3e7c45f4db561c684b1a6ecc69c86666d22f127f | []
| no_license | juleari/mlscheme | c8327b2b3ad2151bb231baa529a25a711341968b | 5f0cf5bded95fd63ca38c6a3446ec82b429d5c2b | refs/heads/master | 2020-04-12T06:18:39.190401 | 2020-01-11T16:44:05 | 2020-01-11T16:44:05 | 44,351,323 | 2 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 596 | scm | compile.scm | ;(import "defs.scm")
;(import "lib.scm")
;(import "lexer.scm")
;(import "syntax.scm")
;(import "semantic.scm")
;(import "generate.scm")
(define (prepare-gen-file)
(let ((lib-funcs-file (open-input-file ###PATH-TO-GENBASE-FILE###)))
(while (not (eof-object? (peek-char lib-funcs-file)))
(display (read-char lib-funcs-file) gen-file))))
(define gen-file (open-output-file ###PATH-TO-GEN-FILE###))
(prepare-gen-file)
(define port (open-input-file ###PATH-TO-INPUT-FILE###))
(define tokens (tokenize-file port))
(define ast (syntax))
(define model (semantic ast))
(generate model)
| false |
d72764df00c6eaa0fabb3413fdcafdc75534ab71 | 0885e4bb297f70bef71f6793cfafcb2db5155058 | /linear-temporal-operators.scm | 013515b388571c98c5a2eb3318916cf1cdebac10 | []
| no_license | nathanielrb/time-in-microKanren | e1ee454fcac9598a761d9f152c8799e52b00f92d | 8ca0a48afdaa17fbe5b707f57a84b7089bc5dc90 | refs/heads/master | 2020-03-20T07:23:35.271350 | 2018-09-10T05:25:21 | 2018-09-10T05:25:21 | 137,279,741 | 3 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 1,361 | scm | linear-temporal-operators.scm | (use srfi-1)
(define (assp pred alist)
(find (lambda (pair) (pred (car pair))) alist))
(load "temporal-microKanren.scm")
(load "miniKanren-wrappers.scm")
(define (precedes* g* h*)
(let ((g (g*)) (h (h*)))
(disj h
(conj g
(next (precedes* g* h*))))))
(define-syntax precedes
(syntax-rules ()
((_ g h) (precedes* (lambda () g) (lambda () h)))))
(define (always* g*)
(let ((g (g*)))
(conj g (next (always* g*)))))
(define-syntax always
(syntax-rules ()
((_ g) (always* (lambda () g)))))
(define (as-long-as* g* h*)
(let ((g (g*)) (h (h*)))
(lambda (s/c)
(let (($ (g s/c)))
(if (null? $) mzero
(bind $ (disj h (next (as-long-as* g* h*)))))))))
(define-syntax as-long-as
(syntax-rules ()
((_ g h) (as-long-as* (lambda () g) (lambda () h)))))
;; Naive definition
;;
;; (define (eventually* g*)
;; (let ((g (g*)))
;; (disj g (next (eventually* g*)))))
;; (define-syntax eventually
;; (syntax-rules ()
;; ((_ g) (eventually* (lambda () g)))))
(define (eventually* g*)
(let ((g (g*)))
(lambda (s/c)
(let (($ (g s/c)))
(if (null? $)
(bind (list s/c) (next (eventually* g*)))
$)))))
(define-syntax eventually
(syntax-rules ()
((_ g) (eventually* (lambda () g)))))
(define-syntax until
(syntax-rules ()
((_ g h) (conj (precedes g h) (eventually h)))))
| true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.