Code: Select all
(setq foo "bar")
(setq bar '(1 2 3 ,foo foobar)) ; => (1 2 3 "bar" foobar)
Code: Select all
(define-macro (unless condition)
(let ( (body (args)) )
(eval '(if (not ,condition) ,body))))
Code: Select all
(setq foo "bar")
(setq bar '(1 2 3 ,foo foobar)) ; => (1 2 3 "bar" foobar)
Code: Select all
(define-macro (unless condition)
(let ( (body (args)) )
(eval '(if (not ,condition) ,body))))
Code: Select all
; takes an item from the template and decides whether to evaluate it or not.
; if the item starts with an "@" and is a symbol, then return the evaluation
; of that item without the "@", or else just return the item as given.
(define (template-replace s)
(if (and (starts-with (string s) "@") (symbol? s))
(eval (sym (1 (string s)))) s))
; templating macro for newLISP.
; example:
; (setq foo "bar")
; (template (1 2 @foo foo)) ; => (1 2 "bar" foo)
(define-macro (template tmp)
(map template-replace tmp))
Code: Select all
(define-macro (template)
(let ((form (args 0)) (syms (rest (args))))
(if (symbol? form) (set 'form (eval form)))
(cond ((empty? syms) form)
(true
(begin (nth-set (form (ref '_ form)) (eval (first syms)))
(if (rest syms)
(eval (cons 'template (cons form (rest syms))))
form))))))
(set 'test-fn '(define (_) (println _)))
(set 'some-var "hello")
(set 'expanded
(template test-fn (sym (format "print-%s" some-var))
some-var))
(println expanded)
(eval expanded)
(print-hello)