Not clear about this syntax

New to FreeBASIC? Post your questions here.
Post Reply
rnbas
Posts: 35
Joined: Jul 22, 2019 18:54

Not clear about this syntax

Post by rnbas »

I saw Fl_Tile01.bas file from fltk-c-1.3.3 :

Code: Select all

#include once "fltk-c.bi"
' test of:
' Fl_Tile    http://www.fltk.org/doc-1.3/classFl__Tile.html

'
' main
'
var win = Fl_Double_WindowNew(512,512,"drag the lines or the cross in the middle")
var w   = Fl_WidgetGetW(win)		' WHAT IS "var" IN THESE LINES? <<<<<<<<<<<<
var h   = Fl_WidgetGetH(win)
var til = Fl_TileNew(0,0,w,h)
Fl_TileBegin til       ' WHAT KIND OF LOOP IS THIS? <<<<<<<<<<<
  w=w\2 : h=h\2      ' WHAT DOES COLON (:) MEAN HERE <<<<<<<<<<
  Fl_WidgetSetBox Fl_Round_ClockNew(0,0,w,h),BoxType(FL_DOWN_BOX)  ' IS Fl_WidgetSetBox A FUNCTION? <<<<<<<<<<<<
  Fl_WidgetSetBox Fl_Round_ClockNew(w,0,w,h),BoxType(FL_DOWN_BOX) '  WHAT DOES COMMA MEAN? <<<<<<<<<<
  Fl_WidgetSetBox Fl_Round_ClockNew(0,h,w,h),BoxType(FL_DOWN_BOX)
  Fl_WidgetSetBox Fl_Round_ClockNew(w,h,w,h),BoxType(FL_DOWN_BOX)
Fl_TileEnd til			' IS THIS A FUNCTION CALL WITHOUT BRACKETS ()? 
Fl_GroupResizeable win,til	' IS THIS ALSO A FUNCTION CALL? WHY A COMMA HERE?
Fl_WindowSizeRange win,256,256
Fl_WindowShow win
Fl_Run
There are many syntax points that I found different from usual freebasic syntax. I have written them as comments in code above and marked with: <<<<<<<<<<

Could someone explain to me these syntax points? Thanks in anticipation.
Knatterton
Posts: 165
Joined: Apr 19, 2019 19:03

Re: Not clear about this syntax

Post by Knatterton »

These are the fltk-c commands which can be found in fltk-main.bi. But there exists no further doc for fb, See the usage in the examples. It can be mixed with FB so the colon is a normal line separator. This way a lot of flexible constructions are possible like fb variables and functions instead of fltk-parameters and more. It's a lot "try and error".
fxm
Moderator
Posts: 12110
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Not clear about this syntax

Post by fxm »

'Var' declares a variable whose type is implied from the initializer expression.
Syntax:
Var [Shared] symbolname = expression
is equivalent to:
Dim [Shared] symbolname As Typeof(expression) = expression
fxm
Moderator
Posts: 12110
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Not clear about this syntax

Post by fxm »

When declaring/defining a procedure (subroutine or function), parentheses (after the procedure name) surrounding a non empty argument list are required.

When calling a subroutine, parentheses (after the subroutine name) surrounding an argument list (empty or non empty) are optional.

When calling a function as a subroutine (without using the return variable), the same rules as for subroutine apply.
When calling a function in an expression (which uses the return value), parentheses surrounding a non empty argument list are required.

But it is a common convention to always use parentheses (empty or non empty) after the procedure name, to signify a procedure call.
Post Reply