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

Suggestion: Warn about implicit multiplication at the end of a line #49

Open
Masterxilo opened this issue Jun 28, 2016 · 6 comments
Open
Assignees

Comments

@Masterxilo
Copy link

I run into this quite often:

"poseWorldToView" -> poseWorldToView
"intrinsicsRgb" -> intrinsicsRgb,

The first line is missing a comma. But the code is parsed and executed correctly and gives undesired results.

@szhorvat
Copy link
Contributor

szhorvat commented Jun 28, 2016

This is available and you can turn it on under Inspections in the preferences. I thought it was on by default (or at least I don't remember turning it on and it's working).

@halirutan
Copy link
Owner

halirutan commented Jun 28, 2016

Can you give a complete example? Commas in Mathematica can only appear in a list, in function arguments or in things like Part ([[..]]) for instance. When I use a list in Idea with this content, I get the following annotation:

screen shot 2016-06-28 at 15 25 52

This shows a slightly yellow underline where the comma is missing and a red underline where the comma is at the end. Therefore, it is telling something (1) might be wrong and something (2) is definitely wrong. You might ask, why the missing comma is only "probably wrong". It is because Mathematica considers whitespace as multiplication in certain circumstances. This here

{
  a,
  b
  c
 }

is a list of the elements a and b*c. This is the reason why the missing comma is only an annotation and not an error. It is correct syntax after all.

@Masterxilo
Copy link
Author

I changed the missing comma inspection to generate an error instead of just an annotation because I never make cross-line multiplications without * intentionally, thanks for pointing out where to find the Inspection options.

Anyways, it does not seem to work within Association and [[ ]], but it does work within function arguments and {}:
image

@szhorvat
Copy link
Contributor

szhorvat commented Jun 28, 2016

For some amusement:

Actually the following is correct syntax:

{a,
}

It parses to {a, Null}. However, the Mathematica parser built into the kernel generates a warning (in the form of a message) when parsing this. The parser built into the front end does not warn at all ...

The message happens to be of the Syntax:: type which causes the front end to freak out and colour the cell bracket red, as if there were a syntax error. In fact this is only a syntax warning, not an error. But there's no way to tell if a message is an error or warning in Mathematica.

It can be triggered from a notebook if we write {a,} in a package and load it. Or if we use ToExpression["{a,}"]. But not if we simply evaluate {a,}.

By this reasoning the missing command and the extra comma are similar: neither is a real syntax error (though the latter may trigger a more scary looking warning).

Note: Personally I am happy with the current setup of red/yellow underlines.

@halirutan
Copy link
Owner

@Masterxilo You are right, the annotator currently only dives into lists and function calls. I'll fix this.

@szhorvat I gave this a long thought whether or not I allow the parser to say Function[,#+3,{Listable}] is correct syntax (one of the things Leonid loves to confuse newbies :-).
I decided against it because if someone really needs a Null, he just has to type it for the greater good of all the hundred developers that would do this accidentally.

@halirutan halirutan self-assigned this Jun 28, 2016
@szhorvat
Copy link
Contributor

szhorvat commented Jun 28, 2016

The SciDraw package actually has its own warning, along the lines of: "I found a Null, stray comma?".

I think they should either have made it a fatal parsing error, or otherwise the parser should just ignore trailing commas (like in C and Python).

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

No branches or pull requests

3 participants