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

World: r3wp

[Core] Discuss core issues

Steeve
28-Feb-2010
[15963x2]
Because USE make and do a closure! in R3 (which is a function).
Don't like that :-)
Look that alternate implementation of USE:

>> use2: funco [vars body][foreach :vars vars body]
>> use2 [a b][a: 1 b: 2  b + a]
== 3


The funny trick is that although the [a b] vars are locals to the 
block, we can pass values from the encompassing context.

>> a: 5
== 5

>> use2 [a][a: 1 + get a]
== 6

>> a
== 5
BrianH
1-Mar-2010
[15965x2]
USE is not broken because it uses closure!, it's broken because R3 
functions don't support something like the [throw] attribute yet.
Note the "yet" - that's intended to be fixed.
Geomol
1-Mar-2010
[15967x2]
ZERO?, TRUE? and coercion. I can't really deside what to think about 
these examples:

>> zero? 0.0.0
== true
>> 0.0.0 = 0
== false

>> true? 1
== true
>> 1 = true
== false

What do you guys think?
As ZERO is defined in REBOL, the first example could be:

>> zero? 0.0.0
== true
>> 0.0.0 = zero
== false
Henrik
1-Mar-2010
[15969]
I agree with REBOL on 'zero? vs. = 0.
BrianH
1-Mar-2010
[15970x2]
The TRUE? function was added specifically to give that answer, what 
is considered truth by the conditional functions. ZERO? compares 
to the zero value of the datatype.
If TRUE? compared directly to #[true] then there would be no point 
to the function.
Geomol
1-Mar-2010
[15972x2]
Yes, there would in situations, where someone wants to set a variable 
to the truth value of something.

my-var: true? some-value
Someone might argue, that if conditional functions can operate on 
almost any value, then those values would be either true or false. 
Does it makes sense, that such values are neither true or false?
BrianH
1-Mar-2010
[15974]
That is why TRUE? is there, to convert the truth value of something 
to a logic value.
Geomol
1-Mar-2010
[15975]
>> "hey" = true
== false
>> "hey" = false
== false
>> if "hey" [print {"hey" is true}]
hey
 is true
BrianH
1-Mar-2010
[15976x3]
It does make sense to have conditionals work on more than just logic 
values. Whether or not to do so is arbitrary, and many languages 
do so (mostly the Lisp-derived languages). It's one of the two main 
models.
The Pascal-derived languages only use logic (or boolean) values. 
The assembly-derived ones use 0 and non-0. Others are weirder.
The Icon-derived ones use success and failure - those are weird, 
but useful.
Nicolas
4-Mar-2010
[15979]
Can rebol save program state as an image?
Rebolek
4-Mar-2010
[15980]
no.
Henrik
4-Mar-2010
[15981]
R2 challenge:


Implement a debug-function that uses a call-stack. I made this context:

context [
	action-level: 0
	func-name: make block! []

 set 'hint func [str] [reform [action-level: action-level + 1 ":" 
 str]]

 set 'doing func [name] [print hint join "Doing " last append func-name 
 name]

 set 'done does [print join "Done with " first name: back tail func-name 
 remove name action-level: action-level - 1]
	set 'last-hint does [print mold func-name]
]

And I use it like this:

my-func: func [] [
	doing 'my-func
	...stuff...
	done
]


What would it take to build a function that does this automatically, 
like:

my-func: debug-func [] [
	... stuff ...
]


and also automatically catches all exits, returns and throws and 
allows the function to return a value?

As this is built into R3, this is only for R2.
Andreas
4-Mar-2010
[15982x3]
debug-func: function [name spec body] [b] [b: copy body insert b 
compose [doing (name)] append b [done] tfunc spec b]
ah, that was premature :)
reminder to self: should not draft code in the altme message area 
:)
Henrik
4-Mar-2010
[15985]
well, it's a start. keep going :-)
Andreas
4-Mar-2010
[15986]
but ladislav's tfunc should help with most of the tough issues :)
Henrik
4-Mar-2010
[15987x2]
I'm not sure it's entirely simple. I would like it to work with the 
above context. The point is also that when you don't want debugging 
to work, you can insert a line:

debug-func: :func
I've not studied that one....
Andreas
4-Mar-2010
[15989]
if you want to pass the name to doing, you'll have pass the name 
to debug-func as well, i fear.
Henrik
4-Mar-2010
[15990]
then I guess I can't entirely do a debug-func: :func.


that's OK as long as there will be a method to not produce much overhead 
for production code.
Andreas
4-Mar-2010
[15991]
debug-func: func [name spec body] [make function! spec body] should 
be fine, or something similar
Henrik
4-Mar-2010
[15992]
yes, then manipulate the body to contain DOING and DONE at the right 
spots.
Andreas
4-Mar-2010
[15993]
i meant for the disabling case, now :)
Henrik
4-Mar-2010
[15994]
well, that'll do too :-)
Gabriele
5-Mar-2010
[15995x3]
there is a trick to get the function name, if you don't mind the 
overhead.
>> f: has [err] [err: disarm try [1 / 0] print ["My name is" err/where]]
>> f
My name is f
I was using this in a profiler I did which just replaced FUNC and 
did something like Henrik wants above. It did however create problems 
with more complex REBOL scripts, eg. it made the PDF Maker 2 blow 
up. I never spent the time to figure out why.
Henrik
5-Mar-2010
[15998]
it's probably better to not try to find the name during runtime, 
but simply create the debug-func function as above. With that in 
mind, it's necessary to ask how pervasive this functionality has 
to be. I don't mind that it's only useful for 'func.
Gabriele
5-Mar-2010
[15999x2]
Of note, as it may not be clear from the above, it's not the error 
trick that created problem, but the replacement of FUNC with my own 
profiling and stack tracking version.
it may be safer if you use a different name though. i don't think 
i was supporting catch and throw though.
Henrik
5-Mar-2010
[16001]
yes, agree
Gabriele
5-Mar-2010
[16002x5]
this is what i was doing:
func*: func [
    "Defines a user function with given spec and body."
    [catch]

    spec [block!] {Help string (opt) followed by arg words (and opt type 
    and string)}
    body [block!] "The body block of the function"

    /local f
] [
    throw-on-error [
        use [*temp*] [
            f: make function! spec compose/only/deep [
                in-func *temp*: do this-function-name
                out-func *temp* (body)
            ]
            body: second :f
            body/7: make function! [] body/7
            :f
        ]
    ]
]
this-function-name: [get in disarm try [1 / 0] 'where]
with in-func: func [name] [...] and out-func: func [name return-value 
[any-type!]] [... get/any 'return-value]
Ladislav's TFUNC probably handles more cases. The problem is however 
making it "transparent" enough which is a bit tricky, especially 
since you need to catch return and exit so i think you can't avoid 
having a sub function.
Henrik
5-Mar-2010
[16007x2]
if I'm being consistent, wouldn't it be enough to simply scan for 
RETURN and EXIT words?
it limits flexibility of what I can do in a function, I know.
Geomol
5-Mar-2010
[16009]
That this-function-name is kinda cool, but a trick with an overhead. 
Would it be an idea, if we could get the function name with self/name 
or something like that?
Dockimbel
5-Mar-2010
[16010]
I just hit the following issue (2.7.6 on Windows XP SP3 and Linux 
Libc6, same in 2.7.7) :
>> wait [596:0:0]
(escape)
>> wait [597:0:0]
== none


It seems that 597 hours is the maximum accepted by WAIT (Why the 
hell this kind of information is not in the online documentation 
of WAIT native?)

Will this issue be fixed if reported to RAMBO? Very doubtful.
Should REBOL be open-sourced? Yes.
Henrik
5-Mar-2010
[16011]
I don't think you should report it to RAMBO. Keep it predictably 
unfixed and undocumented forever.
Dockimbel
5-Mar-2010
[16012]
This issue is making my scheduler lib useless for general purpose 
usage (won't work for jobs scheduled in more than 24 days). As usual, 
stuck at 99% of the goal...