# Racket:cant return input

**URL:** <https://racket.discourse.group/t/racket-cant-return-input/638>\
**Category:** Questions & Answers\
**Tags:** question, drracket\
**Created:** [January 31, 2022, 11:11am UTC](https://racket.discourse.group/t/racket-cant-return-input/638 "2022-01-31T11:11:44Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![osman44](https://avatars.discourse-cdn.com/v4/letter/o/85f322/32.png) [@osman44](https://racket.discourse.group/u/osman44)\
**Post date:** [January 31, 2022, 11:11am UTC](https://racket.discourse.group/t/racket-cant-return-input/638/1 "2022-01-31T11:11:44Z")

</div>

i have been asked to "Write a function with one argument, L, such that, if L is a number, then it is  
doubled and returned, otherwise it is returned unchanged" The problem iwhenever i run the function and say type in something other than a number it does not return the input exepct return an error i want the function to return the input.it does return the double of the number but i also want it to retun whatever i put as the input.here is my code

(define L (λ (b)

```
        (cond
          (number? b (* 2 b))
```

---

<div class="post-metadata">

**Author:** ![dominik.pantucek](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/dominik.pantucek/32/144_2.png) [@dominik.pantucek](https://racket.discourse.group/u/dominik.pantucek)\
**Post date:** [January 31, 2022, 12:02pm UTC](https://racket.discourse.group/t/racket-cant-return-input/638/2 "2022-01-31T12:02:36Z")

</div>

This looks like a school assignment, but anyway...

Apart from missing parentheses at the end, there are probably some missing in the (missing) application of the `number?` predicate. Look at cond[1] documentation - the mistake should be obvious. Also remember that if no cond-clause matches and produces a result, the result is void - an else clause is what you are probably looking for. But right now that is not the error you see in your code. Also the error that's produced is fairly self-explanatory:

```scheme
> (L "a")
; *: contract violation
; expected: number?
; given: "a"
; [,bt for context]

```

Anything you pass to your procedure gets passed on as second argument of `*` procedure.  
Is there any reason you are using `cond` and not `if` for this one?

[1] [3.12&nbsp;Conditionals: if, cond, and, and or](https://docs.racket-lang.org/reference/if.html#(form._((lib._racket%2Fprivate%2Fletstx-scheme..rkt)._cond)))

---

<div class="post-metadata">

**Author:** ![soegaard](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/soegaard/32/19_2.png) [@soegaard](https://racket.discourse.group/u/soegaard)\
**Post date:** [January 31, 2022, 12:23pm UTC](https://racket.discourse.group/t/racket-cant-return-input/638/3 "2022-01-31T12:23:24Z")

</div>

@osman44 Check the chapter 4.1 Programming with Conditionals.  
[I&nbsp;Fixed-Size Data](https://htdp.org/2021-11-15/Book/part_one.html#%28part._sec~3acond%29)

---

<div class="post-metadata">

**Author:** ![osman44](https://avatars.discourse-cdn.com/v4/letter/o/85f322/32.png) [@osman44](https://racket.discourse.group/u/osman44)\
**Post date:** [January 31, 2022, 12:35pm UTC](https://racket.discourse.group/t/racket-cant-return-input/638/4 "2022-01-31T12:35:08Z")

</div>

im still confused the number? checks to see if the input is a number however i want to ignore it if its not and return the input such as S can you give a little more help

---

<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:** [January 31, 2022, 1:02pm UTC](https://racket.discourse.group/t/racket-cant-return-input/638/5 "2022-01-31T13:02:32Z")

</div>

S’s reference was to [htdp.org](http://htdp.org) Please take a look now.

---

<div class="post-metadata">

**Author:** ![soegaard](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/soegaard/32/19_2.png) [@soegaard](https://racket.discourse.group/u/soegaard)\
**Post date:** [January 31, 2022, 1:18pm UTC](https://racket.discourse.group/t/racket-cant-return-input/638/6 "2022-01-31T13:18:38Z")

</div>

Watch John's video:

[![](https://global.discourse-cdn.com/free1/uploads/racket/original/2X/b/b816f03cee5aa5ed74e8418e29283fdc92e2281c.jpeg "DrRacket 11 -- cond") ](https://www.youtube.com/watch?v=-Wi7OC4uWoY)

---

<div class="post-metadata">

**Author:** ![alexh](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/alexh/32/315_2.png) [@alexh](https://racket.discourse.group/u/alexh)\
**Post date:** [January 31, 2022, 10:58pm UTC](https://racket.discourse.group/t/racket-cant-return-input/638/7 "2022-01-31T22:58:34Z")

</div>

Hi @osman44 , allow me to offer an additional suggestion: change DrRacket to use the "Beginning Student Language" and run your program again -- if you do this, DrRacket will tell you exactly what the problem is.

Alex.

---

<div class="post-metadata">

**Author:** ![jbclements](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/jbclements/32/11_2.png) [@jbclements](https://racket.discourse.group/u/jbclements)\
**Post date:** [February 1, 2022, 12:10am UTC](https://racket.discourse.group/t/racket-cant-return-input/638/8 "2022-02-01T00:10:29Z")

</div>

AMEN. Also: follow the design recipe. Here's a data definition to get you started

```scheme
A maybe-number is either
- a number, or 
- something else

```
