Skip to content

Instantly share code, notes, and snippets.

@mnicky
mnicky / self-calling-lambda.scm
Created August 23, 2011 12:10
How to make an anonymous function call itself
;we define a function 'starter' which calls its first parameter on itself and the second parameter
(define starter
(lambda (f arg)
((f f arg))))
;we call the 'starter' on anonymous (lambda) function (calling its first parameter on itself and the second parameter) and a number
(starter (lambda (g num)
(printf "~a\n" num)
(g g (+ num 1)))
0)
@mnicky
mnicky / lisp.lisp
Created January 28, 2012 13:13
McCarthy's LISP from 1960 in Common Lisp:
; source: http://lib.store.yahoo.net/lib/paulgraham/jmc.lisp
; The Lisp defined in McCarthy's 1960 paper, translated into CL.
; Assumes only quote, atom, eq, cons, car, cdr, cond.
; Bug reports to lispcode@paulgraham.com.
(defun null. (x)
(eq x '()))
(defun and. (x y)
@mnicky
mnicky / simple_infer.clj
Created June 16, 2012 22:02
Simple inference engine
;simple inference engine, using bruteforce propagation of modus ponens
;if the fact matches given clause (using supplied map of bindings),
;returns a map of established bindings, else returns false
(defn match
([clause fact] (match clause fact {}))
([clause fact bnds]
(let [[cls & clsR] clause, [fct & fctR] fact]
(cond (contains? #{:not=} cls) {:__special__ clause}
(= clause fact) bnds
@mnicky
mnicky / github_lang_chart.sh
Created June 22, 2012 08:30
GitHub programming language popularity chart
# Display chart of programming languages recognized by GitHub, sorted by their popularity.
# Be patient, it takes about one minute to complete on a good internet connection.
for i in `curl -s "https://github.com/languages" | grep -io "/languages/[^\"]*" | sort | uniq`; do curl -s "https://github.com$i" | grep "<h1>.*</h1>" | sed 's/the most/#1/g' | sed 's/.*<h1>\(.*\) <em>.*#\([0-9]*\).*/\2 \1/g'; done | sort -n
@mnicky
mnicky / stopwords-en
Last active October 9, 2015 06:18
Extract words from all your tweets and count their occurences
able
about
above
abst
accordance
according
accordingly
across
act
actually
@mnicky
mnicky / sokuza-kanren.scm
Created October 25, 2012 11:26 — forked from fogus/sokuza-kanren.scm
Mini-kanren like logic programming in Scheme
; source: http://okmij.org/ftp/Scheme/sokuza-kanren.scm
; Quick miniKanren-like code
;
; written at the meeting of a Functional Programming Group
; (Toukyou/Shibuya, Apr 29, 2006), as a quick illustration of logic
; programming. The code is really quite trivial and unsophisticated:
; it was written without any preparation whatsoever. The present file
; adds comments and makes minor adjustments.
Rozhovor v kancelárii.
"Čaf. Workuje to?"
"No čau, už si tu? Nie, zatiaľ sa mi to nepodarilo rozbehať."
"Okej, tak sa logofni, ja sa na to luknem."
"Inak júzujem tvoju stoličku, neva? Len si toto sejvnem a hneď ti ju ritarnem. Aj tak to musím ísť dať sajnúť hedovi."
"Kľudne si ju nechaj, tejknem si tamtú."
"Ako chceš, ja už idem za hedom, už si môžeš tejknúť svoju."
U šéfa:
"Šéfko, sajneš mi túto invojsu? Vendor ma už obháňa, že sme overďjú."
@mnicky
mnicky / gist:4027422
Created November 6, 2012 20:48 — forked from jlongster/gist:1712455
traditional lisp macros
;; outlet code for implementing traditional macro expansion
;; macros
(define (expand form)
(cond
((variable? form) form)
((literal? form) form)
((macro? (car form))
(expand ((macro-function (car form)) form)))
@mnicky
mnicky / fsm.clj
Created November 22, 2012 12:38 — forked from Pet3ris/fsm.clj
Finite State Machine in Clojure core.logic
(ns fsm
(:refer-clojure :exclude [==])
(:use [clojure.core.logic]))
;; Encoding a Finite State Machine and recognizing strings in its language in Clojure core.logic
;; We will encode the following FSM:
;;
;; (ok) --+---b---> (fail)
;; ^ |
;Lisp in Lisp in Golomb forests. Includes use of linked lists.
;Based on Paul Graham's version of McCarthy's paper and code.
;Uses only eq, cond, atom, quote, cons, car, and cdr.
(defun null. (x)
(eq x '()))
(defun and. (x y)
(cond (x
(cond (y 't)