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 23:43:45 +0100 Message-ID: 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 1291243450 19908 80.91.229.12 (1 Dec 2010 22:44:10 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Wed, 1 Dec 2010 22:44:10 +0000 (UTC) To: guile-user@gnu.org Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Wed Dec 01 23:44:06 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 1PNvPB-00060I-Vb for guile-user@m.gmane.org; Wed, 01 Dec 2010 23:44:06 +0100 Original-Received: from localhost ([127.0.0.1]:44149 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PNvPB-0002pT-Fs for guile-user@m.gmane.org; Wed, 01 Dec 2010 17:44:05 -0500 Original-Received: from [140.186.70.92] (port=47635 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PNvOv-0002kz-Mz for guile-user@gnu.org; Wed, 01 Dec 2010 17:43:50 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PNvOu-0003eQ-Ck for guile-user@gnu.org; Wed, 01 Dec 2010 17:43:49 -0500 Original-Received: from smtp-out12.han.skanova.net ([195.67.226.212]:38945) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PNvOu-0003eB-42 for guile-user@gnu.org; Wed, 01 Dec 2010 17:43:48 -0500 Original-Received: from h131n2-fre-d2.ias.bredband.telia.com (78.72.157.131) by smtp-out12.han.skanova.net (8.5.124.10) (authenticated as u26619196) id 4C7E0D4901C00A45 for guile-user@gnu.org; Wed, 1 Dec 2010 23:43:46 +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:8270 Archived-At: On 1 Dec 2010, at 22:34, Keith Wright wrote: >> 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 > > Somebody should patch that so that it mentions the > wrong type. it means > > first argument of apply should be a function > but it is: sin, which is a symbol Yes, I realized this. >> 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. > > It's the other way around; |quote| is a keyword > that means that the following is data. > If you want to make a list of anything other > than literal data, use |list|. > > So '(sin cos) is data: a list of two symbols, > the same as (list 'sin 'cos). Strictly speaking, they are, as you noted, symbols. Quote turns off further evaluation. If one should have a more normal evaluation model of tuples, perhaps one should use back-quote and commas (see below). > On the other hand |list| is an ordinary variable > so, (list sin cos) is evaluated by evaluating > the three subexpressions, giving a function > that makes lists and two numeric functions of > a numeric vaiable, and then applying the first > function, i.e. list, to the two arguments, ie. > sin and cos, giving a list of functions. I build lists directly using the Guile C functions. However, I encountered an ambiguity in my implementation which has to do with the (x) = x property of tuples: both x y and (x, y) parsed as Guile (x y) = (list x y). If one writes just (x_1, ..., x_k), what Guile object should one get? (x_1 ... x_k) may cause later evaluation, '(x_1 ... x_k) turns off evaluation of the arguments. So perhaps one should construct `(,x_1 ... ,x_k). >> This normality only has to do with parser grammar >> implementation. If in the evaluation syntax f ..., >> and the binding syntax corresponding in Haskell to >> \... -> f, the two "..." use the same syntax, I can >> eliminate the "\". Then the evaluation syntax (f_1, >> ..., f_k) x becomes available. I could eliminate it >> semnatically or set it to what is common in math, if >> not too complicated. >> >>>>>> and () x into (() x), but I'm not sure if the >>>>>> lists (f g) and () can be made acting as functions >>>>>> this way. >>> >>> I have not only never seen the "normal syntax" in >>> use here, but I have no guess what it is supposed >>> to mean. In Scheme "(() x)" means nothing at all. >>> In fact it is so far from meaningful that I can >>> not guess how to fix it. >> >> 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. Yes, and the first item of the list should not treat the following items as its arguments for an evaluation. It is a different data object than the Guile evaluation list. > 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) > > The only tricky part is that apply takes > a function and a list of arguments, > and so (list x) is a list of one argument. Thank you. I will try some different possibilities.