Re: DConf 2017 Day 3 Livestream

2017-05-06 Thread Joshua Niehus via Digitalmars-d-announce
It's over. The video has already been take down. They will chop 
it into individual lectures and repost them on Monday or 
thereabouts, I think.


Ahh I see, thanks.





Re: DConf 2017 Day 3 Livestream

2017-05-06 Thread Joshua Niehus via Digitalmars-d-announce

On Saturday, 6 May 2017 at 08:03:11 UTC, Mike Parker wrote:

https://www.youtube.com/watch?v=XTtruC3D2Ag


Is anyone else having issues viewing the livestream?


Re: Performance of std.json

2014-06-01 Thread Joshua Niehus via Digitalmars-d

On Monday, 2 June 2014 at 00:18:19 UTC, David Soria Parra wrote:
Would it make sense to start thinking about using ujson4c as an 
external library, or maybe come up with a better 
implementation. I know Orvid has something and might add some 
analysis as to why std.json is slow. Any ideas or pointers as 
to how to start with that?


std.json is underpowered and in need of an overhaul.  In the mean 
time have you tried vibe.d's json?


http://vibed.org/api/vibe.data.json/



To deadalnix

2014-05-23 Thread Joshua Niehus via Digitalmars-d
watching your talk was like witnessing Fermats last theorem being 
proven...


the scheduler solution was brilliant and the semantic analysis of 
a mixin statement that resulted in a comprehensible error message 
blew my mind.


Here is a belated applause that should have happened during those 
slides.


Well done.

josh


idup class

2014-05-16 Thread Joshua Niehus via Digitalmars-d-learn

trying to follow:
http://ddili.org/ders/d.en/class.html

//--- OSX 10.9 DMD 2.065
module test;

class Foo {
 int num;

 this(int num) {
 this.num = num;
 }

 Foo dup() const {
 return new Foo(this.num);
 }

 immutable(Foo) idup() const {
 return new immutable(Foo)(this.num);
 }
}

void main() {
 auto  foo = new Foo(1);
 auto mfoo = foo.dup();
 auto ifoo = foo.idup();
}

* test.d(15): Error: mutable method test.Foo.this is not callable
using a immutable object
* test.d(15): Error: no constructor for Foo
* Failed: [dmd, -v, -o-, test.d, -I.]
//---

What am i missing?


Re: idup class

2014-05-16 Thread Joshua Niehus via Digitalmars-d-learn

On Friday, 16 May 2014 at 20:36:37 UTC, Ali Çehreli wrote:


My apologies. The code was written for an older version of dmd. 
The simplest fix is to define the constructor as pure:


 pure this(int num) {
 this.num = num;
 }

Ali


Ahh great thanks guys.
No worries Ali, great book, i refer to it all the time :)


Re: [OT] DConf - How to survive without a car?

2014-05-14 Thread Joshua Niehus via Digitalmars-d
On Wednesday, 14 May 2014 at 21:31:08 UTC, Jeremy Powers via 
Digitalmars-d wrote:


Excellent. I need a lift if possible? Of so please tell me 
when I should

be in the aloft lobby?



This seems to still be an open question - what time to gather?


I'll be there between 8am and 8:15am and will have 3 seats 
available


(want to get there in time for breakfast)



Re: [OT] DConf - How to survive without a car?

2014-05-09 Thread Joshua Niehus via Digitalmars-d

I live in the area and will be driving by Aloft on my way to FB.
I can fit 3 other people (sliver Rav4).  Ill just pull up with a
clever D theme sign on my car and pick up any stragglers if
needed.


Re: core.sync.rwmutex example

2014-05-09 Thread Joshua Niehus via Digitalmars-d-learn

Hi Charles,

would the following work (just a shot in the dark) ?

//---
module test;

import std.stdio;
import std.concurrency;

void spawnedFuncFoo(Tid tid, Tid tidBar) {
 receive(
 (int i) {
 writeln(Foo Received the number , i);
 send(tidBar, i, thisTid);
 auto barSuccessful = receiveOnly!(string);
 writeln(Bar got my (Foo) message);
 }
 );

 send(tid, true);
}

void spawnedFuncBar(Tid tid) {
 receive(
 (int i, Tid tidFoo) {
 writeln(Foo passed me (Bar) the number , i);
 send(tidFoo, done);
 }
 );

 receive(
 (string sig) {
 writeln(Main says I'm (Bar) done.);
 send(tid, 42);
 }
 );
}

void main() {
 auto tidBar = spawn(spawnedFuncBar, thisTid);
 auto tidFoo = spawn(spawnedFuncFoo, thisTid, tidBar);
 send(tidFoo, 42);
 auto fooWasSuccessful = receiveOnly!(bool);
 assert(fooWasSuccessful);

 send(tidBar, your done);
 auto barWasSuccessful = receiveOnly!(int);
 assert(barWasSuccessful == 42);
 writeln(Successfully had two separate threads communicate
with each other);
}
//---


Atom text editor

2014-05-06 Thread Joshua Niehus via Digitalmars-d-learn

FYI:

If anyone is using GitHub's text editor Atom and would like
basic D syntax highlighting:

apm init --package ~/.atom/packages/language-d --convert
https://github.com/textmate/d.tmbundle

https://atom.io/docs/v0.94.0/converting-a-text-mate-bundle


Re: OT: Your accomplishments in 2013 and plans for 2014

2013-12-11 Thread Joshua Niehus
On Wednesday, 11 December 2013 at 19:45:25 UTC, Andrej Mitrovic 
wrote:

As for my future plans, I'm hoping to land myself a nice
programming-related job next year.


I hear facebook and sociomantic are hiring ;)



Re: Lambda syntax for methods and functions

2013-12-10 Thread Joshua Niehus

On Saturday, 7 December 2013 at 17:29:43 UTC, bearophile wrote:
Even Ada2012 has a similar syntax. I think it's worth having in 
D.


The ER:
https://d.puremagic.com/issues/show_bug.cgi?id=7176

Bye,
bearophile


similar to dart, my 2nd favorite lang :)
https://www.dartlang.org/articles/idiomatic-dart/





Re: No household is perfect

2013-12-03 Thread Joshua Niehus

On Tuesday, 3 December 2013 at 22:28:26 UTC, H. S. Teoh wrote:

[snip] Then you can write:

Set a, b, c;
auto d = mixin(SetExpr!a ∪ (b ∩ c));
// The above line gets turned into:
// auto d = a.union(b.intersection(c));
// at compile-time.

So you can write your set expressions the natural way, *and* 
[snip]


This would make for a good blog post/wiki article.  Does one 
already exist?





Re: Building druntime on MAC OS X

2013-11-21 Thread Joshua Niehus
On Thursday, 21 November 2013 at 13:56:07 UTC, Jacob Carlborg 
wrote:
BTW, if you're able to figure out how to build the Mac OS X 
installer on Linux Walter would appreciate it. I failed to do 
that.


