/now
projects
ramblings
smol projects

my first library... and it's incredibly useless

24.10.2023 2 min read

My friend sent me an Instagram video this morning. He knows I’m off Instagram, but I suppose he thought I’d enjoy it. Regrettably, I did - perhaps a little more than I should have. Here’s the video. If you don’t care enough to watch it, it’s basically some folks meme-ing on Gen-Z slang.

I’ve been learning a bit of Nim, and I got to thinking: “I can probably do this, right?” And so I wrote my first “library”, which is basically a re-implementation of this (with quite a few features missing - I don’t know the language well enough yet. And some things don’t have a direct equivalent).

Here’s how it looks:

let mySeq = @[1,2,3,4]

proc findIdx(nums: seq[int], item: int): int =
    for i in 0 ..< nums.len:
        if nums[i] == item:
            drop i
    itsGiving -1

fr findIdx(mySeq, 5) == -1

if 2 == 2:
    try:
        yeet(newException(L, "some L"))
    except L as e:
        stan e.msg # "some L"

type Todo = object
    completed: bool = onGod

var todo = Todo()

if todo.completed == cap:
    todo.completed = noCap

frfr "wow" == "WOW".based()

for i in 0 .. 100:
    if i mod 2 == 0:
        skrt

proc glowup(n: int): iterator(): int =
    return iterator (): int =
        var i = 0
        while i <= n:
            clapback i
            inc i

let glowup100 = glowup(100)

for i in glowup100():
    stan i

frfr "wow".highkey() == "WOW"
frfr "WOW".lowkey() == "wow"

proc someFn() {.async.} =
  holup sleepAsync(500)

letItCook someFn()

# example from nim docs

proc asyncProc(): Future[string] {.async.} =
  var client = newAsyncHttpClient()
  try:
    return holup client.getContent("http://google.com")
  finally:
    client.close()

stan letItCook asyncProc()

It’s basically a bunch of constants and some templates. But yeah - my first library. It’s not useful, in any sense of the word - but it was fun.

Built with Astro and Tailwind 🚀