reset password
Author Message
nikkodg
Posts: 12
Posted 18:36 Oct 09, 2015 |

I am currently on the last step of the lab. I have a variable that holds an empty list. What I am doing is creating a game struct and a new list to hold it at the end of each game and appending that list to the existing variable list. 

Using a line like this: 

(set! gamesList (append gamesList newList)

gamesList is the variable with the empty list

newList is the list that holds the game struct

What is happening is that when I call the history function or the list it only shows the most recent list added.

I would appreciate any help or advice, thanks!

 

darkserith
Posts: 45
Posted 18:58 Oct 09, 2015 |

Well what you are doing is exactly how I implemented my code, and I got it to work.

my code is:

 (set! allGames (append (list (game gameNumber initialLower initialUpper finalLower finalUpper answer numberOfGuesses)) allGames))

(define (history) (display (reverse allGames)))

Here, allGames is the variable that started out with an empty list value. It works the same way you explained it, in that I append

the game object with the allGames list. So yeah looks pretty similar to yours imo.

The only reason that I could think of for why your history function is returning only the most recently added list, is that you are calling (display) on newList (which holds the game object) instead of gamesList (which holds the running list of all games added so far)??

if you want me to look at your code and help you out you can PM me, with your email or some link to a google doc i don't mind reviewing it.

nikkodg
Posts: 12
Posted 19:00 Oct 09, 2015 |

I would very much appreciate that. Just give me some time to comment everything really quick its still a bit messy

darkserith
Posts: 45
Posted 19:06 Oct 09, 2015 |

uh actually hm i guess there is no "PM" functionality on this forums. darn.

just instant message me on Skype if you want.

my Skype ID is "darkserith".

nikkodg
Posts: 12
Posted 19:12 Oct 09, 2015 |

I added you. Im nikkdg

dbravoru
Posts: 60
Posted 19:16 Oct 09, 2015 |

I have it the same way as the second post; instead of having two lists in separate places, you can just just append the list containing the game structure (where list (game gamenum.....and so on)) to the empty list. 

Then when you start another game, you dont have to keep setting the game structure to a list, since you create one at the end and append it immediately.

Amedrano
Posts: 80
Posted 22:42 Oct 09, 2015 |
darkserith wrote:

 (set! allGames (append (list (game gameNumber initialLower initialUpper finalLower finalUpper answer numberOfGuesses)) allGames))

(define (history) (display (reverse allGames)))

Here, allGames is the variable that started out with an empty list value. It works the same way you explained it, in that I append

 

could you explain your (history) function? how does (display) work? and how can I iterate through my list to print out my gameList information? 

Amedrano
Posts: 80
Posted 22:52 Oct 09, 2015 |

I know how display works.  I'm not sure how to use my custom write procedure to iterate through and display my list of games.

 

Any help would be appreciated!

darkserith
Posts: 45
Posted 23:16 Oct 09, 2015 |
Amedrano wrote:

I know how display works.  I'm not sure how to use my custom write procedure to iterate through and display my list of games.

 

Any help would be appreciated!

if you added the games to the list (that keeps a list of all the games played), then calling display on that list would automatically use the custom-write procedure to achieve desired output. just make sure the custom write procedure works though. 

Amedrano
Posts: 80
Posted 23:24 Oct 09, 2015 |
darkserith wrote:
Amedrano wrote:

I know how display works.  I'm not sure how to use my custom write procedure to iterate through and display my list of games.

 

Any help would be appreciated!

if you added the games to the list (that keeps a list of all the games played), then calling display on that list would automatically use the custom-write procedure to achieve desired output. just make sure the custom write procedure works though. 

Ok so my problem is if I have gameList of size 2 when I call the (history) function displays the last game entered twice.  If i have 3 items it will display the last game 3 times and so on...

Last edited by Amedrano at 23:25 Oct 09, 2015.
Amedrano
Posts: 80
Posted 23:32 Oct 09, 2015 |

got it thanks