IRC channel logs
2026-05-27.log
back to list of logs
<probie>Is there a way I could define a macro (let's call it `define-x`) such that `(define-x foo ...)` is equivalent to `(define foo ...)` and I can get a list of all symbols defined using `define-x` that are either in the current module or [transitively] imported? <probie>actually, now that I think about it, that's probably as straight forward as generating the `(define foo ...)` as well as something like `(set! define-x-symbols (cons 'foo define-x-symbols))` <ArneBab>probie: yes, look into what the define-typed code does with 'check-argument-and-type-count'. <apteryx>is there way to check if *any* variable exists in a module, whether exported or not? <apteryx>I want to do so dynamically too, so cannot rely on @@ <apteryx>hm, apparently module-local-variable is a thing <identity>the module-* stuff is sparsely documented in general <apteryx>module-local-variable won't pick private variables either, so it doesn't help my use case <identity>apteryx: ‹module-map› should work, at least <identity>(module-map (λ (sym var) sym) (resolve-module '(module))) returns a list of all symbols defined in (module) <identity>or maybe i do not understand the question <identity>e.g. (module-local-variable (resolve-module '(web server http)) '*events*) works just fine, with *events* being a private (local?) variable <apteryx>that's useful; but I still do not see jami-configuration-fields for example <apteryx>my REPL must have been in a weird state <apteryx>,pp (module-map cons (resolve-module '(gnu services telephony))) shows it somewhere <apteryx>I'll continue looking at it a bit later, thank you! <identity>hm, (module-map values …) returns a #<values (…)>. probably because it is implemented in terms of hash-table->list (proc table), which is written in C <ArneBab>apteryx: any chance that you could document your findings in the guile texinfo manual? <apteryx>identity: module-local-variable seems to work now in a fresh REPL, great <apteryx>haha, of course, it's because of fold-module-public-variables* <apteryx>not module-local-variable. I need a fold-module-variables <apteryx>fold-module-public-variables* is implemented via module-map, which suggests it only maps the public variables? <apteryx>,pp (module-map cons (resolve-module '(gnu services telephony))) shows 'jami-configuration-fields', which is private <identity>apteryx: that fold2 stuff goes way over my head, but i *think* it traverses all the variables, but only calls proc on exported variables <apteryx>I don't see the fold2 doing anything other than tracking which variables have already been visited <apteryx>I think in the original version, the 'public' part of the name is implemented via (module-map (lambda (sym var) (false-if-exception (variable-ref var))) module) <apteryx>that variable-ref probably returns #f for private bindings? <apteryx>but there's no such thing in fold-module-public-variables*, so probably it should just be named fold-module-variables* <identity>the names and the docstrings are misleading, then <apteryx>I'll try to clean-up the guix docstrings/proc naming and then contribute at least module-local-variable doc to guile <apteryx>hm, variable-ref is not about public/private <civodul>apteryx: ‘module-ref’ is the way to check for the existence of a binding, but note that private variables may not exist at run time due to inlining <apteryx>I think the guard there is to avoid bound syntax-transformers from errorring out <apteryx>civodul: hello! that will error out for syntax objects, right? <civodul>apteryx: no, a syntax object is an object like any other one <apteryx>but module-ref does (variable-ref var), which I think errors with an unbound variable error for syntax... let me check again <civodul>(module-ref the-root-module 'false-if-exception) => #<syntax-transformer ...> <civodul>(otherwise ‘fold-packages’ would choke on all the ‘define-deprecated’ stuff we have, for instance) <apteryx>and would you be able to tell me where the public selection happens in fold-module-public-variables? I don't see it <apteryx>and at least for fold-module-public-variables*, it seems to fold on the private variables as well? <apteryx>like if I do (fold-module-public-variables* (lambda (module symbol . r) (pk 'symbol symbol)) '() (list (resolve-module '(gnu services telephony)))), I do see this private symbol: jami-configuration-fields <apteryx>I don't see a jami-configuration-fields in ,pp (fold-module-public-variables (lambda (object result) (pk 'object object)) '() (list (resolve-module '(gnu services telephony)))), but I think it's because the name is lost in the representation (it's just a list) <apteryx>fold-module-public-variables* gives me 238 symbols, while fold-module-public-variables gives me 236 variables. <apteryx>civodul: I'm not sure about the discrepancy of 2, but I think the '-public-' should be dropped from these procedure names? <ArneBab>apteryx: thank you! feel free to ping me when you have a PR for the documentation changes. <apteryx>I'll need to refine my understanding still before I can make it, but OK ^^' <apteryx>ha! I think the public property comes from the modules fed to these procedures; they are retrieved via `all-modules', which uses resolve-interface, hence expose only the public API! <apteryx>without touching (guix discovery) so far, I can get what I want by translating all-modules from interfaces to "directories" with (resolve-module (module-name interface)) <apteryx>it's hacky to access the -fields private variable to know if a config was made with define-configuration, but currently that's the only thing I can think of using <old>what are you trying to achieve apteryx? <apteryx>I'm adding some building blocks to be able to automatically generate the texinfo documentation for every service configurations we have in guix which are defined with the 'define-configuration' macro <apteryx>and then just @include that in the texinfo doc <apteryx>(and let the build system take care to update the texinfo fragments) <apteryx>instead of the manual generation + copy-paste we currently have <old>oh funny. we are doing the same thing for BLUE. <old>the texinfo introspection module is not doing what you need? <mwette>I do the same for my stuff. I use one script to search .scm files for textino as comments and extract. And I have an emacs macro that converts texinfo comments to docstring and inserts in procedure defs. <mwette>^ not bulletproof, but works in most cases <ieure>apteryx, There is a lot of prose in the Guix manual for services which isn't captured in the configuration record, do you have a plan for that? <sneek>This system has been up 2 weeks, 2 days, 4 hours, 22 minutes