Re: [BLACKBOX] RECORDs and ARRAYs

From: [at]} <Chris>
Date: Mon, 16 Mar 2009 15:02:41 +1030

----boundary-LibPST-iamunique-1057675372_-_-
Content-type: text/plain

Doug,

Maybe I'm missing something but why do you want to use a method to process
the array rather than a procedure?

Why not:

  PROCEDURE Norm (IN x: ARRAY): REAL;
    VAR i: INTEGER; d2, norm: REAL;
  BEGIN
    FOR i := 0 TO LEN(r.x)-1 DO d2 := d2 + r.x[i]*r.x[i] END;
    norm := Math.Sqrt(d2);
    RETURN norm
  END Norm;
        
So that for
  
  VAR
    x: Array;
    norm: REAL;

One would call
        
  norm := Norm(x);

--
Chris Burrows
CFB Software
Armaide: ARM Oberon-07 Development System for Windows
http://www.cfbsoftware.com/armaide
________________________________
	From: BlackBox [mailto:BLACKBOX{([at]})nowhere.xyDouglas G. Danforth
	Sent: Monday, 16 March 2009 2:25 PM
	To: BLACKBOX{([at]})nowhere.xy	Subject: [BLACKBOX] RECORDs and ARRAYs
	
	
	This is a grumble.
	If you have a good suggestion then I would like to hear it.
	
	Why do I have to wrap arrays in records just so I can have methods
	that operate on the arrays?  Why can't I have methods for arrays?
	
	Here is what is currently necessary to get a method for an array
	    TYPE
	       Array = POINTER TO ARRAY OF REAL;
	       ArrayRec = POINTER TO RECORD (x: Array) END;
	
	    PROCEDURE (r: ArrayRec) Norm (): REAL;
	       VAR i: INTEGER; d2, norm: REAL;
	    BEGIN
	       FOR i := 0 TO LEN(r.x)-1 DO d2 := d2 + r.x[i]*r.x[i] END;
	       norm := Math.Sqrt(d2);
	       RETURN norm
	    END Norm;
	
	Here is what I would rather like to do
	
	    PROCEDURE (x: Array) Norm (): REAL;
	       VAR i: INTEGER; d2, norm: REAL;
	    BEGIN
	       FOR i := 0 TO LEN(x)-1 DO d2 := d2 + x[i]*x[i] END;
	       norm := Math.Sqrt(d2);
	       RETURN norm
	    END Norm;
	
	So that for
	    VAR
	       r:   ArrayRec;
	       x:   Array;
	       norm:   REAL;
	One would call
	
	    norm := x.Norm();
	rather than
	    norm := r.Norm();
	
	With array methods the code is more efficient (less dereferencing)
and cleaner.
	
	Now what does this break?  Why wasn't this done?  Where is the error
in my thoughts?
	
	-Doug Danforth
	
	
	---- To unsubscribe, send a message with body "SIGNOFF BLACKBOX" to
LISTSERV{([at]})nowhere.xy----
To unsubscribe, send a message with body "SIGNOFF BLACKBOX" to LISTSERV{([at]})nowhere.xy----boundary-LibPST-iamunique-1057675372_-_-
Content-type: application/rtf
Content-transfer-encoding: base64
Content-Disposition: attachment; filename="rtf-body.rtf"
e1xydGYxXGFuc2lcYW5zaWNwZzEyNTJcZnJvbXRleHQgXGRlZmYwe1xmb250dGJsDQp7XGYwXGZz
d2lzcyBBcmlhbDt9DQp7XGYxXGZtb2Rlcm4gQ291cmllciBOZXc7fQ0Ke1xmMlxmbmlsXGZjaGFy
c2V0MiBTeW1ib2w7fQ0Ke1xmM1xmbW9kZXJuXGZjaGFyc2V0MCBDb3VyaWVyIE5ldzt9fQ0Ke1xj
b2xvcnRibFxyZWQwXGdyZWVuMFxibHVlMDtccmVkMFxncmVlbjBcYmx1ZTI1NTt9DQpcdWMxXHBh
cmRccGxhaW5cZGVmdGFiMzYwIFxmMFxmczIwIERvdWcsXHBhcg0KXHBhcg0KTWF5YmUgSSdtIG1p
c3Npbmcgc29tZXRoaW5nIGJ1dCB3aHkgZG8geW91IHdhbnQgdG8gdXNlIGEgbWV0aG9kIHRvIHBy
b2Nlc3NccGFyDQp0aGUgYXJyYXkgcmF0aGVyIHRoYW4gYSBwcm9jZWR1cmU/IFxwYXINClxwYXIN
CldoeSBub3Q6XHBhcg0KXHBhcg0KICBQUk9DRURVUkUgTm9ybSAoSU4geDogQVJSQVkpOiBSRUFM
O1xwYXINCiAgICBWQVIgaTogSU5URUdFUjsgZDIsIG5vcm06IFJFQUw7XHBhcg0KICBCRUdJTlxw
YXINCiAgICBGT1IgaSA6PSAwIFRPIExFTihyLngpLTEgRE8gZDIgOj0gZDIgKyByLnhbaV0qci54
W2ld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FDS0JPWCIgdG9ccGFy
DQpMSVNUU0VSVkBMSVNUUy5PQkVST04uQ0hccGFyDQpccGFyDQpccGFyDQotLS0tXHBhcg0KVG8g
dW5zdWJzY3JpYmUsIHNlbmQgYSBtZXNzYWdlIHdpdGggYm9keSAiU0lHTk9GRiBCTEFDS0JPWCIg
dG8gTElTVFNFUlZATElTVFMuT0JFfX0AZ1hIQmhjZzBLWA==
----boundary-LibPST-iamunique-1057675372_-_---
Received on Mon Mar 16 2009 - 05:32:41 UTC

This archive was generated by hypermail 2.3.0 : Thu Sep 26 2013 - 06:30:49 UTC