wenyan-lang / book

文言陰符 An Introduction to Programming in Wenyan Language

Home Page:https://book.wy-lang.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Array-copying algorithm fails

sozysozbot opened this issue · comments

The code given in the book,

吾有一列。名之曰「甲」。充「甲」以三。充「甲」以五。

吾有一列。名之曰「乙」。
凡「甲」中之「元」。充「乙」以其也。

compiles to

var 甲 = [];
甲.push(3);
甲.push(5);
var 乙 = [];
for (let 元 of 甲) {
  乙.push();
};

in both the online IDE and wenyan -c.

Contrary to what is claimed in the book (欲令其實亦二。互不相干。當如何。曰。當如是), this code does not make a copy of an array, since no element is pushed to 「乙」. Though

吾有一列。名之曰「甲」。充「甲」以三。充「甲」以五。

吾有一列。名之曰「乙」。
凡「甲」中之「元」。充「乙」以「元」也。

would fix the problem, it might be that the failure of 其 to point to 「元」 is a regression introduced somewhere within the long history of wenyan-lang.

Hi @sozysozbot, thanks for pointing out the issue!

I believe it's a typo in the book, using 其 to refer「元」in this case shouldn't be valid wenyan, since 其 refers to an unnamed previous computation result, while in this case the variable is already given the name of「元」.

The error is now fixed in the book: 0c8c030

Thanks again for spotting the mistake!