Jira (PUP-3978) Missing values for optional parameters places block at wrong position

2015-02-10 Thread Henrik Lindberg (JIRA)
Title: Message Title
 
 
 
 
 
 
 
 
 
 
  
 
 Henrik Lindberg commented on  PUP-3978 
 
 
 
 
 
 
 
 
 
 


 
 
 
 
 
 
  Re: Missing values for optional parameters places block at wrong position  
 
 
 
 
 
 
 
 
 
 
Again our old friend Ruby 1.8.7 gives us surprises. The solution does not work there because ruby recreates the Proc rather than passing it by reference. This means that information is lost. Since we want to have the same API on 3.7.x and 4.0.0 we needed to come up with a solution for Ruby 1.8.7. 
The problem is that when a Proc is used to carry information, it has no access to detailed information about the closure since the information about arity and parameters is derived from the puppet evaluator closure. All we have in Ruby 1.8.7 is the arity, and this arity is hardcoded into how Proc works.  
In practice, it is (currently) only the slice function that introspects the arity of the block. If users write 4x functions that need this, they need to be aware of the differences between Proc in Ruby 1.8 and later (where Proc has richer support - it has correct arity and knows the names of the parameters, and we can return the puppet evaluator closure). 
The caveat for Ruby 1.8.7 implementations seems like a reasonable trade off as the alternatives are that the API is radically different between 3x with future parser and 4.0.0 when it comes to calling and introspecting code blocks. Now there is only a small difference motivated by the difference in ruby itself. 
 

Users of functions naturally does not see the change at all
 

Implementors of functions should change to using yield and implict blocks if they have written functions accepting blocks. (ping Charlie Sharpsteen, Erik Daln) 
 

this has better performance
 

it easier to write tests since a ruby block can be given instead of a Puppet evaluator closure (and those are somewhat elaborate to create in tests).
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

 
 Add Comment 
 
 
 
 
 
 
 
 
 
 


 
 

Jira (PUP-3978) Missing values for optional parameters places block at wrong position

2015-02-10 Thread Henrik Lindberg (JIRA)
Title: Message Title
 
 
 
 
 
 
 
 
 
 
  
 
 Henrik Lindberg commented on  PUP-3978 
 
 
 
 
 
 
 
 
 
 


 
 
 
 
 
 
  Re: Missing values for optional parameters places block at wrong position  
 
 
 
 
 
 
 
 
 
 
