#lang racket
;; Use '() instead of the 'empty' alias
(define board #("X" "0" empty empty))
(for/vector ([val board]
#:when (empty? val))
val) ; this returns '#()
I would expect it to return '#(empty empty)
#lang racket
;; Use '() instead of the 'empty' alias
(define board #("X" "0" empty empty))
(for/vector ([val board]
#:when (empty? val))
val) ; this returns '#()
I would expect it to return '#(empty empty)
(for/vector ([val board]
#:when (eq? val 'empty))
val)
this works, why? I am a bit confused
this works:
(define board (vector "X" "0" empty empty))
(for/vector ((val board) #:when (empty? val)) val)
'#(() ())
Literal vectors are self-quoting, so you have a vector with two strings, and two symbols (Both 'empty
). If you want to use empty
so it gets treated as a variable and its contents used, you have to use vector
:
(define board (vector "X" "O" empty empty))
;;; this works too:
;;; (define board #("X" "0" () ()))
;;; or quasiquote shenanigans
;;; (define board `#("X" "0" ,empty ,empty))