View difference between Paste ID: 0nPBg8LY and
SHOW: | | - or go back to the newest paste.
1-
1+
/*
2
I downloaded the whole sweet.js zip from github and then put this file (macrotest.js) into the bin folder of the zip (after unzipping it).  It runs on node, you just say "node sjs macrotest.js" and it expands the macros.  Pretty cool.
3
*/
4
macro scheme {
5
	case: ($x $y) => {
6
		$x($y);
7
	}
8
	case: [$x $y] => {
9
		[$x [$y]];
10
	}
11
	case: (define $x $y) => {
12
		var $x = $y;
13
	}
14
	case: (if $params $body) => {
15
		if ($params) { $body }
16
	}
17
	case: (+ $x $y) => {
18
		$x + $y;
19
	}
20
}
21
macro lambda {
22
  case $params $body => {
23
  	function $params { $body }
24
  }
25
}
26
macro display {
27
	case $params => {
28
		console.log($params)
29
	}
30
}
31
scheme: (display "hello")
32
scheme: (define factorial (lambda () (display "hello"))) // scheme lambda
33
scheme: (display "hello")
34
scheme: (if true (display "hello"))
35
scheme: (+ 5 5)
36
scheme: [5 6] // scheme list