Smalltalk 㨠Ruby 㨠LISP ã®ã·ã³ãã«
Smalltalk ã Ruby ã LISP ãã·ã³ãã«ã®æ¬è³ªã¯ãããããâã¤ã³ã¿ã¼ã³ãããæååâã§ããã¤ã³ã¿ã¼ã³ï¼internï¼ã«ã¯ãã訳èªãæãã¤ããªãã®ã§ãããç°¡åã«ã¯ãç»é²ãã管çãããâ¦ãã¨ããæãã§ãããããããããå®è£
ãæ¯ãèãã¯å¿
ããããã®ã¨ããã«ã¯ãªã£ã¦ãã¾ãããç¹ã«æååã ã¨æèãã¦æ±ãéã«ã¯æ³¨æãå¿
è¦ã§ãããã
注æï¼ããã§ã®ãSmalltalkãã¨ã¯ Squeak ã® Smalltalk ãæãã¾ããä»ã® Smalltalk å¦çç³»ï¼ç¹ã«ãããã¡ã¯ãã»ã¹ã¿ã³ãã¼ãã® VisualWorks ã ANSI æºæ ã®ãæ製 Smalltalk å¦çç³»ï¼ã§ã¯ç°ãªãæåã示ãã¨ã®ãææãåãã¾ããã®ã§ããè©«ã³ãã¦ä¿®æ£ã以ä¸ã®é
ç®ã«è¿½è¨ãããã¦ããã ãã¾ãã
Smalltalk ã®ã·ã³ãã«
Smalltalk ã®ã·ã³ãã«ã¯ãâç価ãªã常ã«åä¸ã§ãã¤ãã¥ã¼ã¿ãã«ãªæååâã¨ãããµãã«ä½ç½®ã¥ããããå®éã«å®è£
ããããªã£ã¦ãã¾ãï¼ã·ã³ãã«ã®ã¯ã©ã¹ Symbol ã¯ãString ã®ãµãã¯ã©ã¹ã§ãããã¨ãï¼ã
ç価ãªãåä¸
'hoge' copy = 'hoge' copy " => true " 'hoge' copy == 'hoge' copy " => false " #hoge copy = #hoge copy " => true " #hoge copy == #hoge copy " => true "
ã¤ãã¥ã¼ã¿ãã«
'hoge' at: 2 put: $a; yourself " => 'hage' " #hoge at: 2 put: $a " => Error: symbols can not be modified. "
ãªããVisualWorks ã® Smalltalk ã§ã¯ãæååã§ããªãã©ã«ã¯ã¤ãã¥ã¼ã¿ãã«ãªã®ã§ããã£ããã³ãã¼ãã¦ããã§ãªãã¨ã¨ã©ã¼ã«ãªãã¾ãã
'hoge' at: 2 put: $a; yourself " => Error " 'hoge' copy at: 2 put: $a; yourself " => 'hage' "
ãããã®ç¹å¾´ã«çç¾ããªãéããæååã¨åæ§ã«æ¯ãèããã¾ãåãå
容ã®æååã¨ã¯ç価ã¨ã¿ãªããã¾ãã
æååã®ããã«æ¯ãèã
'hoge' at: 3 " => $g " #hoge at: 3 " => $g " 'hoge' asUppercase " => 'HOGE' " #hoge asUppercase " => 'HOGE' "
åãå 容ã®æååã¨ã¯ç価ã¨ã¿ãªããã
'hoge' = #hoge " => true " #hoge = 'hoge' " => true "
追è¨ï¼åæã® Squeakï¼1.13ï¼ãã 2.x ã¾ã§ã¯ãããã¨ã¯ç°ãªãæåã§ããããããã Smalltalk-80 ã§ã¯ï¼Squeak 1.13 åæ§ãï¼åè
㯠true å¾è
㯠false ã ã£ãã®ããANSI ã§ã¯åæ¹ false ã«ãANSI ã¨ã¯è·é¢ãããã¦ãã Squeak ã§ã¯åæ¹ true ã«ãªã£ãâ¦ã¨ããçµç·¯ããã£ãããã§ãããããã£ã¦ãåãå
容ãªãç価ã¨ã¿ãªãããããã©ããã¯ãSmalltalk ã§ãæè¦ãåãããã¨ããã®ããã§ãã
Ruby ã®ã·ã³ãã«
Ruby ã®ã·ã³ãã«ã¯ãç価ãªãåä¸ã¨ããä¸ææ§ã®ã»ãã«éããç½®ããä½ç½®ã¥ãã«ãªã£ã¦ãã¾ããæååã®ä»£ããã«ç¨ãããã¨ãã§ãã¾ãããå¿
ãããæååã¨åãæ¯ãèãã¯ãã¾ããï¼to_s ã«ããæ示çã«æååã«å¤æããå¿
è¦ãããã¾ãï¼ãã Ruby ã½ã¼ã¹ã³ã¼ãå®å
¨è§£èª¬ãã®ç¬¬ï¼ç« ããªãã¸ã§ã¯ããã«ããã°ãRuby ã®ã·ã³ãã«ã¯ã以åã¯åãªã Fixnumï¼Smalltalk ã® a SmallInteger ï¼ã ã£ãããã§ããããC ã® enum ã®ãããªæ©æ§ãå½¹å²ãã¤ã¡ã¼ã¸ããæ¹ãç¡é£â¦ã¨ãããããªå°è±¡ãå人çã«ã¯åãã¾ããï¼è¿½è¨ï¼1.9 以éã§ã¯ãä»æ§ãå¤æ´ã«ãªãå¯è½æ§ãé«ãããã§ããï¼
ç価ãªãåä¸
"hoge".id == "hoge".id #=> false :hoge.id == :hoge.id #=> true
æååã®ä»£æ¿ãã¨ãã¦ä½¿ããã¨ããããããæååã®ããã«ã¯æ¯ãèããªã
Object.method("to_s") #=> #<Method: Class(Module)#to_s> Object.method(:to_s) #=> #<Method: Class(Module)#to_s>
"hoge"[2].chr #=> "g" :hoge[2].chr #=> NoMethodError "hoge".upcase #=> "HOGE" :hoge.upcase #=> NoMethodError
åãå 容ã§ãæååã¨ã¯åºå¥ããã
"hoge" == "hoge" #=> true "hoge" == :hoge #=> nil 1.8.2 以éã§ã¯ falseã :hoge == "hoge" #=> false
LISP ã®ã·ã³ãã«ï¼Common Lisp ãªã©ã®å ´åï¼
両è
ã«å½±é¿ãä¸ãã LISP ã®ã·ã³ãã«ã¯ãããããã®ã·ã³ãã«ã¨ã¯ã¾ãä¸ç·ãç»ãããã®ã«ãªã£ã¦ãã¾ããæååã®ããã«è¦ãã¦ããå¿
ããã常ã«ãã®ããã«æ±ããã¨ã¯éããªãç¹ã«é¢ãã¦ã¯ãRuby ã®ã·ã³ãã«ã«ããä¼¼ã¦ãã¾ãããããããã®å®ä½ã¯æ´æ°ã®ãããªåç´ãªãã®ã§ã¯ãªãã対å¿ããæååã¯ãã¡ãããã¤ã³ã¿ã¼ã³ãããããã±ã¼ã¸åãå¤ãé¢æ°ï¼ãããã¯å±æ§ãªã¹ãï¼ã¨ããããã«å¤å²ã«ãããæ
å ±ãä¿æã§ããæ¯è¼çè¤éãªãªãã¸ã§ã¯ãã§ããããã§ãï¼åèï¼ã·ã³ãã«ã¨ããã±ã¼ã¸ï¼ã
ç価ãªãåä¸
(eq "hoge" "hoge") ;;=> NIL (eq 'hoge 'hoge ) ;;=> T
å¿ ããã常ã«æååã®ããã«æ±ããããã§ã¯ãªãï¼é¢æ°ã®å®è£ ã«ä¾åï¼ï¼
(char "hoge" 2) ;;=> #\g (char 'hoge 2) ;;=> argument HOGE is not STRING (string-upcase "hoge") ;;=> "HOGE" (string-upcase 'hoge ) ;;=> "HOGE"
ãã ãã
(symbol-name 'hoge) ;;=> "HOGE"
(symbol-name '|hoge|) ;;=> "hoge" (string-upcase '|hoge| ) ;;=> "HOGE"
åãå 容ã®æååã¨ã¯åºå¥ããã
(equal "HOGE" 'hoge) ;;=> NIL (equal "hoge" '|hoge|) ;;=> NIL
ãã ããæååã¨è¦ãªãã¨ãã¯ï¼å½ç¶ã ãâ¦ï¼ç価ã¨å¤æãããã
(string= "HOGE" 'hoge) ;;=> T (string= "hoge" '|hoge|) ;;=> T
å¤ and/or é¢æ°ãæç¸ãã¦ãããããã®å¥åã¨ãã¦ä½¿ãã
(setq foo 4) (defun foo (x) (+ 3 x))
(symbol-name 'foo) ;;=> "FOO" (symbol-package 'foo) ;;=> #<PACKAGE COMMON-LISP-USER> (symbol-value 'foo) ;;=> 4 (symbol-function 'foo) ;;=> #<CLOSURE FOO (X) (DECLARE (SYSTEM::IN-DEFUN FOO)) (BLOCK FOO (+ 3 X))>
(* 3 foo) ;;=> 12 (foo 0.5) ;;=> 3.5 (foo foo) ;;=> 7