Forum Index
HomeZBasic Home   Forum RulesForum Rules   Forum FAQForum FAQ   MemberlistMemberlist   UsergroupsUsergroups   RSS FeedRSS Feed
Site SearchSite Search   LinksLinks   DownloadDownload   Digests and SubscriptionsDigests and Subscriptions
ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in   RegisterRegister
Determine numeric types programmatically?

 
Post new topic   Reply to topic    Forum Index -> ZBasic Language
Author Message
victorf



Joined: 01 Jan 2006
Posts: 342
Location: Schenectady, New York

Posted: 10 March 2006, 22:52 PM    Post subject: Determine numeric types programmatically? Reply with quote

Is there any reasonable way to determine a numeric's type programmatically Question

I would like to be able to write a general purpose routine that could handle any numeric. So I would like to test for it something like:

A = Typeof(num) Smile

where A might be 0 for byte, 1 for integer, 2 for Unsigned integer, etc. Is there any way to do this Question

Any enlightenment will be appreciated.

Vic
Back to top
dkinzer
Site Admin


Joined: 03 Sep 2005
Posts: 2499
Location: Portland, OR

Posted: 11 March 2006, 1:20 AM    Post subject: Reply with quote

There is no way to determine the type of a value or parameter currently. With the current language design, it isn't necessary in most circumstances. If/when VarType parameters to procedures is implemented, then TypeOf() becomes useful/necessary.

Of course, I may have misunderstood the intent of your question. What is it that you're trying to accomplish?
Back to top
stevech



Joined: 23 Feb 2006
Posts: 657

Posted: 11 March 2006, 2:46 AM    Post subject: Reply with quote

May I add - ZBasic is strongly typed - so you must declare the type of each parameter passed to a sub or function, and declare if this is by reference or by value.

So - it seems rare that you'd need or want a typeof()
Back to top
victorf



Joined: 01 Jan 2006
Posts: 342
Location: Schenectady, New York

Posted: 11 March 2006, 12:26 PM    Post subject: Reply with quote

What I am attempting to do is write a sub/function that can handle a variable of any type:

Code:

Public Sub MySub(ByVal myvar as anytype)

  Select Case Typeof(myvar)
    Case Byteof
      do some bytething
    Case Intof
      do som integer thing
    etc
End Sub


assuming for a moment that Typeof() returned a value that could be identify its argument as I described.

I got this idea of TypeOf() after studying your format.bas which has subroutines to handle each type of variable, single, integer and unsigned. This seemed awkward to me. Confused

Since ZBasic is a strongly typed language I just assumed that somehow each type was known. I have little (read NO) knowledge of how a compiler is designed to do the strong typing. I guess I was just imagining how I could handle multiple types in a single routine. After all, there are several routines like this:

Code:

Function returning the same type as the first parameter


that can determine what type to return, though I guess that they can know this at compile time Smile

Wishful thinking I suspect.

Thanks for the replies.

Vic
Back to top
dkinzer
Site Admin


Joined: 03 Sep 2005
Posts: 2499
Location: Portland, OR

Posted: 11 March 2006, 14:43 PM    Post subject: Reply with quote

I agree that it is awkward to handle multiple data types. Currently, however, that is the only way it can be done. The difference is that of being able to determine the type of a variable at compile-time versus doing so at run-time. The former is fairly simple to do. The latter requires that type information be passed along with the variable so that it can be used at run-time.

I haven't yet looked into what it will take to implement VarType but I'm assuming that at least one extra byte of space will have to be used to hold the type information in addition to that used for the variable's data.
Back to top
victorf



Joined: 01 Jan 2006
Posts: 342
Location: Schenectady, New York

Posted: 11 March 2006, 19:05 PM    Post subject: Reply with quote

dkinzer wrote:
Quote:

I haven't yet looked into what it will take to implement VarType but I'm assuming that at least one extra byte of space will have to be used to hold the type information in addition to that used for the variable's data.


I guess the real question is; Is this sort of thing really worth knowing or doing Question Have you explored the idea of having function/subroutine overloading. I have used it in programming but I suspect that the same question could be asked of it as well.

Anyway, thanks for taking the time to respond. It is appreciated.

Vic
Back to top
Display posts from previous:   
Post new topic   Reply to topic    Forum Index -> ZBasic Language Time synchro. with the server - Timezone/DST with your computer
Page 1 of 1

 


All content Copyright © 2005-2012 Elba Corp. All Rights Reserved.
Opinions expressed in posts are those of the author and not necessarily those of Elba Corp.
Powered by phpBB © 2001, 2005 phpBB Group