• merits of Lisp vs Python

    From Robert L.@21:1/5 to All on Fri Feb 11 18:29:42 2022
    (loop for e in list
    maximizing e into max
    minimizing e into min
    finally (return (values min max)))

    In one pass, find the largest number and
    the smallest number.

    Even better: in one pass, find the smallest number,
    the largest number, the sum, and the product.

    (multi-reduce min max + * '(3 2 9 8 4 5 6 7))

    2
    9
    44
    362880

    Given:

    (define (multi-fold* funcs knils the-list)
    (let loop ((the-list the-list)
    (accums knils))
    (if (null? the-list)
    (apply values accums)
    (loop (cdr the-list)
    (map (lambda (fn acc) (fn (car the-list) acc))
    funcs
    accums)))))

    (define (multi-fold . args)
    (let ((rev (reverse args)))
    (multi-fold* (reverse (cddr rev)) (cadr rev) (car rev))))

    (define (multi-reduce* funcs the-list)
    (multi-fold* funcs (map (lambda _ (car the-list)) funcs) (cdr the-list)))

    (define (multi-reduce . args)
    (let ((rev (reverse args)))
    (multi-reduce* (reverse (cdr rev)) (car rev))))

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From B. Pym@21:1/5 to Wade Humeniuk on Wed Jun 18 21:25:23 2025
    Wade Humeniuk wrote:

    John Thingstad wrote:

    (defun + (array) (loop for number across array summing number))
    for a array.


    Really?

    CL-USER 1 > (reduce '+ #(1 2 3))
    6

    Gauche Scheme

    (use gauche.sequence)

    (fold + 0 #(1 2 3))
    ===>
    6

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Kaz Kylheku@21:1/5 to B. Pym on Thu Jun 19 03:06:49 2025
    On 2025-06-18, B. Pym <[email protected]> wrote:
    Wade Humeniuk wrote:

    John Thingstad wrote:

    (defun + (array) (loop for number across array summing number))
    for a array.


    Really?

    CL-USER 1 > (reduce '+ #(1 2 3))
    6

    Gauche Scheme

    (use gauche.sequence)

    (fold + 0 #(1 2 3))

    Alas, that could have been

    (fold + #(1 2 3))

    if they had only copied the good idea: when the initial accumulator is
    not specified, infer it by calling the function without arguments.

    With functions like +, you usually want the reduce accumulator to be the identity element, and the function can give it to you: (+) -> 0.

    For the list appending monad, the empty list is the identity element,
    and that's what (append) returns, so it works for that too:

    (reduce #'append '((1) (2 3 4) (5))) -> (1 2 3 4 5)

    --
    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 B. Pym@21:1/5 to All on Thu Jul 24 09:20:59 2025
    XPost: comp.lang.scheme

    Contrast the much more common

    a[i] = b[n]

    with

    (setf (aref a i) (aref b n))

    Would this be concise enough?

    (a i b n)


    Gauche Scheme

    (define-method object-apply
    ((v0 <vector>) (i0 <integer>) (v1 <vector>) (i1 <integer>))
    (vector-set! v0 i0 (ref v1 i1)))

    (define a #(2 4 6 8))
    (define b #(30 50 70 90))

    gosh> a
    #(2 4 6 8)

    (a 2 b 3)

    gosh> a
    #(2 4 90 8)


    --
    [T]he problem is that lispniks are as cultish as any other devout group and basically fall down frothing at the mouth if they see [heterodoxy].
    --- Kenny Tilton
    The good news is, it's not Lisp that sucks, but Common Lisp. --- Paul Graham

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