简体   繁体   中英

find parameter types in an erlang module

after searching, I couldn't find how to get the type of parameters in an erlang module. 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
  • 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)
  • 3/ show parameter types in the above founded function -> I got stuck at this ...

An example:

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

    • Module_Name: application
    • Function_Name: load
    • Number of params: 6
    • Param lists:

      • "1" ---> type: string
      • 2 ---> type: integer
      • "3" ---> type: string
      • {123, "2\\"{[1234", 123} ---> type: 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

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:

-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() . Dialyzer is the only thing that can help, perhaps checking dialyzer:plt_info(Plt)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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