Re: Raku is removed from Debian

2024-09-04 Thread Timo Paulssen via perl6-users

Hi Dominique,

first of all, thank you for bringing this to our attention, and all the 
time you've spent on maintaining the Raku packages and debhelpers!


Coke and myself have signed up to salsa with the user names timotimo and 
coke respectively.


We* would appreciate if you give us access to the perl6-team group and 
what else we need to start working on the packages. For example, I have 
a patch that should make moarvm build again, and I would like to get the 
salsa ci/cd pipeline configured for at least moarvm as well.


We can probably find out what the first few steps are going to be from 
the "getting started contributing to debian" documentation and asking on 
#debian-mentors. If you want to point some stuff out or give us a little 
tour right away, that would also be cool of course.


Feel free to reach out on IRC if you have the time, or via mail is fine 
as well, of course.


Hopefully we can have some packages for you to "sponsor" soon :)

Kind Regards
  - Timo

* I can only speak for myself, I'm just assuming Will is fine with my 
claims / suggestions




Re: my zenity adventure

2023-03-26 Thread Timo Paulssen via perl6-users
Hey Todd,

Its likely that because you are using the shell sub the < and > characters have 
been interpreted by the shell to mean redirection. Check for odd files in your 
working directory that have the text you saw zenity output in them, and perhaps 
there is even a file with heat the capital letter S.

When you are putting together strings like that to put into a shell call, you 
are dancing on very thin ice wearing Doc Martens and a backpack filled to point 
of bursting with tungsten bars while balancing buckets of boiling water on the 
tip of your nose and also for some reason there are sharks below the ice ...

Also, sprintf should pass \n through as-is Anne it likely got interpreted later 
on by some other part of the process.

Be extremely weary of your variables containing double quotes in them, and 
slightly weary of single quotes.

Hope that helps you find out what exactly is going on

On 27 March 2023 01:35:39 CEST, ToddAndMargo via perl6-users 
 wrote:
>Hi All,
>
>Fedora 36
>zenity-3.43.0-3.fc37.x86_64
>rakudo-pkg-2022.7.0-03.x86_64
>
>
>My adventure with a zenity call!
>
>I just worked around a problem with a call to zenity:
>
>Note: zenity can not resolve Raku's "\n", so you have to
>preformat the "text" field with "sprintf".
>
>
>$NotifyStr = sprintf "\nStarting $ProgramName\n\nTakes about $Timeout seconds 
>to finish compiling\nMozilla Mirror = <$MozillaMirror>\n";
>
>The above gave me "All updates are complete" in the text
>field. H.  I do goof a lot of stuff up (who me)
>but I am "pretty sure" I did not tell zenity that.
>I did a direct print of $NotifyStr to the command
>line to make sure anyway.
>
>
>I traced it down to the "<" and ">".
>
>Separating the "<" and ">" with `~ ">" ~` in the string
>did not help.
>
>
>Taking out the "<" and ">" got rid of the problem.  Not
>as pretty, but it will due.
>
>$NotifyStr = sprintf "\nStarting $ProgramName\n\nTakes about $Timeout seconds 
>to finish compiling\nMozilla Mirror = $MozillaMirror\n";
>
>
>The zenity call:
>
>shell "zenity --info --title \"$Title\" --text \"$NotifyStr\" --width=220 
>--timeout=$Timeout &";
>
>
>I was unable to reproduce this from a direct call
>to zenity from the command line, so it was probably
>something that happened between Raku and zenity.
>
>Of interest, on the direct call "\n" came out as an "S".
>
>
>Hope this helps someone else.
>
>-T
>

-- 
Sent from my Android device with K-9 Mail. Please excuse my brevity.

Re: the MAIN questions

2021-12-29 Thread Timo Paulssen

Hey marc,

since the default value for a "Bool" is an undefined Bool, you can just 
boolify whatever happens to be in :$diff, which will be False for "no 
flag passed" or True for "flag passed and was True".


Hope that helps
  - Timo

On 29/12/2021 13:00, Marc Chantreux wrote:

hello rakoons,

I have a script named fixlines which is basically

sub fixline (Str $line) { ...  }
say fixline $_ for lines;

This is far enough for personal usage but i would like to release it
so i need a decent -h to be implemented and basically should look
like

Usage:
   fixlines [--test] 

to do so, my

say fixline $_ for lines;

becomes

sub MAIN (
 #| don't fix for real, just show the diff
 Bool :$diff = False,
 #| input files (stdin by default or explicit '-' in the list)
 *@files
 ) {
 +@files or @files = ('-');
 my $argfiles = IO::ArgFiles.new(@files);
 .&fixline.say for $argfiles.lines
}

This would be fair enough in any other langages but the whole thing looks
unelegant in a raku code.

So now I have 2 questions:

* I'm pretty sure i saw something like :!$test to express Bool :$test = False.
   Did i just dreamed about it ?
* more importantly, is the a better choice than

 +@files or @files = ('-');
 my $argfiles = IO::ArgFiles.new(@files);
 .&fixline.say for $argfiles.lines

I saw %*SUB-MAIN-OPTS in the documentation and was wondering if something like

 %*SUB-MAIN-OPTS= my @files; #= input files, stdin if none

could be achievable by a module MAIN::UnixFilter i could put on Raku.land?

Regards,
marc


Re: dimensions in a multidimensional array

2021-02-05 Thread Timo Paulssen
Shaped Arrays and Native Shaped Arrays already use one contiguous blob 
to store all their data; in Shaped Arrays that's an array of pointers to 
the stored objects, in a Native Shaped Array it'll be like a big array 
of 32bit integers or whatever you have.


Regards
  - Timo

On 05/02/2021 16:48, yary wrote:
This got me interested in 
https://docs.raku.org/language/list#index-entry-Shaped_arrays 



and I find myself wanting to implement a role "Shaped" and applying it 
to List, for an immutable shaped list, whose implementation packs its 
elements for o(1) lookup... on my ever-lengthening to-do list


-y


On Fri, Feb 5, 2021 at 10:06 AM Elizabeth Mattijsen > wrote:


> On 5 Feb 2021, at 15:49, Theo van den Heuvel
mailto:vdheu...@heuvelhlt.nl>> wrote:
> I cannot seem to find an idiomatic way to get the dimensions of
a multidimensional array,
> other than by looking at the size of the first row and column,
with @m[0;*].elems and @m[*;0].elems.
> Am I missing something in the docs?

If it's a shaped multidimensional array, you can call the .shape
method

    my @a[3;3;3];
    dd @a.shape;   # (3,3,3)

If it is not, then your workaround appears the way to do it.



Re: msi of 2020.10?

2020-12-02 Thread Timo Paulssen

Hi todd,

please give this a try:

    https://setxkbmap.de/rakudo-2020-11-windows-32bit.zip

good luck!

btw I forgot you wanted 2020.10 so I just made 2020.11. And I assumed 
you wanted a 32bit build, since that was what I remember you wanted last 
time?


HTH
  - Timo

On 02/12/2020 22:39, ToddAndMargo via perl6-users wrote:

Any Raku developer reading this,

May we please have an msi of 2020.10?

2020.10 msi?
https://github.com/rakudo/rakudo/issues/4001

Many thanks,
-T


Re: Missing NullPointerException

2020-12-02 Thread Timo Paulssen

On 02/12/2020 17:18, William Michels via perl6-users wrote:
Does this explain why calling "dd" in the REPL returns Nil on the 
final line, but Nil doesn't seem to be returned on the final line when 
using "dd" from the Bash shell?


user@mbook:~$ raku -e 'dd "0123456789";'
"0123456789"
user@mbook:~$ raku
Welcome to 𝐑𝐚𝐤𝐮𝐝𝐨™ v2020.10.
Implementing the 𝐑𝐚𝐤𝐮™ programming language v6.d.
Built on MoarVM version 2020.10.

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


To exit type 'exit' or '^D'
> dd "0123456789"
"0123456789"
Nil
>



This difference is just from the REPL printing out the return value of 
each line, which doesn't happen in script files or with the -e flag




Re: Metamodel parent and return values ...

2020-10-30 Thread Timo Paulssen

On 30/10/2020 07:58, Paul Procacci wrote:

Here is what I have ... trimmed.

#
use JSON::Pretty;
use Staticish;

unit class MyClass is Static;

method client(::?CLASS:D: Str:D $service! --> MyClass)
{
        my %data := from-json %?RESOURCES{$service}.slurp;
        my $type = Metamodel::ClassHOW.new_type(
                name => $service,
                ver => v0.0.1,
                auth => 'github:me'
        );

        $type.HOW.add_parent($type, 'MyClass');
        $type.HOW.compose($type);
        $type.new;
}
#



Hi Paul,

I think when you're passing a string to add_parent, you're actually 
setting the class Str as the parent. raku will not go looking for a 
class with that name. Instead, it expects you to pass the actual type 
object.


Hope that helps!
  - Timo


Re: Language Design: 'special casing' of split()? (i.e. .split performs concomitant .join? )

2020-10-10 Thread Timo Paulssen
On 10/10/2020 23:21, William Michels via perl6-users wrote:
> So I guess the first question I have is whether the 'auto-joining' of
> array elements is specc'ed or not.
>
> What you seem to be saying is that when calling a function on an
> array, the first response is for Raku to call something similar to
> 'cat' on the array, then proceed to process the function call. As it
> is my understanding that Raku incorporates a lot of different
> programming paradigms (imperative, object-oriented, functional, etc.),
> I'm not sure where this behavior falls on the 'paradigm ladder'.

Hi Bill,

the auto-joining of an array is a property of the split method, or more
precisely, a result of split coming from Str.

Cool has many methods and is in many things.

You can call .split on Num or Rat, so 0.123451234512345.split("5") would
give you strings, because split stringifies first.

Conversely, .join is "a listy cool method" (i just made that up) so what
you call it on will be treated as if it were an array. "hello".join("X")
will pretend you passed ["hello"] and just result in "hello" again.

Trigonometric methods like sin, cos, tan, are all "numerical cool
methods" so the first thing they do is coerce to Numeric, that's why
"99".tan.say gives you roughly -25.1.

Please check out the table near the beginning of this documentation page:

    https://docs.raku.org/type/Cool

hope that makes things more clear
  - Timo


Re: zef: too many files in ~/.raku/short

2020-08-08 Thread Timo Paulssen
Hi Fernando,

do you happen to have the exact error message? The simplest search
through the zef source didn't find anything related, so perhaps it was
actually "too many open files" caused by a too-low limit on open file
descriptors?

`ulimit -a` on my system gives me `Maximum number of open file
descriptors (-n) 1048576` because i have set it to "a very high value"
at some point in the past in /etc/security/limits.conf, but some systems
have it at an obnoxiously low number.

Obviously we don't want zef to open billions of file descriptors just to
go through a directory or something, so tracking that down further could
be interesting if that is the case.

HTH
  - Timo

On 01/08/2020 22:46, Fernando Santagata wrote:
> Hello,
>
> I found out that on my system at a certain point zef was unable to
> read the content of ~/.raku/short and because of that to install any
> other module.
> According to zef there were too many files in that directory and
> indeed there were a lot of subdirectories.
>
> I don't know what happened, because I try to keep my installation lean
> and I uninstall old versions of all the modules that I update.
>
> Is it possible that zef failed to update that directory content when,
> I don't know, a module fails to install or something like that,
> leaving behind unused directories?
> Has that happened to anyone else?
>
> -- 
> Fernando Santagata


Re: Raku version of "The top 10 tricks of Perl one-liners" ?!?

2020-07-22 Thread Timo Paulssen
Try it with a very filled folder, though. I would expect the majority of
the time spent is setup and actually going through the lines themselves
isn't very slow.

On 22/07/2020 22:31, Aureliano Guedes wrote:
> That is a little bit disappointing:
>
> $ time ls -l | perl -lane 'print "$F[7] $F[1]"' > /dev/null
>
> real 0m0.008s
> user 0m0.013s
> sys 0m0.000s
>
> $ time ls -l | raku -ne 'say "$_[7] $_[1]" given .words' > /dev/null
> Use of Nil in string context
>   in block  at -e line 1
>
> real 0m0.302s
> user 0m0.370s
> sys 0m0.060s 
>
>
> The delay is so long that I wouldn't use that in a very filled folder.
> Perhaps I know, it will be improved (I hope).   
>
> On Wed, Jul 22, 2020 at 4:21 PM Larry Wall  > wrote:
>
> On Sun, Jul 19, 2020 at 09:38:31PM -0700, William Michels via
> perl6-users wrote:
> : Hello,
> :
> : I ran across this 2010 Perl(5) article on the Oracle Linux Blog:
> :
> : "The top 10 tricks of Perl one-liners"
> :
> https://blogs.oracle.com/linux/the-top-10-tricks-of-perl-one-liners-v2
> :
> : Q1. Now that it's a decade later--and Raku (née Perl6) has hit the
> : scene--can someone translate the 'top ten tricks' in the blog
> article
> : above into Raku?
> :
> : Q2. Are many of the ten Perl(5) one-liner 'tricks' unnecessary
> in Raku
> : (better defaults, more regularized regexes, etc.)?
> :
> : Best, Bill.
>
> Yes, and yes.  :-)
>
> More specificially, here's my take.
>
> >   Trick #1: -l
> >
> >        Smart newline processing. Normally, perl hands you entire
> lines,
> >        including a trailing newline. With -l, it will strip the
> trailing
> >        newline off of any lines read, and automatically add a
> newline to
> >        anything you print (including via -p).
> >
> >        Suppose I wanted to strip trailing whitespace from a
> file. I might
> >        naïvely try something like
> >
> >        perl -pe 's/\s*$//'
> >
> >        The problem, however, is that the line ends with "\n",
> which is
> >        whitespace, and so that snippet will also remove all
> newlines from
> >        my file! -l solves the problem, by pulling off the
> newline before
> >        handing my script the line, and then tacking a new one on
> afterwards:
> >
> >        perl -lpe 's/\s*$//'
>
> This trick is not needed in Raku, since newlines are stripped by
> default.  Also,
> there are .trim methods that you can use instead of regex.
>
> >    Trick #2: -0
> >
> >        Occasionally, it's useful to run a script over an entire
> file,
> >        or over larger chunks at once. -0 makes -n and -p feed
> you chunks
> >        split on NULL bytes instead of newlines. This is often
> useful for,
> >        e.g. processing the output of find -print0. Furthermore,
> perl -0777
> >        makes perl not do any splitting, and pass entire files to
> your script
> >        in $_.
> >
> >        find . -name '*~' -print0 | perl -0ne unlink
> >
> >        Could be used to delete all ~-files in a directory tree,
> without
> >        having to remember how xargs works.
>
> The key word above is "occasionally", so most of these seldom-used
> switches are gone.
> Also, most of their functions are really easy to do from inside
> the language.
> So these days dividing a file by null chars would typicaly be
> handled with:
>
>     for slurp.split("\0") { ... }
>
> >    Trick #3: -i
> >
> >        -i tells perl to operate on files in-place. If you use -n
> or -p with
> >        -i, and you pass perl filenames on the command-line, perl
> will run
> >        your script on those files, and then replace their
> contents with the
> >        output. -i optionally accepts an backup suffix as
> argument; Perl will
> >        write backup copies of edited files to names with that
> suffix added.
> >
> >        perl -i.bak -ne 'print unless /^#/' script.sh
> >
> >        Would strip all whole-line commands from script.sh, but
> leave a copy
> >        of the original in script.sh.bak.
>
> I'm not aware of a direct replacement for this in Raku.  Perl has
> to be
> better at something...
>
> >    Trick #4: The .. operator
> >
> >        Perl's .. operator is a stateful operator -- it remembers
> state
> >        between evaluations. As long as its left operand is
> false, it returns
> >        false; Once the left hand returns true, it starts
> evaluating the
> >        right-hand operand until that becomes true, at which
> point, on
> >        the next iteration it resets to false and starts testing
> the other
> >        operand again.
> >
> >        What does 

Re: I cannot install any lib with Zef

2020-07-21 Thread Timo Paulssen
I would assume the ffi, tommath, atomic_ops, and uv linker flags come
straight from moarvm's linker flags, probably because the build script
of Digest::SHA256::Native uses the flags used to compile moarvm itself.
If you've compiled your moarvm yourself, this is a safe bet; these
libraries are guaranteed to exist unless you've uninstalled them in the
mean time. If you get the stuff from a package instead, that's not quite
as sensible …

