[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: pcase defuns
From: |
Stefan Monnier |
Subject: |
Re: pcase defuns |
Date: |
Sun, 19 Dec 2021 12:23:59 -0500 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux) |
> As a part of a personal project, I wrote a way to define functions in an
> equivalent way to pcases. For example:
>
> (pcase-defun mytest (a b _)
> "Match on 'a 'b with the third argument a wildcard"
> "a b match")
>
> (pcase-defun mytest (c ,var _)
> "Match on 'c binding VAR, with the third argument a wildcard"
> (format "c %s match" var) )
>
> (mytest 'a 'b 'c) -> "a b match"
> (mytest 'c 100 'c) -> "c 100 match"
>
> This is all accomplished by a few small but tricky macros and a hashtable
> that holds all the rules.
This kind of design crossed my mind a few times but I couldn't come up
with a way to give it a reasonable semantics and implementation.
Beside the issue of precedence/ordering already mentioned by Tassilo,
there's the issue of scoping and order/timing of macroexpansion. E.g.:
(let ((x 0))
(pcase-defun mytest (inc-x)
(setq x (1+ x)))
(pcase-defun mytest (get-x)
x))
(let ((y 0))
(pcase-defun mytest (inc-y)
(setq y (1+ y)))
(pcase-defun mytest (get-y)
y))
Does this work "right" with your code?
Or:
(eval-when-compile (require 'cl-lib))
(pcase-defun foo (..)
..
(cl-incf ..)
..)
is `cl-incf` properly macroexpanded during compilation of the file, or
is it delayed to when the file is loaded, at which point the `cl-incf`
macro may be undefined?
Stefan
Re: pcase defuns,
Stefan Monnier <=
- Re: pcase defuns, Andrew Hyatt, 2021/12/19
- Re: pcase defuns, Richard Stallman, 2021/12/20
- Re: pcase defuns, Andrew Hyatt, 2021/12/21
- Re: pcase defuns, Richard Stallman, 2021/12/21
- Re: pcase defuns, Andrew Hyatt, 2021/12/22
- Re: pcase defuns, Richard Stallman, 2021/12/23
Re: pcase defuns, Stefan Monnier, 2021/12/21
Re: pcase defuns, Richard Stallman, 2021/12/19
Re: pcase defuns, Po Lu, 2021/12/22