Skip to content
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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

nickdrozd
Copy link
Collaborator

No description provided.

@shaleh
Copy link
Collaborator

shaleh commented Dec 12, 2019

I need to scan this line by line, but overall solid. Thanks for taking the effort.

@@ -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) }
Copy link
Member

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.

Copy link
Collaborator

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
}

@nickdrozd
Copy link
Collaborator Author

@harryfei @brotzeit @agraven This change should address your complaint.

@agraven
Copy link
Collaborator

agraven commented Dec 22, 2019

I'd still prefer something akin to the macro shaleh proposed, while the automatic dereferencing is definitely an improvement, !! is still not a very intuitive symbol, I personally have to stop and consciously think about what it means every time I see it.

@shaleh
Copy link
Collaborator

shaleh commented Jan 10, 2020

What do you say Nick? Is bool!() concise enough? Do we stick with is_nil()? I am not sold on the double bang having seen how this reads. But this is a group effort so my vote is not the one that matters. I know that '!!' is somewhat common in Javascript circles. So maybe this for me is generational.

@nickdrozd
Copy link
Collaborator Author

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?

@shaleh
Copy link
Collaborator

shaleh commented Jan 15, 2020

I hear ya @nickdrozd. 1000% agreed.

@db48x
Copy link
Collaborator

db48x commented Jan 16, 2020

Yea, I feel like if should have a trait the way for does. Maybe we should write a proposal. Maybe there already is one? I haven't looked, but it seems like a fairly obvious one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants