Skip to content

Instantly share code, notes, and snippets.

View vito's full-sized avatar

Alex Suraci vito

View GitHub Profile
blah
@vito
vito / gist:784020
Created January 18, 2011 05:26
regex planning
"123-456-hello" case-of: {
/(\d+)-(\d+)-(?<foo>\w+)/ ->
{ \0 print -- prints 123-456-hello
\1 print -- prints 123
foo print -- prints hello (\2 available too?)
} call
}
"123-456-hello" replace: /(\d+)-(?<foo>\w+)/ with: {
foo .. "-" .. \1
@vito
vito / gist:783933
Created January 18, 2011 03:29
atomo's regexp flags
-- standard Perl
toOpt 'm' = return compMultiline
toOpt 's' = return compDotAll
toOpt 'i' = return compCaseless
toOpt 'x' = return compExtended
-- additional
toOpt 'a' = return compAnchored
toOpt 'G' = return compUngreedy
toOpt 'e' = return compDollarEndOnly
[0]> { a = 1
.... @(a: a) print
.... a + 1
.... } call
@(a: 1)
2
[1]> 1 +
.... 2
3
[2]>
[0]> A = Object clone
<object (delegates to 1 object)>
[1]> B = Object clone
<object (delegates to 1 object)>
[2]> C = Object clone
<object (delegates to 1 object)>
[3]> A2 = Object clone
<object (delegates to 1 object)>
[4]> A2 = A clone
<object (delegates to 1 object)>
[0]> a x: b &c: 2 := a + b + c
@ok
[1]> 1 x: 2
5
[2]> 1 x: 2 &c: 3
6
[3]>
[0]> (a x: b &c: 2) := a + b + c
@ok
[1]> 1 x: 2
5
[2]> 1 x: 2 &c: 3
6
[0]> 0.28 rationalize
7/25
[1]> 0.28 rationalize: 0.1
1/3
[2]> 0.28 rationalize: 0.01
2/7
[3]> 0.28 rationalize: 0.001
7/25
[4]> 0.28 rationalize: 0.2
1/3
@(foo: a) matches @(foo: 2), binding a as 2
@(foo: 2) matches @(foo: 2)
@(foo: _) matches @(foo: 2)
@(foo: _) matches @(foo: _)
@(foo: a) SHOULD NOT MATCH @(foo: _) (I just checked, and it *does* match atm, but it doesn't bind a as anything)
@(foo: 2) DOES NOT MATCH @(foo: _)
~~> x = reference to x
=> = direct value
before:
Reference (~~> Object { oDelegates => [Value], oMethods => (MethodMap, MethodMap) })
- match, comparePrecision, etc. need to use unsafePerformIO to check delegates,
or be locked into the IO monad
- @join:/@do: needed to be careful with the target's delegates; they would make a dummy