all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Another pcase-lambda
@ 2017-09-19  0:56 Mark Oteiza
  2017-09-21 11:40 ` Michael Heerdegen
  0 siblings, 1 reply; 11+ messages in thread
From: Mark Oteiza @ 2017-09-19  0:56 UTC (permalink / raw)
  To: emacs-devel; +Cc: Stefan Monnier

Hi,

I wrote the following, as I wanted more out of pcase-lambda.  However,
pcase-lambda already exists so I don't know what to call it.  It does
somewhat emulate SRFI-16's case-lambda.

(defmacro case-lambda (&rest spec)
  "Return an arbitrary arity function."
  (declare (indent 0) (debug (&rest (pcase-QPAT body))))
  (let ((args (make-symbol "args")))
   `(lambda (&rest ,args)
      (pcase-exhaustive ,args ,@spec))))

(case-lambda
  (`() t)
  (`(,x) (cons x 1))
  (`(,x ,y) (list :x x :y y))
  (`(,x ,y . ,z) (vconcat (cons x (cons y z)))))




^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Another pcase-lambda
  2017-09-19  0:56 Another pcase-lambda Mark Oteiza
@ 2017-09-21 11:40 ` Michael Heerdegen
  2017-09-22 21:37   ` Mark Oteiza
  0 siblings, 1 reply; 11+ messages in thread
From: Michael Heerdegen @ 2017-09-21 11:40 UTC (permalink / raw)
  To: Mark Oteiza; +Cc: Stefan Monnier, emacs-devel

Mark Oteiza <mvoteiza@udel.edu> writes:

