• Re: What's more idiomatic?

    From B. Pym@21:1/5 to Pascal Costanza on Sun Sep 22 08:38:51 2024
    XPost: comp.lang.scheme

    Pascal Costanza wrote:

    (loop for x in '(1 2 3)
    for y in '(4 5 6)
    collect (* 2 (+ x y)))

    vs.

    (mapcar (lambda (x y)
    (* 2 (+ x y)))
    '(1 2 3)
    '(4 5 6))

    However, what if there were 9 lists instead of 2?
    The CL (COBOL-Like) version would become:

    (loop for a in '(1 2 3)
    for b in '(4 5 6)
    for c in '(7 8 9)
    for d in '(20 21 22)
    for e in '(23 24 25)
    for f in '(26 27 28)
    for g in '(29 30 31)
    for h in '(32 33 34)
    for i in '(35 36 37)
    collect (* 2 (+ a b c d e f g h i)))


    (354 372 390)

    The Scheme version would simply become:

    (map (~>> + (* 2))
    '(1 2 3)
    '(4 5 6)
    '(7 8 9)
    '(20 21 22)
    '(23 24 25)
    '(26 27 28)
    '(29 30 31)
    '(32 33 34)
    '(35 36 37))

    ===>
    (354 372 390)

    Given:

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

    (define-syntax ~>>
    (syntax-rules ()
    [(_ (func0 a ...) func ...)
    (lambda xs (->> (apply func0 a ... xs) func ...))]
    [(_ 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 Pascal Costanza on Tue Jun 24 14:16:15 2025
    Pascal Costanza wrote:

    (loop for x in '(1 2 3)
    for y in '(4 5 6)
    collect (* 2 (+ x y)))

    vs.

    (mapcar (lambda (x y)
    (* 2 (+ x y)))
    '(1 2 3)
    '(4 5 6))


    What if there were 26 lists instead of 2? Instead of just
    "x" and "y", the CL worshipper would have to use "a" through
    "z". Of course, he would run into another problem.
    In CL (COBOL-Like), if you try to use "t" as a variable name,
    you get:

    T is a constant and thus cannot be set.

    (loop
    for a in '(0 1 2)
    for b in '(3 4 5)
    for c in '(6 7 8)
    for d in '(9 10 11)
    for e in '(12 13 14)
    for f in '(15 16 17)
    for g in '(18 19 20)
    for h in '(21 22 23)
    for i in '(24 25 26)
    for j in '(27 28 29)
    for k in '(30 31 32)
    for l in '(33 34 35)
    for m in '(36 37 38)
    for n in '(39 40 41)
    for o in '(42 43 44)
    for p in '(45 46 47)
    for q in '(48 49 50)
    for r in '(51 52 53)
    for s in '(54 55 56)
    for t-is-a-constant in '(57 58 59)
    for u in '(60 61 62)
    for v in '(63 64 65)
    for w in '(66 67 68)
    for x in '(69 70 71)
    for y in '(72 73 74)
    for z in '(75 76 77)
    collect (* 2 (+ a b c d e f g h i j k l m n o p q r s
    t-is-a-constant u v w x y z)))


    (1950 2002 2054)

    Yes, CL (COBOL-Like) is an unbelievably clunky language.
    Its worshippers have no affinity for Lispy programming or
    for elegance of any sort.

    Instead of giving a name to the number from each list,
    wouldn't it be easier simply to say "sum the numbers from
    the lists"?


    (define the-lists
    '((0 1 2)
    (3 4 5)
    (6 7 8)
    (9 10 11)
    (12 13 14)
    (15 16 17)
    (18 19 20)
    (21 22 23)
    (24 25 26)
    (27 28 29)
    (30 31 32)
    (33 34 35)
    (36 37 38)
    (39 40 41)
    (42 43 44)
    (45 46 47)
    (48 49 50)
    (51 52 53)
    (54 55 56)
    (57 58 59)
    (60 61 62)
    (63 64 65)
    (66 67 68)
    (69 70 71)
    (72 73 74)
    (75 76 77)))

    (apply map (lambda args (* 2 (apply + args))) the-lists)

    (1950 2002 2054)

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Kaz Kylheku@21:1/5 to B. Pym on Tue Jun 24 19:56:24 2025
    On 2025-06-24, B. Pym <[email protected]> wrote:
    What if there were 26 lists instead of 2? Instead of just

    I've never seen a situation where two named lists had to scale to 26.
    For instance, zipping over symbols and their values.

    You've been demonstrating your skills in writing small one-liner
    programs for solving tiny sub-problems for probably close to
    two decades.

    It's not even on the level of Leetcode problems.

    Meanwhile, in that time, beginners have matured into professionals
    working on complex applications.

    What actual skills do you have?

    --
    TXR Programming Language: http://nongnu.org/txr
    Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
    Mastodon: @[email protected]

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Jeff Barnett@21:1/5 to Kaz Kylheku on Tue Jun 24 17:26:44 2025
    On 6/24/2025 1:56 PM, Kaz Kylheku wrote:
    On 2025-06-24, B. Pym <[email protected]> wrote:
    What if there were 26 lists instead of 2? Instead of just

    I've never seen a situation where two named lists had to scale to 26.
    For instance, zipping over symbols and their values.

    You've been demonstrating your skills in writing small one-liner
    programs for solving tiny sub-problems for probably close to
    two decades.

    It's not even on the level of Leetcode problems.

    Meanwhile, in that time, beginners have matured into professionals
    working on complex applications.

    What actual skills do you have?


    I think that's a good question. My opinion, stated in the past, is that
    we are only honored with its presence when he is between jobs. Given the frequency of its appearance, I'd say those jobs don't last very long.
    Perhaps that is because of the same display of unwarranted arrogance
    displayed here.
    --
    Jeff Barnett

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