Re: BEGIN {} question

2022-09-01 Thread Andinus via perl6-users

ToddAndMargo via perl6-users @ 2022-09-01 10:30 -07:

> On 9/1/22 00:45, Richard Hainsworth wrote:
>> Treat the regexes as data for a program. Compile the program once.
>> Run the regexes as often as you need.
>
> Please elucidate.  That could save me boat loads
> of time.

You could take the regex string from an environment variable or read
from a file. The program is compiled only once and you can test regexes
without re-compilation.

Thanks Richard, this is going to save me a lot of time.


signature.asc
Description: PGP signature


Re: sprintf and print question

2022-09-01 Thread William Michels via perl6-users
Hi Todd,

~$ raku -e '(sprintf "%.4s", "andefghi" ).put;'
ande
~$ raku -e 'put (sprintf "%.4s", "andefghi" );'
ande

If sprintf isn't a requirement, then:

~$ raku -e 'put substr("andefghi", 0..3);'
ande

HTH, Bill.


On Thu, Sep 1, 2022 at 7:37 PM ToddAndMargo via perl6-users <
perl6-users@perl.org> wrote:

> Hi All,
>
> Is there a cleaner way to do this?
>
>  $ raku -e 'print( (sprintf "%.4s", "andefghi" ) ~ "\n";)'
>  ande
>
> I want to print the first four letter s to STDOUT.
>
> -T
>


Re: sprintf and print question

2022-09-01 Thread Andinus via perl6-users

ToddAndMargo via perl6-users @ 2022-09-01 19:37 -07:

> Is there a cleaner way to do this?
>
> $ raku -e 'print( (sprintf "%.4s", "andefghi" ) ~ "\n";)'
> ande
>
> I want to print the first four letter s to STDOUT.

You can use substr,

  | put "andefghi".substr(0, 4)
  ande


signature.asc
Description: PGP signature


Re: sprintf and print question

2022-09-01 Thread Norman Gaywood
On Fri, 2 Sept 2022 at 12:37, ToddAndMargo via perl6-users <
perl6-users@perl.org> wrote:

> Is there a cleaner way to do this?
>
>  $ raku -e 'print( (sprintf "%.4s", "andefghi" ) ~ "\n";)'
>  ande
>
> I want to print the first four letter s to STDOUT.
>

 $ raku -e 'printf "%.4s\n","andefghi"'
ande

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

ngayw...@une.edu.au  http://turing.une.edu.au/~ngaywood
Phone: +61 (0)2 6773 2412  Mobile: +61 (0)4 7862 0062

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


sprintf and print question

2022-09-01 Thread ToddAndMargo via perl6-users

Hi All,

Is there a cleaner way to do this?

$ raku -e 'print( (sprintf "%.4s", "andefghi" ) ~ "\n";)'
ande

I want to print the first four letter s to STDOUT.

-T


Re: BEGIN {} question

2022-09-01 Thread ToddAndMargo via perl6-users

On 9/1/22 00:45, Richard Hainsworth wrote:
Raku and Perl are two different languages in the same family. They 
evolved with different targets, perl to react quickly to internet 
requests, Raku to be a better programming language. This may not be the 
take the actual developers have, but it's what I think happened.


So the thing you designed for Perl will be faster because it fits the 
pattern. But it's not the best way for Raku. Even though stage parse 
will get significantly faster over time because Raku was designed to be 
optimisable, I think Perl will always be faster.





Hi Richard,

I do not think I have been clean enough
in my intentions.

I have two goals: long and short term.

My short term goal, which I have expounded on at
length, is to assist me with a program for my
business where I have to constantly keep up with
it and have to do a lot recompiling.  .precomp
is not helpful in that instance.

My long term goal is future programs (as I get
better at this stuff and if I EVER have a chance
to learn GLADE).

What I am after is NOT a race between Perl 5 and
Perl 6 (Raku) or any other programming language.
I really do not care if Perl 5 compiles 300 times
faster.  I care what the customer's "perception"
of what the start time is.

Ten microseconds or two seconds, the users
can't tell them apart.  Ten or twenty seconds and
users think something is wrong and start
several more instances of the program. This
is the "professionally embarrassing" part I
have written about.  I constantly have to tell
users (of non Perl 6) programs to just wait
or you will continue to crash things.

A widows work around is to have them start slow
to start programs by right clicking on the icon
and left clicking on "Open".  That way they know
they did not flub the double click.

Think of it this way. An NVMe drive is about eight
times faster that a mechanical drive.  Do the user's
programs run any faster once loaded from either
drive?  Unless they are doing substantial (YUGE)
continuing writes and reads from their drive, no
they do not run any faster.

But!  They load substantially faster, giving
the user the impression of a fast, snappy program.
This colors the rest of the user's experience.
And they don't start five instances of the program
thinking they flubbed the double click.

So I DO NOT CARE if Perl 6 is slower to compiler
AS LONG as the user/customer does not think
something is wrong.  One or two seconds is
just fine with me.  I am not after microseconds.

-T


Re: BEGIN {} question

2022-09-01 Thread ToddAndMargo via perl6-users

On 9/1/22 00:45, Richard Hainsworth wrote:

Work with Raku rather than expect it to be the same as Perl.


Oh I intent too!   I program in Top Down.  Perl 5's
subroutines are a nightmare.  I ADORE Perl 6's subroutines.

By saying above / below, this indicates a linear view of 
code at the same time.


Please elucidate!


Can you show me an example of FIRST and LAST

There are some in the documentation


https://docs.raku.org/syntax/FIRST

syntax FIRST

Documentation for syntax FIRST assembled from
the following types:  language documentation Phasers

From Phasers
(Phasers) Phasers FIRST FIRST

Runs at loop initialization, before c.

Which brings me back to my on going criticism of
the documentation.  It is a "refresher" for those
that already know what they are doing and do not
need it.

Can you point me to a good beginner's reference?


Treat the regexes as data for a program. Compile the program once. Run 
the regexes as often as you need.


Please elucidate.  That could save me boat loads
of time.


Re: BEGIN {} question

2022-09-01 Thread Richard Hainsworth
On Wed, 31 Aug 2022, 00:59 ToddAndMargo via perl6-users, <
perl6-users@perl.org> wrote:

> On 8/30/22 13:34, Richard Hainsworth wrote:
> > Hi Todd,
> >
> 
> > Since you continue for ever to complain about 'compile' time issues,
>
> "Stage parce" is specifically what I am whining about
>
> > rather than startup times, I wonder whether the programs you write are
> > massive monolithic lines of code with thousands of lines, much like most
> > standard software when FORTRAN or COBOL were the high level languages,
> > or whether you design things to make each section more manageable.
>
>
> $ raku -c --stagestats GetUpdates.pl6
> Stage start : 0.000
> Stage parse : 17.851
> Stage syntaxcheck: Syntax OK
>
> Perl 5 does it over 300 times faster on the code I ported
>
Raku and Perl are two different languages in the same family. They evolved
with different targets, perl to react quickly to internet requests, Raku to
be a better programming language. This may not be the take the actual
developers have, but it's what I think happened.

So the thing you designed for Perl will be faster because it fits the
pattern. But it's not the best way for Raku. Even though stage parse will
get significantly faster over time because Raku was designed to be
optimisable, I think Perl will always be faster.

Having said that Raku is still better because it separates out things that
should be separate. So you may need to change the way you handle your task.
Work with Raku rather than expect it to be the same as Perl.

>
> >
> > If the programs you write to be run from the command line are thousands
> > of lines long, then yes!! you will suffer!!! from long startup times

Think about the difference between start up and parsing. Move as much stuff
away from parsing as possible.

> > because the program is re-compiled EVERY time. However, if you redesign
> 
>
> Hi Richard,
>
> Long time no talk to you either.  Don't be a stranger.
> (If you like, I can always "whine" about compile times
> to get your attention, if you like.  Chuckle.)
>
> Thank you.  That letter took a lot of work!
>
> How does this sound?
>
No. I think you are missing the explicit difference being made in Raku,
which differs from all other languages I know (explicit since one could
argue C preprocessing  does the Sam)  between compile time and run time.
Raku explicitly allows you to specify compile time actions in the program
itself. By saying above / below, this indicates a linear view of code at
the same time.
This distinction will become even greater when the new Macros are
incorporated. That's the next version of Raku.

>
>   BEGIN is a special block of code called a "phaser"
>   that runs at compile time.  It will see any code
>   above it, such as variables and  imported modules,
>   but not below it.
>
> Snip
>
> Can you show me an example of FIRST and LAST
>
> There are some in the documentation
>


>
> Where .precomp does not work for me is my software
> updates program.  This is a behemoth program (imports
> six of my custom modules too) that goes out and checks
> for software updates that I support at my customer
> sites.  it is about 70 programs.
>
Change the way you do this to be more compliant with the realities of Raku.
You may find in the refactoring process that your old way is probably
subject to bit rot.

>
> To do this open the web site with firefox.  Then I
> use their developer's tools to examine the page's
> source code.  I find the fragment I am looking
> for and regex them to extract them.
>
> In the process, I goof the regex/s "A LOT".  Not
> to mention  having to chase down hidden character
> that do not appear in Firefox's page source.
> And download that are different on a web browser
> than with curl.
>
> I do have a function that allows me to only run that
> one web site's extraction, so I do not have to go
> through all 70 of them.
>
> So, I have to recompile the code maybe up to 20 times
> depending on the difficulty of the web site.  The
> L-O-N-G delays drives me nuts.
>
Treat the regexes as data for a program. Compile the program once. Run the
regexes as often as you need.

>
> Snip.
>
> Speaking of BEGIN, is this Raku's "parallel
> processing" method?  Does Raku have a way to
> spawn parallel processes and have them talk to
> each other?
>
> -T
>
> Concurrency is a major change that Raku does differently. But it bursts my
> head. Because concurrency is hard!
>


>
>
>
>
>
>
>