问题标签 [name-binding]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
2 回答
181 浏览

haskell - 正确标记 AST

我一直在尝试构建标记的 AST 一段时间。我们来介绍一下这个问题:

对我来说,那段代码的问题在于FooIntBool. 这个想法是它需要一个int表达式和一个bool表达式,并将它们粘合在一起。但E a可以是任何东西。鉴于上述定义,这将是有效的E

你可以看到问题。那么,我们想要什么?带标签的表达式。鉴于 E 的当前定义,这是不可能的,所以让我们介绍一些GADT

这是相当不错的!我现在可以纠正这种代码:

问题是当我想让它成为单子或应用程序时。这是不可能的。考虑 monad 的实现:

这是显而易见的,直截了当。让我们看看绑定实现:

我们不能写a >>= fb >>= f因为f :: a -> E l b. 我还没有找到解决这个问题的方法,我真的很好奇如何处理这个问题并且仍然能够使用 de Bruijn 索引(通过bound)。

0 投票
1 回答
282 浏览

c++ - 实例化点和名称绑定

我对以下示例的实例化点感到困惑:

我虽然 f 是一个从属名称,而 1. 是 g< int > 的实例化点,而 2. 是 g< double > 的实例化点,所以 f(double) 对于 g(1.1) 是可见的,但是输出是

如果我在 3 处评论 f(int) 的声明,gcc 会报告错误(并不奇怪)并指出 4 处的 f(t) 是实例化点(惊讶!!)。

任何人都可以为我清除实例化点和名称绑定的概念吗?

0 投票
1 回答
74 浏览

python - Python; 名称绑定不是对象引用?

我试图了解 Python 名称绑定到底是什么,以及何时解释此绑定。

在 c 中,

打印 666。我期待 Python 代码块:

做同样的事情,但事实并非如此。标记为 3 和 5 的行之间究竟发生了什么?#3 是否再次引用称为“42”的对象,例如 X,我们将其称为 X',并将 X' 存储在 L 指向的对象中,即 []?

0 投票
2 回答
2089 浏览

python - Saving the current value of a variable for later use in a local scope

I want to to create functions in a loop, depending on the loop variable (for use with PyQT), but the functions are not "dereferencing" the loop variable as I want. (I don't know the proper terminology, so forgive my sloppiness.) This is a simple example:

I'd want b to be a list of functions, each printing the corresponding element of a (at the time of definition, they shouldn't change if a is modified later). As suggested in the links, func = lambda item=item: print(item) fixes this simple case, but I can't make my PyQT case work with the same fix:

I want to pass an xml.etree element, but if I use the lambda function, what I get is only False. With explicit creation of each button, everything works fine.

0 投票
3 回答
2464 浏览

java - JAX RS,我的过滤器不工作

我正在研究:使用 JAX-RS 和 Jersey 进行基于 REST 令牌的身份验证的最佳实践

但是我的过滤器没有触发,我的呼叫直接传递到端点......

我的安全界面:

我的过滤器:

我的端点:

还有我的 web.xml(没关系??):

我在堆栈中阅读了很多相关的问题,但找不到错误。

有人知道吗?

提前致谢。

0 投票
1 回答
721 浏览

c++ - At which point occurs template Instantiation binding?

This code is from "C++ programming language" by Bjarne Stroustrup (C.13.8.3 Point of Instantiation Binding)

And he mentions:

Here, the point of instantiation for f() is just before h(), so the g() called in f() is the global g(int) rather than the local g(double). The definition of ‘‘instantiation point’’ implies that a template parameter can never be bound to a local name or a class member.

My questions are:

  1. Why should the first code work? g() is declared later, and I really get an error with G++ 4.9.2 that g isn't declared at that point.

  2. extern g(double) - how this works? since return value doesn't matter in case of function overloading, then we can miss it in forward declarations?

  3. the point of instantiation for f() is just before h() - why? isn't it logical that it'll get instantiated when f(2) is being called? Right where we call it, whence g(double) will be in scope already.

  4. The definition of ‘‘instantiation point’’ implies that a template parameter can never be bound to a local name or a class member - Has this changed in C++14? I'm getting error with C++(G++ 4.9.2), but don't get error with C++14(G++ 4.9.2).

0 投票
5 回答
16595 浏览

javascript - 当 JavaScript 变量名和函数名相同时会发生什么?

我有以下代码,我在其中声明了一个函数,然后声明了一个与函数同名的变量:

我希望这会 alert undefined,但如果我运行它,警报将显示以下内容:

函数 a(x) {
    返回 x * 2
}

如果我为变量赋值(如var a = 4),警报将显示该值(4),但如果没有此更改,a将被识别为函数。

为什么会这样?

0 投票
0 回答
96 浏览

javascript - JS有名称绑定操作吗?

我是js的新手。让我用几个例子来说明我的问题。

代码 1

这里result出乎意料。

代码 2

现在这result就是我想要的。

它看起来像 Python 中的名称绑定操作。但我google了很多,无法得到满意的答案。所以我不得不求助于stackoverflow。

我的问题:

JS有没有类似Python的名字绑定操作?如果不是,为什么这两段代码会得到不同的结果?

[编辑]

我知道C++ 中的引用和 Python 中的名称绑定。而且我也知道这两者之间的区别。

我唯一感到困惑的是:在 JS 中,它是引用还是名称绑定?或者是其他东西?

感谢所有评论,我完全理解它与name binding而不是reference相似。(因为我找不到任何按钮来关闭这个问题,所以我在这里添加了答案。)

0 投票
1 回答
174 浏览

python - 就名称对象绑定而言,当我在 python 中创建诸如 c=[1] 之类的列表时会发生什么?

阅读http://www.effbot.org/zone/python-objects.htm后,我留下了这个问题:

在 python 中,如果a=1创建一个整数对象并将其绑定到 name ab=[]创建一个空列表对象并将其绑定到 name b,当我调用 eg 时会发生什么c=[1]

我想这会创建一个 list-object 并将其绑定到 name c,但究竟是如何1处理的呢?列表对象的实际内容在幕后是什么样子的?它是由整数对象还是对“单独”整数对象的引用组成?可以将例如c[0]视为绑定到列表项的名称吗?

那么以下内容呢:

列表对象(命名e)的内容是对被调用的整数对象的引用d还是新的整数对象?

我想答案就在上面提到的来自 Lundh 先生的这句话中,但我仍然有点困惑:

然后,您在该对象上调用一个方法,告诉它将一个整数对象附加到自身。这会修改列表对象的内容,但不会触及命名空间,也不会触及整数对象。

我也相信部分答案可以在这里找到:Python;名称绑定不是对象引用?,但我仍在寻找更多的见解。

0 投票
0 回答
42 浏览

python - python trie实现-函数运行时全局引用发生变化

我正在尝试在 python 中实现一个 trie。这是我的课:

然后我创建了一个简单的函数来为 trie 添加一个名称:

问题是函数 add_contact 正在改变全局变量 trie。我猜“node”和“trie”是同一事物的不同名称,但我尝试使用 copy() 并且它根本没有用。有谁知道我该如何正确地做到这一点?谢谢!