How to read a binary floating-point file?

70 views
Skip to first unread message

jkc

unread,
Jul 26, 2006, 1:29:35 PM7/26/06
to
I've spent hours parsing comp.lang.lisp and various UFFI, CFFI
documents, the CMUCL manual, trying to figure out how to read a binary
floating point file in Lisp off and on for the last week without
success. I'm hoping someone here will help me.

The files in question are written on the same machine Lisp is running
on, using something analagous to this C fragment:

FILE fp* = fopen("f.bin", "wb");
fwrite (fvector, 4, 1000, fp);

I ran across the following Lisp code (posted by rif):

(asdf:operate 'asdf:load-op :uffi)
(use-package :uffi)

(defun save-df-array (array file-handle)
(declare (type (simple-array double-float (*)) array))
(%fwrite (sys:vector-sap array)
8
(length array)
file-handle))

(defun read-df-array (array file-handle)
(declare (type (simple-array double-float (*)) array))
(%fread (sys:vector-sap array)
8
(length array)
file-handle))

(defmacro with-fopen-file ((var path mode) &body body)
`(let ((,var (fopen ,path ,mode)))
(unwind-protect
(if (= (%fp-is-null-p ,var) 1)
(error "Error with file ~A (mode ~A): ~A~%" ,path ,mode
(%get-errno))
(multiple-value-prog1
(progn ,@body)))
(%fclose ,var))))

Unfortunately, the 'READ-DF-ARRAY function won't compile; I get the
following warnings:

-+ Warnings (2)
|-- Undefined function %FREAD
`-- This function is undefined:
%FREAD


Presumably, the $FREAD function needs to be defined previously, but all
my attempts to do so fail.

Can someone help me out here?

Thanks
-jkc

Paolo Amoroso

unread,
Jul 26, 2006, 2:03:47 PM7/26/06
to
"jkc" <jef...@makewavs.com> writes:

> I've spent hours parsing comp.lang.lisp and various UFFI, CFFI
> documents, the CMUCL manual, trying to figure out how to read a binary
> floating point file in Lisp off and on for the last week without
> success. I'm hoping someone here will help me.

See:

read-bytes-standalone
http://www.cl-user.net/asp/libs/read-bytes-standalone


Paolo
--
Why Lisp? http://wiki.alu.org/RtL%20Highlight%20Film
The Common Lisp Directory: http://www.cl-user.net

William James

unread,
Jul 26, 2006, 3:36:20 PM7/26/06
to

In MatzLisp (a.k.a. Ruby):

# Make array containing 4 floats.
a = (2..5).map{ |x| x**0.5 }

# Make a file 16-bytes long containing the 4 floats.
File.open( "junk3", "w" ) { |handle|
handle.print a.pack( "f*" ) }

# Read and print the floats.
puts IO.read( "junk3").unpack( "f*" )

----
Output:

1.41421353816986
1.73205077648163
2.0
2.2360680103302

jkc

unread,
Jul 26, 2006, 9:35:56 PM7/26/06
to
On Wed, 26 Jul 2006 20:03:47 +0200, Paolo Amoroso wrote:

> See:
>
> read-bytes-standalone
> http://www.cl-user.net/asp/libs/read-bytes-standalone
>
>
> Paolo

Thank you, Paolo. I did run into that, but it appeared to be designed to
read a file one float at a time. Wouldn't this be incredibly slow for
large files? (say, 10^6 floats). Isn't there a way to allocate a simple
vector, pass a pointer to it and fill it quickly by calling fread?

I've seen code fragments involving UFFI or CFFI to do it, but always
missing essential details (at least to me).

Regards,

jkc

James Bielman

unread,
Jul 26, 2006, 11:40:55 PM7/26/06
to
"jkc" <jef...@makewavs.com> writes:

> I've spent hours parsing comp.lang.lisp and various UFFI, CFFI
> documents, the CMUCL manual, trying to figure out how to read a binary
> floating point file in Lisp off and on for the last week without
> success. I'm hoping someone here will help me.
>

> I ran across the following Lisp code (posted by rif):

[...]

> Unfortunately, the 'READ-DF-ARRAY function won't compile; I get the
> following warnings:
>
> -+ Warnings (2)
> |-- Undefined function %FREAD
> `-- This function is undefined:
> %FREAD

Indeed, because it has not been defined! You want to define a Lisp
function %FREAD that calls the foreign function "fread"---for UFFI,
add something like (from memory, my UFFI-fu is rusty):

(def-function ("fread" %fread)
((ptr :pointer-void)
(size :long)
(nmemb :long)
(stream :pointer-void))
:returning :long)

The equivalent incantation in CFFI is:

(defcfun ("fread" %fread) :long
(ptr :pointer)
(size :long)
(nmemb :long)
(stream :pointer))

Note that neither UFFI nor CFFI export an operator that is the exact
equivalent of VECTOR-SAP, so there is still a portability issue there.
There is a similar feature in CFFI, but it requires using a special
constructor for the array, which is necessary for some CL
implementations.

You may also need to look into disabling garbage collection or
instructing the GC not to move your array for the duration of the
system call, for maximum safety. I don't know about CMUCL, but in
SBCL I would suggest the use of WITH-PINNED-OBJECTS.

James

Greg Menke

unread,
Jul 27, 2006, 12:22:14 AM7/27/06
to

"jkc" <jef...@makewavs.com> writes:

> I've spent hours parsing comp.lang.lisp and various UFFI, CFFI
> documents, the CMUCL manual, trying to figure out how to read a binary
> floating point file in Lisp off and on for the last week without
> success. I'm hoping someone here will help me.
>

http://darcs.informatimago.com/local/darcs/public/lisp/common-lisp/heap.lisp

Scroll down to "gen-ieee-encoding"

Its not doing vector IO but it does work pretty well and no need for
UFFI/CFFI. You can pull out the float stuff by itself to work on.

Gregm

Rob Warnock

unread,
Jul 27, 2006, 12:25:16 AM7/27/06
to
James Bielman <jam...@jamesjb.com> wrote:
+---------------

| You may also need to look into disabling garbage collection or
| instructing the GC not to move your array for the duration of the
| system call, for maximum safety. I don't know about CMUCL, but in
| SBCL I would suggest the use of WITH-PINNED-OBJECTS.
+---------------

cmu> (describe 'system:without-gcing)

WITHOUT-GCING is an external symbol in the SYSTEM package.
Macro-function: #<Function (:MACRO SYSTEM:WITHOUT-GCING) {102BE7A9}>
Macro arguments:
(&rest body)
Macro documentation:
Executes the forms in the body without doing a garbage collection.
...
cmu>

This should surround the call to (%FREAD (SYS:VECTOR-SAP array) ...).

Though note that in compiled code, VECTOR-SAP doesn't cons.
So since CMUCL is single-threaded (from the OS/s POV), in practice
it's safe even without the SYSTEM:WITHOUT-GCING, provided all the
other arguments to %FREAD have been precomputed as well. [This is
probably *not* the case in SBCL on platforms on which it supports
native threading.]


-Rob

-----
Rob Warnock <rp...@rpw3.org>
627 26th Avenue <URL:http://rpw3.org/>
San Mateo, CA 94403 (650)572-2607

jkc

unread,
Jul 27, 2006, 1:00:47 PM7/27/06
to
Thank you, all. I succeeded using UFFI. My simple code follows. If you
see any problems with it, don't hesitate to criticize.

I'm still working on the CFFI version.

-jkc

(asdf:operate 'asdf:load-op :uffi)
(use-package :uffi)

(def-function ("fopen" %fopen)
((path :cstring)
(mode :cstring))
:returning :pointer-void)

(def-function ("fclose" %fclose)
((ptr :pointer-void))
:returning :void)

(def-function ("fread" %fread)
((ptr :pointer-void)
(size :long)
(nmemb :long)
(stream :pointer-void))
:returning :long)

(def-function ("fwrite" %fwrite)


((ptr :pointer-void)
(size :long)
(nmemb :long)
(stream :pointer-void))
:returning :long)

(defun write-df-array (array file-handle)


(declare (type (simple-array double-float (*)) array))

(system::without-gcing


(%fwrite (sys:vector-sap array)
8
(length array)

file-handle)))

(defun read-df-array (array file-handle)
(declare (type (simple-array double-float (*)) array))

(system::without-gcing


(%fread (sys:vector-sap array)
8
(length array)

file-handle)))

(defmacro with-fopen-file ((var path mode) &body body)

`(let ((,var (%fopen ,path ,mode)))
(unwind-protect
(if (null-pointer-p ,var)
(error "Error opening file ~A (mode ~A)~%" ,path ,mode)


(multiple-value-prog1 (progn ,@body)))
(%fclose ,var))))

;; TESTS
(with-fopen-file (os "d10.bin" "rb")
(let ((ar (make-array 10 :element-type 'double-float)))
(read-df-array ar os)
(print ar)))

(with-fopen-file (os "d10.bin" "wb")
(let ((ar (make-array 10 :element-type 'double-float)))
(dotimes (i 10) (setf (aref ar i) (coerce i 'double-float)))
(write-df-array ar os)))

Marcin 'Qrczak' Kowalczyk

unread,
Jul 27, 2006, 5:58:46 PM7/27/06
to
James Bielman <jam...@jamesjb.com> writes:

> (defcfun ("fread" %fread) :long
> (ptr :pointer)
> (size :long)
> (nmemb :long)
> (stream :pointer))

This is not portable: the 2nd and 3rd argument of fread and its result
have C type size_t, not long.

For example on 64-bit Windows long has 32 bits but size_t has 64 bits.
Ignoring even signedness mismatch.

--
__("< Marcin Kowalczyk
\__/ qrc...@knm.org.pl
^^ http://qrnik.knm.org.pl/~qrczak/

Duane Rettig

unread,
Jul 28, 2006, 1:46:33 AM7/28/06
to
"jkc" <jef...@makewavs.com> writes:

> Thank you, all. I succeeded using UFFI. My simple code follows. If you
> see any problems with it, don't hesitate to criticize.
>
> I'm still working on the CFFI version.
>
> -jkc


[ ... ]

Hmm, seems complex to me. Simple-streams has read-vector
http://www.franz.com/support/documentation/8.0/doc/operators/excl/read-vector.htm
and write-vector
http://www.franz.com/support/documentation/8.0/doc/operators/excl/write-vector.htm
that do what you want without needing any ffi.

--
Duane Rettig du...@franz.com Franz Inc. http://www.franz.com/
555 12th St., Suite 1450 http://www.555citycenter.com/
Oakland, Ca. 94607 Phone: (510) 452-2000; Fax: (510) 452-0182

jkc

unread,
Jul 28, 2006, 8:06:13 AM7/28/06
to
On Thu, 27 Jul 2006 23:58:46 +0200, Marcin 'Qrczak' Kowalczyk wrote:

> James Bielman <jam...@jamesjb.com> writes:
>
>> (defcfun ("fread" %fread) :long
>> (ptr :pointer)
>> (size :long)
>> (nmemb :long)
>> (stream :pointer))
>
> This is not portable: the 2nd and 3rd argument of fread and its result
> have C type size_t, not long.
>
> For example on 64-bit Windows long has 32 bits but size_t has 64 bits.
> Ignoring even signedness mismatch.

So how would I make it portable? So far as I know, there isn't a :size_t

jkc

unread,
Jul 28, 2006, 10:34:35 AM7/28/06
to
Duane Rettig wrote:

> [ ... ]
>
> Hmm, seems complex to me. Simple-streams has read-vector
> http://www.franz.com/support/documentation/8.0/doc/operators/excl/read-vector.htm
> and write-vector
> http://www.franz.com/support/documentation/8.0/doc/operators/excl/write-vector.htm
> that do what you want without needing any ffi.

I looked at that, Duane, but wasn't able to make it work. Here's what I
tried:

(let ((vec (make-array 10 :element-type 'double-float)))
(with-open-file (os "d10.bin")
(read-vector vec os)
(print vec)))

where "d10.bin" is a 10 double-float binary file. It produces the
following error:

Type-error in KERNEL::OBJECT-NOT-DOUBLE-FLOAT-ERROR-HANDLER:
#\Null is not of type DOUBLE-FLOAT

I can read it using this CFFI function:

(with-fopen-file (os "d10.bin" "rb")
(let ((ar (make-array 10 :element-type 'double-float)))
(read-df-array ar os)
(print ar)))

#(0.0d0 1.0d0 2.0d0 3.0d0 4.0d0 5.0d0 6.0d0 7.0d0 8.0d0 9.0d0)

--jeff

Duane Rettig

unread,
Jul 28, 2006, 4:52:00 PM7/28/06
to
"jkc" <jef...@makewavs.com> writes:

> Duane Rettig wrote:
>
>> [ ... ]
>>
>> Hmm, seems complex to me. Simple-streams has read-vector
>> http://www.franz.com/support/documentation/8.0/doc/operators/excl/read-vector.htm
>> and write-vector
>> http://www.franz.com/support/documentation/8.0/doc/operators/excl/write-vector.htm
>> that do what you want without needing any ffi.
>
> I looked at that, Duane, but wasn't able to make it work. Here's what I
> tried:
>
> (let ((vec (make-array 10 :element-type 'double-float)))
> (with-open-file (os "d10.bin")
> (read-vector vec os)
> (print vec)))
>
> where "d10.bin" is a 10 double-float binary file. It produces the
> following error:
>
> Type-error in KERNEL::OBJECT-NOT-DOUBLE-FLOAT-ERROR-HANDLER:
> #\Null is not of type DOUBLE-FLOAT

You must be using a simple-streams implementation from another lisp.
Allegro CL doesn't have a KERNEL package.

What you're seeing above is a bug; you should report it to that
lisp's support team.

It works fine in Allegro CL (for which you can download the Express
Edition for free):

CL-USER(1): (defvar *x*
(make-array 10 :element-type 'double-float
:initial-contents
(loop for i from 0.0d0 to 9.0d0
collect i)))
*X*
CL-USER(2): *x*


#(0.0d0 1.0d0 2.0d0 3.0d0 4.0d0 5.0d0 6.0d0 7.0d0 8.0d0 9.0d0)

CL-USER(3): (with-open-file (s "z.dat" :direction :io
:if-exists :overwrite
:if-does-not-exist :create)
(write-vector *x* s))
80
CL-USER(4): (defvar *y* (make-array 10 :element-type 'double-float
:initial-element 10.0d0))
*Y*
CL-USER(5): (with-open-file (s "z.dat")
(read-vector *y* s))
80
CL-USER(6): *y*


#(0.0d0 1.0d0 2.0d0 3.0d0 4.0d0 5.0d0 6.0d0 7.0d0 8.0d0 9.0d0)

CL-USER(7):

jkc

unread,
Jul 28, 2006, 5:47:07 PM7/28/06
to
On Fri, 28 Jul 2006 13:52:00 -0700, Duane Rettig wrote:
>>
>> Type-error in KERNEL::OBJECT-NOT-DOUBLE-FLOAT-ERROR-HANDLER:
>> #\Null is not of type DOUBLE-FLOAT
>
> You must be using a simple-streams implementation from another lisp.
> Allegro CL doesn't have a KERNEL package.
>
> What you're seeing above is a bug; you should report it to that
> lisp's support team.

I'm using CMUCL (I thought I mentioned that). If this is indeed a bug, I
will see what I can do to let them know about it.

Thank you.
-jeff

Duane Rettig

unread,
Jul 29, 2006, 11:19:28 AM7/29/06
to
jkc <jef...@makewavs.com> writes:

Or fix it yourself. It is, after all, free software - it should be
easy :-)

> Thank you.
> -jeff

You're welcome.

Pascal Bourguignon

unread,
Jul 29, 2006, 11:12:15 PM7/29/06
to
Duane Rettig <du...@franz.com> writes:

> jkc <jef...@makewavs.com> writes:
>
>> On Fri, 28 Jul 2006 13:52:00 -0700, Duane Rettig wrote:
>>>>
>>>> Type-error in KERNEL::OBJECT-NOT-DOUBLE-FLOAT-ERROR-HANDLER:
>>>> #\Null is not of type DOUBLE-FLOAT
>>>
>>> You must be using a simple-streams implementation from another lisp.
>>> Allegro CL doesn't have a KERNEL package.
>>>
>>> What you're seeing above is a bug; you should report it to that
>>> lisp's support team.
>>
>> I'm using CMUCL (I thought I mentioned that). If this is indeed a bug, I
>> will see what I can do to let them know about it.
>
> Or fix it yourself. It is, after all, free software - it should be
> easy :-)

s/easy/possible/

We never claimed it would be easy, but that it'd be possible.

--
__Pascal Bourguignon__ http://www.informatimago.com/

CONSUMER NOTICE: Because of the "uncertainty principle," it is
impossible for the consumer to simultaneously know both the precise
location and velocity of this product.

Duane Rettig

unread,
Jul 30, 2006, 12:56:24 AM7/30/06
to
Pascal Bourguignon <p...@informatimago.com> writes:

> Duane Rettig <du...@franz.com> writes:
>
>> jkc <jef...@makewavs.com> writes:
>>
>>> On Fri, 28 Jul 2006 13:52:00 -0700, Duane Rettig wrote:
>>>>>
>>>>> Type-error in KERNEL::OBJECT-NOT-DOUBLE-FLOAT-ERROR-HANDLER:
>>>>> #\Null is not of type DOUBLE-FLOAT
>>>>
>>>> You must be using a simple-streams implementation from another lisp.
>>>> Allegro CL doesn't have a KERNEL package.
>>>>
>>>> What you're seeing above is a bug; you should report it to that
>>>> lisp's support team.
>>>
>>> I'm using CMUCL (I thought I mentioned that). If this is indeed a bug, I
>>> will see what I can do to let them know about it.
>>
>> Or fix it yourself. It is, after all, free software - it should be
>> easy :-)
>
> s/easy/possible/

More accurately:

s/easy :-)/possible./


> We never claimed it would be easy, but that it'd be possible.

A little testy, are we, in the face of a joke? It was my little jab
at the obviously long-winded and sometimes irate posturing being done
elsewhere on this NG. But wait a minute, isn't it someone like me
that should have the right to be irritated - I who put my livlihood
on the line with no other source of income, in spite of strong
competition from many free software vendors? Nah, let's just let it
go...

Pascal Bourguignon

unread,
Jul 30, 2006, 1:05:38 AM7/30/06
to
Duane Rettig <du...@franz.com> writes:
>> We never claimed it would be easy, but that it'd be possible.
>
> A little testy, are we, in the face of a joke? It was my little jab
> at the obviously long-winded and sometimes irate posturing being done
> elsewhere on this NG. But wait a minute, isn't it someone like me
> that should have the right to be irritated - I who put my livlihood
> on the line with no other source of income, in spite of strong
> competition from many free software vendors? Nah, let's just let it
> go...

Note that you and Franz may not be at fault at all, but during the
past 30 years a lot of users and programmers have been burned by the
behavior of proprietary software vendors, whether the company failed
and the software sources and support disappeared, or the company became
too big and failed to attend the needs of smaller niche users, or just
unresponsiveness, etc. Free software resolves these problems by puting
the users in charge of their software, as it was in the first epoch.

Proportionnaly, there was certainly more jobs for IT people when each
corporation that used computers had their own programmer team, than
nowadays when programmers concentrate at software vendors. Free
software is an opportunity to add some programmer jobs back to the
users.

--
__Pascal Bourguignon__ http://www.informatimago.com/

"By filing this bug report you have challenged the honor of my
family. Prepare to die!"

Duane Rettig

unread,
Jul 30, 2006, 1:26:32 AM7/30/06
to
Pascal Bourguignon <p...@informatimago.com> writes:

> Duane Rettig <du...@franz.com> writes:
>>> We never claimed it would be easy, but that it'd be possible.
>>
>> A little testy, are we, in the face of a joke? It was my little jab
>> at the obviously long-winded and sometimes irate posturing being done
>> elsewhere on this NG. But wait a minute, isn't it someone like me
>> that should have the right to be irritated - I who put my livlihood
>> on the line with no other source of income, in spite of strong
>> competition from many free software vendors? Nah, let's just let it
>> go...
>
> Note that you and Franz may not be at fault at all, but during the
> past 30 years a lot of users and programmers have been burned by the
> behavior of proprietary software vendors, whether the company failed
> and the software sources and support disappeared, or the company became
> too big and failed to attend the needs of smaller niche users, or just
> unresponsiveness, etc. Free software resolves these problems by puting
> the users in charge of their software, as it was in the first epoch.
>
> Proportionnaly, there was certainly more jobs for IT people when each
> corporation that used computers had their own programmer team, than
> nowadays when programmers concentrate at software vendors. Free
> software is an opportunity to add some programmer jobs back to the
> users.

I will not enter into this argument.

Pascal Bourguignon

unread,
Jul 30, 2006, 1:49:37 AM7/30/06
to
Duane Rettig <du...@franz.com> writes:
>> Proportionnaly, there was certainly more jobs for IT people when each
>> corporation that used computers had their own programmer team, than
>> nowadays when programmers concentrate at software vendors. Free
>> software is an opportunity to add some programmer jobs back to the
>> users.
>
> I will not enter into this argument.

You have already.
You're saying that free software takes work from programmers.
I believe that free software gives more work to programmers.
Unfortunately we only have anecdotal data about it.

--
__Pascal Bourguignon__ http://www.informatimago.com/

In deep sleep hear sound,
Cat vomit hairball somewhere.
Will find in morning.

Duane Rettig

unread,
Jul 30, 2006, 2:17:11 AM7/30/06
to
Pascal Bourguignon <p...@informatimago.com> writes:

> Duane Rettig <du...@franz.com> writes:
>>> Proportionnaly, there was certainly more jobs for IT people when each
>>> corporation that used computers had their own programmer team, than
>>> nowadays when programmers concentrate at software vendors. Free
>>> software is an opportunity to add some programmer jobs back to the
>>> users.
>>
>> I will not enter into this argument.
>
> You have already.

Sorry, but no.

> You're saying that free software takes work from programmers.

This is precisely what all of these arguments are about (it's not about
free software, but about who says somebody says something that they
have not said). I will not take part.

> I believe that free software gives more work to programmers.

Believe what you wish. You do not know what I believe, because you
have not asked me and I have not said.

> Unfortunately we only have anecdotal data about it.

OK, whatever.

Pascal Bourguignon

unread,
Jul 30, 2006, 2:24:30 AM7/30/06
to
Duane Rettig <du...@franz.com> writes:

> Pascal Bourguignon <p...@informatimago.com> writes:
>
>> Duane Rettig <du...@franz.com> writes:
>>>> Proportionnaly, there was certainly more jobs for IT people when each
>>>> corporation that used computers had their own programmer team, than
>>>> nowadays when programmers concentrate at software vendors. Free
>>>> software is an opportunity to add some programmer jobs back to the
>>>> users.
>>>
>>> I will not enter into this argument.
>>
>> You have already.
>
> Sorry, but no.

It's me who is sorry, I made a confusion of person.


--
__Pascal Bourguignon__ http://www.informatimago.com/

This universe shipped by weight, not volume. Some expansion may have
occurred during shipment.

Duane Rettig

unread,
Jul 30, 2006, 2:32:52 AM7/30/06
to
Pascal Bourguignon <p...@informatimago.com> writes:

> Duane Rettig <du...@franz.com> writes:
>
>> Pascal Bourguignon <p...@informatimago.com> writes:
>>
>>> Duane Rettig <du...@franz.com> writes:
>>>>> Proportionnaly, there was certainly more jobs for IT people when each
>>>>> corporation that used computers had their own programmer team, than
>>>>> nowadays when programmers concentrate at software vendors. Free
>>>>> software is an opportunity to add some programmer jobs back to the
>>>>> users.
>>>>
>>>> I will not enter into this argument.
>>>
>>> You have already.
>>
>> Sorry, but no.
>
> It's me who is sorry, I made a confusion of person.

No problem.

Ken Tilton

unread,
Jul 30, 2006, 4:02:15 AM7/30/06
to

Pascal Bourguignon wrote:
> Duane Rettig <du...@franz.com> writes:
>
>
>>jkc <jef...@makewavs.com> writes:
>>
>>
>>>On Fri, 28 Jul 2006 13:52:00 -0700, Duane Rettig wrote:
>>>
>>>>>Type-error in KERNEL::OBJECT-NOT-DOUBLE-FLOAT-ERROR-HANDLER:
>>>>> #\Null is not of type DOUBLE-FLOAT
>>>>
>>>>You must be using a simple-streams implementation from another lisp.
>>>>Allegro CL doesn't have a KERNEL package.
>>>>
>>>>What you're seeing above is a bug; you should report it to that
>>>>lisp's support team.
>>>
>>>I'm using CMUCL (I thought I mentioned that). If this is indeed a bug, I
>>>will see what I can do to let them know about it.
>>
>>Or fix it yourself. It is, after all, free software - it should be
>>easy :-)
>
>
> s/easy/possible/
>
> We never claimed it would be easy, but that it'd be possible.
>

Because CMUCL is Turing equivalent? <sigh> The poor guy has already
spent more in time-dollars on this one bug than the cost of a pro
license to Lispworks:

> I've spent hours parsing comp.lang.lisp and various UFFI, CFFI
> documents, the CMUCL manual, trying to figure out how to read a binary
> floating point file in Lisp off and on for the last week without
> success.

You want to upgrade his waste to an enterprise license for ACL?

kt (LMAO because all this time I thought "how could a 'reading binary'
thread in any way relate to my only interest here, viz. the outing of
the FSF as the biggest waste of energy on the planet?". k

--
Cells: http://common-lisp.net/project/cells/

"I'll say I'm losing my grip, and it feels terrific."
-- Smiling husband to scowling wife, New Yorker cartoon

Pascal Bourguignon

unread,
Jul 30, 2006, 6:43:38 AM7/30/06
to
Ken Tilton <kent...@gmail.com> writes:
> kt (LMAO because all this time I thought "how could a 'reading binary'
> thread in any way relate to my only interest here, viz. the outing of
> the FSF as the biggest waste of energy on the planet?". k

CMUCL is Public Domain, not GPL.

--
__Pascal Bourguignon__ http://www.informatimago.com/

"This machine is a piece of GAGH! I need dual Opteron 850
processors if I am to do battle with this code!"

Pascal Bourguignon

unread,
Jul 30, 2006, 6:45:21 AM7/30/06
to
Pascal Bourguignon <p...@informatimago.com> writes:

> Ken Tilton <kent...@gmail.com> writes:
>> kt (LMAO because all this time I thought "how could a 'reading binary'
>> thread in any way relate to my only interest here, viz. the outing of
>> the FSF as the biggest waste of energy on the planet?". k
>
> CMUCL is Public Domain, not GPL.

Well at least some source files of CMUCL are. I've only watched one.

jkc

unread,
Jul 30, 2006, 11:08:22 AM7/30/06
to
On Fri, 28 Jul 2006 13:52:00 -0700, Duane Rettig wrote:
> It works fine in Allegro CL (for which you can download the Express
> Edition for free):

The problem for me with becoming dependent on Allegro CL is that I find
the licensing restrictions on the potential sale of my products
objectionable. Otherwise I would just buy it.

-jkc

jkc

unread,
Jul 30, 2006, 4:10:15 PM7/30/06
to
On Sun, 30 Jul 2006 04:02:15 -0400, Ken Tilton wrote:

>
> Because CMUCL is Turing equivalent? <sigh> The poor guy has already
> spent more in time-dollars on this one bug than the cost of a pro
> license to Lispworks:
>
>> I've spent hours parsing comp.lang.lisp and various UFFI, CFFI
>> documents, the CMUCL manual, trying to figure out how to read a binary
>> floating point file in Lisp off and on for the last week without
>> success.
>
> You want to upgrade his waste to an enterprise license for ACL?
>
> kt (LMAO because all this time I thought "how could a 'reading binary'
> thread in any way relate to my only interest here, viz. the outing of
> the FSF as the biggest waste of energy on the planet?". k

It has not been a waste for me at all. I've learned countless things in
the process of the search - the same as you all did when you were getting
started with a new language, I'll warrant.

-jkc

Nathan Baum

unread,
Jul 30, 2006, 5:04:49 PM7/30/06
to
On Sun, 30 Jul 2006, Ken Tilton wrote:
> Pascal Bourguignon wrote:
>> Duane Rettig <du...@franz.com> writes:
>>
>>
>> > jkc <jef...@makewavs.com> writes:
>> >
>> >
>> > > On Fri, 28 Jul 2006 13:52:00 -0700, Duane Rettig wrote:
>> > >
>> > > > > Type-error in KERNEL::OBJECT-NOT-DOUBLE-FLOAT-ERROR-HANDLER:
>> > > > > #\Null is not of type DOUBLE-FLOAT
>> > > >
>> > > > You must be using a simple-streams implementation from another lisp.
>> > > > Allegro CL doesn't have a KERNEL package.
>> > > >
>> > > > What you're seeing above is a bug; you should report it to that
>> > > > lisp's support team.
>> > >
>> > > I'm using CMUCL (I thought I mentioned that). If this is indeed a bug,
>> > > I
>> > > will see what I can do to let them know about it.
>> >
>> > Or fix it yourself. It is, after all, free software - it should be
>> > easy :-)
>>
>>
>> s/easy/possible/
>>
>> We never claimed it would be easy, but that it'd be possible.
>>
>
> Because CMUCL is Turing equivalent? <sigh> The poor guy has already spent
> more in time-dollars on this one bug than the cost of a pro license to
> Lispworks:

Really? What's the exchange rate between time-dollars and real dollars
these days?

>> I've spent hours parsing comp.lang.lisp and various UFFI, CFFI
>> documents, the CMUCL manual, trying to figure out how to read a binary
>> floating point file in Lisp off and on for the last week without
>> success.
>
> You want to upgrade his waste to an enterprise license for ACL?
>
> kt (LMAO because all this time I thought "how could a 'reading binary' thread
> in any way relate to my only interest here, viz. the outing of the FSF as the
> biggest waste of energy on the planet?". k

Riiight. Because CMUCL is made by the FSF...

Ken Tilton

unread,
Jul 30, 2006, 6:51:46 PM7/30/06
to

First PB tries wo wipe all our hard drives, now you want me to have a
zero divide error....The Savages of FSF?

:)

kt

Rob Warnock

unread,
Jul 30, 2006, 9:21:34 PM7/30/06
to
Pascal Bourguignon <p...@informatimago.com> wrote:
+---------------

| Pascal Bourguignon <p...@informatimago.com> writes:
| > CMUCL is Public Domain, not GPL.
|
| Well at least some source files of CMUCL are. I've only watched one.
+---------------

Almost all of CMUCL is "public domain". Where there are copyrights,
they are mostly of the "MIT" or "BSD" flavors:

- Large hunks of CLX are "Copyright (C) 1987 Texas Instruments",
but with an MIT-style permission clause. The "clx/defsystem.lisp"
also adds "Portions Copyright (C) 1988, 1989 Franz Inc.", but
retains the MIT-style permissions. Ditto "clx/doc.lisp", with
the additional copyright holder being MIT.

- The LOOP macro, "src/code/loop.lisp", is Copyright 1986 by MIT
and 1989, 1990, 1991, 1992 by Symbolics. [MIT-style]

- "code/pprint-loop.lisp" says "taken from Dick Water's XP", and
copies MIT-style permissions said to have come from there, but
there is no explicit copyright or date given.

- "contrib/demos/demos.lisp" has a *bunch* of authors & dates
credited, but only one actual "Copyright" [an MIT-style one].

- Most of the PCL-based CLOS stuff is "Copyright (c) 1985, 1986, 1987,
1988, 1989, 1990 Xerox Corporation" with MIT-style permissions,
except for an added "must comply with all applicable United States
export control laws" clause. [Well, duh!]

- A massive amount of recent tuning on CLOS (and "fwrappers")
is "Copyright (C) 2002, 2003 Gerd Moellmann" with BSD-style
permissions. [ISTR some controversy about that at the time,
something about Germany (where Gerd lives) not recognizing
the concept of "dedicating to the public domain".]

Some of the non-core bits have specific more-restrictive copyrights, e.g.:

- The SOAR benchmarks are "Copyright (c) 1985 Xerox Corporation. ...
[use] is permitted for non-commercial research purposes, and
it may be copied only for that use." [That's the only such
"non-commercial" limitation I know of.]

- The files "motif/{lisp,server}/timer-support.{lisp,c}" in the
optional Motif-based debugger module are "Copyright (C) Marco
Antoniotti 1994", with neither a reservation of rights nor
any use permissions, so that one is... questionable. [Marco?
Are you willing to make this an MIT- or BSD-style copyright?]

Rob Warnock

unread,
Jul 30, 2006, 9:28:45 PM7/30/06
to
Nathan Baum <natha...@btinternet.com> wrote:
+---------------

| Riiight. Because CMUCL is made by the FSF...
+---------------

Please, that's an insult to CMUCL!! As Pascal pointed out,
CMUCL was not & is not an FSF project, nor is it GPL'd
[thank goodness!].


-Rob

p.s. See my quick informal survey of CMUCL's copyright status
in a parallel reply.

Thomas F. Burdick

unread,
Aug 3, 2006, 5:09:14 AM8/3/06
to
jkc <jef...@makewavs.com> writes:

> On Wed, 26 Jul 2006 20:03:47 +0200, Paolo Amoroso wrote:
>
> > See:
> >
> > read-bytes-standalone
> > http://www.cl-user.net/asp/libs/read-bytes-standalone
> >
> >
> > Paolo
>
> Thank you, Paolo. I did run into that, but it appeared to be designed to
> read a file one float at a time. Wouldn't this be incredibly slow for
> large files? (say, 10^6 floats). Isn't there a way to allocate a simple
> vector, pass a pointer to it and fill it quickly by calling fread?
>
> I've seen code fragments involving UFFI or CFFI to do it, but always
> missing essential details (at least to me).

The most efficient way to do this would be to mmap the file, and use
that as an alien array. Something like (cast mmapped (* double-float))

Reply all
Reply to author
Forward
0 new messages