Re: idup class
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 :)
idup class
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: core.sync.rwmutex example
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
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: fedora libcurl-gnutls issue
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
fedora libcurl-gnutls issue
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: shared std.signals
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
shared std.signals
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: Help me write "saveAll"
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: prune with dirEntries
On Friday, 30 November 2012 at 19:52:26 UTC, Jonathan M Davis wrote: If you're compiling with -property, filter must have the parens for the function call as it's a function, not a property. The !() is for the template arguments and is separate from the parens for the function call. That means that if you're compiling with -property and using UFCS, then you end up with range.filter!(pred)(), whereas you have range.filter!(pred). - Jonathan M Davis ahh... well i hope those silly parens never become mandatory. Ruby seems to be doing just fine with or without them. Sorry Jonathan ;)
Re: prune with dirEntries
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
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: prune with dirEntries
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: path matching problem
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: path matching problem
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: Converting a number to complex
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
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
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
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
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
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); }
parallelism with message passing
Hello, Im starting one process in the main thread who in turn is going to kick off another process but has no way of passing along main's Tid, hence the shared(Tid) nonsense. * This works in serial (i.e. change workUnitSize > x.length in mains foreach loop). * It also works when passing the tid directly into f.run(mainTid) with workUnitSize == 1 But I get a crash when attempting to run in parallel with a "shared" tid (see below). Any ideas how to make this work? Thanks, Josh // garbage: newb playing with threads module test; import core.thread; import std.concurrency, std.parallelism, std.stdio; shared(Tid) mainTid; struct Foo { void run() { Thread.sleep(dur!"seconds"(1)); writeln(cast(Tid)mainTid); send(cast(Tid)mainTid, true); } } void someAction(Tid tid) { mainTid = cast(shared(Tid))tid; } void main() { Foo[] x = [Foo(), Foo(), Foo()]; spawn( &someAction, thisTid ); foreach(f; taskPool.parallel(x, 1)) { f.run(); receiveTimeout(dur!"seconds"(3), (bool x) { writeln("received"); } ); } } // exception output: core.exception.AssertError@/usr/share/dmd/src/phobos/std/concurrency.d(1007): null this 5 test0x00010604a4ad _d_assert_msg + 69 6 test0x000106032523 bool std.concurrency.MessageBox.get!(core.time.Duration, void function(bool)*).get(scope core.time.Duration, scope void function(bool)*) + 83 7 test0x0001060324bb bool std.concurrency.receiveTimeout!(void function(bool)*).receiveTimeout(core.time.Duration, void function(bool)*) + 59 8 test0x00010602c5c7 void test.main().int __foreachbody1416(ref test.Foo) + 71 9 test0x0001060320f0 int std.parallelism.ParallelForeach!(test.Foo[]).ParallelForeach.opApply(scope int delegate(ref test.Foo)).void doIt() + 256 10 test0x0001060583f4 void std.parallelism.run!(void delegate()).run(void delegate()) + 20 11 test0x00010605800c void std.parallelism.__T4TaskS213std11parallelism3runTDFZvZ.Task.impl(void*) + 24 12 test0x000106056da3 void std.parallelism.AbstractTask.job() + 15 13 test0x000106056df9 void std.parallelism.TaskPool.doJob(std.parallelism.AbstractTask*) + 33 14 test0x000106056f20 void std.parallelism.TaskPool.workLoop() + 132 15 test0x00010603f915 void core.thread.Thread.run() + 49 16 test0x00010603ec5a thread_entryPoint + 334 17 libsystem_c.dylib 0x7fff9681f742 _pthread_start + 327 18 libsystem_c.dylib 0x7fff9680c181 thread_start + 13 19 ??? 0x 0x0 + 0
Re: std.concurrency msg passing
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.
std.concurrency msg passing
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: -lib question(s)
On Monday, 30 April 2012 at 02:49:21 UTC, Jesse Phillips wrote: However you also will need to specify the library you want to load: -L-lworld More detail. [snip] Hi Jesse, Thanks for the help, that was informative! I didn't realize I needed the load command (-L-lworld) and so I was trying to use the libworld.a file directly, thinking that dmd's -L-L search paths would handle it. Josh
-lib question(s)
Hello, I have a few methods that I want to put into a library but I'm having some trouble figuring out how to go about doing it... Here is my "library": // world.d module world; import std.traits; T hello(T)(T name) /* probably want a string constraint here... */ { return "hello " ~ name; } string hello2(string name) { return "hello " ~ name; } I put this file into one of my import paths (in dmd.conf) and use it as follows: // testworld.d import std.stdio, world; void main() { writeln(hello("josh")); //writeln(hello2("josh")); // error: undefined symbol - name mangle of world_hello2 } Q1) The template version of hello seems to work, but the simpleton version doesn't. What am i missing? Q2) Shouldn't I be compiling world.d with -lib and then put world.a in some linker directory? I did that but got nowhere fast. Basically I have my .a file and a bunch of lame scripts that need to use functions from it, its in a -L dir listed in my dmd.conf, but nothing compiles. Thanks, Josh
Re: regex issue
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
regex issue
Hello, Does anyone know why I would get different results between ctRegex and regex in the following snippet? Thanks, Josh --- #!/usr/local/bin/rdmd import std.stdio, std.regex; void main() { string strcmd = "./myApp.rb -os OSX -path \"/GIT/Ruby Apps/sec\" -conf 'no timer'"; auto ctre = ctRegex!(`(".*")|('.*')`, "g"); auto re = regex (`(".*")|('.*')`, "g"); auto ctm = match(strcmd, ctre); foreach(ct; ctm) writeln(ct.hit()); auto m = match(strcmd, re); foreach(h; m) writeln(h.hit()); } /* output */ "/GIT/Ruby Apps/sec" 'no timer' "/GIT/Ruby Apps/sec"
Re: Compiling DMD on MAC OS X
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 Quick Edit: just noticed that your gcc command is working, so i guess this isnt the prob.
Re: Compiling DMD on MAC OS X
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
Re: Reflection
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...
Reflection
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
Syntax highlighting for CodeRunner
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
Waiting around
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
Re: File append Limit
@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
File append limit?
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
Interfacing to C
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
Hi Robert and Dmitry, Thanks for your replies and the heads up on the current status of DMDScript! Josh
dmdscript osx.mak
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: simple syntax issue with template
> 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
Re: dmd vs rdmd
Thanks Jonathan, that cleared things up for me. Josh On Sat, Jun 11, 2011 at 12:00 PM, 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 > To: digitalmars-d-learn@puremagic.com > Subject: dmd vs rdmd > Message-ID: > 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" > To: "digitalmars.D.learn" > 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 &g
dmd vs rdmd
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