Posts tagged tutorials

Understanding and Implementing Algebraic Effects

:: racket, continuations, tutorials, programming-languages, understand-and-implement

By: Mike Delmonaco

Algebraic effects are kind of like exceptions that you can resume from. They can be used to express computational effects like non-determinism, generators, multi-threading, and of course, exceptions. They are a slightly less confusing alternative to using raw continuations via operators like call/cc and have other benefits like dynamic interpretation.

In this post, we will discover and implement algebraic effects using continuations in Racket. I will assume you are familiar with Racket and continuations. If you’re not, I have the perfect post for you!

Understanding and Implementing a Macro System

:: racket, tutorials, programming-languages, understand-and-implement, macros

By: Mike Delmonaco

Macros are a powerful tool that allow programmers to extend the syntax of a language. In a language with macros, features like for-loops, while-loops, and pattern matching can be implemented as a library by users of the langauge! In this post, we’ll discover what macros are, how and why to use them, and how to implement a tiny language with a simple macro system.

For this post, you’ll need some familiarity with Racket, but no familiarity with macros is required. If you don’t know what something is, click on the variable name in the code and you’ll be taken to its documentation.

Everything from call/cc

:: racket, continuations, tutorials, programming-languages

By: Mike Delmonaco

call/cc is a powerful tool for implementing custom control forms operators. However, call/cc can be pretty unwieldy, so people tend to use delimited, composable continuations with operators like reset and shift. But what if I told you that these operators can be implemented using just call/cc?

In this post, we’ll implement delimited continuations, composable continuations, dynamic-wind, and parameters all from just call/cc. I will assume a solid familiarity with continuations and Racket. If you aren’t very familiar, then feel free to check out my continuations post to get some background. But even having read that, you sould play around with them a lot to get familiar, because this post is pretty heavy on continuation weirdness!

Understanding and Implementing Pattern Matching

:: racket, tutorials, programming-languages, understand-and-implement

By: Mike Delmonaco

Pattern matching is a very powerful tool used to destructure and perform case analysis on data. It’s commonly found in more academic functional languages and has recently made its way into Python. In this post, we’ll discover pattern matching and implement it in Racket.

I will assume that you have some familiarity with Racket. We’re going to be writing some macros, but general familiarity with macros should be enough, we’re not doing anything fancy.

Pi Calculus: Understanding and Implementing Concurrency

:: racket, programming-languages, tutorials, understand-and-implement

By: Mike Delmonaco

You may have heard of the lamdba calculus. It is a model of computation where everything is either a function, a variable, or a function call. It is the essence of functional programming and the theoretical foundation for modern functional programming languages. Even though it is very simple, it is just as powerful as any programming language since it is Turing-complete.

The pi calculus is a similar idea, but instead of functional programming, it is the essence of concurrent programming. For our purposes, it will serve as a simple example of a programming language with concurrency. In this post, we will explore and implement the pi calculus in Racket. This will give an idea of how modern programming languages implement concurrency.

This post requires some familiarity with Racket or any Lisp-like language. If you have read some of my Racket posts which explain Racket stuff, you should be fine. If you see something you don’t understand in the code, you can click on it and the link will take you to its documentation.

Continuations

:: racket, continuations, tutorials, programming-languages, understand-and-implement

By: Mike Delmonaco

Continuations are a powerful tool that allow you to implement control flow constructs like exceptions, generators, and multi-threading, and back tracking as libraries. That’s right, libraries! In a programming language that gives access to continuations, these features don’t have to be baked into the implementation of the language. In this post, we will explore what continuations are, how to use them, and how to implement them in a programming language as a pre-processing step.

Understanding and Implementing Automatic Differentiation

:: racket, math, machine-learning, projects, tutorials, understand-and-implement

By: Mike Delmonaco

\[ \DeclareMathOperator{\expt}{expt} \DeclareMathOperator{\mul}{mul} \DeclareMathOperator{\add}{add} \DeclareMathOperator{\derivative}{derivative} \]

Automatic differentiation is a technique that allows programs to compute the derivatives of functions. It is vital for deep learning and useful for optimization in general. For me, it’s always been dark magic, but I recently thought of a nice way to implement it and made a little library. This blog post takes you along the journey of discovering that implementation. Specifically, we will be implementing forward mode automatic differentiation for scalar numbers.

This post requires some knowledge of differential calculus. You’ll need to know basic derivative rules, the chain rule, and it’d help to know partial derivatives. If you’ve taken an introductory calculus course, you should be fine.

The code is in Racket. If you don’t know Racket, you should still be able to follow along. I’ll explain the Racket-y stuff. Don’t let the parentheses scare you away!

Matching Regular Expressions by Computing Their Derivatives

:: racket, tutorials

By: Mike Delmonaco

Regular expressions allow us to describe patterns in text. They are very useful and show up all over the place in programming, but matching regular expressions can be difficult. One well-known technique for matching regular expressions is converting the regular expression to a finite state machine. This is pretty elegant, but can get complicated and messy.

An alternative technique, which is the subject of this blog post, involves something called a Brzozowski derivative. This technique can be used to compute the derivative of a generalized regular expression.