Thread Rating:
  • 478 Vote(s) - 2.82 Average
  • 1
  • 2
  • 3
  • 4
  • 5
#t , any , Type の違いは?
09-10-2013, 06:02 PM, (This post was last modified: 09-10-2013, 06:06 PM by umemura.)
#t , any , Type の違いは?
open-controls のソースを見ていたところ、「#t」という型の定義を見かけました。


また、配列の {Array-of t:Type} のように、型定義に 「Type」や、「ClassType」を指定しているものもありますが、


{define-class public {DisplayFrame-of t:Type}  {inherits BaseFrame}

  field private _contents:#t = null
  field private _display?:bool = true

  {constructor public {default
                          contents:#t = null,
    {construct-super ...}
    set self.display? = display?
    set self.contents = contents


  {getter public {contents}:#t {return self._contents}}
  {setter public {contents value:#t}:void
    {if value != self._contents then
        set self._contents = value
        {if-non-null value then
            {if self.display? then
                {self.add-internal value}

  {getter public {display?}:bool {return self._display?}}
  {setter public {display? value:bool}:void
    {if value != self._display? then
        set self._display? = value
        {if not value then
            {if-non-null con = self._contents then
                {self.add-internal con}

{def df:{DisplayFrame-of Scrollbar} = {{DisplayFrame-of Scrollbar} contents = {Scrollbar}}}

{value df}

{value {type-of df.contents}}
09-13-2013, 02:52 PM,
RE: #t , any , Type の違いは?
> ご存知の型 --> ご存知の方? Smile

”#t”の中の t 自体は変数名でしょう? よく見られるのが、パラメータ化クラス定義ですね。
{define-class public {Array-of t:Type}
|| body of class


{Array-of String}で指定する場合、データ型は{Array-of String}になり、
{Array-of int}で指定するなら、データ型は{Array-of int}になります。

09-14-2013, 11:31 AM,
RE: #t , any , Type の違いは?
#t means that the template will substitute in the nullable version of type 't' which you specified when you instantiate the template. (E.g. this is means that if you ask for {DisplayFrame-of String} that field will be #String. For non-class types there is no # variant (#int == int).)

This is different from using 'any' in that the field or argument will be of the specified type, attempting to pass other types will cause a compilation error, and the storage will be the size of that type, and math operators will be natively compiled in the right type. (Note that you could do {DisplayFrame-of any} and lose all of those benefits, but it might be suitable in some cases.)

Type means any type can be used, ClassType means that it must be a subclass of Object (anything defined with define-class.) (Type also includes value types and basic types like int.)

09-17-2013, 08:05 PM, (This post was last modified: 10-22-2013, 09:10 AM by umemura.)
RE: #t , any , Type の違いは?

Template の「t」なのですね。

any 型ではなく、インスタンス時に型が決まるので、

Type と ClassType も、意味は若干異なり、前者はすべての型、後者はクラスの型をあらわす、という理解です。


{define-class public {CustomClass-of t:Type}
  field data:t
  {constructor public {default data:t}
    set = data

{define-class public {CustomClassNull-of t:Type}
  field data:#t
  {constructor public {default data:#t}
    set = data

{define-class public CustomClass
  field data:any
  {constructor public {default data:any}
    set = data

{def a = {{CustomClass-of String} "String"}} ||<- null を指定できない
{value {type-of}}

{def c = {{CustomClassNull-of String} null}} ||null指定可能
{value {type-of}}

{def b = {CustomClass "String"}}
{value {type-of}}

    let str:String = ""
    set str =  || キャスト必要なし
    set str = {non-null} || nullable の判断
    set str = asa String || 明示的なキャストが必要


Possibly Related Threads...
Thread Author Replies Views Last Post
  type-switch で Array-of 、HashTable-of を判別したい umemura 2 3,824 12-28-2012, 01:39 PM
Last Post: wbardwell
Forum Jump:

Users browsing this thread:
1 Guest(s)

MyBB SQL Error

MyBB has experienced an internal SQL error and cannot continue.

SQL Error:
1017 - Can't find file: 'mybb_threadviews' (errno: 2)
INSERT INTO mybb_threadviews (tid) VALUES('966')