On Wed, Mar 9, 2022 at 6:40 AM Salvador Fandiño <sfandino@gmail.com> wrote: > > > IMO, the problem here is that we are still keeping the old mindset where > perls scalars where transformed from one type to the other and we > couldn't tell which one was the former one. > > The thing is that now we know the former type, so, I think we should > stop thinking about the-scalar-that-was-created-as-a-number and instead > start considering it the-scalar-that-is-a-number. > > > The fact that Perl can internally keep other representations of the > scalar (for instance, a string) doesn't change the fact that the scalar > *is* a number. > > > >> From a functional point of view, I think that was is needed is a set > of > >> functions to check the type of a scalar and another set of functions (a > >> la looks_like_number) to check whether it can be converted into > >> something else: > >> > >> builtin::isa_number > >> builtin::looks_like_number > >> etc. > > I dont really follow what "isa_number" is compared to > > "looks_like_number". Is "isa_number" meant to to be the same as > > "created_as_number" from this proposal? > > Yes! > > > > > >> One important point here is that neither "isa_number", neither > >> "looks_like_number" are influenced by the private type flags (or the > >> scalar history, which is an uninteresting thing, right?): > >> > >> $a = "7"; > >> say isa_number($a), looks_like_number($a); > >> $b = $a+1; > >> say isa_number($a), looks_like_number($a); # same results > > I dont get what you want here. The standard definition of > > looks_like_number() would return the same thing for both lines. I am > > not sure what isa_number is supposed to do, but if its the same as > > created_as_number() then it would too. Eg, say would output FALSE, > > TRUE both times. (For some printed definition of FALSE and TRUE). > > Yes, and that is the point. > > From a functional point of view you are interested in two things: > > 1) is this scalar a number? (equivalent to was this scalar created as a > number?!) > > 2) can this scalar by used as a number? > > And something that is completely uninteresting is: > > 3) has this scalar been used as a number? > > > We are not talking about a strict typing system (yet). All scalars are numbers because all scalars can be used as numbers, barring overloads that explicitly throw an exception. -DanThread Previous | Thread Next