tip for today: script uptime?

Started by newdep, April 11, 2008, 12:51:00 AM

Previous topic - Next topic

newdep

Sometimes its for newlisp handy to know how long itself is running.

An "uptime" counter is not default inside newlisp, (though would be nice to have inside (sys-info), here a way to do it:


Quote;; @syntax (uptime?)

;; @returns time in seconds newlisp is UP.

;; @description place this in your init.lsp

;; (constant 'sys-uptime (date-value))

;; (define (uptime?) (- (date-value) sys-uptime))

;; @example

;;

;; (uptime?)

;; => 10
-- (define? (Cornflakes))

cormullion

#1
That's good!



For init.lsp, don't I have to edit the /usr/share/newlisp/init.lsp to contain something as well, though? My local init.lsp doesn't seem to run by default.

newdep

#2
Is it called "init.lsp"  in /usr/share/newlisp/init.lsp ?

(because there is a "init.lsp.example" which should be renamed...)

(env "NEWLISPDIR") or is there one in your (env "HOME") ?



yes just put



(constant 'sys-uptime (date-value))

(define (uptime?) (- (date-value) sys-uptime))



inside init.lsp, its read every time a newlisp script is executed..
-- (define? (Cornflakes))

cormullion

#3
I've been looking at the init.lsp facility.



Wouldn't it be better if the file /usr/share/newlisp/init.lsp contained the followed code when it's installed?


(constant (global '$HOME) (or (env "HOME") (env "USERPROFILE") (env "DOCUMENT_ROOT")))
(if $HOME (catch (load (append $HOME "/.init.lsp")) 'error))


That way, all your customizations can be done in your home directory (in ~/.init.lsp) and they're per user too. It seems that the current way requires you to edit the root-owned files /usr/share/newlisp (which is either impossible or needs authorization depending on your status) and also stops it being a multi-user setup...

Lutz

#4
The idea of the current setup is, that there are system wide initializations valid for all users (i.e. certain environment settings) plus settings on a per user basis.



Because of this the code to load a .init.lsp from the users home directory is already contained in the current /usr/share/newlisp/init.lsp.example and gets active as soon as you rename it to /usr/share/newlisp/init.lsp.



In any case installation of newLISP requires the root password (except when  doing a "make install_home" from a self built newLISP).

cormullion

#5
That's mostly true ... But I don't think it's possible to have your own ~/.init.lsp running on a site like nfshost, where the newlisp installation is outside one's control. (Actually, I don't think they have an init.lsp at all.)



But if the default was to look first in /usr/share/newlisp then /usr/local/share/newlisp then ~/ you could have your own init.lsp without having root access...