Skip to content

Instantly share code, notes, and snippets.

View siraben's full-sized avatar

Ben Siraphob siraben

View GitHub Profile
@siraben
siraben / emacs.el
Last active January 11, 2018 01:05
Emacs Config
(require 'package)
(let* ((no-ssl (and (memq system-type '(windows-nt ms-dos))
(not (gnutls-available-p))))
(proto (if no-ssl "http" "https")))
;; Comment/uncomment these two lines to enable/disable MELPA and MELPA Stable as desired
(add-to-list 'package-archives (cons "melpa" (concat proto "://melpa.org/packages/")) t)
;;(add-to-list 'package-archives (cons "melpa-stable" (concat proto "://stable.melpa.org/packages/")) t)
(when (< emacs-major-version 24)
;; For important compatibility libraries like cl-lib
(add-to-list 'package-archives '("gnu" . (concat proto "://elpa.gnu.org/packages/")))))
@siraben
siraben / default.nix
Last active December 30, 2018 07:11
Building scas with Nix
with import <nixpkgs> {};
lib.fix (self: {
z80e = stdenv.mkDerivation {
name = "z80e";
src = fetchurl {
url = "https://github.com/KnightOS/z80e/archive/0.4.0.tar.gz";
sha256 = "b8940393bfff843ef26b2f43770a9d7e8cb0601f67804571b238bbca52919e7d";
};
@siraben
siraben / backtrack.fs
Created January 7, 2019 10:48
Backtracking in Forth through exceptions
VARIABLE HANDLER
0 HANDLER !
: CATCH ( xt -- exception# | 0 \ return addr on stack )
SP@ >R ( xt ) \ save data stack pointer
HANDLER @ >R ( xt ) \ and previous handler
RP@ HANDLER ! ( xt ) \ set current handler
EXECUTE ( ) \ execute returns if no THROW
R> HANDLER ! ( ) \ restore previous handler
@siraben
siraben / small-backtrack.fs
Last active January 7, 2019 13:53
Small backtracking
: ENTER >R ;
: SUCC ' R@ , ' ENTER , ; IMMEDIATE
: FAIL ' R> , ' DROP , ' EXIT , ; IMMEDIATE
: RANGE
1+ >R 1-
CREATE
' LIT ,
,
POSTPONE BEGIN
@siraben
siraben / default.nix
Created January 9, 2019 11:47
Building tilp under Nix
with import <nixpkgs> {};
lib.fix (self: {
tilp = stdenv.mkDerivation {
name = "tilp";
src = fetchurl {
url = "https://www.ticalc.org/pub/unix/tilp.tar.gz";
sha256 = "1mww2pjzvlbnjp2z57qf465nilfjmqi451marhc9ikmvzpvk9a3b";
};
nativeBuildInputs = [ autoreconfHook automake ];
@siraben
siraben / logical foundations.v
Created January 17, 2019 23:42
First steps in coq.
Inductive day : Type :=
| monday
| tuesday
| wednesday
| thursday
| friday
| saturday
| sunday.
Definition next_weekday (d:day) : day :=
@siraben
siraben / nat-bin.v
Created January 19, 2019 02:05
correct binary to natural number conversion
Require Import Omega.
Require Import Extraction.
(* Inductive binary number data type. *)
Inductive bin : Type :=
| Z
| A (n : bin)
| B (n : bin).
@siraben
siraben / csj.scm
Created January 31, 2019 11:42
Parsing CSJ
;; Monadic parsing in Scheme
(use-modules (ice-9 match)
(ice-9 binary-ports)
(rnrs bytevectors)
(ice-9 textual-ports)
(srfi srfi-9))
;; Helper procedures `compile-port' and `emit' for output.
(define compile-port
@siraben
siraben / nat.elm
Created February 2, 2019 06:23
Natural numbers defined inductively in Elm
module Nat exposing (..)
-- Example of inductively defined data type.
type Nat = O | S Nat
toNat : Int -> Nat
toNat n = case n of
0 -> O
sn -> S (toNat (sn - 1))
@siraben
siraben / actor.scm
Created February 3, 2019 02:42
Actor model in Scheme
(use-modules (ice-9 match))
;; An actor is a computational entity that, in response to a message
;; it receives, can concurrently:
;; send a finite number of messages to other actors;
;; create a finite number of new actors;
;; designate the behavior to be used for the next message it receives.
;; So it's a dispatch of sorts.