Jump to content

Wikifunctions:Type proposals/Sign

From Wikifunctions

Done: Sign (Z16659)

Summary

The sign type represents the sign of a signed integer number, i.e. has the three values positive, neutral, and negative.

It may be useful in other contexts too.

Uses

  • Why should this exist?

So that we can represent signed integer numbers.

  • What kinds of functions would be created using this?

There are very few functions expected that are using just this type., most importantly "same sign" and "switch sign".

  • What standard concepts, if any, does this align with?

The sign in numbers.

Structure

Signs are represented as an enumeration with three values. Like all enumeration types, the Sign consists of a single key. The key is an identity key.

Values

There are three values.

  1. Positive
  2. Neutral
  3. Negative

Example values

Value

{
  "type": "Sign",
  "value": "Positive"
}
{
  "Z1K1": "Znnnnn",
  "ZnnnnnK1": "Zmmmmm"
}

Validator

The validator ensures that:

  • the identity key points directly to a value of Sign

Identity

Two signs are the same if their identity is the same ZID.

Converting to code

Python

We represent them as numbers: 1 for positive, 0 for neutral, and -1 for negative.

JavaScript

We represent them as numbers: 1 for positive, 0 for neutral, and -1 for negative.

Renderer

As for all enumerations, the renderer displays the label of the value object.

Parsers

As with all enumerations, there is no parser, but a selector based on pre-defined values.

Alternatives

Instead of having a Sign type, we could just ignore the neutral option, and just use a Boolean. It seems that using Sign has cleaner semantics, though.

We could also have just two values, positive and negative. But this always leads to confusion for zero.

Comments