Comments (8)
The first documentation problem involving try... else...
was noted in #1734, but it's great that a new user has noticed the same issue. That new users have noticed the same issue makes it even more important to improve that aspect of the documentation.
from elvish.
In that case, I'll raise a PR to fix the try... else...
example in the docs.
Perhaps it would have been better for me to create two separate issues, as I feel the ?(...)
docs example and explanation are fundamentally at odds with each other.
The explanation
Note: Exception captures do not affect the output of the code chunk. You can combine output capture and exception capture:
doesn't align with the code example
var output = (var error = ?(commands-that-may-fail))
Would it be better for me to close this issue, create a PR to address the existing issue #1734, then create a separate issue for discussion of the exception capture docs?
from elvish.
Here is a PR to address #1734
from elvish.
As an observation, the syntax for try/else/finally
is a bit confusing as a new user.
The syntax implies the else
happens instead of the try
Also, is there a need for such a construct?
For example, instead of
try {
cat log-file > /tmp/log-snapshot
} else {
aws s3api put-object --bucket logs --key logs/latest --body /tmp/log-snapshot
} finally {
rm -f /tmp/log-snapshot
}
would it not be sufficient to simply do
try {
cat log-file > /tmp/log-snapshot
aws s3api put-object --bucket logs --key logs/latest --body /tmp/log-snapshot
} finally {
rm -f /tmp/log-snapshot
}
If there is a valid use case for try/else/finally
I'd be happy to add it to the above PR
If try/else/finally
doesn't make sense, perhaps it would be better to make else
conditional on the presence of catch
?
from elvish.
As far as I can tell, an else
block without both a catch
block and a finally
block has no purpose. If there is no catch
, you can merge the try
and else
blocks, and if there is no finally
, you just put the content of the else
after the try
statement. (And if there is neither a catch
nor a finally
block, the try
statement is a syntax error anyhow, so the point is moot. But that raises the question whether an else
block without both catch
and finally
should be a syntax error too.)
from elvish.
I forgot to address this one:
The syntax implies the
else
happens instead of thetry
As in if/else
, you mean? The intent is that the else
happens instead of the catch
when there is no error, but if there is no catch
block, it does indeed get a bit confusing. That's another argument for actually restricting the syntax to avoid this problem.
from elvish.
Thanks for clarifying
@xiaq said the same thing
An else
doesn't make sense in the absence of a catch
from elvish.
As far as I can tell, an
else
block without both acatch
block and afinally
block has no purpose. If there is nocatch
, you can merge thetry
andelse
blocks, and if there is nofinally
, you just put the content of theelse
after thetry
statement. (And if there is neither acatch
nor afinally
block, thetry
statement is a syntax error anyhow, so the point is moot. But that raises the question whether anelse
block without bothcatch
andfinally
should be a syntax error too.)
In version 0.21.0
an else
without either a catch
or finally
is an error, which is what prompted the issue. =)
Thanks for the clarification though. I'm super excited about the future of Elvish
from elvish.
Related Issues (20)
- Unique symbols HOT 1
- Disable flow control by default HOT 1
- vscode-neovim doesn't work with Elvish as default shell HOT 15
- Race condition when starting multiple instances simultaneously HOT 2
- RSS support for the blog
- Support semantic prompts (OSC 133) HOT 1
- Directory Elvish is launched from doesn't seem to be added to location history HOT 10
- Docs for embedding Elvish? HOT 6
- RISC-V binaries HOT 5
- "Command not found" error when running a batch script with space in path with an argument with space HOT 16
- API to change the in-command colours? HOT 3
- Cursor and prompt control in function to avoid prompt flick HOT 10
- document and change behavior of `doc:find` with no arguments
- Indexing into a list of maps HOT 2
- listbox_window: integer divide by zero HOT 6
- Add `&key` option to `compact`.
- Are there any good examples for custom completion script? HOT 2
- Add helpful message for arity mismatch on function call
- Minibuffer namespace
- COMPLETING argument menu shown even when only one completion on paths that start ~/ HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from elvish.