> (defmacro case-lambda (&rest spec)
>   "Return an arbitrary arity function."
>   (declare (indent 0) (debug (&rest (pcase-QPAT body))))
>   (let ((args (make-symbol "args")))
>    `(lambda (&rest ,args)
>       (pcase-exhaustive ,args ,@spec))))

I think I would prefer to spell it out and use the expanded form
instead.  It's nice, but I'm not convinced it would be worth adding.

OTOH, as an occasional user of `pcase-lambda' I know that it's a bit
cumbersome to use.  But `case-lambda' defers all calculation into the
argument list - I'm not sure if this is so useful all the time.

BTW, what I sometimes do miss is `pcase-defun'.


Michael.



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Another pcase-lambda
  2017-09-21 11:40 ` Michael Heerdegen
@ 2017-09-22 21:37   ` Mark Oteiza
  2017-09-22 21:50     ` Clément Pit-Claudel
  2017-09-23 14:25     ` Michael Heerdegen
  0 siblings, 2 replies; 11+ messages in thread
From: Mark Oteiza @ 2017-09-22 21:37 UTC (permalink / raw)
  To: Michael Heerdegen; +Cc: Stefan Monnier, emacs-devel

On 21/09/17 at 11:40am, Michael Heerdegen wrote:
> Mark Oteiza <mvoteiza@udel.edu> writes:
> 
> > (defmacro case-lambda (&rest spec)
> >   "Return an arbitrary arity function."
> >   (declare (indent 0) (debug (&rest (pcase-QPAT body))))
> >   (let ((args (make-symbol "args")))
> >    `(lambda (&rest ,args)
> >       (pcase-exhaustive ,args ,@spec))))
> 
> I think I would prefer to spell it out and use the expanded form
> instead.  It's nice, but I'm not convinced it would be worth adding.
> 
> OTOH, as an occasional user of `pcase-lambda' I know that it's a bit
> cumbersome to use.  But `case-lambda' defers all calculation into the
> argument list - I'm not sure if this is so useful all the time.

Thanks.  I just always expect pcase-lambda to behave more like pcase,
hence I wrote this.

> BTW, what I sometimes do miss is `pcase-defun'.

Was that a thing that existed?



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Another pcase-lambda
  2017-09-22 21:37   ` Mark Oteiza
@ 2017-09-22 21:50     ` Clément Pit-Claudel
  2017-09-23 14:25     ` Michael Heerdegen
  1 sibling, 0 replies; 11+ messages in thread
From: Clément Pit-Claudel @ 2017-09-22 21:50 UTC (permalink / raw)
  To: emacs-devel

On 2017-09-22 23:37, Mark Oteiza wrote:
> Thanks.  I just always expect pcase-lambda to behave more like pcase,
> hence I wrote this.

Am I correct to think that is is very similar to ML's 'function'? as in

let string_of_bool = function
  | true -> "true"
  | false -> "false"

If so, could pcase-function work?

Clément.




^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Another pcase-lambda
  2017-09-22 21:37   ` Mark Oteiza
  2017-09-22 21:50     ` Clément Pit-Claudel
@ 2017-09-23 14:25     ` Michael Heerdegen
  2017-09-23 14:29       ` Stefan Monnier
  1 sibling, 1 reply; 11+ messages in thread
From: Michael Heerdegen @ 2017-09-23 14:25 UTC (permalink / raw)
  To: Mark Oteiza; +Cc: Stefan Monnier, emacs-devel

Mark Oteiza <mvoteiza@udel.edu> writes:

> > BTW, what I sometimes do miss is `pcase-defun'.
>
> Was that a thing that existed?

No, it never existed, but maybe it should?  pcase argument matching is
not only useful for anonymous functions.  I often wanted it for named
helper functions and had to `defalias' to a `pcase-lambda'.


Michael.



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Another pcase-lambda
  2017-09-23 14:25     ` Michael Heerdegen
@ 2017-09-23 14:29       ` Stefan Monnier
  2017-09-23 15:31         ` Michael Heerdegen
  2017-09-28 21:11         ` Ted Zlatanov
  0 siblings, 2 replies; 11+ messages in thread
From: Stefan Monnier @ 2017-09-23 14:29 UTC (permalink / raw)
  To: emacs-devel

>> > BTW, what I sometimes do miss is `pcase-defun'.
>> Was that a thing that existed?
> No, it never existed, but maybe it should?  pcase argument matching is
> not only useful for anonymous functions.  I often wanted it for named
> helper functions and had to `defalias' to a `pcase-lambda'.

There a "case" to be made that all variable bindings should support the
pcase syntax (i.e. dolist should be pcase-dolist, let should be
pcase-let, ...).


        Stefan




^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Another pcase-lambda
  2017-09-23 14:29       ` Stefan Monnier
@ 2017-09-23 15:31         ` Michael Heerdegen
  2017-09-28 21:11         ` Ted Zlatanov
  1 sibling, 0 replies; 11+ messages in thread
From: Michael Heerdegen @ 2017-09-23 15:31 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: emacs-devel

Stefan Monnier <monnier@iro.umontreal.ca> writes:

> There a "case" to be made that all variable bindings should support the
> pcase syntax (i.e. dolist should be pcase-dolist, let should be
> pcase-let, ...).

Great to hear that you consider this as something that could actually
become reality.

Michael.



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Another pcase-lambda
  2017-09-23 14:29       ` Stefan Monnier
  2017-09-23 15:31         ` Michael Heerdegen
@ 2017-09-28 21:11         ` Ted Zlatanov
  2017-10-04 11:03           ` Michael Heerdegen
  1 sibling, 1 reply; 11+ messages in thread
From: Ted Zlatanov @ 2017-09-28 21:11 UTC (permalink / raw)
  To: emacs-devel

On Sat, 23 Sep 2017 10:29:53 -0400 Stefan Monnier <monnier@iro.umontreal.ca> wrote: 

SM> There a "case" to be made that all variable bindings should support the
SM> pcase syntax (i.e. dolist should be pcase-dolist, let should be
SM> pcase-let, ...).

I'm not sure I understand what you're proposing.

Ted




^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Another pcase-lambda
  2017-09-28 21:11         ` Ted Zlatanov
@ 2017-10-04 11:03           ` Michael Heerdegen
  2017-10-04 16:12             ` Ted Zlatanov
  0 siblings, 1 reply; 11+ messages in thread
From: Michael Heerdegen @ 2017-10-04 11:03 UTC (permalink / raw)
  To: emacs-devel

Ted Zlatanov <tzz@lifelogs.com> writes:

> On Sat, 23 Sep 2017 10:29:53 -0400 Stefan Monnier
> <monnier@iro.umontreal.ca> wrote:
>
> SM> There a "case" to be made that all variable bindings should
> SM> support the pcase syntax (i.e. dolist should be pcase-dolist, let
> SM> should be pcase-let, ...).
>
> I'm not sure I understand what you're proposing.

AFAIU the proposal is to make any construct that receives variable
bindings implicitly act like the `pcase' variant, i.e. `lambda' would
become equivalent to `pcase-lambda' (which would become obsolete) etc.


Michael.



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Another pcase-lambda
  2017-10-04 11:03           ` Michael Heerdegen
@ 2017-10-04 16:12             ` Ted Zlatanov
  2017-10-05  3:13               ` Stefan Monnier
  0 siblings, 1 reply; 11+ messages in thread
From: Ted Zlatanov @ 2017-10-04 16:12 UTC (permalink / raw)
  To: emacs-devel

On Wed, 04 Oct 2017 13:03:03 +0200 Michael Heerdegen <michael_heerdegen@web.de> wrote: 

MH> Ted Zlatanov <tzz@lifelogs.com> writes:
>> On Sat, 23 Sep 2017 10:29:53 -0400 Stefan Monnier
>> <monnier@iro.umontreal.ca> wrote:
>> 
SM> There a "case" to be made that all variable bindings should
SM> support the pcase syntax (i.e. dolist should be pcase-dolist, let
SM> should be pcase-let, ...).
>> 
>> I'm not sure I understand what you're proposing.

MH> AFAIU the proposal is to make any construct that receives variable
MH> bindings implicitly act like the `pcase' variant, i.e. `lambda' would
MH> become equivalent to `pcase-lambda' (which would become obsolete) etc.

That sounds good for people who use `pcase'. Does it have the potential
to create confusion or bugs (including performance issues) for the rest?
If yes, can it be optional for some time?

Outside of those concerns, I think it's a great idea and would use it.

Ted




^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: Another pcase-lambda
  2017-10-04 16:12             ` Ted Zlatanov
@ 2017-10-05  3:13               ` Stefan Monnier
  0 siblings, 0 replies; 11+ messages in thread
From: Stefan Monnier @ 2017-10-05  3:13 UTC (permalink / raw)
  To: emacs-devel

> That sounds good for people who use `pcase'. Does it have the potential
> to create confusion or bugs (including performance issues) for the rest?

I think it's pretty unlikely to be used inadvertently.

> If yes, can it be optional for some time?

It's not clear how to implement it, so I wouldn't worry about details of
how/if/when it gets introduced.


        Stefan







^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2017-10-05  3:13 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-09-19  0:56 Another pcase-lambda Mark Oteiza
2017-09-21 11:40 ` Michael Heerdegen
2017-09-22 21:37   ` Mark Oteiza
2017-09-22 21:50     ` Clément Pit-Claudel
2017-09-23 14:25     ` Michael Heerdegen
2017-09-23 14:29       ` Stefan Monnier
2017-09-23 15:31         ` Michael Heerdegen
2017-09-28 21:11         ` Ted Zlatanov
2017-10-04 11:03           ` Michael Heerdegen
2017-10-04 16:12             ` Ted Zlatanov
2017-10-05  3:13               ` Stefan Monnier

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.