[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Calling functions in `make-flags'
From: |
Mark H Weaver |
Subject: |
Re: Calling functions in `make-flags' |
Date: |
Sun, 23 Feb 2014 01:20:47 -0500 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) |
Sree Harsha Totakura <address@hidden> writes:
> Can you explain why my earlier code did not work?
Your earlier code was:
> (arguments
> '(#:make-flags '((string-append "SH=" (which "sh")))
The expression immediately following "#:make-flags" is evaluated to
produce the list of make flags. In this case, that expression is:
'((string-append "SH=" (which "sh")))
The single-quote at the beginning means that this is a literal
expression. In other words, it inhibits evaluation of all nested forms
within, and simply returns the following datum:
((string-append "SH=" (which "sh")))
i.e. a list containing one element:
(string-append "SH=" (which "sh"))
which is a list whose first element is the symbol 'string-append', whose
second element is the string "SH=", etc.
What you want it to return is something like this:
("SH=/nix/store/1bjqv56slfsgpfs0dngj9zww1mx9ikny-bash-4.2/bin/sh")
In other words, you need it to evaluate (string-append "SH=" ...)
instead of returning that code as a data structure.
One way to do this is to use (list (string-append "SH=" ...)). Whereas
the single-quote inhibits evaluation of all forms within, 'list' is a
normal procedure that evaluates its arguments before combining the
results into a list.
Another way is to use quasiquote (`), and to unquote (,) the inner
expressions that you'd like to evaluate:
`(,(string-append "SH=" ...))
In this case, I think the quasiquote doesn't add much readability, but
it's a matter of taste I suppose.
As for why 'which' didn't work, I suspect it's because this code is
evaluated very early in the build process, before the PATH variable has
been set.
You can use 'which' in the code segments passed to #:phases because
those are wrapped with 'lambda', which defines an anonymous procedure.
The procedure returned by that lambda expression is not called until
it's time to run the phase. At that point, PATH is set.
Does that make sense?
Regards,
Mark