Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

func args by ladislav

 [1/13] from: arolls:idatam:au at: 16-Oct-2001 12:40


> > To end: > > http://www.sweb.cz/LMecir/contexts.html gives a broken file > > It works OK for me. Does somebody else have the same problem > as Romano?
No, it works for me ok. Anton.

 [2/13] from: rotenca:telvia:it at: 16-Oct-2001 13:01


----- Original Message ----- From: "Ladislav Mecir" <[lmecir--mbox--vol--cz]> To: <[rebol-list--rebol--com]> Sent: Monday, October 15, 2001 10:19 PM Subject: [REBOL] Re: func args by ladislav
> Hi Romano, > > Hi, Ladislav
<<quoted lines omitted: 6>>
> and > args-taken? :do reduce [:- 1 2] ; == 3
It is the difference between: do - 1 2 and do :- 1 2 Always only one argument to 'do. Look at:
>> do :-
** Script Error: ?op? expected value1 argument of type: number pair char money date time tuple ** Where: do-boot ** Near: do :- What need an argument? do? No, the function pointed by the op. And here:
>> do -
** Script Error: Operator is missing an argument ** Where: do-boot ** Near: do - It is the operator which need an argument, not 'do. It has been already satisfied by both the espressions.
> head next [1 2] > > , you should write: > > args-taken? :head reduce [next [1 2]]
Now is clear to me how to use the function.
> > To end: > > http://www.sweb.cz/LMecir/contexts.html gives a broken file > > It works OK for me. Does somebody else have the same problem as Romano?
It was an Explorer problem. It continue to read the broken doc from the cache. Problem resolved with Rebol read (better re-read until your server awakes) :-) --- Ciao Romano

 [3/13] from: lmecir:mbox:vol:cz at: 16-Oct-2001 16:35


Hi Romano, I don't think, I must change your mind, but there is a difference you probably don't see. It is possible to define a Rebol function (a FUNCTION! datatype value to be exact), that takes one argument and evaluates it: do-f-0: func [f] [ f ] 1) DO-F-0 is able to evaluate any zero-argument function supplied as the F argument. 2) DO-F-0 is unable to evaluate any one-or-more-argument function supplied as the F argument Similarly it is possible to define a function that takes two arguments and evaluates the first one supplying it the second one as its argument: do-f-1: func [f arg1] [ f :arg1 ] do-f-2: func [f arg1 arg2] [ f :arg1 :arg2 ] etc. 3) I think, that we are in agreement, how many arguments the above defined functions take. It is evident, that for a Rebol function to evaluate its F argument, the function must take n + 1 arguments, where n is the number of arguments of F. 4) Can you write a Rebol function (a FUNCTION! datatype value) able to evaluate any F (i.e. F with any number of arguments) without cheating, i.e. without "packing" the arguments into a block? Cheers Ladislav

 [4/13] from: rotenca:telvia:it at: 16-Oct-2001 17:47


Hi Ladislav,
> Hi Romano, > > I don't think, I must change your mind, but there is a difference you
Don't worry!
> probably don't see.
I hope. A new thing to learn.
> It is possible to define a Rebol function (a FUNCTION! > datatype value to be exact), that takes one argument and evaluates it:
<<quoted lines omitted: 18>>
> argument, the function must take n + 1 arguments, where n is the number of > arguments of F.
Upto here, we agree. Functions have a fixed number of args. Right?
> 4) Can you write a Rebol function (a FUNCTION! datatype value) able to > evaluate any F (i.e. F with any number of arguments) without cheating, i.e. > without "packing" the arguments into a block?
I don't understand. If the answer is no, functions have always a fixed number of args, like i think. You think that this is false. So, you should be able to write this kind of function. Right? My answer should be: no. Only if i have a pointer to the block in which my function has been called i could emulate the interpreter and count the argument taken by f and its following args. I could try with do/next or with a deep analysys of spec of function. It should be a problem to resolve infix/prefix op. But perhaps i have not understood your point.
> Cheers > Ladislav
P.S. I'm almost sure: the datatype simbol! is created every time a new bound or not bound word is added to the system. --- Ciao Romano

 [5/13] from: rotenca:telvia:it at: 16-Oct-2001 18:52


