From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Olivier Dion via "Developers list for Guile, the GNU extensibility library" Newsgroups: gmane.lisp.guile.devel Subject: Re: Pretty print bytevectors with its content in hex format Date: Fri, 30 Sep 2022 11:20:16 -0400 Message-ID: <87wn9kkhxr.fsf@laura> References: <86czbdp7xa.fsf@163.com> Reply-To: Olivier Dion Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="29162"; mail-complaints-to="usenet@ciao.gmane.io" To: Zhu Zihao , guile-devel Original-X-From: guile-devel-bounces+guile-devel=m.gmane-mx.org@gnu.org Fri Sep 30 17:22:59 2022 Return-path: Envelope-to: guile-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oeHqt-0007Nz-BK for guile-devel@m.gmane-mx.org; Fri, 30 Sep 2022 17:22:59 +0200 Original-Received: from localhost ([::1]:40468 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oeHqs-0006aj-6K for guile-devel@m.gmane-mx.org; Fri, 30 Sep 2022 11:22:58 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:42654) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oeHoo-00052y-VU for guile-devel@gnu.org; Fri, 30 Sep 2022 11:20:50 -0400 Original-Received: from smtp.polymtl.ca ([132.207.4.11]:59625) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oeHom-0007eL-JG for guile-devel@gnu.org; Fri, 30 Sep 2022 11:20:50 -0400 Original-Received: from localhost (modemcable094.169-200-24.mc.videotron.ca [24.200.169.94]) by smtp.polymtl.ca (8.14.7/8.14.7) with ESMTP id 28UFKGTG012437; Fri, 30 Sep 2022 11:20:21 -0400 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp.polymtl.ca 28UFKGTG012437 In-Reply-To: <86czbdp7xa.fsf@163.com> X-Poly-FromMTA: (modemcable094.169-200-24.mc.videotron.ca [24.200.169.94]) at Fri, 30 Sep 2022 15:20:16 +0000 Received-SPF: pass client-ip=132.207.4.11; envelope-from=olivier.dion@polymtl.ca; helo=smtp.polymtl.ca X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-devel-bounces+guile-devel=m.gmane-mx.org@gnu.org Original-Sender: "guile-devel" Xref: news.gmane.io gmane.lisp.guile.devel:21376 Archived-At: On Fri, 30 Sep 2022, Zhu Zihao 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 ) 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