oovm / wenyanlanguage Goto Github PK
View Code? Open in Web Editor NEWHome Page: https://wenyan.netlify.com/basic/type.html
License: Mozilla Public License 2.0
Home Page: https://wenyan.netlify.com/basic/type.html
License: Mozilla Public License 2.0
有一书名曰 《九章算数》, 载 「求和」之术, 今名之曰 「加」
from 九章算数 import 求和 as 加
Originally posted by @GalAster in https://github.com/LingDong-/wenyan-lang/issues/100#issuecomment-567509316
Function parameters can have different types. You can specify the them like so
欲行是術。必先得一數。曰「甲」。二言。曰「乙」。曰「丙」。一爻。曰「丁」。
(float a, string b, string c, bool d)
The goal is indeed to have statically typed language, but compile time type checking/inference is yet to be implemented.
Thanks.
Originally posted by @LingDong- in https://github.com/LingDong-/wenyan-lang/issues/280#issuecomment-567987049
WenyanLanguage looks similiar to LingDong-/wenyan-lang, what's the relationship and differences between them?
我这有个算法不知道有没有漏洞:
从左往右读, 每一读一位乘十加上后一位, 但如果是倍数词那得乘上相应的倍数
然后读到 <EOS>
额外检测, 如果是不是十那么乘十.
因为只有 二百五
, 没有 二百五万
, 只能读成 二百五十万
.
这个算法好处是同时支持 一零九九
和 一千零九十九
两种读法.
Originally posted by @GalAster in https://github.com/LingDong-/wenyan-lang/issues/338#issuecomment-568283148
这算是步入正轨了,另外我觉得编译器后端可以直接生成estree,然后再用astring,或者espy 转译成js和python即可
https://github.com/farteryhr/labs/blob/master/cm.g4
but it somehow fails (and i can't figure it out)
try at: http://farter.cn/cmath/ (done long ago)
#155 @UltimatePea proposed that Nested function calling like var e = (f (g a) b (h c d))
or in python e = f(g(a), b, h(c,d))
, can be implemented by introducing temporary variables
施「庚」於「甲」名之曰「其一」。
施「辛」於「丙」於「丁」名之曰「其二」。
施「己」於「其一」於「乙」於「其二」名之曰「戊」。
or using lambda expressions
施「己」
於數。欲得是數,施「庚」於「甲」。
於「乙」
於數。欲得是數,施「辛」於「丙」於「丁」。
Actually by simulating the stack of functions, there is a third solution, which allow a serialized syntax that is more elegant and doesn't involve complex syntax like lambda expression. The compilation should not be to hard with the help of an extra stack.
入「甲」求「庚」入「乙」「丙」「丁」取二求「辛」求「己」得「戊」
We have four keywords in the above expression:
入[x]:push an item x into the stack
求[f]:receives a function f, pops out elements from the stack for evaluation, and push the result back into the stack. By default, all the elements from the stacks are poped out as function arguments.
取[n]求[f]:Only pop the top n items for function evaluation
得[x]:pop the top of the stack and assign it to variable x
The execution procedure is as follows:
operation | Stack | expression |
---|---|---|
入「甲」 | a | a |
求「庚」 | _1 | g(a) |
入「乙」「丙」「丁」 | _1, b, c, d | g(a), b, c, d |
取二求「辛」 | _1, b, _2 | g(a), b, h(c, d) |
求「己」 | _3 | f(g(a), b, h(c, d)) |
得「戊」 | empty | e = f(g(a), b, h(c, d)) |
python | 文言 |
---|---|
e = f(g(a), b, h(c, d)) |
入「甲」求「庚」入「乙」「丙」「丁」取二求「辛」求「己」得「戊」 |
e = d(c(b(a))) |
入「甲」求「乙」「丙」「丁」得「戊」 |
x = f(e, d(c,x), b(a,x)) |
入「戊」「丙」「斯」取二求「丁」入「甲」「斯」取二求「乙」求「己」得「斯」 |
Originally posted by @Lotayou in https://github.com/LingDong-/wenyan-lang/issues/285#issuecomment-568061353
functions in wenyan are now automatically curried, that is, partially applied to return a new function.
吾有一術。名之曰「丁」。欲行是術。必先得三數。曰「寅」曰「卯」曰「辰」乃行是術曰。
乘「寅」以「卯」。加其以「辰」。乃得其。
是謂「丁」之術也。
施「丁」於一於二。名之曰「半丁」。
施「半丁」於三。書之。
compiles to
var 丁 = () => 0;
丁 = function(寅) {
return function(卯) {
return function(辰) {
var _ans1 = 寅 * 卯;
var _ans2 = _ans1 + 辰;
return _ans2
};
};
};
var _ans3 = 丁(1)(2);
var 半丁 = _ans3;
var _ans4 = 半丁(3);
console.log(_ans4);
Again, more FP on its way.
Originally posted by @LingDong- in https://github.com/LingDong-/wenyan-lang/issues/322#issuecomment-568219775
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.