Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Re: Associativity paradox in functional expressions

70 views
Skip to first unread message

Totaram Sanadhya

unread,
Oct 31, 2012, 3:24:32 AM10/31/12
to
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?

Swami

Barb Knox

unread,
Oct 31, 2012, 4:14:22 AM10/31/12
to
In article
<9972e570-2504-4401...@c17g2000yqe.googlegroups.com>,
Easily: Lisp does not use curried functions.


> Swami
--
---------------------------
| BBB b \ Barbara at LivingHistory stop co stop uk
| B B aa rrr b |
| BBB a a r bbb | Quidquid latine dictum sit,
| B B a a r b b | altum videtur.
| BBB aa a r bbb |
-----------------------------

Nils M Holm

unread,
Oct 31, 2012, 5:21:23 AM10/31/12
to
In comp.lang.scheme Totaram Sanadhya <swami.totar...@gmail.com> wrote:
> 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?

It depends.

How do you obtain the curried F in the above expression?

What is (curry (curry cons x) y) supposed to give?

What exactly is the paradox?

Maybe, it would be helpful if you posted some code that
demonstrates what you are trying to do.

F'up-To: comp.lang.scheme

--
Nils M Holm < n m h @ t 3 x . o r g > www.t3x.org

Totaram Sanadhya

unread,
Oct 31, 2012, 1:34:04 PM10/31/12
to
On Oct 31, 1:14 am, Barb Knox <s...@sig.below> wrote:
> In article
> <9972e570-2504-4401-8de8-49eb1929f...@c17g2000yqe.googlegroups.com>,
> Totaram Sanadhya <swami.totaram.sanad...@gmail.com> wrote:
>
> > 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?
>
> Easily: Lisp does not use curried functions.

Which programming languages use curried functions?

I have often heard people like Kastrup talk of
curried functions in gnu.emacs.help and they
even give some code like

((lambda(g n) (funcall g g n))
(lambda(f n)
(if (zerop n) 1
(* n (funcall f f (1- n)))))
4 )


Is there some kind of hack by which I could come close to it in emacs
lisp?

I would have gladly put a backtrace or execution trace for you, but I
could not find a single function that gives an output like the
detailed backtrace when there is an execution error. Perhaps, someone
who is more knowledgeable can take this as an _aside_ question.

However, before I end my post, I just want to thank both Barb and
especially Nils for his student-friendly writings, and the wonderful
books he has written.

Swami

P.S. Unfortunately, I have to crosspost as this is relevant in many
groups, so please avoid or ignore any flames or derailing attempts.

Dirk Thierbach

unread,
Oct 31, 2012, 6:36:11 PM10/31/12
to
Totaram Sanadhya <swami.totar...@gmail.com> wrote:
> On Oct 31, 1:14 am, Barb Knox <s...@sig.below> wrote:
>> Easily: Lisp does not use curried functions.

> Which programming languages use curried functions?

The original lambda calculus, Haskell, OCaml, I think the whole ML family ...

On the other hand, these languages don't depend on lists for program
code.

[F'up to c.l.f.]

- Dirk

Pascal J. Bourguignon

unread,
Nov 2, 2012, 9:45:19 AM11/2/12
to
By defining a leflt-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 Bourguignon__

Rivka Miller

unread,
Nov 2, 2012, 9:59:48 PM11/2/12
to
On Nov 2, 6:45 am, "Pascal J. Bourguignon" <p...@informatimago.com>
wrote:
@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.

(defun lons (prefix item)
(append prefix (list item)))

(lons (lons (lons (lons nil 'a) 'b) 'c) 'd)

(lons (lons (lons '(f) 'x) 'y) 'z)

;; clarifies the meaning of lons by Pascal
(append (append (append (append nil (list 'a)) (list 'b)) (list 'c))
(list 'd))

;; clarifies the role of append
(append '(a b) '(c (d) e))

R





Pascal J. Bourguignon

unread,
Nov 2, 2012, 11:14:04 PM11/2/12
to
Rivka Miller <rivkau...@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

Rivka Miller

unread,
Nov 5, 2012, 7:53:16 PM11/5/12
to
On Nov 2, 7:14 pm, "Pascal J. Bourguignon" <p...@informatimago.com>
wrote:
Are you saying that the Late Dr McCarthy, after thinking of lisp in
terms of lambda calculus (and its associated currying), nevertheless
implemented it in terms of variadic non-curried functions? Thus the
turing machine replacement that lambda calculus is supposed to be,
does not need any currying to be a replacement of turing machine - in
the sense of computability?

How would the "(funcall g g n)" and "(funcall f f (1- n))" in the
function advanced by the OP supposed to be associated if currying were
available?

((lambda(g n) (funcall g g n))
(lambda(f n)
(if (zerop n) 1
(* n (funcall f f (1- n)))))
4 )


R

Pascal J. Bourguignon

unread,
Nov 6, 2012, 1:28:47 AM11/6/12
to
Rivka Miller <rivkau...@gmail.com> writes:

> Are you saying that the Late Dr McCarthy, after thinking of lisp in
> terms of lambda calculus (and its associated currying), nevertheless
> implemented it in terms of variadic non-curried functions? Thus the
> turing machine replacement that lambda calculus is supposed to be,
> does not need any currying to be a replacement of turing machine - in
> the sense of computability?

Yes. John McCarthy didn't understand lambda calculus at the time. He
just used the lambda notation for his functions, but they differed
greately, notably in that he used dynamic binding instead of lexical
binding.


> How would the "(funcall g g n)" and "(funcall f f (1- n))" in the
> function advanced by the OP supposed to be associated if currying were
> available?
>
> ((lambda(g n) (funcall g g n))
> (lambda(f n)
> (if (zerop n) 1
> (* n (funcall f f (1- n)))))
> 4 )

Well, in lisp there are parentheses to imply the order of evaluation…

Barb Knox

unread,
Nov 7, 2012, 11:35:58 PM11/7/12
to
In article <87ip9j8...@informatimago.com>,
"Pascal J. Bourguignon" <p...@informatimago.com> wrote:

> Rivka Miller <rivkau...@gmail.com> writes:
>
> > Are you saying that the Late Dr McCarthy, after thinking of lisp in
> > terms of lambda calculus (and its associated currying), nevertheless
> > implemented it in terms of variadic non-curried functions? Thus the
> > turing machine replacement that lambda calculus is supposed to be,
> > does not need any currying to be a replacement of turing machine - in
> > the sense of computability?

Lambda calculus supports currying. Lisp is not lambda calculus.
>
> Yes. John McCarthy didn't understand lambda calculus at the time. He
> just used the lambda notation for his functions

Yeah right. McCarthy had a PhD in mathematics and specialised in
mathematical logic; of course he knew lambda calculus. Or do you
believe his use of "lambda" was just a coincidence? In his1960 paper
introducing LISP ("Recursive Functions of Symbolic Expressions and Their
Computation by Machine"
<http://www-formal.stanford.edu/jmc/recursive.html>), one of his
references is Church's 1941 paper on the lambda calculus.

Are you a moron? Is that why you have such a self-aggrandising nickname?

[snip]

Aatu Koskensilta

unread,
Nov 8, 2012, 12:42:33 AM11/8/12
to
Barb Knox <s...@sig.below> writes:

> In article <87ip9j8...@informatimago.com>,
> "Pascal J. Bourguignon" <p...@informatimago.com> wrote:
>
>> Yes. John McCarthy didn't understand lambda calculus at the time. He
>> just used the lambda notation for his functions
>
> Yeah right. McCarthy had a PhD in mathematics and specialised in
> mathematical logic; of course he knew lambda calculus. Or do you
> believe his use of "lambda" was just a coincidence?

Naturally McCarthy got the lambda notation from lambda
calculus. McCarthy was not a mathematical logician by any stretch of the
imagination -- his research was mainly in computer science, artificial
intelligence in particular, and his PhD dissertation was on a problem in
partial differantial equations -- and had this to say about the state of
his understanding of the lambda calculus at the time:

To use functions as arguments, one needs a notation for functions,
and it seemed natural to use the lambda-notation of Church (1941). I
didn't understand the rest of the book, so I wasn't tempted to
implement his more general mechanism for defining functions.

This excerpt is from McCarthy's /History of Lisp/, available on-line at:

http://www-formal.stanford.edu/jmc/history/lisp.ps

> Are you a moron? Is that why you have such a self-aggrandising
> nickname?

You think "Pascal J. Bourguignon" a "self-aggrandising nickname"?

--
Aatu Koskensilta (aatu.kos...@uta.fi)

"Wovon man nicht sprechen kann, darüber muss man schweigen"
- Ludwig Wittgenstein, Tractatus Logico-Philosophicus

Pascal J. Bourguignon

unread,
Nov 8, 2012, 3:47:53 PM11/8/12
to
Aatu Koskensilta <aatu.kos...@uta.fi> writes:

> Barb Knox <s...@sig.below> writes:
>> Are you a moron? Is that why you have such a self-aggrandising
>> nickname?
>
> You think "Pascal J. Bourguignon" a "self-aggrandising nickname"?

"informatimago" would be the nickname. It means Software Sorcerer.
Yes, perhaps it's self aggrandising. You have to forgive it, I chosed
it when I was much younger. Software Sorcerer was a name we took with a
friend in 1984, when I was barely 20, with SOS\000 to SOS\377 having
been registered as MacOS application signatures with Apple Computer.
Unfortunately we split out before finishing our developments, and each
went his way. Eventually I moved to Spain and registered the
informatimago.com domain name on 25-may-2001. I was probably influenced
by those early memories and by sicp.

Barb Knox

unread,
Nov 9, 2012, 9:13:20 PM11/9/12
to
In article <87zk2sa...@uta.fi>,
Aatu Koskensilta <aatu.kos...@uta.fi> wrote:

> Barb Knox <s...@sig.below> writes:
>
> > In article <87ip9j8...@informatimago.com>,
> > "Pascal J. Bourguignon" <p...@informatimago.com> wrote:
> >
> >> Yes. John McCarthy didn't understand lambda calculus at the time. He
> >> just used the lambda notation for his functions
> >
> > Yeah right. McCarthy had a PhD in mathematics and specialised in
> > mathematical logic; of course he knew lambda calculus. Or do you
> > believe his use of "lambda" was just a coincidence?
>
> Naturally McCarthy got the lambda notation from lambda
> calculus. McCarthy was not a mathematical logician by any stretch of the
> imagination -- his research was mainly in computer science, artificial
> intelligence in particular, and his PhD dissertation was on a problem in
> partial differantial equations -- and had this to say about the state of
> his understanding of the lambda calculus at the time:
>
> To use functions as arguments, one needs a notation for functions,
> and it seemed natural to use the lambda-notation of Church (1941). I
> didn't understand the rest of the book, so I wasn't tempted to
> implement his more general mechanism for defining functions.
>
> This excerpt is from McCarthy's /History of Lisp/, available on-line at:
>
> http://www-formal.stanford.edu/jmc/history/lisp.ps
>
> > Are you a moron? Is that why you have such a self-aggrandising
> > nickname?
>
> You think "Pascal J. Bourguignon" a "self-aggrandising nickname"?

Oops. I confused it with "Harrison Bergeron". My bad. And I withdraw
the "moron" semi-rhetorical question.
0 new messages