Conversation
CyberShadow
left a comment
There was a problem hiding this comment.
Not sure about this one; it doesn't seem particularly exciting on its own. It's not really something you can't do in almost any language.
index.dd
Outdated
| ) | ||
| $(EXTRA_EXAMPLE | ||
| ---- | ||
| void main() |
There was a problem hiding this comment.
Needs a comment at the top explaining what the program does.
"Counts frequencies of adjacent pairs of DNA bases" (though I'm fairly sure I got the terminology wrong).
index.dd
Outdated
| int[char[2]] aa; | ||
|
|
||
| // The string `arr` has a limited alphabet: {A, C, G, T} | ||
| // Thus, iteration can be done _without_ decoding |
There was a problem hiding this comment.
I don't think we should bring up auto-decoding in a front page example.
index.dd
Outdated
| // iterate over all pairs in the string and observe each pair | ||
| // ('A', 'G'), ('G', 'A'), ('A', 'T'), ... | ||
| foreach (i; 0 .. arr.length - 1) | ||
| aa[arr[i .. $][0 .. 2]]++; |
There was a problem hiding this comment.
Might be worth mentioning/implying that slicing a string does not allocate a copy
index.dd
Outdated
| foreach (i; 0 .. arr.length - 1) | ||
| aa[arr[i .. $][0 .. 2]]++; | ||
|
|
||
| // iterate over all key/value pairs of the Associative Array |
There was a problem hiding this comment.
This comment seems redundant.
52bc6db to
9ef887e
Compare
|
Thanks for your pull request, @wilzbach! Bugzilla referencesYour PR doesn't reference any Bugzilla issue. If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog. |
9ef887e to
d6bb71a
Compare
There was a long discussion on the NG one months ago with the gist that the current examples are too advanced and that Python.org shows simple things like list comprehensions on their front page. |
| // ('A', 'B'), ('B', 'B'), ('B', 'A'), ... | ||
| // String slicing doesn't allocate a copy | ||
| foreach (i; 0 .. arr.length - 1) | ||
| aa[arr[i .. $][0 .. 2]]++; |
There was a problem hiding this comment.
The above looks cool, but can be simplified to:
aa[arr[i .. i + 2]]++;There was a problem hiding this comment.
I think in this case it's necessary:
onlineapp.d(11): Error: cannot implicitly convert expression `arr[i..i + 2LU]` of type `string` to `char[2]`
a707ff9 to
aa4af2f
Compare

From @CyberShadow's comment:
I really liked the example and imho it makes a good fit for the frontpage.
(this temporarily includes the first commit from #1755 to fix the roulette picker, s.t. it can be previewed)