[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Map and filter without intermediate tables
- From: Geoff Leyland <geoff_leyland@...>
- Date: Fri, 8 Jun 2012 09:36:28 +1200
On 8/06/2012, at 12:06 AM, joao lobato wrote:
> Things like list comprehensions, pattern matching as it exists in
> Haskell or Erlang, ...
So in rima, list comprehension seems like the only option, since nothing is mutable.
For example, if a, i and j are references (or placeholders) then you can*
a[i][j] = i * j
=eval(a[2][3])
6
=eval(a[1000][10000])
10000000
As you say, you can't break out of the implied for loop assigning to a[i][j] (a key problem for breaking out of the for loop is that the loop never happens)
You can tell current rima that such an index expression is restricted to a set, but it's only used in cases where you iterate over the set (not shown here), not to check bounds:
a[{i=I}] = 10
=eval(a[10000], {I={1,2,3}})
10 -- would hope that this was not defined since 10000 is not in [1,3]
Future-rima would like this, and more complex expressions, to work correctly. I tried using something like a case on the right-hand side of the assignment, but that sucked, so I'm aiming for things like:
a[{i=I,[i%2]=0}][{j<=i}] = i * j (**)
a[{i=I,[i%2]=1}][{j<=i}] = j^2
So, I guess I'm trying to evaluate options for implementing list comprehensions. One option is to try to emulate list comprehensions, another is to use intermediate tables.
*this code doesn't actually work, but it's clearer than code with all the bells and whistles that does work
**you can't actually use "<=" for this in lua because there's restrictions on overriding comparison operators