Hey Alex,
It seems to work as expected using collects :) Here's the complete program
- it prints out ITEM1 and ITEM6 as expected.

(call "rm" "-f" "test.db")

(class +Item +Entity)
(rel ttl (+IdxFold +String))
(rel tgs (+List +Joint) itm (+Tag))
(rel sts (+IdxFold +String))

(class +Tag +Entity)
(rel itm (+Joint) tgs (+Item))
(rel v (+Ref +Link) NIL +TagVal)

(class +TagVal +Entity)
(rel nm (+IdxFold +String))

(de print-item (This)
    (prinl (: ttl) ": " (: sts) " [" (glue ", " (mapcar '( (This) (get (:
v) 'nm)) (: tgs) ) ) "]" )
)

(pool "test.db")

(setq RED (new! '(+TagVal) 'nm "RED"))
(setq BLUE (new! '(+TagVal) 'nm "BLUE"))

(de new-item (Ttl Sts Tgs)
    (let N (new! '(+Item) 'ttl Ttl 'sts Sts)
         (for Tg Tgs
              (put!> N 'tgs (new! '(+Tag) 'v Tg 'itm N))
         )
    )
)

(new-item "ITEM1" "OPEN" (list RED BLUE))
(new-item "ITEM2" "CLOSED" (list RED))
(new-item "ITEM3" "OPEN" (list BLUE))
(new-item "ITEM4" "OPEN" (list))
(new-item "ITEM5" "CLOSED" (list))
(new-item "ITEM6" "OPEN" (list BLUE RED))
(new-item "ITEM7" "OPEN" (list RED))

(commit)

(let (RED (db 'nm '+TagVal "RED")
      BLUE (db 'nm '+TagVal "BLUE"))
      (setq L1 (collect 'v '+Tag RED RED 'itm))
      (setq L2 (collect 'v '+Tag BLUE BLUE 'itm)))

(for I (sect L1 L2)
     (print-item I))

On Tue, Nov 26, 2019 at 1:52 PM Alexander Burger <a...@software-lab.de>
wrote:

> On Tue, Nov 26, 2019 at 01:13:09PM -0800, C K Kashyap wrote:
> > Hey Alex,
> > What I need is an "and" - with collects, I do a (sect of L1 L2) ... I
> tried
> > a bunch but cant seem to get "and" working -
> > I need the items that are "RED" and "BLUE" :(
>
> Hmm, isn't that impossible? In your model, a tag has a *single* link to a
> TagVal, so it has *one* color and cannot have red AND blue at the same time
>
>    (class +Tag +Entity)
>    (rel itm (+Joint) tgs (+Item))
>    (rel v (+Ref +Link) NIL +TagVal)
>
>    (class +TagVal +Entity)
>    (rel nm (+IdxFold +String))
>
> so
>
> > >> >       (setq L1 (collect 'v '+Tag RED RED 'itm))
> > >> >       (setq L2 (collect 'v '+Tag BLUE BLUE 'itm)))
> > >> > (sect L1 L2) --> this is what I want
>
> the section of L1 and L2 will always be empty, no?
>
> ☺/ A!ex
>
> --
> UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe
>

Reply via email to