[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.lisp

Problems with defining functions

gengyangcai

11/10/2015 8:00:00 AM

I defined a function called "our-fifth" to return the fifth element of a list and it works well ----

CL-USER 3 : 1 > (defun our-fifth (x)
(car (cdr (cdr (cdr (cdr x))))))
OUR-FIFTH

CL-USER 4 : 1 > (our-fifth '(a b c d e f g))
E

but when i changed the function name to simply "fifth", it gives an error message ----

CL-USER 6 : 1 > (defun fifth (x)
(car (cdr (cdr (cdr (cdr x))))))

Error: Redefining function FIFTH visible from package COMMON-LISP.
1 (continue) Redefine it anyway.
2 (abort) Return to level 1.
3 Return to debug level 1.
4 Redefine it anyway.
5 Return to level 0.
6 Return to top loop level 0.

Am I missing something here ? This is not a 'troll' question right ?



A nice programming joke :

Q: How do you tell an introverted computer scientist from an extroverted computer scientist?

A: An extroverted computer scientist looks at your shoes when he talks to you.
2 Answers

Pascal J. Bourguignon

11/10/2015 11:58:00 AM

0

CAI GENGYANG <gengyangcai@gmail.com> writes:

> Error: Redefining function FIFTH visible from package COMMON-LISP.
>
> Am I missing something here ? This is not a 'troll' question right ?

No, it's not a troll question. But one important skill a newbie
programmer has to learn, is to READ THE FINE ERROR MESSAGE!

Here, the error message is:

"Error: Redefining function FIFTH visible from package COMMON-LISP."

And it says that you are REDEFINING the FUNCTION FIFTH, which logically
is already DEFINED, in the PACKAGE COMMON-LISP.

And this is a problem since you must not try to redefine things that
are defined in the COMMON-LISP package.

Here are all the rules about the COMMON-LISP package:
http://www.lispworks.com/documentation/HyperSpec/Body/1...


So basicaly, in the current state of your lisp system, when it reads
"fifth", it actually reads the symbol COMMON-LISP:FIFTH.
You could define your own package where COMMON-LISP:FIFTH wouldn't be
visible, and where you could intern your own symbol named "FIFTH.

(defpackage "CAI"
(:use "COMMON-LISP")
(:shadow "FIFTH")
(:export "FIFTH"))


(in-package "CAI")

(defun fifth (x)
(car (cdr (cdr (cdr (cdr x))))))

(fifth '(1 2 3 4 5 6 7 8))
;; --> 5

(eq 'cai:fifth 'fifth)
;; --> T

(eq 'cl:fifth 'fifth)
;; --> NIL


(in-package "COMMON-LISP-USER")

(cai:fifth '(1 2 3 4 5 6 7 8))
;; --> 5

(eq 'cai:fifth 'fifth)
;; --> NIL

(eq 'cl:fifth 'fifth)
;; --> T


--
__Pascal Bourguignon__ http://www.informat...
â??The factory of the future will have only two employees, a man and a
dog. The man will be there to feed the dog. The dog will be there to
keep the man from touching the equipment.� -- Carl Bass CEO Autodesk

gengyangcai

11/12/2015 4:40:00 AM

0

Ok



On Tuesday, November 10, 2015 at 7:57:50 PM UTC+8, informatimago wrote:
> CAI GENGYANG <gengyangcai@gmail.com> writes:
>
> > Error: Redefining function FIFTH visible from package COMMON-LISP.
> >
> > Am I missing something here ? This is not a 'troll' question right ?
>
> No, it's not a troll question. But one important skill a newbie
> programmer has to learn, is to READ THE FINE ERROR MESSAGE!
>
> Here, the error message is:
>
> "Error: Redefining function FIFTH visible from package COMMON-LISP."
>
> And it says that you are REDEFINING the FUNCTION FIFTH, which logically
> is already DEFINED, in the PACKAGE COMMON-LISP.
>
> And this is a problem since you must not try to redefine things that
> are defined in the COMMON-LISP package.
>
> Here are all the rules about the COMMON-LISP package:
> http://www.lispworks.com/documentation/HyperSpec/Body/1...
>
>
> So basicaly, in the current state of your lisp system, when it reads
> "fifth", it actually reads the symbol COMMON-LISP:FIFTH.
> You could define your own package where COMMON-LISP:FIFTH wouldn't be
> visible, and where you could intern your own symbol named "FIFTH.
>
> (defpackage "CAI"
> (:use "COMMON-LISP")
> (:shadow "FIFTH")
> (:export "FIFTH"))
>
>
> (in-package "CAI")
>
> (defun fifth (x)
> (car (cdr (cdr (cdr (cdr x))))))
>
> (fifth '(1 2 3 4 5 6 7 8))
> ;; --> 5
>
> (eq 'cai:fifth 'fifth)
> ;; --> T
>
> (eq 'cl:fifth 'fifth)
> ;; --> NIL
>
>
> (in-package "COMMON-LISP-USER")
>
> (cai:fifth '(1 2 3 4 5 6 7 8))
> ;; --> 5
>
> (eq 'cai:fifth 'fifth)
> ;; --> NIL
>
> (eq 'cl:fifth 'fifth)
> ;; --> T
>
>
> --
> __Pascal Bourguignon__ http://www.informat...
> "The factory of the future will have only two employees, a man and a
> dog. The man will be there to feed the dog. The dog will be there to
> keep the man from touching the equipment." -- Carl Bass CEO Autodesk