Page 2 of 2

Re: issue-#27 Adding SET conversion to Strings

Posted: Mon Feb 02, 2015 1:12 pm
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

Re: issue-#27 Adding SET conversion to Strings

Posted: Tue Feb 03, 2015 12:25 pm
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

Re: issue-#27 Adding SET conversion to Strings

Posted: Wed Feb 04, 2015 8:21 am
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

Re: issue-#27 Adding SET conversion to Strings

Posted: Wed Feb 04, 2015 8:27 am
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.

Re: issue-#27 Adding SET conversion to Strings

Posted: Sun Feb 08, 2015 11:11 am
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

Re: issue-#27 Adding SET conversion to Strings

Posted: Sun Feb 08, 2015 12:18 pm
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;