Ad
  • Custom User Avatar

    Wow, I absolutely hated the C version of this.

    Having the add function described in the AST description let me down a sidequest of trying to understand the strange structure of having add nodes AND str nodes. Took a while to realize add is just a helper function to append to a str linked list node.

    Not to mention I thought I was supposed to implement the AST myself (which you sorta have to for testing). Looking at languages like rust it is immediately clear that it is an enum. In C its not so obvious from the start.

    Perhaps some of these things could be added specifically to the C version's description (as I see a few other comments reflecting this opinion too, which is really what saved me).

  • Custom User Avatar

    it's not really an "issue" but a mistake people are likely to make, and that makes one scratch their head for a moment. what caused it for me was that in prototype methods, this always has type object, even for primitives (they are "boxed"), i.e. :

    String.prototype.f = function () { console.log(typeof this); };
    ''.f(); // 'object', not 'string'
    

    and assert.deepEqual(new String('abc'), 'abc'); fails (as it should, imo). but once stringified by chai, they look identical

  • Custom User Avatar

    What exactly causes the issue? Is it a type of the returned value being an iterator vs array? Maybe an explicit assertion on the expected type would help?

  • Custom User Avatar

    it'll be tough to fix since the stringification happens as one would expect, and I think deepEqual() failing is the right behavior. It was interesting to figure out what was happening too. I dont know what should be done here - a warning in the description ? a dedicated it() block with an helpful title ?

  • Custom User Avatar

    To anyone experiencing this, console.log your values instead and you'll probably figure out the quirk that's causing the comparison to fail

  • Custom User Avatar

    Not true aivenaut. You can try easily for yourself:

    package main
    
    import "fmt"
    
    func x(slc []int) {
      slc[1] = 42
    }
    
    func main() {
      slc := []int{1,2,3}
      x(slc)
      fmt.Println(slc) // prints 1, 42, 3
    }
    

    You are correct that things are passed by value. But certain things are pointer types themselves without being a pointer. A slice is a structure with a size, a capacity, and an underlying array pointer. Even if you pass the slice as value, the underlying array is the same.

  • Custom User Avatar

    In golang when you pass a parameter to a function it will make a copy of it, unless pointer type is specified (eg arr *[]int). So this function is pure.

  • Custom User Avatar

    I was trying to get to this! I knew there had to be a one-liner with take_while. I didn't quite achieve it. Well done.

  • Custom User Avatar
  • Custom User Avatar

    yeah no you have to implement your own

  • Custom User Avatar

    Pretty fun kata with prior knowledge in crafting interpreters

  • Custom User Avatar

    It still happens with the Java random test.

  • Custom User Avatar

    Can someone please explain me this piece of code? what is id?

  • Custom User Avatar

    Good Kata. If you don't know what to do here, check out "Simplexer" first, since it teaches you the basics of Expression Parsing.

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Loading more items...