Skip to content

Instantly share code, notes, and snippets.

View remexre's full-sized avatar

Nathan Ringo remexre

View GitHub Profile
;; POSIX-based API. Really long and yuck.
(defn capitalize-file (path)
; Read the input.
(def in-fd (open path))
(def in-str (read in-fd))
(close in-fd)
; Process the input.
(def out-str (toupper in-str))
; Write the output.
(def out-fd (open path 'w))
;; C-like
(defn int foo (int x str y)
...)
;; Rust-like
(defn foo:int (x:int y:str)
...)
;; CLOS-like
(defn (foo int) ((x int) (y str))
;; With infix arithmetic macro:
(defn f-real (cr ci zr zi)
~{ zr * zr - ir * ir + cr})
(defn f-imag (cr ci zr zi)
~{ 2 * zr * zi + ci })
(defn complex-abs (a b)
(sqrt ~{a * a + b * b}))
(defn m-loop (cr ci zr zi i)
(if ~{i = 0}
~{(complex-abs zr zi) < 2}
@remexre
remexre / monads.md
Created October 26, 2016 23:57
Hello!

Monad Tutorial?

Making a Monad

We're going to make a monad called Result. First, define it as a type. This definition makes it essentially an enum which is generic over two types. It can either be Success containing a value of the first type, or Error containing a value of the second type.

data Result a e
@remexre
remexre / passmenu
Last active February 4, 2017 04:11
#!/usr/bin/env bash
shopt -s nullglob globstar
typeit=0
if [[ $1 == "--type" ]]; then
typeit=1
shift
fi
@remexre
remexre / hwk_01_tests.ml
Last active January 25, 2017 21:40
CSCI2014 Spring 2017 Homework 1 Unit Tests
(*****************************************************************************)
(******************************** UNIT TESTS *******************************)
(*****************************************************************************)
#use "hwk_01.ml"
(* even or odd *)
let () =
assert (even 4);
assert (not (even 5))
(* Odd is not required *)
use ::expr::Expr;
use nom::{hex_digit, oct_digit};
use num::{BigInt, ToPrimitive};
use std::mem;
named!(pub parse_number(&str) -> Expr, complete!(alt!(
based_number
)));
named!(foo(&str) -> &str, alt!(
@remexre
remexre / y.md
Last active March 6, 2017 20:34

The Y Combinator

In most functional languages, you can write something like:

let rec fac = function
  | 0 -> 1
  | n -> n * fac (n - 1)
use std::collections::btree_map::{BTreeMap, Entry};
fn main() {
let mut m: BTreeMap<&'static str, i32> = BTreeMap::new();
m.insert("foo", 4);
println!("=== Starting Foo ===");
match m.entry("foo") {
Entry::Vacant(entry) => {
println!("{:?}", entry)
<html version="-//W3C//DTD XHTML 2.0//EN" xml:lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<META http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Copper HTML dump</title>
<style type="text/css">
/* div.page { width: 800px; } */
table.symtable,
table.dfatable { border: 1px solid #000000; border-collapse: collapse; }
span.lookaheadset { background-color: #d0d0d0; padding-left: 4pt; padding-right: 4pt; }
table.symtable tr.trodd { background-color: #d0d0d0; }