netraken wrote on 1/20/19 8:31 AM:
(define (EnumVarDim n value result) (if ( >= n 2) ( (define pairValue Enum(result))
That first Racket parentheses in `( (define` is not like grouping parentheses or braces in some other languages. Each Racket parentheses is significant. When you want to make a sequence of expressions, one option is to use `begin`.
In this case, however, internal `define` is weird, so, instead of `(begin (define`, you might want `(let`. See the documentation for `let`.
;; Enum(n) is the inverse of the Cantor pairing function (append result (fst pairValue)) (EnumVarDim sub1 dim (snd pairValue) result))
The way that lists work in Racket, the `append` is pure-functional, returning a new list, rather than modifiying the lists. It also doesn't change the value of a variable. So you probably want that entire `(append ...)` expression to instead be an argument to your application of `EnumVarDim` in the expression currently after it.
BTW, `append` only appends lists together, so, if you want to get a list that is a copy of a given list but with a single other element added onto the end of it, a way to do it with `append ` is to first make a list of that new element.
(Advanced alternative to `append` sometimes: Getting a list that is like a given list, but with a single other element *prepended* to it, is much more efficient than appending, and can by done like `(cons my-new-element my-original-list)`. We very often use `cons` this way, especially in recursive procedures that construct lists. Even if we do a `reverse` at the end, because we eventually need the list in the reverse order.)
The application of `EnumVarDim` there has an extra argument.
(result)))
The syntax `(result)` expects the value of the result `result` variable to be a procedure, which is then applied. You might want simply `result`.
BTW, you might try to use a different name than `pair`, since the term "pair" already has central meaning in Racket.
You have a very good start here. As you're learning Racket, after you write some code, it helps to go back and reread the discussions of syntax and semantics, and the mechanics of pairs and lists, now that you have more context for anchoring your understanding. You'll also discover other helpful language features that way, which you didn't appreciate on the first read. Also, any time you're using a procedure or special form that you don't already know intimately, it helps to double-check the documentation (which I do very frequently myself, as good practice for avoiding bugs, and which I suspect is much less costly than even most short-lived bugs; I just wouldn't ask for the documentation during one of those awful dotcom interview whiteboard coding hazing rituals :).
-- 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.