develooper Front page | perl.perl6.users | Postings from July 2021

Re: REPL / Linenoise question (backslashes)

Thread Previous | Thread Next
From:
William Michels via perl6-users
Date:
July 19, 2021 20:47
Subject:
Re: REPL / Linenoise question (backslashes)
Message ID:
CAA99HCwpeHVMdsp_PZ_F_ewZ1vQOXfo=p-WQUSUK96TXat3Mbw@mail.gmail.com
Hi Rob!

Thanks for the reply. So what you're saying is the "backslash-newline"
combination tells the REPL that it has received incomplete input? Otherwise
I don't see how the Raku REPL knows how to cycle from taking input at its
prompt and moving to the read/evaluate step.

I took a quick look at how three other languages (R, Python2.7, Ruby)
handle backslashes in their REPLs. None of the versions below are "the
latest and greatest", but it should give us an idea what (historically)
other languages have done. R balks at backslashes (but can accept
multi-line input pasted into the terminal, as well as pasted into the
R-GUI). Python2.7 and Ruby appear to accept backslashes as continuation
lines, then balk at syntax errors (Python immediately, Ruby after typing
'exit'):

$ R

R version 3.6.3 (2020-02-29) -- "Holding the Windsock"
Copyright (C) 2020 The R Foundation for Statistical Computing
Platform: x86_64-apple-darwin15.4.0 (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

  Natural language support but running in an English locale

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> \
Error: unexpected input in "\"
> \\
Error: unexpected input in "\"
> \\\
Error: unexpected input in "\"
> q()

$ python
Python 2.7.10 (v2.7.10:15c95b7d81dc, May 23 2015, 09:33:12)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> \
... \
... \\
  File "<stdin>", line 3
    \\
     ^
SyntaxError: unexpected character after line continuation character
>>> exit()

$ ruby --version
ruby 2.0.0p481 (2014-05-08 revision 45883) [universal.x86_64-darwin14]
$ irb --version
irb 0.9.6(09/06/30)
$ irb
irb(main):001:0>
irb(main):002:0* \
irb(main):003:0* \
irb(main):004:0* \\
irb(main):005:0* \\\
irb(main):006:0*
irb(main):007:0* exit
SyntaxError: (irb):4: syntax error, unexpected $undefined
from /usr/bin/irb:12:in `<main>'
irb(main):008:0> exit


HTH, Bill.



On Sat, Jul 17, 2021 at 6:46 PM rir <rirans@comcast.net> wrote:

> On Wed, Jul 14, 2021 at 08:40:07AM -0700, William Michels via perl6-users
> wrote:
>
> > > \
> > {}
> > > \\
> > {}
> > > \\\
> > {}
>
> > Curiously, I seem to create an object in my REPL environment when I enter
> > either a single-, double-, or triple-backslash.   ...
>
> Your backslash destroys the newline so the input is non-existent.  The
> empty hash seems an implementation artifact; a place to capture
> the type and value of the code.  Perhaps issuing a prompt as if a bare
> newline
> was typed would be better.
>
> Witness:
>
> > my $x = 1 + 3 \
> {}
> > my $x = ( 1 + 3 \ )
> 4
> > \ # comment
> Nil
> > ;
> Nil
>
> Rob
>

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About