Skip to content

Commit 564f893

Browse files
Add example for inserting ownership with value variable (#1004)
## Goal Adds an example with the `insert $owner has attr-type == $value;`
1 parent 332bab6 commit 564f893

File tree

1 file changed

+35
-0
lines changed
  • typeql-reference/modules/ROOT/pages/statements

1 file changed

+35
-0
lines changed

typeql-reference/modules/ROOT/pages/statements/has.adoc

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,41 @@ match $person isa person;
3939
insert $person has name "Alice";
4040
----
4141
42+
If the value is a variable instead of a literal, you must use `==`.
43+
44+
[,typeql]
45+
----
46+
#!test[write]
47+
#{{
48+
match
49+
$person isa person;
50+
#}}
51+
match let $name_value = "Alice";
52+
insert $person has name == $name_value;
53+
----
54+
[NOTE]
55+
====
56+
Writing `insert $person has name $name_value;` will result in an error:
57+
"_The variable 'name_value' cannot be declared as both a 'Attribute' and as a 'Value'._"
58+
59+
60+
This is best understood by rewriting syntactic short-hands into atomic constraints.
61+
62+
`$p has name $n;` *becomes* `$p has $n; $n isa T;`.
63+
64+
`$p has T == $n;` *becomes* `$p has $_a; $_a isa T; $_a == $n;`
65+
66+
In the first case, `$n` is clearly an attribute. The
67+
second case, introduces a new variable `$_a` as the attribute and requires its value to be the same as that of $n.
68+
69+
The confusion arises from being able to write ``$p has name "Alice;"``. But:
70+
71+
`$p has name "Alice;"` *becomes* `$p has T == "Alice";`
72+
73+
This is syntax-sugar introduced *ONLY* for literals, and is rewritten further as above.
74+
====
75+
76+
4277
== Deleting attribute ownership
4378

4479
The `has` keyword is used to remove an attribute from its owner.

0 commit comments

Comments
 (0)