On 2014-28-01 17:29, Pawel Tomulik wrote:
W dniu wtorek, 28 stycznia 2014 16:47:53 UTC+1 użytkownik henrik
lindberg napisał:
I have been working on a new API for functions that I hope we will be
able to finish for Puppet 4.0. I have just started and have looked at
the work dalen and zaphod42 did earlier.
The need for a new API is because the 3x API requires values to be
presented to functions in a particular way (empty strings instead of
undef is one of those). If we want to fix that we do need to have a new
API. I will come back later and present ideas in more detail (I am not
quite done with exploration yet).
Requirements as I see them:
* Must be redefinable in different environments / be reloadable
* Support fully qualified names
Names with '::'? So probably they can't be just module members (or there
must be an additional step of registering these methods under fqdn names).
Yes, there must be an extra step - the classes must be anonymous. (easy
to do), and then bound via a name. (Work remains on how exactly this
should work).
* Support arity (fixed and variable)
It appear that this is quite easy to implement, the idea is just to
convert procs/blocks provided by user at definition point to lambas and
store lambdas. Basically, I use this code in my implementation of
macros: https://gist.github.com/ptomulik/8670700. Of course, if you
store puppet functions as a regular methods it becomes even easier.
* Support default arguments
Works only on ruby 1.9+ (at least when we speek in terms of
lambdas/procs). On 1.8 `|a=nil|` is a syntax error.
* Support the new type system with automatic type checking
* Support overloading of one function (i.e. multiple signatures)
That would be great! And shouldn't be so hard to implement, at least on
ruby 1.9+.
It will be easy to implement using something similar to the polymorphic
dispatch used throughout the future parser/evaluator. It cannot be
specified using ruby methods directly - it is either implemented
with one method where the overaloding logic takes place inside one
method, or the user dispatches to different methods depending on
signature. (That is the idea anyway).
* Be easy to write for simple functions
The current interface is not so scary, the only scary thing is the need
to validate arguments manually, which usually takes 85% of the
function's code. If there were dedicated validators, it would be just
great! I suppose, most of the work could be done by the type system with
automatic type checking (if it's applicable to function arguments).
Yeah, interface is not too bad, but as you say, user is fully
responsible for the handling of arguments and their types.
* Easy to test
So - special rspec helper for functions?
I was thinking more about ability to just call it without having to have
scopes and stuff. Unfortunately, with an anonymous class it is not
as easy as just going MyFunc.call(a,b). Can almost get there though.
* Callable direct from Ruby
Current functions are actually callable from ruby, aren't they?
yes sure, but only after having the Puppet Runtime jumping through hoops
adding them to a scope (which requires an environment an a compiler, and
known resource types, and...) i.e to get a banana you also get a
gorilla and a jungle filled with wildlife.
- 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 view this discussion on the web visit
https://groups.google.com/d/msgid/puppet-dev/lc9hbr%24r99%241%40ger.gmane.org.
For more options, visit https://groups.google.com/groups/opt_out.