Skip to content

Instantly share code, notes, and snippets.

@jrk
jrk / llvmlisp.cpp
Created November 5, 2009 08:26
Toy LLVM Lisp, originally from http://paste.lisp.org/display/74068
/* A Trivial LLVM LISP
* Copyright (C) 2008-2009 David Robillard <dave@drobilla.net>
*
* Parts from the Kaleidoscope tutorial <http://llvm.org/docs/tutorial/>
* by Chris Lattner and Erick Tryzelaar
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
@micha
micha / gist:997056
Created May 28, 2011 17:34
Euler project problem #1
#! /usr/bin/env racket
; Euler problem #1. Sum of integers between 1 and N which are
; divisible by i, j, k, ..., or l.
;
; The sum 1+2+3+...+n = (n^2 + n)/2, call this sum-range(n).
;
; Then the sum of i+2i+3i+...+qi = i * sum-range(floor(n/i)), where
; qi is the greatest multiple of i such that i <= n.
;
@spullara
spullara / ReflectTest.java
Created December 25, 2011 22:31
Invokedynamic all in one example
package indy;
import java.lang.invoke.CallSite;
import java.lang.invoke.ConstantCallSite;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;
import java.lang.reflect.Constructor;
import org.objectweb.asm.ClassWriter;
;; depends on [org.imgscalr/imgscalr-lib "4.2"]
(ns XXX.image
(:refer-clojure :exclude [read])
(:require [clojure.java.io :as io])
(:import [org.imgscalr Scalr Scalr$Method Scalr$Mode]
[java.awt Image]
[java.awt.image RenderedImage BufferedImageOp]
[javax.imageio ImageIO ImageWriter ImageWriteParam IIOImage]
@jerrypnz
jerrypnz / test_watchers.clj
Created November 6, 2012 09:33
Clojure wrapper for Java 7 WatchService (java.nio.files)
(load-file "./watch_service.clj")
(refer 'watch-service)
(defn print-ev
[ev ctx]
(println "[foo]" ev " --> " ctx)
(println "Parent Dir:" (.getParent ctx)))
(defn print-ev-2
[ev ctx]
@taylorbanks
taylorbanks / gist:4196062
Created December 3, 2012 16:24 — forked from samsonjs/gist:4076746
Compiling and running mosh on Dreamhost
PREFIX=$HOME
VERSION=1.2.3-ltb
# Install Protocol Buffers
wget http://protobuf.googlecode.com/files/protobuf-2.4.1.tar.bz2
tar -xf protobuf-2.4.1.tar.bz2
cd protobuf-2.4.1
./configure --prefix=$PREFIX
make
make install
@fsmunoz
fsmunoz / abcl-mqtt.lisp
Created June 24, 2013 14:02
Simple example of MQTT message publish in Common Lisp and ABCL, using the Eclipse Paho client
;; Simple example of MQTT message publish using Common Lisp and ABCL
;;
;; Uses the Eclipse Paho client
;;
;; Author: Frederico Munoz <frederico.munoz@pt.ibm.com>
;; Date: 22-Jun-2013
;; Keywords: mqtt, messaging, m2m, telemetry, abcl, iot, paho, lisp
;;
;; Copying and distribution of this file, with or without modification,
;; are permitted in any medium without royalty provided the copyright
@kanaka
kanaka / tokenizer.sh
Last active December 30, 2015 12:18
bash lisp tokenizer NOTE: doesn't handle \" within strings yet
#!/bin/bash
wholefile=$(cat $1)
filelen=${#wholefile}
idx=0
chunk=0
chunksz=500
while true; do
if (( ${#str} < ( chunksz / 2) )) && (( chunk < filelen )); then
@DASpringate
DASpringate / cond.R
Last active May 19, 2017 15:24
A simple R implementation of `cond` from Lisp. Allows for arbitrary numbers of conditionals without nested if statements
#' R implementation of `cond` from Lisp
#' allows for arbitrary numbers of conditionals without ugly nested if statements
#' conditionals are entered as pairs of expressions (clauses),
#' first the expression to be evaluated and second the return value if the expression is true
#' @param ... an even number of expressions as pairs (see example)
#' @param true the `else` expression (Taken from the Lisp (T resultN) see http://www.cis.upenn.edu/~matuszek/LispText/lisp-cond.html)
#' @return The paired value of the first true conditional expression or the value of true
#' @examples
#' x <- runif(1)
#' cond(x < 0.2, "lower tail",
@chaitanyagupta
chaitanyagupta / _reader-macros.md
Last active April 29, 2024 09:09
Reader Macros in Common Lisp

Reader Macros in Common Lisp

This post also appears on lisper.in.

Reader macros are perhaps not as famous as ordinary macros. While macros are a great way to create your own DSL, reader macros provide even greater flexibility by allowing you to create entirely new syntax on top of Lisp.

Paul Graham explains them very well in [On Lisp][] (Chapter 17, Read-Macros):

The three big moments in a Lisp expression's life are read-time, compile-time, and runtime. Functions are in control at runtime. Macros give us a chance to perform transformations on programs at compile-time. ...read-macros... do their work at read-time.