Re: Find 3: The Reckoning

new topic     » goto parent     » topic index » view thread      » older message » newer message

------=_NextPart_000_014A_01C04234.2004EC20
        charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Ok Thomas, I'll bite.

------
Derek Parnell
Melbourne, Australia
(Vote [1] The Cheshire Cat for Internet Mascot)


  include get.e
  sequence names,curname
  object input
  integer location
  atom wn
  wn=3Drand(3)
  names =3D{"bob","them","worms"}
  curname=3Dnames[wn]
  printf(1,"curname: %s\n",{curname})

  input=3Dgets(0)
  ? curname
  puts(1,"\n")
  ? input
  location =3D find(input[1],names[2])
This previous line is saying "Find where the first character of input =
inside of the second sequence of names".  Is this what you are really =
trying to find out?
I suspect you are trying to find out if "input" is one of the three =
possible names. If that is so, try this instead...
  if sequence(input) then
      -- Strip off the trailing newline char.
      input =3D input[1 .. length(input) - 1]
      -- convert to lowercase.
      input =3D lower(input)
      -- See if the input sequence is one of the sequences in names.
      location =3D find(input, names)
      -- "location" should equal 0, 1, 2, or 3 now.
  else
      -- End-Of-File (Ctrl-Z) entered.
      location =3D 0
  end if       =20


  puts(1,"\n")
  ? location


      The "location" variable only gives a correct number if "them" is =
used.=20
And what is the correct number? What were you expecting to see?
  Nothing else. I've looked at all the documentation I've got and either =
I am quite blind or, I just haven't found my solution. Anywho, if you =
could solve this problem, I'd be most grateful....

I suspect you are confused by the find() function. It takes two =
parameters, the first can be an atom or a sequence but the second must =
be a sequence. It then scans each element in the second parameter to see =
if it equals the first parameter. If so, it returns the number of the =
element in the second parmeter that equalled the first parameter.

This means that if the first parameter is a sequence, as is your case =
here, then each of the elements in the second parmeter should be =
sequences too. Also, this is what you have coded for names. However, in =
your coding of find() you used input[1] which is not a sequence but the =
first character of input. It is a single character - an atom. Also, you =
coded the second parameter as names[2] which is a sequence if characters =
- namely "them" . Thus, find() went looking through the characters ''t', =
'h', 'e', and 'm' to see if the first character of input equalled any.

This would mean that location would be non-zero, 1 to 4, for any input =
that begun with 't', 'h', 'e', or 'm'.

  Das Svendanya
  Thomas


  PS. This should  be the last one.........
Yeah, sure Thomas.=20

------=_NextPart_000_014A_01C04234.2004EC20
        charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 5.50.4207.2601" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV dir=3Dltr style=3D"FONT: 10pt arial"><FONT face=3DArial size=3D2>Ok =
Thomas, I'll=20
bite.</FONT></DIV>
<DIV dir=3Dltr style=3D"FONT: 10pt arial"><FONT face=3DArial=20
size=3D2></FONT>&nbsp;</DIV>
<DIV dir=3Dltr style=3D"FONT: 10pt arial">------<BR>Derek =
Parnell<BR>Melbourne,=20
Australia<BR>(Vote [1] The Cheshire Cat for Internet Mascot)<BR></DIV>
<BLOCKQUOTE dir=3Dltr=20
style=3D"PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; =
BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
  <DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
  <DIV><FONT face=3DArial color=3D#000080 size=3D2>include =
get.e<BR>sequence=20
  names,curname<BR>object input<BR>integer location<BR>atom=20
  wn<BR>wn=3Drand(3)<BR>names=20
  =3D{"bob","them","worms"}<BR>curname=3Dnames[wn]<BR>printf(1,"curname: =

  %s\n",{curname})</FONT></DIV>
  <DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
  <DIV><FONT face=3DArial color=3D#000080 size=3D2>input=3Dgets(0)<BR>?=20
  curname<BR>puts(1,"\n")<BR>? input</FONT></DIV>
  <DIV><FONT face=3DArial size=3D2>
  <DIV><FONT face=3DArial color=3D#000080 size=3D2>location =3D=20
  find(input[1],names[2])</FONT></DIV></FONT></DIV></BLOCKQUOTE>
<DIV dir=3Dltr><FONT face=3DArial size=3D2>This&nbsp;previous line is =
saying "Find=20
where the first character of input inside of the second sequence of=20
names".&nbsp; Is this what you are really trying to find =
out?</FONT></DIV>
<DIV dir=3Dltr><FONT face=3DArial size=3D2>I suspect you are trying to =
find out if=20
"input" is one of the three possible names. If that is so, try this=20
instead...</FONT></DIV>
<BLOCKQUOTE dir=3Dltr style=3D"MARGIN-RIGHT: 0px">
  <DIV dir=3Dltr><STRONG><FONT size=3D2>if sequence(input)=20
then</FONT></STRONG></DIV>
  <DIV dir=3Dltr><STRONG><FONT size=3D2>&nbsp;&nbsp;&nbsp; -- Strip off =
the trailing=20
  newline char.</FONT></STRONG></DIV>
  <DIV dir=3Dltr><STRONG><FONT size=3D2>&nbsp;&nbsp;&nbsp; input =3D =
input[1 ..=20
  length(input) - 1]</FONT></STRONG></DIV>
  <DIV dir=3Dltr><STRONG><FONT size=3D2>&nbsp;&nbsp;&nbsp; -- convert to =

  lowercase.</FONT></STRONG></DIV>
  <DIV dir=3Dltr><STRONG><FONT size=3D2>&nbsp;&nbsp;&nbsp; input =3D=20
  lower(input)</FONT></STRONG></DIV>
  <DIV dir=3Dltr><STRONG><FONT size=3D2>&nbsp;&nbsp;&nbsp; -- See if the =
input=20
  sequence is one of the sequences in names.</FONT></STRONG></DIV>
  <DIV dir=3Dltr><STRONG><FONT size=3D2>&nbsp;&nbsp;&nbsp; location =3D =
find(input,=20
  names)</FONT></STRONG></DIV>
  <DIV dir=3Dltr><STRONG><FONT size=3D2>&nbsp;&nbsp;&nbsp; -- "location" =
should=20
  equal 0, 1, 2, or 3 now.</FONT></STRONG></DIV>
  <DIV dir=3Dltr><STRONG><FONT size=3D2>else</FONT></STRONG></DIV>
  <DIV dir=3Dltr><STRONG><FONT size=3D2>&nbsp;&nbsp;&nbsp; -- =
End-Of-File (Ctrl-Z)=20
  entered.</FONT></STRONG></DIV>
  <DIV dir=3Dltr><FONT size=3D2><STRONG>&nbsp;&nbsp;&nbsp; location =3D=20
  0</STRONG></FONT></DIV>
  <DIV dir=3Dltr><FONT size=3D2><STRONG>end if</STRONG><FONT=20
  face=3DArial>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
</FONT></FONT></DIV>
  <DIV dir=3Dltr><STRONG><FONT =
<BLOCKQUOTE dir=3Dltr=20
style=3D"PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; =
BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
  <DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
  <DIV><FONT face=3DArial color=3D#000080 size=3D2>puts(1,"\n")<BR>?=20
  location</FONT></DIV>
  <DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
  <DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
  <DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; The "location" =
variable only=20
  gives a correct number if "them" is used. </FONT></DIV></BLOCKQUOTE>
<DIV dir=3Dltr><FONT face=3DArial size=3D2>And what is the =
<STRONG>correct</STRONG>=20
number? What were you expecting to see?</FONT></DIV>
<BLOCKQUOTE dir=3Dltr=20
style=3D"PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; =
BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
  <DIV><FONT face=3DArial size=3D2>Nothing else. I've looked at all the=20
  documentation I've got and either I am quite blind or, I just haven't =
found my=20
  solution. Anywho, if you could solve this problem, I'd be most=20
  grateful....</FONT></DIV>
  <DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV></BLOCKQUOTE>
<DIV dir=3Dltr><FONT face=3DArial size=3D2>I suspect you are confused by =

the&nbsp;<STRONG>find()</STRONG> function. It takes two parameters, the =
first=20
can be an atom or a sequence but the second must be a sequence. It then =
scans=20
each element in the second parameter to see if it equals the first =
parameter. If=20
so, it returns the number of the element in the second parmeter that =
equalled=20
the first parameter.</FONT></DIV>
<DIV dir=3Dltr><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV dir=3Dltr><FONT face=3DArial size=3D2>This means that if the first =
parameter is a=20
sequence, as is your case here, then each of the elements in the second =
parmeter=20
should be sequences too. Also, this is what you have coded for =
<EM>names</EM>.=20
However, in your coding of <STRONG>find()</STRONG> you used =
<EM>input[1]</EM>=20
which is <STRONG>not</STRONG> a sequence but the first character of =
input. It is=20
a single character -&nbsp;an atom. Also, you coded the second parameter =
as=20
<EM>names[2]</EM> which is a sequence if characters - namely =
<EM>"them"</EM> .=20
Thus, <STRONG>find()</STRONG> went looking through the characters ''t', =
'h',=20
'e', and 'm' to see if the first character of <EM>input</EM> equalled=20
any.</FONT></DIV>
<DIV dir=3Dltr><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV dir=3Dltr><FONT face=3DArial size=3D2>This would mean that =
<EM>location</EM>=20
would be non-zero, 1 to 4,&nbsp;for any input that begun with 't', 'h', =
'e', or=20
'm'.</FONT></DIV>
<BLOCKQUOTE dir=3Dltr=20
style=3D"PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; =
BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
  <DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
  <DIV><FONT face=3DArial size=3D2>Das Svendanya</FONT></DIV>
  <DIV><FONT face=3DArial size=3D2>Thomas</FONT></DIV>
  <DIV>&nbsp;</DIV>
  <DIV>&nbsp;</DIV>
  <DIV><FONT face=3DArial size=3D2>PS. This <EM>should</EM>&nbsp; be the =
last=20
  one.........</FONT></DIV></BLOCKQUOTE>
<DIV dir=3Dltr><FONT face=3DArial size=3D2>Yeah, sure&nbsp;Thomas.=20

------=_NextPart_000_014A_01C04234.2004EC20--

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu