sweet-expressions instead of s-expressions?



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.

.



Relevant Pages

  • Re: Too much code - slicing
    ... Apart from occasions like this and throwaway one-liners I use regular ... If Python had added the C-like a? ...
    (comp.lang.python)
  • Re: On-topic: alternate Python implementations
    ... CPython runtime and allows for easy manual optimisations to get C-like ... Cython is great, but I question that it is a *Python* implementation. ...
    (comp.lang.python)
  • Re: Python syntax in Lisp and Scheme
    ... dislike blatantly arguing with people over language choice. ... I think that if you can get over S-exps then Scheme and Common Lisp ... feel very like python. ...
    (comp.lang.lisp)
  • Re: Python or PHP?
    ... If it's one of the things for which Python ... every language here and there more ways to do something. ... you make Perl more complicated than it is:-D. ... Not the programmer. ...
    (comp.lang.python)
  • Re: Attack a sacred Python Cow
    ... Prove that implicit self is a good idea -- ... The issue here has nothing to do with the inner workings of the Python ... needs to be supplied by the programmer. ... It just occurred to me that Python could allow the ".member" access ...
    (comp.lang.python)