官术网_书友最值得收藏!

Getting more information with the i helper

IEx has a really handy helper function available to us: i. This function comes in two separate arities, i/0 and i/1 (arities, in this case, being the number of arguments that we have to supply to each version of the function). i/0 displays information about the last value output in IEx, whereas i/1 displays information about a particular value or variable. Let's take a look at a few examples:

iex(3)> x = 5
5
iex(4)> i
Term
5
Data type
Integer
Reference modules
Integer
Implemented protocols
IEx.Info, Inspect, List.Chars, String.Chars

Let's talk about what the preceding example is giving us. First, it tells us the Term, which almost literally means the value itself. Next, we have the Data type, which tells us what Elixir is classifying this particular value as (in the example, it's an integer). Next, it tells us the Reference modules, which is a fancy way of telling us what modules we should use to be able to interact with this particular data type. Finally, it gives us a list of implemented protocols. These are additional modules that provide some sort of behavior that we expect that data type to adhere to if it implements a particular behavior. You can think of them as being similar in concept to interfaces in other programming languages.

主站蜘蛛池模板: 禹州市| 固镇县| 芜湖市| 邹城市| 昭通市| 黎平县| 新丰县| 肥西县| 怀远县| 府谷县| 崇左市| 甘南县| 林州市| 教育| 廉江市| 大埔区| 沐川县| 灵寿县| 瓦房店市| 潞城市| 大田县| 江孜县| 襄垣县| 开鲁县| 宁远县| 华蓥市| 大港区| 苍山县| 金堂县| 和龙市| 施甸县| 丹巴县| 米易县| 定南县| 东阿县| 瓦房店市| 阿拉尔市| 唐海县| 锦屏县| 卫辉市| 洮南市|