I wrote this:

  proc push_front (dl:&dlist_t, v:T) { 
    var oldfirst = dl*.first;
    var node = new (data=v, next=oldfirst, prev=nullptr[dnode_t]); 
    dl.first <- Ptr node;
    match oldfirst with
    | nullptr => dl.last <- Ptr node;
    | Ptr p => p.prev <- Ptr node;
    endmatch; 
  }

This is for a doubly linked list. Now I will show you the beauty of the pointer 
projection semantics:

   match oldfirst with | nullptr => dl.last | Ptr p => p.prev endmatch <- Ptr 
node;

In fact we can do better if we like convoluted expressions:

        proc asgn2[T] (p: &T, q:&T) (var v:T) { p <- v; q <-v; }

to save writing "Ptr node" more than once :)

--
john skaller
skal...@users.sourceforge.net
http://felix-lang.org




------------------------------------------------------------------------------
Dive into the World of Parallel Programming The Go Parallel Website, sponsored
by Intel and developed in partnership with Slashdot Media, is your hub for all
things parallel software development, from weekly thought leadership blogs to
news, videos, case studies, tutorials and more. Take a look and join the 
conversation now. http://goparallel.sourceforge.net/
_______________________________________________
Felix-language mailing list
Felix-language@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/felix-language

Reply via email to