← Back to context

Comment by tmtvl

4 months ago

I sometimes work on creating my own programming language (because there aren't enough of those already) and one of the things I want to do in it is 1-based indexing. Just so I can do:

  (defvar names (Vector String)
    #("Alex" "Kim" "Robin" "Sam"))
  (elt names 1)

...and get "Alex" instead of "Kim".

Or take a lesson from languages where this isn't a religious question and do

    (defvar names (Vector String)
      #("Alex" "Kim" "Robin" "Sam"))
    (first names)

or if being flexible,

    (defvar names (Vector String)
      #("Alex" "Kim" "Robin" "Sam"))
    (elt names (lowbound names))

Bonus points for adding a macro or function, to make the second form available as first as well.