Skip to content

Instantly share code, notes, and snippets.

@RhodiumToad
RhodiumToad / ryu.lua
Created June 22, 2023 01:29
Translation of Ryu float-to-string algorithm into Lua
--
--[[
ryu.d2string(d) -- convert float number d to shortest-exact string
As this code stands, it will produce output only in exponential
notation (e.g. "1e+00" rather than "1"). IEEE format is required.
It is an error to pass in an integer rather than a float.
@jart
jart / equiv
Created April 18, 2023 03:35
equiv -- checks if integral c expressions are equivalent
#!/usr/bin/env python3
# -*- python -*-
#
# SYNOPSIS
#
# equiv -- checks if integral c expressions are equivalent
#
# EXAMPLES
#
# $ equiv '(gn1 & 1) || (gn1 != gn2)' '(gn1 & 1) | (gn1 ^ gn2)'
@belm0
belm0 / article_sc_and_lua_2.md
Last active February 6, 2023 15:10
Structured concurrency and Lua (part 2)

Structured concurrency and Lua (part 2)

John Belmonte, 2022-Sep

In the previous installment, we introduced some basics of structured concurrency, and considered how this paradigm might fit within the Lua programming language.

An important point was encapsulation: the caller of a function shouldn't be concerned whether the implementation employs concurrency or not. We shouldn't have to give up features of the language or runtime just because our program contains concurrency.

A primary example is exception handling. In a basic Lua program without concurrency, we have the following expectations about error propagation:

@belm0
belm0 / article_sc_and_lua_1.md
Last active September 21, 2023 06:37
Structured concurrency and Lua (part 1)

Structured concurrency and Lua (part 1)

John Belmonte, 2022-Sep

I've started writing a toy structured concurrency implementation for the Lua programming language. Some motivations:

  • use it as a simple introduction to structured concurrency from the perspective of Lua (this article)
  • learn the fundamental properties of structured concurrency and how to implement them
  • share code that could become the starting point for a real Lua library and framework

So what is structured concurrency? For now, I'll just say that it's a programming paradigm that makes managing concurrency (arguably the hardest problem of computer science) an order of magnitude easier in many contexts. It achieves this in ways that seem subtle to us—clearly so, since its utility didn't reach critical mass until around 2018[^sc_birth] (just as control structures like functions, if, and while weren't introduced to languages until long after the first compu