Page 1 of 3

A Walrus :=

Posted: Wed Jan 04, 2023 6:34 pm
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

Re: A Walrus :=

Posted: Wed Jan 04, 2023 7:24 pm
by jacdelad
Searching for the keyword "walrus" would have shown a thread where I suggested that a while ago: viewtopic.php?p=587146#p587146

Re: A Walrus :=

Posted: Wed Jan 04, 2023 7:37 pm
by Little John
I like walruses. :)

Re: A Walrus :=

Posted: Wed Jan 04, 2023 8:23 pm
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' :|

Re: A Walrus :=

Posted: Wed Jan 04, 2023 8:33 pm
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

Re: A Walrus :=

Posted: Tue Sep 12, 2023 7:27 pm
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)

Re: A Walrus :=

Posted: Tue Sep 12, 2023 7:43 pm
by Caronte3D
The ":=" reminds me the old Delphi/Pascal days :D

Re: A Walrus :=

Posted: Tue Sep 12, 2023 8:26 pm
by nsstudios
I like the define way too.
Sadly I can't imagine PB getting syntax updates, but one can dream I guess.

Re: A Walrus :=

Posted: Tue Sep 12, 2023 11:45 pm
by Little John
Let Define alone, please!

Re: A Walrus :=

Posted: Wed Sep 13, 2023 7:14 am
by Lord
Please stay BASIC.
There are too many influences from other programming languages lately. :evil:

Re: A Walrus :=

Posted: Wed Sep 13, 2023 9:00 am
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.

Re: A Walrus :=

Posted: Wed Sep 13, 2023 9:59 am
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.

Re: A Walrus :=

Posted: Wed Sep 13, 2023 11:15 am
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

Re: A Walrus :=

Posted: Wed Sep 13, 2023 11:56 am
by jacdelad
We are asking for an addition, not a replacement. Nobody would be forced to use it...

Re: A Walrus :=

Posted: Wed Sep 13, 2023 12:39 pm
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”.