Comments (10)
i have no idea where this comes from ^^
Offtoppic: can you explain me yield/generators?
For example, i don't understand why yield is needed here, for me it looks like its not even necessary..
<?php
function fib($n)
{
$cur = 1;
$prev = 0;
for ($i = 0; $i < $n; $i++) {
yield $cur;
$temp = $cur;
$cur = $prev + $cur;
$prev = $temp;
}
}
$fibs = fib(9);
foreach ($fibs as $fib) {
echo " " . $fib;
}
This here is just the same:
<?php
function fib($n)
{
$res = [];
$cur = 1;
$prev = 0;
for ($i = 0; $i < $n; $i++) {
$res[] = $cur;
$temp = $cur;
$cur = $prev + $cur;
$prev = $temp;
}
return $res;
}
$fibs = fib(9);
foreach ($fibs as $fib) {
echo " " . $fib;
}
from bettergen.
Notice: Undefined index: generation.level4.manager in phar://C:/Users/Administrator/Desktop/Server/MinecraftPE/WolvesFortressCSphp7/ClearSky-PocketMine-MP_1.6.2dev.phar/src/pocketmine/scheduler/AsyncTask.php on line 142
from bettergen.
I see... will fix this this evening.
from bettergen.
Oh actually i see now. it simply doesn't save an array to memory
from bettergen.
@thebigsmileXD There is an another difference, yield pauses the function execution and execute the code on the foreach (where you can send values back using the $gen->send() function).
Your code should look like this:
<?php
function fib($n) {
$cur = 1;
for ($i = 0; $i < $n; $i++) {
echo " " . $cur;
$cur += yield $cur;
}
}
$prev = 0;
foreach ($gen = fib(9) as $fib) {
echo " Foreach:" . $fib;
$gen->send($fib);
$prev = $fib;
}
This would output:
1 Foreach:1 2 2 Foreach:2 4 4 Foreach:4 8 8 Foreach:8 16 16 Foreach:16
from bettergen.
Uhh. What branch are you runing?
from bettergen.
Not sure, i guess.. master?
from bettergen.
Well on master, BetterNormal::$options is public. Try updating it maybe?
from bettergen.
Do anyone still get this bug or I can close it? I cannot reproduce it.
from bettergen.
👍
from bettergen.
Related Issues (20)
- Update Plugin.yml HOT 13
- CRITICAL - failed to open stream: No such file or directory HOT 4
- Alpha-7 Incompatible HOT 5
- Not Working for 1.2 (3.0.0-ALPHA9) HOT 11
- Add custom swamp biomes HOT 3
- Error. HOT 1
- Update ? HOT 6
- Issue : Could not execute asynchronous task PopulationTask
- Chest data packs folder not being created HOT 12
- Water and lava not falling after generation HOT 2
- No Console command check on world tp.
- Fix for ALPHA12
- Plugin crash when delBio option is specified HOT 1
- Update?!! 1.5. #1313 HOT 1
- how i can use this? HOT 5
- update? HOT 1
- Working on 3.5.7 HOT 1
- Poggit Orphanage Adoption HOT 1
- No Mesa Biom, Iglos, Dschungel?
- Not Working 2020 HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bettergen.