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 poney.world) | |
(defn hastalavistaify [xs] | |
(str "Hasta la vista " xs)) | |
(hastalavistaify "Thomas") ;;; Outputs : "Hasta la vista Thomas" | |
(map hastalavistaify ["Thomas" "poney" "mutability"]) ;;; Outputs : ("Hasta la vista Thomas" "Hasta la vista poney" "Hasta la vista mutability") |
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
;;; ClojureScript example from David Nolen's talk "ClojureScript : Lisp's revenge" | |
;;; https://www.youtube.com/watch?v=MTawgp3SKy8 | |
(defn capitalize [s] | |
(str (.toUpperCase (aget s 0)) | |
(.substring s 1))) | |
(defn keyword->property [k] | |
(let [[x & xs] (-> (str k) (.substring 1) (.split "-"))] | |
(apply str x (map capitalize xs)))) |
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
// Run the code with NodeJS | |
var Monet = require('monet'); | |
function getValue (obj, keysString) { | |
var keys = keysString.split('.'); | |
var curr = obj; | |
keys.forEach(function (key) { |
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
module Exercises where | |
import Data.Monoid | |
class (Monoid m) <= Action m a where | |
act :: m -> a -> a | |
instance repeatAction :: Action Number String where | |
act 0 _ = "" | |
act n s = s ++ act (n - 1) s |
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
combineMaybe :: forall a f. (Applicative f) => Maybe (f a) -> f (Maybe a) | |
combineMaybe (Just x) = pure <$> x | |
combineMaybe Nothing = pure Nothing |
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
module Exercises where | |
import Math | |
import Control.Monad.Eff.Random | |
import Control.Monad.Eff | |
import Control.Monad.ST | |
import Debug.Trace |
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
{- Non-working version -} | |
foreign import mapHRecLabel | |
"function mapHRecLabel(f, rec) {\ | |
\ var mapped = {};\ | |
\ for (var k in rec) {\ | |
\ if (rec.hasOwnProperty(k)) {\ | |
\ mapped[k] = f(k, rec[k]);\ | |
\ }\ | |
\ }\ | |
\ return mapped;\ |
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
{-# OPTIONS_GHC -Wall #-} | |
module HW04 where | |
newtype Poly a = P [a] | |
-- Exercise 1 ----------------------------------------- | |
x :: Num a => Poly a | |
x = P [0, 1] |
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
fibs2 :: [Integer] | |
fibs2 = 1 : 1 : zipWith (\a b -> a + b) fibs2 (tail fibs2) |
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 keypressed = Bacon.fromEvent(document.getElementById('text-editor'), 'keypress'); | |
var evaluatedString = keypressed | |
.filter(function (event) { return event.ctrlKey && event.charCode === 10; }) | |
.map(function (event) { return getSelection(event.target.value, event.target.selectionStart, event.target.selectionEnd); }) | |
.filter(function (value) { return !!value.trim(); }).log(); |
OlderNewer