# Extending an iterative template function to print information

**URL:** https://discourse.ats-lang.org/t/extending-an-iterative-template-function-to-print-information/505
**Category:** Google Group
**Created:** [February 16, 2014, 5:04pm UTC](https://discourse.ats-lang.org/t/extending-an-iterative-template-function-to-print-information/505 "2014-02-16T17:04:50Z")
**Posts on this page:** 8
**Page:** 1

<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: [February 16, 2014, 5:04pm UTC](https://discourse.ats-lang.org/t/extending-an-iterative-template-function-to-print-information/505/1 "2014-02-16T17:04:50Z")

</div>

Right now I’m wanting to print each iteration (just the iteration integer  
is fine) of list\_map\_fun. list\_map\_fun (in list.dats) is not explicitly  
iterative, and calls a functional … function called list\_map.  
So the current strategy I can think of is to basically reimplement both  
list\_map and list\_map\_fun to do what is needed - or is there a more elegant  
way?

I only ask because I still do not understand all that well what is possible  
with templates at the moment.

---

<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: [February 17, 2014, 12:07am UTC](https://discourse.ats-lang.org/t/extending-an-iterative-template-function-to-print-information/505/2 "2014-02-17T00:07:05Z")

</div>

That makes great sense; for some reason I’d tricked myself in to thinking I  
needed to use list\_map\_fun.On Sunday, February 16, 2014 2:56:39 PM UTC-5, gmhwxi wrote:

> If I understand you correctly, then this can be readily done in ATS2.
> 
> Please compare list\_double and list\_double2 in the following file:
> 
> [https://github.com/githwxi/ATS-Postiats/blob/master/doc/EXAMPLE/ATS-QA-LIST/qa-list-197.dats](https://github.com/githwxi/ATS-Postiats/blob/master/doc/EXAMPLE/ATS-QA-LIST/qa-list-197.dats)
> 
> list\_double2 is the kind of function you want.
> 
> On Sunday, February 16, 2014 2:28:11 PM UTC-5, Brandon Barker wrote:
> 
> > Not sure why the message was deleted and never went through email, maybe  
> > something to do with using an old web page on google groups.
> > 
> > Basically, what I’m proposing probably can’t be done with the list  
> > implementations anyway, but maybe with arrays (though I’m not sure that’s  
> > what we want in the long haul):
> > 
> > Currently we have:  
> > fun  
> > grexplst\_cnfize (gxs: grexplst): grcnflst
> > 
> > implement  
> > grexplst\_cnfize (gxs) =  
> > list\_map\_fun (gxs, grexp\_cnfize)
> > 
> > I was wondering (even if it isn’t possible for lists or the given list  
> > implementation), if it is possible to do something like this:  
> > implement  
> > grexplst\_cnfize (gxs) =  
> > list\_map\_fun (gxs, (print list\_map\_fun$count; print " ";  
> > grexp\_cnfize))
> > 
> > Where $count is a template “sub function” that instructs the template to  
> > maintain and increment a counter, and also returns the value of the counter.
> > 
> > On Sunday, February 16, 2014 12:23:28 PM UTC-5, gmhwxi wrote:
> > 
> > > Not sure what you want to do. Some (pseudo) code?
> > > 
> > > On Sunday, February 16, 2014 12:04:50 PM UTC-5, Brandon Barker wrote:
> > > 
> > > > Right now I’m wanting to print each iteration (just the iteration  
> > > > integer is fine) of list\_map\_fun. list\_map\_fun (in list.dats) is not  
> > > > explicitly iterative, and calls a functional … function called list\_map.  
> > > > So the current strategy I can think of is to basically reimplement both  
> > > > list\_map and list\_map\_fun to do what is needed - or is there a more elegant  
> > > > way?
> > > > 
> > > > I only ask because I still do not understand all that well what is  
> > > > possible with templates at the moment.

---

<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: [February 16, 2014, 7:56pm UTC](https://discourse.ats-lang.org/t/extending-an-iterative-template-function-to-print-information/505/3 "2014-02-16T19:56:39Z")

</div>

If I understand you correctly, then this can be readily done in ATS2.

Please compare list\_double and list\_double2 in the following file:

> <https://github.com/githwxi/ATS-Postiats/blob/master/doc/EXAMPLE/ATS-QA-LIST/qa-list-197.dats>

list\_double2 is the kind of function you want.On Sunday, February 16, 2014 2:28:11 PM UTC-5, Brandon Barker wrote:

> Not sure why the message was deleted and never went through email, maybe  
> something to do with using an old web page on google groups.
> 
> Basically, what I’m proposing probably can’t be done with the list  
> implementations anyway, but maybe with arrays (though I’m not sure that’s  
> what we want in the long haul):
> 
> Currently we have:  
> fun  
> grexplst\_cnfize (gxs: grexplst): grcnflst
> 
> implement  
> grexplst\_cnfize (gxs) =  
> list\_map\_fun (gxs, grexp\_cnfize)
> 
> I was wondering (even if it isn’t possible for lists or the given list  
> implementation), if it is possible to do something like this:  
> implement  
> grexplst\_cnfize (gxs) =  
> list\_map\_fun (gxs, (print list\_map\_fun$count; print " ";  
> grexp\_cnfize))
> 
> Where $count is a template “sub function” that instructs the template to  
> maintain and increment a counter, and also returns the value of the counter.
> 
> On Sunday, February 16, 2014 12:23:28 PM UTC-5, gmhwxi wrote:
> 
> > Not sure what you want to do. Some (pseudo) code?
> > 
> > On Sunday, February 16, 2014 12:04:50 PM UTC-5, Brandon Barker wrote:
> > 
> > > Right now I’m wanting to print each iteration (just the iteration  
> > > integer is fine) of list\_map\_fun. list\_map\_fun (in list.dats) is not  
> > > explicitly iterative, and calls a functional … function called list\_map.  
> > > So the current strategy I can think of is to basically reimplement both  
> > > list\_map and list\_map\_fun to do what is needed - or is there a more elegant  
> > > way?
> > > 
> > > I only ask because I still do not understand all that well what is  
> > > possible with templates at the moment.

---

<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: [February 17, 2014, 9:17pm UTC](https://discourse.ats-lang.org/t/extending-an-iterative-template-function-to-print-information/505/4 "2014-02-17T21:17:41Z")

</div>

The simple reason is that grcnf is not an abstract type. It can be easily  
fixed.

It may be a good idea to traverse the list twice: using list\_app the first  
time and  
using list\_map the second time.On Monday, February 17, 2014 3:37:38 PM UTC-5, Brandon Barker wrote:

> Trying this out on my actual example, I got it to typecheck and generate  
> .c code, but there seems to be some issues with compiling.
> 
> Here are the relevant parts of falcon\_cnfize.dats
> 
> #include  
> “share/atspre\_define.hats”  
> #include  
> “share/atspre\_staload.hats”  
> //  
> (\* \*\*\*\*\*\* \*\*\*\*\*\* \*)
> 
> staload “./falcon.sats”
> 
> (\* \*\*\*\*\*\* \*\*\*\*\*\* \*)
> 
> staload “./falcon\_genes.dats”  
> staload “./falcon\_parser.dats”
> 
> (\* \*\*\*\*\*\* \*\*\*\*\*\* \*)
> 
> staload  
> LS = “libats/ATS1/SATS/linset\_listord.sats”  
> staload  
> \_ = “libats/ATS1/DATS/linset\_listord.dats”
> 
> (\* \*\*\*\*\*\* \*\*\*\*\*\* \*)
> 
> staload  
> UN = “prelude/SATS/unsafe.sats”
> 
> // …  
> extern  
> fun  
> grexplst\_cnfize\_except (gxs: grexplst, exceptions: &($LS.set(int))):  
> grcnflst
> 
> implement  
> grexplst\_cnfize\_except (gxs, exceptions) = let  
> val gdum = gene\_make\_name (“dummy”)  
> var gxdum: grexp = GRgene(gdum)  
> var count: int = 0  
> //  
> implement  
> list\_map$fopr (gx) = let  
> val n = $UN.ptr0\_get(addr@count)  
> val gxd = $UN.ptr0\_get(addr@gxdum)  
> val (pf, fpf | excp) = $UN.ptr0\_vtake{$LS.set(int)}(addr@exceptions)  
> val () = (print(n); print(" "))  
> val skip = $LS.linset\_is\_member(!excp, n, lam(x,y) =\>  
> g0int\_compare\_int(x, y))  
> prval () = fpf(pf)  
> val () = $UN.ptr0\_set(addr@count, n+1)  
> in // in of [list\_map$fopr]  
> //  
> if skip then  
> (println!("Skipping rule “, n); grexp\_cnfize(gxd))  
> else  
> (print(n); print(” "); grexp\_cnfize(gx))  
> end // end of [list\_map$fopr]  
> //  
> val () = print("Starting cnfizing on rule #: ")  
> in  
> list\_map (gxs)  
> end
> 
> Here is the emitted c code surrounding the problem (which I’m not at all  
> good at reading yet):
> 
> /\*  
> emit\_instr: loc0 = : 0(line=0, offs=0) – 0(line=0, offs=0)  
> _/  
> /_  
> ibranch-mbody:  
> _/  
> /_  
> emit\_instr: loc0 = /home/brandon/ATS-Postiats/prelude/DATS/list.dats:  
> 20054(line=1044, offs=26) – 20318(line=1055, offs=8)  
> _/  
> /_  
> letpush(beg)  
> _/  
> /_  
> emit\_instr: loc0 = /home/brandon/ATS-Postiats/prelude/DATS/list.dats:  
> 20080(line=1046, offs=9) – 20102(line=1046, offs=31)  
> \*/  
> ATSINSmove(tmp146\_\_4,  
> PMVtmpltcstmat[0](list\_map$fopr\<S2Ecst(grexp)\>\<S2Eexi(n$8782(13931);  
> S2Eapp(S2Ecst(\>=); S2Evar(n$8782(13931)), S2Eintinf(0));  
> S2Eapp(S2Ecst(list\_vt); S2Ecst(genes\_vty  
> pe), S2Evar(n$8782(13931))))\>)(tmp144\_\_4)) ;
> 
> /\*  
> emit\_instr: loc0 = /home/brandon/ATS-Postiats/prelude/DATS/list.dats:  
> 20134(line=1048, offs=9) – 20163(line=1048, offs=38)  
> \*/
> 
> Full code at:  
> [https://github.com/bbarker/ATS-Postiats/tree/falconMinConjTest](https://github.com/bbarker/ATS-Postiats/tree/falconMinConjTest)
> 
> On Sunday, February 16, 2014 7:07:05 PM UTC-5, Brandon Barker wrote:
> 
> > That makes great sense; for some reason I’d tricked myself in to thinking  
> > I needed to use list\_map\_fun.
> > 
> > On Sunday, February 16, 2014 2:56:39 PM UTC-5, gmhwxi wrote:
> > 
> > > If I understand you correctly, then this can be readily done in ATS2.
> > > 
> > > Please compare list\_double and list\_double2 in the following file:
> > > 
> > > [https://github.com/githwxi/ATS-Postiats/blob/master/doc/EXAMPLE/ATS-QA-LIST/qa-list-197.dats](https://github.com/githwxi/ATS-Postiats/blob/master/doc/EXAMPLE/ATS-QA-LIST/qa-list-197.dats)
> > > 
> > > list\_double2 is the kind of function you want.
> > > 
> > > On Sunday, February 16, 2014 2:28:11 PM UTC-5, Brandon Barker wrote:
> > > 
> > > > Not sure why the message was deleted and never went through email,  
> > > > maybe something to do with using an old web page on google groups.
> > > > 
> > > > Basically, what I’m proposing probably can’t be done with the list  
> > > > implementations anyway, but maybe with arrays (though I’m not sure that’s  
> > > > what we want in the long haul):
> > > > 
> > > > Currently we have:  
> > > > fun  
> > > > grexplst\_cnfize (gxs: grexplst): grcnflst
> > > > 
> > > > implement  
> > > > grexplst\_cnfize (gxs) =  
> > > > list\_map\_fun (gxs, grexp\_cnfize)
> > > > 
> > > > I was wondering (even if it isn’t possible for lists or the given list  
> > > > implementation), if it is possible to do something like this:  
> > > > implement  
> > > > grexplst\_cnfize (gxs) =  
> > > > list\_map\_fun (gxs, (print list\_map\_fun$count; print "  
> > > > "; grexp\_cnfize))
> > > > 
> > > > Where $count is a template “sub function” that instructs the template  
> > > > to maintain and increment a counter, and also returns the value of the  
> > > > counter.
> > > > 
> > > > On Sunday, February 16, 2014 12:23:28 PM UTC-5, gmhwxi wrote:
> > > > 
> > > > > Not sure what you want to do. Some (pseudo) code?
> > > > > 
> > > > > On Sunday, February 16, 2014 12:04:50 PM UTC-5, Brandon Barker wrote:
> > > > > 
> > > > > > Right now I’m wanting to print each iteration (just the iteration  
> > > > > > integer is fine) of list\_map\_fun. list\_map\_fun (in list.dats) is not  
> > > > > > explicitly iterative, and calls a functional … function called list\_map.  
> > > > > > So the current strategy I can think of is to basically reimplement  
> > > > > > both list\_map and list\_map\_fun to do what is needed - or is there a more  
> > > > > > elegant way?
> > > > > > 
> > > > > > I only ask because I still do not understand all that well what is  
> > > > > > possible with templates at the moment.

---

<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: [February 16, 2014, 7:28pm UTC](https://discourse.ats-lang.org/t/extending-an-iterative-template-function-to-print-information/505/5 "2014-02-16T19:28:11Z")

</div>

Not sure why the message was deleted and never went through email, maybe  
something to do with using an old web page on google groups.

Basically, what I’m proposing probably can’t be done with the list  
implementations anyway, but maybe with arrays (though I’m not sure that’s  
what we want in the long haul):

Currently we have:  
fun  
grexplst\_cnfize (gxs: grexplst): grcnflst

implement  
grexplst\_cnfize (gxs) =  
list\_map\_fun (gxs, grexp\_cnfize)

I was wondering (even if it isn’t possible for lists or the given list  
implementation), if it is possible to do something like this:  
implement  
grexplst\_cnfize (gxs) =  
list\_map\_fun (gxs, (print list\_map\_fun$count; print " ";  
grexp\_cnfize))

Where $count is a template “sub function” that instructs the template to  
maintain and increment a counter, and also returns the value of the counter.On Sunday, February 16, 2014 12:23:28 PM UTC-5, gmhwxi wrote:

> Not sure what you want to do. Some (pseudo) code?
> 
> On Sunday, February 16, 2014 12:04:50 PM UTC-5, Brandon Barker wrote:
> 
> > Right now I’m wanting to print each iteration (just the iteration integer  
> > is fine) of list\_map\_fun. list\_map\_fun (in list.dats) is not explicitly  
> > iterative, and calls a functional … function called list\_map.  
> > So the current strategy I can think of is to basically reimplement both  
> > list\_map and list\_map\_fun to do what is needed - or is there a more elegant  
> > way?
> > 
> > I only ask because I still do not understand all that well what is  
> > possible with templates at the moment.

---

<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: [February 17, 2014, 8:37pm UTC](https://discourse.ats-lang.org/t/extending-an-iterative-template-function-to-print-information/505/6 "2014-02-17T20:37:38Z")

</div>

Trying this out on my actual example, I got it to typecheck and generate .c  
code, but there seems to be some issues with compiling.

Here are the relevant parts of falcon\_cnfize.dats

#include  
“share/atspre\_define.hats”  
#include  
“share/atspre\_staload.hats”  
//  
(\* \*\*\*\*\*\* \*\*\*\*\*\* \*)

staload “./falcon.sats”

(\* \*\*\*\*\*\* \*\*\*\*\*\* \*)

staload “./falcon\_genes.dats”  
staload “./falcon\_parser.dats”

(\* \*\*\*\*\*\* \*\*\*\*\*\* \*)

staload  
LS = “libats/ATS1/SATS/linset\_listord.sats”  
staload  
\_ = “libats/ATS1/DATS/linset\_listord.dats”

(\* \*\*\*\*\*\* \*\*\*\*\*\* \*)

staload  
UN = “prelude/SATS/unsafe.sats”

// …  
extern  
fun  
grexplst\_cnfize\_except (gxs: grexplst, exceptions: &($LS.set(int))):  
grcnflst

implement  
grexplst\_cnfize\_except (gxs, exceptions) = let  
val gdum = gene\_make\_name (“dummy”)  
var gxdum: grexp = GRgene(gdum)  
var count: int = 0  
//  
implement  
list\_map$fopr (gx) = let  
val n = $UN.ptr0\_get(addr@count)  
val gxd = $UN.ptr0\_get(addr@gxdum)  
val (pf, fpf | excp) = $UN.ptr0\_vtake{$LS.set(int)}(addr@exceptions)  
val () = (print(n); print(" "))  
val skip = $LS.linset\_is\_member(!excp, n, lam(x,y) =\>  
g0int\_compare\_int(x, y))  
prval () = fpf(pf)  
val () = $UN.ptr0\_set(addr@count, n+1)  
in // in of [list\_map$fopr]  
//  
if skip then  
(println!("Skipping rule “, n); grexp\_cnfize(gxd))  
else  
(print(n); print(” "); grexp\_cnfize(gx))  
end // end of [list\_map$fopr]  
//  
val () = print("Starting cnfizing on rule #: ")  
in  
list\_map (gxs)  
end

Here is the emitted c code surrounding the problem (which I’m not at all  
good at reading yet):

/\*  
emit\_instr: loc0 = : 0(line=0, offs=0) – 0(line=0, offs=0)  
_/  
/_  
ibranch-mbody:  
_/  
/_  
emit\_instr: loc0 = /home/brandon/ATS-Postiats/prelude/DATS/list.dats:  
20054(line=1044, offs=26) – 20318(line=1055, offs=8)  
_/  
/_  
letpush(beg)  
_/  
/_  
emit\_instr: loc0 = /home/brandon/ATS-Postiats/prelude/DATS/list.dats:  
20080(line=1046, offs=9) – 20102(line=1046, offs=31)  
\*/  
ATSINSmove(tmp146\_\_4,  
PMVtmpltcstmat[0](list\_map$fopr\<S2Ecst(grexp)\>\<S2Eexi(n$8782(13931);  
S2Eapp(S2Ecst(\>=); S2Evar(n$8782(13931)), S2Eintinf(0));  
S2Eapp(S2Ecst(list\_vt); S2Ecst(genes\_vty  
pe), S2Evar(n$8782(13931))))\>)(tmp144\_\_4)) ;

/\*  
emit\_instr: loc0 = /home/brandon/ATS-Postiats/prelude/DATS/list.dats:  
20134(line=1048, offs=9) – 20163(line=1048, offs=38)  
\*/

Full code at: [https://github.com/bbarker/ATS-Postiats/tree/falconMinConjTestOn](https://github.com/bbarker/ATS-Postiats/tree/falconMinConjTestOn) Sunday, February 16, 2014 7:07:05 PM UTC-5, Brandon Barker wrote:

> That makes great sense; for some reason I’d tricked myself in to thinking  
> I needed to use list\_map\_fun.
> 
> On Sunday, February 16, 2014 2:56:39 PM UTC-5, gmhwxi wrote:
> 
> > If I understand you correctly, then this can be readily done in ATS2.
> > 
> > Please compare list\_double and list\_double2 in the following file:
> > 
> > [https://github.com/githwxi/ATS-Postiats/blob/master/doc/EXAMPLE/ATS-QA-LIST/qa-list-197.dats](https://github.com/githwxi/ATS-Postiats/blob/master/doc/EXAMPLE/ATS-QA-LIST/qa-list-197.dats)
> > 
> > list\_double2 is the kind of function you want.
> > 
> > On Sunday, February 16, 2014 2:28:11 PM UTC-5, Brandon Barker wrote:
> > 
> > > Not sure why the message was deleted and never went through email, maybe  
> > > something to do with using an old web page on google groups.
> > > 
> > > Basically, what I’m proposing probably can’t be done with the list  
> > > implementations anyway, but maybe with arrays (though I’m not sure that’s  
> > > what we want in the long haul):
> > > 
> > > Currently we have:  
> > > fun  
> > > grexplst\_cnfize (gxs: grexplst): grcnflst
> > > 
> > > implement  
> > > grexplst\_cnfize (gxs) =  
> > > list\_map\_fun (gxs, grexp\_cnfize)
> > > 
> > > I was wondering (even if it isn’t possible for lists or the given list  
> > > implementation), if it is possible to do something like this:  
> > > implement  
> > > grexplst\_cnfize (gxs) =  
> > > list\_map\_fun (gxs, (print list\_map\_fun$count; print " ";  
> > > grexp\_cnfize))
> > > 
> > > Where $count is a template “sub function” that instructs the template to  
> > > maintain and increment a counter, and also returns the value of the counter.
> > > 
> > > On Sunday, February 16, 2014 12:23:28 PM UTC-5, gmhwxi wrote:
> > > 
> > > > Not sure what you want to do. Some (pseudo) code?
> > > > 
> > > > On Sunday, February 16, 2014 12:04:50 PM UTC-5, Brandon Barker wrote:
> > > > 
> > > > > Right now I’m wanting to print each iteration (just the iteration  
> > > > > integer is fine) of list\_map\_fun. list\_map\_fun (in list.dats) is not  
> > > > > explicitly iterative, and calls a functional … function called list\_map.  
> > > > > So the current strategy I can think of is to basically reimplement  
> > > > > both list\_map and list\_map\_fun to do what is needed - or is there a more  
> > > > > elegant way?
> > > > > 
> > > > > I only ask because I still do not understand all that well what is  
> > > > > possible with templates at the moment.

---

<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: [February 16, 2014, 5:23pm UTC](https://discourse.ats-lang.org/t/extending-an-iterative-template-function-to-print-information/505/7 "2014-02-16T17:23:28Z")

</div>

Not sure what you want to do. Some (pseudo) code?On Sunday, February 16, 2014 12:04:50 PM UTC-5, Brandon Barker wrote:

> Right now I’m wanting to print each iteration (just the iteration integer  
> is fine) of list\_map\_fun. list\_map\_fun (in list.dats) is not explicitly  
> iterative, and calls a functional … function called list\_map.  
> So the current strategy I can think of is to basically reimplement both  
> list\_map and list\_map\_fun to do what is needed - or is there a more elegant  
> way?
> 
> I only ask because I still do not understand all that well what is  
> possible with templates at the moment.

---

<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: [February 17, 2014, 8:41pm UTC](https://discourse.ats-lang.org/t/extending-an-iterative-template-function-to-print-information/505/8 "2014-02-17T20:41:35Z")

</div>

Forgot to post the c compiler error:

The 4th translation (type/proof-erasing) of [falcon\_cnfize.dats] is  
successfully completed!  
exec(patsopt -IATS /home/brandon/ATS-Postiats/contrib --output  
falcon\_cnfize\_dats.c --dynamic falcon\_cnfize.dats) = 0  
exec(gcc -std=c99 -D\_XOPEN\_SOURCE -I/home/brandon/ATS-Postiats  
-I/home/brandon/ATS-Postiats/ccomp/runtime  
-I/home/brandon/ATS-Postiats/contrib -DATS\_MEMALLOC\_GCBDW -D\_GNU\_SOURCE -c  
falcon\_cnfize\_dats.c)  
falcon\_cnfize\_dats.c: In function ‘loop\_52\_\_52\_\_4’:  
falcon\_cnfize\_dats.c:6989:1: error: ‘PMVtmpltcstmat’ undeclared (first use  
in this function)  
falcon\_cnfize\_dats.c:6989:1: note: each undeclared identifier is reported  
only once for each function it appears in  
falcon\_cnfize\_dats.c:6989:1: error: ‘list\_map$fopr’ undeclared (first use  
in this function)  
falcon\_cnfize\_dats.c:6989:1: warning: implicit declaration of function  
‘S2Ecst’ [-Wimplicit-function-declaration]  
falcon\_cnfize\_dats.c:6989:1: error: ‘grexp’ undeclared (first use in this  
function)  
falcon\_cnfize\_dats.c:6989:1: error: expected expression before ‘\<’ token  
exec(gcc -std=c99 -D\_XOPEN\_SOURCE -I/home/brandon/ATS-Postiats  
-I/home/brandon/ATS-Postiats/ccomp/runtime  
-I/home/brandon/ATS-Postiats/contrib -DATS\_MEMALLOC\_GCBDW -D\_GNU\_SOURCE -c  
falcon\_cnfize\_dats.c) = 256  
make: \*\*\* [falcon\_cnfize\_dats.o] Error 1On Monday, February 17, 2014 3:37:38 PM UTC-5, Brandon Barker wrote:

> Trying this out on my actual example, I got it to typecheck and generate  
> .c code, but there seems to be some issues with compiling.
> 
> Here are the relevant parts of falcon\_cnfize.dats
> 
> #include  
> “share/atspre\_define.hats”  
> #include  
> “share/atspre\_staload.hats”  
> //  
> (\* \*\*\*\*\*\* \*\*\*\*\*\* \*)
> 
> staload “./falcon.sats”
> 
> (\* \*\*\*\*\*\* \*\*\*\*\*\* \*)
> 
> staload “./falcon\_genes.dats”  
> staload “./falcon\_parser.dats”
> 
> (\* \*\*\*\*\*\* \*\*\*\*\*\* \*)
> 
> staload  
> LS = “libats/ATS1/SATS/linset\_listord.sats”  
> staload  
> \_ = “libats/ATS1/DATS/linset\_listord.dats”
> 
> (\* \*\*\*\*\*\* \*\*\*\*\*\* \*)
> 
> staload  
> UN = “prelude/SATS/unsafe.sats”
> 
> // …  
> extern  
> fun  
> grexplst\_cnfize\_except (gxs: grexplst, exceptions: &($LS.set(int))):  
> grcnflst
> 
> implement  
> grexplst\_cnfize\_except (gxs, exceptions) = let  
> val gdum = gene\_make\_name (“dummy”)  
> var gxdum: grexp = GRgene(gdum)  
> var count: int = 0  
> //  
> implement  
> list\_map$fopr (gx) = let  
> val n = $UN.ptr0\_get(addr@count)  
> val gxd = $UN.ptr0\_get(addr@gxdum)  
> val (pf, fpf | excp) = $UN.ptr0\_vtake{$LS.set(int)}(addr@exceptions)  
> val () = (print(n); print(" "))  
> val skip = $LS.linset\_is\_member(!excp, n, lam(x,y) =\>  
> g0int\_compare\_int(x, y))  
> prval () = fpf(pf)  
> val () = $UN.ptr0\_set(addr@count, n+1)  
> in // in of [list\_map$fopr]  
> //  
> if skip then  
> (println!("Skipping rule “, n); grexp\_cnfize(gxd))  
> else  
> (print(n); print(” "); grexp\_cnfize(gx))  
> end // end of [list\_map$fopr]  
> //  
> val () = print("Starting cnfizing on rule #: ")  
> in  
> list\_map (gxs)  
> end
> 
> Here is the emitted c code surrounding the problem (which I’m not at all  
> good at reading yet):
> 
> /\*  
> emit\_instr: loc0 = : 0(line=0, offs=0) – 0(line=0, offs=0)  
> _/  
> /_  
> ibranch-mbody:  
> _/  
> /_  
> emit\_instr: loc0 = /home/brandon/ATS-Postiats/prelude/DATS/list.dats:  
> 20054(line=1044, offs=26) – 20318(line=1055, offs=8)  
> _/  
> /_  
> letpush(beg)  
> _/  
> /_  
> emit\_instr: loc0 = /home/brandon/ATS-Postiats/prelude/DATS/list.dats:  
> 20080(line=1046, offs=9) – 20102(line=1046, offs=31)  
> \*/  
> ATSINSmove(tmp146\_\_4,  
> PMVtmpltcstmat[0](list\_map$fopr\<S2Ecst(grexp)\>\<S2Eexi(n$8782(13931);  
> S2Eapp(S2Ecst(\>=); S2Evar(n$8782(13931)), S2Eintinf(0));  
> S2Eapp(S2Ecst(list\_vt); S2Ecst(genes\_vty  
> pe), S2Evar(n$8782(13931))))\>)(tmp144\_\_4)) ;
> 
> /\*  
> emit\_instr: loc0 = /home/brandon/ATS-Postiats/prelude/DATS/list.dats:  
> 20134(line=1048, offs=9) – 20163(line=1048, offs=38)  
> \*/
> 
> Full code at:  
> [https://github.com/bbarker/ATS-Postiats/tree/falconMinConjTest](https://github.com/bbarker/ATS-Postiats/tree/falconMinConjTest)
> 
> On Sunday, February 16, 2014 7:07:05 PM UTC-5, Brandon Barker wrote:
> 
> > That makes great sense; for some reason I’d tricked myself in to thinking  
> > I needed to use list\_map\_fun.
> > 
> > On Sunday, February 16, 2014 2:56:39 PM UTC-5, gmhwxi wrote:
> > 
> > > If I understand you correctly, then this can be readily done in ATS2.
> > > 
> > > Please compare list\_double and list\_double2 in the following file:
> > > 
> > > [https://github.com/githwxi/ATS-Postiats/blob/master/doc/EXAMPLE/ATS-QA-LIST/qa-list-197.dats](https://github.com/githwxi/ATS-Postiats/blob/master/doc/EXAMPLE/ATS-QA-LIST/qa-list-197.dats)
> > > 
> > > list\_double2 is the kind of function you want.
> > > 
> > > On Sunday, February 16, 2014 2:28:11 PM UTC-5, Brandon Barker wrote:
> > > 
> > > > Not sure why the message was deleted and never went through email,  
> > > > maybe something to do with using an old web page on google groups.
> > > > 
> > > > Basically, what I’m proposing probably can’t be done with the list  
> > > > implementations anyway, but maybe with arrays (though I’m not sure that’s  
> > > > what we want in the long haul):
> > > > 
> > > > Currently we have:  
> > > > fun  
> > > > grexplst\_cnfize (gxs: grexplst): grcnflst
> > > > 
> > > > implement  
> > > > grexplst\_cnfize (gxs) =  
> > > > list\_map\_fun (gxs, grexp\_cnfize)
> > > > 
> > > > I was wondering (even if it isn’t possible for lists or the given list  
> > > > implementation), if it is possible to do something like this:  
> > > > implement  
> > > > grexplst\_cnfize (gxs) =  
> > > > list\_map\_fun (gxs, (print list\_map\_fun$count; print "  
> > > > "; grexp\_cnfize))
> > > > 
> > > > Where $count is a template “sub function” that instructs the template  
> > > > to maintain and increment a counter, and also returns the value of the  
> > > > counter.
> > > > 
> > > > On Sunday, February 16, 2014 12:23:28 PM UTC-5, gmhwxi wrote:
> > > > 
> > > > > Not sure what you want to do. Some (pseudo) code?
> > > > > 
> > > > > On Sunday, February 16, 2014 12:04:50 PM UTC-5, Brandon Barker wrote:
> > > > > 
> > > > > > Right now I’m wanting to print each iteration (just the iteration  
> > > > > > integer is fine) of list\_map\_fun. list\_map\_fun (in list.dats) is not  
> > > > > > explicitly iterative, and calls a functional … function called list\_map.  
> > > > > > So the current strategy I can think of is to basically reimplement  
> > > > > > both list\_map and list\_map\_fun to do what is needed - or is there a more  
> > > > > > elegant way?
> > > > > > 
> > > > > > I only ask because I still do not understand all that well what is  
> > > > > > possible with templates at the moment.
