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

Add Math. to known math function calls #36

Closed
tlienart opened this issue Mar 31, 2020 · 3 comments
Closed

Add Math. to known math function calls #36

tlienart opened this issue Mar 31, 2020 · 3 comments
Labels
enhancement New feature or request

Comments

@tlienart
Copy link

tlienart commented Mar 31, 2020

julia> @js (a,b) -> a*sin(b)
JSString("(function (a,b){return (a*sin(b))})")

it could be nice to map the standard mathematical functions like sin, cos, tan, sqrt, ... to their JS counterpart like Math.sin, Math.cos, Math.tan, Math.sqrt; the list of js math functions seems to suggest this is fairly straightforward (names are mostly identical).

Another nice step would be to interpolate symbols like π or .

PS: I'm happy to try to open a PR but I'd need some guidance as to what's the likely good way to go about this

@twavv
Copy link
Member

twavv commented Mar 31, 2020

I'm opposed to this change, though I'm willing to consider it.

(IMO) I think it should be very clear that the code you are writing is not Julia - it is JS, and I'm opposed to anything that lulls the user into thinking that they're writing Julia. JS is very different from Julia and sometimes has very different semantics.

If someone wants to simulate this themself, they can just do

const setup_function @js function()
  for s in ["sin", "cos", "tan", "sqrt"]
    # .bind might not be necessary for math functions, but better safe than sorry
    window[s] = Math[s].bind(Math)
  end
end

@twavv twavv added the enhancement New feature or request label Mar 31, 2020
@tlienart
Copy link
Author

fair enough, I might do this in a secondary package, thanks for the tip! feel free to close this issue

@twavv
Copy link
Member

twavv commented Mar 31, 2020

In the v1 of JSExpr (which is unreleased because I've yet to go update WebIO to be compatible), there's functionality that makes it really easy to extend existing JSExpr functionality (the only downside is that it's global, so might adversely impact unrelated modules if they happen to use identifiers named sin, cos, etc.)

@twavv twavv closed this as completed Apr 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants