Array model doesn't carry type #121

Open
stretchyboy opened this Issue Jan 31, 2012 · 4 comments

Comments

Projects
None yet
3 participants
@stretchyboy
Member

stretchyboy commented Jan 31, 2012

Can build an array of Number but the items aren't numbers, and I don't think we want casting

@dethe

This comment has been minimized.

Show comment
Hide comment
@dethe

dethe Mar 9, 2013

Member

In Javascript, arrays don't have types. For other languages the quickest way to get this would probably be to have multiple typed array blocks, so instead of an Array, you would use a NumberArray block. Does that make sense?

Member

dethe commented Mar 9, 2013

In Javascript, arrays don't have types. For other languages the quickest way to get this would probably be to have multiple typed array blocks, so instead of an Array, you would use a NumberArray block. Does that make sense?

@TechplexEngineer

This comment has been minimized.

Show comment
Hide comment
@TechplexEngineer

TechplexEngineer Mar 10, 2013

Member

I think so.

One other approach would be to have a block "array of [list]" where list is
a list of types that the array can be of. Rather than having a bunch of
"...Array" blocks cluttering the menu.

I wonder if there is a way that modules can describe how the language they
wrap stores its data. Like the different datatypes and what can implicitly
cast and what needs an explicit cast. This would be really helpful for
logic relating to placing a number type block into a string type socket. In
python that would work, as the interpreter would automatically cast.
However the opposite would most likely require an explicit cast to get
proper results.

On Sat, Mar 9, 2013 at 4:27 PM, Dethe Elza notifications@github.com wrote:

In Javascript, arrays don't have types. For other languages the quickest
way to get this would probably be to have multiple typed array blocks, so
instead of an Array, you would use a NumberArray block. Does that make
sense?


Reply to this email directly or view it on GitHubhttps://github.com/waterbearlang/waterbear/issues/121#issuecomment-14671053
.

Member

TechplexEngineer commented Mar 10, 2013

I think so.

One other approach would be to have a block "array of [list]" where list is
a list of types that the array can be of. Rather than having a bunch of
"...Array" blocks cluttering the menu.

I wonder if there is a way that modules can describe how the language they
wrap stores its data. Like the different datatypes and what can implicitly
cast and what needs an explicit cast. This would be really helpful for
logic relating to placing a number type block into a string type socket. In
python that would work, as the interpreter would automatically cast.
However the opposite would most likely require an explicit cast to get
proper results.

On Sat, Mar 9, 2013 at 4:27 PM, Dethe Elza notifications@github.com wrote:

In Javascript, arrays don't have types. For other languages the quickest
way to get this would probably be to have multiple typed array blocks, so
instead of an Array, you would use a NumberArray block. Does that make
sense?


Reply to this email directly or view it on GitHubhttps://github.com/waterbearlang/waterbear/issues/121#issuecomment-14671053
.

@dethe

This comment has been minimized.

Show comment
Hide comment
@dethe

dethe Jul 3, 2013

Member

We should hash out exactly what you need here so it can go into the Beta + IDE work.

Member

dethe commented Jul 3, 2013

We should hash out exactly what you need here so it can go into the Beta + IDE work.

@TechplexEngineer

This comment has been minimized.

Show comment
Hide comment
@TechplexEngineer

TechplexEngineer Jul 3, 2013

Member

I did some work back when I was heavily working on easyj. I came up with a json structure that I could use to define what types are and valid values for them (via a regex) the other types that can be implicitly cast.

