Hello Neil,

Thanks for your help.
On 20/01/2019 13:54, Neil Van Dyke wrote:
> Hello, Alain.  You might wish to write out htdp.org design recipes for
> EnumVarDim and Enum. 

Yes it seems that this is an useful reference for learning. Thanks for
pointing it.

 I don't know what they're supposed to do, but is
> the below code closer to what you want?
> 
Unfortunately, I don't think so.
What I posted whas  a stripped down version of what my function is
supposed to do. The most important point is that this function is
supposed to be called recursively so PairValue should be defined in the
body of the function and not elswhere (if I have correctly understood
your post).
I post below a  complete version

(define-struct pair (fst snd)#:transparent)
(define (fst p)(pair-fst p))
(define (snd p)(pair-snd p))

(define (discriminant n)(+ 1 (* 8 n)))
(define (soluce_equation n)(/  (- (sqrt (discriminant n) )1) 2))

;; Enum : N --> N x N
;;        n --> le couple (x,y) dont le numéro de Cantor est n
(define (Enum n)
  (define w (floor(soluce_equation n)))
  (define t (/ (* w (+ w 1)) 2))
  (define x (- n t))
  (define y ( - w x))
  (pair x y)
)

;; Inverse Cantor paring function  in variable  dimension
;; The goal is to obtain the n-uplet whose Cantor pairing function
;; in dimension n gives value
;; This function should be called with result as an empty list
(define (EnumVarDim n value result)
  (if ( >= n 2)
  ( (define pairValue Enum(result))
     ;; Enum(n) is the inverse of the Cantor pairing function
    (append result (fst pairValue))
    (EnumVarDim sub1 dim (snd pairValue) result))
  (result)))


> 
> #lang racket/base
> 
> (define (Enum x)
>   (fprintf (current-error-port) "TODO: implement Enum\n")
>   x)
> 
> (define (EnumVarDim dim value)
>   (if (>= dim 2)
>       (Enum value)
>       value))
> 
> (define pairValue (EnumVarDim 111 222))
> 
> (printf "pairValue = ~S\n" pairValue)
> 
> 
> In this code, the value of pairValue isn't being set inside EnumVarDim. 
> Instead, the value of pairValue is set outside of EnumVarDim, to the
> value of applying EnumVarDim.
> 
> (BTW, if you wish to try Racket naming conventions, you could use names
> like enum-var-dim and pair-value.)
OK, I'll try that as soon as I get it to work.

Best regards,

Alain
> 


-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to