unofficial mirror of help-guix@gnu.org 
 help / color / mirror / Atom feed
From: Tobias Geerinckx-Rice <me@tobias.gr>
To: "André A. Gomes" <andremegafone@gmail.com>
Cc: help-guix@gnu.org
Subject: Re: Meaning of "~@" in the format procedure
Date: Wed, 29 Sep 2021 18:24:57 +0200	[thread overview]
Message-ID: <87wnmz1h2p.fsf@nckx> (raw)
In-Reply-To: <874ka3zco4.fsf@gmail.com>

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

André,

André A. Gomes 写道:
> I see that "~@" is used frequently in Guix' codebase in the 
> format
> procedure but I don't understand what it does.  (info "(guile)
> Formatted Output") didn't help much.

For background: ~@<specifier> conventionally modifies the 
behaviour of ~<specifier>.  For example, ~f formats a fixed-point 
number, and ~@f tweaks it to unconditionally print a + sign on 
positive numbers.

At first glance the ‘@’ in ~@ looks like a first-class format 
character, but it's really just the same thing: it modifies 
~<newline>, where <newline> is the literal newline that follows ~@ 
in your example.  I hope that's clear :-)  That's why it's hard to 
search for.

The Guile manual section you read uses the literal strings 
‘~newline’ and ‘~@newline’ for this.  I hope re-reading that with 
this in mind will be more clear.  If not, an example is probably 
worth all of the above words:

  |(format #t "a~
  |b")
  => ab

I.e., the newline is ignored, similar to \ at the end of a line in 
other languages.  This allows writing crazy long output lines 
without exceeding 80 characters in your text editor.

  |(format #t "a~
  |            b")
  => a            b

  |(format #t "a~@
  |            b")
  => ab

The @ between ~ and the newline makes Guile ignore all leading 
whitespace before the b.  It looks much better in code than the 
first format example, but the result is identical.  The reason to 
follow the first or last style is purely cosmetic.

In the case of emacs-exwm, we want to generate a .desktop file 
without leading spaces, without messing up the indentation of the 
.scm file.

> Speaking of that, what does "$@" do after emacs?
> emacs "$@" --eval 'a-sexp'

This is a completely unrelated @.  In shell scripting, and 
contexts that try to be ’shell-like’, "$@" expands to all 
command-line arguments.  They are safely quoted so that one 
argument that contains whitespace won't get misinterpreted as 
multiple arguments.

Example shell script:

  #!/bin/sh
  echo "I was called with these arguments:" "$@"
  # Now invoke emacs with the same arguments, adding --floop at 
  the end:
  emacs "$@" --floop

Kind regards,

T G-R

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

  reply	other threads:[~2021-09-29 17:09 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-29 14:20 Meaning of "~@" in the format procedure André A. Gomes
2021-09-29 16:24 ` Tobias Geerinckx-Rice [this message]
2021-10-04 17:34   ` André A. Gomes
2021-09-29 16:34 ` zimoun

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://guix.gnu.org/

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

  git send-email \
    --in-reply-to=87wnmz1h2p.fsf@nckx \
    --to=me@tobias.gr \
    --cc=andremegafone@gmail.com \
    --cc=help-guix@gnu.org \
    /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).