blk是什么意思| 高利贷是什么意思| 眼睛大小不一样是什么原因| 满是什么结构| 27度穿什么衣服合适| 蛋白粉什么味道| 啮齿类动物什么意思| 焦虑症吃什么好| 企业背书是什么意思| 弄虚作假是什么生肖| 仔字五行属什么| 制片人是什么意思| 乙肝病毒表面抗原阳性是什么意思| 老鼠爱吃什么食物| 什么属于包皮过长| 霖字五行属什么| 梦见亲人死了是什么意思| 孕早期头疼是什么原因| 痛风吃什么食物好| 佛跳墙是什么菜| 四大美女指什么生肖| 梅花什么季节开| 做梦梦见搬家是什么意思| 烟雾病是什么| 浪子是什么意思| 沼气是什么| vsop是什么意思| 持续耳鸣是什么原因引起的| 殖民地是什么意思| 解惑是什么意思| 苹果煮水喝有什么好处和坏处| 唇钉是干什么用的| 情有独钟是什么意思| 脖子长小肉粒是什么原因| 茁壮的什么| 三岁属什么生肖| 嬴政和芈月是什么关系| 质感是什么意思| 香蕉和什么一起吃能减肥| 那悲歌总会在梦中惊醒是什么歌| 盐是什么味道| 左肺下叶钙化灶是什么意思| 心血管科是看什么病| 蛋白糖是什么糖| 前列腺增大钙化是什么意思| 缓刑是什么意思还要坐牢吗| 刘欢属什么生肖| 渡情劫是什么意思| gln是什么意思| 肚子胀气老放屁是什么原因| 吃东西就吐是什么原因| 蕾字五行属什么| 伽是什么意思| 私奔什么意思| 碳14呼气试验阳性是什么意思| 肚子有硬块是什么原因| c2可以开什么车| 梦见玉碎了是什么意思| 车水马龙什么意思| 酒品是什么意思| 贫血的人来姨妈会有什么症状| 甲状腺是什么科| 大红袍茶属于什么茶| 道心是什么意思| 六月十六什么星座| 拔罐为什么会起水泡| 为什么上小厕会有刺痛感| 什么立什么群| 吃什么东西能通便| 万事达卡是什么卡| 男性生殖器叫什么| 卵巢过度刺激综合症是什么| 党委副书记是什么级别| 才下眉头却上心头是什么意思| 老夫聊发少年狂什么意思| 急性胃肠炎用什么抗生素| 什么生日的人有佛缘| 梦见房屋倒塌是什么征兆| 茉莉茶叶有什么功效和作用| 莀字五行属什么| 脚后跟疼是什么原因引起的| 痔疮的表现症状是什么| 什么是跳蛋| 痔疮和肛周脓肿有什么区别| 健康证都查什么传染病| 干巴爹什么意思| 男士补肾吃什么| 拔完火罐要注意什么| 狐狸吊坠有什么寓意| 大校相当于政府什么官| 平和是什么意思| 让心归零是什么意思| 割包皮应该挂什么科| 女性脂肪率偏高说明什么| 维生素b12治什么病| 农历正月初一是什么节日| 什么叫疝气| 什么冰淇淋最贵| 虾不能和什么食物一起吃| 彷徨是什么意思| hpv59阳性是什么意思| 身上长红点很痒是什么原因| 刘强东属什么生肖| 脂蛋白a高是什么原因| 眼睛红肿是什么原因引起的| 吃什么可以拉肚子| 淋巴细胞升高说明什么| 男性尿道疼痛小便刺痛吃什么药| 脑白质疏松是什么意思| 相亲为什么不能拖太久| 咳嗽能吃什么| 尿酸高注意什么| 痔疮是什么意思| 耿直什么意思| 备孕检查什么项目| 海椒是什么辣椒| 大自然是什么意思| 粳米是什么米| 六块钱麻辣烫什么意思| 胃低分化腺癌是什么意思| 心脏早搏是什么原因造成的| 肌腱属于什么组织| 氟西汀什么意思| 脂肪肝有什么危害| 长黑斑是什么原因引起的| 农历正月是什么星座| 捐精有什么要求| 什么叫翡翠| 莫名其妙的名是什么意思| 刺猬为什么叫白仙| 牙痛吃什么药最有效| 白发多吃什么可以改善| 皮疹是什么| 气血不足吃什么补得快| 宁波有什么特产| husky是什么牌子| 牙龈肿痛上火吃什么药最好| 在农村做什么生意好| 告示是什么意思| 廿二是什么意思| 胃火大吃什么药效果好| 为什么运动完会恶心头晕想吐| bf是什么牌子| 反流性食管炎b级是什么意思| 怀孕的最佳时间是什么时候| 12月是什么月| 原本是什么意思| 侬是什么意思| 过期牛奶有什么用途| 梦见女婴儿是什么意思| 服装属于五行什么行业| 吐奶严重是什么原因| 中药什么时间喝效果最好| 处男什么意思| 西汉后面是什么朝代| 纤支镜主要检查什么| 睾丸扭转是什么意思| 什么是四环素牙| 阴蒂长什么样| 拜忏是什么意思| 买李世民是什么生肖| 男人左眼下有痣代表什么| 内心os是什么意思| 尿频是什么症状| ca医学代表什么意思| 湖水蓝是什么颜色| 114514是什么梗| 大腿抽筋是什么原因引起的| 阻生智齿是什么意思| 占便宜是什么意思| 网络cp是什么意思| 澳门回归是什么时候| 吃什么水果减肥| 1920年属什么生肖| 疙瘩是什么意思| 什么菊花茶降火最好| 什么是cosplay| 白月光是什么意思| 血脂高吃什么食物好| 经血逆流的症状是什么| 什么食物不能一起吃| 丹参有什么作用| 神经性皮炎不能吃什么食物| 7月1号是什么星座| 猪肝有什么功效| 肚子左侧疼是什么原因| 黄瓜含有什么营养成分| 11月份生日是什么星座| 正山小种属于什么茶类| 16周检查什么项目| 辛巳五行属什么| 什么是鼻窦炎| 宫内小囊是什么意思| 掉头发是什么原因| 女人性冷淡是什么原因| 木林森是什么品牌| 保险费率是什么| 高压氧是什么| 新癀片主要治什么病| aj和nike什么关系| 镜子碎了有什么征兆吗| 金银花有什么功效| castle是什么意思| 2月30日是什么星座| 高原反应有什么症状| 意淫什么意思| 妈妈生日送什么礼物| 呜呼哀哉什么意思| 吃桑葚有什么好处| 唐僧叫什么| 晚上九点是什么时辰| 腹泻吃什么药最好| 预拌粉是什么东西| 梦到蜈蚣是什么意思| 茯苓生长在什么地方| 胰腺的作用和功能是什么| 空囊是什么原因造成的| 出汗太多吃什么药好| 子宫什么样子图片| 人为什么要死| 胆囊结石用什么药好| 夜盲症缺什么| 鱼刺卡喉咙挂什么科| 72年属鼠是什么命| 小米长什么样| 拍黄瓜什么意思| 血小板低是什么原因引起的| 梦见抓蛇是什么预兆| 脑供血不足会导致什么后果| 拉肚子后吃什么食物好| 1882年属什么生肖| 左前支阻滞吃什么药| 安然无恙的恙是什么意思| 四十年是什么婚| 上火吃什么水果好| 咽炎吃什么药最有效| 摆渡人什么意思| 第57个民族是什么民族| 猫眼石是什么| 感冒咳嗽一直不好是什么原因| 摩卡棕是什么颜色| 小肚子疼是什么情况| 尿检潜血是什么意思| 刀模是什么| 鹿角粉有什么功效和作用| 打呼噜是什么原因造成的| 现充什么意思| 吐露是什么意思| pr过高是什么意思| 玉和翡翠有什么区别| dsa检查是什么| 小孩记忆力差是什么原因| 肠溶片是什么意思| 摩羯座喜欢什么样的女生| 证过二是什么意思| 肾阴虚吃什么| viomi是什么牌子| 硬结灶是什么意思| pinky是什么意思| 大便带血丝是什么原因| 甘胆酸是查什么的| 总胆汁酸高说明什么| 蟑螂的天敌是什么| 后厨是做什么的| 百度

