raku

Incorporate C library function into Perl6 with NativeCall

为君一笑 提交于 2019-12-23 19:29:45
问题 I am attempting to use lgamma from C's math.h in Perl6. How can I incorporate this into Perl6? I have tried use NativeCall; sub lgamma(num64 --> num64) is native(Str) {}; say lgamma(3e0); my $x = 3.14; say lgamma($x); This works for the first number (a Str ) but fails for the second, $x , giving the error: This type cannot unbox to a native number: P6opaque, Rat in block <unit> at pvalue.p6 line 8 I want to do this very simply, like in Perl5: use POSIX 'lgamma'; and then lgamma($x) but I don

How to pipe a string to process' STDIN?

你说的曾经没有我的故事 提交于 2019-12-23 18:24:23
问题 I have a command that expects input from a pipe. For example, consider the famous cat command: $ echo Hello | cat Hello Suppose I have a string in a Perl 6 program that I want to pipe to the command: use v6; my $input = 'Hello'; # This is the string I want to pipe to the command. my $proc = run 'cat', :in($input); This does not work (I get no output). I can work around the problem by invoking bash and echo : my $proc = run 'bash', '-c', "echo $input | cat"; But is there a way I can do this

Installing Perl6 and Panda on Ubuntu 15.10. Problems with bootstrap.pl

二次信任 提交于 2019-12-23 17:41:20
问题 I am trying to install Panda on Ubuntu 15.10. First I tried: git clone --recursive git://github.com/tadzik/panda.git cd panda perl6 bootstrap.pl The last command gives error message: ===SORRY!=== Error while compiling bootstrap.pl Confused at bootstrap.pl:3 ------> use v6.⏏c; expecting any of: statement list Based on comments from @gfldex (see below), I then ran: > perl6 --version This is perl6 version 2014.07 built on parrot 6.6.0 revision 0 So the problem seems that an old version of Perl6

perl6 Is there a way to do editable prompt input?

时间秒杀一切 提交于 2019-12-23 17:29:11
问题 In bash shell, if you hit up or down arrows, the shell will show you your previous or next command that you entered, and you can edit those commands to be new shell commands. In perl6, if you do my $name = prompt("Enter name: "); it will print "Enter name: " and then ask for input; is there a way to have perl6 give you a default value and then you just edit the default to be the new value. E.g.: my $name = prompt("Your name:", "John Doe"); and it prints Your name: John Doe where the John Doe

Should this Perl 6 CATCH block be able to change variables in the lexical scope?

白昼怎懂夜的黑 提交于 2019-12-23 16:26:37
问题 I'm playing with resumable exceptions. In this example, I try to numify something that doesn't numify. I catch that and attempt to give the $value variable an appropirate value then resume execution: try { my $m = 'Hello'; my $value; $value = +$m; put "Outside value is 「{$value.^name}」"; CATCH { when X::Str::Numeric { put "「$m」 isn't a number!"; put "Inside value is 「{$value.^name}」"; $value = 0; put "Inside value is now 「$value.」"; .resume; } default { put "Unhandled type 「{.^name}」"; } }

Perl 6 capturing repeating matching groups separately?

狂风中的少年 提交于 2019-12-23 15:03:17
问题 I believe Perl 6 offers the capability of capturing repeating groups separately as opposed to earlier flavors where you could only capture the last group or the whole matched group string. Can someone please give a good example how to use this awesome feature of Perl 6? For e.g. I need to capture all the matching groups for this regex ((?:(?:(?:(?:")(?:[^"]*?)")|(?:(?<!")(?:[^"]*?)(?!")))(?<!\\)\|)*) How do I do that in Perl 6? 回答1: In general, if you quantify a capture, you simply get a list

When is white space really important in Perl6 grammars?

早过忘川 提交于 2019-12-23 10:54:12
问题 can someone clarify when white space is significant in rules in Perl 6 grammars? I am learning some by trial and error, but can't seem to find the actual rules in the documentation. Example 1: rule number { <pm> \d '.'? \d*[ <pm> \d* ]? } rule pm { [ '+' || '-' ]? } Will match a number 2.68156e+154 , and not care about the spaces that are present in rule number . However, if I add a space after \d* , it will fail. (i.e. <pm> \d '.'? \d* [ <pm> \d* ]? fails). Example 2: If I am trying to find

<.ident> function/capture in perl6 grammars

六眼飞鱼酱① 提交于 2019-12-23 10:25:57
问题 While reading the Xml grammar for perl6 (https://github.com/supernovus/exemel/blob/master/lib/XML/Grammar.pm6), I am having some difficulties understanding the following token. token pident { <!before \d> [ \d+ <.ident>* || <.ident>+ ]+ % '-' } More specifically <.ident>, there are no other definitions of ident, so I am assuming it is a reserved term. Though i cant find find a proper definition on perl6.org. Does anyone know what this means? 回答1: Does anyone know what [ <.ident> ] means?

Print embedded Pod as formatted text with termcap escapes

落花浮王杯 提交于 2019-12-23 10:25:50
问题 I am trying to output embedded Pod as ANSI text to the terminal. In Perl 5 I can use Pod::Text::Termcap: use strict; use warnings; use Pod::Text::Termcap; my $str = do {local $/; <DATA>}; my $parser = Pod::Text::Termcap->new(); $parser->parse_string_document( $str, \*STDERR ); __DATA__ =head1 SYNOPSIS my_test_command I<filename> [OPTIONS] =head1 ARGUMENTS =over 4 =item I<filename> File name to test =back =head1 OPTIONS =over 4 =item B<--help> Prints help =back =head1 DESCRIPTION A sample test

Perl6: Constructors in subclases

五迷三道 提交于 2019-12-23 10:25:42
问题 Is there a way to assign instance variables declared in a super class, from a constructor in a sub class? I have gotten used to using BUILD() as constructor, but I am wondering if this is a good idea. I.e: use v6; class File { has $!filename; } class XmlFile is File { submethod BUILD(:$!filename) { } } my XmlFile $XF = XmlFile.new(filename => "test.xml"); The code above doesn’t work, prompting an error: "Attribute $!filename not declared in class XmlFile". Is it a matter of using the right