Custom AST Transformation 㧠ã¡ã¢åã試ãã¦ã¿ã¾ãã
Groovy ASTå¤æã«ããã³ã³ãã¤ã«æã¡ã¿ããã°ã©ãã³ã°ã«ã¤ãã¦ã調æ»ãç¶ç¶ãã¦ãã¾ãã
ä»æ¥ã¯ãç°¡åãªã³ã¼ããæ¸ãã¦ã¿ã¾ãããã³ã³ãã¤ã«ä¸ã« AST å¤æãè¡ããä»»æã®ã¡ã½ãããã¡ã¢åã§ãã¾ãã
ã¨ãããã使ç¨ä¾ãã
@Memoized def fib(n) { if (n <= 1) return n else return fib(n - 1) + fib(n - 2) }
ä¸è¨ã®ããã«ã@Memoized ã¨ã¢ãã¼ãã¼ã·ã§ã³ãã¤ããã¨ããã®ã¡ã½ãããã¡ã¢åããããã㪠Custom AST å¤æãä½ã£ã¦ã¿ã¾ããã
ASTå¤æåä½ã®æ¦è¦ã¯ãä¸è¨ã®ãããªæãã§ãã
- ã¢ãã¼ãã¼ã·ã§ã³ãä»ããããã¡ã½ãããå¥åã«å¤æ´ãã
- å ã®ååã§ã¡ã¢åå¦çç¨ã®ãã£ãã·ã¥åç §é¢æ°ãçæãã
ç¾ç¶ã§ã¯ã1å¼æ°ã®ã¡ã½ããã«ã ã対å¿ãã¦ãã¾ããã¾ã ã¾ã Groovy ã§ã®éçºç°å¢æ´åãåºæ¥ã¦ããªãç¶æ³ã§ãããã«ãã¹ã/ãããã°ãã§ããªãæãæ§ã§ããå®éãã½ã¼ã¹ãã覧ããã ããã°åããã¨ãããã¡ãã»ã¼ã¸ããã¯ã¹ã§ãããã°ã¡ãã»ã¼ã¸ãåºãã¦ããã¨ããç¶æ ãã¨ããããã§ãã¾ãã¯ç°å¢æ´åãé²ãã¦ãããã¨æãã¾ãã
次åã¯ãCustom AST ã³ã¼ãéçºã«ããããã¹ãç°å¢ãªã©ã«ã¤ãã¦èãã¦ããããã¨æãã¾ããç¾ç¶ã¯ãASTå¤æã楽ããã®ã§å£æªãªãã¹ãç°å¢ã§ãæ°ã«ãªããªãã®ã§ããããã®ãã¡ã«å«æ°ãå·®ãã¦ããã§ãããããããã