about summary refs log tree commit diff
diff options
context:
space:
mode:
authorArun Isaac2026-01-27 01:43:03 +0000
committerArun Isaac2026-01-27 01:48:20 +0000
commit039b396088d086335925c3add556d4b2afae2ae1 (patch)
treed13fbdc84be45211b478316bd13faf6e2528f521
parent7da2555b8b014a5801d15dc9bb1657274bd579e4 (diff)
downloadccwl-039b396088d086335925c3add556d4b2afae2ae1.tar.gz
ccwl-039b396088d086335925c3add556d4b2afae2ae1.tar.lz
ccwl-039b396088d086335925c3add556d4b2afae2ae1.zip
ccwl: Allow literals as arguments to workflows, not just commands.
-rw-r--r--ccwl/ccwl.scm37
-rw-r--r--tests/ccwl.scm12
2 files changed, 38 insertions, 11 deletions
diff --git a/ccwl/ccwl.scm b/ccwl/ccwl.scm
index 8f02b0c..0692786 100644
--- a/ccwl/ccwl.scm
+++ b/ccwl/ccwl.scm
@@ -1,5 +1,5 @@
 ;;; ccwl --- Concise Common Workflow Language
-;;; Copyright © 2021–2025 Arun Isaac <arunisaac@systemreboot.net>
+;;; Copyright © 2021–2026 Arun Isaac <arunisaac@systemreboot.net>
 ;;;
 ;;; This file is part of ccwl.
 ;;;
@@ -282,7 +282,7 @@ compared using @code{equal?}."
 (define-immutable-record-type <js-expression>
   (make-js-expression inputs expression outputs requirements other)
   js-expression?
-  (inputs js-expression-inputs)
+  (inputs js-expression-inputs set-js-expression-inputs)
   (expression js-expression-expression)
   (outputs js-expression-outputs)
   (requirements js-expression-requirements)
@@ -292,14 +292,14 @@ compared using @code{equal?}."
   (make-cwl-workflow file inputs outputs)
   cwl-workflow?
   (file cwl-workflow-file)
-  (inputs cwl-workflow-inputs)
+  (inputs cwl-workflow-inputs set-cwl-workflow-inputs)
   (outputs cwl-workflow-outputs))
 
 (define-immutable-record-type <workflow>
   (make-workflow steps inputs outputs other)
   workflow?
   (steps workflow-steps)
-  (inputs workflow-inputs)
+  (inputs workflow-inputs set-workflow-inputs)
   (outputs workflow-outputs)
   (other workflow-other))
 
@@ -653,6 +653,21 @@ identifiers defined in the commands."
     (else (error "Unrecognized ccwl function" function)))
    function))
 
+(define (set-function-inputs function inputs)
+  "Set inputs of @var{function} to @var{inputs}---a
+@code{<command>}, @code{<js-expression>}, @code{<cwl-workflow>} or
+@code{<workflow> object. @code{set-function-inputs} is purely
+functional. It returns a copy of @var{function}. @var{function} is not
+mutated."
+  ((cond
+    ((command? function) set-command-inputs)
+    ((js-expression? function) set-js-expression-inputs)
+    ((cwl-workflow? function) set-cwl-workflow-inputs)
+    ((workflow? function) set-workflow-inputs)
+    (else (error "Unrecognized ccwl function" function)))
+   function
+   inputs))
+
 (define (function-input-keys function)
   "Return the list of input keys accepted by FUNCTION, a <command>,
 <js-expression>, <cwl-workflow> or <workflow> object."
@@ -679,11 +694,11 @@ identifiers defined in the commands."
       ;; Global input/output
       (symbol->string (key-cwl-id key))))
 
-(define (apply-partially command partial-arguments)
-  "Return a new command that is a partial application of
-@var{partial-arguments} to @var{command}. @var{partial-arguments} is
+(define (apply-partially function partial-arguments)
+  "Return a new function that is a partial application of
+@var{partial-arguments} to @var{function}. @var{partial-arguments} is
 an association list mapping keyword arguments to their values."
-  (set-command-inputs command
+  (set-function-inputs function
     (map (lambda (input)
            (set-input-default input
              (or (any (match-lambda
@@ -693,7 +708,7 @@ an association list mapping keyword arguments to their values."
                               value)))
                       partial-arguments)
                  (input-default input))))
-         (command-inputs command))))
+         (function-inputs function))))
 
 (define (function-object x)
   "Return the ccwl function object (a <command>, <js-expression>,
@@ -890,7 +905,9 @@ represented by <step> objects."
                                                           input-keys)))))
                                           (pairify (syntax->datum #'(args ...))))))))
            ;; If literal values are provided as arguments, partially
-           ;; apply those literal values to the command and recurse.
+           ;; apply those literal values to the function object
+           ;; (command, workflow, js-expression, cwl-workflow) and
+           ;; recurse.
            (_
             (collect-steps #`(((module-ref (resolve-module '(ccwl ccwl))
                                            'apply-partially)
diff --git a/tests/ccwl.scm b/tests/ccwl.scm
index 4aa5801..85ec322 100644
--- a/tests/ccwl.scm
+++ b/tests/ccwl.scm
@@ -1,5 +1,5 @@
 ;;; ccwl --- Concise Common Workflow Language
-;;; Copyright © 2021–2025 Arun Isaac <arunisaac@systemreboot.net>
+;;; Copyright © 2021–2026 Arun Isaac <arunisaac@systemreboot.net>
 ;;;
 ;;; This file is part of ccwl.
 ;;;
@@ -187,6 +187,16 @@
   (workflow ()
     (print-int #:number 42)))
 
+;; TODO: Define this in the lexical scope of the test that requires
+;; it.
+(define print-workflow
+  (workflow ((message #:type string))
+    (print #:message message)))
+
+(test-assert "allow literals as arguments to workflows"
+  (workflow ()
+    (print-workflow #:message "foo")))
+
 (test-condition "step supplied with an unknown key must raise a &ccwl-violation condition"
   ccwl-violation?
   (macroexpand