Custom $Rel

how do you create a new custom relation?
i’m trying to set up “put object beside object” and thought this would work:

(relation #beside)
(name #beside)  beside
(grammar [put [held] [beside] [single]] for [put $ #beside $])
(before [put $obj #beside $])
                (ensure $obj is held)
(perform [put $obja #beside $objb])
                (log){$obja, $objb}

but the perform predicate never gets called. i simply get ‘you can’t put things beside the xxx’

Looking at the library for how the other relations work:

(prevent [put $ $Rel $Dest])
	(when $Dest won't accept $Rel)
~(when (supporter $O) won't accept #on)

~(when (container $O) won't accept #in)

(when $O won't accept $Rel)
	(if) ($Rel is one of [#under #behind]) (then)
		Putting things (name $Rel) (the $O) would achieve little.
	(else)
		You can't put things (name $Rel) (the $O).
	(endif)

So we can invent a trait for objects that accept #beside (similar to container / #in or supporter / #on) , and add its accompanying negated rule like the ones above.

Or we could just make all objects accept #beside for demo purposes.

~(when $ won't accept #beside)
1 Like

thanks, that last ‘quick and dirty’ method seems to work for my purposes, as long as i rein it in with some (prevents).

As long as your reins are simple flag checks, you can incorporate them into the (when $ won't accept #beside) negated rule. That way you save typing prevent rules and their fail messages.

~(when $O won't accept #beside)
	~(room $O)
	~($O is #in #sack)
	~($O is #on #spinning_disk)
1 Like