Re: Fwd: Working with a regex using positional captures stored in a variableperl6-us...@perl.org

2021-03-11 Thread Moritz Lenz
Hi there,

On 11.03.21 17:43, William Michels wrote:
> Hi Moritz your book is mentioned below. Care to chime in? Reply to
> perl6-users  .
> 
> Thx, Bill.
> W. Michels, Ph.D.
> 
> -- Forwarded message -
> From: Joseph Brenner 
> Date: Thu, Mar 11, 2021 at 12:28 AM
> Subject: Working with a regex using positional captures stored in a variable
> To: perl6-users 
> 
> 
> Does this behavior make sense to anyone?  When you've got a regex
> with captures in it, the captures don't work if the regex is
> stashed in a variable and then interpolated into a regex.
> 
> Do capture groups need to be defined at the top level where the
> regex is used?
> 
> { #  From a code example in the "Parsing" book by Moritz Lenz, p. 48,
> section 5.2
>my $input = 'There are 9 million bicycles in beijing.';
>if $input ~~ / (\d+) \s+ (\w+) / {
>say $0.^name;  # Match
>say $0;# 「9」
>say $1.^name;  # Match
>say $1;# 「million」
>say $/;
> # 「9 million」
> #  0 => 「9」
> #  1 => 「million」
>}
> }
> 
> say '---';
> 
> { # Moving the pattern to var which we interpolate into match
>my $input = 'There are 9 million bicycles in beijing.';
>my $pattern = rx{ (\d+) \s+ (\w+) };
>if $input ~~ / <$pattern> / {
>say $0.^name;  # Nil
>say $0;# Nil
>say $1.^name;  # Nil
>say $1;# Nil
>say $/;# 「9 million」
>}
> }
> 
> In the second case, the match clearly works, but it behaves as
> though the capture groups aren't there.

$0 is an alias for $/[0].

When the match is in a different variable, you need to access the
capture group as $match[0] instead of its alias $/[0].

Regards,
Moritz

-- 
Moritz Lenz
https://perlgeek.de/ -- https://raku.org/


Re: Where is "Subject"?

2017-02-23 Thread Moritz Lenz
Hi,

On 24.02.2017 07:51, ToddAndMargo wrote:
> Am I blind or is there nowhere to set the subject of an eMail
> in Net::SMTP?
> 
> https://github.com/retupmoca/P6-Net-SMTP

You're not blind, just thinking at the wrong level. Net::SMTP expects
you to have an email string that contains both the headers and the body
($email in the README), and the subject is part of the headers.

The only reason that $from and @to have a separate interface is that
SMTP handles them separately.

Cheers,
Moritz


-- 
Moritz Lenz
https://deploybook.com/ -- https://perlgeek.de/ -- https://perl6.org/


Re: per 5 converter?

2017-02-12 Thread Moritz Lenz
Hi,

What's the use case for converting Perl 5 to Perl 6 automatically?

If you want to use Perl 5 code from within your Perl 6 code, you can do
that through Inline::Perl5.

But automatic translation (if it works at all) typically doesn't produce
good or idiomatic code, so you should try to stay away from it.

Cheers,
Moritz

On 12.02.2017 07:47, ToddAndMargo wrote:
> Hi All,
> 
> I know I asked this once before and I had though I'd written it
> down, but do you have any favorite Perl5 to Per6 converters?
> 
> Many thanks,
> -T
> 

-- 
Moritz Lenz
https://deploybook.com/ -- https://perlgeek.de/ -- https://perl6.org/


Re: mocking $*OUT

2017-01-24 Thread Moritz Lenz
Hi Brian,

On 24.01.2017 23:28, Brian Duggan wrote:
> Hi All,
> 
> This code:
> 
>   my $str = '';
>   class Mock {
> method say($arg) { $str ~= $arg }
>   }
>   $*OUT = Mock.new;
>   say 'hi';
> 
> produces:
> 
>   Too many positionals passed; expected 1 argument but got 2
> in block  at out.p6 line 6
> 
> Changing the signature of say doesn't seem to help.
> 
> If I change 'say' to 'print' in Mock, things work
> fine, though I'm having a hard time figuring out why
> the code above doesn't work.  Any ideas?

Because say() is a high-level function that uses the lower-level
$*OUT.print under the hood.

>From rakudo's src/core/io_operators.pm:

multi sub say(Str:D \x) {
my $out := $*OUT;
$out.print(nqp::concat(nqp::unbox_s(x),$out.nl-out));
}

You might be interested in
https://perlgeek.de/blog-en/perl-6/2016-book-testing-say.html :-)

Cheers,
Moritz

-- 
Moritz Lenz
https://deploybook.com/ -- https://perlgeek.de/ -- https://perl6.org/


Re: A stricter typed variable

2017-01-07 Thread Moritz Lenz
Hi,

On 07.01.2017 15:52, Joseph Garvin wrote:
> Being able to type the elements in containers was considered a major
> problem in Java for years before they added generics. 

Please note that Java and Perl 6 are coming from very different
directions. Java 1 a statically typed language, where every operation
whose type safety the compiler can't prove at compile time is rejected.
So with untyped containers in Java 1.4-, you needed explicit runtime
casts juts to call methods on container elements.

Perl used to be a dynamically typed language, which means that the
compiler basically never rejected a program due to type errors. Type
errors can happen at run time.

> And the whole
> point of having a computer is to have it do repetitive things, e.g. loop
> over a bunch of stuff and do the same thing to all of it.

You can loop over a bunch of stuff and do the same thing to all of it
without explicitly typing the contents of an array. That's what all
other dynamically typed languages tend to do (python, ruby, lua, PHP,
you name it).


If you have, for example:

sub wants-str(Str $x) { ...}
sub test(@a) {
   for @a -> $x { wants-str($x) }
}

Perl 6 happily compiles and executes this, because it can't prove a type
error at compile time. Java OTOH would reject the equivalent code.


> How is this an
> "exaggerated" use of containers? Why have the language feature at all if
> it's too clunky for people to use it?

I'm not saying it's always too clunky to use. I'm saying there's a cost
attached, and you should consider whether to use it.

I observe some weird behavior in Perl 6 newbies (and I've observed it in
myself too): they're so enamored by type constraints that they use them
everywhere, and run into all sorts of type errors they didn't expect.
The weird part is that if they wanted a statically typed language, they
could have easily chosen one. But they picked Perl 6, and then they try
to use it like a statically language, and wonder why it feels clunky.

If you write a type constraint, ask yourself: could there be an object
from another type that my could would also work with? Maybe I'm just
calling a method that's implemented in type Str, but a user-supplied
object could implement the same method as well. If it walks like a duck,
and quacks like a duck, do I really have to care if it's a duck or not?

Cheers,
Moritz

-- 
Moritz Lenz
https://deploybook.com/ -- https://perlgeek.de/ -- https://perl6.org/


Re: Need some help to understand how modify an AST.

2016-12-05 Thread Moritz Lenz
Hi,

