1{
2 "cells": [
3 {
4 "cell_type": "markdown",
5 "id": "ns-0",
6 "metadata": {},
7 "source": "# Namespaces and packages\n\nMATLAB organizes code into packages using `+folder` directories, referenced\nwith dotted names. numbl supports these, including nested packages, classes\ninside packages, and `import`."
8 },
9 {
10 "cell_type": "markdown",
11 "id": "ns-1",
12 "metadata": {},
13 "source": "## Calling package functions\n\n[+geom/circle_area.m](./+geom/circle_area.m) is reached as\n`geom.circle_area`. Packages nest: [+geom/+util/deg2rad.m](./+geom/+util/deg2rad.m)\nis `geom.util.deg2rad`."
14 },
15 {
16 "cell_type": "code",
17 "id": "ns-2",
18 "metadata": {},
19 "execution_count": null,
20 "outputs": [],
21 "source": "geom.circle_area(2)\ngeom.util.deg2rad(180)"
22 },
23 {
24 "cell_type": "markdown",
25 "id": "ns-3",
26 "metadata": {},
27 "source": "## import brings names into scope"
28 },
29 {
30 "cell_type": "code",
31 "id": "ns-4",
32 "metadata": {},
33 "execution_count": null,
34 "outputs": [],
35 "source": "import geom.util.deg2rad\ndeg2rad(90)"
36 },
37 {
38 "cell_type": "code",
39 "id": "ns-5",
40 "metadata": {},
41 "execution_count": null,
42 "outputs": [],
43 "source": "import geom.*\ncircle_area(3)"
44 },
45 {
46 "cell_type": "markdown",
47 "id": "ns-6",
48 "metadata": {},
49 "source": "## Classes can live inside packages\n\n[+geom/Point.m](./+geom/Point.m) is the class `geom.Point`."
50 },
51 {
52 "cell_type": "code",
53 "id": "ns-7",
54 "metadata": {},
55 "execution_count": null,
56 "outputs": [],
57 "source": "pt = geom.Point(3, 4);\npt.dist()"
58 },
59 {
60 "cell_type": "markdown",
61 "id": "ns-8",
62 "metadata": {},
63 "source": "## Organizing internal helpers with `private/`\n\nA `private` subfolder holds helpers used by the functions in its parent\nfolder. [toolbox/robust_center.m](./toolbox/robust_center.m) delegates to a\nhelper kept in `toolbox/private/`."
64 },
65 {
66 "cell_type": "code",
67 "id": "ns-9",
68 "metadata": {},
69 "execution_count": null,
70 "outputs": [],
71 "source": "addpath('toolbox');\nrobust_center([1 2 3 4 100]) % trims the extremes, then averages"
72 }
73 ],
74 "metadata": {
75 "kernelspec": {
76 "display_name": "numbl (MATLAB syntax)",
77 "language": "numbl",
78 "name": "numbl"
79 },
80 "language_info": {
81 "codemirror_mode": "octave",
82 "file_extension": ".m",
83 "mimetype": "text/x-octave",
84 "name": "numbl",
85 "nbconvert_exporter": "script",
86 "pygments_lexer": "matlab"
87 }
88 },
89 "nbformat": 4,
90 "nbformat_minor": 5
91}