Functions as vector elements in a racket

How do you represent vector elements that are functions / procedures in a racket?

I would think it would be something like:

#(+ -)

But when I retrieve the elements, I get the characters '+ and' -.

+4
source share
1 answer

The reason is because it #(is a special syntax for reading array literals, and not an operator that evaluates the contents between parentheses. From the manual:

#(, #[ #{, vector; . Vectors .... - read-syntax, , .

: #(1 apple 3) (vector 1 'apple 3)

, vector:

(define a (vector + -))

((vector-ref a 0) 2 3)  ; => 5
+6

Source: https://habr.com/ru/post/1624908/


All Articles