Skip to content

Instantly share code, notes, and snippets.

@peteristhegreat
Created July 16, 2019 18:41
Show Gist options
  • Save peteristhegreat/e8e7516150566109e37ef1c9e015e38a to your computer and use it in GitHub Desktop.
Save peteristhegreat/e8e7516150566109e37ef1c9e015e38a to your computer and use it in GitHub Desktop.
k language gotchas, k v3, k v2

Ternary's exist :[cond; truthy; falsey] Multiline If statements exist

if[condition
  statement1
  statement2
  statement3
  ]

Multiline if/else statements do NOT exist, and the work around is to repeat the conditional statement in the negative.

if[condition
  statement1
  statement2
  ]
if[~ condition // effectively an else statement
  statement1
  statement2
  ]

Spaces sometimes get seen as changing a verb or accessor into a diactic verb. Square brackets (myfunc[param]) resolve the ambiguity.

Print statements/debugging statements are not well documented. And most variables need to go through the "format" verb ($) to be printed.

  `0:"Hello World"
Hello World


  `0:,"Hello ","World"   / adds in a trailing new line
Hello World


  `0:("Hello"
      "World")

When returning from a function return with : nil or : retval, or at the very end of the function put retval} . Note that retval and } must be on the same line.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment