Mombu the Programming Forum

Go Back   Mombu the Programming Forum > Programming > Weak formal methods ?
User Name
Password
REGISTER NOW! Mark Forums Read




Reply
1 31st October 14:16
External User
 
Posts: 1
Default Weak formal methods ?



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.
  Reply With Quote


 


2 31st October 14:16
cbfalconer
External User
 
Posts: 1
Default Weak formal methods ?



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
  Reply With Quote
3 31st October 14:16
xcriber51
External User
 
Posts: 1
Default Weak formal methods ?


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/...p.lang.oberon/
More information at http://www.talkaboutprogramming.com/faq.html
  Reply With Quote
4 31st October 14:16
xcriber51
External User
 
Posts: 1
Default Weak formal methods ?


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/...p.lang.oberon/
More information at http://www.talkaboutprogramming.com/faq.html
  Reply With Quote
5 31st October 14:16
External User
 
Posts: 1
Default Weak formal methods ?


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 ?
  Reply With Quote
6 31st October 18:56
External User
 
Posts: 1
Default Weak formal methods ?


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.
  Reply With Quote
7 31st October 18:57
cbfalconer
External User
 
Posts: 1
Default Weak formal methods ?


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
  Reply With Quote
8 31st October 18:57
External User
 
Posts: 1
Default Weak formal methods ?


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 ?
  Reply With Quote


 


Reply


Thread Tools
Display Modes




666