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

[bind] Patrick's pages ; using 'local ; using bind/copy

 [1/9] from: rebol:meurrens at: 14-May-2003 13:07


Hello all, Bonjour Patrick, CC to the contributors of Patrick's pages on "bind", SUMMARY: visit http://rebol.mksa.net/bind-demo-1.r?help As a fresh new rebolutionar, I appreciate the help provided by the communauty and a.o. I found in your pages all the explanations about this mysterious/magic 'bind word... Thanks... However, I have 2 small concerns regarding the "solution 3.1" of your exbind.html page. 1. I think that it would be more neat to *allways* bind, when binding your words to a local function context, by referring to 'local (the pseudo refinement allways present...) rather than relying on a specific variable. It works also for functions without parameters... 2. Another issue is that your example use "bind" rather than "bind/copy" Even if, in your small example, this is ok, I would suggest to emphasize instead the use of the /copy refinement. I think it would be stupid to create (on my own site) still another page related to bind just to publish these very small comments but I suggest instead that, after discussion of my remarks, the "main" pages on bind (namely, Patrick's pages) should eventually be updated. Everything is detailled as explained in the header partially provided below: REBOL [ Url: http://rebol.mksa.net/bind-demo-1.r?help Credits: { 1. The REBOL dictionnary entry is at URL: http://www.rebol.com/docs/words/wbind.html 2. A good introduction by Brett Handley can be found at: http://www.codeconscious.com/rebol/deeper-techniques.html#Usingcodeblocksandbind 2. An excellent tutorial on bind by Patrick Philipot (10-mar-2002, 11-mar-2002 version: 1.01) is at: http://www.pat665.free.fr/doc/bind.html an example (author: pat665 date: 3-nov-2002 contributions: Ladislav and Gabriele) is available on Patrick's site at: http://www.pat665.free.fr/doc/exbind.html 3. However the solution proposed in 3.1 of this exbind.html page - binds the block to a variable 'nb1 which is ok, ... but binding to 'local would be more neat - does not bind/copy which is ok for the example ... but may be wrong in most cases } Purpose: { - demonstrates the use of the 'local "pseudo refinement" to bind a block to the local context of a function. - demonstrates the consequences of " bind " and " bind/copy " respectively } Usage: { demo: %http://rebol.mksa.net/bind-demo-1.r browse join demo "?help" print read demo do demo } ] Regards, </marc> Prof. Ir Marc Meurrens, Brussels (be) TEL: +32 (0)2 537 2812 FAX: +32 (0)2 537 7645 EMAIL: [marc--meurrens--org] URL: http://www.meurrens.org/ REB: http://rebol.mksa.net/ PGPKEY: http://www.meurrens.org/pgp/ Please don't mail me attached files, instead, use my 'exchange area' : EXCHANGE AREA: http://www.meurrens.org/exchange/ (HTTP/FTP upload/download of temporary/persistent files)

 [2/9] from: rotenca:telvia:it at: 14-May-2003 14:12


Hi Marc
> 1. I think that it would be more neat to *allways* bind, > when binding your words to a local function context, > by referring to 'local (the pseudo refinement allways present...) rather > than relying > on a specific variable. It works also for functions without parameters...
But not for function without local words:
>> x: [local] local: 10 do does[print get first bind x 'local]
10 Is interesting to observe that /local is a refinement like any others:
>> x: func [/local a][print [local a]] >> x/local 10
true 10 --- Ciao Romano

 [3/9] from: rebol:meurrens at: 14-May-2003 23:15


Hi Romano, Taking your message in account, I have modified the page http://rebol.mksa.net/bind-demo-1.r?help and the script %http://rebol.mksa.net/bind-demo-1.r to show the availability (and eventually unavailability) of 'local under different circumstances. There are subtil differences illustrated on this page e.g. between function and func ... Practically, when a function is created with the word 'function (and I personnally prefer this fully explicit construction over the 'func 'has 'does and even make function! ...) 'local is allways available (yields none if unused in the call of the function). On the other hand, you point out a situation where there is a function without local words... But, in this case, what could be the good reason to bind a word or a block to an "unexisting" context... I was unsucessfull to find a realistic example where one would like to bind a block in such circumstances ... ??? Best regards, </marc> At 14:12 14/05/2003 +0200, Romano Paolo Tenca wrote:
>Hi Marc > > 1. I think that it would be more neat to *allways* bind,
<<quoted lines omitted: 3>>
> > on a specific variable. It works also for functions without parameters... >But not for function without local words:
Prof. Ir Marc Meurrens, Brussels (be) TEL: +32 (0)2 537 2812 FAX: +32 (0)2 537 7645 EMAIL: [marc--meurrens--org] URL: http://www.meurrens.org/ REB: http://rebol.mksa.net/ PGPKEY: http://www.meurrens.org/pgp/ Please don't mail me attached files, instead, use my 'exchange area' : EXCHANGE AREA: http://www.meurrens.org/exchange/ (HTTP/FTP upload/download of temporary/persistent files)

 [4/9] from: ptretter:charter at: 14-May-2003 20:13


Cool now lets ponder some more stuff like this: a: context [b: 1 c: 2] a/self: 3
>> probe a
make object! [ b: 1 c: 2 ]
>> a/self
== 3 You can assign a value to the objects /self refinement only after the object has been defined. Its not particularly apparent as you can see by the probe. So where is this value? It appears to be local to 'a but acts globally in some respects. now do: second a == [3 1 2] But yet it still acts an object You would obviously have to use this at your own risk as many functions might not function correctly. Paul Tretter ----- Original Message ----- From: "Marc Meurrens" <[rebol--meurrens--org]> To: <[rebol-list--rebol--com]> Cc: <[patrick--philipot--laposte--net]>; <[brett--codeconscious--com]>; <[g--santilli--tiscalinet--it]>; <[lmecir--mbox--vol--cz]>; <[team--qcp--be]> Sent: Wednesday, May 14, 2003 6:07 AM Subject: [REBOL] [bind] Patrick's pages ; using 'local ; using bind/copy
> Hello all, > Bonjour Patrick, > CC to the contributors of Patrick's pages on "bind", > > SUMMARY: visit http://rebol.mksa.net/bind-demo-1.r?help > > As a fresh new rebolutionar, I appreciate the help provided by the
communauty
> and a.o. I found in your pages all the explanations about this
mysterious/magic
> 'bind word... > Thanks...
<<quoted lines omitted: 16>>
> (namely, Patrick's pages) should eventually be updated. > Everything is detailled as explained in the header partially provided
below:
> REBOL [ > Url: http://rebol.mksa.net/bind-demo-1.r?help > Credits: { > 1. The REBOL dictionnary entry is at URL: > http://www.rebol.com/docs/words/wbind.html > > 2. A good introduction by Brett Handley can be found at: >
http://www.codeconscious.com/rebol/deeper-techniques.html#Usingcodeblocksand bind

 [5/9] from: g::santilli::tiscalinet::it at: 15-May-2003 9:53


Hi Marc, On Wednesday, May 14, 2003, 11:15:42 PM, you wrote: MM> Practically, when a function is created with the word 'function MM> (and I personnally prefer this fully explicit construction over MM> the 'func 'has 'does and even make function! ...) MM> 'local is allways available (yields none if unused in the call of the MM> function).
>> source function
function: func [ "Defines a user function with local words." spec [block!] {Optional help info followed by arg words (and optional type and string)} vars [block!] "List of words that are local to the function" body [block!] "The body block of the function" ][ make function! head insert insert tail copy spec /local vars body ] Regards, Gabriele. -- Gabriele Santilli <[g--santilli--tiscalinet--it]> -- REBOL Programmer Amigan -- AGI L'Aquila -- REB: http://web.tiscali.it/rebol/index.r

 [6/9] from: lmecir:mbox:vol:cz at: 15-May-2003 9:15


Hi Paul, ...
> a: context [b: 1 c: 2] > a/self: 3
<<quoted lines omitted: 7>>
> You can assign a value to the objects /self refinement only after the object > has been defined.
see below: context [ set 'a self b: 0 c: 1 self: 2 ] a/self probe a Regards -L

 [7/9] from: patrick:philipot:laposte at: 15-May-2003 13:23


Hi Marc, I am not sure to understand exactly what you want, but I will be happy to make any change to my page. Patrick

 [8/9] from: rotenca:telvia:it at: 15-May-2003 17:41


Hi, Marc
> On the other hand, > you point out a situation where there is a function without local words...
<<quoted lines omitted: 3>>
> a block > in such circumstances ... ???
The concept of local words in functions as a different thing from arguments and refinements is only an appearance. Strictly speaking, functions have arguments and refinements defined as local words. They have not locals words which are not arguments or refinements. Examples. Given: x: [a] a: 0 1) Classic situation, here 'a is defined like a local word (indeed it is the argument of the /local refinement!) do func [/local a][a: 34 print bind x 'a]; == 34 2) Here 'a is defined like an argument of the function (and it is also a local word) do func [a][a: 34 print bind x 'a] 1; == 34 3) Here 'a is defined like an argument of another refinement (and it is also a local word) do func [/new a][a: 34 print bind x 'a]; == 34 4) Here 'a is defined like a refinement! (and it is also a local word) do func [/a][a: 34 print bind x 'a]; == 34 --- Ciao Romano

 [9/9] from: rebol::meurrens::org at: 16-May-2003 9:39

[bind/synthesis/marc/16-May-2003] Patrick's pages ; using 'local ; using


Hello Romano, Gabriele, Patrick and the others, I agree with Romano: The concept of local words in functions as a different thing from arguments
>and refinements is only an appearance. >Strictly speaking, functions have arguments and refinements defined as local >words. They have not locals words which are not arguments or refinements.
In the 3 cases below, we may use as well 'm or 'local or 'a or 'b instead of 'n
>> a: 1 b: 2 c: 3
== 3
>> x: [ a b c ]
== [a b c]
>> do func [m n /local a b ][a: 10 b: 20 print bind x 'n ] 100 200 ; *** 1
10 20 3
>> do function [m n][a b][a: 10 b: 20 print bind x 'n ] 100 200 ; *** 2
10 20 3
>> do function [m n][a b][a: 10 b: 20 print bind x 'local ] 100 200 ; *** 3
10 20 3
>>
Thus the choice of the word used to indicate the context is quite arbitrary. If I use 'n , as in the examples 1 and 2, of course it works. But, if, later on, I modify my script I need to care about the word I effectively used to bind.
>> do func [nana m /local a b ][a: 10 b: 20 print bind x 'n ] 100 200 ;
*** 1 *** 'n removed from args but forgot in bind !!! ================== My suggestion (related to Patrick's pages) is to encourage the above form 3 a) - because the word 'local used in bind is a self documentation ! b) - because there is no need for an arbitrary choice between (in this example) 'm 'n 'local 'a 'b c) - because the word 'local is allways available in the circumstances where a bind is usefull either c-1) because you used the form 1 (func) and explicitely report the /local refinement or c-2) because this was done automatically for you in the forms 2 or 3 as already reported by Gabriele in this thread :
>> source function
function: func [ "Defines a user function with local words." spec [block!] {Optional help info followed by arg words (and optional type and string)} vars [block!] "List of words that are local to the function" body [block!] "The body block of the function" ][ make function! head insert insert tail copy spec /local vars body ]
>>
============ This thread discussed essentially the issue 1 of my initial message: http://www.escribe.com/internet/rebol/m31369.html in Patrick's page (see below), replace return do bind cb 'nb1 by return do bind cb 'local There was no message on the list on the issue 2: replace the line by: return do bind/copy cb 'local =============== My synthesis of this thread ======================== Thus, in the page http://www.pat665.free.fr/doc/exbind.html#sect3.1. After the definition of : fn-calculate: func [ nb1 [decimal!] nb2 [decimal!] nb3 [decimal!] cb [block!] ][ return do bind cb 'nb1 ] I should add the following (after reviewing my english typos...) ;;; in the above example 'nb1 was choised to define the local context ;;; but you could as well have used ;;; 'nb2 or 'nb3 or even 'cb it-self ! ;;; however, a more general definition of fn-calculate is proposed below: ;;; the 3 differences are: ;;; - we use function instead of func , and thus add an empty block between the signature and the body ;;; - we use 'local instead of 'nb1 ;;; - we use bind/copy instead of bind fn-calculate: function [ nb1 [decimal!] nb2 [decimal!] nb3 [decimal!] cb [block!] ][][ return do bind/copy cb 'local ] ;;; Mind that the word 'local used in the above example ;;; is a refinement produced automatically when using ;;; the 'function or the 'has words to build a function ;;; The double advantage of using 'local instead of 'nb1 ;;; is the readability (for everybody 'local means local !) ;;; and the fact that, if you modify your script, ;;; you don't need to modify the word used to bind. ;;; ;;; The use of bind/copy instead of bind is recommended ;;; to make sure you do not modify definitively ;;; the original version of ;;; your cb block: only a copy will be binded to your local ;;; function context. ================== In a similar approach to using 'local when binding within functions, the word 'self should be used within objects by preference over other arbitrary choised words. ============================================================== { We may have, in the future, another thread with a suggested head [bind 'self] if needed... } Thanks to all participants in this thread, Cordially </marc> Prof. Ir Marc Meurrens, Brussels (be) TEL: +32 (0)2 537 2812 FAX: +32 (0)2 537 7645 EMAIL: [marc--meurrens--org] URL: http://www.meurrens.org/ REB: http://rebol.mksa.net/ PGPKEY: http://www.meurrens.org/pgp/ Please don't mail me attached files, instead, use my 'exchange area' : EXCHANGE AREA: http://www.meurrens.org/exchange/ (HTTP/FTP upload/download of temporary/persistent files)

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