; ---------- SORTS ------------------------------------------ TYPE relation = tuple-set; tuple = atribute -> value; ENDTYPE ; ---------- FUNCTIONS ------------------------------------- FUNC proj ( r:relation, ats:artibute-set ): relation RETURN {x / ats | x <- r}; FUNC agree(x:tuple ,condi:tuple) : Bool PRE subset(dom(condi),dom(x)) RETURN if (condi == []) then true else let ( y=choice(dom(condi))) in x[y] == condi[y] && agree(x,condi\{y}); FUNC sel(r:relation ,condi:tuple):relation RETURN { x | x <- r :agree(x,condi)}; FUNC join(r1:relation,r2:relation):relation RETURN {t1+t2 | t1<-r1, t2<-r2: let (d = dom(t2) * dom(t1)) in agree(t1,t2/d)}; ; ---------- TEST -------------------------------------------- r <- { ["name" -> "Paul Smith","sig" -> "ps"], ["name" -> "David West","sig" -> "dw"], ["name" -> "Anna Rose","sig" -> "ar"]}; r1 <- {["sig" -> "ps", "tel" -> 379], ["sig" -> "ps", "tel" -> 675866], ["sig" -> "dw", "tel" -> 375], ["sig" -> "dw", "tel" -> "At home does not have"]}; r2 <- proj (r,{"sig"}); r3 <- sel( r, ["sig" -> "dw"]); r5 <- sel(r1,["sig"->"ps"]); r6 <- join(r,r1);