About the "ugliness" of C-style of ATS code

ATS has a fairly sophisticated macro system, which, unfortunately, has
barely been
documented.

Say I want to prettify Chiris Double’s code:

I can first introduce the following macros:

macdef int(x) = $UN.cast2int(,(x))
macdef ucharptr_succ § = ptr0_succ (,§)
macdef ucharptr_get § = $UN.ptr0_get (,§)
macdef ucharptr_set (p, c) = $UN.ptr0_set (,§, ,©)

Instead of writing $UN.cast2int(payload), I can write (int)payload, which a
C programmer
would probably prefer.

Similarly, a C programmer probably prefers ucharptr_set(p, c) over
$UN.ptr0_set (p, c).

Actually, n2s and s2n in Chris’s code can take advantage of the support for
call-by-reference
in ATS:

fun n2s (p: &ptr >> _): usint
fun s2n (p: &ptr >> _, x: usint): void

We can have the following if p is a left-value:

macdef ucharptr_incby1 § = ,§ := ptr0_succ (,§)

In Lisp, there is so-called backquote-comma-notation for defining macros.
ATS borrowed it.

macdef foo(x) = ,(x) + ,(x) // short form

is shorthand fo

macrodef foo(x) = `(,(x) + ,(x)) // long form

(...) means to treat whatever inside literally; ,(...) cancels the effect of (…). Search for backquote-comma-notation,
and you should find plenty explanation.On Sat, May 9, 2015 at 10:20 PM, ‘Yannick Duchêne’ via ats-lang-users < ats-lan...@googlegroups.com> wrote:

Le vendredi 11 avril 2014 22:02:59 UTC+2, gmhwxi a écrit :

ATS has a fairly sophisticated macro system, which, unfortunately, has
barely been
documented.

Say I want to prettify Chiris Double’s code:

https://github.com/doublec/openssl/blob/ats/ssl/d1_both.dats

I can first introduce the following macros:

macdef int(x) = $UN.cast2int(,(x))
macdef ucharptr_succ (p) = ptr0_succ (,(p))
macdef ucharptr_get (p) = $UN.ptr0_get (,(p))
macdef ucharptr_set (p, c) = $UN.ptr0_set (,(p), ,(c))

Instead of writing $UN.cast2int(payload), I can write (int)payload, which
a C programmer
would probably prefer.

Similarly, a C programmer probably prefers ucharptr_set(p, c) over
$UN.ptr0_set (p, c).

Actually, n2s and s2n in Chris’s code can take advantage of the support
for call-by-reference
in ATS:

fun n2s (p: &ptr >> _): usint
fun s2n (p: &ptr >> _, x: usint): void

We can have the following if p is a left-value:

macdef ucharptr_incby1 (p) = ,(p) := ptr0_succ (,(p))

Please, how to understand the commas in these definitions? Why are there
commas which seems to separate blanks? Also, what is the reasons of the
seemingly unnecessary parentheses around what looks to be atomic
expressions? Is this for the same reason as with C defines, which is to
avoid issue in case the expression is composed with operators which could
cause precedence issues?


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 http://groups.google.com/group/ats-lang-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/ats-lang-users/9d254cb6-8705-4315-a28a-d41351186687%40googlegroups.com
https://groups.google.com/d/msgid/ats-lang-users/9d254cb6-8705-4315-a28a-d41351186687%40googlegroups.com?utm_medium=email&utm_source=footer
.

ATS has a fairly sophisticated macro system, which, unfortunately, has
barely been
documented.

Say I want to prettify Chiris Double’s code:

https://github.com/doublec/openssl/blob/ats/ssl/d1_both.dats

I can first introduce the following macros:

macdef int(x) = $UN.cast2int(,(x))
macdef ucharptr_succ (p) = ptr0_succ (,(p))
macdef ucharptr_get (p) = $UN.ptr0_get (,(p))
macdef ucharptr_set (p, c) = $UN.ptr0_set (,(p), ,(c))

Instead of writing $UN.cast2int(payload), I can write (int)payload, which
a C programmer
would probably prefer.

Similarly, a C programmer probably prefers ucharptr_set(p, c) over
$UN.ptr0_set (p, c).

Actually, n2s and s2n in Chris’s code can take advantage of the support
for call-by-reference
in ATS:

fun n2s (p: &ptr >> _): usint
fun s2n (p: &ptr >> _, x: usint): void

We can have the following if p is a left-value:

macdef ucharptr_incby1 (p) = ,(p) := ptr0_succ (,(p))

Please, how to understand the commas in these definitions? Why are there
commas which seems to separate blanks? Also, what is the reasons of the
seemingly unnecessary parentheses around what looks to be atomic
expressions? Is this for the same reason as with C defines, which is to
avoid issue in case the expression is composed with operators which could
cause precedence issues?