For var in (string1, string, string3)

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
elwood
User
User
Posts: 30
Joined: Tue Dec 27, 2016 4:40 pm
Location: Lyon, France

For var in (string1, string, string3)

Post by elwood »

Such feature would be great in PB:

For os in ("Windows", "Linux", "MacOS")
Debug "PB is available for " + $os
Next
AmigaOS betatester
French Amiga Translation Team
Team for the Planet member
User avatar
Caronte3D
Addict
Addict
Posts: 1355
Joined: Fri Jan 22, 2016 5:33 pm
Location: Some Universe

Re: For var in (string1, string, string3)

Post by Caronte3D »

Code: Select all

  NewMap OS.s()

  OS("W") = "Windows"
  OS("L") = "Linux"
  OS("M") = "MacOS"

  ForEach OS()
    Debug "PB is available for " + OS()
  Next
User avatar
Mijikai
Addict
Addict
Posts: 1517
Joined: Sun Sep 11, 2016 2:17 pm

Re: For var in (string1, string, string3)

Post by Mijikai »

Something:

Code: Select all

DataSection:Data.s "Windows","Linux","MacOs":EndDataSection
For i = 0 To 2
 Read.s s.s:Debug s
Next
User avatar
Caronte3D
Addict
Addict
Posts: 1355
Joined: Fri Jan 22, 2016 5:33 pm
Location: Some Universe

Re: For var in (string1, string, string3)

Post by Caronte3D »

:P

Code: Select all

OS.s= "Windows,Linux,MacOs"
For i = 1 To CountString(OS, ",")+1
 Debug StringField(OS, i, ",")
Next
User avatar
mk-soft
Always Here
Always Here
Posts: 6207
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: For var in (string1, string, string3)

Post by mk-soft »

There are many ways to do this.
LinkedList also maintains the order.

"For xyz in list" comes more from vb programming and requires an object list.

Code: Select all

Macro AddElementValue(_List_, _Value_)
  AddElement(_List_) : _List_ = _Value_
EndMacro

NewList OS.s()

AddElementValue(OS(), "Windows")
AddElementValue(OS(), "Linux")
AddElementValue(OS(), "MacOS")

ForEach OS()
  Debug OS()
Next
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Quin
Addict
Addict
Posts: 1127
Joined: Thu Mar 31, 2022 7:03 pm
Location: Colorado, United States
Contact:

Re: For var in (string1, string, string3)

Post by Quin »

This would actually be quite nice, but we can't even declare arrays inline, I very highly doubt we're going to get convenience features like this :(

Seems the PB team doesn't really care about syntax sugar and other things that would make code so much shorter. Not a position I personally agree with, but it's their project.
elwood
User
User
Posts: 30
Joined: Tue Dec 27, 2016 4:40 pm
Location: Lyon, France

Re: For var in (string1, string, string3)

Post by elwood »

Thanks everyone for the ideas.
I tend to think our suggestions could make a better Purebasic but I just read this thread so I now understand it will not happen.
I wonder why some people think everything should be free. Our meal is not free, neither our car is, so...
AmigaOS betatester
French Amiga Translation Team
Team for the Planet member
User avatar
Demivec
Addict
Addict
Posts: 4260
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: For var in (string1, string, string3)

Post by Demivec »

elwood wrote: Thu Jan 04, 2024 12:11 am I wonder why some people think everything should be free. Our meal is not free, neither our car is, so...
IMHO, your pondering seems a little bit off the mark. There was a purchase and what was purchased is what is being expected and also what is being provided, nothing more and nothing less. To Fred and the PureBasic Team's credit, it is a genuine bargain and a treasure. I am not alone in advocating for showing appreciation, support, encouragement and so forth through generous contributions if one is able to. Others contribute to the value of PureBasic in other ways, including in the forums.
AZJIO
Addict
Addict
Posts: 2143
Joined: Sun May 14, 2017 1:48 am

Re: For var in (string1, string, string3)

Post by AZJIO »

Quin wrote: Mon Sep 11, 2023 12:52 am This would actually be quite nice, but we can't even declare arrays inline, I very highly doubt we're going to get convenience features like this :(

Seems the PB team doesn't really care about syntax sugar and other things that would make code so much shorter. Not a position I personally agree with, but it's their project.
1. Then you get a function by combining two logical operations, then what if you need only one logical operation? You will also waste time doing unnecessary operations (assigning an empty string when it is not required).
2. If you create new functions every time, you will have to support them. Sources will become incompatible due to differences in functions. In this case, you can create a library of new functions created on the basis of PureBasic. For example, you can take functions from different programming languages ​​and make their analogues by writing them in the PureBasic language, so that those people who came from another programming language do not feel the limitations and are immediately provided with greater opportunities.

For example, make a "slice" function from the "js" programming language

Code: Select all

var sString = "Hello";
sString = sString.slice(-4,-2)
WScript.Echo(sString);
Post Reply