Re: dlang.org/spec/function.html#pure-functions example

2023-10-16 Thread Paul via Digitalmars-d-learn
On Thursday, 12 October 2023 at 21:20:44 UTC, Jonathan M Davis wrote: look like? Types can have static members. Basically what it comes down to is that outside of immutable data, pure functions only have access to their arguments and to what they can access via their arguments (be it by

Re: dlang.org/spec/function.html#pure-functions example

2023-10-16 Thread Paul via Digitalmars-d-learn
On Thursday, 12 October 2023 at 21:20:44 UTC, Jonathan M Davis wrote: Thanks Jonathan

Re: extern (c)

2023-10-11 Thread Paul via Digitalmars-d-learn
On Wednesday, 11 October 2023 at 12:54:53 UTC, user1234 wrote: `extern(C)` on module level functions affect the mangling and the calling convention. - Mangling is used by the linker to link symbols between objects. - Calling convention affects the compiler backend in how code is generated

extern (c)

2023-10-11 Thread Paul via Digitalmars-d-learn
What does the extern (c) attribute(?) do? Does it tell the compiler/linker to build the function like a C compiler would build a C function? If so what does that mean? Does it tell the compiler/linker to let C functions know it exists? If so what does that mean? Is it meant for the compiler or

Re: "macro" expansion to build switch case code

2023-07-03 Thread Paul via Digitalmars-d-learn
On Sunday, 2 July 2023 at 20:27:47 UTC, Steven Schveighoffer wrote: On 7/2/23 1:02 PM, Paul wrote: [...] Use a static foreach: ```d import std.traits; // for FieldNameTuple. there are other ways, but this is the most straightforward switchlabel: // this is needed for break inside a static

"macro" expansion to build switch case code

2023-07-02 Thread Paul via Digitalmars-d-learn
I have a struct similar to the following example. I'd like to build an adder method without having to code the whole method. How do I use the D language to do this? Template, mixins, CTFE..all of them? ```d struct myS { int a, b, c, d, e, f, g, h, i; adder(string s, int n) {

Re: key membership in multi-dimensional assoc. array

2023-06-14 Thread Paul via Digitalmars-d-learn
On Thursday, 15 June 2023 at 02:21:16 UTC, Steven Schveighoffer wrote: Not in as short code. You could write a helper though: ```d auto deepIn(V, K, Keys...)(V[K] aa, Keys keys) if (Keys.length > 0) { auto v = keys[0] in aa; static if(keys.length == 1) return v; else return

key membership in multi-dimensional assoc. array

2023-06-14 Thread Paul via Digitalmars-d-learn
I found I can check for key membership in a multi-D aa... ```d byte zKey = someval; byte[byte][byte][byte] cubelist; foreach(byte xK, yzcubelist; cubelist) { foreach(byte yK, zcubelist; yzcubelist) { foreach(byte zK, val; zcubelist) { ``` with this expression... ```d if(zKey in

Re: Union with bits ?

2023-06-14 Thread Paul via Digitalmars-d-learn
On Wednesday, 14 June 2023 at 22:44:41 UTC, Ali Çehreli wrote: By the way, the string that bitfields() generates can be visualized by simply printing it: const code = bitfields!( ubyte, "A", 1, ubyte, "B", 1, ubyte, "C", 1, ubyte,

Re: Union with bits ?

2023-06-14 Thread Paul via Digitalmars-d-learn
On Wednesday, 14 June 2023 at 14:43:58 UTC, Ali Çehreli wrote: D's string mixin syntax may not be the best, the implementation may be slower than necessary, and the concept may be strange (not macros but very similar) but I still find phobos's bifields to be brilliant.

Union with bits ?

2023-06-13 Thread Paul via Digitalmars-d-learn
I would like to have labeled bits in a union with a ubyte. Something like this: ```d struct MyStruct { union { ubyte status; bit A, B, C…etc } } ``` Is something like this possible? Thanks

Re: regex matching but not capturing

2023-04-06 Thread Paul via Digitalmars-d-learn
On Thursday, 6 April 2023 at 16:27:23 UTC, Alex Bryan wrote: My understanding browsing the documentation is the matchAll returns a range of Captures (struct documented at https://dlang.org/phobos/std_regex.html#Captures). In your for loop I think c[0] will contain the current full match

regex matching but not capturing

2023-04-06 Thread Paul via Digitalmars-d-learn
My regex is matching but doesnt seem to be capturing. You may recognize this from the AOC challenges. file contains... **Valve AA has flow rate=0; tunnels lead to valves DD, II, BB** **Valve BB has flow rate=13; tunnels lead to valves CC, AA** **Valve CC has flow rate=2; tunnels lead to valves

Re: foreach (i; taskPool.parallel(0..2_000_000)

2023-04-06 Thread Paul via Digitalmars-d-learn
On Thursday, 6 April 2023 at 01:44:15 UTC, H. S. Teoh wrote: D ranges are conceptually sequential, but the actual underlying memory access patterns depends on the concrete type at runtime. An array's elements are stored sequentially in memory, and arrays are ranges. But a linked-list can

Re: foreach (i; taskPool.parallel(0..2_000_000)

2023-04-05 Thread Paul via Digitalmars-d-learn
On Wednesday, 5 April 2023 at 23:06:54 UTC, H. S. Teoh wrote: So your data structures and algorithms should be designed in a way that takes advantage of linear access where possible. T Yes I understand, basically, what's going on in hardware. I just wasn't sure if the access type was

Re: foreach (i; taskPool.parallel(0..2_000_000)

2023-04-05 Thread Paul via Digitalmars-d-learn
On Tuesday, 4 April 2023 at 22:20:52 UTC, H. S. Teoh wrote: Best practices for arrays in hot loops: - Avoid appending if possible; instead, pre-allocate outside the loop. - Where possible, reuse existing arrays instead of discarding old ones and allocating new ones. - Use slices where

Re: foreach (i; taskPool.parallel(0..2_000_000)

2023-04-04 Thread Paul via Digitalmars-d-learn
On Monday, 3 April 2023 at 23:50:48 UTC, Steven Schveighoffer wrote: So what you need is inside `createSpansOfNoBeacons`, take as a reference a `ref Span[MAX_SPANS]`, and have it return a `Span[]` that is a slice of that which was "alocated". See if this helps. Well Steven just making the

Re: foreach (i; taskPool.parallel(0..2_000_000)

2023-04-03 Thread Paul via Digitalmars-d-learn
On Monday, 3 April 2023 at 23:13:58 UTC, Steven Schveighoffer wrote: Yeah, please post. ```d module aoc2215b2; import std.stdio; import std.file: readText; import std.conv: to; import std.math: abs; import std.traits; import std.parallelism; import std.range; import core.time: MonoTime; //

Re: foreach (i; taskPool.parallel(0..2_000_000)

2023-04-03 Thread Paul via Digitalmars-d-learn
On Monday, 3 April 2023 at 22:24:18 UTC, Steven Schveighoffer wrote: If your `foreach` body takes a global lock (like `writeln(i);`), then it's not going to run any faster (probably slower actually). **Ok I did have some debug writelns I commented out.** And did it help? **No** My

Re: foreach (i; taskPool.parallel(0..2_000_000)

2023-04-03 Thread Paul via Digitalmars-d-learn
On Sunday, 2 April 2023 at 15:32:05 UTC, Steven Schveighoffer wrote: It's important to note that parallel doesn't iterate the range in parallel, it just runs the body in parallel limited by your CPU count. **?!?** If your `foreach` body takes a global lock (like `writeln(i);`), then it's

Re: foreach (i; taskPool.parallel(0..2_000_000)

2023-04-01 Thread Paul via Digitalmars-d-learn
On Saturday, 1 April 2023 at 18:30:32 UTC, Steven Schveighoffer wrote: On 4/1/23 2:25 PM, Paul wrote: ```d import std.range; foreach(; iota(0, 2_000_000).parallel) ``` -Steve Is there a way to tell if the parallelism actually divided up the work? Both versions of my program run in the

Re: foreach (i; taskPool.parallel(0..2_000_000)

2023-04-01 Thread Paul via Digitalmars-d-learn
```d import std.range; foreach(; iota(0, 2_000_000).parallel) ``` -Steve Is there a way to verify that it split up the work in to tasks/threads ...? The example you gave me works...compiles w/o errors but the execution time is the same as the non-parallel version. They both take about 6

Re: foreach (i; taskPool.parallel(0..2_000_000)

2023-04-01 Thread Paul via Digitalmars-d-learn
Thanks Steve.

foreach (i; taskPool.parallel(0..2_000_000)

2023-04-01 Thread Paul via Digitalmars-d-learn
Thanks in advance for any assistance. As the subject line suggests can I do something like? : ```d foreach (i; taskPool.parallel(0..2_000_000)) ``` Obviously this exact syntax doesn't work but I think it expresses the gist of my challenge.

New to profiling: dmd -profile; ldc2 --fdmd-trace-functions

2023-03-31 Thread Paul via Digitalmars-d-learn
Thanks in advance for any assistance. As the subject line states I'm just now trying to learn profiling. I have a very small program with 1/2 dozen functions and would like to see where the cpu is spending the most time. I've tried both of these lines with identical results: **ldc2

Re: Read a text file at once for regex searching

2023-03-20 Thread Paul via Digitalmars-d-learn
On Monday, 20 March 2023 at 17:47:19 UTC, Adam D Ruppe wrote: On Monday, 20 March 2023 at 17:42:17 UTC, Paul wrote: Do we have some such function in our std library? Try static import std.file; string s = std.file.readText("filename.txt"); http://phobos.dpldocs.info/std.file.readText.html

Read a text file at once for regex searching

2023-03-20 Thread Paul via Digitalmars-d-learn
I've been looking through our Library documentation and having trouble finding what I want. **I'd like to read a text file in all at once** and do some searching and analytics on it instead of reading it bit by bit or line by line. Do we have some such function in our std library? Thanks

Re: Assign to Array Column

2023-01-31 Thread Paul via Digitalmars-d-learn
On Wednesday, 1 February 2023 at 03:45:11 UTC, Salih Dincer wrote: On Tuesday, 31 January 2023 at 01:04:41 UTC, Paul wrote: Can I perform a similar assignment to the column? This, myArr[][0] = 5, doesn't work. Of course, this question has a short answer and a long answer. So the issue is

Re: Address of a class object

2023-01-31 Thread Paul via Digitalmars-d-learn
On Thursday, 5 January 2023 at 05:59:26 UTC, Ali Çehreli wrote: On 1/4/23 20:04, Paul wrote: >> (Again, there is no problem here; we are just learning.) >> Ali > > Do I have this much right? > ..with this output? Looks good to me. While we're here, you can force the class objects to be on the

Assign to Array Column

2023-01-30 Thread Paul via Digitalmars-d-learn
Greetings, for an array byte[3][3] myArr, I can code myArr[0] = 5 and have: 5,5,5 0,0,0 0,0,0 Can I perform a similar assignment to the column? This, myArr[][0] = 5, doesn't work. Thanks!

Re: Coding Challenges - Dlang or Generic

2023-01-12 Thread Paul via Digitalmars-d-learn
On Thursday, 12 January 2023 at 20:28:26 UTC, Christian Köstlin wrote: For this years advent-of-code Steven Schveighoffer (https://github.com /schveiguy/adventofcode/tree/master/2022) has a complete set of dlang solutions. Kind regards, Christian Very helpful. Thanks Christian.

Re: Coding Challenges - Dlang or Generic

2023-01-10 Thread Paul via Digitalmars-d-learn
On Tuesday, 10 January 2023 at 01:31:28 UTC, Ali Çehreli wrote: On 1/9/23 16:17, Paul wrote: > coding challenges Perhaps the following two? https://rosettacode.org/ https://adventofcode.com/ Ali Excellent. Thanks.

Re: Coding Challenges - Dlang or Generic

2023-01-10 Thread Paul via Digitalmars-d-learn
On Tuesday, 10 January 2023 at 06:45:40 UTC, Siarhei Siamashka wrote: ... What kind of D class is that? Are you learning D language in a school or university? Or is it some kind of online language course? ... I don't know if there are rules about sharing links and such but its a site

Re: Coding Challenges - Dlang or Generic

2023-01-10 Thread Paul via Digitalmars-d-learn
On Tuesday, 10 January 2023 at 01:22:33 UTC, H. S. Teoh wrote: ... Here's a challenge. Given an input year, for example, "2023", write a program that outputs (for the corresponding year): ... Code will be graded on readability, unittest coverage, and reusability (how many functions have

Coding Challenges - Dlang or Generic

2023-01-09 Thread Paul via Digitalmars-d-learn
Greetings Dlang-ers I was wondering if anyone knew of any coding challenges available where the input and output are specified and its left to the programmer to find a solution? Free would be nice but even paid services would be worth considering. I'm taking a D class right now and it has

Re: Address of a class object

2023-01-05 Thread Paul via Digitalmars-d-learn
On Thursday, 5 January 2023 at 05:59:26 UTC, Ali Çehreli wrote: While we're here, you can force the class objects to be on the stack as well: scope MyClassVar1 = new MyClass(); I replaced 'auto' with 'scope'. Ali Very interesting. Thanks Ali.

Re: Address of a class object

2023-01-04 Thread Paul via Digitalmars-d-learn
(Again, there is no problem here; we are just learning.) Ali Do I have this much right? ```d import std.stdio, std.traits; class MyClass {char c;} void main() { auto MyInt = 1; writeln("The address of MyInt is : ",," (stack)"); auto MyClassVar1 = new MyClass();

Re: Address of a class object

2023-01-03 Thread Paul via Digitalmars-d-learn
matheus, using dmd64 on my laptop to compile and run this: ```d import std.stdio, std.traits; class MyClass {char[16] c;} void main() { writeln(" Size Alignment Type\n", "="); size_t size = __traits(classInstanceSize, MyClass); size_t alignment

Re: Address of a class object

2023-01-02 Thread Paul via Digitalmars-d-learn
Thank you, Teoh, Ali, & Matheus

Re: Address of a class object

2023-01-01 Thread Paul via Digitalmars-d-learn
Thanks all. Yes it seems my understanding and "D" vocabulary are still a bit confused. So I'm taking a D course online and was trying to verify what I was learning. The course example printed out the size and alignment of types...something close to this: ```d import std.stdio; import

Address of a class object

2022-12-31 Thread Paul via Digitalmars-d-learn
Hello. Thanks for any assistance. Can I acquire the address of a class object, not a class variable (i.e. the instantiations of the class) but the object definition itself? ```d class MyClass {char c} ... MyClass MyClassVar; writeln(); // this compiles writeln();// this does not ```

Re: _Symbols _with _leading _underscores

2022-12-19 Thread Paul via Digitalmars-d-learn
Much appreciated...

_Symbols _with _leading _underscores

2022-12-16 Thread Paul via Digitalmars-d-learn
I see code like this from time to time. Are the leading underscores significant, in general, in the D language? Is it just programmer preference? Is it a coding practice, in general, that is common...even outside of D? Thanks for any assistance. From:

Re: Convert int to dchar

2022-10-05 Thread Paul via Digitalmars-d-learn
On Wednesday, 5 October 2022 at 17:16:29 UTC, H. S. Teoh wrote: For the former: dchar ch = '0' + intValue; This! Thanks Teoh.

Re: Convert int to dchar

2022-10-05 Thread Paul via Digitalmars-d-learn
Thanks Steve. I need to covert something like this: int myvar = 5; How would I convert myvar to a dchar?

Convert int to dchar

2022-10-05 Thread Paul via Digitalmars-d-learn
I'm sure I'm making this more difficult than it needs to be. I'm trying to convert an integer to a dchar. The solution below works but seems like overkill. dstring dstrValue = to!dstring(5); dchar dcharValue = to!dchar(dstrValue); ... this, dchar dcharValue = to!dchar(5);

Re: write struct as raw data to file

2021-09-27 Thread Paul via Digitalmars-d-learn
Vitaliy, Thanks for your assistance. I was looking at your serialization package. Is your example correct? struct MyStruct { ubyte mybyte1; @NoCereal uint nocereal1; //won't be serialised @Bits!4 ubyte nibble; @Bits!1 ubyte bit; @Bits!3 ubyte bits3;

Re: write struct as raw data to file

2021-09-26 Thread Paul via Digitalmars-d-learn
Finished product... ~15k samples x 2 sin() waves/composite wave x 16 DTMF tones = 16 DTMF wave files in ~40ms! I love D.

Re: write struct as raw data to file

2021-09-26 Thread Paul via Digitalmars-d-learn
What's with the 4 bytes of zero? I miss-counted. All is well! Thanks Ali / Steven

Re: write struct as raw data to file

2021-09-26 Thread Paul via Digitalmars-d-learn
Hmm...well this is what I did and sort of got what I wanted; it did compile and write data! auto myStruct = new mystruct[1]; File f = File("myFile.wav", "wb"); f.rawWrite(myStruct); //this is 44 bytes f.rawWrite(shortWaveArray); What I got in the file was this: -my 44 byte myStruct data + (4

write struct as raw data to file

2021-09-26 Thread Paul via Digitalmars-d-learn
I'm building a binary file. I can write my 'short[] myArray' directly to the file using: File f = File( "myFile.wav", "wb" ); f.rawWrite(myArray); It doesn't write any array formatting stuff (i.e. '[ , , ]'); it just moves the data into myFile like I want. I can't seem to do this with

Re: associative array with element type struct ?

2021-09-23 Thread Paul via Digitalmars-d-learn
Of course! And it's very common. <= lol Thanks Ali. Much appreciated!

associative array with element type struct ?

2021-09-23 Thread Paul via Digitalmars-d-learn
Can I have an associative array with the element type being a struct? ..this 26 // simple dual tone key struct 27 struct keytones { ushort rowFreq; ushort colFreq; } 28 29 // keypad associative array 30 keytones[string] keypad; 31 keypad["1"].rowFreq = 697; keypad["1"].colFreq = 1209;

DMD32 D Compiler v2.097.2-dirty ?

2021-09-06 Thread Paul via Digitalmars-d-learn
I like to write CLEAN code:) Why does my DMD installation say v2.097.2-dirty?

Re: Assigning to class struct member leading to unexpected behavior.

2021-01-27 Thread Paul via Digitalmars-d-learn
On Thursday, 28 January 2021 at 02:03:40 UTC, Paul Backus wrote: The braced-initializer syntax only works in declarations, not assignments. Oh, I see, I'm guessing that explains the (sadly unfinished) In-place struct initialization DIP of wilzbach. (https://github.com/dlang/DIPs/pull/71)

Assigning to class struct member leading to unexpected behavior.

2021-01-27 Thread Paul via Digitalmars-d-learn
I'm experiencing a compile error, but for the life of me, I cannot figure out what is wrong. I'll try to keep it short but the code is roughly as follows: class Window{ Screen screen; alias screen this; this() { Screen s = {bottom_f: {[0, 1]}}; this.screen = s; //

Re: Template argument deduction not working with template specialization

2021-01-17 Thread Paul via Digitalmars-d-learn
I just figured out half of my frustration is caused by a collision between the 'alias this'd template possibillity and the normal one. For example: struct Bar(uint size, V) { V[size] blup; alias blup this; } void foo(S : T[], T)(S a) { pragma(msg, "first"); } void

Re: Template argument deduction not working with template specialization

2021-01-17 Thread Paul via Digitalmars-d-learn
On Sunday, 17 January 2021 at 16:42:27 UTC, Steven Schveighoffer wrote: I've always hated that aspect of specialization. I don't really understand why it's valid (how can T be T[]?) I totally agree with that, that confuses me as well. This works: void TFoo(T : U[], U)(T a) Oh cool, that's

Template argument deduction not working with template specialization

2021-01-17 Thread Paul via Digitalmars-d-learn
While trying to use template specializations I noticed the argument deductions do not yield the same version as the ones yielded when being explicit. Example: uint a = 1; uint[] b = [2]; TFoo(a); TFoo!(uint[])(b); void TFoo(T)(T a) { pragma(msg, "T: " ~ T.stringof); } void TFoo(T

Re: Template alias as template specialisation not recognized.

2021-01-15 Thread Paul via Digitalmars-d-learn
On Saturday, 16 January 2021 at 01:38:38 UTC, Paul Backus wrote: You have encountered issue 1807: https://issues.dlang.org/show_bug.cgi?id=1807 Ah I see, thank you, sad to see several DIP's I'd be interested in are postponed :( Thanks for the workaround hint, I'll probably be using that.

Template alias as template specialisation not recognized.

2021-01-15 Thread Paul via Digitalmars-d-learn
I'm having issues when trying to use a template alias as a template specialisation. When using the following: alias Vec(uint size, Type) = Mat!(size, 1, Type); void setUniform(V : Vec!(L, bool), int L)(string name, V value) {...} Vec!(4, bool) a; setUniform("test", a); I get the

Re: opCast / operator overloading with additional template arguments

2021-01-10 Thread Paul via Digitalmars-d-learn
On Monday, 11 January 2021 at 00:48:49 UTC, Steven Schveighoffer wrote: I would think though, that this should work: T opCast(T : Vec!(vecsize, S), S)() Oh wouw, this seems to work perfectly! Awesome thanks ^^ Any Idea why T opCast(T, S)() const if (is(T : Vec!(grootte, S))) { yields the

Re: opCast / operator overloading with additional template arguments

2021-01-10 Thread Paul via Digitalmars-d-learn
On Monday, 11 January 2021 at 02:37:24 UTC, Ali Çehreli wrote: >> T opCast(T)() const if (is(T : Vec!(size, S2), S2)) { The is expression can be so complicated that I used a different approach below. if (isInstanceOfVec!T && T.init.content.length == size) { // ADDED:

Re: opCast / operator overloading with additional template arguments

2021-01-10 Thread Paul via Digitalmars-d-learn
On Monday, 11 January 2021 at 00:25:36 UTC, Ali Çehreli wrote: You don't show complete code; so, I hope I came up with something that reflects your case. Thank you, sadly S (S2 now) is not any specific type, sorry I'll paste more of my file, I hope that's ok. (Sidenote, I'm not sure it's the

opCast / operator overloading with additional template arguments

2021-01-10 Thread Paul via Digitalmars-d-learn
Is there a way to have additional template arguments in operator overloads? The problem I'm having is mostly caused by casting a templated struct to other templated structs. I had the following code; T opCast(T)() const if (is(T : Vec!(vecsize, S), S)) { T converted; static

Conflict when using stderr with import.

2021-01-04 Thread Paul via Digitalmars-d-learn
I'm trying to use stderr.writefln, while using the 'bindbc-opengl' package, but when I try to I get the message: source\app.d(13,2): Error: function std.stdio.makeGlobal!"core.stdc.stdio.stderr".makeGlobal at C:\D\dmd2\windows\bin\..\..\src\phobos\std\stdio.d(4853,20) conflicts with variable

Re: Tuple enumeration without integers or strings

2021-01-03 Thread Paul via Digitalmars-d-learn
On Sunday, 3 January 2021 at 06:05:48 UTC, frame wrote: The hash is also generated at compile time. Is there an easy way for me to know when code is assessed / generated at compile time? For example, is indexing a constant compile time array compile time or run time? Or how about functions?

Re: Tuple enumeration without integers or strings

2021-01-02 Thread Paul via Digitalmars-d-learn
On Sunday, 3 January 2021 at 02:17:43 UTC, frame wrote: Besides the problem with equal values, what's wrong with that: alias Thing = Tuple!(int, int); enum Wind { A = Thing(0, 1), B = Thing(0, 2), C = Thing(0, 2) } void some_function(Wind w) { switch (w.hashOf) { case

Re: Tuple enumeration without integers or strings

2021-01-02 Thread Paul via Digitalmars-d-learn
On Saturday, 2 January 2021 at 21:48:04 UTC, Paul Backus wrote: Yes, but this will be true of any approach you choose. If two enum members have exactly the same value, there is no way to distinguish between them, either at compile time or at runtime. Oh I see, thanks! A bit of a bummer as I

Re: Tuple enumeration without integers or strings

2021-01-02 Thread Paul via Digitalmars-d-learn
On Saturday, 2 January 2021 at 03:20:29 UTC, Paul Backus wrote: D's switch statement only works on strings and integers. For more complex values, the easiest thing is to just use an if-else chain. If you really want to use a switch statement, you can do it by defining a function that maps

Re: Tuple enumeration without integers or strings

2021-01-01 Thread Paul via Digitalmars-d-learn
It seems w.to!string works in conjunction with Wind.N.stringof, though I wonder about the efficiency/wastefulness of this method. Sadly this also leads to very funny behavior when some of the enums have the same value, as to!string(Enum) will yield the name of the first of these enums having

Re: New integer promotion rules

2021-01-01 Thread Paul via Digitalmars-d-learn
On Thursday, 18 January 2018 at 16:31:02 UTC, ag0aep6g wrote: I'm interpreting that to mean that it will become an error for some time, but later it will be allowed again with the new behavior. And then you can throw away `-transition=intpromote`. Seeing as it's almost 3 years later, I'd like

Re: Print int[string] sorted by Value

2020-10-28 Thread Paul via Digitalmars-d-learn
On Wednesday, 28 October 2020 at 15:27:04 UTC, H. S. Teoh wrote: foreach (key; aa.keys.sort!((a,b) => aa[a] < aa[b])) { writeln(key); This solution worked perfectly without modifying any of my other code. I don't fully understand it but can study up

Re: Print int[string] sorted by Value

2020-10-28 Thread Paul via Digitalmars-d-learn
On Wednesday, 28 October 2020 at 15:40:23 UTC, aberba wrote: Have you tries .values() function? dictionary.values.sort() Thanks aberba. Yes, that was my first attempt! If my terminology is correct that gives me a "range" of sorted VALUES. I think I can't "iterate"(foreach) through an array

Re: Print int[string] sorted by Value

2020-10-28 Thread Paul via Digitalmars-d-learn
On Wednesday, 28 October 2020 at 15:25:26 UTC, Paul Backus wrote: auto sorted = dictionary.byPair.array.sort!((a, b) => a.value < b.value) It seems this method produces a ?sorted array of tuples? [..Tuple!(string, "key", uint, "value")("Program", 74), Tuple!(string, "key", uint,

Re: Print int[string] sorted by Value

2020-10-28 Thread Paul via Digitalmars-d-learn
Thanks Teoh

Re: Print int[string] sorted by Value

2020-10-28 Thread Paul via Digitalmars-d-learn
On Wednesday, 28 October 2020 at 15:25:26 UTC, Paul Backus wrote: On Wednesday, 28 October 2020 at 15:15:40 UTC, Paul wrote: per the D sample wc2.d size_t[string] dictionary; <-is printed by... . foreach (word1; dictionary.keys.sort) writef etc I want to print the dictionary

Print int[string] sorted by Value

2020-10-28 Thread Paul via Digitalmars-d-learn
per the D sample wc2.d size_t[string] dictionary; <-is printed by... . foreach (word1; dictionary.keys.sort) writef etc I want to print the dictionary sorted by value not key. I can write an algorithm but is there a library method(s) I can use to iterate through the array sorted

Compile and run in Win10-VSCode

2020-09-25 Thread Paul via Digitalmars-d-learn
Hi Community, I'm Win10: I have VSCode installed. I have DMD installed and can compile examples from a Win CMD console. 1) How do I compile and run from within VSCode? 2) VSCode Extensions: Do I need them? One kept generating errors and a note said it was not under active

Re: Example uses "volatile"; compiler says "undefined identifier volatile"

2019-08-01 Thread Paul via Digitalmars-d-learn
Thank you. I'll try that.

Example uses "volatile"; compiler says "undefined identifier volatile"

2019-07-31 Thread Paul via Digitalmars-d-learn
I'm trying to build a Bare Bones 'OS' via example. Example says to compile with "gdc -c kernel.main.d -o kernel.main.o -g" I'm having trouble getting GDC all set up..as I'm a rank amateur. So, I tried compiling the example below with DMD. DMD spits out exceptions to the use of 'volatile'.

Re: Moving location of dub packages?

2019-07-21 Thread Paul via Digitalmars-d-learn
On Sunday, 21 July 2019 at 09:42:15 UTC, Andre Pany wrote: On Sunday, 21 July 2019 at 09:20:52 UTC, Andre Pany wrote: On Saturday, 20 July 2019 at 12:47:59 UTC, Paul wrote: I'd like to move where dub has stored packages to a shorter path, is there a procedure for this? Thanks in advance!

Moving location of dub packages?

2019-07-20 Thread Paul via Digitalmars-d-learn
I'd like to move where dub has stored packages to a shorter path, is there a procedure for this? Thanks in advance!

Re: Quotes inside wysiwyg strings, or alternative solution?

2019-07-18 Thread Paul via Digitalmars-d-learn
All string literals may span multiple lines. Ah, I didn't know that. Thanks for the detailed reply!

Quotes inside wysiwyg strings, or alternative solution?

2019-07-18 Thread Paul via Digitalmars-d-learn
Hi, I have searched, but can't find a solution. In C++ and Rust there is the option of enclosing a string in a sequence of chars (after R/r) to allow quotation marks in multiline string literals. What is the solution in D for wysiwyg strings (or similar) spanning multiple lines containing

Re: How to concatenate a tuple of strings at compile time?

2018-01-06 Thread paul via Digitalmars-d-learn
Thanks for the input. Unfortunately I still can't convince the compiler. __traits allMembers includes functions. Trying to filter those with std.traits.isCallable, it complains about strings that can't be read or fields that can't be accessed at compile time. Affected are both solutions.

How to concatenate a tuple of strings at compile time?

2018-01-06 Thread paul via Digitalmars-d-learn
Hi! How to concatenate a tuple of strings at compile time? Appending to an enum or an immutable string in a static foreach doesn't work. (And shadowing the thing doesn't work either) a) Calling a function recursively doesn't work because I had to turn the tuple into an array which cannot be

Re: Initialise dynamic array in array of structures

2016-06-22 Thread Paul via Digitalmars-d-learn
On Tuesday, 21 June 2016 at 19:33:31 UTC, cym13 wrote: ... but “trackTemplates[0].coords = [{0, 9}, {1, 1}, {3, 6}];” is an assignment so the compiler can infer as much and doesn't understand that each of those list of values are really CoordLists. I see, but it seems a bit strange given that

Initialise dynamic array in array of structures

2016-06-21 Thread Paul via Digitalmars-d-learn
Given these structures and declaration: struct CoordList{ int x, y; } struct Part{ int x, y; CoordList[] coords; int nextNode, prevNode; string nextEnter, prevEnter; } Part[10] trackTemplates; Can someone please tell me why I can't initialise

Re: ref parameter qualifier and static arrays

2015-09-10 Thread Paul via Digitalmars-d-learn
On Wednesday, 9 September 2015 at 20:35:53 UTC, anonymous wrote: When you pass a slice (without ref), what's actually passed is a pointer and length. The contents are not copied. That means, when you alter an array element, the change will be done the original, even without ref: Thanks

ref parameter qualifier and static arrays

2015-09-09 Thread Paul via Digitalmars-d-learn
Is it possible to call a function like this... void foo(ref int[] anArray) ...with slices of static arrays? I thought I might be able to use [0..$-1] but to no avail - I get an error like this (which is confusing!): (ref int[] anArray) is not callable using argument types (int[]) I've

Re: Superfluous code in switch statement

2015-09-05 Thread Paul via Digitalmars-d-learn
On Friday, 4 September 2015 at 21:20:11 UTC, Timon Gehr wrote: On 09/04/2015 11:12 PM, anonymous wrote: On Friday 04 September 2015 23:04, Timon Gehr wrote: DMD never warns about dead code. It warns here: import std.stdio; void main() { return; writeln("hi"); /* Warning:

Superfluous code in switch statement

2015-09-04 Thread Paul via Digitalmars-d-learn
I discovered the other day (during a cut and paste malfunction!) that it's possible to have code before the first case in a switch. Google tells me that it's legal C code and something I read said it could be used for initialization but was rather vague. void main() { import std.stdio;

Re: tkd - basic compilation problem

2015-07-02 Thread Paul via Digitalmars-d-learn
On Thursday, 2 July 2015 at 17:41:45 UTC, Gary Willoughby wrote: This is exactly why you use dub, so you don't have to worry about all this! You're right, there's sufficient information there if using dub.

Re: tkd - basic compilation problem

2015-07-01 Thread Paul via Digitalmars-d-learn
On Wednesday, 1 July 2015 at 09:38:05 UTC, Marc Schütz wrote: Someone more familiar with Debian/Ubuntu than me may be able to help you here, sorry. I was hoping to keep a tight rein on what was required to be installed to simplify deployment but its spiraling out of control again LOL. The

Re: tkd - basic compilation problem

2015-07-01 Thread Paul via Digitalmars-d-learn
On Wednesday, 1 July 2015 at 17:43:11 UTC, Gary Willoughby wrote: On Tuesday, 30 June 2015 at 12:58:21 UTC, Paul wrote: ... I really don't understand posts like this when literally all information needed is in the README file: https://github.com/nomad-software/tkd Just read RTFM. I read

Re: tkd - basic compilation problem

2015-07-01 Thread Paul via Digitalmars-d-learn
On Wednesday, 1 July 2015 at 18:38:27 UTC, Jordi Sayol wrote: For shared linking against libphobos2.so and libtkd.so: $ dmd `pkg-config --cflags --libs tkd` -J/usr/share/libtkd-doc/example/media/ /usr/share/libtkd-doc/example/example.d For static linking against libphobos2.a and libtkd.a: $

Re: tkd - basic compilation problem

2015-07-01 Thread Paul via Digitalmars-d-learn
On Tuesday, 30 June 2015 at 16:06:41 UTC, Marc Schütz wrote: On Tuesday, 30 June 2015 at 15:25:27 UTC, Alex Parrill wrote: On Tuesday, 30 June 2015 at 14:28:49 UTC, Paul wrote: Using dub I get this during linking: Building tkd-test ~master configuration application, build type debug.

Re: tkd - basic compilation problem

2015-06-30 Thread Paul via Digitalmars-d-learn
On Tuesday, 30 June 2015 at 13:22:43 UTC, Paul wrote: On Tuesday, 30 June 2015 at 13:19:25 UTC, Marc Schütz wrote: If you don't want to use DUB, you need to download the other two packages from code.dlang.org and specifiy -I/path/to/tcltk -I/path/to/x11 -I/path/to/tkd in the DMD invocation.

Re: tkd - basic compilation problem

2015-06-30 Thread Paul via Digitalmars-d-learn
On Tuesday, 30 June 2015 at 13:19:25 UTC, Marc Schütz wrote: If you don't want to use DUB, you need to download the other two packages from code.dlang.org and specifiy -I/path/to/tcltk -I/path/to/x11 -I/path/to/tkd in the DMD invocation. Thank you, I'll try that.

  1   2   >