Some time ago somebody complained about Common Lisp IO being way
too slow. The explanation was that IO is based on streams providing
a lot more functionality than simple C IO.
If you don't need this functionality, you can of course just call the
low-level C functions from within Lisp. Here is some Franz Allegro CL
specific code only tested on Sun/Solaris.
(load "" :unreferenced-lib-names
(list (ff:convert-to-lang "fopen" :language :c)))
(load "" :unreferenced-lib-names
(list (ff:convert-to-lang "fclose" :language :c)))
(load "" :unreferenced-lib-names
(list (ff:convert-to-lang "getc" :language :c)))
(FF:defforeign 'fopen :arguments '(simple-string simple-string)
:return-type :fixnum)
(FF:defforeign 'fclose :arguments '(fixnum) :return-type :fixnum)
(FF:defforeign 'getc :arguments '(fixnum) :return-type :fixnum
:call-direct t :arg-checking nil :callback nil)
(defun count-lines (filename)
(loop with port =(fopen filename "r")
for c = (getc port)
until (minusp c)
count (eq c 10)
finally (fclose port)))
--
Bernhard Pfahringer
···············@cs.waikato.ac.nz http://www.ai.univie.ac.at/~bernhard