Re: File::Copy ??

2017-03-22 Thread Brad Gilbert
For basic copy and move, the built-in subs should work https://docs.perl6.org/routine/copy https://docs.perl6.org/routine/move On Wed, Mar 22, 2017 at 12:24 AM, ToddAndMargo wrote: > Hi All, > > Do we have anything like > > http://perldoc.perl.org/File/Copy.html > > under

Re: Am I suppose to be able to change a variable's type on the fly?

2017-03-22 Thread Brad Gilbert
The default type constraint is Mu, with a default of Any (everything is of type Mu, and most are of type Any) You shouldn't be able to change the type constraint of a scalar container (used for rw variables) Changing the type of a value, of course makes no sense. (a Str is always a Str, even

Re: next

2017-06-19 Thread Brad Gilbert
On Mon, Jun 19, 2017 at 11:15 AM, Andy Bach wrote: > > On Fri, Jun 16, 2017 at 11:11 PM, Gabor Szabo wrote: >> >> If the loop has some action and a condition it will jump to execute >> the action again (increment $i) and check the condition and act >>

Re: need help with "next"

2017-05-23 Thread Brad Gilbert
You do realize that `next` immediately stops the current iteration and goes onto the *next* one right? That is, there is no point putting any code after it because it will never be run. On Tue, May 23, 2017 at 11:30 PM, ToddAndMargo wrote: > Hi All, > > I have a test code

Re: How do you call the variable types?

2017-06-09 Thread Brad Gilbert
@ does the Positional role % does Associative & does Callable $ causes its value to be an item (its values do not flatten into an outer list when you use `flat`) my %hash is SetHash; Array does Positional, and all of its values are itemized We are unlikely to call $ variables "generic"

Re: <<>> question

2017-10-05 Thread Brad Gilbert
On Thu, Oct 5, 2017 at 11:44 AM, Andy Bach wrote: > >> is ><<>> >> synonymous with >qw[] > ? `<<>>` is the same as `qqww<<>>` Which is short for `Q :qq :ww <<>>` the `:qq` is short for `:double`, that is it turns on double quote behaviour `:double` is short for

Re: tip: case insensitive test

2017-11-07 Thread Brad Gilbert
The way to add `:i` to regex without using `m` is to include it inside of the regex `/:i abcdef/` On Fri, Nov 3, 2017 at 5:30 PM, ToddAndMargo wrote: > Dear List, > > Okay, I am pretty sure there are no copyrights here. > > I had a problem where I had to read through a

Re: any better explanation of look ahead assertions

2018-05-10 Thread Brad Gilbert
On Thu, May 10, 2018 at 9:09 PM, ToddAndMargo <toddandma...@zoho.com> wrote: > On 05/10/2018 07:06 PM, Brad Gilbert wrote: >> >> You could read how they work in PCRE > > > What is PCRE? Perl Compatible Regular Expressions, Basically someone reimplemented the r

Re: any better explanation of look ahead assertions

2018-05-10 Thread Brad Gilbert
On Thu, May 10, 2018 at 8:13 PM, ToddAndMargo wrote: > Hi All, > > Looking at: > https://docs.perl6.org/language/regexes#Lookahead_Assertions > https://docs.perl6.org/language/regexes#Lookbehind_assertions > > I can't tell heads from tails. Does anyone know of a

Re: I need `dir` help

2018-05-10 Thread Brad Gilbert
On Thu, May 10, 2018 at 7:02 PM, ToddAndMargo wrote: > On 05/10/2018 04:56 PM, Brandon Allbery wrote: >> >> I think you'll need to provide a better explanation of what you're trying >> to accomplish. I can think of lots of ways to do useful things with the >> output of

Re: mixin syntax: does vs but

2018-06-12 Thread Brad Gilbert
On Tue, Jun 12, 2018 at 2:16 PM, JJ Merelo wrote: > This is what the documentation says: https://docs.perl6.org/syntax/WHAT > You can override it, but we'll pay no attention anyway, basically. So you > can't achieve it otherwise, I guess. It is easy to achieve. sub user-made-what ( ::Type )

Re: mixin syntax: does vs but

2018-06-12 Thread Brad Gilbert
On Tue, Jun 12, 2018 at 12:55 PM, Joseph Brenner wrote: > Thanks, both your suggestion and JJ Merelo's work, but I think I like > yours for readability: > > # # using binding, suggested by JJ Merelo > # my @y := @x but LookInside; > > # suggested by Elizabeth Mattijsen l...@dijkmat.nl >

Re: stackoverflow vs the world (and perl6-users)

2018-06-12 Thread Brad Gilbert
On Tue, Jun 12, 2018 at 3:57 PM, Brandon Allbery wrote: > I replied to this one in private, but I want to make a point in public as > well. > > On Tue, Jun 12, 2018 at 4:24 PM Brad Gilbert wrote: >> >> The barrier is not with Stack Overflow. (←What I obviously meant) >

Re: stackoverflow vs the world (and perl6-users)

2018-06-12 Thread Brad Gilbert
On Tue, Jun 12, 2018 at 2:29 PM, The Sidhekin wrote: > > > On Tue, Jun 12, 2018 at 9:18 PM, Brad Gilbert wrote: >> >> On Tue, Jun 12, 2018 at 1:19 PM, Joseph Brenner wrote: >> > Attention conservation: it's unlikely I'm going to say something >> > int

Re: stackoverflow vs the world (and perl6-users)

2018-06-12 Thread Brad Gilbert
On Tue, Jun 12, 2018 at 2:42 PM, Brandon Allbery wrote: > On Tue, Jun 12, 2018 at 3:38 PM Brad Gilbert wrote: >> >> > The barrier is non-existent. >> >> I have only ever heard about speculated and imagined barriers. > > > This is not proof that such barr

Re: stackoverflow vs the world (and perl6-users)

2018-06-12 Thread Brad Gilbert
On Tue, Jun 12, 2018 at 1:19 PM, Joseph Brenner wrote: > Attention conservation: it's unlikely I'm going to say something > interesting you haven't thought of already. > > A side-discussion that came up here: should you ask questions here, or > at stackoverflow (or both here *and* at

Re: How do I remove leading zeros?

2018-06-13 Thread Brad Gilbert
On Wed, Jun 13, 2018 at 1:09 PM ToddAndMargo wrote: > > On 06/13/2018 11:06 AM, ToddAndMargo wrote: > > On 06/13/2018 11:03 AM, ToddAndMargo wrote: > >> On 06/13/2018 11:00 AM, Larry Wall wrote: > > > $ p6 'my $x = "01.000.103.006.10"; $x ~~ s:g/«0+)>\d//; say "$x"' > > 1.0.103.6.10 > >

Re: An operation first awaited

2018-05-28 Thread Brad Gilbert
Comments inline. On Mon, May 28, 2018 at 2:02 AM, Norman Gaywood wrote: > T""his simple program creates a thread to read a directory with dir() and > place the files on a channel. $N worker threads read that channel and > "process" (prints) the files. But I'm getting this "An

Re: my keeper on random numbers

2018-05-26 Thread Brad Gilbert
On Sat, May 26, 2018 at 10:59 PM, ToddAndMargo wrote: > On 05/26/2018 05:10 AM, Brian Duggan wrote: >>> >>> To convert to an positive integer, use truncate: >>> $ p6 'say 1000.rand.truncate;' >>> 876 >> >> >> or use pick: >> >> perl6 -e 'say (^1000).pick' >> 209

Re: need second pair of eyes

2018-06-03 Thread Brad Gilbert
It's -I. not -I On Sun, Jun 3, 2018 at 5:05 PM, ToddAndMargo wrote: > On 06/03/2018 02:54 PM, Brad Gilbert wrote: >> >> You can use q[./] instead of \'./\' >> (especially useful so that it will work on both Windows and Unix >> >> But in this case it is even bett

Re: need second pair of eyes

2018-06-03 Thread Brad Gilbert
You can use q[./] instead of \'./\' (especially useful so that it will work on both Windows and Unix But in this case it is even better to use -I and -M p6 -I. -MRunNoShell -e '( my $a, my $b ) = RunNoShell::RunNoShell("ls *.pm6"); say $a;' On Sun, Jun 3, 2018 at 4:47 PM,

Re: <> question

2018-06-03 Thread Brad Gilbert
On Sun, Jun 3, 2018 at 3:08 PM, ToddAndMargo wrote: > On 06/03/2018 11:01 AM, Brandon Allbery wrote: > >> Is there something missing in the examples at the link? >> > > Well, a bit. When I see > > chmod 0o755, ; > > I think `myfile1` and `myfile2` are "functions", not > data. > They

