Skip to content

Instantly share code, notes, and snippets.

View mmontone's full-sized avatar

Mariano Montone mmontone

View GitHub Profile

Polymorphism in Scheme via compile time dispatch

Here's an example of polymorphism in C++:

int nth ( int a[] , int i ) { return a[i] ; }

double nth ( double a[] , int i ) { return a[i] ; }

One way to think of this is that there are two functions called nth. One can be called with an int array and the other can be called with a double array. The function that is called is determined at compile time by looking at the type of the expression of the first argument.

Generics in Scheme

In a previous note I demonstrated polymorphism in Scheme using Chez Scheme's compile time values and properties.

The code in that example is pretty raw; you might not want to code each generic in that manner. One approach is to decouple the signature/method table. We can do this by factoring out some code into a 'make-generic' procedure:

(define (make-generic table)
  (lambda (stx)
 (lambda (lookup)
@danlentz
danlentz / hash-class
Created December 7, 2012 06:15
MOP design pattern
;; http://sourceforge.net/tracker/index.php?func=detail&aid=1359066&group_id=1355&atid=101355
;; user-defined :allocation :hash
(defpackage #:hash-classes
(:use #:common-lisp
#+allegro #:clos
#+clisp #:clos
#+cmu #:clos-mop
#+lispworks #:clos
#+(and mcl (not openmcl)) #:mcl-mop
@jackrusher
jackrusher / skewer-coffee.el
Last active December 19, 2017 19:20
The tiniest possible skewer-mode extension for coffeescript support.
;;; skewer-coffee.el --- skewer support for live-interactive Coffeescript
(defun skewer-coffee-eval (coffee-code)
"Requests the browser to evaluate a coffeescipt string."
;; XXX should escape double quote characters
(skewer-eval (concat "CoffeeScript.eval(\""
(s-replace "\n" "\\n" (s-trim coffee-code))
"\");")
#'skewer-post-minibuffer))
@OrionReed
OrionReed / dom3d.js
Last active November 16, 2024 13:18
3D DOM viewer, copy-paste this into your console to visualise the DOM topographically.
// 3D Dom viewer, copy-paste this into your console to visualise the DOM as a stack of solid blocks.
// You can also minify and save it as a bookmarklet (https://www.freecodecamp.org/news/what-are-bookmarklets/)
(() => {
const SHOW_SIDES = false; // color sides of DOM nodes?
const COLOR_SURFACE = true; // color tops of DOM nodes?
const COLOR_RANDOM = false; // randomise color?
const COLOR_HUE = 190; // hue in HSL (https://hslpicker.com)
const MAX_ROTATION = 180; // set to 360 to rotate all the way round
const THICKNESS = 20; // thickness of layers
const DISTANCE = 10000; // ¯\\_(ツ)_/¯