ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
No. That being said, a key point to remember is this... *anything* can be done in *any* programming language. It's just a matter of complexity. There are things you can do in lisp easily that are more complex to do in Perl, sometimes because they're not native to the language, sometimes because they're just a pain in the backside.
Programming languages are not defined by what you can do in them specifically, but rather by what they let you do *easily*.
The statement in bold is wrong.
For example, in "C" there are no anonymous references (well, there is, AFAIR, one case when an anonymous pointer to structure can be used in C99) while in Perl there are anonymous references that can be used "everywhere".
In "C" there are no closures while in Perl there are.
In "C" itself you can't add a piece of code on the fly - rather, you can, but you need to know what compiler to use, so it's not portable, while in Perl/Python/Java/Ruby you can do it portably.
All these features, or lack thereof, drastically affect the way programs are developed in the corresponding languages.
For example, you need something like XML for "C", and you don't need it for Perl - Perl is self-sufficient to pass data between Perl programs, i.e. data can be passed in Perl format and it's the easiest way to do it.
Macros. But the main thing about the LISP family of languages is their elegance. Not everybody appreciates that, but some do, and their life is transformed.
I hope they'll complete Perl 6, there are macros in it.
'eval' can be used as simple and good enough macro approximation:
Code:
sergei@amdam2:~/junk> cat -n perl_macro.pl
1 #!/usr/bin/perl -w
2
3 use warnings;
4 use strict;
5
6
7 my $greeting = 'Hello';
8
9 my $end;
10 my $macro = sub{my ($person) = @_; "print \"$greeting, $person$end\\n\"";};
11
12 $end = ' !';
13 eval &{$macro}("John");
14
15 $end = ', is it you ?';
16 eval &{$macro}("Paul");
17
sergei@amdam2:~/junk> ./perl_macro.pl
Hello, John !
Hello, Paul, is it you ?
sergei@amdam2:~/junk>
Agree. I don't know why the "it's Turing-complete" argument gets floated about so much, it's totally worthless in anything other than a purely academic sense. It's not that it's not true, it's just meaningless. Like saying "both a car and your feet could take you thirty miles to work each day, it's just a matter of how long you're willing to take." PostScript is Turing-complete, but you certainly won't find me coding a complex web service in it.
The key point is not that it can simply be done in any language, that's a mundane fact. The real key point is that the language you choose can have a profound impact on how easy it is for you to do it.
I hope they'll complete Perl 6, there are macros in it.
'eval' can be used as simple and good enough macro approximation:
Perl 6 will indeed have Lisp-style macros, which are totally unlike the text substitution macros in C and similar languages. I can't really see how your eval example is like a Lisp macro either, since it does not seem to have access to its unparsed arguments. Can you write a write a macro in Perl, so that calling
Code:
macro(@my_array);
(using eval or whatever) will return something like
Code:
@my_array = (1, 2, 3, ...)
And, no, you can't say
Code:
macro('@my_array');
because that would the defeat the whole purpose of the exercise.
Perl 6 will indeed have Lisp-style macros, which are totally unlike the text substitution macros in C and similar languages. I can't really see how your eval example is like a Lisp macro either, since it does not seem to have access to its unparsed arguments. Can you write a write a macro in Perl, so that calling
Code:
macro(@my_array);
(using eval or whatever) will return something like
Code:
@my_array = (1, 2, 3, ...)
And, no, you can't say
Code:
macro('@my_array');
because that would the defeat the whole purpose of the exercise.
Probably with extra effort I can implement it as
Code:
'macro(@my_array)'
, but, I guess, it's not what you want.
OTOH, there are Perl modules of source filter kind which do all kinds of text substitution.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.