Groups | Search | Server Info | Login | Register


Groups > comp.lang.scheme > #6573

Re: relativity of programming languages

Path csiph.com!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail
From "B. Pym" <Nobody447095@here-nor-there.org>
Newsgroups comp.lang.lisp, comp.lang.scheme
Subject Re: relativity of programming languages
Date Thu, 4 Sep 2025 11:22:34 -0000 (UTC)
Organization A noiseless patient Spider
Lines 56
Message-ID <109bspp$1ntug$1@dont-email.me> (permalink)
References <1045rsn$5gdl$1@dont-email.me>
MIME-Version 1.0
Content-Type text/plain; charset=iso-8859-1
Injection-Date Thu, 04 Sep 2025 11:22:35 +0000 (UTC)
Injection-Info dont-email.me; posting-host="fa2961a8ab9535733cba973fb4e6d169"; logging-data="1832912"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18mmpEFDJzGqZFvY6GU40yU"
User-Agent XanaNews/1.18.1.6
Cancel-Lock sha1:ys1JtenfynBI0xkZdot0Q4EJRqo=
Xref csiph.com comp.lang.lisp:60706 comp.lang.scheme:6573

Cross-posted to 2 groups.

Show key headers only | View raw


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

Back to comp.lang.scheme | Previous | NextPrevious in thread | Find similar


Thread

Re: relativity of programming languages "B. Pym" <Nobody447095@here-nor-there.org> - 2025-07-03 12:08 +0000
  Re: relativity of programming languages "B. Pym" <Nobody447095@here-nor-there.org> - 2025-09-04 11:22 +0000

csiph-web