This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(use gauche.generator) | |
; | |
#| | |
Scheme:generatorとdoとwhile | |
http://practical-scheme.net/wiliki/wiliki.cgi?Scheme%3agenerator%e3%81%a8do%e3%81%a8while#H-17qe7ru | |
|# | |
(define (generator-generate proc) | |
(define next #f) | |
(define return #f) | |
(lambda () |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(use util.match) | |
(use srfi-1) | |
(define-macro (def proc . xs) | |
(let loop ([xs xs] [clauses '()]) | |
(if (null? xs) | |
`(define ,proc (match-lambda* ,@(reverse clauses))) | |
(receive (args rest) (break ($ eq? '-> $) xs) | |
(loop (cddr rest) | |
(cons (list args (cadr rest)) clauses)))))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; -*- coding:utf-8 -*- | |
(use srfi-60) ; integer->list | |
;; "3:5b8" -> ((#f #t #f) (#t #t #f) (#t #t #t)) | |
(define (parse input) | |
(rxmatch-let (#/^(\d+):([\da-fA-F]+)/ input) (_ ssize data) | |
(let1 size (x->integer ssize) | |
($ (cut take <> size) $ (cut slices <> size) | |
$ integer->list (string->number data 16) (* 4 (string-length data)))))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(define (map_ proc lis) | |
(map1 proc lis 0)) | |
(define (map1 proc lis n) | |
(cond [(null? lis) '()] | |
[(> n 30) (reverse (fold (^[elt r] (cons (proc elt) r)) '() lis))] | |
[else (cons (proc (car lis)) (map1 proc (cdr lis) (+ n 1)))])) | |
#| | |
gosh> (use gauche.time) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; モジュールgauche.baseがr7rsを読まないと定義されないので、読んどく (次のバージョンで直す) | |
(require "r7rs") | |
;; gauche.baseから不要なもの以外をインポート | |
(import (gauche.base :except (quote))) | |
;; 継承を切る | |
(extend) | |
;; define => #<syntax define> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defvar orig-list-reader (get-macro-character #\()) | |
(set-macro-character #\( (lambda (stream ch) | |
(let ((lis (funcall orig-list-reader stream ch))) | |
(if (eq (car lis) 'comment) (values) lis)))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/class.c b/src/class.c | |
index cdebd2c..9b6a1e3 100644 | |
--- a/src/class.c | |
+++ b/src/class.c | |
@@ -2701,6 +2701,11 @@ static void accessor_method_slot_accessor_set(ScmAccessorMethod *m, ScmObj v) | |
* Foreign pointer mechanism | |
*/ | |
+/* foreign pointer instance flags */ | |
+enum { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(define-library (scheme linear-algebra) | |
(import (rename (scheme base) (* r7rs:*))) | |
(export *) | |
(begin | |
(define (* x y) | |
(if (or (array? x) (array? y)) | |
(array-multiplication x y) | |
(r7rs:* x y))) | |
(define (array? obj) ...) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(use gauche.sequence) | |
;; (xrotate '(x a b c d e) 3) -> (a b c x d e) etc. | |
(define (xrotate lis n) | |
`(,@(subseq lis 1 (+ n 1)) ,(car lis) ,@(drop lis (+ n 1)))) | |
(define (digit->column n) | |
`(#\# ,@(xrotate '(#\o #\|) (div n 5)) #\# ,@(xrotate '(#\| #\o #\o #\o #\o) (mod n 5)) #\#)) | |
(define (num->columns num width) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
gosh> (let-syntax ((foo (syntax-rules () ((_ a) (quote (a a)))))) | |
(%macroexpand (foo foo))) | |
(#<identifier user#quote.1c06de0> (foo foo)) |