Skip to content

Instantly share code, notes, and snippets.

@tuturto
tuturto / secondo.hy
Last active August 29, 2015 14:01
some secondᵒ magic
(import [adderall.dsl [*]])
(require adderall.dsl)
(defreader t [expr] `(, ~@expr))
(defn secondᵒ [l x]
(fresh [r]
(restᵒ l r)
(firstᵒ r x)))
@tuturto
tuturto / path.hy
Last active August 29, 2015 14:01
(import [adderall.dsl [*]])
(require adderall.dsl)
(defn lastᵒ [s l]
(fresh [a]
(appendᵒ a [l] s)))
(defn adjacentᵒ [x y z]
(fresh [a b]
(condᵉ
@tuturto
tuturto / gist:71d02d4561864d90f526
Last active August 29, 2015 14:02
wallᵒ or not to wallᵒ
(setv level-data
[[:wall-data
[(, (, 5 5) :rock-wall)
(, (, 6 5) :rock-wall)
(, (, 7 5) :tile-wall)]]
[:floor-data
[(, (, 5 6) :dirt-floor)
(, (, 6 6) :rock-floor)
(, (, 7 6) :rock-floor)]]])
@tuturto
tuturto / binary.hy
Last active August 29, 2015 14:05
bsp (failing one)
;; -*- coding: utf-8 -*-
;;
;; Copyright 2010-2014 Tuukka Turto
;;
;; This file is part of pyherc.
;;
;; pyherc 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.
@tuturto
tuturto / gist:1cbd211efa8aa8f45298
Created February 13, 2015 21:24
fooling with macros
(require hy.contrib.anaphoric)
(require pyherc.macros)
(import [pyherc.data [new-level Portal add-portal get-locations-by-tag
wall-tile]]
[pyherc.generators.level.partitioners.old-grid [RandomConnector]])
(defmacro run-generators [level &rest generators]
(list (map (fn [x] `(ap-each ~x (it level))) generators)))
;; Adapted from https://github.com/ReactiveX/RxPY/blob/master/examples/konamicode/konamicode.py
(import [rx.subjects [Subject]])
(setv codes [:up :up :down :down :left :right :left :right :b :a])
(setv subject (Subject))
(setv query (-> (.window_with_count subject 10 1)
(.select-many (fn [win] (.sequence-equal win codes)))
(.filter (fn [equal] equal))))
@tuturto
tuturto / shimmy.lisp
Created April 1, 2015 03:58
Getting cl-charms to support colour in Windows and sdl build of pdcurses
(in-package #:cl-charms/low-level)
; #define COLOR_PAIR(n) (((chtype)(n) << PDC_COLOR_SHIFT) & A_COLOR)
; for 32-bit curses
(defun COLOR-PAIR (n)
(logand (ash n 24) #xff000000))
;(defun COLOR-PAIR (n)
; (logand (ash n 24) (ash #x7fffffff 24)))
@tuturto
tuturto / gist:486c4ff24b94248a2dfe
Last active August 29, 2015 14:27
set-attributes
(defmacro set-attributes [&rest attributes]
`(do ~@(genexpr `(setattr self ~x ~x) [x attributes])))
(defmacro set-attributes [&rest attributes]
`(do ~@(genexpr `(setv self.~x ~x) [x attributes])))
(defn --init-- [self foo bar baz]
(set-attributes foo bar baz))
->
(defn --init-- [self foo bar baz]
@tuturto
tuturto / foo.hy
Created October 5, 2015 18:51
unspeakable things
(defmacro set-parameters [&rest parameters]
(defn setter [parameter]
(HyExpression [(HySymbol "setv")
(HySymbol (+ "self." parameter))
(HySymbol parameter)]))
`(do ~@(map setter parameters)))
(defclass Kissa []
[[--init-- (fn [self name age]
(super-init)
@tuturto
tuturto / macros.hy
Created October 7, 2015 18:25
Bots build bots
;; do-trigger should be ~name, but there's two levels of quasi-quotes
(defmacro method-with-attributes [name]
`(defmacro effect-trigger [attributes body]
`[do-trigger (fn [self dying-rules]
(let [~@(genexpr `[~x (. self ~x)] [x attributes])]
~body))]))