On 03/07/2012, at 4:18 PM, john skaller wrote:
> Ouch .. something I didn't think of: with a compact representation
> of types like 3 * 2 in a single integer .. the components aren't addressable.
> And so not assignable in principle. Same deal as bitfields in C.
>
> I can fudge it in some cases with a read/modify/write.
I love fudge! Observe below, we can now assign to a linear tuple.
The triple loop indicates that the current linear order makes the
first index move most quickly. It's not instantly clear if this is
arbitrary, correct, cleanest, expected, etc etc.
If you consider an array of arrays:
var a = (
(1,2,3), // row 1
(4,5,6), // row 2
(7,8,9) // row 3
);
then a . i first selects a row, then a . i . j selects a column in the row.
To get the elements in the order 1-9 you would advance j most
quickly in an inner loop. This is the *opposite* of the current ordering.
However note in prefix form:
j (i a)
the j comes first (even though i is applied first).
Please note this is still a step towards generalised array handling.
It's still not complete by any means!
/////////////////////
fun ==: 3 * 3 -> bool = "$1==$2";
fun ==: 4 * 4 -> bool = "$1==$2";
fun ==: 5 * 5 -> bool = "$1==$2";
var i : 3 = case 1 of 3;
var j : 4 = case 2 of 4;
var k : 5 = case 3 of 5;
var ijk : 3 * 4 * 5 = i,j,k;
fun str (x:3*4*5) => (x :>> int) . str;
fun str (x:3) => (x :>> int) . str;
fun str (x:4) => (x :>> int) . str;
fun str (x:5) => (x :>> int) . str;
println$ "ijk=" + str ijk;
println$ ijk . 0 .str;
println$ ijk . 1 .str;
println$ ijk . 2 .str;
assert ijk . 0 == i;
assert ijk . 1 == j;
assert ijk . 2 == k;
assert ijk . 0 :>> int == 1;
assert ijk . 1 :>> int == 2;
assert ijk . 2 :>> int == 3;
for var kk in 0 upto 4 do
k = kk :>> 5;
for var jj in 0 upto 3 do
j = jj :>> 4;
for var ii in 0 upto 2 do
i = ii :>> 3;
ijk = i,j,k;
println$ ijk.0.str + "," + ijk.1.str + "," + ijk.2.str+" encoding=" +
(ijk :>>int) .str;
done
done
done
println$ str ijk;
ijk.1 = case 2 of 4;
println$ str ijk;
/////////////////////////////////
Handling coercion in egen 3 * 4 * 5 -> int
ijk=43
1
2
3
0,0,0 encoding=0
1,0,0 encoding=1
2,0,0 encoding=2
0,1,0 encoding=3
1,1,0 encoding=4
2,1,0 encoding=5
0,2,0 encoding=6
1,2,0 encoding=7
2,2,0 encoding=8
0,3,0 encoding=9
1,3,0 encoding=10
2,3,0 encoding=11
0,0,1 encoding=12
1,0,1 encoding=13
2,0,1 encoding=14
0,1,1 encoding=15
1,1,1 encoding=16
2,1,1 encoding=17
0,2,1 encoding=18
1,2,1 encoding=19
2,2,1 encoding=20
0,3,1 encoding=21
1,3,1 encoding=22
2,3,1 encoding=23
0,0,2 encoding=24
1,0,2 encoding=25
2,0,2 encoding=26
0,1,2 encoding=27
1,1,2 encoding=28
2,1,2 encoding=29
0,2,2 encoding=30
1,2,2 encoding=31
2,2,2 encoding=32
0,3,2 encoding=33
1,3,2 encoding=34
2,3,2 encoding=35
0,0,3 encoding=36
1,0,3 encoding=37
2,0,3 encoding=38
0,1,3 encoding=39
1,1,3 encoding=40
2,1,3 encoding=41
0,2,3 encoding=42
1,2,3 encoding=43
2,2,3 encoding=44
0,3,3 encoding=45
1,3,3 encoding=46
2,3,3 encoding=47
0,0,4 encoding=48
1,0,4 encoding=49
2,0,4 encoding=50
0,1,4 encoding=51
1,1,4 encoding=52
2,1,4 encoding=53
0,2,4 encoding=54
1,2,4 encoding=55
2,2,4 encoding=56
0,3,4 encoding=57
1,3,4 encoding=58
2,3,4 encoding=59
59
56
///////////////////////////////
--
john skaller
[email protected]
http://felix-lang.org
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Felix-language mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/felix-language