Last active
August 29, 2015 14:02
-
-
Save soegaard/c3dcd53143504e4a9b11 to your computer and use it in GitHub Desktop.
The pattern class even
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 even { | |
function (stx) { /* stx is an array of syntax objects */ | |
console.log(stx); | |
var name_stx = stx[0]; | |
var arg = stx[1]; | |
var val = arg.token.value; | |
var res = ( ((val%2)==0) ? [makeValue(true,name_stx)] : false ); | |
if (res) return { result: [stx[1]], | |
rest: stx.slice(2) } | |
else return false }} | |
macro isAllEven { | |
case { _ ($e:even (,) ...) } | |
=> { return #{["yes",$e(,)...]} } | |
case { _ ($e (,) ...) } | |
=> { return #{["no", $e(,)...]} } } | |
"----------------"; | |
isAllEven(); | |
isAllEven(2,4,6); | |
"----------------"; | |
isAllEven(2,5,6); | |
isAllEven("x",5,6); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment