What is the best way in newLISP to drill down into various parts of this structure?
I have so far been using code like:
Code: Select all
((assoc "nodes" (((assoc "nodes" ((get_tree) (0 -1 (ref '("name" "VGA1") (get_tree) match)))) 1) 1)) 1))
Code: Select all
((assoc "nodes" (((assoc "nodes" ((get_tree) (0 -1 (ref '("name" "VGA1") (get_tree) match)))) 1) 1)) 1))
Code: Select all
(ref-all '(* ("cachePagesTrack" 200) * ) data match)
;->
((0 1 0 1 0 2 1)
(0 1 0 1 1 2 1)
(0 1 0 1 2 2 1)
(0 1 0 1 3 2 1)
(0 1 0 1 4 2 1)
(0 1 0 1 5 2 1)
(0 1 0 1 6 2 1))
Code: Select all
nil
Code: Select all
(define (nodes beneath_name in_list)
((assoc "nodes" (ref (list '* (list "name" beneath_name) '*) in_list match true))1))
I don't know. Your latest one is pretty clear. You could try defining it as a macro -- to clean up the look of the exp-key, and then use (lookup ...) instead of ((assoc ...) 1).bairui wrote:Perhaps there are still places where that can be cleaned up?
Code: Select all
(define-macro (nodes beneath_name in_list)
(letex ($B beneath_name $L in_list)
(lookup "nodes"
(ref '(* ("name" $B) *) $L match true))))
Code: Select all
(define (nodes beneath_name in_list)
((assoc "nodes" (ref (list '* (list "name" beneath_name) '*) in_list match true))1))
Code: Select all
(definm (nodes beneath_name in_list)
(lookup "nodes" (ref '(* ("name" beneath_name) *) in_list match true)))
Code: Select all
(lambda-macro (beneath_name in_list)
(letex (beneath_name beneath_name in_list in_list)
(lookup "nodes" (ref '(* ("name" beneath_name) *) in_list match true))))
Code: Select all
(define-macro (definm)
(letex ($MFORM (args 0)
$LARGS (apply append (map (fn (a) (list a a)) (1 (args 0))))
$LBODY (1 (args)))
(letex ($MBODY (letex ($$LARGS '$LARGS $$LBODY '$LBODY)
(cons 'letex (cons '$$LARGS '$$LBODY))))
(define-macro $MFORM $MBODY))))
Code: Select all
(define (get_workspace_trees , x)
(let (x '())
(dolist (output (get_active_output_names))
(push (list output (nodes "content" (nodes output (get_tree)))) x))
x))
Code: Select all
(define-macro (nodes beneath_name in_list)
(letex ($B beneath_name $L (eval in_list))
(lookup "nodes"
(ref '(* ("name" $B) *) $L match true))))
Code: Select all
(define (nodes beneath_name in_list)
(or (lookup "nodes"
(or (ref (list '* (list "name" beneath_name) '*)
in_list match true)
'()))
'()))