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

    From B. Pym@Nobody447095@here-nor-there.org to comp.lang.lisp,comp.lang.scheme on Sat Sep 21 14:58:42 2024
    From Newsgroup: 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 ...))]))
    --- Synchronet 3.22a-Linux NewsLink 1.2
  • From B. Pym@Nobody447095@here-nor-there.org to comp.lang.lisp,comp.lang.scheme on Sat Sep 21 21:55:53 2024
    From Newsgroup: 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))


    --- Synchronet 3.22a-Linux NewsLink 1.2