Re: tail recursion guidelines

Liste des GroupesRevenir à cl lisp 
Sujet : Re: tail recursion guidelines
De : Nobody447095 (at) *nospam* here-nor-there.org (B. Pym)
Groupes : comp.lang.lisp comp.lang.scheme
Date : 12. Sep 2024, 12:59:41
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vbuhir$7h42$1@dont-email.me>
User-Agent : XanaNews/1.18.1.6
Juho Snellman wrote:

One useful detail that I didn't see mentioned in that chapter is the
loop keyword "it". I find that it pops up often in code like
 
  (let ((x ...))
    ...
    (loop for e in list when (foo-bar e x) collect it))
 
, where foo-bar returns nil on failure and some sort of state object
otherwise.

Gauche Scheme

(define (foo-bar x)  (and (positive? x) (sqrt x)))

(filter-map foo-bar '(-3 0 4 9))
  ===>
(2 3)


Here's an anaphoric "if" that provides "it".
(Adapted from an example in the Gauche documentation.)

(use util.match)

(define-syntax if@
  (er-macro-transformer
    (lambda (form rename id=?)
      (match form
        [(if@ test expr1 expr2)
         (quasirename rename
           `(let ((,'it ,test))
              (if ,'it ,expr1 ,expr2)))]))))

(if@ (find odd? '(2 3)) (print it) (print "false is " it))
3

(if@ (find odd? '(2 30)) (print it) (print "false is " it))
false is #f

Date Sujet#  Auteur
12 Sep 24 o Re: tail recursion guidelines1B. Pym

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal