Case

Another conditional expression is case which uses memv to compare lists of values and run a corresponding expression.

Each clause takes the form ((v ...) expr ...) that is a C-style switch like:

bool result;

switch (c) {
case 'a':
case 'e':
case 'i':
case 'o':
case 'u':
    result = 1;
    break;
default:
    result = 0;
    break;
}

transforms into:

simple-case.idio
define (vowel? c) {

  (case
   c
   ((#\a #\e #\i #\o #\u) #t)
   (else #f))
}

for c in "hello" {
  printf "vowel? %s: %s\n" c (vowel? c)
}
$ idio simple-case
vowel? h: #f
vowel? e: #t
vowel? l: #f
vowel? l: #f
vowel? o: #t

Last built at 2024-11-21T07:11:43Z+0000 from 77077af (dev) for Idio 0.3