Post AXnhJTtYbuO2Saxij2 by louis@emacs.ch
 (DIR) More posts by louis@emacs.ch
 (DIR) Post #AXnhJTtYbuO2Saxij2 by louis@emacs.ch
       2023-07-17T23:28:14Z
       
       0 likes, 0 repeats
       
       TIL: Structures in #CommonLisp are implemented like vectors. Accessing elements is O(1) independent of the number of fields. They could also be used a tuples. I would prefer structures over ALISTs or PLISTs, even Hashes when the data model is consistent.Although many prefer CLOS classes over structures, I like their simplicity as a lightweight place for storing data.
       
 (DIR) Post #AXnjp8qkajb4MesFkG by rwxrwxrwx@mathstodon.xyz
       2023-07-17T23:56:18Z
       
       0 likes, 0 repeats
       
       @louis I only recently learnt that you can use defstruct to create structures that are stored as lists (and vectors as well):CL-USER> (defstruct (foo (:type list)) bar baz)FOOCL-USER> (make-foo :bar 1 :baz 2)(1 2)CL-USER> (foo-baz *)2
       
 (DIR) Post #AXpURnFEZjShneHv6G by wwolf@mastodon.online
       2023-07-18T20:13:28Z
       
       0 likes, 0 repeats
       
       @louis CLOS is much more convenient during development, i.e. while you'd want to change data structures often during interactive sessions.It's common to switch to structs later on, when the system gets stable and performance becomes the main goal.