�ʡ��ʤ�Ǥ��ȡ���
1�Ĥθ���˰Ϥ����ޤ��ꥹ�� @ 2008ǯ01�� @ ratio - rational - irrational @ IDMarc��꡼������ǤȤ�!
�Ȥ����櫓�������Ƥߤ���
����www ���졢Lisp Fundamentalist �ۤɵ���ȿ�����������Ǥ��Ϥ���ä�˨������ä���
�ʲ���Tutorial����֤äȤӲս�����Ԥä����äס�
defvar �� =
�ޤ��Ϥ��졣
arc> (= foo 13) 13 arc> foo 13
defun �� def
Scheme������(define (funname arg) (...)
�Ǥʤ���(defvar funname (arg) (...)
�Ǥ���mzscheme�Ǽ�������Ƥ뤯���ˤ���
arc> (def average (x y) (/ (+ x y) 2)) #<procedure: average> arc> (average 2 4) 3
scheme�����������ʻ�Ȥ��Ƥϡ��ѿ�������def
�Ǥ����󤸤㡢�Ȥ���ä���⤹��ΤǤ������ѿ��ؤ������ȴؿ������ʬ���Ƥ��뤪�����ǡ������������Ȥ����ޤ���
arc> x (a b) arc> (= (car x) 'z) z arc> x (z b)
lambda �Ϧˡ�����ʤ���fn
�����Ǽ���������Ȥ������ʤ󤿤äƤ褯�Ȥ��ޤ����顣
arc> ((fn (x y) (/ (+ x y) 2)) 2 4) 3
�ǡ�����¤ = �ؿ�
���Τ����굡ǽ�Ȥ��Ƥ�Lisp�ο���ĺ���Ǥ�������ä�Lisp�ˤߤ��ͤ���
arc> ("foo" 0) #\f arc> ("foo" 1) ; ������ #\o
���ˤ����ɤΤ��Ĥ�����?
���������ѿ���with��
���Τ褦��let�⤢��ΤǤ�����
arc> (let x 1 (+ x (* x 2))) 3
ʣ���ѿ���Ȥ��������with��Ȥ��ޤ���
arc> (with (x 3 y 4) (sqrt (+ (expt x 2) (expt y 2)))) 5
if�νŤ��Ǥ�
(if a b c d e) ; �ʲ���Ʊ�� ; (if a ; b ; (if c ; d ; e))
Graham����äơ����˨���Υͥ��ȷ���?
and��or�ϥ��硼�ȥ������å�
����Ϥ狼��䤹��
arc> (and nil (pr "you'll never see this")) nil
�����not����ʤ���no
�ʤ��!
�ˤ��ʤ��ä������
arc> (def mylen (xs) (if (no xs) 0 (+ 1 (mylen (cdr xs))))) #<procedure: mylen> arc> (mylen nil) 0 arc> (mylen '(a b)) 2
== �� is
����Ϥʤ�ۤɤ��⡣==
���Ϥ狼��䤹����
arc> (is 'a 'a) t arc> (is "foo" "foo") t
���������ꥹ�Ȥ����Ƥޤ���Ӥ������iso (isomorphic��ά)
arc> (iso (list 'a) (list 'a)) t
for/each/while/repeat
����ϤդĤ���LL�Ȥ��ˤϤդĤ���
arc> (for i 1 10 (pr i " ")) 1 2 3 4 5 6 7 8 9 10 nil arc> (each x '(a b c d e) (pr x " ")) a b c d e nil arc> (let x 10 (while (> x 5) (= x (- x 1)) (pr x))) arc> (repeat 5 (pr "la ")) la la la la la nil
����äȸ���map
�դĤ���
arc> (map (fn (x) (+ x 10)) '(1 2 3)) (11 12 13 . nil)
�Ǥ���������ʤ��Ȥ�Ǥ��ޤ���
arc> (map + '(1 2 3 4) '(100 200 300)) (101 202 303)
�ǡ����졣
arc> (map [+ _ 10] '(1 2 3)) (11 12 13 . nil)
����äƤɤ���perl?
keep��grep
����ϥ��󥹤�������
arc>> (keep odd '(1 2 3 4 5 6 7)) (1 3 5 7)
�Ǥ⤳���ά���᤮
arc> (rem odd '(1 2 3 4 5 6)) (2 4 6)
���ä�
arc> (keep ~odd '(1 2 3 4 5 6)) (2 4 6)
�ǻ�Â���Ϥ������rem�ä�basic���ȥ����Ȥˤʤä��㤦���
�դĤ���hash��������
������紿��!
arc> (= airports (table)) #hash() arc> (= (airports "Boston") 'bos) bos arc> (let h (listtab '((x 1) (y 2))) (h 'y)) 2 arc> (let h (obj x 1 y 2) (h 'y)) 2
�����פ��㤹�Ȥ���
���⤤���Ǥ�����������
arc> (coerce "foo" 'cons) (#\f #\o #\o) arc> (coerce "99" 'int) 99 arc> (coerce "99" 'int 16) 153
push ���� pop
arc> (= x '(c a b)) (c a b) arc> (pop x) c arc> x (a b) arc> (push 'f x) (f a b) arc> x (f a b)
�ޥå��ޥ���
����Graham�餷���Ȼפä��Τ����졣ro�����ä����ʤ��ΤǤ��͡�
(mac when (test . body) `(if ,test (do ,@body)))
�������
�ʾ塢�Â��arc�ò¸«¤Æ¤ï¿½ï¿½Þ¤ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½ï¿½Ê¤Þ¤ï¿½lisp/scheme���ΤäƤ���ȥ��⤯�����ޤ������Ϥ��ᤫ�餳��Ǥ��ä���빽�������ɤ��Ȥ���ΤǤϤʤ����Ȼפä���ä��������Ǿ�ʤΤǤ��礦�ͤ���list��array�äݤ��Ȥ���(e.g. push/pop)��hash���ӥ�ȥ���Ȥ����ΤϤ��֥ݥ��ȥ�������פäݤ�������car
�Ȥ�cdr
�Ȥ��ϡ��ָŤ��¤�lisp�פΤޤޤǤ�����
�Ǥ⡢���ֳ�¦��()��ɤ����뤫����arc�򵤤����뤫�ɤ����μ�����
'(dan the arc newbie)
http://www.lingr.com/room/gauche/archives/2008/02/01#msg-25178946
$ gosh
gosh> (define fn lambda)
fn
gosh> (map (fn (x) (+ x 10)) '(1 2 3))
(11 12 13)
gosh> (map + '(1 2 3 4) '(100 200 300))
(101 202 303)