PDA

View Full Version : Load external data


Driqus
03-23-2005, 03:28 AM
is it possible within LISP to load external data (table), for instance a CSV ?

and if so, how can it be done?

a CSV is much easyer to edit, for an application engineer/enduser
and as programmer you can focus more on your LISP code.

I wan't to define a list with specific properties which can be applied
on a (or multiple) part(s) such as productcode, material, density, color etc.

Greetzz
Driqus

clausb
03-23-2005, 07:52 AM
Sure - LISP has all the usual file handling stuff built-in, so you can open files, read from them, parse their contents, and close the files again.

Check out the LISP documentation, such as the LISP HyperSpec at http://www.lispworks.com/documentation/HyperSpec/Front/; in particular, you'll probably be interested in open (http://www.lispworks.com/documentation/HyperSpec/Body/f_open.htm), close (http://www.lispworks.com/documentation/HyperSpec/Body/f_close.htm), read-line (http://www.lispworks.com/documentation/HyperSpec/Body/f_rd_lin.htm) and maybe also read-from-string (http://www.lispworks.com/documentation/HyperSpec/Body/f_rd_fro.htm) and read-delimited-list (http://www.lispworks.com/documentation/HyperSpec/Body/f_rd_del.htm).

There are also code examples out there which show how to parse CSV files, even in Common LISP, as a simple Google search reveals - http://www.google.com/search?q=read+csv+file+common+lisp . You might want to try one of those solutions/libraries and integrate them into your code. Parsing CSV is not as easy as many might think, however, so if you can control the format of the external data, try to choose a format which requires less parsing effort (and hence less LISP code).

Claus