unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
* Pretty print bytevectors with its content in hex format
@ 2022-09-30  8:41 Zhu Zihao
  2022-09-30 15:20 ` Olivier Dion via Developers list for Guile, the GNU extensibility library
  0 siblings, 1 reply; 3+ messages in thread
From: Zhu Zihao @ 2022-09-30  8:41 UTC (permalink / raw)
  To: guile-devel

[-- Attachment #1: Type: text/plain, Size: 496 bytes --]

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)

I don't see any option to toggle this, What should I do to custom how
bytevector looks?

Thanks!
-- 
Retrieve my PGP public key:

  gpg --recv-keys B3EBC086AB0EBC0F45E0B4D433DB374BCEE4D9DC

Zihao

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 255 bytes --]

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

* Re: Pretty print bytevectors with its content in hex format
  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
  2022-10-04 10:49   ` Zhu Zihao
  0 siblings, 1 reply; 3+ messages in thread
From: Olivier Dion via Developers list for Guile, the GNU extensibility library @ 2022-09-30 15:20 UTC (permalink / raw)
  To: Zhu Zihao, guile-devel

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



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

* Re: Pretty print bytevectors with its content in hex format
  2022-09-30 15:20 ` Olivier Dion via Developers list for Guile, the GNU extensibility library
@ 2022-10-04 10:49   ` Zhu Zihao
  0 siblings, 0 replies; 3+ messages in thread
From: Zhu Zihao @ 2022-10-04 10:49 UTC (permalink / raw)
  To: Olivier Dion; +Cc: guile-devel

[-- Attachment #1: Type: text/plain, Size: 612 bytes --]


> Right.  The Guile printer has no option of that sort yet.  Quickly I
> would think that this should work:
>
> (use-modules (oop goops))
>
> (define-method (display (bv <bytevector>) port)
>   (format port "#vu8(~{#x~x~})" (bytevector->u8-list bv)))
>
> but I haven't tested it.

Thanks for your help!

I test your code in repl but it looks that procedure "display" is still not
a generic function. If I test `(format port ....)` independently, it
works well.

Anyway, thanks a lot :)

-- 
Retrieve my PGP public key:

  gpg --recv-keys B3EBC086AB0EBC0F45E0B4D433DB374BCEE4D9DC

Zihao

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 255 bytes --]

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

end of thread, other threads:[~2022-10-04 10:49 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
2022-10-04 10:49   ` Zhu Zihao

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).