Re: Fw: Issue #1 of the Science Perl Journal now on sale at Barnes & Noble

2024-10-16 Thread Todd Chester via perl6-users

Perl 5?


Re: Is irc.libera.chat down?

2024-04-19 Thread Todd Chester via perl6-users




On 4/19/24 03:09, Todd Chester via perl6-users wrote:

A sex, 19-04-2024 às 02:36 -0700, Todd Chester via perl6-users
escreveu:

Hi All,

Is
 https://kiwiirc.com/nextclient/irc.libera.chat/#raku
down?

-T




On 4/19/24 03:03, David Santiago wrote:
 >
 > It works for me.
 >
 > Regards,
 > David
 >

Hi David,

The circle just goes round and round and after
a while, it times out.

I tried both Firefox and Brave Browser.

I wonder if I got "quieted" or banned.   Is there
a way to tell?

-T


I changed my username and got immediately in.
Wonder what it does not like about my user name?



Re: Is irc.libera.chat down?

2024-04-19 Thread Todd Chester via perl6-users

A sex, 19-04-2024 às 02:36 -0700, Todd Chester via perl6-users
escreveu:

Hi All,

Is
     https://kiwiirc.com/nextclient/irc.libera.chat/#raku
down?

-T




On 4/19/24 03:03, David Santiago wrote:
>
> It works for me.
>
> Regards,
> David
>

Hi David,

The circle just goes round and round and after
a while, it times out.

I tried both Firefox and Brave Browser.

I wonder if I got "quieted" or banned.   Is there
a way to tell?

-T


Is irc.libera.chat down?

2024-04-19 Thread Todd Chester via perl6-users

Hi All,

Is
   https://kiwiirc.com/nextclient/irc.libera.chat/#raku
down?

-T


Re: need native call help

2024-04-19 Thread Todd Chester via perl6-users




On 4/18/24 04:50, yary wrote:
I did a lot of very deep windows programming in my previous job and 
reminding me that I would always use the 8.3 short name for file 
operations! dir /x will get it for you. Must be API called for it also. 
Probably only works on local volumes not network rounded ones. Just a guess.


AreShortNamesEnabled function (fileapi.h)
https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-areshortnamesenabled

and

GetShortPathNameW function (fileapi.h)
https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-getshortpathnamew

The silly "W" at the above means you have to convert your
string to UTF16.  If yo have a "A" at the end, you can
just use UTF8.  I have modules for to convert both the them.



I've run into problems on some unix shells with maximum command-line 
lengths.


-y



Hi Yary,

The 64 thousand dollar questions is should
the programming language make allowances for
the "quirks" of an operating system, such as the
260 file limit DeleteFileA, and just presume the
user of the programming language has no business
programming for the particular operating system
if he does not already know the quirks or should
the programming language make allowances?

As for me, when I throw unlink at a file, I expect it
to work or at least be told why not.  So, I think
allowances show be made.

In my DeleteFileA module, I obviously wanted it
to just work, quirks or no quirks, so I could just
go about deleting what I want without having
to be a genius at the operating system and
wasting hours troubleshooting things that don't work
as expected.

In an "ideal world", I never have to goof around
with API calls, unless I was shooting
for something really weird.

Your take?
-T


Re: Practical Raku projects

2020-12-24 Thread Todd Chester via perl6-users




On 12/24/20 12:23 AM, JJ Merelo wrote:

Hi,

El jue, 24 dic 2020 a las 3:55, Matthias Peng (>) escribió:


May I ask if there is any practical perl6 project running? For
example, homebrew by ruby, k8s by go, flask by python etc.


I doubt there's any perl6 practical project _now_. There are a few 
practical Raku projects, however, and they are big. For instance, Cro is 
much better than Flask will ever be: its way of handling routes, 
templates, and the fact that it's concurrent, puts it in another level. 
There's no docker or k8s... yet. But just you wait..


Hi JJ,

Any sign of a toolkit to develop window interfaces?  A simple
text processor would be a cool example.

-T



Re: I need help understanding ".contains" method construction

2020-12-23 Thread Todd Chester via perl6-users



On 12/23/20 4:39 PM, Ralph Mellor wrote:

1) why is it "$needle" and not "$!needle" on line 338?
Is this because it is an internal variable and not
a variable from the class declaration?


Got it



It's a parameter from line 337. If that's what you mean by
"an internal variable", then yes. :)


Apparently some other programming language do not give your
the option of internal variables in side class declarations:
everything is visable




2) where is variable ".value" defined on line 338?
What kind of variable is .value?


I don't see a `.value`, only a `$!value`. But if I did, and had that
sort of name, it would typically be a method call that returns an
attribute of the same name -- like `$!value`.


Is this .self with a better name?




3) the first "Str:D" goes to what on line 337?  To .value?


No, to the invocant.


Would you define "invocant" so I stop guessing?




4) Is .value the default, if there is no name given?


I don't see a `.value`, nor what you mean by "name".


Re: Is the cosine page wrong?

2020-12-23 Thread Todd Chester via perl6-users







Going back to the original question,

should not the doc page say?

  method cos( Cool:D: --> Cool:D )



On 12/23/20 4:28 PM, Ralph Mellor wrote:
> If a method does not explicitly specify its invocant type, it is set
> to the type of the enclosing class.

But it does not specify an invocant.  It just leaves it blank
>
> The `cos` method is declared in the `Cool` class, so that is its
> invocant type.
>
> The doc shows that it's declared in the `Cool` class.
>
> So, the doc is fine as is for the invocant.

I was not asking if you could pick it up by context with
other things written on the page.  I was specifically asking
about the definition line.

Once you learn to read them, the definition lines can be really
useful.  My problem is that they are often incorrect, which
put a hammer into learning them.

> The returned value is a cosine, which, per the linked doc,
> is a real number. The doc could perhaps show a return value
> of Real:D.

I like it!

