Arc Forumnew | comments | leaders | submitlogin
2 points by shader 3213 days ago | link | parent

Does anyone use the "fns" function? I am considering either changing it or replacing it with a better function lister function.

If you had to pick a name for a function that listed all the currently defined functions or macros, or allowed you to filter them, what would it be? Would you stick with the current name "fns" or not?



1 point by rntz 3212 days ago | link

'fns is nice, but I'd like to be able to pass it symbols, not just strings. (Just run 'string on the argument.) I'll push this to anarki next chance I get, unless there are objections.

It would also probably be nicer if passing the 'test argument didn't make the 'pfx argument irrelevant - it's not really an optional argument, it's a bimodal function. Perhaps just testing whether the 'pfx argument was a function and using it as test if it were, and otherwise using [prefix string.pfx _]? This is a bigger change, though, and I won't push it unless people think it's a good idea.

-----

1 point by shader 3212 days ago | link

I've done most of that, but I haven't pushed it yet. The only thing different is that I made pfx optional too, so that it would return all functions if you called fns with no args.

Another difference is that I made fns a macro so that it would quote the symbol passed to it, instead of evaluating it. Maybe that's what you mean. Unfortunately, the scheme of taking in bare symbols as prefixes is rather incompatible with the test to see if it's a function.

Right now the way you'd call it if you wanted your own function without a prefix is (fns nil [ex _]).

Should I push what I have?

-----

1 point by skenney26 3212 days ago | link

Logically defs for function definitions and macs for macros would make the most sense. How are you planning on filtering them?

-----

1 point by shader 3212 days ago | link

currently fns takes an optional filter argument, and defaults to prefix. i.e., you give it a string, and it keeps all of the keys from the "sig" table that begin with that string. So it finds both macs and defs.

I've modified my version so that a) if you don't give any arg it returns the signatures all currently defined functions and macros, and b) it can take unquoted symbols as input instead of just strings. That makes use from repl easier.

I don't know how I would filter defs from macs. Maybe have def and mac store them in a different table? How do you get the object associated with a symbol? If I knew that, we could filter based on (type key).

-----

2 points by cchooper 3212 days ago | link

  (eval symbol)

-----

1 point by shader 3212 days ago | link

That works, I suppose

-----

1 point by cchooper 3211 days ago | link

I'm afraid it's the only thing that works.

But there's nothing wrong with it. You're doing non-performance sensitive metaprogramming, which is a perfect example of where eval should be used.

-----

1 point by shader 3211 days ago | link

I just found the macro varif on Anarki, which returns the value if bound. Would that be better, or worse? I should think it might be a little better, but I don't know.

True, this is running, I think, in the repl. So I don't think it matters that much. But having a good way to look up the value of a symbol is kind of important, I think. I want to do similar things that might be used in a "performance-sensitive" environment, not that arc is really performance sensitive in general. ;)

-----

1 point by cchooper 3208 days ago | link

varif will be better if you can use it in what you're doing. It doesn't evaluate its argument, which might make it useless to you.

-----

1 point by shader 3208 days ago | link

rntz wanted two separate functions to search macs and defs, so I suggested filtering the sig table based on whether each symbol was a mac or fn; that would only be possible if there was a way to turn the symbol into a value we could take the type of.

-----

1 point by cchooper 3208 days ago | link

But do you need to evaluate the argument to varif in your implementation? If so, then it's no good to you.

-----