Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: PATCH: functions with redirections



On 29 September 2014 23:37, Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
> On Sep 29, 2014 1:53 PM, "Bart Schaefer" <schaefer@xxxxxxxxxxxxxxxx> wrote:
>>
>>
>> On Sep 29, 2014 12:52 PM, "Peter Stephenson" <p.w.stephenson@xxxxxxxxxxxx>
> wrote:
>> >
>> > I haven't yet looked at dump files.  That's partly becuase I don't
>> > understand them and partly because I don't use them.  Any hints would be
>> > great.
>>
>> By dump files do you mean zcompile?
>> I fear I'm not of much help there.
>
> A thought:
>
> My first idea when this came up was to alter the wordcode for functions
> with redirections to explicitly add the implicit set of braces, e.g.,
>
> foo () { echo foo } >&3
>
> becomes
>
> foo () { { echo foo } >&3 }
>
> Then it would not be necessary to mess with printing/dumping etc. of the
> definition, or invent a new place to store the redirections.  Yeah, output
> of "functions" et al. becomes a little less faithful but so what?
>
> Sadly I never managed to make that work, but maybe the concept is helpful
> for dump file creation.

I noticed that the contents of $functions[foo] in the former case
completely omits the redirection as it is currently. An argument for
turning the syntax into the latter is that you could claim it wasn't a
function definition of the form foo() { ... } in the first place, but
a foo() ... definition, where ... happens to be { xyz } > &3 which is
also a valid single statement command, printing the function in a
normalized form would then tack on the outer braces as usual. I don't
know if this would hold up in court though.

-- 
Mikael Magnusson



Messages sorted by: Reverse Date, Date, Thread, Author