spdegabrielle
2019-6-28 07:30:46

I know about Rebellion, Turnstile, and Rosette, but are there any outer Meta-DLSs available? https://github.com/racket/racket/wiki/Creating-Languages#meta-dsls


synth
2019-6-28 09:55:04

@synth has joined the channel


synth
2019-6-28 09:55:54

g’day!


sorawee
2019-6-28 10:06:18

Is it possible to implement a fixpoint operator for syntax/parse pattern? E.g.,

(syntax-parse #'(1 ((((2)))) 3)
  [(a {~fix f {~or* b:number (f)}} c) #'(a b c)]) ;=> #'(1 2 3)

Right now I have to write something like:

(define calc
  (syntax-parser
    [x:number #'x]
    [(x) (calc #'x)]))
(syntax-parse #'(1 ((((2)))) 3)
  [(a b c) #`(a #,(calc #'b) c)]) ;=> #'(1 2 3)

which is pretty verbose.


ryanc
2019-6-28 10:36:56

@sorawee That’s what syntax classes are for. But there are no anonymous syntax classes or fixed-point patterns.


sorawee
2019-6-28 10:38:14

I see. Thanks!


alexknauth
2019-6-28 13:10:26

Since syntax-classes can do this, it should be possible to define this ~fix pattern in terms of syntax classes. Here’s my rough attempt to do that.

The main thing that I needed to add was an #:attributes declaration, so you have to write {~fix f {~or* b:number (f)} #:attributes [b]} in order for b to be bound in the body below the pattern. #lang racket (require syntax/parse syntax/parse/experimental/reflect (for-syntax racket/syntax syntax/parse)) (begin-for-syntax (define (fix-name name-class) (pattern-expander (syntax-parser [name:id #:with blank (datum->syntax #'name '\|\| #'name #'name) #`{~var blank #,name-class}] [(name:id . rst) #:with blank (datum->syntax #'name '\|\| #'name #'name) #`({~var blank #,name-class} . rst)])))) (define-syntax ~fix (pattern-expander (syntax-parser [(_ name:id pat {~optional {~seq #:attributes attrs} #:defaults ([attrs #'()])}) #:with name-class (generate-temporary #'name) #:with blank (datum->syntax #'name '\|\| #'name #'name) #'{~reflect blank ((let () (define-syntax name (fix-name (quote-syntax name-class))) (define-syntax-class name-class #:attributes attrs [pattern pat]) (reify-syntax-class name-class))) #:attributes attrs}]))) (syntax-parse #'(1 ((((2)))) 3) [(a {~fix f {~or* b:number (f)} #:attributes [b]} c) #'(a b c)])


stefan.kruger
2019-6-28 13:59:07

I’m getting the following error when trying to make an executable — any idea what that means? The program itself runs fine. Many thanks for any pointers!


mflatt
2019-6-28 14:12:27

That looks like a bug in raco exe. Do you have an example that you can share?


rokitna
2019-6-28 14:15:27

That looks pretty cool. Seems like it oughta be preserved somewhere other than a Slack message. :smile:


stefan.kruger
2019-6-28 14:27:45

It seems to happen for every program no matter how simple, including #lang racket (require math) (define (main) (printf "hello ~a\n" (sum '(1 2 3 4)))) (main)


stefan.kruger
2019-6-28 14:28:16

I’ve only raco-ed one package (fancy-app).


alexknauth
2019-6-28 14:28:29

I just put it in a gist: https://gist.github.com/AlexKnauth/9d6a322279bb80b2b4f86184b4607361 I don’t think it should be in a package though, because putting the pattern into a separate syntax class will cause some strange behaviors like #:literals, #:datum-literals, and #:conventions not being respected within the ~fix pattern, and I’m sure there are many more things that would trip up anyone who wasn’t aware it was a fresh new syntax-class under the hood. It’s not an abstraction that hides its internals behind a sensible interface.


stefan.kruger
2019-6-28 14:29:32

I initiated the exe-building from DrRacket.


mflatt
2019-6-28 15:11:55

Ah, I see that error when creating executables in DrRacket, but not from command-line raco exe. Does raco exe work for you?


stefan.kruger
2019-6-28 15:19:28

Ah yes, that works cleanly.


notjack
2019-6-28 16:13:20

What do you mean by “meta-dsl”? I sort of get what you’re going for with those examples, but I’m not sure


spdegabrielle
2019-6-28 16:19:33

A meta-dsl is a DSL that helps you create other DSLs ‘This paper introduces ROSETTE, a framework for design- ing solver-aided languages’ from the rosette paper


spdegabrielle
2019-6-28 16:20:01

‘The turnstile language "[…]aims to help Racket programmers create typed languages’


notjack
2019-6-28 16:26:21

Ah, okay I see. I’m not sure if rebellion fits there since it mostly provides libraries rather than DSLs. But I do want it to help DSL implementors


spdegabrielle
2019-6-28 16:31:40

I just updated the page


spdegabrielle
2019-6-28 16:33:59

spdegabrielle
2019-6-28 16:34:41

I don’t mind if you update it too. It’s a wiki.


notjack
2019-6-28 16:35:18

Looks great :+1: and thank you! I’ll keep that in mind when I’m not on mobile


spdegabrielle
2019-6-28 16:36:41

Haha- I am on mobile and I just updated it!


spdegabrielle
2019-6-28 16:36:53

spdegabrielle
2019-6-28 16:37:00

Proof!


notjack
2019-6-28 16:58:57

Whoa I didn’t know you could do that!


notjack
2019-6-28 16:59:12

Even better :simple_smile:


caleb.e.allen
2019-6-28 17:36:40

@caleb.e.allen has joined the channel


bkovitz
2019-6-28 18:17:34

@spdegabrielle Thanks for making this wiki page! I just bookmarked it. I’ve been wondering ever since I started using Racket, how do you make languages in Racket? It’s great to see all the available materials collected in one place.


lexi.lambda
2019-6-28 19:51:15

Clever—I was thinking about something similar, but I didn’t think to just stick the define-syntax-class inside a let in the pattern itself.