Boolean Logic
Your language has no not, and, or or operators. But it doesn’t need them.
Start with not. It takes a boolean and returns the opposite. You don’t have a negation operator, but you do have if — and if already inspects a boolean and picks between two outcomes. What should those two outcomes be?
Once you have not, think about and. It takes two booleans (curried) and returns true only when both are true. Think about short-circuit evaluation: if the first argument is false, the result of AND is always the same, regardless of the second argument. What is it? And if the first argument is true, what determines the result?
or is the mirror of and. If the first argument is true, you know the result immediately. If it’s false, the result depends entirely on the second argument.
All three functions follow the same pattern: use if to inspect one boolean, and either return a known value or return the other boolean. The boolean operators aren’t special — they’re just branching.
What You Can’t Do Yet
Try to imagine writing these programs in your language:
-
A function that returns the list of numbers from 1 to n. You can’t — there are no lists. The only values are numbers, booleans, and functions.
-
A function that takes two points and computes the distance between them. You can’t — a point needs two coordinates bundled together, and there’s no way to bundle values. (Or is there? Could you represent a pair as a function that takes a selector? Think about it.)
-
A function that joins two strings. You can’t — there are no strings in the language. Names like
"x"exist in the syntax but they’re variable references, not string values.
Your language is small. It can express any computation on numbers — it’s Turing-complete with just recursion and conditionals — but it can’t express data structures. Every interesting program eventually needs to group values together, and right now the language has no way to do that.
But before adding new features, look back at the programs you wrote. The nested brackets, the string tags, the arrays within arrays. The language works, but writing it is tedious. That’s a problem worth solving too.