digitalmars.D - foreach
- Sam S E (2/2) Nov 22 2008 Does foreach use delegates? Isn't that unnecessary overhead?
- Jarrett Billingsley (8/10) Nov 22 2008 It does use delegates, for iterating over most types. When iterating
- bearophile (5/6) Nov 23 2008 Sort of is the key word here :-)
- Bill Baxter (5/15) Nov 23 2008 How does delegate overhead compare to the stack thread context switch
- Christopher Wright (3/22) Nov 23 2008 ~32 instructions per switch and 4KB allocated for fibers, versus about 2...
- Bill Baxter (4/31) Nov 23 2008 Oh, that's a bit worse than I was thinking. Not a good default
- Sam S E (2/15) Nov 23 2008 Why not just use a normal for loop; wouldn't it be almost as simple as t...
- Jarrett Billingsley (9/24) Nov 23 2008 How do you use a for loop to iterate over an associative array whose
- Sam S E (2/30) Nov 23 2008 Where are the docs on opApply?
- Steven Schveighoffer (4/5) Nov 23 2008 Kind of hidden. They are not on the operators page:
- Ary Borenszweig (23/52) Nov 23 2008 Search opApply in http://www.digitalmars.com/d/1.0/statement.html
- Ary Borenszweig (4/70) Nov 24 2008 Umm... I didn't mean to sound rude or anything. Unfortunately, when
- Chad J (6/46) Nov 24 2008 Yes. I think I've mentioned this before too.
- Jesse Phillips (6/80) Nov 24 2008 I don't think this really sounded terribly rude. I do agree that
- Steven Schveighoffer (18/21) Nov 25 2008 I never use it. Simply because I only ever go on DM to look at the spec...
Does foreach use delegates? Isn't that unnecessary overhead? --Sam
Nov 22 2008
On Sat, Nov 22, 2008 at 11:40 PM, Sam S E <eisenstat.aa sympatioco.ca> wrote:Does foreach use delegates? Isn't that unnecessary overhead? --SamIt does use delegates, for iterating over most types. When iterating over arrays, the compiler turns it into a sort of for loop instead. Is it unnecessary overhead? It's not always as fast as it could be, but unless someone can figure out some other way of implementing it, it's pretty much the best we can get. How about iterator objects, like in C++ or Java? Are they unnecessary overhead? ;)
Nov 22 2008
Jarrett Billingsley Wrote:When iterating over arrays, the compiler turns it into a sort of for loop instead.<Sort of is the key word here :-) It's not as light as a normal for, but in 98% situations is fine. Bye, bearophile
Nov 23 2008
On Sun, Nov 23, 2008 at 3:25 PM, Jarrett Billingsley <jarrett.billingsley gmail.com> wrote:On Sat, Nov 22, 2008 at 11:40 PM, Sam S E <eisenstat.aa sympatioco.ca> wrote:How does delegate overhead compare to the stack thread context switch overhead in the new Fibers in druntime? --bbDoes foreach use delegates? Isn't that unnecessary overhead? --SamIt does use delegates, for iterating over most types. When iterating over arrays, the compiler turns it into a sort of for loop instead. Is it unnecessary overhead? It's not always as fast as it could be, but unless someone can figure out some other way of implementing it, it's pretty much the best we can get. How about iterator objects, like in C++ or Java? Are they unnecessary overhead? ;)
Nov 23 2008
Bill Baxter wrote:On Sun, Nov 23, 2008 at 3:25 PM, Jarrett Billingsley <jarrett.billingsley gmail.com> wrote:~32 instructions per switch and 4KB allocated for fibers, versus about 2 instructions and no allocation for delegates.On Sat, Nov 22, 2008 at 11:40 PM, Sam S E <eisenstat.aa sympatioco.ca> wrote:How does delegate overhead compare to the stack thread context switch overhead in the new Fibers in druntime? --bbDoes foreach use delegates? Isn't that unnecessary overhead? --SamIt does use delegates, for iterating over most types. When iterating over arrays, the compiler turns it into a sort of for loop instead. Is it unnecessary overhead? It's not always as fast as it could be, but unless someone can figure out some other way of implementing it, it's pretty much the best we can get. How about iterator objects, like in C++ or Java? Are they unnecessary overhead? ;)
Nov 23 2008
On Sun, Nov 23, 2008 at 11:26 PM, Christopher Wright <dhasenan gmail.com> wrote:Bill Baxter wrote:Oh, that's a bit worse than I was thinking. Not a good default iteration strategy then. Bummer. --bbOn Sun, Nov 23, 2008 at 3:25 PM, Jarrett Billingsley <jarrett.billingsley gmail.com> wrote:~32 instructions per switch and 4KB allocated for fibers, versus about 2 instructions and no allocation for delegates.On Sat, Nov 22, 2008 at 11:40 PM, Sam S E <eisenstat.aa sympatioco.ca> wrote:How does delegate overhead compare to the stack thread context switch overhead in the new Fibers in druntime? --bbDoes foreach use delegates? Isn't that unnecessary overhead? --SamIt does use delegates, for iterating over most types. When iterating over arrays, the compiler turns it into a sort of for loop instead. Is it unnecessary overhead? It's not always as fast as it could be, but unless someone can figure out some other way of implementing it, it's pretty much the best we can get. How about iterator objects, like in C++ or Java? Are they unnecessary overhead? ;)
Nov 23 2008
Jarrett Billingsley Wrote:On Sat, Nov 22, 2008 at 11:40 PM, Sam S E <eisenstat.aa sympatioco.ca> wrote:Why not just use a normal for loop; wouldn't it be almost as simple as token substitution? By 'most types,' do you mean associative arrays or am I forgetting something? As a mainly C(++) programmer, I don't use iterators when I don't need to. I don't even use classes when I don't need to.Does foreach use delegates? Isn't that unnecessary overhead? --SamIt does use delegates, for iterating over most types. When iterating over arrays, the compiler turns it into a sort of for loop instead. Is it unnecessary overhead? It's not always as fast as it could be, but unless someone can figure out some other way of implementing it, it's pretty much the best we can get. How about iterator objects, like in C++ or Java? Are they unnecessary overhead? ;)
Nov 23 2008
On Sun, Nov 23, 2008 at 10:48 AM, Sam S E <asdf mailinator.com> wrote:Jarrett Billingsley Wrote:How do you use a for loop to iterate over an associative array whose implementation is hidden, or a binary tree, or any arbitrary container, or a sequence or words in a file, or the zipped contents of two lists, or... The point of foreach isn't performance, it's flexibility and abstraction. As long as you can make an opApply or function which takes a delegate, you can use the foreach loop with it. Not everything is an array.On Sat, Nov 22, 2008 at 11:40 PM, Sam S E <eisenstat.aa sympatioco.ca> wrote:Why not just use a normal for loop; wouldn't it be almost as simple as token substitution? By 'most types,' do you mean associative arrays or am I forgetting something? As a mainly C(++) programmer, I don't use iterators when I don't need to. I don't even use classes when I don't need to.Does foreach use delegates? Isn't that unnecessary overhead? --SamIt does use delegates, for iterating over most types. When iterating over arrays, the compiler turns it into a sort of for loop instead. Is it unnecessary overhead? It's not always as fast as it could be, but unless someone can figure out some other way of implementing it, it's pretty much the best we can get. How about iterator objects, like in C++ or Java? Are they unnecessary overhead? ;)
Nov 23 2008
Jarrett Billingsley Wrote:On Sun, Nov 23, 2008 at 10:48 AM, Sam S E <asdf mailinator.com> wrote:Where are the docs on opApply?Jarrett Billingsley Wrote:How do you use a for loop to iterate over an associative array whose implementation is hidden, or a binary tree, or any arbitrary container, or a sequence or words in a file, or the zipped contents of two lists, or... The point of foreach isn't performance, it's flexibility and abstraction. As long as you can make an opApply or function which takes a delegate, you can use the foreach loop with it. Not everything is an array.On Sat, Nov 22, 2008 at 11:40 PM, Sam S E <eisenstat.aa sympatioco.ca> wrote:Why not just use a normal for loop; wouldn't it be almost as simple as token substitution? By 'most types,' do you mean associative arrays or am I forgetting something? As a mainly C(++) programmer, I don't use iterators when I don't need to. I don't even use classes when I don't need to.Does foreach use delegates? Isn't that unnecessary overhead? --SamIt does use delegates, for iterating over most types. When iterating over arrays, the compiler turns it into a sort of for loop instead. Is it unnecessary overhead? It's not always as fast as it could be, but unless someone can figure out some other way of implementing it, it's pretty much the best we can get. How about iterator objects, like in C++ or Java? Are they unnecessary overhead? ;)
Nov 23 2008
"Sam S E" wroteWhere are the docs on opApply?Kind of hidden. They are not on the operators page: http://www.digitalmars.com/d/2.0/statement.html#ForeachStatement -Steve
Nov 23 2008
Sam S E escribió:Jarrett Billingsley Wrote:Search opApply in http://www.digitalmars.com/d/1.0/statement.html Can't the search in digitalmars.com/d be improved? Searching for "opApply" you get ten results which are just questions in the newsgroups, and just in the second page you can see the result you probably are looking for. I suggest improving it in this way: 1. Have a map of obvious keywords that people will look for, to precise urls. Some examples are: delegate, function, override, virtual, class, struct, union, interface, pointer, op*, operator overloading, inheritance, final, const, invariant, etc. 2. If the search is exactly one of the keywords, use the map above. 3. Else, use Google Search Engine. The list might be big, but it can be done if the community helps, and I think it will improve a lot the usability of the site. Actually, the map can be [keyword -> list of urls]. For example, for invariant it should point the invariant attribute as well as invariant classes. And don't point me to http://www.wikiservice.at/wiki4d/wiki.cgi?LanguageSpecification/KeywordIndex I know it exists, but people how enter the D site (and the above is not the D site) will use the search box. Who uses indexes these days when you can search and find what you want?On Sun, Nov 23, 2008 at 10:48 AM, Sam S E <asdf mailinator.com> wrote:Where are the docs on opApply?Jarrett Billingsley Wrote:How do you use a for loop to iterate over an associative array whose implementation is hidden, or a binary tree, or any arbitrary container, or a sequence or words in a file, or the zipped contents of two lists, or... The point of foreach isn't performance, it's flexibility and abstraction. As long as you can make an opApply or function which takes a delegate, you can use the foreach loop with it. Not everything is an array.On Sat, Nov 22, 2008 at 11:40 PM, Sam S E <eisenstat.aa sympatioco.ca> wrote:Why not just use a normal for loop; wouldn't it be almost as simple as token substitution? By 'most types,' do you mean associative arrays or am I forgetting something? As a mainly C(++) programmer, I don't use iterators when I don't need to. I don't even use classes when I don't need to.Does foreach use delegates? Isn't that unnecessary overhead? --SamIt does use delegates, for iterating over most types. When iterating over arrays, the compiler turns it into a sort of for loop instead. Is it unnecessary overhead? It's not always as fast as it could be, but unless someone can figure out some other way of implementing it, it's pretty much the best we can get. How about iterator objects, like in C++ or Java? Are they unnecessary overhead? ;)
Nov 23 2008
Ary Borenszweig escribió:Sam S E escribió:Umm... I didn't mean to sound rude or anything. Unfortunately, when someone doesn't speak in its native language, he tends to sound rude. Does anyone else have problems with the search box in digitalmars.com/d ?Jarrett Billingsley Wrote:Search opApply in http://www.digitalmars.com/d/1.0/statement.html Can't the search in digitalmars.com/d be improved? Searching for "opApply" you get ten results which are just questions in the newsgroups, and just in the second page you can see the result you probably are looking for. I suggest improving it in this way: 1. Have a map of obvious keywords that people will look for, to precise urls. Some examples are: delegate, function, override, virtual, class, struct, union, interface, pointer, op*, operator overloading, inheritance, final, const, invariant, etc. 2. If the search is exactly one of the keywords, use the map above. 3. Else, use Google Search Engine. The list might be big, but it can be done if the community helps, and I think it will improve a lot the usability of the site. Actually, the map can be [keyword -> list of urls]. For example, for invariant it should point the invariant attribute as well as invariant classes. And don't point me to http://www.wikiservice.at/wiki4d/wiki.cgi?LanguageSpecification/KeywordIndex I know it exists, but people how enter the D site (and the above is not the D site) will use the search box. Who uses indexes these days when you can search and find what you want?On Sun, Nov 23, 2008 at 10:48 AM, Sam S E <asdf mailinator.com> wrote:Where are the docs on opApply?Jarrett Billingsley Wrote:How do you use a for loop to iterate over an associative array whose implementation is hidden, or a binary tree, or any arbitrary container, or a sequence or words in a file, or the zipped contents of two lists, or... The point of foreach isn't performance, it's flexibility and abstraction. As long as you can make an opApply or function which takes a delegate, you can use the foreach loop with it. Not everything is an array.On Sat, Nov 22, 2008 at 11:40 PM, Sam S E <eisenstat.aa sympatioco.ca> wrote:Why not just use a normal for loop; wouldn't it be almost as simple as token substitution? By 'most types,' do you mean associative arrays or am I forgetting something? As a mainly C(++) programmer, I don't use iterators when I don't need to. I don't even use classes when I don't need to.Does foreach use delegates? Isn't that unnecessary overhead? --SamIt does use delegates, for iterating over most types. When iterating over arrays, the compiler turns it into a sort of for loop instead. Is it unnecessary overhead? It's not always as fast as it could be, but unless someone can figure out some other way of implementing it, it's pretty much the best we can get. How about iterator objects, like in C++ or Java? Are they unnecessary overhead? ;)
Nov 24 2008
Ary Borenszweig wrote:Ary Borenszweig escribió:Yes. I think I've mentioned this before too. And I agree that letting the computer handle the searching instead of manually memorizing where to find things in trees of indexed information is... just better. The computer is (erm, /should/ be) better at it than we are (most of the time).Sam S E escribió:Umm... I didn't mean to sound rude or anything. Unfortunately, when someone doesn't speak in its native language, he tends to sound rude. Does anyone else have problems with the search box in digitalmars.com/d ?Where are the docs on opApply?Search opApply in http://www.digitalmars.com/d/1.0/statement.html Can't the search in digitalmars.com/d be improved? Searching for "opApply" you get ten results which are just questions in the newsgroups, and just in the second page you can see the result you probably are looking for. I suggest improving it in this way: 1. Have a map of obvious keywords that people will look for, to precise urls. Some examples are: delegate, function, override, virtual, class, struct, union, interface, pointer, op*, operator overloading, inheritance, final, const, invariant, etc. 2. If the search is exactly one of the keywords, use the map above. 3. Else, use Google Search Engine. The list might be big, but it can be done if the community helps, and I think it will improve a lot the usability of the site. Actually, the map can be [keyword -> list of urls]. For example, for invariant it should point the invariant attribute as well as invariant classes. And don't point me to http://www.wikiservice.at/wiki4d/wiki.cgi?LanguageSpecification/KeywordIndex I know it exists, but people how enter the D site (and the above is not the D site) will use the search box. Who uses indexes these days when you can search and find what you want?
Nov 24 2008
On Tue, 25 Nov 2008 00:40:41 -0200, Ary Borenszweig wrote:Ary Borenszweig escribió:KeywordIndexSam S E escribió:Jarrett Billingsley Wrote:Search opApply in http://www.digitalmars.com/d/1.0/statement.html Can't the search in digitalmars.com/d be improved? Searching for "opApply" you get ten results which are just questions in the newsgroups, and just in the second page you can see the result you probably are looking for. I suggest improving it in this way: 1. Have a map of obvious keywords that people will look for, to precise urls. Some examples are: delegate, function, override, virtual, class, struct, union, interface, pointer, op*, operator overloading, inheritance, final, const, invariant, etc. 2. If the search is exactly one of the keywords, use the map above. 3. Else, use Google Search Engine. The list might be big, but it can be done if the community helps, and I think it will improve a lot the usability of the site. Actually, the map can be [keyword -> list of urls]. For example, for invariant it should point the invariant attribute as well as invariant classes. And don't point me to http://www.wikiservice.at/wiki4d/wiki.cgi?LanguageSpecification/On Sun, Nov 23, 2008 at 10:48 AM, Sam S E <asdf mailinator.com> wrote:Where are the docs on opApply?Jarrett Billingsley Wrote:How do you use a for loop to iterate over an associative array whose implementation is hidden, or a binary tree, or any arbitrary container, or a sequence or words in a file, or the zipped contents of two lists, or... The point of foreach isn't performance, it's flexibility and abstraction. As long as you can make an opApply or function which takes a delegate, you can use the foreach loop with it. Not everything is an array.On Sat, Nov 22, 2008 at 11:40 PM, Sam S E <eisenstat.aa sympatioco.ca> wrote:Why not just use a normal for loop; wouldn't it be almost as simple as token substitution? By 'most types,' do you mean associative arrays or am I forgetting something? As a mainly C(++) programmer, I don't use iterators when I don't need to. I don't even use classes when I don't need to.Does foreach use delegates? Isn't that unnecessary overhead? --SamIt does use delegates, for iterating over most types. When iterating over arrays, the compiler turns it into a sort of for loop instead. Is it unnecessary overhead? It's not always as fast as it could be, but unless someone can figure out some other way of implementing it, it's pretty much the best we can get. How about iterator objects, like in C++ or Java? Are they unnecessary overhead? ;)I don't think this really sounded terribly rude. I do agree that searching the site can be annoying when top results are always from the newsgroup. Maybe an option to search digitalmars/d and one to search digitalmars/d/archive (don't know if that could be customized).I know it exists, but people how enter the D site (and the above is not the D site) will use the search box. Who uses indexes these days when you can search and find what you want?Umm... I didn't mean to sound rude or anything. Unfortunately, when someone doesn't speak in its native language, he tends to sound rude. Does anyone else have problems with the search box in digitalmars.com/d ?
Nov 24 2008
"Ary Borenszweig" wroteUmm... I didn't mean to sound rude or anything. Unfortunately, when someone doesn't speak in its native language, he tends to sound rude. Does anyone else have problems with the search box in digitalmars.com/d ?I never use it. Simply because I only ever go on DM to look at the spec, and at bugs (which have their own search box). For the spec, it's generally more fruitful to click on each page, then use my browser search to find the item I want. If I use the search box, it gives me a billion results from the newsgroups. If the search box could be focused at specific parts of DM, I might start using it. I'd split it into: Newsgroups D1 spec D1 phobos D2 spec D2 phobos Articles Everything else With checkboxes for each so I can specify combinations if I want. And BTW, you don't sound rude ;) -Steve
Nov 25 2008