On 20/07/2020 20:15, Aureliano Guedes wrote:
> Thanks, I checked it out. 
> now it is working
>
> But now I'm getting issues to install  zef install Jupyter::Kernel,
> the issue itself is on Digest::SHA256::Native:ver<0.03> installation.
>
> $ zef install "Digest::SHA256::Native:ver<0.03>" --force-build
> --force-test
>
> ===> Searching for: Digest::SHA256::Native:ver<0.03>
> ===> Building: Digest::SHA256::Native:ver<0.03>
> [Digest::SHA256::Native] /usr/bin/ld: cannot find -lffi
> [Digest::SHA256::Native] /usr/bin/ld: cannot find -ltommath
> [Digest::SHA256::Native] /usr/bin/ld: cannot find -latomic_ops
> [Digest::SHA256::Native] /usr/bin/ld: cannot find -luv
> [Digest::SHA256::Native] collect2: error: ld returned 1 exit status
> [Digest::SHA256::Native] make: ***
> 
> [/home/acpguedes/.zef/store/Digest-SHA256-Native-0.03.tar.gz/Digest-SHA256-Native-0.03/resources/libraries/libsha256.so]
> Error 1
> [Digest::SHA256::Native] The spawned command 'make' exited
> unsuccessfully (exit code: 2)
> [Digest::SHA256::Native]   in method build at
> 
> /home/acpguedes/.zef/store/Digest-SHA256-Native-0.03.tar.gz/Digest-SHA256-Native-0.03/Build.pm
> line 14
> [Digest::SHA256::Native]   in block  at -e line 1
> ===> Building [FAIL]: Digest::SHA256::Native:ver<0.03>
> [Digest::SHA256::Native] Failed to build, but continuing with
> --force-build
> ===> Testing: Digest::SHA256::Native:ver<0.03>
> [Digest::SHA256::Native] Cannot locate native library
> 
> '/home/acpguedes/.zef/store/Digest-SHA256-Native-0.03.tar.gz/Digest-SHA256-Native-0.03/resources/libraries/libsha256.so':
> 
> /home/acpguedes/.zef/store/Digest-SHA256-Native-0.03.tar.gz/Digest-SHA256-Native-0.03/resources/libraries/libsha256.so:
> cannot open shared object file: No such file or directory
> [Digest::SHA256::Native]   in method setup at
> /usr/lib/perl6/sources/24DD121B5B4774C04A7084827BFAD92199756E03
> (NativeCall) line 290
> [Digest::SHA256::Native]   in method CALL-ME at
> /usr/lib/perl6/sources/24DD121B5B4774C04A7084827BFAD92199756E03
> (NativeCall) line 577
> [Digest::SHA256::Native]   in sub sha256-hex at
> 
> /home/acpguedes/.zef/store/Digest-SHA256-Native-0.03.tar.gz/Digest-SHA256-Native-0.03/lib/Digest/SHA256/Native.pm6
> (Digest::SHA256::Native) line 19
> [Digest::SHA256::Native]   in sub sha256-hex at
> 
> /home/acpguedes/.zef/store/Digest-SHA256-Native-0.03.tar.gz/Digest-SHA256-Native-0.03/lib/Digest/SHA256/Native.pm6
> (Digest::SHA256::Native) line 9
> [Digest::SHA256::Native]   in block  at t/01-basic.t line 6
> [Digest::SHA256::Native] Cannot locate native library
> 
> '/home/acpguedes/.zef/store/Digest-SHA256-Native-0.03.tar.gz/Digest-SHA256-Native-0.03/resources/libraries/libsha256.so':
> 
> /home/acpguedes/.zef/store/Digest-SHA256-Native-0.03.tar.gz/Digest-SHA256-Native-0.03/resources/libraries/libsha256.so:
> cannot open shared object file: No such file or directory
> [Digest::SHA256::Native]   in method setup at
> /usr/lib/perl6/sources/24DD121B5B4774C04A7084827BFAD92199756E03
> (NativeCall) line 290
> [Digest::SHA256::Native]   in method CALL-ME at
> /usr/lib/perl6/sources/24DD121B5B4774C04A7084827BFAD92199756E03
> (NativeCall) line 577
> [Digest::SHA256::Native]   in sub sha256-hex at
> 
> /home/acpguedes/.zef/store/Digest-SHA256-Native-0.03.tar.gz/Digest-SHA256-Native-0.03/lib/Digest/SHA256/Native.pm6
> (Digest::SHA256::Native) line 19
> [Digest::SHA256::Native]   in block  at t/02-blob.t line 7
> [Digest::SHA256::Native] Cannot locate native library
> 
> '/home/acpguedes/.zef/store/Digest-SHA256-Native-0.03.tar.gz/Digest-SHA256-Native-0.03/resources/libraries/libsha256.so':
> 
> /home/acpguedes/.zef/store/Digest-SHA256-Native-0.03.tar.gz/Digest-SHA256-Native-0.03/resources/libraries/libsha256.so:
> cannot open shared object file: No such file or directory
> [Digest::SHA256::Native]   in method setup at
> /usr/lib/perl6/sources/24DD121B5B4774C04A7084827BFAD92199756E03
> (NativeCall) line 290
> [Digest::SHA256::Native]   in method CALL-ME at
> /usr/lib/perl6/sources/24DD121B5B4774C04A7084827BFAD92199756E03
> (NativeCall) line 577
> [Digest::SHA256::Native]   in sub sha256-hex at
> 
> /home/acpguedes/.zef/store/Digest-SHA256-Native-0.03.tar.gz/Digest-SHA256-Native-0.03/lib/Digest/SHA256/Native.pm6
> (Digest::SHA256::Native) line 19
> [Digest::SHA256:

Re: junctions and parenthesis

2020-06-24 Thread Timo Paulssen
On 22/06/2020 20:12, Joseph Brenner wrote:
> > Speculating wildly: could there be a need for a different type of >
function with different precedence?
I would suggest calling .any on the list, that gives you just the tight
preference you want; even if there were no .any method available on the
object you've got, or you want a different function, you can .&mysub

LMKWYT
  - Timo




Re: fill in form

2020-05-13 Thread Timo Paulssen
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

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


Re: fill in form

2020-05-12 Thread Timo Paulssen
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

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


Re: NativeCall questions

2020-05-08 Thread Timo Paulssen
Hi David,

the first thing that catches my eye is that your struct and the class
have the members switched around, so you're already almost guaranteed to
read a bogus pointer when trying to get the data.

Also, please note that returning structs directly, or passing structs
directly, as arguments is hairy business, you'll probably want to work
with pointers instead, which either means your function has to malloc
the EncodedData struct, or take a pointer to an already created one as
an argument - you would then create the EncodedData on the raku side
with a .new

Whenever you declare a struct to be passed as argument or received as
return value in NativeCall, you will get "TheStruct *" on the C side.

Not sure if that's all it takes to fix this. Feel free to write back to
the list.

Hope to Help
  - Timo

On 08/05/2020 12:44, David Santiago wrote:
> Hello,
>
> I'm porting some personal perl5 scripts to Raku, and  one of those
> scripts  is using Inline::C.
>
> The inline::c code would contain a function with the signature:
>
> AV* encode(unsigned char* data, size_t data_size)
>
> Description of the parameters on the original perl script:
> data -> binary string (the value comes from read $FH)
> data_size -> size in bytes of binary_string (the value comes from the
> return of the read function)
>
> And it would return an array with two values (a binary string and its crc32):
>
> """
> SV* enc_string = newSVpv(buffer, 0);
> SV* ret = sv_2mortal(newAV());
> av_push(ret, enc_string);
> SV* hex_string = newSVpv(hex_number, 0);
> av_push(ret, hex_string);
> free(hex_number);
> return ret;
> """
>
>
> Now for using it in raku, i'm changing  the return value to a struct:
> typedef struct{
>   unsigned char* data;
>   uint32_t crc32;
> } EncodedData;
>
> So i changed the signature to:
> EncodedData encode(unsigned char* data, size_t data_size)
>
> And i'm returning the struct:
> """
> EncodedData ed;
> ed.crc32 = crc32;
> ed.data = encbuffer;
>
> return ed;
> """
>
> Create a shared lib gcc -shared -olibmylib.so mylib.c
>
> Now on my raku script i did:
> """
> class EncodedData is repr('CStruct') {
> has uint32 $.crc32;
> has str $.data;
> }
>
> sub MAIN() {
> sub encode(str $data, size_t $size --> EncodedData) is
> native('lib/MyLib/libmylib.so') {*};
> my EncodedData $ed = encode("this is my string that will be
> encoded", "this is my string that will be encoded".chars );
> say $ed.crc32.base(16);
> say $ed.data;
> }
> """
> However this isn't working. Everytime i access "$ed.data" I'm getting
> the following error:
> "fish: 'raku bin/uints.p6' terminated by signal SIGSEGV (Address
> boundary error)"
>
> Why? How do i fix it?
>
> Also the read method from the IO::Handle returns a Buf. I would like
> to pass it directly to my C function. Is there any change in the
> C/raku code i should do?
> The data field from class EncodedData is type "str". Should it be
> CArray[uint8] instead?
>
> Best regards,
> David Santiago


Re: subst :g and captures in the replacement

2020-04-19 Thread Timo Paulssen
Hi Yary,

in the first example you've got a WhateverCode, but in the second one
you're actually just passing a string to subst, i.e. you're evaluating
$0 before subst is even called.

Check this as well:

> raku -e '"whoa" ~~ /(.)/; say \'fosdffgg\'.subst(/(f+)/,"( $0 )", :g)'
> ( w )osd( w )gg

Hope that helps
  - Timo

On 19/04/2020 23:53, yary wrote:
> Question from today's Raku meetup. This works in a way I expect
>
> > 'fosdffgg'.subst(/f+/,"( "~ * ~" )", :g);
> ( f )osd( ff )gg
>
> This one, $0 gets the single f each time
>
> > 'fosdffgg'.subst(/(f+)/,"( $0 )", :g);

> ( f )osd( f )gg
>
> Bug or misunderstanding on my part?
>
> -y


Re: OAuth2?

2020-03-23 Thread Timo Paulssen
The link was just missing a "../" at the beginning.

The example code lives here:

   
https://github.com/tbrowder/Google-API-Client/blob/master/eg/get-calendar-data.p6

Hope that helps
  - Timo

On 23/03/2020 04:34, ToddAndMargo via perl6-users wrote:
> On 2020-03-22 16:43, Tom Browder wrote:
>> On Sun, Mar 22, 2020 at 17:05 ToddAndMargo via perl6-users
>> mailto:perl6-users@perl.org>> wrote:
>>
>>     On 2020-03-22 10:39, Tom Browder wrote:
>>
>>  > Have you folks checked out Raku module "OAuth2::Client::Google"?
>>
>> ...
>>
>>     Any chance at a peakl at your code?  The example over
>>     on OAuth2::Client::Google is 404
>>
>>
>> What link are you using? Go to my account on
>>  and search for oauth2 and there's my code.
>>
>> Also did you search on ? Are you aware of
>> that site?
>>
>> -Tom
>
> Hi Tom,
>
> On your web page:
>
> https://github.com/tbrowder/Google-API-Client/blob/master/docs/GOOGLE.md
>
> For a working example, see eg/get-calendar-data.p6.
>
> Points to
>
> https://github.com/tbrowder/Google-API-Client/blob/master/docs/eg/get-calendar-data.p6
>
>
> is 404 (missing).  And it is for the calendar, not
> send mail
>
> Your "Quick how-to" flies right over my head because I
> can not figure out how to use it to send an eMail
>
> Do you have any examples of how to send mail with
> OAuth2 authentication?
>
> Many thanks,
> -T


Re: stashing an array in a hash and yanking it back out

2020-03-05 Thread Timo Paulssen

Hi William,

The line that has the important difference is where you put a `my` in
front of `%stash{'monsters'} = @monsters`. Probably a copy-paste error
or something like that.

>> my %stash> {}>> my @monsters = <> fingfangfoom>>
tingler>>> [godzilla grendel wormface blob fingfangfoom tingler]>> my
%stash{'monsters'} = @monsters;> {fingfangfoom => tingler, godzilla =>
grendel, wormface => blob}>> my @m = %stash{'monsters'};> [(Any)]>> say
@m> [(Any)]>> exit

timo@schmand ~> perl6 -e 'my %stash{"monsters"} = :1a; dd %stash'
Hash[Any,Str] %stash = (my Any %{Str} = :a(1))
timo@schmand ~> perl6 -e 'my %stash; %stash{"monsters"} = :1a; dd %stash'
Hash %stash = {:monsters(:a(1))}

Here you can see that in the case of having a "my" in front, the
assigned data doesn't get put in the hash at the "monsters" key.
instead, it gets assigned to the whole hash. The reason for that is that
`my %foo{Bar}` is syntax for restricting the keys of the hash to a
specific type (by default it's `Str(Any)`) and giving a string instance
("monsters" in this case) just takes the type of the value.

Hope that clears things up
  - Timo



Re: Question about Blob and Buf

2020-02-11 Thread Timo Paulssen
On 11/02/2020 14:14, David Santiago wrote:
> Awesome explanation! Thank you!
>
> BTW, 
>> my Blob $read = Buf.new;
> Is it creating either a Blob or a Buf?
>
> Regards,
> David Santiago


Hi David,

"my Blob $read" will define the variable $read to 1) only accept things
that typecheck against Blob, and 2) has the starting value of Blob (the
Blob type object). Assigning Buf.new to it will assign the newly created
Buf object to the variable, because a Buf Is-A Blob (by the liskov
substitution principle, everywhere you can use a Blob, you can also use
a Buf, but not the other way around).

BTW, assigning to a variable with a % or @ sigil behaves differently.
That is called "list assignment" and will actually use whatever type the
% or @ variable is defined to use (Hash and Array by default) and store
the values from the right-hand side of the assignment into the existing
object. This is why "my %foo = SetHash.new()" will result in a
Hash. For this example, you would want "my %foo is SetHash = "
instead.

Hope that clears things up
  - Timo


Re: Question about Blob and Buf

2020-02-11 Thread Timo Paulssen
On 11/02/2020 10:56, David Santiago wrote:
> Hi!
>
> Can someone explain me why this doesn't work:
>
> my Blob $read;
> $read ~= $socket.read(1024);
>
> Dies with error:
>
> X::Buf::AsStr: Cannot use a Buf as a string, but you called the Stringy 
> method on it
>
> This also doesn't work:
>
> my Buf $read;
> $read ~= $socket.read(1024);
>
> Dies with the same error as above.
>
>
> But this works?
>
> my Blob $read = Buf.new;
> $read ~= $socket.read(1024);
>
>
> Best regards,
> David Santiago


Hi David,

the important difference is that in the first two examples $read
contains an undefined object, either Blob or Buf. In the last one it
contains an instance.

The operator ~= uses the one-argument form of ~ to build an initial
value to calculate with. The reason is that with *= you want to start
with 1, but with += you want to start with 0, and so on.

However, ~ being called with no options doesn't realize you really want
a Buf or Blob, it just gives the empty string by default, and then the
next thing that happens is you get "" ~ $socket.read(1024) and that
complains that you're mixing strings and bufs.

I'm not sure if there is a good solution for inside rakudo or the raku
language. Setting an initial value for the variable is one correct way
to do this, though.

Hope that helps!
  - Timo


Re: printf question

2020-02-10 Thread Timo Paulssen
Hi Paul and Todd,

just a little extra info: the limitation for nameds to come after
positionals is only for declarations of signatures.

Usage of subs/methods as well as capture literals (which you don't use
often, i imagine, so feel free to disregard) allow you to mix nameds and
positionals freely; it will handle named parameters that are put between
positionals as if they were after the positional parameters.

> sub abcdefg($b, $f, $g, :$a, :$c, :$e) { say $a, $b, $c, $e }   
&abcdefg
> abcdefg(1, a => 5, 2, c => 99, 100, e => 1024)
51991024

Most cases where I wanted named parameters early in the call was when
there was something big in the call, for example if a sub takes a block
and a few options, i prefer to put the options before the block, so they
are visible at a glance rather than after scrolling. I suppose this
mirrors how regex modifiers (like :ignorecase / :i, :global, etc) have
been moved to the front of regexes.

Hope that's interesting
  - Timo

On 10/02/2020 07:48, Paul Procacci wrote:
> Named parameters must come after all positional parameters.
> Your example subroutine is invalid for this reason, while the
> following would be fine:
>
> sub abcdefg( $b, $f, $g, :$a, :$c, :$e)
>
> abcdefg("position1", "position2", "position3", :e("named_e"),
> :a("named_a"), :c("named_c"));
>
>
>
> On Sun, Feb 9, 2020 at 6:24 PM ToddAndMargo via perl6-users
> mailto:perl6-users@perl.org>> wrote:
>
> On 2020-02-09 14:53, Paul Procacci wrote:
> > subchdir(IO() $path, :$d=True, :$r, :$w, :$x-->IO::Path:D)
>
> Hi Paul,
>
> What I wanted to see is how something liek
>
> sub abcdefg( :$a, $b, :$c, :$e, $f, $g )
>
> would be called
>
> -T
>
>
>
> -- 
> __
>
> :(){ :|:& };:


Re: NQPMu ??

2020-01-09 Thread Timo Paulssen
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).

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?


Re: rmdir question

2019-12-03 Thread Timo Paulssen
On 03/12/2019 04:46, Paul Procacci wrote:
> On success it return a Bool::True.
> On failure it throws an exception.
> It doesn't crash the program.
> If you are interested in handling the exception, add logic to handle it.
>
> Examples:
> ---
> # mkdir a ; `which perl6` -e "'a'.IO.rmdir.perl.say"
> Bool::True
> # mkdir a ; `which perl6` -e "'b'.IO.rmdir.perl.say"
> Failure.new(exception => X::IO::Rmdir.new(path => "/root/test/b",
> os-error => "Failed to rmdir: no such file or directory"), backtrace
> => Backtrace.new)
> # mkdir a ; `which perl6` -e "try { 'b'.IO.rmdir.perl.say; CATCH {
> default { 'tsk tsk'.say }}}"
> tsk tsk


Hi Paul,

thanks to your email I found and fixed an oversight in the Raku docs:

it says it throws an exception, when actually it returns a Failure.

Thank you!
  - Timo


Re: Quoting issue in Windows

2019-11-30 Thread Timo Paulssen


On 30/11/2019 09:05, ToddAndMargo via perl6-users wrote:
> One of the weirdest was
>
> for @Result.kv -> $I, $Line {
>    if $I % 2 = 0
>
> being told I could not change an immutable object.


Here you're trying to assign 0 to the result of $I % 2, if that's
actually exactly the code. You want to compare here, not assign, i.e.
use == instead of =

HTH
  - Timo


Re: split to walk into an HoH ?

2019-11-22 Thread Timo Paulssen
Hi Marc,

here's a one-liner based on the classify method, which you may find to
be an interesting jumping-off-point, or centerpiece:

perl6 -e 'use JSON::Fast; my %foo =
lines()>>.trim-leading.classify(*.split(",").head(2)); say to-json %foo'
    A,1,garbage .
    A,2,garbage .
    A,2,garbage .
    A,2,garbage .
    A,3,garbage .
    A,3,garbage .
    A,3,garbage .
    B,1,garbage .
    B,2,garbage .
    B,2,garbage .
    B,2,garbage .
    B,3,garbage .
    B,3,garbage .
    B,3,garbage .
{
  "A": {
    "3": [
  "A,3,garbage .",
  "A,3,garbage .",
  "A,3,garbage ."
    ],
    "1": [
  "A,1,garbage ."
    ],
    "2": [
  "A,2,garbage .",
  "A,2,garbage .",
  "A,2,garbage ."
    ]
  },
  "B": {
    "3": [
  "B,3,garbage .",
  "B,3,garbage .",
  "B,3,garbage ."
    ],
    "1": [
  "B,1,garbage ."
    ],
    "2": [
  "B,2,garbage .",
  "B,2,garbage .",
  "B,2,garbage ."
    ]
  }
}

Things to note are: it makes hashes, so the order isn't retained. if
that's important, you could, for example, use/build a Hash that retains
its key insertion order and call .categorize-list on an instance of it.

Hope that helps, and Good Luck!
  - Timo

On 22/11/2019 16:06, Marc Chantreux wrote:
> hello,
>
> On Fri, Nov 22, 2019 at 03:07:28PM +0100, Patrick Spek via perl6-users wrote:
>> Could you post some input and expected output? That would make it
>> easier for me (and perhaps others) to see what exactly you're trying to
>> accomplish, in practical terms.
> sorry ... i'm so confortable with awk i haven't though about some are
> not. i sincerely apologize.
>
> Basically i want to figure out what are the sections, subsections of of
> a CSV file:
>
> A,1,garbage .
> A,2,garbage .
> A,2,garbage .
> A,2,garbage .
> A,3,garbage .
> A,3,garbage .
> A,3,garbage .
> B,1,garbage .
> B,2,garbage .
> B,2,garbage .
> B,2,garbage .
> B,3,garbage .
> B,3,garbage .
> B,3,garbage .
>
> becomes
>
> A
> 1
> 2
> 3
> B
> 1
> 2
> 3
>
> regards,
> marc


Re: getting comb to return match objects

2019-11-16 Thread Timo Paulssen
Oh dang!

This may very well be a rakudobug. I've actually never used the sub form
of comb, only ever the method form, for which the "match" named
parameter definitely exists:

"a;b;c".comb(/\w/, match => True);
(「a」 「b」 「c」)

Someone will have to fix that and then the code from my mail will
retroactively become correct ;)

HTH
  - Timo

On 16/11/2019 18:35, William Michels wrote:
> Hello Timo, and thank you for taking the time to explain how "comb"
> routine signatures work. I have no doubt your description is the
> correct way to use comb routine(s) in Raku/Perl6.
>
> First of all, I should preface my remarks by saying that I'm using
> Rakudo (moar) 2019.07.1, with the Linenoise module to run the
> Raku/Perl6 REPL. It has been suggested to me that my install might
> somehow be broken, because I tried to 'roll-my-own' Rakudo-Star
> release (basically I copied over pre-installed modules from my Rakudo
> 2019.03 install, and ran 'zef update').
>
> In any case, I haven't been able to get the code you posted to work. I
> checked all six examples in the REPL, and the last example I checked
> at the command line as well. I'm hoping someone on the list running
> Rakudo (moar) 2019.07.1 can confirm/refute my results:
>
>> #Timo
> Nil
>> comb(/\w/, "a;b;c", match => True);
> Unexpected named argument 'match' passed
>   in block  at  line 1
>
>> comb(/\w/, "a;b;c", :match);
> Unexpected named argument 'match' passed
>   in block  at  line 1
>
>> comb(/\w/, "a;b;c", :match(True));
> Unexpected named argument 'match' passed
>   in block  at  line 1
>
>> comb(/\w/, "a;b;c", :!match);
> Unexpected named argument 'match' passed
>   in block  at  line 1
>
>> comb(/\w/, "a;b;c", :match(False));
> Unexpected named argument 'match' passed
>   in block  at  line 1
>
>> comb(/\w/, "a;b;c", 2, :match);
> Unexpected named argument 'match' passed
>   in block  at  line 1
>
>> $*VM
> moar (2019.07.1)
>> exit
> mbook:~ homedir$ perl6 -e 'comb(/\w/, "a;b;c", 2, :match);'
> Unexpected named argument 'match' passed
>   in block  at -e line 1
> mbook:~ homedir$
>
> As for what's going on, I'm wondering if there might be an issue with
> "comb" signatures in general. There exists both a '(Str) routine comb'
> and a '(Cool) routine comb'. Maybe these two routines are somehow
> interfering with each other?
>
> Thank you, and any further help appreciated, Bill.
>
>
> On Sat, Nov 16, 2019 at 6:34 AM Timo Paulssen  wrote:
>> Hi Bill,
>>
>> In your repl examples you're actually passing the True or False as a 
>> positional parameter, which makes it go into the slot for $limit, not the 
>> slot for :$match.
>>
>> In order to pass true or false for the "match" named parameter you have 
>> different syntactical options:
>>
>>   comb(/\w/, "a;b;c", match => True) # maybe the simplest is using a pair
>>
>>   comb(/\w/, "a;b;c", :match) # using "colon pair" syntax; it's syntax that 
>> puts a colon at the beginning and makes a pair
>>
>>   comb(/\w/, "a;b;c", :match(True)) # :match is short for match => True, and 
>> :match(True) is long for match => True
>>
>>   comb(/\w/, "a;b;c", :!match) # putting a ! after the : negates the pair, 
>> i.e. it's now match => False
>>
>>   comb(/\w/, "a;b;c", :match(False)) # same value
>>
>> And on top of that, you can add the third positional parameter to pass a 
>> value for $limit
>>
>>   comb(/\w/, "a;b;c", 2, :match) # output up to two results, as match objects
>>
>> Here's a few comments on the examples you pasted:
>>
>>
>>> On another note (or possibly the same note), I tried code similar to > 
>>> Joe's with fair success. I was able to get the REPL to understand a > 
>>> "True" or "False" parameter, but never in conjunction with a > "$limit" 
>>> parameter. Is this the correct behaviour, and why?
>> The surprise here comes from Bool actually being derived from Int, and 
>> therefore being totally acceptable values to pass for $limit.
>>>> #REPL > Nil >> say comb(/\w/, "a;b;c", False).perl; > ().Seq You can see 
>>>> here that it gave no results; that's because it interpreted the False as 0 
>>>> in

Re: getting comb to return match objects

2019-11-16 Thread Timo Paulssen
Hi Bill,

In your repl examples you're actually passing the True or False as a
positional parameter, which makes it go into the slot for $limit, not
the slot for :$match.

In order to pass true or false for the "match" named parameter you have
different syntactical options:

  comb(/\w/, "a;b;c", match => True) # maybe the simplest is using a pair

  comb(/\w/, "a;b;c", :match) # using "colon pair" syntax; it's syntax
that puts a colon at the beginning and makes a pair

  comb(/\w/, "a;b;c", :match(True)) # :match is short for match => True,
and :match(True) is long for match => True

  comb(/\w/, "a;b;c", :!match) # putting a ! after the : negates the
pair, i.e. it's now match => False

  comb(/\w/, "a;b;c", :match(False)) # same value

And on top of that, you can add the third positional parameter to pass a
value for $limit

  comb(/\w/, "a;b;c", 2, :match) # output up to two results, as match
objects

Here's a few comments on the examples you pasted:


> On another note (or possibly the same note), I tried code similar to > Joe's 
> with fair success. I was able to get the REPL to understand a >
"True" or "False" parameter, but never in conjunction with a > "$limit"
parameter. Is this the correct behaviour, and why?
The surprise here comes from Bool actually being derived from Int, and
therefore being totally acceptable values to pass for $limit.
>> #REPL > Nil >> say comb(/\w/, "a;b;c", False).perl; > ().Seq You can see here
that it gave no results; that's because it interpreted the False as 0 in
the $limit parameter.

>> say comb(/\w/, "a;b;c",  True).perl; > ("a",).Seq
Here the True is interpreted as 1 for $limit, giving you just "a", and
it's a string because the match named parameter wasn't given and
defaulted to False.
>> say comb(/\w+/, "a;b;c",  True).perl; > ("a",).Seq
The difference between \w and \w+ isn't noticeable here, as the source
string only ever has single word character in a row, but you can try
with "ab;cd;ef" for example with both \w and \w+.

>> say comb(/\w+/, "a;b;c",  2).perl; > ("a", "b").Seq >> say comb(/\w+/, 
>> "a;b;c", 3).perl; > ("a", "b",
"c").Seq >> say comb(/\w+/, "a;b;c", 4).perl; > ("a", "b", "c").Seq >>
say comb(/\w+/, "a;b;c", True).perl; > ("a",).Seq
Same as above; True being interpreted as 1

>> say comb(/\w+/, "a;b;c",  2, True).perl; > Too many positionals passed; 
>> expected 2 or 3 arguments but got 4 in >
block  at  line 1
There's no syntax here that distinguishes 2, a positional parameter,
from True, also a positional parameter.

>> say comb(/\w+/, "a;b;c",  2, :True).perl; > Unexpected named argument 'True' 
>> passed in block  at 
file> line 1
The issue here is that :True is short for True => True, i.e. passing the
value True to the named parameter called "True", easy to get confused by
the error message here!
> Any help appreciated, Bill.

I hope the explanations make sense!
  - Timo



Re: FC31 can't find my module subs

2019-11-04 Thread Timo Paulssen
Todd,

can you please double-check if putting a comma in between the
:import-tags in the "use" statement makes a difference? Like this:

# perl6 -I./p6lib -e 'use ModuleTest :ModuleTest, :ModuleTst;
ModuleTest; ModuleTst; # correct'
# perl6 -I./p6lib -e 'use ModuleTest :ModuleTest :ModuleTst; ModuleTest;
ModuleTst;  # missing the comma'

it should look like in the first line, the comma right between
:ModuleTest and :ModuleTst

Thanks
  - Timo

On 04/11/2019 03:56, ToddAndMargo via perl6-users wrote:
> On 11/3/19 3:15 PM, ToddAndMargo via perl6-users wrote:
>> Hi All,
>>
>> Help!
>>
>> I just upgraded Fedora from 30 to 31.
>>
>> I upgraded to rakudo-pkg-Fedora31-2019.07.1-03.x86_64.rpm
>> from https://github.com/nxadm/rakudo-pkg/releases
>>
>> Now P6 can not find my subs inside my modules:
>>
>> # perl6 -I/home/linuxutil/p6lib -MPrintColors -e 'PrintGreen( "Hi\n" );'
>>  ===SORRY!=== Error while compiling -e
>>  Undeclared name:
>>  PrintGreen used at line 1
>>
>> [editorial comment] HHH! [/editorial comment]
>>
>> The stock "rakudo" and "rakudo-zef" that resides in the
>> Fedora repo's has the same issue.
>>
>> Many thanks,
>> -T
>
>
> I am hamstrung on so may fronts if I don't get this working!
>
> I gets uglier:
>
> # cat p6lib/ModuleTest.pm6
> sub ModuleTest() is export( :ModuleTest ) { say "Hi"; }
> sub ModuleTst()  is export( :ModuleTst )  { say "Bye"; }
>
>
> # perl6 -I./p6lib -e 'use ModuleTest :ModuleTest :ModuleTst;
> ModuleTest; ModuleTst;'
>
> ===SORRY!=== Error while compiling -e
> Undeclared name:
>     ModuleTst used at line 1
>
>
> And way uglier.  I removed the ":"
> # cat p6lib/ModuleTest.pm6
>
> # sub ModuleTest() is export( :ModuleTest ) { say  "Hi"; }
> # sub ModuleTst()  is export( :ModuleTst )  { say "Bye"; }
> sub ModuleTest() is export( ModuleTest ) { say  "Hi"; }
> sub ModuleTst()  is export( ModuleTst )  { say "Bye"; }
>
>
> # perl6 -I/home/linuxutil/p6lib -e 'use ModuleTest;  ModuleTest;
> ModuleTst;'
> ===SORRY!=== Error while compiling
> /home/linuxutil/p6lib/ModuleTest.pm6 (ModuleTest)
> Undeclared name:
>     ModuleTest used at line 4
>
> And, And, depending on the position of the moon overhead,
> sometimes it works.    AAAHHH!


Re: Typed Pairs

2019-09-05 Thread Timo Paulssen
You can try defining a subset type a bit like this:

subset StrArrStrsPair of Pair where .key ~~ Str && .value ~~ Positional[Str];

Please be aware that the arrays have to be explicitly created with the type 
constant of Str for this to work.

On 5 September 2019 14:34:05 CEST, Mikkel  wrote:
>Hello
>
>I am wondering whether it is possible to define a Pair with a key and a
>value of a specific class.
>
>Suppose I want an Array of Pairs with keys as Str and values as Array
>of
>Str called "properties". And define it as a instance variable.Something
>of
>the likes:
>
>has Pair[Str, Array[Str]] @!properties;
>
>Except this wont work.
>
>
>Best regards
>Mikkel

-- 
Sent from my Android device with K-9 Mail. Please excuse my brevity.

Re: is inlinable trait missing from docs

2019-07-13 Thread Timo Paulssen
First off, a correction: liz found that the trait_mod: candidate for
"inlinable" is actually used internally.

Here's a link to the source to get you started, it's got a good comment
at the start about how rakudo's own inliner works:
https://github.com/rakudo/rakudo/blob/master/src/Perl6/Actions.nqp#L4193

On top of that, there's MoarVM's spesh, which also does inlining. The
profiler can tell you what was inlined and what wasn't, and IIRC the
spesh log can give you more specific info on why an inline was not
performed in a given case.

HTH
  - Timo

On 13/07/2019 12:51, Marcel Timmerman wrote:
> On 7/13/19 12:37 PM, Timo Paulssen wrote:
>> I wouldn't put "is inlinable" in the docs; it requires the user to put a
>> QAST tree in the value, which isn't a thing an end-user would touch,
>> IMO. In fact I'm not sure why we have a trait for that at all, since
>> it's not used anywhere in rakudo's source.
>>
>> On 13/07/2019 12:33, Marcel Timmerman wrote:
>>> Hi,
>>>
>>> I found out about a trait 'is inlinable' when I made a typo in using a
>>> trait on subs. There is no documentation for it so I thought maybe it
>>> is not implemented, experimental or some other reason it is kept out
>>> of the docs. Otherwise it should be documented too.
>>>
>>> Great work on the documentation, still learning a lot from it.
>>> Regards,
>>> Marcel
> Thanks @Timo
>
> I have used it here and there without any arguments. Can not see if it
> helps.
> Btw, is rakudo finding out itself if routines are inlinable and what
> algorithm is it using? I have this question to see if one can
> influence this process and nudge the routine into inlining.
>


Re: is inlinable trait missing from docs

2019-07-13 Thread Timo Paulssen
I wouldn't put "is inlinable" in the docs; it requires the user to put a
QAST tree in the value, which isn't a thing an end-user would touch,
IMO. In fact I'm not sure why we have a trait for that at all, since
it's not used anywhere in rakudo's source.

On 13/07/2019 12:33, Marcel Timmerman wrote:
> Hi,
>
> I found out about a trait 'is inlinable' when I made a typo in using a
> trait on subs. There is no documentation for it so I thought maybe it
> is not implemented, experimental or some other reason it is kept out
> of the docs. Otherwise it should be documented too.
>
> Great work on the documentation, still learning a lot from it.
> Regards,
> Marcel


Re: Odd Complex behavior

2019-06-14 Thread Timo Paulssen
That sounds like a recipe for even more confusion further down the road; 
now whether you get a -0-i or a 0-i out of your bag depends on which one 
of the two was put in first, and the difference between 0 and -0 surely 
makes a difference in enough cases when doing floating point math that 
it would come up at just the right time to ruin your day :(


On 14/06/2019 00:28, Elizabeth Mattijsen wrote:

We could potentially give 0e0 and -0e0 the same .WHICH, which would solve the 
bag issue.


On 13 Jun 2019, at 21:02, Timo Paulssen  wrote:

Unfortunately, that's what the IEEE prescribes, so all we can really do is: 
*shrug*

On 13/06/2019 21:01, Sean McAfee wrote:

On Thu, Jun 13, 2019 at 11:12 AM Brad Gilbert  wrote:
 > (-i).reals
 (-0 -1)

Ah, so it's nothing particular to Complex:


bag 0e0, -0e0

bag(-0, 0)

Can't say I'm thrilled to have two distinct zeroes.



Re: Odd Complex behavior

2019-06-13 Thread Timo Paulssen
Unfortunately, that's what the IEEE prescribes, so all we can really do 
is: *shrug*


On 13/06/2019 21:01, Sean McAfee wrote:
On Thu, Jun 13, 2019 at 11:12 AM Brad Gilbert > wrote:


    > (-i).reals
    (-0 -1)


Ah, so it's nothing particular to Complex:

> bag 0e0, -0e0
bag(-0, 0)

Can't say I'm thrilled to have two distinct zeroes.



Re: LogP6 not working as I expect

2019-05-10 Thread Timo Paulssen
Hi Patrick,

It could be that compile time is too early for the logger object to
properly be set up; try to see if "my \Log" instead of "constant Log"
fixes it, then we can perhaps find a better solution that still has
"constant" (for example a feature request for LogP6)

Kind Regards
  - Timo


Re: Short term Zef fix

2019-04-30 Thread Timo Paulssen
Doesn't updating zef to the latest version fix everything up nicely?
  - Timo

On 30/04/2019 12:06, Simon Proctor wrote:
> Until the p6c system is fixed here's a short term fix that will at
> least let zef install modules from cpan.
>
> zef --help
> This lists a config file mine is :
>
> CONFIGURATION /home/sproctor/.config/zef/config.json
>
> Open that file and fine the "p6c" section. Set enabled to 0 and zef
> will stop trying to access the ecosystem modules.
>
> It's not perfect as not everything is in CPAN but it should help.
>
> -- 
> Simon Proctor
> Cognoscite aliquid novum cotidie
>
> http://www.khanate.co.uk/


Re: library search path ?

2019-04-29 Thread Timo Paulssen
you can use these one-liners:

    perl6 -e '.say for $*REPO.repo-chain'

    perl6 -e '.perl.say for $*REPO.repo-chain'

On 29/04/2019 00:33, ToddAndMargo via perl6-users wrote:
> Hi All,
>
> Could not find xxx::yyy at line zz in:
>     file#/home/linuxutil/p6lib
>     inst#/home/tony/.perl6
>     inst#/usr/lib64/perl6/site
>     inst#/usr/lib64/perl6/vendor
>     inst#/usr/lib64/perl6
>     ap#
>     nqp#
>     perl5#
>
>
> If I remember correctly, there was a way to ask Perl 5 for
> a list of the module paths from the command line.
>
> Right now I have to deliberately crash a program.
>
> Perl6 -h is not helping.
>
> How do I ask Perl 6 for this list from the command line
> the proper way?
>
> Many thanks,
> -T
>
> What is "ap#, nqp#, and perl5#" anyway?


Re: Something happened to the chat line

2019-04-28 Thread Timo Paulssen
I'm just about to go to bed, but you can use this link instead (i think
what was there before was just a redirect anyway):

    https://webchat.freenode.net/?channels=#perl6

HTH
  - Timo

On 29/04/2019 00:38, ToddAndMargo via perl6-users wrote:
> Hi All,
>
> Going to
>
>     https://docs.perl6.org/
>
> and clicking on "Chat with us"
>
>     https://docs.perl6.org/webchat.html
>
> gives
>
>     Page not found... yet!
>
>     None of these routes could generate a response for your GET
>     request for /webchat.html, maybe you need to add a new one?
>
>
> Please fix!
>
> Many thanks,
> -T


Re: Why so slow

2019-04-28 Thread Timo Paulssen
the strace command ended up only tracing the shell script "perl6", which 
very quickly execs moar, at which point strace considers its job done. 
there was barely any output at all for that reason.


fortunately we can just add -f to the strace command so that it follows 
processes as they are spawned.


does /home/linuxutil have many files and folders in it?

was the output from RAKUDO_MODULE_DEBUG going smoothly, or were there 
any points where it did any very long pauses?


it does look a little like some of your individual modules have their 
own "use lib" commands in them, but i'm not exactly sure how it 
influences precompilation and such.


On 28/04/2019 09:21, ToddAndMargo via perl6-users wrote:




Hi Timo,

This tell you anything?

$ perl6 --stagestats GetUpdates.pl6
Stage start  :   0.000
Stage parse  :  13.150
Stage syntaxcheck:   0.000
Stage ast    :   0.000
Stage optimize   :   0.351
Stage mast   :   1.133
Stage mbc    :   0.019
Stage moar   :   0.000

GetUpdates.pl6  <-- my program starts here
Mozilla Mirror 
Debug is OFF


The "Stage parse : 13.150" is eating me alive!

-T


On 4/28/19 12:01 AM, Timo Paulssen wrote:> Please give this a try:
>
>  env RAKUDO_MODULE_DEBUG=1 perl6 GetUpdates.pl6
>
> and tell me if any of the lines it spits out takes considerable amounts
> of time before the next one shows up.
>
> Then, you can also
>
>  strace -e stat perl6 GetUpdates.pl6
>
> to see if it's going through a whole load of files.
>
> without the "-e stat" you will get a whole lot more output, but it'll
> tell you pretty much everything that it's asking the kernel to do.
> Pasting that whole file could be a privacy concern, especially if it
> iterates your entire home directory, which is still my working 
hypothesis.

>
> HTH
>    - Timo
>

My home directory is pretty small, except for .wine.
All the good stuff is on my network shares to share
with my numerous VM's


$ env RAKUDO_MODULE_DEBUG=1 perl6 GetUpdates.pl6 > GetUpdates.debug 2>&1
http://vpaste.net/xmwcd


$ strace -e stat perl6 GetUpdates.pl6 > GetUpdates.debug 2>&1
http://vpaste.net/8ekeI


Re: Why so slow

2019-04-28 Thread Timo Paulssen
I'm writing a program called moarperf, which is a local web app written in Cro 
that doesn't touch the network outside of loopback. It just has to build its 
JavaScript blobs once by downloading like a brazillion libraries from npm.

Also, comma complete comes with support for profiling, which also doesn't need 
a live net connection.

Finally, I think at least Debian patches the profiler html app to point at an 
angularjs downloaded from Debian repositories. It's quite feasible to have an 
env var for nqp/rakudo that changes the path to the js libraries to something 
local.

On 28 April 2019 09:01:28 CEST, David Christensen  
wrote:
>> On 21/04/2019 05:58, ToddAndMargo via perl6-users wrote:
>>> Hi All,
>>> 
>>> One liners are fast, but my own programs are very slow to start.
>>> 
>>> I download
>>> 
>>> https://github.com/perl6/gtk-simple/blob/master/examples/05-bars.pl6
>>>
>>>
>>> To check it out and it also takes ten second to start. >>
>>> What gives?
>>> 
>>> Many thanks, -T
>
>
>On 4/27/19 11:14 PM, Timo Paulssen wrote:
>> You don't happen to have a PERL6LIB or -I pointed at a folder with
>> loads of stuff in it? If that is the case, having a single "use"
>> statement will cause rakudo to iterate through all files and
>> subfolders, which can take a long time if you've got, for example,
>> your home directory in that list (be it via -I. or PERL6LIB=. or
>> explicitly mentioning the big folder)
>> 
>> There's many different tools to find out what's going on. For the
>> "too big perl6lib folder" problem, "strace" will give you a good hint
>> by giving one "stat" command for every file under your home
>> directory.
>> 
>> Other than that, check "perl6 --stagestats -e 'blah'" or "perl6 
>> --stagestats FooBar.p6", which will give timings for the different 
>> phases, most notably "parse", "optimize", and "mbc". loading modules
>> and precompiling are part of the parse stage.
>> 
>> the "time" command will split your run time between "system" and
>> "user" time (as well as wallclock time). if "system" is particularly
>> high, then the program spends a lot of time asking the kernel to do
>> stuff (such as iterating files on the filesystem for the PERL6LIB
>> case i've menitoned above).
>> 
>> If none of that helps, startup can be profiled with "perl6 
>> --profile-compile blah" and run time can be profiled with "perl6 
>> --profile blah". The default output will be a html file that you can
>>  just open in your browser to get an interactive performance
>> inspection tool thingie. Be aware, though, that it can become very
>> big in the case of --profile-compile, depending on the structure of
>> the program being compiled.
>> 
>> Hope any of that helps - Timo
>
>
>Yes, very useful -- thank you.  :-)
>
>
>(I do not seem to have a man page for Perl 6, but 'perl6 --help' gives
>a 
>brief overview of those options.)
>
>
>The only drawback is that the HTML profile reports require JavaScript
>and a live Internet connection to function.
>
>
>David

-- 
Sent from my Android device with K-9 Mail. Please excuse my brevity.

Re: Why so slow

2019-04-28 Thread Timo Paulssen

Please give this a try:

    env RAKUDO_MODULE_DEBUG=1 perl6 GetUpdates.pl6

and tell me if any of the lines it spits out takes considerable amounts 
of time before the next one shows up.


Then, you can also

    strace -e stat perl6 GetUpdates.pl6

to see if it's going through a whole load of files.

without the "-e stat" you will get a whole lot more output, but it'll 
tell you pretty much everything that it's asking the kernel to do. 
Pasting that whole file could be a privacy concern, especially if it 
iterates your entire home directory, which is still my working hypothesis.


HTH
  - Timo

On 28/04/2019 08:41, ToddAndMargo via perl6-users wrote:

> On 21/04/2019 05:58, ToddAndMargo via perl6-users wrote:>> Hi All,
>>
>> One liners are fast, but my own programs are very slow to start.
>>
>> I download
>>
>> https://github.com/perl6/gtk-simple/blob/master/examples/05-bars.pl6
>>
>> To check it out and it also takes ten second to start.
>>
>> What gives?
>>
>> Many thanks,
>> -T

On 4/27/19 11:14 PM, Timo Paulssen wrote:
You don't happen to have a PERL6LIB or -I pointed at a folder with 
loads of stuff in it? If that is the case, having a single "use" 
statement will cause rakudo to iterate through all files and 
subfolders, which can take a long time if you've got, for example, 
your home directory in that list (be it via -I. or PERL6LIB=. or 
explicitly mentioning the big folder)


There's many different tools to find out what's going on. For the 
"too big perl6lib folder" problem, "strace" will give you a good hint 
by giving one "stat" command for every file under your home directory.


Other than that, check "perl6 --stagestats -e 'blah'" or "perl6 
--stagestats FooBar.p6", which will give timings for the different 
phases, most notably "parse", "optimize", and "mbc". loading modules 
and precompiling are part of the parse stage.


