# Call by const reference?

**URL:** <https://discourse.ats-lang.org/t/call-by-const-reference/167>\
**Category:** Google Group\
**Created:** [September 4, 2014, 7:04pm UTC](https://discourse.ats-lang.org/t/call-by-const-reference/167 "2014-09-04T19:04:36Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shea\_Levy](https://avatars.discourse-cdn.com/v4/letter/s/b38774/32.png) [@Shea\_Levy](https://discourse.ats-lang.org/u/Shea_Levy)\
**Post date:** [September 4, 2014, 7:04pm UTC](https://discourse.ats-lang.org/t/call-by-const-reference/167/1 "2014-09-04T19:04:36Z")

</div>

Hi all,

Is there any way to declare a function call-by-reference but not allow  
it to modify its arguments? Similarly, is there a way to pass a value  
(not a variable) to such a function?

For my particular use case, I want to wrap the bind function, which  
takes a const pointer to a struct sockaddr, and there’s no inherent  
reason why a program shouldn’t be able to declare one as a val.

~Shea

---

<div class="post-metadata">

**Author:** ![Shea\_Levy](https://avatars.discourse-cdn.com/v4/letter/s/b38774/32.png) [@Shea\_Levy](https://discourse.ats-lang.org/u/Shea_Levy)\
**Post date:** [September 5, 2014, 12:19am UTC](https://discourse.ats-lang.org/t/call-by-const-reference/167/2 "2014-09-05T00:19:29Z")

</div>

Would there be any way (possibly with unsafe features under the hood?)  
to get a pointer to a value?On Thu, Sep 04, 2014 at 01:04:06PM -0700, gmhwxi wrote:

> Conceptually, this is easy to do:
> 
> absvtype RD (a:t@ype, l:addr) = ptr(l)
> 
> fun{a:t@ype} read{l:agz} (x: !RD (a, l)): a
> 
> Doing so means you need to write a lot of “administrative”  
> proof code.
> 
> On Thursday, September 4, 2014 3:04:43 PM UTC-4, Shea Levy wrote:
> 
> > Hi all,
> > 
> > Is there any way to declare a function call-by-reference but not allow  
> > it to modify its arguments? Similarly, is there a way to pass a value  
> > (not a variable) to such a function?
> > 
> > For my particular use case, I want to wrap the bind function, which  
> > takes a const pointer to a struct sockaddr, and there’s no inherent  
> > reason why a program shouldn’t be able to declare one as a val.
> > 
> > ~Shea
> 
> –  
> You received this message because you are subscribed to the Google Groups “ats-lang-users” group.  
> To unsubscribe from this group and stop receiving emails from it, send an email to [ats-lang-user...@googlegroups.com](mailto:ats-lang-user...@googlegroups.com).  
> To post to this group, send email to [ats-lan...@googlegroups.com](mailto:ats-lan...@googlegroups.com).  
> Visit this group at [http://groups.google.com/group/ats-lang-users](http://groups.google.com/group/ats-lang-users).  
> To view this discussion on the web visit [https://groups.google.com/d/msgid/ats-lang-users/421168e3-a2d8-486b-9c1d-eb1a5845499a%40googlegroups.com](https://groups.google.com/d/msgid/ats-lang-users/421168e3-a2d8-486b-9c1d-eb1a5845499a%40googlegroups.com).

---

<div class="post-metadata">

**Author:** ![gmhwxi](https://avatars.discourse-cdn.com/v4/letter/g/67e7ee/32.png) [@gmhwxi](https://discourse.ats-lang.org/u/gmhwxi)\
**Post date:** [September 5, 2014, 12:39am UTC](https://discourse.ats-lang.org/t/call-by-const-reference/167/3 "2014-09-05T00:39:26Z")

</div>

I guess it won’t hurt if I repeat myself one more time:

Learning how to use unsafe features in ATS is _essential_ for the purpose  
of practical  
programming, that is, writing code that you and others can really use (and  
also want to use).  
The real world is far more complex than any type systems :)On Thursday, September 4, 2014 8:26:30 PM UTC-4, gmhwxi wrote:

> See:
> 
> [http://www.ats-lang.org/DOCUMENT/INT2PROGINATS/HTML/x2107.html](http://www.ats-lang.org/DOCUMENT/INT2PROGINATS/HTML/x2107.html)
> 
> On Thursday, September 4, 2014 8:19:38 PM UTC-4, Shea Levy wrote:
> 
> > Would there be any way (possibly with unsafe features under the hood?)  
> > to get a pointer to a value?
> > 
> > On Thu, Sep 04, 2014 at 01:04:06PM -0700, gmhwxi wrote:
> > 
> > > Conceptually, this is easy to do:
> > > 
> > > absvtype RD (a:t@ype, l:addr) = ptr(l)
> > > 
> > > fun{a:t@ype} read{l:agz} (x: !RD (a, l)): a
> > > 
> > > Doing so means you need to write a lot of “administrative”  
> > > proof code.
> > > 
> > > On Thursday, September 4, 2014 3:04:43 PM UTC-4, Shea Levy wrote:
> > > 
> > > > Hi all,
> > > > 
> > > > Is there any way to declare a function call-by-reference but not  
> > > > allow  
> > > > it to modify its arguments? Similarly, is there a way to pass a value  
> > > > (not a variable) to such a function?
> > > > 
> > > > For my particular use case, I want to wrap the bind function, which  
> > > > takes a const pointer to a struct sockaddr, and there’s no inherent  
> > > > reason why a program shouldn’t be able to declare one as a val.
> > > > 
> > > > ~Shea
> > > 
> > > –  
> > > You received this message because you are subscribed to the Google  
> > > Groups “ats-lang-users” group.  
> > > To unsubscribe from this group and stop receiving emails from it, send  
> > > an email to [ats-lang...@googlegroups.com](mailto:ats-lang...@googlegroups.com).  
> > > To post to this group, send email to [ats-l...@googlegroups.com](mailto:ats-l...@googlegroups.com).  
> > > Visit this group at [http://groups.google.com/group/ats-lang-users](http://groups.google.com/group/ats-lang-users).  
> > > To view this discussion on the web visit  
> > > [https://groups.google.com/d/msgid/ats-lang-users/421168e3-a2d8-486b-9c1d-eb1a5845499a%40googlegroups.com](https://groups.google.com/d/msgid/ats-lang-users/421168e3-a2d8-486b-9c1d-eb1a5845499a%40googlegroups.com).

---

<div class="post-metadata">

**Author:** ![gmhwxi](https://avatars.discourse-cdn.com/v4/letter/g/67e7ee/32.png) [@gmhwxi](https://discourse.ats-lang.org/u/gmhwxi)\
**Post date:** [September 5, 2014, 12:26am UTC](https://discourse.ats-lang.org/t/call-by-const-reference/167/4 "2014-09-05T00:26:30Z")

</div>

See:

[http://www.ats-lang.org/DOCUMENT/INT2PROGINATS/HTML/x2107.htmlOn](http://www.ats-lang.org/DOCUMENT/INT2PROGINATS/HTML/x2107.htmlOn) Thursday, September 4, 2014 8:19:38 PM UTC-4, Shea Levy wrote:

> Would there be any way (possibly with unsafe features under the hood?)  
> to get a pointer to a value?
> 
> On Thu, Sep 04, 2014 at 01:04:06PM -0700, gmhwxi wrote:
> 
> > Conceptually, this is easy to do:
> > 
> > absvtype RD (a:t@ype, l:addr) = ptr(l)
> > 
> > fun{a:t@ype} read{l:agz} (x: !RD (a, l)): a
> > 
> > Doing so means you need to write a lot of “administrative”  
> > proof code.
> > 
> > On Thursday, September 4, 2014 3:04:43 PM UTC-4, Shea Levy wrote:
> > 
> > > Hi all,
> > > 
> > > Is there any way to declare a function call-by-reference but not allow  
> > > it to modify its arguments? Similarly, is there a way to pass a value  
> > > (not a variable) to such a function?
> > > 
> > > For my particular use case, I want to wrap the bind function, which  
> > > takes a const pointer to a struct sockaddr, and there’s no inherent  
> > > reason why a program shouldn’t be able to declare one as a val.
> > > 
> > > ~Shea
> > 
> > –  
> > You received this message because you are subscribed to the Google  
> > Groups “ats-lang-users” group.  
> > To unsubscribe from this group and stop receiving emails from it, send  
> > an email to [ats-lang...@googlegroups.com](mailto:ats-lang...@googlegroups.com) \<javascript:\>.  
> > To post to this group, send email to [ats-l...@googlegroups.com](mailto:ats-l...@googlegroups.com)  
> > \<javascript:\>.  
> > Visit this group at [http://groups.google.com/group/ats-lang-users](http://groups.google.com/group/ats-lang-users).  
> > To view this discussion on the web visit  
> > [https://groups.google.com/d/msgid/ats-lang-users/421168e3-a2d8-486b-9c1d-eb1a5845499a%40googlegroups.com](https://groups.google.com/d/msgid/ats-lang-users/421168e3-a2d8-486b-9c1d-eb1a5845499a%40googlegroups.com).

---

<div class="post-metadata">

**Author:** ![gmhwxi](https://avatars.discourse-cdn.com/v4/letter/g/67e7ee/32.png) [@gmhwxi](https://discourse.ats-lang.org/u/gmhwxi)\
**Post date:** [September 4, 2014, 8:04pm UTC](https://discourse.ats-lang.org/t/call-by-const-reference/167/5 "2014-09-04T20:04:06Z")

</div>

Conceptually, this is easy to do:

absvtype RD (a:t@ype, l:addr) = ptr(l)

fun{a:t@ype} read{l:agz} (x: !RD (a, l)): a

Doing so means you need to write a lot of “administrative”  
proof code.On Thursday, September 4, 2014 3:04:43 PM UTC-4, Shea Levy wrote:

> Hi all,
> 
> Is there any way to declare a function call-by-reference but not allow  
> it to modify its arguments? Similarly, is there a way to pass a value  
> (not a variable) to such a function?
> 
> For my particular use case, I want to wrap the bind function, which  
> takes a const pointer to a struct sockaddr, and there’s no inherent  
> reason why a program shouldn’t be able to declare one as a val.
> 
> ~Shea
