Comment

Comment by kelas

> i assume that in most array languages, you also create "words" or however you want to call functions, to reuse code.

sure, that's a very useful feature, like elsewhere.

> I wonder about a purely aesthetic issue: how does it look to interleave those symbols with user-defined words that by nature will be much, much longer, i.e. "create-log-entry" or "calculate-estimated-revenue".

strictly speaking, dashes and underscores in k can't even be a part of identifier - they are core language primitives. it is very uncommon to see java-like identifiers like CalculateEstimatedRevenue, why would you want that?

to your question:

here's a bit of an oddity: all user-defined functions and core language operators can be called using functional notation:

  v:1 2 3        / some vector
    v+v          / usual infix notation, two operands: left and right
  2 4 6
   +[v;v]        / same as infix, but called as it were a function.
   2 4 6

  add:{x+y}      / a user-defined function: a lambda with a name and two operands.
  add[v;v]
   2 4 6
but there is an important distinction between the two. you can't use your `add` function infix, you must call it as a function, and there are good reasons for that:

  2 add 2         / that's not gonna work
that said, mixing language primitives with function calls looks and reads just fine:

  +/add[v;v]
 12
hope this helps!
parent kelas 1 year ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton