I'm studying Common Lisp and want to play with lisp and web development. My current problem comes from a simple idea to iterate over all javascript files i want to include. I use SBCL and Quicklisp for fast startup. The problem could be related to the cl-who
package I'm using.
So I've declared my package and started like this:
(defpackage :0xcb0
(:use :cl :cl-who :hunchentoot :parenscript))
(in-package :0xcb0)
To keep it simple I reduced my problem function. So I have this page
function:
(defun page (test)
(with-html-output-to-string
(*standard-output* nil :prologue nil :indent t)
(:script
(:script :type "text/javascript" :href test))))
This will produce the desired output
*(0xcb0::page "foo")
<script>
<script type='text/javascript' href='foo'></script>
</script>
Now my I've created a macro which produces :script
tags.
(defmacro js-source-file (filename)
`(:script :type "text/javascript" :href ,filename)))
This works as expected:
*(macroexpand-1 '(0XCB0::js-source-file "foo"))
(:SCRIPT :TYPE "text/javascript" :HREF "foo")
However if I include this into my page
function:
(defun page (test)
(with-html-output-to-string
(*standard-output* nil :prologue nil :indent t)
(:script
(js-source-file "foo"))))
...it will give me a style warning (undefined function: :SCRIPT
) when defining the new page
function. Also, the page
function produces this error when executed:
*(0xcb0::page "foo")
The function :SCRIPT is undefined.
[Condition of type UNDEFINED-FUNCTION]
Why does the embedded macro js-source-file
works as expected, in that it produces the desired output, but fails when is called within another function?
P.S. I know the topic of macros in Lisp can be quite exhausting for a beginner like me. But currently I can't wrap my head around the fact that this should work but doesn't!