this might help:
https://github.com/hogliux/bomutils





Re: dmd 2.064.2

2013-11-05 Thread Joshua Niehus

On Tuesday, 5 November 2013 at 22:10:53 UTC, Joshua Niehus wrote:
On Tuesday, 5 November 2013 at 22:08:48 UTC, Walter Bright 
wrote:

Ok, this is it:

http://ftp.digitalmars.com/dmd.2.064.2.dmg


Not found :(


nvm, just started working...
apologies


Re: dmd 2.064.2

2013-11-05 Thread Joshua Niehus

On Tuesday, 5 November 2013 at 22:08:48 UTC, Walter Bright wrote:

Ok, this is it:

http://ftp.digitalmars.com/dmd.2.064.2.dmg


Not found :(

http://d.puremagic.com/issues/show_bug.cgi?id=2

still open :(


Re: Anyone used LLVM-D with Dub?

2013-10-02 Thread Joshua Niehus

On Wednesday, 2 October 2013 at 02:22:42 UTC, Alan wrote:

Hello! I'm working on a project and I was going to use LLVM ...
[...snip..]
I want to know if anyone here has any experience witht his by 
any chance? The source of the problem? Is it a bug? Thanks for 
any suggestions.


Sorry, I haven't tried it, but you're more likely to get positive 
responses on the vibe.d forum:

http://forum.rejectedsoftware.com/


fedora libcurl-gnutls issue

2013-09-27 Thread Joshua Niehus

http://d.puremagic.com/issues/show_bug.cgi?id=10710

Does anyone know if there is there a workaround for this issue?
Unfortunately Im stuck with fedora and cant jump to another OS...

Thanks


Re: fedora libcurl-gnutls issue

2013-09-27 Thread Joshua Niehus

On Friday, 27 September 2013 at 16:52:49 UTC, Dicebot wrote:
Simply building dmd/phobos from git tag should result in proper 
linkage.


Nothing is ever simple with me :)

Thanks Dejan and Dicebot



Re: Improved Phobos dox

2013-09-16 Thread Joshua Niehus

On Sunday, 15 September 2013 at 18:38:54 UTC, Sönke Ludwig wrote:


Just as a reminder, this is the current version:
http://vibed.org/temp/d-programming-language.org/phobos/std/array.html


This is way better
+1


Re: dub: should we make it the de jure package manager for D?

2013-09-10 Thread Joshua Niehus
On Tuesday, 10 September 2013 at 20:48:58 UTC, Andrei 
Alexandrescu wrote:
We're considering making dub the official package manager for 
D. What do you all think?


This would be awesome.
+1



Re: The definitive guide to Trolls (was Move VisualD to github).

2013-09-09 Thread Joshua Niehus

-- sycophant (wishes he was an Ent)


Re: Programming in D book is about 88% translated

2013-06-29 Thread Joshua Niehus

On Saturday, 29 June 2013 at 02:02:26 UTC, Ali Çehreli wrote:

I have continued with the translation of the book [snip]


excellent.  Keep up the good work Ali!



Re: DMD 2.063.2 now up

2013-06-18 Thread Joshua Niehus

On Tuesday, 18 June 2013 at 13:52:25 UTC, Gary Willoughby wrote:

Thanks, but Mac OS has a broken download link.


time to open a More Mac Love? thread...



Re: Path as an object in std.path

2013-06-05 Thread Joshua Niehus

On Wednesday, 5 June 2013 at 06:27:46 UTC, Dylan Knutson wrote:
which exposes a much more palatable interface to path string 
manipulation.

[...snip...]
I'd like some feedback on what others think about this;


personally, I prefer the current implementation and found it easy 
to use for the multitudes of tiny scripts I've written.  I 
wouldn't like to create an object just to call isAbsolute.


That being said, I don't see why having the struct would hurt.

Nice work by the way






Re: The stately := operator feature proposal

2013-06-05 Thread Joshua Niehus

On Thursday, 30 May 2013 at 13:13:02 UTC, MrzlganeE wrote:

I hate you all, and with this, I exit the D community


ooo, a sensitive troll...

There was a time when D didn't have the sugary lambda syntax: =
I think that turned out nicely.
(maybe someone already mentioned this in the thread, didn't see 
it)


I'm also in favor of :=




Re: D's limited template specialization abilities compared to C++

2013-05-25 Thread Joshua Niehus

On Saturday, 25 May 2013 at 16:27:59 UTC, deadalnix wrote:

Hi, I obviously don't know D that much, but I assume I do.
[..snip..]


chuckle

+1




Re: Vote for std.uni

2013-05-20 Thread Joshua Niehus

On Monday, 20 May 2013 at 06:18:15 UTC, Jesse Phillips wrote:

Sunday April 26 PST will be the last day of voting.


2014?

vote: yes


Re: Low-Lock Singletons In D

2013-05-05 Thread Joshua Niehus

On Monday, 6 May 2013 at 02:35:33 UTC, dsimcha wrote:

Article:
http://davesdprogramming.wordpress.com/2013/05/06/low-lock-singletons/

Reddit:
http://www.reddit.com/r/programming/comments/1droaa/lowlock_singletons_in_d_the_singleton_pattern/


Excellent talk at the conf, solid blog: +1 and 1


Re: Reducing the inter-dependencies (in Phobos and at large)

2013-04-24 Thread Joshua Niehus
On Wednesday, 24 April 2013 at 12:03:52 UTC, Dmitry Olshansky 
wrote:
E.g. std.regex would import std.concept.random to get 
isUniformRNG and rely on duck typing thusly described to use it 
correctly.

Thoughts? Other ideas?


how would this be different then limited imports such as:
import std.random: isUniformRNG;
?


Re: Vote for std.process

2013-04-12 Thread Joshua Niehus

yes



Re: OSX users out there? Serious bug (I think)

2013-03-31 Thread Joshua Niehus

On Sunday, 31 March 2013 at 20:02:40 UTC, monarch_dodra wrote:

This is a two part post.

First, I wanted to pol how many users out there were developing 
under OSX? The threads seem to indicated users under windows or 
Linux, but I've never heard of anybody under OSX. So who has or 
is developing under OSX? Anybody?

[snip]


I use osx as well.
most of the things i do are small toy programs.  Though i do play 
around with vibe a bit and never had any major issue.




Re: T-shirt design

2013-03-18 Thread Joshua Niehus

ill be wearing the losers TShirt:

https://www.dropbox.com/s/vr5cmklgjpiomgk/dconfTShirt.png


Re: T-shirt design

2013-03-18 Thread Joshua Niehus

On Tuesday, 19 March 2013 at 05:02:36 UTC, deadalnix wrote:

I like it as well. Did you printed it already ?


not yet, i was mocking up the design (after some feedback*) on a 
custom t-shirt website. I'll probably order it next week or so; 
wear it around for humor's sake.


* can't believe people were so put-off by brown, its very 
fashionable!


Re: T-shirt design

2013-03-06 Thread Joshua Niehus
On Wednesday, 6 March 2013 at 20:58:35 UTC, Andrei Alexandrescu 
wrote:

Hi everyone,


Time to design the DConf 2013 T-shirts! Please reply to this 
with any ideas you may have.


I have some ideas, but I'm sure they're not the best one. 
Destroy!



Thanks,

Andrei


Here is my design:

https://docs.google.com/file/d/0B6Ql34B0g27ZZ3JRMFVEQ3VIbGc/edit


Re: DIP27 available for destruction

2013-02-26 Thread Joshua Niehus
On Tuesday, 26 February 2013 at 18:27:13 UTC, Andrej Mitrovic 
wrote:
Where's the link? I don't see it listed: 
http://wiki.dlang.org/DIPs


just added:
http://wiki.dlang.org/DIP27


Transitional measure to mitigate breakage

// Transitional behavior.
static assert(is(typeof(foo) == void function());

// Error (foo has no address). Final behavior
static assert(is(typeof(foo) == void function());

are these supposed to be different?


Re: What happened to the alias this = identifier syntax in 2.062?

2013-02-22 Thread Joshua Niehus

On Friday, 22 February 2013 at 21:23:04 UTC, Timon Gehr wrote:
[snip].. or the alias this syntax should be deprecated in 
favour of a specially named member function.


pseudonym foo;




Re: What happened to the alias this = identifier syntax in 2.062?

2013-02-22 Thread Joshua Niehus

On Friday, 22 February 2013 at 23:20:55 UTC, Timon Gehr wrote:


auto opPseudonym() { ... }

alias opPseudonym=foo;


Isn't that creating multiple functions for the same thing?

shamelessly copies Ali's example
struct Fraction
{
long numerator;
long denominator;

double value() const @property
{
return cast(double)numerator / denominator;
}

alias this = value;
}

as opposed to:

struct Fraction
{
long numerator;
long denominator;

double value() const @property
{
return cast(double)numerator / denominator;
}

@pseudonym value;
   // in the year 2000...
@pseudonym value, value2, value3;
}


Re: What happened to the alias this = identifier syntax in 2.062?

2013-02-22 Thread Joshua Niehus

didn't fully formulate that thought:

above examples vs. the following

struct Fraction
{
long numerator;
long denominator;

double value() const @property
{
return cast(double)numerator / denominator;
}

auto opPseudonym() { /* points to value() ? */ }
alias opPsuedonym=value;  // ??
}



Re: D 2.062 release

2013-02-18 Thread Joshua Niehus

On Monday, 18 February 2013 at 07:31:53 UTC, Walter Bright wrote:

As long as it isn't written in Ruby :-)

But more seriously, a D tool to do it might be interesting.


Here is a simpleton hack:

### RUBY
require nokogiri
require open-uri

# provided the urls are given
changes_new_features_url = http://...blah blah...
d_runtime_fixes_url = http://...blah blah...
phobos_fixes_url = http://...blah blah...

def get_summaries(url)
summaries = []
page  = Nokogiri::HTML(open(url))
table = page.css(.bz_buglist)
rows  = table.css(tr)
rows.each do |row|
summary = row.css(td:last-child).text.strip
summaries   summary if !summary.empty?
end
summaries
end

puts \nChanges and New Features:
puts get_summaries(changes_new_features_url)
puts \nD Runtime Fixes:
puts get_summaries(d_runtime_fixes_url)
puts \nPhobos Fixes:
puts get_summaries(phobos_fixes_url)

### END

I guess the correct approach is to use Bugzilla's REST api, but 
its 1am... and this might be good enough?


A Mathematician looks at D

2013-02-18 Thread Joshua Niehus

http://www.reddit.com/r/programming/comments/18r7zk/a_mathematician_looks_at_d/

No REPL, I guess we are rubbish?


Re: A Mathematician looks at D

2013-02-18 Thread Joshua Niehus
Personally I find REPLs super annoying, especially when you need 
to import or require something or like to use multiple lines. 
 Serious how hard is it to just do:


### Ruby
#!/usr/bin/ruby
require pp

puts do stuff

// D
#!/usr/bin/rdmd
import std.stdio;

void main() {
writeln(do stuff);
}

then press Command+b (Sublime text) and watch it work/fail?



Re: D for scientific computing

2013-01-23 Thread Joshua Niehus

On Wednesday, 23 January 2013 at 22:39:04 UTC, Alan wrote:

to know if D can compete with C or Fortran for numerical work.


https://github.com/kyllingstad/scid

You dont need to compete, you can take established good and 
fast FORTRAN/C code and use it within your own D program.


Re: D for scientific computing

2013-01-23 Thread Joshua Niehus

On Thursday, 24 January 2013 at 00:29:15 UTC, Joshua Niehus wrote:
You dont need to compete, you can take established good and 
fast FORTRAN/C code and use it within your own D program.


I forgot to add:
If you doing new stuff then D can be as fast as anything eles, 
provided the algorithm is sound, optimizers turned on, sprinkle 
in a lil asembly, etc...


shared std.signals

2013-01-22 Thread Joshua Niehus

Is it possible to create a shared signal class?
I  would like to create a shared signal class so some other 
process that knows certain things can come along emit its info to 
any observer:


import std.stdio, std.signals;

class Observer {
void watch(string msg) {
writeln(msg);
}
}

class Foo {
string value() {
return _value;
}

string value(string v) {
if (v != _value) {
_value = v;
emit(_value);
}
return v;
}

mixin Signal!(string);

private:
string _value;
}

shared Foo a;
void main() {
a = new shared Foo();
Observer o1 = new Observer();
a.connect(o1.watch);
}


Re: shared std.signals

2013-01-22 Thread Joshua Niehus
On Wednesday, 23 January 2013 at 07:11:59 UTC, Joshua Niehus 
wrote:

Is it possible to create a shared signal class?


oh god... dont tell me __gshared !
Think i answered my own question, it got me to the next step.  
going to have to read through those giant shared threads again




Re: D rawkz! -- custom writefln formats

2013-01-16 Thread Joshua Niehus
On Wednesday, 16 January 2013 at 19:49:55 UTC, Philippe Sigaud 
wrote:
What about creating a new page on the Wiki (D Rawks) and 
putting small
articles in them? That way, we can all do it without having a 
website

and newcomers can be shown its content.


http://wiki.dlang.org/D_Rocks


Re: Mac OS installer

2013-01-07 Thread Joshua Niehus

On Tuesday, 8 January 2013 at 04:00:25 UTC, Elias Zamaria wrote:

Can anyone help me with this?


Do you have Xcode installed?
If so, do you have Command Line Tools installed?
Otherwise, you'll need to install Xcode (free from app store), 
then:
Open Xcode - Preferences - Downloads - Components - Command 
Line Tools


related thread:
http://forum.dlang.org/thread/nxawipcegdmbkqkal...@forum.dlang.org



Re: Help me write saveAll

2012-12-21 Thread Joshua Niehus

On Friday, 21 December 2012 at 17:01:14 UTC, monarch_dodra wrote:
There are a lot of algorithms in std.algorithm that operate on 
foo(Range, Needles...)(Range range, Needles needles).


Needles can be anything, in particular, either an element or 
a range.


The thing is that every now and then, you want to save the 
entirety of (the ranges) inside needles. EG, I want to be able 
to write:

foo(range, needles.saveAll);
[...snip...]
Any thought on how do get this working?
size_t r = startsWith!pred(haystack, needles.saveAll);


Sorry if im misunderstanding, but doesn't filter do this?
Example:
import std.stdio, std.algorithm, std.range;
void main() {
auto x = [
[1, 2, 3],
[4, 5, 6],
[7, 8, 9],
[10, 11, 12]
];
//haystack   // needle  // 
needle
auto y = x.filter!(a = (a == [4, 5, 6] || a == [7, 8, 
9])).array;

y.writeln;
}


Re: [OT] Three Optimization Tips for C++

2012-12-20 Thread Joshua Niehus
On Thursday, 20 December 2012 at 05:29:46 UTC, Andrei 
Alexandrescu wrote:

Vote up!


http://www.reddit.com/r/programming/comments/155ivw/three_optimization_tips_for_c_video/

Andrei


Almost 2 years ago, I stumbled across your book at a BarnesNobel 
and began my journey with D. It turns out its an unsigned copy. 
 Any chance you'll sign it at the DConf?


Re: Invalid trainling code unit

2012-12-14 Thread Joshua Niehus

On Saturday, 15 December 2012 at 06:07:10 UTC, rumbu wrote:
I'm trying to understand how strings are working in D. I got 
the following error when declaring a simple string variable: 
Invalid trailing code unit:


wstring needle = `Être sans la verité`;

Considering that the line obove is copied exactl from the site 
examples, what I'm doing wrong?


works for me and on the DPaste site:
http://dpaste.dzfl.pl/00b66ba8

what platform are you on and what version of D are you using?
are you passing any compiler flags or just running plain ol' 
$rdmd test.d ?




Dr. Dobbs

2012-12-13 Thread Joshua Niehus

in case anyone missed it:

http://www.drdobbs.com/cpp/porting-the-d-compiler-to-win64/240144208


Re: Experimental Phobos modules?

2012-12-05 Thread Joshua Niehus
On Wednesday, 5 December 2012 at 21:05:30 UTC, Jonathan M Davis 
wrote:
But I think that that's completely inappropriate for putting 
into Phobos.


I'd love to try out the new stuff if its convient enough...
I dont want to go jumping around github, pick up the staging 
material, put it into my current dev system and then play.

It would be *much* nicer if its part of Phobos



Re: Deprecated Library Functions / Methods

2012-12-02 Thread Joshua Niehus
On Sunday, 2 December 2012 at 23:56:29 UTC, Jonathan M Davis 
wrote:

[... breath snip /breath ...]

I don't like leaving clutter in code, and in this case, I think 
that it's safe

and reasonable to clean up that clutter.

- Jonathan M Davis


+1




Re: prune with dirEntries

2012-11-30 Thread Joshua Niehus

On Friday, 30 November 2012 at 12:02:51 UTC, Dan wrote:
Good idea, thanks. I could not get original to compile as is - 
but the concept is just what was needed. I got an error on line 
8:
Error: not a property dirEntries(path, cast(SpanMode)0, 
true).filter!(__lambda2)

I'm using a quite recent version of dmd and phobos.


hmm strange... I'm using 2.060 (on a mac),

But, I pulled the lamda out into a function and it works great. 
I assume the parallel is for performance, and it actually runs 
significantly slower than without on my test case - but no work 
is being done other than build the list of files, so that is 
probably normal. For my case the breakdown is:


No Pruning: 11 sec
Pruning Parallel: 4.78 sec
Pruning Serial: 0.377 sec


Thats cool.
Yea I thought parallel would make a big difference (in the 
positive sense) for large directories, but I guess if we are 
recursively spawning parallel tasks, the overhead involved starts 
accumulating, resulting in worse performance (my best guess 
anyway).





Re: prune with dirEntries

2012-11-29 Thread Joshua Niehus

On Friday, 30 November 2012 at 01:57:21 UTC, Dan wrote:
That will do the filtering correctly - but what I was hoping 
was to actually prune at the directory level and not drill down 
to the files in of an unwanted directory (e.g. .git). The 
problem with this and what I'm trying to overcome is accessing 
lots of files and directories recursively all of which I want 
to skip. Much like there is a *followSymlink* it would be nice 
if a predicate were accepted to *followDirectory* in general or 
some way to cause that.


what about the following?

import std.algorithm, std.array, std.regex;
import std.stdio, std.file;
void main()
{
  auto exclude = regex(r\.git, g);
  dirEntries(/path/GIT, SpanMode.breadth)
.filter!(a = match(a.name, exclude).empty)
.writeln();
}

I think if you go breadth first, you can filter out the unwanted 
directories before it delves into them




Re: prune with dirEntries

2012-11-29 Thread Joshua Niehus

On Friday, 30 November 2012 at 06:29:01 UTC, Joshua Niehus wrote:
I think if you go breadth first, you can filter out the 
unwanted directories before it delves into them


oh wait... it probably still looks through all those dir's.
What about this?

import std.algorithm, std.regex, std.stdio, std.file;
import std.parallelism;
DirEntry[] prune(string path, ref DirEntry[] files)
{
  auto exclude = regex(r\.git|\.DS_Store, g);
  foreach(_path; taskPool.parallel(dirEntries(path, 
SpanMode.shallow)

.filter!(a = match(a.name, exclude).empty)))
  {
files ~= _path;
if (isDir(_path.name)) { prune(_path.name, files); }
  }
return files;
}

void main()
{
  DirEntry[] files;
  prune(/path, files);
  foreach(file;files) { writeln(file.name); }
}



Re: path matching problem

2012-11-27 Thread Joshua Niehus
On Tuesday, 27 November 2012 at 19:40:56 UTC, Charles Hixson 
wrote:
Is there a better way to do this?  (I want to find files that 
match any of some extensions and don't match any of several 
other strings, or are not in some directories.):


 import std.file;

...

 string  exts  =  *.{txt,utf8,utf-8,TXT,UTF8,UTF-8};
 string[]  exclude  =  [/template/,  biblio.txt,  
categories.txt,

subjects.txt,  /toCDROM/]

 int  limit  =  1
 //  Iterate  a  directory  in  depth
 foreach  (string  name;  dirEntries(sDir,  exts,  
SpanMode.depth))

 {  bool  excl  =  false;
foreach  (string  part;  exclude)
{  if  (part  in  name)
   {  excl  =  true;
  break;
   }
}
if  (excl)  break;
etc.


maybe this:?

import std.algorithm, std.array, std.regex;
import std.stdio, std.file;
void main()
{
enum string[] exts  =  [`.txt`, `.utf8`, `.utf-8`, 
`.TXT`, `.UTF8`, `.UTF-8`];
enum string exclude = 
`r/template/|biblio\.txt|categories\.txt|subjects\.txt|/toCDROM/`;


auto x = dirEntries(/path, SpanMode.depth)
.filter!(`endsWith(a.name,` ~ exts.join(,) ~ `)`)
.filter!(`std.regex.match(a.name,` ~ exclude ~ 
`).empty`);;


writeln(x);
}


Re: path matching problem

2012-11-27 Thread Joshua Niehus
On Tuesday, 27 November 2012 at 23:43:43 UTC, Charles Hixson 
wrote:
But why the chained filters, rather than using the option 
provided by dirEntries for one of them?  Is it faster?  Just 
the way you usually do things? (Which I accept as a legitimate 
answer.  I can see that that approach would be more flexible.)


Ignorance...
Your right, I didn't realize that dirEntries had that filter 
option, you should use that.  I doubt the double .filter would 
effect performance at all (might even slow it down for all i know 
:)


//update:
import std.algorithm, std.array, std.regex;
import std.stdio, std.file;
void main()
{
  string exts = *.{txt,utf8,utf-8,TXT,UTF8,UTF-8};
  enum string exclude =

`r/template/|biblio\.txt|categories\.txt|subjects\.txt|/toCDROM/`;


  dirEntries(/path, exts, SpanMode.depth)
.filter!(` std.regex.match(a.name,` ~ exclude ~ `).empty `)
.writeln();
}



Re: Converting a number to complex

2012-11-25 Thread Joshua Niehus
On Saturday, 24 November 2012 at 07:27:18 UTC, Philippe Sigaud 
wrote:
It's an is() expression (you cited my tutorial, there is an 
appendix on
it). It recently became even more powerful, so the tutorial is 
not accurate

any more.


its time for another read through:)
Template constraints might make for a good talk at the conf...



Re: Converting a number to complex

2012-11-23 Thread Joshua Niehus
On Friday, 23 November 2012 at 12:39:59 UTC, Frederik Vagner 
wrote:

Now do it for complex number please ^^


touche!

import std.stdio, std.conv, std.traits, std.complex;

template isComplexNumeric(T)
{
static if(is(NumericTypeOf!T)) {
enum bool isComplexNumeric = is(NumericTypeOf!T);
}
else static if (is(T == Complex!double))
{
enum bool isComplexNumeric = is(Complex!double);
}
// fillin real and float here... (e.g. is(Complex!real); 
etc...

}

class Example(T) if (isComplexNumeric!T)
{
T k = to!T(1);
}

void main()
{
auto x = new Example!(Complex!double)();
writeln(x.k);
auto y = new Example!double();
writeln(y.k);
auto z = new Example!string(); // fail
writeln(z.k);
}

A bit messy, but im sure there is some room for cleanup 
somewhere...





Re: Converting a number to complex

2012-11-23 Thread Joshua Niehus

On Friday, 23 November 2012 at 16:11:25 UTC, Joshua Niehus wrote:
A bit messy, but im sure there is some room for cleanup 
somewhere...


Errata... (what i get for copy/pasting)

import std.stdio, std.conv, std.traits, std.complex;
template isComplexNumeric(T)
{
static if(isNumeric!T) {
enum bool isComplexNumeric = true;
}
else static if (is(T == Complex!double))
{
enum bool isComplexNumeric = true;
}
else {
enum bool isComplexNumeric = false;
}
}

class Example(T) if (isComplexNumeric!T)
{
T k = to!T(1);
}

void main()
{
auto x = new Example!(Complex!double)();
writeln(x.k);
auto y = new Example!double();
writeln(y.k);
auto z = new Example!string();
writeln(z.k);
}

i did have to reference Philippe Sigaud's excellent book on 
Templates several times:

https://github.com/PhilippeSigaud/D-templates-tutorial/blob/master/dtemplates.pdf



Re: Converting a number to complex

2012-11-23 Thread Joshua Niehus

meh, couldn't resist:

import std.stdio, std.conv, std.traits, std.complex;
template isComplex(T)
{
static if (is(T == Complex!double))
{
enum bool isComplex = true;
}
else static if (is(T == Complex!float))
{
enum bool isComplex = true;
}
else static if (is(T == Complex!real))
{
enum bool isComplex = true;
}
else {
enum bool isComplex = false;
}
}

template isComplexOrNumeric(T)
{
enum bool isComplexOrNumeric = (isComplex!T || isNumeric!T);
}

class Example(T) if (isComplexOrNumeric!T)
{
T k = to!T(1);
}



Re: Converting a number to complex

2012-11-23 Thread Joshua Niehus

On Friday, 23 November 2012 at 18:45:53 UTC, Artur Skawina wrote:

   template isComplex(T) {
  static if (is(T _ == Complex!CT, CT))
 enum isComplex = true;
  else
 enum isComplex = false;
   }

artur


oh wow didnt know u could do that. much nicer.



Re: Converting a number to complex

2012-11-22 Thread Joshua Niehus
On Thursday, 22 November 2012 at 15:47:11 UTC, Frederik Vagner 
wrote:
I am trying to make a templated class to accept any numeric 
type:


class example(Type) if (isNumeric(Type))
{
Type k = to!Type(1);

}

however I always get a compiler erro stating I cannot make that 
conversion. How do I fix it?


// phobos
import std.stdio, std.conv, std.traits;
class Example(T) if (isNumeric!T)
{
T k = to!T(1);
}

void main()
{
auto x = new Example!double();
writeln(x.k);
}


Re: Talk proposal (kinda): D Programming in D (Or: Writing idiomatic D code)

2012-11-21 Thread Joshua Niehus
On Wednesday, 21 November 2012 at 18:42:55 UTC, Leandro Motta 
Barros wrote:
Well, this is actually a talk proposal for someone else. I'd 
be the

audience, not the speaker.

TITLE: D Programming in D (Or: Writing idiomatic D code)


+1

I'd like to add, maybe put some focus on Range oriented coding 
seeing as Phobos is full or ranges etc...




Re: DConf 2013 on kickstarter.com: we made it!

2012-11-20 Thread Joshua Niehus

On Tuesday, 20 November 2012 at 20:23:56 UTC, Iain Buclaw wrote:
I got tired of the suspense, so I pledged the remainder $550 to 
push you over the finish line.


http://www.kickstarter.com/projects/2083649206/the-d-programming-language-conference-2013-0


Lets hold a big congrats to Andrei and Walter.  Look forward to 
seeing you all in April/May.


Awesome :)




Re: OSX Installer

2012-11-01 Thread Joshua Niehus
On Thursday, 1 November 2012 at 07:30:58 UTC, Jacob Carlborg 
wrote:
It's not just the installer that depends on having Xcode 
installed, D depends on it. DMD uses GCC as the linker.


I see, thanks Jacob.  I'll stick with the Xcode-cmd line tools 
instructions then and sprinkle in a little more detail about why.





OSX Installer

2012-10-31 Thread Joshua Niehus
I'm trying to write up a tutorial for D+vibed and have stumbled 
on a pretty basic issue.  The DMD installer for OSX fails out of 
the box on Lion and Mountain Lion because Apple got rid of their 
developer command line tools stuff:

http://robots.thoughtbot.com/post/27985816073/the-hitchhikers-guide-to-riding-a-mountain-lion

So basically the install process for new mac users is:
1. Get Xcode
2. Install Command Line tools via Xcode preferences
3. Run DMD mac installer

Obvious first question:
D needs Xcode to run? sigh

Is this going to be fixed in the next release or should I just 
point to the .zip package instead?


Thanks,
Josh




std.concurrency msg passing

2012-10-18 Thread Joshua Niehus

Is the following snippet a bug?

---
import core.thread;
import std.stdio, std.concurrency;

void foo(Tid tid) {
send(tid, true);
}

void main() {
auto fooTid = spawn(foo, thisTid);
auto receiveInt = receiveTimeout(dur!seconds(10), (int 
isInt) {

writeln(I should not be here);
});
}
// output: I should not be here
---

If not, is there some way I could achieve 
receiveOnlyTimeout!(int)(dur, fun); ?


Thanks,
Josh


Re: std.concurrency msg passing

2012-10-18 Thread Joshua Niehus

On Thursday, 18 October 2012 at 17:33:04 UTC, cal wrote:

I can't see the bug? The receiver accepts a bool as an int,
same way a normal function does. The timeout is long enough 
that foo gets a chance to send.  If you want to stop the int 
receiver getting a bool, you could add another receiver with 
(bool) { // do nothing } or whatever before the (int) one, 
which will be a better match for the send.


I got myself into a situation where I dont know which will be 
called first, the int or the bool and when the call happens 
matters.


It was my assumption that receiveTimeout(dur, (type){}); would 
distinguish between a bool and an int like it does for float and 
int.  But I can see why it would treat true/false as 0/1, so not 
a bug.


Anyway my current workaround is to define a few Signal structs 
and use those instead:

struct SignalReady { blah }
struct SignalXDone { blah }
struct SignalYDone { blah }

Thanks for the reply.





Re: clear() and UFCS

2012-05-25 Thread Joshua Niehus
I take it back, dispose is no good.  That should be the name of 
the deterministic destructor in the object.


Now I don't have a good name.  Finalize isn't right, and 
neither is dispose...


-Steve


disembowel?


Re: Mono-D 0.3.5

2012-04-04 Thread Joshua Niehus

On Monday, 26 March 2012 at 23:57:27 UTC, alex wrote:

Couple of bug fixes + new refactoring feature:

[snip]


Got it up and running on my Mac. Awesome job, thanks

josh


Re: Three Unlikely Successful Features of D

2012-03-21 Thread Joshua Niehus
On Tuesday, 20 March 2012 at 19:02:16 UTC, Andrei Alexandrescu 
wrote:
What are your faves? I have a few in mind, but wouldn't want to 
influence answers.


Thanks,

Andrei


1) inferred types (auto)
2) slices
3) whole  sum(mixin, opDispatch, static if)




