From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Olivier Dion Newsgroups: gmane.lisp.guile.user Subject: [RFC PATCH 0/2] Strings interpolation Date: Sat, 10 Dec 2022 17:17:22 -0500 Message-ID: <20221210221724.23998-1-olivier.dion@polymtl.ca> Mime-Version: 1.0 Content-Transfer-Encoding: 8bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="36327"; mail-complaints-to="usenet@ciao.gmane.io" Cc: rekado@elephly.net, Olivier Dion To: guile-user@gnu.org Original-X-From: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Sat Dec 10 23:18:23 2022 Return-path: Envelope-to: guile-user@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 1p48Ao-0009Fu-B0 for guile-user@m.gmane-mx.org; Sat, 10 Dec 2022 23:18:22 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p48AS-0007gd-Sb; Sat, 10 Dec 2022 17:18:00 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p48AQ-0007ec-3p for guile-user@gnu.org; Sat, 10 Dec 2022 17:17:58 -0500 Original-Received: from smtp.polymtl.ca ([132.207.4.11]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p48AO-0000WA-A4 for guile-user@gnu.org; Sat, 10 Dec 2022 17:17:57 -0500 Original-Received: from laura.ht.home (modemcable094.169-200-24.mc.videotron.ca [24.200.169.94]) (authenticated bits=0) by smtp.polymtl.ca (8.14.7/8.14.7) with ESMTP id 2BAMHc9T021592 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT); Sat, 10 Dec 2022 17:17:46 -0500 DKIM-Filter: OpenDKIM Filter v2.11.0 smtp.polymtl.ca 2BAMHc9T021592 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=polymtl.ca; s=default; t=1670710667; bh=bvVF/gpfemLbDDPVOu1mCdk/VI9MVGTBUvnCPTUYGKk=; h=From:To:Cc:Subject:Date:From; b=ZS85/t/rScz3vrCGy03kcaL5QFg8HjMV4cu4yQjOv9mlSrwZ0fTZ87o4sH7IhSOsd Y50Bg0JyOnFOxSMaUiAIInpid20MKnykkGskxpPaxNDcQkYJLbNIdqkIMYT9+y8OwP pX3lFZGusd+u5s8iRRJiksCU3ZPse3g95obUImGo= X-Mailer: git-send-email 2.38.1 X-Poly-FromMTA: (modemcable094.169-200-24.mc.videotron.ca [24.200.169.94]) at Sat, 10 Dec 2022 22:17:38 +0000 Received-SPF: pass client-ip=132.207.4.11; envelope-from=olivier.dion@polymtl.ca; helo=smtp.polymtl.ca X-Spam_score_int: -43 X-Spam_score: -4.4 X-Spam_bar: ---- X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, 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-user@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Original-Sender: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.lisp.guile.user:18769 Archived-At: Hi Guilers, I've added a hash reader extension in ice-9 boot to do strings interpolation. One can interpolate expressions in a string by using the `@' character before the expressions. If that characters is doubled, then it acts as an escaping to insert itself without evaluation. The interpolation is done by extracting the expressions and putting them in a call to `format'. Expressions are all formatted with `~a', which is perhaps a little bit limiting here. As an optimization, if there's no expression to interpolate, then no call to `format' is done and a string is returned instead. Example of interpolations: #"foo" -> "foo" #"9^2=@(* 9 9)" -> (format #f "9^2=~a" (* 9 9)) #"one=@1" -> (format #f "one=~a" 1) #"bar@'buz" -> (format #f "bar=~a" (quote buz)) #"@me@@gnu.org" -> (format #f "~a@gnu.org" me) #"me@@gnu.org" -> "me@gnu.org" #"@@no-suffix@" -> "@weird" #"@@suffix@@" -> "@weird@" Olivier dion (2): Add reader extension for interpolated strings. Add tests for strings interpolation reader extension. module/ice-9/boot-9.scm | 37 ++++++++++++++++++++++++++++++++++++ test-suite/tests/reader.test | 11 ++++++++++- 2 files changed, 47 insertions(+), 1 deletion(-) -- 2.38.1