• Re: relativity of programming languages

    From B. Pym@Nobody447095@here-nor-there.org to comp.lang.lisp,comp.lang.scheme on Thu Sep 4 11:22:34 2025
    From Newsgroup: comp.lang.lisp

    B. Pym wrote:

    Ken Tilton wrote:

    How about?:

    (loop for drink in list-of-drinks
    collecting (list drink (random 100)))

    Gauche Scheme

    (use srfi-27) ;; random-integer

    (map (cut list <> (random-integer 100)) '(g h i j))
    ===>
    ((g 79) (h 3) (i 36) (j 84))

    (use srfi-27) ;; random-integer
    (define random random-integer)

    (% map (list _ (random 100)) list-of-drinks)

    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)
    ;; When used with functions such as "map" and "fold", the macro
    ;; can deduce the number of arguments the lambda will receive.
    ;; The number of arguments can be specified by an integer
    ;; after the function name. For example:
    ;; (% 2 lset-adjoin (eq? B: (char-upcase A:)) '(#\M #\N) #\m #\o)
    ;;
    (define-macro %
    (case-lambda
    ((func expr List) `(,func (lambda(_) ,expr) ,List))
    ((func expr . more)
    ;; Number of arguments received by the lambda.
    (let ((n (if (integer? func)
    (begin0
    func
    (set! func expr)
    (set! expr (car more))
    (set! more (cdr more)))
    (length more))))
    (let* ((nums (do ((i n (- i 1))
    (r '() (cons (+ i 64) r))) ((= 0 i) r)))
    (vnames
    (map (lambda(n)
    (string->symbol (string (integer->char n) #\:)))
    nums)))
    `(,func (lambda ,vnames ,expr) ,@more))))))

    --- Synchronet 3.21a-Linux NewsLink 1.2