Skip to content

Instantly share code, notes, and snippets.

View HerbM's full-sized avatar

Herb Martin HerbM

  • LearnQuick.Com
  • Austin, TX
View GitHub Profile
@HerbM
HerbM / komp.clj
Created September 3, 2016 05:08
Re-implement Clojure "comp" for 4Clojure problem #58
(ns clojure4.core)
;;; Re-implement Clojure "comp" for 4Clojure problem #58 (as "komp")
(defn komp
([] (fn [n] (identity n)))
([fn1] (fn [& n] (apply fn1 n)) )
([fn1 fn2] (fn [& n]
(fn1 ((fn [m] (apply fn2 m)) n))))
([fn1 fn2 & fns] (fn [& n]
(fn1 ((fn [m] (apply (apply komp (conj fns fn2)) m )) n )))))
@HerbM
HerbM / tipe58.clj
Created September 4, 2016 15:05
4Clojure problem #58 Black box testing: Find type of set, map, vector, list without using built-in typing functions etc.
(defn tipe [s]
(let [sym1 (gensym) sym2 (gensym)
sym3 (gensym) s12 (conj s {sym1 sym2})
s1221 (conj (conj s {sym2 sym1}) s12)]
(if (get s12 sym1) :map
(if (get s12 {sym1 sym2}) :set
(if (= (first s1221) s12) :list :vector)))))
(= :map (tipe {:a 1, :b 2}))
(= :list (tipe (range (rand-int 20))))
(defn rducts
([f aseq] (lazy-seq (rducts f (f (first aseq)) (rest aseq))))
([f accum aseq]
(lazy-seq (cons accum (let [fs (first aseq) rs (rest aseq)]
(if (not (seq rs))
(list (f accum fs))
(rducts f (f accum fs) rs)))))))
(take 5 (rducts + (range)))
(rducts conj [1] [2 3 4])
;; My solution
(defn intervs [s]
(let [sorted (sort (into #{} s))
fs (first sorted)]
(cond (not (seq sorted)) ()
(= 1 (count sorted)) (list [fs fs])
(not= (inc fs) (second sorted)) (cons [fs fs] (intervs (rest sorted)))
:ELSE
(let [pairs (partition 2 1 sorted)]
(let [contig (take-while #(= (inc (first %)) (second %)) pairs)
open System
open System.IO
open System.Collections.Generic
open System.Text
open System.Text.RegularExpressions
#load "Library1.fs"
open Library1
// Define your library scripting code here
// Dr. Syme meets Dr. Seuss :slightly_smiling_face:
// Expert FSharp 4.0 p. 165 read aloud:
module public GlobalClock =
type TickTock = Tick | Tock
let mutable private clock = Tick
let private tick = new Event<TickTock>()
let internal oneTick() =
(clock <- match clock with
Tick -> Tock
| Tock -> Tick)
@HerbM
HerbM / OXML-1.fs
Created December 16, 2016 06:04
OpenXML-test-errors
// OpenXML-test-errors OXML-1
open System.IO
open System.IO.Packaging
open DocumentFormat.OpenXml.Packaging
open DocumentFormat.OpenXml.Wordprocessing
[<EntryPoint>]
let Main args =
let byteArray = File.ReadAllBytes "Test.docx"
use mem = new MemoryStream()
open System
open System.Text.RegularExpressions
exception QuitProgram
(* // defining this function causes the initial "> " to not be displayed first
let ProcessInput =
let input = System.Console.ReadLine()
try
let f = System.Single.Parse(input)
@HerbM
HerbM / map_fold.ps1
Created June 17, 2017 10:00 — forked from cdhunt/map_fold.ps1
Map and Fold implementations in Powershell
function map([scriptblock]$map, [Collections.IEnumerable]$x, $y) { $x.ForEach({& $map $_ $y}) }
# Two parameters
map { param($x, $y) $x + $y } @(1,2,3) 10
# Anonymous function as a value
$squareIt = { param($x) $x + $x }
map $squareIt @(1,2,3)
# One parameter
1 subgoal
n, m, p : nat
H : leb n m = true
IHp : leb (p + n) (p + m) = true
______________________________________(1/1)
leb (S p + n) (S p + m) = true
(* How does assumption complete the goal? I agree it's true but don't see how Coq gets that. *)