ben
2018-8-24 17:54:36

sometimes I’ll re-type the function name in the search box, because the search results give the providing module


samth
2018-8-24 18:01:27

@mflatt (or maybe @lexi.lambda) is there a way to print slideshow to produce widescreen slides?


samth
2018-8-24 18:05:18

everything I try produces 4:3 slides with my widescreen slides in the middle


lexi.lambda
2018-8-24 18:06:36

(I have no idea, sorry; I haven’t tried the widescreen feature at all yet)


plotnus
2018-8-24 19:16:54

Is there a way to execute code inside a syntax-parses cases Here is how I got to the point of wanting to do this. ;; first iteration (syntax-parse stx [(op e0 e1) (build-some-struct op e0 e1)] ;; second iteration - props to samth for helping me on this one [(op e0 e1) (quasi-syntax/loc stx (build-some-struct op e0 e1 (quote-syntax #,stx))] ;; third iteration [(op e0 e1) ;; build the struct like in the first iteration ;; add the stx that was a parameter in the second iteration to the struct ;; print the struct so I can make sure it is working & debugging ] How would I do the third iteration? Is it possible to do that inside a syntax-parse?


shu--hung
2018-8-24 19:31:20

You can do arbitrary computation in a macro. Is that what ‘execute’ mean? Also, it depends on what build-some-struct is (say a macro? a phase 1 function? a phase 0 function? etc)


shu--hung
2018-8-24 19:32:18

From the second case it looks like build-some-struct is a phase 0 function. In that case, it’ll only be executed at runtime


plotnus
2018-8-24 19:34:35

@shu—hung yes, build-some-struct is a defined function. Because it’ll only be executed at runtime does that mean I cannot print the struct returned from that function, or add stx to the object returned from that function within this case?


shu--hung
2018-8-24 19:36:38
(define-for-syntax (f) ...)
(begin-for-syntax
  (define (f) ...)
  )

or (define (f) ...) ;; at top-level, phase 0


shu--hung
2018-8-24 19:37:31

for the latter case, what #'(build-some-struct op e0 e1) does is to create a syntax object representing function application; that syntax object will later be compiled and executed at runtime (not macro expansion time)


shu--hung
2018-8-24 19:38:34

so in the latter case you can only print the struct returned at runtime — it’s not executed at expansion time


shu--hung
2018-8-24 19:39:05

if it’s the former case (define-for-syntax or begin-for-syntax define, then it’s a function defined for phase 1 and you can just print the result


plotnus
2018-8-24 19:43:31

@shu—hung ok, thank you for taking the time to explain. This helps a lot. I’ll look into using define-for-syntax.


mflatt
2018-8-24 20:44:32

@samth Slideshow’s print/PS/PDF output was set up for paper output. I’ve added a --not-paper/-e flag to make the output bounds match the slide bounds.


samth
2018-8-24 20:48:44

Awesome, thanks


plotnus
2018-8-24 22:22:32

When building syntax is there a way to add a line of code to all patterns that are matched instead of having to add it separately to each pattern? Eg: [(_ foo) (begin (one-arg-func) (proc-for-all))] [(_ foo bar) (begin (one-arg-func) (proc-for-all))] [(_ foo bar baz) (begin (one-arg-func) (proc-for-all))] ... ;; vs something like [(_ foo) (one-arg-func)] [(_ foo bar) (two-arg-func)] [(_ foo bar baz) (thr-arg-func)] ;; then somehow, in one place, apply proc-for all on them all I must admit i did oversimplify. proc-for-all combines stx info with the results of one-arg-func two-arg-func and thr-arg-func.

So it’d really be something like this for every case [(_ foo) (quasisyntax/loc stx (let ([bar (on-arg-func)]) (proc-for-all (quote-syntax #,stx) bar)))] ;; I'm a syntax noob so there may be mistakes above but hopefully you understand what I'm trying to do and the problem which gets a bit unweildy when you have over 40 patterns being matched Is there a way to avoid having to add it to all the cases?


notjack
2018-8-24 23:35:27

@plotnus I don’t have a direct answer to your question, but I think having lots of pattern cases should generally be avoided. I minimize them by factoring things out into syntax classes.


shu--hung
2018-8-24 23:51:10

maybe something like (syntax-parse stx [(_ arg:expr ...) (define len (length (syntax->list #'(arg ...)))) (quasisyntax/loc stx (let ([bar (n-arg-func #,len)]) (proc-for-all bar)))])


shu--hung
2018-8-24 23:53:02

btw if you want to use the information from stx, don’t use (quote-syntax #,stx); rather, extracts the info first and pass the info in e.g. '#,(syntax-column stx)


ryanc
2018-8-25 06:28:48

@plotnus it’s also perfectly fine to wrap the whole syntax-parse expression with a function call, definition, etc: (define-syntax (macro1 stx) (do-more-transformation (syntax-parse stx ....) stx)) (define-syntax (macro2 stx) (define first-part (syntax-parse stx ....)) .... first-part ....)