Structures with predefined member values

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
Franky
Enthusiast
Enthusiast
Posts: 213
Joined: Sat Apr 26, 2003 2:58 pm

Structures with predefined member values

Post by Franky »

Hi there,

We have

Code: Select all

Global value.l=5
And we have

Code: Select all

Structure dings
  value.l
  List Werte.l()
EndStructure

Global var.dings
var\value=5


Initializing the List needs setting values anyway, so, why not allow

Code: Select all

Structure dings
  value.l=5
  List Werte.l()
EndStructure

Global var.dings

Thanks for reading, discussing, implementing

Greetings

Franky


Edit: The old posting showed an example with Strings, but this needs memory allocation. So, it was removed with Numeric Values example.

Code: Select all

Global test.s="String"
And we have

Code: Select all

Structure dings
  test.s
  List Werte.l()
EndStructure

Global var.dings
var\test="String"


Initializing the List needs setting values anyway, so, why not allow

Code: Select all

Structure dings
  test.s="String"
  List Werte.l()
EndStructure

Global var.dings
Last edited by Franky on Tue Feb 21, 2012 12:42 pm, edited 1 time in total.
Give Up everything but trying!
c4s
Addict
Addict
Posts: 1981
Joined: Thu Nov 01, 2007 5:37 pm
Location: Germany

Re: Structures with predefined member values

Post by c4s »

Yes, I like that!
If any of you native English speakers have any suggestions for the above text, please let me know (via PM). Thanks!
Little John
Addict
Addict
Posts: 4779
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: Structures with predefined member values

Post by Little John »

Franky wrote:Initializing the List needs setting values anyway, so, why not allow

Code: Select all

Structure dings
  test.s="String"
  List Werte.l()
EndStructure

Global var.dings
And why not even allow

Code: Select all

Structure dings
   test.s = "String"
   List Werte.l() = {1,2,3}
EndStructure

Global var.dings
:)

Regards, Little John
User avatar
STARGÅTE
Addict
Addict
Posts: 2227
Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:

Re: Structures with predefined member values

Post by STARGÅTE »

-1

don't need it, a structure is a structure, and not a variable with pre-definition!

one way:

Code: Select all

Structure MyStructure
	String.s
	List Value.l()
EndStructure
With PreDefinition.MyStructure
	\String = "String"
	AddElement(\Value()):\Value() = 123
EndWith

Global Variable.MyStructure = PreDefinition

Debug Variable\String
FirstElement(Variable\Value())
Debug Variable\Value() 
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
Little John
Addict
Addict
Posts: 4779
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: Structures with predefined member values

Post by Little John »

I'm sorry, I don't want to hijack this thread, since what I'm proposing here actually is independent of structures. However, I think I should clarify what I previously wrote.
STARGÅTE wrote:one way:

Code: Select all

Structure MyStructure
	String.s
	List Value.l()
EndStructure
With PreDefinition.MyStructure
	\String = "String"
	AddElement(\Value()):\Value() = 123
EndWith
With

Code: Select all

List Werte.l() = {1,2,3}
I did not mean

Code: Select all

AddElement(\Werte()): \Werte() = 123
but this (pseudocode)

Code: Select all

ForEach element in sequence of constants
   AddElement(\Werte()): \Werte() = element
Next
Something like this would come in very handy (also for arrays)!

Regards, Little John
Franky
Enthusiast
Enthusiast
Posts: 213
Joined: Sat Apr 26, 2003 2:58 pm

Re: Structures with predefined member values

Post by Franky »

Hey Little John, great idea, but it would be one step up.
I've corrected my example at the beginning as I currently only would need the predefined Members with values.

An imaginary roadmap could be like this:

Release 1:

Code: Select all

Structure Test
   value.l=5 ; <-Works
  string.s="Test"; <-Not implemented
  List Parts.l()={1;2;3} <-Not implemented
EndStructure
=> No Memory allocations needed

Release 2:

Code: Select all

Structure Test
   value.l=5 ; <-Works
  string.s="Test"; <-Works
  List Parts.l()={1;2;3} <-Not implemented
EndStructure
=> one single Memory allocation needed ; InitializeStructure needs to be handled with care


Release 3:

Code: Select all

Structure Test
   value.l=5 ; <-Works
  string.s="Test"; <-Works
  List Parts.l()={1;2;3}; <-Works
EndStructure
=> Multiple memory allocation and a new Syntax is needed


So far

Franky
Give Up everything but trying!
Post Reply