2011/12/17
ç¯å²ã®æå®
Schemeã§ã¯ãããããããã¾ã§ãã¨ããç¯å²ãæå®ããã®ã«ã
å§ç¹(å§ç¹èªèº«ã¯å«ã¾ãã)ã¨çµç¹(çµç¹èªèº«ã¯å«ã¾ããªã)ã®half-open intervalã
使ããã¨ãå¤ããSRFI:13(string library)ãSRFI:43(vector library)
ãªã©ã®ä»£è¡¨çãªSRFIãããã ããGaucheãããã«åããã¦ããããã [å§ç¹,çµç¹)
ã¨æ¸ããã¨ã«ãããã
ãã®ä»ã«ä»£è¡¨çãªæµåã¨ãã¦ã¯ãå§ç¹ã¨çµç¹ãã¨ãã«å«ã¾ããã¨ããclosed intervalã
ããããå§ç¹ã¨é·ããããããããã [å§ç¹,çµç¹]
, {å§ç¹,é·ã}
ã¨ãããã
Schemeã§ã¯SRFI:1ã®iotaãä¾å¤çã«{å§ç¹,é·ã}
ãåããä½ãå¼æ°é ã¨ãã¦ã¯é·ãã®æ¹ãå
ã§ãå§ç¹ã¯çç¥å¯è½ãçç¥æ0ã¨ããå½¢ã3çªç®ã®å¼æ°ã¨ãã¦ã¹ããããåããã¨ãã§ããã
Pythonã®array slicingã¯[å§ç¹,çµç¹)
ããªãã·ã§ãã«ã§ã¹ããã(ã¹ãã©ã¤ã)ã
Common Lispã®loop
ãã¯ãã¯ã[å§ç¹,çµç¹]
ã¨[å§ç¹,çµç¹)
ã®ã©ã¡ãã使ãããåè
ã¯fromãtoã¨ãfromãdowntoãå¾è
ã¯fromãbelowã¨fromãaboveã
Rubyã¯ã©ãã使ãããé
åã§x[a,b]ã¨ããã°{å§ç¹,é·ã}
, ããã«rangeãªãã¬ã¼ã¿ã2種é¡ãã£ã¦[å§ç¹,çµç¹]
ã¨[å§ç¹,çµç¹)
ã«å¯¾å¿ã
ãã®3æ¹å¼ã¯å®¹æã«ç¸äºå¤æå¯è½ãªã®ã§ãã©ããæ¡ç¨ãããã¯å¥½ã¿ã®åé¡ãä¸è²«æ§ãããã°ããããã¨ä»ã¾ã§ã¯æã£ã¦ããã
ã¨ããããã¨ããAPIãèãã¦ãã¦ã2ã¤ã®ãã©ã¡ã¼ã¿ã§ç¯å²æå®ããããã¤æé ã¨éé ã®åºå¥ãåºæ¥ãããããªãã¨èãã¦ããããã®3æ¹å¼ã«è¡¨ç¾åã®éãããããã¨ã«æ°ã¥ãããæ£ç¢ºã«ã¯ãã¤ã³ããã¯ã¹ã®round trip (-1, -2 ãªã©è² ã®ã¤ã³ããã¯ã¹ã§ãçµç«¯ããã®è·é¢ãæ°ããå ´åãä¾ãã°pythonã§a[0:-1]ã¨ããã°æå¾ã®è¦ç´ ãé¤ããé åãå¾ãããããªã©) ã使ããã¨ããå ´åãã ããã©ã
{å§ç¹,é·ã}
ã¯ãé·ããè² ã®å ´åã«éé ã¨ãããã¨ããã«ã¼ã«ãå ¥ããã°ãã対å¿ã§ãããã¤ã³ããã¯ã¹ã®round tripãç¹ã«åé¡ãªããä½ãããæå¾ãã3çªç®ã®è¦ç´ ãèµ·ç¹ã«æåã®è¦ç´ ã¾ã§ãéé ã§ãã®ããã«åãããæã«ãç¯å²ã®é·ããé½ã«ä¸ããå¿ è¦ããã (æé ãªãããé·ãçç¥æãæå¾ã®è¦ç´ ã¾ã§ãã¨ãã¦ãããã®ã«)ã対称ã§ãªãã®ã¯ã¡ãã£ã¨æ°æã¡ãããã[å§ç¹,çµç¹]
ã§ã¯ å§ç¹>çµç¹ ã®æã«éé ã¨ãããã¨ãããã«æãã¤ãããround tripãããã¨åç´ãªå¤§å°æ¯è¼ãã§ããªããå§ç¹ã¨çµç¹ãããããmodulo(ç¯å²ã®å¤§ãã)ããå¾ã§å¤§å°æ¯è¼ããã°ä½ã¨ããªããè¥å¹²ãç´æçã§ãªãå ´åã¯åºã¦ããã[å§ç¹,çµç¹)
ãå°ããã®ãããå¤ããéé ã«å é ã¾ã§ãå ¥ãããæã«ã¯ããã¼ãããä¸ã¤åããçµç¹ã¨ãã¦æå®ããå¿ è¦ããããããã-1ã«ãã¦ãã¾ãã¨ããçµç«¯ããã²ã¨ã¤æåããæå®ããã®ã¨åºå¥ãã¤ããªããè¨ãæããã°ããã®æ¹å¼ã§ã¯ãä¸çªæå¾ã®è¦ç´ +1ãã¨ãä¸çªæåã®è¦ç´ -1ããå¥ã ã«è¡¨ç¾ããå¿ è¦ããã£ã¦ããã®å表è¨ã«ããªã¨ã¼ã·ã§ã³ãå¿ è¦ã«ãªãã¨ãããã¨ã ãendçç¥æã«ãæå¾ã®è¦ç´ +1ãæããã¨ããå ´åã¯å¤ããããçç¥ããããã¨ããã®ã¯1種é¡ã®æ å ±ã§ãããªãã®ã§ãéé ã表ç¾ããã®ã«å¥ã®æ å ±ãå¿ è¦ã«ãªãã
Luaã¿ããã«ã¤ã³ããã¯ã¹ã1ããã¹ã¿ã¼ããããã¨ã«ããã°0ããæåã®è¦ç´ ã®ã²ã¨ã¤åãã¨ãããã¨ãåºæ¥ãããã®ç¹ã§ã¯1-ãã¼ã¹ã®ã¤ã³ãã¯ã·ã³ã°ã«å©ç¹ãããã¨ãè¨ãããªãã
Tag: Programming
Post a comment