[Small-cl-src] RE: a Clisp problem (Xie Wen Sheng)
Xie Wen Sheng
wen-sheng.xie at thomson.net
Mon Dec 5 01:14:23 UTC 2005
Hi, All:
I got a solution from comp.lang.lisp:
Pascal Bourguignon:
(DEFUN COMBINE (ARGS)
"
RETURN: (elt args 0) x (elt args 1) x ... x (elt args (1- (length args)))
= the set of tuples built taking one item in order from each list
in args.
EXAMPLE: (COMBINE '((WWW FTP) (EXA) (COM ORG)))
--> ((WWW EXA COM) (WWW EXA ORG) (FTP EXA COM) (FTP EXA ORG))
"
(COND
((NULL ARGS) '(NIL))
((NULL (CAR ARGS)) (COMBINE (CDR ARGS)))
((CONSP (CAR ARGS))
(MAPCAN (LAMBDA (ITEM) (COMBINE (cons ITEM (CDR ARGS))))
(CAR ARGS)))
(T
(MAPCAN (LAMBDA (REST) (LIST (CONS (CAR ARGS) REST)))
(COMBINE (CDR ARGS))))))
Tron3k:
(defun combine (lst)
(if (endp lst)
(list '())
(loop with crest = (combine (rest lst))
for item in (first lst)
nconc (loop for items in crest
collect (cons item items)))))
Thank you all.
XIE Wensheng
-----Original Message-----
From: small-cl-src-bounces at hexapodia.net
[mailto:small-cl-src-bounces at hexapodia.net]On Behalf Of
small-cl-src-request at hexapodia.net
Sent: Saturday, December 03, 2005 8:00 PM
To: small-cl-src at hexapodia.net
Subject: Small-cl-src Digest, Vol 10, Issue 1
Send Small-cl-src mailing list submissions to
small-cl-src at hexapodia.net
To subscribe or unsubscribe via the World Wide Web, visit
http://www.hexapodia.net/mailman/listinfo/small-cl-src
or, via email, send a message with subject or body 'help' to
small-cl-src-request at hexapodia.net
You can reach the person managing the list at
small-cl-src-owner at hexapodia.net
When replying, please edit your Subject line so it is more specific
than "Re: Contents of Small-cl-src digest..."
Today's Topics:
1. a Clisp problem (Xie Wen Sheng)
----------------------------------------------------------------------
Message: 1
Date: Mon, 28 Nov 2005 16:22:54 +0800
From: "Xie Wen Sheng" <wen-sheng.xie at thomson.net>
Subject: [Small-cl-src] a Clisp problem
To: <small-cl-src at hexapodia.net>
Message-ID:
<CE1F1B158B2B1C4080BA3F114B158B5B019013 at szntsmail01.ap.thmulti.com>
Content-Type: text/plain; charset="iso-8859-1"
Hi ,All
I'm new to lisp, using GNU Clisp.
I have a problem when I do some Lisp programming training.
For example, for the list (a (b1 b2) c (d1 d2) (e1 e2 e3) f), I need a function to return all the possible combinations like:
((a b1 c d1 e1 f)
(a b1 c d1 e2 f)
(a b1 c d1 e3 f)
(a b1 c d2 e1 f)
(a b1 c d2 e2 f)
(a b1 c d2 e3 f)
(a b2 c d1 e1 f)
(a b2 c d1 e2 f)
(a b2 c d1 e3 f)
(a b2 c d2 e1 f)
(a b2 c d2 e2 f)
(a b2 c d2 e3 f))
My tries trended to be unsuccessful. Is it too easy to ask this here? If so, where is the forum for people like me?
best regards,
XIE Wensheng
------------------------------
_______________________________________________
Small-cl-src mailing list
Small-cl-src at hexapodia.net
http://www.hexapodia.net/mailman/listinfo/small-cl-src
End of Small-cl-src Digest, Vol 10, Issue 1
*******************************************
More information about the Small-cl-src
mailing list