diff --git a/beautiful-racket-demo/basic-demo-3/expr.rkt b/beautiful-racket-demo/basic-demo-3/expr.rkt index 207a27f..db5108a 100644 --- a/beautiful-racket-demo/basic-demo-3/expr.rkt +++ b/beautiful-racket-demo/basic-demo-3/expr.rkt @@ -30,14 +30,16 @@ (define-macro (b-func FUNC-ID ARG ...) #'(if (procedure? FUNC-ID) - (let ([result (FUNC-ID ARG ...)]) - (cond - [(number? result) (b-expr result)] - [(string? result) result] - [(boolean? result) (if result 1 0)] - [else - (raise-line-error - (format "unknown data type: ~v" result))])) + (convert-result (FUNC-ID ARG ...)) (raise-line-error (format "expected ~a to be a function, got ~v" 'FUNC-ID FUNC-ID)))) + +(define (convert-result result) + (cond + [(number? result) (b-expr result)] + [(string? result) result] + [(boolean? result) (if result 1 0)] + [else + (raise-line-error + (format "unknown data type: ~v" result))])) \ No newline at end of file