Idioms K3.Pdf
Total Page:16
File Type:pdf, Size:1020Kb
Learning K programming, idiom by idiom K2/K3 version Eusebio C Rufian-Zilbermann Cover image © 2019 Eusebio C Rufian-Zilbermann. All rights reserved. Commentary and main text: Eusebio C Rufian-Zilbermann List of Idioms, original K version by: Eugene McDonnell Included Reference Documentation from: Arthur Whitney Select ideas and comments by: Stevan Apter, John Earnest, Michal Wallace Contents Introduction to K ........................................................................................................................................... 1 Why K? ...................................................................................................................................................... 1 Why study idioms? .................................................................................................................................... 3 Getting K ................................................................................................................................................... 4 Running K .................................................................................................................................................. 5 Fundamental types ................................................................................................................................... 6 Idioms ............................................................................................................................................................ 8 Direct application of verbs ........................................................................................................................ 8 575. Kronecker delta of x and y ............................................................................................................ 8 571. x but not y ..................................................................................................................................... 8 570. x implies y ...................................................................................................................................... 8 573. exclusive or ................................................................................................................................... 8 41. indices of ones in Boolean vector x................................................................................................. 9 629. error to stop execution ................................................................................................................. 9 516. multiply each column of x by y ..................................................................................................... 9 566. zero all items of Boolean x .......................................................................................................... 10 624. zero numerical array ................................................................................................................... 10 622. retain value of items marked by y, zero others .......................................................................... 10 331. identity for floating point and integer maximum, negative infinity -0i ...................................... 10 337. identity for floating point and integer minimum, positive infinity ............................................. 11 357, 544. does x match y .................................................................................................................... 11 328. number of items .......................................................................................................................... 12 411. number of rows in matrix x ......................................................................................................... 12 445. number of columns in matrix x ................................................................................................... 12 388. drop y rows from top of matrix x ................................................................................................ 12 154. range (nub; remove duplicate items) ......................................................................................... 13 70. remove duplicate rows ................................................................................................................. 13 143. indices of distinct items .............................................................................................................. 13 228. is y a row of x .............................................................................................................................. 14 232. is y a row of x .............................................................................................................................. 14 559. index of first marker in Boolean x ............................................................................................... 14 78. number from alphanumeric .......................................................................................................... 14 88. name variable according to x ........................................................................................................ 15 96. conditional execution .................................................................................................................... 15 115, 116, 117. case structure .............................................................................................................. 15 493. choose x or y depending on Boolean g ....................................................................................... 16 434. replace first item of x with y ....................................................................................................... 16 433. replace last item of x with y ........................................................................................................ 16 406. add y to last item of x .................................................................................................................. 17 449. limiting x between l and h, inclusive ........................................................................................... 17 495. indices of all occurrences of y in x .............................................................................................. 17 504. replace items of y satisfying x with g .......................................................................................... 17 569. change y to one if x ..................................................................................................................... 18 556. all indices of vector x ................................................................................................................... 18 535. avoiding parentheses using reverse ........................................................................................... 18 591. reshape vector x into 2-column matrix ....................................................................................... 18 595. one-row matrix from vector ....................................................................................................... 18 616. scalar from one-item vector ....................................................................................................... 19 509. remove y from x .......................................................................................................................... 19 510. remove blanks ............................................................................................................................. 19 496. remove punctuation characters .................................................................................................. 19 177. indices of start of string x in string y ........................................................................................... 20 45. binary representation of positive integer ..................................................................................... 20 84. scalar from Boolean vector ........................................................................................................... 20 129. arctangent y%x ............................................................................................................................ 20 561. numeric code from character ..................................................................................................... 20 241. sum over subsets of x specified by y ........................................................................................... 20 245. randomize the random seed ....................................................................................................... 21 61. cyclic counter, repeating 1 through n ........................................................................................... 21 384. drop 1st, postpend 0 ................................................................................................................... 21 385. drop last, prepend 0 .................................................................................................................... 21 178. index of first occurrence of string x in string y ............................................................................ 21 447. conditional drop of y items from array x .................................................................................... 22 448. conditional drop of last item of array x ...................................................................................... 22 549. alphabetic comparison (depends on storage values)