Lisp notation

6 views
Skip to first unread message

r2

unread,
Sep 9, 2009, 2:04:07 PM9/9/09
to Programming Nu
Hi, I'm new to this group and very curious about Nu, looks like a very
powerfull tool. I've allways liked lisp but never really got into it,
like many others the notation has sent me away and distracted into
other things. I bring this subject here because Nu looks like a very
open minded project, taking the best ideas for the task at hand. I
don't pretend to change lisp or to know anything better than others,
just the opposite, I simplyt have an idea and would like to hear what
others with more experience think about it.

What I thinks is the problem for me is not lists or the prefix
notation, and not even the parenthesis, but the many nested level wich
makes lisp code look confusing some times. When you see something like
this:

(define (f x y)
(let ((a (+ 1 (* x y)))
(b (- 1 y)))
(+ (* x (square a))
(* y b)
(* a b))))

It's easy to get lost about what's actually happening.
Of course you can use indentation to make it better:

(define (f x y)

 (let ((a (+ 1 (* x y)))
(b (- 1 y)))

 (+ (* x (square a))

 (* y b)
(* a b))))

Better, but still I find myself counting parenthesis to really get it,
and bad placed parenthesis can have unpredictable results.
If we align parenthesis vertically it's a lot mor clear what's inside
of what:

(define (f x y)
 (let
(
(a (+ 1 (* x y)))
(b (- 1 y))
)
(+
(* x (square a))

 (* y b)

 (* a b)
)
)
)

But, this seems redundant to me, indentation and parenthesis are doing
the same thing, why not DRY it?

define (f x y)

 let
a (+ 1 (* x y))
b (- 1 y)
+
* x (square a)

 * y b

 * a b

Look very clean, and none of the good things about lisp notation is
lost, you can mix parenthesis and indentation however you like whith
the exact same meaningm and converting from this notation to standard
lisp is mechanic and easy. I'd love to be able to write code like this
and use it for lisp (or Nu) development.

I hope indentation is clear, don't know if it's possible to use fixed
spacing on this groups.
What do you think?

Arturo.

Jakub Piotr Cłapa

unread,
Sep 9, 2009, 3:24:02 PM9/9/09
to program...@googlegroups.com
On 09-09-09 20:04, r2 wrote:
> I hope indentation is clear, don't know if it's possible to use fixed
> spacing on this groups.
> What do you think?

There were at least several attempts at bringing some better syntax
(including meaningful indentation) to various Lisps. None of them really
succeeded but you may look at the more recent ones for Scheme to get
some inspiration:
http://srfi.schemers.org/srfi-49/srfi-49.html
http://www.dwheeler.com/readable/readable-s-expressions.html

Both contain a working reader (implemented in Scheme but it should not
be very hard to port it) and discuss some corner cases.

--
regards,
Jakub Piotr Cłapa

stephen white

unread,
Sep 9, 2009, 3:25:40 PM9/9/09
to program...@googlegroups.com
On 10/09/2009, at 3:34 AM, r2 wrote:
> I hope indentation is clear, don't know if it's possible to use fixed
> spacing on this groups.
> What do you think?


I think your idea is very interesting and would like to try it out. It
would be a very lightweight option!

--
st...@adam.com.au


Tim Burks

unread,
Sep 9, 2009, 3:45:46 PM9/9/09
to program...@googlegroups.com
Hi Arturo,

I think the best way to get a feel for a notation this would be to
write a reader/converter for it and then start writing some nontrivial
programs with it. Feel free to use any code that I've posted as
examples to convert. Intuitively, I think you'll find it to be more
constraining than you expect, but your mileage may vary!

Tim

r2

unread,
Sep 9, 2009, 6:52:31 PM9/9/09
to Programming Nu
Thanks for the links Jakub, the first one is very similar to what I
think, the second one I think is going too far and trades up too much
power for readability. I remember how the Winston-Horn book teaches S-
expressions like boxes inside of boxes, and how those horizontally
nested boxes translate to parenthesis. Well, this indentation thing is
like boxes in the vertical direction instead of the horizontal, so
nothing of the s-exp's power should be lost, i think of it more like
an alternative graphical representation of S-exps, not a new notation
at all. S-exps are also an abreviation of dotted pair notation, wich
is closer to internal lisp data implementation. If it works ok it
would be great to have a lisp system (maybe Nu) wich accepts this
extension to the notation.

