Well, you did identify the problem as something that was for yourself
> The only problems I forsee, is that are instructor was very
> picky about which already defined functions we could use.
and not for the instructor.
If you want to know for yourself, then you can use the extra functions.
If you want to know for an instructor, you should identify that fact
clearly so that people don't misunderstand and end up doing your homework
> Like I'm not sure he would allow "dolist" or push, if he were to have us do DOLIST is just an abstraction for visiting every element of a list.
> this. I was just wondering if there was a round about way to accomplish this.
It is conceptually the same as a recursive function, but it doesn't
have a problem with stack. (In Scheme, tail recursion is guaranteed
as part of the language definition to get optimized so that you can
use it for control in the way teachers often want you to, but in Lisp
you do NOT have that guarantee and except in toy examples, it is a BAD
PLAN to be using tail recursion in Common Lisp code when trying to
traverse a data structure that might be unbounded in size, since you
will almost certainly blow out of stack.)
The following two functions are essentially equivalent except that
(in Common Lisp), the first will be much more likely to still work for long
lists. Both functions will probably work for short lists.
(defun foo (x)
(dolist (elem x) (print x)))
(defun foo (x)
(cond ((null x) nil)
(t (print (car x))
(foo (cdr x)))))
There are two things your teacher might be trying to teach you.
One is that tail recursion offers a useful way to think about things.
That's a good thing to learn. The other is that tail recursion is
the right thing to use in Common Lisp to traverse lists, and my
personal advice would be to be doubtful of any such claim if you
hear it being made.
You can think about things however you want, but when it comes down
to applying tools, you must apply them with a knowledge of both their
power AND their limitation. To use tail recursion without understanding
that it is limited in CL is not to use the tool correctly.
> for instance some of my funtions were With dolist, you'd write the following. Incidentally, it's worth
> (defun myunion (Lst1 Lst2)
> ((null Lst1) Lst2)
> ((memberp (car Lst1) Lst2) (myunion (cdr Lst1) Lst2))
> (t (cons (car Lst1)(myunion (cdr Lst1) Lst2)))
> We had t do it all from scratch.
putting those vowels back. Call your variables things that are
easy to pronounce so you can talk to people about your programs and
they will know how to spell what you are talking about.
(defun myunion (list1 list2)
(let ((result list2))
(dolist (element list1)
(unless (member element result)
(push element result)))
> So now that this is longer winded than intended. I guess I was still I'm not sure what "the hard way" is... is that using the real lisp
> wondering how to change (a a a b b) to ((a3) (b2)) and back again
> ....the hard way.
tools or using the things your instructor wants you to use?