AA default value?

Leandro Lucarella llucax at gmail.com
Fri Jan 25 07:15:27 PST 2008


Janice Caron, el 25 de enero a las 14:58 me escribiste:
> On 1/25/08, Ary Borenszweig <ary at esperanto.org.ar> wrote:
> > Janice Caron wrote:
> > > Wouldn't
> > > it be nicer if, instead, it simply returned
> > >
> > >       typeof(aa[key]).init
> > >
> > > if the key was not present in the array?
> >
> > But then you can't tell wheter the key was present and the value was
> > init, or it was not present at all.
> 
> If knowing that is important, you must use "in", as you always have
> done. I wasn't for one moment suggesting deprecating "in". However,
> there are plenty of circumstances where the distinction is
> unimportant.
> 
> Another approach would be to specify the default at the time you make
> the call (instead of relying on init). Of course, for that you'd need
> a new syntax - e.g.
> 
>     aa[key; defaultValue]
> or
>     aa[key ? defaultValue]
> or
>     aa[key else defaultValue]
> etc.

aa.get(key, defaultvalue) (a la python)?

I think your proposed syntax, well, besides being a new syntax =P, it's
not clear because is not the key which will be replaced for a default
value, the default value "else" clause should be outside the [] (if a new
syntax is wanted), which I think is hard to do.

-- 
Leandro Lucarella (luca) | Blog colectivo: http://www.mazziblog.com.ar/blog/
----------------------------------------------------------------------------
GPG Key: 5F5A8D05 (F8CD F9A7 BF00 5431 4145  104C 949E BFB6 5F5A 8D05)
----------------------------------------------------------------------------
HOMBRE DESNUDO AMENAZA A LOS VECINOS CON UNA "KATANA" DESDE SU BALCON
	-- Crónica TV



More information about the Digitalmars-d mailing list