Skip to content

Instantly share code, notes, and snippets.

@alandipert
alandipert / days.boot
Last active January 6, 2024 07:22
Boot script to print the days in some interval to standard out
#!/usr/bin/env boot
(set-env! :dependencies '[[clj-time "0.11.0"]])
(require '[clj-time.core :as t]
'[clj-time.format :as f]
'[boot.cli :refer [defclifn]])
(defn day-range
"Sequence of days from start-day (inclusive) to end-day (exclusive)"
(defun find-terms (num-terms max-size
&optional (desired-sum 0)
&aux (iterations 0))
"Returns a list of terms in the range -max-size ... +max-size,
inclusive, that sum to desired-sum.
Has strange properties. Likelier to blow the stack as max-size
increases. Seems to spend most time backtracking on the last few
terms.
@alandipert
alandipert / kahn.clj
Last active June 24, 2023 17:59
Kahn's topological sort in Clojure
;; Copyright (c) Alan Dipert. 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)
;; 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.
(ns alandipert.kahn
(:require [clojure.set :refer [difference union intersection]]))
# Clojure syntax highlighting for GNU source-highlight
# rocks with SHJS
# http://gist.github.com/265810
comment start ";"
include "number.lang"
vardef SPECIALCHAR = '\\.'
@alandipert
alandipert / opml2org.pl
Created November 14, 2010 00:03
Convert OPML to org-mode style nested headings, suitable for Confluence or Emacs
#!/usr/bin/perl
# Usage: perl opml2org.pl "My OPML File.opml"
use XML::Parser;
binmode STDOUT, ":utf8";
$xp = new XML::Parser();
$xp->setHandlers(Start => \&start, End => \&end);
$xp->parsefile($ARGV[0]);
$indent = 0;
@alandipert
alandipert / lis.pl
Created December 1, 2012 07:04 — forked from syohex/lis.pl
Simple Scheme interpreter in Perl(inspired by lis.py http://norvig.com/lispy.html)
#!perl
use strict;
use warnings;
package Lispl;
use Scalar::Util qw(blessed looks_like_number);
use List::Util qw(reduce);
my $global_env;

The following was sent to the JACL e-mail announcement list on 2021-02-26.

Hello everyone, and a belated happy 2021 to you! I hope your year has been off to a good start.

It's been almost a year since JACL became public, and nearly as long since any other announcement or release, so I thought to share three major related educational and design developments. The project is very much alive, just mostly in my head :-)

First, while I haven't made significant tangible progress on the JACL compiler or runtime since last year, I have continued to research and study implementation techniques. I have prototyped several schemes for efficient and JavaScript-friendly multiple-value returns, consuming relevant literature (mostly from the Scheme community) along the way. I have also studied and experimented with CLOS, and to speculate about how best to support a maximum of CLOS functionality without compromising JACL's calculated relationship with the JavaScript platform. One interes

@alandipert
alandipert / maptemplate.md
Created January 30, 2013 00:28
ClojureScript macros: kinda, sorta, not really.

ClojureScript macros: kinda, sorta, not really.

ClojureScript does not have a standalone macro system. To write ClojureScript macros, one must write them in Clojure and then refer to them in ClojureScript code. This situation is workable, but at a minimum it forces one to keep ClojureScript code and the macros it invokes in separate files. I miss the locality of regular Clojure macros, so I wrote something called maptemplate that gives me back some of what I miss. The technique may be useful in other scenarios.

Problem

Suppose you're wrapping functionality in another namespace or package so that you can have your own namespace of identically named but otherwise decorated functions:

ClojureScript:

@alandipert
alandipert / ded.clj
Created August 24, 2011 03:18
Command-line structural data editing
(ns ded
"Structural Data EDitor for Clojure with zippers. Inspired by Interlisp: http://larry.masinter.net/interlisp-ieee.pdf"
(:require [clojure.zip :as z])
(:use [clojure.pprint :only (with-pprint-dispatch code-dispatch pprint)]
[clojure.repl :only (source-fn)]))
(defn print-hr
"Prints 30 dashes and a newline."
[c]
(println (apply str (repeat 30 c))))
(defconstant mv-limit 20)
(defparameter *mv-expected* 1)
(defparameter *mv* (make-array mv-limit))
(defun mv (&rest vals)
(do ((i 0 (1+ i))
(vs vals (cdr vs)))
((or (eql i *mv-expected*) (null vs))