wenyan-lang / wenyan

文言文編程語言 A programming language for the ancient Chinese.
https://wy-lang.org/
MIT License
19.54k stars 1.1k forks source link

Anonymous function and function args #315

Open brynne8 opened 4 years ago

brynne8 commented 4 years ago

Will anonymous function be supported by wenyan-lang? Currently it seems we always need to have a name, and start functions with 吾有 int_num 術 reference_single_statement 欲行是術, which is not very flexible. For example. we want to express object like

var obj = {
  a: function () { return 42; }
}

But according to the syntax, object properties are made up of either value or identifier. So we may have to define it before we assign it to a property.


As function_arg is defined as

必先得 num type [assign identifier] 是術曰|乃行是術曰 

we might be unable to define a function with different types of args, for example

public void function test(String arg1, Integer arg2, String arg3) {
  ...
}

Moreover, we might need to use variable number of args in some cases, and most languages support that, for example,

print(a, b, c, d)
LingDong- commented 4 years ago

Hi @AlexanderMisel , function with different types of args are supported, see:

https://github.com/LingDong-/wenyan-lang/issues/280#issuecomment-567987049

Sorry ./documentation/syntax.txt is a work in progress and might be inaccurate. @jiangzoi , Please fix :)

Anonymous functions are not here yet, but I agree it will be very handy and will be probably implemented along with other functional programming goodies.

Thank you for bringing this up!