Re: bash "."?

2020-05-14 Thread ToddAndMargo via perl6-users

On 2020-05-13 22:27, Bruce Gray wrote:




On May 13, 2020, at 9:37 PM, ToddAndMargo via perl6-users 
 wrote:

Hi All,

Do we have anything like Bash's "." statement where
we can read in a bunch of values from a .cfg file?
(I think it is called "include", but I am not sure.)

. /etc/sysconfig/network-scripts/ifcfg-br0

which populates these (and other) variables

DEVICE=br0
TYPE=Bridge
ONBOOT=yes
USERCTL=yes
DELAY=0
NM_CONTROLLED=yes
BOOTPROTO=none
PREFIX=24
...

Many thanks,
-T


Hi Todd,

FYI, the `.` Bash command is also called `source`, which is easier to search on 
the Web, and clearer in email:
https://ss64.com/bash/source.html

The closest equivalent in Raku is:
https://docs.raku.org/routine/EVALFILE
, which could be used for config data like so:
$ cat a.dat
$foo = "bar";
$baz = "quxx";

$ perl6 -e 'our ($foo, $baz); EVALFILE "a.dat"; .say for $foo, $baz;'
bar
quxx

, but please do not use it for this purpose.

EVALFILE is in all-caps to show that it might be dangerous and not for general 
use; it is “grep-able evil”, and could eval any valid Raku code, even evil 
things like `run “rm -rf /“`.

IMHO, Bash's `source`-style of loading variables pollutes the main namespace 
and causes hard-to-debug “action at a distance”.
In Raku (or any other dynamic language), the use of some kind of Config module 
is safer and cleaner:
https://modules.raku.org/t/CONFIG
https://github.com/raku-community-modules/perl6-Config-JSON
https://github.com/Skarsnik/perl6-config-simple
https://metacpan.org/pod/Config::Tiny

For example:

$ cat config.json
{
   "baz": "quxx",
   "foo": "bar”
}
$ perl6 -e 'use Config::JSON; my %c; %c{$_} = jconf($_) for ; say %c{$_} for 
;'
bar
quxx

$ cat b.dat
foo = bar
baz = quxx
$ perl6 -e 'use Config::Tiny:from; my $conf = Config::Tiny.read("b.dat"); .say for 
$conf<_>'
bar
quxx


—
Hope this helps,
Bruce Gray (Util of PerlMonks)



Hi Bruce,

I looked at the first two links above.  Neither showed
the format of the data being read. But you did.  Is
there some reason why the two links did not show the format?

-T


sqrt and Buf question

2020-05-14 Thread ToddAndMargo via perl6-users

Hi All,

1) how do I get 40 or more digits out of sqrt?

2) how to I assist those bytes to a 40 (or more)
byte long Buf?

This obviously does not work:

my Num $x = 3.sqrt; my Buf $y = Buf.new($x)

Type check failed in initializing element #0 to Buf; expected uint8 but 
got Num (1.7320508075688772e0)

  in block  at  line 1

Many thanks,
-T


Re: sqrt and Buf question

2020-05-14 Thread Tobias Boege
On Thu, 14 May 2020, ToddAndMargo via perl6-users wrote:
> Hi All,
> 
> 1) how do I get 40 or more digits out of sqrt?
> 

Meaningful digits? Not possible as sqrt uses limited precision. I think
the IEEE 754 doubles that I would suspect to be used internally are capped
way below 40 significant decimal digits.

> 2) how to I assist those bytes to a 40 (or more)
> byte long Buf?
> 
> This obviously does not work:
> 
> my Num $x = 3.sqrt; my Buf $y = Buf.new($x)
> 
> Type check failed in initializing element #0 to Buf; expected uint8 but got
> Num (1.7320508075688772e0)
>   in block  at  line 1
> 

You can convert the Num to a string and put that string into a Buf:

  Buf.new(3.sqrt.Str.encode)

That's what I'd do without any clue at all about who is supposed to use
this Buf. At least the buffer is about as long as the number is decimal
digits, which seems to be what you wanted?

Regards,
Tobias


Re: sqrt and Buf question

2020-05-14 Thread ToddAndMargo via perl6-users

On 2020-05-14 05:51, Tobias Boege wrote:

On Thu, 14 May 2020, ToddAndMargo via perl6-users wrote:

Hi All,

1) how do I get 40 or more digits out of sqrt?



Meaningful digits? 


In this instance, I do not care about meaningful.  I only
care about the noise.  Just has to be repeatable.

I may have to look it up on a chart.


Not possible as sqrt uses limited precision. I think
the IEEE 754 doubles that I would suspect to be used internally are capped
way below 40 significant decimal digits.


2) how to I assist those bytes to a 40 (or more)
byte long Buf?

This obviously does not work:

my Num $x = 3.sqrt; my Buf $y = Buf.new($x)

Type check failed in initializing element #0 to Buf; expected uint8 but got
Num (1.7320508075688772e0)
   in block  at  line 1



You can convert the Num to a string and put that string into a Buf:

   Buf.new(3.sqrt.Str.encode)

That's what I'd do without any clue 


I am not disclosing on purpose.  Sorry for keeping you
in the dark.


at all about who is supposed to use
this Buf. At least the buffer is about as long as the number is decimal
digits, which seems to be what you wanted?

Regards,
Tobias



my Buf $x = Buf.new(3.sqrt.Str.encode)
Buf:0x<31 2E 37 33 32 30 35 30 38 30 37 35 36 38 38 37 37 32>


Thank you!


Re: sqrt and Buf question

2020-05-14 Thread Bruce Gray



> On May 14, 2020, at 7:27 AM, ToddAndMargo via perl6-users 
>  wrote:
> 
> Hi All,
> 
> 1) how do I get 40 or more digits out of sqrt?

—snip—

Use an Integer Root algorithm on ($number-you-want-the-root-of * 100 ** 
$number-of-digits-you-want), then shift the decimal point of the result.

Exact code here:
https://rosettacode.org/wiki/Integer_roots#Raku

— 
Hope this helps,
Bruce Gray (“Util” on RosettaCode, too)


Re: bash "."?

2020-05-14 Thread Peter Pentchev
On Thu, May 14, 2020 at 04:39:18AM -0700, ToddAndMargo via perl6-users wrote:
> On 2020-05-13 22:27, Bruce Gray wrote:
> > 
> > 
> > > On May 13, 2020, at 9:37 PM, ToddAndMargo via perl6-users 
> > >  wrote:
> > > 
> > > Hi All,
> > > 
> > > Do we have anything like Bash's "." statement where
> > > we can read in a bunch of values from a .cfg file?
> > > (I think it is called "include", but I am not sure.)
> > > 
> > > . /etc/sysconfig/network-scripts/ifcfg-br0
> > > 
> > > which populates these (and other) variables
> > > 
> > > DEVICE=br0
> > > TYPE=Bridge
> > > ONBOOT=yes
> > > USERCTL=yes
> > > DELAY=0
> > > NM_CONTROLLED=yes
> > > BOOTPROTO=none
> > > PREFIX=24
> > > ...
> > > 
> > > Many thanks,
> > > -T
> > 
> > Hi Todd,
> > 
> > FYI, the `.` Bash command is also called `source`, which is easier to 
> > search on the Web, and clearer in email:
> > https://ss64.com/bash/source.html
> > 
> > The closest equivalent in Raku is:
> > https://docs.raku.org/routine/EVALFILE
> > , which could be used for config data like so:
> > $ cat a.dat
> > $foo = "bar";
> > $baz = "quxx";
> > 
> > $ perl6 -e 'our ($foo, $baz); EVALFILE "a.dat"; .say for $foo, $baz;'
> > bar
> > quxx
> > 
> > , but please do not use it for this purpose.
> > 
> > EVALFILE is in all-caps to show that it might be dangerous and not for 
> > general use; it is “grep-able evil”, and could eval any valid Raku code, 
> > even evil things like `run “rm -rf /“`.
> > 
> > IMHO, Bash's `source`-style of loading variables pollutes the main 
> > namespace and causes hard-to-debug “action at a distance”.
> > In Raku (or any other dynamic language), the use of some kind of Config 
> > module is safer and cleaner:
> > https://modules.raku.org/t/CONFIG
> > https://github.com/raku-community-modules/perl6-Config-JSON
> > https://github.com/Skarsnik/perl6-config-simple
> > https://metacpan.org/pod/Config::Tiny
> > 
> > For example:
> > 
> > $ cat config.json
> > {
> >"baz": "quxx",
> >"foo": "bar”
> > }
> > $ perl6 -e 'use Config::JSON; my %c; %c{$_} = jconf($_) for ; say 
> > %c{$_} for ;'
> > bar
> > quxx
> > 
> > $ cat b.dat
> > foo = bar
> > baz = quxx
> > $ perl6 -e 'use Config::Tiny:from; my $conf = 
> > Config::Tiny.read("b.dat"); .say for $conf<_>'
> > bar
> > quxx
> > 
> > 
> > —
> > Hope this helps,
> > Bruce Gray (Util of PerlMonks)
> 
> 
> Hi Bruce,
> 
> I looked at the first two links above.  Neither showed
> the format of the data being read. But you did.  Is
> there some reason why the two links did not show the format?

Well, they do both say they read .ini-style files. I think that they
will both be able to read simple key=value files like the network
definition sysconfig ones on RedHat-style systems that you seem to want.
Keep in mind that the shell probably interprets a bit more, so some
configuration-reading modules may e.g. return the quotes around the
value or something like that; take them for a spin and see.
Also, it's almost certain that these modules will not be able to help if
the files that you read make use of the fact that the shell performs
variable expansion: they will not be able to expand other variables in
lines like:

KEYFILE="/etc/keys/$HOSTNAME.key"

or something like that.

If you come across files like that, you may have to write your own
parser.

For some general information on ini-like files, see
https://en.wikipedia.org/wiki/INI_file

G'luck,
Peter

-- 
Peter Pentchev  r...@ringlet.net r...@debian.org p...@storpool.com
PGP key:http://people.FreeBSD.org/~roam/roam.key.asc
Key fingerprint 2EE7 A7A5 17FC 124C F115  C354 651E EFB0 2527 DF13


signature.asc
Description: PGP signature


the state of the build and install instructions

2020-05-14 Thread Joseph Brenner
I'm having trouble doing a build of raku from github.  Could it
be the INSTALL.txt file is out-of-date?

I was trying to build a "bleeding edge" Raku using the
instructions here:

  https://github.com/rakudo/rakudo/blob/master/INSTALL.txt

So I thought I'd just need to do this:

  cd /home/doom/End/Sys/Perl6/dev
  git clone git://github.com/rakudo/rakudo.git
  cd rakudo
  git pull
  perl Configure.pl --gen-moar --gen-nqp --backends=moar
  make

  pwd
  /home/doom/End/Sys/Perl6/dev/rakudo

  ./perl6 --version

But actually, there is no ./perl6 here.  And I don't see a
"Generating" message for it:

  [...]
  +++ Generatingrakudo-gdb-m
  +++ Generatingrakudo-lldb-m
  +++ Generatingrakudo-valgrind-m
  +++ Generatingperl6-gdb-m
  +++ Generatingperl6-lldb-m
  +++ Generatingperl6-valgrind-m

Trying something that looks close, I just get this an error:

  ./perl6-gdb-m --version

  Unhandled exception: While looking for
'/home/doom/End/Sys/Perl6/dev/rakudo/perl6.moarvm': no such file or
directory

That file doesn't exist... so despite the --gen-moar option, it
wasn't created?

  sudo updatedb
  locate perl6.moarvm

  /home/doom/End/Sys/Perl6/rakudo-star-2019.03/rakudo/perl6.moarvm
  /home/doom/End/Sys/Perl6/rakudo-star-2020.01/rakudo/perl6.moarvm
  /root/rakudo/share/perl6/runtime/perl6.moarvm

The INSTALL.txt describes a --with-moar option, so I thought I
might try building with an existing moarvm:

  cd /home/doom/End/Sys/Perl6/dev/rakudo
  perl Configure.pl
--with-moar=/home/doom/End/Sys/Perl6/rakudo-star-2020.01/rakudo/perl6.moarvm
--gen-nqp --backends=moar
  make

But that just errors out:

  Unknown option: with-moar


Re: the state of the build and install instructions

2020-05-14 Thread Elizabeth Mattijsen
Personally, I always do:

perl Configure.pl --gen-moar --gen-nqp --make-install

> On 14 May 2020, at 22:08, Joseph Brenner  wrote:
> 
> I'm having trouble doing a build of raku from github.  Could it
> be the INSTALL.txt file is out-of-date?
> 
> I was trying to build a "bleeding edge" Raku using the
> instructions here:
> 
>  https://github.com/rakudo/rakudo/blob/master/INSTALL.txt
> 
> So I thought I'd just need to do this:
> 
>  cd /home/doom/End/Sys/Perl6/dev
>  git clone git://github.com/rakudo/rakudo.git
>  cd rakudo
>  git pull
>  perl Configure.pl --gen-moar --gen-nqp --backends=moar
>  make
> 
>  pwd
>  /home/doom/End/Sys/Perl6/dev/rakudo
> 
>  ./perl6 --version
> 
> But actually, there is no ./perl6 here.  And I don't see a
> "Generating" message for it:
> 
>  [...]
>  +++ Generating   rakudo-gdb-m
>  +++ Generating   rakudo-lldb-m
>  +++ Generating   rakudo-valgrind-m
>  +++ Generating   perl6-gdb-m
>  +++ Generating   perl6-lldb-m
>  +++ Generating   perl6-valgrind-m
> 
> Trying something that looks close, I just get this an error:
> 
>  ./perl6-gdb-m --version
> 
>  Unhandled exception: While looking for
> '/home/doom/End/Sys/Perl6/dev/rakudo/perl6.moarvm': no such file or
> directory
> 
> That file doesn't exist... so despite the --gen-moar option, it
> wasn't created?
> 
>  sudo updatedb
>  locate perl6.moarvm
> 
>  /home/doom/End/Sys/Perl6/rakudo-star-2019.03/rakudo/perl6.moarvm
>  /home/doom/End/Sys/Perl6/rakudo-star-2020.01/rakudo/perl6.moarvm
>  /root/rakudo/share/perl6/runtime/perl6.moarvm
> 
> The INSTALL.txt describes a --with-moar option, so I thought I
> might try building with an existing moarvm:
> 
>  cd /home/doom/End/Sys/Perl6/dev/rakudo
>  perl Configure.pl
> --with-moar=/home/doom/End/Sys/Perl6/rakudo-star-2020.01/rakudo/perl6.moarvm
> --gen-nqp --backends=moar
>  make
> 
> But that just errors out:
> 
>  Unknown option: with-moar


Re: the state of the build and install instructions

2020-05-14 Thread Will Coleda
I think it's out of date, yes.

Need a "make install" to install the binaries (by default to
./install). Previous versions of the build left a copy in ./perl6 but
that hasn't been the case for a while. Thanks for the ping, we'll open
a ticket to get INSTALL.txt updated.

On Thu, May 14, 2020 at 4:20 PM Elizabeth Mattijsen  wrote:
>
> Personally, I always do:
>
> perl Configure.pl --gen-moar --gen-nqp --make-install
>
> > On 14 May 2020, at 22:08, Joseph Brenner  wrote:
> >
> > I'm having trouble doing a build of raku from github.  Could it
> > be the INSTALL.txt file is out-of-date?
> >
> > I was trying to build a "bleeding edge" Raku using the
> > instructions here:
> >
> >  https://github.com/rakudo/rakudo/blob/master/INSTALL.txt
> >
> > So I thought I'd just need to do this:
> >
> >  cd /home/doom/End/Sys/Perl6/dev
> >  git clone git://github.com/rakudo/rakudo.git
> >  cd rakudo
> >  git pull
> >  perl Configure.pl --gen-moar --gen-nqp --backends=moar
> >  make
> >
> >  pwd
> >  /home/doom/End/Sys/Perl6/dev/rakudo
> >
> >  ./perl6 --version
> >
> > But actually, there is no ./perl6 here.  And I don't see a
> > "Generating" message for it:
> >
> >  [...]
> >  +++ Generating   rakudo-gdb-m
> >  +++ Generating   rakudo-lldb-m
> >  +++ Generating   rakudo-valgrind-m
> >  +++ Generating   perl6-gdb-m
> >  +++ Generating   perl6-lldb-m
> >  +++ Generating   perl6-valgrind-m
> >
> > Trying something that looks close, I just get this an error:
> >
> >  ./perl6-gdb-m --version
> >
> >  Unhandled exception: While looking for
> > '/home/doom/End/Sys/Perl6/dev/rakudo/perl6.moarvm': no such file or
> > directory
> >
> > That file doesn't exist... so despite the --gen-moar option, it
> > wasn't created?
> >
> >  sudo updatedb
> >  locate perl6.moarvm
> >
> >  /home/doom/End/Sys/Perl6/rakudo-star-2019.03/rakudo/perl6.moarvm
> >  /home/doom/End/Sys/Perl6/rakudo-star-2020.01/rakudo/perl6.moarvm
> >  /root/rakudo/share/perl6/runtime/perl6.moarvm
> >
> > The INSTALL.txt describes a --with-moar option, so I thought I
> > might try building with an existing moarvm:
> >
> >  cd /home/doom/End/Sys/Perl6/dev/rakudo
> >  perl Configure.pl
> > --with-moar=/home/doom/End/Sys/Perl6/rakudo-star-2020.01/rakudo/perl6.moarvm
> > --gen-nqp --backends=moar
> >  make
> >
> > But that just errors out:
> >
> >  Unknown option: with-moar


Re: the state of the build and install instructions

2020-05-14 Thread Parrot Raiser
Working with p.spek p.s...@tyil.nl on a revised Rakudo Star we
encountered a problem with the Configure step; it might be worthwhile
contacting him to coordinate any changes.

On 5/14/20, Will Coleda  wrote:
> I think it's out of date, yes.
>
> Need a "make install" to install the binaries (by default to
> ./install). Previous versions of the build left a copy in ./perl6 but
> that hasn't been the case for a while. Thanks for the ping, we'll open
> a ticket to get INSTALL.txt updated.
>
> On Thu, May 14, 2020 at 4:20 PM Elizabeth Mattijsen  wrote:
>>
>> Personally, I always do:
>>
>> perl Configure.pl --gen-moar --gen-nqp --make-install
>>
>> > On 14 May 2020, at 22:08, Joseph Brenner  wrote:
>> >
>> > I'm having trouble doing a build of raku from github.  Could it
>> > be the INSTALL.txt file is out-of-date?
>> >
>> > I was trying to build a "bleeding edge" Raku using the
>> > instructions here:
>> >
>> >  https://github.com/rakudo/rakudo/blob/master/INSTALL.txt
>> >
>> > So I thought I'd just need to do this:
>> >
>> >  cd /home/doom/End/Sys/Perl6/dev
>> >  git clone git://github.com/rakudo/rakudo.git
>> >  cd rakudo
>> >  git pull
>> >  perl Configure.pl --gen-moar --gen-nqp --backends=moar
>> >  make
>> >
>> >  pwd
>> >  /home/doom/End/Sys/Perl6/dev/rakudo
>> >
>> >  ./perl6 --version
>> >
>> > But actually, there is no ./perl6 here.  And I don't see a
>> > "Generating" message for it:
>> >
>> >  [...]
>> >  +++ Generating   rakudo-gdb-m
>> >  +++ Generating   rakudo-lldb-m
>> >  +++ Generating   rakudo-valgrind-m
>> >  +++ Generating   perl6-gdb-m
>> >  +++ Generating   perl6-lldb-m
>> >  +++ Generating   perl6-valgrind-m
>> >
>> > Trying something that looks close, I just get this an error:
>> >
>> >  ./perl6-gdb-m --version
>> >
>> >  Unhandled exception: While looking for
>> > '/home/doom/End/Sys/Perl6/dev/rakudo/perl6.moarvm': no such file or
>> > directory
>> >
>> > That file doesn't exist... so despite the --gen-moar option, it
>> > wasn't created?
>> >
>> >  sudo updatedb
>> >  locate perl6.moarvm
>> >
>> >  /home/doom/End/Sys/Perl6/rakudo-star-2019.03/rakudo/perl6.moarvm
>> >  /home/doom/End/Sys/Perl6/rakudo-star-2020.01/rakudo/perl6.moarvm
>> >  /root/rakudo/share/perl6/runtime/perl6.moarvm
>> >
>> > The INSTALL.txt describes a --with-moar option, so I thought I
>> > might try building with an existing moarvm:
>> >
>> >  cd /home/doom/End/Sys/Perl6/dev/rakudo
>> >  perl Configure.pl
>> > --with-moar=/home/doom/End/Sys/Perl6/rakudo-star-2020.01/rakudo/perl6.moarvm
>> > --gen-nqp --backends=moar
>> >  make
>> >
>> > But that just errors out:
>> >
>> >  Unknown option: with-moar
>


Re: the state of the build and install instructions

2020-05-14 Thread Will Coleda
https://github.com/rakudo/rakudo/issues/3693

On Thu, May 14, 2020 at 5:11 PM Parrot Raiser <1parr...@gmail.com> wrote:
>
> Working with p.spek p.s...@tyil.nl on a revised Rakudo Star we
> encountered a problem with the Configure step; it might be worthwhile
> contacting him to coordinate any changes.
>
> On 5/14/20, Will Coleda  wrote:
> > I think it's out of date, yes.
> >
> > Need a "make install" to install the binaries (by default to
> > ./install). Previous versions of the build left a copy in ./perl6 but
> > that hasn't been the case for a while. Thanks for the ping, we'll open
> > a ticket to get INSTALL.txt updated.
> >
> > On Thu, May 14, 2020 at 4:20 PM Elizabeth Mattijsen  wrote:
> >>
> >> Personally, I always do:
> >>
> >> perl Configure.pl --gen-moar --gen-nqp --make-install
> >>
> >> > On 14 May 2020, at 22:08, Joseph Brenner  wrote:
> >> >
> >> > I'm having trouble doing a build of raku from github.  Could it
> >> > be the INSTALL.txt file is out-of-date?
> >> >
> >> > I was trying to build a "bleeding edge" Raku using the
> >> > instructions here:
> >> >
> >> >  https://github.com/rakudo/rakudo/blob/master/INSTALL.txt
> >> >
> >> > So I thought I'd just need to do this:
> >> >
> >> >  cd /home/doom/End/Sys/Perl6/dev
> >> >  git clone git://github.com/rakudo/rakudo.git
> >> >  cd rakudo
> >> >  git pull
> >> >  perl Configure.pl --gen-moar --gen-nqp --backends=moar
> >> >  make
> >> >
> >> >  pwd
> >> >  /home/doom/End/Sys/Perl6/dev/rakudo
> >> >
> >> >  ./perl6 --version
> >> >
> >> > But actually, there is no ./perl6 here.  And I don't see a
> >> > "Generating" message for it:
> >> >
> >> >  [...]
> >> >  +++ Generating   rakudo-gdb-m
> >> >  +++ Generating   rakudo-lldb-m
> >> >  +++ Generating   rakudo-valgrind-m
> >> >  +++ Generating   perl6-gdb-m
> >> >  +++ Generating   perl6-lldb-m
> >> >  +++ Generating   perl6-valgrind-m
> >> >
> >> > Trying something that looks close, I just get this an error:
> >> >
> >> >  ./perl6-gdb-m --version
> >> >
> >> >  Unhandled exception: While looking for
> >> > '/home/doom/End/Sys/Perl6/dev/rakudo/perl6.moarvm': no such file or
> >> > directory
> >> >
> >> > That file doesn't exist... so despite the --gen-moar option, it
> >> > wasn't created?
> >> >
> >> >  sudo updatedb
> >> >  locate perl6.moarvm
> >> >
> >> >  /home/doom/End/Sys/Perl6/rakudo-star-2019.03/rakudo/perl6.moarvm
> >> >  /home/doom/End/Sys/Perl6/rakudo-star-2020.01/rakudo/perl6.moarvm
> >> >  /root/rakudo/share/perl6/runtime/perl6.moarvm
> >> >
> >> > The INSTALL.txt describes a --with-moar option, so I thought I
> >> > might try building with an existing moarvm:
> >> >
> >> >  cd /home/doom/End/Sys/Perl6/dev/rakudo
> >> >  perl Configure.pl
> >> > --with-moar=/home/doom/End/Sys/Perl6/rakudo-star-2020.01/rakudo/perl6.moarvm
> >> > --gen-nqp --backends=moar
> >> >  make
> >> >
> >> > But that just errors out:
> >> >
> >> >  Unknown option: with-moar
> >


Re: sqrt and Buf question

2020-05-14 Thread ToddAndMargo via perl6-users

On 2020-05-14 08:13, Bruce Gray wrote:




On May 14, 2020, at 7:27 AM, ToddAndMargo via perl6-users 
 wrote:

Hi All,

1) how do I get 40 or more digits out of sqrt?


—snip—

Use an Integer Root algorithm on ($number-you-want-the-root-of * 100 ** 
$number-of-digits-you-want), then shift the decimal point of the result.

Exact code here:
https://rosettacode.org/wiki/Integer_roots#Raku

—
Hope this helps,
Bruce Gray (“Util” on RosettaCode, too)



sub integer_root ( Int $p where * >= 2, Int $n --> Int ) {
my Int $d = $p - 1;
my $guess = 10**($n.chars div $p);
my $iterator = { ( $d * $^x   +   $n div ($^x ** $d) ) div $p };
my $endpoint = {  $^x  ** $p <= $n
 and ($^x + 1) ** $p >  $n };
min (+$guess, $iterator ... $endpoint)[*-1, *-2];
}

say integer_root( 2, 2 * 100 ** 2000 );



It does help!  I can reproduce noise to my heart's content!

Questions:

what is $p in the sub declaration? Is it always a 2?

what is `$n` in the sub declaration?  Looks like
the third set of numbers is the digits I want.

what is the second number (100)?

And what is `2 * 100 ** 2000 `?  Is that `(2 x 100)^ 2000`
((2 times 100) to the 2000 power?

> say integer_root( 2, 2 * 100 ** 4 );
14142

> say 3.sqrt
1.7320508075688772

> say integer_root( 2, 3 * 100 ** 16 );
17320508075688772


-T


Re: bash "."?

2020-05-14 Thread ToddAndMargo via perl6-users

On 2020-05-14 08:22, Peter Pentchev wrote:

On Thu, May 14, 2020 at 04:39:18AM -0700, ToddAndMargo via perl6-users wrote:

On 2020-05-13 22:27, Bruce Gray wrote:




On May 13, 2020, at 9:37 PM, ToddAndMargo via perl6-users 
 wrote:

Hi All,

Do we have anything like Bash's "." statement where
we can read in a bunch of values from a .cfg file?
(I think it is called "include", but I am not sure.)

. /etc/sysconfig/network-scripts/ifcfg-br0

which populates these (and other) variables

DEVICE=br0
TYPE=Bridge
ONBOOT=yes
USERCTL=yes
DELAY=0
NM_CONTROLLED=yes
BOOTPROTO=none
PREFIX=24
...

Many thanks,
-T


Hi Todd,

FYI, the `.` Bash command is also called `source`, which is easier to search on 
the Web, and clearer in email:
https://ss64.com/bash/source.html

The closest equivalent in Raku is:
https://docs.raku.org/routine/EVALFILE
, which could be used for config data like so:
$ cat a.dat
$foo = "bar";
$baz = "quxx";

$ perl6 -e 'our ($foo, $baz); EVALFILE "a.dat"; .say for $foo, $baz;'
bar
quxx

, but please do not use it for this purpose.

EVALFILE is in all-caps to show that it might be dangerous and not for general 
use; it is “grep-able evil”, and could eval any valid Raku code, even evil 
things like `run “rm -rf /“`.

IMHO, Bash's `source`-style of loading variables pollutes the main namespace 
and causes hard-to-debug “action at a distance”.
In Raku (or any other dynamic language), the use of some kind of Config module 
is safer and cleaner:
https://modules.raku.org/t/CONFIG
https://github.com/raku-community-modules/perl6-Config-JSON
https://github.com/Skarsnik/perl6-config-simple
https://metacpan.org/pod/Config::Tiny

For example:

$ cat config.json
{
"baz": "quxx",
"foo": "bar”
}
$ perl6 -e 'use Config::JSON; my %c; %c{$_} = jconf($_) for ; say %c{$_} for 
;'
bar
quxx

$ cat b.dat
foo = bar
baz = quxx
$ perl6 -e 'use Config::Tiny:from; my $conf = Config::Tiny.read("b.dat"); .say for 
$conf<_>'
bar
quxx


—
Hope this helps,
Bruce Gray (Util of PerlMonks)



Hi Bruce,

I looked at the first two links above.  Neither showed
the format of the data being read. But you did.  Is
there some reason why the two links did not show the format?


Well, they do both say they read .ini-style files. I think that they
will both be able to read simple key=value files like the network
definition sysconfig ones on RedHat-style systems that you seem to want.
Keep in mind that the shell probably interprets a bit more, so some
configuration-reading modules may e.g. return the quotes around the
value or something like that; take them for a spin and see.
Also, it's almost certain that these modules will not be able to help if
the files that you read make use of the fact that the shell performs
variable expansion: they will not be able to expand other variables in
lines like:

KEYFILE="/etc/keys/$HOSTNAME.key"

or something like that.

If you come across files like that, you may have to write your own
parser.

For some general information on ini-like files, see
https://en.wikipedia.org/wiki/INI_file

G'luck,
Peter



Hi Peter,

That was extremely helpful!  I never realized INI
files were standardized.

I will be playing with them shortly.  I really want
to see how CONFIG handles section titles.

Thank you!

-T


Re: sqrt and Buf question

2020-05-14 Thread ToddAndMargo via perl6-users

On 2020-05-14 05:51, Tobias Boege wrote:

On Thu, 14 May 2020, ToddAndMargo via perl6-users wrote:

Hi All,

1) how do I get 40 or more digits out of sqrt?



Meaningful digits? Not possible as sqrt uses limited precision. I think
the IEEE 754 doubles that I would suspect to be used internally are capped
way below 40 significant decimal digits.


2) how to I assist those bytes to a 40 (or more)
byte long Buf?

This obviously does not work:

my Num $x = 3.sqrt; my Buf $y = Buf.new($x)

Type check failed in initializing element #0 to Buf; expected uint8 but got
Num (1.7320508075688772e0)
   in block  at  line 1



You can convert the Num to a string and put that string into a Buf:

   Buf.new(3.sqrt.Str.encode)

That's what I'd do without any clue at all about who is supposed to use
this Buf. At least the buffer is about as long as the number is decimal
digits, which seems to be what you wanted?

Regards,
Tobias



Using Peter's code:

Buf.new(integer_root( 2, 3 * 100 ** 39 ).Str.encode)
Buf:0x<31 37 33 32 30 35 30 38 30 37 35 36 38 38 37 37 32 39 33 35 32 37 
34 34 36 33 34 31 35 30 35 38 37 32 33 36 36 39 34 32>


LAT AND LOTS OF repeatable NOISE!


--
~~
Computers are like air conditioners.
They malfunction when you open windows
~~


Re: How do I handle Getopt::Long stray entries?

2020-05-14 Thread ToddAndMargo via perl6-users

On 2020-05-11 21:19, Peter Pentchev wrote:

#!/usr/bin/env raku

use v6.d;

use Getopt::Long;

sub cmd_install($cmd, Array[Str] :$enablerepo = [], Bool :$y = False, *@rest 
--> int)
{
say 'install';
dd $cmd;
dd @rest;
dd $enablerepo;
dd $y;
return 0;
}

sub cmd_list($cmd, Array[Str] :$enablerepo = [], *@rest --> int)
{
say 'list';
dd $cmd;
dd @rest;
dd $enablerepo;
return 42;
}

my %HANDLERS = (
install => &cmd_install,

# "list" doesn't care about the "-y" parameter, so skip it
list => -> $cmd, :$enablerepo = [], :$y = False, *@rest --> int {
cmd_list $cmd, :$enablerepo, |@rest
},
);

sub note-fatal(Str:D $msg)
{
$msg.note;
exit 1;
}

{
my $opts = get-options(
"enablerepo=s@",
"y",
);
CATCH { when Getopt::Long::Exception { .message.note; exit 1 } };
dd $opts;

note-fatal 'No command specified' unless $opts.elems;
my $cmd = $opts[0];
my $handler = %HANDLERS{$cmd};
note-fatal "Unknown command '$cmd'" unless $handler;
exit $handler(|$opts);
}



How do I use it?  Where are the options declared?

$ GetOptLongTest2.pl6
Capture $opts = \()
No command specified

$ GetOptLongTest2.pl6 --help
Unknown option help





--
~~
Computers are like air conditioners.
They malfunction when you open windows
~~


RFE: ini documentation

2020-05-14 Thread ToddAndMargo via perl6-compiler

Dear Config,

https://modules.raku.org/dist/Config:cpan:TYIL

Would you please consider add the following reference to your
web page:

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

It gives a wonderful description of INI files.  And
there are folks out there that do not realize that INI
files are standardized or how to write them

Many thanks,
-T


Re: How do I handle Getopt::Long stray entries?

2020-05-14 Thread Peter Pentchev
On Thu, May 14, 2020 at 06:46:17PM -0700, ToddAndMargo via perl6-users wrote:
> On 2020-05-11 21:19, Peter Pentchev wrote:
> > #!/usr/bin/env raku
> > 
> > use v6.d;
> > 
> > use Getopt::Long;
> > 
> > sub cmd_install($cmd, Array[Str] :$enablerepo = [], Bool :$y = False, 
> > *@rest --> int)
> > {
> > say 'install';
> > dd $cmd;
> > dd @rest;
> > dd $enablerepo;
> > dd $y;
> > return 0;
> > }
> > 
> > sub cmd_list($cmd, Array[Str] :$enablerepo = [], *@rest --> int)
> > {
> > say 'list';
> > dd $cmd;
> > dd @rest;
> > dd $enablerepo;
> > return 42;
> > }
> > 
> > my %HANDLERS = (
> > install => &cmd_install,
> > 
> > # "list" doesn't care about the "-y" parameter, so skip it
> > list => -> $cmd, :$enablerepo = [], :$y = False, *@rest --> int {
> > cmd_list $cmd, :$enablerepo, |@rest
> > },
> > );
> > 
> > sub note-fatal(Str:D $msg)
> > {
> > $msg.note;
> > exit 1;
> > }
> > 
> > {
> > my $opts = get-options(
> > "enablerepo=s@",
> > "y",
> > );
> > CATCH { when Getopt::Long::Exception { .message.note; exit 1 } };
> > dd $opts;
> > 
> > note-fatal 'No command specified' unless $opts.elems;
> > my $cmd = $opts[0];
> > my $handler = %HANDLERS{$cmd};
> > note-fatal "Unknown command '$cmd'" unless $handler;
> > exit $handler(|$opts);
> > }
> 
> 
> How do I use it?  Where are the options declared?

What does https://modules.raku.org/dist/Getopt::Long:cpan:LEONT (the
link you posted at the top of your first message) say in the "SYNOPSIS"
section?

G'luck,
Peter

-- 
Peter Pentchev  r...@ringlet.net r...@debian.org p...@storpool.com
PGP key:http://people.FreeBSD.org/~roam/roam.key.asc
Key fingerprint 2EE7 A7A5 17FC 124C F115  C354 651E EFB0 2527 DF13


signature.asc
Description: PGP signature


Re: How do I handle Getopt::Long stray entries?

