Help language development. Donate to The Perl Foundation

Text::CodeProcessing cpan:ANTONOV last updated on 2022-04-27

#!/usr/bin/env perl6

=begin para
This file shows how create simple "remote kernel" process that can be accessed through ZMQ
from, say, Mathematica or RStudio notebooks.

Since the code is small it can be included inside Mathematica or R packages.
See the Mathematica package

The code below is an adaptation of one of the introductory codes from the ZMQ guide.
See L<"ØMQ - The Guide", "Chapter 1, Basics"|>.
=end para

use v6;

use Net::ZMQ4;
use Net::ZMQ4::Constants;
use Text::CodeProcessing::REPLSandbox;
use Text::CodeProcessing;

sub MAIN(Str :$url = 'tcp://*', Str :$port = '5555', Str :$rakuOutputPrompt = '', Str :$rakuErrorPrompt = '#ERROR: ') {

    # Socket to talk to clients
    my Net::ZMQ4::Context $context .= new;
    my Net::ZMQ4::Socket $responder .= new($context, ZMQ_REP);

    ## Create a sandbox
    my $sandbox =;

    while (1) {
        my $message = $responder.receive();
        say "Received : { $ }";
        my $res = CodeChunkEvaluate($sandbox, $, $rakuOutputPrompt, $rakuErrorPrompt);