yaotti's diary

Software is Eating the World

gauche

cutの使いかた

Gaucheで、 (map (lambda (x) (* x x)) '(1 2 3)) をcutを使うなら、どう書けばいいんだろう。 cut内で特定の引数を2回以上使いたいってことなんだけど。 (let ((sq (lambda (x) (* x x)))) (map (cut sq <>) '(1 2 3))) ;;pa$を使えばこう ;;(map (pa$ sq) …

gaucheのstreamについてメモ

たぶん追記していく。 stream便利だなぁ。無限の必要なとこだけ使うという感覚が好き。 (use util.stream) write-streamはストリームの要素が文字の時しか使えない →数字のときはstream-ref使って手続き作ればいいか sicpではcons-streamとなってるけどgauch…

Gauche0.8.13をさくらのレンタルサーバ(ベーシック)へインストール

せっかくサーバ借りてるので、入れてみる。 kahuaも入れる予定。 ここを参考にさせてもらいました。というかほぼそのまんま。 とても助かりました。 http://d.hatena.ne.jp/scinfaxi/20070518/1179468568 まずここでGauche-0.8.13.tgzをダウンロード。サーバ…

Gaucheで今日理解したこと

ちょっとしかしてないけど。モジュールニツイテ (use gauche.interactive) (apropos 'module) てやるとわかるんだけど、 (all-modules) (current-module) なんていう関数がある。 それぞれ、 現在存在するすべての名前つきモジュールのリスト コンパイル時の…

listとquoteの違い

(find (cut eq? '+ <>) (list '+ '- '* '/)) (find (cut eq? '+ <>) '('+ '- '* '/)) この2つ、挙動が違う。 上は+が返ってきて、下は#fが返る。 なんでかなーと思って調べたところ、 gosh>(list 'a 'b) (a b) gosh>'('a 'b) ('a 'b) quoteだと中身は評価さ…

逆ポーランド記法で計算

(define (re-polish args) (let1 operators (list '+ '- '* '/) (define (iter rest-args stack) (cond [(null? rest-args) (car stack)] [(number? (car rest-args)) (iter (cdr rest-args) (append stack (list (car rest-args))))] [(find (cut eq? (car …

世界のナベアツ的なもの

3の倍数と3が含まれる数のときだけpiyopiyoする。 (use srfi-1) (define (contain-tree? num) (find (cut eq? #\3 <>) (string->list (number->string num)))) (define (nabeatsu n) (map (lambda (x) (if (or (= (modulo x 3) 0) (contain-tree? x)) 'piyop…

ターミナルからtwitterへポストするgaucheスクリプト

かいた。 #!/usr/local/bin/gosh (use rfc.http) (use rfc.base64) (define (main args) (let* ((username (cadr args)) (passwd (caddr args)) (status (cadddr args)) (basic-info (string-append "Basic " (base64-encode-string (string-append username…