-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
[ANNOUNCEMENT] Nested Function Calls and More! #322
Comments
Automatically curried functionsfunctions in wenyan are now automatically curried, that is, partially applied to return a new function.
compiles to
Again, more FP on its way. |
That is awesome. I can see how this project is rapidly growing from an undergraduate class project to a powerful, self-contained programming language. Maybe we can create some influential projects using wenyan-lang. Keep up the good work :-) |
Only support 3-address code should be fine to me... Anyway, how to describe |
@tiansh The syntax would be:
or
:) |
Stack-based way to nest function calls
Due to popular demand, nested function calls is now a feature. Here is a taste:
More complex example for the courageous:
How it works
The original syntax of wenyan already employs a stack-like behavior. You can use
其
to refer to the previous unnamed variable, you can use書之
to print all the unnamed variables, use名之曰
to name them etc. Therefore, it is natural to use the same system for function calls.Now I'll refer to the "list of unnamed variables" as the "stack" for convenience.
夫
keyword pushes a variable in into the stack.取n
marks the lastn
items on the stack as "usable".以施f
takes all the items marked "usable" and apply functionf
that takes those items as arguments, and push the result onto the stack. Finally you can use名之曰
to take stuff from back the stack and give them names for later use.Recap on other features that already existed before this update:
噫
Clears the stack, discarding everything.其
Refers to the most recent item on the stack. It also clears the stack. The reason for this is not techincal, but is purely done from Classical Chinese readability standpoint: if you use multiple其
in a row, it can be very confusing:加其以其。乘其以其。昔之其者。今其是矣。
. Hence.More examples, showing that you can also push items of an Array, math results, and so on to stack:
You can find more examples in
./examples/nested_fun.wy
A thank you to @Lotayou and everyone for the discussion in #285 and #301. More functional programming goodies are on their way!
Please let me know if you have any suggestions or found any bugs! Thanks.
The text was updated successfully, but these errors were encountered: