Testing for Pre-existing symbols in a context

Notices and updates
Locked
Tim Johnson
Posts: 253
Joined: Thu Oct 07, 2004 7:21 pm
Location: Palmer Alaska USA

Testing for Pre-existing symbols in a context

Post by Tim Johnson »

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.

Code: Select all

;; 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:

Code: Select all

(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

lithper
Posts: 39
Joined: Sun Feb 24, 2008 12:58 am
Location: USA

Post by lithper »

"symbols"

> (context 'cgi 'xxx 33)
33
> xxx
nil
> cgi:xxx
33
> (symbols cgi)
(cgi:xxx)
>

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

Post by cormullion »

Is symbol? useful here?

(symbol? exp)
Evaluates the exp expression and returns true if the value is a symbol; otherwise, it returns nil.

Jeff
Posts: 604
Joined: Sat Apr 07, 2007 2:23 pm
Location: Ohio
Contact:

Post by Jeff »

(context? ctx "symbol")
Jeff
=====
Old programmers don't die. They just parse on...

Artful code

Tim Johnson
Posts: 253
Joined: Thu Oct 07, 2004 7:21 pm
Location: Palmer Alaska USA

Post by Tim Johnson »

Jeff wrote:(context? ctx "symbol")
Hello Jeff:
A quick test suggests that this is what I'm after.
Thanks
Tim

Locked