散列前面的+的历史记录是否可以从代码块中消除歧义? [英] What's the history of the + in front of a hashref that disambiguates from a code block?

查看:96
本文介绍了散列前面的+的历史记录是否可以从代码块中消除歧义?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想多读一点关于通常放在hashref前面的+,这有助于从代码块中消除歧义。




  • 什么时候首次推出?


  • 谁第一次推出它(推荐它)? $ b

  • 人们在介绍之前是如何解决问题的?

  • 任何琐事或笔记想一想使用这种语法? 来自匿名hashref构造函数的代码块不能比匿名hashref构造函数更早,该匿名hashref构造函数早在1993年4月被添加了Perl 5.0。在此之前,这个问题并不存在。



    但是unary plus已经存在了很长时间 - 至少从Perl 4开始(它不在Perl中1,但根据我的知识,它可以在几年之间的任何时间加入)。它总是做同样的事情,迫使其RHS被评估为一个术语,而不是其他任何可能在上下文中有意义的东西,并区分,例如:

      print(1 + 2),42; #对42没有用处! 

    from

      print +(1 + 2),42; #打印3和42. 


    I would like to read a little more about the + that is usually put in front of a hashref that helps to disambiguate from a code block.

    • When was it first introduced?

    • Who first introduced it (recommended it)?

    • How did people go around the issue before this was introduced?

    • Any trivia or notes that comes to mind while using this syntax?

    解决方案

    The specific case of disambiguating a codeblock from the anonymous hashref constructor can't be older than the anonymous hashref constructor, which was added with Perl 5.0 back in 1993-4. Before then the problem didn't exist.

    But the "unary plus" has been around for longer -- since Perl 4 at least (it wasn't there in Perl 1 but it could have been added any time in the intervening few years, as far as my knowledge goes). It's always done the same thing, forcing its RHS to be evaluated as a term rather than anything else that might make sense in context, and distinguishing, for example:

    print (1 + 2), 42; # Does nothing useful with 42!
    

    from

    print +(1 + 2), 42; # Prints 3 and 42.
    

    这篇关于散列前面的+的历史记录是否可以从代码块中消除歧义?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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