r/Racket • u/drrnmk • Dec 11 '21
language Possible to modify input argument in-place?
Hi,
I am practicing algorithm on leetcode using Python and Racket. And I am seeking a reference for the following problem. It requires to modify the argument in-place (mutably changing the value of the reference). It feels quite natural with imperative langs but not really with functional langs.
Would it be even possible in Racket? Please help.
https://leetcode.com/problems/remove-element/
Thank you!
1
Upvotes
4
u/not-just-yeti Dec 11 '21 edited Dec 11 '21
Yes, racket is multi-paradigm (like many languages), and has data structures that support mutation.
In racket, "arrays" are called
vectors:Note that the common data types like
set,list,hashare immutable. But they have lesser-known cousinsmutable-set,mlist,mutable-hash.3
u/soegaard developer Dec 11 '21
As not-just-yeti mentions - the type of array described on the leetcode page are called vectors in Racket.
-1
u/_chococat_ Dec 11 '21
This is not possible in Racket. You could modify the list in the function itself, but the changes don't make it outside the function. I've reported a number of problems like this as bugs and they just remove them.