Skip to content

Instantly share code, notes, and snippets.

View mmontone's full-sized avatar

Mariano Montone mmontone

View GitHub Profile
@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))
@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

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)

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.