zatonovo/lambda.r

Doesn't accept `call` as a function type parameter

Closed this issue · 3 comments

EvalCall(quote_call) %::% call : numeric
EvalCall(quote_call) %as% {
    eval(quote_call)
}

EvalCall_Native = function(quote_call){ eval(quote_call) }
> EvalCall(quote({2+2}))
Error in UseFunction(type.fn, type.name, ...) : 
  No valid function for 'EvalCall({)'

For native:

> EvalCall_Native(quote({2+2}))
[1] 4

It looks like the class returned by your quoted expression is not call:

> class(quote({2+2}))
[1] "{"

That said, supplying { in the type constraint will surely fail, since it's a special character.

This appears to work:

EvalCall(quote_call) %::% call : numeric
EvalCall(quote_call) %as% {
    eval(quote_call)
}

> EvalCall(quote(2+2))
[1] 4
attr(,"class")
[1] "EvalCall" "numeric"

I'm not sure what your use case is for this, but you can always pass a closure instead of the quoted expression sequence and specify Function as the type.

{ enables you to eval such expressions.

> EvalCall_Native(quote({
            a <- 5
            b <- 7
            a + b
        }))
[1] 12

?Paren
Which is function in fact.

> class(.Primitive("{"))
[1] "function"

I evaluate this complex expressions within data.table environment with some Non Standard Evaluation user-defined operator.

My point is that { and ( have special meaning in the parser, despite being functions. So you can't use those literals in a type constraint. Despite quote({2+2}) being a call, the class doesn't contain "call".

> x <- quote({3+4})
> is.call(x)
[1] TRUE
> class(x)
[1] "{"

So to work within the current behavior of lambda.r, you need to associate the quoted expression with a call.

> az.call <- function(x) { class(x) <- c('call',class(x)); x }
> EvalCall(az.call(quote({3+4})))
[1] 7
attr(,"class")
[1] "EvalCall" "numeric"