On 06.12.2016 00:49, CARAYOL Jean-Pierre wrote:
> Hi,
> 
> 
> 
> I don't understand why the 2 following Perl6 programs give a different
> result when running.
> 
> If someone could give me an explanation, it will help me a lot. Many thanks.
> 
> 
> 
> /(Note the 2 programs run on Linux and the Linux environment variable
> $toto is set to "totoenv". ( export toto=totenv )/
> 
> 
> _Program1 :_
> 
> /cattest051.pl6/_
> _
> 
> #!/opt/rakudo-star-2016.10/bin/perl6
> use v6;
> 
> grammar TEST {
> rule  TOP { :i \s*}
> token varenv {'$' }
> token mot { <[a..z A..Z 0..9 =\-_!~'():@&+$,\']>+ }
> }
> 
> class ActionsTest {
> method TOP ($/) { $/.make( ~%*ENV{$}); }
> }
> 
> my $actions = ActionsTest.new;
> my $script = "\$toto" ;
> my $scr = TEST.parse($script,:$actions);
> say $scr;
> say $scr.made;
> ===>./test051.pl6
> 「$toto」
>  varenv => 「$toto」
>   mot => 「toto」
> *totoenv*
> 
> This programs runs fine and displayed the value for the toto environment
> variable.
> 
> 
> 
> _Program2:_
> 
> __cat test052.pl6
> 
> grammar TEST {
> rule  TOP { :i \s*}
> token varenv {'$' }
> token mot { <[a..z A..Z 0..9 =\-_!~'():@&+$,\']>+ }
> }
> 
> class ActionsTest {
> method varenv ($/) { $/.make( %*ENV{$}); }
> method TOP ($/) { $/.make( ~$/); }

$/.make stores the result in $/.made, so the second line should be

method TOP($/) { $/.make($.made) }

HTH,
Moritz

> }
> 
> my $actions = ActionsTest.new;
> my $script = "\$toto" ;
> my $scr = TEST.parse($script,:$actions);
> say $scr;
> say $scr.made;
> 
> ===>
> Use of Nil in string context
>   in method varenv at ./test052.pl6 line 14
> 「$toto」
>  varenv => 「$toto」
>   mot => 「toto」
> $toto
> 
> This program displays an error message and doesn't find the value of
> toto environment variable.
> 
> 
> The only difference between the 2 programs is instruction "make(
> %*ENV{$}" is part of the TOP method in the program 1 and
> part of the varenv method in program 2.
> 
> I'm certainly missing something but I don't understand why program 2
> doesn't work. I'm very interested to get explanations for that. It will
> help me to understand how to modify and AST using Perl6.
> 
> 
> Thanks a lot for your help.
> 
> Best regards,
> 
> Jean-Pierre 
> 
> 

-- 
Moritz Lenz
https://deploybook.com/ -- https://perlgeek.de/ -- https://perl6.org/


Re: Where to start?

2016-11-18 Thread Moritz Lenz
Hi,

On 19.11.2016 03:34, ToddAndMargo wrote:
> Hi All,
> 
> I just install rakudi-star in my Fedora 24 virtual machine.
> 
> I know how to program and run things in perl 5.
> 
> Can someone point me to a how to that will show me the
> basic template for running a perl 6 program in Linux.

#!/usr/bin/env /path/to/your/rakudo/inst/bin/perl6

use v6;


> Also, do I need to run perl6 through a compiler or
> does it compile on the fly like perl 5?

There's no separate compilation step.

Cheers,
Moritz

-- 
Moritz Lenz
https://deploybook.com/ -- https://perlgeek.de/ -- https://perl6.org/


Re: What's involved in the creation of a new Rakudo * version?

2016-10-16 Thread Moritz Lenz
Hi

On 16.10.2016 17:24, Parrot Raiser wrote:
> We "Star" users are falling rather behind the compiler versions.
> I'd like to help catch up, if the processes involved are sufficiently mundane.
> Is there a checklist of the required tasks from which to work?

Yes, there is:
https://github.com/rakudo/star/blob/master/tools/star/release-guide.pod

Cheers,
Moritz


-- 
Moritz Lenz
https://deploybook.com/ -- https://perlgeek.de/ -- https://perl6.org/


Re: think I found a bug in the doc's

2016-10-04 Thread Moritz Lenz
Hi,

On 04.10.2016 13:06, Francis (Grizzly) Smit wrote:
> in https://docs.perl6.org/type/Int#routine_expmod
> 
> it reads:
> 
> 
> routine expmod <https://docs.perl6.org/type/Int#___top>
> 
> multi  sub expmod(Int  $y,Int  $mod)returns  Int:D
> multi  method  expmod(Int:D:  Int  $y,Int  $mod)returns  Int:D
> 
> Returns the given |Int| raised to the |$y| power within modulus |$mod|.
> 
> say  expmod(4,2,5);# 1
> say  7.expmod(2,5);# 4
> 
> 
> Shouldn't the su form read:
> 
> multi  sub expmod(Int:D $x,Int  $y,Int  $mod)returns  Int:D it needs 
> three parameters

Yes, that's right.

If you tell me your github username, I can give you access so that you
can change it directly on https://github.com/perl6/doc/.

Otherwise a pull request would be very welcome.

Cheers,
Moritz


-- 
Moritz Lenz
https://deploybook.com/ -- https://perlgeek.de/ -- https://perl6.org/


Re: What are variables/parameters that start with a pipe | char

2016-10-01 Thread Moritz Lenz
Hi,

On 01.10.2016 04:22, Francis (Grizzly) Smit wrote:
> I keep finding stuff like this:
> 
> multi method spurt(IO::Path:D: Blob $contents, :$bin, |c)
> multi method spurt(IO::Path:D: Cool $contents, :$bin, |c)
> 
> 
> but I cannot find the |c syntax in the docs I have googled but no good 
> a pointer or link would be good. 

Just for the record, a good approach to find such a thing would be to
type the defining character, here the |, into search box on
https://doc.perl6.org/.

It doesn't work for everything, but for | it does give you, among other
things, "| (parameter)", which points to relevant documentation.

Cheers,
Moritz


-- 
Moritz Lenz
https://deploybook.com/ -- https://perlgeek.de/ -- https://perl6.org/


Re: Fwd: perl6 INC

2016-05-11 Thread Moritz Lenz

On 05/11/2016 04:30 PM, Bennett Todd wrote:

Thanks for the explanation. Sounds like an unfortunate situation, rather than 
letting the system admin choose modules within the limits of filesystem 
namespace,  it's using a separate database, opaque to filesystem tools. I hope 
this is just a temporary hack until a mature solution is hammered out.


We'd love it to be temporary, but until all target platforms (Linux, Mac 
OS X, Windows) can offer fully Unicode-capable, case sensitive file 
systems, we *have* make our own workarounds.


Cheers,
Moritz



Re: Work around to "unwanted fail"

2016-05-11 Thread Moritz Lenz

Hi,

On 05/11/2016 09:22 AM, Richard Hainsworth wrote:

I had

grammar RatingGrammar {

 rule TOP{ ^ + $ };

 rule statement  {  '=' 
  | {
 if ($/.CURSOR.pos < $/.orig.chars) {

 self.panic($/, "Declaration syntax
incorrect.")
 }
 }
 };


This generates an error for a correct input because it fails 
at the end of input.


I think the problem is that you use | which instructs the compiler to 
try both paths "at the same time" (no extra threading involved, just 
notionally). You really want to use || instead, which is "first try the 
first path, and if it doesn't work, try the second path".


Cheers,
Moritz


Re: question about Supply.act()

2016-04-28 Thread Moritz Lenz

On 04/28/2016 11:11 AM, mt1957 wrote:

Hi,

The documentation about the method act explains that 'the given code is
guaranteed to be only executed by one thread at a time'.

Can I assume from this that any other thread including the main thread
isn't running?


No. Other threads might still be running and do other things.

Cheers,
Moritz


Re: Perl 6 pod-handling code seems widely scattered

2016-04-27 Thread Moritz Lenz

On 04/25/2016 03:27 PM, Tadeusz Sośnierz wrote:

On 25/04/16 14:13, Tom Browder wrote:

I would like to hack on the pod handling code (particularly the HTML
generation) but it seems to be quite scattered around github.  Is
http://github.com/perl6/Pod::To::HTML>> the definitive repo location
for that chunk?

Yes, that's the module that turns Pod AST into HTML. That's what you're
looking for :)



It's a document tree, not really an AST.
The AST is an intermediate format inside the compiler that user-space 
modules don't see.



Cheers,
Moritz :-)


Re: Installing both from rakudobrew and Rakudo Star

2016-02-05 Thread Moritz Lenz



On 02/05/2016 01:57 AM, James E Keenan wrote:

Follow-up questions to those I posed on perl6-users today.

So I have successfully used rakudobrew to build moar and panda.  That
perl6 executable is located here:
$ which perl6
/home/jkeenan/.rakudobrew/bin/perl6

Now, suppose I *also* wish to install Rakudo Star.  I've downloaded the
rakudo-star-2016.01 tarball and have read the instructions in README for
installation.  From past experience, I guess that if I say simply:

$ perl Configure.pl --backend=moar --gen-moar
$ make
$ make install

... that this will install in /usr/local/bin/.  Is that recommended
(assuming that my main emphasis is on learning Perl6 in the context of a
beginners study group)?


I generally recommend installing star releases.
We didn't have an R* release for some time, which is why recommendations 
for perlbrew have started to show up, but that's more for staying at the 
(b)leading edge, not for beginners.



Is there a PREFIX setting,


sure, Configure.pl --prefix=... --gen-moar

(--gen-moar implies backend moar)


should I wish to install it under my home
directory?


It makes permission management easier, which is why I tend to do that.

Cheers,
Moritz


Re: Confused about rakudobrew and Rakudo Star

2016-02-04 Thread Moritz Lenz



On 02/04/2016 01:26 PM, James E Keenan wrote:

On 02/03/2016 10:48 PM, Brandon Allbery wrote:

On Wed, Feb 3, 2016 at 10:30 PM, James E Keenan 
wrote:


I am evidently confused as to the relationship, if any, between the
'rakudobrew' utility and the Rakudo::Star distribution.



In short: rakudobrew is for the folks who want to track the rapid
development of Rakudo. Star is for folks who want something stable in
order
to play with the language, and includes the Task::Star ecosystem. As Star
was cut earlier today, it's based on the rakudo that was current earlier
today (and still fairly current as there haven't been many commits in the
past few hours).

It's more or less the difference between a Python or Perl 5 release, and
installing either from git HEAD. rakudobrew builds from HEAD; Star is a
release, which happens to be close to HEAD at the moment because it was
just created. HEAD will keep moving; Star will stay stable for a while
(used to be monthly, but they're considering releasing less often now)
before the next release.



So, to clarify:  If I want to get this week's release of Rakudo Star on,
say, Linux, I have to download this tarball:

http://rakudo.org/downloads/star/rakudo-star-2016.01.tar.gz

... and build from source -- correct?  I cannot use rakudobrew for
Rakudo Star -- correct?


Correct on both.


Re: Confused about rakudobrew and Rakudo Star

2016-02-04 Thread Moritz Lenz

Hi,

On 02/04/2016 01:44 PM, Brock Wilcox wrote:

If my understanding is correct (might not be), the tarball should be
ALMOST equivalent to:

 rakudobrew build moar 2016.01.1 # Install rakudo 2016.01.1
 rakudobrew global 2016.01.1 # Make this the default
 rakudobrew build panda  # Build panda for this rakudo
 panda install Task::Star# Get the latest Task::Star,
needs --force to do again

I just did these steps on my Debian machine with no problems.

The main issue I can think of is the last step -- installing Task::Star
installs the current version of all the packages, whereas the tarball
rakudo-star release includes a specific version of each of the Star
modules. If someone updates SVG then this will get the LATEST, not the
one in the official release. I think this is a weakness of the
versioning system -- ideally you'd be able to do something like "panda
install Task::Star=2016.01" and get the exact same thing.

I see Moritz replied to this also saying that the tarball is the way to
go. I'd love to know what I'm missing out on by doing it this way.


Exactly what you speculated above.

The correct approach would be to have releases from each module, and 
depend on these versions, and then one could make a Task::Star release 
that depends on these specific versions.


Cheers,
Moritz




Re: Jonathan's "Perl 6 Introductory course"

2015-12-31 Thread Moritz Lenz


On 12/31/2015 04:26 PM, Sitaram Chamarty wrote:
> On 31/12/15 20:43, Tom Browder wrote:
>> Jonathan's intro course, in pdf, here:
>> 
>>   https://github.com/rakudo/star/raw/master/docs/2015-spw-perl6-course.pdf
>> 
>> is excellent, of course.  But I really like the presentation theme and
>> the slide formatting!
>> 
>> Does anyone know what slide-making process he uses?
>> 
>> So far the best I have found that meets my needs is using asciidoc
>> input with Asciidoctor's Deck.js backend. I think I can convert from
>> the generated html to pdf but can't say for sure yet, but it is the
>> good looks of his slides that I'm primarily interested in.
> 
> Looks like Beamer (latex+beamer).

The meta data of the PDF agrees, it says "LaTeX with Beamer class
version 3.10" in the "creator" field.

Cheers,
Moritz


Re: Constants as members of a class

2015-12-18 Thread Moritz Lenz
Hi,

On 12/18/2015 03:46 AM, TS xx wrote:
> Hello dear perl6 users,
> 
> I was in the need of declaring a member variable as a constant integer.

I don't understand this. If it's a constant, why does it need to be
member at all? A member is per-instance storage, which seems to be a
waste for a constant.

Just do

class MyClass {
method TheConstant { 42 }
}

Then you can use it both on the class:

say MyClass.TheConstant

or on an instance:

say MyClass.new.TheConstant


Cheers,
Moritz


Re: Gather/take & return, PHP7-style

2015-12-10 Thread Moritz Lenz

On 12/09/2015 07:35 PM, yary wrote:

This feature builds upon the generator functionality introduced into
PHP 5.5. It enables for a return statement to be used within a
generator to enable for a final expression to be returned (return by
reference is not allowed). This value can be fetched using the new
Generator::getReturn() method, which may only be used once the
generator has finishing yielding values.

getReturn(), PHP_EOL;

The above example will output:

1
2
3

Being able to explicitly return a final value from a generator is a
handy ability to have. This is because it enables for a final value to
be returned by a generator (from perhaps some form of coroutine
computation) that can be specifically handled by the client code
executing the generator. This is far simpler than forcing the client
code to firstly check whether the final value has been yielded, and
then if so, to handle that value specifically.


So this is meant as some sort of "EOF" (or rather EOL) marker, right?

Perl 6 does not do this, because there's already an EOF mechanism, and 
you can use LAST phasers to execute after the final iteration, but still 
inside the scope of the loop that works with the list.


Cheers,
Moritz


Announce: Rakudo Star Release 2015.11

2015-11-28 Thread Moritz Lenz
On behalf of the Rakudo and Perl 6 development teams, I'm happy to
announce the November 2015 release of "Rakudo Star", a useful and usable
distribution of Perl 6. The tarball for the November 2015 release is
available from .

This Rakudo Star release comes with support for the MoarVM
backend (all module tests pass on supported platforms).

In the Perl 6 world, we make a distinction between the language
("Perl 6") and specific implementations of the language such as
"Rakudo Perl". This Star release includes [release 2015.11] of the
[Rakudo Perl 6 compiler], version 2015.11 of [MoarVM], plus various
modules, documentation, and other resources collected from the
Perl 6 community.

[release 2015.11]:
https://github.com/rakudo/rakudo/blob/nom/docs/announce/2015.11.md
[Rakudo Perl 6 compiler]: http://github.com/rakudo/rakudo
[MoarVM]: http://moarvm.org/

Some of the new compiler features since the ast Rakudo Star release include:

+ There is now an `infix:<.>` operator that does method calls with slightly
  looser precedence than the postfix unary method call.
+ New operator `infix o` for function composition
+ `fc` for Unicode-correct case folding implemented
+ grep now accepts :k, :v, :kv, :p attributes
+ `Supply.throttle` for rate-limiting
+ Array.push is now used for pushing one element (mostly); Array.append
  exists for pushing multiple values. Same for `unshift`/`prepend`
+ Basic arithmetic operations (`+`, `*`, `-`, `/`) on Range objects
  that shift or scale the end points while maintaining exclusions
+ The v notation now allows alphabetic components: v1.2.beta.  (Incompatible
  because method calls on a version must be protected by \ or () now.)
+ `use v6b+;` notation is now recognized and enforced
+ Many built-in methods that return iterables are now much faster
+ Better error messages when comparing version strings with numbers
+ Several error messages that were lacking line numbers now include them
+ Initial shaped array support
+ `\r\n` (Carriage Return/LineFeed) is now a single (synthetic) grapheme
+ Unicode support adheres to Unicode Annex #29
+ Unicode quotes are now also allowed in regular expressions
+ Improved newline support with "use newline" and updates to IO::Handle
+ Added List.head, List.tail, List.repeated methods
+ Str.encode now allows :replacement parameter for unencodable sequences
+ Str.split now accepts multiple strings to split on
+ New Range.int-bounds returns first/last value for integer ranges
+ Auto-generated meta-ops vivified by referring to them, instead of
executing
+ Illegal assignment of different Numeric values now caught at compile time
+ `` implemented, which returns the routine that `nextsame`
would invoke
+ Many speedups

The Rakudo Perl 6 compiler is now officially in beta for the upcoming
production release around Christmas 2015.

Please note that this release of Rakudo Star is not fully functional
with the
JVM backend from the Rakudo compiler. Please use the MoarVM backend only.

Notable changes in modules shipped with Rakudo Star:

* Bailador: Add MIT License
* DBIish: Improved Windows support
* doc: More documentation; generated HTML is better searchable
* Template::Mustache: Switched from LGPL to Artistic License 2.0
* panda: Default action is no longer `install`; better help messages
* Digest::MD5: Now accepts non-ASCII input (internally encodes as Latin-1)
* LWP::Simple: Support for successful return codes besides 200
* Shell::Command: `which` routine for locating executables
* Updated docs/2015-spw-perl6-course.pdf from Nov 21

There are some key features of Perl 6 that Rakudo Star does not yet
handle appropriately, although they will appear in upcoming releases.
Some of the not-quite-there features include:

  * advanced macros
  * non-blocking I/O (in progress)
  * much of Synopsis 9 and 11

There is an online resource at 
that lists the known implemented and missing features of Rakudo's
backends and other Perl 6 implementations.

In many places we've tried to make Rakudo smart enough to inform the
programmer that a given feature isn't implemented, but there are many
that we've missed. Bug reports about missing and broken features are
welcomed at .

See  for links to much more information about
Perl 6, including documentation, example code, tutorials, reference
materials, specification documents, and other supporting resources. A
Perl 6 tutorial is available as docs/2015-spw-perl6-course.pdf in
the release tarball.

The development team thanks all of the contributors and sponsors for
making Rakudo Star possible. If you would like to contribute, see
, ask on the 
mailing list, or join us on IRC \#perl6 on freenode.


Re: signature to preserve @*ARGFILES ?

2015-11-28 Thread Moritz Lenz
Hi,

On 11/28/2015 05:49 PM, Marc Chantreux wrote:
> hello,
> 
> i would like to write a better version of the unix `column` with some
> options like 'preserve separator' so i started to write it down.
> 
> sub padded-cols ($sep,@sheet) {
> my $fmt =
> join $sep,
> @sheet[0].keys.map: 
> -> $col { "\%-{ [max] @sheet[*;$col].map: *.chars }s" };
> @sheet.map: {$fmt.sprintf(|$_)}
> }
> 
> my $sep = @*ARGS.shift;
> .say for padded-cols $sep, $*ARGFILES.lines.map: (*.split($sep)).eager;
> 
> now i would like to add options like -mean -max 1:25 and it would be
> nice to write a MAIN function to delegate borring stuff to perl6. 
> 
> i googled, tried to read the doc and grep in roast but i found no way to
> do it. any idea to help me. so thanks thanks for reading and helping.

Since $*ARGFILES (the thing behind lines() for example) uses @*ARGS to
determine what files to open, you can say


sub MAIN(*@*ARGS, Bool :$mean) { ... }

Cheers,
Moritz


Re: combine hashes

2015-11-07 Thread Moritz Lenz
On 11/07/2015 10:17 AM, Marc Chantreux wrote:
> hello Moritz, 
> 
> On Sat, Nov 07, 2015 at 08:17:21AM +0100, Moritz Lenz wrote:
>> my %x = < login jdoe first john last doe >;
>> my %y = flat (:enable, %x< login first >:p);
> 
> i tried :p but the thing is i was searching for something straight as
> the perl5 
> 
> my %y = (%x, qw( enable 1 ));
> 
> si i really loved  
> 
> my %x = < login jdoe first john last doe >;
> my %y = ( :enable, %x< login first >:p);  
> 
> to work. thanks for showing me this working code. 
> 
> actually, it rises a new question to me: why the parenthesis around
> flat are mandatory?
> 
> my %x = < login jdoe first john last doe >;
> my %y = flat (:enable, %x< login first >:p);
> 
> is ok but 
> 
> my %x = < login jdoe first john last doe >;
> my %y = flat :enable, %x< login first >:p;
> 
> give me 
> 
>> first => john, last => doe, login => jdoe
>> Unexpected named parameter 'enable' passed

Because some of the pair literal syntaxes (:enable, :enable(1), enable
=> 1, but for example not "enable" => 1) are also used for named
arguments, and sub flat doesn't want a named argument.

Putting the parens around it force it not be a named argument.

Cheers,
Moritz


Re: How to call a super class method?

2015-10-28 Thread Moritz Lenz


On 10/28/2015 08:03 AM, Patrick R. Michaud wrote:

On Wed, Oct 28, 2015 at 03:31:09AM +, TS xx wrote:


Can I call the Person's constructor (in non static context),
pass the required parameter and do more things before returning?


There are two answers to this question, both of which likely deserve
a few lines in doc.perl6.org/language/faq.  Lloyd alludes to both
answers in his replies to the original post.

1.  The typical answer to this question is to use "callwith",
"callsame", "nextwith", or "nextsame".

2.  Constructors already have some special support for building
the superclass portions of an object -- see the BUILD submethod
described in Synopsis 12.


Or more to the point, read the documentation on 
http://doc.perl6.org/language/objects#Object_Construction


(The design documents are meant for compiler writers, doc.perl6.org is 
meant for users; this has consequences on the number of examples, 
language, information density etc.)


Cheers,
Moritz


Re: Forking or running external process in background

2015-10-24 Thread Moritz Lenz


On 10/24/2015 10:06 AM, Gabor Szabo wrote:
> I am trying to test the Perl6::Maven web application by launching the
> full application (which is uses Bailador) and then accessing the pages
> using LWP::Simple.
> 
> 
> Unfortunately so far I could not figure out how to launch an external
> program in the background
> or how to fork an exec ?
> 
> I tried QX{"command &") but it waited till the command finished.
> I tried run(), but that insisted I pass each argument as a separate value
> 
> my $p = run("/usr/bin/perl", "-V", :out);

There's a shell() function that might be closer to what you want, if you
don't want to pass each argument separately.

There's also Proc::Async: http://doc.perl6.org/type/Proc::Async

But to me, it also looks like a perfect use case for threads. Have you
tried that?

Cheers,
Moritz


Re: require on string stopped working in rakudo 2015.09

2015-09-26 Thread Moritz Lenz
Hi,

On 09/26/2015 06:47 AM, Gabor Szabo wrote:
> Hi,
> 
> I am really glad Rakudo finally came out.
> I've installed in and tried to run the tests of Perl6::Maven.
> 
> They quickly failed as I have been using 'require' on string
> to check if all the module compile properly.
> 
> The following code now fails:
> 
> use v6;
> my $name = 'Bailador';
> require $name;
> 
> 
> even though
> 
> require Bailador;
> 
> works.
> 
> In 2015.07 both worked.

I stumbled across the same thing in DBIish, and was told that the proper
way to require a module name (and not a file name) is

require ::($name);

which does work in 2015.09.

I guess there's no deprecation, because it was only an accident that the
string form worked before.

Cheers,
Moritz


Re: require on string stopped working in rakudo 2015.09

2015-09-26 Thread Moritz Lenz

On 09/26/2015 01:07 PM, Elizabeth Mattijsen wrote:
>> On 26 Sep 2015, at 06:47, Gabor Szabo  wrote:
>> I am really glad Rakudo finally came out.
>> I've installed in and tried to run the tests of Perl6::Maven.
>> 
>> They quickly failed as I have been using 'require' on string
>> to check if all the module compile properly.
>> 
>> The following code now fails:
>> 
>> use v6;
>> my $name = 'Bailador';
>> require $name;
>> 
>> 
>> even though
>> 
>> require Bailador;
>> 
>> works.
>> 
>> In 2015.07 both worked.
>> 
>> 
>> I've fixed my script by switching to EVAL "use $module";
>> but I wonder if this is a regression or a planned deprecation?
> 
> I’m not sure yet.
> 
> Could you please rakudobug it so that it doesn’t fall through the cracks?  
> This change did not fire any spectest alarm either, so maybe we need a test 
> for it as well  :-)

I've opened https://rt.perl.org/Ticket/Display.html?id=126096 and later
rejcted it when learning about the desired behavior.

Cheers,
Moritz


Re: Method 'send' not found for invocant of class 'IO::Socket::INET'

2015-09-26 Thread Moritz Lenz
Hi,

method .send was deprecated in favor of .print (for strings) and .write
(with bufs/blobs)

Maybe Bailador or one of its dependencies needs updating.

Cheers,
Moritz


Re: How to push a hash on an array without flattening it to Pairs?

2015-09-26 Thread Moritz Lenz

On 09/26/2015 02:26 PM, Aristotle Pagaltzis wrote:
> Now of course I must ask – is there an opposite also? I.e. when writing
> a list, is there a way I can say “do flatten this item?” 

Yes, that's what type Slip is for: http://doc.perl6.org/type/Slip

It's useful for returning more than one list item from a .map call, for
example.

Cheers,
Moritz


Announce: Rakudo Star Release 2015.09

2015-09-26 Thread Moritz Lenz
On behalf of the Rakudo and Perl 6 development teams, I'm excited to
announce the September 2015 release of "Rakudo Star", a useful and
usable distribution of Perl 6. The tarball for the September 2015
release is available from .

This Rakudo Star release comes with support for the MoarVM backend (all
module tests pass on supported platforms).
Please note that this release of Rakudo Star is not fully functional
with the JVM backend from the Rakudo compiler. Support should be
restored shortly.

In the Perl 6 world, we make a distinction between the language ("Perl
6") and specific implementations of the language such as "Rakudo Perl".
This Star release includes [release 2015.09] of the [Rakudo Perl 6
compiler], version 2015.09 of [MoarVM], plus various modules,
documentation, and other resources collected from the Perl 6 community.

[release 2015.09]:
https://github.com/rakudo/rakudo/blob/nom/docs/announce/2015.09.md
[Rakudo Perl 6 compiler]: http://github.com/rakudo/rakudo
[MoarVM]: http://moarvm.org/

Some of the new compiler features added to this release include:

* Great List Refactor (GLR) - See http://design.perl6.org/S07.html
* All Deprecations removed in preparation for Christmas release
* Added support for calling into C++ libraries and calling methods on
C++ classes
* New slurpy parameter, +args or +@args, to allow for one-argument style
binding
* New with/orwith/without conditionals allow you to check for .defined
but topicalize to the actual value returned
* New `supply`, `whenever` and `react` blocks for easy reactive programming
* All Unicode digits can now be part of literal numbers
* `val()` and allomorphic types implemented
* Most European quoting styles are now supported
* New $[...] and ${...} constructs allow prefix itemization
* The .gist and .perl methods can now deal with self-referential structures


Notable changes in modules shipped with Rakudo Star:

* All modules fixed to work with GLR where needed
* Panda now includes JSON::Fast and no longer precompiles to byte code
* Terminal::ANSIColor replaces the deprecated Term::ANSIColor
* New Perl 6 tutorial replaces original perl6 book draft

There are some key features of Perl 6 that Rakudo Star does not yet
handle appropriately, although they will appear in upcoming releases.
Some of the not-quite-there features include:

  * advanced macros
  * non-blocking I/O (in progress)
  * much of Synopsis 9 and 11

There is an online resource at 
that lists the known implemented and missing features of Rakudo's
backends and other Perl 6 implementations.

In many places we've tried to make Rakudo smart enough to inform the
programmer that a given feature isn't implemented, but there are many
that we've missed. Bug reports about missing and broken features are
welcomed at .

See  for links to much more information about
Perl 6, including documentation, example code, tutorials, reference
materials, specification documents, and other supporting resources. A
Perl 6 tutorial is available as docs/2015-spw-perl6-course.pdf in
the release tarball.

The development team thanks all of the contributors and sponsors for
making Rakudo Star possible. If you would like to contribute, see
, ask on the 
mailing list, or join us on IRC \#perl6 on freenode.


Re: What are Perl 6's killer advantages over Perl 5?

2015-08-26 Thread Moritz Lenz

Hi,

On 11.08.2015 14:12, Tom Browder wrote:

I have seen several lists of new Perl 6 features (versus Perl 5) but
they all seem to be lists that intermix features with varying degrees of
value to ordinary Perl 5 users.  If one wants to sell long-time Perl 5
users (already using the latest Perl 5, Moose, etc.) on the value of
Perl 6, what should be on the important feature list?


on a more meta level: Perl 6 has the ability to evolve, and lots of 
things that Perl 5 most likely will never have.


Just as an example: when I started to get involved with Perl around 2003 
or '04 or so, people seemed to be aware that subroutine signatures were 
a good thing to have. They probably were aware of that much longer. And 
yet it took until perl 5.20 in 2014 to get even the most basic 
subroutine signatures (and still marked as experimental).


Another one is the inability to reliably introspect strings for whether 
they are text or binary data, which means enormous care must be taken to 
not accidentally mix the two. Again, known for ages that it's a problem, 
afaict no practical solution in sight.


These are just two examples of things that people take for granted in a 
modern programming language, yet Perl 5 has real trouble with.


I could continue with other Perl 5 deficiencies (no strict by default, 
lack of easy threading, too many globals, obscure regex syntax), but the 
individual problems aren't the point. My main point is that large parts 
of Perl 5 are still stuck in the past, with no good way forward.


Cheers,
Moritz


Re: Is creating and Array or Parcel ?

2015-08-02 Thread Moritz Lenz

Hi,

On 02.08.2015 06:43, Gabor Szabo wrote:



On Fri, Jul 31, 2015 at 4:16 PM, Moritz Lenz mor...@faui2k3.org
mailto:mor...@faui2k3.org wrote:



On 07/31/2015 03:02 PM, Gabor Szabo wrote:

The following code (with comments) is confusing me.
Can someone give some explanation please?
Specifically the difference between

my @x = a b;


It's the assignment to the Array variable that makes the Array here;
  by itself just creates a Parcel:

$ ./perl6-m -e 'say a b.^name'
Parcel
$ ./perl6-m -e 'say (my @ = a b ).^name'
Array

# we can assign that array to a scalar variable and it is still
and array
my $y = @x;


that's because assignment to $ isn't coercive in the same way as
assignment to @ or %.

It just wraps things into a Scalar, which is normally invisible.

But, you can observe the difference still

my @a = a b;
my $s = @a'

for @a { } # two iterations
for $s { } # one iteration


Thanks though this just shows I still don't get the whole sigil and
Array thing in Perl 6.
I thought you can put an array in a $ -ish variable and that will still
be a real array, but
now I see it is not an array.


It's an Array inside a Scalar.

If you want to extract it from the scalar, use the @ again, this time as 
a prefix:


for @$s { } # two iterations again.

Cheers,
Moritz


Re: Sub args: choose one of two?

2015-06-28 Thread Moritz Lenz
Hi,

On 06/28/2015 12:39 AM, Tom Browder wrote:
 I'm trying to take advantage of the MAIN suroutine to handle most all of
 my routine command line arg handling.  One idiom I use a lot is for the
 user to choose only one of two args, but one must be chosen.

So since it's not optional, you might consider not making it an option
(prefixed with --), but rather a simple command:


$ cat door
#!/usr/bin/env perl6

multi MAIN('open') {
say Opening door;
}
multi MAIN('close') {
say Closing door;
}
$ ./door
Usage:
  ./door open
  ./door close
$ ./door open
Opening door

Cheers,
Moritz


Re: Perl 5's $0 vs. Perl 6's $*EXECUTABLE_NAME

2015-05-30 Thread Moritz Lenz
Hi,

On 05/30/2015 04:36 PM, Paul Cochrane wrote:
 Thanks for pointing out the $*PROGRAM omission!  I've just added it to the
 list of special variables and it should be available online within the next
 10-15 minutes.

Minor nit pick: according to the last log on
http://doc.perl6.org/build-log/ building the docs alone takes ~17min;
the cron job runs every 5 minutes, so it's more likely 17-22min before
it becomes available :-)

And thanks for adding $*PROGRAM to the docs!

Cheers,
Moritz


Re: Can a user cheat and call a class's private method?

2015-05-12 Thread Moritz Lenz
Hi,

On 05/12/2015 09:40 PM, R. Ransbottom wrote:
 On Mon, May 11, 2015 at 03:22:46PM -0700, Darren Duncan wrote:
 
 you can use trusts.  Also having to do this may indicate bad code
 design. -- Darren Duncan
 
 I saw Moritz' and Carl's responses and I agree with the smell
 issue.  
 
 Given that the code exists and needs testing,

I'm curious, what's a case where private state of a class needs to be
tested, and tests agains the public interface are not enough?

In my experience, testing against private parts only makes the tests
more brittle (that is, every implementation change causes test failures,
even if the public interface is unchanged).

Also, are you talking about an actual Perl 6 code base that needs
testing, but that is too large for a refactoring? If yes, I'd be curious
where such a beast exists.

 Is class finalization implemented?

I don't think so.

Cheers,
Moritz


Re: Fancy sub arg handling: ability to expand error message?

2015-03-28 Thread Moritz Lenz
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Hi,

On 28.03.2015 12:27, Tom Browder wrote:
 I like the subroutine arg handling in Perl 6.  Is there any simple 
 way to attach a short error msg in place of or additive to the 
 default for, say, a missing arg?

You can always use multi subs, and use a catch-all candidate which
produces the error message.

multi thingy($x) { $x + 42 }
multi thingy(|c) { die Must call thingy with exactly one argument }

Though IMHO that's usually not worth the trouble; you get the error
message only for programming errors, not for user errors; and
programmers should be able to understand the error message (or we need
to improve the error messages, if that's not the case).

Also it makes it harder for others to extend your API by providing
additional multi candidates.

Cheers,
Moritz
-BEGIN PGP SIGNATURE-
Version: GnuPG v1

iEYEARECAAYFAlUWsnQACgkQT81LMIj/VkTbAwCfTsQumtjPKj1lxXZlnQ+U+0Xz
uTQAn287aU2xU7m6iMFGWD+j2R+Bouy6
=LWsI
-END PGP SIGNATURE-


Re: How to get indirect access to a class attribute?

2015-03-25 Thread Moritz Lenz
Hi,

On 25.03.2015 13:44, Tom Browder wrote:
 Given a class like:
 
 our %attrs = (age=1,wgt=2);
 class foo { has $.age = rw;}

should be 'has $.age is rw'. The is indicates a trait (not an
assignment).

 method a {
   for %attrs.kv - $k, $v {
  my $aval = self.$k();  # supposed to work for a method name


Etiher method a needs to be inside class foo, or it needs to be a
subroutine, and refer to foo instead of self here.

A method outside a class doesn't ususally make sense, which is why you
get this message:

Other potential difficulties:
Useless declaration of a has-scoped method in mainline (did you mean
'my method a'?)

  say attr { $k } has value '{ $aval }';
   }
 }
 
 Question:
 
 1. How can I indirectly refer to the attributes in a method?  The
 above doesn't work (with or without the '()').

the indirect method call syntax is the right approach, you just got too
many other details wrong to make it work.

Cheers,
Moritz


Announce: Rakudo Star Release 2015.03

2015-03-21 Thread Moritz Lenz
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

## A useful, usable, early adopter distribution of Perl 6

On behalf of the Rakudo and Perl 6 development teams, I'm happy to
announce the March 2015 release of Rakudo Star, a useful and usable
distribution of Perl 6. The tarball for the March 2015 release is
available from http://rakudo.org/downloads/star/.

This Rakudo Star release comes with support for the MoarVM
backend (all module tests pass on supported platforms) along with
experimental support for the JVM backend (the modules `Bailador`,
`Digest::MD5` and `Grammar::Profiler::Simple` are known to fail tests).

In the Perl 6 world, we make a distinction between the language
(Perl 6) and specific implementations of the language such as
Rakudo Perl. This Star release includes [release 2015.03] of the
[Rakudo Perl 6 compiler], version 2015.03 of [MoarVM], plus various
modules, documentation, and other resources collected from the
Perl 6 community.

[release 2015.03]:
https://github.com/rakudo/rakudo/blob/nom/docs/announce/2015.03.md
[Rakudo Perl 6 compiler]: http://github.com/rakudo/rakudo
[MoarVM]: http://moarvm.org/

Some of the new compiler features added to this release include:

+ several renames of semi-internal methods. Please refer to [the Rakudo
  2015.02 release
notes](https://github.com/rakudo/rakudo/blob/nom/docs/announce/2015.03.md)
for the full list
+ Allow `Buf.AT-POS` to return an l-value.
+ Implement `method ^foo($) { ... }` syntax.
+ Implemented [PairMap](http://doc.perl6.org/type/PairMap) (the simple
case only, for now).
+ Implemented `.antipairs` (pairs with value = key).
+ Implemented [pairup](http://doc.perl6.org/type/Any#method_pairup)
for creating pairs from lists.
+ Implemented `LEXICAL`, `OUTERS` and `CALLERS` pseudo-packages
+ Add `array[T]`, usable for native `int`/`num` (MoarVM only for now)
+ Other native improvements, e.g. `my int $a; $a++`
+ Implement `IO::Path.resolve` on r-m/POSIX

In future, the `nqp::` namespace willl only be available after a
declaration
like `use nqp;`.

Changes to modules included in Rakudo Star:

- - [DBIish](https://github.com/perl6/DBIish) supports local Sockets on
mysql,
  and now correctly handles returned NULL values in the Pg backend
- - [doc](https://github.com/perl6/doc) ships with much more documentation

There are some key features of Perl 6 that Rakudo Star does not yet
handle appropriately, although they will appear in upcoming releases.
Some of the not-quite-there features include:

  * advanced macros
  * threads and concurrency (in progress)
  * Unicode strings at levels other than codepoints
  * interactive readline that understands Unicode
  * non-blocking I/O (in progress)
  * much of Synopsis 9 and 11

There is an online resource at http://perl6.org/compilers/features
that lists the known implemented and missing features of Rakudo's
backends and other Perl 6 implementations.

In many places we've tried to make Rakudo smart enough to inform the
programmer that a given feature isn't implemented, but there are many
that we've missed. Bug reports about missing and broken features are
welcomed at rakudo...@perl.org.

See http://perl6.org/ for links to much more information about
Perl 6, including documentation, example code, tutorials, reference
materials, specification documents, and other supporting resources. A
draft of a Perl 6 book is available as docs/UsingPerl6-draft.pdf in
the release tarball.

The development team thanks all of the contributors and sponsors for
making Rakudo Star possible. If you would like to contribute, see
http://rakudo.org/how-to-help, ask on the perl6-compi...@perl.org
mailing list, or join us on IRC \#perl6 on freenode.
-BEGIN PGP SIGNATURE-
Version: GnuPG v1

iEYEARECAAYFAlUN3iYACgkQT81LMIj/VkTYSACfeumxLQzxeRPfNHIYge6ZHEwU
L9sAn0rfiVwi5CB0RSFJ125UKvv5P7OG
=+CBE
-END PGP SIGNATURE-


Re: Need help with: Cannot find method 'postcircumfix:( )'...

2015-03-20 Thread Moritz Lenz



On 03/20/2015 11:00 AM, Timo Paulssen wrote:

On 03/20/2015 03:40 AM, Brandon Allbery wrote:


On Thu, Mar 19, 2015 at 10:33 PM, Tom Browder tom.brow...@gmail.com
mailto:tom.brow...@gmail.com wrote:

Why do you say that is not a method?  The first line says


Sorry, somehow I managed to misread that.

So you want what I have already said twice: the accessor `self.elem`.
If you want to access the variable directly for some reason, you use
the form `$.elem`. (By the way, that shadowing is generally bad form,
and not just in Perl 6. It makes code confusing to read)


Actually, $.elem is just short for $(self.elem); if you want direct
access to the variable you'd write $!elem. Also, an indirect method
call would be self.$elem,


small correction: self.$elem().
self.$elem is an error, which is useful to catch p5 programmers who 
use . for string concatenation.


Cheers,
Moritz


Re: Can a class have an attribute and a method with the same name?

2015-03-19 Thread Moritz Lenz

Hi,

On 03/19/2015 12:40 AM, Tom Browder wrote:

I have a class with an attribute and a method with the same name and
it looks so far like they clash.


Attributes are always private. If you write 'has $.x', that generates 
not only the attribute, but also an accessor method of name 'x'. See 
also http://doc.perl6.org/language/objects#Attributes


So, you can have an attribute $!x and a method x, but if you write

class A {
has $.x;
method x() {... }
}

then the method will prevent the automatic accessor from being generated.


Cheers,
Moritz


Re: Passing arrays to subroutines

2015-03-19 Thread Moritz Lenz



On 03/19/2015 04:05 PM, Tom Browder wrote:

In Perl 5 I can do this:

my @a = (1, 2);
my @b = (3);

foo(@a,@b);

sub foo { my $n = @_;  die Wrong num args: $n if ($n != 3);}

In Perl 6 I think this is correct (or nearly so):

sub foo(*@args) { die Wrong num args: { @args.elems } if @args.elems != 3;}

Questions for Perl 6:

foo is now defined as:

sub foo($a, $b, $c) { # do something with $a, $b, $c }

but I want to call it with a flattened array arg.

1.  How can I combine arrays @a and @b into one array?


generally with the comma operator:

my @combined = @a, @b;


2.  Can I flatten the arrays into elements inside the foo call?


foo(|@combined)

Cheers,
Moritz


Re: Object Contruction

2015-03-18 Thread Moritz Lenz

Hi

On 03/18/2015 01:06 PM, Tom Browder wrote:

My new object needs some methods run during construction.  How can I
do that without defining my own new method?


http://doc.perl6.org/language/objects#Object_Construction lists at least 
two possible ways. Probably the most interesting one is BUILDALL with a 
callsame; see the last example (or example skeleton) in that section.


Cheers,
Moritz


Announce: Rakudo Star Release 2015.01

2015-02-07 Thread Moritz Lenz
# Announce: Rakudo Star Release 2015.01

## A useful, usable, early adopter distribution of Perl 6

On behalf of the Rakudo and Perl 6 development teams, I'm happy to
announce the January 2015 release of Rakudo Star, a useful and usable
distribution of Perl 6. The tarball for the January 2015 release is
available from http://rakudo.org/downloads/star/.

This Rakudo Star release comes with support for the MoarVM
backend (all module tests pass on supported platforms) along with
experimental support for the JVM backend (some module tests fail).
Three shipped modules are known to fail on Parrot (zavolaj (NativeCall),
jsonrpc and doc)

In the Perl 6 world, we make a distinction between the language
(Perl 6) and specific implementations of the language such as
Rakudo Perl. This Star release includes [release 2015.01.1] of the
[Rakudo Perl 6 compiler], version 7.0.1 of the [Parrot Virtual
Machine], version 2015.01 of [MoarVM], plus various modules,
documentation, and other resources collected from the Perl 6
community.

[release 2015.01.1]:
https://github.com/rakudo/rakudo/blob/nom/docs/announce/2015.01.md
[Rakudo Perl 6 compiler]: http://github.com/rakudo/rakudo
[Parrot Virtual Machine]: http://parrot.org
[MoarVM]: http://moarvm.org/

Some of the new compiler features added to this release include:

+ Many improvements to Java interop for the JVM backend
+ New simple way of creating an object hash: :{}
+ Substitution now supports assignment meta-op, e.g. s[\d+] += 2
+ Many memory and CPU optimizations
+ Supply.for deprecated in favour of Supply.from-list

Changes to modules included in Rakudo Star:

- [Bailador](https://github.com/tadzik/Bailador) handles POST and URL
params separately
- [DBIish](https://github.com/perl6/DBIish) has improved error reporting
on SQLite
- [doc](https://github.com/perl6/doc) ships with much more documentation
- [panda](https://github.com/tadzik/panda) has a new command `installdeps`
- [Pod::To::HTML](https://github.com/perl6/Pod-To-HTML) now supports
callbacks for code areas

Parrot support will likely be suspended or dropped from future Rakudo
and Rakudo
Star releases, starting with the February or March releases.

In the next Rakudo Star release, modules `Math::RungeKutta` and
`Math::Model`
will likely be dropped. They can still be installed with `panda`.

In future, the `nqp::` namespace willl only be available after a declaration
like `use nqp;'.

There are some key features of Perl 6 that Rakudo Star does not yet
handle appropriately, although they will appear in upcoming releases.
Some of the not-quite-there features include:

  * advanced macros
  * threads and concurrency (in progress for the JVM and MoarVM backend)
  * Unicode strings at levels other than codepoints
  * interactive readline that understands Unicode
  * non-blocking I/O (in progress for the JVM and MoarVM backend)
  * much of Synopsis 9 and 11

There is an online resource at http://perl6.org/compilers/features
that lists the known implemented and missing features of Rakudo's
backends and other Perl 6 implementations.

In many places we've tried to make Rakudo smart enough to inform the
programmer that a given feature isn't implemented, but there are many
that we've missed. Bug reports about missing and broken features are
welcomed at rakudo...@perl.org.

See http://perl6.org/ for links to much more information about
Perl 6, including documentation, example code, tutorials, reference
materials, specification documents, and other supporting resources. A
draft of a Perl 6 book is available as docs/UsingPerl6-draft.pdf in
the release tarball.

The development team thanks all of the contributors and sponsors for
making Rakudo Star possible. If you would like to contribute, see
http://rakudo.org/how-to-help, ask on the perl6-compi...@perl.org
mailing list, or join us on IRC \#perl6 on freenode.


Re: time and now showing different time?

2015-01-12 Thread Moritz Lenz



On 01/12/2015 10:36 AM, Gabor Szabo wrote:


On Mon, Jan 12, 2015 at 10:35 AM, Tobias Leich em...@froggs.de
mailto:em...@froggs.de wrote:

Also interesting might be the fact that BEGIN statements/blocks do
return a value:

say now() - BEGIN now; # parens needed to there so that it does not gobble 
args


Hmm, actually it does not let me put the parens there:
$ perl6 -e 'say now() - BEGIN now;'

===SORRY!=== Error while compiling -e
Undeclared routine:
 now used at line 1

This works:

$ perl6 -e 'say now - BEGIN now;'
0.0467931

but I am not sure why is that interesting. Could you elaborate please?


It's mostly interesting when you're working on the compiler, because it 
gives an easy way to time how long it takes to compile the program.






One of them counts leap seconds, the other doesn't. Instant is
supposed
to be a monotonic clock, the other isn't.



Oh and Timo,  I think, if I understand this correctly, they are both
monotonic in the mathematical sense.
Neither can decreases, can day?


I don't think so, but I'm not an expert in the domain.


The difference is that 'time' stops here-and-there and waits for a leap
second to pass before it resumes increasing.


Right, that's strictly monotonic vs. monotonic.

The background is that if you want to control something where the 
interval is more important than the exact timing, use 'now'. You don't 
want to X-ray the patient for an extra second just because there's a 
leap second during the test.


Cheers,
Moritz


Re: Rationale for a VM + compiler approach instead of an interpreter?

2014-12-06 Thread Moritz Lenz

Hi,

On 06.12.2014 18:55, Mayuresh Kathe wrote:

Hello,

I have been reading up (a bit) on Perl6 and found most articles
mentioning Parrot + Rakudo as the primary tools for development using
the language.


Well, these days we have three backends (MoarVM, JVM and Rakudo).


Is there any rationale for going with the above approach instead of an
interpreter based one?


First of all, the lines between interpreters and compilers a bit blurry. 
People think of Perl 5 as an interpreter, but actually it compilers to 
bytecode, which is then run by a runloop. So it has a compiler and an 
interpreter stage.


Rakudo does the same, except that it also adds the ability to serialize 
the byte code to a file. (At least for modules; doesn't work for scripts).


Apart from the usual trade-offs between compilers and interpreters, 
there's a Perl 6 specific reason. There are lots of pieces from the 
compiler that must behave like Perl 6 code. For example you must be able 
to extend the grammar that parses Perl 6 with Perl 6 regexes. The 
compiler must provide the built-in types and routines, all with the 
usual Perl 6 calling conventions, with Perl 6 type constraints etc.


And these things are much easier to achieve if you have some degree of 
self-hosting, that is, stuff is implemented in Perl 6 (or a subset 
thereof). And for self-hosting, a compiler tends to be a better choice, 
because you can store the byte code and use it as a base for 
bootstrapping. Maybe it's just my lack of imagination, but I have 
trouble imagine a sane and fast bootstrapping mechanism for interpreters.



Also, would there be community acceptance of an interpreter written in
portable c89 for Perl6?


Oh yes!
We've had many lucky periods where more than one compiler was actively 
developed (any(pugs, kp6 (now perlito), rakudo, niecza)), which lead to 
friendly competition, fresh ideas and generally lots of fun.


Cheers,
Moritz


Re: Date truncated-to method argument?

2014-11-10 Thread Moritz Lenz

Hi,

On 11/10/2014 01:39 PM, Steve Mynott wrote:

http://doc.perl6.org/type/Date says

my $c = Date.new('2012-12-24');
say $c.truncated-to(:year); # 2012-01-01

but this doesn't work and what's implemented appears to be year
rather than :year

$ perl6

my $c = Date.new('2012-12-24');

2012-12-24

say $c.truncated-to(year)

2012-01-01

Which is correct the code or docs?



iirc there was a spec change.

Let's check...

$ ~/p6/specs (master)$ git log -p -S truncated
commit 9d8bc5fe62dd38805d791c0351c85185d351290e
Author: Carl Masak cma...@gmail.com
Date:   Thu Jan 24 18:27:55 2013 +0100

[S32/Temporal] spec DateTime.delta and Date.delta

Clarify the .truncated-to method as well; it also uses the
CTimeUnit enum, instead of named parameters.

...
-The Ctruncated-to method allows you to clear a number of time values
+The Ctruncated-to constructor allows you to clear a number of time 
values

 below a given resolution:

 my $dt = DateTime.new('2005-02-01T15:20:35Z');
-say $dt.truncated-to(:hour); # 2005-02-01T15:00:00Z
+say $dt.truncated-to(hour); # 2005-02-01T15:00:00Z

-An argument of C:week yields an object with the date of the last Monday
+Arguments to Ctruncated-to belong to the enum CTimeUnit, which 
encompasses

+these values:
+
+second  seconds
+minute  minutes
+hourhours
+day days
+weekweeks
+month   months
+yearyears
+
...

so looks like the docs are out of date. Patches to fix that would be 
awesome!


Cheers,
Moritz


Re: Code execution during compilation

2014-06-15 Thread Moritz Lenz
Hi,

class and role bodies are executed at compile time, so yes, that's
expected. The same thing happens in BEGIN blocks.

(Actually, the case with roles is more complicated; iirc their bodies
are executed at role application time, but in your example, 'class B
does Xx' runs at compile time, so the two are roughly equivalent).

Cheers,
Moritz

On 06/15/2014 02:31 AM, Kamil Kułaga wrote:
 Hi,
 
 I got amazed little bit when this code:
 class A {
  method wow{say I'm alive}
 }
 
 role Xx{
   my $th = A.wow;
 }
 
 
 class B does Xx {
 }
 
 Started to live during compilation (also tried with ufo):
 
 $ perl6 -o o.pir funnyrole.pl
 I'm alive
 
 
 Is this expected or subject to change?
 


Re: Perl6 and wxwidgets

2014-06-08 Thread Moritz Lenz
Hallo Erik,

On 08.06.2014 12:54, Erik Colson wrote:
 Is it possible to use an external C-library like wxwidgets from perl6/moarvm ?
 If so, is there any doc how this can be achieved ?

It is, through the NativeCall library: https://github.com/jnthn/zavolaj/

Cheers,
Moritz


Re: Regex: fail if ... present

2014-05-30 Thread Moritz Lenz
Hi Peter,

On 30.05.2014 20:46, Peter Schwenn wrote:
 Dear Perl6istes,
 
 How does one express in a perl6 match pattern that if a certain
 subpattern is present the match fails.
 
 I had expected something like:
 
 $txt ~~ s/... -[ unwanted \s+ pattern ] .../ .../;
 
  but its not that.  Can't find it in S05.

The reason it's not that simple is that it's not enough to say what
*shouldn't* match; you also have to specify the pattern that *should*
match, even if it's .*.

Say you want to match two numbers that are separated by a word that's
not 'perl', you'd write

/ \d+ !before perl \w+ \d+ /

So, you solve it with a negative look-ahead.

Cheers,
Moritz


Re: Regex: fail if ... present

2014-05-30 Thread Moritz Lenz
Hi Peter,

On 30.05.2014 22:39, Peter Schwenn wrote:
 Dear Moritz,
 
 $txt ~~ s:g/ !before System \. Guid  /.Moniker/;
 
 transforms (in $txt):System.Guid - System.Moniker
 
 i.e. the match succeeds.  So obviously I'm not understanding negative
 look-ahead correctly.  Where's there a good description of negative look
 ahead. 

The look-ahead looks *ahead*, that is, it matches because where the
regex matches '.Guid', the next token isn't 'System'.

So either write the look-ahead like this:

$txt ~~ s:g/ !before System « \w+ \. ( Guid /Moniker/;

(The ( limits where the substitution starts).

or use a look-behind:

s:g/ !after 'System' \. Guid /.Moniker/;


For a general introduction into look-araound assertions (and many other
regex topics) I can recommend Mastering Regular Expressions by Jeffrey
Friedl. It mostly uses Perl 5 regex syntax, but the concepts translate
well to Perl 6.

Cheers,
Moritz


Re: Does perl have ensue override?

2014-05-16 Thread Moritz Lenz

Hi Kamil,

On 05/15/2014 07:48 PM, Kamil Kułaga wrote:

Is there any ordinary way (not something like getting list of methods
from base class) to ensure we are overriding method?

Java has @Override annotation that that causes compilation error if
method is not necessary for Interface(Role). It is very handy if class
does many of them and someone cuts out deprecated method and there is
no reason to implement them any longer.


Not by default, but the meta programming facilities make it just a small 
exercise to implement such a thing in user space.


I've done that in
https://gist.github.com/moritz/2c6ed01eef0029dabdeb

Feel inspired :-)

Cheers,
Moritz


Re: perl 6 beginner: regex questions

2014-02-04 Thread Moritz Lenz
Hi,

On 02/01/2014 10:56 PM, infor...@hushmail.com wrote:
 Hello,
 
 I have a few questions about the regexes.  I'm new to perl 6
 and I don't know perl 5.  I'm proficient with grep/sed.
 
 I installed Rakudo with the defaults on Linux (Mandriva 2010.1)
 and Windows 7. I get identical output for all these questions
 with the two latest Rakudo versions on Linux (2014.01 2013.12)
 and Windows (2014.01 2013.09).
 
 Questions
 
 (1) :global
 
 This works as expected:
   say ~( 'aaa'.match(/a/,:g) )  # a a a
 but this doesn't work:
   say ?( 'aaa' ~~ m:g/a/)   # False
 
 Is the second form m:g/.../ implemented?
 if it is, can you give me an example

It seems you have run into a nasty corner case.

Since m:g/.../ is immediately evaluated, and returns a list, the
resulting list is smart-matched against the string 'aaa', which fails.

Also it doesn't make too much sense to use m:g in boolean context (if
you want to know if it matches, a simple m/.../ is enough).

So instead write

given 'aaa' {
   for m:g/a/ - $m {
   say $m;
   }
}

 
 (2) capture to lexical variables, external aliasing
 
 From the synopsis:
   You may capture to existing lexical variables;
   such variables may already be visible from an
   outer scope, or may be declared within the
   regex via a :my declaration.
   my $x; / $x = [...] /  # capture to outer lexical $x
   / :my $x; $x = [...] / # capture to our own lexical $x
 
 Here I have two examples and they don't work, why?
 is this feature implemented?

No, it's not. The best you can do right now is to create a named alias
inside $/:

'abc' ~~ /$x=(..)/;
say ~$x;  # ab

   my $x; 'a' ~~ / $x=. /; say $x;# (Any)
 
   'a' ~~ / :my $x; $x = . {say $x} / # [no output]
 
 
 (3) arrays
 
 None of these four cases work and I don't know why:
 
 my @x; 'abc' ~~ / @x = .+ /; say @x[0]; # (Any)

 'abc' ~~ /^ @x=.+ $/;  say @x;  # Nil
 
 my @x; 'abc' ~~ /@x = (.)+/; # Could not find sub cuid_1_1384375491.61906
 
 'abc' ~~ / @x = (.)+ /;# Could not find sub cuid_1_1391263931.391

There are all not implemented (not sure if they are specced).

But a convenient way to create an array capture is

'abc' ~~ / $x = (.)+ /; say $x.elems;   # 3

by quantifying the capture you force it to be an array, independently of
the sigil

 
 (4) submatch
 
 I'm somewhat puzzled what a submatch is.
 
 This works:
 'ab' ~~ / (..) { say ~($0 ~~ /b/) } / # b
 
 But can a submatch be immediately nested in a regex like this:
 
 'ab' ~~ /(..) [$0 ~~ b] }/ # doesn't work

I'm somwhat puzzled too. There's a syntax for submatches like ~~0,
which means 'Match here with the regex that produced $0. Maybe that's
what you mean?

Much more useful are subrule calls, which look like foo.

 (5) interpolation
 
 how do I get a variable to interpolate into [] ?
 
 doesn't work:
   my $x='a';
   say ~('aaa' ~~ /^ [$x]+ $/) # [no output]

I'm afraid by patching Rakudo (or NQP).

 (6) why does this enter an infinite loop instead of matching?
 
 'a' ~~ /^ [.*? {say 'ok'}]+ $/

Because a repeated match that doesn't consume any characters doesn't
consume any characters.

Most regex engines have safeguards against that, we haven't yet :(


 (7) why don't these produce the same output?
 
 say 'ab'.subst(/ ''  ?before b /,'c'); # ab
 say 'ab'.subst(/ ? ?before b /,'c'); # acb
 say 'ab'.subst(/ ?before b /,'c'); # acb

At a glance, the first one looks like a bug to me.

 Similar question for these:
 
 'a' ~~ / (b ** 0..3)/; say ~$0; # [no output]

It matches zero b's a the start of the string, thus producing a
zero-width match in $0.

 'a' ~~ / (b ** 1..3)/; say ~$0; # bbb
 
 (8) implicit scanning at the beginning
 (a) regex/token/rule
 I don't understand the behavior of regex/token/rule in
 these cases, for I thought they didn't implicit scan:
 'a11' ~~ regex { (\d+) }; say $0; # 11
 'a11' ~~ token { (\d+) }; say $0; # 11
 'a11' ~~ rule  { (\d+) }; say $0; # 11

They don't scan when called with the subrule syntax, because that
implicltly anchor. Called on their own, as indepent regexes, they scan.

 the synopsis seems to suggest the opposite:
   ...
   $string ~~ regex { \d+ }
   $string ~~ token { \d+ }
   $string ~~ rule { \d+ }
   and these are equivalent to
   $string ~~ m/^ \d+ $/;
   $string ~~ m/^ \d+: $/;
   $string ~~ m/^ .ws \d+: .ws $/;
 
 (b) I find this behavior unexpected:
 say ?('ab' ~~ / ?before a /); # True
 say ?('ab' ~~ / ?before b /); # True
 say ?('ab' ~~ / ?before a ?before b /); # False
 
 In each case there is scanning at the very beginning, but
 in the 3rd case there is no scanning before ?before b as
 if ?before a had the side effect of cancelling it
 in spite of its ?
 
 i.e I was expecting ? to make ?before a side effect free

It's only side-effect free in the sense that it doesn't consume any
characters.

All independent regexes (ie not 

Re: how to set constants from command line?

2013-12-14 Thread Moritz Lenz

Hi Richard,

On 12/12/2013 08:56 AM, Richard Hainsworth wrote:

I would like to set a series of magic numbers from the command line.

I have in a program

constant N-SCENARIOS = 10;

which works great. But I would like to set an option in the command
line, such as
perl6 program.p6 scenarios=15


.. then it's not a constant. So don't use a constant. Use a variable 
instead.



I could have a normal scalar
my $scenarios ;

But that doesn't seem as elegant as creating a constant.


Using a constant for something that isn't a constant doesn't strike me 
as elegant at all.


Note that in Perl 6, there is no guarantee that command line arguments 
are known at compile time, so mucking with @*ARGS in BEGIN seems like a 
very bad idea.


Cheers,
Moritz


Rakudo Star 2013.11 released

2013-11-24 Thread Moritz Lenz

## A useful, usable, early adopter distribution of Perl 6

On behalf of the Rakudo and Perl 6 development teams, I'm happy to
announce the November 2013 release of Rakudo Star, a useful and usable
distribution of Perl 6. The tarball for the November 2013 release is
available from http://rakudo.org/downloads/star/. A Windows .MSI
version of Rakudo star will usually appear in the downloads area
shortly after the tarball release.

In the Perl 6 world, we make a distinction between the language
(Perl 6) and specific implementations of the language such as
Rakudo Perl. This Star release includes [release 2013.11] of the
[Rakudo Perl 6 compiler], version 5.9.0 of the [Parrot Virtual
Machine], plus various modules, documentation, and other resources
collected from the Perl 6 community.

[release 2013.11]:
https://github.com/rakudo/rakudo/blob/nom/docs/announce/2013.11.md
[Rakudo Perl 6 compiler]: http://github.com/rakudo/rakudo
[Parrot Virtual Machine]: http://parrot.org

Some of the new features added to this release include:

+ Order::Increase/Decrease are deprecated.  Please use Order::Less/More.
+ Leading whitespace is ignored for :sigspace
+ Better null pattern detection in regexes
+ improved run()/shell(), these return Proc::Status-objects now
+ The gethostname function implemented
+ Performance optimization: unfold junctions in 'when' clauses

This release also contains a range of bug fixes, improvements to error
reporting and better failure modes.

Please note that this release of Rakudo Star does not support the JVM
backend from the Rakudo compiler. While the JVM backend mostly 
implements the same features as the Parrot backend, many bits are still 
missing, most prominently the native call interface.

We hope to provide a JVM-based Rakudo Star release soon.

The following notable features have been deprecated or modified from 
previous releases due to changes in the Perl 6 specification, and are 
planned to be removed or changed as follows:


  * All unary hyper ops currently descend into nested arrays and
hashes. In the future, those operators and methods that are
defined nodal will behave like a one-level map.

There are some key features of Perl 6 that Rakudo Star does not yet
handle appropriately, although they will appear in upcoming releases.
Some of the not-quite-there features include:

  * advanced macros
  * threads and concurrency (in work for the JVM backend)
  * Unicode strings at levels other than codepoints
  * interactive readline that understands Unicode
  * non-blocking I/O
  * much of Synopsis 9 and 11

There is an online resource at http://perl6.org/compilers/features
that lists the known implemented and missing features of Rakudo and
other Perl 6 implementations.

In many places we've tried to make Rakudo smart enough to inform the
programmer that a given feature isn't implemented, but there are many
that we've missed. Bug reports about missing and broken features are
welcomed at rakudo...@perl.org.

See http://perl6.org/ for links to much more information about
Perl 6, including documentation, example code, tutorials, reference
materials, specification documents, and other supporting resources. A
draft of a Perl 6 book is available as docs/UsingPerl6-draft.pdf in
the release tarball.

The development team thanks all of the contributors and sponsors for
making Rakudo Star possible. If you would like to contribute, see
http://rakudo.org/how-to-help, ask on the perl6-compi...@perl.org
mailing list, or join us on IRC \#perl6 on freenode.


Announce: Rakudo Star Release 2013.09

2013-09-26 Thread Moritz Lenz

## A useful, usable, early adopter distribution of Perl 6

On behalf of the Rakudo and Perl 6 development teams, I'm happy to
announce the September 2013 release of Rakudo Star, a useful and usable
distribution of Perl 6. The tarball for the September 2013 release is
available from http://rakudo.org/downloads/star/. A Windows .MSI
version of Rakudo star will usually appear in the downloads area
shortly after the tarball release.

In the Perl 6 world, we make a distinction between the language
(Perl 6) and specific implementations of the language such as
Rakudo Perl.  This Star release includes [release 2013.09] of the
[Rakudo Perl 6 compiler], version 5.5.0 of the [Parrot Virtual
Machine], plus various modules, documentation, and other resources
collected from the Perl 6 community.

[release 2013.09]:
https://github.com/rakudo/rakudo/blob/nom/docs/announce/2013.09.md
[Rakudo Perl 6 compiler]: http://github.com/rakudo/rakudo
[Parrot Virtual Machine]: http://parrot.org

Some of the new features added to this release include:

+ candidate argument to bless removed (per spec change)
+ @a.VAR.name and %h.VAR.name implemented
+ The $var.++ and $var.() syntaxes work
+ basics of tr/// implemented
+ Sets/Bags/KeySet/KeyBag now up to spec, except for the empty set 
symbol '∅'


This release also contains a range of bug fixes, improvements to error
reporting and better failure modes.

Please note that this release of Rakudo Star does not support the JVM
backend from the Rakudo compiler. While the JVM backend mostly implements
the same features as the Parrot backend, many bits are still missing,
most prominently the native call interface.
We hope to provide a JVM-based Rakudo Star release soon.

The following features have been deprecated or modified from previous
releases due to changes in the Perl 6 specification, and are planned
to be removed or changed as follows:

  * `postcircumfix:[ ]` and `postcircumfix:{ }` will become
multi-subs rather than multi-methods *IN THE NEXT RELEASE* of Rakudo
Star. Both at_pos and at_key will remain methods.

  * All unary hyper ops currently descend into nested arrays and
hashes. In the future, those operators and methods that are
defined nodal will behave like a one-level map.

  * The Str.ucfirst builtin is deprecated; it will be replaced by
Str.tc.  In the next Rakudo Star release, use of Str.ucfirst will 
actually

generate a warning upon first usage.

  * Leading whitespace in rules and under :sigspace will no longer be
converted to `.ws`.  For existing regexes that expect this
conversion, add a `?` in front of leading whitespace to make it
meta again.

There are some key features of Perl 6 that Rakudo Star does not yet
handle appropriately, although they will appear in upcoming releases.
Some of the not-quite-there features include:

  * advanced macros
  * threads and concurrency
  * Unicode strings at levels other than codepoints
  * interactive readline that understands Unicode
  * non-blocking I/O
  * much of Synopsis 9 and 11

There is an online resource at http://perl6.org/compilers/features
that lists the known implemented and missing features of Rakudo and
other Perl 6 implementations.

In many places we've tried to make Rakudo smart enough to inform the
programmer that a given feature isn't implemented, but there are many
that we've missed.  Bug reports about missing and broken features are
welcomed at rakudo...@perl.org.

See http://perl6.org/ for links to much more information about
Perl 6, including documentation, example code, tutorials, reference
materials, specification documents, and other supporting resources.  A
draft of a Perl 6 book is available as docs/UsingPerl6-draft.pdf in
the release tarball.

The development team thanks all of the contributors and sponsors for
making Rakudo Star possible.  If you would like to contribute, see
http://rakudo.org/how-to-help, ask on the perl6-compi...@perl.org
mailing list, or join us on IRC \#perl6 on freenode.


Rakudo Star 2013.08 released

2013-08-24 Thread Moritz Lenz
On behalf of the Rakudo and Perl 6 development teams, I'm happy to
announce the August 2013 release of Rakudo Star, a useful and usable
distribution of Perl 6. The tarball for the August 2013 release is
available from http://rakudo.org/downloads/star/. A Windows .MSI
version of Rakudo star will usually appear in the downloads area
shortly after the tarball release.

In the Perl 6 world, we make a distinction between the language
(Perl 6) and specific implementations of the language such as
Rakudo Perl.  This Star release includes [release 2013.08] of the
[Rakudo Perl 6 compiler], version 5.5.0 of the [Parrot Virtual
Machine], plus various modules, documentation, and other resources
collected from the Perl 6 community.

[release 2013.08]:
https://github.com/rakudo/rakudo/blob/nom/docs/announce/2013.08.md
[Rakudo Perl 6 compiler]: http://github.com/rakudo/rakudo
[Parrot Virtual Machine]: http://parrot.org

Some of the new features added to this release include:

* `is default` traits on variables are now implemented
* assigning Nil restores the default value
* `Buf` is now a role, and Buf objects are immutable.
* `printf` now correctly handles big integers
* fixed handling of indented heredocs
* `dir()` is now lazy

This release also contains a range of bug fixes, improvements to error
reporting and better failure modes.

Please note that this release of Rakudo Star does not support the JVM
backend from the Rakudo compiler. While the JVM backend mostly implements
the same features as the Parrot backend, many small IO bits are still
missing, rendering some crucial parts like the module installer unsable.
We hope to provide a JVM-based Rakudo Star release soon.

The following features have been deprecated or modified from previous
releases due to changes in the Perl 6 specification, and are planned
to be removed or changed as follows:

  * `postcircumfix:[ ]` and `postcircumfix:{ }` will become
multi-subs rather than multi-methods. Both at_pos and at_key will
remain methods.

  * All unary hyper ops currently descend into nested arrays and
hashes. In the future, those operators and methods that are
defined nodal will behave like a one-level map.

  * The Str.ucfirst builtin is deprecated; it will be replaced by
Str.tc.

  * Leading whitespace in rules and under :sigspace will no longer be
converted to `.ws`.  For existing regexes that expect this
conversion, add a `?` in front of leading whitespace to make it
meta again.

There are some key features of Perl 6 that Rakudo Star does not yet
handle appropriately, although they will appear in upcoming releases.
Some of the not-quite-there features include:

  * advanced macros
  * threads and concurrency
  * Unicode strings at levels other than codepoints
  * interactive readline that understands Unicode
  * non-blocking I/O
  * much of Synopsis 9

There is an online resource at http://perl6.org/compilers/features
that lists the known implemented and missing features of Rakudo and
other Perl 6 implementations.

In many places we've tried to make Rakudo smart enough to inform the
programmer that a given feature isn't implemented, but there are many
that we've missed.  Bug reports about missing and broken features are
welcomed at rakudo...@perl.org.

See http://perl6.org/ for links to much more information about
Perl 6, including documentation, example code, tutorials, reference
materials, specification documents, and other supporting resources.  A
draft of a Perl 6 book is available as docs/UsingPerl6-draft.pdf in
the release tarball.

The development team thanks all of the contributors and sponsors for
making Rakudo Star possible.  If you would like to contribute, see
http://rakudo.org/how-to-help, ask on the perl6-compi...@perl.org
mailing list, or join us on IRC \#perl6 on freenode.


Re: prove that the meaning of live is math

2013-05-26 Thread Moritz Lenz
Hi Marc,

On 05/26/2013 12:49 PM, Marc Chantreux wrote:
 say [+]
 ('a'..'z')\
 .pairs\
 .map: { 1 + .key if .value ~~ any  m a t h  }  
 
 i already know i have to get used to the anoying \ at the end of the
 lines but i'm pretty sure there are plenty ways to make this expression
 shorter. 

masak took this to #perl6:
http://irclog.perlgeek.de/perl6/2013-05-26#i_7117450

My solution, with a bit of help from masak:

say [+] m a t h».ord X- ('a'.ord - 1)

Other approaches have been developed too, it's worth reading the logs :-)

If anybody has a good idea for removing that - 1, please tell me. (Using
'`'.ord instead of 'a'.ord - 1 seems too obscure for my taste).

Cheers,
Moritz


Re: Packaging Perl 6 (or rather, Rakudo Star)

2013-03-05 Thread Moritz Lenz

On 03/05/2013 12:02 PM, Rob Hoelz wrote:

On 3/5/13 11:44 AM, Patrick R. Michaud wrote:

On Tue, Mar 05, 2013 at 11:13:51AM +0100, Rob Hoelz wrote:

I already have my own package for Arch Linux for Rakudo Star, and I keep
the OS X homebrew package up-to-date as well.  I'd like to create an RPM
spec file and a DEB spec file as well.  I have two questions:

1) Do these spec files belong in the Rakudo Star repository?

I have no problem with maintaining spec files in any of the
Rakudo-related repos (NQP, Rakudo, Star).


2) Which makes more sense: having a Rakudo Star package that depends on
a separate Rakudo package (so Rakudo Star would only consist of modules
and applications), or having a Rakudo Star package that conflicts with a
separate Rakudo package (so users may install one or the other)?  [...]

I suspect to ever be considered for official inclusion in Debian/Ubuntu
distros, you'd have to have the first option (separate compiler and
module packages).  And moreso:  they likely prefer to see each module
as its own package, rather than a single package containing a complete
collection of modules.  (I think module collections in the .deb world
tend to be managed as packages with dependencies, as opposed to
all-in-one packages.)


That's a good point; that's probably the proper way to do things.  Now
to make that happen...


It may also be worth noting/reminding that Rakudo Star has never been
intended to be the only or even primary module collection, it's just
one of the first.  It could make good sense to come up with a new
P6 distribution that is better tailored to the needs of OS distros.


Another good point; should we hold off on making packages for Rakudo
Star until something more appropriate comes along, or should we go
ahead and make some packages?  I would favor the latter, myself.


I think a good idea is to start packaging Rakudo, panda, perl6-debug and 
the various modules. And if/when all of the modules in Star are 
packaged, you can make a sort of meta package that depends on them all, 
and call it 'rakudo-star'.


That's a bit of a bottom-up approach, which worked well in other areas 
of Perl 6 development.


Cheers,
Moritz


Announce: Rakudo Star 2013.02 released

2013-02-24 Thread Moritz Lenz

On behalf of the Rakudo and Perl 6 development teams, I'm happy to
announce the February 2013 release of Rakudo Star, a useful and
usable distribution of Perl 6.  The tarball for the  February 2013
release is available from http://rakudo.org/downloads/star/.
A Windows .MSI version of Rakudo star will usually appear in
the downloads area shortly after the tarball release.

In the Perl 6 world, we make a distinction between the language
(Perl 6) and specific implementations of the language such as
Rakudo Perl.  This Star release includes release 2013.02.1 [0] of the
Rakudo Perl 6 compiler [1], version 4.10.0 of the Parrot Virtual
Machine [2], and various modules, documentation, and other
resources collected from the Perl 6 community.

Some of the new features added to this release include:

* Did you mean ... suggestions for symbol-not-found errors

* Compile-time optimization of some cases of junctions in boolean context

* IO::Socket.get now works again with non-ASCII characters

* constant folding for routines marked as 'is pure'

* natively typed variables and better error reporting in the REPL

* speed up eqv-comparison of Bufs

* warnings for useless use of (some) literals, variables and constant
  expressions in sink context


This release also contains a range of bug fixes, improvements to error 
reporting

and better failure modes.

The following features have been deprecated or modified from previous
releases due to changes in the Perl 6 specification, and are being removed
or changed as follows:

* .gist on a type object will return '(Typename)' instead of 'Typename()'.
  If you want to get the class name alone, continue to use $obj.^name

* postcircumfix:[ ] and postcircumfix:{ } will become multi-subs rather
  than multi-methods. Both at_pos and at_key will remain methods.

* Unary hyper ops currently descend into nested arrays and hashes.
  This will change to make them equivalent to a one-level map.

* The Str.ucfirst builtin is deprecated; it will be replaced by Str.tc.

* Leading whitespace in rules and under :sigspace will no longer be
  converted to .ws .  For existing regexes that expect this conversion,
  add a ? in front of leading whitespace to make it meta again.

* The ?-quantifier on captures in regexes currently binds the capture
  slot to a List containing either zero or one Match objects; i.e., it
  is equivalent to ** 0..1.  In the future, the ?-quantifier will
  bind the slot directly to a captured Match or to Nil.  Existing code
  can manage the transition by changing existing ?-quantifiers to
  use ** 0..1, which will continue to return a List of matches.

There are some key features of Perl 6 that Rakudo Star does not
yet handle appropriately, although they will appear in upcoming
releases.  Some of the not-quite-there features include:

  * advanced macros
  * threads and concurrency
  * Unicode strings at levels other than codepoints
  * interactive readline that understands Unicode
  * non-blocking I/O
  * much of Synopsis 9

There is an online resource at http://perl6.org/compilers/features
that lists the known implemented and missing features of Rakudo
and other Perl 6 implementations.

In many places we've tried to make Rakudo smart enough to inform the
programmer that a given feature isn't implemented, but there are
many that we've missed.  Bug reports about missing and broken
features are welcomed at rakudo...@perl.org.

See http://perl6.org/ for links to much more information about
Perl 6, including documentation, example code, tutorials, reference
materials, specification documents, and other supporting resources.
A draft of a Perl 6 book is available as docs/UsingPerl6-draft.pdf
in the release tarball.

The development team thanks all of the contributors and sponsors
for making Rakudo Star possible.  If you would like to contribute,
see http://rakudo.org/how-to-help, ask on the perl6-compi...@perl.org
mailing list, or join us on IRC #perl6 on freenode.

[0] https://github.com/rakudo/rakudo/blob/nom/docs/announce/2013.01
[1] http://github.com/rakudo/rakudo
[2] http://parrot.org/


Re: Per-Object Roles..

2013-02-23 Thread Moritz Lenz
Hi Frank,

On 02/24/2013 07:27 AM, Frank White wrote:
 Hi, I am new to Perl6 and I'm interested in the feature that allows you to
 add roles to classes.  From what I understand you can add a role to an
 object using the does keyword.  Is there any way you can remove a role or

No, you cannot remove roles.

 check to see if a role is attached to an object? 

With normal type checking:

if $obj ~~ YourRole {
...
}

Cheers,
Moritz


Announce: Rakudo Star 2012.12 release

2012-12-27 Thread Moritz Lenz
Announce: Rakudo Star - a useful, usable, early adopter distribution
of Perl 6

On behalf of the Rakudo and Perl 6 development teams, I'm happy to
announce the December 2012 release of Rakudo Star, a useful and
usable distribution of Perl 6.  The tarball for the  December 2012
release is available from http://rakudo.org/downloads/star/.
A Windows .MSI version of Rakudo star will usually appear in
the downloads area shortly after the tarball release.

In the Perl 6 world, we make a distinction between the language
(Perl 6) and specific implementations of the language such as
Rakudo Perl.  This Star release includes release 2012.11 [0] of the
Rakudo Perl 6 compiler [1], version 4.10.0 of the Parrot Virtual
Machine [2], and various modules, documentation, and other
resources collected from the Perl 6 community.

Some of the new features added to this release include:

* Parse errors are much improved, and follow STD, the standard parser,
  much more closely; they are more accurate and more information is given

* Rakudo now keeps parsing after some less serious errors

* Better errors for various parse failures

* The junction autothreader is now an order of magnitude faster

* Texas (ASCII) versions of the Set and Bag operators implemented

* Nested Pairs now give correct .perl output

* { a = $_ } now correctly considered a block, not a hash as before

This release also contains a range of performance improvements, bug fixes,
improvements to error reporting and better failure modes.

The following features have been deprecated or modified from previous
releases due to changes in the Perl 6 specification, and are being removed
or changed as follows:

* 'for'-loops will become lazy, and are only evaluated eagerly in
  eager or sink (void) context. This means that if a for-loop is
  the last statement in a routine, it will usually run after the
  routine has returned, so it cannot call return() anymore.

* Unary hyper ops currently descend into nested arrays and hashes.
  This will change to make them equivalent to a one-level map.

* The Str.ucfirst builtin is deprecated; it will be replaced by Str.tc.

* Leading whitespace in rules and under :sigspace will no longer be
  converted to .ws .  For existing regexes that expect this conversion,
  add a ? in front of leading whitespace to make it meta again.

* The ?-quantifier on captures in regexes currently binds the capture
  slot to a List containing either zero or one Match objects; i.e., it
  is equivalent to ** 0..1.  In the future, the ?-quantifier will
  bind the slot directly to a captured Match or to Nil.  Existing code
  can manage the transition by changing existing ?-quantifiers to
  use ** 0..1, which will continue to return a List of matches.

There are some key features of Perl 6 that Rakudo Star does not
yet handle appropriately, although they will appear in upcoming
releases.  Some of the not-quite-there features include:

  * advanced macros
  * threads and concurrency
  * Unicode strings at levels other than codepoints
  * interactive readline that understands Unicode
  * non-blocking I/O
  * much of Synopsis 9

There is an online resource at http://perl6.org/compilers/features
that lists the known implemented and missing features of Rakudo
and other Perl 6 implementations.

In many places we've tried to make Rakudo smart enough to inform the
programmer that a given feature isn't implemented, but there are
many that we've missed.  Bug reports about missing and broken
features are welcomed at rakudo...@perl.org.

See http://perl6.org/ for links to much more information about
Perl 6, including documentation, example code, tutorials, reference
materials, specification documents, and other supporting resources.
A draft of a Perl 6 book is available as docs/UsingPerl6-draft.pdf
in the release tarball.

The development team thanks all of the contributors and sponsors
for making Rakudo Star possible.  If you would like to contribute,
see http://rakudo.org/how-to-help, ask on the perl6-compi...@perl.org
mailing list, or join us on IRC #perl6 on freenode.

[0] https://github.com/rakudo/rakudo/blob/nom/docs/announce/2012.12
[1] http://github.com/rakudo/rakudo
[2] http://parrot.org/


Rakudo Star 2012.11 released

2012-11-28 Thread Moritz Lenz
On behalf of the Rakudo and Perl 6 development teams, I'm happy to
announce the November 2012 release of Rakudo Star, a useful and
usable distribution of Perl 6.  The tarball for the November 2012
release is available from http://github.com/rakudo/star/downloads.
A Windows .MSI version of Rakudo star will usually appear in
the downloads area shortly after the tarball release.

In the Perl 6 world, we make a distinction between the language
(Perl 6) and specific implementations of the language such as
Rakudo Perl.  This Star release includes release 2012.11 [0] of the
Rakudo Perl 6 compiler [1], version 4.6.0 of the Parrot Virtual
Machine [2], and various modules, documentation, and other
resources collected from the Perl 6 community.

Some of the new features added to this release include:

* heredocs

* quote adverbs (like q:w//)

* implemented precedence related traits (equiv, looser, tighter, assoc)

* Perl 6 grammar NFAs are pre-computed, saving some work on each
  invocation; this shaved around 10% off the time needed to run the
spectests

* regexes and quotes have better support for user-selected delimiters

* FIRST/NEXT/LAST can now be used in all types of loop (previously
  limited to for)

* several fixes related to module precompilation. This should make working
  with larger code bases much less painful.

This release also contains a range of performance improvements, bug fixes,
improvements to error reporting and better failure modes.

The following features have been deprecated or modified from previous
releases due to changes in the Perl 6 specification, and are being removed
or changed as follows:

* at present, a reference to an foo that does not exist evalutes to Nil.
  This will become a CHECK-time failure, in line with STD.

* Unary hyper ops currently descend into nested arrays and hashes.
  This will change to make them equivalent to a one-level map.

* ~/.perl6/lib will go away from the default include path (@*INC).
  Instead %*CUSTOM_LIB now holds paths to four library locations:
  perlRakudo installs its core modules here
  vendor  OS-level package managers should install their modules here
  sitefor local module installations (e.g. with panda or ufo)
  homelike site, but always under the user's home directory.
  fallback if site isn't writable.

* The Str.ucfirst builtin is deprecated; it will be replaced by Str.tc.

* Leading whitespace in rules and under :sigspace will no longer be
  converted to .ws .  For existing regexes that expect this conversion,
  add a ? in front of leading whitespace to make it meta again.

* The ?-quantifier on captures in regexes currently binds the capture
  slot to a List containing either zero or one Match objects; i.e., it
  is equivalent to ** 0..1.  In the future, the ?-quantifier will
  bind the slot directly to a captured Match or to Nil.  Existing code
  can manage the transition by changing existing ?-quantifiers to
  use ** 0..1, which will continue to return a List of matches.

There are some key features of Perl 6 that Rakudo Star does not
yet handle appropriately, although they will appear in upcoming
releases.  Some of the not-quite-there features include:

  * advanced macros
  * threads and concurrency
  * Unicode strings at levels other than codepoints
  * interactive readline that understands Unicode
  * non-blocking I/O
  * much of Synopsis 9

There is an online resource at http://perl6.org/compilers/features
that lists the known implemented and missing features of Rakudo
and other Perl 6 implementations.

In many places we've tried to make Rakudo smart enough to inform the
programmer that a given feature isn't implemented, but there are
many that we've missed.  Bug reports about missing and broken
features are welcomed at rakudo...@perl.org.

See http://perl6.org/ for links to much more information about
Perl 6, including documentation, example code, tutorials, reference
materials, specification documents, and other supporting resources.
A draft of a Perl 6 book is available as docs/UsingPerl6-draft.pdf
in the release tarball.

The development team thanks all of the contributors and sponsors
for making Rakudo Star possible.  If you would like to contribute,
see http://rakudo.org/how-to-help, ask on the perl6-compi...@perl.org
mailing list, or join us on IRC #perl6 on freenode.

[0] https://github.com/rakudo/rakudo/blob/nom/docs/announce/2012.11
[1] http://github.com/rakudo/rakudo
[2] http://parrot.org/


Re: the nature of a scalar?

2012-10-24 Thread Moritz Lenz



On 10/24/2012 02:46 PM, Marc Chantreux wrote:


use v6;
use lib 'lib';
use Bailador;

get / (.*) '/' / = sub ($path) {
 $path||=foo;


$path is a subroutine parameter, and thus read-only by default.
If you want to modify $path locally, write

sub ($path is copy) { ... }

Also if Bailador passes Match objects instead of strings into the 
function, $path evaluates to True in boolean context even if it matched 
the empty string.


Cheers,
Moritz


Re: perl6 spec tests results ?

2012-08-28 Thread Moritz Lenz
Hi,

On 08/28/2012 10:09 PM, Marc Chantreux wrote:
 i'm writing an article on Perl6 and i would like some facts to reassure
 early adopters. according to the test suite and the will of Perl6
 implentors, what proportion (in %) of Perl6 can be concidered as stable?

That's a hard question to answer, because I don't know how to quantify
language features. Counting them is very difficult, because there are
small and large features, and which feature is what really depends
on your point of view.

 what are the parts that are not ? any link ?

I've tried to come up with some sort of stability rating for the specs,
and this is as far as I got: https://gist.github.com/2346494

It's easy to identify some subsytems that are definitively not stable:
IO, concurrency, Unicode support, object pipes.

There are areas that are pretty stable (control flow, basic OO,
variables, scoping).

Then there are areas that don't seem to have moved a lot recently, but
that have unresolved issues smoldering under the surface, and it's
unclear how large the waves will be when those issues are resolved.

Cheers,
Moritz

.oO( Never ask a 6er for completion estimates, for he will say both Yay
and Nay )


Re: Capturing warning

2012-07-12 Thread Moritz Lenz



Am 12.07.2012 13:50, schrieb Gabor Szabo:

On Thu, Jul 12, 2012 at 2:31 PM, Tadeusz Sośnierz tadzi...@gmail.com wrote:

On Thu, 12 Jul 2012 13:27:26 +0200, Gabor Szabo ga...@szabgab.com wrote:


Hi,

is there a way to capture warnings in Perl 6 - similar to
$SIG{__WARN__} in Perl 5 ?

Gabor



CONTROL block seems to be the solution.

$ perl6 -e 'warn oh noes; CONTROL { default { say caught: $_ } }'
caught: oh noes


Thanks, but:

use v6;

say 'before';
warn oh noes;
say 'between';
CONTROL {
default {
say caught: $_;
}
}
say 'after';

prints:

before
caught: oh noes


Where is 'between' and 'after' ?


I've just added a .resume method to class Exception in Rakudo, along 
with a method .resumable, which checks if .resume may be called.


Cheers,
Moritz


Re: say vs print for .WHAT

2012-06-29 Thread Moritz Lenz

Am 28.06.2012 23:43, schrieb Smylers:

Patrick R. Michaud writes:


print will stringify its arguments and write them to $*OUT.

say will invoke .gist on its arguments and write them (along with a
final newline) to $*OUT.


Hi there. What's the rationale for the difference there?

Under what circumstances are each likely to be useful?



I've tried to answer that here: http://faq.perl6.org/#say

Cheers,
Moritz


Re: Panda with git:// or https:// ?

2012-06-28 Thread Moritz Lenz
FWIW the reason I always use git:// over https:// is that at some point 
cloning from github via https:// would result in strange errors on the 
client side (iirc something about missing objects).


I have no idea if that's fixed, but I haven't seen a reason to change 
back to https either.


Am 28.06.2012 16:48, schrieb Gabor Szabo:

On Thu, Jun 28, 2012 at 5:15 PM, Tadeusz Sośnierz
tadeusz.sosni...@onet.pl wrote:

On Thursday, June 28, 2012 14:32:58 Gabor Szabo wrote:

In panda all the projects, where there is a source URL, are listed with
their git:// url except of https://github.com/perlpilot/p6-File-Temp.git

Where is that?


in projects.json




I am just wondering why, and if it would not be better if that was
also using git://

That's because it was added to the ecosystem with https:// rather than git://.
Panda doesn't care, for it just uses the url to tell `git clone` where to get
the source from.


Some project have no source URL:
- Druid
- GGE
- HTML::Template
- Lingua::EN::Numbers::Ordinal
- Perl6::Literate
- Tardis
- Test::Mock
- Text::CSV
- Yarn

Those are using the old META.info format, which wanted repo-type and repo-url
rather than source-url.


Should the URLs be added? Where?

Should be, aye, in the modules' META.info files. See
https://github.com/masak/druid/blob/master/META.info for example.


Is there an explanation or documentation somewhere how those files
should look like
or do people just imitate working packages?


http://wiki.perl6.org/Create%20and%20Distribute%20Modules

I kinda remember that we had more detailed specs somewhere, but 
currently I can't seem to remember where.



Is there a documentation on how to add a new package to panda?
(where to update projects.json and who could should do that?)


Currently the process is just Add the META.info URL to 
https://github.com/perl6/ecosystem/blob/master/META.list, and if you 
don't have access, ask for it (here or on #perl6). Or make a pull request


Cheers,
Moritz


Re: Perl6 grammars -- Parsing english

2012-06-26 Thread Moritz Lenz


On 06/26/2012 02:04 PM, Lard Farnwell wrote:
 Hi guys,
 
 To understand and play around with perl6 grammars I was trying to do a simple 
 NLP parts of speech parser in perl6 grammars. This is sort of what I did: 
 
 ---
 grammar Sentence{
 proto rule VP {*}
 proto rule NP {*}
   
   rule sentence {
   imperative|statement
   }
rule imperative {VP}
rule statement {NP VP}
 }
 
 grammar VerbPhrase is Sentence{
   rule VP:symhit  {sym  NP}
   rule VP:symkill {sym  NP}
 }
 
 grammar NounPhrase is Sentence{
   #define NP:sym etc
 }
 
 
 grammar English is NounPhrase is VerbPhrase {
   rule TOP {
   Sentence[\. Sentence]*
 }
 }
 
 
 So in case you don't get it, A sentence is made up of phrases which in turn 
 can be made up on other phrases. And English is made up of Sentences.
 This sort of thing works but doesn't make much sense.
 
 The obvious problem is that to get the correct definitions of the proto rules 
 in Sentence I have to say verbPhrase is Sentence and then English is 
 NounPhrase is VerbPhrase etc .  This makes me feel like I'm doing it wrong.

Indeed. The intended mechanism for code reuse in object oriented Perl 6
code is role composition.

Grammar rules and regexes are just methods, so defining them in a role
and applying it to a class sounds like a good idea to me.

role VerbPhrase {
rule VP { verb NP }
proto token verb  {*}
token verb:symhit  { sym }
token verb:symkill { sym }
}

Define NounPhrase in a similar way, leave out the definition of NP and
VP from Sentence, and then write

grammar English does NounPhrase does VerbPhrase is Sentence {
token TOP { ... }
}

Role composition has much more transparent error modes than inheritance,
and probably works better for you.


 How do I build a flexible dynamic grammar in a OO sort of way. For example 
 how could I do this so:
 
 1) I define all my phrase structures (NP,VP,PP etc) in their own file while 
 still being able to use each other. There are VPs can be made of NPs and NPs 
 can be made up of VPs. 

See above

 2) Add to these definitions dynamically. For example, here I have defined 
 hit and kill VPs. What if I wanted to add dance VP definition at run time?

In theory you can write

role VerbPhrases[@verbs] {
 token verb:symdynamic { @verbs }
 # note that 'dynamic' has no special meaning here, but since
 # we don't use sym in the regex body, it doesn't matter what
 # we write
}

And then instantiate your grammar as

my $g = English.new does VerbPhrases[dance listen juggle ...];
my $match = $g.parse($yourstring);

But Rakudo doesn't yet properly handle array variables in regexes, so
you have to write something like

role AdditionalVerbPhrase[$verb] {
token verb:symdynamic { $verb };
}

my $g = English.new;
$g does AddtionalVerbPhrase[$_] for dance listen juggle ...;
my $match = $g.parse(...);

I haven't tested it though.
If you experiment with it, please report your findings here, I'm curious
about what works right now. If it doesn't work, we can surely find some
way to make it work by going through the meta object to add methods to
the grammar.

Cheers,
Moritz


Re: Is rindex broken or does my brain need a reboot?

2012-05-10 Thread Moritz Lenz
Now fixed in 2012.04.1-93-g128e996:

$ ./perl6 -e 'say @*ARGS[0].rindex(e)' perl
1


Re: use v6

2012-01-18 Thread Moritz Lenz

Am 18.01.2012 11:53, schrieb David Arroyo:

use v6;

This is obligatory in perl 6? What does the module do?


'use v6;' is the declaration that the following program is written in 
Perl 6. It has the advantage that if you accidentally run the file with 
a perl 5 compiler, it will give you a much better error message.


Once Perl 6 has been released in several version, you'll be able to tell 
exactly which Perl 6 version you want to use.


S01 also says that if if a compiler understands both Perl 5 and Perl 6, 
the default mode is v5, so you'll need to explicitly write 'use v6;' to 
enable Perl 6 semantics.


So in most cases today it's not strictly necessary to write 'use v6;', 
but it's usually a good idea to write it nonetheless.


Cheers,
Moritz


Announcing the Perl 6 Coding Contest 2011

2011-12-25 Thread Moritz Lenz
Dear all,

you can have fun using Perl 6 and win 100€ worth of books -- just join
the Perl 6 Coding Contest:
http://strangelyconsistent.org/blog/the-2011-perl-6-coding-contest

Merry Christmas,
Moritz


Re: Handling binary files

2011-10-02 Thread Moritz Lenz
Hi,

On 10/01/2011 03:39 PM, Klāvs Priedītis wrote:
 I have a question about binary files. How can I read binary files? I need to
 do folowing things: read numbers of different widths, strings.

The read() method in IO allows you to read binary data. The result is a
Buf object.

Example:

my $file = open('MyFile');

# read 10 bytes:
my $buf = $file.read(10);

$file.close;

You can write a buffer to another file handle with $fh.write($buf), and
decode them to a string via the $buf.decode($encoding) method.

Hope that helped,
Moritz


Re: Form of I/O statements

2011-07-12 Thread Moritz Lenz

Am 11.07.2011 23:27, schrieb Parrot Raiser:

Printing to STDOUT (by default) works; every attempt to write to a
named file has failed. Is this another Not Yet Implemented?


No, you just didn't get the syntax right :-)


Executing this code:

my $skeleton = bones\n;
my $new_file = x_file;
my $handle   = open($new_file, :w);
$handle.print $skeleton;


'print' is just a method on $handle, and method call with arguments must 
be written as either


$handle.print(arguments here)

or

$handle.print: arguments here

(note the colon)

Rakudo's error message isn't very good though, STD gives you this error 
message:


Two terms in a row (method call requires colon or parens to take arguments)

Sorry for the inconvenience.

Cheers,
Moritz


Re: Using precompiled modules, Assembling a project into one single file (pbc)

2011-06-17 Thread Moritz Lenz

Am 17.06.2011 11:40, schrieb Георгий Устинов:

If you compile Hello.pm to Hello.pir and remove Hello.pm,
PIR module does not load. Why?


Because .pm files are the authoritative source of information (for 
example regarding version information, but also regarding actual program 
code), and .pir files are just caches for that.



Also, if you look at the (pir) code for any compiled script,
it becomes clear that it uses some library called perl6_ops.
Does this mean that the file can not be run on a machine
where you have installed parrot but have not installed perl6?


That is correct.
Just consider the case where your program calls the eval() function - it 
needs the full Perl 6 compiler available. So you need rakudo installed 
to run Perl 6 scripts.



Also, I do not understand, is there a way to build a project
from a large number of classes and roles (that placed
in different files and folders) into a single executable
portable pbc-file.


I don't think parrot supports merging of .so and .pbc files, which would 
be required for such a step. Essentially you'd have to create something 
like Par::Packer, which extracts various files from an archive and makes 
that available.



This can be very useful for scripting in desktop applications.
I pinned my hopes on pbc_merge, but it seems compiled
modules do not work together.


It would be useful, but I don't think it is as straight-forward as you 
hoped it would be.


Cheers,
Moritz


Re: Current vs future Perl 6 binary size

2011-04-22 Thread Moritz Lenz
On 04/22/2011 01:33 AM, gvim wrote:
 Do I take it that the Perl 6 binary is, by design, much larger than the 
 current Perl 5.12 (1.6Mb) 

No, we didn't design either the language or the compiler with the goal
of having a large executable.

And I seem to recall we already had a similar discussion on #perl6,
regarding executing speed.

Cheers,
Moritz


Re: Criteria for production-ready?

2011-04-16 Thread Moritz Lenz
On 04/16/2011 05:02 PM, gvim wrote:
 Does there currently exist a set of criteria by which Perl6, or an 
 implementation thereof, can be defined as production-ready?

No. production-ready is just as subjective as good or fast or
mature or beautiful or any other adjective you can think of, because
different production environments have different needs.

Which is why you usually don't gain much by such discussions. Instead we
tend to focus on making the language and the compilers better.

Cheers,
Moritz


Re: Fwd: FOSDEM - perl 6 critic

2011-02-22 Thread Moritz Lenz

Am 22.02.2011 16:57, schrieb Gabor Szabo:

He, as a sysadmin would like to do the small tasks in a relatively
small language. He would like to make sure the modules/applications
he will download and will have to support are in such a relatively small
language.


Whatever Perl 6 will turn out to be, it won't be a small language.
If I have any influence, it will be a language that's pleasant to write 
and to use (and it largely is already), but it's not small. (Neither is 
Perl 5 a small language; Perl 6 is just another step larger).


We can't be everybody's darling, as much as we would love to.

I wouldn't be opposed to stripping down some parts of Perl 6 a bit, and 
make them available by loading (core) modules, but that's not the Perl 6 
we are working on, but rather a different beast.



Arne Wichmann wrote:
 My other gripe is that perl5 nowadays already is too big - it takes
 too much memory and time for small tasks. But that is only secondary.

Here's the waterbed again: if we push it down on the one side and make 
it pleasant to use, other parts (resource usage) go up. That said, early 
Java compilers and VMs also sucked in terms of resource usage. We'll 
just have to see how well Perl 6 can be optimized, and if/when we can 
muster the resources to do it.


Cheers,
Moritz


Re: Fwd: FOSDEM - perl 6 critic

2011-02-22 Thread Moritz Lenz
On 02/23/2011 02:10 AM, Frank S Fejes III wrote:
 On Tue, Feb 22, 2011 at 10:46 AM, Moritz Lenz mor...@faui2k3.org wrote:
 
 We can't be everybody's darling, as much as we would love to.
 
 That's a fair statement, however do consider that perl5 is still a
 darling for many system administrators and command-line warriors who
 have long since left awk and sed far behind and never looked back.  In
 this use case, perl5 still rules, and I would suspect that you
 wouldn't want to simply throw away these users. 

That's correct. But those users chose Perl because they get stuff done
with it, not because it's a small language (and it's not).

 My (admittedly
 limited) experience with rakudo leads me to believe that the one-liner
 or power-tool usage we've come to expect with perl5 may simply not
 exist in perl6.

As Gabor points out, they haven't been implement yet, but they will be.

Cheers,
Moritz


Re: Dynamic method generation?

2011-01-09 Thread Moritz Lenz
On 01/09/2011 02:26 AM, Sean McAfee wrote:
 On Sat, Jan 8, 2011 at 3:50 PM, Moritz Lenz mor...@faui2k3.org wrote:
 
 class MyMatcher {
for FOO BAR BAZ BLETCH QUUX - $field {
MyMatcher.^add_method($field, method() {
 self!matches($field);
}
);
}
 }

 The .^  means a method of the metaclass is called, here add_method

 Maybe you'll find
 http://perlgeek.de/en/article/discovering-meta-object-protocolinteresting.


 I did, but now I'm wondering how one would do this in the case of an
 anonymous class. 

my $class = ClassHOW.new_class(); # just leave out the name here
for @list - $field {
   $class.^add_method();
}


Re: Dynamic method generation?

2011-01-08 Thread Moritz Lenz
On 01/08/2011 09:11 PM, Sean McAfee wrote:
 package MyMatcher;
 
 my @SIMPLE_FIELDS = qw(FOO BAR BAZ BLETCH QUUX ...);
 
 for my $field (@SIMPLE_FIELDS) {
 no strict 'refs';
 *{ is_\L$field } = sub { shift-_matches($field) };
 }
 

class MyMatcher {
for FOO BAR BAZ BLETCH QUUX - $field {
MyMatcher.^add_method($field, method() {
 self!matches($field);
}
);
}
}

The .^  means a method of the metaclass is called, here add_method

Maybe you'll find
http://perlgeek.de/en/article/discovering-meta-object-protocol interesting.

Cheers,
Moritz


Re: Can't download Rakudo Dec 2010 without git

2011-01-03 Thread Moritz Lenz
On 01/04/2011 03:19 AM, gvim wrote:
 Does this mean I have no option but to install git in order to keep my Perl 6 
 up to date?

No. You can download and install a release tarball of parrot, and then
point rakudo's Configure.pl to the installed parrot. Only if you use the
--gen-parrot option, git needs to be available.

Cheers,
Moritz


Re: Questions for Survey about Perl

2011-01-01 Thread Moritz Lenz
On 01/01/2011 10:15 AM, Gabor Szabo wrote:
 It would be nice to figure out what is the percentage of people who
 don't yet look at Perl 6 because there was not official Perl 6.0
 release
 or in more general what are the blocking issues for them.
 I just would like to make sure that by asking the question we don't
 strengthen the belief that there ever will be an official Perl 6.0
 release.
 Of course that might be part of *my* misunderstanding that I think
 there won't be such thing. I don't have trouble if the questions
 and the possible answers already provide some form of education
 pointing people to the possible real answers.
 
 So for example:
 
 I'll start learning Perl 6  (select one or more that fits your opinion)
 *) when Larry Wall declares that Perl 6.0 is ready
 *) after Rakudo 1.0 is released

Given the current version number scheme (year.month), it's highly
unlikely that we'll ever see a Rakudo 1.0.

So I'd change that to after a production release of a Perl 6 compiler

 *) when the default running perl -v in my Linux distribution will say
 it is version 6.0 or later
 *) After the Learning Perl 6th edition will be published
 *) After DBI and DBD::Mysql is ported
 *) never
 *) I have already started to learn
 Other:
 
 
 What do you think?

Maybe add

*) when it's about as fast as perl5

I think it's an interesting question.

Cheers,
Moritz


Re: Announce: Rakudo Star 2010.12 released

2010-12-31 Thread Moritz Lenz
On 12/31/2010 03:31 PM, Daniel Carrera wrote:
 Out of curiosity, is it possible to get Rakukdo to talk to C, C++ or Fortran?

For C, see https://github.com/jnthn/zavolaj
Fortran uses the same calling conventions, albeit with weird name
mangling rules that depend on the compiler. So you can use Zavolaj for
Fortran too, if you're ready to suffer.

Cheers,
Moritz


Re: Questions for Survey about Perl

2010-12-29 Thread Moritz Lenz
Hi,

On 12/29/2010 08:02 AM, Gabor Szabo wrote:
 I'd be happy to get your input on how else would you put this question or
 what possible other answers you would allow.

Here are some very rough ideas:

How much do you know about Perl 6?
 * nothing except the name
 * some design ideas or history
 * enough for very simple programs
 * solid knowledge

How do you keep informed about Perl 6 (multiple answers)?
 * I don't
 * general tech news sites (slashdot, reddit, lwn, ...)
 * mailing lists
 * Perl 6 specific blogs or blog aggregators
 * other (please comment)

What do you think about the relation between 5 and 6
 * I don't
 * Perl 6 hurts Perl 5
 * Perl 5 benefits from Perl 5
 * The two are mostly independent

Cheers,
Moritz


Re: reading binary stream?

2010-12-28 Thread Moritz Lenz
Hi,

On 12/28/2010 03:30 PM, Hiroki Horiuchi wrote:
 How can I fix the problem?

The following works right now in Rakudo, but I don't know if it conforms
to the spec:

my $h = open '/dev/urandom', :bin;
$*OUT.write: $h.read(10)

note that read() returns a Buf, which can be printed out again with write().

Cheers,
Moritz


Re: Q: Code example in Using Perl 6 - methods and spaces.

2010-12-27 Thread Moritz Lenz
On 12/27/2010 09:12 PM, Daniel Carrera wrote:
 Thanks. The blacklash unspace works.
 
 my @sorted = @names.sort({ %sets{$_} })\
.sort({ %matches{$_} })\
.reverse;
 
 Though I'm a bit sad that you need that and you can't just separate methods
 with spaces.

But there's a good reason: .method is a term on its own, and actually
means $_.method. So if you write  @names.foo .bar, that's two terms in a
row.

You could argue that that's always a syntax error, and we could
special-case it after a method, but I think it's a bad idea. Firstly
it's an exception that makes it harder to learn the language, and
secondly disallowing two terms in a row is what enables predictive
parsing, and is very important for getting sensible syntax error messages.

Cheers,
Moritz


Re: New Perl 6 Advent Calendar: call for ideas

2010-11-06 Thread Moritz Lenz
Hi,

On 11/06/2010 01:51 PM, Tadeusz Sośnierz wrote:
 As I accidentally volunteered for managing a list of topics and writers
 for this year's Advent Calendar [1],

Thanks for volunteering!

 I started to collect some ideas of
 things it'd be nice to write about. There's a gist [2] with the list of
 things from the top of my head. If you have any ideas, please post them,
 bonus points if you could write about it.

I'd suggest to use a file in a repo that we can easily edit, like last
year's https://github.com/perl6/mu/tree/master/misc/perl6advent-2009/

Possible topics of interest (two stars mark those topics that I'd write
about myself, though certainly not all of them, and I'm happy to
delegate to others):


** MAIN and USAGE subs
* laziness (+ perhaps list iteration model)
* series operator
* explaining one or more Perl 6 solutions on rosettacode
** lexical subs and importing/exporting
* is everything a reference?
** Z and X meta operators (not covered in
http://perl6advent.wordpress.com/2009/12/05/day-5-metaoperator/ )
** basic parsing: what is a term, what is an operator? why is the
distinction import?
** meta object protocol
* the Perl 6 community
* infrastructure (what editors/IDEs are good for Perl 6 hacking/have
syntax hilighting, tools used for hacking and presentations etc.)

Cheers,
Moritz


Grammars: parse tags of which only some need closing tags

2010-08-28 Thread Moritz Lenz
Hi,

I'm currently in the progress of porting a template system [1] to Perl 6
[2].

It's fun to write the parser as a Perl 6 grammar, but there's one thing
that I don't know how to solve elegantly.

The markup format allows arbitrary text, and optionally some tags
interleaved. Some of them stand on their own, like

[% setvar title Grammars: parse tags of which only some ... %]

And others have opening/closing pairs, and their proper nesting needs to
be enforced, for example

[% ifvar title %]
h1[% readvar title %]
[% endifvar %]

(yes, the syntax is horrible, but when you write that stuff, 90% is
normal text, and only 10% markup or so, so that's OK, more or less).

Additionally, what goes between nested tags depends on the tags, for
example the [% verbatim %] ... [% endverbatim %] tag pair allows
unmatched [% in between (but that's the only case, so I could cheat a
bit if necessary).


I've started to parse the simple tags like this:

our $open  = '[%';
our $close = '%]';

...

token chunk { literal | directive }

token directive {
$open ~ $close
[.ws command .ws ]
}

proto token command { ... }
token command:symcomment { sym  [ !before $close .]* }
token command:syminclude { sym .ws arg }
rule  command:symsetvar  { sym name '='? slurpy_arg }
rule  command:symreadvar { sym name }


which seems to be a fairly idiomatic way, and factors out the matching
of open/closing delimiters. But that way, I don't see how I can properly
check for closing tags that follow some of the opening tags.

I could cheat, and say

rule  command:symifvar   { sym name '%]' chunks* '[%' 'endifvar' }

But that would be, well, cheating (and would probably mess up the
backtracking control).


Another idea is to directive a proto token, and have each branch match
its own '[%'. But that's rather repetitive.

Another idea is to have nested_command and a single_command rules, and
use them as alternations, thus duplicating the matching of the delimiter
only twice. (Upon more reflection, this seems like the best approach so
far).


Can anybody think of a pattern that solves this problem even more
elegantly, hopefully without any repetition?

Cheers,
Moritz

[1] http://perlgeek.de/en/software/mowyw
[2] http://github.com/moritz/6mowyw


Re: implementing every(N)

2010-08-01 Thread Moritz Lenz
Hi,

Ted Zlatanov wrote:
 I have a Perl 5 module called Every which provides, simply,
 
 every(5); # true on invocation 5, 10, etc.
 every(seconds = 5); # true at 5, 10, etc. seconds
 
 It's really nice in endless loops, logging, etc.  I'd like to translate
 it to Perl 6 (using Rakudo specifically).
 
 Its current implementation requires Devel::Opcode because it needs to
 know what location is getting called again and again.
 
 Generally for Perl 6, is there a simple way to make Every obsolete by
 using built-ins? 

State variables will probably make that a lot easier. Something like

(do { state $x; $x++}) %% 5

 I'd love that but haven't seen anything in the
 language that would help.  I want to avoid closures, they are expensive
 (the current implementation uses one hash key per location).  Maybe I
 could use a continuation (I don't know the syntax for that)?
 
 Specifically for Rakudo, if I have to implement it, can I avoid
 Devel::Opcode?  Are continuations expensive?

Currently there is no Devel::Opcode in Rakudo (and I doubt that it will
work when being called through Blizkost), and everything is expensive :/

Once macros and 'state' are implemented, I think it will be easy to turn

every(5)
into
(do { state $x; $x++}) %% 5

Until then the best you can do for now is probably to use
callframe(1).file and .line to fingerprint the source location. You'll
only get line-level resolution, but that should be enough for a start.

Cheers,
Moritz


Re: very basic type checking

2010-06-25 Thread Moritz Lenz

Hi,

Am 23.06.2010 13:59, schrieb Hiroki Horiuchi:

I asked the same question to #perl6.
But now I think it was a wrong place.


no, you had the bad luck of asking at a time when nobody was around.


My question is:
In current Rakudo,
my Int $i = '123';
causes a runtime error, not a compile time error.
How about in future Perl 6?


In general this is a very hard problem. Let me explain why.

Perl 6 is a very extensible language; you can override built-in 
functions, methods and operators, as well as add new multi variants.

So in a seemingly simple case as

my Str $x = 2 + 3

the compiler has to know
1) which infix:= and infix:+ multis are available in the current 
lexical scope
2) if those are pure functions that can be executed at compile time 
without loss of semantics
3) about local grammar modifications that might change the meaning of 
the number literals

4) if there is a local redefiniton of the Str type

Since the + is implemented as a multi sub, it can't just know the return 
type, but it has to execute the 2 + 3 at compile time (constant folding) 
to find the type of the return value.


That is why the specification doesn't mandate a minimum level of type 
inference at compile time.


That said, the consensus seems to be that detecting failures early (ie 
at compile time) is a good thing, as far as it's robust.



Back to the current situation, I don't think we will significant effort 
on constant folding, type checking or other things at compile time prior 
to the Rakudo Star release.


Tyler Curtis is currently working on an optimization framework 
(sponsored by Google as part of the Summer of Code project), which I 
plan to use to play around with compile-time transformations.


But I fear that optimizations are a risky business, considering our 
rather low test coverage (and considering that we don't really know how 
much of our code paths are actually covered by tests).


Cheers,
Moritz


Re: Two questions on Perl 6 functionality

2010-06-21 Thread Moritz Lenz
Hi,

Xi Yang wrote:
 1: Does Perl 6 has method modifiers like those in Moose? 

Perl 6 has traits, so you can write for example

class A {
   method x() is rw { ...}
}

to indicate that it's an lvalue routine (though I don't think it's
implemented in Rakudo yet).

 Where can I get the doc about that? By reading apocalypse?

The Apocalypses are of historical interest only. Please read the
Synopsis instead

http://perlcabal.org/syn/
http://perlcabal.org/syn/S06.html
http://perlcabal.org/syn/S12.html


 2: Does Perl 6 has build-in support for message passing (like those in Glib 
 and Actionscript)?  

I fear I'm not qualified to answer that, and I hope somebody else picks
up the topic.

Cheers,
Moritz


Re: Two questions on Perl 6 functionality

2010-06-21 Thread Moritz Lenz


Xi Yang wrote:
 You might mis-understood method modifiers. I mean:
 before x()
 after x()
 around x()
 

In Perl 6, you do that with wrapping:

http://perlcabal.org/syn/S06.html#Wrapping


Cheers,
Moritz


Rakudo Perl 6 development release #28 (Moscow)

2010-04-22 Thread Moritz Lenz

On behalf of the Rakudo development team, I'm pleased to announce the
March 2010 development release of Rakudo Perl #28 Moscow.
Rakudo is an implementation of Perl 6 on the Parrot Virtual Machine
(see http://www.parrot.org).  The tarball for the April 2010 release
is available from http://github.com/rakudo/rakudo/downloads .

Rakudo Perl follows a monthly release cycle, with each release named
after a Perl Mongers group.  The April 2010 release is code named
Moscow in recognition of Москва.пм and their invitation of Jonathan
Worthington, one of our core develepors, to speak at the Russian Internet
Technologies 2010 [1] conference.

Some of the specific changes and improvements occuring with this
release include:

*  Expressions that begin with a variable and end with a circumfix now 
properly interpolate into double-quoted strings, like @array.sort() or 
%hashkey.


*  Item assignment now has tighter precdence than list assignment, so 
both 'my @a = 1, 2, 3' and '$a = 1, $b = 2' magically work.


*  Most of the DateTime built-in type has been backported from the 
alpha branch, and is now accompanied by a Date type for date-only 
calculations.


*  Many obsolete uses of Perl 5 constructs are now caught and give 
helpful  error messages.


*  As always, many additional small features and bug fixes make working 
with Rakudo more pleasant.


*  Rakudo now passes 30,931 spectests. We estimate that there are about 
39,000 tests in the test suite, so Rakudo passes about 79% of all tests.


For a more detailed list of changes see docs/ChangeLog.

The development team thanks all of our contributors and sponsors for
making Rakudo Perl possible.  If you would like to contribute,
see http://rakudo.org/how-to-help , ask on the perl6-compi...@perl.org
mailing list, or ask on IRC #perl6 on freenode.

The next release of Rakudo (#29) is scheduled for May 20, 2010.
A list of the other planned release dates and code names for 2010 is
available in the docs/release_guide.pod file.  In general, Rakudo
development releases are scheduled to occur two days after each
Parrot monthly release.  Parrot releases the third Tuesday of each month.

Have fun!


Re: ^[[A^[[A

2010-03-10 Thread Moritz Lenz
Hi,

Kiffin Gish wrote:
 How can recall previous commands (history) using ./perl6 without getting
 ^[[A^[[A instead?

You need to have readline development files installed when configuring
and building Rakudo, then it just works[tm].

In the configure steps it should say

auto::readline -  Does your platform support
readline.yes.

Then reconfigure and rebuild rakudo, and you should be happy.
-- 
Moritz Lenz
http://perlgeek.de/ |  http://perl-6.de/ | http://sudokugarden.de/


Re: Compiling Perl6 code to bytecode

2010-01-30 Thread Moritz Lenz
Tadeusz Sośnierz wrote:
 On 29-01-2010 14:46:40, Moritz Lenz wrote:
 Hi,
 Hi, thanks for your response. 
 
 Tadeusz Sośnierz wrote:
  However, compiling the code for later use makes problems:
  
  $ perl6 --target=pir hello.pl  hello.pir
  $ parrot /usr/lib/parrot/2.0.0/languages/perl6/perl6.pbc hello.pir
 
 You should use parrot to turn the .pir file, not the Perl 6 compiler. So try
 
 parrot hello.pir
 
 instead.
 Well, when trying alone 'parrot hello.pir' I get the following:
 
 $ parrot hello.pir 
 load_bytecode couldn't find file 'perl6.pbc'

Did you run 'make install' in Rakudo? If you do, parrot should find
perl6.pbc.

Cheers,
Moritz


Re: Compiling Perl6 code to bytecode

2010-01-29 Thread Moritz Lenz
Hi,

Tadeusz Sośnierz wrote:
 However, compiling the code for later use makes problems:
 
 $ perl6 --target=pir hello.pl  hello.pir
 $ parrot /usr/lib/parrot/2.0.0/languages/perl6/perl6.pbc hello.pir

You should use parrot to turn the .pir file, not the Perl 6 compiler. So try

parrot hello.pir

instead.

However it could be that the .pir is missing some loading directives
(known bug), it might be necessary to add

.loadlib 'perl6_group'
.loadlib 'perl6_ops'

at the beginning of the file (see perl6.pir for how it looks).

The good news is that if you compile a module to PIR, you don't need
such extra work.

 I tried to ask for help on #perl6 on freenode, and the following seems
 to work with rakudo compiled with --gen-parrot. Is this some known case
 of separately used Parrot? Am I doing something wrong?

I don't know of any such relation.

Cheers,
Moritz


Re: Perl 6 IDEs

2009-12-07 Thread Moritz Lenz
Hi,

On Sun, Dec 06, 2009 at 01:47:37PM -0300, Víctor A. Rodríguez (Bit-Man) wrote:
 but it doesn't support Perl 6 (yet). Also tied to install Padre on top
 of Ubuntu but just went to nowhere :-P

I'm sure the Padre developers will appreciate your feedback, and can help you
with the setup.

 Did anyone tried any other Perl 6 aware IDE ??

I'm a vim fanboy, and there's a pretty decent syntax hilighting module for
Perl 6 here:
http://github.com/petdance/vim-perl

Not a full IDE, but enough for me.

Cheers,
Moritz


Re: Iterate X times

2009-09-14 Thread Moritz Lenz
Christian Sturm wrote:
 do you know a short and easy way to iterate a block X times?

Aye ;-)

 I know, one could use while, for, ... but there are some reasons,
 why they don't fit.
 
 All these versions are long. I really like Perl, because you can
 do thing with shorter code. In all these loops you must define a
 variable which gets increased or decreased in each iteration.

No.

for ^5 { say hi }

I don't define any variable to be incremented, and it's not really that
many keystrokes.

 Here is the next problem. To be honest I don't know much about
 how to make a program efficient, but for me it seems to be
 inefficient to have a calculation, a comparison each time and two
 variables (or one variable, which changes every time and a
 constant) only for doing something X times. Especially if I know
 how often I want to run the block before I start it and if I
 don't need to know the value of $_ in
 
 for 1..5 {
   $value = $_;
 }

In a perfect world the optimizer finds out by static analysis that $_ is
not needed in the block, and doesn't generate it. In the real world we
don't have any optimizing Perl 6 compilers yet.

 So where is this needed?
 
 I know Perl isn't the best language when I want to do big
 calculations, but the Lucas?Lehmer primality test[1] would be one
 example.
 
 I'm not sure how this should look like. Ruby allows something
 like this. So maybe one should have look there. Here a few
 suggestions:
 
 
 $X.times {
   $s = $s * $s;
 }

It always felt weird to me to delegate control flow to integers - but
maybe that's just me.

 $X * {
   $s = $s * $s
 }
 
 iterate ( $X )
 {
   $s = $s * $s;
 }
 
 
 I guess something always has to be increased/decreased if it
 comes down to C/Assembly, but even if it doesn't make it faster
 it would make to code smaller and easier to understand.

Would it? given that Perl 6 has at least 4 loop constructs today (for,
while, map, loop), and that * is already taken both as an infix operator
and a term, I'm not sure about that one.

Cheers,
Moritz


[proto] installing a module if PARROT_DIR is a symlink

2009-06-13 Thread Moritz Lenz
Since viklund++ added proto support to JSON yesterday, I wanted to try
it - and I found some problem that I don't know how to fix.

This is how my setup looks:
rakudo (bleed) lives in ~/rakudo/. Parrot lives in ~/rakudo/parrot/,
which is a symlink to ~/tmp/parrot-all/
~/bin/ is in $PATH, and ~/bin/perl6 is a symlink to ~/rakudo/perl6.

Now I cloned JSON, and tried this:

mor...@trudi:~/src/jsonperl6 Configure

Configure.pm is preparing to make your Makefile.

Found a PARROT_DIR to be /home/moritz/tmp/parrot-all
but there is no Rakudo nearby. Please contact the proto people.

Setting PARROT_DIR explicitly to ~/rakudo/parrot leads to exactly the
same message.

So, what should I do?
I don't want proto to manage my rakudo or parrot installation for me,
just the module build.

Cheers,
Moritz


Re: attributes initialisation

2009-05-18 Thread Moritz Lenz
Hi,

Илья wrote:
 Hi,
 no one answered at #perl6, so I sending this question in list:
 
 ihrd: I have question about attr initialization
 ihrd: if I have two attr with same name
 ihrd: like @.args and %.args
 ihrd: and instance object, like .new(args = {foo = 1}), rakudo init both 
 attr
 ihrd: and question is, how this is should work in perl6?

Not at all.

Note that you *could* have private attributes @!args and %!args, but as
soon as you generate a public accessor you get a conflict (because both
just create a nullary method named 'arg', which can never be called
ordinarily, just things like $obj.+arg() would work).

So the answer seems to be don't do that.

Cheers,
Moritz


  1   2   >