unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: Panicz Maciej Godek <godek.maciek@gmail.com>
To: guile-devel <guile-devel@gnu.org>
Subject: Re: Shorter lambda expressions
Date: Sat, 24 Sep 2016 11:38:28 +0200	[thread overview]
Message-ID: <CAMFYt2Y7jL2YtXtb-7R6ovbsBMOrFiw_=b4-z32bdK0CXUoYNw@mail.gmail.com> (raw)
In-Reply-To: <CAMFYt2b4h5pPNCXyaSx_Con2dTM-tnW0S4ASCGajybr3z9f6mg@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 1697 bytes --]

2016-09-23 18:44 GMT+02:00 Panicz Maciej Godek <godek.maciek@gmail.com>:

> I hope you don't mind me having dug this thread up, with an idea that is
> only loosely related with the original one.
>
> Recently I've been doing a small project in Clojure, and I've found that
> it provides a function called "partial" that performs a sort of partial
> application.
>
> With guile's curried definitions, it can be defined as
>
> (define ((partial function . args) . args+)
>   (apply function `(,@args ,@args+)))
>
> and it works rather nicely:
>
> (map (partial cons 2) '((3 4) (3 5) (4 6) (7 1)))
> ===> ((2 3 4) (2 3 5) (2 4 6) (2 7 1))
>
> I believe that -- since it is just a function -- it is much less
> controversial than both the short macros and SRFI-26  (although its range
> of applicability is narrower), and it seems to compose well with the spirit
> of Scheme, so maybe that would be a nice-have?
>

I take it back.
It is a terrible idea. Using explicit lambda is a better solution, because
it gives an opportunity to provide a name for an element of a list. Yet the
name "partial" reads terribly. Compound usages such as

(partial map (partial cons 1))

are much worse than their regular counterparts, i.e.

(lambda (list)
  (map (lambda (element)
             (cons 1 element))
          list))

because even though the latter are more lengthy, this length actually
serves the purpose of exposing the structure of expression. In the former
case, it isn't clear (without knowing the arity of map) what will be the
arity of the whole expression, nor the role of those arguments. It seems to
be a problem even in the case of well-known functions such as cons or map.

Sorry for the noise

[-- Attachment #2: Type: text/html, Size: 2442 bytes --]

  reply	other threads:[~2016-09-24  9:38 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-01-23  4:51 Shorter lambda expressions Mark H Weaver
2014-01-23  7:17 ` Mateusz Kowalczyk
2014-01-23  8:17 ` Panicz Maciej Godek
2014-01-24 10:54   ` Ludovic Courtès
2014-01-24 11:28     ` Taylan Ulrich Bayırlı/Kammer
2014-01-24 16:09       ` Mark H Weaver
2016-09-23 16:44 ` Panicz Maciej Godek
2016-09-24  9:38   ` Panicz Maciej Godek [this message]
     [not found] <201401241138.s0OBc9u5025102@lambda.ccs.neu.edu>
2014-01-24 13:28 ` Eli Barzilay

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/guile/

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

  git send-email \
    --in-reply-to='CAMFYt2Y7jL2YtXtb-7R6ovbsBMOrFiw_=b4-z32bdK0CXUoYNw@mail.gmail.com' \
    --to=godek.maciek@gmail.com \
    --cc=guile-devel@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).