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

World: r3wp

[Core] Discuss core issues

Volker
30-Oct-2005
[2582]
path seems to be a "clear find". Do not know about uses.
OneTom
30-Oct-2005
[2583]
but it keeps the length
Volker
30-Oct-2005
[2584]
it pokes an 'unset! there. mold then stops.
OneTom
30-Oct-2005
[2585x2]
yeah, i saw
and fucks it up somehow, because if i change the unset!  to something, 
the path still stays in a strange state
Volker
30-Oct-2005
[2587x2]
I could repair it with a/4: 12
maybe could be used to exclude something from mold? To stop this 
recursive things?
OneTom
30-Oct-2005
[2589]
could u show me w an example what mold are u talkin about?
BrianH
30-Oct-2005
[2590]
OneTom, actions are how type-specific operations are implemented 
in REBOL. Every datatype has a table of function pointers, one pointer 
for every action. Every one of those tables are layed out the same, 
with the function corresponding to the same index being the version 
of the same function for that specific type. Each action! has an 
index associated with it - you can see the index like this:

>> second :add
== 1


When the action! is called, REBOL checks the datatype of the first 
argument to it and then calls the function at that index into the 
datatype's table. This is the way that REBOL implements polymorphic 
native functions, single dispatch on the datatype.


But really, you don't need to know any of this. All you need to know 
is that an action! is like a native!, but with a differently named 
datatype.
Volker
30-Oct-2005
[2591]
!> a: [b 1 c 2 d 3]
== [b 1 c 2 d 3]
!> path a 'c
!> a
== [b 1 c]
!> length? a
== 6
!> a/4: 12
== 12
!> a
== [b 1 c 12 d 3]
OneTom
30-Oct-2005
[2592]
:)) it still makes me feel a lot happier knowing all these background 
info, brianh! thank you for clarifying this
Volker
30-Oct-2005
[2593x2]
Its a good idea to know about it. Seems its possible to path action! 
to protocol. at least i made a 'find in a  protocol once and got 
all the refinements.
to path -> to pass ..
BrianH
30-Oct-2005
[2595x3]
It's pretty easy to figure out when you realize that second on an 
action! returns an integer. Everything else follows from there.
At this point, I can't imagine what the path action! would be good 
for. Perhaps it is part of the object! internals?
Volker, by protocol do you mean a port type?
Volker
30-Oct-2005
[2598x3]
Cant have a use, else i had heard of it :) Practical use: it blocks 
mold. Recursive data, Code-obfuscation?
!> a: context[b: 1 c: 2]  path a 'b  ?? a
a: make object! [
    b: end
    c: 2
]
Yes.
Would be able to implement find on a port that way.
BrianH
30-Oct-2005
[2601]
I'm going to copy my path question to RT Q&A.
OneTom
30-Oct-2005
[2602]
let us know the answer! paste it here if u got any!
Gabriele
31-Oct-2005
[2603]
path is internal, and should probably not be exposed. my guess is 
that it has to do with path evaluation.
BrianH
31-Oct-2005
[2604x3]
You are probably right that it wasn't intended to be exposed, but 
you got my curiosity going. What is it used for internally?
I mean, it says "Path selection." right in the doc comment so that's 
a good guess :) But how does it help with path selection? How is 
it used? Just for implementing set-path assignment?
For that matter, what types implement the path action?
Gabriele
1-Nov-2005
[2607]
i don't have answers. when i noticed it months ago and asked carl, 
he said it was an internal thing. no more details.
Geomol
1-Nov-2005
[2608x3]
I had a problem with SWITCH, and it turned out to be a funny thing 
with SELECT (see source switch). If you've got a block like this:
blk: [1 word "string" 1.2 01:00:00 1-11-2005 any-type! 4]
you can do things like this:
>> select blk 1
== word
>> select blk 1.2
== 1:00
>> select blk 'word
== "string"
>> select blk 1:00
== 1-Nov-2005
>> select blk 1-11-2005
== any-type!

And now the fun (or strange) part:
>> select blk any-type!
== word

It's possible to select on a datatype. The first element in the block 
(1) is of type any-type!, so I get: word. It's possible to do things 
like:
>> select blk date!
== any-type!
>> select blk time!
== 1-Nov-2005

So how do I select a datatype in a block? I could do this:
>> select blk to-word any-type!
== 4
or something like this:
>> select reduce [file! 1 url! 2] url!
== 2
I can cope with this in my code, just found it peculiar.
In the last part, what I'm trying to do, is selecting a datatype 
word in a block.
It all came from the include function in Canvas. I wanted it to be 
able to include modules both from diskfiles and URLs. So I did something 
like:
switch type? object [
	file!	[...]
	url!	[...]
]
But this wont work, and I ended up doing:
switch to-word type? object [


Maybe there should be some notes about this behaviour of SELECT in 
the wikibook?
Ladislav
1-Nov-2005
[2611]
see switch type?/word ...
Geomol
1-Nov-2005
[2612]
Brilliant! Of course Carl've thought about that. :-)
DideC
2-Nov-2005
[2613]
Yeah, this one catch me too some times ago ;-)
Allen
2-Nov-2005
[2614]
Searching for datatype works with FIND as well. It's very handy
Graham
4-Nov-2005
[2615]
I wonder if it would be possible to implement a dialect to get at 
parts of a series as in python.  With rebcode?


instead of copy/part string 4 ... , string/[:4], or if I want the 
5 and 6 elements, then string/[5,6]
JaimeVargas
4-Nov-2005
[2616]
Very posible
Graham
4-Nov-2005
[2617]
that seems easier than copy/part skip string 4 2
JaimeVargas
4-Nov-2005
[2618]
I believe Greg already has something like that he named his function 
slice.
Graham
4-Nov-2005
[2619x2]
But now we can use rebcode to speed it up ?
Is Gregg's function dialected ?
JaimeVargas
4-Nov-2005
[2621x2]
Lost me there.
This type of function is quite fast in native rebol.
Graham
4-Nov-2005
[2623x2]
it's just a pain to write.
the power of a language can be measured by how few symbols are required 
to perform a given task.
JaimeVargas
4-Nov-2005
[2625x2]
I don't think so. It all depends on the functionality you want.
Well you can create your on slice function.
Graham
4-Nov-2005
[2627x2]
don't want to :)
I want native handling that is expressive, and short
BrianH
4-Nov-2005
[2629]
Graham, I don't think that's a very good measure. REBOL isn't Perl, 
you know, but that doesn't make it less powerful.
Graham
4-Nov-2005
[2630]
But also it assists in debugging programs.  It is well known that 
the number of errors per line is fairly constant.  You reduce the 
number of words you use with a powerful language, and this leads 
automatically to reduced number of errors since you need fewer lines.
JaimeVargas
4-Nov-2005
[2631]
substring: func [
    [catch]
    source [string!]
    spec [block!]
    /local start stop rule
][
    rule: [set start integer! '.. set stop integer!]
    unless parse spec rule [
        throw make error! "Invalid range spec."
    ]
    copy/part skip source start stop
]