问题标签 [language-theory]
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.
python - python中的赋值符号实际上是什么?
大多数来源在线调用=(和+=,-=等...)赋值运算符(用于python)。这在大多数语言中是有意义的,但在 python 中则不然。运算符接受一个或多个操作数,返回一个值,然后形成一个表达式。但是,在python中,赋值不是表达式,赋值不会产生值。因此,= 不能是运算符。
那么它到底是什么?在像 x = 0 这样的语句中,x 是标识符,0 是数字文字,但我不知道如何称呼“=”。
programming-languages - 这种编程语言功能的名称是什么,是否有任何支持它的实际语言?
让树数据结构定义如下:
一棵树有一个节点作为它的根。节点要么是叶子,要么是具有一个或多个节点作为其子节点的内部节点。
在某种伪 OO 编程语言中,我们可以定义这样的树:
现在我们可以定义两个函数,“bad_code”和“good_code”。函数 'bad_code' 不编译,其他函数编译:
问题:
- 以上是否是以某种官方方式定义/描述的语言功能的示例?
- 如果是这样:这种语言功能的正式名称是什么?
- 是否有任何实现此语言功能的现实世界编程语言?
- 这种语言功能可以实现为运行时零成本的编译时检查吗?
c# - Why is TryParse the way round that it is?
I've been struggling to get my head around a natural way of using TryParse
because I keep expecting it to work the other way around (i.e. to return the parsed value and emit the boolean for whether the input parsed).
For example, if we take a basic implementation of Parse
, the return value is the parsed input:
This works fine until it gets a value that it can't parse, at which point it entirely reasonably throws an exception. To me, the option then is either to wrap the parse in something like a try-catch block to handle the exception and a condition to set a default, or just to use TryParse
to let C# do all that for me. Except that's not how TryParse
works. The above example now looks like this:
To get it to assign in the same way as Parse
, I wrap it in a ternary conditional with parsedValue
and a default value (in this case, 0) as the true
and false
results respectively:
But I still feel like I'm missing the point with TryParse
if I'm just working around its default behaviour like this. I've read Tim Schmelter's excellent answer in which he shows its internal workings, from which I can suppose that it returns the boolean because it's easier internally than passing it out at all the various places that it currently returns. But I'm not sure about this, and I'm not satisfied that I understand its intent correctly. I also tried reading the documentation for it, but the remarks don't clear up my confusion (I don't think they even make its differences with Parse
clear enough, like the change in return type).
Am I understanding it correctly, or am I missing something?
turing-machines - 图灵机中的递归与递归可枚举语言?
如果语言L由 TM决定,我们就说它是递归的。
如果L被TM识别,则它是递归可枚举(re) 的。
假设,枚举器( en-r ) 是一个确定性图灵机,其打印机从空白磁带开始,可以打印字符串 s1, s2, s3, s4... sn... 如果语言是无限的,则永远继续。
程序需要生成正在打印的字符串,所以这是一个图灵机,它在磁带上的某个地方生成语言中的所有字符串。我也可以在磁带上存储其他东西。
en-r 的语言是它打印的所有字符串的集合。En-r 是生成器机器,而不是识别器机器。
对于枚举器 EN,我们说 L(EN) = {s| EN 打印 s}。
关于这种情况,我有 3 个问题:
假设 L 是一个重集,那么我们如何使用识别器为 L 创建一个枚举器?
如果 L 是一种语言,并且有一个枚举器按升序枚举 L,那么为什么 L 是递归的?
为什么如果 L 是递归的,那么有一个 en-r 以递增的顺序枚举它?
谢谢
turing-machines - 集合在大小范围方面的可识别性
试图自学计算理论,偶然发现了这个问题:
假设我们有两个集合:
- {T | T 是图灵机,L(T) 至少包含 1001 个字符串}
- {T | T 是图灵机,L(T) 最多包含 1001 个字符串}
其中一个是可识别的,另一个则不是。
哪个是哪个,为什么?
直觉上,我认为具有“至少 1001 个字符串”的那个是无法识别的,因为它没有字符串数量的上限,所以这个数字可能是无限的,但同样一些无限的语言应该是可识别的。
我对这个问题很困惑。表明一组可识别而另一组不可识别的正确直觉和正式方法是什么?
language-features - 是否有编程语言中的变量“知道”它们自己的类型,并且可以检索、比较和打印该类型?
我最近在使用 Game Maker Language。作为一名 Fortran/C/C++ 程序员,我惊讶地发现那里的变量似乎“知道”它们的类型,并且这些信息可以在运行时以非常简单的方式在某种程度上使用。我不想深入研究 GML 的细节,所以我想稍微抽象一下这个问题:
是否存在类型信息表现为(可能是 const)字符串或枚举的语言,例如使以下操作(我将使用 C 风格,但当然细节无关紧要)成为可能,如果是,名称是什么那个语言功能?
假设我们已经声明了一个变量my_var
、一个被调用的超类foo
和一个子类bar
:
printf("The name of this type is %s\n", foo);
if(my_var == foo) printf("This variable holds %s\n", foo);
printf("%s superclass is %s\n", bar, bar.superclass);
context-free-grammar - aabbabb 是否属于正则表达式 ((a*| b*)bb)*?
我只是好奇 ((a*| b*)bb)* 是否意味着内括号中使用的任何数量的 a 或 b 都必须是固定的。就像如果我有 aabb,我不能用不同数量的 a 跟随它?`
像 abbaabb 或 a bbbabb 或 bbbaaabb 之类的东西是否属于正则表达式?
automata-theory - 是在编程语言中声明的变量**终端**符号或**非终端**符号
我对计算理论和自动机有疑问。是在编程语言终端符号或非终端符号中声明的变量。