Hey all....
Fooling around, getting comfortable with newLISP! Currently learning to load modules; trap load errors; checking for existence of files, etc. I cobbled together the following:
(define (load_mod x)
(if (file? (append (env "NEWLISPDIR") "/modules/" x)) (print "Loading module: " x)
(throw-error "module does not exist")
)
)
So, obviously, I'm first checking whether or not the required file "x", exists. If it does, it will get loaded (I have only a debug msg. at the moment).
Is there a way to absolutely tell that the file did get loaded?
Should "load_mod" be called from within a "catch", e.g.
(catch (load_mod "cgi.lsp")) ?
You might be able to get away with something as simple as this:
(define (load-module x)
(set 'module (append (env "NEWLISPDIR") "/modules/" x))
(catch (load module) 'error))
(load-module "cgi.lsp")
which returns true or nil. If nil, you could do something with the error message stored in 'error.
(unless (load-module "cg.lsp")
(println "sorry dude: " error (exit)))
Cool!
I have to admit that this "catch-throw" thing is throwing me for a loop. I'll just have to study some more code.
Thanks for the input.