Hello,
For a student work I need to use the function simp,
which behavior can be described by the 3 following
cases:
(simp '(... (a) ...)) => (... a ...)
(simp '((((x1 x2) x3) x4) x5)) => (x1 x2 x3 x4 x5)
(simp '(... xi ((((xj xj+1) ...) ...)
=> (... xi (xj xj+1) ...)
On told me, that simp is a scheme function, but
DrScheme with Windows doesn't know it.
Can anyone give me the source code of this function?
Thank
Michael Parienti
[Note crossposting between c.l.lisp and c.l.scheme]
Micha�l Parienti <········@altern.org> writes:
> On told me, that simp is a scheme function, but
> DrScheme with Windows doesn't know it.
It is not a standard scheme function.
It looks like an student exercise to me, perhaps it is a result of an
earlier exercise you never did?
By the way, it doesn't seem to me that the function is well defined
from what you wrote.
Stig Hemmer,
Jack of a Few Trades.
In article <·················@altern.org>, =?iso-8859-1?Q?Micha=EBl?=
Parienti <········@altern.org> wrote:
> Hello,
>
> For a student work I need to use the function simp,
> which behavior can be described by the 3 following
> cases:
>
> (simp '(... (a) ...)) => (... a ...)
> (simp '((((x1 x2) x3) x4) x5)) => (x1 x2 x3 x4 x5)
>
>
> (simp '(... xi ((((xj xj+1) ...) ...)
> => (... xi (xj xj+1) ...)
>
> On told me, that simp is a scheme function, but
> DrScheme with Windows doesn't know it.
>
> Can anyone give me the source code of this function?
I think maybe the idea is that you're supposed to write it?
Given that, here's a rather stupid (but correct) way to do it, that will
give you the idea how to do it yourself. Hand this in and you'll get low
marks :-)
(define (simp x)
(define (simp1 x y)
(cond
((pair? x) (simp1 (car x) (if (null? (cdr x)) y (cons (cdr x) y))))
((null? x) (if (null? y) '() (simp1 y `())))
(#t (cons x (simp1 y '())))))
(trace simp1)
(simp1 x '()))