Hacker News new | ask | show | jobs
by mhh__ 1943 days ago
I do this in D all the time, and the system is actually so flexible you can even use things like simulated annealing to optimize (if you are completely mad) to optimize the parameters.

    struct DiscardPastN(uint len)
    {
        int[len] buffer;
        uint state = 0;
        void put(int x)
        {
         buffer[++state % len] = x;
            //mwuhahahaha
            static if(len == 4)
                asm {
                        ud2;
                }
        }
        int[len] get() const 
        {
         return buffer;
        }
    }
So extremely useful all over the place let alone linear algebra, I'm glad Rust now has it too
1 comments

Why undefined when Len is 4? Is it just an intentional sort of heisenbug?
Yes - it's quicker than doing something clever but is meant to show you can specialise the asm or intrinsics etc.