(note: all REPL sessions were performed using the environment described at the end of this email)
> There is no such thing as ‘program-arguments-alists’ AFAICT, there is only > ‘program-arguments-alist’ (singular instead of plural is key here) > > You can’t implement it in terms of ‘find-program-arguments-alist’, because > that procedure output format can only accomodate single-arity procedures, > whereas program-arities returns all the arities. However, > ‘find-program-arities’ looks fine (it actually wouldn’t work for general > procedures since ‘find-program-arities’ has “FIXME: handle case-lambda > arities”, but that comment makes clear it is _supposed_ for those). I think we might be looking at different versions of the repository. I'm on commit 8ac25f3faeb92c31c94f2bc09f4b29780df383fe, which is the most recent commit on the branch "main" in the repository located at https://git.sv.gnu.org/git/guile.git. In this version of the code, both program-arguments-alist and program-arguments-alists are defined (and exported) in modules/system/program.scm. Additionally, find-program-arities works for case-lambda arities (at least, the comment is no longer there and the number of returned entries is correct). Although, I am noticing that the alist functions don't include the information provided by alist:start and alist:end (the start and end addresses of the procedure definition in the relevant ELF image). scheme@(guile-user)> (pretty-print (program-arguments-alists map)) (((required f l) (optional) (keyword) (allow-other-keys? . #f) (rest . #f)) ((required f l1 l2) (optional) (keyword) (allow-other-keys? . #f) (rest . #f)) ((required f l1) (optional) (keyword) (allow-other-keys? . #f) (rest . rest))) scheme@(guile-user)> (length (find-program-arities (program-code map))) $4 = 3 > ‘count’ from SRFI 1 is not primitive code. Maybe there is also another > implementation in (guile), but ‘count’ from the SRFI 1 implementation is just > a Scheme procedure defined in Scheme by ‘define’. I don’t know what Guile > does _currently_, but is used to be that the information _is_ available: type > (display f) for any procedure f that is a (compiled) case-lambda with > multiple branches (e.g. count), and you would see all the arities. That was > in Guile 3.0, which postdates the mentioned commits. > > I’m not sure, but I think primitive procedures aren’t technically programs > (and if they were technically programs, they probably wouldn’t have an ELF > section). I don’t know if the arity information is recorded anywhere, but at > least during the definition of the primitive procedure the arity information > is passed to the primitive procedure-constructing C function (look for > gsubr). Perhaps there is a hint there on where arity information of primitive > procedures is stored (if anywhere). It might also be the case that even > before those commits, arity information of such procedures weren’t available > at runtime (can test with (display insert-primitive-procedure-here)). I don't know what the "primitive-code?" predicate is actually testing, and I agree it is surprising (based purely on the name) that it returns true when "count" is given. Perhaps I am calling it incorrectly. Regardless, for both this procedure and others which pass the "primitive-code?" predicate "find-program-arities" returns #f. scheme@(guile-user)> (primitive-code? (program-code count)) $5 = #t scheme@(guile-user)> (find-program-arities (program-code count)) $6 = #f > You could probably modify the interpreter to record arity information as a > ‘procedure property’, and then modify the arity querying procedures to look > for this information when available, and prefer it above. There is actually a place where arity information is recorded as a procedure property - line 576 of module/ice-9/eval.scm (on the same commit as mentioned above). However, I have not found a function which actually has this property so I'm not sure what circumstances exercise this code path. > If there is some relevant performance impact, I have a rather ugly method for > eliminating it during bootstrapping (at cost of not having proper arity > information for interpreted things during bootstrapping) if you are > interested. > > (Also, technically there are multiple Scheme interpreters in Guile for > technical reasons – a Scheme interpreter written in Scheme (“meta-circular > evaluator’), and one written in C. The C implementation exists for > bootstrapping the Scheme Scheme interpreter, so it’s of less interest to get > arity information in there.) Good to know! I'm not super familiar with the bootstrapping process so I haven't looked at this aspect yet. I'll keep you in mind when I do! > You would need to investigate the performance impact (especially the > performance impact on the bootstrapping process (i.e. compile without any > precompiled .go)) (Inconveniently there doesn’t seem to be a standard way of > testing for such.) My hope is that I can test this locally by using Guix's --with-patch flag to perform the build. The precompiled files should not be used according to Guix's model, but it is technically possible to use them and I haven't looked at the build definition that closely. However, I'm not sure if my computing environment is representative of the typical computing environment or the subset of computing environments that are most relevant to people building Guile from scratch. Shell environment: $ guix time-machine --channels=./channels.scm -- shell --container --nesting guile-next guile-readline coreutils user@foreign-guix /dev/shm [env]$ cat channels.scm (use-modules (guix ci)) (list (channel-with-substitutes-available %default-guix-channel "https://ci.guix.gnu.org")) user@foreign-guix /dev/shm [env]$ guix describe guix d663d4b repository URL: https://git.savannah.gnu.org/git/guix.git branch: master commit: d663d4b6cae2289bcdd8bdcd02d58ed30769f1e2 user@foreign-guix /dev/shm [env]$ guile GNU Guile 3.0.9-0.3b76a30 Copyright (C) 1995-2024 Free Software Foundation, Inc. Guile comes with ABSOLUTELY NO WARRANTY; for details type `,show w'. This program is free software, and you are welcome to redistribute it under certain conditions; type `,show c' for details. Enter `,help' for help. scheme@(guile-user)> (use-modules (ice-9 pretty-print) (system vm debug) (system vm program) (srfi srfi-1))