[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Shorter lambda expressions

From: Panicz Maciej Godek
Subject: Re: Shorter lambda expressions
Date: Sat, 24 Sep 2016 11:38:28 +0200

2016-09-23 18:44 GMT+02:00 Panicz Maciej Godek <address@hidden>:
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))

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

reply via email to

[Prev in Thread] Current Thread [Next in Thread]