TypeOf(""),TypeOf(1),TypeOf(1.1), @1, @1.1

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
GPI
PureBasic Expert
PureBasic Expert
Posts: 1394
Joined: Fri Apr 25, 2003 6:41 pm

TypeOf(""),TypeOf(1),TypeOf(1.1), @1, @1.1

Post by GPI »

TypeOf("") should return #pb_string
TypeOf(1) should return #pb_quad (because every numeric can be stored in quad)
TypeOf(1.1) should retrun #pb_double (because double can store float-values)

@"something" returns the address of the string, so this
@1 should return the address to a quad with the value 1 (like the string)
@1.1 should return the address to a double with the value 1.1

And maybe

Code: Select all

procedure.a proc()
endprocedure
debug TypeOf(proc())
should return a #pb_procedure

Why?

Code: Select all

Structure vary
  StructureUnion
    a.a
    b.b
    c.c
    d.d
    f.f
    i.i
    l.l
    w.w
    q.q
  EndStructureUnion
EndStructure



Procedure.q _test(t1,*v1.vary)
  Protected ret.vary
  If t1=#PB_Integer     
    ret\i=*v1\i
    Debug "Integer!"+*v1\i    
  ElseIf t1=#PB_Double
    ret\d=*v1\d
    Debug "double!"+*v1\d
  EndIf
  ProcedureReturn ret\q
EndProcedure

Macro test(v1)
  _test(TypeOf(v1),@v1)
EndMacro

a.i=11
b.d=20.5
Debug test(a)
Debug test(b)
debug test(99);<-compilererror
User avatar
Didelphodon
PureBasic Expert
PureBasic Expert
Posts: 448
Joined: Sat Dec 18, 2004 11:56 am
Location: Vienna - Austria
Contact:

Re: TypeOf(""),TypeOf(1),TypeOf(1.1), @1, @1.1

Post by Didelphodon »

+1

For extended macros I'd also like to have the TypeOf-function working (and not failing) for literal string values.
However, imho it should lead to something like "#PB_LiteralString" to not confuse with "#PB_String" ...

Example:

Code: Select all

If (TypeOf("hallo") = #PB_LiteralString) ; This is a literal string
Go, tell it on the mountains.
Mistrel
Addict
Addict
Posts: 3415
Joined: Sat Jun 30, 2007 8:04 pm

Re: TypeOf(""),TypeOf(1),TypeOf(1.1), @1, @1.1

Post by Mistrel »

Just tried to make a macro today and was stopped by this. I was surprised to find that TypeOf() doesn't work with literal strings.
Post Reply