From: Ian Price <ianprice90@googlemail.com>
To: Nikita Karetnikov <nikita@karetnikov.org>
Cc: guile-user@gnu.org
Subject: Re: Safe pattern matching
Date: Sat, 09 Feb 2013 10:48:34 +0000 [thread overview]
Message-ID: <8762217ofx.fsf@Kagami.home> (raw)
In-Reply-To: <876221olm1.fsf@karetnikov.org> (Nikita Karetnikov's message of "Sat, 09 Feb 2013 04:57:26 -0500")
Nikita Karetnikov <nikita@karetnikov.org> writes:
> How would you rewrite the following function in Guile?
>
> foo :: [Int] -> String -> [Int]
> foo (x:y:ys) "+" = (x + y):ys
> foo (x:y:ys) "-" = (x - y):ys
> foo xs num = read num:xs
Daniel covered most of this already, but instead you might consider
(define foo
(match-lambda* ....))
rather than
(define (foo . args)
(match args
....))
the nearest analogue to read is object->string, but it is not a generic.
--
Ian Price -- shift-reset.com
"Programming is like pinball. The reward for doing it well is
the opportunity to do it again" - from "The Wizardy Compiled"
next prev parent reply other threads:[~2013-02-09 10:48 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-02-09 9:57 Safe pattern matching Nikita Karetnikov
2013-02-09 10:12 ` Daniel Hartwig
2013-02-09 10:15 ` Daniel Hartwig
2013-02-09 10:48 ` Ian Price [this message]
2013-02-09 11:09 ` Ian Price
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=8762217ofx.fsf@Kagami.home \
--to=ianprice90@googlemail.com \
--cc=guile-user@gnu.org \
--cc=nikita@karetnikov.org \
/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).