Re: Can we use strings with scanf?

2021-01-25 Thread Rempas via Digitalmars-d-learn
On Monday, 25 January 2021 at 10:33:14 UTC, Mike Parker wrote: On Monday, 25 January 2021 at 09:16:11 UTC, Rempas wrote: For printf() we can use this format `"%.*s", cast(int)s s.length, s.ptr`. When trying to use the same for scanf(), it says that this specifier is invalid. The * has a

How to covert dchar and wchar to string?

2021-01-25 Thread Rempas via Digitalmars-d-learn
Actually what the title says. For example I have dchar c = '\u03B3'; and I want to make it into string. I don't want to use "to!string(c);". Any help?

Re: Can we use strings with scanf?

2021-01-25 Thread Rempas via Digitalmars-d-learn
On Monday, 25 January 2021 at 18:28:09 UTC, Ferhat Kurtulmuş wrote: On Monday, 25 January 2021 at 17:38:21 UTC, Rempas wrote: On Monday, 25 January 2021 at 10:33:14 UTC, Mike Parker wrote: [...] Thanks! Actually for some reason. It won't accept a char[size]. I created a heap allocated (with

What are the advantages of using betterC?

2021-01-19 Thread Rempas via Digitalmars-d-learn
Sorry if that's a stupid question but I've read [this](https://dlang.org/spec/betterc.html) post that talks about betterC but I didn't understand where betterC is being used and what are the advantages it gives. Can anyone help me out with this?

Re: What are the advantages of using betterC?

2021-01-19 Thread Rempas via Digitalmars-d-learn
On Tuesday, 19 January 2021 at 18:04:42 UTC, Adam D. Ruppe wrote: On Tuesday, 19 January 2021 at 17:44:03 UTC, Rempas wrote: Oh ok! So there is not advantage from using it like faster compile time, better performance etc. right? The default betterC build will compile about a quarter second

Re: What are the advantages of using betterC?

2021-01-19 Thread Rempas via Digitalmars-d-learn
On Tuesday, 19 January 2021 at 17:40:52 UTC, Adam D. Ruppe wrote: betterC is a niche restricted feature set. If you don't already have a use case in mind, I'd recommend avoiding it. It is for cases where you're stuck with certain limitations to integrate with the outside world. Like running

Can we use strings with scanf?

2021-01-25 Thread Rempas via Digitalmars-d-learn
For printf() we can use this format `"%.*s", cast(int)s s.length, s.ptr`. When trying to use the same for scanf(), it says that this specifier is invalid.

DUB doesn't seem to respect my config, am I doing something wrong?

2021-05-22 Thread rempas via Digitalmars-d-learn
I've read the documentation about DUB's config (I'm using the SDL format) and it seems that DUB completely ignores my config. My config file is: ``` name "test" description "Testing dub" authors "rempas" copyright "Copyright © 2021, rempas" license "AGPL-3.0" compiler "ldc2" configuration

Re: DUB doesn't seem to respect my config, am I doing something wrong?

2021-05-23 Thread rempas via Digitalmars-d-learn
On Sunday, 23 May 2021 at 15:00:37 UTC, Steven Schveighoffer wrote: The "build types" section is saying what the EQUIVALENT build types are when passing on command line. [...] This will do it! Thanks a lot!

Re: DUB doesn't seem to respect my config, am I doing something wrong?

2021-05-23 Thread rempas via Digitalmars-d-learn
On Sunday, 23 May 2021 at 09:45:06 UTC, Guillaume Piolat wrote: On Saturday, 22 May 2021 at 20:28:56 UTC, rempas wrote: [...] Hello, DUB has two separate concepts: [...] Thanks a lot man!

Re: DUB doesn't seem to respect my config, am I doing something wrong?

2021-05-23 Thread rempas via Digitalmars-d-learn
On Sunday, 23 May 2021 at 04:56:18 UTC, Mike Parker wrote: I just looked in the dub documentation for "build" and "compiler" entries, which I had never heard of, and I see none now. As Jordan said, those have always been configured on the command line. Did you perhaps see something about those

Re: DUB doesn't seem to respect my config, am I doing something wrong?

2021-05-23 Thread rempas via Digitalmars-d-learn
On Sunday, 23 May 2021 at 00:36:48 UTC, Jordan Wilson wrote: On Saturday, 22 May 2021 at 20:28:56 UTC, rempas wrote: [...] Ignoring the "dubug" typo...normally, I think you pass compiler values directly to dub via the ```--compiler``` flag. For example: ```shell dub --config=development

Re: Can I make system calls directly from D?

2021-07-09 Thread rempas via Digitalmars-d-learn
On Friday, 9 July 2021 at 08:18:51 UTC, Ferhat Kurtulmuş wrote: On Friday, 9 July 2021 at 08:08:57 UTC, rempas wrote: I just wonder if I'm able to do system calls directly from D or If I have to create bindings from "unistd.h" from C I don't know if it covers what you want but, druntime has

Re: Why I'm getting this "Range Violation" error?

2021-07-09 Thread rempas via Digitalmars-d-learn
On Friday, 9 July 2021 at 07:38:50 UTC, Mike Parker wrote: On Friday, 9 July 2021 at 07:21:06 UTC, rempas wrote: When I execute it, I'm getting a range violation error. If I try to set "len" to be the length of the "prompt" minus 1, then it will work and it will print the "prompt" until the

Re: Why I'm getting this "Range Violation" error?

2021-07-09 Thread rempas via Digitalmars-d-learn
On Friday, 9 July 2021 at 07:54:44 UTC, zjh wrote: On Friday, 9 July 2021 at 07:21:06 UTC, rempas wrote: I have the following code: `prompt[i]!='{'`,here,i=len.so `array overflow` Thanks a lot. It seems I have a lot to learn. Have an amazing day!

Re: Can I make system calls directly from D?

2021-07-09 Thread rempas via Digitalmars-d-learn
On Friday, 9 July 2021 at 08:28:25 UTC, Dennis wrote: On Friday, 9 July 2021 at 08:08:57 UTC, rempas wrote: I just wonder if I'm able to do system calls directly from D or If I have to create bindings from "unistd.h" from C If with directly means 'without calling any C function' you can use

Can I make system calls directly from D?

2021-07-09 Thread rempas via Digitalmars-d-learn
I just wonder if I'm able to do system calls directly from D or If I have to create bindings from "unistd.h" from C

Re: Where is "open" in "core.sys.linux.unistd"?

2021-07-09 Thread rempas via Digitalmars-d-learn
On Friday, 9 July 2021 at 15:11:38 UTC, Steven Schveighoffer wrote: On 7/9/21 10:51 AM, rempas wrote: The file can be found quickly [here](https://github.com/dlang/druntime/blob/master/src/core/sys/posix/unistd.d) or in your system if you want. Now the question is, why isn't there an "open"

Re: Where is "open" in "core.sys.linux.unistd"?

2021-07-09 Thread rempas via Digitalmars-d-learn
On Friday, 9 July 2021 at 15:31:50 UTC, Dennis wrote: On Friday, 9 July 2021 at 15:11:38 UTC, Steven Schveighoffer wrote: But reading/writing, closing these file descriptors is always the same. For sockets you'd typically use `recv` and `send` instead or `read` and `write` because the former

Re: Where is "open" in "core.sys.linux.unistd"?

2021-07-09 Thread rempas via Digitalmars-d-learn
On Friday, 9 July 2021 at 15:04:32 UTC, rikki cattermole wrote: On 10/07/2021 2:51 AM, rempas wrote: The file can be found quickly [here](https://github.com/dlang/druntime/blob/master/src/core/sys/posix/unistd.d) or in your system if you want. Now the question is, why isn't there an "open"

Where is "open" in "core.sys.linux.unistd"?

2021-07-09 Thread rempas via Digitalmars-d-learn
The file can be found quickly [here](https://github.com/dlang/druntime/blob/master/src/core/sys/posix/unistd.d) or in your system if you want. Now the question is, why isn't there an "open" function for the equivalent system call? "close", "write", "read" etc. all exist. Anyone knows what's going

Re: Where is "open" in "core.sys.linux.unistd"?

2021-07-09 Thread rempas via Digitalmars-d-learn
On Friday, 9 July 2021 at 15:37:41 UTC, Ali Çehreli wrote: On 7/9/21 8:31 AM, rempas wrote: > I searched "fnctl" in the repo [...] Probably made a typo Yes, the typo should be obvious to the non-dyslexic among us. :) fnctl <-- wrong fcntl <-- correct Ali Lol, I'm not dyslexic (or at least

Re: Why I'm getting this "Range Violation" error?

2021-07-09 Thread rempas via Digitalmars-d-learn
On Friday, 9 July 2021 at 11:56:40 UTC, Ali Çehreli wrote: In addition to what others said, you can take advantage of ranges to separate concerns of filtering and iteration. Here are two ways: [...] Of course another help from the legend himself ;) As always thanks a lot and have an

Why I'm getting this "Range Violation" error?

2021-07-09 Thread rempas via Digitalmars-d-learn
I have the following code: ``` import core.stdc.stdio; void print(T)(string prompt, T args...) { size_t len = prompt.length; size_t i = 0; while (prompt[i] != '{' && i < len) { printf("%c", prompt[i]); i++; } } void main() { print("Hello, world!\n", 10); } ``` When I

Re: Can I get the time "Duration" in "nsecs" acurracy?

2021-07-09 Thread rempas via Digitalmars-d-learn
On Friday, 9 July 2021 at 20:54:21 UTC, Paul Backus wrote: On Friday, 9 July 2021 at 20:43:48 UTC, rempas wrote: I'm reading the library reference for [core.time](https://dlang.org/phobos/core_time.html#Duration) and It says that the duration is taken in "hnsecs" and I cannot understand if we

Can I get the time "Duration" in "nsecs" acurracy?

2021-07-09 Thread rempas via Digitalmars-d-learn
I'm reading the library reference for [core.time](https://dlang.org/phobos/core_time.html#Duration) and It says that the duration is taken in "hnsecs" and I cannot understand if we can change that and choose the precision. Does anyone know if we can do that?

Re: Can I get the time "Duration" in "nsecs" acurracy?

2021-07-10 Thread rempas via Digitalmars-d-learn
On Friday, 9 July 2021 at 21:04:42 UTC, Ali Çehreli wrote: On 7/9/21 1:54 PM, Paul Backus wrote: [...] Yes but the resolution seems not to be better than 100 nsecs. A quick research reveals a better resolution is not possible with common hardware on at least Linux. The following program

Re: What exactly are the String literrals in D and how they work?

2021-08-15 Thread rempas via Digitalmars-d-learn
On Sunday, 15 August 2021 at 07:43:59 UTC, jfondren wrote: ```d unittest { pragma(msg, typeof("John")); // string pragma(msg, is(typeof("John") == immutable(char)[])); // true } ``` Still don't know what "pragma" does but thank you. ```d void zerort(string s) {

Re: What exactly are the String literrals in D and how they work?

2021-08-15 Thread rempas via Digitalmars-d-learn
On Sunday, 15 August 2021 at 08:17:47 UTC, rikki cattermole wrote: pragma is a set of commands to the compiler that may be compiler specific. In the case of the msg command, it tells the compiler to output a message to stdout during compilation. Thanks man!

Re: What exactly are the String literrals in D and how they work?

2021-08-15 Thread rempas via Digitalmars-d-learn
On Sunday, 15 August 2021 at 08:47:39 UTC, jfondren wrote: dup() isn't aware of the NUL since that's outside the slice of the string. It only copies the chars in "John". You can use toStringz to ensure NUL termination: https://dlang.org/phobos/std_string.html#.toStringz Is there something

Re: What exactly are the String literrals in D and how they work?

2021-08-15 Thread rempas via Digitalmars-d-learn
On Sunday, 15 August 2021 at 08:53:50 UTC, Tejas wrote: External C libraries expect strings to be null terminated, so if you do use `.dup`, use `.toStringz` as well. Yeah, yeah I got that. My question is, if I should avoid `cast(char*)` and use `.toStringz` while both do the exact same

Re: What exactly are the String literrals in D and how they work?

2021-08-15 Thread rempas via Digitalmars-d-learn
On Sunday, 15 August 2021 at 09:01:17 UTC, jfondren wrote: They don't do the same thing. toStringz always copies, always GC-allocates, and always NUL-terminates. `cast(char*)` only does what you want in the case that you're applying it a string literal. But in that case you shouldn't cast, you

Re: What exactly are the String literrals in D and how they work?

2021-08-15 Thread rempas via Digitalmars-d-learn
On Sunday, 15 August 2021 at 09:06:14 UTC, Mike Parker wrote: The D `string` is an alias for `immutable(char)[]`, immutable contents of a mutable array reference (`immutable(char[])` would mean the array reference is also immutable). You don't want to assign that to a `char*`, because then

What exactly are the String literrals in D and how they work?

2021-08-15 Thread rempas via Digitalmars-d-learn
So when I'm doing something like the following: `string name = "John";` Then what's the actual type of the literal `"John"`? In the chapter [Calling C functions](https://dlang.org/spec/interfaceToC.html#calling_c_functions) in the "Interfacing with C" page, the following is said: Strings are

How to do "C++ classes"?

2021-09-18 Thread rempas via Digitalmars-d-learn
I'm seeing in the page about "BeterC" and in the part about the [retained features](https://dlang.org/spec/betterc.html#retained), the #11 says about "COM classes and C++ classes". What are the "C++ classes"? I tried to create a class using "extern(C++)" but this didn't worked. Can someone

Re: How to do "C++ classes"?

2021-09-19 Thread rempas via Digitalmars-d-learn
On Saturday, 18 September 2021 at 22:16:32 UTC, Adam D Ruppe wrote: On Saturday, 18 September 2021 at 15:38:38 UTC, rempas wrote: I'm seeing in the page about "BeterC" and in the part about the [retained features](https://dlang.org/spec/betterc.html#retained), the #11 says about "COM classes

Re: How to "stringnify"?

2021-10-10 Thread rempas via Digitalmars-d-learn
On Sunday, 10 October 2021 at 08:48:21 UTC, Imperatorn wrote: For simple stuff you have .stringof Thanks!

Re: How to "stringnify"?

2021-10-10 Thread rempas via Digitalmars-d-learn
On Sunday, 10 October 2021 at 08:54:55 UTC, evilrat wrote: That's probably depends on what you are trying to achieve. If you want to write code-like string that looks like a code you can use token strings https://dlang.org/spec/lex.html#token_strings ```d string code = q{ float sqr(float

How to "stringnify"?

2021-10-10 Thread rempas via Digitalmars-d-learn
Is there a way to "stringnify" in Dlang? In C we would do something like the following: `#define STRINGIFY(x) #x` What's the equivalent in D?

How to do a function pointer to "malloc" and "free"?

2021-10-10 Thread rempas via Digitalmars-d-learn
I'm having the following C code: ``` static void* (*ppmalloc)(size_t) = malloc; static void (*ppfree)(void*) = free; ``` I want to covert this code in D so I try to do the following: ``` static void* function(size_t)*ppmalloc = malloc; static void function(void*)*ppfree = free; ``` If I do

What is a "comma expression"?

2021-10-10 Thread rempas via Digitalmars-d-learn
This is the first time I'm finding something like that. I'm having the following code in C: ``` if (0 == (i >> 7)) { if (len < 1) return -1; v = i; return *ret = v, 1; } ``` This is part of a function that returns an `int`. When I'm running this in C, it works. However in D,

Re: How to do a function pointer to "malloc" and "free"?

2021-10-10 Thread rempas via Digitalmars-d-learn
On Sunday, 10 October 2021 at 13:52:57 UTC, Elmar wrote: Hopefully it will :-) . D has some good C support. You can call any C function from `D` by declaring it `extern(C) `. The language subset "BetterC" is required for calling D functions from C though. Unfortunately, the runtime

Re: How to do a function pointer to "malloc" and "free"?

2021-10-10 Thread rempas via Digitalmars-d-learn
On Sunday, 10 October 2021 at 14:00:37 UTC, Elmar wrote: On Sunday, 10 October 2021 at 13:56:06 UTC, rempas wrote: Actually I know about BetterC and how to call C functions from D and visa versa. I would also disagree that "BetterC" is almost no improvement over C as about 90% of the

Re: What is a "comma expression"?

2021-10-10 Thread rempas via Digitalmars-d-learn
On Sunday, 10 October 2021 at 12:13:47 UTC, Elmar wrote: Hello rempas. The comma-operator `,` is like `;` but results in an expression value, not a statement like `;` would. The left side of `,` is executed like a statement and the value of the right side of `,` is returned.

Re: How to do a function pointer to "malloc" and "free"?

2021-10-10 Thread rempas via Digitalmars-d-learn
On Sunday, 10 October 2021 at 11:26:18 UTC, Elmar wrote: Hello rempas. This is the way: ```d import core.stdc.stdlib : malloc, free; extern(C) void* function(ulong) mallocPointer = extern(C) void function(void*) freePointer = ``` `function` in the type is already a function pointer. Not

Re: What is a "comma expression"?

2021-10-10 Thread rempas via Digitalmars-d-learn
On Sunday, 10 October 2021 at 12:19:39 UTC, Adam D Ruppe wrote: On Sunday, 10 October 2021 at 12:01:33 UTC, rempas wrote: [...] The comma expression in C is a combination of two things but in the context of another thing. Well that's not very good, but like there's statements and

Can we use "ImportC" used yet?

2021-10-15 Thread rempas via Digitalmars-d-learn
Cause I can't find an option in the latest DMD release and because the ImportC [page](https://dlang.org/spec/importc.html#importing) seems to be incomplete (even saying it's under construct), I'm wondering if ImportC exists even as prototype but it's hidden or if it's not available at all.

Re: Can we use "ImportC" used yet?

2021-10-16 Thread rempas via Digitalmars-d-learn
On Saturday, 16 October 2021 at 07:09:16 UTC, jfondren wrote: This test_og.c works (while obviously breaking some bswap functions): I don't know if I should have known that but what is "bswap"? It would be less annoying to compile the original test_og.o with gcc and then link it in. If I

Re: Can we use "ImportC" used yet?

2021-10-16 Thread rempas via Digitalmars-d-learn
On Friday, 15 October 2021 at 20:45:35 UTC, jfondren wrote: There's no option, you just use a normal import statement when the module is named .c instead of .d I say 'just' but typical C uses the C preprocessor and can't be imported as-is. [ ... ] First of all, I see you answering

Re: Can we use "ImportC" used yet?

2021-10-16 Thread rempas via Digitalmars-d-learn
On Saturday, 16 October 2021 at 11:03:06 UTC, jfondren wrote: I came up with those `#define`s by looking at test_c.c as d complained about it. It includes these functions in the final result: ```c static __uint16_t __bswap_16 (__uint16_t __bsx) { return (__bsx); } static __uint32_t

Is it possible to do this with a template?

2021-12-16 Thread rempas via Digitalmars-d-learn
I want to use an expression and put it in place inside the `if` parentheses. The expression is: `is(typeof(val) == type)`. I want to use a template called "is_same" that will take the value and a type to place them to the respective places. I have tried the following but it doesn't seem to

Re: Is it possible to do this with a template?

2021-12-17 Thread rempas via Digitalmars-d-learn
On Friday, 17 December 2021 at 08:44:39 UTC, Mitacha wrote: It isn't really about limitation of templates. You're trying to use mixin template and it's main purpose is to inject declarations. If you want to replace `is expression` with template you could use something like this: ```d bool

Re: How to insert code in place with templates/mixins?

2021-12-20 Thread rempas via Digitalmars-d-learn
On Monday, 20 December 2021 at 09:30:30 UTC, rumbu wrote: because you cannot have statements directly in a template (the fact that is a mixin template is irelevant), only declarations. If you want to just insert some random code, use strings. You can create a templated enum to store your

Re: Is it possible to do this with a template?

2021-12-17 Thread rempas via Digitalmars-d-learn
On Friday, 17 December 2021 at 16:02:45 UTC, RazvanN wrote: There is also a compiler trait [1] which can do that for you: ```d void main() { int val = 10; static if (__traits(isSame, typeof(val), int)) {} } ``` [1] https://dlang.org/spec/traits.html#isSame Thanks! The other options

Re: Is it possible to do this with a template?

2021-12-17 Thread rempas via Digitalmars-d-learn
On Friday, 17 December 2021 at 13:00:55 UTC, Ali Çehreli wrote: On 12/17/21 1:57 AM, bauss wrote: > You can also do it as a normal template: > > ```d > template is_same(alias value, T) > { > enum is_same = is(typeof(value) == T); > } > ``` And even shorter by realizing that it's an

How to insert code in place with templates/mixins?

2021-12-20 Thread rempas via Digitalmars-d-learn
Here I am having a problem with templates again. No matter how much I read, I can't seem to understand how templates/mixins work. So I'm having the following code (just a snippet of the real code): ``` if (c != '%') { if (stdout_index < STDOUT_BUF_LEN) {

Re: How to insert code in place with templates/mixins?

2021-12-20 Thread rempas via Digitalmars-d-learn
On Monday, 20 December 2021 at 11:58:58 UTC, Tejas wrote: Ehh, it still fails; should've explicitly put the length of the array and the `extern (C)` in `main` ```d module demo; [ ... ] extern(C) /+added this because you used -betterC+/ void main() { while (true) {

Re: How to insert code in place with templates/mixins?

2021-12-20 Thread rempas via Digitalmars-d-learn
On Monday, 20 December 2021 at 18:06:32 UTC, rempas wrote: On Monday, 20 December 2021 at 11:58:58 UTC, Tejas wrote: Ehh, it still fails; should've explicitly put the length of the array and the `extern (C)` in `main` ```d module demo; [ ... ] extern(C) /+added this because you used

Re: How to insert code in place with templates/mixins?

2021-12-20 Thread rempas via Digitalmars-d-learn
On Monday, 20 December 2021 at 18:12:35 UTC, Stanislav Blinov wrote: https://dlang.org/spec/traits.html#identifier Thanks!!! Finally I was able to do it! The code is the following (well not in my final project but it's a demonstration): ``` enum add_char(string c) = `if (stdout_index <

Re: How to insert code in place with templates/mixins?

2021-12-20 Thread rempas via Digitalmars-d-learn
On Monday, 20 December 2021 at 11:30:09 UTC, rumbu wrote: Enums (that's why the string is declarated as enum) are evaluated at compile time, the concatenation op will not end in your code as instruction, so you can do anything outside betterC rules as long you do it at compile time. You are

Re: How to print unicode characters (no library)?

2021-12-27 Thread rempas via Digitalmars-d-learn
On Monday, 27 December 2021 at 14:23:37 UTC, Adam D Ruppe wrote: [...] After reading the whole things, I said it and I'll say it again! You guys must get paid for your support I also helped a guy in another forum yesterday writing a very big reply and tbh it felt great :P (or of

Re: How to print unicode characters (no library)?

2021-12-27 Thread rempas via Digitalmars-d-learn
On Monday, 27 December 2021 at 14:47:51 UTC, Kagamin wrote: https://utf8everywhere.org/ - this is an advise from a windows programmer, I use it too. Windows allocates a per thread buffer and when you call, say, WriteConsoleA, it first transcodes the string to UTF-16 in the buffer and calls

Re: How to print unicode characters (no library)?

2021-12-27 Thread rempas via Digitalmars-d-learn
On Monday, 27 December 2021 at 14:30:55 UTC, Adam D Ruppe wrote: Most unix things do utf-8 more often than not, but technically you are supposed to check the locale and change the terminal settings to do it right. Cool! I mean, I don't plan on supporting legacy systems so I think we're fine

Re: How to print unicode characters (no library)?

2021-12-27 Thread rempas via Digitalmars-d-learn
On Monday, 27 December 2021 at 21:38:03 UTC, Era Scarecrow wrote: Well to add functionality with say ANSI you entered an escape code and then stuff like offset, color, effect, etc. UTF-8 automatically has escape codes being anything 128 or over, so as long as the terminal understand it, it

Re: How to properly use variadic templates (functions)?

2021-12-20 Thread rempas via Digitalmars-d-learn
On Monday, 20 December 2021 at 22:02:02 UTC, russhy wrote: Here how i'd do, but i'm not sure how to keep track of the index of the arguments, i forgot.. ```D import core.stdc.stdio: putc, stdout; void print(T...)(string prompt, T args) { foreach (a; args) { alias A =

Re: How to properly use variadic templates (functions)?

2021-12-20 Thread rempas via Digitalmars-d-learn
On Monday, 20 December 2021 at 21:49:59 UTC, Adam D Ruppe wrote: still use foreach(arg; args) and skip that index variable. I know I can use foreach ("static foreach" more specifically) but I need to be able to get the index to choose a specific argument because I want to do formatting

Re: How to properly use variadic templates (functions)?

2021-12-21 Thread rempas via Digitalmars-d-learn
On Tuesday, 21 December 2021 at 08:11:39 UTC, Anonymouse wrote: I'm not certain I understand, but won't `foreach (i, a; args) { /* ... */ }` in his example do that? As in, if you necessarily must index `args` instead of using a foreach variable, ```d import core.stdc.stdio : putc, stdout;

How to print unicode characters (no library)?

2021-12-26 Thread rempas via Digitalmars-d-learn
Hi! I'm trying to print some Unicode characters using UTF-8 (char), UTF-16 (wchar) and UTF-32 (dchar). I want to do this without using any library by using the "write" system call directly with 64-bit Linux. Only the UTF-8 solution seems to be working as expected. The other solutions will not

Re: mixin does not work as expected

2022-01-05 Thread rempas via Digitalmars-d-learn
On Wednesday, 5 January 2022 at 09:02:53 UTC, vit wrote: Try this: ```d pragma(msg, type_check!("static if", "i8", "true", "5", "4", "10", "5")); ``` Result: ```d static if(is_same!(num, i8)) { mixin(base_digit!("5", "4", "10", "5")); static if (true) {

mixin does not work as expected

2022-01-05 Thread rempas via Digitalmars-d-learn
I'm trying to use mixins and enums to "expand" code in place but the results are not what I expected and I'm getting an weird error. I have created the smallest possible example to reproduce the error and it is the following: ``` enum base_digit(string ten, string sixteen, string two, string

Re: mixin does not work as expected

2022-01-05 Thread rempas via Digitalmars-d-learn
On Wednesday, 5 January 2022 at 09:33:07 UTC, vit wrote: 2) if-else must be in same mixin: ```d mixin("" + type_check!("static if", "i8", "true", "5", "4", "10", "5") + type_check!("else static if", "i16", "true", "7", "6", "18", "8") + type_check!("else static if",

Re: mixin does not work as expected

2022-01-05 Thread rempas via Digitalmars-d-learn
On Wednesday, 5 January 2022 at 10:47:44 UTC, rempas wrote: There may be a problem in the "type_check" enum but I wanted to post this reply before I search any any case there is something else happening and you happen to know. I will update if I found it Well, it is specifically the "static

Re: mixin does not work as expected

2022-01-05 Thread rempas via Digitalmars-d-learn
On Wednesday, 5 January 2022 at 17:48:03 UTC, H. S. Teoh wrote: Yeah, this won't fly. Whatever you pass to mixin must be one or more *complete* declaration or (possibly compound) statements. It's illegal to pass the `static if` and its else-clause to two different mixin() invocations (they are

Re: FreeBSD 13 : wrong kernel version and size of kevent_t

2021-12-21 Thread rempas via Digitalmars-d-learn
On Tuesday, 21 December 2021 at 10:28:15 UTC, eugene wrote: filed an issue, see https://issues.dlang.org/show_bug.cgi?id=22615 Nice! Hope they see and fix it soon! Love for open source Operating Systems!!

Re: How to properly use variadic templates (functions)?

2021-12-21 Thread rempas via Digitalmars-d-learn
On Tuesday, 21 December 2021 at 15:42:59 UTC, russhy wrote: Please keep us updated, that'll be interesting to see how a pure D printf would look like! Glad someone is interested! I'm actually planning to make a whole library ;) Check my

Re: How to properly use variadic templates (functions)?

2021-12-21 Thread rempas via Digitalmars-d-learn
On Tuesday, 21 December 2021 at 08:42:35 UTC, vit wrote: You can use switch + static foreach: ```d import std.stdio; //this print args in reverse order: void print(T...)(string prompt, T args) { void print_arg(size_t index){ switch(index){

Re: FreeBSD 13 : wrong kernel version and size of kevent_t

2021-12-21 Thread rempas via Digitalmars-d-learn
I would love to see more full (and correct) support for FreeBSD, OpenBSD and DragonflyBSD from Dlang! Maybe one day..

Re: FreeBSD 13 : wrong kernel version and size of kevent_t

2021-12-21 Thread rempas via Digitalmars-d-learn
On Tuesday, 21 December 2021 at 17:00:06 UTC, Johan wrote: Please add which compiler(s) you have tried in the bug report. Yeah, you are right! Please eugene use LDC2 and check confirm that the behavior is the same there. I think the fix is needed here:

Re: FreeBSD 13 : wrong kernel version and size of kevent_t

2021-12-21 Thread rempas via Digitalmars-d-learn
On Tuesday, 21 December 2021 at 19:00:04 UTC, eugene wrote: Well, I just installed it by pkg intstall ldc Actually, this is my first experience with FreeBSD, I did not have much to go deeper. That's nice trying new things ;) Oh, no, sorry. :) It is the problem of FreeBSD maintainers

Re: FreeBSD 13 : wrong kernel version and size of kevent_t

2021-12-21 Thread rempas via Digitalmars-d-learn
On Tuesday, 21 December 2021 at 18:35:43 UTC, eugene wrote: LDC2 stdlib does not have correct struct event_t for 12+ in /usr/local/include/d/core/sys/freebsd/sys/event.d at all, only for earlier versions, ie without extension field. DMD stdlib does have, the only problem is the OS version is

Re: FreeBSD 13 : wrong kernel version and size of kevent_t

2021-12-21 Thread rempas via Digitalmars-d-learn
On Tuesday, 21 December 2021 at 19:40:52 UTC, eugene wrote: But i like to use software out of the box and do not like compile it from source. Me too! The link I gave you has a binary release with LDC2. You won't have to compile it yourself. I do not see any reason for me to do this. The

Re: FreeBSD 13 : wrong kernel version and size of kevent_t

2021-12-21 Thread rempas via Digitalmars-d-learn
On Tuesday, 21 December 2021 at 19:55:13 UTC, eugene wrote: core/sys/freebsd/config.d and core/sys/freebsd/sys/event.d are the same as in fresh dmd, so there is not much sense to try it. dmd (including phobos) is a reference, and I do not think, that ldc is ahead of dmd with it's stdlib.

Re: How to properly use variadic templates (functions)?

2021-12-21 Thread rempas via Digitalmars-d-learn
On Tuesday, 21 December 2021 at 17:33:09 UTC, Steven Schveighoffer wrote: The reason your original isn't working is that indexing a list of differently-typed things cannot be done using a runtime index. I'd say that an inner function + static foreach + switch is the best way to convert

Is there a way to make a function parameter accept only values that can be checked at compile time?

2021-12-28 Thread rempas via Digitalmars-d-learn
I would like to know if that's possible. Actually I would like to do something like the following: ``` extern (C) void main() { void print_num(int num, comp_time_type int mul) { static if (is(mul == ten)) { printf("%d\n", num * 10); } else static if (is(mul == three)) {

Re: How to print unicode characters (no library)?

2021-12-28 Thread rempas via Digitalmars-d-learn
On Tuesday, 28 December 2021 at 13:04:26 UTC, Adam D Ruppe wrote: What is your library? You might be able to just use my terminal.d too My library will be "libd" it will be like "libc" but better and cooler! And it will be native to D! And of course it will not depend on "libc" and it

Re: How to print unicode characters (no library)?

2021-12-28 Thread rempas via Digitalmars-d-learn
On Tuesday, 28 December 2021 at 14:53:57 UTC, rempas wrote: On Tuesday, 28 December 2021 at 12:56:11 UTC, Adam D Ruppe wrote: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html and that's not quite full either. it really is a mess from hell Still less complicated and organized

Re: How to print unicode characters (no library)?

2021-12-28 Thread rempas via Digitalmars-d-learn
On Tuesday, 28 December 2021 at 12:56:11 UTC, Adam D Ruppe wrote: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html and that's not quite full either. it really is a mess from hell Still less complicated and organized than my life...

How to find how many places from left the dot appears in a flot/double?

2021-12-30 Thread rempas via Digitalmars-d-learn
Let's say that I have the following float/double: 137.837 How can I find how many places from left the dot appears? So in this example I want to take either three or four (depending on how you think it). Does anyone knows how I can do that and can explain it to me?

Re: Is there a way to make a function parameter accept only values that can be checked at compile time?

2021-12-29 Thread rempas via Digitalmars-d-learn
On Tuesday, 28 December 2021 at 22:06:50 UTC, Steven Schveighoffer wrote: On 12/28/21 4:19 PM, rempas wrote: Here: ``` extern (C) void main() {   void print_num(int mul)(int num) {     static if (is(mul == ten)) {   printf("%d\n", num * 10);     } else static if (is(mul == three)) {  

Re: Is there a way to make a function parameter accept only values that can be checked at compile time?

2021-12-29 Thread rempas via Digitalmars-d-learn
On Tuesday, 28 December 2021 at 22:26:33 UTC, max haughton wrote: Why do you need this? What's wrong with a normal branch in this case. Runtime performance. I want the value to get checked at compile time and use "static if" with it

Re: Is there a way to make a function parameter accept only values that can be checked at compile time?

2021-12-29 Thread rempas via Digitalmars-d-learn
On Wednesday, 29 December 2021 at 01:34:22 UTC, Stanislav Blinov wrote: One can also do this kind of stuff: ```d import core.stdc.stdio; struct Literal(alias val) { enum value = val; } enum lit(alias val) = Literal!val.init; void print_num(Arg)(int num, Arg mul) { static if (is(Arg

Re: How to find how many places from left the dot appears in a flot/double?

2021-12-30 Thread rempas via Digitalmars-d-learn
On Thursday, 30 December 2021 at 11:17:39 UTC, afg45 wrote: See the https://en.wikipedia.org/wiki/Common_logarithm fpr the explanations. ``` import std.stdio, std.math; void main(string[] args) { alias numDigits = (f) => log10(f + 0.5).ceil(); } ``` Thanks a lot! However, I used the

Re: FreeBSD 13 : wrong kernel version and size of kevent_t

2021-12-21 Thread rempas via Digitalmars-d-learn
On Tuesday, 21 December 2021 at 21:09:14 UTC, eugene wrote: * The ldc installed by 'pkg install ldc' (the old one), does not have config module * Most resent ldc (link you indicated), does have condig module, and it is exactly the same as condig in most recent dmd Cool! Makes sense! I

Re: How to properly use variadic templates (functions)?

2021-12-22 Thread rempas via Digitalmars-d-learn
On Tuesday, 21 December 2021 at 22:50:57 UTC, russhy wrote: I took a look and to be honest, it's the same story as everything in the STD, they try to do everything at the same time, so they up end calling each other, you end up lost in multiple 8k LOC modules, not understanding what the

Re: FreeBSD 13 : wrong kernel version and size of kevent_t

2021-12-22 Thread rempas via Digitalmars-d-learn
On Wednesday, 22 December 2021 at 08:41:56 UTC, eugene wrote: You thought right - I **DID NOT** try the latest LDC, I just looked into ldc2-1.28.0-freebsd-x86_64.tar.xz archive to see what is in core/sys/freebsd/config.d and in core/sys/freebsd/sys/event.d Both these files are just copies

Re: How to insert code in place with templates/mixins?

2021-12-20 Thread rempas via Digitalmars-d-learn
On Monday, 20 December 2021 at 18:58:39 UTC, bachmeier wrote: You can see the ["String mixins" section here](http://ddili.org/ders/d.en/mixin.html) for more details. Mixins are generated at compile time, so if you're referring to a string mixin inside a runtime loop, the code will not be

Re: FreeBSD 13 : wrong kernel version and size of kevent_t

2021-12-20 Thread rempas via Digitalmars-d-learn
On Sunday, 19 December 2021 at 09:49:29 UTC, eugene wrote: test program: ```d import std.stdio; import core.sys.freebsd.config; import core.sys.freebsd.sys.event; void main(string[] args) { writefln("FreeBSD_version = %s", __FreeBSD_version); writefln("sizeof(kevent_t) = %s",

How to properly use variadic templates (functions)?

2021-12-20 Thread rempas via Digitalmars-d-learn
I'm trying to implement "printf" and I'm getting an error. The smallest possible code to demonstrate the error is: ``` import core.stdc.stdio; void print(T...)(string prompt, T args) { // Suppose all 'args' are of type "string" for this example ulong carg = 0; for (ulong i = 0; i <

Re: FreeBSD 13 : wrong kernel version and size of kevent_t

2021-12-22 Thread rempas via Digitalmars-d-learn
On Wednesday, 22 December 2021 at 09:49:59 UTC, eugene wrote: It looks strange - leading D compiler is not in Linux/FreeBSD repos :) Well no so much. The only official compiler is DMD and when it comes to that, Digital Mars, has pre-built binaries for most Linux distros and for FreeBSD.

Re: How to print unicode characters (no library)?

2021-12-27 Thread rempas via Digitalmars-d-learn
On Monday, 27 December 2021 at 09:29:38 UTC, Kagamin wrote: D strings are plain arrays without any text-specific logic, the element is called code unit, which has a fixed size, and the array length specifies how many elements are in the array. This model is most adequate for memory

  1   2   3   >