Newbie questions - and yes, its homework :-(
Posted: Thu Jan 27, 2011 1:45 pm
Hi Everyone.
I need some very basic help. I am taking a course on lisp, but was up until now unable to attend (just moved to a new city (and continent. ha) and family and health issues :-S...) Now I just figured out that I have an assignment due this monday.
Now the last two days I have done my best to learn as much as possible, but I still feel quite far away from actually solving any of the problems. Maybe someone here can give me some pointers on how to think of them. Here is the first problem.
----------------------
(1) Write a recursiveLISP function addâ€toâ€odd which takes a list of numbers as its argument and returns the same list, but with 1 added to each of the odd numbers. So:
> (addâ€toâ€odd '(3 6 7 4 6 5))
(4 6 8 4 6 6)
----------------------
(I am using Allegro Common Lisp by Franz if thats of any relevence)
The way I figure this should work is something like this:
Well anyway, this does not work - I am currently working myself through this lisp tutorial: http://www.gigamonkeys.com/book/ but so far it has not specifically been of help for my problems.
I am looking for
a) A tutorial which focuses on recursion
b) Someone to point out my mistakes in the code I posted (I realise its very foulty most of it is me just guessing what it should be like)
and
c) Someone who could describe to me how to think of this problem, what the structure of the solution should look like.
******
I am not trying to get you guys to do my homework for me. I just need to learn how to do this in three days and would apreceate all the help I get.
Thanks in advance
Regards
p.
(ah, also: is there any program you could recommend to me which is similar to the allegreo cl interpreter/compiler by franz which uses colour for marking comments etc. Something to make the code easyer to read, like notepad++ does?)
I need some very basic help. I am taking a course on lisp, but was up until now unable to attend (just moved to a new city (and continent. ha) and family and health issues :-S...) Now I just figured out that I have an assignment due this monday.
Now the last two days I have done my best to learn as much as possible, but I still feel quite far away from actually solving any of the problems. Maybe someone here can give me some pointers on how to think of them. Here is the first problem.
----------------------
(1) Write a recursiveLISP function addâ€toâ€odd which takes a list of numbers as its argument and returns the same list, but with 1 added to each of the odd numbers. So:
> (addâ€toâ€odd '(3 6 7 4 6 5))
(4 6 8 4 6 6)
----------------------
(I am using Allegro Common Lisp by Franz if thats of any relevence)
The way I figure this should work is something like this:
Code: Select all
;; write function add-to-list with a list as input
(defun add-to-odd (mylist)
;;some sort of condition to brake the loop
;;(my reasoning: when mylist is equal nil,
;; its an empy list and we have gone through all elements of the list)
(cond ((eql mylist nil) nil))
;;check whether the first number of the list is odd or even
(cond (eql(mod (car mylist)) 1) )
;; if its odd, add 1
((+ (car mylist) 1) ,
;; repeat with the rest of the list
(add-to-odd (cdr mylist))))
I am looking for
a) A tutorial which focuses on recursion
b) Someone to point out my mistakes in the code I posted (I realise its very foulty most of it is me just guessing what it should be like)
and
c) Someone who could describe to me how to think of this problem, what the structure of the solution should look like.
******
I am not trying to get you guys to do my homework for me. I just need to learn how to do this in three days and would apreceate all the help I get.
Thanks in advance
Regards
p.
(ah, also: is there any program you could recommend to me which is similar to the allegreo cl interpreter/compiler by franz which uses colour for marking comments etc. Something to make the code easyer to read, like notepad++ does?)