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

World: r3wp

[Core] Discuss core issues

Chris
14-Mar-2005
[701]
a: context [c: to-set-word 'b b: 123]
Pekr
14-Mar-2005
[702]
strange result, I would expect obtaining error here?
>> unset in a 'b
>> probe a

make object! [
    b: unset
    c: 6
]
>> a/b
>>
Micha
14-Mar-2005
[703]
how to add object e: 7 to a ?
Graham
14-Mar-2005
[704]
you have to clone the object with the new instance variable
Ammon
14-Mar-2005
[705]
a: make a [ e: 7 ]
Micha
14-Mar-2005
[706x2]
ok
how to [ d: 5]
word: "d"
integer : "5"
Ammon
14-Mar-2005
[708]
Lookup 'parse for that one..
Pekr
14-Mar-2005
[709]
parse? why parse? What do you mean, Micha?
Graham
14-Mar-2005
[710x3]
what do you want to do?
do [ d: 5 ]
>> d
== 5
Pekr
14-Mar-2005
[713]
>> word: "d"
== "d"
>> integer: 5
== 5
>> set to-set-word word integer
== 5
>> d
== 5
Ammon
14-Mar-2005
[714]
Or did you mean something more like...

foreach [word integer] [a 1 b 2 c 3] [
    print ["Word: " to string! word newline "Integer: " integer]
]
BrianW
14-Mar-2005
[715x2]
I'm getting a confusing error about using paths on a logic! object 
when trying to use the methods of a created object. I figure I'm 
missing something obvious, but I can't figure out what it is:

test-result: make object! [
    run-count: 0
    error-count: 0

    test-started: does [
        run-count: run-count + 1
    ]

    test-failed: does [
        error-count: error-count + 1
    ]

    summary: does [
        return join  run-count [ " run, " error-count " failed" ]
    ]
]


; ...


            ed: make test-result [ ]
            ed/test-started
            ed/test-failed
            assert [ ed/summary == "1 run, 1 failed" ]

; output of code:

[[wisti-:-us1-dhcp-227-65] xUnit]$ rebol xunit.r
** Script Error: Cannot use path on logic! value
** Where: test-failed-result-formatting
** Near: ed/test-started
ed/test-failed
assert [ed/summary == "1 run, 1 failed"]
The code is just me working my way through the book "Test-Driven 
Development" by Kent Beck. I like applying educational exercises 
to new languages as I find them :-)
Ammon
14-Mar-2005
[717]
Where is 'ed defined?
BrianW
14-Mar-2005
[718x2]
ed: make test-result [ ]
beginning of the second block
Ammon
14-Mar-2005
[720x3]
Ah, so it is. ;~>
Hm...  I end up with...

** Script Error: assert has no value
** Near: assert [ed/summary == "1 run, 1 failed"]
So 'ed must be defined somewhere else as well?  Have you tried using 
another word?
BrianW
14-Mar-2005
[723x3]
Let me make the whole script available. I was hoping it was a very 
simple logic error in those lines.
http://coolnamehere.com/rebol/xunit.r
The "probe result" line at the end is usually "print probe disarm 
result", but I set it back while trying to poke at this issue.
Ammon
14-Mar-2005
[726]
Ahah!
BrianW
14-Mar-2005
[727]
aha? Yes, yes?
Ammon
14-Mar-2005
[728]
A favorite subject of mine. ;-)
BrianW
14-Mar-2005
[729]
heh.
Ammon
14-Mar-2005
[730]
in 'test-case-test, you are redefining 'test-result as a function, 
not globaly so you aren't actually changing the definition but adding 
a new one to the current context.
BrianW
14-Mar-2005
[731]
oh jeez. Thanks :-)
Ammon
14-Mar-2005
[732]
so when you 'make 'test-result you are making a function not the 
object that you thought that you were making...
BrianW
14-Mar-2005
[733x2]
Is there a flag I can set to warn when something is being redefined?
I changed function 'test-result to function 'test-result-summary 
and everything is golden again.
Ammon
14-Mar-2005
[735x3]
You can keep your current set up with the redefined 'test-result 
but you will need to run 'compose on the spec block being passed 
to 'test-case-test and enclose 'test-result in a paren
Not for something like this, particularly since you aren't actually 
redefining anything! ;~>
You're creating a NEW definition in a NEW context.
BrianW
14-Mar-2005
[738x2]
so ...

test-case-test: make test-case compose([ ... ])
Did I understand that correctly?
Ammon
14-Mar-2005
[740x2]
almost
'compose evaluates any parens in the block passed to it.  If you 
are passing 'compose a block containing blocks that contain values 
you would like composed then you need to use the /deep refinement 
of compose
BrianW
14-Mar-2005
[742]
ow.
Ammon
14-Mar-2005
[743]
; (i.e. 
test-case-test: make test-case compose/deep [
    ...
    test-result-formating: func [/local ed][
        ed: make (test-result)
        ...
    ]
]
BrianW
14-Mar-2005
[744x2]
I think I'll avoid 'compose for now, and leave it for when I'm done 
with the basic stuff in the test book.
but that's good to know, thanks again.
Ammon
14-Mar-2005
[746]
Np, you're welcome!
Gregg
14-Mar-2005
[747]
obj-spec: func [
    "Returns the object spec as a single line (flat) string."
    obj [object!]
    /only "no surrounding brackets"
    /mold "Multi-line MOLDed format"
    /local res
][
    res: copy find/tail system/words/mold obj "make object! "
    if not mold [trim/lines res]
    if only [res: trim/auto next head remove back tail next res]
    res
]

remove-words: func [

    "Returns a copy of the object with the specified words removed."
    object [object!]
    words  [word! block!] "The word, or words, to remove"
    /local spec
][
    spec: load obj-spec object
    foreach word compose [(words)] [
        remove/part find spec to set-word! word 2
    ]
    make object! spec
]
Micha
15-Mar-2005
[748]
how to count difference time
 x:  now/precise
== 15-Mar-2005/11:01:58.139+1:00
 y: now/precise
== 15-Mar-2005/11:02:38.733+1:00

x - y  =
Graham
15-Mar-2005
[749]
help difference
Micha
15-Mar-2005
[750]
subtract