Skip to content

Instantly share code, notes, and snippets.

@mnicky
mnicky / interp2.lisp
Created December 11, 2012 21:37
Tail-recursive Scheme interpreter by Peter Norvig
;source: http://norvig.com/paip/interp2.lisp
;;; -*- Mode: Lisp; Syntax: Common-Lisp; -*-
;;; Code from Paradigms of Artificial Intelligence Programming
;;; Copyright (c) 1991 Peter Norvig
;;; File interp2.lisp: Tail-recursive Scheme interpreter.
(requires "interp1")
@mnicky
mnicky / interp1.lisp
Created December 11, 2012 21:36
simple Scheme interpreter, including macros, by Peter Norvig
;source: http://norvig.com/paip/interp1.lisp
;;; -*- Mode: Lisp; Syntax: Common-Lisp; -*-
;;; Code from Paradigms of Artificial Intelligence Programming
;;; Copyright (c) 1991 Peter Norvig
;;; File interp1.lisp: simple Scheme interpreter, including macro.sgi
(defun interp (x &optional env)
"Interpret (evaluate) the expression x in the environment env."
@mnicky
mnicky / lisp_macros.lisp
Created December 11, 2012 21:23
McCarthy's LISP with macros
;source: http://ideone.com/lEx0T
;explanation: http://stackoverflow.com/a/3685147
(defun null. (x)
(eq x '()))
(defun and. (x y)
(cond (x (cond (y 't) ('t '())))
('t '())))
@mnicky
mnicky / lispy.py
Created December 11, 2012 19:20
Lispy2: (Advanced) Scheme Interpreter in Python
################ Scheme Interpreter in Python
## (c) Peter Norvig, 2010; See http://norvig.com/lispy2.html
################ Symbol, Procedure, classes
from __future__ import division
import re, sys, StringIO
class Symbol(str): pass
@mnicky
mnicky / lis.py
Created December 10, 2012 20:48
Lispy: Scheme Interpreter in Python
################ Lispy: Scheme Interpreter in Python
## (c) Peter Norvig, 2010; See http://norvig.com/lispy.html
################ Symbol, Env classes
from __future__ import division
Symbol = str
;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)
@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)
;; ^ |
@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)))
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 / 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.