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: Wed, 1 Dec 2010 21:26:50 +0100 Message-ID: References: <82728ACE-C593-4789-BED2-45674C06057E@telia.com> <4F285BF4-6D05-4FEF-8DF7-93D7FFC5B9AE@telia.com> <201012011920.oB1JKhwJ003938@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 1291235227 11060 80.91.229.12 (1 Dec 2010 20:27:07 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Wed, 1 Dec 2010 20:27:07 +0000 (UTC) Cc: guile-user@gnu.org To: Keith Wright Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Wed Dec 01 21:27:02 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 1PNtGV-0007Dh-F2 for guile-user@m.gmane.org; Wed, 01 Dec 2010 21:26:59 +0100 Original-Received: from localhost ([127.0.0.1]:58145 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PNtGU-0002oe-SW for guile-user@m.gmane.org; Wed, 01 Dec 2010 15:26:58 -0500 Original-Received: from [140.186.70.92] (port=53826 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PNtGQ-0002lv-No for guile-user@gnu.org; Wed, 01 Dec 2010 15:26:55 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PNtGP-0007zs-ET for guile-user@gnu.org; Wed, 01 Dec 2010 15:26:54 -0500 Original-Received: from smtp-out21.han.skanova.net ([195.67.226.208]:60552) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PNtGP-0007za-4o for guile-user@gnu.org; Wed, 01 Dec 2010 15:26:53 -0500 Original-Received: from h131n2-fre-d2.ias.bredband.telia.com (78.72.157.131) by smtp-out21.han.skanova.net (8.5.124.10) (authenticated as u26619196) id 4C7E106502469F7F; Wed, 1 Dec 2010 21:26:51 +0100 In-Reply-To: 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:8265 Archived-At: On 1 Dec 2010, at 20:50, Hans Aberg wrote: >>> ... in standard syntax would be natural to let (f, g)(x) evaluate >>> to (f(x), g(x)), producing a list of two elements. In Guile, that >>> would be something involving "map". If I try in Haskell, I can let >>> (sin, cos)(2) be the same as >>> map (g 2) [sin, cos] where g x = \f -> f x >>> -> [0.909297426825682,-0.416146836547142] >>> But when I try that similar constructs in Guile, I get problems with >>> evaluation. >> >> Works for me >> >> guile> (let () >> (define (g x)(lambda (f)(f x))) >> (map (g 2) (list sin cos))) >> >> (0.909297426825682 -0.416146836547142) >> >> There are other ways to write it, but that >> is the most direct translation of your Haskell >> into Scheme. > > I was trying variations like > (let () > (define (g x)(lambda (f)(f x))) > (map (g 2) '(sin cos))) > Which gives an error: > In expression (f x): > Wrong type to apply: sin > > I'm not sure when to use quote or list, here. Quote seems to work > when the list is data, not a list of functions. I realized the problem here: quote prevents evaluation in the list, so one gets symbols, not procedures. Using back-quote and comma works: (let () (define (g x)(lambda (f)(f x))) (map (g 2) `(,sin ,cos))) Anyway, thanks, I now know what to fiddle around with.