Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Square brackets and curly brackets in expressions?
#1
I'm thinking of adding the ability to use curly brackets and square brackets in expressions, along with parentheses, to make complex expressions easier to read.

But not if square brackets (i.e. [ and ] ) and curly brackets (i.e. { and } ) are used in any way as special characters in QB64pe.

Are square brackets and/or curly brackets used for any purpose in QB64pe?  (I haven't noticed any.)
Reply
#2
Not that I know of
45y and 2M lines of MBASIC>BASICA>QBASIC>QBX>QB64 experience
Reply
#3
No I don't think other brackets are used. 

Have you tried spacing out multiple brackets to make it clearer which nest you are in while you type a line in QB64 IDE? It can get confusing while composing.
b = b + ...
Reply
#4
Not in QB64PE yet but:

square bracket had been used for fake array subscript into an allocated block defined by pointer, such as:

Code: (Select All)
int *pa, num;
pa = (int *)calloc(10, sizeof(int));
num = pa[0];  //first element
num = pa[9];  //last element

curly brace had been used in "initializer", ie. define the extent of an array or UDT and then put in the values for each element and/or field.

Even with those grouping characters besides parenthesis, we are still needing code editors highlighting which grouping character is paired with another one...
Reply
#5
(02-13-2023, 05:59 PM)bplus Wrote: No I don't think other brackets are used. 

Have you tried spacing out multiple brackets to make it clearer which nest you are in while you type a line in QB64 IDE? It can get confusing while composing.

Spaces?  That's cute?
Reply
#6
Code: (Select All)
TODELETE=$(( (DISKSIZE - 10000)/1000 ))

This is actually in one of the Bash scripts I use on Linux, which I obtained from one of the member sites of "Stackexchange-dot-com". The double-parenthesis on the outside are absolutely required to do math evaluations in an "ancient" terminal being given too many "modern" features.

The script was to create a large useless file only with ASCII0 in it, to then erase it, to then create a compressed image of the entire disk that Linux was installed into. Good for distro-hoppers like me LOL. This was the original source:

https://unix.stackexchange.com/a/584898
Reply
#7
some of the better IDEs and text editors will highlight opening and closing brackets to make editing expressions a little easier.  There's no shame in using spaces or newlines to break up expressions although the PE ide may squish them together with autoindent enabled which is why I opt for my own formatting.

I would not recommend introducing alternative brackets especially if they are interchangeable.  They sometimes do that in Math but not in Basic which is a practice I personally dislike because the other brackets can sometimes indicate a different purpose in other contexts
Reply
#8
If I may remind, while you remain on the same line of QB64pe the spaces remain spaced until you move onto the next line, THEN the spaces are pushed together. 

And yes, the highlights are helpful in pointing the end bracket for the first on same level or vice versa.
b = b + ...
Reply
#9
(02-13-2023, 05:49 PM)CharlieJV Wrote: I'm thinking of adding the ability to use curly brackets and square brackets in expressions, along with parentheses, to make complex expressions easier to read.

But not if square brackets (i.e. [ and ] ) and curly brackets (i.e. { and } ) are used in any way as special characters in QB64pe.

Are square brackets and/or curly brackets used for any purpose in QB64pe?  (I haven't noticed any.)

Just some samples I'm using to evaluate.

Just enough of a subtle visual cue to see what goes with what.

I think.


Code: (Select All)
PRINT ( [ 1 + 2 ] / [ 3 + 4 ] ) + 5
' vs
PRINT ( ( 1 + 2 ) / ( 3 + 4 ) ) + 5

8 PSET (ix, iy), ( [ix - L] XOR [iy + L] ) XOR ( [ix + L] XOR [iy - L] )
'vs
8 PSET (ix, iy), ( (ix - L) XOR (iy + L) ) XOR ( (ix + L) XOR (iy - L) )

VAL(MID$(M$, [{Y% * 2} * 16] + [X% * 2] + 1, 2))
'vs
VAL(MID$(M$, ((Y% * 2) * 16) + (X% * 2) + 1, 2))

PSET ( [ 160 + COS(A!) * 50 + X% ], [ 100 + SIN(A!) * 50 + Y%] ), this_c
'vs
PSET (160 + COS(A!) * 50 + X%, 100 + SIN(A!) * 50 + Y%), this_c
Reply
#10
Is this something that's being considered to be implemented in QB64PE?

Personally, I would find the use of multiple bracket types confusing in the BASIC dialect. Other languages, such as Python, use square brackets to identify constructs such as tuples which set them apart from evaluations. If I remember correctly I believe curly braces were used in Pascal (Delphi) for comment blocks. I don't believe I've ever run across a language that uses a mix of bracket types for evaluations. Again, my personal opinion, but I believe this would cause confusion.
New to QB64pe? Visit the QB64 tutorial to get started.
QB64 Tutorial
Reply




Users browsing this thread: 3 Guest(s)