Dune: evaluating an expression before printing its boolean value

In my dune file, I have a rule similar to this:

(rule
  (deps (universe))
  (targets "foo")
  (action (with-stdout-to "foo" (echo "a " (= 1 2) "\n")))
)

But the above does not parse (Error: Unexpected list).

I’d like to tell Dune to evaluate the expression (= 1 2) (resulting in false), then print it as a string (so the output would be a false\n).

Is it possible to do so?

No. Even though Dune uses s-exp syntax, the Dune language is not a general purpose language, and in particular, it does not evaluate subexpressions in arbitrary places. In this case, the argument of the echo action must be a literal string (possibly interpolated with variables).

You can read about the possible actions and their arguments at:

https://dune.readthedocs.io/en/latest/reference/actions.html

Cheers,
Nicolas

2 Likes