You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to
Samir Barjoud wrote:
> Is there any function or macro defined by Common Lisp that does the
> following?
>
> Example usage:
> ............
> (map-by (x y) '(1 2 3 4 5 6)
> (+ x y))
>
> => (3 7 11)
>
> (map-by (x y z) '(1 2 3 4 5 6)
> (* x y z))
>
> => (6 120)
(map-by ($$(x y tl ...) (values (+ x y) tl)) (range 8))
--> '(1 5 9 13)
;; Group consecutive numbers or non-numbers.
(map-by (match-lambda
[(list (? number? n) ..1 tl ...) (values n tl)]
[(list (? (negate number?) x) ..1 tl ...) (values x tl)])
'(a b c 2 3 4 x y 5 z))
--> '((a b c) (2 3 4) (x y) (5) (z))
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to
Better in common-lisp
(defmacro max-by (args lst &body body)
(let ((n (length args)))
`(loop for l = ,lst then (nthcdr ,n l) while l collect (apply (lambda ,args ,@body) (subseq l 0 ,n)))))
(max-by (x y) '(1 2 3 4 5 6) (+ x y))
(3 7 11)
danielrupi...@yahoo.es
unread,
Oct 31, 2012, 4:08:41 PM10/31/12
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to
a
A better solution
(defmacro max-by (args lst &body body)
`(loop for ,args on ,lst by (lambda(x)(nthcdr ,(length args) x)) collect
(progn ,@body)))