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

World: r3wp

[Core] Discuss core issues

Dockimbel
8-Jan-2010
[15393]
Janko, a function is a context! value like objects. You can use the 
following mental analogy to see how it is related :

foo: func ["for demo" a [integer!] /local b][...]


would be *roughly* equivalent to constructing an object like that 
:

foo-def: make object! [
	hidden-ctx: make object! [a: none local: none b: none]
	body: [...]
	spec: ["for demo" a [integer!] /local b]
]


The body is bound to the 'hidden-ctx context at function creation. 
When calling 'foo, the interpreter will set the 'hidden-ctx object 
words values according to passed arguments and refinements and then 
DO 'body.


There's no differences on how REBOL treats "arguments" and "local 
words", it's part of the illusion. The /local refinement is used 
by *convention* only, to set "local words", you could just decide 
to use any other refinement for the same job. Here's an example :

>> a: func [/local b][print b]
>> a/local 5
5


Additionnaly, when you apply the ordinal natives on a function! value, 
you get :

>> first :foo
== [a /local b]		;=> the hidden context words

>> second :foo
== [...]			;=> the function body block

>> third :foo
== ["for demo" a [integer!] /local b]	;=> the original spec block
Henrik
8-Jan-2010
[15394]
trying:

source context

might be a revelation too.
Janko
8-Jan-2010
[15395x4]
huh.. plenty of info, might need some time to process this to get 
all that you two meant .


but I did already know first :foo second: foo stuff (I was playing 
with rebol to js compiler) and I did know that context is object
hm.. if rebol binds hidden ctx to function body then it really can't 
do anything to trigger warning on global words. (if I understand 
things aroung bind correctly)
ok .. query/clear will find me seek out leaking globals so this problem 
has got a solution in a way
if function uses objects and bind internally or something like that, 
then objects in rebol and bind should be cheap right? and then an 
object is cheaper than function ?
Dockimbel
8-Jan-2010
[15399x3]
if rebol binds hidden ctx to function body

 => It's the other way around, "binds body to ctx". BIND will only 
 link the words that match those defined in the target context, to 
 that same context, nothing more.
Object! and function! have different creation and usage semantics, 
AFAIU, they share a common internal parent datatype, context!. So, 
context! (which is not directly accessible) should be "cheaper". 
Objects and functions have different purposes, so this might be like 
comparing apples and oranges...in a closed blackbox.
BIND on a block! does a full recursive traversal of the block! and 
for each word! found, does a fast lookup in the target context (probably 
hashed). So the cost is directly proportional to the size and depth 
of the argument block!.
Terry
8-Jan-2010
[15402x4]
Is it just me, or does anyone else find JOIN and REJOIN cumbersome?
ie: Comparing to PHP

$var = "Hello World";

echo "This is $var in the sentence";
Rebol

var: "Hello World"
print rejoin ["This is " var "in the sentence"]
That's not too bad, but when you start including single quotes, double 
quotes, multiple variable etc, it becomes more difficult
Henrik
8-Jan-2010
[15406]
well, how else would you do it? I guess you need kind of an escape 
sequence to evaluate a word or something.
Steeve
8-Jan-2010
[15407x3]
there is plenty of functions to do such, the simple one is the one 
you can do
Terry, show use case you think is cumbersome and we'll show you a 
simpler way (i hope)
did you tried REWORD ?
Claude
8-Jan-2010
[15410]
terry:      var={coucou}            print rejoin [{hello + }  var 
{ à vous}]
Terry
8-Jan-2010
[15411x4]
$varA =<<<VA
 \'hello\'s {Worlds \';
VA;

$varB =<<<VB
 'and {so "on';
VB;
 
$n=<<<HD
<button onclick="alert('$varA ');">CLICK ME</button>
$varB
HD;

echo $n;
<<< is a here-doc in php
(output is JS)
so.. the result is a button that alerts.. 

\'hello\'s {Worlds \';

...and prints...

 'and {so "on';

after the button
Steeve
8-Jan-2010
[15415]
I see nothing you can't do with rebol, so what ?
Terry
8-Jan-2010
[15416x2]
um.. i don't think that was the point
Show me the 'simpler way'
Steeve
8-Jan-2010
[15418x2]
I just can't figure the exact string output you want.
don't mess it with escaping characters or comments.
Terry
8-Jan-2010
[15420]
no comments.. that's functioning php.. and if you don't escape it, 
it doesn't function as JS
Gregg
8-Jan-2010
[15421]
There has been talk in the past of including a substituion function, 
REWORD being the R3 func for it. In R2 we have build-markup, which 
shouldn't be hard to hack, but I don't know of a version that anyone 
has done for a given substitution syntax.
Steeve
8-Jan-2010
[15422]
Terry, i don't think your output must be
{
\'hello\'s {Worlds \';

...and prints...

 'and {so "on';
}

And yet, that's what you show us actually
Gregg
8-Jan-2010
[15423x2]
build: func [
    {Return text replacing $tags with their evaluated results.}
    content [string! file! url!]
    /quiet "Do not show errors in the output."
    /local out eval value
][
    content: either string? content [copy content] [read content]
    out: make string! 126
    eval: func [val /local tmp] [
        either error? set/any 'tmp try [do val] [
            if not quiet [
                tmp: disarm :tmp
                append out reform ["***ERROR" tmp/id "in:" val]
            ]
        ] [
            if not unset? get/any 'tmp [append out :tmp]
        ]
    ]
    parse/all content [
        any [
            end break

            | " $" [copy value to " " | copy value to end] (eval value)
            | copy value [to " $" | to end] (append out value)
        ]
    ]
    out
]
Now, that's norribly naive, and doesn't work because of that. e.g. 
it needs a space before the $ marker, so a var at the beginning of 
the text gets missed.
Steeve
8-Jan-2010
[15425]
yes seems a little messy Greg ;-)
Gregg
8-Jan-2010
[15426]
Well, what do you in five minutes? ;-)
Terry
8-Jan-2010
[15427]
Spend 6 :)
Gregg
8-Jan-2010
[15428x2]
Needs a different name too, as Ladislav has a nice BUILD func that 
works on blocks.
I need a spec first. ;-)
Terry
8-Jan-2010
[15430x3]
Although, i would be impressed if it didn't choke while trying to 
escape stuff.
If it was a smple matter of replacing variables with values.. i have 
some °7° code that does that.
The problem is well formed javascript to send back to the DOM.
via AJAX
Steeve
8-Jan-2010
[15433]
I say it again, you didn't give us the real output. Doing some assumptions, 
i got this.

varA: { \'hello\'s ^{Worlds \';}
varB: {
 'and ^{so "on';
}

print rejoin  [{<button onclick="alert('} varA {');">CLICK ME</button>} 
varB ]


<button onclick="alert(' \'hello\'s {Worlds \';');">CLICK ME</button>
 'and {so "on';

So where is the burden ? i don't see one
Terry
9-Jan-2010
[15434x2]
Should probably put this in rant.. but just spent the last hour wondering 
why my function wasn't working

result: sofp 'firstname'

the solution? change the single quotes to double.. aye carumba
Steeve, it's cumbersome.. I spend more time joining and escaping 
than anything else.
Henrik
9-Jan-2010
[15436x2]
From all this, the easiest way would be to produce a dialect that 
does its own escaping, so you don't have to write JS at all.
rephrasing that: not "easiest way", but easiest to use in the end.
Janko
9-Jan-2010
[15438]
as anyone tried to run cheyenne or rebol on sheevaplug ( http://www.globalscaletechnologies.com/t-sheevaplugdetails.aspx
)
WuJian
9-Jan-2010
[15439]
Good stufff
Henrik
13-Jan-2010
[15440]
does anyone have a rebol based bracket checking tool? preferrably 
something that can be integrated into a diagnostic tool.
Steeve
13-Jan-2010
[15441]
hey ?
WuJian
14-Jan-2010
[15442]
e
	)