Another challenge

Started by cormullion, March 07, 2011, 11:05:40 AM

Previous topic - Next topic

cormullion

I thought this thread on comp.lang.lisp was quite entertaining https://groups.google.com/d/topic/comp.lang.lisp/sJdB5SXzcU0/discussion">//https://groups.google.com/d/topic/comp.lang.lisp/sJdB5SXzcU0/discussion. It's to produce the list:


((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?

Sammo

#1
This works but is ugly looking.
(map list (sort (flat (dup (sequence 1 5) 4))) (explode (dup "abcd" 5)))
With comments:
(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))."

johu

#2
A shortcut in newLISP ?

 Though my understanding might be different, I try :


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


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

newdep

#3
Just to keep that head fresh..Explain the behavior...



(((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)
-- (define? (Cornflakes))