{
    "int": {
        "hrName":"int",
        "targets":"int, double, float",
        "accepts":"[-|0-9]",  //0-9
        "errMsg":"Int fields only accept numbers [0-9] and a negative sign [-]"
    },
    "double": {
        "hrName":"decimal",
        "targets":"decimal",
        "accepts":"[-|\.0-9]", //0-9 and dot (probs need better regex)
        "errMsg":"Decimal fields only accept numbers [0-9] and a dot [.]"
    },
   "float": {
        "hrName":"decimal",
        "targets":"float, double",
        "accepts":"[+-]?(?=[.]?[0-9])[0-9]*(?:[.][0-9]*)?(?:[Ee][+-]?[0-9]+)?", //from: http://stackoverflow.com/a/9854031
        "errMsg":"float fields only accept numbers [0-9] and a dot [.] signs [+-] and exponents (ex:4.8e5)"
    },
    "string": {
        "hrName":"string",
        "targets":"string",
        "accepts":".*", //special case?
        "errMsg":"String field accepts anything but quotes [\"]"
    },
    "bool": {
        "hrName":"bool",
        "targets":"bool"
    },
//varname is a special case
    "varname": {
        "hrName":"varname",
        "targets":"varname",
        "accepts":"[_a-zA-Z]",  //Match a string which contains any letter a-z or underscore
        "errMsg": "Variable Names can only contain letters [a-z] capital [A-Z] and underscores [_]"
    }
}

Let me try to explain whats here
the keys (int, double. float, string, bool... are the types)
hrName is the human readable name
targets is anywhere a block of the key type can be inserted
accepts is a regex that can be used to validate user input
errMsg is used in a popup telling the user what they typed is invalid

This doesn't account for types that can be casted explicitly, (I had only implemented it for implicit casting)

This pull request hasn't aged that well but it has the majority of the work I did in this area in it:
40aa624

@dethe mentions a json structure similar to the above here: #94

Member

TechplexEngineer commented Jul 3, 2013

I did some work back when I was heavily working on easyj. I came up with a json structure that I could use to define what types are and valid values for them (via a regex) the other types that can be implicitly cast.

{
    "int": {
        "hrName":"int",
        "targets":"int, double, float",
        "accepts":"[-|0-9]",  //0-9
        "errMsg":"Int fields only accept numbers [0-9] and a negative sign [-]"
    },
    "double": {
        "hrName":"decimal",
        "targets":"decimal",
        "accepts":"[-|\.0-9]", //0-9 and dot (probs need better regex)
        "errMsg":"Decimal fields only accept numbers [0-9] and a dot [.]"
    },
   "float": {
        "hrName":"decimal",
        "targets":"float, double",
        "accepts":"[+-]?(?=[.]?[0-9])[0-9]*(?:[.][0-9]*)?(?:[Ee][+-]?[0-9]+)?", //from: http://stackoverflow.com/a/9854031
        "errMsg":"float fields only accept numbers [0-9] and a dot [.] signs [+-] and exponents (ex:4.8e5)"
    },
    "string": {
        "hrName":"string",
        "targets":"string",
        "accepts":".*", //special case?
        "errMsg":"String field accepts anything but quotes [\"]"
    },
    "bool": {
        "hrName":"bool",
        "targets":"bool"
    },
//varname is a special case
    "varname": {
        "hrName":"varname",
        "targets":"varname",
        "accepts":"[_a-zA-Z]",  //Match a string which contains any letter a-z or underscore
        "errMsg": "Variable Names can only contain letters [a-z] capital [A-Z] and underscores [_]"
    }
}

Let me try to explain whats here
the keys (int, double. float, string, bool... are the types)
hrName is the human readable name
targets is anywhere a block of the key type can be inserted
accepts is a regex that can be used to validate user input
errMsg is used in a popup telling the user what they typed is invalid

This doesn't account for types that can be casted explicitly, (I had only implemented it for implicit casting)

This pull request hasn't aged that well but it has the majority of the work I did in this area in it:
40aa624

@dethe mentions a json structure similar to the above here: #94

@dethe dethe removed this from the Beta + IDE milestone Apr 25, 2014

@dethe dethe modified the milestone: Custom Elements Jun 23, 2015

@dethe dethe modified the milestones: Custom Elements, Drag and Drop Jul 2, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment