class Campa::Lisp::Defun

Attributes

label_fn[R]
printer[R]

Public Class Methods

new() click to toggle source
# File lib/campa/lisp/defun.rb, line 4
def initialize
  @printer = Printer.new
  @label_fn = Label.new
end

Public Instance Methods

call(label, params, *body, env:) click to toggle source
# File lib/campa/lisp/defun.rb, line 13
def call(label, params, *body, env:)
  raise label_error(label) if !label.is_a?(Symbol)

  label_fn.call(
    label,
    invoke_lambda(params, body),
    env: env
  )
end
macro?() click to toggle source
# File lib/campa/lisp/defun.rb, line 9
def macro?
  true
end

Private Instance Methods

invoke_lambda(params, body) click to toggle source
# File lib/campa/lisp/defun.rb, line 31
def invoke_lambda(params, body)
  List.new(SYMBOL_LAMBDA, params, *body)
end
label_error(given) click to toggle source
# File lib/campa/lisp/defun.rb, line 27
def label_error(given)
  Error::IllegalArgument.new(printer.call(given), "symbol")
end