为什么大多数“主流"广告系列不支持区间比较(例如:x <变量<y)语言? [英] Why are interval comparisons (e.g: x &lt; variable &lt; y) not supported in most &quot;mainstream&quot; languages?

查看:74
本文介绍了为什么大多数“主流"广告系列不支持区间比较(例如:x <变量<y)语言?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这可能是一个非常简单的问题,或者以前曾被问过,但在这里和通过Google进行简短搜索后,我找不到真正的答案.

This might be a very simple question, or perhaps have been asked before but I couldn't really find an answer after a brief search here and via google.

所以冒着错过与此类似的事情的风险,这是我的问题.为什么这样通常不支持检查间隔的条件语句,而是将其实现为块if或使用&&运算符将两个独立的条件绑定在一起?

So taking the risk of having missed something similar to this, here goes my question. Why is it so that conditional statements checking for intervals are often not supported as they are, but instead implemented as block ifs or using the && operator to bind together the two separate conditions?

承认如果我必须编写两行以上的代码,这不是整个世界,但是来自数学背景,我发现现代编译器无法在此相对简单的语句上进行伏都教是非常奇特的.

Admitted that it's not the whole world if I have to write two lines of more code, but coming from mathematics background, I find it really peculiar that modern compilers cannot do their voodoo on this relatively simple statement.

从技术或理论角度来看,是否有特定原因?

Is there a particular reason for it for a technical or theoretical perspective?

推荐答案

我会说从技术角度来看没有障碍,因为某些语言确实支持这种比较:

I would say that there is no impediment from a technical point of view since some languages do support that kind of comparison:

  • Python(文档)
  • Clojure(文档)-以及几乎所有其他的卑鄙的语言
  • Perl 6(文档)
  • Python (docs)
  • Clojure (docs) -and almost any other lispy language out there
  • Perl 6 (docs)

如果我没记错的话还有Mathematica.

And Mathematica if I remember right.

可以肯定的是,这会使语言的解析变得更加复杂,并且如果语言设计人员不认为它是经常使用的功能,则语言设计人员可能会或可能不会为此付出代价.

What it is sure is that it makes the parsing of the language a bit more complex, and language designers may or may not pay that price if they don't see it as a feature to be used very frequently.

ps.我个人喜欢它,但发现自己很少在Python中使用它.

ps. I personally like it but have found myself rarely using it in Python.

这篇关于为什么大多数“主流"广告系列不支持区间比较(例如:x <变量<y)语言?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