Re: regex issue

2012-03-16 Thread Joshua Niehus

On Friday, 16 March 2012 at 08:34:18 UTC, Dmitry Olshansky wrote:
Ehm, because they have different engines that _should_ give 
identical results. And the default one apparently has a bug, 
that I'm looking into.

Fill the bug report plz.


Ok, submitted: id 7718

Thanks,
Josh


Re: Compiling DMD on MAC OS X

2012-02-29 Thread Joshua Niehus
On Monday, 20 February 2012 at 11:18:34 UTC, Tyro[a.c.edwards] 
wrote:

...

and I doubt you want me to put all of what dmd -v spits out 
for this little script.


Thanks,
Andrew


Hi Andrew,

I ran into this problem as well and here is how I fixed/hacked it:
OSX Lion, and soon to be Mountain Lion, no longer come with GCC 
installed for the Command Line (/usr/bin/gcc)
What you need to do is Install Xcode from the app store, which is 
free, and then:

  * Launch your Xcode 4.1
  * Go to preferences  Downloads
  * Click on the install button near the Command line tools

This will put gcc in your /usr/bin directory.

Then try to recompile your code.

-- the new mac installer on the website should probably come with 
gcc or check for dependencies


Josh


Reflection

2012-02-27 Thread Joshua Niehus

Hello,

I dont understand the following snippet's output:

import std.stdio, std.traits;
void main() {
writeln(isSomeFunction!(writeln));
writeln(isCallable!(writeln));
writeln(Yes I am...);
}

/* OUTPUT */
false
false
Yes I am...

If 'writeln' isn't a method/function and it's not callable, then 
what is it?


Thanks,
Josh


Re: Reflection

2012-02-27 Thread Joshua Niehus
On Tuesday, 28 February 2012 at 06:10:11 UTC, Jesse Phillips 
wrote:

It is a template.


I see, thanks.
And I bet its not possible to figure out if a template is a 
function template or a class template etc...





Syntax highlighting for CodeRunner

2012-02-26 Thread Joshua Niehus
In the off chance that some of you are running a Mac and using 
CodeRunner to play around with D, I cooked up the files you need 
for CodeRunner to highlight D's syntax:

https://github.com/jniehus/Dlang-for-CodeRunner


Re: [your code here]

2012-02-18 Thread Joshua Niehus
On Saturday, 18 February 2012 at 08:18:32 UTC, Denis Shelomovskij 
wrote:

Some remarks:
0. `string[] args` isn't needed;
1. `delegate` is not needed;
2. `isSomeString!(T)` can be replaced by `isSomeString!T`;
3. `static if` can be replaced by `auto m = 
mixin(isSomeString!T ? n ~ i : n + i);`;

