help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to stop from loading a script?


From: Joost Kremers
Subject: Re: How to stop from loading a script?
Date: 21 Oct 2015 12:13:35 GMT
User-agent: slrn/1.0.1 (Linux)

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)


reply via email to

[Prev in Thread] Current Thread [Next in Thread]