Introducing Objective newLISP
Introducing Objective newLISP
My apologies for the delay (I said I would announce this sooner), but it is finally done!
Check it out and let me know what you think!
Introducing Objective newLISP
Edit: link fixed, thanks!
Check it out and let me know what you think!
Introducing Objective newLISP
Edit: link fixed, thanks!
Last edited by itistoday on Wed Dec 09, 2009 2:47 am, edited 1 time in total.
Get your Objective newLISP groove on.
-
- Posts: 388
- Joined: Thu May 08, 2008 1:24 am
- Location: Croatia
- Contact:
-
- Posts: 394
- Joined: Wed Apr 26, 2006 3:37 am
- Location: Oregon, USA
- Contact:
Re: Introducing Objective newLISP
The link takes us to the Mutable objects in FOOP in development v.10.1.8 thread. Is this what you intended? I can't see any new links to your OOP module. Did I overlook it or are you just teasing us ;-)
m i c h a e l
P.S. Kazimir posted the link just before I posted. Thanks, Kazimir!
m i c h a e l
P.S. Kazimir posted the link just before I posted. Thanks, Kazimir!
-
- Posts: 2038
- Joined: Tue Nov 29, 2005 8:28 pm
- Location: latiitude 50N longitude 3W
- Contact:
Re: Introducing Objective newLISP
Cool. Well done!
To paraphrase that old joke about buses - you can wait for Object Oriented frameworks for ages and then suddenly two come along at the same time. I'm just trying to digest the new stuff Lutz posted, and now there's loads more to look at. Not complaining - that's great!
I think you could usefully say what Objective newLISP consists of - my first thought was that you had written a new language. :) It's just a module, though? So it can be mixed with existing newLISP code...
I can't say much about the introduction you've written - it's excellently done, but it's just theory to me, and I'd need to see some simple practical examples or descriptions of suitable applications before I could understand what you're aiming for with OnL, and why it would be worth getting into it. Don't worry about that too much, though, because I'm no OO programmer anyway, so these things typically operate above my head.
But - in any case - great stuff!
To paraphrase that old joke about buses - you can wait for Object Oriented frameworks for ages and then suddenly two come along at the same time. I'm just trying to digest the new stuff Lutz posted, and now there's loads more to look at. Not complaining - that's great!
I think you could usefully say what Objective newLISP consists of - my first thought was that you had written a new language. :) It's just a module, though? So it can be mixed with existing newLISP code...
I can't say much about the introduction you've written - it's excellently done, but it's just theory to me, and I'd need to see some simple practical examples or descriptions of suitable applications before I could understand what you're aiming for with OnL, and why it would be worth getting into it. Don't worry about that too much, though, because I'm no OO programmer anyway, so these things typically operate above my head.
But - in any case - great stuff!
Re: Introducing Objective newLISP
Yes.cormullion wrote:I think you could usefully say what Objective newLISP consists of - my first thought was that you had written a new language. :) It's just a module, though? So it can be mixed with existing newLISP code...
You'll probably want to check out the code for this then:I can't say much about the introduction you've written - it's excellently done, but it's just theory to me, and I'd need to see some simple practical examples or descriptions of suitable applications before I could understand what you're aiming for with OnL, and why it would be worth getting into it.
http://newlispfanclub.alh.net/forum/vie ... =17&t=3411
(Future proof link)
Thanks!But - in any case - great stuff!
Get your Objective newLISP groove on.
-
- Posts: 2038
- Joined: Tue Nov 29, 2005 8:28 pm
- Location: latiitude 50N longitude 3W
- Contact:
Re: Introducing Objective newLISP
Yes, I looked at that... What would be helpful for me (yet to grasp all the OO benefits) would be an example set in a simpler and more familiar problem domain - complex numbers, simple geometry, etc. How about doing a quick comparison of that complex number class that michael did?itistoday wrote:You'll probably want to check out the code for this then:
Code: Select all
(define (Class:Class) (cons (context) (args)))
(new Class 'Complex)
(define (Complex:rad c)
(sqrt (add (pow (c 1) ) (pow (c 2)))))
(define (Complex:add a b)
(Complex (add (a 1) (b 1)) (add (a 2) (b 2))))
(define (Complex:mul a b)
(let (a.re (a 1) a.im (a 2) b.re (b 1) b.im (b 2))
(Complex
(sub (mul a.re b.re) (mul a.im b.im))
(add (mul a.re b.im) (mul a.im b.re)))))
-
- Posts: 394
- Joined: Wed Apr 26, 2006 3:37 am
- Location: Oregon, USA
- Contact:
Re: Introducing Objective newLISP
With the addition of the Class context as a built-in (giving us the Class:Class constructor to inherit), the new method syntax (object implicitly passed) and the self function, this would be rewritten today as:
m i c h a e l
Code: Select all
(new Class 'Complex)
(define (Complex:rad)
(sqrt (add (pow (self 1) ) (pow (self 2))))
)
(define (Complex:add other)
(setf (self 1) (add (self 1) (other 1)))
(setf (self 2) (add (self 2) (other 2)))
(self)
)
(define (Complex:mul other) (let
(
a.re (self 1) a.im (self 2)
b.re (other 1) b.im (other 2)
)
(setf (self 1) (sub (mul a.re b.re) (mul a.im b.im)))
(setf (self 2) (add (mul a.re b.im) (mul a.im b.re)))
(self)
))
-
- Posts: 2038
- Joined: Tue Nov 29, 2005 8:28 pm
- Location: latiitude 50N longitude 3W
- Contact:
Re: Introducing Objective newLISP
(I had an email notification of your reply - thanks Ryon!)
Is that FOOP or ObjNL...?
Is that FOOP or ObjNL...?
-
- Posts: 394
- Joined: Wed Apr 26, 2006 3:37 am
- Location: Oregon, USA
- Contact:
Re: Introducing Objective newLISP
FOOP!
It's a direct copy of the code you posted above using the latest version of FOOP.
m i c h a e l
It's a direct copy of the code you posted above using the latest version of FOOP.
m i c h a e l
-
- Posts: 2038
- Joined: Tue Nov 29, 2005 8:28 pm
- Location: latiitude 50N longitude 3W
- Contact:
Re: Introducing Objective newLISP
I'm thinking about trying out ObjNL for a project. But I can't get started... Fancy helping me?
The general idea is to create a book, containing chapters, each of which contain sections, each of which contain paragraphs. Would ObjNL be a good way to explore/develop this kind of structure?
I've stared at this code for a few minutes now, and I'm not getting it. What is it doing? What is a Foo and a Bar anyway...?
Anyway, a few hints would be great...!
The general idea is to create a book, containing chapters, each of which contain sections, each of which contain paragraphs. Would ObjNL be a good way to explore/develop this kind of structure?
I've stared at this code for a few minutes now, and I'm not getting it. What is it doing? What is a Foo and a Bar anyway...?
Code: Select all
(context Foo)
(define (Foo:Foo _bar)
(setf bar _bar)
true
)
(context Bar)
(define (Bar:Bar _foo)
(setf foo _foo)
true ; don't allow ourselves to be deallocated
)
Re: Introducing Objective newLISP
It certainly can be used for that.cormullion wrote:I'm thinking about trying out ObjNL for a project. But I can't get started... Fancy helping me?
The general idea is to create a book, containing chapters, each of which contain sections, each of which contain paragraphs. Would ObjNL be a good way to explore/develop this kind of structure?
Foo and Bar are classes. Have you done OOP before?I've stared at this code for a few minutes now, and I'm not getting it. What is it doing? What is a Foo and a Bar anyway...?
Remember though that you need to create them using the (new-class) function. I.e. (new-class 'Foo).
If you haven't done OOP before, I would recommend reading up on that, then the blog post on ObjNL should be perfectly clear. Let me know if there are any other questions I can answer.
Get your Objective newLISP groove on.
-
- Posts: 394
- Joined: Wed Apr 26, 2006 3:37 am
- Location: Oregon, USA
- Contact:
Re: Introducing Objective newLISP
cormullion!
foo, bar, and baz are the names often given to variables in code examples. "Foo" and "bar" were inspired by the acronym FUBAR, which stands for "F***ed up Beyond all Recognition."
The early MIT hackers popularized many terms introduced during WWII, such as FUBAR and kludge.
m i c h a e l
BTW, here is a FOOP version ;-)
foo, bar, and baz are the names often given to variables in code examples. "Foo" and "bar" were inspired by the acronym FUBAR, which stands for "F***ed up Beyond all Recognition."
The early MIT hackers popularized many terms introduced during WWII, such as FUBAR and kludge.
m i c h a e l
BTW, here is a FOOP version ;-)
Code: Select all
(new Class 'Book)
(new Class 'Chapter)
(new Class 'Paragraph)
(define (Paragraph:text) (self 1))
(define (Chapter:text)
(format
"Chapter %d\n%s\n"
(self 1) (join (map (curry :text) (2 (self))) "\n")
)
)
(define (Book:text)
(format
"%s\n\n%s\nThe End\n"
(self 1) (join (map (curry :text) (2 (self))) "\n")
)
)
(setq frankenstein
(Book "Frankenstein"
(Chapter 1
(Paragraph "I am by birth a Genevese; and my family is . . .")
(Paragraph "As the circumstances of his marriage illustrate . . .")
(Paragraph "Beaufort had taken effectual measures to conceal . . .")
)
(Chapter 2
(Paragraph "We were brought up together; there was not quite . . .")
(Paragraph "On the birth of a second son, my junior by . . .")
(Paragraph "No human being could have passed a happier . . .")
)
(Chapter 3
(Paragraph "When I had attained the age of seventeen, my . . .")
(Paragraph "Elizabeth had caught the scarlet fever; her . . .")
(Paragraph "She died calmly; and her countenance expressed . . .")
)
)
)
(println (:text frankenstein))
-
- Posts: 2038
- Joined: Tue Nov 29, 2005 8:28 pm
- Location: latiitude 50N longitude 3W
- Contact:
Re: Introducing Objective newLISP
Thanks michael - example code is my favourite way of learning...!
I don't do much OOP - but am familiar with the concepts, in languages ranging from SmallTalk to Java. But I'd just like to see an example of ObjNL that makes sense at the same level as michael's example. I don't 'get' why you construct instances of each object to be the other. For me, the words foo and bar (I've heard of the tradition :) quickly become noise words, too devoid of meaning to be informative.
I don't do much OOP - but am familiar with the concepts, in languages ranging from SmallTalk to Java. But I'd just like to see an example of ObjNL that makes sense at the same level as michael's example. I don't 'get' why you construct instances of each object to be the other. For me, the words foo and bar (I've heard of the tradition :) quickly become noise words, too devoid of meaning to be informative.
Re: Introducing Objective newLISP
cormullion, I would check to see if FOOP satisfies your needs for your book project. ObjNL is for situations where you have complicated object relationships, and objects are being passed around and modified.
To use ObjNL properly, you also need to correctly make use of the functions retain and release, and possibly autorelease as well. These are documented a little bit in the blog post, but for a better understanding of them you may want to read the documentation on Objective-C, or some other language where you do manual reference counting.
Also, notice that the "FOOP way" uses the class name as the "constructor" of the objects (e.g.: (Paragraph "blah blah")). Normally ObjNL objects are instantiated using the instantiate function, like so:
You don't have to do this, however, if you write your constructor like so:
That allows you to create paragraphs like so:
You get essentially identical looking code to michael's example with Chapter/Paragraph/etc. classes. However, unlike FOOP, because ObjNL allows you to pass objects around by reference, you also have to correctly manage their memory. That means using proper conventions and the memory management functions I mentioned previously.
So, unless you want to learn learn about reference counting, I would stick to FOOP for this project. If FOOP's limitations start getting to you though, ObjNL should handle all of your object-oriented needs.
As an aside, I've just finished adding a basic ORM layer to DF.DB that I've tested using Sqliite3, and it uses ObjNL. It's already in the mercurial repository, and will be in the next release of Dragonfly. :-)
To use ObjNL properly, you also need to correctly make use of the functions retain and release, and possibly autorelease as well. These are documented a little bit in the blog post, but for a better understanding of them you may want to read the documentation on Objective-C, or some other language where you do manual reference counting.
Also, notice that the "FOOP way" uses the class name as the "constructor" of the objects (e.g.: (Paragraph "blah blah")). Normally ObjNL objects are instantiated using the instantiate function, like so:
Code: Select all
(instantiate Paragraph "blah blah")
Code: Select all
(new-class 'Paragraph)
(new-class 'Chapter)
(context Paragraph)
(define (Paragraph:Paragraph _str)
(if (= @self @class)
(autorelease (instantiate @class _str))
(begin (setf str _str) true) ; we don't retain _str b/c it's not an ObjNL object
)
)
(context Chapter)
(define (Chapter:Chapter _paragraph)
(if (= @self @class)
(autorelease (instantiate @class _paragraph))
(setf paragraph (retain _paragraph)) ; we don't have a 'true' at the end so that we're deallocated if given nil
)
)
Code: Select all
(Paragraph "my great paragraph")
So, unless you want to learn learn about reference counting, I would stick to FOOP for this project. If FOOP's limitations start getting to you though, ObjNL should handle all of your object-oriented needs.
As an aside, I've just finished adding a basic ORM layer to DF.DB that I've tested using Sqliite3, and it uses ObjNL. It's already in the mercurial repository, and will be in the next release of Dragonfly. :-)
Get your Objective newLISP groove on.
Re: Introducing Objective newLISP
BTW, to get exactly michael's version for Chapter, this would be the required ObjNL constructor:
Edit: If you didn't care about calling 'instantiate' yourself, the constructor is a bit simpler:
Code: Select all
(define (Chapter:Chapter _num)
(if (= @self @class)
(autorelease (eval (extend (list 'instantiate @class _num) $args)))
(set 'num _num 'paragraphs (map retain $args))
)
)
Code: Select all
(define (Chapter:Chapter _num)
(set 'num _num 'paragraphs (map retain $args))
)
Get your Objective newLISP groove on.
Re: Introducing Objective newLISP
Hi m i c h a e l!m i c h a e l wrote:Code: Select all
(new Class 'Book) (new Class 'Chapter) (new Class 'Paragraph) (define (Paragraph:text) (self 1)) (define (Chapter:text) (format "Chapter %d\n%s\n" (self 1) (join (map (curry :text) (2 (self))) "\n") ) ) (define (Book:text) (format "%s\n\n%s\nThe End\n" (self 1) (join (map (curry :text) (2 (self))) "\n") ) ) (setq frankenstein (Book "Frankenstein" (Chapter 1 (Paragraph "I am by birth a Genevese; and my family is . . .") (Paragraph "As the circumstances of his marriage illustrate . . .") (Paragraph "Beaufort had taken effectual measures to conceal . . .") ) (Chapter 2 (Paragraph "We were brought up together; there was not quite . . .") (Paragraph "On the birth of a second son, my junior by . . .") (Paragraph "No human being could have passed a happier . . .") ) (Chapter 3 (Paragraph "When I had attained the age of seventeen, my . . .") (Paragraph "Elizabeth had caught the scarlet fever; her . . .") (Paragraph "She died calmly; and her countenance expressed . . .") ) ) ) (println (:text frankenstein))
I'm just learning FOOP in newLISP from example code. The hardest part is to find some written in newLISP ;-)
Your "Book example" is great but I get this error:
Code: Select all
ERR: invalid function in function format : (MAIN:self 1)
called from user defined function Book:text
Thanks!
Marc
--()o Dragonfly web framework for newLISP
http://dragonfly.apptruck.de
http://dragonfly.apptruck.de
Re: Introducing Objective newLISP
It works fine on my end, I'm guessing you're running an older version of newLISP that doesn't support the new FOOP stuff.hilti wrote:Code: Select all
ERR: invalid function in function format : (MAIN:self 1) called from user defined function Book:text
Get your Objective newLISP groove on.
-
- Posts: 2038
- Joined: Tue Nov 29, 2005 8:28 pm
- Location: latiitude 50N longitude 3W
- Contact:
Re: Introducing Objective newLISP
Ah, yes. I'm very grateful for the advice. I think I'm more interested in modelling the hierarchical structure rather than the interactions of objects, so you're probably right...! I shall get round to ObjNL soon.itistoday wrote:ObjNL is for situations where you have complicated object relationships, and objects are being passed around and modified.
-
- Posts: 394
- Joined: Wed Apr 26, 2006 3:37 am
- Location: Oregon, USA
- Contact:
Re: Introducing Objective newLISP
Hi Mark!
m i c h a e l
:-) I'm nearing completion of a new video on FOOP, but it's just a basic overview. The next video I'd like to do should contain a more complex example, so I'm hoping that one will clear up any grey areas. Although, to be honest, there's a lot about FOOP I still don't understand myself ;-)hilti wrote:I'm just learning FOOP in newLISP from example code.
The hardest part is to find some written in newLISP ;-)
I'd be happy to, but I think Greg already nailed it. newLISP gained the self function in v.10.1.8 and had a bug fix in v.10.1.9. self is still only available through a development release.hilti wrote:Your "Book example" is great but I get this error:
Code:
ERR: invalid function in function format : (MAIN:self 1)
called from user defined function Book:text
May You help me?
m i c h a e l