32.2.3. Testing Your UDF

A small executable named qa is provided for testing UDFs. This program is located in the $Polyflow/bin directory. When executed, this program will display a CLIPS> prompt. Consider that the file containing your CLIPS code is named myudf.clp, and that the function name is UDFP1 as in the previous example. At the CLIPS prompt, enter

 (batch myudf.clp) 

to instruct qa to read in and assess your UDF. If no errors are found, qa will report TRUE and print out the UDF. If any errors are found with the UDF, qa will print them here.

Assuming no errors were found, you can now test your UDF to see if it returns the values you expect. At the CLIPS prompt, enter

 (UDFP1 1.1) 

to evaluate the UDF with ?X1 taking the value of 1.1. qa will print 11.051, the value returned by UDFP1. Note that this is the correct value, since when .

Here is the transcript of this qa session:

CLIPS> (batch myudf.clp)
TRUE
CLIPS>
;
; This is a polynomial function with 1 argument
;
(deffunction UDFP1 (?X1)
  (bind ?MyX (+ 4. (* 3. ?X1) (* 2. ?X1 ?X1) (* 1. ?X1 ?X1 ?X1) ))
  ?MyX
)
CLIPS> (UDFP1 1.1)
11.051
CLIPS>