mark.warren
2020-1-30 14:43:51

When creating new data structures in Racket, are they usually built using cons cells or is there just a variety of ways using existing built in data structures.?


soegaard2
2020-1-30 14:44:20

Structures!


soegaard2
2020-1-30 14:46:22

Complicated data structures can contain values of different kinds, but cons-cells (list) are for single-linked lists primarily.


soegaard2
2020-1-30 14:46:59

If you read SICP you will see, that they use cons-cell lists to build other kinds of data structures - but Scheme at the time did not have structurs (aka records).


soegaard2
2020-1-30 14:47:08

So they were forced to use lists.



mark.warren
2020-1-30 14:50:26

@soegaard2 Thanks, I’ve read some of SICP, but still plodding through.


rokitna
2020-1-30 22:04:14

I consider match to be indispensable in combination with structures, so I can construct and deconstruct values using concise positional arguments. I think the Rebellion library offers a way to define records that use keyword arguments instead.



notjack
2020-1-30 22:12:29

They can be pattern matched on as well.


krismicinski
2020-1-31 00:50:06

I wonder if there’s a stylistic preference for values vs. just a list and a pattern match. It feels weird to have this values thing that somehow feels like data I can’t really easily destruct on.


krismicinski
2020-1-31 00:50:18

so I always tend towards using lists.


notjack
2020-1-31 00:55:44

I recommend avoiding values unless you’re micro-optimizing


notjack
2020-1-31 00:57:03

lists and pattern matching works in a pinch, but making a transparent struct is much better


krismicinski
2020-1-31 00:57:29

so sincere question, if I’m only going to use it at (say) one callsite, why the need to codify explicitly as a struct?


krismicinski
2020-1-31 00:57:41

or like 1–2 callsites


krismicinski
2020-1-31 00:57:51

i realize 1 doesn’t make any sense


notjack
2020-1-31 00:58:36

Arity checking and field names


krismicinski
2020-1-31 00:58:54

ah hm, yeah, I see your point.


notjack
2020-1-31 01:00:49

also if it’s more than a small number of fields (like, say, three or more maybe), it’s really helpful to have a keyword constructor for the struct type so you don’t have to remember their order.


notjack
2020-1-31 01:04:19

Rebellion has tuple types which are ordered (like regular structs), and record types which aren’t (like structs but with keyword arguments). I usually default to record types and use tuple types when there’s an “obvious” order, like the x and y coordinates of a point.


soegaard2
2020-1-31 01:14:43

@krismicinski It’s an interesting question. People wildly disagree. One point of view: “If lists aren’t part of the problem, then they shouldn’t be part of the solution.” Example: Integer division results in both a quotient and a remainder. Some like the symmetry of passing and returning multiple values. Others dislike that the semantics of function returns become more complicated.


soegaard2
2020-1-31 01:16:45

Here is a link to an extensive discussion on multiple values: https://groups.google.com/d/msg/comp.lang.scheme/ruhDvI9utVc/786ztruIUNYJ