sorawee
2019-6-30 09:04:20

Curious why begin0 is a core form rather than a macro


sorawee
2019-6-30 09:06:58

I guess it’s difficult to do that efficiently due to multiple values?


soegaard2
2019-6-30 09:36:14

How would an expansion of (begin0 e0 e ...) look like?


lexi.lambda
2019-6-30 09:48:43

(call-with-values (lambda () e0) (lambda vs e ... (apply values vs))) should be functionally equivalent.


soegaard2
2019-6-30 09:53:21

Yeah, much simpler to keep begin0 - apply is expensive.


soegaard2
2019-6-30 09:53:52

Is it also equivalent in the case (begin0 e0) where e0 is a tail call?


soegaard2
2019-6-30 09:54:34

Well, doesn’t matter - one can use the long form only if there is more than one subexpression.


lexi.lambda
2019-6-30 09:58:16

Right, yes. I imagine begin0 is useful for the compiler, and there’s little reason not to expose it directly.


soegaard2
2019-6-30 10:09:39

It is pretty simple to handle for a byte code interpreter.


lexi.lambda
2019-6-30 10:11:14

I would admittedly hope that the bigger expression using call-with-values would be compiled exactly the same way as begin0, but I don’t know if the Racket optimizer actually does that optimization, especially since I doubt the call-with-values code appears very often in the wild.


soegaard2
2019-6-30 10:12:19

Even trickier to find out now, that Chez is the backend.


lexi.lambda
2019-6-30 10:13:08

I found there’s a way to see the optimizer output—you have to set an environment variable and compile a module. I think it’s PLT_SHOW_CP0 or something like that.


soegaard2
2019-6-30 10:13:29

Nice tip.


lexi.lambda
2019-6-30 10:14:10

Ah, it’s PLT_LINKLET_SHOW_CP0.



soegaard2
2019-6-30 10:17:55
(define-syntax begin0
  (syntax-rules ()
    ((_ x y ...) (let ((t x)) y ... t))))

soegaard2
2019-6-30 10:19:15

That’s not equivalent to a Racket begin0.


lexi.lambda
2019-6-30 10:23:09

No, in fact it looks like begin0 for Racket-on-Chez is defined here, and it does, in fact, expand into call-with-values: https://github.com/racket/racket/blob/020c75792ca4649ed0b6994aa095cb3d02793be8/racket/src/cs/rumble/begin0.ss


soegaard2
2019-6-30 10:27:20

I suspect the ChezScheme turns the single value case into something reasonable.


soegaard2
2019-6-30 17:27:12

?!?


mflatt
2019-6-30 17:39:27

I haven’t seen that and don’t know why it would happen, so I recommend “Don’t Allow”!


soegaard2
2019-6-30 17:41:00

The context: I picked “Open…” then got a file window. Clicked through the correct folder. Then entered a search term in the text field used to filter results.


soegaard2
2019-6-30 17:45:38

Digging a little. It seems macOS will display these dialogs when access to certain folders is attempted. Similar situation here: https://github.com/atom/atom/issues/17687 So I guess, it’s just the way things work.


soegaard2
2019-6-30 17:46:02

A bit confusing though.


samth
2019-6-30 18:15:57

From reading that issue, the only way we can avoid that is by adding some paths to be excluded from whatever directory traversal it was doing


samdphillips
2019-6-30 23:57:36

sorawee
2019-7-1 03:55:49

@mflatt I played with RacketCS and found that function that returns multiple values won’t work well with cp0 when callsite is at top level. Is there a way to improve this?

For instance:

(define-values (foo bar) (values 1 2))
(+ foo 10)

cp0 could propagate foo, reducing (+ foo 10) to 11 at compile time.

However, if we have

(define (call) (values 1 2))
(define-values (foo bar) (call))
(+ foo 10)

then cp0 is stuck at

  (letrec ([call (lambda () (#2%values 1 2))])
    (variable-set!/define call121 call 'consistent)
    (call-with-module-prompt (lambda () (#2%values 1 2))
      '(foo bar) '(constant constant) foo120 bar119)
    (let ([foo (#3%$object-ref 'scheme-object foo120 9)])
      (call-with-module-prompt
        (letrec ([procz122 (lambda () (#2%+ foo 10))])
          (lambda () (#%call-with-values procz122 print-values118))))
      (#2%void)))

(presumably due to call-with-module-prompt?)