Skip to content
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

PutLink can give different results in case GetLink or result of it executin is used #2307

Closed
stellarspot opened this issue Jul 30, 2019 · 3 comments

Comments

@stellarspot
Copy link
Contributor

stellarspot commented Jul 30, 2019

Run the example below where ListLink uses GetLinks inside:

(use-modules (opencog) (opencog exec))

(Inheritance (Concept "Jim") (Concept "Father"))
(Inheritance (Concept "Jane") (Concept "Mother"))

(define put-get-multi
 (PutLink
  (LambdaLink
   (VariableList (Variable "x") (Variable "y"))
   (EvaluationLink
    (PredicateNode "relatives")
    (ListLink
     (Variable "x")
     (Variable "y")
     (Concept "mom and pop"))))
  (ListLink
   (GetLink (TypedVariable (Variable "$X") (Type 'ConceptNode))
    (Inheritance (Variable "$X") (Concept "Father")))
   (GetLink (TypedVariable (Variable "$X") (Type 'ConceptNode))
    (Inheritance (Variable "$X") (Concept "Mother"))))))


(display
 (cog-execute! put-get-multi))

The result is:

(EvaluationLink
   (PredicateNode "relatives")
   (ListLink
      (ConceptNode "Jim")
      (ConceptNode "Jane")
      (ConceptNode "mom and pop")
   )
)

Here is the updated example where GetLinks are executed and the result is used inside of ListLink:

(use-modules (opencog) (opencog exec))

(Inheritance (Concept "Jim") (Concept "Father"))
(Inheritance (Concept "Jane") (Concept "Mother"))

(define father
 (cog-execute!
  (GetLink (TypedVariable (Variable "$X") (Type 'ConceptNode))
   (Inheritance (Variable "$X") (Concept "Father")))))

(define mother
 (cog-execute!
  (GetLink (TypedVariable (Variable "$X") (Type 'ConceptNode))
   (Inheritance (Variable "$X") (Concept "Mother")))))

(define put-get-multi
 (PutLink
  (LambdaLink
   (VariableList (Variable "x") (Variable "y"))
   (EvaluationLink
    (PredicateNode "relatives")
    (ListLink
     (Variable "x")
     (Variable "y")
     (Concept "mom and pop"))))
  (ListLink
    father
    mother)))

(display
 (cog-execute! put-get-multi))

The result is:

(EvaluationLink
   (PredicateNode "relatives")
   (ListLink
      (SetLink
         (ConceptNode "Jim")
      )
      (SetLink
         (ConceptNode "Jane")
      )
      (ConceptNode "mom and pop")
   )
)

Now SetLink is used inside the result.

There should be explicit documentation that needs to properly clarify what is a result of LambdaLink execution when its arguments are SetLink.

(PutLink
 (LambdaLink
  (VariableList (Variable "X"))
  ...
 )
 (ListLink
  (SetLink Y1 Y2 Y3)))

a) LambdaLink is executed only once and X is substituted by (SetLink Y1 Y2 Y3)
b) LambdaLink is executed 3 times where X is substituted by Y1, Y2, Y3
c) LambdaLink is executed only once with the first argument of the SetLink where X is substituted by Y1
d) LambdaLink is executed only once with the random value from the SetLink

@stellarspot
Copy link
Contributor Author

stellarspot commented Jul 30, 2019

I run the code where the result of GetLink is empty:

(Inheritance (Concept "Jane") (Concept "Mother"))

(define put-get-multi
 (PutLink
  (LambdaLink
   (VariableList (Variable "x") (Variable "y"))
   (EvaluationLink
    (PredicateNode "relatives")
    (ListLink
     (Variable "x")
     (Variable "y")
     (Concept "mom and pop"))))
  (ListLink
   (GetLink (TypedVariable (Variable "$X") (Type 'ConceptNode))
    (Inheritance (Variable "$X") (Concept "Father")))
   (GetLink (TypedVariable (Variable "$X") (Type 'ConceptNode))
    (Inheritance (Variable "$X") (Concept "Mother"))))))

(display
 (cog-execute! put-get-multi))

The result contains SetLink:

(EvaluationLink
   (PredicateNode "relatives")
   (ListLink
      (SetLink
      )
      (ConceptNode "Jane")
      (ConceptNode "mom and pop")
   )
)

It looks like if ListLink contains SetLink the LambdaLink needs to be applied to each value inside link (version b).

Anyway, it should be explicitly described in the specification. See #2308

@linas
Copy link
Member

linas commented Jul 30, 2019

Part of what you are describing are bugs in the code, The reason there are bugs in the code is issue #1502 -- It turns out that SetLink was a fundamentally bad idea, precisely because it creates problems like this. There are two paths: a short-term fix: fix the code so that SetLinks are always unwrapped. The long-term fix is to stop using SetLink. The long-term fix is ... does not yet have a good design proposal; it's still in the idea stage.

linas added a commit to linas/atomspace that referenced this issue Jul 30, 2019
@linas
Copy link
Member

linas commented Jul 30, 2019

I'm going to close this, because it is fixed in #2310

I'll say it again: I really don't like all the fiddling around with SetLink that is done inside of the PutLink. But in order for it to work "naturally" and "easily" with a mixture of Get and Put, there seems to be no other choice, other than to somehow solve #1502

Hopefully, your examples also show why there has been o forward progress on #1502 -- there are just enough special cases that a good, easy, elegant solution for #1502 is not entirely obvious. Again -- the goal is to have things work "naturally", and be "easy" to use.

@linas linas closed this as completed Jul 30, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants