how to return a reference in function

Q&A's, tips, howto's

how to return a reference in function

Postby csfreebird » Sat Dec 13, 2014 5:50 pm

Hi, I got some DAG code from rickyboy. In these code, I can get a node object from dag(I renamed it to Graph now) object, Graph and Node are FOOP object classes.
Then I try to modify this node, but find it's just a copy.
Code: Select all
;; @syntax (Graph:get-node node-name)
;; @description
;; <p>If you want to get a Node out of the Graph (e.g. in order to extract
;; its properties), then use the following function to get it by name.</p>
;; @example
;; (println (:get-node my-dag "G")) ;;=> (Node "G" sad)
;; (println (:get-node my-dag "Does not exist")) ;;=> nil
(define (Graph:get-node node-name)
  (and (find (list 'Node node-name '*)
             (:nodes (self))
             match)
       $0))


My calling code is:
Code: Select all
(setq product-node (:get-node my-dag "result"))
(push "2014-12-12 10:10" product-node -1)
(println product-node)
(println (:get-node my-dag "result"))


The output is:
(Node "result" "2014-12-12 10:10")
(Node "result")

I have no idea about returning a reference of Node object from Graph method.
csfreebird
 
Posts: 107
Joined: Tue Jan 15, 2013 11:54 am
Location: China, Beijing

Re: how to return a reference in function

Postby ralph.ronnquist » Sun Dec 14, 2014 7:53 am

I think you might be hunting a Snark there... as far as I have experienced, you may only treat lists as objects by "naming" them, and then refer to them via their "names". The naming would typically be by using symbols within a context, e.g. a context of such "objects" with generated names x0, x1, etc.

I think there a couple of frameworks for support in this OO style programming, although personally I tend to rather reinvent myself to not think about lists as objects, but as mere values, and then build the solutions from there.
ralph.ronnquist
 
Posts: 209
Joined: Mon Jun 02, 2014 1:40 am
Location: Melbourne, Australia


Return to newLISP in the real world

Who is online

Users browsing this forum: No registered users and 1 guest

cron