[Tutor] Comparative code questions: Python vs. Rebol
Magnus Lycka
magnus@thinkware.se
Thu Jan 16 08:25:01 2003
At 13:13 2003-01-16 +0300, antonmuhin =ED=E0 rambler.ru wrote:
>There is another approach that seems not to be mentioned yet. It might
>be a little bit closer to Rebol (actually, it's rather Lisp-ish):
>
> >>> def H(level):
>... return lambda x: "<H%d>" % level + x + "</H%d>" % level
>...
> >>> h1 =3D H(1)
> >>> h1("string")
>'<H1>string</H1>'
> >>> h2 =3D H(2)
> >>> h2("another string")
>'<H2>another string</H2>'
Or if you don't like Lisp, use a class...
I'll make it slightly more generic.
>>> class Tag:
... def __init__(self, tag):
... self.tag =3D tag
... def __call__(self, text):
... return "<%s>%s</%s>" % (self.tag, text, self.tag)
...
>>> H1 =3D Tag('h1')
>>> HTML =3D Tag('html')
>>> print HTML(H1('Hello')+'\nHow are you.\n'+H1('Goodbye')+'\nSee you=20
later.\n')
<html><h1>Hello</h1>
How are you.
<h1>Goodbye</h1>
See you later.
</html>
--=20
Magnus Lycka, Thinkware AB
Alvans vag 99, SE-907 50 UMEA, SWEDEN
phone: int+46 70 582 80 65, fax: int+46 70 612 80 65
http://www.thinkware.se/ mailto:magnus@thinkware.se