Can someone please explain me what happens when I call eg

Dates.Year("100")

? From the constructor, only ::Number arguments should be accepted, yet
this "just works" --- I am not sure it is intended though (I recall the
manual saying somewhere that Julia does not treat strings as numbers).

I reread certain parts of the manual, but I can't figure this out.

Best,

Tamas

On Wed, Jan 13 2016, Stefan Karpinski wrote:

> I suspect it's because Jacob originally wrote this code  for 0.3 which
> provided much less permissive default constructors which only worked with
> exactly matching argument types.
>
> On Wednesday, January 13, 2016, Tamas Papp <[email protected]> wrote:
>
>> Hi,
>>
>> I am reading the code of Base libraries to improve my understanding and
>> style. In base/dates/types.jl, I noticed
>>
>> for T in (:Year,:Month,:Week,:Day)
>>     @eval immutable $T <: DatePeriod
>>         value::Int64
>>         $T(v::Number) = new(v)
>>     end
>> end
>>
>> which expands to code like
>>
>> immutable Year <: DatePeriod
>>   value::Int64
>>   Year(v::Number) = new(v)
>> end
>>
>> I have a simple question: what is the reason for defining the inner
>> constructor? Wouldn't
>>
>> immutable Year <: DatePeriod
>>   value::Int64
>> end
>>
>> automatically define one, except for restricting to ::Number? If that is
>> the reason, I would like to understand why.
>>
>> Best,
>>
>> Tamas
>>

Reply via email to