1. type test broken

I am feeding a sequence to some code:

data = parse("AbCdEF",{"si",'c'})

global function parse(sequence s, object c)

if sequence(c) then
  str = 0 -- this is executed
end if

if atom(c) 
 then 
  --code -- not executed
 else 
  -- code -- not executed
end if


So why won't the "if atom(c)... else" code execute?

Kat

new topic     » topic index » view message » categorize

2. Re: type test broken

Kat wrote:
> 
> I am feeding a sequence to some code:
> 
> }}}
<eucode>
> data = parse("AbCdEF",{"si",'c'})
> 
> global function parse(sequence s, object c)
> 
> if sequence(c) then
>   str = 0 -- this is executed
> end if
> 
> if atom(c) 
>  then 
>   --code -- not executed
>  else 
>   -- code -- not executed
> end if
> </eucode>
{{{

> 
> So why won't the "if atom(c)... else" code execute?
> 

Could you post the full function (or at least a full demo that exhibits this
behavior)?  I've done stuff like this, and found I overlooked a return or 
something, or had incorrectly nested if statements.

Matt Lewis

new topic     » goto parent     » topic index » view message » categorize

3. Re: type test broken

Kat wrote:
> 
> I am feeding a sequence to some code:
> 
data = parse("AbCdEF",{"si",'c'})

 global function parse(sequence s, object c)
 
if sequence(c) then
  str = 0 -- this is executed
 end if

 if atom(c) 
 then 
  --code -- not executed
 else 
   -- code -- not executed
 end if

> 
> So why won't the "if atom(c)... else" code execute?
> 
> Kat
> 
> 

if "AbCdEF",{"si",'c'} is the actual data you are basing this on then
the "if atom(c)" will fail (since {"si",'c'} is a sequence) but it should at
least _do_ the test (let me guess, this is the program you can't trace? :)

My advice, if you're not being paid for it, sleep on it :) 

Gary

new topic     » goto parent     » topic index » view message » categorize

4. Re: type test broken

On 11 Jul 2005, at 3:49, Matt Lewis wrote:

> 
> 
> posted by: Matt Lewis <matthewwalkerlewis at gmail.com>
> 
> Kat wrote:
> > 
> > I am feeding a sequence to some code:
> > 
> > }}}
<eucode>
> > data = parse("AbCdEF",{"si",'c'})
> > 
> > global function parse(sequence s, object c)
> > 
> > if sequence(c) then
> >   str = 0 -- this is executed
> > end if
> > 
> > if atom(c) 
> >  then 
> >   --code -- not executed
> >  else 
> >   -- code -- not executed
> > end if
> > </eucode>
{{{

> > 
> > So why won't the "if atom(c)... else" code execute?
> > 
> 
> Could you post the full function (or at least a full demo that exhibits this
> behavior)?  I've done stuff like this, and found I overlooked a return or
> something, or had incorrectly nested if statements.

I added the "if sequence(c)" to strtok-v2-1.e while trying to find why calling 
parse() didn't work properly. I called thusly:

include get.e -- for wait_key()
include wildcard.e -- for upper()
include Strtok-v2-2.e
include file.e
with trace

object junk, data, writefile

trace(1)
data = parse("AbCdEF",{"si",'c'})

writefile = open("H:\\DataMinerCode\\minenews\\newgetter-wget\\wget\\tmp2-
parsed.txt","w")

for loop = 1 to length(data) do
  
puts(writefile,data[loop]&"\n====================================
====================================\n")
end for
close(writefile)
--junk = wait_key()


I have since rebooted the machine, no joy. I also tried the interpreter in 
several project directories, in case one of them had been corrupted, no joy. I 
also tried both exw.exe and exw40.exe, no joy.

Kat

new topic     » goto parent     » topic index » view message » categorize

5. Re: type test broken

Hi again Kat,


A guess would be that you're modifying one file and your program
is using another different file.  Check to see if you have other
files that are named the same in your 'include' directories.

include stringstuff.e --Where exactly is this file?  Are there two?
                      --Is my main program reading the right one or
                      --using one from my current directory?

Take care,
Al

And, good luck with your Euphoria programming!

My bumper sticker: "I brake for LED's"

new topic     » goto parent     » topic index » view message » categorize

6. Re: type test broken

Kat wrote:
> 
> 
> I added the "if sequence(c)" to strtok-v2-1.e while trying to find why calling
>
> parse() didn't work properly. I called thusly:
> 
> }}}
<eucode>
> include get.e -- for wait_key()
> include wildcard.e -- for upper()
> include Strtok-v2-2.e
> include file.e
> with trace
> 
> object junk, data, writefile
> 
> trace(1)
> data = parse("AbCdEF",{"si",'c'})
> 
> writefile = open("H:\\DataMinerCode\\minenews\\newgetter-wget\\wget\\tmp2-
> parsed.txt","w")
> 
> for loop = 1 to length(data) do
>   
> puts(writefile,data[loop]&"\n====================================
> ====================================\n")
> end for
> close(writefile)
> --junk = wait_key()
> <font color="#330033"></eucode>
{{{
</font>
> 
> I have since rebooted the machine, no joy. I also tried the interpreter in 
> several project directories, in case one of them had been corrupted, no joy. I
>
> also tried both exw.exe and exw40.exe, no joy.

I only have strtok v2.1 (maybe 2.2 is unreleased, couldn't find any 
reference to it other than this post).  I modified it a bit by adding
the test for sequence (str isn't here, so I just did a "? 0").  I also
reformatted some of the code in the big if block where you test for an
atom.  I think the problem was that the "while" was on the same line
as "else" and the tracer skips right over them.  If you move the while
to its own line, you can see that the while condition is evaluated,
and just skips over it.

I did a dissassembly of the il code using ooeu, and the reason for this
I think is that an else doesn't get a STARTLINE opcode, which is what 
the tracer looks for, and since it's not a new line, the while must not
generate it.  So I think that the code is executing properly, but just
looks like it isn't because of the formatting and the peculiarities with
the tracer.
global function parse(sequence s, object c) -- "object" by kat
integer slen, spt, flag, keep, case
sequence parsed, upperc, uppers
keep = 0
case = 0
upperc = ""
uppers = ""

if sequence(c) then
	? 0
end if

if atom(c) then -- kat
  
  c = {c}
  else 
  
  	while equal(c[1],"k") or equal(c[1],"i") do
         if equal(c[1],"k") then
           keep = 1
           c = c[2..length(c)]
         end if
         if equal(c[1],"i") then
           case = 1
           c = c[2..length(c)]
         end if
    end while
end if -- kat


Matt Lewis

new topic     » goto parent     » topic index » view message » categorize

7. Re: type test broken

On 11 Jul 2005, at 5:31, Matt Lewis wrote:

> 
> 
> posted by: Matt Lewis <matthewwalkerlewis at gmail.com>
> 
> Kat wrote:
> > 
> > 
> > I added the "if sequence(c)" to strtok-v2-1.e while trying to find why
> > calling
> > parse() didn't work properly. I called thusly:
> > 
> > }}}
<eucode>
> > include get.e -- for wait_key()
> > include wildcard.e -- for upper()
> > include Strtok-v2-2.e
> > include file.e
> > with trace
> > 
> > object junk, data, writefile
> > 
> > trace(1)
> > data = parse("AbCdEF",{"si",'c'})
> > 
> > writefile = open("H:\\DataMinerCode\\minenews\\newgetter-wget\\wget\\tmp2-
> > parsed.txt","w")
> > 
> > for loop = 1 to length(data) do
> >   
> > puts(writefile,data[loop]&"\n====================================
> > ====================================\n")
> > end for
> > close(writefile)
> > --junk = wait_key()
> > <font color="#330033"></eucode>
{{{
</font>
> > 
> > I have since rebooted the machine, no joy. I also tried the interpreter in
> > several project directories, in case one of them had been corrupted, no joy.
> > I
> > also tried both exw.exe and exw40.exe, no joy.
> 
> I only have strtok v2.1 (maybe 2.2 is unreleased, couldn't find any 
> reference to it other than this post).  

It *is* unreleased. I found this bug(?) and cannot get past it.

> I modified it a bit by adding
> the test for sequence (str isn't here, so I just did a "? 0").  I also
> reformatted some of the code in the big if block where you test for an
> atom.  I think the problem was that the "while" was on the same line
> as "else" and the tracer skips right over them.  If you move the while
> to its own line, you can see that the while condition is evaluated,
> and just skips over it.

If you watch the variable contents in the trace window, str should have been 
set to 1 in the ..else.. code (see below where i added it). It isn't. Ergo, it
isn't
executing. I'll paste the entire parse code to this email (below), and the code 
which calls parse() again.
 
> I did a dissassembly of the il code using ooeu, and the reason for this
> I think is that an else doesn't get a STARTLINE opcode, which is what 
> the tracer looks for, and since it's not a new line, the while must not
> generate it.  So I think that the code is executing properly, but just
> looks like it isn't because of the formatting and the peculiarities with
> the tracer.
> }}}
<eucode>
> global function parse(sequence s, object c) -- "object" by kat
> integer slen, spt, flag, keep, case
> sequence parsed, upperc, uppers
> keep = 0
> case = 0
> upperc = ""
> uppers = ""
> 
> if sequence(c) then
>  ? 0
> end if
> 
> if atom(c) then -- kat
> 
>   c = {c}
>   else 
>    while equal(c[1],"k") or equal(c[1],"i") do

put this code where it's obvious to be:

else while equal(c[1],"k") or equal(c[1],"i") or equal(c[1],"s")do
  
         if equal(c[1],"s") then
           str = 1
           thestring = c[2]
           lenc = length(thestring)
           c = c[2..length(c)]
         end if
         



>          if equal(c[1],"k") then
>            keep = 1
>            c = c[2..length(c)]
>          end if
>          if equal(c[1],"i") then
>            case = 1
>            c = c[2..length(c)]
>          end if
>     end while
> end if -- kat
> </eucode>
{{{



--Andy Serpas Turbo version 3X faster
-- modified by Kat for case and keep-separator
-- getting modified more by Kat July 11 2005
-- yes, this is a mess, i am trying to add my parses() to parse()
-- and keep backwards compatability

global function parse(sequence s, object c) -- "object" by kat
integer slen, spt, flag, keep, case, str, lenc
sequence parsed, upperc, uppers, thestring, temp

keep = 0
case = 0
str = 0
upperc = ""
uppers = ""
parsed = {}

if sequence(c) then -- i added this *only* because the atom() failed
  str = 0  -- if the trace window stops here, it's a seq
end if  -- if a seq, then the else right below should run too

if atom(c) -- kat
  then 
       c = {c}
       temp = c
  else while equal(c[1],"k") or equal(c[1],"i") or equal(c[1],"s")do
  
         if equal(c[1],"s") then
           str = 1 -- this does NOT happen, watch the variable dump!
           thestring = c[2]
           lenc = length(thestring)
           c = c[2..length(c)]
         end if
         
         if equal(c[1],"k") then
           keep = 1
           c = c[2..length(c)]
         end if
         
         if equal(c[1],"i") then
           case = 1
           c = c[2..length(c)]
         end if
       end while
       
end if -- kat


if str then
  if case 
    then temp = -lenc & find_alls(upper(thestring),upper(s)) & length(s)
    else temp = -lenc & find_alls(thestring,s) & length(s)  
  end if
    
  for loop = 1 to length(temp)-1 do
    parsed &= {s[temp[loop]+lenc+1..temp[loop+1]-1]}
  end for
  
return parsed

end if

if atom(c) -- kat
  then c = {c}
end if
	parsed = {}
	slen = length(s)
	spt = 1
	flag = 0

if case = 0 then
	for i = 1 to slen do
		--if s[i] = c then -- kat
		if find(s[i],c) then
			if flag = 1 then
				parsed = append(parsed,s[spt..i-1])
				if keep then
				  parsed = append(parsed,{s[i]})
				end if
				flag = 0
				spt = i+1
			else
				spt += 1
			end if
		else
			flag = 1
		end if
	end for
	if flag = 1 then
		parsed = append(parsed,s[spt..slen])
	end if
end if

if case = 1 then  -- kat
  upperc = upper(c)
  uppers = upper(s)
	for i = 1 to slen do
		--if s[i] = c then -- kat
		if find(uppers[i],upperc) then
			if flag = 1 then
				parsed = append(parsed,s[spt..i-1])
				if keep then
				  parsed = append(parsed,{s[i]})
				end if
				flag = 0
				spt = i+1
			else
				spt += 1
			end if
		else
			flag = 1
		end if
	end for
	if flag = 1 then
		parsed = append(parsed,s[spt..slen])
	end if
end if

	return parsed
end function

include get.e -- for wait_key()
include wildcard.e -- for upper()
include Strtok-v2-2.e
include file.e
with trace

object junk, data, writefile

trace(1)
data = parse("AbCdEF",{"si",'c'})

writefile = open("H:\\DataMinerCode\\minenews\\newgetter-wget\\wget\\tmp2-
parsed.txt","w")

for loop = 1 to length(data) do
  
puts(writefile,data[loop]&"\n====================================
====================================\n")
end for
close(writefile)
--junk = wait_key()




new topic     » goto parent     » topic index » view message » categorize

8. Re: type test broken

On 11 Jul 2005, at 5:47, Al Getz wrote:

> 
> 
> posted by: Al Getz <Xaxo at aol.com>
> 
> Hi again Kat,
> 
> 
> A guess would be that you're modifying one file and your program
> is using another different file.  Check to see if you have other
> files that are named the same in your 'include' directories.
> 
> include stringstuff.e --Where exactly is this file?  Are there two?
>                       --Is my main program reading the right one or
>                       --using one from my current directory?

I can see the changed code in the Eu trace screen when i run it. There is 
only one edition of the strtok*.2 file.

Kat

new topic     » goto parent     » topic index » view message » categorize

9. Re: type test broken

Kat wrote:
> 
> On 11 Jul 2005, at 5:47, Al Getz wrote:
> 
> > 
> > posted by: Al Getz <Xaxo at aol.com>
> > 
> > Hi again Kat,
> > 
> > 
> > A guess would be that you're modifying one file and your program
> > is using another different file.  Check to see if you have other
> > files that are named the same in your 'include' directories.
> > 
> > include stringstuff.e --Where exactly is this file?  Are there two?
> >                       --Is my main program reading the right one or
> >                       --using one from my current directory?
> 
> I can see the changed code in the Eu trace screen when i run it. There is 
> only one edition of the strtok*.2 file.
> 
> Kat
> 
> 

Hi Kat,

Oh ok, well i ran your code the way you posted it and it worked.
I printed ?1 if the test passed, and ?2 if it failed, and it
printed '2' because it wasnt an atom, so i was looking for
possibilities.


Take care,
Al

And, good luck with your Euphoria programming!

My bumper sticker: "I brake for LED's"

new topic     » goto parent     » topic index » view message » categorize

10. Re: type test broken

Kat wrote:
> 
> If you watch the variable contents in the trace window, str should have been 
> set to 1 in the ..else.. code (see below where i added it). It isn't. Ergo, it
> isn't
> executing. I'll paste the entire parse code to this email (below), and the
> code
> which calls parse() again.

<snip>
  
else while equal(c[1],"k") or equal(c[1],"i") or equal(c[1],"s")do

data = parse("AbCdEF",{"si",'c'})


Here's the problem.  You've either constructed 'c' incorrectly, or your
tests are incorrect, because c[1] = "si".  Perhaps it should be:
else while equal(c[1],"k") or match("i",c[1]) or match("s",c[1]) do


If you move the start of the while loop off of the same line as the else, 
you can see that it does go into the else block, but the while tests fail.

Matt Lewis

new topic     » goto parent     » topic index » view message » categorize

11. Re: type test broken

On 11 Jul 2005, at 9:49, Matt Lewis wrote:

> 
> 
> posted by: Matt Lewis <matthewwalkerlewis at gmail.com>
> 
> Kat wrote:
> > 
> > If you watch the variable contents in the trace window, str should have been
> > set to 1 in the ..else.. code (see below where i added it). It isn't. Ergo,
> > it
> > isn't executing. I'll paste the entire parse code to this email (below), and
> > the code which calls parse() again.
> 
> <snip>
> 
> }}}
<eucode>
>    else while equal(c[1],"k") or equal(c[1],"i") or equal(c[1],"s")do
> 
> data = parse("AbCdEF",{"si",'c'})
> </eucode>
{{{

> 
> Here's the problem.  You've either constructed 'c' incorrectly, or your
> tests are incorrect, because c[1] = "si".  Perhaps it should be:
> }}}
<eucode>
>    else while equal(c[1],"k") or match("i",c[1]) or match("s",c[1]) do
> </eucode>
{{{

> 
> If you move the start of the while loop off of the same line as the else, 
> you can see that it does go into the else block, but the while tests fail.

Yes, i noticed that this morning too. It's another case of compounding the 
error before submitting the question here. I'm sorry.

Kat
looking sheepish.

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu