Only in Lisp

Discussion of Common Lisp
findinglisp
Posts: 447
Joined: Sat Jun 28, 2008 7:49 am
Location: Austin, TX
Contact:

Re: Only in Lisp

Post by findinglisp » Sat Aug 28, 2010 9:59 am

Ramarren wrote:The crippled lambda and statement/expression division in Python alone are enough for me to strongly prefer Lisp over it.
This is one reason that I prefer Ruby over Python. Every time I start writing Python, I get bitten by the fact that statements don't return values and can't be used in expressions. I LOVE the fact that in Lisp and Ruby everything is an expression and returns a value. Sometimes the value is not very useful, but it makes it easy to write code anyplace and have it make sense. With Python, I find myself reworking code to convert expressions to statements or vice-versa.
Cheers, Dave
Slowly but surely the world is finding Lisp. http://www.findinglisp.com/blog/

Kohath
Posts: 61
Joined: Mon Jul 07, 2008 8:06 pm
Location: Toowoomba, Queensland, Australia
Contact:

Re: Only in Lisp

Post by Kohath » Sun Aug 29, 2010 4:53 am

Can this be done in Python :?:

gugamilare
Posts: 406
Joined: Sat Mar 07, 2009 6:17 pm
Location: Brazil
Contact:

Re: Only in Lisp

Post by gugamilare » Sun Aug 29, 2010 8:48 am

findinglisp wrote:
Ramarren wrote:The crippled lambda and statement/expression division in Python alone are enough for me to strongly prefer Lisp over it.
This is one reason that I prefer Ruby over Python. Every time I start writing Python, I get bitten by the fact that statements don't return values and can't be used in expressions. I LOVE the fact that in Lisp and Ruby everything is an expression and returns a value. Sometimes the value is not very useful, but it makes it easy to write code anyplace and have it make sense. With Python, I find myself reworking code to convert expressions to statements or vice-versa.
I also love that in Lisp. I find so odd when you have to explicitly create a variable and assign different values to it. Incredibly people in general find that awkward and end up creating a lot of variables in Lisp (not to mention they use SETF instead of LET). That is actually awkward.

I think it might be the greatest reason for people avoiding to learn Lisp. They make it look like imperative language, like they are used to, which doesn't work well and they just give up.

findinglisp
Posts: 447
Joined: Sat Jun 28, 2008 7:49 am
Location: Austin, TX
Contact:

Re: Only in Lisp

Post by findinglisp » Sun Aug 29, 2010 6:42 pm

August wrote:
Gerenuk wrote: I'd highly appreciate real, short examples in this thread. I hardly know enough Lisp to make up my own, but I can guess what example code means. Can you write out an example, which cannot easily be replicated with Python?
I'm learning Lisp at the moment and use Python fairly regularly but am certainly not an expert. This question is for my own edification as much as anything. Before Python introduced the "with" statement in 2.5, could you have implemented "with" yourself with the same level of integration into the language?

Code: Select all

with open("hello.txt") as f:
    for line in f:
        ---arbitrary code in here----
        print line
In Lisp, this kind of thing is easy.
This is a really important point, and it's one that is easily lost. There is something bigger at work here than just macros (said in an awesome voice).

Lisp, you see, is self-contained and very, very, very evolvable in ways that other languages aren't. The "core" of Lisp, it's special forms, is insanely small. The rules for interpreting Lisp code fit in a few lines (I actually have a coffee cup with the original McCarthy interpreter printed on its side). Everything else is essentially a library routine or macro on top of that core. A full-featured Lisp, like Common Lisp, has slightly more infrastructure, but even that is built on that insanely small core.

Essentially, a Common Lisp implementation works by translating ASCII program text into data structures (sexprs). That step is customizable and a programmer can, using reader macros, change the way the Lisp READ function creates the data structures. This potentially allows you great freedom in customizing the surface syntax that Lisp offers. In practice, most people don't go that far and find that the basic sexpr syntax works just fine. Then, just before the interpreter or compiler gets a crack at the sexpr, it is subject to macro expansion (standard macros, symbol macros, etc.) that again allows potentially radical transformation of the code. Finally, the code gets interpreted/compiled/executed.

It's the small, almost trivially simple core, couple with a flexible set of processing steps that allow radical transformation of the data structures that represent the program code that makes Lisp so flexible. And, of course, since these data structures can be constructed on the fly (code is data is code) it's very easy to write code that writes code.

To me, those things are what Lisp has that no other programming language can really match. The only other language in the same league is Forth. If you look at Lisp and barf because of the parenthesis, then you simply don't get it (yet). I know that I didn't get it for a long time, either. But once you understand it, you never look at another programming language the same. I should also point out that if you look at Forth and just see RPN, you also don't get it.
Cheers, Dave
Slowly but surely the world is finding Lisp. http://www.findinglisp.com/blog/

Post Reply