lilypond-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: "procedure" vs. "function"


From: J Martin Rushton
Subject: Re: "procedure" vs. "function"
Date: Sat, 18 Apr 2015 21:51:40 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.6.0

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1



On 18/04/15 21:28, PMA wrote:
> J Martin Rushton wrote:
> 
> 
<snip>
> 
> FORTRAN also insists on the distinction (at least officially).  In 
> FORTRAN you CALL procedures as a single statement whereas you
> simply use functions in an expression.  If you try to mix them the
> compiler _ought_ to throw the syntax out.  Likewise BASIC
> distinguishes between GOSUB and invoking a function in an
> expression.
> 
> Consider writing a procedure to perform a task.  If this is invoked
> as a function then what is the return value?  It might be anything
> that was left in the register used to pass the value back; worse,
> if returning by reference then you could be interpreting random
> data as an address!  Modern compilers often trap this by zeroing
> the return value, but you can't rely on it.
> 
> You also need to keep in mind that the syntax checking of 2&  3
> GLs was not as extensive as modern languages like C/C++.  Pascal,
> in particular, was designed as a single pass language so that cards
> or tape could be read in, passed sequentially through the compiler
> and the object code stored to tape.  In the 1970s even mainframes
> often only had 128 KiB of memory.  Saving a few machine
> instructions may seem trivial today, but major programs were often
> only kibibytes in length in the 1960s.
>> 
>> _______________________________________________ lilypond-user
>> mailing list address@hidden 
>> https://lists.gnu.org/mailman/listinfo/lilypond-user
> Martin,
> 
> Thank you for this!   (And obviously after 40+ years, I have
> forgotten my BASIC.)
> 
> PMA

Getting a bit OT, but I've just had a quick look in my books.  Ada and
PL/1 also make the distinction, the former is possibly slightly
surprising given its object-orientated pretensions.  COBOL is
fascinating though, it has procedures, subprograms but no functions.
Procedures are unparametised blocks of code within the same
compilation unit accessed by a PERFORM statement.  To use a subprogram
you needed to write it as a separate compilation unit and invoke it
with CALL <subproc> USING <param> [...]

All in all it was a lot easier in machine code. ;-)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.22 (GNU/Linux)

iQIcBAEBAgAGBQJVMsPcAAoJEAF3yXsqtyBlUZwP/3w5Twm7fvKfZFGFXH5iZ/pV
vBI4R37WpUgCZI2QnYuWvyZtRQEJOmIJzfdifwETsQYUZtG0QHgchF6er4H61DUz
9vkVlv7+rHAh8W5ggQubchHnpVERybV54Jrm3Zee1JAPicjlkmgWznp2f4jA+kOw
PSViycVAJ5Pscjkb6O4ggpANtf2D/hZQATEN6J1RqGYnrLbP1NkWz7dCHkcxJVhx
5Thr1i3i3ZKIGlTVT4vhFGtcokKqSoSZxmRWly2xQMrvUMuRu7A8eaQohx5DALQn
c3TKxfBMyOZu4M/5R0xQa3R7pepAqGvo+DhkilnRC4JfLxqL8N8emY4shDyobQn4
ml7zckkiEgth6aIQBc4iWo+71q8uFw7OkNxaGRjbE/19V3jfb+MrcfaA8BqrQ//Q
37kaXineP9vO1iZevYe/cMwO21UIJPUAfVr3UypXPXSQ63Af4JBVil9UeAZ7H9Sf
XnjJs0vHgBrz/Xbk9Xd/2mgp6lYoO2Gn7xIEdoOczDObRcJgoTsngV7O3vp9OGwB
i/yHAi75Oy1fYpVz1ig9JwrgBBcL/AiZVP2EhdaitGHBP+yfIns9uZuONIUPNlpc
xAL9CN4SoSHldGDmw0bflDxPq0T8SjbtsRfT19ONw5OtP0L+73u4huaAAJK1Dwd8
e/ORmlkZ8a9xmHU7alag
=1V4Q
-----END PGP SIGNATURE-----



reply via email to

[Prev in Thread] Current Thread [Next in Thread]