gpt4 book ai didi

nix - 当函数定义中没有使用问号时,Nix 中的问号是什么意思?

转载 作者:行者123 更新时间:2023-12-05 02:42:58 24 4
gpt4 key购买 nike

我知道 a similar question , 但它指的是 ?function definitions with a set pattern 中使用(pinned)。

我查看了 lib.makeOverridable 的实现并发现了 this line :

  ${if result ? overrideAttrs then "overrideAttrs" else null} = fdrv:

(还了解到这种动态分配是可能的,所以这是一个奖励。)

最佳答案

根据 15.3. Operators 处的表格( pinned ) 在 Nix manual 中:

表 15.1。运算符

| Name          | Syntax       | Description                     |
+---------------+--------------+---------------------------------+
| | | Test whether set e contains the |
| Has Attribute | e ? attrpath | attribute denoted by attrpath; |
| | | return true or false. |
+---------------+--------------+---------------------------------+

例子:

$ nix repl
Welcome to Nix version 2.3.10. Type :? for help.

nix-repl> set = { a = 27; b = "lofa"; }

nix-repl> set ? a
true

nix-repl> set ? lofa
false

nix-repl> supset = { c = set; d = 7; }

nix-repl> supset ? c.a
true

关于nix - 当函数定义中没有使用问号时,Nix 中的问号是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67150458/

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