Gaucheのvariableとprocedure
procedureは、

では「手続き」と呼んでる
関数のこと

boolを返すprocedureの名前はsufixに ?
をつけるっぽい
rbと同じ
e.g. odd?
, null?
変数束縛
lisp(define sqrt2 (sqrt 4)) ; sqrt2 = sqrt 4
lisp(define (pythagoras x y) (sqrt (+ (* x x) (* y y))))
procedureの中でprocedureの定義
lisp(define (max-number lis)
(define (pick-greater a b)
(if (> a b) a b))
(fold pick-greater -inf.0 lis))
無名関数
lisp(lambda (a b) (+ a b))
((lambda (a b) (+ a b)) 1 2)
local変数
(let ((変数定義) (変数定義) ..) (式))
例
lisp(let ((a 3)
(b 4))
(+ (* a a) (* b b)))
((lambda (a b) (+ (* a a) (* b b))) 1 2)
と同じ
letの方が見やすい
Haskellの let..in
と同じ
代入
set!
を使って変数に値を代入する
その値はすでに定義済みでないといけない
gauche(define x 3)
(set! x (list 1 2))
x ; 3
debugっぽいやつ
関数中に #?=
を仕込めば、そこを通過するたびにその式の評価値が出力される
lisp(define (folda proc init lis)
(if (null? lis)
init
(folda proc (proc (car lis) init) #?=(cdr lis))))
変数名の慣習
/
は「with」と読み替える
例えば hoge/piyo
は、「hoge with piyo」
call with current continuation