unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* get all available symbols in scheme
@ 2016-06-13 18:38 source liu
  2016-06-13 19:22 ` Panicz Maciej Godek
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: source liu @ 2016-06-13 18:38 UTC (permalink / raw)
  To: guile-user@gnu.org

Hi,

glad to join the list

I wonder if there is some way to dump all available symbols in current
enviroment(something like “dir” in python), i think it is very useful when
you are trying new modules

I have tried the guile reference guide as well as google,but cant find any
clue

Any suggestion?

great thanks


-- 
Liu An
Institution of modern physics, Shanghai, China


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: get all available symbols in scheme
  2016-06-13 18:38 get all available symbols in scheme source liu
@ 2016-06-13 19:22 ` Panicz Maciej Godek
  2016-06-13 21:46 ` Arne Babenhauserheide
  2016-06-13 22:07 ` Taylan Ulrich Bayırlı/Kammer
  2 siblings, 0 replies; 6+ messages in thread
From: Panicz Maciej Godek @ 2016-06-13 19:22 UTC (permalink / raw)
  To: source liu; +Cc: guile-user@gnu.org

I don't think it is a very portable solution, but you can use
"module-obarray" procedure that returns an appropriate hash table, for
example:

(hash-map->list cons (module-obarray (current-module)))

(You can use resolve-module with quoted module name for other modules)

Best regards,
Panicz


2016-06-13 20:38 GMT+02:00 source liu <sourceonly@gmail.com>:

> Hi,
>
> glad to join the list
>
> I wonder if there is some way to dump all available symbols in current
> enviroment(something like “dir” in python), i think it is very useful when
> you are trying new modules
>
> I have tried the guile reference guide as well as google,but cant find any
> clue
>
> Any suggestion?
>
> great thanks
>
>
> --
> Liu An
> Institution of modern physics, Shanghai, China
>


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: get all available symbols in scheme
  2016-06-13 18:38 get all available symbols in scheme source liu
  2016-06-13 19:22 ` Panicz Maciej Godek
@ 2016-06-13 21:46 ` Arne Babenhauserheide
  2016-06-14  6:42   ` tomas
  2016-06-13 22:07 ` Taylan Ulrich Bayırlı/Kammer
  2 siblings, 1 reply; 6+ messages in thread
From: Arne Babenhauserheide @ 2016-06-13 21:46 UTC (permalink / raw)
  To: source liu; +Cc: guile-user@gnu.org

