Skip to content

Instantly share code, notes, and snippets.

View missingfaktor's full-sized avatar
🥔

Rahul Goma Phulore missingfaktor

🥔
View GitHub Profile
(defn evaluate [exp]
(match exp
(:variant :val [x]) x
(:variant :add [x y]) (+ (evaluate x) (evaluate y))
(:variant :multiply [x y]) (* (evaluate x) (evaluate y))))
(def numeric-expression
[:add [:val 2]
[:multiply [:val 4]
[:val 5]]])
(ns akar.talk-examples
(:require [akar.try-out :refer :all]
[clojure.xml :as xml])
(:import [java.util.concurrent ConcurrentHashMap]
[java.io ByteArrayInputStream]))
; Example 1
(def request-ids-pattern
#"rid=(.*)\|(.*)")
(require '[clojure.spec :as sp])
(defn define-syntax* [name' forms spec target]
(let [enclosing-form (cons name' forms)
result (sp/conform spec enclosing-form)]
(if (= ::sp/invalid result)
(throw (ex-info "Syntax error" (sp/explain-data spec enclosing-form)))
(target result))))
(defmacro define-syntax [name & {:keys [spec-name spec target]}]
(defn find [seq' pred]
(match seq'
(:seq [(:and x [(!pred pred)]) & :_]) x
(:seq [:_ & rest]) (find rest pred)
(:seq []) nil))
sealed trait JobDescription
sealed trait HasN {
def n: Int
}
case class JobOne(n: Int) extends JobDescription with HasN
case object JobTwo extends JobDescription
case class JobThree(n: Int) extends JobDescription with HasN
@missingfaktor
missingfaktor / Actor.java
Created June 18, 2016 23:19 — forked from viktorklang/Actor.java
Minimalist Java Actors
// 6,046 bytes jarred.
/*
Copyright 2012 Viktor Klang
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Prelude> newtype Dyn a = Dyn a deriving Show
Prelude> data Book = Book (Dyn String) Int deriving Show
Prelude> :{
Prelude| class Serialise a where
Prelude| serialise :: a -> String
Prelude| :}
Prelude> instance Serialise Book where serialise (Book (Dyn s) i) = s ++ ":" ++ show i
Prelude>
Prelude> let serialisedBook = fmap serialise (\s -> Book s 32)
Prelude> -- apply dynamic value when available
scala> case class Callback[A](f: (A => Unit) => Unit) {
| def map[B](g: A => B): Callback[B] = Callback { (h: B => Unit) => f(a => h(g(a))) }
| def flatMap[B](g: A => Callback[B]): Callback[B] = Callback { (h: B => Unit) => f(a => g(a).f(b => h(b))) }
| }
defined class Callback
package sudoku.console
object Monadology {
// Wear the function goggles.
val foo = 2 + 3
val bar = foo + 1
Math.min(foo, bar)
package sudoku.errors
import scala.language.higherKinds
import scala.reflect.ClassTag
object Modes {
trait Mode {
type Result[_, _]
def run[E : ClassTag, A](a: => A): Result[E, A]