How to execute raku script from interpreter?

Viewed 306

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 :(

2 Answers

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.

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.
Related