Extending an iterative template function to print information

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.

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

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.

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

Please compare list_double and list_double2 in the following file:

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.

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

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

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.

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.

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 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

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.

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.

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

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

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.