Skip to content

Instantly share code, notes, and snippets.

This is an enhanced version of my old generic proposal.

This proposal suggests a gen code element which can be viewed as a compile-time code generation function call. The parameters and results of a gen can be any source elements, such as type, const, var, func, import, even gen.

This proposal will use the contract idea in the Go 2 generic draft to constraint input gen parameters. It will also use the following helpers:

- `typeOf(v)` // return the type (or default type) of value `v`.
@dotaheor
dotaheor / syslog
Last active September 15, 2018 11:58
dump of /var/log/syslog
# date -d "$(</proc/uptime awk '{print $1}') seconds ago"
Sat Sep 15 06:31:45 EDT 2018
# last reboot
reboot system boot 4.18.0-1-amd64 Sat Sep 15 02:31 still running
reboot system boot 4.18.0-1-amd64 Sat Sep 15 02:25 still running
reboot system boot 4.18.0-1-amd64 Sat Sep 15 02:16 still running
reboot system boot 4.18.0-1-amd64 Sat Sep 15 01:53 still running
reboot system boot 4.18.0-1-amd64 Fri Sep 14 07:38 still running
reboot system boot 4.18.0-1-amd64 Fri Sep 14 04:31 still running
reboot system boot 4.18.0-1-amd64 Thu Sep 13 13:21 still running
@dotaheor
dotaheor / go-generic-proposal.md
Last active February 17, 2019 02:26
A Go generic syntax proposal which combine contract definition and code implementation tegother, so that generic code looks fimilar with general Go code.

A gen can be viewed as a compile-time code generation function call. It can has type and const inputs, and can has type, func and const outputs.

There are three new keywords are used in the propsoal: gen, assure and export.

A gen block body may contain

  • some assure lines which are used to constraint types. They have no effects on generic code executions. The purpose of these lines are to define inputs (types and consts) constraints/contracts. In practice, assure lines should be placed at the very beginning of a gen block.
  • some general Go code. Such as type declarations, function declarations, ...
@dotaheor
dotaheor / go-generic-constraints.md
Last active February 17, 2019 02:15
List all potentially useful type constraints/contracts

This gist will list all potentially useful type constraints/contracts. Please ignore the syntax used in this gist. The syntax is just to make the desciption convenient. If you have interests on my Go proposal, please read this gist instead.

This gist can also be viewed as a contract proposal, which propose some built-in contracts, upon which we can build more complex contracts.

Basic constraints/contracts

There are about 20 built-in (basic) contracts.

Type property related constraints/contracts