Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(Idea) Trick for converting Ruby blocks to SymEngine formulae #41

Open
zverok opened this issue May 24, 2016 · 0 comments
Open

(Idea) Trick for converting Ruby blocks to SymEngine formulae #41

zverok opened this issue May 24, 2016 · 0 comments

Comments

@zverok
Copy link
Collaborator

zverok commented May 24, 2016

OK, it is not the time for it currently, just an idea for future.

Usage:

puts SymEngine.formula {|x, y| x**2 + y**2}
# => x**2 + y**2

Naive implementation:

def SymEngine.formula &block
  block.parameters.empty? and fail(ArgumentError, "Block should list all expected symbols")
  block.parameters.map(&:first).uniq == [:opt] or fail(ArgumentError, "Only plain parameters are supported (no defaults, no *rest, no keyword args)")
  symbols = block.parameters.map(&:last).map(&SymEngine::Symbol.method(:new))
  block.call(*symbols)
end

There's almost no "dangerous" magics (with method_missing, instance_eval and stuff), and seems pretty useful?..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant