I may be completely missing the point, but how about unused optional 
arguments(s) to store the constant(s):

julia> test9(x, aconst = 1.0) = x + aconst
test9 (generic function with 2 methods)


julia> @code_native test9(4.2)
        .text
Filename: none
Source line: 1
        push    RBP
        mov     RBP, RSP
        movabs  RAX, 481367024
Source line: 1
        addsd   XMM0, QWORD PTR [RAX]
        pop     RBP
        ret






On Wednesday, February 11, 2015 at 2:27:54 PM UTC-8, Simon Danisch wrote:
>
> Ah yeah, sure...
> And also my all time favorite staged functions could be misused:
> stagedfunction test5() 
>        quote 
>         a = $(a = rand() )
>         a + a
>     end
>    end
> But I'm actually searching for answers, why it is like this and what 
> speaks against a nice solution for such a common use case.
> My code using this is absolutely not performance critical ;)
>
> @Mauro I am aware of the scope, and I agree with you. I didn't open an 
> issue, as I wanted to discuss this first.
>
> Am Mittwoch, 11. Februar 2015 17:20:02 UTC+1 schrieb Simon Danisch:
>>
>> Hi, 
>> I was trying to find out, what the best way is to have some local, 
>> constant storage for a function, which is only accessible from inside the 
>> function
>> So something like this:
>> begin
>> const local a = []
>> test() = dosomething(a)
>> end
>>
>> I was quite surprised, that you can't do this efficiently.
>> Or at least I didn't find a way, or tested it incorrectly.
>> Here are the different combinations I tried and the emitted native code:
>>
>> https://gist.github.com/SimonDanisch/e4bed0a16bdd847a8c2b#file-local_function_storage-jl
>>
>> test11 && test12 seems to be what julia does internally for test1-test4 
>> (and the example here)
>> It's especially odd, as a global const seems to be faster than a local 
>> const, even though that the local version is more restricted.
>> Is this because there has been more time spend on making globals fast?
>>
>> Best,
>> Simon
>>
>

Reply via email to