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

function application #31

Closed
bieganski opened this issue May 30, 2021 · 3 comments
Closed

function application #31

bieganski opened this issue May 30, 2021 · 3 comments

Comments

@bieganski
Copy link

$ f(x) =  x^2
$ f 2
4
$ g(x,y) = x^2y
g 1 2
Expected 2 arguments for function g, but got 1.

Haskell-like function application would be very useful, is it meant to be supported only for one-param functions?

@PaddiM8
Copy link
Owner

PaddiM8 commented May 31, 2021

Well, this kind of thing is currently made to only support one-param functions, to avoid even more ambiguity. the problem is that it needs to be able to figure out if you're multiplying or not. For example if you write sin2x, it should interpret it as sin(2*x), and spaces are not kept from the tokenizing. However, if given enough context, the parser may be able to figure it out, but that may lead to excessive complexity.

@abrudz
Copy link
Contributor

abrudz commented Jun 2, 2021

I disagree that g 1 2 should work. It is fairly common in mathematics to temporarily adopt additional notation, so one can e.g. say:

Let x∗y denote 1-(1-x)+(1-y). Now, 0.5∗0.5 = 0.75 …

When using a 2-param function without parenthesis, the first parameter should be taken from the left of the function name. This will allow writing the above human language as:

>> ∗(x,y) = 1-(1-x)(1-y)
>> 0.5∗0.5
0.75

@PaddiM8
Copy link
Owner

PaddiM8 commented Jan 1, 2022

This would lead to excessive complexity and is probably not worth it.

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

3 participants