Created
August 9, 2012 15:03
-
-
Save jaytaph/3304967 to your computer and use it in GitHub Desktop.
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
hashes and lists and other data structures | |
------------------------------------------ | |
The current idea for shorthand notation: | |
lists: | |
[ 1, 2, 3, 4] | |
hash: | |
{ "foo":1, "bar":2, 3:"baz" } | |
problem: | |
{} is used to group statements, which makes it very hard to parse. | |
Solution #1: | |
lists: | |
[ 1, 2, 3, 4] | |
hash: | |
[ "foo":1, "bar":2, 3:"baz" ] | |
We can parse them correctly, since they don't interfere with compound statements, but what would this be: | |
$a = []; // hash or list? | |
Solution #2 | |
We provide a generic shorthand notation for datastructures: | |
<datastructure>[<values>] | |
hash["foo":1,"bar":2] | |
list[1,2,3,4] | |
set[1,2,3,4] | |
bloomfilter[1,5,5,6] | |
hash, list, set and bloomfilter are regular classes. | |
// Example 1: | |
if 5 in bloomfilter[1,2,3,4,5] { | |
io.printf("It might be here"); | |
} else { | |
io.printf("It's definately not here"); | |
} | |
// Example 2: | |
$a = list[1,2,3]; | |
$b = $a + list[4,5,6]; // $b = list[1,2,3,4,5,6] | |
// Example 3 | |
$a = set[1,2,3]; | |
$b = $a + set[1,3,4]; // $b = set[1,2,3,4] | |
// Example 4 | |
$a = list[1,1,1,2,3,3]; | |
$b = set[$a]; // $b = set[1,2,3] | |
$item = $b[0]; // fetch first index from set | |
$count = $b.length() // 3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment