Indent version lisp

For the Compleat Fan
Locked
LoveVirus
Posts: 4
Joined: Fri Dec 13, 2013 1:25 pm

Indent version lisp

Post by LoveVirus »

Many people complain that LISP braces too, because the formatted LISP code itself is a hierarchical structure, then we can learn about the format of the python, use indentation to indicate the level, remove the bracket. For example:
QQ截图20140805125316.png
QQ截图20140805125316.png (741 Bytes) Viewed 14377 times
In this way, both for the convenience of reading, but also reduces the number of characters,
Last edited by LoveVirus on Tue Aug 05, 2014 5:03 am, edited 2 times in total.

TedWalther
Posts: 608
Joined: Mon Feb 05, 2007 1:04 am
Location: Abbotsford, BC
Contact:

Re: Indent version lisp

Post by TedWalther »

You mean like Lispin? The website is offline, but I suppose it could be fairly easily implemented as a front end filter for newLISP. Be a neat thing to do. I'll put it on my todo list; perhaps by the end of August I'll have a spare couple hours and hack it up; looks easy to implement.

http://wayback.archive.org/web/20080517 ... ontolispin
Cavemen in bearskins invaded the ivory towers of Artificial Intelligence. Nine months later, they left with a baby named newLISP. The women of the ivory towers wept and wailed. "Abomination!" they cried.

LoveVirus
Posts: 4
Joined: Fri Dec 13, 2013 1:25 pm

Re: Indent version lisp

Post by LoveVirus »

Ha ha, very glad you approve of my idea!

TedWalther
Posts: 608
Joined: Mon Feb 05, 2007 1:04 am
Location: Abbotsford, BC
Contact:

Re: Indent version lisp

Post by TedWalther »

LoveVirus wrote:Ha ha, very glad you approve of my idea!
It is a very old idea in LISP circles. Here, read this: http://sourceforge.net/p/readable/wiki/Solution/

"sweet expressions" have been in development for a very long time. A stripped down version of them could be easily turned into newLISP. But I'd want to also have it go the other way, turning newLISP code into sweet expressions, so people could edit in one or the other, and have it convert back to where it belongs.

http://srfi.schemers.org/srfi-110/srfi-110.html

Actually, newLISP probably makes sweet expressions easier to implement than scheme or Common Lisp. However, the [] and {} syntax wouldn't make the transfer.

Too bad there is no EBNF grammar for newLISP; I'd dearly love to run it through the railway diagram generator. (Found here: http://bottlecaps.de/rr/ui)
Cavemen in bearskins invaded the ivory towers of Artificial Intelligence. Nine months later, they left with a baby named newLISP. The women of the ivory towers wept and wailed. "Abomination!" they cried.

HPW
Posts: 1390
Joined: Thu Sep 26, 2002 9:15 am
Location: Germany
Contact:

Re: Indent version lisp

Post by HPW »

In the past there were often discussion about Lisp-style and indention.
For my taste it is not a good idea to remove any braces.
I find Python's use of indention for programm flow a very bad idea, especially for longer code blocks.
My prefered indention style:

Code: Select all

(+ 1
   2
   (* 2
      3
   )
)
My used Editor automaticly highlights any matching braces and draw a thin vertical line from start-brace to end brace.

For released production code I use a tool to remove unneeded whitespace and linebreaks to get a compact Lisp stream for optimum load-performance resulting in a one-liner:

Code: Select all

(+ 1 2(* 2 3))
Regards
Hans-Peter

cormullion
Posts: 2038
Joined: Tue Nov 29, 2005 8:28 pm
Location: latiitude 50N longitude 3W
Contact:

Re: Indent version lisp

Post by cormullion »

I tried it, and soon started to miss the parentheses.

Code: Select all

#!/usr/bin/newlisp
define D:D
map 
	fn
		x     
		D x 
			inc 
				D x     
	explode
		read-file
			
				main-args 2
map 
	fn 
		p 
		println 
			p 0 "\t:\t" 
			p 1 
	D
exit
or

Code: Select all

#!/usr/bin/newlisp