This look right to me (but keep in mind I don't know what I am doing)
method cos( Cool:D: --> Real:D )

These two look wrong to me:
method cos()
method cos( --> Cool:D )  or --> Real:D

Thank you for the wonderful explanation.

-T


Re: New Raku 2020.10.02

2020-10-29 Thread Todd Chester via perl6-users




On 10/29/20 2:58 PM, Bruce Gray wrote:

I don't know if you are*supposed*  to have to do all this to "know what 
changed" (since I do not use those packages myself); I am just trying to answer the 
implied question.


I wrote a program that checks about 70 programs I support and
downloads new revisions.   It does not download release notes,
so I say I don't know what changed.

I was not asking for help.  Just informing.


Re: Is thre a way to do an "if" on "use lib"?

2020-06-12 Thread Todd Chester via perl6-users




On 2020-06-07 18:49, ToddAndMargo via perl6-users wrote:

~
#!/usr/bin/env raku

# Note: this has to be the first thing at the top

my @LibPath;

BEGIN {
    for ('K:/Windows/NtUtil', 'X:/NtUtil') -> $candidate {
  push @LibPath, $candidate if $candidate.IO.d;
   }
    push @LibPath, 'C:/NtUtil';
    push @LibPath, '.';
}


use lib @LibPath;

dd @LibPath;
dd $*REPO.repo-chain.lines;
~~

raku use.lib.test.pl6

Array @LibPath = ["K:/Windows/NtUtil", "C:/NtUtil", "."]

("K:\\Windows\\NtUtil C:\\NtUtil C:\\Users\\todd\\.raku 
C:\\rakudo\\share\\perl6\\site C:\\rakudo\\share\\perl6\\vendor 
C:\\rakudo\\share\\perl6\\core 
CompUnit::Repository::AbsolutePath<131860432> 
CompUnit::Repository::NQP<124427016> 
CompUnit::Repository::Perl5<124427056>",).Seq



AH 

The above worked fine on my W10 virtual machine
when called from Cobian, but on a customer's (native)
Windows 10, I had to go back to using to comment out
method.


Re: I reproduced one of the errors!

2020-06-05 Thread Todd Chester via perl6-users




On 2020-06-04 00:08, Peter Pentchev wrote:

On Wed, Jun 03, 2020 at 07:00:53PM -0700, ToddAndMargo via perl6-users wrote:

On 2020-06-03 02:21, Peter Pentchev wrote:

On Wed, Jun 03, 2020 at 01:06:33AM -0700, ToddAndMargo via perl6-users wrote:

On 2020-06-02 22:15, Peter Pentchev wrote:

On Tue, Jun 02, 2020 at 07:39:16PM -0700, ToddAndMargo via perl6-users wrote:

On 2020-06-01 23:02, Peter Pentchev wrote:

https://docs.raku.org/language/classtut


Error 522 Ray ID: 59d609616954eb79 • 2020-06-03 02:38:12 UTC
Connection timed out

Poop!


This is usually some kind of temporary error - something broke down
between your computer and the server. Try again later, it might work.
(it's the Raku docs site, you've used it before, you know it usually
works :)

G'luck,
Peter



Hi Peter,

It is working now.  Thank you.

You would happen to know of a tutorial.  Me and
the documents ... well, lets say they are not
written with the same outcome in mind as perldocs.

Is there a way to write a methods as I would write
a sub and avoiding the class thing?


OK, now I really have to ask, just like other people have.

What exactly do you mean by "method"?

G'luck,
Peter




say "AbCd".lc

abcd

lc would be the method:
multi method lc(Str:D: --> Str:D)


Right. So apart from the & trick that Fernando Santagata showed you (but
see below, it's not really calling a method) and that is neat but has
its drawbacks (like for instance you cannot ask an object if it .can()
do a specific method), you want to call a method on an object.

In general, and the point of this subthread is, methods are not
standalone subroutines; they are defined as part of the whole "variables
have types, those types are called classes, each class defines
the methods that you may call on its variables" object-oriented
programming thing. When you say "method", this is what people think
you're talking about, because, well, this is what "method" kind of means
when one uses it in a conversation about computer programming,
especially when talking about a language with a class-, role-, and
inheritance-based type system.

The trick that Fernando showed you is not really calling a method;
it is a cute way of the Raku syntax to specify the first argument when
calling a subroutine. The subroutine is not a method, it does not show
up in .can() or .^methods or .HOW or any of the way to ask a variable
what methods it supports. Yes, it is possible to define a multi sub that
does different things when called on different types of first argument,
but it is still not a method, it is a subroutine.

A method is something that is tied to a class. For a quick overview of
classes, methods, and the main ideas of object-oriented programming, try
https://www.freecodecamp.org/news/object-oriented-programming-concepts-21bb035f7260/
Also, take another look at https://docs.raku.org/language/classtut -
especially the part "Starting with a class" and onwards.

G'luck,
Peter




Thank you.  I gots some reading in my future


Re: fill in form

2020-05-13 Thread Todd Chester via perl6-users

> On 12/05/2020 20:44, ToddAndMargo via perl6-users wrote:
>>> On 12/05/2020 00:47, ToddAndMargo via perl6-users wrote:
 Hi All,

 I want to create a fill in form in Windows: city,
 state, etc., you fill in the data.

 Is there some library out there for that?

 Any words of wisdom?

 Many thanks,
 -T
>>
>>
>> On 2020-05-12 08:18, Timo Paulssen wrote:
>>> Hi Todd,
>>>
>>> normally I'd expect you want to create a grid with labels on the left
>>> and text inputs on the right.
>>>
>>> the examples/ folder in the GTK::Simple distribution (or the source on
>>> github) has an example of the Grid class, which is very powerful.
>>>
>>> The grid is possibly more complicated than you need it to be; instead
>>> you can probably have one VBox that contains one HBox for every label +
>>> input field.
>>>
>>> One benefit that the Grid will give you is that you can much more 
easily

>>> line up all the fill-in text inputs, whereas with a VBox of HBoxes it
>>> may just make every text input as wide as possible so it (almost)
>>> touches the end of the label, so different words ("city" vs "first
>>> name") could result in different-sized text inputs.
>>>
>>> hope that helps
>>> - Timo
>>>
>>
>>
>> Hi Timo,
>>
>> You mean this one?
>>
>> 
https://github.com/raku-community-modules/gtk-simple/blob/master/examples/03-grid.pl6

>>
>>
>> https://ibb.co/hgKHgW4
>>
>> I do not see the utility of what I am after.
>>
>> :'(
>>
>> -T

On 2020-05-13 05:26, Timo Paulssen wrote:

Is this not anything like what you're after?

https://external-content.duckduckgo.com/iu/?u=https%3A%2F%2Fwww.w3.org%2FTR%2F2016%2FCR-css-grid-1-20160929%2Fimages%2Fauto-placed-form.png&f=1&nofb=1

Kind Regards
   - Timo



Yes!


Re: tip: Windows, Git, and those nice Linux utilities

2020-04-11 Thread Todd Chester via perl6-users

On 10/04/2020 01:37, ToddAndMargo via perl6-users wrote:

On 2020-04-09 09:39, Richard Hainsworth wrote:

Am I missing something here?

It would seem obvious to me that Git and Raku are not linked in any 
way, except of course for developers who only use Git with Raku, or 
who only have a dependency on Git through zef.


It would therefore seem to me that a Raku / Zef distribution should 
NOT bundle Git. Consequently, 'Git' is not "forgotten" and that is 
*should* be installed independently.


Git is required for Zef to operate.  So Git is a dependency
of Zef.  Therefor Zef should either include Git or warn
the user that he needs to download it himself


On 2020-04-10 15:44, Richard Hainsworth wrote:
> Whether or not git is "required" (for some definition of required) for
> zef is somewhat irrelevant.
>
> A computer is required for zef, so is an operating system. Not
> everything can be included in a distribution.
>
> The real question is therefore which things (modules/tools/etc) should
> be included in a distribution that someone in the target audience may
> not have, and which may it be assumed that someone in the target
> audience will already have or can find. It seems fairly obvious to me
> that git is something a developer should have or can easily obtain.
>
> But that is a matter of judgement. Leaving git out is not 'a mistake',
> not was it 'forgotten'. It was a judgement.
>
> It is also a matter of judgement as to whom the target audience is. But
> that is entirely another topic.
>

Hi Richard,

Interesting take on the issue.  I doubt it was
"judgement" as they had no idea the issue existed
until I raised the issue.  Programmers commonly
already have Git installed.  (End users do not.)

And speaking of "judgement", I would posit that
it is "good judgement" to either include or warm
the user when a companion piece of software is
required for your software to operate properly.

The installer is a great place to do such.
Fedora's SRPM spec files are a wonder example
of this.  Windows severely lags behind on this.

I would also posit that "you should be smart
enough to go figure it out yourself" method
would fall in the "bad judgement" category.

I did figure it out, so I guess I fall in the
smart enough category.  I should have not
had to, which I why the bug report.  Others
should not have to repeat my troubleshooting
over and over.

Anyway, you have an interesting take on the matter.
Thank you for sharing.

-T


Re: irrational nubmer?

2020-03-11 Thread Todd Chester via perl6-users




On 2020-03-11 01:23, Todd Chester via perl6-users wrote:



On 2020-03-10 22:55, Shlomi Fish wrote:

Speaking of trivia, and off topic, did you know that
√2 caused a major religious upheaval when the result
of a 1,1,√2 triangle came out?  The poor Pythagoreans:
all numbers had to be rational.  Hippasus even
got murdered for blowing the whistle on √2.

Seehttps://en.wikipedia.org/wiki/Hippasus  for what we more accurately 
know

about that.


Hi Shlomi,

That is a trip down memory lane!

More years ago that I like to admit, wrote a college
paper on the Pythagoreans.  The only real thing I
really remember about it is the "Harmony of the Spheres"
(Musica universalis).

https://en.wikipedia.org/wiki/Musica_universalis

I don't know how I ever got a A on the paper.  The
stuff on Wikipedia is 20 times better than anything
I wrote.

Thank you for sharing!

-T



Who would have thought √2 would have caused so much consternation?

In my days as a Radio Frequency designer, √2÷2 was a big deal.
Fortunately, no one got tossed overboard for using it!


Re: irrational nubmer?

2020-03-11 Thread Todd Chester via perl6-users




On 2020-03-10 22:55, Shlomi Fish wrote:

Speaking of trivia, and off topic, did you know that
√2 caused a major religious upheaval when the result
of a 1,1,√2 triangle came out?  The poor Pythagoreans:
all numbers had to be rational.  Hippasus even
got murdered for blowing the whistle on √2.


Seehttps://en.wikipedia.org/wiki/Hippasus  for what we more accurately know
about that.


Hi Shlomi,

That is a trip down memory lane!

More years ago that I like to admit, wrote a college
paper on the Pythagoreans.  The only real thing I
really remember about it is the "Harmony of the Spheres"
(Musica universalis).

https://en.wikipedia.org/wiki/Musica_universalis

I don't know how I ever got a A on the paper.  The
stuff on Wikipedia is 20 times better than anything
I wrote.

Thank you for sharing!

-T


Re: qqx with quotes

2020-02-28 Thread Todd Chester via perl6-users




On 2020-02-27 15:38, Andy Bach wrote:

Win10 with a new raku install.


would you do a
   perl6 -v
for me?


Re: irrational nubmer?

2020-02-26 Thread Todd Chester via perl6-users




On 2020-02-20 22:32, Tobias Boege wrote:

On Thu, 20 Feb 2020, ToddAndMargo via perl6-users wrote:

On Fri, 21 Feb 2020 at 13:31, ToddAndMargo via perl6-users
mailto:perl6-users@perl.org>> wrote:

 $ perl6 -e 'say sqrt(2).base-repeating();'
 No such method 'base-repeating' for invocant of type 'Num'
 in block  at -e line 1



On 2020-02-20 19:07, Norman Gaywood wrote:


perl6 -e 'say sqrt(2).Rat.base-repeating();'
(1.4 
14213197969543147208121827411167512690355329949238578680203045685279187817258883248730964467005076)


Hi Norman,

Much better!

Question: Rat:
https://docs.raku.org/type/Rat

   Rat objects store rational numbers as a pair
   of a numerator and denominator. Number literals
   with a dot but without exponent produce Rats.

What does Rat do to sqrt(2) to give it a numerator
and a denominator?



I'm not sure if you have digested what others have said, so I'll repeat it:
sqrt(2) already has a numerator and denominator. sqrt(2) takes the integer
2 and computes its square root as a floating point number using magic IEEE
powder. If you look up the IEEE 754 float representations, you'll notice
that every (non-NaN, non-Inf) float is a rational number. So sqrt(2) is
already a rational number approximating the positive real number whose
square is 2.

That said, just taking the obvious numerator and denominator from the float
might give you unnecessarily large numbers, and the Rat conversion on Num
has to support a user-supplied tolerance as well. Reading the documentation,
it seems that Raku does not require IEEE 754 to be in effect at all.

So what Rakudo does (I recommend reading the source code [1]) is a variant
of finding a continued fraction for the Num [2], except that it computes
the Rat instead and stops when it reached the requested accuracy. It starts
from scratch and iteratively approximates the Num, which has the advantage
that you can stop when you don't have to continue and that it only relies
on arithmetic on the Num working, not that it is represented according to
some standard internally.

Note also that Num.Rat supports a :fat argument to give you a FatRat back,
but you cannot actually increase the precision of your rational approximation
of √2 beyond the source you put in, which is a double precision float:

   > sqrt(2).Rat.nude # precision 1e-6, the default
   (1393 985)
   > sqrt(2).Rat(1e-8).nude   # a bit better requested, request granted
   (19601 13860)
   > sqrt(2).Rat(1e-16).nude  # still better but 1e-16 is ca. the limit
   (131836323 93222358)

   > sqrt(2).Rat(1e-20).nude  # no improvement
   (131836323 93222358)
   > sqrt(2).Rat(1e-100, :fat).nude  # fatter but not better, because
   (131836323 93222358)  # the source sqrt(2) is too lossy

Regards,
Tobias

[1] https://github.com/rakudo/rakudo/blob/cdbd60c1/src/core.c/Num.pm6#L46
[2] 
https://en.wikipedia.org/wiki/Continued_fraction#Calculating_continued_fraction_representations



Hi Tobias,

I am confused as to as to what you mean by numerator and
denominator.

When I say:
$ p6 'say (99/70).base-repeating();'
(1.4 142857)

$ p6 'say (665857/470832).base-repeating();'
(1.4142 
135623746899106262955788901349101165596221157440445849050192000543718353892683589900431576443402317599483467563801950589594590002378767798280490705814388146939885139497740170591633533829476331260407109117477146837937948142861997485302613246338396710503958949264281102388962517415978523125021238998198932952730485608454820403031229822951711013694906038671967920617120331668195874536989839263261630475413735684915213919189859652699901451048356951099330546776769633329935093621504060896455635980562068848336561661059571142148367145818466034594080266421993407414959051211472457267)


$ p6 'say sqrt(2).Rat.base-repeating();'
(1.4 
14213197969543147208121827411167512690355329949238578680203045685279187817258883248730964467005076)


How does Raku know √2 is approximated by 99/70 or 665857/470832?
Does not Raku just throw a binary algorithm at any number you
feed sqrt?

also, what exactly am I look at with (1.4 142857)?   Is
this a way of saying that 1.4 is the rational part and
142857 the irrational part?

What is also confusing is when a number does not repeat,
what is .base-repeating() trying to tell me?  Is does not repeat?

2/3 is 0.666.
$ p6 'say (2/3).Rat.base-repeating();'
(0. 6)

Does that mean that the 6 repeats?

and

$ p6 'say (99/70).base-repeating();'
(1.4 142857)

means that 142857 also repeats (it does not), but
that it is best it can figure out with the precision
it has?

And it it can not find a repeat, why does it not say so?

And why am I getting zero back from
$ p6 'say sqrt(2).Rat.base-repeating() - (665857/470832).base-repeating();'
0

Also, what is the algebraic precedence of the operation?  In
(665857/470832).base-repeating()

is (665857/470832) solved first or is (665857/470832) a special
number (Rat) that is fed to .base-repeating?

And what are the unboxing rules for (665857

Re: irrational nubmer?

2020-02-26 Thread Todd Chester via perl6-users




On 2020-02-23 03:07, Shlomi Fish wrote:

Hi,

just for the record - I was not talking about Raku, just about a hypothetical
language with CAS-like capabilities (see
https://en.wikipedia.org/wiki/Computer_algebra_system  ) that would be able to
do it. I was just using Raku-like syntax for familiarity. I am aware that the
functionality is not built in in Raku.


Interesting!


Re: REPL and arrows problem

2020-01-22 Thread Todd Chester via perl6-users




On 2020-01-21 21:44, Norman Gaywood wrote:
On Wed, 22 Jan 2020 at 13:30, Todd Chester via perl6-users 
mailto:perl6-users@perl.org>> wrote:


On 2020-01-21 16:38, Todd Chester via perl6-users wrote:
 > Fedora31

I have Fedora 31 and Readline does not seem to be working for me in the 
raku REPL as well.

But see below!


$ rpm -qa \*raku\*
xfce4-terminal-0.8.9.1-1.fc31.x86_64


Hmm, I don't think that is output from that command. Mine:
  $ rpm -qa \*raku\*
rakudo-XML-0.0.3-0.6.20190728git417f637.fc31.x86_64
rakudo-MIME-Base64-1.2.1-6.fc31.x86_64
rakudo-zef-0.8.2-1.fc31.x86_64
rakudo-0.2019.11-3.fc31.x86_64
rakudo-Readline-0.1.5-2.fc31.x86_64
rakudo-URI-0.2.2-1.fc31.x86_64

$ raku -v
This is Rakudo version 2019.07.1 built on MoarVM version 2019.07.1
implementing Perl 6.d.


Looks like you might have your own rakudo installed not from the default 
system packages. Mine:

$ which raku
/usr/bin/raku
$ raku -v
This is Rakudo version 2019.11 built on MoarVM version 2019.11
implementing Perl 6.d.

In any case, I also have the problem with raku REPL not using Readline 
despite rakudo-Readline-0.1.5-2 being installed.

$ raku
You may want to `zef install Readline` or `zef install Linenoise` or use 
rlwrap for a line editor


To exit type 'exit' or '^D'
 > my $history^[[A^[[A

This seems like a Fedora 31 packaging problem to me.

However, after this:
$ zef install Readline

The arrow keys once again work for me.

--
Norman Gaywood, Computer Systems Officer
School of Science and Technology
University of New England
Armidale NSW 2351, Australia

ngayw...@une.edu.au <mailto:ngayw...@une.edu.au> 
http://turing.une.edu.au/~ngaywood

Phone: +61 (0)2 6773 2412  Mobile: +61 (0)4 7862 0062

Please avoid sending me Word or Power Point attachments.
See http://www.gnu.org/philosophy/no-word-attachments.html


Hi Norman,

Readline was it.  Joy!  Thank you!

-T


Re: I need syntax to sub declare return a hash and an array

2020-01-21 Thread Todd Chester via perl6-users




On 2020-01-21 18:57, Tom Browder wrote:
On Tue, Jan 21, 2020 at 18:34 Todd Chester via perl6-users 
mailto:perl6-users@perl.org>> wrote:


On 2020-01-21 16:09, Todd Chester via perl6-users wrote:
 >> 4) A block (that is the { ... } bit) will always 'return' the last
 >> expression evaluated.
 >
 > Seems to me I have see the last expression returned even without
 > the {...}.  Maybe I am misremembering.


Todd, the {} is the block defining the subroutine.

  > sub AplusB( $a, $b --> Int ){$a+$b;}


The above is the sub's definition.



&AplusB


The above should generate an error because the mandatory args are 
missing, depending on the context (don't quote me on that).


&AplusB is printer out by REPL.  I don't know why.  REPL
does that a lot.



  > AplusB 2, 3
5

The above shows the sub being called with the required two args, and the 
5 is the returned value which is probably shown in the REPL since there 
is no semicolon after the call and the 5 is not usually seen otherwise.


$ p6 'sub AplusB( $a, $b --> Int ){$a+$b}; say AplusB 2, 3;'
5



-Tom


Hi Tom,

I was trying to cut things down to the simplest terms.
I was responding to Richard's statement

 >> 4) A block (that is the { ... } bit) will always 'return' the last
 >>expression evaluated.

I created a sub without the "{...}" and showed where it would
return the last equation without the "{...}".  I may have
misunderstood Richard.

-T


Re: Using raku/perl6 as unix "cat"....

2020-01-21 Thread Todd Chester via perl6-users




On 2020-01-21 11:08, William Michels via perl6-users wrote:

Good answers, all. Thanks to everyone for contributing.
For anyone who wants a golfed "cat" replacement, command line
arguments can give you shorter code:


Hi William,

I don't know if I contributed anything at all,
but you are most welcome.

Now for your next homework assignment, write
a "less" substitute in Raku!  You have to read the
keyboard, do a forwards and backwards, and a
search.

man less
DESCRIPTION
Less is a program similar to more (1), but which allows
backward  movement in the file as well as forward movement.
Also, less does not have to read the entire input file
before  starting,  so  with  large  input files  it
starts  up  faster than text editors like vi (1).  Less
uses termcap (or terminfo on some systems), so it can run
on  a  variety  of terminals.   There is even limited
support for hardcopy terminals.  (On a hardcopy terminal,
lines which should be printed at the  top  of  the screen
are prefixed with a caret.)

Commands  are based on both more and vi.  Commands may
be preceded by a decimal number, called N in the
descriptions below.  The number is used by some commands,
as indicated.


Like "cat" on steroids!  Probably more fun than writing
Winn API calls!

:-)

-T


Re: REPL and arrows problem

2020-01-21 Thread Todd Chester via perl6-users




On 2020-01-21 16:38, Todd Chester via perl6-users wrote:

Fedora31
Xfce 4.14
xfce4-terminal-0.8.9.1-1.fc31.x86_64


$ rpm -qa \*raku\*
xfce4-terminal-0.8.9.1-1.fc31.x86_64

$ raku -v
This is Rakudo version 2019.07.1 built on MoarVM version 2019.07.1
implementing Perl 6.d.


REPL and arrows problem

2020-01-21 Thread Todd Chester via perl6-users

Hi All,

Fedora31
Xfce 4.14
xfce4-terminal-0.8.9.1-1.fc31.x86_64

I have the same setup on both computers.  On
my shop computer, in REPL, the arrow keys
do not read correctly:

> a todd special booboo^[[D^[[D^[[D^[[D^[[D

How do I get my arrow back in REPL on mu
shop computer?

Many thanks,
-T


Re: I need syntax to sub declare return a hash and an array

2020-01-21 Thread Todd Chester via perl6-users




On 2020-01-21 16:09, Todd Chester via perl6-users wrote:
4) A block (that is the { ... } bit) will always 'return' the last 
expression evaluated. 


Seems to me I have see the last expression returned even without
the {...}.  Maybe I am misremembering.


> sub AplusB( $a, $b --> Int ){$a+$b;}
&AplusB

> AplusB 2, 3
5


how do you --> two variables?

2020-01-21 Thread Todd Chester via perl6-users

Hi All,

What is the syntax for returning two variable from a sub?

> sub x(--> Int, UInt) { return(-2,4) };

===SORRY!=== Error while compiling:
Malformed return value (return constraints only allowed at the end of 
the signature)

--> sub x(--> Int⏏, UInt) { return(-2,4) };

Many thanks,
-T


Re: I need syntax to sub declare return a hash and an array

2020-01-21 Thread Todd Chester via perl6-users




On 2020-01-21 14:03, Elizabeth Mattijsen wrote:

On 21 Jan 2020, at 22:37, Richard Hainsworth  wrote:
2) 'returns' in the declaration (not the part in the block) used to be used, 
but for some arcane reason that I never really understood, it is deprecated.


Not sure it is *the* reason, but the return type is part of the signature of a block.  A 
signature of a block is expressed as ":()", not allowing anything outside of 
the parentheses.

 sub a() returns Int { };
 dd &a.signature; # :( --> Int)



Not sure what you just said.


Re: I need syntax to sub declare return a hash and an array

2020-01-21 Thread Todd Chester via perl6-users

> On 21/01/2020 04:09, ToddAndMargo via perl6-users wrote:
>> On 2020-01-20 19:55, ToddAndMargo via perl6-users wrote:
>>> Hi All,
>>>
>>> What is the proper way to state that I am returning a
>>> hash from a sub?   `sub x() returns % {}`
>>>
>>> And an array?  `sub x() returns @ {}`
>>>
>>> Many thanks,
>>> -T
>>
>>
>> I think this is it:
>>
>> > sub x() returns Associative { my %h= A=>"a"; return %h}
>> &x
>> > x
>> {A => a}
>>
>>
>> > sub y() returns Array { my @a=(1,2,3,2,1) ; return @a}
>> &y
>> > y
>> [1 2 3 2 1]
>>
>>
>> Am I too high up the food chain with Associative and Array?
>>
>> -T

On 2020-01-21 13:37, Richard Hainsworth wrote:

sub x( --> Hash) { my %h = A => 'a' }

1) '-->' in the signature is the best way to provide information to the 
compiler about what the subroutine should return


2) 'returns' in the declaration (not the part in the block) used to be 
used, but for some arcane reason that I never really understood, it is 
deprecated.


3) 'Hash' or 'Associative'. These all refer to roles that a hash will 'do'.

4) A block (that is the { ... } bit) will always 'return' the last 
expression evaluated. 


Seems to me I have see the last expression returned even without
the {...}.  Maybe I am misremembering.


So there is no need for the 'return %h' in your 
code. 'return ...' is only needed if you  have some logic where the 
block can exit in several places, not just the last expression.


5) To specify an 'array', you can use 'sub x( --> Array) { my @a = 1..* }'

6) HOWEVER, you really do need to read the documentation about 
Sequences, lists and arrays.


Richard



I have always used "return" to make it more readable.  And
sometimes I will return before end of the sub.   I can
type, so extra words don't bother me.

Nice exposition!  Thank you!


Re: Once again - You say one thing and do another Re: Bug to report: cardinal called an integer

2020-01-17 Thread Todd Chester via perl6-users




On 2020-01-17 00:12, Veesh Goldman wrote:

he's finally looked into making pull requests.


Do you have a link to the pull requests for
the documentation?  I'd like to add some examples
to a few pages.


Re: bitwise NOT

2020-01-14 Thread Todd Chester via perl6-users
On Tue, Jan 14, 2020 at 7:45 AM Paul Procacci > wrote:


 >> What is the syntax for a twos complement anyway?

I'm not sure I understand the question.
Two's compliment is +^ ... the routine you've been using.

On Tue, Jan 14, 2020 at 12:33 AM ToddAndMargo via perl6-users
mailto:perl6-users@perl.org>> wrote:

 >> On Mon, Jan 13, 2020 at 11:30 PM ToddAndMargo via perl6-users
 >> mailto:perl6-users@perl.org>
>> wrote:
 >>
 >> Hi All,
 >>
 >> This works,
 >>
 >>  $ p6 'my uint8 $c = 0xA5; my uint8 $d =  +^$c; say
$d.base(16);'
 >>  5A
 >>
 >> But this does not:
 >>
 >>  $ p6 'my uint8 $c = 0xA5; say (+^$c).base(16);'
 >>  -A6
 >>
 >> 1) who turned it into an negative integer?
 >>
 >> 2) how do I turn it back?
 >>
 >> Many thanks,
 >> -T

On 2020-01-13 21:18, Paul Procacci wrote:
 > If you read the signature for +^, you'll notice it returns an
Int.
 >
 > In your first working example, you're taking a uint8 with
binary value
 > 10100101, zero extending it to 64 bits via +^, applying a two's
 > compliment, and then assigning bits [0:7] to another uint8
which at that
 > point contains the binary value of 01011010 (or hex value 0x5A).
 > In your second example that isn't working, you're taking
uint8 with
 > binary value 10100101, zero extending it to 64 bits via +^,
applying a
 > two's compliment, and then displaying this *Int* (64 bits) as
hex.[1]
 > To turn it back you need to mask off bits [8:63] with: say
((+^$e) +&
 > 0x0FF).base(16);" [2]
 >
 > [1] I'd show you the 64 bit value but it's a bunch of 1's
followed by
 > the value -0xA6.
 > [2] Note, since the type has been promoted to an Int there'
no going
 > back to uint8 without an explicit assignment (afaik)
 >

That explains it.  Thank you.

I used uint8 to keep the ones to a mild torrent!

If I am remembering correctly, 0xA5 going to 0x5A is
a ones compliment.

What is the syntax for a twos complement anyway?





On 2020-01-14 05:14, Gerard ONeill wrote:
A negative number (-A5) is the twos compliment of the positive number.  
A ones compliment is all the bits flipped.  A twos compliment is a ones 
compliment plus one.  So a ones compliment of (A5) is (-A5 - 1), which 
is -A6.


So presumably, the twos compliment operator is (-). And I suppose for 
consistency, +-A5 gives you -A5, which makes +- the twos compliment 
bitwise operator..




It is a pain to keep the variables from being "Coerced to Int",
but this pretty much shows it

$ p6 'my byte $x = 0xA5; say $x.base(16), " original";
  my byte $y = +^$x; say $y.base(16), " ones compliment";
  my byte $z = $x + $y + 1;
  say $z.base(16), "  original + 2s compliment";'

A5 original
5A ones compliment
0  original + 2s compliment


Re: NQPMu ??

2020-01-09 Thread Todd Chester via perl6-users





On 09/01/2020 19:16, ToddAndMargo via perl6-users wrote:

On 2020-01-09 10:11, ToddAndMargo via perl6-users wrote:

Hi All,

What am I doing wrong here?

Many thanks,
-T


$ raku
To exit type 'exit' or '^D'
  > my uint32 $c;
0

  > $c = 0xFFAA;
Cannot find method 'qast' on object of type NQPMu

  > $c = 2;
Cannot find method 'qast' on object of type NQPMu




$ p6 'my uint32 $c; $c = 0xFFAA; say $c.base(16);'
FFAA

Hmmm ...

Bug in REPL?


On 2020-01-09 10:22, Timo Paulssen wrote:
> Yes, native integers/nums don't work in the REPL (that's any uint or int
> with number after it, or num32 or num64 or num or int or long etc).
>

Bummer.  I really love that utility.  Thank you for the confirmation.

Do you know if there is a bug I can sign up to watch?

-T


Re: How do I convert integer to cardinal on the fly?

2020-01-07 Thread Todd Chester via perl6-users
On Tue, Jan 7, 2020 at 10:20 AM ToddAndMargo via perl6-users 
mailto:perl6-users@perl.org>> wrote:


On 2020-01-06 22:54, ToddAndMargo via perl6-users wrote:
 > Hi All,
 >
 > What am I doing wrong here?
 >
 >  > my int16 $x = 0xABCD;
 > -21555
 >
 >  > say $x.base(16);
 > -5433
 >
 >  > my uint16 $y = $x.uint16;
 > No such method 'uint16' for invocant of type 'Int'
 >in block  at  line 1
 >
 > Many thanks,
 > -T


Came up with a work around:

   my int16 $x = 0xABCD;
   my uint16 $y = $x +| 0x;
   say $x.base(16);
   say $y.base(16)

   -5433
   ABCD

What is the proper way?





On 2020-01-07 08:33, Brad Gilbert wrote:

       my int16 $x = 0xABCD;
       my uint16 $y = $x;

       say $x.base(16);
       say $y.base(16)

       -5433
       ABCD

If you just want to coerce to uint16

     (my uint16 $ = $x)

     say (my uint16 $ = $x).base(16)



I was looking for a way to do it after the variables were declared


Re: Cardinals

2020-01-03 Thread Todd Chester via perl6-users




On 2020-01-02 22:19, Darren Duncan wrote:

On 2020-01-02 10:01 a.m., ToddAndMargo via perl6-users wrote:

How do I do a 32 bit unsigned integer (cardinal)?  I
have a situation where I need to be able to have the
first bit be a one and not have Raku think it is
a negative number.


Why do you use the term "cardinal" to refer to a 32 bit unsigned integer?

The term "cardinal" in practice is just an integer/number of any 
magnitude with the added semantics of representing a quantity/count of 
something in contrast to say an ordinal position or name of something.


Cardinals can't be negative.  Think of them as counting numbers



The term definitely does not represent a fixed-size number and it can 
also be negative.


You are confusing a cardinal with an integer.  An easy mistake
to make


-- Darren Duncan


Hi Darren,

Cardinal number
https://simple.wikipedia.org/wiki/Cardinal_number

 "Cardinal numbers (or cardinals) are numbers that say how
 many of something there are, for example: one, two,
 three, four, five, six. They are sometimes called
 counting numbers. "


Cardinal Numbers
https://www.mathsisfun.com/numbers/cardinal-ordinal-nominal.html

"A Cardinal Number says how many of something there are,
such as one, two, three, four, five.

A Cardinal Number answers the question 'How Many?'"


Modula-2 Basic Data Types
https://www.modula2.org/sb/env/index75.htm

CARDINAL   16-bit compiler:   2 bytes  0 to 65535
   32-bit compiler:   4 bytes  0 to 4,294,967,295

I was pretty good at Modula2 back in the day,

:-)

-T


Re: Cardinals

2020-01-02 Thread Todd Chester via perl6-users




On 2020-01-02 10:14, Tobias Boege wrote:

On Thu, 02 Jan 2020, ToddAndMargo via perl6-users wrote:

Hi All,

  “He who asks is a fool for five minutes, but he who
  does not ask remains a fool forever.”
  ― Mark Twain

This would be my five minutes.  I will live.

How do I do a 32 bit unsigned integer (cardinal)?  I
have a situation where I need to be able to have the
first bit be a one and not have Raku think it is
a negative number.




It's called uint32: 
https://docs.perl6.org/language/nativetypes#index-entry-uint32



Hi Tobias,

Perfect!   Thank you!

-T


p6 'my uint16 $x = 0x8765;
my int16  $y = 0x8765;
say $x.base(0x10);
say $y.base(0x10);'

8765
-789B


p6 'my uint16 $x = 0x8765;
$x += 0xFF;
say $x.base(0x10);'

8864


p6 'my uint16 $x = 0x8765;
my int16 $y = $x +| 0x00;
say $x.base(0x10); say $y.base(0x10);'

8765
-789B


p6 'my uint16 $x = 0x4ABC;
$x = $x +< 1;
say $x.base(0x10);'
9578


p6 'my uint16 $x = 0x4ABC;
$x += $x;
say $x.base(0x10);'

9578


Re: I need helping understanding a pointer example

2019-12-31 Thread Todd Chester via perl6-users




On 2019-12-30 23:14, Veesh Goldman wrote:
Method declares a method as opposed to a function. The difference is 
that in a method, the first argument passed to the function is bound to 
`self`, which represents the object the call was made on.


In traditional perl style, when you call a method on an object 
`your.face('scrambled eggs')`, it actually calls `face(your, 'scrambled 
eggs')`. At least that's the semantics in Perl.





Hi Veesh,

I spaced on method for a moment.  I use them all
the time. I don't think I had ever seen their
definitions written and thought I was looking
at something new.  Doesn't help that I can't write one
myself.

Thank you!

-T


Re: My Native Call notes

2019-12-30 Thread Todd Chester via perl6-users




On 2019-12-29 17:05, ToddAndMargo via perl6-users wrote:

Native Call is tack the chr(0) at the end for you, most of the time


Mistake on my part.  No it won't.  You have to add it yourself.


I need helping understanding a pointer example

2019-12-30 Thread Todd Chester via perl6-users

Hi All,

Over at

https://docs.raku.org/language/nativecall.html#Basic_use_of_pointers

There is an example:

   useNativeCall;
   classFooHandleisrepr('CPointer') {
   # Here are the actual NativeCall functions.
   subFoo_init() returnsFooHandleisnative("foo") {*}
   subFoo_free(FooHandle) isnative("foo") {*}
   subFoo_query(FooHandle, Str) returnsint8isnative("foo") {*}
   subFoo_close(FooHandle) returnsint8isnative("foo") {*}
   # Here are the methods we use to expose it to the outside world.
   methodnew{
   Foo_init();
   }
   methodquery(Str$stmt) {
   Foo_query(self, $stmt);
   }
   methodclose{
   Foo_close(self);
   }
   # Free data when the object is garbage collected.
   submethodDESTROY{
   Foo_free(self);
   }
   }

I just can't keeping my head what is going on.

Questions:

1) How can I get a list of what types are imported (like Pointer
and CArray) when I `use nativeCall` and what their definitions
are?

2) on

   # Here are the actual NativeCall functions.
   subFoo_init() returnsFooHandleisnative("foo") {*}
   subFoo_free(FooHandle) isnative("foo") {*}
   subFoo_query(FooHandle, Str) returnsint8isnative("foo") {*}
   subFoo_close(FooHandle) returnsint8isnative("foo") {*}

He called subs exported from NativeCall "foo*"?

What does hemean by `# Here are the actual NativeCall functions.`?

If he means these are fictitious "C" calls formatted into NativeCall
format, he in NOT BEING HELPFUL.  I need to see BOTH the actual "C"
calls as well as how he formatted them to NativeCall.

3) what is ?
subFoo_init() returnsFooHandleisnative("foo") {*}`

4) what is ?
    subFoo_free(FooHandle) isnative("foo") {*}

5) what is ?
subFoo_query(FooHandle, Str) returnsint8isnative("foo") {*}

6) what is ?
subFoo_close(FooHandle) returnsint8isnative("foo") {*}

7) A) in the below, where did `self` come from?  Is it a type?

   B) not to ask too stupid a question, but what does "method"
    do for me?

   methodquery(Str$stmt) {
   Foo_query(self, $stmt);
   }


Just a general comment:

It would be wonderful if the docs would show actual "C" calls
from something like Kernel32.dll and how to access them
with NativeCall.

For instance:

   |LSTATUS RegQueryValueExA( HKEY hKey, LPCSTR lpValueName, LPDWORD
   lpReserved, LPDWORD lpType, LPBYTE lpData, LPDWORD lpcbData );
   |

|The example should go over what to give NativeCall for|
|all of the above "C" types.|
||
Yours in Confusion,,
-T





NativeCall Doc booboo

2019-12-30 Thread Todd Chester via perl6-users

Hi All,

https://docs.raku.org/language/nativecall.html#Passing_and_returning_values

Did anyone else discover the mistake, hopefully not the hard way like I
did.  Anyone get weird gibberish printed out like I did?

   my$string="FOO";
   # The lifetime of this variable must be equal to the required lifetime of
   # the data passed to the C function.
   my$array=CArray[uint8].new($string.encode.list);v

The mistake is that "C" strings are terminated by a chr(0) -- in
"C" terms chr(0) is called a nul or 0x00.

If you don't terminate your C string, the reading functions keep careening
until it finds a chr(0).  You have to tack a chr(0) onto the end.

   my$array=CArray[uint8].new($string.encode.list);
   $array [$array.elems] = 0;

$array should be 70 79 70 0  not  70 79 79
You can test this with `say "$array"` (include the quotes).

Maybe JJ will pick up on this and get it fixed.

-T


Re: modules and subsets

2019-12-13 Thread Todd Chester via perl6-users




On 2019-12-13 01:06, Fernando Santagata wrote:

our $pi is export = 4.13;



Thank you!


Re: modules and subsets

2019-12-12 Thread Todd Chester via perl6-users




On 2019-12-12 00:22, Fernando Santagata wrote:
On Thu, Dec 12, 2019 at 3:46 AM Todd Chester > wrote:


On 2019-12-11 10:22, Fernando Santagata wrote:
 > File test.pm6
 >
 > unit module test;
 > subset PosInt of Int is export where * > 0;
 >
 >
 > File test.p6
 >
 > use lib '.';
 > use test;
 > sub mytest(PosInt $a) { say $a }
 > mytest(1); # output: 1
 > mytest(-1);    # output Constraint type check failed in binding to
 > parameter '$a'; expected test::PosInt but got Int (-1)

Hi Fernando,

What response do you get back with?

      perl6 -c test.pl6

-T


I don't understand the reason for your question, but anyway:

$ perl6 -c test.pl6
Syntax OK

--
Fernando Santagata



Hi Frenando,

Thank you!

I was looking to see at what point in the process
the "constraint type" check triggered.

You test showed me that there is no benefit to using
a subset when it comes to trapping the error before
run time.

Another thank you for

subset PosInt of Int is export where * > 0;

I can export the subset from the module.

Can I export any other variable and constants the same way:

 my $pi = 4.13 is export;

-T


Re: Fwd: Raku, docs, help [was: Re: vulgar?]

2019-12-11 Thread Todd Chester via perl6-users




On 2019-12-11 14:26, Joseph Brenner wrote:

Joseph Brenner  wrote:

The signatures in the documentation are certainly helpful, but they're
no substitute for code examples.   I'd go after adding more code
examples, rather than removing other stuff.


But then, maybe I'm coming into this discussion in the middle-- is the
topic here adding command-line switches to suppress some type
checking, e.g. for one-liners?

That would make some sense to me, but I don't have any strong feelings about it.



The discussion changed into me not liking the way they
prssent the signatures in the doc pages.  You were on target.


Re: Fwd: Raku, docs, help [was: Re: vulgar?]

2019-12-11 Thread Todd Chester via perl6-users




On 2019-12-11 14:06, Joseph Brenner wrote:

The signatures in the documentation are certainly helpful, but they're
no substitute for code examples.   I'd go after adding more code
examples, rather than removing other stuff.



Hi Joseph,

I would compromise on that.

I would also like to see the doc's signature page explain in
detail what each position and symbol means before jumping
into various signatures.  In other words, start at the
beginning, not the middle.

-T


Re: modules and subsets

2019-12-11 Thread Todd Chester via perl6-users




On 2019-12-11 10:16, Elizabeth Mattijsen wrote:

$ 6 'subset A of Int; dd OUR::.keys'
("A",).Seq


Hi Elizabeth,

subset A of Int; dd OUR::.keys
("A",).Seq
Nil

Would you explain how your are using dd and what your
are showing me here?

Also how it ties into my original question as to if
the calling programs sees anything in the
global section of a module's sub.

Many thanks,
-T


Re: modules and subsets

2019-12-11 Thread Todd Chester via perl6-users




On 2019-12-11 09:54, JJ Merelo wrote:
By default, the scope of anything (containers, classes, whatever) is 
lexical to the scope they are in.


Hi JJ,

Thank you for responding.

By the way, I'd be a Golden.

I don't understand how you are using the word "lexical".

I may be mixing Modula2 with Raku in that I am thinking
I define the subset and some kind of structure in the global
section of the module and expecting the importer of the sub
also see it.  Is the structure defined in the declaration
line of the exported sub?

Many thanks,
-T


Re: where is my map typo?

2019-12-05 Thread Todd Chester via perl6-users




On 2019-12-04 15:53, William Michels via perl6-users wrote:

Do you not have a working Raku/Perl6 REPL install?


Hi William,

Being as I do not know what REPL is, I would have
to say "no".

This is the Perl I am using:

https://github.com/nxadm/rakudo-pkg/releases/download/v2019.11/rakudo-pkg-Fedora31-2019.11-01.x86_64.rpm

-T


Re: hash and print question

2019-12-05 Thread Todd Chester via perl6-users




On 2019-12-05 01:59, Todd Chester via perl6-users wrote:

put he space


or the "t" before "the".  Chuckle.


Re: hash and print question

2019-12-05 Thread Todd Chester via perl6-users
On Thu, Dec 5, 2019 at 10:52 AM Todd Chester via perl6-users 
mailto:perl6-users@perl.org>> wrote:


Hi All,

In the following,


$ p6 'my %x= YesNo=>0xff, OkayCancel=>0x55; my $y="YesNo"; if  %x<<$y>>
{say %x<<$y >>.base(16)}else{say "n"};'
FF

$ p6 'my %x= YesNo=>0xff, OkayCancel=>0x55; my $y="Help"; if  %x<<$y>>
{say %x<< $y >>.base(16)}else{say "n"};'
n

I have to use a space after $y
 say %x<<$y >>.base(16)

or I get the finger wagged at me.

  Ambiguous use of >>; use » instead to mean hyper, or
  insert whitespace before >> to mean a quote terminator
  (or use different delimiters?)

Is there a better way to write:
  say %x<<$y >>.base(16)

Many thanks,
-T




On 2019-12-05 01:56, Fernando Santagata wrote:

Try

say %x{$y}.base(16);

Fernando Santagata


Hi Fernando,

Much prettier!  Thank you!

I would never remember to put he space in before the >>

-T

$ p6 'my %x= YesNo=>0xff, OkayCancel=>0x55; my $y="Help"; if  %x{$y} 
{say %x{$y}.base(16)}else{say "n"};'

n

$ p6 'my %x= YesNo=>0xff, OkayCancel=>0x55; my $y="YesNo"; if  %x{$y} 
{say %x{$y}.base(16)}else{say "n"};'

FF


vulgar?

2019-12-05 Thread Todd Chester via perl6-users

Hi All,

I really like this guys style of writing and examples
for Perl6.

But he can be a bit vulgar at times, which I ignore.
Is he doing it on purpose?  Or is there some translation
error and he does not realize he is swearing?

Warning: if you go here there are some dirty words
in the titles:

https://andrewshitov.com/category/using-perl-6/

-T


hash and print question

2019-12-05 Thread Todd Chester via perl6-users

Hi All,

In the following,


$ p6 'my %x= YesNo=>0xff, OkayCancel=>0x55; my $y="YesNo"; if  %x<<$y>> 
{say %x<<$y >>.base(16)}else{say "n"};'

FF

$ p6 'my %x= YesNo=>0xff, OkayCancel=>0x55; my $y="Help"; if  %x<<$y>> 
{say %x<< $y >>.base(16)}else{say "n"};'

n

I have to use a space after $y
   say %x<<$y >>.base(16)

or I get the finger wagged at me.

Ambiguous use of >>; use » instead to mean hyper, or
insert whitespace before >> to mean a quote terminator
(or use different delimiters?)

Is there a better way to write:
say %x<<$y >>.base(16)

Many thanks,
-T


Re: Match operator: error with any() junction and user-defined $_ topic variable

2019-10-10 Thread Todd Chester via perl6-users




On 10/8/19 10:53 AM, Brad Gilbert wrote:

Most operations with Junctions produce Junctions.

     > 1 + any(2, 3)
     any(3, 4)


$ p6 'say 4 + any(44,66);'
any(48, 70)

Sweet!  But what would you ever use it for?

Would this be the intended use: add a number to all
values in an array?

$ p6 'my @x=[44,66]; say 4 + @x.any;'
any(48, 70)

$ p6 'my @x=[44,66]; 4 + @x.any; say @x'
WARNINGS for -e:
Useless use of "+" in expression "4 + @x.any" in sink context (line 1)
[44 66]


-T


Re: I need help with "lines"

2019-03-15 Thread Todd Chester via perl6-users




On 3/15/19 7:58 AM, Todd Chester via perl6-users wrote:

Never did figure out why everything went into @x[0]


The entire pipe gets put into @x[0].  @x[1] is uninitialized


Re: I need help with "lines"

2019-03-15 Thread Todd Chester via perl6-users




On 3/15/19 3:02 AM, Peter Pentchev wrote:

On Fri, Mar 15, 2019 at 11:52:15AM +0200, Peter Pentchev wrote:
[snip]

3. The standard input stream in Perl 6 is called $*IN (think of it as
mostly equivalent to what <<>> and <> would read from in Perl 5,


...sorry about this part, I know it's not correct.


and pretty much the same thing as Perl 5's STDIN.


...this is the correct statement.


sub is-ours($line) {
$line ~~ /^ \s* $ = [\d+] \s+ "zsh" \s .* \s+ $ = [ <[- \d 
:]> + ] $/
?? (~$/ => pad-elapsed $/)
!! Any
}


Of course, you may need to modify this a bit if you don't want to look
for "zsh" processes... :)

G'luck,
Peter




Never did figure out why everything went into @x[0]


Re: I need help with "lines"

2019-03-15 Thread Todd Chester via perl6-users




On 3/15/19 2:52 AM, Peter Pentchev wrote:

Hope that helped!

G'luck,
Peter

[1] The "almost certainly" is because, yes, yes, I know, I also have that
 dusty old HP/UX crunching away in a customer's basement; still.


Yes it does.  Thank you!

I remember zsh for my Solaris days.  Or at least I think I
remember that.  Time fades ...


Re: I need help with "lines"

2019-03-15 Thread Todd Chester via perl6-users




On 3/15/19 2:52 AM, Peter Pentchev wrote:

1. Learn to use pgrep instead of the myriad variations of ps | grep;
pgrep has been standardized by POSIX for a long time and is almost
certainly available in all the installations that you will ever need
to touch[1].


pgrep is interesting!  But it is not listing all the processes.  :'(

$ pgrep firefox
2135

$ ps ax | grep [f]irefox | awk '{print $1}'
2135
2239
2342
2425


Re: I need help with "lines"

2019-03-15 Thread Todd Chester via perl6-users




On 3/15/19 2:35 AM, Simon Proctor wrote:

All looking good so far. what is it you're wanting from this data?


Hi Simon,

Thank you!

What this is for is a backup routine.  I am checking for
the highest instance of any jammed running instances of
[xfa]dump.  If I find any, I "kill -9" it and walk backwards
until I have them all killed.

Once I am sure there are no long any jammed [xfa]dump's running,
then I cut loose my own instance of [xfa]dump.

This is bash script language.

GetLastDumpPID () {
   local Last=$(ps ax | grep "[d]ump " | awk '{print $1}' | 
/usr/bin/sort -r | /usr/bin/sed -n '1p')

   echo $Last
}


KillJammedDumps () {
   local PID="`GetLastDumpPID`"

   if [ -z "$PID" ]; then
  echo " ... No jammed dumps detected"

   else
  while [ -n "$PID" ]
 do
echo " ... kill jammed dump PID <"$PID">"
kill -9 $PID
PID="`GetLastDumpPID`"
 done
   fi

   echo " "
}



-T


Re: I need help with "lines"

2019-03-15 Thread Todd Chester via perl6-users




On 3/14/19 10:05 PM, Todd Chester via perl6-users wrote:

Hi All,

What am I doing wrong here?

ps ax | grep [f]irefox | perl6 -ne 'my @x = $_.words[0].lines.reverse; 
print @x[0] ~ "\n";'

7380
7581
7698
13023
13767
13908


Two problems:

1) "lines" is putting everything into @x[0]

2) "reverse" is ignoring me as there is no @x[1]. etc.

The result I want is 13908

Many thanks,
-T



This is what I am trying to duplicate:

$ ps ax | grep [f]irefox | awk '{print $1}' | /usr/bin/sort -r | 
/usr/bin/sed -n '1,1p'


7814


Re: I need help with "lines"

2019-03-14 Thread Todd Chester via perl6-users
On Fri, 15 Mar 2019, 05:34 Todd Chester via perl6-users, 
mailto:perl6-users@perl.org>> wrote:




On 3/14/19 10:05 PM, Todd Chester via perl6-users wrote:
 > Hi All,
 >
 > What am I doing wrong here?
 >
 > ps ax | grep [f]irefox | perl6 -ne 'my @x =
$_.words[0].lines.reverse;
 > print @x[0] ~ "\n";'
 > 7380
 > 7581
 > 7698
 > 13023
 > 13767
 > 13908
 >
 >
 > Two problems:
 >
 > 1) "lines" is putting everything into @x[0]
 >
 > 2) "reverse" is ignoring me as there is no @x[1]. etc.
 >
 > The result I want is 13908
 >
 > Many thanks,
 > -T

And why do I have a broken pipe here?

$ ps ax | grep [f]irefox | perl6 -ne 'say
$_.lines.sort.reverse.words[0];'
7380
7581
7698
13023
13767
22369

$ ps ax | grep [f]irefox | perl6 -ne 'say
$_.lines.sort.reverse.words[0];' | sort -r

Failed to write bytes to filehandle: Broken pipe
in block  at -e line 1





On 3/14/19 10:53 PM, Simon Proctor wrote:
6am here and I'm not at a computer but I think your problem is trying to 
use both -n which runs your code on each line of STDIN and lines.


Try one or the other see what happens.

Once I'm ambulant and at a computer I'll poke at it myself.



Thank you anyway.


$ ps ax | grep [f]irefox | perl6 -n 'my @x = $_.words[0].lines.reverse; 
print @x[0] ~ "\n";'
Could not open my @x = $_.words[0].lines.reverse; print @x[0] ~ "\n";. 
Failed to stat file: no such file or directory


$ ps ax | grep [f]irefox | perl6 -e 'my @x = $_.words[0].lines.reverse; 
print @x[0] ~ "\n";'

No such method 'words' for invocant of type 'Any'
  in block  at -e line 1





Re: I need help with "lines"

2019-03-14 Thread Todd Chester via perl6-users




On 3/14/19 10:05 PM, Todd Chester via perl6-users wrote:

Hi All,

What am I doing wrong here?

ps ax | grep [f]irefox | perl6 -ne 'my @x = $_.words[0].lines.reverse; 
print @x[0] ~ "\n";'

7380
7581
7698
13023
13767
13908


Two problems:

1) "lines" is putting everything into @x[0]

2) "reverse" is ignoring me as there is no @x[1]. etc.

The result I want is 13908

Many thanks,
-T


And why do I have a broken pipe here?

$ ps ax | grep [f]irefox | perl6 -ne 'say $_.lines.sort.reverse.words[0];'
7380
7581
7698
13023
13767
22369

$ ps ax | grep [f]irefox | perl6 -ne 'say 
$_.lines.sort.reverse.words[0];' | sort -r


Failed to write bytes to filehandle: Broken pipe
  in block  at -e line 1


print to a printer

2019-03-14 Thread Todd Chester via perl6-users

Hi All

Fedora 29

Is there a way to print to a printer, other than a system call
to lpr?

Many thanks,
-T


I need help with "lines"

2019-03-14 Thread Todd Chester via perl6-users

Hi All,

What am I doing wrong here?

ps ax | grep [f]irefox | perl6 -ne 'my @x = $_.words[0].lines.reverse; 
print @x[0] ~ "\n";'

7380
7581
7698
13023
13767
13908


Two problems:

1) "lines" is putting everything into @x[0]

2) "reverse" is ignoring me as there is no @x[1]. etc.

The result I want is 13908

Many thanks,
-T


Re: .payload

2019-02-28 Thread Todd Chester via perl6-users




On 2/28/19 2:06 PM, Timo Paulssen wrote:

I just changed the docs to replace payload with message here. It's not a
language bug, however.

Here's the change on github:


https://github.com/perl6/doc/commit/fb5d341036afe387f0ead0b76e09aef75205dcaf


You are a force of nature Timo!

:-)


Re: shift left syntax?

2019-02-07 Thread Todd Chester via perl6-users




On 2/7/19 10:36 PM, yary wrote:

perl6 -e 'my $i = 0x5DAE; $i +<= 1; say $i.base(0x10);'

BB5C

-y




Hi Yary,

$ p6 'my Buf $x=Buf.new(0xAE,0x5D); my int32 $i=0x5DAE; say $x; say 
$i.base(0x10); $i +< 0x01; say $i.base(0x10);'


WARNINGS for -e:
Useless use of "+<" in expression "$i +< 0x01" in sink context (line 1)
Buf:0x
5DAE
5DAE


Ah poop!  I forgot the =

$ p6 'my int32 $i=0x5DAE; say $i.base(0x10); $i +<= 0x01; say 
$i.base(0x10);'

5DAE
BB5C


Thank you!

-T


Re: print hex?

2019-02-07 Thread Todd Chester via perl6-users




On 2/7/19 11:22 AM, Curt Tilmes wrote:
On Thu, Feb 7, 2019 at 2:14 PM ToddAndMargo via perl6-users 
mailto:perl6-users@perl.org>> wrote:


What is the easiest way to get both print and say to print $i below
in Hex?

$ p6 'my Buf $x=Buf.new(0xAE,0x5D); my int16 $i=0x5DAE; say $x; say $i;'

Buf:0x
23982


say $i.base(16)




Hi Curt,

   A thing of beauty!  Thank you!

-T

$ p6 'my Buf $x=Buf.new(0xAE,0x5D); my int16 $i=0x5DAE; say $x; say 
$i.base(0x10); print $i.base(16) ~ "\n"'


Buf:0x
5DAE
5DAE


buf to integer?

2019-02-07 Thread Todd Chester via perl6-users

Hi All,

I am dealing with a Buf what includes 32 bit integers, but
they are entered somewhat backwards as view with hexedit:

AE 5D 5C 72 represents the number 725C5DAE

This is what I have come up with to convert this type of
number in a buffer to and integer

$ p6 'my Buf $x=Buf.new(0xAE,0x5D,0x5C,0x72); my int32 $i=$x[3] +< 0x18 
+  $x[2] +< 0x10  +  $x[1] +< 0x08  +  $x[0];  say $x; say $i.base(0x10);'


Buf:0x
725C5DAE


Is there a more "elegant" way to do this?

Many thanks,
-T


shift left syntax?

2019-02-07 Thread Todd Chester via perl6-users

Hi All,

Is this the only way to shift left?

  $i = $i +< 0x01

$ p6 'my int32 $i=0x5DAE; say $i.base(0x10); $i = $i +< 0x01; say 
$i.base(0x10);'


5DAE
BB5C


Does we have any of those fancy += ~= ways of doing it?

Many thanks,
-T


Re: zef installs not working

2018-10-17 Thread Todd Chester via perl6-users




On 10/17/18 1:05 PM, Joseph Brenner wrote:

Todd Chester wrote:


What I do is to go to the github source for the module:
Next I cd into the directory and install it with

 zef install .

Yes, that much seems to work fine.  It seems a little peculiar that I
can search the repositories with "zef list", but not with "zef install
".

Maybe some sort of permissions issue with a LTA error message?


I have never been able to figure it out.  I basically
try the "zef install " method first.  If
that does not work, I download int.

Glad to have helped!  Usually folks are always helping me.
Nice to be the other way around for a change.

-T


Re: zef installs not working

2018-10-16 Thread Todd Chester via perl6-users




On 10/16/18 8:20 PM, Joseph Brenner wrote:

Lately zef hasn't been working for me to do module installation.
I can do things like "zef --list" to get a list of available
modules but when I actually try to do the installation I see
things like this:

   zef install Array::Agnostic

   ===> Searching for: Array::Agnostic
   ===> Testing: Array::Agnostic:ver<0.0.6>:auth
   ===SORRY!===
   Object does not exist in serialization context
   ===> Testing [FAIL]: Array::Agnostic:ver<0.0.6>:auth
   Aborting due to test failure:
Array::Agnostic:ver<0.0.6>:auth (use --force-test to
override)

And no, using --force-test only gets me a little further, it
still fails with "Object does not exist in serialization context".

Any suggestions on what that might mean?



perl6 --version
This is Rakudo Star version 2018.06 built on MoarVM version 2018.06
implementing Perl 6.c.



Hi Joseph,

What I do is to go to the github source for the module:

https://github.com/lizmat/Array-Agnostic

Then I "Clone or Download" (green button on the right middle).
I usually download it as a "zip".  Then I unzip it to a directory.

Next I cd into the directory and install it with

   zef install .

HTH,
-T


Re: routine declaration line question

2018-10-12 Thread Todd Chester via perl6-users




On 10/12/18 3:47 AM, Curt Tilmes wrote:



On Fri, Oct 12, 2018 at 6:08 AM Todd Chester via perl6-users 
mailto:perl6-users@perl.org>> wrote:


 > If nothing is being returned, it should really be indicated with
--> Nil
 > since that can enable certain optimizations.  Similarly, if a
routine always
 > returns true upon success, that can be indicated with --> True.

Am I interpreting Larry correctly?  Should every definition line
always have a --> at the end?


Adding it gives more information to the consumers of that routine, the 
people reading it,
the compiler optimizing use of the routine, and the runtime execution 
which will validate the
return and throw an exception for you if it is wrong.  (There is a tiny, 
tiny bit of runtime overtime
to do that check.  Optimization could easily offset or overwhelm that 
overhead.)


Like many things in Perl, you are free to add the extra stuff if you 
want to take advantage of that,
but also free to leave it out if you don't feel like it.  The language 
supports many different levels
of formality you get to choose from.  For "quick and dirty" programming, 
go ahead and leave

them out if  you want.

Curt



Hi Curt,

I was asking because sometimes the documentation for routines does
not give a --> and I find having to dig around to figure out what
the return is to be time consuming and confusing.

Based on what Larry stated, I do believe that the documentation
should always have a --> in the definition line.  This was
my question, not whether or not I should write a definition
line for my own subs.

-T

'"quick and dirty" programming', huh.  I live and die by Top Down.
You can't maintain "stream of conscience" programming.  If you
do a little up front planning, you save yourself 10 times the
time down the road trying to maintain it.


Re: routine declaration line question

2018-10-12 Thread Todd Chester via perl6-users




On 10/5/18 8:39 AM, Larry Wall wrote:

On Thu, Oct 04, 2018 at 03:13:15PM -0400, Trey Harris wrote:
: Right; that's what I meant by "stylistically" — a `--> Mu` can highlight
: that something is being returned (and that side-effects are not the primary
: purpose), while nothing indicates that the return value, though it exists,
: is incidental and probably from "falling off the end" or using `return` as
: a control-flow jump.

If nothing is being returned, it should really be indicated with --> Nil
since that can enable certain optimizations.  Similarly, if a routine always
returns true upon success, that can be indicated with --> True.

Larry



Am I interpreting Larry correctly?  Should every definition line
always have a --> at the end?