Comparing path!
[1/13] from: robert::muench::robertmuench::de at: 30-Aug-2002 18:21
Hi, I'm sure this is again one of those things where I'm just not smart
enough... I would expect 'true instead of 'false with this code:
>> test: [type contact/company]
== [type contact/company]
>> text: "contact_company"
== "contact_company"
>> (select test 'type) = (to-path replace text "_" "/")
== false
Any idea? I tried this with to-lit-path as well but no luck too... Robert
-- Binary/unsupported file stripped by Listar --
-- Type: application/ms-tnef
-- File: winmail.dat
[2/13] from: greggirwin:mindspring at: 30-Aug-2002 10:47
Hi Robert,
<< I'm sure this is again one of those things where I'm just not smart
enough... I would expect 'true instead of 'false with this code:
>> test: [type contact/company]
== [type contact/company]
>> text: "contact_company"
== "contact_company"
>> (select test 'type) = (to-path replace text "_" "/")
== false >>
When you do to-path on the string, it doesn't parse the string and create a
path based on the slash delimiter. The path it creates only contains one
element, even though it looks like it contains two because of the embedded
slash.
I'm sure somebody has a better way to do this, but since I don't know what
it is, I hacked this real quick to convert a delimited string to a path.
path-from-dlm-string: func [string dlm /local result] [
result: make path! none
foreach item parse/all string dlm [
append result to word! item
]
result
]
HTH!
--Gregg
[3/13] from: gscottjones:mchsi at: 30-Aug-2002 12:13
Hi, Robert,
From: "Robert M. Muench"
> Hi, I'm sure this is again one of those things where I'm just not smart
> enough... I would expect 'true instead of 'false with this code:
<<quoted lines omitted: 5>>
> == false
> Any idea? I tried this with to-lit-path as well but no luck too... Robert
Looks like Gregg already answered the "real" question. Since I already
hacked my work-around, I thought I would throw in my version (I couldn't get
Gregg's to work; maybe I misunderstand its use; maybe I'm not reading
carefully enough again! Very common theme...).
test: [type contact/company]
text: "contact_company"
a: parse/all text "_"
forall a [a/1: to-word a/1]
a: head a
(select test 'type) = (make path! a)
--Scott Jones
[4/13] from: g:santilli:tiscalinet:it at: 30-Aug-2002 19:52
Hi Robert,
On Friday, August 30, 2002, 6:21:02 PM, you wrote:
>>> (select test 'type) = (to-path replace text "_" "/")
TO-PATH is not doing what you expect it to do (maybe this is a
bug, what do others think?); use LOAD instead.
>> p: 'a/b/c/d
== a/b/c/d
>> p/1
== a
>> p/2
== b
>> p/3
== c
>> p: to-path "a/b/c/d"
== a/b/c/d
>> p/1
== a/b/c/d
>> p/2
== none
>> p: load "a/b/c/d"
== a/b/c/d
>> p/1
== a
>> p/2
== b
Regards,
Gabriele.
--
Gabriele Santilli <[g--santilli--tiscalinet--it]> -- REBOL Programmer
Amigan -- AGI L'Aquila -- REB: http://web.tiscali.it/rebol/index.r
[5/13] from: anton:lexicon at: 31-Aug-2002 3:42
Ok, so this does essentially the same,
but it does it in place and doesn't use any
extra words:
(select test 'type) to-path foreach str parse text "_" [append [] to-word str]
except for 'str, which is tucked away safely in
the foreach's context.
Anton.
[6/13] from: greggirwin:mindspring at: 30-Aug-2002 12:18
Robert, Scott, et al
<< I couldn't get Gregg's to work; maybe I misunderstand its use; maybe I'm
not reading carefully enough again! Very common theme...>>
Sorry I didn't provide a usage example. Let me know if the following example
helps.
--Gregg
>> path-from-dlm-string: func [string dlm /local result] [
[ result: make path! none
[ foreach item parse/all string dlm [
[ append result to word! item
[ ]
[ result
[ ]
>> test: [type contact/company]
== [type contact/company]
>> text: "contact_company"
== "contact_company"
>> (select test 'type) = path-from-dlm-string text "_"
== true
[7/13] from: greggirwin:mindspring at: 30-Aug-2002 12:22
LOAD! DOH! See, I *knew* there was an eaiser way. :)
--Gregg
[8/13] from: robert:muench:robertmuench at: 30-Aug-2002 20:26
> -----Original Message-----
> From: [rebol-bounce--rebol--com] [mailto:[rebol-bounce--rebol--com]]
<<quoted lines omitted: 4>>
> TO-PATH is not doing what you expect it to do (maybe this
> is a bug, what do others think?)
Hi, see other posting ;-))
> use LOAD instead.
Cool! I have to better remember to use load not only in combination with
external sources but to use it on internal blocks as well... For me load
isn't that natural to use in such a context but it does the job very
elegant. Robert
[9/13] from: robert:muench:robertmuench at: 30-Aug-2002 20:28
> -----Original Message-----
> From: [rebol-bounce--rebol--com] [mailto:[rebol-bounce--rebol--com]]
<<quoted lines omitted: 6>>
> path it creates only contains one element, even though it
> looks like it contains two because of the embedded slash.
Hi, grrrr... That's what I don't like. It looks like the same, the type is the
same etc. (I know the length isn't ;-) but I didn't checked this) IMO the slash
should be recognized by the to-path conversion because it's the delimiter
character for path! everywhere else...
Thanks for the info, could be added to the non-existing-Rebol-FAQ. Robert
-- Binary/unsupported file stripped by Listar --
-- Type: application/ms-tnef
-- File: winmail.dat
[10/13] from: gscottjones:mchsi at: 30-Aug-2002 13:40
Hi, Gregg,
From: "Gregg Irwin"
<snip>
> Sorry I didn't provide a usage
<<quoted lines omitted: 3>>
> >> (select test 'type) = path-from-dlm-string text "_"
> == true
That was what I was doing. Even with a fresh REBOL session, I get:
>> (select test 'type) = path-from-dlm-string text "_"
** Script Error: contact has no value
** Where: path-from-dlm-string
** Near: append result to word! item
I was puzzled, because your code looks like it should run fine. Curious.
Hmmm.
Then out of no where it occurred to me that you are using the Beta!!! When
I fire up the /Core Beta, your script runs fine. Now, I wonder what
changed???
Didn't mean to imply any sloppiness on your part; your stuff is always first
rate! Thanks for offering the usage example anyway.
--Scott Jones
[11/13] from: greggirwin:mindspring at: 30-Aug-2002 13:19
Hey Scott,
<< Then out of no where it occurred to me that you are using the Beta!!!
When
I fire up the /Core Beta, your script runs fine. Now, I wonder what
changed??? >>
Aaaahhhh! Dang. You know, I've been using it for so long now that I *very*
rarely go back and test these quickie things, which I obviously should.
Looks like it might have been a bug fix for path! values. I can see it here
too. Maybe it was the old agressive evaluation thing. I think Gabrielle's
solution should work on the old version though, which makes it smaller,
faster, better, *and* more compatible. :)
--Gregg
[12/13] from: g:santilli:tiscalinet:it at: 31-Aug-2002 0:46
Hi Scott,
On Friday, August 30, 2002, 8:40:07 PM, you wrote:
GSJ> Then out of no where it occurred to me that you are using the Beta!!! When
GSJ> I fire up the /Core Beta, your script runs fine. Now, I wonder what
GSJ> changed???
Paths are evaluated less aggressively in the beta.
Regards,
Gabriele.
--
Gabriele Santilli <[g--santilli--tiscalinet--it]> -- REBOL Programmer
Amigan -- AGI L'Aquila -- REB: http://web.tiscali.it/rebol/index.r
[13/13] from: carl:cybercraft at: 31-Aug-2002 14:05
On 31-Aug-02, Robert M. Muench wrote:
> Hi, I'm sure this is again one of those things where I'm just not
> smart enough... I would expect 'true instead of 'false with this
<<quoted lines omitted: 7>>
> Any idea? I tried this with to-lit-path as well but no luck too...
> Robert
Lots of answers already, but I didn't see any suggesting to replace
the "/" with a " "...
>> test: [type contact/company]
== [type contact/company]
>> text: "contact_company"
== "contact_company"
>> (select test 'type) = (to-path replace text "_" " ")
== true
Works on the non-beta View, at least. (;
--
Carl Read
Notes
- Quoted lines have been omitted from some messages.
View the message alone to see the lines that have been omitted