You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This enables developers to write 文言 in functional programming style, which increases its interoperability with modern frameworks and makes the language much more expressive.
The simplest way to achieve this is to use the original grammar for named functions, with slight modification:
Notice that for better readability, "也" is used to indicate the end of the lambda expression, and "名之曰" is replaced by "吾有一列。名之曰「果」。欲得此列" to receive the result of function invocation.
But the way function arguments are specified is too tedious to be used in such functional style. Therefore, I propose a "specify-on-use" solution:
If function arguments are not specified beforehand, the compiler tracks appearances of "argument placeholders" with the form of “某” + type in the function body. For example, "某数",“某列”,“某言”. Then for each of them, the compiler appends a new argument to the argument list, and replaces the placeholder with the actual reference to that argument.
This grammar can also be used in ordinary functions:
The compiler sees "某列" first, so it knows that the first argument of 「周立」 is an array, and it replaces the "某列" with the reference to that argument. So is "某術". Thus the generated code is identical to the original version.
Of course we should use it cautiously, since not specifying function arguments beforehand would cause a lot of confusion for large functions. On the other hand, it can be a perfect way for reducing boilerplate when used in lambda expressions, which are generally very short:
This enables developers to write 文言 in functional programming style, which increases its interoperability with modern frameworks and makes the language much more expressive.
The simplest way to achieve this is to use the original grammar for named functions, with slight modification:
First, let's define 「周立」。
吾有一術。名之曰「周立」。欲行是術。必先得一列。曰「甲」。一術。曰「转」。乃行是術曰。
吾有一列。名之曰「乙」。
凡「甲」中之「物」。
施「转」於「物」。名之曰「新」。充「乙」以「新」。
云云。
乃得「乙」。
是謂「周立」之術也。
Then use it with lambda expression:
吾有一列。名之曰「甲」。充「甲」以一。以二。以三。
吾有一列。名之曰「果」。欲得此列。施「周立」
於「甲」。
於術。欲行是術。必先得一數。曰「甲」。乃行是術曰。
加「甲」以一。名之曰「乙」。乃得「乙」也。
Notice that for better readability, "也" is used to indicate the end of the lambda expression, and "名之曰" is replaced by "吾有一列。名之曰「果」。欲得此列" to receive the result of function invocation.
But the way function arguments are specified is too tedious to be used in such functional style. Therefore, I propose a "specify-on-use" solution:
If function arguments are not specified beforehand, the compiler tracks appearances of "argument placeholders" with the form of “某” + type in the function body. For example, "某数",“某列”,“某言”. Then for each of them, the compiler appends a new argument to the argument list, and replaces the placeholder with the actual reference to that argument.
This grammar can also be used in ordinary functions:
吾有一術。名之曰「周立」。是術曰。
吾有一列。名之曰「乙」。
凡某列中之「物」。
施某術於「物」。名之曰「新」。充「乙」以「新」。
云云。
乃得「乙」。
是謂「周立」之術也。
The compiler sees "某列" first, so it knows that the first argument of 「周立」 is an array, and it replaces the "某列" with the reference to that argument. So is "某術". Thus the generated code is identical to the original version.
Of course we should use it cautiously, since not specifying function arguments beforehand would cause a lot of confusion for large functions. On the other hand, it can be a perfect way for reducing boilerplate when used in lambda expressions, which are generally very short:
吾有一列。名之曰「甲」。充「甲」以一。以二。以三。
吾有一列。名之曰「果」。欲得此列。施「周立」
於「甲」。
於術。曰加某数以一。名之曰「乙」。乃得「乙」也。
The text was updated successfully, but these errors were encountered: