
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 has joined the channel

g’day!

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.

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

I see. Thanks!

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)])

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!

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

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

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)

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

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.

I initiated the exe-building from DrRacket.

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

Ah yes, that works cleanly.

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

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

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

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

I just updated the page


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

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

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


Proof!

Whoa I didn’t know you could do that!

Even better :simple_smile:

@caleb.e.allen has joined the channel

@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.

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.