Last active
August 2, 2018 08:21
-
-
Save iizukak/3375955 to your computer and use it in GitHub Desktop.
Scheme手習いメモ (3章 - 偉大なるCons) ref: https://qiita.com/iizukak/items/630ffe8dc5f350cccc7e
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (define multirember | |
| (lambda (a lat) | |
| (cond | |
| ((null? lat) (quote ())) | |
| (else | |
| (cond | |
| ((eq? (car lat) a) | |
| (multirember a (cdr lat))) | |
| (else (cons (car lat) | |
| (multirember a | |
| (cdr lat))))))))) | |
| (define a 'cup) | |
| (define lat '(coddee cup tea cup and hick cup)) | |
| (print (multirember a lat)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (define firsts | |
| (lambda (l) | |
| (cond | |
| ((null? l) quote ()) | |
| (else (cons (car (car l)) | |
| (firsts (cdr l))))))) | |
| (print (firsts '((a b) (b c) (d e)))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (define insertR | |
| (lambda (new old lat) | |
| (cond | |
| ((null? lat) (quote ())) | |
| (else (cond | |
| ((eq? (car lat) old) | |
| (cons old | |
| (cons new (cdr lat)))) | |
| (else (cons (car lat) | |
| (insertR new old | |
| (cdr lat))))))))) | |
| (define new 'topping) | |
| (define old 'fudge) | |
| (define lat '(ice cream with fudge for dessert)) | |
| (print (insertR new old lat)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (define multisubset | |
| (lambda (new old lat) | |
| (cond | |
| ((null? lat) (quote ())) | |
| (else | |
| (cond | |
| ((eq? (car lat) old) | |
| (cons new | |
| (multisubset new old | |
| (cdr lat)))) | |
| (else (cons (car lat) | |
| (multisubset new old | |
| (cdr lat))))))))) | |
| (define old 'fudge) | |
| (define new 'topping) | |
| (define lat '(fudge cream with fudge for dessert)) | |
| (print (multisubset new old lat)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (define rember | |
| (lambda (a lat) | |
| (cond | |
| ((null? lat) (quote ())) | |
| ((eq? (car lat) a) (cdr lat)) | |
| (else (cons (car lat) | |
| (rember a (cdr lat))))))) | |
| (define a 'and) | |
| (define lat '(bacon and potatos)) | |
| (print (rember a lat)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment