On Sat, 17 Apr 2021 05:02:00 -0700 (PDT)
Dan Synek <[email protected]> wrote:
> I am trying to implement a variation of define. In order to do that I am
> trying to understand the source of the define macro in racket.
> It calls a function normalize-definition which looks like this:
> (define-values (normalize-definition)
> (case-lambda
> [(stx lambda-stx check-context? allow-key+opt?)
> (let-values ([(id mk-rhs body)
> (normalize-definition/mk-rhs stx lambda-stx
> check-context? allow-key+opt? #t)])
> (values id (mk-rhs body)))]
> [(stx lambda-stx check-context?) (normalize-definition stx lambda-stx
> check-context? #f)]
> [(stx lambda-stx) (normalize-definition stx lambda-stx #t #f)])))
>
> In the two last cases of the case-lambda there is a call to
> normalize-definition. It is not a recursive call, since define-values
> cannot be used recursively. I cannot find any other normalize-definition in
> the modules required by the norm-define module.
> If I try to enter a copy of the definition (renamed to
> normalize-definition1) I get (as expected) that normalize-definition1 is
> undefined.
> What is going on?
Beginner here. I don't see the problem you seem to be referring to
here. In this example below, I recursively define arglen using
define-values.
#lang racket/base
(define-values (arglen)
(case-lambda
[() 'no-list]
[(ls) (if (null? ls)
0
(+ 1 (arglen (cdr ls))))]))
case-lambda-recursion.rkt> (arglen)
'no-list
case-lambda-recursion.rkt> (arglen (list))
0
case-lambda-recursion.rkt> (arglen (list 1))
1
case-lambda-recursion.rkt> (arglen (list 1 1))
2
case-lambda-recursion.rkt> (arglen (list 1 1 1))
3
case-lambda-recursion.rkt>
--
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 [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/racket-users/20210417093414.00007527%40protonmail.com.