notjack
2020-12-20 10:14:18

yup this is wack and makes stuff weird


notjack
2020-12-20 10:14:38

notjack
2020-12-20 10:16:57

but really, just, don’t use cons pairs to represent arbitrary pairs of things


notjack
2020-12-20 10:17:02

just let lists be lists and if you have a pair of two things, make a struct for them


notjack
2020-12-20 10:18:38

if only so you get useful names for the fields


laurent.orseau
2020-12-20 10:18:45

assocs are very useful dictionaries though, memory and time efficient for few entries, and very easy to manipulate


notjack
2020-12-20 10:20:17

I’d much rather have something that prevents duplicate keys


laurent.orseau
2020-12-20 10:24:10

I don’t disagree though it’s not a bug I’ve had often, nor that I can recall lost me a lot of time


notjack
2020-12-20 10:26:11

and there’s certainly a lot more functions for transforming lists than there are for transforming hash tables


notjack
2020-12-20 10:27:01

(the fact that hash-filter returns a list is incredibly evil)


laurent.orseau
2020-12-20 10:28:59

It’s also quite nice to be able to sort the dictionary, in particular for printing


laurent.orseau
2020-12-20 10:29:33

( this can even be used for better performance than with hashes in some cases)


notjack
2020-12-20 10:30:14

yeah sorted maps are an important use case


notjack
2020-12-20 10:30:37

ideally I’d just have a good API for that specifically


laurent.orseau
2020-12-20 10:31:42

As long as it’s as efficient :p


laurent.orseau
2020-12-20 10:34:21

I think there’s a package that does that


laurent.orseau
2020-12-20 10:34:34

Or something in data/


sorawee
2020-12-20 10:35:15

The usual toy interpreter in intro to prog lang usually implements an environment with an assoc list, with duplicate keys


sorawee
2020-12-20 10:35:43

It’s really easy to implement it. Adding a value is just consing to the front. No need to check for duplication.


notjack
2020-12-20 10:36:27

to deal with the problems discussed in the original post, could we just do that with entry structs instead of cons cells for the mappings http://docs.racket-lang.org/rebellion/Entries.html\|docs.racket-lang.org/rebellion/Entries.html


notjack
2020-12-20 10:36:47

(list (entry 'a 1) (entry 'b 2)) instead of (list (cons 'a 1) (cons 'b 2))


laurent.orseau
2020-12-20 10:41:01

Of course, if what you want is a singly linked list of tuples


laurent.orseau
2020-12-20 10:41:24

Usually i just have a list a struct objects


laurent.orseau
2020-12-20 10:43:28

And I often even use #:prefab so I can easily write/read


laurent.orseau
2020-12-20 10:51:37

A classic use case I often have currently is to read log files that contain many entries in text form. I parse them with match and regexps, generate a list of #s(info ...) (although entry is a good name), then a #s(summary ...) with some stats about the infos, and cache everything to a file for faster loading next time.


laurent.orseau
2020-12-20 10:52:29

(I should probably write a small lib at some point… there’s already with-input-from-file/cache in bazaar/file though, but bazaar is unstable)


kellysmith12.21
2020-12-21 00:38:33

In my lang, there is no cons, and lists are always proper (specifically, I just provide rebellion/collection/list). I also use different syntax for rest arguments, so dot syntax is unnecessary. For example, instead of (λ (a . rest) <body>), there is {λ a rest ... ⇒ <body>}, borrowing the ellipses syntax from syntax templates.