Now i've understand. That function exists: it is 'do also if we can't write it. I'll think it. --- Ciao Romano

 [6/13] from: joel:neely:fedex at: 16-Oct-2001 12:13


Hi, Romano, Romano Paolo Tenca wrote:
> Upto here, we agree. Functions have a fixed number of args. Right? >
No, not AFAICT...
> I don't understand. If the answer is no, functions have always a fixed number > of args, like i think. > You think that this is false. So, you should be able to write this kind of > function. Right? >
Here's a function with a varying (within bounds) number of args... zzz: func [a [any-type!] b [any-type!]] [ either value? 'a [ either value? 'b [ print ["Foo with" a "and" b] ][ print ["Foo with just" a] ] ][ print "Just foo!" ] ] ... which behaves as follows ...
>> zzz
Just foo!
>> zzz 1
Foo with just 1
>> zzz 1 2
Foo with 1 and 2 Of course, this is not a completely unbounded number of arguments, but it is not absolutely fixed. -jn- -- This sentence contradicts itself -- no actually it doesn't. -- Doug Hofstadter joel<dot>neely<at>fedex<dot>com

 [7/13] from: rotenca:telvia:it at: 15-Oct-2001 18:27


Hi, Ladislav I have read your beatiful new article about func args. There is at least one thing with which I do not agree: i think that 'do takes only one argument. It is of type 'any (not 'any-type!). If you pass a function pointer to 'do, it evaluate it, if it requires others arguments the interpret take them and so on. It is the same for expressions like: next head insert ... Another thing: your function fails in these cases:
>> args-taken? :head reduce [:next [1 2]]
** Script Error: none expected series argument of type: series port ** Where: args-taken? ** Near: test: do/next test
>> args-taken? :head [next [1 2]]
** Script Error: none expected series argument of type: series port ** Where: args-taken? ** Near: test: do/next test To end: http://www.sweb.cz/LMecir/contexts.html gives a broken file --- Ciao Romano

 [8/13] from: lmecir:mbox:vol:cz at: 15-Oct-2001 22:19


Hi Romano,
> Hi, Ladislav > > I have read your beatiful new article about func args. There is at least
one
> thing with which I do not agree: i think that 'do takes only one argument.
That cannot explain the difference between: args-taken? :- [1 2] ; == 1 and args-taken? :do reduce [:- 1 2] ; == 3
> Another thing: your function fails in these cases: > > >> args-taken? :head reduce [:next [1 2]] > ** Script Error: none expected series argument of type: series port > ** Where: args-taken? > ** Near: test: do/next test
My function doesn't fail. Supplying these arguments to HEAD is the same as invoking: head :next [1 2] ** Script Error: head expected series argument of type: series port ** Where: halt-view ** Near: head :next [1 2]
> >> args-taken? :head [next [1 2]] > ** Script Error: none expected series argument of type: series port > ** Where: args-taken? > ** Near: test: do/next test
Here the example is the same as writing: head 'next [1 2] ** Script Error: head expected series argument of type: series port ** Where: halt-view ** Near: head 'next [1 2] which is wrong too. If you would like to test something like head next [1 2] , you should write: args-taken? :head reduce [next [1 2]]
> To end: > http://www.sweb.cz/LMecir/contexts.html gives a broken file
It works OK for me. Does somebody else have the same problem as Romano?
> --- > Ciao > Romano
Ciao Ladislav

 [9/13] from: rotenca:telvia:it at: 16-Oct-2001 19:52


Hi Joel,
> > Upto here, we agree. Functions have a fixed number of args. Right? > > > > No, not AFAICT...
We are not speaking of any-type! args.
> Here's a function with a varying (within bounds) number of args... > > zzz: func [a [any-type!] b [any-type!]] [
Trace: zzz (word) Trace: (end) Trace: (end) If you trace the execution of this function you will see that at every args is assigned a fixed number of values of datatype end! which appears as unset! value in the inner of function. The words 'a and 'b exist, are bound to the function context and their value is unset.
>> zzz3: func [a [any-type!] b [any-type!] c [any-type!]] [] >> zzz3
Trace: zzz3 (word) Trace: (end) Trace: (end) Trace: (end)
> Of course, this is not a completely unbounded number of arguments, > but it is not absolutely fixed.
Is "fixed" in the sense of what Mecir say about 'do. Do can collect an unlimited (undefined) number of arguments for Mecir. I can't imagine how can exists in Rebol a function like 'do. I think at a sort of in-line sostitution in case like: do :+ 3 4
> -jn-
--- Ciao Romano

 [10/13] from: g:santilli:tiscalinet:it at: 17-Oct-2001 15:06


Romano Paolo Tenca wrote:
> P.S. I'm almost sure: the datatype simbol! is created every time a new bound > or not bound word is added to the system.
Since SYMBOL! is probably still a mistery for everyone except RT, I would be very happy to know what you have discovered about it. :-) Ciao, Gabriele. -- Gabriele Santilli <[giesse--writeme--com]> - Amigan - REBOL programmer Amiga Group Italia sez. L'Aquila -- http://www.amyresource.it/AGI/

 [11/13] from: rotenca:telvia:it at: 17-Oct-2001 16:06


I have examined the dinamic changes in system/stats/types. It is not simple to understand what happens with a given instruction, because every command makes some changes in that list. --- Ciao Romano

 [12/13] from: rotenca:telvia:it at: 17-Oct-2001 17:16


Hi, Ladislav, Now i've thinked a little about the 'do mistery.
> 4) Can you write a Rebol function (a FUNCTION! datatype value) able to > evaluate any F (i.e. F with any number of arguments) without cheating, i.e. > without "packing" the arguments into a block?
No. And RT also. I think that it is impossible to write a function which read an unlimited number of arguments without a pointer to the line in which arguments can be found. So i think there are 3 cases: 1) RT "cheats". In the sense that it gives to the function 'do an hidden arg which points to the executed line (the pointer used by the interpreter). 2) In expressions like: do :- 1 2 'do sends to the interpreter a signal which say "evaluate the next value (the 'do arg) in a special mode", a sort of flag for the interpreter. I think that the 2nd case is the most probable. Among others things, in the example shown, do/next does not make its work. It seems that it makes its work only with block or other arguments which are reduced to block (file, string...). Adifference treatment between blocks and others value. 3) Mecir can explain to me how to pass an unlimited number of arguments to a function without "cheating". For what you know, the behaviour of 'do can be found in other fuctions too? --- Ciao Romano

 [13/13] from: lmecir:mbox:vol:cz at: 17-Oct-2001 23:19


