Check-in [88827b8336]
Not logged in
Overview
SHA1 Hash:88827b833669fcab08ae1f8d663bb2a067245ea2
Date: 2010-12-02 19:30:24
User: kinaba
Comment:sample clean-up
Timelines: family | ancestors | descendants | both | trunk | release
Downloads: Tarball | ZIP archive
Other Links: files | file ages | manifest
Tags And Properties
Changes

Modified doc/index.html from [a25f52da129efe47] to [8335b49cb250b861].

431 <pre> 431 <pre> 432 &gt;&gt; @value( 1 + 2 ) 432 &gt;&gt; @value( 1 + 2 ) 433 3 433 3 434 </pre> 434 </pre> 435 他のレイヤで動かしてみましょう。適当に。「<tt>@hoge</tt> レイヤ」で。 435 他のレイヤで動かしてみましょう。適当に。「<tt>@hoge</tt> レイヤ」で。 436 <pre> 436 <pre> 437 &gt;&gt; @hoge( 3 ) 437 &gt;&gt; @hoge( 3 ) 438 polemy.failure.RuntimeException@C:\Develop\Projects\Polemy\polemy\eval.d(138 | 438 polemy.failure.RuntimeException@polemy\eval.d(138): 439 [<REPL>:4:8] lift function for @hoge is not registered 439 [<REPL>:4:8] lift function for @hoge is not registered 440 </pre> 440 </pre> 441 <p> 441 <p> 442 エラーになりました。Polemy のインタプリタは、起動時には、<tt>@value</tt> 442 エラーになりました。Polemy のインタプリタは、起動時には、<tt>@value</tt> 443 レイヤでのコードの意味しか知りません。<tt>@hoge</tt> レイヤでは <tt>3</tt> 443 レイヤでのコードの意味しか知りません。<tt>@hoge</tt> レイヤでは <tt>3</tt> 444 というのがどんな意味なのか、わかりません!というエラーが出ています。 444 というのがどんな意味なのか、わかりません!というエラーが出ています。 445 </p> 445 </p> ................................................................................................................................................................................ 463 6 463 6 464 </pre> 464 </pre> 465 <p> 465 <p> 466 では、1+2 を <tt>@hoge</tt> レイヤで動かしてみましょう。 466 では、1+2 を <tt>@hoge</tt> レイヤで動かしてみましょう。 467 </p> 467 </p> 468 <pre> 468 <pre> 469 &gt;&gt; @hoge( 1 + 2 ) 469 &gt;&gt; @hoge( 1 + 2 ) 470 polemy.failure.RuntimeException@C:\Develop\Projects\Polemy\polemy\eval.d(466 | 470 polemy.failure.RuntimeException@polemy\eval.d(466): 471 [<REPL>:3:7] only @value layer can call native function: + 471 [<REPL>:3:7] only @value layer can call native function: + 472 [<REPL>:3:7] + 472 [<REPL>:3:7] + 473 </pre> 473 </pre> 474 <p> 474 <p> 475 まだエラーですね。これは要するに "+" の意味がわからない、と言っています。 475 まだエラーですね。これは要するに "+" の意味がわからない、と言っています。 476 <font color=red><b>レイヤ指定変数定義式</b></font> で、"+" の意味を教えてあげます。 476 <font color=red><b>レイヤ指定変数定義式</b></font> で、"+" の意味を教えてあげます。 477 </p> 477 </p> 478 <pre> 478 <pre> 479 &gt;&gt; @hoge "+" = fun(x, y) {x} | 479 &gt;&gt; @hoge + = fun(x, y) {x} 480 (function:182eca0:18435e0) 480 (function:182eca0:18435e0) 481 &gt;&gt; @hoge( 3 + 4 ) 481 &gt;&gt; @hoge( 3 + 4 ) 482 6 482 6 483 </pre> 483 </pre> 484 <p> 484 <p> 485 できました。 485 できました。 486 </p> 486 </p> 487 <p> 487 <p> 488 他の組み込み関数の意味も決めてみましょう。この <tt>@hoge</tt> レイヤでは、 488 他の組み込み関数の意味も決めてみましょう。この <tt>@hoge</tt> レイヤでは、 489 引き算のつもりで書いたコードが、掛け算になってしまうのだ! 489 引き算のつもりで書いたコードが、掛け算になってしまうのだ! 490 </p> 490 </p> 491 <pre> 491 <pre> 492 &gt;&gt; @hoge "-" = fun(x, y) {x * y} | 492 &gt;&gt; @hoge - = fun(x, y) {x * y} 493 (function:1b4c6a0:1b4fbe0) 493 (function:1b4c6a0:1b4fbe0) 494 &gt;&gt; @hoge( 5 - 6 ) 494 &gt;&gt; @hoge( 5 - 6 ) 495 polemy.failure.RuntimeException@C:\Develop\Projects\Polemy\polemy\eval.d(469 | 495 polemy.failure.RuntimeException@polemy\eval.d(469): 496 [<REPL>:3:24] only @value layer can call native function: * 496 [<REPL>:3:24] only @value layer can call native function: * 497 [<REPL>:3:24] * 497 [<REPL>:3:24] * 498 [<REPL>:4:8] - 498 [<REPL>:4:8] - 499 </pre> 499 </pre> 500 <p> 500 <p> 501 5、の意味は 10 で 6 の意味は 12 なので、10 - 12 と見せかけて掛け算して 120 が返るのだ! 501 5、の意味は 10 で 6 の意味は 12 なので、10 - 12 と見せかけて掛け算して 120 が返るのだ! 502 と思いきや、エラーになってしまいました。なぜでしょう。それは、この "-" の定義、 502 と思いきや、エラーになってしまいました。なぜでしょう。それは、この "-" の定義、 ................................................................................................................................................................................ 505 </p> 505 </p> 506 <p> 506 <p> 507 ここは、「普通の」意味の掛け算を使いたいのです。 507 ここは、「普通の」意味の掛け算を使いたいのです。 508 この部分については、<tt>@value</tt> レイヤで計算して欲しい。 508 この部分については、<tt>@value</tt> レイヤで計算して欲しい。 509 そんなときは、レイヤ指定式を使います。 509 そんなときは、レイヤ指定式を使います。 510 </p> 510 </p> 511 <pre> 511 <pre> 512 &gt;&gt; @hoge "-" = fun(x, y) {<b>@value(@hoge(x) * @hoge(y))</b>} | 512 &gt;&gt; @hoge - = fun(x, y) {<b>@value(@hoge(x) * @hoge(y))</b>} 513 (function:1b086c0:1b4fbe0) 513 (function:1b086c0:1b4fbe0) 514 &gt;&gt; @hoge( 5 - 6 ) 514 &gt;&gt; @hoge( 5 - 6 ) 515 120 515 120 516 </pre> 516 </pre> 517 <p> 517 <p> 518 できました。掛け算は、<tt>@value</tt> レイヤの意味で実行します。 518 できました。掛け算は、<tt>@value</tt> レイヤの意味で実行します。 519 各変数は、<tt>@hoge</tt> レイヤで計算された意味を使います、という意味になります。 519 各変数は、<tt>@hoge</tt> レイヤで計算された意味を使います、という意味になります。 ................................................................................................................................................................................ 706 var ty = @type(y); 706 var ty = @type(y); 707 if tx=="runtime error" then ty 707 if tx=="runtime error" then ty 708 else if ty=="runtime error" then tx 708 else if ty=="runtime error" then tx 709 else if tx=="int" &amp;&amp; ty=="int" then "int" 709 else if tx=="int" &amp;&amp; ty=="int" then "int" 710 else "type error" 710 else "type error" 711 )}; 711 )}; 712 712 713 @type "+" = int_int_int; | 713 @type + = int_int_int; 714 @type "-" = int_int_int; | 714 @type - = int_int_int; 715 @type "&lt;" = int_int_int; | 715 @type &lt; = int_int_int; 716 </pre> 716 </pre> 717 <pre> 717 <pre> 718 &gt;&gt; @type( 1 + 2 ) 718 &gt;&gt; @type( 1 + 2 ) 719 int 719 int 720 &gt;&gt; @type( 1 + "foo" ) 720 &gt;&gt; @type( 1 + "foo" ) 721 type error 721 type error 722 </pre> 722 </pre> 723 <p> 723 <p> 724 「実行時エラーについては、それが起きなければ返すはずの型」を計算するという定義に、 724 「実行時エラーについては、それが起きなければ返すはずの型」を計算するという定義に、 725 ここではしています。さらに(ちょっと手抜きで int 以外を考えていない)if の型定義を考えると、 725 ここではしています。さらに(ちょっと手抜きで int 以外を考えていない)if の型定義を考えると、 726 こんな雰囲気。 726 こんな雰囲気。 727 </p> 727 </p> 728 <pre> 728 <pre> 729 @type "if" (c, t, e) {@value( | 729 @type if (c, t, e) {@value( 730 if( @type(c)=="int" || @type(c)=="runtime error" ) then 730 if( @type(c)=="int" || @type(c)=="runtime error" ) then 731 @type( int_int_int(t(), e()) ) 731 @type( int_int_int(t(), e()) ) 732 else 732 else 733 "type error" 733 "type error" 734 )}; 734 )}; 735 </pre> 735 </pre> 736 <p> 736 <p> ................................................................................................................................................................................ 1009 <script>explorer.outline.writeEnabled = false;</script> 1009 <script>explorer.outline.writeEnabled = false;</script> 1010 1010 1011 <dd><p> 1011 <dd><p> 1012 これはエラーになります。 1012 これはエラーになります。 1013 </p> 1013 </p> 1014 <pre> 1014 <pre> 1015 &gt;&gt; let _ = (@macro twice(x) {x;x} in twice(print("Hello"))) 1015 &gt;&gt; let _ = (@macro twice(x) {x;x} in twice(print("Hello"))) 1016 polemy.failure.RuntimeException@C:\Develop\Projects\Polemy\polemy\value.d(10 | 1016 polemy.failure.RuntimeException@polemy\value.d(109): 1017 [<REPL>:2:35] 'twice' is not set in @value layer 1017 [<REPL>:2:35] 'twice' is not set in @value layer 1018 </pre> 1018 </pre> 1019 <p> 1019 <p> 1020 どういうことかというと、<tt>@macro</tt> で定義したマクロはいつから使えるようになるかという話で、 1020 どういうことかというと、<tt>@macro</tt> で定義したマクロはいつから使えるようになるかという話で、 1021 この <tt>@macro twice(x) {x;x} in ...</tt> の部分は <tt>@value</tt> レイヤの式なので、 1021 この <tt>@macro twice(x) {x;x} in ...</tt> の部分は <tt>@value</tt> レイヤの式なので、 1022 まずこの式全体のマクロ展開が終わったあとにしか実行されないのです。<tt>twice</tt> 1022 まずこの式全体のマクロ展開が終わったあとにしか実行されないのです。<tt>twice</tt> 1023 がマクロと見なされはじめるのは、<tt>@macro</tt> 実行が終わった後。 1023 がマクロと見なされはじめるのは、<tt>@macro</tt> 実行が終わった後。 ................................................................................................................................................................................ 1158 <script>explorer.outline.decSymbolLevel();</script> 1158 <script>explorer.outline.decSymbolLevel();</script> 1159 1159 1160 1160 1161 </td></tr> 1161 </td></tr> 1162 <tr><td id="docfooter"> 1162 <tr><td id="docfooter"> 1163 Page was generated with 1163 Page was generated with 1164 <img src="candydoc/img/candydoc.gif" style="vertical-ali 1164 <img src="candydoc/img/candydoc.gif" style="vertical-ali 1165 on Tue Nov 30 10:23:12 2010 | 1165 on Thu Dec 2 09:14:39 2010 1166 1166 1167 </td></tr> 1167 </td></tr> 1168 </table> 1168 </table> 1169 </div> 1169 </div> 1170 <script> 1170 <script> 1171 explorer.packageExplorer.addModule("index"); 1171 explorer.packageExplorer.addModule("index"); 1172 explorer.packageExplorer.addModule("main"); 1172 explorer.packageExplorer.addModule("main");

Modified index.dd from [c411cf72312ff15e] to [b0a85a436fa9ea4b].

318 <pre> 318 <pre> 319 &gt;&gt; @value( 1 + 2 ) 319 &gt;&gt; @value( 1 + 2 ) 320 3 320 3 321 </pre> 321 </pre> 322 他のレイヤで動かしてみましょう。適当に。「<tt>@hoge</tt> レイヤ」で。 322 他のレイヤで動かしてみましょう。適当に。「<tt>@hoge</tt> レイヤ」で。 323 <pre> 323 <pre> 324 &gt;&gt; @hoge( 3 ) 324 &gt;&gt; @hoge( 3 ) 325 polemy.failure.RuntimeException@C:\Develop\Projects\Polemy\polemy\eval.d(138 | 325 polemy.failure.RuntimeException@polemy\eval.d(138): 326 [<REPL>:4:8] lift function for @hoge is not registered 326 [<REPL>:4:8] lift function for @hoge is not registered 327 </pre> 327 </pre> 328 <p> 328 <p> 329 エラーになりました。Polemy のインタプリタは、起動時には、<tt>@value</tt> 329 エラーになりました。Polemy のインタプリタは、起動時には、<tt>@value</tt> 330 レイヤでのコードの意味しか知りません。<tt>@hoge</tt> レイヤでは <tt>3</tt> 330 レイヤでのコードの意味しか知りません。<tt>@hoge</tt> レイヤでは <tt>3</tt> 331 というのがどんな意味なのか、わかりません!というエラーが出ています。 331 というのがどんな意味なのか、わかりません!というエラーが出ています。 332 </p> 332 </p> ................................................................................................................................................................................ 350 6 350 6 351 </pre> 351 </pre> 352 <p> 352 <p> 353 では、1+2 を <tt>@hoge</tt> レイヤで動かしてみましょう。 353 では、1+2 を <tt>@hoge</tt> レイヤで動かしてみましょう。 354 </p> 354 </p> 355 <pre> 355 <pre> 356 &gt;&gt; @hoge( 1 + 2 ) 356 &gt;&gt; @hoge( 1 + 2 ) 357 polemy.failure.RuntimeException@C:\Develop\Projects\Polemy\polemy\eval.d(466 | 357 polemy.failure.RuntimeException@polemy\eval.d(466): 358 [<REPL>:3:7] only @value layer can call native function: + 358 [<REPL>:3:7] only @value layer can call native function: + 359 [<REPL>:3:7] + 359 [<REPL>:3:7] + 360 </pre> 360 </pre> 361 <p> 361 <p> 362 まだエラーですね。これは要するに "+" の意味がわからない、と言っています。 362 まだエラーですね。これは要するに "+" の意味がわからない、と言っています。 363 $(RED $(B レイヤ指定変数定義式)) で、"+" の意味を教えてあげます。 363 $(RED $(B レイヤ指定変数定義式)) で、"+" の意味を教えてあげます。 364 </p> 364 </p> 365 <pre> 365 <pre> 366 &gt;&gt; @hoge "+" = fun(x, y) {x} | 366 &gt;&gt; @hoge + = fun(x, y) {x} 367 (function:182eca0:18435e0) 367 (function:182eca0:18435e0) 368 &gt;&gt; @hoge( 3 + 4 ) 368 &gt;&gt; @hoge( 3 + 4 ) 369 6 369 6 370 </pre> 370 </pre> 371 <p> 371 <p> 372 できました。 372 できました。 373 </p> 373 </p> 374 <p> 374 <p> 375 他の組み込み関数の意味も決めてみましょう。この <tt>@hoge</tt> レイヤでは、 375 他の組み込み関数の意味も決めてみましょう。この <tt>@hoge</tt> レイヤでは、 376 引き算のつもりで書いたコードが、掛け算になってしまうのだ! 376 引き算のつもりで書いたコードが、掛け算になってしまうのだ! 377 </p> 377 </p> 378 <pre> 378 <pre> 379 &gt;&gt; @hoge "-" = fun(x, y) {x * y} | 379 &gt;&gt; @hoge - = fun(x, y) {x * y} 380 (function:1b4c6a0:1b4fbe0) 380 (function:1b4c6a0:1b4fbe0) 381 &gt;&gt; @hoge( 5 - 6 ) 381 &gt;&gt; @hoge( 5 - 6 ) 382 polemy.failure.RuntimeException@C:\Develop\Projects\Polemy\polemy\eval.d(469 | 382 polemy.failure.RuntimeException@polemy\eval.d(469): 383 [<REPL>:3:24] only @value layer can call native function: * 383 [<REPL>:3:24] only @value layer can call native function: * 384 [<REPL>:3:24] * 384 [<REPL>:3:24] * 385 [<REPL>:4:8] - 385 [<REPL>:4:8] - 386 </pre> 386 </pre> 387 <p> 387 <p> 388 5、の意味は 10 で 6 の意味は 12 なので、10 - 12 と見せかけて掛け算して 120 が返るのだ! 388 5、の意味は 10 で 6 の意味は 12 なので、10 - 12 と見せかけて掛け算して 120 が返るのだ! 389 と思いきや、エラーになってしまいました。なぜでしょう。それは、この "-" の定義、 389 と思いきや、エラーになってしまいました。なぜでしょう。それは、この "-" の定義、 ................................................................................................................................................................................ 392 </p> 392 </p> 393 <p> 393 <p> 394 ここは、「普通の」意味の掛け算を使いたいのです。 394 ここは、「普通の」意味の掛け算を使いたいのです。 395 この部分については、<tt>@value</tt> レイヤで計算して欲しい。 395 この部分については、<tt>@value</tt> レイヤで計算して欲しい。 396 そんなときは、レイヤ指定式を使います。 396 そんなときは、レイヤ指定式を使います。 397 </p> 397 </p> 398 <pre> 398 <pre> 399 &gt;&gt; @hoge "-" = fun(x, y) {$(B @value(@hoge(x) * @hoge(y)))} | 399 &gt;&gt; @hoge - = fun(x, y) {$(B @value(@hoge(x) * @hoge(y)))} 400 (function:1b086c0:1b4fbe0) 400 (function:1b086c0:1b4fbe0) 401 &gt;&gt; @hoge( 5 - 6 ) 401 &gt;&gt; @hoge( 5 - 6 ) 402 120 402 120 403 </pre> 403 </pre> 404 <p> 404 <p> 405 できました。掛け算は、<tt>@value</tt> レイヤの意味で実行します。 405 できました。掛け算は、<tt>@value</tt> レイヤの意味で実行します。 406 各変数は、<tt>@hoge</tt> レイヤで計算された意味を使います、という意味になります。 406 各変数は、<tt>@hoge</tt> レイヤで計算された意味を使います、という意味になります。 ................................................................................................................................................................................ 553 var ty = @type(y); 553 var ty = @type(y); 554 if tx=="runtime error" then ty 554 if tx=="runtime error" then ty 555 else if ty=="runtime error" then tx 555 else if ty=="runtime error" then tx 556 else if tx=="int" && ty=="int" then "int" 556 else if tx=="int" && ty=="int" then "int" 557 else "type error" 557 else "type error" 558 )}; 558 )}; 559 559 560 @type "+" = int_int_int; | 560 @type + = int_int_int; 561 @type "-" = int_int_int; | 561 @type - = int_int_int; 562 @type "<" = int_int_int; | 562 @type &lt; = int_int_int; 563 </pre> 563 </pre> 564 <pre> 564 <pre> 565 &gt;&gt; @type( 1 + 2 ) 565 &gt;&gt; @type( 1 + 2 ) 566 int 566 int 567 &gt;&gt; @type( 1 + "foo" ) 567 &gt;&gt; @type( 1 + "foo" ) 568 type error 568 type error 569 </pre> 569 </pre> 570 <p> 570 <p> 571 「実行時エラーについては、それが起きなければ返すはずの型」を計算するという定義に、 571 「実行時エラーについては、それが起きなければ返すはずの型」を計算するという定義に、 572 ここではしています。さらに(ちょっと手抜きで int 以外を考えていない)if の型定義を考えると、 572 ここではしています。さらに(ちょっと手抜きで int 以外を考えていない)if の型定義を考えると、 573 こんな雰囲気。 573 こんな雰囲気。 574 </p> 574 </p> 575 <pre> 575 <pre> 576 @type "if" (c, t, e) {@value( | 576 @type if (c, t, e) {@value( 577 if( @type(c)=="int" || @type(c)=="runtime error" ) then 577 if( @type(c)=="int" || @type(c)=="runtime error" ) then 578 @type( int_int_int(t(), e()) ) 578 @type( int_int_int(t(), e()) ) 579 else 579 else 580 "type error" 580 "type error" 581 )}; 581 )}; 582 </pre> 582 </pre> 583 <p> 583 <p> ................................................................................................................................................................................ 796 )) 796 )) 797 $(SECTION 微妙なところ3, $(SECBODY 797 $(SECTION 微妙なところ3, $(SECBODY 798 <p> 798 <p> 799 これはエラーになります。 799 これはエラーになります。 800 </p> 800 </p> 801 <pre> 801 <pre> 802 &gt;&gt; let _ = (@macro twice(x) {x;x} in twice(print("Hello"))) 802 &gt;&gt; let _ = (@macro twice(x) {x;x} in twice(print("Hello"))) 803 polemy.failure.RuntimeException@C:\Develop\Projects\Polemy\polemy\value.d(10 | 803 polemy.failure.RuntimeException@polemy\value.d(109): 804 [<REPL>:2:35] 'twice' is not set in @value layer 804 [<REPL>:2:35] 'twice' is not set in @value layer 805 </pre> 805 </pre> 806 <p> 806 <p> 807 どういうことかというと、<tt>@macro</tt> で定義したマクロはいつから使えるようになるかという話で、 807 どういうことかというと、<tt>@macro</tt> で定義したマクロはいつから使えるようになるかという話で、 808 この <tt>@macro twice(x) {x;x} in ...</tt> の部分は <tt>@value</tt> レイヤの式なので、 808 この <tt>@macro twice(x) {x;x} in ...</tt> の部分は <tt>@value</tt> レイヤの式なので、 809 まずこの式全体のマクロ展開が終わったあとにしか実行されないのです。<tt>twice</tt> 809 まずこの式全体のマクロ展開が終わったあとにしか実行されないのです。<tt>twice</tt> 810 がマクロと見なされはじめるのは、<tt>@macro</tt> 実行が終わった後。 810 がマクロと見なされはじめるのは、<tt>@macro</tt> 実行が終わった後。

Modified readme.txt from [d03287608e84fd60] to [366a1df4067e228e].

1 ----------------------------------------------------------------------------- 1 ----------------------------------------------------------------------------- 2 Polemy 0.1.0 2 Polemy 0.1.0 3 by k.inaba (www.kmonos.net) 3 by k.inaba (www.kmonos.net) 4 Nov 25, 2010 | 4 Dec 4, 2010 5 ----------------------------------------------------------------------------- 5 ----------------------------------------------------------------------------- 6 6 7 [How to Build] 7 [How to Build] 8 8 9 - Install DMD 9 - Install DMD 10 http://www.digitalmars.com/d/2.0/changelog.html 10 http://www.digitalmars.com/d/2.0/changelog.html 11 Version 2.050 is recommended. Older or newer version may not work. 11 Version 2.050 is recommended. Older or newer version may not work.

Modified sample/fib.pmy from [4438bc82733dcb16] to [fd8a6f88bc7a9f4a].

6 6 7 let upto = fun(n, f){ 7 let upto = fun(n, f){ 8 if n > 0: upto(n-1,f); 8 if n > 0: upto(n-1,f); 9 f(n) 9 f(n) 10 }; 10 }; 11 11 12 var compose = fun(f,g){ fun(x){f(g(x))} }; 12 var compose = fun(f,g){ fun(x){f(g(x))} }; 13 var "<<" = compose; | 13 var << = compose; 14 14 15 upto(18, print<<fib); 15 upto(18, print<<fib); 16 16 17 17 18 ###################################### 18 ###################################### 19 # Omake. Feel the automatic memoization! 19 # Omake. Feel the automatic memoization! 20 20 21 # Set up a mirror layer (do-the-same-thing layer) of @value 21 # Set up a mirror layer (do-the-same-thing layer) of @value 22 @@m(x){x}; 22 @@m(x){x}; 23 @m "+" (x,y) { @value(@m(x)+@m(y)) }; | 23 @m + (x,y) { @value(@m(x)+@m(y)) }; 24 @m "-" (x,y) { @value(@m(x)-@m(y)) }; | 24 @m - (x,y) { @value(@m(x)-@m(y)) }; 25 @m "<" (x,y) { @value(@m(x)<@m(y)) }; | 25 @m < (x,y) { @value(@m(x)<@m(y)) }; 26 @m "if" (c,t,e) { @value(if @m(c) then @m(t()) else @m(e())) }; | 26 @m if (c,t,e) { @value(if @m(c) then @m(t()) else @m(e())) }; 27 27 28 # Helper function to call fib in layer @m 28 # Helper function to call fib in layer @m 29 def fibm(x @value) { @m(fib(@value(x))) }; 29 def fibm(x @value) { @m(fib(@value(x))) }; 30 30 31 # User defined layers are automatically memoized. 31 # User defined layers are automatically memoized. 32 # So this is much faster. 32 # So this is much faster. 33 upto(18, print<<fibm); 33 upto(18, print<<fibm);

Deleted sample/fizzbuzz.pmy version [8920e9fd1d398081]

1 # < 2 # Not at all a good example of the usage of layers, but anyway... < 3 # < 4 < 5 @@3(x){x}; < 6 @@5(x){x}; < 7 @@15(x){x}; < 8 def incr(x) { x+1 }; < 9 @ 3 incr(x) {@value( if(@ 3(x)+1< 3)then@ 3(x)+1 else 0 )}; < 10 @ 5 incr(x) {@value( if(@ 5(x)+1< 5)then@ 5(x)+1 else 0 )}; < 11 @15 incr(x) {@value( if(@15(x)+1<15)then@15(x)+1 else 0 )}; < 12 < 13 def fb(n @value @3 @5 @15) { < 14 print( if @15(n): if @5(n): if @3(n): n else: "Fizz" else "Buzz" else "FizzBuz < 15 fb(incr(n)) < 16 }; < 17 < 18 fb(0) <

Added sample/lazy.pmy version [4af3c4ccb9eff42b]

> 1 # I'm lazy. So I define only the primitives needed for tarai. > 2 @@lazy(x) { fun(){x} }; > 3 @lazy - (x,y) { fun(){@value(@lazy(x)() - @lazy(y)()) } }; > 4 @lazy <= (x,y) { fun(){@value(@lazy(x)() <= @lazy(y)()) } }; > 5 @lazy if (c,t,e) { fun(){@value(if @lazy(c)() then @lazy(t())() else @lazy(e())( > 6 > 7 def tarai(x,y,z) > 8 { > 9 if x<=y then > 10 y > 11 else > 12 tarai( tarai(x-1,y,z), tarai(y-1,z,x), tarai(z-1,x,y) ) > 13 }; > 14 > 15 # print( tarai(12, 6, 0) ); > 16 print( @lazy( tarai(12, 6, 0) )() ); > 17 > 18 > 19 #### Omake: only Z is made lazy. > 20 def taraiZ(x,y,z @lazy) > 21 { > 22 if x<=y then > 23 y > 24 else > 25 taraiZ( taraiZ(x-1,y,z), taraiZ(y-1,@lazy(z)(),x), taraiZ(@lazy( > 26 }; > 27 print( taraiZ(12,6,0) );

Modified sample/type.pmy from [a04d420215bb851f] to [5f72922a0ac6e212].

61 if @type(x)=="RE" || @type(y)=="RE": "RE" 61 if @type(x)=="RE" || @type(y)=="RE": "RE" 62 else if @type(x)=="TE" || @type(y)=="TE": "TE" 62 else if @type(x)=="TE" || @type(y)=="TE": "TE" 63 else t0 63 else t0 64 )} 64 )} 65 }; 65 }; 66 66 67 # type annotation for built-in ops 67 # type annotation for built-in ops 68 @type "+" = Tbin("int", "int", "int"); | 68 @type + = Tbin("int", "int", "int"); 69 @type "-" = Tbin("int", "int", "int"); | 69 @type - = Tbin("int", "int", "int"); 70 @type "*" = Tbin("int", "int", "int"); | 70 @type * = Tbin("int", "int", "int"); 71 @type "/" = Tbin("int", "int", "int"); | 71 @type / = Tbin("int", "int", "int"); 72 @type "%" = Tbin("int", "int", "int"); | 72 @type % = Tbin("int", "int", "int"); 73 @type "&&" = Tbin("int", "int", "int"); | 73 @type && = Tbin("int", "int", "int"); 74 @type "||" = Tbin("int", "int", "int"); | 74 @type || = Tbin("int", "int", "int"); 75 @type print = fun(x){x}; 75 @type print = fun(x){x}; 76 @type gensym = fun(){"str"}; 76 @type gensym = fun(){"str"}; 77 @type argv = {list: "str"}; 77 @type argv = {list: "str"}; 78 @type rand = Tuni("int","int"); 78 @type rand = Tuni("int","int"); 79 @type "~" = Tbinany("str"); | 79 @type ~ = Tbinany("str"); 80 @type "<" = Tbinany("int"); | 80 @type < = Tbinany("int"); 81 @type "<=" = Tbinany("int"); | 81 @type <= = Tbinany("int"); 82 @type ">" = Tbinany("int"); | 82 @type > = Tbinany("int"); 83 @type ">=" = Tbinany("int"); | 83 @type >= = Tbinany("int"); 84 @type "==" = Tbinany("int"); | 84 @type == = Tbinany("int"); 85 @type "!=" = Tbinany("int"); | 85 @type != = Tbinany("int"); 86 @type "if" (c,t,e) {@value( | 86 @type if (c,t,e) {@value( 87 if @type(c)=="RE": "RE" 87 if @type(c)=="RE": "RE" 88 else if @type(c)!="int": "TE" 88 else if @type(c)!="int": "TE" 89 else mergeType( @type(t()), @type(e()) ); 89 else mergeType( @type(t()), @type(e()) ); 90 )}; 90 )}; 91 @type _isint = Tuniany("int"); 91 @type _isint = Tuniany("int"); 92 @type _isstr = Tuniany("int"); 92 @type _isstr = Tuniany("int"); 93 @type _isfun = Tuniany("int"); 93 @type _isfun = Tuniany("int"); ................................................................................................................................................................................ 94 @type _istbl = Tuniany("int"); 94 @type _istbl = Tuniany("int"); 95 @type _isbot = Tuniany("int"); 95 @type _isbot = Tuniany("int"); 96 96 97 ################################### 97 ################################### 98 98 99 # for lists 99 # for lists 100 @type "{}"() {@value( {list: "RE"} )}; 100 @type "{}"() {@value( {list: "RE"} )}; 101 @type ".?"(t, s) {@value( | 101 @type .? (t, s) {@value( 102 if @type(t)=="RE": "RE" 102 if @type(t)=="RE": "RE" 103 else if @type(t)=="TE": "TE" 103 else if @type(t)=="TE": "TE" 104 else if _istbl( @type(t) ): "int" 104 else if _istbl( @type(t) ): "int" 105 else "TE" 105 else "TE" 106 )}; 106 )}; 107 @type ".="(t, s@value, v) {@value( | 107 @type .= (t, s@value, v) {@value( 108 var tt = @type(t); 108 var tt = @type(t); 109 if tt == "TE": "TE" 109 if tt == "TE": "TE" 110 else if tt == "RE": "RE" 110 else if tt == "RE": "RE" 111 else if _istbl(tt) && tt.?list: 111 else if _istbl(tt) && tt.?list: 112 if s == "car": 112 if s == "car": 113 mergeType(tt, {list: @type(v)}) 113 mergeType(tt, {list: @type(v)}) 114 else if s == "cdr": 114 else if s == "cdr": 115 mergeType(tt, @type(v)) 115 mergeType(tt, @type(v)) 116 else: 116 else: 117 tt 117 tt 118 else: 118 else: 119 "TE" 119 "TE" 120 )}; 120 )}; 121 @type "."(t, s@value) {@value( | 121 @type . (t, s@value) {@value( 122 var tt = @type(t); 122 var tt = @type(t); 123 if tt == "TE": "TE" 123 if tt == "TE": "TE" 124 else if tt == "RE": "RE" 124 else if tt == "RE": "RE" 125 else if _istbl(tt) && tt.?list: 125 else if _istbl(tt) && tt.?list: 126 if s == "car": 126 if s == "car": 127 tt.list 127 tt.list 128 else if s == "cdr": 128 else if s == "cdr":