Skip to content

Instantly share code, notes, and snippets.

View shirok's full-sized avatar

Shiro Kawai shirok

View GitHub Profile
;; begin reference implementation
(define (string-split s delimiter . args)
;; The argument checking part might be refactored with other srfi-130
;; routines.
(unless (string? s) (error "string expected" s))
(unless (string? delimiter) (error "string expected" delimiter))
(let ((slen (string-length s)))
(receive (grammar limit no-limit start end)
(if (pair? args)
(if (pair? (cdr args))
(use util.match)
(use data.random)
(define (zndoco)
(let loop ([s (generator->lseq (samples$ '("ズン" "ドコ")))])
(match s
[("ズン" "ズン" "ズン" "ズン" "ドコ" . _)
(for-each display (take s 5)) (print "キ・ヨ・シ!")]
[(x . xs) (display x) (loop xs)])))
(use gauche.process)
(use rfc.http)
(define (spawn-and-talk-to-server)
(let* ([p (run-process '("gosh" "./server-script.scm") :wait #f :output :pipe)]
[s (read-line (process-output p))])
(unwind-protect
(and (string? s) (#/^\d+$/ s)
(http-get #"localhost:~s" "/"))
(process-kill p)
(use makiki)
(use gauche.net)
(define (main args)
(start-http-server :port 0 :startup-callback echo-server-info))
(define (echo-server-info server-socks)
(print (any (^s (sockaddr-port (socket-address s))) server-socks))
(flush))
diff --git a/src/gauche/win-compat.h b/src/gauche/win-compat.h
index c0a1ec6..50cd556 100644
--- a/src/gauche/win-compat.h
+++ b/src/gauche/win-compat.h
@@ -146,11 +146,11 @@ int sigaction(int signum, const struct sigaction *act, struct sigaction *oact);
/* Implementation of Scm_MBS2WCS/WCS2MBS is in win-compat.c */
#if defined(LIBGAUCHE_BODY)
-extern __declspec(dllexport) WCHAR *Scm_MBS2WCS(const char *s);
-extern __declspec(dllexport) const char *Scm_WCS2MBS(const WCHAR *s);
(define-module data.ftree-map
(use util.match)
(use gauche.record)
(use srfi-114)
(export make-ftree-map ftree-map?
ftree-map-empty?
ftree-map-exists? ftree-map-get ftree-map-put)
)
(select-module data.ftree-map)
(defun factor (n)
(loop for i from 2 to n
if (zerop (mod n i))
return `(,i ,@(factor (/ n i)))))
;; -*- coding:utf-8 -*-
(use util.match)
(use data.random)
(set! (random-data-seed) (sys-time))
(define *parts* (map (^s (cons s (string-length s))) '("進捗" "どう" "です" "か")))
(define index-gen (integers$ (length *parts*)))
(define *stream* (generator->lseq (^[] (~ *parts* (index-gen)))))
(let loop ([s *stream*] [cnt 0])
gosh> (use math.const)
#<undef>
gosh> (define (foo) pi)
foo
gosh> (define pi 3)
pi
gosh> (foo)
3.141592653589793
(use gauche.sequence)
(use gauche.lazy)
(use math.prime)
(use srfi-1)
(define-constant *bound* (- (expt 2 31) 1))
(define (solve)
(let* ([reverse-primes (reverse! (take-while (^p (<= p *bound*)) *primes*))]
[total (length reverse-primes)])