Erlang中的函数链接 [英] Function chaining in Erlang

查看:65
本文介绍了Erlang中的函数链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

创建像Active Record或Hibernate这样的ORM很好,它应该像这样处理链接的查询:

It would be nice to create ORM like Active Record or Hibernate, it should process chained queries like this:

User = User:new():for_login(«stackoverflow_admin»):for_password(«1984»):load().

我们该怎么做?还是这样,在一行中-或至少在精神和含义上相似。

How can we do this? Or just like that, in one line - or at least similar in spirit and meaning.

也许有一些预处理工具可以帮上忙?

Maybe there are some preprocessing tools that can help in this?

推荐答案

尽管我发现 @ zxq9 回答因此,内容丰富,在Erlang中模仿类似Java的OOP样式的历史可能会有所帮助。

Although I found @zxq9 answer so informative, mentioning the history of imitating Java-like OOP style in Erlang could be helpful.

方法链接需要 state ,并且已经在努力在Erlang中包括状态模块:

Method chaining needs state and there were efforts to include "Stateful Modules" into Erlang:


  • 参数化模块:一种建议,使开发人员可以实现接受参数的模块并将其作为模块状态保存在其功能中使用。很久以前,它已作为实验功能添加到Erlang中,但技术委员会决定删除 R16对此功能的语法支持,因为它引起了概念上和实践上的不兼容性。

  • Parametrized Module: A proposal that lets developer to implement modules that accept parameters and hold them as a module state to use in its functions. Long ago it had been added to Erlang as an experimental feature, but the technical board decided to remove the syntactic support for this feature in R16 because of both conceptual and practical incompatibilities that it caused.

元组模块:参数化模块的向后兼容性,在对Erlang(第二版)进行编程,但是没有官方文档,它仍然是有争议的功能,它以Erlang方式引入了复杂性和歧义性,没有任何作用。

Tuple Module: A backwards compatibility for parametrized module, which also introduced in details in chapter 8 of Programming Erlang (Second Edition), but there is no official documentation for it and it is still a controversial feature that introduces complexity and ambiguity with no power in the Erlang way.

模仿不同语言的编码方式诸如erlang中的Ruby和Java之类的t语言范例是一种具有不同概念的功能语言,可能会令人兴奋,但没有附加值。

Imitating coding style of languages with different paradigms like Ruby and Java in Erlang which is a functional language with different concepts could be exciting but with no added value.

这篇关于Erlang中的函数链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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