Hornbills are one of the most magnificent birds present in the wild. Their distinctive appearance can be attributed to their black bodies with a white chest and the large, curved yellow beak with a…
A simple library for ~~swerving~~ past a restriction of an otherwise powerful language.
by Kenny Peluso
I made a small library that ~~swerves~~ past this restriction. We’ll discuss that in a moment. I’ll briefly review Vyper before analyzing the library.
The Becoming Future team loves Vyper for all the simplicity and security it provides. We hope to contribute more to the (admittedly, currently tiny) Vyper community in the future.
Here’s why this simple code is useful: Vyper only allows you to perform range()
on a constant
-sized input, which is problematic when one has a dynamic amount of content to loop over. Operations such as remove()
would be impossible without a tiny fix. Simply define a different, mutable variable (in this case, self.currMax
) and loop along range(MAX)
until self.currMax
is reached.
That’s it!
I chose MAX
to be the largest value a uint256
could be in Vyper, namely 2²⁵⁶ just because I can. Clearly this destroys my space complexity, but at least all use cases are permitted. Feel free to alter this value to fit your own needs.
Thanks for reading! Feedback is always welcomed!
Changemakers are connected, involved, and dedicated to the common good.
The Global Risks Report 2019, published by the World Economic Forum, defined a “global risk” as “an uncertain event or condition that, if it occurs, can cause a significant negative impact for…
Today I was organizing my collection of book reading notes, and wondered: how many books have I read in my lifetime? I made a wild (and probably generous) guess: a few thousand. I recently saw a clip…