Re: Circular Buffer

2014-02-11 Thread Jonathan Dunlap
Ooo.. I like the drop and take approach! I wonder if this could 
be something that makes it into the standard library 
(std.range?). What would be the best way to approach in 
suggesting that?



Why not drop and take?
http://dpaste.dzfl.pl/0649b809c81e




Re: Circular Buffer

2014-02-11 Thread Jonathan Dunlap
Wow! This is GREAT stuff. My use-case is slightly more complex, 
and I'm not sure how to best apply this knowledge. The retro 
reverses the array which is problematic in itself as well as 
losing the starting index location. I have an array that I'd like 
to elegantly "rotate". Best way I can show this is by example of 
an imaginary rotate function:


auto data = [1,2,3];
assert( data.cycle.rotate(2) == [3,1,2] );
assert( data.cycle.rotate(-2) == [2,3,1] );

Perhaps what I'm doing is too complex requires me making my own 
iterator or something. In my quest of writing readable efficient 
code, I'm wondering what's the best route here. Thanks :)


On Monday, 10 February 2014 at 09:16:31 UTC, Gary Willoughby 
wrote:

void main(string[] args)
{
auto data = [1,2,3];

assert(data.cycle.take(5).array   == [1,2,3,1,2]);
assert(data.retro.cycle.take(5).array == [3,2,1,3,2]);
}




Re: Circular Buffer

2014-02-09 Thread Jonathan Dunlap

(disclaimer: I'm new around here)
Is it possible to cycle backwards? If not, what's the best 
approach?


Example of some ideal "takeBack" function:
data = cycle([1,2,3][])
take(data, 4) is [1,2,3,1][]
takeBack(data, 4) would be [1,3,2,1][]

Thoughts?


Re: Fibers vs Async/await

2013-06-15 Thread Jonathan Dunlap

*bump*

On Tuesday, 11 June 2013 at 19:57:27 UTC, Jonathan Dunlap wrote:
I was listening to one of the DConf sessions and where was some 
talk about implementing async from C# into D someday in the far 
future. Recently I learned about D's fibers... and it looks 
like the same thing to me. What are the major differences in 
principle?


-Jonathan
@jonathanAdunlap




Fibers vs Async/await

2013-06-11 Thread Jonathan Dunlap
I was listening to one of the DConf sessions and where was some 
talk about implementing async from C# into D someday in the far 
future. Recently I learned about D's fibers... and it looks like 
the same thing to me. What are the major differences in principle?


-Jonathan
@jonathanAdunlap


Re: 1 compiler error without error message

2013-05-11 Thread Jonathan Dunlap

So what does "Error: function
std.algorithm.MapResult!(adjoin, Result).MapResult.opIndex cannot
get frame pointer to adjoin" actually mean? It's a bit cryptic to 
me.


Thanks!

On Saturday, 11 May 2013 at 05:13:18 UTC, Maxim Fomin wrote:

On Saturday, 11 May 2013 at 01:18:47 UTC, Jonathan Dunlap wrote:

This looks like already fixed in git head incorrect error 
gagging. With latest dmd it prints:


DMD v2.063-devel-1215bc3 DEBUG
/usr/include/d/dmd/phobos/std/algorithm.d(404): Error: function 
std.algorithm.MapResult!(adjoin, Result).MapResult.back cannot 
get frame pointer to adjoin
/usr/include/d/dmd/phobos/std/algorithm.d(438): Error: function 
std.algorithm.MapResult!(adjoin, Result).MapResult.front cannot 
get frame pointer to adjoin
/usr/include/d/dmd/phobos/std/algorithm.d(450): Error: function 
std.algorithm.MapResult!(adjoin, Result).MapResult.opIndex 
cannot get frame pointer to adjoin


Re: 1 compiler error without error message

2013-05-11 Thread Jonathan Dunlap
Hmm, it must be an issue then with 2.062. I'll upgrade tomorrow 
and see if that helps. Thanks!


On Saturday, 11 May 2013 at 05:13:18 UTC, Maxim Fomin wrote:

On Saturday, 11 May 2013 at 01:18:47 UTC, Jonathan Dunlap wrote:

This looks like already fixed in git head incorrect error 
gagging. With latest dmd it prints:


DMD v2.063-devel-1215bc3 DEBUG
/usr/include/d/dmd/phobos/std/algorithm.d(404): Error: function 
std.algorithm.MapResult!(adjoin, Result).MapResult.back cannot 
get frame pointer to adjoin
/usr/include/d/dmd/phobos/std/algorithm.d(438): Error: function 
std.algorithm.MapResult!(adjoin, Result).MapResult.front cannot 
get frame pointer to adjoin
/usr/include/d/dmd/phobos/std/algorithm.d(450): Error: function 
std.algorithm.MapResult!(adjoin, Result).MapResult.opIndex 
cannot get frame pointer to adjoin


1 compiler error without error message

2013-05-10 Thread Jonathan Dunlap

Building Solution: DFizzBuzz (Debug)



Building: DFizzBuzz (Debug)
Performing main compilation...

Current dictionary: C:\D\Projects\DFizzBuzz\DFizzBuzz
C:\D\dmd2\windows\bin\dmd.exe -debug -gc "main.d"  
"-IC:\D\dmd2\src\druntime\import" "-IC:\D\dmd2\src\phobos" 
"-odobj\Debug" 
"-ofC:\D\Projects\DFizzBuzz\DFizzBuzz\bin\Debug\DFizzBuzz.exe"


Exit code 1
Build complete -- 1 error, 0 warnings
-- Done --
Build: 1 error, 0 warnings
===

module main;

import std.stdio;
import std.file;
import std.path;
import std.string;
import std.conv;
import std.algorithm;
import std.range;
import std.traits;
import std.typetuple;
import std.typecons;

// Sample input file:
// 3 5 10
// 2 7 15
void main(string[] args)
{
string input;
writeln("This program is the classic Fizz Buzz application.");
writeln("It's more fun to let you play your own way.");
input = chomp(readln());
input = absolutePath(input);

assert( input.isFile );
auto lines = splitLines( readText(input) );
foreach(line; lines) {
writeln( getResults(line) );
}
}

string getResults(string line)
{
string[] members = std.regex.split(line, std.regex.regex(" "));
int A = to!int(members[0]);
int B = to!int(members[1]);
int N = to!int(members[2]);

string outputStr;

alias Tuple!(int, bool, bool) RuleType;
//== THE LINE THAT BREAKS THE COMPILER
	auto lazylist = map!(i => i, i => i % A==0, i => i % B==0)( 
iota(1, N+1, 1) );

// =
RuleType[] rules = array(lazylist);

foreach(RuleType rule; rules) {
if (rule[1]) outputStr ~= 'F';
if (rule[2]) outputStr ~= 'B';
else if (!rule[1]) outputStr ~= to!string(rule[0]);
outputStr ~= " ";
}
return outputStr;
}