Re: Sweet-expressions

677 views
Skip to first unread message

Herwig Hochleitner

unread,
Mar 25, 2013, 1:13:46 PM3/25/13
to clo...@googlegroups.com
Oh, it's this thread again. Please read https://groups.google.com/d/topic/clojure/TB4i3ATmrEE/discussion before discussing further.

TLDR: If you want to demonstrate the merits of significant white space for clojure, please implement a reader with the alternative rules you envision.
Right now, the community seems to sway towards sticking with s-expressions.

Personally: The sentiment on readable.sourceforge.net ("... a language that makes source code ugly is maddening to an exacting programmer ...") doesn't convince me, since find clojure code neither ugly nor maddening, while I do consider myself exacting. Also the small example, literally contrasting "(Awkward) S-expression" with "(Improved) Sweet-expression" doesn't lend much credibility.
Another problem: Curly braces as syntax are already taken in clojure. I haven't watched the video yet, but will do so later.

Ben Wolfson

unread,
Mar 25, 2013, 1:19:37 PM3/25/13
to clo...@googlegroups.com
One difficulty in that transformation for clojure might be that "{"
already has significance to the clojure reader, denoting the beginning
of a map literal.

If { in that notation is exclusively used for infix binary operations,
you could get around it, because in that context the {...} expression
would always have exactly three elements, which isn't legal for a map.
But it would increase potential confusion:

{1 <} is a map from the integer 1 to the function <

{1 < 2} is the application of < to the arguments 1 and 2

(Odd seeing you here, dominic!)

On Mon, Mar 25, 2013 at 3:52 AM, poetix <domin...@gmail.com> wrote:
> I really like the look of this:
>
> http://readable.sourceforge.net/
>
> which defines a completely reversible transformation between e.g.
>
> define fibfast(n)
> if {n < 2}
> n
> fibup(n 2 1 0)
>
> and
>
> (define (fibfast n)
> (if (< n 2)
> n
> (fibup n 2 1 0)))
>
>
> and wonder how difficult it would be to support it (or something like it)
> in/for Clojure. A coffeescript-like approach might be a good first step.
>
> Any thoughts?
>
> Dominic
>
> --
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clo...@googlegroups.com
> Note that posts from new members are moderated - please be patient with your
> first post.
> To unsubscribe from this group, send email to
> clojure+u...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
> ---
> You received this message because you are subscribed to the Google Groups
> "Clojure" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to clojure+u...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>



--
Ben Wolfson
"Human kind has used its intelligence to vary the flavour of drinks,
which may be sweet, aromatic, fermented or spirit-based. ... Family
and social life also offer numerous other occasions to consume drinks
for pleasure." [Larousse, "Drink" entry]

Laurent PETIT

unread,
Mar 25, 2013, 1:21:57 PM3/25/13
to clo...@googlegroups.com
As stated in the web site, there are sometimes different needs while
creating/editing, and while reading.

I see no need to create a second edition syntax.

It may be interesting (and potentially way easier to prototype / play
with the idea) to only provide alternative "views" of clojure code.

My 0,02€,

--
Laurent

2013/3/25 poetix <domin...@gmail.com>:

Antoine Noo

unread,
Mar 25, 2013, 2:16:20 PM3/25/13
to clo...@googlegroups.com
Some idea for alternative clojure syntax:

(first | first coll) ; (first (first coll))
(count | first | second coll) ; (count (first (second coll)))
(nth % 2 | first coll) ; (nth (first coll) 2)

(+ 1)# ; (partial + 1)
(+ 1 (* 2))## ; (fn [nb] (+ 1 (* 2 %))

(count | first | second)## ; (fn [coll] (count (first (second coll))))
(nth | first | second coll)# ; (fn [nb] (nth (first (second coll)) nb))


2013/3/25 Laurent PETIT <lauren...@gmail.com>

Timothy Baldridge

unread,
Mar 25, 2013, 2:20:41 PM3/25/13
to clo...@googlegroups.com
(first | first coll) ; (first (first coll))
(count | first | second coll) ; (count (first (second coll)))
(nth % 2 | first coll) ; (nth (first coll) 2)

How is this better than the threading macro?

(-> coll first first)

(-> coll second first count)

(-> coll first (nth 2))


Timothy Baldridge
“One of the main causes of the fall of the Roman Empire was that–lacking zero–they had no way to indicate successful termination of their C programs.”
(Robert Firth)

Kris Jenkins

unread,
Mar 25, 2013, 6:44:04 PM3/25/13
to clo...@googlegroups.com
As an interesting point of trivia, the idea of abandoning S-expressions for some other notation actually pre-dates the first implementation of Lisp. S-expressions were originally intended as a temporary measure, before a more familiar representation - deemed M-expressions - could be formalized. But in the words of John McCarthy:

"The project of defining M-expressions precisely and compiling them or at least translating them into S-expressions was neither finalized nor explicitly abandoned. It just receded into the indefinite future, and a new generation of programmers appeared who preferred internal notation to any FORTRAN-like or ALGOL-like notation that could be devised." The History Of Lisp

In short, the idea of abandoning S-expressions has fair claim to be one of the oldest ideas in Lisp. My personal theory about that is that by the time someone knows enough Lisp to do a decent job of the translation, they no longer see any problem...

Kris

Jason Lewis

unread,
Mar 25, 2013, 9:02:34 PM3/25/13
to clo...@googlegroups.com
NOOOOOOOOOOOO!!!!!!!!



Jason Lewis

Email          jasonl...@gmail.com     

Twitter        @canweriotnow

Blog           http://decomplecting.org

About         http://about.me/jason.lewis


--

Joseph Smith

unread,
Mar 25, 2013, 11:03:38 PM3/25/13
to clo...@googlegroups.com
I never have understood the obsession with moving the parens in Lisp to the same place they are in C-like languages. I'm not typing any less, and it certainly undermines the code = data (i.e. lisp lists / function calls) homoiconic representation. Is it "clearer"? Maybe to someone unaccustomed to Lisp, but it's a very superficial thing- you get used to it (and these days I screw up interpreting/writing my C-lang code bc/ I'm used to Lisp). 

Regarding infix vs. postfix, it doesn't take a Lisper long to appreciate the advantages of prefix notation, e.g. (+ 1 8 9 3) vs 1 + 8 + 9 + 3. 

There is a (arguably, at least) Lisp out there with hardly any parens- Haskell. :D

david sheldrick

unread,
Mar 26, 2013, 1:18:51 PM3/26/13
to clo...@googlegroups.com
I don't like the idea of infix math as a reader macro. Yeah prefix is weird to read for complex expressions, but in such rare cases there are ordinary macros that let you do infix math. Use them.

An interesting thought I had the other day regarding infix math:
It would be possible for Clojure to provide it's own implementations of the basic number classes (Integer, Long, Double, etc) that implement IFn such that they take a function and another number and apply themselves and the other number to the function.

Then we could just write (2 + 5).

I imagine this has all kinds of downsides regarding optimisation and what to do with numbers that get emitted from java code and so forth.

Gary Verhaegen

unread,
Mar 26, 2013, 5:34:49 PM3/26/13
to clo...@googlegroups.com
Right now, Clojure is fighting its way to get to Java-like performance
for numerics, and that involves emitting primitive numbers and
operations whenever possible. I'm afraid that would be utterly
incompatible with turning numbers into functions - that would be at
least two levels of indirection (numbers would have to be objects, and
these objects would have to implement IFn).

Nice idea on a conceptual level, though.

JvJ

unread,
Mar 31, 2013, 12:05:52 AM3/31/13
to clo...@googlegroups.com
Once you write enough lisp, eliminating parens becomes more trouble than it's worth.

Also the guy who did this has the same name as my dad?  I'm ashamed.
Reply all
Reply to author
Forward
0 new messages