2020-05-14 Thread Peter Pentchev
On Fri, May 15, 2020 at 07:57:47AM +0300, Peter Pentchev wrote:
> On Thu, May 14, 2020 at 06:46:17PM -0700, ToddAndMargo via perl6-users wrote:
> > On 2020-05-11 21:19, Peter Pentchev wrote:
> > > #!/usr/bin/env raku
> > > 
> > > use v6.d;
> > > 
> > > use Getopt::Long;
> > > 
> > > sub cmd_install($cmd, Array[Str] :$enablerepo = [], Bool :$y = False, 
> > > *@rest --> int)
> > > {
> > >   say 'install';
> > >   dd $cmd;
> > >   dd @rest;
> > >   dd $enablerepo;
> > >   dd $y;
> > >   return 0;
> > > }
> > > 
> > > sub cmd_list($cmd, Array[Str] :$enablerepo = [], *@rest --> int)
> > > {
> > >   say 'list';
> > >   dd $cmd;
> > >   dd @rest;
> > >   dd $enablerepo;
> > >   return 42;
> > > }
> > > 
> > > my %HANDLERS = (
> > >   install => &cmd_install,
> > >   
> > >   # "list" doesn't care about the "-y" parameter, so skip it
> > >   list => -> $cmd, :$enablerepo = [], :$y = False, *@rest --> int {
> > >   cmd_list $cmd, :$enablerepo, |@rest
> > >   },
> > > );
> > > 
> > > sub note-fatal(Str:D $msg)
> > > {
> > >   $msg.note;
> > >   exit 1;
> > > }
> > > 
> > > {
> > >   my $opts = get-options(
> > >   "enablerepo=s@",
> > >   "y",
> > >   );
> > >   CATCH { when Getopt::Long::Exception { .message.note; exit 1 } };
> > >   dd $opts;
> > > 
> > >   note-fatal 'No command specified' unless $opts.elems;
> > >   my $cmd = $opts[0];
> > >   my $handler = %HANDLERS{$cmd};
> > >   note-fatal "Unknown command '$cmd'" unless $handler;
> > >   exit $handler(|$opts);
> > > }
> > 
> > 
> > How do I use it?  Where are the options declared?
> 
> What does https://modules.raku.org/dist/Getopt::Long:cpan:LEONT (the
> link you posted at the top of your first message) say in the "SYNOPSIS"
> section?

Okay, so that might have been something of a trick question, since
it seems that synopsis does not have an example of the Capture-style
invocation[1] :) You may have to actually read the "Simple options" section
below to find out what get-options() returns :)

G'luck,
Peter

[1] https://github.com/Leont/getopt-long6/pull/5

-- 
Peter Pentchev  r...@ringlet.net r...@debian.org p...@storpool.com
PGP key:http://people.FreeBSD.org/~roam/roam.key.asc
Key fingerprint 2EE7 A7A5 17FC 124C F115  C354 651E EFB0 2527 DF13


signature.asc
Description: PGP signature


Re: sqrt and Buf question

2020-05-14 Thread Peter Pentchev
On Thu, May 14, 2020 at 02:36:30PM -0700, ToddAndMargo via perl6-users wrote:
> On 2020-05-14 08:13, Bruce Gray wrote:
> > 
> > 
> > > On May 14, 2020, at 7:27 AM, ToddAndMargo via perl6-users 
> > >  wrote:
> > > 
> > > Hi All,
> > > 
> > > 1) how do I get 40 or more digits out of sqrt?
> > 
> > —snip—
> > 
> > Use an Integer Root algorithm on ($number-you-want-the-root-of * 100 ** 
> > $number-of-digits-you-want), then shift the decimal point of the result.
> > 
> > Exact code here:
> > https://rosettacode.org/wiki/Integer_roots#Raku
> > 
> > —
> > Hope this helps,
> > Bruce Gray (“Util” on RosettaCode, too)
> 
> 
> sub integer_root ( Int $p where * >= 2, Int $n --> Int ) {
> my Int $d = $p - 1;
> my $guess = 10**($n.chars div $p);
> my $iterator = { ( $d * $^x   +   $n div ($^x ** $d) ) div $p };
> my $endpoint = {  $^x  ** $p <= $n
>  and ($^x + 1) ** $p >  $n };
> min (+$guess, $iterator ... $endpoint)[*-1, *-2];
> }
> 
> say integer_root( 2, 2 * 100 ** 2000 );
> 
> 
> 
> It does help!  I can reproduce noise to my heart's content!
> 
> Questions:
> 
> what is $p in the sub declaration? Is it always a 2?

https://rosettacode.org/wiki/Integer_roots

> what is `$n` in the sub declaration?  Looks like
> the third set of numbers is the digits I want.

https://rosettacode.org/wiki/Integer_roots

> what is the second number (100)?

https://rosettacode.org/wiki/Integer_roots

> And what is `2 * 100 ** 2000 `?  Is that `(2 x 100)^ 2000`
> ((2 times 100) to the 2000 power?

Point 1: exponentiation has a higher priority than multiplication.

Point 2: https://rosettacode.org/wiki/Integer_roots

G'luck,
Peter

-- 
Peter Pentchev  r...@ringlet.net r...@debian.org p...@storpool.com
PGP key:http://people.FreeBSD.org/~roam/roam.key.asc
Key fingerprint 2EE7 A7A5 17FC 124C F115  C354 651E EFB0 2527 DF13


signature.asc
Description: PGP signature