Studio/Indexing

From J Wiki
Jump to navigation Jump to search

Indexing is effected using the verb { (from), and indexed replacement using the adverb } (amend). From and amend are symmetric. These are described in entries in the Dictionary.

From and amend provide all the functionality of bracket indexing found in other languages, and much more.

Examples of from

   ]m=. 4 5$'cabletreatbraidrider'
cable
treat
braid
rider

pick row 2:

   2{m
braid

pick columns 1 2:

   1 2{"1 m
ab
re
ra
id

pick the element in row 2, column 1:

   (<2 1){m
r

scattered indexing:

   (0 3;2 2;2 3;3 0){m
lair

Examples of amend

replace row 2:

   'godel' 2 } m
cable
treat
godel
rider

replace columns 1 and 2:

    ('xyzt',.'XYZT') 1 2}"1 m
cxXle
tyYat
bzZid
rtTer

replace element in row 2, column 1:

   'Z' (<2 1)}m
cable
treat
bZaid
rider

scattered replacement:

   'ABCD' (0 3;2 2;2 3;3 0)}m
cabAe
treat
brBCd
Dider