r3wp [groups: 83 posts: 189283]
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

World: r3wp

[Core] Discuss core issues

Ladislav
8-Oct-2011
[2344x2]
You are missing the point, I guess. The MAKE function binds the function 
body when the function is not running. The restriction to BIND is 
just artificial, and circumventable. I do not use the circumvention 
not because it is not possible, but because it looks "ugly".
(I do know at least two ways how to do it, to be exact, but both 
look uglier than what I normally like)
BrianH
8-Oct-2011
[2346]
I wouldn't mind BIND accepting function! for its context argument, 
as long you still have the error on referring to any of the bound 
words when the function isn't running. But not closure! though, since 
that context is different every time.
Ladislav
8-Oct-2011
[2347]
So, I rather always regenerate the function using MAKE, which, of 
course, does the binding for me
GrahamC
8-Oct-2011
[2348]
Your substitute function is similar to the dialect used for sql .. 
except it doesn't reduce, and it uses % instead of ?
BrianH
8-Oct-2011
[2349]
I don't mind the SQL dialect reducing, because that block is always 
code anyways, so you already have to treat it carefully. However, 
the method for treating code carefully is different than the methods 
for treating REBOL code carefully, so it doubles the analysis and 
screening. It's best to just resign yourself to not accepting SQL 
code blocks from unknown sources.
GrahamC
8-Oct-2011
[2350x2]
And is there a %n ... or is it just %0 and %1 ?
Anyway, sounds like a duplicate functionality .. that could wrapped 
into one function with a refinement
BrianH
8-Oct-2011
[2352]
Maybe SUBSTITUTE should have an /only option that works like APPLY/only: 
reduce by default, don't reduce with /only.
GrahamC
8-Oct-2011
[2353x2]
At present everyone is rolling their own substitute function for 
writing sql in R3 .. so it would be useful to have an official function
Not forgetting that the R2 sql substitute functionaiity is bugged
BrianH
8-Oct-2011
[2355]
That SUBSTITUTE function wouldn't work well for SQL, since most SQL 
dialects use % as a wildcard character in like expressions.
Ladislav
8-Oct-2011
[2356x2]
Aha, this was not meant for that specific purpose, being optimized 
for the translation. But, nevertheless, do you think that the #"?" 
character is better than the % character in general?
%0 and %1 - no, %123456 can be used as well
BrianH
8-Oct-2011
[2358x2]
Certainly not for anything other than SQL. Regular language uses 
? for regular punctuation. Does SUBSTITUTE need an escape character 
option?
I don't want to make it too complex, but that seems like a low-overhead 
option.
Ladislav
8-Oct-2011
[2360x2]
Cyphre was against it, and, in fact, it is not needed, since you 
can substitute so, you can generate any string you like this way.
for example, the "%1%2" string can be generated as follows:

["%1" "%1%2"]
BrianH
8-Oct-2011
[2362]
Well, you can't use % in SQL and can't use ? in English (and some 
other european languages). If we want to code to be more flexible, 
an escape char option would have low overhead for a lot of benefit.
GrahamC
8-Oct-2011
[2363]
substitute/with
BrianH
8-Oct-2011
[2364]
That would be in keeping with how /with is used in other functions.
Ladislav
8-Oct-2011
[2365x2]
I suggested the #"%" character as an escape, but, Cyphre is right, 
that it is, in fact, not needed.
For example, if the #"%" were handled as an escape character, you 
could write

["%%"]


to obtain the "%" string, but the current version allows you to write 
just 

["%"]
GrahamC
8-Oct-2011
[2367]
So, how do you prevent %1 from being substituted?
Ladislav
8-Oct-2011
[2368]
I do not need to, if I want to obtain %1 somewhere, I can write:

["this is a string containing '%1'" "%1"]

, and I get it (although substituted)
BrianH
8-Oct-2011
[2369x2]
Yup, it's only needed if you want SUBSTITUTE to be used for more 
than just translated strings. And something like SUBSTITUTE using 
? is only needed for SQL dialects that we implement ourselves, not 
for server access where they do their own parsing of prepared statements.
I'm OK with not having a /with, but I'm sold on having an APPLY-style 
/only option.
GrahamC
8-Oct-2011
[2371]
That sounds tricky ... if you're reading two input streams .. to 
substitute ... you need to know when a %n is intended not to be replaced
BrianH
8-Oct-2011
[2372]
What if "%%" was always interpreted as "%"? Then the way that you 
signify %n as not being a replacement is to write it as %%n.
GrahamC
8-Oct-2011
[2373x2]
This is what happens in MS dos
shell
BrianH
8-Oct-2011
[2375x2]
Yup.
The main advantage to APPLY reducing its argument is that it doesn't 
necessarily have to allocate an intermediate block. This might be 
tricky though if you want to implement SUBSTITUTE as a command. Can 
you DO/next in a command?
GrahamC
8-Oct-2011
[2377]
And I guess my next question is, do you really need "n" ?  Why not 
prepare the arguments in order and just use them as in SQL dialect?
Ladislav
8-Oct-2011
[2378]
The current proposal allows me to write:

["%%1" "%1"]


to obtain the "%%1" string. With your proposal I would need to write 
it as

["%%%%1"]

, so, I do not think I gain any advantage.
GrahamC
8-Oct-2011
[2379]
Yes, it's more flexible
Ladislav
8-Oct-2011
[2380]
Why not prepare the arguments in order
 - that is not suitable for translation
BrianH
8-Oct-2011
[2381]
Graham, the %n method supports switching template strings between 
languages with different sentence ordering.
Ladislav
8-Oct-2011
[2382]
(thranslation should be able to adjust the order according to the 
language requirements)
GrahamC
8-Oct-2011
[2383]
Sounds then the cases are quite different and should have different 
functions
BrianH
8-Oct-2011
[2384x3]
Ladislav, the advantage would be that you don't have to allocate 
a substitution argument for that % escaping, especially if some of 
your template strings might need a %1 in them and others might not.
I am thinking of the code-generation posibilities, where instead 
of Russian you are generating ASP or something.
Or RSP if you like.
Ladislav
8-Oct-2011
[2387]
the advantage would be that you don't have to allocate a substitution 
argument for that % escaping

 - yes, understood, I was originally for that alternative, but, Cyphre 
 convinced me, that for human writers, actualy the substitution is 
 more readable
BrianH
8-Oct-2011
[2388]
Ah, sticking to the natural language translation usage model, even 
though you are allocating a more generally applicable name to the 
function.
GrahamC
8-Oct-2011
[2389]
substitute ( "%1" "translate" )
Ladislav
8-Oct-2011
[2390x2]
Well, yes, the name may be conflicting, sure
But, "translate" is not a good name, since the translation is what 
is being performed as well, besides the substitution
BrianH
8-Oct-2011
[2392]
Well, given my current business needs I would use SUBSTITUTE more 
for code generation than for translation, but it would be useful 
for generating English as well.
Ladislav
9-Oct-2011
[2393]
Sure, I expect there *are* other uses. As for the %% case, I am still 
not sure, it might be intersting to know what would Robert prefer.