Skip to content

Commit b223c02

Browse files
committed
patch holes in call syntax
1 parent 1ff8629 commit b223c02

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

src/subs.jl

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,12 @@ subs(ex::T, d::Pair...) where {T <: SymbolicType} = subs(ex, [(p.first, p.second
3838
## Allow an expression to be called, as with ex(2). When there is more than one symbol, one can rely on order of `free_symbols` or
3939
## be explicit by passing in pairs : `ex(x=>1, y=>2)` or a dict `ex(Dict(x=>1, y=>2))`.
4040
function (ex::Basic)(args...)
41-
xs = free_symbols(ex)
42-
subs(ex, collect(zip(xs, args))...)
41+
xs = free_symbols(ex)
42+
isempty(xs) && return ex
43+
subs(ex, collect(zip(xs, args))...)
4344
end
4445
(ex::Basic)(x::AbstractDict) = subs(ex, x)
45-
(ex::Basic)(x::Pair...) = subs(ex, x...)
46+
(ex::Basic)(x::Pair, xs::Pair...) = subs(ex, x, xs...)
4647

4748

4849
## Lambdify

test/runtests.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,14 @@ x,y,z = symbols("x y z")
196196
@test Set(free_symbols(x*y)) == Set([x,y])
197197
@test Set(free_symbols(x*y^z)) != Set([x,y])
198198

199+
# call without specifying variables
200+
@vars x y
201+
z = x(2)
202+
@test x(2) == 2
203+
@test (x*y^2)(1,2) == subs(x*y^2, x=>1, y=>2) == (x*y^2)(x=>1, y=>2)
204+
@test z() == 2
205+
@test z(1) == 2
206+
199207
## check that callable symengine expressions can be used as functions for duck-typed functions
200208
@vars x
201209
function simple_newton(f, fp, x0)

0 commit comments

Comments
 (0)