• 2 Posts
  • 4 Comments
Joined 1 year ago
cake
Cake day: September 8th, 2023

help-circle
  • Hi! I created a stack-based language called kcats that is meant to be a simple and powerful language and good for small programs like this one. You can read more about it here: https://skyrod-vactai.github.io/kcats/book-of-kcats.html

    Here’s the solution in kcats (assumes the input is on the stack):

    [[\[ \]] [\{ \}] [\( \)]]
    "" float
    [[[last] dive wrap swap [lookup] dip =]
     [drop pop drop]
     [put]
     if] step
    dropdown
    

    A bit of explanation: First place a mapping of opening bracket to its matching closing bracket on the stack. Then place the empty result which will be modified as we go. Float the input to the top of stack. Then an if statement. The first part of the if statement is the condition: look up the matching close bracket to the last item in the result, see if it equals the current character. If the condition is true, drop the current character and the last item in the result. If not, put the item into the result. Then ‘step’ runs that if statement on each character of the input. Finally, when we’re done we don’t need the mapping of matching brackets anymore, and we drop it.


  • Here are the symbols that have meaning in say, Java:

    { } - Denote code blocks (for classes, methods, loops, etc.).
    [ ] - Array indexing and declarations.
    " - Delimits strings.
    @ - Annotation indicator (e.g., @Override).
    ^ - Bitwise XOR operator.
    & - Bitwise AND, and logical AND (&&).
    ( ) - Surround method parameters and denote precedence.
    ! - Logical NOT.
    | - Bitwise OR, and logical OR (||).
    < > - Less than, greater than, and generics.
    

    In kcats, it’s just [, ], and ". So 3 vs 14. It’s a real effect.

    I get what you are saying about python but I respectfully disagree. There’s way less a beginner needs to learn to use kcats vs python. There’s way more for YOU to learn because kcats is very unfamiliar to most programmers so they are to a large degree starting over, vs a language that’s similar to one they already know. But put yourself in the shoes of a beginner and it’s a different story.

    I am not talking about “functions you need to learn” - kcats’ tiny stdlib is not a “feature”, I’d rather it be extensive, I just don’t have the resources to make it that way, yet. I am talking about the core language.


  • Yes, exactly this - the language itself does not care about any symbols other than quotation marks. I admit I should have included the string delimiter ", I’ll update that.

    It’s true that there are some standard library function names that have symbols in them, but the names are not part of the core language, you could easily alias them to something else and it would work just fine. In fact you could alias every function name to emoji if you want, the language doesn’t care. That was my point about lack of symbols.