/
head.ijt
228 lines (168 loc) · 6.22 KB
/
head.ijt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
NB. Lab: Video - The Head Monadic Verb - {.y
NB.
NB.labchapter:Video Requirements
0 : 0
_______________________________________
To run this video lab, you must have
access to youtube.com through the
internet.
If you do not, the lab will still
advance through the exercises, but the
videos will not be displayed.
Videos will appear as steps in the lab,
but you will need to click play on the video
to get it started.
When you have viewed a video, click back on
the terminal window to continue the lab.
This is required because when you are
interacting with a video, you are not
actually interacting with the J lab.
Now to prepare for the video
_______________________________________
)
3 : 0 ''
if. IFQT do. require jpath '~addons/media/videolabs/videolabjqt.ijs'
elseif. IFJHS do. require jpath '~addons/media/videolabs/videolabjhs.ijs'
elseif. IFJA do. echo 'Video is not available in Android'
elseif. IFIOS do. echo 'Video is not available for IOS at this time'
elseif. 1 do. require jpath '~addons/media/videolabs/videolabcon.ijs' NB. Jconsole if nothing else.
end.
)
NB.labchapter:Action of {. on Non-Empty arrays
display_video_ 'Szo4FNzsXa0'
NB.Click here and advance lab to continue
0 : 0
_______________________________________
Now, a chance to play with some of these
concepts and see if the results of these
examples meet your expectations.
_______________________________________
)
[ A23 =. i. 2 3
$ A23
NB.Can you predict the result of
NB.{. A23 and $ {. A23 ?
{. A23 NB. The first item is a row of length 3
$ {. A23
0 : 0
_______________________________________
Pretty much makes sense that the first
item of a shape of 2 3 will have a
shape of 3.
Remember that we create a one item list
using 1 {. A23 and then take the first
item from that list using 0 { 1 {. A23
Now, let's try another one.
_______________________________________
)
[ A4 =. i. 4
$ A4
NB.Can you predict the result of
NB.{. A4 and $ {. A4 ?
{. A4
$ {. A4 NB. Atoms have empty shape
0 : 0
_______________________________________
The shape of the first item is empty
because the first item of a rank one
array with shape 4 is an atom.
What if we had a list of length 1?
_______________________________________
)
[ A1 =. ,4
$ A1
NB.Can you predict the result of
NB.{. A1 and $ {. A1 ?
{. A1
$ {. A1 NB. Atoms have empty shape
0 : 0
_______________________________________
Even if it is a list of length one,
1 {. A1 will still create a list of
length one and the first item of that
list will be an atom with an empty shape.
Play around a bit more until you are
comfortable with these results or
any others that you might invent. You are
working in a fully functioning J
environment.
When you are satisfied, advance the
lab and get ready for the next video
which covers the case of empty shapes.
_______________________________________
)
display_video_ 'Wup3WjZrqkI'
0 : 0
_______________________________________
Now we have looked at a number of
different empty arrays, so we probably
don't have to go over the examples you
have just seen, but feel free to on
your own time if you wish. I'll define
a few for your benefit.
_______________________________________
)
[ A0 =. 0 $ 4
[ A02 =. 0 2 $ 4
[ A20 =. 2 0 $ 4
0 : 0
_______________________________________
What is more interesting is whether we
can tell if the fills have taken place
even if there is no visible result.
What about A010=. 0 1 0 $ 4
We know that the result was an empty line,
but is there any way to know if a fill was
ever used?
As a matter of fact there is, if we use the
fit conjunction (!.) which specifies the fill
that is used if required.
_______________________________________
)
[ A010=. 0 1 0 $ 4
datatype A010 NB. Integer as expected because the 'empty' content is 4.
{. A010 NB. Returns an empty line as expected.
$ {. A010 NB. The shape of the first item is 1 0 as expected.
datatype {. A010 NB. Integer as expected.
0 : 0
_______________________________________
But if we force a fill of a different type,
then we can see if the type changes.
We do this using the Fit Conjunction !.
{.(!.a:) is a new verb based on {.
where !. forces the fill (if required)
to be an empty box - a:
_______________________________________
)
{.(!.a:) A010 NB. Returns an empty line, as before
datatype {.(!.a:) A010 NB. But now the type has changed, so fill was used even if we could not see it!
NB.Well, that pretty much wraps up this lab,
NB.except for a list of references where you
NB.can find out more in depth information about
NB.what you have seen.
NB.labchapter:References
0 : 0
_______________________________________
Nuvoc Definition for Head found at https://code.jsoftware.com/wiki/Vocabulary/curlylfdot
J for C Programmers - Chapter 8 - Head found in Monads section at https://www.jsoftware.com/help/jforc/more_verbs.htm#_Toc191734357
The J Dictionary Vocabulary Definition for Head found at https://www.jsoftware.com/help/dictionary/d521.htm
Nuvoc Definition for From found at https://code.jsoftware.com/wiki/Vocabulary/curlylf#dyadic
J for C Programmers - Chapter 8 - More Verbs - From found in Dyads section at https://www.jsoftware.com/help/jforc/more_verbs.htm#_Toc191734356
The J Dictionary Vocabulary Definition for From found at https://www.jsoftware.com/help/dictionary/d520.htm
Nuvoc Definition for Take found at https://code.jsoftware.com/wiki/Vocabulary/curlylfdot#dyadic
J for C Programmers - Chapter 8 - More Verbs - Take found in Dyads section at https://www.jsoftware.com/help/jforc/more_verbs.htm#_Toc191734356
The J Dictionary Vocabulary Definition for Take found at https://www.jsoftware.com/help/dictionary/d521.htm
Nuvoc Definition for Fit Conjunction found at https://code.jsoftware.com/wiki/Vocabulary/bangdot
J for C Programmers - Chapter 8 - Fit Conjunction found in Dyads section at https://www.jsoftware.com/help/jforc/more_verbs.htm#_Toc191734356
The J Dictionary Vocabulary Definition for Fit Conjunction found at https://www.jsoftware.com/help/dictionary/d411.htm
_______________________________________
)
0 : 0
_______________________________________
If you would like to review any of the
previous chapters, advance the lab then
select the chapter you wish to review
from the pop up message box.
_______________________________________
)
lab ':'