Author Topic: VariableType  (Read 4057 times)

0 Members and 1 Guest are viewing this topic.

Peter

  • Guest
VariableType
« on: November 15, 2011, 01:12:24 PM »
Deleted
« Last Edit: May 05, 2015, 09:31:12 AM by Peter »

Charles Pegge

  • Guest
Re: VariableType
« Reply #1 on: November 15, 2011, 01:49:10 PM »

Hi Peter,

Some clues here

Code: OxygenBasic
  1.  
  2. type ty string s,t,u
  3.  
  4. ty t
  5.  
  6. 'print typeof ty
  7. 'print typeof t
  8. 'print typeof t.s "   "
  9. 'print typecodeof t.s
  10.  
  11.  
  12. '=============
  13.  
  14.  
  15. function foo(any*v,sys typ) as string
  16. string s
  17. select case typ
  18. case 0x02    : s="short"
  19. case 0x04    : s="long"
  20. case 0x08    : s="quad"
  21. case 0x21    : s="byte"
  22. case 0x22    : s="word"
  23. case 0x24    : s="dword"
  24. case 0x64    : s="single"
  25. case 0x68    : s="double"
  26. case 0xa1    : s="zstring"
  27. case 0xe1    : s="string"
  28. end select
  29. return s
  30. end function
  31.  
  32.  
  33. byte   b
  34. word   w
  35. dword  d
  36. string s
  37.  
  38.  
  39.  
  40. print foo b,typecodeof b
  41. print foo w,typecodeof w
  42. print foo d,typecodeof d
  43. print foo s,typecodeof s
  44.  
  45.  

Charles

efgee

  • Guest
Re: VariableType
« Reply #2 on: November 15, 2011, 04:44:57 PM »
Do you have the "in progress" oxygen zip file?

It works fine here...
(with oxygen.dll of Nov 13th)

bye

BTW: Shouldn't you be in bed by now?
« Last Edit: November 15, 2011, 04:47:08 PM by efgee »

Charles Pegge

  • Guest
Re: VariableType
« Reply #3 on: November 15, 2011, 06:05:59 PM »

typecodeof is a recent feature, (15th October).

Function overloading is another possibility, and eliminates the select case logic

Code: OxygenBasic
  1.  
  2. 'FUNCTION OVERLOADING
  3. '====================
  4.  
  5. function foo (long v) as string
  6. return "long " v
  7. end function
  8.  
  9. function foo (double v) as string
  10. return "double " v
  11. end function
  12.  
  13. function foo (string v) as string
  14. return "string " v
  15. end function
  16.  
  17.  
  18. long l=42
  19. double d=42.5
  20. string s="43"
  21.  
  22. print foo l
  23. print foo d
  24. print foo s
  25.  
  26.  

Charles

PS: My bed time is whenever the brain goes fuzzy :)



JRS

  • Guest
Re: VariableType
« Reply #4 on: November 15, 2011, 07:07:46 PM »
Is function overloading a default for typeless languages?

Code: [Select]
SUB foo(arg)
  IF ISNUMERIC(arg) THEN
    PRINT "Numeric Value\n"
  ELSE IF ISSTRING(arg) THEN
    PRINT "String Value\n"
  ELSE
    PRINT "undef\n"
  END IF
END SUB

foo 1
foo "two"
foo

jrs@laptop:~/sb/test$ scriba foo.sb
Numeric Value
String Value
undef
jrs@laptop:~/sb/test$
« Last Edit: November 15, 2011, 07:14:08 PM by JRS »

Charles Pegge

  • Guest
Re: VariableType
« Reply #5 on: November 15, 2011, 08:18:57 PM »

It's more for compiled typed languages, so they can pretend to be typeless :)

But overloading is not confined to primitives. You could use functions of the same name for totally different types

feed(Baby)

feed(Geraniums)

feed(Boiler)


Charles

efgee

  • Guest
Re: VariableType
« Reply #6 on: November 15, 2011, 08:24:15 PM »

PS: My bed time is whenever the brain goes fuzzy :)


If this is the rule of the day... I can't get out of bed  ;D

Thinking of fuzzy:
Who remembers the hype about fuzzy logic in the 90'

Come and gone  ???

Charles Pegge

  • Guest
Re: VariableType
« Reply #7 on: November 15, 2011, 08:28:47 PM »

Along with Expert systems.

But only to reappear in algorithmic trading systems for the stock market - contributing to global financial instability.

Charles Pegge

  • Guest
Re: VariableType
« Reply #8 on: November 16, 2011, 05:34:40 AM »
Hi Peter,

You have to pass the typecode to the function as well as the variable. My first example demonstrates this.

You can use a macro to do this for you, so you only have to specify the variable once when calling.

def FlexiFunc FlexifuncA %1,typecodeof %1

FlexiFunc v

expands to:

FlexiFuncA v, typecodeof v




Charles
« Last Edit: November 16, 2011, 09:53:46 AM by Charles Pegge »