Skip to content

Instantly share code, notes, and snippets.

View remexre's full-sized avatar

Nathan Ringo remexre

View GitHub Profile
(defn times-two (x)
(* x 2))
(defn div-by-three (x)
(= (% x 3) 0))
;; With threading macro:
(->>
(range 100)
(filter div-by-three)
(map times-two)
;; 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 / 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 *)
@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
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)
@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
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; }
@remexre
remexre / .zshrc
Created May 17, 2017 19:34
A .zshrc for Silver development
export ZSH="${HOME}/.oh-my-zsh"
ZSH_THEME="ys"
plugins=(common-aliases compleat dircycle git git-extras pip python sudo tmux)
export EDITOR="vim"
export PATH="${HOME}/bin:${HOME}/.local/bin:${HOME}/.cabal/bin:${HOME}/.cargo/bin:${GOPATH}/bin:${PATH}"
export SILVERTRACE=1
source $ZSH/oh-my-zsh.sh