Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
p5-Lodash!
Search
Kenta Kobayashi
May 26, 2018
Technology
2
810
p5-Lodash!
吉祥寺.pm #14 / LT
Kenta Kobayashi
May 26, 2018
Tweet
Share
More Decks by Kenta Kobayashi
See All by Kenta Kobayashi
Perlの生きのこり - エンジニアがこの先生きのこるためのカンファレンス2025
kfly8
4
2k
Tシャツに書かれたコードを読む
kfly8
0
1.3k
Introduce Sub::Meta
kfly8
0
56
研修はイベントでなくコミュニティ作り
kfly8
0
1.7k
明日からできる新人のオンボーディングガイド
kfly8
0
810
メンター成長のためのふりかえり会
kfly8
0
1.2k
Interfaces in Perl5 at The Perl Conference 2019 in Pittsburgh
kfly8
0
2.9k
経験から効率よく学習する
kfly8
0
320
Interfaces in Perl5
kfly8
1
940
Other Decks in Technology
See All in Technology
出前館を支えるJavaとKotlin
demaecan
0
130
Symfony in 2025: Scaling to 0
fabpot
2
270
Tirez profit de Messenger pour améliorer votre architecture
tucksaun
1
180
製造業の会計システムをDDDで開発した話
caddi_eng
3
1.1k
「ラベルにとらわれない」エンジニアでいること/Be an engineer beyond labels
kaonavi
0
220
Restarting_SRE_Road_to_SRENext_.pdf
_awache
1
210
【5分でわかる】セーフィー エンジニア向け会社紹介
safie_recruit
0
20k
Re:VIEWで書いた「Compose で Android の edge-to-edge に対応する」をRoo Codeで発表資料にしてもらった
tomoya0x00
0
230
大規模プロジェクトにおける 品質管理の要点と実践 / 20250327 Suguru Ishii
shift_evolve
0
310
20250326_管理ツールの権限管理で改善したこと
sasata299
1
570
日本MySQLユーザ会ができるまで / making MyNA
tmtms
1
410
サーバシステムを無理なくコンテナ移行する際に伝えたい4つのポイント/Container_Happy_Migration_Method
ozawa
1
120
Featured
See All Featured
Scaling GitHub
holman
459
140k
Product Roadmaps are Hard
iamctodd
PRO
52
11k
The Invisible Side of Design
smashingmag
299
50k
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.2k
Designing for humans not robots
tammielis
251
25k
Adopting Sorbet at Scale
ufuk
75
9.3k
Faster Mobile Websites
deanohume
306
31k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
233
17k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
47
5.3k
Fantastic passwords and where to find them - at NoRuKo
philnash
51
3.1k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
29
2k
How to train your dragon (web standard)
notwaldorf
91
5.9k
Transcript
p5-Lodash! 吉祥寺.pm14 / LT @k y8
_.defaults({ 'a': 1 }, { 'a': 3, 'b': 2 });
// → { 'a': 1, 'b': 2 } _.partition([1, 2, 3, 4], n => n % 2); // → [[1, 3], [2, 4]]
p5-Lodash Perl5 port of Lodash.js 同じ挙動を目指してる ( ひとまず) 手書き Inline
module に頼るでなく、 真正面から モチベー ション JSer に楽してもらいたい CPAN に便利なモジュー ルがたくさんあるけ ど、 知らないが為に損することもある
use Lodash; _->defaults({ a => 1 }, { a =>
3, b => 2 }); # → { a => 1, b => 2 } _->partition([1, 2, 3, 4], sub ($n) { $n % 2 }); # → [[1, 3], [2, 4]]
use Lodash qw(_defaults _partition); _defaults({ a => 1 }, {
a => 3, b => 2 }); # → { a => 1, b => 2 } _partition([1, 2, 3, 4], sub ($n) { $n % 2 }); # → [[1, 3], [2, 4]]
use Lodash -core; # => export core functions
_.add
6 + 4
❯ perl -e 'print 6 + 4' 10 ❯ node
-e 'console.log(6+4)' 10
'6' + '4'
❯ perl -e "print '6' + '4'" 10 ❯ node
-e "console.log('6'+'4')" 64
_.add(6, 4) # => 10 _.add('6', '4') # => '64'
❯ perl -MDevel::Peek -e "Dump 6" SV = IV(0x7fdf7d011370) at
0x7fdf7d011380 REFCNT = 1 FLAGS = (IOK,READONLY,PROTECT,pIOK) IV = 6
❯ perl -MDevel::Peek -e "Dump '6'" SV = PV(0x7fb986803e80) at
0x7fb98700a998 REFCNT = 1 FLAGS = (POK,IsCOW,READONLY,PROTECT,pPOK) PV = 0x7fb986500b70 "6"\0 CUR = 1 LEN = 10 COW_REFCNT = 0
どちらも Scalar Value だけど、 中身は違う 一方は、 Integer Value もう一方は Pointer
Value 6 と '6' の中身の違いを浮き出せれば、 区別できる
use B;
use Test::More; use B; ok B::svref_2object(\6)->FLAGS & B::SVp_IOK; ok not
B::svref_2object(\'6')->FLAGS & B::SVp_IOK; done_testing;
None
XOR operator
use Test::More; ok((6^6) eq '0'); ok not (('6'^'6') eq '0');
done_testing;
use Test::More; # NUL ok not ((6^6) eq "\0"); ok(('6'^'6')
eq "\0"); done_testing;
sub is_number { my $value = shift; looks_like_number($value) && ($value^$value)
eq '0' }
None
!!1
is_number(!!1^!!1) # => ok ❯ perl -MDevel::Peek -e 'Dump !!1^!!1'
SV = IV(0x7f93e7015370) at 0x7f93e7015380 REFCNT = 1 FLAGS = (PADTMP,IOK,READONLY,PROTECT,pIOK) IV = 0
None
❯ perl -MDevel::Peek -e 'Dump !!1' SV = PVNV(0x7ff3a4001010) at
0x10d9b7b58 REFCNT = 2147483644 FLAGS = (IOK,NOK,POK,READONLY,PROTECT,pIOK,pNOK,pPOK) IV = 1 NV = 1 PV = 0x10d99cd43 "1" CUR = 1 LEN = 0
PVNV!
PVNV dual value Scalar::Util::isdual
sub is_number { my $value = shift; looks_like_number($value) && ($value^$value)
eq '0' && !isdual($value) }
None
雑まとめ p5-Lodash の話から Perl の話に脱線 SV は、 多態 コンテキストで、 値が変わる
見ようと思えば、 中身も見れる Devel::Peek B.pm etc
進捗
7/256
やっていき
Gotanda.pm #18 6/11( 月) 株式会社メルカリ 六本木! スピー カー @kazeburo 「System
Programming and Perl」
ぱー るもんがー ごたぴー きちぴー ぜんぶがいねん ( 字余り)