Re: '!' versus 'not' in boolean expression

2016-01-25 Thread Carl Mäsak
Tom (>):
> In creating some new Perl 6 programs I've run across several instances
> I'm confused about, to wit:
>
> Example 1
> ---
>
>> my %h; say 'false' if !%h:exists;
> Unexpected named parameter 'exists' passed

I can explain this one. But it's the kind of explanation that makes a
person sadder, not happier.

Adverbs like `:exists` latch onto a preceding operator according to a
rule described below. The operator you want it to latch onto is the
postcircumfix `` indexing of `%h`. The operator it *does* latch on
to is the prefix `!`. That's not what a sane human reader expects, but
that's what happens.

How does it happen? Here's the rule for what an adverb latches onto:
it looks back at the preceding expression, views it as a tree, and
picks the "top" node, that is, whatever operator is holding the rest
of the expression.

Without the `!`, the top node is ``. With the `!`, the top node is `!`.

This is slightly easier to see if we convert the expression the adverb
is considering to Lisp form:

(prefix: (postcircumfix:<< <> >> %h "a"))

The fact that the "prefix:" ends up being first in Lisp form means
that it's the top node in the expression tree.

This also means that one way to make this problem go away is to add
extra parentheses, because that again puts `` at the top by
shutting out `!` from consideration:

$ perl6 -e 'my %h; say "false" if !(%h :exists)'
false

Personally, I find that while the "top node" rule always perfectly
explains the behavior of adverbs in retrospect, it's not a natural
rule to use, and it's downright refactoring-hostile. It sows distrust
in one's ability to just add a `!` somewhere and being able to predict
the result.

I think I would much prefer adverbs to latch onto the textually last
operator. (But in saying this, I realize that I might be unaware of
some terribly important use case for adverbs that this would
preclude.)

Of course, all this is moot if you just take lizmat++'s advice and do
:!exists. :)

// Carl


Re: signatures, multi and named arguments

2015-09-29 Thread Carl Mäsak
 the "signatures, multi and named arguments" email on p6u, is
that a case of the querent forgetting to ! their nameds?
 masak: Sounds like; named args serve as a tie-break but you
actually have to demand them be present in methods for that to help,
given methods accept all named args.
* masak sends that as a reply to p6u

Brief example, which you can probably translate to your BUILD case:

$ perl6 -e 'class C { multi method x(:$foo) { say "foo" }; multi
method x(:$bar) { say "bar" } }; C.new.x(:bar)'
foo

$ perl6 -e 'class C { multi method x(:$foo!) { say "foo" }; multi
method x(:$bar!) { say "bar" } }; C.new.x(:bar)'
bar

For more on this, see
 and
.

// Carl

On Sat, Sep 26, 2015 at 5:13 PM, mt1957  wrote:
> I was wondering if the long name of sub/method/submethod also includes the
> named arguments to differentiate between multi's. I had problems using multi
> on  BUILD submethods which only accept named arguments. The dispather (also
> with other named methods) always takes the first method of the multi's and
> doesn't choose the proper one looking at the named arguments.
>
> Is this behavior correct?
>
> For the moment I can get by using callsame after doing tests on the
> arguments.
>
> perl6 version 2015.09-95-g3970634 built on MoarVM version
> 2015.09-35-gd15a446
>
> Greetings
> Marcel Timmerman
>


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

2015-08-28 Thread Carl Mäsak
Moritz (), Tux ():
 I could continue with other Perl 5 deficiencies (no strict by default,

 Using strict *STILL* is not enabled by default for perl6
 one-liners either:

 $ perl6 -e'my Int $this = 1; $thıs++; say $this;'
 1
 $ perl6 -Mstrict -e'my Int $this = 1; $thıs++; say $this;'
 ===SORRY!=== Error while compiling -e
 Variable '$thıs' is not declared. Did you mean '$this'?
 at -e:1
 -- my Int $this = 1; ⏏$thıs++; say $this;

 That, IMHO, is a huge deficiency!

 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.

Good news! I just pushed a change (with backing from other core
developers) that makes -e strict by default!

commit 5fb81fffa90f90515e663a21987cff484e8260b8
Author: Carl Masak cma...@gmail.com
Date:   Fri Aug 28 17:45:25 2015 +0200

strict is now on by default, even for -e

This should make (most of) p6u happy.

Enjoy! :)

// Carl


Re: Is there an equivalent env var to PERL5LIB for Perl 6 module locations?

2015-03-31 Thread Carl Mäsak
It's worth noting that PERL6LIB is at most a developer convenience,
shouldn't be encouraged or used by module consumers, and will possibly
be deprecated in the future. This is because Perl 6 has a slightly
more ambitious view of module loading which isn't directly compatible
with OS paths.

I use PERL6LIB all the time when I develop, though.

// Carl

On Tue, Mar 31, 2015 at 2:35 AM, Rob Hoelz r...@hoelz.ro wrote:
 Yup, PERL6LIB. =)

 On Mon, 30 Mar 2015 17:03:05 -0500
 Tom Browder tom.brow...@gmail.com wrote:

 I would like an easy way to have a local search path for local Perl 6
 modules (those not installed via Panda).

 I'm used to using the environment variable PERL5LIB for Perl 5
 modules.  Is there currently any equivalent way to do that for Perl 6?

 Thanks.

 -Tom




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

2015-03-27 Thread Carl Mäsak
This feels like the same conversation we had earlier this week about
accessing private methods. :) But maybe there are still a few new
points that can be made.

Tom (), Moritz ():
 I need to test some private routines, so is there a way to do that?

 The easiest way to do that is when the class with the private methods
 trusts the class that calls them. See for example
 http://doc.perl6.org/type/Metamodel::Trusting
 http://design.perl6.org/S12.html#Trusts
 https://github.com/perl6/roast/blob/master/S12-attributes/trusts.t

I would consider all usages of `trusts` a code smell, if nothing else
than for the reason that it links your upstream producer (your class)
to a downstream producer (your tests), and explicitly talking about
something downstream creates an unholy coupling to it, *and* is
difficult because you have to predeclare it in some way.

 But you should ask yourself if you really, really want this.

 And then you can also do something like:

 my $private_method = $obj.^private_method_table{$methodname};
 $obj.$private_metnod(arguments here)

 but it is rather questionable use of the MOP.

I would actually use $obj.^find_private_method, as I showed in that
other thread:

class C { method !foo { say OH HAI } }; my $obj = C.new; my $pm
= C.^find_private_method(foo); $obj.$pm

But I would also amend moritz' rather questionable by saying that if
you do this, even from the comfort of your own tests, you waive
certain advantages of good OOP that you then won't get back.

That little '^' means time to cheat -- if private methods are the
walls of a labyrinth preventing you from going wrong, the '^' just
took you to cheat mode and you can survey the whole labyrinth from
above. In my opinion, tests shouldn't have to resort to that. A very
small list of things require cheat mode. Tests don't.

The reason we deal with all this inside/outside stuff and make some
things private, is so that we can reserve the right to evolve them
without breaking anything on the outside. Like a
https://en.wikipedia.org/wiki/Ball_bearing, the insides are supposed
to be able to move without creating any friction on the outside.

Any kind of coupling with the outside makes that kind of frictionless
evolution harder. Going to the MOP to break the privacy couples the
tests to the implementation.

Beyond that, this simply *shouldn't need to happen* if the tests are
written by the same person as the implementation.

(A) Either you need to test the method, and then it can happily be
made public, or be made an our sub, or a sub outside of the class.
(B) Or you keep the method private, but find some other way to test it
besides calling it directly.

The goal here is to write tests that don't break in the future. In a
way, this is what good OOP leads to. Coupling your tests to private
methods is a mistake, IMHO. Perl 6 makes this difficult because it's
not a good idea.

// Carl


Re: Object Introspection for Existence of Methods: How?

2015-03-23 Thread Carl Mäsak
(resending to p6u)

Tom (), Henk ():
  That doesn't seem to work with private methods.  Any trick to accomplish 
  that?

 What part of 'private' did you mis?

Henk, that's an unnecessarily harsh way to say Private methods are
private and not visible or testable outside of the class.

In my copious spare $dayjob, I teach. Any kind of teaching seems to
involve taking both the teacher's stance (of knowing stuff and being
able to phrase it right) and the learner's stance (trying to remember
what it was like *not* to know something). Pulling that off, and being
able to speedily convey people along all intermediate points from
not-knowing to knowing, is a weirdly satisfying experience.

Questioning the querent's knowledge sends the message (to the querent
and to passive beginner onlookers) that it's somehow a bad idea to ask
direct questions. It's also a non-constructive response, putting the
focus on how much someone knows or doesn't know, rather than the
subject matter. The querent responded very well in this case (I think
I need to learn a lot more about testing in general.), but lesser
provocations than yours have led to flame wars online.

(A) Private methods are private and not visible or testable outside
of the class. is only the most proximal answer to the question.
There's also (B) You can do most things using the MOP, including
finding private methods. (Pointed out by moritz++.)

$ perl6 -e 'class C { method !foo {} }; say C.^find_private_method(foo)'
foo

Or how about (C) The underlying reason we only test on the public
interface is so that the internal bits of an object can change freely
without breaking the test. as a response? Or maybe even (D) There
are ways to test just on the *consequences* of a (public)
message-send, such that you don't even *want* to introspect the
private parts. (Which leads to a more BDD-y style of testing.) Either
of these answers helps convey the querent to a better understanding.

Teaching is about compassion. Literally feeling with the querent. If
you find yourself unable to do that when replying, consider whether
you're simply having a bad day. If the problem persists, ask yourself
whether your reply is representative of the people on p6u who enjoy
helping scurry people forwards along the learning curve.

// Carl


Re: time and now showing different time?

2015-01-12 Thread Carl Mäsak
Yes, this is why phasers are awesome. They allow you to write code in
a natural order, but the phasers will basically time-travel the code
around to where you send it. The two `now` calls execute in two
completely different environments; the first one in the runtime, the
second one during the parsing of the program.

This, incidentally, is the frame of mind one has when writing macros,
too. Most of the action around macros happen at BEGIN time, while the
program is still being processed by the compiler.

/me wanders off towards the horizon, rambling on about macros

// Carl

On Mon, Jan 12, 2015 at 11:33 AM, Gabor Szabo ga...@szabgab.com wrote:


 On Mon, Jan 12, 2015 at 11:48 AM, Tobias Leich em...@froggs.de wrote:


 $ perl6 -e 'sleep 3; say now - BEGIN now;'
 3.0180351



 Oh, so this what they call bending time around space. (Or was that the other
 way around?)
 You call now in the BEGIN block which is the first thing to finish in that
 code, but it is placed
 later in the script so it will appear only after the sleep and the second
 now (written as first now)
 will have been executed.

 It's clear.

 :)

 Gabor



Re: Could method calls warn in void context?

2015-01-11 Thread Carl Mäsak
...It could also be taken as a subtle suggestion to write unit tests,
in which case you would discover such logical bugs within one
red/green/refactor iteration. ;-)

// Carl

On Sat, Jan 10, 2015 at 10:12 PM, Gabor Szabo ga...@szabgab.com wrote:


 On Sat, Jan 10, 2015 at 11:02 PM, Moritz Lenz mor...@faui2k3.org wrote:

 To elaborate a bit on the previous answer:

 On 10.01.2015 17:12, Tobias Leich wrote:

 In case we would know that certain methods had no side effects (and are
 not called because of their side effects), ...

 But at the moment we don't know and therefore we can't warn for every
 method.


 there are two possible choices for warnings: run time and compile time.

 Run-time warnings suffer from run-time overhead, and I think this would be
 unacceptable here.

 Compile-time warnings can't work here, because at compile time we don't
 know what method we'll dispatch to eventually. Note that subroutine calls
 already have such warnings (in some cases):

 $ perl6-m -e 'sqrt(4); say done'
 WARNINGS:
 Useless use of sqrt(4) in expression sqrt(4) in sink context (line 1)
 done


 Oh right. Multiple dispatch. I see.

 anyway, IMHO the run-time overhead would be probably ok if it was optional.
 Like a development mode.
 It would certainly be faster than people, especially beginners like me,
 wasting their time not understanding
 why the method does not have an impact on that object.

 Gabor




Re: non-string keys (in a BagHash, for example)

2014-12-01 Thread Carl Mäsak
Theo van den Heuvel ():
 Perl6 considers all entries as new, and the hash has 3 separate entries. Do
 I actually have to project my objects to strings to accomplish this?

You're putting arrays into a hash. When you put something into a hash,
it matters whether the object in question has *reference nature* or
*value nature*.

* If it has reference nature, the *reference* is used as the hashable thing.
* If it has value nature, the *value* (i.e. contents) is used as the
hashable thing.

It is important for the hash that whatever we use as the hashable
thing won't change over time. (Because if it does, then we won't find
the object again when we look for it later.) The value/contents of an
array can change over time, and therefore it cannot have value nature,
and therefore Perl 6 uses the reference to hash arrays, and therefore
you get three distinct things.

Hope that helps.

// Carl


Re: non-string keys (in a BagHash, for example)

2014-12-01 Thread Carl Mäsak
Yes, the WHICH method controls how the hashing happens.

But the more fundamental principle is that the method always return
the same value for the same objects. This tends to be implemented by
returning either (a representation of) the reference, or the value
itself (which must then not be mutable).

// Carl

On Mon, Dec 1, 2014 at 12:22 PM, Theo van den Heuvel
vdheu...@heuvelhlt.nl wrote:
 Thanks, Carl, that helps. I just need to add a WHICH method. great.

 Theo



Re: how to handle debug code?

2014-01-04 Thread Carl Mäsak
Richard ():
 What am I doing wrong?

Passing constant strings into the macro, instead of code.

masak r: macro m($code) { quasi { {{{$code}}} } }; class A { m(has
$.x is rw) }; say A.new(:x('OH HAI')).x
camelia rakudo-parrot e32249, rakudo-jvm e32249: OUTPUT«OH HAI␤»
* masak replies to the p6u email

So, it works fine, except for the assumption about strings.

// Carl


Re: hyperoperator bug? «~» != ~

2013-03-04 Thread Carl Mäsak
No, both programs are wrong, not correct. The bug is that Rakudo
accepts the first one, not that it rejects the second one. The error
message to the second one looks correct to me. (It tries to hash-index
the list of stuff the .map generated.)

masak r: .say for (1, 2, 3) ~ !; .say for (1, 2, 3) «~» !;
.say for (1, 2, 3)«~»!
p6eval rakudo 87ad7c: OUTPUT«1!␤2!␤3!␤1!␤2!␤3!␤1!␤2!␤3!␤»
masak r: .say for (1, 2, 3)~!
p6eval rakudo 87ad7c: OUTPUT«===SORRY!===␤Two terms in a row␤at
/tmp/Kg__QjZ4yV:1␤-- .say for (1, 2, 3)~⏏!␤ [...]
* masak submits rakudobug
jnthn masak: It parsed as a subscript
masak jnthn: I know.
jnthn masak: Yes, and STD does it too.
jnthn masak: It's not a bug.
masak jnthn: responding to Ovid's p6u email from a week ago.
masak jnthn: the fact that it parses as a subscript isn't the bug.
masak jnthn: look at the evaluation before.
masak it parses as a subscript when it's ~, but not when it's «~»
jnthn oh...
jnthn Yeah, that's 'cus we're missing those quotes in the grammar somehow
masak that's the bug.
jnthn masak: OK, fair enough.

// masak

On Mon, Feb 25, 2013 at 11:56 AM, Ovid curtis_ovid_...@yahoo.com wrote:
 I was playing with this code: 
 https://github.com/Keith-S-Thompson/fizzbuzz-polyglot/blob/master/fizzbuzz.pl6

 [~](((1..100).map: {
 $_ % 15 == 0 ?? FizzBuzz !!
 $_ %  3 == 0 ?? Fizz !!
 $_ %  5 == 0 ?? Buzz !!
 $_
 })«~»(\n)).print;

 I was cleaning it up and since not everyone can type guillemets, I wound up 
 with this:

 [~](((1..100).map: {
 $_ %% 15 ?? FizzBuzz !!
 $_ %%  3 ?? Fizz !!
 $_ %%  5 ?? Buzz !!
 $_
 })~(\n)).print;

 That generated this error:

 No such method 'postcircumfix:( )' for invocant of type 'Parcel'
   in  at src/gen/BOOTSTRAP.pm:852
   in any  at src/gen/BOOTSTRAP.pm:836
   in block  at fizzbuzz.p6:6

 Reverting to guillemets fixes the problem. Is this a Rakudo bug or are double 
 angle brackets not interchangeable with guillemets?


 bin/perl6 -v
 This is perl6 version 2013.01 built on parrot 4.10.0 revision 0

 Cheers,
 Ovid
 --
 Twitter - http://twitter.com/OvidPerl/
 Buy my book - http://bit.ly/beginning_perl
 Buy my other book - http://www.oreilly.com/catalog/perlhks/
 Live and work overseas - http://www.overseas-exile.com/


