This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Example of a C program embedding ECL with callbacks to C functions. | |
Compiled via: gcc ecldemo.c -lecl | |
*/ | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include "ecl/ecl.h" | |
#define DEFUN(name,fun,args) \ | |
cl_def_c_function(c_string_to_object(name), \ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(require :cl-lex) | |
(require :yacc) | |
(require :arnesi) | |
(use-package :cl-lex) | |
(use-package :yacc) | |
(arnesi:enable-sharp-l) | |
(defun str->sym (str) | |
(values (intern (string-upcase str)))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(define (push element) | |
(lambda (stack) | |
(list '() (cons element stack)))) | |
(define (pop) | |
(lambda (stack) | |
(let ((element (car stack)) | |
(new-stack (cdr stack))) | |
(list element new-stack)))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns evolvefn) ;; Lee Spector ([email protected]) 20111018 | |
;; This code defines and runs a genetic programming system on the problem | |
;; of finding a function that fits a particular set of [x y] pairs. | |
;; The aim here is mostly to demonstrate how genetic programming can be | |
;; implemented in Clojure simply and clearly, and several things are | |
;; done in somewhat inefficient and/or non-standard ways. But this should | |
;; provide a reasonable starting point for developing more efficient/ | |
;; standard/capable systems. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(use '[clojure.core.match :only [match]]) | |
(defn evaluate [env [sym x y]] | |
(match [sym] | |
['Number] x | |
['Add] (+ (evaluate env x) (evaluate env y)) | |
['Multiply] (* (evaluate env x) (evaluate env y)) | |
['Variable] (env x))) | |
(def environment {"a" 3, "b" 4, "c" 5}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// "Extend" the EventEmitter like this: | |
var EventEmitter = require('events').EventEmitter; | |
EventEmitter.prototype.once = function(events, handler){ | |
// no events, get out! | |
if(! events) | |
return; | |
// Ugly, but helps getting the rest of the function |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
macro $do { | |
case { $y:expr } => { | |
$y | |
} | |
case { $x:ident <- $y:expr $rest ... } => { | |
λ['>=']($y, function($x) { | |
return $do { $rest ... } | |
}); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
macro sexp { | |
case () => { | |
; | |
} | |
case ($p) => { | |
$p | |
} | |
case ($x $y) => { | |
$x($y); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Note: there are bugs in hygienic renaming, so this doesn't work all the time yet. | |
macro varr { | |
case [$var (,) ...] = $expr => { | |
var i = 0; | |
var arr = $expr; | |
$(var $var = arr[i++];) ... | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
macro def { | |
case $name:ident ( $($params:ident : $type:ident) (,) ...) $body => { | |
// just throwing away the type annotation. The semantics of type | |
// annotations left as an exercise to the reader :) | |
function $name ($params (,) ...) $body | |
} | |
} | |
def add (a : Number, b : Number) { | |
return a + b; |
OlderNewer