Skip to content

Instantly share code, notes, and snippets.

View fogus's full-sized avatar
💭
attempting to learn how to better learn

Fogus fogus

💭
attempting to learn how to better learn
View GitHub Profile
#!/bin/bash
# ---------------------------------------------------------------------------
# OO support functions
# Kludged by Pim van Riezen <pi@madscience.nl>
# ---------------------------------------------------------------------------
DEFCLASS=""
CLASS=""
THIS=0
@fogus
fogus / 0 - UNIX Fifth Edition
Created July 20, 2011 00:15
UNIX V5, OpenBSD, Plan 9, FreeBSD, and GNU coreutils implementations of echo.c
main(argc, argv)
int argc;
char *argv[];
{
int i;
argc--;
for(i=1; i<=argc; i++)
printf("%s%c", argv[i], i==argc? '\n': ' ');
}
;; The following is a tiny Prolog interpreter in MacLisp
;; written by Ken Kahn and modified for XLISP by David Betz.
;; It was inspired by other tiny Lisp-based Prologs of
;; Par Emanuelson and Martin Nilsson.
;; There are no side-effects anywhere in the implementation.
;; Though it is VERY slow of course.
(defun prolog (database &aux goal)
(do () ((not (progn (princ "Query?") (setq goal (read)))))
(prove (list (rename-variables goal '(0)))
;
; Ported to Chicken Scheme by Ivan Raikov.
;
; Scheme 9 from Empty Space, Function Library
; By Nils M Holm, 1998-2009
; See the LICENSE file of the S9fES package for terms of use
;
; (prolog list1 list2) ==> list
; (new-database!) ==> unspecific
; (fact! list) ==> unspecific
;;; PORTABLE PROLOG INTERPRETER by H. Nakashima
;;; ( Version 2 ) 1983.04.09
;;; Common Lisp Version 1988.11.21
(defvar cue nil "Goals to be executed")
(defvar clause nil "Body of a goal")
(defvar epilog nil "Switch to exit")
(defvar fetched-subst nil "The environment of the value of a variable")
(defvar goal nil "top-level goal")
(defvar new-subst nil "environment of the callee")
@fogus
fogus / rle.clj
Created March 8, 2011 19:47
Run-length encoding a seq
(defn mundane-pack
"Mundane recursive way to pack a sequence"
[[f & r :as S]]
(if (seq S)
(let [[packed tail] (split-with {f true} S)]
(if (seq tail)
(cons packed (mundane-pack tail))
[packed]))
[nil]))
@cgrand
cgrand / maze.clj
Created January 24, 2011 08:02
A maze generator (Wilson's algorithm) which can work with any topography (hextiles, torus variants, teapot etc.)
; http://groups.google.com/group/clojure/browse_thread/thread/974e2c7f89e27231/5f4bff3e58dfa36f
; output images http://i.imgur.com/gSASS.png (square maze)
; http://i.imgur.com/uEqaq.png (hex maze)
;; generic Wilson's algorithm implementation
(defn maze
"Returns a random maze carved out of walls; walls is a set of
2-item sets #{a b} where a and b are locations.
The returned maze is a set of the remaining walls."
[walls]
@Chouser
Chouser / avoid-force-print.clj
Created September 21, 2010 13:38
Avoid forcing lazy seqs when printing
; Copyright (c) Rich Hickey. All rights reserved.
; The use and distribution terms for this software are covered by the
; Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
; which can be found in the file epl-v10.html at the root of this distribution.
; By using this software in any fashion, you are agreeing to be bound by
; the terms of this license.
; You must not remove this notice, or any other, from this software.
; modified by Chris Houser
(require '[clojure.contrib.reflect :as hack])
@fogus
fogus / j.c
Created August 27, 2010 01:33
#include "stdio.h"
#include "stdlib.h"
#include "string.h"
typedef char C;typedef long I;
typedef struct a{I t,r,d[3],p[2];}*A;
#define P printf
#define R return
#define V1(f) A f(w)A w;
#define V2(f) A f(a,w)A a,w;
;; stolen from http://cemerick.com/2010/08/02/defrecord-slot-defaults/
(defmacro defrecord+defaults
"Defines a new record, along with a new-RecordName factory function that
returns an instance of the record initialized with the default values
provided as part of the record's slot declarations. e.g.
(defrecord+ Foo [a 5 b \"hi\"])
(new-Foo)
=> #user.Foo{:a 5, :b \"hi\"}"
[name slots & etc]