(define D:D)

(map (fn (x)
     (D x (inc (D x))))
     (explode (read-file ((main-args) 2))))

(map (fn (p) 
              (println (p 0) "\t:\t" (p 1))) 
         (D))
(exit)

The script I used:

Code: Select all

(set 'the-data  (explode (read-file (nth 2 (main-args)))))

(set 'level 0)
(define (start-list)
  (print "\n" (dup "\t" level))
  (inc level))

(define (close-list)  
  (dec level))
            
(dolist (c the-data)
    (cond
        ((= c "(")    
                (start-list)
                )
        ((= c ")")
                (close-list))
        (true 
                (print (trim c "\n")))))
(exit)
Of course, it breaks if the strings contains parentheses, so it doesn't run on itself... :)

TedWalther
Posts: 608
Joined: Mon Feb 05, 2007 1:04 am
Location: Abbotsford, BC
Contact:

Re: Indent version lisp

Post by TedWalther »

Hi cormullion. Yes, the lispin and sweet-expression guys thought of that, their solutions avoid the type of problem you showed in your example.

With a tool to convert to and from newlisp, you could play with pythonesque syntax without losing anything. Linecount would increase marginally.
Cavemen in bearskins invaded the ivory towers of Artificial Intelligence. Nine months later, they left with a baby named newLISP. The women of the ivory towers wept and wailed. "Abomination!" they cried.

rickyboy
Posts: 607
Joined: Fri Apr 08, 2005 7:13 pm
Location: Front Royal, Virginia

Re: Indent version lisp

Post by rickyboy »

TedWalther wrote:... Here, read this: http://sourceforge.net/p/readable/wiki/Solution/

... "sweet expressions" ...

http://srfi.schemers.org/srfi-110/srfi-110.html
Good Lord, is that bloody awful.[1] I'm with cormullion.

People who like the sort of things as "sweet expressions" may not yet perceive the beauty in s-expressions. The beauty comes from the s-expression's regularity and generality, and the way I see it, combined with the standard indentation, they are easier to read than "sweet expressions."[2]

Let's keep the "syntax" simple. We don't need to tax our minds remembering the vagaries of syntax born from Blub. Better to have that eliminated -- which s-expressions do -- so that we can instead focus our minds on the problem at hand.

On the other hand, perhaps I'm a dinosaur. :) I'm curious to see what you come up with, Ted.
___________
[1] Especially, check out the examples in SRFI 110 in the "Tutorial" after the "Basics" section.

[2] Indeed, that's the very purpose of the standard indentation. And as HPW noted, a good editor can make writing s-expressions very easy.
(λx. x x) (λx. x x)

TedWalther
Posts: 608
Joined: Mon Feb 05, 2007 1:04 am
Location: Abbotsford, BC
Contact:

Re: Indent version lisp

Post by TedWalther »

Cormullion, is your newlisp parser up to date with the latest 10.6 release of newlisp? I'd like to use it as the basis for my experiments with what I am tentatively calling "newlispy" Or maybe "newlis.py" :)
Cavemen in bearskins invaded the ivory towers of Artificial Intelligence. Nine months later, they left with a baby named newLISP. The women of the ivory towers wept and wailed. "Abomination!" they cried.

cormullion
Posts: 2038
Joined: Tue Nov 29, 2005 8:28 pm
Location: latiitude 50N longitude 3W
Contact:

Re: Indent version lisp

Post by cormullion »

Well I don't test my code very thoroughly .. :) but I remember adding something for bigints earlier, so it kind of works, and it's not too far behind. Pull requests accepted!

TedWalther
Posts: 608
Joined: Mon Feb 05, 2007 1:04 am
Location: Abbotsford, BC
Contact:

Re: Indent version lisp

Post by TedWalther »

Does Lutz have a handrolled parser, or does he use lex/yacc? An EBNF grammar would make this so much easier. Is there one?
Cavemen in bearskins invaded the ivory towers of Artificial Intelligence. Nine months later, they left with a baby named newLISP. The women of the ivory towers wept and wailed. "Abomination!" they cried.

Locked