-
Notifications
You must be signed in to change notification settings - Fork 236
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add cond link #2066
Add cond link #2066
Conversation
Add reference
Fix include path
Add test for list_link wrapped cond_link
opencog/atoms/execution/CondLink.cc
Outdated
return HandleCast(inst.instantiate(default_exp, HandleMap())); | ||
} | ||
|
||
DEFINE_LINK_FACTORY(CondLink, COND_LINK) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DEFINE_LINK_FACTORY(CondLink, COND_LINK) | |
DEFINE_LINK_FACTORY(CondLink, COND_LINK) | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What Nil says. Your editor seems to forget to inert a newline.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks very nice! I don't really have any complaints; I don't have any major complaints; all my remarks are about style, rather than design. Fix them up, and I have no problems with a merge.
opencog/atoms/execution/CondLink.cc
Outdated
// using true_link as condition should do it. | ||
if (i != 0 && LIST_LINK == _outgoing[i - 1]->get_type()) | ||
throw SyntaxException(TRACE_INFO, | ||
"CondLink is expected to wrap expressions in LIST_LINK."); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of this check, and the checks below, it would be better to check if the even atoms are evaluatable, and the odd ones are executable. nameserver().isA(type, EVALUATABLE_LINK)
and nameserver.isA(type, EXECUTABLE_LINK)
The EVALUATABLE_LINK type already exists, and "does the right thing"; the EXECUTABLE_LINK does not yet exist) (I started adding it a few weeks ago, but did not finish. Perhaps you can add it, in a separate pull req?)
opencog/atoms/execution/CondLink.cc
Outdated
for (unsigned i = 0; i < conds.size(); ++i) { | ||
tvp = EvaluationLink::do_evaluate(scratch, conds[i]); | ||
if (tvp->get_mean() > 0.5) | ||
return HandleCast(inst.instantiate(exps[i], HandleMap())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not wrong, but there is now a new and better way of doing this: call exps[i]->execute(scratch)
.
This generic execute()
method is brand new, introduced just a week ago, and it is meant to resolve multiple issues with calling the instantiator directly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @linas, In case of eager execution the expressions in the CondLink might have been already executed right? such as an ArithmeticLink might have been already reduced to a NumberNode and calling execute on that NumberNode should throw the "Not Executable" exception in Atom.h? or am I missing something?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, for eager evaluation, the arguments will already have been reduced. There should not be any exceptions as a result, as the reduction is (meant to be) performed only once, not twice.
Lay evaluation would be better; it almost works; there's some open issue saying "must finish this work. Anyway, toe CondLink code looks OK to me.
opencog/atoms/execution/CondLink.cc
Outdated
return HandleCast(inst.instantiate(default_exp, HandleMap())); | ||
} | ||
|
||
DEFINE_LINK_FACTORY(CondLink, COND_LINK) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What Nil says. Your editor seems to forget to inert a newline.
@@ -0,0 +1,59 @@ | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest adding one test for EvaluationLink with grounded predicate
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @noskill my scheme knowledge is very limited, will this suffice
(define (grounded_cond1 ) (cog-new-stv 0 0)) (define (grounded_cond2 ) (cog-new-stv 1 1)) (define grounded-cond (CondLink (Evaluation (GroundedPredicate "scm:grounded_cond1") (List )) (NumberNode 1) (Evaluation (GroundedPredicate "scm:grounded_cond2") (List )) (NumberNode 2)))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks like it was added
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, looks good, thanks
Thanks! This looks good. Sorry for all the earlier confusion about whether this was needed or not. |
; Expression for the above condition. | ||
(PlusLink (Number 3)(Number 2)) | ||
; This is the second condition | ||
(FalseLink ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it the same as?:
else if false:
(PlusLink (Number 1)(Number 2))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep
(FalseLink ) | ||
(PlusLink (Number 1)(Number 2))) | ||
) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there an example of common usecase:
if (expression)
some code
else
some other code
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do you mean like this?
(CondLink |expression| ; EvaluatableLink |some-code| ; if |expression| evaluates to true |some-other-code| ; else )
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes
As per opencog/asmoses#46