\n",
"\n",
"[Calysto Scheme](https://github.com/Calysto/calysto_scheme) is a real Scheme 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 Calysto Scheme uses [MetaKernel](https://github.com/Calysto/metakernel/blob/master/README.rst), it has a fully-supported set of \"magics\"---meta-commands for additional functionality. This includes running Scheme in parallel. See all of the [MetaKernel Magics](https://github.com/Calysto/metakernel/blob/master/metakernel/magics/README.md).\n",
"\n",
"Calysto Scheme is written in Scheme, and then translated into Python (and other backends). The entire functionality lies in a single Python file: https://github.com/Calysto/calysto_scheme/blob/master/calysto_scheme/scheme.py However, you can easily install it (see below).\n",
"\n",
"Please see [Calysto Scheme Language](Calysto%20Scheme%20Language.ipynb) for more details on the Calysto Scheme language.\n",
"\n",
"## Installation\n",
"\n",
"You can install Calysto Scheme with Python3:\n",
"\n",
"```\n",
"pip3 install --upgrade calysto-scheme --user -U\n",
"python3 -m calysto_kernel install --user\n",
"```\n",
"\n",
"or in the system kernel folder with:\n",
"\n",
"```\n",
"sudo pip3 install --upgrade calysto-scheme -U\n",
"sudo python3 -m calysto_kernel install\n",
"```\n",
"\n",
"Change pip3/python3 to use a different pip or Python. The version of Python used will determine how Calysto Scheme is run.\n",
"\n",
"Use it in the console, qtconsole, or notebook with IPython 3:\n",
"\n",
"```\n",
"ipython console --kernel calysto_scheme\n",
"ipython qtconsole --kernel calysto_scheme\n",
"ipython notebook --kernel calysto_scheme\n",
"```\n",
"\n",
"In addition to all of the following items, Calysto Scheme 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 Calysto Scheme in Jupyter (console, notebook, qtconsole, etc.) you get:\n",
"\n",
"* TAB completions of Scheme 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",
"Calysto Scheme 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",
"Calysto Scheme 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": [
"(define α 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": [
"(define i 2)\n",
"(define 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": [
"(calysto)"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"(import \"calysto.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": [
"(calysto.display.HTML \"This is bold, italics, underlined.\")"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(calysto)"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"(import \"calysto.graphics\")"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"(define canvas (calysto.graphics.Canvas))"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
"(define ball (calysto.graphics.Circle '(150 150) 100))"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": [
""
],
"text/plain": [
"