How hard could be to add block scoped vars to Harbour?

202 views
Skip to first unread message

Lorenzo Fiorini

unread,
Mar 12, 2024, 5:46:20 AMMar 12
to harbou...@googlegroups.com
IMHO it is one of the major "divergence" between Harbour and the other
"popular" languages: having to declare local vars ONLY at the top of the
function.

Is there anyone that knows the compiler internals that could give me an
idea where to start to look?

best regards,
Lorenzo

--

Il presente messaggio è indirizzato esclusivamente ai destinatari. Tutte le informazioni
contenute, compresi eventuali allegati, sono confidenziali ai sensi del Regolamento (UE)
2016/679 e del D. Lgs. 196/2003. Pertanto ne sono vietati l'inoltro, la divulgazione e la
messa a disposizione in qualunque forma o modo, in mancanza di preventiva autorizzazione
del mittente. Qualora il messaggio Le fosse pervenuto per errore, La invitiamo cortesemente
ad eliminarlo in modo definitivo dando immediato riscontro.

This message is exclusively addressed to the recipients. All the information contained in this
message, including any attachments, is confidential in compliance with Regulation (UE)
2016/679 and Legislative Decree 196/2003. Therefore, forwarding, disclosing and making
the above-mentioned information available without prior authorization from the sender is
forbidden in any form or manner. If you have received this message in error, we kindly invite
you to delete it permanently and to notify the sender.
--

Bacco

unread,
Mar 12, 2024, 10:46:06 AMMar 12
to harbou...@googlegroups.com
Hi, Lorenzo

Just don't forget Harbour is Cl*pper compatible, probably even if you
find a way, you'll need to mantain your fork.

I also don't use Harbour as Cl*pper, and don't care with Cl*pper compat,
so I understand the pain, anyway, but it is what it is :D - Perhaps some
day we get traciton to do a 'modern harbour', but I don't see this trend
yet.

For me a simple "End Function" would help a lot to at least declare
statics and help including things between functions and program sections.
Anyway, please share if you have any success.

Regards
Bacco









--
You received this message because you are subscribed to the Google Groups "Harbour Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to harbour-deve...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/harbour-devel/093af8d8-b463-460f-ab0a-e49af44dd0a8%40gmail.com.

marcosgambeta

unread,
Mar 12, 2024, 1:19:14 PMMar 12
to Harbour Developers
Lorenzo,

Are you talking about something like this ?

FUNCTION Main()

   Test()

RETURN NIL

#define BEGINBLOCK Eval({||
#define ENDBLOCK   })

STATIC FUNCTION Test()

   LOCAL a := 0

   ? "a=", a

   BEGINBLOCK
      LOCAL b := 1
      LOCAL c := 2
      ? "in block 1"
      ? "b=", b
      ? "c=", c
      a := a + b + c
      ? "a=", a
      ? "out block 1"
   ENDBLOCK

   ? "a=", a

   BEGINBLOCK
      LOCAL b := 3
      LOCAL c := 4
      ? "in block 2"
      ? "b=", b
      ? "c=", c
      a := a + b + c
      ? "a=", a
      BEGINBLOCK
         LOCAL b := 5
         LOCAL c := 6
         ? "in block 3"
         ? "b=", b
         ? "c=", c
         a := a + b + c
         ? "a=", a
         ? "out block 3"
      ENDBLOCK
      ? "b=", b
      ? "c=", c
      ? "a=", a
      ? "out block 2"
   ENDBLOCK

   ? "a=", a

RETURN NIL

Note that I am only simulating the idea using Eval and codeblocks.

Regards,
Marcos Gambeta

Enrico Maria Giordano

unread,
Mar 12, 2024, 1:47:22 PMMar 12
to harbou...@googlegroups.com


Il 12/03/2024 18:19, marcosgambeta ha scritto:

> Lorenzo,
>
> Are you talking about something like this ?

It seems a good idea to me!

--
Enrico Maria Giordano

http://www.emagsoftware.it
http://www.emagsoftware.it/emgmusic
http://www.emagsoftware.it/spectrum
http://www.emagsoftware.it/tbosg

Lorenzo Fiorini

unread,
Mar 12, 2024, 3:51:08 PMMar 12
to harbou...@googlegroups.com
Hello everybody, I’m just looking for a “normal” behavior like:

- if at line 324 of a function you need a var i for a loop, you don’t need to jump to line 2 to add “local i”

- even better would be sth like:
….
const i := “Hello”
const a := true

for let i := 1 to 100
 …
   let a := i+1
next

so we could leave static and local as they are now and everyone would be free to use the new syntax or not.
--
You received this message because you are subscribed to the Google Groups "Harbour Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to harbour-deve...@googlegroups.com.

oleksa

unread,
Mar 12, 2024, 3:59:34 PMMar 12
to harbou...@googlegroups.com
Hi,

Look at ###    EXTENDED CODEBLOCKS    ### in https://github.com/harbour/core/blob/master/doc/xhb-diff.txt
...
In Harbour extended codeblocks works like nested functions and supports
all function attributes, f.e. they can have own static variables or
other declarations which are local to extended codeblocks only and
do not effect upper function body.
...

Regards,
Oleksii

12 березня 2024, 21:51:09, від "Lorenzo Fiorini" <lorenzo...@gmail.com>:

Reply all
Reply to author
Forward
0 new messages