Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
    Paul M Cohen
    @paul1956
    In both cases about if you pass a string with the value "" it will return "" and if you pass a string = Nothing it will return otherwiseusethis. There are 2 helper functions in String class that should be used to get consistent behavior. String.IsNullOrEmpty and String.IsNullOrWhiteSpace.
    Adam Speight
    @AdamSpeight2008

    To test to see if a value is within a range of numbers, we can use a simple expression like min <= value and value <= max.
    Is there an equivalent expression to test if a value is within a range that uses a stepping.
    I think the following function would suffice, for ascending range. ​Not too sure about descending ranges.

        <extension>
        function IsBewteen( value As Integer, min As Integer, max As Integer, stepping As Integer) As BooleanIf min <= max Then
                If stepping <= 0 Then Throw New ArgumentOutOfRangeException(NameOf(stepping), "Must have a non-zero positive value.")
            Return ((min <= value) And (value <= max)) AndAlso ( (value Mod stepping) = (min Mod stepping) )
            Else
                If stepping >=0 Then Throw New ArgumentOutOfRangeException(NameOf(stepping), "Must have a non-zero negative value.")
                Return value.IsBewteen(max, min, -stepping)
    ​     End IFEnd Function

    There is still an issue around the Integer.MinValue and Integer.MaxValue, any suggestion on how to manage them with out resorting to enclosing it in a try ... catch block?

    Mohammad Hamdy Ghanem
    @VBAndCs
    Are the community willing to take over ghe fate of vb?
    Cory Smith
    @DualBrain
    @VBAndCs ummm, because people like @paul1956 and I (to mention a couple) are doing nothing to improve VB directly... nothing at all.
    Paul M Cohen
    @paul1956
    @AdamSpeight2008 what is "an issue around the Integer.MinValue and Integer.MaxValue, any suggestion on how to manage them with out resorting to enclosing it in a try ... catch block?"
    John Moreno
    @jrmoreno1
    @AdamSpeight2008: just the obvious of checking against min/max manually, be a bit complicated but doable
    Are allowing arbitrary step size?
    Paul M Cohen
    @paul1956
    I don't understand purpose of stepping
    CyrusNajmabadi
    @CyrusNajmabadi
    me neither
    what is the use case where you are doing a range check.. and you have some concept of a step?
    John Moreno
    @jrmoreno1
    Find the difference between min/max and then compare that to step and MaxValue-value
    CyrusNajmabadi
    @CyrusNajmabadi
    when is that useful?
    when would i use IsBewteen?
    John Moreno
    @jrmoreno1
    @CyrusNajmabadi : don’t know his use case, but it could be useful when examining a for loop with a step
    Although I have never had a for/step with values anywhere near the limits….
    CyrusNajmabadi
    @CyrusNajmabadi
    i'm asking what hte use case is because i don't understand it :)
    i genuinely can't even figure out what that code really does :)
    Paul M Cohen
    @paul1956
    I think it is for a "For i as byte = Byte.Min to Byte.Max Step anything" and I don't believe it ever worked correctly in VB when step is used especially when it is negative. But I can't point out what is broken, there was a bug report when I first started looking a Roslyn. This goes back a very long time and I have never used it.
    CyrusNajmabadi
    @CyrusNajmabadi
    i understand stepping in teh context of a for loop
    it's how the value is incremented/decremented at the end of each pass.
    what i don't undertand is hte IsBewteen method and what it does
    Paul M Cohen
    @paul1956
    I think it was proposed to replace the For loop to handle the edge cases. While i.Inbetween(Byte.Min, Byte.Max, Step:=2) But maybe Adam had something else in mind.
    Adam Speight
    @AdamSpeight2008

    I want to fairly efficiently to check if a value, is within two bounds but that range isn't continuous but has a regular stepping.
    start := 0, finish := 10, stepping:= 2' Ifvalue:=2then return true. Ifvalue=7` return false.
    The following works, assuming we if pass in arguments that satisfies the for loop conditions.

    Function IsBetween(value as Integer, start As Integer, finish As Integer, stepping As Integer ) As Boolean
      For index = start To finish Step stepping
        If index = value Then Return True
      Next
      Return False
    End Function

    But it is rather inefficient, since we could check if a value is within some bounds simply using Math.Min(start, finish) <= value and value<=Math.Max(start, finish). But this doesn't take into account a stepping. My question is, "Is there an efficient way to do that?"

    CyrusNajmabadi
    @CyrusNajmabadi
    why do you need the for loop?
    ignoring negatives for now, isn't this just seeing if the distance from start to your value is a integer multiple of your step?
    so like... (value - start) % step == 0?
    you're basically asking: could i step an exact number of times from start and that added to start would equal value.
    Mohammad Hamdy Ghanem
    @VBAndCs
    I am adding new language features to small basic, such as indexing string x[0]. This one was easy as i am working on the sb vetsion that has no runtime. It just generates il code which calls the methods of the primitive class to do every thing. So i just modified the primative class to ondex the string with some more fantastic features when calling the indexer setter, like padding spaces when the index is negative or greater that the string length, and allowing setting a string with any lingth i
    I am now trying to add array initializer
    I did the parsing part smoothly and it allows nested {}
    The code compiles fine, but of couse i don't know how to emit il code for that!
    I can't use a method in the premative class because sb will not accept param array
    Ineed to do it at the il level
    A work arroun is to lower the initializer to many arrat cells assignment
    Mohammad Hamdy Ghanem
    @VBAndCs
    But this will mess with the line numbers in err messages
    So, il it is
    Any idea where to begin reading?
    It can seem daunting at first.
    But it's actually super simple
    And then you realize there's no magic here. Just a lot of basic opcodes that do sensible things
    Cory Smith
    @DualBrain
    @CyrusNajmabadi 👍
    Mohammad Hamdy Ghanem
    @VBAndCs
    Thanks @CyrusNajmabadi
    I already solved the issue and aray initializerscworks now in sb (will puplish it in minutes) :)
    I totakly avoided il. I tried to deliver to the il generator only the syntax it understands
    So, i loweted the code in the emit phase to avoid altering the source code text
    Mohammad Hamdy Ghanem
    @VBAndCs
    To do that, i cteated the lowed code as a separit code, parsed and analyzed it, then added the resuling info to the original compilation,. Finally i used the same generator scope to emit il for the new parse tree of the lowered code
    And since i am already in the middle of ghe emmit phase, the il for the lowered code is its right pos, and of course i don't emit anything for the original array initializer
    Il spy is a grate help, since i used it to figure out what i did wrong in emmiting il.