A Lisp syntax with fewer parentheses

JiyinYiyong
Cirru Project
Published in
3 min readMay 10, 2015

It’s cool idea to “Code in AST” in Lisp. But it would be more elegant if Lisp requires fewer parentheses.

Back in 2012, I got an idea on writing syntax tree without parentheses. And that is creating a structured text editor which generates syntax tree directly. And I call it Cirru Editor.

Since 2013, I realized the text based syntax is still vital in this decade, I began to learn basic knowledges on text parsing from my friends and implementd Cirru Parser. Today Cirru Parser is available in CoffeeScript, Go Language, Haskell, Racket, Julia, Ruby. It’s quite easy to port to other high level languages.

Here’re some Demos of Cirru Parser:

set a 4
set a (+ 1 2)
set b
+ 3 4

It’s just like Racket with fewer parentheses. I would use indentations to create blocks. You see, it’s really simple(notice that you must keep the closing parenthesis in same line with its opening one).

And to make Cirru Syntax better fitted to real programming langauges, I also borrowed syntax from Haskell and CoffeeScript:

set a $ + 1 2
;; same as
set a (+ 1 2)

It’s not hard to to understand. A “$” turns followed words into an expression,

+ a
+ 1 2
, 3 4 5
;; same as
+ a (+ 1 2) (, 3 4 5)
;; also
+ a (+ 1 2) 3 4 5

And a “,” breaks the expression it belongs apart into several words(or expressions).

However, Cirru does contain tricky parts in representing strings in Cirru. Oops, it behaves like a Bash(double quotes are only for escaping):

print "data"
;; same as
print data

As a result people have to explicitly convert a symbol into string before printing:

print (string data)

Quotes are required when a node contains whitespace!

print (string "node with whitespace inside")

Anyway I can code in Cirru now. I created CirruScript and started writing JavaScript with indentations:

= list $ array 1 2 3 4 5
= obj $ object (:a 1) (:b 2)

for (list index item)
console.log item index

for (obj key value)
console.log key value

But JavaScript is a boring language, at least not as fun as Racket. Let’s try if we can write Racket in Cirru Syntax. After I digging into Racket, I got a tiny demo:

define (add1 x)
+ x 1
print (add1 3)define (add-str a b)
string-append a b
print (add-str :aaa :bbb)define l1 (list 1 2 3 4 5)
define (show x)
display x
displayln :
for-each show l1print “:test if:”
print (if (> 2 1) 2 3)
print (if #t 2 3)

It is just 1) parsing the text into a Racket list, 2) converting each string item into symbols(or numbers, strings, booleans). Now it’s a quoted expression, just evalute it and this Racket program will run:

(eval list (make-base-namespace)))

It has been three years since I got that idea, wow I can write Lisp with far fewer parentheses. By now that demo is merely a prototype, I just hope it may become a real fun project one day.

Meanwhile I got quite some inspirations playing with Cirru, which you may find on GitHub, Twitter and Cirru.org. I think it looks quite good in Sublime Text too:

Hope you like it. A Lisp syntax with fewer parentheses.

--

--