Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Array-copying algorithm fails #18

Open
sozysozbot opened this issue Jul 26, 2020 · 1 comment
Open

Array-copying algorithm fails #18

sozysozbot opened this issue Jul 26, 2020 · 1 comment

Comments

@sozysozbot
Copy link
Contributor

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.

@LingDong-
Copy link
Member

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants