# Inconsistencies in some methods and more

#1

Dear All,

I didn’t want to start a new issue in GitHub without checking first what is your opinion on this regard. I found the issue #25098 by change, and I started trying to define a function named “·”. I found various things I try to explain as clear as I can.

I did my checkings in v"0.6.2", since at the time of checking this, writing a middot would crash the Julia REPL (see issue #25098)

First of all, it is already defined in Base a function called ·.

julia> (⋅)(x, y) = x * y
ERROR: error in method definition: function Base.⋅ must be explicitly imported to be extended


which is normal. Then,

julia> methods(·)
ERROR: syntax: invalid character "·"
julia> methods(Base.·)
ERROR: syntax: invalid character "·"


I think things start to get confusing.

Hence, I checked other behaviours of methods, but this time I still use by accident the Base.foo naming to call some functions and I found that +, as probably other functions defined as operators (unary or binary), throw an error. I listed some of them,

julia> methods(Base.+)
ERROR: syntax: unexpected ")"
julia> methods(Base.!)
ERROR: syntax: missing comma or ) in argument list


A way to avoid this is to write the colon in front of the symbol, which works almost for all cases except the conlon itself

julia> methods(Base.:+)
# 182 methods for generic function "+":
···
julia> methods(Base.::)
ERROR: UndefVarError: :: not defined


Still I’m not able to add a method to Base.·.

Any suggestion for the title of this thread is welcome.

#2

I think your cdot is not the standard one. See:

julia> '·' # Your cdot
'·': Unicode U+00b7 (category Po: Punctuation, other)

julia> '⋅' # Correct cdot
'⋅': Unicode U+22c5 (category Sm: Symbol, math)


Try methods(\cdot<TAB>)<ENTER>

This gives for me

julia> methods(⋅)
# 11 methods for generic function "dot":
dot(x::BitArray{1}, y::BitArray{1}) in Base.LinAlg at linalg/bitarray.jl:5
dot(x::Number, y::Number) in Base.LinAlg at linalg/generic.jl:675
...


For the second question, you can use:

julia> methods(Colon)
# 2 methods for generic function "(::Type)":
Colon() in Base at essentials.jl:321
(::Type{T})(arg) where T in Base at sysimg.jl:77


#3

EDIT: I’m wrong, I was using U+22c5 as @kristoffer.carlsson says

Thanks @kristoffer.carlsson!

Why then it tells me that Base.· (where I used the very same dot U+00b7) must be explicitly imported?

julia> (⋅)(x, y) = x * y
ERROR: error in method definition: function Base.⋅ must be explicitly imported to be extended


This Error message made me try try it again and again. It should be changed to something like the standard error ERROR: syntax: invalid character "·".

Just a comment: Would it be worth to make them equivalent in Julia. I think the answer is yes.

#4

It doesn’t look like you are using U+00b7 (at least not in the message you just pasted).

#5

YOU ARE RIGHT!!

I meshed up both using copy/paste, since I was also writing for the issue #25098.

Thanks, I will update the issue telling which unicode character brakes the REPL.

#6

Perhaps we should add this to our custom Unicode normalization table? See:

#7

How do you type U+00b7? If it is easy to do by accident, we could definitely normalize it to U+22c5.

#8

It is as easy as typing SHIFT+3 in my keyboard.

I already fixed it in this PR https://github.com/JuliaLang/julia/pull/25157

It works for me, but probably it is not the most elegant way to do it.

Now working on an alternative, inspired by “WIP: custom Unicode normalization for Julia identifiers”

#9

Ah, I see — this is the “interpunct” character, and there are various keyboard shortcuts for it, e.g. option-shift-9 on macOS.