poetry new <project-name>
poetry add <library>
const std = @import("std"); | |
const allocator = std.heap.page_allocator; | |
pub fn main() !void { | |
const n = 10; | |
const ret = try (try Task.run(fib, .{n})); | |
std.debug.warn("fib({}) = {}\n", .{n, ret}); | |
} | |
fn fib(n: usize) std.mem.Allocator.Error!usize { |
const std = @import("std"); | |
// usage: | |
fn asyncMain() !void { | |
// Start two interleaving tasks | |
var task_a = async waitUntilAndPrint(start + 1000, start + 1200, "task a"); | |
var task_b = async waitUntilAndPrint(start + 500, start + 1300, "task b"); | |
var task_c = async waitUntilAndPrint(start + 800, start + 1100, "task c"); | |
await task_a; |
defmodule End do | |
defmodule Region do | |
defstruct name: "", population: 0, south_edge: 0 | |
end | |
defp tally(lines, regions) do | |
Enum.reduce(lines, regions, fn line, regions -> | |
fields = String.split(line, "\t") | |
{latitude, _} = Enum.at(fields, 4) |> Float.parse() | |
{population, _} = Enum.at(fields, 14) |> Integer.parse() |
// Example: Opcode dispatch in a bytecode VM. Assume the opcode case dispatching is mispredict heavy, | |
// and that pc, ins, next_ins, next_opcase are always in registers. | |
#define a ((ins >> 8) & 0xFF) | |
#define b ((ins >> 16) & 0xFF) | |
#define c ((ins >> 24) & 0xFF) | |
// Version 1: Synchronous instruction fetch and opcode dispatch. The big bottleneck is that given how light | |
// the essential work is for each opcode case (e.g. something like ADD is typical), you're dominated | |
// by the cost of the opcode dispatch branch mispredicts. When there's a mispredict, the pipeline restarts |
On September 28, 2021, I asked on Twitter:
PL Twitter:
you get to recommend one published PL paper for an undergrad to read with oversight by someone experienced. the paper should be interesting, approachable, and (mostly) self-contained.
what paper do you recommend?
The way different programming languages implement the mapping of runtime polymorphic values to code both at the source level and in the language implementation is a defining characteristic. There are two opposite approaches that languages facilitate to varying degrees:
You have two types: A
, containing a string, and B
, containing an int, and two operations: x
and y
.