1. Restarting the compare() thread. Was: Re: Say hello to the
On Wed, 23 Sep 1998, Matt Z Nunyabidness wrote:
> if not compare(action,"SAVE") then
*Shudder*
I like compare, but not this counter-intuitive usage...
I prefer to use compare(a,b)=0 or declare a func (deep breaths as Carl
launches into another example coding):
function equal(object a, object b)
-- Compare anything with anything else.
-- Return 1 if they're *exactly* alike.
return compare({a},{b})=0
end function
--Can now do things like (without risk of compare() error):
include get.e
sequence bar
integer foo, file
-- There's even the possibility of making a safe_open() routine from the
-- next 5 lines:
file = open("foobar.baz", "r")
if file < 3 then
-- call error routine
-- possibly abort(0)
end if
foo = 42
bar = get(file)
if not equal(bar, {}) then
if equal({foo}, bar[1]) then
-- do something
else
-- do something else
end if
end if
close(file)
Happy Coding,
Carl
--
Carl R White
E-mail...: cyrek- at -bigfoot.com -- Remove the hyphens before mailing. Ta :)
Url......: http://www.bigfoot.com/~cyrek/
"Ykk rnyllaqur rgiokc cea nyemdok ymc giququezka caysgr." - B.Q.Vgesa
2. Re: Restarting the compare() thread. Was: Re: Say hello to the
Carl R. White wrote:
> function equal(object a, object b)
> -- Compare anything with anything else.
> -- Return 1 if they're *exactly* alike.
> return compare({a},{b})=0
> end function
wot's the difference between the above:
return compare({a},{b})=0
and the following:
return compare(a,b)=0
?????
personally, i find the latter easier to read.
but more than that, the first method will
convert an atom to a sequence, and that might
not be what the coder desires, and if you
read library.doc about this it says that
atoms are considered less than sequences.
so changing an atom to a sequence would
negate that check and potentially create
a result that isn't what the coder desires.
or am I wrong here?
(this is why i ask what the difference is,
and no, i'm not answering my own question
here, even tho it seems like it :> )
3. Re: Restarting the compare() thread. Was: Re: Say hello to the
I think my mailer munged Hawke's message so it may look a little
different...
On Wed, 23 Sep 1998, Hawke wrote:
> wot's the difference between the above:
> return compare({a},{b})=0
> and the following:
> return compare(a,b)=0
> Personally, i find the latter easier to read. but more than that, the
> first method will convert an atom to a sequence, and that might not be
> what the coder desires, and if you read library.doc about this it says
> that atoms are considered less than sequences. so changing an atom to a
> sequence would negate that check and potentially create a result that
> isn't what the coder desires. or am I wrong here?
Good point, so let's work through it:
Using "compare({a},{b})=0" adds an extra layer of sequence to *both*
parameters and therefore, relative to one another, the same.
relationships hold. e.g.:
{2,3} is to 2 as -- seq ; atom
{{2,3}} is to {2} as -- seq in seq ; atom in seq
{{{2,3}}} is to {{2}} etc. -- seq in seq, in seq; atom in seq, in seq
i.e. they all have the same "common denominator" of "seq, atom". Do you
get where I'm coming from?
I like discussions where I at least *think* I'm right, :)
Carl
--
Carl R White
E-mail...: cyrek- at -bigfoot.com -- Remove the hyphens before mailing. Ta :)
Url......: http://www.bigfoot.com/~cyrek/
"Ykk rnyllaqur rgiokc cea nyemdok ymc giququezka caysgr." - B.Q.Vgesa
4. Re: Restarting the compare() thread. Was: Re: Say hello to the
Carl R. White wrote:
> I think my mailer munged
munged!
ya jus have a warm, gooey feeling all over when
you hear that word!
<snip>
> Good point, so let's work through it:
thanks. let's.
>Using "compare({a},{b})=0" adds an extra layer of
>sequence to *both* parameters and therefore,
>relative to one another, the same.
>get where I'm coming from?
>I like discussions where I at least *think* I'm right, :)
quite right. indeed. sometimes it helps to sit and
work all the way thru it... i am illuminated :)
query: which do you think reads better tho?
> return compare({a},{b})=0
> return compare(a,b)=0
(not that it *truly* matters...)
--Hawke'