newlisp is not inhere //http://www.99-bottles-of-beer.net so i just
hacked the example below.. Its a way of doing it.. I did not look at the
other languages at that website, I did it after I build thisone below, there
are certainly some nice ways to do it ;-) (Dont peek at the Perl version!)
I think we should post be best newlisp-way-of-putting-99-bottles-on-the-wall version on there ;-)
Or should it be the smallest? or the most charming code?
Who Dares? ;-)
;; A way of putting them on the wall, newdep
(set 'y 99 'z '( " bottles" " of beer on the wall" "no more" "Take one down and pass it around, " "Go to the store and buy some more, " ".n" ))
(set 'a (z 0) 'b (z 1) 'c (z 2) 'd (z 3) 'e (z 4) 'f (z 5) 'g (0 -1 a) 'h (0 8 b) 'i (-2 d))
(for (x y 0) (println (if (> x 0) x (title-case c)) (if (= x 1) g a) b i (if (= x 0) c x) (if (= x 1) g a) h f (if (= x 0) e d) (case x (0 y) (1 c) (true (- x 1))) (if (= x 2) g a) b f ))
PS: edited post, pasted the wrong version..
Nice find! An amazing number of languages, some of which might even be useful...
I'm feeling dull and boring this morning, so this is a suitably dull and boring version. It would get no points for coolness:
(define (bottles n)
(cond
((> n 2)
(println (string n { bottles of beer on the wall, } n { bottles of beer. Take one down and pass it around, } (- n 1) { bottles of beer on the wall.})))
((= n 2)
(println (string n { bottles of beer on the wall, } n { bottles of beer. Take one down and pass it around, 1 bottle of beer on the wall.})))
((= n 1)
(println {1 bottle of beer on the wall, 1 bottle of beer. Take one down and pass it around, no more bottles of beer on the wall.}))
((= n 0)
(println {No more bottles of beer on the wall, no more bottles of beer. Go to the store and buy some more, 99 bottles of beer on the wall.})))
(if (> n 0) (bottles (- n 1))))
(bottles 100)
Aaa nice...now we need 97 more.. ;-)
I was also thinking of a FOOP version... (but...still thinking ;-)
So far I like Norman's version because it is showing off more newLISP code and makes the reader think "how does this work?", trying to minimize preformatted text.
Lutz
No problem :)
But although obfuscated code is fun, and making the reader work hard is good for their brain, it can also be nice to write code that doesn't need decoding...
But I agree that my version is dull... :)
#!/usr/bin/env newlisp
(eval-string
(base64-dec
(replace {s}
[text] KGRl
Zm luZ SAo Ym9
0dG xlc yBu KS
AKIC AoY 29u Z
CAKIC AgI CAo
KD4gbi AyK SAK
ICAgI CAgI CA
ocHJpb nRsb i
A oc3Rya W5nI
G4 geyBib 3R 0
bGVzI G9mIGJ
l ZXIgb 24gdGh
l IHd hbGwsI
H0g biB 7IGJvd
HRsZXM gb
2Y g YmVlc i4g
VGF rZSBv b mUgZG9
3biBh bmQ gcG Fzc
yBp dCBhcm 91bmQs
IH0gKC 0gbiAx K SB7IG
JvdHRs ZXMgb2 Yg YmVl
ciBvbi B0aGUg d2FsbC 5
9KSkp IAogIC Ag ICgoPS
Bu IDIp IAogIC AgICAg
IChwcm lu d GxuIC hzd
HJp bmcgbi B7IGJv dHR sZX
Mg b2YgYm VlciBv biB0aG Ug
d2Fs bCwgfS Bu IHsgYm 90d
Gxl cyBvZ i BiZWVy LiBUYW
tlIG9u ZSBkb3 duI GFuZCB w
YXNzI Gl0IGF yb3Vu Z CwgMS
B ib3R0b GUgb2Y gYm Vlc iB
vbi B0aGUg d2FsbC 59 KSkp
IAogIC AgICgo PSBuID EpIAo
g ICAgIC AgIChw cmlud G xu
IHsx IGJvdH RsZSBv ZiB iZW
VyIG9u IHRoZS B3YWxs L CA
xIG JvdHRs Z SBvZi BiZWVy L
iBUYW tlIG9u ZSBkb3 duIG F
u ZCBwYX NzIGl0 IGFyb3 Vu
ZCwg bm8gbW 9yZSBi b3R0bG
VzIG9m IGJlZX Igb24g dGhlI
H dhbGwu fSkpIA ogICAg IC
g oPS BuIDAp IAogIC AgICAg
I Chwcm ludGxu IHtOby Btb
3Jl IGJvdH RsZXMg b2YgYm V
lci Bv biB0aG Ugd2Fs bCwgb
m 8g bW9y ZSBib3 R0bGVz IG
9mIG JlZXIu IEdvIH RvIHRo
ZSBzd G 9yZSBh bmQgYn V5IH
Nv bWU gbW 9yZSwg OTkgYm 9
0dGxl c yBvZi BiZWVy IG9uI
H RoZSB3 YWxsLn 0pKSkg CiA
gKG lmIC g+ IG4gMC kgKGJv
dHRsZX Mg KC0g biAxKS kpKS
AK ICAgIA ooYm90 dGxlcy Ax
MDAp[/text] {} 0))) (exit) :)
...hahahahahaha...
Beer taken to excess is dangerous for health ;o) ... hic ...
Quote from: "Norman"
I was also thinking of a FOOP version... (but...still thinking ;-)
Looks like I beat you to it, Norman ;-)
(define (Class:Class) (cons (context) (args)))
(new Class 'Bottle)
(new Class 'Wall)
(define (Wall:restock s) (cons (s 0) (dup (Bottle "beer") 99)))
(define (Wall:take-one-down s) (set '$0 (pop s -1)) s)
(define (Wall:bottles-left s) (length (1 s)))
(define (Wall:empty? s) (empty? (1 s)))
(define (Wall:string s (verbose true))
(set 'bl (:bottles-left s))
(string
(if (= bl 0) "No more" bl)
" bottles of beer"
(if verbose " on the wall" "")
)
)
(new Class 'Bar)
(define (Bar:sing! b)
(set 'w (assoc Wall b))
(unless (:empty? w)
(begin
(print
(:string w) "n"
(:string w nil) "!n"
(amb
"if one of those bottles should happen to falln"
"take one down, pass it aroundn"
)
)
(set 'w (:take-one-down w))
(println (:string w) ".n")
(:sing! (set-assoc (b Wall) w))
)
(println (:string w) "!")
)
)
(:sing! (Bar (:restock (Wall))))
I'm still not sure this is the right approach, but it works :-)
m i c h a e l
P.S. I really like your second solution, cormullion!
P.P.S I actually wrote a version of 99 bottles back in October, going so far as to draft a post to the club about it, but I could never get that earlier version to work correctly (I was still a newLISP newbie). Thanks Norman, for bringing this topic up!
*Changed code to reflect Lutz's correct use of Class rather than Object in his manual example.
That's pretty cool - Quote
(:sing! (Bar (:restock (Wall))))
It's starting to look like a new language... Which is good, probably! Although I think that you have to think in the right way before writing code like this...
Out of my efforts I have a general purpose bottlize script that can make any text into a bottle shape. In case of emergencies...
Aaa what can i say yes yes... thats a nice FOOP ;-)
I especialy like the Amb ! good thinking after random beers ;-)
Another version using:
http://intricatevisions.com/source/newlisp/oop.lsp
(load "oop.lsp")
(set 'Wall
(object ()
bottles 0
init (fn (b) (set 'bottles b))
bottles? (fn () (> bottles 0))
take-one (fn () (dec 'bottles))
restock (fn () (set 'bottles 99))
bottle-count (fn ((verbose nil))
(string
(if (= bottles 0) "no more" bottles)
" bottle" (if (!= bottles 1) "s" "")
" of beer"
(if verbose " on the wall" "")))
bottle-count-extended (fn ()
(string
(title-case (bottle-count true))
", " (bottle-count) "."))
))
(set 'Bar
(object ()
sing (fn ()
(let (w Wall)
(.do 'w (restock))
;; drink beer
(while (.do 'w (bottles?))
(println (.do 'w (bottle-count-extended)))
(.do 'w (take-one))
(println
"Take one down and pass it around, "
(.do 'w (bottle-count true)) ".n"))
;; no more - restock ;-)
(println (.do 'w (bottle-count-extended)))
(.do 'w (restock))
(println
"Go to the store and buy some more, "
(.do 'w (bottle-count true)) ".")))
))
(.do 'Bar (sing))
Bar object and its method 'sing' can be rewritten as:
(set 'Bar
(object ()
sing (fn ()
(let (w Wall)
(.do 'w
(restock)
;; drink beer
(while (bottles?)
(println (bottle-count-extended))
(take-one)
(println
"Take one down and pass it around, "
(bottle-count true) ".n"))
;; no more - restock ;-)
(println (bottle-count-extended))
(restock)
(println
"Go to the store and buy some more, "
(bottle-count true) "."))))
))
Fanda
//http://www.99-bottles-of-beer.net/language-newlisp-1752.html
Here is the updated FOOP version of 99 Bottles for newLISP 10.x:
(define (Class:Class) (cons (context) (args)))
(new Class 'Bottle)
(new Class 'Wall)
(define (Wall:restock s) (cons (s 0) (dup (Bottle "beer") 99)))
(define (Wall:take-one-down s) (set '$0 (pop s -1)) s)
(define (Wall:bottles-left s) (length (1 s)))
(define (Wall:empty? s) (empty? (1 s)))
(define (Wall:string s (verbose true))
(set 'bl (:bottles-left s))
(string
(if (= bl 0) "No more" bl)
" bottles of beer"
(if verbose " on the wall" "")
)
)
(new Class 'Bar)
(define (Bar:sing! b)
(set 'w (assoc Wall b))
(if-not (:empty? w)
(begin
(print
(:string w) "n"
(:string w nil) "!n"
(amb
"if one of those bottles should happen to falln"
"take one down, pass it aroundn"
)
)
(set 'w (:take-one-down w))
(println (:string w) ".n")
(setf (assoc Wall b) w)
(:sing! b)
)
(println (:string w) "!")
)
)
(:sing! (Bar (:restock (Wall))))
The only changes were:
(unless (:empty? w)
and:
(:sing! (set-assoc (b Wall) w))
to:
(if-not (:empty? w)
and:
(setf (assoc Wall b) w)
(:sing! b)
respectively.
m i c h a e l
Cheers!
(//%3C/s%3E%3CURL%20url=%22http://smileys.sur-la-toile.com/repository/Boissons/C_10CH%7E1.GIF%22%3E%3CLINK_TEXT%20text=%22http://smileys.sur-la-toile.com/reposit%20...%20CH%7E1.GIF%22%3Ehttp://smileys.sur-la-toile.com/repository/Boissons/C_10CH%7E1.GIF%3C/LINK_TEXT%3E%3C/URL%3E%3Ce%3E)
Cheers - to your good health! Are you going to post it on the web site?
Cheers! Click (touching Bertrand's glass), click (and cormullion's). To newLISP!
Yes cormullion, you're right, I should post this to the 99 Bottles website. Unfortunately, I'm a notorious procrastinator! That's why I submitted it before responding ;-)
The submission form mentioned it may take a while for it to show up, so we'll have to wait and see.
m i c h a e l
cormullion,
How about posting your creative 99 Bottles contribution, as well?
#!/usr/bin/env newlisp
(eval-string
(base64-dec
(replace {s}
[text] KGRl
Zm luZ SAo Ym9
0dG xlc yBu KS
AKIC AoY 29u Z
CAKIC AgI CAo
KD4gbi AyK SAK
ICAgI CAgI CA
ocHJpb nRsb i
A oc3Rya W5nI
G4 geyBib 3R 0
bGVzI G9mIGJ
l ZXIgb 24gdGh
l IHd hbGwsI
H0g biB 7IGJvd
HRsZXM gb
2Y g YmVlc i4g
VGF rZSBv b mUgZG9
3biBh bmQ gcG Fzc
yBp dCBhcm 91bmQs
IH0gKC 0gbiAx K SB7IG
JvdHRs ZXMgb2 Yg YmVl
ciBvbi B0aGUg d2FsbC 5
9KSkp IAogIC Ag ICgoPS
Bu IDIp IAogIC AgICAg
IChwcm lu d GxuIC hzd
HJp bmcgbi B7IGJv dHR sZX
Mg b2YgYm VlciBv biB0aG Ug
d2Fs bCwgfS Bu IHsgYm 90d
Gxl cyBvZ i BiZWVy LiBUYW
tlIG9u ZSBkb3 duI GFuZCB w
YXNzI Gl0IGF yb3Vu Z CwgMS
B ib3R0b GUgb2Y gYm Vlc iB
vbi B0aGUg d2FsbC 59 KSkp
IAogIC AgICgo PSBuID EpIAo
g ICAgIC AgIChw cmlud G xu
IHsx IGJvdH RsZSBv ZiB iZW
VyIG9u IHRoZS B3YWxs L CA
xIG JvdHRs Z SBvZi BiZWVy L
iBUYW tlIG9u ZSBkb3 duIG F
u ZCBwYX NzIGl0 IGFyb3 Vu
ZCwg bm8gbW 9yZSBi b3R0bG
VzIG9m IGJlZX Igb24g dGhlI
H dhbGwu fSkpIA ogICAg IC
g oPS BuIDAp IAogIC AgICAg
I Chwcm ludGxu IHtOby Btb
3Jl IGJvdH RsZXMg b2YgYm V
lci Bv biB0aG Ugd2Fs bCwgb
m 8g bW9y ZSBib3 R0bGVz IG
9mIG JlZXIu IEdvIH RvIHRo
ZSBzd G 9yZSBh bmQgYn V5IH
Nv bWU gbW 9yZSwg OTkgYm 9
0dGxl c yBvZi BiZWVy IG9uI
H RoZSB3 YWxsLn 0pKSkg CiA
gKG lmIC g+ IG4gMC kgKGJv
dHRsZX Mg KC0g biAxKS kpKS
AK ICAgIA ooYm90 dGxlcy Ax
MDAp[/text] {} 0))) (exit) :)
:-)
m i c h a e l
It's not very good, so no I haven't thought about it... :) There is, though, a much better and wilder (//http) Perl version comprising 6 bottles and no discernible program code at all. It also echoes some of my thoughts when looking at Perl code...!