Skip to content
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

@yield all but last #13

Closed
davidavdav opened this issue Dec 7, 2017 · 1 comment
Closed

@yield all but last #13

davidavdav opened this issue Dec 7, 2017 · 1 comment

Comments

@davidavdav
Copy link

Hi,

This package fills a great omission in Julia (I don't understand why things can't be just as simple as in python---I get the impression that things are better and more general in Julia with tasks and coroutines, and even better things that outdate these, but I can't figure out how to use them).

However, here @yield should produce all but the last element, and last element should be the return value of the resumable function.

That is not handy.

Having julia have base-1 indexing is already not handy for many purposes, but then having to deal with the last element separately make code even hairier.

It would be great if @yield would just return all elements.

@davidavdav
Copy link
Author

Excuse me, I was mistaken.

The "better things that outdate these" are called Channels.

The proper method for a python-style generator function hence is

fibonacci(n) = Channel() do c
	a = 1
	b = 1
	for i in 1:n
		push!(c, a)
		a, b = b, a + b
	end
end

The problem, really, is finding this idiom when searching for generator julia.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant