slack1
2017-11-14 16:32:33

Does anyone know why Racket differentiates Lists from Pairs?


slack1
2017-11-14 16:32:38

They appear to be so similar


royall
2017-11-14 16:46:43

Just a guess, but usually the cdr of a list is also a list, not an atom


royall
2017-11-14 16:47:24

so if you passed a pair to a contract that specified list, there could still be a runtime error if it does something with the tail of it


rick.moynihan
2017-11-14 21:41:26

@rick.moynihan has joined the channel


abmclin
2017-11-15 03:07:53

Lists are built out of pairs, and if the pair notation was the only thing we had available then a list would be written as ( a . ( b . ( c . ( d . ())))). It’s rather cumbersome to write a list like that so it’s just easier to employ a list notation (a b c d) and be done with it.


abmclin
2017-11-15 03:15:29

And why the need for () as the very last thing in the list written out in the pair notation? If you consider a list of just one element, (d). How would you want to write that in pair notation? You might try write it as (d . ) but that doesn’t work, a pair always has two elements, the car and cdr of a pair always return valid elements. So we just define the concept of an empty list, identify it as (), which is a valid value in Racket. Now we can write (d) as (d . ()). Thus the cdr of (d) will always be ().