<div>This is what you posted initially (insert-everywhere/in-all-words 's (list (list 'm 'e) (list 'x))) . Try it out in your in function, I would like to know how it plays out.</div>
<div> </div>
<div><br><br>Emeka</div>
<div> </div>
<div> </div>
<div class="gmail_quote">On Mon, Apr 27, 2009 at 10:29 PM, S Brown <span dir="ltr"><<a href="mailto:ontheheap@gmail.com">ontheheap@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">What I ended up doing was creating a helper function to insert-<br>everywhere, which takes 3 arguments, the front of the word, the<br>
symbol, and the back of the word. insert-everywhere doesn't do<br>anything except make the initial call to the insert-everywhere-helper<br>function, which does the actual work of inserting the letter into the<br>word. So, what I ended up with is basically this:<br>
<div class="im"><br>;; insert-everywhere: symbol word -> list-of-words<br></div>;; creates a list of words from symbol s, and word w, where<br>;; s has been inserted into each position of w<br>(define (insert-everywhere s w) ... )<br>
<br>and also<br><br>;; insert-everywhere-helper: word symbol word -> list-of-words<br>;; creates a list of words where symbol is between word f and word b<br>(define (insert-everywhere-helper f s b) ... )<br><br>I don't know how correct this is, at least as far as what the book<br>
wants, but it does pass the following check-expect calls:<br><br> (check-expect (insert-everywhere 'x empty)<br> (list (list 'x)))<br><br> (check-expect (insert-everywhere 'x (list 'a 'b))<br> (list (list 'x 'a 'b)<br>
(list 'a 'x 'b)<br> (list 'a 'b 'x)))<br><br> (check-expect (insert-everywhere 'x (list 'a 't 'o 'm))<br> (list (list 'x 'a 't 'o 'm)<br>
(list 'a 'x 't 'o 'm)<br> (list 'a 't 'x 'o 'm)<br> (list 'a 't 'o 'x 'm)<br> (list 'a 't 'o 'm 'x)))<br>
<br> (check-expect (arrangements (list 'h 'o 't))<br> (list (list 'h 'o 't)<br> (list 'o 'h 't)<br> (list 'o 't 'h)<br>
(list 'h 't 'o)<br> (list 't 'h 'o)<br> (list 't 'o 'h)))<br><br>Thank you to everyone who provided input!<br>
<div>
<div></div>
<div class="h5"><br>On Apr 26, 6:02 pm, Nadeem Abdul Hamid <<a href="mailto:nad...@acm.org">nad...@acm.org</a>> wrote:<br>> Consider having the purpose of your insert-everywhere function:<br>><br>> > (insert-everywhere 'x (list 'h 'o 't))<br>
><br>> to be to produce this result by the time it's done:<br>><br>> > => (list (list 'x 'h 'o 't)<br>> > (list 'h 'x 'o 't)<br>> > (list 'h 'o 'x 't)<br>
> > (list 'h 'o 't 'x))<br>><br>> and consider what function you wish you could use in the body of <br>> insert-everywhere itself to achieve this (as opposed to thinking about <br>
> applying your helper function only after insert-everywhere has <br>> produced the result that you currently have it producing).<br>><br>> On Apr 26, 2009, at 5:37 PM, S Brown wrote:<br>><br>><br>><br>
> > I've been working on this for the last few hours, and my insert-<br>> > everywhere function is now working like so:<br>><br>> > (insert-everywhere 'x (list 'h 'o 't))<br>><br>
> > => (list (list 'x 'h 'o 't)<br>> > (list 'x 'o 't)<br>> > (list 'x 't)<br>> > (list 'x))<br>><br>> > So, I wish I had some function that would prefix each list with the<br>
> > "remainder" of the word, such that:<br>><br>> > (list (prefix remainder (list 'x 'h 'o 't))<br>> > (prefix remainder (list 'x 'o 't))<br>> > (prefix remainder (list 'x 't))<br>
> > (prefix remainder (list 'x)))<br>><br>> > => (list (list 'x 'h 'o 't)<br>> > (list 'h 'x 'o 't)<br>> > (list 'h 'o 'x 't)<br>
> > (list 'h 'o 't 'x))<br>><br>> > So, based on this I want a function, prefix, which basically takes two<br>> > words, appends them, and returns the new list. So, I guess in order to<br>
> > use this "prefix" function, I need to figure out how to define<br>> > "remainder," but now I seem to be stuck again because remainder<br>> > depends on information that isn't being passed along (ie, for (prefix<br>
> > remainder (list 'x 't)), remainder needs to be (list 'h 'o), but I<br>> > can't figure out how to do this!<br>><br>> > Am I at least on the right path with this? Any tips/hints??<br>
><br>> > On Apr 26, 1:25 pm, Matthias Felleisen <<a href="mailto:matth...@ccs.neu.edu">matth...@ccs.neu.edu</a>> wrote:<br>> >> Yes, and don't forget, you may need *more* auxiliary functions than<br>
> >> just insert-everywhere<br>><br>> >> On Apr 26, 2009, at 1:19 PM, S Brown wrote:<br>><br>> >>> Thanks for the input so far. I don't know how I didn't see this<br>> >>> before! Instead of calling append on (list s) (first a-low), what I<br>
> >>> need is to call append on another function which takes as it's<br>> >>> arguments a symbol and a single word, which returns a list of words<br>> >>> where the symbol has been been inserted before and after each letter<br>
> >>> in the word. In other words, where insert-everywhere/in-all-words is<br>> >>> concerned with a list of words, my new function is only concerned <br>> >>> with<br>> >>> a single word.<br>
><br>> >>> So, now it's a matter of going through the design process for my new<br>> >>> function, which I'm going to call insert-everywhere.<br>><br>> >>> ;; insert-everywhere: symbol word -> list-of-words<br>
> >>> ;; to create a list-of-words where symbol s is inserted before<br>> >>> ;; and after each letter in the word w<br>> >>> (define (insert-everywhere s w)<br>> >>> (cond<br>
> >>> ((empty? w) ... s ...)<br>> >>> (else ... s (first w) ...<br>> >>> ... (insert-everywhere s (rest w)) ...)))<br>><br>> >>> I think this makes sense. Now it's a matter of completing each cond<br>
> >>> line in my new function insert-everywhere.. and figuring out how to<br>> >>> actually insert a letter into each position of a word.<br>> >>> _________________________________________________<br>
> >>> For list-related administrative tasks:<br>> >>> <a href="http://list.cs.brown.edu/mailman/listinfo/plt-scheme" target="_blank">http://list.cs.brown.edu/mailman/listinfo/plt-scheme</a><br>><br>
> >> _________________________________________________<br>> >> For list-related administrative tasks:<br>> >> <a href="http://list.cs.brown.edu/mailman/listinfo/plt-scheme" target="_blank">http://list.cs.brown.edu/mailman/listinfo/plt-scheme</a><br>
> > _________________________________________________<br>> > For list-related administrative tasks:<br>> > <a href="http://list.cs.brown.edu/mailman/listinfo/plt-scheme" target="_blank">http://list.cs.brown.edu/mailman/listinfo/plt-scheme</a><br>
><br>> _________________________________________________<br>> For list-related administrative tasks:<br>> <a href="http://list.cs.brown.edu/mailman/listinfo/plt-scheme" target="_blank">http://list.cs.brown.edu/mailman/listinfo/plt-scheme</a><br>
_________________________________________________<br> For list-related administrative tasks:<br> <a href="http://list.cs.brown.edu/mailman/listinfo/plt-scheme" target="_blank">http://list.cs.brown.edu/mailman/listinfo/plt-scheme</a><br>
</div></div></blockquote></div><br>