Re: Per-Object Roles..

2013-03-04 Thread Carl Mäsak
Frank (), Moritz ():
 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.

However, if you want an un-adorned object later, just use infix:but,
and keep the original object around.

class C {
   has $.name = original;
}

role W {
   method name { wrapped }
}

my $original = C.new;
{
   my $wrapped = $original but W;
   say $wrapped.name;  # wrapped
   say $wrapped ~~ W;  # True
}
say $original.name;  # original
say $original ~~ W;  # False

// Carl


Re: implementing every(N)

2013-01-07 Thread Carl Mäsak
Ted ():
 Are state variables available now, or is the every(N) functionality
 possible in some other way now?

Why not try it by writing a small program? :)

Rakudo is available at a discount right now -- download it before it's
too late! -- and the syntax for state variables is the same as it's
always been. The one-liner to find out is shorter than your question:

$ perl6 -e 'sub foo { state $s = 0; say $s++ }; foo; foo; foo'
0
1
2

Regards,
// Carl


Re: s:g/T/U/ doesn't work ?

2012-10-24 Thread Carl Mäsak
Marc ():
 hello perl6 people,

 On

 This is perl6 version 2012.09.1
 built on parrot 4.6.0 revision 0

 When i try to run

 use v6;
 use Test;
 for 'GATGGAACTTGACTACGTAAATT' {
 s:g/T/U/;
 is $_
 , 'GAUGGAACUUGACUACGUAAAUU'
 , 'RNA';
 }

 I get

 Cannot assign to a non-container
   in sub infix:= at src/gen/CORE.setting:11692
   in block at /tmp/ZZZ:4

 As far as i understand from the doc, s:g/T/U/ is a valid syntax. any idea?

It's valid syntax. The error you're getting is not a syntax error;
it's a run-time error complaining about assigning to something that
isn't a container.

What you're assigning to is 'GATGGAACTTGACTACGTAAATT', a Str object.
That's a bit like trying to assign to the number 5. It should produce
an error, and it does. You need to put it into a variable, or an array
element, or a hash value -- in short, a container -- for it to work.
I think part of what felt confusing about this is that you did things
in a 'for' loop, so the assignment directly to a Str isn't that
obvious.

By the way, that 'for' loop over a single element is usually spelled
'given' in Perl 6.

I would write your code like this:

use v6;
use Test;

{
$_ = 'GATGGAACTTGACTACGTAAATT';
s:g/T/U/;
is $_,
'GAUGGAACUUGACUACGUAAAUU',
'RNA';
}

// Carl


Re: More bugs or PEBKAC

2011-09-05 Thread Carl Mäsak
1parrota (), Carl ():
 $ perl6 -e 'say Yo; if !{...}  { say Bye} '
 Yo
 $ perl6 -e 'say Yo; if {...}  { say Bye} '
 Yo
 Bye
 #       The opposite to what I'd expect, if ... returns failure

 Same base cause as your first example above. Similarly wrong.

Oops, I jumped the gun on this one, and sorear++ got it right in the
twin thread. The block is never exectured, but instead evaluated for
truth qua block. Blocks are always true, hence the above (correct)
results.

// Carl



Re: Criteria for production-ready?

2011-04-16 Thread Carl Mäsak
gvim ():
 Does there currently exist a set of criteria by which Perl6, or an
 implementation thereof, can be defined as production-ready?

Not just one set of criteria, but lots of sets of criteria.

Some of these sets have already gone from showing a no flag to
showing a yes flag in the past few years. Lots of other sets will
switch over in the next couple of years.

Our challenge as a Perl 6 community is to attract those people whose
criteria makes Perl 6 interesting enough, so that they can help making
Perl 6 useful for even more people, by using it, reporting bugs,
writing tutorials, blogging about it, etc. This process is *already*
self-maintaining and snowballing, but we can consciously help boost it
in various ways.

But this is why when you ask the production-ready question, you'll
not get a short, straight answer but a long one like this one. :)

// Carl


Re: Pack in perl6

2011-02-13 Thread Carl Mäsak
Richard ():
 I came across the idiom

 print P4\n$w $h\n;
 for my $y (0..$h-1) {
    print pack 'B*', pack 'C*', map dot($_, $y), 0..$w-1;
 }

 in a perl5 program for outputting dots in a graphical format. dot() produces
 a 0 or -1.

 I found the 'pack' function in perl6, but it does not seem to work the same.

Two differences that I can think of:

* The pack function in Rakudo is not fully implemented. For the cases
B* and C*, I can definitely imagine that it doesn't work yet.
Patches are welcome. I also plan to find some time to work more on it
myself.

* The fundamental difference in Perl 6 would be that a call to 'pack'
would result in a Buf, not a string as in Perl 5. (This is because
Perl 6 makes a clear separation between sequences of bits/bytes, and
strings of characters. 'pack' deals in the former.) It's not immediate
to me that a Buf could be output without first having been converted
to a Str. A conversion may or may not be necessary for it to work.

