8
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Elixir その2Advent Calendar 2020

Day 21

1260 (Elixir 1.11.2-otp-23)

Last updated at Posted at 2020-12-20

この記事はElixir その2 Advent Calendar 2020 21日目です。
前日は、@mnishiguchiさんの「[Elixir] Referenceの作り方」 でした。
6日間ありがとうございました。残りはお任せください。


はじめに

  • Elixir楽しんでいますか!
  • さて、1260とはなんでしょうか

答え

  • Elixir 1.11.2-otp-23にある関数の数です

どうやって数えたの?

とても参考にしたページ

こんな感じ

:code.all_loaded()
|> Enum.filter(fn {mod, _} -> "#{mod}" =~ ~r{^[A-Z]} end)
|> Enum.map(fn {mod, _} -> mod end)
|> Enum.reduce(%{}, fn mod, acc -> 
  Map.put(acc, mod, mod.__info__(:functions))
end)

結果

%{
  Supervisor.Default => [init: 1],
  Module => [
    __get_attribute__: 3,
    __put_attribute__: 4,
    add_doc: 5,
    add_doc: 6,
    check_behaviours_and_impls: 4,
    compile_definition_attributes: 6,
    concat: 1,
    concat: 2,
    create: 3,
    defines?: 2,
    defines?: 3,
    defines_type?: 2,
    definitions_in: 1,
    definitions_in: 2,
    delete_attribute: 2,
    eval_quoted: 2,
    eval_quoted: 3,
    eval_quoted: 4,
    get_attribute: 2,
    get_attribute: 3,
    has_attribute?: 2,
    make_overridable: 2,
    open?: 1,
    overridable?: 2,
    put_attribute: 3,
    register_attribute: 3,
    safe_concat: 1,
    safe_concat: 2,
    spec_to_callback: 2,
    split: 1
  ],
  Inspect.Atom => [__impl__: 1, inspect: 2],
  Inspect => [__protocol__: 1, impl_for: 1, impl_for!: 1, inspect: 2],
  Access => [
    all: 0,
    at: 1,

数を数えてみよう

:code.all_loaded()
|> Enum.filter(fn {mod, _} -> "#{mod}" =~ ~r{^[A-Z]} end)
|> Enum.map(fn {mod, _} -> mod end)
|> Enum.reduce(%{}, fn mod, acc ->
  Map.put(acc, mod, mod.__info__(:functions))
end)
|> Enum.reduce(0, fn {_, funs}, acc -> acc + Enum.count(funs) end)
  • 一回マップにする必要はありませんが、まあ、さっきのプログラムを利用して足してみましたですよ

Wrapping Up :christmas_tree::santa::santa_tone1::santa_tone2::santa_tone3::santa_tone4::santa_tone5::christmas_tree:

8
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?