test_sugar

204 views
Skip to first unread message

alex;

unread,
Sep 17, 2025, 12:18:38 PMSep 17
to Harbour Users
#xtranslate <c>.Upper() => Qout( Upper( <c> ) )
#xtranslate <c>.Lower() => Qout( Lower( <c> ) )

"harbour".Upper()   // "HARBOUR"
"Harbour".Lower()   // "harbour"

Inkey(0)

alex;

unread,
Sep 17, 2025, 12:30:15 PMSep 17
to Harbour Users
#xtranslate <d>.Day() => Qout( Day( <d> ) )

{^2025-09-17}.Day()

среда, 17 сентября 2025 г. в 19:18:38 UTC+3, alex;:

alex;

unread,
Sep 17, 2025, 12:39:58 PMSep 17
to Harbour Users
LOCAL i
#xtranslate <n>.times => FOR i:=1 TO <n>

3.times

?i

NEXT

среда, 17 сентября 2025 г. в 19:30:15 UTC+3, alex;:

alex;

unread,
Sep 17, 2025, 12:44:30 PMSep 17
to Harbour Users
LOCAL i
#xcommand <n>.times VAR <v> => ;
   FOR <v>:=1 TO <n>

3.times VAR i

?i

NEXT

среда, 17 сентября 2025 г. в 19:39:58 UTC+3, alex;:
Message has been deleted

diego...@gmail.com

unread,
Sep 17, 2025, 1:48:25 PMSep 17
to Harbour Users
#xtranslate <!name!>.<func>([<p,...>]) => <func>(<name>[,<p>])
#xtranslate <!name!>.<func1>([<p1,...>]).<func2>([<p2,...>]) => <func2>(<func1>(<name>[,<p1>])[,<p2>])
#xtranslate <!name!>.<func1>([<p1,...>]).<func2>([<p2,...>]).<func3>([<p3,...>]) => <func3>(<func2>(<func1>(<name>[,<p1>])[,<p2>])[,<p3>])

cVar := "Hello"
? cVar.Upper()                      // HELLO
? cVar.Substr(1,2)                  // He
? cVar.Upper().Substr(1,2)          // HE
? cVar.Upper().Substr(1,2).Left(1)  // H

Diego.

carloskds

unread,
Sep 17, 2025, 2:13:49 PMSep 17
to Harbour Users

En xharbour estoy es posible usando las instrucciones de extender clases, con la clase character se le agregan esos métodos y ya es posible usar la sintaxis similar a javaacript. No sé si esto en harbour sea posible de forma nativa o usando la lib xhb.
Sería que unos de los desarrolladores no los indique.

alex;

unread,
Sep 17, 2025, 2:34:32 PMSep 17
to Harbour Users
Hi, Diego.
It's cool.
I will experiment further. 
Maybe with classes for types and iterators. As Carlos said. 
Thanks.

WBR, alex;
среда, 17 сентября 2025 г. в 21:13:49 UTC+3, carloskds:

hmpaquito

unread,
Sep 17, 2025, 4:39:58 PMSep 17
to Harbour Users
Scalar from Victor Cajasuana

carloskds

unread,
Sep 19, 2025, 7:16:47 PMSep 19
to Harbour Users
from xhb-diff.txt from harbour:

###    SCALAR CLASSES    ###
============================
Both compilers support scalar classes and allows to add OOP functionality
to native types like numeric, character, array, hash, codeblock, date, ...
It's possible to overload default scalar classes provided by Harbour and
xHarbour or use ASSOCIATE CLASS command to bound any class with some native
type. It's also possible to overload the behavior of some operators if it's
not already defined for given types. Anyhow it's not possible to change
operator precedence which is the same for all types and defined at compile
time.

example from xharbour: associat.prg

#include "hbclass.ch"

PROCEDURE Main()

   LOCAL cVar := "Funny", nVar := 1

   ASSOCIATE CLASS MyStringClass  WITH TYPE CHARACTER
   ASSOCIATE CLASS MyNumericClass WITH TYPE NUMERIC

   ? cVar:ClassName
   ? nVar:ClassName

   ? cVar:AsString
   ? cVar:Super:AsString
   ? cVar:Character:AsString
   ? cVar:Sub( 1, 3 )
   ? cVar:Version

   cVar := "23"
   ? nVar + cVar

RETURN

CLASS MyStringClass FROM CHARACTER

   // CLASSDATA are allowed, but DATAs are not, as we don't have a real instance for storing such properties.
   CLASSDATA Version INIT "1.0"

   METHOD AsString INLINE "MyString: >" + Self + "<"

   METHOD Sub( nFrom, nLen ) INLINE SubStr( Self, nFrom, nLen )

ENDCLASS

CLASS MyNumericClass FROM NUMERIC

   OPERATOR "+" ARG xArg INLINE Alert( "Adding type: " + ValType( xArg ) ) , Self := Self + Val( xArg )

ENDCLASS

carloskds

unread,
Sep 19, 2025, 7:34:28 PMSep 19
to Harbour Users
mod for harbour

#include "hbclass.ch"

PROCEDURE Main()
   LOCAL cVar := "Funny", nVar := 1

   ASSOCIATE CLASS MyStringClass  WITH TYPE CHARACTER
   ASSOCIATE CLASS MyNumericClass WITH TYPE NUMERIC

   ? cVar:ClassName
   ? nVar:ClassName

   ? cVar:AsString
   //? cVar:Super:AsString
   //? cVar:Character:AsString

   ? cVar:Sub( 1, 3 )
   ? cVar:Version

   cVar := "23"
   ? nVar + cVar

RETURN

CLASS MyStringClass //FROM CHARACTER


   // CLASSDATA are allowed, but DATAs are not, as we don't have a real instance for storing such properties.
   CLASSDATA Version INIT "1.0"

   METHOD AsString INLINE "MyString: >" + Self + "<"

   METHOD Sub( nFrom, nLen ) INLINE SubStr( Self, nFrom, nLen )

ENDCLASS

CLASS MyNumericClass// FROM NUMERIC


   OPERATOR "+" ARG xArg INLINE Alert( "Adding type: " + ValType( xArg ) ) , Self := Self + Val( xArg )

ENDCLASS

Reply all
Reply to author
Forward
0 new messages