• Re: mapcar using a function with one argument fixed

    From B. Pym@21:1/5 to Rainer Joswig on Thu Aug 29 06:42:09 2024
    Rainer Joswig wrote:

    (LOOP FOR x IN list-for-xs AND y IN list-for-ys
    COLLECT (my-function a y x b))

    (define x-list '(x0 x1 x2 x3))
    (define y-list '(y0 y1 y2 y3))

    (map (cut list '! <> '! <>) x-list y-list)

    ===>
    ((! x0 ! y0) (! x1 ! y1) (! x2 ! y2) (! x3 ! y3))

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From B. Pym@21:1/5 to Rainer Joswig on Thu Jun 19 22:29:50 2025
    Rainer Joswig wrote:

    (LOOP FOR x IN list-for-xs AND y IN list-for-ys
    COLLECT (my-function a y x b))

    Scheme:

    (map
    (lambda(x y) (list x '< y))
    '(2 3 4 5)
    '(6 7 8 9))

    ===>
    ((2 < 6) (3 < 7) (4 < 8) (5 < 9))

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From B. Pym@21:1/5 to B. Pym on Fri Aug 29 00:57:06 2025
    XPost: comp.lang.scheme

    B. Pym wrote:

    Rainer Joswig wrote:

    (LOOP FOR x IN list-for-xs AND y IN list-for-ys
    COLLECT (my-function a y x b))

    (define x-list '(x0 x1 x2 x3))
    (define y-list '(y0 y1 y2 y3))

    (map (cut list '! <> '! <>) x-list y-list)

    ===>
    ((! x0 ! y0) (! x1 ! y1) (! x2 ! y2) (! x3 ! y3))


    (define x-list '(x0 x1 x2 x3))
    (define y-list '(y0 y1 y2 y3))

    (% map (list '-- A: '-- B:) x-list y-list)

    ===>
    ((-- x0 -- y0) (-- x1 -- y1) (-- x2 -- y2) (-- x3 -- y3))

    Given:

    ;; Anaphoric macro to abbreviate lambdas for higher-order functions.
    ;; Uses "_" for 1 argument;
    ;; uses "A:" and "B:" and so on for 2 or more arguments.
    ;; This version works under both Gauche Scheme
    ;; and Racket. Racket needs:
    ;; (require compatibility/defmacro)
    ;;
    (define-macro %
    (case-lambda
    ((func expr List) `(,func (lambda(_) ,expr) ,List))
    ((func expr . more)
    (let* ((n 64)
    (nums (map (lambda _ (set! n (+ 1 n)) n) more))
    (vnames
    (map (lambda(n)
    (string->symbol (string (integer->char n) #\:)))
    nums)))
    `(,func (lambda ,vnames ,expr) ,@more)))))

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