Created
February 1, 2019 13:52
-
-
Save goropikari/3b63ae95ed6df1b16db9197ae876c9a9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": 1, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"Julia Version 1.1.0\n", | |
"Commit 80516ca202 (2019-01-21 21:24 UTC)\n", | |
"Platform Info:\n", | |
" OS: Linux (x86_64-pc-linux-gnu)\n", | |
" CPU: Intel(R) Core(TM) i5-4460T CPU @ 1.90GHz\n", | |
" WORD_SIZE: 64\n", | |
" LIBM: libopenlibm\n", | |
" LLVM: libLLVM-6.0.1 (ORCJIT, haswell)\n", | |
"Environment:\n", | |
" JULIA_SHELL = /usr/bin/bash\n", | |
" JULIA_EDITOR = nvim\n", | |
" JULIA_NUM_THREADS = 4\n" | |
] | |
} | |
], | |
"source": [ | |
"versioninfo()" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 2, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/latex": [ | |
"The analogue of IPython's \\texttt{\\%\\%bash ...code...} in Julia can be constructed by first evaluating\n", | |
"\n", | |
"\\begin{verbatim}\n", | |
"macro bash_str(s) open(`bash`,\"w\",stdout) do io; print(io, s); end; end\n", | |
"\\end{verbatim}\n", | |
"to define the \\texttt{bash\"....\"} \\href{http://docs.julialang.org/en/latest/manual/strings/#non-standard-string-literals}{string macro} in Julia. Subsequently, you can simply do:\n", | |
"\n", | |
"\\begin{verbatim}\n", | |
"bash\"\"\"\n", | |
"...code...\n", | |
"\"\"\"\n", | |
"\\end{verbatim}\n", | |
"to evaluate the code in \\texttt{bash} (outputting to \\texttt{stdout}).\n", | |
"\n" | |
], | |
"text/markdown": [ | |
"The analogue of IPython's `%%bash ...code...` in Julia can be constructed by first evaluating\n", | |
"\n", | |
"```\n", | |
"macro bash_str(s) open(`bash`,\"w\",stdout) do io; print(io, s); end; end\n", | |
"```\n", | |
"\n", | |
"to define the `bash\"....\"` [string macro](http://docs.julialang.org/en/latest/manual/strings/#non-standard-string-literals) in Julia. Subsequently, you can simply do:\n", | |
"\n", | |
"```\n", | |
"bash\"\"\"\n", | |
"...code...\n", | |
"\"\"\"\n", | |
"```\n", | |
"\n", | |
"to evaluate the code in `bash` (outputting to `stdout`).\n" | |
], | |
"text/plain": [ | |
" The analogue of IPython's \u001b[36m%%bash ...code...\u001b[39m in Julia can be constructed by\n", | |
" first evaluating\n", | |
"\n", | |
"\u001b[36m macro bash_str(s) open(`bash`,\"w\",stdout) do io; print(io, s); end; end\u001b[39m\n", | |
"\n", | |
" to define the \u001b[36mbash\"....\"\u001b[39m string macro\n", | |
" (http://docs.julialang.org/en/latest/manual/strings/#non-standard-string-literals)\n", | |
" in Julia. Subsequently, you can simply do:\n", | |
"\n", | |
"\u001b[36m bash\"\"\"\u001b[39m\n", | |
"\u001b[36m ...code...\u001b[39m\n", | |
"\u001b[36m \"\"\"\u001b[39m\n", | |
"\n", | |
" to evaluate the code in \u001b[36mbash\u001b[39m (outputting to \u001b[36mstdout\u001b[39m)." | |
] | |
}, | |
"metadata": {}, | |
"output_type": "display_data" | |
} | |
], | |
"source": [ | |
"%%bash" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 3, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"ename": "LoadError", | |
"evalue": "syntax: extra token \"hoge\" after end of expression", | |
"output_type": "error", | |
"traceback": [ | |
"syntax: extra token \"hoge\" after end of expression", | |
"" | |
] | |
} | |
], | |
"source": [ | |
";echo hoge\n", | |
";echo piyo" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 4, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"@bash_str (macro with 1 method)" | |
] | |
}, | |
"execution_count": 4, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"macro bash_str(s) open(`bash`,\"w\",stdout) do io; print(io, s); end; end" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 5, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"hoge\n", | |
"piyo\n" | |
] | |
} | |
], | |
"source": [ | |
"bash\"\"\"\n", | |
"echo hoge\n", | |
"echo piyo\n", | |
"\"\"\"" | |
] | |
} | |
], | |
"metadata": { | |
"@webio": { | |
"lastCommId": "1264c832af7d4eb7869f10bc44ab6c04", | |
"lastKernelId": "15b55562-fcb8-4955-ba5d-02919a0d6d3b" | |
}, | |
"kernelspec": { | |
"display_name": "Julia 1.1.0", | |
"language": "julia", | |
"name": "julia-1.1" | |
}, | |
"language_info": { | |
"file_extension": ".jl", | |
"mimetype": "application/julia", | |
"name": "julia", | |
"version": "1.1.0" | |
}, | |
"toc": { | |
"nav_menu": {}, | |
"number_sections": true, | |
"sideBar": true, | |
"skip_h1_title": false, | |
"toc_cell": false, | |
"toc_position": {}, | |
"toc_section_display": "block", | |
"toc_window_display": false | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 2 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment