-
Notifications
You must be signed in to change notification settings - Fork 106
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Inconsistency between code&documentation of partition
.
#57
Comments
Probably the best bet is to update the documentation in order to avoid breaking code. Btw, |
Btw, the documentation also mentions
yet the parameter is a predicate. So this was probably caused by an incorrect copy/paste. |
It seems so: tarantool> function predicate(i, x) return i % 2 == 0 end
---
...
tarantool> predicate
---
- 'function: 0x40d2f9b0'
...
tarantool> range = fun.range(10)
---
...
tarantool> range
---
- state: 0
gen: 'function: 0x401ddf90'
param:
- 10
- 1
...
tarantool> fun.partition(predicate, range)
---
- state: 0
gen: 'function: 0x401e5ca0'
param:
- 'function: 0x40d2f9b0'
- 'function: 0x401ddf90'
- &0
- 10
- 1
- state: 0
gen: 'function: 0x401e5ca0'
param: &1
- 'function: 0x418b6e68'
- 'function: 0x401ddf90'
- *0
- *1
- 0
...
tarantool> g1, g2, state, param = fun.partition(predicate, range)
---
...
tarantool> g1
---
- state: 0
gen: 'function: 0x401e5ca0'
param:
- 'function: 0x40d2f9b0'
- 'function: 0x401ddf90'
- - 10
- 1
...
tarantool> g2
---
- state: 0
gen: 'function: 0x401e5ca0'
param:
- 'function: 0x407a15b8'
- 'function: 0x401ddf90'
- - 10
- 1
...
tarantool> state
---
- - 'function: 0x407a15b8'
- 'function: 0x401ddf90'
- - 10
- 1
...
tarantool> param
---
- 0
... It is not critical, but may be confusing. |
The same for tarantool> g1, param, state = fun.filter(function(x) return x % 3 == 0 end, fun.range(10))
---
...
tarantool> g1
---
- state: 0
gen: 'function: 0x41f93bc8'
param:
- 'function: 0x40551738'
- 'function: 0x41f877f8'
- - 10
- 1
...
tarantool> param
---
- - 'function: 0x40551738'
- 'function: 0x41f877f8'
- - 10
- 1
...
tarantool> state
---
- 0
...
|
luafun functions that returns generators also returns a param and state. It was not described in documentation, so patch fixes it. Closes luafun#57
I see, the change is mostly about replacing DefinitionsFirst, let's define Next, let's define CorrectnessOkay, so whether What would be incorrect? If we would say I would also highlight that describing a luafun iterator as Actual mistakesSure, I see, there are places, where such See, there is also the following sentence in the
It is the artifact of the old implementation as well. Return two iterators (what is okay)If we'll describe the Let's consider the following snippet first: tarantool> function x() return unpack({1, 2, 3}), unpack({'a', 'b', 'c'}) end
tarantool> x()
---
- 1
- a
- b
- c
... Here we return two triplets and, according to the Lua language rules, only the last one gives more than one value. Our iterators are triplets too! So the Return two iterators (actual mistakes)Not all persons who write on Lua so deep know it to keep all those multireturn details in the mind. Nicely, with luafun you usualy don't ever need to know about triplets and can consider the iterator as one value. Just use When we return one luafun iterator from a function, it also works with the tarantool> for i in fun.range(10):partition(function(i) return i % 2 == 0 end) do print(i) end
---
- error: 'builtin/fun.lua:544: attempt to call local ''gen_x'' (a nil value)'
... I think that we should add a recipe for those functions (a note in each of them, at least
(I use tarantool in examples, but it is better to adopt them to the luafun documentation style.) Footnotes
|
Documentation says that partition returns
{gen1, param1, state1}, {gen2, param2, state2}
, yet what is really being returned isgen1, gen2, param2, state2
.The text was updated successfully, but these errors were encountered: