æãVelocityãæ¿ããæ¹é ããããã°ã©ãã³ã°è¨èª(ãã¡ããå¦çç³»ã)ãä½ã£ããã¨ãããã®ã§ããã
PCãæ´çãã¦ãããä»æ§æ¸ãåºã¦ããã®ã§è¼ãã¦ã¿ã¾ãã
ãããæ·±ãæå³ã¯ãªããã§ãã
è¿é ã¯å¤å¿ã®ããå
¨ãããã°ãæ´æ°ã§ãã¦ããããè¦ãç´ãã«ãã£ã¦ãã ãããã
ã³ã¬ãä½ã£ãå½æã
ä¸çªè¦å´ãã¦ããã®ããåãããããã³ã³ãã¤ã«ã¨ã©ã¼æ
å ±ã®è¡¨ç¤ºãã
åãããããã³ã³ãã¤ã«ã¨ã©ã¼æ
å ±ã表示ããããã«ã¯ãç¸å½ãªåéã®æ
å ±ããã£ã¨æã¡ã¾ãã£ã¦ãããªããã°ãªãã¾ããã
ã¾ããã³ã³ãã¤ã«ã¨ã©ã¼ãèµ·ããã¦ããç®æãç¹å®ãã¦ãããã ãæãåºãã®ãçµæ§å¤§å¤ã§ããã
ãã¡ãã¨ããã³ã³ãã¤ã©ãä½ãã人ã¯ã¹ã´ã¤ãã¨èº«ãæã£ã¦ç¥ããã¨ã«ãªã£ãä½åã§ãã
å ¨æè²¼ãã¤ãããéä¸ã§åãã¡ãã£ãã®ã§ã
éä¸(10ç« )ã¾ã§ã§ããã§ã¯ã©ããã
Title: ã¹ã¯ãªããè¨èªvel ãªãã¡ã¬ã³ã¹ããã¥ã¢ã«
version : $Id$
1 ç®æ¬¡
- ç®æ¬¡
- velã¨ã¯
- Hello, World
- Hello, World (ãã®2)
- åç §ã®è¨å®
- åç
§(ãã®2)
- ã³ã¡ã³ãã«ã¤ãã¦
- å®è£
ä¸ã®å¶éã¨ããã®åé¿æ¹æ³
- velã®ãã¼ã¿å
- æ¼ç®å
- ãã£ã¬ã¯ãã£ã
- setãã£ã¬ã¯ãã£ã
- unsetãã£ã¬ã¯ãã£ã
- é¢æ°
- é¢æ°ã«ã¤ãã¦ã®é«åº¦ãªãããã¯
- evalé¢æ°
- lazyé¢æ°
- é¢æ°ãªãã©ã«
- ä¾å¤
- ãªãã¸ã§ã¯ã
- ãªã¹ãã¨ããã
- ã¹ã©ã¤ã·ã³ã°
- æååå±é
- é¢æ°ãã¼ãã«
- é¢æ°ãã¼ãã«ã¨çä¼¼ã¯ã©ã¹æ§é
- javaããªãã¸
- ãã«ãã¤ã³é¢æ°
- å¤é¨ã½ã¼ã¹ãã¡ã¤ã«ã¨ã®é£æº
- ç¹æ®åç
§
- ãã®ä»ã®ãã£ã¬ã¯ãã£ã
- ãã©ã±ããä»ããã£ã¬ã¯ãã£ã
- ãã«ãã¤ã³ãªãã¸ã§ã¯ã
- HTMLã«é¢ãããã®
- I/Oã«é¢ãããã®
- ç»åã®æä½ã«é¢ãããã®
- HTTPéä¿¡ã«é¢é£ãããã®
- 表è¨æ³ã«é¢ãããã®
- æååã®æä½ã«é¢ãããã®
- ãã«ããã¤ãæååã®æä½ã«é¢ãããã®
- æ¥ä»å¦çã«é¢ãããã®
- XMLã«é¢ãããã®
- ã·ã¹ãã ã³ã¼ã«ã«é¢ãããã®
- ãã®ä»ã¦ã¼ãã£ãªãã£ãªã©
- ãã«ãã¤ã³ãªãã¸ã§ã¯ã
$_variables
2 velã¨ã¯
ããããã¯ãApache Velocityã«ä¸é
æ¼ç®åã追å ããã¨ãããã
éçºãã¹ã¿ã¼ãããã¹ã¯ãªããè¨èªã§ããåºæ¬çãªææ³ã¯ãä¸é¨ãé¤ãã¦ã»ã¼äºææ§ãããã¾ãã
ãããvelã¯ãVelocityã¨ç°ãªã ãã³ãã¬ã¼ãã¨ã³ã¸ã³ã§ã¯ãªããããã¾ã§ãã¹ã¯ãªããè¨èª ã§ãã
å¾ã£ã¦ãããããç®æãã¨ãããå
¨ãéãã¾ãã
2.1 è¬è¾
ã¹ã¯ãªããè¨èªvelã¯ãApache Velocityã®ã½ã¼ã¹ãå
ã«ä½æããã¾ããã
ãã®å大ãªè£½åãä½ãåºããä½è
ã®æ¹ã
ã«ã¯ãå¿ããã®å°æ¬ã®æã表ãã¾ãã
2.2 è¬ç½ª
ã¾ãæåã«ã
- ã·ã³ãã«ãªãã³ãã¬ã¼ãã¨ã³ã¸ã³ã§ããVelocityãããããªé¢¨ã«æ¹é ãã¦ãã¾ã£ã¦ããã¾ããã
ã¾ããç¾ç¶ã®velã³ã³ãã¤ã©å®è£ ã«ã¯ããããããªãã ããªãå¶éãããã¾ãã
- ä¾ãã°ãå¼ã®ã°ã«ã¼ãã³ã°ããåºæ¬çã«ã¯ãã§ãã¾ãããããããªããã
- ä¾ãã°ãå¼ã®ä¸ã«ã³ã¡ã³ããå ¥ãããã¨ã¯ã§ãã¾ãããããããªããã
- ä¾ãã°ãã³ã³ãã¤ã«ã¨ã©ã¼ã®ã¡ãã»ã¼ã¸ã¯ã¨ã¦ãä¸è¦ªåã§ããããããªããã
2.3 åææ¡ä»¶
ãã®ããã¹ãã®èªè ã«ã¯ã以ä¸ã®ç¥èããããã¨ãåæã¨ãã¦ãã¾ãã
- ä½ãã®ã¹ã¯ãªããè¨èªãå¤å°ä½¿ãã (Python, Perl, Javascriptãªã©ãã©ããä¸ã¤ã§OK)
- javaã«ã¤ãã¦ã®åºæ¬çãªç¥èããã
3 Hello, World
ããã§ã¯ãæ©éãç´æã®ããã°ã©ã (ã¨è¨ãããã©ããå¾®å¦ã§ãã)ãä½æãã¦ã¿ã¾ãã
<prog.1>
Hello, World!
ãã®ããã°ã©ã <prog.1>ã®åºåã¯ä»¥ä¸ã®éãã§ãã
Hello, World!
ã©ãã§ããããã
ã¾ãããã®ã¾ã¾ã§ã¯å³æ°ãªãã®ã§ãHTMLã§æ¸ãã¦ã¿ã¾ãã
<prog.2>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html lang="ja-JP">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
Hello, World!
</body>
</html>
<prog.2>ã®åºåã¯ä»¥ä¸ã®éãã§ãã
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html lang="ja-JP">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
Hello, World!
</body>
</html>
åºåã¯ã<prog.2>ã§è¨è¿°ããå 容ãã®ã¾ãã¾ã§ãã(å®éã³ããããã ãã§ã)
以ä¸ã®ãã¨ãããæ®éã®HTML(velã®å¶å¾¡æ§æãå
¥ã£ã¦ããªãããã¬ã¼ã³ãªHTML)ãåºåããåã«ã¯ã
ãã®ã¾ã¾æ¸ãã°ããããã ã¨ãããã¨ããããã¨æãã¾ãã
ã¾ã¨ããã¨ã
- ãã ã®ãã¬ã¼ã³ãªããã¹ãã§ããæ£å½ãªvelã®ããã°ã©ã ã¨ãã¦èªèãããã
- åºåã¯ãããã¹ãã®å 容ãã®ã¾ãã¾ã§ãããPHPã¨ãã¨åãã
4 Hello, World (ãã®2)
åç« ã§ã¯ããã åã«åºå®ã®æååãåºåãã¦ã¿ãã ãã§ããã
次ã¯ããã£ããã ããèªåã®ã¦ã¼ã¶IDãåºåããããã°ã©ã ã«æ¹è¯ãã¦ã¿ã¾ãã
<prog.1>
Hello, $_USER.id!
ããã¦ãå®è¡ãã¾ãã以ä¸ã®ããã«åºåãããã¯ãã§ãã
Hello, kechizen!
ãã£ã¨ããã°ã©ã ããããªã£ã¦ãã¾ããã
ãã¦ããã£ããã§ããä¸è¨<prog.1>ã®
$_USER.id
ã¯ãããªæå³ã§ãã
ããUSERã¨ããååã®ãªãã¸ã§ã¯ããã®ä¸ãããidã¨ããååã®å¤ããåãåºãã¦è¡¨ç¤ºããã
velã§ã¯ã $_USER
ã®ããã« $
ããå§ã¾ãåè§è±æ°æååã¯ã åç
§ ã¨å¼ã³ã¾ãã
ã¹ã¯ãªããè¨èªã§ã¯ã馴æã®è¨æ³ã§ãã
ããã¦ã .id
ã¯ãã®é¨å㯠ãããã㣠ã¨å¼ã³ã¾ãã
ããã¯ããªãã¸ã§ã¯ãã®ä¸ããå¤ãåãã ãã¨ããæå³ã¨ãªãã¾ãã
ãªãã $_USER
èªä½ã¯ ãã«ãã¤ã³ãªãã¸ã§ã¯ã ã§ãã
ãã«ãã¤ã³ãªãã¸ã§ã¯ãã«ã¤ãã¦ã¯å¾ã®ç« ã§è§£èª¬ãã¾ãã
4.1 åç §ã®ä¾
æå¹ãªåç §ã¨ã¯ã
$
ããå§ã¾ãã- 次ã«[åè§è±åãã¾ãã¯ã¢ã³ãã¼ã¹ã³ã¢]ãããã
- ãã®å¾ã«0å以ä¸ã®[åè§è±æ°ãã¾ãã¯ã¢ã³ãã¼ã¹ã³ã¢]ãç¶ããã®
ã¨ãªãã¾ãã大æµã®ããã°ã©ãã³ã°è¨èªã®å ´åã¨ã»ã¼åãã§ãã
以ä¸ã¯ãæå¹ãªåç §ã®ä¾ã§ãã
$a$sn42
$HOGE
$foo_bar
ããã¦ããã¡ãã¯ç¡å¹ãªåç §ã®ä¾ã§ãã(ãã¼ã¹ã¨ã©ã¼ã«ãªãã¾ã)
$ ## "$" ã ã$42sn ## æ°åããå§ã¾ã£ã¦ãã
$foo&bar ## "&"ã¯ç¡å¹ãªæå
$ hoge ## "$" 㨠"hoge" ã®éã«ã¹ãã¼ã¹ããã
ãªããæå¹ãªåç §ãæ£è¦è¡¨ç¾ã§è¡¨ãã¨
\$[A-z_][A-z0-9_]*
ã¨ãªãã¾ãã
4.2 ç¡å¹ãªåç §
ãã¦ã $USER.id
ã¨è¨è¿°ããã¨èªåã®ã¦ã¼ã¶IDã表示ãããã¨ããããã¾ããã
ããã§ã¯ã次ã«èªåã®å¹´é½¢ã表示ãã¦ã¿ã¾ãã
$USER.age
ãããå®è¡ããã¨ã以ä¸ã®ããã«è¡¨ç¤ºããã¾ãã
$USER.age
ãããããã°ã©ã ã¨å
¨ãåä¸ã®åºåã§ãããã¡ããã¨å®è¡ããã¦ããªãã®ã§ããããã
ããã§ã¯ãããã§ã¯ã©ãã§ããããã
$my_age
ããã®å®è¡çµæãããã¯ãåãã§ãã
$my_age
â¦ã¨ã¾ããããããåºåãããã¯ãããªãã§ããã29ã¨ãã表示ããããã¯ãã¾ããã
ãªããªãã¦ã¼ã¶ç»é²ããéã«ãèªåã®å¹´é½¢ãããããããªæ
å ±ã¯ããªã«ãæãã¦ããªãã§ãããã
ããã§ã¯ãåå¨ããªãåç
§ãã¾ãã¯ããããã£ãæå®ããã¨ã©ããªãããä¾ç¤ºããããã«
ããã¨ãèªåã®å¹´é½¢ããªã©ã¨ããåå¨ããªãå¤ã使ãã¾ããã
以ä¸ã®ããã«ãvelã§ã¯åå¨ããªãåç
§ãã¾ãã¯ããããã£ãæå®ããã¨ã
è¨è¿°ããå
容ããã®ã¾ã¾è¡¨ç¤ºãããä»æ§ã§ãã
ã¾ã¨ããã¨ã以ä¸ã®éãã§ãã
$USER.id
ã¨æ¸ãã¨ãUSERã¨ããåç §ã®idã¨ããããããã£ã表示ããã- ãªãã¸ã§ã¯ãã®å¤ã表示ããã ããªããä»ã®ã¹ã¯ãªããè¨èªã¨ã»ã¼åãè¨æ³ã§OKã
- åç §ã¾ãã¯ããããã£ãåå¨ããªãå ´åããã®ã¾ã¾åºåãããã
5 åç §ã®è¨å®
ã»ã¨ãã©ã®ããã°ã©ãã³ã°è¨èªã«ã¯ãå¤ã®ä»£å
¥ã®ããã®æ§æãåãã£ã¦ãã¾ãã
å½ç¶ã®ãã¨ãªããvelã«ãã代å
¥ã®æ§æ(代å
¥æ)ãåå¨ãã¾ãã
<prog.1>
#set($foo = 1)
ãã®æã¯ã "foo" ã¨ããååã®åç §ã«ãæ´æ°å¤ 1 ãä»£å ¥ãã ã¨ããæå³ã«ãªãã¾ãã
ãããã£ã¦ã以ä¸ã®ãããªããã°ã©ã
#set($one = 1)
#set($two = 2)
#set($three = 3)$one $two $thee
ã®å®è¡çµæã¯ã以ä¸ã®éãã¨ãªãã¾ãã
1 2 3
ãã¦ã大æµã®ããã°ã©ãã³ã°è¨èªã§ã¯ãä»£å ¥æã¯
<prog.2>
foo = 1
ãªã©ã¨æ¸ããã®ã§ãããvelã§ã¯ããã¯ãã¡ã§ãã
ãã¡ãã¡ #set
ãªã©ã¨æ¸ãã¦ããå¿
è¦ãããã¾ããé¢åãããã§ããã
ã§ãããã«ã¯çç±ãããã¾ãã
åã®ç« ã§åºã¦ãã Hellow World
ã®ä¾ã®ããã«ãvelã¯ããã°ã©ã ä¸ã®ãã¬ã¼ã³ãªããã¹ãã¯ãã®ã¾ã¾åºåãã¾ãã
ãã£ã¦ããã åã«<prog.2>ã®ããã«æ¸ãã¦ããvelã¯ããã°ã©ã (ãã®å ´åã¯ä»£å
¥æ)ã¨ãã¦ã¯èªèããªãä»æ§ã«ãªã£ã¦ãã¾ãã
(éã«ã foo = 1
ã®ãããªããã¹ãã代å
¥æã¨ã¿ãªããã¦ãã¾ãã¨ã
ä¾ãã°HTMLã®å±æ§ãå
¨ã¦ä»£å
¥æã¨ãã¦èªèããã¦ãã¾ããã¾ã¨ãã«è¡¨ç¤ºã§ããªããªãã¾ã)
ããã§ã<prog.1>ã®ããã«ç¹å¥ãªæ§æ(ãã®å ´å㯠#set
)ãç¨ãããã¨ã§ãããã¯ããã°ã©ã ã¨ãã¦è§£éãã¦ãã
ã¨velã³ã³ãã¤ã©ã«æãã¦ããå¿
è¦ãããã®ã§ãã
ãã®ãç¹å¥ãªæ§æãã®ãã¨ããvelã§ã¯ ãã£ã¬ã¯ãã£ã ã¨å¼ã³ã¾ãã
velã«ã¯ãsetãã£ã¬ã¯ãã£ã( #set
ã®ãã¨ã§ã)以å¤ã«ãããããã®ãã£ã¬ã¯ãã£ããåå¨ãã¾ããã
ããã¯ããããã®ç« ã§å¾ã
ã«è§£èª¬ãã¦ããã¾ãã
6 åç §(ãã®2)
6.1 ãã©ã¼ãã«è¨æ³
åç §ã«æ³¢æ¬å¼§ãä»ãããã¨ã§ãåç §ã®åºåããæ示çã«æå®ãããã¨ãã§ãã¾ãã
#set($foo = 'foo')
#set($foobar = 'FOOBAR')$foobar ## 'FOOBAR'
${foo}bar ## 'foobar'
ããããã£ã«ã使ãã¾ãã
${_USER.id} ## 'foo'
6.2 åç §ã®ã¨ã¹ã±ã¼ã
åç §ã®ã¨ã¹ã±ã¼ãã«ã¯ã以ä¸ã®3éãã®æ¹æ³ãããã¾ãã
$$
#set($foo = 1)
$foo ## "1"
$$foo ## "$foo"
$${foo} ## "${foo}"$$$foo ## "$$foo"
$$$$foo ## "$$$foo"{$}
#set($foo = 1)
$foo ## "1"
{$}foo ## "$foo"
{$}{foo} ## "${foo}"{$$}foo ## "{$}foo"
{$$$}foo ## "{$$}foo"\$
(Velocityã¨ã®äºææ§ã®ããã«åå¨ãã¦ããã®ã¿ã§ããéæ¨å¥¨ã
å°æ¥ã®ãã¼ã¸ã§ã³ã§ã¯ä½¿ããªããªãå¯è½æ§ãããã¾ã)#set($foo = 1)
$foo ## "1"
\$foo ## "$foo"
\${foo} ## "${foo}"ãªãã
${foo == 1}
ã®ãããªæååãã¨ã¹ã±ã¼ãããå ´åã¯ã
\$
ã¯ä½¿ãã¾ãããããªãã¡$${foo == 1}
{$$}{foo == 1}
ã®ããã«æ¸ãå¿ è¦ãããã¾ãã
6.3 ã¯ã¯ã¤ã¨ããè¨æ³
é常ãå¤ã null
ã§ããåç
§ã表示ããã¨ããã®é¨åã®ã³ã¼ãããã®ã¾ã¾åºåããã¦ãã¾ãã¾ãã
ãããé¿ããããã«ã¯ã ã¯ã¯ã¤ã¨ããè¨æ³ ã使ç¨ãã¾ãã
ã¯ã¯ã¤ã¨ããè¨æ³ã使ãã«ã¯ãåç
§ã®éå§ã示ãã·ã³ãã« $
ã®ä»£ãã«ã $!
ã使ãã¾ãã
$foo ## fooã¯å®ç¾©ããã¦ããªãã®ã§ã"$foo"
$!foo ## ã¯ã¯ã¤ã¨ããè¨æ³ã使ã£ã¦ããã®ã§ããªã«ãåºåãããªã
$foo.bar ## "$foo.bar"
$!foo.bar ## ãªã«ãåºåãããªã
$!{foo} ## ãã©ã¼ãã«è¨æ³ã ã¨ãããªã
6.4 ãã§ãã¯ãè¨æ³
$
ã®ä»£ãã« $?
ã使ããã¨ã§ã
ããåç
§ã®å¤ã null
ã§ãªããã¨ãå¼·å¶çã«ç¢ºèªã§ãã¾ãã
$?foo ## $fooã®å¤ãnullã ã¨ãããã§ä¾å¤ãçºçãã
$?foo.bar() ## åä¸
## $fooãnullã§ãªãã¨ãã«ã
## $hogeã¯nullã§ããããã$mogeãnullã ã¨bazãå¼ã°ããåã«ä¾å¤ãçºçãã
$?foo.baz($hoge, $?moge)
7 ã³ã¡ã³ãã«ã¤ãã¦
velã®ã³ã¡ã³ãã«ã¯ã è¡ã³ã¡ã³ã 㨠ãããã¯ã³ã¡ã³ã ã®2ã¤ãããã¾ãã
- è¡ã³ã¡ã³ãã¯
##
ããéå§ãã¾ãã - ãããã¯ã³ã¡ã³ãã¯ã
#*
ããéå§ãã*#
ã§çµäºãã¾ãã- ãããã¯ã³ã¡ã³ãã®ä¸ã«ãè¡ã³ã¡ã³ãããã¹ãããããã¨ãã§ãã¾ãã
- ãããã¯ã³ã¡ã³ãã®ä¸ã«ããããã¯ã³ã¡ã³ãããã¹ãããããã¨ã¯ ã§ãã¾ãã ã
以ä¸ã«ãæå¹ãªã³ã¡ã³ãã®ä¾ã示ãã¾ãã
##è¡ã³ã¡ã³ã#*
ãããã¯ã³ã¡ã³ã
*##*
ãã®ããã«ã
##ãããã¯ã³ã¡ã³ãã®ä¸ã«è¡ã³ã¡ã³ã
ããã¹ãã§ãã¾ãã
*#
8 å®è£ ä¸ã®å¶éã¨ããã®åé¿æ¹æ³
ããã§ã¯ãç¾ç¶ã®velã³ã³ãã¤ã©ãä¸å®å ¨ãªããã«åå¨ããå¶éã«ã¤ãã¦è§£èª¬ãã¾ãã
8.1 ã³ã¡ã³ãã®å¶é
ã¹ãã¼ãã¡ã³ãå ã«ã³ã¡ã³ããå ¥ãããã¨ã¯ã§ãã¾ããã
ä¾ãã°ã以ä¸ã®ãããªã³ã¼ãã¯ã³ã³ãã¤ã«ã¨ã©ã¼ã«ãªãã¾ãã
#set(##$foo = 1 â ã³ã¡ã³ããsetãã£ã¬ã¯ãã£ãã®ä¸ã«å ¥ã£ã¦ãã
$foo = 2
)
ãã®å ´åãé¢åã§ãã以ä¸ã®ããã«ããªãã¨ãã¡ã§ãã
## #set($foo = 1) â setãã£ã¬ã¯ãã£ããã¨ã³ã¡ã³ãã¢ã¦ããã#set($foo = 2)
8.2 åç §ç´å¾ã®è¨å·
åç §ã®ç´å¾ã«è¨å·ãä»ãå ´åããã©ã¼ãã«è¨æ³ãå¿ è¦ã«ãªããã¨ãããã¾ãã
ä¾ãã°ã次ã®ã³ã¼ãã¯ã³ã³ãã¤ã«ã¨ã©ã¼ãçºçãã¦ãã¾ãã¾ãã
#set($foo = 'FOO')"$foo" ## ããã§ã³ã³ãã¤ã«ã¨ã©ã¼
ãã®ã¨ã©ã¼ã¯ããã©ã¼ãã«è¨æ³ã使ããã¨ã§è§£æ¶ãã¾ãã
#set($foo = 'FOO')"${foo}"
ã¾ãã次ã®ãããªã³ã¼ããã¨ã©ã¼ã«ãªãã¾ãã
#set($foo, $bar = 'FOO', 'BAR')#set($foobar = "$foo:$bar") ## ããã§ã³ã³ãã¤ã«ã¨ã©ã¼
$foobar
ãã®ãããªå ´åãããã©ã¼ãã«è¨æ³ã使ãã°ã¨ã©ã¼ã¯è§£æ¶ããã¾ãã
#set($foo, $bar = 'FOO', 'BAR')#set($foobar = "${foo}:${bar}")
$foobar
9 velã®ãã¼ã¿å
velã«ã¯ããããã®ãã¼ã¿åãããã¾ãããããã1ã¤ãã¤è§£èª¬ãã¦ããã¾ãã
9.1 æ´æ°å
æ´æ°ã表ç¾ããåã§ãã
velã§ã¯ã32bit符å·ä»ãæ´æ°ãã¾ãã¯64bit符å·ä»æ´æ°ãå¿
è¦ã«å¿ãã¦èªåçã«ä½¿ãããã¾ãã
æ大é·64bitã符å·ä»ããªã®ã§ã表ç¾ã§ããå¤ã®ç¯å²ã¯
- -9223372036854775808 (æå°å¤)
- 9223372036854775807 (æ大å¤)
ã§ãã
9.2 å°æ°å
å°æ°ã表ç¾ããåã§ãã
精度ã®ç¯å²ã«ä¸éã¯ããã¾ããã
æµ®åå°æ°ç¹ã¨ã¯ç°ãªããæ´æ°ã©ããã®æ¼ç®(é¤ç®ä»¥å¤)ãããããã精度ã失ããããã¨ã¯ããã¾ããã
velã§ã¯ã .1
ã®ããã«ãæåã®ã¼ããçç¥ãããã¨ã¯ã§ãã¾ããããã¡ã㨠0.1
ã¨æ¸ãå¿
è¦ãããã¾ãã
#set($very_long_integer = 10000000000000000000000000000000000000000000000000000000000000000) ## 10 ^ 64
#set($very_very_long_integer = $very_long_integer * $very_long_integer)$very_very_long_integer ## 10 ^ 128
#set($f = 0.1)
#set($very_small_decimal = 0.00000000000000000000000000000000000000000000000000000000000001)
#set($very_large_decimal = 10000000000000000000000000000000000000000000000000000000000000.0)
ææ°è¡¨è¨ã使ç¨ãããã¨ãã§ãã¾ãã
#set($f1 = 1.234e5) ## 1.234 * 10 ^ 5#set($f2 = 1.234e+5) ## ãã®ããã«ãæ¸ãã
å°æ°è¡¨è¨ã使ç¨ãããã¨ã§ãæ´æ°å¤ãå¼·å¶çã«å°æ°ã§ããã¨èªèããããã¨ãã§ãã¾ãã
#set($d = 1d) ## æ´æ°åã§ãªããå°æ°åã®å¤ã¨ãã¦æ±ã
9.3 æååå
æååã表ç¾ããåã§ãã
velã§ã¯ãã·ã³ã°ã«ã¯ã©ã¼ãã§å²ã¾ããæåã·ã¼ã±ã³ã¹ãæååã¨è¦ãªãã¾ãã
- æ¹è¡æå(ã¨ã¹ã±ã¼ãæåã§ã¯ãªãããã³ãã®æ¹è¡æå)ãå«ããã¨ãã§ãã¾ãã
- 以ä¸ã®ã¨ã¹ã±ã¼ãæåãæå¹ã§ãã
\n
- æ¹è¡\t
- ã¿ã\b
- ããã¯ã¹ãã¼ã¹\r
- 復帰\f
- æ¹ãã¼ã¸\\
- ã¨ã¹ã±ã¼ãæå\"
- ããã«ã¯ã©ã¼ã\'
- ã·ã³ã°ã«ã¯ã©ã¼ã\`
- ããã¯ã¯ã©ã¼ã
- ã¦ãã³ã¼ãã¨ã¹ã±ã¼ãã使ç¨å¯è½ã§ãã
ã³ã¼ãä¾
#set($str0 = 'hoge')#set($str1 = '') ## 空æåå
#set($str2 = 'hoge
moge') ## "hoge" 㨠"moge" ã®éã«æ¹è¡ããã#set($str3 = 'hoge\nmoge') ## ã¨ã¹ã±ã¼ãæåã§æ¹è¡ãå ¥ãã
## ã·ã³ã°ã«ã¯ã©ã¼ãã®ä¸ã«ããã«ã¯ã©ã¼ããã¨ã¹ã±ã¼ããªãã§å ¥ãããã
#set($str4 = ' He said, "Stop!" ')
## ã¦ãã³ã¼ãã¨ã¹ã±ã¼ã
#set($str5 = '\u3042\u3044\u3046\u3048\u304a') ## ããããããããæ ¼ç´ããã
ãã¦ãä»ã®ããã°ã©ãã³ã°è¨èªã§ã¯ãæååã¯ããã«ã¯ã©ã¼ãæååã§è¡¨ããã¨ãå¤ãã§ãã
ããããvelã§ã¯ããã«ã¯ã©ã¼ãæååã¯ãªãã®ããã¨è¨ãã¨ãä¸å¿ããã¾ããâ¦
ããã ããã«ã¯ã©ã¼ãæååã®ä¸ã« $
(åç
§ã®éå§æå)ãã¾ã㯠#
(ãã£ã¬ã¯ãã£ãã®éå§æå)ãåºç¾ãã å ´åã«ã
ã·ã³ã°ã«ã¯ã©ã¼ãæååã®å ´åã¨åä½ã大ããç°ãªãã¾ãã
ããããã©ãéãã®ããã¨ããã¨ããããç解ããã«ã¯ããå°ãvelã®ç¥èãå¿
è¦ã«ãªãã¾ãã
ãã£ã¦ãããã§ã¯ã¨ãããããvelã§ã¯ãæååã¯ã·ã³ã°ã«ã¯ã©ã¼ãã使ããã¨ãããã¨ã«ãã¦ããã¾ãã
ããã«ã¯ã©ã¼ãæååã®è©³ç´°ã«ã¤ãã¦ã¯ãå¾ã®ç« (æååå±éã®ç« )ã§ãã¡ãã¨è§£èª¬ãã¾ãã
9.4 boolå
æ£ãã¾ãã¯å½ã®2å¤ã表ç¾ããå¤ã§ãã
#set($this_is_true = true)#set($this_is_false = false)
9.5 nullå¤
ãã«å¤ã§ãããªã«ãå¤ãè¨å®ããã¦ããªããã¨ã表ç¾ãã¾ãã
Javascriptç³»ã®è¨èªã¨ç°ãªããvelã«ã¯ undefined
ã¯ããã¾ããã
#set($this_is_null = null)
9.6 ãªã¹ã
åç §ã®ãé çªä»ã·ã¼ã±ã³ã¹ã表ç¾ãã¾ãã
<prog.1>
#set($one_two_three = [1, 2, 3])#set($foo_bar_baz = ['foo', 'bar', 'baz'])
## åç §ããªã¹ãã«å ¥ãããã¨ãã§ããã
##ãã®å ´åãä¸ã¤ä¸ã® "$nested" ã¨å ¨ãåãè¦ç´ ãæã¤ãªã¹ãã«ãªãã
#set($refs = [ $one_two_three, $foo_bar_baz ])
ãªã¹ãã®åè¦ç´ ã«ã¢ã¯ã»ã¹ããã«ã¯ã []
æ¼ç®åã使ãã¾ãã
ã¤ã³ããã¯ã¹ã¯ã0ããéå§ãã¾ãã
ãªããvelã§ã¯ ä¸æ£ãªã¤ã³ããã¯ã¹ãæå®ããå ´åã¯å¸¸ã« null
ã¨ãªãã¾ãã
#set($list = [1, 2, 3])$list[0] ## "1"
$list[1] ## "2"
$list[2] ## "3"$list[3] ## ã¤ã³ããã¯ã¹ãªã¼ãã¼ãnullã¨ãªãã
ã©ãã§ããããã
è¨æ³ã«ã¤ãã¦ã¯ãæ®éã®ããã°ã©ãã³ã°è¨èªã§è¨ãã¨ããã®ãé
åãã¨åããããªãã®ã§ãã
å ¥ãå表è¨ãå¯è½ã§ããå ¥ãåã®æ·±ãã«ä¸éã¯ããã¾ããã
#set($nested = [ [1, 2, 3], ['foo', 'bar', 'baz'] ]) ## ãªã¹ãã®å ¥ãå$nested[0][0] ## "1"
$nested[0][1] ## "2"
$nested[0][2] ## "3"
$nested[1][0] ## "foo"
$nested[1][1] ## "bar"
$nested[1][2] ## "baz"
9.6.1 ç¯å²æå®ãªã¹ã
ããä¸å®ã®ç¯å²ã表ãæ´æ°å¤ã®ãªã¹ããçæããããã«ã
以ä¸ã®4ã¤ã®ç¹å¥ãªè¨æ³ãç¨æããã¦ãã¾ãã
..
<..
..<
<..<
ä¾ãã°ãä¸ã®<prog.1>ã® $one_two_three
ã¯ã以ä¸ã®ããã«æ¸ãæãããã¨ãå¯è½ã§ãã
#set($one_two_three = [1..3])
#set($one = 1)
#set($three = 3)#set($one_two_trhee_by_ref = [$one..$three]) ## ç¯å²æå®ã«ã¯ãåç §ã使ããã¨ãã§ãã
#set($one_two_trhee_by_num_and_ref = [1..$three]) ## ãããOK
ã¾ããç¯å²æå®ã«ã¯è² å¤ãæå®ã§ãã¾ãã
#set($minus1_to_plus1 = [-1..1]) ## [-1, 0, 1]ã¨ãªã
æ´ã«ã [$x..$y]
ã¨ããã¨ãã«ã $x <= $y
ãæºãå¿
è¦ã¯ããã¾ããã
éã«ããå ´åã¯éé ã®ãªã¹ãã¨ãªãã¾ãã
#set($plus1_to_minus1 = [1..-1]) ## [1, 0, -1]ã¨ãªã
ãªãããã®ä»ã®ç¯å²æå®ãªã¹ãè¨æ³ã¯ãããã以ä¸ã®åä½ããã¾ãã
..<
ã¯ã ç¯å²çµäºå¤ãå«ã¾ããªã ã¨ããç¹ä»¥å¤ã¯ã..
ã¨åãã§ãã<..
ã¯ã ç¯å²éå§å¤ãå«ã¾ããªã ã¨ããç¹ä»¥å¤ã¯ã..
ã¨åãã§ãã<..<
ã¯ã ç¯å²éå§ããã³çµäºå¤ãå«ã¾ããªã ã¨ããç¹ä»¥å¤ã¯ã..
ã¨åãã§ãã
以ä¸ã«ä¾ã示ãã¾ãã
#set($list00 = [0..<5])
#set($list01 = [0..<-5])#set($list10 = [0<..5])
#set($list11 = [0<..-5])#set($list20 = [0<..<5])
#set($list21 = [0<..<-5])
$list00 ## "[0, 1, 2, 3, 4]"
$list01 ## "[0, -1, -2, -3, -4]"$list10 ## "[1, 2, 3, 4, 5]"
$list11 ## "[-1, -2, -3, -4, -5]"$list20 ## "[1, 2, 3, 4]"
$list21 ## "[-1, -2, -3, -4]"
9.6.1.1 ç¯å²éå§å¤ã¨ç¯å²çµäºå¤ãåãå ´å
ãã®å ´åã空ã®ãªã¹ããçæãã¾ãã
以ä¸ã«ä¾ã示ãã¾ãã
#set($list0 = [0..0])
#set($list1 = [0<..0])
#set($list2 = [0..<0])
#set($list3 = [0<..<0])
$list0 ## ""
$list1 ## ""
$list2 ## ""
$list3 ## ""
9.6.2 ãªã¹ãã¸ã®å¤ã®è¨å®
æ®éã®è¨èªã§è¨ãã¨ããã®é
åã¸ã®å¤ã®è¨å®ã¨åãã§ãã
ãã ãä¸æ£ãªã¤ã³ããã¯ã¹ã¸ã®å¤ã®è¨å®ã¯ã¨ã©ã¼ã¨ãªãã¾ããã
åã«ç¡è¦ãã¾ãã
#set($hoge = [0, 0, 0])#set($hoge[0] = 1) ## ã¤ã³ããã¯ã¹0ã®å¤ã¨ãã¦1ãè¨å®
#set($hoge[1] = 10) ## ã¤ã³ããã¯ã¹1ã®å¤ã¨ãã¦10ãè¨å®
#set($hoge[2] = 100) ## ã¤ã³ããã¯ã¹2ã®å¤ã¨ãã¦100ãè¨å®#set($hoge[3] = 1000) ## ã¤ã³ããã¯ã¹ãªã¼ãã¼ãç¡è¦ããã
$hoge ## "[1, 10, 100]"ã¨è¡¨ç¤ºããã
9.7 ããã
ãã¼ã¨ããã«é¢é£ä»ããããå¤ããã¢ã¨ãã¦ãè¤æ°ã®ãã¼ã¿ãããããã£ã¨ãã¦ä¿æãããã¼ã¿åã§ãã
ä¸è¬çã«ã¯ããã·ã¥ã¨ãé£æ³é
åã¨å¼ã°ãã¦ãããã®ã§ãã
velã§ã¯ãããã¦ãããããã¨å¼ã¶ãã¨ã«ãã¾ã(ãã®çç±ã¯å¾ã§ãããã¾ã)ã
ãã¼ãå¤ã¨ãã«ä½¿ç¨ã§ããåã«å¶éã¯ããã¾ãããã©ããªå¤ã§ããã¼/å¤ã¨ãã¦ä½¿ç¨ã§ãã¾ãã
ãã¡ããããããã®å¤ã¨ãã¦ããããæå®ãããã¨ã§ããããã®å
¥ãåã¨ãããã¨ãã§ãã¾ãã
ã¾ãããªã¹ãã®æã¨è¦é ã¯åãã§ãã
æ ¼ç´ãããå¤ã¸ã®ã¢ã¯ã»ã¹ã«ã¯ã以ä¸ã®æ段ãããã¾ãã
- ããããã£å½¢å¼
#set($foo_bar_baz = { 'foo':1, 'bar':2, 'baz':3 })$foo_bar_baz.foo ## "1"
$foo_bar_baz.bar ## "2"
$foo_bar_baz.baz ## "3"$foo_bar_baz['foo'] ## "1"
$foo_bar_baz['bar'] ## "2"
$foo_bar_baz['baz'] ## "3"
æ¼ç®åã使ãå ´åããã¼ã¨ãã¦æå®ããå¤ã¯åç
§ã§ãOKã§ãã
#set($foo_bar_baz = { 'foo':1, 'bar':2, 'baz':3 })
#set($key_of_1 = 'foo')
#set($key_of_2 = 'bar')
#set($key_of_3 = 'baz')$foo_bar_baz[$key_of_1] ## "1"
$foo_bar_baz[$key_of_2] ## "2"
$foo_bar_baz[$key_of_3] ## "3"
ã¾ãããã¼ã¨ãã¦æå®ããå¤ãæååãªãã©ã«ã§ãæ£è¦è¡¨ç¾
[A-z][A-z0-9_]*
ã«ãããããå ´åãã¯ã©ã¼ãããã«ã以ä¸ã®ããã«è¨è¿°ãããã¨ãã§ãã¾ãã
#set($foo_bar_baz = { 'foo':1, 'bar':2, 'baz':3 })$foo_bar_baz[foo] ## "1"
$foo_bar_baz[bar] ## "2"
$foo_bar_baz[baz] ## "3"
以ä¸ã®ä¾ã¯ãããããæ£ããããã¾ãããå ¨ã¦ã³ã³ãã¤ã«ã¨ã©ã¼ã«ãªãã¾ãã
#set($one_two_three = { '1one':1, 'the two':2, 'three!':3 })#foo_bar_baz[1one] ## ã³ã³ãã¤ã«ã¨ã©ã¼ (æ°åããå§ã¾ã£ã¦ãããããã¡)
#foo_bar_baz[the two] ## ã³ã³ãã¤ã«ã¨ã©ã¼ (ã¹ãã¼ã¹ãå«ããããã¡)
#foo_bar_baz[three!] ## ã³ã³ãã¤ã«ã¨ã©ã¼ ("!"ãå«ããããã¡)
å
¥ãåã®ãããããå¤ãåãåºãå ´åãªã©ã«ãä¸è¨ã®ã¢ã¯ã»ã¹æ¹æ³ãçµã¿åãã¦ä½¿ããã¨ãå¯è½ã§ãã
ãã ãã使ãå ´é¢ã¯ã»ã¨ãã©ãªãã¨æãã¾ããâ¦
##ä¸éã®å ¥ãåããã
#set($nested = {
'inner1':{
'inner2':{
'foo':1
}
}
})##以ä¸ã¯ããããã"1"ã表示ããã
##æ®éã®ã¢ã¯ã»ã¹æ¹æ³
$nested.inner1.inner2.foo
$nested[inner1][inner2][foo]
##çµã¿åããããã¢ã¯ã»ã¹æ¹æ³ (ãã ãããã¾ãæå³ã¯ãªã)
$nested[inner1].inner2['foo']
$nested.inner1[inner2].foo
9.7.1 ãããã¸ã®å¤ã®åçãªè¨å®
ãããã¸ã®å¤ã®è¨å®ã¯ããªã«ã宣è¨æã«éãããããã§ã¯ããã¾ããã
以ä¸ã«ããããã¸ã®å¤ã®è¨å®æ¹æ³ä¾ã示ãã¾ãã
è¦ã¯ãã¢ã¯ã»ã¹ããè¨æ³ããã®ã¾ã¾setãã£ã¬ã¯ãã£ãã®ä¸ã§ä½¿ãã ãã§ãã
#set($hoge = {}) ## 空ã®ãããã¯ããæ¸ã#set($hoge.foo = 1) ## ãã¼"foo"ã®å¤ã¨ãã¦1ãè¨å®
#set($hoge['bar'] = 2) ## ãã¼"bar"ã®å¤ã¨ãã¦2ãè¨å®
#set($hoge[baz] = 3) ## ãã¼"baz"ã®å¤ã¨ãã¦3ãè¨å®$hoge ## "{foo:1, bar:2, baz:3}"ã¨è¡¨ç¤ºããã
å ¥ãåã®ãããã«å¯¾ãã¦ãå¤ãè¨å®ã§ãã¾ãã
#set($hoge = {
'foo':{},
'bar':{}
})#set($hoge.foo.a = 1)
#set($hoge.foo.b = 2)
#set($hoge.bar.a = 3)
#set($hoge.bar.b = 4)$hoge ## "{foo:{a:1, b:2}, bar:{a:3, b:4}}"
ãªããåå¨ããªããããã«å¯¾ãã¦å¤ãè¨å®ãããã¨ãã¦ãç¡è¦ããã¾ãã
#set($hoge = {'foo':{}})#set($hoge.foo.a = 1)
#set($hoge.foo.b = 2)
#set($hoge.bar.a = 3)
#set($hoge.bar.b = 4)$hoge
ãã®ã³ã¼ãã®å®è¡çµæã¯ä»¥ä¸ã®éãã§ãã
#set($hoge.bar.a = 3) â ãããã®ã³ã¼ãã¯ç¡è¦ãããã®ã§ããã®ã¾ã¾åºåããã¦ãã¾ã
#set($hoge.bar.b = 4) â{foo:{a:1, b:2}}
9.7.2 ãããã®å®£è¨è¨æ³ã«ã¤ãã¦
ãã¦ãå®ã¯ãæåååãã¼ã®ã¯ã©ã¼ãçç¥ã¯ã []
æ¼ç®åã ãã§ãªããããã®å®£è¨æã«ã使ãã¾ãã
#set($foo_bar_baz = { foo:1, bar:2, baz:3 })
ãã£ã¡ã®æ¹ããã¯ã©ã¼ãæåããªãã®ã§èªãã®ãæ¸ãã®ãã©ã¯ã§ãã
æ¬ããã¥ã¡ã³ãã§ã¯ã以ä¸ãæãã¿ã¤ãéã®å°ãªãè¨æ³ã使ããã¨ã«ãã¾ãã
ããªãã¡ã
- ããããã£ã®åå¾ãè¨å®ã¯
$foo.bar
å½¢å¼ - ãããã®å®£è¨ã¯ã
{foo:'bar'}
å½¢å¼
ã§ãã
10 æ¼ç®å
velã§ä½¿ããæ¼ç®åã®ã»ããã¯ã大æµã®ããã°ã©ãã³ã°è¨èªã¨åçã®ãã®ã§ããã
velç¬èªã®ãã®ãããã¤ãåå¨ãã¾ãã
10.1 æ¼ç®åã®ä¸è¦§
ç®è¡æ¼ç®åã«ã¯ã以ä¸ã®ãã®ãããã¾ãã
åªå
é ä½ã®é«ããã®ããé ã«æãã¦ãã¾ãã
ãªããä¾ãã°(1)ã® !
, not
ã®ããã«æ¼ç®åã2ã¤ç»å ´ãã¦ããå ´åã
ãã㯠not
㯠!
ã®ã¨ã¤ãªã¢ã¹ã ã¨ããæå³ã§ãã
ã¤ã¾ãã©ã¡ãã使ã£ã¦ãåãæå³ã«ãªãã¾ãã
!
,not
(not)-
,negate
(nagate)*
,mul
(multiply)/
,div
(divide)%
,mod
(modulus)+
,add
(add)-
,sub
(subtract)<
,lt
(less than)<=
,le
(less equal)>
,gt
(greater than)>=
,ge
(greater equal)==
,eq
(equal)!=
,ne
(not equal)same
(same pointer)isnt
(type is not)is
(type is)=~
,matches
(regular expression match)has
(contains value)&
(operational and)|
(operational or)&&
,and
(logical and)||
,or
(logical or)^^
,xor
(logical xor)=>>
,applies
(function application);
,default
(default value)asserts
(inline assertion)[cond] then [if cond true] else [if cond false]
(ternary operation)
10.2 å ¨ã¦ã®æ¼ç®åã«å ±éã®æ§è³ª
- ããã¤ãã®äºé
æ¼ç®åã¯ãç¹å®ã®å¤ã®çµã¿åããã§ãããã¨ãè¦æ±ããã¾ãã
æ£ããå¤ã®çµãæå®ããªãã£ãå ´åãã»ã¨ãã©ã®å ´åã¯false
ã¾ãã¯null
ãè¿ãã¾ãã - ç¹ã«è¨è¿°ããªãéããäºé
æ¼ç®åã®å·¦è¾ºã«
null
ãæå®ããå ´åãè¨ç®çµæã¯ä»¥ä¸ã®éãã¨ãªãã¾ããåç §ãè¿ãæ¼ç®ã®å ´åã¯
null
ã¤ã¾ãã
null
ã«å¯¾ãã¦ã©ããªæ¼ç®ãè¡ãªã£ã¦ãnull
ã«ãªãã¾ããbooleanãè¿ãæ¼ç®ã®å ´åã¯
false
ã¤ã¾ãã
null
ã¨ã®è«çæ¼ç®ã®çµæã¯å¸¸ã«false
ã«ãªãã¾ãã
- booleanãè¦æ±ããæ¼ç®åã¯ã以ä¸ã®å¤ã®ã¿ã
true
ã§ããã¨è¦ãªãã¾ãã- booleanå¤
true
- æåå
t
(ã±ã¼ã¹éä¾å) - æåå
true
(ã±ã¼ã¹éä¾å) - æ°å¤
0
以å¤ã®ä»»æã®æ°å¤ - æåå æ°å¤æååã§ã
'0'
以å¤ã®ãã®
- booleanå¤
10.3 ä¸è¬çãªæ¼ç®å
次ã®æ¼ç®åã¯ã大æµã®ããã°ã©ãã³ã°è¨èªã«ã¯åå¨ãã¦ããæ¼ç®åã§ãã
ãããã¯ãvelã§ãåæ§ã®æå³ãæã£ã¦ãã¾ãã
!
: å¦å® (åé æ¼ç®å)-
: 符å·å転 (åé æ¼ç®å)*
: ä¹ç®/
: é¤ç®%
: å°ä½ç®+
: å ç®-
: æ¸ç®<
: 縲æï½¢æº<=
: 縲æ¦ï¾ä¸>
: 縲æ©è¬é¡è¯ï½«ã>=
: 縲æ¦ï¾ä¸==
: çãã!=
: çãããªã
ãã ããç¹å®ã®å¤ã®çµåãã®å ´åã«ã¯ãç¹å¥ãªæ¼ç®çµæãçæãããã¨ãããã¾ãã
以ä¸ãç¹å®ã®çµåãã«ã¤ãã¦èª¬æãã¦ããã¾ãã
10.3.1 æ¼ç®å *
, /
, +
, -
ã®ç¹ä¾
左辺ãæ°å¤ãå³è¾ºãæååã®å ´åã
å³è¾ºãæ°å¤ã«å¤æãã¦ãããé常ã®ç®è¡æ¼ç®ãè¡ãªãã¾ãã
(ãã®æ§è³ªã使ããã¨ã§ãæååããæ°å¤ã¸ã®åå¤æãç°¡åã«ã§ãã¾ã)
#set($num = 1 + '2')$num ## "3"ã表示
#set($num = 1 + 'abc')
$num ## "abc"ã¯æ°å¤ã«å¤æä¸å¯è½ããã£ã¦ "1 + 0" ã¨åãã§ããã¨è¦ãªããããã "1" ã表示
#set($foo = '42')
#set($bar = 0 + $foo) ##"$foo"ãæ°å¤ã«å¤æãããªãã¡"$bar"ã¯æ´æ°å¤"42"
10.3.2 æ¼ç®å *
ã®ç¹ä¾
- 左辺ãæååãå³è¾ºãæ´æ°å¤ã®å ´å
左辺ã®æååããå³è¾ºã®æ°å¤åæ°åç¹°ãè¿ããæååãçæãã¾ãã
#set($foo3 = 'foo' * 3)$foo3 ## "foofoofoo"
- 左辺ããªã¹ããå³è¾ºãæ´æ°å¤ã®å ´å
左辺ã®ãªã¹ãããå³è¾ºã®æ°å¤åæ°åé£çµããæ°ãããªã¹ããçæãã¾ãã
#set($list3 = [1, 2, 3] * 3)$list3 ## "[1, 2, 3, 1, 2, 3, 1, 2, 3]"
10.3.3 æ¼ç®å %
ã®ç¹ä¾
- 左辺ãæååãå³è¾ºããªã¹ãã®å ´å
左辺ããã³ãã¬ã¼ããå³è¾ºãå¤ã¨ãã¦printfãã©ã¼ãããããçµæã®æååãçæãã¾ãã(pythonã¨åæ§)
#set($printf_sample = '%d is a number, and %s is a string.' % [100, 'foo'])$printf_sample ## "100 is a number, and foo is a string."
10.3.4 æ¼ç®å +
ã®ç¹ä¾
- 左辺ãæååãå³è¾ºã¯ä»»æã®å
左辺ã¨ã å³è¾ºã®æååè¡¨ç¾ ãé£çµããæååãçæãã¾ãã
- 左辺ããªã¹ããå³è¾ºããªã¹ã
äºã¤ã®ãªã¹ããé£çµãããæ°ãããªã¹ããçæãã¾ãã
#set($two_lists = [1, 2] + [3, 4])$two_lists ## "[1, 2, 3, 4]"
10.3.5 æ¼ç®å -
ã®ç¹ä¾
- 左辺ãæååãå³è¾ºã¯ä»»æã®å
左辺ã®æååã«ã å³è¾ºã®æååè¡¨ç¾ ãå«ã¾ããå ´åããã®ãã¡æãå é ã«è¿ããã®ãåé¤ããæååãçæãã¾ãã
#set($barbaz1 = 'foobarbazfoobarbaz' - 'foo')$barbaz1 ## 左辺ããã"foo"ãä¸ã¤åé¤ããæååãããªãã¡ "barbazfoobarbaz"
#set($barbaz2 = 'foobarbazfoobarbaz' - 'foo' - 'foo')
$barbaz2 ## 左辺ããã"foo"ã2ã¤åé¤ããæååãããªãã¡ "barbazbarbaz"
#set($barbaz3 = 'foobarbazfoobarbaz' - 'foo' - 'foo' - 'foo')
$barbaz3 ## "foo"ã¯2ã¤ãããªãã®ã§ã3å以ä¸å¼ãç®ãã¦ãå¤åãªããããªãã¡ "barbazbarbaz"
- 左辺ããªã¹ããå³è¾ºããªã¹ã
左辺ã®ãªã¹ãã®è¦ç´ ãããå³è¾ºã®ãªã¹ãã®è¦ç´ ãå é ããé ã«åé¤ããæ°ãããªã¹ããçæãã¾ãã
#set($list = [1, 1, 1, 2, 2, 3, 2, 1] - [1, 1, 2])$list ## "1"ã2ã¤ã"2"ã1ã¤åé¤ããã®ã§ãæ®ãã¯"[1, 2, 3, 2, 1]"
10.3.6 æ¼ç®å <
, <=
, >
, >=
ã®ç¹ä¾
以ä¸ã®ããã«ãããå¤ã«å¯¾ããè¤æ°åã®æ¯è¼å¼ããä¸ã¤ã«ã¾ã¨ãã¦è¨è¿°ãããã¨ãå¯è½ã§ãã
#set($two = 2)##大æµã®ããã°ã©ãã³ã°è¨èªã®å ´åã
##ãã㯠"0 <= $two && $two < 3" ãªã©ã¨æ¸ãå¿ è¦ããã
#set($less_than_3 = (0 <= $two < 3))$less_than_3 ## "true"
10.4 æ¼ç®å =>>
ãã®æ¼ç®åã¯ãäºé æ¼ç®åã§ãããªã¹ãããããã¾ãã¯ã¤ãã¬ã¼ã¿ãè¿ãã¾ãã
ãã®æ¼ç®åã¯ã
- 左辺ã¯ãªã¹ã or ããã or ã¤ãã¬ã¼ã¿
- å³è¾ºã¯ é¢æ°
ã¨ããçµã¿åãã§ãªãã¦ã¯ãªãã¾ããã
ãã®æ¼ç®åãç解ããã«ã¯ãããå°ãvelã«ã¤ãã¦ã®ç¥èãå¿
è¦ã«ãªãããã
ãé¢æ°ã«ã¤ãã¦ã®é«åº¦ãªãããã¯ãã®ç« ã§è©³ãã解説ãããã¨ã¨ããããã§ã¯è§£èª¬ãã¾ããã
10.5 æ¼ç®å ;
ãã®æ¼ç®åã¯ãäºé
æ¼ç®åã§ããåç
§ãè¿ãã¾ãã
左辺ãå³è¾ºã¨ãã«ä»»æã®åã®å¤ãæå®ã§ãã¾ãã
ãã®æ¼ç®åã¯ã
- 左辺ã
null
㧠ãªã ãªãã°å·¦è¾ºã®å¤èªèº« - 左辺ã
null
ã®å ´åã¯ãå³è¾ºã®å¤
ãè¿ãã¾ãã
ãã®æ¼ç®åã¯ãä¸é
æ¼ç®åã®ç¹å¥ãªãã¼ã¸ã§ã³ã¨èãããã¨ãã§ãã¾ãã
ããã©ã«ãå¤ãè¨å®ãããå ´åãªã©ã«ä½¿ãã¾ãã
## $augendã¨$addendã足ãç®ããã
## ã§ãã$fooãnullã®å ´åãè¨ç®çµæããããããªã£ã¦ãã¾ãã®ã§ã
## $fooãnullã®å ´åã¯0ãããã©ã«ãå¤ã¨ãã¦è¨å®ããã
#set($augend = $foo ; 0)#set($addend = 1)
#set($add_result = $augend + $addend)
10.6 æ¼ç®å asserts
ãã®æ¼ç®åã¯ãäºé
æ¼ç®åã§ããåç
§ãè¿ãã¾ãã
左辺ãå³è¾ºã¨ãã«ä»»æã®åã®å¤ãæå®ã§ãã¾ãã
ãã®æ¼ç®åã¯ã以ä¸ã®åä½ãè¡ãªãã¾ãã
- å³è¾ºã
true
ã§ããå ´åã¯å·¦è¾ºã®å¤ãè¿ãã¾ã - å³è¾ºã
false
ã§ããå ´åã¯ã¨ã©ã¼ã¨ãªããã¹ã¯ãªããã®å®è¡ãç´ã¡ã«çµäºãã¾ã
ãã®æ¼ç®åã¯ãã¤ã³ã©ã¤ã³ã®ã¢ãµã¼ã·ã§ã³æ§æãæä¾ãã¾ãã
ä¾ãã°æ¬¡ã®ããã«è¨è¿°ãããã¨ã§ã $bar
ã®å¤ã 0
以ä¸ã§ãããã¨ã確èªããä¸ã§
$foo
ã«å¤ãè¨å®ã§ãã¾ãã
#set($foo = ($bar asserts (0 <= $bar)) )
10.6.1 æ¼ç®å same
ãã®æ¼ç®åã¯ãäºé æ¼ç®åã§ããbooleanå¤ãè¿ãã¾ãã
- 2ã¤ã®åç
§ã®åç
§å
ãåããªãã¸ã§ã¯ããæãã¦ãããªã
true
- ããã§ãªããªã
false
ã¤ã¾ãããã¤ã³ã¿ã®æ¯è¼ã§ãã
#set($list0 = [0, 1, 2])
#set($list1 = $list0)
#set($list2 = [0, 1, 2])#set($list0_same_list1 = ($list0 same $list1))
#set($list0_same_list2 = ($list0 same $list2))$list0_same_list1 ## "true"
$list0_same_list2 ## "false"
10.7 æ¼ç®å is
, isnt
æ¼ç®å is
ã¯ãäºé
æ¼ç®åã§ããbooleanå¤ãè¿ãã¾ãã
10.7.1 左辺ã¯ä»»æã®åãå³è¾ºã«æåååã®å¤
- 左辺ã®å¤ã®åããå³è¾ºã®æååã§æå®ãããåã«ä¸è´ãããªã
true
ã³ã¼ãä¾
#set($foo = 'foo')
#set($bar = 42)#set($foo_is_string = ($foo is 'string') )
#set($foo_is_number = ($foo is 'number') )
#set($bar_is_string = ($bar is 'string') )
#set($bar_is_number = ($bar is 'number') )$foo_is_string ## "true"
$foo_is_number ## "false"$bar_is_string ## "false"
$bar_is_number ## "true"
10.7.2 左辺ã¯ä»»æã®åãå³è¾ºã¯ null
- 左辺ã®å¤ã
null
ãªãtrue
ã³ã¼ãä¾
#set($foo = null)
#set($bar = 42)#set($foo_is_null = ($foo is null) )
#set($bar_is_null = ($bar is null) )
#set($baz_is_null = ($baz is null) ) ##å®ç¾©ããã¦ããªãåç §ã¯ã常ã«nullã§ãããã¨ã«æ³¨æ$foo_is_null ## "true"
$bar_is_null ## "false"
$baz_is_null ## "true"
10.7.3 左辺ã¯ç¹å®ã®åãå³è¾ºã¯ 'empty'
- 以ä¸ã®ã±ã¼ã¹ã«è©²å½ããå ´åã«
true
- 左辺ã空æåå
- 左辺ã空ãªã¹ã
- 左辺ã空ããã
10.7.4 ãã®ä»ãå³è¾ºã«æå®å¯è½ãªæåå
- æ¬ããã¥ã¡ã³ãã§ãæ¢ã«ç»å ´æ¸ã¿ã®å
- 'string' â æååå
- 'number' â æ´æ°å
- 'decimal' â å°æ°å
- 'list' â ãªã¹ãå
- 'map' â ãããå
- 'boolean' â ãã¼ãªã¢ã³å
- æªç»å ´ã®å
- 'bytes' â ãã¤ãé åå
- 'date' â æ¥ä»å
- 'function' â é¢æ°å
- 'template' â ãã³ãã¬ã¼ãå
- 'functable' â é¢æ°ãã¼ãã«å
- 'builtin_obj' â ãã«ãã¤ã³ãªãã¸ã§ã¯ãå
- 'object' â ãªãã¸ã§ã¯ãå
10.7.5 isnt
ã«ã¤ãã¦
æ¼ç®å isnt
(isn'tã®æå³) ã¯ã is
ã®å¦å®ã§ããããªãã¡ã
not ($x is 'yyy')
ã¨ããå¼ã¨ã $x isnt 'yyy'
ã¯ç価ã§ãã
#set($foo = 'foo')#set($not_number1 = not ($foo is 'number'))
#set($not_number2 = $foo isnt 'number')$not_number1 ## "true"
$not_number2 ## "true"
10.8 æ¼ç®å =~
ãã®æ¼ç®åã¯ãäºé
æ¼ç®åã§ããbooleanå¤ãè¿ãã¾ãã
左辺ãå³è¾ºã¨ãã«æåååã®å¤ãæå®ãã¾ãã
æ£è¦è¡¨ç¾ãããã³ã°ãè¡ãªãããã®çµæãbooleanã§è¿ãã¾ãã
ãã®æã左辺ã¯ãããã³ã°å¯¾è±¡æååãå³è¾ºã¯æ£è¦è¡¨ç¾ãã¿ã¼ã³ã§ã(Rubyã®ããã«å·¦å³é転ã¯ã§ãã¾ãã)ã
使ç¨ãã¦ããæ£è¦è¡¨ç¾ã¨ã³ã¸ã³ã¯ãJDKæ¨æºæ·»ä»ã®ãã®ã§ãã
å¾ã£ã¦ãæ±ããæ£è¦è¡¨ç¾ã¯JDKããµãã¼ããã¦ãããã®ã«ãªãã¾ãã
#set($foo = 'abc123cdf')#set($match_result = ($foo =~ '^[a-z]+[0-9]+[a-z]+$'))
$match_result ## "true"
ã¾ããæå®ããæ£è¦è¡¨ç¾ãã¿ã¼ã³ã«ã¯ããªãã·ã§ã³ãæå®ã§ãã¾ãã
ãªãã·ã§ã³ãæå®ããå ´åãæ£è¦è¡¨ç¾ãã¿ã¼ã³ã¯
/[regex pattern]/[options]
ã®ããã«è¨è¿°ãã¾ãã
options
ã«æå®ã§ãããªãã·ã§ã³ã¯ãJDKã®æ£è¦è¡¨ç¾ã«ããã åãè¾¼ã¿ãã©ã° ã¨ãã¦æå®ã§ãããã®ã§ãã
åãè¾¼ã¿ãã©ã°ã¨ãã¦ä½¿ç¨ã§ãããã®ã¯ã以ä¸ã®éãã§ãã
詳ããã¯ãJDKããã¥ã¡ã³ããåç
§ãã¦ãã ããã
m
: ã¡ã¿ãã£ã©ã¯ã¿^
ã¨$
ããå ¥åæååã®å é ã¨æ«å°¾ã§ãªããè¡é ã¨è¡æ«ã«ãããããããã«ãªãã¾ããi
: 大æåå°æåã®å¥ãç¡è¦ãã¾ããs
: ã¡ã¿ãã£ã©ã¯ã¿.
(ããã)ããæ¹è¡æåã«ããããããããã«ãªãã¾ããd
: UNIXæ¹è¡æå(LF)ã®ã¿ãæ¹è¡æåã¨ãã¦èªèããããã«ãªãã¾ããu
: ãªãã·ã§ã³i
ãæå®ããéã«ãã¦ãã³ã¼ãæåã対象ã«å«ããããã«ãã¾ããx
: ãã¿ã¼ã³å ã®ç©ºç½æåãç¡è¦ããã³ã¡ã³ããå ¥ãããã¨ã許å¯ãã¾ãã
以ä¸ã«ããªãã·ã§ã³æå®ãããããã³ã°ã®ä¾ã示ãã¾ãã
#set($foo = 'abc123CDF')#set($match_result1 = ($foo =~ '^[A-z0-9]+$'))
#set($match_result2 = ($foo =~ '(?i)^[a-z]+[0-9]+[a-z]+$')) ## '(?i)' ã¯JDKã®æ£è¦è¡¨ç¾ã§ãµãã¼ãããã¦ããåãè¾¼ã¿ãªãã·ã§ã³$match_result1 ## "true"
$match_result2 ## "true"
ãªããæ£è¦è¡¨ç¾ãperl風ã«è¨è¿°ãããã¨ãã§ãã¾ãã
#set($foo = 'abc123CDF')#set($match_result1 = ($foo =~ '/^[A-z0-9]+$/'))
#set($match_result2 = ($foo =~ 'm/^[a-z]+[0-9]+[a-z]+$/i')) ## 'm'ãä»ãã¦ããã$match_result1 ## "true"
$match_result2 ## "true"
ãã ããæ£è¦è¡¨ç¾ãªãã©ã«ã¯ãµãã¼ãããã¦ãã¾ããã
ããªãã¡ã
#if( $foo =~ /^[A-z0-9]+$/ )
ã®ããã«è¨è¿°ãããã¨ã¯ã§ãã¾ããã
ã¾ããperl風ã®è¨æ³ã§ãµãã¼ããã¦ããã®ã¯ãããã³ã°ã ãã§ãã
ç½®æ( s/.../.../
, tr/.../.../
)ã¯ä½¿ãã¾ããã
10.9 æ¼ç®å has
ãã®æ¼ç®åã¯ãäºé æ¼ç®åã§ããbooleanå¤ãè¿ãã¾ãã
左辺ã¯ã
- æåå
- ãªã¹ã
- ããã
ã®ã©ããã§ããå³è¾ºã¯ãä»»æã®åãæå®ã§ãã¾ãã
10.9.1 左辺ãæååã®ç¹ä¾
- 左辺ã®æååä¸ã«ã å³è¾ºã®æåå表ç¾ãå«ã¾ãã¦ãã ãªã
true
- ãã以å¤ãªã
false
ä¾
#set($foobar = 'foobar')#set($has_foo = ($foobar has 'foo') )
#set($has_bar = ($foobar has 'bar') )
#set($has_baz = ($foobar has 'baz') )$has_foo ## "true"
$has_bar ## "true"
$has_baz ## "false"
10.9.2 左辺ããªã¹ãã®ç¹ä¾
- 左辺ã®ãªã¹ãããå³è¾ºã®å¤ã«çããè¦ç´ ã1ã¤ä»¥ä¸å«ãã§ãããªã
true
- ãã以å¤ãªã
false
ä¾
#set($one_two = [1, 2])#set($has_one = ($one_two has 1) )
#set($has_two = ($one_two has 2) )
#set($has_three = ($one_two has 3) )$has_one ## "true"
$has_two ## "true"
$has_three ## "false"
10.9.3 左辺ããããã®ç¹ä¾
- 左辺ã®ãããããå³è¾ºã§ç¤ºããããã¼ãä¿æãã¦ãããªã
true
- ãã以å¤ãªã
false
ä¾
#set($foobar = {foo:1, bar:2})#set($has_foo = ($foobar has 'foo') )
#set($has_bar = ($foobar has 'bar') )
#set($has_baz = ($foobar has 'baz') )$has_foo ## "true"
$has_bar ## "true"
$has_baz ## "false"
10.10 æ¼ç®å &
ãã®æ¼ç®åã¯ãäºé
æ¼ç®åã§ãã
ããã¤ãã®å¤ã®çµã¿åãããããã¾ãããã®çµã¿åããã«ãããè¨ç®çµæã®åãç°ãªãã¾ãã
10.10.1 左辺ãå³è¾ºã¨ãã«æ°å¤
左辺ãå³è¾ºã®ä¸¡æ¹ã64bit符å·ä»ãæ´æ°å¤ã«å¤æããä¸ã§ãbitç©ãè¨ç®ãã¾ãã
#set($bit_and = 7 & 14)$bit_and ## "6"
10.10.2 左辺ãå³è¾ºã¨ãã«boolean
左辺ã¨å³è¾ºã®è«çç©ãè¨ç®ãã¾ãã
10.10.3 左辺ãå³è¾ºã¨ãã«ãªã¹ã
左辺ãå³è¾ºã¨ãã«ãªã¹ãã®å ´åã
å³è¾ºã¨å·¦è¾ºã®ãªã¹ãã®ã©ã¡ãã«ãå«ã¾ãã¦ããè¦ç´ ã ããå«ããæ°ãããªã¹ã ãè¿ãã¾ãã
ã¤ã¾ãã左辺ã¨å³è¾ºã®ãªã¹ããéåã¨ã¿ã¦ããã®éåã®ç©ãåå¾ããã¨ãããã¨ã§ãã
ã¾ãã以ä¸ã®æ§è³ªãããã¾ãã
- ãªã¹ãå ã§éè¤ãã¦ããè¦ç´ ãåå¨ããå ´åãæåã®è¦ç´ ã ãã対象ã¨ãªããæ®ãã¯ç¡è¦ãã¾ãã
- è¨ç®çµæã®ãªã¹ãã«ãããè¦ç´ ã®é åºã¯ã å³è¾ºã®ãªã¹ãã«ãããé åº ãé©ç¨ãã¾ãã
ä¾
#set($fib_even = [1, 2, 3, 5, 8, 13] & [12, 10, 8, 6, 4, 2, 0])$fib_even ## [8, 2]
#set($empty = [0..10] & )
$empty ## ""
10.10.4 左辺ãå³è¾ºã¨ãã«ããã
左辺ãå³è¾ºã¨ãã«ãããã®å ´åã以ä¸ã®è¨ç®çµæãçæãã¾ãã
- ã¾ãã 左辺ã¨å³è¾ºã®ãããã®ã©ã¡ãã«ãå«ã¾ãã¦ãããã¼ ãæ½åºãã
- æ½åºããããã¼ã®å¤ãã å³è¾ºã®ãããããåãåºã㦠æ°ããããããä½æãã
ã¤ã¾ãã左辺ã¨å³è¾ºãããããã®ããããä¿æãããã¼éåã®ç©ãåå¾ããã¨ãããã¨ã§ãã
#set($map = {foo:1, bar:2, baz3:, qux:4} & {foo:'FOO', baz:'BAZ', hoge:'HOGE', moge:'MOGE'})$map ## "{foo:'FOO', baz:'BAZ'}"
10.10.5 左辺ãããããå³è¾ºããªã¹ã
以ä¸ã®è¨ç®çµæãçæãã¾ãã
- ã¾ãã 左辺ã®ãã¼éåã¨å³è¾ºã®ãªã¹ãã®ã©ã¡ãã«ãå«ã¾ãã¦ããå¤ ãæ½åºãã
- æ½åºãããå¤ããã¼ã¨ã¿ãªãã左辺ã®ãããããå¤ãåãåºãã¦æ°ããããããçæãã
ã¤ã¾ãã左辺ã®ãããã«å¯¾ããå³è¾ºã®ãªã¹ãã§(ãã¼éåã¨ã¿ãªãã¦)ãã£ã«ã¿ãæããã¨ãããã¨ã§ãã
10.10.6 左辺ããªã¹ããå³è¾ºãããã
左辺ã¨å³è¾ºãå
¥ãæ¿ããä¸ã§ãå度 &
æ¼ç®åãé©ç¨ãã¾ãã
10.10.7 ä¸è¨ä»¥å¤ã®ã±ã¼ã¹
ä¾å¤ãã¹ãã¼ãã¾ãã
10.11 æ¼ç®å |
ãã®æ¼ç®åã¯ãäºé
æ¼ç®åã§ãã
æ¼ç®å &
ã¨åæ§ã«ãããã¤ãã®å¤ã®çµã¿åãããåå¨ãã¾ãã
10.11.1 左辺ãå³è¾ºã¨ãã«æ°å¤
左辺ãå³è¾ºã®ä¸¡æ¹ã64bité·æ´æ°å¤ã«å¤æããä¸ã§ãbitåãè¨ç®ãã¾ãã
#set($bit_or = 7 & 14)$bit_or ## "15"
10.11.2 左辺ãå³è¾ºã¨ãã«boolean
左辺ã¨å³è¾ºã®è«çåãè¨ç®ãã¾ãã
10.11.3 左辺ãå³è¾ºã¨ãã«ãªã¹ã
左辺ãå³è¾ºã¨ãã«ãªã¹ãã®å ´åã
å³è¾ºã¨å·¦è¾ºã®ãªã¹ãã®ã©ã¡ããã«å«ã¾ãã¦ããè¦ç´ ãå«ããæ°ãããªã¹ã ãè¿ãã¾ãã
ã¤ã¾ãã左辺ã¨å³è¾ºã®ãªã¹ããéåã¨ã¿ã¦ããã®éåã®åãåå¾ããã¨ãããã¨ã§ãã
ã¾ãã以ä¸ã®æ§è³ªãããã¾ãã
- ãªã¹ãå ã§éè¤ãã¦ããè¦ç´ ãåå¨ããå ´åãæåã®è¦ç´ ã ãã対象ã¨ãªããæ®ãã¯ç¡è¦ãã¾ãã
- è¨ç®çµæã®ãªã¹ãã«ãããè¦ç´ ã®é åºã¯ã以ä¸ã®æ³åã«å¾ãã¾ãã
- 左辺ã«å«ã¾ãã¦ããè¦ç´ ã¯ãå³è¾ºã«å«ã¾ãã¦ããè¦ç´ ããå ã«åºç¾ãã
- 左辺ã«å«ã¾ãã¦ããè¦ç´ ãªãã°ã左辺ã®ãªã¹ãã®é åº
- 左辺ã«ã¯å«ã¾ãã¦ããããå³è¾ºã®ã¿ã«å«ã¾ãã¦ããè¦ç´ ãªãã°ãå³è¾ºã®ãªã¹ãã®é åº
ä¾
#set($or_list = [2, 4, 6, 8, 10, 12] | [3, 6, 9, 12, 15])$or_list ## "[2, 4, 6, 8, 10, 12, 3, 9, 15]"
10.11.4 左辺ãå³è¾ºã¨ãã«ããã
+
æ¼ç®åãé©ç¨ããå ´åã¨åä¸ã®çµæ(ãããã®è¶³ãç®)ãçæãã¾ãã
10.11.5 左辺ãããããå³è¾ºããªã¹ã
å³è¾ºã®ãªã¹ãã®è¦ç´ ã®ãã¡ã左辺ã®ãããã®ãã¼ã¨ãªã£ã¦ããªããã®ãã
ãã¼ã¨ãã¦è¿½å (å¤ã¯ null
)ãããæ°ããããããè¿ãã¾ãã
ã¾ãããã¾ãå½¹ã«ç«ããªãã®ã§ä½¿ããã¨ã¯ãªãã§ãããã
ä¾
#set($filtered = {foo:1, baz:3} | ['foo', 'bar', 'baz'])$filtered ## "{foo:1, bar:null, baz:3}"
10.11.6 左辺ããªã¹ããå³è¾ºãããã
左辺ã¨å³è¾ºãå
¥ãæ¿ããä¸ã§ãæ¼ç®å |
ãå度é©ç¨ãã¾ãã
ãããããã¾ãå½¹ã«ç«ã¡ã¾ããã
10.11.7 ä¸è¨ä»¥å¤ã®ã±ã¼ã¹
ä¾å¤ãã¹ãã¼ãã¾ãã
10.12 æ¼ç®å &&
, ||
, ^^
é常ã®è«çæ¼ç®åã¨åä¸ã§ãããã£ã¦è§£èª¬ã¯çç¥ãã¾ãã
10.13 æ¼ç®å [cond] then [if cond true] else [if cond false]
ããã¯ä¸é æ¼ç®åã§ãã
æ®éã®è¨èªã§ã¯ã [cond] ? [if cond true] : [if cond false]
ã¨æ¸ãã¤ãã§ãã
åä½çã«ã¯æ®éã®ä¸é æ¼ç®åã¨åä¸ãªã®ã§ã解説ã¯çç¥ãã¾ãã