Re: Languages that don't suck after Perl?
- From: "Veli-Pekka Tätilä" <vtatila@xxxxxxxxxxxxxxxxxxxxxx>
- Date: Mon, 21 Jul 2008 18:18:35 +0300
Tim Smith wrote:
I've found that as I've spent more time in Perl, my tolerance for otherI might get flamed for this <shy smile>, but for me, Lua was such a
languages has gone down. I keep finding myself muttering "why is this
stupid language making me go through so much work just make a simple
data structure that I only will need for a few lines?" <snippage>
what languages have you found are not annoying after Perl?
language. I had to pick it up recently and after an initial great dislike
that had to do with lack of programmer convenience and the Perlish TIMTOWTDI
I found myself greatly enjoying its simplicity and minimalism, even
preffering it to Perl at times given some small convenience wrappers. To me
it is a clean redesign of many of the cool, core mechanisms already in perl
with a much more orthogonal and less messy legacy-free design. It was about
the quickest language for me to learn, ever, since there's so much I've
learned in Perl over the years that can be directly applied in a Lua
context. I guess this is true for many other dynamically typed langs,
though.
Frankly, I'm happy that when I program in Lua I have a feeling I've mastered
most of the language well, and can hold a significant subset in my head,
where as I always have to go and re-read the man page for the more obscure
Perlisms whose limitations and obscurities annoy me.
Lua is also very clean and punctuation free syntactically, which is an
important difference if you ever have to code legally blind based on
synthetic speech and Braille, granted this is very unlikely. Perl regexp,
which I love for saving me from having to cursor through text linearly with
speech in my text editor, are about the most horrible speech read, though,
you have to go character by character to parse them mentally with a naive
screen reader like Hal for Windows or Gnome's Orca.
Here are some examples of Perl and Lua similarities. If you know Perl
hashes, Lua hashes work much the same. Except that they can be indexed with
any type other than nil (undef), including ints for fast arrays. And in
stead of type globs and packages, you have just global hashes mapping
strings to data and a bit of syntactic sugar. Rather than explicit
dereffing, you have separate, very simple ref types for tables, functions
etc..
Again, Lua OOp after Perl was quite palatable: classes and objects are
hashes. Rather than blessing, just overload indexing on a per object basis
such that it looks in the class hash for methods and data fields not found
in the object. You can also give a code ref for multiple inheritance,
autoloading, or whatever rather than a hash to look missing fields in. In
Lua, Accessing string keys of a hash with a dot and calling functions like
methods, are just a bit of true syntactic sugar around indexing a hash and
passing the invocant as the first arg. Where Perl has ISA, Overload, bless,
tie, package etc... all Lua has are tables, and the ability to set their
operations.
In fact I've written a bit of a conversion guide for folks who already know
Perl and need to learn Lua for one reason or another. This works best for
folks who have a similar, rather informal way of thinking of coding,than I
do:
http://vtatila.kapsi.fi/luatut.html
Be warned this is just an initial version, and I'm only an intermediate
Perler rather new to Lua. Still, loads of shortcuts can be taken if you know
Perl. here's my explanation of Lua patterns, which is not long:
Quote
Quantifiers and Character Classes
The primary simplification is that a quantifier may only follow a character
class, you cannot quantify a parenthesize subexpression or a capturing
group. *, question ? and + work exactly like their greedy counter parts in
regexp. The only other quantifier is minus - which is like the lazy star, *?
Character classes are locale sensitive in Lua and Perl. Syntactically, in
stead of backslashing symbols, you use the percent sign for the same thing.
%a, %u and %l for alphabetic, caps and lowwercase letters, %d and %x for
ordinary and hex digits, %c, %p and %z for control, punctuation and null
characters. Uppercased versions of these classes are the complements, much
as in Perl. Additionally, %% is a percent sign and the dot %. is any
character, including new lines, unlike in regexp by default.
Bracketed sets of characters including character ranges and classes as part
of them can be used much as in regexp. Exception: you cannot augment a
character class with a range. You can, however, invert a range with a
leading caret [^...].
Finally, lua patterns may also contain %b followed by two characters. The
construct will match an expression with the counts of these characters being
balanced, e.g. %b() for matching nested parens. Again, a balanced expression
may not be quantified but may be captured.
Capturing Groups and Anchors
Parens in Lua patterns neither group nor change precedence, they only
surround bits of patterns to be captured. captured are numbered from 1
onwards and referred to in the same pattern as %1, %2 and so on. %0 in a
replacement is the whole matched string. An empty pair of parens
exceptionally captures the 1-based match position in stead.
The only anchors in Lua patterns are the caret ^and dollar $, which always
only anchor at the beginning and end of the whole pattern, new lines in
matched text don't affect their meaning.
End quote.
--
With kind regards Veli-Pekka Tätilä
Accessibility, Apps and Coding plus Synths and Music:
http://vtatila.kapsi.fi
.
- References:
- Languages that don't suck after Perl?
- From: Tim Smith
- Languages that don't suck after Perl?
- Prev by Date: Re: Languages that don't suck after Perl?
- Next by Date: Re: Net::Ldap pb with SASL under multidomain MS Lan.
- Previous by thread: Re: Languages that don't suck after Perl?
- Next by thread: Re: Languages that don't suck after Perl?
- Index(es):
Relevant Pages
|