Typed and Untyped Comprehensions


#1

Hi everyone,

What are typed and untyped comprehensions and what are syntax forms of those?

Thanks in advance.


#2

Does the info here: https://docs.julialang.org/en/stable/manual/arrays/#Comprehensions-1 help?


#3

Can there be dictionary based comprehensions?
is so can you give me an example?

Thanks


#4
julia> ex = :([x^2 for x in 0:9 if x>5])
:([x ^ 2 for x = 0:9 if x > 5])

julia> ex.head
:comprehension

julia> ex.args
1-element Array{Any,1}:
 :((x ^ 2 for x = 0:9 if x > 5))

julia> ex.args[1]
:((x ^ 2 for x = 0:9 if x > 5))

julia> ex.args[1].head
:generator

julia> ex = :(Int[x^2 for x in 0:9 if x>5])
:(Int[x ^ 2 for x = 0:9 if x > 5])

julia> ex.head
:typed_comprehension

I see :compherension and :typed_compherension can there be any more head symbols related to comprehensions?

How can i learn that?
Thanks


#5

Might be some useful stuff here: https://docs.julialang.org/en/latest/devdocs/ast/#Bracketed-forms-1


#6

Is generator missing from that table, or does it belong elsewhere?