jenshweber / grape

Grape - Graph Rewriting and Persistence Engine
http://jenshweber.github.io/grape/
Eclipse Public License 1.0
29 stars 2 forks source link

Assign without creating other elements #14

Closed sdiemert closed 2 years ago

sdiemert commented 4 years ago

Right now it appears that the (assign ...) operator requires that it be incorporated into a pattern that also creates other nodes/edges.

For example,

(rule 'create-person! ['p]
  :create 
   (pattern 
    (node :label "Person" :asserts {:name "'&p'"})))

(rule 'change-name! ['x 'y]
      :read (pattern (node 'n :label "Person" :asserts {:name "'&x'"}))
      :create (pattern 
               (assign "n.name='&y'")))

(clear!)

(create-person! "Simon")
(-> any? matches view)

(change-name! "Simon" "Bob")
(-> any? matches view)

Does not have the desired effect. It fails to do the assignment of Simon -> Bob.

However, if I add a DONT_CARE node to the create pattern then it works as desired.

(rule 'create-person! ['p]
  :create 
   (pattern 
    (node :label "Person" :asserts {:name "'&p'"})))

(rule 'change-name! ['x 'y]
      :read (pattern (node 'n :label "Person" :asserts {:name "'&x'"}))
      :create (pattern 
               (node :label "DONT_CARE")
               (assign "n.name='&y'")))
sdiemert commented 4 years ago

This can be mitigated for now using the :merge true option on the DONT_CARE nodes (so you only ever have one of these... but it still isn't ideal in my view.

jenshweber commented 2 years ago

I am going to revisit this part in context of the next major release of Grape.

jenshweber commented 2 years ago

Since the new version of Grape (GrapeVine) no longer has assignments (since it is functional), I am closing this issue.