Re: using run

2018-06-21 Thread Brad Gilbert
:out can take an argument On Wed, Jun 20, 2018 at 10:32 AM Theo van den Heuvel wrote: > > Hi all, > > trying to make sense of the documentation on run: > https://docs.perl6.org/routine/run. > In particular the last part. I don't understand the adverbs :out and : > err there. > Can I set it up

Re: Force integers in an array?

2018-08-06 Thread Brad Gilbert
> my Int @a; > @a[0] = '1' Type check failed in assignment to @a; expected Int but got Str ("1") in block at line 1 On Mon, Aug 6, 2018 at 3:39 PM ToddAndMargo wrote: > > Hi All, > > Is there a way to force all the members of an array > to be integers and to error out is a non-integer > is

Re: MAIN subroutine

2018-07-19 Thread Brad Gilbert
The MAIN sub executes after the mainline. After all should MAIN be called before or after do-it('2') in the following? sub do-it(Str $string) { say $string; } do-it("1"); multi sub MAIN() { say "This is MAIN so this should print after the mainline"; }

Re: Bailador vs. Cro

2018-07-09 Thread Brad Gilbert
Bailador is based on Perl 5's Dancer which is based on Sinatra (Ruby). (bailador is spanish for dancer) Cro on the other hand was designed specifically around the features that are in Perl 6. This can make things more intuitive for someone proficient in Perl 6. It might also make it easier to

Re: Using HashBags

2018-04-08 Thread Brad Gilbert
You can do the following my %b is BagHash = … or my %b := bag … On Sun, Apr 8, 2018 at 10:54 AM, Vittore Scolari wrote: > I answer myself: with % you get an Hash > > On Sun, Apr 8, 2018 at 5:53 PM, Vittore Scolari > wrote: >> >>

Re: Could this be any more obscure?

2018-09-27 Thread Brad Gilbert
In Perl 6 most normal operators are subroutines: @a[1..3] :« [ ] »( @a,1..3 ) # same as above Since they are just subroutines they often just call something else. # an overly simplified version sub postcircumfix:« [ ] » ( @array, **@indicies ) { gather {

Re: slurp so many?

2018-10-07 Thread Brad Gilbert
I think the easiest way to get a 400 characters from a file is with .comb() on the file. 'example.txt'.IO.comb(400).head() On Sun, Oct 7, 2018 at 6:42 PM ToddAndMargo via perl6-users wrote: > > Hi All, > > I use `slurp` all the time, so of course, I can't > make heads or tails out of > >

Re: need --> help

2018-10-12 Thread Brad Gilbert
That would be `List` sub RtnOrd( Str $Char --> List ){ $Char, ord($Char) } say RtnOrd "A" # (A 65) On Fri, Oct 12, 2018 at 3:14 PM ToddAndMargo via perl6-users < perl6-users@perl.org> wrote: > >> On Fri, Oct 12, 2018 at 3:32 PM ToddAndMargo via perl6-users > >>

Re: Malformed UTF-8 ???

2018-10-13 Thread Brad Gilbert
Change the encoding to `utf8-c8` to let the invalid unicode through. or use binary methods. or make sure it isn't in some other encoding. On Sat, Oct 13, 2018 at 5:18 AM ToddAndMargo via perl6-users wrote: > > Hi All, > > if $StdOut { $ReturnStr = $$proc.out.slurp-rest; } > > gives me >

Re: what type $in,$out and $err is

