Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- 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.
- */
- macro scheme {
- case: ($x $y) => {
- $x($y);
- }
- case: [$x $y] => {
- [$x [$y]];
- }
- case: (define $x $y) => {
- var $x = $y;
- }
- case: (if $params $body) => {
- if ($params) { $body }
- }
- case: (+ $x $y) => {
- $x + $y;
- }
- }
- macro lambda {
- case $params $body => {
- function $params { $body }
- }
- }
- macro display {
- case $params => {
- console.log($params)
- }
- }
- scheme: (display "hello")
- scheme: (define factorial (lambda () (display "hello"))) // scheme lambda
- scheme: (display "hello")
- scheme: (if true (display "hello"))
- scheme: (+ 5 5)
- scheme: [5 6] // scheme list
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement