I need a function to generate a decision tree based on X variables,
each of which can have Y possible values. Is there a straightforward
way to take a nested list of the variables and their associated sets
of possible values, like the following:
'((var1 '("A" "B" "C"))
(var2 '(123 234 345 456))
(var3 '(SYM1 SYM2 SYM3))
(var4 '('(* SYM1 5.0) '(/ SYM2 4.0) '(+ SYM2 SYM3))))
and produce a [hierarchical] 'decision tree'-like expression in which
all the possible branches are iterated? So, to continue with the
above example, if passed a nested list like the one above, the
function I'm looking for would return an expression not unlike the
following:
(cond ((= var1 "A")
(cond ((= var2 123)
(cond ((= var3 SYM1)
(cond ((= var4 (* SYM1 5.0))
(princ "case 1.1.1.1"))
((= var4 (/ SYM2 4.0))
(princ "case 1.1.1.2"))
((= var4 (+ SYM2 SYM3))
(princ "case 1.1.1.3"))
((= var3 SYM2)
(cond ((= var4 (* SYM1 5.0))
(princ "case 1.1.2.1"))
((= var4 (/ SYM2 4.0))
(princ "case 1.1.2.2"))
((= var4 (+ SYM2 SYM3))
(princ "case 1.1.2.3"))
. . .
As above, it's assumed that the first key/value-list pair in the
argument becomes the top level in the hierarchy.
I couldn't find anything that looked similar in the FAQ, although this
problem _looks_ general enough [and somehow familiar enough] that it's
easy to think it must have been repeatedly solved in the past.
Any ideas or pointers to previous [hopefully optimal] solutions are
welcome!
Ben
--
;Ben Olasov ······@shadow.cs.columbia.edu
; ···@syska.com
In article <··········@hpscit.sc.hp.com>, Jens Kilian <·····@bbn.hp.com> wrote:
>> '((var1 '("A" "B" "C"))
>> (var2 '(123 234 345 456))
>> (var3 '(SYM1 SYM2 SYM3))
>> (var4 '('(* SYM1 5.0) '(/ SYM2 4.0) '(+ SYM2 SYM3))))
>
>Why do you use so many quotes? The first one would be sufficient.
<deletia>
>> ((= var4 (/ SYM2 4.0))
>> (princ "case 1.1.1.2"))
>> ((= var4 (+ SYM2 SYM3))
>> (princ "case 1.1.1.3"))
>> ((= var3 SYM2)
>Also, the test using "=" may not be what you really want; I suspect you should
>be using EQUAL.
I know - after I sent this off, I remembered I should have expected
this to get misunderstood - it's an invitation to misinterpretation
after all - the 'code' above was simply intended as
shorthand/pseudocode to convey a concept, not to compile.
Anyway, thanks for the idea - I'll try it out...
>Greetings,
>
> Jens.
Ben
--
;Ben Olasov ······@shadow.cs.columbia.edu
; ···@syska.com