# Is it possible to use Template Variables in constants definitions?

**URL:** <https://racket.discourse.group/t/is-it-possible-to-use-template-variables-in-constants-definitions/885>\
**Category:** Questions & Answers\
**Created:** [April 15, 2022, 11:14am UTC](https://racket.discourse.group/t/is-it-possible-to-use-template-variables-in-constants-definitions/885 "2022-04-15T11:14:45Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jgomo3](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/jgomo3/32/496_2.png) [@jgomo3](https://racket.discourse.group/u/jgomo3)\
**Post date:** [April 15, 2022, 11:14am UTC](https://racket.discourse.group/t/is-it-possible-to-use-template-variables-in-constants-definitions/885/1 "2022-04-15T11:14:45Z")

</div>

**Language** : BSL  
**Doc** : [Template variables](https://docs.racket-lang.org/htdp-langs/beginner.html#%28part._beginner._.Template._.Variables%29)

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:

```scheme
...: expected a finished expression, but found a template

```

1. Why?
2. Is there anyway to express something like that within constants definitions?

---

<div class="post-metadata">

**Author:** ![EmEf](https://avatars.discourse-cdn.com/v4/letter/e/53a042/32.png) [@EmEf](https://racket.discourse.group/u/EmEf)\
**Post date:** [April 15, 2022, 1:25pm UTC](https://racket.discourse.group/t/is-it-possible-to-use-template-variables-in-constants-definitions/885/2 "2022-04-15T13:25:03Z")

</div>

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,

```scheme
(define (f x) 

```

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

Similarly,

```scheme
(define f (lambda (x)

```

could be completed to a function definition.

But,

```scheme
(define x …)

```

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

---

<div class="post-metadata">

**Author:** ![jgomo3](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/jgomo3/32/496_2.png) [@jgomo3](https://racket.discourse.group/u/jgomo3)\
**Post date:** [April 15, 2022, 1:36pm UTC](https://racket.discourse.group/t/is-it-possible-to-use-template-variables-in-constants-definitions/885/3 "2022-04-15T13:36:15Z")

</div>

Thank you!

Than maybe this text:

> [@EmEf](#):
>
> a _template_ is an outline of a function

Would be more appropriate than:

```scheme
A placeholder for indicating that a definition is a template.

```

in [the Help Desk documentation](https://docs.racket-lang.org/htdp-langs/beginner.html#%28part._beginner._.Template._.Variables%29),

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

---

<div class="post-metadata">

**Author:** ![EmEf](https://avatars.discourse-cdn.com/v4/letter/e/53a042/32.png) [@EmEf](https://racket.discourse.group/u/EmEf)\
**Post date:** [April 15, 2022, 2:04pm UTC](https://racket.discourse.group/t/is-it-possible-to-use-template-variables-in-constants-definitions/885/4 "2022-04-15T14:04:12Z")

</div>

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