Page 1 of 1

Another challenge

Posted: Mon Mar 07, 2011 7:05 pm
by cormullion
I thought this thread on comp.lang.lisp was quite entertaining https://groups.google.com/d/topic/comp. ... discussion. It's to produce the list:

Code: Select all

((1 "a") (1 "b") (1 "c") (1 "d") (2 "a") (2 "b") (2 "c") (2 "d") (3 "a")
 (3 "b") (3 "c") (3 "d") (4 "a") (4 "b") (4 "c") (4 "d") (5 "a") (5
"b") (5 "c") (5 "d"))


Can you provide a newLISP alternative to the various loops, mapcans, collects, iters, and nconcs? Can you avoid creating intermediate storage? Can you do all this while resisting the urge to insult other programmers?! :)

Obviously, there's a simple iterator solution, using two dolists. I found a shortcut in newLISP. Can you find it?

Re: Another challenge

Posted: Mon Mar 07, 2011 8:43 pm
by Sammo
This works but is ugly looking.

Code: Select all

(map list (sort (flat (dup (sequence 1 5) 4))) (explode (dup "abcd" 5)))
With comments:

Code: Select all

(map list
	(sort (flat (dup (sequence 1 5) 4))) ;numbers
	(explode (dup "abcd" 5)) ;letters
)
Edit: Simplified expression generating list of letters. Was "(flat (dup (explode "abcd") 5))."

Re: Another challenge

Posted: Tue Mar 08, 2011 9:57 am
by johu
A shortcut in newLISP ?
Though my understanding might be different, I try :

Code: Select all

(for (i 1 5) (extend x (map (curry list i) '("a" "b" "c" "d"))))
or

Code: Select all

(for (i 1 5) (extend '() (map (curry list i) '("a" "b" "c" "d"))))

And Another challenge

Posted: Thu Apr 21, 2011 8:17 am
by newdep
Just to keep that head fresh..Explain the behavior...

Code: Select all

(((lambda(x) (lambda(x)))))   ---> nil
((lambda(x) (lambda(x))))   ---> (lambda (x))
(lambda(x) (lambda(x)))   ---> (lambda (x) (lambda (x)))
((lambda(x) lambda(x)))   ---> ERR: invalid lambda expression : (lambda x)