1 / 17

ITEC 380

ITEC 380. Organization of programming languages Lecture 10 – Prolog. Review. Homework 2 due on F Semester project will be out either F or M C# picked as OO Language Lists Recursion. Objectives. Review Prolog Look at GUIs with Prolog. Exercise.

cole
Download Presentation

ITEC 380

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. ITEC 380 Organization of programming languages Lecture 10 – Prolog

  2. Review • Homework 2 due on F • Semester project will be out either F or M • C# picked as OO Language • Lists • Recursion

  3. Objectives • Review Prolog • Look at GUIs with Prolog

  4. Exercise • How do you create a set of facts/rules in Prolog that can read in five numbers and store them a stack of numbers? • How would you reverse the contents of the list? • How would you pop off the top 2 and add the result to the top of the stack?

  5. Review • How would you represent that Bill has five dollars and Ted has two in Prolog? • How would your represent a purchase of an item that costs three dollars? • How would you add two numbers and print out if the result is greater than 5? • How would you change the previous example to allow user input?

  6. Methods of reversing • Accumulator versus appending • How do we tell which one is better? naiverev([],[]). naiverev([H|T],R):-  naiverev(T,RevT),  append(RevT,[H],R). Versus accRev([H|T],A,R):-  accRev(T,[H|A],R). accRev([],A,A). rev(L,R):-  accRev(L,[],R).

  7. XPCE • A system for creating GUIs using prolog • Demo of capabilities • Type manpce in your prolog interpreter

  8. Basics • Four predicates for controlling GUIs • New, send, get free • Java GUI components comparison • Example of creating a GUI with prolog new(@demo, dialog(“Demo Window”)). send(@demo, open).

  9. Components • To add to the window you use send • send(@demo, append(text_item(‘Hello’)). • Capabilities • button (name, RuleToCall). • int_item %Integer with bump up/down • slider %Numerical value in a range • menu %Radio button, tick-box, combo-box • label %Images / Text • list_browser %View a list of data • editor %Allow editing of data

  10. Example program ask_employee :- new(Dialog, dialog('Define employee')), send_list(Dialog, append, [ new(N1, text_item(first_name)), new(N2, text_item(family_name)), new(S, new(S, menu(sex))), new(A, int_item(age, low := 18, high := 65)), new(D, menu(department, cycle)), button(cancel, message(Dialog, destroy)), button(enter, and(message(@prolog, assert_employee, N1?selection, N2?selection, S?selection, A?selection, D?selection), message(Dialog, destroy))) ]),

  11. Continuing on send_list(S, append, [male, female]), send_list(D, append, [research, development, marketing]), send(Dialog, default_button, enter), send(Dialog, open).

  12. Example 2 • Get a name ask_name(Name) :- new(D, dialog('Prompting for name')), send(D, append, new(TI, text_item(name, ’’))), send(D, append, button(ok, message(D, return, TI?selection))), send(D, append, button(cancel, message(D, return, @nil))), send(D, default_button, ok), % Ok: default button get(D, confirm, Answer), % This blocks! send(D, destroy), Answer \== @nil, % canceled Name = Answer.

  13. Shapes • Can get creative send(@p, display, new(@bo, box(100,100))). send(@p, display, new(@ci, circle(50)), point(25,25)). send(@p, display, new(@tx, text(’Hello’)), point(120, 50)). send(@p, display,new(@bz, bezier_curve(point(50,100), point(120,132), point(50, 160), point(120, 200)))).

  14. Display • Can get the information from the GUI • get(@demo, display, D). %Display var • get(@display, size, Size) • get(Size, width, W)

  15. Process • Find basic component idea • Find out arguments • Figure out when to call new, send, get • Build it piece by piece

  16. GUIs • What is your opinion of Prolog’s GUI implementation? • What are it’s strengths? • What are it’s weaknesses? • If you wanted to do something other than this GUI with prolog, what would you do (hint, covered previously)?

  17. Next week • C#

More Related