Advertisement
Guest User

Scheme in Node

a guest
Oct 8th, 2012
263
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  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
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement