- The added line is THIS COLOR.
- The deleted line is THIS COLOR.
//[[Documentation]]
*Hyperlinks (slim)
*Hyperlinks
LMNtal links represent point-to-point connection between atoms and form an ordinary graph. In some applications, however, we may want '''hyperlinks''', namely links that interconnect more than two atoms and form a '''hypergraph'''.
LMNtal provides syntax and operations for hypergraphs, which will be described below. Currently, hyperlinks are supported by the slim runtime
in the ordinary (as opposed to non-deterministic) execution mode.
in the ordinary (as opposed to non-deterministic) execution mode.
**Creating a hyperlink
-A hyperlink is created by a "new" construct specified in a guard.
hoge.
hoge :- new($h) | a($h), b($h).
*--> a(!1), b(!1).
-Each hyperlink is given a fresh private name, which will be printed as a "!" followed by a hexadecimal number.
**Type checking for hyperlinks
-hlink($x)
a(!1).
**Type checking
-The type constraint "hlink($x)" checks if $x represents a hyperlink.
main.
main :- new($x) | a($x).
a($x) :- hlink($x) | b($x).
*--> b(!1).
**Merging two hyperlinks
**Equality checking
-Two hyperlinks can be merged into one using the "><" operator.
-An occurrence of a hyperlink is regarded as a unary atom (with a special, private name). Therefore, the constructs == and \= can be used for comparing two hyperlinks, e.g.,
a($x), b($y) :- hlink($x), hlink($y), $x == $y | ok.
In addition, the above rule can be written as
a($x), b($x) :- ok.
**Fusing two hyperlinks
-Two hyperlinks can be fused into one using the "><" operator.
a(!1), b(!2).
a($x), a($y) :- $x \= $y | a($x), b($y), $x >< $y.
--If $x and $y represent different hyperlinks, they will be merged into one.
***Number of occurrences
-If $x and $y represent different hyperlinks (i.e., have different hyperlink names), they will be merged into one; that is, they are made to have the same hyperlink name.
**Number of occurrences
-The "num" construct in a guard will return the number of occurrences of the specified hyperlink.
a(!1), b(!1).
a($h) :- $n = num($h) | number($n).
*--> b(!1), number(2).
*--> b(!1), number(2).
--Another use
a(!1).
a($h) :- $n = num($h), $n < 5 | a($h), a($h).
*--> a(!1), a(!1), a(!1), a(!1), a(!1).
--Yet another use
flag(!1), a(!1), a(!1), a(!1), a(!1).
a($h) :- hlink($h) | .
flag($h) :- $n = num($h), $n =:= 1 | ok.
*--> ok. // ok is created when all a(!1)'s are removed
---Thus, using hyperlinks, one can check the absence of a particular atom.
**Guard Library
*How to use
The following type constraints can be used in guards.
The + (input) sign preceding a process context name means that the name should
appear in the head, while the - (output) sign means that the name should not
appear in the head.
**Compiling
:'='(+$u,-$v)|make sure that $u[X] and $v[Y] are unary atoms with the same name.
:'='(-$u,+$v)|same as above.
:'=='(+$u,+$v)|check if $u[X] and $v[Y] are unary atoms with the same name.
:unary(+$u)|check if $u[X] is a unary atom.
:ground(+$g)|check if $g[X1,...,Xn] (n>0) is a connected graph whose free links are exactly X1,...,Xn.
:int(+$i)|check if $i[X] is an integer.
:float(+$f)|check if $f[X] is a floating-point number.
:int(+$float,-$int)|cast.
:float(+$int,-$float)|cast.
:345(-$int)|defined for every integer (not only with 345).
:'-3.14'(-$float)|defined for every float.
:'<'(+$int,+$int)|integer comparison; also: ''&color(#8B4513){'>'};'', ''&color(#8B4513){'=<'};'', ''&color(#8B4513){'>='};'', ''&color(#8B4513){'=:='};'', ''&color(#8B4513){'=\='};''.
:'+'(+$int,+$int,-$int)|integer operation; also: ''&color(#8B4513){'-'};'', ''&color(#8B4513){'*'};'', ''&color(#8B4513){'/'};'', ''&color(#8B4513){mod};''.
:'<.'(+$float,+$float)|float comparison; also: ''&color(#8B4513){'>.'};'', ''&color(#8B4513){'=<.'};'', ''&color(#8B4513){'>=.'};'', ''&color(#8B4513){'=:=.'};'', ''&color(#8B4513){'=\=.'};''.
:'+.'(+$float,+$float,-$float)|float operation; also: ''&color(#8B4513){'-.'};'', ''&color(#8B4513){'*.'};'', ''&color(#8B4513){'/.'};''.
:uniq(+$g1,...,+$gn)|uniqueness constraint; checks if the rule has not been applied to the tuple $g1[X1], ..., $gn[Xn] (n>=0).
Currently, programs with hyperlinks can be executed only under slim. To compile, both --slimcode and --hl (or --hl-opt) options need be specified, e.g.,
lmntal --slimcode --hl hoge.lmn > hoge.il
-- --hl : uses hyperlinks.
//[[同名型付きプロセス文脈構文>http://www.ueda.info.waseda.ac.jp/~seiji/wiki/index.php?%B8%A6%B5%E6%C6%FC%BB%EF%A4%C8%A4%A6%A4%E1%A4%AD#r3fa6a93]]を許す
-- --hl-opt : uses hyperlinks and optimizes matching
//--- 以下は実装のこと
--- 中間命令findproccxtが挿入される
--- ガードに自動的にhlink制約を挿入ことで、ground対groundの構造比較をファンクタ対ファンクタで済ませるようにしている
---ちなみに同名型付きプロセス文脈は、処理系内部のコードではsameproccxtなどと呼称
***Executing
Specify --hl when running slim, e.g.,
slim --hl --show-hl hoge.il
-- --hl : uses hyperlinks
--- currently, this cannot be specified with -nd
-- --show-hl : prints the details of hyperlinks
--- Without this option, different occurrences of a hyperlink are printed with the same name.
--- With this option, each occurrence of a hyperlink is printed with its own ID. In addition, a table of hyperlink occurrences will be printed.