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

World: r3wp

[Core] Discuss core issues

[unknown: 5]
22-Feb-2009
[12622]
http://www.tretbase.com/forum/viewtopic.php?f=8&t=30&p=141#p141
Izkata
22-Feb-2009
[12623]
So.. it looks to me like this is just what you wanted:  any [word? 
val  lit-word? val]
Is it, or does is-lit-word? do something I'm missing?
[unknown: 5]
22-Feb-2009
[12624x2]
Almost does.  I fixed it up a bit for you to give you more of a match 
to my function here:


 a: func [val][if any [word? val lit-word? val][return true] false]

However, you used lit-word? which was what I was avoiding.
I would have to look at it much more to see how closely it matches 
but via the test posted here it seems to work.
[unknown: 5]
23-Feb-2009
[12626x3]
Nope yours doesn't do exactly what I wanted.
Works for most cases but some important ones it fails on.
>> a first reduce [to-word "test"]
== true
>> as-lit-word? reduce [to-word "test"]
== false
Izkata
23-Feb-2009
[12629]
>> a first reduce [to-word "test"]                               
    
== true
>> as-lit-word? first reduce [to-word "test"]
== true
>> a reduce [to-word "test"]      
== false
>> as-lit-word? reduce [to-word "test"]
== false
[unknown: 5]
23-Feb-2009
[12630x6]
oh - lol
I forgot the first.
actually it would be correct in both cases as it would still be a 
block.
Here you go:

>> c: make set-word! 'd
== d:
>> c
== d:
>> a c
== false
>> as-lit-word? c
== true
My function shows that BrianH was wrong.
And many agreed with him are wrong also.
Henrik
23-Feb-2009
[12636]
Paul, I have a hard time following the discussion. Can you show what 
you are right about?
[unknown: 5]
23-Feb-2009
[12637x4]
Sure henrik.
Here is what BrianH said:


You aren't passing 'test as an argument to LIT-WORD? whenn you do 
this:
lit-word? 'test
==false

What you are doing is *evaluating* 'test and then passing *that* 
value to LIT-WORD?. There's a difference.
Obviously that isn't true as my function shows.
Brian is saying that 'test would get evaluated to a word and *THAT* 
value is then in turn passed to lit-word? function.  But that isn't 
the case.  Because if it was indeed a word! at that point then there 
is no way my function could detect it as a lit-word!
Henrik
23-Feb-2009
[12641]
what was the source for as-lit-word? again?
[unknown: 5]
23-Feb-2009
[12642x2]
http://www.tretbase.com/forum/viewtopic.php?f=8&t=30&p=141#p141
as-lit-word?: make function! [  

    "Returns logic on whether the val argument is as a lit-word! type"
    val
    ][
    not error? try [= :val make lit-word! :val]
]
Dockimbel
23-Feb-2009
[12644]
You're using the wrong operator, your should be using == instead 
of = to test for datatype equality.

not error? try [== :val make lit-word! :val]
[unknown: 5]
23-Feb-2009
[12645x4]
You can use that also Doc and it still works.
I have already used both in my function.
A gave the link because the one on my computer actually has the == 
symbol  instead.
I will probably update the website one later.  Still testing some 
other modifications to the function.
Dockimbel
23-Feb-2009
[12649]
>> a: 'test
== test
>> :a == make lit-word! :a
== false
>> :a = make lit-word! :a
== true
Henrik
23-Feb-2009
[12650]
Doc, the problem is that Paul never actually passes a lit-word to 
the function, so he can't test for strict-equal?. It just happens 
to work the way he wants for lit-words.
[unknown: 5]
23-Feb-2009
[12651x2]
>> as-lit-word? 'test
== true
See doc - that is with the strict equal.
Dockimbel
23-Feb-2009
[12653]
What does mean the resulting value of as-lit-word? That no error 
happened? What's the point?
[unknown: 5]
23-Feb-2009
[12654]
gotta call in for unemployment be back in awhile depending on when 
i get thru on the phone.
Dockimbel
23-Feb-2009
[12655x2]
Henrik: yeah I see now what's he is doing. The function just returns 
true for word! values passed as argument. I still don't see the point...looks 
like Paul is chasing windmills.
Paul, in your examples : as-lit-word? test is equal to : as-lit-word? 
1. Functions arguments are evaluated before the function is called 
 except if the functions arguments are defined as lit-word! in the 
specification block.
BrianH
23-Feb-2009
[12657]
Paul, your LIT-WORD? function returns true if passed a word! value, 
which breaks it.
Geomol
23-Feb-2009
[12658]
>> a: 'test
== test
>> type? a
== word!
>> type? :a
== word!
>> a: to lit-word! 'test
== 'test
>> type? a              
== word!
>> type? :a             
== lit-word!

As I see it, 'test gets evaluated to a word.
BrianH
23-Feb-2009
[12659]
LIT-WORD? needs to return false for values of other word types. That 
is its job.
Geomol
23-Feb-2009
[12660x2]
Agree.
And that is what it does, right? So no problem there?
[unknown: 5]
23-Feb-2009
[12662x5]
back.  ok it only took like 35 redial attempts to get through the 
Illinois unemployment claims service this week - unbelievable.
Ok, let me check it out
Doc, I'm testing to see if a word behaves like a lit-word.
That is all my function does.
BrianH, it doesn't break.  My function is not a replacement for lit-word? 
function.
BrianH
23-Feb-2009
[12667]
Nice to hear. Interestingly enough, you can write code in R3 without 
lit-word!, get-word! or set-word! values in the code. Not R2 though.
[unknown: 5]
23-Feb-2009
[12668x2]
Doc, the reason in the example above that mine returned true was 
because it matched the error.  But that is what I want because it 
still indicates that the word behaved in a manner of a lit-word.
That is why the function is called as-lit-word.  I changed it yesterday 
to get rid of this idea that it is matching a lit-word.
BrianH
23-Feb-2009
[12670x2]
Just add one function:


quote: func [
	"Returns the value passed to it without evaluation."
	:value [any-type!]
] [
	:value
]


And you can pretend that there are no lit-word!, get-word! or set-word! 
types. It needs R3's get-word! parameter semantics though.
(sorry for the formatting of that last message)