4. With nnew `=` syntax function body can be replaced by
`return (T i) = mixin(isSomeString!T ? n ~ i : n + i);`
or
`return (T i) = mixin(n ~ (isSomeString!T ? '~' : '+') ~ 
'i');`



So your code can looks like this:
---
import std.stdio, std.traits;

void main() {
auto foo(T)(T n) {
return (T i) = mixin(n ~ (isSomeString!T ? '~' : 
'+') ~ 'i');

}
writeln(foo(Hello)( World!));
writeln(foo(18)(24));
}

IMHO, all these three versions should be on the site grouped 
somehow (i.e. one can navigate between analogous).


Ahhh, thats much cleaner, thanks.


[your code here]

2012-02-17 Thread Joshua Niehus
Not as fancy as the other submits, but it might be worthy of the 
front page:


import std.stdio, std.traits;

void main(string[] args) {
auto foo(T)(T n) {
return delegate(T i) {
static if (isSomeString!(T))
auto m = mixin(n ~ i);
else
auto m = mixin(n + i);
return m;
};
}
writeln(foo(Hello)( World!));
writeln(foo(18)(24));   }


Re: [your code here]

2012-01-28 Thread Joshua Niehus
import std.stdio, std.stream, std.string, std.range, 
std.algorithm;


void main() {
   int countPalindromes;
   auto infile = new BufferedFile(ukacd17.txt);
   foreach (char[] line; infile) {
   if (line.walkLength(2)  1) {
   line.toLowerInPlace;
   if (equal(line, retro(line)))
   countPalindromes++;
   }
   }
   writeln(palindromes found: , countPalindromes);
}


