Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • Dec 03 2017 05:53
    @PeterWAWood banned @matrixbot
  • Sep 28 2016 12:19
    @PeterWAWood banned @TimeSeriesLord
  • Aug 13 2016 03:23
    @PeterWAWood banned @Vexercizer
hiiamboris
@hiiamboris
true as well, since there's nothing that shouldn't be evaluated there ;)
Toomas Vooglaid
@toomasv
Can do w/o parens:
rejoin ["zip.exe " dirize target-directory short-filename ".zip"]
hiiamboris
@hiiamboris
you're all torturing the original idea :D
that was to throw in a lot of exprs, some to be evaluated, some not, some may be files, and get the string
Gregg Irwin
@greggirwin

you're all torturing the original idea

And now nobody will test composite. :^(

hiiamboris
@hiiamboris
@greggirwin actually I was wondering, what's the use case for it?
I mean, even in c++ they decided to hell with %d %s etc, let's just << everything into a stream
nedzadarek
@nedzadarek
@lepinekong_twitter compose-string {zip.exe "(target-directory)(short-filename).zip"} It reminds me of the Ruby's "2 + 2 #{2 + 2}"
Toomas Vooglaid
@toomasv
@lepinekong_twitter
composite works fine:
>> target: %. short: "myfile" composite {zip.exe :(dirize target)::(short):.zip}
== "zip.exe ./myfile.zip"
nedzadarek
@nedzadarek

@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"
Vladimir Vasilyev
@9214
@nedzadarek and you absolutely can't do the same with rejoin?
nedzadarek
@nedzadarek
@9214 I can rejoin ["zip.exe " target-directory "/" short-filename ".zip"] but I prefer Ruby style.
nedzadarek
@nedzadarek
With mentioned composite I can do this: composite/marks {Some #{probe "interesting"} Red expressions like 3 + 2 = #{3 + 2}} ["#{" "}"]. @9214 wouldn't it be possible to have some special syntax like e"foo", """triple""" or "foo"e?
Well... no need to new syntax if nothing will change:
e: func [str] [composite/marks str ["#{" "}"]]
e"zip.exe #{target-directory}/#{short-filename}.zip"
I just like when a programming languages allow such little things!
Vladimir Vasilyev
@9214
@nedzadarek if you can fulfill your strongly opionated preferences by yourself with mezzanines, why push it into core language? I have yet to see a single need in string interpolation with Red.
9214 @9214 opinionated*
nedzadarek
@nedzadarek
@9214 I'm not good with mezzanines or "low level Red" but "syntax" like e"some string" is good enough.
Vladimir Vasilyev
@9214

@nedzadarek

I'm not good with mezzanines

But you just wrote one.

nedzadarek
@nedzadarek
Really?
Vladimir Vasilyev
@9214

@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.

nedzadarek
@nedzadarek
@9214 I thought that mezzanine were wrote in Red/System (in case of Red). It's great to know.
Vladimir Vasilyev
@9214
@nedzadarek those are routines and natives.
nedzadarek
@nedzadarek
I see, thank you for clarifications!
nedzadarek
@nedzadarek
@greggirwin 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.red
And I'm sorry for the mess. Git seems to see more changes than I do.
ps. I might do something wrong because I haven't been using git for ages.
Semseddin Moldibi
@endo64
@nedzadarek @9214 substitute is also very useful function for string substitution,
It's written by Gabrielle if I remember correctly:
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"
nedzadarek
@nedzadarek
@endo64 it's interesting too! Thank you.
geekyi
@geekyi
@9214 :point_up: April 3, 2018 3:18 PM :smile:

@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).

More or less, it's from a bug I opened
red/red#2249
geekyi
@geekyi
Could be something else, that's how I first encountered bind and in
nedzadarek
@nedzadarek
What's the purpose of only in the change: parse s: [a] [change only set w word! (to-string w)] s? And when you want transform something (e.g. capitalize foo -> Foo) is using rule change set p PATTERN (transform p) good? Or is there more idiomatic way to do this?
Vladimir Vasilyev
@9214
@nedzadarek
>> get also 'x parse x: [[1 2 3] d e][change block! [a b c]]
== [a b c d e]
>> get also 'x parse x: [[1 2 3] d e][change only block! [a b c]]
== [[a b c] d e]
that is, change matched pattern by the content of the series, or change it only by the series (i.e. as-is).
@nedzadarek yes, usually I use change copy match ... (... match).
nedzadarek
@nedzadarek
@9214 (i.e. as-is): ah it's like append/only. I should guessed that.
Good, thank you.
Vladimir Vasilyev
@9214
@nedzadarek yes, only has the same meaning in the most functions.
Gregg Irwin
@greggirwin
:point_up: April 6, 2018 12:12 AM @hiiamboris, 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.
Gregg Irwin
@greggirwin

: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.
Gregg Irwin
@greggirwin
The underlying logic makes sense. Each cell in the incoming series is formed separately, without intervening separators, where 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"
It's perhaps not intuitive, but at least easy to explain and work around.
nedzadarek
@nedzadarek

@greggirwin

as mold may be the only real use case

I think it might be more useful for more complex types. For example you have object that have range (start and end value):

range1: make object! [
  start-value: 0
  end-value: 10
]
It can be just parsed as 0...10.
Gregg Irwin
@greggirwin
But then you have a single func being applied to all expressions in the source string, yes?
nedzadarek
@nedzadarek
Yes. I guess that function should be "general" like Ruby's (it will just call obj/to_string function).
Gregg Irwin
@greggirwin
Which is what it does today.
nedzadarek
@nedzadarek
But can we define our own to_string function?
Gregg Irwin
@greggirwin
If you'd like to add a note about 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.