|
Posted by Jon Slaughter on 06/07/07 15:23
"Erwin Moller"
<since_humans_read_this_I_am_spammed_too_much@spamyourself.com> wrote in
message news:4667c82f$0$336$e4fe514c@news.xs4all.nl...
> Jon Slaughter wrote:
>
>> is there any way to simply add an attribute like feature to a
>> function/method definition?
>>
>> say I create a function like
>>
>> function Test()
>> {
>>
>> //....
>> }
>>
>> but I want to assign a probability to it in the definition itself...
>> maybe
>> something like
>>
>> function Test()
>> {
>> static $probability = 0.234321;
>> //....
>> }
>>
>> Now is there any way that I can get the probability from the function?
>> I'm
>> using function pointers to call the functions in a random way.
>> Essentially
>> having a list of functions that have assigned probabilities and calling
>> them based on that probability(I don't want to really seperate the
>> probability from the definition.
>>
>>
>> Ultimately it would be nice to extend the syntax to handle a new keyword
>> like
>>
>> function Test():[Probability=0.123421]
>> {
>>
>> }
>>
>> or something like that but I know thats not going to happen.
>>
>> Thanks,
>> Jon
>
> Hi Jon,
>
> A simple idea but maybe it works in your situation:
> 1) Make your function a class.
> 2) Instantiate one for each function you need. (Function should now be
> named
> method in OOP)
> 3) Add a simple method that stores name/value pairs you like to add to
> that
> instance, simply storing them in an instancevariable hashed array.
>
> class TestFunction{
> var $addedValues;
> function addValues($name,$value) {
> $addedValues[$name]=$value;
> }
>
> function getValues(){
> return $addedValues;
> }
> // rest goes here
> }
>
> $test1 = new TestFunction();
> $test1->addValues("probability",0.234321);
>
>
> Is such an approach of any use in your situation?
>
>
Its not that I can't use it but I feel that its to much "work". It defeats
the purpose ot trying to make it easier. Essentially I would have to wrap
all the functions into functors for just one attribute. Essentially what I
need is a way to add meta data. I think Toby's method might work.
Thanks,
Jon
Navigation:
[Reply to this message]
|