Skip to content

Instantly share code, notes, and snippets.

View athos's full-sized avatar
🤷‍♂️
I know the value and cost of nothing

Shogo Ohta athos

🤷‍♂️
I know the value and cost of nothing
View GitHub Profile
@athos
athos / deps.edn
Last active June 21, 2023 00:15
Try on your terminal `clojure -Sdeps '{:deps {hello-clojure/hello-clojure {:git/url "https://gist.github.com/athos/b68b15b08efedffaf14d8c020b125202" :git/sha "099bdf7d565b2c35c1df601abf58514cc5276237"}}}' -M -m hello-clojure`
{:paths ["."]
:deps {clansi/clansi {:mvn/version "1.0.0"}}}
@athos
athos / gist:3295528
Created August 8, 2012 14:39
a solution for SRFI-72's "Improved hygiene" using syntactic closures
;; A solution for SRFI-72's "improved hygiene" using syntactic closures.
;; See also http://srfi.schemers.org/srfi-72/srfi-72.html#hygiene
(let-syntax ([main (sc-macro-transformer
(lambda (form env)
(define (make-swap x y)
`(let ([t ,x])
(set! ,x ,y)
(set! ,y t)))
`(let ([s 1] [t 2])

Benchmark of first vs first'

We benchmarked the performance of the following two functions for various sequence types (and some other collection types):

  • (first (filter <pred> <coll>))
  • (first' (filter <pred>) <coll>) where first' is defined as follows:
    (defn first' [xform coll]
      (transduce xform (completing (fn [_ x] (reduced x))) nil coll))
@athos
athos / gist:1033052
Created June 18, 2011 12:34
An example code to generate a class with ASM in Clojure.
(import '[clojure.asm Opcodes Type ClassWriter]
'[clojure.asm.commons Method GeneratorAdapter])
(defn make-class [name]
(let [cw (ClassWriter. ClassWriter/COMPUTE_FRAMES)
init (Method/getMethod "void <init>()")
meth (Method/getMethod "int fact(int)")]
(.visit cw Opcodes/V1_6 Opcodes/ACC_PUBLIC (.replace name \. \/) nil "java/lang/Object" nil)
(doto (GeneratorAdapter. Opcodes/ACC_PUBLIC init nil nil cw)
(.visitCode)
(def cs [:a :b :c])
(defn ^:dynamic S [k]
(if-let [key (get cs (dec k))]
(assoc (zipmap cs (repeat 0)) key 1 :n 1)
(let [children (map S (range (- k 3) k))]
(-> (apply merge-with + (map #(dissoc % :children) children))
(assoc :children children)))))
(defn solve* [t s e acc]
{:paths ["."]
:deps {clj-skkserv
{:git/url "https://github.com/athos/clj-skkserv.git"
:sha "fba7b099252e3fb376be019b495ddee5da0ecd28"}
org.apache.logging.log4j/log4j-core {:mvn/version "2.12.1"}}
:aliases {:start {:main-opts ["-m" "clj-skkserv.main" "--handler" "skkserv-example/handler"]}}}
(ns jise.extension.tagbody
(:require [jise.emit :as emit]
[jise.parse :as parse])
(:import [clojure.asm Label MethodVisitor Opcodes]))
(defn parse-tagbody-body [body]
(loop [body body
tag nil
block []
blocks []]
@athos
athos / defexception.clj
Created August 24, 2019 00:31
Another implementation of defexception https://github.com/redplanetlabs/defexception using JiSE
(require '[jise.core :refer [defclass]])
(defmacro defexception [ex-name]
`(do
^:public
(defclass ~ex-name [clojure.lang.ExceptionInfo]
^:public
(defm ~ex-name [^String msg# ^clojure.lang.IPersistentMap map#]
(super msg# map#))
^:public
@athos
athos / README.md
Last active May 30, 2019 15:14
Shibuya.lisp Lisp meetup #76 LT発表資料

Shibuya.lisp Lisp meetup #76 LT発表資料

  • LT発表資料です
  • Clojure CLIがインストールされていれば、以下で実行できます:
$ clj -Sdeps '{:deps {athos/form-and-env {:git/url "https://gist.github.com/athos/1e92959529dc60316cc2fff4ed3990ff.git" :sha "343f21f5dc5999d9eeef3d993a31755ebd9b84a4"}}}'
@athos
athos / method_callsites.txt
Last active December 21, 2018 03:23
for classfile in target/classes/cljam/**/*.class; do line=$(javap -v $classfile | grep -E 'Method java/nio/(Char|Byte)Buffer.(clear|flip|limit|mark|position|reset|rewind):'); if (( ! $? )); then echo $classfile; echo $line; fi; done
target/classes/cljam/io/bam/decoder$parse_option$fn__2824.class
69: invokevirtual #57 // Method java/nio/CharBuffer.flip:()Ljava/nio/CharBuffer;
target/classes/cljam/io/bcf/reader$parse_data_line_shallow.class
220: invokevirtual #94 // Method java/nio/ByteBuffer.position:(I)Ljava/nio/ByteBuffer;
target/classes/cljam/io/fasta/reader$create_ba.class
31: invokevirtual #35 // Method java/nio/ByteBuffer.clear:()Ljava/nio/ByteBuffer;
53: invokevirtual #35 // Method java/nio/ByteBuffer.clear:()Ljava/nio/ByteBuffer;
target/classes/cljam/io/fasta/reader$read_sequence.class
583: invokevirtual #212 // Method java/nio/CharBuffer.flip:()Ljava/nio/CharBuffer;
target/classes/cljam/io/fasta/reader$sequential_read1_BANG_.class