wenyan-lang/wenyan

How to express these logic?

calpa opened this issue · 5 comments

calpa commented
  1. a || !b

  2. !a || b

  3. !a && b

  4. a && !b

  5. a << 2

  6. a >> 2

  7. a >> n

  8. a << n

  9. this.

  10. constructor

  11. require()

  12. import

  13. a ** 2

  14. Math.sqrt()

  15. console.table()

Hi there,

Good question! You can express logical not with , and logical and/or with 中有陽乎 and 中無陰乎, like so:

吾有二爻。名之曰「甲」。曰「乙」。
變「甲」。名之曰「丙」。夫「乙」「丙」中有陽乎。書之。
變「甲」。名之曰「丙」。夫「乙」「丙」中無陰乎。書之。

Currently you need to simulate bit shifts with multiplication. I don’t intend to add bitwise operations into the syntax itself (as I don’t think they fit with the philosophy), but likely as methods of an importable module.

Which brings us to the question of require. I’m currently thinking of implementing imports with the following syntax:

欲解此中意。必先讀「位元運算」篇。

But I haven’t finalized on the details yet. Similar with the math functions you mentioned. Perhaps in the near future!

P.S. A somewhat hacky alternative at this time would be to use the js identifiers directly, but is of course, hacky :-P

吾有一術。名之曰「平方根」。昔之「平方根」者。今「Math.sqrt」是矣。施「平方根」於四。書之。

Thanks.

qex commented

吾有一術。名之曰「平方根」。昔之「平方根」者。今「Math.sqrt」是矣。施「平方根」於四。書之。

这句话看起来真是充满了玄幻的味道 ...

以及说关于 慾解此中意 此句应为 欲解此中意 ... 「慾」字仅限名词使用如「食慾」「性慾」等 ...

动词用法必须用「欲」 ... 如「欲罷不能」「欲蓋彌彰」等 ... 正体中文不可乱用呀 ...

Good call @qex ! I'm going to blame it on the input method :-P
Just edited my comment.

I was thinking about this:
a>>1//倍「甲」
a<<1//半「甲」而棄其餘
a>>2//倍「甲」二番
a<<2//半「甲」而棄其餘者二番也

antfu commented

We are now having stdlibs for Bit Manipulation and Math, check out here: https://github.com/wenyan-lang/wenyan/wiki/Standard-Library-Cheatsheet

For module importing: https://github.com/wenyan-lang/wenyan/wiki/Importing

Class support is still in the plan, please continue in #31

Thanks.