0

To implement depth-first search in a grid, I wrote a function like this

(define (expand dim node visited obs)
  (not-in (neighbor dim obs node) visited))

The function dfs is

(dfs dim obs visited fringe path goal)

The only appearance of expand in dfs is

(expand dim (car fringe) visited obs)

And I called dfs using

(dfs '(5 5) '((2 2) (3 2)) '((2 1)) '((1 1) (3 1)) '((2 1)) '(4 5))

dim is the dimension of the grid, obs is a list of the blocked positions in the grid.

When I call expand by hand it works perfectly. But when it's called in dfs, it says "expand: expects 1 argument, given 4: '(5 5) '(1 1) '((2 1)) '((2 2) (3 2) (3 4) (4 4) (5 4))"

However, if I change the position of arguments of expand, e.g. put obs as the second argument,

(define (expand dim obs node visited)
  (not-in (neighbor dim obs node) visited))

and modify dfs and my callings correspondingly, then the error won't appear and everything works well. Then next time I launch DrRacket and paste the modified code into it, the same error reappears. If I swap obs back, it works well again... What on earth is happening here?! Thanks!

2
  • 1
    Please write the code for the other procedures so we can understand your problem better.
    – Eran Egozi
    Feb 18, 2012 at 22:16
  • It would also be helpful to know: are you putting all your definitions into a single file, or have you put them in separate modules? Are you in #lang racket, or in one of the teaching languages? The problem you're describing sounds as though Racket thinks it should be using the expand function from its standard library, rather than the one that you've defined. We need more context to diagnose what is actually happening.
    – dyoo
    Feb 18, 2012 at 23:40

2 Answers 2

1

expand is an awfully generic name that might have a definition somewhere else. Rename your funciton to dfs-expand and see if this fixes it.

4
  • This would most likely fix it, but it avoids resolving the problem that causes it. Feb 19, 2012 at 3:13
  • Unless the problem that causes it is that he has two functions named expand! ;-) Feb 19, 2012 at 16:40
  • Unlikely. See my pointer: s/he had the same problem with a different builtin, and still didn't explain precisely what s/he's doing. Feb 19, 2012 at 17:02
  • I still have no idea what the problem and solution to this is. The original author accepted an answer, but after reading the entry, I still have no idea what just happened. If the OP can please explain what just happened, that will be really helpful to others on Stack Overflow who encounter similar situations.
    – dyoo
    Feb 20, 2012 at 4:01
1

It looks like this is the same problem you're having in this question. As is the case there, expand is a function that is already defined in Racket, but writing your own definition should still work fine. So like I said there, you should describe exactly what you're doing to know why you have these problems in the first place.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.