Content deleted Content added
Mindmatrix (talk | contribs) m Reverted edit by 2409:4063:4E4B:58C:80FD:6F81:5A92:9EC4 (talk) to last version by Anomalocaris |
→Correct results for Prolog numeric grade example: Reset without password or app service Finnish or all Data password reset Gemini app privacy service or all take number delete formated Tags: Reverted Mobile edit Mobile web edit |
||
Line 57:
== Correct results for Prolog numeric grade example ==
The displayed results for Prolog's numeric grade example is not what the user would expect. The article says the results will display: X = 'A'. The expected results should display: X = 4. [[User:
:The example in its current form has two relations, which can be queried in isolation, or which can be queried in combination (like a join in a relational
numeric_grade('B', 3).
numeric_grade('C', 2).
Line 71 ⟶ 69:
X = 'A',
Y = 4
</>
:Alternatively, the query could be used to define a new relation, which gives the grade of a student as a number:
<
numeric_grade('A', 4).
numeric_grade('B', 3).
numeric_grade('C',
numeric_grade(X, -1) :- not X = 'A', not X = 'B', not X = 'C', not X = 'D', not X = 'F'.
grade_as_number(Student, Number) :-
Line 85 ⟶ 81:
?- grade_as_number('The Student', Number).
Number = 4
</
Followup: It would be nice to learn Prolog's syntax for forming functions. Could this example be converted to a function? If so, then how would the the driver program execute it? [[User:Timhowardriley|Timhowardriley]] ([[User talk:Timhowardriley|talk]]) 20:33, 16 August 2023 (UTC)▼
▲Followup: It would be nice to learn Prolog's syntax for forming functions. Could this example be converted to a function? If so, then how would the the driver program
: Here is the example in [[Ciao (programming language) | Ciao]] Prolog's functional syntax:▼
grade_as_number(Student) := numeric_grade(grade(Student)).
grade('The Student') := 'A'.
Line 108 ⟶ 96:
Number = -1,
Student = bob
</>
:Just for fun, the query asks for all input-output pairs that satisfy the functional relationship "grade_as_number". Good for debugging.
|