diff options
author | Mathieu Lirzin <mthl@gnu.org> | 2016-04-20 02:53:22 +0200 |
---|---|---|
committer | Mathieu Lirzin <mthl@gnu.org> | 2016-05-07 23:38:53 +0200 |
commit | 5da0024b934513aa76a2cb32dc8f6cb00370262a (patch) | |
tree | 3180cd37a760917d12addcc932329b9fffe272fc /scm/mcron/job-specifier.scm | |
parent | ce0d72ec8319a6a67d3fc4cb8a855ed75d18d514 (diff) | |
download | mcron-5da0024b934513aa76a2cb32dc8f6cb00370262a.tar.gz mcron-5da0024b934513aa76a2cb32dc8f6cb00370262a.tar.bz2 mcron-5da0024b934513aa76a2cb32dc8f6cb00370262a.zip |
job-specifier: Rewrite 'range' procedure.
* scm/mcron/job-specifier.scm (range): Use 'unfold'.
Diffstat (limited to 'scm/mcron/job-specifier.scm')
-rw-r--r-- | scm/mcron/job-specifier.scm | 25 |
1 files changed, 8 insertions, 17 deletions
diff --git a/scm/mcron/job-specifier.scm b/scm/mcron/job-specifier.scm index 1647ede..3f73b82 100644 --- a/scm/mcron/job-specifier.scm +++ b/scm/mcron/job-specifier.scm @@ -1,4 +1,5 @@ ;; Copyright (C) 2003 Dale Mellor +;; Copyright (C) 2016 Mathieu Lirzin ;; ;; This file is part of GNU mcron. ;; @@ -37,26 +38,16 @@ #:use-module (mcron core) #:use-module (mcron environment) #:use-module (mcron vixie-time) + #:use-module (srfi srfi-1) + #:use-module (srfi srfi-26) #:re-export (append-environment-mods)) - -;; Function (available to user configuration files) which produces a list of -;; values from start up to (but not including) end. An optional step may be -;; supplied, and (if positive) only every step'th value will go into the -;; list. For example, (range 1 6 2) returns '(1 3 5). - -(define (range start end . step) - (let ((step (if (or (null? step) - (<= (car step) 0)) - 1 - (car step)))) - (let loop ((start start)) - (if (>= start end) '() - (cons start - (loop (+ start step))))))) - - +(define* (range start end #:optional (step 1)) + "Produces a list of values from START up to (but not including) END. An +optional STEP may be supplied, and (if positive) only every step'th value will +go into the list. For example, (range 1 6 2) returns '(1 3 5)." + (unfold (cut >= <> end) identity (cute + <> (max step 1)) start)) ;; Internal function (not supposed to be used directly in configuration files; ;; it is exported from the module for the convenience of other parts of the |