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.
/***************************************************************************** | |
* Copyright (c) 2011 Kenneth Waters | |
* | |
* | |
* Permission is hereby granted, free of charge, to any person obtaining a | |
* copy of this software and associated documentation files (the "Software"), | |
* to deal in the Software without restriction, including without limitation | |
* the rights to use, copy, modify, merge, publish, distribute, sublicense, | |
* and/or sell copies of the Software, and to permit persons to whom the | |
* Software is furnished to do so, subject to the following conditions: |
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) |
/// Playground - noun: a place where people can play | |
/// Church-Turing clan ain’t nothing to func with. | |
/// Church encoding is a means of representing data and operators in the lambda | |
/// calculus. In Swift, this means restricting functions to their fully curried | |
/// forms; returning blocks wherever possible. Church Encoding of the natural | |
/// numbers is the most well-known form of encoding, but the lambda calculus is | |
/// expressive enough to represent booleans, conditionals, pairs, and lists as | |
/// well. This file is an exploration of all 4 representations mentioned. |
// | |
// APAspectFitImageView.h | |
// autolayout | |
// | |
// Created by Antol Peshkov on 16.10.14. | |
// Copyright (c) 2014 Antol Peshkov. All rights reserved. | |
// | |
#import <UIKit/UIKit.h> |
import UIKit | |
struct Monoid<A> { | |
let zero: A | |
let append: (A, A) -> A | |
} | |
let additive = Monoid(zero: 0, append: +) | |
let multiplicative = Monoid(zero: 1, append: *) |
/// An operator is given by a list of arities, where each element indicates the number of | |
/// variables bound by the operator at that position and the length of the list determines the | |
/// number of variables the operator accepts. The full generalization of arity is called | |
/// the operator's "valence". | |
/// | |
/// For example, if I have a little calculator language with let-bindings, its operators | |
/// would look like this: | |
/// | |
/// | |
/// enum CalcOps : Operator { |
@import Foundation; | |
@import CoreGraphics; | |
typedef struct __attribute__((objc_boxable)) CGPoint CGPoint; | |
typedef struct __attribute__((objc_boxable)) CGSize CGSize; | |
typedef struct __attribute__((objc_boxable)) CGRect CGRect; | |
typedef struct __attribute__((objc_boxable)) CGVector CGVector; | |
int main(int argc, const char * argv[]) { | |
@autoreleasepool { |
extension String { | |
var composedCount : Int { | |
var count = 0 | |
enumerateSubstringsInRange(startIndex..<endIndex, options: .ByComposedCharacterSequences) {_ in count++} | |
return count | |
} | |
} |
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.
import Cocoa | |
protocol Thing { | |
var x: String {get} | |
init(s: String) | |
} | |
class Foo: Thing { | |
let x: String |