User defined functions like print! ?

23 views
Skip to first unread message

Yannick Duchêne

unread,
Jun 19, 2018, 6:19:24 AM6/19/18
to ats-lang-users
There is with ATS2, something reminding a feature Pascal had with Write and WriteLn. ATS2 uses an exclamation mark as a suffix for this:

val () = print!("abc", "def", "ghi") // Generates an implicit sequence

is implicitly the same as:

val () = (print("abc"); print("def"); print("ghi")) // No more exclamation mark, that’s the raw `print`.

The first case applies on multiple arguments generating an implicit sequence (ATS2 sources says the second idiomatic construct is named a sequence)

For documenting purpose, I tried to define one such function as example, but it fails, Patsopt always complains some external symbol cannot be handled, where the external symbol is the name of the function I try to define and use with an exclamation mark as a suffix:

fn f(c:char): void = ()
val () = (f('a'); f('b'); f('c')) // OK
val () = f!('a', 'b', 'c') // Says “the external id [f] cannot be handled.”

May be it’s just not accessible to user defined function?

Artyom Shalkhakov

unread,
Jun 19, 2018, 6:26:36 AM6/19/18
to ats-lang-users
Hi Yannick,

`print!` works because it is specially handled by the compiler.

However, you can write your own recursive macrodef to perform similar rewrites for you.

Please take a look at:



--
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-users+unsubscribe@googlegroups.com.
To post to this group, send email to ats-lang-users@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/30af070e-f553-4534-9168-eb0362b0e4cc%40googlegroups.com.



--
Cheers,
Artyom Shalkhakov

Yannick Duchêne

unread,
Jun 19, 2018, 7:32:05 AM6/19/18
to ats-lang-users
Additional thanks for the mention of the ATS-Postiats-test repository I did not knew, it will be useful to me, since I need a lot of ATS2 source samples for investigating ATS2 constructs.
Reply all
Reply to author
Forward
0 new messages