# Atscc2clj

**URL:** <https://discourse.ats-lang.org/t/atscc2clj/816>\
**Category:** Google Group\
**Created:** [July 14, 2016, 9:15pm UTC](https://discourse.ats-lang.org/t/atscc2clj/816 "2016-07-14T21:15:34Z")\
**Posts on this page:** 5\
**Page:** 1

<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:** [July 14, 2016, 9:15pm UTC](https://discourse.ats-lang.org/t/atscc2clj/816/1 "2016-07-14T21:15:34Z")

</div>

I am pleased to announce that  
ATS code can now be compiled to Clojure (and then to JVM).

I include an example as follows.

Obviously, the generated Clojure code is not so-called idiomatic Clojure  
code.  
But it is really a lot safer than manually written Clojure code because the  
source  
of the code passes type-checking in ATS.

;;fun  
(defn  
fact[arg0]  
(  
with-local-vars  
[  
;;knd = 0  
tmpret0 nil  
tmp1 nil  
tmp2 nil  
tmp3 nil  
;;var tmplab, tmplab\_clj  
] ;; with-local-vars  
;; \_\_patsflab\_fact  
(var-set tmp1 (ats2cljpre\_gt\_int0\_int0 arg0 0))  
(if @tmp1  
(do  
(var-set tmp3 (ats2cljpre\_sub\_int0\_int0 arg0 1))  
(var-set tmp2 (fact @tmp3))  
(ats2cljpre\_mul\_int0\_int0 arg0 @tmp2)  
) ;; if-then  
(do  
1  
) ;; if-else  
)  
) ;; end-of-with-local-vars  
) ;; end-of-fun

Now I need to figure out how to write apps in Clojure 🙂 After that, we  
should be able to write apps in ATS (via Clojure).

Cheers!

---

<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:** [July 17, 2016, 1:37am UTC](https://discourse.ats-lang.org/t/atscc2clj/816/2 "2016-07-17T01:37:15Z")

</div>

Ported some old code for testing atscc2cli:

[https://github.com/githwxi/ATS-Postiats-contrib/tree/master/projects/SMALL/GameOf24/ClojureOn](https://github.com/githwxi/ATS-Postiats-contrib/tree/master/projects/SMALL/GameOf24/ClojureOn) Friday, July 15, 2016 at 10:59:26 AM UTC-4, gmhwxi wrote:

> For the record, here is the directory for Atscc2clj:
> 
> [https://github.com/githwxi/ATS-Postiats-contrib/tree/master/projects/MEDIUM/CATS-atsccomp/CATS-atscc2clj](https://github.com/githwxi/ATS-Postiats-contrib/tree/master/projects/MEDIUM/CATS-atsccomp/CATS-atscc2clj)
> 
> There is a Makefile for generating atscc2clj. Also, some of the running  
> examples can be found at:
> 
> [https://github.com/githwxi/ATS-Postiats-contrib/tree/master/projects/MEDIUM/CATS-atsccomp/CATS-atscc2clj/TEST](https://github.com/githwxi/ATS-Postiats-contrib/tree/master/projects/MEDIUM/CATS-atsccomp/CATS-atscc2clj/TEST)
> 
> Clojure uses a rather peculiar way to support optimization of recursive  
> tail-calls. So far, ATS can only properly handle tail-call  
> optimization if the call is located not inside the body of a pattern  
> matching clause. Hopefully, this restriction can be removed  
> later…
> 
> On Thursday, July 14, 2016 at 5:15:35 PM UTC-4, gmhwxi wrote:
> 
> > I am pleased to announce that  
> > ATS code can now be compiled to Clojure (and then to JVM).
> > 
> > I include an example as follows.
> > 
> > Obviously, the generated Clojure code is not so-called idiomatic Clojure  
> > code.  
> > But it is really a lot safer than manually written Clojure code because  
> > the source  
> > of the code passes type-checking in ATS.
> > 
> > ;;fun  
> > (defn  
> > fact[arg0]  
> > (  
> > with-local-vars  
> > [  
> > ;;knd = 0  
> > tmpret0 nil  
> > tmp1 nil  
> > tmp2 nil  
> > tmp3 nil  
> > ;;var tmplab, tmplab\_clj  
> > ] ;; with-local-vars  
> > ;; \_\_patsflab\_fact  
> > (var-set tmp1 (ats2cljpre\_gt\_int0\_int0 arg0 0))  
> > (if @tmp1  
> > (do  
> > (var-set tmp3 (ats2cljpre\_sub\_int0\_int0 arg0 1))  
> > (var-set tmp2 (fact @tmp3))  
> > (ats2cljpre\_mul\_int0\_int0 arg0 @tmp2)  
> > ) ;; if-then  
> > (do  
> > 1  
> > ) ;; if-else  
> > )  
> > ) ;; end-of-with-local-vars  
> > ) ;; end-of-fun
> > 
> > Now I need to figure out how to write apps in Clojure 🙂 After that, we  
> > should be able to write apps in ATS (via Clojure).
> > 
> > Cheers!

---

<div class="post-metadata">

**Author:** ![Brandon\_Barker](https://sea1.discourse-cdn.com/flex019/user_avatar/discourse.ats-lang.org/brandon_barker/32/61_2.png) [@Brandon\_Barker](https://discourse.ats-lang.org/u/Brandon_Barker)\
**Post date:** [July 14, 2016, 9:18pm UTC](https://discourse.ats-lang.org/t/atscc2clj/816/3 "2016-07-14T21:18:43Z")

</div>

Very nice!On Thu, Jul 14, 2016 at 5:15 PM, gmhwxi [gmh...@gmail.com](mailto:gmh...@gmail.com) wrote:

> I am pleased to announce that  
> ATS code can now be compiled to Clojure (and then to JVM).
> 
> I include an example as follows.
> 
> Obviously, the generated Clojure code is not so-called idiomatic Clojure  
> code.  
> But it is really a lot safer than manually written Clojure code because the  
> source  
> of the code passes type-checking in ATS.
> 
> ;;fun  
> (defn  
> fact[arg0]  
> (  
> with-local-vars  
> [  
> ;;knd = 0  
> tmpret0 nil  
> tmp1 nil  
> tmp2 nil  
> tmp3 nil  
> ;;var tmplab, tmplab\_clj  
> ] ;; with-local-vars  
> ;; \_\_patsflab\_fact  
> (var-set tmp1 (ats2cljpre\_gt\_int0\_int0 arg0 0))  
> (if @tmp1  
> (do  
> (var-set tmp3 (ats2cljpre\_sub\_int0\_int0 arg0 1))  
> (var-set tmp2 (fact @tmp3))  
> (ats2cljpre\_mul\_int0\_int0 arg0 @tmp2)  
> ) ;; if-then  
> (do  
> 1  
> ) ;; if-else  
> )  
> ) ;; end-of-with-local-vars  
> ) ;; end-of-fun
> 
> Now I need to figure out how to write apps in Clojure 🙂 After that, we  
> should be able to write apps in ATS (via Clojure).
> 
> Cheers!
> 
> –  
> 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 [https://groups.google.com/group/ats-lang-users](https://groups.google.com/group/ats-lang-users).  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/ats-lang-users/401b2ea7-b5af-4805-8ba8-1d5b30b7c899%40googlegroups.com](https://groups.google.com/d/msgid/ats-lang-users/401b2ea7-b5af-4805-8ba8-1d5b30b7c899%40googlegroups.com).

Brandon Barker  
[brandon...@gmail.com](mailto:brandon...@gmail.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:** [July 15, 2016, 2:59pm UTC](https://discourse.ats-lang.org/t/atscc2clj/816/4 "2016-07-15T14:59:26Z")

</div>

For the record, here is the directory for Atscc2clj:

[https://github.com/githwxi/ATS-Postiats-contrib/tree/master/projects/MEDIUM/CATS-atsccomp/CATS-atscc2clj](https://github.com/githwxi/ATS-Postiats-contrib/tree/master/projects/MEDIUM/CATS-atsccomp/CATS-atscc2clj)

There is a Makefile for generating atscc2clj. Also, some of the running  
examples can be found at:

[https://github.com/githwxi/ATS-Postiats-contrib/tree/master/projects/MEDIUM/CATS-atsccomp/CATS-atscc2clj/TEST](https://github.com/githwxi/ATS-Postiats-contrib/tree/master/projects/MEDIUM/CATS-atsccomp/CATS-atscc2clj/TEST)

Clojure uses a rather peculiar way to support optimization of recursive  
tail-calls. So far, ATS can only properly handle tail-call  
optimization if the call is located not inside the body of a pattern  
matching clause. Hopefully, this restriction can be removed  
later…On Thursday, July 14, 2016 at 5:15:35 PM UTC-4, gmhwxi wrote:

> I am pleased to announce that  
> ATS code can now be compiled to Clojure (and then to JVM).
> 
> I include an example as follows.
> 
> Obviously, the generated Clojure code is not so-called idiomatic Clojure  
> code.  
> But it is really a lot safer than manually written Clojure code because  
> the source  
> of the code passes type-checking in ATS.
> 
> ;;fun  
> (defn  
> fact[arg0]  
> (  
> with-local-vars  
> [  
> ;;knd = 0  
> tmpret0 nil  
> tmp1 nil  
> tmp2 nil  
> tmp3 nil  
> ;;var tmplab, tmplab\_clj  
> ] ;; with-local-vars  
> ;; \_\_patsflab\_fact  
> (var-set tmp1 (ats2cljpre\_gt\_int0\_int0 arg0 0))  
> (if @tmp1  
> (do  
> (var-set tmp3 (ats2cljpre\_sub\_int0\_int0 arg0 1))  
> (var-set tmp2 (fact @tmp3))  
> (ats2cljpre\_mul\_int0\_int0 arg0 @tmp2)  
> ) ;; if-then  
> (do  
> 1  
> ) ;; if-else  
> )  
> ) ;; end-of-with-local-vars  
> ) ;; end-of-fun
> 
> Now I need to figure out how to write apps in Clojure 🙂 After that, we  
> should be able to write apps in ATS (via Clojure).
> 
> Cheers!

---

<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:** [July 14, 2016, 9:23pm UTC](https://discourse.ats-lang.org/t/atscc2clj/816/5 "2016-07-14T21:23:49Z")

</div>

With all the Java classes being available, it is really really pleasant :)On Thursday, July 14, 2016 at 5:19:03 PM UTC-4, Brandon Barker wrote:

> Very nice!
> 
> On Thu, Jul 14, 2016 at 5:15 PM, gmhwxi \<…\> wrote:
> 
> > I am pleased to announce that  
> > ATS code can now be compiled to Clojure (and then to JVM).
> > 
> > I include an example as follows.
> > 
> > Obviously, the generated Clojure code is not so-called idiomatic Clojure  
> > code.  
> > But it is really a lot safer than manually written Clojure code because  
> > the  
> > source  
> > of the code passes type-checking in ATS.
> > 
> > ;;fun  
> > (defn  
> > fact[arg0]  
> > (  
> > with-local-vars  
> > [  
> > ;;knd = 0  
> > tmpret0 nil  
> > tmp1 nil  
> > tmp2 nil  
> > tmp3 nil  
> > ;;var tmplab, tmplab\_clj  
> > ] ;; with-local-vars  
> > ;; \_\_patsflab\_fact  
> > (var-set tmp1 (ats2cljpre\_gt\_int0\_int0 arg0 0))  
> > (if @tmp1  
> > (do  
> > (var-set tmp3 (ats2cljpre\_sub\_int0\_int0 arg0 1))  
> > (var-set tmp2 (fact @tmp3))  
> > (ats2cljpre\_mul\_int0\_int0 arg0 @tmp2)  
> > ) ;; if-then  
> > (do  
> > 1  
> > ) ;; if-else  
> > )  
> > ) ;; end-of-with-local-vars  
> > ) ;; end-of-fun
> > 
> > Now I need to figure out how to write apps in Clojure 🙂 After that, we  
> > should be able to write apps in ATS (via Clojure).
> > 
> > Cheers!
> > 
> > –  
> > 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 [https://groups.google.com/group/ats-lang-users](https://groups.google.com/group/ats-lang-users).  
> > To view this discussion on the web visit
> 
> [https://groups.google.com/d/msgid/ats-lang-users/401b2ea7-b5af-4805-8ba8-1d5b30b7c899%40googlegroups.com](https://groups.google.com/d/msgid/ats-lang-users/401b2ea7-b5af-4805-8ba8-1d5b30b7c899%40googlegroups.com).
> 
> –  
> Brandon Barker
