From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Hans Aberg Newsgroups: gmane.lisp.guile.user Subject: Re: List functions Date: Fri, 3 Dec 2010 16:06:03 +0100 Message-ID: <69312ECE-8DC8-4AFF-86EA-42F52D8AC5F2@telia.com> References: <82728ACE-C593-4789-BED2-45674C06057E@telia.com> <4F285BF4-6D05-4FEF-8DF7-93D7FFC5B9AE@telia.com> <201012011920.oB1JKhwJ003938@fcs13.keithdiane.us> <201012012134.oB1LY0uo004089@fcs13.keithdiane.us> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 (Apple Message framework v936) Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes Content-Transfer-Encoding: 7bit X-Trace: dough.gmane.org 1291388784 16286 80.91.229.12 (3 Dec 2010 15:06:24 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Fri, 3 Dec 2010 15:06:24 +0000 (UTC) Cc: guile-user@gnu.org To: Keith Wright Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Fri Dec 03 16:06:19 2010 Return-path: Envelope-to: guile-user@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1POXDE-0003IS-K9 for guile-user@m.gmane.org; Fri, 03 Dec 2010 16:06:16 +0100 Original-Received: from localhost ([127.0.0.1]:37611 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1POXDD-0001sC-8W for guile-user@m.gmane.org; Fri, 03 Dec 2010 10:06:15 -0500 Original-Received: from [140.186.70.92] (port=33689 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1POXD6-0001qJ-GE for guile-user@gnu.org; Fri, 03 Dec 2010 10:06:09 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1POXD5-0003vn-87 for guile-user@gnu.org; Fri, 03 Dec 2010 10:06:08 -0500 Original-Received: from smtp-out11.han.skanova.net ([195.67.226.200]:54625) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1POXD4-0003vE-NS for guile-user@gnu.org; Fri, 03 Dec 2010 10:06:07 -0500 Original-Received: from h131n2-fre-d2.ias.bredband.telia.com (78.72.157.131) by smtp-out11.han.skanova.net (8.5.124.10) (authenticated as u26619196) id 4C7E12700253C971; Fri, 3 Dec 2010 16:06:05 +0100 In-Reply-To: <201012012134.oB1LY0uo004089@fcs13.keithdiane.us> X-Mailer: Apple Mail (2.936) X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: guile-user-bounces+guile-user=m.gmane.org@gnu.org Errors-To: guile-user-bounces+guile-user=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.user:8285 Archived-At: 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 ...).