new "!Includestring $var" command which loads the $var content like a file

0 votes
asked Jan 29 in Wanted features by kirchsth (4,680 points)
edited Jan 29 by kirchsth

I want to simplify the definition of (customer specific) procedures/functions in the C4 model.

And my idea was to write a function which defines the new functions/procedures into a string and then include the string like a file. My first idea (without the !includestring) was that I write it directly into the file but this produces a syntax error like below

!unquoted function Call($from, $to, $text = "calls")
!$def = '[' + $dq + $from + $dq +']->[' +$dq + $to + $dq + '] :' + $dq + $text + $dq
!return $def

Call(a 1, b 1)

!unquoted function $defineCall2($newDefault)
  !$def = '!unquoted procedure Call2($from, $to, $text = ' + $dq + $newDefault + $dq + ')' + %newline()
  !$def = $def + '[' + $dq + '$from' + $dq +']->[' +$dq + '$to' + $dq + '] :' + $dq + '$text' + $dq + %newline()
  !$def = $def + '!endprocedure' + %newline()
  !return $def
$defineCall2("is called via message")

' with following include call, could it work
' !includestring $defineCall2("is called via message")

Call2(c 1, d 1)

Atm. I could only create via a `-preproc` command an intermediate file and in a second call create the final diagram.


["a 1"]->["b 1"] :"calls"

!unquoted procedure Call2($from, $to, $text = "is called via message")
["$from"]->["$to"] :"$text"

Call2(c 1, d 1)

With `!includestring $defineCall2("is called via message")` dynamic macros would be possible.

Thank you and best regards

commented Feb 1 by The-Lu (60,440 points)
commented Feb 3 by kirchsth (4,680 points)

Hello The-Lu,

from the problem perspective I agree, but I think my solution approach is much simpler.
I think it needs only a local replace statement instead of a recursive preprocessor handling, ...
because if I use a normal !include the current implementation tries already to load the calculated string

And if the new implementation would only replace the `!includestring $defineCall2(...)` with the corresponding return value of the function the implementation could support dynamic created procedures too.

BR Helmut

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:

[Antispam2 Feature: please please wait 1 or 2 minutes (this message will disappear) before pressing the button otherwise it will fail](--------)
To avoid this verification in future, please log in or register.