diff --git a/libguile/ChangeLog b/libguile/ChangeLog index 90dec9bb1..746842857 100644 --- a/libguile/ChangeLog +++ b/libguile/ChangeLog @@ -1,3 +1,7 @@ +2003-10-11 Dirk Herrmann + + * eval.c (scm_m_case): Allow empty lists of case labels. + 2003-10-11 Dirk Herrmann * tags.h (SCM_IM_ELSE, SCM_IM_ARROW): New memoizer codes. diff --git a/libguile/eval.c b/libguile/eval.c index 25f435468..ba3972043 100644 --- a/libguile/eval.c +++ b/libguile/eval.c @@ -741,6 +741,13 @@ scm_m_case (SCM expr, SCM env) s_bad_case_labels, labels, expr); all_labels = scm_append_x (scm_list_2 (labels, all_labels)); } + else if (SCM_NULLP (labels)) + { + /* The list of labels is empty. According to R5RS this is allowed. + * It means that the sequence of expressions will never be executed. + * Therefore, as an optimization, we could remove the whole + * clause. */ + } else { ASSERT_SYNTAX_2 (SCM_EQ_P (labels, scm_sym_else) && else_literal_p, diff --git a/test-suite/ChangeLog b/test-suite/ChangeLog index d5f6646d0..17b5d572c 100644 --- a/test-suite/ChangeLog +++ b/test-suite/ChangeLog @@ -1,3 +1,8 @@ +2003-10-11 Dirk Herrmann + + * tests/syntax.test: Fixed and activated test of empty case label + support. + 2003-10-11 Dirk Herrmann * tests/syntax.test (exception:bad-expression, diff --git a/test-suite/tests/syntax.test b/test-suite/tests/syntax.test index 20e9a44a5..c46d615df 100644 --- a/test-suite/tests/syntax.test +++ b/test-suite/tests/syntax.test @@ -509,6 +509,9 @@ (with-test-prefix "case" + (pass-if "clause with empty labels list" + (case 1 (() #f) (else #t))) + (with-test-prefix "case is hygienic" (pass-if-exception "bound 'else is handled correctly" @@ -558,11 +561,6 @@ (eval '(case 1 ("foo" "bar")) (interaction-environment))) - ;; According to R5RS, the following one is syntactically correct. - ;; (pass-if-exception "(case 1 (() \"bar\"))" - ;; exception:bad/missing-clauses - ;; (case 1 (() "bar"))) - (pass-if-exception "(case 1 ((2) \"bar\") . \"foo\")" exception:bad-expression (eval '(case 1 ((2) "bar") . "foo")