Wade Bowmer <[EMAIL PROTECTED]> wrote:

" Secondly, I had an idea of how to add references to Unicon in a
" limited but still useful capacity.

 Neat!

" 
" What I had in mind was a built-in function, probably called
" ref(), that was the reverse of copy(). That is, instead of making
" sure you had a value, it tried to make what you gave it a
" reference. So that
" 
"    a := ref(b)
" 
" ... would result in two names for the same variable, and of
" course:
" 
"    x := ref(z + 15)
" 
" ... should be absolutely identical to:
" 
"    x := z + 15

 Is this to be similar to c++ references, Fortran pointer/target, or
 Ada access types?

 I haven't given it any deep thought, but some things to think about
 may be:

 1. Are you sure that 'ref' should revert to ':=' when given an
    expression rather than a variable?  Two other options come
    to mind:

     a) fail if  i) the 'ref' parameter isn't a variable name or
                ii) the expression doesn't return a LHS (e.g.:
                    L[1] for a list L)

     b) create a reference to the value.

 2. What would/should be the result of 'x := ref(f())' where procedure
    'f' is:

    a) procedure f()
         static w := <whatever>
         return w
       end

       (Here, 'f() := <something>' changes the value of static var 'w'.
       Since 'w' is permanent, it's not unreasonable to have a
       reference to it.)

    b) procedure f()
         local L := [1, 2, 3]
         return L[1]
       end

       (Here, 'f() := 23' doesn't cause an error, but has no observable
       effect.  Since 'L' disappears when the call completes, it doesn't
       make sense to have a reference to it unless the call leaves 'L'
       for the GC.  What happens to 'L[2]' and 'L[3]'?)

 3. What happens if the referenced variable goes out of scope? E.g.:

    a) procedure f(x)
         local y := 1
         x := y
         .
         :
       end

       called as 'a := f(ref(i))'

    b) procedure f(x)
         local y := 1
         x := ref(y)    #<***
         .
         :
       end

       called as 'a := f(ref(i))'

    What happens if 'y' is a structure?

 4. Does the GC have to keep track of references?

 5. Do we have to distinguish between 'ref' assignment and ':=', e.g.:

    b := 4
    a := ref(b)  # 'a' is implicitly a pointer?
    a := 5       # b = 5
    a := ref(c)  # what happens to the reference to 'b'?
                 # does 'b' now refer to 'c'?

" 
" The biggest use for this would be to pass variables by reference
" into functions. You can sort of do it now, by doing:
" 
"    p := [ x ] f(p)
" 
" ... but you can't go back to using x after you make that call;
" you have to use p[1]. It would be so much easier if you could do
" 
"    f(ref(x))
" 
" ... then x would still be valid and the function f() could modify
" it, too.
" 

 That would be handy and is something I have wanted to do.  I wonder
 if this may not also allow something like:

   ce1 := create x | y | z
   ce2 := !f(a, x)  # f returns a list longer than 2

   while @ce1 := @ce2

 and have x, y, and z assigned.


" 
" Note, I've not spent more than about 30 minutes in the Unicon

  Well, that's about 30 minutes longer than I have :^)

" code. And it's late at night. And I'm sure there will be some
" possibly lively discussion about this. Thoughts? Clues?
" 
" Wade.
"

  Thanks in advance for the effort!

  Michael Borek
  "Death before Dishonour; Beer before Lunch"


__________________________________________________________________
New! Unlimited Netscape Internet Service.
Only $9.95 a month -- Sign up today at http://isp.netscape.com/register
Act now to get a personalized email address!

Netscape. Just the Net You Need.


-------------------------------------------------------
SF.Net is sponsored by: Speed Start Your Linux Apps Now.
Build and deploy apps & Web services for Linux with
a free DVD software kit from IBM. Click Now!
http://ads.osdn.com/?ad_id=1356&alloc_id=3438&op=click
_______________________________________________
Unicon-group mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/unicon-group

Reply via email to