
I have a program that reads text (a special language) to racket asts which I then eval and print to the user like so (displayln (eval (read-special-form)))
. The result of (read-special-form)
looks like '(+ 1 2 (* 3 4))
. I want the (read-special-form)
to be able to emit forms with special symbol x
like (+ 1 x)
which will be plotted. The way I do that is (plot (eval
(lambda (x) ,(read-special-form))) . Is there a variant of
eval` that will also optimize the lambda it is given?

What do you mean by “optimize”?

All expressions that are evaluated go through the optimizer.

So the lambda is optimized like any other racket code? It’s not just interpreted?

(It is important that the function passed to plot
is performant)

Yes, it’s optimized like other code, although using eval
and the top-level generally can inhibit some optimizations

Hmm, does that also mean that eval
can be used for jit compilation to machine code?

All compilation in Racket is effectively jit compilation.

@laurent.orseau unfortunately, the recent change to text-table broke the sawzall package. You can try this example: https://github.com/ralsei/sawzall/issues/4

I’ll take a look, thanks for the report!

The problem, I think, is that the contract for table->string/c
passes (-> any/c string?)
to pattern-list-of
but that expects a predicate, not a contract.

Here’s an example using just text-table
. I think any use of #:->string
will have the problem. #lang racket
(require text-table)
(table->string #:->string (λ _ "") 1)

Oh, that’s weird, I am using that argument in other places :thinking_face:

but I see, I could pass (procedure-arity-includes/c 1)
I think

Another example that actually should work: #lang racket
(require text-table)
(table->string #:->string (λ _ "") '((a)))

I assumed wrongly that (any/c . -> . string?)
would be a predicate, like other contracts.

(on second thought, of course it can’t be a predicate)

Only first-order contracts are predicates

Should be fixed now.

Thank you!

(I think I know what happened: I used this argument in other projects before strengthening the contract and haven’t looked at the other projects since)

@raphael has joined the channel

whoops