Is it possible to use Template Variables in constants definitions?

Language: BSL
Doc: Template variables

A function definition, like (define (f x) ...) has no problem with template variables.

But a constant definition, like (define X ...) has problems with template variables, specifically, DrRacket says:

...: expected a finished expression, but found a template
  1. Why?
  2. Is there anyway to express something like that within constants definitions?
1 Like

By definition in HtDP (for which *SL exist), a template is an outline of a function (an “inventory of what we know about the function based on its purpose statement and the data def. for its input(s)”). Hence … is allowed to show up inside of a function definition but nowhere else.

Concretely,

(define (f x) 

are the first few keystrokes for entering a function definition. Check.

Similarly,

(define f (lambda (x)

could be completed to a function definition.

But,

(define x …)

is not the beginning of a function definition. In the spirit of “signal errors early” the *SL evaluators signal an error.

2 Likes

Thank you!

Than maybe this text:

Would be more appropriate than:

A placeholder for indicating that a definition is a template.

in the Help Desk documentation,

just because the first text uses the word function but the last one uses the word definition.

A reader is expected to know HtDP (somewhat) where this terminology is defined.
But adding “function” to these explanations makes them somewhat more self-contained
so I pushed a fix to the docs (commit 9379cf6bdb083e8a32889504e1531addc890724).

2 Likes