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

World: r3wp

[Core] Discuss core issues

BrianH
31-Oct-2005
[2606]
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
[2631x3]
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
]
You can create your own dialects and grammar. But don't ask for everything 
to be written to your liking.
substring "abcd" [2 .. 3]
BrianH
4-Nov-2005
[2634x2]
; 1-based indexing
slice: func [str start len] [copy/part at str start len]
; 0-based indexing
slice: func [str start len] [copy/part skip str start len]
Fill in with doc strings and [catch] attributes, but the algorithm 
doesn't have to be hard.
Graham
4-Nov-2005
[2636]
which is briefer ?

substring "abcd" [ 2 .. 3 ]

and "abcd"/[2 .. 3]
BrianH
4-Nov-2005
[2637]
The first one, because you can tell what it's doing without having 
to remember more syntax.
Graham
4-Nov-2005
[2638]
I'm not saying that Rebol should be Python, just that it could be 
useful this way.
BrianH
4-Nov-2005
[2639]
How about:  slice "abcd" 2 3
JaimeVargas
4-Nov-2005
[2640x2]
The '.. in my small dialect block is pure syntax sugar and un-necessary 
but easy to remember for some people.
[2 .. 3] hints that it is a range.
Graham
4-Nov-2005
[2642]
yeah

so, "abcd"/[ 2 3 ]
BrianH
4-Nov-2005
[2643]
You don't need a dialect processor and its overhead for what is essentially 
a library function.
JaimeVargas
4-Nov-2005
[2644x2]
That could have more than many menings.
BrianH agreed. I'm just saying that if you want to use other language 
syntax you can always create a dialect.
Graham
4-Nov-2005
[2646]
what's the difference between

series/1

and 

series/[ 1 ]
BrianH
4-Nov-2005
[2647]
I prefer to create a translator for those purposes. Syntactic sugar 
is nice, but I like my runtime code to be on a diet.
Graham
4-Nov-2005
[2648]
Rebol is the translator :)
JaimeVargas
4-Nov-2005
[2649x2]
Brian depends on who is coding and for what purpose? But I am with 
you.
series/1 has clear defined meaning under rebol. series/[1] is undefined.
Graham
4-Nov-2005
[2651]
looks like I'm outnumbered here ... so I'll just withdraw to my corner 
:)
BrianH
4-Nov-2005
[2652x2]
No, REBOL is the runtime. A dialect processor only counts as a translator 
by my standards if the translation is only performed once rather 
than every time the operation is performed. Other languages can have 
tons of syntax because they are compiled.
For that matter, series/[1] violates REBOL data syntax for paths, 
AFAIK.
Graham
4-Nov-2005
[2654]
mere detail
JaimeVargas
4-Nov-2005
[2655]
Graham you want an enhance notation. I think you will do well with 
just a func.