Wenyan: 吾思虑再三,若备一转换之工具,甚美呓。吾之工程,尽为文言呓!

Created on 18 Dec 2019  ·  11Comments  ·  Source: wenyan-lang/wenyan

related-project

Most helpful comment

That would be really nice, but would also need a huge amount of work to implement. Think about all the various nuances and tricky details of other languages, and the fact that other languages (especially JavaScript) are constantly evolving themselves. I imagine it could be quite a pain to keep up. Perhaps one day there would be a large enough community of wenyan developers to support this kind of project. I look forward to that day :)

All 11 comments

That would be really nice, but would also need a huge amount of work to implement. Think about all the various nuances and tricky details of other languages, and the fact that other languages (especially JavaScript) are constantly evolving themselves. I imagine it could be quite a pain to keep up. Perhaps one day there would be a large enough community of wenyan developers to support this kind of project. I look forward to that day :)

LLVM might be helpful. There is emscripten (https://github.com/emscripten-core/emscripten) which can compile C/C++ to js. Given the simiarlirties between Wenyan and js, it would be possible to translate js to Wenyan.

Given the simiarlirties between Wenyan and js, it would be possible to translate js to Wenyan.

This might be impossible, it's hard to convert the JavaScript to LLVM IR, however the reverse is done.

Thus the LLVM IR to wenyan is meaningful a use case that C/C++ into wenyan, but that won't work for converting JS to wenyan.

@yorkie Let me rephrase: we can convert c/c++ to LLVM IR. And we also know that we can convert LLVM IR to js (using emscripten). Since js shares some similarities with Wenyan, it is possible to modify emscripten and generate Wenyan, instread of js.

I should not have used the word translate js to Wenyan

it would be possible to translate js to Wenyan.

You actually said it as it's possible, aha but never mind :)

And yes, we can output "wenyan" from LLVM IR, IMHO I'm a little bit -1 on this idea, the "wenyan"'s good part is to represent a program in Classical Chinese, that means what a programmer now think about the solution to problems in Classical Chinese language model, I'm very inspired on this part :)

Yep, your idea definitely worths checking out.

I, and the person who starts this thread, wish to compile existing programs to Wenyan. For example, we can have OpenSSL in Wenyan. Then people from 1000 years ago can securely communicate with us. I would say this idea to trans-compile, as well as the Wenyan itself, is more for recreational and research purposes rather than actual usage.

How about developing a tool to take a JS/Java source code, and explain it in Wen Yan. That will make programming or learning how to programming fun. Users can also learn JS/Java etc at the same time improve their Wenyan.

How about developing a tool to take a JS/Java source code, and explain it in Wen Yan. That will make programming or learning how to programming fun. Users can also learn JS/Java etc at the same time improve their Wenyan.

Isn't it exactly what this title suggests?

@LingDong- I'm working on one. https://github.com/zxch3n/wenyanizer

You can play it online http://zxch3n.github.io/wenyanizer

There are still some basic js grammars that are not parsed correctly. But I'm optimistic 😄. (it has passed all the example tests, where it should compile back the compiled wenyan examples, and has the same output as them)

When making it, I met some obstacles resulting from the current syntax. I hope the incoming specifications will include the following two things.

  1. typeof keyword. For example, a[b] = 3 is hard to implement since in Wenyan Lang index starts from 1. If b is a number, we should index a by b + 1; however, when b is of string type, we should index a by b. Though it can be polyfilled by using data, it will look bad.
  2. this keyword. I really need this one to make things better. But I guess it's a hard problem due to the weird behavior of JS' this.

PS: I guess we need not keep up with the development of JS specifications. We might only need es5, and use babel to compile all the new things down.

It turns out I can actually use 「this」 directly right now. Though weird, but it works.

Currently, I'm using the following way to make new working.

function A(arg){
    this.arg = arg;
}

const a = new A(123);

=>

吾有一術。名之曰「A」
欲行是術。必先得一物。曰「arg」。
乃行是術曰。
    昔之「this」之「「arg」」者。今「arg」是矣。
是謂「A」之術也。

吾有一術。名之曰「造物」
欲行是術。必先得一物。曰「蓝图」。
乃行是術曰。
    乃得  new 蓝图(...Array.prototype.slice.call(arguments, 1))
是謂「造物」之術也。

施「造物」於「A」。於一百二十三。
名之曰「a」。

@zxch3n . Nice tricks! Glad you figured it out. I think you can also use 今有一數 to generate this.. Hopefully the language will evolve soon enough that we wouldn't need hacks anymore :)

Was this page helpful?
0 / 5 - 0 ratings