简体   繁体   English

在erlang模块中查找参数类型

[英]find parameter types in an erlang module

after searching, I couldn't find how to get the type of parameters in an erlang module. 搜索后,我找不到如何在erlang模块中获取参数类型。 For more clear, this is what I'm trying to do: 更清楚地说,这就是我想要做的:

  • 1/ show all loaded erlang modules by: erlang:loaded() -> this returns a list of atoms which are modules names 1 /通过以下方式显示所有已加载的erlang模块: erlang:loaded() ->这将返回原子列表,这些原子是模块名称
  • 2/ show all exported functions for a module by this: Module:module_info(exports) -> this returns a list of tuples which are likely this: {function_name, number_of_parameters) 2 /通过以下方式显示模块的所有导出函数: Module:module_info(exports) ->这将返回一个可能是这样的元组列表:{function_name,number_of_parameters)
  • 3/ show parameter types in the above founded function -> I got stuck at this ... 3 /在上面建立的函数中显示参数类型->我被困在这里...

An example: 一个例子:

  • Input: application:load("1", 2, "3", {123, "2\\"{[1234", 123}, ad, <<"asa]}\\">>\\", 2, 300:16>>). 输入: application:load("1", 2, "3", {123, "2\\"{[1234", 123}, ad, <<"asa]}\\">>\\", 2, 300:16>>).
  • Output: 输出:

    • Module_Name: application Module_Name:应用程序
    • Function_Name: load Function_Name:加载
    • Number of params: 6 参数数量:6
    • Param lists: 参数列表:

      • "1" ---> type: string
      • 2 ---> type: integer
      • "3" ---> type: string
      • {123, "2\\"{[1234", 123} ---> type: tuple` {123, "2\\"{[1234", 123} --->类型:tuple`
      • ad ---> type: atom
      • <<"asa]}\\">>\\", 2, 300:16>> ---> type: binary

Solved 解决了

my problem was solved at this: erlang parse string to data types using regex 我的问题在此得到解决: erlang使用正则表达式将字符串解析为数据类型

I'm not aware that this is possible, the way you describe parameters in Erlang is using spec annotations in your code, but not all the code out there is well documented and using specs like: 我不知道这是可能的,您在Erlang中描述参数的方式是在代码中使用规范注释,但并非所有代码都已被很好地记录在案,并使用如下规范:

-spec Module:Function(ArgType1, ..., ArgTypeN) -> ReturnType.

Also, a function can take different argument types and use guards for different handling of the input. 同样,函数可以采用不同的参数类型,并使用防护措施来对输入进行不同的处理。 Or even use syntactic sugar on records to create custom types or use any() . 甚至在记录上使用语法糖来创建自定义类型或使用any() Dialyzer is the only thing that can help, perhaps checking dialyzer:plt_info(Plt) 透析器是唯一可以帮助的事情,也许检查dialyzer:plt_info(Plt)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM