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

World: r3wp

[!REBOL3-OLD1]

Pekr
11-Jan-2010
[20652]
We are not talking about block here, but a function body. And if 
I write switch type? %user.r [file! [print "... a file"]] ... it 
is imo supposed to work ...
Rebolek
11-Jan-2010
[20653]
...switch should be supplied a reduced block

no, that's wrong. See:

>> a: 1
== 1
>> switch 'a [a ["ok"]]
== "ok"


>> switch 'a reduce [a ["ok"]]

== none
WuJian
11-Jan-2010
[20654]
>> a: 1
== 1
>> switch a reduce [a ["ok"]]
== "ok"
Pekr
11-Jan-2010
[20655]
how is novice supposed to know, that actually submitting result of 
type? %user.r is not going to work with file! datatype in a switch 
body?
sqlab
11-Jan-2010
[20656]
no need for reducing
  type? first [#[datatype! file!]]
Rebolek
11-Jan-2010
[20657x2]
By reading manual probably
file! in the switch body is not datatype! but word! Understanding 
this will help to better understand how REBOL works.
Steeve
11-Jan-2010
[20659]
Pekr, an old Reboler like you...
Rebolek
11-Jan-2010
[20660]
:)
Steeve
11-Jan-2010
[20661x2]
the idiom [switch type? /word [...]] is used in such lot of places 
in mezz functions.
You should be well aware of that now ;-)
including R2-forward.r , 14 occurences in R2
8 occurences in R3
Pekr
11-Jan-2010
[20663x2]
Steeve - I don't care. type?/word looks awfull ...
The reason why /word has to be introduced is imo because exactly 
'switch is not able to handle datytype directly in its body, and 
that is what I am pointing out ...
Steeve
11-Jan-2010
[20665]
uhuh
Pekr
11-Jan-2010
[20666x3]
Help string to 'switch does not reveal much. And docs are imo even 
incorrect:


Switch also returns the value of the block it executes. The cases 
can be any datatype. If none of the other cases match, use the /DEFAULT 
refinement to specify a default case.
If the case can be ANY datatype, and it works with xy datatypes, 
there is no point into turning datatype! dtype into word first, no?
http://www.rebol.com/r3/docs/functions/switch.html.... or someone 
should correct docs so that this special case is more obvious ...
Steeve
11-Jan-2010
[20669]
i don't see anything wrong in the definition, but yeah, we could 
add some use cases
Pekr
11-Jan-2010
[20670x2]
The cases can be any datatype

 - is imo wrong, as it is not obviously true. You can't use datatype! 
 type for the case. You have to convert it to word! type ...
It might be usefull to add idiom like you mentioned to the end of 
examples? Now I at least know, what type?/word exists ...
Steeve
11-Jan-2010
[20672]
Or maybe a new mezz would be good to have.

Krenzelokize: func [bum this [block!]][
	switch type?/word bum this
]
Pekr
11-Jan-2010
[20673]
It was Graham who actually asked, how is he supposed to handle datatype! 
datatype in 'switch function. If he was confused for a fraction of 
minute, then novices could be confused too. The function behaviour 
is inconsistent, at least in reference to docs, period. Even if I 
never used type?/word (as I don't work with dynamic code much), I 
used to-word type? value in 20 seconds, so I found may way around 
the "problem". 


Maybe now I understand, why some external ppl see REBOL community 
as bunch of "we are best, we know the best" luxury fools - we try 
to make idiots from ppl not actually as knowleable as some elite 
members.
Steeve
11-Jan-2010
[20674]
Pekr my friend, it was just a little tease :-)
Rebolek
11-Jan-2010
[20675x2]
Pekr, you may be right about correcting docs, I'm not sure, haven't 
read them in a while. But in all other aspects you are wrong. What 
you want is basically same as what that crazy spammer on blog wanted 
few weeks ago. Blocks always reduced.
And that's wrong. And if people don't get it, they're free to use 
some other language.
Pekr
11-Jan-2010
[20677x3]
I surely don't want all blocks being reduced. I think I know what 
you are talking about. But then let's stop claiming 'switch can accept 
any datatype for the case branching. It can't ...
But - was switch always native?
It is difficult for me to explain, but - I thought, that 'switch 
case block could be treaded some other way internally. Not reduced, 
but in kind of  "DELECT" or dialect kind of type. Then you could 
really write any datatype for the case ..... not sure it is doable 
nor neccessary, just thinking aloud ...
Rebolek
11-Jan-2010
[20680x2]
What you want is that words that get evaluated to datatype! should 
be evaluated but other words shouldn't. That's inconsistent and for 
everyone trying REBOL is better to understand the difference between 
word! and it's value than otherwise.
I agree that it may look confusing to some people, same as:

>> f: func [a][append [] a]       

>> f 1
== [1]


>> f 2

== [1 2]


But as I said, it's better to understand why works this way than 
dumbening the language just because newbies may be confused.
Pekr
11-Jan-2010
[20682]
no, you don't understand. It is just you understanding the only one 
holy way - submitting function a regular REBOL code :-) Whereas I 
was just wondering, with rather uniform design of switch (case followed 
by code to execute), if we could supply kind of dialect to switch 
function as a body. The same way as how we have 'secure, 'get-modes 
or other dialects ...
Rebolek
11-Jan-2010
[20683]
...why IT works...
Pekr
11-Jan-2010
[20684]
Then there would not be need for type?/word ...
Rebolek
11-Jan-2010
[20685x2]
Ah, ok, some kind of dialect - I'm not against it, if you design 
something and put it here I thing it will get some attention, it 
will be enhanced and it also  may become part of Rx. But SWITCH uses 
"the only holy way" and that's good :)
Also I think that adding those five characters "/word" to your (or 
Graham's who asked initialy) code takesmuch less time than this discussion.
Pekr
11-Jan-2010
[20687]
fixing docs as well ...
Rebolek
11-Jan-2010
[20688]
As Orbital said, "sad but true". Fixing docs is probably !1.
sqlab
11-Jan-2010
[20689]
switch works with datatype!, if you use a datatype! (read a true 
datatype!)  in the block.
see 
switch type? %test.r [#[datatype! file!]    [print "type file!"]]
Pekr
11-Jan-2010
[20690]
ah, interesting ....
BrianH
11-Jan-2010
[20691]
Pekr, "The cases can be any datatype" refers to the type of the values, 
not their value. The type of integer! is datatype!, the value is 
#[datatype! integer!]. You can use the serialized syntax if you want 
to specify dataype! values directly, but watch out: If your build 
process goes through a MOLD then the serialized syntax will be lost 
- this tripped me up when I was porting R2/Forward to the R2 mezzanine 
code, I had to rewrite TYPES-OF and TO-TYPESET.
sqlab
11-Jan-2010
[20692]
Do you use it during mold?
I think you loose it thru load.
BrianH
11-Jan-2010
[20693]
There was a suggestion that SWITCH treat certain words as keywords, 
translating them to their standard values, in particular logic! and 
datatype! keywords. This would make SWITCH work like CONSTRUCT, and 
would likely require an /only refinement for the non-keyworded behavior 
like CONSTRUCT has. This would add a little overhead to SWITCH, but 
not as much as the workaround code already adds. The question hasn't 
yet been resolved, and should be brought up again for final resolution 
- some mezzanine code would need revising.
sqlab
11-Jan-2010
[20694]
I just checked it.
loading after a mold/all still gives the datatype!
Pekr
11-Jan-2010
[20695]
BrianH: what does it mean, that serialised syntax will be lost? I 
thought that we are closer to the state, when REBOL is going to be 
fully serialisable :-)
BrianH
11-Jan-2010
[20696x4]
Yes, but MOLD/all loses the procedural syntax that MOLD generates, 
so many types just don't work when loaded because of binding.
Pekr, the opposite of LOAD is MOLD/all, the opposite of DO is MOLD. 
MOLD doesn't generate serialized syntax.
R3 won't be fully serializable, even when the bugs are fixed. You 
won't be able to serialize handle!, command!, task! or module! values.
Or native!, op! or action! values.
sqlab
11-Jan-2010
[20700x2]
I think load should be the match for mold, and load/all for mold7all
mold/all