Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Parameters for user-defined functions
#1
Hi,

In Macro6, I have a lot of key-value pairs, each value needs to be replaced(replace [] with ┃)

So, I want to define the duplicate part of the code as a function kvs ,  I can simply use it in Macro7

But I ran into a problem: In practical use, where the parameters of key-value pairs are not fixed, e.g: A Av B Bv C Cv D Dv E Ev ....

How do I define the parameters for the function kvs ?  Or is there a better way to achieve it?

Thanks in advance for any advice and help
david

Macro Macro6
 
Code:
Copy      Help
out
str A="1 key"
str Av=
;1 hello
;1 world
Av.replacerx("[]" "┃")

str B="2 key"
str Bv=
;2 hello
;2 world
Bv.replacerx("[]" "┃")

str C="3 key"
str Cv=
;3 hello
;3 world
Cv.replacerx("[]" "┃")

str kv=
F
;{A}={Av}
;{B}={Bv}
;{C}={Cv}

IStringMap m._create
m.AddList(kv "=")

str v=m.Get("1 key")
if(v)
,v.replacerx("┃" "[]")
,out v
else
,out "not found"

Macro Macro7
 
Code:
Copy      Help
out
str A="1 key"
str Av=
;1 hello
;1 world

str B="2 key"
str Bv=
;2 hello
;2 world

str C="3 key"
str Cv=
;3 hello
;3 world

str kv=kvs(A Av B Bv C Cv)

IStringMap m._create
m.AddList(kv "=")

str v=m.Get("1 key")
if(v)
,v.replacerx("┃" "[]")
,out v
else
,out "not found"

Function kvs
Code:
Copy      Help
function'str str&A str&Av str&B str&Bv str&C str&Cv
Av.replacerx("[]" "┃")
Bv.replacerx("[]" "┃")
Cv.replacerx("[]" "┃")

_s=
F
;{A}={Av}
;{B}={Bv}
;{C}={Cv}

ret _s


Messages In This Thread
Parameters for user-defined functions - by Davider - 12-31-2022, 05:23 AM

Forum Jump:


Users browsing this thread: 1 Guest(s)