Skip to content

Instantly share code, notes, and snippets.

@non
non / seeds.md
Last active April 12, 2024 09:18
Simple example of using seeds with ScalaCheck for deterministic property-based testing.

introduction

ScalaCheck 1.14.0 was just released with support for deterministic testing using seeds. Some folks have asked for examples, so I wanted to produce a Gist to help people use this feature.

simple example

These examples will assume the following imports:

@non
non / answer.md
Last active January 9, 2024 22:06
answer @nuttycom

What is the appeal of dynamically-typed languages?

Kris Nuttycombe asks:

I genuinely wish I understood the appeal of unityped languages better. Can someone who really knows both well-typed and unityped explain?

I think the terms well-typed and unityped are a bit of question-begging here (you might as well say good-typed versus bad-typed), so instead I will say statically-typed and dynamically-typed.

I'm going to approach this article using Scala to stand-in for static typing and Python for dynamic typing. I feel like I am credibly proficient both languages: I don't currently write a lot of Python, but I still have affection for the language, and have probably written hundreds of thousands of lines of Python code over the years.

@non
non / transducers2.scala
Created January 25, 2015 16:52
Basic encoding of Transducers with a little fanciness
import spire.algebra._
import spire.implicits._
object Transducer {
type RF[R, A] = (R, A) => R
def apply[A, B](f: A => B) =
new Transducer[B, A] {
def apply[R](rf: RF[R, B]): RF[R, A] = (r, a) => rf(r, f(a))
}
@non
non / godel14.md
Created March 12, 2015 17:01
Gödel's fourteen point outline of his philosophical views.

Gödel left in his papers a fourteen-point outline of his philosophical beliefs, that are dated around 1960. They show his deep belief in the rational structure of the world. Here are his 14 points:

  1. The world is rational.
  2. Human reason can, in principle, be developed more highly (through certain techniques).
  3. There are systematic methods for the solution of all problems (also art, etc.).
  4. There are other worlds and rational beings of a different and higher kind.
  5. The world in which we live is not the only one in which we shall live or have lived.
  6. There is incomparably more knowable a priori than is currently known.
  7. The development of human thought since the Renaissance is thoroughly intelligible (durchaus einsichtige).
  8. Reason in mankind will be developed in every direction.
@non
non / maze.tal
Last active January 22, 2023 08:00
Prototype maze generator for the UXN virtual machine.
( maze.tal )
( )
( mazes generated by randomized depth-first search )
( press any key to generate a new maze )
( )
( generator uses a simple 16-bit xorshift RNG )
( based on http://b2d-f9r.blogspot.com/2010/08/16-bit-xorshift-rng-now-with-more.html )
%DEBUG { #ff #0e DEO }
%<<5 { #50 SFT2 }
@non
non / uxnbot.patch
Created October 21, 2022 01:34
patch that turns uxnbot.lua into uxnrepl.lua
--- uxnbot.lua 2022-10-20 21:33:58.783691604 -0400
+++ uxnrepl.lua 2022-10-20 21:33:14.229193549 -0400
@@ -1201,6 +1201,12 @@
end
end
local chat = require('chat')
+print('uxnrepl (ctrl-d to quit)')
+io.write('> ')
+io.flush()
for l in io.stdin:lines() do
@non
non / div16.tal
Last active October 20, 2022 03:50
tested implementation of signed division for 16-bit numbers in uxntal
( main method for testing )
|0100
#1234 #0001 ;testcases JSR2
#0000 #0431 ;testcases JSR2
#0039 #0003 ;testcases JSR2
#9321 #ffff ;testcases JSR2
#ffff #9321 ;testcases JSR2
#ffff #ffff ;testcases JSR2
#7654 #8000 ;testcases JSR2
#8000 #0001 ;testcases JSR2
@non
non / calc.py
Created December 2, 2012 06:28
python calculator
#!/usr/bin/python
#
# by Erik Osheim
#
# This program uses a recursive descent, LL1 parser to generate a Code object
# for the given input. Code objects are pure expressions whose behavior can
# only be controlled via a dictionary of strings-to-numbers provided to run.
#
# Syntax:
#
@non
non / half.scala
Last active June 10, 2022 03:11
Scala implementation of 16-bit floating point numbers. Also, a test prgoram.
package half
import scala.math.{pow, round, signum}
import scala.util.Random.nextInt
import java.lang.{Float => JFloat}
/**
* Float16 represents 16-bit floating-point values.
*
* This type does not actually support arithmetic directly. The
@non
non / laws.md
Last active February 20, 2022 00:26
I feel like conversations around laws and lawfulness in Scala are often not productive, due to a lack of rigor involved. I wanted to try to be as clear and specific as possible about my views of lawful (and unlawful) behavior, and what I consider a correct and rigorous way to think about laws (and their limits) in Scala.

Laws

A law is a group of two or more expressions which are required to be the same. The expressions will usually involve one or more typed holes ("inputs") which vary.

Some examples:

x.map(id) === x