bug-bash
[Top][All Lists]
Advanced

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

Re: feature request: new builtin `defer`, scope delayed eval


From: Dale R. Worley
Subject: Re: feature request: new builtin `defer`, scope delayed eval
Date: Fri, 07 Oct 2022 21:48:58 -0400

The Go programming language has a "defer" statement which is used
considerably for exactly this purpose.  So we know that it's useful in
practice.  The question remains what is a good way to introduce it into
Bash.

As others have noted, there is already a "trap" with similar
functionality.  I'm not familiar with it, but it seems that it does not
have "signal" choices that cover the the situation(s) we want "defer" to
be triggered by.  However, that seems to be a straightforward extension.

More important is "safely appending to a trap can be filled with holes".
Why don't we allow a trap to be a sequence of strings, and define a new
option to "trap" that prepends the argument string to the sequence?  (Go
specifies that "defer" actions are executed in reverse order from the
execution of the "defer" statements that establishd them.)

This approach seems to have the functionality we want while being a
small extension of an existing, similar mechanism.

Dale



reply via email to

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