• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

LISP programming help needed

adlep

Diamond Member
Help...
This lisp programming is something very diffrient from what I have seen before...
Anyhow
Is it possible to modify this code so it is going to remove 3rd element from the list instead of the second?
The code:
(define deletesecond (lambda (L)
(cond
; if L isn't a list return null
((not (list? L)) '())

; if L has length less than 2 return null
((> 2 (length L)) '())

; return the cons of the head of L
; with the tail of the tail of L
(else (cons (car L)
(cdr (cdr L))
)
)
)
))
Help...
Thanks
 
I haven't had Lisp in a long time so this probably won't work. My editing is in bold.


--------------------------------------------------------------------------------

(define deletethird (lambda (L)
(cond
; if L isn't a list return null
((not (list? L)) '())

; if L has length less than 3 return null
((> 3 (length L)) '())

; return the cons of the head of L
; with the tail of the tail of L
(else (cons (car L)
(cdr (cdr (cdr L)))
)
)
)
))


--------------------------------------------------------------------------------


PS. Do your own homework from now on 😉
 
To program effectively in lisp, drink a lot of alcohol and remember to stop every 10 minutes to bang your head against the wall...
 
Long live the Language of Irritating Thingle Parenthetheth!

BTW: Does anybody else find it immoral that an "s" is included in the word "lisp"?
 
Thanks folks, but I have figured it out..
Wrote a diffrient code...
And LISP IS RETARDED
(define (remove lis)
(cond
((null? lis) '())
((null? (cdr lis)) '())
((null? (cdr (cdr lis))) '())
(else (append (list (car lis) (car (cdr lis))) (cdddr lis)))
))

That works just fine!
 
Kyteland, thanks for the feedback, but your modification removes second and third element from the list:

(cdr (cdr (cdr L)))

I am doing my homework for myself....😀
 
Back
Top