11

I open raku/rakudo/perl6 thus:

con@V:~/Scripts/perl6$ perl6
To exit type 'exit' or '^D'
> 

Is the above environment called the "interpreter"? I have been searching forever, and I cannot find what it's called.

How can I execute a rakudo script like I would do

source('script.R') in R, or exec(open('script.py').read()) in python3?

To clarify, I would like the functions and libraries in the script to be available in REPL, which run doesn't seem to do.

I'm sure this exists in documentation somewhere but I can't find it :(

4
  • 1
    Do you just want to execute the script file, or do you want the functions defined in the file available in the REPL?
    – rajashekar
    Oct 24, 2021 at 8:49
  • @rajashekar I would like the libraries/modules and functions from the script available in REPL
    – con
    Oct 24, 2021 at 12:23
  • If at the Linux/Unix shell command line, you type raku followed by your script name my_raku_script.p6, the rakudo compiler/interpreter executes the my_raku_script.p6 for you. If at the Linux/Unix shell command line you type raku followed by a return, the rakudo compiler/interpreter opens a REPL for you. Oct 24, 2021 at 20:35
  • 2
    .@con My guess is that the repl function Liz added to Rakudo earlier this year would do the trick if you're willing to call it from within your script. But it's not mentioned in the Raku docs (which is fair enough if it's Rakudo specific, which I imagine it is), and I haven't found it elsewhere either (which is not so cool but might be my lack of search skills/patience), and nor have I managed to get it to work. Anyhow, maybe .@Liz will read this and provide an answer...
    – raiph
    Oct 24, 2021 at 23:05

2 Answers 2

7

As Valle Lukas has said, there's no exact replacement. However, all usual functions are there to run external programs,

  • shell("raku multi-dim-hash.raku") will run that as an external program.
  • IIRC, source also evaluated the source. So you might want to use require, although symbols will not be imported directly and you'll have to use indirect lookup for that.
  • You can also use EVAL on the loaded module, but again, variables and symbols will not be imported.
3
  • Hi @JJ. ❶ Do you know how to get the repl function to work? (The one Liz introduced into Rakudo per my comment on .@con's question.) I tried but failed to get it to work. ❷ If you can, am I right to think that, if you run .@con's program (script) and it calls the repl function from within that program, then global variables/symbols (and perhaps even lexical ones?) are accessible in the REPL? ❸ Is this capability re-entrant, i.e. if one starts a REPL, then invokes a program from there that calls repl (to get an inner REPL), does the inner REPL function as correctly as the outer one?
    – raiph
    Oct 25, 2021 at 13:35
  • @raiph I didn't even know it existed...
    – jjmerelo
    Oct 25, 2021 at 15:16
  • 1
    .@JJ Ah. Hmm. If you can get it working (maybe ask Liz?), and ❷ pans out, then I'd say that that would be a very valuable addition to your answer (and/or it would be great if someone added another answer that describes it). I'm not sure if it's meant to be part of Raku or just Rakudo (I presume the latter), and even if it's just Rakudo, I could well imagine it's not intended to be something that's officially supported, but either way it does seem like a pretty big deal. @con can't be the only one wanting to be able to run a program and get access to its symbols, including ones it imports.
    – raiph
    Oct 25, 2021 at 18:08
7

It's called Read-Eval-Print Loop REPL. You can execute raku scripts direct in the shell: raku filename.raku without REPL. To run code from REPL you can have a look at run (run <raku test.raku> ) or EVALFILE.

The rosettacode page Include a file has some information. But it looks like there is no exact replacement for your R source('script.R') example at the moment.

2
  • 2
    how can I get the modules and libraries from the script available in the REPL?
    – con
    Oct 24, 2021 at 12:24
  • @con Wikipedia--REPL Oct 24, 2021 at 20:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.