Skip to content

Instantly share code, notes, and snippets.

@cser
Last active July 28, 2022 10:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cser/dabe6e064915701be3d3bb5f50db4d42 to your computer and use it in GitHub Desktop.
Save cser/dabe6e064915701be3d3bb5f50db4d42 to your computer and use it in GitHub Desktop.

1 Syntax description

Common syntax:

#def {macros_name}$({arguments})
    {body}
#end def

The full equivalent one-line syntax (possible only if {body} contains one line):

#def {macros_name}$({parameters}) = {body}

Calling:

{macros_name}$({arguments})

{macros_name}$ - must satisfy the same rules as variable naming, but must ends with $, for example: macro_1$, MACRO1$, β$, a,0$, e.t.c.

{parameters} - parameters list, must satisfy the same rules as simple function parameters, but no parameters is allowed.

{arguments} - arguments list. Several arguments must be separated by semicolon ;. Arguments can be: variable names, function names, equations, assigments, macros names (with $).

{body} - one or several lines, processing like a flat calculation code, but variables/functions that eponymous with parameters are replaced by arguments

2 Examples

2.1 Simple case

#def CHECK$(σ; IσI)
	#if σ ≤ IσI
		'<font color="green">The condition is satisfied</font> ('σ''IσI')
	#else if σ ≤ IσI*1.05
		'<font color="orange">The condition is satisfied</font> ('σ' exceeds 'IσI
		#val
		' by '(1 - IσI/σ)*100'%)
		#equ
	#else
		'<font color="red">The condition is satisfied</font> ('σ'>'IσI')
	#end if
#end def
τ=100MPa
IτI=150MPa
CHECK$(τ; IτI)

Output:

τ=100MPa
IτI=150MPa
The condition is satisfied (τ=100MPa≤IτI=150MPa)

2.2 Helpers examples

One-line #val/#equ

#def VAL$(v)
	#val
	v
	#equ
#end def
τ = 100MPa
VAL$(τ)
VAL$(τ = 300MPa)
VAL$(τ + 10MPa)
τ = 200MPa

Output:

τ=100MPa
100
300
310
τ=200MPa

Expample of nested #hide/#show

#hide
hide.depth = 0
#show
#def HIDE_OPEN$()
    #hide
    hide.depth = hide.depth + 1
    #end def
#def HIDE_CLOSE$()
    #hide
    hide.depth = hide.depth - 1
    #if (hide.depth ≤ 0)
        #show
    #end if
#end def

#def EXAMPLE$(a)
    HIDE_OPEN$()
    x = a
    HIDE_CLOSE$()
    'There x: 'x
#end def
EXAMPLE$(100)
'---
HIDE_OPEN$()
EXAMPLE$(200)
HIDE_CLOSE$()
'---
EXAMPLE$(300)

Output:

There x: x = 100
---
---
There x: x = 300

2.3 Macroses can be overwrited like variables

σ_y=100MPa
σ_u=200MPa
#if σ_y/σ_u > 0.7
	#def STEEL$() = 'Strange steel
#else
	#def STEEL$() = 'Normal steel
#end if
'Steel type: 'STEEL$()

Output:

σ_y=100MPa
σ_u=200MPa
Steel type: Normal steel

2.4 Macros name replacing

Main idea is to replace parameters on every macro calling at RUNTIME and then execute it as NORMAL CODE. If this NORMAL CODE agan contains macros calling - we replace variables again and execute it as NORMAL CODE.

Text passing in arguments

#def CHECK$(σ;IσI;condition)
    #if σ ≤ IσI
        '<font color="green">The condition is satisfied ('condition()')</font> ('σ''IσI')
    #else
        '<font color="red">The condition is not satisfied ('condition()')</font> ('σ'>'IσI')
    #end if
#end def
τ = 100MPaI = 150MPa
#def text$() = 'for production
CHECK$(τ;IτI;text$)
'---
τ_test = 120MPa
IτI_test = 180MPa
#def text$() = 'for test
CHECK$(τ_test;IτI_test;text$)

Output

τ=100MPa
IτI=150MPa
τ_test=120MPa
IτI_test=180MPa
The condition is satisfied (for production) (τ=100MPa≤IτI=150MPa)
The condition is satisfied (for test) (τ_test=120MPa≤IτI_test=180MPa)

Inverse calculation order

#def INVERSE_ORDER$(F1;F2)
    #hide
    F2()
    #show
    '<center>'F1',</center>
    'where:
    F2()
#end def

'Perimeter:
#def ARGS$()
    '&ensp;&ensp;'a = 200mm' - width;
    '&ensp;&ensp;'b = 10mm' - height.
#end def
INVERSE_ORDER$(P = 2*(a + b);ARGS$)
'Area of round is:
#def ARGS$()
    '&ensp;&ensp;'d = 50mm' - diameter.
#end def
INVERSE_ORDER$(A = π*d^2/4;ARGS$)

Output

Perimeter:
    P = 2·(b + c) = 2·(200mm + 10mm) = 420mm,
where:
  a = 200mm - width;
  b = 10mm - height.
Area of round is:
    A = π·d²/4 = 3.14·50mm²/4 = 1963.5mm²,
where:
  d = 50mm - diameter.
@Proektsoftbg
Copy link

Proektsoftbg commented Jun 27, 2022

Thank you! This is very useful. I am already back on this and advancing. I will send you a pre-release for testing soon. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment