A Walrus :=

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
the.weavster
Addict
Addict
Posts: 1576
Joined: Thu Jul 03, 2003 6:53 pm
Location: England

A Walrus :=

Post by the.weavster »

So that

Code: Select all

Result = OpenFile(#PB_Any, Filename$)
If Result
  ; do work with Result
EndIf
... could be abbreviated to

Code: Select all

If Result := OpenFile(#PB_Any, Filename$)
  ; do work with Result
EndIf
User avatar
jacdelad
Addict
Addict
Posts: 1993
Joined: Wed Feb 03, 2021 12:46 pm
Location: Riesa

Re: A Walrus :=

Post by jacdelad »

Searching for the keyword "walrus" would have shown a thread where I suggested that a while ago: viewtopic.php?p=587146#p587146
Good morning, that's a nice tnetennba!

PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
Little John
Addict
Addict
Posts: 4779
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: A Walrus :=

Post by Little John »

I like walruses. :)
Oso
Enthusiast
Enthusiast
Posts: 595
Joined: Wed Jul 20, 2022 10:09 am

Re: A Walrus :=

Post by Oso »

jacdelad wrote: Wed Jan 04, 2023 7:24 pm Searching for the keyword "walrus" would have shown a thread where I suggested that a while ago: viewtopic.php?p=587146#p587146
This would have been nice tonight. It's 2 am and I'm in the process of going through code converting from OpenFile(n, to OpenFile(#PB_Any, because the software will be moving to 'multiple-user' :|
nsstudios
Enthusiast
Enthusiast
Posts: 309
Joined: Wed Aug 28, 2019 1:01 pm
Location: Serbia
Contact:

Re: A Walrus :=

Post by nsstudios »

Yes please!
It can be kinda done in inlineC, though.

Code: Select all

Define t1, t2
; f_testfunc1() and f_testfunc2() not found if not procedureDll
ProcedureDLL testfunc1(): ProcedureReturn 123: EndProcedure
ProcedureDLL testfunc2(): ProcedureReturn 321: EndProcedure
!if((v_t1=f_testfunc1())==(v_t2=f_testfunc2())) {
;do something
!}
Debug t1
Debug t2
User avatar
yuki
Enthusiast
Enthusiast
Posts: 101
Joined: Sat Mar 31, 2018 9:09 pm

Re: A Walrus :=

Post by yuki »

This would be quite handy especially if it defines the LHS so EnableExplicit is satisfied.

It might simplify this common pattern slightly (less one little line):

Code: Select all

Define x
For x = 0 To limit
  ; ...
Next
Into:

Code: Select all

For x := 0 To limit
  ; ...
Next
Though, I might put forward an alternative syntax suggestion:

Code: Select all

For Define x = 0 To limit
  ; ...
Next

If Define result = OpenFile(#PB_Any, filename$)
  ; do work with result
EndIf
(more verbose but it avoids ":" taking on another responsibility alongside its existing use in subroutines and continuation. it's at least hard to miss)
User avatar
Caronte3D
Addict
Addict
Posts: 1355
Joined: Fri Jan 22, 2016 5:33 pm
Location: Some Universe

Re: A Walrus :=

Post by Caronte3D »

The ":=" reminds me the old Delphi/Pascal days :D
nsstudios
Enthusiast
Enthusiast
Posts: 309
Joined: Wed Aug 28, 2019 1:01 pm
Location: Serbia
Contact:

Re: A Walrus :=

Post by nsstudios »

I like the define way too.
Sadly I can't imagine PB getting syntax updates, but one can dream I guess.
Little John
Addict
Addict
Posts: 4779
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: A Walrus :=

Post by Little John »

Let Define alone, please!
User avatar
Lord
Addict
Addict
Posts: 900
Joined: Tue May 26, 2009 2:11 pm

Re: A Walrus :=

Post by Lord »

Please stay BASIC.
There are too many influences from other programming languages lately. :evil:
Image
User avatar
the.weavster
Addict
Addict
Posts: 1576
Joined: Thu Jul 03, 2003 6:53 pm
Location: England

Re: A Walrus :=

Post by the.weavster »

Caronte3D wrote: Tue Sep 12, 2023 7:43 pm The ":=" reminds me the old Delphi/Pascal days :D
The idea was really from Python PEP 572
yuki wrote: Tue Sep 12, 2023 7:27 pm Though, I might put forward an alternative syntax suggestion:

Code: Select all

If Define result = OpenFile(#PB_Any, filename$)
  ; do work with result
EndIf
If an alternative syntax is considered to be more BASIC that's cool, I'd just like to see that pattern, which is common in PB, compressed.
BarryG
Addict
Addict
Posts: 4135
Joined: Thu Apr 18, 2019 8:17 am

Re: A Walrus :=

Post by BarryG »

Lord wrote: Wed Sep 13, 2023 7:14 amPlease stay BASIC.
There are too many influences from other programming languages lately. :evil:
100% agreed. I chose PureBasic for BASIC.
User avatar
the.weavster
Addict
Addict
Posts: 1576
Joined: Thu Jul 03, 2003 6:53 pm
Location: England

Re: A Walrus :=

Post by the.weavster »

BarryG wrote: Wed Sep 13, 2023 9:59 am
Lord wrote: Wed Sep 13, 2023 7:14 amPlease stay BASIC.
There are too many influences from other programming languages lately. :evil:
100% agreed. I chose PureBasic for BASIC.
Image
User avatar
jacdelad
Addict
Addict
Posts: 1993
Joined: Wed Feb 03, 2021 12:46 pm
Location: Riesa

Re: A Walrus :=

Post by jacdelad »

We are asking for an addition, not a replacement. Nobody would be forced to use it...
Good morning, that's a nice tnetennba!

PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
Little John
Addict
Addict
Posts: 4779
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: A Walrus :=

Post by Little John »

jacdelad wrote: Wed Sep 13, 2023 11:56 am Nobody would be forced to use it...
Well, that depends on your definition of “usage”.
Post Reply