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
enum CollectionMultiplicity<C: Collection> { | |
case none | |
case one(first: C.Index) | |
case many(first: C.Index, second: C.Index) | |
} | |
extension Collection { | |
func indexedMultiplicity(where predicate: (Element) -> Bool) -> CollectionMultiplicity<Self> { | |
guard let i = firstIndex(where: predicate) else { | |
return .none |
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
struct InterspersedSequence<S: Sequence>: Sequence, IteratorProtocol { | |
var separator: S.Element | |
var iterator: S.Iterator | |
enum State { | |
case separator | |
case element(nextElement: S.Element?) | |
} | |
var state: State |
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
// Most implementations first check if the file exists, and then do the remove. | |
// This is subject to race conditions and requires accessing the file system twice. | |
// A better solution is to ignore that particular exception. | |
extension FileManager { | |
func removeItemIfExists(at url: URL) throws { | |
func isDoesNotExist(error: NSError) -> Bool { | |
return error.domain == NSPOSIXErrorDomain && error.code == ENOENT | |
} | |
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
float g_epsilon = 0.002; | |
float g_max = 50.0; | |
float sdSphere( vec3 toCenter, float s ) | |
{ | |
return length(toCenter)-s; | |
} | |
float sdBox( vec3 p, vec3 b ) | |
{ |
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
\ -*- text -*- | |
\ A sometimes minimal FORTH compiler and tutorial for Linux / i386 systems. -*- asm -*- | |
\ By Richard W.M. Jones <rich@annexia.org> http://annexia.org/forth | |
\ This is PUBLIC DOMAIN (see public domain release statement below). | |
\ $Id: jonesforth.f,v 1.17 2007/10/12 20:07:44 rich Exp $ | |
\ | |
\ The first part of this tutorial is in jonesforth.S. Get if from http://annexia.org/forth | |
\ | |
\ PUBLIC DOMAIN ---------------------------------------------------------------------- | |
\ |
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
#include <iostream> | |
#include <iterator> | |
// With C++20 concepts | |
#include <concepts> | |
template<typename F, typename T> | |
concept unary_operation = std::invocable<F, T> | |
&& std::same_as<T, std::invoke_result_t<F, T>>; |
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
; From Page 149 of "LISP" 1st edition. | |
; This code has been translated to Common Lisp | |
; from the dialect used in the book: | |
; table -> *table* | |
; (store (table n) x) -> (setf (aref table n) x) | |
; (boole 1 ...) -> (boole boole-and ...) | |
; greaterp -> > | |
; lessp -> < | |
; (quotient x y) -> (floor x y) |
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
(defun add-to-counter (counter carry zero op &key (test #'eq)) | |
(dotimes (i (length counter)) | |
(if (funcall test (aref counter i) zero) | |
(progn (setf (aref counter i) carry) | |
(setf carry zero)) | |
(progn | |
(setf carry (funcall op (aref counter i) carry)) | |
(setf (aref counter i) zero)) | |
)) | |
carry) |
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 Darwin | |
enum CatError: Error { | |
case open(path: String) | |
} | |
func parsePosixCommands(_ args: [String]) -> ([String], [String]) { | |
let endOfOptions = args.firstIndex { $0 == "--" } ?? args.count | |
let certainArguments = args.suffix(from: endOfOptions) | |
var toConsider = args.prefix(upTo: endOfOptions) |