About deftables in branch 7.x

62 views
Skip to first unread message

denis.be...@gmail.com

unread,
Feb 13, 2025, 6:09:48 AMFeb 13
to CLIPSESG
In branch 7.x, the current implementation of deftables allows to do much more than the example in the Basic Manual. 
One can use (fixed) A-lists (association lists), which (in their non-fixed version)  are a fundamental data structure in functional languages.

14.1 
(deftable <deftable-name> [<comment>]

   [<table-declaration>]               
   <column-specification>

   <row-specification>*)

<row-specification> ::= (<row-value>+)

 

<row-value> ::= <constant> | (<constant>*)


Everything lies in the "(<constant>*)" part of the previous line.

If you define:

(deftable Alist

   (key data)

   (111 (211 311 411 112 113 114 121 131 141 122))

   (112 (212 312 412 111 113 114 122 132 142 121))

   (113 (213 313 413 111 112 114 123 133 143 124))

   (114 (214 314 414 111 112 113 124 134 144 123))

   (121 (221 321 421 122 123 124 111 131 141 112))

   (122 (222 322 422 121 123 124 112 132 142 111))

   (211 (111 311 411 212 213 214 221 231 241 222))

   (212 (112 312 412 211 213 214 222 232 242 221))

 )

the elements in the data column are indeed interpreted as (fixed) lists (of constants).


Check that it works as expected:

(deffunction linked (?lab1 ?lab2)

    (if (member$ ?lab2 (lookup Alist ?lab1 data)) then TRUE else FALSE)

)

CLIPS> (linked 211 241)

TRUE




What's still missing (but announced) is a way for constructing such deftables other than by hand-listing all the lines.
Gary, do you have some expected date for adding constructors of deftables?
.




CLIPS Support

unread,
Feb 13, 2025, 9:07:37 PMFeb 13
to CLIPSESG
I'm going to allow functional calls and global variables within the rows and try to check that in this week. For more complex scenarios, the build function can be used. 

CLIPS Support

unread,
Feb 21, 2025, 5:01:14 PMFeb 21
to CLIPSESG
CLIPS> (defglobal ?*a* = colors ?*v* = ($ red green blue))
CLIPS>
(deftable av
   (attribute value)
   (?*a* ?*v*)
   (=(sym-cat "dimensions") = ($ 6 3.5)))
CLIPS> (lookup av colors value)
(red green blue)
CLIPS> (lookup av dimensions value)
(6 3.5)
CLIPS> 

denis.be...@gmail.com

unread,
Feb 21, 2025, 11:24:31 PMFeb 21
to CLIPSESG
About syntax. It seems strange to have a space between the "=" sign and thefunction call. In rules, there's no space.

CLIPS Support

unread,
Feb 22, 2025, 1:16:17 AMFeb 22
to CLIPSESG
The '(' character is a delimiter for symbols, so it doesn't matter whether there's a space between the '=' and the '('. The same is true for rules and globals. 

denis.be...@gmail.com

unread,
Feb 26, 2025, 12:47:10 AMFeb 26
to CLIPSESG
Formally, you are right. But as a writing style, it remains strange and not homogeneous with the terms definition in the User Manual.
<term> ::= <constant> | <single-field-variable> | <multifield-variable> | :<function-call> | =<function-call>
(deftemplate data (slot x) (slot y)) 
(defrule twice
   (data (x ?x) (y =(* 2 ?x))) 
=>
)
Of course, anyone is free to use the writing style they want.

Le samedi 22 février 2025 à 07:16:17 UTC+1, CLIPS Support a écrit :
The '(' character is a delimiter for symbols, so it doesn't matter whether there's a space between the '=' and the '('. The same is true for rules and globals. 

CLIPS Support

unread,
Feb 26, 2025, 11:57:45 AMFeb 26
to CLIPSESG
I copied/pasted that example directly from a test case. It's just testing that it's legal to have a space between the '=' and the '('.
Reply all
Reply to author
Forward
0 new messages