Working with objects
[1/5] from: mat:plothatching at: 19-Jan-2009 16:51
Dudes,
Hope you can shed some light here. Every time I feel bold enough to ask a
question it results in a forehead slapping, so here's hoping :)
Got a script that pulls in some cgi data.
cgidatain: read-cgi
cgidata: construct decode-cgi cgidatain
Groovy. Problem is sometimes we might not get passed all the values we want.
I had been ignoring this... but now it's time to figure out really how to
deal with it. So I looked at object handling more closely.
Seems we can do:
get in cgidata 'digital
This will return 'none' if digital is either set to none in the block or it
doesn't exist. That'll do! Next I run into all the usual issues I have with
rebol such as not understanding how to test for none, is a value, is it
unset? In the end, I just test to see if it equals none, that seems to work.
And because I'm sick to the back teeth of not understanding the exact order
in which I have to sprinkle things in rebol, I'll do the usual thing and
shove brackets around everything until I'm sure it works:
if ((get in cgidata 'digital) = none) [
Print "Digital don't equal nuffin!"
]
That works. Great! Course now there doesn't appear to be any nice way to
easily tack on a named value pair to an object, I see there is in Rebol 3 *
but not for current Rebol... so this is what it looks like I have to do:
if ((get in cgidata 'digital) = none) [
cgidata: make cgidata [digital: "all"]
]
If there's no cgidata/digital set because we didn't get it on the http get
URL request, we remake the cgidata block from the old one and add the path
with our default value. Sweet, it works.
Now, how should I have really done this? And can anyone suggest a reasonably
elegant way to do things based on an object like this with some fallbacks to
defaults?
Cheers!
* I asked to be added to the AltMe Rebol 3 world and got messaged a
username, but no password? I couldn't really see what I could do with that
without a password or am I missing something / being stupid?
--
Regards,
Mat Bettinson
[2/5] from: compkarori::gmail::com at: 19-Jan-2009 7:37
you can use
none? get in cgidata 'digital
and also
find first cgidigital 'analogue
to see if it is in the object.
On Mon, Jan 19, 2009 at 6:51 PM, Mat Bettinson <mat-plothatching.com> wrote:
> Dudes,
> Hope you can shed some light here. Every time I feel bold enough to ask a
> question it results in a forehead slapping, so here's hoping :)
>
> Got a script that pulls in some cgi data.
>
> cgidatain: read-cgi
> cgidata: construct decode-cgi cgidatain
--
Graham Chiu
http://www.synapsedirect.com
Synapse - the use from anywhere EMR.
[3/5] from: dhsunanda:gmai:l at: 19-Jan-2009 8:46
Hi Mat
There are several things that can go wrong when converting CGI
data into an object. I wrote an article about them:
<http://www.rebol.org/art-display-article.r?article=x60w>
And a script that makes most of it much easier:
<http://www.rebol.org/documentation.r?script=safe-cgi-data-read.r>
<http://www.rebol.org/view-script.r?script=safe-cgi-data-read.r>
Sunanda
[4/5] from: henrikmk::gmail::com at: 19-Jan-2009 9:45
On Mon, Jan 19, 2009 at 7:12 AM, Graham Chiu <compkarori-gmail.com> wrote:
If you test for:
in cgidata 'digital
You will either get none or the word 'digital returned. It does not
return the value itself, so it's safe to test like this:
if in cgidata 'digital [blah]
--
Regards,
Henrik Mikael Kristensen
[5/5] from: santilli::gabriele::gmail::com at: 19-Jan-2009 17:57
[Please forward to the ML if this arrives there garbled.]
On Mon, Jan 19, 2009 at 6:51 AM, Mat Bettinson <mat-plothatching.com> wrote:
> cgidatain: read-cgi
> cgidata: construct decode-cgi cgidatain
1) Make a template object with your default values:
template: context [
digital: "all"
; ...
]
2) Use construct/with:
cgidata: construct/with decode-cgi cgidatain template
3) Now, if digital was not specified in the query, the expression:
cgidata/digital
will just be "all".
HTH,
Gabriele.