On Mon, Feb 23, 2009 at 10:42 AM, Mark Volkmann
<r.mark.volkm...@gmail.com> wrote:
>
> I have an idea I'd like to float to see if there are reasons why it's
> a bad idea.
>
> What if Clojure had an alternate "surface" syntax that was translated
> into standard Clojure syntax by a kind of preprocessor?
>
> Many people that don't like Lisp dialects don't like them because of
> the parentheses. I'm trying to address that.
>
> Here's a simple example of valid Clojure code.
>
> (defn pig-latin [word]
>  (let [first-letter (first word)]
>    (if (.contains "aeiou" (str first-letter))
>      (str word "ay")
>      (str (subs word 1) first-letter "ay"))))
>
> (println (pig-latin "red"))
> (println (pig-latin "orange"))
>
> Here's what that same code would look like in my alternate syntax.
>
> defn pig-latin [word]
>  let [first-letter (first word)]
>    if .contains "aeiou" (str first-letter)
>      str word "ay"
>      str (subs word 1) first-letter "ay"
>
> println (pig-latin "red")
> println (pig-latin "orange")
>
> The rules for turning this into standard Clojure syntax are pretty simple.
>
> 1) If a line is indented farther than the previous one, it is part of
> the previous line.
> 2) If a line doesn't start with a (, then add one.
> 3) If the next line is indented less than this one, add the
> appropriate number of )'s at the end.
> 4) If the first token on a line is "if" and the first non-whitespace
> character after it is not (
>    then assume the rest of the line is the condition and wrap it in ( ).
>

If the procedure application uses a nested expression to select the
procedure to apply, it looks like using your heuristics, the
parentheses cannot be omitted:

Clojure:
((if (< x 0) - +) x)

Haskell: (s-expression with optional parentheses and infix operators):
(if (x < 0) then (\x -> -x) else id) x

Using your proposed rules, this does not work
(if (< x 0) - +) x

as the line starts with parentheses, and so the parser will assume
parentheses do not need to be added

A Haskell-like parser would be kind of cool, though -- is it worth the hassle?

-- 
miʃel salim  •  http://hircus.jaiku.com/
IUCS         •  msa...@cs.indiana.edu
Fedora       •  sali...@fedoraproject.org
MacPorts     •  hir...@macports.org

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to