wenyan icon indicating copy to clipboard operation
wenyan copied to clipboard

added macro for imports: 予观夫「列經」胜状,在「遍施」、「篩剔」、「左併」三湖。

Open kaiyuan01 opened this issue 5 years ago • 9 comments

吾嘗觀「「列經」」之書。方悟「遍施」「篩剔」「左併」之義。

或云「「予观夫「甲」胜状,在「乙」、「丙」、「丁」三湖」」。 蓋謂「「吾嘗觀「甲」之書。方悟「乙」「丙」「丁」之義」。

予观夫「列經」胜状,在「遍施」、「篩剔」、「左併」三湖。

kaiyuan01 avatar Dec 31 '19 20:12 kaiyuan01

Follow the syntax in

予观夫巴陵胜状,在洞庭一湖.

岳阳楼记 (作者:范仲淹)

kaiyuan01 avatar Dec 31 '19 20:12 kaiyuan01

Any idea why the build failed with:

TypeError: Cannot read property 'length' of undefined

?

kaiyuan01 avatar Dec 31 '19 21:12 kaiyuan01

Hi @kaiyuan01 ,

Thanks for the PR. However, a couple of things:

  • You are missing a at the end of蓋謂「「吾嘗觀「甲」之書。方悟「乙」「丙」「丁」之義」。. That is one of the reasons why it doesn't compile. Please double check your code before submitting any PR.

  • Currently import statements cannot be patched by macros. They are used by the processor to figure out which files to extract macros from, and having them as part of a macro confuses the preprocessor. I can see a way around this, will investigate later. Thanks for bringing this up.

  • We all love 岳陽樓記, but I don't think your addition adds much to the illustrative purpose of the example. Moreover, I think this usage is showing an anti-pattern. We would hope that users utilize macros to make their code more clear and concise, while your example is doing the exact opposite: obfuscating the import statement into something irrelevant. Technically this is something cool the user can do if they choose to, but we would like to refrain from advocating it in the examples :)

Thanks again for your understanding.

LingDong- avatar Dec 31 '19 22:12 LingDong-

Sorry I was on another computer which was not able to run gitpod due to network issues. This is more like an example to show how macro works (it can be more concise, or more verbose if we want to attract non-programmers :-) )

kaiyuan01 avatar Jan 01 '20 01:01 kaiyuan01

Hi @kaiyuan01 ,

Thanks for the PR. However, a couple of things:

  • You are missing a at the end of蓋謂「「吾嘗觀「甲」之書。方悟「乙」「丙」「丁」之義」。. That is one of the reasons why it doesn't compile. Please double check your code before submitting any PR.
  • Currently import statements cannot be patched by macros. They are used by the processor to figure out which files to extract macros from, and having them as part of a macro confuses the preprocessor. I can see a way around this, will investigate later. Thanks for bringing this up.
  • We all love 岳陽樓記, but I don't think your addition adds much to the illustrative purpose of the example. Moreover, I think this usage is showing an anti-pattern. We would hope that users utilize macros to make their code more clear and concise, while your example is doing the exact opposite: obfuscating the import statement into something irrelevant. Technically this is something cool the user can do if they choose to, but we would like to refrain from advocating it in the examples :)

Thanks again for your understanding.

@LingDong- Thanks for the help. Was the second issue fixed? Just wondering what failed the current tests.

kaiyuan01 avatar Jan 01 '20 19:01 kaiyuan01

  • Second issue is not fixed yet, will look into it
  • I maintain the opinion in my third point Thanks!

LingDong- avatar Jan 01 '20 21:01 LingDong-

I made the change as suggested. You may consider merging it once you fix Issue #2.

kaiyuan01 avatar Jan 03 '20 00:01 kaiyuan01

Hi, sorry for the delay, the issue of inability to use macros for import statements has been fixed in my newest commit 55d288581783c183b0a40caeb662bf6757302022.

However there is one more problem with your code, that is, a macro cannot end with an identifier. If it ends with an identifier like 得「乙」「丙」「丁」於「甲」, the finding-replacing wouldn't know where to end. See #440 for details.

I recommend that you change it to something like this:

...

或云「「得「乙」「丙」「丁」於「甲」焉」」。
蓋謂「「吾嘗觀「甲」之書。方悟「乙」「丙」「丁」之義」」。

...

得「遍施」「篩剔」「左併」於「「列經」」焉

...

Also please drop the 三湖 etc comment. Thanks!

LingDong- avatar Jan 07 '20 03:01 LingDong-

想法挺好

Xuanmizhen avatar Apr 10 '22 14:04 Xuanmizhen