Add a REPL #213

Open
wolverian opened this Issue Nov 22, 2011 · 6 comments

Projects

None yet

4 participants

@wolverian

It'd be nice if Perl5i included an easy way to get a REPL running, e.g. perl5i -r or ipb (like irb from Ruby). There are problems with reserving a command line flag, of course, and ipb is just ugly. re.pl is cute, but it doesn't ship with Perl5i.

I think this is in the scope of Perl5i. (I think it's in the scope for Perl itself!)

@schwern

Since I'm learned with the debugger, I've never caught the REPL bug myself, but I understand the utility.

Two questions to get things started: What makes a good REPL? Can we just ship Devel::REPL?

@wolverian

There are a few basic things a REPL must do:

  • Preserve lexical environment across lines
  • Print the return value(s) of each input line

And it should support the following:

  • Allow easy loading of files
    • On the command line when starting the REPL
    • Inside the REPL
  • Support proper readline editing (history, emacs keys, etc.)
  • Multiple line editing support (e.g. 'sub foo {' would enter a nested prompt until the closing })

And it would be nice if it supported some of these features:

  • Dump variable contents (I'd advocate Data::Dump)
  • Show the lexical environment
  • Show the current package

There is a ton of other stuff you could do; http://pry.github.com/ is a pretty REPL to take inspiration from.

In the short term, shipping Devel::REPL and advertising it would be fine by me. In the slightly longer term, I'd like to investigate if it could be enhanced to be a more complete REPL than it is right now, along the lines of pry.

@schwern

Good list. My nits...

  • Preserve lexical environment across lines

I was going to disagree, but that's how the debugger works and I've never had a problem.

  • Easy loading of files (inside the REPL)

Is require/use/do insufficient? Or are you referring to REPL plugins?

  • Multiple line editing support

Eeeeeerch... nice feature, not so easy in Perl. Maybe a simpler alternative is to have a hotkey which opens up $EDITOR where you can type in and edit a command. Bonus points if it's split screen with something like curses! If the hotkey is pressed while some code is already typed in, this shows up in the editor.

  • Dump variable contents

I'd call that critical. And we have plenty of existing ways to do it.

This calls into question whether printing the return value of each line is a normal stringification or a dump. A dump would be nice, except every once in a while you'll get a vomit as some huge nested object comes out, like with DBIx::Class. So I'd say stringification by default.

  • Show the lexical environment

For example...?

@trapd00r

I'd also like a repl. Some notes:

  • Preserve lexical environment across lines

Eval::WithLexicals is perfect for this. It even have a tiny repl script in the SYNOPSIS.

Personally I do prefer dumps over stringification, perhaps this could be configurable.

@wolverian

Devel::REPL actually already does most of this via plugins, e.g. multiline editing via detecting multiline constructs with PPI. (Whether PPI is something perl5i wants to use is another matter.)

Is require/use/do insufficient? Or are you referring to REPL plugins?

It probably is sufficient. As for plugins, I'd rather I didn't need to load a bunch of plugins just to get a usable REPL. :)

  • Show the lexical environment For example...?

Get a list of lexical variables, like with B::LexInfo or such.

@grtodd

Hi I like the idea of a smaller simpler REPL that would come with perl5i, but for right now Devel::REPL is a great tool and some of what it requires is already installed with perl5i.

Devel::REPL's "re.pl" script looks for "$HOME/.re.pl/repl.rc" and runs statements in that file as if they are being executed from the REPL commandline. You can also name profiles under $HOME/.re.pl/ and call re.pl with --rcfile. I seem to be successfully using re.pl with perl5i using this rcfile:

# $HOME/.re.pl/p5i
# call this profile with re.pl --rcfile p5i
use perl5i::latest ;                                                                                           
use indirect ;   # this is needed last

Without 'use indirect ;' I get this error:
Error executing script /home/user/.re.pl/p5i: Indirect call of method "_hints" on object "$_REPL" at (eval 376) line 10.

daxim on IRC pointed out that use indirect; is the work-around for this since LexEnv's support is incomplete. So to quote daxim this is "not a perl5i bug".

ps: Running two copies of re.pl (one with 'use perl5i::latest;' and one without) in a tmux or screen split screen or in a couple of xterms is a fun and educational way to experiment with classic versus Modern/p5i idioms of "Pumpkin Perl" ;-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment