christos.perivolaropo
2022-3-11 15:24:21

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 ofeval` that will also optimize the lambda it is given?


samth
2022-3-11 15:26:04

What do you mean by “optimize”?


samth
2022-3-11 15:26:14

All expressions that are evaluated go through the optimizer.


christos.perivolaropo
2022-3-11 15:26:53

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


christos.perivolaropo
2022-3-11 15:27:23

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


samth
2022-3-11 15:31:12

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


christos.perivolaropo
2022-3-11 15:31:26

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


samth
2022-3-11 15:33:18

All compilation in Racket is effectively jit compilation.


samth
2022-3-11 16:21:14

@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


laurent.orseau
2022-3-11 16:23:02

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


samth
2022-3-11 16:25:07

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.


samth
2022-3-11 16:26:46

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)


laurent.orseau
2022-3-11 16:29:12

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


laurent.orseau
2022-3-11 16:29:43

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


samth
2022-3-11 16:31:47

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


laurent.orseau
2022-3-11 16:32:41

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


laurent.orseau
2022-3-11 16:33:08

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


samth
2022-3-11 16:33:11

Only first-order contracts are predicates


laurent.orseau
2022-3-11 16:49:09

Should be fixed now.


samth
2022-3-11 16:49:31

Thank you!


laurent.orseau
2022-3-11 16:52:10

(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
2022-3-11 19:40:13

@raphael has joined the channel


hazel
2022-3-12 04:13:59

whoops