Deutsch   English   Français   Italiano  
<vbuhir$7h42$1@dont-email.me>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: "B. Pym" <Nobody447095@here-nor-there.org>
Newsgroups: comp.lang.lisp,comp.lang.scheme
Subject: Re: tail recursion guidelines
Date: Thu, 12 Sep 2024 10:59:41 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 40
Message-ID: <vbuhir$7h42$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Injection-Date: Thu, 12 Sep 2024 12:59:42 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="0068c9cac97edf80ad7dcfbe07391a5a";
	logging-data="246914"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX1/+puBN5kTNQCK51QZ70gqQ"
User-Agent: XanaNews/1.18.1.6
Cancel-Lock: sha1:K/I7ghKjYFQqZJVz4CY+Qmzc8Ug=
Bytes: 1812

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