joshibharathiramana
2020-12-15 16:55:48

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?


joshibharathiramana
2020-12-15 16:57:33

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?


ben.knoble
2020-12-15 16:58:50

Isn’t there a (declare …) form? Though it may not be needed for mutually-recursive functions because the function bodies are not evaluated?


joshibharathiramana
2020-12-15 17:00:28

@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


ben.knoble
2020-12-15 17:00:47

Huh, maybe my brain made that up :slightly_smiling_face: sorry


laurent.orseau
2020-12-15 17:04:49

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))


joshibharathiramana
2020-12-15 17:05:01

ah well :white_frowning_face:, the second part of your answer makes sense though thanks for that!


ben.knoble
2020-12-15 17:13:26