Re: Larry Wall Talks, Perl and Lua (Was: Programming is hard, let's go scripting)
- From: Veli-Pekka Tätilä <vtatila@xxxxxxxxxxxxxxxxxxxx>
- To: programmingblind@xxxxxxxxxxxxx
- Date: Sat, 29 Mar 2008 00:36:10 +0200
Octavian Rasnita wrote:
> Read a nice article by Larry Wall at:
> http://www.perl.com/pub/a/2007/12/06/soto-11.html
Hi Octavian,
And thanks for the post. I really like Larry's talks written down, even,
really smart, whitty and still serious talk, I'd say. Another Perl
article I like by him is this one about natural language principles:
http://www.wall.org/~larry/natural.html
I'm also beginning to like Lua very much based on this free Lua book:
http://www.lua.org/pil/
Dolphin chose it as their screen reader scripting language introduced in
CSUN I've heard and it will be properly publicized in the upcoming
V9.02. Very speech friendly and extremely minimalist, yet it is about as
flexible as Perl is in terms of functional programming and
object-orientation.
I learned about the Lua screen reader API, yet to be finalized, in an
experimental Dolphin course on using Lua in addition to the mapping
system they have, somewhat similar to WindowEye's set files.
Finally, to demonstrate, I decided to do the same task in Lua and Perl,
namely sorting BibTeX references by their citation key. The Perl version
is more functional, briefer and probably more idiomatic, but that's how
I code Perl. the Lua version, in turn, using a different strategy, is
much cleaner and maintainable by default. It doesn't have map or split,
though I've coded map from scratch easily experimentally. And now the
code:
Perl version:
use strict; use warnings;
@ARGV == 2 or die "usage: inFile outFile\n";
($/, my %entries) = "";
open my $in, shift or die "Cannot read file: $^E\n";
/^@\w+\{(.+),/ and $entries{$1} = $_ for <$in>;
open my $out, ">", shift or die "Cannot write file: $^E\n";
print $out $entries{$_} for sort keys %entries
Lua version:
require "strict"
if not # arg == 2 then error "Usage: inFile outFile" end
local entries, sortedEntries, thisEntry = { }, { }, ""
for line in io.lines( arg[1] ) do
local ref = string.match(line, "@%w+%s*%{(%w+)")
if ref then thisEntry = ref end
if not entries[thisEntry] then entries[thisEntry] = { } end
table.insert(entries[thisEntry], line)
end
for entry in pairs(entries) do table.insert(sortedEntries, entry) end
table.sort(sortedEntries)
local outFile = io.open( arg[2], "w")
for _, entry in ipairs(sortedEntries) do
for _, line in ipairs(entries[entry] ) do outFile:write(line, "\n")
end
end
Of course, you could do the Lua version in Perl. And since Perl has
proper arrays where as Lua arrays are just fast indexed hashes with int
keys, the PErl version might be more natural. Also, Perl autovivifies
arrays on indexing ($f{bar}[5] creates the hash and creates the array in
it), avoiding yet another if.
The key difference is not so much on what is possible but what the
coding culture says. The perl version is natural in Perl and the LUa
version is natural in Lua. Both are equally valid. The lua version is
easier to understand, though, and Lua is about as speech friendly as
Ruby is at best. The same is not true of Perl, though it seems to me
Perl 6 will rectify this partly.
I think the Lua object system is just plain clean and simple. The same
minimalism as in Perl but using only meta tables, not language magic
like @ISA and bless or library magic, such as overload.pm.
Finally, as for funny LArry quotes that make a good fortune file, here's
a list for you:
http://en.wikiquote.org/wiki/Larry_Wall
--
With kind regards Veli-Pekka Tätilä (vtatila@xxxxxxxxxxxxxxxxxxxx)
Accessibility, game music, synthesizers and programming:
http://www.student.oulu.fi/~vtatila
__________
View the list's information and change your settings at
http://www.freelists.org/list/programmingblind
- Follow-Ups:
- Re: Larry Wall Talks, Perl and Lua (Was: Programming is hard, let's go scripting)
- From: Octavian Rasnita
- Re: Larry Wall Talks, Perl and Lua (Was: Programming is hard, let's go scripting)
- From: Octavian Rasnita
- References:
- Programming is hard, let's go scripting
- From: Octavian Rasnita
Other related posts:
- » Re: Larry Wall Talks, Perl and Lua (Was: Programming is hard, let's go scripting)
- » Re: Larry Wall Talks, Perl and Lua (Was: Programming is hard, let's go scripting)
- » Re: Larry Wall Talks, Perl and Lua (Was: Programming is hard, let's go scripting)
- Re: Larry Wall Talks, Perl and Lua (Was: Programming is hard, let's go scripting)
- From: Octavian Rasnita
- Re: Larry Wall Talks, Perl and Lua (Was: Programming is hard, let's go scripting)
- From: Octavian Rasnita
- Programming is hard, let's go scripting
- From: Octavian Rasnita