Hello!
I'm new to lisp and newLisp - sorry if that's quite stupid ;)
Can I return a list from a function as element-by-element, without collecting it to the temporary variable? And is it have a sense?
To enumerate network interfaces I wrote such thing:
# analog to: /sbin/ifconfig|awk '/^[[:alpha:]]/{print $1}'
(define (if-list)
(set 'iflist (list))
(dolist (str (exec "/sbin/ifconfig"))
(if (find "^[[:alpha:]][[:alnum:]]+" str 0)
(set 'iflist (append iflist (list $0)))))
iflist)
Can I somehow remove "iflist" from code?
Possible there is a better way for such tasks?
The least thing you can do is using 'push' to make things smaller:
(define (if-list)
(dolist (str (exec "/sbin/ifconfig"))
(if (find "^[[:alpha:]][[:alnum:]]+" str 0)
(push $0 iflist)))
iflist)
You could also use your original query which is even smaller:
(define (if-list)
(dolist (str (exec "/sbin/ifconfig | awk '/^[[:alpha:]]/{print $1}'"))
(push str iflist)
iflist))
Returning element-by-element means keeping track of the interface number to be returned, introducing an extra variable, I suppose.
Peter
Thanks, Peter! That helps!