unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* Meaning of symbol prefixed with "#$"
@ 2023-05-26  1:43 N. Y.
  2023-05-26  4:26 ` Robby Zambito
  2023-05-26 18:22 ` Daniel Meißner
  0 siblings, 2 replies; 3+ messages in thread
From: N. Y. @ 2023-05-26  1:43 UTC (permalink / raw)
  To: guile-user

Hi all,

I was wondering what is the meaning of symbols prefixed with "#$", for
example "#$version" in Guix package definitions.

I was trying to write a package definition for a python package whose
version number was intended to be inferred from git metadata during build
time via versioneer. However, since Guix does not retain git metadata
during build, the setup.py statement declaring the version number as to be
inferred from git metadata had to be changed to refer to a simple version
number string. I wrote,

#+begin_src
(arguments
  '(#:phases (modify-phases %standard-phases
    (add-after 'unpack 'amend-version
      (lambda _
        (substitute* "setup.py"
          (("versioneer.get_version\\(\\)")
          (string-append "\"" #$version "\"")))))
#+end_src

With reference to a patch describing the same issue with a different python
package with the same inferred git metadata version number issue:
https://issues.guix.gnu.org/63628#0-lineno26.

However, I get an error I do not understand:

#+begin_src
starting phase `amend-version'
error: in phase 'amend-version': uncaught exception:
unbound-variable #f "Unbound variable: ~S" (ungexp) #f
#+end_src

I thought I could begin to debug this by understanding what "#$" means in
"#$version".

Thanks in advance!

Best regards,
Ning


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

* Re: Meaning of symbol prefixed with "#$"
  2023-05-26  1:43 Meaning of symbol prefixed with "#$" N. Y.
@ 2023-05-26  4:26 ` Robby Zambito
  2023-05-26 18:22 ` Daniel Meißner
  1 sibling, 0 replies; 3+ messages in thread
From: Robby Zambito @ 2023-05-26  4:26 UTC (permalink / raw)
  To: guile-user


"N. Y." <ningyuan.sg@gmail.com> writes:

> Hi all,
>
> I was wondering what is the meaning of symbols prefixed with "#$", for
> example "#$version" in Guix package definitions.

G-Expressions in Guix are created using #~<exp ...>, similar to how
S-Expressions are created using '<exp ...> or `<exp ...> in Scheme (and
other Lisps). The single quote in Scheme is actually a reader macro that
expands to the following:

'exp        => (quote exp)
'(exps ...) => (quote (exps ...))

Similarly, the backtick is a reader macro that expands to the following:

`exp        => (quasiquote exp)
`(exps ...) => (quasiquote (exps ...))

The latter is interesting because it allows us to /unquote/ data in the
S-expression, like so:

(let ((x 5)
      (y 6))
  (quasiquote (x (unquote x) y (unquote y)))) => (list 'x 5 'y 6)

I used the long form to avoid ambiguity, but that is the same as:

(let ((x 5)
      (y 6))
  `(x ,x y ,y)) => (list 'x 5 'y 6)

Where the comma is used as the unquote reader macro.

I apologize if this is review for you, but it's important to say because
this is exactly what is happening with #~ and #$. They are both reader
macros, that behave similarly to the quasiquote and unquote reader
macros: ` and ,.

(let ((x 5)
      (y 6))
  #~(x #$x y #$y))

Is the same as:

(let ((x 5)
      (y 6))
  (gexp (x (ungexp x) y (ungexp y))))

After expanding the reader macros.

I'm not sure about your package error, but I hope this helps point you
in the right direction :-)

Robby



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

* Re: Meaning of symbol prefixed with "#$"
  2023-05-26  1:43 Meaning of symbol prefixed with "#$" N. Y.
  2023-05-26  4:26 ` Robby Zambito
@ 2023-05-26 18:22 ` Daniel Meißner
  1 sibling, 0 replies; 3+ messages in thread
From: Daniel Meißner @ 2023-05-26 18:22 UTC (permalink / raw)
  To: guile-user

Hi Ning!

ningyuan.sg@gmail.com writes:

> Hi all,
> 
> I was wondering what is the meaning of symbols prefixed with "#$", for
> example "#$version" in Guix package definitions.
> 
> I was trying to write a package definition for a python package whose
> version number was intended to be inferred from git metadata during build
> time via versioneer. However, since Guix does not retain git metadata
> during build, the setup.py statement declaring the version number as to be
> inferred from git metadata had to be changed to refer to a simple version
> number string. I wrote,
> 
> #+begin_src
> (arguments
>   '(#:phases (modify-phases %standard-phases
>     (add-after 'unpack 'amend-version
>       (lambda _
>         (substitute* "setup.py"
>           (("versioneer.get_version\\(\\)")
>           (string-append "\"" #$version "\"")))))
> #+end_src
> 
> With reference to a patch describing the same issue with a different python
> package with the same inferred git metadata version number issue:
> https://issues.guix.gnu.org/63628#0-lineno26.
> 
> However, I get an error I do not understand:
> 
> #+begin_src
> starting phase `amend-version'
> error: in phase 'amend-version': uncaught exception:
> unbound-variable #f "Unbound variable: ~S" (ungexp) #f
> #+end_src
> 
> I thought I could begin to debug this by understanding what "#$" means in
> "#$version".

The problem in your package definition is that you use an ungexp form outside of a gexp form. The correct code could be (untested):

  (arguments
    (list
     #:phases
     #~(modify-phases %standard-phases
         (add-after 'unpack 'amend-version
           (lambda _
             (substitute* "setup.py"
               (("versioneer.get_version\\(\\)")
                (string-append "\"" #$version "\"")))))

As already mentioned by Robby #$version is equivalent to (ungexp version) and similar to quasiquotation in Scheme.

Also: Be sure to import the (guix gexp) module. Otherwise gexp and ungexp might not be defined.

Best

-- 
Daniel





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

end of thread, other threads:[~2023-05-26 18:22 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-26  1:43 Meaning of symbol prefixed with "#$" N. Y.
2023-05-26  4:26 ` Robby Zambito
2023-05-26 18:22 ` Daniel Meißner

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