《七周七语言》之Io 第一天自习
答:
1:对1+1求值,然后对1+"one"求值;Io是强类型还是弱类型?用代码证实你的答案。
Io> 1+1 ==> 2 Io> 1+"ont" Exception: argument 0 to method '+' must be a Number, not a 'Sequence' --------- message '+' in 'Command Line' on line 1
可以看出,强类型;
2:0是true还是false?空字符串是true还是false?nil是true还是false?用代码证实你的答案。
Io> true and 0 ==> true Io> false and 0 ==> false Io> true and -1 ==> true
0是true
Io> true and "" ==> true Io> false and "" ==> false Io> 0 and "" ==> true
空字符串是true
Io> nil and true ==> false Io> nil and false ==> false Io> nil or "" ==> true
nil是false
3:如果知道某个原型支持那些槽?
根据:对象有槽;槽包含对象,方法; Io> Object proto ==> Object_0x272020: Car = Car_0x49a6b0 Lobby = Object_0x272020 Protos = Object_0x271f90 _ = Object_0x272020 exit = method(...) forward = method(...) set_ = method(...)
4:= 、 := 、 ::= 之间的区别?你会在什么情况下使用他们?
=是复制; :=是方法复制不存在,则创建; ::=: Io> Car := Object clone ==> Car_0x2d8d40: type = "Car" Io> Car1 := Car clone ==> Car1_0x2e0af0: type = "Car1" Io> Car2 ::= Car clone ==> Car_0x2716c0: Io> Car3 ::= Car1 clone ==> Car1_0x234380: Io> Car4 ::= Car2 clone ==> Car_0x204010: Io> Car2 type ==> Car 根据原型,创建一个原型对象,再赋值引用; 而如果是:=,则代表根据原型,创建自己的一个对象;
operator action ::= Creates slot, creates setter, assigns value := Creates slot, assigns value = Assigns value to slot if it exists, otherwise raises exception
参考资料:
http://iolanguage.org/scm/io/docs/IoGuide.html#Syntax-Operators
做:
从文件运行Io程序。
命名为*.io,直接运行;
给定槽的名称和原型。执行槽中的代码。
obj method

浙公网安备 33010602011771号