newLISP Fan Club

Forum => newLISP newS => Topic started by: Tim Johnson on March 06, 2008, 07:00:54 PM

Title: Testing for Pre-existing symbols in a context
Post by: Tim Johnson on March 06, 2008, 07:00:54 PM
Example:

I have written my own cgi context. It has a number of control

variables (think symbols)

I want to - if necessary customize those symbols on startup.

I have a context method call 'on.

;; Intialize the CGI object
(cgi:on 'cs nil 'placeholder true) ;; assumes that 'cs and 'placholder
                                              ;; are already defined

Inside of the 'on method, a helper function called 'parse-args

intercepts args and processes them two at a time as follows:

(define (parse-args)
 (let((key)(val))
   (dolist (item (explode (args)))
  (set 'key (last(parse(string(first(first item)))":")))
  (set 'val(second(first item)))
  (set (sym key) val))) ;; reset the symbol
 )

As written, I may mistakenly submit a symbol that is not predefined

in the context. I would like to be able to test whether that symbol

is already defined and throw an error if not. I like error messages!

I'd welcome some suggestions on how to proceed.

Thanks

Tim
Title:
Post by: lithper on March 06, 2008, 08:41:24 PM
"symbols"



> (context 'cgi 'xxx 33)

33

> xxx

nil

> cgi:xxx

33

> (symbols cgi)

(cgi:xxx)

>
Title:
Post by: cormullion on March 07, 2008, 01:20:39 AM
Is symbol? useful here?



(symbol? exp)

Evaluates the exp expression and returns true if the value is a symbol; otherwise, it returns nil.
Title:
Post by: Jeff on March 07, 2008, 07:55:58 AM
(context? ctx "symbol")
Title:
Post by: Tim Johnson on March 07, 2008, 08:54:26 AM
Quote from: "Jeff"(context? ctx "symbol")

Hello Jeff:

A quick test suggests that this is what I'm after.

Thanks

Tim