You can run this program on any LMC emulator, such as http://peterhigginson.co.uk/LMC/
LMC, which stands for Little Man Computer is a model of a computer, used to teach students how CPUs work. Read More.
You can run this program on any LMC emulator, such as http://peterhigginson.co.uk/LMC/
LMC, which stands for Little Man Computer is a model of a computer, used to teach students how CPUs work. Read More.
extension String { | |
var composedCount : Int { | |
var count = 0 | |
enumerateSubstringsInRange(startIndex..<endIndex, options: .ByComposedCharacterSequences) {_ in count++} | |
return count | |
} | |
} |
/// Sectional Sale | |
prefix operator >> {} | |
postfix operator >> {} | |
public prefix func >>(rhs: UInt16) -> UInt16 -> UInt16 { | |
return { lhs in lhs >> rhs } | |
} | |
public postfix func >>(lhs: UInt16) -> UInt16 -> UInt16 { |
#! /usr/bin/swift | |
import ScriptingBridge | |
@objc protocol iTunesTrack { | |
optional var name: String {get} | |
optional var album: String {get} | |
} | |
@objc protocol iTunesApplication { |
// | |
// APAspectFitImageView.h | |
// autolayout | |
// | |
// Created by Antol Peshkov on 16.10.14. | |
// Copyright (c) 2014 Antol Peshkov. All rights reserved. | |
// | |
#import <UIKit/UIKit.h> |
// | |
// CollectionViewDataSource.swift | |
// Khan Academy | |
// | |
// Created by Andy Matuschak on 10/14/14. | |
// Copyright (c) 2014 Khan Academy. All rights reserved. | |
// | |
import UIKit |
// Playground - noun: a place where people can play | |
public func id<A>(x : A) -> A { | |
return x | |
} | |
public func error<A>(x : String) -> A { | |
assert(false, x) | |
} |
public func unsafeCoerce<A, B>(_ x : A) -> B { | |
return unsafeBitCast(x, to: B.self) | |
} | |
func Y<A>(_ f : @escaping (A) -> A) -> A { | |
return { (x : @escaping (A) -> A) in | |
return f((x(unsafeCoerce(x)))) | |
}({ (x : A) -> A in | |
let fn : (A) -> A = unsafeCoerce(x) | |
return f(fn(x)) |
// Creating a generic recursive data structure with autoclosure. (READ ALL NOTES; THIS MAY NOT DO WHAT YOU WANT.) | |
// Closures are reference types, so the size is known (? I think ?) | |
// Note that this is just because of unimplemented features in the compiler in Beta5 | |
// There's no reason to think this is a long-term requirement. | |
// IMPORTANT: the closure will run every time you access this value, so if that has | |
// side effects, this won't work. It's only possible on pure value types. | |
// But the fact that this works as expected is actually kind of incredible. | |
// Think about what is required for it to work out the type for NestedList.Elem("first"). |
import XCTest | |
import Foundation | |
// Generates values from a closure that invokes a "yield" function | |
struct YieldGenerator<T>: Generator { | |
var yieldedValues = Array<T>() | |
var index = 0 | |
mutating func yield(value: T) { | |
yieldedValues.append(value) |