Re: Removing elements from dynamic arrays?

2022-04-04 Thread Salih Dincer via Digitalmars-d-learn
On Monday, 4 April 2022 at 23:15:30 UTC, Enjoys Math wrote: ```d // remove an item from an array template drop(T) { T drop( inout T[] arr, T which ) { int i; T result; for (i=0; i < arr.length; i++) {

Re: Removing elements from dynamic arrays?

2022-04-04 Thread Ali Çehreli via Digitalmars-d-learn
On 4/4/22 16:15, Enjoys Math wrote: > https://forum.dlang.org/post/eih04u$1463$1...@digitaldaemon.com 2006 is a long time ago. :) > A version of the code that takes `T which` as a parameter instead of > `int index`. > > ``` > // remove an item from an array > template drop(T) > { >T drop(

Re: Google Code Jam 2022

2022-04-04 Thread Siarhei Siamashka via Digitalmars-d-learn
A plot twist. I actually used Golang for submitting all my solutions in the qualification round: https://codingcompetitions.withgoogle.com/codejam/submissions/00876ff1/0048a518 The reason is that right now I'm switching to Golang at work. And Code Jam tasks are a good practice

Removing elements from dynamic arrays?

2022-04-04 Thread Enjoys Math via Digitalmars-d-learn
https://forum.dlang.org/post/eih04u$1463$1...@digitaldaemon.com A version of the code that takes `T which` as a parameter instead of `int index`. ``` // remove an item from an array template drop(T) { T drop( inout T[] arr, T which ) { int i; T

How do you get passed `LNK: cannot find python39.lib` errors when using PyD for Python to D calling?

2022-04-04 Thread Enjoys Math via Digitalmars-d-learn
``` C:\Users\FruitfulApproach\Desktop\BananaCats\BananaCatsInD\pyd\infrastructure\pyd\make_object.d(1190): Deprecation: returning `` escapes a reference to parameter `this` C:\Users\FruitfulApproach\Desktop\BananaCats\BananaCatsInD\pyd\infrastructure\pyd\make_object.d(1190): perhaps

Re: Const Variables

2022-04-04 Thread Ali Çehreli via Digitalmars-d-learn
On 4/4/22 13:37, H. S. Teoh wrote: >> I remember reading somewhat similar requests in the past: Assign to a >> variable freely but at some point say "no more mutation to this >> variable". > [...] > > It's not just "assign freely"; it's "assign once". Or rather, "assign > before the outside

Re: Const Variables

2022-04-04 Thread H. S. Teoh via Digitalmars-d-learn
On Mon, Apr 04, 2022 at 11:20:31AM -0700, Ali Çehreli via Digitalmars-d-learn wrote: > On 4/3/22 17:42, H. S. Teoh wrote: > > > In some sense, this is like an extension of ctors initializing > > immutable values. The compiler tracks whether the variable has been > > initialized yet, and inside

Re: Const Variables

2022-04-04 Thread Ali Çehreli via Digitalmars-d-learn
On 4/3/22 17:42, H. S. Teoh wrote: > In some sense, this is like an extension of ctors initializing immutable > values. The compiler tracks whether the variable has been initialized > yet, and inside the ctor you can assign to immutable because the > uninitialized value is not observable from

Re: I want to append to lists without using append

2022-04-04 Thread Vinod K Chandran via Digitalmars-d-learn
On Monday, 4 April 2022 at 13:32:19 UTC, Steven Schveighoffer wrote: This looks more like lisp or scheme. You know this is a forum for the D programming language? This was the same question in my mind.

Re: I want to append to lists without using append

2022-04-04 Thread Paul Backus via Digitalmars-d-learn
On Monday, 4 April 2022 at 12:57:28 UTC, V3nom wrote: define the lists: (define liste (cons 10(cons 20(cons 30(cons 40 ' ()) (define liste2 (cons 20(cons 30(cons 10(cons 40 ' ()) define the "function": (define (listapp list1 list2)( if (null? (cdr list1))

Re: I want to append to lists without using append

2022-04-04 Thread Steven Schveighoffer via Digitalmars-d-learn
On 4/4/22 8:57 AM, V3nom wrote: define the lists: (define liste (cons 10(cons 20(cons 30(cons 40 ' ()) (define liste2 (cons 20(cons 30(cons 10(cons 40 ' ()) This looks more like lisp or scheme. You know this is a forum for the D programming language? -Steve

I want to append to lists without using append

2022-04-04 Thread V3nom via Digitalmars-d-learn
define the lists: (define liste (cons 10(cons 20(cons 30(cons 40 ' ()) (define liste2 (cons 20(cons 30(cons 10(cons 40 ' ()) define the "function": (define (listapp list1 list2)( if (null? (cdr list1)) (cons (car list1) (listapp list2 (cdr list1)))

Re: Is it safe to read to memory after it has been allocated with `pureMalloc` and `pureRealloc`?

2022-04-04 Thread rempas via Digitalmars-d-learn
On Monday, 4 April 2022 at 09:26:13 UTC, Stanislav Blinov wrote: No. Neither `malloc` nor `realloc` (for which D's `pure...` variants are mere wrappers) are specified to initialize allocated memory. `calloc`, however, is - it initializes allocated block with zeroes. Thanks, that's what I was

Re: Is it safe to read to memory after it has been allocated with `pureMalloc` and `pureRealloc`?

2022-04-04 Thread Salih Dincer via Digitalmars-d-learn
On Monday, 4 April 2022 at 07:48:40 UTC, rempas wrote: Maybe, I didn't explained it properly. The example works. However, I wonder if it randomly works or if it is safe to do something like that as if the bytes have been initialized to '\0'. ```d import core.memory : pureMalloc; import

Re: Is it safe to read to memory after it has been allocated with `pureMalloc` and `pureRealloc`?

2022-04-04 Thread Stanislav Blinov via Digitalmars-d-learn
On Monday, 4 April 2022 at 07:32:00 UTC, rempas wrote: In other terms, do these functions auto-initialize memory to be ready for use? No. Neither `malloc` nor `realloc` (for which D's `pure...` variants are mere wrappers) are specified to initialize allocated memory. `calloc`, however, is -

Re: Is it safe to read to memory after it has been allocated with `pureMalloc` and `pureRealloc`?

2022-04-04 Thread rempas via Digitalmars-d-learn
On Monday, 4 April 2022 at 07:39:08 UTC, Salih Dincer wrote: On Monday, 4 April 2022 at 07:32:00 UTC, rempas wrote: Does anyone knows what's going on here? Source code? Why does it matter? ``` import core.memory; import core.stdc.stdio; import core.stdc.stdlib; extern (C) void main() {

Re: Is it safe to read to memory after it has been allocated with `pureMalloc` and `pureRealloc`?

2022-04-04 Thread Salih Dincer via Digitalmars-d-learn
On Monday, 4 April 2022 at 07:32:00 UTC, rempas wrote: Does anyone knows what's going on here? Source code?

Is it safe to read to memory after it has been allocated with `pureMalloc` and `pureRealloc`?

2022-04-04 Thread rempas via Digitalmars-d-learn
In other terms, do these functions auto-initialize memory to be ready for use? I test it out using `printf` to print a string. "%s" expects for a null terminated string and it seems to work so I suppose that these functions auto-initialize the bytes to `\0`. However, memory is tricky and I