I ran this code on Mac OSX Lion using the /usr/share/dict/words 
file and got 235834 words out of 235886.  I think something is 
wrong.


Re: [your code here]

2012-01-28 Thread Joshua Niehus
I ran this code on Mac OSX Lion using the 
/usr/share/dict/words file and got 235834 words out of 
235886.  I think something is wrong.


found the problem: PEBKAC (problem exists between keyboard and 
chair)

sorry:)



Re: D for the web?

2012-01-23 Thread Joshua Niehus

On Monday, 23 January 2012 at 16:43:06 UTC, F i L wrote:
There are better languages for large client-side web apps like 
Coffeescript...


CoffeeScript is a little language that compiles into JavaScript



Waiting around

2012-01-09 Thread Joshua Niehus
Hello,

I need to connect to a network location and read a file but I also need
some way of waiting around until the connection is established.  Currently
I use the following snippet to do this:

while (!std.file.exists(/Volumes/mountedDir/myfile.txt)  timeout  30)
{
core.thread.Thread.sleep(10_000_000);  // core.thread.Thread
conflicts with std.regex.Thread, hence the full path reference
timeout++;
}

with the recent changes to std.regex it stopped compiling due to the
Thread conflict.  Is there a more obvious way to do what I'm doing that
avoids importing core.thread?

Thanks,
Josh


Java Scala - new thread: GUI for D

2011-12-02 Thread Joshua Niehus
On 12/1/11 2:59 AM, Walter Bright wrote:
 On 12/1/2011 2:42 AM, Gour wrote:
 I'd like to help with GUI bindings if D community would come more close
 together here with some people ready to lead the herd...

 Why not you lead the effort?

I just went to the Qt DevDays 2011 and it looks like a lot of work is
being done to get QML ready for desktop applications. Its Qt's next gen UI
framework and its JavaScript based (it looks pretty good).  It might be
worth while to investigate using QML as a UI frontend and use D code to
do the backend heavy lifting as opposed to C++.
I know there was a Qt port to D a while back, but it seems to have died
out or was buggy.  This might be much easier (im new to development so
forgive my naivety :)


File append limit?

2011-08-05 Thread Joshua Niehus
Hello,

I am running a script that creates a file which lists all the folders in a
directory:

foreach (string name; dirEntries(/Users/josh/, SpanMode.shallow)) {
append(/Users/dirList.txt, name ~ \n);
}

But it seems to stop appending after 255 lines (this particular folder has
350 folders in all).
When trying to read the created file:

   auto f = File(/Users/dirList.txt, r);
   foreach (string line; lines(f)) {
   writeln(line);
   }
   f.close();

It writes out the lines, but after the last one I get Bus error: 10

Any thoughts on what im missing or doing wrong?

I am currently using D 2.054 on Mac OSX Lion
The script was working with D 2.053 on Mac OSX Snow Leopard

Thanks,
Josh


Re: File append Limit

2011-08-05 Thread Joshua Niehus
@Kagamin

 What if

 foreach(i;0..512) {
  append(/Users/dirList.txt, text(line ,i,'\n'));
 }

That works, but I misrepresented the problem and found that the following
may be the issue (this looks more like the code im using):

import std.conv, std.stdio;

void main()
{
string[] strArr;
foreach(int i; 0 .. 257) {
strArr ~= text(Line:  ~ to!string(i));
}

foreach(string e; strArr) {
writeln(e);
}
}

// OUTPUT for first 87 lines
Line: 2
?O
?O
`O
@O
 O

?N
?N
...
ect
...
?@
?@
`@
0@

Line: 88
 /* rest of output is as expected */

Changing 257 to 256 gives you what you would expect.

Josh


Interfacing to C

2011-06-28 Thread Joshua Niehus
Hello,

I was trying to run the example on the Interfacing to C page (
http://www.d-programming-language.org/interfaceToC.html) and ran into few
issues. To get it to work as is i was .dup(ing) strings into new chars
with defined size and passing those with .ptr. Anyway it seemed like quite a
bit of work for something simple so I added const in the signatures and
things worked much more smoothly:

import std.stdio, std.string;

extern (C) int strcmp(const char* string1, const char* string2);

void main()
{
writeln(myDfunction(foo));
}

int myDfunction(const char[] s) {
return strcmp(std.string.toStringz(s), foo);
}

Was there a reason why the consts were left out?
if this is a typo I'd be happy to update the web page, would be good
experience for a noob like me. (never used GIT before and first time
participating in a community)

Thanks,
Josh


RE: dmdscript osx.mak

2011-06-19 Thread Joshua Niehus
Hi Robert and Dmitry,

Thanks for your replies and the heads up on the current status of DMDScript!

Josh


dmdscript osx.mak

2011-06-18 Thread Joshua Niehus
Hello,

I apologize if this is the wrong forum to post this question, but I couldn't
find a corresponding learn mailing list for DMDScript.

I wanted to play around with DMDScript but cant seem to get started.  I
downloaded the source and attempted to make it via:
$ make -f osx.mak

But I get the following error:
textgen.d(132): Error: cannot implicitly convert expression ~ some
string ~ of type string to char[]

Am I doing the right thing? Or how do I go about getting building 'ds' so I
can run simpleton scripts?

Josh


Re: dmd vs rdmd

2011-06-13 Thread Joshua Niehus
Thanks Jonathan, that cleared things up for me.

Josh

On Sat, Jun 11, 2011 at 12:00 PM, digitalmars-d-learn-requ...@puremagic.com
 wrote:

 Send Digitalmars-d-learn mailing list submissions to
digitalmars-d-learn@puremagic.com

 To subscribe or unsubscribe via the World Wide Web, visit

 http://lists.puremagic.com/cgi-bin/mailman/listinfo/digitalmars-d-learn

 or, via email, send a message with subject or body 'help' to
digitalmars-d-learn-requ...@puremagic.com

 You can reach the person managing the list at
digitalmars-d-learn-ow...@puremagic.com

 When replying, please edit your Subject line so it is more specific
 than Re: Contents of Digitalmars-d-learn digest...


 Today's Topics:

   1. dmd vs rdmd (Joshua Niehus)
   2. Re: dmd vs rdmd (Jonathan M Davis)
   3. Re: dmd vs rdmd (Andrej Mitrovic)
   4. char[] to string (Jonathan Sternberg)
   5. Re: char[] to string (Jonathan M Davis)
   6. Re: DMD Backend: Deciding instructions to use/avoid?
  (Nick Sabalausky)
   7. Re: char[] to string (bearophile)


 --

 Message: 1
 Date: Fri, 10 Jun 2011 14:28:41 -0700
 From: Joshua Niehus jm.nie...@gmail.com
 To: digitalmars-d-learn@puremagic.com
 Subject: dmd vs rdmd
 Message-ID: BANLkTi=TYnN+UuxCr8wj8UwFRjS=ivz...@mail.gmail.com
 Content-Type: text/plain; charset=iso-8859-1

 Hello,

 I am trying to compile code which is composed of two modules (in the same
 directory):

 main.d
 foo.d

 foo.d just declares a class Foo which has a string variable bar which i
 set to hello and main.d just prints bar's value to the console:

 // - main.d ---
 import std.stdio, foo;

 void main() {
Foo f = new Foo;
writeln(f.bar);
 }

 When i attempt to compile main.d via:
 $dmd main.d
 I get undefined symbol errors.

 But when I run:
 $rdmd main.d
 it works as expected.

 The only way I could get main.d to compile with just dmd was to compile foo
 as a lib first and then compile main.d and passing the foo.a file as an
 argument:
 $dmd -lib foo.d
 $dmd main.d foo.a

 Is this normal?
 I got the impression from TDPL (Alexandrescu) that the dmd compiler would
 automatically search the root directory, find foo.d, work its magic, and
 create all the symbols that were defined in foo.d for main.d to compile...

 Thanks,
 Josh
 -- next part --
 An HTML attachment was scrubbed...
 URL: 
 http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20110610/dccf485f/attachment-0001.html
 

 --

 Message: 2
 Date: Fri, 10 Jun 2011 21:50:37 +
 From: Jonathan M Davis jmdavisp...@gmx.com
 To: digitalmars.D.learn digitalmars-d-learn@puremagic.com
 Subject: Re: dmd vs rdmd
 Message-ID: 20110610215037.56...@gmx.com
 Content-Type: text/plain; charset=utf-8

 On 2011-06-10 14:28, Joshua Niehus wrote:
  Hello,
 
  I am trying to compile code which is composed of two modules (in the same
  directory):
 
  main.d
  foo.d
 
  foo.d just declares a class Foo which has a string variable bar which i
  set to hello and main.d just prints bar's value to the console:
 
  // - main.d ---
  import std.stdio, foo;
 
  void main() {
  Foo f = new Foo;
  writeln(f.bar);
  }
 
  When i attempt to compile main.d via:
  $dmd main.d
  I get undefined symbol errors.
 
  But when I run:
  $rdmd main.d
  it works as expected.
 
  The only way I could get main.d to compile with just dmd was to compile
 foo
  as a lib first and then compile main.d and passing the foo.a file as an
  argument:
  $dmd -lib foo.d
  $dmd main.d foo.a
 
  Is this normal?
  I got the impression from TDPL (Alexandrescu) that the dmd compiler would
  automatically search the root directory, find foo.d, work its magic, and
  create all the symbols that were defined in foo.d for main.d to
 compile...

 With dmd, you must list every file that you're compiling. The only
 exceptions
 are that when dealing with libraries, dmd to have the root directory where
 the
 source is passed to -I, and it needs to have the root directory where the
 library is given with -L and -l with the library name (or just the library
 directly if you don't want it to search for the library). It's like gcc and
 dmc in that respect. It does nothing extra to track down files to compile
 for
 you. It'll find the source for importing thanks to -I, but it won't compile
 it. You must still compile it. You don't normally need -I or -L however,
 because dmd.conf (or sc.ini on Windows) already adds the appropriate flags
 for
 Phobos for you. You only need too specify them yourself when using other
 libraries.

 rdmd does extra magic to automatically track down all of the files that
 main.d
 imports and compile them. dmd doesn't do that.

 - Jonathan M Davis


 --

 Message: 3
 Date: Sat, 11 Jun 2011 01:08:50 +0200
 From: Andrej Mitrovic andrej.mitrov...@gmail.com
 To: digitalmars.D.learn digitalmars-d-learn

Re: simple syntax issue with template

2011-06-13 Thread Joshua Niehus
 I'm trying to create 2 extra method for arrays (range would be
 better, though I don't quite understand what is a range)
 Although I have some indecipherable (to me) compiler error...

 What's wrong with the code below?
 ==
 import std.algorithm;

 public:

 void remove(T)(ref T[] array, T element)
 {
auto index = array.countUntil!(a == b, T[], T)(array, element);
removeAt(index);
 }

 void removeAt(T)(ref T[] array, sizediff_t index)
 {
if(index  0 || index = array.length)
return;
array.replaceInPlace(index, index + 1, []);
 }


 unittest
 {
auto a = [1, 3, 4];
a.remove(3);
assert(a == [1, 4]);
 }
 ==

Hi Lloyd,

why not just use the built in functionality of arrays?

//--
import std.stdio;

void main() {
auto a = [1, 2, 3, 4, 5, 6, 7, 8];
remove(a, 3);

foreach (i; a) {
write(i,  );
}
writeln();
}

void remove(T) (ref T[] myarray, int element) {
auto front = myarray[0 .. (element -1)];
auto back =  myarray[element .. $];
myarray = front ~ back;
// or simply: myarray = myarray[0 .. (element - 1)] ~ myarray[element ..
$];
}
//--

Josh


dmd vs rdmd

2011-06-10 Thread Joshua Niehus
Hello,

I am trying to compile code which is composed of two modules (in the same
directory):

main.d
foo.d

foo.d just declares a class Foo which has a string variable bar which i
set to hello and main.d just prints bar's value to the console:

// - main.d ---
import std.stdio, foo;

void main() {
Foo f = new Foo;
writeln(f.bar);
}

When i attempt to compile main.d via:
$dmd main.d
I get undefined symbol errors.

But when I run:
$rdmd main.d
it works as expected.

The only way I could get main.d to compile with just dmd was to compile foo
as a lib first and then compile main.d and passing the foo.a file as an
argument:
$dmd -lib foo.d
$dmd main.d foo.a

Is this normal?
I got the impression from TDPL (Alexandrescu) that the dmd compiler would
automatically search the root directory, find foo.d, work its magic, and
create all the symbols that were defined in foo.d for main.d to compile...

Thanks,
Josh