A Strong Working Knowledge of K


Dennis Shasha
Courant Institute of Mathematical Sciences
Department of Computer Science
New York University
shasha@cs.nyu.edu
http://cs.nyu.edu/cs/faculty/shasha/index.html



Unit 2: Conditionals, Adverbs, and String Manipulation





Topics




Conditionals




While Loops




Do Loops




Each Operator




Exercise: VP Salary Raise




VP Salary Raise, Solution 1




VP Salary Raise, Index Approach



VP Salary Raise, Vector Approach




An Idiom




Example: Good stock




Recursion and Cousins



More in the spirit




Currying

  • Suppose the coefficient of the high order term (a) is always 1 in a setting we call "normalized". Then we can define
    normquad: quad[1]
    quad[1;4;2] = normquad[4;2]
    



    Lambda Expressions




    Executing Strings




    Exercises




    Delete All Blanks


    deleteallblanks:{[s]
      x: s = " " / gives binary 1 or zero saying whether s is blank or not.
      i: & ~ x / gives all indices that are not blank
      s[i]}
    


    Delete Leading Blanks

    deleteleadingblanks:{[s]
      x: s = " " / 1s whenever blank, 0s elsewhere
      (x ? 0) _ s} / drop up to first non-1.
    



    Delete Trailing Blanks




    Find Most Consecutive Ones



    The Road to Ruin