Skip to content

Instantly share code, notes, and snippets.

@antimon2
Created October 10, 2020 01:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save antimon2/2308260da736dc14093a1abe504fac64 to your computer and use it in GitHub Desktop.
Save antimon2/2308260da736dc14093a1abe504fac64 to your computer and use it in GitHub Desktop.
at_dbind.jl.ipynb
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"metadata": {
"ExecuteTime": {
"end_time": "2020-10-10T10:31:16.913000+09:00",
"start_time": "2020-10-10T01:31:16.120Z"
},
"trusted": true
},
"cell_type": "code",
"source": "versioninfo()",
"execution_count": 1,
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": "Julia Version 1.5.2\nCommit 539f3ce943 (2020-09-23 23:17 UTC)\nPlatform Info:\n OS: Linux (x86_64-pc-linux-gnu)\n CPU: Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz\n WORD_SIZE: 64\n LIBM: libopenlibm\n LLVM: libLLVM-9.0.1 (ORCJIT, skylake)\n"
}
]
},
{
"metadata": {
"ExecuteTime": {
"end_time": "2020-10-10T10:31:17.374000+09:00",
"start_time": "2020-10-10T01:31:16.122Z"
},
"trusted": true
},
"cell_type": "code",
"source": "macro dbind(ex)\n @assert Meta.isexpr(ex, :(=))\n Expr(:(=), esc(vect2tuple(ex.args[1])), esc(ex.args[2]))\nend",
"execution_count": 2,
"outputs": [
{
"data": {
"text/plain": "@dbind (macro with 1 method)"
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
]
},
{
"metadata": {
"ExecuteTime": {
"end_time": "2020-10-10T10:31:17.441000+09:00",
"start_time": "2020-10-10T01:31:16.123Z"
},
"trusted": true
},
"cell_type": "code",
"source": "vect2tuple(ex) = ex\nfunction vect2tuple(ex::Expr)\n if Meta.isexpr(ex, :vect)\n Expr(:tuple, vect2tuple.(ex.args)...)\n else\n Expr(ex.head, vect2tuple.(ex.args)...)\n end\nend",
"execution_count": 3,
"outputs": [
{
"data": {
"text/plain": "vect2tuple (generic function with 2 methods)"
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
]
},
{
"metadata": {
"ExecuteTime": {
"end_time": "2020-10-10T10:31:17.793000+09:00",
"start_time": "2020-10-10T01:31:16.125Z"
},
"trusted": true
},
"cell_type": "code",
"source": "@macroexpand @dbind [a, [b, c, d], e] = [1, [2, 3, 4], 5]",
"execution_count": 4,
"outputs": [
{
"data": {
"text/plain": ":((a, (b, c, d), e) = [1, [2, 3, 4], 5])"
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
]
},
{
"metadata": {
"ExecuteTime": {
"end_time": "2020-10-10T10:31:18.824000+09:00",
"start_time": "2020-10-10T01:31:16.126Z"
},
"trusted": true
},
"cell_type": "code",
"source": "@dbind [a, [b, c, d], e] = [1, [2, 3, 4], 5]",
"execution_count": 5,
"outputs": [
{
"data": {
"text/plain": "3-element Array{Any,1}:\n 1\n [2, 3, 4]\n 5"
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
]
},
{
"metadata": {
"ExecuteTime": {
"end_time": "2020-10-10T10:31:19.046000+09:00",
"start_time": "2020-10-10T01:31:16.134Z"
},
"trusted": true
},
"cell_type": "code",
"source": "(a, b, c, d, e)",
"execution_count": 6,
"outputs": [
{
"data": {
"text/plain": "(1, 2, 3, 4, 5)"
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
]
},
{
"metadata": {
"ExecuteTime": {
"end_time": "2020-10-10T10:34:12.915000+09:00",
"start_time": "2020-10-10T01:34:13.552Z"
},
"trusted": true
},
"cell_type": "code",
"source": "@dbind [a, (b, [c, d]), e] = [11, [12, (13, 14)], 15]\n(a, b, c, d, e)",
"execution_count": 7,
"outputs": [
{
"data": {
"text/plain": "(11, 12, 13, 14, 15)"
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
]
}
],
"metadata": {
"kernelspec": {
"name": "julia-1.5",
"display_name": "Julia 1.5.2",
"language": "julia"
},
"language_info": {
"file_extension": ".jl",
"name": "julia",
"mimetype": "application/julia",
"version": "1.5.2"
},
"gist": {
"id": "",
"data": {
"description": "at_dbind.jl.ipynb",
"public": true
}
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment