JuliaKurs23/notebooks/nb-types.ipynb

183 lines
4.1 KiB
Plaintext
Raw Permalink Normal View History

2023-05-12 20:12:56 +02:00
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "46e9fc16",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"629"
]
},
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"#| label: nb4\n",
"#| echo: true\n",
"length(subtypes(Any))"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "9feb9e06",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Number\n",
" Complex\n",
" Real\n",
" AbstractFloat\n",
" BigFloat\n",
" Float16\n",
" Float32\n",
" Float64\n",
" AbstractIrrational\n",
" Irrational\n",
" Integer\n",
" Bool\n",
" Signed\n",
" BigInt\n",
" Int128\n",
" Int16\n",
" Int32\n",
" Int64\n",
" Int8\n",
" Unsigned\n",
" UInt128\n",
" UInt16\n",
" UInt32\n",
" UInt64\n",
" UInt8\n",
" Rational\n"
]
}
],
"source": [
"#| label: nb1\n",
"#| echo: true\n",
"\n",
"function show_subtype_tree(T, i=0)\n",
" println(\" \"^i, T)\n",
" for Ts ∈ subtypes(T)\n",
" show_subtype_tree(Ts, i+1)\n",
" end\n",
"end\n",
"\n",
"show_subtype_tree(Number)"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "fe5594b9",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Number\n",
"├─ Complex\n",
"└─ Real\n",
" ├─ AbstractFloat\n",
" │ ├─ BigFloat\n",
" │ ├─ Float16\n",
" │ ├─ Float32\n",
" │ └─ Float64\n",
" ├─ AbstractIrrational\n",
" │ └─ Irrational\n",
" ├─ Integer\n",
" │ ├─ Bool\n",
" │ ├─ Signed\n",
" │ │ ├─ BigInt\n",
" │ │ ├─ Int128\n",
" │ │ ├─ Int16\n",
" │ │ ├─ Int32\n",
" │ │ ├─ Int64\n",
" │ │ └─ Int8\n",
" │ └─ Unsigned\n",
" │ ├─ UInt128\n",
" │ ├─ UInt16\n",
" │ ├─ UInt32\n",
" │ ├─ UInt64\n",
" │ └─ UInt8\n",
" └─ Rational\n"
]
}
],
"source": [
"#| label: nb2\n",
"#| echo: true\n",
"using AbstractTrees\n",
"\n",
"AbstractTrees.children(x::Type) = subtypes(x)\n",
"print_tree(Number)"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "0dcccd86",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"4-element Vector{Any}:\n",
" AbstractFloat\n",
" AbstractIrrational\n",
" Integer\n",
" Rational"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"#| label: nb3\n",
"#| echo: true\n",
"subtypes(Real)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "dfabcc51",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"@webio": {
"lastCommId": null,
"lastKernelId": null
},
"kernelspec": {
"display_name": "Julia 1.8.5",
"language": "julia",
"name": "julia-1.8"
},
"language_info": {
"file_extension": ".jl",
"mimetype": "application/julia",
"name": "julia",
"version": "1.8.5"
}
},
"nbformat": 4,
"nbformat_minor": 5
}