Arc Forumnew | comments | leaders | submit | shader's commentslogin
1 point by shader 6103 days ago | link | parent | on: Source table

One of the other ideas I've had for the auto-doc feature of arc is a modification to the help op on the web server that instead of just looking at names between [[ ]] a) prints the source if in verbose mode and b) if so searches the source tree of the fn or mac for all symbols bound to fns or macs and makes them links. That would provide a pretty cool code explorer tool that would (almost) rival arc-fn

So I have a few questions:

1) What is the best way to search a source tree.

2) Currently src works by having a hook in def save the source to the table just like help, but that means that only things defined by def and mac actually have source entries. What about all of the xdefed functions? Should I add a hook to xdef as well? We could add docstring support to xdef too I suppose.

3) Since src saves the source after read, it has all of the reader macros already expanded, such as backquote and br-fns. Is there a way to get around that so that the source is more readable?

-----

1 point by shader 6102 days ago | link

Is it possible to condense the form (quasiquote l), (unquote l), (quote l) and (make-br-fn l) into their respective string based syntaxes? How would you go about doing this?

What is the arc method for mapping a function across a tree?

-----

2 points by absz 6102 days ago | link

You could try doing something like

  (def syntaxify (xs)
      (map
        [if (acons _)
          (case (car _)
            quote            (string "'"  (stringify:cdr _))
            quasiquote       (string "`"  (stringify:cdr _))
            unquote          (string ","  (stringify:cdr _))
            unquote-splicing (string ",@" (stringify:cdr _))
            make-br-fn       (string "["  (stringify:cdr _) "]")
                             (syntaxify _))
          (stringify _)]
        xs))
where stringify is some function that does sensible stringification. I don't know precisely how you're doing this, though, so that might not work.

-----

1 point by shader 6102 days ago | link

>I don't know precisely how you're doing this, though, so that might not work.

All my source table does is

  (sref source* '(def ,name ,parms ,@body) ',name)
for def and

  (sref source* '(mac ,name ,parms ,@body) ',name)
for mac.

Since name, parms, and body are read by the reader, reader macros have already been expanded. I'm looking for a way to print the source in a more readable fashion.

Your functions looks pretty close to what I want. Maybe stringify could just be syntaxify, and make it recursive? I don't know if tail recursion is possible because of make-br-fn, but the rest of it looks pretty simple.

If the current object is a cons, but not one of the above, return "(" (syntaxify:cdr _) ")", and if it's an atom return (string _).

I'll do some more thinking on it, but it looks like you're on the right track.

-----

1 point by absz 6102 days ago | link

That would work, except that

  (do
    (zap [cons 'head _] xs)
    (prn xs))
would come out as something like

  (do(zap[cons'head_]xs)(prnxs))
and I'm not sure how to deal with that, even if we add spaces.

-----

1 point by shader 6102 days ago | link

Adding spaces shouldn't be too hard; are you saying that we don't know how to handle indentation and newlines? I don't think that should be too hard. Looking at ppr and friends in string.arc should give us a clue as to that.

Is it possible to create a list in which the syntax is not expanded? I.e. preserve our syntaxification, after we've completed it? So that ', `, , ,@ [] become part of their symbols? That would probably be helpful, because then we could just use the built in ppr function, and not have to worry about formatting.

-----

1 point by shader 6104 days ago | link | parent | on: Source table

Would you guys prefer that the access function to the source table be named "src" or "source"? I don't know if src would cause any confilcts, but it fits with the current abbrev. style ;)

-----

2 points by rntz 6104 days ago | link

It should be named 'source* . Naming conventions are a good thing. Abbreviation for things like this is unnecessary. Also 'src or 'source might be a good name for a macro to get the source of a given function, much like 'help is now:

    (mac src (name) `(source* ',name))

-----

1 point by shader 6103 days ago | link

That's almost exactly what I was thinking ;)

-----

2 points by shader 6105 days ago | link | parent | on: Source table

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 6104 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 6103 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 6104 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 6104 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 6104 days ago | link

  (eval symbol)

-----

1 point by shader 6104 days ago | link

That works, I suppose

-----

1 point by cchooper 6103 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 6103 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 6100 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 6100 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 6099 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.

-----

4 points by shader 6105 days ago | link | parent | on: Source table

I was thinking at runtime, I.e. in the repl or available via the online help op. It would add greatly to the automatic documentation that currently exists.

-----

2 points by shader 6106 days ago | link | parent | on: How to install a new forum like this?

Here is a previous thread on this subject: http://arclanguage.org/item?id=8849

-----

1 point by shader 6108 days ago | link | parent | on: Fold

If you don't like _1, _2, etc. we could implement the system discussed here: http://arclanguage.org/item?id=8617. Basically, bind the unbound symbols inside the brackets in alphabetical order. It would work with _, _1, _2 as usual, but also x, y. Generally when people do short functions of a few variables they pick them in alphabetical order, so it makes sense. I'm just not sure how to go about implementing it. Presumably it would have to search the body for symbols which fail the bound predicate. sort them, and use them as the argument list. Unfortunately, it sounds like a macro with run-time knowledge. I don't know if macros have information on whether a symbol is bound or not; I would presume not.

Anyway, it's an idea.

-----

1 point by absz 6108 days ago | link

You could look at make-br-fn on Anarki; it crawls through the [] functions finding free variables of the form it wants (_\d+ or __). It might be possible to modify it to pick everything out, if we want to. The downside, of course, is that if you typo, say, string as strnig, the [] function will think it's a brand-new variable. And the other downside is that lexically speaking, '_10 < '_2, though we could always special-case numbers.

-----

1 point by shader 6108 days ago | link

Ok, I'll look at make-br-fn. And I hadn't thought about _10 < _2. However, when is someone going to write a 10 arg function with no names? Sounds suspicious to me. I agree that strnig would cause problems. However, unless you are very lucky, calling the arg "strnig" in function position will cause as much of an error as calling strnig in a normal function call. Of course, to see how useful it really is, I'd have to try it. I think that in most cases where all you want is three vars a, b, & c, or x, y, and z, it should work fine. And look better than _1 _2 _3, with less typing.

-----

1 point by shader 6115 days ago | link | parent | on: Can Arc run as a script instead of REPL?

Is there a way to execute a script that a) runs some arc or scheme code (specifically "(thread (asv))" or similar) and then b) starts the repl? Do I just change your main.arc to run the arc code I want, and then call ($ (tl))?

-----


Is there a way for an expression to access it's parent? We could either try and make err aware of it's surroundings, or re-read the source code and print the expression that contains the line number. Which is easier?

-----

1 point by shader 6120 days ago | link | parent | on: Curl in arc

How would you add support for cookies to http-get?

-----

1 point by shader 6120 days ago | link | parent | on: Curl in arc

Thanks.

Do we have any documentation for the various libs included in anarki? Or at least a list of what's available?

What use is a library if I can't find it, and can't use it once I do? ;)

-----

More