gpt4 book ai didi

nix - 从 Nix 表达式语言中的另一个集合继承属性

转载 作者:行者123 更新时间:2023-12-04 15:55:49 27 4
gpt4 key购买 nike

在 Nix 手册的 Inheriting attributes 中部分,我们有

graphviz = (import ../tools/graphics/graphviz) {
inherit fetchurl stdenv libpng libjpeg expat x11 yacc;
inherit (xlibs) libXaw;
};

xlibs = {
libX11 = ...;
libXaw = ...;
...
}

libpng = ...;
libjpg = ...;
...
import ...周围的括号是什么意思(即 (import ../tools/graphics/graphviz) )吗?另外, inherit (xlibs) libXaw;中的括号是什么意思?做?

最佳答案

xlibs与 graphviz 处于同一范围内,但 libXaw不是,因为它在 xlibs 里面放。因此,为了能够将其作为参数传递给 graphviz 函数,您需要明确 inherit (xlibs) libXaw .括号中表示的行为是 inherit 独有的。关键词。
(import ../tools/graphics/graphviz)中的括号只是表示评估顺序的通用约定。 import是一个接受单个参数的函数 path . ../tools/graphics/graphviz 中的文件包含一个接受一组属性作为其参数的函数。所以括号表示求值的顺序应该是 (1) 导入 path 中的函数然后 (2) 应用属性集 {...}到那个功能。

编辑:@danbst 指出,在这种情况下,import ../tools/graphics/graphviz 中的括号不需要。这样做的原因是评估 import ../tools/graphics/graphviz返回一个函数,然后使用集合 { ... } 调用该函数.

括号的必要性可以通过使用相同的值作为此函数的参数来证明 typesOfArgs = one: two: with builtins; "${typeOf one} and ${typeOf two}"它返回一个字符串。 typesOfArgs (import ../tools/graphics/graphviz) { }将评估为 "lambda and set"但如果没有括号,解释器将评估 typesOfArgs import ../tools/graphics/graphviz"lambda and path"然后尝试将该字符串作为带有参数 { } 的函数调用这将导致 error: attempt to call something which is not a function but a string
如果没有括号,解释器会假设您要调用函数 import带有 2 个参数 path{ ... } ,这将是一个错误。

关于nix - 从 Nix 表达式语言中的另一个集合继承属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41195309/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com