LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Lisp, Ruby, or python (https://www.linuxquestions.org/questions/programming-9/lisp-ruby-or-python-698998/)

Sergei Steshenko 01-23-2009 09:32 PM

Quote:

Originally Posted by rweaver (Post 3418563)
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.

Sergei Steshenko 01-23-2009 09:48 PM

Quote:

Originally Posted by burschik (Post 3418565)
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>


taylor_venable 01-23-2009 10:25 PM

Quote:

Originally Posted by Sergei Steshenko (Post 3419268)
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.

Su-Shee 01-26-2009 12:00 PM

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/

burschik 01-27-2009 01:57 AM

Quote:

Originally Posted by Sergei Steshenko (Post 3419279)
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.

Sergei Steshenko 01-27-2009 02:49 AM

Quote:

Originally Posted by burschik (Post 3422488)
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.


All times are GMT -5. The time now is 04:37 PM.