Skip to content
/ jrg94 Public

Jeremy Grifski's GitHub profile

License

Notifications You must be signed in to change notification settings

jrg94/jrg94

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

280 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Welcome to My Profile!

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: ๐ŸŽ)

Also, here are some fun links you can use to support my work.

An image of @jrg94's Holopin badges, which is a link to view their full Holopin profile


This document was automatically rendered on 2026-01-30 using SnakeMD.

About

Jeremy Grifski's GitHub profile

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •