Skip to content

Instantly share code, notes, and snippets.

View roman's full-sized avatar

Roman Gonzalez roman

View GitHub Profile
(ns blah
(:use [zetta.parser.seq :only (whitespace number char)]
[zetta.combinators :only (choice around)]
[zetta.core :only (*>, <*)])
(:require [zetta.core :as z]))
(def whitespaces (many whitespace))
; For that you should use parser combinators and the monadic interface!
; if you have conditionals in your parser, this is the way to go
(ns blah
(:use [zetta.parser.seq :only (whitespace number char)]
[zetta.combinators :only (choice around)]
[zetta.core :only (*>, <*)])
(:require [zetta.core :as z]))
(def whitespaces (many whitespace))
(def identifier
(around
(def identifier
(around
whitespaces
(choice
[(<$> (partial apply vector)
(*> (string "#")
(<* number (string "#"))))
; ^ I think you should be using just number here right?
; you are trying to parse (many1 digit)
(<$> (partial apply vector)
@roman
roman / swank-failure.sh
Created March 9, 2012 03:11
stacktrace of swank-clojure v1.4.0 and leiningen2 master
The eval-in-project function has moved to the leiningen.core.eval
namespace; please update your plugin to use that instead.
Note that `init' is now the third argument instead of the fifth.
This function will be removed for the final 2.0.0 release.
Listening for transport dt_socket at address: 60158
Compiling wedding.app
Compilation succeeded.
Listening for transport dt_socket at address: 60159
Exception in thread "main" java.lang.RuntimeException: java.io.FileNotFoundException: Could not locate swank/swank__init.class or swank/swank.clj on classpath:
at clojure.lang.Util.runtimeException(Util.java:165)
@roman
roman / tumblr.clj
Created February 20, 2012 00:35
Tumblr API using river
(ns river.tumblr
(:use [clojure.pprint :only (pprint)])
(:use [river.core]
[zetta.core]
[river.http :only (produce-http-get)]
[zetta.river :only (parse*)]
[zetta.json :only (json)])
(:require [river.seq :as rs]
[zetta.parser.seq :as zs]))
@roman
roman / monad.clj
Created December 8, 2011 19:40
Playing with clojure monads
(ns playground.monad
(:use [clojure.algo.monads :only
[domonad defmonadfn with-monad state-m fetch-state set-state
update-state m-fmap]]))
(def get-name
(domonad state-m
[a (fetch-state)]
(:name a)))
@roman
roman / example.clj
Created November 28, 2011 02:32
clojure's repeatedly gotcha
(ns example)
; This won't work.
(defn wrong-process-lines [n action]
(letfn [(process []
(let [ln (read-line)]
(action ln)))]
(repeatedly n process)))
; The dorun call is going to evaluate each item of the lazy-seq returned from the
@roman
roman / reverse_sum.clj
Created November 27, 2011 18:56
Keep the important parameter first!
(ns main
(:require [clojure.string :as string]))
; this code is to solve the following algorithmic problem:
; http://www.spoj.pl/problems/ADDREV/
(def sum (partial reduce + 0))
(defn main [& args]
(let [n (Integer/parseInt (read-line))]
@roman
roman / logical.core.clj
Created November 25, 2011 00:36
Usage of clojure.core.logic
(ns logical.core
(:use [clojure.core.logic
:only [
defrel fact fresh to-stream unify all
]]))
(defrel man p)
(fact man "adam")
(fact man "peter")
(fact man "paul")
@roman
roman / iteratee.clj
Created October 22, 2011 02:18
Haskell Iteratees in clojure (naive impl)
(ns iteratee
(:require [clojure.contrib.types :as adt]))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(adt/defadt ::stream
eof
(chunks xs))
(adt/defadt ::iteratee