* How to stop from loading a script?
@ 2015-10-21 11:35 Shiyao Ma
2015-10-21 12:13 ` Joost Kremers
0 siblings, 1 reply; 3+ messages in thread
From: Shiyao Ma @ 2015-10-21 11:35 UTC (permalink / raw)
To: help-gnu-emacs
Hi,
Say the caller will *always* load a script.
But inside the script, I'd like to *directly* return to the caller if some conditions are met.
A workaround is to wrap all the stuff in side a when/unless clause.
e.g.,
(unless (COND)
do-my-stuff)
However, the do-my-stuff is too lengthy and I am in search of the following form:
(when (COND)
EARLY_RETURN_TO_THE_LOADER)
(do-my-stuff).
So my question is, what should I fill in the EARLY_RETURN_TO_THE_LOADER slot?
Regards.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: How to stop from loading a script?
2015-10-21 11:35 How to stop from loading a script? Shiyao Ma
@ 2015-10-21 12:13 ` Joost Kremers
2015-10-21 13:11 ` Pascal J. Bourguignon
0 siblings, 1 reply; 3+ messages in thread
From: Joost Kremers @ 2015-10-21 12:13 UTC (permalink / raw)
To: help-gnu-emacs
Shiyao Ma wrote:
> Hi,
>
> Say the caller will *always* load a script.
>
> But inside the script, I'd like to *directly* return to the caller if some conditions are met.
>
> A workaround is to wrap all the stuff in side a when/unless clause.
>
> e.g.,
>
>
> (unless (COND)
>
> do-my-stuff)
>
>
> However, the do-my-stuff is too lengthy and I am in search of the following form:
Why is it too lengthy?
> (when (COND)
>
> EARLY_RETURN_TO_THE_LOADER)
>
> (do-my-stuff).
>
> So my question is, what should I fill in the EARLY_RETURN_TO_THE_LOADER slot?
There is nothing that really fits the bill. You could exit the function
with `error`, but that won't pass control back to the calling function
unless the call was wrapped in a `condition-case` or `ignore-errors`.
Alternatively, you could use `catch` and `throw`, but that also requires
that the call to your function is wrapped in a special form. See the
Elisp manual, section on nonlocal exits for both options.
But in either case, you're making the code more complex for unnecessary
reasons. Using `unless` the way you describe is not a workaround IMHO
but the best way to do it. The fact that the body of `unless` is long is
not an issue, the only "disadvantage" is that there are two additional
spaces for indentation.
--
Joost Kremers joostkremers@fastmail.fm
Selbst in die Unterwelt dringt durch Spalten Licht
EN:SiS(9)
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: How to stop from loading a script?
2015-10-21 12:13 ` Joost Kremers
@ 2015-10-21 13:11 ` Pascal J. Bourguignon
0 siblings, 0 replies; 3+ messages in thread
From: Pascal J. Bourguignon @ 2015-10-21 13:11 UTC (permalink / raw)
To: help-gnu-emacs
Joost Kremers <joost.m.kremers@gmail.com> writes:
> Shiyao Ma wrote:
>> Hi,
>>
>> Say the caller will *always* load a script.
>>
>> But inside the script, I'd like to *directly* return to the caller if some conditions are met.
>>
>> A workaround is to wrap all the stuff in side a when/unless clause.
>>
>> e.g.,
>>
>>
>> (unless (COND)
>>
>> do-my-stuff)
>>
>>
>> However, the do-my-stuff is too lengthy and I am in search of the following form:
>
> Why is it too lengthy?
>
>> (when (COND)
>>
>> EARLY_RETURN_TO_THE_LOADER)
>>
>> (do-my-stuff).
>>
>> So my question is, what should I fill in the EARLY_RETURN_TO_THE_LOADER slot?
>
> There is nothing that really fits the bill. You could exit the function
> with `error`, but that won't pass control back to the calling function
> unless the call was wrapped in a `condition-case` or `ignore-errors`.
> Alternatively, you could use `catch` and `throw`, but that also requires
> that the call to your function is wrapped in a special form. See the
> Elisp manual, section on nonlocal exits for both options.
>
> But in either case, you're making the code more complex for unnecessary
> reasons. Using `unless` the way you describe is not a workaround IMHO
> but the best way to do it. The fact that the body of `unless` is long is
> not an issue, the only "disadvantage" is that there are two additional
> spaces for indentation.
I wonder if in emacs lisp there'd also be consequences for some forms
not to be top-level forms. In the case of Common Lisp this certainly
could be a problem.
For example, in CL:
(unless (find-package "SOME-PACKAGE")
(ql:quickload :some-system)
(some-package:some-function))
won't work, because the form will be read before the package named
SOME-PACKAGE (assumedly loaded from the system named "some-system" by
quickload) is defined.
The semantics of EVAL-WHEN are also changed (and therefore any macro
that expand to an EVAL-WHEN form.
In either case, if indentation or toplevelness is a problem, you can put
the optional part in another file that can be compiled and loaded
separately:
-----------(file1.el)--------------
(unless (condition)
(load "file1optional"))
-----------------------------------
--
__Pascal Bourguignon__ http://www.informatimago.com/
“The factory of the future will have only two employees, a man and a
dog. The man will be there to feed the dog. The dog will be there to
keep the man from touching the equipment.” -- Carl Bass CEO Autodesk
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2015-10-21 13:11 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-10-21 11:35 How to stop from loading a script? Shiyao Ma
2015-10-21 12:13 ` Joost Kremers
2015-10-21 13:11 ` Pascal J. Bourguignon
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).