You should have read Yariv's recless blog, a nice blog talking about how to make record accessing simple.
Recless is a static type inferring record parse transform, that means, as described in Yariv's blog:
one main restriction in Recless’s type inference algorithm: function parameters must indicate their record types for type inference to work on them. For instance, this won’t work:
get_name(Person) -> Person.name.
Instead, you must write this:
get_name(Person = #person{}) -> Person.name.
How about a dynamic record inferring solution? I got some idea that was also inspired from my friend Haobo. As I'm familiar with Erlang AST tree when developing ErlyBird, I took a try and got some good result. I named it recbird.
The magic behind recbird is, it parses the Erlang AST tree, and adds some setter/getter functions for each record's field. Then, at runtime, it will detect the first element of record var, and thus knows which setter/getter function should be rediected, and call it.
It just works now, with none limits, you can write R.a.b.c and R.a.b.c = Sth almost every where.
Notice: There may be some bugs.
The perfomance is also reasonable, for example, when you do R.a.b = 'yes' 1,000,000 times, the original Erlang record syntax takes about 300ms in my machine, the recbird is about 310ms. When you run it 10,000,000 times, the recbird is about 150% more time costed than original Erlang record accessing.
The recbird's source code can be got at:
recbird.erl
To use it, compile it, include compiled recbird.beam under your code path, add
-compile({parse_transform, recbird}).
in your source file.
分享到:
相关推荐
error: /tmp/esl-erlang_26.0.2-1~alinux~3_x86_64.rpm : not an rpm package (or packape manifest): arning: /tmp/rabbitmg-erver 3.12.4-1 all.rpm: Header V4 RSA/SHA512 Signature, key ID 6026dfca: NOKEY ...
标题中的“<27>erlang record”可能指的是Erlang编程语言中的Record特性,它是一种数据结构,类似于结构体或者哈希表,用于组织和操作数据。在Erlang中,Record提供了一种方便的方式来定义和访问具有固定字段的数据...
erlang_23.0.2-1版本 centos7 64bit esl-erlang_23.0.2-1_centos_7_amd64.rpm
Linux系统中的Erlang软件包是安装RabbitMQ消息队列服务器的重要前提,因为RabbitMQ是用Erlang编程语言编写的。Erlang是一种并发性极强、容错性高、适合构建分布式系统的语言,它在系统稳定性、可靠性和可扩展性方面...
esl-erlang_17.3-1~centos~6_amd64.rpm esl-erlang_17.3-1~centos~6_amd64.rpm
esl-erlang_24.2.1-1_centos_7_amd64.rpm
标题“esl-erlang_19.3_osx_10.10_amd64.dmg”指的是一个特定版本的Erlang编程环境的安装镜像文件,由Erlang Solutions Limited(ESL)发布,适用于Apple macOS 10.10 Yosemite操作系统,并且是为64位AMD处理器设计...
esl-erlang_25.0.3-1_centos_7_amd64.rpm erlang_25.0.3-1 rpm用于rabitmq基础环境安装
esl-erlang_16.b.3-2~centos~6_amd64.rpm
esl-erlang-20.1-1.x86_64只适用于Centos7; 安装命令:rpm -ivh --force esl-erlang-20.1-1.x86_64.rpm
esl-erlang_19.0~centos~6_amd64.rpm
此rpm包是专门为部署rabbitmq-server而准备的所需的包,centos7.5系统,相关博客详见https://blog.csdn.net/baidu_38432732/article/details/105813004
linux环境 erlang rpm包 esl-erlang_23.0.3-1~centos~7_amd64.rpm
esl-erlang_23.0和rabbitmq-3.8.4windows版本 直接下载安装就行,可以直接下载就可安装,非常的方便 ,欢迎大家下载 注意事项: 1. Erlang版本和RabbitMQ版本要配套 (Erlang23.0, RabbitMQ3.8.4) 2. amd芯片请乖乖...
**RabbitMQ 3.8.2 和 Erlang OTP Win64 22.2 安装指南** RabbitMQ 是一个广泛使用的开源消息代理和队列服务器,它基于 AMQP(Advanced Message Queuing Protocol)协议,适用于多种编程语言。在Windows系统上部署...
这个erlang23.0版本,根据rabbitMQ官网的介绍,可以和下面这几个版本的rabbitMQ配合使用: 3.8.9 3.8.8 3.8.7 3.8.6 3.8.5 3.8.4 其他版本的rabbit,请移步其他资源下载
This package contains the Erlang/OTP runtime implementation, which is configured and built with HiPE support (allows compiling to native code), and minimal set of Erlang applications: compiler - ...
在"Aerospike-client-erlang-2.1.2"这个压缩包中,包含的是Aerospike Erlang客户端的2.1.2版本。这个版本可能包含了对Aerospike C客户端的封装,C客户端是Aerospike官方提供的核心接口,它直接与数据库服务器进行低...
esl-erlang-compat-R14B-1.el6.noarch.rpm