{ "cells": [ { "cell_type": "markdown", "id": "ns-0", "metadata": {}, "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`." }, { "cell_type": "markdown", "id": "ns-1", "metadata": {}, "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`." }, { "cell_type": "code", "id": "ns-2", "metadata": {}, "execution_count": null, "outputs": [], "source": "geom.circle_area(2)\ngeom.util.deg2rad(180)" }, { "cell_type": "markdown", "id": "ns-3", "metadata": {}, "source": "## import brings names into scope" }, { "cell_type": "code", "id": "ns-4", "metadata": {}, "execution_count": null, "outputs": [], "source": "import geom.util.deg2rad\ndeg2rad(90)" }, { "cell_type": "code", "id": "ns-5", "metadata": {}, "execution_count": null, "outputs": [], "source": "import geom.*\ncircle_area(3)" }, { "cell_type": "markdown", "id": "ns-6", "metadata": {}, "source": "## Classes can live inside packages\n\n[+geom/Point.m](./+geom/Point.m) is the class `geom.Point`." }, { "cell_type": "code", "id": "ns-7", "metadata": {}, "execution_count": null, "outputs": [], "source": "pt = geom.Point(3, 4);\npt.dist()" }, { "cell_type": "markdown", "id": "ns-8", "metadata": {}, "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/`." }, { "cell_type": "code", "id": "ns-9", "metadata": {}, "execution_count": null, "outputs": [], "source": "addpath('toolbox');\nrobust_center([1 2 3 4 100]) % trims the extremes, then averages" } ], "metadata": { "kernelspec": { "display_name": "numbl (MATLAB syntax)", "language": "numbl", "name": "numbl" }, "language_info": { "codemirror_mode": "octave", "file_extension": ".m", "mimetype": "text/x-octave", "name": "numbl", "nbconvert_exporter": "script", "pygments_lexer": "matlab" } }, "nbformat": 4, "nbformat_minor": 5 }