tip for today: script uptime?

Featuring the Dragonfly web framework
Locked
newdep
Posts: 2038
Joined: Mon Feb 23, 2004 7:40 pm
Location: Netherlands

tip for today: script uptime?

Post 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
-- (define? (Cornflakes))

cormullion
Posts: 2038
Joined: Tue Nov 29, 2005 8:28 pm
Location: latiitude 50N longitude 3W
Contact:

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

newdep
Posts: 2038
Joined: Mon Feb 23, 2004 7:40 pm
Location: Netherlands

Post 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..
-- (define? (Cornflakes))

cormullion
Posts: 2038
Joined: Tue Nov 29, 2005 8:28 pm
Location: latiitude 50N longitude 3W
Contact:

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

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Post 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).

cormullion
Posts: 2038
Joined: Tue Nov 29, 2005 8:28 pm
Location: latiitude 50N longitude 3W
Contact:

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

Locked