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

Will some Math functions and constants be added? #55

Closed
enomoto-kudamono opened this issue Dec 18, 2019 · 5 comments
Closed

Will some Math functions and constants be added? #55

enomoto-kudamono opened this issue Dec 18, 2019 · 5 comments
Labels
stdlib Issues related to standard library

Comments

@enomoto-kudamono
Copy link

enomoto-kudamono commented Dec 18, 2019

For example:

  • 圓周率 -> Math.PI
  • 之平方/自乘 -> Math.pow(x, 2)
  • 之立方 -> Math.pow(x, 3)
  • 之平方根/開方除之 -> Math.sqrt(x)
  • 「甲」度之正弦值 -> Math.sin(x * Math.PI / 180)

Code example:

吾有一術。名之曰「勾股定理」。欲行是術。必先得二數。曰「勾」。曰「股」。乃行是術曰。
  批曰「「勾股各自乘,並之,為弦實,開方除之,即弦。」」
  「勾」自乘。名之曰「勾實」。
  「股」自乘。名之曰「股實」。
  加「勾實」以「股實」。開方除之。名之曰「弦」。
  乃得「弦」。
是謂「勾股定理」之術也。

施「勾股定理」於三。於四。書之。
@LingDong-
Copy link
Member

LingDong- commented Dec 18, 2019

Thanks for the proposal and code example! The answer is yes! they will be, but not as part of the syntax, and instead as function calls from a standard library.

So probably something like 施「平方根」於二. I agree it looks not as nice as 二之平方根. The reason for that is there could be a ton of things people would like to do with a programming language: e.g. math, bit manipulation, gui, etc., and it would be quite a mess if they're all part of the syntax (and quite a burden for potential implementers of the language).

Please see also this issue for details: https://github.com/LingDong-/wenyan-lang/issues/2

Thanks!

@tiansh
Copy link

tiansh commented Dec 18, 2019

二之平方根 reads like 2..sqrt() to me. Since sqrt is not implemented on Number.prototype, it would be better to be 施「數術之平方根」於二.

@xubaiw
Copy link

xubaiw commented Dec 19, 2019

二之平方根 reads like 2..sqrt() to me. Since sqrt is not implemented on Number.prototype, it would be better to be 施「數術之平方根」於二.

Why should this language be implemented on JavaScript?👀 It can has its own standard library.

@Ai-Zixun
Copy link
Contributor

Following up with @AshyAzure 's comment. As the author implementing the import and object functionality of the language. We can use wenyan-lang itself to built its own standard library. Should we be creating something like/library/math.wy and develop the libraries in the function syntax for now. Then we can migrated those into objects that can be imported once the object functionality is implemented.

Maybe we can import each library as a stand along object following the syntax proposed in https://github.com/LingDong-/wenyan-lang/issues/20

@LingDong- LingDong- added the stdlib Issues related to standard library label Dec 24, 2019
@antfu
Copy link
Member

antfu commented Dec 30, 2019

Standard lib is now supported. https://github.com/LingDong-/wenyan-lang/blob/master/lib/%E7%AE%97%E7%B6%93.wy

Closing now. Feel free to reopen it if you got any questions.

@antfu antfu closed this as completed Dec 30, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stdlib Issues related to standard library
Projects
None yet
Development

No branches or pull requests

6 participants