issue-#27 Adding SET conversion to Strings

Merged to the master branch
User avatar
Josef Templ
Posts: 2047
Joined: Tue Sep 17, 2013 6:50 am

Re: issue-#27 Adding SET conversion to Strings

Post by Josef Templ »

SetToString has been simplified by me after studying and modifying a proposal by luowy.
See the diff in http://redmine.blackboxframework.org/pr ... b332f61767.
It is very readable now, I think.

- Josef
User avatar
Josef Templ
Posts: 2047
Joined: Tue Sep 17, 2013 6:50 am

Re: issue-#27 Adding SET conversion to Strings

Post by Josef Templ »

StringToSet is now also simplified after studying and modifying a proposal by luowy.
See the diff in http://redmine.blackboxframework.org/pr ... trings.odc.
Instead of using the state machine I am using a standard top-down parser approach as usual when parsing structured texts.
There is absolutely no need for a state machine and it is really hard to understand.
I hope I didn't introduce too many bugs. Of course I did lots of tests but there may always be
very special cases...

- Josef
User avatar
DGDanforth
Posts: 1061
Joined: Tue Sep 17, 2013 1:16 am
Location: Palo Alto, California, USA
Contact:

Re: issue-#27 Adding SET conversion to Strings

Post by DGDanforth »

Josef,
I just coded and tested your two routines SetToString and StringToSet.

Testing consisted of generating a random set s0 by sampling 16 times a random integer in the range 0..31 and
including those integers in s0. So approximately 1/2 of s0 is occupied. I converted s0 to a string and then
converted the string back to a set s1. I then checked res and equality s0=s1.
I did that whole process 1,000 times without complaint.

So your code looks good.

-Doug
User avatar
DGDanforth
Posts: 1061
Joined: Tue Sep 17, 2013 1:16 am
Location: Palo Alto, California, USA
Contact:

Re: issue-#27 Adding SET conversion to Strings

Post by DGDanforth »

Josef Templ wrote:> I have only 1.9GB of space on my machine.

Doug, it should be possible to use a USB memory stick.
You get plenty of space for a few dollars and you don't have to
switch to a new machine.

- Josef
Thank you. That is a good suggestion.
User avatar
Josef Templ
Posts: 2047
Joined: Tue Sep 17, 2013 6:50 am

Re: issue-#27 Adding SET conversion to Strings

Post by Josef Templ »

> So your code looks good.

Doug, thanks for the testing.
Did you also take a look at the added documentation in System/Docu/Strings?

I think it is time for voting now.

- Josef
Ivan Denisov
Posts: 1700
Joined: Tue Sep 17, 2013 12:21 am
Location: Russia

Re: issue-#27 Adding SET conversion to Strings

Post by Ivan Denisov »

Now, we can also change TextMappers module:

Code: Select all

	PROCEDURE (VAR f: Formatter) WriteSet* (x: SET), NEW;
		VAR i: INTEGER; str: ARRAY 128 OF CHAR;
	BEGIN
		Strings.SetToString(x, str);
		f.WriteString(str);
		(*
		f.WriteChar("{"); i := MIN(SET);
		WHILE x # {} DO
			IF i IN x THEN f.WriteInt(i); EXCL(x, i);
				IF (i + 2 <= MAX(SET)) & (i+1 IN x) & (i+2 IN x) THEN f.WriteString("..");
					x := x - {i+1, i+2}; INC(i, 3);
					WHILE (i <= MAX(SET)) & (i IN x) DO EXCL(x, i); INC(i) END;
					f.WriteInt(i-1)
				END;
				IF x # {} THEN f.WriteString(", ") END
			END;
			INC(i)
		END;
		f.WriteChar("}")
		*)
	END WriteSet;
Post Reply