Hi Cle,

> Ok, here comes my story! Currently there is an application/tool written
> ...
>    #  (Edge id fromNode toNode)
>    (be edge ("ts1" "end#1" "points#1"))
>    (be edge ("ts2" "points#1" "points#2"))
>    (be edge ("ts3" "points#1" "points#2"))
>    (be edge ("ts4" "points#2" "end#2"))
> ...
>    (be walk (@Begin @Way)
>      (edge @Begin @From @To)
>      (walk @To (@Begin) @Way)
>    )
> 
>    (be walk (@Node @Way @Way))
> 
>    (be walk (@FromNode @AuxWay @Way)
>      (edge @Edge @FromNode @ToNode)
>      (walk @ToNode (@Edge . @AuxWay) @Way)
>    )


OK, so my modification of your original DB program would be

(pool "x.db")

(class +Test +Entity)
(rel id (+Ref +String))
(rel src (+Ref +String))
(rel tgt (+Ref +String))

(new T '(+Test) 'id "ts1"  'src "end#1"  'tgt "points#1")
(new T '(+Test) 'id "ts2"  'src "points#1"  'tgt "points#2")
(new T '(+Test) 'id "ts3"  'src "points#1"  'tgt "points#2")
(new T '(+Test) 'id "ts4"  'src "points#2"  'tgt "end#2")

(commit)

(be walk (@Begin @Way)
   (db id +Test @Begin @Obj)
   (val @From @Obj  src)
   (val @To @Obj tgt)
   (walk @To (@Begin) @Way) )

(be walk (@Node @Way @Way))

(be walk (@FromNode @AuxWay @Way)
   (db src +Test @FromNode @Obj)
   (val @Edge @Obj id)
   (val @ToNode @Obj tgt)
   (walk @ToNode (@Edge . @AuxWay) @Way) )


Now, I must confess that I use the 'db' Pilog predicate here, instead of
the suggested Lisp 'db' function. In the latter case, the line

   (db id +Test @Begin @Obj)

would need to be replaced with

   (@Lst collect 'id '+Test (-> @Begin))
   (lst @Obj @Lst)

and

   (db src +Test @FromNode @Obj)

would be

   (@Lst collect 'src '+Test (-> @FromNode))
   (lst @Obj @Lst)

No big thing, but not so beautiful ;-)


But I remembered a fact which would allow us to stay with the beautiful
solution: The 'db' predicate matches "val%" only for string types (for
some obscure practical and historical reasons). If 'id' were a numeric
type, then only exact matches are returned. Would this be an option,
i.e.

   (rel id (+Ref +Number))

or probably even

   (rel id (+Key +Number))

If so, then we could safely stay with the 'db' predicate.

Cheers,
- Alex
-- 
UNSUBSCRIBE: mailto:picol...@software-lab.de?subject=unsubscribe

Reply via email to