Skip to content

Instantly share code, notes, and snippets.

(defmacro def-curry-fn [name args & body]
{:pre [(not-any? #{'&} args)]}
(if (empty? args)
`(defn ~name ~args ~@body)
(let [rec-funcs (reduce (fn [l v]
`(letfn [(helper#
([] helper#)
([x#] (let [~v x#] ~l))
([x# & rest#] (let [~v x#]
(apply (helper# x#) rest#))))]
(ns typed-play.core
(:require-macros [clojure.core.typed :as ct])
(:require [clojure.core.typed :as ct]))
(ct/ann my-identity (All [x] (Fn [x -> x])))
(defn my-identity [x]
(if (number? x)
(inc x)
x))
@rm-hull
rm-hull / sudoku.cljs
Last active December 24, 2015 14:49 — forked from swannodette/gist:3217582
(ns sudoku
;(:refer-clojure :exclude [==])
(:require-macros [cljs.core.logic.macros :as m])
(:use [cljs.core.logic :only [everyg infd distinctfd]]))
(defn get-square [rows x y]
(for [x (range x (+ x 3))
y (range y (+ y 3))]
(get-in rows [x y])))
@rm-hull
rm-hull / core-logic-demo.cljs
Created October 3, 2013 19:58
Simple script to check that core.logic is wired in properly
(ns example
(:require-macros [cljs.core.logic.macros :as m])
(:use [cljs.core.logic :only [membero]]))
(println
(m/run* [q]
(membero q '(:cat :dog :bird :bat :debra))))
@rm-hull
rm-hull / classic-ai.cljs
Last active December 24, 2015 14:59
Adapted to clojurescript flavor, derived from https://github.com/clojure/core.logic/wiki/Examples
(ns classic-ai-example
(:require-macros [cljs.core.logic.macros :as m])
(:use [cljs.core.logic :only [-take*]]))
(m/defne moveo [before action after]
([[:middle :onbox :middle :hasnot]
:grasp
[:middle :onbox :middle :has]])
([[pos :onfloor pos has]
:climb
@rm-hull
rm-hull / maze.cljs
Last active March 29, 2020 21:18
Maze generator and solver using Dijkstra's graph search algorithm, served up in ClojureScript & rendered on a HTML5 canvas. Try adding ?draw=X to the URL where X is one of none, path, snake or snail
(ns maze.core
(:use [enchilada :only [canvas ctx value-of canvas-size]]
[monet.canvas :only [get-context stroke stroke-style stroke-cap begin-path close-path line-to move-to stroke-width]]
[monet.core :only [animation-frame]]
[jayq.core :only [$ document-ready data attr hide show]]
[maze.util :only [coord->pos]]
[maze.generator :only [create-maze]]
[maze.solver :only [solve]]))
(defn draw-path-segments [ctx snake start end]
(ns tests
(:refer-clojure :exclude [==])
(:use-macros
[cljs.core.logic.macros
:only [run run* == conde conda condu fresh defne matche all]])
(:require-macros [cljs.core.logic.macros :as m]
[clojure.tools.macro :as mu])
(:use
[enchilada :only [ctx]]
[cljs.core.logic
@rm-hull
rm-hull / einsteins-zebra-puzzle.md
Last active October 14, 2022 05:25
@swannodette: "Reminder Norvig could solve Einstein's Puzzle in 17s in '93 using Common Lisp, today milliseconds in your browser"

From https://en.wikipedia.org/wiki/Zebra_Puzzle

  1. There are five houses.
  2. The Englishman lives in the red house.
  3. The Spaniard owns the dog.
  4. Coffee is drunk in the green house.
  5. The Ukrainian drinks tea.
  6. The green house is immediately to the right of the ivory house.
  7. The Old Gold smoker owns snails.
  8. Kools are smoked in the yellow house.
@rm-hull
rm-hull / three.cljs
Last active March 27, 2021 10:13 — forked from michiakig/three.cljs
Simple demonstration of using THREE.js with ClojureScript [from a fork of https://gist.github.com/spacemanaki/1157978], now working with thanks to @seabre
(ns three.demo
(:require [THREE :as THREE]))
(def camera
(THREE/PerspectiveCamera.
75
(/ 800 600)
1
10000))
@rm-hull
rm-hull / quine.cljs
Last active December 25, 2015 23:59
From Wikipedia: "A quine is a computer program which takes no input and produces a copy of its own source code as its only output. The standard terms for these programs in the computability theory and computer science literature are self-replicating programs, self-reproducing programs, and self-copying programs. A quine is a fixed point of an ex…
(println
(#(list % (list 'quote %)) '#(list % (list 'quote %))))