Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can you clone a Perl 6 Proc?

Tags:

raku

I was playing with this in 2018.01:

my $proc = Proc.new: :out;
my $f = $proc.clone;
$f.spawn: 'ls';
put $f.out.slurp;

It says it can't do it. It's curious that the error message is about a routine I didn't use and a different class:

Cannot resolve caller stdout(Proc::Async: :bin); none of these signatures match:
    (Proc::Async:D $: :$bin!, *%_)
    (Proc::Async:D $: :$enc, :$translate-nl, *%_)
  in block <unit> at proc-out.p6 line 3
like image 935
brian d foy Avatar asked Apr 26 '18 18:04

brian d foy


People also ask

Does this still work in the newest versions of Perl?

This still works in the newest versions of Perl, but it is not recommended since it bypasses the subroutine prototypes. Let's have a look into the following example, which defines a simple function and then call it. Because Perl compiles your program before executing it, it doesn't matter where you declare your subroutine. Hello, World!

What is Perl 6?

Perl 6 is the long-awaited redesign and reimplementation of the popular and venerable Perl programming language. It’s not out yet–nor is there an official release date–but the design and implementations make continual progress. Innumerable programmers, hackers, system administrators, hobbyists, and dabblers write Perl 5 quite successfully.

What are Perl subroutines?

Perl-Subroutines. A Perl subroutine or function is a group of statements that together performs a task. You can divide up your code into separate subroutines. How you divide up your code among different subroutines is up to you, but logically the division usually is so each function performs a specific task.

Why does Oracle recommend using software-only installation instead of cloning?

Hence, Oracle recommends that you use the software-only installation option, available in the database installer, instead of clone.pl to clone your database. During cloning, Oracle Universal Installer (OUI) prompts you to run scripts that require root privileges.


1 Answers

Everything inherits a default clone method from Mu, which does a shallow clone, but that doesn't mean that everything makes sense to clone. This especially goes for objects that might hold references to OS-level things, such as Proc or IO::Handle. As the person who designed Proc::Async, I can say for certain that making it do anything useful on clone was not a design consideration. I didn't design Proc, but I suspect the same applies.

As for the error, keep in mind that the Perl 6 standard library is implemented in Perl 6 (a lot like in Java and .Net, but less like Perl 5 where many things that are provided by default go directly to something written in C). In this particular case, Proc is implemented in terms of Proc::Async. Rakudo tries to trim stack traces somewhat to eliminate calls inside of the setting, which is usually a win for the language user, but in cases like this can be a little less helpful. Running Rakudo with the --ll-exception flag provides the full details, and thus makes clearer what is going on.

like image 83
Jonathan Worthington Avatar answered Sep 18 '22 15:09

Jonathan Worthington