> It looks like there are 2 potential candidates for aliasing, but both of them 
> have some problems. When aliasing to "find-program-arities" I am unable to 
> get the arity of any procedure which passes the "primitive-code?" predicate; 
> it just returns #f. When aliasing to "program-arguments-alists" I get results 
> for primitive code, but they are not accurate. For example, try calling it on 
> the "count" procedure from SRFI 1. It is using the "fallback" helper which 
> hardcodes unknown values for missing information. Also, the alists it returns 
> do not provide the information needed for "arity:start" and "arity:end".

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).

‘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 believe that program-arguments-alists is the intended replacement for 
>program-arities, based on this timeline of relevant commits: […]

There is no such thing as program-arguments-alists, as far as I can tell, 
though if it existed that seems a good replacement. And program-arguments-alist 
(singular) is not a replacement, since it only returns a _single_ arity.

Based on that timeline, I think a mistake was made – whether by accidentally 
removing program-arities as well, or by intentionally choosing to remove 
program-arities (without providing a replacement).

>The second concern is ensuring that arity information is available for all 
>procedures. However, I would like to delay that discussion until after I spend 
>more time studying how different programming languages handle arguments.

The interpreter probably constructs procedures by (lambda args [first 
deconstruct args, then do relevant actions]) closures (*), so it probably looks 
like a compiled procedure with a rest argument to the current implementation. 
(*) at least, that’s how I would implement a Scheme interpreter in Scheme.

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. 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.)

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.)

Best regards,
Maxime Devos.
  • Removing program-... Developers list for Guile, the GNU extensibility library
    • RE: Removing... Maxime Devos
      • RE: Remo... Developers list for Guile, the GNU extensibility library
        • RE: ... Developers list for Guile, the GNU extensibility library
          • ... Dr. Arne Babenhauserheide
            • ... Developers list for Guile, the GNU extensibility library
            • ... Developers list for Guile, the GNU extensibility library
          • ... Maxime Devos
            • ... Developers list for Guile, the GNU extensibility library

Reply via email to