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

World: r3wp

[Core] Discuss core issues

ChristianE
23-Mar-2010
[16060x4]
>> again: :test
>> again
My name is AGAIN
The exact same function may return another name if assigned to another 
word.
Or it may return no name at all:
>> do reduce [:test]
My name is NONE
Steeve
23-Mar-2010
[16064]
nice trick
ChristianE
23-Mar-2010
[16065x2]
Credit where credit belongs, that trick is courtesy of Gabriele.
Who was the first to come up with this trick iirc.
jdishun
23-Mar-2010
[16067]
I probably didn't explain it well -- that's the behavior I want! 
Including the NONE.


Clever - I understand about creating an error object.  ... I could 
look look it up, but can you give me a quick explanation of  "/local" 
- sounds very interesting.
ChristianE
23-Mar-2010
[16068x9]
All words after the /LOCAL refinement are words local to the function, 
all words preceeding /LOCAL are function arguments
>> additon: func [one two /local three] [three: one + two] 
>> addition 1 2
== 3
The above can be written as
>> test: function [] [self] [self: get in disarm try [1 / 0] 'where 
print ["My name is" uppercase form self]]
>> test
My name is TEST
(a function with no arguments and one local word SELF)
Way shorter:
>> test: does [print ["My name is" uppercase form get in disarm try 
[1 / 0] 'where]]
>> test
My name is TEST
(no local words here)
With DOES being shorthand for a function with no arguments.
jdishun
23-Mar-2010
[16077]
I'm out of synch - but  --does  "self" have special meaning or is 
it just a varible name? If so how does it get set to  the name.
ChristianE
23-Mar-2010
[16078x3]
No, SELF is as good a word as any other, the above example with DOES 
shows that you don't need a word at all.
Just break it into little steps:
>> test: function [] [error me] [error: disarm try [1 / 0] probe 
error me: error/where print ["My name is" uppercase form me]]
>> test
make object! [
    code: 400
    type: 'math
    id: 'zero-divide
    arg1: none
    arg2: none
    arg3: none
    near: [1 / 0]
    where: 'test
]
My name is TEST
jdishun
23-Mar-2010
[16081]
Now I think I remember -- the error object contains the name of the 
function -- correct?
ChristianE
23-Mar-2010
[16082x2]
So to say. It isn't very precise, though. What's happening here is:
In the disarmed error object REBOL tells you where your code breaks; 
it breaks when trying to evaluate the word 'TEST
jdishun
23-Mar-2010
[16084]
Yes - the "little steps" reminds me about "where". That nails it

Many many thanks.
ChristianE
23-Mar-2010
[16085]
In a strict sense, REBOL doesn't tells you the name of the function 
(it can't), it rather tells you where in your code the error occurs. 
The error occurs when you try to evaluate the TEST word.
Graham
23-Mar-2010
[16086]
Not sure where to put this ... so  ...


I am running a number of server processes ... not necessarily listening 
on any ports, though some are.

What's the best way of tracking them all to make sure that they are 
all working?

I guess the processes that aren't listening on a port could touch 
a file
jdishun
23-Mar-2010
[16087]
Christian - Appreciate the clarification Works for me!
ChristianE
23-Mar-2010
[16088]
You're welcome!
Steeve
23-Mar-2010
[16089]
Great work, would be a nice alias to add in Rebol.

>> whereof: [get in disarm try [+] 'where]

>> g: f: does [print ["my name is" do whereof]]
>> g
my name is g
>> f
my name is f
ChristianE
23-Mar-2010
[16090]
>>	I guess the processes that aren't listening on a port could touch 
a file


Likely the easiest way to go, I've always went for that approach, 
Graham. Renaming files afaik is an atomic operation, so you can toggle 
process states between %process-a.running  and %process-a.finished 
or %process-b.failed etc. Not suggesting that there aren't better 
ways ...
Steeve
23-Mar-2010
[16091]
obviously, it can't be a mezz
ChristianE
23-Mar-2010
[16092]
Steeve, please make sure that BrianH doesn't see what you are suggesting 
here ;-) That method is so wrong!
Steeve
23-Mar-2010
[16093x2]
eh why that ? :)
it's rebolish enough for me
ChristianE
23-Mar-2010
[16095x2]
Mainly, I was just kidding.
On the other hand, it really is just a dirty hack, not more. The 
main point is, it doesn't provide an answer to the function's "What 
is my name?"-question. Functions have no names.
Steeve
23-Mar-2010
[16097]
(If you want BrianH accept it, just let him think he find the trick 
himself)
ChristianE
23-Mar-2010
[16098x2]
I'm not argueing that it wouldn't come in handy sometimes ... If 
you know what you do.
(That wasn't nice of you, but LOL)

Brian hopefully can LOL too :)
Steeve
23-Mar-2010
[16100]
Don't worry ;-)
ChristianE
23-Mar-2010
[16101x3]
There is another aspect of this. Questions on functions names probably 
occur too often to not answer them by a proper language construct. 

I was always thinking that something like a SELF word in functions 
would suffice. A function would then be able to envoke itself, and 
only itself, without worrying about it's "name", whatever that is.
I am no language designer, though, I'm not able to overlook the implications 
that would have.
A SELF word in a function always evaluating to the exact same function 
wouldn't be very different from being a keyword, whilst Rebol claims 
to have no keywords. I don't see a way around this.
Ladislav
23-Mar-2010
[16104]
re 'self as a keyword: do not worry, Christian, many Rebol dialects 
have keywords, e.g. 'self is already a keyword of the object specification 
dialect, as I see it. Just the Do dialect is promoted to not have 
keywords, alghough the names of infix operators actually are treated 
as keywords in R2, as I noted elsewhere
ChristianE
23-Mar-2010
[16105]
But, when Rebol evaluates a function / the code in a function's body 
- isn't that the DO dialect at its work? 

An isn't

>> a: func [value] [value]
>> a: func [value] [do [value]]

pretty much the same?
Steeve
23-Mar-2010
[16106]
Are you asking why whereof can't be a function ?
Ladislav
23-Mar-2010
[16107]
as far as I am concerned, I do not understand the people who ask 
for the name of the function - I never needed that, so it may be 
a design problem - they want to do something, that can be done in 
Rebol more elegantly, than they are trying to do it
Sunanda
23-Mar-2010
[16108]
I'd want it for better error reporting...
  error near append a b
  is not very helpful!
Hoping R3's stack etc functions will help.
Ladislav
23-Mar-2010
[16109]
but, I can define (easily) a special function specification dialect 
using the word 'self analogically as objects do, if that is of any 
interest