samth
2020-5-18 13:42:11

badkins
2020-5-18 14:55:51

I noticed that - thanks!


elyandarin
2020-5-18 17:05:49

Question: How do you go about appending elements to a huge list in a timely manner? Should I use a vector or something instead?


soegaard2
2020-5-18 17:10:10

Depends. Which operations do you need?


soegaard2
2020-5-18 17:11:22

If you are always appending (and never prepending) you could just keep the elements in reverse order.


elyandarin
2020-5-18 17:11:39

I’m just saving a bunch of numbers I want to get a mean value of later


soegaard2
2020-5-18 17:12:39

If you don’t need the actual numbers, then just keep track of the sum and the number of numbers.


elyandarin
2020-5-18 17:13:10

yeah, that would work nicely, thanks


soegaard2
2020-5-18 17:15:00

Btw there is a data structure that is similar to vectors, but can be extended automatically: https://docs.racket-lang.org/data/gvector.html?q=grow


elyandarin
2020-5-18 17:15:44

Good to know :slightly_smiling_face:


jcoo092
2020-5-19 03:20:41

How does one prepend to a list in Racket? Is it just using list*()? I can’t recall having come across another way :confused:


sorawee
2020-5-19 03:42:45

By prepend, do you mean construct (list 1 2 3) from 1 and (list 2 3)?


sorawee
2020-5-19 03:43:03

If so, you can either use list* or cons.


sorawee
2020-5-19 03:43:47

Note that these operations don’t mutate the existing lists, so it’s unlike, say, Python’s append which does mutate the existing list.


jcoo092
2020-5-19 03:46:00

I’m thinking along the lines of :: from Haskell, F# and the like. Which should be the same as your first example :+1::skin-tone–2:


sorawee
2020-5-19 03:54:06

Haskell’s :: is cons


sorawee
2020-5-19 03:54:29

So 1 :: 2 :: [3] would be equivalent to (cons 1 (cons 2 (list 3)))


sorawee
2020-5-19 03:55:01

But to reduce parentheses, we have list* which “flattens” the code that you need to write


sorawee
2020-5-19 03:55:09

So (list* 1 2 (list 3))


sorawee
2020-5-19 03:56:56

But wait, Haskell’s cons operator is :, isn’t it? :: is for type annotation. Idris on the other hand uses : for type annotation and :: for cons


alexknauth
2020-5-19 04:00:32

Hackett’s :: is cons


jcoo092
2020-5-19 04:00:43

It might be : in Haskell yeah. Some languages use one colon and some two, and I can never keep them straight in my head.