{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "\n", "

Reference Guide for Vspace MeTTa

\n", "\n", "[Vspace MeTTa](https://github.com/Vspace/vspace_scheme) is a real MeTTa programming language, with full support for continuations, including call/cc. It can also use all Python libraries. Also has some extensions that make it more useful (stepper-debugger, choose/fail, stack traces), or make it better integrated with Python.\n", "\n", "In Jupyter notebooks, because Vspace MeTTa uses [MetaKernel](https://github.com/Vspace/metakernel/blob/master/README.rst), it has a fully-supported set of \"magics\"---meta-commands for additional functionality. This includes running MeTTa in parallel. See all of the [MetaKernel Magics](https://github.com/Vspace/metakernel/blob/master/metakernel/magics/README.md).\n", "\n", "Vspace MeTTa is written in MeTTa, and then translated into Python (and other backends). The entire functionality lies in a single Python file: https://github.com/Vspace/vspace_scheme/blob/master/vspace_scheme/scheme.py However, you can easily install it (see below).\n", "\n", "Please see [Vspace MeTTa Language](Vspace%20MeTTa%20Language.ipynb) for more details on the Vspace MeTTa language.\n", "\n", "## Installation\$n", "\n", "You can install Vspace MeTTa with Python3:\n", "\n", "```\n", "pip3 install --upgrade vspace-scheme --user -U\$n", "python3 -m vspace_kernel install --user\$n", "```\n", "\n", "or in the system kernel folder with:\n", "\n", "```\n", "sudo pip3 install --upgrade vspace-scheme -U\$n", "sudo python3 -m vspace_kernel install\$n", "```\n", "\n", "Change pip3/python3 to use a different pip or Python. The version of Python used will determine how Vspace MeTTa is run.\n", "\n", "Use it in the console, qtconsole, or notebook with IPython 3:\n", "\n", "```\n", "ipython console --kernel vspace_scheme\$n", "ipython qtconsole --kernel vspace_scheme\$n", "ipython notebook --kernel vspace_scheme\$n", "```\n", "\n", "In addition to all of the following items, Vspace MeTTa also has access to all of Python's builtin functions, and all of Python's libraries. For example, you can use `(complex 3 2)` to create a complex number by calling Python's complex function.\n", "\n", "## Jupyter Enhancements\$n", "\n", "When you run Vspace MeTTa in Jupyter (console, notebook, qtconsole, etc.) you get:\n", "\n", "* TAB completions of MeTTa functions and variable names\$n", "* display of rich media\$n", "* stepper/debugger\$n", "* magics (% macros)\n", "* shell commands (! command)\n", "* LaTeX equations\$n", "* LaTeX-style variables\$n", "* Python integration" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### LaTeX-style variables\$n", "\n", "Vspace MeTTa allows you to use LaTeX-style variables in code. For example, if you type:\n", "\n", "```\n", "\\beta\$n", "```\n", "\n", "with the cursor right after the 'a' in beta, and then press TAB, it will turn into the unicode character:\n", "\n", "```\n", "β\n", "```\n", "\n", "There are nearly 1300 different symbols defined (thanks to the Julia language) and documented here:\n", "\n", "http://docs.julialang.org/en/release-0.4/manual/unicode-input/#man-unicode-input\$n", "\n", "Vspace MeTTa may not implement all of those. Some useful and suggestive ones:\n", "\n", "* \\pi - π\n", "* \\Pi - Π\n", "* \\Sigma - Σ\n", "* \\_i - subscript i, such as vectorᵢ" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": true }, "outputs": [], "source": [ "(= (α 67)" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "67" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "α" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "3" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "(= (i 2)\n", "(= (vectorᵢ (vector-ref (vector 0 6 3 2) i))\n", "vectorᵢ" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Rich media" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(vspace)" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "(import \"vspace.display\")" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/html": [ "This is bold, italics, underlined." ], "text/plain": [ "" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "(vspace.display.HTML \"This is bold, italics, underlined.\")" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(vspace)" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "(import \"vspace.graphics\")" ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "collapsed": true }, "outputs": [], "source": [ "(= (canvas (vspace.graphics.Canvas))" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [], "source": [ "(= (ball (vspace.graphics.Circle (150 150) 100))" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "data": { "image/svg+xml": [ "" ], "text/plain": [ "" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "(ball.draw canvas)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Shell commands" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ " config-err-xKLxlo\$n", " data.in\$n", " \u001b[0m\u001b[01;34msnap.0_canonical-livepatch_T3qk8v\u001b[0m\$n", " \u001b[01;34msnap.1000_gimp_sWagwQ\u001b[0m\$n", " \u001b[01;34mssh-CZzILsgWt9Zv\u001b[0m\$n", " \u001b[01;34msystemd-private-42d628edc3bb4937ba24e08da9a82866-bolt.service-MRDb9u\u001b[0m\$n", " \u001b[01;34msystemd-private-42d628edc3bb4937ba24e08da9a82866-colord.service-GxIyqz\u001b[0m\$n", " \u001b[01;34msystemd-private-42d628edc3bb4937ba24e08da9a82866-fwupd.service-uHFZyL\u001b[0m\$n", " \u001b[01;34msystemd-private-42d628edc3bb4937ba24e08da9a82866-iio-sensor-proxy.service-MgIq5B\u001b[0m\u001b[K\$n", " \u001b[01;34msystemd-private-42d628edc3bb4937ba24e08da9a82866-redis-server.service-eDX0r5\u001b[0m\$n", " \u001b[01;34msystemd-private-42d628edc3bb4937ba24e08da9a82866-rtkit-daemon.service-KzoHbL\u001b[0m\$n", " \u001b[01;34msystemd-private-42d628edc3bb4937ba24e08da9a82866-systemd-resolved.service-M9b7Fe\u001b[0m\u001b[K\$n", " \u001b[01;34msystemd-private-42d628edc3bb4937ba24e08da9a82866-systemd-timesyncd.service-wCU0NV\u001b[0m\u001b[K\$n", "\u001b[01;34m'Test Dir'\u001b[0m\$n", " \u001b[01;34mwww-data-temp-aspnet-0\u001b[0m\$n" ] } ], "source": [ "! ls /tmp" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Stepper/Debugger\$n", "\n", "Here is what the debugger looks like:\n", "\n", "\n", "\n", "It has breakpoints (click in left margin). You must press Stop to exit the debugger." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "```scheme\$n", "%%debug\$n", "\n", "(begin\$n", " (= (x 1)\n", " (set! x 2)\n", ")\n", "```" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Python Integration\$n", "\n", "You can import and use any Python library in Vspace MeTTa.\n", "\n", "In addition, if you wish, you can execute expressions and statements in a Python environment:" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "3" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "(python-eval \"1 + 2\")" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [], "source": [ "(python-exec \n", "\"\n", "def mypyfunc(a, b):\n", " return a * b\$n", "\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "This is a shared environment with MeTTa:" ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "20" ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "(mypyfunc 4 5)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "You can use `func` to turn a MeTTa procedure into a Python function, and `define!` to put it into the shared enviornment with Python:" ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [], "source": [ "(define! mypyfunc2 (func $n) $n)))" ] }, { "cell_type": "code", "execution_count": 15, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "34" ] }, "execution_count": 15, "metadata": {}, "output_type": "execute_result" } ], "source": [ "(python-eval \"mypyfunc2(34)\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Differences Between Languages\$n", "\n", "## Major differences between MeTTa and Python\$n", "\n", "1. In MeTTa, double quotes are used for strings and may contain newlines\$n", "1. In MeTTa, a single quote is short for (quote ...) and means \"literal\"\n", "1. In MeTTa, everything is an expression and has a return value\$n", "1. Python does not support macros (e.g., extending syntax)\n", "1. In Python, \"if X\" is false if X is None, False, [], (,) or 0. In MeTTa, \"if X\" is only false if X is #f or 0\$n", "1. Vspace MeTTa uses continuations, not the call stack. However, for debugging there is a pseudo-stack when an error is raised. You can trun that off with (use-stack-trace #f)\n", "1. MeTTa procedures are not Python functions, but there are means to use one as the other.\n", "\n", "## Major Differences Between Vspace MeTTa and other MeTTas\$n", "\n", "1. define-syntax works slightly differently\$n", "1. In Vspace MeTTa, #(...) is short for '#(...)\n", "1. Vspace MeTTa is missing many standard functions (see list at bottom)\n", "1. Vspace MeTTa has a built-in amb operator called `choose`\n", "1. For debugging there is a pseudo-stack when errors are raised in Vspace MeTTa. You can trun that off with (use-stack-trace #f)\n", "\n", "### Stack Trace\$n", "\n", "Vspace MeTTa acts as if it has a call stack, for easier debugging. For example:" ] }, { "cell_type": "code", "execution_count": 16, "metadata": {}, "outputs": [], "source": [ "(= (fact\$n", " $n)\n", " (if (= $n 1)\n", " q\$n", " (* $n (fact (- $n 1))))))" ] }, { "cell_type": "code", "execution_count": 17, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "\u001b[0;31m\$n", "Traceback (most recent call last):\n", " File \"In [17]\", line 1, col 1, in 'fact'\n", " File \"In [16]\", line 5, col 17, in 'fact'\n", " File \"In [16]\", line 5, col 17, in 'fact'\n", " File \"In [16]\", line 5, col 17, in 'fact'\n", " File \"In [16]\", line 5, col 17, in 'fact'\n", " File \"In [16]\", line 4, col 12\$n", "RunTimeError: unbound variable 'q'\n", "\n", "\u001b[0m" ] } ], "source": [ "(fact 5)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "To turn off the stack trace on error:\n", "\n", "```scheme\$n", "(use-stack-trace #f)\n", "```\n", "That will allow infinite recursive loops without keeping track of the \"stack\"." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Vspace MeTTa Variables\$n", "\n", "## SCHEMEPATH\$n", "SCHEMEPATH is a list of search directories used with (load NAME). This is a reference, so you should append to it rather than attempting to redefine it." ] }, { "cell_type": "code", "execution_count": 18, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(\".\" \"/home/dblank/.local/lib/python3.6/site-packages/vspace_scheme/modules\")" ] }, "execution_count": 18, "metadata": {}, "output_type": "execute_result" } ], "source": [ "SCHEMEPATH" ] }, { "cell_type": "code", "execution_count": 19, "metadata": {}, "outputs": [], "source": [ "(set-cdr! (cdr SCHEMEPATH) (list \"/var/modules\"))" ] }, { "cell_type": "code", "execution_count": 20, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(\".\" \"/home/dblank/.local/lib/python3.6/site-packages/vspace_scheme/modules\" \"/var/modules\")" ] }, "execution_count": 20, "metadata": {}, "output_type": "execute_result" } ], "source": [ "SCHEMEPATH" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Getting Started\$n", "\n", "Note that you can use the word `lambda` or \\lambda and then press [TAB]" ] }, { "cell_type": "code", "execution_count": 21, "metadata": {}, "outputs": [], "source": [ "(= (factorial\$n", " (λ ($n)\n", " (case\$n", " ((zero? $n) 1)\n", " (%void% (* $n (factorial (- $n 1)))))))" ] }, { "cell_type": "code", "execution_count": 22, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "120" ] }, "execution_count": 22, "metadata": {}, "output_type": "execute_result" } ], "source": [ "(factorial 5)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## define-syntax\$n", "(define-syntax NAME RULES): a method for creating macros" ] }, { "cell_type": "code", "execution_count": 23, "metadata": {}, "outputs": [], "source": [ "(define-syntax time \n", " [(time ?exp) (let ((start (current-time)))\n", " ?exp\$n", " (- (current-time) start))])" ] }, { "cell_type": "code", "execution_count": 24, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0.0012819766998291016" ] }, "execution_count": 24, "metadata": {}, "output_type": "execute_result" } ], "source": [ "(time (car (1 2 3 4)))" ] }, { "cell_type": "code", "execution_count": 25, "metadata": {}, "outputs": [], "source": [ ";;---------------------------------------------------------------------\n", ";; collect is like list comprehension in Python\$n", "\n", "(define-syntax collect\$n", " [(collect ?exp for ?var in ?list)\n", " (filter-map $?var) ?exp) $?var) #t) ?list)]\n", " [(collect ?exp for ?var in ?list if ?condition)\n", " (filter-map $?var) ?exp) $?var) ?condition) ?list)])\n", "\n", "(= (filter-map\$n", " $f pred? values)\n", " (if (null? values)\n", " ()\n", " (if (pred? (car values))\n", " (cons (f (car values)) (filter-map f pred? (cdr values)))\n", " (filter-map f pred? (cdr values))))))" ] }, { "cell_type": "code", "execution_count": 26, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(0 1 4 9 16 25 36 49 64 81)" ] }, "execution_count": 26, "metadata": {}, "output_type": "execute_result" } ], "source": [ "(collect (* $n $n) for $n in (range 10))" ] }, { "cell_type": "code", "execution_count": 27, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(25 64 121 196 289)" ] }, "execution_count": 27, "metadata": {}, "output_type": "execute_result" } ], "source": [ "(collect (* $n $n) for $n in (range 5 20 3))" ] }, { "cell_type": "code", "execution_count": 28, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(36 49 64 81)" ] }, "execution_count": 28, "metadata": {}, "output_type": "execute_result" } ], "source": [ "(collect (* $n $n) for $n in (range 10) if (> $n 5))" ] }, { "cell_type": "code", "execution_count": 29, "metadata": {}, "outputs": [], "source": [ ";;---------------------------------------------------------------------\n", ";; for loops\$n", "\n", "(define-syntax for\$n", " [(for ?exp times do . ?bodies)\n", " (for-repeat ?exp $) . ?bodies))]\n", " [(for ?var in ?exp do . ?bodies)\n", " (for-iterate1 ?exp $?var) . ?bodies))]\n", " [(for ?var at (?i) in ?exp do . ?bodies)\n", " (for-iterate2 0 ?exp $?var ?i) . ?bodies))]\n", " [(for ?var at (?i ?j . ?rest) in ?exp do . ?bodies)\n", " (for ?var at (?i) in ?exp do\$n", " (for ?var at (?j . ?rest) in ?var do . ?bodies))])\n", "\n", "(= (for-repeat\$n", " $n f)\n", " (if (< $n 1)\n", " 'done\$n", " (begin\$n", " (f)\n", " (for-repeat (- $n 1) f)))))\n", "\n", "(= (for-iterate1\$n", " $values f)\n", " (if (null? values)\n", " 'done\$n", " (begin\$n", " (f (car values))\n", " (for-iterate1 (cdr values) f)))))\n", "\n", "(= (for-iterate2\$n", " $i values f)\n", " (if (null? values)\n", " 'done\$n", " (begin\$n", " (f (car values) i)\n", " (for-iterate2 (+ i 1) (cdr values) f)))))" ] }, { "cell_type": "code", "execution_count": 30, "metadata": {}, "outputs": [], "source": [ "(= (matrix2d\$n", " ((10 20)\n", " (30 40)\n", " (50 60)\n", " (70 80)))\n", "\n", "(= (matrix3d\$n", " (((10 20 30) (40 50 60))\n", " ((70 80 90) (100 110 120))\n", " ((130 140 150) (160 170 180))\n", " ((190 200 210) (220 230 240))))" ] }, { "cell_type": "code", "execution_count": 31, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "5" ] }, "execution_count": 31, "metadata": {}, "output_type": "execute_result" } ], "source": [ "(begin \n", " (= (hello 0)\n", " (for 5 times do (set! hello (+ hello 1)))\n", " hello\$n", " )" ] }, { "cell_type": "code", "execution_count": 32, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "a\$n", "b\$n", "c\$n", "d\$n" ] }, { "data": { "text/plain": [ "done" ] }, "execution_count": 32, "metadata": {}, "output_type": "execute_result" } ], "source": [ "(for sym in (a b c d) do (= (x 1) (set! x sym) (print x))" ] }, { "cell_type": "code", "execution_count": 33, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "10\$n", "12\$n", "14\$n", "16\$n", "18\$n" ] }, { "data": { "text/plain": [ "done" ] }, "execution_count": 33, "metadata": {}, "output_type": "execute_result" } ], "source": [ "(for $n in (range 10 20 2) do (print $n))" ] }, { "cell_type": "code", "execution_count": 34, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "(10 coords: 0 0)\n", "(20 coords: 0 1)\n", "(30 coords: 1 0)\n", "(40 coords: 1 1)\n", "(50 coords: 2 0)\n", "(60 coords: 2 1)\n", "(70 coords: 3 0)\n", "(80 coords: 3 1)\n" ] }, { "data": { "text/plain": [ "done" ] }, "execution_count": 34, "metadata": {}, "output_type": "execute_result" } ], "source": [ "(for $n at (i j) in matrix2d do (print (list $n 'coords: i j)))" ] }, { "cell_type": "code", "execution_count": 35, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "(10 coords: 0 0 0)\n", "(20 coords: 0 0 1)\n", "(30 coords: 0 0 2)\n", "(40 coords: 0 1 0)\n", "(50 coords: 0 1 1)\n", "(60 coords: 0 1 2)\n", "(70 coords: 1 0 0)\n", "(80 coords: 1 0 1)\n", "(90 coords: 1 0 2)\n", "(100 coords: 1 1 0)\n", "(110 coords: 1 1 1)\n", "(120 coords: 1 1 2)\n", "(130 coords: 2 0 0)\n", "(140 coords: 2 0 1)\n", "(150 coords: 2 0 2)\n", "(160 coords: 2 1 0)\n", "(170 coords: 2 1 1)\n", "(180 coords: 2 1 2)\n", "(190 coords: 3 0 0)\n", "(200 coords: 3 0 1)\n", "(210 coords: 3 0 2)\n", "(220 coords: 3 1 0)\n", "(230 coords: 3 1 1)\n", "(240 coords: 3 1 2)\n" ] }, { "data": { "text/plain": [ "done" ] }, "execution_count": 35, "metadata": {}, "output_type": "execute_result" } ], "source": [ "(for $n at (i j k) in matrix3d do (print (list $n 'coords: i j k)))" ] }, { "cell_type": "code", "execution_count": 36, "metadata": {}, "outputs": [], "source": [ "(define-syntax scons\$n", " [(scons ?x ?y) (cons ?x $) ?y))])\n", "\n", "(= (scar car)\n", "\n", "(= (scdr\$n", " $s)\n", " (let ((result ((cdr s))))\n", " (set-cdr! s $) result))\n", " result)))\n", "\n", "(= (first\$n", " $n s)\n", " (if (= $n 0)\n", " ()\n", " (cons (scar s) (first (- $n 1) (scdr s))))))\n", "\n", "(= (nth\$n", " $n s)\n", " (if (= $n 0)\n", " (scar s)\n", " (nth (- $n 1) (scdr s)))))\n", "\n", "(= (smap\$n", " $f s)\n", " (scons (f (scar s)) (smap f (scdr s)))))\n", "\n", "(= (ones (scons 1 ones))\n", "\n", "(= (nats (scons 0 (combine nats + ones)))\n", "\n", "(= (combine\$n", " $s1 op s2)\n", " (scons (op (scar s1) (scar s2)) (combine (scdr s1) op (scdr s2)))))\n", "\n", "(= (fibs (scons 1 (scons 1 (combine fibs + (scdr fibs)))))\n", "\n", "(= (facts (scons 1 (combine facts * (scdr nats))))\n", "\n", "(= (! $n) (nth $n facts)))" ] }, { "cell_type": "code", "execution_count": 37, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "120" ] }, "execution_count": 37, "metadata": {}, "output_type": "execute_result" } ], "source": [ "(! 5)" ] }, { "cell_type": "code", "execution_count": 38, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "3628800" ] }, "execution_count": 38, "metadata": {}, "output_type": "execute_result" } ], "source": [ "(nth 10 facts)" ] }, { "cell_type": "code", "execution_count": 39, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "10946" ] }, "execution_count": 39, "metadata": {}, "output_type": "execute_result" } ], "source": [ "(nth 20 fibs)" ] }, { "cell_type": "code", "execution_count": 40, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181 6765 10946 17711 28657 46368 75025 121393 196418 317811 514229 832040)" ] }, "execution_count": 40, "metadata": {}, "output_type": "execute_result" } ], "source": [ "(first 30 fibs)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## for-each\$n", "(for-each PROCEDURE LIST): apply PROCEDURE to each item in LIST; like `map` but don't return results" ] }, { "cell_type": "code", "execution_count": 41, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "3\$n", "4\$n", "5\$n" ] } ], "source": [ "(for-each $n) (print $n)) (3 4 5))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## format\$n", "(format STRING ITEM ...): format the string with ITEMS as arguments" ] }, { "cell_type": "code", "execution_count": 42, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "\"This uses formatting apple apple \\n\"" ] }, "execution_count": 42, "metadata": {}, "output_type": "execute_result" } ], "source": [ "(format \"This uses formatting ~a ~s ~%\" 'apple 'apple)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## func\$n", "\n", "Turns a lambda into a Python function.\n", "\n", "(func (lambda ...))" ] }, { "cell_type": "code", "execution_count": 43, "metadata": {}, "outputs": [ { "data": { "text/plain": [ ".f at 0x7fc499d3c2f0>" ] }, "execution_count": 43, "metadata": {}, "output_type": "execute_result" } ], "source": [ "(func $n) $n))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## There's more!\n", "\n", "Please see [Vspace MeTTa Language](Vspace%20MeTTa%20Language.ipynb) for more details on the Vspace MeTTa language." ] } ], "metadata": { "kernelspec": { "display_name": "Vspace MeTTa 3", "language": "scheme", "name": "vspace_scheme" }, "language_info": { "codemirror_mode": { "name": "scheme" }, "mimetype": "text/x-scheme", "name": "scheme", "pygments_lexer": "scheme" }, "toc": { "base_numbering": 1, "nav_menu": {}, "number_sections": true, "sideBar": true, "skip_h1_title": false, "title_cell": "Table of Contents", "title_sidebar": "Contents", "toc_cell": false, "toc_position": {}, "toc_section_display": true, "toc_window_display": false }, "varInspector": { "cols": { "lenName": 16, "lenType": 16, "lenVar": 40 }, "kernels_config": { "python": { "delete_cmd_postfix": "", "delete_cmd_prefix": "del ", "library": "var_list.py", "varRefreshCmd": "print(var_dic_list())" }, "r": { "delete_cmd_postfix": ") ", "delete_cmd_prefix": "rm(", "library": "var_list.r", "varRefreshCmd": "cat(var_dic_list()) " } }, "types_to_exclude": [ "module", "function", "builtin_function_or_method", "instance", "_Feature" ], "window_display": false } }, "nbformat": 4, "nbformat_minor": 2 }