Skip to content

Instantly share code, notes, and snippets.

@soegaard
Last active August 29, 2015 14:02
Show Gist options
  • Save soegaard/c3dcd53143504e4a9b11 to your computer and use it in GitHub Desktop.
Save soegaard/c3dcd53143504e4a9b11 to your computer and use it in GitHub Desktop.
The pattern class even
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