* Does pcase need progn in if condition
@ 2021-05-21 9:25 pietru
2021-05-21 17:09 ` Christopher Dimech
2021-05-21 21:26 ` Emanuel Berg via Users list for the GNU Emacs text editor
0 siblings, 2 replies; 8+ messages in thread
From: pietru @ 2021-05-21 9:25 UTC (permalink / raw)
To: Help Gnu Emacs
Does "pcase" need progn in an "if" condition
--------
(if condition
(pcase n
(0 (save-excursion (insert s)))
((or 1 2 3 4 5)
(delete-region (point) b)
(save-excursion (insert s)))
(_ (delete-region (point) b))) ))
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Does pcase need progn in if condition
2021-05-21 9:25 Does pcase need progn in if condition pietru
@ 2021-05-21 17:09 ` Christopher Dimech
2021-05-22 4:39 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-05-21 21:26 ` Emanuel Berg via Users list for the GNU Emacs text editor
1 sibling, 1 reply; 8+ messages in thread
From: Christopher Dimech @ 2021-05-21 17:09 UTC (permalink / raw)
To: pietru; +Cc: Help Gnu Emacs
I do not think it needs a progn as it consists of a single expression.
> Sent: Friday, May 21, 2021 at 9:25 PM
> From: pietru@caramail.com
> To: "Help Gnu Emacs" <help-gnu-emacs@gnu.org>
> Subject: Does pcase need progn in if condition
>
>
> Does "pcase" need progn in an "if" condition
>
> --------
>
> (if condition
>
> (pcase n
>
> (0 (save-excursion (insert s)))
>
> ((or 1 2 3 4 5)
> (delete-region (point) b)
> (save-excursion (insert s)))
>
> (_ (delete-region (point) b))) ))
>
>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Does pcase need progn in if condition
2021-05-21 9:25 Does pcase need progn in if condition pietru
2021-05-21 17:09 ` Christopher Dimech
@ 2021-05-21 21:26 ` Emanuel Berg via Users list for the GNU Emacs text editor
1 sibling, 0 replies; 8+ messages in thread
From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2021-05-21 21:26 UTC (permalink / raw)
To: help-gnu-emacs
pietru wrote:
> Does "pcase" need progn in an "if" condition
>
> (if condition
>
> (pcase n
>
> (0 (save-excursion (insert s)))
>
> ((or 1 2 3 4 5)
> (delete-region (point) b)
> (save-excursion (insert s)))
>
> (_ (delete-region (point) b))) ))
>
`if' should her better be `when'!
How `pcase' behaves within a when tho? Maybe depends on things
even INSIDE the when?
--
underground experts united
https://dataswamp.org/~incal
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Does pcase need progn in if condition
2021-05-21 17:09 ` Christopher Dimech
@ 2021-05-22 4:39 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-05-22 9:09 ` Jean Louis
0 siblings, 1 reply; 8+ messages in thread
From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2021-05-22 4:39 UTC (permalink / raw)
To: help-gnu-emacs
Christopher Dimech wrote:
> I do not think it needs a progn as it consists of
> a single expression.
(while some-thing do)
(unless not-some-thing do)
(if something
do-this <- `progn' here if >1
else-do-that-1
else-do-furthermore-this-2
...
alright-done-n)
sometimes one can put useful things there, e.g. `let', and
avoid using progn for this reason
Yeah, progn is imbecile, almost. only, for some reason, prog1
is cool, and prog2 is weird.
(if t 1 2 3 4) ; 1
--
underground experts united
https://dataswamp.org/~incal
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Does pcase need progn in if condition
2021-05-22 4:39 ` Emanuel Berg via Users list for the GNU Emacs text editor
@ 2021-05-22 9:09 ` Jean Louis
2021-05-22 9:32 ` Emanuel Berg via Users list for the GNU Emacs text editor
0 siblings, 1 reply; 8+ messages in thread
From: Jean Louis @ 2021-05-22 9:09 UTC (permalink / raw)
To: help-gnu-emacs
* Emanuel Berg via Users list for the GNU Emacs text editor <help-gnu-emacs@gnu.org> [2021-05-22 07:40]:
> sometimes one can put useful things there, e.g. `let', and
> avoid using progn for this reason
>
> Yeah, progn is imbecile, almost. only, for some reason, prog1
> is cool, and prog2 is weird.
>
> (if t 1 2 3 4) ; 1
`progn` returns the the last value:
(progn
'(do-something)
'(do-more)
emacs-build-number) ⇒ 1
and is better looking then `let` when empty:
(let ()
(message "hello")
'(do-more)
emacs-build-number) ⇒ 1
`prog1' is very handy as it will not return the last value but the value from 1st form:
Example is when you wish to return a value and after that informa a user like here below:
(cond ((= a 1) (do-something))
(t (prog1 nil (message "Query shall be longer..."))))
After returning `report' it will message user about it. Maybe you
wish to return the status of a function and continue informing
user?
(defun function ()
"Return REPORT"
(prog1
report
(message report)))
And `prog2' is more than this, it will return the value from 2nd
form, not third or first.
(prog2
(do-this-but-not-keep-return-value)
(do-this-and-keep-and-return-value)
(do-more-something-but-return-value-is-from-above))
--
Jean
Take action in Free Software Foundation campaigns:
https://www.fsf.org/campaigns
Sign an open letter in support of Richard M. Stallman
https://stallmansupport.org/
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Does pcase need progn in if condition
2021-05-22 9:09 ` Jean Louis
@ 2021-05-22 9:32 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-05-22 11:08 ` Jean Louis
0 siblings, 1 reply; 8+ messages in thread
From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2021-05-22 9:32 UTC (permalink / raw)
To: help-gnu-emacs
Jean Louis wrote:
> `progn` returns the the last value:
The nth value...
> [progn] is better looking then `let` when empty:
>
> (let ()
> (message "hello")
> '(do-more)
> emacs-build-number) ⇒ 1
Your example :)
> `prog1' is very handy as it will not return the last value
> but the value from 1st form:
:)
> Example is when you wish to return a value and after that
> informa a user like here below:
>
> (cond ((= a 1) (do-something))
> (t (prog1 nil (message "Query shall be longer..."))))
...
> After returning `report' it will message user about it.
> Maybe you wish to return the status of a function and
> continue informing user?
>
> (defun function ()
> "Return REPORT"
> (prog1
> report
> (message report)))
But you can do that with `let' as well and besides ... message
already does that? :O
(message "Oh, baby!") ; "Oh, baby!"
?
> And `prog2' is more than this, it will return the value from
> 2nd form, not third or first.
Some Elisp for you:
cl-prog
cl-prog*
cl-progv
cl-tagbody
--
underground experts united
https://dataswamp.org/~incal
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Does pcase need progn in if condition
2021-05-22 9:32 ` Emanuel Berg via Users list for the GNU Emacs text editor
@ 2021-05-22 11:08 ` Jean Louis
2021-05-22 11:37 ` Emanuel Berg via Users list for the GNU Emacs text editor
0 siblings, 1 reply; 8+ messages in thread
From: Jean Louis @ 2021-05-22 11:08 UTC (permalink / raw)
To: help-gnu-emacs
* Emanuel Berg via Users list for the GNU Emacs text editor <help-gnu-emacs@gnu.org> [2021-05-22 12:33]:
> Some Elisp for you:
>
> cl-prog
> cl-prog*
> cl-progv
> cl-tagbody
Those are Common Lisp emulation functions. I consider those good for
people used to Common Lisp. I used to be used to it, not any
more. cl-macs.el is macro package. So I find it good when it is
necessary to port some Common Lisp to Emacs Lisp. When writing new
code they never necessary.
--
Jean
Take action in Free Software Foundation campaigns:
https://www.fsf.org/campaigns
Sign an open letter in support of Richard M. Stallman
https://stallmansupport.org/
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Does pcase need progn in if condition
2021-05-22 11:08 ` Jean Louis
@ 2021-05-22 11:37 ` Emanuel Berg via Users list for the GNU Emacs text editor
0 siblings, 0 replies; 8+ messages in thread
From: Emanuel Berg via Users list for the GNU Emacs text editor @ 2021-05-22 11:37 UTC (permalink / raw)
To: help-gnu-emacs
Jean Louis wrote:
>> Some Elisp for you:
>>
>> cl-prog
>> cl-prog*
>> cl-progv
>> cl-tagbody
>
> Those are Common Lisp emulation functions. I consider those
> good for people used to Common Lisp. I used to be used to
> it, not any more. cl-macs.el is macro package. So I find it
> good when it is necessary to port some Common Lisp to Emacs
> Lisp. When writing new code they never necessary.
Easy for you to say who write Lisp like it is Pascal...
--
underground experts united
https://dataswamp.org/~incal
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2021-05-22 11:37 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-05-21 9:25 Does pcase need progn in if condition pietru
2021-05-21 17:09 ` Christopher Dimech
2021-05-22 4:39 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-05-22 9:09 ` Jean Louis
2021-05-22 9:32 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-05-22 11:08 ` Jean Louis
2021-05-22 11:37 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-05-21 21:26 ` Emanuel Berg 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).