unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: Olivier Dion via "Developers list for Guile, the GNU extensibility library" <guile-devel@gnu.org>
To: Zhu Zihao <all_but_last@163.com>, guile-devel <guile-devel@gnu.org>
Subject: Re: Pretty print bytevectors with its content in hex format
Date: Fri, 30 Sep 2022 11:20:16 -0400	[thread overview]
Message-ID: <87wn9kkhxr.fsf@laura> (raw)
In-Reply-To: <86czbdp7xa.fsf@163.com>

On Fri, 30 Sep 2022, Zhu Zihao <all_but_last@163.com> wrote:
> Hi, dear Guile users!
>
> I'm using Guile to play around with some binaries. In Guile, the
> bytevector prints its content in decimal format. Just like:
>
> #vu8(255 255 255 255)
>
> But, it's always more convenient if its content is printed in hex format
> like
>
> #vu8(#xff #xff #xff #xff)

Right.  The Guile printer has no option of that sort yet.  Quickly I
would think that this should work:
--8<---------------cut here---------------start------------->8---
(use-modules (oop goops))

(define-method (display (bv <bytevector>) port)
  (format port "#vu8(~{#x~x~})" (bytevector->u8-list bv)))
--8<---------------cut here---------------end--------------->8---

but I haven't tested it.

-- 
Olivier Dion
oldiob.dev



  reply	other threads:[~2022-09-30 15:20 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-30  8:41 Pretty print bytevectors with its content in hex format Zhu Zihao
2022-09-30 15:20 ` Olivier Dion via Developers list for Guile, the GNU extensibility library [this message]
2022-10-04 10:49   ` Zhu Zihao

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87wn9kkhxr.fsf@laura \
    --to=guile-devel@gnu.org \
    --cc=all_but_last@163.com \
    --cc=olivier.dion@polymtl.ca \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).