the "time" command will split your run time between "system" and 
"user" time (as well as wallclock time). if "system" is particularly 
high, then the program spends a lot of time asking the kernel to do 
stuff (such as iterating files on the filesystem for the PERL6LIB 
case i've menitoned above).


If none of that helps, startup can be profiled with "perl6 
--profile-compile blah" and run time can be profiled with "perl6 
--profile blah". The default output will be a html file that you can 
just open in your browser to get an interactive performance 
inspection tool thingie. Be aware, though, that it can become very 
big in the case of --profile-compile, depending on the structure of 
the program being compiled.


Hope any of that helps
   - Timo



Hi Timo,

This tell you anything?

$ perl6 --stagestats GetUpdates.pl6
Stage start  :   0.000
Stage parse  :  13.150
Stage syntaxcheck:   0.000
Stage ast    :   0.000
Stage optimize   :   0.351
Stage mast   :   1.133
Stage mbc    :   0.019
Stage moar   :   0.000

GetUpdates.pl6  <-- my program starts here
Mozilla Mirror 
Debug is OFF


The "Stage parse : 13.150" is eating me alive!

-T


Re: Why so slow

2019-04-27 Thread Timo Paulssen
You don't happen to have a PERL6LIB or -I pointed at a folder with loads 
of stuff in it? If that is the case, having a single "use" statement 
will cause rakudo to iterate through all files and subfolders, which can 
take a long time if you've got, for example, your home directory in that 
list (be it via -I. or PERL6LIB=. or explicitly mentioning the big folder)


There's many different tools to find out what's going on. For the "too 
big perl6lib folder" problem, "strace" will give you a good hint by 
giving one "stat" command for every file under your home directory.


Other than that, check "perl6 --stagestats -e 'blah'" or "perl6 
--stagestats FooBar.p6", which will give timings for the different 
phases, most notably "parse", "optimize", and "mbc". loading modules and 
precompiling are part of the parse stage.


the "time" command will split your run time between "system" and "user" 
time (as well as wallclock time). if "system" is particularly high, then 
the program spends a lot of time asking the kernel to do stuff (such as 
iterating files on the filesystem for the PERL6LIB case i've menitoned 
above).


If none of that helps, startup can be profiled with "perl6 
--profile-compile blah" and run time can be profiled with "perl6 
--profile blah". The default output will be a html file that you can 
just open in your browser to get an interactive performance inspection 
tool thingie. Be aware, though, that it can become very big in the case 
of --profile-compile, depending on the structure of the program being 
compiled.


Hope any of that helps
  - Timo

On 21/04/2019 05:58, ToddAndMargo via perl6-users wrote:

Hi All,

One liners are fast, but my own programs are very slow to start.

I download

https://github.com/perl6/gtk-simple/blob/master/examples/05-bars.pl6

To check it out and it also takes ten second to start.

What gives?

Many thanks,
-T


Re: gtk widget?

2019-04-22 Thread Timo Paulssen
Please check out Marcel Timmermann's GTK::Glade module. Here's the readme:

https://github.com/MARTIMM/gtk-glade

Sadly, modules.perl6.org is currently not available, however, you can
download the distribution here:

https://www.cpan.org/authors/id/M/MA/MARTIMM/Perl6/gtk-glade-0.8.3.tar.gz

or you can git clone the repository and "zef install ." from inside it.

There's a little pdf file in the docs/ folder about using the module itself.

In order to build a glade file to use with this library, you can install
the program "glade". This allows you to graphically put a GUI together.

https://glade.gnome.org/


Good Luck!
  - Timo


On 22/04/2019 05:44, ToddAndMargo via perl6-users wrote:
> Hi All,
>
> I see
>
> https://github.com/perl6/gtk-simple/tree/master/examples
>
> but I have no clue what is going on.
>
> Is there some kind of gtk widget that you can graphically
> design these windows with?
>
> Many thanks,
> -T
>


Re: Why so slow?

2019-04-22 Thread Timo Paulssen
It's the second line:

use v6;
use lib 'lib';  # ← this line right here
use GTK::Simple;
use GTK::Simple::App;

  -Timo

On 22/04/2019 12:51, ToddAndMargo via perl6-users wrote:
>>> On 22/04/2019 03:32, ToddAndMargo via perl6-users wrote:
>>>> Hi All,
>>>>
>>>> One liners are fast, but my own programs are very slow to start.
>>>>
>>>> I download
>>>>
>>>> https://github.com/perl6/gtk-simple/blob/master/examples/05-bars.pl6
>>>>
>>>> To check it out and it also takes ten second to start.
>>>>
>>>> What gives?
>>>>
>>>> Many thanks,
>>>> -T
>
> On 4/22/19 3:35 AM, Timo Paulssen wrote:
>> It's quite possible that when you start that program, you're first
>> waiting for GTK::Simple to be precompiled; the "use lib 'lib'" can
>> interfere with the storage of precompilation results. If you have
>> installed GTK::Simple (for example by going to its folder and running
>> "zef install .") and removed the line "use lib 'lib';", it might start a
>> lot faster when you run it the second time.
>>
>> Hope that helps!
>>    - Timo
>>
>
>
>
> Not seeing a `use lib`.  :'(
>
> use v6;
> use lib 'lib';
> use GTK::Simple;
> use GTK::Simple::App;


Re: Why so slow?

2019-04-22 Thread Timo Paulssen
It's quite possible that when you start that program, you're first
waiting for GTK::Simple to be precompiled; the "use lib 'lib'" can
interfere with the storage of precompilation results. If you have
installed GTK::Simple (for example by going to its folder and running
"zef install .") and removed the line "use lib 'lib';", it might start a
lot faster when you run it the second time.

Hope that helps!
  - Timo

On 22/04/2019 03:32, ToddAndMargo via perl6-users wrote:
> Hi All,
>
> One liners are fast, but my own programs are very slow to start.
>
> I download
>
> https://github.com/perl6/gtk-simple/blob/master/examples/05-bars.pl6
>
> To check it out and it also takes ten second to start.
>
> What gives?
>
> Many thanks,
> -T


Re: perl6.org down and documentation

2019-04-21 Thread Timo Paulssen
Hi mimosinnet,

we have a fallback live on http://docs.perl6.wakelift.de/ for the docs
and http://perl6.wakelift.de/ for the main website. There is an outage
somewhere near the server that hosts all our sites. We'll be able to get
physical access and fix whatever's wrong on tuesday.

I'm not sure why zef is trying to install p6doc system-wide, but you
could try creating and giving your user write access to
/usr/share/perl6/site/doc to see what it comes up with next …

Cheers,
  - Timo

On 21/04/2019 10:27, mimosinnet wrote:
> Dear perl6 users,
>
> Perl6 web [1] seems to be down. I was looking for documentation, and
> it seems I could not install p6doc [2]. I have installed the
> documentation [3] and I can now review the documentation in my box :D.
>
> Cheers!
>
> [1] https://perl6.org/
> [2]
> ===> Updated cpan mirror:
> https://raw.githubusercontent.com/ugexe/Perl6-ecosystems/master/cpan1.json
> !!!> Failed to update p6c mirror:
> http://ecosystem-api.p6c.org/projects1.json
> ===> Updating p6c mirror: http://ecosystem-api.p6c.org/projects.json
> !!!> Failed to update p6c mirror:
> http://ecosystem-api.p6c.org/projects.json
> ===> Updating p6c mirror: git://github.com/ugexe/Perl6-ecosystems.git
> ===> Updated p6c mirror: git://github.com/ugexe/Perl6-ecosystems.git
> ===> Searching for missing dependencies: Pod::To::BigPage:ver<0.5.1+>,
> Pod::To::HTML:ver<0.6.1+>
> ===> Searching for missing dependencies: Pod::Load:ver<0.4.0+>,
> Test::When, IO::Socket::SSL
> ===> Building: p6doc:ver<1.002001>
> Failed to create directory '/usr/share/perl6/site/doc' with mode
> '0o777': Failed to mkdir: Permission denied
>  in method build at
> /home/mimosinnet/.zef/store/doc.git/ee6df93dcabb46e240f5f5c9372fbeba0a2ab2b0/Build.pm6
> line 12
>  in block  at -e line 1
> [3] https://github.com/perl6/doc
>
>


Re: .payload

2019-02-28 Thread Timo Paulssen
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


On 28/02/2019 21:54, ToddAndMargo via perl6-users wrote:
>
>> On 28/02/2019 12:46, ToddAndMargo via perl6-users wrote:
>>> Hi All,
>>>
>>> https://docs.perl6.org/language/exceptions#Catching_exceptions
>>>
>>> I am trying to place .payload into a variable `my $Payload = .payload;`
>>>
>>>
>>> CATCH {
>>>     # Reference:
>>> https://docs.perl6.org/language/exceptions#Catching_exceptions
>>>     my $NotifyStr;
>>>     my $Payload = .payload;
>>>
>>>     default {
>>>    # $*ERR.say: .payload;
>>>    PrintRedErr( "$Payload\n" );
>>>    $NotifyStr = $Payload;
>>>    for .backtrace.reverse {
>>>   next if .file.starts-with('SETTING::');
>>>   next unless .subname;
>>>   # $*ERR.say: "  in block {.subname} at {.file} line {.line}";
>>>   PrintRedErr( "  in block {.subname} at {.file} line
>>> {.line}\n" );
>>>    }
>>>     }
>>>     RunNoShell( "notify-send -u critical -t 0 -i \"$AlarmJpg\" \"CATCH
>>> Trap \" \"$NotifyStr\"" );
>>> }
>>>
>>>
>>> But keep pulling the following error:
>>>
>>>   No such method 'payload' for invocant of type
>>>   'X::TypeCheck::Assignment' in block 
>>>   at ./GetUpdates.pl6 line 60
>>>
>>> Line 60 is `my $Payload = .payload;`
>>>
>>> What am I doing wrong?
>>>
>>> Many thanks,
>>> -T
>
> On 2/28/19 7:27 AM, Timo Paulssen wrote:> As you can see from the
> routine page for "payload":
> >
> >  https://docs.perl6.org/routine/payload
> >
> > it only exists on X::AdHoc, which if you follow the link "from
> X::AdHoc"
> > explains:
> >
> >  X::AdHoc is the type into which objects are wrapped if they are
> > thrown as exceptions, but don't inherit from Exception.
> >
> > In your case you have a proper exception, i.e. the
> X::TypeCheck::Assignment
> >
> > In this case you'll probably want .message instead. .message on
> X::AdHoc
> > will call .Str on the payload and return that, which is basically the
> > same thing you wanted to do with the payload with
> > PrintRedErr("$Payload\n") anyway. On top of that, every Exception
> object
> > implements message.
> >
> > Hope that helps!
> >    - Timo
> >
>
> Hi Timo,
>
> That did the trick.  Thank you!
>
> Did I just trip across a bug?
>
> -T


Re: .payload

2019-02-28 Thread Timo Paulssen
As you can see from the routine page for "payload":

    https://docs.perl6.org/routine/payload

it only exists on X::AdHoc, which if you follow the link "from X::AdHoc"
explains:

    X::AdHoc is the type into which objects are wrapped if they are
thrown as exceptions, but don't inherit from Exception.

In your case you have a proper exception, i.e. the X::TypeCheck::Assignment

In this case you'll probably want .message instead. .message on X::AdHoc
will call .Str on the payload and return that, which is basically the
same thing you wanted to do with the payload with
PrintRedErr("$Payload\n") anyway. On top of that, every Exception object
implements message.

Hope that helps!
  - Timo

On 28/02/2019 12:46, ToddAndMargo via perl6-users wrote:
> Hi All,
>
> https://docs.perl6.org/language/exceptions#Catching_exceptions
>
> I am trying to place .payload into a variable `my $Payload = .payload;`
>
>
> CATCH {
>    # Reference:
> https://docs.perl6.org/language/exceptions#Catching_exceptions
>    my $NotifyStr;
>    my $Payload = .payload;
>
>    default {
>   # $*ERR.say: .payload;
>   PrintRedErr( "$Payload\n" );
>   $NotifyStr = $Payload;
>   for .backtrace.reverse {
>  next if .file.starts-with('SETTING::');
>  next unless .subname;
>  # $*ERR.say: "  in block {.subname} at {.file} line {.line}";
>  PrintRedErr( "  in block {.subname} at {.file} line
> {.line}\n" );
>   }
>    }
>    RunNoShell( "notify-send -u critical -t 0 -i \"$AlarmJpg\" \"CATCH
> Trap \" \"$NotifyStr\"" );
> }
>
>
> But keep pulling the following error:
>
>  No such method 'payload' for invocant of type
>  'X::TypeCheck::Assignment' in block 
>  at ./GetUpdates.pl6 line 60
>
> Line 60 is `my $Payload = .payload;`
>
> What am I doing wrong?
>
> Many thanks,
> -T


Re: Typed Arrays and for-loops

2019-02-13 Thread Timo Paulssen
You could use the @ sigil for your files variable, too. Then you can
just "for @files". There's two ways to get that to work:

my Str @files = "Test", "Test 2";

or

my @files := Array[Str].new("Test", "Test 2");

Hope to help
  - Timo

On 13/02/2019 13:29, Mikkel wrote:
> Hello. (recurring noob-question here)
>
> I seem always seem to get myself confused with Arrays/Typed Arrays.
> Can I ask of you to explain why the 'for' loop does not work without
> .flat? It seems so counter intuitive
>
> > my Array[Str] $files;
> (Array[Str])
>
> > $files.push("Test");
> [Test]
>
> > $files.push("Test 2");
> [Test Test 2]
>
> > for $files -> Str $f {.say}
> Type check failed in binding to parameter '$f'; expected Str but got
> Array[Str] (Array[Str].new("Test", "Test 2"))
>   in block  at  line 1
>
> Best regards
> Mikkel Birkedam


Re: subs and variables speed question

2019-02-11 Thread Timo Paulssen


> On 2/11/19 3:27 AM, Timo Paulssen wrote:
> > WHICH doesn't give you a numerical value. just print it as it is.
>
>
> $ p6 'sub a (Buf $b) { say $b.WHICH }; my $c = Buf.new(1,2,3); say
> $c.WHICH; a($c);'
> Buf|71848984
> Buf|71848984
>
> If "moarvm has a moving garbage collector" moves my 100 MB+ buffer
> around, "I am in a heap of trouble".
The buffer lives one indirection (aka pointer) away from the part that
is garbage-collector managed, so moving the object doesn't make a
difference here, luckily.


Re: subs and variables speed question

2019-02-11 Thread Timo Paulssen
WHICH doesn't give you a numerical value. just print it as it is.

On 11/02/2019 12:16, ToddAndMargo via perl6-users wrote:
> On 2/11/19 2:52 AM, Timo Paulssen wrote:
>> Please be aware that WHERE will give you the actual memory address of an
>> object, but moarvm has a moving garbage collector, which means that
>> objects can change their memory location. at the moment it will only
>> happen up to two times, i believe.
>>
>> you'll probably have a better result with .WHICH for what you want to
>> achieve.
>>
>> On 11/02/2019 07:12, ToddAndMargo via perl6-users wrote:
>>> WHERE is pretty sweet command!
>>>
>>>
>>> $ p6 'sub a (Buf $b) { say $b.WHERE.base(0x10) }; my $c =
>>> Buf.new(1,2,3); say $c.WHERE.base(0x10); a($c);'
>>>
>>> 7F385D41334C
>>> 7F385D41334C
>
> $ p6 'sub a (Buf $b) { say $b.WHICH.base(0x10) }; my $c =
> Buf.new(1,2,3); say $c.WHICH.base(0x10); a($c);'
> No such method 'base' for invocant of type 'ObjAt'. Did you mean any
> of these?
>     Hash
>     hash
>     take
>
>   in block  at -e line 1
>
>
>


Re: subs and variables speed question

2019-02-11 Thread Timo Paulssen
Please be aware that WHERE will give you the actual memory address of an
object, but moarvm has a moving garbage collector, which means that
objects can change their memory location. at the moment it will only
happen up to two times, i believe.

you'll probably have a better result with .WHICH for what you want to
achieve.

On 11/02/2019 07:12, ToddAndMargo via perl6-users wrote:
> WHERE is pretty sweet command!
>
>
> $ p6 'sub a (Buf $b) { say $b.WHERE.base(0x10) }; my $c =
> Buf.new(1,2,3); say $c.WHERE.base(0x10); a($c);'
>
> 7F385D41334C
> 7F385D41334C


Re: filever.exe sub?

2019-02-01 Thread Timo Paulssen
On 01/02/2019 01:33, Bruce Gray wrote:
> To call those Windows APIs in Perl 6, you would use NativeCall.
>

Don't forget that Todd wanted to use this on non-windows with not-wine.
NativeCall on linux won't run windows code all by itself.

That said, wine is still a good source for info on how windows things
work internally (though of course they only reverse-engineered how
windows things work, so there's often still differences in the exact
behaviour).

Here's their implementation of the version info code:

https://source.winehq.org/git/wine.git/blob/908903b7f105c62061d62959fd8d8c866095dcdc:/dlls/version/info.c

and the corresponding header file (i think?)

https://source.winehq.org/git/wine.git/blob/c84b7d33dd18651057a80f609e11f809cc7f4bd0:/include/winver.h


Normally I'd just say "good luck and have fun!", but that whole file is
very big and doesn't seem very self-explanatory at all.

I don't have time right now to go through it, but if you want to give
understanding it a try, here's a link to wine's "cross-referenced source
browser" thingie where most keywords are clickable so you can directly
find other header files, or where and how symbols/types that are used in
the code are defined:

https://source.winehq.org/source/dlls/version/version.c

Sorry for not giving a super simple solution. Perhaps there's something
on the net for "PE metadata parser" or "PE file parser" or whatever.

Hope that gets you closer to your goal!
  - Timo


Re: I need m/ help

2019-01-13 Thread Timo Paulssen
LAMITE TWO THIRDS
74855: 𒑧 CUNEIFORM NUMERIC SIGN ELAMITE FORTY
74856: 𒑨 CUNEIFORM NUMERIC SIGN ELAMITE FIFTY
74857: 𒑩 CUNEIFORM NUMERIC SIGN FOUR U VARIANT FORM
74858: 𒑪 CUNEIFORM NUMERIC SIGN FIVE U VARIANT FORM
74859: 𒑫 CUNEIFORM NUMERIC SIGN SIX U VARIANT FORM
74860: 𒑬 CUNEIFORM NUMERIC SIGN SEVEN U VARIANT FORM
74861: 𒑭 CUNEIFORM NUMERIC SIGN EIGHT U VARIANT FORM
74862: 𒑮 CUNEIFORM NUMERIC SIGN NINE U VARIANT FORM

On 13/01/2019 09:42, ToddAndMargo via perl6-users wrote:
> On 1/12/19 3:04 PM, Timo Paulssen wrote:
>> On 12/01/2019 23:40, ToddAndMargo via perl6-users wrote:
>>> But this does not.  What is wrong with (<:N>**2)  ?
>>>
>>> $ perl6 -e 'my Str $Date=DateTime.now.Str; $Date~~m/ (<:N>**4) "-"
>>> (<:N>**2) "-" (<:Nl>**2) "T" .* /; print "$Date\n\t$0  $1  $2\n"'
>>> Use of Nil in string context
>>>    in block  at -e line 1
>>> Use of Nil in string context
>>>    in block  at -e line 1
>>> Use of Nil in string context
>>>    in block  at -e line 1
>>> 2019-01-12T14:33:10.692302-08:00
>>>
>>>
>>> Many thanks,
>>> -T
>>
>>
>> Hi Todd,
>>
>> it looks like you have an accidental l in there: the third capture group
>> has <:Nl> instead of <:N>.
>>
>> Changing that makes it work for me
>>    - Timo
>>
>
> Hi Timo,
>
> Just out of curiosity, what is the difference between "Number (<:N>)"
> and "Number Like (<:Nl>)"?  What would they not be the same in this
> context?
>
> My latest:
>
> $ perl6 -e 'DateTime.now.Str ~~ m/ (<:N>+) "-" (<:N>+) "-" (<:N>+) "T"
> .* /; my Str $Po="$1$2x$0_"; $Po~~s/x20//;print "$Po\n";'
>
> 011319_
>
> I stuck the "x" in there so I would not clobber day = 20.
>
> -T


Re: I need m/ help

2019-01-12 Thread Timo Paulssen
On 12/01/2019 23:40, ToddAndMargo via perl6-users wrote:
> But this does not.  What is wrong with (<:N>**2)  ?
>
> $ perl6 -e 'my Str $Date=DateTime.now.Str; $Date~~m/ (<:N>**4) "-"
> (<:N>**2) "-" (<:Nl>**2) "T" .* /; print "$Date\n\t$0  $1  $2\n"'
> Use of Nil in string context
>   in block  at -e line 1
> Use of Nil in string context
>   in block  at -e line 1
> Use of Nil in string context
>   in block  at -e line 1
> 2019-01-12T14:33:10.692302-08:00
>
>
> Many thanks,
> -T


Hi Todd,

it looks like you have an accidental l in there: the third capture group
has <:Nl> instead of <:N>.

Changing that makes it work for me
  - Timo


Re: I need hash inside a hash help

2019-01-11 Thread Timo Paulssen
Hi Todd,

the error you're getting comes from a closing quotation mark missing
after "Larry

You will also need to give perl6 some hint that you want the list of
pairs to actually become a hash.

To do that, I would recommend just putting a % in front of the ()

The working code looks like this:

perl6 -e 'my %Vendors=("acme" => %( "ContactName" => "Larry",
"AccountNo" => 1234 ) ); say %Vendors;'
{acme => {AccountNo => 1234, ContactName => Larry}}

Hope that helps!
  - Timo

On 11/01/2019 19:41, ToddAndMargo via perl6-users wrote:
> Hi All,
>
> How do I do a hash inside a hash?
>
> So far I have:
>
> $ p6 'my %Vendors=("acme" => ( "ContactName" => "Larry, "AccountNo" =>
> 1234 ) ); say %Vendors;'
> ===SORRY!=== Error while compiling -e
>
>
> I want to be able to have both a Contact Name and and AccountNo
> associated with each key in %Vendors.
>
>
> Many thanks,
> -T


Re: Exactly what is type match?

2018-12-21 Thread Timo Paulssen

> Like this? > > $ p6 'my $x="11.2."; my Str $D0; my Str $D1; $x~~m{ (<:N>+) 
> [.] >
(\d+)}; $D0 ~= $0; $D1 ~= $1; print "$D0 $D1\n";' > > 11 2 >

There's an important difference between "$D1 ~= $0" and "$D1 = ~$0".
They only do the same thing if $D0 (and $D1) are empty at that point; if
they have something in them, the result will be the concatenation of
$D0's current content and $0's content (same thing with $D1 and $1).

~= is an operator that is formed as a combination of ~ and "assignment".
"$a ~= $b" does almost the same as "$a = $a ~ $b". it works for every
infix operator, too:

$a += 1 is probably known to many

$a max= 5 will leave $a containing either $a or 5, whichever is higher

$a **= 2 will leave $a with the result of $a ** 2

and so on, and so forth.

Does that clear things up?
  - Timo



Re: Exactly what is type match?

2018-12-21 Thread Timo Paulssen


On 21/12/2018 20:38, ToddAndMargo via perl6-users wrote:
> $ p6 'my $x="11.2."; my Str $D0; my Str $D1; $x~~m{ (<:N>+) [.] (\d+)
> }; $D0 ~$0; $D1 ~ $1;  print "$D0 $D1\n";'
> WARNINGS for -e:
> Useless use of "~" in expression "$D1 ~ $1" in sink context (line 1)
> Useless use of "~" in expression "$D0 ~$0" in sink context (line 1)
> Use of uninitialized value of type Str in string context.
> Methods .^name, .perl, .gist, or .say can be used to stringify it to
> something meaningful.
>   in block  at -e line 1
> Use of uninitialized value of type Str in string context.
> Methods .^name, .perl, .gist, or .say can be used to stringify it to
> something meaningful.
>   in block  at -e line 1
> Use of uninitialized value of type Str in string context.
> Methods .^name, .perl, .gist, or .say can be used to stringify it to
> something meaningful.
>   in block  at -e line 1
> Use of uninitialized value of type Str in string context.
> Methods .^name, .perl, .gist, or .say can be used to stringify it to
> something meaningful.
>   in block  at -e line 1


The trouble here is that what you have coded here is

"create the concatenation of $D0 and $0, then create the concatenation
of $D1 and $1". The compiler tells you that just creating the
concatenation and not doing anything with it (like storing it into a
variable) is useless, and probably wrong.

Then you get errors for using uninitialized Str, which $D0 and $D1 are
in both situations (since you never assign anything to it).

What you need is to put a = between $D0 and ~$0 and between $D1 and ~$1

That should work.

Hope that made some sense
  - Timo


Re: wxWidgets nativecall

2018-11-27 Thread Timo Paulssen
I haven't looked at wxwidgets with perl6, and the last time I used it
was with python many moons ago.

But I think the "AST converter" you're refering to is probably
App::GPTrixie - https://github.com/Skarsnik/gptrixie

If you have more questions, feel free to ask on the mailing list, or on
Stack Overflow, or real-time discussions on IRC, links can be found on
perl6.org

I haven't actually tried the C++ stuff in NativeCall, but we can surely
figure it out together :)

HTH
  - Timo

