5.2の途中だけど例のごとくIolanguageで。
5章5.1, 5.2
Object curlyBrackets := method( map := Map clone; call message arguments foreach(arg, arg setName("atPut"); map doMessage(arg)); map; ) Object squareBrackets := method( list := List clone; call message arguments foreach(arg, list append(arg)); list ) nodes := { living_room := "you are in the living-room. a wizard is snoring loudly on the couch.", garden := "you are in a beautiful garden. there is a well in front of you.", attic := "you are in the attic. there is a giant welding torch in the corner." } //nodes := Map clone //nodes atPut("living_room", "you are in the living-room. a wizard is snoring loudly on the couch.") //nodes atPut("garden", "you are in a beautiful garden. there is a well in front of you.") //nodes atPut("attic", "you are in the attic. there is a giant welding torch in the corner.") assoc := method(key, items, items at(key)) describe_location := method(key, items, assoc(key, items)) //describe_location("garden", nodes) println edges := { living_room := [ ["garden", "west", "door"], ["attic", "upstairs", "ladder"] ], garden := [ ["living_room", "east", "door"] ], attic := [ ["living_room", "downstairs", "ladder"] ] } car := method(list, list at(0)) cdr := method(list, list exSlice(1, list size)) cadr := method(list, car(cdr(list))) cddr := method(list, cdr(cdr(list))) caddr := method(list, car(cddr(list))) describe_path := method(edge, "there is a " .. caddr(edge) .. " going " .. cadr(edge) .. " from here.") describe_path([garden, west, door]) println
所感
JSでいうところのリテラルの配列やオブジェクトがIolanguageではないから、curlyBrackets, squareBracketsとMap, Listを駆使して定義しないといけなかった。
carやcdrの定義も結構適当。
書籍
- 作者: M.D. Conrad Barski,川合史朗
- 出版社/メーカー: オライリージャパン
- 発売日: 2013/02/23
- メディア: 大型本
- 購入: 1人 クリック: 7回
- この商品を含むブログ (4件) を見る