Discussion:
Weak formal methods ?
(too old to reply)
p***@gmail
2007-10-29 01:35:38 UTC
Permalink
First an analogy:
when first small scale integrated circuits came on the market
experimenters built digital circuits by busking since they didn't
yet know how to 'read the score'. One used an intuitive
designing method to chose various combinations and
configuratins of gates to acheive the desired result.

Later, simple tools like Karnaugh maps and equations to
get cannonical forms ...etc. were use to replace the art
with some science.
--------
It seems to me that the pre & post conditions advocated
eg. by Eiffel provide a type of weak formal method for
software design ?

Occasionally, like now, I want to write a small routine to:
FOR StartLine TO EndLine DO
RemoveMultipleConsecutiveSpaces;
I.e. remove the extra spaces -- which I remember WS
could insert for text to fill the line nicely.

I'm too old & tired to fire up the attention and concentration
to do this without many iterations, and expect to just
modify a sample out of a library of examples.

Idealy such a library of example sources would include the
pre & post conditions like Eiffel or Oberon.

Q - are there online lists of examples for such trivial tasks,
perhaps eg. as part of Eiffel tutors ?

Thanks for any feedback,

== Chris Glur.
CBFalconer
2007-10-29 05:08:11 UTC
Permalink
Post by p***@gmail
when first small scale integrated circuits came on the market
experimenters built digital circuits by busking since they
didn't yet know how to 'read the score'. One used an intuitive
designing method to chose various combinations and
configuratins of gates to acheive the desired result.
Later, simple tools like Karnaugh maps and equations to get
cannonical forms ...etc. were use to replace the art with some
science.
FYI Karnaugh maps, logical equations etc. were in common use back
in the 1930s, and date back much earlier than that. Telephone
systems, using relays, required lots of digital knowledge.
--
Chuck F (cbfalconer at maineline dot net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net>
--
Posted via a free Usenet account from http://www.teranews.com
Xcriber51
2007-10-29 12:43:00 UTC
Permalink
Hi

Don't know what pre- and post-conditions you want to assert for this
routine (whether it contains consecutive spaces? By the time you find that
you're already halfway into the routine), but here's what I came up with
(if I didn't misunderstand what you want as output). This I coded using
BlackBox:

PROCEDURE RemoveExtraSpaces*(VAR s, result: ARRAY OF CHAR);
VAR i, k, pos: INTEGER;
BEGIN
s := s+' ';
i := 0; Strings.Find(s, ' ', i, pos);

k := 0;

WHILE pos # -1 DO
IF pos-i > 1 THEN
WHILE i <= pos DO result[k] := s[i]; INC(k); INC(i) END ;
END ;
i := pos+1; Strings.Find(s, ' ', i, pos);
END ;

result[k] := 0X;

END RemoveExtraSpaces;

It only checks the difference between two constantly updated indeces, one
hunting for the next space while the other trailing it, and if their
difference is more than one, copies what is between them.

Hope it does the job.


-- Ken

--
Message posted using http://www.talkaboutprogramming.com/group/comp.lang.oberon/
More information at http://www.talkaboutprogramming.com/faq.html
Xcriber51
2007-10-29 17:51:21 UTC
Permalink
The previous version is a bit confused and inefficient. It traverses the
string twice: once when hunting for spaces in the string with the
"Strings.Find" call, and a second time when copying a portion of it.
Here's a simpler, a more primitive but hopefully clearer version.

PROCEDURE RemoveExtraSpaces2*(VAR s, result: ARRAY OF CHAR);
VAR i,j,k: INTEGER;
ch: CHAR;
BEGIN
j := -1; k := 0;
FOR i := 0 TO LEN(s$) DO
ch := s[i];
IF ch # ' ' THEN
result[k] := ch; INC(k)
ELSE
IF (i-j) > 1 THEN result[k] := ch; INC(k) END ;
j := i
END ;
END ;

DEC(k);
IF result[k-1] = ' ' THEN DEC(k) END ;

result[k] := 0X;

END RemoveExtraSpaces2;

The last part looks like thrashing about a bit, but the trailing spaces
are tricky and I didn't want to make a call to the "Trim" function.


-- Ken


--
Message posted using http://www.talkaboutprogramming.com/group/comp.lang.oberon/
More information at http://www.talkaboutprogramming.com/faq.html
p***@gmail
2007-10-30 12:23:32 UTC
Permalink
Post by p***@gmail
FOR StartLine TO EndLine DO
RemoveMultipleConsecutiveSpaces;
I.e. remove the extra spaces -- which I remember WS
could insert for text to fill the line nicely.
The STRING class has some routines that I guess will be
helpful here. See http://www.gobosoft.com/eiffel/nice/elks01/string.html
feature -- Access
...
feature -- Removal
...
If this requires too many intuitions, so to speak, you can also get
Lex style parsing from that place, and probably REs with replacements.
Thanks ! That's excellent. I'd like the implementation code too,
although that's probably too tied to the other Eiffel classes to be
conveniently transformed to Oberon source.

== Chris Glur.

PS. why doesn't N-O's String.Mod have an 'Insert' PROC ?

Continue reading on narkive:
Loading...