Sorry, but I could not find any good subject title for my question!
Well, I have this problem:
I created a function which manage text in a 2D engine... here an example:
(simple-text-create "fldOne" "Content-One!")
It works but, if someone wants to create many text fields, he needs to write a lot of text:
(simple-text-create "fldOne" "Content-One!")
(simple-text-create "fldTow" "Content-Two!")
(simple-text-create "fldThree" "Content-Three!")
(simple-text-update "fldOne" "My New Text")
(simple-text-update "fldTwo" "My New Text")
(simple-text-update "fldThree" "My New Text")
In order to avoid to repeat "simple-text-create" everytime, I wanted to create a "shortcut", like this (just a concept, not real code):
(simple-text
create ( ("fldOne" "Content-One!")
"fldTwo" "Content-One!"
create "fldThree" "Content-One!"
update "fldOne" "My New Text"
update "fldTwo" "My New Text"
update "fldThree" "My New Text"
)
My problem is I don't want to write-down another function "simple-text" that wraps the other ones.
I could even imagine a syntax shortcut like this:
(simple-text
(create
("fldOne" "My content")
("fldTwo" "My content")
("fldThree" "My content")
) )
Can I use a function like MAP (or another one!) to speed-up this process?
I don't want to write these functions again since I'm mapping hundreds of them, so if I need to write references more than once I could easily make mistakes, and my program could become unreliable.
Thank you for your help!
There two ways to do it, first using 'map':
(set 'ids '(
"fldOne"
"fldTow"
"fldThree"
))
(set 'content '(
"Content-One!"
"Content-Two!"
"Content-Three!"
))
(map simple-text-create ids content)
the other method has both parameters in a list and uses 'apply':
(set 'params '(
("fldOne" "Content-One!")
("fldTow" "Content-Two!")
("fldThree" "Content-Three!")
))
(dolist (p params)
(apply simple-text-create p)
)
; or using 'map' again with 'curry'
(map (curry apply simple-text-create) params)
Thank you, I will check if (and how) I can implement in my code.