<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
    <title>Brian Wisti</title>
    <link rel="alternate" type="text/html" href="http://blogs.perl.org/users/brian_wisti/" />
    <link rel="self" type="application/atom+xml" href="http://blogs.perl.org/users/brian_wisti/atom.xml" />
    <id>tag:blogs.perl.org,2009-11-03:/users/brian_wisti//270</id>
    <updated>2013-02-25T02:28:09Z</updated>
    <subtitle>A blog about the Perl programming language</subtitle>
    <generator uri="http://www.sixapart.com/movabletype/">Movable Type Pro 4.38</generator>

<entry>
    <title>Think Python in Perl 6 Chapter 4: Interface Design</title>
    <link rel="alternate" type="text/html" href="http://blogs.perl.org/users/brian_wisti/2013/02/think-python-in-perl-6-chapter-4-interface-design.html" />
    <id>tag:blogs.perl.org,2013:/users/brian_wisti//270.4378</id>

    <published>2013-02-25T02:21:33Z</published>
    <updated>2013-02-25T02:28:09Z</updated>

    <summary>It is time for Chapter 4 of Allen Downey&#8217;s Think Python refashioned in Perl 6. I just needed some time to make a simple wrapper for his Swampy framework. Feel free to install and play along, but don&#8217;t rattle Swampy.pm6...</summary>
    <author>
        <name>Brian Wisti</name>
        <uri>http://coolnamehere.com</uri>
    </author>
    
        <category term="Perl 6" scheme="http://www.sixapart.com/ns/types#category" />
    
    <category term="thinkperl6" label="thinkperl6" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en" xml:base="http://blogs.perl.org/users/brian_wisti/">
        <![CDATA[<p>It is time for Chapter 4 of Allen Downey&#8217;s <a href="http://www.thinkpython.com">Think Python</a> refashioned in Perl 6. I just needed some time to make a <a href="http://blogs.perl.org/users/brian_wisti/2013/02/swampypm6.html">simple wrapper</a> for his <a href="http://www.thinkpython.com/swampy">Swampy</a> framework. Feel free to install and play along, but don&#8217;t rattle Swampy.pm6 too much. I have only implemented enough to finish this chapter.</p>

<p>Then again, go ahead. </p>
]]>
        <![CDATA[<h2>TurtleWorld</h2>

<p>First is <code>mypolygon.pl6</code>, getting the hang of the interface.</p>

<pre><code>use v6;
use Swampy;

my $turtle = make-turtle();
say $turtle;
draw-it();
</code></pre>

<p>Didn&#8217;t actually draw anything, but it did fire up the TurtleWorld display. It even printed out a little bit.</p>

<pre><code>$ perl6 mypolygon.pl6
t1
Python code is in mypolygon.pl6.py
</code></pre>

<p>Here are a couple implementation details for you. The turtle has a simple name: <code>t1</code>. And the Python code associated with <code>mypolygon.pl6</code> will go in <code>mypolygon.pl6.py</code>.</p>

<pre><code>from swampy.TurtleWorld import *

world = TurtleWorld()
t1 = Turtle()

wait_for_user()
</code></pre>

<p><em>Only</em> the Python code relevant to interacting with the swampy library will be written to disk. I expect this means some of the Python code will be tediously long when we get into looping and such. Not concerned about it today. I am amazed it works at all.</p>

<p>Now add the initial sample drawing instructions.</p>

<pre><code>use v6;
use Swampy;

my $bob = make-turtle();
say $bob;

fd($bob, 100);
lt($bob);
fd($bob, 100);

draw-it();
</code></pre>

<p>Run it. Woo! A right angle!</p>

<blockquote>
  <p>Now modify the program to draw a square.</p>
</blockquote>

<p>Okay okay. I already know one way to do this because of my <a href="https://github.com/brianwisti/perl6-swampy">Swampy.pm6</a> adventure.</p>

<pre><code>use v6;
use Swampy;

my $bob = make-turtle();

for 1..4 {
    fd($bob, 100);
    lt($bob);
}

draw-it();
</code></pre>

<p>The book suggestion is pretty much the same. Simple loops over ranges where you ignore the counter.</p>

<pre><code>use v6;

for 1..4 {
    say "Hello!";
}
</code></pre>

<p>Welcome to looping, kids. It doesn&#8217;t look too painful in Perl 6, does it?</p>

<h3>Exercises</h3>

<h4>Exercise 1</h4>

<blockquote>
  <p>Write a function called <code>square</code> that takes a parameter named <code>$t</code>, which is a turtle. It should use the turtle to draw a square.</p>

<p>Write a function call that passes <code>$bob</code> as an argument to <code>square</code>, and then run the program again.</p>
</blockquote>

<p>Stand back. I&#8217;ve got this.</p>

<pre><code>use v6;
use Swampy;

sub square($t) {
    for 1..4 {
        fd($t, 100);
        lt($t);
    }
}

my $bob = make-turtle();
square($bob);
draw-it();
</code></pre>

<h4>Exercise 2</h4>

<blockquote>
  <p>Add another parameter, named <code>$length</code>, to <code>square</code>. Modify the body so length of the sides is <code>$length</code>, and then modify the function call to provide a second argument. Run the program again. Test your program with a range of values for <code>$length</code>.</p>
</blockquote>

<p>Still not too exciting.</p>

<pre><code>use v6;
use Swampy;

sub square($t, $length) {
    for 1..4 {
        fd($t, $length);
        lt($t);
    }
}

my $bob = make-turtle();

square($bob, 50);
square($bob, 75);
square($bob, 100);

draw-it();
</code></pre>

<blockquote>
  <p>The functions <code>lt</code> and <code>rt</code> make 90 degree turns by default, but you can provide a second argument that specifies the number of degrees. For example, <code>lt($bob, 45)</code> turns <code>$bob</code> 45 degrees to the left.</p>

<p>Make a copy of <code>square</code> and change the name to <code>polygon</code>. Add another parameter named <code>$n</code> and modify the body so it draws an n-sided regular polygon. Hint: the exterior angles of an n-sided regular polygon are <em>360/n</em> degrees.</p>
</blockquote>

<p>BRB, updating <a href="https://github.com/brianwisti/perl6-swampy">Swampy.pm6</a>.</p>

<p>Okay, done.</p>

<pre><code># ... 

sub polygon($t, $length, $n) {
    my $angle = 360 / $n;
    for 1..$n {
        fd($t, $length);
        lt($t, $angle);
    }
}

my $bob = make-turtle();

polygon($bob, 20, 8);

draw-it();
</code></pre>

<h4>Exercise 4</h4>

<blockquote>
  <p>Write a function called <code>circle</code> that takes a turtle, <code>$t</code>, and radius, <code>$r</code>, as parameters and that draws an approximate circle by invoking <code>polygon</code> with an appropriate length and number of sides. Test your function with a range of values of <code>$r</code>.</p>

<p>Hint: figure out the circumference of the circle and make sure that <code>$length * $n = $circumference</code>.</p>

<p>Another hint: if <code>$bob</code> is too slow for you, you can speed him up by changing <code>$bob.delay</code>, which is the time between moves, in seconds. <code>$bob.delay = 0.01</code> ought to get him moving.</p>
</blockquote>

<p>Um. That&#8217;s right. <code>$bob</code> is actually an object over in Python land. Well, I&#8217;m not that far in Perl 6 yet. Let me just add a <code>set-delay($t, $delay)</code> sub.</p>

<pre><code># ...
my $pi = 3.1415926;

sub circle($t, $r) {
    my $circumference = 2 * $pi * $r;
    my $n = 30;
    my $length = $circumference / $n;
    polygon($t, $length, $n);
}

my $bob = make-turtle();

set-delay($bob, 0.01);
circle($bob, 100);
circle($bob, 10);
circle($bob, 20);
circle($bob, 80);
circle($bob, 60);

draw-it();
</code></pre>

<p>Well that was fun. And <code>circle.p6.py</code> has 309 lines.</p>

<h4>Exercise 5</h4>

<blockquote>
  <p>Make a more general version of <code>circle</code> called <code>arc</code> that takes an additonal parameter <code>$angle</code>, which determines what fraction of a circle to draw. <code>$angle</code> is in units of degrees, so when <code>$angle=360</code>, <code>arc</code> should draw a complete circle.</p>
</blockquote>

<p>Can&#8217;t just draw a polygon for this one.</p>

<pre><code># ...
sub arc($t, $r, $angle) {
    my $arc-length = 2 * $pi * $r * $angle / 360;
    my $step-count = 30;
    my $step-length = $arc-length / $step-count;
    my $step-angle = $angle / $step-count;

    for 1..$step-count {
        fd($t, $step-length);
        lt($t, $step-angle);
    }
}

my $bob = make-turtle();

set-delay($bob, 0.01);

arc($bob, 10, 90);
arc($bob, 20, 90);
arc($bob, 30, 90);
arc($bob, 40, 90);
arc($bob, 50, 90);
arc($bob, 60, 90);
arc($bob, 70, 90);
arc($bob, 80, 90);
arc($bob, 90, 360);

draw-it();
</code></pre>

<p>Don&#8217;t use a loop. Don&#8217;t use a loop. Don&#8217;t use a loop. When&#8217;s the book going to get to loops?</p>

<h3>Encapsulation</h3>

<p>Nothing fancy. Just talking about how functions can keep your app tidy.</p>

<h3>Generalization</h3>

<p>There&#8217;s a bit in here about keyword arguments. In Perl 6, it looks like you must specify the arguments that accept keywords:</p>

<pre><code>sub polygon($t, :$length, :$n) {
}
</code></pre>

<p>Calling this keyword-enabled <code>polygon</code> looks quite a bit different.</p>

<pre><code>polygon($bob, :length(50), :n(6));
</code></pre>

<p>That will take some getting used to. I am so accustomed to hash-style passing in Perl 5 and Ruby. Still, keyword arguments are quite handy for functions that accept a lot of options. I&#8217;ll want to revisit them later.</p>

<h3>Interface Design</h3>

<p>Fine-tuning the logic of <code>circle</code>.</p>

<pre><code>sub circle($t, $r) {
    my $circumference = 2 * $pi * $r;
    my $n = ($circumference / 3).Int + 1;
    my $length = $circumference / $n;
    polygon($t, $length, $n);
}
</code></pre>

<p>Refactoring <code>polygon</code> into the more general <code>polyline</code>.</p>

<pre><code>sub polyline($t, $n, $length, $angle) {
    for 1..$n {
        fd($t, $length);
        lt($t, $angle);
    }
}
</code></pre>

<p>Changing our shape functions to take advantage of that refactoring.</p>

<pre><code>use v6;
use Swampy;

my $pi = 3.1415926;

sub polyline($t, $n, $length, $angle) {
    for 1..$n {
        fd($t, $length);
        lt($t, $angle);
    }
}

sub polygon($t, $length, $n) {
    my $angle = 360 / $n;
    polyline($t, $n, $length, $angle);
}

sub square($t, $length) {
    polygon($t, $length, 4);
}

sub arc($t, $r, $angle) {
    my $arc-length = 2 * $pi * $r * $angle / 360;
    my $step-count = 30;
    my $step-length = $arc-length / $step-count;
    my $step-angle = $angle / $step-count;
    polyline($t, $step-count, $step-length, $step-angle);
}

sub circle($t, $r) {
    arc($t, $r, 360);
}

my $bob = make-turtle();

set-delay($bob, 0.01);

polyline($bob, 5, 50, 45);
lt($bob, 45);
fd($bob, 100);
polygon($bob, 75, 6);
lt($bob, 45);
square($bob, 100);
lt($bob, 45);
arc($bob, 50, 180);
lt($bob, 45);
circle($bob, 75);
</code></pre>

<h3>A Development Plan</h3>

<p>I&#8217;ve heard of those.</p>

<h3>Docstring</h3>

<p>How about <a href="http://perlcabal.org/syn/S26.html">POD</a>?</p>

<p>I&#8217;ll keep it simple, since <code>p6doc &lt;filename&gt;</code> doesn&#8217;t seem to work as well as <code>perldoc &lt;filename&gt;</code>.</p>

<pre><code>=begin pod

=NAME polygon.p6

=begin DESCRIPTION 

Shape-drawing functions used with Swampy.pm6, written while I read "Think Python"
but write Perl 6.

=end DESCRIPTION

=begin SUBROUTINE C&lt;polyline($t, $n, $length, $angle)&gt;

Draws C&lt;$n&gt; line segements with the given C&lt;$length&gt; and C&lt;$angle&gt;. C&lt;$t&gt; is
a turtle.

=end SUBROUTINE

=end pod
</code></pre>

<p>I don&#8217;t even know. It would probably be better to stick with the POD notation that is more familiar to Perl 5 folks. Then again, this is mostly for my own entertainment.</p>

<h3>Exercises</h3>

<p>For these exercises I pretty much just translated the Python code I already had sitting around into Perl 6.</p>

<h4>Exercise 4-1</h4>

<p>Not much Python-specific here.</p>

<h4>Exercise 4-2</h4>

<blockquote>
  <p>Write an appropriately general set of functions that can draw flowers as in Figure 4.1</p>
</blockquote>

<p>Just dumping everything into <code>polygon.p6</code> because I&#8217;m in a hurry.</p>

<pre><code># ...
sub petal($t, $r, $angle) {
    for 1..2 {
        arc($t, $r, $angle);
        lt($t, 180-$angle);
    }
}

sub flower($t, $n, $r, $angle) {
    for 1..$n {
        petal($t, $r, $angle);
        lt($t, 360/$n);
    }
}

sub move($t, $length) {
    pu($t);
    fd($t, $length);
    pd($t);
}

my $bob = make-turtle();
set-delay($bob, 0.01);

move($bob, -100);
flower($bob, 7, 60, 60);
move($bob, 100);
flower($bob, 10, 40, 80);
move($bob, 100);
flower($bob, 10, 140, 20);
draw-it();
</code></pre>

<h4>Exercise 4-3</h4>

<blockquote>
  <p>Write an appropriately general set of functions that can draw shapes as in Figure 4.2</p>
</blockquote>

<p>This one took me a couple of tries, because I forgot a semi-colon. Somewhere a Pythonista is feeling smug.</p>

<pre><code># ...
sub isosceles($t, $r, $angle) {
    my $y = $r * sin($angle * $pi / 180);

    rt($t, $angle);
    fd($t, $r);

    lt($t, 90+$angle);
    fd($t, 2*$y);

    lt($t, 90+$angle);
    fd($t, $r);

    lt($t, 180-$angle);
}

sub segmented-pie($t, $n, $r) {
    my $angle = 360 / $n;

    for 1..$n {
        isosceles($t, $r, $angle / 2);
        lt($t, $angle);
    }
}

sub draw-pie($t, $n, $r) {
    segmented-pie($t, $n, $r);
    move($t, $r*2 + 10);
}

my $bob = make-turtle();
set-delay($bob, 0.01);

pu($bob);
bk($bob, 130);
pd($bob);

draw-pie($bob, 5, 40);
draw-pie($bob, 6, 40);
draw-pie($bob, 7, 40);
draw-pie($bob, 8, 40);
kill-turtle($bob);
dump-canvas();

draw-it();
</code></pre>

<p>Next is an alphabet exercise. I know it will be fairly time consuming, so I will post what I have so far and come back to finish the chapter when I have the time. Right now there is a Mojolicious project I&#8217;m supposed to be working on for someone.</p>
]]>
    </content>
</entry>

<entry>
    <title>Swampy.pm6</title>
    <link rel="alternate" type="text/html" href="http://blogs.perl.org/users/brian_wisti/2013/02/swampypm6.html" />
    <id>tag:blogs.perl.org,2013:/users/brian_wisti//270.4359</id>

    <published>2013-02-20T14:08:02Z</published>
    <updated>2013-02-20T14:13:24Z</updated>

    <summary>Last night I reached chapter 4 of Think Python, which is full of good old fashioned turtle graphics stuff. It&#8217;s just - well - there&#8217;s a problem. I don&#8217;t think there is a port of the swampy library to Perl...</summary>
    <author>
        <name>Brian Wisti</name>
        <uri>http://coolnamehere.com</uri>
    </author>
    
        <category term="Perl 6" scheme="http://www.sixapart.com/ns/types#category" />
    
    <category term="project" label="project" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en" xml:base="http://blogs.perl.org/users/brian_wisti/">
        <![CDATA[<p>Last night I reached chapter 4 of <a href="http://thinkpython.com">Think Python</a>, which is full of good old fashioned turtle graphics stuff.</p>

<p>It&#8217;s just - well - there&#8217;s a problem. I don&#8217;t think there is a port of the swampy library to Perl 6. I could write one, but that would probably require a Tk interface with Perl 6. Even just writing a Perl 5 Tk version of Swampy is beyond <em>my</em> spare time attention span.</p>

<p>I know what I&#8217;ll do. I&#8217;ll cheat and have <code>perl6</code> call <code>python</code>.</p>
]]>
        <![CDATA[<p>First, I install <a href="http://www.greenteapress.com/thinkpython/swampy/">Swampy</a>. It is available on <a href="http://pypi.python.org/pypi/swampy/2.1.1">PyPi</a>;</p>

<pre><code>$ tar xfvz swampy-2.1.1.tar.gz
$ cd swampy
$ python setup.py build
$ sudo python setup.py install
</code></pre>

<p>If you didn&#8217;t break your <code>pip</code> like I did the other day, you can probably just <code>pip install swampy</code>.</p>

<p>Right now I&#8217;m just shooting for enough to make the first example work. <code>fd</code> and <code>lt</code> need to be implemented, and nothing else.</p>

<pre><code>use v6;

my $turtle = 'turtle';
my @directives;

sub fd($distance) {
    @directives.push("fd($turtle, $distance)");
}

sub lt() {
    @directives.push("lt($turtle)");
}

sub swampy() {
    my $code = @directives.join("\n");

    my $full-code = qq:to/END/;
from swampy.TurtleWorld import *

world = TurtleWorld()
$turtle = Turtle()

$code

wait_for_user()
END

    my $python-file = save-code $full-code;
    say "Python code is in $python-file";
    run-python-with $python-file;
}

sub save-code($code, $name='default.py') {
    my $handle = open $name, :w;
    $handle.say($code);
    $handle.close;

    return $name;
}

sub run-python-with($script) {
    my $python = qx{which python}.chomp;
    my $result = qqx{$python $script}.chomp;

    if $result {
        say "$python output:";
        say $result;
    }
}

fd(100);
lt();
fd(100);
swampy();
</code></pre>

<p>Total cheat. I do one-for-one generation of Python Swampy directives from Perl 6, and when everything is generated I create a Python file and hand that off to <code>python</code>. Despite my good intentions of looking for the default Python interpreter, the odds are good that this will only work on my machine.</p>

<p>Even so, I need to make this a module. I don&#8217;t want to copy and paste all this every time I want to work through a Swampy example in the book. I&#8217;m sticking with a module interface rather than a class so that I can keep the invocation style used in this chapter of Think Python. Also, I&#8217;m not entirely certain that I am ready for Perl 6 classes quite yet. Maybe later.</p>

<p>Rather than bore you with details, I&#8217;ll send the patient reader to <a href="https://github.com/brianwisti/perl6-swampy">perl6-swampy</a>. This is a simple stupid Perl 6 module that can be downloaded, and then installed with <a href="https://github.com/tadzik/panda/">Panda</a>. It probably won&#8217;t stay simple for long, but let&#8217;s hope it stays stupid. I&#8217;m no good with code that&#8217;s smarter than I am.</p>

<p>And then the starter code for Chapter 4?</p>

<pre><code>use v6;

use Swampy;

fd(100);
lt();
fd(100);

draw-it();
</code></pre>

<p>Yes, I have grand ideas for Swampy.pm6, including crazy stuff like documention. And actual functionality. But hey. It works. I can draw a line and turn left, but in <em>Perl 6</em>. Yay me!</p>

<p>All I had to do was cheat.</p>
]]>
    </content>
