newLisp competition 2007

Started by newdep, June 05, 2007, 11:17:43 AM

Previous topic - Next topic

Lutz

#30
Congratulations and my best wishes for you, and your growing family. Lets hope little Norman (what is his name?) leaves his amazingly creative dad some time for making more wonderful programs :-)



Lutz

m i c h a e l

#31
Since Lutz has expressed it so well already, let Melissa and I just say: Congratulations on your new boy!



m i c h a e l



P.S. I wonder if your son will one day appreciate that his birth announcement was written in newLISP :-)

newdep

#32
Thanks ! ;-)
-- (define? (Cornflakes))

ghfischer

#33
Although not a complex piece of code, the following is quite useful when you have to sort lists the way most real people think of sorting.



(define (natural-key s)
  (set 'strs (parse s "[0-9]+" 0))
  (set 'nums (find-all "[0-9]+" s))
  (if nums (set 'nums (map int nums)) (set 'nums '()))
  (filter if (flat (transpose (list strs nums))))
)

(define (natural-sort l)
  (sort l (fn (x y) (< (natural-key x) (natural-key y))))
)

(set 'foo '("i19n" "i17n" "z40" "40a" "50" "foo" "z4000" "z30"))

(natural-sort foo)


which returns



("40a" "50" "foo" "i17n" "i19n" "z30" "z40" "z4000")


Based on http://nedbatchelder.com/blog/200712.html#e20071211T054956">Human Sorting

Lutz

#34
But doesn't the plain newLISP 'sort' do this already?


(set 'foo '("i19n" "i17n" "z40" "40a" "50" "foo" "z4000" "z30"))

(sort foo) => ("40a" "50" "foo" "i17n" "i19n" "z30" "z40" "z4000")


Lutz



ps: but the difference will show up with a different example:


(set 'foo '("i19n" "i17n" "z40" "40a" "50" "foo" "z4000" "z80"))

; natural sort
("40a" "50" "foo" "i17n" "i19n" "z40" "z80" "z4000")

; plain sort
("40a" "50" "foo" "i17n" "i19n" "z40" "z4000" "z80")

ghfischer

#35
Good point Lutz.  I should have provided a better example.



Here's the basic case
> (natural-sort '("a10" "a2" "a1" "a14"))
("a1" "a2" "a10" "a14")
> (sort '("a10" "a2" "a1" "a14"))
("a1" "a10" "a14" "a2")


and the embedded case
> (natural-sort '("i30z" "i3n" "i20n" "i18z"))
("i3n" "i18z" "i20n" "i30z")
> (sort '("i30z" "i3n" "i20n" "i18z"))
("i18z" "i20n" "i30z" "i3n")


Of course there's always the edge cases ...
> (natural-sort '("i1" "i03" "i5"))
("i1" "i03" "i5")
> (sort '("i1" "i03" "i5"))
("i03" "i1" "i5")


To me having the zero first seems better.  But to most non-programmers it doesn't.  Hopefully whatever you're sorting in this case will have consistency on leading zeroes.

cormullion

#36
a little too short to get my vote (:-) but it's certainly nice to see you back on the board!

ghfischer

#37
Quote from: "cormullion"a little too short


I also noticed that in 9.2.5 or higher I can make it even shorter! :)


(define (natural-key s)
  (filter if (flat (transpose (list (parse s "[0-9]+" 0) (map int (find-all "[0-9]+" s)))))))

pjot

#38
Folks,



It's time for my contribution: a http://en.wikipedia.org/wiki/Comic_Book_Archive_file">comicbook reader.



It is able to handle .cbr, .cbz and .rar formats, reads JPG, PNG and GIF files. Written with http://www.gtk-server.org">GTK-server because I am porting the newlisp code to another language as well.



Runs in Unix/Linux/Win32. Users of the infamous Win32 platform need to download 'unzip.exe' and 'unrar.exe' separately. See the header of the program for details.



Free comicbooks can be obtained from http://www.flashbackuniverse.com">FlashbackUniverse, http://www.freecomicbooks.org">FreeComicBooks and many other places, including torrentsites (if you have the original copy yourself, of course ;-) )



The code is here: http://www.turtle.dds.nl/newlisp/comic.lsp">//http://www.turtle.dds.nl/newlisp/comic.lsp

The corresponding configfile here: http://www.gtk-server.org/gtk-server.cfg">//http://www.gtk-server.org/gtk-server.cfg



This is a screenshot of the program running in windowed mode, after pressing the right mouse button:



http://www.turtle.dds.nl/newlisp/comic.jpg">





The program also handles key events. Pressing the <SPACE> key moves forward to the next page, also <CURSORRIGHT>. The <CURSORLEFT> moves back, and with the 'F' key fullscreen mode can be toggled on or off.



Enjoy!!!

cormullion

#39
Looks great, but...





http://farm3.static.flickr.com/2110/2117667406_22a4f5eb86.jpg">

pjot

#40
Quote
Runs in Unix/Linux/Win32.


I do not own a Mac so I cannot support MacOSX.... sorry! If you want me to support MacOSX, please donate €600,= so I can buy one :-)



From your error it seems newLisp is unable to load the GTK-server DLL. Did you compile it from scratch? It should be possible to run GTK on MacOSX, but again, I have never tested it myself...



Peter

tom

#41
You have to admit that's the best "something's wrong" post ever, no matter what the problem is...

Lutz

#42
There is a long drawn out procedure to compile the GTK libraries for the Mac (natively, not X-Windows) and I tried it twice, but never could get it to work.



Before OS X 10.5 Leopard, there was a rumor that GTK would ship with Mac OS X, but unfortunately this did not come true.



Lets just hope then one day GTK offers binaries for OS X, just like they do for Windows.



Lutz

pjot

#43
QuoteYou have to admit that's the best "something's wrong" post ever, no matter what the problem is...


That's true! I fully agree :-)


QuoteLets just hope then one day GTK offers binaries for OS X, just like they do for Windows.


Indeed, I hope so too... as soon as it happens I'll support MacOSX as well.



Cheers

Pete

Cyril

#44
Quoteas long as the newlisp language is involved


I am just curious what the word "involved" means. Does my newLISP syntax highlighting mode for Vim (written in vimscript) qualify? Not that I am pretending to be a winner, but may I at least enter the competition with this contribution?
With newLISP you can grow your lists from the right side!