rebcabin / masr

Meta ASR: replacement for aging ASDL
MIT License
4 stars 0 forks source link

Request for preference in syntactic sugar for `ttype` #3

Open rebcabin opened 1 year ago

rebcabin commented 1 year ago

An example of a fully explicit ttype entity for Integer, is, say

(Integer :kind 4, :dimensions [])

which produces

          {::term ::ttype,
           ::asr-ttype-head
           {::ttype-head ::Integer,
            ::bytes-kind 4
            ::dimensions []}}

This latter is the 'ground truth', fully explicit hash-map that specifies all details explicitly.

This issue concerns the syntax-sugar constructor functions.

This Issue requests a preference for defaulting. Clojure only allows optional keyword arguments in functions. Absent keyword arguments in a call have value nil. This issues boils down to interpreting nil in the syntax-sugar function Integer, that is, what does

(Integer)

mean?

Alternatives:

  1. Missing keyword arguments produce non-conforming specs, i.e., errors. (Integer), (Integer :kind 4), and (Integer :dimensions [6, 42]) would be errors. Upside: explicitness. Downside: verbosity. Every valid call of Integer, say, is as long as (Integer :kind 4, :dimensions []).

  2. Missing keyword arguments are defaulted to :kind 4 and :dimensions [], so that (Integer), (Integer :kind 4), and (Integer :dimensions []) all mean exactly (Integer :kind 4, :dimensions []). Upside: brevity. Downside: missing keywords are defaulted, so that a naive mistake like

(Integer 'foobar [42 45 "foo"])

means exactly (Integer :kind 4, :dimensions [])

Which alternative do you prefer? If neither, do you have a better proposal?

rebcabin commented 1 year ago

Another alternative:

  1. Two constructors: Integer-pedantic with option 1 for explicitness and Integer with option 2 for brevity.
rebcabin commented 1 year ago

I'll implement option 2 (brevity) for now, then add option 3 later because option 3 implies option 1 (explicitness)

certik commented 1 year ago

I think we will implement Dimension as a dedicated ttype, similar to Pointer. So Integer will be just (Integer :kind 4). I would not do default kinds. In ASDL, some members have ?, then they are optional, but when they do not have ?, then they should always be present, so that the backend can simply count on it, instead of always querying if it is present and then using some default.

rebcabin commented 1 year ago

just to be clear, this discussion pertains only to syntax sugar. The "full-form" always has all info spelled out in a hash map.

On Thu, Apr 13, 2023 at 12:35 PM Ondřej Čertík @.***> wrote:

I think we will implement Dimension as a dedicated ttype, similar to Pointer. So Integer will be just (Integer :kind 4). I would not do default kinds. In ASDL, some members have ?, then they are optional, but when they do not have ?, then they should always be present, so that the backend can simply count on it, instead of always querying if it is present and then using some default.

— Reply to this email directly, view it on GitHub https://github.com/rebcabin/masr/issues/3#issuecomment-1507511482, or unsubscribe https://github.com/notifications/unsubscribe-auth/AABSRR24Q2WUI6D6TN3EKC3XBBIPLANCNFSM6AAAAAAW5IEBO4 . You are receiving this because you authored the thread.Message ID: @.***>