Page 1 of 1

mystery string bug ...

Posted: Mon Aug 21, 2006 5:23 pm
by starseed
I don't understand, what happens here ...

Me being lazy I want a fast way to load a file ni the console, so I created the following, which tries to load a file by:
- converting the given file-name to a string and appending .lsp
- just converting to a string

Code: Select all

(define-macro (do myfile)
  "tries to load the file given as a symbol, tries to append .lsp"
  (println myfile)
  (or 
    (catch (load (println (string myfile ".lsp")))) 
    (catch (load (string myfile)))
    (throw-error (string "file not found: " myfile))))

> (do tools.lsp)
tools.lsp
tools.lsp.lsp

problem accessing file : "tools.lsp.lsp"
I understand, that it can't load tools.lsp.lsp,
but after that it should just try tools.lsp, which seems not to happen ...
and I don't at all understand, where the tools.lsp.lsp in the error message comes from ...

(verson 8.9.6 Mingw)

Ingo

Posted: Mon Aug 21, 2006 6:02 pm
by Lutz
If you want to work on the return value of 'catch' use the following form:

Code: Select all

(catch (......) 'result)
In case of error, 'catch' will now return 'nil'. When using 'catch' for error catching you need the extra parameter symbol which receives either the error message or the result of the evaluated (...) expression.

The form of 'catch' you are using does not trap the error, only returns the result of (...). It is meant for early return from program blocks, functions, loops.

Read the manual entry her:
http://newlisp.org/downloads/newlisp_manual.html#catch

Lutz