{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Metaprogramming & macros\n", "\n", "Julia represents its own code as a data structure accessible from the language itself. Since code is represented by objects that can be created and manipulated from within the language, it is possible for a program to transform and generate its own code, that is to create powerful macros (the term \"metaprogramming\" refers to the possibility to write code that write codes that is then evaluated).\n", "\n", "Note the difference with C or C++ macros. There, macros work performing textual manipulation and substitution before any actual parsing or interpretation occurs.\n", "\n", "In Julia, macros works when the code has been already parsed and organised in a syntax tree, and hence the semantic is much richer and allows for much more powerful manipulations." ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "# Macros in C++ (example from FFSM++)\n", "#=\n", "\n", "#define CONSTRAIN_START_LOOP(pVector,cn) \\\n", " for (uint r1=0;r1= 10 println(\"array has fewer than 10 elements\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Julia 1.2.0", "language": "julia", "name": "julia-1.2" }, "language_info": { "file_extension": ".jl", "mimetype": "application/julia", "name": "julia", "version": "1.2.0" } }, "nbformat": 4, "nbformat_minor": 1 }