Discussion:
What to do with (time (length L)) proportional to (length L)
(too old to reply)
B. Pym
2024-09-21 14:58:42 UTC
Permalink
(let* ((temp1 (mapcar #'f1 some-list))
(temp2 (mapcar #'f2 temp1))
(temp3 (mapcar #'f3 temp2)))
(mapcar #'f4 temp3))
(loop for elem in some-list
collect (f4 (f3 (f2 (f1 elem)))))
(map (~> abs sqrt list) '(-4 -9 25))

===>
((2) (3) (5))

Given:

(define-syntax ->>
(syntax-rules ()
[(_ x) x]
[(_ x (y ...) z ...)
(->> (y ... x) z ...)]
[(_ x y z ...)
(->> (y x) z ...)]))

(define-syntax ->
(syntax-rules ()
[(_ x) x]
[(_ x (y more ...) z ...)
(-> (y x more ...) z ...)]
[(_ x y z ...)
(-> (y x) z ...)]))

;; currying
(define-syntax ~>
(syntax-rules ()
[(_ func0 func ...)
(lambda xs (-> (apply func0 xs) func ...))]))
B. Pym
2024-09-21 21:55:53 UTC
Permalink
Post by B. Pym
(loop for elem in some-list
collect (f4 (f3 (f2 (f1 elem)))))
(map (~> abs sqrt list) '(-4 -9 25))
===>
((2) (3) (5))
(map (~> abs sqrt list (append '(finished))) '(-4 -9 25))
===>
((2 finished) (3 finished) (5 finished))

Loading...