Sysop: | Amessyroom |
---|---|
Location: | Fayetteville, NC |
Users: | 28 |
Nodes: | 6 (0 / 6) |
Uptime: | 43:45:50 |
Calls: | 422 |
Calls today: | 1 |
Files: | 1,024 |
Messages: | 90,185 |
(defun shrug (list)
(loop for (x . sublist-and-more) on list
for more = (member x sublist-and-more)
when more
collect `(g ,x ,(ldiff sublist-and-more more))))
SHRUG
(shrug '(a b c a d b d))
((G A (B C)) (G B (C A D)) (G D (B)))
Kent M. Pitman wrote:
(defun shrug (list)
(loop for (x . sublist-and-more) on list
for more = (member x sublist-and-more)
when more
collect `(g ,x ,(ldiff sublist-and-more more))))
SHRUG
(shrug '(a b c a d b d))
((G A (B C)) (G B (C A D)) (G D (B)))
newLISP
(define (shrug xs (x (pop xs)))
(and xs
(if (match (list '* x '*) xs)
(cons (list 'g x ($it 0)) (shrug xs))
(shrug xs))))
(shrug '(a b c a d b d))
((g a (b c)) (g b (c a d)) (g d (b)))
Looks like the Haskell syntax is not good enough, because there is Template Haskell and doesn't look like it is invented by people who don't know how
to write it with higher order functions, because there are functions in the Haskell List package like this:
-- | The 'zip4' function takes four lists and returns a list of
-- quadruples, analogous to 'zip'.
zip4 :: [a] -> [b] -> [c] -> [d] -> [(a,b,c,d)]
zip4 = zipWith4 (,,,)