Is there any solution to use an identifier before its definition, as in #lang racket
(square 5)
(define (square x) (* x x))
Other than to just rewrite all my code so definitions come first?
also follow up question, when I do mutually recursive defines like #lang racket
(define (isodd x)
(if (zero? x) #f (not (iseven x))))
(define (iseven x)
(if (zero? x) #t (not (isodd x))))
it works, even though I’m using iseven
before it is being define
d. Why is this allowed but the previous example not allowed?
Isn’t there a (declare …)
form? Though it may not be needed for mutually-recursive functions because the function bodies are not evaluated?
@ben.knoble what do I have to require
to use (declare ...)
? #lang racket
is not sufficient forback.rkt:3:1: declare: unbound identifier
in: declare
Huh, maybe my brain made that up :slightly_smiling_face: sorry
Yes, but not if it’s going to be evaluated (to produce a value) before its definition. For example this works: #lang racket
(define (foo)
(square 2))
(define (square x)
(* x x))
(foo)
But this doesn’t work: #lang racket
(define (foo)
(square 2))
(foo)
(define (square x)
(* x x))
ah well :white_frowning_face:, the second part of your answer makes sense though thanks for that!