現在のモジュールは
(module-name (current-module)) ;; -> user
その親のモジュールは
(module-parents (current-module)) ;; -> (#<module gauche.gf>)
現在のモジュールから見えているsymbolは
(hash-table-keys (module-table (current-module))) ;; -> (*program-name* *argv*)
モジュールを継承すると親モジュールの中のsymbolは全て見えるということなので、継承関係を遡って全ての親モジュールを取得する。
(define (all-parents module) (let ((parents (module-parents module))) (let rec ((parents parents)(acc '())) (if (null? parents) acc (rec (cdr parents)(append (cons (car parents) acc) (all-parents (car parents)))))))) (all-parents (current-module)) ;; -> (#<module gauche.gf> #<module gauche> #<module scheme> #<module null>)
で、それぞれのモジュール内のsymbol名を取得して集める。
(define (all-symbols module) (map (lambda (m) (list (module-name m) (sort (hash-table-keys (module-table m)) (lambda (x y) (string<? (symbol->string x) (symbol->string y)))))) (all-parents module))) (all-symbols (current-module)) ;; ((gauche.gf ()) ;; (gauche (%add-load-path %alist-delete %alist-delete! %autoload %bignum-dump %char-set-add! %char-set-add-chars! %char-set-add-range! %char-set-complement! %char-set-dump %char-set-equal? %char-set-predefined %char-set-ranges %char-set<=? %check-class-binding %default-signal-handler %delete %delete! %delete-duplicates %delete-duplicates! %ensure-generic-function %exit %export-all %extend-module %format %gauche-runtime-directory %get-reader-ctor %guard-rec %hash-string %hash-table-iter %let-keywords-rec %macroexpand %macroexpand-1 %make-tree-map %maybe-substring %open-input-file %open-input-file/conv %open-output-file %open-output-file/conv %regexp-dump %regexp-pattern %regmatch-dump %require %sort %sort! %string-pointer-dump %string-replace-body! %string-split-by-char %sys-escape-windows-command-line %tree-map-bound %tree-map-check-consistency %tree-map-dump %tree-map-iter %uvector-ref %vm-make-parameter-slot %vm-parameter-ref %vm-parameter-set! %vm-show-stack-trace &condition &error &i/o-closed-error &i/o-error &i/o-port-error &i/o-read-error &i/o-write-error &message &read-error &serious *. *char-code-max* |+.| |-.| |.$| /. <abandoned-mutex-exception-meta> <abandoned-mutex-exception> <accessor-method> <arity-at-least> <autoload-meta> <autoload> <boolean-meta> <boolean> <char-meta> <char-set-meta> <char-set> <char> <class> <coding-aware-port> <collection> <compiled-code> <complex-meta> <complex> <compound-condition> <condition-meta> <condition> <dictionary> <eof-object> <error> <exception> <f16vector-meta> <f16vector> <f32vector-meta> <f32vector> <f64vector-meta> <f64vector> <foreign-pointer> <generic> <gloc-meta> <gloc> <hash-table-meta> <hash-table> <identifier> <integer-meta> <integer> <io-closed-error> <io-error> <io-read-error> <io-unit-error> <io-write-error> <join-timeout-exception-meta> <join-timeout-exception> <keyword-meta> <keyword> <list-meta> <list> <macro-meta> <macro> <message-condition> <method> <module-meta> <module> <next-method> <null-meta> <null> <number-meta> <number> <object> <ordered-dictionary> <pair-meta> <pair> <port-error> <port> <procedure> <promise-meta> <promise> <rational-meta> <rational> <read-context> <read-error> <read-reference> <real-meta> <real> <regexp-meta> <regexp> <regmatch-meta> <regmatch> <s16vector-meta> <s16vector> <s32vector-meta> <s32vector> <s64vector-meta> <s64vector> <s8vector-meta> <s8vector> <sequence> <serious-compound-condition> <serious-condition> <slot-accessor> <string-meta> <string-pointer-meta> <string-pointer> <string> <symbol-meta> <symbol> <syntactic-closure> <syntax-meta> <syntax-pattern-meta> <syntax-pattern> <syntax-rules-meta> <syntax-rules> <syntax> <sys-fdset> <sys-group> <sys-passwd> <sys-sigset> <sys-stat> <sys-tm> <system-error> <terminated-thread-exception-meta> <terminated-thread-exception> <thread-exception-meta> <thread-exception> <thread-meta> <thread> <time> <top> <tree-map-meta> <tree-map> <u16vector-meta> <u16vector> <u32vector-meta> <u32vector> <u64vector-meta> <u64vector> <u8vector-meta> <u8vector> <uncaught-exception-meta> <uncaught-exception> <undefined-object> <unhandled-signal-error> <unknown> <uvector-meta> <uvector> <vector-meta> <vector> <weak-hash-table-meta> <weak-hash-table> <weak-vector-meta> <weak-vector> E2BIG EACCES EADDRINUSE EADDRNOTAVAIL EADV EAFNOSUPPORT EAGAIN EALREADY EBADE EBADF EBADFD EBADMSG EBADR EBADRQC EBADSLT EBFONT EBUSY ECANCELED ECHILD ECHRNG ECOMM ECONNABORTED ECONNREFUSED ECONNRESET EDEADLK EDEADLOCK EDESTADDRREQ EDOM EDOTDOT EDQUOT EEXIST EFAULT EFBIG EHOSTDOWN EHOSTUNREACH EIDRM EILSEQ EINPROGRESS EINTR EINVAL EIO EISCONN EISDIR EL2HLT EL2NSYNC EL3HLT EL3RST ELIBACC ELIBBAD ELIBEXEC ELIBMAX ELIBSCN ELNRNG ELOOP EMFILE EMLINK EMSGSIZE EMULTIHOP ENAMETOOLONG ENETDOWN ENETRESET ENETUNREACH ENFILE ENOANO ENOBUFS ENOCSI ENODATA ENODEV ENOENT ENOEXEC ENOLCK ENOLINK ENOMEDIUM ENOMEM ENOMSG ENONET ENOPKG ENOPROTOOPT ENOSPC ENOSR ENOSTR ENOSYS ENOTBLK ENOTCONN ENOTDIR ENOTEMPTY ENOTSOCK ENOTTY ENOTUNIQ ENXIO EOPNOTSUPP EOVERFLOW EPERM EPFNOSUPPORT EPIPE EPROTO EPROTONOSUPPORT EPROTOTYPE ERANGE EREMCHG EREMOTE EROFS ESHUTDOWN ESOCKTNOSUPPORT ESPIPE ESRCH ESRMNT ESTALE ESTRPIPE ETIME ETIMEDOUT ETOOMANYREFS ETXTBSY EUNATCH EUSERS EWOULDBLOCK EXDEV EXFULL F_OK LC_ALL LC_COLLATE LC_CTYPE LC_MONETARY LC_NUMERIC LC_TIME RAND_MAX RLIMIT_AS RLIMIT_CORE RLIMIT_CPU RLIMIT_DATA RLIMIT_FSIZE RLIMIT_NOFILE RLIMIT_OFILE RLIMIT_STACK RLIM_INFINITY R_OK SCM_UVECTOR_F16 SCM_UVECTOR_F32 SCM_UVECTOR_F64 SCM_UVECTOR_S16 SCM_UVECTOR_S32 SCM_UVECTOR_S64 SCM_UVECTOR_S8 SCM_UVECTOR_U16 SCM_UVECTOR_U32 SCM_UVECTOR_U64 SCM_UVECTOR_U8 SEEK_CUR SEEK_END SEEK_SET SIGABRT SIGALRM SIGBUS SIGCHLD SIGCONT SIGFPE SIGHUP SIGILL SIGINT SIGIO SIGKILL SIGPIPE SIGPOLL SIGPROF SIGPWR SIGQUIT SIGSEGV SIGSTOP SIGTERM SIGTRAP SIGTSTP SIGTTIN SIGTTOU SIGURG SIGUSR1 SIGUSR2 SIGVTALRM SIGWINCH SIGXCPU SIGXFSZ SIG_BLOCK SIG_SETMASK SIG_UNBLOCK W_OK X_OK ^ ^-generator ^_ ^a ^b ^c ^d ^e ^f ^g ^h ^i ^j ^k ^l ^m ^n ^o ^p ^q ^r ^s ^t ^u ^v ^w ^x ^y ^z acons acosh add-load-path add-method! alist->tree-map all-modules allocate-instance and-let* any any$ any-pred append! apply$ apply-generic apply-method apply-methods arity arity-at-least-value arity-at-least? ash asinh assoc$ atanh autoload begin0 bignum? bit-field boolean byte-ready? byte-substring caaaar caaadr caaar caadar caaddr caadr cadaar cadadr cadar caddar cadddr caddr call-with-input-string call-with-output-string call-with-string-io case-lambda cdaaar cdaadr cdaar cdadar cdaddr cdadr cddaar cddadr cddar cdddar cddddr cdddr ceiling->exact change-class change-object-class char->ucs char-set char-set-contains? char-set-copy char-set? check-arg circular-list? clamp class-direct-methods class-direct-slots class-direct-subclasses class-direct-supers class-name class-of class-precedence-list class-redefinition class-slot-accessor class-slot-bound? class-slot-definition class-slot-ref class-slot-set! class-slots closure-code closure? compare complement compose compute-applicable-methods compute-cpl compute-get-n-set compute-slot-accessor compute-slots cond-expand condition condition-has-type? condition-ref condition-type? condition? copy-bit copy-bit-field copy-port cosh count$ current-class-of current-error-port current-exception-handler current-load-history current-load-next current-load-path current-load-port current-microseconds current-module current-thread current-time cut cute debug-print debug-print-width debug-source-info dec! declare decode-float default-endian define define-^x define-class define-compiler-macro define-condition-type define-constant define-generic define-in-module define-inline define-macro define-method define-module define-reader-ctor define-reader-directive define-values delete$ delete-keyword delete-keyword! delete-keywords delete-keywords! delete-method! digit->integer disasm dolist dotimes dotted-list? dynamic-load eager eof-object eq-hash eqv-hash error errorf eval-when every every$ every-pred exit exit-handler export export-all export-if-defined extend extract-condition file-exists? file-is-directory? file-is-regular? filter$ find find$ find-module find-tail$ finite? fixnum-width fixnum? flonum? floor->exact fluid-let flush flush-all-ports fmod fold fold$ fold-right fold-right$ for-each$ foreign-pointer-attribute-get foreign-pointer-attribute-set foreign-pointer-attributes format format/ss frexp gauche-architecture gauche-architecture-directory gauche-character-encoding gauche-dso-suffix gauche-library-directory gauche-site-architecture-directory gauche-site-library-directory gauche-version gc gc-stat gensym get-keyword get-keyword* get-optional get-output-byte-string get-output-string get-remaining-input-string get-signal-handler get-signal-handler-mask get-signal-handlers get-signal-pending-limit getter-with-setter glob glob-component->regexp glob-fold global-variable-bound? global-variable-ref greatest-fixnum guard has-setter? hash hash-table hash-table-clear! hash-table-copy hash-table-delete! hash-table-exists? hash-table-fold hash-table-for-each hash-table-get hash-table-keys hash-table-map hash-table-num-entries hash-table-pop! hash-table-push! hash-table-put! hash-table-stat hash-table-type hash-table-update! hash-table-values hash-table? identifier->symbol identifier? identity if-let1 import inc! include inexact-/ infinite? initialize inline-stub instance-slot-ref instance-slot-set integer->digit integer-length is-a? keyword->string keyword? lambda last-pair lazy ldexp least-fixnum let-keywords let-keywords* let-optionals* let/cc let1 library-exists? library-fold library-for-each library-has-module? library-map list* list->sys-fdset list-copy load-from-port logand logbit? logcount logior lognot logtest logxor macroexpand macroexpand-1 make make-byte-string make-compound-condition make-condition make-condition-type make-glob-fs-fold make-hash-table make-keyword make-list make-module make-string-pointer make-tree-map make-weak-vector map$ member$ merge merge! method-more-specific? min&max modf module-exports module-imports module-name module-name->path module-parents module-precedence-list module-table module? monotonic-merge nan? native-endian null-list? object-* object-+ object-- object-/ object-apply object-compare object-equal? object-hash open-coding-aware-port open-input-buffered-port open-input-fd-port open-input-string open-output-buffered-port open-output-fd-port open-output-string pa$ partition$ path->module-name peek-byte pop! port->byte-string port->list port->sexp-list port->string port->string-list port-buffering port-case-fold-set! port-closed? port-current-line port-fd-dup! port-file-number port-fold port-fold-right port-for-each port-map port-name port-position-prefix port-seek port-tell port-type print procedure-arity-includes? procedure-info profiler-reset profiler-show profiler-show-load-stats profiler-start profiler-stop program promise-kind promise? proper-list? provide provided? push! quotient&remainder raise read-block read-byte read-char-set read-eval-print-loop read-from-string read-line read-list read-reference-has-value? read-reference-value read-reference? read-with-shared-structure read/ss rec receive redefine-class! reduce$ reduce-right$ ref ref* regexp->string regexp-ast regexp-case-fold? regexp-compile regexp-optimize regexp-parse regexp-quote regexp-replace regexp-replace* regexp-replace-all regexp-replace-all* regexp-unparse regexp? regmatch? remove$ report-error require require-extension reverse! rlet1 round->exact rxmatch rxmatch->string rxmatch-after rxmatch-before rxmatch-case rxmatch-cond rxmatch-end rxmatch-if rxmatch-let rxmatch-num-matches rxmatch-start rxmatch-substring seconds->time select-module set!-values set-signal-handler! set-signal-pending-limit setter |setter of object-apply| |setter of ref| sinh slot-bound-using-accessor? slot-bound-using-class? slot-bound? slot-definition-accessor slot-definition-allocation slot-definition-getter slot-definition-name slot-definition-option slot-definition-options slot-definition-setter slot-exists-using-class? slot-exists? slot-initialize-using-accessor! slot-missing slot-pop! slot-push! slot-ref slot-ref-using-accessor slot-ref-using-class slot-set! slot-set-using-accessor! slot-set-using-class! slot-unbound sort sort! sort-applicable-methods sort-by sort-by! sorted? split-at stable-sort stable-sort! stable-sort-by stable-sort-by! standard-error-port standard-input-port standard-output-port string->regexp string->uninterned-symbol string-byte-ref string-byte-set! string-complete->incomplete string-fill! string-immutable? string-incomplete->complete string-incomplete->complete! string-incomplete? string-interpolate string-join string-pointer-byte-index string-pointer-copy string-pointer-index string-pointer-next! string-pointer-prev! string-pointer-ref string-pointer-set! string-pointer-substring string-pointer? string-scan string-size string-split subr? supported-character-encoding? supported-character-encodings symbol-bound? symbol-interned? symbol-sans-prefix syntax-error syntax-errorf sys-abort sys-access sys-alarm sys-asctime sys-basename sys-chdir sys-chmod sys-chown sys-close sys-ctermid sys-ctime sys-difftime sys-dirname sys-environ sys-environ->alist sys-exec sys-exit sys-fchmod sys-fdset sys-fdset->list sys-fdset-clear! sys-fdset-copy! sys-fdset-max-fd sys-fdset-ref sys-fdset-set! sys-fork sys-fork-and-exec sys-fstat sys-ftruncate sys-getcwd sys-getdomainname sys-getegid sys-getenv sys-geteuid sys-getgid sys-getgrgid sys-getgrnam sys-getgroups sys-gethostname sys-getloadavg sys-getlogin sys-getpgid sys-getpgrp sys-getpid sys-getppid sys-getpwnam sys-getpwuid sys-getrlimit sys-gettimeofday sys-getuid sys-gid->group-name sys-glob sys-gmtime sys-group-name->gid sys-isatty sys-kill sys-lchown sys-link sys-localeconv sys-localtime sys-lstat sys-mkdir sys-mkfifo sys-mkstemp sys-mktime sys-nanosleep sys-normalize-pathname sys-pause sys-pipe sys-putenv sys-random sys-readdir sys-readlink sys-realpath sys-remove sys-rename sys-rmdir sys-select sys-select! sys-setenv sys-setgid sys-setlocale sys-setpgid sys-setrlimit sys-setsid sys-setuid sys-sigmask sys-signal-name sys-sigset sys-sigset-add! sys-sigset-delete! sys-sigset-empty! sys-sigset-fill! sys-sigsuspend sys-sigwait sys-sleep sys-srandom sys-stat sys-stat->atime sys-stat->ctime sys-stat->dev sys-stat->file-type sys-stat->gid sys-stat->ino sys-stat->mode sys-stat->mtime sys-stat->nlink sys-stat->rdev sys-stat->size sys-stat->type sys-stat->uid sys-strerror sys-strftime sys-symlink sys-system sys-time sys-times sys-tm->alist sys-tmpdir sys-tmpnam sys-truncate sys-ttyname sys-uid->user-name sys-umask sys-uname sys-unlink sys-unsetenv sys-user-name->uid sys-utime sys-wait sys-wait-exit-status sys-wait-exited? sys-wait-signaled? sys-wait-stopped? sys-wait-stopsig sys-wait-termsig sys-waitpid tanh time time->seconds time? toplevel-closure? touch-instance! tree-map->alist tree-map-ceiling tree-map-ceiling-key tree-map-ceiling-value tree-map-clear! tree-map-copy tree-map-delete! tree-map-empty? tree-map-exists? tree-map-floor tree-map-floor-key tree-map-floor-value tree-map-fold tree-map-fold-right tree-map-for-each tree-map-get tree-map-keys tree-map-map tree-map-max tree-map-min tree-map-num-entries tree-map-pop! tree-map-pop-max! tree-map-pop-min! tree-map-predecessor tree-map-predecessor-key tree-map-predecessor-value tree-map-push! tree-map-put! tree-map-successor tree-map-successor-key tree-map-successor-value tree-map-update! tree-map-values tree-map? truncate->exact ucs->char undefined undefined? unless until unwind-protect unwrap-syntax update! update-direct-method! update-direct-subclass! use use-version uvector-immutable? uvector-length values-ref vector-copy vm-dump vm-get-stack-trace vm-get-stack-trace-lite vm-set-default-exception-handler warn weak-vector-length weak-vector-ref weak-vector-set! when while with-error-handler with-error-to-port with-exception-handler with-input-from-port with-input-from-string with-module with-output-to-port with-output-to-string with-port-locking with-ports with-signal-handlers with-string-io write* write-byte write-limited write-object write-to-string write-with-shared-structure write/ss x->integer x->number x->string ~)) ;; (scheme (%acos %asin %atan %cos %cosh %exp %expt %gcd %log %sin %sinh %sqrt %tan %tanh * *dynamic-load-path* *load-path* *load-suffixes* + - / < <= = > >= abs acos angle append apply asin assoc assq assv atan boolean? caaaar caaadr caaar caadar caaddr caadr caar cadaar cadadr cadar caddar cadddr caddr cadr call-with-current-continuation call-with-input-file call-with-output-file call-with-values call/cc car cdaaar cdaadr cdaar cdadar cdaddr cdadr cdar cddaar cddadr cddar cdddar cddddr cdddr cddr cdr ceiling char->integer char-alphabetic? char-ci<=? char-ci<? char-ci=? char-ci>=? char-ci>? char-downcase char-lower-case? char-numeric? char-ready? char-upcase char-upper-case? char-whitespace? char<=? char<? char=? char>=? char>? char? close-input-port close-output-port complex? cons cos current-input-port current-output-port denominator display div div-and-mod div0 div0-and-mod0 dynamic-wind eof-object? eq? equal? eqv? eval even? exact exact->inexact exact-integer-sqrt exact? exp expt floor for-each force gcd imag-part inexact inexact->exact inexact? input-port? integer->char integer-valued? integer? interaction-environment lcm length length+ list list->string list->vector list-ref list-tail list? load log magnitude make-polar make-rectangular make-string make-vector map max member memq memv min mod mod0 modulo nearly=? negative? newline not null-environment null? number->string number? numerator odd? open-input-file open-output-file output-port? pair? peek-char port? positive? procedure? quotient rational-valued? rational? read read-char real-part real-valued? real? remainder reverse round scheme-report-environment set-car! set-cdr! sin sqrt string string->list string->number string->symbol string-append string-ci<=? string-ci<? string-ci=? string-ci>=? string-ci>? string-copy string-length string-ref string-set! string<=? string<? string=? string>=? string>? string? substring symbol->string symbol? tan truncate values vector vector->list vector-fill! vector-length vector-ref vector-set! vector? with-input-from-file with-output-to-file write write-char zero?)) ;; (null (and begin case cond define define-syntax delay do if lambda let let* let-syntax letrec letrec-syntax or quasiquote quote set! syntax-rules unquote unquote-splicing)))思ったよりたくさん出てきてびっくりした。
- vallog: なんで Lisp/Scheme の変数名は長いの?
- vallog: Gauche: use してる module から export されてる symbol たち
- vallog: Gaucheのmoduleとdefine-in-moduleとevalで作るsandbox
追記
正確には、「初期状態で見えているsymbolたち(Gaucheのuserモジュール)」ではなく「初期状態で束縛されているsymbolたち(Gaucheのuserモジュール)」か。
0 件のコメント:
コメントを投稿