Print!/fprint! - how does it work?

I’d like to implement a similar macro but don’t know how.

This is for binary printing of values (to write binary files easily if
error reporting is of little concern). At first I thought that co-opting
fprint_val/fprint_ref would be enough, but now I think the user would have
to staload the overriden template instantiations for basic types (and a
host of other types, e.g. lists, etc.), which can be quite puzzling.

print! and fprint! are handled by the compiler in a special way:

There is currently no support for doing this outside the compiler.On Wed, Dec 23, 2015 at 10:33 PM, Artyom Shalkhakov < artyom.s...@gmail.com> wrote:

I’d like to implement a similar macro but don’t know how.

This is for binary printing of values (to write binary files easily if
error reporting is of little concern). At first I thought that co-opting
fprint_val/fprint_ref would be enough, but now I think the user would have
to staload the overriden template instantiations for basic types (and a
host of other types, e.g. lists, etc.), which can be quite puzzling.


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.
To post to this group, send email to ats-lan...@googlegroups.com.
Visit this group at 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/75a62ff5-d0ca-405a-a906-59d7b927677a%40googlegroups.com
https://groups.google.com/d/msgid/ats-lang-users/75a62ff5-d0ca-405a-a906-59d7b927677a%40googlegroups.com?utm_medium=email&utm_source=footer
.

I did a very minor fix to make the print_mac example work.

See:

The changes have been uploaded to the Github repo for ATS2.On Thursday, December 24, 2015 at 10:09:38 AM UTC-5, gmhwxi wrote:

I see. I think this can be made to work as expected.
I need to do a bit reverse engineering to figure it out.

On Thu, Dec 24, 2015 at 3:14 AM, Artyom Shalkhakov <artyom…> wrote:

On Thursday, December 24, 2015 at 10:08:25 AM UTC+6, gmhwxi wrote:

print! and fprint! are handled by the compiler in a special way:

https://github.com/githwxi/ATS-Postiats/blob/master/src/pats_trans1_syndef.dats

There is currently no support for doing this outside the compiler.

Thanks for the info. There is commented out code in
$ATSHOME/prelude/lmacrodef.sats (the print_mac and println_mac). Can these
be used instead of print! and println! ? I tried this code:

#include
“share/atspre_staload.hats”

local

macrodef
rec
auxlist
(xs, y) =
(
//
if iscons! (xs) then
`(print ,(car! xs); ,(auxlist (cdr! xs, y)))
else y // end of [if]
//
) // end of [auxlist]

in (* in of [local] *)

macdef
print_mac (x) =
,(
if islist! (x) then auxlist (x, ()) else (print ,(x))
) // end of [print_mac]

macdef
println_mac (x) =
,(
if islist! (x)
then auxlist (x, (print_newline())) else (print ,(x))
// end of [if]
) // end of [println_mac]

end // end of [local]

implement
main0 () = {
val () = println_mac ("the value is: ", 2*2)
}

and it yields:

admin@artyom-laptop:ats$patscc lmacrodeftest.dats
/home/admin/org/ats/lmacrodeftest.dats: 576(line=38, offs=12) –
611(line=38, offs=47): error(mac): the form of dynamic expression
[D2Esing(D2Eifhead(D2Emacfun(iscons; D2Evar(xs$3803(-1)));
D2Emacsyn(MSKencode; D2Eseq(D2Eapplst(D2Esym(print); D2EXPARGdyn(-1;
D2Emacsyn(MSKdecode; D2Emacfun(car; D2Evar(xs$3803(-1)))))),
D2Emacsyn(MSKdecode; D2Eapplst(D2Emac(auxlist); D2EXPARGdyn(-1;
D2Emacfun(cdr; D2Evar(xs$3803(-1))), D2Evar(y$3804(-1)))))));
Some(D2Evar(y$3804(-1)))))] is unsupported for macro expansion.
/home/admin/org/ats/lmacrodeftest.dats: 576(line=38, offs=12) –
611(line=38, offs=47): error(mac): the expansion of the dynamic expression
at (/home/admin/org/ats/lmacrodeftest.dats: 391(line=29, offs=3) –
466(line=30, offs=60)) is expected to return code (AST) but it does not.
/home/admin/org/ats/lmacrodeftest.dats: 571(line=38, offs=7) –
573(line=38, offs=9): error(3): the void pattern is ill-typed.
/home/admin/org/ats/lmacrodeftest.dats: 571(line=38, offs=7) –
573(line=38, offs=9): error(3): mismatch of static terms (tyleq):
The actual term is: S2Ecst(atsvoid_t0ype)
The needed term is: S2Eerr()
patsopt(TRANS3): there are [2] errors in total.
exit(ATS): uncaught exception:
_2home_2admin_2postiats_2src_2pats_error_2esats__FatalErrorExn(1025)

On Wed, Dec 23, 2015 at 10:33 PM, Artyom Shalkhakov < artyo...@gmail.com> wrote:

I’d like to implement a similar macro but don’t know how.

This is for binary printing of values (to write binary files easily if
error reporting is of little concern). At first I thought that co-opting
fprint_val/fprint_ref would be enough, but now I think the user would have
to staload the overriden template instantiations for basic types (and a
host of other types, e.g. lists, etc.), which can be quite puzzling.


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.
To post to this group, send email to ats-l...@googlegroups.com.
Visit this group at 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/75a62ff5-d0ca-405a-a906-59d7b927677a%40googlegroups.com
https://groups.google.com/d/msgid/ats-lang-users/75a62ff5-d0ca-405a-a906-59d7b927677a%40googlegroups.com?utm_medium=email&utm_source=footer
.


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.
To post to this group, send email to ats-lan...@googlegroups.com.
Visit this group at 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/880affc7-d82b-48b7-a67f-ecbab9cb00f0%40googlegroups.com
https://groups.google.com/d/msgid/ats-lang-users/880affc7-d82b-48b7-a67f-ecbab9cb00f0%40googlegroups.com?utm_medium=email&utm_source=footer
.

I see. I think this can be made to work as expected.
I need to do a bit reverse engineering to figure it out.On Thu, Dec 24, 2015 at 3:14 AM, Artyom Shalkhakov < artyom.s...@gmail.com> wrote:

On Thursday, December 24, 2015 at 10:08:25 AM UTC+6, gmhwxi wrote:

print! and fprint! are handled by the compiler in a special way:

https://github.com/githwxi/ATS-Postiats/blob/master/src/pats_trans1_syndef.dats

There is currently no support for doing this outside the compiler.

Thanks for the info. There is commented out code in
$ATSHOME/prelude/lmacrodef.sats (the print_mac and println_mac). Can these
be used instead of print! and println! ? I tried this code:

#include
“share/atspre_staload.hats”

local

macrodef
rec
auxlist
(xs, y) =
(
//
if iscons! (xs) then
`(print ,(car! xs); ,(auxlist (cdr! xs, y)))
else y // end of [if]
//
) // end of [auxlist]

in (* in of [local] *)

macdef
print_mac (x) =
,(
if islist! (x) then auxlist (x, ()) else (print ,(x))
) // end of [print_mac]

macdef
println_mac (x) =
,(
if islist! (x)
then auxlist (x, (print_newline())) else (print ,(x))
// end of [if]
) // end of [println_mac]

end // end of [local]

implement
main0 () = {
val () = println_mac ("the value is: ", 2*2)
}

and it yields:

admin@artyom-laptop:ats$patscc lmacrodeftest.dats
/home/admin/org/ats/lmacrodeftest.dats: 576(line=38, offs=12) –
611(line=38, offs=47): error(mac): the form of dynamic expression
[D2Esing(D2Eifhead(D2Emacfun(iscons; D2Evar(xs$3803(-1)));
D2Emacsyn(MSKencode; D2Eseq(D2Eapplst(D2Esym(print); D2EXPARGdyn(-1;
D2Emacsyn(MSKdecode; D2Emacfun(car; D2Evar(xs$3803(-1)))))),
D2Emacsyn(MSKdecode; D2Eapplst(D2Emac(auxlist); D2EXPARGdyn(-1;
D2Emacfun(cdr; D2Evar(xs$3803(-1))), D2Evar(y$3804(-1)))))));
Some(D2Evar(y$3804(-1)))))] is unsupported for macro expansion.
/home/admin/org/ats/lmacrodeftest.dats: 576(line=38, offs=12) –
611(line=38, offs=47): error(mac): the expansion of the dynamic expression
at (/home/admin/org/ats/lmacrodeftest.dats: 391(line=29, offs=3) –
466(line=30, offs=60)) is expected to return code (AST) but it does not.
/home/admin/org/ats/lmacrodeftest.dats: 571(line=38, offs=7) –
573(line=38, offs=9): error(3): the void pattern is ill-typed.
/home/admin/org/ats/lmacrodeftest.dats: 571(line=38, offs=7) –
573(line=38, offs=9): error(3): mismatch of static terms (tyleq):
The actual term is: S2Ecst(atsvoid_t0ype)
The needed term is: S2Eerr()
patsopt(TRANS3): there are [2] errors in total.
exit(ATS): uncaught exception:
_2home_2admin_2postiats_2src_2pats_error_2esats__FatalErrorExn(1025)

On Wed, Dec 23, 2015 at 10:33 PM, Artyom Shalkhakov < artyo...@gmail.com> wrote:

I’d like to implement a similar macro but don’t know how.

This is for binary printing of values (to write binary files easily if
error reporting is of little concern). At first I thought that co-opting
fprint_val/fprint_ref would be enough, but now I think the user would have
to staload the overriden template instantiations for basic types (and a
host of other types, e.g. lists, etc.), which can be quite puzzling.


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.
To post to this group, send email to ats-l...@googlegroups.com.
Visit this group at 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/75a62ff5-d0ca-405a-a906-59d7b927677a%40googlegroups.com
https://groups.google.com/d/msgid/ats-lang-users/75a62ff5-d0ca-405a-a906-59d7b927677a%40googlegroups.com?utm_medium=email&utm_source=footer
.


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.
To post to this group, send email to ats-lan...@googlegroups.com.
Visit this group at 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/880affc7-d82b-48b7-a67f-ecbab9cb00f0%40googlegroups.com
https://groups.google.com/d/msgid/ats-lang-users/880affc7-d82b-48b7-a67f-ecbab9cb00f0%40googlegroups.com?utm_medium=email&utm_source=footer
.

print! and fprint! are handled by the compiler in a special way:

https://github.com/githwxi/ATS-Postiats/blob/master/src/pats_trans1_syndef.dats

There is currently no support for doing this outside the compiler.

Thanks for the info. There is commented out code in
$ATSHOME/prelude/lmacrodef.sats (the print_mac and println_mac). Can these
be used instead of print! and println! ? I tried this code:

#include
“share/atspre_staload.hats”

local

macrodef
rec
auxlist
(xs, y) =
(
//
if iscons! (xs) then
`(print ,(car! xs); ,(auxlist (cdr! xs, y)))
else y // end of [if]
//
) // end of [auxlist]

in (* in of [local] *)

macdef
print_mac (x) =
,(
if islist! (x) then auxlist (x, ()) else (print ,(x))
) // end of [print_mac]

macdef
println_mac (x) =
,(
if islist! (x)
then auxlist (x, (print_newline())) else (print ,(x))
// end of [if]
) // end of [println_mac]

end // end of [local]

implement
main0 () = {
val () = println_mac ("the value is: ", 2*2)
}

and it yields:

admin@artyom-laptop:ats$patscc lmacrodeftest.dats
/home/admin/org/ats/lmacrodeftest.dats: 576(line=38, offs=12) –
611(line=38, offs=47): error(mac): the form of dynamic expression
[D2Esing(D2Eifhead(D2Emacfun(iscons; D2Evar(xs$3803(-1)));
D2Emacsyn(MSKencode; D2Eseq(D2Eapplst(D2Esym(print); D2EXPARGdyn(-1;
D2Emacsyn(MSKdecode; D2Emacfun(car; D2Evar(xs$3803(-1)))))),
D2Emacsyn(MSKdecode; D2Eapplst(D2Emac(auxlist); D2EXPARGdyn(-1;
D2Emacfun(cdr; D2Evar(xs$3803(-1))), D2Evar(y$3804(-1)))))));
Some(D2Evar(y$3804(-1)))))] is unsupported for macro expansion.
/home/admin/org/ats/lmacrodeftest.dats: 576(line=38, offs=12) –
611(line=38, offs=47): error(mac): the expansion of the dynamic expression
at (/home/admin/org/ats/lmacrodeftest.dats: 391(line=29, offs=3) –
466(line=30, offs=60)) is expected to return code (AST) but it does not.
/home/admin/org/ats/lmacrodeftest.dats: 571(line=38, offs=7) –
573(line=38, offs=9): error(3): the void pattern is ill-typed.
/home/admin/org/ats/lmacrodeftest.dats: 571(line=38, offs=7) –
573(line=38, offs=9): error(3): mismatch of static terms (tyleq):
The actual term is: S2Ecst(atsvoid_t0ype)
The needed term is: S2Eerr()
patsopt(TRANS3): there are [2] errors in total.
exit(ATS): uncaught exception:
_2home_2admin_2postiats_2src_2pats_error_2esats__FatalErrorExn(1025)> On Wed, Dec 23, 2015 at 10:33 PM, Artyom Shalkhakov <artyo...@gmail.com <javascript:>> wrote:

I’d like to implement a similar macro but don’t know how.

This is for binary printing of values (to write binary files easily if
error reporting is of little concern). At first I thought that co-opting
fprint_val/fprint_ref would be enough, but now I think the user would have
to staload the overriden template instantiations for basic types (and a
host of other types, e.g. lists, etc.), which can be quite puzzling.


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 <javascript:>.
To post to this group, send email to ats-l...@googlegroups.com
<javascript:>.
Visit this group at 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/75a62ff5-d0ca-405a-a906-59d7b927677a%40googlegroups.com
https://groups.google.com/d/msgid/ats-lang-users/75a62ff5-d0ca-405a-a906-59d7b927677a%40googlegroups.com?utm_medium=email&utm_source=footer
.