To your second proposal: Am I correct that your main concern is about 
arrays here (because you mention setindex). If yes it is pretty straight 
forward to implement a readonly wrapper about standard arrays having no 
setindex method. It could inherit from AbstractArray and used in all 
methods that get an AbstractArray as argument or use duck typing.

And just in case you have not seen this. Julia also offers immutable types 
where the members are read only. They are however not meant as an 
alternative to heap allocated arrays but rather for small things that have 
value type character (e.g. an rgb color type).

I am myself a C++ programmer and like the language a lot with all its 
concepts. But if I am honest to myself I have to realize that I develop a 
lot slower in C++ and that the code that I have produced is less readable 
for people that have a deep understanding of the C++ language. Realizing 
this made me a big fan of Julia.

Am Freitag, 13. Juni 2014 10:31:21 UTC+2 schrieb [email protected]:
>
> It appears that the experts have debated this topic before and concluded 
> that inarg/outarg specifications do not mix well with the Julia type 
> system, so I will drop my request for them.
>
> However, it seems that the Fortran 90 and C++ communities would agree that 
> they are still very useful for self-documenting code and for debugging, so 
> let me float two other proposals.
>
> First, for improving code readability, could the language developers 
> propose a stylistic convention for indicating which function arguments are 
> in, out and inout and put it in the manual?
>
> Second, for the purpose of debugging, I'm guessing that it would not be 
> incompatible with the Julia type system if the caller rather than the 
> routine enforced const args.  In other words, there could be a function 
> makereadonly that makes a mutable value read-only, so that if you called 
> "sort!(makereadonly(v))", there would be a run-time exception.  I cannot 
> think of any way to implement such a feature except by adding a check for 
> the read-only-bit in setIndex, which would cause a general hit on 
> performance, so it should be possible to turn the makereadonly checking off 
> (globally) to improve performance.  Similarly, there could be a 
> ignoreexistingvalue() function for arguments that are intended as outargs.
>
> Thanks,
> Steve Vavasis
>
>
>
>
>
>
>
>
> On Thursday, June 12, 2014 8:28:18 PM UTC+3, [email protected] wrote:
>>
>> Both C++ and Fortran 90 allow the programmer to annotate 
>> call-by-reference arguments to a function as to whether the function is 
>> allowed to change them (this is denoted  const & in C++).  The compiler 
>> then enforces the const-ness of the argument.  I don't see how to do this 
>> in Julia.  Is it available?  If not, is there a reason why it was not 
>> included?  This is a fairly basic tool for self-documenting code and for 
>> ensuring program correctness.
>>
>> And a related question: the documentation makes a big deal about "stable 
>> types" for function return arguments.  An obvious question is why the 
>> language doesn't allow the programmer to declare in the function heading 
>> what will be the return types of the function, and then have the compiler 
>> enforce this stability.  Is this possible in Julia?  If not, is there a 
>> technical reason for omitting it?
>>
>> Thanks,
>> Steve Vavasis
>>
>> P.S. I have a few more questions but I'll pause now to wait for answers 
>> to these questions.  I hope they are easy to answer!
>>
>

Reply via email to