// Carl


Re: Things to Implement for Rakudo

2011-01-06 Thread Carl Mäsak
Guy ():
 I may have asked them why they did not map (A,C,G,T) - (0,1,2,3) but
 since then, I've learned more about what GC-content implies in terms of
 chemistry -- it also seems to have evolutionary implications, about
 which I know nothing.

With this I can help at least, being schooled in molecular biology.
People who don't care much about biochemistry, feel free to ignore
this post, which is admittedly not about Perl 6.

DNA is ultimately to be turned into proteins, which make up our
bodies. The genetic code is a hash table from all possible triplets
of (A, C, G, T) -- so, 64 possible triplets -- to 21 amino acids that
chain up to make proteins. 21 is smaller than 64, so there's
redundancy in the genetic code (mathematicians would call this a
non-injective mapping). Since several triplets may map to the same
amino acid, there is some wiggle room in the choice of bases.
(Furthermore, some amino acids are chemically quite similar, giving
even more potential wiggle room.)

Now, let's say you're a thermophilic bacterium living around the hot
springs of Iceland. Your DNA is under a lot of stress from the heat,
and the bonds break up all the time. Something needs to be done,
stable DNA is important. You decide -- well, natural selection pushes
you as a group, really -- to favour GC bonds rather than AT bonds,
because a GC bond has three hydrogen bonds whereas an AT bond has only
two. You're constrained by the proteins you want to produce, but the
wiggle room allows you to favour GC bonds. Higher GC content - more
hydrogen bonds - sturdier DNA - better survival.

Hopefully that also explains why the mapping in the algorithm can be
GC - 1 and AT - 0. From the viewpoint of hydrogen bonds, only this
simpler mapping matters.

 http://en.wikipedia.org/wiki/Genetic_code
 http://en.wikipedia.org/wiki/GC-content
 http://en.wikipedia.org/wiki/Injective_function
 http://en.wikipedia.org/wiki/Thermophile

Hope that helps,
// Carl


Announce: Rakudo Perl 6 development release #30 (Kiev)

2010-06-17 Thread Carl Mäsak
On behalf of the Rakudo development team, I'm pleased to announce the
June 2010 development release of Rakudo Perl #30 Kiev. Rakudo is an
implementation of Perl 6 on the Parrot Virtual Machine (see
http://www.parrot.org). The tarball for the June 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. This release is named after the Perl
Mongers from the beautiful Ukrainian capital, Kiev. They recently
helped organize and participated in the Perl Mova + YAPC::Russia
conference, the хакмит (hackathon) of which was a particular success
for Rakudo. All those who joined the Rakudo hacking - from Kiev and
further afield - contributed spec tests as well as patches to Rakudo,
allowing various RT tickets to be closed, and making this month's
release better. Дякую!

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

* Rakudo now uses immutable iterators internally, and generally hides
their existence from programmers. Many more things are now evaluated
lazily.

* Backtraces no longer report routines from Parrot internals. This
used to be the case in the Rakudo alpha branch as well, but this time
they are also very pleasant to look at.

* Match objects now act like real hashes and arrays.

* Regexes can now interpolate variables.

* Hash and array slicing has been improved.

* The REPL shell now prints results, even when not explicitly asked to
print them, thus respecting the P part of REPL.

* Rakudo now passes 33,378 spectests. We estimate that there are about
39,900 tests in the test suite, so Rakudo passes about 83% 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, as well as those people who worked on
parrot, the Perl 6 test suite and the specification.

The following people contributed to this release:
Patrick R. Michaud, Moritz Lenz, Jonathan Worthington, Solomon Foster,
Patrick Abi Salloum, Carl Mäsak, Martin Berends, Will Coke Coleda,
Vyacheslav Matjukhin, snarkyboojum, sorear, smashz, Jimmy Zhuo,
Jonathan Duke Leto, Maxim Yemelyanov, Stéphane Payrard, Gerd
Pokorra, cognominal, Bruce Keeler, Ævar Arnfjörð Bjarmason,
Shrivatsan, Hongwen Qiu, quester, Alexey Grebenschikov, Timothy Totten

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 (#31) is scheduled for July 22, 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: Perl6 confused about module name

2010-03-02 Thread Carl Mäsak
Victor ():
 Why it asks for Opendir.pir instead of Opendir.pm ?
 Any clue ?

Short answer: Rakudo has regressed and doesn't support loading .pm
modules at the moment. You're probably on the Amsterdam (February)
release. I suggest using the Minneapolis (January) release until
Rakudo regains this functionality.

Long answer: The release announcement http://rakudo.org/node/64 says
the following:

] This release is the first release based on the new branch of
] Rakudo development begun in October 2009. The branch refactors
] the grammar, object metamodel, and a number of other key features
] to improve compatibility with the Perl 6 specification and give us
] a more solid foundation to build on. Indeed, in many ways the
] development of this new branch has driven important changes to the
] specification in the areas of lists, iterators, slices, and much
] more.
]
] However, this release contains a number of significant regressions
] from previous compiler releases. We expect to have full functionality
] restored in this branch in the next couple of weeks. For those
] looking to explore a wide variety of Perl 6 features or who have
] applications developed using previous releases of Rakudo, you may
] wish to continue to use the January 2010 (#25, Minneapolis)
] release.

// Carl


Re: trouble building rakudo

2009-11-22 Thread Carl Mäsak
Paul ():
 I try building rakudo from git clone git://github.com/rakudo/rakudo.git but 
 during make it hangs forever (12+ hours) at

    /usr/local/bin/parrot  perl6_s1.pbc --target=pir src/gen_setting.pm  
 src/gen_setting.pir

 While it hangs at that line the linux (Debian 5.0 Lenny) box starts lots of 
 swapping activity.

 Anybody have any ideas what might be happening?

Yes, that step is pretty resource-intensive.

From your description, it sounds like Rakudo could use a little more
memory during compilation. On my computer, that compile step takes
about 3 minutes, and sucks up about 750 MB of RAM. My guess is that
you have less than that free when you're building Rakudo.

// Carl


Rakudo Perl 6 development release #23 (Lisbon)

2009-11-19 Thread Carl Mäsak
Announce: Rakudo Perl 6 development release #23 (Lisbon)

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

Due to the continued rapid pace of Rakudo development and the frequent
addition of new Perl 6 features and bugfixes, we recommend building Rakudo
from the latest source, available from the main repository at github.
More details are available at http://rakudo.org/how-to-get-rakudo.

Rakudo Perl follows a monthly release cycle, with each release code
named after a Perl Mongers group.  The November 2009 release is code
named Lisbon for Lisbon.pm, who did a marvellous job arranging this
year's YAPC::EU.

Shortly after the October 2009 (#22) release, the Rakudo team
began a new branch of Rakudo development (ng) that refactors
the grammar to much more closely align with STD.pm as well as
update some core features that have been difficult to achieve
in the master branch [1, 2].  Most of our effort for the past month
has been in this new branch, but as of the release date the new
version had not sufficiently progressed to be the release copy.
We expect to have the new version in place in the December 2009 release.

This release of Rakudo requires Parrot 1.8.0.  One must still
perform make install in the Rakudo directory before the perl6
executable will run anywhere other than the Rakudo build directory.
For the latest information on building and using Rakudo Perl, see the
readme file section titled Building and invoking Rakudo.

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

* Rakudo is now passing 32,753 spectests, an increase of 171 passing
  tests since the October 2009 release.  With this release Rakudo is
  now passing 85.5% of the available spectest suite.

* As mentioned above, most development effort for Rakudo in November
  has taken place in the ng branch, and will likely be reflected
  in the December 2009 release.

* Rakudo now supports unpacking of arrays, hashes and objects in
  signatures

* Rakudo has been updated to use Parrot's new internal calling conventions,
  resulting in a slight performance increase.

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 (#24) is scheduled for December 17, 2009.
A list of the other planned release dates and codenames for 2009 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!

[1] http://use.perl.org/~pmichaud/journal/39779
[2] http://use.perl.org/~pmichaud/journal/39874


Announcing pun (Re: rakudo-current loop 2-3 orders of magnitude slower than perl 5?)

2009-06-05 Thread Carl Mäsak
Steffen (), Fagyal ():
 However, performance is an issue. I would not mind running into
 bugs, writing some extra code to work around missing stuff, etc.,
 but right now it is just hard to find any projects (for me - YMMV)
 where performance would not be a blocker.

 I suggest to start using it as replacement for sysadmin automation
 tasks. The same way Perl started to replace sh/sed/awk. This would not
 need all the funky OO or FP features you get with Perl 6 but many of
 those tasks are not speed critical and still of practical use and
 would already benefit from the syntax cleanup compared to Perl 5.

I'll take this opportunity to announce 'pun', a small Perl 6 project
to emulate the behaviour of the -p and -n flags in Rakudo. (The name
'pun', believe it or not, doesn't stand for anything in particular.)

pun
 http://github.com/masak/pun/

The principle behind it is easy: you just type 'perl6n' instead of
'perl6 -n'. Same thing for 'perl6p' and 'perl6 -p'.

$ ./perl6p -e .=flip # here's a rev clone
I CAN HAZ BACKWARDS?
?SDRAWKCAB ZAH NAC I
^D

I find this is an excellent way to start using Perl 6 for simple
sed/awk-like tasks today. Maybe some of you will too.

If you try pun and would like to comment, critique, patch, document,
or otherwise improve the software for the greater good of the Perl 6
community, please don't hesitate to contact me, via email or #perl6 on
freenode.

// Carl


Re: the file slurping is not working

2009-06-05 Thread Carl Mäsak
Daniel (), Leon (), Daniel ():
 Then why is it that .get works fine for $*IN?

 while $*IN.get - $line {
       say $line
 }


 Because you're using a while loop instead of a for loop ;-)

 Worse. The code I wrote has a subtle but horrible error. The condition will
 fail as soon as you hit a blank line!!

Which, I think, summarizes why the 'for $*IN.lines' idiom is preferred
in Perl 6.

// Carl


Announcing Form

2009-03-16 Thread Carl Mäsak
I'd like to take this opportunity to announce Form[1], a Perl 6
project by Matthew Walton. It's a port to Perl 6 of Damian Conway's
Perl6::Form[2], and is meant to replace the Cformat built-in in Perl
5.[3][4]

Form is still in its early stages, but is already showing great
promise. Consider downloading it and trying it out, or even
contributing.

[1] http://github.com/mattw/form/
[2] http://search.cpan.org/dist/Perl6-Form/Form.pm
[3] http://perldoc.perl.org/functions/format.html
[4] http://perldoc.perl.org/perlform.html


Re: perl6 tutorials

2009-03-02 Thread Carl Mäsak
Hej Lars,

Lars ():
 I do not know Perl at all, but I'm very interested in perl6.
 My problem is I do not find a good tutorial how to do real perl6
 development, all I find seems to assume you know perl5 and the perl
 community. And I do not.

That's an interesting question! I guess most of the people heavily
involved in Perl 6 are also quite familiar with Perl 5. Since people
scratch mostly their own itches, not much Perl 6 for newcomers.

I'd recomment the Perl 6 Programmin wikibook,

 http://en.wikibooks.org/wiki/Perl_6_Programming

but unfortunately it's still in its very early stages, and
unfortunately its owner writes slightly unidiomatic Perl 6 code.

 As an example I like to build a routine that connects to SAP and fetch data
 from SAP. I know there are SAP-Perl5 routines, can those be used? how do I
 find and use them? etc.

 It is even hard to find someone to ask?

I would recommend that you start by visiting #perl6 on
irc.freenode.net -- the people there can often provide detailed
answers and help newcomers. During European daytime, it's not hard to
find someone to ask.

As to CPAN modules in Rakudo Perl 6 -- if that's what you're asking
about -- we're not quite there yet. It'll be really sweet once we are,
but I think integrating the Perl 5 and 6 runloops is fairly
nontrivial.

 Yeah, I know Perl6 isn't ready yet, but it looks really really good and I'm
 eager to learn perl6, but not by learning perl5 first if possible.

I think you represent a very important target group for Perl 6: it
shouldn't be necessary to have prior knowledge of Perl 5 in order to
learn Perl 6.

At present, however, tutorials and documentation are sorely lacking.
During the summer, we'll be fleshing out U4X, a documentation effort
which aims to explain all aspects of Perl 6 to newcomers. But it's not
summer yet, so the best tip I can give you is to tap the brains of the
nice people over at #perl6.

Regards,
// Carl


Re: perl6 -e 'say Hello World!'

2009-02-02 Thread Carl Mäsak
Jeremiah ():
 OHAI!

 I have just built Parrot and perl6 and am just getting started. I'm gonna
 lurk a little. :)

Welcome! Enjoy Perl 6, and let us know if you need clarification or
think you've found a bug. There's plenty of people here (and on #perl6
at irc.freenode.net) who can help in deciphering the synopses, and
providing workarounds to current Rakudo shortcomings.

// Carl


Re: Roles definition

2009-01-18 Thread Carl Mäsak
Илья ():
 I use role to mix in some functionality for testing:

 my $s = November::Storage::File.new does Testing;

 And I have Role definition _after_ this:

 role Testing { ... }

 Now this is fall with:

 Null PMC access in isa()
 current instr.: 'infix:does' pc 20660 (src/builtins/op.pir:403)
 called from Sub '_block14' pc 108 (EVAL_20:47)

 And all work again if I put definition _before_ instant and `does`.

 It looks like bug for my, but mb this is right behaviour?

The 'Null PMC access' certainly isn't right, but even modulo that, the
role must be declared before it's being used. Jonathan said that it
should really be a compile error.

 http://irclog.perlgeek.de/perl6/2009-01-18#i_843003

Generally, in Perl 6, one has to declare identifiers in some way
before referring to them.

// Carl


Re: getting the face value of an enum

2009-01-14 Thread Carl Mäsak
Richard ():
 S12 defines enums and rakudo impliments them, so
 perl6
 enum wkend Sat Sun; my $x = Sun; say $x
 1

 But suppose I want to get the face value of $x, viz., 'Sun'?

 How do I get it?

 say $x.key doesnt work.

Far as I know, the answer to your question is unspecced.

(Yes, that sucks. I've also wanted the name of an enum value
sometimes, but so far I've had to work around it in various ways.)

// Carl


Re: Solution to Games #2

2009-01-11 Thread Carl Mäsak
Richard ():
 use v6;

 my %players;
 my $scores = open('./skaters.txt', :r) or die $!;
 for =$scores {
  my ($name,@list) = .split /\,/;
  %players{$name} = ([+] @list.sort[2..6]) / 5;
 };

 my @ranking = %players.sort: { .value };
 for Gold Silver Bronze - $m {
  given pop @ranking {
  say $m Medal: {$_.key}, {$_.value};
  };
 };

Nice.

A few notes:

* Parsefail at line 6. Should have parens around the regex '/\,/'.
* You don't need semicolons after line-ending braces '}'.
* Consider using .fmt instead of lines 12-14:

  say (pop @ranking).fmt($m Medal: %s, %s);

Ta-da! That's 11 lines of code, 35% shorter than the Perl 5 solution.

// Carl


Re: Fwd: [november] Re: arrays and arrays ref question

2008-10-31 Thread Carl Mäsak
Guy (), Carl (), Moritz ():
  for @($ar) { ... }

 This would arguably be the nicest variant.

Well, actually, by this I meant all three variants that Moritz suggested. :)

  for @$ar { ... }
  or even
  for @ $ar { ... }
  or
  for @($ar) { ... }

Guy ():
 for ( @$ar ) { ... }

 ?

That's Moritz' first suggestion, but with a pair of unnecessary
parentheses thrown in. :)

Larry (), Carl ():
: All I know is that `for $ar.elems { ... }` used to work for this case.
: It doesn't seem to work anymore.
:
: Time to file a ticket, methinks.

Er, .elems is always supposed to return a number.  Maybe you want
.values there instead, though that doesn't work either.  :)

Yes, .values. Sorry about the confusion. (With all the shortcomings of
the name length, it doesn't invite confusion about whether a number
or a list of things is returned, as elems and values might. That
said, I've only used either method a handful times, so maybe it's just
a question of language acquisition.)

// Carl


Re: Precompilation to PIR

2008-10-27 Thread Carl Mäsak
Chris ():
 How safe is it today to pre-compile Rakudo code to PIR and expect that to
 behave identically to as if I compiled from .pm at runtime?  I believe PCT
 is just generating PIR anyway, so my initial guess is that there should be
 no differences.  Are there any gotchas, like compile-time dependency checks,
 that I should look out for?

Precompilation to PIR currently doesn't work in the November project
-- the difficulties occur when trying to call methods in the
precompiled module. Right now our Makefile protests if someone tries
to compile the modules to PIR.

I think there is an rt ticket for this, but my attempts to dig it up
fail. Maybe someone else is more lucky.

// Carl


Re: Assigning and passing $/

2008-10-24 Thread Carl Mäsak
Chris ():
  I can't assign $/ to a variable or
 pass it to a method.  Is this a bug, or am I just confused?

I think it's a bug. I sent your message along to [EMAIL PROTECTED]

// Carl


Re: Recommended Perl 6 best practices?

2008-09-14 Thread Carl Mäsak
Conrad ():
 Is there something more up-to-date concerning Perl 6 best practices that
 are presently-recommended (by p6l or @Larry) than the following item on the
 Perl 6 wiki?

If you ask me, best practices evolve as a countering force to enough
people using less-than-ideal practices to create maintenance headaches
or suboptimal solutions noticeable enough for someone to put together
a collection of tips and insights.

I use Perl 6 every day. My problem is not that I encounter badly
thought-out Perl 6 code frequently -- it's that we're targeting
incomplete Perl 6 implementations and have to go against what would
ordinarily be seen as best practices in order to circumvent bugs and
missing features in various layers of the Perl 6 implementation stack.
The tricks we evolve to do this are far removed from best practices:
they are closer to the worst advice you could give a Perl 6 beginner.
(Because most of them solve a problem _without_ the help of some
convenient Perl 6 feature.)

That said, I do have one Perl 6-specific best practice. I know
you're looking for a collection, but one's a start. :) Here it is:

Do not combine 'ne' and '|', like this:

die Unrecognized directive: TMPL_$directive
   if $directive ne 'VAR' | 'LOOP' | 'IF';

One is tempted to assume that this means the same as $directive ne
'VAR' || $directive ne 'LOOP' || $directive ne 'IF, but it doesn't.
Instead, it's a negated string comparison against three values, the
results of which are then OR-ed together. The condition will always be
true, because there's always at least two values that $directive is
not string-equal to.

The correct form using junctions would be this:

die Unrecognized directive: TMPL_$directive
   if $directive ne 'VAR'  'LOOP'  'IF';

But my brain refuses to let me believe that this is what I want to
write. (If $directive is not string-equal to 'VAR' and 'LOOP' and
'IF'... well of course it isn't!)

So instead, I'd use eq, and negate the whole expression:

die Unrecognized directive: TMPL_$directive
   if !($directive eq 'VAR' | 'LOOP' | 'IF');

The more general advice, then, would be not to use junctions together
with negated equality operators. Instead, use the non-negated equality
operator, and negate the whole expression.

// Carl


November

2008-08-15 Thread Carl Mäsak
We're pleased to annouce the release of November, a wiki engine written
in Perl 6.

November is:

* ...a proof-of-concept of what Rakudo Perl 6 can do today.
* ...released early rather than when it's done.
* ...meant to promote interest and involvement in Perl 6/Rakudo/Parrot
  development.

To learn more, please browse the slides from the YAPC:EU 2008 lightning
talk:

 http://viklund.pp.se/november.pdf

November is free, released under the Artistic License 2.0, and available
online:

 http://github.com/viklund/novmber/

Enjoy!

// Carl Mäsak  Johan Viklund


Re: pugs bugs (or features?)

2007-09-07 Thread Carl Mäsak
Wim ():
 The following program works fine in pugs r17041 (which is the rev of
 /usr/bin/pugs on feather):

 my $r=\{say $x+1};
 my $x=2;
 $r();

 With r17041, this gives 3;
 However, on the latest pugs (r17615 or later), it gives an error:
 ***
 Unexpected $r
 expecting =, ::, context, : or (
 Variable $x requires predeclaration or explicit package name
 at pugs_var_bug.p6 line 1, column 4

 It would think that the r17041 result is correct.
 ---
 There is also a scoping issue in r17615:

 my $v=1;
 if ($v) {
 map -$v {$v},(2);
 } else {
 $v;
 }

 With r17041, this gives 2; With r17615 it gives an error:
 ***
 Unexpected end of input
 expecting ::
 Variable $v requires predeclaration or explicit package name
 at pugs_scoping_bug.p6 line 6, column 15

 Now, if I change $v to $x in the pointy sub, it works fine.
 -

 Both  seems like bugs to me, but can someone confirm that?

They're most likely bugs. Since May, Pugs has been halfway towards
getting a new MO core.

 http://moritz.faui2k3.org/irclog/out.pl?channel=perl6;date=2007-05-17#i_18608

Not everything has been working since then, and likely won't until the
other half is committed. #perl6 people might be able to fix minor
flaws, but there's general hesitation towards fixing things that might
be superceded by the new MO machinery.

// Carl


Re: Same-named arguments

2006-08-23 Thread Carl Mäsak

Juerd (), Michael Snoyman ():

 sub mysub($foo, @foo, %foo) {

I hope this is a compile time failure. If not, I'd expect a warning, at
least.


Why? It looks reasonable IMHO.

// Carl