Upgrade to Pro — share decks privately, control downloads, hide ads and more …

p5-Lodash!

 p5-Lodash!

吉祥寺.pm #14 / LT

Kenta Kobayashi

May 26, 2018
Tweet

More Decks by Kenta Kobayashi

Other Decks in Technology

Transcript

  1. _.defaults({ 'a': 1 }, { 'a': 3, 'b': 2 });

    // → { 'a': 1, 'b': 2 } _.partition([1, 2, 3, 4], n => n % 2); // → [[1, 3], [2, 4]]
  2. p5-Lodash Perl5 port of Lodash.js 同じ挙動を目指してる ( ひとまず) 手書き Inline

    module に頼るでなく、 真正面から モチベー ション JSer に楽してもらいたい CPAN に便利なモジュー ルがたくさんあるけ ど、 知らないが為に損することもある
  3. 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]]
  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]]
  5. ❯ perl -e 'print 6 + 4' 10 ❯ node

    -e 'console.log(6+4)' 10
  6. ❯ perl -e "print '6' + '4'" 10 ❯ node

    -e "console.log('6'+'4')" 64
  7. ❯ perl -MDevel::Peek -e "Dump 6" SV = IV(0x7fdf7d011370) at

    0x7fdf7d011380 REFCNT = 1 FLAGS = (IOK,READONLY,PROTECT,pIOK) IV = 6
  8. ❯ 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
  9. どちらも Scalar Value だけど、 中身は違う 一方は、 Integer Value もう一方は Pointer

    Value 6 と '6' の中身の違いを浮き出せれば、 区別できる
  10. 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;
  11. !!1

  12. 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
  13. ❯ 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