On 2013-01-07 9:49, Simon Marechal wrote:
Hello !

On Friday, June 28, 2013 6:16:42 PM UTC+2, Andy Parker wrote:


    I'm taking this to mean that you find that iteration constructs and
    new structures move the language away from simplicity and their
    utility does not offset that loss of simplicity. Is that right?


I already posted on this subject, but I guess my post made no sense at
all :) I do like the explicit support for loop-like logic, but I believe
the ruby-mimicking is not a great idea. Each (also known as foreach) and
collect are basically the same thing : they let you write arbitrary
statements in the loop and both return something, meaning they can both
be used in "rvalues" or "statement" context. I believe this violates
http://docs.puppetlabs.com/puppet/3/reference/lang_functions.html#behavior.
I didn't test this for the other functions, but I believe they act the
same. "Each" should not return anything (which would result in an error
when compiling catalogs), and collect should only accept expressions in
its body.

each returns the LHS - e.g.

puppet apply --parser future -e
'[1,2,3].each |$x| {$x + 10}.each |$x| { notice $x}'
Notice: Scope(Class[main]): 1
Notice: Scope(Class[main]): 2
Notice: Scope(Class[main]): 3

each/foreach and collect are not the same thing - each produces the input, and collect produces the transformed input

[1,2,3].collect |$x| {$x + 10}.each |$x| {notice $x}
Notice: Scope(Class[main]): 11
Notice: Scope(Class[main]): 12
Notice: Scope(Class[main]): 13


The semantics of function is changed in future parser; it is always ok to call a function that produces a value even if the value is not consumed. When the documentation is updated it will no longer be in "violation" ;-)

In fact, it would be good to get rid of the distinction between expression and statement all together.

Also I am unsure of the value of "slice", "reduce" and "reject", but
this is just a matter of personal taste.


reduce = produce one value given a collection; an aggregate, the "best" (min, max, or something else), etc.
slice = of value when input is flat but has semantic structure
reject = same value as having both if and unless in the language

I would say that these are of value when dealing with messy data. If you are in charge of all aspects of the system (including the structure if all data) then these are naturally of less value simply because there is no need to do more advanced data transformations.

Regards
- henrik


--
You received this message because you are subscribed to the Google Groups "Puppet 
Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/puppet-dev.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to