case

Started by kesha, December 04, 2012, 01:17:58 PM

Previous topic - Next topic

kesha

Hi All,

how can perform multiple checks.

(define (test-case KEY)
  (case KEY
    (0 (begin (println "KEY => " KEY)(test-case (++ KEY))))
    (1 (begin (println "KEY => " KEY)(test-case (++ KEY))))
    (2 (begin (println "KEY => " KEY)(test-case (++ KEY))))
    (3 (begin (println "KEY => " KEY)(test-case (++ KEY))))
    (4 (begin (println "KEY => " KEY)(test-case (++ KEY))))
    (5 (begin (println "KEY => " KEY)(test-case (++ KEY))))
    (6 (begin (println "KEY => " KEY)(test-case (++ KEY))))
    (7 (begin (println "KEY => " KEY)(test-case (++ KEY))))
    (8 (begin (println "KEY => " KEY)(test-case (++ KEY))))
    (9 (begin (println "KEY => " KEY)(test-case (++ KEY))))
    (true (println "END CASE..."))))

cormullion

#1
Perhaps you explain what you want to do a bit more?



The most flexible and readable form for condition testing is probably cond.

kesha

#2
It's just food for thought on the use of recursion.

If refined, could get interesting.

For example:

#!/usr/bin/env newlisp                                                                    

(define (test-case KEY)
  (case KEY
    (0 (begin (println "KEY => " KEY)(test-case (++ KEY))))
    (1 (begin (println "KEY => " KEY)(test-case (++ KEY))))
    (2 (begin (println "KEY => " KEY)(test-case (++ KEY))))
    (3 (begin (println "KEY => " KEY)(test-case (++ KEY))))
    (true (println "END CASE..."))))

(test-case 0)

(exit)
; eof

-------------------------------------------------------------

KEY => 0
KEY => 1
KEY => 2
KEY => 3
END CASE...