From 56e04cb8e5300659b50505c152ad9bc5a802bb9b Mon Sep 17 00:00:00 2001 From: Jeff Bezanson Date: Sat, 10 May 2014 15:45:59 -0400 Subject: [PATCH] =?UTF-8?q?parse=20sqrt=20symbol=20(=E2=88=9A)=20as=20a=20?= =?UTF-8?q?unary=20operator?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- NEWS.md | 1 + base/math.jl | 3 +-- base/operators.jl | 5 +++-- base/sysimg.jl | 1 + src/julia-parser.scm | 4 ++-- 5 files changed, 8 insertions(+), 6 deletions(-) diff --git a/NEWS.md b/NEWS.md index 1e53413140d3b..b9a4e1bdb0a67 100644 --- a/NEWS.md +++ b/NEWS.md @@ -42,6 +42,7 @@ New language features | == | ≥ (>=) ≤ (<=) ≡ (===) ≠ (!=) ≢ (!==) .≥ (.>=) .≤ (.<=) .!= (.≠) ∈ (`in`) ∉ (`(x,y)->!in(x, y)`) ∋ (`(x,y)->in(y, x)`) ∌ (`(x,y)->!in(y, x)`) ⊆ (`issubset`) ⊈ (`(x,y)->!issubset(x, y)`) ⊊ (`(x,y)->x⊆y && x!=y`) ⊂ ⊄ | | + | ⊕ ⊖ ⊞ ⊟ ∪ (`union`) ∨ ⊔ | | * | ÷ (`div`) ⋅ (`dot`) ∘ × (`cross`) ∩ (`intersect`) ∧ ⊓ ⊗ ⊘ ⊙ ⊚ ⊛ ⊠ ⊡ | + | unary | √ | Library improvements -------------------- diff --git a/base/math.jl b/base/math.jl index 9ad78fb5c3541..1347ff0d50e84 100644 --- a/base/math.jl +++ b/base/math.jl @@ -16,7 +16,7 @@ export sin, cos, tan, sinh, cosh, tanh, asin, acos, atan, besselj0, besselj1, besselj, bessely0, bessely1, bessely, hankelh1, hankelh2, besseli, besselk, besselh, beta, lbeta, eta, zeta, polygamma, invdigamma, digamma, trigamma, - erfinv, erfcinv, √ + erfinv, erfcinv import Base: log, exp, sin, cos, tan, sinh, cosh, tanh, asin, acos, atan, asinh, acosh, atanh, sqrt, log2, log10, @@ -284,7 +284,6 @@ sqrt(x::Float64) = box(Float64,sqrt_llvm(unbox(Float64,x))) sqrt(x::Float32) = box(Float32,sqrt_llvm(unbox(Float32,x))) sqrt(x::Real) = sqrt(float(x)) @vectorize_1arg Number sqrt -const √=sqrt for f in (:ceil, :trunc, :significand) # :rint, :nearbyint @eval begin diff --git a/base/operators.jl b/base/operators.jl index f73fcaa423ef2..d61a8b5d84a41 100644 --- a/base/operators.jl +++ b/base/operators.jl @@ -363,7 +363,7 @@ function ifelse(c::AbstractArray{Bool}, x, y::AbstractArray) end # some operators not defined yet -global //, .>>, .<<, >:, <|, |>, hcat, hvcat, ⋅, ×, ∈, ∉, ∋, ∌, ⊆, ⊈, ⊊, ∩, ∪ +global //, .>>, .<<, >:, <|, |>, hcat, hvcat, ⋅, ×, ∈, ∉, ∋, ∌, ⊆, ⊈, ⊊, ∩, ∪, √ module Operators @@ -428,6 +428,7 @@ export ⊊, ∩, ∪, + √, colon, hcat, vcat, @@ -441,6 +442,6 @@ import Base: !, !=, $, %, .%, &, *, +, -, .!=, .+, .-, .*, ./, .<, .<=, .==, .>, .>=, .\, .^, /, //, <, <:, <<, <=, ==, >, >=, >>, .>>, .<<, >>>, <|, |>, \, ^, |, ~, !==, >:, colon, hcat, vcat, hvcat, getindex, setindex!, transpose, ctranspose, - ≥, ≤, ≠, .≥, .≤, .≠, ÷, ⋅, ×, ∈, ∉, ∋, ∌, ⊆, ⊈, ⊊, ∩, ∪ + ≥, ≤, ≠, .≥, .≤, .≠, ÷, ⋅, ×, ∈, ∉, ∋, ∌, ⊆, ⊈, ⊊, ∩, ∪, √ end diff --git a/base/sysimg.jl b/base/sysimg.jl index e942a0d8002ae..0d1cf2921708d 100644 --- a/base/sysimg.jl +++ b/base/sysimg.jl @@ -117,6 +117,7 @@ include("methodshow.jl") include("floatfuncs.jl") include("math.jl") importall .Math +const (√)=sqrt include("float16.jl") # multidimensional arrays diff --git a/src/julia-parser.scm b/src/julia-parser.scm index c599c131b4bbe..67a145217b373 100644 --- a/src/julia-parser.scm +++ b/src/julia-parser.scm @@ -75,7 +75,7 @@ (define (kwarg? e) (and (pair? e) (eq? (car e) 'kw))) -(define unary-ops '(+ - ! ~ |<:| |>:|)) +(define unary-ops '(+ - ! ~ |<:| |>:| √)) ; operators that are both unary and binary (define unary-and-binary-ops '(+ - $ & ~)) @@ -98,7 +98,7 @@ (define ctrans-op (string->symbol "'")) (define vararg-op (string->symbol "...")) -(define operators (list* '~ '! '-> ctrans-op trans-op vararg-op +(define operators (list* '~ '! '-> '√ ctrans-op trans-op vararg-op (delete-duplicates (apply append (vector->list ops-by-prec)))))