[-- Attachment #1: Type: text/plain, Size: 2656 bytes --]

Hi,

Welcome to Guile!

source liu writes:

> I wonder if there is some way to dump all available symbols in current
> enviroment(something like “dir” in python), i think it is very useful when
> you are trying new modules

> I have tried the guile reference guide as well as google,but cant find any
> clue

It’s pretty hidden. The easiest way is activating readline and just
hitting tab twice:

    echo "(use-modules (ice-9 readline))(activate-readline)" >> ~/.guile

Essentially this:

(module-map (λ (sym var) sym) (resolve-interface '(guile)))


and

    ,use ; returns (guile-user)
    ,in (guile-user) ,use ; returns module listing
    ,in (guile) ,b ; returns the bindings
    ,in ...

Essentially this:

    (map (λ (x) (cons (module-name x) (module-map (λ (sym var) sym) (resolve-interface (module-name x))))) (module-uses (resolve-module '(guile-user))))


There actually isn’t a dir function, yet…

(import (ice-9 optargs))
(import (oop goops))
(use-modules (texinfo reflection))

; define basic dir
(define* (dir #:key (all? #f))
  (if all?
      (map (λ (x) (cons (module-name x)
                        (module-map (λ (sym var) sym) (resolve-interface (module-name x)))))
           (module-uses (current-module)))
      (module-map (λ (sym var) sym) (current-module))))
; add support for giving the module as argument
(define-generic dir)
(define-method (dir (all? <boolean>)) (dir #:all? all?))
(define-method (dir (m <list>)) (module-map (λ (sym var) sym) (resolve-interface m)))
; add support for using modules directly (interfaces are also modules, so this catches both)
(define-method (dir (m <module>)) (module-map (λ (sym var) sym) (resolve-interface (module-name m))))


Now there is dir, but its output is a bit unwieldy for large modules…


You can use it this:

(dir) ; all local bindings, excluding imported modules
(dir #t) ; all available bindings, including imported modules
(dir #:all? #t) ; same as above

(dir '(ice-9 optargs)) ; all exported bindings from the (ice-9 optargs) module
; => (let-optional* define* let-keywords let-keywords* define*-public defmacro* defmacro*-public let-optional lambda*)

(dir (resolve-module '(ice-9 optargs)) ; all bindings in the module
; => (let-optional* parse-lambda-case %module-public-interface let-keywords let-keywords* define*-public defmacro* defmacro*-public *uninitialized* let-optional vars&inits)


I just added this to guile-basics: http://www.draketo.de/proj/guile-basics/#sec-2-5


Best wishes,
Arne
-- 
Unpolitisch sein
heißt politisch sein
ohne es zu merken

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 818 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: get all available symbols in scheme
  2016-06-13 18:38 get all available symbols in scheme source liu
  2016-06-13 19:22 ` Panicz Maciej Godek
  2016-06-13 21:46 ` Arne Babenhauserheide
@ 2016-06-13 22:07 ` Taylan Ulrich Bayırlı/Kammer
  2 siblings, 0 replies; 6+ messages in thread
From: Taylan Ulrich Bayırlı/Kammer @ 2016-06-13 22:07 UTC (permalink / raw)
  To: source liu; +Cc: guile-user@gnu.org

source liu <sourceonly@gmail.com> writes:

> Hi,
>
> glad to join the list
>
> I wonder if there is some way to dump all available symbols in current
> enviroment(something like “dir” in python), i think it is very useful when
> you are trying new modules
>
> I have tried the guile reference guide as well as google,but cant find any
> clue
>
> Any suggestion?
>
> great thanks

You can define something like:

    (define (display-module-interface module)
      (module-for-each
       (lambda (name variable)
         (let* ((name-length (string-length (symbol->string name)))
                (value (variable-ref variable))
                (documentation (object-stexi-documentation value)))
           (format #t "~a\n" name)
           (format #t "~a\n\n" (make-string name-length #\=))
           (format #t "Documentation:\n~a\n\n" documentation)
           (format #t "Value:\n~a\n\n\n" value)))
       (resolve-interface module)))

and then use it like this in the REPL:

    (display-module-interface '(rnrs bytevectors))

Comment out the line printing the value if you want...


One problem with this is that the stexi documentation may not look very
nice in plain text.

Another problem is that documentation is attached to objects in Guile,
rather than module/symbol combinations; this means, for example, if a
module defines a constant like O_APPEND which is bound to a number, it's
unclear where the documentation should be attached, since attaching it
to a number would be pretty weird.

A third problem is that we often lack documentation, sadly.

Taylan



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: get all available symbols in scheme
  2016-06-13 21:46 ` Arne Babenhauserheide
@ 2016-06-14  6:42   ` tomas
  2016-06-15 17:57     ` Performance implications of having many methods? " Arne Babenhauserheide
  0 siblings, 1 reply; 6+ messages in thread
From: tomas @ 2016-06-14  6:42 UTC (permalink / raw)
  To: guile-user

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Mon, Jun 13, 2016 at 11:46:20PM +0200, Arne Babenhauserheide wrote:
> Hi,
> 
> Welcome to Guile!
> 
> source liu writes:
> 
> > I wonder if there is some way to dump all available symbols in current
> > enviroment [...]

> It’s pretty hidden. The easiest way [...]
[a blazing tour through Guile introspection follows]

Not the OP here, but... wow, thanks, Arne!

I had to play around with that, although I'm supposed to be doing
something else.

> I just added this to guile-basics: http://www.draketo.de/proj/guile-basics/#sec-2-5

thanks again
- -- t
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.12 (GNU/Linux)

iEYEARECAAYFAldfp2QACgkQBcgs9XrR2kZJdgCeJhyXu3WxcJBJE1qPjA0x4t8Y
LtIAniQ3xgtxo7D7I5mRoeLUTJ868KgD
=P6Wt
-----END PGP SIGNATURE-----



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Performance implications of having many methods? Re: get all available symbols in scheme
  2016-06-14  6:42   ` tomas
@ 2016-06-15 17:57     ` Arne Babenhauserheide
  0 siblings, 0 replies; 6+ messages in thread
From: Arne Babenhauserheide @ 2016-06-15 17:57 UTC (permalink / raw)
  To: tomas; +Cc: guile-user

[-- Attachment #1: Type: text/plain, Size: 988 bytes --]

Hi Tomas,

tomas@tuxteam.de writes:

>> source liu writes:
>> > I wonder if there is some way to dump all available symbols in current
>> > enviroment [...]
>> It’s pretty hidden. The easiest way [...]
> [a blazing tour through Guile introspection follows]
>
> Not the OP here, but... wow, thanks, Arne!

Thank you for writing — I’m glad you like it!

It’s not all my own work, though: I have to thank the people in here and
in IRC who helped me understand it. They are pretty awesome!

What I missed was to note the use of (class-off OBJECT) to find the
value I put into the methods.

What I cannot give is performance information about the methods: There
are some important implications of having many methods, but I just don’t
know them.

>> I just added this to guile-basics: http://www.draketo.de/proj/guile-basics/#sec-2-5
> thanks again

Enjoy Guile, and Happy Hacking!
- Arne
-- 
Unpolitisch sein
heißt politisch sein
ohne es zu merken

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 818 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2016-06-15 17:57 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-06-13 18:38 get all available symbols in scheme source liu
2016-06-13 19:22 ` Panicz Maciej Godek
2016-06-13 21:46 ` Arne Babenhauserheide
2016-06-14  6:42   ` tomas
2016-06-15 17:57     ` Performance implications of having many methods? " Arne Babenhauserheide
2016-06-13 22:07 ` Taylan Ulrich Bayırlı/Kammer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).