Re: Dlang equivalent of #define/#ifdef : not... version

2021-04-20 Thread Ali Çehreli via Digitalmars-d-learn
On 4/20/21 3:03 PM, Simen Kjærås wrote: On Tuesday, 20 April 2021 at 18:57:46 UTC, ichneumwn wrote: So my questions: - is there a module-crossing equivalent of "version"? mw covered this. There's more documentation here: https://dlang.org/spec/version.html#version

Re: How to implement a range?

2021-04-16 Thread Ali Çehreli via Digitalmars-d-learn
On 4/15/21 11:21 PM, Jack wrote: > didn't find much help on the docs. In case it's useful to others as well, I have two chapters on ranges: http://ddili.org/ders/d.en/ranges.html http://ddili.org/ders/d.en/ranges_more.html Ali

Re: How do I create classes dynamically?

2021-04-15 Thread Ali Çehreli via Digitalmars-d-learn
On 4/15/21 1:56 PM, mw wrote: >>> I wanted to find out if it is possible to create classes dynamically. >> >> out of curiosity: Why you would like to do this? I cannot think of a >> use case for this - this is why i ask. > > In response to user input? That's a different question because

Re: How do I create classes dynamically?

2021-04-15 Thread Ali Çehreli via Digitalmars-d-learn
On 4/14/21 1:38 PM, Mario wrote: > Maybe I am just too short in D, but I wanted to find out if it is > possible to create classes dynamically. In D world, "dynamically" means "at run time". > Maybe at mixin templates? Both mixins and templates are compile time features. > Normally I would

Re: weird formattedRead

2021-04-09 Thread Ali Çehreli via Digitalmars-d-learn
On 4/9/21 11:17 AM, Berni44 wrote: > I'm on reworking completely the docs of `std.format`. Awesome! :) Ali

Re: weird formattedRead

2021-04-09 Thread Ali Çehreli via Digitalmars-d-learn
On 4/9/21 9:11 AM, Oleg B wrote: > Is space a special char for `formattedRead` and it simple stop parse > without throwing exception if not found space Yes: The space character means "zero or more white space". Ali P.S. I can't check whether the D standard library documentation includes that

Re: Is there a more elegant way to do this in D?

2021-04-07 Thread Ali Çehreli via Digitalmars-d-learn
On 4/7/21 8:57 PM, Brad wrote:     auto a = [1,0,1,1,1,0,1,0,1,1,1,1,0]; I want to come out of this with a string that looks like this: 101110100 Me, me, me, me! :) import std; void main() { auto a = [1,0,1,1,1,0,1,0,1,1,1,1,0]; string s = format!"%-(%s%)"(a); writeln(s); }

Re: Is this bug ? format %(%)

2021-04-07 Thread Ali Çehreli via Digitalmars-d-learn
On 4/7/21 10:04 AM, novice2 wrote: On Wednesday, 7 April 2021 at 13:43:18 UTC, Paul Backus wrote: So, you should change your code to     writefln("%-(%s, %)", s); sorry i dont read docs so carefully thanks For the sake of completeness, I mention this feature in a couple of other places:

Re: How to work with one very large text table but not in memory

2021-04-06 Thread Ali Çehreli via Digitalmars-d-learn
On 4/6/21 12:55 PM, Alain De Vos wrote: I have one very large text table I want to work with. But I don't want to keep de table in memory, what do I use ? Using an sql database is overkill in my setting. There are 10 colums but millions of rows. Jon Degenhardt of eBay uses D in similar ways

Re: Need for speed

2021-04-02 Thread Ali Çehreli via Digitalmars-d-learn
On 4/1/21 9:01 PM, H. S. Teoh wrote: > 6) (Not described in the thread, but applied later) Reduce GC load even > further by reusing an array that was being allocated per iteration in > an inner loop before. For those who prefer a video description with some accent :) here is how to

Re: Need for speed

2021-04-01 Thread Ali Çehreli via Digitalmars-d-learn
On 4/1/21 12:55 PM, H. S. Teoh wrote: > - Constructing large arrays by appending 1 element at a time with `~`. >Obviously, this requires many array reallocations and the associated >copying And that may not be a contributing factor. :) The following program sees just 15 allocations and

Re: Need for speed

2021-04-01 Thread Ali Çehreli via Digitalmars-d-learn
On 4/1/21 10:15 AM, ag0aep6g wrote: > Move `auto rnd = ...;` out of the loop, and you will get better times. Doing that reduces the time about 15 fold. Using Appender reduces it further a tiny bit: import std.array; // ... Appender!(int[]) mylist; // ... mylist.data.sort(); Ali

Re: Static array initialisation

2021-04-01 Thread Ali Çehreli via Digitalmars-d-learn
On 4/1/21 2:30 AM, DLearner wrote: > immutable uint MemSize=100; // Memory size in bytes. > ubyte[MemSize] MemPool = 8; // Initialised to 8 for debugging. Valid index values there are from 0 to 99, inclusive. > WkPtr = [0]; > > counter = 1; > while (counter <= 102) { >

Re: Derived type

2021-03-30 Thread Ali Çehreli via Digitalmars-d-learn
On 3/30/21 6:28 AM, novice3 wrote: > I want create derived type in D "Derived type" is used in the context of object oriented programming at least in D but your examples indicate you need something else. How about the 'alias this' feature? import std.stdio; struct Xobj { void* value;

Re: How to declare "type of function, passed as an argument, which should have it's type inferred"? (or if D had an "any" type)

2021-03-29 Thread Ali Çehreli via Digitalmars-d-learn
On 3/29/21 8:13 AM, Gavin Ray wrote: > Brief question, is it possible to write this so that the "alias fn" here > appears as the final argument? > >auto my_func(alias fn)(string name, string description, auto otherthing) Yes, as a type template parameter but you would have to constrain

Re: Manually check struct invariants

2021-03-23 Thread Ali Çehreli via Digitalmars-d-learn
On 3/23/21 4:14 PM, Imperatorn wrote:> On Tuesday, 23 March 2021 at 22:22:12 UTC, Q. Schroll wrote: >> For a class object obj, one can use assert(obj) to get its invariants >> checked. How to do this for structs? > > It's called after the constructor has run and before the destructor is >

Re: How to delete dynamic array ?

2021-03-17 Thread Ali Çehreli via Digitalmars-d-learn
On 3/17/21 10:21 AM, jmh530 wrote: > That's a little advanced, I think. And you also have > http://ddili.org/ders/d.en/slices.html > saying that slices are just another name for dynamic arrays. I don't fully agree with myself there. :) Slices are interfaces to many different kinds of

Re: How to delete dynamic array ?

2021-03-17 Thread Ali Çehreli via Digitalmars-d-learn
On 3/17/21 3:54 AM, jmh530 wrote: On Tuesday, 16 March 2021 at 23:49:00 UTC, H. S. Teoh wrote: double[] data; data = cast(double[]) malloc(n * double.sizeof)[0 .. n]; This is one of those things that is not explained well enough. I have something here:

Re: Static initialization of associative arrays

2021-03-11 Thread Ali Çehreli via Digitalmars-d-learn
On 3/11/21 10:06 AM, Chris Piker wrote: >https://dlang.org/spec/hash-map.html#static_initialization > > that this feature is not yet implemented. I use a shared static this() block: immutable string[int] aa; shared static this() { aa = [ 1: "one" ]; } void main() { assert(aa.length

Re: can't link a code, is it a bug or my fault?

2021-03-11 Thread Ali Çehreli via Digitalmars-d-learn
On 3/11/21 8:41 AM, Iliya wrote: > I am using dmd 2.094.1 on linux Your program links fine for me with 2.094.2 on Linux. Ali

Re: Broken examples

2021-03-06 Thread Ali Çehreli via Digitalmars-d-learn
On 3/6/21 12:15 AM, Imperatorn wrote: On Saturday, 6 March 2021 at 01:30:35 UTC, MoonlightSentinel wrote: On Friday, 5 March 2021 at 22:01:37 UTC, Imperatorn wrote: Any idea why? The examples are compiled using an older host compiler (__VERSION__ is 2.093) but use features introduced in a

Re: Can't I allocate at descontructor?

2021-03-05 Thread Ali Çehreli via Digitalmars-d-learn
On 3/5/21 8:29 PM, Jack wrote: > Now about the behavior of a static destructor, like static ~this() { } > is this guaranteed to be run? I don't know any way of creating a module on the GC heap so their destruction should not be related to GC collection. I would expect all 'static ~this()'

Re: Can't I allocate at descontructor?

2021-03-05 Thread Ali Çehreli via Digitalmars-d-learn
On 3/5/21 12:57 PM, Jack wrote: >> destroy() executes the destructor. > > but I would need to call it manually and only after I somewhat I've > determined I no longer need the resources, right? so destroy(c) would be > no different from calling my own finalize-like method like freeResources()?

Re: Can't I allocate at descontructor?

2021-03-05 Thread Ali Çehreli via Digitalmars-d-learn
On 3/5/21 12:24 PM, Jack wrote: Are there some kind of replacement or I have to make my own finalize-like method, once I determine somewhat the application no longer need those resources? destroy() executes the destructor. To my surprise, even though 'c' is not null below, the destructor is

Re: byte array to string

2021-02-25 Thread Ali Çehreli via Digitalmars-d-learn
On 2/24/21 10:58 PM, FeepingCreature wrote: On Thursday, 25 February 2021 at 06:57:57 UTC, FeepingCreature wrote: On Thursday, 25 February 2021 at 06:47:11 UTC, Mike wrote: hi all, If i have an array: byte[3] = [1,2,3]; How to get string "123" from it? Thanks in advance. string str =

Re: Compile-Time Function Parameters That Aren't Types?

2021-02-24 Thread Ali Çehreli via Digitalmars-d-learn
On 2/23/21 7:52 PM, Kyle Ingraham wrote: Where would one find information on this There are Point and Polygon struct templates on the following page where one can pick e.g. the dimension (e.g. three dimensional space) by a size_t template parameter.

Re: Is this a good way to do lazy evaluation?

2021-02-23 Thread Ali Çehreli via Digitalmars-d-learn
On 2/22/21 2:00 PM, Jack wrote: > C defValue() { return C.a; } Yes, putting the expression in a function is the way I know for lazy evaluation. Ali

Re: Restricting D applications to a single instance

2021-02-22 Thread Ali Çehreli via Digitalmars-d-learn
On 2/21/21 7:28 PM, Preetpal wrote: > I decided to implement what I meant (single application (executable) > instance restriction) using the Windows API (since my application only > runs on Windows currently anyways): I achieve it with 'flock' (man 2 flock) on Linux. My case is different

Re: how to make this function nothrow?

2021-02-15 Thread Ali Çehreli via Digitalmars-d-learn
On 2/15/21 1:04 PM, Jack wrote: > I have to make my function nothrow because the function that calls it > (not written by me) is nothrow. So I need to wrap my code in a > try-catch() but how will I report the error message, if the toString() > from Throwable isn't nothrow? how do I get out this

Re: Trying to reduce memory usage

2021-02-12 Thread Ali Çehreli via Digitalmars-d-learn
On 2/11/21 6:22 PM, H. S. Teoh wrote: >bool[size_t] hashes; I would start with an even simpler solution until it's proven that there still is a memory issue: import std.stdio; void main() { bool[string] lines; foreach (line; stdin.byLine) { if (line !in

Re: Finding position of a value in an array

2021-02-06 Thread Ali Çehreli via Digitalmars-d-learn
On 2/6/21 2:26 PM, mw wrote: On Tuesday, 31 December 2019 at 14:52:55 UTC, Steven Schveighoffer wrote: On 12/31/19 9:47 AM, Steven Schveighoffer wrote: for the original example: int[] a = [77,66,55,44]; int i = a.bwin.find(55).bufRef.pos; sorry, should be size_t i. Unsigned?

Re: Ugly c++ syntax

2021-02-05 Thread Ali Çehreli via Digitalmars-d-learn
On 2/5/21 1:10 PM, Rumbu wrote: I gave up after reading a lot, but I didn't manage to understand the meaning "&& ..." I think it's the universal reference. template static uint8_t composite_index_size(Tables const&... tables) { return (composite_index_size(tables.size(),

Re: My simple internet client made in Dlang.

2021-02-04 Thread Ali Çehreli via Digitalmars-d-learn
On 2/3/21 8:44 AM, Marcone wrote: relevant opinion I think the following would be improvements: >char[8192] request; I don't know the protocol but obviously 8192 must be sufficient. >auto rq = c.receive(request); So, what is actually received is request[0..rq]. I would call the

Re: Quick question

2021-02-01 Thread Ali Çehreli via Digitalmars-d-learn
While we're on topic, the size of a class type and a class variable both are constant on a platform, e.g. 8 bytes on 64 bit systems. To get the size of actual instances (objects) of this type, one needs to use the classInstanceSize trait: class C { int i; } void main() { auto a = new

Re: Initializing D runtime and executing module and TLS ctors for D libraries

2021-01-30 Thread Ali Çehreli via Digitalmars-d-learn
On 1/30/21 1:34 AM, Imperatorn wrote: > With this knowledge we have now, what changes could and/or should be > made to make this process easier? 樂 I wonder whether doing something in the runtime is possible. For example, it may be more resilient and not crash when suspending a thread fails

Re: Initializing D runtime and executing module and TLS ctors for D libraries

2021-01-29 Thread Ali Çehreli via Digitalmars-d-learn
On 1/24/21 2:28 AM, IGotD- wrote: > Any threads started by druntime has proper initialization of course. Any > thread started by any module written in another language will not do D > the thread initialization. And that of course has been what I've been trying to deal with. Bugs in the uses of

Re: What does this code snippet even do?

2021-01-29 Thread Ali Çehreli via Digitalmars-d-learn
On 1/29/21 2:41 PM, WhatMeWorry wrote:   Ali's book talks about the colon appearing for There is also "is, expression": http://ddili.org/ders/d.en/is_expr.html#ix_is_expr.is,%20expression But the is expression is so complicated. :( I defined that particular syntax as is (T :

Re: How do I compose pipes?

2021-01-28 Thread Ali Çehreli via Digitalmars-d-learn
On 1/28/21 3:45 PM, Anthony wrote: > void end(AccumulatorPipe acc) { > auto pids = acc.pids ~ P.spawnShell("cat", acc.stdout); > > foreach (pid; pids) { > P.wait(pid); > } > } > ``` > > > So now I can do something like: > ``` > run("find source -name '*.d'") >

Re: How do I compose pipes?

2021-01-28 Thread Ali Çehreli via Digitalmars-d-learn
On 1/28/21 2:16 AM, Anthony wrote: > auto p = pipeProcess("ls"); > auto q = pipeProcess("cat", stdin = p.stdout); //it would be good to do That would work if `cat` received the *contents* of the files (and with a "-" command line switch). Since `ls` produces file names, you would have to make

Re: F*cked by memory corruption after assiging value to associative array

2021-01-27 Thread Ali Çehreli via Digitalmars-d-learn
On 1/26/21 6:31 AM, frame wrote: > all GCs Multiple D runtimes? That might work I guess but I've never heard of anybody talking about having multiple runtimes. Does rt_init() initialize *a* D runtime or *the* D runtime? If it indeed works we definitely need much better documentation. I

Re: F*cked by memory corruption after assiging value to associative array

2021-01-25 Thread Ali Çehreli via Digitalmars-d-learn
On 1/25/21 8:14 AM, vitamin wrote: > If created on the default way mean allocated with new (=> GC) I had the same thought. The following would be the "default way" for me but passing that object's address to addRoot would be wrong: import core.memory; struct S { } void main() { auto a =

Re: Initializing D runtime and executing module and TLS ctors for D libraries

2021-01-23 Thread Ali Çehreli via Digitalmars-d-learn
Thank you very much for your answers. I think I've been on the right track and the following bug that I've mentioned has been messing up by hitting me randomly: https://issues.dlang.org/show_bug.cgi?id=11736 On 1/23/21 5:18 PM, IGotD- wrote: > During rt_init in the main thread,

Initializing D runtime and executing module and TLS ctors for D libraries

2021-01-23 Thread Ali Çehreli via Digitalmars-d-learn
tl;dr I know enough to sense there are important stuff that I don't know. Even though I sometimes act[1] like someone who knows stuff, there are many fuzzy areas for me especially in the runtime. Things work great when D code is inside a D program. The runtime and module states are magically

Re: std.algorithm.splitter on a string not always bidirectional

2021-01-21 Thread Ali Çehreli via Digitalmars-d-learn
On 1/21/21 4:51 PM, H. S. Teoh wrote: > But I wouldn't be surprised if there was some > surprising corner case for which this doesn't work / would have onerous > characteristics. Likely. :) Here is one for uniq.back, which includes a link at the bottom for zip.back:

Re: isCallable fails

2021-01-19 Thread Ali Çehreli via Digitalmars-d-learn
I may know the answer but I can't be sure because you don't provide code that reproduces the issue. I am trying to write code below according to your description but it's really tough. Can you reproduce the issue please. // T = some class // T is not a good name because it is usually

Re: Convert double to long if lossless

2021-01-19 Thread Ali Çehreli via Digitalmars-d-learn
On 1/19/21 10:28 AM, Per Nordlöw wrote: > On Tuesday, 19 January 2021 at 16:14:17 UTC, drug wrote: >>>https://dlang.org/phobos/std_bitmanip.html#FloatRep > > Doesn't this pattern already cover all possible cases of `value` needed? I think so. I just remembered FloatRep as a cleaner tool

Re: Convert double to long if lossless

2021-01-19 Thread Ali Çehreli via Digitalmars-d-learn
On 1/19/21 8:14 AM, drug wrote: > P.S. shouldn't compiler emit the error if a literal can't be represented > lossless? I think it would be a useful improvement. Ali

Re: Convert double to long if lossless

2021-01-19 Thread Ali Çehreli via Digitalmars-d-learn
On 1/19/21 6:04 AM, drug wrote: > Another (low level) way is to shift mantissa left by exponent value. Luckily, we already have a helper in Phobos: https://dlang.org/phobos/std_bitmanip.html#FloatRep Ali

Re: Why D functions paramter can not implicit infer type of Variant?

2021-01-13 Thread Ali Çehreli via Digitalmars-d-learn
On 1/13/21 8:17 AM, Marcone wrote: > import std; > > void a(int b){ > } > > void main() > { >Variant c = 10; >a(c); // Error > } > > Need more sugar. That can't work in a strongly statically typed language. The call a(c) is decided at compile time but Variant is not an int at compile

Re: Problem with templated alias as delegate parameter type

2021-01-12 Thread Ali Çehreli via Digitalmars-d-learn
On 1/12/21 12:58 PM, cc wrote: > void send(T query, void delegate(T.RESPONSE) callback) { That wants a delegate that takes a T.RESPONSE (PingResponse in this case). However, the following lambda is in fact a template: > send(PingQuery("helo"), (resp) { You specify the type there

Re: Variadic Struct Parameter

2021-01-12 Thread Ali Çehreli via Digitalmars-d-learn
On 1/12/21 10:44 AM, Jonathan Levi wrote: > why does `fun` still compile? I'm not familiar with that particular syntax, I don't know why it compiles, and I don't know why structs are different. :) However, it looks very much like the following *slice* syntax: void fun(S[] s...) {

Re: properly passing strings to functions? (C++ vs D)

2021-01-11 Thread Ali Çehreli via Digitalmars-d-learn
On 1/11/21 8:22 AM, zack wrote: On Monday, 11 January 2021 at 15:25:58 UTC, Ola Fosheim Grøstad wrote: I meant allocation... The following prints "1", so no allocation. Just tried on Windows with Visual Studio, it prints "0". So I guess this is platform/compiler dependent. Yes. Earlier C++

Re: Parameter with indetermined tuple elements type?

2021-01-11 Thread Ali Çehreli via Digitalmars-d-learn
On 1/11/21 7:27 AM, Marcone wrote: I want to create a function that receive a tuple (need be a tuple) with indetermined length and indetermined elements type without template. The argument need be a tuple, but length and elements types indetermineds. How can I make it? With isIntanceOf in a

Re: opCast / operator overloading with additional template arguments

2021-01-11 Thread Ali Çehreli via Digitalmars-d-learn
On 1/10/21 7:27 PM, Paul wrote: > 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 && >>

Re: opCast / operator overloading with additional template arguments

2021-01-10 Thread Ali Çehreli via Digitalmars-d-learn
On 1/10/21 6:37 PM, Ali Çehreli wrote: >// OBSERVATION: Should the cast below be S? >converted.content[i] = cast(S2) content[i]; I take that back. Yes, it should be S2. (I've been off lately. :) ) Ali

Re: opCast / operator overloading with additional template arguments

2021-01-10 Thread Ali Çehreli via Digitalmars-d-learn
On 1/10/21 5:09 PM, Paul wrote: > I'll paste more of my file, I hope that's ok. Not only ok but much appreciated. :) >> 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. I left notes in capital letters

Re: opCast / operator overloading with additional template arguments

2021-01-10 Thread Ali Çehreli via Digitalmars-d-learn
On 1/10/21 4:09 PM, Paul wrote: > Is there a way to have additional template arguments in operator overloads? I haven't tried that but the following method seems to work for you. You don't show complete code; so, I hope I came up with something that reflects your case. import std; struct

Re: How can I do lazy variable initialization?

2021-01-09 Thread Ali Çehreli via Digitalmars-d-learn
Explicit with a lambda: import std; int heavyLoadOperation() { writeln("Expensive!"); return uniform(0, 10); } void main(string[] args) { const l = { bool inited = false; static int i; if (!inited) { i = heavyLoadOperation(); } return i; }(); if

Re: How can I do lazy variable initialization?

2021-01-09 Thread Ali Çehreli via Digitalmars-d-learn
On 1/9/21 12:35 PM, Ali Çehreli wrote: > alias lightLoadOperation = memoize!heavyLoadOperation; > >const l = lightLoadOperation(); Well, that doesn't work the way you want but this does: if (args.length == 1) { writefln!"Using lazy variable: %s %s"(lightLoadOperation(),

Re: Cannot implicitly convert expression of type const(string[]) to string[]

2021-01-08 Thread Ali Çehreli via Digitalmars-d-learn
On 1/8/21 3:10 PM, tsbockman wrote: > On Friday, 8 January 2021 at 20:43:37 UTC, Andrey wrote: >> Hello, >> >>> struct Value >>> { >>> int value; >>> string data; >>> string[] text; The destination is immutable(char)[]. The characters cannot be changed. We can still append but

Re: DConf talk : Exceptions will disappear in the future?

2021-01-04 Thread Ali Çehreli via Digitalmars-d-learn
On 1/4/21 7:39 AM, ludo456 wrote: > Can someone point me to an article or more explanations about that? Joe Duffy has a very complete document contrasting various error management strategies in the context of Midori: http://joeduffyblog.com/2016/02/07/the-error-model/ Herb Sutter has a

Re: What is the difference between "delegate()" and "lazy delegate()" ?

2021-01-02 Thread Ali Çehreli via Digitalmars-d-learn
On 1/2/21 4:29 AM, Marcone wrote: Why "lazy delegate()" need two parentheses to execute function? lazy automatically makes a delegate that returns the type of the parameter: void bar(lazy int i) { writeln(i); // i is a delegate called automatically } Strangely, the delegateness leaks out

Re: Custom type / Typle type formatted reader

2020-12-31 Thread Ali Çehreli via Digitalmars-d-learn
On 12/31/20 8:36 AM, Rekel wrote: 樂I'm either asking a stupid question, asking it in a wrong way, or asking an important question. Clueless nontheless. . . Your post was interesting to me but trying to duplicate your situation seemed difficult. Can you describe it with a piece of code? If

Re: Tool to measure the time a function takes to execute?

2020-12-27 Thread Ali Çehreli via Digitalmars-d-learn
On 12/27/20 10:24 PM, Kirill wrote: Hello, is there a tool to measure the execution time of a function in D? Can the GC do it? StopWatch and benchmark(): https://dlang.org/phobos/std_datetime.html Ali

Re: Reading files using delimiters/terminators

2020-12-27 Thread Ali Çehreli via Digitalmars-d-learn
On 12/27/20 3:12 PM, Rekel wrote: > is there a reason to use > either 'splitter' or 'split'? I'm not sure I see why the difference > would matter in the end. splitter() is a lazy range algorithm. split() is a range algorithm as well but it is eager; it will put the results in an array that it

Re: Reading files using delimiters/terminators

2020-12-26 Thread Ali Çehreli via Digitalmars-d-learn
On 12/26/20 4:13 PM, Rekel wrote: I'm trying to read a file with entries seperated by '\n\n' (empty line), with entries containing '\n'. I thought the File.readLine(KeepTerminator, Terminator) might work, as it seems to accept strings as terminators, since there seems to have been a thread

Re: How to resize an image ? 樂

2020-12-25 Thread Ali Çehreli via Digitalmars-d-learn
On 12/25/20 12:59 PM, vnr wrote: > Is there a relatively simple way to do this? I have a minimalist photo album program that resizes images with the help of the magickwand library: https://github.com/acehreli/alibum It has only the magickwand bindings that I needed. Ali P.S. The program

Re: Get the code of any D-entity as string?

2020-12-25 Thread Ali Çehreli via Digitalmars-d-learn
On 12/25/20 1:25 PM, sighoya wrote: > Is generally possible to get the declaration of a type/module/value as > string in traits? I am probably misunderstanding it but there is the .stringof property for all types: T.stringof. > I want also to read > declarations from types outside my source

Re: Slice allocation after appending

2020-12-23 Thread Ali Çehreli via Digitalmars-d-learn
On 12/23/20 8:14 AM, frame wrote: > That implementation > can become very handy for some situations but for this simple case > > foreach (arr; [a, b]) { .. } > > would also work. Absolutely. > The difference is that the foreach loop is happen at > runtime and will not compiled as multiple

Re: Can I output strings using core.stdc.stdio?

2020-12-23 Thread Ali Çehreli via Digitalmars-d-learn
On 12/23/20 1:06 AM, Godnyx wrote: > for (ulong i = 0; i < args.length; i++) { > if (typeof(args[i]).stringof == "string") > printf("%s\n", args[i].toStringz); > } I replaced for with foreach and it worked (and I passed "prompt"). static foreach would work as

Re: Slice allocation after appending

2020-12-22 Thread Ali Çehreli via Digitalmars-d-learn
On 12/22/20 2:12 PM, Rekel wrote: > Now I'm unsure how to check this, I tried to a bit using the online > editor and a bit of pointer usage which seemed to confirm my suspicion, > but does this mean that taking a (small) slice at the end of a > (possibly) very large dynamic array can lead to

Re: Trying to understand multidimensional arrays in D

2020-12-22 Thread Ali Çehreli via Digitalmars-d-learn
On 12/22/20 10:53 AM, Rekel wrote:> On Tuesday, 22 December 2020 at 16:56:18 UTC, Ali Çehreli wrote: >> >[4]Foo b; /* an array of four Foos */ >> >> [4] already has a meaning. ;) > > It does in that context? Do tell, I'm unaware. An array literal with a single int element 4: pragma(msg,

Re: Trying to understand multidimensional arrays in D

2020-12-22 Thread Ali Çehreli via Digitalmars-d-learn
On 12/22/20 8:56 AM, Ali Çehreli wrote: > * already means "derefence" "dereference" > > But now we're no longer C-like, I guess.x That x seems to be due to my fat Emacs fingers. Ali

Re: Trying to understand multidimensional arrays in D

2020-12-22 Thread Ali Çehreli via Digitalmars-d-learn
On 12/22/20 6:35 AM, ag0aep6g wrote: > Flip the pointer syntax, too: > > *Foo a; /* a pointer to a Foo */ I am not a language expert but I think that would make D's parsing complicated (like C++'s < token) because * already means "derefence" in that position. So, the parser would see

Re: Trying to understand multidimensional arrays in D

2020-12-21 Thread Ali Çehreli via Digitalmars-d-learn
On 12/21/20 8:47 PM, Rekel wrote: > On Monday, 30 January 2017 at 07:33:34 UTC, Ali Çehreli wrote: >> As others have said, D's array definition is natural because unlike >> C's inside-out (or is that outside-in?) syntax, it follows from the >> alias syntax. Replacing History inside main with

Re: Flag & byLine confusion.

2020-12-19 Thread Ali Çehreli via Digitalmars-d-learn
On 12/19/20 4:40 PM, Mike Parker wrote: >> 1. Yes.keepTerminator > > This is because of Yes is a struct with an opDispatch template that > "forwards" to Flag!"keepTerminator".yes. This is the preferred syntax > and will work with any Flag parameter. I use Flag a lot but I am always bugged by

Re: Avoid deallocate empty arrays?

2020-12-17 Thread Ali Çehreli via Digitalmars-d-learn
On 12/17/20 8:48 AM, Ali Çehreli wrote: > There is also assumeUnique() I meant assumeSafeAppend(). Ali

Re: Avoid deallocate empty arrays?

2020-12-17 Thread Ali Çehreli via Digitalmars-d-learn
On 12/17/20 8:11 AM, IGotD- wrote: > It's common using arrays for buffering, that means constantly adding > elements and empty the elements. I show an example of this at the following point in a DConf presentation: https://youtu.be/dRORNQIB2wA?t=791 The following code: int[] outer;

Re: extern(C) and name mangling

2020-12-15 Thread Ali Çehreli via Digitalmars-d-learn
On 12/15/20 2:04 PM, Dave P. wrote: > I want to pass > some templated functions as function pointers to some C code As Mike Parker said, it works: // The same thing as a C function pointer: alias Func = long function(int); long bar(T)(int) { return 0; } Func f0 = &(bar!float); Func d1 =

Re: how to print progress of a long running parallel() loop?

2020-12-07 Thread Ali Çehreli via Digitalmars-d-learn
On 12/7/20 4:48 AM, Dukc wrote: On Monday, 7 December 2020 at 08:16:50 UTC, mw wrote: r = Parallel(n_jobs=2, verbose=10)(delayed(sleep)(.2) for _ in range(10)) to print out the progress. How to do this in D's parallel loop? thanks. Allocate a `shared int` before the foreach loop. In the

Re: My first application in Dlang

2020-12-03 Thread Ali Çehreli via Digitalmars-d-learn
On 12/2/20 7:54 PM, Marcone wrote: > Hi, are you Ali Çehreli author of Programming in D book? I am. > I learned Dlang > by reading this book on my Kindle. That makes me happy! :) > If I published my source code you > wouldn't understand. Still, that's the most interesting part to D

Re: Development: Work vs Lazy Programmers... How do you keep sanity?

2020-12-03 Thread Ali Çehreli via Digitalmars-d-learn
On 12/3/20 7:18 AM, matheus wrote: > I didn't know where to post this and I hope this is a good place. I appreciate the question. You can start the subject with [OT] to mean off-topic. > work with Lazy or even Dumb > programmers, and If yes how do you keep your sanity? I used to blame my

Re: My first application in Dlang

2020-12-02 Thread Ali Çehreli via Digitalmars-d-learn
On 12/2/20 5:46 PM, Marcone wrote: Hello, my name is Marcone, I live in Brazil, and I have been studying Dlang for a year. I finished my first application in Dlang with a graphical interface in Win32api and made it available on the internet for anyone who wants to download it. Here is the

Re: A strange charArray.ptr behavior

2020-12-02 Thread Ali Çehreli via Digitalmars-d-learn
On 12/2/20 12:20 PM, Ferhat Kurtulmuş wrote: given the function: export void ceaser_enc(char* input, ref char* output); this compiles:     char* sezar = (new char[65]).ptr;     ceaser_enc(key, sezar); this does not compile:     char[] sezar = new char[65];     ceaser_enc(key, sezar.ptr);

Re: How make Optional pre determined parameter type without overload function?

2020-11-28 Thread Ali Çehreli via Digitalmars-d-learn
On 11/28/20 6:40 PM, Marcone wrote: void a(T1, T2)(T1 b, T2 c){ // I need parameter "c" optional, but only (String or int). How can I make it without overload function? } Since it's optional, T2 must have a default type. I made it 'int' below. void a(T1, T2 = int)(T1 b, T2 c = T2.init)

Re: lambda recursion

2020-11-27 Thread Ali Çehreli via Digitalmars-d-learn
On 11/27/20 9:01 AM, ddcovery wrote: On Friday, 27 November 2020 at 16:40:43 UTC, ddcovery wrote: ... * Can the lambda be transformed to a template (using T instead "int") but avoiding function/return syntax? This is an example using function   template qs(T){     T[] qs( T[] items ){  

Re: implementing default opCmp

2020-11-19 Thread Ali Çehreli via Digitalmars-d-learn
On 11/19/20 6:12 AM, Steven Schveighoffer wrote: On 11/18/20 6:06 PM, ag0aep6g wrote: int opCmp(S other) { import std.typecons: tuple; return tuple(this.tupleof).opCmp(tuple(other.tupleof)); } Ah, excellent solution! I hadn't thought of that. -Steve

Re: Calling function within class.

2020-11-18 Thread Ali Çehreli via Digitalmars-d-learn
On 11/18/20 7:01 AM, Vino wrote: >Request your help on how to call a function(listFile) from another > function(getFilelist) within the same class(GetDirlist), below is an > example code. That code looks unnecessarily complex to me. First of all, parallel() already executes the loop body

Re: Calling function within class.

2020-11-18 Thread Ali Çehreli via Digitalmars-d-learn
On 11/18/20 11:25 AM, Vino wrote: > why is this > so complicated in D where as in PHP it is simple like below > > PHP Code: > class PHPclass { >function test1 ($st) { return $st; } >function test2 () { return $this->test1("Test"); } > } > > $obj = new PHPclass(); >

Re: Iterating chars by Word

2020-11-12 Thread Ali Çehreli via Digitalmars-d-learn
On 11/12/20 9:14 PM, Виталий Фадеев wrote: Is: wchar[] chars;  // like a: "import core.sys.windows.windows;\nimport std.conv  : to;\n" Goal: foreach ( word; chars.byWord ) {     // ... } Iterating chars by Word... How to ? ( simple, fast, low memory, beauty, perfect ) import

Re: Extract sub string from a string

2020-11-09 Thread Ali Çehreli via Digitalmars-d-learn
On 11/9/20 9:53 AM, k2aj wrote: > string text = "welcome2worldinfo"; > string hg = toUpper(text[0..7] ~ "-" ~ text[7..8] ~ "-" ~ text[8..13]); If those concatenations with the ~ operators prove to be costly at runtime, the following range expression may be faster because it does not allocate

Re: toStringz lifetime

2020-11-08 Thread Ali Çehreli via Digitalmars-d-learn
On 11/8/20 6:58 PM, rikki cattermole wrote: > On 09/11/2020 2:58 PM, Ali Çehreli wrote: >> Does the D GC know the complete function call stack of the C program >> all the way up from 'main'? Is there the concept of "bottom of the >> stack" >

Re: toStringz lifetime

2020-11-08 Thread Ali Çehreli via Digitalmars-d-learn
On 10/25/20 3:19 AM, rikki cattermole wrote: On 25/10/2020 11:03 PM, Ali Çehreli wrote: Does the GC see that local variable 'name' that is on the C side? What I don't know is whether the GC is aware only of the stack frames of D functions or the entire thread, which would include the C

Does dmd's -i "include imported modules in the compilation" switch generate object files?

2020-11-03 Thread Ali Çehreli via Digitalmars-d-learn
-i is a useful feature: https://dlang.org/dmd-linux.html Does dmd compile auto-included files separately? Does it generate temporary object files? If so, where does it write the files? Would -i cause race conditions on the file system? Thank you, Ali

Re: I need a most simple and easy example to understand UDA.

2020-11-01 Thread Ali Çehreli via Digitalmars-d-learn
On 11/1/20 1:11 PM, Anonymouse wrote: On Sunday, 1 November 2020 at 20:33:15 UTC, Marcone wrote: I need a most simple and easy example to understand UDA. https://ddili.org/ders/d.en/uda.html The difficulty of understanding UDAs comes up from time to time. Obviously, there are some crucial

Re: What is the difference between enum and shared immutable?

2020-10-29 Thread Ali Çehreli via Digitalmars-d-learn
On 10/29/20 10:16 AM, H. S. Teoh wrote: > Module-level immutable can be initialized either as part of the > declaration: > >immutable int x = 1; To add, the expression can be a call to a function that need not return immutable, as long as it is pure, which can be inferred by the compiler

Re: What is the difference between enum and shared immutable?

2020-10-29 Thread Ali Çehreli via Digitalmars-d-learn
On 10/28/20 3:07 PM, H. S. Teoh wrote: A shared immutable is initialized at compile-time, To prevent a misunderstanding, immutable can be initialized at run time as well. On the other hand, immutable initialized at compile time was surprising to me when I learned it recently: import std;

Re: What is the difference between enum and shared immutable?

2020-10-29 Thread Ali Çehreli via Digitalmars-d-learn
On 10/28/20 5:55 PM, matheus wrote: On Wednesday, 28 October 2020 at 22:07:06 UTC, H. S. Teoh wrote: ... (This is why it's a bad idea to use enum with an array literal, because every time it's referenced you get a new copy of the array.) ... Could you please give an example (Snippet) about

Re: Print int[string] sorted by Value

2020-10-28 Thread Ali Çehreli via Digitalmars-d-learn
On 10/28/20 9:30 AM, Paul wrote: > 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. No, both

Re: Unexpected behaviour using remove on char[]

2020-10-25 Thread Ali Çehreli via Digitalmars-d-learn
On 10/25/20 12:29 PM, IGotD- wrote: What I discovered is that remove doesn't really remove size number of bytes but also removed entire multibyte characters and consider that one step. The result was of course that I got out of bounds exceptions as it went past the end. This is the infamous

<    3   4   5   6   7   8   9   10   11   12   >