On 2019-11-08 7:12 pm, Freeman Gilmore wrote:
\version "2.19.83"
#((define h (make-hash-table 114))
(display h)
(hashq-set! h 3 "val3")
(display (hashq-ref h 3)))

Wrong type to apply: #<unspecified>

Could someone explain why I get this error?

"(define h (make-hash-table 114))" returns (or evaluates to) #<unspecified> which is not a procedure. (#<unspecified> is a special value in Scheme, which you can test for with the "unspecified?" predicate.)

It helps to remember that "(proc 1 2 3)" is shorthand for "(apply proc '(1 2 3))". Your original expression, therefore, is functionally equivalent to this:

;;;;
(apply (define h (make-hash-table 114))
  (list (display h)
        (hashq-set! h 3 "val3")
        (display (hashq-ref h 3))))
;;;;

The solution is to use "begin":

%%%%
\version "2.19.83"
#(begin
  (define h (make-hash-table 114))
  (display h)
  (hashq-set! h 3 "val3")
  (display (hashq-ref h 3)))
%%%%


-- Aaron Hill

Reply via email to