2018-10-28 Thread Brad Gilbert
That is talking about the arguments for the method/subroutine call. The way you pass in $in as True, is to add `:in` run "cat", "-n", :in, :out; The `:in` and `:out` are exactly the same as `:in(True)` `:out(True)` run "cat", "-n", :in(True), :out(True); Which is also the same as `in

Re: Exception Handling, DivideByZero

2018-10-29 Thread Brad Gilbert
.WHAT gives you the actual type, whereas .^name gives you a string that is the name. In Perl6 types are things you can pass around; which is good because you can have more than one with the same name. sub bar (){ my class Foo { } } sub baz (){ my class Foo { } }

Re: <> thank you

2018-10-05 Thread Brad Gilbert
<> is part of the quoting sub-language It is short for q:w' a b c d ' which is short for q:words' a b c d ' Note that you can add spaces q :words ' a b c d ' Even this is short. I'm going to show you various ways of writing the exact same thing q :w(1) ' a b c d ' q

Re: bitwise or?

2018-10-05 Thread Brad Gilbert
Note that = is actually a meta operator that can take an infix operator as an argument So $a += 1 is really short for $a [+]= 1 On Fri, Oct 5, 2018 at 1:02 AM Todd Chester wrote: > > > > On 10/4/18 12:13 PM, Brandon Allbery wrote: > > It's fine syntactically, but I think has no

Re: eof ?

2018-10-09 Thread Brad Gilbert
On Tue, Oct 9, 2018 at 8:31 AM Curt Tilmes wrote: > > On Tue, Oct 9, 2018 at 9:27 AM Laurent Rosenfeld via perl6-users > wrote: >> >> This: >> my $f = $fh.lines; >> will slurp all the lines into $f (but you can still access the individual >> items with something like $f[4]). > > > Is that

Re: Use of the --output flag

2018-10-09 Thread Brad Gilbert
My guess is that this is a bug. You can work around it by adding my $*OUT = q[test].IO.open(:w); in front of the code. On Tue, Oct 9, 2018 at 8:18 AM Simon Proctor wrote: > > So... I'm working through some notes for a talk on Thursday and I am trying > to work out how the --output flag is

Re: eof ?

2018-10-09 Thread Brad Gilbert
That isn't the syntax for a loop local variable in Perl 6. You are trying to use the Perl 5 syntax, which is not going to work in Perl 6 This is the Perl 5 code you are trying to write while( my $f = readline $fh ){ say "$f\n"} Which actually would turn into the following by Perl 5

Re: A problem with native CArrays

2018-09-30 Thread Brad Gilbert
The [+] works because of an optimization. If you use the core :<+> it instead calls the .sum() method. Since CArray has a sum method, that gets called instead. On Sun, Sep 30, 2018 at 4:28 AM Fernando Santagata wrote: > > Hi, > > I was hunting for a bug in my code, this one: > > my @a :=

Re: Package Compile Question

2018-10-01 Thread Brad Gilbert
`Foo::Bar::<$quux>` is basically short for `::Foo::Bar::('$quux')` (except the former is looked up at compile time) So the way to do this is: my $bar = 'Bar'; ::Foo::( $bar ~ '::$quux' ) or ::Foo::($bar)::('$quux') Note that the leading `::` are necessary for dynamic lookups.

Re: routine declaration line question

2018-10-03 Thread Brad Gilbert
If a routine does not declare it's return type, absolutely anything can be returned. One reason may be that its return value isn't really useful. It could be that the writer didn't think to declare it. (or didn't want to) Another possibility is that the potential returned values are of many

Re: What is the syntax of a reference pointer in p6?

2018-10-07 Thread Brad Gilbert
Technically there is a way to reason about some Perl 6 features as pointers. It would probably complicate it to view it this way though. You can think about `is raw` as making it so that arguments are passed by as bare "pointers". sub foo ( $a is raw ) { $a = 42; } my $b =

Re: Grammar doesn't seem to match any token

2018-09-24 Thread Brad Gilbert
I recommend to default to using `token` rather than `rule` or `regex`. If you need backtracking, use `regex` If you have a lot of parts that match whitespace use `rule` (generally used for combining other tokens.) On Sun, Sep 23, 2018 at 7:13 PM Patrick R. Michaud wrote: > > I suspect the rule:

Re: Could this be any more obscure?

2018-09-26 Thread Brad Gilbert
`$limit` isn't an array index. It's an argument that is passed on to the Iterator that tells it to stop when it has produced that many values. (Also it returns a `Seq`, not a `Positional` [fixed]) You can think of it as the following: 'abc def'.words.head( $limit ); `words` does something

Re: More efficient of two coding styles?

2018-11-16 Thread Brad Gilbert
I don't know if either one has had any specific optimizations applied to it. I would go for the multi-dispatch form if there is no overlap of functionality. I think this would have a higher likelihood of getting the subroutine inlined, because the code will be smaller. If you really care that

Re: Bad syntax check

2019-01-02 Thread Brad Gilbert
You can only list one type as a return type. If there were a hypothetical Tuple type: sub AddThree( Int $a, Int $b, Int $c --> Tuple[Str, Int] { my Int $d = $a + $b + $c; return Tuple[Str,Int].new( "a+b+c=", $d ); } my Int $X = 0; my Int $Y = 0; my Str $Z;

Re: **@args question

2019-01-03 Thread Brad Gilbert
f I wanted to create my own print routine > > >> using **@args, how would I declare it? > > >> > > >> sub printx( **@args data ) {...} > > >> > > >> > > >> Many thanks, > > >> -T > > >

Re: **@args question

2019-01-02 Thread Brad Gilbert
The variable name in :(**@args) is @args, it could be any valid array identifier like @data sub printx( **@data ){…} Note that there are several forms for slurpy positional arguments. :( @a ) # not slurpy at all, takes one Positional argument and aliases it as @a. :( *@a ) #

Re: I need m/ help

2019-01-14 Thread Brad Gilbert
Nl is not “*non-arabic numbers*” and it is not “*numbers that have a value by themselves*”. While both seem like correct statements, they are the wrong way to think about the Nl category. If either were entirely correct then there wouldn't be a need for No (Number other). *Nl (Number letter)* is

Re: I need m/ help

2019-01-14 Thread Brad Gilbert
That is only because the special coding rules for Roman numerals weren't added. It still is a wrong way to think about Nl. On Mon, Jan 14, 2019 at 12:59 PM JJ Merelo wrote: > > > > El lun., 14 ene. 2019 a las 18:41, Brad Gilbert () > escribió: >> >> Nl

Re: say Cool-concat-junction question

2018-12-23 Thread Brad Gilbert
if you turn the 3 into a Junction it also starts to work any(3) ~ ('a'|'b') # any(3a, 3b) On Sun, Dec 23, 2018 at 2:22 AM JJ Merelo wrote: > > > > El dom., 23 dic. 2018 a las 7:39, Brad Gilbert () escribió: >> >> I turns out there is a candidate for >> >> Str:D

Re: say Cool-concat-junction question

2018-12-22 Thread Brad Gilbert
I turns out there is a candidate for Str:D, Junction:D but not for Any:D, Junction:D so it is going through one of the other :<~> candidates, specifically it looks like it could be *@args Which doesn't apparently work with Junctions. So yes it is a bug. On Sat, Dec 22, 2018 at 9:05 PM yary

Re: so as a method: Is this expected or a bug?

2018-12-21 Thread Brad Gilbert
You got the order of operations wrong. Method calls happen before prefix operators These are identical +@a.so +(@a.so) @a.so.Numeric @a.Bool.Numeric +?@a As are these +«@a».so +«(@a».so) @a».so».Numeric @a».Bool».Numeric +«?«@a Postfix operators also

Re: How to use sub/method 'dir'

2018-11-25 Thread Brad Gilbert
The reason `dir('a', test => { .IO.d })` doesn't work like you expect is that it is passed strings. > dir('a', test => {.say}); . c b .. ("a/.".IO "a/c".IO "a/b".IO "a/..".IO) So `.IO.d` is looking to see if the CWD directory had a directory of that name, not the `a`

Re: How to use sub/method 'dir'

2018-11-27 Thread Brad Gilbert
On Mon, Nov 26, 2018 at 6:26 PM Trey Harris wrote: > > > > On Mon, Nov 26, 2018 at 04:56 Fernando Santagata > wrote: >> >> On Sun, Nov 25, 2018 at 5:34 PM Brad Gilbert wrote: >>> >>> The reason `dir('a', test => { .IO.d })` doesn't work

Re: I need hash string help

2019-01-11 Thread Brad Gilbert
$a is short for $a{'a','b'} This also happens in string literals my $a = { a => 1, b => 2 }; say "$a"; # 1 2 say "$a{'a','b'}"; # 1 2 A simple way to stop this is to add a backslash my $a = 'b' say "$a\"; # b You can also call methods on variables in string literals, as

Re: I need m/ help

2019-01-13 Thread Brad Gilbert
<:Nl> matches a Number that is letter-like I mean obviously `Ⅿ` (ROMAN NUMERAL ONE THOUSAND) looks like a letter. There is also <:Nd> for Number digit, and <:No> for other Numbers If you want to find out the general category of a character you can call `.uniprop`. say "1".uniprop; # Nd #

Re: A comparison between P5 docs and p6 docs

2018-09-12 Thread Brad Gilbert
The signatures in the docs are often the exact same signatures as the code they are documenting. > Str.^lookup('contains').candidates.map: *.signature.say (Str:D: Cool:D $needle, *%_) (Str:D: Str:D $needle, *%_) (Str:D: Cool:D $needle, Cool:D $pos, *%_) (Str:D: Str:D $needle,

Re: .kv ?

2018-09-14 Thread Brad Gilbert
You can read https://en.wikipedia.org/wiki/Option_type for more information Tell me if you find any of the Perl 6 section confusing. https://en.wikipedia.org/wiki/Option_type#Perl_6 On Fri, Sep 14, 2018 at 6:21 AM Todd Chester wrote: > > >> On Fri, Sep 14, 2018 at 7:08 AM Todd Chester >>

Re: .new?

2018-09-14 Thread Brad Gilbert
On Fri, Sep 14, 2018 at 6:19 AM Todd Chester wrote: > > > > On 09/14/2018 03:34 AM, Simon Proctor wrote: > > I think the docs of objects (sorry on my phone no link) describe object > > creation and the default new quite well. > > They most probably are and most developers would have no issues >

Re: need p5/p6 :: help

2018-09-14 Thread Brad Gilbert
lexical means it is only available within that scope, or in sub-scopes { my $a; { $a = 42; } } $a # error { sub foo (){} # my sub foo (){} # identical { foo(); } } foo() # error --- Note that sub foo (){} is really short for my only sub

Re: Multibyte string in Windows command line

2018-09-15 Thread Brad Gilbert
ap(*.encode('latin1').decode('utf16')) -> $line >> >> { >> Why .encode? I would assume the IO::Handle is allready given back latin-1 >> because of the :enc<"latin-1"> in the Run command. >> >> On Thu, 13 Sep 2018 at 18:20, Brad Gilbert

Re: .kv ?

2018-09-15 Thread Brad Gilbert
On Fri, Sep 14, 2018 at 10:37 PM ToddAndMargo wrote: > > On 09/14/2018 08:09 PM, Brad Gilbert wrote: > > I think that it is because of how you read. > > > > The way your brain figures out what is written, is slow. > > That is how the human the human brain

Re: need p5/p6 :: help

2018-09-14 Thread Brad Gilbert
On Fri, Sep 14, 2018 at 7:10 PM ToddAndMargo wrote: > > On 09/14/2018 04:37 PM, Brandon Allbery wrote: > > > "{$x}::{$y}" > > Most of my programming before Perl 5 was bash. I > did a lot of "${x}abc" to keep the variables > from being confused with each other. > > I carried the practice over to

Re: tip: that annoying character at the end

2018-09-14 Thread Brad Gilbert
You can just remove the control characters my $x="abc.zip"~chr(7)~chr(138); $x .= subst(/<:Cc>+ $/,''); say $x; Note that 13 is carriage return and 10 is newline If the only ending values are (13,10), 13, or 10 you can use .chomp to remove them my $x="abc.zip"~chr(13)~chr(10);

Re: .kv ?

2018-09-14 Thread Brad Gilbert
On Fri, Sep 14, 2018 at 9:42 PM ToddAndMargo wrote: > > On 09/14/2018 07:16 PM, Brad Gilbert wrote: > > The author greatly appreciates the time spent on writing this critique. > > > > (I'm the author) > > > > Responses written inline > > > > On

Re: .kv ?

2018-09-14 Thread Brad Gilbert
The author greatly appreciates the time spent on writing this critique. (I'm the author) Responses written inline On Fri, Sep 14, 2018 at 4:55 PM ToddAndMargo wrote: > > On 09/14/2018 09:26 AM, Brad Gilbert wrote: > > You can read https://en.wikipedia.org/wiki/Option_type for more

Re: Can methods have multiple inputs?

2018-09-14 Thread Brad Gilbert
On Fri, Sep 14, 2018 at 6:03 PM ToddAndMargo wrote: > > >> On Fri, Sep 14, 2018 at 6:47 PM ToddAndMargo >> > wrote: > >> > >> Hi All, > >> > >> Can a method be given multiple inputs? > >> > >> ( $a, $b ).foo > >> > >> and how would the docs

Re: tip: that annoying character at the end

2018-09-14 Thread Brad Gilbert
.* /.zip/; > >> > >> $ p6 'my $x="abc.zip"~chr(7)~chr(138); $x~~s/ ".zip" .* /.zip/; say > >> "<$x>";' > >> > >> > >> Problem solved. And it doesn't care what the weird character(s) > >> at the end i

Re: tip: that annoying character at the end

2018-09-14 Thread Brad Gilbert
On Fri, Sep 14, 2018 at 10:11 PM ToddAndMargo wrote: > > On 09/14/2018 07:34 PM, Brad Gilbert wrote: > > $x ~~ s/ <:Cc>+ $ //; > > What exactly is <:Cc> again? < and > inside of a regular expression is for advanced features If the first character is :

Re: how do I do this index in p6?

2018-09-13 Thread Brad Gilbert
On Thu, Sep 13, 2018 at 11:52 PM Todd Chester wrote: > > >> Le jeu. 13 sept. 2018 à 23:12, ToddAndMargo >> > a écrit : > >> > > > >> $ p6 'constant c=299792458; say c ~" metres per second";' > >> 299792458 metres per second > >> > >> Hm. Now I am

Re: Please explain this to me

2018-09-16 Thread Brad Gilbert
I think I have an idea of where your thinking is going wrong. The trouble is going to be to describe it so that you can understand. First, I think you may be misunderstanding what we mean by defined and undefined. So I will use "instance" and "class" --- class Foo {}; say Foo; # <-

Re: Multibyte string in Windows command line

2018-09-13 Thread Brad Gilbert
On Thu, Sep 13, 2018 at 7:22 AM WFB wrote: > > Hi all, > > My perl6 runs an executable and prints its output. This output is printed as > multibyte string. I assume the executable gives back a multibyte string and > perl6 interpret its as one byte string for whatever reasons. > I tried Run with

Re: binary test and position?

2019-02-01 Thread Brad Gilbert
This would work: my $b = Buf.new( 0,0,0, 1, 2, 0 ); my $match = Buf.new( 1, 2 ); $b.rotor( $match.elems => 1 - $match.elems ).grep(* eqv $match.List, :k) If you only need the first one, swap out `grep` for `first` Another iffy option is to decode it as latin1

Re: binary test and position?

2019-02-01 Thread Brad Gilbert
`eq` is string equality `==` is numeric equality a Buf is neither. You want `eqv` (equivalent) $b[2..4] eqv (0x90,0x00,0x04) On Fri, Feb 1, 2019 at 9:37 PM ToddAndMargo via perl6-users wrote: > > On 2/1/19 7:22 PM, ToddAndMargo via perl6-users wrote: > > Hi All, > > > > On a type Buf,

Re: faster than index?

2019-02-02 Thread Brad Gilbert
`.index` is going to be the fastest because it is directly using NQP ops which are built into the VM. 'abcdefg'.index('de'); # 3 If you want all of the indexes, use `.indices` 'abcdefabc'.indices('abc'); # 0, 6 `.index` will return `Nil` if it doesn't find anything, and `.indices` will

Re: Start reading at a specific index?

2019-02-02 Thread Brad Gilbert
`$whence` means “whence” adverb 1. from what place or source. So it should be one of the values of the `SeekType` enum say SeekType.enums.keys # (SeekFromCurrent SeekFromBeginning SeekFromEnd) - `SeekFromCurrent` means it is relative to where it is currently (go

Re: binary test and position?

2019-02-02 Thread Brad Gilbert
} On Sat, Feb 2, 2019 at 10:05 PM ToddAndMargo via perl6-users wrote: > > On 2/2/19 6:09 AM, Brad Gilbert wrote: > > sub buf-index ( Buf $buf, +@match ) { > > my $elems = @match.elems; > > $buf.rotor( $elems => 1 - $elems ).first(* eqv @match.List,

Re: Fastest way to convert from a Buf to a Str?

2019-02-02 Thread Brad Gilbert
This: for ( @$BinaryFile ) -> $Char { $StrFile ~= chr($Char); } is better written as my $StrFile = $BinaryFile.map(*.chr).reduce(* ~ *); It is also exactly equivalent to just e # if $BinaryFile is a Buf my $StrFile = $BinaryFile.decode('latin1'); # if it isn't my

Re: binary test and position?

2019-02-02 Thread Brad Gilbert
gt;> Basically, what am I doing wrong here? > >>> >> > >>> >> $ p6 'my $handle=open("filever.exe", :bin, :ro); my Buf $b; $b= > >>> >> $handle.read(5); say $b; say $b[2..4];; if ( $b[2..4] eq > >>> 0x90,0x00,0x04 > &

Re: "index" source code?

2019-02-03 Thread Brad Gilbert
The Rakudo Perl6 compilier is written in Perl6 (and a subset of Perl6 named NQP) The `index` subroutines are at https://github.com/rakudo/rakudo/blob/64c88f919841c58f5a6dffd3581770e06a8fd6a5/src/core/Cool.pm6#L276-L282 proto sub index($, $, $?, *%) {*} multi sub index(Cool $s, Cool

Re: binary test and position?

2019-02-05 Thread Brad Gilbert
lly means they are stored as C arrays. On Tue, Feb 5, 2019 at 1:47 AM ToddAndMargo via perl6-users wrote: > > On 2/2/19 9:29 PM, Brad Gilbert wrote: > > Subs do not need to have a `return` statement if it is returning the last > > value. > > > > You also broke the retu

Re: split and nils?

2019-02-07 Thread Brad Gilbert
ot;>";}' > >> > >> Use of Nil in string context > >> in block at -e line 1 > >> Index <0> = <> = ord <> <- nil ??? > >> Index <1> = = ord <97> > >> Index <2> = = ord <98> &

Re: split and nils?

2019-02-06 Thread Brad Gilbert
The reason there is a Nil, is you asked for the ord of an empty string. "".ord =:= Nil The reason there are two empty strings is you asked for them. When you split with "", it will split on every character boundary, which includes before the first character, and after the last. That's

Re: shift left syntax?

2019-02-08 Thread Brad Gilbert
The `=` infix operator is a meta operator. That means it takes an infix operator as a sort of "argument". There is no `+=` operator, it is just the `=` operator combined with the `+` operator. $a += 2; $a [+]= 2; # more explicitly take the + operator as an argument to the = operator So

Re: buf to integer?

2019-02-08 Thread Brad Gilbert
If you have a new enough version of Rakudo: my Buf $x=Buf.new(0xAE,0x5D,0x5C,0x72); my int32 $i = $x.read-int32(0,LittleEndian); say $i.base(16); # 725C5DAE On Fri, Feb 8, 2019 at 12:35 AM Todd Chester via perl6-users wrote: > > Hi All, > > I am dealing with a Buf what

Re: Typed Arrays and for-loops

2019-02-13 Thread Brad Gilbert
The problem with `$files` is the `$` When a `for` loop sees something that is itemized / containerized (`$`) it treats it as a singular value. my @a = 1,2,3; my $a = @a; for @a { .say } # 1 # 2 # 3 for $a { .say } # [1 2 3] for @a.item { .say } # [1 2

Re: list comprehension

2019-02-11 Thread Brad Gilbert
Set.new: (K X[,] X).grep: -> ( \k, \x ) { x < 8 }; > my $s3 = Set.new: ( -> \x { |(-> \k { (k,x) if x < 8 } for K) } for X ); > my $s4 = Set.new: gather { -> \k { -> \x { take (k,x) if x < 8; } for X } for > K } > my $s5 = Set.new: cross( K, X.grep: * < 8 ); &g

Re: list comprehension

2019-02-10 Thread Brad Gilbert
In {l for l in L} The reason it is in `{}` is to create a Set from iterating over `L`. > In Python, the set-builder's braces are replaced with square brackets, > parentheses, or curly braces, giving list, generator, and set objects, > respectively. So in Python: [ l for l in L ]

Re: buf to integer?

2019-02-08 Thread Brad Gilbert
The next release of Rakudo with have read-int32. To use it now you would need to build from the git repository, I think. On Fri, Feb 8, 2019 at 7:56 PM yary wrote: > > the perl6-native "read-int32" or native-but-experimental "unpack" are the > natural answers- they map well from problem to

Re: valid values?

2019-03-03 Thread Brad Gilbert
The `where` clause is already a smart-match, adding `~~` to it is not only redundant, it can cause confusing action at a distance. (By that I mean the right side of `where` is exactly the same as the right side of `~~`) You wouldn't write this: * ~~ (* ~~ 1|2|4|8|16) So don't write this

Re: valid values?

2019-03-04 Thread Brad Gilbert
ub test1 at line 1 > in block at line 1 > > > sub test2(:@array? where .all ~~ Str) { say 'ok' } > > > test2() > ok > > The where clause in test1() doesn't work, but is the clause in test2() > dangerous (action at a distance)? Should I rephrase it differently? >