how to return a reference in function

Started by csfreebird, December 13, 2014, 09:50:10 AM

Previous topic - Next topic

csfreebird

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.

;; @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:

(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.

rrq

#1
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.