• Re: What to do with (time (length L)) proportional to (length L)

    From B. Pym@21:1/5 to Pascal Costanza on Sat Sep 21 14:58:42 2024
    XPost: comp.lang.scheme

    Pascal Costanza wrote:

    (let* ((temp1 (mapcar #'f1 some-list))
    (temp2 (mapcar #'f2 temp1))
    (temp3 (mapcar #'f3 temp2)))
    (mapcar #'f4 temp3))

    You could better say:

    (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 ...))]))

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From B. Pym@21:1/5 to B. Pym on Sat Sep 21 21:55:53 2024
    XPost: comp.lang.scheme

    B. Pym wrote:

    (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))

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)