什么是函数响应式编程

Python043

什么是函数响应式编程,第1张

函数响应式编程(Functional Reactive Programming:FRP)是一种和事件流有关的编程方式,其角度类似EventSoucing,关注导致状态值改变的行为事件,一系列事件组成了事件流。

FRP是更加有效率地处理事件流,而无需显式去管理状态。

具体来说,FRP包括两个核心观点:

1.事件流,离散事件序列

2.属性properties, 代表模型连续的值。

一系列事件是导致属性值发生变化的原因。FRP非常类似于GOF的观察者模式。

#include <stdio.h>

#include <ctype.h>

#include <stdlib.h> 

int main(void)

{

 float  *data = NULL

 char  buf[32]

 FILE  *fp = NULL

 int  i = 0

 

 if((fp = fopen("test.txt", "r")) == NULL)

 {

  printf("open file error!\n")

  return -1

 }

 data = (float*)malloc(sizeof(float) * 120000)//分配内存存储数据

 if(data == NULL)

 {

  printf("momery error!\n")

  return -1

 }

 while(fgets(buf, 30, fp))

 {

  *(data + i) = atof(buf)

  printf("%f\n", *(data + i))

  i ++ 

 }//data就是你要的数组

 

 free(data) //释放内存

 fclose(fp)

 

 return 0

}