lmt is a tool for extracting text from the code blocks in markdown files. This file demonstrates all the lmt features in a C++-centric way.
First, install the go language if you don't have it (homebrew: brew install go
).
(* Exactly what appears in the paper *) | |
datatype term = IND of int (* de Bruijn index *) | |
| ABS of term | |
| APP of term * term | |
structure Eval0 | |
= struct | |
datatype denval = THUNK of unit -> expval | |
and expval = FUNCT of denval -> expval |
lmt is a tool for extracting text from the code blocks in markdown files. This file demonstrates all the lmt features in a C++-centric way.
First, install the go language if you don't have it (homebrew: brew install go
).
/// Returns `(source, transform(source.pointee))` and destroys `source.pointee`. | |
/// | |
/// This is a low-level utility for creating mutable projections of values without | |
/// causing needless copy-on-write. | |
/// | |
/// Typical usage: | |
/// | |
/// func f(x: inout X) { // inout means we have exclusive access to `x`. | |
/// var (xAddress, xFrobnication) | |
/// = unsafeMoveMap(destroying: &x) { x.frobnication() } |
#if os(Linux) | |
import Glibc | |
#else | |
import Darwin | |
#endif | |
extension Collection { | |
/// Returns the index of the first element that matches the predicate. | |
/// | |
/// The collection must already be partitioned according to the predicate, as if |
@propertyWrapper | |
struct UnsafeReference<T> { | |
public let address: UnsafePointer<T> | |
var projectedValue: Self { self } | |
init(_ address: UnsafePointer<T>) { | |
self.address = address | |
} | |
var wrappedValue: T { | |
get { address.pointee } | |
} |
// Copyright 2020 Penguin Authors | |
// | |
// Licensed under the Apache License, Version 2.0 (the "License"); | |
// you may not use this file except in compliance with the License. | |
// You may obtain a copy of the License at | |
// | |
// http://www.apache.org/licenses/LICENSE-2.0 | |
// | |
// Unless required by applicable law or agreed to in writing, software | |
// distributed under the License is distributed on an "AS IS" BASIS, |
// Protocol to use for type erasure. | |
protocol Summable { | |
func sum() -> Int | |
} | |
// Concrete model. Type | |
extension Int: Summable { | |
func sum() -> Int { self } | |
} |
protocol P { var pop: String { get } } | |
extension P { | |
var pop: String { "slow" } | |
var pop1: String { pop } | |
} | |
protocol Q: P {} | |
extension Q { var pop: String { "fastQ" } } | |
protocol R: P {} |
/// Classes whose initializers actually create derived classes | |
protocol FactoryInitializable { | |
/// The type of the least-derived class declared to be FactoryInitializable. | |
/// | |
/// - Warning: Do not define this in your FactoryInitializable type! | |
associatedtype FactoryBase: AnyObject, FactoryInitializable = Self | |
// This associatedtype is a trick that captures `Self` at the point where | |
// `FactoryInitializable` enters a class hierarchy; in other contexts, `Self` | |
// refers to the most-derived type. | |
} |
/// A collection formed by adapting some `Base` collection, typically | |
/// displaying some altered form of the base collection's behavior. | |
/// | |
/// Default implementations of all requirements are provided, forwarding their | |
/// implementations to the `Base` collection instance. | |
public protocol CollectionAdapter: Collection { | |
/// The type of the underlying collection being adapted. | |
associatedtype Base: Collection | |
/// The instance of the underlying collection being adapted. |