Hi Romano,
> Hi, Ladislav, > > Now i've thinked a little about the 'do mistery. > > > 4) Can you write a Rebol function (a FUNCTION! datatype value) able to > > evaluate any F (i.e. F with any number of arguments) without cheating,
i.e.
> > without "packing" the arguments into a block? > > No. And RT also. I think that it is impossible to write a function which
read
> an unlimited number of arguments without a pointer to the line in which > arguments can be found.
I am sorry that I succeeded to use a confusing terminology above. What I really meant was to say, that even a one-argument taking function can "take" an "unlimited" number of arguments, if your code "prepares" the arguments as follows: args: reduce [:arg1 :arg2] f args You would probably agree, that in this case F (formally) takes only one argument.
> 1) RT "cheats". In the sense that it gives to the function 'do an hidden
arg
> which points to the executed line (the pointer used by the interpreter).
That would not be the same as above, because it still ensures, that DO can take as many arguments as it needs.
> 2) In expressions like: > > do :- 1 2 > > 'do sends to the interpreter a signal which say "evaluate the next value
(the
> 'do arg) in a special mode", a sort of flag for the interpreter.
Because DO is native, the distinction simply depends on a decision which code is considered a part of DO and which isn't.
> 3) Mecir can explain to me how to pass an unlimited number of arguments
to a
> function without "cheating".
TOP SECRET :-)
> For what you know, the behaviour of 'do can be found in other fuctions
too? I think, that the MAKE function behaves similarly as DO, because the number of arguments it takes depends on the arguments. The only difference is, that the number is limited in the case of MAKE.

Notes
  • Quoted lines have been omitted from some messages.
    View the message alone to see the lines that have been omitted