Page 1 of 1

Indent version lisp

Posted: Tue Aug 05, 2014 1:34 am
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 20050 times
In this way, both for the convenience of reading, but also reduces the number of characters,

Re: Indent version lisp

Posted: Tue Aug 05, 2014 4:30 am
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

Re: Indent version lisp

Posted: Tue Aug 05, 2014 5:08 am
by LoveVirus
Ha ha, very glad you approve of my idea!

Re: Indent version lisp

Posted: Tue Aug 05, 2014 6:30 am
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)

Re: Indent version lisp

Posted: Tue Aug 05, 2014 6:55 am
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

Re: Indent version lisp

Posted: Tue Aug 05, 2014 7:21 am
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... :)

Re: Indent version lisp

Posted: Tue Aug 05, 2014 7:43 am
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.

Re: Indent version lisp

Posted: Tue Aug 05, 2014 3:29 pm
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.

Re: Indent version lisp

Posted: Wed Aug 06, 2014 11:00 pm
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" :)

Re: Indent version lisp

Posted: Wed Aug 06, 2014 11:07 pm
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!

Re: Indent version lisp

Posted: Thu Aug 07, 2014 12:19 am
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?