Recently I stumbled across a few undocumented Record Database predicates. I found there are push and pop predicates that can be used manipulate arrays. The record_push and record_pop predicates can be used to process global stacks and arrays. The following example shows how the record_push/3 and record_pop/3 can be used to simulate array like functions.
record(hashtable1, key1,[]),
record_push(hashtable1, key1, value1),
record_push(hashtable1, key1, value2),
record_push(hashtable1, key1, value3),
recorded(hashtable1, key1, _arraylist),
record_pop(hashtable1, key1, _first),
record_pop(hashtable1, key1, _second),
recorded(hashtable1, key1, _newarraylist).
If you run this prolog code from a BIMprolog.exe interpreter you will get the following output:
?- record(hashtable1, key1,[]),
record_push(hashtable1, key1, value1),
record_push(hashtable1, key1, value2),
record_push(hashtable1, key1, value3),
recorded(hashtable1, key1, _arraylist),
record_pop(hashtable1, key1, _first),
record_pop(hashtable1, key1, _second),
recorded(hashtable1, key1, _newarraylist).
_arraylist = [value3,value2,value1]
_first = value3
_second = value2
_newarraylist = [value1]
Yes
?-
If you have any questions about this entry feel free to discuss this on the gulfsoft.com/blog.
John Willis
John_willis@gulfsoft.com
Wednesday, March 5, 2008
TEC Prolog Push and Pop Predicates
Those of you who have been dealing with TEC rules over the years, know there are a lot of un-documented predicates available in the Prolog interpreter that TEC uses (i.e., BIM Prolog V40). Every once and a while I run into a few neat trinkets that open up a whole new area for programming with TEC rules...
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment