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

Re: Bug with unset variables



Felipe Contreras wrote on Fri, 27 Nov 2020 20:49 +00:00:
> On Fri, Nov 27, 2020 at 9:44 AM Daniel Shahaf <d.s@xxxxxxxxxxxxxxxxxx> wrote:
> >
> > Felipe Contreras wrote on Wed, Nov 25, 2020 at 02:46:40 -0600:
> > > Maybe there's a better way to describe this fact. Maybe Git's notion
> > > of logically separate changes [1] helps (e.g. you should not mix
> > > whitespace cleanups with functional changes). But the fact is that in
> > > virtually all languages (and bash and ksh) there's an idiom to declare
> > > a local variable and *only* declare a local variable (not do anything
> > > else).
> > >
> > > Can we at least agree on that? In zsh typeset does *two* things.
> >
> > I'd rather say that «typeset» does one thing — it ${verb}s a variable
> > (for some value of $verb) — and the zsh data model doesn't feature
> > a "Not really a value" value, so the variable necessarily gets _some_
> > value, like «int foo;» in C.
> 
> If it's really one thing, then why does adding it in the example above
> changes the behavior in *two* ways?

What two ways?

>   func () {
>     [[ -n "$1" ]] && var=$1
>     dosomething ${var-other}
>   }
> 
>   func () {
>     typeset var
>     [[ -n "$1" ]] && var=$1
>     dosomething ${var-other}
>   }
> 
> -- 
> Felipe Contreras
>




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