On 24/02/10 00:50, Markus Roberts wrote:
> A few more thoughts/questions and a potential option:
>
> * Should hash assignments be by reference or by value? In other words, what
> should this do:
>
> $h1 = { a => b }
> $h2 = $h1
> :
> $h2[x] = y
> notice $h1
>
> Should the hash in $h2 be a copy of the hash in $h1, or are they the same
> object?
I would say a reference if they are in the same scope. A new copy if
used in another scope.
> * Is array really the right consistency model? For example, one might argue
> that $h should be {content=>bar, mode=>0777} throughout the following:
>
> class c0 {
> file {'/tmp/foo': content => 'bar' }
> $h = { contents => bar}
> }
>
> class c1 inherits c0 {
> notice "2: h = $h"
> File['/tmp/foo'] { mode => 0777 }
> $h += { mode => 0777 }
> notice "3: h = $h"
> }
>
> notice "1: h = $h"
> include c1
> notice "4: h = $h"
I'm trying to find an use case for this, but I must admit I'm not sure
to find one.
> -----------------------------------------------------------------------------------------------------------------------
> To get concrete, what do you think of the following semantics:
>
> * $h1 in the first example above would be distinct from $h2 (assignment is a
> copy).
Hmm, why?
Or is it to mimic how we deal with arrays?
> * The value of a hash is the same at all points in all scopes in which the
> hash can be seen, and reflects all contributions.
I'm really not sure about this.
> * h += { k1 => v1, k2 => v2...} is syntactic sugar for h[k1]=v1; h[k2]=v2;
> ...
Yes.
> * Any number of h[kx] =... assignments are allowed each scope, but only one
> per key globally
Yes, I concur.
> * Hash keys are constrained in some way:
> * they must be literal strings
> * or they may not depend on values from a hash
> * or they may not depend on values in the same hash
That indeed makes sense. Does that also means we can use any rvalue in
an hash value acces (ie $h[<rvalue>])?
My view on all this would be to be quite restrictive on the scope thing
at first. If we find that it is to restrictive (ie it becomes impossible
to actually use hash for anything), we could then decide to relax the
scoping.
--
Brice Figureau
My Blog: http://www.masterzen.fr/
--
You received this message because you are subscribed to the Google Groups
"Puppet Developers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/puppet-dev?hl=en.