sort a string

2020-05-01 Thread Chris Katko via Digitalmars-d-learn
I'm making anagrams. According to the nextPermutation() docs, I need to 'sort by less' to get all permutations. ... Except the doc page doesn't mention how to do that, nor does std.algorithm.sort show how to sort a string. ... and the google results on the dlang forums from 2017 don't work.

Re: sort a string

2020-05-01 Thread norm via Digitalmars-d-learn
On Friday, 1 May 2020 at 07:38:53 UTC, Chris Katko wrote: I'm making anagrams. According to the nextPermutation() docs, I need to 'sort by less' to get all permutations. ... Except the doc page doesn't mention how to do that, nor does std.algorithm.sort show how to sort a string. ... and the

Re: sort a string

2020-05-01 Thread Chris Katko via Digitalmars-d-learn
On Friday, 1 May 2020 at 08:17:33 UTC, norm wrote: On Friday, 1 May 2020 at 07:38:53 UTC, Chris Katko wrote: [...] You need to convert the sort output to dchar[], e.g. --- dchar[] line3 = sort(line2.to!(dchar[])).to!(dchar[]); --- Cheers, Norm That works, thanks!

Re: sort a string

2020-05-01 Thread drug via Digitalmars-d-learn
01.05.2020 10:38, Chris Katko пишет: I'm making anagrams. According to the nextPermutation() docs, I need to 'sort by less' to get all permutations. ... Except the doc page doesn't mention how to do that, nor does std.algorithm.sort show how to sort a string. ... and the google results on the

Cross product in lib mir or lubeck

2020-05-01 Thread Erdem via Digitalmars-d-learn
Hi, I am looking for cross product function in libmir or lubeck. But I couldn't find it. Does anyone know if it exists or not? Erdem

Re: Why libmir has to add its own algorithm functions

2020-05-01 Thread bachmeier via Digitalmars-d-learn
On Friday, 1 May 2020 at 11:31:29 UTC, Erdem wrote: As can be seen in the link below : http://mir-algorithm.libmir.org/mir_algorithm_iteration.html Libmir provides almost the same function as std. Why is benefit of doing that? Wouldn't it be better to not duplicate std stuff? Erdem I

Re: sort a string

2020-05-01 Thread drug via Digitalmars-d-learn
01.05.2020 15:29, Steven Schveighoffer пишет: Don't do this, use to!(dchar[]) as you have above. This will create incorrect dchars for non-ascii text. -Steve Argh, as always you're right. Funny that I never did that and sadly that I posted wrong code. Thank you, Steven, for correction of

Re: Why libmir has to add its own algorithm functions

2020-05-01 Thread 9il via Digitalmars-d-learn
On Friday, 1 May 2020 at 11:31:29 UTC, Erdem wrote: As can be seen in the link below : http://mir-algorithm.libmir.org/mir_algorithm_iteration.html Libmir provides almost the same function as std. Why is benefit of doing that? Wouldn't it be better to not duplicate std stuff? Erdem Some

Why libmir has to add its own algorithm functions

2020-05-01 Thread Erdem via Digitalmars-d-learn
As can be seen in the link below : http://mir-algorithm.libmir.org/mir_algorithm_iteration.html Libmir provides almost the same function as std. Why is benefit of doing that? Wouldn't it be better to not duplicate std stuff? Erdem

Re: sort a string

2020-05-01 Thread Steven Schveighoffer via Digitalmars-d-learn
On 5/1/20 4:12 AM, drug wrote: 01.05.2020 10:38, Chris Katko пишет: I'm making anagrams. According to the nextPermutation() docs, I need to 'sort by less' to get all permutations. ... Except the doc page doesn't mention how to do that, nor does std.algorithm.sort show how to sort a string.

Re: sort a string

2020-05-01 Thread drug via Digitalmars-d-learn
01.05.2020 18:04, notna пишет: hmmm, whích results in:  Error: cannot use [] operator on expression of type dchar try this: ```D import std; void main() { string word = "Привет"; dchar[] line3 = to!(dchar[])(word.dup) // make a copy to get a range of mutable char

Re: sort a string

2020-05-01 Thread bachmeier via Digitalmars-d-learn
On Friday, 1 May 2020 at 15:04:01 UTC, notna wrote: On Friday, 1 May 2020 at 12:29:26 UTC, Steven Schveighoffer wrote:     dchar[] line3 = sort(line2.to!(dchar[])); dchar[] line3 = sort(line2.to!dchar[]).release; https://dlang.org/phobos/std_range.html#.SortedRange.release hmmm,

Python eval() equivalent in Dlang working in Runtime?

2020-05-01 Thread Baby Beaker via Digitalmars-d-learn
There is a Python eval() equivalent in Dlang working in Runtime?

Re: sort a string

2020-05-01 Thread notna via Digitalmars-d-learn
On Friday, 1 May 2020 at 15:15:29 UTC, bachmeier wrote: On Friday, 1 May 2020 at 15:04:01 UTC, notna wrote: On Friday, 1 May 2020 at 12:29:26 UTC, Steven Schveighoffer wrote:     dchar[] line3 = sort(line2.to!(dchar[])); dchar[] line3 = sort(line2.to!dchar[]).release;

Re: sort a string

2020-05-01 Thread notna via Digitalmars-d-learn
On Friday, 1 May 2020 at 15:17:53 UTC, drug wrote: 01.05.2020 18:04, notna пишет: hmmm, whích results in:  Error: cannot use [] operator on expression of type dchar try this: ```D import std; void main() { string word = "Привет"; dchar[] line3 = to!(dchar[])(word.dup) // make a

Re: Cross product in lib mir or lubeck

2020-05-01 Thread 9il via Digitalmars-d-learn
On Friday, 1 May 2020 at 11:29:55 UTC, Erdem wrote: Hi, I am looking for cross product function in libmir or lubeck. But I couldn't find it. Does anyone know if it exists or not? Erdem Hi, Libmir doesn't provide cross-product function. Ilya

Re: sort a string

2020-05-01 Thread notna via Digitalmars-d-learn
On Friday, 1 May 2020 at 12:29:26 UTC, Steven Schveighoffer wrote:     dchar[] line3 = sort(line2.to!(dchar[])); dchar[] line3 = sort(line2.to!dchar[]).release; https://dlang.org/phobos/std_range.html#.SortedRange.release hmmm, whích results in: Error: cannot use [] operator on

a function like writeln that returns a string rather than writes to a file

2020-05-01 Thread dan via Digitalmars-d-learn
I'm looking for a function something like writeln or write, but instead of writing to stdout, it writes to a string and returns the string. So i would like something like: import std.stdio; import std.conv; string write_to_string(T...)(T values ) { string s; foreach ( value; values ) s

Re: a function like writeln that returns a string rather than writes to a file

2020-05-01 Thread H. S. Teoh via Digitalmars-d-learn
On Sat, May 02, 2020 at 02:22:42AM +, dan via Digitalmars-d-learn wrote: > I'm looking for a function something like writeln or write, but instead of > writing to stdout, it writes to a string and returns the string. [...] import std.format : format; string str = format("%s %s

Re: a function like writeln that returns a string rather than writes to a file

2020-05-01 Thread dan via Digitalmars-d-learn
On Saturday, 2 May 2020 at 02:29:43 UTC, H. S. Teoh wrote: On Sat, May 02, 2020 at 02:22:42AM +, dan via Digitalmars-d-learn wrote: I'm looking for a function something like writeln or write, but instead of writing to stdout, it writes to a string and returns the string. [...]

Re: a function like writeln that returns a string rather than writes to a file

2020-05-01 Thread dan via Digitalmars-d-learn
On Saturday, 2 May 2020 at 02:49:04 UTC, Steven Schveighoffer wrote: On 5/1/20 10:40 PM, dan wrote: On Saturday, 2 May 2020 at 02:29:43 UTC, H. S. Teoh wrote: On Sat, May 02, 2020 at 02:22:42AM +, dan via Digitalmars-d-learn wrote: [...] [...] import std.format : format; string

Re: sort a string

2020-05-01 Thread Steven Schveighoffer via Digitalmars-d-learn
On 5/1/20 11:17 AM, drug wrote: 01.05.2020 18:04, notna пишет: hmmm, whích results in:   Error: cannot use [] operator on expression of type dchar try this: ```D import std; void main() {     string word = "Привет";     dchar[] line3 = to!(dchar[])(word.dup) // make a copy to get a range

Re: a function like writeln that returns a string rather than writes to a file

2020-05-01 Thread Steven Schveighoffer via Digitalmars-d-learn
On 5/1/20 10:40 PM, dan wrote: On Saturday, 2 May 2020 at 02:29:43 UTC, H. S. Teoh wrote: On Sat, May 02, 2020 at 02:22:42AM +, dan via Digitalmars-d-learn wrote: I'm looking for a function something like writeln or write, but instead of writing to stdout, it writes to a string and returns

Re: Python eval() equivalent in Dlang working in Runtime?

2020-05-01 Thread jmh530 via Digitalmars-d-learn
On Friday, 1 May 2020 at 15:42:54 UTC, Baby Beaker wrote: There is a Python eval() equivalent in Dlang working in Runtime? You might find arsd's script.d interesting [1], but it's more like a blend between D and javascript.

Aliasing current function template instance

2020-05-01 Thread Jean-Louis Leroy via Digitalmars-d-learn
Is it possible, inside a function template, to create an alias to the instantiated function? IOW the equivalent of __FUNCTION__, but yielding an alias? The closest I came is: import std.string; import std.traits; void foo(T)(lazy T) { mixin( "alias thisFunction = ",

Re: Aliasing current function template instance

2020-05-01 Thread Steven Schveighoffer via Digitalmars-d-learn
On 5/1/20 4:28 PM, Jean-Louis Leroy wrote: Something I have overlooked? Any ideas? This trick works. No idea who came up with it: alias thisFunction = __traits(parent, {}); -Steve

Re: Aliasing current function template instance

2020-05-01 Thread Jean-Louis Leroy via Digitalmars-d-learn
On Friday, 1 May 2020 at 21:05:17 UTC, Adam D. Ruppe wrote: On Friday, 1 May 2020 at 20:28:58 UTC, Jean-Louis Leroy wrote: Something I have overlooked? Any ideas? There's an old rule, that I can't find in the spec anymore but I'm still pretty sure it is there, where taking the address of a

Re: Python eval() equivalent in Dlang working in Runtime?

2020-05-01 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, May 01, 2020 at 06:37:41PM +, tsbockman via Digitalmars-d-learn wrote: > On Friday, 1 May 2020 at 18:07:54 UTC, H. S. Teoh wrote: [...] > > Actually, if you're willing to ship a working copy of dmd with your > > program, you *could* compile D code on-the-fly and dynamically load > >

Re: Python eval() equivalent in Dlang working in Runtime?

2020-05-01 Thread H. S. Teoh via Digitalmars-d-learn
On Fri, May 01, 2020 at 05:44:27PM +, tsbockman via Digitalmars-d-learn wrote: > On Friday, 1 May 2020 at 15:42:54 UTC, Baby Beaker wrote: > > There is a Python eval() equivalent in Dlang working in Runtime? > > No, and there almost certainly never will be due to fundamental > differences

Re: Python eval() equivalent in Dlang working in Runtime?

2020-05-01 Thread tsbockman via Digitalmars-d-learn
On Friday, 1 May 2020 at 18:07:54 UTC, H. S. Teoh wrote: On Fri, May 01, 2020 at 05:44:27PM +, tsbockman via Digitalmars-d-learn wrote: On Friday, 1 May 2020 at 15:42:54 UTC, Baby Beaker wrote: > There is a Python eval() equivalent in Dlang working in > Runtime? No, and there almost

Re: Aliasing current function template instance

2020-05-01 Thread Jean-Louis Leroy via Digitalmars-d-learn
On Friday, 1 May 2020 at 20:43:05 UTC, Steven Schveighoffer wrote: On 5/1/20 4:28 PM, Jean-Louis Leroy wrote: Something I have overlooked? Any ideas? This trick works. No idea who came up with it: alias thisFunction = __traits(parent, {}); -Steve I think I get the idea. Alas it doesn't

Re: Aliasing current function template instance

2020-05-01 Thread Adam D. Ruppe via Digitalmars-d-learn
On Friday, 1 May 2020 at 20:28:58 UTC, Jean-Louis Leroy wrote: Something I have overlooked? Any ideas? There's an old rule, that I can't find in the spec anymore but I'm still pretty sure it is there, where taking the address of a template inside a template yields the current instantiation.

Right ways to work without gc without betterC.

2020-05-01 Thread Konstantin via Digitalmars-d-learn
I saw docs for std.experimental.allocator and also had found automem library(https://code.dlang.org/packages/automem) for c++ style memory management via smartpointers. From GC documentation std.experimental.allocator can not be used for: NewExpression Array appending Array

Re: Aliasing current function template instance

2020-05-01 Thread Simen Kjærås via Digitalmars-d-learn
On Friday, 1 May 2020 at 20:28:58 UTC, Jean-Louis Leroy wrote: Is it possible, inside a function template, to create an alias to the instantiated function? IOW the equivalent of __FUNCTION__, but yielding an alias? The closest I came is: import std.string; import std.traits; void

Re: Help playing sounds using arsd.simpleaudio

2020-05-01 Thread johnsmith101 via Digitalmars-d-learn
On Friday, 1 November 2019 at 08:54:31 UTC, johnsmith101 wrote: On Wednesday, 30 October 2019 at 19:11:00 UTC, Adam D. Ruppe wrote: On Saturday, 26 October 2019 at 19:48:33 UTC, Murilo wrote: I play a sound the program never ends, the terminal continues to run the program and I have to end it

Re: Python eval() equivalent in Dlang working in Runtime?

2020-05-01 Thread tsbockman via Digitalmars-d-learn
On Friday, 1 May 2020 at 15:42:54 UTC, Baby Beaker wrote: There is a Python eval() equivalent in Dlang working in Runtime? No, and there almost certainly never will be due to fundamental differences between the languages. Depending on your goal, the closest alternatives are using the string