* pcase with progn
@ 2024-11-27 18:45 Heime via Users list for the GNU Emacs text editor
2024-11-27 19:39 ` Scott Bell
2024-11-28 14:44 ` Stefan Monnier via Users list for the GNU Emacs text editor
0 siblings, 2 replies; 5+ messages in thread
From: Heime via Users list for the GNU Emacs text editor @ 2024-11-27 18:45 UTC (permalink / raw)
To: Heime via Users list for the GNU Emacs text editor
Does pcase require progn for multiple commands?
(defun pola-symbol-name (sbl &optional sel)
"Get the string representation of symbol SBL. If it is
already a string, return it unchanged."
(cond
((symbolp sbl) (symbol-name sbl))
((stringp sbl) sbl)
(t (pcase sel
('nil (error "SBL must be a symbol or a string: %s" sbl))
('nil-output nil)
('default "unknown")
('warn (progn
(message "SBL not symbol nor string: %s" sbl)
nil))
('pass sbl)
(_ (error "SEL Invalid: %s" sel))))))
Sent with Proton Mail secure email.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: pcase with progn
2024-11-27 18:45 pcase with progn Heime via Users list for the GNU Emacs text editor
@ 2024-11-27 19:39 ` Scott Bell
2024-11-27 20:50 ` Heime via Users list for the GNU Emacs text editor
2024-11-28 14:44 ` Stefan Monnier via Users list for the GNU Emacs text editor
1 sibling, 1 reply; 5+ messages in thread
From: Scott Bell @ 2024-11-27 19:39 UTC (permalink / raw)
To: help-gnu-emacs; +Cc: Heime
Heime via Users list for the GNU Emacs text editor
<help-gnu-emacs@gnu.org> writes:
> Does pcase require progn for multiple commands?
Nope. Each clause is of the form ‘(PATTERN BODY-FORMS...)’, where the
body forms of the successful clause are evaluated and the final value is
returned. In this sense it behaves similarly to ‘cond’.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: pcase with progn
2024-11-27 19:39 ` Scott Bell
@ 2024-11-27 20:50 ` Heime via Users list for the GNU Emacs text editor
2024-11-27 22:33 ` Scott Bell
0 siblings, 1 reply; 5+ messages in thread
From: Heime via Users list for the GNU Emacs text editor @ 2024-11-27 20:50 UTC (permalink / raw)
To: Scott Bell; +Cc: help-gnu-emacs
Sent with Proton Mail secure email.
On Thursday, November 28th, 2024 at 7:39 AM, Scott Bell <sctb@me.com> wrote:
> Heime via Users list for the GNU Emacs text editor
> help-gnu-emacs@gnu.org writes:
>
> > Does pcase require progn for multiple commands?
>
>
> Nope. Each clause is of the form ‘(PATTERN BODY-FORMS...)’, where the
> body forms of the successful clause are evaluated and the final value is
> returned. In this sense it behaves similarly to ‘cond’.
The command should return the string representation of symbol if
it exists. When the command fails (symbol does not exist), are commands
customarily return nil or an error?
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: pcase with progn
2024-11-27 20:50 ` Heime via Users list for the GNU Emacs text editor
@ 2024-11-27 22:33 ` Scott Bell
0 siblings, 0 replies; 5+ messages in thread
From: Scott Bell @ 2024-11-27 22:33 UTC (permalink / raw)
To: Heime; +Cc: help-gnu-emacs
Heime <heimeborgia@protonmail.com> writes:
> (defun pola-symbol-name (sbl &optional sel)
> "Get the string representation of symbol SBL. If it is
> already a string, return it unchanged."
> ...
> The command should return the string representation of symbol if
> it exists. When the command fails (symbol does not exist), are commands
> customarily return nil or an error?
This depends entirely on the meaning of your function and its intended
usage. Generally speaking, it’s preferable to return nil to represent
failure unless nil is a valid value in the successful case. Since your
function always returns a string if it’s successful, it would probably
be good to return nil on failure.
Errors are most often employed when the program has encountered some
value or condition under which it’s not possible to proceed normally. In
that case, signalling an error stops execution and returns to the
nearest enclosing error handler which will decide what to do about it.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: pcase with progn
2024-11-27 18:45 pcase with progn Heime via Users list for the GNU Emacs text editor
2024-11-27 19:39 ` Scott Bell
@ 2024-11-28 14:44 ` Stefan Monnier via Users list for the GNU Emacs text editor
1 sibling, 0 replies; 5+ messages in thread
From: Stefan Monnier via Users list for the GNU Emacs text editor @ 2024-11-28 14:44 UTC (permalink / raw)
To: help-gnu-emacs
> Does pcase require progn for multiple commands?
You can find the answer in `C-h f pcase RET`.
Stefan
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2024-11-28 14:44 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-11-27 18:45 pcase with progn Heime via Users list for the GNU Emacs text editor
2024-11-27 19:39 ` Scott Bell
2024-11-27 20:50 ` Heime via Users list for the GNU Emacs text editor
2024-11-27 22:33 ` Scott Bell
2024-11-28 14:44 ` Stefan Monnier via Users list for the GNU Emacs text editor
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).