I know this is probably easy... I want to read a list of numbers from a file and put the numbers into a list.
I'm teaching vector dot products in Prolog, and I want to use large vectors. So I'm reading in two files with numbers, putting these into two lists, then finding the dot product of the two lists.
Thanks, Randy Latimer
============================================================================== Message: Address: Action: help majordomo(a)clip.dia.fi.upm.es Info. on useful commands subscribe ciao-users-request(a)clip.dia.fi.upm.es Subscribe to this list unsubscribe ciao-users-request(a)clip.dia.fi.upm.es Unsubscribe from this list <whatever> ciao-users(a)clip.dia.fi.upm.es Send message to list ----------------------------------------------------------------------------- Archived messages: http://www.clip.dia.fi.upm.es/Mail/ciao-users/ -----------------------------------------------------------------------------
An easy way is to use Prolog syntax in the data file, i.e., you can have file vector1 which contains:
1. 3. 2.
and file vector2 which contains
3. 5. 7.
and then you can simply use file_terms/2 from the library:
:- module(_,_).
:- use_module(library(file_utils)).
main :- file_terms(vector1, V1), file_terms(vector2, V2), write('V1 = '), write(V1), nl, write('V2 = '), write(V2), nl, v_dot_prod(V1,V2,VP), write('VP = '), write(VP), nl.
v_dot_prod([],[],0). v_dot_prod([ V1El | V1Rest ], [ V2El | V2Rest ], VP) :- v_dot_prod(V1Rest, V2Rest, VPRest), VP is V1El * V2El + VPRest.
Hope this helps!