
Perl 6 hands-on tutorial – A small introduction to a big language [pdf] - kbenson
http://jnthn.net/papers/2015-spw-perl6-course.pdf
======
cms07
I absolutely love Perl, and I think that the newest versions of Perl 5 have
taken much of the good things that Perl 6 promised and added them. I really
think that Perl 6 misses the point and removes all of the charm of Perl. Why
change sigils and all of these operators? The people who don't like them
aren't using Perl anyway, and they won't be using Perl 6 just because it
implements them in a more obvious but less meaningful way.

I also don't think the addition of a more mainstream object system is a
positive thing, but that's a debate for another time.

Edit: And it's not just about sigils, but about changing things for no
meaningful reason, especially things that set Perl apart and make it what it
is.

~~~
MadcapJake
Name some things that they changed for "no meaningful reason".

As you state, Perl 5 has added a number of things that Perl 6 promised. So why
would you want Perl 6 to just be what Perl 5 has become? They're two
completely separate languages with _some_ shared syntax/semantics.

~~~
hayksaakian
From an outside perspective, the distinction between Perl 5 and Perl 6 is
confusing.

Are they literally separate languages?

Did Perl 5 come after Perl 6?

~~~
jasonjayr
Perl 6 started around when perl 5.8 was released. Then Perl 5 went stagnant
while most of the core language developers were working on Perl 6. After a few
years where there were competing implementations of perl 6, and still some
wild ideas being tested, folks that still were using Perl 5 watched the rest
of the languages develop, and the growing buglist against perl 5, and starting
poaching ideas from Perl 6, ruby, python, and improving the Perl 5 runtime.

Eventually, The Perl 5 camp committed to regular releases, and continued
renewed development in the engine, and it is still pretty good. But the damage
has been done @ this point -- a lot of the community has wandered off to other
'cool' languages and frameworks.

The confusion will continue, especially since it's become clear Perl 6 is
quite the departure from Perl 5, and there is a _LOT_ of code in the wild
using Perl 5. I've seen some talk of the Perl 5 folks asking Larry Wall to
rename Perl 6, but he's declined to do so.

With perl6's grammar support, some folks are working on importing the perl5
grammar into perl6[0]. Fortunately, there's a very rich testing environment(in
the form of CPAN) to ensure this effort will be stable.

[0] [https://github.com/rakudo-p5/v5/](https://github.com/rakudo-p5/v5/)

~~~
inopinatus
> a lot of the community has wandered off to other 'cool' languages and
> frameworks

I am just one such. Half my career was writing Perl. But these days, most of
my work is in Ruby and as a longtime fan of Erlang (but never having had the
opportunity to use it in production), I'm taking a long look at
Elixir+Phoenix. This tutorial wasn't enough to entice me back to Perl, and I'm
wondering if there is anything at all that could.

In general we choose a language for their applicability to the problem domain.
The focus on text manipulation in Perl 4, and then extension of this with an
object framework in Perl 5, made it a shoo-in in the 90s and early C21 when we
all needed form parsing, HTML template stuffing, and email mangling tools. In
these days of dynamic DOM manipulation and event-driven microservices, it
doesn't seem so relevant; whilst Node and Go and Elixir look entirely on
point.

If you go look at the Perl 6 FAQ, there's a section, "Why should I learn Perl
6?". It lists a grab-bag of language features, rather than a set of problems
that Perl 6's new design can solve. As a result it feels much like a solution
in search of a problem. That wasn't even ever true of JavaScript, even though
JS took years to come of age.

If I was designing a language today, and I am not, but if I were, I would look
at how dominant Java seems to be in the big data community and try knocking it
off that perch with appropriate language primitives, constructs and libraries.
It seems to me this is the modern problem domain homologous to the bulk text
mangling for which Perl originally became famous.

~~~
muraiki
For event-driven microservices, I think Perl 6 is actually a great choice. I
have experience writing some small things in Go and Node.js, but Perl 6 offers
much more powerful high-level features for handling async, concurrency, and
parallelism.

Promise combinators are built into the language to provide composable
concurrency. But unlike using something like Q in Node.js, you can truly
perform tasks across promises in parallel (and with static typing to boot!)

Perl 6 has channels for when you want Go style semantics, but you also have
Supplies for when you want their dual: instead of pushing events through
channels you pull them reactively. This allows you to write highly declarative
code; see
[https://gist.github.com/muraiki/222814d5928f648be3c1](https://gist.github.com/muraiki/222814d5928f648be3c1)

I think that P6 will also be awesome for data munging. Here's a pipeline that
processes text from a file with 4 parallel workers.

    
    
      my $lines = open('foo.json', :r).lines.hyper(batch => 20, degree => 4)
      my $filter = $lines.grep: -> $line { $line ~~ /someregex/ };
      my $json = $filter.map: &from-json;
      my $foos = $json.grep: *<some_property> == 'foo';
      say $foos.list[8];
    

Since the operations are done in scalar context, they essentially operate
lazily, pulling one value through the chain at a time. The pipeline is only
activated once coerced to list context at the end, and only enough values as
are required to find the 9th match are processed.

I've used Elixir before. It has some great features and having the power of
BEAM and OTP is quite awesome. But sometimes the actor model is not what you
want. I think that Perl 6 will be not just a great glue language, but also a
powerful language for writing multi-paradigm applications that meet the
demands of modern systems.

~~~
raiph
Fyi, Jonathan recently wrote:

> Also, the name channel is evocative of the concept in Go, but our channels
> aren't like that. They don't block senders until the receiver is ready, for
> example. While a blocking queue is a very useful thing to have in a
> language, and we should keep it, we may want to stop calling it Channel, to
> avoid confusion (and keep the name free for something that has the Go-ish
> semantics).

(from
[https://gist.github.com/jnthn/a56fd4a22e7c43080078](https://gist.github.com/jnthn/a56fd4a22e7c43080078))

(note that most of the changes mentioned in the gist have since been
implemented)

------
natch
"Try 0.1 + 0.2 == 0.3 in some other language, then try it in Perl 6."

Whoa, wtf python:

    
    
        $ python
        Python 3.4.3 (default, Jul 13 2015, 12:18:23) 
        [GCC 4.2.1 Compatible Apple LLVM 6.1.0 (clang-602.0.53)] on darwin
        Type "help", "copyright", "credits" or "license" for more information.
        >>> 0.1 + 0.2 == 0.3
        False
        >>>

~~~
chubot
Why is this surprising? Floats are defined by the hardware essentially, not
the language.

And this is how they work: they're binary, not decimal. Computers are binary,
not decimal. 0.1 can't be represented exactly as binary.

Python has a decimal type, if that's what you want:
[https://docs.python.org/2/library/decimal.html](https://docs.python.org/2/library/decimal.html)

I consider it a basic point of computer literacy to understand this.

~~~
dragonwriter
That decimal literals represent binary floating point numbers is defined by
the language, not the hardware.

I consider it a basic point of language design literacy that exact decimal
literals without some other indicators should not represent an inexact type
that isn't designed to represent decimal data.

Infuriatingly, very few languages get that right. But perl 6 isn't unique in
doing so; Scheme had been doing it right for decades.

~~~
dragonwriter
(Actually, Scheme doesn't quite get this right: decimals are inexact by
default and only rationals expressed as divisions of integers are exact,
though it is less cumbersome to specify an exact decimal than in most popular
language -- its a literal modifier, not a function call.)

e.g.:

    
    
      0.2
    

is inexact, while

    
    
      #e0.2
    

is exact.

~~~
raiph
The use of an annotative '#e' to get an exact number contrasts with Perl 6's
choices for the default interpretation of number literals. The Perl 6 choice
adopts scientific notation to correspond to floats:

    
    
        200000000000000000000  # exact (integer)  2 * 10 ** 20 
        0.00000000000000000002 # exact (rational) 2 * 10 ** -20
        0.2e-19                # inexact (float)  2 * 10 ** -20
        2e20                   # inexact (float)  2 * 10 ** 20

------
the-owlery
It's great that this is available (haven't worked through it yet).

Two major show-stoppers for me right now though:

* In the Perl 6 repl, I can't use my up/down arrows, or ^p/^n to get at previous lines I typed, nor ^a/^e and alt-B/alt-F to navigate on the line.

* In the repl, I can't do `doc(some-func)` to get at docstrings.

~~~
kbenson
> In the Perl 6 repl, I can't use my up/down arrows, or ^p/^n to get at
> previous lines I typed, nor ^a/^e and alt-B/alt-F to navigate on the line.

Really? In they version I have access to arrow keys and ^p/^n/^a/^e all
function.

I've just been informed that what you need is "panda install Linenoise" to
install the Linenoise module to get this functionality.

I agree documentation in the language would be nice. A module could handle
that nicely.

~~~
kamaal
I think this kind of stuff should be available out of the box. I'm learning
Perl 6 too, Inability to use the arrow keys has almost left the REPL unusable
to me.

I'm just writing programs in proper files and executing them.

~~~
kbenson
I agree. Maybe rakudobrew should have a target that hits install, panda and
p6doc and that being the default for new setups.

FYI, you can install p6doc with "panda install p6doc", which is the Perl 6
equivalent of perldoc. I don't believe it has in-language methods yet, but I
imagine it wouldn't be that hard. For now, it's a CLI tool.

    
    
      # p6doc Str.tclc
       routine tclc
    
         multi sub    tclc(Str:D ) returns Str:D multi method tclc(Str:D:)
         returns Str:D
     
     Turns the first character to title case, and all other characters to lower case
     
     (not implemented in Niecza)

~~~
the-owlery
Thanks. Tried installing but got errors.

    
    
        ==> Fetching p6doc
        ==> Building p6doc
        ==> Testing p6doc
    
        # Failed test 'empty blocks argument gives undefined content'
        # at t/pod-convenience.t line 31
            # Looks like you failed 1 test of 7
    
        # Failed test 'pod-with-title'
        # at t/pod-convenience.t line 23
        t/pod-convenience.t .. 
        Failed 2/10 subtests 
        t/pod-htmlify.t ...... ok
        Method 'super' not found for invocant of class 'Array'
          in sub visit at /home/me/.panda-work/1441386381_4/lib/Perl6/TypeGraph.pm:89
          in sub visit at /home/me/.panda-work/1441386381_4/lib/Perl6/TypeGraph.pm:89
          in method topo-sort at /home/me/.panda-work/1441386381_4/lib/Perl6/TypeGraph.pm:92
          in method parse-from-file at /home/me/.panda-work/1441386381_4/lib/Perl6/TypeGraph.pm:82
          in method new-from-file at /home/me/.panda-work/1441386381_4/lib/Perl6/TypeGraph.pm:30
          in block <unit> at t/typegraph.t:8
    
        t/typegraph.t ........ 
        Dubious, test returned 255 (wstat 65280, 0xff00)
        Failed 8/8 subtests
    

This is with a fresh (as of minutes ago) `rakudobrew build moar`:

    
    
        $ perl6 -v
        This is perl6 version 2015.07.1-728-g9c5cb50 built on
        MoarVM version 2015.07-108-g7e9f29e

~~~
raiph
Hmm.

I'm using my account on the Perl 6 community dev server hack.p6c.org.

I used rakudobrew to rebuild rakudo last night:

This is perl6 version 2015.07.1-215-ge6f3602 built on MoarVM version
2015.07-108-g7e9f29e

I just ran `panda install p6doc` and it worked fine for me.

What do you get when you run `perl6 -e '$*DISTRO.say'?

Investigating...

~~~
the-owlery
This is on Debian Testing:

    
    
        $ perl6 -e '$*DISTRO.say'
        debian (3.16.0.4.amd.64)
    

Sorry, should probably take this to #perl6.

~~~
raiph
I rebuilt everything... and p6doc failed to build.

It turns out that the glr branch got merged about 5 hours ago (about the time
you started commenting). I'm posting this now, before I catch up with the irc
backlog, to give you a heads up, but I'd expect p6doc to be working again
within a few days at the outside and quite likely by the end of today. (In the
meantime you can use the web version at
[http://doc.perl6.org.](http://doc.perl6.org.))

------
logicallee
stopped reading on slide 7. What do you think this does:

    
    
       say 1.WHAT;
    

"say" prints something, and nothing was previously declared. What do you think
it prints?

~~~
dmux
integer?

~~~
logicallee
yes. Maybe it's more reasonable than I thought (or I gave more information
than reasonable - I've now removed some.)

I don't think "say 1.WHAT" is reasonable syntax in the slightest.

~~~
epidemian
> I don't think "say 1.WHAT" is reasonable syntax in the slightest.

The syntax is basically the same as Ruby or Python:

    
    
      # Ruby:
      puts 1.class
      # Python:
      print 1L.__type__
    

The names of the methods are different, and Python needs the L suffix, or wrap
the integer around parens `(1).__type__` to avoid it confusing the dot with a
float literal. But, besides that, the syntax is the same.

~~~
logicallee
yes, class and __type__ seem very reasonable keywords to me, a yelling WHAT
does not. the syntax is the same, except the choice of WHAT. I guess I'm the
only one who considers it hopelessly odd. if "object1.class == object2.class"
seems like something you might think of. But "object1.WHAT == object2.WHAT" is
something that wouldn't occur to me in a million years, and makes me laugh
even now that I've written it. I suppose you might disagree.

~~~
epidemian
class and __type__ are no keywords here. They are just the names chosen for
those attributes/methods.

I was just pointing out that what you considered unreasonable _syntax_ was
actually pretty common syntax. That the function/method names could be better,
I agree. But that's an entirely different matter.

~~~
raiph
> That the function/method names could be better, I agree.

Are you referring to python's choices, ruby's, Perl 6's, or all of them? If
you think .WHAT could be better, is it the all caps you dislike or is it use
of the word 'what' or both? What would you suggest instead?

~~~
logicallee
to epidemian, yes, it's what I was referring to, sorry I wasn't more clear.

raiph: we're talking about perl 6's two choices for the things you've brought
up, that it's in all-caps and that it consists of the contextually nonsense
word 'what'.

The word "what" is one of the most common English words - so the opposite of a
better, explicit choice, like type, class, classtype, etc - and doesn't even
_mean_ "what-is" if you read it out loud. 3.WHAT doesn't sound like "What 3
is" \- it sounds like "3 - I didn't hear you" or if you're being very generous
it means "What is 3?" (asking for its value).

You asked what I would suggest? If you want to be really cute and grammatical
while sounding like a natural language, here is a suggestion. Instead of WHAT
my suggestion is the word STYPE, and read it as though the preceding word had
an apostrophe at the end: 3.STYPE, thiswindow.STYPE and so forth. (3's type,
thiswindow's type, etc). anyway you asked for a suggesiton, there you have it.
I woudn't use it myself though.

~~~
raiph
> the contextually nonsense word 'what'.

I don't buy that it's contextually nonsense. I suspect you had a bad reaction
to it and have gotten caught up in that initial reaction. I could be wrong
about that but your stated perspective is noticeably extreme and unique about
a relatively tiny point.

> if you're being very generous it means "What is 3?" (asking for its value).

I don't think that's being especially generous. But yes, please be generous.
:)

I don't think it's asking for its value.

What is Belgium? (Country) What is HN? (Time Sink) What is `4 -3i` ? (Complex
Number). What is $age? (Int)

If you want a value you just write something like:

    
    
        say 3;    # 3
        say $age; # 55
    

> You asked what I would suggest?

Well I intended my comment for epidemian, but OK. :)

> If you want to be really cute

Perl 6 explicitly incorporates fun but also explicitly avoids "you think
that's cute today" mistakes.

I like the choice of names for the pseudo method mop macros: what, which,
where, who, why, how, etc. But that's partly because: I find them easy to
remember as a group; I found them easy to understand once I'd encountered them
once; and I've not seen anyone react negatively to any of them the way you
have.

\----

Anyhoo, I hope you won't let your dislike for the rarely used .WHAT et al to
unduly color your view of Perl 6. I don't expect the tutorial that's the topic
of this HN to impress anyone but that's because it deliberately sticks to
absolute basics. Instead, I urge you to wait until next year, and then take
another look; I think you'll see there's a lot to like.

