Hi,
I have a problem trying to run an example rule with Rools 0.4. I
wasn't sure where to post the problem description, so I've logged it
on the rools support request tracker:
> Hi,
> I have a problem trying to run an example rule with Rools 0.4. I
> wasn't sure where to post the problem description, so I've logged it
> on the rools support request tracker:
Here is what I found.
I can duplicate the problem using ruby irb (rather than JRuby).
Interestingly enough, the problem does not show up when you load the
same example in a file and run it.
So it seems particular to the interpreter mode. Is this a requirement
for you?
I can patch the code so it does not fail (and still passes the tests
but I am not too happy about it).
Feel free to experiment with it and give me more feedback:
in lib/rools/default_parameter_proc.rb
def method_missing(sym, *args)
facts = @rule.rule_set.get_facts
if facts.has_key?( sym.to_s )
#puts "return fact #{facts[sym.to_s].value}"
return facts[sym.to_s].value
else
if sym.to_s != "inspect"
raise Exception, "symbol: #{sym.to_s} not found in facts"
else
return nil
end
end
end
Thanks,
Pat.
On Apr 20, 7:44 pm, cappelaere <cappela...@gmail.com> wrote:
> Can you reproduce this error in Ruby rather than JRuby?
> I do not use JRuby...
> Thanks,
> Pat.
> On Apr 18, 11:58 am, IanDickinson <i.j.dickin...@gmail.com> wrote:
> > Hi,
> > I have a problem trying to run an example rule with Rools 0.4. I
> > wasn't sure where to post the problem description, so I've logged it
> > on the rools support request tracker:
Hi Pat,
Thanks for your reply. I did note in my original support request that
it applies in ruby and jruby both. I in fact implemented a similar
patch myself as a temporary workaround. However, I think you should
fix this problem properly, for two reasons:
1. it's a common pattern for people to paste example code from a
project's own documentation into the interpreter while getting to know
a Ruby library. An early question we all ask when trying out a new
library is "does this thing work?". Causing the interpreter to exit
suddenly from the example code is likely to lead to more "no" answers
than your hard work merits.
2. the reason for the problem is that in your method_missing, all no-
arg methods that are not facts raise an exception. Here is a case
where there's a legitimate no-arg method, inspect, that is not a fact
and should not be an exception. Are you satisfied that there is no
other possible case in which that method_missing legitimately receives
a no-arg message? If not, you have a latent bug that's waiting to
happen to someone else.
> From: Ian Dickinson <i.j.dickin...@gmail.com> > Date: Mon, 21 Apr 2008 14:24:33 +0100 > To: Pat Cappelaere <cappela...@gmail.com> > Cc: <rools-users@googlegroups.com> > Subject: Re: [rools-users] Re: Running rule example causes interpreter to exit
> Hi Pat, > Well, I'm not sure what I said to generate a response like that. In > your previous message, you wrote:
>> So it seems particular to the interpreter mode. Is this a requirement >> for you? >> I can patch the code so it does not fail (and still passes the tests >> but I am not too happy about it).
> which, to me, suggested that you didn't think it was very important to > fix the issue. Fair enough, it's your project and entirely your call > what to fix and when, no dispute from me. I was simply making a > counter-argument why you might want to consider fixing it *at some > point*. I wasn't thumping the desk and shouting fix it now.
> I have no desire to give you any grief, so I'll switch my project to > use another approach. No grief all round then.
Thanks for not submitting your patch and giving me grief for not fixing it while I am trying to understand what the real problem is.
I certainly understand that it would be nice to support the interpreter. I am sorry if I did not catch that problem before and I am not sure how I could test for it. I have tried to add test cases to get 100% coverage so I guess I failed miserably.
My concern is that the fix I provided to you addresses your problem but I am still not satisfied that there is not another case out there. So YES, there is a latent bug that's waiting to happen. And if you are smarter than I am and can fix it, please let us know.
> Hi Pat, > Thanks for your reply. I did note in my original support request that > it applies in ruby and jruby both. I in fact implemented a similar > patch myself as a temporary workaround. However, I think you should > fix this problem properly, for two reasons:
> 1. it's a common pattern for people to paste example code from a > project's own documentation into the interpreter while getting to know > a Ruby library. An early question we all ask when trying out a new > library is "does this thing work?". Causing the interpreter to exit > suddenly from the example code is likely to lead to more "no" answers > than your hard work merits.
> 2. the reason for the problem is that in your method_missing, all no- > arg methods that are not facts raise an exception. Here is a case > where there's a legitimate no-arg method, inspect, that is not a fact > and should not be an exception. Are you satisfied that there is no > other possible case in which that method_missing legitimately receives > a no-arg message? If not, you have a latent bug that's waiting to > happen to someone else.