arturo-lang / arturo

Simple, expressive & portable programming language for efficient scripting
http://arturo-lang.io
MIT License
695 stars 30 forks source link

Provide a way of iterating over all defined functions #468

Open asampal opened 2 years ago

asampal commented 2 years ago

It would be great to have a function that allows introspection over all defined functions (possibly scoped by some of the functions' metadata) in order to be able to act on the other metadata. I can see this being helpful for tooling (e.g. a language server that might want to provide prioritized auto-completion when in a particular module, etc.).

Maybe this is already there and I missed it (since I guess something like this is being used to generate some of the documentation).

drkameleon commented 2 years ago

All currently-defined symbols can be accessed via the symbols command, as a dictionary (name-value).

Starting from there you can obviously get whatever you want (note: there was a tiny issue with the REPL not handling nested templates well, but it has also been fixed as per the latest PR).

For example:

This returns an array of tuples (name / description) for each of the defined built-in functions. 😉

map select keys symbols => [function?.builtin var] 'sym -> @[sym, get info.get sym 'description]

This is pretty much the same like:

map 
    select keys symbols 'sym [
        function?.builtin var sym
    ] 
    'sym [
        @[
            sym,
            get info.get sym 'description
         ]
    ]

P.S. That being said, the whole thing reminds that I have to add dictionary support for all the remaining functions in the Iterators module, so that e.g. you can select the items you want from a given dictionary and get back a dictionary. I always end up using similar things (as would be the case here), but I still haven't implemented it for Arturo... :S

stale[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] commented 1 year ago

Closing issue as stale.

drkameleon commented 1 year ago

Issue is still active.

RickBarretto commented 11 months ago

@drkameleon How should we name this?

drkameleon commented 11 months ago

@drkameleon How should we name this?

Good question. It could be functions and work in an identical way as symbols, only returning just the functions?

stale[bot] commented 3 months ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.