automatic data typing

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
Tenaja
Addict
Addict
Posts: 1959
Joined: Tue Nov 09, 2010 10:15 pm

automatic data typing

Post by Tenaja »

Sometimes you need to build a table with multiple data types that must align. (i.e. a string containing a color name, and an int with the color value.)

This gets messy:

Code: Select all

datasection
  data.s "White" : data.i $ffffff
  data.s "Black" : data.i 0
enddatasection
Permitting multiple data types, and automatic types with strings would simplify this common use. If we could have a default setting for numbers, strings are easy to differentiate.

Code: Select all

datasection.i
  data $ffffff , "White"
  data 0, "Black"
enddatasection
I think constant arrays with multiple lines would be far superior, but this seems like a great in-between.
User avatar
STARGÅTE
Addict
Addict
Posts: 2227
Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:

Re: automatic data typing

Post by STARGÅTE »

and what is

Code: Select all

data 0
byte, acsii, word, unicode, long, quad, float, double ???
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and moreTypeface - Sprite-based font include/module
User avatar
KJ67
Enthusiast
Enthusiast
Posts: 218
Joined: Fri Jun 26, 2009 3:51 pm
Location: Westernmost tip of Norway

Re: automatic data typing

Post by KJ67 »

I'd prefer the data, read etc. keywords to support structures. Would be more PB-style.

Code: Select all

Structure foo
  x.i
  y.s
  z.f
EndStructure

Restore test
Define t.foo
Read.foo t

test:
DataSection
  Data.foo 1, "Hi", 3.1415
EndDataSection
The best preparation for tomorrow is doing your best today.
User avatar
Tenaja
Addict
Addict
Posts: 1959
Joined: Tue Nov 09, 2010 10:15 pm

Re: automatic data typing

Post by Tenaja »

STARGÅTE wrote:and what is

Code: Select all

data 0
byte, acsii, word, unicode, long, quad, float, double ???
Whatever your Default type was. In my example, I used .i.
User avatar
Tenaja
Addict
Addict
Posts: 1959
Joined: Tue Nov 09, 2010 10:15 pm

Re: automatic data typing

Post by Tenaja »

KJ67 wrote:I'd prefer the data, read etc. keywords to support structures. Would be more PB-style.

Code: Select all

Structure foo
  x.i
  y.s
  z.f
EndStructure

Restore test
Define t.foo
Read.foo t

test:
DataSection
  Data.foo 1, "Hi", 3.1415
EndDataSection
I'd be happy with that!
c4s
Addict
Addict
Posts: 1981
Joined: Thu Nov 01, 2007 5:37 pm
Location: Germany

Re: automatic data typing

Post by c4s »

Tenaja wrote:
KJ67 wrote:I'd prefer the data, read etc. keywords to support structures. Would be more PB-style.

Code: Select all

Structure foo
  x.i
  y.s
  z.f
EndStructure

Restore test
Define t.foo
Read.foo t

test:
DataSection
  Data.foo 1, "Hi", 3.1415
EndDataSection
I'd be happy with that!
Me too! +1
If any of you native English speakers have any suggestions for the above text, please let me know (via PM). Thanks!
User avatar
Demivec
Addict
Addict
Posts: 4260
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: automatic data typing

Post by Demivec »

KJ67 wrote:I'd prefer the data, read etc. keywords to support structures. Would be more PB-style.

Code: Select all

Structure foo
  x.i
  y.s
  z.f
EndStructure

Restore test
Define t.foo
Read.foo t

test:
DataSection
  Data.foo 1, "Hi", 3.1415
EndDataSection
Previous thread covering the same/similar subject: http://www.purebasic.fr/english/viewtopic.php?f=3&t=40966

Oh, and I'm still +1 for this. :)
Post Reply