THIS GIST WAS MOVED TO TERMSTANDARD/COLORS
REPOSITORY.
PLEASE ASK YOUR QUESTIONS OR ADD ANY SUGGESTIONS AS A REPOSITORY ISSUES OR PULL REQUESTS INSTEAD!
(defrel triple ^{:index true} s ^{:index true} p ^{:index true} o) | |
(facts triple [[:Berlin :is-a :city] | |
[:city :is-a :permanent-settlement] | |
[:Berlin :part-of :Germany] | |
[:Germany :part-of :EU] | |
[:EU :part-of :Eurasia] | |
[:Eurasia :part-of :Earth]]) | |
(run* [q] (triple q :is-a :city)) |
#include <stdlib.h> | |
#include <stdio.h> | |
#include <math.h> | |
typedef int i; //Save space by using 'i' instead of 'int' | |
typedef float f; //Save even more space by using 'f' instead of 'float' | |
//Define a vector class with constructor and operator: 'v' | |
struct v { | |
f x,y,z; // Vector has three float attributes. |
use std::task; | |
use std::rt::io::timer::sleep; | |
///<Summary> | |
///Simple butterfly | |
///</Summary> | |
pub fn butterfly<U>(f: &fn() -> U) -> U { | |
let (port, chan) = stream(); | |
do task::spawn_sched(task::SingleThreaded) { | |
print(" "); |
{-# LANGUAGE TypeFamilies #-} | |
import Data.Function (on) | |
import Control.Applicative | |
data EventData e = EventData { | |
eventId :: Int, | |
body :: Event e | |
} |
#include <map> // Component-entity system in 16 lines of C++11. 2013 rlyeh, MIT licensed | |
#include <set> // Code fragment from kult engine - https://github.com/r-lyeh/kult | |
enum {JOIN,MERGE,EXCLUDE};using set=std::set<unsigned>;template<typename T> set&system(){ | |
static set entities;return entities;}template<typename T,int MODE>set subsystem(const set | |
&B){set newset;const set&A=system<T>();if(MODE==MERGE){newset=B;for(auto&id:A)newset.ins\ | |
ert(id);}else if(MODE==EXCLUDE){newset=B;for(auto&id:A)newset.erase(id);}else if(A.size() | |
<B.size()){for(auto&id:A)if(B.find(id)!=B.end())newset.insert(id);}else{for(auto&id:B)if( | |
A.find(id)!=A.end())newset.insert(id);}return newset;}template<typename T>std::map<unsig\ | |
ned,T>&components(){static std::map<unsigned,T>objects;return objects;}template<typename\ | |
T>bool has(unsigned id){return components<T>().find(id)!=components<T>().end();}templat\ |
THIS GIST WAS MOVED TO TERMSTANDARD/COLORS
REPOSITORY.
PLEASE ASK YOUR QUESTIONS OR ADD ANY SUGGESTIONS AS A REPOSITORY ISSUES OR PULL REQUESTS INSTEAD!
(def parent {:x1 0 :y1 0 :x2 600 :y2 400}) | |
(def rs [{:x1 0 :y1 0 :x2 300 :y2 200 } | |
{:x1 0 :y1 200 :x2 300 :y2 400 }]) | |
(defn negative-space [parent rs] | |
(let [x (apply max (map :x2 rs)) | |
y (apply min (map :y1 (filter (comp (partial = x) :x2) rs)))] | |
{:x1 x :y1 y :x2 (parent :x2) :y2 (parent :y2)})) | |
(negative-space parent rs) |
On Understanding Data Abstraction, Revisited: http://www.cs.utexas.edu/~wcook/Drafts/2009/essay.pdf
CLU Reference Manual: http://publications.csail.mit.edu/lcs/pubs/pdf/MIT-LCS-TR-225.pdf
Semantics Engineering with Redex: https://mitpress.mit.edu/books/semantics-engineering-plt-redex
On Understanding Types, Data Abstraction, and Polymorphism: http://lucacardelli.name/Papers/OnUnderstanding.A4.pdf
Practical Foundations of Programming Languages: http://www.cs.cmu.edu/~rwh/plbook/book.pdf
-- in reply to http://www.reddit.com/r/haskell/comments/23uzpg/lens_is_unidiomatic_haskell/ | |
-- | |
-- What the lens library might look like if Getter, Setter, Fold, Traversal, | |
-- Lens, Review, and Prism were separate datatypes. | |
-- | |
-- For each optic, I only define enough combinators to explore pairs/sums | |
-- and lists of integers. Whenever possible, I reimplement the same | |
-- combinators and the same examples with all optics. | |
module IdiomaticLens where |
This is my short-ish tutorial on how to implement closures in | |
a simple functional language: Foo. | |
First, some boilerplate. | |
> {-# LANGUAGE DeriveFunctor, TypeFamilies #-} | |
> import Control.Applicative | |
> import Control.Monad.Gen | |
> import Control.Monad.Writer | |
> import Data.Functor.Foldable |