In a Pascal-like language, would being able to declare a subroutine as "purely functional" be of any value?

noitalmost <noitalmost@cox.net>
Fri, 11 Mar 2011 14:15:59 -0500

          From comp.compilers

Related articles
In a Pascal-like language, would being able to declare a subroutine as noitalmost@cox.net (noitalmost) (2011-03-11)
Re: In a Pascal-like language, would being able to declare a subroutin gah@ugcs.caltech.edu (glen herrmannsfeldt) (2011-03-11)
Re: In a Pascal-like language, would being able to declare a subroutin bobduff@shell01.TheWorld.com (Robert A Duff) (2011-03-11)
Re: In a Pascal-like language, would being able to declare a subroutin pdjpurchase@googlemail.com (1Z) (2011-03-11)
Re: In a Pascal-like language, would being able to declare a subroutin gah@ugcs.caltech.edu (glen herrmannsfeldt) (2011-03-12)
Re: In a Pascal-like language, would being able to declare a subroutin comp.lang.misc@inglorion.net (Robbert Haarman) (2011-03-12)
Re: In a Pascal-like language, would being able to declare a subroutin mcr@wildcard.demon.co.uk (Martin Rodgers) (2011-03-12)
[8 later articles]
| List of all articles for this month |
From: noitalmost <noitalmost@cox.net>
Newsgroups: comp.compilers
Date: Fri, 11 Mar 2011 14:15:59 -0500
Organization: Compilers Central
Keywords: optimize, question
Posted-Date: 11 Mar 2011 14:19:15 EST

I was thinking of something like:
pure function foo(x,y : int) int
begin
...
end;


Then foo isn't allowed to modify its parameters or to reference
(except possibly through a parameter) or modify any non-local
variables. I was thinking of this as a kind of user directive to the
compiler, like const in C++. "Compiler, this is what I intend, now
make sure that it's actually enforced."


I put "purely functional" in quotes because I'm using the term pretty
loosely, since assignments and such would be allowed inside foo. But
they all have to be to local variables (i.e. not to an alias whose
data is in some outer scope).


Can a compiler do this sort of checking, or would the complexity get
out of hand? I'm thinking that at least a limited form must be
possible in order to do any sort of inter-procedural register
allocation.


My apologies if this is a stupid question. Since I've never seen such
a thing implemented, I fear that it just might be.
[See http://publib.boulder.ibm.com/infocenter/ratdevz/v7r6/index.jsp?topic=/com.ibm.ent.pl1.zos.doc/topics/ibma1d111005551.htm -John]



Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.