美文网首页
iOS的block与编程思想(一)

iOS的block与编程思想(一)

作者: PepperCurry | 来源:发表于2017-01-11 11:09 被阅读46次

本文承接自上一篇《iOS的block与链式编程思想》

函数式编程

首先我们需要明白什么是函数式编程么?先说一点比较枯燥的概念,具体详细的定义可以详见维基百科,摘抄如下一段:
In computer science, functional programming is a programming paradigm—a style of building the structure and elements of computer programs—that treats computation as the evaluation of mathematical functions and avoids changing-state and mutable data.
我是这样理解的:
在计算机科学中,函数式编程是一种编程范型,是一种构建程序的数据结构和元素的方法。它将计算机运算视为数学上的函数计算,并且避免使用程序状态以及易变对象。
维基百科还提到函数编程语言最重要的基础是λ演算(lambda calculus)。λ演算中最关键的要素就是函数被当作变量处理,能够参与运算。
概念说的有些云里雾里的,为了刨根问底,百科中还介绍了函数式编程的几个特性:

First-class and higher-order functions:这样拆成两部分:First-class functions 和 higher-order functions,点进去分别的定义如下。

First-class functions:
In computer science, a programming language is said to have first-class functions if it treats functions as first-class citizens. Specifically, this means the language supports passing functions as arguments to other functions, returning them as the values from other functions, and assigning them to variables or storing them in data structures.[1] Some programming language theorists require support for anonymous functions (function literals) as well.
函数为“第一等公民”。这意味着这个语言支持函数作为其他函数的参数,也可以作为函数的返回值,并且可以被赋值给变量或者在数据结构中存储。一些编程语言也支持匿名函数或者函数字面量。
(感觉这明显说的就是block啊!)

Higher-order function
In mathematics and computer science, a higher-order function (also functional, functional form or functor) is a function that does at least one of the following:
takes one or more functions as arguments (i.e., procedural parameters),
returns a function as its result.

看到这里有点懵逼,这两个定义好相似啊。。不怪我们英语水平问题,确实很相似:
*Higher-order functions are closely related to first-class functions in that higher-order functions and first-class functions both allow functions as arguments and results of other functions. *

The distinction between the two is subtle: "higher-order" describes a mathematical concept of functions that operate on other functions, while "first-class" is a computer science term that describes programming language entities that have no restriction on their use (thus first-class functions can appear anywhere in the program that other first-class entities like numbers can, including as arguments to other functions and as their return values).
区别就是高阶函数描述的是数学概念上的函数操作,而一级函数是计算机科学中的专业名词。。

未完待续。。最近有点忙

相关文章

  • iOS的block与编程思想(一)

    本文承接自上一篇《iOS的block与链式编程思想》 函数式编程 首先我们需要明白什么是函数式编程么?先说一点比较...

  • RAC学习详解

    Block开发基础知识 链式编程思想简介 响应式编程思想简介 函数式编程思想简介 参考资料 iOS 关于MVC和M...

  • iOS的block与链式编程思想

    block的基础用法 首先拜一下官方的block图,忘了的时候瞅一眼。 如果您对block不是很熟悉,可以看下bl...

  • iOS RAC学习

    一、RAC使用基础认知 RAC编程思想:响应式编程+函数式编程 在iOS中,类之间的传值,无非就是block、de...

  • Block

    参考:Apple Block 源码Objective-C高级编程 iOS与OS X多线程和内存管理 Block与函...

  • IOS_编程思想_Block

    开启苹果自带的block代码块: 输入inlineBlock开启苹果自带的block代码块 举个例子 当返回值为i...

  • block编程, __block, __weak, __stro

    参考:block编程iOS __weak和__strong在Block中的使用__block & __weak &...

  • iOS链式、函数式和响应式编程

    原文编程思想-iOS链式、函数式和响应式编程 在了解链式、函数式和响应式编程前,我们需要回顾下Block,它在下面...

  • 一、链式编程思想、响应式编程思想和函数式编程

    1. 链式编程思想 链式编程思想的核心就是方法的返回值必须是Block,Masonry是链式编程思想应用的代表。 ...

  • 块与GCD

    没读这本书之前,我对 block理解的成长过程; block编程对于许多初识iOS编程的人来说,很难理解和运用,我...

网友评论

      本文标题:iOS的block与编程思想(一)

      本文链接:https://www.haomeiwen.com/subject/mrtrbttx.html