From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Mikael Djurfeldt Newsgroups: gmane.lisp.guile.user Subject: Re: binary representation of numbers Date: Mon, 03 Feb 2003 16:39:41 +0100 Sender: guile-user-bounces+guile-user=m.gmane.org@gnu.org Message-ID: References: <200302022036.11256.rd@alphalink.com.au> Reply-To: djurfeldt@nada.kth.se NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: main.gmane.org 1044286780 24295 80.91.224.249 (3 Feb 2003 15:39:40 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Mon, 3 Feb 2003 15:39:40 +0000 (UTC) Cc: guile-user@gnu.org Return-path: Original-Received: from monty-python.gnu.org ([199.232.76.173]) by main.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 18figC-0006E2-00 for ; Mon, 03 Feb 2003 16:38:41 +0100 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.10.13) id 18fihn-00009y-01 for guile-user@m.gmane.org; Mon, 03 Feb 2003 10:40:19 -0500 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.10.13) id 18fihK-00006i-00 for guile-user@gnu.org; Mon, 03 Feb 2003 10:39:50 -0500 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.10.13) id 18fihI-000067-00 for guile-user@gnu.org; Mon, 03 Feb 2003 10:39:48 -0500 Original-Received: from kvast.blakulla.net ([213.212.20.77]) by monty-python.gnu.org with esmtp (Exim 4.10.13) id 18fihH-00005r-00 for guile-user@gnu.org; Mon, 03 Feb 2003 10:39:48 -0500 Original-Received: from dyna224-224.nada.kth.se ([130.237.224.224] helo=linnaeus) by kvast.blakulla.net with esmtp (Exim 3.36 #1 (Debian)) id 18fihC-0006kq-00; Mon, 03 Feb 2003 16:39:42 +0100 Original-Received: from mdj by linnaeus with local (Exim 3.36 #1 (Debian)) id 18fihB-00013O-00; Mon, 03 Feb 2003 16:39:41 +0100 Original-To: rd@alphalink.com.au In-Reply-To: <200302022036.11256.rd@alphalink.com.au> (Rohan Drape's message of "Sun, 2 Feb 2003 20:36:11 +1100") User-Agent: Gnus/5.090008 (Oort Gnus v0.08) Emacs/21.2 (i386-pc-linux-gnu) Original-cc: djurfeldt@nada.kth.se X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1b5 Precedence: list List-Id: General Guile related discussions List-Help: List-Post: List-Subscribe: , List-Archive: List-Unsubscribe: , Errors-To: guile-user-bounces+guile-user=m.gmane.org@gnu.org Xref: main.gmane.org gmane.lisp.guile.user:1594 X-Report-Spam: http://spam.gmane.org/gmane.lisp.guile.user:1594 Rohan Drape 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