Skip to content

Instantly share code, notes, and snippets.

View vito's full-sized avatar

Alex Suraci vito

View GitHub Profile
val ensuring: p do: b := {
res = b call: [val]
p call: [val]
res
} call
with-output-to: (fn: String) do: b :=
Port (new: fn) ensuring: @close do: { file |
with-input-from: file do: b
}
@vito
vito / 0-with-output-to.the.hs
Created August 8, 2010 17:10
file writing comparison: The, Scheme, Ruby
"writan to the terminal" print
with-output-to: "foo.txt" do: {
"writan to foo.txt" print
}
@vito
vito / gist:513433
Created August 8, 2010 01:29
dispatch object + pseudo lisp-style parameterization
$ the
> foo := dispatch sender x
> foo
message not understood: (<reference> x)
> x = 0
> foo
0
> { x = 42; foo } call
42
> x
@vito
vito / html.atomo.hs
Created August 7, 2010 21:38
a little HTML DSL in Atomo (incomplete)
HTML = Object clone
Association = Object clone
a -> b := Association clone do: { from = a; to = b }
Self-Closing = ["base", "meta", "link", "hr", "br", "param", "img", "area", "input", "col", "frame"]
-- creating elements with no content
-- keyword dispatch adds attributes
@vito
vito / dict.the.hs
Created August 5, 2010 03:42
Dictionaries implementing using blocks and delicious metaprogramming.
(b: Block) key: (v: Object) := {
find = { l |
l match: {
[] -> @nothing
(e . es) ->
if: (e values head evaluate == v)
then: { @(ok: (e values (at: 1) evaluate)) }
else: { find call: [es] }
}
}
import The.Haskell
load = do
"(x: Object) clone" =: do
Reference r <- getSymbol "x"
proto <- newProto $ \p -> p
{ vpDelegates = [r]
}
return (Reference proto)
(b: Block) in-scope :=
Object clone do: {
delegates-to: b
call := b scope do: b
call: vs := b scope do: b with: vs
}
> (x: Block) .. (y: Block) = Block new: (x contents .. y contents)
> {a = 1} .. {a + 1}
{a = 1; (a + 1)}
> ({a = 1} .. {a + 1}) evaluate do
2
> import: "prelude/expression.hs"
> Expression Block new
{}
> Expression Block new: []
{}
> Expression Block new: [1]
{1}
> Expression Block new: [1, 2]
{1; 2}
> Expression Block new: { a = 1; a + 2 } contents
@vito
vito / problem 1.the.hs
Created July 30, 2010 15:05
Project Euler solutions in The
problem-1: max = {
(0 ... max)
(filter: { n | 3 divides?: n || 5 divides?: n })
sum
} do
(problem-1: 1000) print