I wrote on Saturday1: I had to take out several of the instrinsic functions that were added last week, so now these have to be restored, and there's no guarantee that the code that worked a week ago will work now because several aspects have been changed and tightened up.
I restored the intrinsic functions necessary for the 'time_in_minutes' query2 on Saturday evening. No syntax errors occurred when I did this, but running a query like ?- time_in_minutes (03:30, X). should give the result 210. Unfortunately the result was 270. Looking at the trace of the query, it was clear what happened. The final goal of the rule is X is H * 60 + M, where X is the result, H the number of hours and M the number of minutes. Instead of calculating (H * 60) + M (i.e. (3*60) + 30), the interpreter was calculating H * (60 + M), or 3 * 90.
So we had to reimplement the parsing of a line that could have any number of infix operators. CoPilot went through about four different implementations until we finally got something that would work correctly. On and off through the evening, I considered the final implementation and was sure that it was more complex than necessary. There was also a bubble sort at the beginning of the function that could be avoided with a little preplanning (and it's just occurred to me that the bubble sort would run each time the parsing routine was called which is several times: the sort should have been moved out of the function).
I gave my conclusions to CoPilot and they were sort-of incorporated. At least another two versions were required before the statement was parsed correctly. It's all due to operator precedences - remember from junior school: multiplication and division before addition and subtraction. Just to make things more complicated, (I quote) In Prolog, operator precedence is a numerical value (typically between 1 and 1200) that determines the order in which operators are evaluated within a term. Higher precedence values indicate weaker binding, meaning operators with higher precedence are considered "further out" in the structure of the term, while lower precedence values indicate stronger binding. For a language of logic, it seems illogical that a higher number has what one would normally call lower precedence. This required several loops to run backwards, although it occurred to me afterwards that it would be more sensible to change the operators table once again so that the loops could run normally. Ultimately it doesn't make any difference.
Once again, I have to say that for all the sophistication of CoPilot, sometimes it makes silly mistakes and sometimes the results aren't what were required. One "endearing" feature that I have noticed is remarks like "there's a problem with your code at such-and-such a place". Sometimes it's typing errors, but more often those are mistakes that CoPilot made in early iterations.
Internal links
[1] 2033
[2] 2029
| Title | Tags | ||
|---|---|---|---|
| 773 | Literature review: second draft completed | DBA | |
| 985 | Data collection | DBA | |
| 1090 | INTQUANT and REALQUANT | Priority tips | |
| 1855 | F25 Cell phone stand with wireless speaker | Mobile phone |
No comments:
Post a Comment