From 4d31e2ed9bcf50495edd8bbb7a26ca622831b3c5 Mon Sep 17 00:00:00 2001 From: alex-eg Date: Wed, 14 Oct 2026 20:09:17 +0300 Subject: [PATCH] parenthesise a conditional without a helper to do it for --- sex-fmt-c.scm | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/sex-fmt-c.scm b/sex-fmt-c.scm index f07644e..4be8e0c 100644 --- a/sex-fmt-c.scm +++ b/sex-fmt-c.scm @@ -909,24 +909,23 @@ ;; It groups to the right, so its else arm is written at ;; `conditional-else', just looser: a chain there stays bare, ;; `a ? x : b ? y : z', and an assignment does not. - (define (c-if/expr . args) - (c-maybe-paren '? (apply c-if/expr/aux args))) - - (define (c-if/expr/aux c p . rest) - (let lp ((c c) (p p) (ls rest)) - (cond - ((or (eq? c 'else) (eq? c #t)) - (if (not (null? ls)) - (error "forms after else clause in IF" c p ls) - (c-expr p))) - ((pair? ls) - (cat (c-in-test (c-expr c)) " ? " (c-expr p) " : " - (c-with-op 'conditional-else - (if (pair? (cdr ls)) - (lp (car ls) (cadr ls) (cddr ls)) - (lp 'else (car ls) '()))))) - (else - (c-or (c-in-test (c-expr c)) (c-expr p)))))) + (define (c-if/expr c p . rest) + (c-maybe-paren + '? + (let lp ((c c) (p p) (ls rest)) + (cond + ((or (eq? c 'else) (eq? c #t)) + (if (not (null? ls)) + (error "forms after else clause in IF" c p ls) + (c-expr p))) + ((pair? ls) + (cat (c-in-test (c-expr c)) " ? " (c-expr p) " : " + (c-with-op 'conditional-else + (if (pair? (cdr ls)) + (lp (car ls) (cadr ls) (cddr ls)) + (lp 'else (car ls) '()))))) + (else + (c-or (c-in-test (c-expr c)) (c-expr p))))))) (define (c-if . args) (fmt-if fmt-expression?