# Function definition inside let-block impacting performance?

**URL:** <https://discourse.julialang.org/t/function-definition-inside-let-block-impacting-performance/110007>\
**Category:** Performance\
**Tags:** question\
**Created:** [February 9, 2024, 8:06pm UTC](https://discourse.julialang.org/t/function-definition-inside-let-block-impacting-performance/110007 "2024-02-09T20:06:28Z")\
**Posts on this page:** 1\
**Showing post:** 39

<div class="post-metadata">

**Author:** ![uniment](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/uniment/32/24532_2.png) [@uniment](https://discourse.julialang.org/u/uniment)\
**Post date:** [February 13, 2024, 12:31pm UTC](https://discourse.julialang.org/t/function-definition-inside-let-block-impacting-performance/110007/39 "2024-02-13T12:31:19Z")

</div>

> [@Benny](#):
>
> Lua tables don’t seem to be semantically [ordered](https://stackoverflow.com/questions/41417453/lua-print-table-keys-in-order-of-insertion), and tables can be indexed with [anything](https://www.lua.org/pil/2.5.html)

Understood. However, ordered dictionaries would have the same relationship to vectors as namedtuples have to tuples, which is good for making the user interface for this syntax sugar consistent. Also, ordered dictionaries seem to be generally a better fit for Julia’s target audience (basically the same as Python’s target audience).

One suggestion that [has been made](https://discourse.julialang.org/t/stringindex-idea-julia-2-0/107185/63) is that ordered dictionaries can be indexed in order by a special ordinal index type (e.g. `my_dict[6th]`); any other non-token index will be treated as a hashkey.

> [@jar1](#):
>
> github somewhere there’s a thread

I’m not finding it, so I’ll spitball some thoughts here:

To initialize:

```julia
[;] # OrderedDict{Any,Any}()
[a=1, b=2] # OrderedDict{Symbol, Int}([:a,:b], [1,2])
[; a=1, b=2] # alternative syntax
['a'=1, 'b'=2] # OrderedDict{Char,Int}(['a','b'], [1,2])
[a=1, 'b'=2] # OrderedDict{Any,Int}([:a, 'b'], [1,2])
# note that the l.h.s. can be any literal

# multi-dimensional: (???)
[
    (1,1) = 1 (1,2) = 0
    (2,1) = 0 (2,2) = 2
]

# generator:
[; [Symbol("key",i)] = i^2 for i=1:5]

# non-literal l.h.s.:
[[x]=1, [y]=2] # access variables x and y as keys
[[:a]=1, [:b]=2] # another alternative for [a=1, b=2]

```

To access:

```julia
d = [a=1, 0=2] # OrderedDict{Any,Int}([:a,0], [1,2]) 
d[:a] == d.a == d[1th] == 1

dt = Tokenizer(d) # generates tokens from keys
d[dt(:a)] == d.a

d[0] == d[dt(0)] == d[2th] == 2

let t = dt(some_key, 0) # 2nd argument sets default value if key not found?
    d[t] += 1
end

d.:0 = 3 / d.:0

```

(since `getproperty` and `setproperty!` on dictionaries is otherwise pretty useless, I see no reason not to act like a `PropDict`. This also builds consistency with `NamedTuple`.)

---

_[View the full topic](https://discourse.julialang.org/t/function-definition-inside-let-block-impacting-performance/110007)._
