I am reading the Realm of Racket book, and page 175, I see in effect this code:
(struct dice-world (src board gt))
(struct game (board player moves))
(define (no-more-moves-in-world? w)
(define tree (dice-world-gt w))
(define board (dice-world-board w))
(define player (game-player tree))
player)
The function from the book doesn't return the player, but everything until that line is as in the book. To me, this screams of the need of pattern matching!
And indeed, this works fine and is considerably more readable and explicit to me:
(define (no-more-moves+? w)
(match w
[(dice-world _ board (game _ player _)) player]))
However here we still name the variable w
for no reason at all. I'd like to be able to pattern match directly on the function parameters, like this (invalid syntax):
(define (no-more-moves2? (dice-world _ board (game _ player _)))
player)
From my googling so far, this appears impossible? That sounds unbelievable to me? It's probably possible through some macro trickery I guess, but I'm really surprised that it would not be the standard way to write that code from the book? Being a beginner's book, I thought maybe pattern matching will be introduced later, but I don't find it in the index at all?
Also, in case the answer is that it's not possible/not idiomatic, I wonder whether it's the same with other lisps too?