是“地图”一个循环? [英] Is "map" a loop?

查看:120
本文介绍了是“地图”一个循环?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在回覆此问题,我意识到我不知道Perl的地图是否可以被认为是循环?

While answering this question, I came to realize that I was not sure whether Perl's map can be considered a loop or not?

一方面,它像一个循环(O(n))工作,可以很容易地通过等效的循环重写,并且符合通用定义=连续重复的指令序列的排序。

On one hand, it quacks/walks like a loop (does O(n) work, can be easily re-written by an equivalent loop, and sort of fits the common definition = "a sequence of instructions that is continually repeated").

另一方面,Perl的控制结构通常不列出 map ,其中的循环是。例如。 http://en.wikipedia.org/wiki/Perl_control_structures#Loops

On the other hand, map is not usually listed among Perl's control structures, of which loops are a subset of. E.g. http://en.wikipedia.org/wiki/Perl_control_structures#Loops

所以,我正在寻找的是一个正式的理由相信一方与另一方。到目前为止,前者(这是一个循环)对我来说听起来更加令人信服,但是我从来没有看到Perl循环列表中提到的map这个事实感到困扰。

So, what I'm looking for is a formal reason to be convinced of one side vs. the other. So far, the former (it is a loop) sounds a lot more convincing to me, but I'm bothered by the fact that I never saw "map" mentioned in a list of Perl loops.

推荐答案

map是一个比循环更高级的概念,从功能编程中借来。它不会说从开始到结束一个接一个地对这些项目中的每个项目调用这个函数,它说在所有这些项目上调用这个函数。它可能被实现为循环,但这不是重点 - 它也可能是异步实现的 - 它仍然是映射。

map is a higher level concept than loops, borrowed from functional programming. It doesn't say "call this function on each of these items, one by one, from beginning to end," it says "call this function on all of these items." It might be implemented as a loop, but that's not the point -- it also might be implemented asynchronously -- it would still be map.

此外,它不是真的控制结构本身 - 如果在其实现中使用循环的每个perl功能都列在循环下?只是因为某些东西是使用循环来实现的,并不意味着它应该被认为是它自己的循环类型。

Additionally, it's not really a control structure in itself -- what if every perl function that used a loop in its implementation were listed under "loops?" Just because something is implemented using a loop, doesn't mean it should be considered its own type of loop.

这篇关于是“地图”一个循环?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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