blob: 2285d8d1e5bcdbbaad419eb47bc62cdadbb72867 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
|
@require: class-slydifi/theme/akasaka
@require: code-printer/code-design
@require: code-printer/code-printer
@require: figbox/figbox
let-block +code-block s = '<
+code-printer?:(
CodePrinter.default
|> CodePrinter.set-number-fun CodeDesign.number-fun-null
)(s);
>
open FigBox
in
document '<
+make-title(|
title = {
|明日のあなたの役に立たない
|PHPコーディング技法
|~polyglot~
|};
author = {|nsfisis (いまむら)|};
date = {|第148回PHP勉強会@東京|};
|);
+frame{自己紹介}<
+fig-center(vconcat [
hconcat [
textbox{nsfisis (いまむら)};
gap 20pt;
include-image 50pt `assets/me.jpeg`;
];
gap 20pt;
textbox{\@ デジタルサーカス株式会社};
]);
>
+frame{Polyglotとは}<
+fig-center(vconcat [
textbox{単一のソースコードが複数の言語として解釈可能なプログラム};
gap 20pt;
textbox{今回はPHP・Ruby・Perlの組み合わせ};
]);
>
+frame{ソースコード}<
+code-block(
`#<?php
$a = 'a'; $/* 0; # */$a
=begin
();
echo "php\n";
function begin() {} $a = <<<nil
=end
puts "#ruby"; '
=cut
print "#perl\n";
'# ';
nil;`
);
+p{
実行結果: \inline-code(`#php`);、\inline-code(`#ruby`);、\inline-code(`#perl`);
}
>
+frame{PHPとして解釈する}<
+code-block(
`#<?php`
);
+p{
\inline-code(`#`); とPHPタグ
}
>
+frame{PHPとして解釈する}<
+code-block(
`$a = 'a'; $/* 0; # */$a
=begin
();`
);
+p{
\inline-code(`$a`); に \inline-code(`'a'`); を代入
}
+p{
\inline-code(`$$a = begin();`); (variable variable)
}
>
+frame{PHPとして解釈する}<
+code-block(
`echo "php\n";`
);
+p{
出力部分。実際の出力には先頭に \inline-code(`#`); が付く
}
>
+frame{PHPとして解釈する}<
+code-block(
`function begin() {} $a = <<<nil
=end
puts "#ruby"; '
=cut
print "#perl\n";
'# ';
nil;`
);
+p{
関数 \inline-code(`begin()`); を定義
}
+p{
Here document (delimiter: \inline-code(`nil`);) で残りを飲み込む
}
>
+frame{おわりに}<
+fig-center(vconcat [
textbox{これにもう1言語足したものを};
gap 20pt;
textbox{PHPerKaigi 2023のPHPerチャレンジに出題します!};
]);
>
+frame{Rubyとして解釈する}<
+code-block(
`#<?php`
);
+p{
\inline-code(`#`); は行コメント
}
>
+frame{Rubyとして解釈する}<
+code-block(
`$a = 'a'; $/* 0; # */$a`
);
+p{
\inline-code(`$a`); に \inline-code(`'a'`); を代入
}
+p{
\inline-code(`$/`); はRubyの特殊なグローバル変数。\inline-code(`*`); は乗算
}
+p{
\inline-code(`#`); 以降は行コメント
}
>
+frame{Rubyとして解釈する}<
+code-block(
`=begin
();
echo "php\n";
function begin() {} $a = <<<nil
=end`
);
+p{
\inline-code(`=begin`); から \inline-code(`=end`); はコメント
}
>
+frame{Rubyとして解釈する}<
+code-block(
`puts "#ruby"; '`
);
+p{
出力部。\inline-code(`'`); からは文字列リテラル
}
>
+frame{Rubyとして解釈する}<
+code-block(
`puts "#ruby"; '
=cut
print "#perl\n";
'# ';
nil;`
);
+p{
文字列リテラルとして読み飛ばし、行コメント
}
+p{
\inline-code(`nil`); はPHPでいう \inline-code(`null`);
}
>
+frame{Perlとして解釈する}<
+code-block(
`#<?php
$a = 'a'; $/* 0; # */$a
=begin
();
echo "php\n";
function begin() {} $a = <<<nil
=end
puts "#ruby"; '
=cut
print "#perl\n";
'# ';
nil;`
);
+p{
ほぼRubyと同じ。
Perlだと \inline-code(`=begin`); から \inline-code(`=cut`); までがコメント
}
>
>
|