Sujet : Re: Create functional processing pipe (without eval)?
De : 643-408-1753 (at) *nospam* kylheku.com (Kaz Kylheku)
Groupes : comp.unix.shellDate : 07. May 2025, 03:25:15
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <20250506192051.695@kylheku.com>
References : 1
User-Agent : slrn/pre1.0.4-9 (Linux)
On 2025-05-07, Janis Papanagnou <janis_papanagnou+
ng@hotmail.com> wrote:
I'm pondering about creating a functional processing pipe, depending
on program parameters, and whether that's possible to achieve without
using 'eval'.
>
Say, the program is called "filter" and may accept 0..N parameters and
depending on the set of parameters the respective pipe functionality
shall be defined like
>
filter => cat
filter p1 => cat | func p1
filter p1 p2 => cat | func p1 | func p2
filter p1 p2 ... pN => cat | func p1 | func p2 | ... | func pN
>
where "func" is working as filter and accepts exactly one parameter.
The problem is that the number of pipes on the right hand side
depends on the number of arguments.
The number of pipes in a command pipe is a property of syntax;
it is something that needs eval.
If you're interested in being able to make this kind of code
transformation, perhaps you should start a project to add macros to a
shell. (An educated guess informs me that you'd likely choose Korn).
Macros avoid extra eval by taking advantage of the result of the
substitution being "naturally thrown into the path of the evaluator",
just like any other code that is not expanded by a macro.
-- TXR Programming Language: http://nongnu.org/txrCygnal: Cygwin Native Application Library: http://kylheku.com/cygnalMastodon: @Kazinator@mstdn.ca