June 26th 2026 - Things I Worked On

Added if, then, else to Hith

If statements are the cornerstone of logic so, of course, every good language needs them. Here's the implementation. They're considered a special form:

def doif(self, cond, dothen, doelse, env):
  cond_value = self.evaluate_node(cond, env)

  if cond_value is not False and cond_value != "False":
      return self.evaluate_node(dothen, env)
  else:
      return self.evaluate_node(doelse, env)

Added catching errors in Hith REPL

Before this any error would crash the REPL. Now it prints the error and continues looping. Better error messaging/handling needs to be implemented in the future.

def start_repl():
    print("Welcome to Hith. A lisp written in Python.")
    print("Type exit to quit.")

    while True:
        try:
            exp = input(">>> ")

            if exp == "exit":
                exit()
            else:
                # suppress prints from evaluation
                with contextlib.redirect_stdout(open(os.devnull, 'w')):
                    result = evaluate(exp)

                # print results here
                print(result)
        except Exception as e:
            print(e)

Added handling new line and tab characters in Hith

Python has a nice method for checking if a string contains only whitespace characters (including new line and tabs).

if not c.isspace():
    tokens.append(c)