Add for-loop semantics

* geesh/shell.scm (sh:for): New public function.
* .dir-locals.el: Indent it nicely.
This commit is contained in:
Timothy Sample 2018-10-16 15:26:40 -04:00
parent 46ae7129d5
commit db56b1cc0a
2 changed files with 15 additions and 0 deletions

View File

@ -9,6 +9,7 @@
(eval . (put '<sh-with-redirects> 'scheme-indent-function 1))
(eval . (put 'call-with-backquoted-input-port 'scheme-indent-function 1))
(eval . (put 'make-script 'scheme-indent-function 1))
(eval . (put 'sh:for 'scheme-indent-function 2))
(eval . (put 'sh:subshell 'scheme-indent-function 1))
(eval . (put 'sh:substitute-command 'scheme-indent-function 1))
(eval . (put 'sh:with-redirects 'scheme-indent-function 2)))))

View File

@ -8,6 +8,7 @@
#:export (sh:and
sh:exec-let
sh:exec
sh:for
sh:not
sh:or
sh:pipeline
@ -294,3 +295,16 @@ run @var{thunk2}."
(if (string=? (var-ref* env "?") "0")
(set-var! env "?" "1")
(set-var! env "?" "0")))
;;; Loops.
(define (sh:for env bindings thunk)
"Run @var{thunk} for each binding in @var{bindings}. The value of
@var{bindings} have the form @code{(@var{name} (@var{value} ...))}."
(set-var! env "?" "0")
(match-let (((name (values ...)) bindings))
(for-each (lambda (value)
(set-var! env name value)
(thunk))
values)))