unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: Olivier Dion <olivier.dion@polymtl.ca>
To: guile-user@gnu.org
Cc: rekado@elephly.net, Olivier Dion <olivier.dion@polymtl.ca>
Subject: [RFC PATCH 0/2] Strings interpolation
Date: Sat, 10 Dec 2022 17:17:22 -0500	[thread overview]
Message-ID: <20221210221724.23998-1-olivier.dion@polymtl.ca> (raw)

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




             reply	other threads:[~2022-12-10 22:17 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-10 22:17 Olivier Dion [this message]
2022-12-10 22:17 ` [RFC PATCH 1/2] Add reader extension for interpolated strings Olivier Dion
2022-12-10 22:17 ` [RFC PATCH 2/2] Add tests for strings interpolation reader extension Olivier Dion

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=20221210221724.23998-1-olivier.dion@polymtl.ca \
    --to=olivier.dion@polymtl.ca \
    --cc=guile-user@gnu.org \
    --cc=rekado@elephly.net \
    /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).