[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Instead of pcase
|
From: |
Barry Fishman |
|
Subject: |
Re: Instead of pcase |
|
Date: |
Sun, 19 Nov 2023 11:02:49 -0500 |
|
User-agent: |
Gnus/5.13 (Gnus v5.13) |
On 2023-11-19 13:23:17 +01, Michael Heerdegen wrote:
> So, the advantage would be more of a psychological kind: you have normal
> Lisp function calls, but structurally you have the same thing, and you
> have to remember exactly the same set of details. The complexity comes
> from the task, not from the implementation.
I submit that the opposite is true, the complexity is in its
implementation, not the task.
In languages like Haskell this is expressed in a very simple way, so the
task is not in itself hard to understand.
For example, one implementation might be to use the form:
(proto-case x
(typeproto guard expressions...)
...)
The typeproto would be a type, or a list made up of the type and a
variable that could be use in the expression.
The guard would be an expression which is required to be true before a
match can be declared.
Composite types like pair, list, vector, or list*, would have typeproto's
for their arguments when they are expanded as a list):
(proto-case x
((list string integer) t ...))
which would match a list of two element, the first a string, and the
second an integer. The guard (t) would always consider it a match.
The list arguments which are typeproto's themselves, could be made into
assignments with using a list, as above.
If x is a list with its first element a string "foo" and the second an
integer, remove it from x and add the second element to total:
(proto-case x
((list* (string name) (integer count) (t rest))
(string-equal name "foo")
(set! total (+ total count))
(set! x rest)))
This is just one of many other ways one could setup a matching
expression in elisp, the best is a balance between implementation
efficiency and readability.
I think the complexity doesn't come from the task, but comes from the
choice of implementation. So its the complexity of the implementation
that should determines whether it is worth while implementing.
Although back-quoting is part of Lisp, it was added to solve a specific
problem, and unfortunately added new syntax tokens to Lisp, which it
otherwise avoids.
--
Barry Fishman
- Complex SPEC for variables/customization like font-lock-keywords/org-capture-templates/etc (was: Instead of pcase), (continued)
- Re: Instead of pcase, Eli Zaretskii, 2023/11/16
- Re: Instead of pcase, Michael Heerdegen, 2023/11/17
- Re: Instead of pcase, Dmitry Gutov, 2023/11/16
- Re: Instead of pcase, T.V Raman, 2023/11/16
- Re: Instead of pcase, Philip Kaludercic, 2023/11/16
- Re: Instead of pcase, T.V Raman, 2023/11/16
- Re: Instead of pcase, Richard Stallman, 2023/11/17
- Re: Instead of pcase, Michael Heerdegen, 2023/11/19
- Re: Instead of pcase,
Barry Fishman <=
- Re: Instead of pcase, Dmitry Gutov, 2023/11/19
- Re: Instead of pcase, Eric Abrahamsen, 2023/11/19
- Re: Instead of pcase, Stefan Monnier, 2023/11/24
- Re: Instead of pcase, Richard Stallman, 2023/11/26
- Re: Instead of pcase, Barry Fishman, 2023/11/19
- Re: Instead of pcase, Dmitry Gutov, 2023/11/19
- Re: Instead of pcase, Michael Heerdegen, 2023/11/20
- Re: Instead of pcase, Richard Stallman, 2023/11/22
- Re: Instead of pcase, Dmitry Gutov, 2023/11/24
- Re: Instead of pcase, Richard Stallman, 2023/11/26