title: Scheme How To Return Multiple Values?
body: <p>I notice that almost all scheme functions can only return one list as output.</p>
  
  <p>In the following, I would like to return multiple values of all the adjacent nodes of neighbors.</p>
  
  <pre><code> (define (neighbors l w)
     (if (and (= 1 l) (= 1 w))
       (list (and (l (+ 1 w))) (and (+ 1 l) w)))) ; how to output 2 or more values?
  </code></pre>
  
  <p>In this case I'm first testing if the node is at corner, if so, return 2 values of the coordinates where (l and w+1), (l+1 and w) basically if I'm at (1,1) return me (1,2) and (2,1)</p>
  
  <p>Same applies when the node has only 1 neighbor near the edge, in this case I will have 3 values. </p>
  
  <p>When no edge is nearby I will have 4 return values. </p>
  
  <p>I tried to use <code>cons, append, list, display, write</code> none of them seems working with additional values. I need this as a sub-function of <a href="https://stackoverflow.com/questions/1575891/question-on-scheme-with-best-first-search-algorithm">this question</a>.  How should I implement it so I could pass on the return value and use it recursively to return me all the adjacent nodes?</p>
  
  <p><strong>Edit</strong>: I found the answer: use the keyword "<code>values</code>" to return multiple values.  Example: </p>
  
  <pre><code>(define (store l w)
    (values (write l)
            (write w)
            (newline)
            (list (+ 1 w) l)
            (list w (+ 1 l))))
  </code></pre>