all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Meaning of "~@" in the format procedure
@ 2021-09-29 14:20 André A. Gomes
  2021-09-29 16:24 ` Tobias Geerinckx-Rice
  2021-09-29 16:34 ` zimoun
  0 siblings, 2 replies; 4+ messages in thread
From: André A. Gomes @ 2021-09-29 14:20 UTC (permalink / raw)
  To: help-guix

Hi,

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 a specific example, look at the package definition of emacs-exwm.

Speaking of that, what does "$@" do after emacs?

--8<---------------cut here---------------start------------->8---
emacs "$@" --eval 'a-sexp'
--8<---------------cut here---------------end--------------->8---

Thank you.


-- 
André A. Gomes
"Free Thought, Free World"


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Meaning of "~@" in the format procedure
  2021-09-29 14:20 Meaning of "~@" in the format procedure André A. Gomes
@ 2021-09-29 16:24 ` Tobias Geerinckx-Rice
  2021-10-04 17:34   ` André A. Gomes
  2021-09-29 16:34 ` zimoun
  1 sibling, 1 reply; 4+ messages in thread
From: Tobias Geerinckx-Rice @ 2021-09-29 16:24 UTC (permalink / raw)
  To: André A. Gomes; +Cc: help-guix

[-- 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 --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Meaning of "~@" in the format procedure
  2021-09-29 14:20 Meaning of "~@" in the format procedure André A. Gomes
  2021-09-29 16:24 ` Tobias Geerinckx-Rice
@ 2021-09-29 16:34 ` zimoun
  1 sibling, 0 replies; 4+ messages in thread
From: zimoun @ 2021-09-29 16:34 UTC (permalink / raw)
  To: André A. Gomes; +Cc: help-guix

Hi,

On Wed, 29 Sept 2021 at 18:16, André A. Gomes <andremegafone@gmail.com> wrote:

> 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.

I think it is for multilines.

> --8<---------------cut here---------------start------------->8---
> emacs "$@" --eval 'a-sexp'
> --8<---------------cut here---------------end--------------->8---

It is for a shell.  It means all the arguments.


Hope that helps,
simon


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Meaning of "~@" in the format procedure
  2021-09-29 16:24 ` Tobias Geerinckx-Rice
@ 2021-10-04 17:34   ` André A. Gomes
  0 siblings, 0 replies; 4+ messages in thread
From: André A. Gomes @ 2021-10-04 17:34 UTC (permalink / raw)
  To: Tobias Geerinckx-Rice; +Cc: help-guix

Hi Tobias,

Thank you for the examples and clear explanations.


--
André A. Gomes
"Free Thought, Free World"


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-10-05 12:14 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-09-29 14:20 Meaning of "~@" in the format procedure André A. Gomes
2021-09-29 16:24 ` Tobias Geerinckx-Rice
2021-10-04 17:34   ` André A. Gomes
2021-09-29 16:34 ` zimoun

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/guix.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.