Skip to content

Instantly share code, notes, and snippets.

View pbackus's full-sized avatar

Paul Backus pbackus

View GitHub Profile

Keybase proof

I hereby claim:

  • I am pbackus on github.
  • I am snarwin (https://keybase.io/snarwin) on keybase.
  • I have a public key ASAnmhPVG2DLs6taF1tK8c4kF24Qfc2wqVN7s-AAa0RJNwo

To claim this, I am signing this object:

@pbackus
pbackus / sexpr.d
Last active February 27, 2019 21:29
#!/usr/bin/env dub
/+ dub.sdl:
authors "Paul Backus"
license "MIT"
dependency "sumtype" version="~>0.8.0"
+/
import sumtype;
alias Cell = SumType!(string, This[]);
@pbackus
pbackus / example.d
Last active June 17, 2020 16:18
"Argument-Dependent Lookup" for D
module example;
import extension;
import lib;
// Can extend types from other modules
bool empty(A a) { return false; }
char front(A a) { return 'a'; }
void popFront(A a) {}
@pbackus
pbackus / brainfuck.d
Created July 12, 2020 21:00
Arbitrary Source Languages in D
module brainfuck;
/// Brainfuck memory
struct Memory
{
private ubyte[] data;
private void extendTo(size_t i)
{
if (i >= data.length) data.length = i + 1;
@pbackus
pbackus / DIP1035.md
Last active September 4, 2020 04:02
Proposed Revisions for DIP 1035

@system Variables

Field Value
DIP: 1035
Review Count: 1
Author: Dennis Korpel [email protected]
Implementation:
Status: Post-Community 1
@pbackus
pbackus / dlang.mk
Created April 23, 2021 19:47
Basic D suport for GNU Make
DC = gdc
COMPILE.d = $(DC) $(DFLAGS) $(TARGET_ARCH) -c
LINK.d = $(DC) $(DFLAGS) $(TARGET_ARCH)
.d:
$(LINK.d) $^ $(LOADLIBES) $(LDLIBS) -o $@
.d.o:
$(COMPILE.d) $(OUTPUT_OPTION) $<
@pbackus
pbackus / tail_unqual.d
Last active April 8, 2022 15:11
TailUnqual - a template that breaks qualifier transitivity
module tail_unqual;
import std.traits: isPointer;
import std.stdint: uintptr_t;
private union HiddenPointer
{
// Stores a pointer, cast to an integer.
uintptr_t address;
struct Ref(T)
{
T* ptr;
ref inout(T) deref() inout
{
return *ptr;
}
alias deref this;
}
/// map over a variadic argument list
template mapArgs(alias fun)
{
auto mapArgs(Args...)(auto ref Args args)
{
import std.typecons: tuple;
import core.lifetime: forward;
import std.meta: Map = staticMap;
auto ref mapArg(alias arg)()
@pbackus
pbackus / gensym.d
Last active November 14, 2023 14:12
Gensym for D
// Mixin to generate a new identifier that won't repeat within a scope
enum gensym(string prefix = "_gensym") =
`"` ~ prefix ~ `" ~ __traits(identifier, {})["__lambda".length .. $]`;
// Works multiple times on the same line
unittest
{
enum sym1 = mixin(gensym!()); enum sym2 = mixin(gensym!());
static assert(sym1 != sym2);