Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2022
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lisp 1.24 KB | None | 0 0
  1. (defpackage :program (:use #:cl #:cl-who #:parenscript))
  2. (in-package :program)
  3.  
  4. (setq *js-string-delimiter* #\")
  5.  
  6. (defmacro emit (language file &body body)
  7.  `(with-open-file (str ,file
  8.                        :direction :output
  9.                        :if-exists :supersede)
  10.     (princ ,(cond ((eq language 'html)
  11.                    `(with-html-output-to-string (s nil :prologue t :indent t) ,@body))
  12.                   ((eq language 'javascript)
  13.                    `(ps ,@body))
  14.                   ((eq language 'json)
  15.                    `(remove #\; (ps ,@body))))
  16.            str)))
  17.  
  18. (emit json "~/file.json"
  19.  (create "name" "Wiki-Links"
  20.          "description" "Organize your Wikipedia reading history.")
  21.  (create "version" 1
  22.          "permissions" (array "storage")))
  23.  
  24. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  25. ;; macro-expansion form that the code produces:
  26. ;;
  27. ;; (WITH-OPEN-FILE (STR "~/file.json" :DIRECTION :OUTPUT :IF-EXISTS :SUPERSEDE)
  28. ;;   (PRINC
  29. ;;    (REMOVE #\;
  30. ;;            (PS
  31. ;;              (CREATE "name" "Wiki-Links" "description"
  32. ;;               "Organize your Wikipedia reading history.")
  33. ;;              (CREATE "version" 1 "permissions" (ARRAY "storage"))))
  34. ;;    STR))
  35.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement