From 1eabc563ca5692b3e08d84f1f0e6fd2283284469 Mon Sep 17 00:00:00 2001 From: Dmitry Bogatov Date: Fri, 27 Feb 2015 09:27:35 +0300 Subject: [PATCH] Enable using of #[expr] syntax in conditionals --- lisp/gnu/bash.scm | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/lisp/gnu/bash.scm b/lisp/gnu/bash.scm index 8a14304..199ebc0 100644 --- a/lisp/gnu/bash.scm +++ b/lisp/gnu/bash.scm @@ -22,7 +22,10 @@ ;;; Code: (define-module (gnu bash) - #:export ((bash-eval . eval))) + #:export ((bash-eval . eval)) + #:replace ((e-if . if)) + #:replace ((e-when . when)) + #:replace ((e-unless . unless))) (use-modules (system foreign)) (use-modules (system ffi)) (use-modules (ice-9 match)) @@ -245,11 +248,18 @@ (define (eval-args args) (define eval-str (args->eval-string args)) - (define value (bash-eval eval-str)) - (when (and (not (zero? (last-command-exit-value))) - (exception-on-error)) + (define result (zero? (bash-eval eval-str))) + (when (and (not result) (exception-on-error)) (error 'bash-command-error eval-str (last-command-exit-value))) - value) + result) + +(define-syntax-rule (e-if test then else) + (if (parameterize ((exception-on-error #f)) test) then else)) +(define-syntax-rule (e-when test stmt stmt* ...) + (when (parameterize ((exception-on-error #f)) test) stmt stmt* ...)) + +(define-syntax-rule (e-unless test stmt stmt* ...) + (unless (parameterize ((exception-on-error #f)) test) stmt stmt* ...)) (define (capture-output args) (define eval-str (args->eval-string args)) -- 2.11.4.GIT