符號 s:  _ _ _ 符號

符號為新的資料型態,由動詞 s:產生。 符號提供機制來搜尋、排序與比較效率高於其他機制如封裝字串。現存結構、選擇與關連動詞擴張功能可與符號共同使用。算術動詞不能與符號共同使用。

單邊 s: 得到符號陣列。多種型態的引數為 accep表格:
  • string with leading character as separator
  • literal 陣列where each row, excluding trailing blanks, is name of a 符號
  • 封裝字串的陣列
s:^:_1s:的反指令,為 5&s:

雙邊 s: 採用純量整數左引數,且計算各種函數:

       函數
 0 0 cardinality of set of 符號
 0 1 字串長(在字串表格使用的字數)
 0 2 符號表;行為:
 0 在字串表的索引 
 1位元長度
 2hash value
 3顏色
 4parent
 5
 6
 7order #
 8predecessor
 9successor
 10 bit flags
詳細資料隨 J 版本可能有異。
 0 3 字串表格
 0 4 hash表格. _1 indicates free entries; 非負值為對應符號表的索引。
 0 5 binary tree root
 0 6 binary tree fill factor
 0 7 binary tree gap
 0 10 get global 符號 data, equivalent to 0 s:&.>i.8. details of this data may change from one version of J to 下個.
 0 11 perform an integrity check on global 符號s data
 0 12 每個符號所需的查詢數
 1 符號陣列  一串符號名每個起始都為 '`'
_1 字串 符號條列t for a string containing 符號names each prefaced by leading character
 2 符號陣列 一串符號names each suffixed by a trailing zero character
_2 字串 符號s list for a string containing 符號names each suffixed by trailing character
 3 符號陣列 a literal 陣列of 符號names padded with zero characters
_3 literal陣列 符號陣列for literal 陣列wherein each row, excluding trailing zero characters, is name of a 符號
 4 陣列of 符號s a literal 陣列of 符號names padded with blanks
_4 literal陣列 符號s 陣列for literal 陣列wherein each row, excluding trailing blanks, is name of a 符號
 5 陣列of 符號s an 陣列of boxed strings of 符號names
_5 boxed strings 符號s 陣列for boxed 陣列wherein each box is a string of a 符號name
 6 陣列of 符號s an 整數 陣列of 符號indices (indices into 表格of 符號s)
_6 indices 符號s for indices
 7 陣列of 符號s an 整數 陣列of order numbers for 符號s
10 global 符號s data set global 符號s data (as 前個ly returned by 0 s: 10)after performing an integrity check on it. Incorrect global 符號s data may cause misinterpretation of 符號陣列, or data corruption, or a system crash, or end of civilization as we know it.

inverse of k&s: is (-k)&s:,for non-zero 整數 k between _6 and 6.
 

remainder of this text is divided into following sections: Display, Annotated Examples, Space與Time, and Persistence.

Display

display of a 符號is character ` (96{a.) prefaced to 符號name; display of a 符號陣列is similar to that display of numeric陣列, except that columns are aligned on . See Annotated Examples below.

Annotated Examples
   ] t=: s: ' zero one two three four five'
`zero `one `two `three `four `five

   $ t                              6 符號的條列
6
   3 5 $ t                          符號矩陣
`zero `one  `two  `three `four 
`five `zero `one  `two   `three
`four `five `zero `one   `two  

   1 3 5 3 1 { t
`one `three `five `three `one
   |. t
`five `four `three `two `one `zero
   _2 |. t
`four `five `zero `one `two `three
   1 0 2 0 4 0 # t
`zero `two `two `four `four `four `four

   <"0 t                            符號可以封裝
+-----+----+----+------+-----+-----+
|`zero|`one|`two|`three|`four|`five|
+-----+----+----+------+-----+-----+
   (2|i.#t) </. t
+----------------+-----------------+
|`zero `two `four|`one `three `five|
+----------------+-----------------+

   <:/~ t                           關係可用在符號
1 0 0 0 0 0
1 1 1 1 0 0
1 0 1 0 0 0
1 0 1 1 0 0
1 1 1 1 1 0
1 1 1 1 1 1

   t + t                            算術函數 不能用在符號
|domain error
|   t    +t

   /: t                             符號可以分級/排序
5 4 1 3 2 0

   5 s: t                           轉換符號成封裝字串
+----+---+---+-----+----+----+
|zero|one|two|three|four|five|
+----+---+---+-----+----+----+
   (/: t) -: /: 5 s: t
1

   /:~ t
`five `four `one `three `two `zero

   <:/~ /:~ t
1 1 1 1 1 1
0 1 1 1 1 1
0 0 1 1 1 1
0 0 0 1 1 1
0 0 0 0 1 1
0 0 0 0 0 1

   t i.  s: ' three one four one five nine'
3 1 4 1 5 6
   t e.~ s: ' three one four one five nine'
1 1 1 1 1 0

   10{. t                           填充 符號 0-長度 符號
`zero `one `two `three `four `five ` ` ` `

   _10{.t
` ` ` ` `zero `one `two `three `four `five

   0 s: 0                           cardinality (當前# of unique 符號s)
8

   a=:   ;:'A AAPL AMAT AMD AMZN ATT BA CRA CSCO DELL F GE GM HWP IBM INTC'
   a=: a,;:'JDSU LLY LU MOT MSFT NOK NT PFE PG QCOM RMBS T XRX YHOO'
   b=: ;:'NY SF LDN TOK HK FF TOR'
   c=: ;:'Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec'
   d=: <;._1 ' 00 01 02 03 04 05 06 07 08 09'
   e=: ;:'開啟high low close'

   t=: }.@;&.>{' ',&.>&.>a;b;c;d;<e
   $t
30 7 12 10 4
   */ $t
100800
   2 4 ($,) t
+----------------+----------------+---------------+-----------------+
|A NY Jan 00開啟|A NY Jan 00 high|A NY Jan 00 low|A NY Jan 00 close|
+----------------+----------------+---------------+-----------------+
|A NY Jan 01開啟|A NY Jan 01 high|A NY Jan 01 low|A NY Jan 01 close|
+----------------+----------------+---------------+-----------------+
   y=: s: t                         制訂眾多符號
   $y
30 7 12 10 4
   2 4 ($,) y
`A NY Jan 00 開啟`A NY Jan 00 high `A NY Jan 00 low `A NY Jan 00 close
`A NY Jan 01 開啟`A NY Jan 01 high `A NY Jan 01 low `A NY Jan 01 close

   0 s: 11                          系統整合檢驗
1
   0 s: 0                           cardinality
100808

   (+/ % #) 0 s: 12                 mean # of queries per 符號
1.31213

   h=: 100808 {. 2 {"1 ] 0 s: 2     hash values

   (+/ ~: h) % #h                   fraction of distinct hash values
0.999821
   (+/ ~: h |~ #0 s: 4) % #h        fraction with respect to hash表格
0.831005
Space與Time

在當前implementation, a 符號 y requires 4 bytes for an 索引, 8 or more bytes 在hash表格, 44 bytes 在表格of 符號s, and len y bytes (times 2 if Unicode) 在string表格, where len=: #&>@(5&s:) , length of 符號name. (A 符號requires a single 4-byte entry 在hash表格, but for efficient hashing system maintains at least 2*n entries for n 符號s.) Multiple occurrences of a 符號require just multiple indices; entries 在hash表格, 表格of 符號s,與string表格 are not duplicated.

Computations on 符號s generally require linear time. Specifically:
  query (new)        O((len y) * ^. 0 s: 0)
query (old) O(len y)
/:yO(*/$y)
i{yO((*/$i) * */}.$y)
x < y etc.O(x >.&(*/@$) y)
x i. yO(x + &(*/@$) y)

Persistence

interpretation of 符號s depend on global 符號s data 0 s: 10.For this interpretation to persist across J sessions global 符號s data must be restored at beginning of a session. Thus:

((3!:1) 0 s: 10) 1!:2 <'symb.dat'         to    store global 符號s data
10 s: (3!:2) 1!:1 <'symb.dat' to restore global 符號s data

See cautionary statements under 10 s: x.


下個前個字彙索引主選單