Arrays and Multilines

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
Marlin
Enthusiast
Enthusiast
Posts: 406
Joined: Sun Sep 17, 2006 1:24 pm
Location: Germany

Re: Arrays and Multilines

Post by Marlin »

Using extra variables of course counts as extra instructions to me.
Kaeru Gaman wrote:first setting up the parameters with descriptive names and then making the Call is way more readable to me than a split line without any hint what is what
You are right on that, when it comes to seeing what parameter belongs to what.

However I still would like to have a choice.

And even with your "variables with names like parameter names" approach
lines could get to long for limited screen widths.

On the other side, you than have to look above, to see how you built the value,
now used as a parmeter.
(Could be considered good or not so good depending on the one looking as well as on the circumstances)

PureBasic allows you to find out which parameter is what, by using the status line, too.
That might in many cases be good enough.
People also might know the parameters of their generally used procedures by heart...
Little John
Addict
Addict
Posts: 4777
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: Arrays and Multilines

Post by Little John »

Kale wrote:'_' looks horrid btw. It doesn't matter where you put it.
This is your personal taste, which is not shared by everyone. Especially not by people who are used to old BASIC syntax, where line continuation by '_' is fairly normal.
Saying wrote:There's no accounting for taste.
Kale wrote:surely these things can be handled via a pre-processor and then people can choose their own character?
Using my preprocessor LPP, this can easily be done. You can choose e.g. '&' for line continuation, or even whole expressions such as "line is continued", if you like. :-)

BTW:
The next version of LPP will also allow for elegant assignment of 1-dimensional arrays, e.g.

Code: Select all

a() = {7,3,5,8}
instead of

Code: Select all

a(0) = 7
a(1) = 3
a(2) = 5
a(3) = 8
and e.g.

Code: Select all

a(1..3) = {3,5,8}
instead of

Code: Select all

a(1) = 3
a(2) = 5
a(3) = 8
Regards, Little John
Marlin
Enthusiast
Enthusiast
Posts: 406
Joined: Sun Sep 17, 2006 1:24 pm
Location: Germany

Re: Arrays and Multilines

Post by Marlin »

Little John wrote:The next version of LPP will also allow for elegant assignment of 1-dimensional arrays, e.g.

Code: Select all

a() = {7,3,5,8}
Nice.

The problem with individual changes to a language is,
that code snippets are not compatible for interchange with other users.
Little John
Addict
Addict
Posts: 4777
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: Arrays and Multilines

Post by Little John »

Marlin wrote:The problem with individual changes to a language is,
that code snippets are not compatible for interchange with other users.
Yes, I agree.
However, as far as line continuation is concerned, I just couldn't live without it anymore. :-)

Regards, Little John
Marlin
Enthusiast
Enthusiast
Posts: 406
Joined: Sun Sep 17, 2006 1:24 pm
Location: Germany

Re: Arrays and Multilines

Post by Marlin »

Little John wrote:However, as far as line continuation is concerned, I just couldn't live without it anymore. :-)
I certainly can understand that. :)

Me current suggestion, to be able to spread a logical code line across
multiple text lines in PureBasic, is to use an area of text between a start marker
and an end marker.

Just before the start of compilation, those markers as well as all line breaks
between them are replaced by space characters ("removed").

That should be a very flexible solution to users, as well as rather easy to implement.

Code: Select all

{
anything between
the start
and the end marker
belongs to
the same logical
code line
}
would be treated by the compiler as:

Code: Select all

anything between the start and the end marker belongs to the same logical code line
User avatar
DoubleDutch
Addict
Addict
Posts: 3220
Joined: Thu Aug 07, 2003 7:01 pm
Location: United Kingdom
Contact:

Re: Arrays and Multilines

Post by DoubleDutch »

I don't think you would need a continuation character. The compiler just needs to be made a little smarter - Ruby handles multilines without continuation characters without a problem. Here is how it could work:

Code: Select all

SelectElement(x_dir_file(),n)
If ( save_excludesnapshots And x_matchpattern(x_dir_file(),"*.pb.*.snapshot*.bak",#x_parse_anycase) ) Or
    ( save_excludebuilds And x_matchpattern(x_dir_file(),"*.pb.*.build*.bak",#x_parse_anycase) )
Else
  RenameFile(path+x_dir_file(),path+name+"."+x_strex(save_nr,save_mask)+".wrap.bak")
  save_nr = save_nr+1
EndIf
Because the 'Or' is expecting a parameter on it's right (but it is at the end of line) then the following line is checked for appended automatically.

Here is another example:

Code: Select all

msg$="WARNING:"+#CRLF$+#CRLF$+
    AppName$+" is already running."+#CRLF$+#CRLF$+
    "You may have 'hidden' it!  You can unhide by click the "+AppName$+" logo (the A+) on your taskbar (near the clock)."+#CRLF$+#CRLF$+
    "You cannot install with "+AppName$+" running at the same time."+#CRLF$+#CRLF$+
    "You should close "+AppName$+" then click 'Yes' or stop this install program by clicking 'No'..."+#CRLF$+#CRLF$+
    "Have you closed "+AppName$+" and want to continue installing?"
If QuestionMessage(msg$)=#PB_MessageRequester_No
  End
EndIf
But if it was made even a little smarter then the compiler could also accept this:

Code: Select all

msg$="WARNING:"+#CRLF$+#CRLF$ 
    +AppName$+" is already running."+#CRLF$+#CRLF$ 
    +"You may have 'hidden' it!  You can unhide by click the "+AppName$+" logo (the A+) on your taskbar (near the clock)."+#CRLF$+#CRLF$
    +"You cannot install with "+AppName$+" running at the same time."+#CRLF$+#CRLF$
    +"You should close "+AppName$+" then click 'Yes' or stop this install program by clicking 'No'..."+#CRLF$+#CRLF$
    +"Have you closed "+AppName$+" and want to continue installing?"
If QuestionMessage(msg$)=#PB_MessageRequester_No
  End
EndIf
This this example the compiler (before finishing processing the current line) checks the following line to see if it expects a parameter on its left. Here is another example of what woould also work if this was implemented:

Code: Select all

If OpenWindow(0, 100, 200, 195, 260, "PureBasic Window",
   #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget)
This is how Ruby appears to work, it's all just automatic and intuative.

If it was made even smarter (by getting rid of CR's altogether) then even this could work:

Code: Select all

If a=b a=c Else c=a EndIf
That would be pretty nice too.
https://deluxepixel.com <- My Business website
https://reportcomplete.com <- School end of term reports system
User avatar
Demivec
Addict
Addict
Posts: 4260
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: Arrays and Multilines

Post by Demivec »

DoubleDutch wrote:If it was made even smarter (by getting rid of CR's altogether) then even this could work:

Code: Select all

If a=b a=c Else c=a EndIf
That would be pretty nice too.
@DoubleDutch: I was with you all the way until that last code sample.:wink: I think the last example is something I definitely would not like to see.
User avatar
DoubleDutch
Addict
Addict
Posts: 3220
Joined: Thu Aug 07, 2003 7:01 pm
Location: United Kingdom
Contact:

Re: Arrays and Multilines

Post by DoubleDutch »

It would be a side effect of getting rid of CR as a delimiter. Some would like it, other may not. It's just like ':', I don't use it that much.
https://deluxepixel.com <- My Business website
https://reportcomplete.com <- School end of term reports system
Post Reply