I'll work a little more with this, see how the translation should be
made and use some of the code posted by Tim and see how it goes.
Thanks for your comments.

Jason Grossman

unread,
Sep 9, 2009, 7:29:03 PM9/9/09
to program...@googlegroups.com
I like this idea. I once implemented exactly the same thing for Io.
(Io doesn't use S-expressions, but it does use brackets a lot, and
wherever there are brackets indentation can be used instead.) I only
dropped it because it's difficult to implement properly in Io, which
has a complicated parser. My implementation sucked. In Nu, it should
be possible to implement very cleanly.

stuntmouse

unread,
Sep 9, 2009, 10:12:49 PM9/9/09
to Programming Nu
Welcome to Nu!

It looks like you're reinventing python, which is definitely *not* my
cup of tea :)

I'd suggest waiting till you wrap your head around macros before you
criticize Lisp's lack of syntax.

Also, writing Lisp really requires that you have an editor that can do
proper highlighting and indention. Since you're probably on a Mac,
I'd highly suggest Aquamacs.

In general, Lisp and Emacs both have learning curves, but they're well
worth the effort.

Best regards,
SM

stuntmouse

unread,
Sep 9, 2009, 10:17:27 PM9/9/09
to Programming Nu
By the way, once you let Emacs format this code, you get something I
find pretty readable:

(define (f x y)
(let ((a (+ 1 (* x y)))
(b (- 1 y)))
(+ (* x (square a))
(* y b)
(* a b))))


Phil Rand

unread,
Sep 9, 2009, 11:13:05 PM9/9/09
to program...@googlegroups.com
I think every (smart) programmer, on first encountering s-expressions, thinks for a while about alternative representations that would retain the power of sexps, but be easier to understand.  I don't take it as a criticism of lispy syntax, necessarily, just a natural reaction to it.  It's a sign of an active mind.   And of course it's a fine old tradition that goes all the way back to the father of lisp, John McCarthy.  Arturo is in very good company.  It would be cool if he could come up with something truly new, but I'm not holding my breath ;-)

Somewhere on the inter-tubes, I saw a small lisp program, formatted with indentation in the conventional way, but rendered with colors or fonts so the parentheses nearly blended into the background, while all the atoms stood out boldly.  I don't remember if they were actually proposing that rendering for actual use in an editor, but they were certainly making the point that, for experienced lisp programmers, the parentheses become less of an issue, and the program structure stands out nicely.  Having nice editors that can do the indentation automatically helps a lot, of course.
--
Phil Rand
phil...@gmail.com
phil...@pobox.com

r2

unread,
Sep 10, 2009, 3:17:20 AM9/10/09
to Programming Nu
 It would be cool if he could come up with something truly new, but
> I'm not holding my breath ;-)
>

You Shouldn't, I'm not pretending this to be a great thing, if it's of
any use it would be just a formating feature, and absolutely optional.
I wouldn't even think about it if it where not for the clear
redundancy I see using indentation and parenthesis for the same thing,
the idea is to ignore indentation if the block starts with a
parenthesis and use it if it doesn't. I don't like python much myself
either, but love Ruby and maybe that's where the DRY obsession comes
from. I'm shure with experience parenthesis are not a big deal, but
not everyone has experience.

stephen white

unread,
Sep 10, 2009, 6:22:20 AM9/10/09
to program...@googlegroups.com
On 10/09/2009, at 4:47 PM, r2 wrote:
> the idea is to ignore indentation if the block starts with a
> parenthesis and use it if it doesn't. I don't like python much myself
> either, but love Ruby and maybe that's where the DRY obsession


I agree with you that it's worth trying, and I agree with Tim that
it's going to have some constraints.

Your idea for ignoring indentation on lines that start with a '(' is
an interesting one that neatly solves a problem I thought you were
going to have.

When I see Lisp without ()'s, I also see Ruby and not Python.

--
st...@adam.com.au


stephen white

unread,
Sep 15, 2009, 10:34:49 PM9/15/09
to program...@googlegroups.com
On 10/09/2009, at 4:47 PM, r2 wrote:
> I wouldn't even think about it if it where not for the clear
> redundancy I see using indentation and parenthesis for the same thing,


This popped up in my news feed:

http://www.genyris.com/

--
st...@adam.com.au


r2

unread,
Sep 16, 2009, 9:01:27 AM9/16/09
to Programming Nu
>
> This popped up in my news feed:
>
> http://www.genyris.com/
>

Very interesting Stephen, and very very close to what I've been
thinking of, though I see a few differences:

They call it a Language, the Lispin language, I don't see this as a
new language at all, just as an addition to the reader, merely an
extension to formatting wich would transparently accept indented code
or regular lisp code, everything else is the same. And that's the
other thing I see, regular lisp code will give an error with lispin
and that's a mayor drawback in my opinion, no experienced lisp
programmer would want to use that. I see the potential for something
absolutely transparent wich doesn't affect anything with the language
but allows the programmer to use a much less cluttered notation, that
could be a big help for the beginner and something nice for the
experienced, only if he/she want's to use it.

When I get a little free time I'll start working on it and using it on
example code, thanks for all the links and comments, hopefully you'll
convince me it's not necessary or it's allready been made, less work
is allways a good thing, but I really want to use lisp and can't get
this idea out of my head.

stephen white

unread,
Sep 16, 2009, 9:55:30 AM9/16/09
to program...@googlegroups.com
On 16/09/2009, at 10:31 PM, r2 wrote:
> convince me it's not necessary or it's allready been made, less work
> is allways a good thing, but I really want to use lisp and can't get
> this idea out of my head.


i think that if you just used the brackets, then you would get used to
it like everyone else. Having said that, it is certainly one of the
obstacles that make a large number of people move onto something else.

I share your interest in the indenting idea, even though I can ignore
the brackets if I want to. It would be entirely based on being a pure
transform of text, such that S-expr and indentation is equivalent.

A lot of people can't get past Python's mandatory indenting, so it is
a bit ironic that Lisp would end up with two options, both of which
annoy large groups of people. :) Too bad for them, really.

--
st...@adam.com.au

Jason Grossman

unread,
Sep 16, 2009, 5:42:37 PM9/16/09
to Programming Nu

> i think that if you just used the brackets, then you would get used to  
> it like everyone else. Having said that, it is certainly one of the  
> obstacles that make a large number of people move onto something else.

IIRC, the point of Arturo's idea is not just annoyance with brackets;
it's also that we could be using indentation semantically, instead of
indentation being redundant. That's my view, anyway!


> I share your interest in the indenting idea, even though I can ignore  
> the brackets if I want to. It would be entirely based on being a pure  
> transform of text, such that S-expr and indentation is equivalent.

I agree on both points. The second one is really crucial, I think,
and it's what separates Arturo's idea really clearly from e.g.
Python. Arturo's language (this needs a name! ... I called my similar
language Pony, FWIW) would be TRIVIALLY convertible back to standard
Nu, by a human or by a macro.


> A lot of people can't get past Python's mandatory indenting, so it is  
> a bit ironic that Lisp would end up with two options, both of which  
> annoy large groups of people. :) Too bad for them, really.

LOL.

Jason

sasha

unread,
Sep 17, 2009, 3:31:29 AM9/17/09
to Programming Nu
Hi,

I'm one of that people, that hardly can adopt the Python's indentation
based syntax. And I'm happy with Nu's lisp syntax. That gives so much
convenience to manipulate with the program structure during editing.
I'd rather get rid of the "here string" syntax, that breaks S-exps
syntax in Nu, and fix the usual string syntax to allow multiline
strings, to make Nu more lispy.

I think that Nu will lost a lot of it's charm without it's lispy
syntax. And there is already F-Script, that is quite interesting and
nice language. It doesn't have parens, but this doesn't make it a very
popular.

Aleksandr
Reply all
Reply to author
Forward
0 new messages