PasteRack.org
Paste # 22038
2017-02-17 15:46:15

Fork as a new paste.

Paste viewed 659 times.


Embed:

racket/dict example

  1. #lang racket/base
  2. (require racket/dict)
  3. ;; An association list is a `dict?`,
  4. ;;  so you can pass an association list to functions like `dict-ref`
  5. ;; http://docs.racket-lang.org/reference/dicts.html
  6.  
  7. (for/fold ([acc '()])
  8.           ([key (in-list '(1 2 3))])
  9.   (dict-set acc key key))
  10.  
  11. ;; Preserves order for me, but IDK if that's always true

=>

'((1 . 1) (2 . 2) (3 . 3))