This is a read-only archive of lispforum.com. The forum was locked to new users and posts and is preserved here as static HTML from a database snapshot taken on 2019-09-07.

CLISP Programming

4 posts · 6952 views

There are two parts of this question and I've managed to do the first part. It's the second part I'm currently having problem with.

1. Create a factbase of students and their CGPA for at least 5 students with CGPA ranging from 2 to 5 with students having the CGPA (4.1) by defining deftemplate facts. The name slot should be STRING type and CGPA slot should be of floating point number.

DONE!!

But how to...

2. Write a rule to find names and their CGPA and display the result on the monitor.


(deffacts students-list

(student (name “A B C”) (CGPA 2.0))

(student (name “D E F”) (CGPA 2.5))

(student (name “G H I”) (CGPA 3.0))

(student (name “J K L”) (CGPA 4.1))

(student (name “M N O”) (CGPA 4.1)))

Re: CLISP Programming

So, what you need to do is iterate over the factbase and, for each entry in it, extract two elements, and then incorporate those two elements into text output that you send to the screen.

For the second bit, look into print and format; the latter is particularly good for this kind of thing.

For iterating over the factbase, you need to know what kind of collection you've stored the facts in, and how to iterate over it. Is it a list, a hashmap, a vector, or something else?
For extracting the elements, that depends entirely on what kind of a thing you've stored them in. Again, are you using lists, hashmaps, objects, structs..?
There are two parts of this question and I've managed to do the first part. It's the second part I'm currently having problem with.
Naeem

Re: CLISP Programming

Actually you mean CLIPS (A Tool for Building Expert Systems) and not CLISP (an ANSI Common Lisp Implementation). I found the documentation, you can reference slots (I can't find better example so don't bother with the topic of that particular section) or look at this example (section Phases and Control Facts). I guess that almost nobody knows CLIPS here so the help will be limited.
cl-2dsyntax is my attempt to create a Python-like reader. My mirror of CLHS (and the dark themed version). Temporary mirrors of aferomentioned: CLHS and a dark version.