I'm trying to extend the sample Visual Prolog sample Calendar code to use FACTS instead of creating the Calendar "Event" data within the code (i.e. hard coded Calendar Events).
I'm looking for guidance on the best Prolog coding strategy (i.e. commands) to make the Calendar sample code read Calendar Event data from a set of Prolog Facts. Later I'll be pulling the Facts from a MS SQL Server DB. Ideally I would want to separate the data retrieval code out to another class as the Family4 sample code explains.
The way that I'd like to create the json object (see my code below) is syntactically incorrect and all my attempts to make it syntactically correct produce a cornucopia of other errors that I'm sure would be easy to fix if I knew what I was doing.
Errors such as:
- A foreach loop must be a Procedure (so you can't retrieve Facts within the Foreach)
My json Value isn't compatible with my json Object (Probably something to do with the 'o' in the sample code that I can't figure out to recreate in my code)
Struggles with keeping my Procedure/Determ/Nondeterm constrictions all in alignment
Thanks for your patients...
Original Calendar Sample Code Snippet (Which I want to modify to use FACTS)
Code: Select all
predicates
calendar : jsonProc_name.
clauses
calendar(_Context, ArgMap) = o(Result) :- % Where 'o' is defined and what it is does is a separate mystery to me.
Result = jsonObject::new(),
Email = ArgMap:get_string("emailaddr"),
MyEvents = [
o(mkEvent("Lunch", mkTime(1, 11, 15), mkTime(1, 14, 45),"30"),true),
o(mkEvent("Dinner", mkTime(-1, 10, 30),mkTime(2, 11, 00),"40"),true)
],
Result:set_array("events", MyEvents).
Below is the simplest representation of the code that I wish would work. However it cannot work as written because it is syntactically incorrect and I'm pretty sure I need some help with json Values Vs json Objects syntax.
Code: Select all
predicates
getEvents : () -> jsonObject V.
clauses
getEvents() = (Result) :-
Result=jsonObject::new(),
MyEvents = [
foreach events(Title, Start, End, Resource,AllDay) do
V=mkEvent(Title, Start,End, Resource,AllDay)
end foreach]
"initEventFacts()"
Creates the Facts to Read (this works fine)
Code: Select all
predicates
initEventFacts : ().
clauses
initEventFacts():- % Save two Facts (This clause is working fine)
assert(events("My Facts Row 1", mkTime(1, 11, 15), mkTime(1, 14, 45),"30",true)),
assert(events("My Facts Row 2", mkTime(-1, 10, 30),mkTime(2, 11, 00),"40",true)).
Unmodified Calendar Sample Code (used by me above and the original sample code)
Code: Select all
predicates
mkEvent : (string Title, string Start, string End, string Resource, boolean AllDay) -> jsonObject V.
clauses
mkEvent(Title, Start, End, Resource, AllDay) = V :-
V = jsonObject::new(),
V:set_string("title", Title),
V:set_string("start", Start),
V:set_string("end", End),
V:set_string("resource", Resource),
V:set_boolean("allDay", AllDay).