How do you represent elements of a vector which are functions/procedures in racket?
I would think it would be something like:
#(+ -)
But when I retrieve the elements I get the symbols '+ and '-.
The reason is that #(
is a special syntax for reading array literals, not an operator that evaluates the content between parentheses. From the manual:
When the reader encounters a
#(
,#[
, or#{
, it starts parsing a vector; see Vectors for information on vectors. ... In read-syntax mode, each recursive read for vector elements is also in read-syntax mode, so that the wrapped vector’s elements are also wrapped as syntax objects, and the vector is immutable.Examples:
#(1 apple 3)
reads equal to(vector 1 'apple 3)
So, you should use the explicit vector
operator:
(define a (vector + -))
((vector-ref a 0) 2 3) ; => 5
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With