guess関数(未完成)
ついでにgauche版のguessも作ろうとしたがこちらは未完成。
(define (guess ans . arg) (map (lambda (mod) (hash-table-fold (module-table mod) (lambda (k v r) (if (with-error-handler (lambda (e) #f) (lambda () (eq? (apply v arg) ans))) (cons k r) r)) ())) (all-modules)))
module-tableのハッシュの値は普通の手続きかと思っていたが関数として呼び出すとエラーになる。
glocって何だろ?
useを使うとinteraction-environmentの中にインポートされるのかと思っていたが、入ってなかった。
普通に定義したaは入っているのに。
gosh> (use srfi-1) #<undef> gosh> first #<subr car> gosh> (hash-table-get (module-table (find-module 'srfi-1)) 'first) #<gloc srfi-1#first> gosh> ((hash-table-get (module-table (find-module 'srfi-1)) 'first) '(1 2 3)) *** ERROR: invalid application: (#<gloc srfi-1#first> (1 2 3)) gosh> (define a 1) a gosh> (hash-table-keys (module-table (interaction-environment))) (a *argv* *program-name*)
glocはグローバル環境での束縛??
Scm_Applyの第1引数になっているglocとはGlobal LOCation、グローバル環境での束縛を表しているもので
http://practical-scheme.net/wiliki/wiliki.cgi?Gauche%3AYAGHG%3AIntroduction