2020/05/30 Python東海/JuliaTokaiミニ合同勉強会
@ OSC2020 Online/Nagoya
antimon2(後藤 俊介)
Note:
Julia で衛生を保とう!
Note:
コミュニティ紹介で自己紹介もしたのでこちらでは省略っ
みなさん…
Note:
っ
Note:
帰宅後や食事前にきちんと手を洗っていますか?っ
Note:
外出時や人と会うときにマスクをいますか?っ
普段衛生的な生活を心がけているなら、当然…
じゃぁ当然…
Note:
ますよねっっ?っ
Note:
ますよねっっ?っ
Note:
なぜならっ
衛生的マクロ(hygienic macro)は、マクロ展開によって導入される識別子と展開先のプログラムにある識別子が衝突して、意図とは異なる意味になることを防ぐ機構を持つマクロである。
出典:「多言語に対応した衛生的マクロ機構導入方式」(DOI)
Note:
なぜならっ
macro time_ns(ex)
return quote
t0 = time_ns()
val = $(esc(ex))
t1 = time_ns()
println("elapsed time: ", Int(t1-t0), " nanoseconds")
val
end
end
Note:
これは実行時間を計測するためのマクロの例ですっ
julia> @time_ns 1 + 2
elapsed time: 5604 nanoseconds
3
julia> @time_ns time_ns()
elapsed time: 9684 nanoseconds
0x00049b777cb1b4b1
Note:
ナノ秒なのでこんな単純な計算でも結果がっ
julia> @time_ns t0 += 1000000
# => ???
Note:
ではこんなの実行したらどうなるっ?
julia> @time_ns t0 += 1000000
ERROR: UndefVarError: t0 not defined
Stacktrace:
[1] top-level scope at REPL[XX]:YY
Note:
エラーになりますっ!
julia> @macroexpand @time_ns t0 += 1000000
quote
#= REPL[XX]:YY =#
#12#t0 = (Main.time_ns)()
#= REPL[XX]:YY =#
#13#val = (t0 += 1000000)
#= REPL[XX]:YY =#
#14#t1 = (Main.time_ns)()
#= REPL[XX]:YY =#
(Main.println)("elapsed time: ", (Main.Int)(#14#t1 - #12#t0), " nanoseconds")
#= REPL[XX]:YY =#
#13#val
end
Note:
なぜならこんなコードに変換されて実行されるからっ!
t0
val
t1
)が変な名前(#12#t0
#13#val
#14#t1
)に変換されているtime_ns()
→(Main.time_ns)()
)されているesc(ex)
と書かれた部分は勝手に変換されていない(t0 += 1000000
)⇩
esc(ex)
に渡されたモノだけは勝手に変換されずにそのまま使用される!⇩
でコロナ禍を乗り切ろう!
Note:
で、衛生的な生活を心がけてコロナ禍を乗り切ろう!っ
ご清聴ありがとうございます。
Note:
ご清聴ありがとうございますっ!
or
or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up
Syntax | Example | Reference | |
---|---|---|---|
# Header | Header | 基本排版 | |
- Unordered List |
|
||
1. Ordered List |
|
||
- [ ] Todo List |
|
||
> Blockquote | Blockquote |
||
**Bold font** | Bold font | ||
*Italics font* | Italics font | ||
~~Strikethrough~~ | |||
19^th^ | 19th | ||
H~2~O | H2O | ||
++Inserted text++ | Inserted text | ||
==Marked text== | Marked text | ||
[link text](https:// "title") | Link | ||
 | Image | ||
`Code` | Code |
在筆記中貼入程式碼 | |
```javascript var i = 0; ``` |
|
||
:smile: | ![]() |
Emoji list | |
{%youtube youtube_id %} | Externals | ||
$L^aT_eX$ | LaTeX | ||
:::info This is a alert area. ::: |
This is a alert area. |
On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?
Please give us some advice and help us improve HackMD.
Do you want to remove this version name and description?
Syncing