[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
define-xxx macros
Scott McKay wrote:
;; Defines the element <hd:title-bar inverse="yes">This is a Title</hd:title-bar>
(define-body-element title-bar (contents &key ((inverse?) nil))
(include-html (if inverse? "inverse-title-bar-start" "title-bar-start"))
(include-html contents)
(include-html "title-bar-end"))
So, in Python, this might become:
class title_bar(body_element):
def expand(self, contents, inverse=None):
if inverse: self.include_html("inverse-title-bar-start")
else: self.include_html("title-bar-start")
self.include_html(contents)
self.include_html("title-bar-end")
Or, perhaps:
class title_bar(body_element):
def expand(self, contents, inverse=None):
start = "title-bar-start"
if inverse: start = "inverse-title-bar-start"
self.include_html([start, contents, "title-bar-end"])
Or even:
class hd_elements(body_elements):
def image_server(self):
self.show_string(self.image_server_url)
def title_bar(self, contents, inverse=None):
start = "title-bar-start"
if inverse: start = "inverse-title-bar-start"
self.include_html([start, contents, "title-bar-end"])
Python provides the ability to find objects, such as classes or
methods, by name, and to inspect argument lists (for example, to
discover that title_bar.expand takes an optional argument called
'inverse'). That seems sufficient to me for this task; I don't see
that implementing define-body-element as a macro buys you much in this
case, except possibly some run-time efficiency.
PyUnit defines test cases this way.
I assume that compiling your Lisp into Java required writing something
that understood that e.g. (if condition consequent alternative) should
get compiled into a Java "if" statement, etc. You'd have to do the
same thing for the Python code here, of course, although the output of
the Python standard library parser module stinks compared to the
output of READ.
Also sounds like Charles Simonyi just left Microsoft Research to found
a company to sell an programming environment that sounds an awful lot
like Lisp with macros ("intentions") and different surface syntaxes.
And Gregor Kiczales has left PARC to join him.
--
<kragen@pobox.com> Kragen Sitaker <http://www.pobox.com/~kragen/>
Edsger Wybe Dijkstra died in August of 2002. The world has lost a great
man. See http://advogato.org/person/raph/diary.html?start=252 and
http://www.kode-fu.com/geek/2002_08_04_archive.shtml for details.