Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.programming > #2443

Re: Associativity paradox in functional expressions

From "Pascal J. Bourguignon" <pjb@informatimago.com>
Newsgroups comp.lang.functional, comp.lang.lisp, comp.lang.scheme, comp.programming, comp.emacs
Subject Re: Associativity paradox in functional expressions
Date 2012-11-03 04:14 +0100
Organization Informatimago
Message-ID <87liejml8j.fsf@informatimago.com> (permalink)
References <8120f97b-15c2-4ce8-827a-158e955fb73f@z2g2000yqj.googlegroups.com> <9972e570-2504-4401-8de8-49eb1929fdfd@c17g2000yqe.googlegroups.com> <87pq3wqftc.fsf@voyager.informatimago.com> <3dd68e98-9889-4287-a352-3c7c25a3284e@d17g2000vbv.googlegroups.com>

Cross-posted to 5 groups.

Show all headers | View raw


Rivka Miller <rivkaumiller@gmail.com> writes:

> On Nov 2, 6:45 am, "Pascal J. Bourguignon" <p...@informatimago.com>
> wrote:
>> Totaram Sanadhya <swami.totaram.sanad...@gmail.com> writes:
>> > Hi,
>>
>> > My main functional language is emacs based lisp.
>>
>> > I am not exactly clear about the associativity.
>>
>> > On the one hand the elements of a list such as (a b c d) are right
>> > associative
>>
>> > (cons 'a (cons 'b (cons 'c (cons 'd nil))))    C-x C-e
>>
>> > ==> (a b c d)
>>
>> > On the other hand a curried function such as (f x y z) is left
>> > associative by definition
>>
>> > (...(f x) y) z)
>>
>> > How do you resolve this paradox?
>>
>> By defining a left-associative function.
>>
>>     (defun lons (prefix item)
>>        (append prefix (list item)))
>>
>>     (lons (lons (lons (lons nil 'a) 'b) 'c) 'd)
>>     --> (a b c d)
>>
>>     (lons (lons (lons '(f) 'x) 'y) 'z)
>>     --> (f x y z)
>
> @Pascal
>
> I did not get what you achieved by defining a left-associative
> function. Your sentence did not clarify your thought. I dont see where
> is currying achieved.

Currying is not achieved, there's no currying in lisp, lisp has
multi-adic and variadic functions.  Currying is a notion that is only
needed when you have function taking only one argument.



Now,  you may write a macro that implements some currying.  In such a
macro, you would use lons instead of cons…


-- 
__Pascal Bourguignon__
http://www.informatimago.com

Back to comp.programming | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Re: Associativity paradox in functional expressions Totaram Sanadhya <swami.totaram.sanadhya@gmail.com> - 2012-10-31 00:24 -0700
  Re: Associativity paradox in functional expressions Barb Knox <see@sig.below> - 2012-10-31 21:14 +1300
    Re: Associativity paradox in functional expressions Totaram Sanadhya <swami.totaram.sanadhya@gmail.com> - 2012-10-31 10:34 -0700
      Re: Associativity paradox in functional expressions Dirk Thierbach <dthierbach@usenet.arcornews.de> - 2012-10-31 23:36 +0100
  Re: Associativity paradox in functional expressions Nils M Holm <news2009@t3x.org> - 2012-10-31 09:21 +0000
  Re: Associativity paradox in functional expressions "Pascal J. Bourguignon" <pjb@informatimago.com> - 2012-11-02 14:45 +0100
    Re: Associativity paradox in functional expressions Rivka Miller <rivkaumiller@gmail.com> - 2012-11-02 18:59 -0700
      Re: Associativity paradox in functional expressions "Pascal J. Bourguignon" <pjb@informatimago.com> - 2012-11-03 04:14 +0100
        Re: Associativity paradox in functional expressions Rivka Miller <rivkaumiller@gmail.com> - 2012-11-05 16:53 -0800
          Re: Associativity paradox in functional expressions "Pascal J. Bourguignon" <pjb@informatimago.com> - 2012-11-06 07:28 +0100
            Re: Associativity paradox in functional expressions Barb Knox <see@sig.below> - 2012-11-08 17:35 +1300
              Re: Associativity paradox in functional expressions Aatu Koskensilta <aatu.koskensilta@uta.fi> - 2012-11-08 07:42 +0200
                Re: Associativity paradox in functional expressions "Pascal J. Bourguignon" <pjb@informatimago.com> - 2012-11-08 21:47 +0100
                Re: Associativity paradox in functional expressions Barb Knox <see@sig.below> - 2012-11-10 15:13 +1300

csiph-web