On 21/11/2018 03:31, Perry Sebastian wrote:
> Hi,
> I built an odd little application using wxPerl. The code worked ok,
> but I dislike the object interface and it does not mesh with P6. The
> big issue is that wxPerl gets built and tied to wxWidgets C++ code -
> the two are linked so you are basically stuck with that module to
> access wxWidgets. I have looked at NativeCall and some AST converter
> (can't seem to find it anymore). I'm not real thrilled about hacking C
> code, but I'm thinking that I might be able to NativeCall the wxWindow
> base class or wxFrame and then treat that as a P6 object - a windowing
> object. Any calls to window functions would have to use NativeCall,
> too, but the window object could accept roles and have async behaviors.
> Anyone else looking at this?
> Perry 


Re: How to use sub/method 'dir'

2018-11-24 Thread Timo Paulssen
The dir method gives you entries in the directory you pass. If you don't
pass a test it'll use the default test which is none(".", ".."), i.e.
"anything except . and ..".

I'm not sure why using { .IO.d } as the test would not give you b,
though. Can you check what "a/b".IO.d outputs? Maybe that can give us a
clue.

HTH
  - Timo

On 24/11/2018 22:18, Fernando Santagata wrote:
> Hello,
>
> I think that I don't understand how the 'test' argument of 'dir' works.
> I have a directory 'a', which contains a subdirectory 'b' and a file
> 'c'; I want to select only the subdirectories of 'a'.
>
> Using the REPL I tried to ask the content of the directory 'a':
>
> > my @dirs = dir('a')
> ["a/c".IO "a/b".IO]
> > my @dirs = dir('a', test => { .IO.d })
> ["a/.".IO "a/..".IO]
> Why omitting the test the code returns the right list, while adding
> the test it returns just '.' and '..'?
>
> If I do the same thing for the top level directory '.' the behavior is
> different:
>
> > my @dirs = dir('.', test => { .IO.d })
> [".".IO "a".IO "..".IO]
>
> Now I can see the directory 'a'.
> If I descend a level, doing a 'cd a', the behavior is consistent with
> what I see at the previous level.
> I'm confused.
>
> I'm using version 2018.10.
>
> -- 
> Fernando Santagata


Re: sub name has unexpected interaction with s///

2018-10-23 Thread Timo Paulssen
Hi Richard,

I wouldn't call s/// a routine. It's actually (implemented as) a kind of
quote, like Q, q, qq, qw, and also rx, and tr. I consider that an
important distinction, because the syntax with which you call s/// is
very different from how you call a sub. You can't just `say '(' ~ ')'
1234`, because regular perl6 syntax doesn't allow two terms in a row (in
this case the string ")" and the number 1234).

I'd say it more like "subroutines have precedence over some special
syntax", and "s/ b /x" will be parsed like "s() / b() / x()", but b and
x aren't defined, so it errors out at the end of compilation.

I hope that makes things a bit clearer
  - Timo


Re: Testing Was: Appropriate last words

2018-10-21 Thread Timo Paulssen
I think you would just have something like this in your test program's
mainline:

    my &*EXIT = -> | { die "exit was called" }

and then you can use dies-ok. Bonus points for creating your own
exception class so that you can check that it was actually &*EXIT that
got you there, and not some random exception like "file not found".

On 21/10/2018 10:32, Richard Hainsworth wrote:
> How does this answer the question about testing?
>
> Ok so there is code, but where do I go to find what that code is?
> Where in the Rakudo repo would I start looking, eg.?
>
>
> On 21/10/18 16:23, Timo Paulssen wrote:
>> https://docs.perl6.org/language/variables#index-entry-%24%2AEXIT
>>
>> this should help you get to where you want to be.
>>
>> Someone™ can feel free to open up a ticket on the doc repository that
>> the routine page for exit doesn't have a link to or explanation of
>> &*EXIT.
>>
>> HTH
>>    - Timo


Re: Testing Was: Appropriate last words

2018-10-21 Thread Timo Paulssen
https://docs.perl6.org/language/variables#index-entry-%24%2AEXIT

this should help you get to where you want to be.

Someone™ can feel free to open up a ticket on the doc repository that
the routine page for exit doesn't have a link to or explanation of &*EXIT.

HTH
  - Timo


Re: Run tests only if a module is available

2018-10-11 Thread Timo Paulssen
I'd go with run-time loading and if the module doesn't exist, just
"flunk" or "skip" or what Test.pm6 offers.

Here's a link that explains checking if a module is installed and
loading it if it is:

    https://rakudo.org/post/lexical-require-upgrade-info

Hope that helps!
  - Timo

On 11/10/2018 19:08, Fernando Santagata wrote:
> Hello,
>
> I wish to run some tests on one module of mine only if there's a
> certain third-party module available during installation.
> Before I concocted something horrid using try/catch in the INIT
> phaser, is there any gentle way to do this?
>
> Thanks!
>
> -- 
> Fernando Santagata


Re: Use of the --output flag

2018-10-09 Thread Timo Paulssen
--output is for the compiler's compilation stages

for example:

> timo@schmand ~> perl6 --output=/tmp/outputtest --target=mbc -e 'say "hi"'
> timo@schmand ~> moar --dump /tmp/outputtest | head
>
> MoarVM dump of binary compilation unit:
>
>   SC_0 : B1DFAD9164F11E967B354508CC458ABAB8DEDC27
>   SC_1 : D71FD1C8B1B40FC9B294068F2EC29C505914FDC6-0
>   SC_2 : 0808522FF10EC773B02A4C55883CC154BB964DE2
>   Callsite_0 :
>     num_pos: 0
>     arg_count: 0
>   Callsite_1 :


Most of the compilation stages don't work with --output, which could be
a bug. However, --output isn't supposed to change what $*OUT is set to
in the script.

Hope that helps
  - Timo


On 09/10/2018 15:18, Simon Proctor wrote:
> So... I'm working through some notes for a talk on Thursday and I am
> trying to work out how the --output flag is supposed to work.
>
> I would expect this to create a file called test and print "Hi\n" in it :
>
> perl6 --output=test -e 'say "Hi"'
>
> But instead I got Hi printed to the command line and an error :
>
> Use of Nil in string context
>   in any print at gen/moar/stage2/NQPCORE.setting line 850
>
> Trying use it on a sime file (say "Hi") and it also doesn't do that.
>
> (Note that the test file is created but it's empty).
>
> Any ideas?
>
> -- 
> Simon Proctor
> Cognoscite aliquid novum cotidie
>
> http://www.khanate.co.uk/


Re: bitwise or?

2018-10-05 Thread Timo Paulssen
Yes, there is an absolutely tiny mention of it on the page:

Metaoperators

Metaoperators can be parameterized with other operators or subroutines
in the same way as functions can take functions as parameters. To use a
subroutine as a parameter, prefix its name with a &. Perl 6 will
generate the actual combined operator in the background, allowing the
mechanism to be applied to user defined operators. *To disambiguate
chained metaoperators, enclose the inner operator in square brackets.*
There are quite a few metaoperators with different semantics as
explained, next.

If that's even the part you're asking about, that is. And yes, I would
consider that LTA, making it easier to find, for example by adding an
example or maybe even a sub-heading, would be really good. Who wants to
open a ticket? :)

If you want an example of a disambiguated metaop, try something like Z+=
which could either be [Z+]= or Z[+=].

On 06/10/2018 00:36, Trey Harris wrote:
>
> On Fri, Oct 5, 2018 at 8:33 AM Timo Paulssen t...@wakelift.de
> <http://mailto:t...@wakelift.de> wrote:
>
> It's important to point out that inside metaoperators ("composed
> operators", "combined operators", ...) the [ ] are just for bracketing
> things together — sometimes it's needed to disambiguate, but you
> can put
> it in anyway to make things clearer.
>
> This has nothing to do with [+] 1, 2, 3, which is a way to spell "add
> these three numbers together".
>
> Timo—is this fact formalized in the docs? I can’t find it.
> https://docs.perl6.org/routine/= doesn’t mention it, and while
> https://docs.perl6.org/language/operators#Assignment_operators gives
> an example of using it (with |+=|, |-=|, |min=| and |~=|), I can’t
> find the metaoperator version’s definition.
>
>
> On 05/10/2018 14:26, Brad Gilbert wrote:
> > Note that = is actually a meta operator that can take an infix
> > operator as an argument
> >
> > So
> >
> >     $a += 1
> >
> > is really short for
> >
> >     $a [+]= 1
> >
> > On Fri, Oct 5, 2018 at 1:02 AM Todd Chester
> mailto:toddandma...@zoho.com>> wrote:
> >>
> >>
> >> On 10/4/18 12:13 PM, Brandon Allbery wrote:
> >>> It's fine syntactically, but I think has no effect because
> it'd be '$v =
> >>> $v' after the '+|='. Conceivably some future version of rakudo
> could
> >>> warn about it having no effect.
> >> That explains it.  Thank you!
>


Re: routine declaration line question

2018-10-05 Thread Timo Paulssen
You're probably thinking of ;; in a signature.

On 05/10/2018 20:02, Trey Harris wrote:
> But right now we have a situation where “everything within the
> signature /except for/ the return constraint can participate in multi
> dispatch”, which does feel weird. But is that actually true?
> Something’s nagging at me that there’s something else in this category
> as well, but I can’t think what. (Recursive multi dispatch on
> signatures of multi |Callable| arguments, maybe? I would try but my
> machine’s offline upgrading….) If there are more rules about what
> participates in multi dispatch than “change anything in the signature
> to the left of the |-->| and you’re good”, then it’s probably
> acceptable for |-->| to not participate either—it’s already more
> complex than it looks.
> ​


Re: bitwise or?

2018-10-05 Thread Timo Paulssen
It's important to point out that inside metaoperators ("composed
operators", "combined operators", ...) the [ ] are just for bracketing
things together — sometimes it's needed to disambiguate, but you can put
it in anyway to make things clearer.

This has nothing to do with [+] 1, 2, 3, which is a way to spell "add
these three numbers together".

On 05/10/2018 14:26, Brad Gilbert wrote:
> Note that = is actually a meta operator that can take an infix
> operator as an argument
>
> So
>
> $a += 1
>
> is really short for
>
> $a [+]= 1
>
> On Fri, Oct 5, 2018 at 1:02 AM Todd Chester  wrote:
>>
>>
>> On 10/4/18 12:13 PM, Brandon Allbery wrote:
>>> It's fine syntactically, but I think has no effect because it'd be '$v =
>>> $v' after the '+|='. Conceivably some future version of rakudo could
>>> warn about it having no effect.
>> That explains it.  Thank you!


Re: routine declaration line question

2018-10-03 Thread Timo Paulssen
I just spotted a grave mistake in my earlier mail:

the --> constraints are validated at *run* time, not *compile* time;
that's a very big difference, and an important one. Of course "every
time a sub or method returns" doesn't make much sense if i had meant
"compile time", but I felt i should really point it out before causing
too much confusion.

On 04/10/2018 03:07, ToddAndMargo wrote:
> Hi All,
>
> In another thread, Timo wrote me:
>
>    The "-->" part of the signature is optional. If there isn't
>    one, it defaults to Mu, which is the type that everything
>    conforms to, i.e. the sub or method that either has "--> Mu"
>    explicitly, or has it by leaving it out, may return
>    absolutely whatever it wants.
>
>    After all, the "-->" part is a constraint, and it gets
>    validated at compile time every time a sub or method
>    returns.
>
> I got to thinking, some routines do not return anything.  Without
> the "-->" constraint, how am I to determine if something is
> being returned?
>
> Yours in confusion,
> -T


Re: What are the official names?

2018-10-02 Thread Timo Paulssen
I just saw that this was already kind of answered in the other thread,
sorry about that!


Re: What are the official names?

2018-10-02 Thread Timo Paulssen
On 03/10/2018 01:50, ToddAndMargo wrote:
> On 10/2/18 4:47 PM, David Green wrote:
>> On 2018-10-02 4:06 pm, ToddAndMargo wrote:
>>> What is the official Perl syntaxland name of the [] subroutine?
>> If you search for "[]" at https://docs.perl6.org, it will turn up the
>> routine "postcircumfix [ ]", which links to
>> 
>>
>> https://docs.perl6.org/language/subscripts
>> 
>>
>>
>>
>> -David
>>
>
> Thank you!
>
> One down, one to go!
>
> :-)


The same page you already found by searching for [ ] in the search bar
also gives you the explanation of the other [ ], i.e. the one used in my
@a = [1, 2, 3].

It is perhaps less visible than desirable, as it doesn't come with an
example, but the category it's in, namely "circumfix" can clue you in
that it means the one in [1, 2, 3]. circumfix means "goes around", like
prefix means "goes before" or infix means "in between". postcircumfix is
kind of a combination of postfix and circumfix where there is one thing
that the routine goes after, and another thing that the routine goes
around. That's how you get @a[1]; the [ ] from the view of @a is a
postfix and from the view of 1 is a circumfix. Hence, postcircumfix.

Hope that helps
  - Timo


Re: need doc help with []

2018-10-02 Thread Timo Paulssen
Hi Todd,

On 03/10/2018 02:14, ToddAndMargo wrote:
> sub postcircumfix:<[ ]>(@container, **@index,
>     :$k, :$v, :$kv, :$p, :$exists, :$delete)
>
> 1  Why the <[]>?  I have always used [] with out the <>.
>    Why would I want to use one over the other?
>
> 2)  Where does it state that the <> is optional?


postcircumfix:<[ ]> is the "real name" of the [ ] postfix operator. In
this case the < > are just how it's quoted, i.e. this is how you
communicate to perl6 where the name starts and ends. It is also in other
operator's names, like infix:<+> for the + operator, or postfix:<++> for
the ++ postfix operator. If your operator itself contains a < or a >,
you can instead use ['blah'] for the quoting, like infix:['<'] for the <
operator. As you can see, it's more or less different ways to write what
is essentially a string. Just like you have "foo" and 'foo' but also
q, q«foo», and anything else you want to come up with.


> 6)  Where is the --> return described?


The "-->" part of the signature is optional. If there isn't one, it
defaults to Mu, which is the type that everything conforms to, i.e. the
sub or method that either has "--> Mu" explicitly, or has it by leaving
it out, may return absolutely whatever it wants.

After all, the "-->" part is a constraint, and it gets validated at
compile time every time a sub or method returns.


> Yours in confusion,
> -T


Hope that helps a little
  - Timo


Re: Could this be any more obscure?

2018-09-26 Thread Timo Paulssen
You're still missing that the words method doesn't "take the [2,4]". The
operation that [2,4] does takes place after the words() thing has
already done its work.

You could actually say that every method takes [0]. Try it!

Your confusion looks a bit similar to seeing

    multi sub exp(Cool:D $pow, Cool:D $base?)

and the example code

    say exp(2, 10) + 5

and then asking "where in the multi sub exp in the docs does it say that
i can add 5?"

They are separate things that work together.

The return value of words being Positional means mainly that it gives
you something you can use [ ] on.

The part of words where it says $limit = Inf means that if no number is
passed there, that the value Inf is used. Inf is not a Type, and even
though you can put a type on the right side of an assignment, it will
"just" be used as a value.

I'm not sure why you wrote "I am NOT asking it to limit my request to
Infinity.", maybe if you explain that a little more we can figure out
better what's confusing you.


> Where does
>
>     multi method words(Str:D $input: $limit = Inf --> Positional)
>
> state that I can do such?
>
> I ask this because not all methods will take []
>
>
> $ p6 '"a b c d e".contains( "a","b" ).say;'
> Cannot convert string to number: base-10 number must begin with valid
> digits or '.' in '⏏b' (indicated by ⏏)
>   in block  at -e line 1
>
> $ p6 '"a b c d e".contains( 1, 3 ).say;'
> Ambiguous call to 'contains(Str: Int, Int)'; these signatures all match:
> :(Str:D: Cool:D $needle, Cool:D $pos, *%_)
> :(Str:D: Cool:D $needle, Cool:D $pos, *%_)
>   in block  at -e line 1


You aren't using [] there, you're just putting the strings and numbers
inside the (), which is the difference that people are trying to
explain, but not finding the right words to make you understand. Can you
help us by explaining how you get from "every method takes [ ]" to "i'll
try it with ()"? Perhaps some place wrongly claimed that () and [] are
the same? That might require a bit of re-wording in the docs, then.

Hope any of that helps
  - Timo


Re: Ping Larry and Friends: Need NativeCall help

2018-09-18 Thread Timo Paulssen
Hey Todd,

XLib is indeed very difficult to use even from C, and Perl 6 alone
doesn't help terribly much.

However, there is a library called xcb that is meant to give you what
XLib has, but less terrible.

I haven't used it myself, nor really looked at it, but I hear it's much
less painful.

Hope that helps!
  - Timo


Re: need p5/p6 :: help

2018-09-14 Thread Timo Paulssen
It's important for the PrintRed sub inside PrintColors to be declared
"our", otherwise it is "my" scoped, i.e. limited to the lexical extent
of the module file.

On 14/09/2018 12:59, Todd Chester wrote:
> Hi All,
>
> I am in the process of converting a YUGE program I wrote in
> Perl 5 to Perl 6.  I used "xx::yy" at lot for readability
> so I could tell where something came from.
>
> I take it "::" means something different is Perl 6 than Perl 5.
>
> $ p6 'use lib "/home/linuxutil"; use PrintColors;
> PrintColors::PrintRed "Hi\n";'
>
> Could not find symbol '&PrintRed'
>   in block  at -e line 1
>
> In p5 "PrintColors::PrintRed" means to use the routine called
> "PrintRed" found in a modules called "PrintColors".
>
> Does p6 have an equivalent?
>
> Many thanks,
> -T


Re: I need -M help

2018-09-14 Thread Timo Paulssen
The equivalent of "use lib 'blah'" on the commandline is "-I blah", just
like "-M bloop" is the equivalent of "use 'bloop'" in code.

HTH
  - Timo

On 14/09/2018 12:52, Todd Chester wrote:
> Hi All,
>
> With a one liner, how to I load a module that resides in the
> current directory?
>
> $ ls PrintColors.pm6
> PrintColors.pm6
>
>
> $ perl6 -MPrintColors -e 'PrintRed "Hi";'
> ===SORRY!===
> Could not find PrintColors at line 1 in:
>     /home/tony/.perl6
>     /opt/rakudo-pkg/share/perl6/site
>     /opt/rakudo-pkg/share/perl6/vendor
>     /opt/rakudo-pkg/share/perl6
>     CompUnit::Repository::AbsolutePath<58670368>
>     CompUnit::Repository::NQP<53138976>
>     CompUnit::Repository::Perl5<53139016>
>
>
> $ perl6 -M./PrintColors -e 'PrintRed "Hi";'
> ===SORRY!===
> Could not find ./PrintColors at line 1 in:
>     /home/tony/.perl6
>     /opt/rakudo-pkg/share/perl6/site
>     /opt/rakudo-pkg/share/perl6/vendor
>     /opt/rakudo-pkg/share/perl6
>     CompUnit::Repository::AbsolutePath<53332448>
>     CompUnit::Repository::NQP<47798144>
>     CompUnit::Repository::Perl5<47798184>
>
>
> This works:
> $ p6 'use lib "/home/linuxutil"; use PrintColors; PrintRed "Hi\n";'
> Hi
>
> But how do I get it into the "-M"?
>
> Many thanks,
> -T


Re: .new?

2018-09-14 Thread Timo Paulssen
The doc website creates the pages under "routine/" by collecting every
type's methods and relevant subs of that name and putting them all on a
page.

It's a very unfortunate accident that the one for Telemetry::Sampler
ends up at the top, because right below that is the one for Mu, which is
the most general one that also links to the "documentation on object
construction" where things are explained clearly in a tutorial style.

Telemetry::Sampler isn't a routine, it's a class. You can follow the
link labelled "from Telemetry::Sampler" to get to the documentation of
the class by that name, which explains what it is, how you get it, and
how you use it.

I'll file a bug for the "new" routine page.

Hope that helps!
  - Timo

On 14/09/2018 12:30, Todd Chester wrote:
> Hi All,
>
> What exactly is going on with .new?
>
>   https://docs.perl6.org/routine/new
>   method new(Telemetry::Sampler: @instruments --> Telemetry::Sampler:D)
>
> The whole thing went over my head.  It looks like
> specifications for the developers, but I really can't
> tell.  And it looks like it might be really handy.
>
> What can I use it for?
>
>
> Also, does "Telemetry::Sampler" mean what it does in Perl 5,
> which is a routine called "Sampler" found in the module
> called "Telemetry"?
>
> Many thanks,
> -T


Re: how do I do this index in p6?

2018-09-11 Thread Timo Paulssen
On 11/09/18 17:11, yary wrote:
> "Nil... it's a constant, so you have to use =:= to check for equality."
>
> Can you elaborate on that requirement? == works for an equality checks
> with numeric constants- must be more than Nil's constant-ness that
> makes one use =:= - perhaps that Nil doesn't numify to anything?

Nil does numify, but using == comparison for this is still problematic
for two reasons:

1) Nil numifies to 0, which is a valid "true" result for the index
method and
2) it outputs a warning:

    Use of Nil in numeric context
      in block  at -e line 1

using ~~ instead of =:= should also be okay, or checking for definedness
with either .defined or using "with" instead of "if", which is very
useful especially for index and friends.

HTH
  - Timo


Re: Please explain this to me

2018-09-11 Thread Timo Paulssen
On 11/09/18 12:50, ToddAndMargo wrote:
> On 09/11/2018 03:09 AM, ToddAndMargo wrote:
>> multi method contains(Str:D: Cool:D $needle, Int(Cool:D) $pos)
>
> What the heck (not my exact word) is "multi method"?
>
> What is wrong with calling it a "function"?

Multi Methods are methods that do "multiple dispatch", which means more
or less "there are different candidates that can be called, and it
depends on the arguments you pass. They are matched against the
signatures of the candidates and the most appropriate one is called for
you".

Here's an example:

class TestClass {
    multi method test-method(Str $input) {
        say "this version of test-method is for strings";
    }

    multi method test-method(Int $input) {
        say "this version of test-method is for integers"
    }
}

my $tc = TestClass.new;
$tc.test-method("hello");
$tc.test-method(1234);

So you have the same name, but multiple candidates that have different
signatures.

Does that help?
  - Timo


Re: Please explain this to me

2018-09-11 Thread Timo Paulssen
On 11/09/18 12:38, Curt Tilmes wrote:
>
> On Tue, Sep 11, 2018 at 6:27 AM ToddAndMargo  > wrote:
>
> method ($a: @b, %c) {};       # first argument is the invocant
>
>
> I might say rather that $a is a parameter for the invocant.  The @b
> parameter holds all the positional arguments, %c holds the named
> arguments.

Just a little correction, @b and %c would contain the positionals and
nameds only if they have a * in front. In the example here they are both
just a single positional argument. I would claim this is misleading,
though, since "first an @ parameter, then a % parameter" is so often the
pattern for "take all positionals and all nameds" (in which case they
would each have a * in front), but here that's not the case.


Re: Please explain this to me

2018-09-11 Thread Timo Paulssen
On 11/09/18 12:23, ToddAndMargo wrote:
> As I understand it $needle? is the second optional parameter
> and it is an integer, not "Cool" (both a string and a number).

Where did you get "$needle?" from? I'm looking at the docs for method
"contains" of type Str right now and it only says that $pos is optional.

The : after Str:D means that it applies not to a parameter you put into
the parenthesis, but to the object you're calling the method on.

That means that $needle is actually the first parameter, not the second one.

> I presume "Cool" includes real numbers too.

Yes, types that are derived from Cool can be coerced to numbers, or strings.

> I have no idea how they got from
>
> multi method contains(Str:D: Cool:D $needle, Int(Cool:D) $pos)
>
> to
>
> $ p6 'say "abc".contains("b");'
> True

I hope the comments I made above made this a little clearer.

I also see that the paragraph directly below the different multi
candidates in the docs mention how the Str:D: works, as well. Though
that page was last edited only 23 hours ago, so maybe you're looking at
an outdated page?

> Perl 6's function reference has got to be the hardest
> to understand I have ever come across.  Perl 5's
> "perldocs -v" were a bazillion times easier to understand.
>
> -T

Understanding signature syntax is very important, and the signature
syntax alone already tells you a lot about how a sub or method works.
Since the signatures are so expressive, they can of course also be "a
bit much" to understand, unfortunately.

Hope that helps
  - Timo


Re: Please explain this to me

2018-09-11 Thread Timo Paulssen
On 11/09/18 12:18, JJ Merelo wrote:
>
>
> El mar., 11 sept. 2018 a las 12:15, Timo Paulssen ( <mailto:t...@wakelift.de>>) escribió:
>
> The colon at the end of "Str:D:" signifies that it's a type
> constraint on what you call the method on. For example:
>
>
> That, of course, is also in the documentation:
> https://docs.perl6.org/type/Signature#index-entry-type_constraint_%3AD
> (maybe not with the same words, and maybe it can be improved, but still)
>
> You just have to type :D in the search slot.
>
> JJ
>

I believe you linked to the wrong section,
https://docs.perl6.org/type/Signature#Parameter_separators is where the
colon at the end is explained.

Though you cannot search for :D: and get to somewhere that explains it,
and searching for :D:, which is a very common usage for the invocant
colon, doesn't lead you to this section, either.
  -Timo


Re: Please explain this to me

2018-09-11 Thread Timo Paulssen
The colon at the end of "Str:D:" signifies that it's a type constraint
on what you call the method on. For example:

my Str $foo;
$foo.contains("hello", 0);

won't work because $foo is currently not defined, i.e. doesn't pass the
:D constraint. The : at the end means that the constraint "Str:D"
applies to what's before the method call, in this case $foo.

In this signature, the needle is not optional, and it doesn't make sense
to me to have it optional. What would it mean to ask if a string
contains, but not what it's supposed to contain?

Without having to look at the docs, I would expect $pos to mean the
position in the string that should be checked for presence of the needle
(as in: find a needle in a haystack).

The return value isn't shown in this definition, but I'd say that's an
oversight that should be fixed.

I hope that helps!
  - Timo


On 11/09/18 12:09, ToddAndMargo wrote:
> multi method contains(Str:D: Cool:D $needle, Int(Cool:D) $pos)
>
> Okay, I know that
>    Str is a string
>    Cool is an object that can be treated as both a string and a number
>    $needle is the second optional parameter
>
> What is "D"?
>
> $needle is optional, why is it not stated as "$needle?"
>
> How is both Str:D: and Cool:D the first parameter?
>
> Why does "Str:D:" have a colon on the end and "Cool:D" does not?
>
> What is Int(Cool:D) ?
>
> What is $pos ?
>
> Where is it stated that it has a return a value?
>
> Where is it state that the return value is a boolean?
>
> Yours in confusion,
> -T



Re: "contains" beginning, end?

2018-09-07 Thread Timo Paulssen
It does not, but there are methods .starts-with and .ends-with that
probably do what you need.

HTH
  - Timo


On 08/09/18 02:00, ToddAndMargo wrote:
> Hi All,
>
> Does "contains" have options for "at the start of" and
> "at the end" of matches?
>
>
> Many thanks,
> -T


Re: A grammar to provide substitution

2018-08-29 Thread Timo Paulssen
I should point out that the trans method has a mode that lets you pass
placeholders and substitutions and it will Do The Right Thing regarding
overlaps and order and everything.


On 29/08/18 16:21, Timo Paulssen wrote:
> There's a problem with your code, if any of the substitutions contains
> something that looks like the placeholder thing, and if it comes later
> in the iteration of the hash keys (which is randomized now) it will
> substitute again. This is very likely not what you want, though.
>
> HTH
>   - Timo
>
> On 28/08/18 20:04, Laurent Rosenfeld via perl6-users wrote:
> > Hi Patrick, > > for note that this codeline: > > my Str $input = "Here be a
> $(placeholder), for $(purpose) purposes."; > > will not compile
> because Perl will try to interpolate $(placeholder) and $(purpose) as
> vairables that have not been declared. > > You need to use non
> interpolating quotes: > > my Str $input = 'Here be a $(placeholder),
> for $(purpose) purposes.'; > > Then, I would probably use simple
> substitutions, as with this example: > > my Str $input = 'Here be a
> $(placeholder), for $(purpose) purposes.'; > > sub format-string
> ($input, %substitutions) { > my $str = $input; > for keys
> %substitutions -> $key { > $str ~~ s/$key/%substitutions{$key}/; > } >
> return $str; > } > my %substitutes = '$(placeholder)' =>
> "placeholder", '$(purpose)' => "testing"; > my $output =
> format-string($input, %substitutes); > say $output; > > This is the
> output running this under the REPL: > > > my Str $input = 'Here be a
> $(placeholder), for $(purpose) purposes.'; > Here be a $(placeholder),
> for $(purpose) purposes. > > > > sub format-string ($input,
> %substitutions) { > * my $str = $input; > * for keys %substitutions ->
> $key { > * $str ~~ s/$key/%substitutions{$key}/; > * } > * return
> $str; > * } > sub format-string ($input, %substitutions) {
> #`(Sub|214745424) ... } > > my %substitutes = '$(placeholder)' =>
> "placeholder", '$(purpose)' => "testing"; > {$(placeholder) =>
> placeholder, $(purpose) => testing} > > my $output =
> format-string($input, %substitutes); > Here be a placeholder, for
> testing purposes. > > say $output; > Here be a placeholder, for
> testing purposes. > > I hope this helps. > > Cheers, > Laurent. > > >
> > > Le mar. 28 août 2018 à 12:25, Patrick Spek via perl6-users
> mailto:perl6-users@perl.org>> a écrit : >
>> Hi all,
>>
>> I'm trying to substitute parts of a string, and thought this might be a
>> good use of a grammar. Sadly, grammars aren't my strong suit, so I
>> thought I'd ask the wider community for help. Maybe you guys know an
>> even better solution than using a grammar here.
>>
>> So, consider a string, "Here be a $(placeholder), for $(purpose)
>> purposes.". I want to be able to put that into a sub, along with some
>> Pairs, and get a string with the placeholders replaced back.
>>
>>     my Str $input = "Here be a $(placeholder), for $(purpose) purposes.";
>>     my Str $output = format-string(
>>     $input,
>>     placeholder => "placeholder",
>>     purpose => "testing",
>>     );
>>
>>     dd $output; # "Here be a placeholder, for testing purposes."
>>
>> The `format-string` sub would call the grammar and apply the actual
>> substitution, and that's where I need your help. I am not quite sure
>> how I would implement the grammar (and presumably it's actions) to do
>> what I want.
>>
>> Thanks in advance for your help!
>>
> >
>



Re: A grammar to provide substitution

2018-08-29 Thread Timo Paulssen
There's a problem with your code, if any of the substitutions contains
something that looks like the placeholder thing, and if it comes later
in the iteration of the hash keys (which is randomized now) it will
substitute again. This is very likely not what you want, though.

HTH
  - Timo

On 28/08/18 20:04, Laurent Rosenfeld via perl6-users wrote:
> Hi Patrick, > > for note that this codeline: > > my Str $input = "Here be a
$(placeholder), for $(purpose) purposes."; > > will not compile because
Perl will try to interpolate $(placeholder) and $(purpose) as vairables
that have not been declared. > > You need to use non interpolating
quotes: > > my Str $input = 'Here be a $(placeholder), for $(purpose)
purposes.'; > > Then, I would probably use simple substitutions, as with
this example: > > my Str $input = 'Here be a $(placeholder), for
$(purpose) purposes.'; > > sub format-string ($input, %substitutions) {
> my $str = $input; > for keys %substitutions -> $key { > $str ~~
s/$key/%substitutions{$key}/; > } > return $str; > } > my %substitutes =
'$(placeholder)' => "placeholder", '$(purpose)' => "testing"; > my
$output = format-string($input, %substitutes); > say $output; > > This
is the output running this under the REPL: > > > my Str $input = 'Here
be a $(placeholder), for $(purpose) purposes.'; > Here be a
$(placeholder), for $(purpose) purposes. > > > > sub format-string
($input, %substitutions) { > * my $str = $input; > * for keys
%substitutions -> $key { > * $str ~~ s/$key/%substitutions{$key}/; > * }
> * return $str; > * } > sub format-string ($input, %substitutions) {
#`(Sub|214745424) ... } > > my %substitutes = '$(placeholder)' =>
"placeholder", '$(purpose)' => "testing"; > {$(placeholder) =>
placeholder, $(purpose) => testing} > > my $output =
format-string($input, %substitutes); > Here be a placeholder, for
testing purposes. > > say $output; > Here be a placeholder, for testing
purposes. > > I hope this helps. > > Cheers, > Laurent. > > > > > Le
mar. 28 août 2018 à 12:25, Patrick Spek via perl6-users
mailto:perl6-users@perl.org>> a écrit : >
> Hi all,
>
> I'm trying to substitute parts of a string, and thought this might be a
> good use of a grammar. Sadly, grammars aren't my strong suit, so I
> thought I'd ask the wider community for help. Maybe you guys know an
> even better solution than using a grammar here.
>
> So, consider a string, "Here be a $(placeholder), for $(purpose)
> purposes.". I want to be able to put that into a sub, along with some
> Pairs, and get a string with the placeholders replaced back.
>
>     my Str $input = "Here be a $(placeholder), for $(purpose) purposes.";
>     my Str $output = format-string(
>     $input,
>     placeholder => "placeholder",
>     purpose => "testing",
>     );
>
>     dd $output; # "Here be a placeholder, for testing purposes."
>
> The `format-string` sub would call the grammar and apply the actual
> substitution, and that's where I need your help. I am not quite sure
> how I would implement the grammar (and presumably it's actions) to do
> what I want.
>
> Thanks in advance for your help!
>
>



Re: How do I test my substitutions?

2018-08-14 Thread Timo Paulssen
You're putting your starting string in a variable, $x, but aren't
telling the s/// operator specifically what to operate on, so it
defaults to $_, which is still at its default value.


On 14/08/18 13:08, ToddAndMargo wrote:
> Hi All,
>
> The Perl 5 guys have it pounded into my head that I
> always had to check my substitutions to see if they
> worked if not working would crash the program.
>
> So in Perl 6 I have:
>
> $ p6 'my $x="abc"; if s/b/z/ {say "sub worked"}else{say "sub failed"};
> say "$x";'
>
> Use of uninitialized value of type Any in string context.
> Methods .^name, .perl, .gist, or .say can be used to stringify it to
> something meaningful.
>   in block  at -e line 1
> sub failed
> abc
>
>
> What am I doing wrong?
>
> Many thanks,
> -T


Re: I need the rules for running modules from the command line

2018-08-14 Thread Timo Paulssen
Please be aware that passing a folder with many files in it as the -I
path will cause a tremendous slowdown when loading modules, since it
goes through the whole file hierarchy starting at that path. If
/home/linuxutil is actually a typical home folder with dotfiles and
documents and what have you, that can take a *long* while.


On 14/08/18 12:41, ToddAndMargo wrote:
> Follow up, with Timo's help.  Note keeper note:
>
>
>
> Perl6: running modules from the command line:
>
>
> -M    = module name without the pm6 and no space
>
> -I    = local path to read and no space;
>     "./" is accepted for the current directory
>
> Don't forget the -e
>
>
> $ perl6 -I./ -MPrintColors -e 'PrintBlue( "Blue\n" );'
> Blue
>
> $ perl6 -I/home/linuxutil -MPrintColors -e 'PrintBlue( "Blue\n" );'
> Blue
>
> $ perl6 -e 'use lib "/home/linuxutil"; use PrintColors; PrintBlue(
> "Blue\n" );'
> Blue


Re: I need the rules for running modules from the command line

2018-08-14 Thread Timo Paulssen
You can just put -I lib on your commandline, but what's more important
is that you forgot to pass -e, so it was taking your code and
interpreting it as a filename. It's very unlikely that you have a file
called 'PrintBlue( "Blue\n" );' in the current directory, though.

perl6 -Ilib -MPrintColors -e 'PrintBlue( "Blue\n");' should do what you
meant to do.

HTH
  - Timo


On 14/08/18 12:01, ToddAndMargo wrote:
> Hi All,
>
>
> I presume this is failing as the current directory is not
> in the "lib" path:
>
>
> $ perl6 -MPrintColors 'PrintBlue( "Blue\n" );'
> Could not open PrintBlue( "Blue" ). Failed to stat file: no such
> file or directory
>
>
> This does work, but what a lot of extra work:
>
> $ perl6 -e 'use lib "/home/linuxutil"; use PrintColors; PrintBlue(
> "Blue\n" );'
> Blue
>
>
>
> What are the rules for calling modules from the command line?
>
>
> Many thanks,
> -T


Re: Special token names, or my mistake

2018-08-12 Thread Timo Paulssen
The grammar will never by itself try to call a subroutine, it only looks
for methods in the action object. However, there is a "sum" method that
An-Action inherits from Any. You can find it here:
https://github.com/rakudo/rakudo/blob/master/src/core/Any.pm6#L440

It's probably a good idea to put an empty method of the same name that
accepts one argument (the match object) into the action class.

The same problem occurs with any of the other methods that already exist
on Any.

You can find them like this:

    perl6 -e 'Any.^methods(:all).>>.name.put'


Re: string to integer?

2018-08-07 Thread Timo Paulssen
oops, i only now saw the thread you had about it. never mind, then!


On 07/08/18 15:31, Timo Paulssen wrote:
> dd is a function that outputs a value, and dd returns Nil. You're
> assigning the result of dd to $x, which resets the variable to its
> default value, which is the (Str) you see, i.e. an undefined String.
>
> Just throw out the dd, you don't need it to stringify things, only the ~
> or + prefix is necessary.
>
>
> On 07/08/18 09:01, ToddAndMargo wrote:
>> What is this all about?
>>
>> $ p6 'my Int $y = 7; my Str $x = dd ~$y; say $x'
>> "7"
>> (Str)
>>
>> Why does it say "(Str)"?  The confirmation is nice, but
>> why is it printing out?
>>
>>
>> And why does this error out?
>>
>> $ p6 'my Int $y = 7; my Str $x = dd ~$y; say "$x"'
>> "7"
>> Use of uninitialized value $x of type Str in string context.
>> Methods .^name, .perl, .gist, or .say can be used to stringify it to
>> something meaningful.
>>   in block  at -e line 1


Re: string to integer?

2018-08-07 Thread Timo Paulssen
dd is a function that outputs a value, and dd returns Nil. You're
assigning the result of dd to $x, which resets the variable to its
default value, which is the (Str) you see, i.e. an undefined String.

Just throw out the dd, you don't need it to stringify things, only the ~
or + prefix is necessary.


On 07/08/18 09:01, ToddAndMargo wrote:
> What is this all about?
>
> $ p6 'my Int $y = 7; my Str $x = dd ~$y; say $x'
> "7"
> (Str)
>
> Why does it say "(Str)"?  The confirmation is nice, but
> why is it printing out?
>
>
> And why does this error out?
>
> $ p6 'my Int $y = 7; my Str $x = dd ~$y; say "$x"'
> "7"
> Use of uninitialized value $x of type Str in string context.
> Methods .^name, .perl, .gist, or .say can be used to stringify it to
> something meaningful.
>   in block  at -e line 1


Re: need regex help

2018-08-03 Thread Timo Paulssen
The + is required, perhaps because the first character after the opening
< is supposed to determine exactly what thing it is? Not sure about
that. The + and - is a bit like "start at nothing, add all alnums, then
subtract all alphas". The + after the < > is just to match it any number
of times, but at least once, and the $ at the end, together with the ^
at the start, ensures that every character in the string has to match,
not just any character.

Hope that makes sense
  - Timo


On 03/08/18 20:04, ToddAndMargo wrote:
> On 08/02/2018 05:18 AM, Timo Paulssen wrote:
>> Is this what you want?
>>
>> perl6 -e 'say "12345" ~~ /^<+alnum -alpha>+$/'
>> 「12345」
>>
>> perl6 -e 'say "123a45" ~~ /^<+alnum -alpha>+$/'
>> Nil
>>
>> HTH
>>    - Timo
>>
>
> What does the following do?
>
>  +alnum   (why does it need the "+"?)
>  -alpha   (I presume "-" means negate?)
>  +$
>
> Many thanks,
> -T


Re: need regex help

2018-08-02 Thread Timo Paulssen
Is this what you want?

perl6 -e 'say "12345" ~~ /^<+alnum -alpha>+$/'
「12345」

perl6 -e 'say "123a45" ~~ /^<+alnum -alpha>+$/'
Nil

HTH
  - Timo


Re: parsing in different modes

2018-08-01 Thread Timo Paulssen
Hello Theo,

have you considered placing the code for the actions directly inside the
grammar's tokens and rules instead? You can just { make 123 } right in
the middle and it'll have the same effect as doing that in an action
method, but you'll be able to put code after it, too.

HTH
  - Timo


Re: EVAL?

2018-06-14 Thread Timo Paulssen
If it's literally just the name of a sub that you'll immediately invoke,
you can side-step EVAL completely

    ::('&' ~ $RunSpecific)()

should do the trick.

::("&foo") will give you the sub object, and putting () after it will
immediately call it.

It will allow access to all subs, even from the core, so subs like "die"
and "exit" are reachable, but it's less dangerous than accepting any
random code. For one, it will only work with subs that don't take arguments.

HTH
  - Timo


Re: mixin syntax: does vs but

2018-06-12 Thread Timo Paulssen
You can override WHAT with a method, you just have to use a syntax
that's not literally .WHAT, like this:

    class Test { method WHAT() { say "i'm here" } }; Test."WHAT"();
    # → i'm here


Re: need second pair of eyes

2018-06-12 Thread Timo Paulssen
My recommendations:

    if $line.contains(all("wine-patched/archive/staging-/", ".tar.gz")){ }

    # if the path has to be at the beginning and the extension at the end,
    # which your original regex doesn't require, but it's probably right
    if $line.starts-with("wine-patched/archive/staging-/") &&
$line.ends-with(".tar.gz") { }

    if $line ~~ m{ "wine-patched/archive/staging-/" .* ".tar.gz" } { }

What do you think?
  - Timo


Re: need sort help

2018-06-09 Thread Timo Paulssen
The magic trick is that the last line in the code block is the return value.

when you pass a function that takes a single argument (in this case just
the $_) to sort, it will call your function for every element in the
input array and use the result of that function to sort the elements by.

The "// 0" is there in every field because if the input line doesn't
have the expected format, you'll get a bunch of warnings, because the
variables will contain undefined values, you can try it for yourself
with inputs like "anaconda", "beetle", "zebra".

The last part of the puzzle is how sort will sort lists of lists
(because it has now replaced every string with a list of the parts we've
supplied); By default, sort uses the earliest entry in the list that is
different, so it's very much like lexicographic sort.

Does that explain everything?
  - Timo


Re: need sort help

2018-06-08 Thread Timo Paulssen
your list @x has only a single item, because you're slurping the whole
file contents into it.

replacing slurp with lines should do the trick.


On 09/06/18 07:23, ToddAndMargo wrote:
> On 06/08/2018 09:51 PM, Timo Paulssen wrote:
>> That's unnecessarily long and complicated, here's how you can do it much
>> easier:
>>
>>  @x.sort: {
>>  my ($month, $day, $year, $hour, $minute, $second) =
>> .comb(/\d+/);
>>  ($year // 0, $month // 0, $day // 0, $hour // 0, $minute // 0,
>> $second // 0, $_);
>>  }
>>
>> Trying it on some input data:
>>
>>  cimtrak.log.06-08-2018_16:07:39.zip
>>  cimtrak.log.06-08-2018_17:07:39.zip
>>  cimtrak.log.07-08-2018_06:07:39.zip
>>  cimtrak.log.07-08-2018_16:07:39.zip
>>  cimtrak.log.12-08-2016_06:07:39.zip
>>  cookies
>>  asbestos
>>  fire engine
>>  perl6
>>  butterflies
>>
>> results in:
>>
>>  asbestos
>>  butterflies
>>  cookies
>>  fire engine
>>  perl6
>>  cimtrak.log.12-08-2016_06:07:39.zip
>>  cimtrak.log.06-08-2018_16:07:39.zip
>>  cimtrak.log.06-08-2018_17:07:39.zip
>>  cimtrak.log.07-08-2018_06:07:39.zip
>>  cimtrak.log.07-08-2018_16:07:39.zip
>>
>> This is the schwartzian transform that was mentioned in another mail.
>> why it wasn't actually shown, i have no clue :)
>>
>> Hope that helps
>>    - Timo
>>
>
>
> What am I doing wrong?
>
> $ ls | perl6 -e 'my @x=slurp();  say @x.sort: {my ($month, $day,
> $year, $hour, $minute, $second) = .comb(/\d+/);($year // 0, $month //
> 0, $day // 0, $hour // 0, $minute // 0,$second // 0, $_);}'
> (cimtrak.log.06-08-2018_16:07:39.zip
> cimtrak.log.06-08-2018_17:07:39.zip
> cimtrak.log.07-08-2018_06:07:39.zip
> cimtrak.log.07-08-2018_16:07:39.zip
> cimtrak.log.12-08-2016_06:07:39.zip
> )


Re: need sort help

2018-06-08 Thread Timo Paulssen
If you want to make it robust in the case of fields being different
length, like having entries with the day as "5" instead of "05", you can
put a >>.Int after the .comb(/\d+/) and that'll give you proper numeric
sorting for all fields regardless of width.


On 09/06/18 06:51, Timo Paulssen wrote:
> That's unnecessarily long and complicated, here's how you can do it much
> easier:
>
>     @x.sort: {
>     my ($month, $day, $year, $hour, $minute, $second) = .comb(/\d+/);
>     ($year // 0, $month // 0, $day // 0, $hour // 0, $minute // 0,
> $second // 0, $_);
>     }
>
> Trying it on some input data:
>
>     cimtrak.log.06-08-2018_16:07:39.zip
>     cimtrak.log.06-08-2018_17:07:39.zip
>     cimtrak.log.07-08-2018_06:07:39.zip
>     cimtrak.log.07-08-2018_16:07:39.zip
>     cimtrak.log.12-08-2016_06:07:39.zip
>     cookies
>     asbestos
>     fire engine
>     perl6
>     butterflies
>
> results in:
>
>     asbestos
>     butterflies
>     cookies
>     fire engine
>     perl6
>     cimtrak.log.12-08-2016_06:07:39.zip
>     cimtrak.log.06-08-2018_16:07:39.zip
>     cimtrak.log.06-08-2018_17:07:39.zip
>     cimtrak.log.07-08-2018_06:07:39.zip
>     cimtrak.log.07-08-2018_16:07:39.zip
>
> This is the schwartzian transform that was mentioned in another mail.
> why it wasn't actually shown, i have no clue :)
>
> Hope that helps
>   - Timo


  1   2   3   >