Skip to content

Instantly share code, notes, and snippets.

View bendisposto's full-sized avatar

Jens Bendisposto bendisposto

View GitHub Profile
(ns muster.core
(:use clojure.set))
;; Aufgabe 1
(defn calc' [a op b & rest]
(if-not (seq rest)
(op a b)
(apply calc' (op a b) rest)))
(defmacro calc [bindings & term]
summe [] = 0
summe (x:xs) = x + summe xs
prod [x] = x
prod (x:xs) = x * prod xs
factorial 0 = 1
factorial n = n * factorial (n-1)
(ns repl.core)
(def x -3)
(comment
;; --- Wiederholung
;; -----------------------------------------------------------------------------------------------
;; Performance tuning: type hints
(ns repl.core)
(defn new-thread [f] (.start (Thread. f)))
(comment
;; --- Wiederholung
;; Vars & Concurrency
(ns muster.core)
(set! *print-length* 25)
;; Aufgabe 1
(def nat (iterate inc 0))
(def even-nat (filter even? nat))
(def primes (remove
(fn [a] (some #(= 0 (mod a %)) (range 2 (/ 2 a))))
(iterate inc 2)))
(def partial-sum (reductions + nat))
(ns repl.core
(:refer-clojure :exclude [replace])
(:require [clojure.test :as t])
(:use [clojure.string :only (replace join)]
[clojure.repl :rename {dir ls}]
repl.greeter.friendly-hello)
(:import (java.util Date Timer Random)
java.io.File
(javax.swing JFrame JPanel) ))
(ns muster.core)
;; Aufgabe 1
(defn rev-interleave [col n]
(apply map list (partition n col)))
(defn myflatten [col]
(mapcat #(if (coll? %) (myflatten %) [%]) col))
;; Aufgabe 2
(ns muster.core)
;Aufgabe 1
(defn flip [f] (fn [& args] (apply f (reverse args))))
(defn mycomp [& fs]
(fn [& args] (reduce (fn [a f] (f a))
(apply identity args)
(reverse fs))))
(ns repl.core)
(comment
;; atom
(def foo (atom 2))
foo
(deref foo)
@foo
(ns repl.core)
(comment
;; Atoms
(def foo (atom {}))
foo
(defn store [k v] (swap! foo assoc ,,,, k v))