LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
LinkBack Search this Thread
Old 01-23-2009, 09:32 PM   #16
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,123

Rep: Reputation: 407Reputation: 407Reputation: 407Reputation: 407Reputation: 407

Quote:
Originally Posted by rweaver View Post
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.
 
Old 01-23-2009, 09:48 PM   #17
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,123

Rep: Reputation: 407Reputation: 407Reputation: 407Reputation: 407Reputation: 407
Quote:
Originally Posted by burschik View Post
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>
 
Old 01-23-2009, 10:25 PM   #18
taylor_venable
Member
 
Registered: Jun 2005
Location: Indiana, USA
Distribution: OpenBSD, Ubuntu
Posts: 892

Rep: Reputation: 39
Quote:
Originally Posted by Sergei Steshenko View Post
The statement in bold is wrong.
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.
 
Old 01-26-2009, 12:00 PM   #19
Su-Shee
Member
 
Registered: Sep 2007
Location: Berlin
Distribution: Slackware
Posts: 509

Rep: Reputation: 41
For the lisp-ish side of Perl: Mark Jason Dominus' really great book "Higher Order Perl" is available online:

http://hop.perl.plover.com/book/
 
Old 01-27-2009, 01:57 AM   #20
burschik
Member
 
Registered: Jul 2008
Posts: 159

Rep: Reputation: 31
Quote:
Originally Posted by Sergei Steshenko View Post
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.
 
Old 01-27-2009, 02:49 AM   #21
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,123

Rep: Reputation: 407Reputation: 407Reputation: 407Reputation: 407Reputation: 407
Quote:
Originally Posted by burschik View Post
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.

One can read this: http://perldoc.perl.org/perlfilter.html .

I haven't written a filter of such kind myself, but there is a number of very handy filters written by others.

With those filters the code will look like

Code:
macro(@my_array)
I believe.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Perl vs. Ruby vs. Python vargadanis Programming 53 12-31-2010 12:37 PM
Python, Java, or Ruby? Doctorzongo Programming 9 03-31-2008 11:14 PM
How to install Python and Ruby on DSL? sajro DamnSmallLinux 1 01-15-2008 02:51 PM
Which of theese three to begin with? C++/Python/Ruby seimour Programming 11 03-07-2007 02:57 PM


All times are GMT -5. The time now is 08:53 AM.

Main Menu
 
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration