This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension Int { | |
internal func divMod(other:Int) -> (quotient:Int, modulus:Int) { | |
let quotient = self / other | |
let remainder = self % other | |
if (quotient > 0) || (remainder == 0) { | |
return (quotient, remainder) | |
} else if quotient == 0 && (self > 0) && (other < 0) { | |
let div = quotient - 1 | |
let result = (div * other) - self |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension Int { | |
internal func divMod(other:Int) -> (quotient:Int, modulus:Int) { | |
let quotient = self / other | |
let remainder = self % other | |
if (quotient > 0) || (remainder == 0) { | |
return (quotient, remainder) | |
} else if quotient == 0 && (self > 0) && (other < 0) { | |
let div = quotient - 1 | |
let result = (div * other) - self |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Control.Monad | |
type Var = Integer | |
type Subst = [(Var, Term)] | |
type State = (Subst, Integer) | |
type Program = State -> KList State | |
data Term = Atom String | Pair Term Term | Var Var deriving Show | |
-- Apply a substitution to the top level of a term |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* An implementation of microKanren (and probably most of miniKanren), with | |
* a few extras. Currently, it supports: | |
* | |
* - The essential core of microKanren: Unify, Fresh, Disjunction, Conjunction | |
* - Standard terms: Variables, Atoms, TermCons, EmptyTerm. | |
* - An implicit conversion from type T to Atom[T]. This makes writing programs | |
* much easier. | |
* - A decent reifier, which converts terms to strings. | |
* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protocol PayloadBearing_1 { | |
typealias Payload_1 : Equatable | |
func payload() -> Payload_1? | |
} | |
protocol PayloadBearing_2 : PayloadBearing_1 { | |
typealias Payload_2 : Equatable | |
func payload() -> (Payload_1, Payload_2)? | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public struct MyValue : Comparable { | |
let value: Int | |
} | |
public func ==(first:MyValue, second:MyValue) -> Bool { | |
return true | |
} | |
public func <(first:MyValue, second:MyValue) -> Bool { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var theCounter:Int = 0 | |
var theString:String = "" | |
func doIt() -> String { | |
if theCounter++ % 2 == 0 { | |
return "wakka" | |
} else { | |
return " " | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// Array.swift | |
// TonalKit | |
// | |
// Created by TJ Usiyan on 11/8/14. | |
// Copyright (c) 2014 Buttons and Lights LLC. All rights reserved. | |
// https://gist.github.com/7a9444caf1b225070b88.git | |
public func reduceR<S : CollectionType, U, IndexType : BidirectionalIndexType where S.Index == IndexType>(sequence: S, initial: U, combine: (U, S.Generator.Element) -> U) -> U{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// Optional.swift | |
// TonalKit | |
// | |
// Created by TJ Usiyan on 11/4/14. | |
// Copyright (c) 2014 Buttons and Lights LLC. All rights reserved. | |
// https://gist.github.com/d9d826ed242b89ff2d85.git | |
extension Optional { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// Set.swift | |
// TonalKit | |
// | |
// Created by TJ Usiyan on 3/2/15. | |
// Copyright (c) 2015 buttons-and-lights. All rights reserved. | |
// https://gist.github.com/17d2f63780e9549a3335.git | |
import Foundation |