Created
June 11, 2010 22:57
-
-
Save cametan001/435164 to your computer and use it in GitHub Desktop.
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 Mary (make-hasheq)) | |
| (define John (make-hasheq)) | |
| (define Herb (make-hasheq)) | |
| (define Al (make-hasheq)) | |
| ;;;; 次の事実をコード化する | |
| ;;;; ・ John は Mary の夫である | |
| ;;;; ・ Mary は John の妻である | |
| ;;;; ・ Herb と Al は Mary と John の子供である | |
| ;;;; ・ Mary は Herb と Al の母である | |
| ;;;; ・ John は Herb と Al の父である | |
| ;;;; ・ Herb と Al は兄弟である | |
| (hash-set! Mary 'husband '(John)) | |
| (hash-set! John 'wife '(Mary)) | |
| (hash-set! Mary 'children '(Al Herb)) | |
| (hash-set! John 'children '(Al Herb)) | |
| (hash-set! Herb 'mother '(Mary)) | |
| (hash-set! Al 'mother '(Mary)) | |
| (hash-set! Herb 'father '(John)) | |
| (hash-set! Al 'father '(John)) | |
| (hash-set! Herb 'brother '(Al)) | |
| (hash-set! Al 'brother '(Herb)) | |
| ;;;; データ構造の節への追加 | |
| (define-syntax add-child | |
| (syntax-rules () | |
| ((_ child mom dad) | |
| (begin | |
| (define child (make-hasheq)) | |
| (for-each hash-set! | |
| `(,child ,child ,mom, dad) | |
| '(mother father children children) | |
| `((mom) (dad) | |
| ,@(map (lambda (x) | |
| (cons 'child (hash-ref x 'children '()))) | |
| `(,mom ,dad)))))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment