Re: "ifthen" for more "dynamic" argv manipulation

From: Laurent Bercot <ska-skaware_at_skarnet.org>
Date: Tue, 24 May 2016 16:32:42 +0200

> ifthen { s6-test -n ${DISCARD_ENV} }
> {
> exec -c
> }
> prog1

  Ah, the lure of magic scoping.
  I know. I felt it too. If you want to experiment with it, try with the
undocumented -s option to ifthenelse: it's exactly what it does.

ifthenelse -s { testprog } { trueprog } { falseprog } args...
will execute trueprog args... if testprog returns true, and
falseprog args... otherwise. Your "ifthen" program is actually ifthenelse -s
with an empty false block.

  I kept the option around because it can be practical in some situations,
such as the one you're describing. However, it's undocumented for a reason:
I absolutely do not want to make that practice official in execline.

  The problem is that this kind of thing defeats a very important intuitive
expectation in execline: that nothing escapes a closing brace. Nothing inside
a block leaks outside of the block. And a little experience with writing and
reading execline has shown me that respecting this intuition was far more
important that the additional practicality of magic scoping. I believe you
will understand that with practice too.

  Besides, it's not that elegant - ifthenelse -s has to rewrite the argv,
which normally only happens with substitution commands. This is obviously
negligible as far as efficiency goes, but it's not as aesthetically pleasing
as you'd believe it is.

  Play around with ifthenelse -s if you want; use it. It's probably not
going away. But don't expect me to make it official, or to add commands
that follow the same pattern: not using that pattern is a voluntary design
decision.

-- 
  Laurent
Received on Tue May 24 2016 - 14:32:42 UTC

This archive was generated by hypermail 2.3.0 : Sun May 09 2021 - 19:38:49 UTC