Io Language/Tutorial
IoLanguage/Tutorial ¶
¼Ò°³ ¶
¼³Ä¡ ¶
> wget http://io.urbanape.com/release/Io-2007-02-19.tar.gz Io> ¿Í °°Àº ÇÁ·ÒÇÁÆ®°¡ ¶á´Ù¸é ÀÎÅÍÇÁ¸®Å͸¦ ½ÇÇà½ÃÅ°´Âµ¥ ¼º°øÇÑ °ÍÀÔ´Ï´Ù.
HelloWorld! ¶
aObject otherMethod(arg1, arg2, arg) 42 À̳ª 3.14 °°Àº ´Ù¸¥ ¾ð¾î¿¡¼ ÈçÈ÷ ºÁ¿Â Á¤¼ö, ½Ç¼ö Ç¥ÇöÀ» ¶È°°ÀÌ ÀÌ¿ëÇÏ¿© ¼ýÀÚ¸¦ Ç¥ÇöÇÕ´Ï´Ù. ¶ÇÇÑ Á¤¼öÀÌ°Ç ½Ç¼öÀÌ°Ç °£¿¡ µÑ ´Ù °°Àº Number °´Ã¼¸¦ ºÎ¸ð·Î ÇÕ´Ï´Ù. ÀÌ Number °´Ã¼·ÎºÎÅÍ ³ª¿Â °´Ã¼À̱⠶§¹®¿¡ 42 Àº Number°´Ã¼°¡ Á¦°øÇÏ´Â ¸Þ¼µå¸¦ ÀÌ¿ëÇÒ ¼ö ÀÖ½À´Ï´Ù. ¿¹¸¦ µé¾î¼ ´ÙÀ½Ã³·³ Number°´Ã¼ÀÇ ¸Þ¼µåµéÀ» ÀÌ¿ëÇÒ ¼ö ÀÖ½À´Ï´Ù.
Io> 42 factorial ... Io> 255 asHex ... Io> 2 pow(3) ... Io> 2 ** 3 ... Io> 2 **(3) factorial ¿Í asHex Àº ´Ü¼øÇÕ´Ï´Ù. ¾Æ¹«·± ÀÎÀÚ¾øÀÌ ±× ¼ýÀÚÀ» ÀÎÀÚ·ÎÇؼ °á°ú¸¦ ¸¸µé¾îÁÝ´Ï´Ù. ÇÏÁö¸¸ pow(n) Àº ÀÎÀÚ¸¦ ÇÊ¿ä·Î ÇÕ´Ï´Ù. ÀÌ °æ¿ì¿¡´Â À§¿¡¼ º¸´Â °Íó·³ °ýÈ£·Î ±× ÀÎÀÚ¸¦ ¹¾îÁÝ´Ï´Ù. ¿©±â¿¡ ÇÑ°¡Áö ¿¹¿Ü°¡ Àִµ¥ ÀϹÝÀûÀ¸·Î »ê¼ú¿¬»êÀÚ·Î ¾²ÀÌ´Â ¿¬»êÀÚÀÇ °æ¿ì¿¡´Â ÀÌ·¸°Ô °ýÈ£¸¦ Ä¡Áö ¾Ê¾Æµµ ÀÌ ¸Þ¼µå¸¦ ½ÇÇàÇÏ´Â ¸Þ½ÃÁö¸¦ º¸³»´Â °ÍÀ¸·Î ÀÌÇØÇÕ´Ï´Ù. 2 ** 3 Àº 2 **(3) ÀÇ SyntaticSugarÀÔ´Ï´Ù. (ÀÌ·¸°ÔÇؼ ´Ù¸¥ ¾ð¾î°¡ Á¦°øÇÏ´Â °Íó·³ »ê¼ú¿¬»êÀÚ¸¦ ÀÌ¿ëÇÒ ¼ö ÀÖÀ¸¸é¼ ¿¬»êÀÚ¸¦ ÀçÁ¤ÀÇÇϰųª ¸Þ¼µå¸¸À¸·Î À̸¦ ±¸ÇöÇÕ´Ï´Ù.) ¶ÇÇÑ À̸¦ ¸Þ½ÃÁöÀü´Þ·Î ±¸ÇöÇÑ ´Ù¸¥ ¾ð¾îÀÎ SmalltalkLanguage¿Í´Â ´Ù¸£°Ô ¿¬»êÀÚÀÇ ¿ì¼±¼øÀ§¸¦ °®½À´Ï´Ù.
Io> 4+5*2 ==> 14¿¬»êÀÚÀÇ Æò°¡¼ø¼¸¦ ¹Ù²Ù°íÀÚ ÇÑ´Ù¸é °ýÈ£¸¦ ÀÌ¿ëÇؼ °¨½ÎÁÖ¸é °ýÈ£ºÎÅÍ Æò°¡ÇÕ´Ï´Ù. Io> (4+5)*2 ==> 18¸Þ½ÃÁöÀü´Þ°ú PrototypeBasedLanguageÀÇ Æ¯Â¡¿¡ ´ëÇؼ ´õ ¼³¸íÇÒ °ÍÀÌ ³²¾ÆÀÖÁö¸¸ ÀÌ ¹®¼ÀÇ ³ªÁßÀ¸·Î ¹Ì·ç°í ¿ì¼±Àº ¿ì¸®ÀÇ ÂªÀº ÄÚµå·Î µ¹¾Æ°¡¼ ¼³¸íÀ» °è¼ÓÇÏ°Ú½À´Ï´Ù. ¾Æ±î ¼³¸íÇÏ·Á´ø ÄÚµåÁ¶°¢Àº ºÐ¸íÈ÷ 1 ¿¡ ´ëÇؼ ±× ¸Þ¼µå to(n) À» ½ÇÇàÇϴµ¥ ÀÎÀڷμ 5 À» ³Ñ°ÜÁÖ´Â ÄÚµåÀÔ´Ï´Ù. ´ÙÀ½Ã³·³ 1 to(5) À» ÀÎÅÍÇÁ¸®ÅÍ¿¡ ÀÔ·ÂÇÏ¸é ±× °á°ú¸¦ º¸¿©ÁÝ´Ï´Ù.
Io> 1 to(5) ==> Range_0x8699b90:À̴ ǥÇö½ÄÀÇ °á°ú°¡ Range°´Ã¼ÀÇ ÀÚ½ÄÀÓÀ» ¸»ÇØÁÝ´Ï´Ù. Range°´Ã¼´Â ¼ýÀÚÀÇ ¹üÀ§¸¦ ³ªÅ¸³»´Âµ¥ »ç¿ëÇÕ´Ï´Ù. ½ÇÁ¦·Î ¸®½ºÆ®³ª ¹è¿°ú °°Àº ÀÚ·áÇüó·³ ±× óÀ½°ú ³¡±îÁöÀÇ ¸ðµç ¿ä¼Ò¸¦ °®´Â ÀÚ·áÇüÀÌ ¾Æ´Ï¶ó óÀ½°ª°ú ³¡°ª, ±×¸®°í óÀ½°ªÀÌ ³¡°ªÀÌ µÇ±â À§ÇÑ ´Ü°è°ª¸¸À» °®´Â ÀڷᱸÁ¶ÀÔ´Ï´Ù. °£´ÜÇÏ°Ô ¸»Çؼ Range°´Ã¼¸¦ ÀÌ¿ëÇؼ 1¿¡¼ 5±îÁöÀÇ °¢ ´Ü°è°ªµéÀ» ³ª¿ÇÒ ¼ö ÀÖ½À´Ï´Ù.
48879 asHexÀ§ÀÇ ÄÚµå´Â 48879¿¡ ÇØ´çÇÏ´Â 16Áø¼ö¸¦ ¹®ÀÚ¿·Î µÇµ¹·ÁÁÝ´Ï´Ù. ÇÏÁö¸¸ ¾à°£ º¯´öÀ» ºÎ·Á¼ ÀÌ 16Áø¼ö¸¦ ´ë¹®ÀڷΠǥÇöÇÏ°íÀÚ ÇÑ´Ù¸é String°´Ã¼ÀÇ asUppercase ¸Þ¼µå¸¦ »ç¿ëÇؼ À̸¦ º¯È¯ÇÒ ¼ö ÀÖ½À´Ï´Ù. 48879 asHex asUppercaseÀÌ´Â °á°ú°ª¿¡ ´ëÇؼ ¿¬µ¿ÇÏ¿© »õ·Î¿î °á°ú¸¦ ¸¸µå´Â ¹æ¹ýÀ¸·Î IoLanguage¿¡¼ ÈçÇÏ°Ô »ç¿ëµË´Ï´Ù. (´Ù¸¥ ¾ð¾î¿¡ Àͼ÷ÇÑ ºÐµéÀº ÇϳªÀÇ Æò°¡½ÄÀ» ÇÑ º¯¼ö¿¡ ³Ö°í, ´Ù½Ã ±× º¯¼ö¸¦ º¯È¯´Â ÀÏÀÌ ÈçÇÕ´Ï´Ù.) 1 to(5) foreach(n, ...) : ÀÌ ºÎºÐ ¶ÇÇÑ IoLanguageÀÇ Æ¯Â¡À» Àß º¸¿©Áִ ǥÇö½ÄÀÔ´Ï´Ù. IoLanguage¿¡´Â Å°¿öµå³ª ¿¹¾à¾î°¡ ¾ø°í ±×·¯¹Ç·Î °íÁ¤µÈ Á¦¾î±¸Á¶ ¶ÇÇÑ ¾ø½À´Ï´Ù. ´ë½Å¿¡ ÀÌ·¸°Ô °´Ã¼ ´ëÇÑ ¸Þ¼µå·Î¼ ÄÚµåºí·°À» ³Ñ°ÜÁ༠·çÇÁ³ª Á¦¾î±¸Á¶¸¦ ±¸ÇöÇÕ´Ï´Ù. ¿©±â¿¡¼´Â Range °´Ã¼ÀÇ foreach¸Þ¼µå¸¦ ÀÌ¿ëÇÕ´Ï´Ù. ÀÌ ¸Þ¼µå´Â 2°³ÀÇ ÀÎÀÚ¸¦ ÇÊ¿ä·Î Çϴµ¥ ù¹ø° ÀÎÀÚ´Â °¢ ´Ü°è°ªÀ» ¹ÙÀεùÇØÁÙ º¯¼öÀÇ À̸§(¿©±â¼´Â n)°ú µÎ¹ø°´Â ·çÇÁÀÇ °¢ ´Ü°èº°·Î ½ÇÇàÇÒ ÄÚµåºí·°ÀÔ´Ï´Ù. Áï, ´Ù½Ã ¸»Çؼ 1¿¡¼ºÎÅÍ 5±îÁö 1¾¿ Áõ°¡ÇÏ¸é¼ 1, 2, 3, 4, 5¿¡ ´ëÇؼ Â÷·Ê´ë·Î nÀ» ¼³Á¤ÇÏ°í µÎ¹ø° ÀÎÀÚ¸¦ ½ÇÇàÇÏ´Â °ÍÀÔ´Ï´Ù.
À̸¦ ¼ÕÀ¸·Î Ç®¾îº¸¸é ´ÙÀ½°ú °°½À´Ï´Ù.
n := 1; (n .. ": Hello, World!") n := 2; (n .. ": Hello, World!") ...±ÍÂú¾Æ¼±×¸¸»ý·«... n := 5; (n .. ": Hello, World!") ; Àº ¿©·¯Ç¥Çö½ÄÀ» ÇÑÁÙ¿¡ ÀûÀ» ¼ö ÀÖµµ·Ï Ç¥Çö½ÄÀ» ¼·Î ³ª´²ÁÖ´Â ¿ªÈ°À» ÇÕ´Ï´Ù.
»ç¿ë»óÀÇ ÆÁ ¶
¹®¹ý ¶º¸Åë ´Ù¸¥ ¾ð¾î¿¡¼ ¹®¹ý¿¡ ´ëÇÑ ºÎºÐÀº Ç×»ó ÀÌ·± ¹®¼ÀÇ µÞÂÊ¿¡ ºÎ·ÏÀ¸·Î À§Ä¡ÇÏÁö¸¸ ¹Ý´ë·Î ±× ÆäÀÌÁö¼ö´Â ¾öû³ª°Ô ¸¹½À´Ï´Ù. ÇÏÁö¸¸ IoLanguage¿¡¼´Â ±×·± Ä¿´Ù¶þ°í º¹ÀâÇÑ ¹®¹ýÀÌ ¾ø½À´Ï´Ù. ´ë½Å¿¡ ÀÌ ºÎºÐÀÌ °¡Àå ¾Õ¿¡ À§Ä¡ÇÏ´Â ÀÌÀ¯´Â ¸î°¡Áö ´Ü¼øÇÏ°í ¿ÏÀüÇÑ ¹®¹ý±ÔÄ¢À» ÀÌÇØÇÑ´Ù¸é ÀÌÈÄ¿¡ ³ª¿À´Â ¸ðµç ºÎºÐµéÀÌ ÀÌ ´Ü¼øÇÑ ¹®¹ý¿¡ ±âÃÊÇÑ °ÍÀ̶ó´Â Á¡ÀÌ ¸íÈ®Çϱ⠶§¹®ÀÔ´Ï´Ù.
¸Þ½ÃÁö Àü´Þ ¶»ç½Ç ¹®¹ýÀ» ³ª¿ÇÏ·Á°í Çصµ Èûµç°Ô ¹®¹ýÀ̶ó°í ºÎ¸¦¸¸ÇÑ°Ô ¾ø½À´Ï´Ù. IoLanguage¿¡´Â ¿ÀÁ÷ ¸Þ½ÃÁöÀü´Þ¸¸ÀÌ ÀÖ½À´Ï´Ù. ³ª¸ÓÁö´Â »ó¼ö¸¦ Ç¥ÇöÇÏ°í, ÁÖ¼®À» Ç¥½ÃÇÏ´Â Á¤µµÀÔ´Ï´Ù. ¸Þ½ÃÁö Àü´ÞÀ» °£·«ÇÏ°Ô Ç¥ÇöÇغ¸¸é ´ÙÀ½°ú °°½À´Ï´Ù.
Io> Dog bark Io> Person say("hello") Io> list(1, 2, 3) ¶ÇÇÑ ÀÌ·¸°Ô ¸Þ½ÃÁö¿¡ ³Ñ°ÜÁÖ´Â ¸ðµç ÀÎÀÚµéÀº ¾ðÁ¦³ª ¼ö½ÅÀÚ¿¡°Ô ³Ñ°ÜÁ®¼ ÇÊ¿äÇÑ ¶§¿¡¸¸ Æò°¡°¡ ÀÌ·ç¾îÁý´Ï´Ù. LispLanguage¿¡¼ ¸»ÇÏ´Â SpecialFormÀ̳ª ±×·±°ÍÀÌ ÇÊ¿ä¾øÀÌ ´Ü¼øÇÏ°Ô ¸Þ¼µå¸¦ ÅëÇؼ Á¦¾î±¸¹®À» Ç¥ÇöÇÒ ¼ö ÀÖÀ½À» ÀǹÌÇϸç, ´Ù¸¥ ¾ð¾î¿¡¼ ¸»ÇÏ´Â LazyEvaluation°ú ºñ½ÁÇÕ´Ï´Ù. ¸¸¾à ÀÎÀÚ¸¦ ÀÌ·¸°Ô Æò°¡ÇÏÁö ¾Ê°í, EagerEvaluationÀ¸·Î¼ JavaLanguage³ª PythonLanguageó·³ ÀÎÀÚ¸¦ Æò°¡ÇÑ´Ù¸é ´ÙÀ½ÀÇ ¿¹Á¦´Â ÀÛµ¿ÇÏÁö ¾ÊÀ» °ÍÀÔ´Ï´Ù. Io> 1 to(10) select(n, (n % 2)==0) °´Ã¼ ¸Þ½ÃÁö ¸Þ¼µåÀÌ ÄÚµå´Â 1¿¡¼ 10±îÁöÀÇ ¸ðµç ¦¼ö¸¦ ±¸ÇÕ´Ï´Ù. ÇÏÁö¸¸ ´Ù¸¥ ¾ð¾îÀÇ Æò°¡±ÔÄ¢À» Àû¿ëÇÑ´Ù¸é select ÀÇ ÀÎÀÚÀÎ n°ú "(n%2)==0"Àº °¢°¢ Æò°¡ÇÏ·Á°í Çؼ Àý´ë ÀÛµ¿ÇÏÁö ¾ÊÀ» °ÍÀÔ´Ï´Ù.
ÁÖ¼® ¶ÇÁ·Î±×·¥À» ÀÛ¼ºÇÏ¸é¼ Áß°£Áß°£ ÁÖ¼®À» ´Þ°í ½Í´Ù¸é ´ÙÀ½ ¼¼°¡Áö ½ºÅ¸ÀÏ ¸ðµÎ°¡ Çã¿ëµË´Ï´Ù.
/* C-style multiline */ // C++ style # Shell-style ¹®ÀÚ¿ ¶´ÙÀ½°ú °°ÀÌ 2°¡Áö ½ºÅ¸ÀÏÀÇ ¹®ÀÚ¿ Ç¥ÇöÀ» Áö¿øÇÕ´Ï´Ù.
Io> "foobar" Io> """multiple lines""" """ À¸·Î °¨½Ñ ¹®ÀÚ¿Àº ¿©·¯ÁÙ¿¡ °ÉÃļ Àû°Å³ª ±×¾È¿¡ ´Ù¸¥ ¹®ÀÚ¿À» Ç¥ÇöÇÒ ¼ö ÀÖ½À´Ï´Ù. ¶ÇÇÑ Cµî¿¡¼ Áö¿øÇÏ´Â ¹é½½·¡½¬¸¦ ÀÌ¿ëÇÑ EscapeCharacterÀÇ Ç¥Çöµµ °¡´ÉÇÕ´Ï´Ù.
¼ýÀÚ ¶Á¤¼ö, ½Ç¼ö, exponentÇ¥±â¹ý, 16Áø¼öÇ¥±âµîÀ» Áö¿øÇÕ´Ï´Ù.
123 123.456 0.456 .456 123e-4 123e4 123.456e-7 123.456e2 0x0 0x0F 0XeE ½½·Ô? ¸Þ¼µå? ¸Þ½ÃÁö? ¶Á¶±Ý ¶á±Ý ¾øÁö¸¸, °£´ÜÇÏ°Ô ¸î°¡Áö °³³äÀ» ¼Ò°³ÇØ µå¸®°í ½Í½À´Ï´Ù. ¾Ë°í ÀÖ´Â °ÍÀÌ´õ¶óµµ Ȥ½Ã³ª Á¦°¡ ¸»ÇÏ°íÀÚ ÇÏ´Â °Í°ú ´Ù¸¦ ¼ö ÀÖÀ¸¹Ç·Î Àо¸ç È®ÀÎÇØÁֽñ⠹ٶø´Ï´Ù.
¿¬»êÀÚ ¶IoLanguage¿¡¼ ¿¬»êÀÚ¶ó´Â ¸»Àº »ç½Ç ¼ýÀÚ¿Í ¿µ¹®ÀÚ·Î ÀÌ·ç¾îÁöÁö ¾ÊÀº À̸§À» °®´Â ¸Þ¼µå¸¦ ¸»ÇÕ´Ï´Ù. ÀÌ·¯ÇÑ ¸Þ¼µåµéÀº ÀÎÀÚ°¡ ÀÖ´õ¶óµµ °ýÈ£¸¦ »ý·«ÇÏ°í¼ È£ÃâÇÒ ¼ö ÀÖ½À´Ï´Ù. ¶ÇÇÑ or, and, return µîÀÇ ¹Ì¸® ÁöÁ¤µÈ ¿µ¾î´Ü¾îµé ¶ÇÇÑ ¿¬»êÀڷμ Ãë±ÞÇÕ´Ï´Ù. À̵éÀº ¸ðµÎ ¿¹¿ÜÀûÀÎ ±ÔÄ¢ÀÌÁö¸¸ »ç¿ë»óÀÇ ÆíÀǸ¦ À§Çؼ Á¦°øÇϴ°͵éÀÔ´Ï´Ù.
Io> 3 + 4 ==> 7 Io> 3 type ==> Number Io> Number slotNames ==> list(..., "+", ...) ´ëÀÔ¿¬»êÀÚ ¶´Ù¸¥ ¾ð¾î¿¡¼´Â º¯¼ö¸¦ À§ÇÑ À̸§°ø°£ÀÌ ÀÖ½À´Ï´Ù. IoLanguage¿¡¼´Â ¸ðµç °ÍÀÌ °´Ã¼·Î Ç¥ÇöµÇ¹Ç·Î À̸§°ø°£ ¶ÇÇÑ ¾î¶² °´Ã¼·Î Ç¥ÇöµÉ ÇÊ¿ä°¡ ÀÖ½À´Ï´Ù. ±×·¡¼ Àü¿ªº¯¼ö¿Í °°Àº °ÍÀ» À§ÇÑ À̸§°ø°£À» À§Çؼ Lobby°´Ã¼¸¦ Á¦°øÇÕ´Ï´Ù. ¾î·µç ÀÌ·¯ÇÑ ÇöÀç¶ó´Â ½ÃÁ¡¿¡¼ ¹ÙÀεùµÈ º¯¼öµéÀ» À§ÇÑ °ø°£ÀÌ ÇÊ¿äÇÕ´Ï´Ù. (ÀÌÈÄ¿¡ ¼³¸íÇÒ Æò°¡¹®¸Æ(EvaluationContext)¿¡¼ ÀÌ·¯ÇÑ °Í¿¡ ´ëÇؼ ³íÀÇÇÏ°Ú½À´Ï´Ù.) À̸¦ À§Çؼ »õ·Î¿î ¹æ¹ýÀ» Ãß°¡ÇÏÁö ¾Ê°í ´Ü¼øÈ÷ Lobby °´Ã¼¿¡ ½½·ÔÀ» Ãß°¡ÇÏ°í ±× ½½·ÔÀ» ÅëÇؼ º¯¼ö¸¦ ±¸ÇöÇÕ´Ï´Ù.
´ÙÀ½ÀÇ ÄÚµå´Â ÇöÀç Æò°¡¹®¸Æ¿¡ a¶ó´Â À̸§ÀÇ ½½·ÔÀ» ¸¸µé°í 1¿¡ ÇØ´çÇÏ´Â °´Ã¼ÀÇ ÂüÁ¶¸¦ ´ëÀÔÇÕ´Ï´Ù.
Io> a := 1 Io> a ==> 1´Ü¼øÈ÷ À̸§-°ªÀÇ °ü°èÀ̱⠶§¹®¿¡ DynamicTypingÀÌ °¡´ÉÇÕ´Ï´Ù. Io> a := 1 Io> a := "foobar"IoLanguage¿¡¼ ´ëÀÔ¿¬»êÀÚ´Â := ¿Í = °¡ ÀÖ½À´Ï´Ù. ÀüÀÚÀÇ °æ¿ì´Â ÀÌ¹Ì ½½·ÔÀÌ ÀÖÀ¸¸é ±âÁ¸ ½½·ÔÀ» ´ëüÇÏ°í, ½½·ÔÀÌ ¾øÀ¸¸é ½½·ÔÀ» »ý¼ºÇÕ´Ï´Ù. ÇÏÁö¸¸ ÈÄÀÚ´Â ½½·ÔÀÌ ¾øÀ¸¸é ¿¹¿Ü¸¦ ´øÁö°í ½½·ÔÀÌ ÀÖÀ»¶§¸¸ ½½·ÔÀ» ´ëüÇÕ´Ï´Ù.
true, false, and nil ¶Áø¸®°ªÀ» ³ªÅ¸³»´Â µÎ°¡Áö °ªÀÌ ÀÖ½À´Ï´Ù. Çϳª´Â ÂüÀ» ³ªÅ¸³»´Â true¿Í °ÅÁþ°ªÀ» ³ªÅ¸³»´Â falseÀÔ´Ï´Ù. À̵éÀº ±× ÀÚü·Î¼ Áø¸®°ªÀ» ³ªÅ¸³À´Ï´Ù. ¶ÇÇÑ ³í¸®¿¬»êÀ» ¼öÇàÇÏ´Â ¸Þ¼µåÀÇ °á°ú´Â Ç×»ó ÀÌ µÑ Áß ÇϳªÀÔ´Ï´Ù.
Io> (3 < 4) type ==> trueÀ̵éÀº ±× ÀÚü·Î¼´Â º° ±â´ÉÀÌ ¾øÁö¸¸ À̵é ÀÚü·Î¼µµ °´Ã¼À̱⠶§¹®¿¡ BooleanArithmeticÀ̳ª SmalltalkLanguage ½ºÅ¸ÀÏÀÇ Á¦¾î±¸Á¶¸¦ ¸¸µé°í ½ÍÀ» ¶§ À¯¿ëÇÕ´Ï´Ù. (balance >= amount) ifTrue("ok" println) ifFalse("not enough mineral!" println) ¶ÇÇÑ ´Ù¸¥ ¾ð¾î¿¡¼ null ÀÇ ¿ªÈ°À» ÇÏ´Â nil ÀÌ ÀÖ½À´Ï´Ù. ¾î¶°ÇÑ º¯¼ö(½½·Ô)°¡ ¾Æ¹«°Íµµ ÂüÁ¶ÇÏÁö ¾Ê°íÀÚ ÇÒ ¶§ À̸¦ »ç¿ëÇÕ´Ï´Ù.
Io> a := nil Io> a ifNil("void..." println) °´Ã¼ ¶IoLanguageÀÇ Æ¯Â¡ÀûÀÎ °³³äµéÀº ´Ù¸¥ ¾ð¾î¿¡¼ ãÀ» ¼ö ÀÖ´Â º¹ÀâÇÏ°í ¾î·Á¿ü´ø °³³äµéÀ» Àß ÅëÇÕÇÏ°í ÀÖ½À´Ï´Ù.
ÇÁ·ÎÅäŸÀÔ ¶IoLanguage¿¡¼´Â ÄÚµåºí·°ÀÇ Áö¿ªº¯¼ö¸¦ À§ÇÑ ÀúÀå°ø°£, À̸§°ø°£±îÁö Æ÷ÇÔÇÏ¿© ¸ðµç °ÍÀÌ °´Ã¼·Î Ç¥ÇöÇÕ´Ï´Ù. ±×¸®°í ´ëÀÔÀ» Æ÷ÇÔÇÑ ¸ðµç ÇàÀ§±îÁö ¸Þ½ÃÁö·Î Ç¥ÇöÇÕ´Ï´Ù. °´Ã¼´Â ½½·ÔÀ̶ó°í ºÒ¸®´Â 'Å°/°ª'½ÖÀÇ ¸ñ·Ï°ú ³»ºÎÀûÀ¸·Î °´Ã¼°¡ »ó¼Ó ¹ÞÀº °´Ã¼ÀÇ ¸ñ·ÏÀ» ÀúÀåÇÏ´Â
protos ¶ó ºÒ¸®´Â ¸ñ·ÏÀ¸·Î ÀÌ·ç¾îÁ® ÀÖ½À´Ï´Ù. ½½·ÔÀÇ Å°´Â ½Éº¼(symbol, À¯ÀÏÇÏ¸ç ºÒº¯ÀûÀÎ ½ÃÄö½º)ÀÌ¸ç °ªÀº ¸ðµç ÇüÅÂÀÇ °´Ã¼ÀÏ ¼ö ÀÖ½À´Ï´Ù.
ageldama : ±âÁ¸ ClassBased °´Ã¼ÁöÇâ¾ð¾îµé¿¡ Àͼ÷ÇÑ »ç¶÷µé¿¡°Ô´Â ÀÌ»óÇØ º¸À̰ųª ºñÈ¿À²ÀûÀ̶ó°í »ý°¢ÇÒ¼öµµ ÀÖ½À´Ï´Ù. óÀ½À¸·Î "°´Ã¼¸¦ ¸¸µé±â À§Çؼ´Â Ŭ·¡½º¸¦ ¿ì¼± ¸¸µé¾î¾ß ÇÑ´Ù"¶ó´Â ±âÁ¸»ó½Ä¿¡¼ ¸¹ÀÌ ¹þ¾î³ª°í, "¾î°¼ XXó·³ ±×³É Ŭ·¡½º¸¦ ¸¸µé¾î¼ ÀνºÅϽº¸¦ ¸¸µé¸é ¾ÈµÇ´Â°¡?"¶ó´Â ¹°À½ÀÌ µÚµû¸¦°ÍÀÔ´Ï´Ù. ±âÁ¸ÀÇ °´Ã¼¸¦ ¸¸µå´Âµ¥ ÀÖ¾î¼ Å¬·¡½º¿Í °´Ã¼¿ÍÀÇ °¸À» ÁÙÀÌ°í, Ŭ·¡½º¸¦ ¸¸µéµíÀÌ ¿øÇü °´Ã¼¸¦ ¸¸µé°í ±×°ÍÀ» º¹Á¦Çؼ »ç¿ëÇÏ¸é µË´Ï´Ù. ±×·¯ÇÑ ¾ð¾îµéÀÌ Á¦°øÇÏ´Â »ó¼ÓÀÇ °³³äº¸´Ù ÈξÀ À¯¿¬ÇÑ ¹æ¹ýÀ¸·Î »ó¼Ó°ú °°Àº È¿°ú¸¦ Á¦°øÇÏ´Â °ÍÀÌ protos ¸ñ·ÏÀÔ´Ï´Ù. ÀÌ´Â ÀÌÈÄ¿¡ ¼³¸íÇÒ ¸Þ½ÃÁöÀü´Þ°ú ÇÔ²² Á¶ÇÕÇÏ¿© °£´ÜÇϸ鼵µ °·ÂÇÑ °´Ã¼¸ðµ¨À» Á¦°øÇÕ´Ï´Ù.
clone¿Í init ¶»õ·Î¿î °´Ã¼´Â ±âÁ¸ °´Ã¼¸¦ º¹Á¦(cloning)Çؼ ¸¸µé¾î³À´Ï´Ù. cloneÀº »õ·Î¿î °´Ã¼ÀÇ
protos ¸ñ·Ï¿¡ ºÎ¸ð °´Ã¼¸¦ Æ÷ÇÔÇÑ »õ·Î¿î ºó °´Ã¼¸¦ ¸¸µé¾î³À´Ï´Ù. »õ·Î¿î ÀνºÅϽº(instance)ÀÇ init ½½·ÔÀº »õ·Î¿î °´Ã¼¸¦ ÃʱâÈÇϱâ À§Çؼ È°¼ºÈµÉ °ÍÀÔ´Ï´Ù. NewtonScript¿¡¼Ã³·³ IoLanguage¿¡¼ ½½·ÔÀº ´ëÀÔ°ú ÇÔ²² ¸¸µé¾îÁý´Ï´Ù.(CreateOnWrite)
me := Person cloneÀνºÅϽº¿¡ º¯¼ö³ª ¸Þ¼µå¸¦ Ãß°¡ÇÏ·Á¸é °£´ÜÈ÷ ±×³É ´ëÀÔÇÏ¸é µË´Ï´Ù.: myDog name := "rover" myDog sit := method("I'm sitting" println)°´Ã¼¸¦ º¹Á¦ÇÏ¸é »õ·Î¿î °´Ã¼ÀÇ init ½½·ÔÀÌ °´Ã¼¸¦ ÃʱâÈÇϱâ À§Çؼ È°¼ºÈµË´Ï´Ù.
»ó¼Ó ¶°´Ã¼°¡ ÀûÀýÇÑ ½½·ÔÀ» ã´Â ¸Þ½ÃÁö¸¦ ¹Þ¾ÒÀ»¶§, ¼ö½Å°´Ã¼ Àڽſ¡°Ô´Â ÀÏÄ¡ÇÏ´Â °ÍÀÌ ¾øÀ» °æ¿ì¿¡´Â
protos ¸ñ·ÏÀÇ °´Ã¼µé¿¡ ´ëÇؼ ±íÀÌ¿ì¼±°Ë»öÀ» Àç±ÍÀûÀ¸·Î ¼öÇàÇÕ´Ï´Ù. ´Ù½Ã ¸»Çؼ °´Ã¼°¡ ¾î¶°ÇÑ ¸Þ¼µå³ª ½½·ÔÀ» °®°í ÀÖÁö ¾Ê´õ¶óµµ ±× °´Ã¼ÀÇ ¿øº»°´Ã¼³ª protos ¸ñ·Ï¿¡ Ãß°¡ÇÑ °´Ã¼°¡ ±×·¯ÇÑ °ÍÀ» °®°í ÀÖ´Ù¸é ¸¶Ä¡ ¸Þ½ÃÁö¸¦ ¼ö½ÅÇÑ °´Ã¼°¡ À̸¦ »ó¼Ó ¹Þ´Â °Íó·³ ó¸®ÇÕ´Ï´Ù. ¶Ç´Â °´Ã¼ Àڽſ¡°Ô ÀÏÄ¡ÇÏ´Â ½½·ÔÀÌ ÀÖ´Ù¸é, ¶ÇÇÑ ±× ½½·ÔÀÇ °´Ã¼°¡ Block À̳ª CFunction ŸÀÔ¿¡ ¼ÓÇÏ´Â È°¼º(activatable, ½ÇÇà)°¡´ÉÇÑ °´Ã¼¶ó¸é À̸¦ È°¼ºÈÇÕ´Ï´Ù. ȤÀº ´Ù¸¥ ŸÀÔÀ̶ó¸é ´Ü¼øÈ÷ ±× °´Ã¼¸¦ µÇµ¹¸³´Ï´Ù.
IoLanguage¿¡´Â Àü¿ªº¯¼ö°¡ ¾øÀ¸¸ç, À̸§°ø°£¿¡¼ ÃÖ»óÀ§ÀÇ °´Ã¼¸¦ Lobby ¶ó°í ºÎ¸¨´Ï´Ù.(À̸¦ Àü¿ªÀ̸§°ø°£À¸·Î ÀÌ¿ëÇÕ´Ï´Ù.)
Ŭ·¡½º°¡ ¾ø±â ¶§¹®¿¡ ¼ºêŬ·¡½º(subclass)¿Í ÀνºÅϽº°£ÀÇ ¾î¶°ÇÑ Â÷À̵µ ¾ø½À´Ï´Ù. ´ÙÀ½Àº »õ·Î¿î ¼ºêŬ·¡½º¸¦ ¸¸µå´Â ÄÚµåÀÔ´Ï´Ù.:
Io> Dog := Object clone ...À§ÀÇ ÄÚµå´Â Lobby ÀÇ "Dog"¶ó´Â ½½·ÔÀ» Object °´Ã¼ÀÇ º¹Á¦·Î ¼³Á¤ÇÕ´Ï´Ù. ÀÌ·¸°Ô¸¸ ÇÑ´Ù¸é Dog °´Ã¼ÀÇ protos ¸ñ·Ï¿¡´Â ¿ÀÁ÷ Object °´Ã¼¸¸ÀÌ Æ÷ÇԵǾî ÀÖ½À´Ï´Ù. Dog Àº ÀÌÁ¦ ¼ø¼öÇÏ°Ô Object ÀÇ ¼ºêŬ·¡½ºÀÔ´Ï´Ù. ÀνºÅϽºº¯¼ö¿Í ¸Þ¼µåµéÀº protos ¸ñ·ÏÀÇ °´Ã¼µé·ÎºÎÅÍ »ó¼ÓÀ» ¹Þ½À´Ï´Ù. ½½·ÔÀ» ¼³Á¤Çϸé protos ¿¡ ¼ÓÇÑ °´Ã¼¸¦ ¼öÁ¤ÇÏ´Â °ÍÀÌ ¾Æ´Ï¶ó ´ë»ó °´Ã¼¸¸À» ¼öÁ¤ÇÕ´Ï´Ù.
Io> Dog color := "red" Io> Dog ==> Object_0x4a7c0: color := "red" ... ´ÙÁß»ó¼Ó ¶protos ¸ñ·Ï¿¡ ¾ó¸¶µçÁö ´Ù¸¥ °´Ã¼¸¦ Ãß°¡ÇÒ ¼ö ÀÖ½À´Ï´Ù. À̸¦ ÅëÇؼ ´Ù¸¥ °´Ã¼µéÀ» ºÎ¸ðó·³ »ç¿ëÇÒ ¼ö ÀÖ½À´Ï´Ù. ÀÌ·¸°Ô ÇÏ´õ¶óµµ ¸Þ½ÃÁö¿¡ ÀÀ´äÇϱâ À§Çؼ ½½·ÔÀ» °Ë»öÇÒ ¶§ ±íÀÌ¿ì¼±°Ë»öÀ» ProtoChain¿¡ ´ëÇؼ ¼öÇàÇÕ´Ï´Ù.
¸Þ¼µå ¶¸Þ¼µå(method)Àº È£Ãâ½Ã¿¡ °¢±â ´Ù¸¥ Áö¿ªÀ̸§°ø°£À» À§ÇÑ °´Ã¼¸¦ ¸¸µé°í ¸Þ½ÃÁöÀÇ ¼ö½Å°´Ã¼¸¦ ÂüÁ¶ÇÏ´Â self ½½·ÔÀ» ÀÌ¿¡ ÇÒ´çÇÏ´Â À͸íÇÔ¼ö(AnonymousFunction)ÀÔ´Ï´Ù.
Object ÀÇ method() ¸Þ¼µå¸¦ »ç¿ëÇØ »õ·Î¿î ¸Þ¼µå¸¦ ¸¸µé ¼ö ÀÖ½À´Ï´Ù.:
method((2+2) print)°´Ã¼¿Í ¿¬°üµÈ ¸Þ¼µå¸¦ ¸¸µé·Á¸é ´Ü¼øÈ÷ ¸Þ¼µå °´Ã¼¸¦ °´Ã¼ÀÇ ½½·Ô¿¡ ¹èÁ¤ÇÏ¸é µË´Ï´Ù.: Dog := Object clone Dog bark := method("woof!" print)À§ÀÇ ÄÚµå´Â »õ·Î¿î ¼ºêŬ·¡½º¸¦ ¸¸µé°í »õ·Î¿î Ŭ·¡½ºÀÇ "bark" ½½·Ô¿¡ "woof!"À» Ãâ·ÂÇÏ´Â ¸Þ¼µå¸¦ ´ëÀÔÇÑ °ÍÀÔ´Ï´Ù. À̸¦ »ç¿ëÇÏ·Á¸é ´ÙÀ½Ã³·³ ÇÏ¸é µË´Ï´Ù.: Io> Dog bark ... Io> poochi = Dog clone Io> poochi bark ...¸Þ¼µåÀÇ ±âº» µÇµ¹¸²°ªÀº ¸Ç ¸¶Áö¸·À¸·Î Æò°¡ÇÑ Ç¥Çö½ÄÀÇ °á°ú°ªÀÔ´Ï´Ù. ÀÎÀÚ ¶¸Þ¼µå°¡ ÀÎÀÚ¸¦ ³Ñ°Ü¹Þµµ·Ï Á¤ÀÇÇÏ·Á¸é ´ÙÀ½Ã³·³ ÇÕ´Ï´Ù.:
add := method(a, b, a + b)ÀϹÝÀûÀÎ Çü½ÄÀº ´ÙÀ½°ú °°½À´Ï´Ù.: method(<arg name 0>, <arg name 1>, ..., <do message>)¸Ç ¸¶Áö¸·ÀÇ ÀÎÀÚ´Â ¼±ÅÃÀûÀ¸·Î ¸Þ¼µå¿¡ ³Ñ°ÜÁÙ ÄÚµåºí·° °´Ã¼¸¦ À§ÇÑ ÀÎÀÚÀÏ ¼ö ÀÖ½À´Ï´Ù. ºí·° ¶ºí·°(blocks)Àº ¸Þ¼µå¿Í À¯»çÇÏÁö¸¸, LexicallyScopedÀÌ¸ç ±× ÇØ´ç½½·Ô¿¡ Á¢±ÙÇÒ ¶§ ÀÚµ¿ÀûÀ¸·Î È°¼ºÈµÇÁö ¾Ê´Â´Ù´Â Á¡¿¡¼ ´Ù¸¨´Ï´Ù.(È°¼ºÈÇϱâ À§Çؼ´Â
call ¸Þ¼µå¸¦ »ç¿ëÇÕ´Ï´Ù.)
LexicallyScoped¶õ °ÍÀº ºí·°ÀÌ ½ÇÇàµÉ ¶§ ½½·Ô¿¡ ´ëÇÑ °Ë»öÀÌ ºí·ÏÀÌ »ý¼ºµÈ ¹®¸Æ¿¡¼ °è¼ÓµÈ´Ù´Â °ÍÀÌÁö ºí·°ÀÌ ½ÇÇàµÇ´Â ¹®¸Æ¿¡¼ °è¼ÓµÈ´Ù´Â °ÍÀÌ ¾Æ´Ï¶ó´Â ¶æÀÔ´Ï´Ù. ºí·°Àº Object ÀÇ block() ¸Þ¼µå¸¦ »ç¿ëÇؼ ¸¸µì´Ï´Ù.:
b := block(a, a*2) b call(1)´Ù½Ã LexicallyScoped¿¡ ´ëÇؼ ¼³¸íÇÏ¸é ´ÙÀ½°ú °°½À´Ï´Ù.: m := 2 b := block(a, a*m) Foo := Object clone Foo m := 3 Foo b := b Foo b call(1) printlnÀ§ÀÇ Äڵ忡¼ Foo °´Ã¼´Â m ½½·ÔÀ» °®°í ÀÖÁö¸¸ ÀÌ ½½·ÔÀ» »ç¿ëÇÏÁö ¾Ê°í ºí·°ÀÌ ¸¸µé¾îÁø À̸§°ø°£ÀÇ m ½½·ÔÀ» »ç¿ëÇÏ´Â °ÍÀ» ¾Ë ¼ö ÀÖ½À´Ï´Ù. ´ÙÀ½Àº ¸Þ¼µå¸¦ ÀÌ¿ëÇؼ À̸¦ ±¸ÇöÇÏ¿´½À´Ï´Ù. ÂüÁ¶ÇÏ´Â ´ë»óÀÌ ÀüÇô ´Ù¸¨´Ï´Ù.:
v := 2 Foo := Object clone Foo v := 3 Foo m := method(n, n * v) Foo m(1) println Blocks vs. Methods ¶ÃæºÐÈ÷ È¥¶õÀÇ ¿©Áö°¡ Àֱ⠶§¹®¿¡ ºí·°°ú ¸Þ¼µåÀÇ ¼¼ºÎÀûÀÎ »çÇ׿¡ ´ëÇؼ ¼³¸íÇÏ°í ³Ñ¾î°¡µµ·Ï ÇÏ°Ú½À´Ï´Ù. ¸Þ¼µå¿Í ºí·°Àº µÑ ´Ù È°¼ºÈµÉ ¶§¿¡ °¢°¢ÀÇ Áö¿ªº¯¼ö¸¦ ÀúÀåÇϱâ À§ÇÑ °´Ã¼¸¦ »ý¼ºÇÕ´Ï´Ù. µÑÀÇ Â÷ÀÌÁ¡Àº Áö¿ª°ø°£¿¡ ¼³Á¤µÇ´Â "protos"¿Í "self"½½·Ô¿¡ ÀÖ½À´Ï´Ù. ¸Þ¼µå¿¡¼´Â ÀÌ ½½·ÔµéÀÌ ¸Þ½ÃÁöÀÇ ´ë»ó°´Ã¼(¼ö½Å°´Ã¼)·Î ¼³Á¤µË´Ï´Ù. ºí·°¿¡¼´Â À̵éÀÌ ºí·°ÀÌ Ã³À½ »ý¼ºµÈ Áö¿ª°ø°£°´Ã¼¸¦ ÂüÁ¶Çϵµ·Ï ¼³Á¤ÀÌ µË´Ï´Ù. ±×·¯¹Ç·Î ºí·°¿¡¼ ½½·Ô ã±â°¡ ½ÇÆÐÇÏ¸é ºí·°ÀÌ »ý¼ºµÈ À̸§°ø°£¿¡ ´ëÇؼ °Ë»öÀ» °è¼ÓÇÕ´Ï´Ù. ¸Þ¼µå¿¡ À־ ÀÌ°ÍÀÌ ¸Þ¼µå°¡ »ý¼ºµÈ À̸§°ø°£ÀÌ ¾Æ´Ï¶ó ¸Þ¼µå°¡ Æ÷ÇÔµÈ °´Ã¼¿¡ ´ëÇؼ °è¼ÓÇؼ °Ë»öÀ» ÁøÇàÇÕ´Ï´Ù.
call, self ½½·Ô ¶"locals" °´Ã¼°¡ »ý¼ºµÇ¸é ÀÌ °´Ã¼ÀÇ "self" ½½·ÔÀÌ ¼³Á¤µË´Ï´Ù.(¸Þ¼µåÀÇ °æ¿ì¿¡´Â ¸Þ½ÃÁöÀÇ ¼ö½ÅÀÚ, ºí·°ÀÇ °æ¿ì¿¡´Â »ý¼ºµÈ ¹®¸ÆÀ¸·Î) ±×¸®°í "call" ½½·ÔÀº ´ÙÀ½ÀÇ ½½·ÔµéÀ» Æ÷ÇÔÇÏ´Â °´Ã¼·Î ¼³Á¤À̵˴ϴÙ.
°¡º¯±æÀÌÀÎÀÚ ¶"call message" ½½·ÔÀº Æò°¡µÇÁö ¾ÊÀº ÀÎÀÚµéÀ» Á¢±ÙÇϱâ À§ÇØ »ç¿ëÇÒ ¼ö ÀÖ½À´Ï´Ù. ¿¹¸¦ µé¾î, IoLanguage¿¡¼
if() ÀÇ ±¸ÇöÀ» º¸¸é:
myif := method( (call sender doMessage(call message argAt(0))) ifTrue( call sender doMessage(call message argAt(1))) ifFalse( call sender doMessage(call message argAt(2)))) myif(foo == bar, write("true\n"), write("false\n")) doMessage() ¸Þ¼µå´Â ¼ö½ÅÀÚÀÇ ¹®¸Æ¿¡¼ ÀÎÀÚ¸¦ Æò°¡ÇÕ´Ï´Ù.
À̸¦ ª°Ô Ç¥ÇöÇϸé call °´Ã¼ÀÇ evalArgAt() ¸Þ¼µå¸¦ ÀÌ¿ëÇÏ¸é µË´Ï´Ù.:
myif := method( call evalArgAt(0) ifTrue( call evalArgAt(1)) ifFalse( call evalArgAt(2))) myif(foo == bar, write("true\n"), write("false\n")) forward ¶¸¸ÀÏ °´Ã¼°¡ ¾î¶² ¸Þ½ÃÁö¿¡ ´ëÇؼ ÀÀ´äÇÒ ¼ö ¾øÀ»¶§´Â "forward" ¸Þ¼µå°¡ ÀÖ´Ù¸é À̸¦ È£ÃâÇÕ´Ï´Ù. ´ÙÀ½Àº ½½·Ô¿¡ ´ëÇÑ °Ë»öÀÌ ½ÇÆÐÇßÀ»¶§ ÀÌ ¸Þ½ÃÁö¿¡ ´ëÇÑ Á¤º¸¸¦ Ãâ·ÂÇÏ´Â ¿¹ÀÔ´Ï´Ù.:
MyObject forward := method( write("sender = ", call sender, "\n") write("message name = ", call message name, "\n") args := call message argsEvaluatedIn(call sender) args foreach(i, v, write("arg", i, " = ", v, "\n") )) resend ¶"self"ÀÇ ¹®¸Æ¿¡¼ ÇöÀçÀÇ ¸Þ½ÃÁö¸¦ ¼ö½ÅÀÚÀÇ "proto"·Î ´Ù½Ã º¸³»·Á¸é:
A := Object clone A m := method("in A" println) B := A clone B m := method("in B" println; resend) B mÀÌ´Â °°Àº ¸Þ½ÃÁö¸¦ ÀçÀü´ÞÇÏ°íÀÚ ÇÒ ¶§ »ç¿ëÇϸç, ´Ù¸¥ ¸Þ½ÃÁö¸¦ Àü´ÞÇÏ°íÀÚ ÇÒ¶§¿¡´Â "super" ½½·ÔÀ» ÀÌ¿ëÇÕ´Ï´Ù. super ¶°´Ã¼ÀÇ "proto"¿¡ ´ëÇؼ ¸Þ½ÃÁö¸¦ Á÷Á¢ º¸³»°í ½ÍÀ»¶§¿¡´Â "super"À» ÀÌ¿ëÇÕ´Ï´Ù.:
{{{ Dog := Object clone Dog bark := method("woof!" println) fido := Dog clone fido bark := method("ruf!" println; super(bark)) === Introspection === ´ÙÀ½ ¸Þ¼µåµéÀ» ÀÌ¿ëÇؼ ¸ðµç °´Ã¼µé¿¡ ´ëÇØ introspect ÇÒ ¼ö ÀÖ½À´Ï´Ù. ¶ÇÇÑ ½ÇÇà½Ã°£¿¡ °´Ã¼ÀÇ ¸ðµç ¼Ó¼ºÀ» ¼öÁ¤ÇÒ¼öµµ ÀÖ½À´Ï´Ù. ==== slotNames ==== "slotNames" ¸Þ¼µå´Â °´Ã¼ÀÇ ¸ðµç ½½·ÔÀÇ À̸§¸ñ·ÏÀ» µÇµ¹¸³´Ï´Ù.: {{{ Io> Dog slotNames ==> list("bark") }}} ==== protos ==== "protos" ¸Þ¼µå´Â °´Ã¼°¡ »ó¼ÓÇÏ´Â °´Ã¼µéÀÇ ¸ñ·ÏÀ» µÇµ¹¸³´Ï´Ù.: {{{ Io> Dog protos ==> list("Object") }}} ==== getSlot ==== "getSlot" ¸Þ¼µå´Â °´Ã¼ÀÇ ½½·ÔÀ» È°¼ºÈÇÏÁö ¾Ê°í¼ ½½·ÔÀÇ °ªÀ» Á¢±ÙÇÏ·Á°í ÇÒ ¶§ »ç¿ëÇÕ´Ï´Ù.: {{{ myMethod := Dog getSlot("bark") }}} À§ Äڵ忡¼ "locals"ÀÇ "myMethod" ½½·ÔÀ» "bark"¸Þ¼µå·Î ¼³Á¤Çß½À´Ï´Ù.(À̶§ "bark"¸Þ¼µå¸¦ È°¼ºÈÇÏÁö ¾Ê¾ÒÀ½À» ¸í½ÉÇϼ¼¿ä.) {{{ otherObject newMethod := getSlot("myMethod") }}} ÀÌ·¸°Ô ÇÑ´Ù¸é "getSlot"ÀÇ ´ë»óÀº "locals" °´Ã¼ÀÌ°í, ÀÌ·¸°Ô "myMethod" ½½·ÔÀ» È°¼ºÈÇÏÁö ¾Ê°í ¾ò¾î¼ ±× °´Ã¼¸¦ ´Ù¸¥ °´Ã¼ÀÇ ½½·Ô¿¡ ´ëÀÔÇÏ¿© ¸Þ¼µå¸¸À» º¹»çÇÒ ¼ö ÀÖ½À´Ï´Ù. ==== code ==== ¸Þ¼µåÀÇ ÀÎÀÚµé°ú Ç¥Çö½ÄÀº introspection¿¡ ´ëÇØ °³¹æµÇ¾î ÀÖ½À´Ï´Ù. "code" ¸Þ¼µå´Â ¸Þ¼µåÀÇ ¼Ò½ºÄڵ带 ¹®ÀÚ¿·Î µÇµ¹·ÁÁÝ´Ï´Ù.: {{{ Io> method(a, a*2) code ==> "method(a,a*(2))" }}} ---- == Á¦¾î±¸Á¶ == === true, false, nil === IoLanguageÀº true, false, nil¿¡ ´ëÇؼ ¹Ì¸® Á¤ÀÇµÈ singletonÀ» Á¦°øÇÕ´Ï´Ù. "true", "false"Àº °¢°¢ ºÒ¸®¾ðÁø¸®°ªÀ» ³ªÅ¸³»¸ç "nil"Àº ÀϹÝÀûÀ¸·Î ¼³Á¤µÇÁö¾ÊÀ½(unset)À̳ª °¡¿ëÇÏÁö¾ÊÀº°ª(unavailable value)À» ³ªÅ¸³À´Ï´Ù. ¶ÇÇÑ ÀÌ·¯ÇÑ °ªµéÀº Ç¥½ÄÀ¸·Î¼ÀÇ ±â´É ÀÌ¿Ü¿¡µµ °´Ã¼·Î¼ ±×µé°ú ¿¬°üµÇ¾î Á¶°Ç½Ä°ú °°Àº Á¦¾î±¸Á¶¸¦ ¸¸µé ¼ö ÀÖµµ·Ï ÇØÁÝ´Ï´Ù. (SmalltalkLanguage ½ºÅ¸ÀÏÀÇ Á¦¾î±¸¹®...) === ºñ±³ === Ç¥Áغñ±³¿¬»ê(`==`, `!=`, `>=`, `<=`, `>`, `<`)Àº true ȤÀº falseÀ» µÇµ¹¸³´Ï´Ù. {{{ Io> 1 < 2 ==> true }}} === Á¶°Ç½Ä === ==== if ==== "Lobby"Àº Á¶°Ç½Ä°ú ·çÇÁ¸¦ À§ÇÑ ¸Þ¼µåµéÀ» Æ÷ÇÔÇÏ°í ÀÖ½À´Ï´Ù. Á¶°Ç½ÄÀº ´ÙÀ½°ú °°½À´Ï´Ù.: {{{ if(<Á¶°Ç½Ä>, <then-¸Þ½ÃÁö>, <else-¸Þ½ÃÁö>) }}} ¿¹¸¦ µé¾î: {{{ if(a == 10, "a is 10" println) }}} "else"ÀÎÀÚ´Â ¼±ÅÃÀûÀÔ´Ï´Ù. Á¶°Ç½ÄÀÌ "false"³ª "nil"·Î¼ Æò°¡µÇ¸é ÀÌ´Â ÂüÀÌ ¾Æ´Ñ, °ÅÁþÀ¸·Î ÆÇ´ÜÇÕ´Ï´Ù. ¶ÇÇÑ Æò°¡µÈ ¸Þ½ÃÁöÀÇ °á°ú¸¦ µÇµ¹¸®¹Ç·Î ´ÙÀ½Àº: {{{ if(y < 10, x := y, x := 0) }}} ´ÙÀ½°ú °°½À´Ï´Ù.: {{{ x := if(y < 10, y, 0) }}} Á¶°ÇÁ¦¾î´Â ´ÙÀ½°ú °°ÀÌ ¾µ¼öµµ ÀÖ½À´Ï´Ù.(¼º´ÉÀº ´õ ¶³¾îÁöÁö¸¸): {{{ if(y < 10) then(x := y) else(x := 2) ... if(y < 10) then(x := y) elseif(y==11) then(x := 0) else(x := 2) }}} ¶ÇÇÑ SmalltalkLanguage ½ºÅ¸ÀÏÀÇ "ifTrue", "ifFalse", "ifNil", "ifNonNil" ¸Þ¼µåµµ ÀÖ½À´Ï´Ù.: {{{ (y < 10) ifTrue(x := y) ifFalse(x := 2) }}} À§¿¡¼ Á¶°Ç½ÄÀº ¹Ýµå½Ã °ýÈ£·Î µÑ·¯ÃÄ¾ß ÇÕ´Ï´Ù. ;-) === ·çÇÁ === ==== loop ==== "loop" ¸Þ¼µå´Â '''¹«ÇÑ·çÇÁ'''¸¦ ±¸¼ºÇϴµ¥ »ç¿ëÇÕ´Ï´Ù.: {{{ loop("foo" println) }}} ==== while ==== Á¶°ÇÁ¦¾îó·³ ·çÇÁµé ¶ÇÇÑ ¸Þ½ÃÁöÀÔ´Ï´Ù. "while()"Àº ´ÙÀ½ÀÇ ÀÎÀÚµéÀ» ¿ä±¸ÇÕ´Ï´Ù.: {{{ while(<Á¶°Ç½Ä>, <do-¸Þ½ÃÁö>) }}} ¿¹¸¦ µé¾î: {{{ a := 1 while(a < 10, a print a = a + 1) }}} ==== for ==== "for"Àº 4°³ÀÇ ÀÎÀÚ¸¦ ÇÊ¿ä·Î ÇÕ´Ï´Ù.: {{{ for(<counter>, <start>, <end>, <do-message>) }}} "start", "end" ¸Þ½ÃÁö´Â ¿ÀÁ÷ ·çÇÁ°¡ ½ÃÀ۵ɶ§ Çѹø¸¸ Æò°¡µË´Ï´Ù.: {{{ for(a, 0, 10, a println) }}} ¿ª¼øÀ¸·Î ·çÇÁ¸¦ µ¹¸®·Á¸é ±×³É "start", "end"ÀÇ À§Ä¡¸¦ ¹Ù²ãÁÖ¸é µË´Ï´Ù.: {{{ for(a, 10, 0, a println) }}} '''ÁÖÀÇ''': "start", "end"Àº ¸ðµÎ ·çÇÁ¿¡ Æ÷ÇÔÀÌ µË´Ï´Ù. ´Ù½Ã ¸»Çؼ ´Ù¸¥ ¾ð¾î¿¡¼ ·çÇÁ¸¦ ±¸¼ºÇϵíÀÌ 0¿¡¼ 10±îÁö ·çÇÁ¸¦ µ¹¸°´Ù¸é ½ÇÁ¦·Î 11¹ø ·çÇÁ¸¦ ½ÇÇàÇÒ°ÍÀÔ´Ï´Ù. ==== repeat ==== "Number"ÀÇ "repeat" ¸Þ¼µå´Â ±× ¼ýÀÚ¸¸Å ¹Ýº¹Çؼ ·çÇÁ¸¦ ½ÇÇàÇÏ°íÀÚ ÇÒ ¶§ À¯¿ëÇÕ´Ï´Ù.("counter"Àº Á¦°øÀÌ ¾ÈµË´Ï´Ù.): {{{ 3 repeat("foo" println) }}} ==== break, continue ==== È帧Á¦¾îÀÛ¾÷À» Áß´Ü("break")Çϰųª ´ÙÀ½À¸·Î ¶Ù¾î³Ñ±â("continue") ÇÒ ¼ö ÀÖ½À´Ï´Ù.: {{{ for(i, 1, 10, if(i==3, continue) if(i==7, break) i print) }}} °á°ú´Â...: {{{ 12456 }}} ==== return ==== "return" ¸Þ¼µå¸¦ »ç¿ëÇؼ ºí·°ÀÇ ¾î¶² ºÎºÐ¿¡¼µµ ¹Ù·Î °ªÀ» µÇµ¹¸®¸ç ½ÇÇàÀ» µÇµ¹¸± ¼ö ÀÖ½À´Ï´Ù.: {{{ Io> test := method(123 print; return "abc"; 456 print) Io> test 123 ==> "abc" }}} === Importing === "Importer" ÇÁ·ÎÅä´Â IoLanguageÀÇ ³»Àå AutoImporter±â´ÉÀ» ±¸ÇöÇÕ´Ï´Ù. °¢°¢ÀÇ ÇÁ·ÎÅäµéÀ» ÆÄÀÏ¿¡ ³Ö°í, ÆÄÀÏÀ̸§Àº ÇÁ·ÎÅä¿Í °°Àº À̸§ÀÇ ".io"È®ÀåÀÚ·Î ÀúÀåÇϸé, "Importer"°¡ ÀÚµ¿À¸·Î ÇØ´ç ÇÁ·ÎÅä°¡ ÇÊ¿äÇÒ¶§¿¡ ÆÄÀÏÀ» ·ÎµùÇÒ °ÍÀÔ´Ï´Ù. ImpoterÀÇ ±âº»°Ë»ö°æ·Î´Â ÇöÀç ÀÛ¾÷µð·ºÅ丮À̸ç, "appendSearchPath()" ¸Þ¼µå¸¦ ÀÌ¿ëÇÏ¿© Ãß°¡ÇÒ ¼ö ÀÖ½À´Ï´Ù. ---- == µ¿½Ã¼º == === Coroutine === IoLanguageÀº ¼±Á¡ÀûÀÎ OS¼öÁØ ½º·¹µå(preemptive OS level threads) ´ë½Å¿¡ CoRoutine(user-level cooperative threads)À» »ç¿ëÇÕ´Ï´Ù. ÀÌ´Â NativeThreadÀ» ÀÌ¿ëÇÔ¿¡ ÀÖ¾î¼ Ãß°¡ÀûÀÎ ºñ¿ë(¸Þ¸ð¸®, ½Ã½ºÅÛÄÝ, locking, ij½³¹®Á¦...)µîÀ» ¾ø¾Ö°í ¼ö¸¹Àº È°¼º½º·¹µå¿¡ ´ëÇؼ °í¼öÁØÀÇ µ¿½Ã¼º(concurrency)À» °¡´ÉÇÏ°Ô ÇÕ´Ï´Ù. === Scheduler === "Scheduler" °´Ã¼´Â "yielding"ÁßÀÎ CoRoutineÀ» °è¼ÓÇϵµ·Ï Çϴ°Ϳ¡ Ã¥ÀÓÀÌ ÀÖ½À´Ï´Ù. ÇöÀçÀÇ ½ºÄÉÁ층½Ã½ºÅÛÀº ´Ü¼øÈ÷ ¿ì¼±¼øÀ§ ¾ø´Â FirstInFirstOut Á¤Ã¥À» »ç¿ëÇÕ´Ï´Ù. === Actors === "actor"Àº ½º·¹µå¸¦ °®´Â °´Ã¼¸¦ ¸»ÇÕ´Ï´Ù.(ÀÌ °æ¿ì¿¡´Â coroutine) ÀÌ´Â ºñµ¿±â¸Þ½ÃÁö(asynchronous message)µéÀ» À§ÇÑ Å¥(queue)¸¦ °ü¸®ÇÕ´Ï´Ù. IoLanguageÀÇ ¸ðµç °´Ã¼´Â "@"À̳ª "@@"À» ¸Þ½ÃÁö À̸§ ¾Õ¿¡ ºÙ¿©¼ ºñµ¿±â¸Þ½ÃÁö·Î¼ º¸³¾ ¼ö ÀÖ½À´Ï´Ù.("@"ÀÇ "a"À» "asynchronous"·Î »ý°¢Çغ¸¼¼¿ä) {{{ result := self foo // synchronous futureResult := self @foo // async. Áï½Ã ¸®ÅÏÇÏÁö¸¸ ¸®ÅÏ°ªÀÇ Å¸ÀÔÀº Future self @@foo // async. Áï½Ã nilÀ» ¸®ÅÏ. }}} °´Ã¼°¡ ºñµ¿±â¸Þ½ÃÁö¸¦ ¹ÞÀ¸¸é °¢°¢ÀÇ Å¥¿¡ ¸Þ½ÃÁö¸¦ ³Ö½À´Ï´Ù. ¸¸ÀÏ Å¥¿¡ ¸Þ½ÃÁö°¡ Çϳªµµ ¾ø¾ú´Ù¸é ¹Ù·Î ¸Þ½ÃÁö¸¦ ó¸®ÇÕ´Ï´Ù. Å¥¿¡ ³ÖÀº ¸Þ½ÃÁö´Â FirstInFirstOut ¼ø¼¿¡ ÀÇÇؼ Â÷·Ê´ë·Î 󸮵˴ϴÙ. Á¦¾î±ÇÀ» ´Ù¸¥ CoRoutineÀ¸·Î ³Ñ±â·Á¸é "yield"À» »ç¿ëÇÕ´Ï´Ù.: {{{ obj1 := Object clone obj1 test := method(for(n, 1, 3, n print; yield)) obj2 := obj1 clone obj1 @@test; obj2 @@test while(Scheduler activeActorCount > 1, yield) }}} Ãâ·ÂÀº "112233"ÀÌ µË´Ï´Ù. ´ÙÀ½Àº Á» ´õ ½ÇÁ¦ÀûÀÎ ¿¹Á¦ÀÔ´Ï´Ù.: {{{ HttpServer handleRequest := method(aSocket, HttpRequestHandler clone @@handleRequest(aSocket)) }}} === yield === °´Ã¼´Â ´Ù¸¥ °´Ã¼¿Í ºñµ¿±â¸Þ½ÃÁö¸¦ ó¸®Çϱâ À§ÇØ ÀÚµ¿ÀûÀ¸·Î "yield"ÇÕ´Ï´Ù. "yield"¸Þ¼µå´Â ¿ÀÁ÷ ºñµ¿±â¸Þ½ÃÁöÀÇ ½ÇÇà µµÁß¿¡¸¸ È£ÃâÇÒ ÇÊ¿ä°¡ ÀÖ½À´Ï´Ù. === ÀϽÃÁ¤Áö, °è¼Ó === °´Ã¼¸¦ ÀϽÃÁ¤Áö(pause) Çß´Ù°¡ ´Ù½Ã °è¼Ó(resume) ÇÒ ¼ö ÀÖ½À´Ï´Ù. "Object" primitiveÀÇ µ¿½Ã¼º(concurrency)°ü·Ã ¸Þ¼µåµéÀ» »ìÆ캸¼¼¿ä. :-< === Future === IoLanguageÀÇ "futures"Àº Åõ¸íÇÕ´Ï´Ù. ÀÌ´Â °á°ú°¡ ÁغñµÇ¸é °á°ú°ªÀ¸·Î ¹Ù²ò´Ï´Ù. ¸¸ÀÏ ¸Þ½ÃÁö°¡ "future"¿¡ ´ëÇؼ º¸³»Áö¸¸(2°³ÀÇ ¸Þ¼µå¸¦ ±¸ÇöÇÏ°í ÀÖ½À´Ï´Ù), ¸Þ½ÃÁö¸¦ 󸮰¡ ³¡³ª°í °á°ú°¡ ³ª¿Ã¶§±îÁö ±â´Ù¸³´Ï´Ù. Åõ¸íÇÑ "future"Àº ÇÁ·Î±×·¥ÀÇ ºí·Ï(blocking)µÈ »óŸ¦ ÃÖ¼ÒÈÇØÁÖ¸ç, ÇÁ·Î±×·¡¸Ó¸¦ µ¿±âÈÀÇ ¼¼ºÎÀûÀÎ ºÎºÐÀ¸·ÎºÎÅÍ ÀÚÀ¯·Ó°Ô ÇØÁÖ´Â °·ÂÇÔÀ» Á¦°øÇÕ´Ï´Ù. === AutoDeadlockDetection === "future"À» »ç¿ëÇϴµ¥ ¶Ç ´Ù¸¥ ÀåÁ¡Àº "future"°¡ "wait"ÇÒ ÇÊ¿ä°¡ ÀÖÀ»¶§, °á°ú°¡ ±³Âø(deadlock)À¸·Î À̲øÁö ¾Æ´ÒÁö¸¦ °Ë»çÇÒ ¼ö ÀÖ´Ù´Â °ÍÀ̸ç, À̸¦ ÅëÇؼ ±³Âø»óŸ¦ ¿¹¹æÇÏ°í ¿¹¿Ü¸¦ ¹ß»ý½Ãŵ´Ï´Ù. ÀÌ´Â °ü·ÃµÈ "future"µé¿¡ ´ëÇؼ ¼øȸÇÔÀ¸·Î¼ ±¸ÇöµË´Ï´Ù. === @, @@ ¿¬»êÀÚ === "@", "@@"À» ÀϹÝÀûÀÎ ¸Þ½ÃÁöÀÇ ¾Õ¿¡ ºÙ¿©ÁÖ¸é À̸¦ ¿¬»êÀڷμ ÀÛ¿ëÇÕ´Ï´Ù.: {{{ self @test }}} ...Àº ÆÄ½ÌµÇ¸é ´ÙÀ½°ú °°½À´Ï´Ù.: {{{ self @(test) }}} ---- == ¿¹¿Ü == === raise === ¿¹¿Ü¸¦ ´øÁö·Á¸é "raise()"À» "exception" ÇÁ·ÎÅä¿¡ ´ëÇؼ È£ÃâÇÏ¸é µË´Ï´Ù.: {{{ exceptionProto raise(<description>) }}} "Exception" ÇÁ·ÎÅäÀÇ ÀÚ½ÄÀ¸·Î¼ ¹Ì¸® Á¤ÀÇµÈ 3°³ÀÇ ÇÁ·ÎÅä°¡ ÀÖ½À´Ï´Ù.: "Error", "Warning", "Notification": {{{ Exception raise("generic foo exception") Warning raise("No defaults found, creating them") Error raise("Not enough memory") }}} === try, catch === ¿¹¿Ü¸¦ Àâ±â À§Çؼ´Â "Object" ÇÁ·ÎÅäÀÇ "try()"¸Þ¼µå¸¦ »ç¿ëÇÕ´Ï´Ù. "try()"Àº ±× ¾È¿¡¼ ÀÏ¾î³ ¿¹¿Ü¸¦ Àâ¾Æ¼ ¿¹¿Ü¸¦ µÇµ¹¸®°Å³ª ¿¹¿Ü°¡ ¾ø¾ú´Ù¸é "nil"À» µÇµ¹¸³´Ï´Ù.: {{{ e := try(<doMessage>) }}} ÀÌ·¸°Ô ÀâÀº ¿¹¿Ü¸¦ ó¸®ÇÏ·Á¸é "Exception"ÀÇ "catch()"¸Þ¼µå¸¦ »ç¿ëÇÕ´Ï´Ù.: {{{ e := try( //... ) e catch(Exception, (e coroutine backtraceString) println) }}} "catch"ÀÇ Ã¹¹ø° ÀÎÀÚ´Â ÀâÀ» ¿¹¿ÜÀÇ Å¸ÀÔÀ» ³ªÅ¸³»°í, µÎ¹ø°´Â ±×¿¡ ´ëÇÑ Ã³¸®ºí·°ÀÔ´Ï´Ù. ¸¸ÀÏ "catch()"¿¡ ÀÏÄ¡ÇÏ´Â °ÍÀÌ Çϳªµµ ¾ø´Ù¸é ¿¹¿Ü¸¦ µÇµ¹¸®°í, ÀÖ¾ú´Ù¸é "nil"À» µÇµ¹¸³´Ï´Ù. === pass === "try()"¿¡ ÀÇÇؼ ÀâÀº ¿¹¿Ü¸¦ ´Ù½Ã ´øÁö±â À§Çؼ´Â "pass" ¸Þ¼µå¸¦ »ç¿ëÇÕ´Ï´Ù. ÀÌ ¸Þ¼µå´Â ±× »óÀ§ÀÇ "try()"¿¡°Ô ¿¹¿Ü¸¦ Àü´ÞÇÏ°íÀÚ ÇÒ ¶§ À¯¿ëÇÕ´Ï´Ù. ÀϹÝÀûÀ¸·Î ÀûÀýÇÏ°Ô Ã³¸®ÇÏÁö ¸øÇÑ ¿¹¿Ü°¡ ÀÖÀ»¶§ À̸¦ ÀÌ¿ëÇÏ¿© ¿¹¿Ü¸¦ »óÀ§ Çڵ鷯¿¡°Ô Àü´ÞÇÏ°íÀÚ ÇÒ ¶§¿¡ »ç¿ëÇÕ´Ï´Ù. {{{ e := try( // ... ) e catch(Error, // ... ) catch(Exception, // ... ) pass }}} === »ç¿ëÀÚÁ¤ÀÇ ¿¹¿Ü === ´Ü¼øÈ÷ "Exception" ÇÁ·ÎÅ並 º¹Á¦ÇÏ¿© ÀڽŸ¸ÀÇ ¿¹¿Ü¸¦ ¸¸µé ¼ö ÀÖ½À´Ï´Ù.: {{{ MyErrorType := Error clone }}} === NilMagic === »ç½Ç ¿¹¿Ü¸¦ À§ÀÇ ¿¹Á¦¿Í °°ÀÌ ¿¬µ¿Çؼ »ç¿ëÇϴµ¥ Á¶±Ý ºÒ¾ÈÇÑ »ç¶÷µµ ÀÖÀ»°ÍÀÔ´Ï´Ù. ¿¹¿Ü°¡ ÇÕ´çÇÏ°Ô Ã³¸®µÇ¾ú´Ù¸é "catch"¸Þ¼µå´Â "nil"À» µÇµ¹¸± °ÍÀÌ°í, ±×·¸´Ù¸é "nil"¿¡ ´ëÇؼ "pass"³ª ´Ù¸¥ "catch" ¸Þ½ÃÁö¸¦ º¸³»´Â °ÍÀÌ µÇ¹Ç·Î JavaLanguageµî¿¡ Àͼ÷ÇÑ ºÐµéÀº »ó´çÈ÷ ºÒ¾ÈÇØ ÇÏ½Ç °Í °°½À´Ï´Ù. ÇÏÁö¸¸ "nil slotNames"¿Í °°ÀÌ "nil" ÇÁ·ÎÅ並 ã¾Æº¸¸é ´ÙÇàÈ÷ ÀÌ·¯ÇÑ ¸Þ¼µåµéÀ» ±¸ÇöÇÏ°í ÀÖ´Ù´Â °ÍÀ» ¾Ë ¼ö ÀÖ½À´Ï´Ù.(´ç¿¬È÷ ³»ºÎ ±¸ÇöÀº ¾Æ¹«°Íµµ ÇÏÁö ¾Ê´Â °ÍÀÌ°ÚÁö¿ä.) ¶ÇÇÑ ÀÌÈÄ¿¡ ÀÌ·±½ÄÀ¸·Î "nil"À» ÀÌ¿ëÇÏ°íÀÚ ÇÏ´Â °æ¿ì¿¡´Â ÀÌ·± 󸮸¦ ÇÏ´Â ÇÁ·ÎÅ並 Çϳª ¸¸µé°í¼ "nil" ÇÁ·ÎÅäÀÇ "protos"¸ñ·Ï¿¡ ±× °´Ã¼¸¦ Ãß°¡Çϸé "nil"·Îµµ ±×·¯ÇÑ ÇൿÀ» Àß Ã³¸®Çϵµ·Ï ÇÁ·Î±×·¥À» ÀÛ¼ºÇÒ ¼ö ÀÖ½À´Ï´Ù. ÀÌ·±°Ô PrototypeBasedÀÇ °·ÂÇÔÀÌ ¾Æ´Ò±î¿ä... ^^; ---- == Primitives == "Primitive"("¿ø¼Ò"¶ó°í ¸»ÇÏ°Ú½À´Ï´Ù.)Àº ÀϹÝÀûÀ¸·Î C¾ð¾î·Î ±¸ÇöÇÏ¿© IoLanguage¿¡ ³»ÀåµÇ¾î ÀÖ´Â ±âº»ÀûÀÎ °´Ã¼µéÀ» ¸»ÇÕ´Ï´Ù. ¿¹¸¦ µé¾î "Number"¿ø¼Ò´Â ¹èÁ¤µµ½Ç¼ö(double precision floating point number)¸¦ ±× ³»ºÎÀÇ ¼ûÀº ÀÚ·á·Î¼ Æ÷ÇÔÇϸç, ÀÌ¿¡ ´ëÇÑ ¸Þ¼µåµéÀº »ç½Ç C¾ð¾î·Î ±¸ÇöµÈ ÇÔ¼öÀÔ´Ï´Ù. ¸ðµç IoLanguageÀÇ ¿ø¼ÒµéÀº "Object" ÇÁ·ÎÅä·ÎºÎÅÍ ÆÄ»ýµÇ¾úÀ¸¸ç º¯Çü°¡´É(mutable)ÇÕ´Ï´Ù. ÀÌ´Â ¿ø¼ÒÀÇ ¸Þ¼µåµµ º¯°æÇÒ ¼ö ÀÖÀ½À» ÀǹÌÇÕ´Ï´Ù. ·¹ÆÛ·±½º ¹®¼µéÀº ¿ø¼Òµé¿¡ ´ëÇÑ ´õ ¸¹Àº Á¤º¸¸¦ Æ÷ÇÔÇÏ°í ÀÖ½À´Ï´Ù. ÀÌ ¹®¼´Â ·¹ÆÛ·±½º ¹®¼´Â ¾Æ´ÏÁö¸¸, IoLanguageÀ» ÀÌ¿ëÇϴµ¥ ÀÖ¾î¼ ±âº»ÀûÀ¸·Î »ç¿ëÇÏ´Â ¿ø¼Òµé°ú ¹ÙÀεù(binding)µé¿¡ ´ëÇؼ ¼³¸íÇÏ¸ç ¾î¶°ÇÑ °ÍµéÀÌ Á¦°øµÇ´ÂÁö¸¦ ¾Ë·Áµå¸±°ÍÀÔ´Ï´Ù. ¹«¾ùº¸´Ù ÀÌ ¹®¼¿¡¼ Á¦°øÇÏ´Â °ÍµéÀº ¸»±×´ë·Î ÀÔ¹®¿¡ °üÇÑ ¸Àº¸±â ¼öÁØÀÇ °ÍµéÀÌ¸ç ´õ À¯¿ëÇÏ°í ¸¹Àº ±â´ÉµéÀÌ IoLanguage¿¡´Â Æ÷ÇԵǾî ÀÖ½À´Ï´Ù. :-) === Object === === "?" ¿¬»êÀÚ === Á¾Á¾ ¾î¶² °´Ã¼¿¡ ¸Þ¼µå°¡ Á¸ÀçÇÏ´ÂÁö °Ë»çÇÏ°í ÀÖÀ»¶§¿¡¸¸ À̸¦ È£ÃâÇؾ߸¸ ÇÒ ¶§°¡ ÀÖ½À´Ï´Ù. ÀÌ·² ¶§¿¡ ¿¹¿Ü¸¦ ÀÏÀ¸Å°Áö ¾ÊÀ¸·Á¸é ´ÙÀ½Ã³·³ ÇؾßÇÒ°ÍÀÔ´Ï´Ù.: {{{ if(obj getSlot("foo"), obj foo) }}} À̸¦ ª°Ô ÁÙÀÌ¸é ¸Þ½ÃÁö ¾Õ¿¡ "?"À» ºÙÀÌ¸é °°Àº È¿°ú¸¦ ³¾ ¼ö ÀÖ½À´Ï´Ù.: {{{ obj ?foo }}} === List === "List"Àº ÂüÁ¶µé·Î ÀÌ·ç¾îÁø ¹è¿·Î¼ Ç¥ÁØÀûÀÎ ¹è¿Á¶ÀÛ°ú ³ª¿À» À§ÇÑ ¸Þ¼µåµéÀ» Æ÷ÇÔÇÕ´Ï´Ù. ºó ¸®½ºÆ®¸¦ ¸¸µé·Á¸é: {{{ a := List clone }}} ¶Ç´Â ¹Ù·Î ¸î°³ÀÇ °´Ã¼µéÀ» Æ÷ÇÔÇÏ´Â ¸®½ºÆ®¸¦ ¸¸µé·Á¸é "list()" ¸Þ¼µå¸¦ ÀÌ¿ëÇÕ´Ï´Ù.: {{{ a := list(33, "a") }}} ÀÌ¿¡ °´Ã¼¸¦ Ãß°¡ÇÏ·Á¸é: {{{ a append("b") ==> list(33, "a", "b") }}} ¸®½ºÆ®ÀÇ Å©±â¸¦ ±¸ÇÏ·Á¸é: {{{ a size ==> 3 }}} ¶Ç´Â ¾î¶² À§Ä¡ÀÇ ¿ä¼Ò¸¦ ±¸ÇÏ°íÀÚ ÇÑ´Ù¸é("List"ÀÇ »öÀÎÀº 0ºÎÅÍ ½ÃÀÛÇÕ´Ï´Ù.): {{{ a at(1) ==> "a" }}} '''ÁÖÀÇ''': "List"ÀÇ »öÀÎÀº 0ºÎÅÍ ½ÃÀÛÇÏ°í Á¢±ÙÇÑ »öÀÎÀÌ Á¸ÀçÇÏÁö ¾ÊÀ¸¸é "nil"À» µÇµ¹¸³´Ï´Ù. ƯÁ¤ À§Ä¡ÀÇ ¿ä¼Ò¸¦ ¼³Á¤ÇÏ·Á¸é: {{{ a atPut(2, "foo") ==> list(33, "a", "foo") a atPut(6, "Fred") ==> Exception: index out of bounds }}} ƯÁ¤ ¿ä¼Ò¸¦ »èÁ¦ÇÏ·Á¸é: {{{ a remove("foo") ==> list(33, "a", "b") }}} ƯÁ¤ À§Ä¡¿¡ ¿ä¼Ò¸¦ »ðÀÔÇÏ·Á¸é: {{{ a atInsert(2, "foo") ==> list(33, "a", "foo", ...) }}} ==== foreach ==== "foreach", "map", "select" ¸Þ¼µå´Â 3°¡Áö ÇüÅ·Π»ç¿ëµË´Ï´Ù. {{{ Io> a := list(65, 21, 122) }}} ù¹ø° ÇüÅ·μ ù¹ø° ÀÎÀÚ´Â "index variable", µÎ¹ø° ÀÎÀÚ´Â "value varaible", ¼¼¹ø°´Â °¢°¢ÀÇ °ª¿¡ ´ëÇؼ Æò°¡ÇÒ ¹®ÀåÀÔ´Ï´Ù.: {{{ Io> a foreach(i, v, write(i, ¡°:¡±, v, ¡°, ¡±)) ==> 0:65, 1:21, 2:122, }}} µÎ¹ø° ÇüÅ´ "index argument"À» Á¦¿ÜÇÑ °æ¿ìÀÔ´Ï´Ù.: {{{ Io> a foreach(v, v println) ==> 65 21 122 }}} ¼¼¹ø° ÇüÅ´ ¸ðµç ÀÎÀÚ¸¦ Á¦¿ÜÇÏ°í Ç¥Çö½ÄÀ» °¢°¢ÀÇ °ª¿¡ ´ëÇؼ º¸³»µµ·Ï ÇÏ´Â ¹æ¹ýÀÔ´Ï´Ù.: {{{ Io> a foreach(println) ==> 65 21 122 }}} ==== map, select ==== IoLanguageÀÇ "map", "select"("filter"¶ó°íµµ ´Ù¸¥ ¾ð¾î¿¡¼ ¾Ë·ÁÁø) ¸Þ¼µå´Â ´Ù¾çÇÑ Ç¥Çö½ÄÀ» map/select predicate·Î¼ »ç¿ëÇÏ°Ô ÇØÁÝ´Ï´Ù.: {{{ Io> numbers := list(1,2,3,4,5,6) Io> numbers select(isOdd) ==> list(1,3,5) Io> numbers select(x, x isOdd) ==> list(1,3,5) Io> numbers select(i, x, x isOdd) ==> list(1,3,5) Io> numbers map(x, x*2) ==> list(2,4,6,8,10,12) Io> numbers map(i, x, x+i) ==> list(1,3,5,7,9,11) Io> numbers map(*3) ==> list(3,6,9,12,15,18) }}} "map", "select" ¸Þ¼µå´Â »õ·Î¿î ¸®½ºÆ®¸¦ µÇµ¹¸³´Ï´Ù. InPlaceÇü½ÄÀ¸·Î ÇöÀçÀÇ °´Ã¼¸¦ º¯°æÇÏ·Á¸é "selectInPlace()", "mapInPlace()"À» »ç¿ëÇϼ¼¿ä. === Sequence === IoLanguage¿¡¼ ºÒº¯ÀûÀÎ ½ÃÄö½º(ImmutableSequence)Àº "Symbol"À̶ó°í ºÒ¸®°í "Buffer"³ª "String"ó·³ °¡º¯ÀûÀÎ ½ÃÄö½º´Â "Sequence"¶ó°í ÇÕ´Ï´Ù. ¹®ÀÚ¿Ç¥Çö½Ä(Literal Strings, ¼Ò½ºÄڵ忡¼ ½Öµû¿ÈÇ¥·Î ¹¿©Á®¼ Ç¥ÇöÇÏ´Â)Àº "Symbol"ÀÔ´Ï´Ù. "Symbol"¿¡ ´ëÇؼ´Â º¯°æÀ» ¿äÇÏ´Â ÀÛ¾÷(MutableOperations)Àº Àû¿ëÇÒ ¼ö ¾øÀ¸¸ç, "asMutable" ¸Þ¼µå¸¦ »ç¿ëÇÏ¿© º¹»çÇÑ ´ÙÀ½¿¡ À̸¦ Àû¿ëÇؾßÇÕ´Ï´Ù. ==== °øÅëÀûÀÎ ¹®ÀÚ¿ ÀÛ¾÷µé ==== ¹®ÀÚ¿ÀÇ ±æÀ̸¦ ¾ò±â: {{{ "abc" size ==> 3 }}} ¹®ÀÚ¿ÀÌ ºÎºÐ¹®ÀÚ¿À» Æ÷ÇÔÇϴ°¡?: {{{ "apples" containsSeq("ppl") ==> true }}} NÀÇ À§Ä¡ÀÇ ¹®ÀÚ(¹ÙÀÌÆ®)À» ±¸Çϱâ: {{{ "Kavi" at(1) ==> 97 }}} ½½¶óÀ̽º(Slicing): {{{ "Kirikuro" slice(0,2) ==> "Ki" "KiriKuro" slice(-2) # != slice(-2, 0) ==> "ro" "Kirikuro" slice(0, -2) ==> "Kiriku" }}} °ø¹éÁ¦°ÅÇϱâ(stripping whitespace): {{{ " abc " asMutable strip ==> "abc" " abc " asMutable lstrip ==> "abc " " abc " asMutable rstrip ==> " abc" }}} ´ë¼Ò¹®ÀÚº¯È¯: {{{ "Kavi" asUppercase ==> "KAVI" "Kavi" asLowercase ==> "kavi" }}} ¸®½ºÆ®·Î ºÐ¸®Çϱâ: {{{ "the quick brown fox" split ==> list("the", "quick", "brown", "fox") }}} ´Ù¸¥ ¹®ÀÚ¸¦ ºÐ¸®ÀÚ·Î Çؼ ºÐ¸®Çϱâ: {{{ "a few good men" split("e") ==> list("a f", "w good m","n") }}} ¼ýÀÚ·Î º¯È¯Çϱâ: {{{ "13" asNumber ==> 13 "a13" asNumber ==> nil }}} º¯¼öÆ÷ÇÔÇϱâ(interpolation): {{{ name := "Fred" "My name is #{name}" interpolate ==> "My name is Fred" }}} "interpolate"Àº "#{}"¾ÈÀÇ ¾î¶°ÇÑ ÄÚµåµçÁö LocalContext¾È¿¡¼ Æò°¡ÇÏ¿© °á°ú¸¦ µÇµ¹¸³´Ï´Ù. ÀÌ ÄÚµå´Â ·çÇÁ³ª ¾î¶°ÇÑ °ÍÀ̵ç "asString" ¸Þ½ÃÁö¿¡ ÀÀ´äÇÒ ¼ö ÀÖ´Â °ÍÀº ¹¹µçÁö ÇÒ ¼ö ÀÖ½À´Ï´Ù. === Range === "range"Àº ½ÃÀÛÁ¡°ú ³¡Á¡À» Æ÷ÇÔÇÏ´Â ÀڷᱸÁ¶À̸ç, ½ÃÀÛÁ¡À¸·ÎºÎÅÍ ³¡Á¡±îÁö ¾î¶»°Ô À̵¿ÇÏ´ÂÁö¸¦ Æ÷ÇÔÇÕ´Ï´Ù. "Range"À» ÀÌ¿ëÇÏ¿© Ä¿´Ù¶õ ¸®½ºÆ®³ª ¼øÂ÷ÀûÀÎ µ¥ÀÌÅ͸¦ ¸¸µé¾î ¸®½ºÆ®³ª "for()"À» ´ëüÇÏ´Â °ÍÀ» ½±°ÔÇÕ´Ï´Ù. ==== "Range" ÇÁ·ÎÅäÄÝ ==== ¾î¶² °´Ã¼ÀÌ°Ç "nextInSequence" ¸Þ¼µå¸¦ ±¸ÇöÇϸé "Range"¿¡ Æ÷ÇÔÇÒ ¼ö ÀÖ½À´Ï´Ù. ÀÌ ¸Þ¼µå´Â ÇϳªÀÇ ¼±ÅÃÀûÀÎ ÀÎÀÚ¸¦ ÃëÇÕ´Ï´Ù.(°´Ã¼µéÀÇ ¼ø¼¿¡¼ ¸î°³³ª ±×³É Áö³ªÄ¥ °ÍÀÎÁö¸¦ ÁöÁ¤ÇÏ´Â ¼ýÀÚÀÔ´Ï´Ù.) ¶ÇÇÑ Áö³ª°£ ´ÙÀ½ ´ÙÀ½ÀÇ °´Ã¼¸¦ µÇµ¹¸®¸é µË´Ï´Ù. ±âº»ÀûÀÎ "skip value"Àº 1ÀÔ´Ï´Ù. "skip value" 0Àº Á¤ÀǵÇÁö ¾Ê¾Ò½À´Ï´Ù.: {{{ Number nextInSequence := method(skipVal, if(skipVal isNil, skipVal = 1) self + skipVal) }}} ÀÌ·¸°Ô "Number"¿¡ ÀÌ ¸Þ¼µå¸¦ ³ÖÀ¸¸é(±âº»ÀûÀ¸·Î Æ÷ÇԵǾî ÀÖÁö¸¸), "Number"À» "Range"¿¡¼ »ç¿ëÇÒ ¼ö ÀÖ½À´Ï´Ù.: {{{ 1 to(5) foreach(v, v println) }}} ÀÌ»óÀÇ ÄÚµå´Â 1ºÎÅÍ 5±îÁö Ãâ·ÂÇÒ°ÍÀÔ´Ï´Ù. === File === File°´Ã¼¸¦ »ý¼ºÇÏ´Â °Í¸¸À¸·Î´Â ÆÄÀϳ»¿ë¿¡ °ü·ÃµÈ ÀÛ¾÷À» ÇÏÁö ¾Ê°í, ÆÄÀÏ°ü¸®(»èÁ¦¿Í °°Àº)À» ÇÒ ¼ö ÀÖÀ¸¸ç, ½ÇÁ¦·Î ÆÄÀÏÀÇ ³»¿ëÀ» Àаųª ¾²·Á¸é "openForAppending", "openForReading", "openForUpdating"À» »ç¿ëÇÏ¿© ¿¾î¾ß ÇÕ´Ï´Ù. ÆÄÀÏÀ» »èÁ¦ÇÏ·Á¸é "remove"¸Þ¼µå¸¦ »ç¿ëÇÕ´Ï´Ù. {{{ f := File with(¡°foo.txt) f remove f openForUpdating f write(¡°hello world!¡±) f close }}} === Directory === µð·ºÅ丮 »ý¼ºÇϱâ: {{{ dir := Directory with(¡°/Users/steve/¡±) }}} µð·ºÅ丮ÀÇ ¸ðµç ÆÄÀϵéÀÇ ¸ñ·Ï ±¸Çϱâ: {{{ files := dir files ==> list(File_0x820c40, File_0x820c40, ...) }}} µð·ºÅ丮ÀÇ µð·ºÅ丮¸¦ Æ÷ÇÔÇÑ ÆÄÀϸñ·Ï ±¸Çϱâ: {{{ items := Directory items ==> list(Directory_0x8446b0, File_0x820c40, ...) items at(4) name ==> DarkSide-0.0.1 # a directory name }}} Àý´ë°æ·Î·Î ¼³Á¤ÇÏ°í À̸¦ »ç¿ëÇϱâ: {{{ root := Directory clone setPath("c:/") ==> Directory_0x8637b8 root fileNames ==> list("AUTOEXEC.BAT", "boot.ini", "CONFIG.SYS", ...) }}} Á¸ÀçÇÏ´ÂÁö¸¦ °Ë»çÇϱâ: {{{ Directory clone setPath("q:/") exists ==> false }}} ÇöÀçÀÛ¾÷µð·ºÅ丮 ±¸Çϱâ: {{{ Directory currentWorkingDirectory ==> ¡°/cygdrive/c/lang/IoFull-Cygwin-2006-04-20¡± }}} === Date=== »õ·Î¿î "Date"ÀνºÅϽº¸¦ ¸¸µé±â: {{{ d := Date clone }}} ÇöÀç ½Ã°¢À¸·Î ¸ÂÃß±â: {{{ d now }}} ÃÊ´ÜÀ§·Î ȯ»êÇϱâ: {{{ Date now asNumber ==> 1147198509.417114 Date now asNumber ==> 1147198512.33313 }}} "Date"°´Ã¼ÀÇ ºÎºÐºÎºÐÀ» ¾ò±â: {{{ d := Date now ==> 2006-05-09 21:53:03 EST d ==> 2006-05-09 21:53:03 EST d year ==> 2006 d month ==> 5 d day ==> 9 d hour ==> 21 d minute ==> 53 d second ==> 3.747125 }}} ¾î¶² Äڵ带 ½ÇÇàÇϴµ¥ °É¸° ½Ã°£ ±¸Çϱâ: {{{ Date cpuSecondsToRun(100000 repeat(1+1)) ==> 0.02 }}} === Networking === ¸ðµç IoLanguageÀÇ ³×Æ®¿öÅ· °ü·Ã °´Ã¼µéÀº ºñµ¿±âÀû ¼ÒÄÏ(AsynchronousSocket)ÀÇ ¾Æ·¡¿¡ ÀÖÁö¸¸, Àб⳪ ¾²±â¿Í °°Àº CoRoutineÀÌ È£ÃâµÇ¾î¾ß ÇÏ´Â ÀÛ¾÷µéÀº ÀÌ·¯ÇÑ ÀÛ¾÷ÀÌ ¿Ï·áµÉ ¶§±îÁö µ¿±âÀûÀ¸·Î ó¸®Çϰųª, ŸÀӾƿô(timeout)ÀÌ ¹ß»ýÇÕ´Ï´Ù. '''ÁÖÀÇ''': ´ÙÀ½À» ÀÌ¿ëÇϱâ À§Çؼ "Socket" addon°ú °°Àº addonÀ» ¸ÕÀú ÄÄÆÄÀÏÇÏ¿© Æ÷ÇÔÇÒ ÇÊ¿ä°¡ ÀÖ½À´Ï´Ù. URL °´Ã¼ ¸¸µé±â: {{{ url := URL with("http://example.com/") }}} URLÀÇ ³»¿ë°¡Á®¿À±â: {{{ data := url fetch }}} URLÀÇ ³»¿ëÀ» ÆÄÀÏ·Î ¾²±â: {{{ url streamTo(File with("out.txt")) }}} SimpleWhoisClient: {{{ whois := method(host, socket := Socket clone setHostName("rs.internic.net") setPort(43) socket connect streamWrite(host, "\n") while(socket streamReadNextChunk, nil) return socket readBuffer) }}} MinimalWebServer: {{{ WebRequest := Object clone do( handleSocket := method(aSocket, aSocket streamReadNextChunk request := aSocket readBuffer betweenSeq("GET ", " HTTP") f := File with(request) if(f exists, f streamTo(aSocket), aSocket streamWrite("not found")) aSocket close)) WebServer := Server clone do( setPort(8000) handleSocket := method(aSocket, WebRequest clone @handleSocket(aSocket))) WebServer start }}} === XML === XML Æļ¸¦ »ç¿ëÇÏ¿© ÇØ´ç ÆäÀÌÁöÀÇ ¸µÅ©µéÀ» ¾ò±â: {{{ xml := URL with("http://www.yahoo.com/") fetch asXML links := xml elementsWithName("a") map(attributes at("href")) }}} ---- == ³»ÀåÇϱâ == ÀÌ ¼½¼Ç¿¡¼´Â IoVmÀ» ´Ù¸¥ CÇÁ·Î±×·¥¿¡ ³»ÀåÇÏ´Â ¹æ¹ý¿¡ ´ëÇؼ °£·«ÇÏ°Ô ¼³¸íÇÏ°Ú½À´Ï´Ù. === ÄÚµù±Ô¾à === IoLanguageÀÇ C¾ð¾î ÄÚµåµéÀº ±¸Á¶Ã¼¸¦ °´Ã¼·Î, ÇÔ¼öµéÀ» ¸Þ¼µå·Î ÇÏ´Â °´Ã¼ÁöÇâÀûÀÎ ½ºÅ¸ÀÏ ±Ô¾àÀ» µû¶ó¼ ÀÛ¼ºµÇ¾ú½À´Ï´Ù. ÀÌ·¯ÇÑ °Íµé°ú Ä£¼÷ÇØÁö´Â °ÍÀº ³»Àå APIµéÀ» ´õ ½±°Ô ÀÌÇØÇϴµ¥ ÀÖ¾î¼ µµ¿òÀÌ µÉ °Í ÀÔ´Ï´Ù. ==== ±¸Á¶Ã¼ ==== ¸â¹öÀÇ À̸§Àº ÀϹÝÀûÀÎ ¼Ò¹®ÀÚ·Î ½ÃÀÛÇÏ´Â ³«Å¸·Î Ç¥±âÇÕ´Ï´Ù.: {{{ typedef struct { char *firstName; char *lastName; char *address; } Person; }}} ==== ÇÔ¼ö ==== ÇÔ¼öÀ̸§Àº ±×µéÀÌ ¿¬°üµÈ ±¸Á¶Ã¼ÀÇ À̸§°ú ¹ØÁÙÀ» °¡¿îµ¥ µÎ°í¼ ³ª¸ÓÁö ´Ü¾îµéÀ» ¹ØÁÙ·Î ÀÕ½À´Ï´Ù. ¶ÇÇÑ ¸ðµç ±¸Á¶Ã¼´Â ±×µé¿¡ ÇØ´çÇÏ´Â "new", "free" ÇÔ¼ö°¡ ÀÖ½À´Ï´Ù.: {{{ List *List_new(void); void List_free(List *self); }}} "new"À» Á¦¿ÜÇÏ°í ¸ðµç ¸Þ¼µåµéÀº ("°´Ã¼")¿¡ ´ëÇÑ ±¸Á¶Ã¼¸¦ ù¹ø° ÀÎÀڷμ ¹Þ´Âµ¥ À̸§À» "self"·Î ÇÕ´Ï´Ù. ¸Þ¼µå À̸§Àº "keyword format"À¸·Î Áþ½À´Ï´Ù. ÀÌ´Â °¢°¢ÀÇ ÀÎÀÚ¿¡ ´ëÇؼ ¸Þ¼µå À̸§ ³¡¿¡ ¹ØÁÙÀ» ´Þ¾ÆÁÝ´Ï´Ù.: {{{ int List_count(List *self); /* no argument */ void List_add_(List *self, void *item); /* one argument */ void Dictionary_key_value_(Dictionary *self, char *key, char *value); }}} ==== ÆÄÀÏÀ̸§ ==== °¢°¢ÀÇ ±¸Á¶Ã¼´Â ºÐ¸®µÈ .h, .c ÆÄÀÏ¿¡ ÀúÀåÇÕ´Ï´Ù. ÆÄÀÏÀÇ À̸§Àº ±¸Á¶Ã¼ÀÇ À̸§°ú µ¿ÀÏÇÏ°Ô Áþ½À´Ï´Ù. ÀÌ·¯ÇÑ ÆÄÀϵéÀº ¿¬°üµÈ ¸ðµç ÇÔ¼ö(¸Þ¼µå)¸¦ Æ÷ÇÔÇÕ´Ï´Ù. === IoState === "IoState"Àº IoVmÀÇ ÀνºÅϽº·Î »ý°¢ÇÒ ¼ö ÀÖ½À´Ï´Ù. ==== ¿©·¯°³ÀÇ »óŵé ==== IoLanguageÀº MultiStateÇÕ´Ï´Ù. ÀÌ ¶æÀº Çѹø¿¡ ¿©·¯°³ÀÇ »óÅ°¡ ÇϳªÀÇ ÇÁ·Î¼¼½º ¾È¿¡ Á¸ÀçÇÒ ¼ö ÀÖ´Ù´Â ¶æÀÔ´Ï´Ù. ÀÌ·¯ÇÑ ÀνºÅϽºµéÀº °¢±â °Ý¸®µÇ¾î ÀÖÀ¸¸ç ¾î¶°ÇÑ ¸Þ¸ð¸®µµ °øÀ¯ÇÏÁö ¾ÊÀ¸¹Ç·Î µ¿½Ã¿¡ ´Ù¸¥ ½º·¹µåµé·ÎºÎÅÍ ¾ÈÀüÇÏ°Ô Á¢±ÙÀÌ °¡´ÉÇÕ´Ï´Ù.(ÇϳªÀÇ ½º·¹µå°¡ ÇϳªÀÇ »óŸ¸À» Á¢±ÙÇؾ߰ÚÁö¸¸) ==== Creating a state ==== °£´ÜÇÑ ¹®ÀÚ¿À» Æò°¡ÇÏ´Â ÄÚµåÀÔ´Ï´Ù. »óŸ¦ ¸¸µé°í, ÃʱâÈÇÏ°í, Æò°¡ÇÑ ´ÙÀ½¿¡ ´Ù½Ã ÇØÁ¦ÇÕ´Ï´Ù.: {{{ #include "IoState.h" int main(int argc, const char *argv[]) { IoState *self = IoState_new(); IoState_init(self); IoState_doCString_(self, ¡°writeln(\¡±hello world!\¡±¡±); IoState_free(self); return 0; } }}} === Values === µÇµ¹¸² °ªÀ» ¹Þ¾Æ¼ À̸¦ ´Ù½Ã Ãâ·ÂÇÏ·Á¸é ´ÙÀ½°ú °°ÀÌ ÇÕ´Ï´Ù.: {{{ IoObject *v = IoState_doCString_(self, someString); char *name = IoObject_name(v); printf(¡°return type is a ¡®%s¡¯, name); IoObject_print(v); }}} ==== Checking value types ==== °£´ÜÇÑ Å¸ÀÔüũ¸¦ À§ÇÑ ¸ÅÅ©·Î°¡ ÀÖ½À´Ï´Ù.: {{{ if (ISNUMBER(v)) { printf(¡°result is the number %f¡±, IoNumber_asFloat(v)); } else if(ISSEQ(v)) { printf(¡°result is the string %s¡±, IoSeq_asCString(v)); } else if(ISLIST(v)) { printf(¡°result is a list with %i elements¡±, IoList_rawSize(v)); } }}} '''ÁÖÀÇ''': µÇµ¹¸²°ªÀº ¾ðÁ¦³ª È®½ÇÇÑ Io °´Ã¼ÀÔ´Ï´Ù.(¸ðµç °ªÀÌ Io¾ÈÀÇ °´Ã¼À̵íÀÌ.) ÀÌ·¯ÇÑ °Íµé¿¡ ´ëÇؼ C¾ð¾î ¼öÁØ¿¡¼ ÀÛ¾÷ÇÒ ¼ö ÀÖ´Â ¸Þ¼µåµé("IoList_rawSize()"¿Í °°Àº ÇÔ¼öµé)À» "./libs/iovm/source"ÀÇ Çì´õÆÄÀÏ¿¡¼ ½±°Ô ãÀ» ¼ö ÀÖÀ» °Í ÀÔ´Ï´Ù. ---- ##TODO: È®Àå? ---- CategoryLanguage |