Thanks for the movie!
http://nuevatec.com/FOOP-00-01.mov
Foop, the movie
-
- Posts: 2038
- Joined: Tue Nov 29, 2005 8:28 pm
- Location: latiitude 50N longitude 3W
- Contact:
Fantastic movie ! I can't wait for Chapter 2 !
It made me want to put into practice at once with this little script (inspired by a Python script):
I'm not sure it is perfect, concerning FOOP (and my knowledges about physics)
;)
It made me want to put into practice at once with this little script (inspired by a Python script):
Code: Select all
#!/usr/bin/newlisp
; newlisp 2.9.7 - dec 2007
; This script creates objects 'Atom' and 'Ion'.
; A ion is just an altered atom. So the class 'Ion'
; is derived from the class 'Atom'and inherits from this one
; all its attributes and methods, appending its own.
; One of these added methods (the method 'display') replaces
; a method of the same name inherited from 'Atom'.
; Then 'Atom' and 'Ion' have both a method with the same name
; but making different work. That is polymorphism.
(set 'table '(nil
("hydrogen" 0)("helium" 2)("lithium" 4)
("beryllium" 5)("boron" 6)("carbon" 6)
("nitrogen" 7)("oxygen" 8)("fluorine" 10)("neon" 10)))
(define (Atome:Atome nat , np ne nn)
; nat=atomic number
(set 'np nat 'ne nat 'nn (table nat 1))
(list Atome nat np ne nn))
(define (Atome:display a)
(println "\nName of the element : " (table (a 2) 0))
(println (a 2) " protons, " (a 3) " electrons, " (a 4) " neutrons"))
(new Atome 'Ion)
(define (Ion:Ion nat charge , np ne nn)
(set 'np nat 'ne (- nat charge) 'nn (table nat 1))
(list Ion nat np ne nn charge))
(define (Ion:display a)
(Atome:display a)
(println "Electrified particle. Charge = " (a 5)))
;; Main Program
(set 'a1 (Atome 5))
(set 'a2 (Ion 3 1))
(set 'a3 (Ion 8 -2))
(:display a1)
(:display a2)
(:display a3)
;)
-
- Posts: 2038
- Joined: Tue Nov 29, 2005 8:28 pm
- Location: latiitude 50N longitude 3W
- Contact:
OT!
And when you mention elements in the periodic table just after I've watched michael's wonderful animated movie, I can't resist pointing you to this wonderful flash animation:
http://www.privatehand.com/flash/elements.html
http://www.privatehand.com/flash/elements.html
Re: OT!
Fine and funny :Dcormullion wrote:And when you mention elements in the periodic table just after I've watched michael's wonderful animated movie, I can't resist pointing you to this wonderful flash animation:
http://www.privatehand.com/flash/elements.html
Thanks
-
- Posts: 394
- Joined: Wed Apr 26, 2006 3:37 am
- Location: Oregon, USA
- Contact:
Hi newBert!
I'm glad to see the video inspired you to experiment with FOOP. Since this way of programming with newLISP is still new, there are no FOOP experts. I call what I'm doing explorations because I'm just feeling my way around in the dark. The FOOP way emerges through use.
Your code is quite good, and the comments at the top show you clearly understand the subject. Object access occurs only within methods (display), and your use of Atome:display within Ion:display is really nice. (Here, the complex subject of calling a superclass's overridden method is turned into a simple qualified method call.)
I do have a question about your constructors. Since the values of the symbols np, ne, nn, etc. are lost with the completion of the constructor, why not this?
Or if you want to document the attributes:
There is no single, fixed way to do FOOP, so go with the way that feels most natural to you.
Certain aspects of FOOP will require a mental shift for practiced OOPers. I believe the concept of changeless objects is the part of FOOP that will give them the most difficulty. When we begin to use objects the same way we use the number 5 or the string "hello", I think we'll be on the right track.
m i c h a e l
I'm glad to see the video inspired you to experiment with FOOP. Since this way of programming with newLISP is still new, there are no FOOP experts. I call what I'm doing explorations because I'm just feeling my way around in the dark. The FOOP way emerges through use.
Your code is quite good, and the comments at the top show you clearly understand the subject. Object access occurs only within methods (display), and your use of Atome:display within Ion:display is really nice. (Here, the complex subject of calling a superclass's overridden method is turned into a simple qualified method call.)
I do have a question about your constructors. Since the values of the symbols np, ne, nn, etc. are lost with the completion of the constructor, why not this?
Code: Select all
(define (Atome:Atome nat)
; nat=atomic number
(list Atome nat nat nat (table nat 1)))
Or if you want to document the attributes:
Code: Select all
(define (Ion:Ion nat charge)
;; (Ion nat np ne nn charge)
(list Ion nat nat (- nat charge) (table nat 1) charge))
There is no single, fixed way to do FOOP, so go with the way that feels most natural to you.
Certain aspects of FOOP will require a mental shift for practiced OOPers. I believe the concept of changeless objects is the part of FOOP that will give them the most difficulty. When we begin to use objects the same way we use the number 5 or the string "hello", I think we'll be on the right track.
m i c h a e l
-
- Posts: 2038
- Joined: Tue Nov 29, 2005 8:28 pm
- Location: latiitude 50N longitude 3W
- Contact:
Yes, it's confusing this non-OOPer too. If I understand correctly: you're not able to modify the 'internal variables' of an object instance using these method calls. So when you want to, say, update the x and y coordinates of an object, you have to create a new copy of it with the modified values. Why can't you change the values in place, then...?m i c h a e l wrote: I believe the concept of changeless objects is the part of FOOP that will give them the most difficulty.
It doesn't seem right that you have to create new copies of things all the time just to change one value... One of my original comments about using contexts was that you're duplicating the methods inside each object. Now you're continually making copies of the data...
well, not continually, just a bit more, but in the overall picture the difference is probably less than 5%, because so much copying is going on in the interpreter internally anyway.Now you're continually making copies of the data...
But you gain advantages: code writing which is said less error-prone in a functional style programming and a functional style OO melts better into a functional language.
Lutz
I've done that quickly from a Python script and I didn't take time to think about the name of the attributes that I copied out again from the original script. But I do note your remarks...m i c h a e l wrote:
I do have a question about your constructors. Since the values of the symbols np, ne, nn, etc. are lost with the completion of the constructor, why not this?
Code: Select all
(define (Atome:Atome nat) ; nat=atomic number (list Atome nat nat nat (table nat 1)))
Or if you want to document the attributes:
Code: Select all
(define (Ion:Ion nat charge) ;; (Ion nat np ne nn charge) (list Ion nat nat (- nat charge) (table nat 1) charge))
There is no single, fixed way to do FOOP, so go with the way that feels most natural to you.
:)