Skip to content

Concept syntax revision proposal #13

Closed
@fredrikhr

Description

@fredrikhr

Opening this issue in order to discuss strengths and weaknesses of the concept syntax and to discuss other suggested alternatives.

TL;DR

Thesis: The current concept declaration syntax does not conform to other syntax elements in the language and the write-how-it-can-be-used style seems rather alien.

Examples

Current syntax:

type CanMoveWithTick = concept x
  x.move(0.0)

@PMunch's initial question to this syntax:

Is there a nicer way to specify that move takes a float?

Yes, there is:

type CanMoveWithTick = concept x
  x.move(float)

but according to @Araq this is a special rule for concept matching.

Alternate proposals

@Araq: ref. (alternately also without the leading proc in front of move)

type CanMoveWithTick = concept x
  proc move(self; ticks: float)

@couven92:

type CanMoveWithTick[T] = concept
  move: proc(m: T, ticks: float)

Features of current syntax

Generally, the discussion aims for finding a syntax that is most like the existing Nim syntax while considering the features, the current syntax has:

  • In the current syntax, expression like x.len can be matched by a proc, a field, or a template with a matching signature, in the matching case x.len simply needs to be valid
  • Any statically resolvable boolean expression can be put into the body of a concept

Questions

  1. How do we integrate the statically resolvable boolean expressions into the alternative proposals shown above? Is it reasonable to keep the current syntax for that even though it is slightly dissimilar to Nim syntax in related AST expressions (e.g. object declarations).
  2. Can all statically resolvable boolean expressions be replaced by field and proc signatures as suggested by @Araq and @couven92?
  3. Is it wise to be able to match x.something to both a field inside the matching type as well as against a proc taking the matching type as its first argument?
  4. How do I explicitly require that something MUST be a proc? How do I require it to be a field?
  5. How do I require matching fields/procs to fulfill pragmas?
  6. Is the syntax compatible with 'vref/vptr' @Varriount

This discussion started on IRC between @Varriount, @Araq, @PMunch and @couven92 and on @Araq's suggestion I am now summarizing the discussion here, so that we get a better overview over the different opinions and to decide whether the concept syntax should be changed or not. I am also tagging @zah as I understand he is the author of the current concept syntax.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions