Skip to content

Instantly share code, notes, and snippets.

View shirok's full-sized avatar

Shiro Kawai shirok

View GitHub Profile
(defun arabic->roman (n) (if (< 0 n 4000) (format nil "~@R" n) (error "oob")))
(let ((tab (loop for n from 1 to 3999 collect `(,(format nil "~@R" n) . ,n))))
(defun roman->arabic (r) (or (cdr (assoc r tab :test #'equalp)) (error "huh?"))))
@shirok
shirok / gist:1172508
Created August 26, 2011 01:47
converting json to N-triples
#!/usr/bin/env gosh
;; A quick-and-dirty hack to convert json to N-triples format.
;; Usage: <script-name> x.json y.json ...
;; The output is written to stdout.
;; NB: JSON itself isn't as strict as other format; especially,
;; the meanings of literals and predicates aren't uniquely identifierd
;; in the json file (i.e. json object may have an property "title", but
;; does it mean <http://purl.org/dc/elements/1.1/title>, or some application-
diff --git a/src/system.c b/src/system.c
index ba35faa..cb7a0eb 100644
--- a/src/system.c
+++ b/src/system.c
@@ -1071,9 +1071,11 @@ struct timespec *Scm_GetTimeSpec(ScmObj t, struct timespec *spec)
spec->tv_sec = ct->sec;
#endif /*!SCM_EMULATE_INT64*/
spec->tv_nsec = ct->nsec;
- if (SCM_EXACTP(t)) {
+ if (SCM_INTP(t)) {
--- a/src/number.c
+++ b/src/number.c
@@ -37,6 +37,7 @@
#include "gauche/scmconst.h"
#include "gauche/bits.h"
#include "gauche/builtin-syms.h"
+#include "gauche/arith.h"
#include <limits.h>
#include <float.h>
gosh> (define-syntax for
(syntax-rules (in do)
((for var in lis do expr ...)
(let loop ((xs lis))
(if (not (null? xs))
(begin (let ((var (car xs))) expr ...)
(loop (cdr xs))))))))
#<undef>
gosh> (for x in '(1 2 3 4 5) do (print (* x x)))
1
diff --git a/ext/net/test.scm b/ext/net/test.scm
index b41a607..478be42 100644
--- a/ext/net/test.scm
+++ b/ext/net/test.scm
@@ -288,29 +288,36 @@
(use gauche.process)
+;; sockargs is an expression that yields to a list of server sockets
(define (run-simple-server sockargs)
(define (count xs)
(if (or (null? xs)
(null? (cdr xs)))
0
(let ([minimum (apply min xs)])
(cond
[(= minimum (first xs)) (count (cdr xs))]
[(= minimum (last xs)) (+ 1 (count (cdr (reverse xs))))]
[else (let loop ([L '()] [R xs])
(if (= minimum (car R))
(use gauche.sequence) ; for fold2
(define-macro (tagbody . body)
(let ([entry (gensym)] ;implicit label for the entry
[escape (gensym)])
(receive (segments rest)
(fold2 (^(f ss fs)
(if (symbol? f)
(values (cons (reverse `((,f ,escape) ,@fs)) ss) (list f))
(values ss (cons f fs))))
(define (tak x y z)
(if (not (< y x))
z
(tak (tak (- x 1) y z)
(tak (- y 1) z x)
(tak (- z 1) x y))))
(define (main args)
(display (tak 24 18 6))
(newline)
;; ストリーミングの受け取り方
;; httpレスポンスに対して呼ばれる。
;; - code : httpステータスコード
;; - headers : レスポンスヘッダ ((name value) ...)
;; - total : レスポンス全体のサイズ。streamingの場合はわからないので#fになってるはず
;; - retrieve : レスポンスボディを受け取るための手続き。後述。
(define (stream-receiver code headers total retrieve)
;; codeをチェック。200以外なら適切な処置を。