# ERROR: LoadError: type DataType has no field Let

**URL:** https://discourse.julialang.org/t/error-loaderror-type-datatype-has-no-field-let/116116
**Category:** New to Julia
**Tags:** question
**Created:** [June 23, 2024, 3:40pm UTC](https://discourse.julialang.org/t/error-loaderror-type-datatype-has-no-field-let/116116 "2024-06-23T15:40:27Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![JapaCZECH](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/japaczech/32/50665_2.png) [@JapaCZECH](https://discourse.julialang.org/u/JapaCZECH)
#### Post date: [June 23, 2024, 3:40pm UTC](https://discourse.julialang.org/t/error-loaderror-type-datatype-has-no-field-let/116116/1 "2024-06-23T15:40:27Z")

</div>

Hello! I have a problem which I don’t know how to solve. I am making a lexer for my programming language and there is this problem: `ERROR: LoadError: type DataType has no field Let Stacktrace: [1] getproperty(x::Type, f::Symbol) @ Base .\Base.jl:32 [2] top-level scope @ C:\Users\jakub\Documents\julia\myopl\lexer.jl:15 [3] include(fname::String) @ Base.MainInclude .\client.jl:489 [4] top-level scope @ C:\Users\jakub\Documents\julia\myopl\main.jl:1 in expression starting at C:\Users\jakub\Documents\julia\myopl\lexer.jl:1 in expression starting at C:\Users\jakub\Documents\julia\myopl\main.jl:1`  
Here is the full code:

```module

export Token, TokenType, tokenize

@enum TokenType begin
    Number = 1
    Identifier = 2
    Equals = 3
    OpenParen = 4
    CloseParen = 5
    BinaryOperator = 6
    Let = 7
end

KEYWORDS = Dict(
    "let" => TokenType.Let
)

struct Token 
    value::String
    type::TokenType
end

function token(value, type)
    return Token(value, type)
end

function isalpha(src)
    return uppercase(src) != lowercase(src)
end

function isint(str)
    c = Int(codepoint(str[1]))
    bounds = [Int('0'), Int('9')]
    return c >= bounds[1] && c <= bounds[2]
end

function isskippable(str)
    return str == " " || str == "\n" || str == "\t"
end

function tokenize(sourceCode) 
    tokens = Token[]
    src = split(sourceCode, "")

    while length(src) > 0
        if first(src) == "("
            push!(tokens, token("(", TokenType.OpenParen))
            popfirst!(src)
        elseif first(src) == ")"
            push!(tokens, token(")", TokenType.CloseParen))
            popfirst!(src)
        elseif first(src) == '+' || first(src) == '-' || first(src) == '/' || first(src) == '*'
            push!(tokens, token(first(src), TokenType.BinaryOperator))
            popfirst!(src)
        elseif first(src) == '='
            push!(tokens, token("=", TokenType.Equals))
            popfirst!(src)
        else
            if isint(first(src))
                num = ""
                while length(src) > 0 && isint(first(src))
                    num *= popfirst!(src)
                end

                push!(tokens, token(num, TokenType.Number))
            elseif isalpha(first(src))
                ident = ""
                while length(src) > 0 && (isalpha(first(src)) || isint(first(src)))
                    ident *= popfirst!(src)
                end

                if haskey(KEYWORDS, ident)
                    reserved = KEYWORDS[ident]
                    push!(tokens, token(ident, reserved))
                else
                    push!(tokens, token(ident, TokenType.Identifier))
                end
            elseif isskippable(first(src))
                popfirst!(src)
            else
                println("Unrecognized character found in source: ", first(src))
                exit(1)
            end
        end
    end

    return tokens
end

end

```

Thank you.

---

<div class="post-metadata">

### Author: ![oheil](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oheil/32/220745_2.png) [@oheil](https://discourse.julialang.org/u/oheil)
#### Post date: [June 23, 2024, 3:56pm UTC](https://discourse.julialang.org/t/error-loaderror-type-datatype-has-no-field-let/116116/2 "2024-06-23T15:56:45Z")

</div>

`TokenType.Let` is not the correct syntax.

You refer to the enum member values just with their names:

```julia
KEYWORDS = Dict(
    "let" => Let
)

```

The style guide here is that the member values are lower case, `let` in this case. But `let` is a reserved key word, so you couldn’t use this in lowercase.

See [Essentials · The Julia Language](https://docs.julialang.org/en/v1.10/base/base/#Base.Enums.@enum) for some documentation.

---

<div class="post-metadata">

### Author: ![ericphanson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ericphanson/32/215186_2.png) [@ericphanson](https://discourse.julialang.org/u/ericphanson)
#### Post date: [June 23, 2024, 6:55pm UTC](https://discourse.julialang.org/t/error-loaderror-type-datatype-has-no-field-let/116116/3 "2024-06-23T18:55:21Z")

</div>

You can also use [EnumX.jl](https://github.com/fredrikekre/EnumX.jl) for scoped enums, which would allow `TokenType.Let` to work
