loke,
@loke@functional.cafe avatar

I'm currently trying to decide on the syntax and semantics of field lookup in Kap.

The general syntax of looking of a value in a named field will be the use of the period, just like most object-oriented languages. Such as: foo.bar to look up field bar in the value referenced by foo.

Now, the primary datatype in Kap is of course the array, with the majority of them being 1- and 2-dimensional. Kap also provides the ability to attach labels to any axis, so I can name the the axes of a 3-by-3 array of numbers like this:

    "foo" "bar" "xyz" labels 3 3 ⍴ ⍳9<br></br>┌───┬───┬───┐<br></br>│foo│bar│xyz│<br></br>├→──┴───┴───┤<br></br>↓  0   1   2│<br></br>│  3   4   5│<br></br>│  6   7   8│<br></br>└───────────┘<br></br>

Now, if I have such an array, what better way to select a column than to use the period? So if the above array is tored in the variable "abc", then typing abc.bar would return a 1-dimensional array of the numbers 1 4 7.

Now, this may seem straightforward, but there are some details that makes this a big tricky to get right.

Currently, the labels are strings. But when I parse an expression like foo.bar, the foo and bar are symbols. And symbols in Kap has a namespace attached to them. The semantics of symbols and their namespaces in Kap are almost identical to Common Lisp.

So one may think that the best approach is to allow symbols to be labels, and then permit lookup using the period only for labels that are symbols.

The problem with that is that is that when creating such labels, you have to choose if you use symbols in your own namespace, or if you want to use keywords. If the user of the array is in a different namespace, the way to look up an axis would then be either using keyword:

foo.:bar`<br></br>

Or, if the label is in the namespace of the source:

foo.namespace:bar`<br></br>

Both of which looks ugly.

Since keywords would be by far the most common, you'd want plain foo.bar to refer to the keyword :bar, but then accessing elements in your own namespace wouldn't have a natural syntax.

And yes, I know an alternative is to use plain string matching (similar to how the Common Lisp LOOP macro matches symbol names using strings). That feels a bit ugly though.

  • All
  • Subscribed
  • Moderated
  • Favorites
  • random
  • ngwrru68w68
  • rosin
  • GTA5RPClips
  • osvaldo12
  • love
  • Youngstown
  • slotface
  • khanakhh
  • everett
  • kavyap
  • mdbf
  • DreamBathrooms
  • thenastyranch
  • magazineikmin
  • megavids
  • InstantRegret
  • normalnudes
  • tacticalgear
  • cubers
  • ethstaker
  • modclub
  • cisconetworking
  • Durango
  • anitta
  • Leos
  • tester
  • provamag3
  • JUstTest
  • All magazines