current state of the language

oh-lang is currently not even close to ready as a language. that being said, i'm at a pretty exciting milestone.
  • the design is mostly fleshed out, with some old stuff at github (some very old stuff under a different name), and the newer stuff at codeberg. there are a few concerns that i have with the syntax, discussed later in this post. i also have some doubts with how i'm going to implement futures in Rust (or TypeScript for that matter), but the design is roughly in place (old and new discussion).
  • i have a bootstrap python translator that works with a subset of oh-lang and outputs Rust. it's evolving as i'm "starting over" and rewriting my translator in oh-lang (which you can see side-by-side with the rust translation).
  • i currently have one passing test! you have to run it with cargo test of course since we haven't fully bootstrapped into running oh by itself.
two design concerns can be shown in one example. they are a bit deep in the weeds, but it's a programming language that's mostly fleshed out besides the weeds (hopefully).
# concern 1:
# the `sub_tree` subtype should be a `Box<Tree>` in Rust,
# but i don't like the term `Box` since it doesn't feel like
# it has anything to do with a pointer, so maybe
# `#owned_ptr[#tree]` would be better.  or maybe we can
# do this transparently for the user, which would be nice.
#tree: #one_of[leaf: #u64, sub_tree: #tree]

# example usage, declaring a mutable `my_tree` variable:
my_tree; #tree leaf(123)

# concern 2:
# this would be the cleanest syntax for referring to
# the inner subtypes and being able to mutate them.
# but technically `leaf;` by itself is not a reference
# without parentheses, i.e., `(leaf;)`
if my_tree is leaf;
     leaf += 1
assert(my_tree) == #tree leaf(124) #this is probably expected!

# this is similar for iterating over an array
array; #array[#i32] = [1, 2, 3, 4, 5]
array each i32;
     i32 = i32 * 10 + 1
assert(array) == [11, 21, 31, 41, 51]     
for concern 1, i think i'll try to transparently add in the #owned_ptr type so that users who insert their classes inside of their classes don't have to worry about compile errors. oh-lang does like to do things transparently as long as no unexpected errors would occur in the logic.

for consistency on concern 2, i'd love to see these required as if my_tree is (leaf;) and array each (i32;), but that feels a little clunky. we can get around this and say if and each are special keyword operators that rewrite the code to something like if my_tree is( fn(leaf;): #null { leaf += 1 } ) {} else ..., which is almost certainly analogous to how we'll allow users to define the is operator on their classes.

[edit] actually i do have a third concern. i love my_function(i32:): #str for declaring functions concisely; the argument i32: expands to i32: #i32 and all is well with the world. however, for calling functions concisely, my_function(i32:) feels a bit inconsistent since we'd need to expand as my_function(i32: i32), with the left part being the argument name and the right part being what's being passed in for the argument. more generally, my_function(named_arg: i32) works for a variable i32 in the calling scope, and in this case the : goes on the left of the in-scope variable. that led me to using my_function(:i32) for function call syntax. this is only really necessary if i32 is in scope as a writable variable, and you want to specifically call a readonly overload. however, there are certain situations where :arg looks odd, but i think this is primarily due to lack of exposure to it. (i only recently started using this syntax.) there are some syntax challenges to constant templates though:
#my_class: #[front: #f32, back: #f32, flip: #bool]
{    :;current(): #(f32:;)
          if m flip
               # this is probably overly verbose but
               # it kinda looks like the start of
               # another constant-template method:
               (:;m back)
          else
               # this is probably fine.  
               m front
}
but i think we can interpret any :; encountered inside a constant template as the respective :/; but it will require a little care in the processor.

Comments