Skip to content

Instantly share code, notes, and snippets.

View athos's full-sized avatar
🤷‍♂️
I know the value and cost of nothing

Shogo Ohta athos

🤷‍♂️
I know the value and cost of nothing
View GitHub Profile
@athos
athos / gist:120598
Created May 30, 2009 18:32
this script enables gosh to call the external commands as a function without any definitions.
#!/usr/bin/env gosh
(use gauche.process)
(use srfi-1)
(use srfi-13)
(define (tree-filter f tree)
(define (rec t s)
(cond [(null? t) s]
[(pair? t) (rec (car t) (rec (cdr t) s))]
@athos
athos / Portfile
Created July 10, 2009 07:37
a MacPorts Portfile for tmux 0.9
# $Id: $
PortSystem 1.0
name tmux
version 0.9
categories sysutils
maintainers athos
description terminal multiplexer
long_description \
(define-module breakpoint
(use gauche.parameter)
(export bp bp-enabled? inspect set!-inspect resume reset))
(select-module breakpoint)
(define %inspect #f)
(define %set!-inspect #f)
(define %cont #f)
;; 第1回 Scheme コードバトン
;;
;; ■ これは何か?
;; Scheme のコードをバトンのように回していき面白い物ができあがるのを楽しむ遊びです。
;; 次回 Shibuya.lisp で成果を発表します。
;; Scheme 初心者のコードを書くきっかけに、中級者には他人のコードを読む機会になればと思います。
;;
;; ■ 2 つのルール
;;
;; (1)自分がこれだと思える変更をコードに加えて2日以内に次の人にまわしてください。
@athos
athos / my-do.scm
Created May 24, 2010 21:04
destructive version of `do' macro
;; destructive version of `do' macro
;; (my-do ([x 1 y] [y 1 (+ x y)])
;; ((> x 30) #f)
;; (print x))
;;
;; is expanded as below:
;;
;; (let ([x 1] [y 1])
;; (let loop ()
-module(hanoi).
-compile(export_all).
hanoi(N) ->
hanoi(N, a, c, [], fun lists:reverse/1).
hanoi(0, _, _, Moves, K) ->
K(Moves);
hanoi(N, From, To, Moves, K) ->
[Temp] = [a,b,c] -- [From, To],
;; delayed tree structure for representing brainfuck's ``memory''
(define (make-tree n)
(define (rec start n)
(delay
(if (= n 1)
0
(let* ([n/2 (ceiling (/ n 2))]
[n-n/2 (- n n/2)])
(list (- n/2 1) (rec start n/2) (rec (+ start n/2) n-n/2))))))
(rec 0 n))
;; from http://d.hatena.ne.jp/wasabiz/20110118/1295335821
;; 「Pythonで末尾再帰最適化をする。」のScheme版
(define (TCO proc)
(let ([first? #t] [continue (list 'CONTINUE)] [args #f])
(lambda args*
(if first?
(begin
(set! first? #f)
(let loop ([result (apply proc args*)])
(if (eq? result continue)
@athos
athos / echo.html
Created February 18, 2011 14:39 — forked from mzp/echo.html
<html>
<head>
<style type="text/css">
.log {
color: red;
}
</style>
<script>
ws = new WebSocket("ws://localhost:8080");
ws.onopen = function (e) {
@athos
athos / gist:895752
Created March 31, 2011 03:08
an idea of alternative macros for letfn (I hate its too deep indents)
(letfn [(kons [x y]
(cons x y))]
(kons 1 nil))
(defmacro letfn1 [name args & form]
(let [fbody (butlast form)
body (last form)]
`(letfn [(~name ~args ~@fbody)]
~body)))