Skip to content

Instantly share code, notes, and snippets.

View vito's full-sized avatar

Alex Suraci vito

View GitHub Profile
@vito
vito / main.hs
Created November 14, 2010 01:19
atomo zeromq wrapper
{-# LANGUAGE DeriveDataTypeable, QuasiQuotes, RankNTypes, StandaloneDeriving #-}
import Data.Typeable
import qualified Data.Text.Encoding as T
import qualified System.ZMQ as Z
import Atomo
import Atomo.Valuable
load :: VM ()
@vito
vito / gist:675620
Created November 13, 2010 20:37
block scoping
~ $ atomo
[0]> x = { a = 1; { a + 1 } } call
{ a + 1 }
[1]> x call
2
[2]> a = 100
100
[3]> x call
2
[4]> x context
@vito
vito / gist:675578
Created November 13, 2010 19:45
atomo insertion-sort
~ $ atomo
[0]> (y . ys) insert: x by: pred := if: (pred call: [x, y]) then: { x . y . ys } else: { y . (ys insert: x by: pred) }
@ok
[1]> [] insert: x by: _ := [x]
@ok
[2]> [] insertion-sort: _ := []
@ok
[3]> (x . xs) insertion-sort: pred := (xs insertion-sort: pred) insert: x by: pred
@ok
[4]> [5, 3, 10] insertion-sort: @<=
@vito
vito / gist:665636
Created November 6, 2010 19:15
repl environment
atomo $ atomo
[0]> this
<object (delegates to 1 object)>
[1]> [x, y] = [1, 2]
[1, 2]
[2]> this
<object (delegates to 1 object)>
x := 1
y := 2
[3]>
@vito
vito / gist:665628
Created November 6, 2010 19:05
repls all the way down
atomo $ atomo
[0]> 2 repl
[0]> + 2
4
[1]> * 3
6
[2]>
really quit? (y/n) y
@ok
[3]>
@vito
vito / gist:665158
Created November 6, 2010 03:12
pretty errors
atomo $ rlwrap atomo repl.atomo
[0]> 1 +
------------------------------------------------------------------------------
*** parse error:
*** "<input>" (line 1, column 3):
*** unexpected '+'
*** expecting end of input
restarts:
0: @retry
@vito
vito / cond-test.atomo.hs
Created November 5, 2010 05:23
condition comparison (atomo vs. lisp)
test =
{ { res = { error: @foo } with-restarts: { @use-value -> { r | r } }
res .. "?"
} with-restarts: {
@use-value -> { r | r }
}
} bind: {
Error -> { e | restart: @use-value with: [e show .. "!"] }
}
@vito
vito / gist:660645
Created November 3, 2010 01:09
atomo repl in atomo
_ evaluate-all: [] := error: @no-expressions
t evaluate-all: [e] := e evaluate-in: t
t evaluate-all: (e . es) :=
{ e evaluate-in: t
t evaluate-all: es
} call
(s: String) go: env :=
s parse-expressions match: {
[] -> @ok
@vito
vito / gist:643868
Created October 24, 2010 19:24
(un)quote
> `(x = { a = ~(2 + 2); a . [1 + ~(42 / 5)] })
<expression x = { a = 4; a . [1 + 8] }>
> `(x = { a = ~(2 + 2); a . [1 + ~(42 / 5)] }) evaluate
{ a = 4; a . [1 + 8] }
> x call
[4, 9]
>
@vito
vito / 0-json.hs
Created October 16, 2010 17:18
less-quick-and-dirty JSON
{-# LANGUAGE QuasiQuotes #-}
import Atomo.Environment
import Atomo.Haskell
import Atomo.Method
import Atomo.Valuable
import Text.JSON as JSON
load :: VM ()