11

When I use REPL, I sometimes need to look up how a function functions e.g. splice. I usually go to the documentation website. But I don't always have internet and it'd be good if I could write help("splice") or something (e.g. splice?) in the REPL directly and see the result.

Then I thought p6doc that came with Rakudo Star can be used because p6doc Array.splice on command line gives documentation. Then I do this in REPL:

> run <p6doc Array.splice>

Proc.new(in => IO::Pipe, out => IO::Pipe, err => IO::Pipe, exitcode => 1,
         signal => 0, pid => Nil, command => ("p6doc", "Array.splice"))

but it has exitcode 1. When I capture outputs with :out and :err, both are empty strings but I don't know why.

Is there a way I can make this kind of help functionality in REPL work either with "run p6doc" or something else?

I use Windows10 with

Welcome to ™ v2021.07.
Implementing the ™ programming language v6.d.
Built on MoarVM version 2021.07.
codesections
  • 8,900
  • 16
  • 50
  • I'm afraid not. Not even p6doc is really working now... But it's certainly something that could be handy. – jjmerelo Sep 15 '21 at 15:03
  • @jjmerelo thank you for your response. So do you think `run p6doc` failing has to do with `p6doc` itself –  Sep 15 '21 at 15:36
  • it's entirely possible. You might want to use rakudoc, but I'm not so sure about that one either. – jjmerelo Sep 15 '21 at 16:50
  • @Hanselmann If you are not absolutely committed to sticking with VSCode only rather than perhaps also using Comma, and have not already spent an evening with the latter, I recommend you try that. It has [loads of features](https://commaide.com/features) that VSCode will likely never have, even with a Raku plugin, and the free version (Community) includes most features, including [viewing docs for built in and user defined types and routines](https://www.youtube.com/watch?v=FvDL1XJ2nlY#t=18s), nice listings of multi signatures, and [a REPL](https://www.youtube.com/watch?v=8zqkq8sPQAI#t=18s). – raiph Sep 15 '21 at 20:16
  • 1
    @raiph I did try Comma IDE but it was lagging and slow (on Windows)... Maybe it's because of my system but someone also made similar comments in discord #raku, so... (but I haven't tried the current most recent version I guess, so I will try again probably, thanks.) –  Sep 15 '21 at 20:34
  • 1
    @Hanselmann That sucks. I see that posting a [**slow/laggy**](https://github.com/microsoft/vscode/issues/113647) issue on VScode GH got the poster a solution in 4 days (though I see other VSCode issues like [**Slow reponse to scroll and typing**](https://github.com/microsoft/vscode/issues/107016) remain open). Edument aren't Microsoft, but perhaps you would be willing to email `info@commaide.com` to let them know it's lagging/slow (and include your Windows version and other basic system info)? (If you do, please suggest they open a GH repo with an issue Q for Comma.) Maybe they'll respond... – raiph Sep 15 '21 at 21:03
  • 1
    For the record: I tried a later version of Comma and it worked very well on Windows! –  Nov 16 '21 at 09:37

2 Answers2

8

Your specific question

The error you're getting when you enter run <p6doc Array.splice> in the REPL looks like the error you'd get for a command that can't be found. You can confirm that by entering qx <p6doc Array.splice> – I suspect that you'll get an error that more clearly says that the p6doc command can't be found.

Assuming that is the issue, it sounds like $PATH environmental variable isn't getting set correctly in your REPL. I'm not sure why that would be and I don't have a Windows box handy to test with. But, in any event, you should be able to work around that by specifying an absolute path to the p6doc executable. (For me, that'd be something like qx </home/dsock/.raku/bin/p6doc Array.splice>, but obviously you'll have a different path).

(Oh, and you would probably be better off with qx or shell for this use rather than run, though both should work. See the shell quoting docs.)

Broader question – state of the CLI doc ecosystem

As JJ mentioned in there comment, the Raku ecosystem is in the process of migrating from p6doc to rakudoc source, and neither is 100% where it should be to offer great CLI/REPL documentation. It's definitely a work in progress and an area where we need to improve. Installing rakudoc (with zef install 'rakudoc:auth<github:Raku>') might offer a better experience but, as I said, it's something the community is still working on. PRs welcome!

In the meantime, another option for offline access to the docs is to build the docs locally (instructions in the raku/doc README) and run a local server. This requires either docker or perl, graphviz, and nodejs (and we're also working to slim down those requirements). That way, while you'd still need to switch to a browser to check the docs, at least having slow/no Internet access wouldn't be a problem.

Other options for info in the REPL

You mentioned the idea of a function along the lines of help('splice'). Nothing exactly like that currently exists – though it'd be a good idea for a module. But Raku does provide rich tools for introspection, which can offer much of the same functionality.

For example, if you wanted to check the order to provide the arguments, you can list all of the 30 (!) signatures for Array.splice with:

for Array.^lookup('splice').candidates».signature { .say }
# if "splice" weren't a multi method, you don't need `.candidates»`

Some other good introspection methods to know:

  • &say.candidates».signtaure # same as above, but for independent sub/multi
  • Array.^methods».name
  • $x.VAR.WHAT # returns «(Scalar)» if $x was assigned rather than bound
  • Rat.^attributes».name # all attributes (public and private)
  • Rat.^attributes.grep({Rat.^has_public_attribute(.name)})».name
  • Array.^mro # All classes Array inherits from
  • Array.^roles
  • Foo.WHY # returns any declarator block for the type/method/sub/attribute

The last is worth elaborating on: .WHY prints any declarator pod blocks for the item – that is, any comments in the source code that were made with #| or #= (for the preceding item). It's good practice to include these doc comments in the public items that your module exports, and many modules in the Raku ecosystem do. For a variety of reasons, the Rakudo source code doesn't include #| comments, so .WHY isn't useful for built-in types.

(In my dream world, we'd see a REPL command such as the help you suggested that combines some filtered version of the output from rakudocs for built-in types with .WHY output for custom types, but we don't have anything like that yet.)

codesections
  • 8,900
  • 16
  • 50
  • 1
    thanks for the response. `qx` & `shell` with `` works. For `run`, I specified the full path to `p6doc.bat` as you said and it also worked. As for the introspections: thanks! But IMHO some are verbose, multi signatures are somewhat scary and I'm not sure in which order `^methods` gives the methods (would be cool if first that type-specific methods are given, and then inherited ones, and then CAPITALS etc.). Anyway, I hope REPL will someday ship with `help` command or `?` postfix. Now I will try to make a wrapper around qx p6doc and try making it available every time REPL opens. –  Sep 15 '21 at 19:33
5

While the current built-in REPL does not have help functionality, the Comma IDE does include its own Raku REPL (found on the Tools menu, and included in the free version). Pressing Ctrl+Q while stood on a routine name or type name will try to resolve documentation for it. This includes builtins:

Example of builtins documentation in Comma Raku REPL

But also modules that have Pod declarator docs added:

Example of documentation of Cro::Uri in the Comma Raku REPL

While installing an entire IDE is perhaps a bit much just to get a REPL with help, I figured it was worth a mention - especially since I've encountered folks who are using Comma, but don't realize there's it includes REPL too!

Jonathan Worthington
  • 29,104
  • 2
  • 97
  • 136