Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There are two things you should think about here. The first is the one you mentioned-- that you could have either <code>a</code> or <code>(1 a)</code>, both meaning the same thing. You probably want to move that into <code>expandHelper</code>, so it looks more like <code>(expandHelper value)</code>, and then you should switch on whether it's a list or a symbol.</p> <p>The second is in how you're calling <code>expandHelper</code>. If you feed in a list like <code>'(a (3 b) (3 a) b (2 c) (3 a))</code> to <code>expand</code>, it'll currently call <code>(expandHelper a (3 b))</code>, which is probably not what you had in mind. Instead, you want to make sure you call <code>expandHelper</code> on every element of the list, and <code>cons</code> together the results. You can do that by calling <code>expandHelper</code> on the first element of the list, and then recursively calling <code>expand</code> on the remainder of the list.</p> <p>I haven't checked to see that this compiles, it's just the general idea:</p> <pre><code>(define (expandHelper value) (if (list? value) ;; means value is something like (2 a) (if (= 0 (car value)) ;; then (car value) is 2 '() ;; if it's zero, we complete the list and return! (cons (cadr value) ;;otherwise, we append (cadr value) = a to... (expandHelper (cons (- (car value) 1) (cadr value)))))) ;; the result of expand helper on (- (car value) 1) = 1 ;; and (cadr value) = a (cons value '()))) ;; if it's not a list, we should just return the value. </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload