[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Meaning of "~@" in the format procedure

From: Tobias Geerinckx-Rice
Subject: Re: Meaning of "~@" in the format procedure
Date: Wed, 29 Sep 2021 18:24:57 +0200


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~
 => 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:

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

Kind regards,


Attachment: signature.asc
Description: PGP signature

reply via email to

[Prev in Thread] Current Thread [Next in Thread]