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.