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

Re: Higher order functions in zsh (article link)



Phil Pennock wrote:
> Why does this code have an eval in there?  It's:

I suspect that the eval was there to allow the command to include
arguments: e.g. map 'print -l' *
Using $=func_name will add word-splitting to get that back without
reintroducing the security flaw.

> Oh, and you need to quote the $@ to "$@" if you want to preserve empty
> elements -- whether you do or not depends on what you're mapping across,
> but I tend to think "present but empty" is distinct from "not present".

Actually "$@" is the default for a for loop so you don't need it. And I
can't see that the use of print and command-substitution gets you
anything unless I'm missing something. So:

function map {
    local func_name=$1 elem
    shift
    for elem; $=func_name "${elem}"        
} 

This is unrelated but it seems the warncreateglobal option does't warn
about variables created using a for loop. Does anyone know if that is
intentional or a bug?

Oliver



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