Path: utzoo!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!sol.ctr.columbia.edu!bronze!copper!raja From: raja@copper.ucs.indiana.edu (Raja Sooriamurthi) Newsgroups: comp.lang.scheme Subject: Jensen's device [Was: How to pass parameter by reference in scheme?] Message-ID: Date: 4 Mar 91 12:12:43 GMT References: <9103040333.AA11169@cymbal.reasoning.com.> Sender: news@bronze.ucs.indiana.edu (USENET News System) Organization: Indiana University Lines: 44 gyro@cymbal.reasoning.COM (Scott Layson Burson) writes: > This is not quite passing a variable by reference. It is closer to > Algol 60's call-by-name, and mimics some of its implementations. If > you use this pervasively, you will notice subtle differences with > passing parameters by reference (e.g. Jensen's device). >What is Jensen's device? This sounds interesting. Jensen's device is a technique to parameterize procedures using call-by-name parameter passing. The below Algol 60 code [from Horowitz's book] is an example real procedure sigma (x, j, n); value n; real x, integer j, n; begin real s; s := 0; for j := 1 step 1 until n do s := s + x; sigma := s end By default everything is passed by name in Algol 60 and an explicit declaration is needed for call-by-value (as in value n) sigma(A(i), i, 10) returns the sum of the 1st 10 elements in A A(1)+A(2) ... A(10) The sum of squares of elements as well as the dot product of two vectors could be obtained by: sigma (A(i)*A(i), i, 10) and sigma (A(i)*B(i), i, 10) While Jensen's device was an illustration of how procedures could be parameterized, I feel Scheme's 1st class procedures offer a better mechanism for parameterization. - Raja --- Raja Sooriamurthi | Computer Science Department raja@cs.indiana.edu | Indiana University