Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Constant with Unit #2000

Open
xushiwei opened this issue Oct 30, 2024 · 3 comments
Open

Constant with Unit #2000

xushiwei opened this issue Oct 30, 2024 · 3 comments

Comments

@xushiwei
Copy link
Member

xushiwei commented Oct 30, 2024

Proposal

const unit Distance (
    mm = 1
    cm = 10
    dm = 100
    m  = 1000
)
step 1m  // move forward 1 meter

const unit time.Duration (
    ns = time.Nanosecond
    us = time.Microsecond
    µs = time.Microsecond
    ms = time.Millisecond
    s = time.Second
    m = time.Minute
    h = time.Hour
    d = 24 * time.Hour
)
wait 1s  // wait 1 second
wait 1m  // wait 1 minute. Note that it does not conflict with `step 1m`.
xushiwei added a commit to xushiwei/gop that referenced this issue Nov 7, 2024
xushiwei added a commit to xushiwei/gop that referenced this issue Nov 7, 2024
@xushiwei
Copy link
Member Author

xushiwei commented Nov 7, 2024

number with unit: scanner/parser/format #2007

@xushiwei
Copy link
Member Author

xushiwei commented Nov 7, 2024

cl: compileNumberUnitLit - #2008
now support unit of time.Duration. eg.

wait 0.5s
wait 5µs

It is equivalent to

wait 0.5 * time.Second
wait 5 * time.Microsecond

@xushiwei xushiwei added this to the Go+ v1.3 milestone Nov 7, 2024
@xushiwei
Copy link
Member Author

xushiwei commented Nov 7, 2024

Convert

const unit Distance (
    mm = 1
    cm = 10
    dm = 100
    m  = 1000
)

into

const Gopu_Distance = "mm=1,cm=10,dm=100,m=1000"

xushiwei added a commit to xushiwei/gogen that referenced this issue Nov 8, 2024
xushiwei added a commit to xushiwei/gop that referenced this issue Nov 8, 2024
xushiwei added a commit that referenced this issue Nov 8, 2024
#2000 units of user defined type
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant