unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: "Pascal J. Bourguignon" <pjb@informatimago.com>
To: help-gnu-emacs@gnu.org
Subject: Re: Style Issues in Lisp and Scheme programming, setq versus let ... and onion structure with multiple cores or eyes or kernels Re: string to list or string to array
Date: Wed, 21 Nov 2012 22:56:55 +0100	[thread overview]
Message-ID: <87a9uapql4.fsf@kuiper.lan.informatimago.com> (raw)
In-Reply-To: 9b568902-c943-4b69-b80f-21f7fb0f814b@o8g2000yqh.googlegroups.com

gnuist007@hotmail.com writes:

> On Oct 24, 8:03 am, Stefan Monnier <monn...@iro.umontreal.ca> wrote:
>> > btw, Lisp's prefix notation, (f x y z) is more expressive and
>> > convenient for expressing currying (((f x) y) z) than f(x y z).
>>
>> With all due respect to Lisp, that's not true.  Curried calls in the
>> non-Lisp syntax are simply "f(x)(y)(z)" or even better "f x y z".
>>
>>         Stefan
>
> As an aside you show the notation. well and good. But I realize that
> there is no executable substitute or ability to return a curried
> function
> in emacs. Consider these forms.
>
> (+ 2 3 4) ;; executable
> (((+ 2) 3) 4)  ;; not executable
> (cons '+ (cons 2 (cons 3 (cons 4 nil))))  ;; ditto
> (eval  '(+ (cons 2 (cons 3 (cons 4 nil)))))  ;; ditto
>
> Can anyone suggest an executable version of first in terms of curried
> addition?
>
> Since Pascal is busy, and David Kastrup is not seen for quite some
> time, I hope someone can give a reply to the question of the thread.


Well, if you want to keep the variadicity of the operation, it's hardly
possible, because you can only return either a number or a function.  In
lisp, numbers are not applicable functions.

Otherwise the following should work, in emacs-24:

;; in emacs-24:
(setq lexical-binding t)
(defun plus/2 (arg) (lambda (x) (+ arg x)))
(defun plus/3 (arg) (lambda (y) (plus/2 (funcall (plus/2 arg) y))))

(funcall (plus/2  2) 3)                --> 5
(funcall (plus/3  2) 3)                --> #<some closure>
(funcall (funcall (plus/3  2) 3) 4)    --> 9


-- 
__Pascal Bourguignon__                     http://www.informatimago.com/
A bad day in () is better than a good day in {}.


  parent reply	other threads:[~2012-11-21 21:56 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-10-21 10:37 string to list or string to array Swami Tota Ram Shankar
2012-10-21 11:16 ` Pascal J. Bourguignon
2012-10-21 19:03   ` Swami Tota Ram Shankar
2012-10-21 20:22     ` Pascal J. Bourguignon
2012-10-23  1:16       ` Style Issues in Lisp and Scheme programming, setq versus let ... and onion structure with multiple cores or eyes or kernels " Swami Tota Ram Shankar
2012-10-23  2:36         ` PJ Weisberg
     [not found]         ` <mailman.11503.1350959781.855.help-gnu-emacs@gnu.org>
2012-10-23  3:02           ` Swami Tota Ram Shankar
2012-10-24 15:03             ` Stefan Monnier
2012-10-25  3:20               ` gnuist007
2012-10-25  8:25                 ` José A. Romero L.
2012-11-21 21:56                 ` Pascal J. Bourguignon [this message]
2012-10-23  8:15         ` Pascal J. Bourguignon
2012-10-24  8:05         ` Thien-Thi Nguyen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87a9uapql4.fsf@kuiper.lan.informatimago.com \
    --to=pjb@informatimago.com \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).