flat assembler
Message board for the users of flat assembler.

Index > Heap > Programable programming languages - AKA metaprogramming

Thread Post new topic Reply to topic

Joined: 19 Sep 2003
Posts: 1029
Location: Everywhere
Post your example of metaprogramming!
And let's talk how it can be usefull.

My example is Tcl, which is my favorite HLL! Smile

proc makeTemplate {procname templatename parmlist} {
     set arg  [info args $templatename]
     set body [info body $templatename]

     foreach {a b} $parmlist {
         regsub -all $a $body $b body
     eval "proc $procname {$arg} {$body}"

 proc FooTemplate {a b} {
     puts "MSG1"
     puts "hello, $a, $b"
     puts "MSG2"

 makeTemplate foo1 FooTemplate {MSG1 "hello world!" MSG2 "goodbye!"}
 makeTemplate foo2 FooTemplate {MSG1 "hi!" MSG2 "bye!"}

 foo1 mom dad
 foo2 breathren cistern

Tcl also supports these things:
set a 2
set b 3
set $a$b 5
# The variable 23 now holds the 5 value
# Yes! Tcl variables can be anything, even numbers and symbols!
puts $23

Tcl also has the rename command, so you can rename the if command to tcl_if for example.
And define your own proc if that does something else and call tcl_if! Laughing
It's like a macro programming language.

Pretty nice!
I've heard Lisp does metaprogramming too!
Can anyone confirme this?
Also, can self-modifying executable code be considered metaprogramming?

Post your examples!
Even ASM examples!

Have fun! Smile

If you want to know more about Tcl let me know, so I post more examples and links.
Post 07 Sep 2007, 18:07
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  

< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum

Copyright © 1999-2020, Tomasz Grysztar. Also on YouTube, Twitter.

Website powered by rwasa.