type-inference-engine

Literals

If you want to use some literals of type \(t\) in your code you must do two things. Firstly add an initializer function which takes no arguments and returns a value of type \(t\) to the database of known functions. Then create an associative list with a predicate which tests a term of an expression to determine if it is a literal or not as a key and the initializer functions as a value. For example, you want to use integer literals in your code. You can add something like this inside tie-example package:

(tie:definitializer *fndb* *my-system* init/integer integer)

(defparameter *literals*
  (list
   (cons #'integerp 'init/integer)))
   

Then call parse-expr inside infer-types like this:

(tie:parse-expr expression *literals*)
   

Now type-inference-engine understands integer literals:

   
CL-USER> (tie-example:infer-types '(1+ 2))
#(#((#:RES515 . #<TYPE-INFERENCE-ENGINE:TYPE-NODE INTEGER {100E6E3B43}>)
    (#:VAR516 . #<TYPE-INFERENCE-ENGINE:TYPE-NODE INTEGER {100E6E3B43}>))
  #((#:RES515 . #<TYPE-INFERENCE-ENGINE:TYPE-NODE T {100E6E3BD3}>)
    (#:VAR516 . #<TYPE-INFERENCE-ENGINE:TYPE-NODE T {100E6E3BD3}>))
  #((#:RES515 . #<TYPE-INFERENCE-ENGINE:TYPE-NODE T {100E6E3BD3}>)
    (#:VAR516 . #<TYPE-INFERENCE-ENGINE:TYPE-NODE INTEGER {100E6E3B43}>)))
((TYPE-INFERENCE-ENGINE:FLAT-CONTROL-NODE (2)(1)(#<TYPE-INFERENCE-ENGINE:STATEMENT RES515 ← (INITIALIZE )>
                                                   #<TYPE-INFERENCE-ENGINE:STATEMENT VAR516 ← (INITIALIZE )>))
 (TYPE-INFERENCE-ENGINE:FLAT-CONTROL-NODE (0)(2)(#<TYPE-INFERENCE-ENGINE:STATEMENT VAR516 ← (INIT/INTEGER )>))
 (TYPE-INFERENCE-ENGINE:FLAT-CONTROL-NODE (1)(0)(#<TYPE-INFERENCE-ENGINE:STATEMENT RES515 ← (1+ #:VAR516)>)))
#:RES515