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

Docs: if item not in items #3281

Closed
Soviut opened this issue Dec 10, 2013 · 10 comments
Closed

Docs: if item not in items #3281

Soviut opened this issue Dec 10, 2013 · 10 comments

Comments

@Soviut
Copy link

Soviut commented Dec 10, 2013

I discovered that

if not item in items
    items.push item

Doesn't work. I discovered that the syntax was

if item not in items

But shouldn't my original expression still work? Shouldn't the not still negate the item in items boolean result? I realize my original may not read as nicely, but both make logical sense.

@nfour
Copy link

nfour commented Dec 10, 2013

This is what I intuitively assumed as well. The of syntax is the same.

The value is instead converted to a bool and that is compared, as if you were writing this
if ( not item ) in items

I'd consider if not item of/in items to be preferable syntax when using parenthesis as you would in other languages, though CS tends to favor readable expressions, closer to sentences.

One thing I'll say is that when I was new to CS, I found it quite a headache plowing through code trying to find just what it was that was broken in my code. Turned out it was this, as I wrote the expression as if it were vanilla JS with some (). I've made the same error once or twice since, though I've beaten it out myself by now.

@Soviut
Copy link
Author

Soviut commented Dec 10, 2013

It almost feels like if the want in/not in syntax they should maintain it as is in and isnt in

@nfour
Copy link

nfour commented Dec 10, 2013

isnt in makes sense though it would be too dissimilar from JS. Perhaps the docs just need make this behavior more prominent, explicit, as I can't see the current syntax as being even close to intuitive coming from JS.

A simple CTRL+F on http://coffeescript.org/ yields no not of or not in, though in the changelog I see a mention of not instanceof, which is also relevant. There needs to be a piece in the docs describing these expressions.

@goto-bus-stop
Copy link

I can't see the current syntax as being even close to intuitive coming from JS.

not is merely an alias to !, so
if not item in items

if !item in items

not in is just a bonus, it seems.
Docs would be cool.

@Soviut
Copy link
Author

Soviut commented Dec 10, 2013

Yeah, it just feels like the expected behaviour would be if !(item in items). The reason I even attempted this is because it works fine in Python which inspired a lot of this syntax.

@goto-bus-stop
Copy link

I suppose. But then there would be a difference between ! and not which is also unexpected. And different precedence for not a in b (!(a in b)) and not a is b (!a === b). And specialcasing the alias not but not ! if it is used in front of an in expression sounds kinda unattractive.

@nfour
Copy link

nfour commented Dec 10, 2013

@renekooi sounds about right.

(I'm assuming) Python probably just chose to be consistent with the C-like order of ! ( a === true ). When you think about it, CS does it right when we consider these non enclosed expressions.

So yeah, I just looked up Py syntax and apparently there is also a a not in b not in operator. Carry on.

@Soviut
Copy link
Author

Soviut commented Dec 10, 2013

Yeah, perhaps some documentation explaining this would be helpful. Showing examples of how item not in items and not (item in items) are equivalent.

@Soviut Soviut closed this as completed Dec 10, 2013
@vendethiel
Copy link
Collaborator

Why close ? If documentation needs to be improved, let's keep it open :).

@Soviut Soviut reopened this Dec 10, 2013
@vendethiel vendethiel changed the title "if not item in items" doesn't work Document "if item not in items" Dec 2, 2014
@vendethiel vendethiel added the bug label Dec 2, 2014
@GeoffreyBooth GeoffreyBooth changed the title Document "if item not in items" Docs: if item not in items Apr 30, 2017
@GeoffreyBooth GeoffreyBooth removed the bug label Apr 30, 2017
@GeoffreyBooth GeoffreyBooth mentioned this issue May 2, 2017
13 tasks
GeoffreyBooth added a commit to GeoffreyBooth/coffeescript that referenced this issue May 3, 2017
GeoffreyBooth added a commit that referenced this issue May 6, 2017
* Docs: named functions and function declarations

* No more prototypal `extends`; update docs and example

* More comprehensive documentation of the existential operator; closes #1631

* Better document operators, including `from`

* No fat arrow class methods anymore

* Destructuring shouldn’t say that default values are applied in case of undefined or null

* Spinoff generator and async functions into their own sections; reorder things so that the sections on functions come just before classes, and destructuring goes next to the operators (which discuss assignment)

* Rewrite “CoffeeScript 2” section, making it less practical and more explanatory; move practical info into “Usage”

* Update “Variable Scoping and Lexical Safety” section to remove incorrect reference to Ruby (fixes #2360), add missing details about the safety wrapper, add note about `let`/`const`.

* Updated browser compiler

* Updated docs

* Rewrite Literate CoffeeScript breaking changes

* Split apart the “Breaking Changes” and “Unsupported Features” sections into separate sidebar items and files

* Add example of `not in`, closes #3281

* Fix words in bold that should be in backticks

* Consolidate some breaking changes sections

* Add Node API documentation; closes #3551

* Move the chaining documentation out of the changelog into its own section
@GeoffreyBooth
Copy link
Collaborator

Done in #4536.

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

No branches or pull requests

5 participants