sjs --module ./mod.js --output fn.built.js fn.js
sjs --module ./mod.js --output fn2.built.js fn2.js
sjs --module ./mod.js --output fn3.built.js fn3.js
Created
February 16, 2014 15:09
-
-
Save pasberth/9035794 to your computer and use it in GitHub Desktop.
sweet.js でのアレ
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| fn x y { x }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| square = fn x { x * x }; | |
| cube = fn x { square(x) * x }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| fill = fn container [liquid = "coffee"] { | |
| "Filling the #{container} with #{liquid}..." | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| macro setdefault { | |
| rule { $var = $init } => { if ($var == null) { $var = $init } } | |
| } | |
| macro setdefaults { | |
| rule { { } } => {} | |
| rule { { $var = $init $repeat ... } } => { setdefault $var = $init ; setdefaults { $repeat ... } } | |
| } | |
| macro setdefaults1 { | |
| rule { { = } } => {} | |
| rule { { $var $vars ... = $init $inits ... } } => { setdefault $var = $init ; setdefaults1 { $vars ... = $inits ... } } | |
| } | |
| macro fn { | |
| rule { $params ... [$($option = $init) ...] { $body ... } } => { (function ($params ... $option ...) { setdefaults1 { $option ... = $init ... } ; return ($body ...) }) } | |
| rule { $params ... { $body ... } } => { (function ($params ...) { return ($body ...) }) } | |
| } | |
| macro when { | |
| rule { | |
| $cond { $body ... } | |
| } => { | |
| { | |
| if ($cond) { $body ... } | |
| } | |
| } | |
| } | |
| export fn; | |
| export when; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment