sweet-expressions instead of s-expressions?
- From: "Neil Toronto" <neil.toronto@xxxxxxxxx>
- Date: 23 Sep 2006 11:49:17 -0700
Quick background from the newb: Programmer for 22 years with assembly
and standard C-like imperatives, just recently became proficient in
Python and becoming interested in Common Lisp. Why? I want the
functional goodness and the MACROS, that's why. Also, I do computer
vision and machine learning research, and my Python code is rather
slow. I'd like something that's almost as fast as C but very
expressive, and is strict but highly dynamic and dynamically-typed.
Here's what's keeping me with Python: my code reads like pseudocode,
and I love that. When I come back to Python code I haven't seen in
months, it takes me all of five seconds to grok it again.
So has anyone seen this?
http://www.dwheeler.com/readable/readable-s-expressions.html
Short version: significant whitespace (indentation can replace parens),
"func(param1 param2)" calls, infix notation (which is good for math
code), and it still parses regular s-expressions correctly. Because it
transforms "sweet-expressions" to s-expressions, macros still work.
Example:
defun factorial (n)
if (n <= 1)
1
n * factorial(n - 1)
(which even I can parse :D) is translated to:
(defun factorial (n)
(if (<= n 1)
1
(* n (factorial (- n 1)))))
(which I can still parse, but with more trouble). Or this:
(2 + mystuff(7 + x) * -(henry) - correction(a b c d) + 2 - pi() - x)
which is translated to this:
(- (+ (- (+ 2 (* (mystuff (+ 7 x)) (- henry)))
(correction a b c d)) 2) (pi) x)
He's almost got me convinced.
I understand that experienced Lispers use indentation to understand
code more than parenthesis anyway. This creates a situation (rather
like in C-like languages) where the language syntax *doesn't inherently
communicate with the coder very well*, and coder has to add redundant
formatting to make it clear. Then, like in IDEs for C-like languages,
the editors support this to make programming less painful. So why not
take the Python route and make formatting syntactically significant?
The only difference is that Python requires it, "sweet-expressions"
don't.
My main question is whether there are any downsides at all to this
approach.
And as an aside, I'd love to have Python's array (list) and dictionary
(hash table) syntax. I'd switch to Lisp and convert my entire codebase
TODAY if I had that.
.
- Follow-Ups:
- Re: sweet-expressions instead of s-expressions?
- From: Kaz Kylheku
- Re: sweet-expressions instead of s-expressions?
- From: Andras Simon
- Re: sweet-expressions instead of s-expressions?
- From: JShrager
- Re: sweet-expressions instead of s-expressions?
- From: Lars Rune Nøstdal
- Re: sweet-expressions instead of s-expressions?
- From: Pascal Bourguignon
- Re: sweet-expressions instead of s-expressions?
- From: Stephen Compall
- Re: sweet-expressions instead of s-expressions?
- From: Ari Johnson
- Re: sweet-expressions instead of s-expressions?
- From: Pascal Costanza
- Re: sweet-expressions instead of s-expressions?
- From: Ken Tilton
- Re: sweet-expressions instead of s-expressions?
- From: vsedach
- Re: sweet-expressions instead of s-expressions?
- Prev by Date: Re: Handling Complexity Using Lisp
- Next by Date: Re: Handling Complexity Using Lisp
- Previous by thread: Updating struct value(s) using macro call from function
- Next by thread: Re: sweet-expressions instead of s-expressions?
- Index(es):
Relevant Pages
|