阿里系数澜科技成立半年获两轮融资的秘诀是什么?

Latest comment: 8 years ago by 75.73.1.89 in topic Fuzzy definition?

Origin of the concept

edit
百度   提升从业人员素质。

The article claims that generator were invented in Sather, but they date back significantly further. Jeremy Hylton gives a short historical overview. I could track them down as far as:

I couldn't find enough information about Alphard and IPL-v to know how they compare to later conceptions of generators. --Piet Delport 13:55, 7 November 2005 (UTC)Reply

Changed article to say CLU instead of Sather. CLU iterators are clearly generators. Not sure about Alphard. From Ms Liskov's article it sounds like Alphard didn't have yield. But regardless, the new page is at least marginally more accurate.  ;) Jorend 23:01, 5 January 2006 (UTC)Reply

Generators in Icon

edit

Icon has had generators since I believe it's initial public implementation. The 1st edition of the book "Icon Programming Language" by Griswold and Griswold, Prentice-Hall 1983, states in the preface.

"... It is worth noting here that a number of other programming languages have constructions called generators. CLU [5] is an example. In most languages, however, generators are confined to particular operations on certain kinds of values. In Icon, generators are completely general and may occur in any computation. Generators in themselves lend conciseness and expressive power. ... CheyenneWills 21:17, 12 December 2005 (UTC)Reply

If i'm not mistaken, Icon was quite influential in terms of popularizing generators. If so, it definitely deserves a good mention in the article. Tangentially: i get the impression that Icon's generator support goes hand in hand with its backtracking support; how much does this influence the "flavor" of Icon's generator use, compared to other languages that don't natively support backtracking? --Piet Delport 13:35, 13 December 2005 (UTC)Reply
I believe that you are correct. As for the influence of the "flavor", I believe that the use of generators in Icon can be broken down into 2 main areas, the first is the pure generation of "things", such as all the elements of a list
every write(!biglist)
The second is within the confines of backtracking where alternatives are required. (here the find function is a generator). In this situation, string pattern matching relies heavily on generators
if find("i",string) = (3 | 10) then ...
One of the other interesting areas is preserving the state of a generator by using Icon's coexpressions. The usual example is generating labels.
label := create "L" || seq()
...
newlabel := @label
nextlabel := @label
...
where newlabel would be assigned L1 and nextlabel would get L2 (assuming the first and second invocations of the coexpression). CheyenneWills 18:53, 13 December 2005 (UTC)Reply

Other languages implementing generators

edit

(excluding languages which can implement generator functionality (via more general support for continuations or coroutines), but don't really support them as a native idiom)

Generators versus continuations

edit

I've backed out this recent edit that introduces the wording "[Generators can be thought of as containing] a continuation (a programming language structure which can be thought of as a "frozen stack frame")". It was well-intended (thanks!), but a bit misleading, as generators and continuations are quite different. Tim Peters wrote a most excellent impromptu essay on generators, coroutines and continuations, and how they compare, but i'll attempt to summarize here:

  • While a generator contains a single stack frame, a continuation contains a complete call stack.
  • Invoking a generator resumes it on top of its caller's stack, and suspending/returning from the generator resumes the caller again (working almost exactly like normal function calls, in both cases (which is why generators are often explained as "resumable functions")). Invoking a continuation, on the other hand, is like discarding the old call stack entirely, and replacing it with the one stored in the continuation (with no way to return to the "caller", unless its stack was previously saved as another continuation).

--Piet Delport 16:54, 12 February 2006 (UTC)Reply

Poor choice of example code

edit

The generator code is recursive!!! In order to use the example to confirm my understanding of how a generator works is correct, I must first correctly understand ... generators! Clearly, that's a problem!

Could someone please provide a non-recursive example of the code, preferablely with a comment that describes what the expected mathematical outcome should be (ie. which mathematical "sum" is being calculated?). In that way, the reader can confirm for themselves that their understanding of the code matches the author's intent; and that their understanding of generators is therefore correct.

Right now, I *think* I understand what the code does, but since it doesn't include comments and I don't have a python compiler in front of me, I can't be sure that I've got it right... —Preceding unsigned comment added by 216.254.142.195 (talk ? contribs) 2025-08-06 19:13

I agree, the example is nearly uselessly opaque. I replaced it with an infinite incrementing integer sequence generator (it's not as scary as its name :), which hopefully neatly illustrates generators' laziness and statefulness. What do you think? --Piet Delport 14:13, 30 June 2006 (UTC)Reply
That's much better! Thank you! :-)

Just to provide another example in Icon... (using the same "logic" as the python code)..

procedure countfrom(n)
repeat {
    suspend n
    n +:= 1
}
end

# Example use: printing out the integers from 10 to 20.
# Note that this iteration terminates normally, despite countfrom() being
# written as an infinite loop.

every i :=  countfrom(10) do {
    if i <= 20 then
        write(i)
    else
        break
}

Another popular example is a generator for the Fibonacci sequence

procedure fibseq()
    local i, j, n
    i := 1
    j := 1
    suspend (i |              # Generate the 1st value
             j |              # Generate the 2nd value
             |{               # Repeatedly generate the next values
                n := i + j    # This value is returned
                i := j        # i and j to the "next" value
                j := n                           
               } )
end   

...
every write(|fibseq() \20)         # Will generate the first 20 numbers of the fibonacci sequence

CheyenneWills 05:20, 28 November 2006 (UTC)Reply

The Generator expression example for Icon can be simplified and does not require a co-expression.

 local j
  every j := (|seq(0) \ 20) ^2 do  # Produced the first 20 squares
     write(j)

If the idea is to demonstrate really what Icon can do in terms of using generators outside a loop construct, the following may be a better example

# find the first matching element
a := [1,2,3,4]
b := [5,6,2,7]
c := ( !a = !b ) | &null   # assign first matching element, or set to &null

CheyenneWills (talk) 20:01, 16 June 2010 (UTC)Reply

Generator in Ruby

edit

Piet - why do you think that Ruby does not support generators (iterators) directly?

#!/usr/bin/ruby
#
def countdown(n)
  while n>=0
    yield n
    n-=1
  end
end

countdown(10) { |count|
  print "#{count}\n"
  print "Ignition!\n" if count==3
  print "Liftoff!\n"  if count==0
}

IMHO, unless I am required to "include" or "use" or "import" something to work with a functionality, it is supported by the language. I'd vote for including Ruby to the list of languages that support generators aka iterators. If you'd not have removed ruby twice from the language list I would simply insert it, but let's discuss this. --The emm 15:21, 29 August 2006 (UTC)Reply

What's happening in the Ruby example is that you're creating and passing a block into countdown, which calls it for each value produced, and returns once at the end. Translated to Python (with some decorator syntax abuse), this would look more or less like:
from functools import partial

@partial(partial, partial)      # curry countdown
def countdown(n, block):
    while 0 <= n:
        block(n)
        n -= 1

@countdown(10)
def receive(count):
    print count
    if count == 3: print 'Ignition!'
    if count == 0: print 'Liftoff!'
By contrast, generators are called, and return/yield to their caller (which might be somewhere different each time), once for every value they produce. This means they can yield infinite sequences, and be composed together, passed around, and partially consumed, without worry. To try and illustrate:
def count():
    """Generate all the natural numbers."""
    n = 0
    while True:
        yield n
        n += 1

def divisible(seq, n):
    """Yield all items from seq that are divisible by n."""
    for x in seq:
        if x % n == 0:
            yield x

>>> evens = divisible(count(), 2)

>>> from itertools import islice
>>> list(islice(evens, 5))        # pull 5 items from evens
[0, 2, 4, 6, 8]

>>> for n in evens:
...     if n < 20:
...         print n,
...     else:
...         break
... 
10 12 14 16 18
>>> 
--Piet Delport 12:28, 30 August 2006 (UTC)Reply
Iterators, generators and coroutines seem to be related but different. The coroutine article mentions: "Coroutines in which subsequent calls yield additional results are often known as generators." Is that the right way to define what a generator is? The article also has a link to a Japanese page about coroutines in Ruby. --TuukkaH 13:55, 30 August 2006 (UTC)Reply
That's probably not entirely inaccurate, but it should be understood that, generally speaking, coroutines are a superset of generators. (A generator is more-or-less a suspendable/resumable stack frame; a coroutine is more-or-less a suspendable/resumable call stack.) --Piet Delport 19:21, 30 August 2006 (UTC)Reply

Python primes generator contributed by banned user

edit

It was contributed by User:PWnsivander the Great, who, while a nonobjectionable user, was blocked by User:Rspeer as a reincarnation of (unjustly, in the opinion of most of the board) banned user Mike Church. Shouldn't it, as the contribution of a banned user, be removed? Sentinel89 06:07, 13 March 2007 (UTC)Reply

I would say no. The content should be judged on it's own merits regardless of any activity involving the user who initially contributed it. I've reviewed the code and see nothing wrong with it, and in fact believe it to be an great example for demonstrating Python generators (in terms of ease of understanding, not necessarily efficiency). My only hesitation would be the policy of WP:BAN, in that if these edits were made while the user was banned, then perhaps they could be reverted. But the policy doesn't say such edits have to be reverted, only that they may be. So I believe the content in this case is good enough to keep. Dmeranda 16:56, 16 March 2007 (UTC)Reply
I agree, the quality of the content overrules the character of the contributor. However, the Python example's prime number generator is beyond me. In particular, the line "if not any( n % f == 0 for f in p ):" uses the variable "f" which is never created in the code. Any help?

dblanchard (talk) —Preceding undated comment added 16:22, 5 October 2009 (UTC).Reply

Hi, the code within the brackets of the call to any is itself a generator expression. It iterates through p, the list of primes so far, assigning each to f and returns the value of n %f == 0 for each iteration.So it could be read colloquially as:
  "if there are not any instances of a multiple of already found primes in n"
--Paddy (talk) 17:06, 5 October 2009 (UTC)Reply

Fuzzy definition?

edit

Coming from the STL, I find this definition quite fuzzy. Mixing generators and iterators seems strange, as I saw them serve different purposes:

  • generators are functions with no argument and returning an object, and are not referentially transparents
  • iterators are objects whose designate an element within a collection, and whose methods allow to access that element or designate another one, according to the access mode of the collection

Nowhere man 09:53, 24 April 2007 (UTC)Reply

First of all, generators and iterators do have separate articles, specifically because they are not the same thing. However the external behavior of generators does share a lot in common with that of iterators, so it is worth discussing on this article. Note also that the C++/STL concept of an iterator is much richer and more specialized that the general concept of iterator; so the difference between the two will appear much more pronounced if you have a C++ perspective. It may make it easier to realize that a generator is basically an iterator over a collection; it's just that the collection happens to be algorithmically defined rather than having to physically exist in a memory-resident data structure. Also generators in as much as they act like iterators only support the most Allfundamental behavior; referencing the current element and getting to the next one (although the next function is implicit); it by no means acts like many rich C++-style iterators with all their additional behaviors. -- Dmeranda 16:25, 24 April 2007 (UTC)Reply
OK, generators and iterators do have similarities, but the following text has no justification: "Generators are usually invoked inside loops. The first time that a generator invocation is reached in a loop, an iterator object is created that encapsulates the state of the generator routine at its beginning, with arguments bound to the corresponding parameters." Where does that come from? I never saw an iterator created when using a generator, be it in C++ or nay other language I use.
There are a lot of generators that are not meant to be used in loops, like random or prime numbers generators.
Also, generators' purpose is not to control loops. They are not to be mistaken as some sort of functional control structure! Nowhere man 18:50, 24 April 2007 (UTC)Reply
Yes, that quoted sentence is perhaps misleading in that it implies a specific implementation of generators, using iterators, which doesn't necessarily have to be true. Note though as an example, in the Python language, invoking a generator function does in fact create a real iterator object (it has a next() method, and raises a StopIteration error when/if the generator terminates). But it's not fair to say that just because that's how Python does it that it is how all languages must do it. As far as other types of generators, yes there are undoubtedly a lot of them. Most fall into the more casual use of the Engligh word generator, as in something that produces something else. Many of these are listed on the Generator (disambiguation) article. It probably would be worthwhile to put a little reference to these other types someplace. In terms of the specific type of generator discussed in this article (which is iterator-like), use in loops is quite common. Although a prime number generator or random number generator could be implmented as an interator-style generator, they don't have to be as you pointed out. But that's not what this article is about. I guess we just need to tighten up some language. -- Dmeranda 19:43, 24 April 2007 (UTC)Reply
Here's a python example showing how a generator really results is a true iterator (i.e., it obeys the standard Python iterator-protocol):
>>> def count_to_ten(n):    # Define a generator function
...     while n <= 10:
...         yield n
...         n = n + 1
...     return
... 
>>> gen = count_to_ten(7)   # Invoke the generator
>>> gen.next()              # Treat the invocation as an iterator object
7
>>> gen.next()
8
>>> gen.next()
9
>>> gen.next()
10
>>> gen.next()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
StopIteration

Dmeranda 19:52, 24 April 2007 (UTC)Reply

This article should not, as it is named, be about a specific subtype of generators, namely iterator-like generators. If you want to described them, and there is obviosuly much to say about them, then, fine, go ahead, but in a specific article. The article about generators in CS should about generators in CS. So what about refactoring this article in a general one (that I'm willing to write) and a specific one about iterator-like generators and their variants like list comprehensions? Nowhere man 20:25, 24 April 2007 (UTC)Reply
Although I understand there is confusion that needs rectified, I disagree that this article's topic is too narrow in definition. Generator (computer science) generally agrees with most of the computer science literature in it's use of that term, as an iterator-like function. I've not seen any comp sci literature which defines what a generator (unqualified) is otherwise, except for the apparent convention of using the word in specific instances such as random number generator, code generator, name generator, character generator, etc. that are just a consequence of the common English meaning of the word, rather than a non-English teachnical meaning specific to the comp sci community. Many of those specific uses are listed on Generator (disambiguation) (although the disambig page seems to have been renamed to just Generator now). Would it suffice to just make a more verbose disambiguation statement at the top of the article, maybe something like:
This article is about a type of function in computer science that behaves like an iterator. For other uses of the term in computing in general see Generator.
You say that the article "generally agrees with most of the computer science literature in it's use of that term". Could you give references of actual CS publications going in this direction? The article in itself is in contradiction with this claim, as it takes PRNG as an example, whereas PRNG typically don't behave like iterators, but are simply non referentially transparent functions of no argument.
The first reference cited in the article says:
Generators first appeared in CLU (1975)[1]
Although, the given article, "Iteration Abstraction in Sather", doesn't deal with generators at all. It's very subjects is named iterators, and the term generator only appear a few times, in the last sections were the article makes comparisons with existing approaches of its subject. So long for the agreement of litterature in its use of that term...
Nowhere man 23:31, 24 April 2007 (UTC)Reply
Would that work? We could of course try to invent a broader-scoped definition, but I'm hesitant to do so. -- Dmeranda 21:39, 24 April 2007 (UTC)Reply

Fuzzy or Hairy?

edit

The definition at the very start of the article is very hard to parse. It overuses analogy and is quite confusing. Perhaps later in the intro section it might be comprehensible, but at 0300 in the morning w/ a non-working GRUB2 EFI configuration hanging over my head, I just ditched trying to read the article and leave this short note waiting for the rest of my update to download.

The definition/intro is ambiguous and seems to muddle up the notion of what is being iterated, what the iterator is, and how it is implemented. Try to stay at a very non-computer science language level with the initial definition or include the WP article link for every bit of jargon you need to be clear. You could, however, start by saying that a generator is specific case of an Iterator... However, nearly every CS topic has, someplace, a fairly clear definition using basic mathematics/logic terms that most reasonable educated individuals without a degree in CS can understand.

What you should not say is that it is like an array, since it isn't anything like an array. You might use a generator to access values in an array, but it isn't the array. You can use a bucket to empty a bathtub full of soapy water, but don't confuse the bucket with the bathwater (and for heaven's sake, take the baby out first!).

Sorry, but most of my programming experience is with Java (w/o generators as a built in, but I am sure I have had to write thousands of them w/o ever knowing what the hell I was doing), or I would try my hand at a new intro. — Preceding unsigned comment added by 75.73.1.89 (talk) 09:16, 13 January 2017 (UTC)Reply

Needs verification

edit

OK, I declared the article as needing verification from actual facts.

  • The CLU paper cited just talks about iterators, and compares them to generators.
  • Some contributor stated that the article "generally agrees with most of the computer science literature in it's use of that term", without being able to show any verifiable references.

I'll wait some time for people to be able to gather and show references to backup the article. If that doesn't happen, I'll edit it to describe the concept of generators in general. Nowhere man 12:54, 29 April 2007 (UTC)Reply

I even found a contradictory source. In "Iterators: Signs of Weakness in Object-Oriented Languages" (1992), H. Baker states the following about iterators as found in CLU and C++:
Iterators are a 1980's version of the 1950's concept of generators. A generator is a subroutine which is called like a function, but returns a "new" value every time it is called (i.e., it is emphatically not a mathematical function). The "random number generator" is prototypic of a generator.
With this new information in hands, I will not wait to modify the article. Nowhere man 17:38, 29 April 2007 (UTC)Reply

OK, I claimed the article was inconsistent with reachable publications, so with not a single attempt to counter that claim in nearly one year, I eventually rewrote the article. Nowhere man (talk) 21:18, 12 March 2008 (UTC)Reply

I'm not sure that the claim was clear enough to provoke a counter.
Regarding Baker's paper, it's entirely consistent with the article. The sentence quoted is a simplified introduction, taken somewhat out of context; two paragraphs later, Baker unambiguously explains the difference between generators and functions/iterator classes:

One is tempted to think that every co-routine generator can be emulated by a function which has access to some persistent local state (e.g., an Algol-60 "own" variable), but this is not the case. The standard counter-example is the "samefringe" problem, which can be solved by two co-routined "fringe" generators, but cannot be solved by a function with only a bounded amount of persistent local state.

The paper as a whole is an argument against iterator classes, and for functional generators. Piet Delport 2025-08-06 06:30
How could I make the claim more clear: a banner, examination of cited papers and quotation with links to another contradictory paper! As for Baker's paper, the quote you give doesn't say that generators have any relationship with loops or control structures, and clearly state that a PRNG is a classical example of generator. So I maintain that the article is plain false. It still cites papers that are contradictory to itself. If you can find a reachable reference that clearly support the old version, there's room to improve it based on those references. Until then, I'll revert to my modification.
I gave plenty of time to counter my claim, so don't revert to the previous state of the article without a strong reference. just saying that noone saw the long-standing claim isn't enough. Nowhere man (talk) 21:24, 25 March 2008 (UTC)Reply
I find the paper clear, unambiguous, and non-contradictory. It meets all the qualifications of a reliable source. If you disagree with the paper, Wikipedia is not the avenue to pursue it: Wikipedia's threshold for inclusion is verifiability, not truth, and not original research.
Regarding your individual points:
  • I don't know what you're trying to imply about the text i quoted; it doesn't directly say anything about generators and their relationship with loops / control structures, but that's the subject of the rest of the paper.
  • Baker's paper does not say that PRNGs are examples of generators, it says that PRNGs are prototypic of generators, which includes the sense of being precursory or inspirational to. (Indeed, PRNGs are generally well-implementable both as "plain" procedures and as generators in the sense of this article.) You could quibble over which sense of "prototypic" was meant in the introductory sentence, taken out of context, but any doubt is rendered moot by the body of the paper, which is quite precise, and never mentions PRNGs.
  • The article is not backed by the Baker citation alone, but by Kiselyov, Omohundro (Sather), Liskov (CLU), Shaw (Alphard) and the rest (Python, C#, JavaScript). There are no grounds for reverting the article without a convincing argument that these citations are all invalid.
If you wish to continue this further, the next dispute resolution step is probably to solicit a third opinion, or informal mediation. Piet Delport 2025-08-06 00:07

Suggestion for clarifications, definitions, etc.

edit

The Icon programming language, while not the first language to implement generators, was one of the first to fully integrate the concept into the language. Within Icon, generators are not only used within the scope of loops, but are available throughout the language. In addition while in a certain sense one could say that a generator returns a list of values, a better term is that a generator returns a result sequence. Specifically, a generator could return an infinite number of values (e.g. a random number generator).

There was a lot of research and many papers written on generators. In doing a date sorted search of the string "generator" in the ACM portal, the earliest reference I found (outside random number generators, and a couple of references to code generators) was

Mary Shaw, William A. Wulf, Ralph L. London
August 1977 	  	
Communications of the ACM,  Volume 20 Issue 8
Publisher: ACM Press
Full text available: 	pdf(1.28 MB)
	
Additional Information:	full citation, abstract, references, citings
The Alphard “form” provides the programmer with a great deal of control 
over the implementation of abstract data types. In this paper the 
abstraction techniques are extended from simple data representation and 
function definition to the iteration statement, the most important point 
of interaction between data and the control structure of the language 
itself. A means of specializing Alphard's loops to operate on abstract 
entities without explicit dependence on the representation ...

Keywords: abstraction and representation, abstraction data types, 
assertions, control specialization, correctness, generators, invariants, 
iteration statements, modular decomposition, program specifications, 
programming languages, programming methodology, proofs of correctness, 
types, verification 

Of interest, is that immediately following the above article in the same issue of the Communications of the ACM, was an article on CLU.

The next real reference to generators was the article written by the late Dr Ralph Griswold

Generators in Icon
Full text 	pdf formatPdf (1.03 MB)
Source 	ACM Transactions on Programming Languages and Systems (TOPLAS) archive
Volume 3 ,  Issue 2  (April 1981) table of contents
Pages: 144 - 161  
Year of Publication: 1981
ISSN:0164-0925
Authors 	
Ralph E. Griswold 	 Department of Computer Science, The University of Arizona, Tucson, AZ
David R. Hanson 	 Department of Computer Science, The University of Arizona, Tucson, AZ
John T. Korb 	 Xerox Corporation, 3333 Coyote Hill Road, Palo Alto, CA
Publisher 	
ACM Press   New York, NY, USA 

Quoting from the above

5. RELATED WORK
The concept of generators has appeared in various forms in many languages. An
early language that has generators is IPL-V [31], in which a generator is a
subroutine that calls a processing routine to operate on each object in a data
structure. Other languages, such as ALGOL 68 [38] and COBOL, use the term
generator to describe various language features, but this use is unrelated to the
Icon notion.

Languages that support coroutines frequently use the term generator to describe
a particular coroutine usage. SIMULA [1] is the oldest of such languages;
more recent examples include extensions to POP-2 [24] and SL5 [20] and
coroutine additions to PASCAL [27]. There also has been a substantial amount
of work on the "lazy evaluation" approach to the incremental generation of
sequences, usually in LISP or APL frameworks [7, 17, 22].

More recently, ALPHARD [43] and CLU [28] have been developed to support
data structure abstraction. In these languages generators are used to iterate over
the elements of programmer-defined data structures [35]. Included with the
definition of a data abstraction (or "cluster" in CLU) is a procedure for generating
the elements of the abstraction. In CLU, this procedure, called an iterator,
produces its values using the yield statement. When another element is required,
execution of the iterator continues where the yield statement left off. In each of
these languages, generators are only accessible in a specific context: a particular
type of for statement. This is significantly more restricted than in Icon, where
generators may appear anywhere.

Superficially, generators in ALPHARD and CLU appear to correspond to the
every expression in Icon. But while every has the syntactic appearance of a
standard control structure, the nonstandard goal-directed evaluation mechanism
makes its semantics more general than the corresponding ALPHARD and CLU
constructs. It is the restricted applicability and the lack of goal-directed evaluation
that differentiate these constructs from generators in Icon.

ACM Transactions on Programming Languages and Systems, Vol. 3, No. 2, April 1981.
158 R.E. Griswold, D. R. Hanson, and J. T. Korb

CheyenneWills 20:49, 25 June 2007 (UTC)Reply

C++ generators

edit

I don't think C++ properly supports generators. There is no way to have the compiler save the stack frame; as in the example, the object must remember its own state. Overloading the function call operator makes it look somewhat like a (hypothetical) C++ generator, but a constructor call is still needed. It's close, but this can done, with vary degrees of syntactical success, in most object-oriented languages. —Preceding unsigned comment added by 67.122.120.62 (talk) 10:49, 2 March 2008 (UTC)Reply

Right, the section described an iterator class, not a generator. I removed it. Piet Delport 2025-08-06 06:35

D Generators

edit

In D generators can be done by implementing an opApply function (overload for a 'foreach'). This page shows a good example at the end with primes numbers: [6].

Could this page include a D example thanks.

Tim M. —Preceding unsigned comment added by 125.238.96.209 (talk) 09:22, 6 July 2009 (UTC)Reply

Iterator confusion

edit

I think the current text is messed up to deserve rewrite. I think that generators have little in common with iterators, except a common usage. A generator is a function with a static persistent environment, which is preserved from call to call, cf. local static declaration in C and own in good old Algol-60. Whether used as iterator or not is irrelevant. You cannot create different instances of generators like you can when dealing with iterators, or put it another way: there's only one generator instance ever, and it is "created" at startup. Iterator instances are always created to dynamically produce a sequence, while the generator just preserves a state. When created, the iterators take an argument, often an array or some other enumerable, but not always – this in opposition to the generator, which is not "reset/reinitialized" in a call different from a normal generator call producing the next item. Rursus dixit. (mbork3!) 07:04, 21 June 2010 (UTC)Reply

No, I'm confused by the Python generators definition. Forget it! Rursus dixit. (mbork3!) 07:33, 21 June 2010 (UTC)Reply

ICON as a language

edit

the article opens by characterizing ICON as a string manipulation language.

I think that if you look at ICON 9.5 this will not seem an appropriate characterization. Was ICON not the first expressly free language (after accidental SNOBOL 'release'? )

ObjectIcon at code.google.com/p/objecticon is surely more than a string manipulation language

ICON is better characterized as a free expression-based language with goal-directed facilities

For ICON for pythonistas, see convergepl.org G. Robert Shiplett 14:34, 29 November 2010 (UTC) —Preceding unsigned comment added by Grshiplett (talk ? contribs)

Standard or common implementation of generators at the low-level

edit

This article should describe in-detail the most common ways generators are implemented at the low-level. This means information such as if a program with generators is compiled to an assembly language, what would it look like? What happens to the control flow? What happens to the stack? Is a new stack created? Where does it keep the information about where in the generator control flow is resumed to after the yield statement?

--Eboyjr (talk) 17:02, 16 June 2011 (UTC)Reply

Needs common example; Should be an infinite sequence

edit

(Disclaimer: my view of "what a generator is" and "what they are good for" comes chiefly from my experience with Python.)

The article -- and its examples -- are very scattered. They even include examples of "generating the numbers from 10 to 1". To someone who doesn't understand the power of or purpose of generators, this will be a highly deluminating example, as they could [correctly] disparage the whole idea: "why wouldn't I just do that in a loop, decrementing a counter?"

My suggestions:

  • Point out that generators are really good for generating INFINITE sequences... just a little bit at a time, as the "consumer" needs the "next" item.
  • Point out that most useful generators need to store a complicated state. (It is not just a simple unary test like "is this number even", which -- again -- can be accomplished declaratively and used as a test in a loop.)
  • Point out that languages that "support generators" do so by giving the programmer a simple way to do BOTH of those: generate "infinite sequences incrementally" and "save their state between calls".
  • Pick a simple example that uses BOTH of those features. Such as: calculating the Fibonacci sequence. Let's see a Fib() generator in all the languages discussed.
  • Point out that recursion and generation can each be used on certain calculations, but they are NOT synonymous.
  • Compare and contrast a generator with a memoized recursive routine. (You can quickly calculate Fib(10000000) with a memoized recursive Fib, at the expense of the memory for the 1000000 prior entries. However, with a generator-based Fib(), constant memory (just two state variables) will serve to walk through all the values of Fib forever.)

If I have time someday, I may attempt to update the article with some of these suggestions.

Dharasty (talk) 13:10, 3 May 2012 (UTC)Reply

Dates are incorrect. Fix or maybe even remove?

edit

The dates in this refer to the date the programming language first appeared, which is often *not* the same date as when generators appeared for this language.

For example if you would glance at this article, you would get the impression that:

  • Generators were first introduced in Lisp in 1958 (not so, generators are a recent addition to Lisp, and AFAIK not even standardized in Common Lisp)
  • PHP has generators since 1995 (It's implemented and available in the `latest source', but available in a general release yet).

etc... IMHO this is rather misleading ... Someone should fix the dates to reflect whenever this feature was added to a language (if it wasn't there from the start) or the dates should just be removed. Carpetsmoker (talk) 10:00, 11 March 2013 (UTC)Reply

Just passing by, but came here to write this exact same thing - The Ruby section says 1995 but also says "starting from version 1.9" which was released in 2007. Galestar (talk) 17:21, 22 April 2013 (UTC)Reply

Corrected the date for Python. tlesher (talk) 20:13, 19 August 2013 (UTC)Reply

舌头发涩是什么原因造成的 外痔疮有什么症状 吃什么能升血压 羊水破了是什么症状 食管裂孔疝是什么病
耳朵发热是什么预兆 面肌痉挛吃什么药效果好 每天什么时间锻炼最好 51岁属什么生肖 满月脸水牛背是什么病
脖子肿是什么原因 牛仔是什么面料 什么春什么什么 经常吃紧急避孕药有什么危害 马来西亚主食吃什么
勿忘是什么意思 舌苔厚口臭吃什么药好 花儿乐队为什么解散 球镜是什么意思 高铁特等座有什么待遇
噩耗是什么意思hcv9jop6ns4r.cn 思维跳脱是什么意思hcv8jop6ns1r.cn 甘油三酯高有什么症状gangsutong.com 泡是什么意思hcv8jop0ns2r.cn 封闭针是什么药hcv9jop5ns8r.cn
早上起来口干口苦是什么原因hcv8jop4ns0r.cn 秋葵与什么菜相克hcv8jop9ns6r.cn 舌苔厚腻是什么原因hcv8jop4ns3r.cn rh血型是什么意思hcv9jop8ns2r.cn 总胆汁酸是什么意思xinjiangjialails.com
夏至吃什么传统美食hcv8jop5ns3r.cn 喝什么泡水降血压最好gysmod.com 嫖娼什么意思hcv9jop8ns2r.cn 实质是什么意思clwhiglsz.com save是什么意思hcv7jop6ns5r.cn
55岁属什么生肖hcv8jop9ns7r.cn 不什么一什么hcv9jop1ns1r.cn 接吻是什么样的感觉hcv9jop0ns4r.cn 一什么便什么造句hcv9jop2ns2r.cn 碳酸钙俗称什么hcv8jop0ns5r.cn
百度