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
.