Page 1 of 1

tip for today: script uptime?

Posted: Fri Apr 11, 2008 7:51 am
by 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:
;; @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

Posted: Fri Apr 11, 2008 8:27 am
by cormullion
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.

Posted: Fri Apr 11, 2008 8:32 am
by newdep
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..

Posted: Fri Apr 11, 2008 2:46 pm
by cormullion
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?

Code: Select all

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

Posted: Fri Apr 11, 2008 4:27 pm
by Lutz
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).

Posted: Fri Apr 11, 2008 4:50 pm
by cormullion
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...