From: Hans Aberg <haberg-1@telia.com>
To: Keith Wright <kwright@keithdiane.us>
Cc: guile-user@gnu.org
Subject: Re: List functions
Date: Fri, 3 Dec 2010 16:06:03 +0100 [thread overview]
Message-ID: <69312ECE-8DC8-4AFF-86EA-42F52D8AC5F2@telia.com> (raw)
In-Reply-To: <201012012134.oB1LY0uo004089@fcs13.keithdiane.us>
On 1 Dec 2010, at 22:34, Keith Wright wrote:
>> One can set the constants to functions that evaluate
>> to themselves. One use would be expressions like
>> (1 + f)(x). The () just shows up in the context above.
>
> I didn't really follow that, but in seems that
> you want to be able to apply a list of functions
> to a single argument, and get a list of the
> results of applying each function separately
> to the same argument.
>
> guile>
> (define (fmap fs x)
> (if (null? fs)
> '()
> (cons (apply (car fs) (list x))
> (fmap (cdr fs) x) )))
>
> guile> (fmap (list sin cos) 2)
> (0.909297426825682 -0.416146836547142)
If I extend your function to one of pairs and non-pairs as well, then
() becomes naturally a constant:
(define (fmap fs x)
(if (null? fs)
'()
(if (not (pair? fs))
(apply fs (list x))
(cons (fmap (car fs) x)
(fmap (cdr fs) x)))))
Then
(fmap sqrt 2)
--> 1.4142135623731
(fmap (list sin cos) 2)
--> (0.909297426825682 -0.416146836547142)
(fmap (cons sin cos) 2)
--> (0.909297426825682 . -0.416146836547142)
But also
(fmap (list) 2)
--> ()
So this acts essentially as an extension of the evaluator, if all
expressions (f x1 ...) are replaced by (fmap f x1 ...).
next prev parent reply other threads:[~2010-12-03 15:06 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-12-01 16:28 List functions Hans Aberg
2010-12-01 17:35 ` Joel James Adamson
2010-12-01 17:48 ` Hans Aberg
2010-12-01 19:20 ` Keith Wright
2010-12-01 19:50 ` Hans Aberg
2010-12-01 20:26 ` Hans Aberg
2010-12-01 21:34 ` Keith Wright
2010-12-01 22:19 ` Hans Aberg
2010-12-01 22:43 ` Hans Aberg
2010-12-03 15:06 ` Hans Aberg [this message]
2010-12-01 19:51 ` Andy Wingo
2010-12-01 19:56 ` Hans Aberg
2010-12-02 9:57 ` Marco Maggi
2010-12-02 10:10 ` Marco Maggi
2010-12-02 11:31 ` Hans Aberg
2010-12-02 16:06 ` Hans Aberg
2010-12-03 9:20 ` Hans Åberg
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=69312ECE-8DC8-4AFF-86EA-42F52D8AC5F2@telia.com \
--to=haberg-1@telia.com \
--cc=guile-user@gnu.org \
--cc=kwright@keithdiane.us \
/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).