Compare commits

...

2 commits

Author SHA1 Message Date
4dbbd79b06 update left nav style so the title isn't so small on mobile
All checks were successful
ci/woodpecker/push/deploy Pipeline was successful
2024-12-02 05:28:38 -06:00
ac672a54cf aoc language post 2024-12-02 05:26:45 -06:00
2 changed files with 69 additions and 2 deletions

View file

@ -0,0 +1,60 @@
---
title: The advent of code language
date: 2024-12-02T11:08:41.157Z
tags: [pl, advent-of-code]
---
It's December, which means ~~grad school apps are due soon~~ [Advent of Code (AOC)][aoc] has started.
AOC is an [advent calendar] with increasingly difficult coding challenges from December 1 up until Christmas.
[aoc]: https://adventofcode.com/
[advent calendar]: https://en.wikipedia.org/wiki/Advent_calendar
Usually, people use this as an excuse to learn a new language.
I did this a couple years back with [aoc2022].
[aoc2022]: https://git.mzhang.io/michael/aoc2022
Since I have started to play around with programming language design and theory a bit, I decided to take a stab at writing a new language and using it to crack advent of code challenges.
So far, I have an interpreter that runs very minimal JS-looking language which is capable of solving the first day.
For example, here is the code for the second part of day 1, in my language:
```
input data = "1.txt";
let lines = data.splitlines();
let pairs = lines.map((s) => {
map(s.splitwhitespace(), (n) => { parseint(n) })
});
let lists = pairs.transpose();
let left = lists[0];
let right = lists[1];
let counts = left.map((n) => {
let one_count = right.map((m) => { if m == n then 1 else 0 });
let s = one_count.sum();
n * s
});
print(counts.sum());
```
The source code is [here][code].
Few things to note:
- I've been enamored by the idea of [UFCS] for a while, and my interpreter implements a rather naive version of it.
However, I'm curious about how this scales and how it will interact with polymorphic functions or variable namespaces.
- The parser is still currently very broken. This is why the `pairs` definition couldn't just read
```
let pairs = lines.map((s) => s.splitwhitespace().map((n) => parseint(n)));
```
- Functions like `splitlines`, `parseint`, `map`, and `transpose` are still implemented using intrinsics.
They will be moved to a "standard" library once modules have been figured out.
In a few weeks, I will try to flesh this language out into a playground for some programming language ideas I've been meaning to try to implement, such as algebraic effects.
Stay tuned for further updates!
[code]: https://git.mzhang.io/michael/aoclang2024
[ufcs]: https://en.wikipedia.org/wiki/Uniform_Function_Call_Syntax

View file

@ -72,15 +72,21 @@
}
}
// Small screen
@media screen and (max-width: variables.$breakpoint) {
.side-nav {
background: linear-gradient(to top, var(--sidebar-color) 50%, transparent);
.side-nav-content {
width: 100%;
padding: 18px 0;
padding: 18px;
box-sizing: border-box;
border-bottom: 1px solid var(--shadow-color);
.me {
flex-grow: 1;
}
.home-link {
display: flex;
justify-content: space-evenly;
@ -108,6 +114,7 @@
}
}
// Big screen
@media screen and (min-width: variables.$breakpoint) {
.side-nav {
// Capital Min to avoid invoking SCSS min
@ -139,4 +146,4 @@
}
}
}
}
}