-
Notifications
You must be signed in to change notification settings - Fork 371
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Compiler docs #1040
Compiler docs #1040
Conversation
This will enable us to get help on these commands from within hy.
I'm not sure about this...the majority of these are duplicated from the main docs, resulting in having to update them in two places, and the |
I agree with @kirbyfan64. Perhaps we can document briefly what |
The point of this is to be able to get help from within hy on what the compiler functions do. See http://kitchingroup.cheme.cmu.edu/blog/2016/04/03/Getting-hylp-in-hy/ for example. None of the functions defined in compiler.py have any docstrings attached to them, so they are not introspectable in an editor to find out what they do, e.g. http://kitchingroup.cheme.cmu.edu/blog/2016/04/06/Another-step-towards-HyDE/. This also makes it possible to auto-generate documentation, rather than update it in one place that isn't the code, or two places. |
I guess that makes sense...but it would first require the ability to even auto-generate the docs (which isn't possible ATM). But I still think some of the docstrings, like |
I like the idea of auto-generating the reference docs from the docstrings. They're not identical currently, so for each we'd have to pick the best of the two or merge them somehow. The examples could also be doctests, once we get that working for Hy code. (see #1019.) This way, we can always be sure the examples work as intended, and we can easily access the references from the repl. The rest of the docs will still have to be updated by hand, but we should be able to automatically test the examples there too. |
All of these are used by users I think, but not in an obvious way to (cut col 0 1 2) uses compile_cut_expression. A user would not directly call this, but by e.g. #+BEGIN_SRC hy #+RESULTS:
#+end_example Matthew Egan Odendahl writes:
Professor John Kitchin |
It isn't that far off though. In this post Self explanatory is in the eye of the beholder ;) For people brand-new Ryan Gonzalez writes:
Professor John Kitchin |
@jkitchin Good point about doctest; that would be really useful, since the documentation examples frequently go out of date. |
For example, These examples didn't work for me today: http://docs.hylang.org/en/latest/language/api.html#unquote I gathered that name is a function, and def doesn't redefine it. => (def name "Cuddles") The docs advertise: Ryan Gonzalez writes:
Professor John Kitchin |
@jkitchin That should work outside the REPL. When you call |
That is more or less what I was aiming at in this code: I didn't get to deferring to built-in Python help yet, but I would like to John Professor John Kitchin On Mon, Apr 11, 2016 at 3:50 PM, Matthew Egan Odendahl <
|
Here goes a hydoc macro that covers functions in hy, including macros, and Python functions. I think this should resolve #892 and #356.
|
Maybe more like this? (defn hydoc* [sym]
(import hy)
(. (or (->> false
(.get hy.compiler._compile_table sym)
(.get (get hy.macros._hy_macros nil) sym)
(.get hy.core.shadow.__dict__ sym)
(.get hy.core.language.__dict__ sym))
(eval sym))
__doc__))
(defmacro hydoc [sym]
`(hydoc* '~sym)) |
You could override Python's interactive help using these too: (defmacro help [item]
(if (symbol? item)
`(print (hydoc ~item))
`((get __builtins__ "help") ~item))) |
That is pretty nice, I haven't used the threading macros before. Pretty
Just curious is the hydoc* an indication it is a function (the * at the Matthew Egan Odendahl writes:
--
|
Not exactly. In mathematics, you often talk about some object In this case, the macro lets us avoid quoting the symbol when calling the function, but we still have the function when we need it to e.g. map over a list of symbols and return all of their docstrings. This would be more difficult with only the macro. I'm less confident this is the right approach for Hy (at least in this instance), because of #1041, (Hy's eval doesn't work like Clojure, we might change that #1043.). We wouldn't need that eval if it was all in the macro. You could just unquote it. |
The "TODO" docstrings in this PR are for:
|
It doesn't look like any core members have approved this. While it would be great to have docstrings, I don't want to have the same documentation appear in two different places in the codebase, like @kirbyfan64 was talking about. I think we need to have a way for docstrings to update the manual (e.g., #1044) or vice versa. Copying and pasting is no good even as a temporary solution. |
All this pull request does is add one line to the checkargs decorator to set its doc attribute on the returned function, and add docstrings to all the functions decorated by @builds. A few docstrings are marked TODO. I used the documentation at http://docs.hylang.org/en/latest/ for this.