This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns flp | |
"Function-level programming a la Backus; see | |
http://www.stanford.edu/class/cs242/readings/backus.pdf" | |
(:refer-clojure :exclude [/])) | |
;;; Functional Forms - combine existing functions to form new ones. | |
(def ^{:doc "Composition"} ° comp) | |
(defn / [f] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#lang racket/base | |
(provide current-struct-mappers | |
install-struct-mapper! | |
struct-map | |
struct-map/accumulator) | |
;; Parameter<Hash<StructType,Mapper>> | |
(define current-struct-mappers (make-parameter (hash))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Copyright 2012 Thomas Broyer <[email protected]> | |
* | |
* 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 | |
* | |
* Unless required by applicable law or agreed to in writing, software |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Object addTrait := method(obj, | |
resolutions := call evalArgAt(1) | |
if(resolutions isNil, resolutions = Map clone) | |
getSlot("obj") foreachSlot(name, value, | |
if(getSlot("self") hasLocalSlot(name), | |
if(name == "type", continue) | |
if(resolutions at(name) isNil, Exception raise("""Slot '#{name}' already exists in #{getSlot("self") type}[#{getSlot("self") uniqueId}]. Give it a new name in the map argument.""" interpolate)) | |
getSlot("self") setSlot(resolutions at(name), getSlot("value")) | |
continue |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import flask | |
import flaskext.script | |
default_config = { | |
} | |
def create_app(): | |
import views |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; Type annotation for seq, inspired by haskell | |
;; (+T <var> :- <interface/protocol>* => <classes>) | |
(+T clojure.core/seq :- (ISeq a) (ISeq b) => a -> b) | |
(+T clojure.core/seq :- (Seqable a) (ISeq b) => a -> b) | |
(+T clojure.core/seq :- nil -> nil) | |
(+T clojure.core/seq :- (Iterable a) (ISeq b) => a -> b) | |
(+T clojure.core/seq :- (PrimArray a) (ISeq b) => a -> b) | |
(+T clojure.core/seq :- (CharSequence a) (ISeq b) => a -> b) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Person | |
def initialize(name, age) | |
@name = name | |
@age = age | |
end | |
def set_name(new_name) | |
@name = new_name | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Compositional evaluator as visitor | |
import java.math.BigInteger; | |
// Syntax | |
interface Exp { | |
<X> X accept(Visitor<X> v); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var NodeList = function() {}; | |
var nodeListExtras = {x: 23}; | |
mixin(NodeList.prototype, Array.prototype, nodeListExtras); | |
function mixin(obj /*, mixins*/) { | |
var mixins = [].slice.call(arguments, 1); | |
for (var i=0; i<mixins.length; i++) { | |
var thisMixin = mixins[i]; | |
var props = Object.getOwnPropertyNames(thisMixin); | |
for (var j=0; j<props.length; j++) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- A simple definition without using any fancy functions. | |
haskell>let ifMaybe pred value = if pred value then Just value else Nothing | |
haskell>:t ifMaybe | |
ifMaybe :: (a -> Bool) -> a -> Maybe a | |
haskell>ifMaybe (const True) 2 | |
Just 2 | |
haskell>ifMaybe (const False) 2 | |
Nothing | |
-- Using functions from standard library. |