Talk:Computer program: Difference between revisions

Content deleted Content added
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:Timhowardriley|TimhowardrileyUser:]] ([[User talk:Timhowardriley|talk]]) 19:59, 16 August 2023 (UTC)
 
: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 database). For example:
<syntaxhighlight lang="prolog">
numeric_grade('A', 4).
numeric_grade('B', 3).
numeric_grade('C', 2).
Line 71 ⟶ 69:
X = 'A',
Y = 4
</>
</syntaxhighlight>
:Alternatively, the query could be used to define a new relation, which gives the grade of a student as a number:
<syntaxhighlight lang="prolog">
numeric_grade('A', 4).
numeric_grade('B', 3).
numeric_grade('C', 2).
numeric_grade('D', 1).
numeric_grade('F', 0).
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
</syntaxhighlight> [[User:Robert Kowalski|Robert Kowalski]] ([[User talk:Robert Kowalski|talk]]) 08:18, 18Robert8 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 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 execute it? [[User:Timhowardriley|Timhowardriley]] ([[User talk:Timhowardriley|talk]]) 20:33, 16 AugustexecuAugust 2023 (UTC)
: Here is the example in [[Ciao (programming language) | Ciao]] Prolog's functional syntax:
 
: Here is the example in [[Ciao (programming language) | Ciao]] Prolog's functional syntax:=
<syntaxhighlight lang="prolog">
numeric_grade('A') := 4.
numeric_grade('B') := 3.
numeric_grade('C') := 2.
numeric_grade('D') := 1.
numeric_grade('F') := 0.
numeric_grade(X) := -1 :- X \= 'A', X \= 'B', X \= 'C', X \= 'D', X \= 'F'.
grade_as_number(Student) := numeric_grade(grade(Student)).
grade('The Student') := 'A'.
Line 108 ⟶ 96:
Number = -1,
Student = bob
</>
</syntaxhighlight>
 
:Just for fun, the query asks for all input-output pairs that satisfy the functional relationship "grade_as_number". Good for debugging.