### Thread: Application: not a procedure; Dr. Racket(

1. No Profile Picture
Registered User
Devshed Newbie (0 - 499 posts)

Join Date
Nov 2012
Posts
2
Rep Power
0

#### Application: not a procedure; Dr. Racket(

Hi there! I started studying Dr.racket and I need to produce a list that have first part from a list and the second part from the vector. For example, if I run my program (d '(a b c) '#( 1 2 3))
It should return ((a . 1) (b . 2) ( c . 3)) ;;;. is for pair. So, here is my code:
Code:
```(define d
( lambda(list vector)
(define num 0)
( d cdr list (vector-ref(vector)num+1))
( cons car list vector)))```
However, I am getting
application: not a procedure;
expected a procedure that can be applied to arguments
given: #(1 2 3)
arguments...: [none]
it complains about (vector-ref(vector)num+1) but I don't understand why... Any help?
Thanks.
2. It's because you have extra parentheses around the name vector, which causes the interpreter to treat it as a function of no arguments. That line should read
Code:
`     ( d cdr list (vector-ref vector (+ 1 num)))`
Mind you, this still isn't correct. First off, the names list and vector conflict with existing function names; try lst and vec instead, or something similar. Second, you need to test whether the list is null, and whether the vector is length zero, before you do any of this, otherwise you'll end up with an infinite recursion. Third, you don't need the num local variable, and even if you did, the correct way to declare a local is with let, not define. Finally, you want to rearrange the recursive call to d so that it comes after where you cons the two first elements together.

I would also recommend looking up the vector-length and vector-drop functions in the Racket documentation, as you'll need them both.
Last edited by Schol-R-LEA; November 7th, 2012 at 11:04 AM.
3. No Profile Picture
Registered User
Devshed Newbie (0 - 499 posts)

Join Date
Nov 2012
Posts
2
Rep Power
0
Originally Posted by Schol-R-LEA
It's because you have extra parentheses around the name vector, which causes the interpreter to treat it as a function of no arguments. That line should read
Code:
`     ( d cdr list (vector-ref vector (+ 1 num)))`
Mind you, this still isn't correct. First off, the names list and vector conflict with existing function names; try lst and vec instead, or something similar. Second, you need to test whether the list is null, and whether the vector is length zero, before you do any of this, otherwise you'll end up with an infinite recursion. Third, you don't need the num local variable, and even if you did, the correct way to declare a local is with let, not define. Finally, you want to rearrange the recursive call to d so that it comes after where you cons the two first elements together.

I would also recommend looking up the vector-length and vector-drop functions in the Racket documentation, as you'll need them both.
thanks