HyperTalk

HyperCardのクローンを作ろうかなと思って、いま、HyperTalkの言語仕様を調べつつ、拡張を考えている。
HyperTalkの拡張として、以下の機能を追加予定。

  • HyperCardの機能を除いて、HyperTalkと完全互換
  • プロトタイプ型オブジェクト指向への対応
    • objectブロックの追加
    • objectの継承の追加
    • objectの委譲の追加
    • propertyステートメントの追加
    • パターンマッチの追加
  • クロージャへの対応
    • 内部onブロックの追加
    • 内部functionブロックの追加
    • 内部doブロックの追加

objectブロックの追加

objectブロックを追加することで、プロトタイプ・オブジェクト指向へと対応させる。
以下、Buttonオブジェクトの例。

object Button

  property hilight
  
  on initialize
    set hilight to false
  end initialize

  on mouseUp
    set hilight to not hilight
  end mouseUp

end Button

put new object Button into btn

mouseUp btn -- ボタンがハイライトされる
mouseUp btn -- ボタンのハイライトが消される

objectの継承(?)

プロトタイプを継承して、新しいオブジェクトを作成する。

object VisibleButton cloned Button
  
  property visible

  on show
    set visible to true
  end show

  on hide
    set visible to false
  end hide

end VisibleButton

put new object VisibleButton into btn

show btn    -- ボタンが表示される
mouseUp btn -- ボタンがハイライトされる
hide btn    -- ボタンが非表示になる

objectの委譲

プロトタイプに、メッセージの委譲を行う。

object Card
  on mouseUp
    put "this is Card" & return
  end mouseUp
end Card

object MouseupButton throws Card
  on mouseUp
    put "this is Button" & return
    pass mouseUp
  end mouseUp
end MouseupButton

put new object MouseupButton into btn

mouseUp btn
 -- 以下が出力される
 -- this is Button
 -- this is Card

propertyステートメントの追加

set、getを用いるためのpropertyを定義することが出来る。

set visible of VisibleButton to true  -- ボタンが表示される
set visible of VisibleButton to false -- ボタンが非表示になる

パターンマッチへの対応

メッセージ定義部に、定数を設定することが出来る。

object String
 
  private value

  on initialize arg
    set value to arg
  end initialize

  on put arg @after
    put value & arg into value
  end put

  on put arg @before
    put arg & value into value
  end put

  on put arg @after @line index @of
    put line 1 to index of value & return into t
    put t & arg & return into t
    put t & return line index+1 to last of value into t
    set value to t
  end put

  on put arg @before @line index @of
    put line 1 to index-1 of value & return into t
    put t & return & arg into t
    put t & line index to last of value into t
    set value to t
  end put

  function string
    return value
  end string

end String

 -- Stringオブジェクトの作成
put new object String "foo\nbar\baz" into str

 -- 以下の出力
 -- foo
 -- bar
 -- baz
put str

 -- 文字列の挿入
put "abc" after line 1 of str

 -- 以下を出力
 -- foo
 -- abc
 -- bar
 -- baz
put str

 -- 文字列の挿入
put "def" before line 3 of str

 -- 以下を出力
 -- foo 
 -- abc
 -- bar
 -- def
 -- baz
put str