どんどんいこう。
occure*
occure* はS式のリスト l の中にアトム a がいくつあるかを返す。
(use mymodule) (define occur* (lambda (a l) (cond ((null? l) 0) ((atom? (car l)) (cond ((eqan? (car l) a) (add1 (occur* a (cdr l)))) (else (occur* a (cdr l))))) (else (o+ (occur* a (car l)) (occur* a (cdr l))))))) (print (occur* 'banana '((banana) (split ((((banana ice))) (cream (banana)) sherbe)) (banana) (bread) (banana brandy))))
^o^ > gosh -I. occur_star.scm 5
subst*
subst* は、S式のリスト l の中のアトム old すべてを new に置き換える。
(use mymodule) (define subst* (lambda (new old l) (cond ((null? l) (quote ())) ((atom? (car l)) (cond ((eqan? (car l) old) (cons new (subst* new old (cdr l)))) (else (cons (car l) (subst* new old (cdr l)))))) (else (cons (subst* new old (car l)) (subst* new old (cdr l))))))) (print (subst* 'orange 'banana '((banana) (split ((((banana ice))) (ceam (banana)) sherbet)) (banana) (bread) (banana brandy))))
^o^ > gosh -I. subst_star.scm ((orange) (split ((((orange ice))) (ceam (orange)) sherbet)) (orange) (bread) (o range brandy))
insertL*
insertL* はS式のリストの中のアトム old すべての左に new を挿入する。
(use mymodule) (define insertL* (lambda (new old l) (cond ((null? l) (quote ())) ((atom? (car l)) (cond ((eqan? (car l) old) (cons new (cons old (insertL* new old (cdr l))))) (else (cons (car l) (insertL* new old (cdr l)))))) (else (cons (insertL* new old (car l)) (insertL* new old (cdr l))))))) (print (insertL* 'roast 'chuck '((hew much (wood)) could ((a (wood) chuck)) (((chuck))) (if (a) ((wood chuck))) could chuck wood)))
^o^ > gosh -I. insertL_star.scm ((hew much (wood)) could ((a (wood) roast chuck)) (((roast chuck))) (if (a) ((wo od roast chuck))) could roast chuck wood)
member*
member* は、S式のリストの中にアトム a があれば #t を返し、そうでなければ #f を返す。
(use mymodule) (define member* (lambda (a l) (cond ((null? l) #f) ((atom? (car l)) (cond ((eqan? (car l) a) #t) (else (member* a (cdr l))))) (else (or (member* a (car l)) (member* a (cdr l))))))) (print (member* 'chips '((potato) (chips ((with) fish) (chips)))))
^o^ > gosh -I. member_star.scm #t