Code: Select all
with myVar
this = value 'this refers to myVar
end with
Code: Select all
with myArray(a,b,c)
this=value 'this refers to myArray(a,b,c)
end with
Code: Select all
with myVar
this = value 'this refers to myVar
end with
Code: Select all
with myArray(a,b,c)
this=value 'this refers to myArray(a,b,c)
end with
Code: Select all
select case something.somethingelse[0].somethingfurther
case 0,1,2,3,4,5:
if (This=2)then
print "stuff specific to 2"
endif
print "stuff related to the other cases and 2"
case Is<0:
select case This
case -1:
print "serious error!"
case -2:
print "Abort now!"
end select
end select
Code: Select all
dim as integer myReallyLongFoo(0 to 9, 0 to 9)
with myReallyLongFoo(5, 2) as bar
bar = 10
end with
Code: Select all
Dim As Integer myReallyLongFoo(0 To 9, 0 To 9)
dim as integer ptr bar = myReallyLongFoo(5, 2)
*bar = 10
Code: Select all
#define this_myudt *cptr(my_udt ptr, @.myudtsfirstelement)
It looks to me like type forwarding. I consider my suggestion to be derived/extended from this idea.anonymous1337, your syntax is unambiguous, but it doesn't feel very "BASIC": it looks like "Bar" is supposed to be a Type name.
So it's really just a syntax issue:I've toyed around with a few syntax ideas, but I'm not sure I like any of them. Maybe allow (With) or (Case) in expressions
Code: Select all
with myVar
expr=value
end with
select case myVar
case 10: expr=value
case else
end select
thisWith and thisCase are simply extensions of this which is already a keyword. There's is already a precedent for this in the language with keywords such as: file*, screen*, val*, window*, etc. Personally I feel it works as BASIC syntax and it's easy to read and understand:Simply adding a new keyword would further pollute the namespace though, and none of those suggestions really gel with me.
Code: Select all
with myVar
thisWith=value
end with
select case myVar
case n: thisCase=value
end select
Code: Select all
with myVar
that = value 'that refers to myVar
end with
Code: Select all
with myArray(a,b,c)
that=value 'that refers to myArray(a,b,c)
end with
Code: Select all
sub Foo.bas( byref that as Foo )
this.x = that.x
end sub
theOtherThing = UR_MOMnotthecheatr wrote:Hmm. Why not, just for fun, make a that keyword?
Code: Select all
'replacing "with mydata"
dim as myudt ptr withVar = @mydata
with *withVar
*withVar = [something else]
end with
Code: Select all
' Replacing "with x" v1.0
' By Kristopher Windsor
#define wit(v) Scope: Dim As TypeOf(v) Ptr witVarPtr = @v: With *witVarPtr
#define endWit End With: End Scope
#define witVar *witVarPtr
Type x_type
Declare Sub show ()
As Integer a, b
End Type
Sub x_type.show ()
Print a, b
End Sub
#define showall() Print: Print "Vars: ": x.show(): y.show(): z.show(): Print
Dim As x_type x = Type(3, 4), y = Type(5, 6), z = Type(7, 8)
showall()
wit(x)
.show()
witVar = y
showall()
.show()
Swap witVar, z
showall()
.show()
wit(y)
.show()
endWit
endWit
Sleep
Code: Select all
' Replacing "Select Case a" v1.0
' By Kristopher Windsor
#macro selectCase(v)
Scope
Dim As TypeOf(v) SCVarTemp = v
Scope
Dim As TypeOf(v) thisCase = SCVarTemp
Select Case thisCase
#endmacro
#define endSelect End Select: End Scope: End Scope
Dim As String a = "apple", b = "boom", c = "pizza!!!"
selectCase(a)
Case "purple"
'
Case "apple", "boom"
Print "apple? " & thisCase
thisCase = "happy"
Print "happy? " & thisCase
selectCase(c)
Case "55"
'
Case "pizza!!!"
Print "pizza!!!? " & thisCase
selectCase(thisCase + " owns")
Case "?"
'
Case Else
Print "does pizza own? " & thisCase
endSelect
Print "now the case should be pizza!!! again: " & thisCase
thisCase = "deleted variable"
endSelect
Print "now the case should be happy again: " & thisCase
Case Else
'
endSelect
Sleep
:( Why can't you just use nice variable names like everybody else?anonymous1337 wrote:I constantly use that as a variable name.You'd break nearly all of my code.Code: Select all
sub Foo.bas( byref that as Foo ) this.x = that.x end sub
And notthecheatr, that doesn't solve our problem. I'm not sure what you were getting at. If we're going to change syntax to support with as varname, we might as well support nested withs with varnames as well.
Code: Select all
#define withAs(x, y) scope: dim as typeof(x) ptr y = @x
#define endWithAs() end scope
dim as integer fooreallylonglong(0 to 5, 0 to 9)
dim as integer barreallylonglong(0 to 3, 0 to 13)
fooreallylonglong(3, 5) = 20
barreallylonglong(1, 9) = 10
barreallylonglong(3, 4) = 5
withAs(fooreallylonglong(3, 5), foo)
withAs(barreallylonglong(1, 9), bar)
print "Foo in bar scope: " & *foo
print "Bar in bar scope: " & *bar
endWithAs()
withAs(barreallylonglong(3, 4), baz)
print "Foo in baz scope: " & *foo
print "Bar in baz scope: " & *baz
endWithAs()
print "Foo in foo scope: " & *foo
'' print *bar ' errors as it should
endWithAs()
sleep