</entry>

<entry>
    <title>Think Python, But Perl 6 - Chapter 3: Functions</title>
    <link rel="alternate" type="text/html" href="http://blogs.perl.org/users/brian_wisti/2013/02/think-perl6-03.html" />
    <id>tag:blogs.perl.org,2013:/users/brian_wisti//270.4352</id>

    <published>2013-02-19T13:40:09Z</published>
    <updated>2013-02-19T21:47:59Z</updated>

    <summary>On to chapter 3 of Allen B. Downey&apos;s [Think Python](http://www.thinkpython.com) book, as interpreted through Perl 6.</summary>
    <author>
        <name>Brian Wisti</name>
        <uri>http://coolnamehere.com</uri>
    </author>
    
        <category term="Perl 6" scheme="http://www.sixapart.com/ns/types#category" />
    
    <category term="thinkperl6" label="thinkperl6" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en" xml:base="http://blogs.perl.org/users/brian_wisti/">
        <![CDATA[<p>On to chapter 3 of Allen B. Downey's <a href="http://www.thinkpython.com">Think Python</a> book, as interpreted through Perl 6.</p>
]]>
        <![CDATA[<h2>Function Calls</h2>

<p>Looks pretty much the same. Perl 6 function calls don't require parentheses. Use them or don't. If Perl 5 is anything to go by, not using parens will occasionally have surprising results.</p>

<p>We've already used a lot of method calls. Objects are more fundamental in Perl 6 than in Python, and <em>definitely</em> more than Perl 5. A bit more like Ruby.</p>

<h2>Type Conversion</h2>

<p>Python has <code>int(var)</code>, Perl 6 has <code>$var.Int()</code>.</p>

<pre><code>&gt; '32'.Int
32
&gt; 'Hello'.Int
Cannot convert string to number: base-10 number must begin with valid digits or '.' in '⏏Hello' (indicated by ⏏)
</code></pre>

<p><code>Int</code> truncates, not round. We're used to that by now.</p>

<pre><code> &gt; 3.99999.Int
 3
 &gt; -2.3.Int
 -2
</code></pre>

<p><code>Rat</code> converts integers and strings to Rational numbers, but Perl 6 will generally try to do the right thing if you start doing numbery things to a string.</p>

<pre><code>&gt; '32.1' * 2
64.2
</code></pre>

<p>So conversion between numeric types is not important as often in Perl 6.</p>

<h2>Math Functions ... Methods ... Callable things</h2>

<p>At least some of Python's <code>math</code> functionality is core functionality:</p>

<pre><code>&gt; sin(0.7)
0.644217687237691
</code></pre>

<p>... or is is built into the object?</p>

<pre><code>&gt; 0.7.sin
0.644217687237691
</code></pre>

<p>I'm not really sure. Maybe both. Maybe neither. Further study on this is a good idea. And as long as I'm thinking about "further study" I may as well find out whether there's a hardcoded constant for &pi;. Not today though.</p>

<pre><code>&gt; my $pi = 3.1415926;
3.1415926
&gt; my $degrees = 45;
45
&gt; my $radians = $degrees / 360 * 2 * $pi;
0.78539815
&gt; sin $radians;
0.707106771713121
</code></pre>

<p>Checking the result.</p>

<pre><code>&gt; sqrt(2) / 2;
0.707106781186548
</code></pre>

<p>Hm. Really really close, but hm.</p>

<h2>Composition</h2>

<p>They're just talking about composing expressions from others by using functions.</p>

<pre><code>&gt; my $x = sin( $degrees / 360 * 2 * $pi );
0.707106781186584
&gt; $x = exp(log($x + 1));
1.70710678118658
</code></pre>

<p>What does it look like when you try to assign to something that's not okay as an lvalue?</p>

<pre><code>&gt; my $minutes = $hours * 60;
60
&gt; $hours * 60 = $minutes;
Cannot assign to a non-container
</code></pre>

<h2>Adding new functions</h2>

<p>Oh hey. Things started to get interesting.</p>

<pre><code>&gt; sub print-lyrics() {
Unable to parse expression in block; couldn't find final '}'
</code></pre>

<p>Hm. Well that's something to look at for the REPL. Anyways. How about creating the function in a file?</p>

<pre><code>use v6;

sub print-lyrics() {
    say "I'm a lumberjack and I'm okay.";
    say "I sleep all night and I work all day."
}

print-lyrics();
</code></pre>

<p>Okay maybe not <em>that</em> interesting quite yet.</p>

<pre><code>$ perl6 lyrics.p6
I'm a lumberjack and I'm okay.
I sleep all night and I work all day.
</code></pre>

<p>Let's make a simple sub for examining functions.</p>

<pre><code>&gt; sub yo() { say "Yo!" }
sub yo() { ... }
&gt; yo.WHAT
Yo!
</code></pre>

<p>Well that doesn't work. It just calls <code>&amp;yo</code>. Oh right. What happens if I use the sigil?</p>

<pre><code>&gt; &amp;yo.WHAT
Sub()
</code></pre>

<p>Okay. That works.</p>

<p>Using one function inside another is easy.</p>

<pre><code>&gt; sub yo-yo { yo; yo; }
sub yo-yo() { ... }
&gt; yo-yo
Yo!
Yo!
</code></pre>

<h2>Definitions and uses</h2>

<p>Here's the whole program, Perl 6 style.</p>

<pre><code>use v6;

sub print-lyrics() {
    say "I'm a lumberjack and I'm okay.";
    say "I sleep all night and I work all day."
}

sub repeat-lyrics() {
    print-lyrics();
    print-lyrics();
}

repeat-lyrics();
</code></pre>

<h3>Exercise 1</h3>

<blockquote>
  <p>Move the last line of this program to the top, so the function call appears before the definitions. Run the program and see what error message you get.</p>
</blockquote>

<p>No errors. I removed the parens to see if that caused any change.</p>

<pre><code>use v6;

repeat-lyrics;

sub print-lyrics() {
    say "I'm a lumberjack and I'm okay.";
    say "I sleep all night and I work all day."
}

sub repeat-lyrics() {
    print-lyrics;
    print-lyrics;
}
</code></pre>

<p>Nope. It worked smoothly.</p>

<h3>Exercise 2</h3>

<blockquote>
  <p>Move the function call back to the bottom and move the definition of <code>print-lyrics</code> after the definition of <code>repeat-lyrics</code>. What happens when you run this program?</p>
</blockquote>

<p>What happens is that <code>perl6</code> runs it as expected without issue. Nothing to see here.</p>

<h2>Flow of execution</h2>

<p>Bit of common sense advice about following program flow of execution when reading code.</p>

<h2>Parameters and arguments</h2>

<pre><code>use v6;

sub say-twice($bruce) {
    say $bruce;
    say $bruce;
}

say-twice 'Spam';
say-twice 17;
my $pi = 3.1415926539;
say-twice $pi;
</code></pre>

<p>A moment of silence as we enjoy the fact that we can get to function arguments in Perl 6 without unrolling <code>@_</code> or grabbing a module from CPAN. Okay, moment's over.</p>

<pre><code>$ perl6 say-twice.p6
Spam
Spam
17
17
3.1415926539
3.1415926539
</code></pre>

<p>Show that argument is evaluated before being passed to the function.</p>

<pre><code># ...
say-twice 'Spam ' x 4;
</code></pre>

<p>Yep.</p>

<pre><code>...
Spam Spam Spam Spam
Spam Spam Spam Spam
</code></pre>

<h2>Variables and parameters are local</h2>

<p>Variables are available only in their scope.</p>

<pre><code>&gt; sub say-twice($bruce) { say $bruce; say $bruce; }
sub say-twice($bruce) { ... }
&gt; sub cat-twice($part1, $part2) { my $cat = $part1 ~ $part2; say-twice $cat; }
sub cat-twice($part1, $part2) { ... }
&gt; my $line1 = 'Bing tiddle ';
Bing tiddle
&gt; my $line2 = 'tiddle bang.';
tiddle bang.
&gt; cat-twice($line1, $line2);
Bing tiddle tiddle bang.
Bing tiddle tiddle bang.
&gt; say $cat;
Variable $cat is not declared
</code></pre>

<p>Not too surprising there.</p>

<h2>Stack diagrams</h2>

<p>Kind of useful, but the specific example would need to be reworked. Perl 6 catches simple name errors during compilation rather than run time.</p>

<pre><code>&gt; sub say-thrice($bruce) { say $cat }
Variable $cat is not declared
</code></pre>

<h2>Fruitful functions and void functions</h2>

<p>"Fruitful functions" is what the book calls functions with a return value. Again, the specific example works a bit different than in Python.</p>

<pre><code>&gt; my $result = say-twice('Spam')
Spam
Spam
&gt; $result
True
&gt; $result.WHAT
Bool()
</code></pre>

<p><code>say</code> returns a value, <code>say-twice</code> returns the last value generated. In this case, there was no issue. <code>say</code> returned <code>True</code> and so did <code>say-twice</code>.</p>

<h2>Why functions?</h2>

<p>Explaining the utility of functions from a program architecture perspective.</p>

<h2>Importing with <code>from</code></h2>

<p>Hm. It'd be nice to take a moment to think about <code>use</code>, but I'm not sure which modules are okay to import. I'll just leave this one alone for now.</p>

<h2>Exercises</h2>

<h3>Exercise 3</h3>

<blockquote>
  <p>Strings have a method called <code>chars</code> that returns the number of characters in the string, so the value of <code>'Brian'.chars</code> is <code>5</code>.</p>

<p>Write a function named <code>right-justify</code> that takes a string named <code>$s</code> as a parameter and prints the string with enough leading spaces so that the last letter of the string is in column <code>70</code> of the display.</p>
</blockquote>

<pre><code>use v6;
my $name = 'Brian';
say right-justify( $name );

sub right-justify($s) {
    ' ' x (70 - $s.chars) ~ $s;
}
</code></pre>

<h3>Exercise 4</h3>

<blockquote>
  <p>A function object is a value you can assign to a variable or pass as an argument. For example, <code>do-twice</code> is a function that takes a function object as an argument and calls it twice:</p>
</blockquote>

<pre><code>use v6;

sub do-twice(&amp;f) {
    f();
    f();
}
</code></pre>

<p>Here's an example that uses <code>do-twice</code> to call a function named <code>say-spam</code> twice:</p>

<pre><code>sub say-spam() {
    say 'spam';
}

do-twice(&amp;say-spam);
</code></pre>

<ol>
<li>Type this example into a script and test it.</li>
<li>Modify <code>do-twice</code> so that it takes two arguments, a function and a value, and calls the function twice, passing the value as an argument.</li>
<li>Write a more general version of <code>say-spam</code>, called <code>say-twice</code>, that takes a string as a parameter and prints it twice.</li>
<li>Use the modified version of <code>do-twice</code> to call <code>say-twice</code> twice, passing <code>'spam'</code> as an argument.</li>
<li>Define a new function called <code>do-four</code> that takes a function and a value and calls the function four times, passing the value as a parameter. There should be only two statements in the body of this function, not four.</li>
</ol>

<h4>Exercise 4-2</h4>

<pre><code>use v6;

sub do-twice(&amp;f, $arg) {
    f($arg);
    f($arg);
}

sub uc-it($s) {
    say $s.uc;
}

do-twice(&amp;uc-it, 'spam');
</code></pre>

<h4>Exercise 4-3 and 4-4</h4>

<pre><code>use v6;

sub do-twice(&amp;f, $arg) {
    f($arg);
    f($arg);
}

sub say-twice($s) {
    say $s;
    say $s;
}

do-twice(&amp;say-twice, 'spam');
</code></pre>

<h4>Exercise 4-5</h4>

<pre><code>use v6;

sub do-twice(&amp;f, $arg) {
    f($arg);
    f($arg);
}

sub do-four(&amp;f, $arg) {
    do-twice(&amp;f, $arg);
    do-twice(&amp;f, $arg);
}

sub say-twice($s) {
    say $s;
    say $s;
}

do-four(&amp;say-twice, 'spam');
</code></pre>

<h3>Exercise 5</h3>

<blockquote>
  <p>This exercise can be done using only the statements and other features we have learned so far.</p>

<p>Write a function that draws a grid like the following:</p>
</blockquote>

<pre><code>+ - - - - + - - - - +
|         |         |
|         |         |
|         |         |
|         |         |
+ - - - - + - - - - +
|         |         |
|         |         |
|         |         |
|         |         |
+ - - - - + - - - - +
</code></pre>

<blockquote>
  <p>Write a function that draws a similar grid with four rows and four columns.</p>
</blockquote>

<h4>Exercise 5-1</h4>

<p>The challenge in these exercises is <em>not</em> using the basic language structures I'm already familiar with.</p>

<pre><code>use v6;

sub do-twice(&amp;f) {
    f();
    f();
}

sub do-four(&amp;f) {
    do-twice(&amp;f);
    do-twice(&amp;f);
}

sub draw-intersection() {
    print "+ ";
}

sub draw-row-edge() {
    print "- ";
}

sub draw-cell-row-edge() {
    draw-intersection();
    do-four(&amp;draw-row-edge);
}

sub end-line() {
    say;
}

sub draw-grid-row-edge() {
    do-twice(&amp;draw-cell-row-edge);
    draw-intersection();
    end-line();
}

sub draw-column-edge() {
    print "| ";
}

sub draw-cell-space() {
    print "  ";
}

sub draw-cell-spaces() {
    draw-column-edge();
    do-four(&amp;draw-cell-space);
}

sub draw-grid-spaces() {
    do-twice(&amp;draw-cell-spaces);
    draw-column-edge();
    end-line();
}

sub draw-cell-row() {
    draw-grid-row-edge();
    do-four(&amp;draw-grid-spaces);
}

sub draw-grid() {
    do-twice(&amp;draw-cell-row);
    draw-grid-row-edge();
}

draw-grid();
</code></pre>

<h3>Exercise 5-2</h3>

<blockquote>
  <p>Write a function that draws a similar grid with four rows and four columsn.</p>
</blockquote>

<p>I refactored a little bit, but I'm not sure it was actually helpful with the limited toolkit (general programming, not Perl 6) allowed for the reader at this point.</p>

<pre><code>use v6;

sub do-twice(&amp;f) {
    f();
    f();
}

sub do-four(&amp;f) {
    do-twice(&amp;f);
    do-twice(&amp;f);
}

sub do-one-four(&amp;first, &amp;second) {
    first();
    do-four(&amp;second);
}

sub draw-intersection() {
    print "+ ";
}

sub draw-row-edge() {
    print "- ";
}

sub draw-cell-row-edge() {
    do-one-four(&amp;draw-intersection, &amp;draw-row-edge);
}

sub end-line() {
    say;
}

sub draw-grid-row-edge() {
    do-twice(&amp;draw-cell-row-edge);
    draw-intersection();
    end-line();
}

sub draw-column-edge() {
    print "| ";
}

sub draw-cell-space() {
    print "  ";
}

sub draw-cell-spaces() {
    do-one-four(&amp;draw-column-edge, &amp;draw-cell-space);
}

sub draw-grid-spaces() {
    do-twice(&amp;draw-cell-spaces);
    draw-column-edge();
    end-line();
}

sub draw-cell-row() {
    do-one-four(&amp;draw-grid-row-edge, &amp;draw-grid-spaces);
}

sub draw-two-grid() {
    do-twice(&amp;draw-cell-row);
    draw-grid-row-edge();
}

sub draw-four-edge() {
    do-four(&amp;draw-cell-row-edge);
    draw-intersection();
    end-line();
}

sub draw-four-spaces() {
    do-four(&amp;draw-cell-spaces);
    draw-column-edge();
    end-line();
}

sub draw-four-row() {
    do-one-four(&amp;draw-row-edge, &amp;draw-four-spaces);
}

sub draw-four-grid() {
    do-four(&amp;draw-four-row);
    draw-four-edge();
}

draw-four-grid();
</code></pre>
]]>
    </content>
</entry>

<entry>
    <title>Think Perl6-ish Variables, Expressions, and Statements</title>
    <link rel="alternate" type="text/html" href="http://blogs.perl.org/users/brian_wisti/2013/02/think-perl6-02.html" />
    <id>tag:blogs.perl.org,2013:/users/brian_wisti//270.4348</id>

    <published>2013-02-18T19:44:12Z</published>
    <updated>2013-02-19T15:27:26Z</updated>

    <summary>Continuing the Perl 6 adventures with Allen B. Downey&apos;s Think Python book....</summary>
    <author>
        <name>Brian Wisti</name>
        <uri>http://coolnamehere.com</uri>
    </author>
    
        <category term="Perl 6" scheme="http://www.sixapart.com/ns/types#category" />
    
    <category term="thinkperl6" label="thinkperl6" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en" xml:base="http://blogs.perl.org/users/brian_wisti/">
        <![CDATA[<p>Continuing the Perl 6 adventures with Allen B. Downey's <a href="http://www.thinkpython.com">Think Python</a> book.</p>
]]>
        <![CDATA[<h2><a href="http://www.greenteapress.com/thinkpython/html/thinkpython003.html">Chapter 2</a></h2>

<p>Maybe a brief bit about objects in Chapter 1 would be appropriate, because Perl 6 lets you query an object directly about the type associated with a value.</p>

<pre><code>&gt; 'Hello, World!'.WHAT
Str()
&gt; 17.WHAT
Int()
&gt; 3.2.WHAT
Rat()
</code></pre>

<p>Strings that have numbers are still strings by default.</p>

<pre><code>&gt; '17'.WHAT
Str()
&gt; '3.2'.WHAT
Str()
</code></pre>

<p>Commas make lists.</p>

<pre><code>&gt; 1,000,000
1 0 0
</code></pre>

<p>Variables need to be declared - <code>my</code> is a favorite.</p>

<pre><code>&gt; $message = 'And now for something completely different'
Variable $message is not declared
&gt; my $message = 'And now for something completely different'
And now for something completely different
</code></pre>

<p>Simple string and number variables are prefixed with <code>$</code>. Perl 6 looks at "type" in at least two ways: the type of a value (<code>Str</code>, <code>Int</code>, <code>Rat</code>, and so on) and the type of the variable that holds the value. For now, just remind folks to declare variables with <code>my</code> and use <code>$</code> sigil for the variables they're working with at this point.</p>

<pre><code>&gt; my $n = 17;
17
&gt; my $pi = 3.1415926535897932
3.1415926535897932
</code></pre>

<p>You can ask a variable what type of value it is holding right now using <code>WHAT</code>.</p>

<pre><code>&gt; $message.WHAT
Str()
&gt; $n.WHAT
Int()
&gt; $pi.WHAT
Rat()
</code></pre>

<h4>Exercise 1</h4>

<p>Perl 6 doesn't actually care about leading zero in a value ordinarily. Caveats about literals in other languages don't apply here, except to remind folks about the difference between <code>Int</code> and <code>Str</code>.</p>

<pre><code>&gt; my $zipcode = 02492;
2492
&gt; $zipcode = '02492';
02492
</code></pre>

<p>Rules for variable names are similar to Python and other languages, though that sigil means reserved names aren't such a big deal.</p>

<pre><code>&gt; my $76trombones = 'big parade';
Cannot declare a numeric variable
&gt; my $more@ = 1000000
Two terms in a row
&gt; my $class = 'Advanced Theoretical Zymurgy'
Advanced Theoretical Zymurgy
</code></pre>

<p>Note that Perl 6 errors are more descriptive than the infamous "SyntaxError: invalid syntax" of Python.</p>

<p>Oh, and Perl 6 allows <code>-</code> in variable names.</p>

<pre><code>&gt; my $class-name = 'Advanced Theoretical Zymurgy';
Advanced Theoretical Zymurgy
</code></pre>

<p>Perl 6 does not do floor division by default. It will convert <code>Int</code> to <code>Rat</code> as needed for an operation.</p>

<pre><code>&gt; my $minute = 59
59
&gt; $minute / 60
0.983333
</code></pre>

<p>Use <code>say</code> - remember <code>say</code>? - to get output when running a Perl 6 program as opposed to the interactive shell. </p>

<pre><code>my $miles = 26.2
say $miles * 1.61
</code></pre>

<p>Run it.</p>

<pre><code>$ perl6 sample-01.p6
===SORRY!===
Two terms in a row
at sample-01.p6:2
------&gt; &lt;BOL&gt;⏏say $miles * 1.61
    expecting any of:
        postfix
        infix or meta-infix
        infix stopper
        statement end
        statement modifier
        statement modifier loop
</code></pre>

<p>Yeah. Better start using semicolons now. Probably should've been using semicolons from the beginning, but I was being lazy. Speaking of lazy, I just noticed that <code>perl6</code> doesn't seem to require the <code>use v6</code> pragma. Still, good form is important. </p>

<pre><code>use v6;
my $miles = 26.2;
say $miles * 1.61;
</code></pre>

<p>Run it.</p>

<pre><code>$ perl6 sample-01.p6
42.182
</code></pre>

<p>That's better.</p>

<p>Assignment lines don't produce output when running outside the REPL.</p>

<pre><code>use v6;
say 1;
my $x = 2;
say $x;
</code></pre>

<p>See?</p>

<pre><code>$ perl6 sample-02.p6
1
2
</code></pre>

<h4>Exercise 2</h4>

<p>Type the following statements in the Perl 6 interpreter to see what they do:</p>

<pre><code>5;
my $x = 5;
$x + 1;
</code></pre>

<p>Now put the same statements into a script and run it. What is the output? Modify the script by transforming each expression into a <code>say</code> statement and then run it again.</p>

<pre><code>say 5;
my $x = 5;
say $x + 1;
</code></pre>

<h3>Order of Operations</h3>

<p>No huge difference here for simple operations. PEMDAS. When in doubt, use parens.</p>

<h3>String Operations</h3>

<p>Remember that Perl 6 is still Perl.</p>

<pre><code>&gt; '2' - 1'
1
&gt; 'eggs' / 'easy'
Cannot convert string to number: base-10 number must begin with valid digits or '.' in '⏏eggs' (indicated by ⏏)
</code></pre>

<p>Well, almost.</p>

<p>Python concatenates strings with <code>+</code>. Perl 6 concatenates strings with <code>~</code>.</p>

<pre><code>my $first = 'throat';
my $second = 'warbler';
say $first ~ $second; # says 'throatwarbler'
</code></pre>

<p>Python does string repetition with <code>*</code>. Perl 6 does string repetition with <code>x</code>.</p>

<pre><code>&gt; 'spam' x 3
spamspamspam
</code></pre>

<h3>Comments</h3>

<pre><code># This is a line comment, same as in loads of other languages.
</code></pre>

<h3>Debugging</h3>

<p>Perl 6 error messages are fairly helpful.</p>

<pre><code>&gt; my $bad name = 5;
Two terms in a row
</code></pre>

<p>Typos are a common source of errors when caffeine passes the critical threshold. Here is one of the more common typo errors: misspelling a variable name.</p>

<pre><code>&gt; my $principal = 327.68;
327.68
&gt; my $interest = $principle * $rate;
Variable $principle is not declared
</code></pre>

<h3>Exercises</h3>

<h4>Exercise 3</h4>

<p>Assume that we execute the following assignment statements:</p>

<pre><code>my $width = 17;
my $height = 12.0;
my $delimiter = '.';
</code></pre>

<p>For each of the following expressions, write the value of the expression and the type (of the value of the expression).</p>

<ol>
<li><code>$width / 2</code> = <code>8.5</code> = <code>Rat()</code></li>
<li><code>$width / 2.0</code> = <code>8.5</code> = <code>Rat()</code> <em>Perl 6 just don't care about floor division</em></li>
<li><code>$height / 3</code> = <code>4</code> = <code>Rat()</code> <em>Looks like an <code>Int</code> but it's a <code>Rat</code></em></li>
<li><code>1 + 2 * 5</code> = <code>11</code></li>
<li><code>$delimiter x 5</code> = <code>.....</code></li>
</ol>

<p>Use the Perl 6 interpreter to check your answers.</p>

<h4>Exercise 4</h4>

<p>Practice using the Perl 6 interpreter as a calculator:</p>

<blockquote>
  <p>Volume of a sphere w/radius <code>r</code> is 4/3&pi;r<sup>3</sup>. What is the volume of a sphere with radius <code>5</code>? <em>Python hint doesn't apply.</em> </p>
</blockquote>

<p>One solution</p>

<pre><code> use v6;
 my $radius = 5;
 my $PI = 3.1415926;
 my $area = 4/3 * $pi * $radius**3;
 say $area;
</code></pre>

<p>It works.</p>

<blockquote>
  <p>book cover prices is $24.95, bookstores get 40% discount. Shipping is $3 for first copy and 75 cents per additional copy. What's the total wholesale cost for 60 copies?</p>
</blockquote>

<p>Just your basic calculator solution:</p>

<pre><code> &gt; 24.95 * 0.6 * 60 + 0.75 * (60 - 1) + 3
 945.45
</code></pre>

<p>I had to break the next one down carefully, as I am a bear of very small brain.</p>

<blockquote>
  <p>If I leave my house at 6:52 am and run 1 mile at an easy pace (8:15 per mile), then 3 miles at tempo (7:12 per mile) and 1 mile at easy pace again, what time do I get home for breakfast?</p>
</blockquote>

<p>I am willing to bet good money that my solution is more verbose than it needs to be.</p>

<pre><code>use v6;

my $minute = 60;
my $hour = $minute * 60;

# Turn start time to seconds after midnight
my $start-time = (6 * 60 + 52) * 60;
my $easy-pace  = 8 * 60 + 15;
my $tempo-pace = 7 * 60 + 12;
my $running-time = $easy-pace + 3 * $tempo-pace + $easy-pace;
# Find finish time as seconds after midnight
my $finish-time = $start-time + $running-time;

# Convert finish time to a clock time, first in hours:
my $finish-hour = ($finish-time / $hour).Int;
# ... then the seconds left over, expressed as minutes.
my $finish-minute = ($finish-time % $hour / 60).Int;

say "Finish time was $finish-hour:$finish-minute";
</code></pre>

<p>That gave me:</p>

<pre><code>$ perl6 jogging.p6
Finish time was 7:30
</code></pre>
]]>
    </content>
</entry>

<entry>
    <title><![CDATA[(my $title = "Think Python") ~~ s/Python/Perl 6/ && $title.say;]]></title>
    <link rel="alternate" type="text/html" href="http://blogs.perl.org/users/brian_wisti/2013/02/think-perl6-01.html" />
    <id>tag:blogs.perl.org,2013:/users/brian_wisti//270.4347</id>

    <published>2013-02-18T17:56:57Z</published>
    <updated>2013-02-19T15:28:32Z</updated>

    <summary>I&apos;m rereading Allen B. Downey&apos;s Think Python, but this time with an eye for writing the equivalent code in Perl 6. I am not sure how deep I&apos;ll dig into this, as I am limited by spare time and tools...</summary>
    <author>
        <name>Brian Wisti</name>
        <uri>http://coolnamehere.com</uri>
    </author>
    
        <category term="Perl 6" scheme="http://www.sixapart.com/ns/types#category" />
    
    <category term="thinkperl6" label="thinkperl6" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en" xml:base="http://blogs.perl.org/users/brian_wisti/">
        <![CDATA[<p>I'm rereading Allen B. Downey's <a href="http://www.thinkpython.com">Think Python</a>, but this time with an eye for writing the equivalent code in Perl 6. I am not sure how deep I'll dig into this, as I am limited by spare time and tools from the book like Swampy would have to be made accessible to Perl 6 somehow. BTW, <em>Think Python</em> is available under a <a href="http://creativecommons.org/licenses/by-nc/3.0/">CC-by-nc 3.0</a> license.</p>

<p>Just using this space as a public scratchpad at the moment. I've got <code>$RAKUDO_HOME/install/bin</code> on my path to simplify things.</p>

<pre><code>$ perl6 --version
This is perl6 version 2012.12 built on parrot 4.10.0 revision 0
</code></pre>
]]>
        <![CDATA[<h2><a href="http://www.greenteapress.com/thinkpython/html/thinkpython002.html">Chapter 1</a></h2>

<p>Mostly an explanation of how computer programs work, and bits about the difference between high level and low level languages. Only one actual code sample.</p>

<p>Invoking <code>perl6</code> without any arguments will start the REPL, shell, interactive mode (call it what you will).</p>

<pre><code>$ perl6
&gt;
</code></pre>

<p>Default presentation is a single chevron for user code, and no decoration for output:</p>

<pre><code>&gt; 1 + 1
2
</code></pre>

<h3>The First Program</h3>

<p><code>say</code> covers the print-with-newline angle. We can use it with or without parentheses.</p>

<pre><code>&gt; say 'Hello, world!';
Hello, world!
&gt; say('Hello, world!');
Hello, world!
</code></pre>

<p>But <code>say</code> is also a method attached to objects. Perl 6 literals are objects, too.</p>

<pre><code>&gt; 'Hello, world!'.say;
Hello, world!
</code></pre>

<p>Of course, this could lead you down the rabbit hole of explaining objects and literals when the chapter is mostly about "what the heck is a program?" and "how do I get <code>perl6</code> to do stuff?"</p>

<h3>Exercises</h3>

<p>If I were actually writing <em>Think Perl 6</em>, the Chapter 1 Exercises would look something like this.</p>

<ol>
<li>Go to the <a href="http://perl6.org">Perl 6</a> website. This page contains information about Perl 6 and links to pages related to Perl 6. You can also browse a wealth of documentation about Perl 6. <em>not so much on the searching, though</em></li>
<li><em>It doesn't appear that the <code>perl6</code> REPL includes a built-in help tool, and the POD does not yet have a <code>perl6toc</code> which ties all the installed documentation together. Best to suggest the <a href="http://doc.perl6.org/">doc index</a> for now.</em></li>
<li>Start the <code>perl6</code> interpreter and use it as a calculator. The Perl 6 syntax for math operations is almost the same as standard mathematical notation</li>
</ol>

<p><em>filler line inserted to make Markdown happy</em> </p>

<pre><code>  &gt; 10 / 1.61 # Convert km to miles
  6.211180
  &gt; (43 * 60) + 30 # Convert time to seconds
  2610
  &gt; 2610 / 6.211180 # Average time per mile, in seconds
  420.2100084
  &gt; 420.2100084 / 60 # Average time per mile, in minutes
  7.00350014
  &gt; 60 / 7.00350014 # Miles per hour
  8.5671448277
</code></pre>

<p>All this to show that <code>perl6</code> as a calculator works about the same as <code>python</code> as a calculator, though if you compare to <a href="http://en.wikibooks.org/wiki/Think_Python/Answers#Exercise_1.4">one solution</a> you'll see a difference in the number of significant digits.</p>

<p>I actually have notes for Chapter 2, but my compulsion to begin at the beginning means that this is all I have time for today.</p>

<p><em>Looks like I made it through <a href="http://blogs.perl.org/users/brian_wisti/2013/02/think-perl6-02.html">Chapter 2</a></em></p>
]]>
    </content>
</entry>

<entry>
    <title>My Main Perl5 Project Is Also My Main Parrot Project</title>
    <link rel="alternate" type="text/html" href="http://blogs.perl.org/users/brian_wisti/2011/05/my-main-perl5-project-is-also-my-main-parrot-project.html" />
    <id>tag:blogs.perl.org,2011:/users/brian_wisti//270.1770</id>

    <published>2011-05-16T18:49:21Z</published>
    <updated>2011-05-16T18:55:59Z</updated>

    <summary>I&apos;ve been trying to find time to work on parrot-handler, a parrot management tool in the spirit of perlbrew and rvm, for several months now. It&apos;s written in Perl 5, and could be very useful indeed. I&apos;ve just been so...</summary>
    <author>
        <name>Brian Wisti</name>
        <uri>http://coolnamehere.com</uri>
    </author>
    
        <category term="Parrot" scheme="http://www.sixapart.com/ns/types#category" />
    
        <category term="Perl" scheme="http://www.sixapart.com/ns/types#category" />
    
    
    <content type="html" xml:lang="en" xml:base="http://blogs.perl.org/users/brian_wisti/">
        <![CDATA[<p>I've been trying to find time to work on <a href="https://github.com/brianwisti/parrot-handler">parrot-handler</a>, a parrot management tool in the spirit of <a href="http://search.cpan.org/~gugod/App-perlbrew/lib/App/perlbrew.pm">perlbrew </a>and <a href="https://rvm.beginrescueend.com/">rvm</a>, for several months now. It's written in Perl 5, and could be very useful indeed. I've just been so busy ...</p>

<p>Well, okay. I've been busy playing World of Warcraft, dabbling with languages that are not based on Parrot, and messing about with my laptop. Oh, and doing work stuff. Still, that's kind of busy.</p>

<p>But there are some Parrot things that I'd like to do, and a working parrot-handler could make those things easier. I think maybe a little less WoW and a little more code tonight.</p>]]>
        
    </content>
</entry>

<entry>
    <title>Oh hey</title>
    <link rel="alternate" type="text/html" href="http://blogs.perl.org/users/brian_wisti/2011/05/oh-hey.html" />
    <id>tag:blogs.perl.org,2011:/users/brian_wisti//270.1728</id>

    <published>2011-05-03T20:09:46Z</published>
    <updated>2011-05-03T20:21:58Z</updated>

    <summary>So it&apos;s been over a year since I posted anything here. I&apos;ve been working on Perl code at a big company, and I&apos;ve mostly been enjoying myself. It&apos;s not easy diving into a large legacy application, especially when you have...</summary>
    <author>
        <name>Brian Wisti</name>
        <uri>http://coolnamehere.com</uri>
    </author>
    
        <category term="Meditations" scheme="http://www.sixapart.com/ns/types#category" />
    
    
    <content type="html" xml:lang="en" xml:base="http://blogs.perl.org/users/brian_wisti/">
        <![CDATA[<p>So it's been over a year since I posted anything here. I've been working on Perl code at a big company, and I've mostly been enjoying myself. It's not easy diving into a large legacy application, especially when you have strong opinions about legacy code. But there are plenty of crunchy problems to sort through.</p>

<p>I'm thinking about dumping more random Perlish thoughts here. My Perl world includes Parrot and Rakudo, so some connections may be tangential at best.</p>
]]>
        

    </content>
</entry>

<entry>
    <title>No Bad Code</title>
    <link rel="alternate" type="text/html" href="http://blogs.perl.org/users/brian_wisti/2010/03/no-bad-code.html" />
    <id>tag:blogs.perl.org,2010:/users/brian_wisti//270.367</id>

    <published>2010-03-15T21:38:40Z</published>
    <updated>2010-03-16T17:23:07Z</updated>

    <summary>I am not using Perl at work. I don&apos;t know when I will next get a job that gives me the opportunity to use Perl. That&apos;s too bad, because I really enjoy working with good Perl code. Notice that I...</summary>
    <author>
        <name>Brian Wisti</name>
        <uri>http://coolnamehere.com</uri>
    </author>
    
        <category term="Meditations" scheme="http://www.sixapart.com/ns/types#category" />
    
    <category term="perl" label="perl" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en" xml:base="http://blogs.perl.org/users/brian_wisti/">
        <![CDATA[<p>I am not using Perl at work. I don't know when I will next get a job that gives me the opportunity to use Perl. That's too bad, because I really enjoy working with good Perl code. Notice that I specified <em>good</em> Perl. Unfortunately, a lot of the legacy code that I've seen is bad - painfully bad, even. There's no point in blaming anyone. Bad code happens. We get in a hurry, we push out a quick hack. Maybe we try some clever trick in a production project before we truly understand the ramifications of that trick. Plenty of bad code has come from my own overstressed brain.</p>

<p>Maybe it's unfair to call it "bad code." It was a result of stress, enthusiasm, or simple ignorance. When I have an outlet for all that energy, my code improves. It shines. It doesn't piddle all over the carpet. </p>

<p><a href="http://coolnamehere.com">coolnamehere</a> has occasionally served as that outlet, but over the years it has gelled into a tutorial site. It has a specific audience: novice developers who are curious but nervous. It has served that audience well, based on the feedback I get. However, this focus has a cost. Whenever I'm writing something new for coolnamehere, I have to think about my audience. I need to decide if the material is appropriate for them, and figure out ways of presenting it which sweep complexities under the carpet. My own coding skills have atrophied a little as a result. My Perl coding skills have dropped significantly, because I am confident that the best writing about Perl has been written already, or <a href="http://modernperlbooks.com">is being written</a> by people much more skillful than myself at both coding and writing.</p>

<p>So here I am. A geek - largely a Perl geek - who has not written more than a few lines of Perl code in a couple of years. What to do?</p>

<p>That is why I signed up for this blog. This will be my outlet to play with big Perl projects with <a href="http://www.catalystframework.org/">big frameworks</a>, <a href="http://minimalperl.com">little Perl tasks</a>, and <a href="http://hop.perl.plover.com/">sideways Perl exploration</a>. It will have no focus beyond Perl. Wait. That's a bit of a lie, because "Perl" includes <a href="http://perl.org">Perl 5</a>, <a href="http://parrot.org">Parrot</a>, <a href="http://rakudo.org">Rakudo</a>, and <a href="http://parrot.org/languages">much more</a>. It could even include environment optimizations to make my life as a Perl/Parrot/etc. geek simpler. I'll write about those. Maybe if I can rattle the bits of a few blog entries together, I can come up with more tutorial material for the Perl and Parrot pages at coolnamehere.</p>

<p>Why here rather than continuing on at <a href="http://brianwisti.blogspot.com">Blogspot</a>? It boils down to the community. I have always found the Perl community to be especially supportive and encouraging. <a href="http://seattleperl.org">SPUG</a> and <a href="http://perlmonks.org">PerlMonks</a> are great groups to associate with, even if I mostly just lurk. I have a strong suspicion that the <a href="http://blogs.perl.org">Perl Blogs</a> will be a welcome extension to that community.</p>

<p>Well, I need to get busy with not-Perl stuff at <code>$work</code>. But at least I have a clear idea why I signed up here, and what I plan to do with this blog in my copious free time. I'm gonna do Perl stuff, write about it, and not worry about whether it would make a good tutorial.</p>
]]>
        

    </content>
</entry>

<entry>
    <title>Because I haven&apos;t neglected enough blogs</title>
    <link rel="alternate" type="text/html" href="http://blogs.perl.org/users/brian_wisti/2010/03/because-i-havent-neglected-enough-blogs.html" />
    <id>tag:blogs.perl.org,2010:/users/brian_wisti//270.362</id>

    <published>2010-03-15T06:12:47Z</published>
    <updated>2010-03-15T06:25:18Z</updated>

    <summary>I&apos;ve been thinking that a code journal of some kind would be nice. You know, the stuff that doesn&apos;t matter enough to spend days agonizing over whether I&apos;m being too advanced or too simplistic. My other blog is okay, but...</summary>
    <author>
        <name>Brian Wisti</name>
        <uri>http://coolnamehere.com</uri>
    </author>
    
    
    <content type="html" xml:lang="en" xml:base="http://blogs.perl.org/users/brian_wisti/">
        <![CDATA[<p>I've been thinking that a code journal of some kind would be nice. You know, the stuff that doesn't matter enough to spend days agonizing over whether I'm being too advanced or too simplistic. My <a href="http://brianwisti.blogspot.com">other blog</a> is okay, but I like the MT interface.</p>

<p>Why blogs.perl.org? I realize it may not be cool to say in some crowds, but I like Perl, Parrot, and Rakudo. This site seems like an excellent place to write about writing in those environments.</p>

<p>So, we'll see what happens.</p>]]>
        
    </content>
</entry>

</feed>
