Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extending core.logic to custom types

I'm experimenting with core.logic, and want to enable my own custom data type to participate in logic expressions:

(deftype Expression [node vars]
  ....)

Basically this represents a node in a mathematical expression tree, containing a node tree and a set of unbound variables used. node is either a constant, a symbol or an (Operator Expression Expression....) tree node. I'd like to be able to use core.logic to manipulate mathematical expressions, and match against subtrees of such expresssions.

How can I do this, if possible?

I see from the core.logic source code that there are a number of protocols that look like they would be good to extend (e.g. IUnifyTerms, IReifyTerms etc.) but it's not totally clear how these are all meant to be used, and which ones I really need to extend.

like image 359
mikera Avatar asked Nov 12 '22 08:11

mikera


1 Answers

core.logic is designed to extensible to custom types. However this is not well documented as the protocols are subject to change as we learn what exactly is needed. It's worth examining the clojure.core.logic.nominal namespace to get a sense of what's required to extend core.logic to custom types.

like image 99
dnolen Avatar answered Nov 15 '22 06:11

dnolen