Text
λf(λy(yy))(λz(f(zz)))
Text
I am bad at Rust. This is super wrong, but at least I got something working!
enum List { Cons(uint,Box), Nil}

fn push(v:uint, l:List) -> List { Cons(v,box l) }
fn clear(l:List) -> List { Nil }
fn pop(l:List) -> List {
  match l {Nil=>Nil, Cons(_,box next)=>next}}

// fn forEach() {}

fn len(l:List) -> uint {
  let mut result = 0;
  let mut e = l;
  loop {
    match e {
      Nil => break,
      Cons(_,box next) => { result+=1; e=next }}};
  result }

fn main() {
  let mut v = Nil;
  v = Cons(3,box v);
  v = Cons(4, box Cons(3,box v));
  v = push(3,v);
  v = push(2,v);
  v = push(1,v);
  v = pop(v);
  println!("{}", len(v))
  // v = clear(v);
  // println!("{}", len(v))
}
Text
Wanted to code for 30m, so I wrote a mutable, singly-linked list library in Coffeescript without using this, closures, or objects. Next step? Write this in my favorite languages: Haskell, Rust, and Lua. I want to build up a library of data structures in those languages, and benchmark them.
trace = (x) -> console.log(x); x


# type Ptr a = [a]
Ptr = {}
Ptr.mk = (v) -> [v]
Ptr.get = (p) -> p[0]
Ptr.set = (p,v) -> p[0] = v; null


# type List a  = null | {value:a, next:List a}
# List.fromVector([]) = [null]
# List.fromVector([1]) = [{value:1, next:null}]
# List.fromVector([2,1]) = [{value:2, next:{value:1, next:null}}]
List = {}

# mk :: () → Ptr(List a)
List.mk = () ->
  Ptr.mk(null)

# insert :: (Ptr(List a), a) → ()
List.push = (list,v) ->
  Ptr.set(list, {value:v, next:Ptr.get(list)})
  null

# clear :: (Ptr(List a)) → ()
List.clear = (list) ->
    Ptr.set(list, null)
    null

# (Ptr(List a)) → a | null
List.pop = (list) ->
    return null if null == Ptr.get(list)
    v = Ptr.get(list).value
    Ptr.set(list, Ptr.get(list).next)
    v

# fromVector :: ([a]) → Ptr(List a)
List.fromVector = (arr) ->
    result = List.mk()
    for i in [arr.length-1..0] by -1
        List.push(result, arr[i])
    result

# forEach :: (a→b,Ptr(List a)) → null
List.forEach = (f,list) ->
    e = Ptr.get(list)
    while e
        f(e.value)
        e = e.next
    null


trace "### fromVector, forEach ###"
List.forEach(trace, List.fromVector([3,4,5]))

trace "### mk, push, pop ###"
l = List.mk()
for i in [3..1]
  List.push(l,i)
for i in [0...4]
 trace(List.pop l)

trace "### clear ###"
l = List.fromVector([3,4,5])
List.clear(l)
trace(l)
Photoset

salmon

Tags: project food
Text

Issues so far in my shell-scripting language in Haskell: getLine ignores ^D, and my combination of haskeline/executeFile/getProcessStatus is causing Segfaults when I run my program within ghci.

Fixes: don’t use ghci with this program, and use Haskeline instead of getLine.

Text
Shitty beginnings of a shell REPL in Haskell.
{-# LANGUAGE OverloadedStrings, UnicodeSyntax, NoImplicitPrelude #-}

import Control.Arrow
import qualified Data.Text as Text
import Data.Functor
import ClassyPrelude
import System.Posix.Process
import System.Exit
import System.Console.Haskeline

parseCmd = Text.split (==' ') >>> Just

runMaybe = fromMaybe $ return ()

executeFileText a b c d = executeFile (unpack a) b (unpack <$> c) d

runCmd [] = return ()
runCmd (exec:args) = do
  pid ← forkProcess $ do
    executeFileText exec True args Nothing
    exitImmediately (ExitFailure 1)
  getProcessStatus True False pid
  return ()

repl = do
  minput ← getInputLine "(bs)# "
  runMaybe $ do
    input ← minput
    cmd ← parseCmd $ pack input
    return $ do
      liftIO $ runCmd cmd
      repl

main = runInputT defaultSettings repl
Photo
Got a bike! $150! Jessica’s been showing me how to get around in the city. She’s crazy.

Got a bike! $150! Jessica’s been showing me how to get around in the city. She’s crazy.

Tags: journal pic bike
Photoset

Got a room in the Castro.

Tags: journal pics
Text

I’ve been working for Yo for 3 weeks now, and I’m working 60-80 hour weeks. I like it, but it’s very stressful, and I have almost no free time.

Tags: journal
Text

I ran 1.5 miles at a pretty aggressive pace today! I’ve been running every day for a while now, and it’s pretty wonderful. I started with an easy half mile, and slowly built up to 1.5 miles. Once I build up to a daily 5k, I’m hoping to start working on my pace.

I’ve been settling into a routine that I’m very happy with. I get up around 9, work for around 5 hours, take a nap, work out, do a bunch of chores, and then do whatever for the rest of the day. One of the benefits of this routine is that I can eat while I work and after exercise, but still fast for 8 hours at the end of my day.

Tags: journal
Video

I’ve been using this keyboard for about a month, and this video blew my mind. He uses both thumbs!

Link
Tags: coding haskell
Photo
johnmaynardkanyes:

First four series of a sawtooth wave.

johnmaynardkanyes:

First four series of a sawtooth wave.

(Source: spookynomics, via vrgtms)

Text

https://github.com/riccieri/rust-project_euler/tree/master/

Text

Back Injury

I strained my back about 6 months ago, and it’s never really healed. Sometimes it doesn’t bother for a while, but it always comes back. Basically, it hurts to bend over, sometimes it hurts to run, and I can’t do heavy deadlifts or deep squats without re-straining it.

I did a bunch of research, and I learned:

  • Core strength helps a lot.
  • Lack of hamstring flexibility causes a lot of back strain.
  • Being overweight is really bad for my back.
  • Sitting in the same position for long periods is bad.
  • Having poor posture is bad.
  • Sleeping on your stomach is bad.

So! for the time being, I’m going to replace my daily lifting routine with:

  • 3x5 slow/light deadlifts
  • 3 sets of sit-ups
  • hamstring stretching.