Re: Multiple arguments to mapcar?

Liste des GroupesRevenir à cl lisp 
Sujet : Re: Multiple arguments to mapcar?
De : Nobody447095 (at) *nospam* here-nor-there.org (B. Pym)
Groupes : comp.lang.lisp comp.lang.scheme
Date : 28. Aug 2024, 04:46:16
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vam31l$3b0or$1@dont-email.me>
User-Agent : XanaNews/1.18.1.6
Pascal Costanza wrote:

Johan wrote:
I want to map over a list, but to treat the first object differently
from the rest. My previous experience with Lisp was Interlisp, which
has dynamic binding. In Interlisp I could code my problem similar to
this:
>
(defun foo ()
  (let ((first-time t))
    (mapcar #'bar '(1 2))))
>
(defun bar (n)
  (cond
    (first-time
     (setf first-time nil)
     (+ n 1))
    (t (+ n 2))))
>
and (foo) would return (2 4). This doesn't work with lexical binding,
and I don't want to make first-time a global variable. What is the
best design pattern in Common Lisp?
 
(loop for n in '(1 2)
       for x = (+ n 1) then (+ n 2)
       collect x)

Gauche Scheme

(use gauche.parameter)

(define first-time (make-parameter 'unset))

(define (foo)
  (parameterize ((first-time #t))
    (map bar '(400 500 600))))

(define (bar n)
  (cond
    ((first-time)
     (first-time #f)
     (+ n 1))
    (#t (+ n 2))))

gosh> (foo)
(401 502 602)
gosh> (first-time)
unset

Date Sujet#  Auteur
28 Aug 24 o Re: Multiple arguments to mapcar?1B. Pym

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal