This week's code snippet, Baklava in Mirth, is brought to you by Subete and the Sample Programs repo.
module sample-programs.baklava
import std.prelude
import std.world
import std.list
import std.str
||| stack: n
def abs [Int -- Nat] {
||| if n < 0 then -n else n
dup 0 < if(-1 *, dup drop) Int.>Nat-clamp
}
||| stack: n (count), s (string)
def repeat-string [Nat Str -- Str] {
"" ||| stack: n, s, result = ""
rotl ||| stack: s, result, n
repeat( ||| stack: s, result
||| repeat n times:
over ||| stack: s, result, s
cat ||| stack: s, result = result + s
)
dip(drop) ||| stack: result
}
||| stack: n
def baklava-line [Int -- Str] {
abs ||| stack: num-spaces = abs(n)
dup ||| stack: num-spaces, num-spaces
" " repeat-string ||| stack: num-spaces, spaces = num-spaces " "
swap ||| stack: spaces, num-spaces
Nat.>Int -2 * 21 + Int.>Nat-clamp ||| stack: spaces, num-stars = 21 - 2 * num-spaces
"*" repeat-string ||| stack: spaces, stars = num-stars "*"
cat ||| stack: spaces + stars
}
def main {
||| for n = -10 to 10:
||| print baklava-line(n)
-10 10 range for(baklava-line print)
}
Below you'll find an up-to-date list of articles by me on The Renegade Coder. For ease of browsing, emojis let you know the article category (i.e., blog: βοΈ, code: π», meta: π, teach: π)
- π» Why Does == Sometimes Work on Integer Objects in Java?
- π Online Exams Might Be Cooked
- π Encouraging Attendance With Peer Instruction
- βοΈ Conspiracy Theory: All Pro Sports Are Rigged Now
- π Reflecting on My Teaching Journey Heading into 2026
- π I Hate That Student Feedback Is Now Reviewed by Machine Learning
- βοΈ Not All Code Completion Is Generative AI
- βοΈ AI Haters Stay Winning: What Itβs Like to Be Constantly Vindicated
- βοΈ Computer Science Career Advice in 2026? Your Guess Is as Good as Mine
- π Why I Donβt Record My Lectures
Also, here are some fun links you can use to support my work.
This document was automatically rendered on 2026-01-30 using SnakeMD.





