It is currently Sat Aug 24, 2019 3:50 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 15 posts ] 
Author Message
 Post subject: [Done] Define and Read
PostPosted: Fri Jul 27, 2018 10:23 pm 
Offline
Addict
Addict
User avatar

Joined: Thu Jun 07, 2007 3:25 pm
Posts: 3640
Location: Berlin, Germany
Please update the documentation of Define, since its behaviour has changed.

If no <variables> are specified, Define is used to change the default type for future untyped variables (including procedure parameters, interface method parameters and data to read with the Read keyword).
This (fortunately) does not work anymore, but is currently only documented in the version history:
History for PB version 5.60 wrote:
- Changed: removed 'define.b' syntax to change default type as it could create hard to find bugs.

The documentation of Read is related, and should also be changed. It mentions a default data type and contains a link to the documentation of Define.

The documentation should state clearly, that there is only one default data type (integer), and that this is not subject to change by the user.

_________________
Please excuse my flawed English. My native language is PureBasic.
Search
RSBasic's backups


Top
 Profile  
Reply with quote  
 Post subject: Re: Define and Read
PostPosted: Sat Dec 08, 2018 12:00 am 
Offline
PureBasic Team
PureBasic Team
User avatar

Joined: Fri Apr 25, 2003 6:14 pm
Posts: 1700
Location: Germany (Saxony, Deutscheinsiedel)
Something I'm not sure about the best way to describe / change the docs... :oops:

Any concrete suggestions?

_________________
Bye,
...André
(PureBasicTeam::Docs & Support - PureArea.net | Order:: PureBasic | PureVisionXP)


Top
 Profile  
Reply with quote  
 Post subject: Re: Define and Read
PostPosted: Sat Dec 08, 2018 5:01 am 
Offline
Addict
Addict
User avatar

Joined: Mon Jul 25, 2005 3:51 pm
Posts: 3568
Location: Utah, USA
Somethin like:
Code:
Define

Syntax
Define[.<type>] [<variable> [= <expression>], <variable> [= <expression>], ...]
Description
If no type is specified the default type of integer (.i) will be used. Each variable can have a default value directly assigned to it.

Example

  Define.b a, b = 10, c = b*2, d ; these 4 variables will be byte typed (.b)

Syntax
Define <variable>.<type> [= <expression>] [, <variable>.<type> [= <expression>], ...]
Description
Alternative possibility for the variable declaration using Define.
Example

  Define MyChar.c
  Define MyLong.l
  Define MyWord.w
 
  Debug SizeOf(MyChar)   ; will print 2
  Debug SizeOf(MyLong)   ; will print 4
  Debug SizeOf(MyWord)   ; will print 2

_________________
Image


Top
 Profile  
Reply with quote  
 Post subject: Re: Define and Read
PostPosted: Sat Dec 08, 2018 8:38 am 
Offline
Addict
Addict
User avatar

Joined: Thu Jun 07, 2007 3:25 pm
Posts: 3640
Location: Berlin, Germany
I agree with Demivec's suggestion. Thank you!

_________________
Please excuse my flawed English. My native language is PureBasic.
Search
RSBasic's backups


Top
 Profile  
Reply with quote  
 Post subject: Re: Define and Read
PostPosted: Sat Dec 08, 2018 8:14 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Wed Jun 25, 2014 5:25 pm
Posts: 346
Location: Germany
But that's also possible:
Code:
Define.q a, b.w

Debug SizeOf(a) ; will print 8
Debug SizeOf(b) ; will print 2, because it doesn't have the default type
Therefore I suggest the following syntax, which covers all possibilities:
Code:
Define[.<default_type>] <variable>[.<type>][=<expression>] [,<variable>[.<type>][=<expression>], ...]

_________________
Image
Why OpenSource should have a license
PureBasic-CodeArchiv-Rebirth: Git-Repository / Download -- Any help is welcome!
Manjaro Xfce x64 (Main system) :: WindowsXP/Xubuntu x86 (VirtualBox) :: PureBasic (Linux: x86/x64, Windows: x86) :: All are up to date


Last edited by Sicro on Sat Dec 08, 2018 8:28 pm, edited 2 times in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: Define and Read
PostPosted: Sat Dec 08, 2018 8:24 pm 
Offline
Addict
Addict
User avatar

Joined: Thu Jun 07, 2007 3:25 pm
Posts: 3640
Location: Berlin, Germany
Sicro wrote:
But that's also possible:
Code:
Define.q a, b.w

Yes, that's possible.
But it's no good style IMHO, so people shouldn't be encouraged to write something like that. :-)

_________________
Please excuse my flawed English. My native language is PureBasic.
Search
RSBasic's backups


Top
 Profile  
Reply with quote  
 Post subject: Re: Define and Read
PostPosted: Sat Dec 08, 2018 9:17 pm 
Offline
Addict
Addict

Joined: Thu Aug 30, 2007 11:54 pm
Posts: 1022
Location: right here
to be precise.. :)
Code:
Define.b a, b.w, c
Define d

Debug SizeOf(a) ; 1
Debug SizeOf(b) ; 2
Debug SizeOf(c) ; 1 (type .b and not .w or .i)
Debug SizeOf(d) ; 8 (on x64, 4 on x86)


Top
 Profile  
Reply with quote  
 Post subject: Re: Define and Read
PostPosted: Sat Dec 08, 2018 9:44 pm 
Offline
Addict
Addict
User avatar

Joined: Thu Jun 07, 2007 3:25 pm
Posts: 3640
Location: Berlin, Germany
My "favorite" is something like this: :lol:
Code:
Define.f x$ = "1.23"

_________________
Please excuse my flawed English. My native language is PureBasic.
Search
RSBasic's backups


Top
 Profile  
Reply with quote  
 Post subject: Re: Define and Read
PostPosted: Sat Dec 08, 2018 9:51 pm 
Offline
Addict
Addict

Joined: Thu Aug 30, 2007 11:54 pm
Posts: 1022
Location: right here
:mrgreen:

<edit>
Code:
Define.f x$ = "1.23" + "0.77" + " / 2"


Top
 Profile  
Reply with quote  
 Post subject: Re: Define and Read
PostPosted: Sat Dec 08, 2018 10:08 pm 
Offline
Addict
Addict
User avatar

Joined: Thu Jun 07, 2007 3:25 pm
Posts: 3640
Location: Berlin, Germany
:mrgreen:

_________________
Please excuse my flawed English. My native language is PureBasic.
Search
RSBasic's backups


Top
 Profile  
Reply with quote  
 Post subject: Re: Define and Read
PostPosted: Sat Dec 08, 2018 11:16 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Wed Jun 25, 2014 5:25 pm
Posts: 346
Location: Germany
:mrgreen:

@Little John:
Yes, you're right. Using the keyword "Define" with default type and then defining a variable with a different type can easily be confusing / overlooked by programmers and is therefore not a good programming style.
But I think that a syntax description should always show all possibilities. The syntax variants that are not recommended should then also be mentioned in the description.

_________________
Image
Why OpenSource should have a license
PureBasic-CodeArchiv-Rebirth: Git-Repository / Download -- Any help is welcome!
Manjaro Xfce x64 (Main system) :: WindowsXP/Xubuntu x86 (VirtualBox) :: PureBasic (Linux: x86/x64, Windows: x86) :: All are up to date


Top
 Profile  
Reply with quote  
 Post subject: Re: Define and Read
PostPosted: Sun Dec 09, 2018 11:12 am 
Offline
Enthusiast
Enthusiast

Joined: Tue May 26, 2009 2:11 pm
Posts: 583
Some ideas:
Code:
Define a
; a will be type integer, 4 byte on 32 bit, 8 byte on 64 bit

Define a, b, c
; a, b and c will be type integer, 4 byte on 32 bit, 8 byte on 64 bit

Define a, b.w, c
; should raise a syntax error, no type on b allowed

Define.w a
; a will be type word

Define.w a, b, c
; a, b, c will be of type word

Define.w a, b.i, c
; should raise an syntax error, no type on b allowed

Define.s a
; b will be of type string (= a.s)

Define.s a, b, c
; a, b and c will be of type string (= a.s, b.s, c.s)


; Maybe new:
Define.$ a
; a will be type string (= a$)

Define.$ a, b, c
; a, b, c will be of type string (= a$, b$, c$)

Define.$ a, b.s, c
; should raise an syntax error, no type mixing allowed (a.s <> a$)


In general: no mixing of definitions on same define statement.

Edit: corrected typing errors

_________________
Image


Last edited by Lord on Sun Dec 09, 2018 7:47 pm, edited 1 time in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: Define and Read
PostPosted: Sun Dec 09, 2018 11:43 am 
Offline
Addict
Addict
User avatar

Joined: Thu Jun 07, 2007 3:25 pm
Posts: 3640
Location: Berlin, Germany
@Sicro:
I agree with you.

_________________
Please excuse my flawed English. My native language is PureBasic.
Search
RSBasic's backups


Top
 Profile  
Reply with quote  
 Post subject: Re: Define and Read
PostPosted: Sun Dec 09, 2018 11:56 am 
Offline
Addict
Addict

Joined: Thu Aug 30, 2007 11:54 pm
Posts: 1022
Location: right here
Lord wrote:
Some ideas:
Code:
Define a, b,w, c
; should raise a syntax error, no type on b allowed
should be .w not ,w? I don't like the idea though!
Quote:
Code:
Define.w a, b.i, c
; should raise an syntax error, no type on b allowed

Define.s a, b.i, c
; a, b and c will be of type string (= a.s, b.s, c.s)
Kind of contradictory and i don't like either of them.


Top
 Profile  
Reply with quote  
 Post subject: Re: Define and Read
PostPosted: Sun Dec 09, 2018 5:03 pm 
Offline
Addict
Addict
User avatar

Joined: Mon Jul 25, 2005 3:51 pm
Posts: 3568
Location: Utah, USA
I am in favor of the current ability to mix types on the same line when no default type is specified (i.e. 'Define j.b, k, m.f') but would be in favor of removing the ability to have distinct default along with specific types (i.e. 'Define. b j.f, k, m') because of its potential for confusion and error.

_________________
Image


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 15 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye