[REBOL] Non-reentrant function calling in Rebol Re:(2)

1999-12-05 Thread icimjs

Hi Eric,

you wrote:
>The fact that "unauthorized"
>dereferencing of words seems to do something useful at times is definitely a
>trap, though, and there should be much more warning about this in the
>documentation.

However, shouldn't 'f have been indefinitely extended, when f was returned
as part of the function returned by samef?

Regarding the documentation note, you should send it to [EMAIL PROTECTED]
Or should a different address be used for documentation feedback?

Elan

>
>See you,
>Eric
>
>
>



[REBOL] Non-reentrant function calling in Rebol Re:(2)

1999-12-03 Thread lmecir

Hi, Elan,

you wrote:

Hi Ladislav,

>look at this example:


>
>;Identity function, simply duplicates it's input
>id: func [x [number!]] [:x]
>;Increment function, increases it's input by one
>inc: func [x [number!]] [x + 1]
>;The same function as argument
>samef: func [f [any-function!]] [func [x] [f x]]

You comment on this function saying that it is "The same function as
argument". The same function as argument? I'm not sure what that is
supposed to mean. Perhaps you mean that it returns the same function it was
passed? I'll assume that's what you mean. Correct me if I'm wrong.

>a: samef :id
>;and now it comes:

Wait. Wait. You've got a little bug! If samef indeed is suppsed to return
the same function it was passed, samef should be defined like this:

---
I am sorry, but your approach is worth nothing,
it's too trivial.

With it you can define *only* the same function, but nothing like:

;composition of two functions
o: func [f g] [func [x] [f g x]]
;or shiftarg
shiftarg: func [f] [func [x] [f x + 1]

And, besides, where did you find that my code is prohibited?
---

samef: func [ f [any-function!] ] [
  make function! first :f second :f
]

>> a: samef :id
>> a 1
== 1
>> a 2
== 2
>> b: samef :inc
>> b 1
== 2
>> b 2
== 3

And now for the grand finale:

>> a 1
== 1
>> a 2
== 2

Why mine works? Or better, why yours doesn't?

Using your version of samef:
>> samef: func [f [any-function!]] [func [x] [f x]]
>> a: samef :id
>> source a
a: func [x][f x]
>> b: samef :inc
>> source b
b: func [x][f x]
>> same? get first second :a get first second :b
== true

Using my version of samef:
>> samef: func [ f [any-function!] ] [
[  make function! first :f second :f
[]
>> a: samef :id
>> b: samef :inc
>> source a
a: func [x][x]
>> source b
b: func [x][x + 1]


Hope this helps.

Elan

--
sorry, it doesn't 8^(
see above, or have a good look at curried functions
--

Ladislav