Skip to content

Instantly share code, notes, and snippets.

@k0f1sh
k0f1sh / scheme-interpreter-interperter.scm
Last active February 25, 2023 14:50
プログラミング言語 SCHEMEの練習問題9.7.1, 9.7.2 (メタ循環インタプリタ)
((lambda (interpret)
;; code
(interpret '((lambda (interpret)
;; code
(interpret '((lambda (a b) ((lambda (c d) (cons c d)) a b)) 1 2))
)
((lambda (primitive-environment new-env lookup assign)
((lambda (exec)
(lambda (exp)
(exec exp primitive-environment)))
@k0f1sh
k0f1sh / guile_json_peg.scm
Created February 9, 2023 13:07
guileのPEGパーサーでJSONをalist形式に変換
(use-modules (ice-9 peg))
(define-peg-string-patterns
"True <-- 'true'
False <-- 'false'
Null <-- 'null'
WS < (' ' / '\n' / '\r' / '\t')*
Number <-- Minus? IntegralPart FractionalPart? ExponentPart?
Minus <- '-'
IntegralPart <- '0' / [1-9] [0-9]*
@k0f1sh
k0f1sh / gentbl.el
Last active September 9, 2020 14:05
generate table
;; generate-table
(require 's)
(require 'seq)
(require 'subr-x)
(defun gentbl-get-table-header (table-list)
(car table-list))
(defun gentbl-swap (tl)
@k0f1sh
k0f1sh / re-seq.el
Last active September 8, 2020 15:04
(defun re-seq (r s)
(let ((l)
(n 1)
(break nil))
(save-match-data
(string-match r s)
(while (null break)
(if-let ((m (match-string n s)))
(progn
(push m l)
(ns gengo05
(:require [clojure.java.io :as io]
[incanter.core :as i-core]
[incanter.charts :as i-charts]
[dorothy.core :as dot]
[dorothy.jvm :refer (render save! show!)]))
;; https://nlp100.github.io/ja/ch05.html
;; $ cat neko.txt | cabocha -f1 > neko.txt.cabocha
(ns gengo04
(:require [clojure.java.io :as io]
[incanter.core :as incanter-core]
[incanter.charts :as incanter-charts]
))
;; https://nlp100.github.io/ja/ch04.html
;; $ mecab neko.txt -o neko.txt.mecab
(ns gengo03
(:require [cheshire.core :as cheshire]
[clojure.java.io :as io]))
;; https://nlp100.github.io/ja/ch03.html
;; 20
(def r (io/reader (io/resource "jawiki-country.json")))
(def jsons (doall
(map (fn [line]
@k0f1sh
k0f1sh / 02.sh
Created May 10, 2020 12:31
第2章: UNIXコマンド
#!/bin/bash
# https://nlp100.github.io/ja/ch02.html
# 10
cat popular-names.txt | bb -io "(count *input*)"
# 11
cat popular-names.txt | bb -i '(doseq [line *input*] (println (str/replace line #"\t" " ")))' > popular-names-spaces.txt
@k0f1sh
k0f1sh / 01.clj
Created May 10, 2020 09:51
第1章: 準備運動
;;; https://nlp100.github.io/ja/ch01.html
;; helper
(defn get-words [s]
(->> (clojure.string/split s #"[\., ]")
(filter #(not (empty? %)))))
(defn make-ngram [n coll]
(if (> n (count coll))
[]
@k0f1sh
k0f1sh / core.clj
Created October 8, 2018 17:44
spandexでelasticsearch api叩いてみる
(ns hoge.core
(:require [qbits.spandex :as s]))
;; 参考: https://dev.classmethod.jp/server-side/elasticsearch-getting-started-07/
(def conn (s/client {:hosts ["http://localhost:9200"]}))
;; clusterの状態確認
(s/request conn {:url "/_cat/health?v"})