diff options
| author | nsfisis <nsfisis@gmail.com> | 2023-03-17 01:35:04 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2023-03-17 01:35:04 +0900 |
| commit | 0766039bd9e6b9f5e6334e84666f5be698d41fc3 (patch) | |
| tree | 0f3a52fdbf56496850f903d64dcf7725fb0aedbe /public | |
| parent | ee72f8780cf3681e4202cc3a6358fb4038db1ec8 (diff) | |
| download | blog.nsfisis.dev-0766039bd9e6b9f5e6334e84666f5be698d41fc3.tar.gz blog.nsfisis.dev-0766039bd9e6b9f5e6334e84666f5be698d41fc3.tar.zst blog.nsfisis.dev-0766039bd9e6b9f5e6334e84666f5be698d41fc3.zip | |
feat(nuldoc): implement syntax highlight
Diffstat (limited to 'public')
21 files changed, 746 insertions, 950 deletions
diff --git a/public/hl.css b/public/hl.css index fabe9de..275239a 100644 --- a/public/hl.css +++ b/public/hl.css @@ -1,214 +1,10 @@ -/* ruby -rrouge -e 'puts Rouge::Themes::Github.render(scope: ".highlight")' */ -.highlight table td { padding: 5px; } -.highlight table pre { margin: 0; } -.highlight .cm { - color: #999988; - font-style: italic; -} -.highlight .cp { - color: #999999; - font-weight: bold; -} -.highlight .c1 { - color: #999988; - font-style: italic; -} -.highlight .cs { - color: #999999; - font-weight: bold; - font-style: italic; -} -.highlight .c, .highlight .ch, .highlight .cd, .highlight .cpf { - color: #999988; - font-style: italic; -} -.highlight .err { - color: #a61717; - background-color: #e3d2d2; -} -.highlight .gd { - color: #000000; - background-color: #ffdddd; -} -.highlight .ge { - color: #000000; - font-style: italic; -} -.highlight .gr { - color: #aa0000; -} -.highlight .gh { - color: #999999; -} -.highlight .gi { - color: #000000; - background-color: #ddffdd; -} -.highlight .go { - color: #888888; -} -.highlight .gp { - color: #555555; -} -.highlight .gs { - font-weight: bold; -} -.highlight .gu { - color: #aaaaaa; -} -.highlight .gt { - color: #aa0000; -} -.highlight .kc { - color: #000000; - font-weight: bold; -} -.highlight .kd { - color: #000000; - font-weight: bold; -} -.highlight .kn { - color: #000000; - font-weight: bold; -} -.highlight .kp { - color: #000000; - font-weight: bold; -} -.highlight .kr { - color: #000000; - font-weight: bold; -} -.highlight .kt { - color: #445588; - font-weight: bold; -} -.highlight .k, .highlight .kv { - color: #000000; - font-weight: bold; -} -.highlight .mf { - color: #009999; -} -.highlight .mh { - color: #009999; -} -.highlight .il { - color: #009999; -} -.highlight .mi { - color: #009999; -} -.highlight .mo { - color: #009999; -} -.highlight .m, .highlight .mb, .highlight .mx { - color: #009999; -} -.highlight .sa { - color: #000000; - font-weight: bold; -} -.highlight .sb { - color: #d14; -} -.highlight .sc { - color: #d14; -} -.highlight .sd { - color: #d14; -} -.highlight .s2 { - color: #d14; -} -.highlight .se { - color: #d14; -} -.highlight .sh { - color: #d14; -} -.highlight .si { - color: #d14; -} -.highlight .sx { - color: #d14; -} -.highlight .sr { - color: #009926; -} -.highlight .s1 { - color: #d14; -} -.highlight .ss { - color: #990073; -} -.highlight .s, .highlight .dl { - color: #d14; -} -.highlight .na { - color: #008080; -} -.highlight .bp { - color: #999999; -} -.highlight .nb { - color: #0086B3; -} -.highlight .nc { - color: #445588; - font-weight: bold; -} -.highlight .no { - color: #008080; -} -.highlight .nd { - color: #3c5d5d; - font-weight: bold; -} -.highlight .ni { - color: #800080; -} -.highlight .ne { - color: #990000; - font-weight: bold; -} -.highlight .nf, .highlight .fm { - color: #990000; - font-weight: bold; -} -.highlight .nl { - color: #990000; - font-weight: bold; -} -.highlight .nn { - color: #555555; -} -.highlight .nt { - color: #000080; -} -.highlight .vc { - color: #008080; -} -.highlight .vg { - color: #008080; -} -.highlight .vi { - color: #008080; -} -.highlight .nv, .highlight .vm { - color: #008080; -} -.highlight .ow { - color: #000000; - font-weight: bold; -} -.highlight .o { - color: #000000; - font-weight: bold; -} -.highlight .w { - color: #bbbbbb; -} -.highlight { - background-color: #f8f8f8; -}
\ No newline at end of file +pre code.hljs{display:block;overflow-x:auto;padding:1em}code.hljs{padding:3px 5px}/*! + Theme: GitHub + Description: Light theme as seen on github.com + Author: github.com + Maintainer: @Hirse + Updated: 2021-05-15 + + Outdated base version: https://github.com/primer/github-syntax-light + Current colors taken from GitHub's CSS +*/.hljs{color:#24292e;background:#fff}.hljs-doctag,.hljs-keyword,.hljs-meta .hljs-keyword,.hljs-template-tag,.hljs-template-variable,.hljs-type,.hljs-variable.language_{color:#d73a49}.hljs-title,.hljs-title.class_,.hljs-title.class_.inherited__,.hljs-title.function_{color:#6f42c1}.hljs-attr,.hljs-attribute,.hljs-literal,.hljs-meta,.hljs-number,.hljs-operator,.hljs-selector-attr,.hljs-selector-class,.hljs-selector-id,.hljs-variable{color:#005cc5}.hljs-meta .hljs-string,.hljs-regexp,.hljs-string{color:#032f62}.hljs-built_in,.hljs-symbol{color:#e36209}.hljs-code,.hljs-comment,.hljs-formula{color:#6a737d}.hljs-name,.hljs-quote,.hljs-selector-pseudo,.hljs-selector-tag{color:#22863a}.hljs-subst{color:#24292e}.hljs-section{color:#005cc5;font-weight:700}.hljs-bullet{color:#735c0f}.hljs-emphasis{color:#24292e;font-style:italic}.hljs-strong{color:#24292e;font-weight:700}.hljs-addition{color:#22863a;background-color:#f0fff4}.hljs-deletion{color:#b31d28;background-color:#ffeef0}
\ No newline at end of file diff --git a/public/posts/2021-03-05/my-first-post/index.html b/public/posts/2021-03-05/my-first-post/index.html index 37016b4..93df43a 100644 --- a/public/posts/2021-03-05/my-first-post/index.html +++ b/public/posts/2021-03-05/my-first-post/index.html @@ -9,7 +9,7 @@ <link rel="icon" type="image/svg+xml" href="/favicon.svg"> <title>My First Post | REPL: Rest-Eat-Program Loop</title> <link rel="stylesheet" href="/style.css?h=17cf97a767ec5fb6e64967729f40f30a"> - <link rel="stylesheet" href="/hl.css?h=208c52e3b7c9db1cad782c5d30b4698f"> + <link rel="stylesheet" href="/hl.css?h=340e65ffd5c17713efc9107c06304f7b"> </head> <body class="single"> <header class="header"> diff --git a/public/posts/2021-03-30/phperkaigi-2021/index.html b/public/posts/2021-03-30/phperkaigi-2021/index.html index 5da7c4a..aced3d6 100644 --- a/public/posts/2021-03-30/phperkaigi-2021/index.html +++ b/public/posts/2021-03-30/phperkaigi-2021/index.html @@ -10,7 +10,7 @@ <link rel="icon" type="image/svg+xml" href="/favicon.svg"> <title>PHPerKaigi 2021 | REPL: Rest-Eat-Program Loop</title> <link rel="stylesheet" href="/style.css?h=17cf97a767ec5fb6e64967729f40f30a"> - <link rel="stylesheet" href="/hl.css?h=208c52e3b7c9db1cad782c5d30b4698f"> + <link rel="stylesheet" href="/hl.css?h=340e65ffd5c17713efc9107c06304f7b"> </head> <body class="single"> <header class="header"> diff --git a/public/posts/2021-10-02/cpp-you-can-use-keywords-in-attributes/index.html b/public/posts/2021-10-02/cpp-you-can-use-keywords-in-attributes/index.html index 10e4693..39ab3cd 100644 --- a/public/posts/2021-10-02/cpp-you-can-use-keywords-in-attributes/index.html +++ b/public/posts/2021-10-02/cpp-you-can-use-keywords-in-attributes/index.html @@ -10,7 +10,7 @@ <link rel="icon" type="image/svg+xml" href="/favicon.svg"> <title>【C++】 属性構文の属性名にはキーワードが使える | REPL: Rest-Eat-Program Loop</title> <link rel="stylesheet" href="/style.css?h=17cf97a767ec5fb6e64967729f40f30a"> - <link rel="stylesheet" href="/hl.css?h=208c52e3b7c9db1cad782c5d30b4698f"> + <link rel="stylesheet" href="/hl.css?h=340e65ffd5c17713efc9107c06304f7b"> </head> <body class="single"> <header class="header"> @@ -66,24 +66,24 @@ タイトル落ち。まずはこのコードを見て欲しい。 </p> - <pre class="highlight" language="cpp" linenumbering="unnumbered"><code>#include <iostream> + <pre class="highlight" language="cpp" linenumbering="unnumbered"><code class="highlight"><span class="hljs-meta">#<span class="hljs-keyword">include</span> <span class="hljs-string"><iostream></span></span> -[[alignas]] [[alignof]] [[and]] [[and_eq]] [[asm]] [[auto]] [[bitand]] -[[bitor]] [[bool]] [[break]] [[case]] [[catch]] [[char]] [[char16_t]] -[[char32_t]] [[class]] [[compl]] [[const]] [[const_cast]] [[constexpr]] -[[continue]] [[decltype]] [[default]] [[delete]] [[do]] [[double]] -[[dynamic_cast]] [[else]] [[enum]] [[explicit]] [[export]] [[extern]] [[false]] -[[final]] [[float]] [[for]] [[friend]] [[goto]] [[if]] [[inline]] [[int]] -[[long]] [[mutable]] [[namespace]] [[new]] [[noexcept]] [[not]] [[not_eq]] -[[nullptr]] [[operator]] [[or]] [[or_eq]] [[override]] [[private]] -[[protected]] [[public]] [[register]] [[reinterpret_cast]] [[return]] [[short]] -[[signed]] [[sizeof]] [[static]] [[static_assert]] [[static_cast]] [[struct]] -[[switch]] [[template]] [[this]] [[thread_local]] [[throw]] [[true]] [[try]] -[[typedef]] [[typeid]] [[typename]] [[union]] [[unsigned]] -[[virtual]] [[void]] [[volatile]] [[wchar_t]] [[while]] [[xor]] [[xor_eq]] -// [[using]] -int main() { -std::cout << "Hello, World!" << std::endl; +[[<span class="hljs-keyword">alignas</span>]] [[<span class="hljs-keyword">alignof</span>]] [[<span class="hljs-keyword">and</span>]] [[<span class="hljs-keyword">and_eq</span>]] [[<span class="hljs-keyword">asm</span>]] [[<span class="hljs-keyword">auto</span>]] [[<span class="hljs-keyword">bitand</span>]] +[[<span class="hljs-keyword">bitor</span>]] [[<span class="hljs-type">bool</span>]] [[<span class="hljs-keyword">break</span>]] [[<span class="hljs-keyword">case</span>]] [[<span class="hljs-keyword">catch</span>]] [[<span class="hljs-type">char</span>]] [[<span class="hljs-type">char16_t</span>]] +[[<span class="hljs-type">char32_t</span>]] [[<span class="hljs-keyword">class</span>]] [[<span class="hljs-keyword">compl</span>]] [[<span class="hljs-type">const</span>]] [[<span class="hljs-keyword">const_cast</span>]] [[<span class="hljs-keyword">constexpr</span>]] +[[<span class="hljs-keyword">continue</span>]] [[<span class="hljs-keyword">decltype</span>]] [[<span class="hljs-keyword">default</span>]] [[<span class="hljs-keyword">delete</span>]] [[<span class="hljs-keyword">do</span>]] [[<span class="hljs-type">double</span>]] +[[<span class="hljs-keyword">dynamic_cast</span>]] [[<span class="hljs-keyword">else</span>]] [[<span class="hljs-keyword">enum</span>]] [[<span class="hljs-keyword">explicit</span>]] [[<span class="hljs-keyword">export</span>]] [[<span class="hljs-keyword">extern</span>]] [[<span class="hljs-literal">false</span>]] +[[<span class="hljs-keyword">final</span>]] [[<span class="hljs-type">float</span>]] [[<span class="hljs-keyword">for</span>]] [[<span class="hljs-keyword">friend</span>]] [[<span class="hljs-keyword">goto</span>]] [[<span class="hljs-keyword">if</span>]] [[<span class="hljs-keyword">inline</span>]] [[<span class="hljs-type">int</span>]] +[[<span class="hljs-type">long</span>]] [[<span class="hljs-keyword">mutable</span>]] [[<span class="hljs-keyword">namespace</span>]] [[<span class="hljs-keyword">new</span>]] [[<span class="hljs-keyword">noexcept</span>]] [[<span class="hljs-keyword">not</span>]] [[<span class="hljs-keyword">not_eq</span>]] +[[<span class="hljs-literal">nullptr</span>]] [[<span class="hljs-keyword">operator</span>]] [[<span class="hljs-keyword">or</span>]] [[<span class="hljs-keyword">or_eq</span>]] [[<span class="hljs-keyword">override</span>]] [[<span class="hljs-keyword">private</span>]] +[[<span class="hljs-keyword">protected</span>]] [[<span class="hljs-keyword">public</span>]] [[<span class="hljs-keyword">register</span>]] [[<span class="hljs-keyword">reinterpret_cast</span>]] [[<span class="hljs-keyword">return</span>]] [[<span class="hljs-type">short</span>]] +[[<span class="hljs-type">signed</span>]] [[<span class="hljs-keyword">sizeof</span>]] [[<span class="hljs-type">static</span>]] [[<span class="hljs-keyword">static_assert</span>]] [[<span class="hljs-keyword">static_cast</span>]] [[<span class="hljs-keyword">struct</span>]] +[[<span class="hljs-keyword">switch</span>]] [[<span class="hljs-keyword">template</span>]] [[<span class="hljs-keyword">this</span>]] [[<span class="hljs-keyword">thread_local</span>]] [[<span class="hljs-keyword">throw</span>]] [[<span class="hljs-literal">true</span>]] [[<span class="hljs-keyword">try</span>]] +[[<span class="hljs-keyword">typedef</span>]] [[<span class="hljs-keyword">typeid</span>]] [[<span class="hljs-keyword">typename</span>]] [[<span class="hljs-keyword">union</span>]] [[<span class="hljs-type">unsigned</span>]] +[[<span class="hljs-keyword">virtual</span>]] [[<span class="hljs-type">void</span>]] [[<span class="hljs-keyword">volatile</span>]] [[<span class="hljs-type">wchar_t</span>]] [[<span class="hljs-keyword">while</span>]] [[<span class="hljs-keyword">xor</span>]] [[<span class="hljs-keyword">xor_eq</span>]] +<span class="hljs-comment">// [[using]]</span> +<span class="hljs-type">int</span> <span class="hljs-built_in">main</span>() { +std::cout << <span class="hljs-string">"Hello, World!"</span> << std::endl; }</code></pre> <blockquote> @@ -134,8 +134,8 @@ std::cout << "Hello, World!" << std::endl; 上のコードでは<code>[[using]]</code>をコメントアウトしているが、これは<code>using</code>キーワードのみ属性構文の中で意味を持つからであり、このコメントアウトを外すとコンパイルに失敗する。 </p> - <pre class="highlight" language="cpp" linenumbering="unnumbered"><code>// using の例 -[[using foo: attr1, attr2]] int x; // [[foo::attr1, foo::attr2]] の糖衣構文</code></pre> + <pre class="highlight" language="cpp" linenumbering="unnumbered"><code class="highlight"><span class="hljs-comment">// using の例</span> +[[<span class="hljs-keyword">using</span> foo: attr1, attr2]] <span class="hljs-type">int</span> x; <span class="hljs-comment">// [[foo::attr1, foo::attr2]] の糖衣構文</span></code></pre> <p> C++17 の仕様も見てみる (正確には標準化前のドラフト)。 diff --git a/public/posts/2021-10-02/python-unbound-local-error/index.html b/public/posts/2021-10-02/python-unbound-local-error/index.html index 4461af8..1631ccb 100644 --- a/public/posts/2021-10-02/python-unbound-local-error/index.html +++ b/public/posts/2021-10-02/python-unbound-local-error/index.html @@ -10,7 +10,7 @@ <link rel="icon" type="image/svg+xml" href="/favicon.svg"> <title>【Python】 クロージャとUnboundLocalError: local variable 'x' referenced before assignment | REPL: Rest-Eat-Program Loop</title> <link rel="stylesheet" href="/style.css?h=17cf97a767ec5fb6e64967729f40f30a"> - <link rel="stylesheet" href="/hl.css?h=208c52e3b7c9db1cad782c5d30b4698f"> + <link rel="stylesheet" href="/hl.css?h=340e65ffd5c17713efc9107c06304f7b"> </head> <body class="single"> <header class="header"> @@ -70,10 +70,10 @@ Python でクロージャを作ろうと、次のようなコードを書いた。 </p> - <pre class="highlight" language="python" linenumbering="unnumbered"><code>def f(): -x = 0 -def g(): -x += 1 + <pre class="highlight" language="python" linenumbering="unnumbered"><code class="highlight"><span class="hljs-keyword">def</span> <span class="hljs-title function_">f</span>(): +x = <span class="hljs-number">0</span> +<span class="hljs-keyword">def</span> <span class="hljs-title function_">g</span>(): +x += <span class="hljs-number">1</span> g() f()</code></pre> @@ -92,26 +92,26 @@ f()</code></pre> local変数<code>x</code>が代入前に参照された、とある。これは、<code>f</code>の<code>x</code>を参照するのではなく、新しく別の変数を<code>g</code>内に作ってしまっているため。 前述のコードを宣言と代入を便宜上分けて書き直すと次のようになる。<code>var</code>を変数宣言のための構文として擬似的に利用している。 </p> - <pre class="highlight" language="python" linenumbering="unnumbered"><code># 注: var は正しい Python の文法ではない。上記参照のこと -def f(): -var x # f の local変数 'x' を宣言 -x = 0 # x に 0 を代入 -def g(): # f の内部関数 g を定義 -var x # g の local変数 'x' を宣言 -# たまたま f にも同じ名前の変数があるが、それとは別の変数 -x += 1 # x に 1 を加算 (x = x + 1 の糖衣構文) -# 加算する前の値を参照しようとするが、まだ代入されていないためエラー + <pre class="highlight" language="python" linenumbering="unnumbered"><code class="highlight"><span class="hljs-comment"># 注: var は正しい Python の文法ではない。上記参照のこと</span> +<span class="hljs-keyword">def</span> <span class="hljs-title function_">f</span>(): +var x <span class="hljs-comment"># f の local変数 'x' を宣言</span> +x = <span class="hljs-number">0</span> <span class="hljs-comment"># x に 0 を代入</span> +<span class="hljs-keyword">def</span> <span class="hljs-title function_">g</span>(): <span class="hljs-comment"># f の内部関数 g を定義</span> +var x <span class="hljs-comment"># g の local変数 'x' を宣言</span> +<span class="hljs-comment"># たまたま f にも同じ名前の変数があるが、それとは別の変数</span> +x += <span class="hljs-number">1</span> <span class="hljs-comment"># x に 1 を加算 (x = x + 1 の糖衣構文)</span> +<span class="hljs-comment"># 加算する前の値を参照しようとするが、まだ代入されていないためエラー</span> g()</code></pre> <p> 当初の意図を表現するには、次のように書けばよい。 </p> - <pre class="highlight" language="python" linenumbering="unnumbered"><code>def f(): -x = 0 -def g(): -nonlocal x ## (*) -x += 1 + <pre class="highlight" language="python" linenumbering="unnumbered"><code class="highlight"><span class="hljs-keyword">def</span> <span class="hljs-title function_">f</span>(): +x = <span class="hljs-number">0</span> +<span class="hljs-keyword">def</span> <span class="hljs-title function_">g</span>(): +<span class="hljs-keyword">nonlocal</span> x <span class="hljs-comment">## (*)</span> +x += <span class="hljs-number">1</span> g()</code></pre> <p> diff --git a/public/posts/2021-10-02/ruby-detect-running-implementation/index.html b/public/posts/2021-10-02/ruby-detect-running-implementation/index.html index 06b5eb5..03bae40 100644 --- a/public/posts/2021-10-02/ruby-detect-running-implementation/index.html +++ b/public/posts/2021-10-02/ruby-detect-running-implementation/index.html @@ -10,7 +10,7 @@ <link rel="icon" type="image/svg+xml" href="/favicon.svg"> <title>【Ruby】 自身を実行している処理系の種類を判定する | REPL: Rest-Eat-Program Loop</title> <link rel="stylesheet" href="/style.css?h=17cf97a767ec5fb6e64967729f40f30a"> - <link rel="stylesheet" href="/hl.css?h=208c52e3b7c9db1cad782c5d30b4698f"> + <link rel="stylesheet" href="/hl.css?h=340e65ffd5c17713efc9107c06304f7b"> </head> <body class="single"> <header class="header"> @@ -75,10 +75,10 @@ 上記ページの例から引用する: </p> - <pre class="highlight" language="shell-session" linenumbering="unnumbered"><code>$ ruby-1.9.1 -ve 'p RUBY_ENGINE' + <pre class="highlight" language="shell-session" linenumbering="unnumbered"><code class="highlight">$ ruby-1.9.1 -ve 'p RUBY_ENGINE' ruby 1.9.1p0 (2009-03-04 revision 22762) [x86_64-linux] "ruby" -$ jruby -ve 'p RUBY_ENGINE' +$ jruby -ve 'p RUBY_ENGINE' jruby 1.2.0 (ruby 1.8.6 patchlevel 287) (2009-03-16 rev 9419) [i386-java] "jruby"</code></pre> @@ -200,10 +200,10 @@ jruby 1.2.0 (ruby 1.8.6 patchlevel 287) (2009-03-16 rev 9419) [i386-java] <a href="https://github.com/mruby/mruby/blob/ed29d74bfd95362eaeb946fcf7e865d80346b62b/include/mruby/version.h#L32-L35">mruby 該当部分のソース</a>より引用: </p> - <pre class="highlight" language="c" linenumbering="unnumbered"><code>/* + <pre class="highlight" language="c" linenumbering="unnumbered"><code class="highlight"><span class="hljs-comment">/* * Ruby engine. -*/ -#define MRUBY_RUBY_ENGINE "mruby"</code></pre> +*/</span> +<span class="hljs-meta">#<span class="hljs-keyword">define</span> MRUBY_RUBY_ENGINE <span class="hljs-string">"mruby"</span></span></code></pre> </div> </article> </main> diff --git a/public/posts/2021-10-02/ruby-then-keyword-and-case-in/index.html b/public/posts/2021-10-02/ruby-then-keyword-and-case-in/index.html index 49127f6..f66ae0b 100644 --- a/public/posts/2021-10-02/ruby-then-keyword-and-case-in/index.html +++ b/public/posts/2021-10-02/ruby-then-keyword-and-case-in/index.html @@ -10,7 +10,7 @@ <link rel="icon" type="image/svg+xml" href="/favicon.svg"> <title>【Ruby】 then キーワードと case in | REPL: Rest-Eat-Program Loop</title> <link rel="stylesheet" href="/style.css?h=17cf97a767ec5fb6e64967729f40f30a"> - <link rel="stylesheet" href="/hl.css?h=208c52e3b7c9db1cad782c5d30b4698f"> + <link rel="stylesheet" href="/hl.css?h=340e65ffd5c17713efc9107c06304f7b"> </head> <body class="single"> <header class="header"> @@ -75,36 +75,36 @@ 使われることは稀だが、Ruby では<code>then</code>がキーワードになっている。次のように使う: </p> - <pre class="highlight" language="ruby" linenumbering="unnumbered"><code>if cond then - puts "Y" - else - puts "N" - end</code></pre> + <pre class="highlight" language="ruby" linenumbering="unnumbered"><code class="highlight"><span class="hljs-keyword">if</span> cond <span class="hljs-keyword">then</span> + puts <span class="hljs-string">"Y"</span> + <span class="hljs-keyword">else</span> + puts <span class="hljs-string">"N"</span> + <span class="hljs-keyword">end</span></code></pre> <p> このキーワードが現れうる場所はいくつかあり、<code>if</code>、<code>unless</code>、<code>rescue</code>、<code>case</code>構文がそれに当たる。 上記のように、何か条件を書いた後<code>then</code>を置き、式がそこで終了していることを示すマーカーとして機能する。 </p> - <pre class="highlight" language="ruby" linenumbering="unnumbered"><code># Example: + <pre class="highlight" language="ruby" linenumbering="unnumbered"><code class="highlight"><span class="hljs-comment"># Example:</span> -if x then +<span class="hljs-keyword">if</span> x <span class="hljs-keyword">then</span> a -end +<span class="hljs-keyword">end</span> -unless x then +<span class="hljs-keyword">unless</span> x <span class="hljs-keyword">then</span> a -end +<span class="hljs-keyword">end</span> -begin +<span class="hljs-keyword">begin</span> a -rescue then +<span class="hljs-keyword">rescue</span> <span class="hljs-keyword">then</span> b -end +<span class="hljs-keyword">end</span> -case x -when p then +<span class="hljs-keyword">case</span> x +<span class="hljs-keyword">when</span> p <span class="hljs-keyword">then</span> a -end</code></pre> +<span class="hljs-keyword">end</span></code></pre> </section> <section id="section--_なぜ普段は書かなくてもよいのか"> @@ -113,17 +113,17 @@ end</code></pre> 普通 Ruby のコードで<code>then</code>を書くことはない。なぜか。次のコードを実行してみるとわかる。 </p> - <pre class="highlight" language="ruby" linenumbering="unnumbered"><code>if true puts 'Hello, World!' end</code></pre> + <pre class="highlight" language="ruby" linenumbering="unnumbered"><code class="highlight"><span class="hljs-keyword">if</span> <span class="hljs-literal">true</span> puts <span class="hljs-string">'Hello, World!'</span> <span class="hljs-keyword">end</span></code></pre> <p> 次のような構文エラーが出力される。 </p> - <pre class="monospaced highlight"><code>20:1: syntax error, unexpected local variable or method, expecting `then' or ';' or '\n' -if true puts 'Hello, World!' end + <pre class="monospaced highlight"><code>20:1: syntax error, unexpected local variable or method, expecting `then' or ';' or '\n' +if true puts 'Hello, World!' end ^~~~ -20:1: syntax error, unexpected `end', expecting end-of-input -...f true puts 'Hello, World!' end</code></pre> +20:1: syntax error, unexpected `end', expecting end-of-input +...f true puts 'Hello, World!' end</code></pre> <p> 二つ目のメッセージは無視して一つ目を読むと、<code>then</code>か<code>;</code>か改行が来るはずのところ変数だかメソッドだかが現れたことによりエラーとなっているようだ。 @@ -133,8 +133,8 @@ if true puts 'Hello, World!' end ポイントは改行が<code>then</code>(や<code>;</code>) の代わりとなることである。<code>true</code>の後に改行を入れてみる。 </p> - <pre class="highlight" language="ruby" linenumbering="unnumbered"><code>if true -puts 'Hello, World!' end</code></pre> + <pre class="highlight" language="ruby" linenumbering="unnumbered"><code class="highlight"><span class="hljs-keyword">if</span> <span class="hljs-literal">true</span> +puts <span class="hljs-string">'Hello, World!'</span> <span class="hljs-keyword">end</span></code></pre> <p> 無事 Hello, World! と出力されるようになった。 @@ -147,21 +147,21 @@ puts 'Hello, World!' end</code></pre> なぜ<code>then</code>や<code>;</code>や改行 (以下 「<code>then</code>等」) が必要なのだろうか。次の例を見てほしい: </p> - <pre class="highlight" language="ruby" linenumbering="unnumbered"><code>if a b end</code></pre> + <pre class="highlight" language="ruby" linenumbering="unnumbered"><code class="highlight"><span class="hljs-keyword">if</span> a b <span class="hljs-keyword">end</span></code></pre> <p> <code>then</code>も<code>;</code>も改行もないのでエラーになるが、これは条件式がどこまで続いているのかわからないためだ。 この例は二通りに解釈できる。 </p> - <pre class="highlight" language="ruby" linenumbering="unnumbered"><code># a という変数かメソッドの評価結果が truthy なら b という変数かメソッドを評価 -if a then + <pre class="highlight" language="ruby" linenumbering="unnumbered"><code class="highlight"><span class="hljs-comment"># a という変数かメソッドの評価結果が truthy なら b という変数かメソッドを評価</span> +<span class="hljs-keyword">if</span> a <span class="hljs-keyword">then</span> b -end</code></pre> +<span class="hljs-keyword">end</span></code></pre> - <pre class="highlight" language="ruby" linenumbering="unnumbered"><code># a というメソッドに b という変数かメソッドの評価結果を渡して呼び出し、 -# その結果が truthy なら何もしない -if a(b) then -end</code></pre> + <pre class="highlight" language="ruby" linenumbering="unnumbered"><code class="highlight"><span class="hljs-comment"># a というメソッドに b という変数かメソッドの評価結果を渡して呼び出し、</span> +<span class="hljs-comment"># その結果が truthy なら何もしない</span> +<span class="hljs-keyword">if</span> a(b) <span class="hljs-keyword">then</span> +<span class="hljs-keyword">end</span></code></pre> <p> <code>then</code>等はこの曖昧性を排除するためにあり、条件式は<code>if</code>から<code>then</code>等までの間にある、ということを明確にする。 C系の<code>if</code>後に来る<code>(</code>/<code>)</code>や、Python の<code>:</code>、Rust/Go/Swift などの<code>{</code>も同じ役割を持つ。 @@ -182,7 +182,7 @@ end</code></pre> <a href="https://github.com/ruby/ruby/blob/221ca0f8281d39f0dfdfe13b2448875384bbf735/parse.y#L3961-L3986">https://github.com/ruby/ruby/blob/221ca0f8281d39f0dfdfe13b2448875384bbf735/parse.y#L3961-L3986</a> </p> - <pre class="highlight" language="yacc" linenumbering="unnumbered"><code>p_case_body : keyword_in + <pre class="highlight" language="yacc" linenumbering="unnumbered"><code class="highlight">p_case_body : keyword_in { SET_LEX_STATE(EXPR_BEG|EXPR_LABEL); p->command_start = FALSE; @@ -213,7 +213,7 @@ end</code></pre> 簡略版: </p> - <pre class="highlight" language="yacc" linenumbering="unnumbered"><code>p_case_body : keyword_in p_top_expr then compstmt p_cases + <pre class="highlight" language="yacc" linenumbering="unnumbered"><code class="highlight">p_case_body : keyword_in p_top_expr then compstmt p_cases ;</code></pre> <p> @@ -224,36 +224,36 @@ end</code></pre> これにより、<code>case</code>-<code>when</code>による従来の構文と同じように、<code>then</code>等をパターンの後ろに挿入すればよいことがわかった。つまり次の3通りのいずれかになる: </p> - <pre class="highlight" language="ruby" linenumbering="unnumbered"><code>case x -in 1 then a -in 2 then b -in 3 then c -end + <pre class="highlight" language="ruby" linenumbering="unnumbered"><code class="highlight"><span class="hljs-keyword">case</span> x +<span class="hljs-keyword">in</span> <span class="hljs-number">1</span> <span class="hljs-keyword">then</span> a +<span class="hljs-keyword">in</span> <span class="hljs-number">2</span> <span class="hljs-keyword">then</span> b +<span class="hljs-keyword">in</span> <span class="hljs-number">3</span> <span class="hljs-keyword">then</span> c +<span class="hljs-keyword">end</span> -case x -in 1 +<span class="hljs-keyword">case</span> x +<span class="hljs-keyword">in</span> <span class="hljs-number">1</span> a -in 2 +<span class="hljs-keyword">in</span> <span class="hljs-number">2</span> b -in 3 +<span class="hljs-keyword">in</span> <span class="hljs-number">3</span> c -end +<span class="hljs-keyword">end</span> -case x -in 1; a -in 2; b -in 3; c -end</code></pre> +<span class="hljs-keyword">case</span> x +<span class="hljs-keyword">in</span> <span class="hljs-number">1</span>; a +<span class="hljs-keyword">in</span> <span class="hljs-number">2</span>; b +<span class="hljs-keyword">in</span> <span class="hljs-number">3</span>; c +<span class="hljs-keyword">end</span></code></pre> <p> ところで、<code>p_top_expr</code>には<code>if</code>による guard clause が書けるので、その場合は<code>if</code>-<code>then</code>と似たような見た目になる。 </p> - <pre class="highlight" language="ruby" linenumbering="unnumbered"><code>case x -in 0 then a -in n if n < 0 then b -in n then c -end</code></pre> + <pre class="highlight" language="ruby" linenumbering="unnumbered"><code class="highlight"><span class="hljs-keyword">case</span> x +<span class="hljs-keyword">in</span> <span class="hljs-number">0</span> <span class="hljs-keyword">then</span> a +<span class="hljs-keyword">in</span> n <span class="hljs-keyword">if</span> n < <span class="hljs-number">0</span> <span class="hljs-keyword">then</span> b +<span class="hljs-keyword">in</span> n <span class="hljs-keyword">then</span> c +<span class="hljs-keyword">end</span></code></pre> </section> <section id="section--_まとめ"> diff --git a/public/posts/2021-10-02/rust-where-are-primitive-types-from/index.html b/public/posts/2021-10-02/rust-where-are-primitive-types-from/index.html index e86d724..bc40aaa 100644 --- a/public/posts/2021-10-02/rust-where-are-primitive-types-from/index.html +++ b/public/posts/2021-10-02/rust-where-are-primitive-types-from/index.html @@ -10,7 +10,7 @@ <link rel="icon" type="image/svg+xml" href="/favicon.svg"> <title>Rust のプリミティブ型はどこからやって来るか | REPL: Rest-Eat-Program Loop</title> <link rel="stylesheet" href="/style.css?h=17cf97a767ec5fb6e64967729f40f30a"> - <link rel="stylesheet" href="/hl.css?h=208c52e3b7c9db1cad782c5d30b4698f"> + <link rel="stylesheet" href="/hl.css?h=340e65ffd5c17713efc9107c06304f7b"> </head> <body class="single"> <header class="header"> @@ -65,26 +65,26 @@ Rust において、プリミティブ型の名前は予約語でない。したがって、次のコードは合法である。 </p> - <pre class="highlight" language="rust" linenumbering="unnumbered"><code>#![allow(non_camel_case_types)] -#![allow(dead_code)] + <pre class="highlight" language="rust" linenumbering="unnumbered"><code class="highlight"><span class="hljs-meta">#![allow(non_camel_case_types)]</span> +<span class="hljs-meta">#![allow(dead_code)]</span> -struct bool; -struct char; -struct i8; -struct i16; -struct i32; -struct i64; -struct i128; -struct isize; -struct u8; -struct u16; -struct u32; -struct u64; -struct u128; -struct usize; -struct f32; -struct f64; -struct str;</code></pre> +<span class="hljs-keyword">struct</span> <span class="hljs-title class_">bool</span>; +<span class="hljs-keyword">struct</span> <span class="hljs-title class_">char</span>; +<span class="hljs-keyword">struct</span> <span class="hljs-title class_">i8</span>; +<span class="hljs-keyword">struct</span> <span class="hljs-title class_">i16</span>; +<span class="hljs-keyword">struct</span> <span class="hljs-title class_">i32</span>; +<span class="hljs-keyword">struct</span> <span class="hljs-title class_">i64</span>; +<span class="hljs-keyword">struct</span> <span class="hljs-title class_">i128</span>; +<span class="hljs-keyword">struct</span> <span class="hljs-title class_">isize</span>; +<span class="hljs-keyword">struct</span> <span class="hljs-title class_">u8</span>; +<span class="hljs-keyword">struct</span> <span class="hljs-title class_">u16</span>; +<span class="hljs-keyword">struct</span> <span class="hljs-title class_">u32</span>; +<span class="hljs-keyword">struct</span> <span class="hljs-title class_">u64</span>; +<span class="hljs-keyword">struct</span> <span class="hljs-title class_">u128</span>; +<span class="hljs-keyword">struct</span> <span class="hljs-title class_">usize</span>; +<span class="hljs-keyword">struct</span> <span class="hljs-title class_">f32</span>; +<span class="hljs-keyword">struct</span> <span class="hljs-title class_">f64</span>; +<span class="hljs-keyword">struct</span> <span class="hljs-title class_">str</span>;</code></pre> <p> では、普段単に<code>bool</code>と書いたとき、この<code>bool</code>は一体どこから来ているのか。rustc のソースを追ってみた。 @@ -119,20 +119,20 @@ struct str;</code></pre> <code>rustc</code>はセルフホストされている (=<code>rustc</code>自身が Rust で書かれている) ので、<code>bool</code>や<code>char</code>などで適当に検索をかけてもノイズが多すぎて話にならない。 しかし、お誂え向きなことに<code>i128</code>/<code>u128</code>というコンパイラ自身が使うことがなさそうな型が存在するのでこれを使って<code>git grep</code>してみる。 </p> - <pre class="monospaced highlight"><code>$ git grep "\bi128\b" | wc # i128 + <pre class="monospaced highlight"><code>$ git grep "\bi128\b" | wc # i128 165 1069 15790 -$ git grep "\bu128\b" | wc # u128 +$ git grep "\bu128\b" | wc # u128 293 2127 26667 -$ git grep "\bbool\b" | wc # cf. bool の結果 +$ git grep "\bbool\b" | wc # cf. bool の結果 3563 23577 294659</code></pre> <p> 165 程度であれば探すことができそうだ。今回は、クレート名を見ておおよその当たりをつけた。 </p> - <pre class="monospaced highlight"><code>$ git grep "\bi128\b" + <pre class="monospaced highlight"><code>$ git grep "\bi128\b" ... rustc_resolve/src/lib.rs: table.insert(sym::i128, Int(IntTy::I128)); ...</code></pre> @@ -141,36 +141,36 @@ rustc_resolve/src/lib.rs: table.insert(sym::i128, Int(IntTy::I128)); <code>rustc_resolve</code>というのはいかにも名前解決を担いそうなクレート名である。該当箇所を見てみる。 </p> - <pre class="highlight" language="rust" linenumbering="unnumbered"><code>/// Interns the names of the primitive types. -/// -/// All other types are defined somewhere and possibly imported, but the primitive ones need -/// special handling, since they have no place of origin. -struct PrimitiveTypeTable { + <pre class="highlight" language="rust" linenumbering="unnumbered"><code class="highlight"><span class="hljs-comment">/// Interns the names of the primitive types.</span> +<span class="hljs-comment">///</span> +<span class="hljs-comment">/// All other types are defined somewhere and possibly imported, but the primitive ones need</span> +<span class="hljs-comment">/// special handling, since they have no place of origin.</span> +<span class="hljs-keyword">struct</span> <span class="hljs-title class_">PrimitiveTypeTable</span> { primitive_types: FxHashMap<Symbol, PrimTy>, } -impl PrimitiveTypeTable { -fn new() -> PrimitiveTypeTable { -let mut table = FxHashMap::default(); +<span class="hljs-keyword">impl</span> <span class="hljs-title class_">PrimitiveTypeTable</span> { +<span class="hljs-keyword">fn</span> <span class="hljs-title function_">new</span>() <span class="hljs-punctuation">-></span> PrimitiveTypeTable { +<span class="hljs-keyword">let</span> <span class="hljs-keyword">mut </span><span class="hljs-variable">table</span> = FxHashMap::<span class="hljs-title function_ invoke__">default</span>(); -table.insert(sym::bool, Bool); -table.insert(sym::char, Char); -table.insert(sym::f32, Float(FloatTy::F32)); -table.insert(sym::f64, Float(FloatTy::F64)); -table.insert(sym::isize, Int(IntTy::Isize)); -table.insert(sym::i8, Int(IntTy::I8)); -table.insert(sym::i16, Int(IntTy::I16)); -table.insert(sym::i32, Int(IntTy::I32)); -table.insert(sym::i64, Int(IntTy::I64)); -table.insert(sym::i128, Int(IntTy::I128)); -table.insert(sym::str, Str); -table.insert(sym::usize, Uint(UintTy::Usize)); -table.insert(sym::u8, Uint(UintTy::U8)); -table.insert(sym::u16, Uint(UintTy::U16)); -table.insert(sym::u32, Uint(UintTy::U32)); -table.insert(sym::u64, Uint(UintTy::U64)); -table.insert(sym::u128, Uint(UintTy::U128)); -Self { primitive_types: table } +table.<span class="hljs-title function_ invoke__">insert</span>(sym::<span class="hljs-type">bool</span>, Bool); +table.<span class="hljs-title function_ invoke__">insert</span>(sym::<span class="hljs-type">char</span>, Char); +table.<span class="hljs-title function_ invoke__">insert</span>(sym::<span class="hljs-type">f32</span>, <span class="hljs-title function_ invoke__">Float</span>(FloatTy::F32)); +table.<span class="hljs-title function_ invoke__">insert</span>(sym::<span class="hljs-type">f64</span>, <span class="hljs-title function_ invoke__">Float</span>(FloatTy::F64)); +table.<span class="hljs-title function_ invoke__">insert</span>(sym::<span class="hljs-type">isize</span>, <span class="hljs-title function_ invoke__">Int</span>(IntTy::Isize)); +table.<span class="hljs-title function_ invoke__">insert</span>(sym::<span class="hljs-type">i8</span>, <span class="hljs-title function_ invoke__">Int</span>(IntTy::I8)); +table.<span class="hljs-title function_ invoke__">insert</span>(sym::<span class="hljs-type">i16</span>, <span class="hljs-title function_ invoke__">Int</span>(IntTy::I16)); +table.<span class="hljs-title function_ invoke__">insert</span>(sym::<span class="hljs-type">i32</span>, <span class="hljs-title function_ invoke__">Int</span>(IntTy::I32)); +table.<span class="hljs-title function_ invoke__">insert</span>(sym::<span class="hljs-type">i64</span>, <span class="hljs-title function_ invoke__">Int</span>(IntTy::I64)); +table.<span class="hljs-title function_ invoke__">insert</span>(sym::<span class="hljs-type">i128</span>, <span class="hljs-title function_ invoke__">Int</span>(IntTy::I128)); +table.<span class="hljs-title function_ invoke__">insert</span>(sym::<span class="hljs-type">str</span>, Str); +table.<span class="hljs-title function_ invoke__">insert</span>(sym::<span class="hljs-type">usize</span>, <span class="hljs-title function_ invoke__">Uint</span>(UintTy::Usize)); +table.<span class="hljs-title function_ invoke__">insert</span>(sym::<span class="hljs-type">u8</span>, <span class="hljs-title function_ invoke__">Uint</span>(UintTy::U8)); +table.<span class="hljs-title function_ invoke__">insert</span>(sym::<span class="hljs-type">u16</span>, <span class="hljs-title function_ invoke__">Uint</span>(UintTy::U16)); +table.<span class="hljs-title function_ invoke__">insert</span>(sym::<span class="hljs-type">u32</span>, <span class="hljs-title function_ invoke__">Uint</span>(UintTy::U32)); +table.<span class="hljs-title function_ invoke__">insert</span>(sym::<span class="hljs-type">u64</span>, <span class="hljs-title function_ invoke__">Uint</span>(UintTy::U64)); +table.<span class="hljs-title function_ invoke__">insert</span>(sym::<span class="hljs-type">u128</span>, <span class="hljs-title function_ invoke__">Uint</span>(UintTy::U128)); +<span class="hljs-keyword">Self</span> { primitive_types: table } } }</code></pre> @@ -188,26 +188,26 @@ Self { primitive_types: table } とある。次はこの struct の使用箇所を追う。追うと言っても使われている箇所は次の一箇所しかない。なお説明に不要な箇所は大きく削っている。 </p> - <pre class="highlight" language="rust" linenumbering="unnumbered"><code> /// This resolves the identifier `ident` in the namespace `ns` in the current lexical scope. -/// (略) -fn resolve_ident_in_lexical_scope( -&mut self, -mut ident: Ident, + <pre class="highlight" language="rust" linenumbering="unnumbered"><code class="highlight"> <span class="hljs-comment">/// This resolves the identifier `ident` in the namespace `ns` in the current lexical scope.</span> +<span class="hljs-comment">/// (略)</span> +<span class="hljs-keyword">fn</span> <span class="hljs-title function_">resolve_ident_in_lexical_scope</span>( +&<span class="hljs-keyword">mut</span> <span class="hljs-keyword">self</span>, +<span class="hljs-keyword">mut</span> ident: Ident, ns: Namespace, -// (略) -) -> Option<LexicalScopeBinding<'a>> { -// (略) +<span class="hljs-comment">// (略)</span> +) <span class="hljs-punctuation">-></span> <span class="hljs-type">Option</span><LexicalScopeBinding<<span class="hljs-symbol">'a</span>>> { +<span class="hljs-comment">// (略)</span> -if ns == TypeNS { -if let Some(prim_ty) = self.primitive_type_table.primitive_types.get(&ident.name) { -let binding = -(Res::PrimTy(*prim_ty), ty::Visibility::Public, DUMMY_SP, ExpnId::root()) -.to_name_binding(self.arenas); -return Some(LexicalScopeBinding::Item(binding)); +<span class="hljs-keyword">if</span> ns == TypeNS { +<span class="hljs-keyword">if</span> <span class="hljs-keyword">let</span> <span class="hljs-variable">Some</span>(prim_ty) = <span class="hljs-keyword">self</span>.primitive_type_table.primitive_types.<span class="hljs-title function_ invoke__">get</span>(&ident.name) { +<span class="hljs-keyword">let</span> <span class="hljs-variable">binding</span> = +(Res::<span class="hljs-title function_ invoke__">PrimTy</span>(*prim_ty), ty::Visibility::Public, DUMMY_SP, ExpnId::<span class="hljs-title function_ invoke__">root</span>()) +.<span class="hljs-title function_ invoke__">to_name_binding</span>(<span class="hljs-keyword">self</span>.arenas); +<span class="hljs-keyword">return</span> <span class="hljs-title function_ invoke__">Some</span>(LexicalScopeBinding::<span class="hljs-title function_ invoke__">Item</span>(binding)); } } -None +<span class="hljs-literal">None</span> }</code></pre> <p> @@ -226,12 +226,12 @@ None 動作がわかったところで、例として次のコードを考える。 </p> - <pre class="highlight" language="rust" linenumbering="unnumbered"><code>#![allow(non_camel_case_types)] + <pre class="highlight" language="rust" linenumbering="unnumbered"><code class="highlight"><span class="hljs-meta">#![allow(non_camel_case_types)]</span> -struct bool; +<span class="hljs-keyword">struct</span> <span class="hljs-title class_">bool</span>; -fn main() { -let _: bool = bool; +<span class="hljs-keyword">fn</span> <span class="hljs-title function_">main</span>() { +<span class="hljs-keyword">let</span> <span class="hljs-variable">_</span>: <span class="hljs-type">bool</span> = <span class="hljs-type">bool</span>; }</code></pre> <p> diff --git a/public/posts/2021-10-02/vim-difference-between-autocmd-bufwrite-and-bufwritepre/index.html b/public/posts/2021-10-02/vim-difference-between-autocmd-bufwrite-and-bufwritepre/index.html index 049afdc..f45df6b 100644 --- a/public/posts/2021-10-02/vim-difference-between-autocmd-bufwrite-and-bufwritepre/index.html +++ b/public/posts/2021-10-02/vim-difference-between-autocmd-bufwrite-and-bufwritepre/index.html @@ -10,7 +10,7 @@ <link rel="icon" type="image/svg+xml" href="/favicon.svg"> <title>【Vim】 autocmd events の BufWrite/BufWritePre の違い | REPL: Rest-Eat-Program Loop</title> <link rel="stylesheet" href="/style.css?h=17cf97a767ec5fb6e64967729f40f30a"> - <link rel="stylesheet" href="/hl.css?h=208c52e3b7c9db1cad782c5d30b4698f"> + <link rel="stylesheet" href="/hl.css?h=340e65ffd5c17713efc9107c06304f7b"> </head> <body class="single"> <header class="header"> @@ -122,24 +122,24 @@ <a href="https://github.com/vim/vim/blob/8e6be34338f13a6a625f19bcef82019c9adc65f2/src/autocmd.c#L85-L86">https://github.com/vim/vim/blob/8e6be34338f13a6a625f19bcef82019c9adc65f2/src/autocmd.c#L85-L86</a> </p> - <pre class="highlight" language="c" linenumbering="unnumbered"><code> {"BufAdd", EVENT_BUFADD}, -{"BufCreate", EVENT_BUFADD},</code></pre> + <pre class="highlight" language="c" linenumbering="unnumbered"><code class="highlight"> {<span class="hljs-string">"BufAdd"</span>, EVENT_BUFADD}, +{<span class="hljs-string">"BufCreate"</span>, EVENT_BUFADD},</code></pre> <p> <a href="https://github.com/vim/vim/blob/8e6be34338f13a6a625f19bcef82019c9adc65f2/src/autocmd.c#L95-L97">https://github.com/vim/vim/blob/8e6be34338f13a6a625f19bcef82019c9adc65f2/src/autocmd.c#L95-L97</a> </p> - <pre class="highlight" language="c" linenumbering="unnumbered"><code> {"BufRead", EVENT_BUFREADPOST}, -{"BufReadCmd", EVENT_BUFREADCMD}, -{"BufReadPost", EVENT_BUFREADPOST},</code></pre> + <pre class="highlight" language="c" linenumbering="unnumbered"><code class="highlight"> {<span class="hljs-string">"BufRead"</span>, EVENT_BUFREADPOST}, +{<span class="hljs-string">"BufReadCmd"</span>, EVENT_BUFREADCMD}, +{<span class="hljs-string">"BufReadPost"</span>, EVENT_BUFREADPOST},</code></pre> <p> <a href="https://github.com/vim/vim/blob/8e6be34338f13a6a625f19bcef82019c9adc65f2/src/autocmd.c#L103-L105">https://github.com/vim/vim/blob/8e6be34338f13a6a625f19bcef82019c9adc65f2/src/autocmd.c#L103-L105</a> </p> - <pre class="highlight" language="c" linenumbering="unnumbered"><code> {"BufWrite", EVENT_BUFWRITEPRE}, -{"BufWritePost", EVENT_BUFWRITEPOST}, -{"BufWritePre", EVENT_BUFWRITEPRE},</code></pre> + <pre class="highlight" language="c" linenumbering="unnumbered"><code class="highlight"> {<span class="hljs-string">"BufWrite"</span>, EVENT_BUFWRITEPRE}, +{<span class="hljs-string">"BufWritePost"</span>, EVENT_BUFWRITEPOST}, +{<span class="hljs-string">"BufWritePre"</span>, EVENT_BUFWRITEPRE},</code></pre> </section> <section id="section--_neovim_のソースコード"> @@ -152,11 +152,11 @@ <a href="https://github.com/neovim/neovim/blob/71d4f5851f068eeb432af34850dddda8cc1c71e3/src/nvim/auevents.lua#L119-L124">https://github.com/neovim/neovim/blob/71d4f5851f068eeb432af34850dddda8cc1c71e3/src/nvim/auevents.lua#L119-L124</a> </p> - <pre class="highlight" language="lua" linenumbering="unnumbered"><code> aliases = { -BufCreate = 'BufAdd', -BufRead = 'BufReadPost', -BufWrite = 'BufWritePre', -FileEncoding = 'EncodingChanged', + <pre class="highlight" language="lua" linenumbering="unnumbered"><code class="highlight"> aliases = { +BufCreate = <span class="hljs-string">'BufAdd'</span>, +BufRead = <span class="hljs-string">'BufReadPost'</span>, +BufWrite = <span class="hljs-string">'BufWritePre'</span>, +FileEncoding = <span class="hljs-string">'EncodingChanged'</span>, },</code></pre> <p> diff --git a/public/posts/2021-10-02/vim-swap-order-of-selected-lines/index.html b/public/posts/2021-10-02/vim-swap-order-of-selected-lines/index.html index 366912c..8dbea05 100644 --- a/public/posts/2021-10-02/vim-swap-order-of-selected-lines/index.html +++ b/public/posts/2021-10-02/vim-swap-order-of-selected-lines/index.html @@ -10,7 +10,7 @@ <link rel="icon" type="image/svg+xml" href="/favicon.svg"> <title>Vimで選択した行の順番を入れ替える | REPL: Rest-Eat-Program Loop</title> <link rel="stylesheet" href="/style.css?h=17cf97a767ec5fb6e64967729f40f30a"> - <link rel="stylesheet" href="/hl.css?h=208c52e3b7c9db1cad782c5d30b4698f"> + <link rel="stylesheet" href="/hl.css?h=340e65ffd5c17713efc9107c06304f7b"> </head> <body class="single"> <header class="header"> @@ -125,7 +125,7 @@ なお、<code>:g/^/m0</code>は全ての行を入れ替えるが、<code>:N,Mg/^/mN-1</code>とすることで N行目から M行目を処理範囲とするよう拡張できる。手でこれを入力するわけにはいかないので、次のようなコマンドを用意する。 </p> - <pre class="highlight" language="vim" linenumbering="unnumbered"><code>command! -bar -range=% + <pre class="highlight" language="vim" linenumbering="unnumbered"><code class="highlight">command! -bar -range=% \ Reverse \ <line1>,<line2>g/^/m<line1>-1</code></pre> @@ -160,7 +160,7 @@ 前述した<code>:Reverse</code>コマンドの定義を少し変えて、次のようにする: </p> - <pre class="highlight" language="vim" linenumbering="unnumbered"><code>function! s:reverse_lines(from, to) abort + <pre class="highlight" language="vim" linenumbering="unnumbered"><code class="highlight">function! s:reverse_lines(from, to) abort execute printf("%d,%dg/^/m%d", a:from, a:to, a:from - 1) endfunction @@ -217,7 +217,7 @@ </p> </blockquote> - <pre class="highlight" language="vim" linenumbering="unnumbered"><code>command! -bar -range=% + <pre class="highlight" language="vim" linenumbering="unnumbered"><code class="highlight">command! -bar -range=% \ Reverse \ keeppatterns <line1>,<line2>g/^/m<line1>-1</code></pre> @@ -234,7 +234,7 @@ <section id="section--_コピペ用再掲"> <h2><a href="#section--_コピペ用再掲">コピペ用再掲</a></h2> - <pre class="highlight" language="vim" linenumbering="unnumbered"><code>" License: Public Domain + <pre class="highlight" language="vim" linenumbering="unnumbered"><code class="highlight">" License: Public Domain command! -bar -range=% \ Reverse diff --git a/public/posts/2022-04-09/phperkaigi-2022-tokens/index.html b/public/posts/2022-04-09/phperkaigi-2022-tokens/index.html index 9ac3f90..25873b7 100644 --- a/public/posts/2022-04-09/phperkaigi-2022-tokens/index.html +++ b/public/posts/2022-04-09/phperkaigi-2022-tokens/index.html @@ -10,7 +10,7 @@ <link rel="icon" type="image/svg+xml" href="/favicon.svg"> <title>PHPerKaigi 2022 トークン問題の解説 | REPL: Rest-Eat-Program Loop</title> <link rel="stylesheet" href="/style.css?h=17cf97a767ec5fb6e64967729f40f30a"> - <link rel="stylesheet" href="/hl.css?h=208c52e3b7c9db1cad782c5d30b4698f"> + <link rel="stylesheet" href="/hl.css?h=340e65ffd5c17713efc9107c06304f7b"> </head> <body class="single"> <header class="header"> @@ -76,50 +76,50 @@ ソースコードはこちら。実行には PHP 8.1 以上が必要なので注意。 </p> - <pre class="highlight" language="php" linenumbering="unnumbered"><code><?php + <pre class="highlight" language="php" linenumbering="unnumbered"><code class="highlight"><span class="hljs-meta"><?php</span> - declare(strict_types=0O1); + <span class="hljs-keyword">declare</span>(strict_types=<span class="hljs-number">0O1</span>); - namespace Dgcircus\PHPerKaigi\Y2022; + <span class="hljs-keyword">namespace</span> <span class="hljs-title class_">Dgcircus</span>\<span class="hljs-title class_">PHPerKaigi</span>\<span class="hljs-title class_">Y2022</span>; - /** - * @todo + <span class="hljs-comment">/** + * <span class="hljs-doctag">@todo</span> * Run this program to acquire a PHPer token. - */ + */</span> - https://creativecommons.org/publicdomain/zero/1.0/ + https:<span class="hljs-comment">//creativecommons.org/publicdomain/zero/1.0/</span> - \error_reporting(~+!'We are hiring!'); + \<span class="hljs-title function_ invoke__">error_reporting</span>(~+!<span class="hljs-string">'We are hiring!'</span>); - $z = fn($f) => (fn($x) => $f(fn(...$xs) => $x($x)(...$xs)))(fn($x) => $f(fn(...$xs) => $x($x)(...$xs))); - $id = \spl_object_id(...); - $put = fn($c) => \printf('%c', $c); - $mm = fn($p, $n) => new \ArrayObject(\array_fill(+!![], $n, $p)); + <span class="hljs-variable">$z</span> = <span class="hljs-function"><span class="hljs-keyword">fn</span>(<span class="hljs-params"><span class="hljs-variable">$f</span></span>) =></span> (<span class="hljs-function"><span class="hljs-keyword">fn</span>(<span class="hljs-params"><span class="hljs-variable">$x</span></span>) =></span> <span class="hljs-variable">$f</span>(<span class="hljs-function"><span class="hljs-keyword">fn</span>(<span class="hljs-params">...<span class="hljs-variable">$xs</span></span>) =></span> <span class="hljs-variable">$x</span>(<span class="hljs-variable">$x</span>)(...<span class="hljs-variable">$xs</span>)))(<span class="hljs-function"><span class="hljs-keyword">fn</span>(<span class="hljs-params"><span class="hljs-variable">$x</span></span>) =></span> <span class="hljs-variable">$f</span>(<span class="hljs-function"><span class="hljs-keyword">fn</span>(<span class="hljs-params">...<span class="hljs-variable">$xs</span></span>) =></span> <span class="hljs-variable">$x</span>(<span class="hljs-variable">$x</span>)(...<span class="hljs-variable">$xs</span>))); + <span class="hljs-variable">$id</span> = \<span class="hljs-title function_ invoke__">spl_object_id</span>(...); + <span class="hljs-variable">$put</span> = <span class="hljs-function"><span class="hljs-keyword">fn</span>(<span class="hljs-params"><span class="hljs-variable">$c</span></span>) =></span> \<span class="hljs-title function_ invoke__">printf</span>(<span class="hljs-string">'%c'</span>, <span class="hljs-variable">$c</span>); + <span class="hljs-variable">$mm</span> = <span class="hljs-function"><span class="hljs-keyword">fn</span>(<span class="hljs-params"><span class="hljs-variable">$p</span>, <span class="hljs-variable">$n</span></span>) =></span> <span class="hljs-keyword">new</span> <span class="hljs-title class_">\ArrayObject</span>(\<span class="hljs-title function_ invoke__">array_fill</span>(+!![], <span class="hljs-variable">$n</span>, <span class="hljs-variable">$p</span>)); - $👉 = fn($m, $p, $b, $e, $mp, $pc) => [++$mp, ++$pc]; - $👈 = fn($m, $p, $b, $e, $mp, $pc) => [--$mp, ++$pc]; - $👍 = fn($m, $p, $b, $e, $mp, $pc) => [$mp, ++$pc, ++$m[$mp]]; - $👎 = fn($m, $p, $b, $e, $mp, $pc) => [$mp, ++$pc, --$m[$mp]]; - $📝 = fn($m, $p, $b, $e, $mp, $pc) => [$mp, ++$pc, $put($m[$mp])]; - $🤡 = fn($m, $p, $b, $e, $mp, $pc) => match ($m[$mp]) { - +!![] => [$mp, $z(fn($loop) => fn($pc, $n) => match ($id($p[$pc])) { - $b => $loop(++$pc, ++$n), - $e => $n === +!![] ? ++$pc : $loop(++$pc, --$n), - default => $loop(++$pc, $n), - })($pc, -![])], - default => [$mp, ++$pc], + $👉 = <span class="hljs-function"><span class="hljs-keyword">fn</span>(<span class="hljs-params"><span class="hljs-variable">$m</span>, <span class="hljs-variable">$p</span>, <span class="hljs-variable">$b</span>, <span class="hljs-variable">$e</span>, <span class="hljs-variable">$mp</span>, <span class="hljs-variable">$pc</span></span>) =></span> [++<span class="hljs-variable">$mp</span>, ++<span class="hljs-variable">$pc</span>]; + $👈 = <span class="hljs-function"><span class="hljs-keyword">fn</span>(<span class="hljs-params"><span class="hljs-variable">$m</span>, <span class="hljs-variable">$p</span>, <span class="hljs-variable">$b</span>, <span class="hljs-variable">$e</span>, <span class="hljs-variable">$mp</span>, <span class="hljs-variable">$pc</span></span>) =></span> [--<span class="hljs-variable">$mp</span>, ++<span class="hljs-variable">$pc</span>]; + $👍 = <span class="hljs-function"><span class="hljs-keyword">fn</span>(<span class="hljs-params"><span class="hljs-variable">$m</span>, <span class="hljs-variable">$p</span>, <span class="hljs-variable">$b</span>, <span class="hljs-variable">$e</span>, <span class="hljs-variable">$mp</span>, <span class="hljs-variable">$pc</span></span>) =></span> [<span class="hljs-variable">$mp</span>, ++<span class="hljs-variable">$pc</span>, ++<span class="hljs-variable">$m</span>[<span class="hljs-variable">$mp</span>]]; + $👎 = <span class="hljs-function"><span class="hljs-keyword">fn</span>(<span class="hljs-params"><span class="hljs-variable">$m</span>, <span class="hljs-variable">$p</span>, <span class="hljs-variable">$b</span>, <span class="hljs-variable">$e</span>, <span class="hljs-variable">$mp</span>, <span class="hljs-variable">$pc</span></span>) =></span> [<span class="hljs-variable">$mp</span>, ++<span class="hljs-variable">$pc</span>, --<span class="hljs-variable">$m</span>[<span class="hljs-variable">$mp</span>]]; + $📝 = <span class="hljs-function"><span class="hljs-keyword">fn</span>(<span class="hljs-params"><span class="hljs-variable">$m</span>, <span class="hljs-variable">$p</span>, <span class="hljs-variable">$b</span>, <span class="hljs-variable">$e</span>, <span class="hljs-variable">$mp</span>, <span class="hljs-variable">$pc</span></span>) =></span> [<span class="hljs-variable">$mp</span>, ++<span class="hljs-variable">$pc</span>, <span class="hljs-variable">$put</span>(<span class="hljs-variable">$m</span>[<span class="hljs-variable">$mp</span>])]; + $🤡 = <span class="hljs-function"><span class="hljs-keyword">fn</span>(<span class="hljs-params"><span class="hljs-variable">$m</span>, <span class="hljs-variable">$p</span>, <span class="hljs-variable">$b</span>, <span class="hljs-variable">$e</span>, <span class="hljs-variable">$mp</span>, <span class="hljs-variable">$pc</span></span>) =></span> <span class="hljs-keyword">match</span> (<span class="hljs-variable">$m</span>[<span class="hljs-variable">$mp</span>]) { + +!![] => [<span class="hljs-variable">$mp</span>, <span class="hljs-variable">$z</span>(<span class="hljs-function"><span class="hljs-keyword">fn</span>(<span class="hljs-params"><span class="hljs-variable">$loop</span></span>) =></span> <span class="hljs-function"><span class="hljs-keyword">fn</span>(<span class="hljs-params"><span class="hljs-variable">$pc</span>, <span class="hljs-variable">$n</span></span>) =></span> <span class="hljs-keyword">match</span> (<span class="hljs-variable">$id</span>(<span class="hljs-variable">$p</span>[<span class="hljs-variable">$pc</span>])) { + <span class="hljs-variable">$b</span> => <span class="hljs-variable">$loop</span>(++<span class="hljs-variable">$pc</span>, ++<span class="hljs-variable">$n</span>), + <span class="hljs-variable">$e</span> => <span class="hljs-variable">$n</span> === +!![] ? ++<span class="hljs-variable">$pc</span> : <span class="hljs-variable">$loop</span>(++<span class="hljs-variable">$pc</span>, --<span class="hljs-variable">$n</span>), + <span class="hljs-keyword">default</span> => <span class="hljs-variable">$loop</span>(++<span class="hljs-variable">$pc</span>, <span class="hljs-variable">$n</span>), + })(<span class="hljs-variable">$pc</span>, -![])], + <span class="hljs-keyword">default</span> => [<span class="hljs-variable">$mp</span>, ++<span class="hljs-variable">$pc</span>], }; - $🎪 = fn($m, $p, $b, $e, $mp, $pc) => match ($m[$mp]) { - +!![] => [$mp, ++$pc], - default => [$mp, $z(fn($loop) => fn($pc, $n) => match ($id($p[$pc])) { - $e => $loop(--$pc, ++$n), - $b => $n === +!![] ? $pc+![] : $loop(--$pc, --$n), - default => $loop(--$pc, $n), - })($pc, -![])], + $🎪 = <span class="hljs-function"><span class="hljs-keyword">fn</span>(<span class="hljs-params"><span class="hljs-variable">$m</span>, <span class="hljs-variable">$p</span>, <span class="hljs-variable">$b</span>, <span class="hljs-variable">$e</span>, <span class="hljs-variable">$mp</span>, <span class="hljs-variable">$pc</span></span>) =></span> <span class="hljs-keyword">match</span> (<span class="hljs-variable">$m</span>[<span class="hljs-variable">$mp</span>]) { + +!![] => [<span class="hljs-variable">$mp</span>, ++<span class="hljs-variable">$pc</span>], + <span class="hljs-keyword">default</span> => [<span class="hljs-variable">$mp</span>, <span class="hljs-variable">$z</span>(<span class="hljs-function"><span class="hljs-keyword">fn</span>(<span class="hljs-params"><span class="hljs-variable">$loop</span></span>) =></span> <span class="hljs-function"><span class="hljs-keyword">fn</span>(<span class="hljs-params"><span class="hljs-variable">$pc</span>, <span class="hljs-variable">$n</span></span>) =></span> <span class="hljs-keyword">match</span> (<span class="hljs-variable">$id</span>(<span class="hljs-variable">$p</span>[<span class="hljs-variable">$pc</span>])) { + <span class="hljs-variable">$e</span> => <span class="hljs-variable">$loop</span>(--<span class="hljs-variable">$pc</span>, ++<span class="hljs-variable">$n</span>), + <span class="hljs-variable">$b</span> => <span class="hljs-variable">$n</span> === +!![] ? <span class="hljs-variable">$pc</span>+![] : <span class="hljs-variable">$loop</span>(--<span class="hljs-variable">$pc</span>, --<span class="hljs-variable">$n</span>), + <span class="hljs-keyword">default</span> => <span class="hljs-variable">$loop</span>(--<span class="hljs-variable">$pc</span>, <span class="hljs-variable">$n</span>), + })(<span class="hljs-variable">$pc</span>, -![])], }; - $🐘 = fn($p) => $z(fn($loop) => fn($m, $p, $b, $e, $mp, $pc) => - isset($p[$pc]) && $loop($m, $p, $b, $e, ...($p[$pc]($m, $p, $b, $e, $mp, $pc))) - )($mm(+!![], +(![].![])), $p, $id($🤡), $id($🎪), +!![], +!![]); + $🐘 = <span class="hljs-function"><span class="hljs-keyword">fn</span>(<span class="hljs-params"><span class="hljs-variable">$p</span></span>) =></span> <span class="hljs-variable">$z</span>(<span class="hljs-function"><span class="hljs-keyword">fn</span>(<span class="hljs-params"><span class="hljs-variable">$loop</span></span>) =></span> <span class="hljs-function"><span class="hljs-keyword">fn</span>(<span class="hljs-params"><span class="hljs-variable">$m</span>, <span class="hljs-variable">$p</span>, <span class="hljs-variable">$b</span>, <span class="hljs-variable">$e</span>, <span class="hljs-variable">$mp</span>, <span class="hljs-variable">$pc</span></span>) =></span> + <span class="hljs-keyword">isset</span>(<span class="hljs-variable">$p</span>[<span class="hljs-variable">$pc</span>]) && <span class="hljs-variable">$loop</span>(<span class="hljs-variable">$m</span>, <span class="hljs-variable">$p</span>, <span class="hljs-variable">$b</span>, <span class="hljs-variable">$e</span>, ...(<span class="hljs-variable">$p</span>[<span class="hljs-variable">$pc</span>](<span class="hljs-variable">$m</span>, <span class="hljs-variable">$p</span>, <span class="hljs-variable">$b</span>, <span class="hljs-variable">$e</span>, <span class="hljs-variable">$mp</span>, <span class="hljs-variable">$pc</span>))) + )(<span class="hljs-variable">$mm</span>(+!![], +(![].![])), <span class="hljs-variable">$p</span>, <span class="hljs-variable">$id</span>($🤡), <span class="hljs-variable">$id</span>($🎪), +!![], +!![]); $🐘([ $👍, $👍, $👍, $👍, $👍, $👍, $👍, $👍, $👍, $👍, @@ -175,26 +175,26 @@ <pre class="monospaced highlight"><code>+ + + + + + + + + + [ -> + + + -> + + + + + -> + + + + + + + + + + + + -> + + + + + + + + + + -< < < < - +> + + + +> + + + + + +> + + + + + + + + + + + + +> + + + + + + + + + + +< < < < - ] -> + + + + + . +> + + + + + . - - . -> - - - . -> - - - . +> - - - . +> - - - . - - . - . -< . -> > - - . +< . +> > - - . + + + + + + + . -< - - - - . -< . -> + + . -> - . -< .</code></pre> +< - - - - . +< . +> + + . +> - . +< .</code></pre> <p> 実行結果はこちら:<a href="https://ideone.com/22VWmb">https://ideone.com/22VWmb</a> @@ -277,7 +277,7 @@ ソースコードのライセンスを示したこの部分だが、 </p> - <pre class="highlight" language="php" linenumbering="unnumbered"><code>https://creativecommons.org/publicdomain/zero/1.0/</code></pre> + <pre class="highlight" language="php" linenumbering="unnumbered"><code class="highlight">https:<span class="hljs-comment">//creativecommons.org/publicdomain/zero/1.0/</span></code></pre> <p> 完全に合法な PHP のコードである。<code>https:</code>部分はラベル、<code>//</code>以降は行コメントになっている。 @@ -290,11 +290,11 @@ ソースコード中に、ほとんど数値リテラルが書かれていないことにお気づきだろうか。 PHP では、型変換を利用することで任意の整数を作り出すことができる。 </p> - <pre class="highlight" language="php" linenumbering="unnumbered"><code>assert(0 === +!![]); -assert(1 === +![]); -assert(2 === ![]+![]); -assert(3 === ![]+![]+![]); -assert(10 === +(![].+!![]));</code></pre> + <pre class="highlight" language="php" linenumbering="unnumbered"><code class="highlight"><span class="hljs-title function_ invoke__">assert</span>(<span class="hljs-number">0</span> === +!![]); +<span class="hljs-title function_ invoke__">assert</span>(<span class="hljs-number">1</span> === +![]); +<span class="hljs-title function_ invoke__">assert</span>(<span class="hljs-number">2</span> === ![]+![]); +<span class="hljs-title function_ invoke__">assert</span>(<span class="hljs-number">3</span> === ![]+![]+![]); +<span class="hljs-title function_ invoke__">assert</span>(<span class="hljs-number">10</span> === +(![].+!![]));</code></pre> <p> <code>[]</code>に<code>!</code>を適用すると<code>true</code>が返ってくる。それに<code>+</code>を適用すると、<code>bool</code>から<code>int</code>ヘの型変換が走り、<code>1</code>が生成される。<code>10</code>はさらにトリッキーだ。まず<code>1</code>と<code>0</code>を作り、<code>.</code>で文字列として結合する (<code>'10'</code>)。これに<code>+</code>を適用すると、<code>string</code>から<code>int</code>への型変換が走り、<code>10</code>が生まれる (コード量に頓着しないなら、<code>1</code>を 10 個足し合わせてももちろん 10 が作れる)。 @@ -335,11 +335,11 @@ assert(10 === +(![].+!![]));</code></pre> ソースコードはこちら。実行には PHP 8.0 以上が必要なので注意。 </p> - <pre class="highlight" language="php" linenumbering="unnumbered"><code><?php + <pre class="highlight" language="php" linenumbering="unnumbered"><code class="highlight"><span class="hljs-meta"><?php</span> - /********************************************************* + <span class="hljs-comment">/********************************************************* * This program displays a PHPer token. * - * Guess 'N'. * + * Guess 'N'. * * * * Hints: * * - N itself has no special meaning, e.g., 42, 8128, * @@ -350,24 +350,24 @@ assert(10 === +(![].+!![]));</code></pre> * * * License: * * https://creativecommons.org/publicdomain/zero/1.0/ * - *********************************************************/ - const N = 0 /* Change it to your answer. */; - assert(0 <= N && N <= 0b11111_11111_11111_11111_11111); + *********************************************************/</span> + <span class="hljs-keyword">const</span> <span class="hljs-variable constant_">N</span> = <span class="hljs-number">0</span> <span class="hljs-comment">/* Change it to your answer. */</span>; + <span class="hljs-title function_ invoke__">assert</span>(<span class="hljs-number">0</span> <= N && N <= <span class="hljs-number">0b11111_11111_11111_11111_11111</span>); - $token = [ - 0x14B499C, - 0x0BE34CC, 0x01C9C69, - 0x0ECA069, 0x01C2449, 0x0FDB166, 0x01C9C69, - 0x01C1C66, 0x0FC1C47, 0x01C1C66, - 0x10C5858, 0x1E4E3B8, 0x1A2F2F8, + <span class="hljs-variable">$token</span> = [ + <span class="hljs-number">0x14B499C</span>, + <span class="hljs-number">0x0BE34CC</span>, <span class="hljs-number">0x01C9C69</span>, + <span class="hljs-number">0x0ECA069</span>, <span class="hljs-number">0x01C2449</span>, <span class="hljs-number">0x0FDB166</span>, <span class="hljs-number">0x01C9C69</span>, + <span class="hljs-number">0x01C1C66</span>, <span class="hljs-number">0x0FC1C47</span>, <span class="hljs-number">0x01C1C66</span>, + <span class="hljs-number">0x10C5858</span>, <span class="hljs-number">0x1E4E3B8</span>, <span class="hljs-number">0x1A2F2F8</span>, ]; - foreach ($token as $x) { - $x = $x ^ N; + <span class="hljs-keyword">foreach</span> (<span class="hljs-variable">$token</span> <span class="hljs-keyword">as</span> <span class="hljs-variable">$x</span>) { + <span class="hljs-variable">$x</span> = <span class="hljs-variable">$x</span> ^ N; - $x = sprintf('%025b', $x); - $x = str_replace(search: ['0', '1'], replace: [' ', '#'], subject: $x); - $x = implode("\n", str_split($x, length: 5)); - echo "{$x}\n\n"; + <span class="hljs-variable">$x</span> = <span class="hljs-title function_ invoke__">sprintf</span>(<span class="hljs-string">'%025b'</span>, <span class="hljs-variable">$x</span>); + <span class="hljs-variable">$x</span> = <span class="hljs-title function_ invoke__">str_replace</span>(<span class="hljs-attr">search</span>: [<span class="hljs-string">'0'</span>, <span class="hljs-string">'1'</span>], <span class="hljs-attr">replace</span>: [<span class="hljs-string">' '</span>, <span class="hljs-string">'#'</span>], <span class="hljs-attr">subject</span>: <span class="hljs-variable">$x</span>); + <span class="hljs-variable">$x</span> = <span class="hljs-title function_ invoke__">implode</span>(<span class="hljs-string">"\n"</span>, <span class="hljs-title function_ invoke__">str_split</span>(<span class="hljs-variable">$x</span>, <span class="hljs-attr">length</span>: <span class="hljs-number">5</span>)); + <span class="hljs-keyword">echo</span> <span class="hljs-string">"<span class="hljs-subst">{$x}</span>\n\n"</span>; }</code></pre> <p> @@ -384,33 +384,33 @@ assert(10 === +(![].+!![]));</code></pre> まずはソースコードを読んでいく。 </p> - <pre class="highlight" language="php" linenumbering="unnumbered"><code>$token = [ - // 略 + <pre class="highlight" language="php" linenumbering="unnumbered"><code class="highlight"><span class="hljs-variable">$token</span> = [ + <span class="hljs-comment">// 略</span> ];</code></pre> <p> 数値からなる<code>$token</code>があり、各要素をループしている。 </p> - <pre class="highlight" language="php" linenumbering="unnumbered"><code> $x = $x ^ N;</code></pre> + <pre class="highlight" language="php" linenumbering="unnumbered"><code class="highlight"> <span class="hljs-variable">$x</span> = <span class="hljs-variable">$x</span> ^ N;</code></pre> <p> まずは排他的論理和 (xor) を取り、 </p> - <pre class="highlight" language="php" linenumbering="unnumbered"><code> $x = sprintf('%025b', $x);</code></pre> + <pre class="highlight" language="php" linenumbering="unnumbered"><code class="highlight"> <span class="hljs-variable">$x</span> = <span class="hljs-title function_ invoke__">sprintf</span>(<span class="hljs-string">'%025b'</span>, <span class="hljs-variable">$x</span>);</code></pre> <p> 二進数に変換して、 </p> - <pre class="highlight" language="php" linenumbering="unnumbered"><code> $x = str_replace(search: ['0', '1'], replace: [' ', '#'], subject: $x);</code></pre> + <pre class="highlight" language="php" linenumbering="unnumbered"><code class="highlight"> <span class="hljs-variable">$x</span> = <span class="hljs-title function_ invoke__">str_replace</span>(<span class="hljs-attr">search</span>: [<span class="hljs-string">'0'</span>, <span class="hljs-string">'1'</span>], <span class="hljs-attr">replace</span>: [<span class="hljs-string">' '</span>, <span class="hljs-string">'#'</span>], <span class="hljs-attr">subject</span>: <span class="hljs-variable">$x</span>);</code></pre> <p> 0 を空白に、1 を<code>#</code>にし、 </p> - <pre class="highlight" language="php" linenumbering="unnumbered"><code> $x = implode("\n", str_split($x, length: 5));</code></pre> + <pre class="highlight" language="php" linenumbering="unnumbered"><code class="highlight"> <span class="hljs-variable">$x</span> = <span class="hljs-title function_ invoke__">implode</span>(<span class="hljs-string">"\n"</span>, <span class="hljs-title function_ invoke__">str_split</span>(<span class="hljs-variable">$x</span>, <span class="hljs-attr">length</span>: <span class="hljs-number">5</span>));</code></pre> <p> 5文字ごとに区切ったあと、改行で結合している。 @@ -464,49 +464,49 @@ assert(10 === +(![].+!![]));</code></pre> <code>N</code>は高々 </p> - <pre class="highlight" language="php" linenumbering="unnumbered"><code>assert(0 <= N && N <= 0b11111_11111_11111_11111_11111);</code></pre> + <pre class="highlight" language="php" linenumbering="unnumbered"><code class="highlight"><span class="hljs-title function_ invoke__">assert</span>(<span class="hljs-number">0</span> <= N && N <= <span class="hljs-number">0b11111_11111_11111_11111_11111</span>);</code></pre> <p> なのでブルートフォースしてもよいが、ここではブルートフォースしない方法を紹介する。 </p> - <pre class="highlight" language="php" linenumbering="unnumbered"><code><?php + <pre class="highlight" language="php" linenumbering="unnumbered"><code class="highlight"><span class="hljs-meta"><?php</span> - $x = 0x14B499C; + <span class="hljs-variable">$x</span> = <span class="hljs-number">0x14B499C</span>; - $x = $x ^ N; + <span class="hljs-variable">$x</span> = <span class="hljs-variable">$x</span> ^ N; - $x = sprintf('%025b', $x); - $x = str_replace(search: ['0', '1'], replace: [' ', '#'], subject: $x); - $x = implode("\n", str_split($x, length: 5)); + <span class="hljs-variable">$x</span> = <span class="hljs-title function_ invoke__">sprintf</span>(<span class="hljs-string">'%025b'</span>, <span class="hljs-variable">$x</span>); + <span class="hljs-variable">$x</span> = <span class="hljs-title function_ invoke__">str_replace</span>(<span class="hljs-attr">search</span>: [<span class="hljs-string">'0'</span>, <span class="hljs-string">'1'</span>], <span class="hljs-attr">replace</span>: [<span class="hljs-string">' '</span>, <span class="hljs-string">'#'</span>], <span class="hljs-attr">subject</span>: <span class="hljs-variable">$x</span>); + <span class="hljs-variable">$x</span> = <span class="hljs-title function_ invoke__">implode</span>(<span class="hljs-string">"\n"</span>, <span class="hljs-title function_ invoke__">str_split</span>(<span class="hljs-variable">$x</span>, <span class="hljs-attr">length</span>: <span class="hljs-number">5</span>)); - assert($x === - " # # \n" . - "#####\n" . - " # # \n" . - "#####\n" . - " # # ");</code></pre> + <span class="hljs-title function_ invoke__">assert</span>(<span class="hljs-variable">$x</span> === + <span class="hljs-string">" # # \n"</span> . + <span class="hljs-string">"#####\n"</span> . + <span class="hljs-string">" # # \n"</span> . + <span class="hljs-string">"#####\n"</span> . + <span class="hljs-string">" # # "</span>);</code></pre> <p> この一連の変換に対する逆変換を考えると、次のようになる。 </p> - <pre class="highlight" language="php" linenumbering="unnumbered"><code><?php + <pre class="highlight" language="php" linenumbering="unnumbered"><code class="highlight"><span class="hljs-meta"><?php</span> -$x = -" # # \n" . -"#####\n" . -" # # \n" . -"#####\n" . -" # # "; +<span class="hljs-variable">$x</span> = +<span class="hljs-string">" # # \n"</span> . +<span class="hljs-string">"#####\n"</span> . +<span class="hljs-string">" # # \n"</span> . +<span class="hljs-string">"#####\n"</span> . +<span class="hljs-string">" # # "</span>; -$x = implode('', explode("\n", $x)); -$x = str_replace(search: [' ', '#'], replace: ['0', '1'], subject: $x); -$x = bindec($x); +<span class="hljs-variable">$x</span> = <span class="hljs-title function_ invoke__">implode</span>(<span class="hljs-string">''</span>, <span class="hljs-title function_ invoke__">explode</span>(<span class="hljs-string">"\n"</span>, <span class="hljs-variable">$x</span>)); +<span class="hljs-variable">$x</span> = <span class="hljs-title function_ invoke__">str_replace</span>(<span class="hljs-attr">search</span>: [<span class="hljs-string">' '</span>, <span class="hljs-string">'#'</span>], <span class="hljs-attr">replace</span>: [<span class="hljs-string">'0'</span>, <span class="hljs-string">'1'</span>], <span class="hljs-attr">subject</span>: <span class="hljs-variable">$x</span>); +<span class="hljs-variable">$x</span> = <span class="hljs-title function_ invoke__">bindec</span>(<span class="hljs-variable">$x</span>); -$n = $x ^ 0x14B499C; +<span class="hljs-variable">$n</span> = <span class="hljs-variable">$x</span> ^ <span class="hljs-number">0x14B499C</span>; -echo "N = $n\n";</code></pre> +<span class="hljs-keyword">echo</span> <span class="hljs-string">"N = <span class="hljs-subst">$n</span>\n"</span>;</code></pre> <p> これを実行すると、<code>N</code>が得られる。 @@ -520,41 +520,41 @@ echo "N = $n\n";</code></pre> ソースコードはこちら。 </p> - <pre class="highlight" language="php" linenumbering="unnumbered"><code><?php + <pre class="highlight" language="php" linenumbering="unnumbered"><code class="highlight"><span class="hljs-meta"><?php</span> - // License: https://creativecommons.org/publicdomain/zero/1.0/ - // This is a quine-like program to generate a PHPer token. - // Execute it like this: php toquine.php | php | php | php | ... + <span class="hljs-comment">// License: https://creativecommons.org/publicdomain/zero/1.0/</span> + <span class="hljs-comment">// This is a quine-like program to generate a PHPer token.</span> + <span class="hljs-comment">// Execute it like this: php toquine.php | php | php | php | ...</span> - $s = <<<'Q' - <?cuc - // Yvprafr: uggcf://perngvirpbzzbaf.bet/choyvpqbznva/mreb/1.0/ - // Guvf vf n dhvar-yvxr cebtenz gb trarengr n CUCre gbxra. - // Rkrphgr vg yvxr guvf: cuc gbdhvar.cuc | cuc | cuc | cuc | ... - %f$f = %f; - $f = fge_ebg13($f); $kf = [ + <span class="hljs-variable">$s</span> = <<<<span class="hljs-string">'Q'</span> + <span class="hljs-meta"><?</span>cuc + <span class="hljs-comment">// Yvprafr: uggcf://perngvirpbzzbaf.bet/choyvpqbznva/mreb/1.0/</span> + <span class="hljs-comment">// Guvf vf n dhvar-yvxr cebtenz gb trarengr n CUCre gbxra.</span> + <span class="hljs-comment">// Rkrphgr vg yvxr guvf: cuc gbdhvar.cuc | cuc | cuc | cuc | ...</span> + %f<span class="hljs-variable">$f</span> = %f; + <span class="hljs-variable">$f</span> = <span class="hljs-title function_ invoke__">fge_ebg13</span>(<span class="hljs-variable">$f</span>); <span class="hljs-variable">$kf</span> = [ %f, ]; - $g = ahyy.snyfr; sbe ($v = 0; $v <= vagqvi(__YVAR__-035,6); ++$v) vs (!vffrg($kf[$v])) oernx; ryfr - $g .= vzcybqr("\a", fge_fcyvg(fge_ercynpr(['0','1'], [' ','##'], fcevags(pue(37) . '025o', $kf[$v])), 012)) . "\a\a"; - $jf = neenl_znc(sa($j) => vzcybqr(', ', $j), neenl_puhax(neenl_znc(sa($k) => fcevags('0k' . pue(37) . '07K', $k), $kf), 10)); - cevags($f, $g, fge_ebg13("<<<'Q'\a{$f}\aQ"), vzcybqr(",\a", $jf)); + <span class="hljs-variable">$g</span> = ahyy.snyfr; <span class="hljs-title function_ invoke__">sbe</span> (<span class="hljs-variable">$v</span> = <span class="hljs-number">0</span>; <span class="hljs-variable">$v</span> <= <span class="hljs-title function_ invoke__">vagqvi</span>(__YVAR__-<span class="hljs-number">035</span>,<span class="hljs-number">6</span>); ++<span class="hljs-variable">$v</span>) <span class="hljs-title function_ invoke__">vs</span> (!<span class="hljs-title function_ invoke__">vffrg</span>(<span class="hljs-variable">$kf</span>[<span class="hljs-variable">$v</span>])) oernx; ryfr + <span class="hljs-variable">$g</span> .= <span class="hljs-title function_ invoke__">vzcybqr</span>(<span class="hljs-string">"\a"</span>, <span class="hljs-title function_ invoke__">fge_fcyvg</span>(<span class="hljs-title function_ invoke__">fge_ercynpr</span>([<span class="hljs-string">'0'</span>,<span class="hljs-string">'1'</span>], [<span class="hljs-string">' '</span>,<span class="hljs-string">'##'</span>], <span class="hljs-title function_ invoke__">fcevags</span>(<span class="hljs-title function_ invoke__">pue</span>(<span class="hljs-number">37</span>) . <span class="hljs-string">'025o'</span>, <span class="hljs-variable">$kf</span>[<span class="hljs-variable">$v</span>])), <span class="hljs-number">012</span>)) . <span class="hljs-string">"\a\a"</span>; + <span class="hljs-variable">$jf</span> = <span class="hljs-title function_ invoke__">neenl_znc</span>(<span class="hljs-title function_ invoke__">sa</span>(<span class="hljs-variable">$j</span>) => <span class="hljs-title function_ invoke__">vzcybqr</span>(<span class="hljs-string">', '</span>, <span class="hljs-variable">$j</span>), <span class="hljs-title function_ invoke__">neenl_puhax</span>(<span class="hljs-title function_ invoke__">neenl_znc</span>(<span class="hljs-title function_ invoke__">sa</span>(<span class="hljs-variable">$k</span>) => <span class="hljs-title function_ invoke__">fcevags</span>(<span class="hljs-string">'0k'</span> . <span class="hljs-title function_ invoke__">pue</span>(<span class="hljs-number">37</span>) . <span class="hljs-string">'07K'</span>, <span class="hljs-variable">$k</span>), <span class="hljs-variable">$kf</span>), <span class="hljs-number">10</span>)); + <span class="hljs-title function_ invoke__">cevags</span>(<span class="hljs-variable">$f</span>, <span class="hljs-variable">$g</span>, <span class="hljs-title function_ invoke__">fge_ebg13</span>(<span class="hljs-string">"<<<'Q'\a<span class="hljs-subst">{$f}</span>\aQ"</span>), <span class="hljs-title function_ invoke__">vzcybqr</span>(<span class="hljs-string">",\a"</span>, <span class="hljs-variable">$jf</span>)); Q; - $s = str_rot13($s); $xs = [ - 0x0AFABEA, 0x1F294A7, 0x1F2109F, 0x1F294A7, 0x0002800, 0x1F2109F, 0x0117041, 0x1F294A7, 0x1FAD6B5, 0x1F295B7, - 0x010FC21, 0x1FAD6B5, 0x1151151, 0x010FC21, 0x1F294A7, 0x1F295B7, 0x1FAD6B5, 0x1F294A7, 0x1F295B7, 0x1F8C63F, - 0x1F8C631, 0x1FAD6B5, 0x17AD6BD, 0x17AD6BD, 0x1F8C63F, 0x1F295B7, + <span class="hljs-variable">$s</span> = <span class="hljs-title function_ invoke__">str_rot13</span>(<span class="hljs-variable">$s</span>); <span class="hljs-variable">$xs</span> = [ + <span class="hljs-number">0x0AFABEA</span>, <span class="hljs-number">0x1F294A7</span>, <span class="hljs-number">0x1F2109F</span>, <span class="hljs-number">0x1F294A7</span>, <span class="hljs-number">0x0002800</span>, <span class="hljs-number">0x1F2109F</span>, <span class="hljs-number">0x0117041</span>, <span class="hljs-number">0x1F294A7</span>, <span class="hljs-number">0x1FAD6B5</span>, <span class="hljs-number">0x1F295B7</span>, + <span class="hljs-number">0x010FC21</span>, <span class="hljs-number">0x1FAD6B5</span>, <span class="hljs-number">0x1151151</span>, <span class="hljs-number">0x010FC21</span>, <span class="hljs-number">0x1F294A7</span>, <span class="hljs-number">0x1F295B7</span>, <span class="hljs-number">0x1FAD6B5</span>, <span class="hljs-number">0x1F294A7</span>, <span class="hljs-number">0x1F295B7</span>, <span class="hljs-number">0x1F8C63F</span>, + <span class="hljs-number">0x1F8C631</span>, <span class="hljs-number">0x1FAD6B5</span>, <span class="hljs-number">0x17AD6BD</span>, <span class="hljs-number">0x17AD6BD</span>, <span class="hljs-number">0x1F8C63F</span>, <span class="hljs-number">0x1F295B7</span>, ]; - $t = null.false; for ($i = 0; $i <= intdiv(__LINE__-035,6); ++$i) if (!isset($xs[$i])) break; else - $t .= implode("\n", str_split(str_replace(['0','1'], [' ','##'], sprintf(chr(37) . '025b', $xs[$i])), 012)) . "\n\n"; - $ws = array_map(fn($w) => implode(', ', $w), array_chunk(array_map(fn($x) => sprintf('0x' . chr(37) . '07X', $x), $xs), 10)); - printf($s, $t, str_rot13("<<<'D'\n{$s}\nD"), implode(",\n", $ws));</code></pre> + <span class="hljs-variable">$t</span> = <span class="hljs-literal">null</span>.<span class="hljs-literal">false</span>; <span class="hljs-keyword">for</span> (<span class="hljs-variable">$i</span> = <span class="hljs-number">0</span>; <span class="hljs-variable">$i</span> <= <span class="hljs-title function_ invoke__">intdiv</span>(<span class="hljs-keyword">__LINE__</span>-<span class="hljs-number">035</span>,<span class="hljs-number">6</span>); ++<span class="hljs-variable">$i</span>) <span class="hljs-keyword">if</span> (!<span class="hljs-keyword">isset</span>(<span class="hljs-variable">$xs</span>[<span class="hljs-variable">$i</span>])) <span class="hljs-keyword">break</span>; <span class="hljs-keyword">else</span> + <span class="hljs-variable">$t</span> .= <span class="hljs-title function_ invoke__">implode</span>(<span class="hljs-string">"\n"</span>, <span class="hljs-title function_ invoke__">str_split</span>(<span class="hljs-title function_ invoke__">str_replace</span>([<span class="hljs-string">'0'</span>,<span class="hljs-string">'1'</span>], [<span class="hljs-string">' '</span>,<span class="hljs-string">'##'</span>], <span class="hljs-title function_ invoke__">sprintf</span>(<span class="hljs-title function_ invoke__">chr</span>(<span class="hljs-number">37</span>) . <span class="hljs-string">'025b'</span>, <span class="hljs-variable">$xs</span>[<span class="hljs-variable">$i</span>])), <span class="hljs-number">012</span>)) . <span class="hljs-string">"\n\n"</span>; + <span class="hljs-variable">$ws</span> = <span class="hljs-title function_ invoke__">array_map</span>(fn(<span class="hljs-variable">$w</span>) => <span class="hljs-title function_ invoke__">implode</span>(<span class="hljs-string">', '</span>, <span class="hljs-variable">$w</span>), <span class="hljs-title function_ invoke__">array_chunk</span>(<span class="hljs-title function_ invoke__">array_map</span>(fn(<span class="hljs-variable">$x</span>) => <span class="hljs-title function_ invoke__">sprintf</span>(<span class="hljs-string">'0x'</span> . <span class="hljs-title function_ invoke__">chr</span>(<span class="hljs-number">37</span>) . <span class="hljs-string">'07X'</span>, <span class="hljs-variable">$x</span>), <span class="hljs-variable">$xs</span>), <span class="hljs-number">10</span>)); + <span class="hljs-title function_ invoke__">printf</span>(<span class="hljs-variable">$s</span>, <span class="hljs-variable">$t</span>, <span class="hljs-title function_ invoke__">str_rot13</span>(<span class="hljs-string">"<<<'D'\n<span class="hljs-subst">{$s}</span>\nD"</span>), <span class="hljs-title function_ invoke__">implode</span>(<span class="hljs-string">",\n"</span>, <span class="hljs-variable">$ws</span>));</code></pre> <p> コメントにもあるとおり、次のようにして実行すれば答えがでてくる。 </p> - <pre class="highlight" language="shell-session" linenumbering="unnumbered"><code>$ php toquine.php | php | php | php | ...</code></pre> + <pre class="highlight" language="shell-session" linenumbering="unnumbered"><code class="highlight">$ php toquine.php | php | php | php | ...</code></pre> <p> 実際にはもう少しパイプで繋げなければならない。 diff --git a/public/posts/2022-04-24/term-banner-write-tool-showing-banner-in-terminal/index.html b/public/posts/2022-04-24/term-banner-write-tool-showing-banner-in-terminal/index.html index eb55d81..8ae0fa6 100644 --- a/public/posts/2022-04-24/term-banner-write-tool-showing-banner-in-terminal/index.html +++ b/public/posts/2022-04-24/term-banner-write-tool-showing-banner-in-terminal/index.html @@ -9,7 +9,7 @@ <link rel="icon" type="image/svg+xml" href="/favicon.svg"> <title>term-banner: ターミナルにバナーを表示するツールを書いた | REPL: Rest-Eat-Program Loop</title> <link rel="stylesheet" href="/style.css?h=17cf97a767ec5fb6e64967729f40f30a"> - <link rel="stylesheet" href="/hl.css?h=208c52e3b7c9db1cad782c5d30b4698f"> + <link rel="stylesheet" href="/hl.css?h=340e65ffd5c17713efc9107c06304f7b"> </head> <body class="single"> <header class="header"> @@ -53,7 +53,7 @@ こんなものを作った。 </p> - <pre class="monospaced highlight"><code>$ term-banner 'Hello, World!' 'こんにちは、' '世界!'</code></pre> + <pre class="monospaced highlight"><code>$ term-banner 'Hello, World!' 'こんにちは、' '世界!'</code></pre> <p> image::https://raw.githubusercontent.com/nsfisis/term-banner/main/screenshot.png[term-banner のスクリーンショット] diff --git a/public/posts/2022-05-01/phperkaigi-2022/index.html b/public/posts/2022-05-01/phperkaigi-2022/index.html index ea9c581..a722db0 100644 --- a/public/posts/2022-05-01/phperkaigi-2022/index.html +++ b/public/posts/2022-05-01/phperkaigi-2022/index.html @@ -10,7 +10,7 @@ <link rel="icon" type="image/svg+xml" href="/favicon.svg"> <title>PHPerKaigi 2022 | REPL: Rest-Eat-Program Loop</title> <link rel="stylesheet" href="/style.css?h=17cf97a767ec5fb6e64967729f40f30a"> - <link rel="stylesheet" href="/hl.css?h=208c52e3b7c9db1cad782c5d30b4698f"> + <link rel="stylesheet" href="/hl.css?h=340e65ffd5c17713efc9107c06304f7b"> </head> <body class="single"> <header class="header"> diff --git a/public/posts/2022-08-27/php-conference-okinawa-code-golf/index.html b/public/posts/2022-08-27/php-conference-okinawa-code-golf/index.html index 851f76c..1e124bf 100644 --- a/public/posts/2022-08-27/php-conference-okinawa-code-golf/index.html +++ b/public/posts/2022-08-27/php-conference-okinawa-code-golf/index.html @@ -10,7 +10,7 @@ <link rel="icon" type="image/svg+xml" href="/favicon.svg"> <title>PHP カンファレンス沖縄で出題されたコードゴルフの問題を解いてみた | REPL: Rest-Eat-Program Loop</title> <link rel="stylesheet" href="/style.css?h=17cf97a767ec5fb6e64967729f40f30a"> - <link rel="stylesheet" href="/hl.css?h=208c52e3b7c9db1cad782c5d30b4698f"> + <link rel="stylesheet" href="/hl.css?h=340e65ffd5c17713efc9107c06304f7b"> </head> <body class="single"> <header class="header"> @@ -121,7 +121,7 @@ 書いたものがこちら: </p> - <pre class="highlight" language="php" linenumbering="unnumbered"><code>[<?php $n=$argv[1];foreach([1e4,5e3,2e3,1e3,500,100,50,10,5,1]as$x)for(;$n>=$x;$n-=$x)$r[]=$x;echo implode(', ',$r??[]);?>]</code></pre> + <pre class="highlight" language="php" linenumbering="unnumbered"><code class="highlight">[<span class="hljs-meta"><?php</span> <span class="hljs-variable">$n</span>=<span class="hljs-variable">$argv</span>[<span class="hljs-number">1</span>];<span class="hljs-keyword">foreach</span>([<span class="hljs-number">1e4</span>,<span class="hljs-number">5e3</span>,<span class="hljs-number">2e3</span>,<span class="hljs-number">1e3</span>,<span class="hljs-number">500</span>,<span class="hljs-number">100</span>,<span class="hljs-number">50</span>,<span class="hljs-number">10</span>,<span class="hljs-number">5</span>,<span class="hljs-number">1</span>]<span class="hljs-keyword">as</span><span class="hljs-variable">$x</span>)<span class="hljs-keyword">for</span>(;<span class="hljs-variable">$n</span>>=<span class="hljs-variable">$x</span>;<span class="hljs-variable">$n</span>-=<span class="hljs-variable">$x</span>)<span class="hljs-variable">$r</span>[]=<span class="hljs-variable">$x</span>;<span class="hljs-keyword">echo</span> <span class="hljs-title function_ invoke__">implode</span>(<span class="hljs-string">', '</span>,<span class="hljs-variable">$r</span>??[]);<span class="hljs-meta">?></span>]</code></pre> <p> しめて 123 バイトとなった (末尾改行を含めずにカウント)。 @@ -131,15 +131,15 @@ こちらは改行とスペースを追加したバージョン: </p> - <pre class="highlight" language="php" linenumbering="unnumbered"><code>[<?php + <pre class="highlight" language="php" linenumbering="unnumbered"><code class="highlight">[<span class="hljs-meta"><?php</span> - $n = $argv[1]; - foreach ([1e4, 5e3, 2e3, 1e3, 500, 100, 50, 10, 5, 1] as $x) - for (; $n >= $x; $n -= $x) - $r[] = $x; - echo implode(', ', $r ?? []); + <span class="hljs-variable">$n</span> = <span class="hljs-variable">$argv</span>[<span class="hljs-number">1</span>]; + <span class="hljs-keyword">foreach</span> ([<span class="hljs-number">1e4</span>, <span class="hljs-number">5e3</span>, <span class="hljs-number">2e3</span>, <span class="hljs-number">1e3</span>, <span class="hljs-number">500</span>, <span class="hljs-number">100</span>, <span class="hljs-number">50</span>, <span class="hljs-number">10</span>, <span class="hljs-number">5</span>, <span class="hljs-number">1</span>] <span class="hljs-keyword">as</span> <span class="hljs-variable">$x</span>) + <span class="hljs-keyword">for</span> (; <span class="hljs-variable">$n</span> >= <span class="hljs-variable">$x</span>; <span class="hljs-variable">$n</span> -= <span class="hljs-variable">$x</span>) + <span class="hljs-variable">$r</span>[] = <span class="hljs-variable">$x</span>; + <span class="hljs-keyword">echo</span> <span class="hljs-title function_ invoke__">implode</span>(<span class="hljs-string">', '</span>, <span class="hljs-variable">$r</span> ?? []); - ?>]</code></pre> + <span class="hljs-meta">?></span>]</code></pre> </section> <section id="section--_使用したテクニック"> diff --git a/public/posts/2022-08-31/support-for-communty-is-employee-benefits/index.html b/public/posts/2022-08-31/support-for-communty-is-employee-benefits/index.html index cc4f96e..a0e072b 100644 --- a/public/posts/2022-08-31/support-for-communty-is-employee-benefits/index.html +++ b/public/posts/2022-08-31/support-for-communty-is-employee-benefits/index.html @@ -9,7 +9,7 @@ <link rel="icon" type="image/svg+xml" href="/favicon.svg"> <title>弊社の PHP Foundation への寄付に寄せて | REPL: Rest-Eat-Program Loop</title> <link rel="stylesheet" href="/style.css?h=17cf97a767ec5fb6e64967729f40f30a"> - <link rel="stylesheet" href="/hl.css?h=208c52e3b7c9db1cad782c5d30b4698f"> + <link rel="stylesheet" href="/hl.css?h=340e65ffd5c17713efc9107c06304f7b"> </head> <body class="single"> <header class="header"> diff --git a/public/posts/2022-09-29/write-fizzbuzz-in-php-2-letters-per-line/index.html b/public/posts/2022-09-29/write-fizzbuzz-in-php-2-letters-per-line/index.html index b450a07..7546291 100644 --- a/public/posts/2022-09-29/write-fizzbuzz-in-php-2-letters-per-line/index.html +++ b/public/posts/2022-09-29/write-fizzbuzz-in-php-2-letters-per-line/index.html @@ -10,7 +10,7 @@ <link rel="icon" type="image/svg+xml" href="/favicon.svg"> <title>【PHP】 fizzbuzz を書く。1行あたり2文字で。 | REPL: Rest-Eat-Program Loop</title> <link rel="stylesheet" href="/style.css?h=17cf97a767ec5fb6e64967729f40f30a"> - <link rel="stylesheet" href="/hl.css?h=208c52e3b7c9db1cad782c5d30b4698f"> + <link rel="stylesheet" href="/hl.css?h=340e65ffd5c17713efc9107c06304f7b"> </head> <body class="single"> <header class="header"> @@ -135,7 +135,7 @@ 特に、C言語でこのような試みをおこなったことがあるかたならそう思うだろう。事実、Cでのこの制約はほとんど無意味に等しい。 </p> - <pre class="highlight" language="c" linenumbering="unnumbered"><code>#\ + <pre class="highlight" language="c" linenumbering="unnumbered"><code class="highlight">#\ i\ n\ c\ @@ -143,7 +143,7 @@ l\ u\ d\ e\ -<\ +&lt;\ s\ t\ d\ @@ -151,14 +151,14 @@ i\ o\ .\ h\ ->\ -/* -*/ +&gt;\ +<span class="hljs-comment">/* +*/</span> i\ n\ t\ -/* -*/ +<span class="hljs-comment">/* +*/</span> m\ a\ i\ @@ -170,30 +170,30 @@ r( i\ n\ t\ -/* -*/ +<span class="hljs-comment">/* +*/</span> i= -1; -i< -1\ -0\ -0; +<span class="hljs-number">1</span>; +i&lt; +<span class="hljs-number">1</span>\ +<span class="hljs-number">0</span>\ +<span class="hljs-number">0</span>; i\ +\ +) -if +<span class="hljs-keyword">if</span> (i %\ -15 +<span class="hljs-number">15</span> == -0) +<span class="hljs-number">0</span>) p\ r\ i\ n\ t\ f( -"\ +<span class="hljs-string">"\ F\ i\ z\ @@ -204,11 +204,11 @@ z\ z\ %\ c\ -", -10 +"</span>, +<span class="hljs-number">10</span> ); -/* あとは同じように普通のプログラムを変形するだけなので省略 */</code></pre> +<span class="hljs-comment">/* あとは同じように普通のプログラムを変形するだけなので省略 */</span></code></pre> <p> バックスラッシュを使った行継続がトークンを区切らない、というのがポイントだ。 @@ -268,9 +268,9 @@ c\ また、2文字だと文字列がまともに書けないのも辛い。<code>''</code>だけで 2文字使うので、「1文字の文字列リテラル」というものを書くことができない。PHP では文字列リテラル中に生の改行が書けるので </p> - <pre class="highlight" language="php" linenumbering="unnumbered"><code>$a -=' -a' + <pre class="highlight" language="php" linenumbering="unnumbered"><code class="highlight"><span class="hljs-variable">$a</span> +=<span class="hljs-string">' +a'</span> ;;</code></pre> <p> @@ -290,10 +290,10 @@ a' まずは普通に書くとしよう。 </p> - <pre class="highlight" language="php" linenumbering="unnumbered"><code><?php + <pre class="highlight" language="php" linenumbering="unnumbered"><code class="highlight">&lt;?php -for ($i = 1; $i < 100; $i++) { - echo (($i % 3 ? '' : 'Fizz') . ($i % 5 ? '' : 'Buzz') ?: $i) . "\n"; +<span class="hljs-keyword">for</span> (<span class="hljs-variable">$i</span> = <span class="hljs-number">1</span>; <span class="hljs-variable">$i</span> &lt; <span class="hljs-number">100</span>; <span class="hljs-variable">$i</span>++) { + <span class="hljs-keyword">echo</span> ((<span class="hljs-variable">$i</span> % <span class="hljs-number">3</span> ? <span class="hljs-string">''</span> : <span class="hljs-string">'Fizz'</span>) . (<span class="hljs-variable">$i</span> % <span class="hljs-number">5</span> ? <span class="hljs-string">''</span> : <span class="hljs-string">'Buzz'</span>) ?: <span class="hljs-variable">$i</span>) . <span class="hljs-string">"\n"</span>; }</code></pre> <p> @@ -307,13 +307,13 @@ for ($i = 1; $i < 100; $i++) { <code>for</code>は、3文字もある長いキーワードである。こんなものは使えない。<code>array_</code>系の関数を使って、適当に置き換えるとしよう。 </p> - <pre class="highlight" language="php" linenumbering="unnumbered"><code><?php + <pre class="highlight" language="php" linenumbering="unnumbered"><code class="highlight">&lt;?php -$s = range(1, 100); -array_walk( - $s, - fn($i) => - printf((($i % 3 ? '' : 'Fizz') . ($i % 5 ? '' : 'Buzz') ?: $i) . "\n"), +<span class="hljs-variable">$s</span> = <span class="hljs-title function_ invoke__">range</span>(<span class="hljs-number">1</span>, <span class="hljs-number">100</span>); +<span class="hljs-title function_ invoke__">array_walk</span>( + <span class="hljs-variable">$s</span>, + fn(<span class="hljs-variable">$i</span>) =&gt; + <span class="hljs-title function_ invoke__">printf</span>(((<span class="hljs-variable">$i</span> % <span class="hljs-number">3</span> ? <span class="hljs-string">''</span> : <span class="hljs-string">'Fizz'</span>) . (<span class="hljs-variable">$i</span> % <span class="hljs-number">5</span> ? <span class="hljs-string">''</span> : <span class="hljs-string">'Buzz'</span>) ?: <span class="hljs-variable">$i</span>) . <span class="hljs-string">"\n"</span>), );</code></pre> <p> @@ -327,17 +327,17 @@ array_walk( <code>range</code>、<code>array_walk</code>、<code>printf</code>は長すぎるのでどうにかせねばならない。ここで、PHP の可変関数を使う。可変関数とは、関数名が文字列として入った変数を経由して、関数を呼び出す機能である。 </p> - <pre class="highlight" language="php" linenumbering="unnumbered"><code><?php + <pre class="highlight" language="php" linenumbering="unnumbered"><code class="highlight">&lt;?php -$r = 'range'; -$w = 'array_walk'; -$p = 'printf'; +<span class="hljs-variable">$r</span> = <span class="hljs-string">'range'</span>; +<span class="hljs-variable">$w</span> = <span class="hljs-string">'array_walk'</span>; +<span class="hljs-variable">$p</span> = <span class="hljs-string">'printf'</span>; -$s = $r(1, 100); -$w( - $s, - fn($i) => - $p((($i % 3 ? '' : 'Fizz') . ($i % 5 ? '' : 'Buzz') ?: $i) . "\n"), +<span class="hljs-variable">$s</span> = <span class="hljs-variable">$r</span>(<span class="hljs-number">1</span>, <span class="hljs-number">100</span>); +<span class="hljs-variable">$w</span>( + <span class="hljs-variable">$s</span>, + <span class="hljs-function"><span class="hljs-keyword">fn</span>(<span class="hljs-params"><span class="hljs-variable">$i</span></span>) =&<span class="hljs-title">gt</span></span>; + <span class="hljs-variable">$p</span>(((<span class="hljs-variable">$i</span> % <span class="hljs-number">3</span> ? <span class="hljs-string">''</span> : <span class="hljs-string">'Fizz'</span>) . (<span class="hljs-variable">$i</span> % <span class="hljs-number">5</span> ? <span class="hljs-string">''</span> : <span class="hljs-string">'Buzz'</span>) ?: <span class="hljs-variable">$i</span>) . <span class="hljs-string">"\n"</span>), );</code></pre> <p> @@ -365,7 +365,7 @@ $w( というルールがない場合、「未定義の定数が評価された場合、その定数の名前が値になる」という PHP 7.x までの仕様が利用できる。例えば、<code>Fizz</code>という文字列が欲しければ、次のようにする。 </p> - <pre class="highlight" language="php" linenumbering="unnumbered"><code>$f + <pre class="highlight" language="php" linenumbering="unnumbered"><code class="highlight"><span class="hljs-variable">$f</span> =F .i .z @@ -376,13 +376,13 @@ $w( こうして簡単に文字列を作れる。なお、この仕様は 7.x 時点でも警告を受けるので、<code>@</code>演算子を使って抑制してやるとよい。 </p> - <pre class="highlight" language="php" linenumbering="unnumbered"><code>$f + <pre class="highlight" language="php" linenumbering="unnumbered"><code class="highlight"><span class="hljs-variable">$f</span> =@ F. @i -.# +.<span class="hljs-comment">#</span> @z -.# +.<span class="hljs-comment">#</span> @z ;;</code></pre> @@ -401,66 +401,66 @@ F. ずばり、文字列同士のビット演算を使う。PHP では、文字列同士でビット演算 (<code>&</code>、<code>|</code>、<code>^</code>) をした場合、文字列の各バイトごとに指定したビット演算がなされ、それを結合したものが演算結果となる。 </p> - <pre class="highlight" language="php" linenumbering="unnumbered"><code>$a = "12345"; -$b = "world"; + <pre class="highlight" language="php" linenumbering="unnumbered"><code class="highlight"><span class="hljs-variable">$a</span> = <span class="hljs-string">"12345"</span>; +<span class="hljs-variable">$b</span> = <span class="hljs-string">"world"</span>; -// $a ^ $b は次のコードと同じ -$result = ''; -for ($i = 0; $i < min(strlen($a), strlen($b)); $i++) { -$result .= $a[$i] ^ $b[$i]; +<span class="hljs-comment">// $a ^ $b は次のコードと同じ</span> +<span class="hljs-variable">$result</span> = <span class="hljs-string">''</span>; +<span class="hljs-keyword">for</span> (<span class="hljs-variable">$i</span> = <span class="hljs-number">0</span>; <span class="hljs-variable">$i</span> &lt; <span class="hljs-title function_ invoke__">min</span>(<span class="hljs-title function_ invoke__">strlen</span>(<span class="hljs-variable">$a</span>), <span class="hljs-title function_ invoke__">strlen</span>(<span class="hljs-variable">$b</span>)); <span class="hljs-variable">$i</span>++) { +<span class="hljs-variable">$result</span> .= <span class="hljs-variable">$a</span>[<span class="hljs-variable">$i</span>] ^ <span class="hljs-variable">$b</span>[<span class="hljs-variable">$i</span>]; } -echo $result; -// => F]AXQ</code></pre> +<span class="hljs-keyword">echo</span> <span class="hljs-variable">$result</span>; +<span class="hljs-comment">// =&gt; F]AXQ</span></code></pre> <p> これを踏まえ、次のコードを見てみよう。 </p> - <pre class="highlight" language="php" linenumbering="unnumbered"><code>$x = "x\nOm\n"; -$y = "\nk!\no"; -$r = $x ^ $y; -echo "$r\n";</code></pre> + <pre class="highlight" language="php" linenumbering="unnumbered"><code class="highlight"><span class="hljs-variable">$x</span> = <span class="hljs-string">"x\nOm\n"</span>; +<span class="hljs-variable">$y</span> = <span class="hljs-string">"\nk!\no"</span>; +<span class="hljs-variable">$r</span> = <span class="hljs-variable">$x</span> ^ <span class="hljs-variable">$y</span>; +<span class="hljs-keyword">echo</span> <span class="hljs-string">"<span class="hljs-subst">$r</span>\n"</span>;</code></pre> <p> 実行すると、<code>range</code>が表示される。さて、PHP では文字列リテラル中に生の改行を直接書いてもよいのだった (「主な障害」の節を参照のこと)。書きかえてみよう。 </p> - <pre class="highlight" language="php" linenumbering="unnumbered"><code>$x -='x + <pre class="highlight" language="php" linenumbering="unnumbered"><code class="highlight"><span class="hljs-variable">$x</span> +=<span class="hljs-string">'x Om -'; -$y -=' +'</span>; +<span class="hljs-variable">$y</span> +=<span class="hljs-string">' k! -o' +o'</span> ; -$r = $x ^ $y; -echo "$r\n";</code></pre> +<span class="hljs-variable">$r</span> = <span class="hljs-variable">$x</span> ^ <span class="hljs-variable">$y</span>; +<span class="hljs-keyword">echo</span> <span class="hljs-string">"<span class="hljs-subst">$r</span>\n"</span>;</code></pre> <p> さらに<code>#</code>を使って適当に調整すると、次のようになる。 </p> - <pre class="highlight" language="php" linenumbering="unnumbered"><code>$x -=# -'x + <pre class="highlight" language="php" linenumbering="unnumbered"><code class="highlight"><span class="hljs-variable">$x</span> +=<span class="hljs-comment">#</span> +<span class="hljs-string">'x Om -'; -$y -=' +'</span>; +<span class="hljs-variable">$y</span> +=<span class="hljs-string">' k! -o' -;# -$r -=# -$x -^# -$y -;# +o'</span> +;<span class="hljs-comment">#</span> +<span class="hljs-variable">$r</span> +=<span class="hljs-comment">#</span> +<span class="hljs-variable">$x</span> +^<span class="hljs-comment">#</span> +<span class="hljs-variable">$y</span> +;<span class="hljs-comment">#</span> -echo "$r\n";</code></pre> +<span class="hljs-keyword">echo</span> <span class="hljs-string">"<span class="hljs-subst">$r</span>\n"</span>;</code></pre> <p> 1行あたり2文字で、<code>range</code>という文字列を生成することに成功した。他の必要な文字列にも、同様の処理をほどこす。 @@ -478,154 +478,154 @@ echo "$r\n";</code></pre> 完成したものがこちら。 </p> - <pre class="highlight" language="php" linenumbering="unnumbered"><code><?php + <pre class="highlight" language="php" linenumbering="unnumbered"><code class="highlight">&lt;?php -$x -=# -'i -S' +<span class="hljs-variable">$x</span> +=<span class="hljs-comment">#</span> +<span class="hljs-string">'i +S'</span> ;; -$y -=' +<span class="hljs-variable">$y</span> +=<span class="hljs-string">' b! -'; -$c -=# -$x -^# -$y -;# -$x -=# -'x +'</span>; +<span class="hljs-variable">$c</span> +=<span class="hljs-comment">#</span> +<span class="hljs-variable">$x</span> +^<span class="hljs-comment">#</span> +<span class="hljs-variable">$y</span> +;<span class="hljs-comment">#</span> +<span class="hljs-variable">$x</span> +=<span class="hljs-comment">#</span> +<span class="hljs-string">'x Om -'; -$y -=' +'</span>; +<span class="hljs-variable">$y</span> +=<span class="hljs-string">' k! -o' -;# -$r -=# -$x -^# -$y -;# -$x -=# -'k +o'</span> +;<span class="hljs-comment">#</span> +<span class="hljs-variable">$r</span> +=<span class="hljs-comment">#</span> +<span class="hljs-variable">$x</span> +^<span class="hljs-comment">#</span> +<span class="hljs-variable">$y</span> +;<span class="hljs-comment">#</span> +<span class="hljs-variable">$x</span> +=<span class="hljs-comment">#</span> +<span class="hljs-string">'k Sk ~} Ma -'; -$y -=' +'</span>; +<span class="hljs-variable">$y</span> +=<span class="hljs-string">' x! s! k! -'; -$w -=# -$x -^# -$y -;# -$x -=# -'z +'</span>; +<span class="hljs-variable">$w</span> +=<span class="hljs-comment">#</span> +<span class="hljs-variable">$x</span> +^<span class="hljs-comment">#</span> +<span class="hljs-variable">$y</span> +;<span class="hljs-comment">#</span> +<span class="hljs-variable">$x</span> +=<span class="hljs-comment">#</span> +<span class="hljs-string">'z Hd -G' -;# -$y -=' +G'</span> +;<span class="hljs-comment">#</span> +<span class="hljs-variable">$y</span> +=<span class="hljs-string">' x! ~! -'; -$p -=# -$x -^# -$y -;# -$x -=# -'L +'</span>; +<span class="hljs-variable">$p</span> +=<span class="hljs-comment">#</span> +<span class="hljs-variable">$x</span> +^<span class="hljs-comment">#</span> +<span class="hljs-variable">$y</span> +;<span class="hljs-comment">#</span> +<span class="hljs-variable">$x</span> +=<span class="hljs-comment">#</span> +<span class="hljs-string">'L [p -'; -$y -=' +'</span>; +<span class="hljs-variable">$y</span> +=<span class="hljs-string">' c! -'; -$f -=# -$x -^# -$y -;# -$x -=# -'H +'</span>; +<span class="hljs-variable">$f</span> +=<span class="hljs-comment">#</span> +<span class="hljs-variable">$x</span> +^<span class="hljs-comment">#</span> +<span class="hljs-variable">$y</span> +;<span class="hljs-comment">#</span> +<span class="hljs-variable">$x</span> +=<span class="hljs-comment">#</span> +<span class="hljs-string">'H [p -'; -$y -=' +'</span>; +<span class="hljs-variable">$y</span> +=<span class="hljs-string">' _! -'; -$b -=# -$x -^# -$y -;# -$b -[1 +'</span>; +<span class="hljs-variable">$b</span> +=<span class="hljs-comment">#</span> +<span class="hljs-variable">$x</span> +^<span class="hljs-comment">#</span> +<span class="hljs-variable">$y</span> +;<span class="hljs-comment">#</span> +<span class="hljs-variable">$b</span> +[<span class="hljs-number">1</span> ]= -$c -(# -13 -*9 +<span class="hljs-variable">$c</span> +(<span class="hljs-comment">#</span> +<span class="hljs-number">13</span> +*<span class="hljs-number">9</span> ); -$s -=# -$r -(1 +<span class="hljs-variable">$s</span> +=<span class="hljs-comment">#</span> +<span class="hljs-variable">$r</span> +(<span class="hljs-number">1</span> ,( -10 +<span class="hljs-number">10</span> ** -2) +<span class="hljs-number">2</span>) ); -$w -(# -$s -,# -fn -(# -$i -)# -=> -$p +<span class="hljs-variable">$w</span> +(<span class="hljs-comment">#</span> +<span class="hljs-variable">$s</span> +,<span class="hljs-comment">#</span> +<span class="hljs-function"><span class="hljs-keyword">fn</span> +(<span class="hljs-params"># +<span class="hljs-variable">$i</span> +</span>)# +=&<span class="hljs-title">gt</span></span>; +<span class="hljs-variable">$p</span> (( -(# -$i -%3 -?# -'' -:# -$f +(<span class="hljs-comment">#</span> +<span class="hljs-variable">$i</span> +%<span class="hljs-number">3</span> +?<span class="hljs-comment">#</span> +<span class="hljs-string">''</span> +:<span class="hljs-comment">#</span> +<span class="hljs-variable">$f</span> ). -(# -$i -%5 -?# -'' -:# -$b +(<span class="hljs-comment">#</span> +<span class="hljs-variable">$i</span> +%<span class="hljs-number">5</span> +?<span class="hljs-comment">#</span> +<span class="hljs-string">''</span> +:<span class="hljs-comment">#</span> +<span class="hljs-variable">$b</span> )? -:# -$i -)# -.' -') +:<span class="hljs-comment">#</span> +<span class="hljs-variable">$i</span> +)<span class="hljs-comment">#</span> +.<span class="hljs-string">' +'</span>) );</code></pre> </section> @@ -646,17 +646,17 @@ $i PHP では、バッククォートを使ってシェルを呼び出せる。これは<code>shell_exec</code>関数と等価である。さて、PHP ではバックスラッシュによる行継続が使えないと書いたが、シェルでは使える (当然だが、呼び出されるシェルに依存する。Bash なら大丈夫だろう。知らんけど)。 </p> - <pre class="highlight" language="php" linenumbering="unnumbered"><code><?php + <pre class="highlight" language="php" linenumbering="unnumbered"><code class="highlight">&lt;?php -printf(` +<span class="hljs-title function_ invoke__">printf</span>(` e\ c\ h\ o\ \ -1\ -2\ -3\ +<span class="hljs-number">1</span>\ +<span class="hljs-number">2</span>\ +<span class="hljs-number">3</span>\ `);</code></pre> <p> @@ -685,34 +685,34 @@ o\ もうこれ以上は不可能だと思っていたのだが、この記事の執筆中に解決する方法を思いついたので載せておく。 </p> - <pre class="highlight" language="php" linenumbering="unnumbered"><code><?php + <pre class="highlight" language="php" linenumbering="unnumbered"><code class="highlight">&lt;?php -$c = 'chr'; +<span class="hljs-variable">$c</span> = <span class="hljs-string">'chr'</span>; ${ -'_ -'} -=# -$c -(# -32 +<span class="hljs-string">'_ +'</span>} +=<span class="hljs-comment">#</span> +<span class="hljs-variable">$c</span> +(<span class="hljs-comment">#</span> +<span class="hljs-number">32</span> ). -$c -(# -92 +<span class="hljs-variable">$c</span> +(<span class="hljs-comment">#</span> +<span class="hljs-number">92</span> ); -printf(` +<span class="hljs-title function_ invoke__">printf</span>(` e\ c\ h\ o\ ${ -'_ -'} -1\ -2\ -3\ +<span class="hljs-string">'_ +'</span>} +<span class="hljs-number">1</span>\ +<span class="hljs-number">2</span>\ +<span class="hljs-number">3</span>\ `);</code></pre> <p> @@ -720,8 +720,8 @@ ${ </p> <pre class="monospaced highlight"><code>${ -'_ -'}</code></pre> +'_ +'}</code></pre> <p> は変数で、中にはスペースとエスケープが入っている (<code>chr(32) . chr(92)</code>)。シェルに渡されている文字列は次のようになる。 @@ -749,8 +749,8 @@ o\ </p> <pre class="monospaced highlight"><code>${ -'_ -'}</code></pre> +'_ +'}</code></pre> <p> 最新版で警告が出るというのも美しくないので、私としては本編の解法を推す。 diff --git a/public/posts/2022-10-23/phperkaigi-2023-unused-token-quiz-1/index.html b/public/posts/2022-10-23/phperkaigi-2023-unused-token-quiz-1/index.html index d7f71aa..10ef763 100644 --- a/public/posts/2022-10-23/phperkaigi-2023-unused-token-quiz-1/index.html +++ b/public/posts/2022-10-23/phperkaigi-2023-unused-token-quiz-1/index.html @@ -10,7 +10,7 @@ <link rel="icon" type="image/svg+xml" href="/favicon.svg"> <title>PHPerKaigi 2023: ボツになったトークン問題 その 1 | REPL: Rest-Eat-Program Loop</title> <link rel="stylesheet" href="/style.css?h=17cf97a767ec5fb6e64967729f40f30a"> - <link rel="stylesheet" href="/hl.css?h=208c52e3b7c9db1cad782c5d30b4698f"> + <link rel="stylesheet" href="/hl.css?h=340e65ffd5c17713efc9107c06304f7b"> </head> <body class="single"> <header class="header"> @@ -78,26 +78,26 @@ 注意: これはボツ問なので、得られたトークンを PHPerKaigi で入力してもポイントにはならない。 </p> - <pre class="highlight" language="php" linenumbering="unnumbered"><code><?php + <pre class="highlight" language="php" linenumbering="unnumbered"><code class="highlight"><span class="hljs-meta"><?php</span> -$π = $argv[1] ?? null; -if ($π === null) { -exit('No input.'); +$π = <span class="hljs-variable">$argv</span>[<span class="hljs-number">1</span>] ?? <span class="hljs-literal">null</span>; +<span class="hljs-keyword">if</span> ($π === <span class="hljs-literal">null</span>) { +<span class="hljs-keyword">exit</span>(<span class="hljs-string">'No input.'</span>); } -$π = trim($π); -if (!is_numeric($π)) { -exit('Invalid input.'); +$π = <span class="hljs-title function_ invoke__">trim</span>($π); +<span class="hljs-keyword">if</span> (!<span class="hljs-title function_ invoke__">is_numeric</span>($π)) { +<span class="hljs-keyword">exit</span>(<span class="hljs-string">'Invalid input.'</span>); } -$s = implode(array_map(chr(...), str_split($π, 2))); +<span class="hljs-variable">$s</span> = <span class="hljs-title function_ invoke__">implode</span>(<span class="hljs-title function_ invoke__">array_map</span>(<span class="hljs-title function_ invoke__">chr</span>(...), <span class="hljs-title function_ invoke__">str_split</span>($π, <span class="hljs-number">2</span>))); -preg_match('/(\x23.+?) /', $s, $m); -$t = $m[1] ?? ''; +<span class="hljs-title function_ invoke__">preg_match</span>(<span class="hljs-string">'/(\x23.+?) /'</span>, <span class="hljs-variable">$s</span>, <span class="hljs-variable">$m</span>); +<span class="hljs-variable">$t</span> = <span class="hljs-variable">$m</span>[<span class="hljs-number">1</span>] ?? <span class="hljs-string">''</span>; -if (md5($t) === '056e831a4146bf123e8ea16613303d2e') { -echo "Token: {$t}\n"; -} else { -echo "Failed.\n"; +<span class="hljs-keyword">if</span> (<span class="hljs-title function_ invoke__">md5</span>(<span class="hljs-variable">$t</span>) === <span class="hljs-string">'056e831a4146bf123e8ea16613303d2e'</span>) { +<span class="hljs-keyword">echo</span> <span class="hljs-string">"Token: <span class="hljs-subst">{$t}</span>\n"</span>; +} <span class="hljs-keyword">else</span> { +<span class="hljs-keyword">echo</span> <span class="hljs-string">"Failed.\n"</span>; }</code></pre> </section> @@ -107,14 +107,14 @@ echo "Failed.\n"; ソースを見るとわかるとおり、<code>$argv[1]</code>を参照している。それを<code>$π</code>なる変数に代入しているので、円周率を渡してみる。 </p> - <pre class="highlight" language="shell-session" linenumbering="unnumbered"><code>$ php Q.php 3.14 + <pre class="highlight" language="shell-session" linenumbering="unnumbered"><code class="highlight">$ php Q.php 3.14 Failed.</code></pre> <p> 失敗してしまった。精度を上げてみる。 </p> - <pre class="highlight" language="shell-session" linenumbering="unnumbered"><code>$ php Q.php 3.1415 + <pre class="highlight" language="shell-session" linenumbering="unnumbered"><code class="highlight">$ php Q.php 3.1415 Failed.</code></pre> <p> @@ -125,7 +125,7 @@ Failed.</code></pre> 最初にトークンが得られるのは、小数点以下 16 桁目まで入力したときで、こうなる。 </p> - <pre class="highlight" language="shell-session" linenumbering="unnumbered"><code>$ php Q.php 3.1415926535897932 + <pre class="highlight" language="shell-session" linenumbering="unnumbered"><code class="highlight">$ php Q.php 3.1415926535897932 Token: #YO</code></pre> <p> @@ -139,20 +139,20 @@ Token: #YO</code></pre> 短いので頭から追っていく。 </p> - <pre class="highlight" language="php" linenumbering="unnumbered"><code>$π = $argv[1] ?? null; - if ($π === null) { - exit('No input.'); + <pre class="highlight" language="php" linenumbering="unnumbered"><code class="highlight">$π = <span class="hljs-variable">$argv</span>[<span class="hljs-number">1</span>] ?? <span class="hljs-literal">null</span>; + <span class="hljs-keyword">if</span> ($π === <span class="hljs-literal">null</span>) { + <span class="hljs-keyword">exit</span>(<span class="hljs-string">'No input.'</span>); } - $π = trim($π); - if (!is_numeric($π)) { - exit('Invalid input.'); + $π = <span class="hljs-title function_ invoke__">trim</span>($π); + <span class="hljs-keyword">if</span> (!<span class="hljs-title function_ invoke__">is_numeric</span>($π)) { + <span class="hljs-keyword">exit</span>(<span class="hljs-string">'Invalid input.'</span>); }</code></pre> <p> 入力のバリデーション部分。数値のみ受け付ける。 </p> - <pre class="highlight" language="php" linenumbering="unnumbered"><code>$s = implode(array_map(chr(...), str_split($π, 2)));</code></pre> + <pre class="highlight" language="php" linenumbering="unnumbered"><code class="highlight"><span class="hljs-variable">$s</span> = <span class="hljs-title function_ invoke__">implode</span>(<span class="hljs-title function_ invoke__">array_map</span>(<span class="hljs-title function_ invoke__">chr</span>(...), <span class="hljs-title function_ invoke__">str_split</span>($π, <span class="hljs-number">2</span>)));</code></pre> <p> <code>$π</code>を 2 文字ごとに区切り (<code>str_split</code>)、数値を ASCII コードと見做して文字に変換 (<code>chr</code>) して結合 (<code>implode</code>) している。 @@ -162,13 +162,13 @@ Token: #YO</code></pre> 例えば、<code>$π</code>が<code>'656667'</code>だったとすると、<code>65</code>、<code>66</code>、<code>67</code>に対応した<code>'A'</code>、<code>'B'</code>、<code>'C'</code>へと変換され、<code>'ABC'</code>になる。 </p> - <pre class="highlight" language="php" linenumbering="unnumbered"><code>$π = '656667'; -$s = implode(array_map(chr(...), str_split($π, 2))); -echo $s; -// => ABC</code></pre> + <pre class="highlight" language="php" linenumbering="unnumbered"><code class="highlight">$π = <span class="hljs-string">'656667'</span>; +<span class="hljs-variable">$s</span> = <span class="hljs-title function_ invoke__">implode</span>(<span class="hljs-title function_ invoke__">array_map</span>(<span class="hljs-title function_ invoke__">chr</span>(...), <span class="hljs-title function_ invoke__">str_split</span>($π, <span class="hljs-number">2</span>))); +<span class="hljs-keyword">echo</span> <span class="hljs-variable">$s</span>; +<span class="hljs-comment">// => ABC</span></code></pre> - <pre class="highlight" language="php" linenumbering="unnumbered"><code>preg_match('/(\x23.+?) /', $s, $m); -$t = $m[1] ?? '';</code></pre> + <pre class="highlight" language="php" linenumbering="unnumbered"><code class="highlight"><span class="hljs-title function_ invoke__">preg_match</span>(<span class="hljs-string">'/(\x23.+?) /'</span>, <span class="hljs-variable">$s</span>, <span class="hljs-variable">$m</span>); +<span class="hljs-variable">$t</span> = <span class="hljs-variable">$m</span>[<span class="hljs-number">1</span>] ?? <span class="hljs-string">''</span>;</code></pre> <p> 正規表現でマッチングしている。<code>\x23</code>は<code>#</code>と同じであることに留意すると、この正規表現は「<code>#</code>から始まる 2 以上の長さ (含<code>#</code>) の文字列で、最初に現れるスペースまで」にマッチする。つまりこれは、PHPerKaigi におけるトークンである。 @@ -178,10 +178,10 @@ $t = $m[1] ?? '';</code></pre> なお、<code>#</code>を直接書いていないのは、<code>/#.+?) /</code>と書くと、<code>#.+?)</code>という意図せぬトークンが登録されてしまうからである。 </p> - <pre class="highlight" language="php" linenumbering="unnumbered"><code>if (md5($t) === '056e831a4146bf123e8ea16613303d2e') { -echo "Token: {$t}\n"; -} else { -echo "Failed.\n"; + <pre class="highlight" language="php" linenumbering="unnumbered"><code class="highlight"><span class="hljs-keyword">if</span> (<span class="hljs-title function_ invoke__">md5</span>(<span class="hljs-variable">$t</span>) === <span class="hljs-string">'056e831a4146bf123e8ea16613303d2e'</span>) { +<span class="hljs-keyword">echo</span> <span class="hljs-string">"Token: <span class="hljs-subst">{$t}</span>\n"</span>; +} <span class="hljs-keyword">else</span> { +<span class="hljs-keyword">echo</span> <span class="hljs-string">"Failed.\n"</span>; }</code></pre> <p> diff --git a/public/posts/2022-10-28/setup-server-for-this-site/index.html b/public/posts/2022-10-28/setup-server-for-this-site/index.html index e050bac..2f458ad 100644 --- a/public/posts/2022-10-28/setup-server-for-this-site/index.html +++ b/public/posts/2022-10-28/setup-server-for-this-site/index.html @@ -10,7 +10,7 @@ <link rel="icon" type="image/svg+xml" href="/favicon.svg"> <title>【備忘録】 このサイト用の VPS をセットアップしたときのメモ | REPL: Rest-Eat-Program Loop</title> <link rel="stylesheet" href="/style.css?h=17cf97a767ec5fb6e64967729f40f30a"> - <link rel="stylesheet" href="/hl.css?h=208c52e3b7c9db1cad782c5d30b4698f"> + <link rel="stylesheet" href="/hl.css?h=340e65ffd5c17713efc9107c06304f7b"> </head> <body class="single"> <header class="header"> @@ -83,7 +83,7 @@ ローカルマシンで鍵を生成する。 </p> - <pre class="highlight" language="shell-session" linenumbering="unnumbered"><code>$ ssh-keygen -t ed25519 -b 521 -f ~/.ssh/teika.key + <pre class="highlight" language="shell-session" linenumbering="unnumbered"><code class="highlight">$ ssh-keygen -t ed25519 -b 521 -f ~/.ssh/teika.key $ ssh-keygen -t ed25519 -b 521 -f ~/.ssh/github2teika.key</code></pre> <p> @@ -97,7 +97,7 @@ <code>.ssh/config</code>に設定しておく。 </p> - <pre class="highlight" language="ssh_config" linenumbering="unnumbered"><code>Host teika + <pre class="highlight" language="ssh_config" linenumbering="unnumbered"><code class="highlight">Host teika HostName ********** User ********** Port ********** @@ -120,7 +120,7 @@ 管理者ユーザで作業すると危ないので、メインで使うユーザを作成する。<code>sudo</code>グループに追加して<code>sudo</code>できるようにし、<code>su</code>で切り替え。 </p> - <pre class="highlight" language="shell-session" linenumbering="unnumbered"><code>$ sudo adduser ********** + <pre class="highlight" language="shell-session" linenumbering="unnumbered"><code class="highlight">$ sudo adduser ********** $ sudo adduser ********** sudo $ su ********** $ cd</code></pre> @@ -128,12 +128,12 @@ <section id="section--_ホスト名を変える"> <h3><a href="#section--_ホスト名を変える">ホスト名を変える</a></h3> - <pre class="highlight" language="shell-session" linenumbering="unnumbered"><code>$ sudo hostname teika</code></pre> + <pre class="highlight" language="shell-session" linenumbering="unnumbered"><code class="highlight">$ sudo hostname teika</code></pre> </section> <section id="section--_公開鍵を置く"> <h3><a href="#section--_公開鍵を置く">公開鍵を置く</a></h3> - <pre class="highlight" language="shell-session" linenumbering="unnumbered"><code>$ mkdir ~/.ssh + <pre class="highlight" language="shell-session" linenumbering="unnumbered"><code class="highlight">$ mkdir ~/.ssh $ chmod 700 ~/.ssh $ vi ~/.ssh/authorized_keys</code></pre> @@ -148,7 +148,7 @@ SSH の設定を変更し、少しでも安全にしておく。 </p> - <pre class="highlight" language="shell-session" linenumbering="unnumbered"><code>$ sudo cp /etc/ssh/sshd_config /etc/ssh/sshd_config.bak + <pre class="highlight" language="shell-session" linenumbering="unnumbered"><code class="highlight">$ sudo cp /etc/ssh/sshd_config /etc/ssh/sshd_config.bak $ sudo vi /etc/ssh/sshd_config</code></pre> <ul> @@ -175,7 +175,7 @@ そして設定を反映。 </p> - <pre class="highlight" language="shell-session" linenumbering="unnumbered"><code>$ sudo systemctl restart sshd + <pre class="highlight" language="shell-session" linenumbering="unnumbered"><code class="highlight">$ sudo systemctl restart sshd $ sudo systemctl status sshd</code></pre> </section> @@ -185,7 +185,7 @@ $ sudo systemctl status sshd</code></pre> 今の SSH セッションは閉じずに、ターミナルを別途開いて疎通確認する。セッションを閉じてしまうと、SSH の設定に不備があった場合に締め出しをくらう。 </p> - <pre class="highlight" language="shell-session" linenumbering="unnumbered"><code>$ ssh teika</code></pre> + <pre class="highlight" language="shell-session" linenumbering="unnumbered"><code class="highlight">$ ssh teika</code></pre> </section> <section id="section--_ポートの遮断"> @@ -194,7 +194,7 @@ $ sudo systemctl status sshd</code></pre> デフォルトの 22 番を閉じ、設定したポートだけ空ける。 </p> - <pre class="highlight" language="shell-session" linenumbering="unnumbered"><code>$ sudo ufw deny ssh + <pre class="highlight" language="shell-session" linenumbering="unnumbered"><code class="highlight">$ sudo ufw deny ssh $ sudo ufw allow ******* $ sudo ufw enable $ sudo ufw reload @@ -211,20 +211,20 @@ $ sudo systemctl status sshd</code></pre> GitHub に置いてある private リポジトリをサーバから clone したいので、SSH 鍵を生成して置いておく。 </p> - <pre class="highlight" language="shell-session" linenumbering="unnumbered"><code>$ ssh-keygen -t ed25519 -b 521 -f ~/.ssh/github.key + <pre class="highlight" language="shell-session" linenumbering="unnumbered"><code class="highlight">$ ssh-keygen -t ed25519 -b 521 -f ~/.ssh/github.key $ cat ~/.ssh/github.key.pub</code></pre> <p> <a href="https://github.com/settings/ssh">GitHub の設定画面</a>から、この公開鍵を追加する。 </p> - <pre class="highlight" language="shell-session" linenumbering="unnumbered"><code>$ vi ~/.ssh/config</code></pre> + <pre class="highlight" language="shell-session" linenumbering="unnumbered"><code class="highlight">$ vi ~/.ssh/config</code></pre> <p> 設定はこう。 </p> - <pre class="highlight" language="ssh_config" linenumbering="unnumbered"><code>Host github.com + <pre class="highlight" language="ssh_config" linenumbering="unnumbered"><code class="highlight">Host github.com HostName github.com User git IdentityFile ~/.ssh/github.key</code></pre> @@ -233,12 +233,12 @@ IdentityFile ~/.ssh/github.key</code></pre> 最後に接続できるか確認しておく。 </p> - <pre class="highlight" language="shell-session" linenumbering="unnumbered"><code>ssh -T github.com</code></pre> + <pre class="highlight" language="shell-session" linenumbering="unnumbered"><code class="highlight">ssh -T github.com</code></pre> </section> <section id="section--_パッケージの更新"> <h3><a href="#section--_パッケージの更新">パッケージの更新</a></h3> - <pre class="highlight" language="shell-session" linenumbering="unnumbered"><code>$ sudo apt update + <pre class="highlight" language="shell-session" linenumbering="unnumbered"><code class="highlight">$ sudo apt update $ sudo apt upgrade $ sudo apt update $ sudo apt upgrade @@ -257,12 +257,12 @@ IdentityFile ~/.ssh/github.key</code></pre> <section id="section--_使うソフトウェアのインストール"> <h3><a href="#section--_使うソフトウェアのインストール">使うソフトウェアのインストール</a></h3> - <pre class="highlight" language="shell-session" linenumbering="unnumbered"><code>$ sudo apt install docker docker-compose git make</code></pre> + <pre class="highlight" language="shell-session" linenumbering="unnumbered"><code class="highlight">$ sudo apt install docker docker-compose git make</code></pre> </section> <section id="section--_メインユーザが_docker_を使えるように"> <h3><a href="#section--_メインユーザが_docker_を使えるように">メインユーザが Docker を使えるように</a></h3> - <pre class="highlight" language="shell-session" linenumbering="unnumbered"><code>sudo adduser ********** docker</code></pre> + <pre class="highlight" language="shell-session" linenumbering="unnumbered"><code class="highlight">sudo adduser ********** docker</code></pre> </section> <section id="section--_httphttps_を通す"> @@ -271,7 +271,7 @@ IdentityFile ~/.ssh/github.key</code></pre> 80 番と 443 番を空ける。 </p> - <pre class="highlight" language="shell-session" linenumbering="unnumbered"><code>$ sudo ufw allow 80/tcp + <pre class="highlight" language="shell-session" linenumbering="unnumbered"><code class="highlight">$ sudo ufw allow 80/tcp $ sudo ufw allow 443/tcp $ sudo ufw reload $ sudo ufw status</code></pre> @@ -279,7 +279,7 @@ IdentityFile ~/.ssh/github.key</code></pre> <section id="section--_リポジトリのクローン"> <h3><a href="#section--_リポジトリのクローン">リポジトリのクローン</a></h3> - <pre class="highlight" language="shell-session" linenumbering="unnumbered"><code>$ cd + <pre class="highlight" language="shell-session" linenumbering="unnumbered"><code class="highlight">$ cd $ git clone git@github.com:nsfisis/nsfisis.dev.git $ cd nsfisis.dev $ git submodule update --init</code></pre> @@ -287,13 +287,13 @@ IdentityFile ~/.ssh/github.key</code></pre> <section id="section--_certbot_で証明書取得"> <h3><a href="#section--_certbot_で証明書取得">certbot で証明書取得</a></h3> - <pre class="highlight" language="shell-session" linenumbering="unnumbered"><code>$ docker-compose up -d acme-challenge + <pre class="highlight" language="shell-session" linenumbering="unnumbered"><code class="highlight">$ docker-compose up -d acme-challenge $ make setup</code></pre> </section> <section id="section--_サーバを稼動させる"> <h3><a href="#section--_サーバを稼動させる">サーバを稼動させる</a></h3> - <pre class="highlight" language="shell-session" linenumbering="unnumbered"><code>$ make serve</code></pre> + <pre class="highlight" language="shell-session" linenumbering="unnumbered"><code class="highlight">$ make serve</code></pre> </section> </section> diff --git a/public/posts/2022-11-19/phperkaigi-2023-unused-token-quiz-2/index.html b/public/posts/2022-11-19/phperkaigi-2023-unused-token-quiz-2/index.html index fd1a1d2..e78fdce 100644 --- a/public/posts/2022-11-19/phperkaigi-2023-unused-token-quiz-2/index.html +++ b/public/posts/2022-11-19/phperkaigi-2023-unused-token-quiz-2/index.html @@ -10,7 +10,7 @@ <link rel="icon" type="image/svg+xml" href="/favicon.svg"> <title>PHPerKaigi 2023: ボツになったトークン問題 その 2 | REPL: Rest-Eat-Program Loop</title> <link rel="stylesheet" href="/style.css?h=17cf97a767ec5fb6e64967729f40f30a"> - <link rel="stylesheet" href="/hl.css?h=208c52e3b7c9db1cad782c5d30b4698f"> + <link rel="stylesheet" href="/hl.css?h=340e65ffd5c17713efc9107c06304f7b"> </head> <body class="single"> <header class="header"> @@ -82,17 +82,17 @@ 注意: これはボツ問なので、得られたトークンを PHPerKaigi で入力してもポイントにはならない。 </p> - <pre class="highlight" language="php" linenumbering="unnumbered"><code> - <?php printf((isset($s)?fn($s)=>trim($s,""):fn($s)=>chr(strlen($s)/3))($s='<?php printf((isset($s)?fn($s)=>trim($s,""):fn($s)=>chr(strlen($s)/3))($s=%s)."\n","\x27$s\x27");?>')."\n","\x27$s\x27");?> - <?php printf((isset($s)?fn($s)=>trim($s,""):fn($s)=>chr(strlen($s)/3))($s='<?php printf((isset($s)?fn($s)=>trim($s,""):fn($s)=>chr(strlen($s)/3))($s=%s)."\n","\x27$s\x27");?>')."\n","\x27$s\x27");?> - <?php printf((isset($s)?fn($s)=>trim($s,""):fn($s)=>chr(strlen($s)/3))($s='<?php printf((isset($s)?fn($s)=>trim($s,""):fn($s)=>chr(strlen($s)/3))($s=%s)."\n","\x27$s\x27");?>')."\n","\x27$s\x27");?> - <?php printf((isset($s)?fn($s)=>trim($s,""):fn($s)=>chr(strlen($s)/3))($s='<?php printf((isset($s)?fn($s)=>trim($s,""):fn($s)=>chr(strlen($s)/3))($s=%s)."\n","\x27$s\x27");?>')."\n","\x27$s\x27");?> - <?php printf((isset($s)?fn($s)=>trim($s,""):fn($s)=>chr(strlen($s)/3))($s='<?php printf((isset($s)?fn($s)=>trim($s,""):fn($s)=>chr(strlen($s)/3))($s=%s)."\n","\x27$s\x27");?>')."\n","\x27$s\x27");?> - <?php printf((isset($s)?fn($s)=>trim($s,""):fn($s)=>chr(strlen($s)/3))($s='<?php printf((isset($s)?fn($s)=>trim($s,""):fn($s)=>chr(strlen($s)/3))($s=%s)."\n","\x27$s\x27");?>')."\n","\x27$s\x27");?> - <?php printf((isset($s)?fn($s)=>trim($s,""):fn($s)=>chr(strlen($s)/3))($s='<?php printf((isset($s)?fn($s)=>trim($s,""):fn($s)=>chr(strlen($s)/3))($s=%s)."\n","\x27$s\x27");?>')."\n","\x27$s\x27");?> - <?php printf((isset($s)?fn($s)=>trim($s,""):fn($s)=>chr(strlen($s)/3))($s='<?php printf((isset($s)?fn($s)=>trim($s,""):fn($s)=>chr(strlen($s)/3))($s=%s)."\n","\x27$s\x27");?>')."\n","\x27$s\x27");?> - <?php printf((isset($s)?fn($s)=>trim($s,""):fn($s)=>chr(strlen($s)/3))($s='<?php printf((isset($s)?fn($s)=>trim($s,""):fn($s)=>chr(strlen($s)/3))($s=%s)."\n","\x27$s\x27");?>')."\n","\x27$s\x27");?> - <?php printf((isset($s)?fn($s)=>trim($s,""):fn($s)=>chr(strlen($s)/3))($s='<?php printf((isset($s)?fn($s)=>trim($s,""):fn($s)=>chr(strlen($s)/3))($s=%s)."\n","\x27$s\x27");?>')."\n","\x27$s\x27");?> + <pre class="highlight" language="php" linenumbering="unnumbered"><code class="highlight"> + <span class="hljs-meta"><?php</span> <span class="hljs-title function_ invoke__">printf</span>((<span class="hljs-keyword">isset</span>(<span class="hljs-variable">$s</span>)?<span class="hljs-function"><span class="hljs-keyword">fn</span>(<span class="hljs-params"><span class="hljs-variable">$s</span></span>)=></span><span class="hljs-title function_ invoke__">trim</span>(<span class="hljs-variable">$s</span>,<span class="hljs-string">""</span>):<span class="hljs-function"><span class="hljs-keyword">fn</span>(<span class="hljs-params"><span class="hljs-variable">$s</span></span>)=></span><span class="hljs-title function_ invoke__">chr</span>(<span class="hljs-title function_ invoke__">strlen</span>(<span class="hljs-variable">$s</span>)/<span class="hljs-number">3</span>))(<span class="hljs-variable">$s</span>=<span class="hljs-string">'<?php printf((isset($s)?fn($s)=>trim($s,""):fn($s)=>chr(strlen($s)/3))($s=%s)."\n","\x27$s\x27");?>'</span>).<span class="hljs-string">"\n"</span>,<span class="hljs-string">"\x27<span class="hljs-subst">$s</span>\x27"</span>);<span class="hljs-meta">?></span> + <span class="hljs-meta"><?php</span> <span class="hljs-title function_ invoke__">printf</span>((<span class="hljs-keyword">isset</span>(<span class="hljs-variable">$s</span>)?<span class="hljs-function"><span class="hljs-keyword">fn</span>(<span class="hljs-params"><span class="hljs-variable">$s</span></span>)=></span><span class="hljs-title function_ invoke__">trim</span>(<span class="hljs-variable">$s</span>,<span class="hljs-string">""</span>):<span class="hljs-function"><span class="hljs-keyword">fn</span>(<span class="hljs-params"><span class="hljs-variable">$s</span></span>)=></span><span class="hljs-title function_ invoke__">chr</span>(<span class="hljs-title function_ invoke__">strlen</span>(<span class="hljs-variable">$s</span>)/<span class="hljs-number">3</span>))(<span class="hljs-variable">$s</span>=<span class="hljs-string">'<?php printf((isset($s)?fn($s)=>trim($s,""):fn($s)=>chr(strlen($s)/3))($s=%s)."\n","\x27$s\x27");?>'</span>).<span class="hljs-string">"\n"</span>,<span class="hljs-string">"\x27<span class="hljs-subst">$s</span>\x27"</span>);<span class="hljs-meta">?></span> + <span class="hljs-meta"><?php</span> <span class="hljs-title function_ invoke__">printf</span>((<span class="hljs-keyword">isset</span>(<span class="hljs-variable">$s</span>)?<span class="hljs-function"><span class="hljs-keyword">fn</span>(<span class="hljs-params"><span class="hljs-variable">$s</span></span>)=></span><span class="hljs-title function_ invoke__">trim</span>(<span class="hljs-variable">$s</span>,<span class="hljs-string">""</span>):<span class="hljs-function"><span class="hljs-keyword">fn</span>(<span class="hljs-params"><span class="hljs-variable">$s</span></span>)=></span><span class="hljs-title function_ invoke__">chr</span>(<span class="hljs-title function_ invoke__">strlen</span>(<span class="hljs-variable">$s</span>)/<span class="hljs-number">3</span>))(<span class="hljs-variable">$s</span>=<span class="hljs-string">'<?php printf((isset($s)?fn($s)=>trim($s,""):fn($s)=>chr(strlen($s)/3))($s=%s)."\n","\x27$s\x27");?>'</span>).<span class="hljs-string">"\n"</span>,<span class="hljs-string">"\x27<span class="hljs-subst">$s</span>\x27"</span>);<span class="hljs-meta">?></span> + <span class="hljs-meta"><?php</span> <span class="hljs-title function_ invoke__">printf</span>((<span class="hljs-keyword">isset</span>(<span class="hljs-variable">$s</span>)?<span class="hljs-function"><span class="hljs-keyword">fn</span>(<span class="hljs-params"><span class="hljs-variable">$s</span></span>)=></span><span class="hljs-title function_ invoke__">trim</span>(<span class="hljs-variable">$s</span>,<span class="hljs-string">""</span>):<span class="hljs-function"><span class="hljs-keyword">fn</span>(<span class="hljs-params"><span class="hljs-variable">$s</span></span>)=></span><span class="hljs-title function_ invoke__">chr</span>(<span class="hljs-title function_ invoke__">strlen</span>(<span class="hljs-variable">$s</span>)/<span class="hljs-number">3</span>))(<span class="hljs-variable">$s</span>=<span class="hljs-string">'<?php printf((isset($s)?fn($s)=>trim($s,""):fn($s)=>chr(strlen($s)/3))($s=%s)."\n","\x27$s\x27");?>'</span>).<span class="hljs-string">"\n"</span>,<span class="hljs-string">"\x27<span class="hljs-subst">$s</span>\x27"</span>);<span class="hljs-meta">?></span> + <span class="hljs-meta"><?php</span> <span class="hljs-title function_ invoke__">printf</span>((<span class="hljs-keyword">isset</span>(<span class="hljs-variable">$s</span>)?<span class="hljs-function"><span class="hljs-keyword">fn</span>(<span class="hljs-params"><span class="hljs-variable">$s</span></span>)=></span><span class="hljs-title function_ invoke__">trim</span>(<span class="hljs-variable">$s</span>,<span class="hljs-string">""</span>):<span class="hljs-function"><span class="hljs-keyword">fn</span>(<span class="hljs-params"><span class="hljs-variable">$s</span></span>)=></span><span class="hljs-title function_ invoke__">chr</span>(<span class="hljs-title function_ invoke__">strlen</span>(<span class="hljs-variable">$s</span>)/<span class="hljs-number">3</span>))(<span class="hljs-variable">$s</span>=<span class="hljs-string">'<?php printf((isset($s)?fn($s)=>trim($s,""):fn($s)=>chr(strlen($s)/3))($s=%s)."\n","\x27$s\x27");?>'</span>).<span class="hljs-string">"\n"</span>,<span class="hljs-string">"\x27<span class="hljs-subst">$s</span>\x27"</span>);<span class="hljs-meta">?></span> + <span class="hljs-meta"><?php</span> <span class="hljs-title function_ invoke__">printf</span>((<span class="hljs-keyword">isset</span>(<span class="hljs-variable">$s</span>)?<span class="hljs-function"><span class="hljs-keyword">fn</span>(<span class="hljs-params"><span class="hljs-variable">$s</span></span>)=></span><span class="hljs-title function_ invoke__">trim</span>(<span class="hljs-variable">$s</span>,<span class="hljs-string">""</span>):<span class="hljs-function"><span class="hljs-keyword">fn</span>(<span class="hljs-params"><span class="hljs-variable">$s</span></span>)=></span><span class="hljs-title function_ invoke__">chr</span>(<span class="hljs-title function_ invoke__">strlen</span>(<span class="hljs-variable">$s</span>)/<span class="hljs-number">3</span>))(<span class="hljs-variable">$s</span>=<span class="hljs-string">'<?php printf((isset($s)?fn($s)=>trim($s,""):fn($s)=>chr(strlen($s)/3))($s=%s)."\n","\x27$s\x27");?>'</span>).<span class="hljs-string">"\n"</span>,<span class="hljs-string">"\x27<span class="hljs-subst">$s</span>\x27"</span>);<span class="hljs-meta">?></span> + <span class="hljs-meta"><?php</span> <span class="hljs-title function_ invoke__">printf</span>((<span class="hljs-keyword">isset</span>(<span class="hljs-variable">$s</span>)?<span class="hljs-function"><span class="hljs-keyword">fn</span>(<span class="hljs-params"><span class="hljs-variable">$s</span></span>)=></span><span class="hljs-title function_ invoke__">trim</span>(<span class="hljs-variable">$s</span>,<span class="hljs-string">""</span>):<span class="hljs-function"><span class="hljs-keyword">fn</span>(<span class="hljs-params"><span class="hljs-variable">$s</span></span>)=></span><span class="hljs-title function_ invoke__">chr</span>(<span class="hljs-title function_ invoke__">strlen</span>(<span class="hljs-variable">$s</span>)/<span class="hljs-number">3</span>))(<span class="hljs-variable">$s</span>=<span class="hljs-string">'<?php printf((isset($s)?fn($s)=>trim($s,""):fn($s)=>chr(strlen($s)/3))($s=%s)."\n","\x27$s\x27");?>'</span>).<span class="hljs-string">"\n"</span>,<span class="hljs-string">"\x27<span class="hljs-subst">$s</span>\x27"</span>);<span class="hljs-meta">?></span> + <span class="hljs-meta"><?php</span> <span class="hljs-title function_ invoke__">printf</span>((<span class="hljs-keyword">isset</span>(<span class="hljs-variable">$s</span>)?<span class="hljs-function"><span class="hljs-keyword">fn</span>(<span class="hljs-params"><span class="hljs-variable">$s</span></span>)=></span><span class="hljs-title function_ invoke__">trim</span>(<span class="hljs-variable">$s</span>,<span class="hljs-string">""</span>):<span class="hljs-function"><span class="hljs-keyword">fn</span>(<span class="hljs-params"><span class="hljs-variable">$s</span></span>)=></span><span class="hljs-title function_ invoke__">chr</span>(<span class="hljs-title function_ invoke__">strlen</span>(<span class="hljs-variable">$s</span>)/<span class="hljs-number">3</span>))(<span class="hljs-variable">$s</span>=<span class="hljs-string">'<?php printf((isset($s)?fn($s)=>trim($s,""):fn($s)=>chr(strlen($s)/3))($s=%s)."\n","\x27$s\x27");?>'</span>).<span class="hljs-string">"\n"</span>,<span class="hljs-string">"\x27<span class="hljs-subst">$s</span>\x27"</span>);<span class="hljs-meta">?></span> + <span class="hljs-meta"><?php</span> <span class="hljs-title function_ invoke__">printf</span>((<span class="hljs-keyword">isset</span>(<span class="hljs-variable">$s</span>)?<span class="hljs-function"><span class="hljs-keyword">fn</span>(<span class="hljs-params"><span class="hljs-variable">$s</span></span>)=></span><span class="hljs-title function_ invoke__">trim</span>(<span class="hljs-variable">$s</span>,<span class="hljs-string">""</span>):<span class="hljs-function"><span class="hljs-keyword">fn</span>(<span class="hljs-params"><span class="hljs-variable">$s</span></span>)=></span><span class="hljs-title function_ invoke__">chr</span>(<span class="hljs-title function_ invoke__">strlen</span>(<span class="hljs-variable">$s</span>)/<span class="hljs-number">3</span>))(<span class="hljs-variable">$s</span>=<span class="hljs-string">'<?php printf((isset($s)?fn($s)=>trim($s,""):fn($s)=>chr(strlen($s)/3))($s=%s)."\n","\x27$s\x27");?>'</span>).<span class="hljs-string">"\n"</span>,<span class="hljs-string">"\x27<span class="hljs-subst">$s</span>\x27"</span>);<span class="hljs-meta">?></span> + <span class="hljs-meta"><?php</span> <span class="hljs-title function_ invoke__">printf</span>((<span class="hljs-keyword">isset</span>(<span class="hljs-variable">$s</span>)?<span class="hljs-function"><span class="hljs-keyword">fn</span>(<span class="hljs-params"><span class="hljs-variable">$s</span></span>)=></span><span class="hljs-title function_ invoke__">trim</span>(<span class="hljs-variable">$s</span>,<span class="hljs-string">""</span>):<span class="hljs-function"><span class="hljs-keyword">fn</span>(<span class="hljs-params"><span class="hljs-variable">$s</span></span>)=></span><span class="hljs-title function_ invoke__">chr</span>(<span class="hljs-title function_ invoke__">strlen</span>(<span class="hljs-variable">$s</span>)/<span class="hljs-number">3</span>))(<span class="hljs-variable">$s</span>=<span class="hljs-string">'<?php printf((isset($s)?fn($s)=>trim($s,""):fn($s)=>chr(strlen($s)/3))($s=%s)."\n","\x27$s\x27");?>'</span>).<span class="hljs-string">"\n"</span>,<span class="hljs-string">"\x27<span class="hljs-subst">$s</span>\x27"</span>);<span class="hljs-meta">?></span> </code></pre> <p> @@ -106,42 +106,42 @@ 実行してみると、次のような出力が得られる。 </p> - <pre class="highlight" language="php" linenumbering="unnumbered"><code> - # - <?php printf((isset($s)?fn($s)=>trim($s,""):fn($s)=>chr(strlen($s)/3))($s='<?php printf((isset($s)?fn($s)=>trim($s,""):fn($s)=>chr(strlen($s)/3))($s=%s)."\n","\x27$s\x27");?>')."\n","\x27$s\x27");?> - <?php printf((isset($s)?fn($s)=>trim($s,""):fn($s)=>chr(strlen($s)/3))($s='<?php printf((isset($s)?fn($s)=>trim($s,""):fn($s)=>chr(strlen($s)/3))($s=%s)."\n","\x27$s\x27");?>')."\n","\x27$s\x27");?> - <?php printf((isset($s)?fn($s)=>trim($s,""):fn($s)=>chr(strlen($s)/3))($s='<?php printf((isset($s)?fn($s)=>trim($s,""):fn($s)=>chr(strlen($s)/3))($s=%s)."\n","\x27$s\x27");?>')."\n","\x27$s\x27");?> - <?php printf((isset($s)?fn($s)=>trim($s,""):fn($s)=>chr(strlen($s)/3))($s='<?php printf((isset($s)?fn($s)=>trim($s,""):fn($s)=>chr(strlen($s)/3))($s=%s)."\n","\x27$s\x27");?>')."\n","\x27$s\x27");?> - <?php printf((isset($s)?fn($s)=>trim($s,""):fn($s)=>chr(strlen($s)/3))($s='<?php printf((isset($s)?fn($s)=>trim($s,""):fn($s)=>chr(strlen($s)/3))($s=%s)."\n","\x27$s\x27");?>')."\n","\x27$s\x27");?> - <?php printf((isset($s)?fn($s)=>trim($s,""):fn($s)=>chr(strlen($s)/3))($s='<?php printf((isset($s)?fn($s)=>trim($s,""):fn($s)=>chr(strlen($s)/3))($s=%s)."\n","\x27$s\x27");?>')."\n","\x27$s\x27");?> - <?php printf((isset($s)?fn($s)=>trim($s,""):fn($s)=>chr(strlen($s)/3))($s='<?php printf((isset($s)?fn($s)=>trim($s,""):fn($s)=>chr(strlen($s)/3))($s=%s)."\n","\x27$s\x27");?>')."\n","\x27$s\x27");?> - <?php printf((isset($s)?fn($s)=>trim($s,""):fn($s)=>chr(strlen($s)/3))($s='<?php printf((isset($s)?fn($s)=>trim($s,""):fn($s)=>chr(strlen($s)/3))($s=%s)."\n","\x27$s\x27");?>')."\n","\x27$s\x27");?> - <?php printf((isset($s)?fn($s)=>trim($s,""):fn($s)=>chr(strlen($s)/3))($s='<?php printf((isset($s)?fn($s)=>trim($s,""):fn($s)=>chr(strlen($s)/3))($s=%s)."\n","\x27$s\x27");?>')."\n","\x27$s\x27");?> + <pre class="highlight" language="php" linenumbering="unnumbered"><code class="highlight"> + <span class="hljs-comment">#</span> + <span class="hljs-meta"><?php</span> <span class="hljs-title function_ invoke__">printf</span>((<span class="hljs-keyword">isset</span>(<span class="hljs-variable">$s</span>)?<span class="hljs-function"><span class="hljs-keyword">fn</span>(<span class="hljs-params"><span class="hljs-variable">$s</span></span>)=></span><span class="hljs-title function_ invoke__">trim</span>(<span class="hljs-variable">$s</span>,<span class="hljs-string">""</span>):<span class="hljs-function"><span class="hljs-keyword">fn</span>(<span class="hljs-params"><span class="hljs-variable">$s</span></span>)=></span><span class="hljs-title function_ invoke__">chr</span>(<span class="hljs-title function_ invoke__">strlen</span>(<span class="hljs-variable">$s</span>)/<span class="hljs-number">3</span>))(<span class="hljs-variable">$s</span>=<span class="hljs-string">'<?php printf((isset($s)?fn($s)=>trim($s,""):fn($s)=>chr(strlen($s)/3))($s=%s)."\n","\x27$s\x27");?>'</span>).<span class="hljs-string">"\n"</span>,<span class="hljs-string">"\x27<span class="hljs-subst">$s</span>\x27"</span>);<span class="hljs-meta">?></span> + <span class="hljs-meta"><?php</span> <span class="hljs-title function_ invoke__">printf</span>((<span class="hljs-keyword">isset</span>(<span class="hljs-variable">$s</span>)?<span class="hljs-function"><span class="hljs-keyword">fn</span>(<span class="hljs-params"><span class="hljs-variable">$s</span></span>)=></span><span class="hljs-title function_ invoke__">trim</span>(<span class="hljs-variable">$s</span>,<span class="hljs-string">""</span>):<span class="hljs-function"><span class="hljs-keyword">fn</span>(<span class="hljs-params"><span class="hljs-variable">$s</span></span>)=></span><span class="hljs-title function_ invoke__">chr</span>(<span class="hljs-title function_ invoke__">strlen</span>(<span class="hljs-variable">$s</span>)/<span class="hljs-number">3</span>))(<span class="hljs-variable">$s</span>=<span class="hljs-string">'<?php printf((isset($s)?fn($s)=>trim($s,""):fn($s)=>chr(strlen($s)/3))($s=%s)."\n","\x27$s\x27");?>'</span>).<span class="hljs-string">"\n"</span>,<span class="hljs-string">"\x27<span class="hljs-subst">$s</span>\x27"</span>);<span class="hljs-meta">?></span> + <span class="hljs-meta"><?php</span> <span class="hljs-title function_ invoke__">printf</span>((<span class="hljs-keyword">isset</span>(<span class="hljs-variable">$s</span>)?<span class="hljs-function"><span class="hljs-keyword">fn</span>(<span class="hljs-params"><span class="hljs-variable">$s</span></span>)=></span><span class="hljs-title function_ invoke__">trim</span>(<span class="hljs-variable">$s</span>,<span class="hljs-string">""</span>):<span class="hljs-function"><span class="hljs-keyword">fn</span>(<span class="hljs-params"><span class="hljs-variable">$s</span></span>)=></span><span class="hljs-title function_ invoke__">chr</span>(<span class="hljs-title function_ invoke__">strlen</span>(<span class="hljs-variable">$s</span>)/<span class="hljs-number">3</span>))(<span class="hljs-variable">$s</span>=<span class="hljs-string">'<?php printf((isset($s)?fn($s)=>trim($s,""):fn($s)=>chr(strlen($s)/3))($s=%s)."\n","\x27$s\x27");?>'</span>).<span class="hljs-string">"\n"</span>,<span class="hljs-string">"\x27<span class="hljs-subst">$s</span>\x27"</span>);<span class="hljs-meta">?></span> + <span class="hljs-meta"><?php</span> <span class="hljs-title function_ invoke__">printf</span>((<span class="hljs-keyword">isset</span>(<span class="hljs-variable">$s</span>)?<span class="hljs-function"><span class="hljs-keyword">fn</span>(<span class="hljs-params"><span class="hljs-variable">$s</span></span>)=></span><span class="hljs-title function_ invoke__">trim</span>(<span class="hljs-variable">$s</span>,<span class="hljs-string">""</span>):<span class="hljs-function"><span class="hljs-keyword">fn</span>(<span class="hljs-params"><span class="hljs-variable">$s</span></span>)=></span><span class="hljs-title function_ invoke__">chr</span>(<span class="hljs-title function_ invoke__">strlen</span>(<span class="hljs-variable">$s</span>)/<span class="hljs-number">3</span>))(<span class="hljs-variable">$s</span>=<span class="hljs-string">'<?php printf((isset($s)?fn($s)=>trim($s,""):fn($s)=>chr(strlen($s)/3))($s=%s)."\n","\x27$s\x27");?>'</span>).<span class="hljs-string">"\n"</span>,<span class="hljs-string">"\x27<span class="hljs-subst">$s</span>\x27"</span>);<span class="hljs-meta">?></span> + <span class="hljs-meta"><?php</span> <span class="hljs-title function_ invoke__">printf</span>((<span class="hljs-keyword">isset</span>(<span class="hljs-variable">$s</span>)?<span class="hljs-function"><span class="hljs-keyword">fn</span>(<span class="hljs-params"><span class="hljs-variable">$s</span></span>)=></span><span class="hljs-title function_ invoke__">trim</span>(<span class="hljs-variable">$s</span>,<span class="hljs-string">""</span>):<span class="hljs-function"><span class="hljs-keyword">fn</span>(<span class="hljs-params"><span class="hljs-variable">$s</span></span>)=></span><span class="hljs-title function_ invoke__">chr</span>(<span class="hljs-title function_ invoke__">strlen</span>(<span class="hljs-variable">$s</span>)/<span class="hljs-number">3</span>))(<span class="hljs-variable">$s</span>=<span class="hljs-string">'<?php printf((isset($s)?fn($s)=>trim($s,""):fn($s)=>chr(strlen($s)/3))($s=%s)."\n","\x27$s\x27");?>'</span>).<span class="hljs-string">"\n"</span>,<span class="hljs-string">"\x27<span class="hljs-subst">$s</span>\x27"</span>);<span class="hljs-meta">?></span> + <span class="hljs-meta"><?php</span> <span class="hljs-title function_ invoke__">printf</span>((<span class="hljs-keyword">isset</span>(<span class="hljs-variable">$s</span>)?<span class="hljs-function"><span class="hljs-keyword">fn</span>(<span class="hljs-params"><span class="hljs-variable">$s</span></span>)=></span><span class="hljs-title function_ invoke__">trim</span>(<span class="hljs-variable">$s</span>,<span class="hljs-string">""</span>):<span class="hljs-function"><span class="hljs-keyword">fn</span>(<span class="hljs-params"><span class="hljs-variable">$s</span></span>)=></span><span class="hljs-title function_ invoke__">chr</span>(<span class="hljs-title function_ invoke__">strlen</span>(<span class="hljs-variable">$s</span>)/<span class="hljs-number">3</span>))(<span class="hljs-variable">$s</span>=<span class="hljs-string">'<?php printf((isset($s)?fn($s)=>trim($s,""):fn($s)=>chr(strlen($s)/3))($s=%s)."\n","\x27$s\x27");?>'</span>).<span class="hljs-string">"\n"</span>,<span class="hljs-string">"\x27<span class="hljs-subst">$s</span>\x27"</span>);<span class="hljs-meta">?></span> + <span class="hljs-meta"><?php</span> <span class="hljs-title function_ invoke__">printf</span>((<span class="hljs-keyword">isset</span>(<span class="hljs-variable">$s</span>)?<span class="hljs-function"><span class="hljs-keyword">fn</span>(<span class="hljs-params"><span class="hljs-variable">$s</span></span>)=></span><span class="hljs-title function_ invoke__">trim</span>(<span class="hljs-variable">$s</span>,<span class="hljs-string">""</span>):<span class="hljs-function"><span class="hljs-keyword">fn</span>(<span class="hljs-params"><span class="hljs-variable">$s</span></span>)=></span><span class="hljs-title function_ invoke__">chr</span>(<span class="hljs-title function_ invoke__">strlen</span>(<span class="hljs-variable">$s</span>)/<span class="hljs-number">3</span>))(<span class="hljs-variable">$s</span>=<span class="hljs-string">'<?php printf((isset($s)?fn($s)=>trim($s,""):fn($s)=>chr(strlen($s)/3))($s=%s)."\n","\x27$s\x27");?>'</span>).<span class="hljs-string">"\n"</span>,<span class="hljs-string">"\x27<span class="hljs-subst">$s</span>\x27"</span>);<span class="hljs-meta">?></span> + <span class="hljs-meta"><?php</span> <span class="hljs-title function_ invoke__">printf</span>((<span class="hljs-keyword">isset</span>(<span class="hljs-variable">$s</span>)?<span class="hljs-function"><span class="hljs-keyword">fn</span>(<span class="hljs-params"><span class="hljs-variable">$s</span></span>)=></span><span class="hljs-title function_ invoke__">trim</span>(<span class="hljs-variable">$s</span>,<span class="hljs-string">""</span>):<span class="hljs-function"><span class="hljs-keyword">fn</span>(<span class="hljs-params"><span class="hljs-variable">$s</span></span>)=></span><span class="hljs-title function_ invoke__">chr</span>(<span class="hljs-title function_ invoke__">strlen</span>(<span class="hljs-variable">$s</span>)/<span class="hljs-number">3</span>))(<span class="hljs-variable">$s</span>=<span class="hljs-string">'<?php printf((isset($s)?fn($s)=>trim($s,""):fn($s)=>chr(strlen($s)/3))($s=%s)."\n","\x27$s\x27");?>'</span>).<span class="hljs-string">"\n"</span>,<span class="hljs-string">"\x27<span class="hljs-subst">$s</span>\x27"</span>);<span class="hljs-meta">?></span> + <span class="hljs-meta"><?php</span> <span class="hljs-title function_ invoke__">printf</span>((<span class="hljs-keyword">isset</span>(<span class="hljs-variable">$s</span>)?<span class="hljs-function"><span class="hljs-keyword">fn</span>(<span class="hljs-params"><span class="hljs-variable">$s</span></span>)=></span><span class="hljs-title function_ invoke__">trim</span>(<span class="hljs-variable">$s</span>,<span class="hljs-string">""</span>):<span class="hljs-function"><span class="hljs-keyword">fn</span>(<span class="hljs-params"><span class="hljs-variable">$s</span></span>)=></span><span class="hljs-title function_ invoke__">chr</span>(<span class="hljs-title function_ invoke__">strlen</span>(<span class="hljs-variable">$s</span>)/<span class="hljs-number">3</span>))(<span class="hljs-variable">$s</span>=<span class="hljs-string">'<?php printf((isset($s)?fn($s)=>trim($s,""):fn($s)=>chr(strlen($s)/3))($s=%s)."\n","\x27$s\x27");?>'</span>).<span class="hljs-string">"\n"</span>,<span class="hljs-string">"\x27<span class="hljs-subst">$s</span>\x27"</span>);<span class="hljs-meta">?></span> </code></pre> <p> 1 行目を除き、先ほどのコードとほぼ同じものが出てきた。もう一度実行してみる。 </p> - <pre class="highlight" language="php" linenumbering="unnumbered"><code> - # + <pre class="highlight" language="php" linenumbering="unnumbered"><code class="highlight"> + <span class="hljs-comment">#</span> W -<?php printf((isset($s)?fn($s)=>trim($s,""):fn($s)=>chr(strlen($s)/3))($s='<?php printf((isset($s)?fn($s)=>trim($s,""):fn($s)=>chr(strlen($s)/3))($s=%s)."\n","\x27$s\x27");?>')."\n","\x27$s\x27");?> -<?php printf((isset($s)?fn($s)=>trim($s,""):fn($s)=>chr(strlen($s)/3))($s='<?php printf((isset($s)?fn($s)=>trim($s,""):fn($s)=>chr(strlen($s)/3))($s=%s)."\n","\x27$s\x27");?>')."\n","\x27$s\x27");?> -<?php printf((isset($s)?fn($s)=>trim($s,""):fn($s)=>chr(strlen($s)/3))($s='<?php printf((isset($s)?fn($s)=>trim($s,""):fn($s)=>chr(strlen($s)/3))($s=%s)."\n","\x27$s\x27");?>')."\n","\x27$s\x27");?> -<?php printf((isset($s)?fn($s)=>trim($s,""):fn($s)=>chr(strlen($s)/3))($s='<?php printf((isset($s)?fn($s)=>trim($s,""):fn($s)=>chr(strlen($s)/3))($s=%s)."\n","\x27$s\x27");?>')."\n","\x27$s\x27");?> -<?php printf((isset($s)?fn($s)=>trim($s,""):fn($s)=>chr(strlen($s)/3))($s='<?php printf((isset($s)?fn($s)=>trim($s,""):fn($s)=>chr(strlen($s)/3))($s=%s)."\n","\x27$s\x27");?>')."\n","\x27$s\x27");?> -<?php printf((isset($s)?fn($s)=>trim($s,""):fn($s)=>chr(strlen($s)/3))($s='<?php printf((isset($s)?fn($s)=>trim($s,""):fn($s)=>chr(strlen($s)/3))($s=%s)."\n","\x27$s\x27");?>')."\n","\x27$s\x27");?> -<?php printf((isset($s)?fn($s)=>trim($s,""):fn($s)=>chr(strlen($s)/3))($s='<?php printf((isset($s)?fn($s)=>trim($s,""):fn($s)=>chr(strlen($s)/3))($s=%s)."\n","\x27$s\x27");?>')."\n","\x27$s\x27");?> - <?php printf((isset($s)?fn($s)=>trim($s,""):fn($s)=>chr(strlen($s)/3))($s='<?php printf((isset($s)?fn($s)=>trim($s,""):fn($s)=>chr(strlen($s)/3))($s=%s)."\n","\x27$s\x27");?>')."\n","\x27$s\x27");?> +<span class="hljs-meta"><?php</span> <span class="hljs-title function_ invoke__">printf</span>((<span class="hljs-keyword">isset</span>(<span class="hljs-variable">$s</span>)?<span class="hljs-function"><span class="hljs-keyword">fn</span>(<span class="hljs-params"><span class="hljs-variable">$s</span></span>)=></span><span class="hljs-title function_ invoke__">trim</span>(<span class="hljs-variable">$s</span>,<span class="hljs-string">""</span>):<span class="hljs-function"><span class="hljs-keyword">fn</span>(<span class="hljs-params"><span class="hljs-variable">$s</span></span>)=></span><span class="hljs-title function_ invoke__">chr</span>(<span class="hljs-title function_ invoke__">strlen</span>(<span class="hljs-variable">$s</span>)/<span class="hljs-number">3</span>))(<span class="hljs-variable">$s</span>=<span class="hljs-string">'<?php printf((isset($s)?fn($s)=>trim($s,""):fn($s)=>chr(strlen($s)/3))($s=%s)."\n","\x27$s\x27");?>'</span>).<span class="hljs-string">"\n"</span>,<span class="hljs-string">"\x27<span class="hljs-subst">$s</span>\x27"</span>);<span class="hljs-meta">?></span> +<span class="hljs-meta"><?php</span> <span class="hljs-title function_ invoke__">printf</span>((<span class="hljs-keyword">isset</span>(<span class="hljs-variable">$s</span>)?<span class="hljs-function"><span class="hljs-keyword">fn</span>(<span class="hljs-params"><span class="hljs-variable">$s</span></span>)=></span><span class="hljs-title function_ invoke__">trim</span>(<span class="hljs-variable">$s</span>,<span class="hljs-string">""</span>):<span class="hljs-function"><span class="hljs-keyword">fn</span>(<span class="hljs-params"><span class="hljs-variable">$s</span></span>)=></span><span class="hljs-title function_ invoke__">chr</span>(<span class="hljs-title function_ invoke__">strlen</span>(<span class="hljs-variable">$s</span>)/<span class="hljs-number">3</span>))(<span class="hljs-variable">$s</span>=<span class="hljs-string">'<?php printf((isset($s)?fn($s)=>trim($s,""):fn($s)=>chr(strlen($s)/3))($s=%s)."\n","\x27$s\x27");?>'</span>).<span class="hljs-string">"\n"</span>,<span class="hljs-string">"\x27<span class="hljs-subst">$s</span>\x27"</span>);<span class="hljs-meta">?></span> +<span class="hljs-meta"><?php</span> <span class="hljs-title function_ invoke__">printf</span>((<span class="hljs-keyword">isset</span>(<span class="hljs-variable">$s</span>)?<span class="hljs-function"><span class="hljs-keyword">fn</span>(<span class="hljs-params"><span class="hljs-variable">$s</span></span>)=></span><span class="hljs-title function_ invoke__">trim</span>(<span class="hljs-variable">$s</span>,<span class="hljs-string">""</span>):<span class="hljs-function"><span class="hljs-keyword">fn</span>(<span class="hljs-params"><span class="hljs-variable">$s</span></span>)=></span><span class="hljs-title function_ invoke__">chr</span>(<span class="hljs-title function_ invoke__">strlen</span>(<span class="hljs-variable">$s</span>)/<span class="hljs-number">3</span>))(<span class="hljs-variable">$s</span>=<span class="hljs-string">'<?php printf((isset($s)?fn($s)=>trim($s,""):fn($s)=>chr(strlen($s)/3))($s=%s)."\n","\x27$s\x27");?>'</span>).<span class="hljs-string">"\n"</span>,<span class="hljs-string">"\x27<span class="hljs-subst">$s</span>\x27"</span>);<span class="hljs-meta">?></span> +<span class="hljs-meta"><?php</span> <span class="hljs-title function_ invoke__">printf</span>((<span class="hljs-keyword">isset</span>(<span class="hljs-variable">$s</span>)?<span class="hljs-function"><span class="hljs-keyword">fn</span>(<span class="hljs-params"><span class="hljs-variable">$s</span></span>)=></span><span class="hljs-title function_ invoke__">trim</span>(<span class="hljs-variable">$s</span>,<span class="hljs-string">""</span>):<span class="hljs-function"><span class="hljs-keyword">fn</span>(<span class="hljs-params"><span class="hljs-variable">$s</span></span>)=></span><span class="hljs-title function_ invoke__">chr</span>(<span class="hljs-title function_ invoke__">strlen</span>(<span class="hljs-variable">$s</span>)/<span class="hljs-number">3</span>))(<span class="hljs-variable">$s</span>=<span class="hljs-string">'<?php printf((isset($s)?fn($s)=>trim($s,""):fn($s)=>chr(strlen($s)/3))($s=%s)."\n","\x27$s\x27");?>'</span>).<span class="hljs-string">"\n"</span>,<span class="hljs-string">"\x27<span class="hljs-subst">$s</span>\x27"</span>);<span class="hljs-meta">?></span> +<span class="hljs-meta"><?php</span> <span class="hljs-title function_ invoke__">printf</span>((<span class="hljs-keyword">isset</span>(<span class="hljs-variable">$s</span>)?<span class="hljs-function"><span class="hljs-keyword">fn</span>(<span class="hljs-params"><span class="hljs-variable">$s</span></span>)=></span><span class="hljs-title function_ invoke__">trim</span>(<span class="hljs-variable">$s</span>,<span class="hljs-string">""</span>):<span class="hljs-function"><span class="hljs-keyword">fn</span>(<span class="hljs-params"><span class="hljs-variable">$s</span></span>)=></span><span class="hljs-title function_ invoke__">chr</span>(<span class="hljs-title function_ invoke__">strlen</span>(<span class="hljs-variable">$s</span>)/<span class="hljs-number">3</span>))(<span class="hljs-variable">$s</span>=<span class="hljs-string">'<?php printf((isset($s)?fn($s)=>trim($s,""):fn($s)=>chr(strlen($s)/3))($s=%s)."\n","\x27$s\x27");?>'</span>).<span class="hljs-string">"\n"</span>,<span class="hljs-string">"\x27<span class="hljs-subst">$s</span>\x27"</span>);<span class="hljs-meta">?></span> +<span class="hljs-meta"><?php</span> <span class="hljs-title function_ invoke__">printf</span>((<span class="hljs-keyword">isset</span>(<span class="hljs-variable">$s</span>)?<span class="hljs-function"><span class="hljs-keyword">fn</span>(<span class="hljs-params"><span class="hljs-variable">$s</span></span>)=></span><span class="hljs-title function_ invoke__">trim</span>(<span class="hljs-variable">$s</span>,<span class="hljs-string">""</span>):<span class="hljs-function"><span class="hljs-keyword">fn</span>(<span class="hljs-params"><span class="hljs-variable">$s</span></span>)=></span><span class="hljs-title function_ invoke__">chr</span>(<span class="hljs-title function_ invoke__">strlen</span>(<span class="hljs-variable">$s</span>)/<span class="hljs-number">3</span>))(<span class="hljs-variable">$s</span>=<span class="hljs-string">'<?php printf((isset($s)?fn($s)=>trim($s,""):fn($s)=>chr(strlen($s)/3))($s=%s)."\n","\x27$s\x27");?>'</span>).<span class="hljs-string">"\n"</span>,<span class="hljs-string">"\x27<span class="hljs-subst">$s</span>\x27"</span>);<span class="hljs-meta">?></span> +<span class="hljs-meta"><?php</span> <span class="hljs-title function_ invoke__">printf</span>((<span class="hljs-keyword">isset</span>(<span class="hljs-variable">$s</span>)?<span class="hljs-function"><span class="hljs-keyword">fn</span>(<span class="hljs-params"><span class="hljs-variable">$s</span></span>)=></span><span class="hljs-title function_ invoke__">trim</span>(<span class="hljs-variable">$s</span>,<span class="hljs-string">""</span>):<span class="hljs-function"><span class="hljs-keyword">fn</span>(<span class="hljs-params"><span class="hljs-variable">$s</span></span>)=></span><span class="hljs-title function_ invoke__">chr</span>(<span class="hljs-title function_ invoke__">strlen</span>(<span class="hljs-variable">$s</span>)/<span class="hljs-number">3</span>))(<span class="hljs-variable">$s</span>=<span class="hljs-string">'<?php printf((isset($s)?fn($s)=>trim($s,""):fn($s)=>chr(strlen($s)/3))($s=%s)."\n","\x27$s\x27");?>'</span>).<span class="hljs-string">"\n"</span>,<span class="hljs-string">"\x27<span class="hljs-subst">$s</span>\x27"</span>);<span class="hljs-meta">?></span> + <span class="hljs-meta"><?php</span> <span class="hljs-title function_ invoke__">printf</span>((<span class="hljs-keyword">isset</span>(<span class="hljs-variable">$s</span>)?<span class="hljs-function"><span class="hljs-keyword">fn</span>(<span class="hljs-params"><span class="hljs-variable">$s</span></span>)=></span><span class="hljs-title function_ invoke__">trim</span>(<span class="hljs-variable">$s</span>,<span class="hljs-string">""</span>):<span class="hljs-function"><span class="hljs-keyword">fn</span>(<span class="hljs-params"><span class="hljs-variable">$s</span></span>)=></span><span class="hljs-title function_ invoke__">chr</span>(<span class="hljs-title function_ invoke__">strlen</span>(<span class="hljs-variable">$s</span>)/<span class="hljs-number">3</span>))(<span class="hljs-variable">$s</span>=<span class="hljs-string">'<?php printf((isset($s)?fn($s)=>trim($s,""):fn($s)=>chr(strlen($s)/3))($s=%s)."\n","\x27$s\x27");?>'</span>).<span class="hljs-string">"\n"</span>,<span class="hljs-string">"\x27<span class="hljs-subst">$s</span>\x27"</span>);<span class="hljs-meta">?></span> </code></pre> <p> 今度は 2 行目が書き換えられた。すべての行が変化するまで繰り返すと次のようになる。 </p> - <pre class="highlight" language="php" linenumbering="unnumbered"><code> - # + <pre class="highlight" language="php" linenumbering="unnumbered"><code class="highlight"> + <span class="hljs-comment">#</span> W E L @@ -168,8 +168,8 @@ W Vim で開くと次のようになる (1 行目を抜粋)。 </p> - <pre class="highlight" language="php" linenumbering="unnumbered"><code> - <?php printf((isset($s)?fn($s)=>trim($s,"<200b>"):fn($s)=>chr(strlen($s)/3))($s='<200b><?php printf((isset($s)?fn($s)=>trim($s,"<200b>"):fn($s)=>chr(strlen($s)/3))($s=%s)."\n","\x27$s\x27");?>')."\n","\x27$s\x27");?> + <pre class="highlight" language="php" linenumbering="unnumbered"><code class="highlight"> + <span class="hljs-meta"><?php</span> <span class="hljs-title function_ invoke__">printf</span>((<span class="hljs-keyword">isset</span>(<span class="hljs-variable">$s</span>)?<span class="hljs-function"><span class="hljs-keyword">fn</span>(<span class="hljs-params"><span class="hljs-variable">$s</span></span>)=></span><span class="hljs-title function_ invoke__">trim</span>(<span class="hljs-variable">$s</span>,<span class="hljs-string">"<200b>"</span>):<span class="hljs-function"><span class="hljs-keyword">fn</span>(<span class="hljs-params"><span class="hljs-variable">$s</span></span>)=></span><span class="hljs-title function_ invoke__">chr</span>(<span class="hljs-title function_ invoke__">strlen</span>(<span class="hljs-variable">$s</span>)/<span class="hljs-number">3</span>))(<span class="hljs-variable">$s</span>=<span class="hljs-string">'<200b><?php printf((isset($s)?fn($s)=>trim($s,"<200b>"):fn($s)=>chr(strlen($s)/3))($s=%s)."\n","\x27$s\x27");?>'</span>).<span class="hljs-string">"\n"</span>,<span class="hljs-string">"\x27<span class="hljs-subst">$s</span>\x27"</span>);<span class="hljs-meta">?></span> </code></pre> <p> @@ -195,16 +195,16 @@ W 続いて、トークンへの変換ロジックを解析する。注目すべきはこの部分だ。以下、ゼロ幅スペースは Vim での表示に合わせて<code><200b></code>と記載する。 </p> - <pre class="highlight" language="php" linenumbering="unnumbered"><code> - fn($s)=>chr(strlen($s)/3) + <pre class="highlight" language="php" linenumbering="unnumbered"><code class="highlight"> + <span class="hljs-function"><span class="hljs-keyword">fn</span>(<span class="hljs-params"><span class="hljs-variable">$s</span></span>)=></span><span class="hljs-title function_ invoke__">chr</span>(<span class="hljs-title function_ invoke__">strlen</span>(<span class="hljs-variable">$s</span>)/<span class="hljs-number">3</span>) </code></pre> <p> PHP の<code>strlen()</code>は文字列のバイト数を返す。1 行目の<code>$s</code>は以下の内容となっており、 </p> - <pre class="highlight" language="php" linenumbering="unnumbered"><code> - $s='<200b><?php printf((isset($s)?fn($s)=>trim($s,"<200b>"):fn($s)=>chr(strlen($s)/3))($s=%s)."\n","\x27$s\x27");?>' + <pre class="highlight" language="php" linenumbering="unnumbered"><code class="highlight"> + <span class="hljs-variable">$s</span>=<span class="hljs-string">'<200b><?php printf((isset($s)?fn($s)=>trim($s,"<200b>"):fn($s)=>chr(strlen($s)/3))($s=%s)."\n","\x27$s\x27");?>'</span> </code></pre> <p> diff --git a/public/posts/2023-01-10/phperkaigi-2023-unused-token-quiz-3/index.html b/public/posts/2023-01-10/phperkaigi-2023-unused-token-quiz-3/index.html index ab47b2b..61d9880 100644 --- a/public/posts/2023-01-10/phperkaigi-2023-unused-token-quiz-3/index.html +++ b/public/posts/2023-01-10/phperkaigi-2023-unused-token-quiz-3/index.html @@ -10,7 +10,7 @@ <link rel="icon" type="image/svg+xml" href="/favicon.svg"> <title>PHPerKaigi 2023: ボツになったトークン問題 その 3 | REPL: Rest-Eat-Program Loop</title> <link rel="stylesheet" href="/style.css?h=17cf97a767ec5fb6e64967729f40f30a"> - <link rel="stylesheet" href="/hl.css?h=208c52e3b7c9db1cad782c5d30b4698f"> + <link rel="stylesheet" href="/hl.css?h=340e65ffd5c17713efc9107c06304f7b"> </head> <body class="single"> <header class="header"> @@ -92,24 +92,24 @@ 注意: これはボツ問なので、得られたトークンを PHPerKaigi で入力してもポイントにはならない。 </p> - <pre class="highlight" language="php" linenumbering="unnumbered"><code><?php -try { - f(g() / __LINE__); -} catch (Throwable $e) { - while ($e = $e->getPrevious()) printf('%c', $e->getLine() + 23); - echo "\n"; + <pre class="highlight" language="php" linenumbering="unnumbered"><code class="highlight"><span class="hljs-meta"><?php</span> +<span class="hljs-keyword">try</span> { + <span class="hljs-title function_ invoke__">f</span>(<span class="hljs-title function_ invoke__">g</span>() / <span class="hljs-keyword">__LINE__</span>); +} <span class="hljs-keyword">catch</span> (<span class="hljs-built_in">Throwable</span> <span class="hljs-variable">$e</span>) { + <span class="hljs-keyword">while</span> (<span class="hljs-variable">$e</span> = <span class="hljs-variable">$e</span>-><span class="hljs-title function_ invoke__">getPrevious</span>()) <span class="hljs-title function_ invoke__">printf</span>(<span class="hljs-string">'%c'</span>, <span class="hljs-variable">$e</span>-><span class="hljs-title function_ invoke__">getLine</span>() + <span class="hljs-number">23</span>); + <span class="hljs-keyword">echo</span> <span class="hljs-string">"\n"</span>; } -function f(int $i) { - if ($i < 0) f(); - try { - match ($i) { - 0 => 0 / 0, +<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">f</span>(<span class="hljs-params"><span class="hljs-keyword">int</span> <span class="hljs-variable">$i</span></span>) </span>{ + <span class="hljs-keyword">if</span> (<span class="hljs-variable">$i</span> < <span class="hljs-number">0</span>) <span class="hljs-title function_ invoke__">f</span>(); + <span class="hljs-keyword">try</span> { + <span class="hljs-keyword">match</span> (<span class="hljs-variable">$i</span>) { + <span class="hljs-number">0</span> => <span class="hljs-number">0</span> / <span class="hljs-number">0</span>, - 15, 36 => 0 / 0, - 14 => 0 / 0, - 37 => 0 / 0, + <span class="hljs-number">15</span>, <span class="hljs-number">36</span> => <span class="hljs-number">0</span> / <span class="hljs-number">0</span>, + <span class="hljs-number">14</span> => <span class="hljs-number">0</span> / <span class="hljs-number">0</span>, + <span class="hljs-number">37</span> => <span class="hljs-number">0</span> / <span class="hljs-number">0</span>, @@ -120,16 +120,16 @@ function f(int $i) { - 6 => 0 / 0, + <span class="hljs-number">6</span> => <span class="hljs-number">0</span> / <span class="hljs-number">0</span>, - 5 => 0 / 0, + <span class="hljs-number">5</span> => <span class="hljs-number">0</span> / <span class="hljs-number">0</span>, - 22 => 0 / 0, + <span class="hljs-number">22</span> => <span class="hljs-number">0</span> / <span class="hljs-number">0</span>, - 34, 35 => 0 / 0, + <span class="hljs-number">34</span>, <span class="hljs-number">35</span> => <span class="hljs-number">0</span> / <span class="hljs-number">0</span>, @@ -138,10 +138,10 @@ function f(int $i) { - 25 => 0 / 0, - 17, 21 => 0 / 0, + <span class="hljs-number">25</span> => <span class="hljs-number">0</span> / <span class="hljs-number">0</span>, + <span class="hljs-number">17</span>, <span class="hljs-number">21</span> => <span class="hljs-number">0</span> / <span class="hljs-number">0</span>, - 24, 32 => 0 / 0, + <span class="hljs-number">24</span>, <span class="hljs-number">32</span> => <span class="hljs-number">0</span> / <span class="hljs-number">0</span>, @@ -149,12 +149,12 @@ function f(int $i) { - 33 => 0 / 0, + <span class="hljs-number">33</span> => <span class="hljs-number">0</span> / <span class="hljs-number">0</span>, - 16 => 0 / 0, + <span class="hljs-number">16</span> => <span class="hljs-number">0</span> / <span class="hljs-number">0</span>, - 18 => 0 / 0, + <span class="hljs-number">18</span> => <span class="hljs-number">0</span> / <span class="hljs-number">0</span>, @@ -163,35 +163,35 @@ function f(int $i) { - 7 => 0 / 0, + <span class="hljs-number">7</span> => <span class="hljs-number">0</span> / <span class="hljs-number">0</span>, - 2 => 0 / 0, - 1, 20 => 0 / 0, - 10, 28 => 0 / 0, - 8, 12, 26 => 0 / 0, - 4, 9, 13 => 0 / 0, + <span class="hljs-number">2</span> => <span class="hljs-number">0</span> / <span class="hljs-number">0</span>, + <span class="hljs-number">1</span>, <span class="hljs-number">20</span> => <span class="hljs-number">0</span> / <span class="hljs-number">0</span>, + <span class="hljs-number">10</span>, <span class="hljs-number">28</span> => <span class="hljs-number">0</span> / <span class="hljs-number">0</span>, + <span class="hljs-number">8</span>, <span class="hljs-number">12</span>, <span class="hljs-number">26</span> => <span class="hljs-number">0</span> / <span class="hljs-number">0</span>, + <span class="hljs-number">4</span>, <span class="hljs-number">9</span>, <span class="hljs-number">13</span> => <span class="hljs-number">0</span> / <span class="hljs-number">0</span>, - 31 => 0 / 0, + <span class="hljs-number">31</span> => <span class="hljs-number">0</span> / <span class="hljs-number">0</span>, - 29 => 0 / 0, + <span class="hljs-number">29</span> => <span class="hljs-number">0</span> / <span class="hljs-number">0</span>, - 11 => 0 / 0, + <span class="hljs-number">11</span> => <span class="hljs-number">0</span> / <span class="hljs-number">0</span>, - 3, 19, 23 => 0 / 0, + <span class="hljs-number">3</span>, <span class="hljs-number">19</span>, <span class="hljs-number">23</span> => <span class="hljs-number">0</span> / <span class="hljs-number">0</span>, - 27 => 0 / 0, + <span class="hljs-number">27</span> => <span class="hljs-number">0</span> / <span class="hljs-number">0</span>, - 30 => 0 / 0, + <span class="hljs-number">30</span> => <span class="hljs-number">0</span> / <span class="hljs-number">0</span>, }; - } finally { - f($i - 1); + } <span class="hljs-keyword">finally</span> { + <span class="hljs-title function_ invoke__">f</span>(<span class="hljs-variable">$i</span> - <span class="hljs-number">1</span>); } } @@ -201,8 +201,8 @@ function f(int $i) { -function g() { - return __LINE__; +<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">g</span>(<span class="hljs-params"></span>) </span>{ + <span class="hljs-keyword">return</span> <span class="hljs-keyword">__LINE__</span>; }</code></pre> <p> @@ -247,19 +247,19 @@ function g() { このうち 1つ目のケースは、<code>finally</code>節の中でエラーを投げると PHP 処理系が勝手に<code>$previous</code>を設定してくれる。 </p> - <pre class="highlight" language="php" linenumbering="unnumbered"><code><?php + <pre class="highlight" language="php" linenumbering="unnumbered"><code class="highlight"><span class="hljs-meta"><?php</span> -try { - try { - throw new Exception("Error 1"); - } finally { - throw new Exception("Error 2"); +<span class="hljs-keyword">try</span> { + <span class="hljs-keyword">try</span> { + <span class="hljs-keyword">throw</span> <span class="hljs-keyword">new</span> <span class="hljs-built_in">Exception</span>(<span class="hljs-string">"Error 1"</span>); + } <span class="hljs-keyword">finally</span> { + <span class="hljs-keyword">throw</span> <span class="hljs-keyword">new</span> <span class="hljs-built_in">Exception</span>(<span class="hljs-string">"Error 2"</span>); } -} catch (Exception $e) { - echo $e->getMessage() . PHP_EOL; - // => Error 2 - echo $e->getPrevious()->getMessage() . PHP_EOL; - // => Error 1 +} <span class="hljs-keyword">catch</span> (<span class="hljs-built_in">Exception</span> <span class="hljs-variable">$e</span>) { + <span class="hljs-keyword">echo</span> <span class="hljs-variable">$e</span>-><span class="hljs-title function_ invoke__">getMessage</span>() . PHP_EOL; + <span class="hljs-comment">// => Error 2</span> + <span class="hljs-keyword">echo</span> <span class="hljs-variable">$e</span>-><span class="hljs-title function_ invoke__">getPrevious</span>()-><span class="hljs-title function_ invoke__">getMessage</span>() . PHP_EOL; + <span class="hljs-comment">// => Error 1</span> }</code></pre> <p> @@ -273,14 +273,14 @@ try { 出力部をコメントや改行を追加して再掲する: </p> - <pre class="highlight" language="php" linenumbering="unnumbered"><code><?php -try { - f(g() / __LINE__); -} catch (Throwable $e) { - while ($e = $e->getPrevious()) { - printf('%c', $e->getLine() + 23); + <pre class="highlight" language="php" linenumbering="unnumbered"><code class="highlight"><span class="hljs-meta"><?php</span> +<span class="hljs-keyword">try</span> { + <span class="hljs-title function_ invoke__">f</span>(<span class="hljs-title function_ invoke__">g</span>() / <span class="hljs-keyword">__LINE__</span>); +} <span class="hljs-keyword">catch</span> (<span class="hljs-built_in">Throwable</span> <span class="hljs-variable">$e</span>) { + <span class="hljs-keyword">while</span> (<span class="hljs-variable">$e</span> = <span class="hljs-variable">$e</span>-><span class="hljs-title function_ invoke__">getPrevious</span>()) { + <span class="hljs-title function_ invoke__">printf</span>(<span class="hljs-string">'%c'</span>, <span class="hljs-variable">$e</span>-><span class="hljs-title function_ invoke__">getLine</span>() + <span class="hljs-number">23</span>); } - echo "\n"; + <span class="hljs-keyword">echo</span> <span class="hljs-string">"\n"</span>; }</code></pre> <p> @@ -291,7 +291,7 @@ try { フォーマット指定子<code>%c</code>は、整数を ASCII コード<span></span>と見做して印字する。トークン<code>#base64_decode('SGVsbG8sIFdvcmxkIQ==')</code>の<code>b</code>であれば、ASCII コード<code>98</code>なので、75 行目で発生したエラー、 </p> - <pre class="highlight" language="php" linenumbering="unnumbered"><code>1, 20 => 0 / 0,</code></pre> + <pre class="highlight" language="php" linenumbering="unnumbered"><code class="highlight"><span class="hljs-number">1</span>, <span class="hljs-number">20</span> => <span class="hljs-number">0</span> / <span class="hljs-number">0</span>,</code></pre> <p> によって表現されている。エラーを起こす方法はいろいろと考えられるが、今回はゼロ除算を使った。 @@ -308,24 +308,24 @@ try { <code>f()</code>の定義を再掲する (エラーオブジェクトの行数を利用しているので、一部分だけ抜き出すと値が変わることに注意): </p> - <pre class="highlight" language="php" linenumbering="unnumbered"><code>function f(int $i) { - if ($i < 0) f(); - try { - match ($i) { - 0 => 0 / 0, // 12 行目 + <pre class="highlight" language="php" linenumbering="unnumbered"><code class="highlight"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">f</span>(<span class="hljs-params"><span class="hljs-keyword">int</span> <span class="hljs-variable">$i</span></span>) </span>{ + <span class="hljs-keyword">if</span> (<span class="hljs-variable">$i</span> < <span class="hljs-number">0</span>) <span class="hljs-title function_ invoke__">f</span>(); + <span class="hljs-keyword">try</span> { + <span class="hljs-keyword">match</span> (<span class="hljs-variable">$i</span>) { + <span class="hljs-number">0</span> => <span class="hljs-number">0</span> / <span class="hljs-number">0</span>, <span class="hljs-comment">// 12 行目</span> - 15, 36 => 0 / 0, - 14 => 0 / 0, - 37 => 0 / 0, + <span class="hljs-number">15</span>, <span class="hljs-number">36</span> => <span class="hljs-number">0</span> / <span class="hljs-number">0</span>, + <span class="hljs-number">14</span> => <span class="hljs-number">0</span> / <span class="hljs-number">0</span>, + <span class="hljs-number">37</span> => <span class="hljs-number">0</span> / <span class="hljs-number">0</span>, - // (略) + <span class="hljs-comment">// (略)</span> - 30 => 0 / 0, // 97 行目 + <span class="hljs-number">30</span> => <span class="hljs-number">0</span> / <span class="hljs-number">0</span>, <span class="hljs-comment">// 97 行目</span> }; - } finally { - f($i - 1); + } <span class="hljs-keyword">finally</span> { + <span class="hljs-title function_ invoke__">f</span>(<span class="hljs-variable">$i</span> - <span class="hljs-number">1</span>); } }</code></pre> @@ -333,12 +333,12 @@ try { 前述のように、<code>finally</code>節でエラーを投げると PHP 処理系が<code>$previous</code>を設定する。ここでは、エラーを繋げるために<code>f()</code>を再帰呼び出ししている。最初に<code>f()</code>を呼び出している箇所を確認すると、 </p> - <pre class="highlight" language="php" linenumbering="unnumbered"><code><?php -try { - f(g() / __LINE__); // 3 行目</code></pre> + <pre class="highlight" language="php" linenumbering="unnumbered"><code class="highlight"><span class="hljs-meta"><?php</span> +<span class="hljs-keyword">try</span> { + <span class="hljs-title function_ invoke__">f</span>(<span class="hljs-title function_ invoke__">g</span>() / <span class="hljs-keyword">__LINE__</span>); <span class="hljs-comment">// 3 行目</span></code></pre> - <pre class="highlight" language="php" linenumbering="unnumbered"><code>function g() { - return __LINE__; // 111 行目 + <pre class="highlight" language="php" linenumbering="unnumbered"><code class="highlight"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">g</span>(<span class="hljs-params"></span>) </span>{ + <span class="hljs-keyword">return</span> <span class="hljs-keyword">__LINE__</span>; <span class="hljs-comment">// 111 行目</span> }</code></pre> <p> diff --git a/public/posts/2023-03-10/rewrite-this-blog-generator/index.html b/public/posts/2023-03-10/rewrite-this-blog-generator/index.html index 0d05ca5..855203b 100644 --- a/public/posts/2023-03-10/rewrite-this-blog-generator/index.html +++ b/public/posts/2023-03-10/rewrite-this-blog-generator/index.html @@ -9,7 +9,7 @@ <link rel="icon" type="image/svg+xml" href="/favicon.svg"> <title>このブログのジェネレータを書き直した | REPL: Rest-Eat-Program Loop</title> <link rel="stylesheet" href="/style.css?h=17cf97a767ec5fb6e64967729f40f30a"> - <link rel="stylesheet" href="/hl.css?h=208c52e3b7c9db1cad782c5d30b4698f"> + <link rel="stylesheet" href="/hl.css?h=340e65ffd5c17713efc9107c06304f7b"> </head> <body class="single"> <header class="header"> |
