-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
WIP: Document noteworthy unusual Julia features. #11998
Changes from all commits
e4284da
926bd77
86e6c5c
768dcf3
98440f5
dde34b9
86b53ca
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,39 @@ | |
Noteworthy Differences from other Languages | ||
******************************************* | ||
|
||
Noteworthy and unusual Julia features | ||
--------------------------------- | ||
|
||
* Julia allows identifiers with complex Unicode, for example you could represent the value of a chi-squared test with ``χ²``, | ||
similarly ``χ⁽³⁾`` is used in electromagnetism for the third-order nonlinear susceptibility, another example is ``∇²`` | ||
which is the name of the Laplacian operator. All of these Unicode symbols are valid Julia identifiers. | ||
|
||
It can also be useful for caching powers of ``x`` to ensure that intermediate products are reused optimally in time-critical code. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I get why this example was put here, but this is a microoptimization that is going to freak people out if its the first thing they see in a section of the manual. I'm not sure an example is needed. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. One would hope also that the compiler would be smart enough to lift things out of loops, if you have |
||
A classic example is in computing the [Lennard-Jones 12-6 potential energy](https://en.wikipedia.org/wiki/Lennard-Jones_potential) in computational chemistry and physics, in order to compute: | ||
|
||
.. math:: | ||
|
||
A/x^12 - B/x^6 | ||
|
||
one can write: | ||
|
||
.. doctest:: | ||
|
||
"Lennard-Jones potential" | ||
function lj(x, A, B) | ||
x⁻² = x^-2 | ||
x⁻⁶ = (x⁻²)^3 | ||
x⁻¹² = (x⁻⁶)^2 | ||
A*x⁻¹² - B*x⁻⁶ | ||
end | ||
|
||
.. note:: | ||
|
||
Be wary about referencing a global variable while thinking it was an operator applied to a local variable and updating a | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have no idea what this sentence is trying to say. Could you word it differently? Is this related to unicode? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ScottPJones would you mind showing a short example of this pitfall? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This "pitfall" is a contrived strawman crafted to make a specific point. |
||
variable without remembering to update the cached value. | ||
|
||
* The ``/`` operator gives floating-point results for integer arguments, use ``div`` for truncating to an integer. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should probably just be in the C differences section, people coming from Python, MATLAB, R, etc. wouldn't find this a noteworthy or unusual Julia feature. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it is a lot more languages than just C/C++, also Java, Lua, Python, etc. >>> x³ = 5
File "<stdin>", line 1
x³ = 5
^
SyntaxError: invalid character in identifier
> There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ScottPJones, its talking about division, not unicode, what are you talking about? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Never mind, I thought you were talking about the part above. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok I'll change it to the C part. |
||
|
||
Noteworthy differences from MATLAB | ||
---------------------------------- | ||
|
||
|
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.
This sentence is way too long. Also, I don't think using Unicode in identifiers in general is what would cause problems, I think its more just this one particular case.
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.
It is a whole set of characters that at least as I understand the Unicode standard UAX 31, shouldn't be considered part of identifiers. (I have no problem at all with Unicode in identifiers, I just brought up a point where it seemed inconsistent with other uses of Unicode characters in Julia)
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.
Great. Instead of replying to me, write that in documentation form, which is not what is here right now.