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

Re: "(anon)" is not a useful pointer

On Mon, 11 Dec 2017 20:13:40 +0000
Daniel Shahaf <d.s@xxxxxxxxxxxxxxxxxx> wrote:
> P.S. "(anon):1" isn't helpful to the developer of f if f contains more
> than one anonymous function (either nested, f() { () { () { : } } }, or
> siblings, f() { () {:}; () {:}; }).  Ideas about that welcome. :)

(I moved this to zsh-workers.  No user-serviceable parts inside.)

If somebody wants to have a go at this (won't be me), it shouldn't be
too difficult.

One aproach is to make anonymous functions stick out in funcstack with a
flag as follows:

- Some form of creative marking in Shfunc structures for anonymous
functions.  We've spare space for PM_* flags for functions: many of the
existing ones are for variables and there is prior art for overlap
where functions and variables have distinct behaviour.

- The flag needs to be propagated to top level -- when we set scriptname
set a flag saying this is a bogus function name and you need to search
funcstack for a real one.  A set of bit flags would be more

- Then when we push stuff onto funcstack we push this flag as well
(again, same as what we do with scriptname which it's effectively

- Then when printing out an error message check if the current function
is anonymous using the new top-level flag and then scan funcstack using
the pushed version of the flag to scan back for the name of something
not marked as an anonymous function.

This mechanism could be extended in case of anything else which isn't
giving you a particularly useful name.

Fascinating exercise for someone.


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