短路求值(Short-circuit evaluation)

短路求值是一种在布尔表达式求值时仅根据首个操作数确定结果的策略,常用于AND和OR操作。在C程序和Lisp中,这种机制可以避免不必要的计算或潜在错误。然而,它可能导致某些情况下预期外的行为,如资源分配问题。并非所有语言都支持短路求值。
摘要由CSDN通过智能技术生成

短路求值

Short-circuit evaluation

最早是在php中接触到的这种求值,后来在学习Lisp中又一次接触到了,于是想写一篇文章记录一下,并分享一下,这个被我忽略的可能可以说是细节的点吧

什么是短路求值(Short-circuit evaluation)

以下摘自Short-circuit evaluation

Short-circuit evaluation, minimal evaluation, or McCarthy evaluation (after John McCarthy) is the semantics of some Boolean operators in some programming languages in which the second argument is executed or evaluated only if the first argument does not suffice to determine the value of the expression: when the first argument of the AND function evaluates to false, the overall value must be false; and when the first argument of the OR function
evaluates to true, the overall value must be tru

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值