@hiiamboris
actually I was wondering, what's the use case for it?
I guess text manipulation (1) and and calling external exes (2).
1) Ruby:
name = "Baltazar"
age = 999
puts "Hello #{name}. You have #{age} years."
puts "Random number #{rand 42 + 1000}"
It's very easy to write and read.
2) LIke @lepinekong_twitter wanted to call zip.exe
with some arguments, in Ruby you can do something like this:
system "zip.exe #{target_directory}/{short-filename}.zip"
e: func [str] [composite/marks str ["#{" "}"]]
e"zip.exe #{target-directory}/#{short-filename}.zip"
@nedzadarek http://www.rebol.com/article/0352.html
In general, mezzanine functions are short helpers -- used to make coding easier but without losing much performance.
composite
is interesting function. I added small change described here (3 lines): https://github.com/nedzadarek/red-formatting/blob/master/test-composite.red#L86 https://github.com/nedzadarek/red-formatting/blob/master/composite.redsubstitute
is also very useful function for string substitution,substitute: func [
"Do variable substitution inside a string"
string [any-string!] vars [object! block!] /local out emit rule word start end
][out: make string 2 + length? string
emit: func [str] [append out :str] rule: make block! 256
if block? vars [vars: context vars] foreach word copy keys-of vars [
append rule compose/deep [
(either empty? rule [] ['|]) (form word) ">" (to paren! bind compose [emit (word)] vars)
]
] parse string [
any [
start:
to "<" end: (head append/part out start end) ["<" rule | skip (emit "<")]
]
]
out
]
>> substitute "Name <name>, age <age>" [name: "Endo" age: 40]
== "Name Endo, age 40"
>> substitute "Name <name>, age <age>" context [name: "Endo" age: 40]
== "Name Endo, age 40"
@dockimbel :point_up: April 3, 2018 3:18 PM
You're sure it's my code? new: bind 'a (context? in c 'a) doesn't look like my style (though I could have forgotten).
only
by the series (i.e. as-is).
change copy match ... (... match)
.
composite
is a string interpolator. R2 had build-markup
, which was modeled on PHP's approach to embedding code inside markup with escapes. String interpolation is widely used because it's relatively easy to explain and understand. I've used it a lot when providing configuration options for end users. e.g. they can write email templates, and insert data from the system.
:point_up: April 6, 2018 6:59 AM @nedzadarek, thanks for finding an interesting behavior. I don't know that a /fun
refinement is the way to go, as mold
may be the only real use case. And that is only because of how lit-paths work with change
in strings. Red kept this behavior from Rebol, but I'm not sure it's the best option:
>> head change "" 'f/b
== "fb"
>> head change "" form 'f/b
== "f/b"
>> head change "" mold 'f/b
== "f/b"
/only
has no effect on this behavior.
Can anyone come up with use cases where the current behavior is desired? I can't remember ever using change
with a lit-path myself, and it's easily worked around, but what is the design intent behind the behavior.
Paren!
exhibits the same behavior.
form
adds them when operating on an entire series, like a path, paren, or block. That is, change
does not just form
the value and insert it, but inserts each of its cells separately. e.g.>> head change "" ['f/b]
== "'f/b"
0...10
.
change
and paths to https://github.com/red/red/wiki/Path!-notes, that would be great.
But can we define our own
to_string
function?
Of course, it's just a function. You can't change the action of existing datatypes however.