badkins
2020-11-6 15:33:21

Hmm… from the link that @sorawee posted, “In the latter case, the function that first-class-or evaluates to is similar to or, but evaluates all its arguments.” first-class-or doesn’t seem very useful, but maybe there are other identifier macros I would have a use for.


sorawee
2020-11-6 15:36:09

(apply first-class-or xs) is the same as (ormap values xs).


sorawee
2020-11-6 15:36:19

I use the latter a lot.


badkins
2020-11-6 15:43:33

I use ormap and andmap a lot also, but if they didn’t exist, I expect I’d write them as a function instead of an identifier macro.


phanthero
2020-11-6 22:36:26

How would you implement a 2D lookup table in Racket? Say you have a-z as rows, and 1–26 on each column, and you wanted to store some data in each Table[letter][number]. What’s the best way to do this? Nested hash tables? That seems not so good though, with those nested (hash-ref (hash-ref ...) things will look pretty ugly


sorawee
2020-11-6 22:38:56

(hash-ref my-hash-table (cons 'a 1))


sorawee
2020-11-6 22:39:11

(hash-set! my-hash-table (cons 'a 1) 42)


badkins
2020-11-6 23:24:54

The solution @sorawee posted is probably what you want, but as a quick example of a two dimensional vector in Racket: #lang racket (define (construct-vec num-rows num-cols) (let ([ vec (make-vector num-rows) ]) (for ([i (in-range num-rows)]) (vector-set! vec i (make-vector num-cols))) vec)) (define (get-vec vec row col) (vector-ref (vector-ref vec row) col)) (define (set-vec! vec row col val) (vector-set! (vector-ref vec row) col val)) (define vec (construct-vec 26 26)) (set-vec! vec 7 8 "I live at row 7 col 8") (displayln (get-vec vec 7 8))


badkins
2020-11-6 23:26:01

In your example, you might need a function to convert a letter/symbol to an index e.g. (get-vec vec (index-of 'a) 8)