Merged to stable at: 147f621 
 
 
 
 
 
 
 
 
 
 
 
 

 
 Add Comment 
 
 
 
 
 
 
 
 
 
 


 
 
 
 
 
 
 
 
 

 This message was sent by Atlassian JIRA (v6.3.10#6340-sha1:7ea293a) 
 
 
 
 
  
 
 
 
 
 
 
 
 
   





-- 
You received this message because you are subscribed to the Google Groups Puppet Bugs group.
To unsubscribe from this group and stop receiving emails from it, send an email to puppet-bugs+unsubscr...@googlegroups.com.
To post to this group, send email to puppet-bugs@googlegroups.com.
Visit this group at http://groups.google.com/group/puppet-bugs.
For more options, visit https://groups.google.com/d/optout.


Jira (PUP-3978) Missing values for optional parameters places block at wrong position

2015-02-10 Thread Henrik Lindberg (JIRA)
Title: Message Title
 
 
 
 
 
 
 
 
 
 
  
 
 Henrik Lindberg commented on  PUP-3978 
 
 
 
 
 
 
 
 
 
 


 
 
 
 
 
 
  Re: Missing values for optional parameters places block at wrong position  
 
 
 
 
 
 
 
 
 
 
And merged to master at cf3ffdfb9ca5bab5e770d49c9284994ada1209ec with the Ruby 1.8.7 uglifications removed. 
 
 
 
 
 
 
 
 
 
 
 
 

 
 Add Comment 
 
 
 
 
 
 
 
 
 
 


 
 
 
 
 
 
 
 
 

 This message was sent by Atlassian JIRA (v6.3.10#6340-sha1:7ea293a) 
 
 
 
 
  
 
 
 
 
 
 
 
 
   





-- 
You received this message because you are subscribed to the Google Groups Puppet Bugs group.
To unsubscribe from this group and stop receiving emails from it, send an email to puppet-bugs+unsubscr...@googlegroups.com.
To post to this group, send email to puppet-bugs@googlegroups.com.
Visit this group at http://groups.google.com/group/puppet-bugs.
For more options, visit https://groups.google.com/d/optout.


Jira (PUP-3978) Missing values for optional parameters places block at wrong position

2015-02-10 Thread Henrik Lindberg (JIRA)
Title: Message Title
 
 
 
 
 
 
 
 
 
 
  
 
 Henrik Lindberg commented on  PUP-3978 
 
 
 
 
 
 
 
 
 
 


 
 
 
 
 
 
  Re: Missing values for optional parameters places block at wrong position  
 
 
 
 
 
 
 
 
 
 
I will update the specification of the 4x function api 
 
 
 
 
 
 
 
 
 
 
 
 

 
 Add Comment 
 
 
 
 
 
 
 
 
 
 


 
 
 
 
 
 
 
 
 

 This message was sent by Atlassian JIRA (v6.3.10#6340-sha1:7ea293a) 
 
 
 
 
  
 
 
 
 
 
 
 
 
   





-- 
You received this message because you are subscribed to the Google Groups Puppet Bugs group.
To unsubscribe from this group and stop receiving emails from it, send an email to puppet-bugs+unsubscr...@googlegroups.com.
To post to this group, send email to puppet-bugs@googlegroups.com.
Visit this group at http://groups.google.com/group/puppet-bugs.
For more options, visit https://groups.google.com/d/optout.


Jira (PUP-3978) Missing values for optional parameters places block at wrong position

2015-02-10 Thread Henrik Lindberg (JIRA)
Title: Message Title
 
 
 
 
 
 
 
 
 
 
  
 
 Henrik Lindberg updated an issue 
 
 
 
 
 
 
 
 
 
 


 
 
 
 
 
 
 Puppet /  PUP-3978 
 
 
 
  Missing values for optional parameters places block at wrong position  
 
 
 
 
 
 
 
 
 

Change By:
 
 Henrik Lindberg 
 
 
 

Story Points:
 
 1 2 
 
 
 
 
 
 
 
 
 
 
 
 

 
 Add Comment 
 
 
 
 
 
 
 
 
 
 


 
 
 
 
 
 
 
 
 

 This message was sent by Atlassian JIRA (v6.3.10#6340-sha1:7ea293a) 
 
 
 
 
  
 
 
 
 
 
 
 
 
   





-- 
You received this message because you are subscribed to the Google Groups Puppet Bugs group.
To unsubscribe from this group and stop receiving emails from it, send an email to puppet-bugs+unsubscr...@googlegroups.com.
To post to this group, send email to puppet-bugs@googlegroups.com.
Visit this group at http://groups.google.com/group/puppet-bugs.
For more options, visit https://groups.google.com/d/optout.


Jira (PUP-3978) Missing values for optional parameters places block at wrong position

2015-02-10 Thread Henrik Lindberg (JIRA)
Title: Message Title
 
 
 
 
 
 
 
 
 
 
  
 
 Henrik Lindberg assigned an issue to Henrik Lindberg 
 
 
 
 
 
 
 
 
 
 


 
 
 
 
 
 
 Puppet /  PUP-3978 
 
 
 
  Missing values for optional parameters places block at wrong position  
 
 
 
 
 
 
 
 
 

Change By:
 
 Henrik Lindberg 
 
 
 

Assignee:
 
 HenrikLindberg 
 
 
 
 
 
 
 
 
 
 
 
 

 
 Add Comment 
 
 
 
 
 
 
 
 
 
 


 
 
 
 
 
 
 
 
 

 This message was sent by Atlassian JIRA (v6.3.10#6340-sha1:7ea293a) 
 
 
 
 
  
 
 
 
 
 
 
 
 
   





-- 
You received this message because you are subscribed to the Google Groups Puppet Bugs group.
To unsubscribe from this group and stop receiving emails from it, send an email to puppet-bugs+unsubscr...@googlegroups.com.
To post to this group, send email to puppet-bugs@googlegroups.com.
Visit this group at http://groups.google.com/group/puppet-bugs.
For more options, visit https://groups.google.com/d/optout.


Jira (PUP-3978) Missing values for optional parameters places block at wrong position

2015-02-09 Thread Henrik Lindberg (JIRA)
Title: Message Title
 
 
 
 
 
 
 
 
 
 
  
 
 Henrik Lindberg commented on  PUP-3978 
 
 
 
 
 
 
 
 
 
 


 
 
 
 
 
 
  Re: Missing values for optional parameters places block at wrong position  
 
 
 
 
 
 
 
 
 
 
Looks great - a couple of small things: 
 

attr_accessor for :closure should be attr_reader as we do not want it to be settable except from the constructor
 

call_function must be changed to accept a Proc instead of being given a puppet block as an argument
 

We should create the PuppetProc in the evaluator (at the origin of the call chain) to avoid having to wrap/unwrap if one puppet function calls another
 
 
It is currently possible to pass a block to a 3x function via call_function since it is a regular argument. Don't think we need to support that. In case someone has a 3x function written for future parser, they should migrate it to the 4x API. 
 
 
 
 
 
 
 
 
 
 
 
 

 
 Add Comment 
 
 
 
 
 
 
 
 
 
 


 
 
 
 
 
 
 
 
 

 This message was sent by Atlassian JIRA (v6.3.10#6340-sha1:7ea293a) 
 
 
 
 
  
 
 
 
 
 
 
 
 
   





-- 
You received this message because you are subscribed to the Google Groups Puppet Bugs group.
To unsubscribe from this group and stop receiving emails from it, send an email to puppet-bugs+unsubscr...@googlegroups.com.
To post to this group, send email to puppet-bugs@googlegroups.com.
Visit this group at http://groups.google.com/group/puppet-bugs.
For more options, visit https://groups.google.com/d/optout.


Jira (PUP-3978) Missing values for optional parameters places block at wrong position

2015-02-09 Thread Thomas Hallgren (JIRA)
Title: Message Title
 
 
 
 
 
 
 
 
 
 
  
 
 Thomas Hallgren updated an issue 
 
 
 
 
 
 
 
 
 
 


 
 
 
 
 
 
 Puppet /  PUP-3978 
 
 
 
  Missing values for optional parameters places block at wrong position  
 
 
 
 
 
 
 
 
 

Change By:
 
 Thomas Hallgren 
 
 
 

Scrum Team:
 
 Language 
 
 
 
 
 
 
 
 
 
 
 
 

 
 Add Comment 
 
 
 
 
 
 
 
 
 
 


 
 
 
 
 
 
 
 
 

 This message was sent by Atlassian JIRA (v6.3.10#6340-sha1:7ea293a) 
 
 
 
 
  
 
 
 
 
 
 
 
 
   





-- 
You received this message because you are subscribed to the Google Groups Puppet Bugs group.
To unsubscribe from this group and stop receiving emails from it, send an email to puppet-bugs+unsubscr...@googlegroups.com.
To post to this group, send email to puppet-bugs@googlegroups.com.
Visit this group at http://groups.google.com/group/puppet-bugs.
For more options, visit https://groups.google.com/d/optout.


Jira (PUP-3978) Missing values for optional parameters places block at wrong position

2015-02-09 Thread Henrik Lindberg (JIRA)
Title: Message Title
 
 
 
 
 
 
 
 
 
 
  
 
 Henrik Lindberg commented on  PUP-3978 
 
 
 
 
 
 
 
 
 
 


 
 
 
 
 
 
  Re: Missing values for optional parameters places block at wrong position  
 
 
 
 
 
 
 
 
 
 
We chatted about the arg_count and last_captures_rest way of defining required, optional and splatted parameters and that we really would like to have indivdual methods to deal with these - e.g. param, optional_param, and splatted_param since that is clearer. This can however be introduced during the 4x series and we can then deprecate the current way of specifying these options while maintaining compatibility. We should fix these at the earliest opportunity - e.g. 4.1.0 and 3.7.6 (unless we actually do actually find some extra time before the 4.0.0 release). 
 
 
 
 
 
 
 
 
 
 
 
 

 
 Add Comment 
 
 
 
 
 
 
 
 
 
 


 
 
 
 
 
 
 
 
 

 This message was sent by Atlassian JIRA (v6.3.10#6340-sha1:7ea293a) 
 
 
 
 
  
 
 
 
 
 
 
 
 
   





-- 
You received this message because you are subscribed to the Google Groups Puppet Bugs group.
To unsubscribe from this group and stop receiving emails from it, send an email to puppet-bugs+unsubscr...@googlegroups.com.
To post to this group, send email to puppet-bugs@googlegroups.com.
Visit this group at http://groups.google.com/group/puppet-bugs.
For more options, visit https://groups.google.com/d/optout.


Jira (PUP-3978) Missing values for optional parameters places block at wrong position

2015-02-09 Thread Thomas Hallgren (JIRA)
Title: Message Title
 
 
 
 
 
 
 
 
 
 
  
 
 Thomas Hallgren commented on  PUP-3978 
 
 
 
 
 
 
 
 
 
 


 
 
 
 
 
 
  Re: Missing values for optional parameters places block at wrong position  
 
 
 
 
 
 
 
 
 
 
I now have a PuppetProc based solution that seems to work very well. It's a little different from what you suggested Henrik Lindberg in that user never needs to know about nor call on PuppetProc. 
Using yield should be the preferred method but it is always possible to instead declare the last argument as block. This is indifferent to the caller will also yield the same result when calling block_given?. Access to the block enables it to be passed on or examined (check its arity for instance). Advanced usage may also include checking the closure property of the block if we decide to make that part of the public API. 
Using yield semantics and Proc.new to get the block is of course still possible but a Proc.new will always result in a proc that has arity == -1. 
Here's the current implementation of PuppetProc 
 
 
 
 
 
 
class Puppet::Pops::Evaluator::PuppetProc  Proc 
 
 
 
 
  def self.new(closure, block) 
 
 
 
 
proc = super(block) 
 
 
 
 
proc.closure = closure 
 
 
 
 
proc 
 
 
 
 
  end 
 
 
 
 
 
 
 
 
 
  attr_accessor :closure 
 
 
  

Jira (PUP-3978) Missing values for optional parameters places block at wrong position

2015-02-08 Thread Thomas Hallgren (JIRA)
Title: Message Title
 
 
 
 
 
 
 
 
 
 
  
 
 Thomas Hallgren updated an issue 
 
 
 
 
 
 
 
 
 
 


 
 
 
 
 
 
 Puppet /  PUP-3978 
 
 
 
  Missing values for optional parameters places block at wrong position  
 
 
 
 
 
 
 
 
 

Change By:
 
 Thomas Hallgren 
 
 
 
 
 
 
 
 
 
 Apuppetfunctioncreatedusingoptionalparametersfollowedbyablock,thatthengetscalledwithoutprovidingavalueforthoseoptionalparameters,willcausetheweavinglogictocreateanargumentsarraythatistooshort,leavingtheblockthatissupposedtobelast,atthewrongposition(it'ssimplypassedonatthepositionit'splacedinbythecaller).Thefactthatablockisn'treallyablockbutanormalparameterinRubymakestheoptionalparameterparadigminconsistentinthedispatchdeclaration.Itcanonlyworkwithouttheblocksinceinordertoputtheblocklast,avaluemustbepresentforeachparameterintheinvocation.Thisinturnmeansthatusingnormalrubysyntaxtosetparameterdefaultvalueswillfail(passing {{ nil }} overridessuchadefaultsetting).Onsolutionwouldbetoprovideaparameterdefaultvalueinthedispatchconfigurationasanoptional fourth third argumentto_param_andrequirethattherubymethodthatthedispatchistargetingneverhasanyoptionalparameters(themethod arity _arity_ mustneverbenegative).Thedefaultvaluewouldbeoptionalinitselfanddefaultto {{ nil }} .Whengiven,itmustofcoursecomplywiththeparameter type _type_ (whichisanotherreasontoputitthereinsteadofintherubymethoddeclaration,defaultsdeclaretheredoesn'thavethisrequirement). 
 
 
 
 
 
 
 
 
 
 
 
 

 
 Add Comment 
 
 
 
 
 
 
 
 
 
 


 
 
 
 
 
 
 
 
 

 This message was sent by Atlassian JIRA (v6.3.10#6340-sha1:7ea293a) 
 
 
 
 
  
 
 
 
 
 
 
 
 
   





-- 
You received this message because you are subscribed to the Google Groups Puppet Bugs group.
To unsubscribe from this group and stop receiving emails from it, send an email to 

Jira (PUP-3978) Missing values for optional parameters places block at wrong position

2015-02-08 Thread Thomas Hallgren (JIRA)
Title: Message Title
 
 
 
 
 
 
 
 
 
 
  
 
 Thomas Hallgren commented on  PUP-3978 
 
 
 
 
 
 
 
 
 
 


 
 
 
 
 
 
  Re: Missing values for optional parameters places block at wrong position  
 
 
 
 
 
 
 
 
 
 
I found another ambiguity when investigating this issue. The arg_count(min, max) will allow max to be the symbol :default. What is the difference between that and using last_captures_rest ? Doesn't one imply the other? 
 
 
 
 
 
 
 
 
 
 
 
 

 
 Add Comment 
 
 
 
 
 
 
 
 
 
 


 
 
 
 
 
 
 
 
 

 This message was sent by Atlassian JIRA (v6.3.10#6340-sha1:7ea293a) 
 
 
 
 
  
 
 
 
 
 
 
 
 
   





-- 
You received this message because you are subscribed to the Google Groups Puppet Bugs group.
To unsubscribe from this group and stop receiving emails from it, send an email to puppet-bugs+unsubscr...@googlegroups.com.
To post to this group, send email to puppet-bugs@googlegroups.com.
Visit this group at http://groups.google.com/group/puppet-bugs.
For more options, visit https://groups.google.com/d/optout.


Jira (PUP-3978) Missing values for optional parameters places block at wrong position

2015-02-08 Thread Thomas Hallgren (JIRA)
Title: Message Title
 
 
 
 
 
 
 
 
 
 
  
 
 Thomas Hallgren commented on  PUP-3978 
 
 
 
 
 
 
 
 
 
 


 
 
 
 
 
 
  Re: Missing values for optional parameters places block at wrong position  
 
 
 
 
 
 
 
 
 
 
I like your proposal. Perhaps it could be improved further? 
The dispatcher calls the method like this: 
 
 
 
 
 
 
f.send(:dispatched_to, *args) { |*block_args| the_block.call(*block_args) }
 
 
 
 
 
 
 
The method that is being dispatched to can do this: 
 
 
 
 
 
 
def dispatched_to(*args, block) 
 
 
 
 
  # call the puppet_lambda with arguments 
 
 
 
 
  block.call('foo', 'fee') 
 
 
 
 
 ... 
 
 
 
 
end
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

 
 Add Comment 
 
 

Jira (PUP-3978) Missing values for optional parameters places block at wrong position

2015-02-08 Thread Henrik Lindberg (JIRA)
Title: Message Title
 
 
 
 
 
 
 
 
 
 
  
 
 Henrik Lindberg commented on  PUP-3978 
 
 
 
 
 
 
 
 
 
 


 
 
 
 
 
 
  Re: Missing values for optional parameters places block at wrong position  
 
 
 
 
 
 
 
 
 
 
How is this ticket different from PUP-3977 ? Looks like a duplicate. 
 
 
 
 
 
 
 
 
 
 
 
 

 
 Add Comment 
 
 
 
 
 
 
 
 
 
 


 
 
 
 
 
 
 
 
 

 This message was sent by Atlassian JIRA (v6.3.10#6340-sha1:7ea293a) 
 
 
 
 
  
 
 
 
 
 
 
 
 
   





-- 
You received this message because you are subscribed to the Google Groups Puppet Bugs group.
To unsubscribe from this group and stop receiving emails from it, send an email to puppet-bugs+unsubscr...@googlegroups.com.
To post to this group, send email to puppet-bugs@googlegroups.com.
Visit this group at http://groups.google.com/group/puppet-bugs.
For more options, visit https://groups.google.com/d/optout.


Jira (PUP-3978) Missing values for optional parameters places block at wrong position

2015-02-08 Thread Henrik Lindberg (JIRA)
Title: Message Title
 
 
 
 
 
 
 
 
 
 
  
 
 Henrik Lindberg commented on  PUP-3978 
 
 
 
 
 
 
 
 
 
 


 
 
 
 
 
 
  Re: Missing values for optional parameters places block at wrong position  
 
 
 
 
 
 
 
 
 
 
We could also pass the puppet block as a ruby block. Making that block be the actual puppet block with correct parameters etc requires se gymnastics, and will lose information about parameter types. We could instead just deliver the puppet block when yielding to the ruby block. 
The dispatcher calls the method like this: 
 
 
 
 
 
 
f.send(:dispatched_to, *args) { the_block }
 
 
 
 
 
 
 
The method that is being dispatched to can do this: 
 
 
 
 
 
 
def dispatched_to(*args, block) 
 
 
 
 
  puppet_lambda = block.call 
 
 
 
 
 ... 
 
 
 
 
end
 
 
 
 
 
 
 
or some variation of that (not declaring the block and checkinw with block_defined, and using yield) etc. 
 
 
 
 
 
 
 
 
 
 
 
 

 
 Add Comment 
 
 
  

Jira (PUP-3978) Missing values for optional parameters places block at wrong position

2015-02-08 Thread Henrik Lindberg (JIRA)
Title: Message Title
 
 
 
 
 
 
 
 
 
 
  
 
 Henrik Lindberg commented on  PUP-3978 
 
 
 
 
 
 
 
 
 
 


 
 
 
 
 
 
  Re: Missing values for optional parameters places block at wrong position  
 
 
 
 
 
 
 
 
 
 
I looked into what can be done with ruby, and it is possible to have required parameters after optional. 
Thus if the method dispatched to has optional parameters followed by a required block, the method would be written: 
 
 
 
 
 
 
def foo(a, b=1, c=2, block) 
 
 
 
 
end
 
 
 
 
 
 
 
Then, if called with 2 parameters, this will give values to a, and block. The parameters b and c will get default values. If called with three parameters, a will get the first value, b the second, and block the third. etc. 
The tricky signature is optional arguments followed by an optional block. We could solve this by always giving a nil for the block if not present. The method being dispatched to can then use a non optional last block argument that will be nil. It will not trigger its default value, but that value would typically be nil anyway. 
I do like the ability to define default values in the dispatch - you could in theory dispatch to the same method from multiple dispatchers and you may want to use different default values. As that is probably a bigger change, I can settle for just passing optional block as nil when not given. 
This is far better than the idea with using a Ruby proc (or a class derived from Proc) since it makes it difficult to pass the block on to another function. 
 
 
 
 
 
 
 
 
 
 
 
 

 
 Add Comment 
 
 
 
 
 
 
 
 
 
 


 
 
 
 
 
 
 
 
 

 

Jira (PUP-3978) Missing values for optional parameters places block at wrong position

2015-02-08 Thread Thomas Hallgren (JIRA)
Title: Message Title
 
 
 
 
 
 
 
 
 
 
  
 
 Thomas Hallgren commented on  PUP-3978 
 
 
 
 
 
 
 
 
 
 


 
 
 
 
 
 
  Re: Missing values for optional parameters places block at wrong position  
 
 
 
 
 
 
 
 
 
 
The above syntax gives an error in Ruby 1.8.x (and travis builds still use that for 3.7.x it seems). 
I've done some tests that pass a real ruby block instead. The resulting code is clean and simple. I stretched it one step further since I found out that passing a block is much more expensive than using yield. Going back to your approach where the block simply returns the puppet_lambda without executing it makes for a really nice API where we have two options of passing the block. A ruby yield block can be passed as Proc.new (see above link) or, we can simply yield, get the ruby lambda and then pass that as a normal parameter. 
Some samples showing how our current functions would change (dispatch declarations unchanged): with function: before 
 
 
 
 
 
 
  def with(*args) 
 
 
 
 
args[-1].call(*args[0..-2]) 
 
 
 
 
  end
 
 
 
 
 
 
 
after 
 
 
 
 
 
 
  def with(*args) 
 
 
 
 
yield.call(*args) 
 
 
 
 
  end
 
 
 
 
 
 
 
scanf function: before 
 
   

Jira (PUP-3978) Missing values for optional parameters places block at wrong position

2015-02-08 Thread Thomas Hallgren (JIRA)
Title: Message Title
 
 
 
 
 
 
 
 
 
 
  
 
 Thomas Hallgren commented on  PUP-3978 
 
 
 
 
 
 
 
 
 
 


 
 
 
 
 
 
  Re: Missing values for optional parameters places block at wrong position  
 
 
 
 
 
 
 
 
 
 
Regarding default values in dispatch. It does have one disadvantage. A ruby parameter default value is an arbitrary _expression_ that is evaluated when the invocation is made. Placing them in the dispatch means that the evaluation happens when the function is loaded. Perhaps it doesn't matter much since defaults usually have static data nature but I thought it worth mentioning. 
 
 
 
 
 
 
 
 
 
 
 
 

 
 Add Comment 
 
 
 
 
 
 
 
 
 
 


 
 
 
 
 
 
 
 
 

 This message was sent by Atlassian JIRA (v6.3.10#6340-sha1:7ea293a) 
 
 
 
 
  
 
 
 
 
 
 
 
 
   





-- 
You received this message because you are subscribed to the Google Groups Puppet Bugs group.
To unsubscribe from this group and stop receiving emails from it, send an email to puppet-bugs+unsubscr...@googlegroups.com.
To post to this group, send email to puppet-bugs@googlegroups.com.
Visit this group at http://groups.google.com/group/puppet-bugs.
For more options, visit https://groups.google.com/d/optout.


Jira (PUP-3978) Missing values for optional parameters places block at wrong position

2015-02-08 Thread Henrik Lindberg (JIRA)
Title: Message Title
 
 
 
 
 
 
 
 
 
 
  
 
 Henrik Lindberg commented on  PUP-3978 
 
 
 
 
 
 
 
 
 
 


 
 
 
 
 
 
  Re: Missing values for optional parameters places block at wrong position  
 
 
 
 
 
 
 
 
 
 
And you are right, the feature allowing required parameters after optional is only available from Ruby 1.9.x and we need this for 3x where we must support Ruby 1.8.7. Using a Proc / yield is better in any case. 
 
 
 
 
 
 
 
 
 
 
 
 

 
 Add Comment 
 
 
 
 
 
 
 
 
 
 


 
 
 
 
 
 
 
 
 

 This message was sent by Atlassian JIRA (v6.3.10#6340-sha1:7ea293a) 
 
 
 
 
  
 
 
 
 
 
 
 
 
   





-- 
You received this message because you are subscribed to the Google Groups Puppet Bugs group.
To unsubscribe from this group and stop receiving emails from it, send an email to puppet-bugs+unsubscr...@googlegroups.com.
To post to this group, send email to puppet-bugs@googlegroups.com.
Visit this group at http://groups.google.com/group/puppet-bugs.
For more options, visit https://groups.google.com/d/optout.


Jira (PUP-3978) Missing values for optional parameters places block at wrong position

2015-02-08 Thread Henrik Lindberg (JIRA)
Title: Message Title
 
 
 
 
 
 
 
 
 
 
  
 
 Henrik Lindberg commented on  PUP-3978 
 
 
 
 
 
 
 
 
 
 


 
 
 
 
 
 
  Re: Missing values for optional parameters places block at wrong position  
 
 
 
 
 
 
 
 
 
 
Did you verify the performance numbers? Is the difference as big on later rubies? 
Since you found that it is possible to give the block with Proc.new it should be possible to create a derived Proc class that can be directly called. Say like this: 
 
 
 
 
 
 
class PuppetProc  Proc 
 
 
 
 
  def initialize(closure) 
 
 
 
 
@closure = closure 
 
 
 
 
  end 
 
 
 
 
  def call(*args) 
 
 
 
 
@closure.call(*args) 
 
 
 
 
  end 
 
 
 
 
end
 
 
 
 
 
 
 
I experimented with that, but stumbled on a small problem since Proc requires a block to be given to new - I guess new can be overridden as well to do the initialization - the above sample requires that the PuppetProc is created like this: 
 
 
 
 
  

Jira (PUP-3978) Missing values for optional parameters places block at wrong position

2015-02-07 Thread Thomas Hallgren (JIRA)
Title: Message Title
 
 
 
 
 
 
 
 
 
 
  
 
 Thomas Hallgren created an issue 
 
 
 
 
 
 
 
 
 
 


 
 
 
 
 
 
 Puppet /  PUP-3978 
 
 
 
  Missing values for optional parameters places block at wrong position  
 
 
 
 
 
 
 
 
 

Issue Type:
 
  Bug 
 
 
 

Assignee:
 
 Thomas Hallgren 
 
 
 

Components:
 

 Language 
 
 
 

Created:
 

 2015/02/07 3:31 PM 
 
 
 

Fix Versions:
 

 PUP 3.7.5 
 
 
 

Priority:
 
  Normal 
 
 
 

Reporter:
 
 Thomas Hallgren 
 
 
 
 
 
 
 
 
 
 
A puppet function created using optional parameters followed by a block, that then gets called without providing a value for those optional parameters, will cause the weaving logic to create an arguments array that is too short, leaving the block that is supposed to be last, at the wrong position (it's simply passed on at the position it's placed in by the caller). 
The fact that a block isn't really a block but a normal parameter in Ruby makes the optional parameter paradigm inconsistent in the dispatch declaration. It can only work without the block since in order to put the block last, a value must be present for each parameter in the invocation. This in turn means that using normal ruby syntax to set parameter default values will fail (passing nil overrides such a default setting). 
On solution would be to provide a parameter default value in the dispatch configuration as an optional fourth argument to param and require that the ruby method that the dispatch is targeting never has any optional