473,804 Members | 2,747 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

which language allows you to change an argument's value?


I wonder which language allows you to change an argument's value?
like:

foo(&a) {
a = 3
}

n = 1
print n

foo(n) # passing in n, not &n
print n

and now n will be 3. I think C++ and PHP can let you do that, using
their reference (alias) mechanism. And C, Python, and Ruby probably
won't let you do that. What about Java and Perl?

is there any way to prevent a function from changing the argument's
value?

isn't "what i pass in, the function can modify it" not a desireable
behavior if i am NOT passing in the address of my argument? For one
thing, if we use a module, and call some functions in that module, and
the module's author made some changes to his code, then we have no way
of knowing what we pass in could get changed. Of course, if it is in
Java, Python, and Ruby, and we pass in a reference to object (not C+
+'s meaning of alias reference), so the object can get changed, but
that can be expected, vs passing in n, when n = 1. Even when it is
Ruby, when everything is an object, passing n in when n = 1 won't ever
make n become 3. Is there a way to prevent it from happening in the
languages that allows it?

Sep 30 '07
17 1689
In article <1P************ *@newsfe12.lga> ,
John W. Kennedy <jw*****@attglo bal.netwrote:
Dennis Lee Bieber wrote:
On Mon, 01 Oct 2007 01:53:47 GMT, Roedy Green
<se*********@mi ndprod.com.inva liddeclaimed the following in
comp.lang.pytho n:

Seem to me you could in FORTRAN and Pascal, and maybe even Algol. It
has been a while.
Everything in classic FORTRAN is a passed as a reference -- even
constant arguments are passed as a reference to the memory location
containing that constant (which is why it was possible in very early
FORTRANs to have "a = 1 + 1" yield something other than "2" if preceded
by, say, "call mutate(1)" where mutate looks like:

subroutine mutate(arg)
arg = arg * 2
end

)

However, some implementations passed /and returned/ elementary arguments
by value, as Ada does.
In FORTRAN/Fortran, don't they call that "copy-in/copy-out"? Same
thing, just nitpicking a little about terminology, I hope correctly.
(The object code was typically faster that way,
and FORTRAN semantics were such that the difference was almost
impossible to observe.)
--
B. L. Massingill
ObDisclaimer: I don't speak for my employers; they return the favor.
Oct 5 '07 #11
bl****@myrealbo x.com wrote:
In article <1P************ *@newsfe12.lga> ,
John W. Kennedy <jw*****@attglo bal.netwrote:
>However, some implementations passed /and returned/ elementary arguments
by value, as Ada does.
In FORTRAN/Fortran, don't they call that "copy-in/copy-out"? Same
thing, just nitpicking a little about terminology, I hope correctly.
Back in the day, IBM called it "by copy". I'm not acquainted with modern
versions of the language.
--
John W. Kennedy
"The whole modern world has divided itself into Conservatives and
Progressives. The business of Progressives is to go on making mistakes.
The business of the Conservatives is to prevent the mistakes from being
corrected."
-- G. K. Chesterton
Oct 5 '07 #12
In article <mz************ *@newsfe12.lga> ,
John W. Kennedy <jw*****@attglo bal.netwrote:
bl****@myrealbo x.com wrote:
In article <1P************ *@newsfe12.lga> ,
John W. Kennedy <jw*****@attglo bal.netwrote:
However, some implementations passed /and returned/ elementary arguments
by value, as Ada does.
In FORTRAN/Fortran, don't they call that "copy-in/copy-out"? Same
thing, just nitpicking a little about terminology, I hope correctly.

Back in the day, IBM called it "by copy". I'm not acquainted with modern
versions of the language.
Huh. I'd have said I was remembering the terminology from back
when I was actively using the language, when it was still FORTRAN
and my then-current place of employment still regarded the F77
standard as a bit too new-fangled to be relied on. But I'm sure
your memory's at least as good as mine, and I can't quite figure
out how to research which term might have been used when ....

--
B. L. Massingill
ObDisclaimer: I don't speak for my employers; they return the favor.
Oct 6 '07 #13
On Oct 4, 12:35 am, "John W. Kennedy" <jwke...@attglo bal.netwrote:
Dennis Lee Bieber wrote:
On Mon, 01 Oct 2007 01:53:47 GMT, Roedy Green
<see_webs...@mi ndprod.com.inva liddeclaimed the following in
comp.lang.pytho n:
Seem to me you could in FORTRAN and Pascal, and maybe even Algol. It
has been a while.
Everything in classic FORTRAN is a passed as a reference -- even
constant arguments are passed as a reference to the memory location
containing that constant (which is why it was possible in very early
FORTRANs to have "a = 1 + 1" yield something other than "2" if preceded
by, say, "call mutate(1)" where mutate looks like:
subroutine mutate(arg)
arg = arg * 2
end
)
However, some implementations passed /and returned/ elementary
arguments by value, as Ada does. (The object code was
typically faster that way, and FORTRAN semantics were such
that the difference was almost impossible to observe.)
The Fortran standard is carefully worded to allow either pass by
reference, or copy-in, copy-out. IIRC, IBM's Fortran-H used
copy-in/copy-out, but most others used call by reference.

Straight copy was never allowed by the standard, and I've never
heard of a pre-standard implementation which used it either.

--
James Kanze (GABI Software) email:ja******* **@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientier ter Datenverarbeitu ng
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

Oct 7 '07 #14
On Oct 7, 2:59 pm, Jerry Coffin <jcof...@taeus. comwrote:
4.7.3.2. Name Replacement (call by name)

Any formal parameter not quoted in the value list is replaced,
throughout the procedure body, by the corresponding actual parameter,
after enclosing this latter in parentheses wherever syntactically
possible. Possible conflicts between identifiers inserted through this
process and other identifiers already present within the procedure will
be avoided by suitable systematic changes of the formal or local
identifiers involved.
This sounds rather like macro expansion as found in languages ranging
from TeX to various flavors of shell and make.
The universe is a figment of its own imagination.
I can't recall -- what was the formal name in philosophy for this
thesis?

Oct 8 '07 #15
Lew
Jerry Coffin wrote:
>The universe is a figment of its own imagination.
bb****@gmail.co m wrote:
I can't recall -- what was the formal name in philosophy for this
thesis?
Zen.

--
Lew
Oct 8 '07 #16
On Oct 8, 4:14 am, James Kanze <james.ka...@gm ail.comwrote:
On Oct 8, 6:58 am, bbo...@gmail.co m wrote:
On Oct 7, 2:59 pm, Jerry Coffin <jcof...@taeus. comwrote:
4.7.3.2. Name Replacement (call by name)
Any formal parameter not quoted in the value list is replaced,
throughout the procedure body, by the corresponding actual parameter,
after enclosing this latter in parentheses wherever syntactically
possible. Possible conflicts between identifiers inserted through this
process and other identifiers already present within the procedure will
be avoided by suitable systematic changes of the formal or local
identifiers involved.
This sounds rather like macro expansion as found in languages ranging
from TeX to various flavors of shell and make.

Not really. [snip loads]
You seem to be meaning to disagree with me, but it's unclear exactly
what you are asserting that contradicts anything that I said.

Oct 10 '07 #17
nebulou...@gmai l.com wrote:
On Oct 8, 4:14 am, James Kanze <james.ka...@gm ail.comwrote:
On Oct 8, 6:58 am, bbo...@gmail.co m wrote:
On Oct 7, 2:59 pm, Jerry Coffin <jcof...@taeus. comwrote:
4.7.3.2. Name Replacement (call by name)
Any formal parameter not quoted in the value list is replaced,
throughout the procedure body, by the corresponding actual parameter,
after enclosing this latter in parentheses wherever syntactically
possible. Possible conflicts between identifiers inserted through this
process and other identifiers already present within the procedure will
be avoided by suitable systematic changes of the formal or local
identifiers involved.
This sounds rather like macro expansion as found in languages ranging
from TeX to various flavors of shell and make.
Not really. [snip loads]
You seem to be meaning to disagree with me,
Yes and no. Algol's name replacement is definitly different
than the usual macro replacement in shells, make and TeX,
since the argument gets expanded each time it is used, and
not once when the function is called. On the other hand,
such languages often do have the capacity to delay
expansion; they also have the capability of treating any
data string as part of the program, so you can pass an
argument as a string, and then execute it multiple times in
a function. In short, you can easily simulate Algol's name
replacement in such languages.

Of course, if you pass a functional object in C++, you can
also get much of the same effect as well.

--
James Kanze (GABI Software) mailto:ja****** ***@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientier ter Datenverarbeitu ng
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

Oct 10 '07 #18

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
1999
by: Andrew | last post by:
Hello, I understand that this is a good place to post suggestions about future changes to the language, and that the Microsoft developers who develop C# read this newsgroup. If there is a more appropriate place to post this, please let me know. So, here are a few things I'd like to see. 1. A way to declare a local variable as being readonly.
17
3984
by: clintonG | last post by:
I'm using an .aspx tool I found at but as nice as the interface is I think I need to consider using others. Some can generate C# I understand. Your preferences please... <%= Clinton Gallagher http://forta.com/books/0672325667/
9
1155
by: Summercool | last post by:
I wonder which language allows you to change an argument's value? like: foo(&a) { a = 3 } n = 1 print n
0
9711
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
10331
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10087
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9166
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5529
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5667
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4306
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3831
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3001
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.