[Gambas-user] print does not output if the var is FALSE, how to override?

Tobias Boege taboege at gmail.com
Fri Jun 29 21:59:58 CEST 2018


On Fri, 29 Jun 2018, PICCORO McKAY Lenz wrote:
> BTW, I personally wouldn't write the function like that in the first place.
> > You only get in trouble because the returned datatype depends on the
> > argument.
> >
> yeah now i got "T" for match case but still "null" or empty for false!
> 

Then something is still using CStr() instead of Str$() to do the string
comparison.

> > I would write it like this:
> >
> >   Public Function email(texto As Variant) As Boolean
> >     ' For performance: compile the pattern once and cache it
> >     Return texto Match "^[A-Za-z0-9._%+-]+@[A-Za-z0-
> > 9.-]+\\.[A-Za-z]{2,8}$"
> >   Endif
> >
> > and use it to actually branch in the code that wants to do something
> > with texto. But if you really value the one-liner here, there's probably
> > no other choice.
> >
> that's horrible, i think its a bug now! as you can see in the previously
> code!

Please test the script I attach so we can see if the behaviour has changed
between your Gambas and mine. I just did a `git log --grep print -i v3.9.0.. -- main`
and couldn't find any mention of PRINT having changed. Also notice that the
PRINT documentation says:

  The expressions are converted to strings by the Str$ function.

That wiki page doesn't even have a "historic" button, so it wasn't changed
in a very long time, at least since 2014 apparently [ because the Language
Overview has historic records of 2014 ].

The expected output is this:

  $ ./false.gbs3
   y este email at mail.com
  False y este email at mail.com
   y este T
  False y este True
  False y este True

Regards,
Tobi

-- 
"There's an old saying: Don't change anything... ever!" -- Mr. Monk
-------------- next part --------------
#!/usr/bin/env gbs3

Use "gb.pcre"

Public Function email(texto As Variant) As Variant
  Dim regex As New RegExp
  Dim strPattern As String = "^[A-Z0-9._%+-]+@[A-Z0-9.-]+\\.[A-Z]{2,8}$"

  If regex.Match(texto, strPattern, regex.Caseless) = True Then
    Return texto
  Endif
  Return False
End

Public Function email2(texto As Variant) As Boolean
  ' For performance: compile the pattern once and cache it
  Return texto Match "^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,8}$"
End

Public Sub Main()
  Print email("mpes") & " y este " & email("email at mail.com")
  Print email("mpes");; "y este";; email("email at mail.com")
  Print email2("mpes") & " y este " & email2("email at mail.com")
  Print Str$(email2("mpes")) & " y este " & Str$(email2("email at mail.com"))
  Print email2("mpes");; "y este";; email2("email at mail.com")
End


More information about the User mailing list