Re: Array concatenation & optimisation

2024-07-22 Thread IchorDev via Digitalmars-d-learn
On Monday, 22 July 2024 at 12:03:33 UTC, Quirin Schroll wrote: this has no effect on whether the function is `@nogc`. That is a highly amusing (but obviously understandable) logical contradiction that I’d never considered before. ‘Sometimes you can’t use non-GC code in `@nogc` code.’

Re: Array concatenation & optimisation

2024-07-22 Thread Nick Treleaven via Digitalmars-d-learn
On Sunday, 21 July 2024 at 10:33:38 UTC, Nick Treleaven wrote: On Sunday, 21 July 2024 at 05:43:32 UTC, IchorDev wrote: Does this mean that array literals are *always* separately allocated first, or is this usually optimised out? My understanding is that they do not allocate if used to initia

Re: Array concatenation & optimisation

2024-07-22 Thread Quirin Schroll via Digitalmars-d-learn
On Sunday, 21 July 2024 at 05:43:32 UTC, IchorDev wrote: Obviously when writing optimised code it is desirable to reduce heap allocation frequency. With that in mind, I'm used to being told by the compiler that I can't do this in `@nogc` code: ```d void assign(ref int[4] a) @nogc{ a[] = [1,3,6

Re: Array concatenation & optimisation

2024-07-21 Thread IchorDev via Digitalmars-d-learn
On Sunday, 21 July 2024 at 15:41:50 UTC, Johan wrote: https://d.godbolt.org/z/sG5Kancs4 The short array is not dynamically allocated (it's allocated on the stack, or for larger arrays it will be a hidden symbol in the binary image), even at `-O0` (i.e. `-O` was not passed). Wow thanks, that'

Re: Array concatenation & optimisation

2024-07-21 Thread IchorDev via Digitalmars-d-learn
oing to yield faster code, or will I waste my time and screen space? Note that concatenation always allocates: Concatenation always creates a copy of its operands, even if one of the operands is a 0 length array https://dlang.org/spec/arrays.html#array-concatenation Thank you for all thi

Re: Array concatenation & optimisation

2024-07-21 Thread Johan via Digitalmars-d-learn
On Sunday, 21 July 2024 at 05:43:32 UTC, IchorDev wrote: Does this mean that array literals are *always* separately allocated first, or is this usually optimised out? Not always allocated, see your example below. I don't quite know what the heuristic is for allocation or not... For instance,

Re: Array concatenation & optimisation

2024-07-21 Thread Nick Treleaven via Digitalmars-d-learn
On Sunday, 21 July 2024 at 10:33:38 UTC, Nick Treleaven wrote: For instance, will this example *always* allocate a new dynamic array for the array literal, and then append it to the existing one, even in optimised builds? ```d void append(ref int[] a){ a ~= [5, 4, 9]; } ``` If there i

Re: Array concatenation & optimisation

2024-07-21 Thread Nick Treleaven via Digitalmars-d-learn
tion; but for small array literals, is splitting them into separate concatenations going to yield faster code, or will I waste my time and screen space? Note that concatenation always allocates: Concatenation always creates a copy of its operands, even if one of the operands is a 0 length

Array concatenation & optimisation

2024-07-20 Thread IchorDev via Digitalmars-d-learn
Obviously when writing optimised code it is desirable to reduce heap allocation frequency. With that in mind, I'm used to being told by the compiler that I can't do this in `@nogc` code: ```d void assign(ref int[4] a) @nogc{ a[] = [1,3,6,9]; //Error: array literal in `@nogc` function `assign`

Re: String concatenation segmentation error

2021-04-23 Thread Imperatorn via Digitalmars-d-learn
On Thursday, 22 April 2021 at 21:15:48 UTC, tcak wrote: string fileContent = ""; ... [...] Do you have a minimal reproducible test case? 🤔

Re: String concatenation segmentation error

2021-04-22 Thread Adam D. Ruppe via Digitalmars-d-learn
On Friday, 23 April 2021 at 00:44:58 UTC, tcak wrote: As far as I see, it is not related to that array or indices at all. The question of where is to see if it was CTFE allocated or runtime allocated. I don't think it should make a difference here but idk. If there is no known situation th

Re: String concatenation segmentation error

2021-04-22 Thread tcak via Digitalmars-d-learn
Oh and *where* is that positions variable defined? I am doing OpenCL programming. CPU side is single threaded. As far as I see, it is not related to that array or indices at all. After running for a short time, if a piece of code does any string/char or byte array concatenation at al

Re: String concatenation segmentation error

2021-04-22 Thread Adam D. Ruppe via Digitalmars-d-learn
On Thursday, 22 April 2021 at 21:15:48 UTC, tcak wrote: "positions" array is defined as auto positions = new float[ 100 ]; So, I am 100% sure, it is not out of range. "ri*dim + 1" is not a big number at all. Oh and *where* is that positions variable defined?

Re: String concatenation segmentation error

2021-04-22 Thread Adam D. Ruppe via Digitalmars-d-learn
Are there any other threads in your program?

Re: String concatenation segmentation error

2021-04-22 Thread tcak via Digitalmars-d-learn
In other parts of the code, concatenation operations are all failing with same error. I need guidance to get out of this situation. My assumption was that as long as there is empty heap memory, concatenation operation would succeed always. But, it doesn't seem like so.

String concatenation segmentation error

2021-04-22 Thread tcak via Digitalmars-d-learn
ll allocation. I remember I had this problem before in another project. I have enough free ram. htop shows 3.96 GiB of 8 GiB is used only and swap is not in use. DMD64 D Compiler v2.094.0 Is this error related to me? Is it a programmer error? Is it a bug? Am I doing something wrong? This is a compiler related operation (string concatenation), and I assume/expect that it would work without a problem.

Re: Asking about performance of std concatenation vs. Appender vs. custom class

2021-04-09 Thread ludo via Digitalmars-d-learn
reserving cuts down on the reallocations, but that only takes some of the time. Appending a 1000-element int array is going to go from a 16-byte block, to a 32-byte block, etc. up to a 4096 byte block. This involves roughly 8 reallocations per test. But every append requires an opaque function

Re: Asking about performance of std concatenation vs. Appender vs. custom class

2021-04-01 Thread Steven Schveighoffer via Digitalmars-d-learn
On 4/1/21 10:53 AM, ludo wrote: The results are below (you can also git clone the repo + dub test): | Concatenation method | benchmark in ms| |-|-| |with std:    | 385 ms| |with stdReserve: | 327 ms| |with stdLength:  | 29 ms| |with

Asking about performance of std concatenation vs. Appender vs. custom class

2021-04-01 Thread ludo via Digitalmars-d-learn
concatenation at the expense of the base pointer being 4 system words instead of two (16 instead of 8 bytes on a 32-bit system). */ ``` So I wrote a unittest to verify that claim, using for benchmark 10_000_000 concatenations : ```d trace("*** ArrayBuilder Concatenation benc

Re: Dude about ~ array concatenation performance

2020-12-02 Thread ddcovery via Digitalmars-d-learn
On Wednesday, 2 December 2020 at 06:31:49 UTC, H. S. Teoh wrote: On Tue, Dec 01, 2020 at 10:49:55PM +, ddcovery via Digitalmars-d-learn wrote: Yesterday I really shocked when, comparing one algorithm written in javascript and the equivalent in D, javascript performed better!!! [...] With

Re: Dude about ~ array concatenation performance

2020-12-01 Thread H. S. Teoh via Digitalmars-d-learn
On Tue, Dec 01, 2020 at 10:49:55PM +, ddcovery via Digitalmars-d-learn wrote: > Yesterday I really shocked when, comparing one algorithm written in > javascript and the equivalent in D, javascript performed better!!! [...] > With 1 million Double numbers (generated randomly): > Javascript (n

Re: Doubts about the performance of array concatenation

2020-12-01 Thread Max Haughton via Digitalmars-d-learn
On Wednesday, 2 December 2020 at 00:08:55 UTC, ddcovery wrote: On Tuesday, 1 December 2020 at 23:43:31 UTC, Max Haughton wrote: On Tuesday, 1 December 2020 at 22:49:55 UTC, ddcovery wrote: Yesterday I really shocked when, comparing one algorithm written in javascript and the equivalent in D, ja

Re: Doubts about the performance of array concatenation

2020-12-01 Thread ddcovery via Digitalmars-d-learn
On Tuesday, 1 December 2020 at 23:43:31 UTC, Max Haughton wrote: On Tuesday, 1 December 2020 at 22:49:55 UTC, ddcovery wrote: Yesterday I really shocked when, comparing one algorithm written in javascript and the equivalent in D, javascript performed better!!! [...] Use ldc, rdmd can invoke

Re: Dude about ~ array concatenation performance

2020-12-01 Thread Max Haughton via Digitalmars-d-learn
On Tuesday, 1 December 2020 at 22:49:55 UTC, ddcovery wrote: Yesterday I really shocked when, comparing one algorithm written in javascript and the equivalent in D, javascript performed better!!! [...] Use ldc, rdmd can invoke it for you. DMD's optimizer is not even close to as advanced as

Re: Doubts about the performance of array concatenation

2020-12-01 Thread ddcovery via Digitalmars-d-learn
On Tuesday, 1 December 2020 at 22:49:55 UTC, ddcovery wrote: Yesterday I really shocked when, comparing one algorithm written in javascript and the equivalent in D, javascript performed better!!! [...] Sorry about title (may be "doubt" :-/ )

Dude about ~ array concatenation performance

2020-12-01 Thread ddcovery via Digitalmars-d-learn
Yesterday I really shocked when, comparing one algorithm written in javascript and the equivalent in D, javascript performed better!!! The idea is to translate the "3 lines sort" in haskell to Javascript and D (with the limitations of each language). This is not a quick sort test, but a "exp

Re: Type sequence concatenation / associative array implementation

2020-02-13 Thread Steven Schveighoffer via Digitalmars-d-learn
On 2/12/20 5:47 PM, Paul Backus wrote: On Wednesday, 12 February 2020 at 20:58:49 UTC, Marcel wrote: 2- How is the builtin associative array implemented? I think I read somewhere it's implemented like C++'s std::unordered_map but with BSTs instead of DLists for handling collisions: is this corr

Re: Type sequence concatenation / associative array implementation

2020-02-12 Thread Paul Backus via Digitalmars-d-learn
On Wednesday, 12 February 2020 at 20:58:49 UTC, Marcel wrote: 2- How is the builtin associative array implemented? I think I read somewhere it's implemented like C++'s std::unordered_map but with BSTs instead of DLists for handling collisions: is this correct? It's an open-addressed hash tabl

Re: Type sequence concatenation / associative array implementation

2020-02-12 Thread H. S. Teoh via Digitalmars-d-learn
On Wed, Feb 12, 2020 at 09:05:22PM +, user1234 via Digitalmars-d-learn wrote: > On Wednesday, 12 February 2020 at 20:58:49 UTC, Marcel wrote: > > Hello! > > I have two questions: > > > > 1- How can I concatenate two type sequences? > > alias Concatenated = AliasSeq!(TList1, TList2); [...] T

Re: Type sequence concatenation / associative array implementation

2020-02-12 Thread user1234 via Digitalmars-d-learn
On Wednesday, 12 February 2020 at 20:58:49 UTC, Marcel wrote: Hello! I have two questions: 1- How can I concatenate two type sequences? alias Concatenated = AliasSeq!(TList1, TList2); or maybe alias Concatenated = AliasSeq!(TList1[0..$], TList2[0..$]); since I don't remember if they nest or

Type sequence concatenation / associative array implementation

2020-02-12 Thread Marcel via Digitalmars-d-learn
Hello! I have two questions: 1- How can I concatenate two type sequences? 2- How is the builtin associative array implemented? I think I read somewhere it's implemented like C++'s std::unordered_map but with BSTs instead of DLists for handling collisions: is this correct?

Re: Concatenation/joining strings together in a more readable way

2020-01-02 Thread bachmeier via Digitalmars-d-learn
On Wednesday, 25 December 2019 at 12:39:08 UTC, BoQsc wrote: Are there any other ways to join two strings without Tilde ~ character? I can't seems to find anything about Tilde character concatenation easily, nor the alternatives to it. Can someone share some knowledge on this or at least

Re: Concatenation/joining strings together in a more readable way

2020-01-02 Thread Marcone via Digitalmars-d-learn
On Wednesday, 25 December 2019 at 12:39:08 UTC, BoQsc wrote: Are there any other ways to join two strings without Tilde ~ character? I can't seems to find anything about Tilde character concatenation easily, nor the alternatives to it. Can someone share some knowledge on this or at least

Re: Concatenation/joining strings together in a more readable way

2020-01-01 Thread Marcone via Digitalmars-d-learn
On Wednesday, 25 December 2019 at 12:39:08 UTC, BoQsc wrote: Are there any other ways to join two strings without Tilde ~ character? I can't seems to find anything about Tilde character concatenation easily, nor the alternatives to it. Can someone share some knowledge on this or at least

Re: Concatenation/joining strings together in a more readable way

2019-12-31 Thread Marcone via Digitalmars-d-learn
On Monday, 30 December 2019 at 14:56:59 UTC, mipri wrote: On Monday, 30 December 2019 at 10:23:14 UTC, Marcone wrote: On Monday, 30 December 2019 at 09:41:55 UTC, mipri wrote: This leaks too much. writeln("Helo {} {}".format("xx", "name")); // Helo xx name writeln("Helo {} {}".format("{}

Re: Concatenation/joining strings together in a more readable way

2019-12-31 Thread Marcone via Digitalmars-d-learn
On Monday, 30 December 2019 at 14:56:59 UTC, mipri wrote: On Monday, 30 December 2019 at 10:23:14 UTC, Marcone wrote: On Monday, 30 December 2019 at 09:41:55 UTC, mipri wrote: This leaks too much. writeln("Helo {} {}".format("xx", "name")); // Helo xx name writeln("Helo {} {}".format("{}

Re: Concatenation/joining strings together in a more readable way

2019-12-30 Thread mipri via Digitalmars-d-learn
On Monday, 30 December 2019 at 10:23:14 UTC, Marcone wrote: On Monday, 30 December 2019 at 09:41:55 UTC, mipri wrote: This leaks too much. writeln("Helo {} {}".format("xx", "name")); // Helo xx name writeln("Helo {} {}".format("{}", "name")); // Helo name {} This function replace {} for

Re: Concatenation/joining strings together in a more readable way

2019-12-30 Thread Marcone via Digitalmars-d-learn
On Monday, 30 December 2019 at 09:41:55 UTC, mipri wrote: On Monday, 30 December 2019 at 06:47:37 UTC, Marcone wrote: Use Python format() style: import std; import std: Format = format; // format() string format(T...)(T text){ string texto = text[0]; foreach(count, i; text[1..$

Re: Concatenation/joining strings together in a more readable way

2019-12-30 Thread mipri via Digitalmars-d-learn
On Monday, 30 December 2019 at 06:47:37 UTC, Marcone wrote: Use Python format() style: import std; import std: Format = format; // format() string format(T...)(T text){ string texto = text[0]; foreach(count, i; text[1..$]){ texto = texto.replaceFirst("{}", to!str

Re: Concatenation/joining strings together in a more readable way

2019-12-29 Thread Marcone via Digitalmars-d-learn
On Wednesday, 25 December 2019 at 13:07:44 UTC, mipri wrote: On Wednesday, 25 December 2019 at 12:39:08 UTC, BoQsc wrote: Are there any other ways to join two strings without Tilde ~ character? I can't seems to find anything about Tilde character concatenation easily, nor the alternativ

Re: Concatenation/joining strings together in a more readable way

2019-12-25 Thread mipri via Digitalmars-d-learn
On Wednesday, 25 December 2019 at 12:39:08 UTC, BoQsc wrote: Are there any other ways to join two strings without Tilde ~ character? I can't seems to find anything about Tilde character concatenation easily, nor the alternatives to it. Can someone share some knowledge on this or at least

Re: Concatenation/joining strings together in a more readable way

2019-12-25 Thread Tobias Pankrath via Digitalmars-d-learn
On Wednesday, 25 December 2019 at 12:39:08 UTC, BoQsc wrote: Are there any other ways to join two strings without Tilde ~ character? I can't seems to find anything about Tilde character concatenation easily, nor the alternatives to it. Can someone share some knowledge on this or at least

Concatenation/joining strings together in a more readable way

2019-12-25 Thread BoQsc via Digitalmars-d-learn
Are there any other ways to join two strings without Tilde ~ character? I can't seems to find anything about Tilde character concatenation easily, nor the alternatives to it. Can someone share some knowledge on this or at least point out useful links/resources?

Re: How array concatenation works... internally

2018-04-23 Thread Dnewbie via Digitalmars-d-learn
On Monday, 23 April 2018 at 23:27:17 UTC, Steven Schveighoffer wrote: ... If you want to know more about the array runtime, I suggest this article: https://dlang.org/articles/d-array-article.html ... Thanks for replying and this article is what I was looking for.

Re: How array concatenation works... internally

2018-04-23 Thread Steven Schveighoffer via Digitalmars-d-learn
On 4/23/18 7:15 PM, Dnewbie wrote: Hi, I'd like to understand how array concatenation works internally, like the example below: //DMD64 D Compiler 2.072.2 import std.stdio; void main(){     string[] arr;     arr.length = 2;     arr[0] = "Hello";     arr[1] = "

Re: How array concatenation works... internally

2018-04-23 Thread Dnewbie via Digitalmars-d-learn
On Monday, 23 April 2018 at 23:15:13 UTC, Dnewbie wrote: It's related to memcpy? By the way... It's related to realloc and memcpy?

How array concatenation works... internally

2018-04-23 Thread Dnewbie via Digitalmars-d-learn
Hi, I'd like to understand how array concatenation works internally, like the example below: //DMD64 D Compiler 2.072.2 import std.stdio; void main(){ string[] arr; arr.length = 2; arr[0] = "Hello"; arr[1] = "World"; writeln(arr.length); arr

Re: nogc string concatenation?

2017-07-13 Thread Nicholas Wilson via Digitalmars-d-learn
On Friday, 14 July 2017 at 00:40:38 UTC, FoxyBrown wrote: Anyone have an efficient implementation that is easy to use? If you are OK with just a range spanning the two or more strings, then you could use chain as is.

Re: nogc string concatenation?

2017-07-13 Thread Moritz Maxeiner via Digitalmars-d-learn
On Friday, 14 July 2017 at 00:40:38 UTC, FoxyBrown wrote: Anyone have an efficient implementation that is easy to use? Not sure what you mean by efficient here, but a \theta(n+m) one is done idiomatically with Allocator+ranges like this (note that the casts to and from ubyte are necessary, be

nogc string concatenation?

2017-07-13 Thread FoxyBrown via Digitalmars-d-learn
Anyone have an efficient implementation that is easy to use?

Re: What is the simplest way of doing @nogc string concatenation?

2016-11-04 Thread ketmar via Digitalmars-d-learn
On Friday, 4 November 2016 at 14:56:46 UTC, Guillaume Piolat wrote: On Friday, 4 November 2016 at 14:55:27 UTC, Guillaume Piolat wrote: On Thursday, 3 November 2016 at 18:54:14 UTC, Gary Willoughby wrote: What is the simplest way of doing @nogc string concatenation? I use sprintf + zero

Re: What is the simplest way of doing @nogc string concatenation?

2016-11-04 Thread Guillaume Piolat via Digitalmars-d-learn
On Friday, 4 November 2016 at 14:55:27 UTC, Guillaume Piolat wrote: On Thursday, 3 November 2016 at 18:54:14 UTC, Gary Willoughby wrote: What is the simplest way of doing @nogc string concatenation? I use sprintf + zero-terminated strings (or a RAII struct to convert slices to ZT strings

Re: What is the simplest way of doing @nogc string concatenation?

2016-11-04 Thread Guillaume Piolat via Digitalmars-d-learn
On Thursday, 3 November 2016 at 18:54:14 UTC, Gary Willoughby wrote: What is the simplest way of doing @nogc string concatenation? I use sprintf + zero-terminated strings (or a RAII struct to convert slices to ZT strings).

Re: What is the simplest way of doing @nogc string concatenation?

2016-11-03 Thread Steven Schveighoffer via Digitalmars-d-learn
On 11/3/16 2:54 PM, Gary Willoughby wrote: What is the simplest way of doing @nogc string concatenation? Where does it go? For instance, this should work: auto newstr = "hello, ".chain("world"); -Steve

Re: What is the simplest way of doing @nogc string concatenation?

2016-11-03 Thread Jonathan M Davis via Digitalmars-d-learn
On Thursday, November 03, 2016 18:54:14 Gary Willoughby via Digitalmars-d- learn wrote: > What is the simplest way of doing @nogc string concatenation? std.range.chain is the closest that you're going to get with actual strings. Dynamic arrays require the GC to do concatenation, because t

What is the simplest way of doing @nogc string concatenation?

2016-11-03 Thread Gary Willoughby via Digitalmars-d-learn
What is the simplest way of doing @nogc string concatenation?

Re: Compile time strings auto concatenation!?

2015-11-21 Thread Marc Schütz via Digitalmars-d-learn
On Friday, 20 November 2015 at 20:39:58 UTC, Ilya wrote: Can DMD frontend optimize string concatenation ``` enum Double(S) = S ~ S; assert(condition, "Text " ~ Double!"+" ~ ___FUNCTION__); ``` to ``` assert(condition, "Text ++_function_name_"); ``` ?

Re: Compile time strings auto concatenation!?

2015-11-21 Thread Tofu Ninja via Digitalmars-d-learn
On Friday, 20 November 2015 at 20:39:58 UTC, Ilya wrote: Can DMD frontend optimize string concatenation ``` enum Double(S) = S ~ S; assert(condition, "Text " ~ Double!"+" ~ ___FUNCTION__); ``` to ``` assert(condition, "Text ++_function_name_"); ``` ? If you

Re: Compile time strings auto concatenation!?

2015-11-20 Thread Justin Whear via Digitalmars-d-learn
On Fri, 20 Nov 2015 20:39:57 +, Ilya wrote: > Can DMD frontend optimize > string concatenation > ``` > enum Double(S) = S ~ S; > > assert(condition, "Text " ~ Double!"+" ~ ___FUNCTION__); > ``` > > to > > ``` > assert(condition, &qu

Compile time strings auto concatenation!?

2015-11-20 Thread Ilya via Digitalmars-d-learn
Can DMD frontend optimize string concatenation ``` enum Double(S) = S ~ S; assert(condition, "Text " ~ Double!"+" ~ ___FUNCTION__); ``` to ``` assert(condition, "Text ++_function_name_"); ``` ?

Re: Concatenation of ubyte[] to char[] works, but assignation doesn't

2015-10-06 Thread Jonathan M Davis via Digitalmars-d-learn
On Tuesday, October 06, 2015 09:28:27 Marc Schütz via Digitalmars-d-learn wrote: > I see, this is a new problem introduced by `char + int = char`. > But at least the following could be disallowed without > introducing problems: > > int a = 'a'; > char b = 32; Sure, it would be nice, but

Re: Concatenation of ubyte[] to char[] works, but assignation doesn't

2015-10-06 Thread Ola Fosheim Grøstad via Digitalmars-d-learn
On Tuesday, 6 October 2015 at 09:28:29 UTC, Marc Schütz wrote: I see, this is a new problem introduced by `char + int = char`. But at least the following could be disallowed without introducing problems: int a = 'a'; char b = 32; But strictly speaking, we already accept overflow (i.e.

Re: Concatenation of ubyte[] to char[] works, but assignation doesn't

2015-10-06 Thread Marc Schütz via Digitalmars-d-learn
On Tuesday, 6 October 2015 at 05:38:36 UTC, Jonathan M Davis wrote: Your suggestion only works by assuming that the result will fit in a char, which doesn't fit at all with how coversions are currently done in D. It would allow for narrowing conversions which lost data. And there's no way that

Re: Concatenation of ubyte[] to char[] works, but assignation doesn't

2015-10-05 Thread Jonathan M Davis via Digitalmars-d-learn
On Monday, October 05, 2015 11:48:51 Marc Schütz via Digitalmars-d-learn wrote: > On Monday, 5 October 2015 at 10:30:02 UTC, Jonathan M Davis wrote: > > On Monday, October 05, 2015 09:07:34 Marc Schütz via > > Digitalmars-d-learn wrote: > >> I don't think math would be a problem. There are some obv

Re: Concatenation of ubyte[] to char[] works, but assignation doesn't

2015-10-05 Thread Marc Schütz via Digitalmars-d-learn
On Monday, 5 October 2015 at 10:30:02 UTC, Jonathan M Davis wrote: On Monday, October 05, 2015 09:07:34 Marc Schütz via Digitalmars-d-learn wrote: I don't think math would be a problem. There are some obvious rules that would likely just work with most existing code: char + int = char char - i

Re: Concatenation of ubyte[] to char[] works, but assignation doesn't

2015-10-05 Thread Jonathan M Davis via Digitalmars-d-learn
On Monday, October 05, 2015 09:07:34 Marc Schütz via Digitalmars-d-learn wrote: > On Sunday, 4 October 2015 at 21:57:44 UTC, Jonathan M Davis wrote: > > On Sunday, October 04, 2015 16:13:47 skilion via > > Digitalmars-d-learn wrote: > >> Is this allowed by the language or it is a compiler bug ? > >

Re: Concatenation of ubyte[] to char[] works, but assignation doesn't

2015-10-05 Thread Marc Schütz via Digitalmars-d-learn
On Sunday, 4 October 2015 at 21:57:44 UTC, Jonathan M Davis wrote: On Sunday, October 04, 2015 16:13:47 skilion via Digitalmars-d-learn wrote: Is this allowed by the language or it is a compiler bug ? void main() { char[] a = "abc".dup; ubyte[] b = [1, 2, 3]; a = b; // cannot impl

Re: Concatenation of ubyte[] to char[] works, but assignation doesn't

2015-10-04 Thread skilion via Digitalmars-d-learn
On Sunday, 4 October 2015 at 21:57:44 UTC, Jonathan M Davis wrote: When appending, b to a, the elements in b are being copied onto the end of a, and presumably it works in this case, because a ubyte is implicitly convertible to char. But all it's doing is converting the individual elements. It'

Re: Concatenation of ubyte[] to char[] works, but assignation doesn't

2015-10-04 Thread Jonathan M Davis via Digitalmars-d-learn
On Sunday, October 04, 2015 16:13:47 skilion via Digitalmars-d-learn wrote: > Is this allowed by the language or it is a compiler bug ? > > void main() { > char[] a = "abc".dup; > ubyte[] b = [1, 2, 3]; > a = b; // cannot implicitly convert expression (b) of type > ubyte[] to char[] >

Concatenation of ubyte[] to char[] works, but assignation doesn't

2015-10-04 Thread skilion via Digitalmars-d-learn
Is this allowed by the language or it is a compiler bug ? void main() { char[] a = "abc".dup; ubyte[] b = [1, 2, 3]; a = b; // cannot implicitly convert expression (b) of type ubyte[] to char[] a ~= b; // works }

Re: string concatenation with %s

2015-03-30 Thread anonymous via Digitalmars-d-learn
On Monday, 30 March 2015 at 17:34:20 UTC, Suliman wrote: string sss = format("foo"-", ""bar"); It should be obvious now that you forgot to escape those double quotes. Thanks! Is there any way to stay string as is. without need of it's escaping and so on? It's seems I have seen something li

Re: string concatenation with %s

2015-03-30 Thread Suliman via Digitalmars-d-learn
string sss = format("foo"-", ""bar"); It should be obvious now that you forgot to escape those double quotes. Thanks! Is there any way to stay string as is. without need of it's escaping and so on? It's seems I have seen something like it in docs, but I am not sure about it...

Re: string concatenation with %s

2015-03-30 Thread anonymous via Digitalmars-d-learn
On Monday, 30 March 2015 at 17:18:01 UTC, Suliman wrote: same problem. I am preparing string to next SQL request: string sss = format("SELECT * FROM test.imgs WHERE src LIKE CONCAT('%', REPLACE(CAST(CURDATE()as char), "-", ""), '%') OR CONCAT('%', CAST(CURDATE()as char), '%')"); Here's your

Re: string concatenation with %s

2015-03-30 Thread Suliman via Digitalmars-d-learn
same problem. I am preparing string to next SQL request: string sss = format("SELECT * FROM test.imgs WHERE src LIKE CONCAT('%', REPLACE(CAST(CURDATE()as char), "-", ""), '%') OR CONCAT('%', CAST(CURDATE()as char), '%')"); but I am getting next error: source\app.d(178): Error: invalid array

Re: Difference between concatenation and appendation

2015-01-25 Thread Jonathan M Davis via Digitalmars-d-learn
On Monday, January 26, 2015 01:17:15 WhatMeWorry via Digitalmars-d-learn wrote: > Ok, I just made up that word. But what is the difference between > appending and concatenating? Page 100 of TPDL says "The result > of the concatenation is a new array..." and the section on >

Re: Difference between concatenation and appendation

2015-01-25 Thread WhatMeWorry via Digitalmars-d-learn
On Monday, 26 January 2015 at 01:57:04 UTC, bearophile wrote: Laeeth Isharc: I think concatenation and append are used as synonyms (the same meaning is meant). a~=b or a=a~b a=a~b always allocates a new array, while a~=b sometimes re-allocates in place. Bye, bearophile Perfect! Thank

Re: Difference between concatenation and appendation

2015-01-25 Thread Laeeth Isharc via Digitalmars-d-learn
On Monday, 26 January 2015 at 01:57:04 UTC, bearophile wrote: Laeeth Isharc: I think concatenation and append are used as synonyms (the same meaning is meant). a~=b or a=a~b a=a~b always allocates a new array, while a~=b sometimes re-allocates in place. Bye, bearophile Thanks. That

Re: Difference between concatenation and appendation

2015-01-25 Thread bearophile via Digitalmars-d-learn
Laeeth Isharc: I think concatenation and append are used as synonyms (the same meaning is meant). a~=b or a=a~b a=a~b always allocates a new array, while a~=b sometimes re-allocates in place. Bye, bearophile

Re: Difference between concatenation and appendation

2015-01-25 Thread Laeeth Isharc via Digitalmars-d-learn
On Monday, 26 January 2015 at 01:17:17 UTC, WhatMeWorry wrote: Ok, I just made up that word. But what is the difference between appending and concatenating? Page 100 of TPDL says "The result of the concatenation is a new array..." and the section on appending talks about possib

Re: Difference between concatenation and appendation

2015-01-25 Thread 岩倉 澪
On Monday, 26 January 2015 at 01:17:17 UTC, WhatMeWorry wrote: Ok, I just made up that word. But what is the difference between appending and concatenating? Page 100 of TPDL says "The result of the concatenation is a new array..." and the section on appending talks about possib

Difference between concatenation and appendation

2015-01-25 Thread WhatMeWorry via Digitalmars-d-learn
Ok, I just made up that word. But what is the difference between appending and concatenating? Page 100 of TPDL says "The result of the concatenation is a new array..." and the section on appending talks about possibly needing expansion and reallocation of memory. But I still don&#

Re: string concatenation with %s

2015-01-07 Thread novice2 via Digitalmars-d-learn
what if a_college[i] will contain ` char? almost SQL have "prepare" statement...

Re: string concatenation with %s

2015-01-07 Thread Suliman via Digitalmars-d-learn
std.string.format interpolates string with the same behavior as writefln Thanks!

Re: string concatenation with %s

2015-01-07 Thread Suliman via Digitalmars-d-learn
Please show the _clean_ input, followed by an output example. Bye, bearophile to prevent visual corruption I had past it here: http://www.everfall.com/paste/id.php?ftzy9lxr6yfy Just FYI use prepared statements instead of string concatenation for SQL queries. You mean some tools, that

Re: string concatenation with %s

2015-01-07 Thread Justin Whear via Digitalmars-d-learn
On Wed, 07 Jan 2015 16:38:23 +, Suliman wrote: > I except that writefln have some behavior as string concatenation, but > it does not. > > IS there any way to put needed values in place of %s in string? std.string.format interpolates string with the same behavior as writefln

Re: string concatenation with %s

2015-01-07 Thread Gary Willoughby via Digitalmars-d-learn
;, '%s', '%s', '%s', '%s', '%s');", date[i], a_fredericksburg[i], fredericksburg[i], a_college[i], college[i], a_planetary[i], planetary[i]); I except that writefln have some behavior as string concatenation, but it does not. IS ther

Re: string concatenation with %s

2015-01-07 Thread bearophile via Digitalmars-d-learn
27;%s', '%s', '%s');", date[i], a_fredericksburg[i], fredericksburg[i], a_college[i], college[i], a_planetary[i], planetary[i]); I except that writefln have some behavior as string concatenation, but it does not. IS there any way to put needed values in place of %s

string concatenation with %s

2015-01-07 Thread Suliman via Digitalmars-d-learn
%s', '%s');", date[i], a_fredericksburg[i], fredericksburg[i], a_college[i], college[i], a_planetary[i], planetary[i]); I except that writefln have some behavior as string concatenation, but it does not. IS there any way to put needed values in place of %s in string?

Re: Ropes (concatenation trees) for strings in D ?

2014-08-18 Thread Justin Whear via Digitalmars-d-learn
On Thu, 14 Aug 2014 05:57:17 +, Carl Sturtivant wrote: > This is the idea I mean. > http://citeseer.ist.psu.edu/viewdoc/download? doi=10.1.1.14.9450&rep=rep1&type=pdf > Here's a C++ implementation supported I think by gcc. > http://www.sgi.com/tech/stl/Rope.html > > Is there a D implementatio

Re: Ropes (concatenation trees) for strings in D ?

2014-08-16 Thread ketmar via Digitalmars-d-learn
On Sat, 16 Aug 2014 10:25:01 + MrSmith via Digitalmars-d-learn wrote: > Can you also share your progress? here is public repo: http://repo.or.cz/w/etx.d.git remember, this is not even alpha-quality code (but it seems to be stable enough to build something upon it). API sux, no docs and so on.

Re: Ropes (concatenation trees) for strings in D ?

2014-08-16 Thread ketmar via Digitalmars-d-learn
On Sat, 16 Aug 2014 10:25:01 + MrSmith via Digitalmars-d-learn wrote: > Can you also share your progress? sure. the project has no public repo yet, but you can take a look at it's current state here: http://ketmar.no-ip.org/etx.txz no undo/redo support for now, and it accepts only dchars, bu

Re: Ropes (concatenation trees) for strings in D ?

2014-08-16 Thread MrSmith via Digitalmars-d-learn
On Saturday, 16 August 2014 at 02:26:29 UTC, ketmar via Digitalmars-d-learn wrote: On Fri, 15 Aug 2014 19:04:10 -0700 Timothee Cour via Digitalmars-d-learn wrote: sounds like my C library based on this article: http://e98cuenc.free.fr/wordprocessor/piecetable.html i'm slowly converting my C co

Re: Ropes (concatenation trees) for strings in D ?

2014-08-15 Thread ketmar via Digitalmars-d-learn
On Fri, 15 Aug 2014 19:04:10 -0700 Timothee Cour via Digitalmars-d-learn wrote: sounds like my C library based on this article: http://e98cuenc.free.fr/wordprocessor/piecetable.html i'm slowly converting my C code to D (nothing fancy yet, still C-style). it's not a 'real' rope -- it's designed

Re: Ropes (concatenation trees) for strings in D ?

2014-08-15 Thread Kagamin via Digitalmars-d-learn
Search gave result "enough rope to hang yourself".

Re: InputRange Concatenation

2013-11-23 Thread Adam D. Ruppe
On Saturday, 23 November 2013 at 23:39:12 UTC, Nordlöw wrote: Is there a higher-order range pattern that concatenate two InputRanges? Sounds like you need std.range.chain: http://dlang.org/phobos/std_range.html#chain

InputRange Concatenation

2013-11-23 Thread Nordlöw
Is there a higher-order range pattern that concatenate two InputRanges? Something like foreach (e; a) { // do stuff with e } foreach (e; b) { // do stuff with e } ... should instead be written as foreach (e; someMagic(a, b, ...)) { // do stuff w

Re: Efficient string concatenation?

2013-11-16 Thread Ali Çehreli
On 11/16/2013 08:59 AM, ilya-stromberg wrote: > I think it's good to listen a little critics from newcomers. I belive > that it helps Ali Cehreli to improve the book. Exactly! :) Two quotes from the Introduction chapter: "If you come across chapters that you find to be particularly difficult,

Re: Efficient string concatenation?

2013-11-16 Thread ilya-stromberg
On Friday, 15 November 2013 at 23:51:42 UTC, Jacek Furmankiewicz wrote: Thanks for the book! I printed it, all 673 pages of it. Immense work you have there. I think it's good to listen a little critics from newcomers. I belive that it helps Ali Cehreli to improve the book. Also, you can use

Re: Efficient string concatenation?

2013-11-16 Thread JR
On Friday, 15 November 2013 at 22:33:34 UTC, Brad Anderson wrote: Appender in std.array is probably what you are looking for. std.algorithm.joiner is also useful (no allocations at all even) but the use case is a bit different. Is Appender considered up to Phobos' current standards? I vaguely

Re: Efficient string concatenation?

2013-11-15 Thread Jacek Furmankiewicz
Thanks for the book! I printed it, all 673 pages of it. Immense work you have there.

  1   2   >