Skip to content

Instantly share code, notes, and snippets.

View alilleybrinker's full-sized avatar

Andrew Lilley Brinker alilleybrinker

View GitHub Profile
#[rustfmt::skip]
fn linear_distance(
[x0, y0]: &[f64; 2],
[x1, y1]: &[f64; 2],
) -> f64
{
let y_component = (y1 - y0).powi(2);
let x_component = (x1 - x0).powi(2);
(y_component + x_component).sqrt()

Recursion Schemes

Recursion schemes are cool but taught badly.

They're functions that describe a pattern of recursion.

Common kinds include:

  • Collapsers: go from bundle of things to a single thing (folds, catamorphisms)

tcalc

A simple CLI calculator for durations.

$ tcalc 5m 32s + 4m 2s
9m 37s
$ tcalc 23h + 5h
1d 4h
$ tcalc 30s + 600s

In the process of converting to an RFC format

Summary

Final Exam Preparation

The following are questions you should be able to answer, and the study of which should be sufficient to succeed in the final exam. These questions are compiled from previous reading, quizzes, and labs. These items are in no particular order.

Study Guide

  • What are closures? How are they implemented?
  • How do functions and closures relate? Are functions closures? Are closures functions?

Lab 9: Unification & Backtracking

Welcome to the first of two labs on Prolog! Prolog is a language very different from the ones you've seen so far. Don't worry too much about being productive in it. Just try and focus on the ideas from Prolog that we're focusing on. (Of course, if you find it interesting, then by all means dive in deeper than we go in these labs!)

Prolog is a logic programming language, this is a programming paradigm that looks like and works similarly to formal logic.

Before we dive deeper, let's talk a bit about logic.

A Bit of Logic

Lab 8: Object–Oriented Design

In this lab we will be talking about some common and important concepts and patterns in object–oriented design. These are not specific to Java, but we will of course be using Java as the illustrating language.

The SOLID Principle

SOLID is an acronym for five of the most important ideas in object–oriented design:

  • Single Responsibility Principle
  • Open/Closed Principle

Lab 7: Objects & Classes

In this lab we will cover classes, objects, subclassing, composition vs. inheritance, subtype polymorphism, and abstract data types.

Compilation

This is our first lab with Java, so before anything else, let’s talk a bit about how compilation works in Java.

In Java, you write separate .java files, each of which contains a single class. The name of the file must exactly match the name of the class contained within; so a file called Blah.java must contain a class called Blah.

Lab 6: Safety & Security

In this lab we will walk through the ways in which Rust’s design facilitates safety, how Rust’s safety guarantees interact with its low-level programming capabilities, and how Rust’s definition of safety interacts with our understanding of security in low-level programming.

Safe Rust vs. Unsafe Rust

Rust is actually split into two languages: Safe Rust and Unsafe Rust. So far in this class we’ve been working with Safe Rust, but in this lab we’re going to get into Unsafe Rust.

The key difference between Safe Rust and Unsafe Rust is that in Safe Rust, the compiler checks your work. It makes sure that nothing you write violates the rules Rust has. In Unsafe Rust, the compiler doesn’t check everything, and instead just assumes you’ve checked the code yourself.

Lab 4: Ownership, Borrowing, & Lifetimes

In today's lab we will introduce the Rust programming language, and the core ideas Rust uses to ensure memory safety without manual memory management or garbage collection. These core ideas are ownership, borrowing, and lifetimes.

Today's lab will be accompanied by copious examples in person, so be sure to show up on time and follow along as we work through them.