unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* binary representation of numbers
@ 2003-02-02  9:36 Rohan Drape
  2003-02-03 15:39 ` Mikael Djurfeldt
  0 siblings, 1 reply; 5+ messages in thread
From: Rohan Drape @ 2003-02-02  9:36 UTC (permalink / raw)


Hello All,

I have searched the documentation but cannot find procedures to convert 
between scheme numbers and common machine byte representations.  I need 
something equivalent to the PLT procedures:

(integer-byte-string->integer string signed? [big-endian?])
(integer->integer-byte-string n size-n signed? [big-endian? to-string])
(floating-point-byte-string->real string [big-endian?])
(floating-point-byte-string->real string [big-endian?])

which assume of course that strings are byte vectors.  These are required to 
implement a simple byte protocol over UDP.  I am sure this is `under my nose' 
but I cannot find it, any pointers would be appreciated.

Regards,
Rohan



_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-user


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: binary representation of numbers
  2003-02-02  9:36 binary representation of numbers Rohan Drape
@ 2003-02-03 15:39 ` Mikael Djurfeldt
  2003-02-04  8:24   ` Rohan Drape
  0 siblings, 1 reply; 5+ messages in thread
From: Mikael Djurfeldt @ 2003-02-03 15:39 UTC (permalink / raw)
  Cc: guile-user

Rohan Drape <rd@alphalink.com.au> writes:

> Hello All,
>
> I have searched the documentation but cannot find procedures to convert 
> between scheme numbers and common machine byte representations.  I need 
> something equivalent to the PLT procedures:
>
> (integer-byte-string->integer string signed? [big-endian?])
> (integer->integer-byte-string n size-n signed? [big-endian? to-string])
> (floating-point-byte-string->real string [big-endian?])
> (floating-point-byte-string->real string [big-endian?])
>
> which assume of course that strings are byte vectors.  These are required to 
> implement a simple byte protocol over UDP.  I am sure this is `under my nose' 
> but I cannot find it, any pointers would be appreciated.

My suspicion is that you can't do this in a reasonable way in Guile.
>From the C level it's easy enough to do it, but not on the Scheme
level.  Someone should implement these primitives for Guile.

There is a clumsy way to do it, though.  It's based on the use of
string-ports and uniform-vector-read/write.

This is a hint of how to do it.  It's an incomplete implementation of
integer->integer-byte-string:

(define (integer->integer-byte-string n size-n signed?)
  (with-output-to-string
    (lambda ()
      (uniform-vector-write
       (list->uniform-vector (select-proto size-n signed?) (list n))))))

(define (select-proto . spec)
  (cdr (assoc spec '(((2 #t) . s)
		     ((4 #f) . 1)
		     ((4 #t) . -1)
		     ((8 #t) . l)))))


_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-user


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: binary representation of numbers
  2003-02-03 15:39 ` Mikael Djurfeldt
@ 2003-02-04  8:24   ` Rohan Drape
  2003-02-05  7:53     ` Mikael Djurfeldt
  0 siblings, 1 reply; 5+ messages in thread
From: Rohan Drape @ 2003-02-04  8:24 UTC (permalink / raw)
  Cc: guile-user

> My suspicion is that you can't do this in a reasonable way in
> Guile. From the C level it's easy enough to do it, but not on the
> Scheme level.  Someone should implement these primitives for
> Guile.

Since it appears there are no primitives to do this I have ported 
the mzscheme procedures.  The API definitions seem fine to me, and 
the implementation is good with regards to size and type checks.  

The intial guile version is packaged as a dynamically loaded module, 
however I would like to submit this work for consideration for 
inclusion in the guile distribution since it seems to me a useful 
set of primitives*.   Is this list the correct place to submit 
contributions?

Thanks,
Rohan

* They are, for example, enough to cleanly implement the 
OpenSoundControl protocol, which is the purpose of this work
(see http://cnmat.cnmat.berkeley.edu/OSC/).



_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-user


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: binary representation of numbers
  2003-02-04  8:24   ` Rohan Drape
@ 2003-02-05  7:53     ` Mikael Djurfeldt
  0 siblings, 0 replies; 5+ messages in thread
From: Mikael Djurfeldt @ 2003-02-05  7:53 UTC (permalink / raw)
  Cc: djurfeldt

Rohan Drape <rd@alphalink.com.au> writes:

>> My suspicion is that you can't do this in a reasonable way in
>> Guile. From the C level it's easy enough to do it, but not on the
>> Scheme level.  Someone should implement these primitives for
>> Guile.
>
> Since it appears there are no primitives to do this I have ported 
> the mzscheme procedures.  The API definitions seem fine to me, and 
> the implementation is good with regards to size and type checks.  

That is great!

> The intial guile version is packaged as a dynamically loaded module, 
> however I would like to submit this work for consideration for 
> inclusion in the guile distribution since it seems to me a useful 
> set of primitives*.

Sounds like a good idea.

> Is this list the correct place to submit contributions?

Normally, contributed source goes to guile-source@gnu.org, but since
you want to promote it for inclusion into guile-core, I'd say
guile-devel@gnu.org is a good choice.

Thanks,
M


_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-user


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: binary representation of numbers
@ 2003-10-14 14:16 Thien-Thi Nguyen
  0 siblings, 0 replies; 5+ messages in thread
From: Thien-Thi Nguyen @ 2003-10-14 14:16 UTC (permalink / raw)
  Cc: guile-user

   From: Rohan Drape <rd@alphalink.com.au>
   Date: Sun, 2 Feb 2003 20:36:11 +1100

   I am sure this is `under my nose' 
   but I cannot find it, any pointers would be appreciated.

here is an excerpt from the upcoming 1.4.1.96 release NEWS file:

 * New installed module: (database binconv)
 
 This module provides the procedures:
 
  (system-big-endian?) => #t | #f
  (integer->integer-byte-string n size signed? [big-endian? [dest]]) => s
  (integer-byte-string->integer s signed? [big-endian?]) => n

i haven't gotten around to the floating-point variants yet, but the
stubs are there (calling them yields a "not yet implemented" error).  if
you want to play, anoncvs access directions are at:

  http://www.glug.org/alt/

you can use "pre-inst-guile" in the top-level build directory to test
your application w/o installing (presuming you don't need the floating
point variants).

thi


_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-user


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2003-10-14 14:16 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-02-02  9:36 binary representation of numbers Rohan Drape
2003-02-03 15:39 ` Mikael Djurfeldt
2003-02-04  8:24   ` Rohan Drape
2003-02-05  7:53     ` Mikael Djurfeldt
  -- strict thread matches above, loose matches on Subject: below --
2003-10-14 14:16 Thien-Thi Nguyen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).