ln012 - Event Programming in Prolog Events in our quagent...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
Event Programming in Prolog %% print an event list print_events([]) :- nl. print_events([H|T]) :- writeln(H), print_events(T). Events in our quagent Prolog API are just list of strings Compared to: :- use_module(library(porter_stem)). %% print an event list print_events([]) :- nl. print_events([H|T]) :- tokenize_atom( H,TokenList), % tokenize the string H writeln(TokenList), print_events(T).
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Event Programming in Prolog %% libraries and modules :- consult('quagent.pro'). :- use_module(library(porter_stem)). %% dispath event predicate dispatch_event(Q,E) :- member('STOPPED',E), q_turn(Q,-30). dispatch_event(Q,E) :- member('rays',E), nth1(9,E,X), % unify the 9th element of E with X, start counting at 1 nth1(10,E,Y), % unify the 10th element of E with Y Dist is sqrt(abs(X)**2 + abs(Y)**2), write('ray> '),write(' distance '),write(Dist),nl, Dist =< 500, q_turn(Q,-30). dispatch_event(_,_). % return true if we are not interested in the event %% handle events predicate handle_events(_,[]). handle_events(Q,[H|T]) :- tokenize_atom(H,TokenList), % tokenize the string H dispatch_event(Q,TokenList), handle_events(Q,T).
Background image of page 2
% parse the rays command event token list, ignoring % the first 6 tokens q_parse_rays([_, _, _, _, _, _|TokenList], ObjList) :-
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 10/03/2011 for the course CSC 592 taught by Professor Staff during the Spring '11 term at Rhode Island.

Page1 / 9

ln012 - Event Programming in Prolog Events in our quagent...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online