Macro to construct function names dynamically
Posted: Thu Jul 28, 2011 6:49 am
Hello,
I'm new to Lisp and my previous programming experience was mostly C, Perl and shell scripts. I'm still heavily influenced by it so please bear with me.
So: Is there a way to define a macro which constructs a function name when given a list of symbols? I'd like to call it like this:
and get as a result
How do I construct the do-function-* names? Once I get past that the rest is easy. Is there a common idiom for this kind of things? If I were using Bash I'd probably say
although it's not quite the same.
Thank you in advance.
I'm new to Lisp and my previous programming experience was mostly C, Perl and shell scripts. I'm still heavily influenced by it so please bear with me.
So: Is there a way to define a macro which constructs a function name when given a list of symbols? I'd like to call it like this:
Code: Select all
(do-expand-functions '(first second third fourth fifth) '(a b c) (list foo bar baz quux))
Code: Select all
(progn
(do-function-a-first foo)
(do-function-a-second foo)
(do-function-a-third foo)
(do-function-a-fourth foo)
(do-function-a-fifth foo)
(do-function-b-first bar)
(do-function-b-second bar)
.
.
.
(do-function-c-fifth quux))
Code: Select all
for I in a b c; do
for J in first second third; do
for K in foo bar baz quux; do
eval do_function_${I}_${J} $K
done
done
done
Thank you in advance.