On Thu, Aug 23, 2018 at 1:02 PM Ben Kovitz <bkov...@gmail.com> wrote:

>
>   In Clojure, the data structures of first resort are map and vector.
>   What's the equivalent in Racket--the short list of bread-and-butter data
>   structures that you reach for first when writing production code? How do
>   you, say, accumulate a sequence of items, like conj'ing to a vector in
>   Clojure? Do you usually do nested data structures in Racket, or do you
>   normally keep them flat, as in Python?
>

For me, the first resorts in Racket are list and hash.  If I'm going to do
any heavy lifting with it then I move to struct:

(hash 'username 'bob 'age 18)  ; quick and easy, works well with database,
useful print representation.  Weak against typos, not easy to identify what
a hash represents

(struct user (username age) #:transparent) ; transparent means "show field
values when printing"
(user 'bob 18) ; well-defined accessors and setters so not vulnerable to
typos, has an inbuilt predicate to identify 'user' structs.

  How do you print stuff in the REPL so you can see what's in it? For
> example,
>   if I print a graph in DrRacket, all I see is this: #<unweighted-graph>
>

For structs you put the #:transparent keyword on it when you define the
struct.  I haven't worked with graphs.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to