As per a homework assignment, I need to read data from a data file.
My data file looks something like this:
Linda A. Martin 43
Phyllis Sebesta 40
Robert Delwood 38
Jack Kennedy 39
Glen Steele 37
The issue I'm currently stuck on is how I'm going to parse this appropriately, as I need to sort the list by the two-digit number on the end.
One strategy I thought of is checking the data type as I do a (read infile)
, but I'm not sure how I'd go about doing that.
My other idea is to read it into an unordered fact and just check the last slot when sorting, but I want to work with the language a little more, so I can utilize some more of the built-in functionality.
Is there any CLIPS functionality that can determine the type of data being read in from an open file?
Some functions you may find useful:
CLIPS> (readline)
Glen Steele 37
"Glen Steele 37"
CLIPS> (explode$ (readline))
Glen Steele 37
(Glen Steele 37)
CLIPS> (nth$ 3 (explode$ (readline)))
Glen Steele 37
37
CLIPS> (type (nth$ 3 (explode$ (readline))))
Glen Steele 37
INTEGER
CLIPS> (str-assert (str-cat "(person " (readline) ")"))
Glen Steele 37
<Fact-1>
CLIPS> (facts)
f-0 (initial-fact)
f-1 (person Glen Steele 37)
For a total of 2 facts.
CLIPS>