From: Taylan Kammer <taylan.kammer@gmail.com>
To: Zelphir Kaltstahl <zelphirkaltstahl@posteo.de>,
Guile User <guile-user@gnu.org>
Subject: Re: Writing a procedure in different style
Date: Sun, 13 Dec 2020 12:51:46 +0100 [thread overview]
Message-ID: <1385bd6a-c14e-76f1-6dfe-4cf50d192375@gmail.com> (raw)
In-Reply-To: <2d6f348c-1e43-a5c4-1998-baa04b91bf8c@gmail.com>
On 13.12.2020 08:06, Taylan Kammer wrote:
>
> (define find-in-tree*
> (λ (peg-tree filter-proc)
>
> (define traverse
> (λ (subtree rest)
> (simple-format (current-output-port)
> "working with subtree ~a\n"
> subtree)
> (cond
> [(null? subtree)
> (if (null? rest)
> '()
> (traverse (car rest) (cdr rest))]
> [(pair? (first subtree))
> (traverse (first subtree)
> (cons (cdr subtree) rest))]
> [(filter-proc (first subtree))
> (cons subtree
> (traverse (car rest) (cdr rest)))]
> [else
> (traverse (cdr subtree) rest)])))
>
> (traverse peg-tree '())))
Correction, for third branch of the cond that didn't check if rest is null:
(define find-in-tree*
(λ (peg-tree filter-proc)
(define traverse
(λ (subtree rest)
(simple-format (current-output-port)
"working with subtree ~a\n"
subtree)
(cond
[(null? subtree)
(if (null? rest)
'()
(traverse (car rest) (cdr rest)))]
[(pair? (first subtree))
(traverse (first subtree)
(cons (cdr subtree) rest))]
[(filter-proc (first subtree))
(cons subtree
(if (null? rest)
'()
(traverse (car rest) (cdr rest))))]
[else
(traverse (cdr subtree) rest)])))
(traverse peg-tree '())))
Taylan
next prev parent reply other threads:[~2020-12-13 11:51 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-12-12 12:22 Writing a procedure in different style Zelphir Kaltstahl
2020-12-13 7:06 ` Taylan Kammer
2020-12-13 11:51 ` Taylan Kammer [this message]
2020-12-13 12:29 ` Zelphir Kaltstahl
2020-12-13 14:24 ` tomas
2020-12-13 15:01 ` Zelphir Kaltstahl
2020-12-13 15:43 ` tomas
2020-12-20 17:57 ` Zelphir Kaltstahl
2020-12-21 12:31 ` tomas
2020-12-21 21:29 ` Zelphir Kaltstahl
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/guile/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1385bd6a-c14e-76f1-6dfe-4cf50d192375@gmail.com \
--to=taylan.kammer@gmail.com \
--cc=guile-user@gnu.org \
--cc=zelphirkaltstahl@posteo.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).