jestarray
2020-10-2 17:36:08

so i have a vector of structs and i want to check if a name exists and return that index: (struct Person name age) (define v (vector (Person "bob" 44) ("alice" 33) ("steven" 22)) (??? (lambda (x) (string=? (person-name x) "alice") v)) ; should return the index location of alice, which is 1 basically is there a built in vector-memqthat takes a function instead of the value to search?


jestarray
2020-10-2 17:40:32

a memf for vector


samth
2020-10-2 17:41:05

I don’t think vector-memf exists.


jestarray
2020-10-2 17:41:41

actually memf doesn’t seem to return the index but the item itself :s



jestarray
2020-10-2 17:48:52

thanks! a little off putting that i have to vector->list


jaz
2020-10-2 17:49:32

you don’t


samth
2020-10-2 17:49:38

that function will work on vectors


jestarray
2020-10-2 17:49:46

:open_mouth:


jestarray
2020-10-2 17:51:04

(index-of (vector 1 2 3) 2 =), i get index-of: contract violation expected: list? given: ’#(1 2 3) argument position: 1st other arguments…:


jaz
2020-10-2 17:52:26

that’s a different index-of


jaz
2020-10-2 17:52:55

Sam pointed you toward the one in the collections package. The one you’re using is in racket/list.


samdphillips
2020-10-2 17:53:49

(for/first ([p (in-vector people)] [i (in-naturals)] #:when (equal? (Person-name p) "bob")) i)


jestarray
2020-10-2 17:54:28

ahhhh


soegaard2
2020-10-2 17:55:09

Just as I was typing this: (define (vector-index-of v p?) (for/first ([x (in-vector v)] [i (in-naturals)] #:when (p? x)) i)) (vector-index-of #(1 3 5 8 9) even?)


jestarray
2020-10-2 17:59:52

thanks guys!


jaz
2020-10-2 18:02:36

One thing: if you do decide to go with collections, it tends to be a kind of all-in decision. It gives you a nice api for working with sequences of any kind, but it also produces lazy sequences, so if you try to mix-and-match functions from collections and ones from the built-in library, you can run into problems. So that could be a reason to go with the approach that @samdphillips and @soegaard2 are proposing.


jestarray
2020-10-2 18:03:39

im surprised vector-index-of isn’t built in :s


jaz
2020-10-2 18:05:11

I’d guess that people would be receptive to a PR against racket/vector. (It should probably be called vector-memf for consistency with the list libs.)


soegaard2
2020-10-2 18:05:18

It’s in srfi/43:

(require srfi/43) (vector-index even? #(1 3 5 8 9))


jestarray
2020-10-2 18:07:16

someone PR it pls :heart:


jeapostrophe
2020-10-2 21:00:24

Would anyone like to help me test RacketCon streaming?


jeapostrophe
2020-10-2 21:12:52

Thanks Michael, seemed fine?


maburns
2020-10-2 21:17:38

Until the zoom feed froze/stopped, yes. Audio and video was fine for me.


jestarray
2020-10-2 23:04:08

so im writing s-expressions to a file and i don’t want the prefix of struct: with the name of the struct. I just want (atlas (frame)) #(#(struct:atlas (frame (w . 13) (x . 1146) (y . 34) (h . 8)) (source (w . 13) (x . 14) (y . 9) (h . 8)) (id . 532737) (duration . -1))) I’m reading the docs on how to customize display but how to customize the reader but im unsure how to use them


jestarray
2020-10-2 23:11:59

and the hash that comes before it, #(struct:atlas) . I think print is closer to what i want but i dont need the single quotes or (vector )


samdphillips
2020-10-2 23:41:12

Depending on your use-case you may just want to use #:prefab structs. They read and write without hassle.


kellysmith12.21
2020-10-3 00:42:21

Is there a reason why struct doesn’t allow each automatic field to have a different automatic value?


jestarray
2020-10-3 00:42:45

you mean default value?


samth
2020-10-3 01:09:30

@kellysmith12.21 default values are a basically useless feature that is only still around for compatibility


jestarray
2020-10-3 01:11:19

why are default values a useless feature :0?


jestarray
2020-10-3 01:27:33

ah, before i write it to a file i can just replace all the ' and keywords. My usecase is that im serializing the s-xpressions in rust using https://docs.rs/serde-lexpr/0.1.1/serde_lexpr/


jestarray
2020-10-3 01:46:57

a bit hacky but lol (define final (string-append "#" (string-replace (string-replace (get-output-string acc) "vector" "") "'" ""))) lengthy but it works


laurent.orseau
2020-10-3 06:47:53

Because they are limited and you should use a ‘smart’ constructor instead, where you can can specify default values but also handle domains and such and report more meaningful errors