In Lisp, this sets the variable a to a list:
(setq a '(1 2 3 4))
Here we create list b where the first element is another list:
(setq b '((0.8 0.9 1) 2 3 4))
Here's the first list in Perl:
@a=(1,2,3,4);
and here's the second:
@b=((0.8,0.9,1),2,3,4);
(The @s before the variable names tells Perl that these are array variables.) That wasn't so bad, was it? Well, let's try to use this.
To pick out the first element of the first list in Lisp, you just write
(first a)
and Lisp gives you
1
To get the first element of the second list you write
(first b)
and Lisp gives you
(0.8 0.9 1)
Let's try this in Perl.
$a[0]
gives us
1
The $ before the variable name tells Perl that we want a single value (scalar in Perl lingo), not an array. The [0] tells Perl that we want the first value of the array. Perl, like many other languages and APIs counts from 0.
Then we do
$b[0]
and Perl happily gives us
0.8
That's right, Perl has broken into the list inside the b list and retrieved the first value of it. Or, rather, it flattened b into one list when we created it, so it's now really one consecutive list with 6 elements.
To do this right we should have written
@b=([(0.8,0.9,1)],2,3,4);
when we created the list. The []s enter a reference to the inner list as the first element of the outer list instead of flattening the inner list into the outer one.
OK. So we try again:
$b[0]
gives us
ARRAY(0xb75eb0)
So obviously we manage to find the array, but something still goes wrong along the way. The problem is that we use $b, which makes Perl think that we want a scalar and so it gives us a reference to the array instead of the array itself (which is not a scalar).
Aha! Of course! We must use
@b[0]
because @ tells Perl we want an array value. Not so. We get
ARRAY(0xb75eb0)
once again. I've never managed to understand why this is so and at this point I gave up on the entire thing.
Some weeks later I saw a helpful posting on no.perl: one should request a reference to the array, like this
@{$b[0]}
which actually gives us
(0.8 0.9 1)
So now I can write code with arrays inside arrays and hashes inside hashes.
Now, ask yourself: do you really think you should have to go through all this in order to put one list inside another?
Name:
Anonymous2011-06-03 19:24
I have learned the fundamental difference between Perl & Lisp - with Lisp macros it is much easier to interlace with HTML, ie jumping in and out to make life easier. I am finding that Perl is no where near as flexible, actually I don't think it's possible, and even if it is, it wouldn't be considered good practise.
>>3
You posted the source for your Lisp DSL quite recently, right?
Anyway, I've been thinking of reading the source, what file should I start with according to you?
Name:
Anonymous2011-06-03 19:36
$a = 2;
sub foo {
$a = $a+1; # create a local copy of $a, so we wont modify global
# ...
}
&foo;
print "$a\n"; # this should print '2'
This prints 3, due to a naive mistake that Larry Wall made early on, one that has permanent and far-reaching implications to the usability of the language. For what it's worth, Guido made the same mistake with Python, Matz made it with Ruby, and Strachan appears to be making it all over again in Groovy. It's a common blunder.
Name:
Anonymous2011-06-03 19:39
>>7
Now it's very outdated. You should wait till I release version 1.0, comment the source and document standard library. Now it's just a useless prototype.
>>9
Okay, the sdl files, are those your own bindings?
Name:
Anonymous2011-06-03 19:54
The little girls are after me.
Name:
Anonymous2011-06-03 20:03
>>10 Okay, the sdl files, are those your own bindings?
They were taken from lispbuilder, with a few fixes. I wanted pixel-level access to framebuffer. The `save-image` is a direct translation of C/C++ from libpng, because sdl-image have no saving capabilities.
>>10 Why does that happen?
Matz, Wall and Guido don't discern between `let` and `set!`. Originally, they probably had a much simplier hashtable-based model (like the one students do in their first infix-calculator project), onto which they added all the crud.
>>22
The use of Perl cripples the mind; its teaching should, therefore, be regarded as a criminal offense.
Name:
Anonymous2011-06-03 22:26
Perl, 'the infantile disorder', by now nearly 20 years old, is hopelessly inadequate for whatever computer application you have in mind today: it is now too clumsy, too risky, and too expensive to use.
>>1
I can't tell if you want /[aeiou]/; or /a.*e.*i.*o.*u/, but I can say you'll only need one regex.
Oh, also: use strict;
That's the real mistake Larry Wall made, not turning it on by default.
Name:
Anonymous2011-06-03 22:57
>>24
Use perl for work. We have over 20k lines of perl.
U mad?
Name:
Anonymous2011-06-03 23:47
>>26
Count how many COBOL and BASIC lines we have.
Name:
Anonymous2011-06-03 23:52
COBOL programs are in use globally in governmental and military agencies and in commercial enterprises, and are running on operating systems such as IBM's z/OS, the POSIX families (Unix/Linux etc.), and Microsoft's Windows as well as ICL's VME operating system and Unisys' OS 2200. In 1997, the Gartner Group reported that 80% of the world's business ran on COBOL with over 200 billion lines of code in existence and with an estimated 5 billion lines of new code annually.[6]
Near the end of the twentieth century the year 2000 problem was the focus of significant COBOL programming effort, sometimes by the same programmers who had designed the systems decades before. The particular level of effort required for COBOL code has been attributed both to the large amount of business-oriented COBOL, as COBOL is by design a business language and business applications use dates heavily, and to constructs of the COBOL language such as the PICTURE clause, which can be used to define fixed-length numeric fields, including two-digit fields for years.[citation needed]