Skip to content

Instantly share code, notes, and snippets.

chansey97 /
Created June 27, 2022 02:13 — forked from swatson555/
nanopass compiler for r0 language
#!/usr/bin/env scheme --script
(import (nanopass))
(define unique-var
(let ()
(define count 0)
(lambda (name)
(let ([c count])
(set! count (+ count 1))
chansey97 / gist:86b9d854336f34d371543e3519009162
Created May 2, 2022 14:32 — forked from osallou/gist:7988178
Sample C foreign interface for SWI-Prolog called with my_function('6',N) loaded with :-use_foreign_library(foreign('')). compile: swipl-ld -shared -o test test.c
View gist:86b9d854336f34d371543e3519009162
#include <SWI-Prolog.h>
#include <stdio.h>
#include <stdlib.h>
typedef struct context /* define a context structure */
int max;
} context;
chansey97 /
Created October 9, 2021 19:23 — forked from staltz/
The introduction to Reactive Programming you've been missing
chansey97 / uniq.rkt
Created October 9, 2021 19:15 — forked from soegaard/uniq.rkt
Uniq for Racket lists
View uniq.rkt
#lang racket/base
(provide uniq)
;;; Uniq
; The function uniq takes a list as input and returns a new list:
; adjacent elements are compared and omits any repeated elements.
; In other words, uniq works like the Unix utility uniq, but on list.
chansey97 / stack.rkt
Created March 3, 2021 16:41
An imperative stack implementation in Racket.
View stack.rkt
#lang racket
(provide (except-out (all-defined-out)
(struct exn:fail:stack exn:fail ())
(struct stack ([vector]
[top #:mutable])
View locked-magic-door-by-inner-failed.rkt
#lang racket
(define the-key 'the-key)
(define the-spell-book 'the-spell-book)
(define person%
(class object%
(init-field items h)
View locked-magic-door-failed.rkt
#lang racket
(define the-key 'the-key)
(define the-spell-book 'the-spell-book)
(define person%
(class object%
(init-field items h)
chansey97 / Crush.hs
Last active March 3, 2021 16:46
Implement cursh by Traversable.
View Crush.hs
{-# LANGUAGE DeriveFunctor #-}
module Crush(
, crush
, crushMap
, crushMapM
-- debugging
, buildAst
, printAst
chansey97 / do-notation-maybe-local-eval.scm
Last active March 3, 2021 16:46
do-notation for maybe monad by `local-eval` and `the-environment `.
View do-notation-maybe-local-eval.scm
;guile 2.2.3
(use-modules (ice-9 local-eval))
(use-modules (ice-9 match))
(use-modules (srfi srfi-9))
(define-record-type Just
(make-Just x)
(x Just-x))
View Bridge.hs
module Bridge where
import Data.List
import Data.Maybe
import qualified Data.Tree as DTree
import qualified Data.Map as Map
-- Note that user must ensure there is at least one (0, x) in pieces
pieces :: [Piece]
pieces = [(0,2), (2,2), (2,3), (3,4), (3,5), (0,1), (10,1), (9,10)]