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 |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
03af84ccc069d6dcfb6fc165ef7dddb49abc127a | 648776d3a0d9a8ca036acaf6f2f7a60dcdb45877 | /queries/mermaid/highlights.scm | 2f3e31b900c0a9bf252cd924e991b593ba8112df | [
"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 | 3,260 | scm | highlights.scm | ; adapted from https://github.com/monaqa/tree-sitter-mermaid
[
"sequenceDiagram"
"classDiagram"
"classDiagram-v2"
"stateDiagram"
"stateDiagram-v2"
"gantt"
"pie"
"flowchart"
"erdiagram"
"participant"
"as"
"activate"
"deactivate"
"note "
"over"
"link"
"links"
; "left of"
; "right of"
"properties"
"details"
"title"
"loop"
"rect"
"opt"
"alt"
"else"
"par"
"and"
"end"
(sequence_stmt_autonumber)
(note_placement_left)
(note_placement_right)
"class"
"state "
"dateformat"
"inclusiveenddates"
"topaxis"
"axisformat"
"includes"
"excludes"
"todaymarker"
"title"
"section"
"direction"
"subgraph"
] @keyword
(comment) @comment @spell
[
":"
(sequence_signal_plus_sign)
(sequence_signal_minus_sign)
(class_visibility_public)
(class_visibility_private)
(class_visibility_protected)
(class_visibility_internal)
(state_division)
] @punctuation.delimiter
[
"("
")"
"{"
"}"
] @punctuation.bracket
[
"-->"
(solid_arrow)
(dotted_arrow)
(solid_open_arrow)
(dotted_open_arrow)
(solid_cross)
(dotted_cross)
(solid_point)
(dotted_point)
] @operator
[
(class_reltype_aggregation)
(class_reltype_extension)
(class_reltype_composition)
(class_reltype_dependency)
(class_linetype_solid)
(class_linetype_dotted)
"&"
] @operator
(sequence_actor) @field
(class_name) @field
(state_name) @field
(gantt_task_text) @field
[
(class_annotation_line)
(class_stmt_annotation)
(class_generics)
(state_annotation_fork)
(state_annotation_join)
(state_annotation_choice)
] @attribute
(directive) @include
(pie_label) @string
(pie_value) @float
[
(flowchart_direction_lr)
(flowchart_direction_rl)
(flowchart_direction_tb)
(flowchart_direction_bt)
] @constant
(flow_vertex_id) @field
[
(flow_link_arrow)
(flow_link_arrow_start)
] @operator
(flow_link_arrowtext "|" @punctuation.bracket)
(flow_vertex_square [ "[" "]" ] @punctuation.bracket )
(flow_vertex_circle ["((" "))"] @punctuation.bracket )
(flow_vertex_ellipse ["(-" "-)"] @punctuation.bracket )
(flow_vertex_stadium ["([" "])"] @punctuation.bracket )
(flow_vertex_subroutine ["[[" "]]"] @punctuation.bracket )
(flow_vertex_rect ["[|" "|]"] @punctuation.bracket )
(flow_vertex_cylinder ["[(" ")]"] @punctuation.bracket )
(flow_vertex_round ["(" ")"] @punctuation.bracket )
(flow_vertex_diamond ["{" "}"] @punctuation.bracket )
(flow_vertex_hexagon ["{{" "}}"] @punctuation.bracket )
(flow_vertex_odd [">" "]"] @punctuation.bracket )
(flow_vertex_trapezoid ["[/" "\\]"] @punctuation.bracket )
(flow_vertex_inv_trapezoid ["[\\" "/]"] @punctuation.bracket )
(flow_vertex_leanright ["[/" "/]"] @punctuation.bracket )
(flow_vertex_leanleft ["[\\" "\\]"] @punctuation.bracket )
(flow_stmt_subgraph ["[" "]"] @punctuation.bracket )
[
(er_cardinarity_zero_or_one)
(er_cardinarity_zero_or_more)
(er_cardinarity_one_or_more)
(er_cardinarity_only_one)
(er_reltype_non_identifying)
(er_reltype_identifying)
] @operator
(er_entity_name) @field
(er_attribute_type) @type
(er_attribute_name) @field
[
(er_attribute_key_type_pk)
(er_attribute_key_type_fk)
] @type.qualifier
(er_attribute_comment) @string @spell
| false |
e04abd30be97bc2004200fe828362f5070a9c977 | ac2a3544b88444eabf12b68a9bce08941cd62581 | /tests/unit-tests/00-check/check_equalp.scm | 1a2deebcd92d5206b42f27788fa088ab6dbef842 | [
"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 | 252 | scm | check_equalp.scm | (include "#.scm")
(check-equal? 42 42)
(check-equal? #t #t)
(check-equal? #f #f)
(check-equal? #\x #\x)
(check-equal? "abc" "abc")
(check-equal? 'hello 'hello)
(check-equal? '() '())
(check-equal? '(1 2 3) '(1 2 3))
(check-equal? '#(1 2 3) '#(1 2 3))
| false |
3c5dc0f52e91661787d2d012b02a93d557a65bb7 | 404799b4b2d5f83ee5304392826a69defc25da77 | /ex2-52.scm | edaebe9e0766dc1fce9ad459369613b43fa6498c | []
| 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 | 290 | scm | ex2-52.scm | ;;; Exercise 2.52
(define (square-limit-2 painter n)
(let ((combine4
(square-of-four identity
flip-horiz
flip-vert
rotate180)))
(combine4 (corner-split painter n))))
| false |
7f0efdc8873463ba5d49185b9ca2c3a8c3c0a8ca | d8fd100f7fedcf165381c5bfeac3b8b04baf5980 | /src/units/activities/splash.scm | e8d3b00c1b85f485de507393d7ffcaea073c2356 | []
| no_license | shelt/flib | 9c7b8228692ac6973c593a4bcd2d89ad96c1879c | 5e2212d0c907297c0859758bc97a0a50f320172e | refs/heads/master | 2021-01-10T04:18:23.371234 | 2016-01-23T05:24:45 | 2016-01-23T05:24:45 | 50,224,827 | 0 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 542 | scm | splash.scm | (declare (unit activities/splash))
(use (prefix sdl2 sdl2:)
(prefix sdl2-image img:)
miscmacros)
(require-extension posix)
(define (splash-activity window)
(let* ((window-surface (sdl2:window-surface window))
(x (util:surface-cx window-surface))
(y (util:surface-cy window-surface))
(splash (make-ui-img x y #f (img:load "assets/splash/ghost.png"))))
(util:clear-surface window-surface)
(splash 'draw window-surface #f)
(sdl2:update-window-surface! window)
(sleep const:splash-time)))
| false |
852ca89ca646076c2ecfc96af30925e8eceeda72 | 3508dcd12d0d69fec4d30c50334f8deb24f376eb | /v8/src/compiler/midend/indexify.scm | 2d6b87a28796fef0f2e71a38f4d2d38f05f8634f | []
| 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 | 4,172 | scm | indexify.scm | #| -*-Scheme-*-
Copyright (c) 1994-1999 Massachusetts Institute of Technology
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at
your option) any later version.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|#
;;;; Constant folder for closure and stack closure indices
;;; package: (compiler midend)
(declare (usual-integrations))
(define (indexify/top-level program)
(indexify/do-dbg-info!)
(indexify/expr program))
(define-macro (define-indexifier keyword bindings . body)
(let ((proc-name (symbol-append 'INDEXIFY/ keyword)))
(call-with-values
(lambda () (%matchup bindings '(handler) '(cdr form)))
(lambda (names code)
`(DEFINE ,proc-name
(LET ((HANDLER (LAMBDA ,names ,@body)))
(NAMED-LAMBDA (,proc-name FORM)
(INDEXIFY/REMEMBER ,code FORM))))))))
(define-indexifier LOOKUP (name)
`(LOOKUP ,name))
(define-indexifier LAMBDA (lambda-list body)
`(LAMBDA ,lambda-list
,(indexify/expr body)))
(define-indexifier LET (bindings body)
`(LET ,(map (lambda (binding)
(list (car binding)
(indexify/expr (cadr binding))))
bindings)
,(indexify/expr body)))
(define-indexifier LETREC (bindings body)
`(LETREC ,(map (lambda (binding)
(list (car binding)
(indexify/expr (cadr binding))))
bindings)
,(indexify/expr body)))
(define-indexifier IF (pred conseq alt)
`(IF ,(indexify/expr pred)
,(indexify/expr conseq)
,(indexify/expr alt)))
(define-indexifier QUOTE (object)
`(QUOTE ,object))
(define-indexifier DECLARE (#!rest anything)
`(DECLARE ,@anything))
(define-indexifier BEGIN (#!rest actions)
`(BEGIN ,@(indexify/expr* actions)))
(define-indexifier CALL (rator cont #!rest rands)
(cond ((or (not (QUOTE/? rator))
(not (eq? (QUOTE/text rator) %vector-index)))
`(CALL ,(indexify/expr rator)
,(indexify/expr cont)
,@(indexify/expr* rands)))
((or (not (equal? cont '(QUOTE #F)))
(not (= (length rands) 2))
(not (QUOTE/? (first rands)))
(not (QUOTE/? (second rands))))
(internal-error "Unexpected use of %vector-index"
`(CALL ,rator ,cont ,@rands)))
(else
`(QUOTE ,(vector-index (QUOTE/text (first rands))
(QUOTE/text (second rands)))))))
(define (indexify/expr expr)
(if (not (pair? expr))
(illegal expr))
(case (car expr)
((QUOTE) (indexify/quote expr))
((LOOKUP) (indexify/lookup expr))
((LAMBDA) (indexify/lambda expr))
((LET) (indexify/let expr))
((DECLARE) (indexify/declare expr))
((CALL) (indexify/call expr))
((BEGIN) (indexify/begin expr))
((IF) (indexify/if expr))
((LETREC) (indexify/letrec expr))
(else (illegal expr))))
(define (indexify/expr* exprs)
(map (lambda (expr)
(indexify/expr expr))
exprs))
(define (indexify/remember new old)
(code-rewrite/remember new old))
(define (indexify/do-dbg-info!)
(define (rewrite-indexifies! expr)
(cond ((dbg/stack-closure-ref? expr)
(rewrite-indexifies! (vector-ref expr 1)))
((dbg/heap-closure-ref? expr)
(rewrite-indexifies! (vector-ref expr 1)))
((QUOTE/? expr))
((LOOKUP/? expr))
((and (CALL/? expr)
(QUOTE/? (call/operator expr))
(eq? %vector-index (quote/text (call/operator expr)))
(for-all? (call/cont-and-operands expr) QUOTE/?))
(internal-error "%vector-index found in DBG info")
(let ((rands (call/operands expr)))
(form/rewrite! expr
`(QUOTE ,(vector-index (QUOTE/text (first rands))
(QUOTE/text (second rands)))))))
((pair? expr)
(map rewrite-indexifies! expr))))
(dbg-info/for-all-dbg-expressions! rewrite-indexifies!))
| false |
96ed6d48a28614a8c5d06e58ca8b48f6bdde1ab5 | 46244bb6af145cb393846505f37bf576a8396aa0 | /eopl/ch1/exercise-1.27.scm | e2fde22db643e834d769b220a886752c42bb310c | []
| no_license | aoeuidht/homework | c4fabfb5f45dbef0874e9732c7d026a7f00e13dc | 49fb2a2f8a78227589da3e5ec82ea7844b36e0e7 | refs/heads/master | 2022-10-28T06:42:04.343618 | 2022-10-15T15:52:06 | 2022-10-15T15:52:06 | 18,726,877 | 4 | 3 | null | null | null | null | UTF-8 | Scheme | false | false | 536 | scm | exercise-1.27.scm | #lang racket
#|
(flatten slist) returns a list of the symbols contained in slist in the order
in which they occur when slist is printed. Intuitively,
flatten removes all the inner parentheses from its argument.
|#
; flatten: List --> List
(define (flatten slist)
(if (symbol? slist)
(list slist)
(if (null? slist)
'()
(append-map flatten slist))))
(display (flatten '(a b c)))
(newline)
(display (flatten '((a) () (b ()) () (c))))
(newline)
(display (flatten '((a b) c (((d)) e))))
(newline) | false |
47f4db943ad2723e5bf4bceb075554f42a6a19c4 | 8a0660bd8d588f94aa429050bb8d32c9cd4290d5 | /test/tests/util/file.scm | 1490d900fea3708719a83fbec259b6d420ee8307 | [
"BSD-2-Clause"
]
| permissive | david135/sagittarius-scheme | dbec76f6b227f79713169985fc16ce763c889472 | 2fbd9d153c82e2aa342bfddd59ed54d43c5a7506 | refs/heads/master | 2016-09-02T02:44:31.668025 | 2013-12-21T07:24:08 | 2013-12-21T07:24:08 | 32,497,456 | 0 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 3,463 | scm | file.scm | (import (rnrs)
(util file)
(sagittarius)
(sagittarius control)
(srfi :1)
(srfi :64 testing))
(test-begin "File operations tests")
;; creates test directory
(define top-test-dir "test-util-file")
(define test-directory (build-path top-test-dir
(build-path "file" "test")))
(create-directory* test-directory)
;; creates test files
(dotimes (i 10)
(let1 path (build-path test-directory (number->string i))
(when (file-exists? path) (delete-file path))
(when (file-symbolic-link? path) (delete-file path))
(if (= i 9)
(create-symbolic-link (build-path test-directory "0")
(build-path test-directory "9"))
(call-with-output-file path
(lambda (p)
(dotimes (j (+ i 1))
(put-string p "test\n")))))))
(test-equal "file->string" "test\n"
(file->string (build-path test-directory "0")))
(test-equal "file->string-list" '("test" "test")
(file->string-list (build-path test-directory "1")))
(test-equal "file->sexp-list" '(test test)
(file->sexp-list (build-path test-directory "1")))
(test-equal "file->list" '(1 1)
(file->list (lambda (p)
(if (eof-object? (read p))
(eof-object)
1))
(build-path test-directory "1")))
;; find files
(let ((files (do ((i 0 (+ i 1))
(r '() (cons (build-path test-directory (number->string i))
r)))
((= i 10) (reverse! r)))))
(test-equal "find-files" (take files 9) (find-files test-directory))
(test-equal "find-files with physical #f"
files
(find-files test-directory :physical #f))
(test-equal "find-files reverse sort"
(reverse files)
(find-files test-directory :sort string>=? :physical #f))
(test-equal "find-files recursive #f"
'()
(find-files top-test-dir :recursive #f))
(test-equal "find-files recursive #t from top"
(take files 9)
(find-files top-test-dir)))
;; path-for-each
(test-assert "path-for-each" (path-for-each top-test-dir (lambda (p t) 'ok)))
(test-assert "path-for-each file-only (inclusing symbolic-link)"
(path-for-each top-test-dir
(lambda (p t)
(unless (or (eq? t 'file) (eq? t 'symbolic-link))
(error 'ng "non-file")))
:file-only #t
:physical #f))
(test-assert "path-for-each file-only"
(path-for-each top-test-dir
(lambda (p t)
(when (eq? t 'directory) (error 'ng "non-file")))
:file-only #t))
(test-assert "path-for-each file-only"
(path-for-each top-test-dir
(lambda (p t)
(when (eq? t 'directory) (error 'ng "non-file")))
:file-only #t))
;; path-map
(let ((files (do ((i 0 (+ i 1))
(r '() (cons (build-path test-directory (number->string i))
r)))
((= i 10) (reverse! r)))))
(test-equal "path-map"
(take files 9) ;; remove symbolic-link
(list-sort string<=? (path-map test-directory (lambda (v t) v))))
(test-equal "path-map physical"
files
(list-sort string<=? (path-map test-directory (lambda (v t) v)
:physical #f)))
)
(test-assert "delete-directory*" (delete-directory* top-test-dir))
;; build-path*
(test-equal "build-path*"
(cond-expand
(windows "a\\b\\c\\d")
(else "a/b/c/d"))
(build-path* "a" "b" "c" "d"))
;; trivials
(test-equal "build-path*(0)" "" (build-path*))
(test-equal "build-path*(1)" "a" (build-path* "a"))
(test-equal "build-path*(2)" (cond-expand (windows "a\\b") (else "a/b"))
(build-path* "a" "b"))
(test-end)
| false |
375422bba06f1f57d46cdb34356ee52919151a7b | 58381f6c0b3def1720ca7a14a7c6f0f350f89537 | /Chapter 2/2.5/Ex2.78.scm | b944ede0e9984d3c1f4f709f2faedca018549d31 | []
| no_license | yaowenqiang/SICPBook | ef559bcd07301b40d92d8ad698d60923b868f992 | c8a0228ebf66d9c1ddc5ef1fcc1d05d8684f090a | refs/heads/master | 2020-04-19T04:03:15.888492 | 2015-11-02T15:35:46 | 2015-11-02T15:35:46 | null | 0 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 724 | scm | Ex2.78.scm | #lang planet neil/sicp
(define (attach-tag type-tag contents)
(if (eq? type-tag 'scheme-number)
contents
(cons type-tag contents)))
(define (type-tag datum)
(cond ((number? datum) datum)
((pair? datum) (car datum))
(else (error "Bad tagged datum: TYPE-TAG" datum))))
(define (contents datum)
(cond ((number? datum) datum)
((pair? datum) (cdr datum))
(else (error "Bad tagged datum: CONTENTS" datum))))
;; TESTS
(attach-tag 'scheme-number 1) ; 1
(type-tag 2) ; 2 - normal scheme number
(contents 3) ; 3
(define complex-number (attach-tag 'complex '(1 2)))
; (mcons 'complex (mcons 1 (mcons 2 '())))
(type-tag complex-number) ; 'complex
(contents complex-number) ; (1 2)
| false |
dc90bedfe231dce64ba5efa92da70d92fec4934d | 2e50e13dddf57917018ab042f3410a4256b02dcf | /etc/R7RS/src/fibfp.sch | 73ec8b8a61a7b475d893f00dde6ec46e407531cd | [
"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",
"MIT",
"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 | 586 | sch | fibfp.sch | ;;; FIBFP -- Computes fib(35) using floating point
(import (rnrs base)
(rnrs io simple)
(rnrs arithmetic flonums))
(define (fibfp n)
(if (fl<? n 2.)
n
(fl+ (fibfp (fl- n 1.))
(fibfp (fl- n 2.)))))
(define (main)
(let* ((count (read))
(input (read))
(output (read))
(s2 (number->string count))
(s1 (number->string input))
(name "fibfp"))
(run-r6rs-benchmark
(string-append name ":" s1 ":" s2)
count
(lambda () (fibfp (hide count input)))
(lambda (result) (= result output)))))
| false |
a60583e4d31f3eafcd679ec4d9f3770e537b5bf6 | a74932f6308722180c9b89c35fda4139333703b8 | /edwin48/scsh/pathname-unix.scm | 295f027758dbc2a937688eb2dab1b1db782f8221 | []
| no_license | scheme/edwin48 | 16b5d865492db5e406085e8e78330dd029f1c269 | fbe3c7ca14f1418eafddebd35f78ad12e42ea851 | refs/heads/master | 2021-01-19T17:59:16.986415 | 2014-12-21T17:50:27 | 2014-12-21T17:50:27 | 1,035,285 | 39 | 10 | null | 2022-02-15T23:21:14 | 2010-10-29T16:08:55 | Scheme | UTF-8 | Scheme | false | false | 11,852 | scm | pathname-unix.scm | ;;; -*- Mode: Scheme; scheme48-package: pathname -*-
;;;; Pathnames
;;;; Unix File System Type
;;; This code is written by Taylor R. Campbell and placed in the Public
;;; Domain. All warranties are disclaimed.
(define :unix (singleton 'UNIX))
(define-method &origin->namestring ((fs-type :unix) origin)
(cond ((not origin) ".")
((eq? origin 'ROOT) "")
((string? origin) (string-append "$" origin))
((eq? origin 'HOME) "~")
((unix-home-origin origin)
=> (lambda (username)
(string-append "~" (unix-path-component username))))
((eq? origin 'BACK) "..")
((let loop ((origin origin))
(if (pair? origin)
(and (eq? (car origin) 'BACK)
(loop (cdr origin)))
(null? origin)))
(decorated-string-append #f "" "/" ""
(map (lambda (x) x "..") origin)))
(else
(error "unrecognized Unix pathname origin" origin))))
(define (unix-home-origin origin)
(and (pair? origin)
(eq? (car origin) 'HOME)
(pair? (cdr origin))
(or (string? (cadr origin))
(symbol? (cadr origin)))
(null? (cddr origin))
(cadr origin)))
(define-method &directory->namestring ((fs-type :unix) directory)
(decorated-string-append "/" "/" "/" "/"
(map unix-filename->namestring directory)))
(define-method &filename->namestring ((fs-type :unix) filename)
(unix-filename->namestring filename))
(define (unix-filename->namestring filename)
(string-append
(unix-path-component (filename-base filename))
(cond ((filename-types filename)
=> (lambda (types)
(decorated-string-append "" "." "." ""
(map unix-path-component types))))
(else ""))
(let ((version (filename-version filename)))
(case version
((OLDEST) (error "Unix has no representation for oldest version"))
((NEWEST #F) "")
(else (string-append ".~" (number->string version 10) "~"))))))
(define (unix-path-component component)
(let ((component (if (symbol? component)
(string-downcase (symbol->string component))
component)))
(if (let ((length (string-length component)))
(or (string-index #\/ component 0 length)
(string-index (ascii->char 0) component 0 length)))
(error "illegal Unix path component" component)
component)))
;;;; Unix Namestring Parser
;++ This is really grody.
(define-method &parse-namestring ((fs-type :unix) namestring)
(or (maybe-parse-unix-namestring namestring)
(error "malformed Unix namestring" namestring)))
(define (ununix-path-component string start end)
(let ((component (substring string start end)))
(let loop ((i 0))
(cond ((= i (string-length component))
(string->symbol component))
((or (not (char-alphabetic? (string-ref component i)))
(char-lower-case? (string-ref component i)))
(loop (+ i 1)))
(else
component)))))
(define (maybe-parse-unix-namestring namestring)
(let ((length (string-length namestring)))
(cond ((= length 0) (make-pathname #f '() #f))
((= length 1)
(case (string-ref namestring 0)
((#\~) (make-pathname 'HOME '() #f))
((#\/) (make-pathname 'ROOT '() #f))
((#\$) #f) ;No name for the environment variable
((#\.) (make-pathname #f '() #f))
(else (make-pathname #f '() namestring))))
(else (parse-unix-namestring/origin namestring)))))
(define (parse-unix-namestring/origin namestring)
(case (string-ref namestring 0)
((#\~) (parse-unix-namestring/home namestring))
((#\/) (parse-unix-namestring/directory namestring 0 'ROOT))
((#\$) (parse-unix-namestring/env namestring))
((#\.) (parse-unix-namestring/dot namestring))
(else (parse-unix-namestring/directory namestring
-1 ;No leading slash
#f))))
(define (parse-unix-namestring/home namestring)
(let ((length (string-length namestring)))
(cond ((string-index #\/ namestring 0 length)
=> (lambda (index)
(parse-unix-namestring/directory
namestring
index
(if (= index 1)
'HOME
`(HOME ,(ununix-path-component namestring 1 index))))))
(else
(make-pathname `(HOME ,(ununix-path-component namestring 1 length))
'()
#f)))))
(define (parse-unix-namestring/env namestring)
(let ((length (string-length namestring)))
(cond ((string-index #\/ namestring 0 length)
=> (lambda (index)
(and (> index 1)
(parse-unix-namestring/directory
namestring
index
(unix-environment-variable-origin
(substring namestring 1 index))))))
(else
(make-pathname (unix-environment-variable-origin
(substring namestring 1 length))
'()
#f)))))
(define (unix-environment-variable-origin variable)
;++ (if (string=? variable "HOME")
;++ 'HOME
;++ variable)
variable)
(define (parse-unix-namestring/dot namestring)
(let ((length (string-length namestring)))
(define (parse-directory index backs)
(parse-unix-namestring/directory namestring (- index 1) backs))
(let loop ((backs #f) (index 0))
(cond ((= index (string-length namestring))
(make-pathname backs '() #f))
((not (char=? #\. (string-ref namestring index)))
(if (char=? #\/ (string-ref namestring index))
(loop backs (+ index 1))
(parse-directory index backs)))
((= length (+ index 1))
(make-pathname backs '() "."))
((not (char=? #\. (string-ref namestring (+ index 1))))
(if (char=? #\/ (string-ref namestring (+ index 1)))
(loop backs (+ index 2))
(parse-directory index backs)))
(else
(loop (add-back backs)
(+ index 3)))))))
(define (add-back backs)
(cond ((not backs) 'BACK)
((eq? backs 'BACK) '(BACK BACK))
(else (cons 'BACK backs))))
(define (parse-unix-namestring/directory namestring start origin)
(define (parse-filename start end)
(parse-unix-file-namestring namestring start end))
(let loop ((directory '()) (index start))
(let ((start (+ index 1)))
(cond ((string-index #\/ namestring start (string-length namestring))
=> (lambda (index)
;; Ignore double slashes and dots.
(loop (if (or (= index start)
(and (= index (+ start 1))
(char=? (string-ref namestring start)
#\.)))
directory
(cons (parse-filename start index) directory))
index)))
(else
(make-pathname origin
(reverse directory)
(let ((end (string-length namestring)))
(and (< start end)
(parse-filename start end)))))))))
(define (parse-unix-file-namestring string start end)
(receive (version end)
(if (parse-unix-file-versions?)
(parse-unix-file-version string start end)
(values #f end))
(if (parse-unix-file-types?)
(receive (types-start types) (parse-unix-file-types string start end)
(make-filename (ununix-path-component string start types-start)
types
version))
(make-filename (ununix-path-component string start end) '() version))))
(define (parse-unix-file-version string start end)
(cond ((and (char=? #\~ (string-ref string (- end 1)))
(string-index-right #\. string start end))
=> (lambda (dot-index)
(cond ((and (< dot-index (- end 2))
(char=? #\~ (string-ref string (+ dot-index 1)))
(string->number (substring string
(+ dot-index 2)
(- end 1))
10))
=> (lambda (version)
(values version dot-index)))
(else (values #f end)))))
(else (values #f end))))
(define (parse-unix-file-types string start end)
(let ((component ununix-path-component))
(cond ((string-index #\. string start end)
=> (lambda (first-dot-index)
(let loop ((types '()) (start first-dot-index))
(let ((start (+ start 1)))
(cond ((string-index #\. string start end)
=> (lambda (dot-index)
(loop (cons (component string start dot-index)
types)
dot-index)))
(else
(values first-dot-index
(reverse (cons (component string start end)
types)))))))))
(else (values end '())))))
(define $parse-unix-file-types? (make-fluid (make-cell #f)))
(define $parse-unix-file-versions? (make-fluid (make-cell #f)))
(define (parse-unix-file-types?) (fluid-cell-ref $parse-unix-file-types?))
(define (parse-unix-file-versions?)
(fluid-cell-ref $parse-unix-file-versions?))
(define (string-index char string start end)
(let loop ((i start))
(and (< i end)
(if (char=? char (string-ref string i))
i
(loop (+ i 1))))))
(define (string-index-right char string start end)
(let loop ((i end))
(and (> i start)
(let ((j (- i 1)))
(if (char=? char (string-ref string j))
j
(loop j))))))
(define (string-downcase string)
(list->string (map char-downcase (string->list string))))
(define (decorated-string-append empty prefix infix suffix strings)
(if (null? strings)
empty
(apply string-append
prefix
(let recur ((strings strings))
(let ((tail (cdr strings)))
(if (pair? tail)
(cons (car strings) (cons infix (recur (cdr strings))))
(list (car strings) suffix)))))))
;++ foo
(define (unix/origin-expansion origin)
(cond ((string? origin)
(lambda ()
(lookup-environment-variable origin)))
((eq? origin 'HOME)
(lambda ()
(user-info-home-directory-pathname
(user-id->user-info (get-user-id)))))
(else #f)))
(define (unix/origin-expander origin-key)
(case origin-key
((HOME)
(lambda (origin)
(cond ((and (pair? (cdr origin))
(or (string? (cadr origin))
(symbol? (cadr origin)))
(null? (cddr origin))
(name->user-info (unix-path-component (cadr origin))))
=> user-info-home-directory-pathname)
(else #f))))
(else #f)))
(define (user-info-home-directory-pathname user-info)
(pathname-as-directory (user-info-home-directory user-info)))
| false |
5669ca41c035a577b52819bef1e3a3136dc899c0 | eef5f68873f7d5658c7c500846ce7752a6f45f69 | /spheres/gambit/ffi/c-define-struct#.scm | 6d1e9125071242e9a9c8e3250664924bdad0bba7 | [
"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 | 5,430 | scm | c-define-struct#.scm | ;; Helper for define-c-struct and define-c-union
(define^ (%%c-define-struct-or-union struct-or-union type fields)
(let* ((type-str (symbol->string type))
(struct-type-str (string-append
(case struct-or-union
((struct) "struct ")
((union) "union ")
(else
(error "%%c-define-struct-or-union: first parameter must be 'struct or 'union")))
type-str))
(struct-type*-str (string-append struct-type-str "*"))
(release-type-str (string-append "___release_" type-str))
(type* (%%generic-symbol-append type-str "*"))
(type*/nonnull (%%generic-symbol-append type-str "*/nonnull"))
(type*/release-rc (%%generic-symbol-append type-str "*/release-rc")))
(define (field-getter-setter field-spec)
(let* ((field (car field-spec))
(field-str (symbol->string field))
(field-description (cadr field-spec)))
(if (pair? field-description)
;; Field is either a 'struct', an 'array' or an 'array of structs'
(let* ((field-tag (car field-description))
(field-type (cadr field-description))
(field-type-str (symbol->string field-type)))
(case field-tag
;; Struct
((struct)
`((define ,(%%generic-symbol-append type-str "-" field-str)
(c-lambda (,type*/nonnull)
,(%%generic-symbol-append field-type-str "*/nonnull")
,(string-append "___result_voidstar = &___arg1->" field-str ";")))
(define ,(%%generic-symbol-append type-str "-" field-str "-set!")
(c-lambda (,type*/nonnull ,field-type)
void
,(string-append "___arg1->" field-str " = ___arg2;")))))
;; Array of fundamental type
((array)
;; generate a getter and a setter
`((define ,(%%generic-symbol-append type-str "-" field-str "-ref")
(c-lambda (,type*/nonnull int)
,field-type
,(string-append "___result = ___arg1->" field-str "[___arg2];")))
(define ,(%%generic-symbol-append type-str "-" field-str "-set!")
(c-lambda (,type*/nonnull int ,field-type)
void
,(string-append "___arg1->" field-str "[___arg2] = ___arg3;")))))
;; Array of structs
((struct-array)
;; only generate a getter returning struct address
`((define ,(%%generic-symbol-append type-str "-" field-str "-ref")
(c-lambda (,type*/nonnull int)
,(%%generic-symbol-append field-type-str "*/nonnull")
,(string-append "___result_voidstar = &___arg1->" field-str "[___arg2];")))))))
;; Field is fundamental type
`((define ,(%%generic-symbol-append type-str "-" field-str)
(c-lambda (,type*/nonnull)
,field-description
,(string-append "___result = ___arg1->" field-str ";")))
(define ,(%%generic-symbol-append type-str "-" field-str "-set!")
(c-lambda (,type*/nonnull ,field-description)
void
,(string-append "___arg1->" field-str " = ___arg2;")))))))
(let ((expansion
`(begin
;; Define the release function which is called when the
;; object is no longer accessible from the Scheme world.
(c-declare
,(string-append
"static ___SCMOBJ " release-type-str "( void* ptr )\n"
"{\n"
" ___EXT(___release_rc)( ptr );\n"
" return ___FIX(___NO_ERR);\n"
"}\n"))
;; Define type allocator procedure.
(define ,(%%generic-symbol-append "alloc-" type-str)
(c-lambda ()
,type*/release-rc
,(string-append "___result_voidstar = ___EXT(___alloc_rc)( sizeof( " struct-type-str " ) );")))
;; Dereference
(define ,(%%generic-symbol-append "*->" type-str)
(c-lambda (,type*/nonnull)
,type
,(string-append "___result_voidstar = (" type-str "*)___arg1;")))
;; Define field getters and setters.
,@(apply append (map field-getter-setter fields)))))
(if #f ;; #t for debugging
(pp `(definition:
(c-define-struct ,type ,@fields)
expansion:
,expansion)))
expansion)))
;;! Defines the c-define-struct macro, which extends the Gambit FFI to
;; interface to C structures.
(define-macro (c-define-struct type . fields)
(%%c-define-struct-or-union 'struct type fields))
;;! Defines the c-define-union macro, which extends the Gambit FFI to
;; interface to C structures.
(define-macro (c-define-union type . fields)
(%%c-define-struct-or-union 'union type fields))
| false |
bdcd88657250bbb494828f4945a2b35251ea283d | fd6a686f9fc2abc16754f9d3224085be1f22feb2 | /imlib2-xlib.scm | af63e0e0b6887de1d0a79fa9ef7a2982ea92a863 | [
"BSD-3-Clause"
]
| permissive | npyl/imlib2-xlib-egg | 88b2921d04e27552c3e201efc839fece57dab56c | 1e85ea5c9ec9019fa1631cdf5e096e347257fa8a | refs/heads/master | 2020-06-13T06:27:00.396146 | 2017-12-18T02:03:01 | 2017-12-18T02:03:01 | null | 0 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 10,002 | scm | imlib2-xlib.scm | ;; Copyright 2017 John J Foerch. All rights reserved.
;;
;; 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 JOHN J FOERCH ''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 JOHN J FOERCH 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.
(module imlib2-xlib
(imlib-context-set-display
imlib-context-disconnect-display
imlib-context-set-visual
imlib-context-set-colormap
imlib-context-set-drawable
imlib-context-set-mask
imlib-context-get-display
imlib-context-get-visual
imlib-context-get-colormap
imlib-context-get-drawable
imlib-context-get-mask
imlib-get-visual-depth
imlib-get-best-visual
imlib-pixmap-and-mask?
imlib-pixmap-and-mask-pixmap
imlib-pixmap-and-mask-mask
imlib-render-pixmaps-for-whole-image
imlib-render-pixmaps-for-whole-image-at-size
imlib-render-image-on-drawable
imlib-render-image-on-drawable-at-size
imlib-render-image-part-on-drawable-at-size
imlib-render-get-pixel-color
imlib-create-image-from-drawable
imlib-create-image-from-ximage
imlib-create-scaled-image-from-drawable
imlib-copy-drawable-to-image
imlib-render-image-on-drawable-skewed
imlib-render-image-on-drawable-at-angle)
(import chicken scheme foreign)
(use foreigners
imlib2)
(declare (disable-interrupts))
(foreign-declare "#include <Imlib2.h>")
;;
;; Datatypes
;;
(define-foreign-type XID unsigned-long)
(define-foreign-type Colormap XID)
(define-foreign-type DATA32 unsigned-int)
(define-foreign-type Display c-pointer)
(define-foreign-type Drawable XID)
(define-foreign-type Imlib_Image c-pointer)
(define-foreign-type Pixmap XID)
(define-foreign-type Visual c-pointer)
(define-foreign-type XImage c-pointer)
(define-foreign-type cbool char
(lambda (b) (integer->char (if b 1 0)))
(lambda (c) (if (eqv? #\null c) #f #t)))
;;
;;
;;
(define (imlib2-xlib-error loc msg . args)
(abort (make-composite-condition
(make-property-condition 'exn
'location loc
'message msg
'arguments args)
(make-property-condition 'imlib2-xlib))))
(define (assert-image img loc . args)
(when (not (image-ptr img))
(imlib2-xlib-error loc "Invalid image parameter" args)))
(define-syntax define/img
(syntax-rules ()
((define/img (func img arg ...)
body ...)
(define (func img arg ...)
(assert-image img (quote func) arg ...)
(%imlib-context-set-image (image-ptr img))
body ...))))
(define %imlib-context-set-image
(foreign-lambda void imlib_context_set_image Imlib_Image))
;;
;; Context setting
;;
(define imlib-context-set-display
(foreign-lambda void imlib_context_set_display Display))
(define imlib-context-disconnect-display
(foreign-lambda void imlib_context_disconnect_display))
(define imlib-context-set-visual
(foreign-lambda void imlib_context_set_visual Visual))
(define imlib-context-set-colormap
(foreign-lambda void imlib_context_set_colormap Colormap))
(define imlib-context-set-drawable
(foreign-lambda void imlib_context_set_drawable Drawable))
(define imlib-context-set-mask
(foreign-lambda void imlib_context_set_mask Pixmap))
;;
;; Context getting
;;
(define imlib-context-get-display
(foreign-lambda Display imlib_context_get_display))
(define imlib-context-get-visual
(foreign-lambda Visual imlib_context_get_visual))
(define imlib-context-get-colormap
(foreign-lambda Colormap imlib_context_get_colormap))
(define imlib-context-get-drawable
(foreign-lambda Drawable imlib_context_get_drawable))
(define imlib-context-get-mask
(foreign-lambda Pixmap imlib_context_get_mask))
(define imlib-get-visual-depth
(foreign-lambda int imlib_get_visual_depth Display Visual))
(define (imlib-get-best-visual display screen)
(let-location ((depth int))
(let ((visual
((foreign-lambda Visual imlib_get_best_visual Display int (c-pointer int))
display screen (location depth))))
(values visual depth))))
;;
;; Rendering functions
;;
(define-record-type :imlib-pixmap-and-mask
(%make-imlib-pixmap-and-mask pixmap mask)
imlib-pixmap-and-mask?
(pixmap imlib-pixmap-and-mask-pixmap)
(mask imlib-pixmap-and-mask-mask))
(define %imlib-free-pixmap-and-mask
(foreign-lambda void imlib_free_pixmap_and_mask Pixmap))
(define (free-imlib-pixmap-and-mask! ipm)
(%imlib-free-pixmap-and-mask (imlib-pixmap-and-mask-pixmap ipm))
(%imlib-free-pixmap-and-mask (imlib-pixmap-and-mask-mask ipm)))
(define (make-imlib-pixmap-and-mask pixmap mask)
(let ((ipm (%make-imlib-pixmap-and-mask pixmap mask)))
(set-finalizer! ipm free-imlib-pixmap-and-mask!)
ipm))
(define/img (imlib-render-pixmaps-for-whole-image img)
(let-location ((pixmap Pixmap)
(mask Pixmap))
((foreign-lambda void imlib_render_pixmaps_for_whole_image
(c-pointer Pixmap) (c-pointer Pixmap))
(location pixmap) (location mask))
(make-imlib-pixmap-and-mask pixmap mask)))
(define/img (imlib-render-pixmaps-for-whole-image-at-size img width height)
(let-location ((pixmap Pixmap)
(mask Pixmap))
((foreign-lambda void imlib_render_pixmaps_for_whole_image_at_size
(c-pointer Pixmap) (c-pointer Pixmap) int int)
(location pixmap) (location mask) width height)
(make-imlib-pixmap-and-mask pixmap mask)))
(define/img (imlib-render-image-on-drawable img x y)
((foreign-lambda void imlib_render_image_on_drawable int int)
x y))
(define/img (imlib-render-image-on-drawable-at-size img x y width height)
((foreign-lambda void imlib_render_image_on_drawable_at_size int int int int)
x y width height))
(define/img (imlib-render-image-part-on-drawable-at-size img source-x source-y
source-width source-height
x y width height)
((foreign-lambda void imlib_render_image_part_on_drawable_at_size
int int int int int int int int)
source-x source-y source-width source-height x y width height))
(define imlib-render-get-pixel-color
(foreign-lambda DATA32 imlib_render_get_pixel_color))
;;
;; Creation functions
;;
(define (imlib-create-image-from-drawable mask x y width height need-to-grab-x?)
(set-finalizer!
(make-image
((foreign-lambda Imlib_Image imlib_create_image_from_drawable
Pixmap int int int int cbool)
mask x y width height need-to-grab-x?))
gc-collect-image))
(define (imlib-create-image-from-ximage ximage mask x y width height need-to-grab-x?)
(set-finalizer!
(make-image
((foreign-lambda Imlib_Image imlib_create_image_from_ximage
XImage XImage int int int int cbool)
ximage mask x y width height need-to-grab-x?))
gc-collect-image))
(define (imlib-create-scaled-image-from-drawable mask source-x source-y
source-width source-height
dest-width dest-height
need-to-grab-x?
get-mask-from-shape?)
(set-finalizer!
(make-image
((foreign-lambda Imlib_Image imlib_create_scaled_image_from_drawable
Pixmap int int int int int int cbool cbool)
mask source-x source-y source-width source-height
dest-width dest-height need-to-grab-x? get-mask-from-shape?))
gc-collect-image))
(define/img (imlib-copy-drawable-to-image img mask x y width height
dest-x dest-y need-to-grab-x?)
((foreign-lambda cbool imlib_copy_drawable_to_image
Pixmap int int int int int int cbool)
mask x y width height dest-x dest-y need-to-grab-x?))
;;
;; Rotation / skewing
;;
(define/img (imlib-render-image-on-drawable-skewed img source-x source-y
source-width source-height
dest-x dest-y
h-angle-x h-angle-y
v-angle-x v-angle-y)
((foreign-lambda void imlib_render_image_on_drawable_skewed
int int int int int int int int int int)
source-x source-y source-width source-height dest-x dest-y
h-angle-x h-angle-y v-angle-x v-angle-y))
(define/img (imlib-render-image-on-drawable-at-angle img source-x source-y
source-width source-height
dest-x dest-y
angle-x angle-y)
((foreign-lambda void imlib_render_image_on_drawable_at_angle
int int int int int int int int)
source-x source-y source-width source-height dest-x dest-y angle-x angle-y))
)
| true |
7365ab1e749405fabdc365b59a0ca6e3e8ec3f3d | 58381f6c0b3def1720ca7a14a7c6f0f350f89537 | /Chapter 3/3.1/3.05.scm | 971c3b180e2998ba5658c589e25dcd889a8cee98 | []
| no_license | yaowenqiang/SICPBook | ef559bcd07301b40d92d8ad698d60923b868f992 | c8a0228ebf66d9c1ddc5ef1fcc1d05d8684f090a | refs/heads/master | 2020-04-19T04:03:15.888492 | 2015-11-02T15:35:46 | 2015-11-02T15:35:46 | null | 0 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 1,291 | scm | 3.05.scm | #lang planet neil/sicp
(define (square x) (* x x))
(define (random-in-range low high)
(let ((range (- high low)))
(+ low (random range))))
(define (estimate-pi trials)
(sqrt (/ 6 (monte-carlo trials
cesaro-test))))
(define (cesaro-test)
(= (gcd (random) (random)) 1))
(define (monte-carlo trials experiment)
(define (iter trials-remaining trials-passed)
(cond ((= trials-remaining 0)
(/ trials-passed trials))
((experiment)
(iter (- trials-remaining 1)
(+ trials-passed 1)))
(else
(iter (- trials-remaining 1)
trials-passed))))
(iter trials 0))
(define (estimate-integral p x1 x2 y1 y2 trials)
(define (experiment)
(p (random-in-range x1 x2)
(random-in-range y1 y2)))
(* (- x2 x1)
(- y2 y1)
(monte-carlo trials experiment)))
(define (pred x y)
(or (= (+ (* (- x 5) (- x 5)) (* (- y 7) (- y 7))) 9)
(< (+ (* (- x 5) (- x 5)) (* (- y 7) (- y 7))) 9)))
;;test
(estimate-integral pred 2 8 4 10 500000)
(/ (* 22 9) 7)
(define (unit-circle-pred x y)
(or (= (+ (square x) (square y)) 1)
(< (+ (square x) (square y)) 1)))
(define pi-estimate (estimate-integral unit-circle-pred -1 1 -1 1 1000000))
pi-estimate
| false |
c67e2fd26bb5e418ef9b16c96d3bdc54735a1176 | 408a2b292dcb010e67632e15aa9c6d6d76b9402d | /optimize-transition.scm | 2fbdd5ab7fb82dd891d0f2ae8284fd7ec1fa4c8c | []
| no_license | shanecelis/mc-2013 | f0e4832bca1fcbb1cd1c9c79ffcef7872488d50b | 19fc6e42ca47a779ea1565148caa1ffa5febe129 | refs/heads/master | 2021-01-10T19:01:47.043317 | 2013-12-17T20:10:26 | 2013-12-17T20:10:26 | null | 0 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 4,669 | scm | optimize-transition.scm | ;; Rename optimize-transition.scm to transition-params, perhaps?
(define-module (optimize-transition)
#:use-module (srfi srfi-9) ;; record
#:use-module (srfi srfi-9 gnu) ;; record
#:use-module (srfi srfi-1) ;; iota
#:use-module (vector-math)
#:use-module (emacsy emacsy)
#:use-module (system foreign)
#:use-module (unified-procedure)
#:use-module (guile-user) ;; because beer-experiment.scm
#:use-module (eval-robot)
#:export (<transition-params>
make-transition-params
make-transition-params-effector
make-make-transition-effector-func
tp:trinary-matrix?
tp:motor-count-in
tp:motor-count-out
transition-params?
tp:gene-count
tp:gene-count*
fix-transition-params))
;; This module is to optimize the transition from a minimal cognition
;; agent in FODE to an agent in Bullet. The trick we're going to try
;; and do is this: Evolve in FODE, then keep that fixed, and evolve a
;; trinary or real matrix between the original agent and the new agent
;; optimized for fitness in Bullet.
(define-record-type <transition-params>
(make-transition-params* trinary-matrix? motor-count-in motor-count-out gene-count)
transition-params?
(trinary-matrix? tp:trinary-matrix?)
(motor-count-in tp:motor-count-in)
(motor-count-out tp:motor-count-out)
(gene-count tp:gene-count))
(set-record-type-printer! <transition-params>
(lambda (record port)
(format port "(make-transition-params ~a ~a ~a)"
(tp:motor-count-in record)
(tp:motor-count-out record)
(tp:trinary-matrix? record))))
(define* (make-transition-params motor-count-in motor-count-out #:optional
(trinary-matrix? #t))
"Make a genome for the given number of initial motors and final motors"
(let ((gene-count (* motor-count-in motor-count-out)))
(make-transition-params* trinary-matrix?
motor-count-in
motor-count-out
gene-count)))
(define (make-transition-params-effector transition-params effector genome)
(make-unified-procedure
double
(lambda (t i . rest)
;; Oh, I can't just do it as matrix multiplication because I get
;; the values one at a time, and I send them out one at a time.
;; Therefore, I would either need to change the interface or I
;; need to collect them before I apply them. I'll just compute
;; the dot product that I need for now without mucking with the
;; interface.
#;(let ((original (apply effector t i rest))
(M (genome->matrix genome)))
(matrix. M original))
(let* ((in-count (tp:motor-count-in transition-params))
(out-count (tp:motor-count-out transition-params))
(inputs (map
;; Effector is called multiple times.
(lambda (i) (apply effector t i rest))
(iota in-count 1)))
;; We'll treat genome like a matrix in row-major order.
;; We want to compute for matrix M = [ r1; r2; r3 ] and
;; input x the value r_i . x
(r_i (map (lambda (j) (array-ref genome j))
(iota in-count (* out-count (1- i)))))
(out (apply + (map * r_i inputs))))
;(format #t "CALLED input ~a out ~a with matrix ~a~%" inputs out genome)
out))
(list double int '*)
#;
(list double int
(list '* (vector-ref (unified-default-values effector) 2)))))
(define make-effector-func-original #f)
(define (make-make-transition-effector-func transition-params genome)
(if (not make-effector-func-original)
(set! make-effector-func-original make-effector-func))
(lambda (ctrnn-state)
(make-transition-params-effector
transition-params
(make-effector-func-original ctrnn-state)
genome)))
(define-interactive (swap-out-effector)
(set! make-effector-func
(make-make-transition-effector-func
(make-transition-params 2 2 #f)
#f64(1. 0. ;; genome
0. 1.)))
(reset-fode))
(define (fix-transition-params tp)
(cond
((transition-params? tp)
tp)
((list? tp)
(eval tp (interaction-environment)))
(else
(scm-error 'invalid-transition-params "fix-transition-params" "Got a weird thing for transition params ~a" (list tp) #f))))
;; Sometimes the record syntax stuff really gunks things up.
(define tp:gene-count* tp:gene-count)
| false |
976d4816bfa1b1bedb108d466da7311ed79ba9c7 | 92b8d8f6274941543cf41c19bc40d0a41be44fe6 | /gnu/kawa/servlet/servlets.scm | bbcbf1aa048635f9f5c986d43b1895f20182d3dd | [
"MIT"
]
| permissive | spurious/kawa-mirror | 02a869242ae6a4379a3298f10a7a8e610cf78529 | 6abc1995da0a01f724b823a64c846088059cd82a | refs/heads/master | 2020-04-04T06:23:40.471010 | 2017-01-16T16:54:58 | 2017-01-16T16:54:58 | 51,633,398 | 6 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 2,052 | scm | servlets.scm | (module-export
;; imported from HTTP.scm:
response-header response-content-type response-status
request-method request-scheme error-response
request-local-socket-address request-local-IP-address
request-local-port request-local-host
request-remote-socket-address request-remote-IP-address
request-remote-port request-remote-host
request-header request-header-map request-URI
request-context-path request-script-path request-local-path
request-path request-uri request-url request-path-translated
request-query-string request-parameter request-parameters
request-parameter-map
;; Local definitions:
current-servlet current-servlet-context current-servlet-config
servlet-context-realpath get-response get-request
request-servlet-path request-path-info)
(require 'http)
(define (current-servlet) ::javax.servlet.http.HttpServlet
(let ((ctx (gnu.kawa.servlet.KawaServlet$Context:getInstanceOrNull)))
(if (eq? ctx #!null) #!null (ctx:getServlet))))
(define (current-servlet-context) ::javax.servlet.ServletContext
((gnu.kawa.servlet.KawaServlet$Context:getInstance "current-servlet-context"):getServletContext))
(define (current-servlet-config) ::javax.servlet.ServletConfig
((gnu.kawa.servlet.KawaServlet$Context:getInstance "current-servlet-config"):getServletConfig))
(define (get-response) ::javax.servlet.http.HttpServletResponse
((gnu.kawa.servlet.KawaServlet$Context:getInstance "get-response"):getResponse))
(define (get-request) ::javax.servlet.http.HttpServletRequest
((gnu.kawa.servlet.KawaServlet$Context:getInstance "get-request"):getRequest))
(define (servlet-context-realpath #!optional (path ::String "")) ::String
(((gnu.kawa.servlet.KawaServlet$Context:getInstance "servlet-context-realpath"):getServletContext):getRealPath))
(define (request-servlet-path) ::String
((gnu.kawa.servlet.KawaServlet$Context:getInstance "request-servlet-path"):getServletPath))
(define (request-path-info) ::String
(((gnu.kawa.servlet.KawaServlet$Context:getInstance "request-path-info"):getRequest):getPathInfo))
| false |
badb5f06312e2ffc8f88af957d3abaf8826c0285 | ce567bbf766df9d98dc6a5e710a77870753c7d29 | /ch9/30.scm | a11ba009d53b8d5cef310c98d3798da6b04fd241 | []
| 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,059 | scm | 30.scm |
;; interface summable
;; method int sum()
;; class sum_list extends object
;; implements summable
;; field summable first
;; field summable left
;; method void initialize(f : summable, l : summable)
;; begin
;; set first = f; set left = l
;; end
;; method int sum() +(send first sum(), send left sum())
;; class leaf_node extends object
;; implements summable
;; field int value
;; method void initialize(v : int)set value = v
;; method int sum() value
;; class interior_node extends object
;; implements summable
;; field summable left
;; field summable right
;; method void initialize(l : summable, r : summable)
;; begin
;; set left = l; set right = r
;; end
;; method int sum() +(send left sum(), send right sum())
;; class general_tree extends object
;; implements summable
;; field sum_list left
;; field sum_list right
;; method void initialize(l : sum_list, r : sum_list)
;; begin
;; set left = l; set right = r
;; end
;; method int sum + (send left sum(), send right sum())
| false |
c41a7629af3e5000f4444a0b7ad75b6596d0dc12 | 3508dcd12d0d69fec4d30c50334f8deb24f376eb | /tests/runtime/test-mime-codec.scm | 3c26a492404a578fc6218f53632f1907a21330ad | []
| 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 | 10,172 | scm | test-mime-codec.scm | #| -*-Scheme-*-
Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994,
1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016,
2017, 2018, 2019, 2020, 2021, 2022 Massachusetts Institute of
Technology
This file is part of MIT/GNU Scheme.
MIT/GNU Scheme is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at
your option) any later version.
MIT/GNU Scheme is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with MIT/GNU Scheme; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301,
USA.
|#
;;;; Tests of MIME codecs
(declare (usual-integrations))
(load-option 'mime-codec)
(define (test-encoder n-packets packet-length text? filename
binary-codec? initialize finalize update)
(call-with-output-file filename
(lambda (port)
(let ((context (initialize port text?))
(n-packets (random n-packets)))
(do ((i 0 (+ i 1)))
((= i n-packets))
(let ((packet-length (random packet-length)))
(write i port)
(write-char #\space port)
(write packet-length port)
(write-char #\space port)
(let ((packet (make-test-packet packet-length text? binary-codec?)))
(write packet port)
(newline port)
(update context packet 0 packet-length))))
(finalize context)))))
(define (make-test-packet packet-length text? binary-codec?)
(cond (binary-codec? (random-bytevector packet-length))
(text? (random-text-string packet-length))
(else (random-byte-vector packet-length))))
(define (random-text-string length)
(let ((builder (string-builder))
(n-text (string-length text-characters)))
(do ((i 0 (fix:+ i 1)))
((not (fix:< i length)))
(builder (string-ref text-characters (random n-text))))
(builder 'immutable)))
(define (random-byte-vector length)
(let ((bv (random-bytevector length))
(builder (string-builder)))
(do ((i 0 (fix:+ i 1)))
((not (fix:< i length)))
(builder (integer->char (bytevector-u8-ref bv i))))
(builder 'immutable)))
(define text-characters
(char-set->string
(char-set-union (ucs-range->char-set #x20 #x7F)
(ucs-range->char-set #xA0 #x100)
(char-set #\tab #\newline))))
(define (test-codec n-packets packet-length text? filename binary-codec?
encode:initialize encode:finalize encode:update
decode:initialize decode:finalize decode:update)
(let ((packets
(make-test-vector n-packets packet-length text? binary-codec?)))
(if binary-codec?
(begin
(call-with-binary-output-file (pathname-new-type filename "clear1")
(lambda (port)
(vector-for-each (lambda (packet)
(write-bytevector packet port))
packets)))
(call-with-output-file (pathname-new-type filename "encoded")
(lambda (port)
(let ((context (encode:initialize port text?)))
(vector-for-each (lambda (packet)
(encode:update context packet))
packets)
(encode:finalize context)))))
(begin
(call-with-output-file (pathname-new-type filename "clear1")
(lambda (port)
(vector-for-each (lambda (packet)
(write-string packet port))
packets)))
(call-with-output-file (pathname-new-type filename "encoded")
(lambda (port)
(let ((context (encode:initialize port text?)))
(vector-for-each (lambda (packet)
(encode:update context packet))
packets)
(encode:finalize context)))))))
(retest-decoder text? filename binary-codec?
decode:initialize decode:finalize decode:update))
(define (make-test-vector n-packets packet-length text? binary-codec?)
(let ((n-packets (random n-packets))
(builder (vector-builder)))
(do ((i 0 (fix:+ i 1)))
((not (fix:< i n-packets)))
(builder
(make-test-packet (random packet-length)
text?
binary-codec?)))
(builder)))
(define (retest-codec text? filename binary-codec?
encode:initialize encode:finalize encode:update
decode:initialize decode:finalize decode:update)
(if binary-codec?
(call-with-binary-input-file (pathname-new-type filename "clear1")
(lambda (input-port)
(call-with-output-file (pathname-new-type filename "encoded")
(lambda (output-port)
(let ((context (encode:initialize output-port text?)))
(let loop ()
(let ((bv (read-bytevector 37 input-port)))
(if (not (eof-object? bv))
(begin
(encode:update context bv)
(loop)))))
(encode:finalize context))))))
(call-with-input-file (pathname-new-type filename "clear1")
(lambda (input-port)
(call-with-output-file (pathname-new-type filename "encoded")
(lambda (output-port)
(let ((context (encode:initialize output-port text?)))
(let loop ()
(let ((string (read-string 37 input-port)))
(if (not (eof-object? string))
(begin
(encode:update context string)
(loop)))))
(encode:finalize context)))))))
(retest-decoder text? filename binary-codec?
decode:initialize decode:finalize decode:update))
(define (retest-decoder text? filename binary-codec?
decode:initialize decode:finalize decode:update)
(let ((pn3 (pathname-new-type filename "clear2")))
(if binary-codec?
(begin
(call-with-input-file (pathname-new-type filename "encoded")
(lambda (input-port)
(call-with-binary-output-file pn3
(lambda (output-port)
(let ((context (decode:initialize output-port text?)))
(let loop ()
(let ((string (read-string 41 input-port)))
(if (not (eof-object? string))
(begin
(decode:update context string)
(loop)))))
(decode:finalize context))))))
(call-with-binary-input-file (pathname-new-type filename "clear1")
(lambda (p1)
(call-with-binary-input-file pn3
(lambda (p3)
(let loop ()
(let ((b1 (read-u8 p1))
(b3 (read-u8 p3)))
(if (eof-object? b1)
(if (eof-object? b3)
unspecific
(error "Output file longer."))
(if (eof-object? b3)
(error "Output file shorter.")
(if (fix:= b1 b3)
(loop)
(error "Files don't match.")))))))))))
(begin
(call-with-input-file (pathname-new-type filename "encoded")
(lambda (input-port)
(call-with-output-file pn3
(lambda (output-port)
(let ((context (decode:initialize output-port text?)))
(let loop ()
(let ((string (read-string 41 input-port)))
(if (not (eof-object? string))
(begin
(decode:update context string)
(loop)))))
(decode:finalize context))))))
(call-with-input-file (pathname-new-type filename "clear1")
(lambda (p1)
(call-with-input-file pn3
(lambda (p3)
(let loop ()
(let ((c1 (read-char p1))
(c3 (read-char p3)))
(if (eof-object? c1)
(if (eof-object? c3)
unspecific
(error "Output file longer."))
(if (eof-object? c3)
(error "Output file shorter.")
(if (char=? c1 c3)
(loop)
(error "Files don't match."))))))))))))))
(define (for-each-setting procedure)
(procedure 20 1024 #t)
(procedure 20 1024 #f))
(define (define-mime-codec-tests name binary-codec?
encode:initialize encode:finalize encode:update
decode:initialize decode:finalize decode:update)
(for-each-setting
(lambda (n-packets packet-length text?)
(define-test (symbol 'encode '- name
'/ (if text? 'text 'binary)
'/ n-packets
'/ packet-length)
(lambda ()
(call-with-temporary-file-pathname
(lambda (pathname)
(test-encoder
n-packets packet-length text? pathname
binary-codec? encode:initialize encode:finalize encode:update)))))
(define-test (symbol 'codec '- name
'/ (if text? 'text 'binary)
'/ n-packets
'/ packet-length)
(lambda ()
(call-with-temporary-file-pathname
(lambda (pathname)
(test-codec
n-packets packet-length text? pathname binary-codec?
encode:initialize encode:finalize encode:update
decode:initialize decode:finalize decode:update))))))))
(define-mime-codec-tests 'BASE64
#t
encode-base64:initialize
encode-base64:finalize
encode-base64:update
decode-base64:initialize
decode-base64:finalize
decode-base64:update)
#;
(define-mime-codec-tests 'BINHEX40
#t
encode-binhex40:initialize
encode-binhex40:finalize
encode-binhex40:update
decode-binhex40:initialize
decode-binhex40:finalize
decode-binhex40:update)
(define-mime-codec-tests 'QUOTED-PRINTABLE
#f
encode-quoted-printable:initialize
encode-quoted-printable:finalize
encode-quoted-printable:update
decode-quoted-printable:initialize
decode-quoted-printable:finalize
decode-quoted-printable:update)
#;
(define-mime-codec-tests 'UUE
#t
encode-uue:initialize
encode-uue:finalize
encode-uue:update
decode-uue:initialize
decode-uue:finalize
decode-uue:update)
(define (encode-quoted-printable string text?)
(call-with-output-string
(lambda (output-port)
(let ((context (encode-quoted-printable:initialize output-port text?)))
(encode-quoted-printable:update context string)
(encode-quoted-printable:finalize context)))))
(define-test 'QUOTED-PRINTABLE/UPPERCASE
(lambda ()
(let* ((string "The quïck brøwn fox jump§ over the lazʒ doﻎ.")
(utf8 (string->utf8 string))
(bytestring (iso8859-1->string utf8)))
(assert-equal
(encode-quoted-printable bytestring #t)
(string-append "The qu=C3=AFck br=C3=B8wn=C2=A0fox jump=C2=A7"
" over the laz=CA=92 do=EF=BB=\n=8E.")))))
(define-test 'QUOTED-PRINTABLE/UNICODE-BUG
(lambda ()
;; Can't handle Unicode strings, only legacy byte strings so far.
(expect-error
(lambda ()
(encode-quoted-printable "üñîçøðε" #t))))) | false |
23334e2cfe2f0173f8a8d01dbb37e24f0de921d8 | 58e98e2ceb0ee7f07d3752919876e9d531c00eac | /scheme/streams.scm | e1027f9bb9110ed269bbad76f315fdcc9007c517 | [
"MIT"
]
| permissive | triffon/fp-2018-19 | d03f65b286ad2e81d2a864da905656d83eb13161 | f3f025b4f22ad5041606eff090b72a162499ba8f | refs/heads/master | 2020-04-01T11:54:56.396063 | 2019-01-16T09:55:41 | 2019-01-16T15:42:41 | 153,183,166 | 0 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 2,256 | scm | streams.scm | (define (fact n)
(if (= n 0) 1 (* n (fact (- n 1)))))
(define the-empty-stream '())
(define empty-stream? null?)
(define (cons-stream h t)
(cons h (delay t)))
(define head car)
(define (tail s)
(force (cdr s)))
(define-syntax mydelay
(syntax-rules ()
((delay x) (lambda () x))))
(define (myforce x) (x))
(define-syntax cons-stream
(syntax-rules ()
((cons-stream h t) (cons h (delay t)))))
(define (enum a b)
(if (> a b) the-empty-stream
(cons-stream a (enum (+ a 1) b))))
(define (take n s)
(if (or (empty-stream? s) (= n 0)) '()
(cons (head s) (take (- n 1) (tail s)))))
(define (search-stream p s)
(cond ((empty-stream? s) #f)
((p (head s)) s)
(else (search-stream p (tail s)))))
(define (search-stream p s)
(and (not (empty-stream? s))
(or (and (p (head s)) s)
(search-stream p (tail s)))))
(define (from n)
(cons-stream n (from (+ n 1))))
(define nats (from 0))
(define (generate-fibs fn fn+1)
(cons-stream fn (generate-fibs fn+1 (+ fn fn+1))))
(define fibs (generate-fibs 0 1))
(define (map-stream f s)
(cons-stream (f (head s)) (map-stream f (tail s))))
(define (filter-stream p? s)
(if (p? (head s)) (cons-stream (head s) (filter-stream p? (tail s)))
(filter-stream p? (tail s))))
(define evens (filter-stream even? nats))
(define (zip-streams op s1 s2)
(cons-stream (op (head s1) (head s2))
(zip-streams op (tail s1) (tail s2))))
(define (map-stream f . ss)
(cons-stream (apply f (map head ss))
(apply map-stream f (map tail ss))))
(define ones (cons-stream 1 ones))
;; ??? (define (tail nats) (map-stream + ones nats))
(define nats (cons-stream 0 (map-stream + ones nats)))
(define fibs
(cons-stream 0
(cons-stream 1
(map-stream + fibs (tail fibs)))))
(define (notdivides d)
(lambda (n)
(> (remainder n d) 0)))
(define (sieve stream)
(cons-stream (head stream)
(filter-stream (notdivides (head stream)) (sieve (tail stream)))))
(define (sieve2 stream)
(cons-stream (head stream)
(sieve2 (filter-stream (notdivides (head stream)) (tail stream)))))
(define primes (sieve (from 2)))
(define primes2 (sieve2 (from 2))) | true |
bef554ded2eb83911e62e3025f6e3122e0bf9e6e | 4b2aeafb5610b008009b9f4037d42c6e98f8ea73 | /util/util.scm | 3e64ded00b7f5a004daa7f106723c1db89b30384 | []
| 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 | 210 | scm | util.scm | (require-extension
syntax-case
array-lib
array-lib-hof)
(module
util
(except?
round-array
sublist
debug)
(include "../util/test.scm")
(include "../util/string.scm")
(include "../util/debug.scm"))
| false |
9e7f99db40826421992581115a578f467058fea6 | 784dc416df1855cfc41e9efb69637c19a08dca68 | /src/std/crypto.ss | 27128140c75e15bd2db6de30e51889b752116859 | [
"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 | 483 | ss | crypto.ss | ;;; -*- Gerbil -*-
;;; (C) vyzo
;;; std libcrypto interface
package: std
(import (only-in :std/crypto/etc random-bytes random-bytes! libcrypto-error?)
:std/crypto/digest
:std/crypto/cipher
:std/crypto/hmac
:std/crypto/dh
:std/crypto/bn)
(export (import: :std/crypto/etc
:std/crypto/digest
:std/crypto/cipher
:std/crypto/hmac
:std/crypto/dh
:std/crypto/bn))
| false |
2959635fe4516c4bfd9bf69dad30079669509724 | dd4cc30a2e4368c0d350ced7218295819e102fba | /vendored_parsers/vendor/tree-sitter-python/queries/tags.scm | c5ca8272b8570641d03a1bd9bca912333223c8f9 | [
"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 | 258 | scm | tags.scm | (class_definition
name: (identifier) @name) @definition.class
(function_definition
name: (identifier) @name) @definition.function
(call
function: [
(identifier) @name
(attribute
attribute: (identifier) @name)
]) @reference.call
| false |
ae47581917ed91da0c4d7ad07035c312ab60788d | 29fdc68ecadc6665684dc478fc0b6637c1293ae2 | /bin/wiliki | b45432adc86284dcbcfba16c27f2d71af79fcf63 | [
"MIT"
]
| permissive | shirok/WiLiKi | 5f99f74551b2755cb4b8deb4f41a2a770138e9dc | f0c3169aabd2d8d410a90033d44acae548c65cae | refs/heads/master | 2023-05-11T06:20:48.006068 | 2023-05-05T18:29:48 | 2023-05-05T18:30:12 | 9,766,292 | 20 | 6 | MIT | 2018-10-07T19:15:09 | 2013-04-30T07:40:21 | Scheme | UTF-8 | Scheme | false | false | 9,223 | wiliki | #!/usr/bin/env gosh
;;;
;;; wiliki - managing wiliki database
;;;
;;; Copyright (c) 2004 Shiro Kawai, 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.
;;;
;;; $Id: wiliki,v 1.2 2004-04-04 11:12:14 shirok Exp $
;; NB: This is just a quick hack. The next version of wiliki
;; will provide enough APIs so that users can create applications
;; like this by just "use"-ing wiliki, instead of overriding
;; internal procedures. Please do not think this as an example
;; of wiliki-based applications!
(use srfi-2)
(use srfi-13)
(use gauche.sequence)
(use gauche.uvector)
(use gauche.parseopt)
(use gauche.parameter)
(use util.list)
(use text.tree)
(use file.filter)
(use file.util)
(use wiliki.db)
(use wiliki.format)
(require "wiliki/macro")
;;;=====================================================
;;; Utilities
;;;
(define (p . args) (for-each print args))
(define (usage)
(p "Usage: wiliki <command> [options] [args ...]"
"Commands:"
" export Exports the content of a wiliki database to a set of"
" HTML, SXML or text files."
" format Takes wiliki-marked up text file(s) and generates"
" HTML or SXML file(s)."
"Type wiliki help <command> for the detailed usage of each command.")
(exit 0))
(define (app-error . args)
(apply format (current-error-port) args)
(newline (current-error-port))
(exit 70))
(define (pagename->path pagename)
(with-string-io pagename
(lambda ()
(let loop ((ch (read-char)))
(cond ((eof-object? ch))
((char-set-contains? #[[:alpha:][:digit:]] ch)
(display ch) (loop (read-char)))
(else (for-each (cut format #t "_~2,'0X" <>)
(string->u8vector (string ch)))
(loop (read-char))))))))
;; Loads wiliki.cgi. Returns <wiliki> object.
(define (load-wiliki.cgi path)
(let ((mod (make-module #f)))
(with-error-handler
(lambda (e)
(app-error "Loading ~a failed: ~a" path (ref e 'message)))
(lambda ()
(eval '(define wiliki-main values) mod)
(load path :paths '(".") :environment mod)
(eval '(main '()) mod)))))
;;;=====================================================
;;; Export
;;;
(define (usage-export)
(p "Usage: wiliki export [-t type][-s style][-l scm] source.cgi dest-dir")
)
;;;=====================================================
;;; Format
;;;
(define (usage-format)
(p "Usage: wiliki format [-t type][-s style][-l scm][-o output] [file.txt]"
" wiliki format [-t type][-s style][-l scm] source-dir dest-dir"
"Options:"
" -t type : specifies output type, which should be either html or sxml."
" (Default html)."
" -s style : uses style as a style sheet path."
" -l scm : <scm> is a Scheme source, which is loaded before"
" start processing the inpu file. You can define your own"
" formatter in it."
" -o output : specifies an output file name."
"Description:"
" Takes a text file with wiliki markup, or a directory that contains"
" such text files, and generates html or sxml file(s)."
" The first line of each text file will be the page name; its content"
" begins from the second line."
""
" The first format takes a single text file and writes out HTML or"
" SXML as specified by -t option to stdout. If an input file name is"
" omitted, input is taken from stdin. If -o option is given, the"
" output goes to the specified file. Note that this wouldn't handle"
" WikiNames nor macros, unless you set your own formatter by -l option."
""
" The second format converts all files with .txt suffix inside a "
" directory <source-dir>, and puts the output files in a directory"
" <dest-dir>, which will be created if it doesn't exist."
" The WikiNames are handled as far as it refers to the file in the"
" same directory. You can customize it by setting your own formatter"
" by -l option."))
(define-class <text-formatter> (<wiliki-formatter>)
((suffix :init-value 'html)))
(define the-style (make-parameter '()))
(define file-page-alist (make-parameter '())) ;; filename - pagename alist
(define-method wiliki:format-wikiname ((f <text-formatter>) name)
(cond ((rassoc-ref (file-page-alist) name)
=> (lambda (file)
`((a (@ (href ,#`",|file|.,(ref f 'suffix)")) ,name))))
(else `(,#`"[[,|name|]]"))))
(define-method wiliki:format-head-elements ((f <text-formatter>) page)
`((title ,(ref page 'title))
,@(the-style)))
(define-method wiliki:format-page-header ((f <text-formatter>) page)
`((h1 ,(ref page 'title))))
(define (cmd-format args)
(let-args args ((type "t|type=y" 'html)
(style "s|style=s" #f)
(loadfile "l|load=s" #f)
(outfile "o|output=s" #f)
. args)
(define emitter
(case type
((html) (lambda (s o) (write-tree (wiliki:sxml->stree s) o)))
((sxml) (lambda (s o) (write s o)))
(else (app-error "type must be either html or sxml: ~a" type))))
(when (> (length args) 2) (usage-format))
(when style
(the-style
`((link (@ (ref "stylesheet") (href ,style) (type "text/css"))))))
(let-optionals* args ((src #f) (dst #f))
(wiliki:formatter (make <text-formatter>))
(when loadfile (load loadfile))
(cond ((and dst (file-is-directory? src))
(format-dir src dst type emitter))
((or (not src) (file-is-regular? src))
(file-filter (cut format-single <> <> emitter)
:input (or src (current-input-port))
:output (or outfile (current-output-port))))
(else
(app-error "input is not a regular file: ~a" src))))
))
(define (format-single in out emitter)
(receive (title content) (get-text-content in)
(emitter (wiliki:format-page (make <wiliki-page>
:title title :content content))
out)))
(define (format-dir src dst type emitter)
(define (get-title path)
(call-with-input-file path
(lambda (p) (string-trim-both (read-line p)))))
(define (process path file&page)
(receive (title content) (call-with-input-file path get-text-content)
(call-with-output-file (build-path dst #`",(car file&page).,type")
(lambda (out)
(emitter (wiliki:format-page (make <wiliki-page>
:title title :content content))
out)))))
(unless (file-exists? dst) (make-directory* dst))
(let* ((paths (directory-list src :children? #t :add-path? #t
:filter #/\.txt$/))
(file&page (map (lambda (path)
(cons (regexp-replace #/\.txt$/
(sys-basename path) "")
(get-title path)))
paths))
)
(parameterize ((file-page-alist file&page))
(for-each process paths file&page))))
(define (get-text-content in)
(let1 s (port->string-list in)
(when (null? s)
(app-error "input file is empty: ~a" (port-name in)))
(values (string-trim-both (car s))
(string-join (cdr s) "\n" 'suffix))))
;;;=====================================================
;;; Help
;;;
(define (cmd-help args)
(cond ((null? args) (usage))
((string=? (car args) "export") (usage-export))
((string=? (car args) "format") (usage-format))
(else (usage))))
;;;=====================================================
;;; Main
;;;
(define (main args)
(unless (> (length args) 2) (usage))
(let ((cmd (cadr args))
(args (cddr args)))
(cond ((string=? cmd "help") (cmd-help args))
((string=? cmd "export") (cmd-export args))
((string=? cmd "format") (cmd-format args))
(else (usage)))
0))
;; Local variables:
;; mode: scheme
;; end:
| false |
|
29a67da504d76c0987806394ecff1cfb7a4ab618 | 360ea1a4b5c638df02f7be578ada6c0f2ca8708f | /main-srfi-37.scm | 594a759567d9fa4cb82edd3ed3da4f7948fc2046 | [
"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 | 4,239 | scm | main-srfi-37.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.
;;;;
(define (debug option name arg seed)
(if arg (sexuna-debug-file arg))
(secuxna-debug #t)
(or seed #f))
(define (help option name arg seed)
(print #<<EOS
usage: genturfahi [-:?]
[-d | --debug]
[-h | --help]
[-i | --input-file NAME]
[-L | --license]
[-m | --no-memoize]
[-n | --define-name NAME]
[-o | --output-file NAME]
[-p | --profile]
[-s | --start-production NAME]
[-t | --define-toplevel]
[-v | --version]
[file]*
EOS
)
(exit 0))
(define (define-name option name arg seed)
(secuxna-define-name arg)
(or seed #f))
(define (define-toplevel option name arg seed)
(secuxna-define-toplevel #t)
(or seed #f))
(define (input-file option name arg seed)
(current-input-port (open-input-file arg))
(or seed #f))
(define (no-memoize option name arg seed)
(secuxna-memoize #f)
(or seed #f))
(define (output-file option name arg seed)
(current-output-port (open-output-file arg))
(or seed #f))
(define (profile option name arg seed)
(if arg (sexuna-profile-file arg))
(secuxna-profile #t)
(or seed #f))
(define (start-production option name arg seed)
(secuxna-start-production arg)
(or seed #f))
(define (license option name arg seed)
(print genturfahi-license)
(exit 0))
(define (version option name arg seed)
(print (format "genturfa'i version ~a" genturfahi-version))
(exit 0))
; handled by the Chicken runtime.
(define (runtime option name arg seed)
'())
(define options
(list (option '(#\d "debug") #f #t debug)
(option '(#\h "sidju" "help") #f #f help)
(option '(#\i "input-file") #t #f input-file)
(option '(#\L "license") #f #f license)
(option '(#\m "no-memoize") #f #f no-memoize)
(option '(#\n "define-name") #t #f define-name)
(option '(#\o "output-file") #t #f output-file)
(option '(#\p "profile") #f #t profile)
(option '(#\s "start-production") #t #f start-production)
(option '(#\t "define-toplevel") #f #f define-toplevel)
(option '(#\v "version") #f #f version)
(option '(#\:) #t #f runtime)))
(define (usage option name args seed)
(error (format "unrecognized option \"~a\"" name)))
(define (for-file name seed)
(or seed (call-with-input-file name for-port)))
(define (for-port port)
(let ((jalge (genturfahi-peg port))
(tamgau (secuxna-define-name))
(toplevel (secuxna-define-toplevel))
(port (current-output-port)))
(if (not jalge)
(secuxna-exit-status 1))
(display genturfahi-license port)
(if toplevel
(for-each (lambda (jalge) (pretty-print jalge port)) jalge)
(pretty-print
(if (pair? tamgau)
`(define-values ,(map string->symbol tamgau) ,jalge)
`(define ,(string->symbol tamgau) ,jalge))
port))
#t))
(define (main)
(let ((args (cdr (argv))))
(and (not (args-fold args options usage for-file #f))
(for-port (current-input-port)))
(exit (secuxna-exit-status))))
| false |
fcae0ce76373c9bd079deb5cfbc0b829778f81dc | defeada37d39bca09ef76f66f38683754c0a6aa0 | /System.Xml/system/xml/serialization/advanced/schema-importer-extension.sls | 3a39742f904481532038371ddfd08320c9907494 | []
| 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,994 | sls | schema-importer-extension.sls | (library (system xml serialization advanced schema-importer-extension)
(export is?
schema-importer-extension?
import-default-value
import-schema-type
import-any-element)
(import (ironscheme-clr-port))
(define (is? a)
(clr-is
System.Xml.Serialization.Advanced.SchemaImporterExtension
a))
(define (schema-importer-extension? a)
(clr-is
System.Xml.Serialization.Advanced.SchemaImporterExtension
a))
(define-method-port
import-default-value
System.Xml.Serialization.Advanced.SchemaImporterExtension
ImportDefaultValue
(System.CodeDom.CodeExpression System.String System.String))
(define-method-port
import-schema-type
System.Xml.Serialization.Advanced.SchemaImporterExtension
ImportSchemaType
(System.String
System.String
System.String
System.Xml.Schema.XmlSchemaObject
System.Xml.Serialization.XmlSchemas
System.Xml.Serialization.XmlSchemaImporter
System.CodeDom.CodeCompileUnit
System.CodeDom.CodeNamespace
System.Xml.Serialization.CodeGenerationOptions
System.CodeDom.Compiler.CodeDomProvider)
(System.String
System.Xml.Schema.XmlSchemaType
System.Xml.Schema.XmlSchemaObject
System.Xml.Serialization.XmlSchemas
System.Xml.Serialization.XmlSchemaImporter
System.CodeDom.CodeCompileUnit
System.CodeDom.CodeNamespace
System.Xml.Serialization.CodeGenerationOptions
System.CodeDom.Compiler.CodeDomProvider))
(define-method-port
import-any-element
System.Xml.Serialization.Advanced.SchemaImporterExtension
ImportAnyElement
(System.String
System.Xml.Schema.XmlSchemaAny
System.Boolean
System.Xml.Serialization.XmlSchemas
System.Xml.Serialization.XmlSchemaImporter
System.CodeDom.CodeCompileUnit
System.CodeDom.CodeNamespace
System.Xml.Serialization.CodeGenerationOptions
System.CodeDom.Compiler.CodeDomProvider)))
| false |
f68ff9e993030b4cdafee48206b1b467a6e81337 | 57d422213477c28adf3fcb2ea5b8859ee5a7beb9 | /src/algorithm/compare-macros.scm | be952f062757e4de27eb828c01e77cc3107b361f | [
"Zlib"
]
| permissive | alvatar/sphere-fabric | 3bc6c5f3bb515fb3774b54f1c97a0f9c6514f104 | 12f5bc7104ede7657017c713be098df5a5d5f485 | refs/heads/master | 2021-01-19T08:02:13.794829 | 2014-08-16T15:16:38 | 2014-08-16T15:16:38 | null | 0 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 2,453 | scm | compare-macros.scm | ;;!! 3-sided conditional
(define-syntax if3
(syntax-rules ()
((if3 c less equal greater)
(case c
((-1) less)
(( 0) equal)
(( 1) greater)
(else (error "comparison value not in {-1,0,1}"))))))
;;!! 2-sided conditionals for comparisons
(define-syntax compare:if-rel?
(syntax-rules ()
((compare:if-rel? c-cases a-cases c consequence)
(compare:if-rel? c-cases a-cases c consequence (if #f #f)))
((compare:if-rel? c-cases a-cases c consequence alternate)
(case c
(c-cases consequence)
(a-cases alternate)
(else (error "comparison value not in {-1,0,1}"))))))
(define-syntax if=?
(syntax-rules ()
((if=? arg ...)
(compare:if-rel? (0) (-1 1) arg ...))))
(define-syntax if<?
(syntax-rules ()
((if<? arg ...)
(compare:if-rel? (-1) (0 1) arg ...))))
(define-syntax if>?
(syntax-rules ()
((if>? arg ...)
(compare:if-rel? (1) (-1 0) arg ...))))
(define-syntax if<=?
(syntax-rules ()
((if<=? arg ...)
(compare:if-rel? (-1 0) (1) arg ...))))
(define-syntax if>=?
(syntax-rules ()
((if>=? arg ...)
(compare:if-rel? (0 1) (-1) arg ...))))
(define-syntax if-not=?
(syntax-rules ()
((if-not=? arg ...)
(compare:if-rel? (-1 1) (0) arg ...))))
;;!! refine and extend construction
(define-syntax refine-compare
(syntax-rules ()
((refine-compare)
0)
((refine-compare c1)
c1)
((refine-compare c1 c2 cs ...)
(if3 c1 -1 (refine-compare c2 cs ...) 1))))
(define-syntax select-compare
(syntax-rules (else)
((select-compare x y clause ...)
(let ((x-val x) (y-val y))
(select-compare (x-val y-val clause ...))))
; used internally: (select-compare (x y clause ...))
((select-compare (x y))
0)
((select-compare (x y (else c ...)))
(refine-compare c ...))
((select-compare (x y (t? c ...) clause ...))
(let ((t?-val t?))
(let ((tx (t?-val x)) (ty (t?-val y)))
(if tx
(if ty (refine-compare c ...) -1)
(if ty 1 (select-compare (x y clause ...)))))))))
(define-syntax cond-compare
(syntax-rules (else)
((cond-compare)
0)
((cond-compare (else cs ...))
(refine-compare cs ...))
((cond-compare ((tx ty) cs ...) clause ...)
(let ((tx-val tx) (ty-val ty))
(if tx-val
(if ty-val (refine-compare cs ...) -1)
(if ty-val 1 (cond-compare clause ...)))))))
| true |
da22b223869f98bc3d4547ef4c20800ea4a5f5ca | 9998f6f6940dc91a99e0e2acb4bc4e918f49eef0 | /src/test/sample-moby-programs/homeward-bound-single.ss | fc43264097884ae68fd828fab8f93cd6b3fa8f00 | []
| 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 | 4,760 | ss | homeward-bound-single.ss | ;; The first three lines of this file were inserted by DrScheme. They record metadata
;; about the language level of this file in a form that our tools can easily process.
#reader(lib "htdp-beginner-reader.ss" "lang")((modname kathi-finder-single) (read-case-sensitive #t) (teachpacks ()) (htdp-settings #(#t constructor repeating-decimal #f #t none #f ())))
;; Kathi finder: A program to report where Kathi is.
(define WIDTH 320)
(define HEIGHT 480)
;; A loc is a lat/long pair representing a location.
(define-struct loc (lat long))
;; A place is centered on a location and extends
;; to a radius measured in meters.
(define-struct place (name loc radius))
;; mile->meter: number -> number
;; Converts miles to meters.
(define (mile->meter miles)
(* miles 1609.344))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Here are a few places of interest.
;; 100 Institute Rd, in a radius of 500 meters
(define WPI-PLACE
(make-place "WPI" (make-loc 42.272824 -71.808207) 500))
;; Parking place.
(define WPI-PARKING-PLACE
(make-place "WPI Parking" (make-loc 42.2737222 -71.8058627) 50))
;; Worcester, in a radius of 3 miles.
(define WORCESTER-PLACE
(make-place "Worcester" (make-loc 42.274514 -71.798744) (mile->meter 3)))
;; This is a list of the places.
(define ALL-PLACES
(list WPI-PLACE
WPI-PARKING-PLACE
WORCESTER-PLACE))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; The telephone number to send messages to.
(define ADDRESS "5554")
;; The world is the current location.
(define initial-world (make-loc 0 0))
;; loc->string: loc -> string
(define (loc->string w)
(string-append "("
(number->string (loc-lat w))
", "
(number->string (loc-long w))
")"))
;; change-location: world number number -> world
(define (change-location w lat long)
(make-loc lat long))
;; identity: world -> world
;; Doesn't change the world.
(define (identity w)
w)
;; current-place: world -> place
;; Returns the closest place.
(define (current-place w)
(cond [(empty? (find-places ALL-PLACES w))
(make-place "Unknown" w 0)]
[else
(choose-smallest
(find-places ALL-PLACES w))]))
;; send-report: world -> effect
;; Sends out a text message of the world description,
;; and produces the world.
(define (send-report w)
(make-effect:send-sms ADDRESS
(string-append (description w)
"\n"
(maps-url (place-loc (current-place w))))))
;; maps-url: loc -> string
;; Creates the Google maps url for a location.
(define (maps-url a-loc)
(string-append "http://maps.google.com/maps?q="
(number->string
(exact->inexact (loc-lat a-loc)))
",+"
(number->string
(exact->inexact (loc-long a-loc)))
"&iwloc=A&hl=en"))
;; description: world -> string
;; Produces a text description of the current place.
(define (description w)
(place-name (current-place w)))
;; choose-smallest: (listof place) -> place
;; Returns the place with the smallest radius.
(define (choose-smallest places)
(cond
[(empty? (rest places))
(first places)]
[(< (place-radius (first places)) (place-radius (second places)))
(choose-smallest (cons (first places) (rest (rest places))))]
[else
(choose-smallest (rest places))]))
;; find-places: world loc -> (listof place)
;; Finds places that match the a-loc.
(define (find-places places a-loc)
(cond
[(empty? places)
empty]
[(place-matches? (first places) a-loc)
(cons (first places) (find-places (rest places) a-loc))]
[else
(find-places (rest places) a-loc)]))
;; place-matches?: place loc -> boolean
;; Returns true if the place matches the location.
(define (place-matches? a-place a-loc)
(<= (location-distance (loc-lat a-loc)
(loc-long a-loc)
(loc-lat (place-loc a-place))
(loc-long (place-loc a-place)))
(place-radius a-place)))
;; draw: world -> DOM-sexp
(define (draw w)
(list (js-div)
(list (js-p '(("id" "aPara")))
(list (js-text (description w)))
(list (js-text " "))
(list (js-text (loc->string w))))))
;; draw-css: world -> CSS-sexp
(define (draw-css w)
'(("aPara" ("font-size" "30px"))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(define tick-delay 10 #;(* 5 60)) ;; wait every five minutes before updates.
(js-big-bang initial-world
'()
(on-draw draw draw-css)
(on-tick* tick-delay identity send-report)
(on-location-change change-location)) | false |
f3b51a172e60fb5f7bf3de399e1686789c1ea2a3 | a09ad3e3cf64bc87282dea3902770afac90568a7 | /3/19.scm | 58d10ea76c3bebe1f7ce1d33e77def5ac585eb09 | []
| no_license | lockie/sicp-exercises | aae07378034505bf2e825c96c56cf8eb2d8a06ae | 011b37387fddb02e59e05a70fa3946335a0b5b1d | refs/heads/master | 2021-01-01T10:35:59.759525 | 2018-11-30T09:35:35 | 2018-11-30T09:35:35 | 35,365,351 | 0 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 451 | scm | 19.scm | #lang sicp
(define (has-cycle x)
(define (iter x cont elem num)
(cond ((null? (cdr x)) false)
((eq? x elem) true)
(else (if (= cont num)
(iter (cdr x) 0 x (+ 1 num))
(iter (cdr x) (+ cont 1) elem num)))))
(iter x 0 nil 0))
(has-cycle (list 1 2 3))
(define t (list 1 2))
(has-cycle (cons t t))
(define a (list 1 2 3))
(set-cdr! (cddr a) a)
(has-cycle a)
| false |
fc05a0b2dba58b4275a09d090fed42fdc64d18a3 | defeada37d39bca09ef76f66f38683754c0a6aa0 | /UnityEngine/unity-engine/edge-collider2-d.sls | 8782fdcb4a1ef6018b4f5aaa1aebc3325af56028 | []
| 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,024 | sls | edge-collider2-d.sls | (library (unity-engine edge-collider2-d)
(export new
is?
edge-collider2-d?
reset
edge-count
point-count
points-get
points-set!
points-update!)
(import (ironscheme-clr-port))
(define-syntax new
(lambda (e)
(syntax-case e ()
((_ a ...) #'(clr-new UnityEngine.EdgeCollider2D a ...)))))
(define (is? a) (clr-is UnityEngine.EdgeCollider2D a))
(define (edge-collider2-d? a) (clr-is UnityEngine.EdgeCollider2D a))
(define-method-port
reset
UnityEngine.EdgeCollider2D
Reset
(System.Void))
(define-field-port
edge-count
#f
#f
(property:)
UnityEngine.EdgeCollider2D
edgeCount
System.Int32)
(define-field-port
point-count
#f
#f
(property:)
UnityEngine.EdgeCollider2D
pointCount
System.Int32)
(define-field-port
points-get
points-set!
points-update!
(property:)
UnityEngine.EdgeCollider2D
points
UnityEngine.Vector2[]))
| true |
f79f4758d2f7561fcf889a2ae304f823e8844660 | d369542379a3304c109e63641c5e176c360a048f | /brice/Chapter1/exercise-1.37.scm | f39244b66db8d40e69128ee47eedebb6aef6947b | []
| no_license | StudyCodeOrg/sicp-brunches | e9e4ba0e8b2c1e5aa355ad3286ec0ca7ba4efdba | 808bbf1d40723e98ce0f757fac39e8eb4e80a715 | refs/heads/master | 2021-01-12T03:03:37.621181 | 2017-03-25T15:37:02 | 2017-03-25T15:37:02 | 78,152,677 | 1 | 0 | null | 2017-03-25T15:37:03 | 2017-01-05T22:16:07 | Scheme | UTF-8 | Scheme | false | false | 2,784 | scm | exercise-1.37.scm | #lang racket
(require "../utils.scm")
; Exercise 1.37:
; a) An infinite continued fraction is an expression of the form
;
; f = N1
; ----------------------
; D1 + ⎧ N2 ⎫
; |---------------|
; ⎩D2 + ⎧ N3 ⎫⎭
; |--------|
; ⎩D3 + ...⎭
;
;
; As an example, one can show that the infinite continued fraction
; expansion with the Ni and the Di all equal to 1 produces 1/φ,
; where φ is the golden ratio (described in Section 1.2.2).
; One way to approximate an infinite continued fraction is to
; truncate the expansion afer a given number of terms. Such a
; truncation (a so-called k-term finite continued fraction)
; has the form
;
; f = N1
; ---------------
; D1 + ⎧ ... ⎫
; |--------|
; ⎩...+⎧Nk⎫⎭
; |--|
; ⎩Dk⎭
;
;
; Suppose that n and d are procedures of one argument
; (the term index i) that return the Ni and Di of the terms of
; the continued fraction. Define a procedure cont-frac such
; that evaluating (cont-frac n d k) computes the value of the
; k -term finite continued fraction. Check your procedure by
; approximating 1/φ using
#;(cont-frac
(lambda (i) 1.0)
(lambda (i) 1.0)
k)
; for successive values of k. How large must you make k in
; order to get an approximation that is accurate to 4 decimal places?
(define (cont-frac n d k)
(define (intern i)
(if (> k i)
(/ (n i) (+ (d i) (intern (inc i))))
(/ (n i) (d i))))
(intern 1))
; let's work out how big k need to be...
(define (rphi k)
(cont-frac (lambda (i) 1.0) (lambda (i) 1.0) k))
(display (format "1/φ: ~a\n" (rphi 10))) ;-> 0.6180555555555556
(define reference 0.61803398875) ; 1/φ = 0.61803398875 (google)
(define tolerance 0.0001)
(define (calc-k f)
"Calculates the number of recursion needed to get
within tolerance of reference for function f"
(define (close-enough? v1 v2)
(< (abs (- v1 v2)) tolerance))
(define (intern n)
(if (close-enough? (f n) reference)
n
(intern (inc n))))
(intern 1)); from 1 to k
(calc-k rphi) ;-> 10
;-> k needed to get to 0.0001 of reference is 10
; b) If your cont-frac procedure generates a recursive process,
; write one that generates an iterative process. If it generates
; an iterative process, write one that generates a recursive process.
(define (cont-frac-iter n d k)
(define (intern i a)
(if (> i 0)
(intern (dec i) (/ (n k) (+ (d k) a)))
a))
(intern (dec k) (/ (n k) (d k))))
(define (rphi-iter k)
(cont-frac-iter (lambda (i) 1.0) (lambda (i) 1.0) k))
(calc-k rphi-iter) ;-> 10
(asserteq "k should be the same for recursive and iterative" (calc-k rphi-iter) (calc-k rphi))
(rphi 10)
(rphi-iter 10)
| false |
322478a24cfcebed2ce5964ee28ad3ad66c6657c | ec5b4a92882f80b3f62eac8cbd059fb1f000cfd9 | /higher-order/!tests/reverse-cps.ss | 56844c5b842b3ce63b94fef63e0041fdf232f90a | []
| no_license | ggem/alpa | ee35ffc91d9f4b1d540ce8b2207595813e488e5f | 4f53b888b5a5b4ffebd220c6e0458442325fbff2 | refs/heads/master | 2019-01-02T03:12:17.899768 | 2005-01-04T03:43:12 | 2005-01-04T03:43:12 | 42,612,681 | 0 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 449 | ss | reverse-cps.ss | ;;;
;;;
;;;
(define reverse-cps
(lambda (ls)
(reverse-cps-hlp ls (lambda (x) x))))
(define reverse-cps-hlp
(lambda (ls k)
(if (null? ls)
(k '())
(reverse-cps-hlp (cdr ls)
(lambda (v)
(append-cps v (cons (car ls) '()) k))))))
(define append-cps
(lambda (ls1 ls2 k)
(if (null? ls1)
(k ls2)
(append-cps (cdr ls1) ls2
(lambda (v)
(k (cons (car ls1) v)))))))
'(reverse-cps (make-list size 'unknown))
| false |
2efeaafc0aafb4bab412b4a52de0d7698c5c46e3 | bfff08ec416296ebf11ed9181789608f0836419c | /first-edition/defrecord-other-attempts/macro.scm | 1e1665ae12b67f049235b2e6f3ea899fff4354d0 | []
| no_license | kesava/eopl | 8c54bb024ee50478ce6f7835fa1f511236a64175 | 9c6cf32e9bdc6ff659ecb45feabaa38550e732a5 | refs/heads/master | 2022-01-24T15:21:30.826989 | 2021-12-27T02:23:36 | 2021-12-27T02:23:36 | 170,910,305 | 3 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 120 | scm | macro.scm | #lang racket
(require racket/syntax)
(define-syntax (quoted-foo stx)
#'"I am also foo, using #' instead of syntax") | true |
316b911c843b98eb90d953477df056dd4c9914d4 | 5667f13329ab94ae4622669a9d53b649c4551e24 | /vector/math.vector.base.scm | e4f338780a733a304372cbf2145dda279fcd2a8a | []
| no_license | dieggsy/chicken-math | f01260e53cdb14ba4807f7e662c9e5ebd2da4dda | 928c9793427911bb5bb1d6b5a01fcc86ddfe7065 | refs/heads/master | 2021-06-11T07:14:21.461591 | 2021-04-12T22:12:14 | 2021-04-12T22:12:14 | 172,310,771 | 2 | 1 | null | null | null | null | UTF-8 | Scheme | false | false | 416 | scm | math.vector.base.scm | (module math.vector.base (vector-ref!)
(import scheme
chicken.base
chicken.fixnum)
(define vector-ref!
(case-lambda
[(vs i thnk) (vector-ref! vs i thnk not)]
[(vs i thnk nothing?)
(define n (vector-length vs))
(define v (vector-ref vs i))
(if (nothing? v)
(let ([v (thnk)])
(vector-set! vs i v)
v)
v)])))
| false |
fa701302329e0749acf368555428ed7f0b99f103 | b68228b54470408e654a9fa0c47688936ab8bf6a | /1.18.scm | d5745791953fbd171557ea7643102fa08227b2ad | []
| no_license | l0stman/sicp | cd4aacb0f938f18701ab416400230b4fe042928a | 69f62c544de711a6fd57ef12fcde9bd7f92faf0c | refs/heads/master | 2021-01-02T08:47:14.733548 | 2011-03-24T10:15:45 | 2011-03-24T10:15:45 | 981,438 | 4 | 1 | null | null | null | null | UTF-8 | Scheme | false | false | 178 | scm | 1.18.scm | (define (* a b)
(define (iter a b res)
(cond ((= b 0) res)
((even? b) (iter (double a)
(halve b)
res))
(else (iter a (- b 1) (+ res a)))))
(iter a b 0)) | false |
ef59c56ff88f9345b36cc39118a2a3927f44fbc6 | defeada37d39bca09ef76f66f38683754c0a6aa0 | /mscorlib/system/reflection/reflection-type-load-exception.sls | dc71886f6b55bb03a62594079fe231999d78e74f | []
| 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,161 | sls | reflection-type-load-exception.sls | (library (system reflection reflection-type-load-exception)
(export new
is?
reflection-type-load-exception?
get-object-data
types
loader-exceptions)
(import (ironscheme-clr-port))
(define-syntax new
(lambda (e)
(syntax-case e ()
((_ a ...)
#'(clr-new
System.Reflection.ReflectionTypeLoadException
a
...)))))
(define (is? a)
(clr-is System.Reflection.ReflectionTypeLoadException a))
(define (reflection-type-load-exception? a)
(clr-is System.Reflection.ReflectionTypeLoadException a))
(define-method-port
get-object-data
System.Reflection.ReflectionTypeLoadException
GetObjectData
(System.Void
System.Runtime.Serialization.SerializationInfo
System.Runtime.Serialization.StreamingContext))
(define-field-port
types
#f
#f
(property:)
System.Reflection.ReflectionTypeLoadException
Types
System.Type[])
(define-field-port
loader-exceptions
#f
#f
(property:)
System.Reflection.ReflectionTypeLoadException
LoaderExceptions
System.Exception[]))
| true |
1450719653577b18a69e2b3dacb4858b8811b5d4 | bdcc255b5af12d070214fb288112c48bf343c7f6 | /rebottled/quaternion.sls | aa6cf2fcb3f1de2386b3d79c00383aae1f17a8f1 | []
| no_license | xaengceilbiths/chez-lib | 089af4ab1d7580ed86fc224af137f24d91d81fa4 | b7c825f18b9ada589ce52bf5b5c7c42ac7009872 | refs/heads/master | 2021-08-14T10:36:51.315630 | 2017-11-15T11:43:57 | 2017-11-15T11:43:57 | 109,713,952 | 5 | 1 | null | null | null | null | UTF-8 | Scheme | false | false | 11,046 | sls | quaternion.sls | #!chezscheme
;;; Port of quaternion.scm to R7RS Scheme, by Peter Lane, 2017.
;;; Original version Copyright (c) 2001-2002, Dorai Sitaram.
;;; All rights reserved.
;;; Permission to distribute and use this work for any
;;; purpose is hereby granted provided this copyright
;;; notice is included in the copy. This work is provided
;;; as is, with no warranty of any kind.
(library
(rebottled quaternion)
(export ; note: renames standard procedures for numbers to handle quaternions as well
(rename q-make-rectangular make-rectangular)
(rename q-make-polar make-polar)
(rename q-imag-part imag-part)
(rename q-magnitude magnitude)
(rename q-angle angle)
(rename q-number? number?)
(rename q-quaternion? quaternion?)
(rename q= =)
(rename q+ +)
(rename q- -)
(rename q* *)
(rename q/ /)
(rename qexp exp)
(rename qlog log)
(rename qexpt expt)
(rename qsqrt sqrt)
(rename qsin sin)
(rename qcos cos)
(rename qtan tan)
(rename qasin asin)
(rename qacos acos)
(rename qatan atan)
jmag-part
kmag-part
vector-part
colatitude
longitude
conjugate
unit-vector
dot-product
cross-product
)
(import (scheme base)
(scheme complex)
(scheme inexact))
(begin
(define-record-type <quaternion>
(make-quaternion w x y z)
quaternion?
(w quaternion-w)
(x quaternion-x)
(y quaternion-y)
(z quaternion-z))
;make-rectangular returns a plain real or
;a plain complex if some arguments are zero
(define q-make-rectangular
(lambda args
(let ((w 0) (x 0) (y 0) (z 0)
(n (length args)))
(when (> n 0)
(set! w (list-ref args 0)))
(when (> n 1)
(set! x (list-ref args 1)))
(when (> n 2)
(set! y (list-ref args 2)))
(when (> n 3)
(set! z (list-ref args 3)))
(when (> n 4)
(error 'make-rectangular "more than 4 args supplied"))
(if (= y z 0)
(make-rectangular w x)
(make-quaternion w x y z)))))
;real-part, etc, operate on reals and complexes too
(define q-real-part
(lambda (q)
(cond ((complex? q) (real-part q))
((quaternion? q) (quaternion-w q))
(else (error 'real-part "~a not a quaternion" q)))))
(define q-imag-part
(lambda (q)
(cond ((complex? q) (imag-part q))
((quaternion? q) (quaternion-x q))
(else (error 'imag-part "~a not a quaternion" q)))))
(define jmag-part
(lambda (q)
(cond ((complex? q) 0)
((quaternion? q) (quaternion-y q))
(else (error 'jmag-part "~a not a quaternion" q)))))
(define kmag-part
(lambda (q)
(cond ((complex? q) 0)
((quaternion? q) (quaternion-z q))
(else (error 'kmag-part "~a not a quaternion" q)))))
;vector part is quaternion minus its real part
(define vector-part
(lambda (q)
(q-make-rectangular 0 (q-imag-part q) (jmag-part q) (kmag-part q))))
;make-polar doesn't need colatitude (phi) and
;longitude (psi), in which case it returns plain
;complex
(define q-make-polar
(lambda (mu theta . phipsi)
(let ((phi 0) (psi 0) (n (length phipsi)))
(when (> n 0) (set! phi (list-ref phipsi 0)))
(when (> n 1) (set! psi (list-ref phipsi 1)))
(when (> n 2) (error 'make-polar
"more than 4 args supplied"))
(q-make-rectangular
(* mu (cos theta))
(* mu (sin theta) (cos phi))
(* mu (sin theta) (sin phi) (cos psi))
(* mu (sin theta) (sin phi) (sin psi))))))
(define q-magnitude
(lambda (q)
(sqrt (+ (expt (q-real-part q) 2)
(expt (q-imag-part q) 2)
(expt (jmag-part q) 2)
(expt (kmag-part q) 2)))))
(define q-angle
(lambda (q)
(atan (sqrt (+ (expt (q-imag-part q) 2)
(expt (jmag-part q) 2)
(expt (kmag-part q) 2)))
(q-real-part q))))
(define colatitude
(lambda (q)
(atan (sqrt (+ (expt (jmag-part q) 2)
(expt (kmag-part q) 2)))
(q-imag-part q))))
(define longitude
(lambda (q)
(atan (kmag-part q)
(jmag-part q))))
;the new number? must succeed on quaternions too
(define q-number?
(lambda (q)
(or (complex? q)
(quaternion? q))))
;in the quaternion language, quaternion?
;should return #t for all numbers, not just
;the quaternion structs
(define q-quaternion? q-number?)
(define q=
(lambda (q . qq)
(let ((w1 (q-real-part q))
(x1 (q-imag-part q))
(y1 (jmag-part q))
(z1 (kmag-part q)))
(let loop ((qq qq))
(or (null? qq)
(let ((q (car qq)))
(and (= (q-real-part q) w1)
(= (q-imag-part q) x1)
(= (jmag-part q) y1)
(= (kmag-part q) z1)
(loop (cdr qq)))))))))
(define q+
(lambda qq
(let loop ((qq qq) (w1 0) (x1 0) (y1 0) (z1 0))
(if (null? qq) (q-make-rectangular w1 x1 y1 z1)
(let ((q (car qq)))
(loop (cdr qq)
(+ w1 (q-real-part q))
(+ x1 (q-imag-part q))
(+ y1 (jmag-part q))
(+ z1 (kmag-part q))))))))
(define q-
(lambda (q . qq)
(let ((w1 (q-real-part q))
(x1 (q-imag-part q))
(y1 (jmag-part q))
(z1 (kmag-part q)))
(if (null? qq)
(q-make-rectangular (- w1) (- x1) (- y1) (- z1))
(let loop ((qq qq) (w1 w1) (x1 x1) (y1 y1) (z1 z1))
(if (null? qq)
(q-make-rectangular w1 x1 y1 z1)
(let ((q (car qq)))
(loop (cdr qq)
(- w1 (q-real-part q))
(- x1 (q-imag-part q))
(- y1 (jmag-part q))
(- z1 (kmag-part q))))))))))
(define q*
(lambda qq
(let loop ((qq qq) (w1 1) (x1 0) (y1 0) (z1 0))
(if (null? qq)
(q-make-rectangular w1 x1 y1 z1)
(let ((q (car qq)))
(let ((w2 (q-real-part q))
(x2 (q-imag-part q))
(y2 (jmag-part q))
(z2 (kmag-part q)))
(loop (cdr qq)
(- (* w1 w2) (* x1 x2) (* y1 y2) (* z1 z2))
(+ (* w1 x2) (* x1 w2) (* y1 z2) (- (* z1 y2)))
(+ (* w1 y2) (* y1 w2) (* z1 x2) (- (* x1 z2)))
(+ (* w1 z2) (* z1 w2) (* x1 y2) (- (* y1 x2))))))))))
;this will work on complexes too
(define conjugate
(lambda (q)
(q-make-rectangular (q-real-part q)
(- (q-imag-part q))
(- (jmag-part q))
(- (kmag-part q)))))
;note we use "right" division
(define q/
(lambda (q . qq)
(if (null? qq)
(cond ((complex? q) (/ q))
((quaternion? q)
(let ((n (let ((m (q-magnitude q))) (* m m))))
(q-make-rectangular
(/ (q-real-part q) n)
(- (/ (q-imag-part q) n))
(- (/ (jmag-part q) n))
(- (/ (kmag-part q) n)))))
(else (error '/ "~a not a quaternion" q)))
(let loop ((qq qq) (r q))
(if (null? qq)
r
(let ((q (car qq)))
(loop (cdr qq)
(q* r (q/ q)))))))))
(define unit-vector
(lambda (q)
(if (real? q) +i
(let ((v (vector-part q)))
(q* v
(q/ (q-magnitude v)))))))
;dot- and cross-product only accept
;vector quaternion arguments
(define dot-product
(lambda (q1 q2)
(unless (and (= (q-real-part q1) 0)
(= (q-real-part q2) 0))
(error 'dot-product "arguments ~a, ~a, are not vector quaternions"
q1 q2))
(- (q-real-part (q* q1 q2)))))
(define cross-product
(lambda (q1 q2)
(unless (and (= (q-real-part q1) 0)
(= (q-real-part q2) 0))
(error 'dot-product "arguments ~a, ~a, are not vector quaternions"
q1 q2))
(vector-part (q* q1 q2))))
;the following are all based on Maclaurin's series
(define qexp
(lambda (q)
(let ((w (q-real-part q))
(u (unit-vector q))
(v (q-magnitude (vector-part q))))
(q* (exp w)
(q+ (cos v) (q* u (sin v)))))))
(define qlog
(lambda (q)
(let ((w (q-real-part q))
(u (unit-vector q))
(v (q-magnitude (vector-part q))))
(q+ (* 1/2 (log (+ (expt w 2) (expt v 2))))
(q* u (atan v w))))))
(define qexpt
(lambda (q1 q2)
(qexp (q* (qlog q1) q2))))
(define qsqrt
(lambda (q)
(qexpt q 1/2)))
;real-valued sinh and cosh, which aren't in standard Scheme,
;are needed to define quat trig
(define sinh
(lambda (x)
(* 1/2 (- (exp x) (exp (- x))))))
(define cosh
(lambda (x)
(* 1/2 (+ (exp x) (exp (- x))))))
(define qsin
(lambda (q)
(let ((w (q-real-part q))
(u (unit-vector q))
(v (q-magnitude (vector-part q))))
(q+ (* (sin w) (cosh v))
(q* u (* (cos w) (sinh v)))))))
(define qcos
(lambda (q)
(let ((w (q-real-part q))
(u (unit-vector q))
(v (q-magnitude (vector-part q))))
(q- (* (cos w) (cosh v))
(q* u (* (sin w) (sinh v)))))))
(define qtan
(lambda (q)
(q* (qsin q) (q/ (qcos q)))))
(define qasin
(lambda (q)
(let ((u (unit-vector q)))
(q- (q* u (qlog (q+ (q* u q)
(qsqrt (q- 1 (q* q q))))))))))
(define qacos
(lambda (q)
(let ((u (unit-vector q)))
(q- (q* u (qlog (q+ q
(qsqrt (q- (q* q q) 1)))))))))
;2-argument atan remains same as before
(define qatan
(lambda (q . qq)
(let ((u (unit-vector q)))
(if (null? qq)
(q* 1/2 u (qlog (q* (q+ u q)
(q/ (q- u q)))))
(atan
;note: args must be real here!
q (car qq))))))
)) ; end of library
| false |
60dbbc76ac2042bc908f67b7a18ab51c83616fb8 | 58381f6c0b3def1720ca7a14a7c6f0f350f89537 | /Chapter 3/3.5/Ex3.72.scm | 2058dd698f34d1e55949d122f125140303c4fdc6 | []
| no_license | yaowenqiang/SICPBook | ef559bcd07301b40d92d8ad698d60923b868f992 | c8a0228ebf66d9c1ddc5ef1fcc1d05d8684f090a | refs/heads/master | 2020-04-19T04:03:15.888492 | 2015-11-02T15:35:46 | 2015-11-02T15:35:46 | null | 0 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 2,413 | scm | Ex3.72.scm | #lang racket
(define (print-n stream n)
(newline)
(if (= n 0)
(display "Done")
(begin (display (stream-first stream))
(print-n (stream-rest stream) (- n 1)))))
(define (integers-starting-from n)
(stream-cons n (integers-starting-from (+ n 1))))
(define integers (integers-starting-from 1))
(define (merge-weighted s1 s2 weight)
(cond ((stream-empty? s1) s2)
((stream-empty? s2) s1)
(else
(let* ((s1pair (stream-first s1))
(s2pair (stream-first s2))
(s1weight (weight s1pair))
(s2weight (weight s2pair)))
(cond ((< s1weight s2weight)
(stream-cons
s1pair
(merge-weighted (stream-rest s1) s2 weight)))
((> s1weight s2weight)
(stream-cons
s2pair
(merge-weighted s1 (stream-rest s2) weight)))
(else
(stream-cons
s1pair
(stream-cons s2pair
(merge-weighted (stream-rest s1) (stream-rest s2) weight)))))))))
(define (weighted-pairs s t weight)
(stream-cons
(list (stream-first s) (stream-first t))
(merge-weighted
(stream-map (lambda (x) (list (stream-first s) x))
(stream-rest t))
(weighted-pairs (stream-rest s) (stream-rest t) weight)
weight)))
(define (square x) (* x x))
(define (sum-square-pair pair) (+ (square (car pair))
(square (cadr pair))))
(define square-pairs-stream
(weighted-pairs integers integers sum-square-pair))
(define (sum-two-squares s)
(let* ((first-pair (stream-first s))
(second-pair (stream-first (stream-rest s)))
(third-pair (stream-first (stream-rest (stream-rest s))))
(w1 (sum-square-pair first-pair))
(w2 (sum-square-pair second-pair))
(w3 (sum-square-pair third-pair)))
(if (= w1 w2 w3)
(stream-cons
(list w1 first-pair second-pair third-pair)
(sum-two-squares (stream-rest (stream-rest (stream-rest s)))))
(sum-two-squares (stream-rest s)))))
(define numbers (sum-two-squares square-pairs-stream))
(print-n numbers 5)
;(325 (1 18) (6 17) (10 15))
;(425 (5 20) (8 19) (13 16))
;(650 (5 25) (11 23) (17 19))
;(725 (7 26) (10 25) (14 23))
;(845 (2 29) (13 26) (19 22)) | false |
71d0bda86a598724c37e33b05dda84135415c47c | d47ddad953f999e29ce8ef02b059f945c76a791e | /lab2-and-3/homework4/set-intersect.scm | 46570723a17347d9428671ce46e1a583dec30a3f | []
| no_license | IvanIvanov/fp2013 | 7f1587ef1f2261f8cd0cd3dd99ec147c4043a2ae | 2ac1bb1102cb65e0ecbfa8d2fb3ca69953ae4ecf | refs/heads/master | 2016-09-11T10:08:59.873239 | 2014-01-23T20:38:27 | 2014-01-23T20:40:34 | 13,211,029 | 5 | 2 | null | 2014-01-10T15:55:14 | 2013-09-30T09:18:33 | Scheme | UTF-8 | Scheme | false | false | 2,248 | scm | set-intersect.scm | ; contains? със стандартна рекурсия
; накрая изразът, който се оценява изглежда така:
; ако елементът се среща някъде из списъка - (or #f (or #f (or #t (or #f #f))))
; ако елементът не се среща, ще бъде само (or) от #f
(define (contains? l elem)
(cond
( (null? l) #f)
(else (or (= (car l) elem) (contains? (cdr l) elem)))))
; Връща списък от само-уникалните елементи в l
(define (unique l)
(define (unique-iter l result)
(cond
( (null? l) result )
( (contains? result (car l)) (unique-iter (cdr l) result))
(else (unique-iter (cdr l) (cons (car l) result)))))
(reverse (unique-iter l (list))))
; selection sort от http://cs.gmu.edu/~white/CS363/Scheme/SchemeSamples.html
(define (selection L)
(cond ( (null? L) '() )
( else (cons (smallest L (car L)) ; put the smallest element
; at the front of the
; current list
(selection (remove L (smallest L (car L)))))
; call selection on the list
; minus the smallest
; element
)
)
)
(define (remove L A) ; remove the first occurance of atom A from L
(cond ( (null? L) '() )
( (= (car L) A) (cdr L)) ; Match found!
(else (cons (car L)(remove (cdr L) A))) ; keep searching
)
)
(define (smallest L A) ; looks for the smallest element in the list
; atom A is the current smallest
(cond ( (null? L) A)
( (< (car L) A) (smallest (cdr L)(car L)))
(else (smallest (cdr L) A ))
)
)
(define (set-intersect l1 l2)
(define (set-intersect-iter l1 l2 result)
(cond
( (null? l1) result )
( (contains? l2 (car l1)) (set-intersect-iter (cdr l1) l2 (cons (car l1) result)) )
(else (set-intersect-iter (cdr l1) l2 result))))
(selection (unique (set-intersect-iter l1 l2 (list)))))
| false |
ed23df392bc989d52fc5197200d0d4d6c2221331 | 86a7d9ada5a7978cc6b3dc51c73a61abf82a6023 | /src/sys.ss | 75783711f8ed027b889d2fefe12710034579b22f | []
| no_license | themetaschemer/rackscad | 6b249559ae9dbced4c12d3562284a41ab0265fe4 | 8915919c24bb93a63d13546610871bd11a823411 | refs/heads/master | 2021-06-26T07:31:04.723127 | 2017-09-15T15:32:41 | 2017-09-15T15:32:41 | 103,672,527 | 0 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 1,367 | ss | sys.ss | #lang racket
(require "utils.ss")
(require racket/include)
(require rackunit)
(define/provide (bin-paths)
(case (system-type 'os)
((unix windows) (string-split (getenv "PATH") ":"))
((macosx) (cons "/Applications/OpenSCAD.app/Contents/MacOS" (string-split (getenv "PATH") ":")))))
(define/provide (find-executable name #:case-sensitive [case-sensitive #f])
(or
(call/cc (λ (return)
(for*/fold ([found? #f]) ([dir (bin-paths)]
[p (if (directory-exists? dir) (directory-list dir) '())])
(let ([path-string (path->string p)])
(if (if (not case-sensitive)
(equal? (string-downcase name) (string-downcase path-string))
(equal? name path-string))
(return (build-path dir p))
found?)))))
(error 'find-executable "Could not find executable: ~a~%" name)))
(define-syntax/provide (define-shell-command x)
(syntax-case x ()
[(_ name filename)
#'(define-syntax (name y)
(syntax-case y ()
[(name #:path)
#'(find-executable filename)]
[(name arg (... ...))
#'(let ([cmd (++ #:separator " " (find-executable filename) arg (... ...))])
(system cmd))]
))]))
(include "sys-tests.ss")
| true |
8dad37bba47da8cc85409ca6bb693755bea0c4ec | 5eb631d9a0885a550b709c6e9f905066f6af531b | /ex/chap2/25.scm | dc9f0397bf26ed9c110340df672b31434b77bbd1 | []
| no_license | hanpum/sicp | 344cb6456daf2c2f6b002aa20dc3e177c34b18bd | 454efaf28ee0f0487e372ede28f452eb762de404 | refs/heads/master | 2023-06-09T08:11:55.080048 | 2021-06-29T00:01:49 | 2021-06-29T00:01:49 | 381,190,193 | 0 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 310 | scm | 25.scm | (load "utils")
(define a (list 1 2 (list 5 7 9)))
(println "input: ~S, output: ~S" a (car (cdaddr a)))
(define b (list (list 7)))
(println "input: ~S, output: ~S" b (caar b))
(define c (list 1 (list 2 (list 3 (list 4 (list 5 (list 6 7)))))))
(println "input: ~S, output: ~S" c (cadadr (cadadr (cadadr c))))
| false |
f12d014c42562393e5402871a713a23b6719b31c | 0768e217ef0b48b149e5c9b87f41d772cd9917f1 | /demo/widget-demo.scm | 435769c25b62f77f01b5d2cebcc340f830d22adb | [
"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 | 2,159 | scm | widget-demo.scm | ;; ./ypsilon --r6rs --top-level-program demo/widget-demo.scm
(import (core)
(ypsilon glcorearb)
(ypsilon glfw)
(ypsilon view)
(ypsilon widget)
(ypsilon c-ffi)
(ypsilon c-types))
(define error-callback
(lambda (error description)
(format #t "error: ~a~%~!" (utf8->string (make-bytevector-mapping description 1024)))))
(define key-callback
(lambda (window key scancode action mods)
(and (= key GLFW_KEY_ESCAPE)
(= action GLFW_PRESS)
(glfwSetWindowShouldClose window GLFW_TRUE))))
(define main
(lambda ()
(glfwSetErrorCallback (c-callback void (int void*) error-callback))
(let ((window (init-window 512 192 "Ypsilon")))
(glfwSetKeyCallback window (c-callback void (void* int int int int) key-callback))
(glfwMakeContextCurrent window)
(glfwSwapInterval 1)
(glEnable GL_BLEND)
(glBlendFunc GL_SRC_ALPHA GL_ONE_MINUS_SRC_ALPHA)
(let ()
(define widget0 (make-text-widget "demo/Roboto-Regular.ttf" 300))
(define m (make-bytevector 64))
(define p (make-bytevector 64))
(define mvp (make-bytevector 64))
(define width (make-c-int 0))
(define height (make-c-int 0))
(let loop ()
(cond ((> (glfwWindowShouldClose window) 0)
(glfwDestroyWindow window) (glfwTerminate) (exit 0))
(else
(glfwGetFramebufferSize window width height)
(glViewport 0 0 (c-int-ref width) (c-int-ref height))
(let ((ratio (/ (inexact (c-int-ref width)) (inexact (c-int-ref height)))))
(mat4x4-ortho p (- ratio) ratio -1 1 1 -1))
(mat4x4-identity m)
(mat4x4-rotate m m 0 0 -1 (glfwGetTime))
(mat4x4-mul mvp p m)
(glClear GL_COLOR_BUFFER_BIT)
(widget0 mvp 0.2 1.0 0.4 1.0 -1.80 0.2 0.3 "The quick brown fox jumps")
(widget0 mvp 0.2 1.0 0.4 1.0 -1.15 -0.2 0.3 "over the lazy dog.")
(glfwSwapBuffers window)
(glfwPollEvents)
(loop))))))))
(main)
| false |
a284f8e3ec9c9673ada60cb67a5c1b8ad824a552 | 923209816d56305004079b706d042d2fe5636b5a | /sitelib/http/request-uri.scm | b09eb082324e19b06ce0753aff04b32f4cf1f39b | [
"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 | 394 | scm | request-uri.scm | (library (http request-uri)
(export Request-URI)
(import (rnrs (6))
(http abnf)
(only (http uri) absoluteURI)
(only (http uri authority) authority)
(only (http uri path) abs_path))
;;; 5.1.2 Request-URI
;; Request-URI = "*" | absoluteURI | abs_path | authority
(define Request-URI (bar (char->rule #\*) absoluteURI abs_path authority))
)
| false |
470af9178621d7ab27a3f5b0a2c4ef8f8e380f8e | 79955bb9083a947c38d202cfa5a7fa2c7ef5f2cf | /ch3.41-concurrency.scm | 2a019be5bd630f5ed33433a74d4df89f1a788dd0 | []
| no_license | vujadetech/YASR | feba5cc9573ff45f55054f874eede1c9a88608d7 | 31ee98e4a8f168fce20261e07987a8d1a704e73b | refs/heads/master | 2020-05-02T17:34:33.405727 | 2019-05-26T02:42:16 | 2019-05-26T02:42:16 | 178,103,249 | 0 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 1,085 | scm | ch3.41-concurrency.scm | #lang racket/base
; "Thunk in the trunk!" (ok I stole that joke from the title of
; an episode of Modern Family. You know a show's funny when
; you're laughing from the title alone.)
(require "modules/utils-vujadeTech.rkt"
"modules/stream.rkt"
;racket/stream
)
(define (parallel-execute . procs)
(map thread-wait (map thread procs)))
(define (stream-filter-primes a b)
(stream-car
(stream-cdr
(stream-filter prime?
(stream-enumerate-interval a b)))))
(define (test n)
(let ([x 10])
(define (run)
(define p1 (lambda () (set! x (* x (++ x)))))
(define p2 (lambda () (set! x (+ x (* x (/ 1 x))))))
; (define p3 (λ () (sleep 0.1)(set! x (- x 1))))
(define ps (list p1 p2))
(apply parallel-execute ps)
; (display x)
;(apply parallel-execute (reverse ps))
(display x)(display " "))
(unless (zero? n)
(run)
(test (-- n))
)
)
)
#;(module joke ch3.41-concurrency
(display "Thunk in the trunk!"))
;(list->values (repeat (test) 5))
(test 10)
| false |
e4471114cb87209038515eeaaac1e90a77647229 | 29b17c2b8d6983198caf5e620dae0da98610b2a6 | /Compiler/lift-letrec.ss | 0848ba8a046cc8e3c7a4b146db97036b8d3a73f3 | []
| no_license | daaasbu/Scheme-Compiler-x86 | ec3f4cd3e2c94c965c0e53ebb45e1a41627dc090 | df971488bbac985479b2d2a516e3f9e566892c61 | HEAD | 2016-09-06T08:28:51.083237 | 2015-03-14T03:08:13 | 2015-03-14T03:08:13 | 32,192,637 | 0 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 2,211 | ss | lift-letrec.ss | (library (Compiler lift-letrec)
(export lift-letrec)
(import
(chezscheme)
(source-grammar)
(Framework helpers)
(Framework nanopass))
(define-pass lift-letrec : LintroduceProcedurePrimitives (x) -> LliftLetrec ()
(definitions
(define bindings '())
)
(Expr : Expr (x) -> Expr ()
[(letrec ([,l* ,[le*]] ...) ,[expr])
(begin
(set! bindings (append (map cons l* le*) bindings))
`,expr)])
(Expr2 : Expr (x) -> Prog ()
[(letrec ([,l* ,[le*]] ...) ,[expr]) (begin
(set! bindings (append (map cons l* le*) bindings))
(let ((l* (map (lambda (x) (car x)) bindings))
(le* (map (lambda (x) (cdr x)) bindings)))
`(letrec ([,l* ,le*] ...) ,expr)))]
[,l (let ((l* (map (lambda (x) (car x)) bindings))
(le* (map (lambda (x) (cdr x)) bindings)))
`(letrec ([,l* ,le*] ...) ,l))]
[,uv (let ((l* (map (lambda (x) (car x)) bindings))
(le* (map (lambda (x) (cdr x)) bindings)))
`(letrec ([,l* ,le*] ...) ,uv))]
[(quote ,i) (let ((l* (map (lambda (x) (car x)) bindings))
(le* (map (lambda (x) (cdr x)) bindings)))
`(letrec ([,l* ,le*] ...) (quote ,i)))]
[(if ,[expr0] ,[expr1] ,[expr2]) (let ((l* (map (lambda (x) (car x)) bindings))
(le* (map (lambda (x) (cdr x)) bindings)))
`(letrec ([,l* ,le*] ...) (if ,expr0 ,expr1 ,expr2)))]
[(begin ,[expr*] ... ,[expr]) (let ((l* (map (lambda (x) (car x)) bindings))
(le* (map (lambda (x) (cdr x)) bindings)))
`(letrec ([,l* ,le*] ...) (begin ,expr* ... ,expr)))]
[(let ([,uv* ,[expr*]] ...) ,[expr]) (let ((l* (map (lambda (x) (car x)) bindings))
(le* (map (lambda (x) (cdr x)) bindings)))
`(letrec ([,l* ,le*] ...) (let ([,uv* ,expr*] ...) ,expr)))]
[(,prim ,[expr*] ...) (let ((l* (map (lambda (x) (car x)) bindings))
(le* (map (lambda (x) (cdr x)) bindings)))
`(letrec ([,l* ,le*] ...) (,prim ,expr* ...)))]
[(call ,[expr] ,[expr*] ...) (let ((l* (map (lambda (x) (car x)) bindings))
(le* (map (lambda (x) (cdr x)) bindings)))
`(letrec ([,l* ,le*] ...) (call ,expr ,expr* ...)))]))) | false |
b5747c4ad71f7f2602681bf0a9e8c2944063ca89 | ce567bbf766df9d98dc6a5e710a77870753c7d29 | /ch6/12.scm | 0c8ad0d43fe0121afdfab9325bb0c923489199f3 | []
| 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 | 324 | scm | 12.scm | ;; Determine whether each of the following expressions is simple.
;; -((f -(x, 1)), 1)
;; --> simple-exp
;; (f -(-(x,y), 1))
;; --> simple-exp
;; if zero?(x) then -(x, y) else -(-(x, y), 1)
;; --> simple-exp
;; let x = proc(y) (y x) in -(x, 3)
;; --> not simple-exp
;; let f = proc(x) x in (f 3)
;; --> simple-exp
;;
| false |
17c160172534d871a57add913ffad86c7aeea25e | 018a7ce673c5be3cf3df61bd5c5036581d6646a7 | /spec/literals.scm | 1772137ff8383d42ee2d84a8971806f5f3200e5c | [
"MIT"
]
| permissive | iwillspeak/feersum | e857deec2b8683960f9ac6d1f395fb5f625204a8 | 1602e8333aa11c0335c9775c0ab49bf01389ba98 | refs/heads/main | 2023-08-07T17:15:19.843607 | 2023-06-20T06:28:28 | 2023-06-20T06:28:28 | 223,348,583 | 31 | 2 | MIT | 2023-06-10T21:29:11 | 2019-11-22T07:33:04 | F# | UTF-8 | Scheme | false | false | 25 | scm | literals.scm | 1
"hello world"
#t
#f
123 | false |
c820321fbb38024ff5537f51ca2aa7e68ce52d17 | 3c9983e012653583841b51ddfd82879fe82706fb | /experiments/precedence-parsing.scm | 823a9c3aac2c98dfab613b10f51c447fc777fd83 | []
| no_license | spdegabrielle/smalltalk-tng | 3c3d4cffa09541b75524fb1f102c7c543a84a807 | 545343190f556edd659f6050b98036266a270763 | refs/heads/master | 2020-04-16T17:06:51.884611 | 2018-08-07T16:18:20 | 2018-08-07T16:18:20 | 165,763,183 | 1 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 1,631 | scm | precedence-parsing.scm | (define table '((== non 4)
(: right 5)
(++ right 5)
(+ left 6)
(- left 6)
(* left 7)
(/ left 7)))
(define (parse exp)
(define (p-op lhs exp min-precedence k)
;;(write `(p-op ,lhs ,exp ,min-precedence)) (newline)
(if (null? exp)
(k lhs exp)
(let ((op (car exp))
(rest0 (cdr exp)))
(cond
((assq op table) =>
(lambda (entry)
(let ((fixity (cadr entry))
(prec (caddr entry)))
(if (>= prec min-precedence)
(p-val rest0
(lambda (rhs rest)
(let loop ((rhs rhs)
(rest rest))
;;(write `(loop ,rhs ,rest)) (newline)
(if (null? rest)
(k `(,op ,lhs ,rhs) rest)
(let ((lookahead (car rest)))
(cond
((assq lookahead table) =>
(lambda (lentry)
(let ((lfixity (cadr lentry))
(lprec (caddr lentry)))
(if (or (and (eq? lfixity 'right) (= lprec prec))
(> lprec prec))
(p-op rhs rest lprec loop)
(p-op `(,op ,lhs ,rhs) rest min-precedence k)))))
(else (loop `(app ,rhs ,lookahead) (cdr rest))
;; (p-op rhs rest min-precedence
;; (lambda (v r)
;; ;;(write `(loop-n ,v ,r)) (newline)
;; (k `(,op ,lhs ,v) r)))
)))))))
(k lhs exp)))))
(else (p-op `(app ,lhs ,op) rest0 min-precedence k))))))
(define (p-val exp k)
(k (car exp) (cdr exp)))
(p-val exp (lambda (lhs rest)
(p-op lhs rest 0 (lambda (result rest)
(list 'result! result rest))))))
(write (parse '(1 + 2 + 2.5 : 3 * 4 y z * 6 : a : b : c)))
;;(write (parse '(1 + 2 : 3 * 4 * 6 : foo)))
(newline)
| false |
48987572e536ba900aed245ecf7514d1625bf8db | f4cf5bf3fb3c06b127dda5b5d479c74cecec9ce9 | /Sources/LispKit/Resources/Libraries/srfi/46.sld | a2c6906cf02ed7c51903a809d6183ec934437f8b | [
"Apache-2.0"
]
| permissive | objecthub/swift-lispkit | 62b907d35fe4f20ecbe022da70075b70a1d86881 | 90d78a4de3a20447db7fc33bdbeb544efea05dda | refs/heads/master | 2023-08-16T21:09:24.735239 | 2023-08-12T21:37:39 | 2023-08-12T21:37:39 | 57,930,217 | 356 | 17 | Apache-2.0 | 2023-06-04T12:11:51 | 2016-05-03T00:37:22 | Scheme | UTF-8 | Scheme | false | false | 1,080 | sld | 46.sld | ;;; SRFI 46
;;; Basic Syntax-rules Extensions
;;;
;;; This SRFI proposes two extensions to the R5RS1 syntax-rules pattern language:
;;; the first allows syntax-rules macros to generate macros, where the macro-generated
;;; macros use ellipsis that is not used by the macro-generating macros; the second allows
;;; for 'tail patterns.'
;;;
;;; Author of spec: Taylor Campbell
;;;
;;; Copyright © 2019 Matthias Zenger. All rights reserved.
;;;
;;; Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
;;; except in compliance with the License. You may obtain a copy of the License at
;;;
;;; http://www.apache.org/licenses/LICENSE-2.0
;;;
;;; Unless required by applicable law or agreed to in writing, software distributed under the
;;; License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
;;; either express or implied. See the License for the specific language governing permissions
;;; and limitations under the License.
(define-library (srfi 46)
(export syntax-rules)
(import (lispkit core))
)
| false |
0d2f02bc38d2971312c3e8be178c586a93914b8b | 77f0eef0782195c4d90f97675b605da300fe270a | /src/tests/test-unary-primitives.scm | a042829d17661237d0ecafb5cc8f55c464d61b33 | []
| no_license | boraseoksoon/scheme_x86 | a36a273d99195e6203b45641b6cafb4a92c37818 | 2a02cde1e482bc4be73ad460c97d643a4ea0e2e0 | refs/heads/master | 2022-03-16T12:08:59.743217 | 2019-11-23T16:44:19 | 2019-11-23T16:44:19 | null | 0 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 3,853 | scm | test-unary-primitives.scm | (add-tests-with-string-output "prim-apply add1"
[(prim-apply add1 1) => "2\n"]
[(prim-apply add1 0) => "1\n"]
[(prim-apply add1 -1) => "0\n"]
[(prim-apply add1 536870910) => "536870911\n"]
[(prim-apply add1 -536870912) => "-536870911\n"]
[(prim-apply add1 (prim-apply add1 0)) => "2\n"])
(add-tests-with-string-output "prim-apply sub1"
[(prim-apply sub1 2) => "1\n"]
[(prim-apply sub1 1) => "0\n"]
[(prim-apply sub1 0) => "-1\n"]
[(prim-apply sub1 -1) => "-2\n"]
[(prim-apply sub1 536870911) => "536870910\n"]
[(prim-apply sub1 -536870911) => "-536870912\n"]
[(prim-apply sub1 (prim-apply sub1 2)) => "0\n"])
(add-tests-with-string-output "prim-apply fixnum->char and prim-apply char->fixnum"
[(prim-apply fixnum->char 65) => "#\\A\n"]
[(prim-apply fixnum->char 97) => "#\\a\n"]
[(prim-apply fixnum->char 122) => "#\\z\n"]
[(prim-apply fixnum->char 90) => "#\\Z\n"]
[(prim-apply fixnum->char 48) => "#\\0\n"]
[(prim-apply fixnum->char 57) => "#\\9\n"]
[(prim-apply char->fixnum #\A) => "65\n"]
[(prim-apply char->fixnum #\a) => "97\n"]
[(prim-apply char->fixnum #\z) => "122\n"]
[(prim-apply char->fixnum #\Z) => "90\n"]
[(prim-apply char->fixnum #\0) => "48\n"]
[(prim-apply char->fixnum #\9) => "57\n"]
[(prim-apply char->fixnum (prim-apply fixnum->char 12)) => "12\n"]
[(prim-apply fixnum->char (prim-apply char->fixnum #\x)) => "#\\x\n"])
(add-tests-with-string-output "prim-apply zero?"
[(prim-apply zero? 0) => "#t\n"]
[(prim-apply zero? 1) => "#f\n"]
[(prim-apply zero? -1) => "#f\n"]
[(prim-apply zero? 64) => "#f\n"]
[(prim-apply zero? 960) => "#f\n"])
(add-tests-with-string-output "fixnum?"
[(prim-apply fixnum? 0) => "#t\n"]
[(prim-apply fixnum? 1) => "#t\n"]
[(prim-apply fixnum? -1) => "#t\n"]
[(prim-apply fixnum? 37287) => "#t\n"]
[(prim-apply fixnum? -23873) => "#t\n"]
[(prim-apply fixnum? 536870911) => "#t\n"]
[(prim-apply fixnum? -536870912) => "#t\n"]
[(prim-apply fixnum? #t) => "#f\n"]
[(prim-apply fixnum? #f) => "#f\n"]
[(prim-apply fixnum? ()) => "#f\n"]
[(prim-apply fixnum? #\Q) => "#f\n"]
[(prim-apply fixnum? (prim-apply fixnum? 12)) => "#f\n"]
[(prim-apply fixnum? (prim-apply fixnum? #f)) => "#f\n"]
[(prim-apply fixnum? (prim-apply fixnum? #\A)) => "#f\n"]
[(prim-apply fixnum? (prim-apply char->fixnum #\r)) => "#t\n"]
[(prim-apply fixnum? (prim-apply fixnum->char 12)) => "#f\n"])
(add-tests-with-string-output "null?"
[(prim-apply null? ()) => "#t\n"]
[(prim-apply null? #f) => "#f\n"]
[(prim-apply null? #t) => "#f\n"]
[(prim-apply null? (prim-apply null? ())) => "#f\n"]
[(prim-apply null? #\a) => "#f\n"]
[(prim-apply null? 0) => "#f\n"]
[(prim-apply null? -10) => "#f\n"]
[(prim-apply null? 10) => "#f\n"])
(add-tests-with-string-output "boolean?"
[(prim-apply boolean? #t) => "#t\n"]
[(prim-apply boolean? #f) => "#t\n"]
[(prim-apply boolean? 0) => "#f\n"]
[(prim-apply boolean? 1) => "#f\n"]
[(prim-apply boolean? -1) => "#f\n"]
[(prim-apply boolean? ()) => "#f\n"]
[(prim-apply boolean? #\a) => "#f\n"]
[(prim-apply boolean? (prim-apply boolean? 0)) => "#t\n"]
[(prim-apply boolean? (prim-apply fixnum? (prim-apply boolean? 0))) => "#t\n"])
(add-tests-with-string-output "not"
[(prim-apply not #t) => "#f\n"]
[(prim-apply not (prim-apply null? '())) => "#f\n"])
(add-tests-with-string-output "char?"
[(prim-apply char? #\a) => "#t\n"]
[(prim-apply char? #\Z) => "#t\n"]
[(prim-apply char? #\newline) => "#t\n"]
[(prim-apply char? #t) => "#f\n"]
[(prim-apply char? #f) => "#f\n"]
[(prim-apply char? ()) => "#f\n"]
[(prim-apply char? (prim-apply char? #t)) => "#f\n"]
[(prim-apply char? 0) => "#f\n"]
[(prim-apply char? 23870) => "#f\n"]
[(prim-apply char? -23789) => "#f\n"])
| false |
ee1d595586a1c336e2c56641392fe90798dcf893 | 120324bbbf63c54de0b7f1ca48d5dcbbc5cfb193 | /packages/srfi/%3a2/and-let%2a.sls | dd0896875c1ede1b1bd7b66841d89623aea932f2 | [
"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 | 803 | sls | and-let%2a.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 :2 and-let*)
(export
and-let*)
(import
(rnrs))
(define-syntax and-let*
(syntax-rules ()
((_ . r)
(and-let*-core #T . r))))
(define-syntax and-let*-core
(lambda (stx)
(syntax-case stx ()
((kw _ ((var expr) . c) . b)
#'(let ((var expr))
(and var
(kw var c . b))))
((kw last ((expr) . c) . b)
#'(kw last ((t expr) . c) . b))
((kw _ (id . c) . b)
(identifier? #'id)
#'(and id
(kw id c . b)))
((_ last ())
#'last)
((_ _ () . b)
#'(let () . b)))))
)
| true |
e746f8ce28520b78524b91a9d987153a09e408ae | ae76253c0b7fadf8065777111d3aa6b57383d01b | /chap1/exec-1.46.ss | 13b35ac83e0bc29601f36c333e7648ef395777d5 | []
| no_license | cacaegg/sicp-solution | 176995237ad1feac39355f0684ee660f693b7989 | 5bc7df644c4634adc06355eefa1637c303cf6b9e | refs/heads/master | 2021-01-23T12:25:25.380872 | 2014-04-06T09:35:15 | 2014-04-06T09:35:15 | null | 0 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 634 | ss | exec-1.46.ss | (define (iterative-improve f-impr terminate?)
(define (iter guess)
(let ((next (f-impr guess)))
(if (terminate? guess next)
next
(iter next))))
(lambda (x) (iter x)))
(define (average x y) (/ (+ x y) 2.0))
(define (sqrt n)
(define (improve guess)
(average guess (/ n guess)))
(define (good-enough? dummy next)
(< (abs (- (* next next) n)) 0.001))
((iterative-improve improve good-enough?) 1))
(sqrt 9)
(define (fixed-point f first-guess)
(define tolerance 0.00001)
(define (close-enough? v1 v2)
(< (abs (- v1 v2)) tolerance))
((iterative-improve f close-enough?) first-guess))
(fixed-point cos 1.0)
| false |
c7f75ec3479ed0f877a2ed9e1a3d19f5df834fb7 | a8216d80b80e4cb429086f0f9ac62f91e09498d3 | /lib/scheme/vector/u16.sld | 25f86e268e658f086f37731153bc53bb481dabdd | [
"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 | 65 | sld | u16.sld |
(define-library (scheme vector u16) (alias-for (srfi 160 u16)))
| false |
9717c8e8e7055c0747380c79fadea6f12f8eaf15 | 378e5f5664461f1cc3031c54d243576300925b40 | /rsauex/packages/xorg.scm | c7fb4fa276ba341d555766108e1ea4ae6010f7e3 | []
| no_license | rsauex/dotfiles | 7a787f003a768699048ffd068f7d2b53ff673e39 | 77e405cda4277e282725108528874b6d9ebee968 | refs/heads/master | 2023-08-07T17:07:40.074456 | 2023-07-30T12:59:48 | 2023-07-30T12:59:48 | 97,400,340 | 2 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 1,479 | scm | xorg.scm | (define-module (rsauex packages xorg)
#:use-module ((gnu packages xorg) #:prefix xorg:)
#:use-module ((guix gexp))
#:use-module ((guix packages)))
;; Adopted from Alezost's config:
;; https://notabug.org/alezost/guix-config/commit/161d5e2e36e53c0d9c46181e10e1595e607748dd
(define-public libxfont2
(package
(inherit xorg:libxfont2)
(version (string-append (package-version xorg:libxfont2)
"-follow-symlinks"))
(arguments
'(#:phases
(modify-phases %standard-phases
(add-before 'configure 'patch-fonts-can-be-links
(lambda _
;; Fix the problem introduced by
;; <https://cgit.freedesktop.org/xorg/lib/libXfont/commit/?id=7b377456f95d2ec3ead40f4fb74ea620191f88c8>:
;; if "fonts.dir" is a symlink, do not ignore it as all
;; files in Guix profiles are symlinks!
(substitute* '("src/fontfile/dirfile.c"
"src/fontfile/fileio.c")
(("\\| ?O_NOFOLLOW") "")))))))
(synopsis (string-append (package-synopsis xorg:libxfont2)
" (with fixed fonts determination)"))))
(define-public xorg-server
(package
(inherit xorg:xorg-server)
(inputs (modify-inputs (package-inputs xorg:xorg-server)
(replace "libxfont2" libxfont2)))
(synopsis (string-append (package-synopsis xorg:xorg-server)
" (with my modifications)"))))
| false |
0fcc3d587a46b3e3581e140ad8de12054de53399 | 6b8bee118bda956d0e0616cff9ab99c4654f6073 | /suda-ex/matrixMul_kernel_1.scm | 5dbb108a491fce1d6c85df0f7999ed0bdd492f86 | []
| 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 | 2,568 | scm | matrixMul_kernel_1.scm | #lang typed-scheme
(require typed-scheme)
(define: BLOCK_SIZE : Integer 4)
; These are from matrixMul_h
;// Matrix dimensions
;// (chosen as multiples of the thread block size for simplicity)
(define: WA : Integer (* 3 BLOCK_SIZE)) ;// Matrix A width
(define: HA : Integer (* 5 BLOCK_SIZE)) ;// Matrix A height
(define: WB : Integer (* 8 BLOCK_SIZE)) ;// Matrix B width
(define: HB : Integer WA) ;// Matrix B height
(define: WC : Integer WB) ;// Matrix C width
(define: HC : Integer HA) ;// Matrix C height
(: matrix-mul-func
(Integer Integer Integer
(Listof Number) (Listof Number)
Keyword Keyword
->
(Listof umber)))
(define (matrix-mul-func wa ha wb A B C #:tq G
block-size #:bix bbi-x #:biy bbi-y #:kix kki-x #:kiy kki-y)
(let*
; Given Blkidx,
; index for submatrix A.
([aBegin (* wa block-size bbi-y)]
[aEnd (- (+ wa aBegin) 1)]
;step size
[aStep block-size]
; index for submatrix B.
[bBegin (* block-size bbi-x)]
[bEnd (- (+ wb bBegin) 1)]
[bStep (* wb block-size)]
; cSub
[Csub 0])
(for*/fold
([a aBegin] [b bBegin])
([(a b) (values (in-range aBegin aEnd aStep)
(in-range bBegin bEnd bStep))])
(let* (;store submatrix of A, B respectively
[As (build-array (shape 0 block-size 0 block-size) 0.0)]
[bS (build-array (shape 0 block-size 0 block-size) 0.0)]
;prepare indices for cpng submatrix into separate matrix
[a-ref (+ a (* wA tti-y) tti-x)]
[b-ref (+ b (* wB tti-y) tti-x)])
(copy-Array-elts (array-set! As tti-y tti-x) (array-ref A a-ref))
(copy-array-elts (array-set! Bs tti-y tti-x) (array-ref B b-ref))
(__syncthreads)
;; matrix Multiplication
(for/fold
([k 0])
([k (+ k 1)] #:when (< k block-size))
(set! Csub (+ Csub (* (array-ref As ty k) (array-ref Bs k tx)))))
;;Synch thread again.
(__syncthreads)))
(let ([c (+ (* wb block-size bbi-y) (block-size bbi-x))])
(vector-set! C (+ c (* wB tti-y) tti-x) Csub))))
;; currently one dimensional array is used for 2D matrix
(marix-mul-func WA HA WB A B C
#:tq 'G
4
#:bix bbi-x #:biy bbi-y
#:kix kki-x #:kiy kki-y) | false |
a84e60a1836da872efcb4078e610c5502fff53ca | d37f41737effcc07eb2bda1e3c4f54ac02aa7afa | /log2dls.ss | 9b8429f636ebeca681f91d053992e13849a4783e | []
| no_license | plt/planet-server | ea3cae6f59679e98df0cff1639fb4a0b12e821cd | a8074909b4c570b750a47e19d8d27d6c7c27ed92 | refs/heads/master | 2020-12-24T15:49:51.488474 | 2016-03-10T03:00:07 | 2016-03-10T03:00:07 | 4,863,599 | 1 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 2,561 | ss | log2dls.ss | (module log2dls mzscheme
(require (lib "port.ss")
(lib "match.ss")
(lib "list.ss")
(lib "date.ss"))
(provide (all-defined))
(define (read-all ip)
(let-values ([(pipe-in pipe-out) (make-pipe)])
(thread
(λ ()
(display #\( pipe-out)
(copy-port ip pipe-out)
(display #\) pipe-out)))
(begin0
(read pipe-in)
(close-input-port pipe-in)
(close-output-port pipe-out))))
;; ============================================================
;; general processing
(define (for-each-log-entry fn file)
(for-each (handle-one fn) (call-with-input-file file read-all)))
(define ((handle-one action) line)
(define (do owner pkg maj min ip time)
(action (list owner pkg maj min) (list ip time)))
(match line
[`(,ip-str ,path-str ,pkg ,maj ,min)
(let-values ([(rep owner) (path->owner/rep path-str)])
(when (string=? rep "300")
(do owner pkg maj min ip-str #f)))]
[`(,ip-str ,seconds ,path-str ,pkg ,maj ,min)
(let-values ([(rep owner) (path->owner/rep path-str)])
(when (string=? rep "300")
(do owner pkg maj min ip-str seconds)))]))
(define (path->owner/rep p)
(let ([ans (regexp-match #rx"^/root/planet/rep/([^/]+)/([^/]+)/" p)])
(unless ans
(error 'path->owner/rep "non-path string: " p))
(apply values (cdr ans))))
(define (hash-table-add! ht k v)
(hash-table-put! ht k (cons v (hash-table-get ht k (λ () '())))))
;; ============================================================
;; functions useful for examining old-style files
(define (read-to-ht file)
(define ht (make-hash-table 'equal))
(for-each-log-entry (λ (pkg item) (hash-table-add! ht pkg item)) file)
ht)
(define (get-tabulation h)
(sort (hash-table-map h (λ (k v) (list k (length v)))) (λ (a b) (< (cadr a) (cadr b)))))
(define (retab tabs)
(define ht (make-hash-table 'equal))
(for-each
(λ (i)
(let ([k (car i)]
[v (cadr i)])
(hash-table-add! ht (list (car k) (cadr k)) v)))
tabs)
(sort (hash-table-map ht (λ (k v) (list k (apply + v)))) (λ (a b) (> (cadr a) (cadr b)))))
;; ============================================================
;; functions useful for importing old-style to new-style logs
(define (format-date-to-sql secs)
(parameterize ([date-display-format 'iso-8601])
(date->string (seconds->date secs) #t)))
) | false |
098e9dfec12e9c2215207ffdd2004328b092a3ee | e1c580145992634f089af18940508f5c26d2e264 | /umcu/packages/nanosvc.scm | c88412c2ac75cfad73032cc7320d72c70452e2c4 | []
| no_license | inijman/guix-additions | 8542592972e644a4ccd7b36ad4dd9b5631008fb5 | b8e0e3f3b9598aade3103e9f491307fa06ece03d | refs/heads/master | 2021-07-13T21:35:25.731179 | 2020-05-28T14:01:04 | 2020-05-28T14:01:04 | 142,980,977 | 0 | 0 | null | 2018-07-31T07:49:53 | 2018-07-31T07:49:53 | null | UTF-8 | Scheme | false | false | 1,165 | scm | nanosvc.scm | (define-module (umcu packages nanosvc)
#:use-module (guix utils)
#:use-module ((guix licenses) #:prefix license:)
#:use-module (guix packages)
#:use-module (guix download)
#:use-module (guix build-system gnu)
#:use-module (gnu packages base)
#:use-module (gnu packages pkg-config)
#:use-module (gnu packages compression))
(define-public libinfra
(package
(name "libinfra")
(version "1.0.0")
(source (origin
(method url-fetch)
(uri (string-append
"https://github.com/roelj/libinfra/releases/download/v"
version "/libinfra-" version ".tar.gz"))
(sha256
(base32 "03yzab5jjaz1r2mfc2i790cwlldhxrvbr30slp9bcb0sbzkjn4c0"))))
(build-system gnu-build-system)
(home-page "https://github.com/roelj/libinfra")
(synopsis "Logging and timing library for C programs")
(description "This library provides a program and library-wide
infrastructure for functionality that is needed in various places.
Concretely, libinfra provides a file logging interface, and a timer
interface which is integrated with the logging interface.")
(license license:gpl3+)))
| false |
ff0009442ff9036bf584d4f4a8b457e2b722caec | b60cb8e39ec090137bef8c31ec9958a8b1c3e8a6 | /test/concurrentScheme/threads/tsp.scm | ee2e0404c1fc13bfca5f2ef77516d0649f68b7c7 | []
| no_license | acieroid/scala-am | eff387480d3baaa2f3238a378a6b330212a81042 | 13ef3befbfc664b77f31f56847c30d60f4ee7dfe | refs/heads/master | 2021-01-17T02:21:41.692568 | 2021-01-15T07:51:20 | 2021-01-15T07:51:20 | 28,140,080 | 32 | 16 | null | 2020-04-14T08:53:20 | 2014-12-17T14:14:02 | Scheme | UTF-8 | Scheme | false | false | 5,377 | scm | tsp.scm | ;; Example adapted from "Introduction to Parallel Programming", chapter 6
(define (build-vector n init f)
(letrec ((v (make-vector n init))
(loop (lambda (i)
(if (< i n)
(begin
(vector-set! v i (f i))
(loop (+ i 1)))
v))))
(loop 0)))
(define N (+ 6 (random 42)))
(define (make-cities N)
(build-vector N '()
(lambda (i)
(letrec ((loopj (lambda (j acc)
(if (= j N)
acc
(if (= i j)
(loopj (+ j 1) acc)
(loopj (+ j 1) (cons (cons j (random 100)) acc)))))))
(loopj 0 '())))))
(define cities
;; At index i, each cons cell represents the edge and their weight
(make-cities N))
(define (city-count tour) (length tour))
(define (cost-of from to)
(let ((alist (vector-ref cities from)))
(cdr (assoc to alist))))
(define (feasible tour to)
(if (and (< (city-count tour) (- N 1)) (= to 0))
#f
(let ((last-city (if (null? tour) 0 (last tour))))
(if (assoc to (vector-ref cities last-city))
(not (member to tour))
#f))))
(define (last l)
(if (null? l)
(error "last: empty list")
(if (null? (cdr l))
(car l)
(last (cdr l)))))
(define (tour-cost tour)
(define (helper t last-city cost)
(if (null? t)
cost
(helper (cdr t) (car t) (+ cost (cost-of last-city (car t))))))
(helper tour 0 0))
(define (add-city tour city)
(append tour (list city)))
(define (tsp-seq)
(define (helper stack best-tour best-cost)
(if (null? stack)
best-tour
(let ((curr-tour (car stack)))
(if (= (city-count curr-tour) N)
(let ((curr-cost (tour-cost curr-tour)))
(if (< curr-cost best-cost)
(helper (cdr stack) curr-tour curr-cost)
(helper (cdr stack) best-tour best-cost)))
(letrec ((loop (lambda (i stack)
(if (< i 0)
stack
(if (feasible curr-tour i)
(let ((curr-tour2 (add-city curr-tour i)))
(loop (- i 1) (cons curr-tour2 stack)))
(loop (- i 1) stack))))))
(helper (loop (- N 1) (cdr stack)) best-tour best-cost))))))
(helper '(()) '() 1000))
(define (enqueue elem q)
(append q (list elem)))
(define (dequeue q)
(car q))
(define (tsp nthreads)
(define best-tour (ref '()))
(define best-cost (ref 1000))
(define best-lock (new-lock))
(define (set-best-tour tour cost)
(acquire best-lock)
(if (< cost (deref best-cost))
(begin
(ref-set best-tour tour)
(ref-set best-cost cost))
#t)
(release best-lock))
(define (tsp-thread my-stack)
(if (null? my-stack)
'done
(let ((curr-tour (car my-stack)))
(if (= (city-count curr-tour) N)
(let ((curr-cost (tour-cost curr-tour)))
(if (< curr-cost (deref best-cost))
(set-best-tour curr-tour curr-cost)
#t)
(tsp-thread (cdr my-stack)))
(letrec ((loop (lambda (i my-stack)
(if (< i 0)
my-stack
(if (feasible curr-tour i)
(let ((curr-tour2 (add-city curr-tour i)))
(loop (- i 1) (cons curr-tour2 my-stack)))
(loop (- i 1) my-stack))))))
(tsp-thread (loop (- N 1) (cdr my-stack))))))))
(define (tsp-bootstrap queue)
(if (null? queue)
#t
(if (>= (length queue) nthreads)
(let ((threads (map (lambda (tour)
(fork (tsp-thread (list tour))))
queue)))
(map (lambda (t) (join t)) threads))
(let ((curr-tour (dequeue queue)))
(if (= (city-count curr-tour) N)
(let ((curr-cost (tour-cost curr-tour)))
(if (< curr-cost (deref best-cost))
(set-best-tour curr-tour curr-cost)
#t)
(tsp-bootstrap (cdr queue)))
(letrec ((loop (lambda (i queue)
(if (< i 0)
queue
(if (feasible curr-tour i)
(let ((curr-tour2 (add-city curr-tour i)))
(loop (- i 1) (enqueue curr-tour2 queue)))
(loop (- i 1) queue))))))
(tsp-bootstrap (loop (- N 1) (cdr queue)))))))))
(tsp-bootstrap '(()))
(deref best-tour))
(define nthreads (random 42))
(let ((tsp-sequential (fork (tsp-seq)))
(tsp-concurrent (fork (tsp nthreads))))
(equal? (join tsp-sequential) (join tsp-concurrent)))
| false |
87c77433d2c42f52d6e660f17eb652b42d587cde | 8f9b45f0ad99a668cf9b1e72830fe640e1105cc0 | /t/nitro.scm | 8027ae3ac6d7b0394e1b849e39c01a154571659a | []
| no_license | picrin-scheme/sulfuric | 56bbb5a01056c232b6b96e93e0e63af866088e75 | 7318dddfdf26b72a2c810246b8511e7d1ff9b70d | refs/heads/master | 2016-09-05T16:46:22.849594 | 2015-01-20T17:28:46 | 2015-01-20T17:28:46 | 29,534,762 | 3 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 749 | scm | nitro.scm | (load "./piclib/util.scm")
(load "./piclib/util/version.scm")
(load "./piclib/nitro.scm")
(import (scheme base)
(picrin test)
(sulfuric nitro))
(define-nitro sample-nitro
(license "MIT")
(authors "nyao" "nyan")
(version "0.0.1")
(dependencies (r7rs "1.0.0")
(other-nitro) ;version is not required
)
(summary "A sample nitro")
(description "This is a sample nitro ...
...
...")
(homepage "http://.....")
(base-dir "./")
#|
;; Or, if remote
(set! (fetch-from n) (git "https://github.com/picrin-scheme/swank-picrin.git")
|#
(src "/piclib/*.scm")
(c-src "/src/*.c")
(doc "/docs/*.rst")
(test "/test/*.scm")
(extra-files "/README.md" "/LICENSE"))
(write nitros)
| false |
28ff4d7a193daac301de3111839390c7d4c87093 | c42881403649d482457c3629e8473ca575e9b27b | /src/make-script.scm | aff212340550686957fa3db1193c628adad37ca2 | [
"BSD-2-Clause",
"BSD-3-Clause"
]
| permissive | kahua/Kahua | 9bb11e93effc5e3b6f696fff12079044239f5c26 | 7ed95a4f64d1b98564a6148d2ee1758dbfa4f309 | refs/heads/master | 2022-09-29T11:45:11.787420 | 2022-08-26T06:30:15 | 2022-08-26T06:30:15 | 4,110,786 | 19 | 5 | null | 2015-02-22T00:23:06 | 2012-04-23T08:02:03 | Scheme | UTF-8 | Scheme | false | false | 1,998 | scm | make-script.scm | ;;; -*- mode: scheme; coding: utf-8 -*-
;;; Generate a shell script to invoke kahua operations.
;;;
;;; Copyright (c) 2004-2007 Scheme Arts, L.L.C., All rights reserved.
;;; Copyright (c) 2004-2007 Time Intermedia Corporation, All rights reserved.
;;; See COPYING for terms and conditions of using this software
;;;
;; Example:
;;
;; % gosh ./make-script.scm $(GOSH) $(libdir) kahua-admin
;;
;; Creates a shell script kahua-admin that kicks kahua-admin.scm
;;
(define *ident* "make-script.scm")
(use file.util)
(use util.match)
(define (main args)
(match (cdr args)
((gosh libdir basename) (generate gosh libdir basename))
(else (usage)))
0)
(define (usage)
(print "gosh make-script.scm $GOSH $libdir <script-basename>")
(exit 0))
(define (generate gosh libdir basename)
(let ((tmpname #`",|basename|.tmp"))
(with-output-to-file tmpname
(lambda ()
(print "#!/bin/sh")
(print "# This script is a part of Kahua")
(print "# Generated by " *ident*)
(print "# Do not edit.")
(print "if test \"$1\" = \"--test\"; then")
(print " shift")
(print " # in-place execution. find source tree")
(print " if test -r ./kahua/config.scm.in; then")
(print " libpath=.")
(print " elif test -r ../src/kahua/config.scm.in; then")
(print " libpath=../src")
(print " elif test -r ../../src/kahua/config.scm.in; then")
(print " libpath=../../src")
(print " else")
(print " echo \"$0: Cannot locate kahua source tree\"")
(print " exit 1")
(print " fi")
(print "else")
(print " libpath=" libdir)
(print "fi")
(print "exec "gosh " -I${libpath} ${libpath}/"basename".scm"
" --gosh " gosh " ${confopt}"
" \"$@\""))
:if-exists :supersede)
(sys-rename tmpname basename)
(sys-chmod basename #o555)))
;; Local variables:
;; mode: scheme
;; end:
| false |
95c840826759eb5d669b8cb5503840c78bd381a9 | 382770f6aec95f307497cc958d4a5f24439988e6 | /projecteuler/686/686.scm | cd2101ab2efd3626165aeaaf4a1a47e6ca331331 | [
"Unlicense"
]
| permissive | include-yy/awesome-scheme | 602a16bed2a1c94acbd4ade90729aecb04a8b656 | ebdf3786e54c5654166f841ba0248b3bc72a7c80 | refs/heads/master | 2023-07-12T19:04:48.879227 | 2021-08-24T04:31:46 | 2021-08-24T04:31:46 | 227,835,211 | 1 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 1,303 | scm | 686.scm | (define n30 (expt 10 30))
(let pro ([i 0]
[curr-val 1]
[nth 0])
(cond
((= nth 90) '())
(else
(let ([now-str (number->string curr-val)])
(cond
((< (string-length now-str) 3)
(pro (+ i 1) (* curr-val 2) nth))
((and (char=? (string-ref now-str 0) #\1)
(char=? (string-ref now-str 1) #\2)
(char=? (string-ref now-str 2) #\3))
(cons i (pro (+ i 1) (* curr-val 2) (+ nth 1))))
(else
(pro (+ i 1) (* curr-val 2) nth)))))))
#|
(time (let pro ...))
579 collections
9.750000000s elapsed cpu time, including 0.015625000s collecting
9.757218300s elapsed real time, including 0.016198300s collecting
2447200744 bytes allocated, including 2447975880 bytes reclaimed
(90 379 575 864 1060 1545 1741 2030 2226 2515 2711 3000 3196
3681 3877 4166 4362 4651 4847 5136 5332 5817 6013 6302 6498
6787 6983 7272 7468 7953 8438 8634 8923 9119 9408 9604 10089
10574 10770 11059 11255 11544 11740 12225 12710 12906 13195
13391 13680 13876 14361 14846 15042 15331 15527 15816 16012
16301 16497 16982 17178 17467 17663 17952 18148 18437 18633
19118 19314 19603 19799 20088 20284 20573 20769 21254 21450
21739 21935 22224 22420 22709 22905 23390 23875 24071 24360
24556 24845 25041)
|#
;;too slow | false |
edd80a45fd47f28d462384643bada9836a075fc5 | b166064abe97092ba6138aa294386ccd632016d8 | /lib/rtmidi/ftype.sls | 2df16b2a4a3dfc8bb81cb7eeb8fb0edf640de399 | [
"MIT"
]
| permissive | Outcue/chez-rtmidi | 8259f6433cdf875cd5b75357d775742474eb333c | 9581356891b9fffe3cec69fd704dce94fe4fc088 | refs/heads/main | 2023-03-07T11:41:30.681905 | 2021-02-26T22:10:50 | 2021-02-26T22:10:50 | 341,785,884 | 1 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 5,033 | sls | ftype.sls | (library
(rtmidi ftype)
(export
RtMidiWrapper
RtMidiCCallback
RtMidiPtr
RtMidiInPtr
RtMidiOutPtr
RtMidiAPI_UNSPECIFIED
RtMidiAPI_MACOSX_CORE
RtMidiAPI_LINUX_ALSA
RtMidiAPI_UNIX_JACK
RtMidiAPI_WINDOWS_MM
RtMidiAPI_RtMidiDUMMY
RtMidiAPI_NUM
RtMidiERROR_WARNING
RtMidiERROR_DEBUG_WARNING
RtMidiERROR_UNSPECIFIED
RtMidiERROR_NO_DEVICES_FOUND
RtMidiERROR_INVALID_DEVICE
RtMidiERROR_MEMORY_ERROR
RtMidiERROR_INVALID_PARAMETER
RtMidiERROR_INVALID_USE
RtMidiERROR_DRIVER_ERROR
RtMidiERROR_SYSTEM_ERROR
RtMidiERROR_THREAD_ERROR
rtmidi_get_compiled_api
rtmidi_api_name
rtmidi_api_display_name
rtmidi_compiled_api_by_name
rtmidi_error
rtmidi_open_port
rtmidi_open_virtual_port
rtmidi_close_port
rtmidi_get_port_count
rtmidi_get_port_name
rtmidi_in_create_default
rtmidi_in_create
rtmidi_in_free
rtmidi_in_get_current_api
rtmidi_in_set_callback
rtmidi_in_cancel_callback
rtmidi_in_ignore_types
rtmidi_in_get_message
rtmidi_out_create_default
rtmidi_out_create
rtmidi_out_free
rtmidi_out_get_current_api
rtmidi_out_send_message)
(import
(chezscheme))
(define *rtmidi*
(case (machine-type)
((i3nt ti3nt a6nt ta6nt) (load-shared-object "rtmidi.dll"))
((i3le ti3le a6le ta6le) (load-shared-object "librtmidi.so"))
((i3osx ti3osx a6osx ta6osx) (load-shared-object "librtmidi.dylib"))))
(define-syntax rtmidi-procedure
(syntax-rules ()
((rtmidi-procedure name params return)
(if (foreign-entry? name)
(foreign-procedure name params return)
(lambda args
(error 'RTMIDI "Function not exported in librtmidi." name))))))
(define-ftype RtMidiPtr void*)
(define-ftype RtMidiInPtr void*)
(define-ftype RtMidiOutPtr void*)
(define RtMidiAPI_UNSPECIFIED 0)
(define RtMidiAPI_MACOSX_CORE 1)
(define RtMidiAPI_LINUX_ALSA 2)
(define RtMidiAPI_UNIX_JACK 3)
(define RtMidiAPI_WINDOWS_MM 4)
(define RtMidiAPI_RtMidiDUMMY 5)
(define RtMidiAPI_NUM 6)
(define RtMidiERROR_WARNING 0)
(define RtMidiERROR_DEBUG_WARNING 1)
(define RtMidiERROR_UNSPECIFIED 2)
(define RtMidiERROR_NO_DEVICES_FOUND 3)
(define RtMidiERROR_INVALID_DEVICE 4)
(define RtMidiERROR_MEMORY_ERROR 5)
(define RtMidiERROR_INVALID_PARAMETER 6)
(define RtMidiERROR_INVALID_USE 7)
(define RtMidiERROR_DRIVER_ERROR 8)
(define RtMidiERROR_SYSTEM_ERROR 9)
(define RtMidiERROR_THREAD_ERROR 10)
(define-ftype RtMidiWrapper
(struct
(ptr void*)
(data void*)
(ok boolean)
(msg (array 32 char))))
(define-ftype RtMidiCCallback
(function (double string size_t void*) void))
(define rtmidi_get_compiled_api (rtmidi-procedure "rtmidi_get_compiled_api" (u32* unsigned-32) int))
(define rtmidi_api_name (rtmidi-procedure "rtmidi_api_name" (int) string))
(define rtmidi_api_display_name (rtmidi-procedure "rtmidi_api_display_name" (int) string))
(define rtmidi_compiled_api_by_name (rtmidi-procedure "rtmidi_compiled_api_by_name" (string) int))
(define rtmidi_error (rtmidi-procedure "rtmidi_error" (int) string))
(define rtmidi_open_port (rtmidi-procedure "rtmidi_open_port" (RtMidiPtr unsigned-32 string) void))
(define rtmidi_open_virtual_port (rtmidi-procedure "rtmidi_open_virtual_port" (RtMidiPtr string) void))
(define rtmidi_close_port (rtmidi-procedure "rtmidi_close_port" (RtMidiPtr) void))
(define rtmidi_get_port_count (rtmidi-procedure "rtmidi_get_port_count" (RtMidiPtr) unsigned-32))
(define rtmidi_get_port_name (rtmidi-procedure "rtmidi_get_port_name" (RtMidiPtr unsigned-32) string))
(define rtmidi_in_create_default (rtmidi-procedure "rtmidi_in_create_default" () RtMidiInPtr))
(define rtmidi_in_create (rtmidi-procedure "rtmidi_in_create" (int string unsigned-32) RtMidiInPtr))
(define rtmidi_in_free (rtmidi-procedure "rtmidi_in_free" (RtMidiInPtr string) void))
(define rtmidi_in_get_current_api (rtmidi-procedure "rtmidi_in_get_current_api" (RtMidiPtr) int))
(define rtmidi_in_set_callback (rtmidi-procedure "rtmidi_in_set_callback" (RtMidiPtr (* RtMidiCCallback) void*) void))
(define rtmidi_in_cancel_callback (rtmidi-procedure "rtmidi_in_cancel_callback" (RtMidiInPtr) void))
(define rtmidi_in_ignore_types (rtmidi-procedure "rtmidi_in_ignore_types" (RtMidiInPtr boolean boolean boolean) void))
(define rtmidi_in_get_message (rtmidi-procedure "rtmidi_in_get_message" (RtMidiInPtr string size_t) double))
(define rtmidi_out_create_default (rtmidi-procedure "rtmidi_out_create_default" () RtMidiOutPtr))
(define rtmidi_out_create (rtmidi-procedure "rtmidi_out_create" (int string) RtMidiOutPtr))
(define rtmidi_out_free (rtmidi-procedure "rtmidi_out_free" (RtMidiOutPtr) void))
(define rtmidi_out_get_current_api (rtmidi-procedure "rtmidi_out_get_current_api" (RtMidiPtr) int))
(define rtmidi_out_send_message (rtmidi-procedure "rtmidi_out_send_message" (RtMidiOutPtr u8* int) int))
)
| true |
a752d06dfebb7719ff0dabb8657b54a96fac7db3 | bdcc255b5af12d070214fb288112c48bf343c7f6 | /r7b-util/port-open.sls | 4223687181fbe1287e7242435be1089286ec0964 | []
| no_license | xaengceilbiths/chez-lib | 089af4ab1d7580ed86fc224af137f24d91d81fa4 | b7c825f18b9ada589ce52bf5b5c7c42ac7009872 | refs/heads/master | 2021-08-14T10:36:51.315630 | 2017-11-15T11:43:57 | 2017-11-15T11:43:57 | 109,713,952 | 5 | 1 | null | null | null | null | UTF-8 | Scheme | false | false | 147 | sls | port-open.sls | #!chezscheme
(library (r7b-util port-open)
(export port-open?)
(import (rnrs))
;; FIXME:
(define (port-open? p) #t)
)
| false |
ce5c7306ba11629264adcaa6ba3db8227a884aff | df0ba5a0dea3929f29358805fe8dcf4f97d89969 | /exercises/informatics-2/03-tree-recursion/fibonacci.scm | 16c4552b54d48f448c29ab79a4d46e1940a4c031 | [
"MIT"
]
| permissive | triffon/fp-2019-20 | 1c397e4f0bf521bf5397f465bd1cc532011e8cf1 | a74dcde683538be031186cf18367993e70dc1a1c | refs/heads/master | 2021-12-15T00:32:28.583751 | 2021-12-03T13:57:04 | 2021-12-03T13:57:04 | 210,043,805 | 14 | 31 | MIT | 2019-12-23T23:39:09 | 2019-09-21T19:41:41 | Racket | UTF-8 | Scheme | false | false | 1,148 | scm | fibonacci.scm | (require rackunit rackunit/text-ui)
(define (fibonacci n)
(cond ((= n 0) 0)
((= n 1) 1)
(else (+ (fibonacci (- n 1))
(fibonacci (- n 2))))))
(define (fibonacci-iter n)
(define (iter current next count)
(if (= count n)
current
(iter next (+ current next) (+ count 1))))
(iter 0 1 0))
(define fibonacci-tests
(test-suite
"Tests for fibonacci"
(check = (fibonacci 0) 0)
(check = (fibonacci 1) 1)
(check = (fibonacci 2) 1)
(check = (fibonacci 3) 2)
(check = (fibonacci 4) 3)
(check = (fibonacci 5) 5)
(check = (fibonacci 6) 8)
(check = (fibonacci 7) 13)
(check = (fibonacci 20) 6765)))
(define fibonacci-iter-tests
(test-suite
"Tests for fibonacci-iter"
(check = (fibonacci-iter 0) 0)
(check = (fibonacci-iter 1) 1)
(check = (fibonacci-iter 2) 1)
(check = (fibonacci-iter 3) 2)
(check = (fibonacci-iter 4) 3)
(check = (fibonacci-iter 5) 5)
(check = (fibonacci-iter 6) 8)
(check = (fibonacci-iter 7) 13)
(check = (fibonacci-iter 20) 6765)))
(run-tests fibonacci-tests)
(run-tests fibonacci-iter-tests)
| false |
cd0937a9370a1f288da25d0693d0dd25499e1a7a | 6b8bee118bda956d0e0616cff9ab99c4654f6073 | /sdk-ex/cpyTestDrv/cpyTestDrv.ss | 72ea0711c0a5379f4745df846cbbe66aa4654374 | []
| no_license | skchoe/2012.Functional-GPU-Programming | b3456a92531a8654ae10cda622a035e65feb762d | 56efdf79842fc465770214ffb399e76a6bbb9d2a | refs/heads/master | 2016-09-05T23:42:36.784524 | 2014-05-26T17:53:34 | 2014-05-26T17:53:34 | 20,194,204 | 1 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 1,050 | ss | cpyTestDrv.ss | #lang scheme
(require scheme/foreign
"../../schcuda/ffi-ext.ss"
"../../schcuda/scuda.ss"
"../../schcuda/suda-set-env.ss"
"../../schcuda/cuda_h.ss"
"../../schcuda/cutil_h.ss"
"../../schcuda/cuda_runtime_api_h.ss"
"../../schcuda/driver_types_h.ss"
"alloc-launch.rkt")
(unsafe!)
(define kernel_name #"cpyTestDrv_kernel")
(define (main)
(let* (;[current_folder (find-system-path 'home-dir)]
;[cubin_path_string (string-append (path->string current_folder) "data/cpyTest_kernel.sm_10.cubin")]
;; Loading kernel from ctx->module
;; set kernel launch configuration
[cubin-path (generate-cubin "data/cpyTestDrv_kernel.sm_10.cubin")]; bytes type if there's '#' infront of string.
[cuDevice (last (suda-init-devices 0))])
;; load kernel function
(let*-values ([(cuContext l-hfunc)
(load-kernel-driver cuDevice cubin-path kernel_name)])
(alloc-and-launch (car l-hfunc))
(cuCtxDetach cuContext))))
(main)
| false |
042fe6087188bca305ad6eccc35de32da19db11a | d9cb7af1bdc28925fd749260d5d643925185b084 | /test/1.02.scm | 786058448a8dcf571e9a61210d1b7368cce45492 | []
| no_license | akerber47/sicp | 19e0629df360e40fd2ea9ba34bf7bd92be562c3e | 9e3d72b3923777e2a66091d4d3f3bfa96f1536e0 | refs/heads/master | 2021-07-16T19:36:31.635537 | 2020-07-19T21:10:54 | 2020-07-19T21:10:54 | 14,405,303 | 0 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 219 | scm | 1.02.scm | (define (run)
(assert (= (ss2l 0 0 0) 0))
(assert (= (ss2l 1 1 0) 2))
(assert (= (ss2l 1 0 1) 2))
(assert (= (ss2l 0 1 1) 2))
(assert (= (ss2l 1 1 1) 2))
(assert (= (ss2l 3 4 5) 41))
"All tests passed!"
)
| false |
3cd3f41e8ada4022279323e38b86a52263b6ae06 | 235b9cee2c18c6288b24d9fa71669a7ee1ee45eb | /compiler/helpers.ss | e962d6625b92f56fb8423a8d3f6d18fb4485de71 | []
| no_license | Tianji-Zhang/p423 | f627046935a58c16a714b230d4a528bdcda41057 | f66fc2167539615a9cd776343e48664b902d98b1 | refs/heads/master | 2021-01-18T04:33:38.905963 | 2013-05-18T05:56:41 | 2013-05-18T05:56:41 | null | 0 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 10,381 | ss | helpers.ss | ;; helpers.ss
;;
;; part of p423-sp12/srwaggon-p423 assign3
;; http://github.iu.edu/p423-sp12/srwaggon-p423
;; introduced in a4
;;
;; Samuel Waggoner
;; [email protected]
;; 2012/2/11
#!chezscheme
(library (compiler helpers)
(export
prim?
effect-prims
effect-prim?
pred-prims
pred-prim?
value-prims
value-prim?
simple?
immediate?
binop?
loc?
relop?
triv?
var?
error-unless
error-when
invalid
int64!32?
uncover-conflicts
)
(import
;; Load Chez Scheme primitives:
(chezscheme)
;; Load compiler framework:
(framework match)
(framework helpers)
)
#| The list of Value primitives.
|#
(define value-prims
'(+ - * car cdr cons make-vector vector-length vector-ref void procedure-ref procedure-code make-procedure))
#| value-prim? : expression --> boolean
|| Determines if the given expression is an Value primitive.
|#
(define (value-prim? expr)
(and #t (memq expr value-prims)))
#| The list of predicate primitives.
|#
(define pred-prims
'(< <= = >= > boolean? eq? fixnum? null? pair? vector? procedure?))
#| pred-prim? : expression --> boolean
|| Determines if the given expression is a Predicate primitive.
|#
(define (pred-prim? expr)
(and #t (memq expr pred-prims)))
#| The list of Effect primitives.
|#
(define effect-prims
'(set-car! set-cdr! vector-set! procedure-set!))
#| effect-prim? : expr --> boolean
|| Determines if the given expression is an Effect primitive.
|#
(define (effect-prim? expr)
(and #t (memq expr effect-prims)))
#| prim? : expr --> boolean
|| Determines if the given expression is a primitive.
|#
(define (prim? expr)
(or (value-prim? expr) (effect-prim? expr) (pred-prim? expr)))
(define (immediate? im)
(or (fixnum? im) (eq? im '()) (eq? im '#f) (eq? im '#t)))
;; simple?
(define (simple? context lhs*)
(lambda (program)
(match program
[(letrec ((,uvar* ,expr*) ...) ,[body])
(let ([e* (map (simple? context (union lhs* uvar*)) expr*)])
(and (not (memq #f e*)) body #t))]
[(if ,[test] ,[conseq] ,[altern])
(and test conseq altern #t)]
[(begin ,[expr*] ... ,[expr])
(and (not (memq #f expr*)) expr #t)]
[(let ((,uvar* ,[expr*]) ...) (assigned ,assign* ,[body]))
(and (not (memq #f expr*)) body #t)]
[(,prim ,[expr*] ...) (guard (prim? prim))
(and (not (memq #f expr*)) #t)]
[(lambda ,uvar* (assigned ,assign* ,[(simple? #t lhs*) -> body]))
(and body #t)]
[(set! ,uvar ,[expr])
(and expr #t)]
[(quote ,immediate) #t]
[(,[rator] ,[rand*] ...)
(if context #f #t)]
[,uvar (guard (uvar? uvar))
(and (not (memq uvar lhs*)) #t)]
[,else (errorf 'simple? "Invalid expression: ~s" else)]
)))
#| uncover-conflicts : tail uvar* who qualifier --> conflict-graph call-live-set
||
|#
(define (uncover-conflicts tail uvar* who qual)
(define call-live '())
;; graph-add! : symbol symbol conflict-graph --> conflict-graph
;; graph-add! side-effects the given conflict-graph by set-cdr!'ing
;; the given symbol's association's cdr as the set-cons of its current
;; cdr and the given conflicting (second) symbol.
(define (graph-add! s conflict graph)
(when (uvar? s)
(let ([assoc (assq s graph)])
(if assoc
(set-cdr! assoc (set-cons conflict (cdr assoc)))
(cons (list s conflict) graph)
)))
graph)
;; update-graph : symbol live-set conflict-graph --> conflict-graph
;; update-graph takes a symbol, a live set, and a conflict graph
;; and adds the live-set as a conflict of the symbol in the graph.
(define (update-graph s conflicts graph)
(if (or (qual s) (uvar? s))
(let loop ([conflicts conflicts]
[graph graph])
(cond
[(null? conflicts) graph]
[else
(loop (cdr conflicts)
(graph-add! (car conflicts) s
(graph-add! s (car conflicts) graph)))]
))
graph))
;; handle : symbol pred live-set --> live-set
;; iff the var qualifies by the pred or is a register it is added
;; to the live-set before the live-set is returned.
(define (handle var ls)
(if (or (uvar? var) (qual var)) (set-cons var ls) ls))
;; graph-union! : conflict-graph conflict-graph --> conflict-graph
;; graph-union! takes two conflict graphs and combines their entries
;; (key-value pairs where the value is a list of conflicts)
;; into a single conflict-graph (through side-effecting the secondly
;; provided conflict graph
(define (graph-union! g0 g1)
(for-each (lambda (assoc)
(let ([s (car assoc)]
[flicts (cdr assoc)])
(update-graph s flicts g1))) g0)
g1 #|Pacman blocker|#
)
;; Effect : Effect* Effect conflict-graph live-set --> conflict-graph live-set
(define (Effect effect* effect graph live)
(match effect
[(begin ,e* ...) (Effect* (append effect* e*) graph live)]
[(if ,pred ,conseq ,altern)
(let*-values ([(ga lsa) (Effect '() altern graph live)]
[(gc lsc) (Effect '() conseq graph live)]
[(gp lsp) (Pred pred gc ga lsc lsa)])
(Effect* effect* gp lsp))]
[(mset! ,base ,offset ,val)
(Effect* effect* graph (handle base (handle offset (handle val live))))]
[(nop) (Effect* effect* graph live)]
[(return-point ,label ,tail)
(let-values ([(gt lst) (Tail tail graph '())])
(set! call-live (union call-live live))
(Effect* effect* gt (union lst (filter (lambda (x) (or (uvar? x) (frame-var? x))) live))))]
[(set! ,lhs (mref ,base ,offset))
(let ([ls (remove lhs live)])
(Effect* effect* (update-graph lhs ls graph) (handle base (handle offset ls))))]
[(set! ,lhs (,binop ,rhs0 ,rhs1)) (guard (binop? binop))
(let ([ls (remove lhs live)])
(Effect* effect* (update-graph lhs ls graph) (handle rhs0 (handle rhs1 ls))))]
[(set! ,lhs ,rhs)
(let ([ls (remove lhs live)])
(Effect* effect* (update-graph lhs ls graph) (handle rhs ls)))]
[,else (invalid who 'Effect else)]))
;; Effect* : Effect* conflict-graph live-set --> conflict-graph live-set
(define (Effect* effect* graph live)
(match effect*
[() (values graph live)]
[(,effect* ... ,effect) (Effect effect* effect graph live)]
[,else (invalid who 'Effect* else)]))
;; Pred : Pred conflict-graph live-set --> conflict-graph live-set
(define (Pred pred Cgraph Agraph Clive Alive)
(match pred
[(true) (values Cgraph Clive)]
[(false) (values Agraph Alive)]
[(begin ,effect* ... ,pred)
(let*-values ([(gp lsp) (Pred pred Cgraph Agraph Clive Alive)]
[(ge* lse*) (Effect* effect* gp lsp)])
(values ge* lse*))]
[(if ,pred ,conseq ,altern)
(let*-values ([(ga lsa) (Pred altern Cgraph Agraph Clive Alive)]
[(gc lsc) (Pred conseq Cgraph Agraph Clive Alive)]
[(gp lsp) (Pred pred gc ga lsc lsa)])
;;(values (graph-union! Cgraph Agraph) (union lsp lsc lsa))
(values gp lsp)
)]
[(,relop ,triv0 ,triv1)
(values (graph-union! Cgraph Agraph) (handle triv0 (handle triv1 (union Clive Alive))))]
[,else (invalid who 'Pred else)]))
;; Tail : Tail conflict-graph live-set --> conflict-graph live-set
(define (Tail tail graph live)
(match tail
[(begin ,effect* ... ,tail)
(let*-values ([(gt lst) (Tail tail graph live)]
[(ge* lse*) (Effect* effect* gt lst)])
(values graph lse*))]
[(if ,pred ,conseq ,altern)
(let*-values ([(ga lsa) (Tail altern graph live)]
[(gc lsc) (Tail conseq graph live)]
[(gp lsp) (Pred pred gc ga lsc lsa)])
;;(values graph (union lsp lsc lsa)))
(values graph lsp))
]
[(,triv ,loc* ...)
(values graph (handle triv
(union (filter (lambda (x) (or (uvar? x) (qual x))) loc*) live)))]
[,else (invalid who 'Tail else)]))
(let*-values ([(empty-graph) (map (lambda (s) (cons s '())) uvar*)]
[(live-set) '()]
[(graph lives) (Tail tail empty-graph live-set)])
(values graph call-live))
)
#|
|| int64!32? : sym
|| returns #t if the given symbol is strictly an 64-bit integer
|| and not a 32-bit integer.
|#
(define (int64!32? x)
(and (not (int32? x)) (int64? x)))
#| relop? : sym --> boolean
| relop? takes a symbol and returns #t
| iff the symbol is a relational operator
|
| Relop --> < | <= | = | >= | >
|#
(define (relop? exp)
(define relops '(< <= = >= >))
(and (memq exp relops) #t)
)
#| binop? : sym --> boolean
| binop? takes a symbol and returns #t
| iff the symbol is a binary operator.
|
| Binop --> + | - | * | logand | logor | sra
|#
(define (binop? exp)
(define binops '(+ - * logand logor sra))
(and (memq exp binops) #t)
)
(define-syntax error-unless
(syntax-rules ()
[(_ bool who string exp ...)
(unless bool
(errorf who string exp ...))]
[(_ bool string exp ...)
(unless bool
(errorf string exp ...))]
)
)
(define-syntax error-when
(syntax-rules ()
[(_ bool who string exp ...)
(when bool
(errorf who string exp ...))]
[(_ bool string exp ...)
(when bool
(errorf string exp ...))]
)
)
#;(define-syntax invalid
(syntax-rules ()
[(_ what exp)
(errorf "invalid ~s ~s" what exp)
]
))
(define (invalid who what exp)
(errorf who "invalid ~s: ~s" what exp))
#| loc? : exp --> boolean
| loc? takes an expression and returns #t
| iff the expression is a location.
|
| Loc --> ,Register | <frame variable>
|#
(define (loc? exp)
(or (register? exp) (frame-var? exp))
)
#| var? : exp --> boolean
| var? takes an expression and returns #t
| iff the expression is a variable.
|
| Var --> ,<uvar> | ,Loc
|#
(define (var? exp)
(or
(uvar? exp)
(loc? exp)
)
)
#| triv? : exp --> boolean
| triv? takes an expression and returns #t
| iff the expression is trivial.
|
| Triv --> ,Var | <integer> | <label>
|#
(define (triv? exp)
(or
(var? exp)
(int64? exp)
(label? exp)
)
)
) ;; End Library | true |
9d6f7f7f9e5f068395e152f2cfc545f2f90fcb08 | 309e1d67d6ad76d213811bf1c99b5f82fa2f4ee2 | /A07.ss | 8afa5c8475f2a213b9d491c6811c7561c93fea48 | []
| no_license | lix4/CSSE304-Programming-Language-Concept-Code | d8c14c18a1baa61ab5d3df0b1ac650bdebc59526 | dd94262865d880a357e85f6def697661e11c8e7a | refs/heads/master | 2020-08-06T02:50:53.307301 | 2016-11-12T03:03:56 | 2016-11-12T03:03:56 | 73,528,000 | 1 | 1 | null | null | null | null | UTF-8 | Scheme | false | false | 6,694 | ss | A07.ss | ;;Xiwen Li
;;Assignment 07
;;1
; (define
(define vector-append-list
(lambda (vec ls)
(let ([new-vector (make-vector (+ (vector-length vec) (length ls)))])
(copy-from-vector new-vector vec 0)
(copy-from-list new-vector ls (vector-length vec) (vector-length vec))
new-vector)))
(define copy-from-vector
(lambda (new-vector vec index)
(cond
[(equal? vec '#()) new-vector]
[(equal? index (- (vector-length vec) 1)) (vector-set! new-vector index (vector-ref vec index))]
[else
(vector-set! new-vector index (vector-ref vec index))
(copy-from-vector new-vector vec (+ index 1))])))
(define copy-from-list
(lambda (new-vector ls index vec-length)
(cond
[(null? ls) new-vector]
[(equal? index (- (vector-length new-vector) 1)) (vector-set! new-vector index (list-ref ls (- index vec-length)))]
[else
(vector-set! new-vector index (list-ref ls (- index vec-length)))
(copy-from-list new-vector ls (+ index 1) vec-length)])))
;;2
(define qsort
(lambda (pred ls)
(cond
[(null? ls) '()]
[else (let ((pivot (car ls)))
(append (qsort pred (qsort-part (lambda (a) (pred a pivot)) (cdr ls)))
(list pivot)
(qsort pred (qsort-part (lambda (a) (not (pred a pivot))) (cdr ls)))))])))
(define qsort-part
(lambda (procedure ls)
(cond
[(null? ls) '()]
[(procedure (car ls)) (append (list (car ls)) (qsort-part procedure (cdr ls)))]
[else (append (qsort-part procedure (cdr ls)))])))
(define connected?
(lambda (graph)
(cond
[(equal? (length graph) 1) #t]
[else (connected?-rec (list-sort connected?-sort-predicate graph) '())]
)
)
)
(define connected?-rec
(lambda (graph union)
(cond
[(null? graph) #t]
[else (let ((current-union (append (list (caar graph)) (cadar graph))))
(cond
[(equal? union '()) (connected?-rec (cdr graph) current-union)]
[(not (connected?-intercept current-union union)) #f]
[else (connected?-rec (cdr graph) (connected?-combiner union current-union))]
)
)])))
(define connected?-sort-predicate
(lambda (ls1 ls2)
(string<? (symbol->string (car ls1)) (symbol->string (car ls2)))))
(define connected?-combiner
(lambda (ls1 ls2)
(cond
[(null? ls2) ls1]
[(member (car ls2) ls1) (connected?-combiner ls1 (cdr ls2))]
[else (connected?-combiner (append ls1 (list (car ls2))) (cdr ls2))])))
(define connected?-intercept
(lambda (ls1 ls2)
(cond
[(null? ls1) #f]
[(member (car ls1) ls2) #t]
[else (connected?-intercept (cdr ls1) ls2)])))
;;4
(define reverse-it
(lambda (lst)
(let rec ([lst lst]
[new-lst '()])
(if (null? lst)
new-lst
(rec (cdr lst)
(cons (car lst)
new-lst))))))
;;5
;(1)
(define empty-BST
(lambda empty
'()))
;(2)
(define empty-BST?
(lambda (BST)
(null? BST)))
;;(3)
(define BST-insert
(lambda (num bst)
(cond [(null? bst) (list num '() '())]
[(= num (car bst)) bst]
[(< num (car bst)) (list (car bst) (BST-insert num (cadr bst)) (caddr bst))]
[else (list (car bst) (cadr bst) (BST-insert num (caddr bst)))])))
;;(4)
(define BST-inorder
(lambda (bst)
(if (null? bst)
'()
(append (BST-inorder (cadr bst))
(list (car bst))
(BST-inorder (caddr bst))))))
;;(5)
(define BST?
(lambda (bst)
(cond
[(null? bst) #t]
[(not (list? bst)) #f]
[(not (number? (car bst))) #f]
[(not (equal? (length bst) 3)) #f]
[(not (or (list? (cadr bst)) (list? (caddr bst)))) #f]
[(not (BST-check-value (BST-inorder bst))) #f]
[else (and (BST? (cadr bst)) (BST? (caddr bst)))])))
(define BST-check-value
(lambda (in-order)
(cond
[(null? in-order) #t]
[(equal? (length in-order) 1) #t]
[(> (car in-order) (cadr in-order)) #f]
[else (BST-check-value (cdr in-order))])))
;;(6)
(define BST-element car)
(define BST-left cadr)
(define BST-right caddr)
;;(7)
(define BST-insert-nodes
(lambda (bst nums)
(cond [(null? nums) bst]
[else (BST-insert-nodes (BST-insert (car nums) bst)
(cdr nums))])))
;;(8)
(define BST-contains?
(lambda (bst num)
(cond [(null? bst) #f]
[(= num (car bst)) #t]
[(< num (car bst)) (BST-contains? (cadr bst) num)]
[else (BST-contains? (caddr bst) num)])))
;;5
(define map-by-position
(lambda (fn-list arg-list)
(map apply fn-list (map list arg-list))))
(define bt-leaf-sum
(lambda (ls)
(cond
[(number? ls) ls]
[else (+ (bt-leaf-sum (cadr ls))
(bt-leaf-sum (caddr ls)))])))
(define bt-inorder-list
(lambda (bt)
(cond
[(number? bt) '()]
[else (append (bt-inorder-list (cadr bt)) (list (car bt)) (bt-inorder-list (caddr bt)))])))
(define bt-max
(lambda (bt)
(cond
[(number? bt) bt]
[(< (bt-max (cadr bt)) (bt-max (caddr bt))) (bt-max (caddr bt))]
[else (bt-max (cadr bt))])))
(define bt-max-interior
(lambda (bt)
(car (bt-max-interior-rec bt))))
(define bt-max-interior-rec
(lambda (bt)
(cond
[(and (number? (cadr bt)) (number? (caddr bt))) (list (car bt) (max (cadr bt) (caddr bt) (+ (cadr bt) (caddr bt))) (+ (cadr bt) (caddr bt)))]
[(number? (caddr bt))
(let ((left-tree-info (bt-max-interior-rec (cadr bt))) (right-value (caddr bt)))
(let ((current-sum (+ (caddr left-tree-info) right-value)))
(cond
[(equal? (max current-sum (cadr left-tree-info)) current-sum) (list (car bt) current-sum current-sum)]
[(equal? (max current-sum (cadr left-tree-info)) (cadr left-tree-info)) (list (car left-tree-info) (cadr left-tree-info) current-sum)]
)
)
)]
[(number? (cadr bt))
(let ((right-tree-info (bt-max-interior-rec (caddr bt))) (left-value (cadr bt)))
(let ((current-sum (+ (caddr right-tree-info) left-value)))
(cond
[(>= current-sum (cadr right-tree-info)) (list (car bt) current-sum current-sum)]
[else (list (car right-tree-info) (cadr right-tree-info) current-sum)]
)
)
)]
[else (let ((left-tree-info (bt-max-interior-rec (cadr bt))) (right-tree-info (bt-max-interior-rec (caddr bt))))
(let ((current-sum (+ (caddr left-tree-info) (caddr right-tree-info))))
(cond
[(equal? (max (cadr right-tree-info) current-sum (cadr left-tree-info)) current-sum) (list (car bt) current-sum current-sum)]
[(equal? (max (cadr right-tree-info) current-sum (cadr left-tree-info)) (cadr left-tree-info)) (list (car left-tree-info) (cadr left-tree-info) current-sum)]
[(equal? (max (cadr right-tree-info) current-sum (cadr left-tree-info)) (cadr right-tree-info)) (list (car right-tree-info) (cadr right-tree-info) current-sum)]
)
)
)]
)
)
) | false |
ab1e9084f8a7e004625484217ae641b59c3ebe64 | b27ef3e23d38dd546df32b2d8d157ce4c33e2092 | /tests/errno.t | 103eed28a5b78ee29f312469ed64f9ea6aeb251f | [
"BSD-2-Clause"
]
| permissive | ft/guile-termios | 004a3018b8ec7fed971ef37835da6e19d98fff7c | 29dfd68bdc64d6cea0cd4a50757439b77523e9f5 | refs/heads/main | 2021-08-08T00:59:23.696684 | 2021-07-02T16:35:35 | 2021-07-02T16:35:35 | 16,850,088 | 4 | 2 | null | null | null | null | UTF-8 | Scheme | false | false | 738 | t | errno.t | ;; -*- scheme -*-
;; Copyright (c) 2014-2021 Frank Terbeck <[email protected]>
;; All rights reserved.
(use-modules (srfi srfi-11)
(test tap)
(test termios)
((termios) #:prefix base:)
((termios with-exceptions) #:prefix ex:))
(with-test-bundle (guile termios errno)
(plan 2)
(let ((f (open-input-file "README")))
(let-values (((value errno) (base:tc-drain f)))
(define-test (format #f "base: Return value indicates error [~a]"
(strerror errno))
(pass-if-true (base:termios-failure? value))))
(define-test "with-exceptions: Failure throws system-error"
(pass-if-exception 'system-error (ex:tc-drain f)))
(close f)))
| false |
03d4c22f1a22697d2f088dd9c81e486e37688604 | 9b2eb10c34176f47f7f490a4ce8412b7dd42cce7 | /lib/yuniapp/phase/generate.sls | be68f43ec3b1dae9c4e6c69e684cdea1566df132 | [
"LicenseRef-scancode-public-domain",
"CC0-1.0"
]
| permissive | okuoku/yuni | 8be584a574c0597375f023c70b17a5a689fd6918 | 1859077a3c855f3a3912a71a5283e08488e76661 | refs/heads/master | 2023-07-21T11:30:14.824239 | 2023-06-11T13:16:01 | 2023-07-18T16:25:22 | 17,772,480 | 36 | 6 | CC0-1.0 | 2020-03-29T08:16:00 | 2014-03-15T09:53:13 | Scheme | UTF-8 | Scheme | false | false | 6,546 | sls | generate.sls | (library (yuniapp phase generate)
(export generate-app-cmd)
(import (yuni scheme)
(yuni compat ident)
(yuni util files)
(yuniconfig build)
(yuniapp util openlibfile)
(yuniapp util enumlibfiles)
(yuniapp util tmplutils)
(yuniapp tmpl cmdline)
(yuniapp tmpl r7rs)
(yuniapp tmpl r6rs))
(define (calc-libsuffix sym)
(case sym
((racket) ".mzscheme.sls")
((guile) ".scm")
((chibi-scheme gauche sagittarius) ".sld")
((chez vicare) ".sls")
(else
(error "Unknown implementation" sym))))
(define (tmpl-do-nothing . bogus) #t)
(define (calc-generator sym)
(case sym
((racket) tmpl-r6rs/racket)
((guile) tmpl-r6rs/guile)
((chibi-scheme) tmpl-r7rs/chibi-scheme)
((gauche sagittarius) tmpl-r7rs/generic-fullpath)
((chez vicare) tmpl-do-nothing)
(else
(error "Unknown implementation" sym))))
(define (use-batchfile?)
(let ((o (yuniconfig-platform)))
(or (string=? "WIN32" o)
(string=? "WIN64" o))))
(define (use-rootrelative? sym) ;; Do direct load?
(case sym
((chibi-scheme chez vicare) #t)
(else #f)))
(define (do-strip-keywords?)
(let ((o (ident-impl)))
(case o
((gauche sagittarius) #t)
(else #f))))
(define (do-strip-stdaux?)
(let ((o (ident-impl)))
(case o
((chicken guile) #t)
(else #f))))
(define (gen generator prepare-dirs!
runtimepath suffix libfile strip-keywords? strip-stdaux?)
(let ((lib (file->sexp-list libfile)))
(unless (and lib (pair? lib) (= 1 (length lib)))
(error "Malformed library" libfile))
(let* ((lib0 (car lib))
(libname (cadr lib0))
(exports (cdr (caddr lib0)))
(imports (cdr (cadddr lib0))))
;; Strip exports
(let* ((a (if strip-keywords?
(filter-keyword exports)
exports))
(e (if strip-stdaux?
(filter-stdaux a)
a)))
;; Output
(let ((content (generator libname e imports libfile)))
(define (generate sym)
(let ((p (openlibfile #t libname runtimepath suffix)))
(write (list sym libfile))
(newline)
(display content p)
(close-port p)))
(when (string? content)
(prepare-dirs!)
(let ((pold (openlibfile #f libname runtimepath suffix)))
(cond
(pold
(let* ((pnew (open-input-string content))
(old (read pold))
(new (read pnew)))
(close-port pold)
(close-port pnew)
(cond
((equal? old new)
;; Skip output
(write (list 'skip: libfile))
(newline))
(else (generate 'Update:)))))
(else (generate 'Generate:))))))))))
(define (prepare-dir! pth)
(unless (file-directory? pth)
(create-directory pth)))
;; FIXME: Tentative
(define (pickup-dir opt)
(define (itr l)
(cond
((and (pair? l) (string=? opt (car l))
(pair? (cdr l)))
(cadr l))
((pair? l)
(itr (cdr l)))
(else ".")))
(let ((cmd (command-line)))
(itr cmd)))
(define (removetrail str)
;; Remove trailing (back)slash
(let* ((len (string-length str))
(c (string-ref str (- len 1))))
(if (or (char=? c #\\ ) (char=? c #\/))
(substring str 0 (- len 1))
str)))
(define (generate-app-cmd) ;; Closes output port
(define impl (ident-impl))
(define batchfile? (use-batchfile?))
(define rootrelative? (use-rootrelative? impl))
(define strip-keywords? (do-strip-keywords?))
(define strip-stdaux? (do-strip-stdaux?))
(define appdir (removetrail (pickup-dir "-GENERATE")))
(define gendir (removetrail (pickup-dir "-CURRENTDIR")))
(define appsrc (string-append appdir "/" "app.sps"))
(define applib "yunilib")
(define libs '())
(define applibpath (string-append appdir "/" applib))
(define loaderroot (removetrail (yuniconfig-loader-rootpath)))
(define runtimeroot (string-append gendir "/_runtime"))
(define stublibpath (string-append gendir "/_yunistub"))
(define runtimepath (string-append runtimeroot "/"
(symbol->string impl)))
(define runtimemodpath (yuniconfig-platform-stubdir))
(define runscript (string-append gendir "/"
"run-" (symbol->string impl)
(if batchfile? ".bat" ".sh")))
(define libpath (if rootrelative?
(list applibpath runtimepath runtimemodpath)
(list runtimepath runtimemodpath)))
(define libsuffix (calc-libsuffix impl))
(define libgen (calc-generator impl))
(define dir-prepared? #f)
(define (prepare-dirs!)
(unless dir-prepared?
(prepare-dir! runtimeroot)
(prepare-dir! runtimepath)
(set! dir-prepared? #t)))
;; Check app.sps
(unless (file-exists? appsrc)
(error "app.sps not found" appsrc))
;; Check appdir
(unless (file-directory? appdir)
(error "appdir is not a directory" appdir))
;; Check gendir
(unless (file-directory? gendir)
(error "gendir is not a directory" gendir))
;; First, enumerate applibs
(when (file-directory? applibpath)
(set! libs (enumlibfiles applibpath)))
;; Check stubdir
(when (file-directory? stublibpath)
(let ((stublibs (enumlibfiles stublibpath)))
(write (list 'stubs: stublibs)) (newline)
(unless (null? stublibs)
(set! libs (append libs stublibs))
(set! libpath (append libpath (list stublibpath))))))
;; Generate stub libraries
(for-each (lambda (f) (gen libgen
prepare-dirs!
runtimepath libsuffix f
strip-keywords? strip-stdaux?)) libs)
;; Generate launch commandline
(when (file-exists? runscript) ;; Not required actually
(delete-file runscript))
(string-list->file runscript
(list
((if batchfile?
cmdline-win32
cmdline-sh)
impl
loaderroot
appdir
libpath
appsrc
'())))
(close-port (current-output-port)))
)
| false |
e1114b100ca6b38c5e26b21bd73ce31da489c2fa | 4bd59493b25febc53ac9e62c259383fba410ec0e | /Scripts/Task/range-expansion/scheme/range-expansion.ss | 80146739cb322dd5dbf7527e12c7343143d6eda4 | []
| no_license | stefanos1316/Rosetta-Code-Research | 160a64ea4be0b5dcce79b961793acb60c3e9696b | de36e40041021ba47eabd84ecd1796cf01607514 | refs/heads/master | 2021-03-24T10:18:49.444120 | 2017-08-28T11:21:42 | 2017-08-28T11:21:42 | 88,520,573 | 5 | 1 | null | null | null | null | UTF-8 | Scheme | false | false | 1,261 | ss | range-expansion.ss | (define split
(lambda (str char skip count)
(let ((len (string-length str)))
(let loop ((index skip)
(last-index 0)
(result '()))
(if (= index len)
(reverse (cons (substring str last-index) result))
(if (eq? char (string-ref str index))
(loop (if (= count (+ 2 (length result)))
len
(+ index 1))
(+ index 1)
(cons char (cons (substring str last-index index)
result)))
(loop (+ index 1)
last-index
result)))))))
(define range-expand
(lambda (str)
(for-each
(lambda (token)
(if (char? token)
(display token)
(let ((range (split token #\- 1 2)))
(if (null? (cdr range))
(display (car range))
(do ((count (string->number (list-ref range 0)) (+ 1 count))
(high (string->number (list-ref range 2))))
((= count high) (display high))
(display count)
(display ","))))))
(split str #\, 0 0))
(newline)))
| false |
23e7de9ed349cadb58b0c46a90da7698f33b3a50 | 68ab1a4b2ff77fc9bf117b6099361d0547d024a2 | /srfi-tests/69/tests.sld | 9713e2dbb2280746ac19b44b931ea4d606fab70d | []
| no_license | sethalves/r7rs-srfis | 4ee8129e93a9870beb9953b797f174465c4aceb9 | ce9aa3757b23bc9910f854fe074c130213d2e90d | refs/heads/master | 2021-01-22T21:13:42.221304 | 2014-12-31T14:39:35 | 2014-12-31T14:39:35 | 20,106,659 | 1 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 2,202 | sld | tests.sld | (define-library (srfi-tests 69 tests)
(export run-tests)
(import (scheme base)
(srfi 69))
(begin
(define (run-tests)
(let ((ht (make-hash-table))
(ht-copy #f)
(ht-a (make-hash-table))
(ht-b (make-hash-table)))
(hash-table-set! ht "ok" "hi")
(hash-table-set! ht "bluh" "fum")
(hash-table-set! ht "x" "a")
(hash-table-set! ht "x" "b")
(set! ht-copy (hash-table-copy ht))
(hash-table-delete! ht "bluh")
(hash-table-update!/default
ht-copy "cons" (lambda (current-list) (cons 1 current-list)) '())
(hash-table-update!
ht-copy "cons" (lambda (current-list) (cons 2 current-list)))
(hash-table-update!
ht-copy "cons" (lambda (current-list) (cons 3 current-list)))
(hash-table-set! ht-a "a" 1)
(hash-table-set! ht-a "b" 2)
(hash-table-merge! ht-a ht-b)
(and
(hash-table? ht)
(equal? (hash-table-ref ht "ok") "hi")
(equal? (hash-table-ref ht "x") "b")
(equal? (hash-table-ref/default ht "bluh" "buh") "buh")
(hash-table-exists? ht "ok")
(not (hash-table-exists? ht "bluh"))
;; (= (length (hash-table-keys ht)) 2)
;; (member "ok" (hash-table-keys ht))
;; (member "x" (hash-table-keys ht))
;; (not (member "bluh" (hash-table-keys ht)))
;; (= (length (hash-table-values ht)) 2)
;; (member "hi" (hash-table-values ht))
;; (member "b" (hash-table-values ht))
;; (not (member "fum" (hash-table-values ht)))
;; (equal? (assoc "ok" (hash-table->alist ht)) '("ok" . "hi"))
(not (assoc "bluh" (hash-table->alist ht)))
(equal? (assoc "c"
(hash-table->alist (alist->hash-table '(("a" . "b")
("c" "d")
("e" . "f")))))
(list "c" "d"))
(equal? (hash-table-ref ht-copy "cons") '(3 2 1))
;; (hash-table-exists? ht-copy "bluh")
(= (hash-table-ref ht-a "b") 2)
)))))
| false |
75f554c3804bd38ad5efd03a82bd9aef89b1cfe5 | 2543c5f8bef7548ce2ea5e805b74df61b953528a | /tutorial-tuesday-1/fib-dir.scm | 20deb71807c297acb44519ec996177478c8b029d | [
"MIT"
]
| permissive | edhowland/tutorial_transcripts | 4776ca9ffd62bcbc71bc888a7c462bbd6ff4ac21 | 1a2c3ce46253790a1488a9a3e945531ecef2e774 | refs/heads/master | 2020-03-25T12:28:23.089618 | 2018-11-27T19:20:58 | 2018-11-27T19:20:58 | 143,778,009 | 1 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 155 | scm | fib-dir.scm | ;; fib - direct way
(define (sub2 n) (sub1 (sub1 n)))
(define (fib n)
(cond
[(zero? n) 1]
[(= n 1) 1]
[else (+ (fib (sub2 n)) (fib (sub1 n)))]))
| false |
89a1d378c2a939050cfd05ac6d1ca01001547989 | a8216d80b80e4cb429086f0f9ac62f91e09498d3 | /lib/chibi/json.sld | d63b41d363e3dda4660a4ca7b50d340ecb7c5dac | [
"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 | 327 | sld | json.sld |
(define-library (chibi json)
(import (scheme base)
(except (srfi 99 records) define-record-type)
(only (chibi ast) type-name)
(only (chibi) make-constructor))
(export string->json json->string json-read json-write
make-json-reader)
(include-shared "json")
(include "json.scm"))
| false |
7fdabe0b037225e43256946b1cd06f31646adfd9 | 54f854ff6b6725cab04dd3e1a3efff518e098ad3 | /assets/sprintf.scm | fa59ec2bd1d0fddd4059212d3a0132fac04a3405 | [
"MIT"
]
| permissive | Vanille-N/rask | 679172799c8cafcc3d280de39b9d6b5246efe973 | 680307d80796bfbf3e5e4d8ee82ec27d7ffdc76c | refs/heads/master | 2022-12-01T23:27:41.540739 | 2020-08-13T08:27:37 | 2020-08-13T08:27:37 | 269,349,976 | 1 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 1,664 | scm | sprintf.scm | (library (tspl formatted-output)
(export printf fprintf)
(import (rnrs))
; dofmt does all of the work. It loops through the control string
; recognizing format directives and printing all other characters
; without interpretation. A tilde at the end of a control string is
; treated as an ordinary character. No checks are made for proper
; inputs. Directives may be given in either lower or upper case.
(define dofmt
(lambda (p cntl args)
(let ([nmax (- (string-length cntl) 1)])
(let loop ([n 0] [a args])
(if (<= n nmax)
(let ([c (string-ref cntl n)])
(if (and (char=? c #\~) (< n nmax))
(case (string-ref cntl (+ n 1))
[(#\a #\A)
(display (car a) p)
(loop (+ n 2) (cdr a))]
[(#\s #\S)
(write (car a) p)
(loop (+ n 2) (cdr a))]
[(#\%)
(newline p)
(loop (+ n 2) a)]
[(#\~)
(put-char p #\~) (loop (+ n 2) a)]
[else
(put-char p c) (loop (+ n 1) a)])
(begin
(put-char p c)
(loop (+ n 1) a)))))))))
; printf and fprintf differ only in that fprintf passes its
; port argument to dofmt while printf passes the current output
; port.
(define printf
(lambda (control . args)
(dofmt (current-output-port) control args)))
(define fprintf
(lambda (p control . args)
(dofmt p control args))))
| false |
a30ee3904cf26e28040f1bbe78fbbd5fcee09728 | 06d73af66d0c8450e2c9cb20757774c61c813ee6 | /test-pairs.ss | cadea8b693905a087087c69f4cb4cac88b7b151e | []
| 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 | 216 | ss | test-pairs.ss | #lang scheme ; File test-pairs.ss
(require redex "pairs.ss" "lazy-evaluator.ss")
(printf "~a~n" "test-pairs")
(test-equal (ev (Car (Cons yes no))) 'yes)
(test-equal (ev (Cdr (Cons yes no))) 'no)
(test-results)
| false |
c9aef4f7c004da4b7d72929afb12f34090da808e | c39b3eb88dbb1c159577149548d3d42a942fe344 | /07-compilation/linker.scm | 5fb3123b757c6faa91984b04d5ebb76d92bc7058 | []
| no_license | mbillingr/lisp-in-small-pieces | 26694220205818a03efc4039e5a9e1ce7b67ff5c | dcb98bc847c803e65859e4a5c9801d752eb1f8fa | refs/heads/master | 2022-06-17T20:46:30.461955 | 2022-06-08T17:50:46 | 2022-06-08T17:50:46 | 201,653,143 | 13 | 3 | null | 2022-06-08T17:50:47 | 2019-08-10T16:09:21 | Scheme | UTF-8 | Scheme | false | false | 3,862 | scm | linker.scm | (import (builtin core)
(libs utils)
(libs book))
(include "common-stuff.scm")
(include "instructions.scm")
(define *constants* '())
(define *code* '())
(define (build-application application-name ofilename . ofilenames)
(set! sg.current.names '())
(set! *dynamic-variables* '())
(set! sg.current (vector))
(set! *constants* (vector))
(set! *code* (vector))
(define (install filenames entry-points)
(if (pair? filenames)
(let ((ep (install-object-file! (car filenames))))
(install (cdr filenames) (cons ep entry-points)))
(write-result-file application-name
(cons ";;; Bytecode application containing "
(cons ofilename ofilenames))
*dynamic-variables*
sg.current.names
*constants*
*code*
entry-points)))
(install (cons ofilename ofilenames) '()))
(define (install-object-file! filename)
(let* ((ofilename (string-append filename ".sco"))
(content (file-read ofilename))
(dynamics (car content))
(global-names (cadr content))
(constants (caddr content))
(code (cadddr content))
(entry (car (cddddr content))))
(relocate-globals! code global-names)
(relocate-constants! code constants)
(relocate-dynamics! code dynamics)
(+ entry (install-code! code))))
(define (relocate-constants! code constants)
(define n (vector-length *constants*))
(let ((code-size (vector-length code)))
(define (scan pc)
(if (< pc code-size)
(let ((instr (vector-ref code pc)))
(if (= instr CONSTANT-code)
(let* ((i (vector-ref code (+ pc 1)))
(quotation (vector-ref constants i)))
(vector-set! code (+ pc 1) (+ n i))))
(scan (+ pc (instruction-size code pc))))))
(scan 0)
(set! *constants* (vector-append *constants* constants))))
(define (relocate-globals! code global-names)
(define (get-index name)
(let ((where (memq name sg.current.names)))
(if where
(- (length where) 1)
(begin (set! sg.current.names (cons name sg.current.names))
(get-index name)))))
(let ((code-size (vector-length code)))
(define (scan pc)
(if (< pc code-size)
(let ((instr (vector-ref code pc)))
(if (or (= instr CHECKED-GLOBAL-REF-code)
(= instr GLOBAL-REF-code)
(= instr SET-GLOBAL!-code))
(let* ((i (vector-ref code (+ pc 1)))
(name (list-ref global-names i)))
(vector-set! code (+ pc 1) (get-index name))))
(scan (+ pc (instruction-size code pc))))))
(scan 0))
(let ((v (make-vector (length sg.current.names))))
(vector-copy! v 0 sg.current 0 (vector-length sg.current))
(set! sg.current v)))
(define (relocate-dynamics! code dynamics)
(for-each get-dynamic-variable-index dynamics)
(let ((dynamics (reverse dynamics))
(code-size (vector-length code)))
(define (scan pc)
(if (< pc code-size)
(let ((instr (vector-ref code pc)))
(if (or (= instr DYNAMIC-REF-code)
(= instr DYNAMIC-PUSH-code))
(let* ((i (vector-ref code (+ pc 1)))
(name (list-ref dynamics (- i 1))))
(vector-set! code (+ pc 1)
(get-dynamic-variable-index name))))
(scan (+ pc (instruction-size code pc))))))
(scan 0)))
; ===========================================================================
(build-application "07-compilation/tests" "07-compilation/test1" "07-compilation/test2")
| false |
0d72dfb8e1a4e21ba997b7cda729832a370a8718 | afc3bd22ea6bfe0e60396a84a837c82a0d836ea2 | /Informatics Basics/Module 3/3-01-stack.scm | f43d86345ac71393ea66c9488a9b85b1b0bfff91 | []
| no_license | BuDashka/BMSTU | c128c2b13065a25ec027c68bcc3bac119163a53f | 069551c25bd11ea81e823b2195851f8563271b01 | refs/heads/master | 2021-04-15T15:22:12.324529 | 2017-10-19T00:59:25 | 2017-10-19T00:59:25 | 126,348,611 | 1 | 1 | null | 2018-03-22T14:35:04 | 2018-03-22T14:35:04 | null | UTF-8 | Scheme | false | false | 685 | scm | 3-01-stack.scm | (define (compute . args)
(define (f stack stack1 xs)
(cond ((and (and (not (null? xs)) (null? stack1)) (number? (car xs))) (f (cons (car xs) stack) '() (cdr xs)))
((and (and (not (null? xs)) (not (null? stack1))) (number? (car xs))) (f (cons (car xs) stack) stack1 (cdr xs)))
((and (not (null? xs)) (null? stack1)) (f '() (cons (apply (car xs) stack) '()) (cdr xs)))
((and (not (null? stack1)) (not (null? stack)) (= (length stack) 1) (= (length stack1) 1)) (f '() (cons (apply (car xs) (append stack stack1)) '()) (cdr xs)))
((not (null? xs)) (f (cons (apply (car xs) stack) '()) stack1 (cdr xs)))
(else (car stack1))))
(f '() '() args))
| false |
6ea76057e19e14a700c5ddd679e33e3e5bb49b73 | 2ba08a4dd6715e61e0f3f5930ad835abadfb869e | /src/builtin_cons.scm | afa3fb7f7f8ea2190fd2865166b069909c4d4150 | [
"BSD-2-Clause"
]
| permissive | y2q-actionman/zatuscheme | a752c9ce8a3349de8a7e02133543502797bfdd56 | 804ceac367c46ad8c85dfb891b6116b2f90ef4ac | refs/heads/master | 2021-01-17T07:11:04.045083 | 2016-04-02T16:27:29 | 2016-04-02T16:27:29 | 3,135,571 | 2 | 1 | null | null | null | null | UTF-8 | Scheme | false | false | 3,119 | scm | builtin_cons.scm | LOAD
(define pair? %pair?)
LOAD
(define cons %cons)
LOAD
(define car %car)
LOAD
(define cdr %cdr)
LOAD
(define set-car! %set-car!)
LOAD
(define set-cdr! %set-cdr!)
LOAD
(define (caar x) (car (car x)))
LOAD
(define (cadr x) (car (cdr x)))
LOAD
(define (cdar x) (cdr (car x)))
LOAD
(define (cddr x) (cdr (cdr x)))
LOAD
(define (caaar x) (car (caar x)))
LOAD
(define (caadr x) (car (cadr x)))
LOAD
(define (cadar x) (car (cdar x)))
LOAD
(define (caddr x) (car (cddr x)))
LOAD
(define (cdaar x) (cdr (caar x)))
LOAD
(define (cdadr x) (cdr (cadr x)))
LOAD
(define (cddar x) (cdr (cdar x)))
LOAD
(define (cdddr x) (cdr (cddr x)))
LOAD
(define (caaaar x) (car (caaar x)))
LOAD
(define (caaadr x) (car (caadr x)))
LOAD
(define (caadar x) (car (cadar x)))
LOAD
(define (caaddr x) (car (caddr x)))
LOAD
(define (cadaar x) (car (cdaar x)))
LOAD
(define (cadadr x) (car (cdadr x)))
LOAD
(define (caddar x) (car (cddar x)))
LOAD
(define (cadddr x) (car (cdddr x)))
LOAD
(define (cdaaar x) (cdr (caaar x)))
LOAD
(define (cdaadr x) (cdr (caadr x)))
LOAD
(define (cdadar x) (cdr (cadar x)))
LOAD
(define (cdaddr x) (cdr (caddr x)))
LOAD
(define (cddaar x) (cdr (cdaar x)))
LOAD
(define (cddadr x) (cdr (cdadr x)))
LOAD
(define (cdddar x) (cdr (cddar x)))
LOAD
(define (cddddr x) (cdr (cdddr x)))
LOAD
(define (null? x)
(eq? x ()))
LOAD
(define (list? obj)
(let loop ((obj obj) (conses ()))
(cond ((null? obj) #t)
((not (pair? obj)) #f)
((memq obj conses) #f)
(else (loop (cdr obj) (cons obj conses))))))
LOAD
(define (list . objs)
objs)
LOAD
(define (length lis)
(do ((l lis (cdr l))
(n 0 (+ n 1)))
((null? l) n)))
LOAD
(define (append . lsts)
(cond ((null? lsts) ())
((null? (cdr lsts)) (car lsts))
((null? (car lsts)) (apply append (cdr lsts)))
(else
(define head (cons (caar lsts) ()))
(let loop ((l (cdar lsts))
(c head))
(cond ((null? l)
(set-cdr! c (apply append (cdr lsts)))
head)
(else
(set-cdr! c (cons (car l) ()))
(loop (cdr l) (cdr c))))))))
LOAD
(define (reverse lis)
(do ((l lis (cdr l))
(ret () (cons (car l) ret)))
((null? l) ret)))
LOAD
(define (list-tail lis n)
(if (zero? n) lis
(list-tail (cdr lis) (- n 1))))
LOAD
(define (list-ref lis num)
(car (list-tail lis num)))
LOAD
(define (%mem-funcs op)
(letrec ((fun
(lambda (obj list)
(cond ((null? list) #f)
((op obj (car list)) list)
(else (fun obj (cdr list)))))))
fun))
LOAD
(define memq (%mem-funcs eq?))
LOAD
(define memv (%mem-funcs eqv?))
LOAD
(define member (%mem-funcs equal?))
LOAD
(define (%ass-funcs op)
(letrec ((fun
(lambda (obj alist)
(cond ((null? alist) #f)
((op obj (caar alist)) (car alist))
(else (fun obj (cdr alist)))))))
fun))
LOAD
(define assq (%ass-funcs eq?))
LOAD
(define assv (%ass-funcs eqv?))
LOAD
(define assoc (%ass-funcs equal?))
| false |
793cd08a0a0adb83dc0223e0f2ec9092e8d95b52 | 849496fae4361b0d814408e48e5dbe5b764f0842 | /ans015.scm | 8008120e310f5370c5cb46731208c511ad51ba2d | []
| no_license | kzfm1024/euler | fba6f9a757369b0055c1c08eee47a4f70ad81f10 | 2e58de5725be097d7f5246b54082846ad7d3062b | refs/heads/master | 2020-06-05T10:41:55.087019 | 2010-10-10T07:09:29 | 2010-10-10T07:09:29 | null | 0 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 1,371 | scm | ans015.scm | ;;;
;;; Project Euler - Problem 15
;;;
#|
Starting in the top left corner of a 2x2 grid, there are 6 routes (without
backtracking) to the bottom right corner.
How many routes are there through a 20x20 grid?
|#
(use srfi-1)
(define (fact n)
(if (= n 0)
1
(* n (fact (- n 1)))))
(define (pascal-triangle n)
(define (C n k)
(/ (fact n)
(* (fact (- n k))
(fact k))))
(map (lambda (k) (C n k)) (iota (+ n 1))))
(define (reduce-adjacent l)
(cond [(null? l) '()]
[(null? (cdr l)) '()]
[else (cons (+ (car l) (cadr l))
(reduce-adjacent (cdr l)))]))
(define (number-of-routes l)
(cond [(null? l) (error "must be non-empty list")]
[(null? (cdr l)) (car l)]
[else (number-of-routes (reduce-adjacent l))]))
(number-of-routes (pascal-triangle 20))
; => 137846528820
;;----------------------------------------------------------------------
;; (2n)! / (n! * n!)
(/ (fact (* 2 20)) (* (fact 20) (fact 20)))
;;----------------------------------------------------------------------
(number-of-routes (pascal-triangle 0))
(number-of-routes (pascal-triangle 1))
(number-of-routes (pascal-triangle 2))
(number-of-routes (pascal-triangle 3))
(number-of-routes (pascal-triangle 20))
(pascal-triangle 0)
(pascal-triangle 1)
(pascal-triangle 2)
(pascal-triangle 3)
(pascal-triangle 20)
| false |
1067515096156b9a910c0daa46d31496c4135a81 | 432924338995770f121e1e8f6283702653dd1369 | /2/p2.60.scm | 9ea2fd9f89d0a6b3e029d5ccee7f41787bb6a587 | []
| no_license | punchdrunker/sicp-reading | dfaa3c12edf14a7f02b3b5f4e3a0f61541582180 | 4bcec0aa7c514b4ba48e677cc54b41d72c816b44 | refs/heads/master | 2021-01-22T06:53:45.096593 | 2014-06-23T09:51:27 | 2014-06-23T09:51:27 | null | 0 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 2,553 | scm | p2.60.scm | (use gauche.test)
(load "./2.3.3-1.scm")
; 問題2.60
; 集合setにオブジェクトxが含まれているかを調べる
; (変更なし)
(define (element-of-set? x set)
(cond ((null? set) false)
((equal? x (car set)) true)
(else (element-of-set? x (cdr set)))))
; 集合setにオブジェクトxを追加した集合を返す
; (重複チェックをしないようにする)
(define (adjoin-set x set) (cons x set))
; 2つの集合の積集合(どちらの集合にも含まれている要素の集合)を返す
; (変更なし)
(define (intersection-set set1 set2)
(cond ((or (null? set1) (null? set2)) '())
((element-of-set? (car set1) set2)
(cons (car set1)
(intersection-set (cdr set1) set2)))
(else (intersection-set (cdr set1) set2))))
; 2つの集合の和集合(どちらかの集合に含まれている要素全ての集合)を返す
; (重複チェックをしないようにする)
(define (union-set set1 set2)
(cond ((null? set1) set2)
; set2に(car set1)をaddして(cdr set1)とset2で再帰
(else (cons (car set1) (union-set (cdr set1) set2)))))
(define (union-set set1 set2)
(append set1 set2))
(trace adjoin-set)
(trace union-set)
(test-start "問題2.60")
(test-section "重複の許される element-of-set?")
(test* "(element-of-set? 'a '(a b c))" true (element-of-set? 'a '(a b c)))
(test* "(element-of-set? 'z '(a b c))" false (element-of-set? 'z '(a b c)))
(test-section "重複の許される adjoin-set")
(test* "(adjoin-set 'z '(a b c))" '(z a b c) (adjoin-set 'z '(a b c)))
(test* "(adjoin-set 'a '(a b c))" '(a a b c) (adjoin-set 'a '(a b c)))
(test-section "重複の許される intersection-set")
(test* "(intersection-set '(a b c) '(b c d))" '(b c) (intersection-set '(a b c) '(b c d)))
(test* "(intersection-set '(a b c) '(hoge fuga))" '() (intersection-set '(a b c) '(hoge fuga)))
(test-section "重複の許される union-set")
(test* "(union-set '(a b c) '(b c d))" '(a b c b c d) (union-set '(a b c) '(b c d)))
(test* "(union-set '() '(b c d))" '(b c d) (union-set '() '(b c d)))
(test* "(union-set '(a b c) '())" '(a b c) (union-set '(a b c) '()))
(test-end)
; 1つ目のunion-set
; union-setだけのtraceだと一見して変わらないように見えるが、
; element-of-set?もtraceしてみると、重複のないadjoin-setとunion-setは
; O(n^2)で増加する事がわかる
; 重複を許すとO(n)で増加する
;
; 2つ目のunion-set
; ただのappendなので、ステップ数はO(1)
| false |
c6357c0b4658567054fb2c66b8aeba84f6871c93 | defeada37d39bca09ef76f66f38683754c0a6aa0 | /System.Xml/system/xml/xsl/xslt-context.sls | 3e71476411bbc2cc3a429020e6c8caaed2d13905 | []
| 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,183 | sls | xslt-context.sls | (library (system xml xsl xslt-context)
(export is?
xslt-context?
compare-document
resolve-variable
preserve-whitespace?
resolve-function
whitespace?)
(import (ironscheme-clr-port))
(define (is? a) (clr-is System.Xml.Xsl.XsltContext a))
(define (xslt-context? a) (clr-is System.Xml.Xsl.XsltContext a))
(define-method-port
compare-document
System.Xml.Xsl.XsltContext
CompareDocument
(System.Int32 System.String System.String))
(define-method-port
resolve-variable
System.Xml.Xsl.XsltContext
ResolveVariable
(System.Xml.Xsl.IXsltContextVariable System.String System.String))
(define-method-port
preserve-whitespace?
System.Xml.Xsl.XsltContext
PreserveWhitespace
(System.Boolean System.Xml.XPath.XPathNavigator))
(define-method-port
resolve-function
System.Xml.Xsl.XsltContext
ResolveFunction
(System.Xml.Xsl.IXsltContextFunction
System.String
System.String
System.Xml.XPath.XPathResultType[]))
(define-field-port
whitespace?
#f
#f
(property:)
System.Xml.Xsl.XsltContext
Whitespace
System.Boolean))
| false |
7f77110ad582f85101d8cc83efb1df720e96e32c | 31aef3d5d3426a7cf9811996296d6e5fd679a3de | /Task/Y-combinator/Scheme/y-combinator-3.ss | afc9a61e49acefa6c346bc08d23ca2ffe948d037 | []
| no_license | ShowMaster32/rosetta-project | 6b47082a16429f58baebd56e7f0786d7ee63dc89 | 87c53a032d2b8020e9690f010cd1b69c7219daff | refs/heads/master | 2023-06-25T13:41:05.065767 | 2021-07-23T14:07:17 | 2021-07-23T14:07:17 | 384,652,116 | 1 | 1 | null | null | null | null | UTF-8 | Scheme | false | false | 65 | ss | y-combinator-3.ss | (define Y2r
(lambda (f)
(lambda a (apply (f (Y2r f)) a))))
| false |
1cd89fe13b3a5bc5ea09c13d89c5a35d2d494f3b | ce567bbf766df9d98dc6a5e710a77870753c7d29 | /ch6/25.scm | 736103ef8f51156d59beb9db76100a794137118f | []
| 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 | 6,149 | scm | 25.scm | (load-relative "../libs/init.scm")
(load-relative "./base/test.scm")
(load-relative "./base/cps.scm")
(load-relative "./base/data-structures.scm")
(load-relative "./base/cps-cases.scm")
(load-relative "./base/cps-lang.scm")
(load-relative "./base/base-iterp.scm")
;; Extend CPS-IN so that a let expression can declare an arbitrary
;; number of variables (exercise 3.16).
;; not a perfect solution, cps-let-exp still keep same
;; multiple args are transformed to multiple cps-let-exp
(define the-grammar
'((program (expression) a-program)
(expression (number) const-exp)
(expression
("-" "(" expression "," expression ")")
diff-exp)
(expression
("+" "(" (separated-list expression ",") ")")
sum-exp)
(expression
("zero?" "(" expression ")")
zero?-exp)
(expression
("if" expression "then" expression "else" expression)
if-exp)
(expression
("letrec"
(arbno identifier "(" (arbno identifier) ")"
"=" expression)
"in"
expression)
letrec-exp)
(expression (identifier) var-exp)
;; New stuff
(expression
("let" (arbno identifier "=" expression) "in" expression)
let-exp)
(expression
("proc" "(" (arbno identifier) ")" expression)
proc-exp)
(expression
("(" expression (arbno expression) ")")
call-exp)
))
;;;;;;;;;;;;;;;; sllgen boilerplate ;;;;;;;;;;;;;;;;
(sllgen:make-define-datatypes the-lexical-spec the-grammar)
(define show-the-datatypes
(lambda () (sllgen:list-define-datatypes the-lexical-spec the-grammar)))
(define scan&parse
(sllgen:make-string-parser the-lexical-spec the-grammar))
(define cps-out-grammar
'((cps-out-program (tfexp) cps-a-program)
(simple-expression (number) cps-const-exp)
(simple-expression (identifier) cps-var-exp)
(simple-expression
("-" "(" simple-expression "," simple-expression ")")
cps-diff-exp)
(simple-expression
("zero?" "(" simple-expression ")")
cps-zero?-exp)
(simple-expression
("+" "(" (separated-list simple-expression ",") ")")
cps-sum-exp)
(simple-expression
("proc" "(" (arbno identifier) ")" tfexp)
cps-proc-exp)
(tfexp
(simple-expression)
simple-exp->exp)
;; New stuff
(tfexp
("let" identifier "=" simple-expression "in" tfexp)
cps-let-exp)
(tfexp
("letrec"
(arbno identifier "(" (arbno identifier) ")" "=" tfexp)
"in"
tfexp)
cps-letrec-exp)
(tfexp
("if" simple-expression "then" tfexp "else" tfexp)
cps-if-exp)
(tfexp
("(" simple-expression (arbno simple-expression) ")")
cps-call-exp)
))
;;;;;;;;;;;;;;;;; sllgen boilerplate ;;;;;;;;;;;;;;;;
(sllgen:make-define-datatypes cps-out-lexical-spec cps-out-grammar)
(define cps-show-the-datatypes
(lambda ()
(sllgen:list-define-datatypes cps-out-lexical-spec cps-out-grammar)))
(define cps-out-scan&parse
(sllgen:make-string-parser cps-out-lexical-spec cps-out-grammar))
(define value-of/k
(lambda (exp env cont)
(cases tfexp exp
(simple-exp->exp (simple)
(apply-cont cont
(value-of-simple-exp simple env)))
(cps-let-exp (var rhs body)
(let ((val (value-of-simple-exp rhs env)))
(value-of/k body
(extend-env* (list var) (list val) env)
cont)))
(cps-letrec-exp (p-names b-varss p-bodies letrec-body)
(value-of/k letrec-body
(extend-env-rec** p-names b-varss p-bodies env)
cont))
(cps-if-exp (simple1 body1 body2)
(if (expval->bool (value-of-simple-exp simple1 env))
(value-of/k body1 env cont)
(value-of/k body2 env cont)))
(cps-call-exp (rator rands)
(let ((rator-proc
(expval->proc
(value-of-simple-exp rator env)))
(rand-vals
(map
(lambda (simple)
(value-of-simple-exp simple env))
rands)))
(apply-procedure/k rator-proc rand-vals cont))))))
;; cps-of-exp : Exp * SimpleExp -> TfExp
(define cps-of-exp
(lambda (exp cont)
(cases expression exp
(const-exp (num) (make-send-to-cont cont (cps-const-exp num)))
(var-exp (var) (make-send-to-cont cont (cps-var-exp var)))
(proc-exp (vars body)
(make-send-to-cont cont
(cps-proc-exp (append vars (list 'k%00))
(cps-of-exp body (cps-var-exp 'k%00)))))
(zero?-exp (exp1)
(cps-of-zero?-exp exp1 cont))
(diff-exp (exp1 exp2)
(cps-of-diff-exp exp1 exp2 cont))
(sum-exp (exps)
(cps-of-sum-exp exps cont))
(if-exp (exp1 exp2 exp3)
(cps-of-if-exp exp1 exp2 exp3 cont))
;; New stuff
(let-exp (vars exps body)
(cps-of-let-exp vars exps body cont))
(letrec-exp (ids bidss proc-bodies body)
(cps-of-letrec-exp ids bidss proc-bodies body cont))
(call-exp (rator rands)
(cps-of-call-exp rator rands cont)))))
;; cps-of-let-exp : Var * InpExp * InpExp * SimpleExp -> TfExp
;; New stuff
(define cps-of-let-exp
(lambda (vars vals body k-exp)
(let cps-of-rest ((vars vars) (vals vals))
(let ((var (car vars))
(val (car vals))
(left-vars (cdr vars))
(left-vals (cdr vals)))
(if (null? left-vars)
(cps-of-exps (list val)
(lambda (new-rands)
(cps-let-exp var
(car new-rands)
(cps-of-exp body k-exp))))
(cps-of-exps (list val)
(lambda (new-rands)
(cps-let-exp var
(car new-rands)
(cps-of-rest left-vars left-vals)))))))))
;; new test
(run "let x = 1 y = 2 in 1")
(run "let x = 30
in let x = -(x,1)
y = -(x,2)
in -(x, y)")
(run "let x = 10
in let x = 20
in +(x, 10)")
(run-all)
| false |
b7a7948cc5a93b51a6f39b1e77f3722487a9663d | d17943098180a308ae17ad96208402e49364708f | /platforms/js-vm/private/private/sandbox/broken-programs/branch/branch.ss | 938eec50f2970f5495401fe8ade204962f50f090 | []
| no_license | dyoo/benchmark | b3f4f39714cc51e1f0bc176bc2fa973240cd09c0 | 5576fda204529e5754f6e1cc8ec8eee073e2952c | refs/heads/master | 2020-12-24T14:54:11.354541 | 2012-03-02T19:40:48 | 2012-03-02T19:40:48 | 1,483,546 | 1 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 81 | ss | branch.ss | #lang scheme/base
(define (f x) x)
(display (if (f #t) 'ok 'not-ok))
(newline)
| false |
3fa8e46c1ee4928507e0b9066d63ca50d34cd8a2 | eef5f68873f7d5658c7c500846ce7752a6f45f69 | /spheres/structure/avl-tree.sld | b00dfb3f53964e2353c1feea7e60fa8bf502f090 | [
"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 | 446 | sld | avl-tree.sld | ;;!!! AVL Tree
;; .author Hans Oesterholt, 2005
;; .author Alvaro Castro-Castilla, 2015
(define-library (spheres/structure avl-tree)
(export avl
avl-from-avl
avl-insert!
avl-remove!
avl-find
avl-exists?
avl-map
avl-for-each
avl-filter
avl-nodes
avl-empty?
avl-min
avl-max
avl-atomic)
(include "avl-tree.scm"))
| false |
8c6743af91c08a149b79ea31bc8400ea4585f0f1 | 751ddc7cb3baf75bccc8e04d9e83750a3af9fabd | /asg1/Examples/hashexample.scm | 0b6390f8760af5b6cb7e6f86a51d0c5909647838 | []
| 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 | 2,099 | scm | hashexample.scm | #!/afs/cats.ucsc.edu/courses/cmps112-wm/usr/racket/bin/mzscheme -qr
;; $Id: hashexample.scm,v 1.2 2014-10-31 17:35:08-07 - - $
;;
;; Another hash table example, showing insertion of variables,
;; vectors, and functions, and checking for lookup.
;; Note the script above uses -qr instead of -qC.
;;
;;
;; A little utility function to make printing easier.
;; Mz Scheme does have a printf function, but we'll stick to
;; standard Scheme here.
;;
(define (show label it)
(display label)
(display " = ")
(display it)
(newline)
)
;;
;; Create a hash table and put in some functions and variables.
;;
(define ht (make-hash))
(for-each
(lambda (item) (hash-set! ht (car item) (cadr item)))
`((var 34)
(print ,(lambda (x) (display x)(newline) ))
(+ ,(lambda (x y) (+ x y)))
(- ,(lambda (x y) (- x y)))
(* ,*)
(vec ,(make-vector 10 0.0)))
)
;;
;; Print the hash table.
;;
(hash-for-each ht (lambda (key value) (show key value)))
(newline)
;;
;; show the value of a simple variable.
;; the last argument #f causes hash-ref to return it
;; rather than crashing the program on failure to find.
;;
;(show "var" (hash-ref ht 'var #f))
;;
;; Set a vector element, print it, and the whole vector.
;;
(vector-set! (hash-ref ht 'vec #f) 5 3.1415926535)
;(show "vec[5]" (vector-ref (hash-ref ht 'vec) 5))
;(show "vec" (hash-ref ht 'vec #f))
;;
;; A couple more examples.
;;
;(show "(+ 3 4)" (apply (hash-ref ht '+ #f) '(3 4)))
;(show "not found" (hash-ref ht 'foo #f))
;;
;; The function evalexpr outlines how to evaluate a list
;; recursively.
;;
(define (evalexpr expr)
(cond ((number? expr) expr)
((symbol? expr) (hash-ref ht expr #f))
((string? expr) expr)
((pair? expr) (apply (hash-ref ht (car expr))
(map evalexpr (cdr expr))))
(else #f))
)
;;
;; Now print out the value of several expressions.
;;
(for-each
(lambda (expr) (evalexpr expr))
'( (print var)
(print "hullo" )
)
)
;;
;; Just to verify that we got all the way.
;;
(display "DONE.") (newline)
| false |
32f6656dbc3f4efaf55f139945cf0f0d02c14899 | 2bcf33718a53f5a938fd82bd0d484a423ff308d3 | /programming/sicp/ch2/ex-2.52.scm | a7c946ed00157c3817cbb2b56aeabf86e902be74 | []
| no_license | prurph/teach-yourself-cs | 50e598a0c781d79ff294434db0430f7f2c12ff53 | 4ce98ebab5a905ea1808b8785949ecb52eee0736 | refs/heads/main | 2023-08-30T06:28:22.247659 | 2021-10-17T18:27:26 | 2021-10-17T18:27:26 | 345,412,092 | 0 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 5,474 | scm | ex-2.52.scm | #lang sicp
;; https://mitpress.mit.edu/sites/default/files/sicp/full-text/book/book-Z-H-15.html#%_thm_2.52
(#%require sicp-pict)
;; original wave from http://community.schemewiki.org/?sicp-ex-2.49
;; 2.52(a) added segments to add a beak
(define wave-mod (segments->painter (list (make-segment (make-vect .25 0)
(make-vect .35 .5))
(make-segment (make-vect .35 .5)
(make-vect .3 .6))
(make-segment (make-vect .3 .6)
(make-vect .15 .4))
(make-segment (make-vect .15 .4)
(make-vect 0 .65))
(make-segment (make-vect 0 .65)
(make-vect 0 .85))
(make-segment (make-vect 0 .85)
(make-vect .15 .6))
(make-segment (make-vect .15 .6)
(make-vect .3 .65))
(make-segment (make-vect .3 .65)
(make-vect .4 .65))
(make-segment (make-vect .4 .65)
(make-vect .35 .85))
(make-segment (make-vect .35 .85)
(make-vect .4 1))
(make-segment (make-vect .4 1)
(make-vect .6 1))
(make-segment (make-vect .6 1)
(make-vect .65 .85))
(make-segment (make-vect .65 .85)
(make-vect .6 .65))
(make-segment (make-vect .6 .65)
(make-vect .75 .65))
(make-segment (make-vect .75 .65)
(make-vect 1 .35))
(make-segment (make-vect 1 .35)
(make-vect 1 .15))
(make-segment (make-vect 1 .15)
(make-vect .6 .45))
(make-segment (make-vect .6 .45)
(make-vect .75 0))
(make-segment (make-vect .75 0)
(make-vect .6 0))
(make-segment (make-vect .6 0)
(make-vect .5 .3))
(make-segment (make-vect .5 .3)
(make-vect .4 0))
(make-segment (make-vect .4 0)
(make-vect .25 0))
(make-segment (make-vect .48 .75)
(make-vect .50 .72))
(make-segment (make-vect .50 .72)
(make-vect .52 .75)))))
;; 2.52(b) altered corner-split pattern (requires up-split and right-split)
(define (right-split painter n)
(if (zero? n)
painter
(beside painter (below (right-split painter (- n 1))
(right-split painter (- n 1))))))
(define (up-split painter n)
(if (zero? n)
painter
(below painter (beside (up-split painter (- n 1))
(up-split painter (- n 1))))))
(define (corner-split-mod painter n)
(if (zero? n)
painter
(beside (below painter
(up-split painter (- n 1)))
(below (right-split painter (- n 1))
(corner-split-mod painter (- n 1))))))
;; 2.52(c) modified square-limit to make einstein look inward toward the center
(define (square-of-four tl tr bl br)
(lambda (painter)
(below (beside (bl painter) (br painter))
(beside (tl painter) (tr painter)))))
;; Original corner-split
(define (corner-split painter n)
(if (zero? n)
painter
(let ((up (up-split painter (- n 1)))
(right (right-split painter (- n 1))))
(let ((top-left (beside up up))
(bottom-right (below right right))
(corner (corner-split painter (- n 1))))
(beside (below painter top-left)
(below bottom-right corner))))))
;; Einstein faces right by default, so the identity painter should be in the
;; bottom-left
(define (square-limit-mod painter n)
(if (zero? n)
painter
((square-of-four flip-vert rotate180
(lambda (x) x) flip-horiz) (corner-split painter n))))
| false |
88d4d73ea2c644c1aa78569bfc4632c30e05d23b | 4b2aeafb5610b008009b9f4037d42c6e98f8ea73 | /11.1/11.1-1.scm | 12829c771ba3ab90f5911a990cb2175b89164252 | []
| 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 | 411 | scm | 11.1-1.scm | (require-extension syntax-case check)
(require '../11.1/section)
(import section-11.1)
;;; No key storage; empty on arbitrary nil (#f); requires Theta(m) to
;;; find max.
(let ((table (make-da-table 12)))
(da-insert! table (make-da-element 1 2))
(da-insert! table (make-da-element 4 4))
(da-insert! table (make-da-element 2 8))
(da-insert! table (make-da-element 9 16))
(check (da-max table) => 16))
| false |
07cee2a084f74862c8aa2c902a6baff9017bd796 | eef5f68873f7d5658c7c500846ce7752a6f45f69 | /doc/parser/silex-ffi-example/analyze.scm | c02365472d24dec71ef00c51d6161677436f46ce | [
"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 | 9,865 | scm | analyze.scm | ;;
;; autoffi - c header parser for generating ffi's
;;
;; util
(define (split-token done? token)
(let loop ((acc '())
(tok token))
(if (or (null? tok)
(done? tok))
(values (reverse acc) tok)
(loop (cons (car tok) acc)
(cdr tok)))))
;; numbers
(define (num-token? token)
(and (pair? token)
(eq? (car token) 'num)
(eq? (length token) 2)))
(define (make-num token)
(cadr token))
;; ids
(define (id-token? token)
(and (pair? token)
(eq? (car token) 'id)
(eq? (length token) 2)))
(define (make-id token)
(string->symbol (cadr token)))
;; pre-processor constants
(define (constant-token? token)
(and (pair? token)
(eq? (car token) 'pp-define)
(eq? (length token) 3)))
(define (make-constant-expr token)
(let ((id-token (cadr token))
(val-token (caddr token)))
(if (not (id-token? id-token))
(parser-error "invalid id: " id-token)
(let ((id (make-id id-token))
(val (cond
((id-token? val-token) (make-id val-token))
((num-token? val-token) (make-num val-token))
(else (parser-error
"invalid constant value: "
val-token)))))
(and val
`(define ,id ,(if (symbol? val)
`(lambda () ,val)
val)))))))
;; type keywords
(define types
'(bool
size_t
int
float
double
short
long
char
void))
(define type-keywords
'(bool
size_t
int
unsigned
signed
float
double
short
long
char
void
const
star
struct))
(define (primitive-type? token)
(memq token types))
(define (type-keyword? token)
(or (memq token type-keywords)
(id-token? token)))
(define (read-type-keywords done? token)
(split-token (lambda (tok)
(if (type-keyword? (car tok))
(done? tok)
#t))
token))
(assert (type-keyword? 'int))
(assert (type-keyword? 'struct))
(assert (type-keyword? '(id "idgen")))
;; types
(define (type-token? token)
(and (pair? token)
(fold (lambda (el r)
(and (type-keyword? el)
r))
#t
token)))
(define (symbolify-type token)
(map (lambda (el)
(if (id-token? el)
(make-id el)
el))
token))
(define (make-type token)
(define (symbol-append . args)
(let ((args (reverse args)))
(string->symbol
(fold (lambda (el r)
(string-append (symbol->string el) "-"
r))
(symbol->string (car args))
(cdr args)))))
(let loop ((acc '())
(pieces (reverse (if (eq? (car token) 'const)
(cdr token)
token))))
(if (null? pieces)
(parser-error "invalid type (no concrete type found): " token)
(if (eq? (car pieces) 'star)
`(pointer ,(loop acc (cdr pieces)))
(let ((rest (symbolify-type (reverse pieces))))
(if (eq? (car rest) 'struct)
`(struct ,(symbol->string (make-id (cadr token))))
(apply symbol-append rest)))))))
(assert (type-token? '(const unsigned int)))
(assert (type-token? '(const unsigned int err)) #f)
(assert (symbolify-type '(unsigned int)) '(unsigned int))
(assert (symbolify-type '((id "idgen"))) '(idgen))
(assert (make-type '(const unsigned int)) 'unsigned-int)
(assert (make-type '(const idgen)) 'idgen)
(assert (make-type '(unsigned int star star))
'(pointer (pointer unsigned-int)))
(assert (make-type '(struct (id "idgen")))
'(struct "idgen"))
(assert (make-type '((id "GLdouble") star))
'(pointer GLdouble))
;; typedefs
(define (typedef-token? token)
(and (pair? token)
(eq? (car token) 'typedef)))
(define (make-typedef-expr token)
(receive (type-token rest)
(read-type-keywords (lambda (tok)
(eq? (length tok) 1))
(cdr token))
(if (not (type-token? type-token))
(parser-error "invalid typedef type <" type-token "> in " token)
(let ((id-token (car rest)))
(if (not (id-token? id-token))
(parser-error "invalid typedef id <" id-token
"> in " token)
(let ((id (make-id id-token))
(type (make-type type-token)))
`(c-define-type ,id ,type)))))))
(assert (typedef-token? '(typedef const unsigned int fooint)))
(assert (typedef-token? '(typedef fooint foobar)))
(assert (make-typedef-expr '(typedef const unsigned int (id "fooint")))
'(c-define-type fooint unsigned-int))
(assert (make-typedef-expr '(typedef struct (id "bar") (id "bar")))
'(c-define-type bar (struct "bar")))
;; externs
(define (extern-token? token)
(and (pair? token)
(eq? (car token) 'extern)))
(assert (extern-token? '(extern unsigned int (id "foo") semicolon)))
;; functions
(define (function-token? token)
(and (pair? token)
(receive (type rest)
(read-type-keywords (lambda (tok)
(eq? (cadr tok) 'open-paren))
token)
(and (type-token? type)
(id-token? (car rest))
(> (length rest) 1)
(eq? (cadr rest) 'open-paren)))))
(assert (function-token? '(unsigned int (id "foo") open-paren close-paren)))
(define (strip-argument-name token)
(let ((has-primitive-type? (fold (lambda (el r)
(or (primitive-type? el)
r))
#f
token))
(num-ids (fold (lambda (el r)
(if (id-token? el) (+ r 1) r))
0
token)))
(if (or (and has-primitive-type?
(= num-ids 1))
(> num-ids 1))
(reverse (cdr (reverse token)))
token)))
(assert (strip-argument-name '(unsigned int)) '(unsigned int))
(assert (strip-argument-name '(unsigned int (id "arg"))) '(unsigned int))
(assert (strip-argument-name '(const (id "typeid") star))
'(const (id "typeid") star))
(assert (strip-argument-name '((id "typeid") (id "inst")))
'((id "typeid")))
(define (make-function-expr token)
(receive (ret-type-token token)
(read-type-keywords (lambda (tok)
(and (id-token? (car tok))
(eq? (cadr tok) 'open-paren)))
token)
(let ((id-token (car token))
(type-tokens (let loop ((acc '())
(tok (cddr token)))
(if (or (null? tok)
(eq? (car tok) 'close-paren))
(reverse acc)
(receive (head tail)
(split-token (lambda (tok)
(or (eq? (car tok) 'comma)
(eq? (car tok) 'close-paren)
(eq? (car tok) 'open-paren)))
(if (eq? (car tok) 'comma)
(cdr tok)
tok))
(if (eq? (car tail) 'open-paren)
(begin (parser-error "invalid function argument type "
"(function callbacks are not supported) ")
(parser-error "token: " token)
(loop '() '()))
(loop (cons (strip-argument-name head) acc)
tail)))))))
(if (not (null? type-tokens))
(let ((ret-type (make-type ret-type-token))
(id (make-id id-token))
(types (map make-type type-tokens)))
`(define ,id
(c-lambda ,(if (equal? types '(void)) '() types)
,ret-type
,(symbol->string id))))))))
(assert (make-function-expr '(unsigned int (id "foo")
open-paren float comma
unsigned int close-paren))
'(define foo (c-lambda (float unsigned-int) unsigned-int "foo")))
(assert (make-function-expr '(unsigned int (id "foo")
open-paren (id "idgen") star (id "inst")
comma unsigned int close-paren))
'(define foo (c-lambda ((pointer idgen) unsigned-int) unsigned-int "foo")))
;; entry
(define (analyze #!optional
(input-port (current-input-port))
(output-port (current-output-port)))
(define (maybe-write-expr expr)
(if expr
(begin
(write expr output-port)
(newline output-port))))
(let loop ()
(let ((token (read input-port)))
(if (not (eq? token #!eof))
(let ((token (if (extern-token? token)
(cdr token)
token)))
(cond
((constant-token? token)
(maybe-write-expr (make-constant-expr token)))
((typedef-token? token)
(maybe-write-expr (make-typedef-expr token)))
((function-token? token)
(maybe-write-expr (make-function-expr token))))
(loop))))))
| false |
2e29abad390c314bef4c6dc65576dab64fc10f10 | defeada37d39bca09ef76f66f38683754c0a6aa0 | /mscorlib/system/runtime/versioning/versioning-helper.sls | 2c73b31f4e774b8874223deab9b96b8faf199367 | []
| 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 | 742 | sls | versioning-helper.sls | (library (system runtime versioning versioning-helper)
(export is? versioning-helper? make-version-safe-name)
(import (ironscheme-clr-port))
(define (is? a) (clr-is System.Runtime.Versioning.VersioningHelper a))
(define (versioning-helper? a)
(clr-is System.Runtime.Versioning.VersioningHelper a))
(define-method-port
make-version-safe-name
System.Runtime.Versioning.VersioningHelper
MakeVersionSafeName
(static:
System.String
System.String
System.Runtime.Versioning.ResourceScope
System.Runtime.Versioning.ResourceScope
System.Type)
(static:
System.String
System.String
System.Runtime.Versioning.ResourceScope
System.Runtime.Versioning.ResourceScope)))
| false |
fad7afa2dc28282c501dae3d523bb329e77c50ca | b9eb119317d72a6742dce6db5be8c1f78c7275ad | /racket/dealer.ss | 1553df3640b04ca2b63ffb0a9874000bd8bc7139 | []
| 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 | 455 | ss | dealer.ss | #lang scheme
(require srfi/1
srfi/26
(planet offby1/offby1/shuffle)
(planet "multiply.scm" ("offby1" "offby1.plt")))
(for/fold ([hands (make-immutable-hash '())])
([h (in-list (circular-list 'north 'east 'south 'west))]
[c (in-list (shuffle (multiply (list (list 'spade 'heart 'diamond 'club)
(build-list 13 (cut + 2 <>))))))])
(hash-update hands h (cut cons c <>) '()))
| false |
75d392cbe92ab87086a7ba28813d608721df09fe | 0ffe5235b0cdac3846e15237c2232d8b44995421 | /src/scheme/Section_1.1/1.02.scm | a8ce0271ce20f2f1a4d0d5ee5f4450c518d57c08 | []
| no_license | dawiedotcom/SICP | 4d05014ac2b075b7de5906ff9a846e42298fa425 | fa6ccac0dad8bdad0645aa01197098c296c470e0 | refs/heads/master | 2020-06-05T12:36:41.098263 | 2013-05-16T19:41:38 | 2013-05-16T19:41:38 | null | 0 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 11 | scm | 1.02.scm | ; sicp 1.2
| false |
db2fb03369873c83ebb42592154d8e2dfdefd36d | 404799b4b2d5f83ee5304392826a69defc25da77 | /ex2-70.scm | d42c688d8b5c9903daeb10c0d7b00d10a7d1601b | []
| 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 | 260 | scm | ex2-70.scm | ;;; Exercise 2.70
(load "huffman-tree.scm")
(load "ex2-69.scm")
(load "ex2-68.scm")
(define alphabet '((BOOM 1) (WAH 1) (A 2) (GET 2) (JOB 2) (SHA 3) (YIP 9) (NA 16)))
(encode '(Get a job Sha na na na na na na na na) (generate-huffman-tree
alphabet))
| false |
e8b6c0cb4662dfdebfa1bef21ba5b862d3d7e868 | abc7bd420c9cc4dba4512b382baad54ba4d07aa8 | /src/old/chez/chez_constants.ss | 090548d6a8bd3c7860d97c0eb96ba4df8adbe541 | [
"BSD-3-Clause"
]
| permissive | rrnewton/WaveScript | 2f008f76bf63707761b9f7c95a68bd3e6b9c32ca | 1c9eff60970aefd2177d53723383b533ce370a6e | refs/heads/master | 2021-01-19T05:53:23.252626 | 2014-10-08T15:00:41 | 2014-10-08T15:00:41 | 1,297,872 | 10 | 2 | null | null | null | null | UTF-8 | Scheme | false | false | 6,430 | ss | chez_constants.ss | ;;;; constants.ss
;;;; These are the chez specific constant/datatype definitions.
;======================================================================
;; Could be define-structure or define-record. <br>
;; This defines the record-representation used throughout the regiment code. <br>
;; UNCOMMENT ONLY ONE OF THESE.
;======================================================================
(chez:module chez_constants
;; Exports:
( reg:struct? reg:struct->list reg:list->struct reg:define-struct
reg:include
;IFCHEZ IF_GRAPHICS IF_THREADS
cond-expand
hash-percent path->string
)
(import scheme)
;; [2007.12.27] Considering switching over to a cond-expand system.
(define-syntax cond-expand
(lambda (syn)
(syntax-case syn (and or not else chez plt larceny r6rs r5rs graphics threads)
;; Standard clauses:
((cond-expand) (syntax-error #'syn "Unfulfilled cond-expand"))
((cond-expand (else body ...)) #'(begin body ...))
((cond-expand ((and) body ...) more-clauses ...) #'(begin body ...))
((cond-expand ((and req1 req2 ...) body ...) more-clauses ...)
#'(cond-expand (req1 (cond-expand ((and req2 ...) body ...) more-clauses ...)) more-clauses ...))
((cond-expand ((or) body ...) more-clauses ...) #'(cond-expand more-clauses ...))
((cond-expand ((or req1 req2 ...) body ...) more-clauses ...)
#'(cond-expand (req1 (begin body ...)) (else (cond-expand ((or req2 ...) body ...) more-clauses ...))))
((cond-expand ((not req) body ...) more-clauses ...)
#'(cond-expand (req (cond-expand more-clauses ...)) (else body ...)))
;; Enabled features (or potentially enabled):
((cond-expand (chez body ...) more-clauses ...) #'(begin body ...))
((cond-expand (graphics body ...) more-clauses ...)
(if (getenv "SWL_ROOT") #'(begin body ...)
#'(cond-expand more-clauses ...)))
((cond-expand (threads body ...) more-clauses ...)
(if (top-level-bound? 'fork-thread)
#'(begin body ...)
#'(cond-expand more-clauses ...)))
;; Otherwise, it's disabled:
((cond-expand (feature-id body ...) more-clauses ...) #'(cond-expand more-clauses ...)))))
;; This is a common syntax for including other source files inline.
;; I use it in both PLT and Chez.
;; DOESN'T WORK YET!!! (Not in PLT. Sigh.) [2006.03.13]
(define-syntax reg:include
(lambda (x)
(syntax-case x (REGIMENTD)
[(_ str* ...)
(let ([lst (datum (str* ...))])
(unless (andmap string? lst)
(error 'reg:include "bad syntax, expects strings: ~a\n" lst))
(with-syntax ([file (datum->syntax-object
#'_
(apply string-append
(cons (getenv "REGIMENTD")
(cons "/src"
(map (lambda (str)
(string-append "/" str))
lst)))))])
#'(include file)))])))
; Defined using RECORDS:
; ======================================================================
;; This version uses generative records and should work if you want to use it.
(define-syntax reg:define-struct
(syntax-rules ()
[(_ (name field ...))
(begin (define-record name (field ...))
;; Allows the reader to read in regiment records. System should work without this:
(define reg:struct-dummy-val (record-reader 'name (type-descriptor name)))
)]))
;; [2006.02.23] <br>
;; This is a new version which makes records non-generative so that
;; they can be marshalled to and from files without binary
;; incompatibilities.. <br><br>
;; [2006.02.24] <br>
;; This works but it is too harsh a restriction to require each name
;; to only be defined once. What if I wish to run too simulations
;; in a row!
;; Instead my approach will be, if I really need to unmarshal
;; records, I will convert them upon reading to the newer records by
;; read/writing them to a string buffer!!
#;
(define-syntax (reg:define-struct x)
(define (uniquify-symbol x) (read (open-input-string (format "#{~s ~:*~s}" x))))
(syntax-case x ()
[(_ (name fields ...))
;; Switch between these to use define-structure instead if you like:
(with-syntax ([newname (datum->syntax-object #'_(uniquify-symbol (datum name)))]
;[genned (datum->syntax-object #'_ (gensym))]
)
#'(begin (define-record newname (fields ...))
;; Also make it read with the plain name.
(define reg:struct-dummy-val (record-reader 'name (type-descriptor newname)))
))
]))
(define reg:struct? record?)
;; Uses introspection to make a record spill its guts.
;; [2006.03.01] Modified this to add the record name in the front.
(define (reg:struct->list x)
(let ((type (#%record-type-descriptor x)))
(cons (string-copy (record-type-name type))
(map (lambda (name)
((#%record-field-accessor type name) x))
(#%record-type-field-names type)))))
;; This constructs a new record, given an instance of the record type.
(define (reg:list->struct template args)
(let ((type (record-type-descriptor template)))
(apply (record-constructor type)
args)))
;; Defined using
;;======================================================================
#|
(begin ;; This begin-block defines structs's as chez structures (vectors).
(define reg:define-struct_name-table (make-hash-table))
(define-syntax reg:define-struct
(syntax-rules ()
[(_ (name field ...))
(begin (define-structure (name field ...))
(define reg:struct-dummy-val
(put-hash-table! reg:define-struct_name-table 'name (void))))]))
(define reg:struct?
(let ([lookup-failure (gensym)])
(lambda (x)
(and (vector? x)
(>= (vector-length x) 1)
(not (eq? (get-hash-table reg:define-struct_name-table
(vector-ref x 0) lookup-failure)
lookup-failure))))))
(define (reg:struct->list x) (cdr (vector->list x)))
)
|#
;; This is a hack to emulate Chez's #%prim syntax without breaking
;; other readers that can't handle it.
(define-syntax (hash-percent syn)
(syntax-case syn ()
[(_ prim) (datum->syntax-object #'_ `(let () (import scheme) ,(datum prim)))]))
;; MISC: This is for PLT compat:
(define path->string (lambda (x) x))
) ;; End module
(include "../generic/constants.ss")
(import constants) ;; Certain bindings are re-exported through the generic module.
| true |
9098501efddc7ad6aac7e96f7d160f2c3ee2366d | 46244bb6af145cb393846505f37bf576a8396aa0 | /sicp/2_12.scm | 246af6858c2e2ab95d12fbb86ca9874fef1f2cb0 | []
| no_license | aoeuidht/homework | c4fabfb5f45dbef0874e9732c7d026a7f00e13dc | 49fb2a2f8a78227589da3e5ec82ea7844b36e0e7 | refs/heads/master | 2022-10-28T06:42:04.343618 | 2022-10-15T15:52:06 | 2022-10-15T15:52:06 | 18,726,877 | 4 | 3 | null | null | null | null | UTF-8 | Scheme | false | false | 604 | scm | 2_12.scm | #lang racket
; Exercise 2.12. Define a constructor make-center-percent that takes a center and a percentage
; tolerance and produces the desired interval.
; You must also define a selector percent that produces the percentage tolerance for a given interval.
; The center selector is the same as the one shown above.
(define (make-center-width c w)
(make-interval (- c w) (+ c w)))
(define (center i)
(/ (+ (lower-bound i) (upper-bound i)) 2))
(define (width i)
(/ (- (upper-bound i) (lower-bound i)) 2))
;
(define (make-center-percent c p)
(let ((w (* c p 0.01)))
(make-center-width c w))) | false |
64cbf4a2465980c9b0f1eaba6baf0a4459f32002 | 174072a16ff2cb2cd60a91153376eec6fe98e9d2 | /Chap-Three/3-65.scm | 99e77b452a8f49b5b354302833d94c14d29b8449 | []
| no_license | Wang-Yann/sicp | 0026d506ec192ac240c94a871e28ace7570b5196 | 245e48fc3ac7bfc00e586f4e928dd0d0c6c982ed | refs/heads/master | 2021-01-01T03:50:36.708313 | 2016-10-11T10:46:37 | 2016-10-11T10:46:37 | 57,060,897 | 1 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 360 | scm | 3-65.scm | (load "3-5-3.scm")
(define (ln2-series n) (cons-stream (/ 1 n) (stream-map - (ln2-series (+ n 1)))))
(define ln2 (scale-stream (partial-sums (ln2-series 1)) 1.00))
;(display-stream (stream-section ln2 0 10))
;(display-stream (stream-section (euler-transform ln2) 0 10))
;(display-stream (stream-section (accelerated-sequence euler-transform ln2) 0 10))
| false |
9d75650f5efa8e00496e7d572e5bcdf16f65295d | 174072a16ff2cb2cd60a91153376eec6fe98e9d2 | /Chap-Three/3-5-1.scm | 85199a66f1ea25cdfc51edb5eb03955b6a3845ec | []
| no_license | Wang-Yann/sicp | 0026d506ec192ac240c94a871e28ace7570b5196 | 245e48fc3ac7bfc00e586f4e928dd0d0c6c982ed | refs/heads/master | 2021-01-01T03:50:36.708313 | 2016-10-11T10:46:37 | 2016-10-11T10:46:37 | 57,060,897 | 1 | 0 | null | null | null | null | UTF-8 | Scheme | false | false | 417 | scm | 3-5-1.scm | ;;;p223
(load "make-stream.scm")
(define (stream-enumerate-interval low high)
(if (> low high) '()
(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)))))
| false |
4b3bb86666ece7e6adda97011e6b229c1ded319a | 4f30ba37cfe5ec9f5defe52a29e879cf92f183ee | /src/tests/implambda.scm | 1d3c66320a2d7ecf9021d76d4383893eea18e442 | [
"MIT"
]
| permissive | rtrusso/scp | e31ecae62adb372b0886909c8108d109407bcd62 | d647639ecb8e5a87c0a31a7c9d4b6a26208fbc53 | refs/heads/master | 2021-07-20T00:46:52.889648 | 2021-06-14T00:31:07 | 2021-06-14T00:31:07 | 167,993,024 | 8 | 1 | MIT | 2021-06-14T00:31:07 | 2019-01-28T16:17:18 | Scheme | UTF-8 | Scheme | false | false | 160 | scm | implambda.scm | (define (func a . b)
(display 456)
(newline)
(display a)
(newline)
(display 123)
(newline))
(display 0)
(newline)
(func 0)
(func 1 2)
(func 2 3 4)
| false |
ba7fc4b75a084959deabca8f3cd189cc459b26dc | 8a7ed1d08cd49c097533e42c5e0b79627c868eb1 | /debug.scm | 9c0f875028b0e005245fb4ce9f6a566a2a48a800 | []
| no_license | klutometis/debug | 9c2469327474f175ba2eb4f75b0ff3c8bc7c1631 | 933f63c71f57ff9c7039af29ddff1d127666dd9d | refs/heads/master | 2020-06-01T19:14:50.796811 | 2015-05-11T23:29:04 | 2015-05-11T23:29:04 | 1,453,964 | 4 | 0 | null | 2014-06-21T22:54:35 | 2011-03-08T09:29:34 | Scheme | UTF-8 | Scheme | false | false | 394 | scm | debug.scm | (module debug
(debug
debug?
debug/syslog
debug-priority
make-syslog-port
trace)
(import chicken
scheme
extras
data-structures
srfi-13)
(import-for-syntax data-structures
ports
matchable
srfi-13)
(use ports
srfi-13
syslog)
(include "debug-core.scm"))
| false |
77c398f4669db1690a3b76c9a6bf578555872cad | 0768e217ef0b48b149e5c9b87f41d772cd9917f1 | /demo/freetype-demo.scm | 1512737cb54dfd5c06747e5084d8d07db882a275 | [
"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 | 5,128 | scm | freetype-demo.scm | ;; ./ypsilon --r6rs --top-level-program demo/freetype-demo.scm
(import (rnrs)
(rnrs programs)
(ypsilon glcorearb)
(ypsilon glfw)
(ypsilon view)
(ypsilon c-ffi)
(ypsilon c-types)
(ypsilon freetype)
(only (core) format mat4x4-identity mat4x4-rotate mat4x4-ortho mat4x4-mul))
(define-record-type Renderable (fields program vao vbo renderer))
(define-record-type Glyph (fields ch texture size.x size.y bearing.x bearing.y advance))
(define make-string-pane
(lambda ()
(define vs-source "
#version 110
uniform mat4 u_mvp;
uniform vec2 u_scale;
uniform vec2 u_offset;
attribute vec2 a_pos;
attribute vec2 a_texcoord0;
varying vec2 v_texcoord0;
void main()
{
gl_Position = u_mvp * vec4(a_pos * u_scale + u_offset, 0.0, 1.0);
v_texcoord0 = a_texcoord0;
}
")
(define fs-source "
#version 110
varying vec2 v_texcoord0;
uniform sampler2D text;
void main()
{
gl_FragColor = vec4(0.0, texture2D(text, v_texcoord0).r, 0.0, 1.0);
}
")
(define vertices
(let ((verts
`(0.0 1.0 0.0 0.0
1.0 0.0 1.0 1.0
0.0 0.0 0.0 1.0
0.0 1.0 0.0 0.0
1.0 1.0 1.0 0.0
1.0 0.0 1.0 1.0)))
(let ((bv (make-bytevector (* 24 4))))
(let loop ((i 0) (verts verts))
(cond ((null? verts) bv)
(else
(bytevector-ieee-single-native-set! bv i (car verts))
(loop (+ i 4) (cdr verts))))))))
(define program (init-program vs-source fs-source))
(define vao (make-vao))
(define vbo (make-vbo vao vertices GL_ARRAY_BUFFER GL_STATIC_DRAW))
(define fonts
(let ((ht (make-eq-hashtable)))
(let-values (((face glyphs) (load-font-textures "demo/Roboto-Regular.ttf" 300)))
(begin0
ht
(for-each (lambda (glyph) (hashtable-set! ht (car glyph) (apply make-Glyph glyph))) glyphs)))))
(define renderer
(lambda (mvp scale x y s)
(glUseProgram program)
(glBindVertexArray vao)
(let loop ((s (string->list s)) (x x) (y y))
(or (null? s)
(let* ((ch (car s)) (glyph (hashtable-ref fonts ch #f)))
(if glyph
(let ((texture (Glyph-texture glyph)))
(glBindTexture GL_TEXTURE_2D texture)
(program-uniform-max4x4-set! program "u_mvp" mvp)
(program-uniform-vec2-set! program "u_scale" (* scale (Glyph-size.x glyph)) (* scale (Glyph-size.y glyph)))
(program-uniform-vec2-set!
program
"u_offset"
(+ x (* scale (Glyph-bearing.x glyph)))
(- y (* scale (- (Glyph-size.y glyph) (Glyph-bearing.y glyph)))))
(glDrawArrays GL_TRIANGLES 0 6)
(loop (cdr s) (+ x (* scale (Glyph-advance glyph))) y))
(loop (cdr s) x y)))))))
(enable-vertex-attribute program vao vbo GL_ARRAY_BUFFER "a_pos" 2 GL_FLOAT GL_FALSE 16 0)
(enable-vertex-attribute program vao vbo GL_ARRAY_BUFFER "a_texcoord0" 2 GL_FLOAT GL_FALSE 16 8)
(make-Renderable program vao vbo renderer)))
(define main
(lambda ()
(define error-callback
(lambda (error description)
(format #t "error: ~a~%~!" (utf8->string (make-bytevector-mapping description 1024)))))
(define key-callback
(lambda (window key scancode action mods)
(and (= key GLFW_KEY_ESCAPE)
(= action GLFW_PRESS)
(glfwSetWindowShouldClose window GLFW_TRUE))))
(glfwSetErrorCallback (c-callback void (int void*) error-callback))
(let ((window (init-window 256 192 "Ypsilon")))
(glfwSetKeyCallback window (c-callback void (void* int int int int) key-callback))
(glfwMakeContextCurrent window)
(glfwSwapInterval 1)
(let ((m (make-bytevector 64))
(p (make-bytevector 64))
(mvp (make-bytevector 64))
(width (make-c-int 0))
(height (make-c-int 0))
(model (make-string-pane)))
(let loop ()
(cond ((= (glfwWindowShouldClose window) 0)
(glfwGetFramebufferSize window width height)
(glViewport 0 0 (c-int-ref width) (c-int-ref height))
(glClear GL_COLOR_BUFFER_BIT)
(mat4x4-identity m)
(mat4x4-rotate m m 0 0 -1 (glfwGetTime))
(let ((ratio (/ (inexact (c-int-ref width)) (inexact (c-int-ref height)))))
(mat4x4-ortho p (- ratio) ratio -1 1 1 -1))
(mat4x4-mul mvp p m)
((Renderable-renderer model) mvp 0.3 -1.0 -0.1 "Hello Ypsilon")
(glfwSwapBuffers window)
(glfwPollEvents)
(loop))
(else
(glfwDestroyWindow window) (glfwTerminate) (exit 0))))))))
(main)
| false |
1c2b50bb539298a35c8e7762db4b787c358e3328 | defeada37d39bca09ef76f66f38683754c0a6aa0 | /UnityEngine/unity-engine/occlusion-area.sls | b78d7e315ac4bf928f50b7b836ba19f1f24fe430 | []
| 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 | 808 | sls | occlusion-area.sls | (library (unity-engine occlusion-area)
(export new
is?
occlusion-area?
center-get
center-set!
center-update!
size-get
size-set!
size-update!)
(import (ironscheme-clr-port))
(define-syntax new
(lambda (e)
(syntax-case e ()
((_ a ...) #'(clr-new UnityEngine.OcclusionArea a ...)))))
(define (is? a) (clr-is UnityEngine.OcclusionArea a))
(define (occlusion-area? a) (clr-is UnityEngine.OcclusionArea a))
(define-field-port
center-get
center-set!
center-update!
(property:)
UnityEngine.OcclusionArea
center
UnityEngine.Vector3)
(define-field-port
size-get
size-set!
size-update!
(property:)
UnityEngine.OcclusionArea
size
UnityEngine.Vector3))
| true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.