Deutsch   English   Français   Italiano  
<20250506192051.695@kylheku.com>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: news.eternal-september.org!eternal-september.org!.POSTED!not-for-mail
From: Kaz Kylheku <643-408-1753@kylheku.com>
Newsgroups: comp.unix.shell
Subject: Re: Create functional processing pipe (without eval)?
Date: Wed, 7 May 2025 02:25:15 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 35
Message-ID: <20250506192051.695@kylheku.com>
References: <vveev6$dll3$1@dont-email.me>
Injection-Date: Wed, 07 May 2025 04:25:19 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="5ac29be9ebf3c71ecf2eea007f6e0586";
	logging-data="476013"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX1/zm51hMpCziLNo8FJ9wOQeaJxQFsefag4="
User-Agent: slrn/pre1.0.4-9 (Linux)
Cancel-Lock: sha1:/uMnmok9mpHtrYl3CeYpxQU/rEo=

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/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca