Skip to content

Instantly share code, notes, and snippets.

@disnet
Created November 28, 2012 23:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save disnet/4165526 to your computer and use it in GitHub Desktop.
Save disnet/4165526 to your computer and use it in GitHub Desktop.
javascript - sweet.js macro checking for null
macro null_helper {
case ($processed ...) ($rest) => {
$processed (.) ... . $rest
}
case ($processed ...) ($rest_head $rest ...) => {
$processed (.) ... . $rest_head
&& null_helper ($processed ... $rest_head) ($rest ...)
}
}
macro nullity {
case ($x) => {
$x
}
case ($head . $rest (.) ...) => {
$head && null_helper ($head) ($rest ...)
}
}
nullity (x.y.z)
// x && x.y && x.y.z
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment