<?xml version="1.0" encoding="UTF-8"?>

<rss version="2.0"
 xmlns:blogChannel="http://backend.userland.com/blogChannelModule"
 xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#"
 xmlns:content="http://purl.org/rss/1.0/modules/content/"
 xmlns:atom="http://www.w3.org/2005/Atom"
 xmlns:dcterms="http://purl.org/dc/terms/"
>

<channel>
<title></title>
<link>http://www.shlomifish.org/me/blogs/</link>
<description></description>

<item>
<title>A Perl-based &#x2192;with(...) method</title>
<link>http://community.livejournal.com/shlomif_tech/46303.html</link>
<description>&#x3C;p&#x3E;
Lately, I&#x27;ve been writing some &#x3C;a href=&#x22;http://pdl.perl.org/&#x22;&#x3E;PDL (Perl Data
Language)&#x3C;/a&#x3E; code and noticed that I&#x27;ve been doing the following:
&#x3C;/p&#x3E;

&#x3C;pre&#x3E;
my $temp_pdl = $pdl-&#x26;gt;&#x2026;-&#x26;gt;final_expr();
my $result_pdl = $temp_pdl-&#x26;gt;where($temp_pdl &#x26;lt; 0);
&#x3C;/pre&#x3E;

&#x3C;p&#x3E;
I&#x27;ve been thinking if I could somehow write it like that:
&#x3C;/p&#x3E;

&#x3C;pre&#x3E;
my $result_pdl = $pdl-&#x26;gt;&#x2026;-&#x26;gt;final_expr()-&#x26;gt;with(sub { $_-&#x26;gt;where($_ &#x26;gt; 0)});
&#x3C;/pre&#x3E;

&#x3C;p&#x3E;
Which seems cleaner and more elegant. I went on IRC asking about it and someone
suggested 
&#x3C;tt&#x3E;rindolf: (sub { local $_ = shift; $_ * $_ * $_})-gt;( $obj-&#x26;gt;... );&#x3C;/tt&#x3E; 
(up to an episolon, but naturally this reverses the order and messes with
the flow of the code). Eventually 
&#x3C;a href=&#x22;http://www.shadowcat.co.uk/blog/matt-s-trout/&#x22;&#x3E;Matt S. 
Trout (mst)&#x3C;/a&#x3E; proposed the following solutions:
&#x3C;/p&#x3E;

&#x3C;pre&#x3E;
sub UNIVERSAL::with
{
    local $_ = shift;
    my $sub = shift;
    return $sub-&#x26;gt;($_,@_);
}

my $_with = sub {
    local $_ = shift;
    my $sub = shift;
    return $sub-&#x26;gt;($_,@_);
};

&#x3C;/pre&#x3E;

&#x3C;p&#x3E;
(I had figured something like that was possible previously, but I was beating
around the bush.)
&#x3C;/p&#x3E;

&#x3C;p&#x3E;
The $_with approach is covered in &#x3C;a href=&#x22;http://www.shadowcat.co.uk/blog/matt-s-trout/madness-with-methods/&#x22;&#x3E;one of Matt&#x27;s blog posts titled &#x22;Madness with
Methods&#x22;&#x3C;/a&#x3E;.
&#x3C;/p&#x3E;

&#x3C;p&#x3E;
I wondered if it will work with 
&#x3C;a href=&#x22;http://search.cpan.org/dist/autobox/&#x22;&#x3E;autobox&#x3C;/a&#x3E; and mst said that
&#x3C;q&#x3E;I don&#x27;t know and I hope not since the UNIVERSAL approach is evil.&#x3C;/q&#x3E;. But
it does, out-of-the-box:
&#x3C;/p&#x3E;

&#x3C;pre&#x3E;
#!/usr/bin/perl

use strict;
use warnings;

use autobox;

sub UNIVERSAL::with
{
    local $_ = shift;
    my $sub = shift;
    return $sub-&#x26;gt;($_,@_);
}

my $_with = sub {
    local $_ = shift;
    my $sub = shift;
    return $sub-&#x26;gt;($_,@_);
};

print +(10+1)-&#x26;gt;with(sub { $_ * $_; }), &#x26;quot;\n&#x26;quot;;
print +(10+1)-&#x26;gt;$_with(sub { $_ * $_; }), &#x26;quot;\n&#x26;quot;;
&#x3C;/pre&#x3E;

&#x3C;p&#x3E;
This prints 121 twice.
&#x3C;/p&#x3E;

&#x3C;p&#x3E;
I now wonder what to do with this knowledge. I have some aspirations of
releasing it to the cpan as a mini-module. Still, it&#x27;s really cool.
&#x3C;/p&#x3E;

&#x3C;p&#x3E;
Finally, I should note that it seems like I&#x27;m going to lose my current
Planet Perl Iron Man karma due to inadequate blogging. Oh well.
&#x3C;/p&#x3E;</description>
<author>Shlomi Fish ( shlomif@iglu.org.il )</author>
<category>perl</category>
<category>fun</category>
<comments>http://community.livejournal.com/shlomif_tech/46303.html</comments>
<guid isPermaLink="true">http://community.livejournal.com/shlomif_tech/46303.html</guid>
<pubDate>Mon, 01 Mar 2010 17:22:55 GMT</pubDate>
</item>
<item>
<title>New Perl Quiz-of-the-Whatever: Short Freecell Solutions</title>
<link>http://community.livejournal.com/shlomif_tech/45610.html</link>
<description>&#x3C;p&#x3E;
I published a new
&#x3C;a href=&#x22;http://article.gmane.org/gmane.comp.lang.perl.qotw.discuss/2655&#x22;&#x3E;Perl 
Quiz-of-the-Whatever about finding short Freecell solutions&#x3C;/a&#x3E;. Hope you enjoy
thinking about it. Here is the &#x3C;a href=&#x22;http://perl.plover.com/qotw/&#x22;&#x3E;Perl
Quiz-of-the-Whatever (formerly &#x22;Quiz of the Week&#x22;) information.&#x3C;/a&#x3E;.
&#x3C;/p&#x3E;</description>
<author>Shlomi Fish ( shlomif@iglu.org.il )</author>
<category>perl</category>
<category>fc-solve</category>
<category>freecell</category>
<comments>http://community.livejournal.com/shlomif_tech/45610.html</comments>
<guid isPermaLink="true">http://community.livejournal.com/shlomif_tech/45610.html</guid>
<pubDate>Mon, 22 Feb 2010 21:57:30 GMT</pubDate>
</item>
<item>
<title>Solving gaal&#x27;s Circuit Riddle Using Perl</title>
<link>http://community.livejournal.com/shlomif_tech/45409.html</link>
<description>&#x3C;p&#x3E;
&#x3C;a href=&#x22;http://gaal.livejournal.com/234795.html&#x22;&#x3E;gaal (= Gaal Yahas)
mentions a riddle&#x3C;/a&#x3E; on his blog:
&#x3C;/p&#x3E;

&#x3C;blockquote&#x3E;
&#x3C;p&#x3E;
There&#x2019;s a box with three input signals: A, B, C. It has three output signals:
~A, ~B, ~C (that is, the negation of each input).
&#x3C;/p&#x3E;

&#x3C;p&#x3E;
Design a circuit satisfying the above description. You have two NOT gates, and
as many AND and OR gates as you like.
&#x3C;/p&#x3E;

&#x3C;p&#x3E;
(If you solve this, don&#x2019;t tell me the answer &#x2014; I haven&#x2019;t solved it yet; I just
want to share the misery.)
&#x3C;/p&#x3E;
&#x3C;/blockquote&#x3E;

&#x3C;p&#x3E;
I decided that I will try to solve this riddle on my own
and then attempt to write a solution using a Perl 5 program, which I&#x27;ve
also thought about how to write. As it turned out, I ended up exploring
and eventually completely solving the riddle using a series of Perl programs.
I won&#x27;t mention the final solution here, but I&#x27;ll tell which programs
I wrote to solve them and how I wrote them. The code can be found in 
&#x3C;a href=&#x22;http://bitbucket.org/shlomif/riddle-not-a-not-b-not-c/src/&#x22;&#x3E;its
Mercurial repository&#x3C;/a&#x3E; under the MIT/X11 licence, as I mentioned
in &#x3C;a href=&#x22;http://gaal.livejournal.com/234795.html?thread=936235#t936235&#x22;&#x3E;a 
comment&#x3C;/a&#x3E; to gaal&#x27;s post.
&#x3C;/p&#x3E;

&#x3C;p&#x3E;
Well, first of all I decided to write a program that will take two negated
expressions of AND and OR gates and see if one can arrive to the final solution
using them and the given inputs (A, B and C). To do this I represented every
such possible expression as its components of (A + ~A) &#xD7; (B + ~B) &#xD7; (C + ~C) - 
8 in total which fit in an 8-bit datum, and which I indexed using an array
of 256 items to see which ones exist in the population. After doing the coding
I realised none of the expressions I tried worked.
&#x3C;/p&#x3E;

&#x3C;p&#x3E;
Then I decided to see if I there are any two possible expressions that when
added to A, B an C will yield all the necessary outputs. I ran it and indeed
found a single pair (and only a single pair) of such expressions (given as 
numbers) which I was able to analyse. I should note that the programs as 
I&#x27;ve written it using some functions and closures was too slow, so I ended
up writing another Perl script to preprocess the code, and inline the 
functions, which has made everything much faster. (You can find this 
preprocessor in the repository).
&#x3C;/p&#x3E;

&#x3C;p&#x3E;
Then I wanted to see if I can indeed construct these expressions from A
, B, and C using two negations. When I had thought about this, I believed
I needed to maintain a collection of expressions&#x27; populations, and to 
keep how many negations were in each. But when I got to code it I thought
of a simpler way: marry all the inputs using AND and OR until no more can
be married, then go over the existing ones and negate each one in turn, then
add the negated vector to the population and marry it with all the rest, and
then do it again for all the existing inputs. Using this I was able to
find a single solution.
&#x3C;/p&#x3E;

&#x3C;p&#x3E;
Then I had to output the solution. For that, I wrote a recursive expression
dumper, which ended up outputting with many parentheses, so I had to post-
process it a bit.
&#x3C;/p&#x3E;

&#x3C;p&#x3E;
The solution I got to was very complicated and I believe it would have taken
me a long time to reach it without resorting to programming. But at least
it saved me a lot of time and head-scratching. 
&#x3C;/p&#x3E;</description>
<author>Shlomi Fish ( shlomif@iglu.org.il )</author>
<category>perl</category>
<category>fun</category>
<comments>http://community.livejournal.com/shlomif_tech/45409.html</comments>
<guid isPermaLink="true">http://community.livejournal.com/shlomif_tech/45409.html</guid>
<pubDate>Fri, 19 Feb 2010 13:28:13 GMT</pubDate>
</item>
<item>
<title>Article Recommendation: &#x22;What Every CSer Should Know about Floating-Point Arithmetic&#x22;</title>
<link>http://community.livejournal.com/shlomif_tech/45104.html</link>
<description>&#x3C;p&#x3E;
I&#x27;ve read the paper 
&#x3C;a href=&#x22;http://docs.sun.com/source/806-3568/ncg_goldberg.html&#x22;&#x3E;&#x22;What 
Every Computer Scientist Should Know About Floating-Point Arithmetic&#x22;&#x3C;/a&#x3E; and
can recommend it as it has many interesting insights. I had received quite a
lot of reports for bugs in 
&#x3C;a href=&#x22;http://search.cpan.org/dist/Statistics-Descriptive/&#x22;&#x3E;the
&#x22;Statistics-Descriptive&#x22; CPAN distribution&#x3C;/a&#x3E; that were caused by expected
floating-point behaviour. Some of them I was able to resolve using some
trickery, and some others possibly can be somewhat mitigated using the insights
I&#x27;ve learnt in the article.
&#x3C;/p&#x3E;</description>
<author>Shlomi Fish ( shlomif@iglu.org.il )</author>
<category>perl</category>
<category>recommendation</category>
<category>article</category>
<comments>http://community.livejournal.com/shlomif_tech/45104.html</comments>
<guid isPermaLink="true">http://community.livejournal.com/shlomif_tech/45104.html</guid>
<pubDate>Thu, 11 Feb 2010 05:24:18 GMT</pubDate>
</item>
<item>
<title>NYTProf-3 is Out!</title>
<link>http://community.livejournal.com/shlomif_tech/44836.html</link>
<description>&#x3C;p&#x3E;
&#x3C;a href=&#x22;http://blog.timbunce.org/2009/12/24/nytprof-v3-worth-the-wait/&#x22;&#x3E;Tim
Bunce writes on his blog about the new features in 
Devel-NYTProf version 3&#x3C;/a&#x3E;. Devel-NYTProf is a profiler for the 
&#x3C;a href=&#x22;http://perl-begin.org/&#x22;&#x3E;Perl programming language&#x3C;/a&#x3E;, which has
put all the previous attempts in profiling in the dust, and now it&#x27;s even 
better than before. Enjoy! (Thanks to 
&#x3C;a href=&#x22;http://mail.pm.org/pipermail/sanfrancisco-pm/2010-February/002704.html&#x22;&#x3E;Fred 
Moyer&#x27;s post&#x3C;/a&#x3E; on the San-Fransisco Perl Mongers mailing list).
&#x3C;/p&#x3E;</description>
<author>Shlomi Fish ( shlomif@iglu.org.il )</author>
<category>3</category>
<category>version</category>
<category>perl</category>
<category>profiler</category>
<category>release</category>
<category>nytprof</category>
<comments>http://community.livejournal.com/shlomif_tech/44836.html</comments>
<guid isPermaLink="true">http://community.livejournal.com/shlomif_tech/44836.html</guid>
<pubDate>Fri, 05 Feb 2010 16:31:51 GMT</pubDate>
</item>
<item>
<title>Project Euler Problem #10 in Haskell, Perl and C</title>
<link>http://community.livejournal.com/shlomif_tech/44006.html</link>
<description>&#x3C;p&#x3E;
zerothorder told 
&#x3C;a href=&#x22;http://zerothorder.blogspot.com/2009/11/after-drinking-functional-immutable-and.html&#x22;&#x3E;how 
he found a solution for Project Euler&#x27;s Problem 10 in Haskell&#x3C;/a&#x3E;. The 
problem is &#x22;Find the sum of all primes less than 2,000,000&#x22;. It is given
here below:
&#x3C;/p&#x3E;

&#x3C;pre&#x3E;
primes :: [Integer]
primes = 2 : filter isPrime [3, 5 ..]
    where
        -- only check divisibility of the numbers less than the square root of n
        isPrime n = all (not . divides n) $ takeWhile (\p -&#x26;gt; p*p &#x26;lt;= n) primes
        divides n p = n `mod` p == 0
 
result = sum $ takeWhile (&#x26;lt; 2000000) primes
 
main = do putStrLn( show result )
&#x3C;/pre&#x3E;

&#x3C;p&#x3E;
He says &#x22;If this doesn&#x27;t give you a nerdgasm, I don&#x27;t know what will.&#x22;. The
problem is that this nerdgasm will last a long time. Benchmarking this
program gives that 20 iterations of it run at 310 seconds - less
than - about 15 seconds each (on my Pentium 4 2.4GHz machine running
Mandriva Linux Cooker). So next I tried a better Haskell
implmenetation that I recalled from a thread I started in the Haskell Caf&#xE9;
mailing list about implementing
&#x3C;a href=&#x22;http://en.wikipedia.org/wiki/Sieve_of_Eratosthenes&#x22;&#x3E;a sieve of
Eratosthenes in Haskell&#x3C;/a&#x3E;:
&#x3C;/p&#x3E;

&#x3C;pre&#x3E;
import Data.Int

primes :: Int64 -&#x26;gt; [Int64]

primes how_much = sieve [2..how_much] where
         sieve (p:x) = 
             p : (if p &#x26;lt;= mybound
                 then sieve (remove (p*p) x)
                 else x) where
             remove what (a:as) | what &#x26;gt; how_much = (a:as)
                                | a &#x26;lt; what = a:(remove what as)
                                | a == what = (remove (what+step) as)
                                | a &#x26;gt; what = a:(remove (what+step) as)
             remove what [] = []
             step = (if (p == 2) then p else (2*p)) 
         sieve [] = []
         mybound = ceiling(sqrt(fromIntegral how_much))

--main = print (length (primes 1000000))
main = print (sum (primes 2000000))
&#x3C;/pre&#x3E;

&#x3C;p&#x3E;
This does not involve costly operations such as modulo or division
and 20 iterations of it run at 135 wallclocks seconds - over two times faster
than zeroth&#x27;s Haskell version.
&#x3C;/p&#x3E;

&#x3C;p&#x3E;
Now how about Perl? Since Perl has assignment, we have the advantage that
we can create a vector of bits that we will mark with the primes by iterating
over all numbers up to the root of the limit. Here is the code:
&#x3C;/p&#x3E;

&#x3C;pre&#x3E;
#!/usr/bin/perl

use strict;
use warnings;

use Math::BigInt lib =&#x26;gt; &#x26;#39;GMP&#x26;#39;;

my $limit = 2_000_000;

my $primes_bitmask = &#x26;quot;&#x26;quot;;

my $loop_to = int(sqrt($limit));
my $sum = 0;
my $total_sum = Math::BigInt-&#x26;gt;new(&#x26;#39;0&#x26;#39;);

for my $p (2 .. $loop_to)
{
    if (vec($primes_bitmask, $p, 1) == 0)
    {
        $sum += $p;

        my $i = $p * $p;

        while ($i &#x26;lt; $limit)
        {
            vec($primes_bitmask, $i, 1) = 1;
        }
        continue
        {
            $i += $p;
        }

    }
}

for my $p ($loop_to .. $limit)
{
    if (vec($primes_bitmask, $p, 1) == 0)
    {
        if (($sum += $p) &#x26;gt; (1 &#x26;lt;&#x26;lt; 30))
        {
            $total_sum += $sum;
            $sum = 0;
        }
    }
}

$total_sum += $sum;
print &#x26;quot;$total_sum\n&#x26;quot;;
&#x3C;/pre&#x3E;

&#x3C;p&#x3E;
20 runs of it run at 95 walclock seconds - even faster than the Haskell
version. But it gets better. Since all the primes we encounter greater than
2 are not even, we can create a map of their pseduo-halves and conserve on
memory and iterations. This is the Perl version:
&#x3C;/p&#x3E;

&#x3C;pre&#x3E;
#!/usr/bin/perl

use strict;
use warnings;

use Math::BigInt lib =&#x26;gt; &#x26;#39;GMP&#x26;#39;;

my $limit = 2_000_000;

my $primes_bitmask = &#x26;quot;&#x26;quot;;

my $loop_to = (int(sqrt($limit)))&#x26;gt;&#x26;gt;1;
my $half_limit = ($limit-1)&#x26;gt;&#x26;gt;1;

my $sum = 0+2;
my $total_sum = Math::BigInt-&#x26;gt;new(&#x26;#39;0&#x26;#39;);

for my $half (1 .. $loop_to)
{
    if (vec($primes_bitmask, $half, 1) == 0)
    {
        my $p = (($half&#x26;lt;&#x26;lt;1)+1);
        $sum += $p;

        my $i = ($p * $p)&#x26;gt;&#x26;gt;1;

        while ($i &#x26;lt; $limit)
        {
            vec($primes_bitmask, $i, 1) = 1;
        }
        continue
        {
            $i += $p;
        }

    }
}


for my $half ($loop_to .. $half_limit)
{
    if (vec($primes_bitmask, $half, 1) == 0)
    {
        if (($sum += (($half&#x26;lt;&#x26;lt;1)+1)) &#x26;gt; (1 &#x26;lt;&#x26;lt; 30))
        {
            $total_sum += $sum;
            $sum = 0;
        }
    }
}

$total_sum += $sum;
print &#x26;quot;$total_sum\n&#x26;quot;;
&#x3C;/pre&#x3E;

&#x3C;p&#x3E;
Running this 20 times takes 73 wallclock seconds, close to half that of my
Haskell version.
&#x3C;/p&#x3E;

&#x3C;p&#x3E;
Then I wondered how long C will take. Here is a C implementation without
the halving:
&#x3C;/p&#x3E;

&#x3C;pre&#x3E;
#include &#x26;lt;string.h&#x26;gt;
#include &#x26;lt;math.h&#x26;gt;
#include &#x26;lt;stdint.h&#x26;gt;
#include &#x26;lt;stdio.h&#x26;gt;

#define limit 2000000
int8_t bitmask[(limit+1)/8];

int main(int argc, char * argv[])
{
    int p, i;
    int mark_limit;
    long long sum = 0;

    memset(bitmask, &#x26;#39;\0&#x26;#39;, sizeof(bitmask));
    mark_limit = (int)sqrt(limit);
    
    for (p=2 ; p &#x26;lt;= mark_limit ; p++)
    {
        if (! ( bitmask[p&#x26;gt;&#x26;gt;3]&#x26;amp;(1 &#x26;lt;&#x26;lt; (p&#x26;amp;(8-1))) ) )
        {
            /* It is a prime. */
            sum += p;
            for (i=p*p;i&#x26;lt;=limit;i+=p)
            {
                bitmask[i&#x26;gt;&#x26;gt;3] |= (1 &#x26;lt;&#x26;lt; (i&#x26;amp;(8-1)));
            }
        }
    }
    for (; p &#x26;lt;= limit; p++)
    {
        if (! ( bitmask[p&#x26;gt;&#x26;gt;3]&#x26;amp;(1 &#x26;lt;&#x26;lt; (p&#x26;amp;(8-1))) ) )
        {
            sum += p;
        }
    }

    printf(&#x26;quot;%lli\n&#x26;quot;, sum);

    return 0;
}
&#x3C;/pre&#x3E;

&#x3C;p&#x3E;
This was too fast to measure with 20 runs alone, so 500 runs of it took 15
seconds, two or three orders of magnitude faster than the fastest Haskell
or Perl versions. But naturally, we can apply the halving paradigm there too:
&#x3C;/p&#x3E;

&#x3C;pre&#x3E;
#include &#x26;lt;string.h&#x26;gt;
#include &#x26;lt;math.h&#x26;gt;
#include &#x26;lt;stdint.h&#x26;gt;
#include &#x26;lt;stdio.h&#x26;gt;

#define limit 2000000
int8_t bitmask[(limit+1)/8/2];

int main(int argc, char * argv[])
{
    int half, p, i;
    int half_limit;
    int loop_to;
    long long sum = 0 + 2;

    memset(bitmask, &#x26;#39;\0&#x26;#39;, sizeof(bitmask));

    loop_to=(((int)(sqrt(limit)))&#x26;gt;&#x26;gt;1);
    half_limit = (limit-1)&#x26;gt;&#x26;gt;1;
    
    for (half=1 ; half &#x26;lt;= loop_to ; half++)
    {
        if (! ( bitmask[half&#x26;gt;&#x26;gt;3]&#x26;amp;(1 &#x26;lt;&#x26;lt; (half&#x26;amp;(8-1))) ) )
        {
            /* It is a prime. */
            p = (half &#x26;lt;&#x26;lt; 1)+1;
            sum += p;
            for (i = ((p*p)&#x26;gt;&#x26;gt;1) ; i &#x26;lt; half_limit ; i+=p )
            {
                bitmask[i&#x26;gt;&#x26;gt;3] |= (1 &#x26;lt;&#x26;lt; (i&#x26;amp;(8-1)));
            }
        }
    }

    for( ; half &#x26;lt; half_limit ; half++)
    {
        if (! ( bitmask[half&#x26;gt;&#x26;gt;3]&#x26;amp;(1 &#x26;lt;&#x26;lt; (half&#x26;amp;(8-1))) ) )
        {
            sum += (half&#x26;lt;&#x26;lt;1)+1;
        }
    }

    printf(&#x26;quot;%lli\n&#x26;quot;, sum);

    return 0;
}
&#x3C;/pre&#x3E;

&#x3C;p&#x3E;
500 runs of it take 10 wallclock seconds - 54.35 times per second,
and 50% better than the previous C version. And I still haven&#x27;t applied
platform-specific gcc optimisations. 
&#x3C;/p&#x3E;

&#x3C;p&#x3E;
I should also note that the executables generated by ghc are extremely
large in comparison to their C ones:
&#x3C;/p&#x3E;

&#x3C;pre&#x3E;
$ ls -l c_* haskell_*
-rwxr-xr-x 1 shlomi shlomi   6082 2009-12-04 07:46 c_mine
-rwxr-xr-x 1 shlomi shlomi   6103 2009-12-04 07:46 c_mine_half
-rwxr-xr-x 1 shlomi shlomi   6092 2009-12-04 07:46 c_mine_micro_opt
-rwxr-xr-x 1 shlomi shlomi 796825 2009-12-04 07:56 haskell_mine
-rwxr-xr-x 1 shlomi shlomi 571717 2009-12-04 07:46 haskell_zeroth
&#x3C;/pre&#x3E;

&#x3C;p&#x3E;
&#x3C;tt&#x3E;c_mine_half&#x3C;/tt&#x3E; is less than 1% the size of &#x3C;tt&#x3E;haskell_mine&#x3C;/tt&#x3E; (and
runs faster). When talking about this to other people, they said that Haskell
has a very optimised primes sequence generator, which I can try using (which
should be over 3 times as fast), and that it has two kinds of integers, which
the other type is faster, and that it has a better way to emulate assignment.
But the bottom line is that the na&#xEF;ve and intuitive way to write such
programs in Haskell is under-performant, even in comparison to Perl, and 100
or 1,000 times as much in comparison to C.
&#x3C;/p&#x3E;

&#x3C;p&#x3E;
I&#x27;ve written this as a separate post and not as a comment to the original
blog post because I&#x27;m very limited with the markup in the commenting there
(I&#x27;m going to post a comment there with a link to this blog post, though). 
I should note that you can find all the code I mentioned inside 
&#x3C;a href=&#x22;http://github.com/shlomif/Project-Euler-Problem-10-Comparison&#x22;&#x3E;a
dedicated Github repository&#x3C;/a&#x3E;, and you can experiment with it further.
&#x3C;/p&#x3E;</description>
<author>Shlomi Fish ( shlomif@iglu.org.il )</author>
<category>problem</category>
<category>summary</category>
<category>primes</category>
<category>project</category>
<category>optimize</category>
<category>optimise</category>
<category>optimization</category>
<category>c</category>
<category>haskell</category>
<category>perl</category>
<category>10</category>
<category>speed</category>
<category>optimisation</category>
<category>euler</category>
<comments>http://community.livejournal.com/shlomif_tech/44006.html</comments>
<guid isPermaLink="true">http://community.livejournal.com/shlomif_tech/44006.html</guid>
<pubDate>Sat, 30 Jan 2010 12:50:07 GMT</pubDate>
</item>
<item>
<title>XML-Grammar-Fortune version 0.0200 Was Released</title>
<link>http://community.livejournal.com/shlomif_tech/43620.html</link>
<description>&#x3C;p&#x3E;
I recently released version 0.0200 of the Perl 5 CPAN Module
&#x3C;a href=&#x22;http://web-cpan.berlios.de/modules/XML-Grammar-Fortune/&#x22;&#x3E;XML-Grammar-Fortune&#x3C;/a&#x3E;.
XML-Grammar-Fortune is a module to maintain a collection of Unix-like
fortune cookies as XML and convert them to XHTML and plain-text.
&#x3C;/p&#x3E;

&#x3C;p&#x3E;
New in this release are a heavily fixed and enhanced code for rendering the XML
to plaintext and a more enhanced META.yml file. XML-Grammar-Fortune was
successfully utilised for
&#x3C;a href=&#x22;http://www.shlomifish.org/humour/fortunes/&#x22;&#x3E;my collection of Fortune
Cookies&#x3C;/a&#x3E;.
&#x3C;/p&#x3E;</description>
<author>Shlomi Fish ( shlomif@iglu.org.il )</author>
<category>release</category>
<category>unix</category>
<category>text</category>
<category>fortune</category>
<category>grammar</category>
<category>hacktivity</category>
<category>xml-grammar-fortune</category>
<category>perl</category>
<category>xml</category>
<category>fortunes</category>
<category>cpan</category>
<comments>http://community.livejournal.com/shlomif_tech/43620.html</comments>
<guid isPermaLink="true">http://community.livejournal.com/shlomif_tech/43620.html</guid>
<pubDate>Mon, 25 Jan 2010 15:49:53 GMT</pubDate>
</item>
<item>
<title>The CPAN Dependencies of Website Meta Language</title>
<link>http://community.livejournal.com/shlomif_tech/43345.html</link>
<description>&#x3C;p&#x3E;
In the past few days I resumed work on converting
the &#x3C;a href=&#x22;http://thewml.org/&#x22;&#x3E;Website Meta Language&#x3C;/a&#x3E; (WML) build-system
from the GNU Autotools (also known as &#x22;GNU Autohell&#x22;) to 
&#x3C;a href=&#x22;http://www.cmake.org/&#x22;&#x3E;CMake&#x3C;/a&#x3E;. This involved implementing a lot
of the existing makefile and autoconf logic in CMake and Perl. 
&#x3C;/p&#x3E;

&#x3C;p&#x3E;
Yesterday, I converted the &#x22;wml_common&#x22; sub-directory which turned out to
contain some ancient versions of CPAN distributions with a forced-upon way
to install under the WML prefix. I decided to forego installing all of them
and just check for their existence in the perl version that wml uses using 
some WML and &#x22;perl -MMyModule&#x22; code. 
&#x3C;/p&#x3E;

&#x3C;p&#x3E;
I was able to find all the needed modules in the Mandriva repository, except
one - 
&#x3C;a href=&#x22;http://search.cpan.org/dist/File-PathConvert/&#x22;&#x3E;File-PathConvert&#x3C;/a&#x3E;
, which I&#x27;ve never heard about.
I checked it on CPAN, and saw that it was deprecated and superseded by
File::Spec and Cwd. So I grepped the tree for its use and found it was used
only in one Perl program which I quickly converted to File::Spec and Cwd.
&#x3C;/p&#x3E;

&#x3C;p&#x3E;
Now, the future build system of Website Meta Language will be simpler
and it won&#x27;t use deprecated modules.
&#x3C;/p&#x3E;

&#x3C;p&#x3E;
Oh! And 
&#x3C;a href=&#x22;http://blog.mozilla.com/blog/2010/01/21/firefox-3-6-release/&#x22;&#x3E;Firefox
3.6 (Gamma) is out&#x3C;/a&#x3E;! I&#x27;ve been using the betas and RCs on Mandriva Cooker
for some time now, and now I&#x27;ve upgraded to the stable version and it&#x27;s
still great.
&#x3C;/p&#x3E;</description>
<author>Shlomi Fish ( shlomif@iglu.org.il )</author>
<category>eumm</category>
<category>wml</category>
<category>language</category>
<category>cmake</category>
<category>perl</category>
<category>firefox</category>
<category>gnu</category>
<category>autohell</category>
<category>website</category>
<category>meta</category>
<category>cpan</category>
<comments>http://community.livejournal.com/shlomif_tech/43345.html</comments>
<guid isPermaLink="true">http://community.livejournal.com/shlomif_tech/43345.html</guid>
<pubDate>Fri, 22 Jan 2010 19:22:40 GMT</pubDate>
</item>
<item>
<title>Perl: Using Vim&#x27;s snipMate for Perl 5 snippets</title>
<link>http://community.livejournal.com/shlomif_tech/43262.html</link>
<description>&#x3C;p&#x3E;
I noticed that there was some Perl 5 code that I had to type or copy-and-paste
again and again on many occasions. So I decided to find a way to put it in
one place and then recall it. I thought of writing it myself, but then recalled
the &#x3C;a href=&#x22;http://www.vim.org/scripts/script.php?script_id=2540&#x22;&#x3E;snipMate
snippets extension for Vim&#x3C;/a&#x3E; (which 
&#x3C;a href=&#x22;http://www.catonmat.net/blog/vim-plugins-snipmate-vim/&#x22;&#x3E;Peteris
Krumins covered in a blog post&#x3C;/a&#x3E;), which allows that. After a little reading,
I was able to prepare the snippets.
&#x3C;/p&#x3E;

&#x3C;p&#x3E;
I placed the following under &#x3C;tt&#x3E;~/.vim/snippets/perl/_slurp.snippet&#x3C;/tt&#x3E; :
&#x3C;/p&#x3E;

&#x3C;pre&#x3E;
sub _slurp
{
	my $filename = shift;

	open my $in, &#x22;&#x26;lt;&#x22;, $filename
		or die &#x22;Cannot open &#x27;$filename&#x27; for slurping - $!&#x22;;

	local $/;
	my $contents = &#x26;lt;$in&#x26;gt;;

	close($in);

	return $contents;
}
&#x3C;/pre&#x3E;

&#x3C;p&#x3E;
And now I can type &#x22;_slurp&#x26;lt;TAB&#x26;gt;&#x22; to recall it. The existing &#x22;slurp&#x22;
snippet in &#x3C;tt&#x3E;~/.vim/snippets/perl.snippets&#x3C;/tt&#x3E; is quite evil, with an
ugly inline line, typeglobs, and a two args open without a die statement. 
Thanks, but no thanks.
&#x3C;/p&#x3E;

&#x3C;p&#x3E;
Afterwards I added the following in 
&#x3C;tt&#x3E;~/.vim/snippets/perl/_ltestb.snippet&#x3C;/tt&#x3E;
&#x3C;/p&#x3E;

&#x3C;pre&#x3E;
	local $Test::Builder::Level = $Test::Builder::Level + 1;
&#x3C;/pre&#x3E;

&#x3C;p&#x3E;
And now I can type &#x22;_ltestb&#x22; (short for &#x22;local Test::Builder&#x22;) and put this 
line there to create my own custom Test::More/Test::Builder tests.
&#x3C;/p&#x3E;

&#x3C;p&#x3E;
Thus, using snipMate, you can create your own short-hands for commonly-used
snippets like that.
&#x3C;/p&#x3E;</description>
<author>Shlomi Fish ( shlomif@iglu.org.il )</author>
<category>test</category>
<category>tip</category>
<category>local</category>
<category>slurp</category>
<category>perl</category>
<category>snipmate</category>
<category>vim tip</category>
<category>builder</category>
<category>snippets</category>
<category>vim</category>
<comments>http://community.livejournal.com/shlomif_tech/43262.html</comments>
<guid isPermaLink="true">http://community.livejournal.com/shlomif_tech/43262.html</guid>
<pubDate>Thu, 21 Jan 2010 16:26:13 GMT</pubDate>
</item>
<item>
<title>Report on the TelFOSS &#x22;Moose for Beginners&#x22; Meeting</title>
<link>http://community.livejournal.com/shlomif_tech/42895.html</link>
<description>&#x3C;p&#x3E;
Last Sunday, &#x3C;a href=&#x22;http://tel.foss.org.il/&#x22;&#x3E;Tel Aviv Open Source club
(TelFOSS)&#x3C;/a&#x3E; met to listen to Sawyer&#x27;s presentation about &#x22;Moose for
Beginners&#x22;. Despite the fact that the meeting was well-publicised, very
few people came. Sawyer did not prepare a lot of slides and since there were
not many questions he finished quickly. After all that, he went to demonstrate
how to implement several use cases that the audience has proposed as Moose
programs, and despite that we still finished early.
&#x3C;/p&#x3E;

&#x3C;p&#x3E;
I asked about implementing an &#x22;XML parser&#x22;, but in fact I wanted to implement
a processor for a certain XML grammar. In any case, he misunderstood and told
me to use Parse-RecDescent for that. I&#x27;ve grown to dislike P-RD for most stuff
though.
&#x3C;/p&#x3E;

&#x3C;p&#x3E;
In any case, I&#x27;m getting tired of the low attendance in TelFOSS meetings. We
do so much work in organising and publicising the meetings, and most people
don&#x27;t bother to come. Are the people too busy? Did they run out of steam? Why
don&#x27;t they come? This makes me frustrating and unwilling to further organise
the TelFOSS meetings.
&#x3C;/p&#x3E;</description>
<author>Shlomi Fish ( shlomif@iglu.org.il )</author>
<category>telux</category>
<category>telfoss</category>
<category>meeting</category>
<category>open</category>
<category>perl</category>
<category>club</category>
<category>sawyer</category>
<category>moose</category>
<category>tel aviv</category>
<category>source</category>
<category>report</category>
<comments>http://community.livejournal.com/shlomif_tech/42895.html</comments>
<guid isPermaLink="true">http://community.livejournal.com/shlomif_tech/42895.html</guid>
<pubDate>Wed, 20 Jan 2010 12:35:04 GMT</pubDate>
</item>
</channel>
</rss>