Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to execute raku script from interpreter?

Tags:

raku

rakudo

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

like image 364
con Avatar asked Oct 24 '21 01:10

con


People also ask

How do you write a raku program?

A Raku program consists of zero or more statements. A statement ends with a semicolon or a curly brace at the end of a line. In Raku, single line comments start with a single hash character # and extend until the end of the line. Raku also supports multi-line/embedded comments.

Is there a compiler for raku?

Depending on your needs, Raku and its compilers may or may not be ready for you. That said, version 6.c (Christmas 2015) is the first official release of Raku as a language, along with a validation suite and a compiler that passes it. Why should I learn Raku?

What is the difference between a statements and comments in raku?

A statement ends with a semicolon or a curly brace at the end of a line. In Raku, single line comments start with a single hash character # and extend until the end of the line. Raku also supports multi-line/embedded comments. The compiler doesn't evaluate comments as program text and they're only intended for human readers.

Where can I find all the Raku talks?

Visit the site of the Raku Conference 2021 to see all the recorded talks! Hi, my name is Camelia. I'm the spokesbug for the Raku Programming Language. Raku has been developed by a team of dedicated and enthusiastic open source volunteers, and continues to be developed.


2 Answers

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.
like image 77
jjmerelo Avatar answered Oct 05 '22 01:10

jjmerelo


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.

like image 36
LuVa Avatar answered Oct 05 '22 02:10

LuVa