-
Notifications
You must be signed in to change notification settings - Fork 309
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Impl Not for LispObject; cut is_nil and is_not_nil #1555
base: master
Are you sure you want to change the base?
Conversation
I need to scan this line by line, but overall solid. Thanks for taking the effort. |
rust_src/src/alloc.rs
Outdated
@@ -57,7 +57,7 @@ pub fn bool_vector(args: &mut [LispObject]) -> LispObject { | |||
let vector = unsafe { make_uninit_bool_vector(args.len() as EmacsInt) }; | |||
|
|||
for (i, arg) in args.iter().enumerate() { | |||
unsafe { bool_vector_set(vector, i as EmacsInt, arg.is_not_nil()) } | |||
unsafe { bool_vector_set(vector, i as EmacsInt, !!*arg) } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMHO, !!*arg
is so confusing and unreadable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
diff --git a/rust_src/src/alloc.rs b/rust_src/src/alloc.rs
index 9ce09f8aad..ff099d9ffa 100644
--- a/rust_src/src/alloc.rs
+++ b/rust_src/src/alloc.rs
@@ -57,7 +57,7 @@ pub fn bool_vector(args: &mut [LispObject]) -> LispObject {
let vector = unsafe { make_uninit_bool_vector(args.len() as EmacsInt) };
for (i, arg) in args.iter().enumerate() {
- unsafe { bool_vector_set(vector, i as EmacsInt, !!*arg) }
+ unsafe { bool_vector_set(vector, i as EmacsInt, bool!(*arg)) }
}
vector
diff --git a/rust_src/src/eval_macros.rs b/rust_src/src/eval_macros.rs
index 8e09736d9d..f24d507dab 100644
--- a/rust_src/src/eval_macros.rs
+++ b/rust_src/src/eval_macros.rs
@@ -7,6 +7,10 @@
* the unsafe is not used.
*/
+macro_rules! bool {
+ ($symbol:expr) => { !!$symbol }
+}
+
/// Macro to generate an error with a list from any number of arguments.
/// Replaces xsignal0, etc. in the C layer.
///
That is one alternative. Then we have code like:
if bool!(some_lisp_val) {
// do something
}
I'd still prefer something akin to the macro shaleh proposed, while the automatic dereferencing is definitely an improvement, |
What do you say Nick? Is |
I don't know, it's hard to get enthusiastic about any of these options. I just wish we could automatically coerce things to booleans in a boolean context...is that so much to ask? Why is it that coercion is fine with negation, but not otherwise? |
I hear ya @nickdrozd. 1000% agreed. |
Yea, I feel like |
No description provided.