[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.lisp

Re: combination function help

William James

9/1/2015 8:32:00 PM

Tron3k wrote:

> > i am looking for a function that does the following combination 'across
> > lists'.
> >
> > ((1 2) (3 4) (5 6))
> >
> > to
> >
> > ((1 3 5) (2 3 5) ( 1 4 5) ( 2 4 5) ( 1 3 6) ( 2 3 6) ( 1 4 6) ( 2 4 6))
> >
> > thanks,
> > -AC
>
> Here's my try at this function:
>
> (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)))))

Gauche Scheme:

(use srfi-42 :only (list-ec))

(define (combine lst)
(if (null? lst)
(list '())
(list-ec
(:let crest (combine (cdr lst)))
(:list item (car lst))
(:list items crest)
(cons item items))))


(combine '((1 2) (3 4) (5 6)))
===>
((1 3 5) (1 3 6) (1 4 5) (1 4 6) (2 3 5) (2 3 6) (2 4 5) (2 4 6))

--
The Authoritarian Personality extends beyond the attempt to pathologize
cohesive gentile groups to pathologizing adaptive gentile behavior in general.
The principal intellectual difficulty is that behavior that is critical to
Judaism as a successful group evolutionary strategy is conceptualized as
pathological in gentiles. --- Dr. Kevin MacDonald; "The Frankfurt School of
Social Research and the Pathologization of Gentile Group Allegiances"