[Tutor] Comparative code questions: Python vs. Rebol
Tim Johnson
tim@johnsons-web.com
Tue Jan 14 18:02:02 2003
Hello All:
I'm writing a column where I am comparing certain simple
coding tasks in different programming languages. This time,
I doing 'rebol' and 'python'.
My first example is swapping values with a temporary variable
(and I lifted this right out of "The Python Cookbook")
# Python
a,b,c = c,b,a
; Rebol
set [a b c] reduce [c b a]
Now here is a more complex example:
Dynamically compose a series of functions such that
# python
print H3("This an html header of level 3")
>>> "<H3>This is an html header of level 3</H3>"
; Rebol
print H3 "This an html header of level 3"
>> gives the same and so on from level 1 through
level 6
In rebol, it works this way:
repeat count 6[
do rejoin[ "H" count ": sub[val][val: reduce val ml[H" count "[(val)]]]" ]
]
; Here rebol composes a series of 6 strings and evaluates them as source
; code for functions, which are then installed in memory.
; Works well for short functions which may have small variances
; in a general code template
Is it possible to do this in python? If so, an example would
be appreciated.
This will be published at http://www.frozen-north-linuxonline.com/
under the label "Code Corner".
And frankly it's good way for me to ease back into Python... I've
got to do some work with it.
Thanks (and I hope I'm being clear here...)
--
Tim Johnson <tim@johnsons-web.com>
http://www.alaska-internet-solutions.com
http://www.johnsons-web.com